@gradio/multimodaltextbox 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/Example.svelte +72 -0
- package/Index.svelte +94 -0
- package/LICENSE +201 -0
- package/MultimodalTextbox.stories.svelte +75 -0
- package/MultimodalTextbox.test.ts +69 -0
- package/MultimodalTextboxExample.stories.svelte +27 -0
- package/README.md +34 -0
- package/package.json +25 -0
- package/shared/MultimodalTextbox.svelte +421 -0
- package/shared/utils.ts +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @gradio/multimodaltextbox
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#7420](https://github.com/gradio-app/gradio/pull/7420) [`15da39f`](https://github.com/gradio-app/gradio/commit/15da39fca01d09a30cf47e7e72d7efa5052f61f8) - Multimodal Textbox (Chat Input Component). Thanks @dawoodkhan82!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/client@0.14.0
|
|
12
|
+
- @gradio/upload@0.8.0
|
|
13
|
+
- @gradio/image@0.9.7
|
package/Example.svelte
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { Image } from "@gradio/image/shared";
|
|
4
|
+
import type { FileData } from "@gradio/client";
|
|
5
|
+
|
|
6
|
+
export let value: { text: string; files: FileData[] } = {
|
|
7
|
+
text: "",
|
|
8
|
+
files: []
|
|
9
|
+
};
|
|
10
|
+
export let type: "gallery" | "table";
|
|
11
|
+
export let selected = false;
|
|
12
|
+
|
|
13
|
+
let size: number;
|
|
14
|
+
let el: HTMLDivElement;
|
|
15
|
+
|
|
16
|
+
function set_styles(element: HTMLElement, el_width: number): void {
|
|
17
|
+
if (!element || !el_width) return;
|
|
18
|
+
el.style.setProperty(
|
|
19
|
+
"--local-text-width",
|
|
20
|
+
`${el_width < 150 ? el_width : 200}px`
|
|
21
|
+
);
|
|
22
|
+
el.style.whiteSpace = "unset";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onMount(() => {
|
|
26
|
+
set_styles(el, size);
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<div
|
|
31
|
+
bind:clientWidth={size}
|
|
32
|
+
bind:this={el}
|
|
33
|
+
class:table={type === "table"}
|
|
34
|
+
class:gallery={type === "gallery"}
|
|
35
|
+
class:selected
|
|
36
|
+
>
|
|
37
|
+
<p>{value.text ? value.text : ""}</p>
|
|
38
|
+
{#each value.files as file}
|
|
39
|
+
{#if file.mime_type && file.mime_type.includes("image")}
|
|
40
|
+
<Image src={file.url} alt="" />
|
|
41
|
+
{:else}
|
|
42
|
+
{file.path}
|
|
43
|
+
{/if}
|
|
44
|
+
{/each}
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<style>
|
|
48
|
+
.gallery {
|
|
49
|
+
padding: var(--size-1) var(--size-2);
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: 20px;
|
|
53
|
+
overflow-x: auto;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
div {
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
min-width: var(--local-text-width);
|
|
59
|
+
|
|
60
|
+
white-space: nowrap;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
:global(img) {
|
|
64
|
+
width: 100px;
|
|
65
|
+
height: 100px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
div > :global(p) {
|
|
69
|
+
font-size: var(--text-lg);
|
|
70
|
+
white-space: normal;
|
|
71
|
+
}
|
|
72
|
+
</style>
|
package/Index.svelte
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
|
|
16
|
+
export let gradio: Gradio<{
|
|
17
|
+
change: typeof value;
|
|
18
|
+
submit: never;
|
|
19
|
+
blur: never;
|
|
20
|
+
select: SelectData;
|
|
21
|
+
input: never;
|
|
22
|
+
focus: never;
|
|
23
|
+
}>;
|
|
24
|
+
export let elem_id = "";
|
|
25
|
+
export let elem_classes: string[] = [];
|
|
26
|
+
export let visible = true;
|
|
27
|
+
export let value: { text: string; files: FileData[] } = {
|
|
28
|
+
text: "",
|
|
29
|
+
files: []
|
|
30
|
+
};
|
|
31
|
+
export let file_types: string[] | null = null;
|
|
32
|
+
export let lines: number;
|
|
33
|
+
export let placeholder = "";
|
|
34
|
+
export let label = "MultimodalTextbox";
|
|
35
|
+
export let info: string | undefined = undefined;
|
|
36
|
+
export let show_label: boolean;
|
|
37
|
+
export let max_lines: number;
|
|
38
|
+
export let container = true;
|
|
39
|
+
export let scale: number | null = null;
|
|
40
|
+
export let min_width: number | undefined = undefined;
|
|
41
|
+
export let submit_btn = "⌲";
|
|
42
|
+
export let loading_status: LoadingStatus | undefined = undefined;
|
|
43
|
+
export let value_is_output = false;
|
|
44
|
+
export let rtl = false;
|
|
45
|
+
export let text_align: "left" | "right" | undefined = undefined;
|
|
46
|
+
export let autofocus = false;
|
|
47
|
+
export let autoscroll = true;
|
|
48
|
+
export let interactive: boolean;
|
|
49
|
+
export let root: string;
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<Block
|
|
53
|
+
{visible}
|
|
54
|
+
{elem_id}
|
|
55
|
+
{elem_classes}
|
|
56
|
+
{scale}
|
|
57
|
+
{min_width}
|
|
58
|
+
allow_overflow={false}
|
|
59
|
+
padding={container}
|
|
60
|
+
>
|
|
61
|
+
{#if loading_status}
|
|
62
|
+
<StatusTracker
|
|
63
|
+
autoscroll={gradio.autoscroll}
|
|
64
|
+
i18n={gradio.i18n}
|
|
65
|
+
{...loading_status}
|
|
66
|
+
/>
|
|
67
|
+
{/if}
|
|
68
|
+
|
|
69
|
+
<MultimodalTextbox
|
|
70
|
+
bind:value
|
|
71
|
+
bind:value_is_output
|
|
72
|
+
{file_types}
|
|
73
|
+
{root}
|
|
74
|
+
{label}
|
|
75
|
+
{info}
|
|
76
|
+
{show_label}
|
|
77
|
+
{lines}
|
|
78
|
+
{rtl}
|
|
79
|
+
{text_align}
|
|
80
|
+
max_lines={!max_lines ? lines + 1 : max_lines}
|
|
81
|
+
{placeholder}
|
|
82
|
+
{submit_btn}
|
|
83
|
+
{autofocus}
|
|
84
|
+
{container}
|
|
85
|
+
{autoscroll}
|
|
86
|
+
on:change={() => gradio.dispatch("change", value)}
|
|
87
|
+
on:input={() => gradio.dispatch("input")}
|
|
88
|
+
on:submit={() => gradio.dispatch("submit")}
|
|
89
|
+
on:blur={() => gradio.dispatch("blur")}
|
|
90
|
+
on:select={(e) => gradio.dispatch("select", e.detail)}
|
|
91
|
+
on:focus={() => gradio.dispatch("focus")}
|
|
92
|
+
disabled={!interactive}
|
|
93
|
+
/>
|
|
94
|
+
</Block>
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import MultimodalTextbox from "./Index.svelte";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<Meta
|
|
7
|
+
title="Components/MultimodalTextbox"
|
|
8
|
+
component={MultimodalTextbox}
|
|
9
|
+
argTypes={{
|
|
10
|
+
label: {
|
|
11
|
+
control: "text",
|
|
12
|
+
description: "The textbox label",
|
|
13
|
+
name: "label"
|
|
14
|
+
},
|
|
15
|
+
show_label: {
|
|
16
|
+
options: [true, false],
|
|
17
|
+
description: "Whether to show the label",
|
|
18
|
+
control: { type: "boolean" },
|
|
19
|
+
defaultValue: true
|
|
20
|
+
},
|
|
21
|
+
text_align: {
|
|
22
|
+
options: ["left", "right"],
|
|
23
|
+
description: "Whether to align the text left or right",
|
|
24
|
+
control: { type: "select" },
|
|
25
|
+
defaultValue: "left"
|
|
26
|
+
},
|
|
27
|
+
lines: {
|
|
28
|
+
options: [1, 5, 10, 20],
|
|
29
|
+
description: "The number of lines to display in the textbox",
|
|
30
|
+
control: { type: "select" },
|
|
31
|
+
defaultValue: 1
|
|
32
|
+
},
|
|
33
|
+
max_lines: {
|
|
34
|
+
options: [1, 5, 10, 20],
|
|
35
|
+
description:
|
|
36
|
+
"The maximum number of lines to allow users to type in the textbox",
|
|
37
|
+
control: { type: "select" },
|
|
38
|
+
defaultValue: 1
|
|
39
|
+
},
|
|
40
|
+
rtl: {
|
|
41
|
+
options: [true, false],
|
|
42
|
+
description: "Whether to render right-to-left",
|
|
43
|
+
control: { type: "boolean" },
|
|
44
|
+
defaultValue: false
|
|
45
|
+
}
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
<Template let:args>
|
|
50
|
+
<MultimodalTextbox {...args} />
|
|
51
|
+
</Template>
|
|
52
|
+
|
|
53
|
+
<Story
|
|
54
|
+
name="MultimodalTextbox with file and label"
|
|
55
|
+
args={{
|
|
56
|
+
value: {
|
|
57
|
+
text: "sample text",
|
|
58
|
+
files: [
|
|
59
|
+
{
|
|
60
|
+
path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
|
61
|
+
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
|
62
|
+
orig_name: "cheetah.jpg"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
label: "My simple label",
|
|
67
|
+
show_label: true
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
<Story
|
|
71
|
+
name="MultimodalTextbox with 5 lines and max 5 lines"
|
|
72
|
+
args={{ lines: 5, max_lines: 5 }}
|
|
73
|
+
/>
|
|
74
|
+
<Story name="Right aligned textbox" args={{ text_align: "right" }} />
|
|
75
|
+
<Story name="RTL textbox" args={{ rtl: true }} />
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test, describe, assert, afterEach } from "vitest";
|
|
2
|
+
import { spy } from "tinyspy";
|
|
3
|
+
import { cleanup, fireEvent, render, get_text, wait } from "@gradio/tootils";
|
|
4
|
+
import event from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
import MultimodalTextbox from "./Index.svelte";
|
|
7
|
+
import type { LoadingStatus } from "@gradio/statustracker";
|
|
8
|
+
|
|
9
|
+
const loading_status: LoadingStatus = {
|
|
10
|
+
eta: 0,
|
|
11
|
+
queue_position: 1,
|
|
12
|
+
queue_size: 1,
|
|
13
|
+
status: "complete" as LoadingStatus["status"],
|
|
14
|
+
scroll_to_output: false,
|
|
15
|
+
visible: true,
|
|
16
|
+
fn_index: 0,
|
|
17
|
+
show_progress: "full"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("MultimodalTextbox", () => {
|
|
21
|
+
afterEach(() => cleanup());
|
|
22
|
+
|
|
23
|
+
test("renders provided value", async () => {
|
|
24
|
+
const { getByDisplayValue } = await render(MultimodalTextbox, {
|
|
25
|
+
show_label: true,
|
|
26
|
+
max_lines: 1,
|
|
27
|
+
loading_status,
|
|
28
|
+
lines: 1,
|
|
29
|
+
value: { text: "hello world", files: [] },
|
|
30
|
+
label: "Textbox",
|
|
31
|
+
interactive: false,
|
|
32
|
+
root: ""
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const item: HTMLInputElement = getByDisplayValue(
|
|
36
|
+
"hello world"
|
|
37
|
+
) as HTMLInputElement;
|
|
38
|
+
assert.equal(item.value, "hello world");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("changing the text should update the value", async () => {
|
|
42
|
+
const { component, getByDisplayValue, listen } = await render(
|
|
43
|
+
MultimodalTextbox,
|
|
44
|
+
{
|
|
45
|
+
show_label: true,
|
|
46
|
+
max_lines: 10,
|
|
47
|
+
loading_status,
|
|
48
|
+
lines: 1,
|
|
49
|
+
value: { text: "hi ", files: [] },
|
|
50
|
+
label: "MultimodalTextbox",
|
|
51
|
+
interactive: true,
|
|
52
|
+
root: ""
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const item: HTMLInputElement = getByDisplayValue("hi") as HTMLInputElement;
|
|
57
|
+
|
|
58
|
+
const mock = listen("change");
|
|
59
|
+
|
|
60
|
+
item.focus();
|
|
61
|
+
await event.keyboard("some text");
|
|
62
|
+
|
|
63
|
+
assert.equal(item.value, "hi some text");
|
|
64
|
+
assert.equal(component.value.text, "hi some text");
|
|
65
|
+
assert.equal(mock.callCount, 9);
|
|
66
|
+
assert.equal(mock.calls[8][0].detail.data.text, "hi some text");
|
|
67
|
+
assert.equal(mock.calls[8][0].detail.data.files.length, 0);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import MultimodalTextbox from "./Example.svelte";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<Meta
|
|
7
|
+
title="Components/MultimodalTextbox/Example"
|
|
8
|
+
component={MultimodalTextbox}
|
|
9
|
+
/>
|
|
10
|
+
|
|
11
|
+
<Template let:args>
|
|
12
|
+
<MultimodalTextbox {...args} />
|
|
13
|
+
</Template>
|
|
14
|
+
|
|
15
|
+
<Story
|
|
16
|
+
name="Text value"
|
|
17
|
+
args={{
|
|
18
|
+
value: { text: "the quick brown fox", files: [] }
|
|
19
|
+
}}
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
<Story
|
|
23
|
+
name="Empty Value"
|
|
24
|
+
args={{
|
|
25
|
+
value: { text: "", files: [] }
|
|
26
|
+
}}
|
|
27
|
+
/>
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# `@gradio/multimodaltextbox`
|
|
2
|
+
|
|
3
|
+
```html
|
|
4
|
+
<script>
|
|
5
|
+
import { BaseMultimodalTextbox, BaseExample } from "@gradio/multimodaltextbox";
|
|
6
|
+
</script>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
BaseMultimodalTextbox
|
|
10
|
+
```javascript
|
|
11
|
+
export let value = "";
|
|
12
|
+
export let value_is_output = false;
|
|
13
|
+
export let lines = 1;
|
|
14
|
+
export let placeholder = "Type here...";
|
|
15
|
+
export let label: string;
|
|
16
|
+
export let info: string | undefined = undefined;
|
|
17
|
+
export let disabled = false;
|
|
18
|
+
export let show_label = true;
|
|
19
|
+
export let container = true;
|
|
20
|
+
export let max_lines: number;
|
|
21
|
+
export let type: "text" | "password" | "email" = "text";
|
|
22
|
+
export let show_copy_button = false;
|
|
23
|
+
export let rtl = false;
|
|
24
|
+
export let autofocus = false;
|
|
25
|
+
export let text_align: "left" | "right" | undefined = undefined;
|
|
26
|
+
export let autoscroll = true;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
BaseExample
|
|
30
|
+
```javascript
|
|
31
|
+
export let value: string;
|
|
32
|
+
export let type: "gallery" | "table";
|
|
33
|
+
export let selected = false;
|
|
34
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gradio/multimodaltextbox",
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
".": "./Index.svelte",
|
|
13
|
+
"./example": "./Example.svelte",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@gradio/atoms": "^0.5.3",
|
|
18
|
+
"@gradio/icons": "^0.3.3",
|
|
19
|
+
"@gradio/upload": "^0.8.0",
|
|
20
|
+
"@gradio/utils": "^0.3.0",
|
|
21
|
+
"@gradio/image": "^0.9.7",
|
|
22
|
+
"@gradio/client": "^0.14.0",
|
|
23
|
+
"@gradio/statustracker": "^0.4.8"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
beforeUpdate,
|
|
4
|
+
afterUpdate,
|
|
5
|
+
createEventDispatcher,
|
|
6
|
+
tick
|
|
7
|
+
} from "svelte";
|
|
8
|
+
import { text_area_resize, resize } from "../shared/utils";
|
|
9
|
+
import { BlockTitle } from "@gradio/atoms";
|
|
10
|
+
import { Upload } from "@gradio/upload";
|
|
11
|
+
import { Image } from "@gradio/image/shared";
|
|
12
|
+
import type { FileData } from "@gradio/client";
|
|
13
|
+
import { Clear, File, Music, Video } from "@gradio/icons";
|
|
14
|
+
import type { SelectData } from "@gradio/utils";
|
|
15
|
+
|
|
16
|
+
export let value: { text: string; files: FileData[] } = {
|
|
17
|
+
text: "",
|
|
18
|
+
files: []
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export let value_is_output = false;
|
|
22
|
+
export let lines = 1;
|
|
23
|
+
export let placeholder = "Type here...";
|
|
24
|
+
export let disabled = false;
|
|
25
|
+
export let label: string;
|
|
26
|
+
export let info: string | undefined = undefined;
|
|
27
|
+
export let show_label = true;
|
|
28
|
+
export let container = true;
|
|
29
|
+
export let max_lines: number;
|
|
30
|
+
export let submit_btn = "⌲";
|
|
31
|
+
export let rtl = false;
|
|
32
|
+
export let autofocus = false;
|
|
33
|
+
export let text_align: "left" | "right" | undefined = undefined;
|
|
34
|
+
export let autoscroll = true;
|
|
35
|
+
export let root: string;
|
|
36
|
+
export let file_types: string[] | null = null;
|
|
37
|
+
|
|
38
|
+
let el: HTMLTextAreaElement | HTMLInputElement;
|
|
39
|
+
let can_scroll: boolean;
|
|
40
|
+
let previous_scroll_top = 0;
|
|
41
|
+
let user_has_scrolled_up = false;
|
|
42
|
+
let dragging = false;
|
|
43
|
+
let oldValue = value.text;
|
|
44
|
+
$: dispatch("drag", dragging);
|
|
45
|
+
|
|
46
|
+
$: if (oldValue !== value.text) {
|
|
47
|
+
dispatch("change", value);
|
|
48
|
+
oldValue = value.text;
|
|
49
|
+
}
|
|
50
|
+
let accept_file_types: string | null;
|
|
51
|
+
if (file_types == null) {
|
|
52
|
+
accept_file_types = null;
|
|
53
|
+
} else {
|
|
54
|
+
file_types = file_types.map((x) => {
|
|
55
|
+
if (x.startsWith(".")) {
|
|
56
|
+
return x;
|
|
57
|
+
}
|
|
58
|
+
return x + "/*";
|
|
59
|
+
});
|
|
60
|
+
accept_file_types = file_types.join(", ");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
$: if (value === null) value = { text: "", files: [] };
|
|
64
|
+
$: value, el && lines !== max_lines && resize(el, lines, max_lines);
|
|
65
|
+
|
|
66
|
+
const dispatch = createEventDispatcher<{
|
|
67
|
+
change: typeof value;
|
|
68
|
+
submit: undefined;
|
|
69
|
+
blur: undefined;
|
|
70
|
+
select: SelectData;
|
|
71
|
+
input: undefined;
|
|
72
|
+
focus: undefined;
|
|
73
|
+
drag: boolean;
|
|
74
|
+
upload: FileData[] | FileData;
|
|
75
|
+
clear: undefined;
|
|
76
|
+
load: FileData[] | FileData;
|
|
77
|
+
error: string;
|
|
78
|
+
}>();
|
|
79
|
+
|
|
80
|
+
beforeUpdate(() => {
|
|
81
|
+
can_scroll = el && el.offsetHeight + el.scrollTop > el.scrollHeight - 100;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const scroll = (): void => {
|
|
85
|
+
if (can_scroll && autoscroll && !user_has_scrolled_up) {
|
|
86
|
+
el.scrollTo(0, el.scrollHeight);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
async function handle_change(): Promise<void> {
|
|
91
|
+
dispatch("change", value);
|
|
92
|
+
if (!value_is_output) {
|
|
93
|
+
dispatch("input");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
afterUpdate(() => {
|
|
98
|
+
if (autofocus && el !== null) {
|
|
99
|
+
el.focus();
|
|
100
|
+
}
|
|
101
|
+
if (can_scroll && autoscroll) {
|
|
102
|
+
scroll();
|
|
103
|
+
}
|
|
104
|
+
value_is_output = false;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function handle_select(event: Event): void {
|
|
108
|
+
const target: HTMLTextAreaElement | HTMLInputElement = event.target as
|
|
109
|
+
| HTMLTextAreaElement
|
|
110
|
+
| HTMLInputElement;
|
|
111
|
+
const text = target.value;
|
|
112
|
+
const index: [number, number] = [
|
|
113
|
+
target.selectionStart as number,
|
|
114
|
+
target.selectionEnd as number
|
|
115
|
+
];
|
|
116
|
+
dispatch("select", { value: text.substring(...index), index: index });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function handle_keypress(e: KeyboardEvent): Promise<void> {
|
|
120
|
+
await tick();
|
|
121
|
+
if (e.key === "Enter" && e.shiftKey && lines > 1) {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
dispatch("submit");
|
|
124
|
+
} else if (
|
|
125
|
+
e.key === "Enter" &&
|
|
126
|
+
!e.shiftKey &&
|
|
127
|
+
lines === 1 &&
|
|
128
|
+
max_lines >= 1
|
|
129
|
+
) {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
dispatch("submit");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handle_scroll(event: Event): void {
|
|
136
|
+
const target = event.target as HTMLElement;
|
|
137
|
+
const current_scroll_top = target.scrollTop;
|
|
138
|
+
if (current_scroll_top < previous_scroll_top) {
|
|
139
|
+
user_has_scrolled_up = true;
|
|
140
|
+
}
|
|
141
|
+
previous_scroll_top = current_scroll_top;
|
|
142
|
+
|
|
143
|
+
const max_scroll_top = target.scrollHeight - target.clientHeight;
|
|
144
|
+
const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
|
|
145
|
+
if (user_has_scrolled_to_bottom) {
|
|
146
|
+
user_has_scrolled_up = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function handle_upload({
|
|
151
|
+
detail
|
|
152
|
+
}: CustomEvent<FileData | FileData[]>): Promise<void> {
|
|
153
|
+
handle_change();
|
|
154
|
+
if (Array.isArray(detail)) {
|
|
155
|
+
for (let file of detail) {
|
|
156
|
+
value.files.push(file);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
value.files.push(detail);
|
|
160
|
+
value = value;
|
|
161
|
+
}
|
|
162
|
+
await tick();
|
|
163
|
+
dispatch("change", value);
|
|
164
|
+
dispatch("upload", detail);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function remove_thumbnail(event: MouseEvent, index: number): void {
|
|
168
|
+
handle_change();
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
value.files.splice(index, 1);
|
|
171
|
+
value = value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let hidden_upload: HTMLInputElement;
|
|
175
|
+
|
|
176
|
+
function handle_upload_click(): void {
|
|
177
|
+
if (hidden_upload) {
|
|
178
|
+
hidden_upload.click();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function handle_submit(): Promise<void> {
|
|
183
|
+
dispatch("submit");
|
|
184
|
+
}
|
|
185
|
+
</script>
|
|
186
|
+
|
|
187
|
+
<!-- svelte-ignore a11y-autofocus -->
|
|
188
|
+
<label class:container>
|
|
189
|
+
<BlockTitle {show_label} {info}>{label}</BlockTitle>
|
|
190
|
+
<div class="input-container">
|
|
191
|
+
<Upload
|
|
192
|
+
on:load={handle_upload}
|
|
193
|
+
filetype={accept_file_types}
|
|
194
|
+
{root}
|
|
195
|
+
bind:dragging
|
|
196
|
+
disable_click={true}
|
|
197
|
+
bind:hidden_upload
|
|
198
|
+
>
|
|
199
|
+
{#if submit_btn}
|
|
200
|
+
<button class:disabled class="submit-button" on:click={handle_submit}
|
|
201
|
+
>{submit_btn}</button
|
|
202
|
+
>
|
|
203
|
+
{/if}
|
|
204
|
+
<button class:disabled class="plus-button" on:click={handle_upload_click}
|
|
205
|
+
>+</button
|
|
206
|
+
>
|
|
207
|
+
{#if value.files.length > 0}
|
|
208
|
+
<div
|
|
209
|
+
class="thumbnails scroll-hide"
|
|
210
|
+
data-testid="container_el"
|
|
211
|
+
style="display: {value.files.length > 0 ? 'flex' : 'none'};"
|
|
212
|
+
>
|
|
213
|
+
{#each value.files as file, index}
|
|
214
|
+
<button class="thumbnail-item thumbnail-small">
|
|
215
|
+
<button
|
|
216
|
+
class:disabled
|
|
217
|
+
class="delete-button"
|
|
218
|
+
on:click={(event) => remove_thumbnail(event, index)}
|
|
219
|
+
><Clear /></button
|
|
220
|
+
>
|
|
221
|
+
{#if file.mime_type && file.mime_type.includes("image")}
|
|
222
|
+
<Image
|
|
223
|
+
src={file.url}
|
|
224
|
+
title={null}
|
|
225
|
+
alt=""
|
|
226
|
+
loading="lazy"
|
|
227
|
+
class={"thumbnail-image"}
|
|
228
|
+
/>
|
|
229
|
+
{:else if file.mime_type && file.mime_type.includes("audio")}
|
|
230
|
+
<Music />
|
|
231
|
+
{:else if file.mime_type && file.mime_type.includes("video")}
|
|
232
|
+
<Video />
|
|
233
|
+
{:else}
|
|
234
|
+
<File />
|
|
235
|
+
{/if}
|
|
236
|
+
</button>
|
|
237
|
+
{/each}
|
|
238
|
+
</div>
|
|
239
|
+
{/if}
|
|
240
|
+
<textarea
|
|
241
|
+
data-testid="textbox"
|
|
242
|
+
use:text_area_resize={{
|
|
243
|
+
text: value.text,
|
|
244
|
+
lines: lines,
|
|
245
|
+
max_lines: max_lines
|
|
246
|
+
}}
|
|
247
|
+
class="scroll-hide"
|
|
248
|
+
dir={rtl ? "rtl" : "ltr"}
|
|
249
|
+
bind:value={value.text}
|
|
250
|
+
bind:this={el}
|
|
251
|
+
{placeholder}
|
|
252
|
+
rows={lines}
|
|
253
|
+
{disabled}
|
|
254
|
+
{autofocus}
|
|
255
|
+
on:keypress={handle_keypress}
|
|
256
|
+
on:blur
|
|
257
|
+
on:select={handle_select}
|
|
258
|
+
on:focus
|
|
259
|
+
on:scroll={handle_scroll}
|
|
260
|
+
style={text_align ? "text-align: " + text_align : ""}
|
|
261
|
+
/>
|
|
262
|
+
</Upload>
|
|
263
|
+
</div>
|
|
264
|
+
</label>
|
|
265
|
+
|
|
266
|
+
<style>
|
|
267
|
+
.input-container {
|
|
268
|
+
display: flex;
|
|
269
|
+
flex-direction: column;
|
|
270
|
+
align-items: center;
|
|
271
|
+
justify-content: center;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
textarea {
|
|
275
|
+
align-self: flex-start;
|
|
276
|
+
outline: none !important;
|
|
277
|
+
background: var(--input-background-fill);
|
|
278
|
+
padding: var(--input-padding);
|
|
279
|
+
width: 90%;
|
|
280
|
+
max-height: 100%;
|
|
281
|
+
height: 25px;
|
|
282
|
+
color: var(--body-text-color);
|
|
283
|
+
font-weight: var(--input-text-weight);
|
|
284
|
+
font-size: var(--input-text-size);
|
|
285
|
+
line-height: var(--line-sm);
|
|
286
|
+
border: none;
|
|
287
|
+
margin-top: 0px;
|
|
288
|
+
margin-bottom: 0px;
|
|
289
|
+
margin-left: 30px;
|
|
290
|
+
padding-top: 12px;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
textarea:disabled {
|
|
294
|
+
-webkit-text-fill-color: var(--body-text-color);
|
|
295
|
+
-webkit-opacity: 1;
|
|
296
|
+
opacity: 1;
|
|
297
|
+
width: 100%;
|
|
298
|
+
margin-left: 0px;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
textarea::placeholder {
|
|
302
|
+
color: var(--input-placeholder-color);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.plus-button,
|
|
306
|
+
.submit-button {
|
|
307
|
+
position: absolute;
|
|
308
|
+
background: var(--button-secondary-background-fill);
|
|
309
|
+
color: var(--button-secondary-text-color);
|
|
310
|
+
border: none;
|
|
311
|
+
text-align: center;
|
|
312
|
+
text-decoration: none;
|
|
313
|
+
font-size: 20px;
|
|
314
|
+
cursor: pointer;
|
|
315
|
+
border-radius: 50%;
|
|
316
|
+
width: 30px;
|
|
317
|
+
height: 30px;
|
|
318
|
+
bottom: 15px;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.plus-button:hover,
|
|
322
|
+
.submit-button:hover {
|
|
323
|
+
background: var(--button-secondary-background-fill-hover);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.plus-button:active,
|
|
327
|
+
.submit-button:active {
|
|
328
|
+
box-shadow: var(--button-shadow-active);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.submit-button {
|
|
332
|
+
right: 10px;
|
|
333
|
+
margin-left: 5px;
|
|
334
|
+
padding-bottom: 5px;
|
|
335
|
+
padding-left: 2px;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.plus-button {
|
|
339
|
+
left: 10px;
|
|
340
|
+
margin-right: 5px;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.thumbnails :global(img) {
|
|
344
|
+
width: var(--size-full);
|
|
345
|
+
height: var(--size-full);
|
|
346
|
+
object-fit: cover;
|
|
347
|
+
border-radius: var(--radius-lg);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.thumbnails {
|
|
351
|
+
align-self: flex-start;
|
|
352
|
+
display: flex;
|
|
353
|
+
justify-content: left;
|
|
354
|
+
align-items: center;
|
|
355
|
+
gap: var(--spacing-lg);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.thumbnail-item {
|
|
359
|
+
display: flex;
|
|
360
|
+
justify-content: center;
|
|
361
|
+
align-items: center;
|
|
362
|
+
--ring-color: transparent;
|
|
363
|
+
position: relative;
|
|
364
|
+
box-shadow:
|
|
365
|
+
0 0 0 2px var(--ring-color),
|
|
366
|
+
var(--shadow-drop);
|
|
367
|
+
border: 1px solid var(--border-color-primary);
|
|
368
|
+
border-radius: var(--radius-lg);
|
|
369
|
+
background: var(--background-fill-secondary);
|
|
370
|
+
aspect-ratio: var(--ratio-square);
|
|
371
|
+
width: var(--size-full);
|
|
372
|
+
height: var(--size-full);
|
|
373
|
+
cursor: default;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.thumbnail-small {
|
|
377
|
+
flex: none;
|
|
378
|
+
transform: scale(0.9);
|
|
379
|
+
transition: 0.075s;
|
|
380
|
+
width: var(--size-12);
|
|
381
|
+
height: var(--size-12);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.thumbnail-item :global(svg) {
|
|
385
|
+
width: 30px;
|
|
386
|
+
height: 30px;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.delete-button {
|
|
390
|
+
display: flex;
|
|
391
|
+
justify-content: center;
|
|
392
|
+
align-items: center;
|
|
393
|
+
position: absolute;
|
|
394
|
+
right: -7px;
|
|
395
|
+
top: -7px;
|
|
396
|
+
color: var(--button-secondary-text-color);
|
|
397
|
+
background: var(--button-secondary-background-fill);
|
|
398
|
+
border: none;
|
|
399
|
+
text-align: center;
|
|
400
|
+
text-decoration: none;
|
|
401
|
+
font-size: 10px;
|
|
402
|
+
cursor: pointer;
|
|
403
|
+
border-radius: 50%;
|
|
404
|
+
width: 20px;
|
|
405
|
+
height: 20px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.disabled {
|
|
409
|
+
display: none;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.delete-button :global(svg) {
|
|
413
|
+
width: 12px;
|
|
414
|
+
height: 12px;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.delete-button:hover {
|
|
418
|
+
filter: brightness(1.2);
|
|
419
|
+
border: 0.8px solid var(--color-grey-500);
|
|
420
|
+
}
|
|
421
|
+
</style>
|
package/shared/utils.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
let max =
|
|
18
|
+
max_lines === undefined
|
|
19
|
+
? false
|
|
20
|
+
: max_lines === undefined // default
|
|
21
|
+
? 21 * 11
|
|
22
|
+
: 21 * (max_lines + 1);
|
|
23
|
+
let min = 21 * (lines + 1);
|
|
24
|
+
|
|
25
|
+
target.style.height = "1px";
|
|
26
|
+
|
|
27
|
+
let scroll_height;
|
|
28
|
+
if (max && target.scrollHeight > max) {
|
|
29
|
+
scroll_height = max;
|
|
30
|
+
} else if (target.scrollHeight < min) {
|
|
31
|
+
scroll_height = min;
|
|
32
|
+
} else {
|
|
33
|
+
scroll_height = target.scrollHeight;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
target.style.height = `${scroll_height}px`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function text_area_resize(
|
|
40
|
+
_el: HTMLTextAreaElement,
|
|
41
|
+
_value: Value
|
|
42
|
+
): any | undefined {
|
|
43
|
+
if (_value.lines === _value.max_lines) return;
|
|
44
|
+
_el.style.overflowY = "scroll";
|
|
45
|
+
_el.addEventListener("input", (event: Event) =>
|
|
46
|
+
resize(event.target as HTMLTextAreaElement, _value.lines, _value.max_lines)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (!_value.text.trim()) return;
|
|
50
|
+
resize(_el, _value.lines, _value.max_lines);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
destroy: () =>
|
|
54
|
+
_el.removeEventListener("input", (e: Event) =>
|
|
55
|
+
resize(e.target as HTMLTextAreaElement, _value.lines, _value.max_lines)
|
|
56
|
+
)
|
|
57
|
+
};
|
|
58
|
+
}
|