Upload folder using huggingface_hub
Browse files- 6.11.0/dataframe/Index.svelte +107 -106
- 6.11.0/dataframe/package.json +5 -4
- 6.11.0/dataframe/shared/BooleanCell.svelte +12 -6
- 6.11.0/dataframe/shared/CellMenu.svelte +74 -49
- 6.11.0/dataframe/shared/CellMenuButton.svelte +3 -3
- 6.11.0/dataframe/shared/CellMenuIcons.svelte +1 -1
- 6.11.0/dataframe/shared/DataCell.svelte +189 -0
- 6.11.0/dataframe/shared/EditableCell.svelte +88 -64
- 6.11.0/dataframe/shared/EmptyRowButton.svelte +2 -2
- 6.11.0/dataframe/shared/FilterMenu.svelte +26 -18
- 6.11.0/dataframe/shared/HeaderCell.svelte +218 -0
- 6.11.0/dataframe/shared/RowNumber.svelte +4 -2
- 6.11.0/dataframe/shared/Table.svelte +1037 -949
- 6.11.0/dataframe/shared/Toolbar.svelte +32 -22
- 6.11.0/dataframe/shared/column_measurement.svelte.ts +103 -0
- 6.11.0/dataframe/shared/icons/FilterIcon.svelte +14 -6
- 6.11.0/dataframe/shared/icons/Padlock.svelte +6 -2
- 6.11.0/dataframe/shared/icons/SelectionButtons.svelte +23 -8
- 6.11.0/dataframe/shared/icons/SortButtonDown.svelte +15 -4
- 6.11.0/dataframe/shared/icons/SortButtonUp.svelte +15 -5
- 6.11.0/dataframe/shared/icons/SortIcon.svelte +13 -7
- 6.11.0/dataframe/shared/tanstack/index.ts +23 -0
- 6.11.0/dataframe/shared/tanstack/table.svelte.ts +117 -0
- 6.11.0/dataframe/shared/tanstack/virtual.svelte.ts +105 -0
- 6.11.0/dataframe/shared/types.ts +3 -0
- 6.11.0/dataframe/shared/utils/filter.ts +66 -0
- 6.11.0/dataframe/shared/utils/selection_utils.ts +1 -1
- 6.11.0/dataframe/shared/utils/table_utils.ts +1 -100
- 6.11.0/dataframe/standalone/Index.svelte +71 -46
- 6.11.0/dataframe/types.ts +34 -0
6.11.0/dataframe/Index.svelte
CHANGED
|
@@ -1,128 +1,129 @@
|
|
| 1 |
-
<
|
| 2 |
-
|
| 3 |
-
<script context="module" lang="ts">
|
| 4 |
export { default as BaseDataFrame } from "./shared/Table.svelte";
|
| 5 |
export { default as BaseExample } from "./Example.svelte";
|
| 6 |
</script>
|
| 7 |
|
| 8 |
<script lang="ts">
|
| 9 |
-
import
|
|
|
|
|
|
|
|
|
|
| 10 |
import { Gradio } from "@gradio/utils";
|
| 11 |
-
|
| 12 |
import type { DataframeProps, DataframeEvents } from "./types";
|
| 13 |
import { dequal } from "dequal";
|
| 14 |
-
import { onMount } from "svelte";
|
| 15 |
-
import DF from "@gradio/dataframe-interim";
|
| 16 |
-
import "@gradio/dataframe-interim/css";
|
| 17 |
|
| 18 |
-
let
|
|
|
|
| 19 |
|
| 20 |
-
let
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
let Component: typeof DF | null = null;
|
| 40 |
-
onMount(() => {
|
| 41 |
-
Component = new DF({
|
| 42 |
-
target: el,
|
| 43 |
-
props: {
|
| 44 |
-
elem_id: gradio.shared.elem_id,
|
| 45 |
-
elem_classes: gradio.shared.elem_classes,
|
| 46 |
-
visible: gradio.shared.visible,
|
| 47 |
-
value: gradio.props.value,
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
show_label: gradio.shared.show_label,
|
| 53 |
-
wrap: gradio.props.wrap,
|
| 54 |
-
datatype: gradio.props.datatype,
|
| 55 |
-
scale: gradio.shared.scale,
|
| 56 |
-
min_width: gradio.shared.min_width,
|
| 57 |
-
root: gradio.shared.root,
|
| 58 |
-
line_breaks: gradio.props.line_breaks,
|
| 59 |
-
column_widths: gradio.props.column_widths,
|
| 60 |
-
gradio: compat_gradio,
|
| 61 |
-
latex_delimiters: gradio.props.latex_delimiters,
|
| 62 |
-
max_height: gradio.props.max_height,
|
| 63 |
-
loading_status: gradio.shared.loading_status,
|
| 64 |
-
interactive: gradio.shared.interactive,
|
| 65 |
-
buttons: gradio.props.buttons,
|
| 66 |
-
max_chars: gradio.props.max_chars,
|
| 67 |
-
show_row_numbers: gradio.props.show_row_numbers,
|
| 68 |
-
show_search: gradio.props.show_search,
|
| 69 |
-
pinned_columns: gradio.props.pinned_columns,
|
| 70 |
-
static_columns: gradio.props.static_columns,
|
| 71 |
-
fullscreen: gradio.props.fullscreen,
|
| 72 |
-
show_copy_button:
|
| 73 |
-
gradio.props.buttons && gradio.props.buttons.includes("copy"),
|
| 74 |
-
show_fullscreen_button:
|
| 75 |
-
gradio.props.buttons && gradio.props.buttons.includes("fullscreen")
|
| 76 |
-
}
|
| 77 |
-
});
|
| 78 |
-
});
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
dispatch(name: keyof DataframeEvents, detail?: any) {
|
| 84 |
-
if (name === "input" && changed) {
|
| 85 |
-
changed = false;
|
| 86 |
-
return;
|
| 87 |
-
}
|
| 88 |
-
gradio.dispatch(name, detail);
|
| 89 |
-
},
|
| 90 |
-
autoscroll: gradio.shared.autoscroll
|
| 91 |
-
};
|
| 92 |
-
$effect(() => {
|
| 93 |
-
if (Component) {
|
| 94 |
-
Component.$set({
|
| 95 |
-
elem_id: gradio.shared.elem_id,
|
| 96 |
-
elem_classes: gradio.shared.elem_classes,
|
| 97 |
-
visible: gradio.shared.visible,
|
| 98 |
-
value: gradio.props.value,
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
root: gradio.shared.root,
|
| 109 |
-
line_breaks: gradio.props.line_breaks,
|
| 110 |
-
column_widths: gradio.props.column_widths,
|
| 111 |
-
gradio: compat_gradio,
|
| 112 |
-
latex_delimiters: gradio.props.latex_delimiters,
|
| 113 |
-
max_height: gradio.props.max_height,
|
| 114 |
-
loading_status: gradio.shared.loading_status,
|
| 115 |
-
interactive: gradio.shared.interactive,
|
| 116 |
-
buttons: gradio.props.buttons,
|
| 117 |
-
max_chars: gradio.props.max_chars,
|
| 118 |
-
show_row_numbers: gradio.props.show_row_numbers,
|
| 119 |
-
show_search: gradio.props.show_search,
|
| 120 |
-
pinned_columns: gradio.props.pinned_columns,
|
| 121 |
-
static_columns: gradio.props.static_columns,
|
| 122 |
-
fullscreen: gradio.props.fullscreen
|
| 123 |
-
});
|
| 124 |
}
|
| 125 |
});
|
| 126 |
</script>
|
| 127 |
|
| 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 |
+
overflow_behavior="visible"
|
| 87 |
+
{fullscreen}
|
| 88 |
+
>
|
| 89 |
+
<StatusTracker
|
| 90 |
+
autoscroll={gradio.shared.autoscroll}
|
| 91 |
+
i18n={gradio.i18n}
|
| 92 |
+
{...gradio.shared.loading_status}
|
| 93 |
+
/>
|
| 94 |
+
<Table
|
| 95 |
+
headers={gradio.props.value?.headers ?? []}
|
| 96 |
+
values={gradio.props.value?.data ?? []}
|
| 97 |
+
display_value={gradio.props.value?.metadata?.display_value ?? null}
|
| 98 |
+
styling={gradio.props.value?.metadata?.styling ?? null}
|
| 99 |
+
col_count={gradio.props.col_count}
|
| 100 |
+
row_count={gradio.props.row_count}
|
| 101 |
+
label={gradio.shared.label}
|
| 102 |
+
show_label={gradio.shared.show_label}
|
| 103 |
+
wrap={gradio.props.wrap}
|
| 104 |
+
datatype={aligned_datatype}
|
| 105 |
+
latex_delimiters={gradio.props.latex_delimiters}
|
| 106 |
+
max_height={gradio.props.max_height}
|
| 107 |
+
editable={gradio.shared.interactive ?? true}
|
| 108 |
+
line_breaks={gradio.props.line_breaks}
|
| 109 |
+
column_widths={gradio.props.column_widths ?? []}
|
| 110 |
+
root={gradio.shared.root}
|
| 111 |
+
i18n={gradio.i18n}
|
| 112 |
+
upload={gradio.shared.client?.upload}
|
| 113 |
+
stream_handler={gradio.shared.client?.stream}
|
| 114 |
+
buttons={gradio.props.buttons}
|
| 115 |
+
max_chars={gradio.props.max_chars}
|
| 116 |
+
show_row_numbers={gradio.props.show_row_numbers}
|
| 117 |
+
show_search={gradio.props.show_search}
|
| 118 |
+
pinned_columns={gradio.props.pinned_columns}
|
| 119 |
+
static_columns={gradio.props.static_columns ?? []}
|
| 120 |
+
{fullscreen}
|
| 121 |
+
onfullscreen={() => {
|
| 122 |
+
fullscreen = !fullscreen;
|
| 123 |
+
}}
|
| 124 |
+
onchange={handle_change}
|
| 125 |
+
oninput={handle_input}
|
| 126 |
+
onselect={handle_select}
|
| 127 |
+
onedit={handle_edit}
|
| 128 |
+
/>
|
| 129 |
+
</Block>
|
6.11.0/dataframe/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dataframe",
|
| 3 |
-
"version": "0.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
@@ -21,7 +21,9 @@
|
|
| 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 |
},
|
| 26 |
"exports": {
|
| 27 |
".": {
|
|
@@ -40,8 +42,7 @@
|
|
| 40 |
"svelte": ">=5.0.0"
|
| 41 |
},
|
| 42 |
"devDependencies": {
|
| 43 |
-
"@gradio/preview": "workspace:^"
|
| 44 |
-
"@gradio/dataframe-interim": "workspace:^"
|
| 45 |
},
|
| 46 |
"repository": {
|
| 47 |
"type": "git",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/dataframe",
|
| 3 |
+
"version": "0.23.0",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 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 |
".": {
|
|
|
|
| 42 |
"svelte": ">=5.0.0"
|
| 43 |
},
|
| 44 |
"devDependencies": {
|
| 45 |
+
"@gradio/preview": "workspace:^"
|
|
|
|
| 46 |
},
|
| 47 |
"repository": {
|
| 48 |
"type": "git",
|
6.11.0/dataframe/shared/BooleanCell.svelte
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { BaseCheckbox } from "@gradio/checkbox";
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
function handle_change(
|
| 9 |
if (editable) {
|
| 10 |
-
on_change(
|
| 11 |
}
|
| 12 |
}
|
| 13 |
</script>
|
|
@@ -17,7 +23,7 @@
|
|
| 17 |
bind:value
|
| 18 |
label=""
|
| 19 |
interactive={editable}
|
| 20 |
-
|
| 21 |
/>
|
| 22 |
</div>
|
| 23 |
|
|
|
|
| 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>
|
|
|
|
| 23 |
bind:value
|
| 24 |
label=""
|
| 25 |
interactive={editable}
|
| 26 |
+
on_change={handle_change}
|
| 27 |
/>
|
| 28 |
</div>
|
| 29 |
|
6.11.0/dataframe/shared/CellMenu.svelte
CHANGED
|
@@ -3,44 +3,66 @@
|
|
| 3 |
import CellMenuIcons from "./CellMenuIcons.svelte";
|
| 4 |
import FilterMenu from "./FilterMenu.svelte";
|
| 5 |
import type { I18nFormatter } from "@gradio/utils";
|
| 6 |
-
import type {
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
let menu_element: HTMLDivElement;
|
| 39 |
-
let active_filter_menu: { x: number; y: number } | null = null;
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
onMount(() => {
|
| 46 |
position_menu();
|
|
@@ -86,7 +108,7 @@
|
|
| 86 |
{#if is_header}
|
| 87 |
<button
|
| 88 |
role="menuitem"
|
| 89 |
-
|
| 90 |
class:active={sort_direction === "asc"}
|
| 91 |
>
|
| 92 |
<CellMenuIcons icon="sort-asc" />
|
|
@@ -97,7 +119,7 @@
|
|
| 97 |
</button>
|
| 98 |
<button
|
| 99 |
role="menuitem"
|
| 100 |
-
|
| 101 |
class:active={sort_direction === "desc"}
|
| 102 |
>
|
| 103 |
<CellMenuIcons icon="sort-desc" />
|
|
@@ -106,13 +128,16 @@
|
|
| 106 |
<span class="priority">{sort_priority}</span>
|
| 107 |
{/if}
|
| 108 |
</button>
|
| 109 |
-
<button role="menuitem"
|
| 110 |
<CellMenuIcons icon="clear-sort" />
|
| 111 |
{i18n("dataframe.clear_sort")}
|
| 112 |
</button>
|
| 113 |
<button
|
| 114 |
role="menuitem"
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
class:active={filter_active || active_filter_menu}
|
| 117 |
>
|
| 118 |
<CellMenuIcons icon="filter" />
|
|
@@ -121,7 +146,7 @@
|
|
| 121 |
<span class="priority">1</span>
|
| 122 |
{/if}
|
| 123 |
</button>
|
| 124 |
-
<button role="menuitem"
|
| 125 |
<CellMenuIcons icon="clear-filter" />
|
| 126 |
{i18n("dataframe.clear_filter")}
|
| 127 |
</button>
|
|
@@ -130,7 +155,7 @@
|
|
| 130 |
{#if !is_header && can_add_rows}
|
| 131 |
<button
|
| 132 |
role="menuitem"
|
| 133 |
-
|
| 134 |
aria-label="Add row above"
|
| 135 |
>
|
| 136 |
<CellMenuIcons icon="add-row-above" />
|
|
@@ -138,7 +163,7 @@
|
|
| 138 |
</button>
|
| 139 |
<button
|
| 140 |
role="menuitem"
|
| 141 |
-
|
| 142 |
aria-label="Add row below"
|
| 143 |
>
|
| 144 |
<CellMenuIcons icon="add-row-below" />
|
|
@@ -147,7 +172,7 @@
|
|
| 147 |
{#if can_delete_rows}
|
| 148 |
<button
|
| 149 |
role="menuitem"
|
| 150 |
-
|
| 151 |
class="delete"
|
| 152 |
aria-label="Delete row"
|
| 153 |
>
|
|
@@ -159,7 +184,7 @@
|
|
| 159 |
{#if can_add_columns}
|
| 160 |
<button
|
| 161 |
role="menuitem"
|
| 162 |
-
|
| 163 |
aria-label="Add column to the left"
|
| 164 |
>
|
| 165 |
<CellMenuIcons icon="add-column-left" />
|
|
@@ -167,7 +192,7 @@
|
|
| 167 |
</button>
|
| 168 |
<button
|
| 169 |
role="menuitem"
|
| 170 |
-
|
| 171 |
aria-label="Add column to the right"
|
| 172 |
>
|
| 173 |
<CellMenuIcons icon="add-column-right" />
|
|
@@ -176,7 +201,7 @@
|
|
| 176 |
{#if can_delete_cols}
|
| 177 |
<button
|
| 178 |
role="menuitem"
|
| 179 |
-
|
| 180 |
class="delete"
|
| 181 |
aria-label="Delete column"
|
| 182 |
>
|
|
@@ -194,7 +219,7 @@
|
|
| 194 |
<style>
|
| 195 |
.cell-menu {
|
| 196 |
position: fixed;
|
| 197 |
-
z-index:
|
| 198 |
background: var(--background-fill-primary);
|
| 199 |
border: 1px solid var(--border-color-primary);
|
| 200 |
border-radius: var(--radius-sm);
|
|
@@ -204,7 +229,7 @@
|
|
| 204 |
gap: var(--size-1);
|
| 205 |
box-shadow: var(--shadow-drop-lg);
|
| 206 |
min-width: 150px;
|
| 207 |
-
|
| 208 |
}
|
| 209 |
|
| 210 |
.cell-menu button {
|
|
|
|
| 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();
|
|
|
|
| 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" />
|
|
|
|
| 119 |
</button>
|
| 120 |
<button
|
| 121 |
role="menuitem"
|
| 122 |
+
onclick={() => on_sort("desc")}
|
| 123 |
class:active={sort_direction === "desc"}
|
| 124 |
>
|
| 125 |
<CellMenuIcons icon="sort-desc" />
|
|
|
|
| 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" />
|
|
|
|
| 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>
|
|
|
|
| 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" />
|
|
|
|
| 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" />
|
|
|
|
| 172 |
{#if can_delete_rows}
|
| 173 |
<button
|
| 174 |
role="menuitem"
|
| 175 |
+
onclick={on_delete_row}
|
| 176 |
class="delete"
|
| 177 |
aria-label="Delete row"
|
| 178 |
>
|
|
|
|
| 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" />
|
|
|
|
| 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" />
|
|
|
|
| 201 |
{#if can_delete_cols}
|
| 202 |
<button
|
| 203 |
role="menuitem"
|
| 204 |
+
onclick={on_delete_col}
|
| 205 |
class="delete"
|
| 206 |
aria-label="Delete column"
|
| 207 |
>
|
|
|
|
| 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);
|
|
|
|
| 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 {
|
6.11.0/dataframe/shared/CellMenuButton.svelte
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
</script>
|
| 4 |
|
| 5 |
<button
|
| 6 |
aria-label="Open cell menu"
|
| 7 |
class="cell-menu-button"
|
| 8 |
aria-haspopup="menu"
|
| 9 |
-
|
| 10 |
-
|
| 11 |
event.preventDefault();
|
| 12 |
const touch = event.touches[0];
|
| 13 |
const mouseEvent = new MouseEvent("click", {
|
|
|
|
| 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", {
|
6.11.0/dataframe/shared/CellMenuIcons.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
</script>
|
| 4 |
|
| 5 |
{#if icon == "add-column-right"}
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
let { icon }: { icon: string } = $props();
|
| 3 |
</script>
|
| 4 |
|
| 5 |
{#if icon == "add-column-right"}
|
6.11.0/dataframe/shared/DataCell.svelte
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
latex_delimiters,
|
| 24 |
+
line_breaks = true,
|
| 25 |
+
editable = true,
|
| 26 |
+
max_chars = undefined,
|
| 27 |
+
i18n,
|
| 28 |
+
components = {},
|
| 29 |
+
is_dragging = false,
|
| 30 |
+
wrap_text = false,
|
| 31 |
+
onmousedown,
|
| 32 |
+
ondblclick,
|
| 33 |
+
oncontextmenu,
|
| 34 |
+
onblur,
|
| 35 |
+
on_menu_click,
|
| 36 |
+
on_select_column,
|
| 37 |
+
on_select_row
|
| 38 |
+
}: {
|
| 39 |
+
value: CellValue;
|
| 40 |
+
display_value?: string | null;
|
| 41 |
+
datatype?: Datatype;
|
| 42 |
+
row_idx: number;
|
| 43 |
+
col_idx: number;
|
| 44 |
+
col_style?: string;
|
| 45 |
+
cell_style?: string;
|
| 46 |
+
selection_classes?: string;
|
| 47 |
+
is_editing?: boolean;
|
| 48 |
+
is_flash?: boolean;
|
| 49 |
+
is_static?: boolean;
|
| 50 |
+
show_menu_button?: boolean;
|
| 51 |
+
show_selection_buttons?: boolean;
|
| 52 |
+
is_first_column?: boolean;
|
| 53 |
+
latex_delimiters: { left: string; right: string; display: boolean }[];
|
| 54 |
+
line_breaks?: boolean;
|
| 55 |
+
editable?: boolean;
|
| 56 |
+
max_chars?: number | undefined;
|
| 57 |
+
i18n: I18nFormatter;
|
| 58 |
+
components?: Record<string, any>;
|
| 59 |
+
is_dragging?: boolean;
|
| 60 |
+
wrap_text?: boolean;
|
| 61 |
+
onmousedown: (event: MouseEvent) => void;
|
| 62 |
+
ondblclick: (event: MouseEvent) => void;
|
| 63 |
+
oncontextmenu: (event: MouseEvent) => void;
|
| 64 |
+
onblur: (detail: {
|
| 65 |
+
blur_event: FocusEvent;
|
| 66 |
+
coords: [number, number];
|
| 67 |
+
}) => void;
|
| 68 |
+
on_menu_click: (event: MouseEvent) => void;
|
| 69 |
+
on_select_column: (col: number) => void;
|
| 70 |
+
on_select_row: (row: number) => void;
|
| 71 |
+
} = $props();
|
| 72 |
+
|
| 73 |
+
let is_selected = $derived(selection_classes !== "");
|
| 74 |
+
</script>
|
| 75 |
+
|
| 76 |
+
<div
|
| 77 |
+
class="body-cell {selection_classes}"
|
| 78 |
+
class:flash={is_flash}
|
| 79 |
+
class:first-column={is_first_column}
|
| 80 |
+
data-row={row_idx}
|
| 81 |
+
data-col={col_idx}
|
| 82 |
+
data-testid={`cell-${row_idx}-${col_idx}`}
|
| 83 |
+
{onmousedown}
|
| 84 |
+
{ondblclick}
|
| 85 |
+
{oncontextmenu}
|
| 86 |
+
style="{col_style} {cell_style}"
|
| 87 |
+
>
|
| 88 |
+
<div class="cell-wrap">
|
| 89 |
+
<EditableCell
|
| 90 |
+
{value}
|
| 91 |
+
{display_value}
|
| 92 |
+
{latex_delimiters}
|
| 93 |
+
{line_breaks}
|
| 94 |
+
{editable}
|
| 95 |
+
{is_static}
|
| 96 |
+
edit={is_editing}
|
| 97 |
+
{datatype}
|
| 98 |
+
{onblur}
|
| 99 |
+
{max_chars}
|
| 100 |
+
{i18n}
|
| 101 |
+
{components}
|
| 102 |
+
{show_selection_buttons}
|
| 103 |
+
coords={[row_idx, col_idx]}
|
| 104 |
+
{on_select_column}
|
| 105 |
+
{on_select_row}
|
| 106 |
+
{is_dragging}
|
| 107 |
+
{wrap_text}
|
| 108 |
+
/>
|
| 109 |
+
{#if show_menu_button}
|
| 110 |
+
<CellMenuButton on_click={on_menu_click} />
|
| 111 |
+
{/if}
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<style>
|
| 116 |
+
.body-cell {
|
| 117 |
+
--ring-color: transparent;
|
| 118 |
+
outline: none;
|
| 119 |
+
box-shadow:
|
| 120 |
+
inset 1px 0 0 var(--border-color-primary),
|
| 121 |
+
inset 0 0 0 1px var(--ring-color);
|
| 122 |
+
padding: 0;
|
| 123 |
+
overflow: visible;
|
| 124 |
+
box-sizing: border-box;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.body-cell.first-column {
|
| 128 |
+
box-shadow: inset 0 0 0 1px var(--ring-color);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.body-cell:hover :global(.cell-menu-button),
|
| 132 |
+
.body-cell.cell-selected :global(.cell-menu-button) {
|
| 133 |
+
display: flex;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.body-cell.cell-selected {
|
| 137 |
+
--ring-color: var(--color-accent);
|
| 138 |
+
--sel-top: inset 0 2px 0 0 var(--ring-color);
|
| 139 |
+
--sel-bottom: inset 0 -2px 0 0 var(--ring-color);
|
| 140 |
+
--sel-left: inset 2px 0 0 0 var(--ring-color);
|
| 141 |
+
--sel-right: inset -2px 0 0 0 var(--ring-color);
|
| 142 |
+
box-shadow:
|
| 143 |
+
var(--sel-top), var(--sel-bottom), var(--sel-left), var(--sel-right);
|
| 144 |
+
z-index: 2;
|
| 145 |
+
position: relative;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.body-cell.cell-selected.no-top {
|
| 149 |
+
--sel-top: inset 0 0 0 0 transparent;
|
| 150 |
+
}
|
| 151 |
+
.body-cell.cell-selected.no-bottom {
|
| 152 |
+
--sel-bottom: inset 0 0 0 0 transparent;
|
| 153 |
+
}
|
| 154 |
+
.body-cell.cell-selected.no-left {
|
| 155 |
+
--sel-left: inset 0 0 0 0 transparent;
|
| 156 |
+
}
|
| 157 |
+
.body-cell.cell-selected.no-right {
|
| 158 |
+
--sel-right: inset 0 0 0 0 transparent;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.body-cell.flash.cell-selected {
|
| 162 |
+
animation: flash-color 700ms ease-out;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
@keyframes flash-color {
|
| 166 |
+
0%,
|
| 167 |
+
30% {
|
| 168 |
+
background: var(--color-accent-copied);
|
| 169 |
+
}
|
| 170 |
+
100% {
|
| 171 |
+
background: transparent;
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.cell-wrap {
|
| 176 |
+
display: flex;
|
| 177 |
+
align-items: center;
|
| 178 |
+
justify-content: flex-start;
|
| 179 |
+
outline: none;
|
| 180 |
+
min-height: var(--size-9);
|
| 181 |
+
position: relative;
|
| 182 |
+
padding: var(--size-2);
|
| 183 |
+
box-sizing: border-box;
|
| 184 |
+
gap: var(--size-1);
|
| 185 |
+
overflow: visible;
|
| 186 |
+
min-width: 0;
|
| 187 |
+
height: 100%;
|
| 188 |
+
}
|
| 189 |
+
</style>
|
6.11.0/dataframe/shared/EditableCell.svelte
CHANGED
|
@@ -1,48 +1,71 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import { createEventDispatcher } from "svelte";
|
| 3 |
import { MarkdownCode } from "@gradio/markdown-code";
|
| 4 |
import type { I18nFormatter } from "@gradio/utils";
|
| 5 |
import type { CellValue } from "./types";
|
| 6 |
import SelectionButtons from "./icons/SelectionButtons.svelte";
|
| 7 |
import BooleanCell from "./BooleanCell.svelte";
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
function truncate_text(
|
| 48 |
text: CellValue,
|
|
@@ -56,17 +79,17 @@
|
|
| 56 |
return str.slice(0, max_length) + "...";
|
| 57 |
}
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
? value
|
| 63 |
-
|
| 64 |
-
? display_value
|
| 65 |
-
: value;
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
function use_focus(node: HTMLTextAreaElement): any {
|
| 72 |
requestAnimationFrame(() => {
|
|
@@ -77,24 +100,26 @@
|
|
| 77 |
}
|
| 78 |
|
| 79 |
function handle_blur(event: FocusEvent): void {
|
| 80 |
-
|
| 81 |
blur_event: event,
|
| 82 |
coords: coords
|
| 83 |
});
|
| 84 |
}
|
| 85 |
|
| 86 |
function handle_keydown(event: KeyboardEvent): void {
|
| 87 |
-
|
| 88 |
}
|
| 89 |
|
| 90 |
function commit_change(checked: boolean): void {
|
| 91 |
handle_blur({ target: { value } } as unknown as FocusEvent);
|
| 92 |
}
|
| 93 |
|
| 94 |
-
$
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
</script>
|
| 99 |
|
| 100 |
{#if edit && datatype !== "bool"}
|
|
@@ -106,11 +131,11 @@
|
|
| 106 |
bind:value
|
| 107 |
class:header
|
| 108 |
tabindex="-1"
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
use:use_focus
|
| 113 |
-
|
| 114 |
/>
|
| 115 |
{/if}
|
| 116 |
|
|
@@ -119,13 +144,13 @@
|
|
| 119 |
{:else}
|
| 120 |
<span
|
| 121 |
class:dragging={is_dragging}
|
| 122 |
-
|
| 123 |
tabindex="0"
|
| 124 |
role="button"
|
| 125 |
class:edit
|
| 126 |
class:expanded={edit}
|
| 127 |
class:multiline={header}
|
| 128 |
-
|
| 129 |
style={styling}
|
| 130 |
data-editable={editable}
|
| 131 |
data-max-chars={max_chars}
|
|
@@ -135,8 +160,8 @@
|
|
| 135 |
class:wrap={wrap_text}
|
| 136 |
>
|
| 137 |
{#if datatype === "image" && components.image}
|
| 138 |
-
|
| 139 |
-
|
| 140 |
value={{ url: display_text }}
|
| 141 |
show_label={false}
|
| 142 |
label="cell-image"
|
|
@@ -201,7 +226,7 @@
|
|
| 201 |
span {
|
| 202 |
flex: 1 1 0%;
|
| 203 |
position: relative;
|
| 204 |
-
display:
|
| 205 |
outline: none;
|
| 206 |
-webkit-user-select: text;
|
| 207 |
-moz-user-select: text;
|
|
@@ -209,8 +234,7 @@
|
|
| 209 |
user-select: text;
|
| 210 |
cursor: text;
|
| 211 |
width: 100%;
|
| 212 |
-
|
| 213 |
-
overflow: hidden;
|
| 214 |
}
|
| 215 |
|
| 216 |
span.text.expanded {
|
|
|
|
| 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 |
+
show_selection_buttons = false,
|
| 25 |
+
coords,
|
| 26 |
+
on_select_column = null,
|
| 27 |
+
on_select_row = null,
|
| 28 |
+
el = $bindable(null),
|
| 29 |
+
onblur,
|
| 30 |
+
onkeydown
|
| 31 |
+
}: {
|
| 32 |
+
edit: boolean;
|
| 33 |
+
value?: CellValue;
|
| 34 |
+
display_value?: string | null;
|
| 35 |
+
styling?: string;
|
| 36 |
+
header?: boolean;
|
| 37 |
+
datatype?:
|
| 38 |
+
| "str"
|
| 39 |
+
| "markdown"
|
| 40 |
+
| "html"
|
| 41 |
+
| "number"
|
| 42 |
+
| "bool"
|
| 43 |
+
| "date"
|
| 44 |
+
| "image";
|
| 45 |
+
latex_delimiters: {
|
| 46 |
+
left: string;
|
| 47 |
+
right: string;
|
| 48 |
+
display: boolean;
|
| 49 |
+
}[];
|
| 50 |
+
line_breaks?: boolean;
|
| 51 |
+
editable?: boolean;
|
| 52 |
+
is_static?: boolean;
|
| 53 |
+
max_chars?: number | null;
|
| 54 |
+
components?: Record<string, any>;
|
| 55 |
+
i18n: I18nFormatter;
|
| 56 |
+
is_dragging?: boolean;
|
| 57 |
+
wrap_text?: boolean;
|
| 58 |
+
show_selection_buttons?: boolean;
|
| 59 |
+
coords: [number, number];
|
| 60 |
+
on_select_column?: ((col: number) => void) | null;
|
| 61 |
+
on_select_row?: ((row: number) => void) | null;
|
| 62 |
+
el?: HTMLTextAreaElement | null;
|
| 63 |
+
onblur?: (detail: {
|
| 64 |
+
blur_event: FocusEvent;
|
| 65 |
+
coords: [number, number];
|
| 66 |
+
}) => void;
|
| 67 |
+
onkeydown?: (event: KeyboardEvent) => void;
|
| 68 |
+
} = $props();
|
| 69 |
|
| 70 |
function truncate_text(
|
| 71 |
text: CellValue,
|
|
|
|
| 79 |
return str.slice(0, max_length) + "...";
|
| 80 |
}
|
| 81 |
|
| 82 |
+
let should_truncate = $derived(!edit && max_chars !== null && max_chars > 0);
|
| 83 |
|
| 84 |
+
let display_content = $derived(
|
| 85 |
+
editable ? value : display_value !== null ? display_value : value
|
| 86 |
+
);
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
let display_text = $derived(
|
| 89 |
+
should_truncate
|
| 90 |
+
? truncate_text(display_content, max_chars, datatype === "image")
|
| 91 |
+
: display_content
|
| 92 |
+
);
|
| 93 |
|
| 94 |
function use_focus(node: HTMLTextAreaElement): any {
|
| 95 |
requestAnimationFrame(() => {
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
function handle_blur(event: FocusEvent): void {
|
| 103 |
+
onblur?.({
|
| 104 |
blur_event: event,
|
| 105 |
coords: coords
|
| 106 |
});
|
| 107 |
}
|
| 108 |
|
| 109 |
function handle_keydown(event: KeyboardEvent): void {
|
| 110 |
+
onkeydown?.(event);
|
| 111 |
}
|
| 112 |
|
| 113 |
function commit_change(checked: boolean): void {
|
| 114 |
handle_blur({ target: { value } } as unknown as FocusEvent);
|
| 115 |
}
|
| 116 |
|
| 117 |
+
$effect(() => {
|
| 118 |
+
if (!edit) {
|
| 119 |
+
// Shim blur on removal for Safari and Firefox
|
| 120 |
+
handle_blur({ target: { value } } as unknown as FocusEvent);
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
</script>
|
| 124 |
|
| 125 |
{#if edit && datatype !== "bool"}
|
|
|
|
| 131 |
bind:value
|
| 132 |
class:header
|
| 133 |
tabindex="-1"
|
| 134 |
+
onblur={handle_blur}
|
| 135 |
+
onmousedown={(e: MouseEvent) => e.stopPropagation()}
|
| 136 |
+
onclick={(e: MouseEvent) => e.stopPropagation()}
|
| 137 |
use:use_focus
|
| 138 |
+
onkeydown={handle_keydown}
|
| 139 |
/>
|
| 140 |
{/if}
|
| 141 |
|
|
|
|
| 144 |
{:else}
|
| 145 |
<span
|
| 146 |
class:dragging={is_dragging}
|
| 147 |
+
onkeydown={handle_keydown}
|
| 148 |
tabindex="0"
|
| 149 |
role="button"
|
| 150 |
class:edit
|
| 151 |
class:expanded={edit}
|
| 152 |
class:multiline={header}
|
| 153 |
+
onfocus={(e) => e.preventDefault()}
|
| 154 |
style={styling}
|
| 155 |
data-editable={editable}
|
| 156 |
data-max-chars={max_chars}
|
|
|
|
| 160 |
class:wrap={wrap_text}
|
| 161 |
>
|
| 162 |
{#if datatype === "image" && components.image}
|
| 163 |
+
{@const ImageComponent = components.image}
|
| 164 |
+
<ImageComponent
|
| 165 |
value={{ url: display_text }}
|
| 166 |
show_label={false}
|
| 167 |
label="cell-image"
|
|
|
|
| 226 |
span {
|
| 227 |
flex: 1 1 0%;
|
| 228 |
position: relative;
|
| 229 |
+
display: block;
|
| 230 |
outline: none;
|
| 231 |
-webkit-user-select: text;
|
| 232 |
-moz-user-select: text;
|
|
|
|
| 234 |
user-select: text;
|
| 235 |
cursor: text;
|
| 236 |
width: 100%;
|
| 237 |
+
overflow-wrap: break-word;
|
|
|
|
| 238 |
}
|
| 239 |
|
| 240 |
span.text.expanded {
|
6.11.0/dataframe/shared/EmptyRowButton.svelte
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
</script>
|
| 4 |
|
| 5 |
-
<button class="add-row-button"
|
| 6 |
+
|
| 7 |
</button>
|
| 8 |
|
|
|
|
| 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 |
|
6.11.0/dataframe/shared/FilterMenu.svelte
CHANGED
|
@@ -1,19 +1,23 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { onMount } from "svelte";
|
| 3 |
import { Check, DropdownArrow } from "@gradio/icons";
|
| 4 |
-
import type { FilterDatatype } from "./
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
let menu_element: HTMLDivElement;
|
| 13 |
-
let datatype: "string" | "number" = "string";
|
| 14 |
-
let current_filter = "Contains";
|
| 15 |
-
let filter_dropdown_open = false;
|
| 16 |
-
let filter_input_value = "";
|
| 17 |
|
| 18 |
const filter_options = {
|
| 19 |
string: [
|
|
@@ -59,7 +63,8 @@
|
|
| 59 |
<div class="filter-datatype-container">
|
| 60 |
<span>Filter as</span>
|
| 61 |
<button
|
| 62 |
-
|
|
|
|
| 63 |
datatype = datatype === "string" ? "number" : "string";
|
| 64 |
current_filter = filter_options[datatype][0];
|
| 65 |
}}
|
|
@@ -72,8 +77,10 @@
|
|
| 72 |
<div class="input-container">
|
| 73 |
<div class="filter-dropdown">
|
| 74 |
<button
|
| 75 |
-
|
| 76 |
-
(
|
|
|
|
|
|
|
| 77 |
aria-label={`Change filter. Using '${current_filter}'`}
|
| 78 |
>
|
| 79 |
{current_filter}
|
|
@@ -84,7 +91,8 @@
|
|
| 84 |
<div class="dropdown-filter-options">
|
| 85 |
{#each filter_options[datatype] as opt}
|
| 86 |
<button
|
| 87 |
-
|
|
|
|
| 88 |
current_filter = opt;
|
| 89 |
filter_dropdown_open = !filter_dropdown_open;
|
| 90 |
}}
|
|
@@ -100,8 +108,8 @@
|
|
| 100 |
<input
|
| 101 |
type="text"
|
| 102 |
value={filter_input_value}
|
| 103 |
-
|
| 104 |
-
|
| 105 |
placeholder="Type a value"
|
| 106 |
class="filter-input"
|
| 107 |
/>
|
|
@@ -109,7 +117,7 @@
|
|
| 109 |
|
| 110 |
<button
|
| 111 |
class="check-button"
|
| 112 |
-
|
| 113 |
>
|
| 114 |
<Check />
|
| 115 |
</button>
|
|
|
|
| 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: [
|
|
|
|
| 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 |
}}
|
|
|
|
| 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}
|
|
|
|
| 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 |
}}
|
|
|
|
| 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 |
/>
|
|
|
|
| 117 |
|
| 118 |
<button
|
| 119 |
class="check-button"
|
| 120 |
+
onclick={() => on_filter(datatype, current_filter, filter_input_value)}
|
| 121 |
>
|
| 122 |
<Check />
|
| 123 |
</button>
|
6.11.0/dataframe/shared/HeaderCell.svelte
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 type { I18nFormatter } from "js/core/src/gradio_helper";
|
| 9 |
+
import type { SortDirection } from "./types";
|
| 10 |
+
|
| 11 |
+
let {
|
| 12 |
+
value,
|
| 13 |
+
col_idx,
|
| 14 |
+
is_editing = false,
|
| 15 |
+
is_selected = false,
|
| 16 |
+
is_static = false,
|
| 17 |
+
sort_direction = null,
|
| 18 |
+
sort_priority = null,
|
| 19 |
+
multi_sort = false,
|
| 20 |
+
is_filtered = false,
|
| 21 |
+
show_menu_button = false,
|
| 22 |
+
is_first_column = false,
|
| 23 |
+
latex_delimiters,
|
| 24 |
+
line_breaks = true,
|
| 25 |
+
editable = true,
|
| 26 |
+
max_chars = undefined,
|
| 27 |
+
i18n,
|
| 28 |
+
onclick,
|
| 29 |
+
on_menu_click,
|
| 30 |
+
on_end_edit
|
| 31 |
+
}: {
|
| 32 |
+
value: string;
|
| 33 |
+
col_idx: number;
|
| 34 |
+
is_editing?: boolean;
|
| 35 |
+
is_selected?: boolean;
|
| 36 |
+
is_static?: boolean;
|
| 37 |
+
sort_direction?: SortDirection | null;
|
| 38 |
+
sort_priority?: number | null;
|
| 39 |
+
multi_sort?: boolean;
|
| 40 |
+
is_filtered?: boolean;
|
| 41 |
+
show_menu_button?: boolean;
|
| 42 |
+
is_first_column?: boolean;
|
| 43 |
+
latex_delimiters: { left: string; right: string; display: boolean }[];
|
| 44 |
+
line_breaks?: boolean;
|
| 45 |
+
editable?: boolean;
|
| 46 |
+
max_chars?: number | undefined;
|
| 47 |
+
i18n: I18nFormatter;
|
| 48 |
+
onclick: (event: MouseEvent, col: number) => void;
|
| 49 |
+
on_menu_click: (event: MouseEvent, col: number) => void;
|
| 50 |
+
on_end_edit: (key: string) => void;
|
| 51 |
+
} = $props();
|
| 52 |
+
</script>
|
| 53 |
+
|
| 54 |
+
<th
|
| 55 |
+
class="header-cell"
|
| 56 |
+
class:focus={is_editing || is_selected}
|
| 57 |
+
class:sorted={sort_direction !== null}
|
| 58 |
+
class:filtered={is_filtered}
|
| 59 |
+
class:first-column={is_first_column}
|
| 60 |
+
onclick={(e) => onclick(e, col_idx)}
|
| 61 |
+
onmousedown={(e) => {
|
| 62 |
+
e.preventDefault();
|
| 63 |
+
e.stopPropagation();
|
| 64 |
+
}}
|
| 65 |
+
title={value}
|
| 66 |
+
>
|
| 67 |
+
<div class="cell-wrap">
|
| 68 |
+
<div class="header-content">
|
| 69 |
+
<EditableCell
|
| 70 |
+
{value}
|
| 71 |
+
{latex_delimiters}
|
| 72 |
+
{line_breaks}
|
| 73 |
+
edit={is_editing}
|
| 74 |
+
onkeydown={(event) => {
|
| 75 |
+
if (["Enter", "Escape", "Tab"].includes(event.key)) {
|
| 76 |
+
on_end_edit(event.key);
|
| 77 |
+
}
|
| 78 |
+
}}
|
| 79 |
+
header
|
| 80 |
+
{editable}
|
| 81 |
+
{is_static}
|
| 82 |
+
{i18n}
|
| 83 |
+
{max_chars}
|
| 84 |
+
coords={[col_idx, 0]}
|
| 85 |
+
/>
|
| 86 |
+
</div>
|
| 87 |
+
{#if sort_direction || is_filtered || is_static}
|
| 88 |
+
<span class="header-icons">
|
| 89 |
+
{#if is_filtered}
|
| 90 |
+
<span class="filter-indicator" aria-label="Filtered">
|
| 91 |
+
<FilterIcon />
|
| 92 |
+
</span>
|
| 93 |
+
{/if}
|
| 94 |
+
{#if sort_direction}
|
| 95 |
+
<span
|
| 96 |
+
class="sort-indicator"
|
| 97 |
+
aria-label="Sorted {sort_direction}ending"
|
| 98 |
+
>
|
| 99 |
+
{#if sort_direction === "asc"}
|
| 100 |
+
<SortButtonUp size={13} />
|
| 101 |
+
{:else}
|
| 102 |
+
<SortButtonDown size={13} />
|
| 103 |
+
{/if}
|
| 104 |
+
{#if multi_sort && sort_priority != null}
|
| 105 |
+
<span class="sort-priority">{sort_priority}</span>
|
| 106 |
+
{/if}
|
| 107 |
+
</span>
|
| 108 |
+
{/if}
|
| 109 |
+
|
| 110 |
+
{#if is_static}
|
| 111 |
+
<Padlock size={11} />
|
| 112 |
+
{/if}
|
| 113 |
+
</span>
|
| 114 |
+
{/if}
|
| 115 |
+
{#if show_menu_button}
|
| 116 |
+
<CellMenuButton on_click={(e) => on_menu_click(e, col_idx)} />
|
| 117 |
+
{/if}
|
| 118 |
+
</div>
|
| 119 |
+
</th>
|
| 120 |
+
|
| 121 |
+
<style>
|
| 122 |
+
.header-cell {
|
| 123 |
+
--ring-color: transparent;
|
| 124 |
+
position: relative;
|
| 125 |
+
outline: none;
|
| 126 |
+
box-shadow:
|
| 127 |
+
inset 1px 0 0 var(--border-color-primary),
|
| 128 |
+
inset 0 0 0 1px var(--ring-color);
|
| 129 |
+
padding: 0;
|
| 130 |
+
background: var(--table-even-background-fill) !important;
|
| 131 |
+
font-weight: var(--weight-bold, 700);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.header-cell.first-column {
|
| 135 |
+
box-shadow: inset 0 0 0 1px var(--ring-color);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.header-cell:hover :global(.cell-menu-button),
|
| 139 |
+
.header-cell.focus :global(.cell-menu-button) {
|
| 140 |
+
display: flex;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
.header-cell.focus {
|
| 144 |
+
--ring-color: var(--color-accent);
|
| 145 |
+
box-shadow:
|
| 146 |
+
inset 1px 0 0 var(--border-color-primary),
|
| 147 |
+
inset 0 0 0 2px var(--ring-color);
|
| 148 |
+
z-index: 4;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
.header-cell.focus.first-column {
|
| 152 |
+
box-shadow: inset 0 0 0 2px var(--ring-color);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.header-content {
|
| 156 |
+
display: flex;
|
| 157 |
+
align-items: center;
|
| 158 |
+
gap: var(--size-1);
|
| 159 |
+
overflow: hidden;
|
| 160 |
+
min-width: 0;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.header-icons {
|
| 164 |
+
display: flex;
|
| 165 |
+
align-items: center;
|
| 166 |
+
gap: 2px;
|
| 167 |
+
flex-shrink: 0;
|
| 168 |
+
margin-left: auto;
|
| 169 |
+
opacity: 0.6;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
.sort-indicator {
|
| 173 |
+
display: flex;
|
| 174 |
+
align-items: center;
|
| 175 |
+
position: relative;
|
| 176 |
+
margin-left: -5px;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.sort-priority {
|
| 180 |
+
font-size: 8px;
|
| 181 |
+
background: var(--button-secondary-background-fill);
|
| 182 |
+
border-radius: var(--radius-full);
|
| 183 |
+
width: 12px;
|
| 184 |
+
height: 12px;
|
| 185 |
+
display: flex;
|
| 186 |
+
align-items: center;
|
| 187 |
+
justify-content: center;
|
| 188 |
+
line-height: 1;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.filter-indicator {
|
| 192 |
+
display: flex;
|
| 193 |
+
align-items: center;
|
| 194 |
+
width: 16px;
|
| 195 |
+
height: 16px;
|
| 196 |
+
margin-top: 3px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.filter-indicator :global(svg) {
|
| 200 |
+
width: 100%;
|
| 201 |
+
height: 100%;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.cell-wrap {
|
| 205 |
+
display: flex;
|
| 206 |
+
align-items: center;
|
| 207 |
+
justify-content: flex-start;
|
| 208 |
+
outline: none;
|
| 209 |
+
min-height: var(--size-9);
|
| 210 |
+
position: relative;
|
| 211 |
+
height: 100%;
|
| 212 |
+
padding: var(--size-2);
|
| 213 |
+
box-sizing: border-box;
|
| 214 |
+
gap: var(--size-1);
|
| 215 |
+
overflow: visible;
|
| 216 |
+
min-width: 0;
|
| 217 |
+
}
|
| 218 |
+
</style>
|
6.11.0/dataframe/shared/RowNumber.svelte
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
</script>
|
| 5 |
|
| 6 |
{#if is_header}
|
|
|
|
| 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}
|
6.11.0/dataframe/shared/Table.svelte
CHANGED
|
@@ -1,933 +1,839 @@
|
|
| 1 |
-
<script lang="ts" context="module">
|
| 2 |
-
import {
|
| 3 |
-
create_dataframe_context,
|
| 4 |
-
type SortDirection,
|
| 5 |
-
type FilterDatatype
|
| 6 |
-
} from "./context/dataframe_context";
|
| 7 |
-
</script>
|
| 8 |
-
|
| 9 |
<script lang="ts">
|
| 10 |
-
import {
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import { Upload } from "@gradio/upload";
|
| 13 |
|
| 14 |
-
import
|
| 15 |
-
import
|
| 16 |
-
import TableHeader from "./TableHeader.svelte";
|
| 17 |
-
import TableCell from "./TableCell.svelte";
|
| 18 |
import EmptyRowButton from "./EmptyRowButton.svelte";
|
| 19 |
import type { SelectData } from "@gradio/utils";
|
| 20 |
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
| 21 |
import { type Client } from "@gradio/client";
|
| 22 |
-
import
|
| 23 |
-
import
|
| 24 |
-
Headers,
|
| 25 |
-
DataframeValue,
|
| 26 |
-
Datatype,
|
| 27 |
-
EditData
|
| 28 |
-
} from "./utils/utils";
|
| 29 |
import CellMenu from "./CellMenu.svelte";
|
| 30 |
import Toolbar from "./Toolbar.svelte";
|
| 31 |
-
import type {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
import {
|
|
|
|
| 33 |
is_cell_selected,
|
| 34 |
-
|
| 35 |
-
get_current_indices,
|
| 36 |
-
handle_click_outside as handle_click_outside_util,
|
| 37 |
-
calculate_selection_positions
|
| 38 |
} from "./utils/selection_utils";
|
| 39 |
-
import {
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
max_chars
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
df_ctx.get_row = get_row;
|
| 125 |
-
df_ctx.dispatch = dispatch;
|
| 126 |
-
init_drag_handlers();
|
| 127 |
-
|
| 128 |
-
const observer = new IntersectionObserver((entries) => {
|
| 129 |
-
entries.forEach((entry) => {
|
| 130 |
-
if (entry.isIntersecting && !is_visible) {
|
| 131 |
-
width_calculated = false;
|
| 132 |
-
}
|
| 133 |
-
is_visible = entry.isIntersecting;
|
| 134 |
});
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
}
|
| 144 |
-
}
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
});
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
const dispatch = createEventDispatcher<{
|
| 166 |
-
change: DataframeValue;
|
| 167 |
-
input: undefined;
|
| 168 |
-
select: SelectData;
|
| 169 |
-
search: string | null;
|
| 170 |
-
edit: EditData;
|
| 171 |
-
}>();
|
| 172 |
-
|
| 173 |
-
let els: Record<
|
| 174 |
-
string,
|
| 175 |
-
{ cell: null | HTMLTableCellElement; input: null | HTMLTextAreaElement }
|
| 176 |
-
> = {};
|
| 177 |
-
let data_binding: Record<string, (typeof data)[0][0]> = {};
|
| 178 |
-
let _headers = make_headers(headers, col_count, els, make_id);
|
| 179 |
-
let old_headers: string[] = headers;
|
| 180 |
-
let data: { id: string; value: CellValue; display_value?: string }[][] = [[]];
|
| 181 |
-
let old_val: undefined | CellValue[][] = undefined;
|
| 182 |
-
let search_results: {
|
| 183 |
-
id: string;
|
| 184 |
-
value: CellValue;
|
| 185 |
-
display_value?: string;
|
| 186 |
-
styling?: string;
|
| 187 |
-
}[][] = [[]];
|
| 188 |
-
let dragging = false;
|
| 189 |
-
let color_accent_copied: string;
|
| 190 |
-
let filtered_to_original_map: number[] = [];
|
| 191 |
-
|
| 192 |
-
onMount(() => {
|
| 193 |
-
const color = getComputedStyle(document.documentElement)
|
| 194 |
-
.getPropertyValue("--color-accent")
|
| 195 |
-
.trim();
|
| 196 |
-
color_accent_copied = color + "40"; // 80 is 50% opacity in hex
|
| 197 |
-
document.documentElement.style.setProperty(
|
| 198 |
-
"--color-accent-copied",
|
| 199 |
-
color_accent_copied
|
| 200 |
-
);
|
| 201 |
});
|
| 202 |
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
| 207 |
-
data?.map((row) => row[col]?.value) ?? [];
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
|
|
|
| 211 |
|
| 212 |
-
|
| 213 |
-
if (!
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
}
|
| 217 |
}
|
| 218 |
|
| 219 |
-
function
|
| 220 |
-
return
|
| 221 |
}
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
(values.length !== old_val.length ||
|
| 234 |
-
(values[0] && old_val[0] && values[0].length !== old_val[0].length));
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
}
|
| 240 |
-
last_width_data_length = 0;
|
| 241 |
-
last_width_column_count = 0;
|
| 242 |
-
width_calculated = false;
|
| 243 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
}
|
| 245 |
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
(values.length !== old_val.length ||
|
| 252 |
-
(values[0] && old_val[0] && values[0].length !== old_val[0].length));
|
| 253 |
-
|
| 254 |
-
data = process_data(
|
| 255 |
-
values as CellValue[][],
|
| 256 |
-
els,
|
| 257 |
-
data_binding,
|
| 258 |
-
make_id,
|
| 259 |
-
display_value,
|
| 260 |
-
datatype
|
| 261 |
-
);
|
| 262 |
-
old_val = JSON.parse(JSON.stringify(values)) as CellValue[][];
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
} else if ($df_state.sort_state.sort_columns.length > 0) {
|
| 267 |
-
sort_data(data, display_value, styling);
|
| 268 |
-
} else {
|
| 269 |
-
df_actions.handle_sort(-1, "asc");
|
| 270 |
-
df_actions.reset_sort_state();
|
| 271 |
-
}
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
}
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
}
|
| 286 |
}
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
row
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
styling: styling?.[row_idx]?.[col_idx] || ""
|
| 310 |
-
});
|
| 311 |
});
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
const filtered = df_actions.filter_data(data);
|
| 315 |
-
|
| 316 |
-
search_results = filtered.map((row) =>
|
| 317 |
-
row.map((cell) => {
|
| 318 |
-
const original = cell_map.get(cell.id);
|
| 319 |
-
return {
|
| 320 |
-
...cell,
|
| 321 |
-
display_value:
|
| 322 |
-
original?.display_value !== undefined
|
| 323 |
-
? original.display_value
|
| 324 |
-
: String(cell.value),
|
| 325 |
-
styling: original?.styling || ""
|
| 326 |
-
};
|
| 327 |
-
})
|
| 328 |
-
);
|
| 329 |
-
} else {
|
| 330 |
-
filtered_to_original_map = [];
|
| 331 |
-
}
|
| 332 |
-
|
| 333 |
-
let previous_headers = _headers.map((h) => h.value);
|
| 334 |
-
let previous_data = data.map((row) => row.map((cell) => cell.value));
|
| 335 |
-
|
| 336 |
-
$: {
|
| 337 |
-
if (data || _headers) {
|
| 338 |
-
df_actions.trigger_change(
|
| 339 |
-
data,
|
| 340 |
-
_headers,
|
| 341 |
-
previous_data,
|
| 342 |
-
previous_headers,
|
| 343 |
-
value_is_output,
|
| 344 |
-
dispatch
|
| 345 |
-
);
|
| 346 |
-
previous_data = data.map((row) => row.map((cell) => cell.value));
|
| 347 |
-
previous_headers = _headers.map((h) => h.value);
|
| 348 |
}
|
| 349 |
}
|
| 350 |
|
| 351 |
-
function
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
}
|
| 355 |
|
| 356 |
-
function
|
| 357 |
-
|
| 358 |
-
|
|
|
|
|
|
|
| 359 |
}
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
}
|
|
|
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
}
|
| 370 |
}
|
| 371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
function handle_filter(
|
| 373 |
col: number,
|
| 374 |
-
|
| 375 |
filter: string,
|
| 376 |
-
|
| 377 |
): void {
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
}
|
| 381 |
|
| 382 |
function clear_filter(): void {
|
| 383 |
-
|
| 384 |
-
filter_data(data, display_value, styling);
|
| 385 |
}
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
}
|
| 391 |
|
| 392 |
-
function
|
| 393 |
-
if (
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
}
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
df_actions.handle_header_click(col, editable);
|
| 401 |
-
parent.focus();
|
| 402 |
}
|
| 403 |
|
| 404 |
-
function
|
| 405 |
-
if (!
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
const new_row = Array(data[0]?.length || headers.length)
|
| 416 |
-
.fill(0)
|
| 417 |
-
.map((_, i) => {
|
| 418 |
-
const _id = make_id();
|
| 419 |
-
els[_id] = { cell: null, input: null };
|
| 420 |
-
return { id: _id, value: "" };
|
| 421 |
-
});
|
| 422 |
-
|
| 423 |
-
if (data.length === 0) {
|
| 424 |
-
data = [new_row];
|
| 425 |
-
} else if (index !== undefined && index >= 0 && index <= data.length) {
|
| 426 |
-
data.splice(index, 0, new_row);
|
| 427 |
-
} else {
|
| 428 |
-
data.push(new_row);
|
| 429 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
}
|
| 433 |
|
| 434 |
-
|
| 435 |
-
parent.focus();
|
| 436 |
if (col_count[1] !== "dynamic") return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
if (!els[cell.id]) {
|
| 443 |
-
els[cell.id] = { cell: null, input: null };
|
| 444 |
-
}
|
| 445 |
-
});
|
| 446 |
-
});
|
| 447 |
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
| 450 |
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
| 457 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
}
|
| 459 |
|
| 460 |
function handle_click_outside(event: Event): void {
|
| 461 |
if (handle_click_outside_util(event, parent)) {
|
| 462 |
-
|
|
|
|
|
|
|
| 463 |
header_edit = false;
|
| 464 |
selected_header = false;
|
|
|
|
|
|
|
| 465 |
}
|
| 466 |
}
|
| 467 |
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
let width_calc_timeout: ReturnType<typeof setTimeout>;
|
| 471 |
-
$: if (cells[0] && cells[0]?.clientWidth) {
|
| 472 |
-
clearTimeout(width_calc_timeout);
|
| 473 |
-
width_calc_timeout = setTimeout(() => set_cell_widths(), 100);
|
| 474 |
-
}
|
| 475 |
-
|
| 476 |
-
let width_calculated = false;
|
| 477 |
-
$: if (cells[0] && !width_calculated) {
|
| 478 |
-
set_cell_widths();
|
| 479 |
-
width_calculated = true;
|
| 480 |
-
}
|
| 481 |
-
let cells: HTMLTableCellElement[] = [];
|
| 482 |
-
let parent: HTMLDivElement;
|
| 483 |
-
let table: HTMLTableElement;
|
| 484 |
-
let last_width_data_length = 0;
|
| 485 |
-
let last_width_column_count = 0;
|
| 486 |
-
|
| 487 |
-
function set_cell_widths(): void {
|
| 488 |
-
const column_count = data[0]?.length || 0;
|
| 489 |
-
if ($df_state.filter_state.filter_columns.length > 0) {
|
| 490 |
-
return;
|
| 491 |
-
}
|
| 492 |
-
if (
|
| 493 |
-
last_width_data_length === data.length &&
|
| 494 |
-
last_width_column_count === column_count &&
|
| 495 |
-
$df_state.sort_state.sort_columns.length > 0
|
| 496 |
-
) {
|
| 497 |
-
return;
|
| 498 |
-
}
|
| 499 |
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
}
|
| 503 |
|
| 504 |
-
|
| 505 |
-
|
| 506 |
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
}
|
| 524 |
-
}
|
| 525 |
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
const calculated_width = `${Math.max(width, 45)}px`;
|
| 529 |
-
parent.style.setProperty(`--cell-width-${i}`, calculated_width);
|
| 530 |
}
|
| 531 |
-
});
|
| 532 |
-
}
|
| 533 |
-
|
| 534 |
-
function get_cell_width(index: number): string {
|
| 535 |
-
return `var(--cell-width-${index})`;
|
| 536 |
-
}
|
| 537 |
-
|
| 538 |
-
let table_height: number =
|
| 539 |
-
values.slice(0, (max_height / values.length) * 37).length * 37 + 37;
|
| 540 |
-
let scrollbar_width = 0;
|
| 541 |
-
|
| 542 |
-
function sort_data(
|
| 543 |
-
_data: typeof data,
|
| 544 |
-
_display_value: string[][] | null,
|
| 545 |
-
_styling: string[][] | null
|
| 546 |
-
): void {
|
| 547 |
-
const result = sort_data_and_preserve_selection(
|
| 548 |
-
_data,
|
| 549 |
-
_display_value,
|
| 550 |
-
_styling,
|
| 551 |
-
$df_state.sort_state.sort_columns,
|
| 552 |
-
selected,
|
| 553 |
-
get_current_indices
|
| 554 |
-
);
|
| 555 |
-
|
| 556 |
-
data = result.data;
|
| 557 |
-
selected = result.selected;
|
| 558 |
-
}
|
| 559 |
-
|
| 560 |
-
function filter_data(
|
| 561 |
-
_data: typeof data,
|
| 562 |
-
_display_value: string[][] | null,
|
| 563 |
-
_styling: string[][] | null
|
| 564 |
-
): void {
|
| 565 |
-
const result = filter_data_and_preserve_selection(
|
| 566 |
-
_data,
|
| 567 |
-
_display_value,
|
| 568 |
-
_styling,
|
| 569 |
-
$df_state.filter_state.filter_columns,
|
| 570 |
-
selected,
|
| 571 |
-
get_current_indices,
|
| 572 |
-
$df_state.filter_state.initial_data?.data,
|
| 573 |
-
$df_state.filter_state.initial_data?.display_value,
|
| 574 |
-
$df_state.filter_state.initial_data?.styling
|
| 575 |
-
);
|
| 576 |
-
data = result.data;
|
| 577 |
-
selected = result.selected;
|
| 578 |
-
}
|
| 579 |
-
|
| 580 |
-
$: selected_index = !!selected && selected[0];
|
| 581 |
-
|
| 582 |
-
let is_visible = false;
|
| 583 |
-
|
| 584 |
-
const set_copy_flash = (value: boolean): void => {
|
| 585 |
-
df_actions.set_copy_flash(value);
|
| 586 |
-
if (value) {
|
| 587 |
-
setTimeout(() => df_actions.set_copy_flash(false), 800);
|
| 588 |
}
|
| 589 |
-
}
|
| 590 |
-
|
| 591 |
-
let previous_selected_cells: [number, number][] = [];
|
| 592 |
|
| 593 |
-
|
| 594 |
-
if (
|
| 595 |
-
|
| 596 |
}
|
| 597 |
-
previous_selected_cells = selected_cells;
|
| 598 |
}
|
| 599 |
|
| 600 |
-
function
|
| 601 |
-
|
| 602 |
-
blur_event: FocusEvent;
|
| 603 |
-
coords: [number, number];
|
| 604 |
-
}>
|
| 605 |
-
): void {
|
| 606 |
-
const { blur_event, coords } = event.detail;
|
| 607 |
-
handle_cell_blur(blur_event, df_ctx, coords);
|
| 608 |
}
|
| 609 |
|
| 610 |
-
function
|
| 611 |
event.stopPropagation();
|
| 612 |
-
if (
|
| 613 |
-
|
| 614 |
} else {
|
| 615 |
-
const
|
| 616 |
-
if (
|
| 617 |
-
const rect =
|
| 618 |
-
|
| 619 |
-
col,
|
| 620 |
-
x: rect.right,
|
| 621 |
-
y: rect.bottom
|
| 622 |
-
});
|
| 623 |
}
|
| 624 |
}
|
| 625 |
}
|
| 626 |
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
df_actions.set_active_header_menu(null);
|
| 641 |
-
df_actions.set_selected(false);
|
| 642 |
-
df_actions.set_selected_cells([]);
|
| 643 |
-
df_actions.set_editing(false);
|
| 644 |
-
}
|
| 645 |
-
|
| 646 |
-
function delete_row_at(index: number): void {
|
| 647 |
-
data = df_actions.delete_row_at(data, index);
|
| 648 |
-
df_actions.set_active_cell_menu(null);
|
| 649 |
-
df_actions.set_active_header_menu(null);
|
| 650 |
-
}
|
| 651 |
-
|
| 652 |
-
let selected_cell_coords: CellCoordinate;
|
| 653 |
-
$: if (selected !== false) selected_cell_coords = selected;
|
| 654 |
-
|
| 655 |
-
$: if (selected !== false) {
|
| 656 |
-
const positions = calculate_selection_positions(
|
| 657 |
-
selected,
|
| 658 |
-
data,
|
| 659 |
-
els,
|
| 660 |
-
parent,
|
| 661 |
-
table
|
| 662 |
-
);
|
| 663 |
-
document.documentElement.style.setProperty(
|
| 664 |
-
"--selected-col-pos",
|
| 665 |
-
positions.col_pos
|
| 666 |
-
);
|
| 667 |
-
document.documentElement.style.setProperty(
|
| 668 |
-
"--selected-row-pos",
|
| 669 |
-
positions.row_pos || "0px"
|
| 670 |
-
);
|
| 671 |
-
}
|
| 672 |
-
|
| 673 |
-
function commit_filter(): void {
|
| 674 |
-
if ($df_state.current_search_query && show_search === "filter") {
|
| 675 |
-
const filtered_data: CellValue[][] = [];
|
| 676 |
-
const filtered_display_values: string[][] = [];
|
| 677 |
-
const filtered_styling: string[][] = [];
|
| 678 |
-
|
| 679 |
-
search_results.forEach((row) => {
|
| 680 |
-
const data_row: CellValue[] = [];
|
| 681 |
-
const display_row: string[] = [];
|
| 682 |
-
const styling_row: string[] = [];
|
| 683 |
-
|
| 684 |
-
row.forEach((cell) => {
|
| 685 |
-
data_row.push(cell.value);
|
| 686 |
-
display_row.push(
|
| 687 |
-
cell.display_value !== undefined
|
| 688 |
-
? cell.display_value
|
| 689 |
-
: String(cell.value)
|
| 690 |
-
);
|
| 691 |
-
styling_row.push(cell.styling || "");
|
| 692 |
-
});
|
| 693 |
-
|
| 694 |
-
filtered_data.push(data_row);
|
| 695 |
-
filtered_display_values.push(display_row);
|
| 696 |
-
filtered_styling.push(styling_row);
|
| 697 |
-
});
|
| 698 |
-
|
| 699 |
-
const change_payload = {
|
| 700 |
-
data: filtered_data,
|
| 701 |
-
headers: _headers.map((h) => h.value),
|
| 702 |
-
metadata: {
|
| 703 |
-
display_value: filtered_display_values,
|
| 704 |
-
styling: filtered_styling
|
| 705 |
-
}
|
| 706 |
-
};
|
| 707 |
-
|
| 708 |
-
dispatch("change", change_payload);
|
| 709 |
-
|
| 710 |
-
if (!value_is_output) {
|
| 711 |
-
dispatch("input");
|
| 712 |
}
|
| 713 |
-
|
| 714 |
-
df_actions.handle_search(null);
|
| 715 |
-
}
|
| 716 |
-
}
|
| 717 |
-
|
| 718 |
-
let viewport: HTMLTableElement;
|
| 719 |
-
let show_scroll_button = false;
|
| 720 |
-
|
| 721 |
-
function scroll_to_top(): void {
|
| 722 |
-
viewport.scrollTo({
|
| 723 |
-
top: 0
|
| 724 |
-
});
|
| 725 |
-
}
|
| 726 |
-
|
| 727 |
-
function handle_resize(): void {
|
| 728 |
-
df_actions.set_active_cell_menu(null);
|
| 729 |
-
df_actions.set_active_header_menu(null);
|
| 730 |
-
selected_cells = [];
|
| 731 |
-
selected = false;
|
| 732 |
-
editing = false;
|
| 733 |
-
width_calculated = false;
|
| 734 |
-
set_cell_widths();
|
| 735 |
-
}
|
| 736 |
-
|
| 737 |
-
function add_row_at(index: number, position: "above" | "below"): void {
|
| 738 |
-
const row_index = position === "above" ? index : index + 1;
|
| 739 |
-
add_row(row_index);
|
| 740 |
-
active_cell_menu = null;
|
| 741 |
-
active_header_menu = null;
|
| 742 |
-
}
|
| 743 |
-
|
| 744 |
-
function add_col_at(index: number, position: "left" | "right"): void {
|
| 745 |
-
const col_index = position === "left" ? index : index + 1;
|
| 746 |
-
add_col(col_index);
|
| 747 |
-
active_cell_menu = null;
|
| 748 |
-
active_header_menu = null;
|
| 749 |
}
|
| 750 |
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
|
|
|
| 754 |
|
| 755 |
-
function
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
new_row[col] = {
|
| 760 |
-
...new_row[col],
|
| 761 |
-
value: checked
|
| 762 |
-
};
|
| 763 |
-
}
|
| 764 |
-
return new_row;
|
| 765 |
});
|
| 766 |
-
}
|
| 767 |
-
|
| 768 |
-
let is_dragging = false;
|
| 769 |
-
let drag_start: [number, number] | null = null;
|
| 770 |
-
let mouse_down_pos: { x: number; y: number } | null = null;
|
| 771 |
-
|
| 772 |
-
const drag_state: DragState = {
|
| 773 |
-
is_dragging,
|
| 774 |
-
drag_start,
|
| 775 |
-
mouse_down_pos
|
| 776 |
-
};
|
| 777 |
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
mouse_down_pos = drag_state.mouse_down_pos;
|
| 782 |
-
}
|
| 783 |
-
|
| 784 |
-
let drag_handlers: DragHandlers;
|
| 785 |
-
|
| 786 |
-
function init_drag_handlers(): void {
|
| 787 |
-
drag_handlers = create_drag_handlers(
|
| 788 |
-
drag_state,
|
| 789 |
-
(value) => (is_dragging = value),
|
| 790 |
-
(cells) => df_actions.set_selected_cells(cells),
|
| 791 |
-
(cell) => df_actions.set_selected(cell),
|
| 792 |
-
(event, row, col) => df_actions.handle_cell_click(event, row, col),
|
| 793 |
-
show_row_numbers,
|
| 794 |
-
parent
|
| 795 |
-
);
|
| 796 |
}
|
| 797 |
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 803 |
|
| 804 |
-
|
| 805 |
-
|
|
|
|
|
|
|
| 806 |
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
: String(search_results[row][col].value);
|
| 811 |
}
|
|
|
|
| 812 |
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
|
| 819 |
-
|
|
|
|
| 820 |
}
|
| 821 |
</script>
|
| 822 |
|
| 823 |
-
<svelte:window
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 824 |
|
| 825 |
-
<div class="table-container">
|
| 826 |
{#if (label && label.length !== 0 && show_label) || (buttons === null ? true : buttons.includes("fullscreen")) || (buttons === null ? true : buttons.includes("copy")) || show_search !== "none"}
|
| 827 |
<div class="header-row">
|
| 828 |
{#if label && label.length !== 0 && show_label}
|
| 829 |
-
<div class="label">
|
| 830 |
-
<p>{label}</p>
|
| 831 |
-
</div>
|
| 832 |
{/if}
|
| 833 |
<Toolbar
|
| 834 |
show_fullscreen_button={buttons === null
|
| 835 |
? true
|
| 836 |
: buttons.includes("fullscreen")}
|
| 837 |
{fullscreen}
|
| 838 |
-
on_copy={
|
| 839 |
show_copy_button={buttons === null ? true : buttons.includes("copy")}
|
| 840 |
{show_search}
|
| 841 |
-
|
| 842 |
-
|
| 843 |
on_commit_filter={commit_filter}
|
| 844 |
-
current_search_query={
|
| 845 |
/>
|
| 846 |
</div>
|
| 847 |
{/if}
|
|
|
|
| 848 |
<div
|
| 849 |
bind:this={parent}
|
| 850 |
class="table-wrap"
|
| 851 |
class:dragging={is_dragging}
|
| 852 |
class:no-wrap={!wrap}
|
| 853 |
class:menu-open={active_cell_menu || active_header_menu}
|
| 854 |
-
|
| 855 |
-
on:mousemove={handle_mouse_move}
|
| 856 |
-
on:mouseup={handle_mouse_up}
|
| 857 |
-
on:mouseleave={handle_mouse_up}
|
| 858 |
role="grid"
|
| 859 |
tabindex="0"
|
| 860 |
>
|
| 861 |
-
<table bind:this={table} aria-hidden="true">
|
| 862 |
-
{#if label && label.length !== 0}
|
| 863 |
-
<caption class="sr-only">{label}</caption>
|
| 864 |
-
{/if}
|
| 865 |
-
<thead>
|
| 866 |
-
<tr>
|
| 867 |
-
{#if show_row_numbers}
|
| 868 |
-
<RowNumber is_header={true} />
|
| 869 |
-
{/if}
|
| 870 |
-
{#each _headers as { value, id }, i (id)}
|
| 871 |
-
<TableHeader
|
| 872 |
-
bind:value={_headers[i].value}
|
| 873 |
-
{i}
|
| 874 |
-
{actual_pinned_columns}
|
| 875 |
-
{header_edit}
|
| 876 |
-
{selected_header}
|
| 877 |
-
{headers}
|
| 878 |
-
{get_cell_width}
|
| 879 |
-
{handle_header_click}
|
| 880 |
-
{toggle_header_menu}
|
| 881 |
-
{end_header_edit}
|
| 882 |
-
sort_columns={$df_state.sort_state.sort_columns}
|
| 883 |
-
filter_columns={$df_state.filter_state.filter_columns}
|
| 884 |
-
{latex_delimiters}
|
| 885 |
-
{line_breaks}
|
| 886 |
-
{max_chars}
|
| 887 |
-
{editable}
|
| 888 |
-
is_static={static_columns.includes(i)}
|
| 889 |
-
{i18n}
|
| 890 |
-
bind:el={els[id].input}
|
| 891 |
-
{col_count}
|
| 892 |
-
datatype={Array.isArray(datatype) ? datatype[i] : datatype}
|
| 893 |
-
{data}
|
| 894 |
-
on_select_all={handle_select_all}
|
| 895 |
-
/>
|
| 896 |
-
{/each}
|
| 897 |
-
</tr>
|
| 898 |
-
</thead>
|
| 899 |
-
<tbody>
|
| 900 |
-
<tr>
|
| 901 |
-
{#if show_row_numbers}
|
| 902 |
-
<RowNumber index={0} />
|
| 903 |
-
{/if}
|
| 904 |
-
{#each max as { value, id }, j (id)}
|
| 905 |
-
<td tabindex="-1" bind:this={cells[j]}>
|
| 906 |
-
<div class="cell-wrap">
|
| 907 |
-
<EditableCell
|
| 908 |
-
{value}
|
| 909 |
-
{latex_delimiters}
|
| 910 |
-
{line_breaks}
|
| 911 |
-
datatype={Array.isArray(datatype) ? datatype[j] : datatype}
|
| 912 |
-
edit={false}
|
| 913 |
-
el={null}
|
| 914 |
-
{editable}
|
| 915 |
-
{i18n}
|
| 916 |
-
show_selection_buttons={selected_cells.length === 1 &&
|
| 917 |
-
selected_cells[0][0] === 0 &&
|
| 918 |
-
selected_cells[0][1] === j}
|
| 919 |
-
coords={selected_cell_coords}
|
| 920 |
-
on_select_column={df_actions.handle_select_column}
|
| 921 |
-
on_select_row={df_actions.handle_select_row}
|
| 922 |
-
{is_dragging}
|
| 923 |
-
on:blur={handle_blur}
|
| 924 |
-
/>
|
| 925 |
-
</div>
|
| 926 |
-
</td>
|
| 927 |
-
{/each}
|
| 928 |
-
</tr>
|
| 929 |
-
</tbody>
|
| 930 |
-
</table>
|
| 931 |
<Upload
|
| 932 |
{upload}
|
| 933 |
{stream_handler}
|
|
@@ -936,125 +842,197 @@
|
|
| 936 |
boundedheight={false}
|
| 937 |
disable_click={true}
|
| 938 |
{root}
|
| 939 |
-
|
| 940 |
-
handle_file_upload(
|
| 941 |
-
detail.data,
|
| 942 |
-
(head) => {
|
| 943 |
-
_headers = make_headers(
|
| 944 |
-
head.map((h) => h ?? ""),
|
| 945 |
-
col_count,
|
| 946 |
-
els,
|
| 947 |
-
make_id
|
| 948 |
-
);
|
| 949 |
-
return _headers;
|
| 950 |
-
},
|
| 951 |
-
(vals) => {
|
| 952 |
-
values = vals;
|
| 953 |
-
}
|
| 954 |
-
)}
|
| 955 |
bind:dragging
|
| 956 |
aria_label={i18n("dataframe.drop_to_upload")}
|
| 957 |
>
|
| 958 |
-
<div
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 975 |
{/if}
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
{
|
| 993 |
-
{
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
{
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
{/if}
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
bind:value={search_results[index][j].value}
|
| 1011 |
-
display_value={get_cell_display_value(index, j)}
|
| 1012 |
-
index={$df_state.current_search_query !== undefined &&
|
| 1013 |
-
filtered_to_original_map[index] !== undefined
|
| 1014 |
-
? filtered_to_original_map[index]
|
| 1015 |
-
: index}
|
| 1016 |
-
{j}
|
| 1017 |
-
{actual_pinned_columns}
|
| 1018 |
-
{get_cell_width}
|
| 1019 |
-
handle_cell_click={(e, r, c) => handle_mouse_down(e, r, c)}
|
| 1020 |
-
{handle_blur}
|
| 1021 |
-
toggle_cell_menu={df_actions.toggle_cell_menu}
|
| 1022 |
-
{is_cell_selected}
|
| 1023 |
-
{should_show_cell_menu}
|
| 1024 |
-
{selected_cells}
|
| 1025 |
-
{copy_flash}
|
| 1026 |
-
{active_cell_menu}
|
| 1027 |
-
styling={search_results[index][j].styling}
|
| 1028 |
-
{latex_delimiters}
|
| 1029 |
-
{line_breaks}
|
| 1030 |
-
datatype={Array.isArray(datatype) ? datatype[j] : datatype}
|
| 1031 |
-
{editing}
|
| 1032 |
-
{max_chars}
|
| 1033 |
-
{editable}
|
| 1034 |
-
is_static={static_columns.includes(j)}
|
| 1035 |
-
{i18n}
|
| 1036 |
-
{components}
|
| 1037 |
-
handle_select_column={df_actions.handle_select_column}
|
| 1038 |
-
handle_select_row={df_actions.handle_select_row}
|
| 1039 |
-
bind:el={els[id]}
|
| 1040 |
-
{is_dragging}
|
| 1041 |
-
{wrap}
|
| 1042 |
-
/>
|
| 1043 |
-
{/each}
|
| 1044 |
-
</tr>
|
| 1045 |
-
</VirtualTable>
|
| 1046 |
</div>
|
| 1047 |
</Upload>
|
|
|
|
| 1048 |
{#if show_scroll_button}
|
| 1049 |
-
<button class="scroll-top-button"
|
| 1050 |
-
↑
|
| 1051 |
-
</button>
|
| 1052 |
{/if}
|
| 1053 |
</div>
|
| 1054 |
</div>
|
| 1055 |
-
{#if data.length === 0 && editable && row_count[1] === "dynamic"}
|
| 1056 |
-
<EmptyRowButton on_click={() => add_row()} />
|
| 1057 |
-
{/if}
|
| 1058 |
|
| 1059 |
{#if active_cell_menu || active_header_menu}
|
| 1060 |
<CellMenu
|
|
@@ -1079,66 +1057,96 @@
|
|
| 1079 |
on_delete_col={() =>
|
| 1080 |
delete_col_at(active_cell_menu?.col ?? active_header_menu?.col ?? -1)}
|
| 1081 |
{editable}
|
| 1082 |
-
can_delete_rows={!active_header_menu &&
|
| 1083 |
-
can_delete_cols={
|
|
|
|
|
|
|
| 1084 |
{i18n}
|
| 1085 |
on_sort={active_header_menu
|
| 1086 |
? (direction) => {
|
| 1087 |
-
|
| 1088 |
-
|
| 1089 |
-
df_actions.set_active_header_menu(null);
|
| 1090 |
-
}
|
| 1091 |
}
|
| 1092 |
: undefined}
|
| 1093 |
on_clear_sort={active_header_menu
|
| 1094 |
? () => {
|
| 1095 |
clear_sort();
|
| 1096 |
-
|
| 1097 |
}
|
| 1098 |
: undefined}
|
| 1099 |
sort_direction={active_header_menu
|
| 1100 |
-
? (
|
| 1101 |
-
(item) => item.col === (active_header_menu?.col ?? -1)
|
| 1102 |
-
)?.direction ?? null)
|
| 1103 |
: null}
|
| 1104 |
sort_priority={active_header_menu
|
| 1105 |
-
?
|
| 1106 |
-
(item) => item.col === (active_header_menu?.col ?? -1)
|
| 1107 |
-
) + 1 || null
|
| 1108 |
: null}
|
| 1109 |
on_filter={active_header_menu
|
| 1110 |
-
? (
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
df_actions.set_active_header_menu(null);
|
| 1114 |
-
}
|
| 1115 |
}
|
| 1116 |
: undefined}
|
| 1117 |
on_clear_filter={active_header_menu
|
| 1118 |
? () => {
|
| 1119 |
clear_filter();
|
| 1120 |
-
|
| 1121 |
}
|
| 1122 |
: undefined}
|
| 1123 |
filter_active={active_header_menu
|
| 1124 |
-
?
|
| 1125 |
-
(c) => c.col === (active_header_menu?.col ?? -1)
|
| 1126 |
-
)
|
| 1127 |
: null}
|
| 1128 |
/>
|
| 1129 |
{/if}
|
| 1130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1131 |
<style>
|
| 1132 |
.table-container {
|
| 1133 |
display: flex;
|
| 1134 |
flex-direction: column;
|
| 1135 |
gap: var(--size-2);
|
| 1136 |
position: relative;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1137 |
}
|
| 1138 |
|
| 1139 |
.table-wrap {
|
| 1140 |
position: relative;
|
| 1141 |
transition: 150ms;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1142 |
}
|
| 1143 |
|
| 1144 |
.table-wrap.menu-open {
|
|
@@ -1165,60 +1173,147 @@
|
|
| 1165 |
overflow: hidden;
|
| 1166 |
}
|
| 1167 |
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
|
| 1172 |
-
|
| 1173 |
-
|
| 1174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1175 |
color: var(--body-text-color);
|
| 1176 |
font-size: var(--input-text-size);
|
| 1177 |
line-height: var(--line-md);
|
| 1178 |
font-family: var(--font-mono);
|
| 1179 |
border-spacing: 0;
|
| 1180 |
border-collapse: separate;
|
| 1181 |
-
|
| 1182 |
-
|
| 1183 |
-
thead {
|
| 1184 |
position: sticky;
|
| 1185 |
top: 0;
|
| 1186 |
-
z-index:
|
| 1187 |
-
|
| 1188 |
}
|
| 1189 |
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
background: var(--table-even-background-fill) !important;
|
| 1194 |
}
|
| 1195 |
|
| 1196 |
-
.
|
| 1197 |
-
|
|
|
|
|
|
|
| 1198 |
}
|
| 1199 |
|
| 1200 |
-
|
| 1201 |
-
|
|
|
|
| 1202 |
}
|
| 1203 |
|
| 1204 |
-
|
| 1205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1206 |
}
|
| 1207 |
|
| 1208 |
-
|
| 1209 |
-
|
| 1210 |
}
|
| 1211 |
|
| 1212 |
-
|
| 1213 |
background: var(--table-even-background-fill);
|
| 1214 |
}
|
| 1215 |
|
| 1216 |
-
|
| 1217 |
-
background: var(--table-
|
| 1218 |
}
|
| 1219 |
|
| 1220 |
-
|
| 1221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1222 |
}
|
| 1223 |
|
| 1224 |
.header-row {
|
|
@@ -1242,8 +1337,6 @@
|
|
| 1242 |
color: var(--block-label-text-color);
|
| 1243 |
font-size: var(--block-label-text-size);
|
| 1244 |
line-height: var(--line-sm);
|
| 1245 |
-
position: relative;
|
| 1246 |
-
z-index: 4;
|
| 1247 |
}
|
| 1248 |
|
| 1249 |
.scroll-top-button {
|
|
@@ -1268,9 +1361,4 @@
|
|
| 1268 |
.scroll-top-button:hover {
|
| 1269 |
opacity: 1;
|
| 1270 |
}
|
| 1271 |
-
|
| 1272 |
-
tr {
|
| 1273 |
-
border-bottom: 1px solid var(--border-color-primary);
|
| 1274 |
-
text-align: left;
|
| 1275 |
-
}
|
| 1276 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 HeaderCell from "./HeaderCell.svelte";
|
| 17 |
+
import DataCell from "./DataCell.svelte";
|
|
|
|
|
|
|
| 18 |
import EmptyRowButton from "./EmptyRowButton.svelte";
|
| 19 |
import type { SelectData } from "@gradio/utils";
|
| 20 |
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
| 21 |
import { type Client } from "@gradio/client";
|
| 22 |
+
import type { Datatype, DataframeValue, EditData } from "./utils/utils";
|
| 23 |
+
import { cast_value_to_type } from "./utils/utils";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
import CellMenu from "./CellMenu.svelte";
|
| 25 |
import Toolbar from "./Toolbar.svelte";
|
| 26 |
+
import type {
|
| 27 |
+
CellValue,
|
| 28 |
+
CellCoordinate,
|
| 29 |
+
SortDirection,
|
| 30 |
+
FilterDatatype
|
| 31 |
+
} from "./types";
|
| 32 |
import {
|
| 33 |
+
is_cell_in_selection,
|
| 34 |
is_cell_selected,
|
| 35 |
+
handle_click_outside as handle_click_outside_util
|
|
|
|
|
|
|
|
|
|
| 36 |
} from "./utils/selection_utils";
|
| 37 |
+
import { copy_table_data, handle_file_upload } from "./utils/table_utils";
|
| 38 |
+
import { gradio_filter_fn } from "./utils/filter";
|
| 39 |
+
import { create_column_measurement } from "./column_measurement.svelte.js";
|
| 40 |
+
|
| 41 |
+
let {
|
| 42 |
+
datatype,
|
| 43 |
+
label = null,
|
| 44 |
+
show_label = true,
|
| 45 |
+
headers = $bindable([]),
|
| 46 |
+
values = $bindable([]),
|
| 47 |
+
col_count,
|
| 48 |
+
row_count,
|
| 49 |
+
latex_delimiters,
|
| 50 |
+
components = {},
|
| 51 |
+
editable = true,
|
| 52 |
+
wrap = false,
|
| 53 |
+
root,
|
| 54 |
+
i18n,
|
| 55 |
+
max_height = 500,
|
| 56 |
+
line_breaks = true,
|
| 57 |
+
column_widths = [],
|
| 58 |
+
show_row_numbers = false,
|
| 59 |
+
upload,
|
| 60 |
+
stream_handler,
|
| 61 |
+
buttons = null,
|
| 62 |
+
value_is_output = $bindable(false),
|
| 63 |
+
max_chars = undefined,
|
| 64 |
+
show_search = "none",
|
| 65 |
+
pinned_columns = 0,
|
| 66 |
+
static_columns = [],
|
| 67 |
+
fullscreen = false,
|
| 68 |
+
display_value = null,
|
| 69 |
+
styling = null,
|
| 70 |
+
onchange,
|
| 71 |
+
oninput,
|
| 72 |
+
onselect,
|
| 73 |
+
onedit,
|
| 74 |
+
onsearch,
|
| 75 |
+
onfullscreen
|
| 76 |
+
}: {
|
| 77 |
+
datatype: Datatype | Datatype[];
|
| 78 |
+
label?: string | null;
|
| 79 |
+
show_label?: boolean;
|
| 80 |
+
headers?: (string | null)[];
|
| 81 |
+
values?: CellValue[][];
|
| 82 |
+
col_count: [number, "fixed" | "dynamic"];
|
| 83 |
+
row_count: [number, "fixed" | "dynamic"];
|
| 84 |
+
latex_delimiters: { left: string; right: string; display: boolean }[];
|
| 85 |
+
components?: Record<string, any>;
|
| 86 |
+
editable?: boolean;
|
| 87 |
+
wrap?: boolean;
|
| 88 |
+
root: string;
|
| 89 |
+
i18n: I18nFormatter;
|
| 90 |
+
max_height?: number;
|
| 91 |
+
line_breaks?: boolean;
|
| 92 |
+
column_widths?: string[];
|
| 93 |
+
show_row_numbers?: boolean;
|
| 94 |
+
upload: Client["upload"];
|
| 95 |
+
stream_handler: Client["stream"];
|
| 96 |
+
buttons?: string[] | null;
|
| 97 |
+
value_is_output?: boolean;
|
| 98 |
+
max_chars?: number | undefined;
|
| 99 |
+
show_search?: "none" | "search" | "filter";
|
| 100 |
+
pinned_columns?: number;
|
| 101 |
+
static_columns?: (string | number)[];
|
| 102 |
+
fullscreen?: boolean;
|
| 103 |
+
display_value?: string[][] | null;
|
| 104 |
+
styling?: string[][] | null;
|
| 105 |
+
onchange?: (detail: DataframeValue) => void;
|
| 106 |
+
oninput?: () => void;
|
| 107 |
+
onselect?: (detail: SelectData) => void;
|
| 108 |
+
onedit?: (detail: EditData) => void;
|
| 109 |
+
onsearch?: (detail: string | null) => void;
|
| 110 |
+
onfullscreen?: () => void;
|
| 111 |
+
} = $props();
|
| 112 |
+
|
| 113 |
+
type GradioRow = Record<string, CellValue> & { _index: number };
|
| 114 |
+
|
| 115 |
+
// convert values[][] into tanstack row objects
|
| 116 |
+
let row_data: GradioRow[] = $derived(
|
| 117 |
+
(values ?? []).map((row, i) => {
|
| 118 |
+
const obj: GradioRow = { _index: i };
|
| 119 |
+
(row ?? []).forEach((val, j) => {
|
| 120 |
+
const dtype = Array.isArray(datatype) ? datatype[j] : datatype;
|
| 121 |
+
obj[`col_${j}`] = cast_value_to_type(val, dtype);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
});
|
| 123 |
+
return obj;
|
| 124 |
+
})
|
| 125 |
+
);
|
| 126 |
+
|
| 127 |
+
let resolved_headers = $derived.by(() => {
|
| 128 |
+
let h = headers ?? [];
|
| 129 |
+
if (col_count[1] === "fixed" && h.length < col_count[0]) {
|
| 130 |
+
h = [
|
| 131 |
+
...h,
|
| 132 |
+
...Array(col_count[0] - h.length)
|
| 133 |
+
.fill(null)
|
| 134 |
+
.map((_, i) => `${i + h.length}`)
|
| 135 |
+
];
|
| 136 |
+
}
|
| 137 |
+
if (!h.length) {
|
| 138 |
+
h = Array(col_count[0])
|
| 139 |
+
.fill(null)
|
| 140 |
+
.map((_, i) => `${i}`);
|
| 141 |
+
}
|
| 142 |
+
return h.map((v) => v ?? "");
|
| 143 |
+
});
|
| 144 |
|
| 145 |
+
let column_defs: ColumnDef<GradioRow, CellValue>[] = $derived(
|
| 146 |
+
resolved_headers.map((header_value, j) => ({
|
| 147 |
+
id: `col_${j}`,
|
| 148 |
+
accessorKey: `col_${j}`,
|
| 149 |
+
header: header_value,
|
| 150 |
+
size: column_widths[j] ? parseInt(column_widths[j]) || 150 : 150,
|
| 151 |
+
minSize: 45,
|
| 152 |
+
filterFn: gradio_filter_fn,
|
| 153 |
+
meta: {
|
| 154 |
+
colIndex: j,
|
| 155 |
+
datatype: Array.isArray(datatype) ? datatype[j] : datatype,
|
| 156 |
+
isStatic:
|
| 157 |
+
static_columns.includes(j) || static_columns.includes(header_value),
|
| 158 |
+
isPinned: j < pinned_columns
|
| 159 |
}
|
| 160 |
+
}))
|
| 161 |
+
);
|
| 162 |
+
|
| 163 |
+
let sorting: SortingState = $state([]);
|
| 164 |
+
let column_filters: ColumnFiltersState = $state([]);
|
| 165 |
+
let global_filter: string = $state("");
|
| 166 |
+
let column_pinning: ColumnPinningState = $derived({
|
| 167 |
+
left: column_defs.filter((_, i) => i < pinned_columns).map((c) => c.id!)
|
| 168 |
+
});
|
| 169 |
|
| 170 |
+
const table = createSvelteTable<GradioRow>({
|
| 171 |
+
get data() {
|
| 172 |
+
return row_data;
|
| 173 |
+
},
|
| 174 |
+
get columns() {
|
| 175 |
+
return column_defs;
|
| 176 |
+
},
|
| 177 |
+
state: {
|
| 178 |
+
get sorting() {
|
| 179 |
+
return sorting;
|
| 180 |
+
},
|
| 181 |
+
get columnFilters() {
|
| 182 |
+
return column_filters;
|
| 183 |
+
},
|
| 184 |
+
get globalFilter() {
|
| 185 |
+
return global_filter;
|
| 186 |
+
},
|
| 187 |
+
get columnPinning() {
|
| 188 |
+
return column_pinning;
|
| 189 |
+
}
|
| 190 |
+
},
|
| 191 |
+
onSortingChange: (updater) => {
|
| 192 |
+
sorting = typeof updater === "function" ? updater(sorting) : updater;
|
| 193 |
+
},
|
| 194 |
+
onColumnFiltersChange: (updater) => {
|
| 195 |
+
column_filters =
|
| 196 |
+
typeof updater === "function" ? updater(column_filters) : updater;
|
| 197 |
+
},
|
| 198 |
+
onGlobalFilterChange: (updater) => {
|
| 199 |
+
global_filter =
|
| 200 |
+
typeof updater === "function" ? updater(global_filter) : updater;
|
| 201 |
+
},
|
| 202 |
+
getCoreRowModel: getCoreRowModel(),
|
| 203 |
+
getSortedRowModel: getSortedRowModel(),
|
| 204 |
+
getFilteredRowModel: getFilteredRowModel(),
|
| 205 |
+
globalFilterFn: "includesString",
|
| 206 |
+
enableSorting: true,
|
| 207 |
+
enableMultiSort: true,
|
| 208 |
+
maxMultiSortColCount: 3
|
| 209 |
});
|
| 210 |
|
| 211 |
+
let rows = $derived(table.getRowModel().rows);
|
| 212 |
+
let header_groups = $derived(table.getHeaderGroups());
|
| 213 |
+
|
| 214 |
+
let scroll_container: HTMLDivElement;
|
| 215 |
+
|
| 216 |
+
const virtualizer = createSvelteVirtualizer<
|
| 217 |
+
HTMLDivElement,
|
| 218 |
+
HTMLTableRowElement
|
| 219 |
+
>({
|
| 220 |
+
get count() {
|
| 221 |
+
return rows.length;
|
| 222 |
+
},
|
| 223 |
+
getScrollElement: () => scroll_container,
|
| 224 |
+
estimateSize: () => 35,
|
| 225 |
+
overscan: 10,
|
| 226 |
+
measureElement: (el, _entry, instance) => {
|
| 227 |
+
const h = el.getBoundingClientRect().height;
|
| 228 |
+
if (h > 0) return h;
|
| 229 |
+
|
| 230 |
+
const idx = el.getAttribute("data-index");
|
| 231 |
+
if (idx != null) {
|
| 232 |
+
const cached = (instance as any).itemSizeCache?.get(Number(idx));
|
| 233 |
+
if (typeof cached === "number") return cached;
|
| 234 |
+
}
|
| 235 |
+
return 35;
|
| 236 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
});
|
| 238 |
|
| 239 |
+
let virtual_items = $derived(virtualizer.virtualItems());
|
| 240 |
+
let total_size = $derived(virtualizer.totalSize());
|
| 241 |
+
|
| 242 |
+
let selected_cells: CellCoordinate[] = $state([]);
|
| 243 |
+
let selected: CellCoordinate | false = $state(false);
|
| 244 |
+
let editing: CellCoordinate | false = $state(false);
|
| 245 |
+
let header_edit: number | false = $state(false);
|
| 246 |
+
let selected_header: number | false = $state(false);
|
| 247 |
+
let active_cell_menu: {
|
| 248 |
+
row: number;
|
| 249 |
+
col: number;
|
| 250 |
+
x: number;
|
| 251 |
+
y: number;
|
| 252 |
+
} | null = $state(null);
|
| 253 |
+
let active_header_menu: { col: number; x: number; y: number } | null =
|
| 254 |
+
$state(null);
|
| 255 |
+
let copy_flash = $state(false);
|
| 256 |
+
let is_dragging = $state(false);
|
| 257 |
+
let show_scroll_button = $state(false);
|
| 258 |
+
let dragging = $state(false); // file drag
|
| 259 |
|
| 260 |
+
let parent: HTMLDivElement;
|
|
|
|
| 261 |
|
| 262 |
+
function get_dtype(col: number): Datatype {
|
| 263 |
+
return Array.isArray(datatype) ? (datatype[col] ?? "str") : datatype;
|
| 264 |
+
}
|
| 265 |
|
| 266 |
+
function get_display_value(row: number, col: number): string {
|
| 267 |
+
if (display_value?.[row]?.[col] !== undefined)
|
| 268 |
+
return display_value[row][col];
|
| 269 |
+
return String(values?.[row]?.[col] ?? "");
|
|
|
|
| 270 |
}
|
| 271 |
|
| 272 |
+
function get_styling(row: number, col: number): string {
|
| 273 |
+
return styling?.[row]?.[col] ?? "";
|
| 274 |
}
|
| 275 |
|
| 276 |
+
function push_change(
|
| 277 |
+
new_values?: CellValue[][],
|
| 278 |
+
new_headers?: (string | null)[]
|
| 279 |
+
): void {
|
| 280 |
+
onchange?.({
|
| 281 |
+
data: new_values ?? values,
|
| 282 |
+
headers: (new_headers ?? resolved_headers) as string[],
|
| 283 |
+
metadata: null
|
| 284 |
+
});
|
| 285 |
+
if (!value_is_output) oninput?.();
|
| 286 |
+
value_is_output = false;
|
| 287 |
+
}
|
| 288 |
|
| 289 |
+
function handle_cell_click(
|
| 290 |
+
event: MouseEvent,
|
| 291 |
+
row: number,
|
| 292 |
+
col: number
|
| 293 |
+
): void {
|
| 294 |
+
event.preventDefault();
|
| 295 |
+
event.stopPropagation();
|
|
|
|
|
|
|
| 296 |
|
| 297 |
+
const coord: CellCoordinate = [row, col];
|
| 298 |
+
if (event.shiftKey && selected) {
|
| 299 |
+
// range select
|
| 300 |
+
const [r1, c1] = selected;
|
| 301 |
+
const [r2, c2] = coord;
|
| 302 |
+
const new_cells: CellCoordinate[] = [];
|
| 303 |
+
for (let r = Math.min(r1, r2); r <= Math.max(r1, r2); r++) {
|
| 304 |
+
for (let c = Math.min(c1, c2); c <= Math.max(c1, c2); c++) {
|
| 305 |
+
new_cells.push([r, c]);
|
| 306 |
}
|
|
|
|
|
|
|
|
|
|
| 307 |
}
|
| 308 |
+
selected_cells = new_cells;
|
| 309 |
+
} else if (event.metaKey || event.ctrlKey) {
|
| 310 |
+
// toggle select
|
| 311 |
+
const exists = selected_cells.some(([r, c]) => r === row && c === col);
|
| 312 |
+
selected_cells = exists
|
| 313 |
+
? selected_cells.filter(([r, c]) => !(r === row && c === col))
|
| 314 |
+
: [...selected_cells, coord];
|
| 315 |
+
} else {
|
| 316 |
+
selected_cells = [coord];
|
| 317 |
}
|
| 318 |
|
| 319 |
+
selected = coord;
|
| 320 |
+
header_edit = false;
|
| 321 |
+
selected_header = false;
|
| 322 |
+
active_cell_menu = null;
|
| 323 |
+
active_header_menu = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
+
// click selects, does NOT enter edit mode (double-click or typing does)
|
| 326 |
+
editing = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
+
onselect?.({
|
| 329 |
+
index: coord,
|
| 330 |
+
value: values?.[row]?.[col],
|
| 331 |
+
row_value: values?.[row] ?? [],
|
| 332 |
+
col_value: values?.map((r) => r[col]) ?? []
|
| 333 |
+
} as any);
|
| 334 |
|
| 335 |
+
tick().then(() => parent?.focus());
|
| 336 |
+
}
|
|
|
|
| 337 |
|
| 338 |
+
function handle_cell_dblclick(
|
| 339 |
+
event: MouseEvent,
|
| 340 |
+
row: number,
|
| 341 |
+
col: number
|
| 342 |
+
): void {
|
| 343 |
+
event.preventDefault();
|
| 344 |
+
event.stopPropagation();
|
| 345 |
+
if (!editable) return;
|
| 346 |
+
const col_is_static =
|
| 347 |
+
static_columns.includes(col) ||
|
| 348 |
+
static_columns.includes(resolved_headers[col]);
|
| 349 |
+
if (!col_is_static) {
|
| 350 |
+
editing = [row, col];
|
| 351 |
}
|
| 352 |
}
|
| 353 |
|
| 354 |
+
function handle_blur(detail: {
|
| 355 |
+
blur_event: FocusEvent;
|
| 356 |
+
coords: [number, number];
|
| 357 |
+
}): void {
|
| 358 |
+
const { coords } = detail;
|
| 359 |
+
const input_el = detail.blur_event.target as HTMLTextAreaElement;
|
| 360 |
+
if (!input_el || input_el.value === undefined) return;
|
| 361 |
+
|
| 362 |
+
const [row, col] = coords;
|
| 363 |
+
const old_value = values?.[row]?.[col];
|
| 364 |
+
const new_value = input_el.value;
|
| 365 |
+
|
| 366 |
+
if (String(old_value) !== String(new_value)) {
|
| 367 |
+
const new_values = values.map((r) => [...r]);
|
| 368 |
+
new_values[row][col] = new_value;
|
| 369 |
+
values = new_values;
|
| 370 |
+
|
| 371 |
+
onedit?.({
|
| 372 |
+
index: [row, col],
|
| 373 |
+
value: new_value,
|
| 374 |
+
previous_value: String(old_value ?? "")
|
|
|
|
|
|
|
| 375 |
});
|
| 376 |
+
push_change(new_values);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
}
|
| 378 |
}
|
| 379 |
|
| 380 |
+
function handle_header_click(event: MouseEvent, col: number): void {
|
| 381 |
+
if (event.target instanceof HTMLAnchorElement) return;
|
| 382 |
+
event.preventDefault();
|
| 383 |
+
event.stopPropagation();
|
| 384 |
+
if (!editable) return;
|
| 385 |
+
|
| 386 |
+
editing = false;
|
| 387 |
+
selected = false;
|
| 388 |
+
selected_cells = [];
|
| 389 |
+
active_cell_menu = null;
|
| 390 |
+
active_header_menu = null;
|
| 391 |
+
selected_header = col;
|
| 392 |
+
header_edit = editable ? col : false;
|
| 393 |
+
parent?.focus();
|
| 394 |
}
|
| 395 |
|
| 396 |
+
function end_header_edit(key: string): void {
|
| 397 |
+
if (["Escape", "Enter", "Tab"].includes(key)) {
|
| 398 |
+
header_edit = false;
|
| 399 |
+
parent?.focus();
|
| 400 |
+
}
|
| 401 |
}
|
| 402 |
|
| 403 |
+
function toggle_header_menu(event: MouseEvent, col: number): void {
|
| 404 |
+
event.stopPropagation();
|
| 405 |
+
if (active_header_menu?.col === col) {
|
| 406 |
+
active_header_menu = null;
|
| 407 |
+
} else {
|
| 408 |
+
const th = (event.target as HTMLElement).closest("th");
|
| 409 |
+
if (th) {
|
| 410 |
+
const rect = th.getBoundingClientRect();
|
| 411 |
+
active_header_menu = { col, x: rect.right, y: rect.bottom };
|
| 412 |
+
}
|
| 413 |
}
|
| 414 |
+
}
|
| 415 |
|
| 416 |
+
function handle_sort(col: number, direction: SortDirection): void {
|
| 417 |
+
const col_id = `col_${col}`;
|
| 418 |
+
const desc = direction === "desc";
|
| 419 |
+
// if already sorted this way, remove it
|
| 420 |
+
const existing = sorting.findIndex((s) => s.id === col_id);
|
| 421 |
+
if (existing >= 0 && sorting[existing].desc === desc) {
|
| 422 |
+
sorting = sorting.filter((s) => s.id !== col_id);
|
| 423 |
+
} else {
|
| 424 |
+
sorting = [
|
| 425 |
+
...sorting.filter((s) => s.id !== col_id),
|
| 426 |
+
{ id: col_id, desc }
|
| 427 |
+
].slice(-3);
|
| 428 |
}
|
| 429 |
}
|
| 430 |
|
| 431 |
+
function clear_sort(): void {
|
| 432 |
+
sorting = [];
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
function handle_filter(
|
| 436 |
col: number,
|
| 437 |
+
dtype: FilterDatatype,
|
| 438 |
filter: string,
|
| 439 |
+
fvalue: string
|
| 440 |
): void {
|
| 441 |
+
const col_id = `col_${col}`;
|
| 442 |
+
const existing = column_filters.findIndex((f) => f.id === col_id);
|
| 443 |
+
if (existing >= 0) {
|
| 444 |
+
column_filters = column_filters.filter((f) => f.id !== col_id);
|
| 445 |
+
} else {
|
| 446 |
+
column_filters = [
|
| 447 |
+
...column_filters,
|
| 448 |
+
{ id: col_id, value: { dtype, filter, value: fvalue } }
|
| 449 |
+
];
|
| 450 |
+
}
|
| 451 |
}
|
| 452 |
|
| 453 |
function clear_filter(): void {
|
| 454 |
+
column_filters = [];
|
|
|
|
| 455 |
}
|
| 456 |
|
| 457 |
+
function handle_search(query: string | null): void {
|
| 458 |
+
global_filter = query ?? "";
|
| 459 |
+
onsearch?.(query);
|
| 460 |
}
|
| 461 |
|
| 462 |
+
function add_row(index?: number): void {
|
| 463 |
+
if (row_count[1] !== "dynamic") return;
|
| 464 |
+
const col_len = values[0]?.length || resolved_headers.length || 1;
|
| 465 |
+
const new_row: CellValue[] = Array(col_len).fill("");
|
| 466 |
+
const new_values = [...values];
|
| 467 |
+
if (index !== undefined) {
|
| 468 |
+
new_values.splice(index, 0, new_row);
|
| 469 |
+
} else {
|
| 470 |
+
new_values.push(new_row);
|
| 471 |
}
|
| 472 |
+
values = new_values;
|
| 473 |
+
push_change(new_values);
|
| 474 |
+
selected = [index ?? new_values.length - 1, 0];
|
| 475 |
+
parent?.focus();
|
|
|
|
|
|
|
| 476 |
}
|
| 477 |
|
| 478 |
+
function add_col(index?: number): void {
|
| 479 |
+
if (col_count[1] !== "dynamic") return;
|
| 480 |
+
const new_headers = [
|
| 481 |
+
...(headers ?? []),
|
| 482 |
+
`Header ${(headers?.length ?? 0) + 1}`
|
| 483 |
+
];
|
| 484 |
+
const new_values = values.map((row) => [...row, ""]);
|
| 485 |
+
if (index !== undefined) {
|
| 486 |
+
new_headers.splice(index, 0, new_headers.pop()!);
|
| 487 |
+
new_values.forEach((row) => row.splice(index, 0, row.pop()!));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
}
|
| 489 |
+
values = new_values;
|
| 490 |
+
headers = new_headers;
|
| 491 |
+
push_change(new_values, new_headers);
|
| 492 |
+
parent?.focus();
|
| 493 |
+
}
|
| 494 |
|
| 495 |
+
function delete_row_at(index: number): void {
|
| 496 |
+
if (values.length <= 1) return;
|
| 497 |
+
values = [...values.slice(0, index), ...values.slice(index + 1)];
|
| 498 |
+
push_change(values);
|
| 499 |
+
active_cell_menu = null;
|
| 500 |
+
active_header_menu = null;
|
| 501 |
}
|
| 502 |
|
| 503 |
+
function delete_col_at(index: number): void {
|
|
|
|
| 504 |
if (col_count[1] !== "dynamic") return;
|
| 505 |
+
if ((values[0]?.length ?? 0) <= 1) return;
|
| 506 |
+
values = values.map((row) => [
|
| 507 |
+
...row.slice(0, index),
|
| 508 |
+
...row.slice(index + 1)
|
| 509 |
+
]);
|
| 510 |
+
headers = [
|
| 511 |
+
...(headers ?? []).slice(0, index),
|
| 512 |
+
...(headers ?? []).slice(index + 1)
|
| 513 |
+
];
|
| 514 |
+
push_change(values, headers as string[]);
|
| 515 |
+
active_cell_menu = null;
|
| 516 |
+
active_header_menu = null;
|
| 517 |
+
selected = false;
|
| 518 |
+
selected_cells = [];
|
| 519 |
+
editing = false;
|
| 520 |
+
}
|
| 521 |
|
| 522 |
+
function add_row_at(index: number, position: "above" | "below"): void {
|
| 523 |
+
add_row(position === "above" ? index : index + 1);
|
| 524 |
+
active_cell_menu = null;
|
| 525 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
|
| 527 |
+
function add_col_at(index: number, position: "left" | "right"): void {
|
| 528 |
+
add_col(position === "left" ? index : index + 1);
|
| 529 |
+
active_cell_menu = null;
|
| 530 |
+
}
|
| 531 |
|
| 532 |
+
// function handle_select_all(col: number, checked: boolean): void {
|
| 533 |
+
// values = values.map((row) => {
|
| 534 |
+
// const new_row = [...row];
|
| 535 |
+
// new_row[col] = checked;
|
| 536 |
+
// return new_row;
|
| 537 |
+
// });
|
| 538 |
+
// push_change(values);
|
| 539 |
+
// }
|
| 540 |
|
| 541 |
+
function commit_filter(): void {
|
| 542 |
+
if (!global_filter || show_search !== "filter") return;
|
| 543 |
+
// get the filtered rows from tanstack and push as new values
|
| 544 |
+
const filtered_values = rows.map((row) => {
|
| 545 |
+
const original_idx = row.original._index;
|
| 546 |
+
return values[original_idx];
|
| 547 |
});
|
| 548 |
+
values = filtered_values;
|
| 549 |
+
global_filter = "";
|
| 550 |
+
push_change(filtered_values);
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
async function handle_copy(): Promise<void> {
|
| 554 |
+
const data_for_copy = values.map((row) =>
|
| 555 |
+
row.map((val, j) => ({ id: `${j}`, value: val }))
|
| 556 |
+
);
|
| 557 |
+
const cells_to_copy = selected_cells.length > 0 ? selected_cells : null;
|
| 558 |
+
await copy_table_data(data_for_copy, cells_to_copy);
|
| 559 |
+
copy_flash = true;
|
| 560 |
+
setTimeout(() => (copy_flash = false), 800);
|
| 561 |
}
|
| 562 |
|
| 563 |
function handle_click_outside(event: Event): void {
|
| 564 |
if (handle_click_outside_util(event, parent)) {
|
| 565 |
+
selected_cells = [];
|
| 566 |
+
selected = false;
|
| 567 |
+
editing = false;
|
| 568 |
header_edit = false;
|
| 569 |
selected_header = false;
|
| 570 |
+
active_cell_menu = null;
|
| 571 |
+
active_header_menu = null;
|
| 572 |
}
|
| 573 |
}
|
| 574 |
|
| 575 |
+
function handle_keydown(e: KeyboardEvent): void {
|
| 576 |
+
if (!selected && selected_header === false) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
|
| 578 |
+
const num_rows = rows.length;
|
| 579 |
+
const num_cols = resolved_headers.length;
|
|
|
|
| 580 |
|
| 581 |
+
if (selected) {
|
| 582 |
+
const [row, col] = selected;
|
| 583 |
|
| 584 |
+
switch (e.key) {
|
| 585 |
+
case "ArrowUp":
|
| 586 |
+
e.preventDefault();
|
| 587 |
+
if (row > 0) {
|
| 588 |
+
selected = [row - 1, col];
|
| 589 |
+
selected_cells = [selected];
|
| 590 |
+
editing = false;
|
| 591 |
+
virtualizer.instance.scrollToIndex(row - 1, { align: "auto" });
|
| 592 |
+
}
|
| 593 |
+
break;
|
| 594 |
+
case "ArrowDown":
|
| 595 |
+
e.preventDefault();
|
| 596 |
+
if (row < num_rows - 1) {
|
| 597 |
+
selected = [row + 1, col];
|
| 598 |
+
selected_cells = [selected];
|
| 599 |
+
editing = false;
|
| 600 |
+
virtualizer.instance.scrollToIndex(row + 1, { align: "auto" });
|
| 601 |
+
}
|
| 602 |
+
break;
|
| 603 |
+
case "ArrowLeft":
|
| 604 |
+
e.preventDefault();
|
| 605 |
+
if (col > 0) {
|
| 606 |
+
selected = [row, col - 1];
|
| 607 |
+
selected_cells = [selected];
|
| 608 |
+
editing = false;
|
| 609 |
+
}
|
| 610 |
+
break;
|
| 611 |
+
case "ArrowRight":
|
| 612 |
+
e.preventDefault();
|
| 613 |
+
if (col < num_cols - 1) {
|
| 614 |
+
selected = [row, col + 1];
|
| 615 |
+
selected_cells = [selected];
|
| 616 |
+
editing = false;
|
| 617 |
+
}
|
| 618 |
+
break;
|
| 619 |
+
case "Tab": {
|
| 620 |
+
e.preventDefault();
|
| 621 |
+
const was_editing = !!editing;
|
| 622 |
+
if (e.shiftKey) {
|
| 623 |
+
if (col > 0) selected = [row, col - 1];
|
| 624 |
+
else if (row > 0) selected = [row - 1, num_cols - 1];
|
| 625 |
+
} else {
|
| 626 |
+
if (col < num_cols - 1) selected = [row, col + 1];
|
| 627 |
+
else if (row < num_rows - 1) selected = [row + 1, 0];
|
| 628 |
+
}
|
| 629 |
+
selected_cells = [selected];
|
| 630 |
+
if (was_editing) {
|
| 631 |
+
const tab_col = (selected as CellCoordinate)[1];
|
| 632 |
+
const tab_static =
|
| 633 |
+
static_columns.includes(tab_col) ||
|
| 634 |
+
static_columns.includes(resolved_headers[tab_col]);
|
| 635 |
+
editing = editable && !tab_static ? selected : false;
|
| 636 |
+
} else {
|
| 637 |
+
editing = false;
|
| 638 |
+
}
|
| 639 |
+
if (!editing) tick().then(() => parent?.focus());
|
| 640 |
+
break;
|
| 641 |
+
}
|
| 642 |
+
case "Enter":
|
| 643 |
+
if (editing && e.shiftKey) {
|
| 644 |
+
// shift+enter inserts newline in textarea — don't intercept
|
| 645 |
+
return;
|
| 646 |
+
}
|
| 647 |
+
e.preventDefault();
|
| 648 |
+
if (editing) {
|
| 649 |
+
editing = false;
|
| 650 |
+
if (row < num_rows - 1) {
|
| 651 |
+
selected = [row + 1, col];
|
| 652 |
+
selected_cells = [selected];
|
| 653 |
+
}
|
| 654 |
+
tick().then(() => parent?.focus());
|
| 655 |
+
} else if (editable) {
|
| 656 |
+
const enter_static =
|
| 657 |
+
static_columns.includes(col) ||
|
| 658 |
+
static_columns.includes(resolved_headers[col]);
|
| 659 |
+
if (!enter_static) {
|
| 660 |
+
editing = [row, col];
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
break;
|
| 664 |
+
case "Escape":
|
| 665 |
+
editing = false;
|
| 666 |
+
tick().then(() => parent?.focus());
|
| 667 |
+
break;
|
| 668 |
+
case "Delete":
|
| 669 |
+
case "Backspace":
|
| 670 |
+
if (!editing && editable) {
|
| 671 |
+
e.preventDefault();
|
| 672 |
+
const new_values = values.map((r) => [...r]);
|
| 673 |
+
selected_cells.forEach(([r, c]) => {
|
| 674 |
+
if (!static_columns.includes(c)) {
|
| 675 |
+
new_values[r][c] = "";
|
| 676 |
+
}
|
| 677 |
+
});
|
| 678 |
+
values = new_values;
|
| 679 |
+
push_change(new_values);
|
| 680 |
+
}
|
| 681 |
+
break;
|
| 682 |
+
default:
|
| 683 |
+
// start editing on printable character
|
| 684 |
+
if (
|
| 685 |
+
editable &&
|
| 686 |
+
!editing &&
|
| 687 |
+
e.key.length === 1 &&
|
| 688 |
+
!e.ctrlKey &&
|
| 689 |
+
!e.metaKey &&
|
| 690 |
+
!static_columns.includes(col)
|
| 691 |
+
) {
|
| 692 |
+
editing = [row, col];
|
| 693 |
+
}
|
| 694 |
+
break;
|
| 695 |
}
|
|
|
|
| 696 |
|
| 697 |
+
if ((e.ctrlKey || e.metaKey) && e.key === "c") {
|
| 698 |
+
handle_copy();
|
|
|
|
|
|
|
| 699 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
}
|
| 701 |
+
}
|
|
|
|
|
|
|
| 702 |
|
| 703 |
+
function handle_scroll(): void {
|
| 704 |
+
if (scroll_container) {
|
| 705 |
+
show_scroll_button = scroll_container.scrollTop > 100;
|
| 706 |
}
|
|
|
|
| 707 |
}
|
| 708 |
|
| 709 |
+
function scroll_to_top(): void {
|
| 710 |
+
scroll_container?.scrollTo({ top: 0 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
}
|
| 712 |
|
| 713 |
+
function toggle_cell_menu(event: MouseEvent, row: number, col: number): void {
|
| 714 |
event.stopPropagation();
|
| 715 |
+
if (active_cell_menu?.row === row && active_cell_menu.col === col) {
|
| 716 |
+
active_cell_menu = null;
|
| 717 |
} else {
|
| 718 |
+
const cell = (event.target as HTMLElement).closest(".body-cell, td");
|
| 719 |
+
if (cell) {
|
| 720 |
+
const rect = cell.getBoundingClientRect();
|
| 721 |
+
active_cell_menu = { row, col, x: rect.right, y: rect.bottom };
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
}
|
| 723 |
}
|
| 724 |
}
|
| 725 |
|
| 726 |
+
function on_file_upload(file_data: any): void {
|
| 727 |
+
handle_file_upload(
|
| 728 |
+
typeof file_data === "string" ? file_data : (file_data?.data ?? ""),
|
| 729 |
+
(head) => {
|
| 730 |
+
headers = head.map((h: any) => h ?? "");
|
| 731 |
+
return (headers as string[]).map((h: string, i: number) => ({
|
| 732 |
+
id: `h_${i}`,
|
| 733 |
+
value: h
|
| 734 |
+
}));
|
| 735 |
+
},
|
| 736 |
+
(vals) => {
|
| 737 |
+
values = vals;
|
| 738 |
+
push_change(vals, headers as string[]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
}
|
| 740 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
}
|
| 742 |
|
| 743 |
+
onMount(() => {
|
| 744 |
+
document.addEventListener("click", handle_click_outside);
|
| 745 |
+
return () => document.removeEventListener("click", handle_click_outside);
|
| 746 |
+
});
|
| 747 |
|
| 748 |
+
function measure_row(node: HTMLElement) {
|
| 749 |
+
tick().then(() => {
|
| 750 |
+
console.log("measuring");
|
| 751 |
+
virtualizer.instance.measureElement(node as any);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
|
| 754 |
+
return {
|
| 755 |
+
destroy() {}
|
| 756 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 757 |
}
|
| 758 |
|
| 759 |
+
let header_row_el: HTMLTableRowElement;
|
| 760 |
+
let header_table_el: HTMLTableElement;
|
| 761 |
+
|
| 762 |
+
const measurement = create_column_measurement({
|
| 763 |
+
header_row_el: () => header_row_el,
|
| 764 |
+
header_table_el: () => header_table_el,
|
| 765 |
+
resolved_headers: () => resolved_headers,
|
| 766 |
+
row_data: () => row_data,
|
| 767 |
+
show_row_numbers: () => show_row_numbers,
|
| 768 |
+
column_widths: () => column_widths,
|
| 769 |
+
on_resize: undefined
|
| 770 |
+
});
|
| 771 |
|
| 772 |
+
let disable_scroll = $derived(
|
| 773 |
+
active_cell_menu !== null || active_header_menu !== null
|
| 774 |
+
);
|
| 775 |
+
let selected_index = $derived(selected !== false ? selected[0] : false);
|
| 776 |
|
| 777 |
+
$effect(() => {
|
| 778 |
+
if (typeof selected_index === "number") {
|
| 779 |
+
virtualizer.instance.scrollToIndex(selected_index, { align: "auto" });
|
|
|
|
| 780 |
}
|
| 781 |
+
});
|
| 782 |
|
| 783 |
+
function get_sort_info(col: number): {
|
| 784 |
+
direction: SortDirection | null;
|
| 785 |
+
priority: number | null;
|
| 786 |
+
} {
|
| 787 |
+
const col_id = `col_${col}`;
|
| 788 |
+
const idx = sorting.findIndex((s) => s.id === col_id);
|
| 789 |
+
if (idx === -1) return { direction: null, priority: null };
|
| 790 |
+
return { direction: sorting[idx].desc ? "desc" : "asc", priority: idx + 1 };
|
| 791 |
+
}
|
| 792 |
|
| 793 |
+
function get_filter_active(col: number): boolean {
|
| 794 |
+
return column_filters.some((f) => f.id === `col_${col}`);
|
| 795 |
}
|
| 796 |
</script>
|
| 797 |
|
| 798 |
+
<svelte:window
|
| 799 |
+
onresize={() => {
|
| 800 |
+
active_cell_menu = null;
|
| 801 |
+
active_header_menu = null;
|
| 802 |
+
}}
|
| 803 |
+
/>
|
| 804 |
|
| 805 |
+
<div class="table-container" class:fullscreen>
|
| 806 |
{#if (label && label.length !== 0 && show_label) || (buttons === null ? true : buttons.includes("fullscreen")) || (buttons === null ? true : buttons.includes("copy")) || show_search !== "none"}
|
| 807 |
<div class="header-row">
|
| 808 |
{#if label && label.length !== 0 && show_label}
|
| 809 |
+
<div class="label"><p>{label}</p></div>
|
|
|
|
|
|
|
| 810 |
{/if}
|
| 811 |
<Toolbar
|
| 812 |
show_fullscreen_button={buttons === null
|
| 813 |
? true
|
| 814 |
: buttons.includes("fullscreen")}
|
| 815 |
{fullscreen}
|
| 816 |
+
on_copy={handle_copy}
|
| 817 |
show_copy_button={buttons === null ? true : buttons.includes("copy")}
|
| 818 |
{show_search}
|
| 819 |
+
onsearch={(query) => handle_search(query)}
|
| 820 |
+
{onfullscreen}
|
| 821 |
on_commit_filter={commit_filter}
|
| 822 |
+
current_search_query={global_filter || null}
|
| 823 |
/>
|
| 824 |
</div>
|
| 825 |
{/if}
|
| 826 |
+
|
| 827 |
<div
|
| 828 |
bind:this={parent}
|
| 829 |
class="table-wrap"
|
| 830 |
class:dragging={is_dragging}
|
| 831 |
class:no-wrap={!wrap}
|
| 832 |
class:menu-open={active_cell_menu || active_header_menu}
|
| 833 |
+
onkeydown={handle_keydown}
|
|
|
|
|
|
|
|
|
|
| 834 |
role="grid"
|
| 835 |
tabindex="0"
|
| 836 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
<Upload
|
| 838 |
{upload}
|
| 839 |
{stream_handler}
|
|
|
|
| 842 |
boundedheight={false}
|
| 843 |
disable_click={true}
|
| 844 |
{root}
|
| 845 |
+
onload={on_file_upload}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
bind:dragging
|
| 847 |
aria_label={i18n("dataframe.drop_to_upload")}
|
| 848 |
>
|
| 849 |
+
<div
|
| 850 |
+
class="virtual-table-viewport"
|
| 851 |
+
class:disable-scroll={disable_scroll}
|
| 852 |
+
bind:this={scroll_container}
|
| 853 |
+
onscroll={handle_scroll}
|
| 854 |
+
style="max-height: {max_height}px;"
|
| 855 |
+
role="grid"
|
| 856 |
+
>
|
| 857 |
+
{#if label && label.length !== 0}
|
| 858 |
+
<span class="sr-only">{label}</span>
|
| 859 |
+
{/if}
|
| 860 |
+
<!-- header row: uses table layout to auto-size columns by content -->
|
| 861 |
+
<table class="header-table" bind:this={header_table_el}>
|
| 862 |
+
<thead>
|
| 863 |
+
<tr bind:this={header_row_el}>
|
| 864 |
+
{#if show_row_numbers}
|
| 865 |
+
<th class="row-number-header"> </th>
|
| 866 |
+
{/if}
|
| 867 |
+
{#each header_groups as headerGroup (headerGroup.id)}
|
| 868 |
+
{#each headerGroup.headers as header (header.id)}
|
| 869 |
+
{@const col_idx =
|
| 870 |
+
(header.column.columnDef.meta as any)?.colIndex ?? 0}
|
| 871 |
+
<HeaderCell
|
| 872 |
+
value={String(header.column.columnDef.header ?? "")}
|
| 873 |
+
{col_idx}
|
| 874 |
+
is_editing={header_edit === col_idx}
|
| 875 |
+
is_selected={selected_header === col_idx}
|
| 876 |
+
is_static={!!(header.column.columnDef.meta as any)
|
| 877 |
+
?.isStatic}
|
| 878 |
+
sort_direction={get_sort_info(col_idx).direction}
|
| 879 |
+
sort_priority={get_sort_info(col_idx).priority}
|
| 880 |
+
multi_sort={sorting.length > 1}
|
| 881 |
+
is_filtered={get_filter_active(col_idx)}
|
| 882 |
+
show_menu_button={col_count[1] === "dynamic"}
|
| 883 |
+
is_first_column={col_idx === 0 && !show_row_numbers}
|
| 884 |
+
{latex_delimiters}
|
| 885 |
+
{line_breaks}
|
| 886 |
+
{editable}
|
| 887 |
+
{max_chars}
|
| 888 |
+
{i18n}
|
| 889 |
+
onclick={handle_header_click}
|
| 890 |
+
on_menu_click={toggle_header_menu}
|
| 891 |
+
on_end_edit={end_header_edit}
|
| 892 |
+
/>
|
| 893 |
+
{/each}
|
| 894 |
+
{/each}
|
| 895 |
+
</tr>
|
| 896 |
+
</thead>
|
| 897 |
+
<!-- hidden sizing row: lets table-layout:auto consider body content widths too -->
|
| 898 |
+
<tbody class="sizing-body" aria-hidden="true">
|
| 899 |
+
{#if rows.length > 0}
|
| 900 |
+
{@const sizing_row = rows.reduce((widest, row) => {
|
| 901 |
+
const cells = row.getVisibleCells();
|
| 902 |
+
cells.forEach((cell, i) => {
|
| 903 |
+
const val = String(cell.getValue() ?? "");
|
| 904 |
+
if (!widest[i] || val.length > widest[i].length) {
|
| 905 |
+
widest[i] = val;
|
| 906 |
+
}
|
| 907 |
+
});
|
| 908 |
+
return widest;
|
| 909 |
+
}, [] as string[])}
|
| 910 |
+
<tr>
|
| 911 |
+
{#if show_row_numbers}
|
| 912 |
+
<td class="row-number-cell">{rows.length}</td>
|
| 913 |
+
{/if}
|
| 914 |
+
{#each sizing_row as val, ci}
|
| 915 |
+
{@const dtype = get_dtype(ci)}
|
| 916 |
+
<td
|
| 917 |
+
><div class="cell-wrap">
|
| 918 |
+
{#if dtype === "html" || dtype === "markdown"}{@html val}{:else}{val}{/if}
|
| 919 |
+
</div></td
|
| 920 |
+
>
|
| 921 |
+
{/each}
|
| 922 |
+
</tr>
|
| 923 |
{/if}
|
| 924 |
+
</tbody>
|
| 925 |
+
</table>
|
| 926 |
+
|
| 927 |
+
<!-- table body: absolutely positioned rows (standard tanstack virtual pattern) -->
|
| 928 |
+
<div
|
| 929 |
+
class="virtual-body"
|
| 930 |
+
style="height: {total_size}px; position: relative; flex-shrink: 0; width: {measurement.total_header_width
|
| 931 |
+
? `${measurement.total_header_width}px`
|
| 932 |
+
: '100%'};"
|
| 933 |
+
>
|
| 934 |
+
{#each virtual_items as virtual_row (virtual_row.key)}
|
| 935 |
+
{@const row = rows[virtual_row.index]}
|
| 936 |
+
{@const row_idx = row?.original._index ?? virtual_row.index}
|
| 937 |
+
{#if row}
|
| 938 |
+
<div
|
| 939 |
+
class="virtual-row"
|
| 940 |
+
class:row-odd={virtual_row.index % 2 !== 0}
|
| 941 |
+
data-index={virtual_row.index}
|
| 942 |
+
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({virtual_row.start}px);{selected_cells.some(
|
| 943 |
+
([r]) => r === row_idx
|
| 944 |
+
)
|
| 945 |
+
? ' z-index: 3;'
|
| 946 |
+
: ''}"
|
| 947 |
+
use:measure_row={row}
|
| 948 |
+
>
|
| 949 |
+
{#if show_row_numbers}
|
| 950 |
+
<div
|
| 951 |
+
class="row-number-cell"
|
| 952 |
+
data-row={row_idx}
|
| 953 |
+
data-col="row-number"
|
| 954 |
+
style="flex: 0 0 {measurement.row_num_width}px; width: {measurement.row_num_width}px;"
|
| 955 |
+
>
|
| 956 |
+
{row_idx + 1}
|
| 957 |
+
</div>
|
| 958 |
+
{/if}
|
| 959 |
+
{#each row.getVisibleCells() as cell, ci (cell.id)}
|
| 960 |
+
{@const col_idx =
|
| 961 |
+
(cell.column.columnDef.meta as any)?.colIndex ?? 0}
|
| 962 |
+
{@const is_sel = is_cell_in_selection(
|
| 963 |
+
[row_idx, col_idx],
|
| 964 |
+
selected_cells
|
| 965 |
+
)}
|
| 966 |
+
<DataCell
|
| 967 |
+
value={cell.getValue() as CellValue}
|
| 968 |
+
display_value={get_display_value(row_idx, col_idx)}
|
| 969 |
+
datatype={get_dtype(col_idx)}
|
| 970 |
+
{row_idx}
|
| 971 |
+
{col_idx}
|
| 972 |
+
col_style={measurement.get_col_style(ci)}
|
| 973 |
+
cell_style={get_styling(row_idx, col_idx)}
|
| 974 |
+
selection_classes={is_cell_selected(
|
| 975 |
+
[row_idx, col_idx],
|
| 976 |
+
selected_cells
|
| 977 |
+
)}
|
| 978 |
+
is_editing={!!(
|
| 979 |
+
editing &&
|
| 980 |
+
editing[0] === row_idx &&
|
| 981 |
+
editing[1] === col_idx
|
| 982 |
+
)}
|
| 983 |
+
is_flash={copy_flash && is_sel}
|
| 984 |
+
is_static={!!(cell.column.columnDef.meta as any)?.isStatic}
|
| 985 |
+
show_menu_button={editable &&
|
| 986 |
+
selected_cells.length === 1 &&
|
| 987 |
+
selected_cells[0][0] === row_idx &&
|
| 988 |
+
selected_cells[0][1] === col_idx}
|
| 989 |
+
show_selection_buttons={selected_cells.length === 1 &&
|
| 990 |
+
selected_cells[0][0] === row_idx &&
|
| 991 |
+
selected_cells[0][1] === col_idx}
|
| 992 |
+
is_first_column={ci === 0 && !show_row_numbers}
|
| 993 |
+
{latex_delimiters}
|
| 994 |
+
{line_breaks}
|
| 995 |
+
{editable}
|
| 996 |
+
{max_chars}
|
| 997 |
+
{i18n}
|
| 998 |
+
{components}
|
| 999 |
+
{is_dragging}
|
| 1000 |
+
wrap_text={wrap}
|
| 1001 |
+
onmousedown={(e) => handle_cell_click(e, row_idx, col_idx)}
|
| 1002 |
+
ondblclick={(e) =>
|
| 1003 |
+
handle_cell_dblclick(e, row_idx, col_idx)}
|
| 1004 |
+
oncontextmenu={(e) => {
|
| 1005 |
+
e.preventDefault();
|
| 1006 |
+
toggle_cell_menu(e, row_idx, col_idx);
|
| 1007 |
+
}}
|
| 1008 |
+
onblur={handle_blur}
|
| 1009 |
+
on_menu_click={(e) => toggle_cell_menu(e, row_idx, col_idx)}
|
| 1010 |
+
on_select_column={(c) => {
|
| 1011 |
+
selected_cells = rows.map(
|
| 1012 |
+
(_, r) => [r, c] as CellCoordinate
|
| 1013 |
+
);
|
| 1014 |
+
selected = selected_cells[0];
|
| 1015 |
+
}}
|
| 1016 |
+
on_select_row={(r) => {
|
| 1017 |
+
selected_cells = resolved_headers.map(
|
| 1018 |
+
(_, c) => [r, c] as CellCoordinate
|
| 1019 |
+
);
|
| 1020 |
+
selected = selected_cells[0];
|
| 1021 |
+
}}
|
| 1022 |
+
/>
|
| 1023 |
+
{/each}
|
| 1024 |
+
</div>
|
| 1025 |
{/if}
|
| 1026 |
+
{/each}
|
| 1027 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
</div>
|
| 1029 |
</Upload>
|
| 1030 |
+
|
| 1031 |
{#if show_scroll_button}
|
| 1032 |
+
<button class="scroll-top-button" onclick={scroll_to_top}>↑</button>
|
|
|
|
|
|
|
| 1033 |
{/if}
|
| 1034 |
</div>
|
| 1035 |
</div>
|
|
|
|
|
|
|
|
|
|
| 1036 |
|
| 1037 |
{#if active_cell_menu || active_header_menu}
|
| 1038 |
<CellMenu
|
|
|
|
| 1057 |
on_delete_col={() =>
|
| 1058 |
delete_col_at(active_cell_menu?.col ?? active_header_menu?.col ?? -1)}
|
| 1059 |
{editable}
|
| 1060 |
+
can_delete_rows={!active_header_menu && values.length > 1 && editable}
|
| 1061 |
+
can_delete_cols={values.length > 0 &&
|
| 1062 |
+
(values[0]?.length ?? 0) > 1 &&
|
| 1063 |
+
editable}
|
| 1064 |
{i18n}
|
| 1065 |
on_sort={active_header_menu
|
| 1066 |
? (direction) => {
|
| 1067 |
+
handle_sort(active_header_menu!.col, direction);
|
| 1068 |
+
active_header_menu = null;
|
|
|
|
|
|
|
| 1069 |
}
|
| 1070 |
: undefined}
|
| 1071 |
on_clear_sort={active_header_menu
|
| 1072 |
? () => {
|
| 1073 |
clear_sort();
|
| 1074 |
+
active_header_menu = null;
|
| 1075 |
}
|
| 1076 |
: undefined}
|
| 1077 |
sort_direction={active_header_menu
|
| 1078 |
+
? get_sort_info(active_header_menu.col).direction
|
|
|
|
|
|
|
| 1079 |
: null}
|
| 1080 |
sort_priority={active_header_menu
|
| 1081 |
+
? get_sort_info(active_header_menu.col).priority
|
|
|
|
|
|
|
| 1082 |
: null}
|
| 1083 |
on_filter={active_header_menu
|
| 1084 |
+
? (dtype, filter, fvalue) => {
|
| 1085 |
+
handle_filter(active_header_menu!.col, dtype, filter, fvalue);
|
| 1086 |
+
active_header_menu = null;
|
|
|
|
|
|
|
| 1087 |
}
|
| 1088 |
: undefined}
|
| 1089 |
on_clear_filter={active_header_menu
|
| 1090 |
? () => {
|
| 1091 |
clear_filter();
|
| 1092 |
+
active_header_menu = null;
|
| 1093 |
}
|
| 1094 |
: undefined}
|
| 1095 |
filter_active={active_header_menu
|
| 1096 |
+
? get_filter_active(active_header_menu.col)
|
|
|
|
|
|
|
| 1097 |
: null}
|
| 1098 |
/>
|
| 1099 |
{/if}
|
| 1100 |
|
| 1101 |
+
{#if values.length === 0 && editable && row_count[1] === "dynamic"}
|
| 1102 |
+
<EmptyRowButton on_click={() => add_row()} />
|
| 1103 |
+
{/if}
|
| 1104 |
+
|
| 1105 |
<style>
|
| 1106 |
.table-container {
|
| 1107 |
display: flex;
|
| 1108 |
flex-direction: column;
|
| 1109 |
gap: var(--size-2);
|
| 1110 |
position: relative;
|
| 1111 |
+
max-width: 100%;
|
| 1112 |
+
overflow: hidden;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
.table-container.fullscreen {
|
| 1116 |
+
padding: var(--size-4);
|
| 1117 |
+
height: 100%;
|
| 1118 |
+
box-sizing: border-box;
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
.table-container.fullscreen .table-wrap {
|
| 1122 |
+
flex: 1 1 auto;
|
| 1123 |
+
min-height: 0;
|
| 1124 |
+
display: flex;
|
| 1125 |
+
flex-direction: column;
|
| 1126 |
+
}
|
| 1127 |
+
|
| 1128 |
+
.table-container.fullscreen .table-wrap > :global(*) {
|
| 1129 |
+
flex: 1 1 auto;
|
| 1130 |
+
min-height: 0;
|
| 1131 |
+
display: flex;
|
| 1132 |
+
flex-direction: column;
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
.table-container.fullscreen .virtual-table-viewport {
|
| 1136 |
+
max-height: none !important;
|
| 1137 |
+
flex: 1 1 auto;
|
| 1138 |
+
min-height: 0;
|
| 1139 |
}
|
| 1140 |
|
| 1141 |
.table-wrap {
|
| 1142 |
position: relative;
|
| 1143 |
transition: 150ms;
|
| 1144 |
+
width: 100%;
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
/* Constrain Upload component wrapper */
|
| 1148 |
+
.table-wrap > :global(*) {
|
| 1149 |
+
max-width: 100%;
|
| 1150 |
}
|
| 1151 |
|
| 1152 |
.table-wrap.menu-open {
|
|
|
|
| 1173 |
overflow: hidden;
|
| 1174 |
}
|
| 1175 |
|
| 1176 |
+
/* Virtual scroll container */
|
| 1177 |
+
.virtual-table-viewport {
|
| 1178 |
+
display: flex;
|
| 1179 |
+
flex-direction: column;
|
| 1180 |
+
overflow: auto;
|
| 1181 |
+
position: relative;
|
| 1182 |
+
-webkit-overflow-scrolling: touch;
|
| 1183 |
+
min-width: 0;
|
| 1184 |
+
max-width: 100%;
|
| 1185 |
+
scrollbar-width: thin;
|
| 1186 |
+
scrollbar-color: rgba(128, 128, 128, 0.5) transparent;
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
.virtual-table-viewport::-webkit-scrollbar {
|
| 1190 |
+
width: 4px;
|
| 1191 |
+
height: 4px;
|
| 1192 |
+
}
|
| 1193 |
+
|
| 1194 |
+
.virtual-table-viewport::-webkit-scrollbar-thumb {
|
| 1195 |
+
background-color: rgba(128, 128, 128, 0.5);
|
| 1196 |
+
border-radius: 4px;
|
| 1197 |
+
}
|
| 1198 |
+
|
| 1199 |
+
.virtual-table-viewport:hover {
|
| 1200 |
+
scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
|
| 1201 |
+
}
|
| 1202 |
+
|
| 1203 |
+
.virtual-table-viewport.disable-scroll {
|
| 1204 |
+
overflow: hidden !important;
|
| 1205 |
+
}
|
| 1206 |
+
|
| 1207 |
+
/* Header table: auto-sizes columns by content, sticky */
|
| 1208 |
+
.header-table {
|
| 1209 |
+
width: 100%;
|
| 1210 |
color: var(--body-text-color);
|
| 1211 |
font-size: var(--input-text-size);
|
| 1212 |
line-height: var(--line-md);
|
| 1213 |
font-family: var(--font-mono);
|
| 1214 |
border-spacing: 0;
|
| 1215 |
border-collapse: separate;
|
| 1216 |
+
table-layout: auto;
|
|
|
|
|
|
|
| 1217 |
position: sticky;
|
| 1218 |
top: 0;
|
| 1219 |
+
z-index: 7;
|
| 1220 |
+
flex-shrink: 0;
|
| 1221 |
}
|
| 1222 |
|
| 1223 |
+
/* Hidden sizing row — visibility:collapse hides the row but keeps column width contribution */
|
| 1224 |
+
.sizing-body tr {
|
| 1225 |
+
visibility: collapse;
|
|
|
|
| 1226 |
}
|
| 1227 |
|
| 1228 |
+
.sizing-body td {
|
| 1229 |
+
padding: var(--size-2);
|
| 1230 |
+
border: none;
|
| 1231 |
+
white-space: nowrap;
|
| 1232 |
}
|
| 1233 |
|
| 1234 |
+
/* Virtual body */
|
| 1235 |
+
.virtual-body {
|
| 1236 |
+
box-sizing: border-box;
|
| 1237 |
}
|
| 1238 |
|
| 1239 |
+
.virtual-row {
|
| 1240 |
+
display: flex;
|
| 1241 |
+
align-items: stretch;
|
| 1242 |
+
background: var(--table-odd-background-fill);
|
| 1243 |
+
|
| 1244 |
+
text-align: left;
|
| 1245 |
+
font-size: var(--input-text-size);
|
| 1246 |
+
line-height: var(--line-md);
|
| 1247 |
+
font-family: var(--font-mono);
|
| 1248 |
+
color: var(--body-text-color);
|
| 1249 |
+
min-height: var(--size-9);
|
| 1250 |
}
|
| 1251 |
|
| 1252 |
+
.virtual-row:last-child {
|
| 1253 |
+
border-bottom: none;
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
+
.virtual-row.row-odd {
|
| 1257 |
background: var(--table-even-background-fill);
|
| 1258 |
}
|
| 1259 |
|
| 1260 |
+
.virtual-row:hover {
|
| 1261 |
+
background: var(--table-row-focus);
|
| 1262 |
}
|
| 1263 |
|
| 1264 |
+
/* Cell content wrapper (used in sizing-body) */
|
| 1265 |
+
.cell-wrap {
|
| 1266 |
+
display: flex;
|
| 1267 |
+
align-items: center;
|
| 1268 |
+
justify-content: flex-start;
|
| 1269 |
+
outline: none;
|
| 1270 |
+
min-height: var(--size-9);
|
| 1271 |
+
position: relative;
|
| 1272 |
+
height: 100%;
|
| 1273 |
+
padding: var(--size-2);
|
| 1274 |
+
box-sizing: border-box;
|
| 1275 |
+
gap: var(--size-1);
|
| 1276 |
+
overflow: visible;
|
| 1277 |
+
min-width: 0;
|
| 1278 |
+
}
|
| 1279 |
+
|
| 1280 |
+
/* Row number cells */
|
| 1281 |
+
.row-number-header {
|
| 1282 |
+
text-align: center;
|
| 1283 |
+
padding: var(--size-1);
|
| 1284 |
+
min-width: var(--size-12);
|
| 1285 |
+
width: var(--size-12);
|
| 1286 |
+
font-weight: var(--weight-semibold);
|
| 1287 |
+
border-right: 1px solid var(--border-color-primary);
|
| 1288 |
+
background: var(--table-even-background-fill) !important;
|
| 1289 |
+
}
|
| 1290 |
+
|
| 1291 |
+
.row-number-cell {
|
| 1292 |
+
text-align: center;
|
| 1293 |
+
padding: var(--size-1);
|
| 1294 |
+
min-width: var(--size-12);
|
| 1295 |
+
width: var(--size-12);
|
| 1296 |
+
flex-shrink: 0;
|
| 1297 |
+
overflow: hidden;
|
| 1298 |
+
text-overflow: ellipsis;
|
| 1299 |
+
white-space: nowrap;
|
| 1300 |
+
font-weight: var(--weight-semibold);
|
| 1301 |
+
border-right: 1px solid var(--border-color-primary);
|
| 1302 |
+
display: flex;
|
| 1303 |
+
align-items: center;
|
| 1304 |
+
justify-content: center;
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
+
.no-wrap {
|
| 1308 |
+
white-space: nowrap;
|
| 1309 |
+
}
|
| 1310 |
+
|
| 1311 |
+
div:not(.no-wrap) :global(td) {
|
| 1312 |
+
overflow-wrap: anywhere;
|
| 1313 |
+
}
|
| 1314 |
+
|
| 1315 |
+
div.no-wrap :global(td) {
|
| 1316 |
+
overflow-x: hidden;
|
| 1317 |
}
|
| 1318 |
|
| 1319 |
.header-row {
|
|
|
|
| 1337 |
color: var(--block-label-text-color);
|
| 1338 |
font-size: var(--block-label-text-size);
|
| 1339 |
line-height: var(--line-sm);
|
|
|
|
|
|
|
| 1340 |
}
|
| 1341 |
|
| 1342 |
.scroll-top-button {
|
|
|
|
| 1361 |
.scroll-top-button:hover {
|
| 1362 |
opacity: 1;
|
| 1363 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1364 |
</style>
|
6.11.0/dataframe/shared/Toolbar.svelte
CHANGED
|
@@ -1,25 +1,33 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { Copy, Check } from "@gradio/icons";
|
| 3 |
import { FullscreenButton } from "@gradio/atoms";
|
| 4 |
-
import { onDestroy } from "svelte";
|
| 5 |
-
import { createEventDispatcher } from "svelte";
|
| 6 |
import { IconButton } from "@gradio/atoms";
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
let timer: ReturnType<typeof setTimeout>;
|
| 21 |
-
|
| 22 |
-
let input_value = "";
|
| 23 |
|
| 24 |
function handle_search_input(e: Event): void {
|
| 25 |
const target = e.target as HTMLTextAreaElement;
|
|
@@ -27,7 +35,7 @@
|
|
| 27 |
const new_query = input_value || null;
|
| 28 |
if (current_search_query !== new_query) {
|
| 29 |
current_search_query = new_query;
|
| 30 |
-
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
|
@@ -44,8 +52,10 @@
|
|
| 44 |
copy_feedback();
|
| 45 |
}
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
});
|
| 50 |
</script>
|
| 51 |
|
|
@@ -56,7 +66,7 @@
|
|
| 56 |
<input
|
| 57 |
type="text"
|
| 58 |
value={current_search_query || ""}
|
| 59 |
-
|
| 60 |
placeholder={show_search === "filter" ? "Filter..." : "Search..."}
|
| 61 |
class="search-input"
|
| 62 |
class:filter-mode={show_search === "filter"}
|
|
@@ -65,7 +75,7 @@
|
|
| 65 |
{#if current_search_query && show_search === "filter"}
|
| 66 |
<button
|
| 67 |
class="toolbar-button check-button"
|
| 68 |
-
|
| 69 |
aria-label="Apply filter and update dataframe values"
|
| 70 |
title="Apply filter and update dataframe values"
|
| 71 |
>
|
|
@@ -82,7 +92,7 @@
|
|
| 82 |
/>
|
| 83 |
{/if}
|
| 84 |
{#if show_fullscreen_button}
|
| 85 |
-
<FullscreenButton {fullscreen}
|
| 86 |
{/if}
|
| 87 |
</div>
|
| 88 |
</div>
|
|
|
|
| 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;
|
|
|
|
| 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 |
|
|
|
|
| 52 |
copy_feedback();
|
| 53 |
}
|
| 54 |
|
| 55 |
+
$effect(() => {
|
| 56 |
+
return () => {
|
| 57 |
+
if (timer) clearTimeout(timer);
|
| 58 |
+
};
|
| 59 |
});
|
| 60 |
</script>
|
| 61 |
|
|
|
|
| 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"}
|
|
|
|
| 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 |
>
|
|
|
|
| 92 |
/>
|
| 93 |
{/if}
|
| 94 |
{#if show_fullscreen_button}
|
| 95 |
+
<FullscreenButton {fullscreen} onclick={(_fs) => onfullscreen?.()} />
|
| 96 |
{/if}
|
| 97 |
</div>
|
| 98 |
</div>
|
6.11.0/dataframe/shared/column_measurement.svelte.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
on_resize?: () => void;
|
| 13 |
+
}): {
|
| 14 |
+
readonly col_widths: number[];
|
| 15 |
+
readonly col_lefts: number[];
|
| 16 |
+
readonly total_header_width: number;
|
| 17 |
+
readonly header_height: number;
|
| 18 |
+
readonly row_num_width: number;
|
| 19 |
+
get_col_style: (index: number) => string;
|
| 20 |
+
} {
|
| 21 |
+
let col_widths: number[] = $state([]);
|
| 22 |
+
let total_header_width: number = $state(0);
|
| 23 |
+
let header_height: number = $state(0);
|
| 24 |
+
|
| 25 |
+
// use offsets (not just widths) avoids accumulated subpixel rounding errors
|
| 26 |
+
let col_lefts: number[] = $state([]);
|
| 27 |
+
|
| 28 |
+
function measure(): void {
|
| 29 |
+
const current_row_el = opts.header_row_el();
|
| 30 |
+
const current_table_el = opts.header_table_el();
|
| 31 |
+
if (!current_row_el) return;
|
| 32 |
+
|
| 33 |
+
const cells = current_row_el.querySelectorAll<HTMLElement>(".header-cell");
|
| 34 |
+
const table_rect = current_table_el?.getBoundingClientRect();
|
| 35 |
+
const table_left = table_rect?.left ?? 0;
|
| 36 |
+
|
| 37 |
+
col_lefts = Array.from(cells).map(
|
| 38 |
+
(c) => c.getBoundingClientRect().left - table_left
|
| 39 |
+
);
|
| 40 |
+
col_widths = Array.from(cells).map((c) => c.getBoundingClientRect().width);
|
| 41 |
+
if (current_table_el) {
|
| 42 |
+
total_header_width = table_rect?.width ?? 0;
|
| 43 |
+
header_height = table_rect?.height ?? 0;
|
| 44 |
+
}
|
| 45 |
+
opts.on_resize?.();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$effect(() => {
|
| 49 |
+
const table_el = opts.header_table_el();
|
| 50 |
+
const row_el = opts.header_row_el();
|
| 51 |
+
if (!table_el || !row_el) return;
|
| 52 |
+
|
| 53 |
+
// re-run when columns change so we observe new cells
|
| 54 |
+
opts.resolved_headers();
|
| 55 |
+
|
| 56 |
+
const ro = new ResizeObserver(measure);
|
| 57 |
+
ro.observe(table_el);
|
| 58 |
+
|
| 59 |
+
// observe individual header cells so content-driven column
|
| 60 |
+
// width changes (editing, data updates) trigger a re-measure
|
| 61 |
+
// even when the overall table dimensions stay the same
|
| 62 |
+
const cells = row_el.querySelectorAll<HTMLElement>(".header-cell");
|
| 63 |
+
cells.forEach((cell) => ro.observe(cell));
|
| 64 |
+
|
| 65 |
+
return () => ro.disconnect();
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
let row_num_width = $derived.by(() => {
|
| 69 |
+
if (!opts.show_row_numbers()) return 0;
|
| 70 |
+
const row_el = opts.header_row_el();
|
| 71 |
+
if (!row_el) return 0;
|
| 72 |
+
const el = row_el.querySelector<HTMLElement>(".row-number-header");
|
| 73 |
+
return el?.getBoundingClientRect().width ?? 48;
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
function get_col_style(index: number): string {
|
| 77 |
+
if (col_widths[index] !== undefined) {
|
| 78 |
+
return `width: ${col_widths[index]}px; flex: 0 0 ${col_widths[index]}px;`;
|
| 79 |
+
}
|
| 80 |
+
const user_widths = opts.column_widths();
|
| 81 |
+
if (user_widths[index]) return `width: ${user_widths[index]};`;
|
| 82 |
+
return "width: 150px;";
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return {
|
| 86 |
+
get col_widths() {
|
| 87 |
+
return col_widths;
|
| 88 |
+
},
|
| 89 |
+
get col_lefts() {
|
| 90 |
+
return col_lefts;
|
| 91 |
+
},
|
| 92 |
+
get total_header_width() {
|
| 93 |
+
return total_header_width;
|
| 94 |
+
},
|
| 95 |
+
get header_height() {
|
| 96 |
+
return header_height;
|
| 97 |
+
},
|
| 98 |
+
get row_num_width() {
|
| 99 |
+
return row_num_width;
|
| 100 |
+
},
|
| 101 |
+
get_col_style
|
| 102 |
+
};
|
| 103 |
+
}
|
6.11.0/dataframe/shared/icons/FilterIcon.svelte
CHANGED
|
@@ -1,12 +1,20 @@
|
|
| 1 |
-
<
|
| 2 |
-
</script>
|
| 3 |
-
|
| 4 |
-
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 5 |
<path
|
| 6 |
-
d="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
stroke="currentColor"
|
| 8 |
stroke-width="2"
|
| 9 |
stroke-linecap="round"
|
| 10 |
-
stroke-linejoin="round"
|
| 11 |
/>
|
| 12 |
</svg>
|
|
|
|
| 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.11.0/dataframe/shared/icons/Padlock.svelte
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<div class="wrapper" aria-label="Static column">
|
| 2 |
<svg
|
| 3 |
xmlns="http://www.w3.org/2000/svg"
|
| 4 |
-
width=
|
| 5 |
-
height=
|
| 6 |
viewBox="0 0 24 24"
|
| 7 |
fill="none"
|
| 8 |
stroke="currentColor"
|
|
|
|
| 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"
|
6.11.0/dataframe/shared/icons/SelectionButtons.svelte
CHANGED
|
@@ -1,25 +1,36 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
position === "column" ? coords[0] === 0 : coords[1] === 0
|
| 8 |
-
|
|
|
|
| 9 |
position === "column"
|
| 10 |
? is_first_position
|
| 11 |
? "down"
|
| 12 |
: "up"
|
| 13 |
: is_first_position
|
| 14 |
? "right"
|
| 15 |
-
: "left"
|
|
|
|
| 16 |
</script>
|
| 17 |
|
| 18 |
<button
|
| 19 |
class="selection-button selection-button-{position} {is_first_position
|
| 20 |
? `move-${direction}`
|
| 21 |
: ''}"
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
aria-label={`Select ${position}`}
|
| 24 |
>
|
| 25 |
<span class={direction}>
|
|
@@ -50,6 +61,8 @@
|
|
| 50 |
|
| 51 |
.selection-button-row {
|
| 52 |
left: calc(var(--size-2-5) * -1);
|
|
|
|
|
|
|
| 53 |
border-radius: var(--radius-sm) 0 0 var(--radius-sm);
|
| 54 |
}
|
| 55 |
|
|
@@ -62,6 +75,8 @@
|
|
| 62 |
.move-right {
|
| 63 |
left: auto;
|
| 64 |
right: calc(var(--size-2-5) * -1);
|
|
|
|
|
|
|
| 65 |
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
|
| 66 |
}
|
| 67 |
|
|
|
|
| 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}>
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
6.11.0/dataframe/shared/icons/SortButtonDown.svelte
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<svg
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
fill="none"
|
| 4 |
xmlns="http://www.w3.org/2000/svg"
|
| 5 |
-
focusable="false"
|
| 6 |
>
|
| 7 |
<path
|
| 8 |
-
d="
|
| 9 |
stroke="currentColor"
|
| 10 |
-
stroke-width="
|
| 11 |
stroke-linecap="round"
|
| 12 |
stroke-linejoin="round"
|
| 13 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
</svg>
|
|
|
|
| 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.11.0/dataframe/shared/icons/SortButtonUp.svelte
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<svg
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
fill="none"
|
| 4 |
xmlns="http://www.w3.org/2000/svg"
|
| 5 |
-
aria-hidden="true"
|
| 6 |
-
focusable="false"
|
| 7 |
>
|
| 8 |
<path
|
| 9 |
-
d="
|
| 10 |
stroke="currentColor"
|
| 11 |
-
stroke-width="
|
| 12 |
stroke-linecap="round"
|
| 13 |
stroke-linejoin="round"
|
| 14 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
</svg>
|
|
|
|
| 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.11.0/dataframe/shared/icons/SortIcon.svelte
CHANGED
|
@@ -1,15 +1,21 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import { createEventDispatcher } from "svelte";
|
| 3 |
import type { I18nFormatter } from "@gradio/utils";
|
| 4 |
import SortButtonUp from "./SortButtonUp.svelte";
|
| 5 |
import SortButtonDown from "./SortButtonDown.svelte";
|
| 6 |
import { IconButton } from "@gradio/atoms";
|
| 7 |
type SortDirection = "asc" | "desc";
|
| 8 |
-
export let direction: SortDirection | null = null;
|
| 9 |
-
export let priority: number | null = null;
|
| 10 |
-
export let i18n: I18nFormatter;
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
</script>
|
| 14 |
|
| 15 |
<div class="sort-icons" role="group" aria-label={i18n("dataframe.sort_column")}>
|
|
@@ -25,7 +31,7 @@
|
|
| 25 |
highlight={direction === "asc"}
|
| 26 |
onclick={(event) => {
|
| 27 |
event.stopPropagation();
|
| 28 |
-
|
| 29 |
}}
|
| 30 |
></IconButton>
|
| 31 |
<IconButton
|
|
@@ -35,7 +41,7 @@
|
|
| 35 |
highlight={direction === "desc"}
|
| 36 |
onclick={(event) => {
|
| 37 |
event.stopPropagation();
|
| 38 |
-
|
| 39 |
}}
|
| 40 |
></IconButton>
|
| 41 |
</div>
|
|
|
|
| 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")}>
|
|
|
|
| 31 |
highlight={direction === "asc"}
|
| 32 |
onclick={(event) => {
|
| 33 |
event.stopPropagation();
|
| 34 |
+
onsort?.("asc");
|
| 35 |
}}
|
| 36 |
></IconButton>
|
| 37 |
<IconButton
|
|
|
|
| 41 |
highlight={direction === "desc"}
|
| 42 |
onclick={(event) => {
|
| 43 |
event.stopPropagation();
|
| 44 |
+
onsort?.("desc");
|
| 45 |
}}
|
| 46 |
></IconButton>
|
| 47 |
</div>
|
6.11.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.11.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.11.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.11.0/dataframe/shared/types.ts
CHANGED
|
@@ -29,3 +29,6 @@ export type ElementRefs = Record<
|
|
| 29 |
>;
|
| 30 |
|
| 31 |
export type DataBinding = Record<string, TableCell>;
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
>;
|
| 30 |
|
| 31 |
export type DataBinding = Record<string, TableCell>;
|
| 32 |
+
|
| 33 |
+
export type SortDirection = "asc" | "desc";
|
| 34 |
+
export type FilterDatatype = "string" | "number";
|
6.11.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.11.0/dataframe/shared/utils/selection_utils.ts
CHANGED
|
@@ -37,7 +37,7 @@ export function get_range_selection(
|
|
| 37 |
const max_col = Math.max(start_col, end_col);
|
| 38 |
|
| 39 |
const cells: CellCoordinate[] = [];
|
| 40 |
-
//
|
| 41 |
// we press shift+arrow keys, the selection will always
|
| 42 |
// include the anchor cell.
|
| 43 |
cells.push(start);
|
|
|
|
| 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);
|
6.11.0/dataframe/shared/utils/table_utils.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
| 1 |
-
import type {
|
| 2 |
-
CellValue,
|
| 3 |
-
Headers,
|
| 4 |
-
HeadersWithIDs,
|
| 5 |
-
TableCell,
|
| 6 |
-
TableData
|
| 7 |
-
} from "../types";
|
| 8 |
-
import { sort_data } from "./sort_utils";
|
| 9 |
-
import { filter_data } from "./filter_utils";
|
| 10 |
-
import type { SortDirection } from "./sort_utils";
|
| 11 |
-
import type { FilterDatatype } from "./filter_utils";
|
| 12 |
import { dsvFormat } from "d3-dsv";
|
| 13 |
|
| 14 |
export function make_cell_id(row: number, col: number): string {
|
|
@@ -19,94 +9,6 @@ export function make_header_id(col: number): string {
|
|
| 19 |
return `header-${col}`;
|
| 20 |
}
|
| 21 |
|
| 22 |
-
export function get_max(data: TableData): TableCell[] {
|
| 23 |
-
if (!data || !data.length) return [];
|
| 24 |
-
let max = data[0].slice();
|
| 25 |
-
for (let i = 0; i < data.length; i++) {
|
| 26 |
-
for (let j = 0; j < data[i].length; j++) {
|
| 27 |
-
if (`${max[j].value}`.length < `${data[i][j].value}`.length) {
|
| 28 |
-
max[j] = data[i][j];
|
| 29 |
-
}
|
| 30 |
-
}
|
| 31 |
-
}
|
| 32 |
-
return max;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
export function sort_table_data(
|
| 36 |
-
data: TableData,
|
| 37 |
-
display_value: string[][] | null,
|
| 38 |
-
styling: string[][] | null,
|
| 39 |
-
sort_columns: { col: number; direction: SortDirection }[]
|
| 40 |
-
): void {
|
| 41 |
-
if (!sort_columns.length) return;
|
| 42 |
-
if (!data || !data.length) return;
|
| 43 |
-
|
| 44 |
-
const indices = sort_data(data, sort_columns);
|
| 45 |
-
|
| 46 |
-
const new_data = indices.map((i: number) => data[i]);
|
| 47 |
-
data.splice(0, data.length, ...new_data);
|
| 48 |
-
|
| 49 |
-
if (display_value) {
|
| 50 |
-
const new_display = indices.map((i: number) => display_value[i]);
|
| 51 |
-
display_value.splice(0, display_value.length, ...new_display);
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
if (styling) {
|
| 55 |
-
const new_styling = indices.map((i: number) => styling[i]);
|
| 56 |
-
styling.splice(0, styling.length, ...new_styling);
|
| 57 |
-
}
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
export function filter_table_data(
|
| 61 |
-
data: TableData,
|
| 62 |
-
display_value: string[][] | null,
|
| 63 |
-
styling: string[][] | null,
|
| 64 |
-
filter_columns: {
|
| 65 |
-
col: number;
|
| 66 |
-
datatype: FilterDatatype;
|
| 67 |
-
filter: string;
|
| 68 |
-
value: string;
|
| 69 |
-
}[],
|
| 70 |
-
original_data?: TableData,
|
| 71 |
-
original_display_value?: string[][] | null,
|
| 72 |
-
original_styling?: string[][] | null
|
| 73 |
-
): void {
|
| 74 |
-
const base_data = original_data ?? data;
|
| 75 |
-
const base_display_value = original_display_value ?? display_value;
|
| 76 |
-
const base_styling = original_styling ?? styling;
|
| 77 |
-
|
| 78 |
-
if (!filter_columns.length) {
|
| 79 |
-
data.splice(0, data.length, ...base_data.map((row) => [...row]));
|
| 80 |
-
if (display_value && base_display_value) {
|
| 81 |
-
display_value.splice(
|
| 82 |
-
0,
|
| 83 |
-
display_value.length,
|
| 84 |
-
...base_display_value.map((row) => [...row])
|
| 85 |
-
);
|
| 86 |
-
}
|
| 87 |
-
if (styling && base_styling) {
|
| 88 |
-
styling.splice(0, styling.length, ...base_styling.map((row) => [...row]));
|
| 89 |
-
}
|
| 90 |
-
return;
|
| 91 |
-
}
|
| 92 |
-
if (!data || !data.length) return;
|
| 93 |
-
|
| 94 |
-
const indices = filter_data(base_data, filter_columns);
|
| 95 |
-
|
| 96 |
-
const new_data = indices.map((i: number) => base_data[i]);
|
| 97 |
-
data.splice(0, data.length, ...new_data);
|
| 98 |
-
|
| 99 |
-
if (display_value && base_display_value) {
|
| 100 |
-
const new_display = indices.map((i: number) => base_display_value[i]);
|
| 101 |
-
display_value.splice(0, display_value.length, ...new_display);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
if (styling && base_styling) {
|
| 105 |
-
const new_styling = indices.map((i: number) => base_styling[i]);
|
| 106 |
-
styling.splice(0, styling.length, ...new_styling);
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
export async function copy_table_data(
|
| 111 |
data: TableData,
|
| 112 |
selected_cells: [number, number][] | null
|
|
@@ -145,7 +47,6 @@ export async function copy_table_data(
|
|
| 145 |
}
|
| 146 |
}
|
| 147 |
|
| 148 |
-
// File Import/Export
|
| 149 |
export function guess_delimiter(
|
| 150 |
text: string,
|
| 151 |
possibleDelimiters: string[]
|
|
|
|
| 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 {
|
|
|
|
| 9 |
return `header-${col}`;
|
| 10 |
}
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
export async function copy_table_data(
|
| 13 |
data: TableData,
|
| 14 |
selected_cells: [number, number][] | null
|
|
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
|
|
|
| 50 |
export function guess_delimiter(
|
| 51 |
text: string,
|
| 52 |
possibleDelimiters: string[]
|
6.11.0/dataframe/standalone/Index.svelte
CHANGED
|
@@ -5,7 +5,52 @@
|
|
| 5 |
import type { I18nFormatter } from "@gradio/utils";
|
| 6 |
import { default_i18n } from "./default_i18n";
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
const i18n_fn = (key: string | null | undefined): string => {
|
| 10 |
if (!key) return "";
|
| 11 |
if (typeof i18n === "function") return (i18n as any)(key);
|
|
@@ -14,31 +59,7 @@
|
|
| 14 |
return default_i18n[key] ?? key;
|
| 15 |
};
|
| 16 |
|
| 17 |
-
|
| 18 |
-
data: [["", "", ""]],
|
| 19 |
-
headers: ["1", "2", "3"],
|
| 20 |
-
metadata: null
|
| 21 |
-
};
|
| 22 |
-
export let datatype: Datatype | Datatype[] = "str";
|
| 23 |
-
export let interactive = true;
|
| 24 |
-
export let show_row_numbers = false;
|
| 25 |
-
export let max_height = 500;
|
| 26 |
-
export let show_search: "none" | "search" | "filter" = "none";
|
| 27 |
-
export let wrap = false;
|
| 28 |
-
export let line_breaks = true;
|
| 29 |
-
export let column_widths: string[] = [];
|
| 30 |
-
export let max_chars: number | undefined = undefined;
|
| 31 |
-
export let pinned_columns = 0;
|
| 32 |
-
export let static_columns: (string | number)[] = [];
|
| 33 |
-
export let fullscreen = false;
|
| 34 |
-
export let label: string | null = null;
|
| 35 |
-
export let show_label = true;
|
| 36 |
-
export let latex_delimiters: any[] = [];
|
| 37 |
-
export let col_count: [number, "fixed" | "dynamic"] | undefined = undefined;
|
| 38 |
-
export let row_count: [number, "fixed" | "dynamic"] | undefined = undefined;
|
| 39 |
-
|
| 40 |
-
// mirrors default row count and column count logic in dataframe.py
|
| 41 |
-
$: resolved_row_count = (() => {
|
| 42 |
if (
|
| 43 |
row_count &&
|
| 44 |
Array.isArray(row_count) &&
|
|
@@ -49,8 +70,9 @@
|
|
| 49 |
return row_count as [number, "fixed" | "dynamic"];
|
| 50 |
}
|
| 51 |
return [1, "dynamic"] as [number, "fixed" | "dynamic"];
|
| 52 |
-
})
|
| 53 |
-
|
|
|
|
| 54 |
if (
|
| 55 |
col_count &&
|
| 56 |
Array.isArray(col_count) &&
|
|
@@ -65,14 +87,21 @@
|
|
| 65 |
? value.headers.length
|
| 66 |
: 3;
|
| 67 |
return [headerLength, "dynamic"] as [number, "fixed" | "dynamic"];
|
| 68 |
-
})
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
let root = "";
|
| 78 |
|
|
@@ -91,8 +120,8 @@
|
|
| 91 |
<Table
|
| 92 |
values={value.data}
|
| 93 |
headers={value.headers}
|
| 94 |
-
display_value={value?.metadata?.display_value}
|
| 95 |
-
styling={value?.metadata?.styling}
|
| 96 |
{datatype}
|
| 97 |
editable={interactive}
|
| 98 |
{show_row_numbers}
|
|
@@ -113,15 +142,11 @@
|
|
| 113 |
row_count={resolved_row_count}
|
| 114 |
{root}
|
| 115 |
i18n={i18n_fn}
|
| 116 |
-
|
| 117 |
-
value.data =
|
| 118 |
-
value.headers =
|
| 119 |
}}
|
| 120 |
-
|
| 121 |
-
on:keydown
|
| 122 |
-
on:input
|
| 123 |
-
on:select
|
| 124 |
-
on:fullscreen={(e) => (fullscreen = e.detail)}
|
| 125 |
upload={async () => null}
|
| 126 |
stream_handler={() => new EventSource("about:blank")}
|
| 127 |
/>
|
|
|
|
| 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);
|
|
|
|
| 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) &&
|
|
|
|
| 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) &&
|
|
|
|
| 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 |
|
|
|
|
| 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}
|
|
|
|
| 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 |
/>
|
6.11.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 |
+
}
|