gradio-pr-bot commited on
Commit
16ee8c2
·
verified ·
1 Parent(s): c1bb5d6

Upload folder using huggingface_hub

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