@gradio/upload 0.17.9 → 0.17.10

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,15 @@
1
1
  # @gradio/upload
2
2
 
3
+ ## 0.17.10
4
+
5
+ ### Fixes
6
+
7
+ - [#13336](https://github.com/gradio-app/gradio/pull/13336) [`14c8870`](https://github.com/gradio-app/gradio/commit/14c88701756c5fa57e8eaeac4df1385b9601da45) - Add UploadButton unit tests. Thanks @freddyaboulton!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/client@2.2.1
12
+
3
13
  ## 0.17.9
4
14
 
5
15
  ### Dependency updates
@@ -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
 
@@ -160,40 +160,6 @@
160
160
  return upload_promise;
161
161
  }
162
162
 
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
163
  export async function load_files(
198
164
  files: File[] | Blob[],
199
165
  upload_id?: string
@@ -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";
@@ -1,3 +1,4 @@
1
+ export declare function is_valid_mimetype(file_accept: string | string[] | null, uploaded_file_extension: string, uploaded_file_type: string): boolean;
1
2
  interface DragActionOptions {
2
3
  disable_click?: boolean;
3
4
  accepted_types?: string | string[] | null;
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.17.9",
3
+ "version": "0.17.10",
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.24.0",
11
- "@gradio/utils": "^0.12.2",
12
10
  "@gradio/icons": "^0.15.1",
13
- "@gradio/client": "^2.2.0"
11
+ "@gradio/atoms": "^0.24.0",
12
+ "@gradio/client": "^2.2.1",
13
+ "@gradio/utils": "^0.12.2"
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
 
@@ -160,40 +160,6 @@
160
160
  return upload_promise;
161
161
  }
162
162
 
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
163
  export async function load_files(
198
164
  files: File[] | Blob[],
199
165
  upload_id?: string
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;