gradio-pr-bot commited on
Commit
97d15a8
·
verified ·
1 Parent(s): 4ed453b

Upload folder using huggingface_hub

Browse files
6.13.1/textbox/Example.svelte ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+
4
+ export let value: string | null;
5
+ export let type: "gallery" | "table";
6
+ export let selected = false;
7
+
8
+ let size: number;
9
+ let el: HTMLDivElement;
10
+
11
+ function set_styles(element: HTMLElement, el_width: number): void {
12
+ element.style.setProperty(
13
+ "--local-text-width",
14
+ `${el_width && el_width < 150 ? el_width : 200}px`
15
+ );
16
+ element.style.whiteSpace = "unset";
17
+ }
18
+
19
+ function truncate_text(text: string | null, max_length = 60): string {
20
+ if (!text) return "";
21
+ const str = String(text);
22
+ if (str.length <= max_length) return str;
23
+ return str.slice(0, max_length) + "...";
24
+ }
25
+
26
+ onMount(() => {
27
+ set_styles(el, size);
28
+ });
29
+ </script>
30
+
31
+ <div
32
+ bind:clientWidth={size}
33
+ bind:this={el}
34
+ class:table={type === "table"}
35
+ class:gallery={type === "gallery"}
36
+ class:selected
37
+ >
38
+ {truncate_text(value)}
39
+ </div>
40
+
41
+ <style>
42
+ .gallery {
43
+ padding: var(--size-1) var(--size-2);
44
+ }
45
+
46
+ div {
47
+ overflow: hidden;
48
+ white-space: nowrap;
49
+ }
50
+ </style>
6.13.1/textbox/Index.svelte ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as BaseTextbox } from "./shared/Textbox.svelte";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { tick } from "svelte";
10
+ import TextBox from "./shared/Textbox.svelte";
11
+ import StatusTracker from "@gradio/statustracker";
12
+ import { Block } from "@gradio/atoms";
13
+ import { Gradio } from "@gradio/utils";
14
+ import type { TextboxProps, TextboxEvents } from "./types";
15
+
16
+ let _props = $props();
17
+ const gradio = new Gradio<TextboxEvents, TextboxProps>(_props);
18
+
19
+ let label = $derived(gradio.shared.label || "Textbox");
20
+ // Need to set the value to "" otherwise a change event gets
21
+ // dispatched when the child sets it to ""
22
+ gradio.props.value = gradio.props.value ?? "";
23
+ let old_value = $state(gradio.props.value);
24
+
25
+ async function dispatch_change() {
26
+ if (old_value !== gradio.props.value) {
27
+ old_value = gradio.props.value;
28
+ await tick();
29
+ gradio.dispatch("change", $state.snapshot(gradio.props.value));
30
+ }
31
+ }
32
+
33
+ async function handle_input(value: string): Promise<void> {
34
+ if (!gradio.shared || !gradio.props) return;
35
+ gradio.props.validation_error = null;
36
+ gradio.props.value = value;
37
+ await tick();
38
+ gradio.dispatch("input");
39
+ }
40
+
41
+ $effect(() => {
42
+ dispatch_change();
43
+ });
44
+
45
+ function handle_change(value: string): void {
46
+ if (!gradio.shared || !gradio.props) return;
47
+ gradio.props.validation_error = null;
48
+ gradio.props.value = value;
49
+ }
50
+ </script>
51
+
52
+ <Block
53
+ visible={gradio.shared.visible}
54
+ elem_id={gradio.shared.elem_id}
55
+ elem_classes={gradio.shared.elem_classes}
56
+ scale={gradio.shared.scale}
57
+ min_width={gradio.shared.min_width}
58
+ allow_overflow={false}
59
+ padding={gradio.shared.container}
60
+ rtl={gradio.props.rtl}
61
+ >
62
+ {#if gradio.shared.loading_status}
63
+ <StatusTracker
64
+ autoscroll={gradio.shared.autoscroll}
65
+ i18n={gradio.i18n}
66
+ {...gradio.shared.loading_status}
67
+ show_validation_error={false}
68
+ on_clear_status={() =>
69
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
70
+ />
71
+ {/if}
72
+
73
+ <TextBox
74
+ bind:value={gradio.props.value}
75
+ {label}
76
+ info={gradio.props.info}
77
+ show_label={gradio.shared.show_label}
78
+ lines={gradio.props.lines}
79
+ type={gradio.props.type}
80
+ rtl={gradio.props.rtl}
81
+ text_align={gradio.props.text_align}
82
+ max_lines={gradio.props.max_lines}
83
+ placeholder={gradio.props.placeholder}
84
+ submit_btn={gradio.props.submit_btn}
85
+ stop_btn={gradio.props.stop_btn}
86
+ buttons={gradio.props.buttons}
87
+ autofocus={gradio.props.autofocus}
88
+ container={gradio.shared.container}
89
+ autoscroll={gradio.shared.autoscroll}
90
+ max_length={gradio.props.max_length}
91
+ html_attributes={gradio.props.html_attributes}
92
+ validation_error={gradio.shared?.loading_status?.validation_error ||
93
+ gradio.shared?.validation_error}
94
+ onchange={handle_change}
95
+ oninput={handle_input}
96
+ onsubmit={() => {
97
+ gradio.shared.validation_error = null;
98
+ gradio.dispatch("submit");
99
+ }}
100
+ onblur={() => gradio.dispatch("blur")}
101
+ onselect={(data) => gradio.dispatch("select", data)}
102
+ onfocus={() => gradio.dispatch("focus")}
103
+ onstop={() => gradio.dispatch("stop")}
104
+ oncopy={(data) => gradio.dispatch("copy", data)}
105
+ oncustombuttonclick={(id) => {
106
+ gradio.dispatch("custom_button_click", { id });
107
+ }}
108
+ disabled={!gradio.shared.interactive}
109
+ />
110
+ </Block>
111
+
112
+ <!-- bind:value_is_output={gradio.props.value_is_output} -->
6.13.1/textbox/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/textbox",
3
+ "version": "0.13.9",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "gradio": "./Index.svelte",
14
+ "svelte": "./dist/Index.svelte",
15
+ "types": "./dist/Index.svelte.d.ts"
16
+ },
17
+ "./example": {
18
+ "gradio": "./Example.svelte",
19
+ "svelte": "./dist/Example.svelte",
20
+ "types": "./dist/Example.svelte.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/icons": "workspace:^",
27
+ "@gradio/statustracker": "workspace:^",
28
+ "@gradio/utils": "workspace:^"
29
+ },
30
+ "devDependencies": {
31
+ "@gradio/preview": "workspace:^"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^5.48.0"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/gradio-app/gradio.git",
39
+ "directory": "js/textbox"
40
+ }
41
+ }
6.13.1/textbox/shared/Textbox.svelte ADDED
@@ -0,0 +1,584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { tick } from "svelte";
3
+ import { BlockTitle, IconButton, IconButtonWrapper } from "@gradio/atoms";
4
+ import { Copy, Check, Send, Square } from "@gradio/icons";
5
+ import type {
6
+ SelectData,
7
+ CopyData,
8
+ CustomButton as CustomButtonType
9
+ } from "@gradio/utils";
10
+ import type { InputHTMLAttributes } from "../types";
11
+
12
+ let {
13
+ value = $bindable(""),
14
+ value_is_output = $bindable(false),
15
+ lines = 1,
16
+ placeholder = "",
17
+ label,
18
+ info = undefined,
19
+ disabled = false,
20
+ show_label = true,
21
+ container = true,
22
+ max_lines = undefined,
23
+ type = "text",
24
+ buttons = null,
25
+ oncustombuttonclick = null,
26
+ submit_btn = null,
27
+ stop_btn = null,
28
+ rtl = false,
29
+ autofocus = false,
30
+ text_align = undefined,
31
+ autoscroll = true,
32
+ max_length = undefined,
33
+ html_attributes = null,
34
+ validation_error = undefined,
35
+ onchange,
36
+ onsubmit,
37
+ onstop,
38
+ onblur,
39
+ onselect,
40
+ oninput,
41
+ onfocus,
42
+ oncopy
43
+ }: {
44
+ value?: string;
45
+ value_is_output?: boolean;
46
+ lines?: number;
47
+ placeholder?: string;
48
+ label: string;
49
+ info?: string | undefined;
50
+ disabled?: boolean;
51
+ show_label?: boolean;
52
+ container?: boolean;
53
+ max_lines?: number | undefined;
54
+ type?: "text" | "password" | "email";
55
+ buttons?: (string | CustomButtonType)[] | null;
56
+ oncustombuttonclick?: ((id: number) => void) | null;
57
+ submit_btn?: string | boolean | null;
58
+ stop_btn?: string | boolean | null;
59
+ rtl?: boolean;
60
+ autofocus?: boolean;
61
+ text_align?: "left" | "right" | undefined;
62
+ autoscroll?: boolean;
63
+ max_length?: number | undefined;
64
+ html_attributes?: InputHTMLAttributes | null;
65
+ validation_error?: string | null | undefined;
66
+ onchange?: (value: string) => void;
67
+ onsubmit?: () => void;
68
+ onstop?: () => void;
69
+ onblur?: () => void;
70
+ onselect?: (data: SelectData) => void;
71
+ oninput?: (value: string) => void;
72
+ onfocus?: () => void;
73
+ oncopy?: (data: CopyData) => void;
74
+ } = $props();
75
+
76
+ // svelte-ignore non_reactive_update
77
+ let el: HTMLTextAreaElement | HTMLInputElement;
78
+ let copied = $state(false);
79
+ let timer: NodeJS.Timeout;
80
+ let can_scroll = $state(false);
81
+ let previous_scroll_top = $state(0);
82
+ let user_has_scrolled_up = $state(false);
83
+ let _max_lines = $state(1);
84
+
85
+ // svelte-ignore state_referenced_locally
86
+ const show_textbox_border = !submit_btn;
87
+
88
+ $effect(() => {
89
+ if (max_lines === undefined || max_lines === null) {
90
+ if (type === "text") {
91
+ _max_lines = Math.max(lines, 20);
92
+ } else {
93
+ _max_lines = 1;
94
+ }
95
+ } else {
96
+ _max_lines = Math.max(max_lines, lines);
97
+ }
98
+ });
99
+
100
+ $effect(() => {
101
+ value;
102
+ validation_error;
103
+ if (el && lines !== _max_lines && _max_lines > 1) {
104
+ resize({ target: el });
105
+ }
106
+ });
107
+
108
+ $effect(() => {
109
+ if (value === null) value = "";
110
+ });
111
+
112
+ $effect.pre(() => {
113
+ if (
114
+ !user_has_scrolled_up &&
115
+ el &&
116
+ el.offsetHeight + el.scrollTop > el.scrollHeight - 100
117
+ ) {
118
+ can_scroll = true;
119
+ }
120
+ });
121
+
122
+ const scroll = (): void => {
123
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
124
+ el.scrollTo(0, el.scrollHeight);
125
+ }
126
+ };
127
+
128
+ async function handle_change(): Promise<void> {
129
+ await tick();
130
+ onchange?.(value);
131
+ }
132
+
133
+ $effect(() => {
134
+ if (autofocus && el) {
135
+ el.focus();
136
+ }
137
+ if (can_scroll && autoscroll) {
138
+ scroll();
139
+ }
140
+ value_is_output = false;
141
+ });
142
+
143
+ $effect(() => {
144
+ value;
145
+ handle_change();
146
+ });
147
+
148
+ async function handle_copy(): Promise<void> {
149
+ if ("clipboard" in navigator) {
150
+ try {
151
+ await navigator.clipboard.writeText(value);
152
+ oncopy?.({ value: value });
153
+ } catch (e) {
154
+ console.error("COPYING CLIPBOARD FAILED", e);
155
+ }
156
+ copy_feedback();
157
+ }
158
+ }
159
+
160
+ function copy_feedback(): void {
161
+ copied = true;
162
+ if (timer) clearTimeout(timer);
163
+ timer = setTimeout(() => {
164
+ copied = false;
165
+ }, 1000);
166
+ }
167
+
168
+ function handle_select(event: Event): void {
169
+ const target: HTMLTextAreaElement | HTMLInputElement = event.target as
170
+ | HTMLTextAreaElement
171
+ | HTMLInputElement;
172
+ const text = target.value;
173
+ const index: [number, number] = [
174
+ target.selectionStart as number,
175
+ target.selectionEnd as number
176
+ ];
177
+ onselect?.({ value: text.substring(...index), index: index });
178
+ }
179
+
180
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
181
+ if (e.key === "Enter" && e.shiftKey && lines > 1) {
182
+ e.preventDefault();
183
+ await tick();
184
+ onsubmit?.();
185
+ } else if (
186
+ e.key === "Enter" &&
187
+ !e.shiftKey &&
188
+ lines === 1 &&
189
+ _max_lines >= 1
190
+ ) {
191
+ e.preventDefault();
192
+ await tick();
193
+ onsubmit?.();
194
+ }
195
+ await tick();
196
+ oninput?.(value);
197
+ }
198
+
199
+ function handle_scroll(event: Event): void {
200
+ const target = event.target as HTMLElement;
201
+ const current_scroll_top = target.scrollTop;
202
+ if (current_scroll_top < previous_scroll_top) {
203
+ user_has_scrolled_up = true;
204
+ }
205
+ previous_scroll_top = current_scroll_top;
206
+
207
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
208
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
209
+ if (user_has_scrolled_to_bottom) {
210
+ user_has_scrolled_up = false;
211
+ }
212
+ }
213
+
214
+ function handle_stop(): void {
215
+ onstop?.();
216
+ }
217
+
218
+ function handle_submit(): void {
219
+ onsubmit?.();
220
+ }
221
+
222
+ async function resize(
223
+ event: Event | { target: HTMLTextAreaElement | HTMLInputElement }
224
+ ): Promise<void> {
225
+ await tick();
226
+ if (lines === _max_lines) return;
227
+
228
+ const target = event.target as HTMLTextAreaElement;
229
+ const computed_styles = window.getComputedStyle(target);
230
+ const padding_top = parseFloat(computed_styles.paddingTop);
231
+ const padding_bottom = parseFloat(computed_styles.paddingBottom);
232
+ const line_height = parseFloat(computed_styles.lineHeight);
233
+
234
+ let max =
235
+ _max_lines === undefined
236
+ ? false
237
+ : padding_top + padding_bottom + line_height * _max_lines;
238
+ let min = padding_top + padding_bottom + lines * line_height;
239
+
240
+ target.style.height = "1px";
241
+
242
+ let scroll_height;
243
+ if (max && target.scrollHeight > max) {
244
+ scroll_height = max;
245
+ } else if (target.scrollHeight < min) {
246
+ scroll_height = min;
247
+ } else {
248
+ scroll_height = target.scrollHeight;
249
+ }
250
+
251
+ target.style.height = `${scroll_height}px`;
252
+
253
+ update_scrollbar_visibility(target);
254
+ }
255
+
256
+ function update_scrollbar_visibility(textarea: HTMLTextAreaElement): void {
257
+ // Using "auto" scroll does not work, as the scrollbar is visible even
258
+ // when the content is about the same height as the textarea height. So
259
+ // here, we add the scrollbar if the content is longer than a threshold
260
+ // of 1 line height beyond the textarea height.
261
+ const content_height = textarea.scrollHeight;
262
+ const visible_height = textarea.clientHeight;
263
+ const line_height = parseFloat(
264
+ window.getComputedStyle(textarea).lineHeight
265
+ );
266
+ if (content_height > visible_height + line_height) {
267
+ textarea.style.overflowY = "scroll";
268
+ } else {
269
+ textarea.style.overflowY = "hidden";
270
+ }
271
+ }
272
+
273
+ function text_area_resize(
274
+ _el: HTMLTextAreaElement,
275
+ _value: string
276
+ ): any | undefined {
277
+ if (lines === _max_lines || (lines === 1 && _max_lines === 1)) return;
278
+
279
+ _el.addEventListener("input", resize);
280
+
281
+ if (_value.trim()) {
282
+ _el.style.overflowY = "scroll";
283
+ resize({ target: _el });
284
+ }
285
+
286
+ return {
287
+ destroy: () => _el.removeEventListener("input", resize)
288
+ };
289
+ }
290
+ </script>
291
+
292
+ <label class:container class:show_textbox_border>
293
+ {#if show_label && buttons && buttons.length > 0}
294
+ <IconButtonWrapper {buttons} on_custom_button_click={oncustombuttonclick}>
295
+ {#if buttons.some((btn) => typeof btn === "string" && btn === "copy")}
296
+ <IconButton
297
+ Icon={copied ? Check : Copy}
298
+ onclick={handle_copy}
299
+ label={copied ? "Copied" : "Copy"}
300
+ />
301
+ {/if}
302
+ </IconButtonWrapper>
303
+ {/if}
304
+ <BlockTitle show_label={validation_error ? true : show_label} {info}
305
+ >{label}
306
+ {#if validation_error}
307
+ <div class="validation-error">{validation_error}</div>
308
+ {/if}
309
+ </BlockTitle>
310
+
311
+ <div class="input-container">
312
+ {#if lines === 1 && _max_lines === 1}
313
+ {#if type === "text"}
314
+ <!-- svelte-ignore a11y_autofocus -->
315
+ <input
316
+ data-testid="textbox"
317
+ type="text"
318
+ class="scroll-hide"
319
+ dir={rtl ? "rtl" : "ltr"}
320
+ bind:value
321
+ bind:this={el}
322
+ {placeholder}
323
+ {disabled}
324
+ {autofocus}
325
+ maxlength={max_length}
326
+ onkeypress={handle_keypress}
327
+ onblur={() => onblur?.()}
328
+ onselect={handle_select}
329
+ onfocus={() => onfocus?.()}
330
+ class:validation-error={validation_error}
331
+ style={text_align ? "text-align: " + text_align : ""}
332
+ autocapitalize={html_attributes?.autocapitalize}
333
+ autocorrect={html_attributes?.autocorrect}
334
+ spellcheck={html_attributes?.spellcheck}
335
+ autocomplete={html_attributes?.autocomplete}
336
+ tabindex={html_attributes?.tabindex}
337
+ enterkeyhint={html_attributes?.enterkeyhint}
338
+ lang={html_attributes?.lang}
339
+ />
340
+ {:else if type === "password"}
341
+ <!-- svelte-ignore a11y_autofocus -->
342
+ <input
343
+ data-testid="password"
344
+ type="password"
345
+ class="scroll-hide"
346
+ bind:value
347
+ bind:this={el}
348
+ {placeholder}
349
+ {disabled}
350
+ {autofocus}
351
+ maxlength={max_length}
352
+ onkeypress={handle_keypress}
353
+ onblur={() => onblur?.()}
354
+ onselect={handle_select}
355
+ onfocus={() => onfocus?.()}
356
+ class:validation-error={validation_error}
357
+ autocomplete=""
358
+ autocapitalize={html_attributes?.autocapitalize}
359
+ autocorrect={html_attributes?.autocorrect}
360
+ spellcheck={html_attributes?.spellcheck}
361
+ tabindex={html_attributes?.tabindex}
362
+ enterkeyhint={html_attributes?.enterkeyhint}
363
+ lang={html_attributes?.lang}
364
+ />
365
+ {:else if type === "email"}
366
+ <!-- svelte-ignore a11y_autofocus -->
367
+ <input
368
+ data-testid="textbox"
369
+ type="email"
370
+ class="scroll-hide"
371
+ bind:value
372
+ bind:this={el}
373
+ {placeholder}
374
+ {disabled}
375
+ {autofocus}
376
+ maxlength={max_length}
377
+ onkeypress={handle_keypress}
378
+ onblur={() => onblur?.()}
379
+ onselect={handle_select}
380
+ onfocus={() => onfocus?.()}
381
+ class:validation-error={validation_error}
382
+ autocomplete="email"
383
+ autocapitalize={html_attributes?.autocapitalize}
384
+ autocorrect={html_attributes?.autocorrect}
385
+ spellcheck={html_attributes?.spellcheck}
386
+ tabindex={html_attributes?.tabindex}
387
+ enterkeyhint={html_attributes?.enterkeyhint}
388
+ lang={html_attributes?.lang}
389
+ />
390
+ {/if}
391
+ {:else}
392
+ <!-- svelte-ignore a11y_autofocus -->
393
+ <textarea
394
+ data-testid="textbox"
395
+ use:text_area_resize={value}
396
+ dir={rtl ? "rtl" : "ltr"}
397
+ class:no-label={!show_label && (submit_btn || stop_btn)}
398
+ bind:value
399
+ bind:this={el}
400
+ {placeholder}
401
+ rows={lines}
402
+ {disabled}
403
+ {autofocus}
404
+ maxlength={max_length}
405
+ onkeypress={handle_keypress}
406
+ onblur={() => onblur?.()}
407
+ onselect={handle_select}
408
+ onfocus={() => onfocus?.()}
409
+ onscroll={handle_scroll}
410
+ class:validation-error={validation_error}
411
+ style={text_align ? "text-align: " + text_align : ""}
412
+ autocapitalize={html_attributes?.autocapitalize}
413
+ autocorrect={html_attributes?.autocorrect}
414
+ spellcheck={html_attributes?.spellcheck}
415
+ autocomplete={html_attributes?.autocomplete}
416
+ tabindex={html_attributes?.tabindex}
417
+ enterkeyhint={html_attributes?.enterkeyhint}
418
+ lang={html_attributes?.lang}
419
+ ></textarea>
420
+ {/if}
421
+ {#if submit_btn}
422
+ <button
423
+ class="submit-button"
424
+ class:padded-button={submit_btn !== true}
425
+ onclick={handle_submit}
426
+ data-testid="submit-button"
427
+ >
428
+ {#if submit_btn === true}
429
+ <Send />
430
+ {:else}
431
+ {submit_btn}
432
+ {/if}
433
+ </button>
434
+ {/if}
435
+ {#if stop_btn}
436
+ <button
437
+ class="stop-button"
438
+ class:padded-button={stop_btn !== true}
439
+ onclick={handle_stop}
440
+ data-testid="stop-button"
441
+ >
442
+ {#if stop_btn === true}
443
+ <Square fill="none" stroke_width={2.5} />
444
+ {:else}
445
+ {stop_btn}
446
+ {/if}
447
+ </button>
448
+ {/if}
449
+ </div>
450
+ </label>
451
+
452
+ <style>
453
+ label {
454
+ display: block;
455
+ width: 100%;
456
+ }
457
+
458
+ input[type="text"],
459
+ input[type="password"],
460
+ input[type="email"],
461
+ textarea {
462
+ flex-grow: 1;
463
+ outline: none !important;
464
+ margin-top: 0px;
465
+ margin-bottom: 0px;
466
+ resize: none;
467
+ z-index: 1;
468
+ display: block;
469
+ position: relative;
470
+ outline: none !important;
471
+ background: var(--input-background-fill);
472
+ padding: var(--input-padding);
473
+ width: 100%;
474
+ color: var(--body-text-color);
475
+ font-weight: var(--input-text-weight);
476
+ font-size: var(--input-text-size);
477
+ line-height: var(--line-sm);
478
+ border: none;
479
+ }
480
+
481
+ textarea.no-label {
482
+ padding-top: 5px;
483
+ padding-bottom: 5px;
484
+ }
485
+ label.show_textbox_border input,
486
+ label.show_textbox_border textarea {
487
+ box-shadow: var(--input-shadow);
488
+ }
489
+ label:not(.container),
490
+ label:not(.container) input,
491
+ label:not(.container) textarea {
492
+ height: 100%;
493
+ }
494
+ label.container.show_textbox_border input,
495
+ label.container.show_textbox_border textarea {
496
+ border: var(--input-border-width) solid var(--input-border-color);
497
+ border-radius: var(--input-radius);
498
+ }
499
+ input:disabled,
500
+ textarea:disabled {
501
+ -webkit-opacity: 1;
502
+ opacity: 1;
503
+ }
504
+
505
+ label.container.show_textbox_border input:focus,
506
+ label.container.show_textbox_border textarea:focus {
507
+ box-shadow: var(--input-shadow-focus);
508
+ border-color: var(--input-border-color-focus);
509
+ background: var(--input-background-fill-focus);
510
+ }
511
+
512
+ input::placeholder,
513
+ textarea::placeholder {
514
+ color: var(--input-placeholder-color);
515
+ }
516
+
517
+ /* Same submit button style as MultimodalTextbox for the consistent UI */
518
+ .input-container {
519
+ display: flex;
520
+ position: relative;
521
+ align-items: flex-end;
522
+ }
523
+ .submit-button,
524
+ .stop-button {
525
+ border: none;
526
+ text-align: center;
527
+ text-decoration: none;
528
+ font-size: 14px;
529
+ cursor: pointer;
530
+ border-radius: 15px;
531
+ min-width: 30px;
532
+ height: 30px;
533
+ flex-shrink: 0;
534
+ display: flex;
535
+ justify-content: center;
536
+ align-items: center;
537
+ z-index: var(--layer-1);
538
+ }
539
+ .stop-button,
540
+ .submit-button {
541
+ background: var(--button-secondary-background-fill);
542
+ color: var(--button-secondary-text-color);
543
+ }
544
+ .stop-button:hover,
545
+ .submit-button:hover {
546
+ background: var(--button-secondary-background-fill-hover);
547
+ }
548
+ .stop-button:disabled,
549
+ .submit-button:disabled {
550
+ background: var(--button-secondary-background-fill);
551
+ cursor: pointer;
552
+ }
553
+ .stop-button:active,
554
+ .submit-button:active {
555
+ box-shadow: var(--button-shadow-active);
556
+ }
557
+ .submit-button :global(svg) {
558
+ height: 22px;
559
+ width: 22px;
560
+ }
561
+
562
+ .stop-button :global(svg) {
563
+ height: 16px;
564
+ width: 16px;
565
+ }
566
+ .padded-button {
567
+ padding: 0 10px;
568
+ }
569
+
570
+ div.validation-error {
571
+ color: var(--error-icon-color);
572
+ font-size: var(--font-sans);
573
+ margin-top: var(--spacing-sm);
574
+ font-weight: var(--weight-semibold);
575
+ }
576
+
577
+ label.container input.validation-error,
578
+ label.container textarea.validation-error {
579
+ border-color: transparent !important;
580
+ box-shadow:
581
+ 0 0 3px 1px var(--error-icon-color),
582
+ var(--shadow-inset) !important;
583
+ }
584
+ </style>
6.13.1/textbox/types.ts ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ type SelectData,
3
+ type CopyData,
4
+ type CustomButton
5
+ } from "@gradio/utils";
6
+ import type { LoadingStatus } from "@gradio/statustracker";
7
+
8
+ export interface TextboxEvents {
9
+ change: string;
10
+ submit: never;
11
+ blur: never;
12
+ select: SelectData;
13
+ input: never;
14
+ focus: never;
15
+ stop: never;
16
+ clear_status: LoadingStatus;
17
+ copy: CopyData;
18
+ custom_button_click: { id: number };
19
+ }
20
+
21
+ export interface TextboxProps {
22
+ value: string;
23
+ info: string;
24
+ lines: number;
25
+ type: "text" | "password" | "email" | undefined;
26
+ rtl: boolean;
27
+ text_align: "right" | "left";
28
+ max_lines: number;
29
+ placeholder: string;
30
+ submit_btn: string;
31
+ stop_btn: string;
32
+ buttons: (string | CustomButton)[] | null;
33
+ autofocus: boolean;
34
+ autoscroll: boolean;
35
+ max_length: number;
36
+ html_attributes: InputHTMLAttributes;
37
+ validation_error: string | null;
38
+ }
39
+
40
+ type FullAutoFill =
41
+ | AutoFill
42
+ | "bday"
43
+ | `${OptionalPrefixToken<AutoFillAddressKind>}${"cc-additional-name"}`
44
+ | "nickname"
45
+ | "language"
46
+ | "organization-title"
47
+ | "photo"
48
+ | "sex"
49
+ | "url";
50
+
51
+ export interface InputHTMLAttributes {
52
+ autocapitalize?:
53
+ | "off"
54
+ | "none"
55
+ | "on"
56
+ | "sentences"
57
+ | "words"
58
+ | "characters"
59
+ | null;
60
+ autocorrect?: "on" | "off" | null;
61
+ spellcheck?: boolean | null;
62
+ autocomplete?: FullAutoFill | undefined | null;
63
+ tabindex?: number | null;
64
+ enterkeyhint?:
65
+ | "enter"
66
+ | "done"
67
+ | "go"
68
+ | "next"
69
+ | "previous"
70
+ | "search"
71
+ | "send"
72
+ | null;
73
+ lang?: string | null;
74
+ }