gradio-pr-bot commited on
Commit
92386aa
·
verified ·
1 Parent(s): 35d8011

Upload folder using huggingface_hub

Browse files
6.9.0/multimodaltextbox/Example.svelte ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 {
20
+ element.style.setProperty(
21
+ "--local-text-width",
22
+ `${el_width && el_width < 150 ? el_width : 200}px`
23
+ );
24
+ element.style.whiteSpace = "unset";
25
+ }
26
+
27
+ $effect(() => {
28
+ if (el && size) {
29
+ set_styles(el, size);
30
+ }
31
+ });
32
+ </script>
33
+
34
+ <div
35
+ class="container"
36
+ bind:clientWidth={size}
37
+ bind:this={el}
38
+ class:table={type === "table"}
39
+ class:gallery={type === "gallery"}
40
+ class:selected
41
+ class:border={value}
42
+ >
43
+ <p>{value.text ? value.text : ""}</p>
44
+ {#each value.files as file}
45
+ {#if file.mime_type && file.mime_type.includes("image")}
46
+ <Image src={file.url} alt="" />
47
+ {:else if file.mime_type && file.mime_type.includes("video")}
48
+ <Video src={file.url} alt="" loop={true} is_stream={false} />
49
+ {:else if file.mime_type && file.mime_type.includes("audio")}
50
+ <audio src={file.url} controls />
51
+ {:else}
52
+ {file.orig_name}
53
+ {/if}
54
+ {/each}
55
+ </div>
56
+
57
+ <style>
58
+ .gallery {
59
+ padding: var(--size-1) var(--size-2);
60
+ display: flex;
61
+ align-items: center;
62
+ gap: 20px;
63
+ overflow-x: auto;
64
+ }
65
+
66
+ div {
67
+ overflow: hidden;
68
+ min-width: var(--local-text-width);
69
+ white-space: nowrap;
70
+ }
71
+
72
+ .container :global(img),
73
+ .container :global(video) {
74
+ object-fit: contain;
75
+ width: 100px;
76
+ height: 100px;
77
+ }
78
+
79
+ .container.selected {
80
+ border-color: var(--border-color-accent);
81
+ }
82
+ .border.table {
83
+ border: 2px solid var(--border-color-primary);
84
+ }
85
+
86
+ .container.table {
87
+ margin: 0 auto;
88
+ border-radius: var(--radius-lg);
89
+ overflow-x: auto;
90
+ width: max-content;
91
+ height: max-content;
92
+ object-fit: cover;
93
+ padding: var(--size-2);
94
+ }
95
+
96
+ .container.gallery {
97
+ object-fit: cover;
98
+ }
99
+
100
+ div > :global(p) {
101
+ font-size: var(--text-lg);
102
+ white-space: normal;
103
+ }
104
+ </style>
6.9.0/multimodaltextbox/Index.svelte ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as BaseMultimodalTextbox } from "./shared/MultimodalTextbox.svelte";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { Gradio, type SelectData } from "@gradio/utils";
10
+ import MultimodalTextbox from "./shared/MultimodalTextbox.svelte";
11
+ import { Block } from "@gradio/atoms";
12
+ import { StatusTracker } from "@gradio/statustracker";
13
+ import { onMount, tick } from "svelte";
14
+ import type { WaveformOptions } from "../audio/shared/types";
15
+ import type {
16
+ MultimodalTextboxProps,
17
+ MultimodalTextboxEvents
18
+ } from "./types";
19
+
20
+ let upload_promise = $state<Promise<any> | null>(null);
21
+
22
+ class MultimodalTextboxGradio extends Gradio<
23
+ MultimodalTextboxEvents,
24
+ MultimodalTextboxProps
25
+ > {
26
+ async get_data() {
27
+ if (upload_promise) {
28
+ await upload_promise;
29
+ await tick();
30
+ }
31
+ const data = await super.get_data();
32
+
33
+ return data;
34
+ }
35
+ }
36
+
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);
44
+
45
+ let color_accent = "darkorange";
46
+
47
+ const waveform_settings = {
48
+ height: 50,
49
+ barWidth: 2,
50
+ barGap: 3,
51
+ cursorWidth: 2,
52
+ cursorColor: "#ddd5e9",
53
+ autoplay: false,
54
+ barRadius: 10,
55
+ dragToSeek: true,
56
+ normalize: true,
57
+ minPxPerSec: 20,
58
+ waveColor: "",
59
+ progressColor: "",
60
+ mediaControls: false as boolean | undefined,
61
+ sampleRate: 44100
62
+ };
63
+
64
+ onMount(() => {
65
+ color_accent = getComputedStyle(document?.documentElement).getPropertyValue(
66
+ "--color-accent"
67
+ );
68
+ set_trim_region_colour();
69
+ waveform_settings.waveColor =
70
+ gradio.props?.waveform_options?.waveform_color || "#9ca3af";
71
+ waveform_settings.progressColor =
72
+ gradio.props?.waveform_options?.waveform_progress_color || color_accent;
73
+ waveform_settings.mediaControls =
74
+ gradio.props?.waveform_options?.show_controls;
75
+ waveform_settings.sampleRate =
76
+ gradio.props?.waveform_options?.sample_rate || 44100;
77
+ });
78
+
79
+ const trim_region_settings = {
80
+ color: gradio.props?.waveform_options?.trim_region_color,
81
+ drag: true,
82
+ resize: true
83
+ };
84
+
85
+ function set_trim_region_colour(): void {
86
+ document.documentElement.style.setProperty(
87
+ "--trim-region-color",
88
+ trim_region_settings.color || color_accent
89
+ );
90
+ }
91
+
92
+ // Create const references to the callbacks so that afterUpdate in child is not called on every prop change
93
+ // in the DOM. See https://github.com/gradio-app/gradio/issues/11933
94
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
95
+ const upload_fn = (...args: Parameters<typeof gradio.shared.client.upload>) =>
96
+ gradio.shared.client.upload(...args);
97
+ const i18n = (s: string | null | undefined): string => gradio.i18n(s);
98
+ const stream_handler_fn = (
99
+ ...args: Parameters<typeof gradio.shared.client.stream>
100
+ ): EventSource => gradio.shared.client.stream(...args);
101
+
102
+ let sources_string = $derived(
103
+ gradio.props.sources.join(",") as
104
+ | "upload"
105
+ | "upload,microphone"
106
+ | "microphone"
107
+ | "microphone,upload"
108
+ );
109
+
110
+ let file_types_string = $derived.by(
111
+ () => (gradio.props.file_types || []).join(",") || null
112
+ );
113
+ </script>
114
+
115
+ <Block
116
+ visible={gradio.shared.visible}
117
+ elem_id={gradio.shared.elem_id}
118
+ elem_classes={[...(gradio.shared.elem_classes || []), "multimodal-textbox"]}
119
+ scale={gradio.shared.scale}
120
+ min_width={gradio.shared.min_width}
121
+ allow_overflow={false}
122
+ padding={false}
123
+ border_mode={dragging ? "focus" : "base"}
124
+ rtl={gradio.props.rtl}
125
+ >
126
+ {#if gradio.shared.loading_status}
127
+ <StatusTracker
128
+ autoscroll={gradio.shared.autoscroll}
129
+ i18n={gradio.i18n}
130
+ {...gradio.shared.loading_status}
131
+ on_clear_status={() =>
132
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
133
+ />
134
+ {/if}
135
+
136
+ <MultimodalTextbox
137
+ bind:upload_promise
138
+ bind:value={gradio.props.value}
139
+ value_is_output
140
+ bind:dragging
141
+ bind:active_source
142
+ {file_types_string}
143
+ root={gradio.shared.root}
144
+ label={gradio.shared.label || "MultimodalTextbox"}
145
+ info={gradio.props.info}
146
+ show_label={gradio.shared.show_label}
147
+ lines={gradio.props.lines}
148
+ rtl={gradio.props.rtl}
149
+ text_align={gradio.props.text_align}
150
+ waveform_settings={waveform_settings as WaveformOptions}
151
+ {i18n}
152
+ max_lines={!gradio.props.max_lines
153
+ ? gradio.props.lines + 1
154
+ : gradio.props.max_lines}
155
+ placeholder={gradio.props.placeholder}
156
+ submit_btn={gradio.props.submit_btn}
157
+ stop_btn={gradio.props.stop_btn}
158
+ autofocus={gradio.props.autofocus}
159
+ autoscroll={gradio.shared.autoscroll}
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}
182
+ max_plain_text_length={gradio.props.max_plain_text_length}
183
+ html_attributes={gradio.props.html_attributes}
184
+ />
185
+ </Block>
6.9.0/multimodaltextbox/package.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/multimodaltextbox",
3
+ "version": "0.11.7",
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
+ "@gradio/upload": "workspace:^",
30
+ "@gradio/image": "workspace:^",
31
+ "@gradio/video": "workspace:^",
32
+ "@gradio/client": "workspace:^",
33
+ "@gradio/audio": "workspace:^"
34
+ },
35
+ "devDependencies": {
36
+ "@gradio/preview": "workspace:^"
37
+ },
38
+ "peerDependencies": {
39
+ "svelte": "^5.48.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/gradio-app/gradio.git",
44
+ "directory": "js/multimodaltextbox"
45
+ }
46
+ }
6.9.0/multimodaltextbox/shared/MultimodalTextbox.svelte ADDED
@@ -0,0 +1,1070 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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";
6
+ import { Image } from "@gradio/image/shared";
7
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
8
+ import type { FileData, Client } from "@gradio/client";
9
+ import type { WaveformOptions } from "@gradio/audio";
10
+ import {
11
+ Clear,
12
+ File,
13
+ Music,
14
+ Paperclip,
15
+ Video,
16
+ ArrowUp,
17
+ Square,
18
+ Microphone,
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 => {
188
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
189
+ el.scrollTo(0, el.scrollHeight);
190
+ }
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
215
+ | HTMLTextAreaElement
216
+ | HTMLInputElement;
217
+ const text = target.value;
218
+ const index: [number, number] = [
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 &&
233
+ lines === 1 &&
234
+ max_lines >= 1
235
+ ) {
236
+ e.preventDefault();
237
+ add_mic_audio_to_files();
238
+ active_source = null;
239
+ await tick();
240
+ onsubmit?.();
241
+ }
242
+ }
243
+
244
+ function handle_scroll(event: Event): void {
245
+ const target = event.target as HTMLElement;
246
+ const current_scroll_top = target.scrollTop;
247
+ if (current_scroll_top < previous_scroll_top) {
248
+ user_has_scrolled_up = true;
249
+ }
250
+ previous_scroll_top = current_scroll_top;
251
+
252
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
253
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
254
+ if (user_has_scrolled_to_bottom) {
255
+ user_has_scrolled_up = false;
256
+ }
257
+ update_fade();
258
+ }
259
+
260
+ async function handle_upload(detail: FileData | FileData[]): Promise<void> {
261
+ handle_change();
262
+ if (Array.isArray(detail)) {
263
+ for (let file of detail) {
264
+ value.files.push(file);
265
+ }
266
+ value = value;
267
+ } else {
268
+ value.files.push(detail);
269
+ value = value;
270
+ }
271
+ await tick();
272
+ onchange?.(value);
273
+ onupload?.(detail);
274
+ }
275
+
276
+ function remove_thumbnail(event: MouseEvent, index: number): void {
277
+ handle_change();
278
+ event.stopPropagation();
279
+ value.files.splice(index, 1);
280
+ value = value;
281
+ }
282
+
283
+ function handle_upload_click(): void {
284
+ upload_component.open_upload();
285
+ }
286
+
287
+ function handle_stop(): void {
288
+ onstop?.();
289
+ }
290
+
291
+ function add_mic_audio_to_files(): void {
292
+ if (mic_audio) {
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> {
307
+ if (!event.clipboardData) return;
308
+ const items = event.clipboardData.items;
309
+ const text = event.clipboardData.getData("text");
310
+
311
+ if (text && text.length > max_plain_text_length) {
312
+ event.preventDefault();
313
+ const file = new window.File([text], "pasted_text.txt", {
314
+ type: "text/plain",
315
+ lastModified: Date.now()
316
+ });
317
+ if (upload_component) {
318
+ upload_component.load_files([file]);
319
+ }
320
+ return;
321
+ }
322
+
323
+ for (let index in items) {
324
+ const item = items[index];
325
+ if (item.kind === "file" && item.type.includes("image")) {
326
+ const blob = item.getAsFile();
327
+ if (blob) upload_component.load_files([blob]);
328
+ }
329
+ }
330
+ }
331
+
332
+ function handle_dragenter(event: DragEvent): void {
333
+ event.preventDefault();
334
+ dragging = true;
335
+ }
336
+
337
+ function handle_dragleave(event: DragEvent): void {
338
+ event.preventDefault();
339
+ const rect = full_container.getBoundingClientRect();
340
+ const { clientX, clientY } = event;
341
+ if (
342
+ clientX <= rect.left ||
343
+ clientX >= rect.right ||
344
+ clientY <= rect.top ||
345
+ clientY >= rect.bottom
346
+ ) {
347
+ dragging = false;
348
+ }
349
+ }
350
+
351
+ function handle_drop(event: DragEvent): void {
352
+ event.preventDefault();
353
+ dragging = false;
354
+ if (event.dataTransfer && event.dataTransfer.files) {
355
+ const files = Array.from(event.dataTransfer.files);
356
+
357
+ if (file_types) {
358
+ const valid_files = files.filter((file) => {
359
+ return file_types.some((type) => {
360
+ if (type.startsWith(".")) {
361
+ return file.name.toLowerCase().endsWith(type.toLowerCase());
362
+ }
363
+ return file.type.match(new RegExp(type.replace("*", ".*")));
364
+ });
365
+ });
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
+ }
373
+
374
+ if (valid_files.length > 0) {
375
+ upload_component.load_files(valid_files);
376
+ }
377
+ } else {
378
+ upload_component.load_files(files);
379
+ }
380
+ }
381
+ }
382
+ </script>
383
+
384
+ <div
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
+ >
395
+ <BlockTitle {show_label} {info} {rtl}>{label}</BlockTitle>
396
+ <div class="input-container">
397
+ {#if sources && sources.includes("microphone") && active_source === "microphone"}
398
+ <div class="recording-overlay" class:has-audio={mic_audio !== null}>
399
+ {#if !mic_audio}
400
+ <div class="recording-content">
401
+ <MinimalAudioRecorder
402
+ label={label || "Audio"}
403
+ {waveform_settings}
404
+ {recording}
405
+ {upload}
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>
424
+ {:else}
425
+ <div class="recording-content">
426
+ <MinimalAudioPlayer
427
+ value={mic_audio}
428
+ label={label || "Audio"}
429
+ loop={false}
430
+ />
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;
438
+ }}
439
+ aria-label="Attach audio"
440
+ >
441
+ <Check />
442
+ </button>
443
+ <button
444
+ class="cancel-button"
445
+ onclick={() => {
446
+ active_source = null;
447
+ recording = false;
448
+ mic_audio = null;
449
+ }}
450
+ aria-label="Clear audio"
451
+ >
452
+ <Clear />
453
+ </button>
454
+ </div>
455
+ </div>
456
+ {/if}
457
+ </div>
458
+ {/if}
459
+ {#if show_upload}
460
+ <Upload
461
+ bind:upload_promise
462
+ bind:this={upload_component}
463
+ onload={handle_upload}
464
+ {file_count}
465
+ filetype={file_types}
466
+ {root}
467
+ {max_file_size}
468
+ bind:dragging
469
+ bind:uploading
470
+ show_progress={false}
471
+ disable_click={true}
472
+ {onerror}
473
+ hidden={true}
474
+ {upload}
475
+ {stream_handler}
476
+ />
477
+ {/if}
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"
487
+ data-testid="container_el"
488
+ >
489
+ {#if show_upload}
490
+ <button
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"
504
+ aria-label="File thumbnail"
505
+ >
506
+ <div class="thumbnail-item thumbnail-small">
507
+ {#if file.mime_type && file.mime_type.includes("image")}
508
+ <Image
509
+ src={file.url}
510
+ restProps={{
511
+ title: null,
512
+ alt: "",
513
+ loading: "lazy",
514
+ class: "thumbnail-image"
515
+ }}
516
+ />
517
+ {:else if file.mime_type && file.mime_type.includes("audio")}
518
+ <Music />
519
+ {:else if file.mime_type && file.mime_type.includes("video")}
520
+ <Video />
521
+ {:else}
522
+ <File />
523
+ {/if}
524
+ <button
525
+ class="delete-button"
526
+ onclick={(event) => remove_thumbnail(event, index)}
527
+ aria-label="Remove file"
528
+ >
529
+ <Clear />
530
+ </button>
531
+ </div>
532
+ </span>
533
+ {/each}
534
+ {#if uploading}
535
+ <div class="loader" role="status" aria-label="Uploading"></div>
536
+ {/if}
537
+ </div>
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 />
550
+ </button>
551
+ {/if}
552
+ <div class="textarea-wrapper">
553
+ <textarea
554
+ data-testid="textbox"
555
+ use:text_area_resize={{
556
+ text: value.text,
557
+ lines: lines,
558
+ max_lines: max_lines
559
+ }}
560
+ class:no-label={!show_label}
561
+ dir={rtl ? "rtl" : "ltr"}
562
+ bind:value={value.text}
563
+ bind:this={el}
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}
576
+ spellcheck={html_attributes?.spellcheck}
577
+ autocomplete={html_attributes?.autocomplete}
578
+ tabindex={html_attributes?.tabindex}
579
+ enterkeyhint={html_attributes?.enterkeyhint}
580
+ lang={html_attributes?.lang}
581
+ />
582
+ <ScrollFade visible={show_fade} position="absolute" />
583
+ </div>
584
+
585
+ {#if sources && sources.includes("microphone")}
586
+ <button
587
+ data-testid="microphone-button"
588
+ class="microphone-button"
589
+ class:recording
590
+ {disabled}
591
+ onclick={async () => {
592
+ if (active_source !== "microphone") {
593
+ active_source = "microphone";
594
+ await tick();
595
+ recording = true;
596
+ } else {
597
+ active_source = null;
598
+ recording = false;
599
+ }
600
+ }}
601
+ aria-label="Record audio"
602
+ >
603
+ <Microphone />
604
+ </button>
605
+ {/if}
606
+
607
+ {#if submit_btn}
608
+ <button
609
+ class="submit-button"
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}
617
+ <ArrowUp />
618
+ {:else}
619
+ {submit_btn}
620
+ {/if}
621
+ </button>
622
+ {/if}
623
+ {#if stop_btn}
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}
631
+ <Square fill={"none"} stroke_width={2.5} />
632
+ {:else}
633
+ {stop_btn}
634
+ {/if}
635
+ </button>
636
+ {/if}
637
+ </div>
638
+ </div>
639
+ </div>
640
+ </div>
641
+
642
+ <style>
643
+ .full-container {
644
+ width: 100%;
645
+ position: relative;
646
+ padding: var(--block-padding);
647
+ border: 1px solid transparent;
648
+ }
649
+
650
+ .full-container.dragging {
651
+ border-color: var(--color-accent);
652
+ border-radius: calc(var(--radius-sm) - var(--size-px));
653
+ }
654
+
655
+ .full-container.dragging::after {
656
+ content: "";
657
+ position: absolute;
658
+ inset: 0;
659
+ pointer-events: none;
660
+ }
661
+
662
+ .input-container {
663
+ display: flex;
664
+ position: relative;
665
+ flex-direction: column;
666
+ gap: 0;
667
+ }
668
+
669
+ .input-wrapper {
670
+ display: flex;
671
+ position: relative;
672
+ flex-direction: column;
673
+ gap: 0;
674
+ background: var(--block-background-fill);
675
+ border-radius: var(--radius-xl);
676
+ padding: var(--spacing-sm) var(--spacing-sm) var(--spacing-sm) 0;
677
+ align-items: flex-start;
678
+ min-height: auto;
679
+ }
680
+
681
+ .input-wrapper.has-files {
682
+ padding-top: var(--spacing-xs);
683
+ }
684
+
685
+ .input-row {
686
+ display: flex;
687
+ align-items: flex-start;
688
+ gap: var(--spacing-sm);
689
+ width: 100%;
690
+ }
691
+
692
+ .thumbnails {
693
+ display: flex;
694
+ align-items: center;
695
+ gap: var(--spacing-sm);
696
+ padding: var(--spacing-xs) 0;
697
+ margin-bottom: var(--spacing-xs);
698
+ overflow-x: auto;
699
+ overflow-y: hidden;
700
+ scrollbar-width: none;
701
+ -ms-overflow-style: none;
702
+ flex-wrap: nowrap;
703
+ -webkit-overflow-scrolling: touch;
704
+ scroll-behavior: smooth;
705
+ overflow-y: scroll;
706
+ width: 100%;
707
+ }
708
+
709
+ .thumbnails::-webkit-scrollbar,
710
+ .thumbnails::-webkit-scrollbar-track,
711
+ .thumbnails::-webkit-scrollbar-thumb {
712
+ display: none;
713
+ }
714
+
715
+ .thumbnails :global(img) {
716
+ width: var(--size-full);
717
+ height: var(--size-full);
718
+ object-fit: cover;
719
+ border-radius: var(--radius-md);
720
+ }
721
+
722
+ .thumbnail-wrapper {
723
+ position: relative;
724
+ flex-shrink: 0;
725
+ }
726
+
727
+ .thumbnail-item {
728
+ position: relative;
729
+ display: flex;
730
+ justify-content: center;
731
+ align-items: center;
732
+ border-radius: var(--radius-md);
733
+ background: var(--background-fill-secondary);
734
+ width: var(--size-full);
735
+ height: var(--size-full);
736
+ cursor: default;
737
+ padding: 0;
738
+ }
739
+
740
+ .thumbnail-small {
741
+ width: var(--size-10);
742
+ height: var(--size-10);
743
+ }
744
+
745
+ .thumbnail-item :global(svg) {
746
+ width: var(--size-5);
747
+ height: var(--size-5);
748
+ }
749
+
750
+ .delete-button {
751
+ position: absolute;
752
+ inset: 0;
753
+ display: flex;
754
+ justify-content: center;
755
+ align-items: center;
756
+ color: var(--button-primary-text-color);
757
+ background: rgba(0, 0, 0, 0.6);
758
+ backdrop-filter: var(--blur-xs);
759
+ border-radius: var(--radius-md);
760
+ padding: 0;
761
+ z-index: var(--layer-1);
762
+ opacity: 0;
763
+ transition: opacity 0.1s var(--easing-standard);
764
+ }
765
+
766
+ .delete-button:hover {
767
+ background: rgba(0, 0, 0, 0.8);
768
+ }
769
+
770
+ .delete-button :global(svg) {
771
+ width: var(--size-5);
772
+ height: var(--size-5);
773
+ }
774
+
775
+ .thumbnail-item:hover .delete-button {
776
+ opacity: 1;
777
+ }
778
+
779
+ textarea {
780
+ flex-grow: 1;
781
+ outline: none !important;
782
+ background: transparent;
783
+ padding: var(--spacing-sm) 0;
784
+ color: var(--body-text-color);
785
+ font-weight: var(--input-text-weight);
786
+ font-size: var(--input-text-size);
787
+ border: none;
788
+ margin: 0;
789
+ resize: none;
790
+ position: relative;
791
+ z-index: var(--layer-1);
792
+ text-align: left;
793
+ }
794
+
795
+ textarea:disabled {
796
+ -webkit-opacity: 1;
797
+ opacity: 1;
798
+ }
799
+
800
+ textarea::placeholder {
801
+ color: var(--input-placeholder-color);
802
+ }
803
+
804
+ textarea[dir="rtl"] {
805
+ text-align: right;
806
+ }
807
+
808
+ textarea[dir="rtl"] ~ .submit-button :global(svg) {
809
+ transform: scaleX(-1);
810
+ }
811
+
812
+ .microphone-button,
813
+ .icon-button {
814
+ color: var(--body-text-color);
815
+ cursor: pointer;
816
+ padding: var(--spacing-sm);
817
+ display: flex;
818
+ justify-content: center;
819
+ align-items: center;
820
+ flex-shrink: 0;
821
+ border-radius: var(--radius-md);
822
+ }
823
+
824
+ .thumbnail-add {
825
+ background: var(--button-secondary-background-fill);
826
+ cursor: pointer;
827
+ display: flex;
828
+ justify-content: center;
829
+ align-items: center;
830
+ flex-shrink: 0;
831
+ width: var(--size-10);
832
+ height: var(--size-10);
833
+ border-radius: var(--radius-md);
834
+ z-index: var(--layer-1);
835
+ }
836
+
837
+ .thumbnail-add:hover:not(:disabled) {
838
+ background: var(--button-secondary-background-fill-hover);
839
+ }
840
+
841
+ .thumbnail-add:disabled {
842
+ opacity: 0.5;
843
+ cursor: not-allowed;
844
+ }
845
+
846
+ .thumbnail-add :global(svg) {
847
+ width: var(--size-5);
848
+ height: var(--size-5);
849
+ }
850
+
851
+ .microphone-button,
852
+ .icon-button {
853
+ width: var(--size-9);
854
+ height: var(--size-9);
855
+ }
856
+
857
+ .microphone-button:hover:not(:disabled),
858
+ .icon-button:hover:not(:disabled) {
859
+ background: var(--button-secondary-background-fill);
860
+ }
861
+
862
+ .microphone-button:disabled,
863
+ .icon-button:disabled {
864
+ opacity: 0.5;
865
+ cursor: not-allowed;
866
+ }
867
+
868
+ .microphone-button :global(svg),
869
+ .icon-button :global(svg) {
870
+ width: var(--size-5);
871
+ height: var(--size-5);
872
+ }
873
+
874
+ .submit-button,
875
+ .stop-button {
876
+ background: var(--button-secondary-background-fill);
877
+ cursor: pointer;
878
+ display: flex;
879
+ justify-content: center;
880
+ align-items: center;
881
+ flex-shrink: 0;
882
+ width: var(--size-9);
883
+ height: var(--size-9);
884
+ border-radius: var(--radius-md);
885
+ z-index: var(--layer-1);
886
+ }
887
+
888
+ .submit-button:hover:not(:disabled),
889
+ .stop-button:hover:not(:disabled) {
890
+ background: var(--button-secondary-background-fill-hover);
891
+ }
892
+
893
+ .submit-button:active:not(:disabled),
894
+ .stop-button:active:not(:disabled) {
895
+ box-shadow: var(--button-shadow-active);
896
+ }
897
+
898
+ .submit-button:disabled,
899
+ .stop-button:disabled {
900
+ cursor: not-allowed;
901
+ }
902
+
903
+ .submit-button :global(svg),
904
+ .stop-button :global(svg) {
905
+ width: var(--size-5);
906
+ height: var(--size-5);
907
+ }
908
+
909
+ .padded-button {
910
+ padding: 0 var(--spacing-lg);
911
+ width: auto;
912
+ border-radius: var(--radius-xl);
913
+ }
914
+
915
+ .loader {
916
+ display: flex;
917
+ justify-content: center;
918
+ align-items: center;
919
+ position: relative;
920
+ border: var(--size-1) solid var(--border-color-primary);
921
+ border-top-color: var(--color-accent);
922
+ border-radius: var(--radius-100);
923
+ width: var(--size-5);
924
+ height: var(--size-5);
925
+ animation: spin 1s linear infinite;
926
+ flex-shrink: 0;
927
+ }
928
+
929
+ @keyframes spin {
930
+ to {
931
+ transform: rotate(360deg);
932
+ }
933
+ }
934
+
935
+ .recording-overlay {
936
+ position: absolute;
937
+ top: 0;
938
+ left: 0;
939
+ right: 0;
940
+ bottom: 0;
941
+ background: var(--block-background-fill);
942
+ border-radius: var(--radius-xl);
943
+ display: flex;
944
+ align-items: center;
945
+ justify-content: center;
946
+ z-index: var(--layer-5);
947
+ padding: var(--spacing-lg);
948
+ backdrop-filter: blur(8px);
949
+ animation: fadeIn 0.2s var(--easing-standard);
950
+ }
951
+
952
+ @keyframes fadeIn {
953
+ from {
954
+ opacity: 0;
955
+ }
956
+ to {
957
+ opacity: 1;
958
+ }
959
+ }
960
+
961
+ .recording-content {
962
+ display: flex;
963
+ align-items: center;
964
+ gap: var(--spacing-lg);
965
+ width: 100%;
966
+ max-width: 700px;
967
+ }
968
+
969
+ .recording-content :global(.minimal-audio-recorder),
970
+ .recording-content :global(.minimal-audio-player) {
971
+ flex: 1;
972
+ }
973
+
974
+ .action-buttons {
975
+ display: flex;
976
+ align-items: center;
977
+ gap: var(--spacing-sm);
978
+ flex-shrink: 0;
979
+ }
980
+
981
+ .stop-button,
982
+ .confirm-button,
983
+ .cancel-button {
984
+ display: flex;
985
+ align-items: center;
986
+ justify-content: center;
987
+ width: var(--size-9);
988
+ height: var(--size-9);
989
+ padding: 0;
990
+ border-radius: var(--radius-md);
991
+ cursor: pointer;
992
+ flex-shrink: 0;
993
+ }
994
+
995
+ .stop-button {
996
+ background: var(--button-secondary-background-fill);
997
+ border-color: var(--border-color-primary);
998
+ color: var(--error-500);
999
+ }
1000
+
1001
+ .stop-button:hover {
1002
+ background: var(--button-secondary-background-fill-hover);
1003
+ color: var(--error-600);
1004
+ }
1005
+
1006
+ .stop-button:active {
1007
+ transform: scale(0.95);
1008
+ }
1009
+
1010
+ .confirm-button {
1011
+ background: var(--button-primary-background-fill);
1012
+ border-color: var(--button-primary-border-color);
1013
+ color: white;
1014
+ }
1015
+
1016
+ .confirm-button:hover {
1017
+ background: var(--button-primary-background-fill-hover);
1018
+ color: var(--button-primary-text-color-hover);
1019
+ }
1020
+
1021
+ .confirm-button:active {
1022
+ transform: scale(0.95);
1023
+ }
1024
+
1025
+ .cancel-button {
1026
+ background: var(--button-secondary-background-fill);
1027
+ color: var(--body-text-color);
1028
+ }
1029
+
1030
+ .cancel-button:hover {
1031
+ background: var(--button-secondary-background-fill-hover);
1032
+ }
1033
+
1034
+ .stop-button :global(svg),
1035
+ .confirm-button :global(svg),
1036
+ .cancel-button :global(svg) {
1037
+ width: var(--size-5);
1038
+ height: var(--size-5);
1039
+ }
1040
+
1041
+ @media (max-width: 768px) {
1042
+ .input-wrapper {
1043
+ padding: var(--spacing-xs);
1044
+ }
1045
+
1046
+ .thumbnails {
1047
+ padding: var(--spacing-xs) 0;
1048
+ margin-bottom: var(--spacing-md);
1049
+ }
1050
+
1051
+ .thumbnail-small,
1052
+ .thumbnail-add {
1053
+ width: var(--size-9);
1054
+ height: var(--size-9);
1055
+ }
1056
+
1057
+ .thumbnail-item:active .delete-button {
1058
+ opacity: 1;
1059
+ }
1060
+ }
1061
+
1062
+ .textarea-wrapper {
1063
+ position: relative;
1064
+ flex-grow: 1;
1065
+ }
1066
+
1067
+ .textarea-wrapper textarea {
1068
+ width: 100%;
1069
+ }
1070
+ </style>
6.9.0/multimodaltextbox/shared/types.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export type { InputHTMLAttributes } from "../../textbox/types";
6.9.0/multimodaltextbox/shared/utils.ts ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { tick } from "svelte";
2
+
3
+ interface Value {
4
+ lines: number;
5
+ max_lines: number;
6
+ text: string;
7
+ }
8
+
9
+ export async function resize(
10
+ target: HTMLTextAreaElement | HTMLInputElement,
11
+ lines: number,
12
+ max_lines: number
13
+ ): Promise<void> {
14
+ await tick();
15
+ if (lines === max_lines) return;
16
+
17
+ const computed_styles = window.getComputedStyle(target);
18
+ const padding_top = parseFloat(computed_styles.paddingTop);
19
+ const padding_bottom = parseFloat(computed_styles.paddingBottom);
20
+ const line_height = parseFloat(computed_styles.lineHeight);
21
+
22
+ let max =
23
+ max_lines === undefined
24
+ ? false
25
+ : padding_top + padding_bottom + line_height * max_lines;
26
+ let min = padding_top + padding_bottom + lines * line_height;
27
+
28
+ target.style.height = "1px";
29
+
30
+ let scroll_height;
31
+ if (max && target.scrollHeight > max) {
32
+ scroll_height = max;
33
+ } else if (target.scrollHeight < min) {
34
+ scroll_height = min;
35
+ } else {
36
+ scroll_height = target.scrollHeight;
37
+ }
38
+
39
+ target.style.height = `${scroll_height}px`;
40
+ }
41
+
42
+ export function text_area_resize(
43
+ _el: HTMLTextAreaElement,
44
+ _value: Value
45
+ ): any | undefined {
46
+ if (_value.lines === _value.max_lines) return;
47
+ _el.style.overflowY = "scroll";
48
+
49
+ function handle_input(event: Event): void {
50
+ resize(event.target as HTMLTextAreaElement, _value.lines, _value.max_lines);
51
+ }
52
+ _el.addEventListener("input", handle_input);
53
+
54
+ if (!_value.text.trim()) return;
55
+ resize(_el, _value.lines, _value.max_lines);
56
+
57
+ return {
58
+ destroy: () => _el.removeEventListener("input", handle_input)
59
+ };
60
+ }
6.9.0/multimodaltextbox/types.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+ import type { SelectData } from "@gradio/utils";
3
+ import type { LoadingStatus } from "@gradio/statustracker";
4
+ import type { InputHTMLAttributes } from "./shared/types";
5
+ import type { WaveformOptions } from "js/audio/shared/types";
6
+
7
+ export interface MultimodalTextboxEvents {
8
+ change: { text: string; files: FileData[] };
9
+ submit: never;
10
+ stop: never;
11
+ blur: never;
12
+ select: SelectData;
13
+ input: never;
14
+ focus: never;
15
+ error: string;
16
+ clear_status: LoadingStatus;
17
+ stop_recording: never;
18
+ upload: FileData[] | FileData;
19
+ clear: undefined;
20
+ }
21
+
22
+ export interface MultimodalTextboxProps {
23
+ value: { text: string; files: FileData[] };
24
+ file_types: string[] | null;
25
+ lines: number;
26
+ placeholder: string;
27
+ info: string | undefined;
28
+ max_lines: number;
29
+ submit_btn: string | boolean | null;
30
+ stop_btn: string | boolean | null;
31
+ value_is_output: boolean;
32
+ rtl: boolean;
33
+ text_align: "left" | "right" | undefined;
34
+ autofocus: boolean;
35
+ file_count: "single" | "multiple" | "directory";
36
+ max_plain_text_length: number;
37
+ sources: ("microphone" | "upload")[];
38
+ waveform_options: WaveformOptions;
39
+ html_attributes: InputHTMLAttributes | null;
40
+ }