@gradio/multimodaltextbox 0.2.1 → 0.2.3

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @gradio/multimodaltextbox
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Features
6
+
7
+ - [#7875](https://github.com/gradio-app/gradio/pull/7875) [`e6d051d`](https://github.com/gradio-app/gradio/commit/e6d051dc8a497fdd6b4cfbd57efd4c8015b97a66) - Paste Images into MultimodalTextbox. Thanks @abidlabs!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/upload@0.8.3
12
+ - @gradio/client@0.15.0
13
+ - @gradio/image@0.9.10
14
+
15
+ ## 0.2.2
16
+
17
+ ### Fixes
18
+
19
+ - [#7848](https://github.com/gradio-app/gradio/pull/7848) [`8d7b3ca`](https://github.com/gradio-app/gradio/commit/8d7b3caebd8f95b1372f8412cadbb5862766c365) - Multimodal Textbox Loading + other fixes. Thanks @dawoodkhan82!
20
+
21
+ ### Dependency updates
22
+
23
+ - @gradio/atoms@0.6.1
24
+ - @gradio/statustracker@0.4.10
25
+ - @gradio/icons@0.3.4
26
+ - @gradio/upload@0.8.2
27
+ - @gradio/image@0.9.9
28
+
3
29
  ## 0.2.1
4
30
 
5
31
  ### Dependency updates
package/Index.svelte CHANGED
@@ -38,7 +38,7 @@
38
38
  export let container = true;
39
39
  export let scale: number | null = null;
40
40
  export let min_width: number | undefined = undefined;
41
- export let submit_btn = "⌲";
41
+ export let submit_btn: string | null = null;
42
42
  export let loading_status: LoadingStatus | undefined = undefined;
43
43
  export let value_is_output = false;
44
44
  export let rtl = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/multimodaltextbox",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -14,12 +14,12 @@
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "dependencies": {
17
- "@gradio/atoms": "^0.6.0",
18
- "@gradio/statustracker": "^0.4.9",
19
- "@gradio/icons": "^0.3.3",
17
+ "@gradio/atoms": "^0.6.1",
18
+ "@gradio/icons": "^0.3.4",
20
19
  "@gradio/utils": "^0.3.0",
21
- "@gradio/upload": "^0.8.1",
22
- "@gradio/image": "^0.9.8",
23
- "@gradio/client": "^0.14.0"
20
+ "@gradio/statustracker": "^0.4.10",
21
+ "@gradio/upload": "^0.8.3",
22
+ "@gradio/image": "^0.9.10",
23
+ "@gradio/client": "^0.15.0"
24
24
  }
25
25
  }
@@ -9,8 +9,8 @@
9
9
  import { BlockTitle } from "@gradio/atoms";
10
10
  import { Upload } from "@gradio/upload";
11
11
  import { Image } from "@gradio/image/shared";
12
- import type { FileData } from "@gradio/client";
13
- import { Clear, File, Music, Video } from "@gradio/icons";
12
+ import type { FileData, upload } from "@gradio/client";
13
+ import { Clear, File, Music, Video, Send } from "@gradio/icons";
14
14
  import type { SelectData } from "@gradio/utils";
15
15
 
16
16
  export let value: { text: string; files: FileData[] } = {
@@ -27,7 +27,7 @@
27
27
  export let show_label = true;
28
28
  export let container = true;
29
29
  export let max_lines: number;
30
- export let submit_btn = "⌲";
30
+ export let submit_btn: string | null = null;
31
31
  export let rtl = false;
32
32
  export let autofocus = false;
33
33
  export let text_align: "left" | "right" | undefined = undefined;
@@ -35,11 +35,14 @@
35
35
  export let root: string;
36
36
  export let file_types: string[] | null = null;
37
37
 
38
+ let upload_component: Upload;
39
+ let hidden_upload: HTMLInputElement;
38
40
  let el: HTMLTextAreaElement | HTMLInputElement;
39
41
  let can_scroll: boolean;
40
42
  let previous_scroll_top = 0;
41
43
  let user_has_scrolled_up = false;
42
44
  let dragging = false;
45
+ let uploading = false;
43
46
  let oldValue = value.text;
44
47
  $: dispatch("drag", dragging);
45
48
 
@@ -171,8 +174,6 @@
171
174
  value = value;
172
175
  }
173
176
 
174
- let hidden_upload: HTMLInputElement;
175
-
176
177
  function handle_upload_click(): void {
177
178
  if (hidden_upload) {
178
179
  hidden_upload.click();
@@ -182,6 +183,18 @@
182
183
  async function handle_submit(): Promise<void> {
183
184
  dispatch("submit");
184
185
  }
186
+
187
+ function handle_paste(event: ClipboardEvent): void {
188
+ if (!event.clipboardData) return;
189
+ const items = event.clipboardData.items;
190
+ for (let index in items) {
191
+ const item = items[index];
192
+ if (item.kind === "file" && item.type.includes("image")) {
193
+ const blob = item.getAsFile();
194
+ if (blob) upload_component.load_files([blob]);
195
+ }
196
+ }
197
+ }
185
198
  </script>
186
199
 
187
200
  <!-- svelte-ignore a11y-autofocus -->
@@ -189,26 +202,34 @@
189
202
  <BlockTitle {show_label} {info}>{label}</BlockTitle>
190
203
  <div class="input-container">
191
204
  <Upload
205
+ bind:this={upload_component}
192
206
  on:load={handle_upload}
193
207
  filetype={accept_file_types}
194
208
  {root}
195
209
  bind:dragging
210
+ bind:uploading
196
211
  disable_click={true}
197
212
  bind:hidden_upload
198
213
  >
199
- {#if submit_btn}
214
+ {#if submit_btn !== null}
200
215
  <button class:disabled class="submit-button" on:click={handle_submit}
201
216
  >{submit_btn}</button
202
217
  >
218
+ {:else}
219
+ <button class:disabled class="submit-button" on:click={handle_submit}
220
+ ><Send /></button
221
+ >
203
222
  {/if}
204
223
  <button class:disabled class="plus-button" on:click={handle_upload_click}
205
224
  >+</button
206
225
  >
207
- {#if value.files.length > 0}
226
+ {#if value.files.length > 0 || uploading}
208
227
  <div
209
228
  class="thumbnails scroll-hide"
210
229
  data-testid="container_el"
211
- style="display: {value.files.length > 0 ? 'flex' : 'none'};"
230
+ style="display: {value.files.length > 0 || uploading
231
+ ? 'flex'
232
+ : 'none'};"
212
233
  >
213
234
  {#each value.files as file, index}
214
235
  <button class="thumbnail-item thumbnail-small">
@@ -235,6 +256,9 @@
235
256
  {/if}
236
257
  </button>
237
258
  {/each}
259
+ {#if uploading}
260
+ <div class="loader"></div>
261
+ {/if}
238
262
  </div>
239
263
  {/if}
240
264
  <textarea
@@ -257,6 +281,7 @@
257
281
  on:select={handle_select}
258
282
  on:focus
259
283
  on:scroll={handle_scroll}
284
+ on:paste={handle_paste}
260
285
  style={text_align ? "text-align: " + text_align : ""}
261
286
  />
262
287
  </Upload>
@@ -288,6 +313,7 @@
288
313
  margin-bottom: 0px;
289
314
  margin-left: 30px;
290
315
  padding-top: 12px;
316
+ resize: none;
291
317
  }
292
318
 
293
319
  textarea:disabled {
@@ -335,11 +361,41 @@
335
361
  padding-left: 2px;
336
362
  }
337
363
 
364
+ .submit-button :global(svg) {
365
+ height: 23px;
366
+ width: 23px;
367
+ padding-left: 4px;
368
+ padding-top: 2px;
369
+ }
370
+
338
371
  .plus-button {
339
372
  left: 10px;
340
373
  margin-right: 5px;
341
374
  }
342
375
 
376
+ .loader {
377
+ display: flex;
378
+ justify-content: center;
379
+ align-items: center;
380
+ --ring-color: transparent;
381
+ position: relative;
382
+ border: 5px solid #f3f3f3;
383
+ border-top: 5px solid var(--color-accent);
384
+ border-radius: 50%;
385
+ width: 25px;
386
+ height: 25px;
387
+ animation: spin 2s linear infinite;
388
+ }
389
+
390
+ @keyframes spin {
391
+ 0% {
392
+ transform: rotate(0deg);
393
+ }
394
+ 100% {
395
+ transform: rotate(360deg);
396
+ }
397
+ }
398
+
343
399
  .thumbnails :global(img) {
344
400
  width: var(--size-full);
345
401
  height: var(--size-full);