gradio-pr-bot commited on
Commit
cceeb9e
·
verified ·
1 Parent(s): d893ddf

Upload folder using huggingface_hub

Browse files
6.19.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.19.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.19.0/multimodaltextbox/package.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/multimodaltextbox",
3
+ "version": "0.12.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
+ "@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.19.0/multimodaltextbox/shared/MultimodalTextbox.svelte ADDED
@@ -0,0 +1,1071 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ value?.text;
177
+ if (el && lines !== max_lines) {
178
+ resize(el, lines, max_lines);
179
+ }
180
+ });
181
+
182
+ $effect.pre(() => {
183
+ if (el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100) {
184
+ can_scroll = true;
185
+ }
186
+ });
187
+
188
+ const scroll = (): void => {
189
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
190
+ el.scrollTo(0, el.scrollHeight);
191
+ }
192
+ };
193
+
194
+ async function handle_change(): Promise<void> {
195
+ onchange?.(value);
196
+ if (!value_is_output) {
197
+ oninput?.();
198
+ }
199
+ }
200
+
201
+ $effect(() => {
202
+ value;
203
+ if (autofocus && el) {
204
+ el.focus();
205
+ }
206
+ });
207
+
208
+ $effect(() => {
209
+ if (can_scroll && autoscroll) {
210
+ scroll();
211
+ }
212
+ });
213
+
214
+ function handle_select(event: Event): void {
215
+ const target: HTMLTextAreaElement | HTMLInputElement = event.target as
216
+ | HTMLTextAreaElement
217
+ | HTMLInputElement;
218
+ const text = target.value;
219
+ const index: [number, number] = [
220
+ target.selectionStart as number,
221
+ target.selectionEnd as number
222
+ ];
223
+ onselect?.({ value: text.substring(...index), index: index });
224
+ }
225
+
226
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
227
+ if (e.key === "Enter" && e.shiftKey && lines > 1) {
228
+ e.preventDefault();
229
+ await tick();
230
+ onsubmit?.();
231
+ } else if (
232
+ e.key === "Enter" &&
233
+ !e.shiftKey &&
234
+ lines === 1 &&
235
+ max_lines >= 1
236
+ ) {
237
+ e.preventDefault();
238
+ add_mic_audio_to_files();
239
+ active_source = null;
240
+ await tick();
241
+ onsubmit?.();
242
+ }
243
+ }
244
+
245
+ function handle_scroll(event: Event): void {
246
+ const target = event.target as HTMLElement;
247
+ const current_scroll_top = target.scrollTop;
248
+ if (current_scroll_top < previous_scroll_top) {
249
+ user_has_scrolled_up = true;
250
+ }
251
+ previous_scroll_top = current_scroll_top;
252
+
253
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
254
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
255
+ if (user_has_scrolled_to_bottom) {
256
+ user_has_scrolled_up = false;
257
+ }
258
+ update_fade();
259
+ }
260
+
261
+ async function handle_upload(detail: FileData | FileData[]): Promise<void> {
262
+ handle_change();
263
+ if (Array.isArray(detail)) {
264
+ for (let file of detail) {
265
+ value.files.push(file);
266
+ }
267
+ value = value;
268
+ } else {
269
+ value.files.push(detail);
270
+ value = value;
271
+ }
272
+ await tick();
273
+ onchange?.(value);
274
+ onupload?.(detail);
275
+ }
276
+
277
+ function remove_thumbnail(event: MouseEvent, index: number): void {
278
+ handle_change();
279
+ event.stopPropagation();
280
+ value.files.splice(index, 1);
281
+ value = value;
282
+ }
283
+
284
+ function handle_upload_click(): void {
285
+ upload_component.open_upload();
286
+ }
287
+
288
+ function handle_stop(): void {
289
+ onstop?.();
290
+ }
291
+
292
+ function add_mic_audio_to_files(): void {
293
+ if (mic_audio) {
294
+ value.files.push(mic_audio);
295
+ value = value;
296
+ mic_audio = null;
297
+ onchange?.(value);
298
+ }
299
+ }
300
+
301
+ function handle_submit(): void {
302
+ add_mic_audio_to_files();
303
+ active_source = null;
304
+ onsubmit?.();
305
+ }
306
+
307
+ async function handle_paste(event: ClipboardEvent): Promise<void> {
308
+ if (!event.clipboardData) return;
309
+ const items = event.clipboardData.items;
310
+ const text = event.clipboardData.getData("text");
311
+
312
+ if (text && text.length > max_plain_text_length) {
313
+ event.preventDefault();
314
+ const file = new window.File([text], "pasted_text.txt", {
315
+ type: "text/plain",
316
+ lastModified: Date.now()
317
+ });
318
+ if (upload_component) {
319
+ upload_component.load_files([file]);
320
+ }
321
+ return;
322
+ }
323
+
324
+ for (let index in items) {
325
+ const item = items[index];
326
+ if (item.kind === "file" && item.type.includes("image")) {
327
+ const blob = item.getAsFile();
328
+ if (blob) upload_component.load_files([blob]);
329
+ }
330
+ }
331
+ }
332
+
333
+ function handle_dragenter(event: DragEvent): void {
334
+ event.preventDefault();
335
+ dragging = true;
336
+ }
337
+
338
+ function handle_dragleave(event: DragEvent): void {
339
+ event.preventDefault();
340
+ const rect = full_container.getBoundingClientRect();
341
+ const { clientX, clientY } = event;
342
+ if (
343
+ clientX <= rect.left ||
344
+ clientX >= rect.right ||
345
+ clientY <= rect.top ||
346
+ clientY >= rect.bottom
347
+ ) {
348
+ dragging = false;
349
+ }
350
+ }
351
+
352
+ function handle_drop(event: DragEvent): void {
353
+ event.preventDefault();
354
+ dragging = false;
355
+ if (event.dataTransfer && event.dataTransfer.files) {
356
+ const files = Array.from(event.dataTransfer.files);
357
+
358
+ if (file_types) {
359
+ const valid_files = files.filter((file) => {
360
+ return file_types.some((type) => {
361
+ if (type.startsWith(".")) {
362
+ return file.name.toLowerCase().endsWith(type.toLowerCase());
363
+ }
364
+ return file.type.match(new RegExp(type.replace("*", ".*")));
365
+ });
366
+ });
367
+
368
+ const invalid_files = files.length - valid_files.length;
369
+ if (invalid_files > 0) {
370
+ onerror?.(
371
+ `${invalid_files} file(s) were rejected. Accepted formats: ${file_types.join(", ")}`
372
+ );
373
+ }
374
+
375
+ if (valid_files.length > 0) {
376
+ upload_component.load_files(valid_files);
377
+ }
378
+ } else {
379
+ upload_component.load_files(files);
380
+ }
381
+ }
382
+ }
383
+ </script>
384
+
385
+ <div
386
+ class="full-container"
387
+ class:dragging
388
+ bind:this={full_container}
389
+ ondragenter={handle_dragenter}
390
+ ondragleave={handle_dragleave}
391
+ ondragover={(e) => e.preventDefault()}
392
+ ondrop={handle_drop}
393
+ role="group"
394
+ aria-label="Multimedia input field"
395
+ >
396
+ <BlockTitle {show_label} {info} {rtl}>{label}</BlockTitle>
397
+ <div class="input-container">
398
+ {#if sources && sources.includes("microphone") && active_source === "microphone"}
399
+ <div class="recording-overlay" class:has-audio={mic_audio !== null}>
400
+ {#if !mic_audio}
401
+ <div class="recording-content">
402
+ <MinimalAudioRecorder
403
+ label={label || "Audio"}
404
+ {waveform_settings}
405
+ {recording}
406
+ {upload}
407
+ {root}
408
+ {max_file_size}
409
+ bind:upload_promise
410
+ onchange={(audio_value) => {
411
+ mic_audio = audio_value;
412
+ }}
413
+ onstoprecording={() => {
414
+ recording = false;
415
+ onstop_recording?.();
416
+ }}
417
+ onclear={() => {
418
+ active_source = null;
419
+ recording = false;
420
+ mic_audio = null;
421
+ onclear?.();
422
+ }}
423
+ />
424
+ </div>
425
+ {:else}
426
+ <div class="recording-content">
427
+ <MinimalAudioPlayer
428
+ value={mic_audio}
429
+ label={label || "Audio"}
430
+ loop={false}
431
+ />
432
+ <div class="action-buttons">
433
+ <button
434
+ class="confirm-button"
435
+ onclick={() => {
436
+ add_mic_audio_to_files();
437
+ active_source = null;
438
+ recording = false;
439
+ }}
440
+ aria-label="Attach audio"
441
+ >
442
+ <Check />
443
+ </button>
444
+ <button
445
+ class="cancel-button"
446
+ onclick={() => {
447
+ active_source = null;
448
+ recording = false;
449
+ mic_audio = null;
450
+ }}
451
+ aria-label="Clear audio"
452
+ >
453
+ <Clear />
454
+ </button>
455
+ </div>
456
+ </div>
457
+ {/if}
458
+ </div>
459
+ {/if}
460
+ {#if show_upload}
461
+ <Upload
462
+ bind:upload_promise
463
+ bind:this={upload_component}
464
+ onload={handle_upload}
465
+ {file_count}
466
+ filetype={file_types}
467
+ {root}
468
+ {max_file_size}
469
+ bind:dragging
470
+ bind:uploading
471
+ show_progress={false}
472
+ disable_click={true}
473
+ {onerror}
474
+ hidden={true}
475
+ {upload}
476
+ {stream_handler}
477
+ />
478
+ {/if}
479
+
480
+ <div
481
+ class="input-wrapper"
482
+ class:has-files={(value?.files?.length ?? 0) > 0 || uploading}
483
+ >
484
+ {#if (value?.files?.length ?? 0) > 0 || uploading}
485
+ <div
486
+ class="thumbnails"
487
+ aria-label="Uploaded files"
488
+ data-testid="container_el"
489
+ >
490
+ {#if show_upload}
491
+ <button
492
+ data-testid="upload-button"
493
+ class="upload-button thumbnail-add"
494
+ {disabled}
495
+ onclick={handle_upload_click}
496
+ aria-label="Upload a file"
497
+ >
498
+ <Paperclip />
499
+ </button>
500
+ {/if}
501
+ {#each value?.files ?? [] as file, index}
502
+ <span
503
+ class="thumbnail-wrapper"
504
+ role="listitem"
505
+ aria-label="File thumbnail"
506
+ >
507
+ <div class="thumbnail-item thumbnail-small">
508
+ {#if file.mime_type && file.mime_type.includes("image")}
509
+ <Image
510
+ src={file.url}
511
+ restProps={{
512
+ title: null,
513
+ alt: "",
514
+ loading: "lazy",
515
+ class: "thumbnail-image"
516
+ }}
517
+ />
518
+ {:else if file.mime_type && file.mime_type.includes("audio")}
519
+ <Music />
520
+ {:else if file.mime_type && file.mime_type.includes("video")}
521
+ <Video />
522
+ {:else}
523
+ <File />
524
+ {/if}
525
+ <button
526
+ class="delete-button"
527
+ onclick={(event) => remove_thumbnail(event, index)}
528
+ aria-label="Remove file"
529
+ >
530
+ <Clear />
531
+ </button>
532
+ </div>
533
+ </span>
534
+ {/each}
535
+ {#if uploading}
536
+ <div class="loader" role="status" aria-label="Uploading"></div>
537
+ {/if}
538
+ </div>
539
+ {/if}
540
+
541
+ <div class="input-row">
542
+ {#if show_upload && (value?.files?.length ?? 0) === 0 && !uploading}
543
+ <button
544
+ data-testid="upload-button"
545
+ class="upload-button icon-button"
546
+ {disabled}
547
+ onclick={handle_upload_click}
548
+ aria-label="Upload a file"
549
+ >
550
+ <Paperclip />
551
+ </button>
552
+ {/if}
553
+ <div class="textarea-wrapper">
554
+ <textarea
555
+ data-testid="textbox"
556
+ use:text_area_resize={{
557
+ text: value.text,
558
+ lines: lines,
559
+ max_lines: max_lines
560
+ }}
561
+ class:no-label={!show_label}
562
+ dir={rtl ? "rtl" : "ltr"}
563
+ bind:value={value.text}
564
+ bind:this={el}
565
+ {placeholder}
566
+ rows={lines}
567
+ {disabled}
568
+ onkeypress={handle_keypress}
569
+ onblur={() => onblur?.()}
570
+ onselect={handle_select}
571
+ onfocus={() => onfocus?.()}
572
+ onscroll={handle_scroll}
573
+ onpaste={handle_paste}
574
+ style={text_align ? "text-align: " + text_align : ""}
575
+ autocapitalize={html_attributes?.autocapitalize}
576
+ autocorrect={html_attributes?.autocorrect}
577
+ spellcheck={html_attributes?.spellcheck}
578
+ autocomplete={html_attributes?.autocomplete}
579
+ tabindex={html_attributes?.tabindex}
580
+ enterkeyhint={html_attributes?.enterkeyhint}
581
+ lang={html_attributes?.lang}
582
+ />
583
+ <ScrollFade visible={show_fade} position="absolute" />
584
+ </div>
585
+
586
+ {#if sources && sources.includes("microphone")}
587
+ <button
588
+ data-testid="microphone-button"
589
+ class="microphone-button"
590
+ class:recording
591
+ {disabled}
592
+ onclick={async () => {
593
+ if (active_source !== "microphone") {
594
+ active_source = "microphone";
595
+ await tick();
596
+ recording = true;
597
+ } else {
598
+ active_source = null;
599
+ recording = false;
600
+ }
601
+ }}
602
+ aria-label="Record audio"
603
+ >
604
+ <Microphone />
605
+ </button>
606
+ {/if}
607
+
608
+ {#if submit_btn}
609
+ <button
610
+ class="submit-button"
611
+ data-testid="submit-button"
612
+ class:padded-button={submit_btn !== true}
613
+ {disabled}
614
+ onclick={handle_submit}
615
+ aria-label="Submit"
616
+ >
617
+ {#if submit_btn === true}
618
+ <ArrowUp />
619
+ {:else}
620
+ {submit_btn}
621
+ {/if}
622
+ </button>
623
+ {/if}
624
+ {#if stop_btn}
625
+ <button
626
+ class="stop-button"
627
+ class:padded-button={stop_btn !== true}
628
+ onclick={handle_stop}
629
+ aria-label="Stop"
630
+ >
631
+ {#if stop_btn === true}
632
+ <Square fill={"none"} stroke_width={2.5} />
633
+ {:else}
634
+ {stop_btn}
635
+ {/if}
636
+ </button>
637
+ {/if}
638
+ </div>
639
+ </div>
640
+ </div>
641
+ </div>
642
+
643
+ <style>
644
+ .full-container {
645
+ width: 100%;
646
+ position: relative;
647
+ padding: var(--block-padding);
648
+ border: 1px solid transparent;
649
+ }
650
+
651
+ .full-container.dragging {
652
+ border-color: var(--color-accent);
653
+ border-radius: calc(var(--radius-sm) - var(--size-px));
654
+ }
655
+
656
+ .full-container.dragging::after {
657
+ content: "";
658
+ position: absolute;
659
+ inset: 0;
660
+ pointer-events: none;
661
+ }
662
+
663
+ .input-container {
664
+ display: flex;
665
+ position: relative;
666
+ flex-direction: column;
667
+ gap: 0;
668
+ }
669
+
670
+ .input-wrapper {
671
+ display: flex;
672
+ position: relative;
673
+ flex-direction: column;
674
+ gap: 0;
675
+ background: var(--block-background-fill);
676
+ border-radius: var(--radius-xl);
677
+ padding: var(--spacing-sm) var(--spacing-sm) var(--spacing-sm) 0;
678
+ align-items: flex-start;
679
+ min-height: auto;
680
+ }
681
+
682
+ .input-wrapper.has-files {
683
+ padding-top: var(--spacing-xs);
684
+ }
685
+
686
+ .input-row {
687
+ display: flex;
688
+ align-items: flex-start;
689
+ gap: var(--spacing-sm);
690
+ width: 100%;
691
+ }
692
+
693
+ .thumbnails {
694
+ display: flex;
695
+ align-items: center;
696
+ gap: var(--spacing-sm);
697
+ padding: var(--spacing-xs) 0;
698
+ margin-bottom: var(--spacing-xs);
699
+ overflow-x: auto;
700
+ overflow-y: hidden;
701
+ scrollbar-width: none;
702
+ -ms-overflow-style: none;
703
+ flex-wrap: nowrap;
704
+ -webkit-overflow-scrolling: touch;
705
+ scroll-behavior: smooth;
706
+ overflow-y: scroll;
707
+ width: 100%;
708
+ }
709
+
710
+ .thumbnails::-webkit-scrollbar,
711
+ .thumbnails::-webkit-scrollbar-track,
712
+ .thumbnails::-webkit-scrollbar-thumb {
713
+ display: none;
714
+ }
715
+
716
+ .thumbnails :global(img) {
717
+ width: var(--size-full);
718
+ height: var(--size-full);
719
+ object-fit: cover;
720
+ border-radius: var(--radius-md);
721
+ }
722
+
723
+ .thumbnail-wrapper {
724
+ position: relative;
725
+ flex-shrink: 0;
726
+ }
727
+
728
+ .thumbnail-item {
729
+ position: relative;
730
+ display: flex;
731
+ justify-content: center;
732
+ align-items: center;
733
+ border-radius: var(--radius-md);
734
+ background: var(--background-fill-secondary);
735
+ width: var(--size-full);
736
+ height: var(--size-full);
737
+ cursor: default;
738
+ padding: 0;
739
+ }
740
+
741
+ .thumbnail-small {
742
+ width: var(--size-10);
743
+ height: var(--size-10);
744
+ }
745
+
746
+ .thumbnail-item :global(svg) {
747
+ width: var(--size-5);
748
+ height: var(--size-5);
749
+ }
750
+
751
+ .delete-button {
752
+ position: absolute;
753
+ inset: 0;
754
+ display: flex;
755
+ justify-content: center;
756
+ align-items: center;
757
+ color: var(--button-primary-text-color);
758
+ background: rgba(0, 0, 0, 0.6);
759
+ backdrop-filter: var(--blur-xs);
760
+ border-radius: var(--radius-md);
761
+ padding: 0;
762
+ z-index: var(--layer-1);
763
+ opacity: 0;
764
+ transition: opacity 0.1s var(--easing-standard);
765
+ }
766
+
767
+ .delete-button:hover {
768
+ background: rgba(0, 0, 0, 0.8);
769
+ }
770
+
771
+ .delete-button :global(svg) {
772
+ width: var(--size-5);
773
+ height: var(--size-5);
774
+ }
775
+
776
+ .thumbnail-item:hover .delete-button {
777
+ opacity: 1;
778
+ }
779
+
780
+ textarea {
781
+ flex-grow: 1;
782
+ outline: none !important;
783
+ background: transparent;
784
+ padding: var(--spacing-sm) 0;
785
+ color: var(--body-text-color);
786
+ font-weight: var(--input-text-weight);
787
+ font-size: var(--input-text-size);
788
+ border: none;
789
+ margin: 0;
790
+ resize: none;
791
+ position: relative;
792
+ z-index: var(--layer-1);
793
+ text-align: left;
794
+ }
795
+
796
+ textarea:disabled {
797
+ -webkit-opacity: 1;
798
+ opacity: 1;
799
+ }
800
+
801
+ textarea::placeholder {
802
+ color: var(--input-placeholder-color);
803
+ }
804
+
805
+ textarea[dir="rtl"] {
806
+ text-align: right;
807
+ }
808
+
809
+ textarea[dir="rtl"] ~ .submit-button :global(svg) {
810
+ transform: scaleX(-1);
811
+ }
812
+
813
+ .microphone-button,
814
+ .icon-button {
815
+ color: var(--body-text-color);
816
+ cursor: pointer;
817
+ padding: var(--spacing-sm);
818
+ display: flex;
819
+ justify-content: center;
820
+ align-items: center;
821
+ flex-shrink: 0;
822
+ border-radius: var(--radius-md);
823
+ }
824
+
825
+ .thumbnail-add {
826
+ background: var(--button-secondary-background-fill);
827
+ cursor: pointer;
828
+ display: flex;
829
+ justify-content: center;
830
+ align-items: center;
831
+ flex-shrink: 0;
832
+ width: var(--size-10);
833
+ height: var(--size-10);
834
+ border-radius: var(--radius-md);
835
+ z-index: var(--layer-1);
836
+ }
837
+
838
+ .thumbnail-add:hover:not(:disabled) {
839
+ background: var(--button-secondary-background-fill-hover);
840
+ }
841
+
842
+ .thumbnail-add:disabled {
843
+ opacity: 0.5;
844
+ cursor: not-allowed;
845
+ }
846
+
847
+ .thumbnail-add :global(svg) {
848
+ width: var(--size-5);
849
+ height: var(--size-5);
850
+ }
851
+
852
+ .microphone-button,
853
+ .icon-button {
854
+ width: var(--size-9);
855
+ height: var(--size-9);
856
+ }
857
+
858
+ .microphone-button:hover:not(:disabled),
859
+ .icon-button:hover:not(:disabled) {
860
+ background: var(--button-secondary-background-fill);
861
+ }
862
+
863
+ .microphone-button:disabled,
864
+ .icon-button:disabled {
865
+ opacity: 0.5;
866
+ cursor: not-allowed;
867
+ }
868
+
869
+ .microphone-button :global(svg),
870
+ .icon-button :global(svg) {
871
+ width: var(--size-5);
872
+ height: var(--size-5);
873
+ }
874
+
875
+ .submit-button,
876
+ .stop-button {
877
+ background: var(--button-secondary-background-fill);
878
+ cursor: pointer;
879
+ display: flex;
880
+ justify-content: center;
881
+ align-items: center;
882
+ flex-shrink: 0;
883
+ width: var(--size-9);
884
+ height: var(--size-9);
885
+ border-radius: var(--radius-md);
886
+ z-index: var(--layer-1);
887
+ }
888
+
889
+ .submit-button:hover:not(:disabled),
890
+ .stop-button:hover:not(:disabled) {
891
+ background: var(--button-secondary-background-fill-hover);
892
+ }
893
+
894
+ .submit-button:active:not(:disabled),
895
+ .stop-button:active:not(:disabled) {
896
+ box-shadow: var(--button-shadow-active);
897
+ }
898
+
899
+ .submit-button:disabled,
900
+ .stop-button:disabled {
901
+ cursor: not-allowed;
902
+ }
903
+
904
+ .submit-button :global(svg),
905
+ .stop-button :global(svg) {
906
+ width: var(--size-5);
907
+ height: var(--size-5);
908
+ }
909
+
910
+ .padded-button {
911
+ padding: 0 var(--spacing-lg);
912
+ width: auto;
913
+ border-radius: var(--radius-xl);
914
+ }
915
+
916
+ .loader {
917
+ display: flex;
918
+ justify-content: center;
919
+ align-items: center;
920
+ position: relative;
921
+ border: var(--size-1) solid var(--border-color-primary);
922
+ border-top-color: var(--color-accent);
923
+ border-radius: var(--radius-100);
924
+ width: var(--size-5);
925
+ height: var(--size-5);
926
+ animation: spin 1s linear infinite;
927
+ flex-shrink: 0;
928
+ }
929
+
930
+ @keyframes spin {
931
+ to {
932
+ transform: rotate(360deg);
933
+ }
934
+ }
935
+
936
+ .recording-overlay {
937
+ position: absolute;
938
+ top: 0;
939
+ left: 0;
940
+ right: 0;
941
+ bottom: 0;
942
+ background: var(--block-background-fill);
943
+ border-radius: var(--radius-xl);
944
+ display: flex;
945
+ align-items: center;
946
+ justify-content: center;
947
+ z-index: var(--layer-5);
948
+ padding: var(--spacing-lg);
949
+ backdrop-filter: blur(8px);
950
+ animation: fadeIn 0.2s var(--easing-standard);
951
+ }
952
+
953
+ @keyframes fadeIn {
954
+ from {
955
+ opacity: 0;
956
+ }
957
+ to {
958
+ opacity: 1;
959
+ }
960
+ }
961
+
962
+ .recording-content {
963
+ display: flex;
964
+ align-items: center;
965
+ gap: var(--spacing-lg);
966
+ width: 100%;
967
+ max-width: 700px;
968
+ }
969
+
970
+ .recording-content :global(.minimal-audio-recorder),
971
+ .recording-content :global(.minimal-audio-player) {
972
+ flex: 1;
973
+ }
974
+
975
+ .action-buttons {
976
+ display: flex;
977
+ align-items: center;
978
+ gap: var(--spacing-sm);
979
+ flex-shrink: 0;
980
+ }
981
+
982
+ .stop-button,
983
+ .confirm-button,
984
+ .cancel-button {
985
+ display: flex;
986
+ align-items: center;
987
+ justify-content: center;
988
+ width: var(--size-9);
989
+ height: var(--size-9);
990
+ padding: 0;
991
+ border-radius: var(--radius-md);
992
+ cursor: pointer;
993
+ flex-shrink: 0;
994
+ }
995
+
996
+ .stop-button {
997
+ background: var(--button-secondary-background-fill);
998
+ border-color: var(--border-color-primary);
999
+ color: var(--error-500);
1000
+ }
1001
+
1002
+ .stop-button:hover {
1003
+ background: var(--button-secondary-background-fill-hover);
1004
+ color: var(--error-600);
1005
+ }
1006
+
1007
+ .stop-button:active {
1008
+ transform: scale(0.95);
1009
+ }
1010
+
1011
+ .confirm-button {
1012
+ background: var(--button-primary-background-fill);
1013
+ border-color: var(--button-primary-border-color);
1014
+ color: white;
1015
+ }
1016
+
1017
+ .confirm-button:hover {
1018
+ background: var(--button-primary-background-fill-hover);
1019
+ color: var(--button-primary-text-color-hover);
1020
+ }
1021
+
1022
+ .confirm-button:active {
1023
+ transform: scale(0.95);
1024
+ }
1025
+
1026
+ .cancel-button {
1027
+ background: var(--button-secondary-background-fill);
1028
+ color: var(--body-text-color);
1029
+ }
1030
+
1031
+ .cancel-button:hover {
1032
+ background: var(--button-secondary-background-fill-hover);
1033
+ }
1034
+
1035
+ .stop-button :global(svg),
1036
+ .confirm-button :global(svg),
1037
+ .cancel-button :global(svg) {
1038
+ width: var(--size-5);
1039
+ height: var(--size-5);
1040
+ }
1041
+
1042
+ @media (max-width: 768px) {
1043
+ .input-wrapper {
1044
+ padding: var(--spacing-xs);
1045
+ }
1046
+
1047
+ .thumbnails {
1048
+ padding: var(--spacing-xs) 0;
1049
+ margin-bottom: var(--spacing-md);
1050
+ }
1051
+
1052
+ .thumbnail-small,
1053
+ .thumbnail-add {
1054
+ width: var(--size-9);
1055
+ height: var(--size-9);
1056
+ }
1057
+
1058
+ .thumbnail-item:active .delete-button {
1059
+ opacity: 1;
1060
+ }
1061
+ }
1062
+
1063
+ .textarea-wrapper {
1064
+ position: relative;
1065
+ flex-grow: 1;
1066
+ }
1067
+
1068
+ .textarea-wrapper textarea {
1069
+ width: 100%;
1070
+ }
1071
+ </style>
6.19.0/multimodaltextbox/shared/types.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export type { InputHTMLAttributes } from "../../textbox/types";
6.19.0/multimodaltextbox/shared/utils.ts ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ update_scrollbar_visibility(target);
41
+ }
42
+
43
+ function update_scrollbar_visibility(
44
+ textarea: HTMLTextAreaElement | HTMLInputElement
45
+ ): void {
46
+ const content_height = textarea.scrollHeight;
47
+ const visible_height = textarea.clientHeight;
48
+ const line_height = parseFloat(window.getComputedStyle(textarea).lineHeight);
49
+ if (content_height > visible_height + line_height) {
50
+ textarea.style.overflowY = "scroll";
51
+ } else {
52
+ textarea.style.overflowY = "hidden";
53
+ }
54
+ }
55
+
56
+ export function text_area_resize(
57
+ _el: HTMLTextAreaElement,
58
+ _value: Value
59
+ ): any | undefined {
60
+ if (_value.lines === _value.max_lines) return;
61
+ update_scrollbar_visibility(_el);
62
+
63
+ function handle_input(event: Event): void {
64
+ resize(event.target as HTMLTextAreaElement, _value.lines, _value.max_lines);
65
+ }
66
+ _el.addEventListener("input", handle_input);
67
+
68
+ if (!_value.text.trim()) return;
69
+ resize(_el, _value.lines, _value.max_lines);
70
+
71
+ return {
72
+ destroy: () => _el.removeEventListener("input", handle_input)
73
+ };
74
+ }
6.19.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
+ }