@gradio/upload 0.5.3 → 0.5.5

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,10 +1,24 @@
1
1
  # @gradio/upload
2
2
 
3
+ ## 0.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`245d58e`](https://github.com/gradio-app/gradio/commit/245d58eff788e8d44a59d37a2d9b26d0f08a62b4)]:
8
+ - @gradio/client@0.9.2
9
+ - @gradio/upload@0.5.5
10
+
11
+ ## 0.5.4
12
+
13
+ ### Fixes
14
+
15
+ - [#6525](https://github.com/gradio-app/gradio/pull/6525) [`5d51fbc`](https://github.com/gradio-app/gradio/commit/5d51fbce7826da840a2fd4940feb5d9ad6f1bc5a) - Fixes Drag and Drop for Upload. Thanks [@dawoodkhan82](https://github.com/dawoodkhan82)!
16
+
3
17
  ## 0.5.3
4
18
 
5
19
  ### Fixes
6
20
 
7
- - [#6709](https://github.com/gradio-app/gradio/pull/6709) [`6a9151d`](https://github.com/gradio-app/gradio/commit/6a9151d5c9432c724098da7d88a539aaaf5ffe88) - Remove progress animation on streaming. Thanks [@aliabid94](https://github.com/aliabid94)!
21
+ - [#6709](https://github.com/gradio-app/gradio/pull/6709) [`6a9151d`](https://github.com/gradio-app/gradio/commit/6a9151d5c9432c724098da7d88a539aaaf5ffe88) - Remove progress animation on streaming. Thanks [@aliabid94](https://github.com/aliabid94)!
8
22
 
9
23
  ## 0.5.2
10
24
 
@@ -261,4 +275,4 @@ From the backend, streamed outputs are served from the `/stream/` endpoint inste
261
275
  ### Patch Changes
262
276
 
263
277
  - Updated dependencies []:
264
- - @gradio/atoms@0.0.2
278
+ - @gradio/atoms@0.0.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -8,9 +8,9 @@
8
8
  "license": "ISC",
9
9
  "dependencies": {
10
10
  "@gradio/atoms": "^0.4.0",
11
- "@gradio/client": "^0.9.0",
12
11
  "@gradio/icons": "^0.3.2",
13
- "@gradio/upload": "^0.5.3",
12
+ "@gradio/client": "^0.9.2",
13
+ "@gradio/upload": "^0.5.5",
14
14
  "@gradio/utils": "^0.2.0"
15
15
  },
16
16
  "main_changeset": true,
package/src/Upload.svelte CHANGED
@@ -5,7 +5,7 @@
5
5
  import { _ } from "svelte-i18n";
6
6
  import UploadProgress from "./UploadProgress.svelte";
7
7
 
8
- export let filetype: string | null = null;
8
+ export let filetype: string | string[] | null = null;
9
9
  export let dragging = false;
10
10
  export let boundedheight = true;
11
11
  export let center = true;
@@ -20,6 +20,7 @@
20
20
 
21
21
  let upload_id: string;
22
22
  let file_data: FileData[];
23
+ let accept_file_types: string | null;
23
24
 
24
25
  // Needed for wasm support
25
26
  const upload_fn = getContext<typeof upload_files>("upload_files");
@@ -28,6 +29,17 @@
28
29
 
29
30
  const dispatch = createEventDispatcher();
30
31
 
32
+ $: if (filetype == null || typeof filetype === "string") {
33
+ accept_file_types = filetype;
34
+ } else {
35
+ filetype = filetype.map((x) => {
36
+ if (x.startsWith(".")) {
37
+ return x;
38
+ }
39
+ return x + "/*";
40
+ });
41
+ accept_file_types = filetype.join(", ");
42
+ }
31
43
  function updateDragging(): void {
32
44
  dragging = !dragging;
33
45
  }
@@ -76,17 +88,23 @@
76
88
  }
77
89
 
78
90
  function is_valid_mimetype(
79
- file_accept: string | null,
91
+ file_accept: string | string[] | null,
80
92
  mime_type: string
81
93
  ): boolean {
82
- if (!file_accept) {
94
+ if (!file_accept || file_accept === "*" || file_accept === "file/*") {
83
95
  return true;
84
96
  }
85
- if (file_accept === "*") {
86
- return true;
97
+ if (typeof file_accept === "string" && file_accept.endsWith("/*")) {
98
+ file_accept = file_accept.split(",");
87
99
  }
88
- if (file_accept.endsWith("/*")) {
89
- return mime_type.startsWith(file_accept.slice(0, -1));
100
+ if (Array.isArray(file_accept)) {
101
+ return (
102
+ file_accept.includes(mime_type) ||
103
+ file_accept.some((type) => {
104
+ const [category] = type.split("/");
105
+ return type.endsWith("/*") && mime_type.startsWith(category + "/");
106
+ })
107
+ );
90
108
  }
91
109
  return file_accept === mime_type;
92
110
  }
@@ -96,13 +114,14 @@
96
114
  if (!e.dataTransfer?.files) return;
97
115
 
98
116
  const files_to_load = Array.from(e.dataTransfer.files).filter((f) => {
99
- if (filetype?.split(",").some((m) => is_valid_mimetype(m, f.type))) {
117
+ const file_extension =
118
+ f.type !== "" ? f.type : "." + f.name.split(".").pop();
119
+ if (file_extension && is_valid_mimetype(filetype, file_extension)) {
100
120
  return true;
101
121
  }
102
122
  dispatch("error", `Invalid file type only ${filetype} allowed.`);
103
123
  return false;
104
124
  });
105
-
106
125
  await load_files(files_to_load);
107
126
  }
108
127
  </script>
@@ -137,7 +156,7 @@
137
156
  type="file"
138
157
  bind:this={hidden_upload}
139
158
  on:change={load_files_from_upload}
140
- accept={filetype}
159
+ accept={accept_file_types}
141
160
  multiple={file_count === "multiple" || undefined}
142
161
  webkitdirectory={file_count === "directory" || undefined}
143
162
  mozdirectory={file_count === "directory" || undefined}