Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite uiElementIsVisible #10534

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion javascript/dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ window.addEventListener('paste', e => {
}

const visibleImageFields = [...gradioApp().querySelectorAll('[data-testid="image"]')]
.filter(el => uiElementIsVisible(el));
.filter(el => uiElementIsVisible(el))
.sort((a,b) => uiElementInSight(b) - uiElementInSight(a));


if (!visibleImageFields.length) {
return;
}
Expand Down
28 changes: 15 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,21 @@ document.addEventListener('keydown', function(e) {
* checks that a UI element is not in another hidden element or tab content
*/
function uiElementIsVisible(el) {
let isVisible = !el.closest('.\\!hidden');
if (!isVisible) {
return false;
if (el === document) {
return true;
}

while ((isVisible = el.closest('.tabitem')?.style.display) !== 'none') {
if (!isVisible) {
return false;
} else if (el.parentElement) {
el = el.parentElement;
} else {
break;
}
}
return isVisible;
const computedStyle = getComputedStyle(el);
const isVisible = computedStyle.display !== 'none';

if (!isVisible) return false;
return uiElementIsVisible(el.parentNode);
}

function uiElementInSight(el) {
const clRect = el.getBoundingClientRect();
const windowHeight = window.innerHeight;
const isOnScreen = clRect.bottom > 0 && clRect.top < windowHeight;

return isOnScreen;
}