gradio-pr-bot commited on
Commit
6197cac
·
verified ·
1 Parent(s): b1c3489

Upload folder using huggingface_hub

Browse files
Files changed (36) hide show
  1. 6.14.0/dataframe/Example.svelte +118 -0
  2. 6.14.0/dataframe/Index.svelte +128 -0
  3. 6.14.0/dataframe/package.json +52 -0
  4. 6.14.0/dataframe/shared/BooleanCell.svelte +54 -0
  5. 6.14.0/dataframe/shared/CellMenu.svelte +278 -0
  6. 6.14.0/dataframe/shared/CellMenuButton.svelte +46 -0
  7. 6.14.0/dataframe/shared/CellMenuIcons.svelte +240 -0
  8. 6.14.0/dataframe/shared/DataCell.svelte +274 -0
  9. 6.14.0/dataframe/shared/EditableCell.svelte +308 -0
  10. 6.14.0/dataframe/shared/EmptyRowButton.svelte +29 -0
  11. 6.14.0/dataframe/shared/Example.svelte +29 -0
  12. 6.14.0/dataframe/shared/FilterMenu.svelte +255 -0
  13. 6.14.0/dataframe/shared/HeaderCell.svelte +280 -0
  14. 6.14.0/dataframe/shared/RowNumber.svelte +34 -0
  15. 6.14.0/dataframe/shared/Table.svelte +1480 -0
  16. 6.14.0/dataframe/shared/Toolbar.svelte +208 -0
  17. 6.14.0/dataframe/shared/column_measurement.svelte.ts +187 -0
  18. 6.14.0/dataframe/shared/icons/FilterIcon.svelte +20 -0
  19. 6.14.0/dataframe/shared/icons/Padlock.svelte +28 -0
  20. 6.14.0/dataframe/shared/icons/SelectionButtons.svelte +108 -0
  21. 6.14.0/dataframe/shared/icons/SortButtonDown.svelte +25 -0
  22. 6.14.0/dataframe/shared/icons/SortButtonUp.svelte +25 -0
  23. 6.14.0/dataframe/shared/icons/SortIcon.svelte +78 -0
  24. 6.14.0/dataframe/shared/tanstack/index.ts +23 -0
  25. 6.14.0/dataframe/shared/tanstack/table.svelte.ts +117 -0
  26. 6.14.0/dataframe/shared/tanstack/virtual.svelte.ts +105 -0
  27. 6.14.0/dataframe/shared/types.ts +34 -0
  28. 6.14.0/dataframe/shared/utils/filter.ts +66 -0
  29. 6.14.0/dataframe/shared/utils/selection_utils.ts +234 -0
  30. 6.14.0/dataframe/shared/utils/table_utils.ts +95 -0
  31. 6.14.0/dataframe/shared/utils/utils.ts +58 -0
  32. 6.14.0/dataframe/standalone/Index.svelte +741 -0
  33. 6.14.0/dataframe/standalone/default_i18n.ts +32 -0
  34. 6.14.0/dataframe/standalone/stubs/Upload.svelte +19 -0
  35. 6.14.0/dataframe/standalone/stubs/upload.ts +1 -0
  36. 6.14.0/dataframe/types.ts +34 -0
6.14.0/dataframe/Example.svelte ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: (string | number)[][] | string;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ export let index: number;
6
+
7
+ let hovered = false;
8
+ let loaded = Array.isArray(value);
9
+ let is_empty = loaded && (value.length === 0 || value[0].length === 0);
10
+ </script>
11
+
12
+ {#if loaded}
13
+ <!-- TODO: fix-->
14
+ <!-- svelte-ignore a11y-no-static-element-interactions-->
15
+ <div
16
+ class:table={type === "table"}
17
+ class:gallery={type === "gallery"}
18
+ class:selected
19
+ on:mouseenter={() => (hovered = true)}
20
+ on:mouseleave={() => (hovered = false)}
21
+ >
22
+ {#if typeof value === "string"}
23
+ {value}
24
+ {:else if is_empty}
25
+ <table class="">
26
+ <tbody>
27
+ <tr>
28
+ <td>Empty</td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+ {:else}
33
+ <table class="">
34
+ <tbody>
35
+ {#each value.slice(0, 3) as row, i}
36
+ <tr>
37
+ {#each row.slice(0, 3) as cell, j}
38
+ <td>{cell}</td>
39
+ {/each}
40
+ {#if row.length > 3}
41
+ <td>…</td>
42
+ {/if}
43
+ </tr>
44
+ {/each}
45
+ </tbody>
46
+ </table>
47
+ {#if value.length > 3}
48
+ <div
49
+ class="overlay"
50
+ class:odd={index % 2 != 0}
51
+ class:even={index % 2 == 0}
52
+ class:button={type === "gallery"}
53
+ ></div>
54
+ {/if}
55
+ {/if}
56
+ </div>
57
+ {/if}
58
+
59
+ <style>
60
+ table {
61
+ position: relative;
62
+ border-collapse: collapse;
63
+ }
64
+
65
+ td {
66
+ border: 1px solid var(--table-border-color);
67
+ padding: var(--size-2);
68
+ font-size: var(--text-sm);
69
+ font-family: var(--font-mono);
70
+ }
71
+
72
+ .selected td {
73
+ border-color: var(--border-color-accent);
74
+ }
75
+
76
+ .table {
77
+ display: inline-block;
78
+ margin: 0 auto;
79
+ }
80
+
81
+ .gallery td:first-child {
82
+ border-left: none;
83
+ }
84
+
85
+ .gallery tr:first-child td {
86
+ border-top: none;
87
+ }
88
+
89
+ .gallery td:last-child {
90
+ border-right: none;
91
+ }
92
+
93
+ .gallery tr:last-child td {
94
+ border-bottom: none;
95
+ }
96
+
97
+ .overlay {
98
+ --gradient-to: transparent;
99
+ position: absolute;
100
+ bottom: 0;
101
+ background: linear-gradient(to bottom, transparent, var(--gradient-to));
102
+ width: var(--size-full);
103
+ height: 50%;
104
+ }
105
+
106
+ /* i dont know what i've done here but it is what it is */
107
+ .odd {
108
+ --gradient-to: var(--table-even-background-fill);
109
+ }
110
+
111
+ .even {
112
+ --gradient-to: var(--table-odd-background-fill);
113
+ }
114
+
115
+ .button {
116
+ --gradient-to: var(--background-fill-primary);
117
+ }
118
+ </style>
6.14.0/dataframe/Index.svelte ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script module lang="ts">
2
+ export { default as BaseDataFrame } from "./shared/Table.svelte";
3
+ export { default as BaseExample } from "./Example.svelte";
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import { tick } from "svelte";
8
+ import Table from "./shared/Table.svelte";
9
+ import StatusTracker from "@gradio/statustracker";
10
+ import { Block } from "@gradio/atoms";
11
+ import { Gradio } from "@gradio/utils";
12
+ import type { DataframeProps, DataframeEvents } from "./types";
13
+ import { dequal } from "dequal";
14
+
15
+ let _props = $props();
16
+ const gradio = new Gradio<DataframeEvents, DataframeProps>(_props);
17
+
18
+ let fullscreen = $state(gradio.props.fullscreen ?? false);
19
+
20
+ // align datatype array to current value headers using the original
21
+ // config-time header→datatype mapping.
22
+ // when columns are hidden or reordered, positional indices shift but
23
+ // the datatype prop doesn't update, the map keeps them synced
24
+ let aligned_datatype = $derived.by(() => {
25
+ const dt = gradio.props.datatype;
26
+ if (!Array.isArray(dt)) return dt;
27
+
28
+ const config_headers: string[] | undefined = (gradio.props as any).headers;
29
+ const current_headers = gradio.props.value?.headers;
30
+ if (!config_headers || !current_headers) return dt;
31
+
32
+ const map = new Map<string, string>();
33
+ for (let i = 0; i < Math.min(config_headers.length, dt.length); i++) {
34
+ map.set(config_headers[i], dt[i]);
35
+ }
36
+ return current_headers.map(
37
+ (h: string, i: number) => map.get(h) ?? dt[i] ?? "str"
38
+ );
39
+ });
40
+
41
+ let old_value = $state(
42
+ gradio.props.value ? JSON.stringify(gradio.props.value) : null
43
+ );
44
+
45
+ function handle_change(detail: any): void {
46
+ gradio.props.value = detail;
47
+ const serialized = JSON.stringify(detail);
48
+ if (serialized !== old_value) {
49
+ old_value = serialized;
50
+ gradio.dispatch("change", detail);
51
+ }
52
+ }
53
+
54
+ function handle_input(): void {
55
+ gradio.dispatch("input");
56
+ }
57
+
58
+ function handle_select(detail: any): void {
59
+ gradio.dispatch("select", detail);
60
+ }
61
+
62
+ function handle_edit(detail: any): void {
63
+ gradio.dispatch("edit", detail);
64
+ }
65
+
66
+ $effect(() => {
67
+ const v = gradio.props.value;
68
+ if (v) {
69
+ const serialized = JSON.stringify(v);
70
+ if (serialized !== old_value) {
71
+ old_value = serialized;
72
+ gradio.dispatch("change", v);
73
+ }
74
+ }
75
+ });
76
+ </script>
77
+
78
+ <Block
79
+ visible={gradio.shared.visible}
80
+ elem_id={gradio.shared.elem_id}
81
+ elem_classes={gradio.shared.elem_classes}
82
+ scale={gradio.shared.scale}
83
+ min_width={gradio.shared.min_width}
84
+ padding={false}
85
+ container={false}
86
+ {fullscreen}
87
+ >
88
+ <StatusTracker
89
+ autoscroll={gradio.shared.autoscroll}
90
+ i18n={gradio.i18n}
91
+ {...gradio.shared.loading_status}
92
+ />
93
+ <Table
94
+ headers={gradio.props.value?.headers ?? []}
95
+ values={gradio.props.value?.data ?? []}
96
+ display_value={gradio.props.value?.metadata?.display_value ?? null}
97
+ styling={gradio.props.value?.metadata?.styling ?? null}
98
+ col_count={gradio.props.col_count}
99
+ row_count={gradio.props.row_count}
100
+ label={gradio.shared.label}
101
+ show_label={gradio.shared.show_label}
102
+ wrap={gradio.props.wrap}
103
+ datatype={aligned_datatype}
104
+ latex_delimiters={gradio.props.latex_delimiters}
105
+ max_height={gradio.props.max_height}
106
+ editable={gradio.shared.interactive ?? true}
107
+ line_breaks={gradio.props.line_breaks}
108
+ column_widths={gradio.props.column_widths ?? []}
109
+ root={gradio.shared.root}
110
+ i18n={gradio.i18n}
111
+ upload={gradio.shared.client?.upload}
112
+ stream_handler={gradio.shared.client?.stream}
113
+ buttons={gradio.props.buttons}
114
+ max_chars={gradio.props.max_chars}
115
+ show_row_numbers={gradio.props.show_row_numbers}
116
+ show_search={gradio.props.show_search}
117
+ pinned_columns={gradio.props.pinned_columns}
118
+ static_columns={gradio.props.static_columns ?? []}
119
+ {fullscreen}
120
+ onfullscreen={() => {
121
+ fullscreen = !fullscreen;
122
+ }}
123
+ onchange={handle_change}
124
+ oninput={handle_input}
125
+ onselect={handle_select}
126
+ onedit={handle_edit}
127
+ />
128
+ </Block>
6.14.0/dataframe/package.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/dataframe",
3
+ "version": "0.23.2",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "./Index.svelte",
11
+ "dependencies": {
12
+ "@gradio/atoms": "workspace:^",
13
+ "@gradio/button": "workspace:^",
14
+ "@gradio/checkbox": "workspace:^",
15
+ "@gradio/client": "workspace:^",
16
+ "@gradio/icons": "workspace:^",
17
+ "@gradio/markdown-code": "workspace:^",
18
+ "@gradio/statustracker": "workspace:^",
19
+ "@gradio/upload": "workspace:^",
20
+ "@gradio/utils": "workspace:^",
21
+ "@types/d3-dsv": "^3.0.7",
22
+ "@types/katex": "^0.16.7",
23
+ "d3-dsv": "^3.0.1",
24
+ "dequal": "^2.0.3",
25
+ "@tanstack/table-core": "^8.21.3",
26
+ "@tanstack/virtual-core": "^3.13.6"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "gradio": "./Index.svelte",
31
+ "svelte": "./dist/standalone/Index.svelte",
32
+ "types": "./dist/standalone/Index.svelte.d.ts"
33
+ },
34
+ "./example": {
35
+ "gradio": "./Example.svelte",
36
+ "svelte": "./dist/Example.svelte",
37
+ "types": "./dist/Example.svelte.d.ts"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "peerDependencies": {
42
+ "svelte": ">=5.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@gradio/preview": "workspace:^"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/gradio-app/gradio.git",
50
+ "directory": "js/dataframe"
51
+ }
52
+ }
6.14.0/dataframe/shared/BooleanCell.svelte ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { BaseCheckbox } from "@gradio/checkbox";
3
+
4
+ let {
5
+ value = $bindable(false),
6
+ editable = true,
7
+ on_change
8
+ }: {
9
+ value?: boolean;
10
+ editable?: boolean;
11
+ on_change: (value: boolean) => void;
12
+ } = $props();
13
+
14
+ function handle_change(val: boolean): void {
15
+ if (editable) {
16
+ on_change(val);
17
+ }
18
+ }
19
+ </script>
20
+
21
+ <div class="bool-cell" role="button" tabindex="-1">
22
+ <BaseCheckbox
23
+ bind:value
24
+ label=""
25
+ interactive={editable}
26
+ on_change={handle_change}
27
+ />
28
+ </div>
29
+
30
+ <style>
31
+ .bool-cell {
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ width: min-content;
36
+ height: var(--size-full);
37
+ }
38
+
39
+ .bool-cell :global(input:disabled) {
40
+ cursor: not-allowed;
41
+ }
42
+
43
+ .bool-cell :global(label) {
44
+ margin: 0;
45
+ width: 100%;
46
+ display: flex;
47
+ justify-content: center;
48
+ align-items: center;
49
+ }
50
+
51
+ .bool-cell :global(span) {
52
+ display: none;
53
+ }
54
+ </style>
6.14.0/dataframe/shared/CellMenu.svelte ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import CellMenuIcons from "./CellMenuIcons.svelte";
4
+ import FilterMenu from "./FilterMenu.svelte";
5
+ import type { I18nFormatter } from "@gradio/utils";
6
+ import type { SortDirection, FilterDatatype } from "./types";
7
+
8
+ let {
9
+ x,
10
+ y,
11
+ on_add_row_above,
12
+ on_add_row_below,
13
+ on_add_column_left,
14
+ on_add_column_right,
15
+ row,
16
+ col_count,
17
+ row_count,
18
+ on_delete_row,
19
+ on_delete_col,
20
+ can_delete_rows,
21
+ can_delete_cols,
22
+ on_sort = () => {},
23
+ on_clear_sort = () => {},
24
+ sort_direction = null,
25
+ sort_priority = null,
26
+ on_filter = () => {},
27
+ on_clear_filter = () => {},
28
+ filter_active = null,
29
+ editable = true,
30
+ i18n
31
+ }: {
32
+ x: number;
33
+ y: number;
34
+ on_add_row_above: () => void;
35
+ on_add_row_below: () => void;
36
+ on_add_column_left: () => void;
37
+ on_add_column_right: () => void;
38
+ row: number;
39
+ col_count: [number, "fixed" | "dynamic"];
40
+ row_count: [number, "fixed" | "dynamic"];
41
+ on_delete_row: () => void;
42
+ on_delete_col: () => void;
43
+ can_delete_rows: boolean;
44
+ can_delete_cols: boolean;
45
+ on_sort?: (direction: SortDirection) => void;
46
+ on_clear_sort?: () => void;
47
+ sort_direction?: SortDirection | null;
48
+ sort_priority?: number | null;
49
+ on_filter?: (
50
+ datatype: FilterDatatype,
51
+ selected_filter: string,
52
+ value: string
53
+ ) => void;
54
+ on_clear_filter?: () => void;
55
+ filter_active?: boolean | null;
56
+ editable?: boolean;
57
+ i18n: I18nFormatter;
58
+ } = $props();
59
+
60
+ let menu_element: HTMLDivElement;
61
+ let active_filter_menu: { x: number; y: number } | null = $state(null);
62
+
63
+ let is_header = $derived(row === -1);
64
+ let can_add_rows = $derived(editable && row_count[1] === "dynamic");
65
+ let can_add_columns = $derived(editable && col_count[1] === "dynamic");
66
+
67
+ onMount(() => {
68
+ position_menu();
69
+ });
70
+
71
+ function position_menu(): void {
72
+ if (!menu_element) return;
73
+
74
+ const viewport_width = window.innerWidth;
75
+ const viewport_height = window.innerHeight;
76
+ const menu_rect = menu_element.getBoundingClientRect();
77
+
78
+ let new_x = x - 30;
79
+ let new_y = y - 20;
80
+
81
+ if (new_x + menu_rect.width > viewport_width) {
82
+ new_x = x - menu_rect.width + 10;
83
+ }
84
+
85
+ if (new_y + menu_rect.height > viewport_height) {
86
+ new_y = y - menu_rect.height + 10;
87
+ }
88
+
89
+ menu_element.style.left = `${new_x}px`;
90
+ menu_element.style.top = `${new_y}px`;
91
+ }
92
+
93
+ function toggle_filter_menu(): void {
94
+ if (filter_active) {
95
+ on_filter("string", "", "");
96
+ return;
97
+ }
98
+
99
+ const menu_rect = menu_element.getBoundingClientRect();
100
+ active_filter_menu = {
101
+ x: menu_rect.right,
102
+ y: menu_rect.top + menu_rect.height / 2
103
+ };
104
+ }
105
+ </script>
106
+
107
+ <div bind:this={menu_element} class="cell-menu" role="menu">
108
+ {#if is_header}
109
+ <button
110
+ role="menuitem"
111
+ onclick={() => on_sort("asc")}
112
+ class:active={sort_direction === "asc"}
113
+ >
114
+ <CellMenuIcons icon="sort-asc" />
115
+ {i18n("dataframe.sort_ascending")}
116
+ {#if sort_direction === "asc" && sort_priority !== null}
117
+ <span class="priority">{sort_priority}</span>
118
+ {/if}
119
+ </button>
120
+ <button
121
+ role="menuitem"
122
+ onclick={() => on_sort("desc")}
123
+ class:active={sort_direction === "desc"}
124
+ >
125
+ <CellMenuIcons icon="sort-desc" />
126
+ {i18n("dataframe.sort_descending")}
127
+ {#if sort_direction === "desc" && sort_priority !== null}
128
+ <span class="priority">{sort_priority}</span>
129
+ {/if}
130
+ </button>
131
+ <button role="menuitem" onclick={on_clear_sort}>
132
+ <CellMenuIcons icon="clear-sort" />
133
+ {i18n("dataframe.clear_sort")}
134
+ </button>
135
+ <button
136
+ role="menuitem"
137
+ onclick={(e) => {
138
+ e.stopPropagation();
139
+ toggle_filter_menu();
140
+ }}
141
+ class:active={filter_active || active_filter_menu}
142
+ >
143
+ <CellMenuIcons icon="filter" />
144
+ {i18n("dataframe.filter")}
145
+ {#if filter_active}
146
+ <span class="priority">1</span>
147
+ {/if}
148
+ </button>
149
+ <button role="menuitem" onclick={on_clear_filter}>
150
+ <CellMenuIcons icon="clear-filter" />
151
+ {i18n("dataframe.clear_filter")}
152
+ </button>
153
+ {/if}
154
+
155
+ {#if !is_header && can_add_rows}
156
+ <button
157
+ role="menuitem"
158
+ onclick={() => on_add_row_above()}
159
+ aria-label="Add row above"
160
+ >
161
+ <CellMenuIcons icon="add-row-above" />
162
+ {i18n("dataframe.add_row_above")}
163
+ </button>
164
+ <button
165
+ role="menuitem"
166
+ onclick={() => on_add_row_below()}
167
+ aria-label="Add row below"
168
+ >
169
+ <CellMenuIcons icon="add-row-below" />
170
+ {i18n("dataframe.add_row_below")}
171
+ </button>
172
+ {#if can_delete_rows}
173
+ <button
174
+ role="menuitem"
175
+ onclick={on_delete_row}
176
+ class="delete"
177
+ aria-label="Delete row"
178
+ >
179
+ <CellMenuIcons icon="delete-row" />
180
+ {i18n("dataframe.delete_row")}
181
+ </button>
182
+ {/if}
183
+ {/if}
184
+ {#if can_add_columns}
185
+ <button
186
+ role="menuitem"
187
+ onclick={() => on_add_column_left()}
188
+ aria-label="Add column to the left"
189
+ >
190
+ <CellMenuIcons icon="add-column-left" />
191
+ {i18n("dataframe.add_column_left")}
192
+ </button>
193
+ <button
194
+ role="menuitem"
195
+ onclick={() => on_add_column_right()}
196
+ aria-label="Add column to the right"
197
+ >
198
+ <CellMenuIcons icon="add-column-right" />
199
+ {i18n("dataframe.add_column_right")}
200
+ </button>
201
+ {#if can_delete_cols}
202
+ <button
203
+ role="menuitem"
204
+ onclick={on_delete_col}
205
+ class="delete"
206
+ aria-label="Delete column"
207
+ >
208
+ <CellMenuIcons icon="delete-column" />
209
+ {i18n("dataframe.delete_column")}
210
+ </button>
211
+ {/if}
212
+ {/if}
213
+ </div>
214
+
215
+ {#if active_filter_menu}
216
+ <FilterMenu {on_filter} />
217
+ {/if}
218
+
219
+ <style>
220
+ .cell-menu {
221
+ position: fixed;
222
+ z-index: var(--layer-1);
223
+ background: var(--background-fill-primary);
224
+ border: 1px solid var(--border-color-primary);
225
+ border-radius: var(--radius-sm);
226
+ padding: var(--size-1);
227
+ display: flex;
228
+ flex-direction: column;
229
+ gap: var(--size-1);
230
+ box-shadow: var(--shadow-drop-lg);
231
+ min-width: 150px;
232
+ width: max-content;
233
+ }
234
+
235
+ .cell-menu button {
236
+ background: none;
237
+ border: none;
238
+ cursor: pointer;
239
+ text-align: left;
240
+ padding: var(--size-1) var(--size-2);
241
+ border-radius: var(--radius-sm);
242
+ color: var(--body-text-color);
243
+ font-size: var(--text-sm);
244
+ transition:
245
+ background-color 0.2s,
246
+ color 0.2s;
247
+ display: flex;
248
+ align-items: center;
249
+ gap: var(--size-2);
250
+ position: relative;
251
+ }
252
+
253
+ .cell-menu button.active {
254
+ background-color: var(--background-fill-secondary);
255
+ }
256
+
257
+ .cell-menu button:hover {
258
+ background-color: var(--background-fill-secondary);
259
+ }
260
+
261
+ .cell-menu button :global(svg) {
262
+ fill: currentColor;
263
+ transition: fill 0.2s;
264
+ }
265
+
266
+ .priority {
267
+ display: flex;
268
+ align-items: center;
269
+ justify-content: center;
270
+ margin-left: auto;
271
+ font-size: var(--size-2);
272
+ background-color: var(--button-secondary-background-fill);
273
+ color: var(--body-text-color);
274
+ border-radius: var(--radius-sm);
275
+ width: var(--size-2-5);
276
+ height: var(--size-2-5);
277
+ }
278
+ </style>
6.14.0/dataframe/shared/CellMenuButton.svelte ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { on_click }: { on_click: (event: MouseEvent) => void } = $props();
3
+ </script>
4
+
5
+ <button
6
+ aria-label="Open cell menu"
7
+ class="cell-menu-button"
8
+ aria-haspopup="menu"
9
+ onclick={on_click}
10
+ ontouchstart={(event) => {
11
+ event.preventDefault();
12
+ const touch = event.touches[0];
13
+ const mouseEvent = new MouseEvent("click", {
14
+ clientX: touch.clientX,
15
+ clientY: touch.clientY,
16
+ bubbles: true,
17
+ cancelable: true,
18
+ view: window
19
+ });
20
+ on_click(mouseEvent);
21
+ }}
22
+ >
23
+ &#8942;
24
+ </button>
25
+
26
+ <style>
27
+ .cell-menu-button {
28
+ flex-shrink: 0;
29
+ display: none;
30
+ align-items: center;
31
+ justify-content: center;
32
+ background-color: var(--block-background-fill);
33
+ border: 1px solid var(--border-color-primary);
34
+ border-radius: var(--block-radius);
35
+ width: var(--size-5);
36
+ height: var(--size-5);
37
+ min-width: var(--size-5);
38
+ padding: 0;
39
+ margin-right: var(--spacing-sm);
40
+ z-index: 2;
41
+ position: absolute;
42
+ right: var(--size-1);
43
+ top: 50%;
44
+ transform: translateY(-50%);
45
+ }
46
+ </style>
6.14.0/dataframe/shared/CellMenuIcons.svelte ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { icon }: { icon: string } = $props();
3
+ </script>
4
+
5
+ {#if icon == "add-column-right"}
6
+ <svg viewBox="0 0 24 24" width="16" height="16">
7
+ <rect
8
+ x="4"
9
+ y="6"
10
+ width="4"
11
+ height="12"
12
+ stroke="currentColor"
13
+ stroke-width="2"
14
+ fill="none"
15
+ />
16
+ <path
17
+ d="M12 12H19M16 8L19 12L16 16"
18
+ stroke="currentColor"
19
+ stroke-width="2"
20
+ fill="none"
21
+ stroke-linecap="round"
22
+ />
23
+ </svg>
24
+ {:else if icon == "add-column-left"}
25
+ <svg viewBox="0 0 24 24" width="16" height="16">
26
+ <rect
27
+ x="16"
28
+ y="6"
29
+ width="4"
30
+ height="12"
31
+ stroke="currentColor"
32
+ stroke-width="2"
33
+ fill="none"
34
+ />
35
+ <path
36
+ d="M12 12H5M8 8L5 12L8 16"
37
+ stroke="currentColor"
38
+ stroke-width="2"
39
+ fill="none"
40
+ stroke-linecap="round"
41
+ />
42
+ </svg>
43
+ {:else if icon == "add-row-above"}
44
+ <svg viewBox="0 0 24 24" width="16" height="16">
45
+ <rect
46
+ x="6"
47
+ y="16"
48
+ width="12"
49
+ height="4"
50
+ stroke="currentColor"
51
+ stroke-width="2"
52
+ />
53
+ <path
54
+ d="M12 12V5M8 8L12 5L16 8"
55
+ stroke="currentColor"
56
+ stroke-width="2"
57
+ fill="none"
58
+ stroke-linecap="round"
59
+ />
60
+ </svg>
61
+ {:else if icon == "add-row-below"}
62
+ <svg viewBox="0 0 24 24" width="16" height="16">
63
+ <rect
64
+ x="6"
65
+ y="4"
66
+ width="12"
67
+ height="4"
68
+ stroke="currentColor"
69
+ stroke-width="2"
70
+ />
71
+ <path
72
+ d="M12 12V19M8 16L12 19L16 16"
73
+ stroke="currentColor"
74
+ stroke-width="2"
75
+ fill="none"
76
+ stroke-linecap="round"
77
+ />
78
+ </svg>
79
+ {:else if icon == "delete-row"}
80
+ <svg viewBox="0 0 24 24" width="16" height="16">
81
+ <rect
82
+ x="5"
83
+ y="10"
84
+ width="14"
85
+ height="4"
86
+ stroke="currentColor"
87
+ stroke-width="2"
88
+ />
89
+ <path
90
+ d="M8 7L16 17M16 7L8 17"
91
+ stroke="currentColor"
92
+ stroke-width="2"
93
+ stroke-linecap="round"
94
+ />
95
+ </svg>
96
+ {:else if icon == "delete-column"}
97
+ <svg viewBox="0 0 24 24" width="16" height="16">
98
+ <rect
99
+ x="10"
100
+ y="5"
101
+ width="4"
102
+ height="14"
103
+ stroke="currentColor"
104
+ stroke-width="2"
105
+ />
106
+ <path
107
+ d="M7 8L17 16M17 8L7 16"
108
+ stroke="currentColor"
109
+ stroke-width="2"
110
+ stroke-linecap="round"
111
+ />
112
+ </svg>
113
+ {:else if icon == "sort-asc"}
114
+ <svg viewBox="0 0 24 24" width="16" height="16">
115
+ <path
116
+ d="M8 16L12 12L16 16"
117
+ stroke="currentColor"
118
+ stroke-width="2"
119
+ fill="none"
120
+ stroke-linecap="round"
121
+ stroke-linejoin="round"
122
+ />
123
+ <path
124
+ d="M12 12V19"
125
+ stroke="currentColor"
126
+ stroke-width="2"
127
+ stroke-linecap="round"
128
+ />
129
+ <path
130
+ d="M5 7H19"
131
+ stroke="currentColor"
132
+ stroke-width="2"
133
+ stroke-linecap="round"
134
+ />
135
+ </svg>
136
+ {:else if icon == "sort-desc"}
137
+ <svg viewBox="0 0 24 24" width="16" height="16">
138
+ <path
139
+ d="M8 12L12 16L16 12"
140
+ stroke="currentColor"
141
+ stroke-width="2"
142
+ fill="none"
143
+ stroke-linecap="round"
144
+ stroke-linejoin="round"
145
+ />
146
+ <path
147
+ d="M12 16V9"
148
+ stroke="currentColor"
149
+ stroke-width="2"
150
+ stroke-linecap="round"
151
+ />
152
+ <path
153
+ d="M5 5H19"
154
+ stroke="currentColor"
155
+ stroke-width="2"
156
+ stroke-linecap="round"
157
+ />
158
+ </svg>
159
+ {:else if icon == "clear-sort"}
160
+ <svg viewBox="0 0 24 24" width="16" height="16">
161
+ <path
162
+ d="M5 5H19"
163
+ stroke="currentColor"
164
+ stroke-width="2"
165
+ stroke-linecap="round"
166
+ />
167
+ <path
168
+ d="M5 9H15"
169
+ stroke="currentColor"
170
+ stroke-width="2"
171
+ stroke-linecap="round"
172
+ />
173
+ <path
174
+ d="M5 13H11"
175
+ stroke="currentColor"
176
+ stroke-width="2"
177
+ stroke-linecap="round"
178
+ />
179
+ <path
180
+ d="M5 17H7"
181
+ stroke="currentColor"
182
+ stroke-width="2"
183
+ stroke-linecap="round"
184
+ />
185
+ <path
186
+ d="M17 17L21 21M21 17L17 21"
187
+ stroke="currentColor"
188
+ stroke-width="2"
189
+ stroke-linecap="round"
190
+ />
191
+ </svg>
192
+ {:else if icon == "filter"}
193
+ <svg viewBox="0 0 24 24" width="16" height="16">
194
+ <path
195
+ d="M5 5H19"
196
+ stroke="currentColor"
197
+ stroke-width="2"
198
+ stroke-linecap="round"
199
+ />
200
+ <path
201
+ d="M8 9H16"
202
+ stroke="currentColor"
203
+ stroke-width="2"
204
+ stroke-linecap="round"
205
+ />
206
+ <path
207
+ d="M11 13H13"
208
+ stroke="currentColor"
209
+ stroke-width="2"
210
+ stroke-linecap="round"
211
+ />
212
+ </svg>
213
+ {:else if icon == "clear-filter"}
214
+ <svg viewBox="0 0 24 24" width="16" height="16">
215
+ <path
216
+ d="M5 5H19"
217
+ stroke="currentColor"
218
+ stroke-width="2"
219
+ stroke-linecap="round"
220
+ />
221
+ <path
222
+ d="M8 9H16"
223
+ stroke="currentColor"
224
+ stroke-width="2"
225
+ stroke-linecap="round"
226
+ />
227
+ <path
228
+ d="M11 13H13"
229
+ stroke="currentColor"
230
+ stroke-width="2"
231
+ stroke-linecap="round"
232
+ />
233
+ <path
234
+ d="M17 17L21 21M21 17L17 21"
235
+ stroke="currentColor"
236
+ stroke-width="2"
237
+ stroke-linecap="round"
238
+ />
239
+ </svg>
240
+ {/if}
6.14.0/dataframe/shared/DataCell.svelte ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import EditableCell from "./EditableCell.svelte";
3
+ import CellMenuButton from "./CellMenuButton.svelte";
4
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
5
+ import type { CellValue } from "./types";
6
+ import type { Datatype } from "./utils/utils";
7
+
8
+ let {
9
+ value,
10
+ display_value = null,
11
+ datatype = "str",
12
+ row_idx,
13
+ col_idx,
14
+ col_style = "",
15
+ cell_style = "",
16
+ selection_classes = "",
17
+ is_editing = false,
18
+ is_flash = false,
19
+ is_static = false,
20
+ show_menu_button = false,
21
+ show_selection_buttons = false,
22
+ is_first_column = false,
23
+ is_solo = false,
24
+ latex_delimiters,
25
+ line_breaks = true,
26
+ editable = true,
27
+ max_chars = undefined,
28
+ i18n,
29
+ components = {},
30
+ is_dragging = false,
31
+ wrap_text = false,
32
+ onmousedown,
33
+ ondblclick,
34
+ oncontextmenu,
35
+ onblur,
36
+ on_menu_click,
37
+ on_select_column,
38
+ on_select_row
39
+ }: {
40
+ value: CellValue;
41
+ display_value?: string | null;
42
+ datatype?: Datatype;
43
+ row_idx: number;
44
+ col_idx: number;
45
+ col_style?: string;
46
+ cell_style?: string;
47
+ selection_classes?: string;
48
+ is_editing?: boolean;
49
+ is_flash?: boolean;
50
+ is_static?: boolean;
51
+ show_menu_button?: boolean;
52
+ show_selection_buttons?: boolean;
53
+ is_first_column?: boolean;
54
+ is_solo?: boolean;
55
+ latex_delimiters: { left: string; right: string; display: boolean }[];
56
+ line_breaks?: boolean;
57
+ editable?: boolean;
58
+ max_chars?: number | undefined;
59
+ i18n: I18nFormatter;
60
+ components?: Record<string, any>;
61
+ is_dragging?: boolean;
62
+ wrap_text?: boolean;
63
+ onmousedown: (event: MouseEvent) => void;
64
+ ondblclick: (event: MouseEvent) => void;
65
+ oncontextmenu: (event: MouseEvent) => void;
66
+ onblur: (detail: {
67
+ blur_event: FocusEvent;
68
+ coords: [number, number];
69
+ }) => void;
70
+ on_menu_click: (event: MouseEvent) => void;
71
+ on_select_column: (col: number) => void;
72
+ on_select_row: (row: number) => void;
73
+ } = $props();
74
+
75
+ let is_selected = $derived(selection_classes !== "");
76
+
77
+ // lock the cell-wrap's height to its pre-selection value so the
78
+ // row doesn't shift when the span goes position: absolute.
79
+ let wrap_el: HTMLDivElement | undefined = $state();
80
+ let locked_height = $state("");
81
+
82
+ // pre is weird but runs _before_ DOM updates
83
+ $effect.pre(() => {
84
+ if (is_solo && wrap_el) {
85
+ locked_height = `height: ${wrap_el.offsetHeight}px;`;
86
+ } else {
87
+ locked_height = "";
88
+ }
89
+ });
90
+ </script>
91
+
92
+ <div
93
+ class="body-cell {selection_classes}"
94
+ class:flash={is_flash}
95
+ class:first-column={is_first_column}
96
+ class:static={is_static}
97
+ class:cell-solo={is_solo}
98
+ data-row={row_idx}
99
+ data-col={col_idx}
100
+ data-testid={`cell-${row_idx}-${col_idx}`}
101
+ tabindex={is_static ? -1 : undefined}
102
+ {onmousedown}
103
+ {ondblclick}
104
+ {oncontextmenu}
105
+ style="{col_style} {cell_style}"
106
+ >
107
+ <div class="cell-wrap" bind:this={wrap_el} style={locked_height}>
108
+ <EditableCell
109
+ {value}
110
+ {display_value}
111
+ {latex_delimiters}
112
+ {line_breaks}
113
+ {editable}
114
+ {is_static}
115
+ edit={is_editing}
116
+ {datatype}
117
+ {onblur}
118
+ {max_chars}
119
+ {i18n}
120
+ {components}
121
+ {show_selection_buttons}
122
+ coords={[row_idx, col_idx]}
123
+ {on_select_column}
124
+ {on_select_row}
125
+ {is_dragging}
126
+ {wrap_text}
127
+ expanded={is_solo}
128
+ />
129
+ {#if show_menu_button}
130
+ <CellMenuButton on_click={on_menu_click} />
131
+ {/if}
132
+ </div>
133
+ </div>
134
+
135
+ <style>
136
+ .body-cell {
137
+ --ring-color: transparent;
138
+ outline: none;
139
+ box-shadow:
140
+ inset 1px 0 0 var(--border-color-primary),
141
+ inset 0 0 0 1px var(--ring-color);
142
+ padding: 0;
143
+ overflow: hidden;
144
+ box-sizing: border-box;
145
+ user-select: none;
146
+ min-width: 0;
147
+ }
148
+
149
+ .body-cell.static {
150
+ user-select: text;
151
+ }
152
+
153
+ .body-cell.first-column {
154
+ box-shadow: inset 0 0 0 1px var(--ring-color);
155
+ }
156
+
157
+ .body-cell:hover :global(.cell-menu-button),
158
+ .body-cell.cell-selected :global(.cell-menu-button) {
159
+ display: flex;
160
+ }
161
+
162
+ .body-cell.cell-selected {
163
+ --ring-color: var(--color-accent);
164
+ --sel-top: inset 0 2px 0 0 var(--ring-color);
165
+ --sel-bottom: inset 0 -2px 0 0 var(--ring-color);
166
+ --sel-left: inset 2px 0 0 0 var(--ring-color);
167
+ --sel-right: inset -2px 0 0 0 var(--ring-color);
168
+ box-shadow:
169
+ var(--sel-top), var(--sel-bottom), var(--sel-left), var(--sel-right);
170
+ z-index: 2;
171
+ position: relative;
172
+ }
173
+
174
+ .body-cell.cell-solo {
175
+ z-index: 10;
176
+ overflow: visible;
177
+ }
178
+
179
+ .body-cell.cell-solo .cell-wrap {
180
+ overflow: visible;
181
+ }
182
+
183
+ .body-cell.cell-solo :global(.cell-wrap > span) {
184
+ position: absolute;
185
+ top: 0;
186
+ left: 0;
187
+ width: 100%;
188
+ min-height: 100%;
189
+ padding: var(--size-2);
190
+ box-sizing: border-box;
191
+ white-space: normal;
192
+ overflow: visible;
193
+ text-overflow: clip;
194
+ overflow-wrap: break-word;
195
+ word-break: break-word;
196
+ background: var(--background-fill-primary);
197
+ box-shadow:
198
+ inset 0 2px 0 0 var(--color-accent),
199
+ inset 0 -2px 0 0 var(--color-accent),
200
+ inset 2px 0 0 0 var(--color-accent),
201
+ inset -2px 0 0 0 var(--color-accent),
202
+ 0 6px 12px -4px rgba(0, 0, 0, 0.22);
203
+ z-index: 1;
204
+ }
205
+
206
+ .body-cell.cell-solo :global(.cell-wrap > textarea) {
207
+ position: absolute;
208
+ top: 0;
209
+ left: 0;
210
+ width: 100%;
211
+ min-height: 100%;
212
+ padding: var(--size-2);
213
+ padding-left: var(--size-2);
214
+ margin: 0;
215
+ box-sizing: border-box;
216
+ transform: none;
217
+ background: var(--background-fill-primary);
218
+ box-shadow:
219
+ inset 0 2px 0 0 var(--color-accent),
220
+ inset 0 -2px 0 0 var(--color-accent),
221
+ inset 2px 0 0 0 var(--color-accent),
222
+ inset -2px 0 0 0 var(--color-accent),
223
+ 0 6px 12px -4px rgba(0, 0, 0, 0.22);
224
+ z-index: 2;
225
+ field-sizing: content;
226
+ height: auto;
227
+ }
228
+
229
+ .body-cell.cell-solo :global(.selection-button) {
230
+ z-index: 3;
231
+ }
232
+
233
+ .body-cell.cell-selected.no-top {
234
+ --sel-top: inset 0 0 0 0 transparent;
235
+ }
236
+ .body-cell.cell-selected.no-bottom {
237
+ --sel-bottom: inset 0 0 0 0 transparent;
238
+ }
239
+ .body-cell.cell-selected.no-left {
240
+ --sel-left: inset 0 0 0 0 transparent;
241
+ }
242
+ .body-cell.cell-selected.no-right {
243
+ --sel-right: inset 0 0 0 0 transparent;
244
+ }
245
+
246
+ .body-cell.flash.cell-selected {
247
+ animation: flash-color 700ms ease-out;
248
+ }
249
+
250
+ @keyframes flash-color {
251
+ 0%,
252
+ 30% {
253
+ background: var(--color-accent-copied);
254
+ }
255
+ 100% {
256
+ background: transparent;
257
+ }
258
+ }
259
+
260
+ .cell-wrap {
261
+ display: flex;
262
+ align-items: center;
263
+ justify-content: flex-start;
264
+ outline: none;
265
+ min-height: var(--size-9);
266
+ position: relative;
267
+ padding: var(--size-2);
268
+ box-sizing: border-box;
269
+ gap: var(--size-1);
270
+ overflow: hidden;
271
+ min-width: 0;
272
+ height: 100%;
273
+ }
274
+ </style>
6.14.0/dataframe/shared/EditableCell.svelte ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { MarkdownCode } from "@gradio/markdown-code";
3
+ import type { I18nFormatter } from "@gradio/utils";
4
+ import type { CellValue } from "./types";
5
+ import SelectionButtons from "./icons/SelectionButtons.svelte";
6
+ import BooleanCell from "./BooleanCell.svelte";
7
+
8
+ let {
9
+ edit,
10
+ value = $bindable(""),
11
+ display_value = null,
12
+ styling = "",
13
+ header = false,
14
+ datatype = "str",
15
+ latex_delimiters,
16
+ line_breaks = true,
17
+ editable = true,
18
+ is_static = false,
19
+ max_chars = null,
20
+ components = {},
21
+ i18n,
22
+ is_dragging = false,
23
+ wrap_text = false,
24
+ expanded = false,
25
+ show_selection_buttons = false,
26
+ coords,
27
+ on_select_column = null,
28
+ on_select_row = null,
29
+ el = $bindable(null),
30
+ onblur,
31
+ onkeydown,
32
+ pad_left = false
33
+ }: {
34
+ edit: boolean;
35
+ value?: CellValue;
36
+ display_value?: string | null;
37
+ styling?: string;
38
+ header?: boolean;
39
+ datatype?:
40
+ | "str"
41
+ | "markdown"
42
+ | "html"
43
+ | "number"
44
+ | "bool"
45
+ | "date"
46
+ | "image";
47
+ latex_delimiters: {
48
+ left: string;
49
+ right: string;
50
+ display: boolean;
51
+ }[];
52
+ line_breaks?: boolean;
53
+ editable?: boolean;
54
+ is_static?: boolean;
55
+ max_chars?: number | null;
56
+ components?: Record<string, any>;
57
+ i18n: I18nFormatter;
58
+ is_dragging?: boolean;
59
+ wrap_text?: boolean;
60
+ expanded?: boolean;
61
+ show_selection_buttons?: boolean;
62
+ coords: [number, number];
63
+ on_select_column?: ((col: number) => void) | null;
64
+ on_select_row?: ((row: number) => void) | null;
65
+ el?: HTMLTextAreaElement | null;
66
+ onblur?: (detail: {
67
+ blur_event: FocusEvent;
68
+ coords: [number, number];
69
+ }) => void;
70
+ onkeydown?: (event: KeyboardEvent) => void;
71
+ pad_left: boolean;
72
+ } = $props();
73
+
74
+ function truncate_text(
75
+ text: CellValue,
76
+ max_length: number | null = null,
77
+ is_image = false
78
+ ): string {
79
+ if (is_image) return String(text);
80
+ const str = String(text);
81
+ if (!max_length || max_length <= 0) return str;
82
+ if (str.length <= max_length) return str;
83
+ return str.slice(0, max_length) + "...";
84
+ }
85
+
86
+ let should_truncate = $derived(
87
+ !edit && !expanded && max_chars !== null && max_chars > 0
88
+ );
89
+
90
+ let display_content = $derived(
91
+ editable ? value : display_value !== null ? display_value : value
92
+ );
93
+
94
+ let display_text = $derived(
95
+ should_truncate
96
+ ? truncate_text(display_content, max_chars, datatype === "image")
97
+ : display_content
98
+ );
99
+
100
+ function use_focus(node: HTMLTextAreaElement): any {
101
+ requestAnimationFrame(() => {
102
+ node.focus();
103
+ });
104
+
105
+ return {};
106
+ }
107
+
108
+ // grow the edit-mode textarea to fit its content so the overlay
109
+ // expands the same way the display span does.
110
+ function use_autosize(node: HTMLTextAreaElement): any {
111
+ function resize(): void {
112
+ node.style.height = "auto";
113
+ node.style.height = `${node.scrollHeight}px`;
114
+ }
115
+ node.addEventListener("input", resize);
116
+ requestAnimationFrame(resize);
117
+ return {
118
+ destroy() {
119
+ node.removeEventListener("input", resize);
120
+ }
121
+ };
122
+ }
123
+
124
+ function handle_blur(event: FocusEvent): void {
125
+ onblur?.({
126
+ blur_event: event,
127
+ coords: coords
128
+ });
129
+ }
130
+
131
+ function handle_keydown(event: KeyboardEvent): void {
132
+ onkeydown?.(event);
133
+ }
134
+
135
+ function commit_change(checked: boolean): void {
136
+ handle_blur({ target: { value } } as unknown as FocusEvent);
137
+ }
138
+
139
+ // returning cleanup from the effect fires the blur only when leaving edit mode, not on every render
140
+ $effect(() => {
141
+ if (edit) {
142
+ return () => {
143
+ handle_blur({ target: { value } } as unknown as FocusEvent);
144
+ };
145
+ }
146
+ });
147
+ </script>
148
+
149
+ {#if edit && datatype !== "bool"}
150
+ <textarea
151
+ readonly={is_static}
152
+ aria-readonly={is_static}
153
+ aria-label={is_static ? "Cell is read-only" : "Edit cell"}
154
+ bind:this={el}
155
+ bind:value
156
+ class:header
157
+ tabindex="-1"
158
+ onblur={handle_blur}
159
+ onmousedown={(e: MouseEvent) => e.stopPropagation()}
160
+ onclick={(e: MouseEvent) => e.stopPropagation()}
161
+ use:use_focus
162
+ use:use_autosize
163
+ onkeydown={handle_keydown}
164
+ class:pad_left
165
+ />
166
+ {/if}
167
+
168
+ {#if datatype === "bool" && typeof value === "boolean"}
169
+ <BooleanCell bind:value {editable} on_change={commit_change} />
170
+ {:else}
171
+ <span
172
+ class:dragging={is_dragging}
173
+ onkeydown={handle_keydown}
174
+ tabindex="0"
175
+ role="button"
176
+ class:edit
177
+ class:expanded={edit}
178
+ class:header
179
+ onfocus={(e) => e.preventDefault()}
180
+ style={styling}
181
+ data-editable={editable}
182
+ data-max-chars={max_chars}
183
+ data-expanded={edit}
184
+ placeholder=" "
185
+ class:text={datatype === "str"}
186
+ class:wrap={wrap_text}
187
+ >
188
+ {#if datatype === "image" && components.image}
189
+ {@const ImageComponent = components.image}
190
+ <ImageComponent
191
+ value={{ url: display_text }}
192
+ show_label={false}
193
+ label="cell-image"
194
+ show_download_button={false}
195
+ {i18n}
196
+ gradio={{ dispatch: () => {} }}
197
+ />
198
+ {:else if datatype === "html"}
199
+ {@html display_text}
200
+ {:else if datatype === "markdown"}
201
+ <MarkdownCode
202
+ message={display_text.toLocaleString()}
203
+ {latex_delimiters}
204
+ {line_breaks}
205
+ chatbot={false}
206
+ />
207
+ {:else}
208
+ {display_text}
209
+ {/if}
210
+ </span>
211
+ {/if}
212
+
213
+ {#if show_selection_buttons && coords && on_select_column && on_select_row}
214
+ <SelectionButtons
215
+ position="column"
216
+ {coords}
217
+ on_click={() => on_select_column(coords[1])}
218
+ />
219
+ <SelectionButtons
220
+ position="row"
221
+ {coords}
222
+ on_click={() => on_select_row(coords[0])}
223
+ />
224
+ {/if}
225
+
226
+ <style>
227
+ .dragging {
228
+ cursor: crosshair !important;
229
+ }
230
+
231
+ textarea {
232
+ position: absolute;
233
+ flex: 1 1 0%;
234
+ transform: translate(0.2px, -0.5px);
235
+ outline: none;
236
+ border: none;
237
+ background: transparent;
238
+ cursor: text;
239
+ width: calc(100% - var(--size-2));
240
+ resize: none;
241
+ height: 100%;
242
+ padding-left: 0;
243
+ font-size: inherit;
244
+ font-weight: inherit;
245
+ line-height: var(--line-lg);
246
+ left: var(--size-2);
247
+ user-select: text;
248
+ }
249
+
250
+ textarea:focus {
251
+ outline: none;
252
+ }
253
+
254
+ textarea.pad_left {
255
+ margin-left: var(--size-7);
256
+ }
257
+
258
+ span {
259
+ flex: 1 1 0%;
260
+ position: relative;
261
+ display: block;
262
+ outline: none;
263
+ cursor: text;
264
+ width: 100%;
265
+ min-width: 0;
266
+ white-space: nowrap;
267
+ overflow: hidden;
268
+ text-overflow: ellipsis;
269
+ }
270
+
271
+ .header {
272
+ font-weight: var(--weight-bold);
273
+ }
274
+
275
+ span.text.expanded {
276
+ height: auto;
277
+ min-height: 100%;
278
+ white-space: pre-wrap;
279
+ word-break: break-word;
280
+ overflow: visible;
281
+ }
282
+
283
+ .edit {
284
+ opacity: 0;
285
+ pointer-events: none;
286
+ }
287
+
288
+ span :global(img) {
289
+ max-height: 100px;
290
+ max-width: 100%;
291
+ height: auto;
292
+ width: auto;
293
+ object-fit: contain;
294
+ }
295
+
296
+ textarea:read-only {
297
+ cursor: not-allowed;
298
+ }
299
+
300
+ .wrap,
301
+ .wrap.expanded {
302
+ white-space: normal;
303
+ overflow: visible;
304
+ text-overflow: clip;
305
+ overflow-wrap: break-word;
306
+ word-break: break-word;
307
+ }
308
+ </style>
6.14.0/dataframe/shared/EmptyRowButton.svelte ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { on_click }: { on_click: () => void } = $props();
3
+ </script>
4
+
5
+ <button class="add-row-button" onclick={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>
6.14.0/dataframe/shared/Example.svelte ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: (string | number)[][];
3
+ </script>
4
+
5
+ <table class="input-dataframe-example">
6
+ {#each value.slice(0, 3) as row}
7
+ <tr>
8
+ {#each row.slice(0, 3) as cell}
9
+ <td class="p-2">{cell}</td>
10
+ {/each}
11
+ {#if row.length > 3}
12
+ <td class="p-2">...</td>
13
+ {/if}
14
+ </tr>
15
+ {/each}
16
+ {#if value.length > 3}
17
+ <tr>
18
+ {#each Array(Math.min(4, value[0].length)) as _}
19
+ <td class="p-2">...</td>
20
+ {/each}
21
+ </tr>
22
+ {/if}
23
+ </table>
24
+
25
+ <style>
26
+ table {
27
+ border-collapse: separate;
28
+ }
29
+ </style>
6.14.0/dataframe/shared/FilterMenu.svelte ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { Check, DropdownArrow } from "@gradio/icons";
4
+ import type { FilterDatatype } from "./types";
5
+
6
+ let {
7
+ on_filter = () => {}
8
+ }: {
9
+ on_filter?: (
10
+ datatype: FilterDatatype,
11
+ selected_filter: string,
12
+ value: string
13
+ ) => void;
14
+ } = $props();
15
+
16
+ let menu_element: HTMLDivElement;
17
+ let datatype: "string" | "number" = $state("string");
18
+ let current_filter = $state("Contains");
19
+ let filter_dropdown_open = $state(false);
20
+ let filter_input_value = $state("");
21
+
22
+ const filter_options = {
23
+ string: [
24
+ "Contains",
25
+ "Does not contain",
26
+ "Starts with",
27
+ "Ends with",
28
+ "Is",
29
+ "Is not",
30
+ "Is empty",
31
+ "Is not empty"
32
+ ],
33
+ number: ["=", "≠", ">", "<", "≥", "≤", "Is empty", "Is not empty"]
34
+ };
35
+
36
+ onMount(() => {
37
+ position_menu();
38
+ });
39
+
40
+ function position_menu(): void {
41
+ if (!menu_element) return;
42
+
43
+ const viewport_width = window.innerWidth;
44
+ const viewport_height = window.innerHeight;
45
+ const menu_rect = menu_element.getBoundingClientRect();
46
+
47
+ const x = (viewport_width - menu_rect.width) / 2;
48
+ const y = (viewport_height - menu_rect.height) / 2;
49
+
50
+ menu_element.style.left = `${x}px`;
51
+ menu_element.style.top = `${y}px`;
52
+ }
53
+
54
+ function handle_filter_input(e: Event): void {
55
+ const target = e.target as HTMLInputElement;
56
+ filter_input_value = target.value;
57
+ }
58
+ </script>
59
+
60
+ <div>
61
+ <div class="background"></div>
62
+ <div bind:this={menu_element} class="filter-menu">
63
+ <div class="filter-datatype-container">
64
+ <span>Filter as</span>
65
+ <button
66
+ onclick={(e) => {
67
+ e.stopPropagation();
68
+ datatype = datatype === "string" ? "number" : "string";
69
+ current_filter = filter_options[datatype][0];
70
+ }}
71
+ aria-label={`Change filter type. Filtering ${datatype}s`}
72
+ >
73
+ {datatype}
74
+ </button>
75
+ </div>
76
+
77
+ <div class="input-container">
78
+ <div class="filter-dropdown">
79
+ <button
80
+ onclick={(e) => {
81
+ e.stopPropagation();
82
+ filter_dropdown_open = !filter_dropdown_open;
83
+ }}
84
+ aria-label={`Change filter. Using '${current_filter}'`}
85
+ >
86
+ {current_filter}
87
+ <DropdownArrow />
88
+ </button>
89
+
90
+ {#if filter_dropdown_open}
91
+ <div class="dropdown-filter-options">
92
+ {#each filter_options[datatype] as opt}
93
+ <button
94
+ onclick={(e) => {
95
+ e.stopPropagation();
96
+ current_filter = opt;
97
+ filter_dropdown_open = !filter_dropdown_open;
98
+ }}
99
+ class="filter-option"
100
+ >
101
+ {opt}
102
+ </button>
103
+ {/each}
104
+ </div>
105
+ {/if}
106
+ </div>
107
+
108
+ <input
109
+ type="text"
110
+ value={filter_input_value}
111
+ onclick={(e) => e.stopPropagation()}
112
+ oninput={handle_filter_input}
113
+ placeholder="Type a value"
114
+ class="filter-input"
115
+ />
116
+ </div>
117
+
118
+ <button
119
+ class="check-button"
120
+ onclick={() => on_filter(datatype, current_filter, filter_input_value)}
121
+ >
122
+ <Check />
123
+ </button>
124
+ </div>
125
+ </div>
126
+
127
+ <style>
128
+ .background {
129
+ position: fixed;
130
+ top: 0;
131
+ left: 0;
132
+ width: 100vw;
133
+ height: 100vh;
134
+ background-color: rgba(0, 0, 0, 0.4);
135
+ z-index: 20;
136
+ }
137
+
138
+ .filter-menu {
139
+ position: fixed;
140
+ background: var(--background-fill-primary);
141
+ border: 1px solid var(--border-color-primary);
142
+ border-radius: var(--radius-sm);
143
+ padding: var(--size-2);
144
+ display: flex;
145
+ flex-direction: column;
146
+ gap: var(--size-2);
147
+ box-shadow: var(--shadow-drop-lg);
148
+ width: 300px;
149
+ z-index: 21;
150
+ }
151
+
152
+ .filter-datatype-container {
153
+ display: flex;
154
+ gap: var(--size-2);
155
+ align-items: center;
156
+ }
157
+
158
+ .filter-menu span {
159
+ font-size: var(--text-sm);
160
+ color: var(--body-text-color);
161
+ }
162
+
163
+ .filter-menu button {
164
+ height: var(--size-6);
165
+ background: none;
166
+ border: 1px solid var(--border-color-primary);
167
+ border-radius: var(--radius-sm);
168
+ padding: var(--size-1) var(--size-2);
169
+ color: var(--body-text-color);
170
+ font-size: var(--text-sm);
171
+ cursor: pointer;
172
+ display: flex;
173
+ align-items: center;
174
+ justify-content: center;
175
+ gap: var(--size-2);
176
+ }
177
+
178
+ .filter-menu button:hover {
179
+ background-color: var(--background-fill-secondary);
180
+ }
181
+
182
+ .filter-input {
183
+ width: var(--size-full);
184
+ height: var(--size-6);
185
+ padding: var(--size-2);
186
+ padding-right: var(--size-8);
187
+ border: 1px solid var(--border-color-primary);
188
+ border-radius: var(--table-radius);
189
+ font-size: var(--text-sm);
190
+ color: var(--body-text-color);
191
+ background: var(--background-fill-secondary);
192
+ transition: all 0.2s ease;
193
+ }
194
+
195
+ .filter-input:hover {
196
+ border-color: var(--border-color-secondary);
197
+ background: var(--background-fill-primary);
198
+ }
199
+
200
+ .filter-input:focus {
201
+ outline: none;
202
+ border-color: var(--color-accent);
203
+ background: var(--background-fill-primary);
204
+ box-shadow: 0 0 0 1px var(--color-accent);
205
+ }
206
+
207
+ .dropdown-filter-options {
208
+ display: flex;
209
+ flex-direction: column;
210
+ background: var(--background-fill-primary);
211
+ border: 1px solid var(--border-color-primary);
212
+ border-radius: var(--radius-sm);
213
+ box-shadow: var(--shadow-drop-md);
214
+ position: absolute;
215
+ z-index: var(--layer-1);
216
+ }
217
+
218
+ .dropdown-filter-options .filter-option {
219
+ border: none;
220
+ justify-content: flex-start;
221
+ }
222
+
223
+ .input-container {
224
+ display: flex;
225
+ gap: var(--size-2);
226
+ align-items: center;
227
+ }
228
+
229
+ .input-container button {
230
+ width: 130px;
231
+ }
232
+
233
+ :global(svg.dropdown-arrow) {
234
+ width: var(--size-4);
235
+ height: var(--size-4);
236
+ margin-left: auto;
237
+ }
238
+
239
+ .filter-menu .check-button {
240
+ background: var(--color-accent);
241
+ color: white;
242
+ border: none;
243
+ width: var(--size-full);
244
+ height: var(--size-6);
245
+ border-radius: var(--radius-sm);
246
+ display: flex;
247
+ align-items: center;
248
+ justify-content: center;
249
+ padding: var(--size-1);
250
+ }
251
+
252
+ .check-button:hover {
253
+ background: var(--color-accent-soft);
254
+ }
255
+ </style>
6.14.0/dataframe/shared/HeaderCell.svelte ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import EditableCell from "./EditableCell.svelte";
3
+ import CellMenuButton from "./CellMenuButton.svelte";
4
+ import Padlock from "./icons/Padlock.svelte";
5
+ import FilterIcon from "./icons/FilterIcon.svelte";
6
+ import SortButtonUp from "./icons/SortButtonUp.svelte";
7
+ import SortButtonDown from "./icons/SortButtonDown.svelte";
8
+ import { BaseCheckbox } from "@gradio/checkbox";
9
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
10
+ import type { SortDirection } from "./types";
11
+
12
+ let {
13
+ value,
14
+ col_idx,
15
+ is_editing = false,
16
+ is_selected = false,
17
+ is_static = false,
18
+ is_bool = false,
19
+ select_all_state = "unchecked",
20
+ sort_direction = null,
21
+ sort_priority = null,
22
+ multi_sort = false,
23
+ is_filtered = false,
24
+ show_menu_button = false,
25
+ is_first_column = false,
26
+ latex_delimiters,
27
+ line_breaks = true,
28
+ editable = true,
29
+ max_chars = undefined,
30
+ i18n,
31
+ wrap_text = false,
32
+ onclick,
33
+ on_menu_click,
34
+ on_end_edit,
35
+ on_select_all
36
+ }: {
37
+ value: string;
38
+ col_idx: number;
39
+ is_editing?: boolean;
40
+ is_selected?: boolean;
41
+ is_static?: boolean;
42
+ is_bool?: boolean;
43
+ select_all_state?: "checked" | "unchecked" | "indeterminate";
44
+ sort_direction?: SortDirection | null;
45
+ sort_priority?: number | null;
46
+ multi_sort?: boolean;
47
+ is_filtered?: boolean;
48
+ show_menu_button?: boolean;
49
+ is_first_column?: boolean;
50
+ latex_delimiters: { left: string; right: string; display: boolean }[];
51
+ line_breaks?: boolean;
52
+ editable?: boolean;
53
+ max_chars?: number | undefined;
54
+ i18n: I18nFormatter;
55
+ wrap_text?: boolean;
56
+ onclick: (event: MouseEvent, col: number) => void;
57
+ on_menu_click: (event: MouseEvent, col: number) => void;
58
+ on_end_edit: (key: string) => void;
59
+ on_select_all?: (col: number, checked: boolean) => void;
60
+ } = $props();
61
+
62
+ let show_select_all = $derived(
63
+ is_bool && editable && !is_static && !!on_select_all
64
+ );
65
+ </script>
66
+
67
+ <th
68
+ class="header-cell"
69
+ class:focus={is_editing || is_selected}
70
+ class:sorted={sort_direction !== null}
71
+ class:filtered={is_filtered}
72
+ class:first-column={is_first_column}
73
+ data-heading={col_idx}
74
+ onclick={(e) => onclick(e, col_idx)}
75
+ onmousedown={(e) => {
76
+ e.preventDefault();
77
+ e.stopPropagation();
78
+ }}
79
+ title={value}
80
+ >
81
+ <div class="cell-wrap">
82
+ <div class="header-content">
83
+ {#if show_select_all}
84
+ <div
85
+ class="select-all-checkbox"
86
+ role="button"
87
+ tabindex="-1"
88
+ onclick={(e) => e.stopPropagation()}
89
+ onmousedown={(e) => e.stopPropagation()}
90
+ onkeydown={(e) => e.stopPropagation()}
91
+ >
92
+ <BaseCheckbox
93
+ value={select_all_state === "checked"}
94
+ indeterminate={select_all_state === "indeterminate"}
95
+ label={`Toggle all: ${value}`}
96
+ interactive={true}
97
+ on_select={() =>
98
+ on_select_all?.(col_idx, select_all_state !== "checked")}
99
+ />
100
+ </div>
101
+ {/if}
102
+ <EditableCell
103
+ {value}
104
+ {latex_delimiters}
105
+ {line_breaks}
106
+ edit={is_editing}
107
+ onkeydown={(event) => {
108
+ if (["Enter", "Escape", "Tab"].includes(event.key)) {
109
+ on_end_edit(event.key);
110
+ }
111
+ }}
112
+ header
113
+ {editable}
114
+ {is_static}
115
+ {i18n}
116
+ {max_chars}
117
+ {wrap_text}
118
+ coords={[col_idx, 0]}
119
+ pad_left={show_select_all ? true : false}
120
+ />
121
+ </div>
122
+ {#if sort_direction || is_filtered || is_static}
123
+ <span class="header-icons">
124
+ {#if is_filtered}
125
+ <span class="filter-indicator" aria-label="Filtered">
126
+ <FilterIcon />
127
+ </span>
128
+ {/if}
129
+ {#if sort_direction}
130
+ <span
131
+ class="sort-indicator"
132
+ aria-label="Sorted {sort_direction}ending"
133
+ >
134
+ {#if sort_direction === "asc"}
135
+ <SortButtonUp size={13} />
136
+ {:else}
137
+ <SortButtonDown size={13} />
138
+ {/if}
139
+ {#if multi_sort && sort_priority != null}
140
+ <span class="sort-priority">{sort_priority}</span>
141
+ {/if}
142
+ </span>
143
+ {/if}
144
+
145
+ {#if is_static}
146
+ <Padlock size={11} />
147
+ {/if}
148
+ </span>
149
+ {/if}
150
+ {#if show_menu_button}
151
+ <CellMenuButton on_click={(e) => on_menu_click(e, col_idx)} />
152
+ {/if}
153
+ </div>
154
+ </th>
155
+
156
+ <style>
157
+ .header-cell {
158
+ --ring-color: transparent;
159
+ position: relative;
160
+ outline: none;
161
+ box-shadow:
162
+ inset 1px 0 0 var(--border-color-primary),
163
+ inset 0 0 0 1px var(--ring-color);
164
+ padding: 0;
165
+ background: var(--table-even-background-fill) !important;
166
+ font-weight: var(--weight-bold, 700);
167
+ outline: none;
168
+ box-shadow:
169
+ inset 1px 0 0 var(--border-color-primary),
170
+ inset 0 0 0 1px var(--ring-color);
171
+ padding: 0;
172
+ overflow: visible;
173
+ box-sizing: border-box;
174
+ }
175
+
176
+ .header-cell.first-column {
177
+ box-shadow: inset 0 0 0 1px var(--ring-color);
178
+ }
179
+
180
+ .header-cell:hover :global(.cell-menu-button),
181
+ .header-cell.focus :global(.cell-menu-button) {
182
+ display: flex;
183
+ }
184
+
185
+ .header-cell.focus {
186
+ --ring-color: var(--color-accent);
187
+ --sel-top: inset 0 2px 0 0 var(--ring-color);
188
+ --sel-bottom: inset 0 -2px 0 0 var(--ring-color);
189
+ --sel-left: inset 2px 0 0 0 var(--ring-color);
190
+ --sel-right: inset -2px 0 0 0 var(--ring-color);
191
+ box-shadow:
192
+ var(--sel-top), var(--sel-bottom), var(--sel-left), var(--sel-right);
193
+ z-index: 2;
194
+ position: relative;
195
+ }
196
+
197
+ .header-cell.focus.first-column {
198
+ box-shadow: inset 0 0 0 2px var(--ring-color);
199
+ }
200
+
201
+ .header-content {
202
+ display: flex;
203
+ align-items: center;
204
+ gap: var(--size-3);
205
+ overflow: hidden;
206
+ min-width: 0;
207
+ }
208
+
209
+ .header-icons {
210
+ display: flex;
211
+ align-items: center;
212
+ gap: 2px;
213
+ flex-shrink: 0;
214
+ margin-left: auto;
215
+ opacity: 0.6;
216
+ }
217
+
218
+ .sort-indicator {
219
+ display: flex;
220
+ align-items: center;
221
+ position: relative;
222
+ margin-left: -5px;
223
+ }
224
+
225
+ .sort-priority {
226
+ font-size: 8px;
227
+ background: var(--button-secondary-background-fill);
228
+ border-radius: var(--radius-full);
229
+ width: 12px;
230
+ height: 12px;
231
+ display: flex;
232
+ align-items: center;
233
+ justify-content: center;
234
+ line-height: 1;
235
+ }
236
+
237
+ .filter-indicator {
238
+ display: flex;
239
+ align-items: center;
240
+ width: 16px;
241
+ height: 16px;
242
+ margin-top: 3px;
243
+ }
244
+
245
+ .filter-indicator :global(svg) {
246
+ width: 100%;
247
+ height: 100%;
248
+ }
249
+
250
+ .cell-wrap {
251
+ display: flex;
252
+ align-items: center;
253
+ justify-content: flex-start;
254
+ outline: none;
255
+ min-height: var(--size-9);
256
+ position: relative;
257
+ height: 100%;
258
+ padding: var(--size-2);
259
+ box-sizing: border-box;
260
+ gap: var(--size-1);
261
+ overflow: visible;
262
+ min-width: 0;
263
+ }
264
+
265
+ .select-all-checkbox {
266
+ display: flex;
267
+ align-items: center;
268
+ justify-content: center;
269
+ flex-shrink: 0;
270
+ width: var(--size-4);
271
+ }
272
+
273
+ .select-all-checkbox :global(label) {
274
+ margin: 0;
275
+ }
276
+
277
+ .select-all-checkbox :global(span) {
278
+ display: none;
279
+ }
280
+ </style>
6.14.0/dataframe/shared/RowNumber.svelte ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let {
3
+ index = null,
4
+ is_header = false
5
+ }: { index?: number | null; is_header?: boolean } = $props();
6
+ </script>
7
+
8
+ {#if is_header}
9
+ <th tabindex="-1" class="row-number">
10
+ <div class="cell-wrap">
11
+ <div class="header-content">
12
+ <div class="header-text"></div>
13
+ </div>
14
+ </div>
15
+ </th>
16
+ {:else}
17
+ <td class="row-number" tabindex="-1" data-row={index} data-col="row-number">
18
+ {index !== null ? index + 1 : ""}
19
+ </td>
20
+ {/if}
21
+
22
+ <style>
23
+ .row-number {
24
+ text-align: center;
25
+ padding: var(--size-1);
26
+ min-width: var(--size-12);
27
+ width: var(--size-12);
28
+ overflow: hidden;
29
+ text-overflow: ellipsis;
30
+ white-space: nowrap;
31
+ font-weight: var(--weight-semibold);
32
+ border-right: 1px solid var(--border-color-primary);
33
+ }
34
+ </style>
6.14.0/dataframe/shared/Table.svelte ADDED
@@ -0,0 +1,1480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import {
3
+ createSvelteTable,
4
+ createSvelteVirtualizer,
5
+ getCoreRowModel,
6
+ getSortedRowModel,
7
+ getFilteredRowModel,
8
+ type ColumnDef,
9
+ type SortingState,
10
+ type ColumnFiltersState,
11
+ type ColumnPinningState
12
+ } from "./tanstack/index.js";
13
+ import { tick, onMount } from "svelte";
14
+ import { Upload } from "@gradio/upload";
15
+
16
+ import { MarkdownCode } from "@gradio/markdown-code";
17
+ import HeaderCell from "./HeaderCell.svelte";
18
+ import DataCell from "./DataCell.svelte";
19
+ import EmptyRowButton from "./EmptyRowButton.svelte";
20
+ import type { SelectData } from "@gradio/utils";
21
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
22
+ import { type Client } from "@gradio/client";
23
+ import type { Datatype, DataframeValue, EditData } from "./utils/utils";
24
+ import { cast_value_to_type } from "./utils/utils";
25
+ import CellMenu from "./CellMenu.svelte";
26
+ import Toolbar from "./Toolbar.svelte";
27
+ import type {
28
+ CellValue,
29
+ CellCoordinate,
30
+ SortDirection,
31
+ FilterDatatype
32
+ } from "./types";
33
+ import {
34
+ is_cell_in_selection,
35
+ is_cell_selected,
36
+ handle_click_outside as handle_click_outside_util
37
+ } from "./utils/selection_utils";
38
+ import { copy_table_data, handle_file_upload } from "./utils/table_utils";
39
+ import { gradio_filter_fn } from "./utils/filter";
40
+ import { create_column_measurement } from "./column_measurement.svelte.js";
41
+
42
+ let {
43
+ datatype,
44
+ label = null,
45
+ show_label = true,
46
+ headers = $bindable([]),
47
+ values = $bindable([]),
48
+ col_count,
49
+ row_count,
50
+ latex_delimiters,
51
+ components = {},
52
+ editable = true,
53
+ wrap = false,
54
+ root,
55
+ i18n,
56
+ max_height = 500,
57
+ line_breaks = true,
58
+ column_widths = [],
59
+ show_row_numbers = false,
60
+ upload,
61
+ stream_handler,
62
+ buttons = null,
63
+ value_is_output = $bindable(false),
64
+ max_chars = undefined,
65
+ show_search = "none",
66
+ pinned_columns = 0,
67
+ static_columns = [],
68
+ fullscreen = false,
69
+ display_value = null,
70
+ styling = null,
71
+ onchange,
72
+ oninput,
73
+ onselect,
74
+ onedit,
75
+ onsearch,
76
+ onfullscreen
77
+ }: {
78
+ datatype: Datatype | Datatype[];
79
+ label?: string | null;
80
+ show_label?: boolean;
81
+ headers?: (string | null)[];
82
+ values?: CellValue[][];
83
+ col_count: [number, "fixed" | "dynamic"];
84
+ row_count: [number, "fixed" | "dynamic"];
85
+ latex_delimiters: { left: string; right: string; display: boolean }[];
86
+ components?: Record<string, any>;
87
+ editable?: boolean;
88
+ wrap?: boolean;
89
+ root: string;
90
+ i18n: I18nFormatter;
91
+ max_height?: number;
92
+ line_breaks?: boolean;
93
+ column_widths?: string[];
94
+ show_row_numbers?: boolean;
95
+ upload: Client["upload"];
96
+ stream_handler: Client["stream"];
97
+ buttons?: string[] | null;
98
+ value_is_output?: boolean;
99
+ max_chars?: number | undefined;
100
+ show_search?: "none" | "search" | "filter";
101
+ pinned_columns?: number;
102
+ static_columns?: (string | number)[];
103
+ fullscreen?: boolean;
104
+ display_value?: string[][] | null;
105
+ styling?: string[][] | null;
106
+ onchange?: (detail: DataframeValue) => void;
107
+ oninput?: () => void;
108
+ onselect?: (detail: SelectData) => void;
109
+ onedit?: (detail: EditData) => void;
110
+ onsearch?: (detail: string | null) => void;
111
+ onfullscreen?: () => void;
112
+ } = $props();
113
+
114
+ type GradioRow = Record<string, CellValue> & { _index: number };
115
+
116
+ // convert values[][] into tanstack row objects
117
+ let row_data: GradioRow[] = $derived(
118
+ (values ?? []).map((row, i) => {
119
+ const obj: GradioRow = { _index: i };
120
+ (row ?? []).forEach((val, j) => {
121
+ const dtype = Array.isArray(datatype) ? datatype[j] : datatype;
122
+ obj[`col_${j}`] = cast_value_to_type(val, dtype);
123
+ });
124
+ return obj;
125
+ })
126
+ );
127
+
128
+ let resolved_headers = $derived.by(() => {
129
+ let h = headers ?? [];
130
+ if (col_count[1] === "fixed" && h.length < col_count[0]) {
131
+ h = [
132
+ ...h,
133
+ ...Array(col_count[0] - h.length)
134
+ .fill(null)
135
+ .map((_, i) => `${i + h.length}`)
136
+ ];
137
+ }
138
+ if (!h.length) {
139
+ h = Array(col_count[0])
140
+ .fill(null)
141
+ .map((_, i) => `${i}`);
142
+ }
143
+ return h.map((v) => v ?? "");
144
+ });
145
+
146
+ let column_defs: ColumnDef<GradioRow, CellValue>[] = $derived(
147
+ resolved_headers.map((header_value, j) => ({
148
+ id: `col_${j}`,
149
+ accessorKey: `col_${j}`,
150
+ header: header_value,
151
+ size: 150,
152
+ minSize: 45,
153
+ filterFn: gradio_filter_fn,
154
+ meta: {
155
+ colIndex: j,
156
+ datatype: Array.isArray(datatype) ? datatype[j] : datatype,
157
+ isStatic:
158
+ static_columns.includes(j) || static_columns.includes(header_value),
159
+ isPinned: j < pinned_columns
160
+ }
161
+ }))
162
+ );
163
+
164
+ let sorting: SortingState = $state([]);
165
+ let column_filters: ColumnFiltersState = $state([]);
166
+ let global_filter: string = $state("");
167
+ let column_pinning: ColumnPinningState = $derived({
168
+ left: column_defs.filter((_, i) => i < pinned_columns).map((c) => c.id!)
169
+ });
170
+
171
+ const table = createSvelteTable<GradioRow>({
172
+ get data() {
173
+ return row_data;
174
+ },
175
+ get columns() {
176
+ return column_defs;
177
+ },
178
+ state: {
179
+ get sorting() {
180
+ return sorting;
181
+ },
182
+ get columnFilters() {
183
+ return column_filters;
184
+ },
185
+ get globalFilter() {
186
+ return global_filter;
187
+ },
188
+ get columnPinning() {
189
+ return column_pinning;
190
+ }
191
+ },
192
+ onSortingChange: (updater) => {
193
+ sorting = typeof updater === "function" ? updater(sorting) : updater;
194
+ },
195
+ onColumnFiltersChange: (updater) => {
196
+ column_filters =
197
+ typeof updater === "function" ? updater(column_filters) : updater;
198
+ },
199
+ onGlobalFilterChange: (updater) => {
200
+ global_filter =
201
+ typeof updater === "function" ? updater(global_filter) : updater;
202
+ },
203
+ getCoreRowModel: getCoreRowModel(),
204
+ getSortedRowModel: getSortedRowModel(),
205
+ getFilteredRowModel: getFilteredRowModel(),
206
+ globalFilterFn: "includesString",
207
+ enableSorting: true,
208
+ enableMultiSort: true,
209
+ maxMultiSortColCount: 3
210
+ });
211
+
212
+ let rows = $derived(table.getRowModel().rows);
213
+ let header_groups = $derived(table.getHeaderGroups());
214
+
215
+ let scroll_container: HTMLDivElement;
216
+
217
+ const virtualizer = createSvelteVirtualizer<
218
+ HTMLDivElement,
219
+ HTMLTableRowElement
220
+ >({
221
+ get count() {
222
+ return rows.length;
223
+ },
224
+ getScrollElement: () => scroll_container,
225
+ estimateSize: () => 35,
226
+ overscan: 10,
227
+ measureElement: (el, _entry, instance) => {
228
+ const h = el.getBoundingClientRect().height;
229
+ if (h > 0) return h;
230
+
231
+ const idx = el.getAttribute("data-index");
232
+ if (idx != null) {
233
+ const cached = (instance as any).itemSizeCache?.get(Number(idx));
234
+ if (typeof cached === "number") return cached;
235
+ }
236
+ return 35;
237
+ }
238
+ });
239
+
240
+ let virtual_items = $derived(virtualizer.virtualItems());
241
+ let total_size = $derived(virtualizer.totalSize());
242
+
243
+ let selected_cells: CellCoordinate[] = $state([]);
244
+ let selected: CellCoordinate | false = $state(false);
245
+ let editing: CellCoordinate | false = $state(false);
246
+ let header_edit: number | false = $state(false);
247
+ let selected_header: number | false = $state(false);
248
+ let active_cell_menu: {
249
+ row: number;
250
+ col: number;
251
+ x: number;
252
+ y: number;
253
+ } | null = $state(null);
254
+ let active_header_menu: { col: number; x: number; y: number } | null =
255
+ $state(null);
256
+ let copy_flash = $state(false);
257
+ let is_dragging = $state(false);
258
+ let show_scroll_button = $state(false);
259
+ let dragging = $state(false); // file drag
260
+
261
+ let parent: HTMLDivElement;
262
+
263
+ function get_dtype(col: number): Datatype {
264
+ return Array.isArray(datatype) ? (datatype[col] ?? "str") : datatype;
265
+ }
266
+
267
+ type SizingEntry = { val: string; col_idx: number; dtype: Datatype };
268
+
269
+ // heading multipliers for markdown/html block elements that render
270
+ // at a larger font size than body text.
271
+ const HEADING_MULT = [2.2, 1.7, 1.4, 1.2, 1.1, 1.05];
272
+
273
+ function md_visual_length(s: string): number {
274
+ const heading = s.match(/^\s*(#{1,6})\s+(.+)/);
275
+ if (heading) {
276
+ const lvl = heading[1].length;
277
+ const text = heading[2].replace(/[*_`[\]()]/g, "");
278
+ return text.length * HEADING_MULT[lvl - 1];
279
+ }
280
+ return s.replace(/[*_`#[\]()]/g, "").length;
281
+ }
282
+
283
+ function html_visual_length(s: string): number {
284
+ const stripped = s.replace(/<[^>]+>/g, "").length;
285
+ const h = s.match(/<h([1-6])\b/i);
286
+ if (h) return stripped * HEADING_MULT[parseInt(h[1]) - 1];
287
+ return stripped;
288
+ }
289
+
290
+ // mirror EditableCell.truncate_text so the sizing row reserves width
291
+ // for the truncated ("…") string, not the full source
292
+ function apply_truncation(s: string, dtype: Datatype): string {
293
+ if (
294
+ max_chars &&
295
+ max_chars > 0 &&
296
+ dtype !== "image" &&
297
+ s.length > max_chars
298
+ ) {
299
+ return s.slice(0, max_chars) + "...";
300
+ }
301
+ return s;
302
+ }
303
+
304
+ // find the widest rendered value per visible column for the sizing row
305
+ function compute_sizing_row(): SizingEntry[] {
306
+ const headers = header_groups[0]?.headers ?? [];
307
+ return headers.map((header) => {
308
+ const col_idx = (header.column.columnDef.meta as any)?.colIndex ?? 0;
309
+ const dtype = get_dtype(col_idx);
310
+ const accessor = `col_${col_idx}`;
311
+
312
+ if (dtype === "bool") {
313
+ return { val: "false", col_idx, dtype };
314
+ }
315
+
316
+ const visual_len =
317
+ dtype === "markdown"
318
+ ? md_visual_length
319
+ : dtype === "html"
320
+ ? html_visual_length
321
+ : (s: string) => s.length;
322
+
323
+ let best = "";
324
+ let best_len = -1;
325
+ for (const r of rows) {
326
+ const row_idx = r.original._index;
327
+ const rendered = editable
328
+ ? r.original[accessor]
329
+ : (display_value?.[row_idx]?.[col_idx] ??
330
+ values?.[row_idx]?.[col_idx]);
331
+ if (rendered == null) continue;
332
+ const v = apply_truncation(String(rendered), dtype);
333
+ const len = visual_len(v);
334
+ if (len > best_len) {
335
+ best_len = len;
336
+ best = v;
337
+ }
338
+ }
339
+ return { val: best, col_idx, dtype };
340
+ });
341
+ }
342
+
343
+ function get_display_value(row: number, col: number): string {
344
+ if (display_value?.[row]?.[col] !== undefined)
345
+ return display_value[row][col];
346
+ return String(values?.[row]?.[col] ?? "");
347
+ }
348
+
349
+ function get_styling(row: number, col: number): string {
350
+ return styling?.[row]?.[col] ?? "";
351
+ }
352
+
353
+ function push_change(
354
+ new_values?: CellValue[][],
355
+ new_headers?: (string | null)[]
356
+ ): void {
357
+ onchange?.({
358
+ data: new_values ?? values,
359
+ headers: (new_headers ?? resolved_headers) as string[],
360
+ metadata: null
361
+ });
362
+ if (!value_is_output) oninput?.();
363
+ value_is_output = false;
364
+ }
365
+
366
+ function handle_cell_click(
367
+ event: MouseEvent,
368
+ row: number,
369
+ col: number
370
+ ): void {
371
+ const col_is_static =
372
+ !editable ||
373
+ static_columns.includes(col) ||
374
+ static_columns.includes(resolved_headers[col]);
375
+ if (!col_is_static) {
376
+ event.preventDefault();
377
+ }
378
+ event.stopPropagation();
379
+
380
+ const coord: CellCoordinate = [row, col];
381
+ if (event.shiftKey && selected) {
382
+ // range select
383
+ const [r1, c1] = selected;
384
+ const [r2, c2] = coord;
385
+ const new_cells: CellCoordinate[] = [];
386
+ for (let r = Math.min(r1, r2); r <= Math.max(r1, r2); r++) {
387
+ for (let c = Math.min(c1, c2); c <= Math.max(c1, c2); c++) {
388
+ new_cells.push([r, c]);
389
+ }
390
+ }
391
+ selected_cells = new_cells;
392
+ } else if (event.metaKey || event.ctrlKey) {
393
+ // toggle select
394
+ const exists = selected_cells.some(([r, c]) => r === row && c === col);
395
+ selected_cells = exists
396
+ ? selected_cells.filter(([r, c]) => !(r === row && c === col))
397
+ : [...selected_cells, coord];
398
+ } else {
399
+ selected_cells = [coord];
400
+ }
401
+
402
+ selected = coord;
403
+ header_edit = false;
404
+ selected_header = false;
405
+ active_cell_menu = null;
406
+ active_header_menu = null;
407
+
408
+ // click selects, does NOT enter edit mode (double-click or typing does)
409
+ editing = false;
410
+
411
+ onselect?.({
412
+ index: coord,
413
+ value: values?.[row]?.[col],
414
+ row_value: values?.[row] ?? [],
415
+ col_value: values?.map((r) => r[col]) ?? []
416
+ } as any);
417
+
418
+ if (!col_is_static) {
419
+ tick().then(() => parent?.focus());
420
+ }
421
+ }
422
+
423
+ function handle_cell_dblclick(
424
+ event: MouseEvent,
425
+ row: number,
426
+ col: number
427
+ ): void {
428
+ const col_is_static =
429
+ !editable ||
430
+ static_columns.includes(col) ||
431
+ static_columns.includes(resolved_headers[col]);
432
+ if (col_is_static) return;
433
+ event.preventDefault();
434
+ event.stopPropagation();
435
+ editing = [row, col];
436
+ }
437
+
438
+ function handle_blur(detail: {
439
+ blur_event: FocusEvent;
440
+ coords: [number, number];
441
+ }): void {
442
+ const { coords } = detail;
443
+ const input_el = detail.blur_event.target as HTMLTextAreaElement;
444
+ if (!input_el || input_el.value === undefined) return;
445
+
446
+ const [row, col] = coords;
447
+ const old_value = values?.[row]?.[col];
448
+ const new_value = input_el.value;
449
+
450
+ if (String(old_value) !== String(new_value)) {
451
+ const new_values = values.map((r) => [...r]);
452
+ new_values[row][col] = new_value;
453
+ values = new_values;
454
+
455
+ onedit?.({
456
+ index: [row, col],
457
+ value: new_value,
458
+ previous_value: String(old_value ?? "")
459
+ });
460
+ push_change(new_values);
461
+ }
462
+ }
463
+
464
+ function handle_header_click(event: MouseEvent, col: number): void {
465
+ if (event.target instanceof HTMLAnchorElement) return;
466
+ event.preventDefault();
467
+ event.stopPropagation();
468
+ if (!editable) return;
469
+
470
+ editing = false;
471
+ selected = false;
472
+ selected_cells = [];
473
+ active_cell_menu = null;
474
+ active_header_menu = null;
475
+ selected_header = col;
476
+ header_edit = editable ? col : false;
477
+ parent?.focus();
478
+ }
479
+
480
+ function end_header_edit(key: string): void {
481
+ if (["Escape", "Enter", "Tab"].includes(key)) {
482
+ header_edit = false;
483
+ parent?.focus();
484
+ }
485
+ }
486
+
487
+ function toggle_header_menu(event: MouseEvent, col: number): void {
488
+ event.stopPropagation();
489
+ if (active_header_menu?.col === col) {
490
+ active_header_menu = null;
491
+ } else {
492
+ const th = (event.target as HTMLElement).closest("th");
493
+ if (th) {
494
+ const rect = th.getBoundingClientRect();
495
+ active_header_menu = { col, x: rect.right, y: rect.bottom };
496
+ }
497
+ }
498
+ }
499
+
500
+ function handle_sort(col: number, direction: SortDirection): void {
501
+ const col_id = `col_${col}`;
502
+ const desc = direction === "desc";
503
+ // if already sorted this way, remove it
504
+ const existing = sorting.findIndex((s) => s.id === col_id);
505
+ if (existing >= 0 && sorting[existing].desc === desc) {
506
+ sorting = sorting.filter((s) => s.id !== col_id);
507
+ } else {
508
+ sorting = [
509
+ ...sorting.filter((s) => s.id !== col_id),
510
+ { id: col_id, desc }
511
+ ].slice(-3);
512
+ }
513
+ }
514
+
515
+ function clear_sort(): void {
516
+ sorting = [];
517
+ }
518
+
519
+ function handle_filter(
520
+ col: number,
521
+ dtype: FilterDatatype,
522
+ filter: string,
523
+ fvalue: string
524
+ ): void {
525
+ const col_id = `col_${col}`;
526
+ const existing = column_filters.findIndex((f) => f.id === col_id);
527
+ if (existing >= 0) {
528
+ column_filters = column_filters.filter((f) => f.id !== col_id);
529
+ } else {
530
+ column_filters = [
531
+ ...column_filters,
532
+ { id: col_id, value: { dtype, filter, value: fvalue } }
533
+ ];
534
+ }
535
+ }
536
+
537
+ function clear_filter(): void {
538
+ column_filters = [];
539
+ }
540
+
541
+ function handle_search(query: string | null): void {
542
+ global_filter = query ?? "";
543
+ onsearch?.(query);
544
+ }
545
+
546
+ function add_row(index?: number): void {
547
+ if (row_count[1] !== "dynamic") return;
548
+ const col_len = values[0]?.length || resolved_headers.length || 1;
549
+ const new_row: CellValue[] = Array(col_len).fill("");
550
+ const new_values = [...values];
551
+ if (index !== undefined) {
552
+ new_values.splice(index, 0, new_row);
553
+ } else {
554
+ new_values.push(new_row);
555
+ }
556
+ values = new_values;
557
+ push_change(new_values);
558
+ selected = [index ?? new_values.length - 1, 0];
559
+ parent?.focus();
560
+ }
561
+
562
+ function add_col(index?: number): void {
563
+ if (col_count[1] !== "dynamic") return;
564
+ const new_headers = [
565
+ ...(headers ?? []),
566
+ `Header ${(headers?.length ?? 0) + 1}`
567
+ ];
568
+ const new_values = values.map((row) => [...row, ""]);
569
+ if (index !== undefined) {
570
+ new_headers.splice(index, 0, new_headers.pop()!);
571
+ new_values.forEach((row) => row.splice(index, 0, row.pop()!));
572
+ }
573
+ values = new_values;
574
+ headers = new_headers;
575
+ push_change(new_values, new_headers);
576
+ parent?.focus();
577
+ }
578
+
579
+ function delete_row_at(index: number): void {
580
+ if (values.length <= 1) return;
581
+ values = [...values.slice(0, index), ...values.slice(index + 1)];
582
+ push_change(values);
583
+ active_cell_menu = null;
584
+ active_header_menu = null;
585
+ }
586
+
587
+ function delete_col_at(index: number): void {
588
+ if (col_count[1] !== "dynamic") return;
589
+ if ((values[0]?.length ?? 0) <= 1) return;
590
+ values = values.map((row) => [
591
+ ...row.slice(0, index),
592
+ ...row.slice(index + 1)
593
+ ]);
594
+ headers = [
595
+ ...(headers ?? []).slice(0, index),
596
+ ...(headers ?? []).slice(index + 1)
597
+ ];
598
+ push_change(values, headers as string[]);
599
+ active_cell_menu = null;
600
+ active_header_menu = null;
601
+ selected = false;
602
+ selected_cells = [];
603
+ editing = false;
604
+ }
605
+
606
+ function add_row_at(index: number, position: "above" | "below"): void {
607
+ add_row(position === "above" ? index : index + 1);
608
+ active_cell_menu = null;
609
+ }
610
+
611
+ function add_col_at(index: number, position: "left" | "right"): void {
612
+ add_col(position === "left" ? index : index + 1);
613
+ active_cell_menu = null;
614
+ }
615
+
616
+ function handle_select_all(col: number, checked: boolean): void {
617
+ const new_values = values.map((row) => {
618
+ const new_row = [...row];
619
+ new_row[col] = checked;
620
+ return new_row;
621
+ });
622
+ values = new_values;
623
+ push_change(new_values);
624
+ }
625
+
626
+ function get_select_all_state(
627
+ col: number
628
+ ): "checked" | "unchecked" | "indeterminate" {
629
+ if (!values.length) return "unchecked";
630
+ let true_count = 0;
631
+ for (const row of values) {
632
+ const v = row[col];
633
+ if (v === true || v === "true" || v === "True") true_count++;
634
+ }
635
+ if (true_count === 0) return "unchecked";
636
+ if (true_count === values.length) return "checked";
637
+ return "indeterminate";
638
+ }
639
+
640
+ function commit_filter(): void {
641
+ if (!global_filter || show_search !== "filter") return;
642
+ // get the filtered rows from tanstack and push as new values
643
+ const filtered_values = rows.map((row) => {
644
+ const original_idx = row.original._index;
645
+ return values[original_idx];
646
+ });
647
+ values = filtered_values;
648
+ global_filter = "";
649
+ push_change(filtered_values);
650
+ }
651
+
652
+ async function handle_copy(): Promise<void> {
653
+ const data_for_copy = values.map((row) =>
654
+ row.map((val, j) => ({ id: `${j}`, value: val }))
655
+ );
656
+ const cells_to_copy = selected_cells.length > 0 ? selected_cells : null;
657
+ await copy_table_data(data_for_copy, cells_to_copy);
658
+ copy_flash = true;
659
+ setTimeout(() => (copy_flash = false), 800);
660
+ }
661
+
662
+ function handle_click_outside(event: Event): void {
663
+ if (handle_click_outside_util(event, parent)) {
664
+ selected_cells = [];
665
+ selected = false;
666
+ editing = false;
667
+ header_edit = false;
668
+ selected_header = false;
669
+ active_cell_menu = null;
670
+ active_header_menu = null;
671
+ }
672
+ }
673
+
674
+ function handle_keydown(e: KeyboardEvent): void {
675
+ if (!selected && selected_header === false) return;
676
+
677
+ const num_rows = rows.length;
678
+ const num_cols = resolved_headers.length;
679
+
680
+ if (selected) {
681
+ const [row, col] = selected;
682
+
683
+ if (
684
+ editing &&
685
+ (e.key === "ArrowUp" ||
686
+ e.key === "ArrowDown" ||
687
+ e.key === "ArrowLeft" ||
688
+ e.key === "ArrowRight")
689
+ ) {
690
+ return;
691
+ }
692
+
693
+ switch (e.key) {
694
+ case "ArrowUp":
695
+ e.preventDefault();
696
+ if (row > 0) {
697
+ selected = [row - 1, col];
698
+ selected_cells = [selected];
699
+ virtualizer.instance.scrollToIndex(row - 1, { align: "auto" });
700
+ }
701
+ break;
702
+ case "ArrowDown":
703
+ e.preventDefault();
704
+ if (row < num_rows - 1) {
705
+ selected = [row + 1, col];
706
+ selected_cells = [selected];
707
+ virtualizer.instance.scrollToIndex(row + 1, { align: "auto" });
708
+ }
709
+ break;
710
+ case "ArrowLeft":
711
+ e.preventDefault();
712
+ if (col > 0) {
713
+ selected = [row, col - 1];
714
+ selected_cells = [selected];
715
+ }
716
+ break;
717
+ case "ArrowRight":
718
+ e.preventDefault();
719
+ if (col < num_cols - 1) {
720
+ selected = [row, col + 1];
721
+ selected_cells = [selected];
722
+ }
723
+ break;
724
+ case "Tab": {
725
+ e.preventDefault();
726
+ const was_editing = !!editing;
727
+ if (e.shiftKey) {
728
+ if (col > 0) selected = [row, col - 1];
729
+ else if (row > 0) selected = [row - 1, num_cols - 1];
730
+ } else {
731
+ if (col < num_cols - 1) selected = [row, col + 1];
732
+ else if (row < num_rows - 1) selected = [row + 1, 0];
733
+ }
734
+ selected_cells = [selected];
735
+ if (was_editing) {
736
+ const tab_col = (selected as CellCoordinate)[1];
737
+ const tab_static =
738
+ static_columns.includes(tab_col) ||
739
+ static_columns.includes(resolved_headers[tab_col]);
740
+ editing = editable && !tab_static ? selected : false;
741
+ } else {
742
+ editing = false;
743
+ }
744
+ if (!editing) tick().then(() => parent?.focus());
745
+ break;
746
+ }
747
+ case "Enter":
748
+ if (editing && e.shiftKey) {
749
+ // shift+enter inserts newline in textarea — don't intercept
750
+ return;
751
+ }
752
+ e.preventDefault();
753
+ if (editing) {
754
+ editing = false;
755
+ if (row < num_rows - 1) {
756
+ selected = [row + 1, col];
757
+ selected_cells = [selected];
758
+ }
759
+ tick().then(() => parent?.focus());
760
+ } else if (editable) {
761
+ const enter_static =
762
+ static_columns.includes(col) ||
763
+ static_columns.includes(resolved_headers[col]);
764
+ if (!enter_static) {
765
+ editing = [row, col];
766
+ }
767
+ }
768
+ break;
769
+ case "Escape":
770
+ editing = false;
771
+ tick().then(() => parent?.focus());
772
+ break;
773
+ case "Delete":
774
+ case "Backspace":
775
+ if (!editing && editable) {
776
+ e.preventDefault();
777
+ const new_values = values.map((r) => [...r]);
778
+ selected_cells.forEach(([r, c]) => {
779
+ if (!static_columns.includes(c)) {
780
+ new_values[r][c] = "";
781
+ }
782
+ });
783
+ values = new_values;
784
+ push_change(new_values);
785
+ }
786
+ break;
787
+ default:
788
+ // start editing on printable character
789
+ if (
790
+ editable &&
791
+ !editing &&
792
+ e.key.length === 1 &&
793
+ !e.ctrlKey &&
794
+ !e.metaKey &&
795
+ !static_columns.includes(col)
796
+ ) {
797
+ editing = [row, col];
798
+ }
799
+ break;
800
+ }
801
+
802
+ if ((e.ctrlKey || e.metaKey) && e.key === "c") {
803
+ handle_copy();
804
+ }
805
+ }
806
+ }
807
+
808
+ function handle_scroll(): void {
809
+ if (scroll_container) {
810
+ show_scroll_button = scroll_container.scrollTop > 100;
811
+ }
812
+ }
813
+
814
+ function scroll_to_top(): void {
815
+ scroll_container?.scrollTo({ top: 0 });
816
+ }
817
+
818
+ function toggle_cell_menu(event: MouseEvent, row: number, col: number): void {
819
+ event.stopPropagation();
820
+ if (active_cell_menu?.row === row && active_cell_menu.col === col) {
821
+ active_cell_menu = null;
822
+ } else {
823
+ const cell = (event.target as HTMLElement).closest(".body-cell, td");
824
+ if (cell) {
825
+ const rect = cell.getBoundingClientRect();
826
+ active_cell_menu = { row, col, x: rect.right, y: rect.bottom };
827
+ }
828
+ }
829
+ }
830
+
831
+ function on_file_upload(file_data: any): void {
832
+ handle_file_upload(
833
+ typeof file_data === "string" ? file_data : (file_data?.data ?? ""),
834
+ (head) => {
835
+ headers = head.map((h: any) => h ?? "");
836
+ return (headers as string[]).map((h: string, i: number) => ({
837
+ id: `h_${i}`,
838
+ value: h
839
+ }));
840
+ },
841
+ (vals) => {
842
+ values = vals;
843
+ push_change(vals, headers as string[]);
844
+ }
845
+ );
846
+ }
847
+
848
+ onMount(() => {
849
+ document.addEventListener("click", handle_click_outside);
850
+ return () => document.removeEventListener("click", handle_click_outside);
851
+ });
852
+
853
+ function measure_row(node: HTMLElement) {
854
+ tick().then(() => {
855
+ console.log("measuring");
856
+ virtualizer.instance.measureElement(node as any);
857
+ });
858
+
859
+ return {
860
+ destroy() {}
861
+ };
862
+ }
863
+
864
+ let header_row_el: HTMLTableRowElement;
865
+ let header_table_el: HTMLTableElement;
866
+ let viewport_width = $state(0);
867
+
868
+ const measurement = create_column_measurement({
869
+ header_row_el: () => header_row_el,
870
+ header_table_el: () => header_table_el,
871
+ resolved_headers: () => resolved_headers,
872
+ row_data: () => row_data,
873
+ show_row_numbers: () => show_row_numbers,
874
+ column_widths: () => column_widths,
875
+ viewport_width: () => viewport_width,
876
+ on_resize: undefined
877
+ });
878
+
879
+ let disable_scroll = $derived(
880
+ active_cell_menu !== null || active_header_menu !== null
881
+ );
882
+ let selected_index = $derived(selected !== false ? selected[0] : false);
883
+
884
+ $effect(() => {
885
+ if (typeof selected_index === "number") {
886
+ virtualizer.instance.scrollToIndex(selected_index, { align: "auto" });
887
+ }
888
+ });
889
+
890
+ function get_sort_info(col: number): {
891
+ direction: SortDirection | null;
892
+ priority: number | null;
893
+ } {
894
+ const col_id = `col_${col}`;
895
+ const idx = sorting.findIndex((s) => s.id === col_id);
896
+ if (idx === -1) return { direction: null, priority: null };
897
+ return { direction: sorting[idx].desc ? "desc" : "asc", priority: idx + 1 };
898
+ }
899
+
900
+ function get_filter_active(col: number): boolean {
901
+ return column_filters.some((f) => f.id === `col_${col}`);
902
+ }
903
+ </script>
904
+
905
+ <svelte:window
906
+ onresize={() => {
907
+ active_cell_menu = null;
908
+ active_header_menu = null;
909
+ }}
910
+ />
911
+
912
+ <div class="table-container" class:fullscreen>
913
+ {#if (label && label.length !== 0 && show_label) || (buttons === null ? true : buttons.includes("fullscreen")) || (buttons === null ? true : buttons.includes("copy")) || show_search !== "none"}
914
+ <div class="header-row">
915
+ {#if label && label.length !== 0 && show_label}
916
+ <div class="label"><p>{label}</p></div>
917
+ {/if}
918
+ <Toolbar
919
+ show_fullscreen_button={buttons === null
920
+ ? true
921
+ : buttons.includes("fullscreen")}
922
+ {fullscreen}
923
+ on_copy={handle_copy}
924
+ show_copy_button={buttons === null ? true : buttons.includes("copy")}
925
+ {show_search}
926
+ onsearch={(query) => handle_search(query)}
927
+ {onfullscreen}
928
+ on_commit_filter={commit_filter}
929
+ current_search_query={global_filter || null}
930
+ />
931
+ </div>
932
+ {/if}
933
+
934
+ <div
935
+ bind:this={parent}
936
+ class="table-wrap"
937
+ class:dragging={is_dragging}
938
+ class:menu-open={active_cell_menu || active_header_menu}
939
+ onkeydown={handle_keydown}
940
+ role="grid"
941
+ tabindex="0"
942
+ style="--df-max-col-width: {viewport_width}px;"
943
+ >
944
+ <Upload
945
+ {upload}
946
+ {stream_handler}
947
+ flex={false}
948
+ center={false}
949
+ boundedheight={false}
950
+ disable_click={true}
951
+ {root}
952
+ onload={on_file_upload}
953
+ bind:dragging
954
+ aria_label={i18n("dataframe.drop_to_upload")}
955
+ >
956
+ <div
957
+ class="virtual-table-viewport"
958
+ class:disable-scroll={disable_scroll}
959
+ bind:this={scroll_container}
960
+ bind:clientWidth={viewport_width}
961
+ onscroll={handle_scroll}
962
+ style="max-height: {max_height}px;"
963
+ role="grid"
964
+ >
965
+ {#if label && label.length !== 0}
966
+ <span class="sr-only">{label}</span>
967
+ {/if}
968
+ <!-- header row: uses table layout to auto-size columns by content -->
969
+ <table class="header-table" bind:this={header_table_el}>
970
+ <thead>
971
+ <tr bind:this={header_row_el}>
972
+ {#if show_row_numbers}
973
+ <th class="row-number-header">&nbsp;</th>
974
+ {/if}
975
+ {#each header_groups as headerGroup (headerGroup.id)}
976
+ {#each headerGroup.headers as header (header.id)}
977
+ {@const col_idx =
978
+ (header.column.columnDef.meta as any)?.colIndex ?? 0}
979
+ <HeaderCell
980
+ value={String(header.column.columnDef.header ?? "")}
981
+ {col_idx}
982
+ is_editing={header_edit === col_idx}
983
+ is_selected={selected_header === col_idx}
984
+ is_static={!!(header.column.columnDef.meta as any)
985
+ ?.isStatic}
986
+ is_bool={get_dtype(col_idx) === "bool"}
987
+ select_all_state={get_select_all_state(col_idx)}
988
+ sort_direction={get_sort_info(col_idx).direction}
989
+ sort_priority={get_sort_info(col_idx).priority}
990
+ multi_sort={sorting.length > 1}
991
+ is_filtered={get_filter_active(col_idx)}
992
+ show_menu_button={col_count[1] === "dynamic"}
993
+ is_first_column={col_idx === 0 && !show_row_numbers}
994
+ {latex_delimiters}
995
+ {line_breaks}
996
+ {editable}
997
+ {max_chars}
998
+ {i18n}
999
+ wrap_text={wrap}
1000
+ onclick={handle_header_click}
1001
+ on_menu_click={toggle_header_menu}
1002
+ on_end_edit={end_header_edit}
1003
+ on_select_all={handle_select_all}
1004
+ />
1005
+ {/each}
1006
+ {/each}
1007
+ </tr>
1008
+ </thead>
1009
+
1010
+ <tbody class="sizing-body" aria-hidden="true">
1011
+ {#if rows.length > 0}
1012
+ {@const sizing_row = compute_sizing_row()}
1013
+ <tr>
1014
+ {#if show_row_numbers}
1015
+ <td class="row-number-cell">{rows.length}</td>
1016
+ {/if}
1017
+ {#each sizing_row as entry (entry.col_idx)}
1018
+ <td
1019
+ ><div class="cell-wrap">
1020
+ {#if entry.dtype === "markdown"}
1021
+ <MarkdownCode
1022
+ message={entry.val}
1023
+ {latex_delimiters}
1024
+ {line_breaks}
1025
+ chatbot={false}
1026
+ />
1027
+ {:else if entry.dtype === "html"}
1028
+ {@html entry.val}
1029
+ {:else}
1030
+ {entry.val}
1031
+ {/if}
1032
+ </div></td
1033
+ >
1034
+ {/each}
1035
+ </tr>
1036
+ {/if}
1037
+ </tbody>
1038
+ </table>
1039
+
1040
+ <!-- table body: absolutely positioned rows (standard tanstack virtual pattern) -->
1041
+ <div
1042
+ class="virtual-body"
1043
+ style="height: {total_size}px; position: relative; flex-shrink: 0; width: {measurement.total_header_width
1044
+ ? `${measurement.total_header_width}px`
1045
+ : '100%'};"
1046
+ >
1047
+ {#each virtual_items as virtual_row (virtual_row.key)}
1048
+ {@const row = rows[virtual_row.index]}
1049
+ {@const row_idx = row?.original._index ?? virtual_row.index}
1050
+ {#if row}
1051
+ <div
1052
+ class="virtual-row"
1053
+ class:row-odd={virtual_row.index % 2 !== 0}
1054
+ data-index={virtual_row.index}
1055
+ style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({virtual_row.start}px);{selected_cells.some(
1056
+ ([r]) => r === row_idx
1057
+ )
1058
+ ? ' z-index: 3;'
1059
+ : ''}"
1060
+ use:measure_row={row}
1061
+ >
1062
+ {#if show_row_numbers}
1063
+ <div
1064
+ class="row-number-cell"
1065
+ data-row={row_idx}
1066
+ data-col="row-number"
1067
+ style="flex: 0 0 {measurement.row_num_width}px; width: {measurement.row_num_width}px;"
1068
+ >
1069
+ {row_idx + 1}
1070
+ </div>
1071
+ {/if}
1072
+ {#each row.getVisibleCells() as cell, ci (cell.id)}
1073
+ {@const col_idx =
1074
+ (cell.column.columnDef.meta as any)?.colIndex ?? 0}
1075
+ {@const is_sel = is_cell_in_selection(
1076
+ [row_idx, col_idx],
1077
+ selected_cells
1078
+ )}
1079
+ <DataCell
1080
+ value={cell.getValue() as CellValue}
1081
+ display_value={get_display_value(row_idx, col_idx)}
1082
+ datatype={get_dtype(col_idx)}
1083
+ {row_idx}
1084
+ {col_idx}
1085
+ col_style={measurement.get_col_style(ci)}
1086
+ cell_style={get_styling(row_idx, col_idx)}
1087
+ selection_classes={is_cell_selected(
1088
+ [row_idx, col_idx],
1089
+ selected_cells
1090
+ )}
1091
+ is_editing={!!(
1092
+ editing &&
1093
+ editing[0] === row_idx &&
1094
+ editing[1] === col_idx
1095
+ )}
1096
+ is_flash={copy_flash && is_sel}
1097
+ is_static={!editable ||
1098
+ !!(cell.column.columnDef.meta as any)?.isStatic}
1099
+ show_menu_button={editable &&
1100
+ !(cell.column.columnDef.meta as any)?.isStatic &&
1101
+ selected_cells.length === 1 &&
1102
+ selected_cells[0][0] === row_idx &&
1103
+ selected_cells[0][1] === col_idx}
1104
+ show_selection_buttons={selected_cells.length === 1 &&
1105
+ selected_cells[0][0] === row_idx &&
1106
+ selected_cells[0][1] === col_idx}
1107
+ is_solo={selected_cells.length === 1 &&
1108
+ selected_cells[0][0] === row_idx &&
1109
+ selected_cells[0][1] === col_idx}
1110
+ is_first_column={ci === 0 && !show_row_numbers}
1111
+ {latex_delimiters}
1112
+ {line_breaks}
1113
+ {editable}
1114
+ {max_chars}
1115
+ {i18n}
1116
+ {components}
1117
+ {is_dragging}
1118
+ wrap_text={wrap}
1119
+ onmousedown={(e) => handle_cell_click(e, row_idx, col_idx)}
1120
+ ondblclick={(e) =>
1121
+ handle_cell_dblclick(e, row_idx, col_idx)}
1122
+ oncontextmenu={(e) => {
1123
+ const is_static_cell = !!(
1124
+ cell.column.columnDef.meta as any
1125
+ )?.isStatic;
1126
+ if (!editable || is_static_cell) return;
1127
+ e.preventDefault();
1128
+ toggle_cell_menu(e, row_idx, col_idx);
1129
+ }}
1130
+ onblur={handle_blur}
1131
+ on_menu_click={(e) => toggle_cell_menu(e, row_idx, col_idx)}
1132
+ on_select_column={(c) => {
1133
+ selected_cells = rows.map(
1134
+ (_, r) => [r, c] as CellCoordinate
1135
+ );
1136
+ selected = selected_cells[0];
1137
+ }}
1138
+ on_select_row={(r) => {
1139
+ selected_cells = resolved_headers.map(
1140
+ (_, c) => [r, c] as CellCoordinate
1141
+ );
1142
+ selected = selected_cells[0];
1143
+ }}
1144
+ />
1145
+ {/each}
1146
+ </div>
1147
+ {/if}
1148
+ {/each}
1149
+ </div>
1150
+ </div>
1151
+ </Upload>
1152
+
1153
+ {#if show_scroll_button}
1154
+ <button class="scroll-top-button" onclick={scroll_to_top}>&uarr;</button>
1155
+ {/if}
1156
+ </div>
1157
+ </div>
1158
+
1159
+ {#if active_cell_menu || active_header_menu}
1160
+ <CellMenu
1161
+ x={active_cell_menu?.x ?? active_header_menu?.x ?? 0}
1162
+ y={active_cell_menu?.y ?? active_header_menu?.y ?? 0}
1163
+ row={active_header_menu ? -1 : (active_cell_menu?.row ?? 0)}
1164
+ {col_count}
1165
+ {row_count}
1166
+ on_add_row_above={() => add_row_at(active_cell_menu?.row ?? -1, "above")}
1167
+ on_add_row_below={() => add_row_at(active_cell_menu?.row ?? -1, "below")}
1168
+ on_add_column_left={() =>
1169
+ add_col_at(
1170
+ active_cell_menu?.col ?? active_header_menu?.col ?? -1,
1171
+ "left"
1172
+ )}
1173
+ on_add_column_right={() =>
1174
+ add_col_at(
1175
+ active_cell_menu?.col ?? active_header_menu?.col ?? -1,
1176
+ "right"
1177
+ )}
1178
+ on_delete_row={() => delete_row_at(active_cell_menu?.row ?? -1)}
1179
+ on_delete_col={() =>
1180
+ delete_col_at(active_cell_menu?.col ?? active_header_menu?.col ?? -1)}
1181
+ {editable}
1182
+ can_delete_rows={!active_header_menu && values.length > 1 && editable}
1183
+ can_delete_cols={values.length > 0 &&
1184
+ (values[0]?.length ?? 0) > 1 &&
1185
+ editable}
1186
+ {i18n}
1187
+ on_sort={active_header_menu
1188
+ ? (direction) => {
1189
+ handle_sort(active_header_menu!.col, direction);
1190
+ active_header_menu = null;
1191
+ }
1192
+ : undefined}
1193
+ on_clear_sort={active_header_menu
1194
+ ? () => {
1195
+ clear_sort();
1196
+ active_header_menu = null;
1197
+ }
1198
+ : undefined}
1199
+ sort_direction={active_header_menu
1200
+ ? get_sort_info(active_header_menu.col).direction
1201
+ : null}
1202
+ sort_priority={active_header_menu
1203
+ ? get_sort_info(active_header_menu.col).priority
1204
+ : null}
1205
+ on_filter={active_header_menu
1206
+ ? (dtype, filter, fvalue) => {
1207
+ handle_filter(active_header_menu!.col, dtype, filter, fvalue);
1208
+ active_header_menu = null;
1209
+ }
1210
+ : undefined}
1211
+ on_clear_filter={active_header_menu
1212
+ ? () => {
1213
+ clear_filter();
1214
+ active_header_menu = null;
1215
+ }
1216
+ : undefined}
1217
+ filter_active={active_header_menu
1218
+ ? get_filter_active(active_header_menu.col)
1219
+ : null}
1220
+ />
1221
+ {/if}
1222
+
1223
+ {#if values.length === 0 && editable && row_count[1] === "dynamic"}
1224
+ <EmptyRowButton on_click={() => add_row()} />
1225
+ {/if}
1226
+
1227
+ <style>
1228
+ .table-container {
1229
+ display: flex;
1230
+ flex-direction: column;
1231
+ gap: var(--size-2);
1232
+ position: relative;
1233
+ max-width: 100%;
1234
+ overflow-x: hidden;
1235
+ }
1236
+
1237
+ .table-container.fullscreen {
1238
+ padding: var(--size-4);
1239
+ height: 100%;
1240
+ box-sizing: border-box;
1241
+ }
1242
+
1243
+ .table-container.fullscreen .table-wrap {
1244
+ flex: 1 1 auto;
1245
+ min-height: 0;
1246
+ display: flex;
1247
+ flex-direction: column;
1248
+ }
1249
+
1250
+ .table-container.fullscreen .table-wrap > :global(*) {
1251
+ flex: 1 1 auto;
1252
+ min-height: 0;
1253
+ display: flex;
1254
+ flex-direction: column;
1255
+ }
1256
+
1257
+ .table-container.fullscreen .virtual-table-viewport {
1258
+ max-height: none !important;
1259
+ flex: 1 1 auto;
1260
+ min-height: 0;
1261
+ }
1262
+
1263
+ .table-wrap {
1264
+ position: relative;
1265
+ transition: 150ms;
1266
+ width: 100%;
1267
+ }
1268
+
1269
+ /* Constrain Upload component wrapper */
1270
+ .table-wrap > :global(*) {
1271
+ max-width: 100%;
1272
+ }
1273
+
1274
+ .table-wrap.menu-open {
1275
+ overflow: hidden;
1276
+ }
1277
+
1278
+ .table-wrap:focus-within {
1279
+ outline: none;
1280
+ }
1281
+
1282
+ .table-wrap.dragging {
1283
+ cursor: crosshair !important;
1284
+ user-select: none;
1285
+ }
1286
+
1287
+ .table-wrap.dragging * {
1288
+ cursor: crosshair !important;
1289
+ user-select: none;
1290
+ }
1291
+
1292
+ .table-wrap > :global(button) {
1293
+ border: 1px solid var(--border-color-primary);
1294
+ border-radius: var(--table-radius);
1295
+ overflow: hidden;
1296
+ }
1297
+
1298
+ /* Virtual scroll container */
1299
+ .virtual-table-viewport {
1300
+ display: flex;
1301
+ flex-direction: column;
1302
+ overflow: auto;
1303
+ position: relative;
1304
+ -webkit-overflow-scrolling: touch;
1305
+ min-width: 0;
1306
+ max-width: 100%;
1307
+ scrollbar-width: thin;
1308
+ scrollbar-color: rgba(128, 128, 128, 0.5) transparent;
1309
+ }
1310
+
1311
+ .virtual-table-viewport::-webkit-scrollbar {
1312
+ width: 4px;
1313
+ height: 4px;
1314
+ }
1315
+
1316
+ .virtual-table-viewport::-webkit-scrollbar-thumb {
1317
+ background-color: rgba(128, 128, 128, 0.5);
1318
+ border-radius: 4px;
1319
+ }
1320
+
1321
+ .virtual-table-viewport:hover {
1322
+ scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
1323
+ }
1324
+
1325
+ .virtual-table-viewport.disable-scroll {
1326
+ overflow: hidden !important;
1327
+ }
1328
+
1329
+ /* Header table: auto-sizes columns by content, sticky */
1330
+ .header-table {
1331
+ width: 100%;
1332
+ color: var(--body-text-color);
1333
+ font-size: var(--input-text-size);
1334
+ line-height: var(--line-md);
1335
+ font-family: var(--font-mono);
1336
+ border-spacing: 0;
1337
+ border-collapse: separate;
1338
+ table-layout: auto;
1339
+ position: sticky;
1340
+ top: 0;
1341
+ z-index: 7;
1342
+ flex-shrink: 0;
1343
+ }
1344
+
1345
+ /* Hidden sizing row — visibility:collapse hides the row but keeps column width contribution */
1346
+ .sizing-body tr {
1347
+ visibility: collapse;
1348
+ }
1349
+
1350
+ .sizing-body td {
1351
+ padding: var(--size-2);
1352
+ border: none;
1353
+ white-space: nowrap;
1354
+ max-width: var(--df-max-col-width);
1355
+ overflow: hidden;
1356
+ }
1357
+
1358
+ .header-table :global(.header-cell) {
1359
+ max-width: var(--df-max-col-width);
1360
+ }
1361
+
1362
+ /* Virtual body */
1363
+ .virtual-body {
1364
+ box-sizing: border-box;
1365
+ }
1366
+
1367
+ .virtual-row {
1368
+ display: flex;
1369
+ align-items: stretch;
1370
+ background: var(--table-odd-background-fill);
1371
+
1372
+ text-align: left;
1373
+ font-size: var(--input-text-size);
1374
+ line-height: var(--line-md);
1375
+ font-family: var(--font-mono);
1376
+ color: var(--body-text-color);
1377
+ min-height: var(--size-9);
1378
+ }
1379
+
1380
+ .virtual-row:last-child {
1381
+ border-bottom: none;
1382
+ }
1383
+
1384
+ .virtual-row.row-odd {
1385
+ background: var(--table-even-background-fill);
1386
+ }
1387
+
1388
+ .virtual-row:hover {
1389
+ background: var(--table-row-focus);
1390
+ }
1391
+
1392
+ /* Cell content wrapper (used in sizing-body) */
1393
+ .cell-wrap {
1394
+ display: flex;
1395
+ align-items: center;
1396
+ justify-content: flex-start;
1397
+ outline: none;
1398
+ min-height: var(--size-9);
1399
+ position: relative;
1400
+ height: 100%;
1401
+ padding: var(--size-2);
1402
+ box-sizing: border-box;
1403
+ gap: var(--size-1);
1404
+ overflow: visible;
1405
+ min-width: 0;
1406
+ }
1407
+
1408
+ /* Row number cells */
1409
+ .row-number-header {
1410
+ text-align: center;
1411
+ padding: var(--size-1);
1412
+ min-width: var(--size-12);
1413
+ width: var(--size-12);
1414
+ font-weight: var(--weight-semibold);
1415
+ border-right: 1px solid var(--border-color-primary);
1416
+ background: var(--table-even-background-fill) !important;
1417
+ }
1418
+
1419
+ .row-number-cell {
1420
+ text-align: center;
1421
+ padding: var(--size-1);
1422
+ min-width: var(--size-12);
1423
+ width: var(--size-12);
1424
+ flex-shrink: 0;
1425
+ overflow: hidden;
1426
+ text-overflow: ellipsis;
1427
+ white-space: nowrap;
1428
+ font-weight: var(--weight-semibold);
1429
+ border-right: 1px solid var(--border-color-primary);
1430
+ display: flex;
1431
+ align-items: center;
1432
+ justify-content: center;
1433
+ }
1434
+
1435
+ .header-row {
1436
+ display: flex;
1437
+ justify-content: flex-end;
1438
+ align-items: center;
1439
+ gap: var(--size-2);
1440
+ min-height: var(--size-6);
1441
+ flex-wrap: nowrap;
1442
+ width: 100%;
1443
+ }
1444
+
1445
+ .header-row .label {
1446
+ flex: 1 1 auto;
1447
+ margin-right: auto;
1448
+ font-family: var(--font-sans);
1449
+ }
1450
+
1451
+ .header-row .label p {
1452
+ margin: 0;
1453
+ color: var(--block-label-text-color);
1454
+ font-size: var(--block-label-text-size);
1455
+ line-height: var(--line-sm);
1456
+ }
1457
+
1458
+ .scroll-top-button {
1459
+ position: absolute;
1460
+ right: var(--size-4);
1461
+ bottom: var(--size-4);
1462
+ width: var(--size-8);
1463
+ height: var(--size-8);
1464
+ border-radius: var(--table-radius);
1465
+ background: var(--color-accent);
1466
+ color: white;
1467
+ border: none;
1468
+ cursor: pointer;
1469
+ display: flex;
1470
+ align-items: center;
1471
+ justify-content: center;
1472
+ font-size: var(--text-lg);
1473
+ z-index: 9;
1474
+ opacity: 0.5;
1475
+ }
1476
+
1477
+ .scroll-top-button:hover {
1478
+ opacity: 1;
1479
+ }
1480
+ </style>
6.14.0/dataframe/shared/Toolbar.svelte ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { Copy, Check } from "@gradio/icons";
3
+ import { FullscreenButton } from "@gradio/atoms";
4
+ import { IconButton } from "@gradio/atoms";
5
+
6
+ let {
7
+ show_fullscreen_button = false,
8
+ show_copy_button = false,
9
+ show_search = "none",
10
+ fullscreen = false,
11
+ on_copy,
12
+ on_commit_filter,
13
+ current_search_query = null,
14
+ onsearch,
15
+ onfullscreen
16
+ }: {
17
+ show_fullscreen_button?: boolean;
18
+ show_copy_button?: boolean;
19
+ show_search?: "none" | "search" | "filter";
20
+ fullscreen?: boolean;
21
+ on_copy: () => Promise<void>;
22
+ on_commit_filter: () => void;
23
+ current_search_query?: string | null;
24
+ onsearch?: (query: string | null) => void;
25
+ onfullscreen?: () => void;
26
+ } = $props();
27
+
28
+ let copied = $state(false);
29
+ let timer: ReturnType<typeof setTimeout>;
30
+ let input_value = $state("");
31
+
32
+ function handle_search_input(e: Event): void {
33
+ const target = e.target as HTMLTextAreaElement;
34
+ input_value = target.value;
35
+ const new_query = input_value || null;
36
+ if (current_search_query !== new_query) {
37
+ current_search_query = new_query;
38
+ onsearch?.(current_search_query);
39
+ }
40
+ }
41
+
42
+ function copy_feedback(): void {
43
+ copied = true;
44
+ if (timer) clearTimeout(timer);
45
+ timer = setTimeout(() => {
46
+ copied = false;
47
+ }, 2000);
48
+ }
49
+
50
+ async function handle_copy(): Promise<void> {
51
+ await on_copy();
52
+ copy_feedback();
53
+ }
54
+
55
+ $effect(() => {
56
+ return () => {
57
+ if (timer) clearTimeout(timer);
58
+ };
59
+ });
60
+ </script>
61
+
62
+ <div class="toolbar" role="toolbar" aria-label="Table actions">
63
+ <div class="toolbar-buttons">
64
+ {#if show_search !== "none"}
65
+ <div class="search-container">
66
+ <input
67
+ type="text"
68
+ value={current_search_query || ""}
69
+ oninput={handle_search_input}
70
+ placeholder={show_search === "filter" ? "Filter..." : "Search..."}
71
+ class="search-input"
72
+ class:filter-mode={show_search === "filter"}
73
+ title={`Enter text to ${show_search} the table`}
74
+ />
75
+ {#if current_search_query && show_search === "filter"}
76
+ <button
77
+ class="toolbar-button check-button"
78
+ onclick={on_commit_filter}
79
+ aria-label="Apply filter and update dataframe values"
80
+ title="Apply filter and update dataframe values"
81
+ >
82
+ <Check />
83
+ </button>
84
+ {/if}
85
+ </div>
86
+ {/if}
87
+ {#if show_copy_button}
88
+ <IconButton
89
+ Icon={copied ? Check : Copy}
90
+ label={copied ? "Copied to clipboard" : "Copy table data"}
91
+ onclick={handle_copy}
92
+ />
93
+ {/if}
94
+ {#if show_fullscreen_button}
95
+ <FullscreenButton {fullscreen} onclick={(_fs) => onfullscreen?.()} />
96
+ {/if}
97
+ </div>
98
+ </div>
99
+
100
+ <style>
101
+ .toolbar {
102
+ display: flex;
103
+ align-items: center;
104
+ gap: var(--size-2);
105
+ flex: 0 0 auto;
106
+ font-family: var(--font-sans);
107
+ }
108
+
109
+ .toolbar-buttons {
110
+ display: flex;
111
+ gap: var(--size-1);
112
+ flex-wrap: nowrap;
113
+ align-items: center;
114
+ }
115
+
116
+ .toolbar-button {
117
+ display: flex;
118
+ align-items: center;
119
+ justify-content: center;
120
+ width: var(--size-6);
121
+ height: var(--size-6);
122
+ padding: var(--size-1);
123
+ border: none;
124
+ border-radius: var(--radius-sm);
125
+ background: transparent;
126
+ color: var(--body-text-color-subdued);
127
+ cursor: pointer;
128
+ transition: all 0.2s;
129
+ }
130
+
131
+ .toolbar-button:hover {
132
+ background: var(--background-fill-secondary);
133
+ color: var(--body-text-color);
134
+ }
135
+
136
+ .toolbar-button :global(svg) {
137
+ width: var(--size-4);
138
+ height: var(--size-4);
139
+ }
140
+
141
+ .search-container {
142
+ position: relative;
143
+ }
144
+
145
+ .search-input {
146
+ width: var(--size-full);
147
+ height: var(--size-6);
148
+ padding: var(--size-2);
149
+ padding-right: var(--size-8);
150
+ border: 1px solid var(--border-color-primary);
151
+ border-radius: var(--table-radius);
152
+ font-size: var(--text-sm);
153
+ color: var(--body-text-color);
154
+ background: var(--background-fill-secondary);
155
+ transition: all 0.2s ease;
156
+ }
157
+
158
+ .search-input:hover {
159
+ border-color: var(--border-color-secondary);
160
+ background: var(--background-fill-primary);
161
+ }
162
+
163
+ .search-input:focus {
164
+ outline: none;
165
+ border-color: var(--color-accent);
166
+ background: var(--background-fill-primary);
167
+ box-shadow: 0 0 0 1px var(--color-accent);
168
+ }
169
+
170
+ .check-button {
171
+ position: absolute;
172
+ right: var(--size-1);
173
+ top: 50%;
174
+ transform: translateY(-50%);
175
+ background: var(--color-accent);
176
+ color: white;
177
+ border: none;
178
+ width: var(--size-4);
179
+ height: var(--size-4);
180
+ border-radius: var(--radius-sm);
181
+ display: flex;
182
+ align-items: center;
183
+ justify-content: center;
184
+ padding: var(--size-1);
185
+ }
186
+
187
+ .check-button :global(svg) {
188
+ width: var(--size-3);
189
+ height: var(--size-3);
190
+ }
191
+
192
+ .check-button:hover {
193
+ background: var(--color-accent-soft);
194
+ }
195
+
196
+ .toolbar-buttons :global(.icon-button) {
197
+ background: transparent !important;
198
+ height: var(--size-6);
199
+ width: var(--size-6);
200
+ }
201
+
202
+ .toolbar-buttons :global(.icon-button:hover) {
203
+ background: var(--background-fill-secondary) !important;
204
+ color: var(--body-text-color) !important;
205
+ border: 1px solid var(--border-color-primary);
206
+ border-radius: var(--radius-sm) !important;
207
+ }
208
+ </style>
6.14.0/dataframe/shared/column_measurement.svelte.ts ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * measures header cell positions/widths and provides inline styles
3
+ * for absolutely-positioned body cells to match.
4
+ */
5
+ export function create_column_measurement(opts: {
6
+ header_row_el: () => HTMLTableRowElement | undefined;
7
+ header_table_el: () => HTMLTableElement | undefined;
8
+ resolved_headers: () => string[];
9
+ row_data: () => any[];
10
+ show_row_numbers: () => boolean;
11
+ column_widths: () => string[];
12
+ viewport_width: () => number;
13
+ on_resize?: () => void;
14
+ }): {
15
+ readonly col_widths: number[];
16
+ readonly col_lefts: number[];
17
+ readonly total_header_width: number;
18
+ readonly header_height: number;
19
+ readonly row_num_width: number;
20
+ get_col_style: (index: number) => string;
21
+ } {
22
+ let col_widths: number[] = $state([]);
23
+ let total_header_width: number = $state(0);
24
+ let header_height: number = $state(0);
25
+
26
+ // use offsets (not just widths) avoids accumulated subpixel rounding errors
27
+ let col_lefts: number[] = $state([]);
28
+
29
+ function resolve_user_width(
30
+ raw: string | undefined,
31
+ vw: number
32
+ ): number | null {
33
+ if (!raw || raw === "auto") return null;
34
+ if (raw.endsWith("%")) {
35
+ const pct = parseFloat(raw);
36
+ if (!isFinite(pct) || vw <= 0) return null;
37
+ return (pct / 100) * vw;
38
+ }
39
+ if (raw.endsWith("px")) {
40
+ const n = parseFloat(raw);
41
+ return isFinite(n) ? n : null;
42
+ }
43
+ const n = parseFloat(raw);
44
+ return isFinite(n) ? n : null;
45
+ }
46
+
47
+ function clear_pin(el: HTMLElement): void {
48
+ if (el.style.width) el.style.width = "";
49
+ if (el.style.minWidth) el.style.minWidth = "";
50
+ if (el.style.maxWidth) el.style.maxWidth = "";
51
+ }
52
+
53
+ function pin(el: HTMLElement, target: string): void {
54
+ if (el.style.width !== target) el.style.width = target;
55
+ if (el.style.minWidth !== target) el.style.minWidth = target;
56
+ if (el.style.maxWidth !== target) el.style.maxWidth = target;
57
+ }
58
+
59
+ function measure(): void {
60
+ const current_row_el = opts.header_row_el();
61
+ const current_table_el = opts.header_table_el();
62
+ if (!current_row_el || !current_table_el) return;
63
+
64
+ const cells = Array.from(
65
+ current_row_el.querySelectorAll<HTMLElement>(".header-cell")
66
+ );
67
+ // sizing-body mirrors the data columns to give auto-layout a read on
68
+ // body-content widths. we also pin its cells so user widths are
69
+ // honored exactly (otherwise the sizing row's nowrap min-content
70
+ // forces the column wider than the user asked for).
71
+ const sizing_tds_all = Array.from(
72
+ current_table_el.querySelectorAll<HTMLElement>(".sizing-body > tr > td")
73
+ );
74
+ const sizing_data_tds = opts.show_row_numbers()
75
+ ? sizing_tds_all.slice(1)
76
+ : sizing_tds_all;
77
+
78
+ cells.forEach(clear_pin);
79
+ sizing_data_tds.forEach(clear_pin);
80
+ current_table_el.style.width = "auto";
81
+ current_table_el.getBoundingClientRect(); // force layout flush
82
+
83
+ const vw = opts.viewport_width();
84
+ const user_widths = opts.column_widths();
85
+
86
+ const next_widths = cells.map((cell, i) => {
87
+ const resolved = resolve_user_width(user_widths[i], vw);
88
+ if (resolved != null) return resolved;
89
+ // cap auto-sized columns at the viewport so a single column
90
+ // can never be wider than the visible scroll area
91
+ const measured = cell.getBoundingClientRect().width;
92
+ return vw > 0 ? Math.min(measured, vw) : measured;
93
+ });
94
+
95
+ cells.forEach((cell, i) => pin(cell, `${next_widths[i]}px`));
96
+ sizing_data_tds.forEach((cell, i) => {
97
+ if (next_widths[i] == null) return;
98
+ pin(cell, `${next_widths[i]}px`);
99
+ });
100
+
101
+ // set the table width to the sum of columns so auto-layout
102
+ // has no extra space to redistribute
103
+ let table_w = next_widths.reduce((a, b) => a + b, 0);
104
+ if (opts.show_row_numbers()) {
105
+ const rn =
106
+ current_row_el.querySelector<HTMLElement>(".row-number-header");
107
+ if (rn) table_w += rn.getBoundingClientRect().width;
108
+ }
109
+ current_table_el.style.width = `${table_w}px`;
110
+
111
+ const after_rect = current_table_el.getBoundingClientRect();
112
+ col_lefts = cells.map(
113
+ (c) => c.getBoundingClientRect().left - after_rect.left
114
+ );
115
+ col_widths = next_widths;
116
+ total_header_width = after_rect.width;
117
+ header_height = after_rect.height;
118
+ opts.on_resize?.();
119
+ }
120
+
121
+ $effect(() => {
122
+ const table_el = opts.header_table_el();
123
+ const row_el = opts.header_row_el();
124
+ if (!table_el || !row_el) return;
125
+
126
+ // re-run when columns change so we observe new cells
127
+ opts.resolved_headers();
128
+
129
+ const ro = new ResizeObserver(measure);
130
+ ro.observe(table_el);
131
+
132
+ // observe individual header cells so content-driven column
133
+ // width changes (editing, data updates) trigger a re-measure
134
+ // even when the overall table dimensions stay the same
135
+ const cells = row_el.querySelectorAll<HTMLElement>(".header-cell");
136
+ cells.forEach((cell) => ro.observe(cell));
137
+
138
+ return () => ro.disconnect();
139
+ });
140
+
141
+ $effect(() => {
142
+ opts.viewport_width();
143
+ opts.column_widths();
144
+ measure();
145
+ });
146
+
147
+ let row_num_width = $derived.by(() => {
148
+ if (!opts.show_row_numbers()) return 0;
149
+ const row_el = opts.header_row_el();
150
+ if (!row_el) return 0;
151
+ const el = row_el.querySelector<HTMLElement>(".row-number-header");
152
+ return el?.getBoundingClientRect().width ?? 48;
153
+ });
154
+
155
+ function get_col_style(index: number): string {
156
+ if (col_widths[index] !== undefined) {
157
+ return `width: ${col_widths[index]}px; flex: 0 0 ${col_widths[index]}px;`;
158
+ }
159
+ const resolved = resolve_user_width(
160
+ opts.column_widths()[index],
161
+ opts.viewport_width()
162
+ );
163
+ if (resolved != null) {
164
+ return `width: ${resolved}px; flex: 0 0 ${resolved}px;`;
165
+ }
166
+ return "width: 150px; flex: 0 0 150px;";
167
+ }
168
+
169
+ return {
170
+ get col_widths() {
171
+ return col_widths;
172
+ },
173
+ get col_lefts() {
174
+ return col_lefts;
175
+ },
176
+ get total_header_width() {
177
+ return total_header_width;
178
+ },
179
+ get header_height() {
180
+ return header_height;
181
+ },
182
+ get row_num_width() {
183
+ return row_num_width;
184
+ },
185
+ get_col_style
186
+ };
187
+ }
6.14.0/dataframe/shared/icons/FilterIcon.svelte ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svg viewBox="0 0 24 24" width="20" height="20">
2
+ <path
3
+ d="M5 5H19"
4
+ stroke="currentColor"
5
+ stroke-width="2"
6
+ stroke-linecap="round"
7
+ />
8
+ <path
9
+ d="M8 9H16"
10
+ stroke="currentColor"
11
+ stroke-width="2"
12
+ stroke-linecap="round"
13
+ />
14
+ <path
15
+ d="M11 13H13"
16
+ stroke="currentColor"
17
+ stroke-width="2"
18
+ stroke-linecap="round"
19
+ />
20
+ </svg>
6.14.0/dataframe/shared/icons/Padlock.svelte ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { size = 16 } = $props();
3
+ </script>
4
+
5
+ <div class="wrapper" aria-label="Static column">
6
+ <svg
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ width={size}
9
+ height={size}
10
+ viewBox="0 0 24 24"
11
+ fill="none"
12
+ stroke="currentColor"
13
+ stroke-width="2"
14
+ stroke-linecap="round"
15
+ stroke-linejoin="round"
16
+ >
17
+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
18
+ <path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
19
+ </svg>
20
+ </div>
21
+
22
+ <style>
23
+ .wrapper {
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ }
28
+ </style>
6.14.0/dataframe/shared/icons/SelectionButtons.svelte ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let {
3
+ position,
4
+ coords,
5
+ on_click = null
6
+ }: {
7
+ position: "column" | "row";
8
+ coords: [number, number];
9
+ on_click?: (() => void) | null;
10
+ } = $props();
11
+
12
+ let is_first_position = $derived(
13
+ position === "column" ? coords[0] === 0 : coords[1] === 0
14
+ );
15
+ let direction = $derived(
16
+ position === "column"
17
+ ? is_first_position
18
+ ? "down"
19
+ : "up"
20
+ : is_first_position
21
+ ? "right"
22
+ : "left"
23
+ );
24
+ </script>
25
+
26
+ <button
27
+ class="selection-button selection-button-{position} {is_first_position
28
+ ? `move-${direction}`
29
+ : ''}"
30
+ onclick={(e: MouseEvent) => {
31
+ e.stopPropagation();
32
+ on_click && on_click();
33
+ }}
34
+ aria-label={`Select ${position}`}
35
+ >
36
+ <span class={direction}>
37
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
38
+ <path
39
+ d="m16.707 13.293-4-4a1 1 0 0 0-1.414 0l-4 4A1 1 0 0 0 8 15h8a1 1 0 0 0 .707-1.707z"
40
+ data-name={direction}
41
+ />
42
+ </svg>
43
+ </span>
44
+ </button>
45
+
46
+ <style>
47
+ .selection-button {
48
+ position: absolute;
49
+ background: var(--color-accent);
50
+ width: var(--size-3);
51
+ height: var(--size-5);
52
+ color: var(--background-fill-primary);
53
+ }
54
+
55
+ .selection-button-column {
56
+ top: -15px;
57
+ left: 50%;
58
+ transform: translateX(-50%) rotate(90deg);
59
+ border-radius: var(--radius-sm) 0 0 var(--radius-sm);
60
+ }
61
+
62
+ .selection-button-row {
63
+ left: calc(var(--size-2-5) * -1);
64
+ top: 50%;
65
+ transform: translateY(-50%);
66
+ border-radius: var(--radius-sm) 0 0 var(--radius-sm);
67
+ }
68
+
69
+ .move-down {
70
+ bottom: -14px;
71
+ top: auto;
72
+ border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
73
+ }
74
+
75
+ .move-right {
76
+ left: auto;
77
+ right: calc(var(--size-2-5) * -1);
78
+ top: 50%;
79
+ transform: translateY(-50%);
80
+ border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
81
+ }
82
+
83
+ svg {
84
+ fill: currentColor;
85
+ }
86
+
87
+ span {
88
+ display: flex;
89
+ width: 100%;
90
+ height: 100%;
91
+ }
92
+
93
+ .up {
94
+ transform: rotate(-90deg);
95
+ }
96
+
97
+ .down {
98
+ transform: rotate(90deg);
99
+ }
100
+
101
+ .left {
102
+ transform: rotate(-90deg);
103
+ }
104
+
105
+ .right {
106
+ transform: rotate(90deg);
107
+ }
108
+ </style>
6.14.0/dataframe/shared/icons/SortButtonDown.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { size = 16 } = $props();
3
+ </script>
4
+
5
+ <svg
6
+ width={size}
7
+ height={size}
8
+ viewBox="0 0 16 16"
9
+ fill="none"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ >
12
+ <path
13
+ d="M4 8L8 12L12 8"
14
+ stroke="currentColor"
15
+ stroke-width="1.5"
16
+ stroke-linecap="round"
17
+ stroke-linejoin="round"
18
+ />
19
+ <path
20
+ d="M8 12V4"
21
+ stroke="currentColor"
22
+ stroke-width="1.5"
23
+ stroke-linecap="round"
24
+ />
25
+ </svg>
6.14.0/dataframe/shared/icons/SortButtonUp.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let { size = 16 } = $props();
3
+ </script>
4
+
5
+ <svg
6
+ width={size}
7
+ height={size}
8
+ viewBox="0 0 16 16"
9
+ fill="none"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ >
12
+ <path
13
+ d="M4 8L8 4L12 8"
14
+ stroke="currentColor"
15
+ stroke-width="1.5"
16
+ stroke-linecap="round"
17
+ stroke-linejoin="round"
18
+ />
19
+ <path
20
+ d="M8 4V12"
21
+ stroke="currentColor"
22
+ stroke-width="1.5"
23
+ stroke-linecap="round"
24
+ />
25
+ </svg>
6.14.0/dataframe/shared/icons/SortIcon.svelte ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { I18nFormatter } from "@gradio/utils";
3
+ import SortButtonUp from "./SortButtonUp.svelte";
4
+ import SortButtonDown from "./SortButtonDown.svelte";
5
+ import { IconButton } from "@gradio/atoms";
6
+ type SortDirection = "asc" | "desc";
7
+
8
+ let {
9
+ direction = null,
10
+ priority = null,
11
+ i18n,
12
+ onsort
13
+ }: {
14
+ direction?: SortDirection | null;
15
+ priority?: number | null;
16
+ i18n: I18nFormatter;
17
+ onsort?: (direction: SortDirection) => void;
18
+ } = $props();
19
+ </script>
20
+
21
+ <div class="sort-icons" role="group" aria-label={i18n("dataframe.sort_column")}>
22
+ {#if (direction === "asc" || direction === "desc") && priority !== null}
23
+ <span aria-label={`Sort priority: ${priority}`} class="priority"
24
+ >{priority}</span
25
+ >
26
+ {/if}
27
+ <IconButton
28
+ size="x-small"
29
+ label={i18n("dataframe.sort_ascending")}
30
+ Icon={SortButtonUp}
31
+ highlight={direction === "asc"}
32
+ onclick={(event) => {
33
+ event.stopPropagation();
34
+ onsort?.("asc");
35
+ }}
36
+ ></IconButton>
37
+ <IconButton
38
+ size="x-small"
39
+ label={i18n("dataframe.sort_descending")}
40
+ Icon={SortButtonDown}
41
+ highlight={direction === "desc"}
42
+ onclick={(event) => {
43
+ event.stopPropagation();
44
+ onsort?.("desc");
45
+ }}
46
+ ></IconButton>
47
+ </div>
48
+
49
+ <style>
50
+ .sort-icons {
51
+ display: flex;
52
+ flex-direction: column;
53
+ gap: 0;
54
+ margin-right: var(--spacing-sm);
55
+ }
56
+
57
+ .sort-icons :global(button) {
58
+ margin-bottom: var(--spacing-xs);
59
+ border: 1px solid var(--border-color-primary);
60
+ background: unset;
61
+ }
62
+
63
+ .priority {
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+ position: absolute;
68
+ font-size: var(--size-2);
69
+ left: 19px;
70
+ z-index: var(--layer-3);
71
+ top: var(--spacing-xs);
72
+ background-color: var(--button-secondary-background-fill);
73
+ color: var(--body-text-color);
74
+ border-radius: var(--radius-sm);
75
+ width: var(--size-2-5);
76
+ height: var(--size-2-5);
77
+ }
78
+ </style>
6.14.0/dataframe/shared/tanstack/index.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export { createSvelteTable } from "./table.svelte.js";
2
+
3
+ export { createSvelteVirtualizer, type VirtualItem } from "./virtual.svelte.js";
4
+
5
+ export {
6
+ createColumnHelper,
7
+ getCoreRowModel,
8
+ getSortedRowModel,
9
+ getFilteredRowModel,
10
+ type ColumnDef,
11
+ type TableOptions,
12
+ type Table,
13
+ type Header,
14
+ type Cell,
15
+ type Row,
16
+ type SortingState,
17
+ type ColumnFiltersState,
18
+ type ColumnPinningState,
19
+ type FilterFn,
20
+ type SortingFn,
21
+ type CellContext,
22
+ type HeaderContext
23
+ } from "@tanstack/table-core";
6.14.0/dataframe/shared/tanstack/table.svelte.ts ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ createTable,
3
+ type RowData,
4
+ type TableOptions,
5
+ type TableOptionsResolved,
6
+ type TableState
7
+ } from "@tanstack/table-core";
8
+
9
+ /**
10
+ * Merges objects while preserving property getters for lazy evaluation.
11
+ * Properties are defined as getters that look up values from sources in
12
+ * reverse order at access time. This is critical: it means reading a
13
+ * property from the merged result doesn't happen until the property is
14
+ * actually accessed, not when mergeObjects is called.
15
+ */
16
+ export function mergeObjects(...sources: any): any {
17
+ const target: Record<string, any> = {};
18
+ for (let i = 0; i < sources.length; i++) {
19
+ let source = sources[i];
20
+ if (typeof source === "function") source = source();
21
+ if (source) {
22
+ const descriptors = Object.getOwnPropertyDescriptors(source);
23
+ for (const key in descriptors) {
24
+ if (key in target) continue;
25
+ Object.defineProperty(target, key, {
26
+ enumerable: true,
27
+ get() {
28
+ for (let j = sources.length - 1; j >= 0; j--) {
29
+ let s = sources[j];
30
+ if (typeof s === "function") s = s();
31
+ const v = (s || {})[key];
32
+ if (v !== undefined) return v;
33
+ }
34
+ }
35
+ });
36
+ }
37
+ }
38
+ }
39
+ return target;
40
+ }
41
+
42
+ /**
43
+ * Creates a reactive TanStack Table for Svelte 5.
44
+ *
45
+ * The reactivity works through mergeObjects' lazy getters:
46
+ * - $effect.pre calls table.setOptions() with a merged object
47
+ * - The merged object has lazy getters for `data`, `columns`, `state`, etc.
48
+ * - TanStack stores this object but doesn't deep-read all properties immediately
49
+ * - When getRowModel() is called (in $derived), TanStack reads `data` and `columns`
50
+ * through the lazy getters, which read the reactive $state/$derived values
51
+ * - onStateChange fires when TanStack mutates its own state → bumps version
52
+ * - version is read by getRowModel/getHeaderGroups → $derived re-evaluates
53
+ */
54
+ export function createSvelteTable<TData extends RowData>(
55
+ options: TableOptions<TData>
56
+ ) {
57
+ const resolvedOptions: TableOptionsResolved<TData> = mergeObjects(
58
+ {
59
+ state: {},
60
+ onStateChange() {},
61
+ renderFallbackValue: null,
62
+ mergeOptions: (
63
+ defaultOptions: TableOptions<TData>,
64
+ opts: Partial<TableOptions<TData>>
65
+ ) => {
66
+ return mergeObjects(defaultOptions, opts);
67
+ }
68
+ },
69
+ options
70
+ );
71
+
72
+ const table = createTable(resolvedOptions);
73
+ let state = $state<Partial<TableState>>(table.initialState);
74
+ let version = $state(0);
75
+
76
+ function updateOptions(): void {
77
+ table.setOptions((prev) => {
78
+ // mergeObjects creates lazy getters — `state` is NOT read here,
79
+ // only when TanStack accesses the `state` property later.
80
+ return mergeObjects(prev, options, {
81
+ state: mergeObjects(state, options.state || {}),
82
+ onStateChange: (updater: any) => {
83
+ if (updater instanceof Function) state = updater(state);
84
+ else state = mergeObjects(state, updater);
85
+ version += 1;
86
+ options.onStateChange?.(updater);
87
+ }
88
+ });
89
+ });
90
+ }
91
+
92
+ // Initial sync
93
+ updateOptions();
94
+
95
+ // Re-sync when options change. Because mergeObjects uses lazy getters,
96
+ // this effect's tracked dependencies are only the properties that
97
+ // table.setOptions() eagerly reads (which is minimal — mostly just
98
+ // checking if the options object reference changed).
99
+ $effect.pre(() => {
100
+ updateOptions();
101
+ });
102
+
103
+ return {
104
+ getRowModel: () => {
105
+ void version;
106
+ return table.getRowModel();
107
+ },
108
+ getHeaderGroups: () => {
109
+ void version;
110
+ return table.getHeaderGroups();
111
+ },
112
+ getColumn: (id: string) => {
113
+ void version;
114
+ return table.getColumn(id);
115
+ }
116
+ };
117
+ }
6.14.0/dataframe/shared/tanstack/virtual.svelte.ts ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Virtualizer,
3
+ elementScroll,
4
+ observeElementOffset,
5
+ observeElementRect,
6
+ type PartialKeys,
7
+ type VirtualizerOptions
8
+ } from "@tanstack/virtual-core";
9
+ import { untrack } from "svelte";
10
+
11
+ export type { VirtualItem } from "@tanstack/virtual-core";
12
+
13
+ /**
14
+ * Creates a reactive TanStack Virtualizer for Svelte 5.
15
+ *
16
+ * Returns a getter function that returns the virtualizer instance.
17
+ * Call the getter inside $derived or template expressions to create
18
+ * reactive dependencies on the virtualizer state.
19
+ */
20
+ export function createSvelteVirtualizer<
21
+ TScrollElement extends Element,
22
+ TItemElement extends Element
23
+ >(
24
+ options: PartialKeys<
25
+ VirtualizerOptions<TScrollElement, TItemElement>,
26
+ "observeElementRect" | "observeElementOffset" | "scrollToFn"
27
+ >
28
+ ): {
29
+ instance: Virtualizer<TScrollElement, TItemElement>;
30
+ virtualItems: () => ReturnType<
31
+ Virtualizer<TScrollElement, TItemElement>["getVirtualItems"]
32
+ >;
33
+ totalSize: () => number;
34
+ } {
35
+ let version = $state(0);
36
+
37
+ const virtualizer = new Virtualizer<TScrollElement, TItemElement>({
38
+ observeElementRect: observeElementRect,
39
+ observeElementOffset: observeElementOffset,
40
+ scrollToFn: elementScroll,
41
+ ...options,
42
+ onChange: (instance, sync) => {
43
+ if (sync) {
44
+ version += 1;
45
+ } else {
46
+ queueMicrotask(() => {
47
+ version += 1;
48
+ });
49
+ }
50
+ options.onChange?.(instance, sync);
51
+ }
52
+ });
53
+
54
+ $effect(() => {
55
+ const cleanup = virtualizer._didMount();
56
+ untrack(() => {
57
+ version += 1;
58
+ });
59
+ return cleanup;
60
+ });
61
+
62
+ let prev_count = 0;
63
+
64
+ $effect(() => {
65
+ const current_count = options.count;
66
+ virtualizer.setOptions({
67
+ observeElementRect: observeElementRect,
68
+ observeElementOffset: observeElementOffset,
69
+ scrollToFn: elementScroll,
70
+ ...options,
71
+ onChange: (instance, sync) => {
72
+ if (sync) {
73
+ version += 1;
74
+ } else {
75
+ queueMicrotask(() => {
76
+ version += 1;
77
+ });
78
+ }
79
+ options.onChange?.(instance, sync);
80
+ }
81
+ });
82
+
83
+ if (prev_count === 0 && current_count > 0) {
84
+ virtualizer.measure();
85
+ }
86
+ prev_count = current_count;
87
+ });
88
+
89
+ $effect.pre(() => {
90
+ void version;
91
+ virtualizer._willUpdate();
92
+ });
93
+
94
+ return {
95
+ instance: virtualizer,
96
+ virtualItems: () => {
97
+ void version;
98
+ return virtualizer.getVirtualItems();
99
+ },
100
+ totalSize: () => {
101
+ void version;
102
+ return virtualizer.getTotalSize();
103
+ }
104
+ };
105
+ }
6.14.0/dataframe/shared/types.ts ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type CellCoordinate = [number, number];
2
+ export type EditingState = CellCoordinate | false;
3
+
4
+ export type Headers = (string | null)[];
5
+
6
+ export interface HeadersWithIDs {
7
+ id: string;
8
+ value: string;
9
+ }
10
+ [];
11
+
12
+ export type CellValue = string | number | boolean;
13
+
14
+ export interface TableCell {
15
+ id: string;
16
+ value: CellValue;
17
+ }
18
+
19
+ export type TableData = TableCell[][];
20
+
21
+ export type CountConfig = [number, "fixed" | "dynamic"];
22
+
23
+ export type ElementRefs = Record<
24
+ string,
25
+ {
26
+ cell: null | HTMLTableCellElement;
27
+ input: null | HTMLTextAreaElement;
28
+ }
29
+ >;
30
+
31
+ export type DataBinding = Record<string, TableCell>;
32
+
33
+ export type SortDirection = "asc" | "desc";
34
+ export type FilterDatatype = "string" | "number";
6.14.0/dataframe/shared/utils/filter.ts ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom filter function for TanStack Table that handles Gradio's
3
+ * { dtype, filter, value } column filter format.
4
+ */
5
+ export function gradio_filter_fn(
6
+ row: any,
7
+ columnId: string,
8
+ filterValue: any
9
+ ): boolean {
10
+ const { dtype, filter, value: fval } = filterValue;
11
+ const cell_value = String(row.getValue(columnId) ?? "");
12
+ const compare_val = fval ?? "";
13
+
14
+ if (dtype === "number") {
15
+ const num = parseFloat(cell_value);
16
+ const target = parseFloat(compare_val);
17
+ if (isNaN(num) || isNaN(target)) {
18
+ if (filter === "Is empty") return cell_value.trim() === "";
19
+ if (filter === "Is not empty") return cell_value.trim() !== "";
20
+ return true;
21
+ }
22
+ switch (filter) {
23
+ case "=":
24
+ return num === target;
25
+ case "≠":
26
+ return num !== target;
27
+ case ">":
28
+ return num > target;
29
+ case "<":
30
+ return num < target;
31
+ case "≥":
32
+ return num >= target;
33
+ case "≤":
34
+ return num <= target;
35
+ case "Is empty":
36
+ return cell_value.trim() === "";
37
+ case "Is not empty":
38
+ return cell_value.trim() !== "";
39
+ default:
40
+ return true;
41
+ }
42
+ }
43
+
44
+ const lower = cell_value.toLowerCase();
45
+ const target_lower = compare_val.toLowerCase();
46
+ switch (filter) {
47
+ case "Contains":
48
+ return lower.includes(target_lower);
49
+ case "Does not contain":
50
+ return !lower.includes(target_lower);
51
+ case "Starts with":
52
+ return lower.startsWith(target_lower);
53
+ case "Ends with":
54
+ return lower.endsWith(target_lower);
55
+ case "Is":
56
+ return lower === target_lower;
57
+ case "Is not":
58
+ return lower !== target_lower;
59
+ case "Is empty":
60
+ return cell_value.trim() === "";
61
+ case "Is not empty":
62
+ return cell_value.trim() !== "";
63
+ default:
64
+ return true;
65
+ }
66
+ }
6.14.0/dataframe/shared/utils/selection_utils.ts ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { CellCoordinate, CellValue } from "./../types";
2
+
3
+ export type CellData = { id: string; value: CellValue };
4
+
5
+ export function is_cell_in_selection(
6
+ coords: [number, number],
7
+ selected_cells: [number, number][]
8
+ ): boolean {
9
+ const [row, col] = coords;
10
+ return selected_cells.some(([r, c]) => r === row && c === col);
11
+ }
12
+
13
+ export function is_cell_selected(
14
+ cell: CellCoordinate,
15
+ selected_cells: CellCoordinate[]
16
+ ): string {
17
+ const [row, col] = cell;
18
+ if (!selected_cells.some(([r, c]) => r === row && c === col)) return "";
19
+
20
+ const up = selected_cells.some(([r, c]) => r === row - 1 && c === col);
21
+ const down = selected_cells.some(([r, c]) => r === row + 1 && c === col);
22
+ const left = selected_cells.some(([r, c]) => r === row && c === col - 1);
23
+ const right = selected_cells.some(([r, c]) => r === row && c === col + 1);
24
+
25
+ return `cell-selected${up ? " no-top" : ""}${down ? " no-bottom" : ""}${left ? " no-left" : ""}${right ? " no-right" : ""}`;
26
+ }
27
+
28
+ export function get_range_selection(
29
+ start: CellCoordinate,
30
+ end: CellCoordinate
31
+ ): CellCoordinate[] {
32
+ const [start_row, start_col] = start;
33
+ const [end_row, end_col] = end;
34
+ const min_row = Math.min(start_row, end_row);
35
+ const max_row = Math.max(start_row, end_row);
36
+ const min_col = Math.min(start_col, end_col);
37
+ const max_col = Math.max(start_col, end_col);
38
+
39
+ const cells: CellCoordinate[] = [];
40
+ // add the start cell as the "anchor" cell so that when
41
+ // we press shift+arrow keys, the selection will always
42
+ // include the anchor cell.
43
+ cells.push(start);
44
+
45
+ for (let i = min_row; i <= max_row; i++) {
46
+ for (let j = min_col; j <= max_col; j++) {
47
+ if (i === start_row && j === start_col) continue;
48
+ cells.push([i, j]);
49
+ }
50
+ }
51
+ return cells;
52
+ }
53
+
54
+ export function handle_selection(
55
+ current: CellCoordinate,
56
+ selected_cells: CellCoordinate[],
57
+ event: { shiftKey: boolean; metaKey: boolean; ctrlKey: boolean }
58
+ ): CellCoordinate[] {
59
+ if (event.shiftKey && selected_cells.length > 0) {
60
+ return get_range_selection(
61
+ selected_cells[selected_cells.length - 1],
62
+ current
63
+ );
64
+ }
65
+
66
+ if (event.metaKey || event.ctrlKey) {
67
+ const is_cell_match = ([r, c]: CellCoordinate): boolean =>
68
+ r === current[0] && c === current[1];
69
+ const index = selected_cells.findIndex(is_cell_match);
70
+ return index === -1
71
+ ? [...selected_cells, current]
72
+ : selected_cells.filter((_, i) => i !== index);
73
+ }
74
+
75
+ return [current];
76
+ }
77
+
78
+ export function handle_delete_key(
79
+ data: CellData[][],
80
+ selected_cells: CellCoordinate[]
81
+ ): CellData[][] {
82
+ const new_data = data.map((row) => [...row]);
83
+ selected_cells.forEach(([row, col]) => {
84
+ if (new_data[row] && new_data[row][col]) {
85
+ new_data[row][col] = { ...new_data[row][col], value: "" };
86
+ }
87
+ });
88
+ return new_data;
89
+ }
90
+
91
+ export function should_show_cell_menu(
92
+ cell: CellCoordinate,
93
+ selected_cells: CellCoordinate[],
94
+ editable: boolean
95
+ ): boolean {
96
+ const [row, col] = cell;
97
+ return (
98
+ editable &&
99
+ selected_cells.length === 1 &&
100
+ selected_cells[0][0] === row &&
101
+ selected_cells[0][1] === col
102
+ );
103
+ }
104
+
105
+ export function get_next_cell_coordinates(
106
+ current: CellCoordinate,
107
+ data: CellData[][],
108
+ shift_key: boolean
109
+ ): CellCoordinate | false {
110
+ const [row, col] = current;
111
+ const direction = shift_key ? -1 : 1;
112
+
113
+ if (data[row]?.[col + direction]) {
114
+ return [row, col + direction];
115
+ }
116
+
117
+ const next_row = row + (direction > 0 ? 1 : 0);
118
+ const prev_row = row + (direction < 0 ? -1 : 0);
119
+
120
+ if (direction > 0 && data[next_row]?.[0]) {
121
+ return [next_row, 0];
122
+ }
123
+
124
+ if (direction < 0 && data[prev_row]?.[data[0].length - 1]) {
125
+ return [prev_row, data[0].length - 1];
126
+ }
127
+
128
+ return false;
129
+ }
130
+
131
+ export function move_cursor(
132
+ event: KeyboardEvent,
133
+ current_coords: CellCoordinate,
134
+ data: CellData[][]
135
+ ): CellCoordinate | false {
136
+ const key = event.key as "ArrowRight" | "ArrowLeft" | "ArrowDown" | "ArrowUp";
137
+ const dir = {
138
+ ArrowRight: [0, 1],
139
+ ArrowLeft: [0, -1],
140
+ ArrowDown: [1, 0],
141
+ ArrowUp: [-1, 0]
142
+ }[key];
143
+
144
+ let i, j;
145
+ if (event.metaKey || event.ctrlKey) {
146
+ if (key === "ArrowRight") {
147
+ i = current_coords[0];
148
+ j = data[0].length - 1;
149
+ } else if (key === "ArrowLeft") {
150
+ i = current_coords[0];
151
+ j = 0;
152
+ } else if (key === "ArrowDown") {
153
+ i = data.length - 1;
154
+ j = current_coords[1];
155
+ } else if (key === "ArrowUp") {
156
+ i = 0;
157
+ j = current_coords[1];
158
+ } else {
159
+ return false;
160
+ }
161
+ } else {
162
+ i = current_coords[0] + dir[0];
163
+ j = current_coords[1] + dir[1];
164
+ }
165
+
166
+ if (i < 0 && j <= 0) {
167
+ return false;
168
+ }
169
+
170
+ const is_data = data[i]?.[j];
171
+ if (is_data) {
172
+ return [i, j];
173
+ }
174
+ return false;
175
+ }
176
+
177
+ export function get_current_indices(
178
+ id: string,
179
+ data: CellData[][]
180
+ ): [number, number] {
181
+ return data.reduce(
182
+ (acc, arr, i) => {
183
+ const j = arr.reduce(
184
+ (_acc, _data, k) => (id === _data.id ? k : _acc),
185
+ -1
186
+ );
187
+ return j === -1 ? acc : [i, j];
188
+ },
189
+ [-1, -1]
190
+ );
191
+ }
192
+
193
+ export function handle_click_outside(
194
+ event: Event,
195
+ parent: HTMLElement
196
+ ): boolean {
197
+ const [trigger] = event.composedPath() as HTMLElement[];
198
+ return !parent.contains(trigger);
199
+ }
200
+
201
+ export function select_column(data: any[][], col: number): CellCoordinate[] {
202
+ return Array.from({ length: data.length }, (_, i) => [i, col]);
203
+ }
204
+
205
+ export function select_row(data: any[][], row: number): CellCoordinate[] {
206
+ return Array.from({ length: data[0].length }, (_, i) => [row, i]);
207
+ }
208
+
209
+ export function calculate_selection_positions(
210
+ selected: CellCoordinate,
211
+ data: { id: string; value: CellValue }[][],
212
+ els: Record<string, { cell: HTMLTableCellElement | null }>,
213
+ parent: HTMLElement,
214
+ table: HTMLElement
215
+ ): { col_pos: string; row_pos: string | undefined } {
216
+ const [row, col] = selected;
217
+ if (!data[row]?.[col]) {
218
+ return { col_pos: "0px", row_pos: undefined };
219
+ }
220
+
221
+ const cell_id = data[row][col].id;
222
+ const cell_el = els[cell_id]?.cell;
223
+
224
+ if (!cell_el) {
225
+ return { col_pos: "0px", row_pos: undefined };
226
+ }
227
+
228
+ const cell_rect = cell_el.getBoundingClientRect();
229
+ const table_rect = table.getBoundingClientRect();
230
+ const col_pos = `${cell_rect.left - table_rect.left + cell_rect.width / 2}px`;
231
+ const row_pos = `${cell_rect.top - table_rect.top + cell_rect.height / 2}px`;
232
+
233
+ return { col_pos, row_pos };
234
+ }
6.14.0/dataframe/shared/utils/table_utils.ts ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { CellValue, Headers, HeadersWithIDs, TableData } from "../types";
2
+ import { dsvFormat } from "d3-dsv";
3
+
4
+ export function make_cell_id(row: number, col: number): string {
5
+ return `cell-${row}-${col}`;
6
+ }
7
+
8
+ export function make_header_id(col: number): string {
9
+ return `header-${col}`;
10
+ }
11
+
12
+ export async function copy_table_data(
13
+ data: TableData,
14
+ selected_cells: [number, number][] | null
15
+ ): Promise<void> {
16
+ if (!data || !data.length) return;
17
+
18
+ const cells_to_copy =
19
+ selected_cells ||
20
+ data.flatMap((row, r) => row.map((_, c) => [r, c] as [number, number]));
21
+
22
+ const csv = cells_to_copy.reduce(
23
+ (acc: { [key: string]: { [key: string]: string } }, [row, col]) => {
24
+ acc[row] = acc[row] || {};
25
+ const value = String(data[row][col].value);
26
+ acc[row][col] =
27
+ value.includes(",") || value.includes('"') || value.includes("\n")
28
+ ? `"${value.replace(/"/g, '""')}"`
29
+ : value;
30
+ return acc;
31
+ },
32
+ {}
33
+ );
34
+
35
+ const rows = Object.keys(csv).sort((a, b) => +a - +b);
36
+ if (!rows.length) return;
37
+
38
+ const cols = Object.keys(csv[rows[0]]).sort((a, b) => +a - +b);
39
+ const text = rows
40
+ .map((r) => cols.map((c) => csv[r][c] || "").join(","))
41
+ .join("\n");
42
+
43
+ try {
44
+ await navigator.clipboard.writeText(text);
45
+ } catch (err) {
46
+ throw new Error("Failed to copy to clipboard: " + (err as Error).message);
47
+ }
48
+ }
49
+
50
+ export function guess_delimiter(
51
+ text: string,
52
+ possibleDelimiters: string[]
53
+ ): string[] {
54
+ return possibleDelimiters.filter(weedOut);
55
+
56
+ function weedOut(delimiter: string): boolean {
57
+ var cache = -1;
58
+ return text.split("\n").every(checkLength);
59
+
60
+ function checkLength(line: string): boolean {
61
+ if (!line) return true;
62
+ var length = line.split(delimiter).length;
63
+ if (cache < 0) cache = length;
64
+ return cache === length && length > 1;
65
+ }
66
+ }
67
+ }
68
+
69
+ export function data_uri_to_blob(data_uri: string): Blob {
70
+ const byte_str = atob(data_uri.split(",")[1]);
71
+ const mime_str = data_uri.split(",")[0].split(":")[1].split(";")[0];
72
+ const ab = new ArrayBuffer(byte_str.length);
73
+ const ia = new Uint8Array(ab);
74
+ for (let i = 0; i < byte_str.length; i++) {
75
+ ia[i] = byte_str.charCodeAt(i);
76
+ }
77
+ return new Blob([ab], { type: mime_str });
78
+ }
79
+
80
+ export function handle_file_upload(
81
+ data_uri: string,
82
+ update_headers: (headers: Headers) => HeadersWithIDs[],
83
+ update_values: (values: CellValue[][]) => void
84
+ ): void {
85
+ const blob = data_uri_to_blob(data_uri);
86
+ const reader = new FileReader();
87
+ reader.addEventListener("loadend", (e) => {
88
+ if (!e?.target?.result || typeof e.target.result !== "string") return;
89
+ const [delimiter] = guess_delimiter(e.target.result, [",", "\t"]);
90
+ const [head, ...rest] = dsvFormat(delimiter).parseRows(e.target.result);
91
+ update_headers(head);
92
+ update_values(rest);
93
+ });
94
+ reader.readAsText(blob);
95
+ }
6.14.0/dataframe/shared/utils/utils.ts ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { CellValue } from "../types";
2
+
3
+ export type Headers = string[];
4
+ export type Data = CellValue[][];
5
+
6
+ export type Datatype =
7
+ | "str"
8
+ | "number"
9
+ | "bool"
10
+ | "date"
11
+ | "markdown"
12
+ | "html"
13
+ | "image";
14
+
15
+ export type Metadata = {
16
+ [key: string]: string[][] | null;
17
+ } | null;
18
+ export type HeadersWithIDs = { value: string; id: string }[];
19
+ export type DataframeValue = {
20
+ data: Data;
21
+ headers: Headers;
22
+ metadata?: Metadata;
23
+ };
24
+
25
+ /**
26
+ * Coerce a value to a given type.
27
+ * @param v - The value to coerce.
28
+ * @param t - The type to coerce to.
29
+ * @returns The coerced value.
30
+ */
31
+ export function cast_value_to_type(v: any, t: Datatype): CellValue {
32
+ if (v === null || v === undefined) {
33
+ return v;
34
+ }
35
+ if (t === "number") {
36
+ const n = Number(v);
37
+ return isNaN(n) ? v : n;
38
+ }
39
+ if (t === "bool") {
40
+ if (typeof v === "boolean") return v;
41
+ if (typeof v === "number") return v !== 0;
42
+ const s = String(v).toLowerCase();
43
+ if (s === "true" || s === "1") return true;
44
+ if (s === "false" || s === "0") return false;
45
+ return v;
46
+ }
47
+ if (t === "date") {
48
+ const d = new Date(v);
49
+ return isNaN(d.getTime()) ? v : d.toISOString();
50
+ }
51
+ return v;
52
+ }
53
+
54
+ export interface EditData {
55
+ index: number | [number, number];
56
+ value: string;
57
+ previous_value: string;
58
+ }
6.14.0/dataframe/standalone/Index.svelte ADDED
@@ -0,0 +1,741 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import Table from "../shared/Table.svelte";
4
+ import type { Datatype, DataframeValue } from "../shared/utils/utils";
5
+ import type { I18nFormatter } from "@gradio/utils";
6
+ import { default_i18n } from "./default_i18n";
7
+
8
+ let {
9
+ i18n = undefined,
10
+ value = $bindable({
11
+ data: [["", "", ""]],
12
+ headers: ["1", "2", "3"],
13
+ metadata: null
14
+ }),
15
+ datatype = "str",
16
+ interactive = true,
17
+ show_row_numbers = false,
18
+ max_height = 500,
19
+ show_search = "none",
20
+ wrap = false,
21
+ line_breaks = true,
22
+ column_widths = [],
23
+ max_chars = undefined,
24
+ pinned_columns = 0,
25
+ static_columns = [],
26
+ fullscreen = $bindable(false),
27
+ label = null,
28
+ show_label = true,
29
+ latex_delimiters = [],
30
+ col_count = undefined,
31
+ row_count = undefined
32
+ }: {
33
+ i18n?: I18nFormatter | undefined;
34
+ value?: DataframeValue;
35
+ datatype?: Datatype | Datatype[];
36
+ interactive?: boolean;
37
+ show_row_numbers?: boolean;
38
+ max_height?: number;
39
+ show_search?: "none" | "search" | "filter";
40
+ wrap?: boolean;
41
+ line_breaks?: boolean;
42
+ column_widths?: string[];
43
+ max_chars?: number | undefined;
44
+ pinned_columns?: number;
45
+ static_columns?: (string | number)[];
46
+ fullscreen?: boolean;
47
+ label?: string | null;
48
+ show_label?: boolean;
49
+ latex_delimiters?: any[];
50
+ col_count?: [number, "fixed" | "dynamic"] | undefined;
51
+ row_count?: [number, "fixed" | "dynamic"] | undefined;
52
+ } = $props();
53
+
54
+ const i18n_fn = (key: string | null | undefined): string => {
55
+ if (!key) return "";
56
+ if (typeof i18n === "function") return (i18n as any)(key);
57
+ if (i18n && typeof i18n === "object")
58
+ return (i18n as any)[key] ?? default_i18n[key] ?? key;
59
+ return default_i18n[key] ?? key;
60
+ };
61
+
62
+ let resolved_row_count = $derived.by(() => {
63
+ if (
64
+ row_count &&
65
+ Array.isArray(row_count) &&
66
+ row_count.length === 2 &&
67
+ typeof row_count[0] === "number" &&
68
+ (row_count[1] === "fixed" || row_count[1] === "dynamic")
69
+ ) {
70
+ return row_count as [number, "fixed" | "dynamic"];
71
+ }
72
+ return [1, "dynamic"] as [number, "fixed" | "dynamic"];
73
+ });
74
+
75
+ let resolved_col_count_base = $derived.by(() => {
76
+ if (
77
+ col_count &&
78
+ Array.isArray(col_count) &&
79
+ col_count.length === 2 &&
80
+ typeof col_count[0] === "number" &&
81
+ (col_count[1] === "fixed" || col_count[1] === "dynamic")
82
+ ) {
83
+ return col_count as [number, "fixed" | "dynamic"];
84
+ }
85
+ const headerLength =
86
+ value && value.headers && typeof value.headers.length === "number"
87
+ ? value.headers.length
88
+ : 3;
89
+ return [headerLength, "dynamic"] as [number, "fixed" | "dynamic"];
90
+ });
91
+
92
+ let resolved_col_count = $derived.by(() => {
93
+ if (
94
+ static_columns &&
95
+ static_columns.length > 0 &&
96
+ resolved_col_count_base[1] !== "fixed"
97
+ ) {
98
+ return [resolved_col_count_base[0], "fixed"] as [
99
+ number,
100
+ "fixed" | "dynamic"
101
+ ];
102
+ }
103
+ return resolved_col_count_base;
104
+ });
105
+
106
+ let root = "";
107
+
108
+ onMount(() => {
109
+ const handler = (e: KeyboardEvent): void => {
110
+ if (e.key === "Escape") {
111
+ fullscreen = false;
112
+ }
113
+ };
114
+ window.addEventListener("keydown", handler);
115
+ return () => window.removeEventListener("keydown", handler);
116
+ });
117
+ </script>
118
+
119
+ <div class="gradio-dataframe-standalone" class:fullscreen>
120
+ <Table
121
+ values={value.data}
122
+ headers={value.headers}
123
+ display_value={value?.metadata?.display_value ?? null}
124
+ styling={value?.metadata?.styling ?? null}
125
+ {datatype}
126
+ editable={interactive}
127
+ {show_row_numbers}
128
+ {max_height}
129
+ {show_search}
130
+ buttons={null}
131
+ {wrap}
132
+ {line_breaks}
133
+ {column_widths}
134
+ {max_chars}
135
+ {pinned_columns}
136
+ {static_columns}
137
+ {fullscreen}
138
+ {label}
139
+ {show_label}
140
+ {latex_delimiters}
141
+ col_count={resolved_col_count}
142
+ row_count={resolved_row_count}
143
+ {root}
144
+ i18n={i18n_fn}
145
+ onchange={(detail) => {
146
+ value.data = detail.data;
147
+ value.headers = detail.headers;
148
+ }}
149
+ onfullscreen={() => (fullscreen = !fullscreen)}
150
+ upload={async () => null}
151
+ stream_handler={() => new EventSource("about:blank")}
152
+ />
153
+ </div>
154
+
155
+ <style>
156
+ .gradio-dataframe-standalone {
157
+ --gr-df-font-mono: unset;
158
+ --gr-df-font-sans: unset;
159
+ --gr-df-table-bg-even: unset;
160
+ --gr-df-table-bg-odd: unset;
161
+ --gr-df-table-border: unset;
162
+ --gr-df-table-radius: unset;
163
+
164
+ --gr-df-table-text: unset;
165
+ --gr-df-accent: unset;
166
+ --gr-df-accent-soft: unset;
167
+
168
+ --gr-df-input-background-fill: unset;
169
+ --gr-df-input-background-fill-focus: unset;
170
+ --gr-df-input-background-fill-hover: unset;
171
+ --gr-df-input-border-color: unset;
172
+ --gr-df-input-border-color-focus: unset;
173
+ --gr-df-input-placeholder-color: unset;
174
+ --gr-df-input-radius: unset;
175
+ --gr-df-input-text-size: unset;
176
+ --gr-df-copied-cell-color: unset;
177
+
178
+ --gr-df-checkbox-border-color: unset;
179
+ --gr-df-checkbox-background-color: unset;
180
+ --gr-df-checkbox-border-color-focus: unset;
181
+ --gr-df-checkbox-shadow: unset;
182
+ --gr-df-checkbox-border-radius: unset;
183
+
184
+ /* Dataframe-scoped defaults (only used as fallbacks) */
185
+ --df-font-mono: var(
186
+ --gr-df-font-mono,
187
+ "IBM Plex Mono",
188
+ ui-monospace,
189
+ Consolas,
190
+ monospace
191
+ );
192
+ --df-font-sans: var(
193
+ --gr-df-font-sans,
194
+ "Source Sans Pro",
195
+ ui-sans-serif,
196
+ system-ui,
197
+ sans-serif
198
+ );
199
+ --df-table-radius: var(--df-radius-sm, 4px);
200
+ --df-border-color-primary: var(--gr-df-table-border, var(--df-neutral-200));
201
+ --df-background-fill-primary: #ffffff;
202
+ --df-background-fill-secondary: #f8fafc;
203
+ --df-color-accent: #7c3aed;
204
+ --df-color-accent-soft: #f3e8ff;
205
+ --df-color-accent-copied: #faf5ff;
206
+ --df-body-text-color: #111827;
207
+ --df-block-background-fill: #ffffff;
208
+ --df-block-radius: var(--df-radius-sm, 4px);
209
+ --df-table-even-background-fill: #ffffff;
210
+ --df-table-odd-background-fill: #f9fafb;
211
+
212
+ --df-background-fill-primary-dark: var(--df-neutral-950, #0f0f11);
213
+ --df-background-fill-secondary-dark: var(--df-neutral-900, #18181b);
214
+ --df-body-text-color-dark: var(--df-neutral-100, #f4f4f5);
215
+ --df-block-background-fill-dark: var(--df-neutral-800, #27272a);
216
+ --df-table-even-background-fill-dark: var(--df-neutral-950, #0f0f11);
217
+ --df-table-odd-background-fill-dark: var(--df-neutral-900, #18181b);
218
+ --df-border-color-primary-dark: var(--df-neutral-700, #3f3f46);
219
+ --df-color-accent-dark: var(--df-primary-600, #ea580c);
220
+ --df-color-accent-soft-dark: var(--df-neutral-700, #3f3f46);
221
+ --df-radius-sm: 4px;
222
+ --df-size-1: 4px;
223
+ --df-size-2: 8px;
224
+ --df-size-4: 16px;
225
+ --df-size-6: 24px;
226
+ --df-size-8: 32px;
227
+ --df-size-12: 48px;
228
+ --df-size-3: 12px;
229
+ --df-size-5: 20px;
230
+ --df-size-7: 28px;
231
+ --df-size-9: 36px;
232
+ --df-size-10: 40px;
233
+ --df-size-11: 44px;
234
+ --df-size-14: 56px;
235
+ --df-size-px: 1px;
236
+ --df-size-full: 100%;
237
+ --df-text-sm: 12px;
238
+ --df-size-0-5: 2px;
239
+ --df-size-1-5: 6px;
240
+ --df-size-2-5: 10px;
241
+ --df-text-md: 14px;
242
+ --df-text-lg: 16px;
243
+ --df-radius-100: 100%;
244
+ --df-radius-xs: 2px;
245
+ --df-radius-sm: 4px;
246
+ --df-radius-md: 6px;
247
+ --df-radius-lg: 8px;
248
+ --df-radius-xl: 12px;
249
+ --df-radius-2xl: 16px;
250
+ --df-radius-3xl: 22px;
251
+ --df-input-text-size: var(--df-text-md, 14px);
252
+
253
+ --df-primary-50: #fff7ed;
254
+ --df-primary-100: #ffedd5;
255
+ --df-primary-200: #fed7aa;
256
+ --df-primary-300: #fdba74;
257
+ --df-primary-400: #fb923c;
258
+ --df-primary-500: #f97316;
259
+ --df-primary-600: #ea580c;
260
+
261
+ --df-neutral-50: #fafafa;
262
+ --df-neutral-100: #f4f4f5;
263
+ --df-neutral-200: #e4e4e7;
264
+ --df-neutral-300: #d4d4d8;
265
+ --df-neutral-400: #bbbbc2;
266
+ --df-neutral-500: #71717a;
267
+ --df-neutral-600: #52525b;
268
+ --df-neutral-700: #3f3f46;
269
+ --df-neutral-800: #27272a;
270
+ --df-neutral-900: #18181b;
271
+ --df-neutral-950: #0f0f11;
272
+
273
+ /* Secondary palette (scoped) */
274
+ --df-secondary-50: #eff6ff;
275
+ --df-secondary-100: #dbeafe;
276
+ --df-secondary-200: #bfdbfe;
277
+ --df-secondary-300: #93c5fd;
278
+ --df-secondary-400: #60a5fa;
279
+ --df-secondary-500: #3b82f6;
280
+
281
+ --neutral-50: var(--df-neutral-50, #f9fafb);
282
+ --neutral-100: var(--df-neutral-100, #f3f4f6);
283
+ --neutral-200: var(--df-neutral-200, #e5e7eb);
284
+ --neutral-300: var(--df-neutral-300, #d1d5db);
285
+ --neutral-400: var(--df-neutral-400, #9ca3af);
286
+ --neutral-500: var(--df-neutral-500, #6b7280);
287
+ --neutral-600: var(--df-neutral-600, #4b5563);
288
+ --neutral-700: var(--df-neutral-700, #374151);
289
+ --neutral-800: var(--df-neutral-800, #1f2937);
290
+ --neutral-900: var(--df-neutral-900, #111827);
291
+ --neutral-950: var(--df-neutral-950, #0b0f19);
292
+
293
+ --secondary-50: var(--df-secondary-50, #eff6ff);
294
+ --secondary-100: var(--df-secondary-100, #dbeafe);
295
+ --secondary-200: var(--df-secondary-200, #bfdbfe);
296
+
297
+ --df-spacing-xxs: 1px;
298
+ --df-spacing-xs: 2px;
299
+ --df-spacing-sm: 4px;
300
+ --df-spacing-md: 6px;
301
+ --df-spacing-lg: 8px;
302
+ --df-spacing-xl: 10px;
303
+ --df-spacing-xxl: 16px;
304
+
305
+ --df-radius-xxs: 1px;
306
+ --df-radius-xxl: 22px;
307
+
308
+ --df-text-xxs: 9px;
309
+ --df-text-xs: 10px;
310
+ --df-text-xl: 22px;
311
+ --df-text-xxl: 26px;
312
+
313
+ --df-body-background-fill: var(
314
+ --df-background-fill-primary,
315
+ var(--background-fill-primary, #ffffff)
316
+ );
317
+ --df-body-text-color: var(--gr-df-table-text, --df-neutral-800);
318
+ --df-body-text-size: var(--df-text-md, 14px);
319
+ --df-body-text-weight: 400;
320
+
321
+ --df-color-accent: var(--df-primary-500, #f97316);
322
+ --df-color-accent-soft: var(--df-primary-50, #fff7ed);
323
+ --df-background-fill-primary: white;
324
+ --df-background-fill-secondary: var(--df-neutral-50, #f9fafb);
325
+ --df-border-color-accent: var(--df-primary-300, #fdba74);
326
+ --df-body-text-color-subdued: var(--df-neutral-400, #9ca3af);
327
+ --df-table-text-color: var(--df-body-text-color, #111827);
328
+ --df-shadow-drop: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
329
+ --df-shadow-drop-lg:
330
+ 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
331
+ --df-shadow-inset: rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset;
332
+ --df-shadow-spread: 3px;
333
+
334
+ --df-bw-svt-p-top: 0px;
335
+ --df-bw-svt-p-bottom: 0px;
336
+
337
+ --df-border-color-secondary: var(--df-border-color-accent, #fdba74);
338
+ --df-shadow-md:
339
+ 0 12px 16px -4px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
340
+
341
+ --df-checkbox-border-radius: var(--df-radius-sm, 4px);
342
+ --df-checkbox-shadow: none;
343
+ --df-checkbox-border-color: var(--df-neutral-300, #d4d4d8);
344
+ --df-checkbox-background-color: var(--df-background-fill-primary, #ffffff);
345
+ --df-checkbox-background-color-selected: var(
346
+ --df-color-accent,
347
+ var(--color-accent)
348
+ );
349
+ --df-checkbox-border-color-focus: var(--df-color-accent, #f97316);
350
+ --df-button-transition: none;
351
+ --df-block-background-fill: var(--df-background-fill-primary, white);
352
+ --df-block-border-color: var(
353
+ --df-border-color-primary,
354
+ var(--df-neutral-200, #e5e7eb)
355
+ );
356
+ --df-block-border-width: 1px;
357
+ --df-input-text-size: 0.95rem;
358
+ --df-line-md: 1.5;
359
+ --df-line-lg: 1.75;
360
+
361
+ --df-input-background-fill: var(--df-background-fill-primary, #ffffff);
362
+ --df-input-background-fill-focus: var(
363
+ --df-input-background-fill,
364
+ var(--df-background-fill-primary, #ffffff)
365
+ );
366
+ --df-input-background-fill-hover: var(
367
+ --df-input-background-fill,
368
+ var(--df-background-fill-primary, #ffffff)
369
+ );
370
+ --df-input-border-color: var(--df-border-color-primary, #e5e7eb);
371
+ --df-input-border-color-focus: var(--secondary-300, #93c5fd);
372
+ --df-input-border-color-hover: var(
373
+ --df-input-border-color,
374
+ var(--df-border-color-primary, #e5e7eb)
375
+ );
376
+ --df-input-border-width: 1px;
377
+ --df-input-padding: var(--df-spacing-xl, 10px);
378
+ --df-input-placeholder-color: var(--neutral-400, #9ca3af);
379
+ --df-input-radius: var(--df-radius-sm, 4px);
380
+ --df-input-shadow: none;
381
+ --df-input-shadow-focus:
382
+ 0 0 0 var(--shadow-spread, 3px) var(--secondary-50, #eff6ff),
383
+ var(--shadow-inset, rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset);
384
+
385
+ --table-radius: var(--gr-df-table-radius, var(--df-table-radius, 4px));
386
+ --table-row-hover: var(--gr-df-table-row-hover, var(--color-accent-soft));
387
+ --cell-padding: var(--gr-df-cell-padding, var(--size-2));
388
+ --df-font-size: var(--gr-df-font-size, var(--text-md));
389
+ --background-fill-primary: var(--df-background-fill-primary, #ffffff);
390
+ --background-fill-primary-dark: var(
391
+ --df-background-fill-primary-dark,
392
+ var(--neutral-950, #0f0f11)
393
+ );
394
+ --background-fill-secondary: var(--df-background-fill-secondary, #f8fafc);
395
+ --background-fill-secondary-dark: var(
396
+ --df-background-fill-secondary-dark,
397
+ var(--neutral-900, #18181b)
398
+ );
399
+ --color-accent: var(--gr-df-accent, var(--df-color-accent, #7c3aed));
400
+ --color-accent-soft: var(
401
+ --gr-df-accent-soft,
402
+ var(--df-color-accent-soft, #f3e8ff)
403
+ );
404
+ --color-accent-copied: var(
405
+ --gr-df-copied-cell-color,
406
+ var(--color-accent-soft)
407
+ );
408
+ --body-text-color: var(--df-body-text-color, #111827);
409
+ --block-background-fill: var(
410
+ --df-block-background-fill,
411
+ var(--background-fill-primary)
412
+ );
413
+ --block-radius: var(--df-block-radius, var(--radius-sm, 4px));
414
+ --table-even-background-fill: var(
415
+ --gr-df-table-bg-even,
416
+ var(--df-table-even-background-fill, #ffffff)
417
+ );
418
+ --table-odd-background-fill: var(
419
+ --gr-df-table-bg-odd,
420
+ var(--df-table-odd-background-fill, #f9fafb)
421
+ );
422
+ --border-color-primary: var(--df-border-color-primary, #e5e7eb);
423
+ --radius-sm: var(--df-radius-sm, 4px);
424
+ --size-1: var(--df-size-1, 4px);
425
+ --size-2: var(--df-size-2, 8px);
426
+ --size-3: var(--df-size-3, 12px);
427
+ --size-4: var(--df-size-4, 16px);
428
+ --size-5: var(--df-size-5, 20px);
429
+ --size-6: var(--df-size-6, 24px);
430
+ --size-7: var(--df-size-7, 28px);
431
+ --size-8: var(--df-size-8, 32px);
432
+ --size-9: var(--df-size-9, 36px);
433
+ --size-10: var(--df-size-10, 40px);
434
+ --size-11: var(--df-size-11, 44px);
435
+ --size-12: var(--df-size-12, 48px);
436
+ --size-14: var(--df-size-14, 56px);
437
+ --size-16: var(--df-size-16, 64px);
438
+ --size-20: var(--df-size-20, 80px);
439
+ --size-24: var(--df-size-24, 96px);
440
+
441
+ --size-px: var(--df-size-px, 1px);
442
+ --size-full: var(--df-size-full, 100%);
443
+ --size-0-5: var(--df-size-0-5, 2px);
444
+ --size-1-5: var(--df-size-1-5, 6px);
445
+ --size-2-5: var(--df-size-2-5, 10px);
446
+ --input-text-size: var(--df-input-text-size, 0.95rem);
447
+ --text-sm: var(--df-text-sm, 12px);
448
+ --text-md: var(--df-text-md, 14px);
449
+ --text-lg: var(--df-text-lg, 16px);
450
+ --text-xl: var(--df-text-xl, 22px);
451
+ --text-xxl: var(--df-text-xxl, 26px);
452
+
453
+ --spacing-xxs: var(--df-spacing-xxs, 1px);
454
+ --spacing-xs: var(--df-spacing-xs, 2px);
455
+ --spacing-sm: var(--df-spacing-sm, 4px);
456
+ --spacing-md: var(--df-spacing-md, 6px);
457
+ --spacing-lg: var(--df-spacing-lg, 8px);
458
+ --spacing-xl: var(--df-spacing-xl, 10px);
459
+ --spacing-xxl: var(--df-spacing-xxl, 16px);
460
+
461
+ --radius-xxs: var(--df-radius-xxs, 1px);
462
+ --radius-xs: var(--df-radius-xs, 2px);
463
+ --radius-sm: var(--df-radius-sm, 4px);
464
+ --radius-md: var(--df-radius-md, 6px);
465
+ --radius-lg: var(--df-radius-lg, 8px);
466
+ --radius-xl: var(--df-radius-xl, 12px);
467
+ --radius-2xl: var(--df-radius-2xl, 16px);
468
+ --radius-3xl: var(--df-radius-3xl, 22px);
469
+ --radius-full: var(--df-radius-full, 9999px);
470
+ --font-mono: var(--df-font-mono, "Courier New", Courier, monospace);
471
+ --font-sans: var(
472
+ --df-font-sans,
473
+ "Source Sans Pro",
474
+ ui-sans-serif,
475
+ system-ui,
476
+ sans-serif
477
+ );
478
+
479
+ --input-background-fill: var(
480
+ --gr-df-input-background-fill,
481
+ var(--df-input-background-fill, var(--background-fill-primary, #ffffff))
482
+ );
483
+ --input-background-fill-focus: var(
484
+ --gr-df-input-background-fill-focus,
485
+ var(
486
+ --df-input-background-fill-focus,
487
+ var(--input-background-fill, var(--background-fill-primary, #ffffff))
488
+ )
489
+ );
490
+ --input-background-fill-hover: var(
491
+ --gr-df-input-background-fill-hover,
492
+ var(
493
+ --df-input-background-fill-hover,
494
+ var(--input-background-fill, var(--background-fill-primary, #ffffff))
495
+ )
496
+ );
497
+ --input-border-color: var(
498
+ --gr-df-input-border-color,
499
+ var(--df-input-border-color, var(--border-color-primary, #e5e7eb))
500
+ );
501
+ --input-border-color-focus: var(
502
+ --gr-df-input-border-color-focus,
503
+ var(--df-input-border-color-focus, var(--secondary-300, #93c5fd))
504
+ );
505
+ --input-border-color-hover: var(
506
+ --gr-df-input-border-color-hover,
507
+ var(
508
+ --df-input-border-color-hover,
509
+ var(--input-border-color, var(--border-color-primary, #e5e7eb))
510
+ )
511
+ );
512
+ --input-border-width: var(
513
+ --gr-df-input-border-width,
514
+ var(--df-input-border-width, 1px)
515
+ );
516
+
517
+ --weight-bold: var(--df-weight-bold, 700);
518
+ --weight-semibold: var(--df-weight-semibold, 600);
519
+ --checkbox-border-radius: var(
520
+ --gr-df-checkbox-border-radius,
521
+ var(--df-checkbox-border-radius, var(--df-radius-sm, 4px))
522
+ );
523
+ --checkbox-shadow: var(
524
+ --gr-df-checkbox-shadow,
525
+ var(--df-checkbox-shadow, none)
526
+ );
527
+ --checkbox-border-color: var(
528
+ --gr-df-checkbox-border-color,
529
+ var(--df-checkbox-border-color, var(--df-neutral-300, #d4d4d8))
530
+ );
531
+ --checkbox-background-color: var(
532
+ --gr-df-checkbox-background-color,
533
+ var(
534
+ --df-checkbox-background-color,
535
+ var(--df-background-fill-primary, #ffffff)
536
+ )
537
+ );
538
+ --checkbox-background-color-selected: var(
539
+ --gr-df-checkbox-background-color,
540
+ var(--df-checkbox-background-color-selected, var(--color-accent))
541
+ );
542
+ --checkbox-border-color-focus: var(
543
+ --gr-df-checkbox-border-color-focus,
544
+ var(--df-checkbox-border-color-focus, var(--df-color-accent, #f97316))
545
+ );
546
+ --checkbox-check: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
547
+ --button-transition: var(--df-button-transition, none);
548
+ --max-height: var(--df-max-height, 500px);
549
+ --df-layer-1: 10;
550
+ --df-layer-2: 20;
551
+ --df-layer-3: 30;
552
+ --df-layer-4: 40;
553
+ --df-layer-5: 50;
554
+ --df-layer-below: -1;
555
+ --df-layer-top: 2147483647;
556
+
557
+ --layer-1: var(--df-layer-1, 10);
558
+ --layer-2: var(--df-layer-2, 20);
559
+ --layer-3: var(--df-layer-3, 30);
560
+ --layer-4: var(--df-layer-4, 40);
561
+ --layer-5: var(--df-layer-5, 50);
562
+ --layer-below: var(--df-layer-below, -1);
563
+ --layer-top: var(--df-layer-top, 2147483647);
564
+
565
+ --line-md: var(--df-line-md, 1.5);
566
+ --line-lg: var(--df-line-lg, 1.75);
567
+
568
+ --shadow-xs:
569
+ 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
570
+ --shadow-sm:
571
+ 0 4px 6px -2px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
572
+ --shadow-md:
573
+ 0 12px 16px -4px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
574
+ --shadow-lg:
575
+ 0 20px 24px -4px rgba(0, 0, 0, 0.1), 0 8px 8px -4px rgba(0, 0, 0, 0.04);
576
+ --shadow-drop: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
577
+ --shadow-drop-lg:
578
+ 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
579
+ --shadow-inset: rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset;
580
+ --shadow-spread: 3px;
581
+ }
582
+
583
+ .gradio-dataframe-standalone.fullscreen {
584
+ position: fixed;
585
+ top: 0;
586
+ left: 0;
587
+ width: 100vw;
588
+ height: 100vh;
589
+ z-index: 1000;
590
+ overflow: auto;
591
+ border-radius: 0;
592
+ background-color: var(--block-background-fill);
593
+ }
594
+
595
+ :global(.dark) .gradio-dataframe-standalone {
596
+ --df-background-fill-primary: var(--df-background-fill-primary-dark);
597
+ --df-background-fill-secondary: var(--df-background-fill-secondary-dark);
598
+ --df-body-text-color: var(--df-body-text-color-dark);
599
+ --df-block-background-fill: var(--df-block-background-fill-dark);
600
+ --df-table-even-background-fill: var(--df-table-even-background-fill-dark);
601
+ --df-table-odd-background-fill: var(--df-table-odd-background-fill-dark);
602
+ --df-border-color-primary: var(--df-border-color-primary-dark);
603
+ --df-color-accent: var(--df-color-accent-dark);
604
+ --df-color-accent-soft: var(--df-color-accent-soft-dark);
605
+ }
606
+
607
+ :global(.gradio-container),
608
+ :global(*),
609
+ :global(::before),
610
+ :global(::after) {
611
+ box-sizing: border-box;
612
+ border-width: 0;
613
+ border-style: solid;
614
+ }
615
+
616
+ :global(.gradio-container) :global(textarea) {
617
+ padding-top: var(--input-padding, var(--df-input-padding, 10px));
618
+ padding-bottom: var(--input-padding, var(--df-input-padding, 10px));
619
+ box-sizing: border-box;
620
+ }
621
+
622
+ :global(button),
623
+ :global(input),
624
+ :global(select),
625
+ :global(textarea) {
626
+ margin: 0;
627
+ padding: 0;
628
+ color: inherit;
629
+ font-weight: inherit;
630
+ font-size: 100%;
631
+ line-height: inherit;
632
+ font-family: inherit;
633
+ }
634
+
635
+ :global([type="text"]),
636
+ :global([type="url"]),
637
+ :global([type="number"]),
638
+ :global([multiple]),
639
+ :global(textarea),
640
+ :global(select) {
641
+ --tw-shadow: 0 0 #0000;
642
+ appearance: none;
643
+ border-width: 1px;
644
+ border-color: #6b7280;
645
+ border-radius: 0px;
646
+ background-color: #fff;
647
+ padding-top: 0.5rem;
648
+ padding-right: 0.75rem;
649
+ padding-bottom: 0.5rem;
650
+ padding-left: 0.75rem;
651
+ font-size: 1rem;
652
+ line-height: 1.5rem;
653
+ }
654
+
655
+ :global(button),
656
+ :global(input[type="button"]),
657
+ :global(input[type="submit"]) {
658
+ -webkit-appearance: button;
659
+ appearance: button;
660
+ background-image: none;
661
+ background-color: transparent;
662
+ }
663
+
664
+ :global(.sr-only) {
665
+ clip: rect(0, 0, 0, 0);
666
+ position: absolute;
667
+ margin: -1px;
668
+ border-width: 0;
669
+ padding: 0;
670
+ width: 1px;
671
+ height: 1px;
672
+ overflow: hidden;
673
+ white-space: nowrap;
674
+ }
675
+
676
+ :global(input[type="checkbox"]) {
677
+ accent-color: var(--color-accent);
678
+ }
679
+
680
+ :global(label) {
681
+ display: flex;
682
+ align-items: center;
683
+ transition: all 0.15s ease;
684
+ cursor: pointer;
685
+ /* default label color */
686
+ color: #111111;
687
+ font-weight: 400;
688
+ font-size: 14px;
689
+ line-height: 1.5;
690
+ }
691
+
692
+ :global(label) > * + * {
693
+ margin-left: 8px;
694
+ }
695
+
696
+ :global(input) {
697
+ --ring-color: transparent;
698
+ position: relative;
699
+ /* default shadow */
700
+ box-shadow: none;
701
+ border: 1px solid #888888;
702
+ border-radius: 6px;
703
+ background-color: #ffffff;
704
+ line-height: 1;
705
+ }
706
+
707
+ :global(input:checked),
708
+ :global(input:checked:hover),
709
+ :global(input:checked:focus) {
710
+ /* checked state: orange */
711
+ background-image: none;
712
+ background-color: #f97316;
713
+ border-color: #f97316;
714
+ }
715
+
716
+ :global(input:checked:focus) {
717
+ background-image: none;
718
+ background-color: #f97316;
719
+ border-color: #f97316;
720
+ }
721
+
722
+ :global(input:hover) {
723
+ border-color: #1e90ff;
724
+ background-color: #e6f0ff;
725
+ }
726
+
727
+ :global(input:focus) {
728
+ border-color: #f97316;
729
+ background-color: #fff4e6;
730
+ }
731
+
732
+ :global(input[disabled]),
733
+ :global(.disabled) {
734
+ cursor: not-allowed !important;
735
+ opacity: 0.6;
736
+ }
737
+
738
+ :global(input:hover) {
739
+ cursor: pointer;
740
+ }
741
+ </style>
6.14.0/dataframe/standalone/default_i18n.ts ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const default_i18n: Record<string, string> = {
2
+ "dataframe.add_row_above": "Add row above",
3
+ "dataframe.add_row_below": "Add row below",
4
+ "dataframe.delete_row": "Delete row",
5
+ "dataframe.add_column_left": "Add column left",
6
+ "dataframe.add_column_right": "Add column right",
7
+ "dataframe.delete_column": "Delete column",
8
+ "dataframe.sort_asc": "Sort ascending",
9
+ "dataframe.sort_desc": "Sort descending",
10
+ "dataframe.sort_ascending": "Sort ascending",
11
+ "dataframe.sort_descending": "Sort descending",
12
+ "dataframe.clear_sort": "Clear sort",
13
+ "dataframe.filter": "Filter",
14
+ "dataframe.clear_filter": "Clear filter",
15
+ "dataframe.copy": "Copy",
16
+ "dataframe.paste": "Paste",
17
+ "dataframe.cut": "Cut",
18
+ "dataframe.select_all": "Select all",
19
+ "dataframe.fullscreen": "Fullscreen",
20
+ "dataframe.exit_fullscreen": "Exit fullscreen",
21
+ "dataframe.search": "Search",
22
+ "dataframe.export": "Export",
23
+ "dataframe.import": "Import",
24
+ "dataframe.edit": "Edit",
25
+ "dataframe.save": "Save",
26
+ "dataframe.cancel": "Cancel",
27
+ "dataframe.confirm": "Confirm",
28
+ "dataframe.reset": "Reset",
29
+ "dataframe.clear": "Clear",
30
+ "dataframe.undo": "Undo",
31
+ "dataframe.redo": "Redo"
32
+ };
6.14.0/dataframe/standalone/stubs/Upload.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export const aria_label = "";
3
+ export const root = "";
4
+ export const upload: any = null;
5
+ export const stream_handler: any = null;
6
+ </script>
7
+
8
+ <div>
9
+ <slot />
10
+ </div>
11
+
12
+ <style>
13
+ div {
14
+ width: 100%;
15
+ border: 1px solid var(--border-color-primary);
16
+ border-radius: var(--table-radius);
17
+ overflow: hidden;
18
+ }
19
+ </style>
6.14.0/dataframe/standalone/stubs/upload.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export { default as Upload } from "./Upload.svelte";
6.14.0/dataframe/types.ts ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { SelectData } from "@gradio/utils";
2
+ import type { LoadingStatus } from "@gradio/statustracker";
3
+ import type { DataframeValue, Datatype, EditData } from "./shared/utils/utils";
4
+
5
+ export interface DataframeEvents {
6
+ change: DataframeValue;
7
+ input: never;
8
+ select: SelectData;
9
+ edit: EditData;
10
+ clear_status: LoadingStatus;
11
+ }
12
+
13
+ export interface DataframeProps {
14
+ value: DataframeValue;
15
+ col_count: [number, "fixed" | "dynamic"];
16
+ row_count: [number, "fixed" | "dynamic"];
17
+ wrap: boolean;
18
+ datatype: Datatype | Datatype[];
19
+ line_breaks: boolean;
20
+ column_widths: string[];
21
+ latex_delimiters: {
22
+ left: string;
23
+ right: string;
24
+ display: boolean;
25
+ }[];
26
+ max_height: number;
27
+ buttons: string[] | null;
28
+ max_chars: number | undefined;
29
+ show_row_numbers: boolean;
30
+ show_search: "none" | "search" | "filter";
31
+ pinned_columns: number;
32
+ static_columns: (string | number)[];
33
+ fullscreen: boolean;
34
+ }