@@ -70,7 +79,7 @@
{#if filtered.length > 0}
-
+
{#each filtered as [inputName, input]}
diff --git a/src/lib/components/gradio/gallery/Gallery.svelte b/src/lib/components/gradio/gallery/Gallery.svelte
index f70705f..8108ca5 100644
--- a/src/lib/components/gradio/gallery/Gallery.svelte
+++ b/src/lib/components/gradio/gallery/Gallery.svelte
@@ -26,6 +26,7 @@
const dispatch = createEventDispatcher<{
select: SelectData;
+ clicked: HTMLImageElement
}>();
// tracks whether the value of the gallery was reset
@@ -142,6 +143,14 @@
let height = 0;
let window_height = 0;
+
+ let imgElem = null;
+
+ function onClick() {
+ // selected_image = next
+ if (imgElem)
+ dispatch("clicked", imgElem)
+ }
@@ -166,7 +175,8 @@
(selected_image = null)} />
(selected_image = next)}
+ on:click={onClick}
+ bind:this={imgElem}
src={_value[selected_image][0].data}
alt={_value[selected_image][1] || ""}
title={_value[selected_image][1] || null}
diff --git a/src/lib/widgets/GalleryWidget.svelte b/src/lib/widgets/GalleryWidget.svelte
index 72361ce..53e9fa9 100644
--- a/src/lib/widgets/GalleryWidget.svelte
+++ b/src/lib/widgets/GalleryWidget.svelte
@@ -49,7 +49,7 @@
let mobileLightbox = null;
- function showMobileLightbox(event: Event) {
+ function showMobileLightbox(source: HTMLImageElement) {
if (!f7)
return
@@ -58,16 +58,14 @@
mobileLightbox = null;
}
- const source = (event.target || event.srcElement) as HTMLImageElement;
const galleryElem = source.closest("div.block")
- console.debug("[ImageViewer] showModal", event, source, galleryElem);
+ console.debug("[ImageViewer] showModal", source, galleryElem);
if (!galleryElem || ImageViewer.all_gallery_buttons(galleryElem).length === 0) {
console.error("No buttons found on gallery element!", galleryElem)
return;
}
const allGalleryButtons = ImageViewer.all_gallery_buttons(galleryElem);
- const selectedSource = source.src
const images = allGalleryButtons.map(button => {
return {
@@ -84,47 +82,18 @@
type: 'popup',
});
mobileLightbox.open(selected_image)
-
- event.stopPropagation()
}
- function setupImageForMobileLightbox(e: HTMLImageElement) {
- if (e.dataset.modded === "true")
- return;
-
- e.dataset.modded = "true";
- e.style.cursor = "pointer";
- e.style.userSelect = "none";
-
- var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
-
- // For Firefox, listening on click first switched to next image then shows the lightbox.
- // If you know how to fix this without switching to mousedown event, please.
- // For other browsers the event is click to make it possiblr to drag picture.
- var event = isFirefox ? 'mousedown' : 'click'
-
- e.addEventListener(event, (evt) => {
- evt.preventDefault()
- showMobileLightbox(evt)
- }, true);
+ function onClicked(e: CustomEvent) {
+ if (isMobile) {
+ showMobileLightbox(e.detail)
+ }
+ else {
+ ImageViewer.instance.showLightbox(e.detail)
+ }
}
function onSelect(e: CustomEvent) {
- // Setup lightbox
- // Wait for gradio gallery to show the large preview image, if no timeout then
- // the event might fire too early
-
- const callback = isMobile ? setupImageForMobileLightbox
- : ImageViewer.instance.setupGalleryImageForLightbox.bind(ImageViewer.instance)
-
- setTimeout(() => {
- const images = element.querySelectorAll('div.block div > img')
- if (images != null) {
- images.forEach(callback);
- }
- ImageViewer.instance.refreshImages();
- }, 200)
-
// Update index
node.setProperty("index", e.detail.index as number)
}
@@ -176,6 +145,7 @@
root={""}
root_url={""}
on:select={onSelect}
+ on:clicked={onClicked}
bind:imageWidth={$imageWidth}
bind:imageHeight={$imageHeight}
bind:selected_image