@gradio/file 0.9.3 → 0.9.4-beta.1
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 +32 -0
- package/dist/Example.svelte +27 -0
- package/dist/Example.svelte.d.ts +19 -0
- package/dist/Index.svelte +104 -0
- package/dist/Index.svelte.d.ts +113 -0
- package/dist/shared/File.svelte +23 -0
- package/dist/shared/File.svelte.d.ts +25 -0
- package/dist/shared/FilePreview.svelte +182 -0
- package/dist/shared/FilePreview.svelte.d.ts +25 -0
- package/dist/shared/FileUpload.svelte +64 -0
- package/dist/shared/FileUpload.svelte.d.ts +40 -0
- package/dist/shared/utils.d.ts +1 -0
- package/dist/shared/utils.js +10 -0
- package/package.json +22 -11
- package/shared/FilePreview.svelte +5 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# @gradio/file
|
2
2
|
|
3
|
+
## 0.9.4-beta.1
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#9187](https://github.com/gradio-app/gradio/pull/9187) [`5bf00b7`](https://github.com/gradio-app/gradio/commit/5bf00b7524ebf399b48719120a49d15bb21bd65c) - make all component SSR compatible. Thanks @pngwn!
|
8
|
+
|
9
|
+
### Dependency updates
|
10
|
+
|
11
|
+
- @gradio/atoms@0.8.1-beta.1
|
12
|
+
- @gradio/icons@0.8.0-beta.1
|
13
|
+
- @gradio/statustracker@0.8.0-beta.1
|
14
|
+
- @gradio/utils@0.7.0-beta.1
|
15
|
+
- @gradio/client@1.6.0-beta.1
|
16
|
+
- @gradio/upload@0.12.4-beta.1
|
17
|
+
- @gradio/wasm@0.13.1-beta.1
|
18
|
+
|
19
|
+
## 0.9.4-beta.0
|
20
|
+
|
21
|
+
### Fixes
|
22
|
+
|
23
|
+
- [#9163](https://github.com/gradio-app/gradio/pull/9163) [`2b6cbf2`](https://github.com/gradio-app/gradio/commit/2b6cbf25908e42cf027324e54ef2cc0baad11a91) - fix exports and generate types. Thanks @pngwn!
|
24
|
+
|
25
|
+
### Dependency updates
|
26
|
+
|
27
|
+
- @gradio/utils@0.7.0-beta.0
|
28
|
+
- @gradio/statustracker@0.8.0-beta.0
|
29
|
+
- @gradio/atoms@0.8.1-beta.0
|
30
|
+
- @gradio/client@1.6.0-beta.0
|
31
|
+
- @gradio/icons@0.8.0-beta.0
|
32
|
+
- @gradio/upload@0.12.4-beta.0
|
33
|
+
- @gradio/wasm@0.13.1-beta.0
|
34
|
+
|
3
35
|
## 0.9.3
|
4
36
|
|
5
37
|
### Features
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<script>export let value;
|
2
|
+
export let type;
|
3
|
+
export let selected = false;
|
4
|
+
</script>
|
5
|
+
|
6
|
+
<div
|
7
|
+
class:table={type === "table"}
|
8
|
+
class:gallery={type === "gallery"}
|
9
|
+
class:selected
|
10
|
+
>
|
11
|
+
{value ? (Array.isArray(value) ? value.join(", ") : value) : ""}
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<style>
|
15
|
+
div {
|
16
|
+
overflow: hidden;
|
17
|
+
text-overflow: ellipsis;
|
18
|
+
white-space: nowrap;
|
19
|
+
}
|
20
|
+
.gallery {
|
21
|
+
display: flex;
|
22
|
+
align-items: center;
|
23
|
+
cursor: pointer;
|
24
|
+
padding: var(--size-1) var(--size-2);
|
25
|
+
text-align: left;
|
26
|
+
}
|
27
|
+
</style>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
import type { FileData } from "@gradio/client";
|
3
|
+
declare const __propDef: {
|
4
|
+
props: {
|
5
|
+
value: FileData | null;
|
6
|
+
type: "gallery" | "table";
|
7
|
+
selected?: boolean | undefined;
|
8
|
+
};
|
9
|
+
events: {
|
10
|
+
[evt: string]: CustomEvent<any>;
|
11
|
+
};
|
12
|
+
slots: {};
|
13
|
+
};
|
14
|
+
export type ExampleProps = typeof __propDef.props;
|
15
|
+
export type ExampleEvents = typeof __propDef.events;
|
16
|
+
export type ExampleSlots = typeof __propDef.slots;
|
17
|
+
export default class Example extends SvelteComponent<ExampleProps, ExampleEvents, ExampleSlots> {
|
18
|
+
}
|
19
|
+
export {};
|
@@ -0,0 +1,104 @@
|
|
1
|
+
<svelte:options accessors={true} />
|
2
|
+
|
3
|
+
<script context="module">export { default as FilePreview } from "./shared/FilePreview.svelte";
|
4
|
+
export { default as BaseFileUpload } from "./shared/FileUpload.svelte";
|
5
|
+
export { default as BaseFile } from "./shared/File.svelte";
|
6
|
+
export { default as BaseExample } from "./Example.svelte";
|
7
|
+
</script>
|
8
|
+
|
9
|
+
<script>import File from "./shared/File.svelte";
|
10
|
+
import FileUpload from "./shared/FileUpload.svelte";
|
11
|
+
import { Block, UploadText } from "@gradio/atoms";
|
12
|
+
import { StatusTracker } from "@gradio/statustracker";
|
13
|
+
export let elem_id = "";
|
14
|
+
export let elem_classes = [];
|
15
|
+
export let visible = true;
|
16
|
+
export let value;
|
17
|
+
export let interactive;
|
18
|
+
export let root;
|
19
|
+
export let label;
|
20
|
+
export let show_label;
|
21
|
+
export let height = void 0;
|
22
|
+
export let _selectable = false;
|
23
|
+
export let loading_status;
|
24
|
+
export let container = true;
|
25
|
+
export let scale = null;
|
26
|
+
export let min_width = void 0;
|
27
|
+
export let gradio;
|
28
|
+
export let file_count;
|
29
|
+
export let file_types = ["file"];
|
30
|
+
let old_value = value;
|
31
|
+
$:
|
32
|
+
if (JSON.stringify(old_value) !== JSON.stringify(value)) {
|
33
|
+
gradio.dispatch("change");
|
34
|
+
old_value = value;
|
35
|
+
}
|
36
|
+
let dragging = false;
|
37
|
+
let pending_upload = false;
|
38
|
+
</script>
|
39
|
+
|
40
|
+
<Block
|
41
|
+
{visible}
|
42
|
+
variant={value ? "solid" : "dashed"}
|
43
|
+
border_mode={dragging ? "focus" : "base"}
|
44
|
+
padding={false}
|
45
|
+
{elem_id}
|
46
|
+
{elem_classes}
|
47
|
+
{container}
|
48
|
+
{scale}
|
49
|
+
{min_width}
|
50
|
+
allow_overflow={false}
|
51
|
+
>
|
52
|
+
<StatusTracker
|
53
|
+
autoscroll={gradio.autoscroll}
|
54
|
+
i18n={gradio.i18n}
|
55
|
+
{...loading_status}
|
56
|
+
status={pending_upload
|
57
|
+
? "generating"
|
58
|
+
: loading_status?.status || "complete"}
|
59
|
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
60
|
+
/>
|
61
|
+
{#if !interactive}
|
62
|
+
<File
|
63
|
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
64
|
+
selectable={_selectable}
|
65
|
+
{value}
|
66
|
+
{label}
|
67
|
+
{show_label}
|
68
|
+
{height}
|
69
|
+
i18n={gradio.i18n}
|
70
|
+
/>
|
71
|
+
{:else}
|
72
|
+
<FileUpload
|
73
|
+
upload={gradio.client.upload}
|
74
|
+
stream_handler={gradio.client.stream}
|
75
|
+
{label}
|
76
|
+
{show_label}
|
77
|
+
{value}
|
78
|
+
{file_count}
|
79
|
+
{file_types}
|
80
|
+
selectable={_selectable}
|
81
|
+
{root}
|
82
|
+
{height}
|
83
|
+
max_file_size={gradio.max_file_size}
|
84
|
+
on:change={({ detail }) => {
|
85
|
+
value = detail;
|
86
|
+
}}
|
87
|
+
on:drag={({ detail }) => (dragging = detail)}
|
88
|
+
on:clear={() => gradio.dispatch("clear")}
|
89
|
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
90
|
+
on:upload={() => gradio.dispatch("upload")}
|
91
|
+
on:error={({ detail }) => {
|
92
|
+
loading_status = loading_status || {};
|
93
|
+
loading_status.status = "error";
|
94
|
+
gradio.dispatch("error", detail);
|
95
|
+
}}
|
96
|
+
on:delete={({ detail }) => {
|
97
|
+
gradio.dispatch("delete", detail);
|
98
|
+
}}
|
99
|
+
i18n={gradio.i18n}
|
100
|
+
>
|
101
|
+
<UploadText i18n={gradio.i18n} type="file" />
|
102
|
+
</FileUpload>
|
103
|
+
{/if}
|
104
|
+
</Block>
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
export { default as FilePreview } from "./shared/FilePreview.svelte";
|
3
|
+
export { default as BaseFileUpload } from "./shared/FileUpload.svelte";
|
4
|
+
export { default as BaseFile } from "./shared/File.svelte";
|
5
|
+
export { default as BaseExample } from "./Example.svelte";
|
6
|
+
import type { Gradio, SelectData } from "@gradio/utils";
|
7
|
+
import type { FileData } from "@gradio/client";
|
8
|
+
import type { LoadingStatus } from "@gradio/statustracker";
|
9
|
+
declare const __propDef: {
|
10
|
+
props: {
|
11
|
+
elem_id?: string | undefined;
|
12
|
+
elem_classes?: string[] | undefined;
|
13
|
+
visible?: boolean | undefined;
|
14
|
+
value: null | FileData | FileData[];
|
15
|
+
interactive: boolean;
|
16
|
+
root: string;
|
17
|
+
label: string;
|
18
|
+
show_label: boolean;
|
19
|
+
height?: number | undefined;
|
20
|
+
_selectable?: boolean | undefined;
|
21
|
+
loading_status: LoadingStatus;
|
22
|
+
container?: boolean | undefined;
|
23
|
+
scale?: (number | null) | undefined;
|
24
|
+
min_width?: number | undefined;
|
25
|
+
gradio: Gradio<{
|
26
|
+
change: never;
|
27
|
+
error: string;
|
28
|
+
upload: never;
|
29
|
+
clear: never;
|
30
|
+
select: SelectData;
|
31
|
+
clear_status: LoadingStatus;
|
32
|
+
delete: FileData;
|
33
|
+
}>;
|
34
|
+
file_count: "single" | "multiple" | "directory";
|
35
|
+
file_types?: string[] | undefined;
|
36
|
+
};
|
37
|
+
events: {
|
38
|
+
[evt: string]: CustomEvent<any>;
|
39
|
+
};
|
40
|
+
slots: {};
|
41
|
+
};
|
42
|
+
export type IndexProps = typeof __propDef.props;
|
43
|
+
export type IndexEvents = typeof __propDef.events;
|
44
|
+
export type IndexSlots = typeof __propDef.slots;
|
45
|
+
export default class Index extends SvelteComponent<IndexProps, IndexEvents, IndexSlots> {
|
46
|
+
get elem_id(): string | undefined;
|
47
|
+
/**accessor*/
|
48
|
+
set elem_id(_: string | undefined);
|
49
|
+
get elem_classes(): string[] | undefined;
|
50
|
+
/**accessor*/
|
51
|
+
set elem_classes(_: string[] | undefined);
|
52
|
+
get visible(): boolean | undefined;
|
53
|
+
/**accessor*/
|
54
|
+
set visible(_: boolean | undefined);
|
55
|
+
get value(): FileData | FileData[] | null;
|
56
|
+
/**accessor*/
|
57
|
+
set value(_: FileData | FileData[] | null);
|
58
|
+
get interactive(): boolean;
|
59
|
+
/**accessor*/
|
60
|
+
set interactive(_: boolean);
|
61
|
+
get root(): string;
|
62
|
+
/**accessor*/
|
63
|
+
set root(_: string);
|
64
|
+
get label(): string;
|
65
|
+
/**accessor*/
|
66
|
+
set label(_: string);
|
67
|
+
get show_label(): boolean;
|
68
|
+
/**accessor*/
|
69
|
+
set show_label(_: boolean);
|
70
|
+
get height(): number | undefined;
|
71
|
+
/**accessor*/
|
72
|
+
set height(_: number | undefined);
|
73
|
+
get _selectable(): boolean | undefined;
|
74
|
+
/**accessor*/
|
75
|
+
set _selectable(_: boolean | undefined);
|
76
|
+
get loading_status(): LoadingStatus;
|
77
|
+
/**accessor*/
|
78
|
+
set loading_status(_: LoadingStatus);
|
79
|
+
get container(): boolean | undefined;
|
80
|
+
/**accessor*/
|
81
|
+
set container(_: boolean | undefined);
|
82
|
+
get scale(): number | null | undefined;
|
83
|
+
/**accessor*/
|
84
|
+
set scale(_: number | null | undefined);
|
85
|
+
get min_width(): number | undefined;
|
86
|
+
/**accessor*/
|
87
|
+
set min_width(_: number | undefined);
|
88
|
+
get gradio(): Gradio<{
|
89
|
+
change: never;
|
90
|
+
error: string;
|
91
|
+
upload: never;
|
92
|
+
clear: never;
|
93
|
+
select: SelectData;
|
94
|
+
clear_status: LoadingStatus;
|
95
|
+
delete: FileData;
|
96
|
+
}>;
|
97
|
+
/**accessor*/
|
98
|
+
set gradio(_: Gradio<{
|
99
|
+
change: never;
|
100
|
+
error: string;
|
101
|
+
upload: never;
|
102
|
+
clear: never;
|
103
|
+
select: SelectData;
|
104
|
+
clear_status: LoadingStatus;
|
105
|
+
delete: FileData;
|
106
|
+
}>);
|
107
|
+
get file_count(): "multiple" | "single" | "directory";
|
108
|
+
/**accessor*/
|
109
|
+
set file_count(_: "multiple" | "single" | "directory");
|
110
|
+
get file_types(): string[] | undefined;
|
111
|
+
/**accessor*/
|
112
|
+
set file_types(_: string[] | undefined);
|
113
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<script>import { BlockLabel, Empty } from "@gradio/atoms";
|
2
|
+
import { File } from "@gradio/icons";
|
3
|
+
import FilePreview from "./FilePreview.svelte";
|
4
|
+
export let value = null;
|
5
|
+
export let label;
|
6
|
+
export let show_label = true;
|
7
|
+
export let selectable = false;
|
8
|
+
export let height = void 0;
|
9
|
+
export let i18n;
|
10
|
+
</script>
|
11
|
+
|
12
|
+
<BlockLabel
|
13
|
+
{show_label}
|
14
|
+
float={value === null}
|
15
|
+
Icon={File}
|
16
|
+
label={label || "File"}
|
17
|
+
/>
|
18
|
+
|
19
|
+
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
|
20
|
+
<FilePreview {i18n} {selectable} on:select {value} {height} />
|
21
|
+
{:else}
|
22
|
+
<Empty unpadded_box={true} size="large"><File /></Empty>
|
23
|
+
{/if}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
import type { FileData } from "@gradio/client";
|
3
|
+
import type { I18nFormatter } from "@gradio/utils";
|
4
|
+
declare const __propDef: {
|
5
|
+
props: {
|
6
|
+
value?: (FileData | FileData[] | null) | undefined;
|
7
|
+
label: string;
|
8
|
+
show_label?: boolean | undefined;
|
9
|
+
selectable?: boolean | undefined;
|
10
|
+
height?: number | undefined;
|
11
|
+
i18n: I18nFormatter;
|
12
|
+
};
|
13
|
+
events: {
|
14
|
+
select: CustomEvent<import("@gradio/utils").SelectData>;
|
15
|
+
} & {
|
16
|
+
[evt: string]: CustomEvent<any>;
|
17
|
+
};
|
18
|
+
slots: {};
|
19
|
+
};
|
20
|
+
export type FileProps = typeof __propDef.props;
|
21
|
+
export type FileEvents = typeof __propDef.events;
|
22
|
+
export type FileSlots = typeof __propDef.slots;
|
23
|
+
export default class File extends SvelteComponent<FileProps, FileEvents, FileSlots> {
|
24
|
+
}
|
25
|
+
export {};
|
@@ -0,0 +1,182 @@
|
|
1
|
+
<script>import { prettyBytes } from "./utils";
|
2
|
+
import { createEventDispatcher } from "svelte";
|
3
|
+
import { DownloadLink } from "@gradio/wasm/svelte";
|
4
|
+
const dispatch = createEventDispatcher();
|
5
|
+
export let value;
|
6
|
+
export let selectable = false;
|
7
|
+
export let height = void 0;
|
8
|
+
export let i18n;
|
9
|
+
function split_filename(filename) {
|
10
|
+
const last_dot = filename.lastIndexOf(".");
|
11
|
+
if (last_dot === -1) {
|
12
|
+
return [filename, ""];
|
13
|
+
}
|
14
|
+
return [filename.slice(0, last_dot), filename.slice(last_dot)];
|
15
|
+
}
|
16
|
+
$:
|
17
|
+
normalized_files = (Array.isArray(value) ? value : [value]).map((file) => {
|
18
|
+
const [filename_stem, filename_ext] = split_filename(file.orig_name ?? "");
|
19
|
+
return {
|
20
|
+
...file,
|
21
|
+
filename_stem,
|
22
|
+
filename_ext
|
23
|
+
};
|
24
|
+
});
|
25
|
+
function handle_row_click(event, index) {
|
26
|
+
const tr = event.currentTarget;
|
27
|
+
const should_select = event.target === tr || // Only select if the click is on the row itself
|
28
|
+
tr && tr.firstElementChild && event.composedPath().includes(tr.firstElementChild);
|
29
|
+
if (should_select) {
|
30
|
+
dispatch("select", { value: normalized_files[index].orig_name, index });
|
31
|
+
}
|
32
|
+
}
|
33
|
+
function remove_file(index) {
|
34
|
+
const removed = normalized_files.splice(index, 1);
|
35
|
+
normalized_files = [...normalized_files];
|
36
|
+
value = normalized_files;
|
37
|
+
dispatch("delete", removed[0]);
|
38
|
+
dispatch("change", normalized_files);
|
39
|
+
}
|
40
|
+
const is_browser = typeof window !== "undefined";
|
41
|
+
</script>
|
42
|
+
|
43
|
+
<div
|
44
|
+
class="file-preview-holder"
|
45
|
+
style="max-height: {typeof height === undefined ? 'auto' : height + 'px'};"
|
46
|
+
>
|
47
|
+
<table class="file-preview">
|
48
|
+
<tbody>
|
49
|
+
{#each normalized_files as file, i (file)}
|
50
|
+
<tr
|
51
|
+
class="file"
|
52
|
+
class:selectable
|
53
|
+
on:click={(event) => {
|
54
|
+
handle_row_click(event, i);
|
55
|
+
}}
|
56
|
+
>
|
57
|
+
<td class="filename" aria-label={file.orig_name}>
|
58
|
+
<span class="stem">{file.filename_stem}</span>
|
59
|
+
<span class="ext">{file.filename_ext}</span>
|
60
|
+
</td>
|
61
|
+
|
62
|
+
<td class="download">
|
63
|
+
{#if file.url}
|
64
|
+
<DownloadLink
|
65
|
+
href={file.url}
|
66
|
+
download={is_browser && window.__is_colab__
|
67
|
+
? null
|
68
|
+
: file.orig_name}
|
69
|
+
>
|
70
|
+
{@html file.size != null
|
71
|
+
? prettyBytes(file.size)
|
72
|
+
: "(size unknown)"} ⇣
|
73
|
+
</DownloadLink>
|
74
|
+
{:else}
|
75
|
+
{i18n("file.uploading")}
|
76
|
+
{/if}
|
77
|
+
</td>
|
78
|
+
|
79
|
+
{#if normalized_files.length > 1}
|
80
|
+
<td>
|
81
|
+
<button
|
82
|
+
class="label-clear-button"
|
83
|
+
aria-label="Remove this file"
|
84
|
+
on:click={() => {
|
85
|
+
remove_file(i);
|
86
|
+
}}
|
87
|
+
on:keydown={(event) => {
|
88
|
+
if (event.key === "Enter") {
|
89
|
+
remove_file(i);
|
90
|
+
}
|
91
|
+
}}
|
92
|
+
>×
|
93
|
+
</button>
|
94
|
+
</td>
|
95
|
+
{/if}
|
96
|
+
</tr>
|
97
|
+
{/each}
|
98
|
+
</tbody>
|
99
|
+
</table>
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<style>
|
103
|
+
.label-clear-button {
|
104
|
+
color: var(--body-text-color-subdued);
|
105
|
+
position: relative;
|
106
|
+
left: -3px;
|
107
|
+
}
|
108
|
+
|
109
|
+
.label-clear-button:hover {
|
110
|
+
color: var(--body-text-color);
|
111
|
+
}
|
112
|
+
|
113
|
+
.file-preview {
|
114
|
+
table-layout: fixed;
|
115
|
+
width: var(--size-full);
|
116
|
+
max-height: var(--size-60);
|
117
|
+
overflow-y: auto;
|
118
|
+
margin-top: var(--size-1);
|
119
|
+
color: var(--body-text-color);
|
120
|
+
}
|
121
|
+
|
122
|
+
.file-preview-holder {
|
123
|
+
overflow: auto;
|
124
|
+
}
|
125
|
+
|
126
|
+
.file {
|
127
|
+
display: flex;
|
128
|
+
width: var(--size-full);
|
129
|
+
}
|
130
|
+
|
131
|
+
.file > * {
|
132
|
+
padding: var(--size-1) var(--size-2-5);
|
133
|
+
}
|
134
|
+
|
135
|
+
.filename {
|
136
|
+
flex-grow: 1;
|
137
|
+
display: flex;
|
138
|
+
overflow: hidden;
|
139
|
+
}
|
140
|
+
.filename .stem {
|
141
|
+
overflow: hidden;
|
142
|
+
text-overflow: ellipsis;
|
143
|
+
white-space: nowrap;
|
144
|
+
}
|
145
|
+
.filename .ext {
|
146
|
+
white-space: nowrap;
|
147
|
+
}
|
148
|
+
|
149
|
+
.download {
|
150
|
+
min-width: 8rem;
|
151
|
+
width: 10%;
|
152
|
+
white-space: nowrap;
|
153
|
+
text-align: right;
|
154
|
+
}
|
155
|
+
.download:hover {
|
156
|
+
text-decoration: underline;
|
157
|
+
}
|
158
|
+
.download > :global(a) {
|
159
|
+
color: var(--link-text-color);
|
160
|
+
}
|
161
|
+
|
162
|
+
.download > :global(a:hover) {
|
163
|
+
color: var(--link-text-color-hover);
|
164
|
+
}
|
165
|
+
.download > :global(a:visited) {
|
166
|
+
color: var(--link-text-color-visited);
|
167
|
+
}
|
168
|
+
.download > :global(a:active) {
|
169
|
+
color: var(--link-text-color-active);
|
170
|
+
}
|
171
|
+
.selectable {
|
172
|
+
cursor: pointer;
|
173
|
+
}
|
174
|
+
|
175
|
+
tbody > tr:nth-child(even) {
|
176
|
+
background: var(--block-background-fill);
|
177
|
+
}
|
178
|
+
|
179
|
+
tbody > tr:nth-child(odd) {
|
180
|
+
background: var(--table-odd-background-fill);
|
181
|
+
}
|
182
|
+
</style>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
import type { FileData } from "@gradio/client";
|
3
|
+
import type { I18nFormatter, SelectData } from "@gradio/utils";
|
4
|
+
declare const __propDef: {
|
5
|
+
props: {
|
6
|
+
value: FileData | FileData[];
|
7
|
+
selectable?: boolean | undefined;
|
8
|
+
height?: number | undefined;
|
9
|
+
i18n: I18nFormatter;
|
10
|
+
};
|
11
|
+
events: {
|
12
|
+
select: CustomEvent<SelectData>;
|
13
|
+
change: CustomEvent<FileData | FileData[]>;
|
14
|
+
delete: CustomEvent<FileData>;
|
15
|
+
} & {
|
16
|
+
[evt: string]: CustomEvent<any>;
|
17
|
+
};
|
18
|
+
slots: {};
|
19
|
+
};
|
20
|
+
export type FilePreviewProps = typeof __propDef.props;
|
21
|
+
export type FilePreviewEvents = typeof __propDef.events;
|
22
|
+
export type FilePreviewSlots = typeof __propDef.slots;
|
23
|
+
export default class FilePreview extends SvelteComponent<FilePreviewProps, FilePreviewEvents, FilePreviewSlots> {
|
24
|
+
}
|
25
|
+
export {};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<script>import { createEventDispatcher, tick } from "svelte";
|
2
|
+
import { Upload, ModifyUpload } from "@gradio/upload";
|
3
|
+
import { BlockLabel } from "@gradio/atoms";
|
4
|
+
import { File } from "@gradio/icons";
|
5
|
+
import FilePreview from "./FilePreview.svelte";
|
6
|
+
export let value;
|
7
|
+
export let label;
|
8
|
+
export let show_label = true;
|
9
|
+
export let file_count = "single";
|
10
|
+
export let file_types = null;
|
11
|
+
export let selectable = false;
|
12
|
+
export let root;
|
13
|
+
export let height = void 0;
|
14
|
+
export let i18n;
|
15
|
+
export let max_file_size = null;
|
16
|
+
export let upload;
|
17
|
+
export let stream_handler;
|
18
|
+
async function handle_upload({
|
19
|
+
detail
|
20
|
+
}) {
|
21
|
+
value = detail;
|
22
|
+
await tick();
|
23
|
+
dispatch("change", value);
|
24
|
+
dispatch("upload", detail);
|
25
|
+
}
|
26
|
+
function handle_clear() {
|
27
|
+
value = null;
|
28
|
+
dispatch("change", null);
|
29
|
+
dispatch("clear");
|
30
|
+
}
|
31
|
+
const dispatch = createEventDispatcher();
|
32
|
+
let dragging = false;
|
33
|
+
$:
|
34
|
+
dispatch("drag", dragging);
|
35
|
+
</script>
|
36
|
+
|
37
|
+
<BlockLabel {show_label} Icon={File} float={!value} label={label || "File"} />
|
38
|
+
|
39
|
+
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
|
40
|
+
<ModifyUpload {i18n} on:clear={handle_clear} absolute />
|
41
|
+
<FilePreview
|
42
|
+
{i18n}
|
43
|
+
on:select
|
44
|
+
{selectable}
|
45
|
+
{value}
|
46
|
+
{height}
|
47
|
+
on:change
|
48
|
+
on:delete
|
49
|
+
/>
|
50
|
+
{:else}
|
51
|
+
<Upload
|
52
|
+
on:load={handle_upload}
|
53
|
+
filetype={file_types}
|
54
|
+
{file_count}
|
55
|
+
{max_file_size}
|
56
|
+
{root}
|
57
|
+
bind:dragging
|
58
|
+
on:error
|
59
|
+
{stream_handler}
|
60
|
+
{upload}
|
61
|
+
>
|
62
|
+
<slot />
|
63
|
+
</Upload>
|
64
|
+
{/if}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
import type { FileData, Client } from "@gradio/client";
|
3
|
+
import type { I18nFormatter } from "@gradio/utils";
|
4
|
+
declare const __propDef: {
|
5
|
+
props: {
|
6
|
+
value: null | FileData | FileData[];
|
7
|
+
label: string;
|
8
|
+
show_label?: boolean | undefined;
|
9
|
+
file_count?: ("single" | "multiple" | "directory") | undefined;
|
10
|
+
file_types?: (string[] | null) | undefined;
|
11
|
+
selectable?: boolean | undefined;
|
12
|
+
root: string;
|
13
|
+
height?: number | undefined;
|
14
|
+
i18n: I18nFormatter;
|
15
|
+
max_file_size?: (number | null) | undefined;
|
16
|
+
upload: Client["upload"];
|
17
|
+
stream_handler: Client["stream"];
|
18
|
+
};
|
19
|
+
events: {
|
20
|
+
select: CustomEvent<import("@gradio/utils").SelectData>;
|
21
|
+
change: CustomEvent<any>;
|
22
|
+
delete: CustomEvent<FileData>;
|
23
|
+
error: CustomEvent<any>;
|
24
|
+
clear: CustomEvent<undefined>;
|
25
|
+
drag: CustomEvent<boolean>;
|
26
|
+
upload: CustomEvent<FileData | FileData[]>;
|
27
|
+
load: CustomEvent<FileData | FileData[]>;
|
28
|
+
} & {
|
29
|
+
[evt: string]: CustomEvent<any>;
|
30
|
+
};
|
31
|
+
slots: {
|
32
|
+
default: {};
|
33
|
+
};
|
34
|
+
};
|
35
|
+
export type FileUploadProps = typeof __propDef.props;
|
36
|
+
export type FileUploadEvents = typeof __propDef.events;
|
37
|
+
export type FileUploadSlots = typeof __propDef.slots;
|
38
|
+
export default class FileUpload extends SvelteComponent<FileUploadProps, FileUploadEvents, FileUploadSlots> {
|
39
|
+
}
|
40
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const prettyBytes: (bytes: number) => string;
|
package/package.json
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/file",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.4-beta.1",
|
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.8.
|
11
|
-
"@gradio/client": "^1.
|
12
|
-
"@gradio/icons": "^0.
|
13
|
-
"@gradio/
|
14
|
-
"@gradio/
|
15
|
-
"@gradio/
|
16
|
-
"@gradio/
|
10
|
+
"@gradio/atoms": "^0.8.1-beta.1",
|
11
|
+
"@gradio/client": "^1.6.0-beta.1",
|
12
|
+
"@gradio/icons": "^0.8.0-beta.1",
|
13
|
+
"@gradio/upload": "^0.12.4-beta.1",
|
14
|
+
"@gradio/wasm": "^0.13.1-beta.1",
|
15
|
+
"@gradio/statustracker": "^0.8.0-beta.1",
|
16
|
+
"@gradio/utils": "^0.7.0-beta.1"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"@gradio/preview": "^0.11.0"
|
19
|
+
"@gradio/preview": "^0.11.1-beta.0"
|
20
20
|
},
|
21
21
|
"main": "./Index.svelte",
|
22
22
|
"main_changeset": true,
|
23
23
|
"exports": {
|
24
|
-
".":
|
25
|
-
|
24
|
+
".": {
|
25
|
+
"gradio": "./Index.svelte",
|
26
|
+
"svelte": "./dist/Index.svelte",
|
27
|
+
"types": "./dist/Index.svelte.d.ts"
|
28
|
+
},
|
29
|
+
"./example": {
|
30
|
+
"gradio": "./Example.svelte",
|
31
|
+
"svelte": "./dist/Example.svelte",
|
32
|
+
"types": "./dist/Example.svelte.d.ts"
|
33
|
+
},
|
26
34
|
"./package.json": "./package.json"
|
27
35
|
},
|
36
|
+
"peerDependencies": {
|
37
|
+
"svelte": "^4.0.0"
|
38
|
+
},
|
28
39
|
"repository": {
|
29
40
|
"type": "git",
|
30
41
|
"url": "git+https://github.com/gradio-app/gradio.git",
|
@@ -55,6 +55,8 @@
|
|
55
55
|
dispatch("delete", removed[0]);
|
56
56
|
dispatch("change", normalized_files);
|
57
57
|
}
|
58
|
+
|
59
|
+
const is_browser = typeof window !== "undefined";
|
58
60
|
</script>
|
59
61
|
|
60
62
|
<div
|
@@ -80,7 +82,9 @@
|
|
80
82
|
{#if file.url}
|
81
83
|
<DownloadLink
|
82
84
|
href={file.url}
|
83
|
-
download={window.__is_colab__
|
85
|
+
download={is_browser && window.__is_colab__
|
86
|
+
? null
|
87
|
+
: file.orig_name}
|
84
88
|
>
|
85
89
|
{@html file.size != null
|
86
90
|
? prettyBytes(file.size)
|