@gradio/file 0.2.7 → 0.3.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @gradio/file
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Features
6
+
7
+ - [#6511](https://github.com/gradio-app/gradio/pull/6511) [`71f1a1f99`](https://github.com/gradio-app/gradio/commit/71f1a1f9931489d465c2c1302a5c8d768a3cd23a) - Mark `FileData.orig_name` optional on the frontend aligning the type definition on the Python side. Thanks [@whitphx](https://github.com/whitphx)!
8
+ - [#6520](https://github.com/gradio-app/gradio/pull/6520) [`f94db6b73`](https://github.com/gradio-app/gradio/commit/f94db6b7319be902428887867500311a6a32a165) - File table style with accessible file name texts. Thanks [@whitphx](https://github.com/whitphx)!
9
+
3
10
  ## 0.2.7
4
11
 
5
12
  ### Patch Changes
@@ -240,4 +247,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
240
247
  - Updated dependencies []:
241
248
  - @gradio/utils@0.0.2
242
249
  - @gradio/atoms@0.0.2
243
- - @gradio/upload@0.0.2
250
+ - @gradio/upload@0.0.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/file",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -8,10 +8,10 @@
8
8
  "private": false,
9
9
  "dependencies": {
10
10
  "@gradio/atoms": "^0.3.0",
11
- "@gradio/client": "^0.8.1",
12
11
  "@gradio/icons": "^0.3.0",
13
12
  "@gradio/statustracker": "^0.4.0",
14
- "@gradio/upload": "^0.5.0",
13
+ "@gradio/client": "^0.8.2",
14
+ "@gradio/upload": "^0.5.1",
15
15
  "@gradio/utils": "^0.2.0"
16
16
  },
17
17
  "main": "./Index.svelte",
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { FileData } from "@gradio/client";
3
- import { display_file_name, display_file_size } from "./utils";
3
+ import { prettyBytes } from "./utils";
4
4
  import { createEventDispatcher } from "svelte";
5
5
  import type { I18nFormatter, SelectData } from "@gradio/utils";
6
6
 
@@ -11,6 +11,23 @@
11
11
  export let selectable = false;
12
12
  export let height: number | undefined = undefined;
13
13
  export let i18n: I18nFormatter;
14
+
15
+ function split_filename(filename: string): [string, string] {
16
+ const last_dot = filename.lastIndexOf(".");
17
+ if (last_dot === -1) {
18
+ return [filename, ""];
19
+ }
20
+ return [filename.slice(0, last_dot), filename.slice(last_dot)];
21
+ }
22
+
23
+ $: normalized_files = (Array.isArray(value) ? value : [value]).map((file) => {
24
+ const [filename_stem, filename_ext] = split_filename(file.orig_name ?? "");
25
+ return {
26
+ ...file,
27
+ filename_stem,
28
+ filename_ext
29
+ };
30
+ });
14
31
  </script>
15
32
 
16
33
  <div
@@ -19,7 +36,7 @@
19
36
  >
20
37
  <table class="file-preview">
21
38
  <tbody>
22
- {#each Array.isArray(value) ? value : [value] as file, i}
39
+ {#each normalized_files as file, i}
23
40
  <tr
24
41
  class="file"
25
42
  class:selectable
@@ -29,8 +46,9 @@
29
46
  index: i
30
47
  })}
31
48
  >
32
- <td>
33
- {display_file_name(file)}
49
+ <td class="filename" aria-label={file.orig_name}>
50
+ <span class="stem">{file.filename_stem}</span>
51
+ <span class="ext">{file.filename_ext}</span>
34
52
  </td>
35
53
 
36
54
  <td class="download">
@@ -40,7 +58,9 @@
40
58
  target="_blank"
41
59
  download={window.__is_colab__ ? null : file.orig_name}
42
60
  >
43
- {@html display_file_size(file)}&nbsp;&#8675;
61
+ {@html file.size != null
62
+ ? prettyBytes(file.size)
63
+ : "(size unknown)"}&nbsp;&#8675;
44
64
  </a>
45
65
  {:else}
46
66
  {i18n("file.uploading")}
@@ -53,26 +73,17 @@
53
73
  </div>
54
74
 
55
75
  <style>
56
- td {
57
- width: 45%;
58
- }
59
-
60
- td:last-child {
61
- width: 10%;
62
- text-align: right;
63
- }
64
- .file-preview-holder {
65
- overflow-x: auto;
66
- overflow-y: auto;
67
- }
68
76
  .file-preview {
77
+ table-layout: fixed;
69
78
  width: var(--size-full);
70
79
  max-height: var(--size-60);
71
80
  overflow-y: auto;
72
81
  margin-top: var(--size-1);
73
82
  color: var(--body-text-color);
74
83
  }
84
+
75
85
  .file {
86
+ display: flex;
76
87
  width: var(--size-full);
77
88
  }
78
89
 
@@ -80,6 +91,26 @@
80
91
  padding: var(--size-1) var(--size-2-5);
81
92
  }
82
93
 
94
+ .filename {
95
+ flex-grow: 1;
96
+ display: flex;
97
+ overflow: hidden;
98
+ }
99
+ .filename .stem {
100
+ overflow: hidden;
101
+ text-overflow: ellipsis;
102
+ white-space: nowrap;
103
+ }
104
+ .filename .ext {
105
+ white-space: nowrap;
106
+ }
107
+
108
+ .download {
109
+ min-width: 8rem;
110
+ width: 10%;
111
+ white-space: nowrap;
112
+ text-align: right;
113
+ }
83
114
  .download:hover {
84
115
  text-decoration: underline;
85
116
  }
package/shared/utils.ts CHANGED
@@ -10,32 +10,3 @@ export const prettyBytes = (bytes: number): string => {
10
10
  let unit = units[i];
11
11
  return bytes.toFixed(1) + "&nbsp;" + unit;
12
12
  };
13
-
14
- export const display_file_name = (value: FileData): string => {
15
- var str: string;
16
- str = value.orig_name;
17
- const max_length = 30;
18
-
19
- if (str.length > max_length) {
20
- const truncated_name = str.substring(0, max_length);
21
- const file_extension_index = str.lastIndexOf(".");
22
- if (file_extension_index !== -1) {
23
- const file_extension = str.slice(file_extension_index);
24
- return `${truncated_name}..${file_extension}`;
25
- }
26
- return truncated_name;
27
- }
28
- return str;
29
- };
30
-
31
- export const display_file_size = (value: FileData | FileData[]): string => {
32
- var total_size = 0;
33
- if (Array.isArray(value)) {
34
- for (var file of value) {
35
- if (file.size !== undefined) total_size += file.size;
36
- }
37
- } else {
38
- total_size = value.size || 0;
39
- }
40
- return prettyBytes(total_size);
41
- };