@gradio/upload 0.6.1 → 0.7.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @gradio/upload
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Features
6
+
7
+ - [#7206](https://github.com/gradio-app/gradio/pull/7206) [`572e360`](https://github.com/gradio-app/gradio/commit/572e360fff4a03c335b86e1a7517a44cb6af2bcd) - Upload tweak. Thanks [@pngwn](https://github.com/pngwn)!
8
+
9
+ ### Fixes
10
+
11
+ - [#7141](https://github.com/gradio-app/gradio/pull/7141) [`c3e61e4`](https://github.com/gradio-app/gradio/commit/c3e61e4f70696a71aede67b65d28447eb67daf16) - Few File component drag and drop. Thanks [@dawoodkhan82](https://github.com/dawoodkhan82)!
12
+
13
+ ## 0.7.0
14
+
15
+ ### Features
16
+
17
+ - [#7104](https://github.com/gradio-app/gradio/pull/7104) [`bc2cdc1`](https://github.com/gradio-app/gradio/commit/bc2cdc1df95b38025486cf76df4a494b66d98585) - Allow download button for interactive Audio and Video components. Thanks [@hannahblair](https://github.com/hannahblair)!
18
+
3
19
  ## 0.6.1
4
20
 
5
21
  ### Fixes
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
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/client": "^0.10.1",
11
- "@gradio/atoms": "^0.4.1",
12
- "@gradio/upload": "^0.6.1",
13
- "@gradio/utils": "^0.2.0",
14
- "@gradio/icons": "^0.3.2"
10
+ "@gradio/atoms": "^0.5.1",
11
+ "@gradio/client": "^0.11.0",
12
+ "@gradio/upload": "^0.7.1",
13
+ "@gradio/wasm": "^0.6.0",
14
+ "@gradio/icons": "^0.3.2",
15
+ "@gradio/utils": "^0.2.2"
15
16
  },
16
17
  "main_changeset": true,
17
18
  "exports": {
@@ -1,12 +1,14 @@
1
1
  <script lang="ts">
2
2
  import { IconButton } from "@gradio/atoms";
3
3
  import type { I18nFormatter } from "@gradio/utils";
4
- import { Edit, Clear, Undo } from "@gradio/icons";
4
+ import { Edit, Clear, Undo, Download } from "@gradio/icons";
5
+ import { DownloadLink } from "@gradio/wasm/svelte";
5
6
 
6
7
  import { createEventDispatcher } from "svelte";
7
8
 
8
9
  export let editable = false;
9
10
  export let undoable = false;
11
+ export let download: string | null = null;
10
12
  export let absolute = true;
11
13
  export let i18n: I18nFormatter;
12
14
 
@@ -37,6 +39,12 @@
37
39
  />
38
40
  {/if}
39
41
 
42
+ {#if download}
43
+ <DownloadLink href={download} download>
44
+ <IconButton Icon={Download} label={i18n("common.download")} />
45
+ </DownloadLink>
46
+ {/if}
47
+
40
48
  <IconButton
41
49
  Icon={Clear}
42
50
  label={i18n("common.clear")}
package/src/Upload.svelte CHANGED
@@ -27,7 +27,6 @@
27
27
  let hidden_upload: HTMLInputElement;
28
28
 
29
29
  const dispatch = createEventDispatcher();
30
-
31
30
  $: if (filetype == null || typeof filetype === "string") {
32
31
  accept_file_types = filetype;
33
32
  } else {
@@ -106,24 +105,29 @@
106
105
 
107
106
  function is_valid_mimetype(
108
107
  file_accept: string | string[] | null,
109
- mime_type: string
108
+ uploaded_file_extension: string,
109
+ uploaded_file_type: string
110
110
  ): boolean {
111
111
  if (!file_accept || file_accept === "*" || file_accept === "file/*") {
112
112
  return true;
113
113
  }
114
- if (typeof file_accept === "string" && file_accept.endsWith("/*")) {
115
- file_accept = file_accept.split(",");
116
- }
117
- if (Array.isArray(file_accept)) {
118
- return (
119
- file_accept.includes(mime_type) ||
120
- file_accept.some((type) => {
121
- const [category] = type.split("/");
122
- return type.endsWith("/*") && mime_type.startsWith(category + "/");
123
- })
124
- );
114
+ let acceptArray: string[];
115
+ if (typeof file_accept === "string") {
116
+ acceptArray = file_accept.split(",").map((s) => s.trim());
117
+ } else if (Array.isArray(file_accept)) {
118
+ acceptArray = file_accept;
119
+ } else {
120
+ return false;
125
121
  }
126
- return file_accept === mime_type;
122
+ return (
123
+ acceptArray.includes(uploaded_file_extension) ||
124
+ acceptArray.some((type) => {
125
+ const [category] = type.split("/").map((s) => s.trim());
126
+ return (
127
+ type.endsWith("/*") && uploaded_file_type.startsWith(category + "/")
128
+ );
129
+ })
130
+ );
127
131
  }
128
132
 
129
133
  async function loadFilesFromDrop(e: DragEvent): Promise<void> {
@@ -131,7 +135,10 @@
131
135
  if (!e.dataTransfer?.files) return;
132
136
  const files_to_load = Array.from(e.dataTransfer.files).filter((file) => {
133
137
  const file_extension = "." + file.name.split(".").pop();
134
- if (file.type && is_valid_mimetype(filetype, file.type)) {
138
+ if (
139
+ file_extension &&
140
+ is_valid_mimetype(filetype, file_extension, file.type)
141
+ ) {
135
142
  return true;
136
143
  }
137
144
  if (
@@ -111,6 +111,7 @@
111
111
  align-items: center;
112
112
  justify-content: center;
113
113
  min-height: var(--size-40);
114
+ width: var(--size-full);
114
115
  }
115
116
 
116
117
  .wrap::after {