gradio-pr-bot commited on
Commit
2768c48
·
verified ·
1 Parent(s): 650fd14

Upload folder using huggingface_hub

Browse files
6.5.0/multimodaltextbox/Example.svelte CHANGED
@@ -1,17 +1,19 @@
1
  <script lang="ts">
2
- import { onMount } from "svelte";
3
  import { Image } from "@gradio/image/shared";
4
  import { Video } from "@gradio/video/shared";
5
  import type { FileData } from "@gradio/client";
6
 
7
- export let value: { text: string; files: FileData[] } = {
8
- text: "",
9
- files: []
10
- };
11
- export let type: "gallery" | "table";
12
- export let selected = false;
 
 
 
13
 
14
- let size: number;
15
  let el: HTMLDivElement;
16
 
17
  function set_styles(element: HTMLElement, el_width: number): void {
@@ -22,8 +24,10 @@
22
  element.style.whiteSpace = "unset";
23
  }
24
 
25
- onMount(() => {
26
- set_styles(el, size);
 
 
27
  });
28
  </script>
29
 
 
1
  <script lang="ts">
 
2
  import { Image } from "@gradio/image/shared";
3
  import { Video } from "@gradio/video/shared";
4
  import type { FileData } from "@gradio/client";
5
 
6
+ let {
7
+ value = { text: "", files: [] },
8
+ type,
9
+ selected = false
10
+ }: {
11
+ value?: { text: string; files: FileData[] };
12
+ type: "gallery" | "table";
13
+ selected?: boolean;
14
+ } = $props();
15
 
16
+ let size = $state<number>(0);
17
  let el: HTMLDivElement;
18
 
19
  function set_styles(element: HTMLElement, el_width: number): void {
 
24
  element.style.whiteSpace = "unset";
25
  }
26
 
27
+ $effect(() => {
28
+ if (el && size) {
29
+ set_styles(el, size);
30
+ }
31
  });
32
  </script>
33
 
6.5.0/multimodaltextbox/Index.svelte CHANGED
@@ -17,7 +17,7 @@
17
  MultimodalTextboxEvents
18
  } from "./types";
19
 
20
- let upload_promise = $state<Promise<any>>();
21
 
22
  class MultimodalTextboxGradio extends Gradio<
23
  MultimodalTextboxEvents,
@@ -37,7 +37,7 @@
37
  let props = $props();
38
  const gradio = new MultimodalTextboxGradio(props);
39
 
40
- const value = $derived(gradio.props.value || { text: "", files: [] });
41
 
42
  let dragging = $state<boolean>(false);
43
  let active_source = $state<"microphone" | null>(null);
@@ -135,7 +135,7 @@
135
 
136
  <MultimodalTextbox
137
  bind:upload_promise
138
- {value}
139
  value_is_output
140
  bind:dragging
141
  bind:active_source
@@ -160,24 +160,22 @@
160
  file_count={gradio.props.file_count}
161
  {sources_string}
162
  max_file_size={gradio.shared.max_file_size}
163
- on:change={(e) => (
164
- (gradio.props.value = e.detail),
165
- gradio.dispatch("change", gradio.props.value)
166
- )}
167
- on:input={() => gradio.dispatch("input")}
168
- on:submit={() => gradio.dispatch("submit")}
169
- on:stop={() => gradio.dispatch("stop")}
170
- on:blur={() => gradio.dispatch("blur")}
171
- on:select={(e) => gradio.dispatch("select", e.detail)}
172
- on:focus={() => gradio.dispatch("focus")}
173
- on:error={({ detail }) => {
174
  gradio.dispatch("error", detail);
175
  }}
176
- on:start_recording={() => gradio.dispatch("start_recording")}
177
- on:pause_recording={() => gradio.dispatch("pause_recording")}
178
- on:stop_recording={() => gradio.dispatch("stop_recording")}
179
- on:upload={(e) => gradio.dispatch("upload", e.detail)}
180
- on:clear={() => gradio.dispatch("clear")}
181
  disabled={!gradio.shared.interactive}
182
  upload={upload_fn}
183
  stream_handler={stream_handler_fn}
 
17
  MultimodalTextboxEvents
18
  } from "./types";
19
 
20
+ let upload_promise = $state<Promise<any> | null>(null);
21
 
22
  class MultimodalTextboxGradio extends Gradio<
23
  MultimodalTextboxEvents,
 
37
  let props = $props();
38
  const gradio = new MultimodalTextboxGradio(props);
39
 
40
+ gradio.props.value = gradio.props.value ?? { text: "", files: [] };
41
 
42
  let dragging = $state<boolean>(false);
43
  let active_source = $state<"microphone" | null>(null);
 
135
 
136
  <MultimodalTextbox
137
  bind:upload_promise
138
+ bind:value={gradio.props.value}
139
  value_is_output
140
  bind:dragging
141
  bind:active_source
 
160
  file_count={gradio.props.file_count}
161
  {sources_string}
162
  max_file_size={gradio.shared.max_file_size}
163
+ onchange={(e) => {
164
+ gradio.props.value = e;
165
+ gradio.dispatch("change", gradio.props.value);
166
+ }}
167
+ oninput={() => gradio.dispatch("input")}
168
+ onsubmit={() => gradio.dispatch("submit")}
169
+ onstop={() => gradio.dispatch("stop")}
170
+ onblur={() => gradio.dispatch("blur")}
171
+ onselect={(e) => gradio.dispatch("select", e)}
172
+ onfocus={() => gradio.dispatch("focus")}
173
+ onerror={(detail) => {
174
  gradio.dispatch("error", detail);
175
  }}
176
+ onstop_recording={() => gradio.dispatch("stop_recording")}
177
+ onupload={(e) => gradio.dispatch("upload", e)}
178
+ onclear={() => gradio.dispatch("clear")}
 
 
179
  disabled={!gradio.shared.interactive}
180
  upload={upload_fn}
181
  stream_handler={stream_handler_fn}
6.5.0/multimodaltextbox/shared/MultimodalTextbox.svelte CHANGED
@@ -1,11 +1,5 @@
1
  <script lang="ts">
2
- import {
3
- onMount,
4
- beforeUpdate,
5
- afterUpdate,
6
- createEventDispatcher,
7
- tick
8
- } from "svelte";
9
  import { text_area_resize, resize } from "../shared/utils";
10
  import { BlockTitle, ScrollFade } from "@gradio/atoms";
11
  import { Upload } from "@gradio/upload";
@@ -25,120 +19,169 @@
25
  Check
26
  } from "@gradio/icons";
27
  import { should_show_scroll_fade, type SelectData } from "@gradio/utils";
28
- import { BaseInteractiveAudio as InteractiveAudio } from "@gradio/audio";
29
  import {
30
  MinimalAudioPlayer,
31
  MinimalAudioRecorder
32
  } from "@gradio/audio/shared";
33
  import type { InputHTMLAttributes } from "./types";
34
 
35
- export let value: { text: string; files: FileData[] } = {
36
- text: "",
37
- files: []
38
- };
39
-
40
- export let value_is_output = false;
41
- export let lines = 1;
42
- export let i18n: I18nFormatter;
43
- export let placeholder = "";
44
- export let disabled = false;
45
- export let label: string;
46
- export let info: string | undefined = undefined;
47
- export let show_label = true;
48
- export let max_lines: number;
49
- export let submit_btn: string | boolean | null = null;
50
- export let stop_btn: string | boolean | null = null;
51
- export let rtl = false;
52
- export let autofocus = false;
53
- export let text_align: "left" | "right" | undefined = undefined;
54
- export let autoscroll = true;
55
- export let root: string;
56
- export let file_types_string: string | null = null;
57
- export let max_file_size: number | null = null;
58
- export let upload: Client["upload"];
59
- export let stream_handler: Client["stream"];
60
- export let file_count: "single" | "multiple" | "directory" = "multiple";
61
- export let max_plain_text_length = 1000;
62
- export let waveform_settings: Record<string, any>;
63
- export let waveform_options: WaveformOptions = {
64
- show_recording_waveform: true
65
- };
66
- export let sources_string:
67
- | "upload"
68
- | "upload,microphone"
69
- | "microphone"
70
- | "microphone,upload" = "upload";
71
- export let active_source: "microphone" | null = null;
72
- export let html_attributes: InputHTMLAttributes | null = null;
73
- export let upload_promise: Promise<any> | null = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  let upload_component: Upload;
76
  let el: HTMLTextAreaElement | HTMLInputElement;
77
- let can_scroll: boolean;
78
- let previous_scroll_top = 0;
79
- let user_has_scrolled_up = false;
80
- let show_fade = false;
81
- export let dragging = false;
82
- let uploading = false;
83
- // value can be null in multimodalchatinterface when loading a deep link
84
- let oldValue = value?.text ?? "";
85
- let recording = false;
86
-
87
- $: sources = sources_string
88
- .split(",")
89
- .map((s) => s.trim())
90
- .filter((s) => s === "upload" || s === "microphone") as (
91
- | "upload"
92
- | "microphone"
93
- )[];
94
- $: file_types = file_types_string
95
- ? file_types_string.split(",").map((s) => s.trim())
96
- : null;
97
- $: dispatch("drag", dragging);
98
- $: show_upload =
99
- sources &&
100
- sources.includes("upload") &&
101
- !(file_count === "single" && value.files.length > 0);
102
- let mic_audio: FileData | null = null;
103
-
104
  let full_container: HTMLDivElement;
105
 
106
- $: if (oldValue !== value.text) {
107
- dispatch("change", value);
108
- oldValue = value.text;
109
- }
110
-
111
- $: if (value === null) value = { text: "", files: [] };
112
- $: (value, el && lines !== max_lines && resize(el, lines, max_lines));
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  function update_fade(): void {
115
  show_fade = should_show_scroll_fade(el);
116
  }
117
 
118
- $: if (el && value.text !== undefined) {
119
- tick().then(update_fade);
120
- }
121
-
122
- const dispatch = createEventDispatcher<{
123
- change: typeof value;
124
- submit: undefined;
125
- stop: undefined;
126
- blur: undefined;
127
- select: SelectData;
128
- input: undefined;
129
- focus: undefined;
130
- drag: boolean;
131
- upload: FileData[] | FileData;
132
- clear: undefined;
133
- load: FileData[] | FileData;
134
- error: string;
135
- start_recording: undefined;
136
- pause_recording: undefined;
137
- stop_recording: undefined;
138
- }>();
139
-
140
- beforeUpdate(() => {
141
- can_scroll = el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100;
 
 
 
142
  });
143
 
144
  const scroll = (): void => {
@@ -148,28 +191,24 @@
148
  };
149
 
150
  async function handle_change(): Promise<void> {
151
- dispatch("change", value);
152
  if (!value_is_output) {
153
- dispatch("input");
154
  }
155
  }
156
 
157
- onMount(() => {
158
- if (autofocus && el !== null) {
 
159
  el.focus();
160
  }
161
  });
162
 
163
- const after_update = (): void => {
164
  if (can_scroll && autoscroll) {
165
  scroll();
166
  }
167
- if (autofocus && el) {
168
- el.focus();
169
- }
170
- };
171
-
172
- afterUpdate(after_update);
173
 
174
  function handle_select(event: Event): void {
175
  const target: HTMLTextAreaElement | HTMLInputElement = event.target as
@@ -180,14 +219,14 @@
180
  target.selectionStart as number,
181
  target.selectionEnd as number
182
  ];
183
- dispatch("select", { value: text.substring(...index), index: index });
184
  }
185
 
186
  async function handle_keypress(e: KeyboardEvent): Promise<void> {
187
  if (e.key === "Enter" && e.shiftKey && lines > 1) {
188
  e.preventDefault();
189
  await tick();
190
- dispatch("submit");
191
  } else if (
192
  e.key === "Enter" &&
193
  !e.shiftKey &&
@@ -198,7 +237,7 @@
198
  add_mic_audio_to_files();
199
  active_source = null;
200
  await tick();
201
- dispatch("submit");
202
  }
203
  }
204
 
@@ -230,8 +269,8 @@
230
  value = value;
231
  }
232
  await tick();
233
- dispatch("change", value);
234
- dispatch("upload", detail);
235
  }
236
 
237
  function remove_thumbnail(event: MouseEvent, index: number): void {
@@ -246,7 +285,7 @@
246
  }
247
 
248
  function handle_stop(): void {
249
- dispatch("stop");
250
  }
251
 
252
  function add_mic_audio_to_files(): void {
@@ -254,14 +293,14 @@
254
  value.files.push(mic_audio);
255
  value = value;
256
  mic_audio = null;
257
- dispatch("change", value);
258
  }
259
  }
260
 
261
  function handle_submit(): void {
262
  add_mic_audio_to_files();
263
  active_source = null;
264
- dispatch("submit");
265
  }
266
 
267
  async function handle_paste(event: ClipboardEvent): Promise<void> {
@@ -327,8 +366,7 @@
327
 
328
  const invalid_files = files.length - valid_files.length;
329
  if (invalid_files > 0) {
330
- dispatch(
331
- "error",
332
  `${invalid_files} file(s) were rejected. Accepted formats: ${file_types.join(", ")}`
333
  );
334
  }
@@ -347,10 +385,10 @@
347
  class="full-container"
348
  class:dragging
349
  bind:this={full_container}
350
- on:dragenter={handle_dragenter}
351
- on:dragleave={handle_dragleave}
352
- on:dragover|preventDefault
353
- on:drop={handle_drop}
354
  role="group"
355
  aria-label="Multimedia input field"
356
  >
@@ -368,17 +406,18 @@
368
  {root}
369
  {max_file_size}
370
  bind:upload_promise
371
- onchange={(value) => {
372
- mic_audio = value;
373
  }}
374
  onstoprecording={() => {
375
  recording = false;
376
- dispatch("stop_recording");
377
  }}
378
  onclear={() => {
379
  active_source = null;
380
  recording = false;
381
  mic_audio = null;
 
382
  }}
383
  />
384
  </div>
@@ -392,7 +431,7 @@
392
  <div class="action-buttons">
393
  <button
394
  class="confirm-button"
395
- on:click={() => {
396
  add_mic_audio_to_files();
397
  active_source = null;
398
  recording = false;
@@ -403,7 +442,7 @@
403
  </button>
404
  <button
405
  class="cancel-button"
406
- on:click={() => {
407
  active_source = null;
408
  recording = false;
409
  mic_audio = null;
@@ -430,7 +469,7 @@
430
  bind:uploading
431
  show_progress={false}
432
  disable_click={true}
433
- onerror={(e) => dispatch("error", e)}
434
  hidden={true}
435
  {upload}
436
  {stream_handler}
@@ -439,9 +478,9 @@
439
 
440
  <div
441
  class="input-wrapper"
442
- class:has-files={value.files.length > 0 || uploading}
443
  >
444
- {#if value.files.length > 0 || uploading}
445
  <div
446
  class="thumbnails"
447
  aria-label="Uploaded files"
@@ -452,13 +491,13 @@
452
  data-testid="upload-button"
453
  class="upload-button thumbnail-add"
454
  {disabled}
455
- on:click={handle_upload_click}
456
  aria-label="Upload a file"
457
  >
458
  <Paperclip />
459
  </button>
460
  {/if}
461
- {#each value.files as file, index}
462
  <span
463
  class="thumbnail-wrapper"
464
  role="listitem"
@@ -484,7 +523,7 @@
484
  {/if}
485
  <button
486
  class="delete-button"
487
- on:click={(event) => remove_thumbnail(event, index)}
488
  aria-label="Remove file"
489
  >
490
  <Clear />
@@ -499,12 +538,12 @@
499
  {/if}
500
 
501
  <div class="input-row">
502
- {#if show_upload && value.files.length === 0 && !uploading}
503
  <button
504
  data-testid="upload-button"
505
  class="upload-button icon-button"
506
  {disabled}
507
- on:click={handle_upload_click}
508
  aria-label="Upload a file"
509
  >
510
  <Paperclip />
@@ -525,12 +564,12 @@
525
  {placeholder}
526
  rows={lines}
527
  {disabled}
528
- on:keypress={handle_keypress}
529
- on:blur
530
- on:select={handle_select}
531
- on:focus
532
- on:scroll={handle_scroll}
533
- on:paste={handle_paste}
534
  style={text_align ? "text-align: " + text_align : ""}
535
  autocapitalize={html_attributes?.autocapitalize}
536
  autocorrect={html_attributes?.autocorrect}
@@ -549,7 +588,7 @@
549
  class="microphone-button"
550
  class:recording
551
  {disabled}
552
- on:click={async () => {
553
  if (active_source !== "microphone") {
554
  active_source = "microphone";
555
  await tick();
@@ -571,7 +610,7 @@
571
  data-testid="submit-button"
572
  class:padded-button={submit_btn !== true}
573
  {disabled}
574
- on:click={handle_submit}
575
  aria-label="Submit"
576
  >
577
  {#if submit_btn === true}
@@ -585,7 +624,7 @@
585
  <button
586
  class="stop-button"
587
  class:padded-button={stop_btn !== true}
588
- on:click={handle_stop}
589
  aria-label="Stop"
590
  >
591
  {#if stop_btn === true}
 
1
  <script lang="ts">
2
+ import { tick } from "svelte";
 
 
 
 
 
 
3
  import { text_area_resize, resize } from "../shared/utils";
4
  import { BlockTitle, ScrollFade } from "@gradio/atoms";
5
  import { Upload } from "@gradio/upload";
 
19
  Check
20
  } from "@gradio/icons";
21
  import { should_show_scroll_fade, type SelectData } from "@gradio/utils";
 
22
  import {
23
  MinimalAudioPlayer,
24
  MinimalAudioRecorder
25
  } from "@gradio/audio/shared";
26
  import type { InputHTMLAttributes } from "./types";
27
 
28
+ let {
29
+ value = $bindable(),
30
+ value_is_output = false,
31
+ lines = 1,
32
+ i18n: _i18n,
33
+ placeholder = "",
34
+ disabled = false,
35
+ label,
36
+ info = undefined,
37
+ show_label = true,
38
+ max_lines,
39
+ submit_btn = null,
40
+ stop_btn = null,
41
+ rtl = false,
42
+ autofocus = false,
43
+ text_align = undefined,
44
+ autoscroll = true,
45
+ root,
46
+ file_types_string = null,
47
+ max_file_size = null,
48
+ upload,
49
+ stream_handler,
50
+ file_count = "multiple",
51
+ max_plain_text_length = 1000,
52
+ waveform_settings,
53
+ waveform_options: _waveform_options = { show_recording_waveform: true },
54
+ sources_string = "upload",
55
+ active_source = $bindable<"microphone" | null>(),
56
+ html_attributes = null,
57
+ upload_promise = $bindable<Promise<any> | null>(),
58
+ dragging = $bindable<boolean>(),
59
+ onchange,
60
+ onsubmit,
61
+ onstop,
62
+ onblur,
63
+ onselect,
64
+ oninput,
65
+ onfocus,
66
+ ondrag,
67
+ onupload,
68
+ onclear,
69
+ onload: _onload,
70
+ onerror,
71
+ onstop_recording
72
+ }: {
73
+ value?: { text: string; files: FileData[] };
74
+ value_is_output?: boolean;
75
+ lines?: number;
76
+ i18n: I18nFormatter;
77
+ placeholder?: string;
78
+ disabled?: boolean;
79
+ label: string;
80
+ info?: string | undefined;
81
+ show_label?: boolean;
82
+ max_lines: number;
83
+ submit_btn?: string | boolean | null;
84
+ stop_btn?: string | boolean | null;
85
+ rtl?: boolean;
86
+ autofocus?: boolean;
87
+ text_align?: "left" | "right" | undefined;
88
+ autoscroll?: boolean;
89
+ root: string;
90
+ file_types_string?: string | null;
91
+ max_file_size?: number | null;
92
+ upload: Client["upload"];
93
+ stream_handler: Client["stream"];
94
+ file_count?: "single" | "multiple" | "directory";
95
+ max_plain_text_length?: number;
96
+ waveform_settings: Record<string, any>;
97
+ waveform_options?: WaveformOptions;
98
+ sources_string?:
99
+ | "upload"
100
+ | "upload,microphone"
101
+ | "microphone"
102
+ | "microphone,upload";
103
+ active_source?: "microphone" | null;
104
+ html_attributes?: InputHTMLAttributes | null;
105
+ upload_promise?: Promise<any> | null;
106
+ dragging?: boolean;
107
+ onchange?: (value: { text: string; files: FileData[] }) => void;
108
+ onsubmit?: () => void;
109
+ onstop?: () => void;
110
+ onblur?: () => void;
111
+ onselect?: (data: SelectData) => void;
112
+ oninput?: () => void;
113
+ onfocus?: () => void;
114
+ ondrag?: (dragging: boolean) => void;
115
+ onupload?: (files: FileData[] | FileData) => void;
116
+ onclear?: () => void;
117
+ onload?: (files: FileData[] | FileData) => void;
118
+ onerror?: (error: string) => void;
119
+ onstop_recording?: () => void;
120
+ } = $props();
121
 
122
  let upload_component: Upload;
123
  let el: HTMLTextAreaElement | HTMLInputElement;
124
+ let can_scroll = $state(false);
125
+ let previous_scroll_top = $state(0);
126
+ let user_has_scrolled_up = $state(false);
127
+ let show_fade = $state(false);
128
+ let uploading = $state(false);
129
+ let oldValue = $state(value?.text ?? "");
130
+ let recording = $state(false);
131
+ let mic_audio = $state<FileData | null>(null);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  let full_container: HTMLDivElement;
133
 
134
+ let sources = $derived(
135
+ sources_string
136
+ .split(",")
137
+ .map((s) => s.trim())
138
+ .filter((s) => s === "upload" || s === "microphone") as (
139
+ | "upload"
140
+ | "microphone"
141
+ )[]
142
+ );
143
+
144
+ let file_types = $derived(
145
+ file_types_string ? file_types_string.split(",").map((s) => s.trim()) : null
146
+ );
147
+
148
+ let show_upload = $derived(
149
+ sources &&
150
+ sources.includes("upload") &&
151
+ !(file_count === "single" && value?.files?.length > 0)
152
+ );
153
 
154
  function update_fade(): void {
155
  show_fade = should_show_scroll_fade(el);
156
  }
157
 
158
+ $effect(() => {
159
+ if (el && value?.text !== undefined) {
160
+ tick().then(update_fade);
161
+ }
162
+ });
163
+
164
+ $effect(() => {
165
+ ondrag?.(dragging);
166
+ });
167
+
168
+ $effect(() => {
169
+ if (value && oldValue !== value.text) {
170
+ onchange?.(value);
171
+ oldValue = value.text;
172
+ }
173
+ });
174
+
175
+ $effect(() => {
176
+ if (el && lines !== max_lines) {
177
+ resize(el, lines, max_lines);
178
+ }
179
+ });
180
+
181
+ $effect.pre(() => {
182
+ if (el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100) {
183
+ can_scroll = true;
184
+ }
185
  });
186
 
187
  const scroll = (): void => {
 
191
  };
192
 
193
  async function handle_change(): Promise<void> {
194
+ onchange?.(value);
195
  if (!value_is_output) {
196
+ oninput?.();
197
  }
198
  }
199
 
200
+ $effect(() => {
201
+ value;
202
+ if (autofocus && el) {
203
  el.focus();
204
  }
205
  });
206
 
207
+ $effect(() => {
208
  if (can_scroll && autoscroll) {
209
  scroll();
210
  }
211
+ });
 
 
 
 
 
212
 
213
  function handle_select(event: Event): void {
214
  const target: HTMLTextAreaElement | HTMLInputElement = event.target as
 
219
  target.selectionStart as number,
220
  target.selectionEnd as number
221
  ];
222
+ onselect?.({ value: text.substring(...index), index: index });
223
  }
224
 
225
  async function handle_keypress(e: KeyboardEvent): Promise<void> {
226
  if (e.key === "Enter" && e.shiftKey && lines > 1) {
227
  e.preventDefault();
228
  await tick();
229
+ onsubmit?.();
230
  } else if (
231
  e.key === "Enter" &&
232
  !e.shiftKey &&
 
237
  add_mic_audio_to_files();
238
  active_source = null;
239
  await tick();
240
+ onsubmit?.();
241
  }
242
  }
243
 
 
269
  value = value;
270
  }
271
  await tick();
272
+ onchange?.(value);
273
+ onupload?.(detail);
274
  }
275
 
276
  function remove_thumbnail(event: MouseEvent, index: number): void {
 
285
  }
286
 
287
  function handle_stop(): void {
288
+ onstop?.();
289
  }
290
 
291
  function add_mic_audio_to_files(): void {
 
293
  value.files.push(mic_audio);
294
  value = value;
295
  mic_audio = null;
296
+ onchange?.(value);
297
  }
298
  }
299
 
300
  function handle_submit(): void {
301
  add_mic_audio_to_files();
302
  active_source = null;
303
+ onsubmit?.();
304
  }
305
 
306
  async function handle_paste(event: ClipboardEvent): Promise<void> {
 
366
 
367
  const invalid_files = files.length - valid_files.length;
368
  if (invalid_files > 0) {
369
+ onerror?.(
 
370
  `${invalid_files} file(s) were rejected. Accepted formats: ${file_types.join(", ")}`
371
  );
372
  }
 
385
  class="full-container"
386
  class:dragging
387
  bind:this={full_container}
388
+ ondragenter={handle_dragenter}
389
+ ondragleave={handle_dragleave}
390
+ ondragover={(e) => e.preventDefault()}
391
+ ondrop={handle_drop}
392
  role="group"
393
  aria-label="Multimedia input field"
394
  >
 
406
  {root}
407
  {max_file_size}
408
  bind:upload_promise
409
+ onchange={(audio_value) => {
410
+ mic_audio = audio_value;
411
  }}
412
  onstoprecording={() => {
413
  recording = false;
414
+ onstop_recording?.();
415
  }}
416
  onclear={() => {
417
  active_source = null;
418
  recording = false;
419
  mic_audio = null;
420
+ onclear?.();
421
  }}
422
  />
423
  </div>
 
431
  <div class="action-buttons">
432
  <button
433
  class="confirm-button"
434
+ onclick={() => {
435
  add_mic_audio_to_files();
436
  active_source = null;
437
  recording = false;
 
442
  </button>
443
  <button
444
  class="cancel-button"
445
+ onclick={() => {
446
  active_source = null;
447
  recording = false;
448
  mic_audio = null;
 
469
  bind:uploading
470
  show_progress={false}
471
  disable_click={true}
472
+ {onerror}
473
  hidden={true}
474
  {upload}
475
  {stream_handler}
 
478
 
479
  <div
480
  class="input-wrapper"
481
+ class:has-files={(value?.files?.length ?? 0) > 0 || uploading}
482
  >
483
+ {#if (value?.files?.length ?? 0) > 0 || uploading}
484
  <div
485
  class="thumbnails"
486
  aria-label="Uploaded files"
 
491
  data-testid="upload-button"
492
  class="upload-button thumbnail-add"
493
  {disabled}
494
+ onclick={handle_upload_click}
495
  aria-label="Upload a file"
496
  >
497
  <Paperclip />
498
  </button>
499
  {/if}
500
+ {#each value?.files ?? [] as file, index}
501
  <span
502
  class="thumbnail-wrapper"
503
  role="listitem"
 
523
  {/if}
524
  <button
525
  class="delete-button"
526
+ onclick={(event) => remove_thumbnail(event, index)}
527
  aria-label="Remove file"
528
  >
529
  <Clear />
 
538
  {/if}
539
 
540
  <div class="input-row">
541
+ {#if show_upload && (value?.files?.length ?? 0) === 0 && !uploading}
542
  <button
543
  data-testid="upload-button"
544
  class="upload-button icon-button"
545
  {disabled}
546
+ onclick={handle_upload_click}
547
  aria-label="Upload a file"
548
  >
549
  <Paperclip />
 
564
  {placeholder}
565
  rows={lines}
566
  {disabled}
567
+ onkeypress={handle_keypress}
568
+ onblur={() => onblur?.()}
569
+ onselect={handle_select}
570
+ onfocus={() => onfocus?.()}
571
+ onscroll={handle_scroll}
572
+ onpaste={handle_paste}
573
  style={text_align ? "text-align: " + text_align : ""}
574
  autocapitalize={html_attributes?.autocapitalize}
575
  autocorrect={html_attributes?.autocorrect}
 
588
  class="microphone-button"
589
  class:recording
590
  {disabled}
591
+ onclick={async () => {
592
  if (active_source !== "microphone") {
593
  active_source = "microphone";
594
  await tick();
 
610
  data-testid="submit-button"
611
  class:padded-button={submit_btn !== true}
612
  {disabled}
613
+ onclick={handle_submit}
614
  aria-label="Submit"
615
  >
616
  {#if submit_btn === true}
 
624
  <button
625
  class="stop-button"
626
  class:padded-button={stop_btn !== true}
627
+ onclick={handle_stop}
628
  aria-label="Stop"
629
  >
630
  {#if stop_btn === true}
6.5.0/multimodaltextbox/shared/types.ts CHANGED
@@ -1 +1 @@
1
- export type { InputHTMLAttributes } from "../../textbox/shared/types";
 
1
+ export type { InputHTMLAttributes } from "../../textbox/types";
6.5.0/multimodaltextbox/types.ts CHANGED
@@ -14,8 +14,6 @@ export interface MultimodalTextboxEvents {
14
  focus: never;
15
  error: string;
16
  clear_status: LoadingStatus;
17
- start_recording: never;
18
- pause_recording: never;
19
  stop_recording: never;
20
  upload: FileData[] | FileData;
21
  clear: undefined;
 
14
  focus: never;
15
  error: string;
16
  clear_status: LoadingStatus;
 
 
17
  stop_recording: never;
18
  upload: FileData[] | FileData;
19
  clear: undefined;