gradio-pr-bot commited on
Commit
577198e
·
verified ·
1 Parent(s): 6738c66

Upload folder using huggingface_hub

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