@gradio/upload 0.5.2 → 0.5.4
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 -1
- package/package.json +5 -5
- package/src/Upload.svelte +32 -11
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @gradio/upload
|
2
2
|
|
3
|
+
## 0.5.4
|
4
|
+
|
5
|
+
### Fixes
|
6
|
+
|
7
|
+
- [#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)!
|
8
|
+
|
9
|
+
## 0.5.3
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
- [#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)!
|
14
|
+
|
3
15
|
## 0.5.2
|
4
16
|
|
5
17
|
### Patch Changes
|
@@ -255,4 +267,4 @@ From the backend, streamed outputs are served from the `/stream/` endpoint inste
|
|
255
267
|
### Patch Changes
|
256
268
|
|
257
269
|
- Updated dependencies []:
|
258
|
-
- @gradio/atoms@0.0.2
|
270
|
+
- @gradio/atoms@0.0.2
|
package/package.json
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/upload",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.4",
|
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.
|
11
|
-
"@gradio/icons": "^0.3.
|
12
|
-
"@gradio/upload": "^0.5.
|
13
|
-
"@gradio/client": "^0.
|
10
|
+
"@gradio/atoms": "^0.4.0",
|
11
|
+
"@gradio/icons": "^0.3.2",
|
12
|
+
"@gradio/upload": "^0.5.4",
|
13
|
+
"@gradio/client": "^0.9.1",
|
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
|
-
|
97
|
+
if (typeof file_accept === "string" && file_accept.endsWith("/*")) {
|
98
|
+
file_accept = file_accept.split(",");
|
87
99
|
}
|
88
|
-
if (
|
89
|
-
return
|
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,19 +114,22 @@
|
|
96
114
|
if (!e.dataTransfer?.files) return;
|
97
115
|
|
98
116
|
const files_to_load = Array.from(e.dataTransfer.files).filter((f) => {
|
99
|
-
|
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>
|
109
128
|
|
110
129
|
{#if uploading}
|
111
|
-
|
130
|
+
{#if !hidden}
|
131
|
+
<UploadProgress {root} {upload_id} files={file_data} />
|
132
|
+
{/if}
|
112
133
|
{:else}
|
113
134
|
<button
|
114
135
|
class:hidden
|
@@ -135,7 +156,7 @@
|
|
135
156
|
type="file"
|
136
157
|
bind:this={hidden_upload}
|
137
158
|
on:change={load_files_from_upload}
|
138
|
-
accept={
|
159
|
+
accept={accept_file_types}
|
139
160
|
multiple={file_count === "multiple" || undefined}
|
140
161
|
webkitdirectory={file_count === "directory" || undefined}
|
141
162
|
mozdirectory={file_count === "directory" || undefined}
|