gradio-pr-bot commited on
Commit
68c88f6
·
verified ·
1 Parent(s): 501bc35

Upload folder using huggingface_hub

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