gradio-pr-bot commited on
Commit
8c6e30f
·
verified ·
1 Parent(s): 0d38149

Upload folder using huggingface_hub

Browse files
5.49.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>
5.49.1/multimodaltextbox/Index.svelte ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 type { Gradio, 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 type { LoadingStatus } from "@gradio/statustracker";
14
+ import type { FileData } from "@gradio/client";
15
+ import { onMount } from "svelte";
16
+ import type { WaveformOptions } from "../audio/shared/types";
17
+ import type { InputHTMLAttributes } from "./shared/types";
18
+
19
+ export let gradio: Gradio<{
20
+ change: typeof value;
21
+ submit: never;
22
+ stop: never;
23
+ blur: never;
24
+ select: SelectData;
25
+ input: never;
26
+ focus: never;
27
+ error: string;
28
+ clear_status: LoadingStatus;
29
+ start_recording: never;
30
+ pause_recording: never;
31
+ stop_recording: never;
32
+ upload: FileData[] | FileData;
33
+ clear: undefined;
34
+ }>;
35
+ export let elem_id = "";
36
+ export let elem_classes: string[] = [];
37
+ export let visible: boolean | "hidden" = true;
38
+ export let value: { text: string; files: FileData[] } = {
39
+ text: "",
40
+ files: []
41
+ };
42
+ export let file_types: string[] | null = null;
43
+ export let lines: number;
44
+ export let placeholder = "";
45
+ export let label = "MultimodalTextbox";
46
+ export let info: string | undefined = undefined;
47
+ export let show_label: boolean;
48
+ export let max_lines: number;
49
+ export let scale: number | null = null;
50
+ export let min_width: number | undefined = undefined;
51
+ export let submit_btn: string | boolean | null = null;
52
+ export let stop_btn: string | boolean | null = null;
53
+ export let loading_status: LoadingStatus | undefined = undefined;
54
+ export let value_is_output = false;
55
+ export let rtl = false;
56
+ export let text_align: "left" | "right" | undefined = undefined;
57
+ export let autofocus = false;
58
+ export let autoscroll = true;
59
+ export let interactive: boolean;
60
+ export let root: string;
61
+ export let file_count: "single" | "multiple" | "directory";
62
+ export let max_plain_text_length: number;
63
+ export let sources: ["microphone" | "upload"] = ["upload"];
64
+ export let waveform_options: WaveformOptions = {};
65
+ export let html_attributes: InputHTMLAttributes | null = null;
66
+
67
+ let dragging: boolean;
68
+ let active_source: "microphone" | null = null;
69
+ let waveform_settings: Record<string, any>;
70
+ let color_accent = "darkorange";
71
+
72
+ onMount(() => {
73
+ color_accent = getComputedStyle(document?.documentElement).getPropertyValue(
74
+ "--color-accent"
75
+ );
76
+ set_trim_region_colour();
77
+ waveform_settings.waveColor = waveform_options.waveform_color || "#9ca3af";
78
+ waveform_settings.progressColor =
79
+ waveform_options.waveform_progress_color || color_accent;
80
+ waveform_settings.mediaControls = waveform_options.show_controls;
81
+ waveform_settings.sampleRate = waveform_options.sample_rate || 44100;
82
+ });
83
+
84
+ $: waveform_settings = {
85
+ height: 50,
86
+
87
+ barWidth: 2,
88
+ barGap: 3,
89
+ cursorWidth: 2,
90
+ cursorColor: "#ddd5e9",
91
+ autoplay: false,
92
+ barRadius: 10,
93
+ dragToSeek: true,
94
+ normalize: true,
95
+ minPxPerSec: 20
96
+ };
97
+
98
+ const trim_region_settings = {
99
+ color: waveform_options.trim_region_color,
100
+ drag: true,
101
+ resize: true
102
+ };
103
+
104
+ function set_trim_region_colour(): void {
105
+ document.documentElement.style.setProperty(
106
+ "--trim-region-color",
107
+ trim_region_settings.color || color_accent
108
+ );
109
+ }
110
+
111
+ // Create const references to the callbacks so that afterUpdate in child is not called on every prop change
112
+ // in the DOM. See https://github.com/gradio-app/gradio/issues/11933
113
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
114
+ const upload_fn = (...args: Parameters<typeof gradio.client.upload>) =>
115
+ gradio.client.upload(...args);
116
+ const i18n = (s: string | null | undefined): string => gradio.i18n(s);
117
+ const stream_handler_fn = (
118
+ ...args: Parameters<typeof gradio.client.stream>
119
+ ): EventSource => gradio.client.stream(...args);
120
+
121
+ $: sources_string = sources.join(",") as
122
+ | "upload"
123
+ | "upload,microphone"
124
+ | "microphone"
125
+ | "microphone,upload";
126
+
127
+ $: file_types_string = (file_types || []).join(",") || null;
128
+ </script>
129
+
130
+ <Block
131
+ {visible}
132
+ {elem_id}
133
+ elem_classes={[...elem_classes, "multimodal-textbox"]}
134
+ {scale}
135
+ {min_width}
136
+ allow_overflow={false}
137
+ padding={false}
138
+ border_mode={dragging ? "focus" : "base"}
139
+ >
140
+ {#if loading_status}
141
+ <StatusTracker
142
+ autoscroll={gradio.autoscroll}
143
+ i18n={gradio.i18n}
144
+ {...loading_status}
145
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
146
+ />
147
+ {/if}
148
+
149
+ <MultimodalTextbox
150
+ bind:value
151
+ bind:value_is_output
152
+ bind:dragging
153
+ bind:active_source
154
+ {file_types_string}
155
+ {root}
156
+ {label}
157
+ {info}
158
+ {show_label}
159
+ {lines}
160
+ {rtl}
161
+ {text_align}
162
+ {waveform_settings}
163
+ {i18n}
164
+ max_lines={!max_lines ? lines + 1 : max_lines}
165
+ {placeholder}
166
+ {submit_btn}
167
+ {stop_btn}
168
+ {autofocus}
169
+ {autoscroll}
170
+ {file_count}
171
+ {sources_string}
172
+ max_file_size={gradio.max_file_size}
173
+ on:change={() => gradio.dispatch("change", value)}
174
+ on:input={() => gradio.dispatch("input")}
175
+ on:submit={() => gradio.dispatch("submit")}
176
+ on:stop={() => gradio.dispatch("stop")}
177
+ on:blur={() => gradio.dispatch("blur")}
178
+ on:select={(e) => gradio.dispatch("select", e.detail)}
179
+ on:focus={() => gradio.dispatch("focus")}
180
+ on:error={({ detail }) => {
181
+ gradio.dispatch("error", detail);
182
+ }}
183
+ on:start_recording={() => gradio.dispatch("start_recording")}
184
+ on:pause_recording={() => gradio.dispatch("pause_recording")}
185
+ on:stop_recording={() => gradio.dispatch("stop_recording")}
186
+ on:upload={(e) => gradio.dispatch("upload", e.detail)}
187
+ on:clear={() => gradio.dispatch("clear")}
188
+ disabled={!interactive}
189
+ upload={upload_fn}
190
+ stream_handler={stream_handler_fn}
191
+ {max_plain_text_length}
192
+ {html_attributes}
193
+ />
194
+ </Block>
5.49.1/multimodaltextbox/package.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/multimodaltextbox",
3
+ "version": "0.10.21",
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
+ },
34
+ "devDependencies": {
35
+ "@gradio/preview": "workspace:^"
36
+ },
37
+ "peerDependencies": {
38
+ "svelte": "^4.0.0"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/gradio-app/gradio.git",
43
+ "directory": "js/multimodaltextbox"
44
+ }
45
+ }
5.49.1/multimodaltextbox/shared/MultimodalTextbox.svelte ADDED
@@ -0,0 +1,753 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "../../audio/shared/types";
16
+ import {
17
+ Clear,
18
+ File,
19
+ Music,
20
+ Paperclip,
21
+ Video,
22
+ Send,
23
+ Square,
24
+ Microphone
25
+ } from "@gradio/icons";
26
+ import type { SelectData } from "@gradio/utils";
27
+ import InteractiveAudio from "../../audio/interactive/InteractiveAudio.svelte";
28
+ import type { InputHTMLAttributes } from "./types";
29
+
30
+ export let value: { text: string; files: FileData[] } = {
31
+ text: "",
32
+ files: []
33
+ };
34
+
35
+ export let value_is_output = false;
36
+ export let lines = 1;
37
+ export let i18n: I18nFormatter;
38
+ export let placeholder = "Type here...";
39
+ export let disabled = false;
40
+ export let label: string;
41
+ export let info: string | undefined = undefined;
42
+ export let show_label = true;
43
+ export let max_lines: number;
44
+ export let submit_btn: string | boolean | null = null;
45
+ export let stop_btn: string | boolean | null = null;
46
+ export let rtl = false;
47
+ export let autofocus = false;
48
+ export let text_align: "left" | "right" | undefined = undefined;
49
+ export let autoscroll = true;
50
+ export let root: string;
51
+ export let file_types_string: string | null = null;
52
+ export let max_file_size: number | null = null;
53
+ export let upload: Client["upload"];
54
+ export let stream_handler: Client["stream"];
55
+ export let file_count: "single" | "multiple" | "directory" = "multiple";
56
+ export let max_plain_text_length = 1000;
57
+ export let waveform_settings: Record<string, any>;
58
+ export let waveform_options: WaveformOptions = {
59
+ show_recording_waveform: true
60
+ };
61
+ export let sources_string:
62
+ | "upload"
63
+ | "upload,microphone"
64
+ | "microphone"
65
+ | "microphone,upload" = "upload";
66
+ export let active_source: "microphone" | null = null;
67
+ export let html_attributes: InputHTMLAttributes | null = null;
68
+
69
+ let upload_component: Upload;
70
+ let el: HTMLTextAreaElement | HTMLInputElement;
71
+ let can_scroll: boolean;
72
+ let previous_scroll_top = 0;
73
+ let user_has_scrolled_up = false;
74
+ export let dragging = false;
75
+ let uploading = false;
76
+ // value can be null in multimodalchatinterface when loading a deep link
77
+ let oldValue = value?.text ?? "";
78
+ let recording = false;
79
+
80
+ $: sources = sources_string
81
+ .split(",")
82
+ .map((s) => s.trim())
83
+ .filter((s) => s === "upload" || s === "microphone") as (
84
+ | "upload"
85
+ | "microphone"
86
+ )[];
87
+ $: file_types = file_types_string
88
+ ? file_types_string.split(",").map((s) => s.trim())
89
+ : null;
90
+ $: dispatch("drag", dragging);
91
+ let mic_audio: FileData | null = null;
92
+
93
+ let full_container: HTMLDivElement;
94
+
95
+ $: if (oldValue !== value.text) {
96
+ dispatch("change", value);
97
+ oldValue = value.text;
98
+ }
99
+
100
+ $: if (value === null) value = { text: "", files: [] };
101
+ $: value, el && lines !== max_lines && resize(el, lines, max_lines);
102
+
103
+ const dispatch = createEventDispatcher<{
104
+ change: typeof value;
105
+ submit: undefined;
106
+ stop: undefined;
107
+ blur: undefined;
108
+ select: SelectData;
109
+ input: undefined;
110
+ focus: undefined;
111
+ drag: boolean;
112
+ upload: FileData[] | FileData;
113
+ clear: undefined;
114
+ load: FileData[] | FileData;
115
+ error: string;
116
+ start_recording: undefined;
117
+ pause_recording: undefined;
118
+ stop_recording: undefined;
119
+ }>();
120
+
121
+ beforeUpdate(() => {
122
+ can_scroll = el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100;
123
+ });
124
+
125
+ const scroll = (): void => {
126
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
127
+ el.scrollTo(0, el.scrollHeight);
128
+ }
129
+ };
130
+
131
+ async function handle_change(): Promise<void> {
132
+ dispatch("change", value);
133
+ if (!value_is_output) {
134
+ dispatch("input");
135
+ }
136
+ }
137
+
138
+ onMount(() => {
139
+ if (autofocus && el !== null) {
140
+ el.focus();
141
+ }
142
+ });
143
+
144
+ const after_update = (): void => {
145
+ if (can_scroll && autoscroll) {
146
+ scroll();
147
+ }
148
+ if (autofocus && el) {
149
+ el.focus();
150
+ }
151
+ };
152
+
153
+ afterUpdate(after_update);
154
+
155
+ function handle_select(event: Event): void {
156
+ const target: HTMLTextAreaElement | HTMLInputElement = event.target as
157
+ | HTMLTextAreaElement
158
+ | HTMLInputElement;
159
+ const text = target.value;
160
+ const index: [number, number] = [
161
+ target.selectionStart as number,
162
+ target.selectionEnd as number
163
+ ];
164
+ dispatch("select", { value: text.substring(...index), index: index });
165
+ }
166
+
167
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
168
+ await tick();
169
+ if (e.key === "Enter" && e.shiftKey && lines > 1) {
170
+ e.preventDefault();
171
+ dispatch("submit");
172
+ } else if (
173
+ e.key === "Enter" &&
174
+ !e.shiftKey &&
175
+ lines === 1 &&
176
+ max_lines >= 1
177
+ ) {
178
+ e.preventDefault();
179
+ dispatch("submit");
180
+ active_source = null;
181
+ if (mic_audio) {
182
+ value.files.push(mic_audio);
183
+ value = value;
184
+ mic_audio = null;
185
+ }
186
+ }
187
+ }
188
+
189
+ function handle_scroll(event: Event): void {
190
+ const target = event.target as HTMLElement;
191
+ const current_scroll_top = target.scrollTop;
192
+ if (current_scroll_top < previous_scroll_top) {
193
+ user_has_scrolled_up = true;
194
+ }
195
+ previous_scroll_top = current_scroll_top;
196
+
197
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
198
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
199
+ if (user_has_scrolled_to_bottom) {
200
+ user_has_scrolled_up = false;
201
+ }
202
+ }
203
+
204
+ async function handle_upload({
205
+ detail
206
+ }: CustomEvent<FileData>): Promise<void> {
207
+ handle_change();
208
+ if (Array.isArray(detail)) {
209
+ for (let file of detail) {
210
+ value.files.push(file);
211
+ }
212
+ value = value;
213
+ } else {
214
+ value.files.push(detail);
215
+ value = value;
216
+ }
217
+ await tick();
218
+ dispatch("change", value);
219
+ dispatch("upload", detail);
220
+ }
221
+
222
+ function remove_thumbnail(event: MouseEvent, index: number): void {
223
+ handle_change();
224
+ event.stopPropagation();
225
+ value.files.splice(index, 1);
226
+ value = value;
227
+ }
228
+
229
+ function handle_upload_click(): void {
230
+ upload_component.open_upload();
231
+ }
232
+
233
+ function handle_stop(): void {
234
+ dispatch("stop");
235
+ }
236
+
237
+ function handle_submit(): void {
238
+ dispatch("submit");
239
+ active_source = null;
240
+ if (mic_audio) {
241
+ value.files.push(mic_audio);
242
+ value = value;
243
+ mic_audio = null;
244
+ }
245
+ }
246
+
247
+ async function handle_paste(event: ClipboardEvent): Promise<void> {
248
+ if (!event.clipboardData) return;
249
+ const items = event.clipboardData.items;
250
+ const text = event.clipboardData.getData("text");
251
+
252
+ if (text && text.length > max_plain_text_length) {
253
+ event.preventDefault();
254
+ const file = new window.File([text], "pasted_text.txt", {
255
+ type: "text/plain",
256
+ lastModified: Date.now()
257
+ });
258
+ if (upload_component) {
259
+ upload_component.load_files([file]);
260
+ }
261
+ return;
262
+ }
263
+
264
+ for (let index in items) {
265
+ const item = items[index];
266
+ if (item.kind === "file" && item.type.includes("image")) {
267
+ const blob = item.getAsFile();
268
+ if (blob) upload_component.load_files([blob]);
269
+ }
270
+ }
271
+ }
272
+
273
+ function handle_dragenter(event: DragEvent): void {
274
+ event.preventDefault();
275
+ dragging = true;
276
+ }
277
+
278
+ function handle_dragleave(event: DragEvent): void {
279
+ event.preventDefault();
280
+ const rect = full_container.getBoundingClientRect();
281
+ const { clientX, clientY } = event;
282
+ if (
283
+ clientX <= rect.left ||
284
+ clientX >= rect.right ||
285
+ clientY <= rect.top ||
286
+ clientY >= rect.bottom
287
+ ) {
288
+ dragging = false;
289
+ }
290
+ }
291
+
292
+ function handle_drop(event: DragEvent): void {
293
+ event.preventDefault();
294
+ dragging = false;
295
+ if (event.dataTransfer && event.dataTransfer.files) {
296
+ const files = Array.from(event.dataTransfer.files);
297
+
298
+ if (file_types) {
299
+ const valid_files = files.filter((file) => {
300
+ return file_types.some((type) => {
301
+ if (type.startsWith(".")) {
302
+ return file.name.toLowerCase().endsWith(type.toLowerCase());
303
+ }
304
+ return file.type.match(new RegExp(type.replace("*", ".*")));
305
+ });
306
+ });
307
+
308
+ const invalid_files = files.length - valid_files.length;
309
+ if (invalid_files > 0) {
310
+ dispatch(
311
+ "error",
312
+ `${invalid_files} file(s) were rejected. Accepted formats: ${file_types.join(", ")}`
313
+ );
314
+ }
315
+
316
+ if (valid_files.length > 0) {
317
+ upload_component.load_files(valid_files);
318
+ }
319
+ } else {
320
+ upload_component.load_files(files);
321
+ }
322
+ }
323
+ }
324
+ </script>
325
+
326
+ <div
327
+ class="full-container"
328
+ class:dragging
329
+ bind:this={full_container}
330
+ on:dragenter={handle_dragenter}
331
+ on:dragleave={handle_dragleave}
332
+ on:dragover|preventDefault
333
+ on:drop={handle_drop}
334
+ role="group"
335
+ aria-label="Multimedia input field"
336
+ >
337
+ <BlockTitle {show_label} {info} {rtl}>{label}</BlockTitle>
338
+ {#if value.files.length > 0 || uploading}
339
+ <div
340
+ class="thumbnails scroll-hide"
341
+ aria-label="Uploaded files"
342
+ data-testid="container_el"
343
+ style="display: {value.files.length > 0 || uploading ? 'flex' : 'none'};"
344
+ >
345
+ {#each value.files as file, index}
346
+ <span role="listitem" aria-label="File thumbnail">
347
+ <button class="thumbnail-item thumbnail-small">
348
+ <button
349
+ class:disabled
350
+ class="delete-button"
351
+ on:click={(event) => remove_thumbnail(event, index)}
352
+ ><Clear /></button
353
+ >
354
+ {#if file.mime_type && file.mime_type.includes("image")}
355
+ <Image
356
+ src={file.url}
357
+ title={null}
358
+ alt=""
359
+ loading="lazy"
360
+ class={"thumbnail-image"}
361
+ />
362
+ {:else if file.mime_type && file.mime_type.includes("audio")}
363
+ <Music />
364
+ {:else if file.mime_type && file.mime_type.includes("video")}
365
+ <Video />
366
+ {:else}
367
+ <File />
368
+ {/if}
369
+ </button>
370
+ </span>
371
+ {/each}
372
+ {#if uploading}
373
+ <div class="loader" role="status" aria-label="Uploading"></div>
374
+ {/if}
375
+ </div>
376
+ {/if}
377
+ {#if sources && sources.includes("microphone") && active_source === "microphone"}
378
+ <InteractiveAudio
379
+ on:change={({ detail }) => {
380
+ if (detail !== null) {
381
+ mic_audio = detail;
382
+ }
383
+ }}
384
+ on:clear={() => {
385
+ active_source = null;
386
+ }}
387
+ on:start_recording={() => dispatch("start_recording")}
388
+ on:pause_recording={() => dispatch("pause_recording")}
389
+ on:stop_recording={() => dispatch("stop_recording")}
390
+ sources={["microphone"]}
391
+ class_name="compact-audio"
392
+ {recording}
393
+ {waveform_settings}
394
+ {waveform_options}
395
+ {i18n}
396
+ {active_source}
397
+ {upload}
398
+ {stream_handler}
399
+ stream_every={1}
400
+ editable={true}
401
+ {label}
402
+ {root}
403
+ loop={false}
404
+ show_label={false}
405
+ show_download_button={false}
406
+ dragging={false}
407
+ />
408
+ {/if}
409
+ <div class="input-container">
410
+ {#if sources && sources.includes("upload") && !(file_count === "single" && value.files.length > 0)}
411
+ <Upload
412
+ bind:this={upload_component}
413
+ on:load={handle_upload}
414
+ {file_count}
415
+ filetype={file_types}
416
+ {root}
417
+ {max_file_size}
418
+ bind:dragging
419
+ bind:uploading
420
+ show_progress={false}
421
+ disable_click={true}
422
+ on:error
423
+ hidden={true}
424
+ {upload}
425
+ {stream_handler}
426
+ />
427
+ <button
428
+ data-testid="upload-button"
429
+ class="upload-button"
430
+ {disabled}
431
+ on:click={disabled ? undefined : handle_upload_click}
432
+ ><Paperclip /></button
433
+ >
434
+ {/if}
435
+ {#if sources && sources.includes("microphone")}
436
+ <button
437
+ data-testid="microphone-button"
438
+ class="microphone-button"
439
+ class:recording
440
+ {disabled}
441
+ on:click={disabled
442
+ ? undefined
443
+ : () => {
444
+ active_source =
445
+ active_source !== "microphone" ? "microphone" : null;
446
+ }}
447
+ >
448
+ <Microphone />
449
+ </button>
450
+ {/if}
451
+ <textarea
452
+ data-testid="textbox"
453
+ use:text_area_resize={{
454
+ text: value.text,
455
+ lines: lines,
456
+ max_lines: max_lines
457
+ }}
458
+ class="scroll-hide"
459
+ class:no-label={!show_label}
460
+ dir={rtl ? "rtl" : "ltr"}
461
+ bind:value={value.text}
462
+ bind:this={el}
463
+ {placeholder}
464
+ rows={lines}
465
+ {disabled}
466
+ on:keypress={handle_keypress}
467
+ on:blur
468
+ on:select={handle_select}
469
+ on:focus
470
+ on:scroll={handle_scroll}
471
+ on:paste={handle_paste}
472
+ style={text_align ? "text-align: " + text_align : ""}
473
+ autocapitalize={html_attributes?.autocapitalize}
474
+ autocorrect={html_attributes?.autocorrect}
475
+ spellcheck={html_attributes?.spellcheck}
476
+ autocomplete={html_attributes?.autocomplete}
477
+ tabindex={html_attributes?.tabindex}
478
+ enterkeyhint={html_attributes?.enterkeyhint}
479
+ lang={html_attributes?.lang}
480
+ />
481
+ {#if submit_btn}
482
+ <button
483
+ class="submit-button"
484
+ class:padded-button={submit_btn !== true}
485
+ {disabled}
486
+ on:click={disabled ? undefined : handle_submit}
487
+ >
488
+ {#if submit_btn === true}
489
+ <Send />
490
+ {:else}
491
+ {submit_btn}
492
+ {/if}
493
+ </button>
494
+ {/if}
495
+ {#if stop_btn}
496
+ <button
497
+ class="stop-button"
498
+ class:padded-button={stop_btn !== true}
499
+ on:click={handle_stop}
500
+ >
501
+ {#if stop_btn === true}
502
+ <Square fill={"none"} stroke_width={2.5} />
503
+ {:else}
504
+ {stop_btn}
505
+ {/if}
506
+ </button>
507
+ {/if}
508
+ </div>
509
+ </div>
510
+
511
+ <style>
512
+ .full-container {
513
+ width: 100%;
514
+ position: relative;
515
+ padding: var(--block-padding);
516
+ border: 1px solid transparent;
517
+ }
518
+
519
+ .full-container.dragging {
520
+ border: 1px solid var(--color-accent);
521
+ border-radius: calc(var(--radius-sm) - 1px);
522
+ }
523
+
524
+ .full-container.dragging::after {
525
+ content: "";
526
+ position: absolute;
527
+ top: 0;
528
+ left: 0;
529
+ right: 0;
530
+ bottom: 0;
531
+ pointer-events: none;
532
+ }
533
+
534
+ .input-container {
535
+ display: flex;
536
+ position: relative;
537
+ align-items: flex-end;
538
+ }
539
+
540
+ textarea {
541
+ flex-grow: 1;
542
+ outline: none !important;
543
+ background: var(--block-background-fill);
544
+ padding: var(--input-padding);
545
+ color: var(--body-text-color);
546
+ font-weight: var(--input-text-weight);
547
+ font-size: var(--input-text-size);
548
+ line-height: var(--line-sm);
549
+ border: none;
550
+ margin-top: 0px;
551
+ margin-bottom: 0px;
552
+ resize: none;
553
+ position: relative;
554
+ z-index: 1;
555
+ text-align: left;
556
+ }
557
+ textarea[dir="rtl"] {
558
+ text-align: right;
559
+ }
560
+
561
+ textarea[dir="rtl"] ~ .submit-button {
562
+ order: -1;
563
+ margin-left: 0;
564
+ margin-right: var(--spacing-sm);
565
+ }
566
+
567
+ textarea[dir="rtl"] ~ .submit-button :global(svg) {
568
+ transform: scaleX(-1);
569
+ }
570
+
571
+ textarea.no-label {
572
+ padding-top: 5px;
573
+ padding-bottom: 5px;
574
+ }
575
+
576
+ textarea:disabled {
577
+ -webkit-opacity: 1;
578
+ opacity: 1;
579
+ }
580
+
581
+ textarea::placeholder {
582
+ color: var(--input-placeholder-color);
583
+ }
584
+
585
+ .microphone-button,
586
+ .upload-button,
587
+ .submit-button,
588
+ .stop-button {
589
+ border: none;
590
+ text-align: center;
591
+ text-decoration: none;
592
+ font-size: 14px;
593
+ cursor: pointer;
594
+ border-radius: 15px;
595
+ min-width: 30px;
596
+ height: 30px;
597
+ flex-shrink: 0;
598
+ display: flex;
599
+ justify-content: center;
600
+ align-items: center;
601
+ z-index: var(--layer-1);
602
+ margin-left: var(--spacing-sm);
603
+ }
604
+ .padded-button {
605
+ padding: 0 10px;
606
+ }
607
+
608
+ .microphone-button,
609
+ .stop-button,
610
+ .upload-button,
611
+ .submit-button {
612
+ background: var(--button-secondary-background-fill);
613
+ }
614
+
615
+ .microphone-button:hover:not(:disabled),
616
+ .stop-button:hover:not(:disabled),
617
+ .upload-button:hover:not(:disabled),
618
+ .submit-button:hover:not(:disabled) {
619
+ background: var(--button-secondary-background-fill-hover);
620
+ }
621
+
622
+ .microphone-button:disabled,
623
+ .stop-button:disabled,
624
+ .upload-button:disabled,
625
+ .submit-button:disabled {
626
+ background: var(--button-secondary-background-fill);
627
+ cursor: not-allowed;
628
+ }
629
+ .microphone-button:active,
630
+ .stop-button:active,
631
+ .upload-button:active,
632
+ .submit-button:active {
633
+ box-shadow: var(--button-shadow-active);
634
+ }
635
+
636
+ .submit-button :global(svg) {
637
+ height: 22px;
638
+ width: 22px;
639
+ }
640
+ .microphone-button :global(svg),
641
+ .upload-button :global(svg) {
642
+ height: 17px;
643
+ width: 17px;
644
+ }
645
+
646
+ .stop-button :global(svg) {
647
+ height: 16px;
648
+ width: 16px;
649
+ }
650
+
651
+ .loader {
652
+ display: flex;
653
+ justify-content: center;
654
+ align-items: center;
655
+ --ring-color: transparent;
656
+ position: relative;
657
+ border: 5px solid #f3f3f3;
658
+ border-top: 5px solid var(--color-accent);
659
+ border-radius: 50%;
660
+ width: 25px;
661
+ height: 25px;
662
+ animation: spin 2s linear infinite;
663
+ }
664
+
665
+ @keyframes spin {
666
+ 0% {
667
+ transform: rotate(0deg);
668
+ }
669
+ 100% {
670
+ transform: rotate(360deg);
671
+ }
672
+ }
673
+
674
+ .thumbnails :global(img) {
675
+ width: var(--size-full);
676
+ height: var(--size-full);
677
+ object-fit: cover;
678
+ border-radius: var(--radius-lg);
679
+ }
680
+
681
+ .thumbnails {
682
+ display: flex;
683
+ align-items: center;
684
+ gap: var(--spacing-lg);
685
+ overflow-x: scroll;
686
+ padding-top: var(--spacing-sm);
687
+ margin-bottom: 6px;
688
+ }
689
+
690
+ .thumbnail-item {
691
+ display: flex;
692
+ justify-content: center;
693
+ align-items: center;
694
+ --ring-color: transparent;
695
+ position: relative;
696
+ box-shadow:
697
+ 0 0 0 2px var(--ring-color),
698
+ var(--shadow-drop);
699
+ border: 1px solid var(--border-color-primary);
700
+ border-radius: var(--radius-lg);
701
+ background: var(--background-fill-secondary);
702
+ aspect-ratio: var(--ratio-square);
703
+ width: var(--size-full);
704
+ height: var(--size-full);
705
+ cursor: default;
706
+ }
707
+
708
+ .thumbnail-small {
709
+ flex: none;
710
+ transform: scale(0.9);
711
+ transition: 0.075s;
712
+ width: var(--size-12);
713
+ height: var(--size-12);
714
+ }
715
+
716
+ .thumbnail-item :global(svg) {
717
+ width: 30px;
718
+ height: 30px;
719
+ }
720
+
721
+ .delete-button {
722
+ display: flex;
723
+ justify-content: center;
724
+ align-items: center;
725
+ position: absolute;
726
+ right: -7px;
727
+ top: -7px;
728
+ color: var(--button-secondary-text-color);
729
+ background: var(--button-secondary-background-fill);
730
+ border: none;
731
+ text-align: center;
732
+ text-decoration: none;
733
+ font-size: 10px;
734
+ cursor: pointer;
735
+ border-radius: 50%;
736
+ width: 20px;
737
+ height: 20px;
738
+ }
739
+
740
+ .disabled {
741
+ display: none;
742
+ }
743
+
744
+ .delete-button :global(svg) {
745
+ width: 12px;
746
+ height: 12px;
747
+ }
748
+
749
+ .delete-button:hover {
750
+ filter: brightness(1.2);
751
+ border: 0.8px solid var(--color-grey-500);
752
+ }
753
+ </style>
5.49.1/multimodaltextbox/shared/types.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export type { InputHTMLAttributes } from "../../textbox/shared/types";
5.49.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
+ }