@gradio/uploadbutton 0.10.2 → 0.11.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 +39 -0
- package/Index.svelte +1 -1
- package/UploadButton.test.ts +21 -25
- package/dist/Index.svelte +1 -1
- package/dist/shared/UploadButton.svelte +14 -5
- package/package.json +6 -6
- package/shared/UploadButton.svelte +14 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @gradio/uploadbutton
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [`db9699e`](https://github.com/gradio-app/gradio/commit/db9699e0bfd364ef7ca104e348618cf235d1d0be) - Name rejected files in upload errors and fix a Document leak in sanitize. Thanks @abidlabs!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/upload@0.19.0
|
|
12
|
+
- @gradio/client@2.7.1
|
|
13
|
+
- @gradio/button@0.8.3
|
|
14
|
+
|
|
15
|
+
## 0.10.2
|
|
16
|
+
|
|
17
|
+
### Dependency updates
|
|
18
|
+
|
|
19
|
+
- @gradio/utils@0.14.2
|
|
20
|
+
- @gradio/client@2.7.0
|
|
21
|
+
|
|
22
|
+
## 0.10.2
|
|
23
|
+
|
|
24
|
+
### Dependency updates
|
|
25
|
+
|
|
26
|
+
- @gradio/client@2.6.0
|
|
27
|
+
- @gradio/utils@0.14.1
|
|
28
|
+
- @gradio/upload@0.18.3
|
|
29
|
+
|
|
30
|
+
## 0.10.2
|
|
31
|
+
|
|
32
|
+
### Dependency updates
|
|
33
|
+
|
|
34
|
+
- @gradio/client@2.5.1
|
|
35
|
+
|
|
36
|
+
## 0.10.2
|
|
37
|
+
|
|
38
|
+
### Dependency updates
|
|
39
|
+
|
|
40
|
+
- @gradio/client@2.5.0
|
|
41
|
+
|
|
3
42
|
## 0.10.2
|
|
4
43
|
|
|
5
44
|
### Dependency updates
|
package/Index.svelte
CHANGED
package/UploadButton.test.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
upload_file,
|
|
7
7
|
mock_client,
|
|
8
8
|
TEST_TXT,
|
|
9
|
-
TEST_JPG
|
|
9
|
+
TEST_JPG,
|
|
10
|
+
TEST_PDF
|
|
10
11
|
} from "@self/tootils/render";
|
|
11
12
|
import { run_shared_prop_tests } from "@self/tootils/shared-prop-tests";
|
|
12
13
|
import event from "@testing-library/user-event";
|
|
@@ -176,6 +177,25 @@ describe("Props: file_types", () => {
|
|
|
176
177
|
expect(upload).not.toHaveBeenCalled();
|
|
177
178
|
});
|
|
178
179
|
|
|
180
|
+
test("reports rejected filenames together while uploading valid files", async () => {
|
|
181
|
+
const { listen, get_data } = await render(UploadButton, {
|
|
182
|
+
...upload_props,
|
|
183
|
+
file_count: "multiple",
|
|
184
|
+
file_types: [".txt"]
|
|
185
|
+
});
|
|
186
|
+
const error = listen("error");
|
|
187
|
+
const upload = listen("upload");
|
|
188
|
+
await upload_file([TEST_JPG, TEST_TXT, TEST_PDF]);
|
|
189
|
+
await waitFor(() => expect(upload).toHaveBeenCalledTimes(1));
|
|
190
|
+
expect(error).toHaveBeenCalledTimes(1);
|
|
191
|
+
expect(error).toHaveBeenCalledWith(
|
|
192
|
+
`Invalid file types: ${TEST_JPG.orig_name}, ${TEST_PDF.orig_name}. Only .txt allowed.`
|
|
193
|
+
);
|
|
194
|
+
expect((await get_data()).value).toEqual([
|
|
195
|
+
expect.objectContaining({ orig_name: TEST_TXT.orig_name })
|
|
196
|
+
]);
|
|
197
|
+
});
|
|
198
|
+
|
|
179
199
|
test("accepts files matching a wildcard MIME category", async () => {
|
|
180
200
|
const { listen } = await render(UploadButton, {
|
|
181
201
|
...upload_props,
|
|
@@ -410,27 +430,3 @@ describe("Edge cases", () => {
|
|
|
410
430
|
expect(upload).not.toHaveBeenCalled();
|
|
411
431
|
});
|
|
412
432
|
});
|
|
413
|
-
|
|
414
|
-
test.todo(
|
|
415
|
-
"VISUAL: variant='primary' renders the button with primary styling — needs Playwright visual regression screenshot comparison"
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
test.todo(
|
|
419
|
-
"VISUAL: variant='secondary' renders the button with secondary styling — needs Playwright visual regression screenshot comparison"
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
test.todo(
|
|
423
|
-
"VISUAL: variant='stop' renders the button with stop/red styling — needs Playwright visual regression screenshot comparison"
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
test.todo(
|
|
427
|
-
"VISUAL: size='sm' renders a small button — needs Playwright visual regression screenshot comparison"
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
test.todo(
|
|
431
|
-
"VISUAL: size='md' renders a medium button — needs Playwright visual regression screenshot comparison"
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
test.todo(
|
|
435
|
-
"VISUAL: size='lg' renders a large button — needs Playwright visual regression screenshot comparison"
|
|
436
|
-
);
|
package/dist/Index.svelte
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { tick } from "svelte";
|
|
3
3
|
import { BaseButton } from "@gradio/button";
|
|
4
4
|
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
invalid_file_type_message,
|
|
7
|
+
is_valid_mimetype,
|
|
8
|
+
to_accept_attribute
|
|
9
|
+
} from "@gradio/upload";
|
|
6
10
|
|
|
7
11
|
let {
|
|
8
12
|
elem_id = "",
|
|
@@ -71,14 +75,19 @@
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
async function load_files(files: FileList): Promise<void> {
|
|
78
|
+
const invalid_files: File[] = [];
|
|
74
79
|
let _files: File[] = Array.from(files).filter((file) => {
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
if (
|
|
81
|
+
is_valid_mimetype(accept_file_types, file.name.toLowerCase(), file.type)
|
|
82
|
+
) {
|
|
77
83
|
return true;
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
invalid_files.push(file);
|
|
80
86
|
return false;
|
|
81
87
|
});
|
|
88
|
+
if (invalid_files.length) {
|
|
89
|
+
onerror?.(invalid_file_type_message(invalid_files, file_types));
|
|
90
|
+
}
|
|
82
91
|
|
|
83
92
|
if (!_files.length) {
|
|
84
93
|
return;
|
|
@@ -118,7 +127,7 @@
|
|
|
118
127
|
|
|
119
128
|
<input
|
|
120
129
|
class="hide"
|
|
121
|
-
accept={accept_file_types}
|
|
130
|
+
accept={to_accept_attribute(accept_file_types)}
|
|
122
131
|
type="file"
|
|
123
132
|
bind:this={hidden_upload}
|
|
124
133
|
onchange={load_files_from_upload}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/uploadbutton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "./Index.svelte",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@gradio/button": "^0.8.
|
|
21
|
-
"@gradio/client": "^2.
|
|
22
|
-
"@gradio/upload": "^0.
|
|
23
|
-
"@gradio/utils": "^0.14.
|
|
20
|
+
"@gradio/button": "^0.8.3",
|
|
21
|
+
"@gradio/client": "^2.7.1",
|
|
22
|
+
"@gradio/upload": "^0.19.0",
|
|
23
|
+
"@gradio/utils": "^0.14.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@gradio/preview": "^0.17.
|
|
26
|
+
"@gradio/preview": "^0.17.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"svelte": "^5.48.0"
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { tick } from "svelte";
|
|
3
3
|
import { BaseButton } from "@gradio/button";
|
|
4
4
|
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
invalid_file_type_message,
|
|
7
|
+
is_valid_mimetype,
|
|
8
|
+
to_accept_attribute
|
|
9
|
+
} from "@gradio/upload";
|
|
6
10
|
|
|
7
11
|
let {
|
|
8
12
|
elem_id = "",
|
|
@@ -71,14 +75,19 @@
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
async function load_files(files: FileList): Promise<void> {
|
|
78
|
+
const invalid_files: File[] = [];
|
|
74
79
|
let _files: File[] = Array.from(files).filter((file) => {
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
if (
|
|
81
|
+
is_valid_mimetype(accept_file_types, file.name.toLowerCase(), file.type)
|
|
82
|
+
) {
|
|
77
83
|
return true;
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
invalid_files.push(file);
|
|
80
86
|
return false;
|
|
81
87
|
});
|
|
88
|
+
if (invalid_files.length) {
|
|
89
|
+
onerror?.(invalid_file_type_message(invalid_files, file_types));
|
|
90
|
+
}
|
|
82
91
|
|
|
83
92
|
if (!_files.length) {
|
|
84
93
|
return;
|
|
@@ -118,7 +127,7 @@
|
|
|
118
127
|
|
|
119
128
|
<input
|
|
120
129
|
class="hide"
|
|
121
|
-
accept={accept_file_types}
|
|
130
|
+
accept={to_accept_attribute(accept_file_types)}
|
|
122
131
|
type="file"
|
|
123
132
|
bind:this={hidden_upload}
|
|
124
133
|
onchange={load_files_from_upload}
|