gradio-pr-bot commited on
Commit
de2e8e0
·
verified ·
1 Parent(s): d70220b

Upload folder using huggingface_hub

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