@gradio/upload 0.18.0 → 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,17 @@
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
+
3
15
  ## 0.18.0
4
16
 
5
17
  ### Features
@@ -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,15 +1,15 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.18.0",
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/atoms": "^0.25.0",
11
- "@gradio/icons": "^0.15.1",
12
- "@gradio/client": "^2.3.0",
10
+ "@gradio/atoms": "^0.26.0",
11
+ "@gradio/icons": "^0.16.0",
12
+ "@gradio/client": "^2.3.1",
13
13
  "@gradio/utils": "^0.13.0"
14
14
  },
15
15
  "main_changeset": true,
@@ -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 {