@gradio/dataframe 0.16.5 → 0.17.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 +34 -0
- package/Dataframe.stories.svelte +202 -9
- package/Index.svelte +7 -13
- package/dist/Index.svelte +5 -9
- package/dist/Index.svelte.d.ts +9 -2
- package/dist/shared/CellMenu.svelte +91 -10
- package/dist/shared/CellMenu.svelte.d.ts +6 -0
- package/dist/shared/CellMenuButton.svelte +45 -0
- package/dist/shared/CellMenuButton.svelte.d.ts +16 -0
- package/dist/shared/CellMenuIcons.svelte +79 -0
- package/dist/shared/EditableCell.svelte +83 -14
- package/dist/shared/EditableCell.svelte.d.ts +12 -3
- package/dist/shared/EmptyRowButton.svelte +28 -0
- package/dist/shared/EmptyRowButton.svelte.d.ts +16 -0
- package/dist/shared/RowNumber.svelte +40 -0
- package/dist/shared/RowNumber.svelte.d.ts +17 -0
- package/dist/shared/Table.svelte +564 -1121
- package/dist/shared/Table.svelte.d.ts +4 -0
- package/dist/shared/TableCell.svelte +291 -0
- package/dist/shared/TableCell.svelte.d.ts +57 -0
- package/dist/shared/TableHeader.svelte +239 -0
- package/dist/shared/TableHeader.svelte.d.ts +45 -0
- package/dist/shared/Toolbar.svelte +18 -8
- package/dist/shared/VirtualTable.svelte +66 -19
- package/dist/shared/VirtualTable.svelte.d.ts +4 -0
- package/dist/shared/context/keyboard_context.d.ts +37 -0
- package/dist/shared/context/keyboard_context.js +12 -0
- package/dist/shared/context/selection_context.d.ts +32 -0
- package/dist/shared/context/selection_context.js +107 -0
- package/dist/shared/context/table_context.d.ts +141 -0
- package/dist/shared/context/table_context.js +375 -0
- package/dist/shared/icons/Padlock.svelte +24 -0
- package/dist/shared/icons/Padlock.svelte.d.ts +23 -0
- package/dist/shared/icons/SelectionButtons.svelte +85 -0
- package/dist/shared/icons/SelectionButtons.svelte.d.ts +18 -0
- package/dist/shared/icons/SortArrowDown.svelte +24 -0
- package/dist/shared/icons/SortArrowDown.svelte.d.ts +16 -0
- package/dist/shared/icons/SortArrowUp.svelte +24 -0
- package/dist/shared/icons/SortArrowUp.svelte.d.ts +16 -0
- package/dist/shared/icons/SortButtonDown.svelte +14 -0
- package/dist/shared/icons/SortButtonDown.svelte.d.ts +23 -0
- package/dist/shared/icons/SortButtonUp.svelte +15 -0
- package/dist/shared/icons/SortButtonUp.svelte.d.ts +23 -0
- package/dist/shared/icons/SortIcon.svelte +46 -68
- package/dist/shared/icons/SortIcon.svelte.d.ts +3 -2
- package/dist/shared/selection_utils.d.ts +2 -1
- package/dist/shared/selection_utils.js +39 -10
- package/dist/shared/utils/data_processing.d.ts +13 -0
- package/dist/shared/utils/data_processing.js +45 -0
- package/dist/shared/utils/drag_utils.d.ts +15 -0
- package/dist/shared/utils/drag_utils.js +57 -0
- package/dist/shared/utils/keyboard_utils.d.ts +2 -0
- package/dist/shared/utils/keyboard_utils.js +186 -0
- package/dist/shared/utils/sort_utils.d.ts +22 -3
- package/dist/shared/utils/sort_utils.js +44 -24
- package/dist/shared/utils/table_utils.d.ts +6 -5
- package/dist/shared/utils/table_utils.js +13 -56
- package/package.json +7 -7
- package/shared/CellMenu.svelte +90 -10
- package/shared/CellMenuButton.svelte +46 -0
- package/shared/CellMenuIcons.svelte +79 -0
- package/shared/EditableCell.svelte +97 -18
- package/shared/EmptyRowButton.svelte +29 -0
- package/shared/RowNumber.svelte +41 -0
- package/shared/Table.svelte +604 -1235
- package/shared/TableCell.svelte +324 -0
- package/shared/TableHeader.svelte +256 -0
- package/shared/Toolbar.svelte +19 -8
- package/shared/VirtualTable.svelte +72 -19
- package/shared/context/keyboard_context.ts +65 -0
- package/shared/context/selection_context.ts +168 -0
- package/shared/context/table_context.ts +625 -0
- package/shared/icons/Padlock.svelte +24 -0
- package/shared/icons/SelectionButtons.svelte +93 -0
- package/shared/icons/SortArrowDown.svelte +25 -0
- package/shared/icons/SortArrowUp.svelte +25 -0
- package/shared/icons/SortButtonDown.svelte +14 -0
- package/shared/icons/SortButtonUp.svelte +15 -0
- package/shared/icons/SortIcon.svelte +47 -70
- package/shared/selection_utils.ts +39 -13
- package/shared/utils/data_processing.ts +72 -0
- package/shared/utils/drag_utils.ts +92 -0
- package/shared/utils/keyboard_utils.ts +238 -0
- package/shared/utils/sort_utils.test.ts +262 -14
- package/shared/utils/sort_utils.ts +67 -31
- package/shared/utils/table_utils.test.ts +66 -45
- package/shared/utils/table_utils.ts +16 -86
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { createEventDispatcher } from "svelte";
|
|
3
3
|
import { MarkdownCode } from "@gradio/markdown-code";
|
|
4
|
-
|
|
4
|
+
import type { I18nFormatter } from "@gradio/utils";
|
|
5
|
+
import SelectionButtons from "./icons/SelectionButtons.svelte";
|
|
5
6
|
export let edit: boolean;
|
|
6
7
|
export let value: string | number = "";
|
|
7
8
|
export let display_value: string | null = null;
|
|
@@ -13,7 +14,8 @@
|
|
|
13
14
|
| "html"
|
|
14
15
|
| "number"
|
|
15
16
|
| "bool"
|
|
16
|
-
| "date"
|
|
17
|
+
| "date"
|
|
18
|
+
| "image" = "str";
|
|
17
19
|
export let latex_delimiters: {
|
|
18
20
|
left: string;
|
|
19
21
|
right: string;
|
|
@@ -22,10 +24,23 @@
|
|
|
22
24
|
export let clear_on_focus = false;
|
|
23
25
|
export let line_breaks = true;
|
|
24
26
|
export let editable = true;
|
|
27
|
+
export let is_static = false;
|
|
25
28
|
export let root: string;
|
|
26
29
|
export let max_chars: number | null = null;
|
|
30
|
+
export let components: Record<string, any> = {};
|
|
31
|
+
export let i18n: I18nFormatter;
|
|
32
|
+
export let is_dragging = false;
|
|
33
|
+
|
|
34
|
+
export let show_selection_buttons = false;
|
|
35
|
+
export let coords: [number, number] | null = null;
|
|
36
|
+
export let on_select_column: ((col: number) => void) | null = null;
|
|
37
|
+
export let on_select_row: ((row: number) => void) | null = null;
|
|
38
|
+
|
|
39
|
+
const dispatch = createEventDispatcher<{
|
|
40
|
+
blur: void;
|
|
41
|
+
keydown: KeyboardEvent;
|
|
42
|
+
}>();
|
|
27
43
|
|
|
28
|
-
const dispatch = createEventDispatcher();
|
|
29
44
|
let is_expanded = false;
|
|
30
45
|
|
|
31
46
|
export let el: HTMLInputElement | null;
|
|
@@ -33,16 +48,28 @@
|
|
|
33
48
|
|
|
34
49
|
function truncate_text(
|
|
35
50
|
text: string | number,
|
|
36
|
-
max_length: number | null = null
|
|
51
|
+
max_length: number | null = null,
|
|
52
|
+
is_image = false
|
|
37
53
|
): string {
|
|
54
|
+
if (is_image) return String(text);
|
|
38
55
|
const str = String(text);
|
|
39
|
-
if (!max_length ||
|
|
56
|
+
if (!max_length || max_length <= 0) return str;
|
|
57
|
+
if (str.length <= max_length) return str;
|
|
40
58
|
return str.slice(0, max_length) + "...";
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
$:
|
|
61
|
+
$: should_truncate =
|
|
62
|
+
!edit && !is_expanded && max_chars !== null && max_chars > 0;
|
|
63
|
+
|
|
64
|
+
$: display_content = editable
|
|
44
65
|
? value
|
|
45
|
-
:
|
|
66
|
+
: display_value !== null
|
|
67
|
+
? display_value
|
|
68
|
+
: value;
|
|
69
|
+
|
|
70
|
+
$: display_text = should_truncate
|
|
71
|
+
? truncate_text(display_content, max_chars, datatype === "image")
|
|
72
|
+
: display_content;
|
|
46
73
|
|
|
47
74
|
function use_focus(node: HTMLInputElement): any {
|
|
48
75
|
if (clear_on_focus) {
|
|
@@ -86,7 +113,10 @@
|
|
|
86
113
|
|
|
87
114
|
{#if edit}
|
|
88
115
|
<input
|
|
116
|
+
readonly={is_static}
|
|
117
|
+
aria-readonly={is_static}
|
|
89
118
|
role="textbox"
|
|
119
|
+
aria-label={is_static ? "Cell is read-only" : "Edit cell"}
|
|
90
120
|
bind:this={el}
|
|
91
121
|
bind:value={_value}
|
|
92
122
|
class:header
|
|
@@ -101,6 +131,7 @@
|
|
|
101
131
|
{/if}
|
|
102
132
|
|
|
103
133
|
<span
|
|
134
|
+
class:dragging={is_dragging}
|
|
104
135
|
on:click={handle_click}
|
|
105
136
|
on:keydown={handle_keydown}
|
|
106
137
|
tabindex="0"
|
|
@@ -111,9 +142,22 @@
|
|
|
111
142
|
on:focus|preventDefault
|
|
112
143
|
style={styling}
|
|
113
144
|
data-editable={editable}
|
|
145
|
+
data-max-chars={max_chars}
|
|
146
|
+
data-expanded={is_expanded}
|
|
114
147
|
placeholder=" "
|
|
148
|
+
class:text={datatype === "str"}
|
|
115
149
|
>
|
|
116
|
-
{#if datatype === "
|
|
150
|
+
{#if datatype === "image" && components.image}
|
|
151
|
+
<svelte:component
|
|
152
|
+
this={components.image}
|
|
153
|
+
value={{ url: display_text }}
|
|
154
|
+
show_label={false}
|
|
155
|
+
label="cell-image"
|
|
156
|
+
show_download_button={false}
|
|
157
|
+
{i18n}
|
|
158
|
+
gradio={{ dispatch: () => {} }}
|
|
159
|
+
/>
|
|
160
|
+
{:else if datatype === "html"}
|
|
117
161
|
{@html display_text}
|
|
118
162
|
{:else if datatype === "markdown"}
|
|
119
163
|
<MarkdownCode
|
|
@@ -124,23 +168,36 @@
|
|
|
124
168
|
{root}
|
|
125
169
|
/>
|
|
126
170
|
{:else}
|
|
127
|
-
{
|
|
171
|
+
{display_text}
|
|
128
172
|
{/if}
|
|
129
173
|
</span>
|
|
174
|
+
{#if show_selection_buttons && coords && on_select_column && on_select_row}
|
|
175
|
+
<SelectionButtons
|
|
176
|
+
position="column"
|
|
177
|
+
{coords}
|
|
178
|
+
on_click={() => on_select_column(coords[1])}
|
|
179
|
+
/>
|
|
180
|
+
<SelectionButtons
|
|
181
|
+
position="row"
|
|
182
|
+
{coords}
|
|
183
|
+
on_click={() => on_select_row(coords[0])}
|
|
184
|
+
/>
|
|
185
|
+
{/if}
|
|
130
186
|
|
|
131
187
|
<style>
|
|
188
|
+
.dragging {
|
|
189
|
+
cursor: crosshair !important;
|
|
190
|
+
}
|
|
191
|
+
|
|
132
192
|
input {
|
|
133
193
|
position: absolute;
|
|
134
|
-
top: var(--size-2);
|
|
135
|
-
right: var(--size-2);
|
|
136
|
-
bottom: var(--size-2);
|
|
137
|
-
left: var(--size-2);
|
|
138
194
|
flex: 1 1 0%;
|
|
139
195
|
transform: translateX(-0.1px);
|
|
140
196
|
outline: none;
|
|
141
197
|
border: none;
|
|
142
198
|
background: transparent;
|
|
143
199
|
cursor: text;
|
|
200
|
+
width: calc(100% - var(--size-2));
|
|
144
201
|
}
|
|
145
202
|
|
|
146
203
|
span {
|
|
@@ -155,25 +212,37 @@
|
|
|
155
212
|
cursor: text;
|
|
156
213
|
width: 100%;
|
|
157
214
|
height: 100%;
|
|
215
|
+
overflow: hidden;
|
|
216
|
+
text-overflow: ellipsis;
|
|
217
|
+
white-space: nowrap;
|
|
158
218
|
}
|
|
159
219
|
|
|
160
|
-
span.expanded {
|
|
220
|
+
span.text:not(.expanded) {
|
|
221
|
+
overflow: hidden;
|
|
222
|
+
text-overflow: ellipsis;
|
|
223
|
+
white-space: nowrap;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
span.text.expanded {
|
|
161
227
|
height: auto;
|
|
162
228
|
min-height: 100%;
|
|
163
229
|
white-space: pre-wrap;
|
|
164
230
|
word-break: break-word;
|
|
165
|
-
|
|
231
|
+
overflow: visible;
|
|
166
232
|
}
|
|
167
233
|
|
|
168
234
|
.multiline {
|
|
169
|
-
white-space: pre
|
|
235
|
+
white-space: pre;
|
|
236
|
+
overflow: hidden;
|
|
237
|
+
text-overflow: ellipsis;
|
|
170
238
|
}
|
|
171
239
|
|
|
172
240
|
.header {
|
|
173
241
|
transform: translateX(0);
|
|
174
242
|
font-weight: var(--weight-bold);
|
|
175
|
-
white-space:
|
|
176
|
-
|
|
243
|
+
white-space: nowrap;
|
|
244
|
+
overflow: hidden;
|
|
245
|
+
text-overflow: ellipsis;
|
|
177
246
|
margin-left: var(--size-1);
|
|
178
247
|
}
|
|
179
248
|
|
|
@@ -181,4 +250,14 @@
|
|
|
181
250
|
opacity: 0;
|
|
182
251
|
pointer-events: none;
|
|
183
252
|
}
|
|
253
|
+
|
|
254
|
+
span :global(img) {
|
|
255
|
+
max-height: 100px;
|
|
256
|
+
width: auto;
|
|
257
|
+
object-fit: contain;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
input:read-only {
|
|
261
|
+
cursor: not-allowed;
|
|
262
|
+
}
|
|
184
263
|
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export let on_click: () => void;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<button class="add-row-button" on:click={on_click} aria-label="Add row">
|
|
6
|
+
+
|
|
7
|
+
</button>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
.add-row-button {
|
|
11
|
+
width: 100%;
|
|
12
|
+
padding: var(--size-1);
|
|
13
|
+
background: transparent;
|
|
14
|
+
border: 1px dashed var(--border-color-primary);
|
|
15
|
+
border-radius: var(--radius-sm);
|
|
16
|
+
color: var(--body-text-color);
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
transition: all 150ms;
|
|
19
|
+
margin-top: var(--size-2);
|
|
20
|
+
z-index: 10;
|
|
21
|
+
position: relative;
|
|
22
|
+
pointer-events: auto;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.add-row-button:hover {
|
|
26
|
+
background: var(--background-fill-secondary);
|
|
27
|
+
border-style: solid;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export let index: number | null = null;
|
|
3
|
+
export let is_header = false;
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
{#if is_header}
|
|
7
|
+
<th tabindex="-1" class="row-number">
|
|
8
|
+
<div class="cell-wrap">
|
|
9
|
+
<div class="header-content">
|
|
10
|
+
<div class="header-text"></div>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</th>
|
|
14
|
+
{:else}
|
|
15
|
+
<td class="row-number" tabindex="-1" data-row={index} data-col="row-number">
|
|
16
|
+
{index !== null ? index + 1 : ""}
|
|
17
|
+
</td>
|
|
18
|
+
{/if}
|
|
19
|
+
|
|
20
|
+
<style>
|
|
21
|
+
.row-number {
|
|
22
|
+
text-align: center;
|
|
23
|
+
padding: var(--size-1);
|
|
24
|
+
min-width: var(--size-12);
|
|
25
|
+
width: var(--size-12);
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
text-overflow: ellipsis;
|
|
28
|
+
white-space: nowrap;
|
|
29
|
+
font-weight: var(--weight-semibold);
|
|
30
|
+
background: var(--table-even-background-fill);
|
|
31
|
+
border-right: 1px solid var(--border-color-primary);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:global(tr:nth-child(odd)) .row-number {
|
|
35
|
+
background: var(--table-odd-background-fill);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:global(tr:nth-child(even)) .row-number {
|
|
39
|
+
background: var(--table-even-background-fill);
|
|
40
|
+
}
|
|
41
|
+
</style>
|