Upload folder using huggingface_hub
Browse files- 6.4.0/gallery/Index.svelte +15 -11
- 6.4.0/gallery/package.json +1 -1
- 6.4.0/gallery/shared/Gallery.svelte +169 -110
6.4.0/gallery/Index.svelte
CHANGED
|
@@ -28,7 +28,9 @@
|
|
| 28 |
}
|
| 29 |
|
| 30 |
const props = $props();
|
| 31 |
-
const gradio = new GalleryGradio<GalleryEvents, GalleryProps>(props
|
|
|
|
|
|
|
| 32 |
|
| 33 |
let fullscreen = $state(false);
|
| 34 |
|
|
@@ -121,18 +123,20 @@
|
|
| 121 |
</BaseFileUpload>
|
| 122 |
{:else}
|
| 123 |
<Gallery
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
fullscreen = detail;
|
| 133 |
}}
|
| 134 |
-
|
| 135 |
-
|
| 136 |
const files = Array.isArray(e.detail) ? e.detail : [e.detail];
|
| 137 |
const new_value = await process_upload_files(files);
|
| 138 |
gradio.props.value = gradio.props.value
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
const props = $props();
|
| 31 |
+
const gradio = new GalleryGradio<GalleryEvents, GalleryProps>(props, {
|
| 32 |
+
selected_index: null
|
| 33 |
+
});
|
| 34 |
|
| 35 |
let fullscreen = $state(false);
|
| 36 |
|
|
|
|
| 123 |
</BaseFileUpload>
|
| 124 |
{:else}
|
| 125 |
<Gallery
|
| 126 |
+
onchange={() => gradio.dispatch("change")}
|
| 127 |
+
onclear={() => gradio.dispatch("change")}
|
| 128 |
+
onselect={(e) => gradio.dispatch("select", e)}
|
| 129 |
+
onshare={(e) => gradio.dispatch("share", e.detail)}
|
| 130 |
+
onerror={(e) => gradio.dispatch("error", e.detail)}
|
| 131 |
+
onpreview_open={() => {
|
| 132 |
+
gradio.dispatch("preview_open");
|
| 133 |
+
}}
|
| 134 |
+
onpreview_close={() => gradio.dispatch("preview_close")}
|
| 135 |
+
onfullscreen={({ detail }) => {
|
| 136 |
fullscreen = detail;
|
| 137 |
}}
|
| 138 |
+
ondelete={handle_delete}
|
| 139 |
+
onupload={async (e) => {
|
| 140 |
const files = Array.isArray(e.detail) ? e.detail : [e.detail];
|
| 141 |
const new_value = await process_upload_files(files);
|
| 142 |
gradio.props.value = gradio.props.value
|
6.4.0/gallery/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/gallery",
|
| 3 |
-
"version": "0.16.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/gallery",
|
| 3 |
+
"version": "0.16.2",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
6.4.0/gallery/shared/Gallery.svelte
CHANGED
|
@@ -9,11 +9,10 @@
|
|
| 9 |
} from "@gradio/atoms";
|
| 10 |
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 11 |
import { ModifyUpload, Upload as UploadComponent } from "@gradio/upload";
|
| 12 |
-
import type { SelectData } from "@gradio/utils";
|
| 13 |
import { Image } from "@gradio/image/shared";
|
| 14 |
import { Video } from "@gradio/video/shared";
|
| 15 |
import { dequal } from "dequal";
|
| 16 |
-
import {
|
| 17 |
import { tick } from "svelte";
|
| 18 |
import type { GalleryImage, GalleryVideo } from "../types";
|
| 19 |
|
|
@@ -28,62 +27,93 @@
|
|
| 28 |
import type { Client } from "@gradio/client";
|
| 29 |
import { format_gallery_for_sharing } from "./utils";
|
| 30 |
import type { I18nFormatter } from "@gradio/utils";
|
|
|
|
| 31 |
|
| 32 |
type GalleryData = GalleryImage | GalleryVideo;
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"cover"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
let is_full_screen = false;
|
| 65 |
let image_container: HTMLElement;
|
| 66 |
|
| 67 |
-
|
| 68 |
-
change: undefined;
|
| 69 |
-
select: SelectData;
|
| 70 |
-
preview_open: undefined;
|
| 71 |
-
preview_close: undefined;
|
| 72 |
-
fullscreen: boolean;
|
| 73 |
-
delete: { file: FileData; index: number };
|
| 74 |
-
upload: FileData | FileData[];
|
| 75 |
-
error: string;
|
| 76 |
-
clear: undefined;
|
| 77 |
-
}>();
|
| 78 |
-
|
| 79 |
-
// tracks whether the value of the gallery was reset
|
| 80 |
-
let was_reset = true;
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
let resolved_value: GalleryData[] | null = null;
|
| 85 |
-
|
| 86 |
-
$: resolved_value =
|
| 87 |
value == null
|
| 88 |
? null
|
| 89 |
: (value.map((data) => {
|
|
@@ -96,55 +126,70 @@
|
|
| 96 |
return { image: data.image as FileData, caption: data.caption };
|
| 97 |
}
|
| 98 |
return {};
|
| 99 |
-
}) as GalleryData[])
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
if (resolved_value && columns && fit_columns) {
|
| 105 |
const item_count = resolved_value.length;
|
| 106 |
if (Array.isArray(columns)) {
|
| 107 |
-
|
| 108 |
} else {
|
| 109 |
-
|
| 110 |
}
|
| 111 |
} else {
|
| 112 |
-
|
| 113 |
}
|
| 114 |
}
|
| 115 |
|
| 116 |
-
let
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
let
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
//
|
| 129 |
-
//
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
);
|
| 136 |
} else {
|
| 137 |
-
selected_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
|
|
|
|
|
|
| 139 |
}
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
-
|
| 145 |
-
((selected_index ?? 0) + (resolved_value?.length ?? 0) - 1) %
|
| 146 |
-
(resolved_value?.length ?? 0);
|
| 147 |
-
$: next = ((selected_index ?? 0) + 1) % (resolved_value?.length ?? 0);
|
| 148 |
|
| 149 |
function handle_preview_click(event: MouseEvent): void {
|
| 150 |
const element = event.target as HTMLElement;
|
|
@@ -164,7 +209,7 @@
|
|
| 164 |
case "Escape":
|
| 165 |
e.preventDefault();
|
| 166 |
selected_index = null;
|
| 167 |
-
|
| 168 |
break;
|
| 169 |
case "ArrowLeft":
|
| 170 |
e.preventDefault();
|
|
@@ -179,7 +224,7 @@
|
|
| 179 |
}
|
| 180 |
}
|
| 181 |
|
| 182 |
-
|
| 183 |
if (selected_index !== old_selected_index) {
|
| 184 |
old_selected_index = selected_index;
|
| 185 |
if (selected_index !== null) {
|
|
@@ -189,26 +234,29 @@
|
|
| 189 |
Math.min(selected_index, resolved_value.length - 1)
|
| 190 |
);
|
| 191 |
}
|
| 192 |
-
|
| 193 |
index: selected_index,
|
| 194 |
value: resolved_value?.[selected_index]
|
| 195 |
});
|
| 196 |
}
|
| 197 |
}
|
| 198 |
-
}
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
|
| 204 |
let el: HTMLButtonElement[] = [];
|
| 205 |
-
let container_element: HTMLDivElement;
|
| 206 |
|
| 207 |
async function scroll_to_img(index: number | null): Promise<void> {
|
| 208 |
if (typeof index !== "number") return;
|
| 209 |
await tick();
|
| 210 |
|
| 211 |
if (el[index] === undefined) return;
|
|
|
|
| 212 |
|
| 213 |
el[index]?.focus();
|
| 214 |
|
|
@@ -262,10 +310,11 @@
|
|
| 262 |
URL.revokeObjectURL(url);
|
| 263 |
}
|
| 264 |
|
| 265 |
-
|
| 266 |
selected_index != null && resolved_value != null
|
| 267 |
? resolved_value[selected_index]
|
| 268 |
-
: null
|
|
|
|
| 269 |
|
| 270 |
let thumbnails_overflow = false;
|
| 271 |
|
|
@@ -286,10 +335,13 @@
|
|
| 286 |
window.removeEventListener("resize", check_thumbnails_overflow);
|
| 287 |
});
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
check_thumbnails_overflow();
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
function handle_item_delete(index: number): void {
|
| 295 |
if (!value || !resolved_value) return;
|
|
@@ -310,7 +362,7 @@
|
|
| 310 |
}
|
| 311 |
|
| 312 |
if (deleted_file_data) {
|
| 313 |
-
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
|
@@ -335,7 +387,7 @@
|
|
| 335 |
<IconButtonWrapper
|
| 336 |
display_top_corner={display_icon_button_wrapper_top_corner}
|
| 337 |
{buttons}
|
| 338 |
-
{
|
| 339 |
>
|
| 340 |
{#if show_download_button}
|
| 341 |
<IconButton
|
|
@@ -358,15 +410,22 @@
|
|
| 358 |
{/if}
|
| 359 |
|
| 360 |
{#if show_fullscreen_button}
|
| 361 |
-
<FullscreenButton
|
|
|
|
|
|
|
|
|
|
| 362 |
{/if}
|
| 363 |
|
| 364 |
{#if show_share_button}
|
| 365 |
<div class="icon-button">
|
| 366 |
<ShareButton
|
| 367 |
{i18n}
|
| 368 |
-
on:share
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
value={resolved_value}
|
| 371 |
formatter={format_gallery_for_sharing}
|
| 372 |
/>
|
|
@@ -378,7 +437,7 @@
|
|
| 378 |
label="Close"
|
| 379 |
on:click={() => {
|
| 380 |
selected_index = null;
|
| 381 |
-
|
| 382 |
}}
|
| 383 |
/>
|
| 384 |
{/if}
|
|
@@ -482,7 +541,7 @@
|
|
| 482 |
{i18n}
|
| 483 |
on:clear={() => {
|
| 484 |
value = [];
|
| 485 |
-
|
| 486 |
}}
|
| 487 |
>
|
| 488 |
{#if upload && stream_handler}
|
|
@@ -490,13 +549,13 @@
|
|
| 490 |
<UploadComponent
|
| 491 |
bind:upload_promise
|
| 492 |
icon_upload={true}
|
| 493 |
-
on:load={(e) =>
|
| 494 |
filetype={file_types}
|
| 495 |
file_count="multiple"
|
| 496 |
{max_file_size}
|
| 497 |
{root}
|
| 498 |
bind:uploading
|
| 499 |
-
on:error={(e) =>
|
| 500 |
{stream_handler}
|
| 501 |
{upload}
|
| 502 |
/>
|
|
@@ -516,7 +575,7 @@
|
|
| 516 |
class:selected={selected_index === i}
|
| 517 |
on:click={() => {
|
| 518 |
if (selected_index === null && allow_preview) {
|
| 519 |
-
|
| 520 |
}
|
| 521 |
selected_index = i;
|
| 522 |
}}
|
|
|
|
| 9 |
} from "@gradio/atoms";
|
| 10 |
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 11 |
import { ModifyUpload, Upload as UploadComponent } from "@gradio/upload";
|
|
|
|
| 12 |
import { Image } from "@gradio/image/shared";
|
| 13 |
import { Video } from "@gradio/video/shared";
|
| 14 |
import { dequal } from "dequal";
|
| 15 |
+
import { onMount } from "svelte";
|
| 16 |
import { tick } from "svelte";
|
| 17 |
import type { GalleryImage, GalleryVideo } from "../types";
|
| 18 |
|
|
|
|
| 27 |
import type { Client } from "@gradio/client";
|
| 28 |
import { format_gallery_for_sharing } from "./utils";
|
| 29 |
import type { I18nFormatter } from "@gradio/utils";
|
| 30 |
+
import { on } from "svelte/events";
|
| 31 |
|
| 32 |
type GalleryData = GalleryImage | GalleryVideo;
|
| 33 |
|
| 34 |
+
let {
|
| 35 |
+
show_label = true,
|
| 36 |
+
label,
|
| 37 |
+
value = $bindable(),
|
| 38 |
+
columns = [2],
|
| 39 |
+
rows = undefined,
|
| 40 |
+
height = "auto",
|
| 41 |
+
preview,
|
| 42 |
+
allow_preview = true,
|
| 43 |
+
object_fit = "cover",
|
| 44 |
+
show_share_button = false,
|
| 45 |
+
show_download_button = false,
|
| 46 |
+
i18n,
|
| 47 |
+
selected_index = $bindable(),
|
| 48 |
+
interactive,
|
| 49 |
+
_fetch,
|
| 50 |
+
show_fullscreen_button = true,
|
| 51 |
+
fullscreen = false,
|
| 52 |
+
root = "",
|
| 53 |
+
file_types = ["image", "video"],
|
| 54 |
+
max_file_size = null,
|
| 55 |
+
upload,
|
| 56 |
+
stream_handler,
|
| 57 |
+
fit_columns = true,
|
| 58 |
+
buttons = null,
|
| 59 |
+
oncustom_button_click = null,
|
| 60 |
+
onpreview_open = () => {},
|
| 61 |
+
onchange = () => {},
|
| 62 |
+
onclear = () => {},
|
| 63 |
+
onselect = (data) => {},
|
| 64 |
+
onshare = (data) => {},
|
| 65 |
+
onerror = (error) => {},
|
| 66 |
+
onpreview_close = () => {},
|
| 67 |
+
onfullscreen = (data) => {},
|
| 68 |
+
ondelete = () => {},
|
| 69 |
+
onupload = () => {}
|
| 70 |
+
}: {
|
| 71 |
+
show_label: boolean;
|
| 72 |
+
label: string;
|
| 73 |
+
value: GalleryData[] | null;
|
| 74 |
+
columns: number | number[] | undefined;
|
| 75 |
+
rows: number | number[] | undefined;
|
| 76 |
+
height: number | "auto";
|
| 77 |
+
preview: boolean;
|
| 78 |
+
allow_preview: boolean;
|
| 79 |
+
object_fit: "contain" | "cover" | "fill" | "none" | "scale-down";
|
| 80 |
+
show_share_button: boolean;
|
| 81 |
+
show_download_button: boolean;
|
| 82 |
+
i18n: I18nFormatter;
|
| 83 |
+
selected_index: number | null;
|
| 84 |
+
interactive: boolean;
|
| 85 |
+
_fetch: typeof fetch;
|
| 86 |
+
show_fullscreen_button: boolean;
|
| 87 |
+
fullscreen: boolean;
|
| 88 |
+
root: string;
|
| 89 |
+
file_types: string[] | null;
|
| 90 |
+
max_file_size: number | null;
|
| 91 |
+
upload: Client["upload"] | undefined;
|
| 92 |
+
stream_handler: Client["stream"] | undefined;
|
| 93 |
+
fit_columns: boolean;
|
| 94 |
+
buttons: (string | CustomButtonType)[] | null;
|
| 95 |
+
oncustom_button_click: ((id: number) => void) | null;
|
| 96 |
+
onpreview_open: () => void;
|
| 97 |
+
onchange: () => void;
|
| 98 |
+
onclear: () => void;
|
| 99 |
+
onselect: (data: any) => void;
|
| 100 |
+
onshare: (data: any) => void;
|
| 101 |
+
onerror: (error: any) => void;
|
| 102 |
+
onpreview_close: () => void;
|
| 103 |
+
onfullscreen: (data: any) => void;
|
| 104 |
+
ondelete: (data: any) => void;
|
| 105 |
+
onupload: (data: FileData | FileData[]) => void;
|
| 106 |
+
} = $props();
|
| 107 |
+
|
| 108 |
+
let upload_promise: Promise<any> | null = null;
|
| 109 |
+
let mode: "normal" | "minimal" = "normal";
|
| 110 |
+
let display_icon_button_wrapper_top_corner = false;
|
| 111 |
let is_full_screen = false;
|
| 112 |
let image_container: HTMLElement;
|
| 113 |
|
| 114 |
+
let was_reset: boolean = $state(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
let resolved_value = $derived.by(() =>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
value == null
|
| 118 |
? null
|
| 119 |
: (value.map((data) => {
|
|
|
|
| 126 |
return { image: data.image as FileData, caption: data.caption };
|
| 127 |
}
|
| 128 |
return {};
|
| 129 |
+
}) as GalleryData[])
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
function resolve_effective_columns(
|
| 133 |
+
resolved_value: GalleryData[] | null,
|
| 134 |
+
columns: number | number[] | undefined,
|
| 135 |
+
fit_columns: boolean
|
| 136 |
+
) {
|
| 137 |
if (resolved_value && columns && fit_columns) {
|
| 138 |
const item_count = resolved_value.length;
|
| 139 |
if (Array.isArray(columns)) {
|
| 140 |
+
return columns.map((col) => Math.min(col, item_count));
|
| 141 |
} else {
|
| 142 |
+
return Math.min(columns, item_count);
|
| 143 |
}
|
| 144 |
} else {
|
| 145 |
+
return columns;
|
| 146 |
}
|
| 147 |
}
|
| 148 |
|
| 149 |
+
let effective_columns: number | number[] | undefined = $derived.by(() =>
|
| 150 |
+
resolve_effective_columns(resolved_value, columns, fit_columns)
|
| 151 |
+
);
|
| 152 |
+
|
| 153 |
+
let prev_value: GalleryData[] | null = $state(value);
|
| 154 |
+
// if (selected_index == null && preview && value?.length) {
|
| 155 |
+
// selected_index = 0;
|
| 156 |
+
// }
|
| 157 |
+
let old_selected_index: number | null = $state(selected_index);
|
| 158 |
+
|
| 159 |
+
$effect(() => {
|
| 160 |
+
if (!dequal(prev_value, value)) {
|
| 161 |
+
// When value is falsy (clear button or first load),
|
| 162 |
+
// preview determines the selected image
|
| 163 |
+
if (was_reset) {
|
| 164 |
+
selected_index = preview && value?.length ? 0 : null;
|
| 165 |
+
was_reset = false;
|
| 166 |
+
// Otherwise we keep the selected_index the same if the
|
| 167 |
+
// gallery has at least as many elements as it did before
|
|
|
|
| 168 |
} else {
|
| 169 |
+
if (selected_index !== null && value !== null) {
|
| 170 |
+
selected_index = Math.max(
|
| 171 |
+
0,
|
| 172 |
+
Math.min(selected_index, value.length - 1)
|
| 173 |
+
);
|
| 174 |
+
} else {
|
| 175 |
+
selected_index = null;
|
| 176 |
+
}
|
| 177 |
}
|
| 178 |
+
onchange();
|
| 179 |
+
prev_value = value;
|
| 180 |
}
|
| 181 |
+
});
|
| 182 |
+
|
| 183 |
+
let previous = $derived.by(
|
| 184 |
+
() =>
|
| 185 |
+
((selected_index ?? 0) + (resolved_value?.length ?? 0) - 1) %
|
| 186 |
+
(resolved_value?.length ?? 0)
|
| 187 |
+
);
|
| 188 |
+
let next = $derived.by(
|
| 189 |
+
() => ((selected_index ?? 0) + 1) % (resolved_value?.length ?? 0)
|
| 190 |
+
);
|
| 191 |
|
| 192 |
+
$inspect("selected_index", selected_index);
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
function handle_preview_click(event: MouseEvent): void {
|
| 195 |
const element = event.target as HTMLElement;
|
|
|
|
| 209 |
case "Escape":
|
| 210 |
e.preventDefault();
|
| 211 |
selected_index = null;
|
| 212 |
+
onpreview_close();
|
| 213 |
break;
|
| 214 |
case "ArrowLeft":
|
| 215 |
e.preventDefault();
|
|
|
|
| 224 |
}
|
| 225 |
}
|
| 226 |
|
| 227 |
+
$effect(() => {
|
| 228 |
if (selected_index !== old_selected_index) {
|
| 229 |
old_selected_index = selected_index;
|
| 230 |
if (selected_index !== null) {
|
|
|
|
| 234 |
Math.min(selected_index, resolved_value.length - 1)
|
| 235 |
);
|
| 236 |
}
|
| 237 |
+
onselect({
|
| 238 |
index: selected_index,
|
| 239 |
value: resolved_value?.[selected_index]
|
| 240 |
});
|
| 241 |
}
|
| 242 |
}
|
| 243 |
+
});
|
| 244 |
|
| 245 |
+
$effect(() => {
|
| 246 |
+
if (allow_preview && container_element) {
|
| 247 |
+
scroll_to_img(selected_index);
|
| 248 |
+
}
|
| 249 |
+
});
|
| 250 |
|
| 251 |
let el: HTMLButtonElement[] = [];
|
| 252 |
+
let container_element: HTMLDivElement | undefined = $state();
|
| 253 |
|
| 254 |
async function scroll_to_img(index: number | null): Promise<void> {
|
| 255 |
if (typeof index !== "number") return;
|
| 256 |
await tick();
|
| 257 |
|
| 258 |
if (el[index] === undefined) return;
|
| 259 |
+
if (!container_element) return;
|
| 260 |
|
| 261 |
el[index]?.focus();
|
| 262 |
|
|
|
|
| 310 |
URL.revokeObjectURL(url);
|
| 311 |
}
|
| 312 |
|
| 313 |
+
let selected_media = $derived.by(() =>
|
| 314 |
selected_index != null && resolved_value != null
|
| 315 |
? resolved_value[selected_index]
|
| 316 |
+
: null
|
| 317 |
+
);
|
| 318 |
|
| 319 |
let thumbnails_overflow = false;
|
| 320 |
|
|
|
|
| 335 |
window.removeEventListener("resize", check_thumbnails_overflow);
|
| 336 |
});
|
| 337 |
|
| 338 |
+
$effect(() => {
|
| 339 |
+
resolved_value;
|
| 340 |
check_thumbnails_overflow();
|
| 341 |
+
if (container_element) {
|
| 342 |
+
check_thumbnails_overflow();
|
| 343 |
+
}
|
| 344 |
+
});
|
| 345 |
|
| 346 |
function handle_item_delete(index: number): void {
|
| 347 |
if (!value || !resolved_value) return;
|
|
|
|
| 362 |
}
|
| 363 |
|
| 364 |
if (deleted_file_data) {
|
| 365 |
+
ondelete(deleted_file_data);
|
| 366 |
}
|
| 367 |
}
|
| 368 |
|
|
|
|
| 387 |
<IconButtonWrapper
|
| 388 |
display_top_corner={display_icon_button_wrapper_top_corner}
|
| 389 |
{buttons}
|
| 390 |
+
on_custom_button_click={oncustom_button_click}
|
| 391 |
>
|
| 392 |
{#if show_download_button}
|
| 393 |
<IconButton
|
|
|
|
| 410 |
{/if}
|
| 411 |
|
| 412 |
{#if show_fullscreen_button}
|
| 413 |
+
<FullscreenButton
|
| 414 |
+
{fullscreen}
|
| 415 |
+
on:fullscreen={(e) => onfullscreen(e)}
|
| 416 |
+
/>
|
| 417 |
{/if}
|
| 418 |
|
| 419 |
{#if show_share_button}
|
| 420 |
<div class="icon-button">
|
| 421 |
<ShareButton
|
| 422 |
{i18n}
|
| 423 |
+
on:share={(detail) => {
|
| 424 |
+
onshare(detail);
|
| 425 |
+
}}
|
| 426 |
+
on:error={(detail) => {
|
| 427 |
+
onerror(detail);
|
| 428 |
+
}}
|
| 429 |
value={resolved_value}
|
| 430 |
formatter={format_gallery_for_sharing}
|
| 431 |
/>
|
|
|
|
| 437 |
label="Close"
|
| 438 |
on:click={() => {
|
| 439 |
selected_index = null;
|
| 440 |
+
onpreview_close();
|
| 441 |
}}
|
| 442 |
/>
|
| 443 |
{/if}
|
|
|
|
| 541 |
{i18n}
|
| 542 |
on:clear={() => {
|
| 543 |
value = [];
|
| 544 |
+
onclear();
|
| 545 |
}}
|
| 546 |
>
|
| 547 |
{#if upload && stream_handler}
|
|
|
|
| 549 |
<UploadComponent
|
| 550 |
bind:upload_promise
|
| 551 |
icon_upload={true}
|
| 552 |
+
on:load={(e) => onupload(e.detail)}
|
| 553 |
filetype={file_types}
|
| 554 |
file_count="multiple"
|
| 555 |
{max_file_size}
|
| 556 |
{root}
|
| 557 |
bind:uploading
|
| 558 |
+
on:error={(e) => onerror(e.detail)}
|
| 559 |
{stream_handler}
|
| 560 |
{upload}
|
| 561 |
/>
|
|
|
|
| 575 |
class:selected={selected_index === i}
|
| 576 |
on:click={() => {
|
| 577 |
if (selected_index === null && allow_preview) {
|
| 578 |
+
onpreview_open();
|
| 579 |
}
|
| 580 |
selected_index = i;
|
| 581 |
}}
|