@gradio/upload 0.17.10 → 0.18.1

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,35 @@
1
1
  # @gradio/upload
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Fixes
6
+
7
+ - [#13597](https://github.com/gradio-app/gradio/pull/13597) [`7a595cb`](https://github.com/gradio-app/gradio/commit/7a595cb72d8a82151ee2231e86d20c91d0bb9062) - Fix ImageEditor brush texture resets. Thanks @dawoodkhan82!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/icons@0.16.0
12
+ - @gradio/atoms@0.26.0
13
+ - @gradio/client@2.3.1
14
+
15
+ ## 0.18.0
16
+
17
+ ### Features
18
+
19
+ - [#13526](https://github.com/gradio-app/gradio/pull/13526) [`53cb4ca`](https://github.com/gradio-app/gradio/commit/53cb4cae1ec3521e9170d12867253516413ba37a) - Run `pnpm lint` and `pnpm ts:check` on CI. Thanks @abidlabs!
20
+
21
+ ### Dependency updates
22
+
23
+ - @gradio/atoms@0.25.0
24
+ - @gradio/utils@0.13.0
25
+ - @gradio/client@2.3.0
26
+
27
+ ## 0.17.10
28
+
29
+ ### Dependency updates
30
+
31
+ - @gradio/client@2.2.2
32
+
3
33
  ## 0.17.10
4
34
 
5
35
  ### Fixes
@@ -49,8 +49,8 @@
49
49
  icon_upload?: boolean;
50
50
  height?: number | string | undefined;
51
51
  aria_label?: string | undefined;
52
- upload_promise?: Promise<(FileData | null)[]>;
53
- onload?: (data: FileData | FileData[] | Blob | File) => void;
52
+ upload_promise?: Promise<(FileData | null)[]> | null;
53
+ onload?: (data: any) => void;
54
54
  onerror?: (error: string) => void;
55
55
  children?: import("svelte").Snippet;
56
56
  } = $props();
@@ -59,7 +59,7 @@
59
59
  _open_file_upload();
60
60
  }
61
61
 
62
- let upload_id: string = "";
62
+ let upload_id = "";
63
63
  let file_data: FileData[];
64
64
  let accept_file_types: string | null = $state(null);
65
65
  let use_post_upload_validation: boolean | null = null;
@@ -141,14 +141,19 @@
141
141
  uploading = true;
142
142
  upload_promise = new Promise(async (resolve) => {
143
143
  try {
144
- const _file_data = await upload(
145
- file_data,
146
- root,
147
- upload_id,
148
- max_file_size ?? Infinity
149
- );
150
- onload?.(file_count === "single" ? _file_data?.[0] : _file_data);
151
- resolve(_file_data || []);
144
+ const _file_data =
145
+ (await upload(
146
+ file_data,
147
+ root,
148
+ upload_id,
149
+ max_file_size ?? Infinity
150
+ )) || [];
151
+ if (file_count === "single") {
152
+ if (_file_data[0] !== undefined) onload?.(_file_data[0]);
153
+ } else {
154
+ onload?.(_file_data);
155
+ }
156
+ resolve(_file_data);
152
157
  uploading = false;
153
158
  } catch (e) {
154
159
  onerror?.((e as Error).message);
@@ -19,8 +19,8 @@ type $$ComponentProps = {
19
19
  icon_upload?: boolean;
20
20
  height?: number | string | undefined;
21
21
  aria_label?: string | undefined;
22
- upload_promise?: Promise<(FileData | null)[]>;
23
- onload?: (data: FileData | FileData[] | Blob | File) => void;
22
+ upload_promise?: Promise<(FileData | null)[]> | null;
23
+ onload?: (data: any) => void;
24
24
  onerror?: (error: string) => void;
25
25
  children?: import("svelte").Snippet;
26
26
  };
@@ -21,8 +21,6 @@
21
21
  let stream: Awaited<ReturnType<Client["stream"]>>;
22
22
  let progress = $state(false);
23
23
  let current_file_upload = $state<FileDataWithProgress>();
24
- let file_to_display = $derived(current_file_upload || files_with_progress[0]);
25
-
26
24
  let files_with_progress = $state<FileDataWithProgress[]>(
27
25
  files.map((file) => {
28
26
  return {
@@ -31,6 +29,7 @@
31
29
  };
32
30
  })
33
31
  );
32
+ let file_to_display = $derived(current_file_upload || files_with_progress[0]);
34
33
 
35
34
  function handleProgress(filename: string, chunk_size: number): void {
36
35
  // Find the corresponding file in the array and update its progress
@@ -1,6 +1,7 @@
1
1
  export declare function is_valid_mimetype(file_accept: string | string[] | null, uploaded_file_extension: string, uploaded_file_type: string): boolean;
2
2
  interface DragActionOptions {
3
3
  disable_click?: boolean;
4
+ ignore_click_selector?: string;
4
5
  accepted_types?: string | string[] | null;
5
6
  mode?: "single" | "multiple" | "directory";
6
7
  on_drag_change?: (dragging: boolean) => void;
package/dist/src/utils.js CHANGED
@@ -75,11 +75,17 @@ export function create_drag() {
75
75
  _options.on_files?.(files);
76
76
  }
77
77
  }
78
- function handle_click() {
79
- if (!_options.disable_click) {
80
- hidden_input.value = "";
81
- hidden_input.click();
78
+ function handle_click(e) {
79
+ const target = e.target;
80
+ const ignored_click_selector = _options.ignore_click_selector;
81
+ if (_options.disable_click ||
82
+ (ignored_click_selector &&
83
+ target instanceof Element &&
84
+ target.closest(ignored_click_selector) !== null)) {
85
+ return;
82
86
  }
87
+ hidden_input.value = "";
88
+ hidden_input.click();
83
89
  }
84
90
  function handle_file_input_change() {
85
91
  if (hidden_input.files) {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.17.10",
3
+ "version": "0.18.1",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "author": "",
8
8
  "license": "ISC",
9
9
  "dependencies": {
10
- "@gradio/icons": "^0.15.1",
11
- "@gradio/atoms": "^0.24.0",
12
- "@gradio/client": "^2.2.1",
13
- "@gradio/utils": "^0.12.2"
10
+ "@gradio/atoms": "^0.26.0",
11
+ "@gradio/icons": "^0.16.0",
12
+ "@gradio/client": "^2.3.1",
13
+ "@gradio/utils": "^0.13.0"
14
14
  },
15
15
  "main_changeset": true,
16
16
  "exports": {
package/src/Upload.svelte CHANGED
@@ -49,8 +49,8 @@
49
49
  icon_upload?: boolean;
50
50
  height?: number | string | undefined;
51
51
  aria_label?: string | undefined;
52
- upload_promise?: Promise<(FileData | null)[]>;
53
- onload?: (data: FileData | FileData[] | Blob | File) => void;
52
+ upload_promise?: Promise<(FileData | null)[]> | null;
53
+ onload?: (data: any) => void;
54
54
  onerror?: (error: string) => void;
55
55
  children?: import("svelte").Snippet;
56
56
  } = $props();
@@ -59,7 +59,7 @@
59
59
  _open_file_upload();
60
60
  }
61
61
 
62
- let upload_id: string = "";
62
+ let upload_id = "";
63
63
  let file_data: FileData[];
64
64
  let accept_file_types: string | null = $state(null);
65
65
  let use_post_upload_validation: boolean | null = null;
@@ -141,14 +141,19 @@
141
141
  uploading = true;
142
142
  upload_promise = new Promise(async (resolve) => {
143
143
  try {
144
- const _file_data = await upload(
145
- file_data,
146
- root,
147
- upload_id,
148
- max_file_size ?? Infinity
149
- );
150
- onload?.(file_count === "single" ? _file_data?.[0] : _file_data);
151
- resolve(_file_data || []);
144
+ const _file_data =
145
+ (await upload(
146
+ file_data,
147
+ root,
148
+ upload_id,
149
+ max_file_size ?? Infinity
150
+ )) || [];
151
+ if (file_count === "single") {
152
+ if (_file_data[0] !== undefined) onload?.(_file_data[0]);
153
+ } else {
154
+ onload?.(_file_data);
155
+ }
156
+ resolve(_file_data);
152
157
  uploading = false;
153
158
  } catch (e) {
154
159
  onerror?.((e as Error).message);
@@ -21,8 +21,6 @@
21
21
  let stream: Awaited<ReturnType<Client["stream"]>>;
22
22
  let progress = $state(false);
23
23
  let current_file_upload = $state<FileDataWithProgress>();
24
- let file_to_display = $derived(current_file_upload || files_with_progress[0]);
25
-
26
24
  let files_with_progress = $state<FileDataWithProgress[]>(
27
25
  files.map((file) => {
28
26
  return {
@@ -31,6 +29,7 @@
31
29
  };
32
30
  })
33
31
  );
32
+ let file_to_display = $derived(current_file_upload || files_with_progress[0]);
34
33
 
35
34
  function handleProgress(filename: string, chunk_size: number): void {
36
35
  // Find the corresponding file in the array and update its progress
@@ -0,0 +1,48 @@
1
+ import { afterEach, describe, expect, test, vi } from "vitest";
2
+ import { create_drag } from "./utils";
3
+
4
+ describe("create_drag", () => {
5
+ afterEach(() => {
6
+ document.body.innerHTML = "";
7
+ vi.restoreAllMocks();
8
+ });
9
+
10
+ test("does not open the file input when an ignored child is clicked", () => {
11
+ const click = vi
12
+ .spyOn(HTMLInputElement.prototype, "click")
13
+ .mockImplementation(() => {});
14
+ const node = document.createElement("div");
15
+ const toolbar = document.createElement("div");
16
+ const button = document.createElement("button");
17
+
18
+ toolbar.className = "toolbar-wrap";
19
+ toolbar.appendChild(button);
20
+ node.appendChild(toolbar);
21
+ document.body.appendChild(node);
22
+
23
+ const { drag } = create_drag();
24
+ const action = drag(node, { ignore_click_selector: ".toolbar-wrap" });
25
+
26
+ button.click();
27
+
28
+ expect(click).not.toHaveBeenCalled();
29
+ action.destroy();
30
+ });
31
+
32
+ test("opens the file input when the dropzone is clicked", () => {
33
+ const click = vi
34
+ .spyOn(HTMLInputElement.prototype, "click")
35
+ .mockImplementation(() => {});
36
+ const node = document.createElement("div");
37
+
38
+ document.body.appendChild(node);
39
+
40
+ const { drag } = create_drag();
41
+ const action = drag(node, { ignore_click_selector: ".toolbar-wrap" });
42
+
43
+ node.click();
44
+
45
+ expect(click).toHaveBeenCalledOnce();
46
+ action.destroy();
47
+ });
48
+ });
package/src/utils.ts CHANGED
@@ -34,6 +34,7 @@ export function is_valid_mimetype(
34
34
 
35
35
  interface DragActionOptions {
36
36
  disable_click?: boolean;
37
+ ignore_click_selector?: string;
37
38
  accepted_types?: string | string[] | null;
38
39
  mode?: "single" | "multiple" | "directory";
39
40
  on_drag_change?: (dragging: boolean) => void;
@@ -116,11 +117,20 @@ export function create_drag(): {
116
117
  }
117
118
  }
118
119
 
119
- function handle_click(): void {
120
- if (!_options.disable_click) {
121
- hidden_input.value = "";
122
- hidden_input.click();
120
+ function handle_click(e: MouseEvent): void {
121
+ const target = e.target;
122
+ const ignored_click_selector = _options.ignore_click_selector;
123
+ if (
124
+ _options.disable_click ||
125
+ (ignored_click_selector &&
126
+ target instanceof Element &&
127
+ target.closest(ignored_click_selector) !== null)
128
+ ) {
129
+ return;
123
130
  }
131
+
132
+ hidden_input.value = "";
133
+ hidden_input.click();
124
134
  }
125
135
 
126
136
  function handle_file_input_change(): void {