@gradio/file 0.4.8 → 0.5.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 +15 -1
- package/Example.svelte +2 -2
- package/FileUpload.stories.svelte +64 -0
- package/Index.svelte +6 -8
- package/package.json +7 -7
- package/shared/FilePreview.svelte +33 -0
- package/shared/FileUpload.svelte +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @gradio/file
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#7299](https://github.com/gradio-app/gradio/pull/7299) [`f35f615`](https://github.com/gradio-app/gradio/commit/f35f615e33a5dd90bfeb106b6f5dca689849fcef) - Added remove button for every file in file preview, to remove individual file in gr.File(). Thanks [@shubhamofbce](https://github.com/shubhamofbce)!
|
8
|
+
- [#7183](https://github.com/gradio-app/gradio/pull/7183) [`49d9c48`](https://github.com/gradio-app/gradio/commit/49d9c48537aa706bf72628e3640389470138bdc6) - [WIP] Refactor file normalization to be in the backend and remove it from the frontend of each component. Thanks [@abidlabs](https://github.com/abidlabs)!
|
9
|
+
|
10
|
+
## 0.4.9
|
11
|
+
|
12
|
+
### Fixes
|
13
|
+
|
14
|
+
- [#7192](https://github.com/gradio-app/gradio/pull/7192) [`8dd6f4b`](https://github.com/gradio-app/gradio/commit/8dd6f4bc1901792f05cd59e86df7b1dbab692739) - Handle the case where examples is `null` for all components. Thanks [@abidlabs](https://github.com/abidlabs)!
|
15
|
+
- [#7221](https://github.com/gradio-app/gradio/pull/7221) [`cae05c0`](https://github.com/gradio-app/gradio/commit/cae05c05ecde56c4d92c6b5ed8d13353505cbd14) - Fix single file upload display. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
16
|
+
|
3
17
|
## 0.4.8
|
4
18
|
|
5
19
|
### Patch Changes
|
@@ -331,4 +345,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
|
|
331
345
|
- Updated dependencies []:
|
332
346
|
- @gradio/utils@0.0.2
|
333
347
|
- @gradio/atoms@0.0.2
|
334
|
-
- @gradio/upload@0.0.2
|
348
|
+
- @gradio/upload@0.0.2
|
package/Example.svelte
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<script lang="ts">
|
2
2
|
import type { FileData } from "@gradio/client";
|
3
3
|
|
4
|
-
export let value: FileData;
|
4
|
+
export let value: FileData | null;
|
5
5
|
export let type: "gallery" | "table";
|
6
6
|
export let selected = false;
|
7
7
|
</script>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
class:gallery={type === "gallery"}
|
12
12
|
class:selected
|
13
13
|
>
|
14
|
-
{Array.isArray(value) ? value.join(", ") : value}
|
14
|
+
{value ? (Array.isArray(value) ? value.join(", ") : value) : ""}
|
15
15
|
</div>
|
16
16
|
|
17
17
|
<style>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<script context="module">
|
2
|
+
import { Template, Story } from "@storybook/addon-svelte-csf";
|
3
|
+
import { format } from "svelte-i18n";
|
4
|
+
import FileUpload from "./shared/FileUpload.svelte";
|
5
|
+
import { get } from "svelte/store";
|
6
|
+
|
7
|
+
export const meta = {
|
8
|
+
title: "Components/FileUpload",
|
9
|
+
component: FileUpload,
|
10
|
+
argTypes: {
|
11
|
+
value: {
|
12
|
+
control: "text",
|
13
|
+
description: "The URL or filepath (or list of URLs or filepaths)",
|
14
|
+
name: "value",
|
15
|
+
value: []
|
16
|
+
},
|
17
|
+
file_count: {
|
18
|
+
control: "radio",
|
19
|
+
options: ["single", "multiple"],
|
20
|
+
description: "Whether to allow single or multiple files to be uploaded",
|
21
|
+
name: "file_count",
|
22
|
+
value: "single"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
};
|
26
|
+
</script>
|
27
|
+
|
28
|
+
<Template let:args>
|
29
|
+
<FileUpload {...args} i18n={get(format)} />
|
30
|
+
</Template>
|
31
|
+
|
32
|
+
<Story
|
33
|
+
name="Single File"
|
34
|
+
args={{
|
35
|
+
value: [
|
36
|
+
{
|
37
|
+
path: "cheetah.jpg",
|
38
|
+
orig_name: "cheetah.jpg",
|
39
|
+
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
40
|
+
size: 10000
|
41
|
+
}
|
42
|
+
],
|
43
|
+
file_count: "single"
|
44
|
+
}}
|
45
|
+
/>
|
46
|
+
<Story
|
47
|
+
name="Multiple files"
|
48
|
+
args={{
|
49
|
+
value: Array(2).fill({
|
50
|
+
path: "cheetah.jpg",
|
51
|
+
orig_name: "cheetah.jpg",
|
52
|
+
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
53
|
+
size: 10000
|
54
|
+
}),
|
55
|
+
file_count: "multiple"
|
56
|
+
}}
|
57
|
+
/>
|
58
|
+
<Story
|
59
|
+
name="No value"
|
60
|
+
args={{
|
61
|
+
value: null,
|
62
|
+
file_count: "multiple"
|
63
|
+
}}
|
64
|
+
/>
|
package/Index.svelte
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
import type { Gradio, SelectData } from "@gradio/utils";
|
12
12
|
import File from "./shared/File.svelte";
|
13
13
|
import FileUpload from "./shared/FileUpload.svelte";
|
14
|
-
import {
|
14
|
+
import type { FileData } from "@gradio/client";
|
15
15
|
import { Block, UploadText } from "@gradio/atoms";
|
16
16
|
|
17
17
|
import { StatusTracker } from "@gradio/statustracker";
|
@@ -28,7 +28,6 @@
|
|
28
28
|
export let show_label: boolean;
|
29
29
|
export let height: number | undefined = undefined;
|
30
30
|
|
31
|
-
export let proxy_url: null | string;
|
32
31
|
export let _selectable = false;
|
33
32
|
export let loading_status: LoadingStatus;
|
34
33
|
export let container = true;
|
@@ -43,12 +42,11 @@
|
|
43
42
|
}>;
|
44
43
|
export let file_count: string;
|
45
44
|
export let file_types: string[] = ["file"];
|
46
|
-
$: _value = normalise_file(value, root, proxy_url);
|
47
45
|
|
48
|
-
let old_value =
|
49
|
-
$: if (JSON.stringify(old_value) !== JSON.stringify(
|
46
|
+
let old_value = value;
|
47
|
+
$: if (JSON.stringify(old_value) !== JSON.stringify(value)) {
|
50
48
|
gradio.dispatch("change");
|
51
|
-
old_value =
|
49
|
+
old_value = value;
|
52
50
|
}
|
53
51
|
|
54
52
|
let dragging = false;
|
@@ -79,7 +77,7 @@
|
|
79
77
|
<File
|
80
78
|
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
81
79
|
selectable={_selectable}
|
82
|
-
value
|
80
|
+
{value}
|
83
81
|
{label}
|
84
82
|
{show_label}
|
85
83
|
{height}
|
@@ -89,7 +87,7 @@
|
|
89
87
|
<FileUpload
|
90
88
|
{label}
|
91
89
|
{show_label}
|
92
|
-
value
|
90
|
+
{value}
|
93
91
|
{file_count}
|
94
92
|
{file_types}
|
95
93
|
selectable={_selectable}
|
package/package.json
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/file",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
6
|
"author": "",
|
7
7
|
"license": "ISC",
|
8
8
|
"private": false,
|
9
9
|
"dependencies": {
|
10
|
-
"@gradio/atoms": "^0.5.0",
|
11
|
-
"@gradio/client": "^0.10.1",
|
12
10
|
"@gradio/icons": "^0.3.2",
|
13
|
-
"@gradio/
|
14
|
-
"@gradio/
|
15
|
-
"@gradio/upload": "^0.7.
|
16
|
-
"@gradio/utils": "^0.2.
|
11
|
+
"@gradio/atoms": "^0.5.1",
|
12
|
+
"@gradio/client": "^0.12.0",
|
13
|
+
"@gradio/upload": "^0.7.2",
|
14
|
+
"@gradio/utils": "^0.2.2",
|
15
|
+
"@gradio/statustracker": "^0.4.5",
|
16
|
+
"@gradio/wasm": "^0.6.0"
|
17
17
|
},
|
18
18
|
"main": "./Index.svelte",
|
19
19
|
"main_changeset": true,
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const dispatch = createEventDispatcher<{
|
9
9
|
select: SelectData;
|
10
|
+
change: FileData[] | FileData;
|
10
11
|
}>();
|
11
12
|
export let value: FileData | FileData[];
|
12
13
|
export let selectable = false;
|
@@ -29,6 +30,13 @@
|
|
29
30
|
filename_ext
|
30
31
|
};
|
31
32
|
});
|
33
|
+
|
34
|
+
function remove_file(index: number): void {
|
35
|
+
normalized_files.splice(index, 1);
|
36
|
+
normalized_files = [...normalized_files];
|
37
|
+
value = normalized_files;
|
38
|
+
dispatch("change", normalized_files);
|
39
|
+
}
|
32
40
|
</script>
|
33
41
|
|
34
42
|
<div
|
@@ -66,6 +74,21 @@
|
|
66
74
|
{i18n("file.uploading")}
|
67
75
|
{/if}
|
68
76
|
</td>
|
77
|
+
{#if normalized_files.length > 1}
|
78
|
+
<td>
|
79
|
+
<button
|
80
|
+
class="label-clear-button"
|
81
|
+
aria-label="Remove this file"
|
82
|
+
on:click={() => remove_file(i)}
|
83
|
+
on:keydown={(event) => {
|
84
|
+
if (event.key === "Enter") {
|
85
|
+
remove_file(i);
|
86
|
+
}
|
87
|
+
}}
|
88
|
+
>×
|
89
|
+
</button>
|
90
|
+
</td>
|
91
|
+
{/if}
|
69
92
|
</tr>
|
70
93
|
{/each}
|
71
94
|
</tbody>
|
@@ -73,6 +96,16 @@
|
|
73
96
|
</div>
|
74
97
|
|
75
98
|
<style>
|
99
|
+
.label-clear-button {
|
100
|
+
color: var(--body-text-color-subdued);
|
101
|
+
position: relative;
|
102
|
+
left: -3px;
|
103
|
+
}
|
104
|
+
|
105
|
+
.label-clear-button:hover {
|
106
|
+
color: var(--body-text-color);
|
107
|
+
}
|
108
|
+
|
76
109
|
.file-preview {
|
77
110
|
table-layout: fixed;
|
78
111
|
width: var(--size-full);
|
package/shared/FileUpload.svelte
CHANGED
@@ -67,9 +67,9 @@
|
|
67
67
|
label={label || "File"}
|
68
68
|
/>
|
69
69
|
|
70
|
-
{#if value && (Array.isArray(value) ? value.length > 0 :
|
70
|
+
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
|
71
71
|
<ModifyUpload {i18n} on:clear={handle_clear} absolute />
|
72
|
-
<FilePreview {i18n} on:select {selectable} {value} {height} />
|
72
|
+
<FilePreview {i18n} on:select {selectable} {value} {height} on:change />
|
73
73
|
{:else}
|
74
74
|
<Upload
|
75
75
|
on:load={handle_upload}
|