@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,4 +1,4 @@
|
|
|
1
|
-
<script>import { onMount, tick } from "svelte";
|
|
1
|
+
<script>import { onMount, tick, createEventDispatcher } from "svelte";
|
|
2
2
|
import { _ } from "svelte-i18n";
|
|
3
3
|
export let items = [];
|
|
4
4
|
export let max_height;
|
|
@@ -8,6 +8,9 @@ export let start = 0;
|
|
|
8
8
|
export let end = 20;
|
|
9
9
|
export let selected;
|
|
10
10
|
export let disable_scroll = false;
|
|
11
|
+
export let show_scroll_button = false;
|
|
12
|
+
export let viewport;
|
|
13
|
+
const dispatch = createEventDispatcher();
|
|
11
14
|
let height = "100%";
|
|
12
15
|
let average_height = 30;
|
|
13
16
|
let bottom = 0;
|
|
@@ -18,7 +21,6 @@ let height_map = [];
|
|
|
18
21
|
let mounted;
|
|
19
22
|
let rows;
|
|
20
23
|
let top = 0;
|
|
21
|
-
let viewport;
|
|
22
24
|
let viewport_height = 200;
|
|
23
25
|
let visible = [];
|
|
24
26
|
let viewport_box;
|
|
@@ -120,6 +122,10 @@ function get_computed_px_amount(elem, property) {
|
|
|
120
122
|
}
|
|
121
123
|
async function handle_scroll(e) {
|
|
122
124
|
const scroll_top = viewport.scrollTop;
|
|
125
|
+
show_scroll_button = scroll_top > 100;
|
|
126
|
+
if (show_scroll_button) {
|
|
127
|
+
dispatch("scroll_top", scroll_top);
|
|
128
|
+
}
|
|
123
129
|
rows = contents.children;
|
|
124
130
|
const is_start_overflow = sortedItems.length < start;
|
|
125
131
|
const row_top_border = get_computed_px_amount(rows[1], "border-top-width");
|
|
@@ -236,8 +242,7 @@ onMount(() => {
|
|
|
236
242
|
<style>
|
|
237
243
|
table {
|
|
238
244
|
position: relative;
|
|
239
|
-
overflow
|
|
240
|
-
overflow-x: scroll;
|
|
245
|
+
overflow: auto;
|
|
241
246
|
-webkit-overflow-scrolling: touch;
|
|
242
247
|
max-height: var(--max-height);
|
|
243
248
|
box-sizing: border-box;
|
|
@@ -252,7 +257,52 @@ onMount(() => {
|
|
|
252
257
|
width: 100%;
|
|
253
258
|
scroll-snap-type: x proximity;
|
|
254
259
|
border-collapse: separate;
|
|
260
|
+
scrollbar-width: thin;
|
|
261
|
+
scrollbar-color: rgba(128, 128, 128, 0.5) transparent;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
table::-webkit-scrollbar {
|
|
265
|
+
width: 4px;
|
|
266
|
+
height: 4px;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
table::-webkit-scrollbar-track {
|
|
270
|
+
background: transparent;
|
|
255
271
|
}
|
|
272
|
+
|
|
273
|
+
table::-webkit-scrollbar-thumb {
|
|
274
|
+
background-color: rgba(128, 128, 128, 0.5);
|
|
275
|
+
border-radius: 4px;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
table:hover {
|
|
279
|
+
scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
table:hover::-webkit-scrollbar-thumb {
|
|
283
|
+
background-color: rgba(160, 160, 160, 0.7);
|
|
284
|
+
border-radius: 4px;
|
|
285
|
+
width: 4px;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
@media (hover: none) {
|
|
289
|
+
table {
|
|
290
|
+
scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
table::-webkit-scrollbar-thumb {
|
|
294
|
+
background-color: rgba(160, 160, 160, 0.7);
|
|
295
|
+
border-radius: 4px;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@media (pointer: coarse) {
|
|
300
|
+
table::-webkit-scrollbar {
|
|
301
|
+
width: 8px;
|
|
302
|
+
height: 8px;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
256
306
|
table :is(thead, tfoot, tbody) {
|
|
257
307
|
display: table;
|
|
258
308
|
table-layout: fixed;
|
|
@@ -287,46 +337,43 @@ onMount(() => {
|
|
|
287
337
|
background: var(--table-even-background-fill);
|
|
288
338
|
}
|
|
289
339
|
|
|
290
|
-
tbody :global(td.
|
|
340
|
+
tbody :global(td.pinned-column) {
|
|
291
341
|
position: sticky;
|
|
292
|
-
z-index:
|
|
342
|
+
z-index: 3;
|
|
293
343
|
}
|
|
294
344
|
|
|
295
|
-
tbody :global(tr:nth-child(odd)) :global(td.
|
|
345
|
+
tbody :global(tr:nth-child(odd)) :global(td.pinned-column) {
|
|
296
346
|
background: var(--table-odd-background-fill);
|
|
297
347
|
}
|
|
298
348
|
|
|
299
|
-
tbody :global(tr:nth-child(even)) :global(td.
|
|
349
|
+
tbody :global(tr:nth-child(even)) :global(td.pinned-column) {
|
|
300
350
|
background: var(--table-even-background-fill);
|
|
301
351
|
}
|
|
302
352
|
|
|
303
|
-
tbody :global(td.
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
tbody :global(td.last-frozen) {
|
|
308
|
-
border-right: 2px solid var(--border-color-primary);
|
|
353
|
+
tbody :global(td.last-pinned) {
|
|
354
|
+
border-right: 1px solid var(--border-color-primary);
|
|
309
355
|
}
|
|
310
356
|
|
|
311
357
|
thead {
|
|
312
358
|
position: sticky;
|
|
313
359
|
top: 0;
|
|
314
360
|
left: 0;
|
|
315
|
-
z-index: var(--layer-3);
|
|
316
361
|
background: var(--background-fill-primary);
|
|
362
|
+
z-index: 7;
|
|
317
363
|
}
|
|
318
364
|
|
|
319
365
|
thead :global(th) {
|
|
320
366
|
background: var(--table-even-background-fill) !important;
|
|
321
367
|
}
|
|
322
368
|
|
|
323
|
-
thead :global(th.
|
|
369
|
+
thead :global(th.pinned-column) {
|
|
324
370
|
position: sticky;
|
|
325
|
-
z-index:
|
|
371
|
+
z-index: 7;
|
|
372
|
+
background: var(--table-even-background-fill) !important;
|
|
326
373
|
}
|
|
327
374
|
|
|
328
|
-
thead :global(th.
|
|
329
|
-
|
|
375
|
+
thead :global(th.last-pinned) {
|
|
376
|
+
border-right: 1px solid var(--border-color-primary);
|
|
330
377
|
}
|
|
331
378
|
|
|
332
379
|
.table.disable-scroll {
|
|
@@ -9,9 +9,13 @@ declare const __propDef: {
|
|
|
9
9
|
end?: number | undefined;
|
|
10
10
|
selected: number | false;
|
|
11
11
|
disable_scroll?: boolean | undefined;
|
|
12
|
+
show_scroll_button?: boolean | undefined;
|
|
13
|
+
viewport: HTMLTableElement;
|
|
12
14
|
scroll_to_index?: ((index: number, opts: ScrollToOptions, align_end?: boolean) => Promise<void>) | undefined;
|
|
13
15
|
};
|
|
14
16
|
events: {
|
|
17
|
+
scroll_top: CustomEvent<number>;
|
|
18
|
+
} & {
|
|
15
19
|
[evt: string]: CustomEvent<any>;
|
|
16
20
|
};
|
|
17
21
|
slots: {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DataFrameContext } from "./table_context";
|
|
2
|
+
import type { CellData } from "../selection_utils";
|
|
3
|
+
import type { DataframeValue } from "../utils";
|
|
4
|
+
import type { CellCoordinate } from "../types";
|
|
5
|
+
export type KeyboardContext = {
|
|
6
|
+
selected_header: number | false;
|
|
7
|
+
header_edit: number | false;
|
|
8
|
+
editing: [number, number] | false;
|
|
9
|
+
selected: [number, number] | false;
|
|
10
|
+
selected_cells: [number, number][];
|
|
11
|
+
editable: boolean;
|
|
12
|
+
data: CellData[][];
|
|
13
|
+
headers: {
|
|
14
|
+
id: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}[];
|
|
17
|
+
els: Record<string, {
|
|
18
|
+
cell: null | HTMLTableCellElement;
|
|
19
|
+
input: null | HTMLInputElement;
|
|
20
|
+
}>;
|
|
21
|
+
df_actions: DataFrameContext["actions"];
|
|
22
|
+
dispatch: {
|
|
23
|
+
(e: "change", detail: DataframeValue): void;
|
|
24
|
+
(e: "input", detail?: undefined): void;
|
|
25
|
+
(e: "select", detail: any): void;
|
|
26
|
+
(e: "search", detail: string | null): void;
|
|
27
|
+
};
|
|
28
|
+
add_row: (index?: number) => Promise<void>;
|
|
29
|
+
get_next_cell_coordinates: (current: CellCoordinate, data: CellData[][], shift_key: boolean) => false | CellCoordinate;
|
|
30
|
+
get_range_selection: (start: CellCoordinate, end: CellCoordinate) => CellCoordinate[];
|
|
31
|
+
move_cursor: (event: KeyboardEvent, current_coords: CellCoordinate, data: CellData[][]) => false | CellCoordinate;
|
|
32
|
+
copy_flash: boolean;
|
|
33
|
+
set_copy_flash: (value: boolean) => void;
|
|
34
|
+
parent_element?: HTMLDivElement;
|
|
35
|
+
};
|
|
36
|
+
export declare function create_keyboard_context(context: KeyboardContext): KeyboardContext;
|
|
37
|
+
export declare function get_keyboard_context(): KeyboardContext | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getContext, setContext } from "svelte";
|
|
2
|
+
const KEYBOARD_KEY = Symbol("keyboard");
|
|
3
|
+
export function create_keyboard_context(context) {
|
|
4
|
+
const instance_id = Symbol(`keyboard_${Math.random().toString(36).substring(2)}`);
|
|
5
|
+
setContext(instance_id, context);
|
|
6
|
+
setContext(KEYBOARD_KEY, { instance_id, context });
|
|
7
|
+
return context;
|
|
8
|
+
}
|
|
9
|
+
export function get_keyboard_context() {
|
|
10
|
+
const ctx = getContext(KEYBOARD_KEY);
|
|
11
|
+
return ctx ? ctx.context : getContext(KEYBOARD_KEY);
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DataFrameContext } from "./table_context";
|
|
2
|
+
import type { CellData } from "../selection_utils";
|
|
3
|
+
import type { DataframeValue } from "../utils";
|
|
4
|
+
export type SelectionContext = {
|
|
5
|
+
df_actions: DataFrameContext["actions"];
|
|
6
|
+
dispatch: {
|
|
7
|
+
(e: "change", detail: DataframeValue): void;
|
|
8
|
+
(e: "input", detail?: undefined): void;
|
|
9
|
+
(e: "select", detail: any): void;
|
|
10
|
+
(e: "search", detail: string | null): void;
|
|
11
|
+
};
|
|
12
|
+
data: CellData[][];
|
|
13
|
+
els: Record<string, {
|
|
14
|
+
cell: null | HTMLTableCellElement;
|
|
15
|
+
input: null | HTMLInputElement;
|
|
16
|
+
}>;
|
|
17
|
+
editable: boolean;
|
|
18
|
+
show_row_numbers: boolean;
|
|
19
|
+
get_data_at: (row: number, col: number) => string | number;
|
|
20
|
+
clear_on_focus: boolean;
|
|
21
|
+
selected_cells: [number, number][];
|
|
22
|
+
parent_element: HTMLElement;
|
|
23
|
+
actions: {
|
|
24
|
+
handle_cell_click: (event: MouseEvent, row: number, col: number) => void;
|
|
25
|
+
toggle_cell_menu: (event: MouseEvent, row: number, col: number) => void;
|
|
26
|
+
toggle_cell_button: (row: number, col: number) => void;
|
|
27
|
+
handle_select_column: (col: number) => void;
|
|
28
|
+
handle_select_row: (row: number) => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare function create_selection_context(context: Omit<SelectionContext, "actions">): SelectionContext;
|
|
32
|
+
export declare function get_selection_context(): SelectionContext;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getContext, setContext } from "svelte";
|
|
2
|
+
import { tick } from "svelte";
|
|
3
|
+
import { handle_selection } from "../selection_utils";
|
|
4
|
+
const SELECTION_KEY = Symbol("selection");
|
|
5
|
+
export function create_selection_context(context) {
|
|
6
|
+
const instance_id = Symbol(`selection_${Math.random().toString(36).substring(2)}`);
|
|
7
|
+
const actions = {
|
|
8
|
+
handle_cell_click: (event, row, col) => {
|
|
9
|
+
if (event.target instanceof HTMLAnchorElement)
|
|
10
|
+
return;
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
event.stopPropagation();
|
|
13
|
+
if (context.show_row_numbers && col === -1)
|
|
14
|
+
return;
|
|
15
|
+
context.clear_on_focus = false;
|
|
16
|
+
context.df_actions.set_active_cell_menu(null);
|
|
17
|
+
context.df_actions.set_active_header_menu(null);
|
|
18
|
+
context.df_actions.set_selected_header(false);
|
|
19
|
+
context.df_actions.set_header_edit(false);
|
|
20
|
+
const new_selected_cells = handle_selection([row, col], context.selected_cells || [], event);
|
|
21
|
+
context.df_actions.set_selected_cells(new_selected_cells);
|
|
22
|
+
context.df_actions.set_selected(new_selected_cells[0]);
|
|
23
|
+
if (context.editable) {
|
|
24
|
+
if (new_selected_cells.length === 1) {
|
|
25
|
+
context.df_actions.set_editing([row, col]);
|
|
26
|
+
tick().then(() => {
|
|
27
|
+
const input_el = context.els[context.data[row][col].id].input;
|
|
28
|
+
if (input_el) {
|
|
29
|
+
input_el.focus();
|
|
30
|
+
input_el.selectionStart = input_el.selectionEnd =
|
|
31
|
+
input_el.value.length;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
context.df_actions.set_editing(false);
|
|
37
|
+
context.parent_element.focus();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
context.parent_element.focus();
|
|
42
|
+
}
|
|
43
|
+
actions.toggle_cell_button(row, col);
|
|
44
|
+
context.dispatch("select", {
|
|
45
|
+
index: [row, col],
|
|
46
|
+
value: context.get_data_at(row, col),
|
|
47
|
+
row_value: context.data[row].map((d) => d.value)
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
toggle_cell_menu: (event, row, col) => {
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
const current_menu = context.df_actions.get_active_cell_menu();
|
|
53
|
+
if (current_menu &&
|
|
54
|
+
current_menu.row === row &&
|
|
55
|
+
current_menu.col === col) {
|
|
56
|
+
context.df_actions.set_active_cell_menu(null);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const cell = event.target.closest("td");
|
|
60
|
+
if (cell) {
|
|
61
|
+
const rect = cell.getBoundingClientRect();
|
|
62
|
+
context.df_actions.set_active_cell_menu({
|
|
63
|
+
row,
|
|
64
|
+
col,
|
|
65
|
+
x: rect.right,
|
|
66
|
+
y: rect.bottom
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
toggle_cell_button: (row, col) => {
|
|
72
|
+
const current_button = context.df_actions.get_active_button();
|
|
73
|
+
const new_button = current_button?.type === "cell" &&
|
|
74
|
+
current_button.row === row &&
|
|
75
|
+
current_button.col === col
|
|
76
|
+
? null
|
|
77
|
+
: { type: "cell", row, col };
|
|
78
|
+
context.df_actions.set_active_button(new_button);
|
|
79
|
+
},
|
|
80
|
+
handle_select_column: (col) => {
|
|
81
|
+
const selected_cells = context.data.map((_, row) => [row, col]);
|
|
82
|
+
context.df_actions.set_selected_cells(selected_cells);
|
|
83
|
+
context.df_actions.set_selected(selected_cells[0]);
|
|
84
|
+
context.df_actions.set_editing(false);
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
context.parent_element.focus();
|
|
87
|
+
}, 0);
|
|
88
|
+
},
|
|
89
|
+
handle_select_row: (row) => {
|
|
90
|
+
const selected_cells = context.data[0].map((_, col) => [row, col]);
|
|
91
|
+
context.df_actions.set_selected_cells(selected_cells);
|
|
92
|
+
context.df_actions.set_selected(selected_cells[0]);
|
|
93
|
+
context.df_actions.set_editing(false);
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
context.parent_element.focus();
|
|
96
|
+
}, 0);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const selection_context = { ...context, actions };
|
|
100
|
+
setContext(instance_id, selection_context);
|
|
101
|
+
setContext(SELECTION_KEY, { instance_id, context: selection_context });
|
|
102
|
+
return selection_context;
|
|
103
|
+
}
|
|
104
|
+
export function get_selection_context() {
|
|
105
|
+
const ctx = getContext(SELECTION_KEY);
|
|
106
|
+
return ctx ? ctx.context : getContext(SELECTION_KEY);
|
|
107
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { Writable } from "svelte/store";
|
|
2
|
+
import type { DataframeValue } from "../utils";
|
|
3
|
+
export declare const DATAFRAME_KEY: unique symbol;
|
|
4
|
+
export type SortDirection = "asc" | "desc";
|
|
5
|
+
export type DataFrameState = {
|
|
6
|
+
config: {
|
|
7
|
+
show_fullscreen_button: boolean;
|
|
8
|
+
show_copy_button: boolean;
|
|
9
|
+
show_search: "none" | "search" | "filter";
|
|
10
|
+
show_row_numbers: boolean;
|
|
11
|
+
editable: boolean;
|
|
12
|
+
pinned_columns: number;
|
|
13
|
+
show_label: boolean;
|
|
14
|
+
line_breaks: boolean;
|
|
15
|
+
wrap: boolean;
|
|
16
|
+
max_height: number;
|
|
17
|
+
column_widths: string[];
|
|
18
|
+
max_chars: number | undefined;
|
|
19
|
+
};
|
|
20
|
+
current_search_query: string | null;
|
|
21
|
+
sort_state: {
|
|
22
|
+
sort_columns: {
|
|
23
|
+
col: number;
|
|
24
|
+
direction: SortDirection;
|
|
25
|
+
}[];
|
|
26
|
+
row_order: number[];
|
|
27
|
+
};
|
|
28
|
+
ui_state: {
|
|
29
|
+
active_cell_menu: {
|
|
30
|
+
row: number;
|
|
31
|
+
col: number;
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
} | null;
|
|
35
|
+
active_header_menu: {
|
|
36
|
+
col: number;
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
} | null;
|
|
40
|
+
selected_cells: [number, number][];
|
|
41
|
+
selected: [number, number] | false;
|
|
42
|
+
editing: [number, number] | false;
|
|
43
|
+
header_edit: number | false;
|
|
44
|
+
selected_header: number | false;
|
|
45
|
+
active_button: {
|
|
46
|
+
type: "header" | "cell";
|
|
47
|
+
row?: number;
|
|
48
|
+
col: number;
|
|
49
|
+
} | null;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export interface DataFrameContext {
|
|
53
|
+
state: Writable<DataFrameState>;
|
|
54
|
+
actions: {
|
|
55
|
+
handle_search: (search_query: string | null) => void;
|
|
56
|
+
handle_sort: (col: number, direction: SortDirection) => void;
|
|
57
|
+
get_sort_status: (name: string, headers: string[]) => "none" | "asc" | "desc";
|
|
58
|
+
sort_data: (data: any[][], display_value: string[][] | null, styling: string[][] | null) => void;
|
|
59
|
+
update_row_order: (data: any[][]) => void;
|
|
60
|
+
filter_data: (data: any[][]) => any[][];
|
|
61
|
+
add_row: (data: any[][], make_id: () => string, index?: number) => any[][];
|
|
62
|
+
add_col: (data: any[][], headers: string[], make_id: () => string, index?: number) => {
|
|
63
|
+
data: any[][];
|
|
64
|
+
headers: string[];
|
|
65
|
+
};
|
|
66
|
+
add_row_at: (data: any[][], index: number, position: "above" | "below", make_id: () => string) => any[][];
|
|
67
|
+
add_col_at: (data: any[][], headers: string[], index: number, position: "left" | "right", make_id: () => string) => {
|
|
68
|
+
data: any[][];
|
|
69
|
+
headers: string[];
|
|
70
|
+
};
|
|
71
|
+
delete_row: (data: any[][], index: number) => any[][];
|
|
72
|
+
delete_col: (data: any[][], headers: string[], index: number) => {
|
|
73
|
+
data: any[][];
|
|
74
|
+
headers: string[];
|
|
75
|
+
};
|
|
76
|
+
delete_row_at: (data: any[][], index: number) => any[][];
|
|
77
|
+
delete_col_at: (data: any[][], headers: string[], index: number) => {
|
|
78
|
+
data: any[][];
|
|
79
|
+
headers: string[];
|
|
80
|
+
};
|
|
81
|
+
set_active_cell_menu: (menu: {
|
|
82
|
+
row: number;
|
|
83
|
+
col: number;
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
} | null) => void;
|
|
87
|
+
set_active_header_menu: (menu: {
|
|
88
|
+
col: number;
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
} | null) => void;
|
|
92
|
+
set_selected_cells: (cells: [number, number][]) => void;
|
|
93
|
+
set_selected: (selected: [number, number] | false) => void;
|
|
94
|
+
set_editing: (editing: [number, number] | false) => void;
|
|
95
|
+
clear_ui_state: () => void;
|
|
96
|
+
set_header_edit: (header_index: number | false) => void;
|
|
97
|
+
set_selected_header: (header_index: number | false) => void;
|
|
98
|
+
handle_header_click: (col: number, editable: boolean) => void;
|
|
99
|
+
end_header_edit: (key: string) => void;
|
|
100
|
+
trigger_change: (data: any[][], headers: any[], previous_data: string[][], previous_headers: string[], value_is_output: boolean, dispatch: {
|
|
101
|
+
(e: "change", detail: DataframeValue): void;
|
|
102
|
+
(e: "input", detail?: undefined): void;
|
|
103
|
+
(e: "select", detail: any): void;
|
|
104
|
+
(e: "search", detail: string | null): void;
|
|
105
|
+
}) => Promise<void>;
|
|
106
|
+
get_selected_cells: () => [number, number][];
|
|
107
|
+
get_active_cell_menu: () => {
|
|
108
|
+
row: number;
|
|
109
|
+
col: number;
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
} | null;
|
|
113
|
+
get_active_button: () => {
|
|
114
|
+
type: "header" | "cell";
|
|
115
|
+
row?: number;
|
|
116
|
+
col: number;
|
|
117
|
+
} | null;
|
|
118
|
+
set_active_button: (button: {
|
|
119
|
+
type: "header" | "cell";
|
|
120
|
+
row?: number;
|
|
121
|
+
col: number;
|
|
122
|
+
} | null) => void;
|
|
123
|
+
reset_sort_state: () => void;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export declare function create_actions(state: Writable<DataFrameState>): DataFrameContext["actions"];
|
|
127
|
+
export declare function create_dataframe_context(config: {
|
|
128
|
+
show_fullscreen_button: boolean;
|
|
129
|
+
show_copy_button: boolean;
|
|
130
|
+
show_search: "none" | "search" | "filter";
|
|
131
|
+
show_row_numbers: boolean;
|
|
132
|
+
editable: boolean;
|
|
133
|
+
pinned_columns: number;
|
|
134
|
+
show_label: boolean;
|
|
135
|
+
line_breaks: boolean;
|
|
136
|
+
wrap: boolean;
|
|
137
|
+
max_height: number;
|
|
138
|
+
column_widths: string[];
|
|
139
|
+
max_chars: number | undefined;
|
|
140
|
+
}): DataFrameContext;
|
|
141
|
+
export declare function get_dataframe_context(): DataFrameContext;
|