Upload folder using huggingface_hub
Browse files
6.16.0/dropdown/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dropdown",
|
| 3 |
-
"version": "0.12.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dropdown",
|
| 3 |
+
"version": "0.12.1",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
6.16.0/dropdown/shared/Dropdown.svelte
CHANGED
|
@@ -52,6 +52,9 @@
|
|
| 52 |
|
| 53 |
let filter_input: HTMLElement;
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
let show_options = $derived.by(() => {
|
| 56 |
return is_browser && filter_input === document.activeElement;
|
| 57 |
});
|
|
@@ -59,30 +62,37 @@
|
|
| 59 |
let choices_values = $derived(choices.map((c) => c[1]));
|
| 60 |
let input_text = $state("");
|
| 61 |
let selected_index: number | null = $state(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
$effect(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
if (
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
(Array.isArray(
|
| 68 |
) {
|
| 69 |
input_text = "";
|
| 70 |
selected_index = null;
|
| 71 |
-
} else if (
|
| 72 |
-
input_text =
|
| 73 |
-
|
| 74 |
-
selected_index = choices_values.indexOf(value as string | number);
|
| 75 |
} else if (allow_custom_value) {
|
| 76 |
-
input_text =
|
| 77 |
selected_index = null;
|
| 78 |
} else {
|
| 79 |
input_text = "";
|
| 80 |
selected_index = null;
|
| 81 |
}
|
|
|
|
| 82 |
});
|
| 83 |
-
// Use last_typed_value to track when the user has typed
|
| 84 |
-
// on_blur we only want to update value if the user has typed
|
| 85 |
-
let last_typed_value = input_text;
|
| 86 |
let initialized = $state(false);
|
| 87 |
let disabled = $derived(!interactive);
|
| 88 |
|
|
@@ -93,6 +103,11 @@
|
|
| 93 |
selected_index === null ? [] : [selected_index]
|
| 94 |
);
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
function handle_option_selected(index: any): void {
|
| 97 |
selected_index = parseInt(index);
|
| 98 |
if (isNaN(selected_index)) {
|
|
@@ -117,7 +132,9 @@
|
|
| 117 |
}
|
| 118 |
|
| 119 |
function handle_focus(e: FocusEvent): void {
|
|
|
|
| 120 |
filtered_indices = choices.map((_, i) => i);
|
|
|
|
| 121 |
show_options = true;
|
| 122 |
on_focus?.();
|
| 123 |
}
|
|
@@ -126,11 +143,11 @@
|
|
| 126 |
if (!allow_custom_value) {
|
| 127 |
input_text =
|
| 128 |
choices_names[choices_values.indexOf(value as string | number)];
|
| 129 |
-
} else {
|
| 130 |
if (choices_names.includes(input_text)) {
|
| 131 |
selected_index = choices_names.indexOf(input_text);
|
| 132 |
value = choices_values[selected_index];
|
| 133 |
-
} else
|
| 134 |
value = input_text;
|
| 135 |
selected_index = null;
|
| 136 |
}
|
|
@@ -138,14 +155,33 @@
|
|
| 138 |
show_options = false;
|
| 139 |
active_index = null;
|
| 140 |
filtered_indices = choices.map((_, i) => i);
|
|
|
|
| 141 |
on_blur?.();
|
| 142 |
on_input?.();
|
| 143 |
}
|
| 144 |
|
| 145 |
async function handle_key_down(e: KeyboardEvent): Promise<void> {
|
| 146 |
await tick();
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
[show_options, active_index] = handle_shared_keys(
|
| 150 |
e,
|
| 151 |
active_index,
|
|
@@ -198,7 +234,7 @@
|
|
| 198 |
<div class="secondary-wrap">
|
| 199 |
<input
|
| 200 |
role="listbox"
|
| 201 |
-
aria-controls=
|
| 202 |
aria-expanded={show_options}
|
| 203 |
aria-label={label}
|
| 204 |
class="border-none"
|
|
@@ -233,6 +269,7 @@
|
|
| 233 |
{disabled}
|
| 234 |
{selected_indices}
|
| 235 |
{active_index}
|
|
|
|
| 236 |
onchange={handle_option_selected}
|
| 237 |
onload={() => (initialized = true)}
|
| 238 |
/>
|
|
|
|
| 52 |
|
| 53 |
let filter_input: HTMLElement;
|
| 54 |
|
| 55 |
+
const uid = $props.id();
|
| 56 |
+
const listbox_id = `${uid}-options`;
|
| 57 |
+
|
| 58 |
let show_options = $derived.by(() => {
|
| 59 |
return is_browser && filter_input === document.activeElement;
|
| 60 |
});
|
|
|
|
| 62 |
let choices_values = $derived(choices.map((c) => c[1]));
|
| 63 |
let input_text = $state("");
|
| 64 |
let selected_index: number | null = $state(null);
|
| 65 |
+
// Use last_typed_value to track when the user has typed
|
| 66 |
+
// on_blur we only want to update value if the user has typed
|
| 67 |
+
let last_typed_value = input_text;
|
| 68 |
+
let focused = $state(false);
|
| 69 |
|
| 70 |
$effect(() => {
|
| 71 |
+
const current_value = value;
|
| 72 |
+
const values = choices_values;
|
| 73 |
+
const names = choices_names;
|
| 74 |
+
if (focused) {
|
| 75 |
+
return;
|
| 76 |
+
}
|
| 77 |
if (
|
| 78 |
+
current_value === undefined ||
|
| 79 |
+
current_value === null ||
|
| 80 |
+
(Array.isArray(current_value) && current_value.length === 0)
|
| 81 |
) {
|
| 82 |
input_text = "";
|
| 83 |
selected_index = null;
|
| 84 |
+
} else if (values.includes(current_value as string | number)) {
|
| 85 |
+
input_text = names[values.indexOf(current_value as string | number)];
|
| 86 |
+
selected_index = values.indexOf(current_value as string | number);
|
|
|
|
| 87 |
} else if (allow_custom_value) {
|
| 88 |
+
input_text = current_value as string;
|
| 89 |
selected_index = null;
|
| 90 |
} else {
|
| 91 |
input_text = "";
|
| 92 |
selected_index = null;
|
| 93 |
}
|
| 94 |
+
last_typed_value = input_text;
|
| 95 |
});
|
|
|
|
|
|
|
|
|
|
| 96 |
let initialized = $state(false);
|
| 97 |
let disabled = $derived(!interactive);
|
| 98 |
|
|
|
|
| 103 |
selected_index === null ? [] : [selected_index]
|
| 104 |
);
|
| 105 |
|
| 106 |
+
$effect(() => {
|
| 107 |
+
choices;
|
| 108 |
+
filtered_indices = choices.map((_, i) => i);
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
function handle_option_selected(index: any): void {
|
| 112 |
selected_index = parseInt(index);
|
| 113 |
if (isNaN(selected_index)) {
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
function handle_focus(e: FocusEvent): void {
|
| 135 |
+
focused = true;
|
| 136 |
filtered_indices = choices.map((_, i) => i);
|
| 137 |
+
active_index = selected_index;
|
| 138 |
show_options = true;
|
| 139 |
on_focus?.();
|
| 140 |
}
|
|
|
|
| 143 |
if (!allow_custom_value) {
|
| 144 |
input_text =
|
| 145 |
choices_names[choices_values.indexOf(value as string | number)];
|
| 146 |
+
} else if (input_text !== last_typed_value) {
|
| 147 |
if (choices_names.includes(input_text)) {
|
| 148 |
selected_index = choices_names.indexOf(input_text);
|
| 149 |
value = choices_values[selected_index];
|
| 150 |
+
} else {
|
| 151 |
value = input_text;
|
| 152 |
selected_index = null;
|
| 153 |
}
|
|
|
|
| 155 |
show_options = false;
|
| 156 |
active_index = null;
|
| 157 |
filtered_indices = choices.map((_, i) => i);
|
| 158 |
+
focused = false;
|
| 159 |
on_blur?.();
|
| 160 |
on_input?.();
|
| 161 |
}
|
| 162 |
|
| 163 |
async function handle_key_down(e: KeyboardEvent): Promise<void> {
|
| 164 |
await tick();
|
| 165 |
+
const is_navigation_key =
|
| 166 |
+
e.key === "ArrowUp" ||
|
| 167 |
+
e.key === "ArrowDown" ||
|
| 168 |
+
e.key === "Enter" ||
|
| 169 |
+
e.key === "Escape";
|
| 170 |
+
const is_filtering = input_text !== last_typed_value;
|
| 171 |
+
if (!is_navigation_key) {
|
| 172 |
+
filtered_indices = handle_filter(choices, input_text);
|
| 173 |
+
active_index = filtered_indices.length > 0 ? filtered_indices[0] : null;
|
| 174 |
+
} else {
|
| 175 |
+
// Recompute the visible options so navigation always spans the full
|
| 176 |
+
// current list. Filter by the typed text when the user is filtering,
|
| 177 |
+
// otherwise (a value is just displayed/selected) show every option.
|
| 178 |
+
filtered_indices = is_filtering
|
| 179 |
+
? handle_filter(choices, input_text)
|
| 180 |
+
: choices.map((_, i) => i);
|
| 181 |
+
if (active_index !== null && !filtered_indices.includes(active_index)) {
|
| 182 |
+
active_index = filtered_indices.length > 0 ? filtered_indices[0] : null;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
[show_options, active_index] = handle_shared_keys(
|
| 186 |
e,
|
| 187 |
active_index,
|
|
|
|
| 234 |
<div class="secondary-wrap">
|
| 235 |
<input
|
| 236 |
role="listbox"
|
| 237 |
+
aria-controls={listbox_id}
|
| 238 |
aria-expanded={show_options}
|
| 239 |
aria-label={label}
|
| 240 |
class="border-none"
|
|
|
|
| 269 |
{disabled}
|
| 270 |
{selected_indices}
|
| 271 |
{active_index}
|
| 272 |
+
{listbox_id}
|
| 273 |
onchange={handle_option_selected}
|
| 274 |
onload={() => (initialized = true)}
|
| 275 |
/>
|
6.16.0/dropdown/shared/DropdownOptions.svelte
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
remember_scroll = false,
|
| 11 |
offset_from_top = 0,
|
| 12 |
from_top = false,
|
|
|
|
| 13 |
onchange,
|
| 14 |
onload
|
| 15 |
}: {
|
|
@@ -22,6 +23,7 @@
|
|
| 22 |
remember_scroll?: boolean;
|
| 23 |
offset_from_top?: number;
|
| 24 |
from_top?: boolean;
|
|
|
|
| 25 |
onchange?: (index: any) => void;
|
| 26 |
onload?: () => void;
|
| 27 |
} = $props();
|
|
@@ -119,6 +121,7 @@
|
|
| 119 |
style:max-height={`calc(${max_height}px - var(--window-padding))`}
|
| 120 |
style:width={input_width + "px"}
|
| 121 |
bind:this={listElement}
|
|
|
|
| 122 |
role="listbox"
|
| 123 |
>
|
| 124 |
{#each filtered_indices as index}
|
|
@@ -130,6 +133,7 @@
|
|
| 130 |
class:dark:bg-gray-600={index === active_index}
|
| 131 |
style:width={input_width + "px"}
|
| 132 |
data-index={index}
|
|
|
|
| 133 |
aria-label={choices[index][0]}
|
| 134 |
data-testid="dropdown-option"
|
| 135 |
role="option"
|
|
|
|
| 10 |
remember_scroll = false,
|
| 11 |
offset_from_top = 0,
|
| 12 |
from_top = false,
|
| 13 |
+
listbox_id = undefined,
|
| 14 |
onchange,
|
| 15 |
onload
|
| 16 |
}: {
|
|
|
|
| 23 |
remember_scroll?: boolean;
|
| 24 |
offset_from_top?: number;
|
| 25 |
from_top?: boolean;
|
| 26 |
+
listbox_id?: string;
|
| 27 |
onchange?: (index: any) => void;
|
| 28 |
onload?: () => void;
|
| 29 |
} = $props();
|
|
|
|
| 121 |
style:max-height={`calc(${max_height}px - var(--window-padding))`}
|
| 122 |
style:width={input_width + "px"}
|
| 123 |
bind:this={listElement}
|
| 124 |
+
id={listbox_id}
|
| 125 |
role="listbox"
|
| 126 |
>
|
| 127 |
{#each filtered_indices as index}
|
|
|
|
| 133 |
class:dark:bg-gray-600={index === active_index}
|
| 134 |
style:width={input_width + "px"}
|
| 135 |
data-index={index}
|
| 136 |
+
id={listbox_id ? `${listbox_id}-option-${index}` : undefined}
|
| 137 |
aria-label={choices[index][0]}
|
| 138 |
data-testid="dropdown-option"
|
| 139 |
role="option"
|