@gradio/upload 0.17.9 → 0.18.0
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 +28 -0
- package/dist/src/Upload.svelte +17 -46
- package/dist/src/Upload.svelte.d.ts +2 -2
- package/dist/src/UploadProgress.svelte +1 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.js +24 -0
- package/package.json +4 -4
- package/src/Upload.svelte +17 -46
- package/src/UploadProgress.svelte +1 -2
- package/src/index.ts +1 -1
- package/src/utils.ts +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @gradio/upload
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#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!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/atoms@0.25.0
|
|
12
|
+
- @gradio/utils@0.13.0
|
|
13
|
+
- @gradio/client@2.3.0
|
|
14
|
+
|
|
15
|
+
## 0.17.10
|
|
16
|
+
|
|
17
|
+
### Dependency updates
|
|
18
|
+
|
|
19
|
+
- @gradio/client@2.2.2
|
|
20
|
+
|
|
21
|
+
## 0.17.10
|
|
22
|
+
|
|
23
|
+
### Fixes
|
|
24
|
+
|
|
25
|
+
- [#13336](https://github.com/gradio-app/gradio/pull/13336) [`14c8870`](https://github.com/gradio-app/gradio/commit/14c88701756c5fa57e8eaeac4df1385b9601da45) - Add UploadButton unit tests. Thanks @freddyaboulton!
|
|
26
|
+
|
|
27
|
+
### Dependency updates
|
|
28
|
+
|
|
29
|
+
- @gradio/client@2.2.1
|
|
30
|
+
|
|
3
31
|
## 0.17.9
|
|
4
32
|
|
|
5
33
|
### Dependency updates
|
package/dist/src/Upload.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { FileData } from "@gradio/client";
|
|
4
4
|
import { prepare_files, type Client } from "@gradio/client";
|
|
5
5
|
import UploadProgress from "./UploadProgress.svelte";
|
|
6
|
-
import { create_drag } from "./utils";
|
|
6
|
+
import { create_drag, is_valid_mimetype } from "./utils";
|
|
7
7
|
|
|
8
8
|
const { drag, open_file_upload: _open_file_upload } = create_drag();
|
|
9
9
|
|
|
@@ -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:
|
|
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
|
|
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 =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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);
|
|
@@ -160,40 +165,6 @@
|
|
|
160
165
|
return upload_promise;
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
function is_valid_mimetype(
|
|
164
|
-
file_accept: string | string[] | null,
|
|
165
|
-
uploaded_file_extension: string,
|
|
166
|
-
uploaded_file_type: string
|
|
167
|
-
): boolean {
|
|
168
|
-
if (
|
|
169
|
-
!file_accept ||
|
|
170
|
-
file_accept === "*" ||
|
|
171
|
-
file_accept === "file/*" ||
|
|
172
|
-
(Array.isArray(file_accept) &&
|
|
173
|
-
file_accept.some((accept) => accept === "*" || accept === "file/*"))
|
|
174
|
-
) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
let acceptArray: string[];
|
|
178
|
-
if (typeof file_accept === "string") {
|
|
179
|
-
acceptArray = file_accept.split(",").map((s) => s.trim());
|
|
180
|
-
} else if (Array.isArray(file_accept)) {
|
|
181
|
-
acceptArray = file_accept;
|
|
182
|
-
} else {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
acceptArray.includes(uploaded_file_extension) ||
|
|
188
|
-
acceptArray.some((type) => {
|
|
189
|
-
const [category] = type.split("/").map((s) => s.trim());
|
|
190
|
-
return (
|
|
191
|
-
type.endsWith("/*") && uploaded_file_type.startsWith(category + "/")
|
|
192
|
-
);
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
168
|
export async function load_files(
|
|
198
169
|
files: File[] | Blob[],
|
|
199
170
|
upload_id?: string
|
|
@@ -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:
|
|
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
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as Upload } from "./Upload.svelte";
|
|
2
2
|
export { default as ModifyUpload } from "./ModifyUpload.svelte";
|
|
3
3
|
export { default as UploadProgress } from "./UploadProgress.svelte";
|
|
4
|
-
export { create_drag } from "./utils";
|
|
4
|
+
export { create_drag, is_valid_mimetype } from "./utils";
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as Upload } from "./Upload.svelte";
|
|
2
2
|
export { default as ModifyUpload } from "./ModifyUpload.svelte";
|
|
3
3
|
export { default as UploadProgress } from "./UploadProgress.svelte";
|
|
4
|
-
export { create_drag } from "./utils";
|
|
4
|
+
export { create_drag, is_valid_mimetype } from "./utils";
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/utils.js
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
export function is_valid_mimetype(file_accept, uploaded_file_extension, uploaded_file_type) {
|
|
2
|
+
if (!file_accept ||
|
|
3
|
+
file_accept === "*" ||
|
|
4
|
+
file_accept === "file/*" ||
|
|
5
|
+
(Array.isArray(file_accept) &&
|
|
6
|
+
file_accept.some((accept) => accept === "*" || accept === "file/*"))) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
let acceptArray;
|
|
10
|
+
if (typeof file_accept === "string") {
|
|
11
|
+
acceptArray = file_accept.split(",").map((s) => s.trim());
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(file_accept)) {
|
|
14
|
+
acceptArray = file_accept;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return (acceptArray.includes(uploaded_file_extension) ||
|
|
20
|
+
acceptArray.some((type) => {
|
|
21
|
+
const [category] = type.split("/").map((s) => s.trim());
|
|
22
|
+
return (type.endsWith("/*") && uploaded_file_type.startsWith(category + "/"));
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
1
25
|
export function create_drag() {
|
|
2
26
|
let hidden_input;
|
|
3
27
|
let _options;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/upload",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
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/utils": "^0.12.2",
|
|
10
|
+
"@gradio/atoms": "^0.25.0",
|
|
12
11
|
"@gradio/icons": "^0.15.1",
|
|
13
|
-
"@gradio/client": "^2.
|
|
12
|
+
"@gradio/client": "^2.3.0",
|
|
13
|
+
"@gradio/utils": "^0.13.0"
|
|
14
14
|
},
|
|
15
15
|
"main_changeset": true,
|
|
16
16
|
"exports": {
|
package/src/Upload.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { FileData } from "@gradio/client";
|
|
4
4
|
import { prepare_files, type Client } from "@gradio/client";
|
|
5
5
|
import UploadProgress from "./UploadProgress.svelte";
|
|
6
|
-
import { create_drag } from "./utils";
|
|
6
|
+
import { create_drag, is_valid_mimetype } from "./utils";
|
|
7
7
|
|
|
8
8
|
const { drag, open_file_upload: _open_file_upload } = create_drag();
|
|
9
9
|
|
|
@@ -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:
|
|
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
|
|
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 =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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);
|
|
@@ -160,40 +165,6 @@
|
|
|
160
165
|
return upload_promise;
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
function is_valid_mimetype(
|
|
164
|
-
file_accept: string | string[] | null,
|
|
165
|
-
uploaded_file_extension: string,
|
|
166
|
-
uploaded_file_type: string
|
|
167
|
-
): boolean {
|
|
168
|
-
if (
|
|
169
|
-
!file_accept ||
|
|
170
|
-
file_accept === "*" ||
|
|
171
|
-
file_accept === "file/*" ||
|
|
172
|
-
(Array.isArray(file_accept) &&
|
|
173
|
-
file_accept.some((accept) => accept === "*" || accept === "file/*"))
|
|
174
|
-
) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
let acceptArray: string[];
|
|
178
|
-
if (typeof file_accept === "string") {
|
|
179
|
-
acceptArray = file_accept.split(",").map((s) => s.trim());
|
|
180
|
-
} else if (Array.isArray(file_accept)) {
|
|
181
|
-
acceptArray = file_accept;
|
|
182
|
-
} else {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
acceptArray.includes(uploaded_file_extension) ||
|
|
188
|
-
acceptArray.some((type) => {
|
|
189
|
-
const [category] = type.split("/").map((s) => s.trim());
|
|
190
|
-
return (
|
|
191
|
-
type.endsWith("/*") && uploaded_file_type.startsWith(category + "/")
|
|
192
|
-
);
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
168
|
export async function load_files(
|
|
198
169
|
files: File[] | Blob[],
|
|
199
170
|
upload_id?: string
|
|
@@ -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
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as Upload } from "./Upload.svelte";
|
|
2
2
|
export { default as ModifyUpload } from "./ModifyUpload.svelte";
|
|
3
3
|
export { default as UploadProgress } from "./UploadProgress.svelte";
|
|
4
|
-
export { create_drag } from "./utils";
|
|
4
|
+
export { create_drag, is_valid_mimetype } from "./utils";
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
export function is_valid_mimetype(
|
|
2
|
+
file_accept: string | string[] | null,
|
|
3
|
+
uploaded_file_extension: string,
|
|
4
|
+
uploaded_file_type: string
|
|
5
|
+
): boolean {
|
|
6
|
+
if (
|
|
7
|
+
!file_accept ||
|
|
8
|
+
file_accept === "*" ||
|
|
9
|
+
file_accept === "file/*" ||
|
|
10
|
+
(Array.isArray(file_accept) &&
|
|
11
|
+
file_accept.some((accept) => accept === "*" || accept === "file/*"))
|
|
12
|
+
) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
let acceptArray: string[];
|
|
16
|
+
if (typeof file_accept === "string") {
|
|
17
|
+
acceptArray = file_accept.split(",").map((s) => s.trim());
|
|
18
|
+
} else if (Array.isArray(file_accept)) {
|
|
19
|
+
acceptArray = file_accept;
|
|
20
|
+
} else {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
acceptArray.includes(uploaded_file_extension) ||
|
|
26
|
+
acceptArray.some((type) => {
|
|
27
|
+
const [category] = type.split("/").map((s) => s.trim());
|
|
28
|
+
return (
|
|
29
|
+
type.endsWith("/*") && uploaded_file_type.startsWith(category + "/")
|
|
30
|
+
);
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
1
35
|
interface DragActionOptions {
|
|
2
36
|
disable_click?: boolean;
|
|
3
37
|
accepted_types?: string | string[] | null;
|