Upload folder using huggingface_hub
Browse files
6.3.1/dropdown/Example.svelte
CHANGED
|
@@ -1,8 +1,15 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
let value_array = value ? (Array.isArray(value) ? value : [value]) : [];
|
| 8 |
let names = value_array
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
let {
|
| 3 |
+
value,
|
| 4 |
+
type,
|
| 5 |
+
selected = false,
|
| 6 |
+
choices
|
| 7 |
+
}: {
|
| 8 |
+
value: string | string[] | null;
|
| 9 |
+
type: "gallery" | "table";
|
| 10 |
+
selected?: boolean;
|
| 11 |
+
choices: [string, string | number][];
|
| 12 |
+
} = $props();
|
| 13 |
|
| 14 |
let value_array = value ? (Array.isArray(value) ? value : [value]) : [];
|
| 15 |
let names = value_array
|
6.3.1/dropdown/Index.svelte
CHANGED
|
@@ -47,7 +47,7 @@
|
|
| 47 |
allow_custom_value={gradio.props.allow_custom_value}
|
| 48 |
filterable={gradio.props.filterable}
|
| 49 |
buttons={gradio.props.buttons}
|
| 50 |
-
|
| 51 |
gradio.dispatch("custom_button_click", { id });
|
| 52 |
}}
|
| 53 |
on_change={() => gradio.dispatch("change")}
|
|
|
|
| 47 |
allow_custom_value={gradio.props.allow_custom_value}
|
| 48 |
filterable={gradio.props.filterable}
|
| 49 |
buttons={gradio.props.buttons}
|
| 50 |
+
oncustom_button_click={(id) => {
|
| 51 |
gradio.dispatch("custom_button_click", { id });
|
| 52 |
}}
|
| 53 |
on_change={() => gradio.dispatch("change")}
|
6.3.1/dropdown/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dropdown",
|
| 3 |
-
"version": "0.11.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dropdown",
|
| 3 |
+
"version": "0.11.2",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
6.3.1/dropdown/shared/Dropdown.svelte
CHANGED
|
@@ -23,7 +23,7 @@
|
|
| 23 |
allow_custom_value = false,
|
| 24 |
filterable = true,
|
| 25 |
buttons = null,
|
| 26 |
-
|
| 27 |
on_change,
|
| 28 |
on_input,
|
| 29 |
on_select,
|
|
@@ -31,17 +31,17 @@
|
|
| 31 |
on_blur,
|
| 32 |
on_key_up
|
| 33 |
}: {
|
| 34 |
-
label
|
| 35 |
info?: string;
|
| 36 |
-
value
|
| 37 |
-
choices
|
| 38 |
-
interactive
|
| 39 |
-
show_label
|
| 40 |
-
container
|
| 41 |
-
allow_custom_value
|
| 42 |
-
filterable
|
| 43 |
-
buttons
|
| 44 |
-
|
| 45 |
on_change?: (value: string | number | null) => void;
|
| 46 |
on_input?: () => void;
|
| 47 |
on_select?: (data: SelectData) => void;
|
|
@@ -89,8 +89,8 @@
|
|
| 89 |
let filtered_indices = $state(choices.map((_, i) => i));
|
| 90 |
let active_index: number | null = $state(null);
|
| 91 |
|
| 92 |
-
function handle_option_selected(
|
| 93 |
-
selected_index = parseInt(
|
| 94 |
if (isNaN(selected_index)) {
|
| 95 |
// This is the case when the user clicks on the scrollbar
|
| 96 |
selected_index = null;
|
|
@@ -182,7 +182,7 @@
|
|
| 182 |
|
| 183 |
<div class:container>
|
| 184 |
{#if show_label && buttons && buttons.length > 0}
|
| 185 |
-
<IconButtonWrapper {buttons} {
|
| 186 |
{/if}
|
| 187 |
<BlockTitle {show_label} {info}>{label}</BlockTitle>
|
| 188 |
|
|
@@ -201,15 +201,15 @@
|
|
| 201 |
{disabled}
|
| 202 |
bind:value={input_text}
|
| 203 |
bind:this={filter_input}
|
| 204 |
-
|
| 205 |
-
|
| 206 |
on_key_up?.({
|
| 207 |
key: e.key,
|
| 208 |
input_value: input_text
|
| 209 |
});
|
| 210 |
}}
|
| 211 |
-
|
| 212 |
-
|
| 213 |
readonly={!filterable}
|
| 214 |
/>
|
| 215 |
{#if !disabled}
|
|
@@ -226,8 +226,8 @@
|
|
| 226 |
{disabled}
|
| 227 |
selected_indices={selected_index === null ? [] : [selected_index]}
|
| 228 |
{active_index}
|
| 229 |
-
|
| 230 |
-
|
| 231 |
/>
|
| 232 |
</div>
|
| 233 |
</div>
|
|
|
|
| 23 |
allow_custom_value = false,
|
| 24 |
filterable = true,
|
| 25 |
buttons = null,
|
| 26 |
+
oncustom_button_click = null,
|
| 27 |
on_change,
|
| 28 |
on_input,
|
| 29 |
on_select,
|
|
|
|
| 31 |
on_blur,
|
| 32 |
on_key_up
|
| 33 |
}: {
|
| 34 |
+
label: string;
|
| 35 |
info?: string;
|
| 36 |
+
value: string | number | null;
|
| 37 |
+
choices: [string, string | number][];
|
| 38 |
+
interactive: boolean;
|
| 39 |
+
show_label: boolean;
|
| 40 |
+
container: boolean;
|
| 41 |
+
allow_custom_value: boolean;
|
| 42 |
+
filterable: boolean;
|
| 43 |
+
buttons: (string | CustomButtonType)[] | null;
|
| 44 |
+
oncustom_button_click?: ((id: number) => void) | null;
|
| 45 |
on_change?: (value: string | number | null) => void;
|
| 46 |
on_input?: () => void;
|
| 47 |
on_select?: (data: SelectData) => void;
|
|
|
|
| 89 |
let filtered_indices = $state(choices.map((_, i) => i));
|
| 90 |
let active_index: number | null = $state(null);
|
| 91 |
|
| 92 |
+
function handle_option_selected(index: any): void {
|
| 93 |
+
selected_index = parseInt(index);
|
| 94 |
if (isNaN(selected_index)) {
|
| 95 |
// This is the case when the user clicks on the scrollbar
|
| 96 |
selected_index = null;
|
|
|
|
| 182 |
|
| 183 |
<div class:container>
|
| 184 |
{#if show_label && buttons && buttons.length > 0}
|
| 185 |
+
<IconButtonWrapper {buttons} {oncustom_button_click} />
|
| 186 |
{/if}
|
| 187 |
<BlockTitle {show_label} {info}>{label}</BlockTitle>
|
| 188 |
|
|
|
|
| 201 |
{disabled}
|
| 202 |
bind:value={input_text}
|
| 203 |
bind:this={filter_input}
|
| 204 |
+
onkeydown={handle_key_down}
|
| 205 |
+
onkeyup={(e) => {
|
| 206 |
on_key_up?.({
|
| 207 |
key: e.key,
|
| 208 |
input_value: input_text
|
| 209 |
});
|
| 210 |
}}
|
| 211 |
+
onblur={handle_blur}
|
| 212 |
+
onfocus={handle_focus}
|
| 213 |
readonly={!filterable}
|
| 214 |
/>
|
| 215 |
{#if !disabled}
|
|
|
|
| 226 |
{disabled}
|
| 227 |
selected_indices={selected_index === null ? [] : [selected_index]}
|
| 228 |
{active_index}
|
| 229 |
+
onchange={handle_option_selected}
|
| 230 |
+
onload={() => (initialized = true)}
|
| 231 |
/>
|
| 232 |
</div>
|
| 233 |
</div>
|
6.3.1/dropdown/shared/DropdownOptions.svelte
CHANGED
|
@@ -1,24 +1,41 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { fly } from "svelte/transition";
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
let distance_from_top: number;
|
| 15 |
let distance_from_bottom: number;
|
| 16 |
let input_height: number;
|
| 17 |
-
let input_width
|
| 18 |
let refElement: HTMLDivElement;
|
| 19 |
let listElement: HTMLUListElement;
|
| 20 |
-
let top: string | null
|
| 21 |
-
let
|
|
|
|
|
|
|
| 22 |
let list_scroll_y = 0;
|
| 23 |
|
| 24 |
function calculate_window_distance(): void {
|
|
@@ -49,7 +66,7 @@
|
|
| 49 |
listElement?.scrollTo?.(0, list_scroll_y);
|
| 50 |
}
|
| 51 |
|
| 52 |
-
$
|
| 53 |
if (show_options && refElement) {
|
| 54 |
if (remember_scroll) {
|
| 55 |
restore_last_scroll();
|
|
@@ -71,6 +88,7 @@
|
|
| 71 |
const rect = refElement.parentElement?.getBoundingClientRect();
|
| 72 |
input_height = rect?.height || 0;
|
| 73 |
input_width = rect?.width || 0;
|
|
|
|
| 74 |
}
|
| 75 |
if (distance_from_bottom > distance_from_top || from_top) {
|
| 76 |
top = `${distance_from_top}px`;
|
|
@@ -81,9 +99,7 @@
|
|
| 81 |
max_height = distance_from_top - input_height;
|
| 82 |
top = null;
|
| 83 |
}
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
const dispatch = createEventDispatcher();
|
| 87 |
</script>
|
| 88 |
|
| 89 |
<svelte:window on:scroll={scroll_listener} bind:innerHeight />
|
|
@@ -93,8 +109,11 @@
|
|
| 93 |
<ul
|
| 94 |
class="options"
|
| 95 |
transition:fly={{ duration: 200, y: 5 }}
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
style:top
|
| 99 |
style:bottom
|
| 100 |
style:max-height={`calc(${max_height}px - var(--window-padding))`}
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { fly } from "svelte/transition";
|
| 3 |
+
let {
|
| 4 |
+
choices,
|
| 5 |
+
filtered_indices,
|
| 6 |
+
show_options = false,
|
| 7 |
+
disabled = false,
|
| 8 |
+
selected_indices = [],
|
| 9 |
+
active_index = null,
|
| 10 |
+
remember_scroll = false,
|
| 11 |
+
offset_from_top = 0,
|
| 12 |
+
from_top = false,
|
| 13 |
+
onchange,
|
| 14 |
+
onload
|
| 15 |
+
}: {
|
| 16 |
+
choices: [string, string | number][];
|
| 17 |
+
filtered_indices: number[];
|
| 18 |
+
show_options: boolean;
|
| 19 |
+
disabled?: boolean;
|
| 20 |
+
selected_indices?: (string | number)[];
|
| 21 |
+
active_index: number | null;
|
| 22 |
+
remember_scroll?: boolean;
|
| 23 |
+
offset_from_top?: number;
|
| 24 |
+
from_top?: boolean;
|
| 25 |
+
onchange?: (index: any) => void;
|
| 26 |
+
onload?: () => void;
|
| 27 |
+
} = $props();
|
| 28 |
|
| 29 |
let distance_from_top: number;
|
| 30 |
let distance_from_bottom: number;
|
| 31 |
let input_height: number;
|
| 32 |
+
let input_width = $state(0);
|
| 33 |
let refElement: HTMLDivElement;
|
| 34 |
let listElement: HTMLUListElement;
|
| 35 |
+
let top: string | null = $state(null);
|
| 36 |
+
let bottom: string | null = $state(null);
|
| 37 |
+
let max_height: number = $state(0);
|
| 38 |
+
let innerHeight = $state(0);
|
| 39 |
let list_scroll_y = 0;
|
| 40 |
|
| 41 |
function calculate_window_distance(): void {
|
|
|
|
| 66 |
listElement?.scrollTo?.(0, list_scroll_y);
|
| 67 |
}
|
| 68 |
|
| 69 |
+
$effect(() => {
|
| 70 |
if (show_options && refElement) {
|
| 71 |
if (remember_scroll) {
|
| 72 |
restore_last_scroll();
|
|
|
|
| 88 |
const rect = refElement.parentElement?.getBoundingClientRect();
|
| 89 |
input_height = rect?.height || 0;
|
| 90 |
input_width = rect?.width || 0;
|
| 91 |
+
onload?.();
|
| 92 |
}
|
| 93 |
if (distance_from_bottom > distance_from_top || from_top) {
|
| 94 |
top = `${distance_from_top}px`;
|
|
|
|
| 99 |
max_height = distance_from_top - input_height;
|
| 100 |
top = null;
|
| 101 |
}
|
| 102 |
+
});
|
|
|
|
|
|
|
| 103 |
</script>
|
| 104 |
|
| 105 |
<svelte:window on:scroll={scroll_listener} bind:innerHeight />
|
|
|
|
| 109 |
<ul
|
| 110 |
class="options"
|
| 111 |
transition:fly={{ duration: 200, y: 5 }}
|
| 112 |
+
onmousedown={(e) => {
|
| 113 |
+
e.preventDefault();
|
| 114 |
+
onchange?.((e.target as HTMLElement).dataset.index);
|
| 115 |
+
}}
|
| 116 |
+
onscroll={(e) => (list_scroll_y = e.currentTarget.scrollTop)}
|
| 117 |
style:top
|
| 118 |
style:bottom
|
| 119 |
style:max-height={`calc(${max_height}px - var(--window-padding))`}
|
6.3.1/dropdown/shared/Multiselect.svelte
CHANGED
|
@@ -116,8 +116,8 @@
|
|
| 116 |
);
|
| 117 |
}
|
| 118 |
|
| 119 |
-
function handle_option_selected(
|
| 120 |
-
const option_index = parseInt(
|
| 121 |
add_or_remove_index(option_index);
|
| 122 |
}
|
| 123 |
|
|
@@ -185,14 +185,14 @@
|
|
| 185 |
}
|
| 186 |
});
|
| 187 |
|
| 188 |
-
function
|
| 189 |
gradio.dispatch("custom_button_click", { id });
|
| 190 |
}
|
| 191 |
</script>
|
| 192 |
|
| 193 |
<label class:container={gradio.shared.container}>
|
| 194 |
{#if gradio.shared.show_label && buttons && buttons.length > 0}
|
| 195 |
-
<IconButtonWrapper {buttons} {
|
| 196 |
{/if}
|
| 197 |
<BlockTitle show_label={gradio.shared.show_label} info={gradio.props.info}
|
| 198 |
>{label}</BlockTitle
|
|
@@ -278,7 +278,7 @@
|
|
| 278 |
{selected_indices}
|
| 279 |
{active_index}
|
| 280 |
remember_scroll={true}
|
| 281 |
-
|
| 282 |
/>
|
| 283 |
</div>
|
| 284 |
</label>
|
|
|
|
| 116 |
);
|
| 117 |
}
|
| 118 |
|
| 119 |
+
function handle_option_selected(index: any): void {
|
| 120 |
+
const option_index = parseInt(index);
|
| 121 |
add_or_remove_index(option_index);
|
| 122 |
}
|
| 123 |
|
|
|
|
| 185 |
}
|
| 186 |
});
|
| 187 |
|
| 188 |
+
function oncustom_button_click(id: number) {
|
| 189 |
gradio.dispatch("custom_button_click", { id });
|
| 190 |
}
|
| 191 |
</script>
|
| 192 |
|
| 193 |
<label class:container={gradio.shared.container}>
|
| 194 |
{#if gradio.shared.show_label && buttons && buttons.length > 0}
|
| 195 |
+
<IconButtonWrapper {buttons} {oncustom_button_click} />
|
| 196 |
{/if}
|
| 197 |
<BlockTitle show_label={gradio.shared.show_label} info={gradio.props.info}
|
| 198 |
>{label}</BlockTitle
|
|
|
|
| 278 |
{selected_indices}
|
| 279 |
{active_index}
|
| 280 |
remember_scroll={true}
|
| 281 |
+
onchange={handle_option_selected}
|
| 282 |
/>
|
| 283 |
</div>
|
| 284 |
</label>
|