Upload folder using huggingface_hub
Browse files- 5.49.1/dataframe/Example.svelte +114 -0
- 5.49.1/dataframe/Index.svelte +123 -0
- 5.49.1/dataframe/package.json +50 -0
- 5.49.1/dataframe/shared/BooleanCell.svelte +49 -0
- 5.49.1/dataframe/shared/CellMenu.svelte +253 -0
- 5.49.1/dataframe/shared/CellMenuButton.svelte +46 -0
- 5.49.1/dataframe/shared/CellMenuIcons.svelte +240 -0
- 5.49.1/dataframe/shared/EditableCell.svelte +261 -0
- 5.49.1/dataframe/shared/EmptyRowButton.svelte +29 -0
- 5.49.1/dataframe/shared/Example.svelte +29 -0
- 5.49.1/dataframe/shared/FilterMenu.svelte +247 -0
- 5.49.1/dataframe/shared/RowNumber.svelte +32 -0
- 5.49.1/dataframe/shared/Table.svelte +1270 -0
- 5.49.1/dataframe/shared/TableCell.svelte +330 -0
- 5.49.1/dataframe/shared/TableHeader.svelte +344 -0
- 5.49.1/dataframe/shared/Toolbar.svelte +198 -0
- 5.49.1/dataframe/shared/VirtualTable.svelte +379 -0
- 5.49.1/dataframe/shared/context/dataframe_context.ts +701 -0
- 5.49.1/dataframe/shared/icons/FilterIcon.svelte +12 -0
- 5.49.1/dataframe/shared/icons/Padlock.svelte +24 -0
- 5.49.1/dataframe/shared/icons/SelectionButtons.svelte +93 -0
- 5.49.1/dataframe/shared/icons/SortArrowDown.svelte +25 -0
- 5.49.1/dataframe/shared/icons/SortArrowUp.svelte +25 -0
- 5.49.1/dataframe/shared/icons/SortButtonDown.svelte +14 -0
- 5.49.1/dataframe/shared/icons/SortButtonUp.svelte +15 -0
- 5.49.1/dataframe/shared/icons/SortIcon.svelte +72 -0
- 5.49.1/dataframe/shared/types.ts +31 -0
- 5.49.1/dataframe/shared/utils/data_processing.ts +77 -0
- 5.49.1/dataframe/shared/utils/drag_utils.ts +105 -0
- 5.49.1/dataframe/shared/utils/filter_utils.ts +208 -0
- 5.49.1/dataframe/shared/utils/keyboard_utils.ts +309 -0
- 5.49.1/dataframe/shared/utils/menu_utils.ts +115 -0
- 5.49.1/dataframe/shared/utils/selection_utils.ts +234 -0
- 5.49.1/dataframe/shared/utils/sort_utils.ts +91 -0
- 5.49.1/dataframe/shared/utils/table_utils.ts +194 -0
- 5.49.1/dataframe/shared/utils/utils.ts +55 -0
- 5.49.1/dataframe/standalone/Index.svelte +718 -0
- 5.49.1/dataframe/standalone/default_i18n.ts +32 -0
- 5.49.1/dataframe/standalone/stubs/Upload.svelte +19 -0
- 5.49.1/dataframe/standalone/stubs/upload.ts +1 -0
5.49.1/dataframe/Example.svelte
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let value: (string | number)[][] | string;
|
| 3 |
+
export let type: "gallery" | "table";
|
| 4 |
+
export let selected = false;
|
| 5 |
+
export let index: number;
|
| 6 |
+
|
| 7 |
+
let hovered = false;
|
| 8 |
+
let loaded = Array.isArray(value);
|
| 9 |
+
let is_empty = loaded && (value.length === 0 || value[0].length === 0);
|
| 10 |
+
</script>
|
| 11 |
+
|
| 12 |
+
{#if loaded}
|
| 13 |
+
<!-- TODO: fix-->
|
| 14 |
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
| 15 |
+
<div
|
| 16 |
+
class:table={type === "table"}
|
| 17 |
+
class:gallery={type === "gallery"}
|
| 18 |
+
class:selected
|
| 19 |
+
on:mouseenter={() => (hovered = true)}
|
| 20 |
+
on:mouseleave={() => (hovered = false)}
|
| 21 |
+
>
|
| 22 |
+
{#if typeof value === "string"}
|
| 23 |
+
{value}
|
| 24 |
+
{:else if is_empty}
|
| 25 |
+
<table class="">
|
| 26 |
+
<tr>
|
| 27 |
+
<td>Empty</td>
|
| 28 |
+
</tr>
|
| 29 |
+
</table>
|
| 30 |
+
{:else}
|
| 31 |
+
<table class="">
|
| 32 |
+
{#each value.slice(0, 3) as row, i}
|
| 33 |
+
<tr>
|
| 34 |
+
{#each row.slice(0, 3) as cell, j}
|
| 35 |
+
<td>{cell}</td>
|
| 36 |
+
{/each}
|
| 37 |
+
{#if row.length > 3}
|
| 38 |
+
<td>…</td>
|
| 39 |
+
{/if}
|
| 40 |
+
</tr>
|
| 41 |
+
{/each}
|
| 42 |
+
</table>
|
| 43 |
+
{#if value.length > 3}
|
| 44 |
+
<div
|
| 45 |
+
class="overlay"
|
| 46 |
+
class:odd={index % 2 != 0}
|
| 47 |
+
class:even={index % 2 == 0}
|
| 48 |
+
class:button={type === "gallery"}
|
| 49 |
+
></div>
|
| 50 |
+
{/if}
|
| 51 |
+
{/if}
|
| 52 |
+
</div>
|
| 53 |
+
{/if}
|
| 54 |
+
|
| 55 |
+
<style>
|
| 56 |
+
table {
|
| 57 |
+
position: relative;
|
| 58 |
+
border-collapse: collapse;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
td {
|
| 62 |
+
border: 1px solid var(--table-border-color);
|
| 63 |
+
padding: var(--size-2);
|
| 64 |
+
font-size: var(--text-sm);
|
| 65 |
+
font-family: var(--font-mono);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.selected td {
|
| 69 |
+
border-color: var(--border-color-accent);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.table {
|
| 73 |
+
display: inline-block;
|
| 74 |
+
margin: 0 auto;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.gallery td:first-child {
|
| 78 |
+
border-left: none;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.gallery tr:first-child td {
|
| 82 |
+
border-top: none;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.gallery td:last-child {
|
| 86 |
+
border-right: none;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.gallery tr:last-child td {
|
| 90 |
+
border-bottom: none;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.overlay {
|
| 94 |
+
--gradient-to: transparent;
|
| 95 |
+
position: absolute;
|
| 96 |
+
bottom: 0;
|
| 97 |
+
background: linear-gradient(to bottom, transparent, var(--gradient-to));
|
| 98 |
+
width: var(--size-full);
|
| 99 |
+
height: 50%;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/* i dont know what i've done here but it is what it is */
|
| 103 |
+
.odd {
|
| 104 |
+
--gradient-to: var(--table-even-background-fill);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.even {
|
| 108 |
+
--gradient-to: var(--table-odd-background-fill);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.button {
|
| 112 |
+
--gradient-to: var(--background-fill-primary);
|
| 113 |
+
}
|
| 114 |
+
</style>
|
5.49.1/dataframe/Index.svelte
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svelte:options accessors={true} />
|
| 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 type { Gradio, SelectData } from "@gradio/utils";
|
| 10 |
+
import { Block } from "@gradio/atoms";
|
| 11 |
+
import Table from "./shared/Table.svelte";
|
| 12 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 13 |
+
import type { LoadingStatus } from "@gradio/statustracker";
|
| 14 |
+
import type { Datatype, DataframeValue } from "./shared/utils/utils";
|
| 15 |
+
import Image from "@gradio/image";
|
| 16 |
+
|
| 17 |
+
export let elem_id = "";
|
| 18 |
+
export let elem_classes: string[] = [];
|
| 19 |
+
export let visible: boolean | "hidden" = true;
|
| 20 |
+
export let value: DataframeValue = {
|
| 21 |
+
data: [["", "", ""]],
|
| 22 |
+
headers: ["1", "2", "3"],
|
| 23 |
+
metadata: null
|
| 24 |
+
};
|
| 25 |
+
export let value_is_output = false;
|
| 26 |
+
export let col_count: [number, "fixed" | "dynamic"];
|
| 27 |
+
export let row_count: [number, "fixed" | "dynamic"];
|
| 28 |
+
export let label: string | null = null;
|
| 29 |
+
export let show_label = true;
|
| 30 |
+
export let wrap: boolean;
|
| 31 |
+
export let datatype: Datatype | Datatype[];
|
| 32 |
+
export let scale: number | null = null;
|
| 33 |
+
export let min_width: number | undefined = undefined;
|
| 34 |
+
export let root: string;
|
| 35 |
+
|
| 36 |
+
export let line_breaks = true;
|
| 37 |
+
export let column_widths: string[] = [];
|
| 38 |
+
export let gradio: Gradio<{
|
| 39 |
+
change: never;
|
| 40 |
+
select: SelectData;
|
| 41 |
+
input: never;
|
| 42 |
+
clear_status: LoadingStatus;
|
| 43 |
+
search: string | null;
|
| 44 |
+
edit: SelectData;
|
| 45 |
+
}>;
|
| 46 |
+
export let latex_delimiters: {
|
| 47 |
+
left: string;
|
| 48 |
+
right: string;
|
| 49 |
+
display: boolean;
|
| 50 |
+
}[];
|
| 51 |
+
export let max_height: number | undefined = undefined;
|
| 52 |
+
export let loading_status: LoadingStatus;
|
| 53 |
+
export let interactive: boolean;
|
| 54 |
+
export let show_fullscreen_button = false;
|
| 55 |
+
export let max_chars: number | undefined = undefined;
|
| 56 |
+
export let show_copy_button = false;
|
| 57 |
+
export let show_row_numbers = false;
|
| 58 |
+
export let show_search: "none" | "search" | "filter" = "none";
|
| 59 |
+
export let pinned_columns = 0;
|
| 60 |
+
export let static_columns: (string | number)[] = [];
|
| 61 |
+
export let fullscreen = false;
|
| 62 |
+
</script>
|
| 63 |
+
|
| 64 |
+
<Block
|
| 65 |
+
{visible}
|
| 66 |
+
padding={false}
|
| 67 |
+
{elem_id}
|
| 68 |
+
{elem_classes}
|
| 69 |
+
container={false}
|
| 70 |
+
{scale}
|
| 71 |
+
{min_width}
|
| 72 |
+
overflow_behavior="visible"
|
| 73 |
+
bind:fullscreen
|
| 74 |
+
>
|
| 75 |
+
<StatusTracker
|
| 76 |
+
autoscroll={gradio.autoscroll}
|
| 77 |
+
i18n={gradio.i18n}
|
| 78 |
+
{...loading_status}
|
| 79 |
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
| 80 |
+
/>
|
| 81 |
+
<Table
|
| 82 |
+
{root}
|
| 83 |
+
{label}
|
| 84 |
+
{show_label}
|
| 85 |
+
{row_count}
|
| 86 |
+
{col_count}
|
| 87 |
+
values={value.data}
|
| 88 |
+
display_value={value.metadata?.display_value}
|
| 89 |
+
styling={value.metadata?.styling}
|
| 90 |
+
headers={value.headers}
|
| 91 |
+
{fullscreen}
|
| 92 |
+
on:change={(e) => {
|
| 93 |
+
value.data = e.detail.data;
|
| 94 |
+
value.headers = e.detail.headers;
|
| 95 |
+
gradio.dispatch("change");
|
| 96 |
+
}}
|
| 97 |
+
on:input={(e) => gradio.dispatch("input")}
|
| 98 |
+
on:select={(e) => gradio.dispatch("select", e.detail)}
|
| 99 |
+
on:edit={(e) => gradio.dispatch("edit", e.detail)}
|
| 100 |
+
on:fullscreen={({ detail }) => {
|
| 101 |
+
fullscreen = detail;
|
| 102 |
+
}}
|
| 103 |
+
{wrap}
|
| 104 |
+
{datatype}
|
| 105 |
+
{latex_delimiters}
|
| 106 |
+
editable={interactive}
|
| 107 |
+
{max_height}
|
| 108 |
+
i18n={gradio.i18n}
|
| 109 |
+
{line_breaks}
|
| 110 |
+
{column_widths}
|
| 111 |
+
upload={(...args) => gradio.client.upload(...args)}
|
| 112 |
+
stream_handler={(...args) => gradio.client.stream(...args)}
|
| 113 |
+
bind:value_is_output
|
| 114 |
+
{show_fullscreen_button}
|
| 115 |
+
{max_chars}
|
| 116 |
+
{show_copy_button}
|
| 117 |
+
{show_row_numbers}
|
| 118 |
+
{show_search}
|
| 119 |
+
{pinned_columns}
|
| 120 |
+
components={{ image: Image }}
|
| 121 |
+
{static_columns}
|
| 122 |
+
/>
|
| 123 |
+
</Block>
|
5.49.1/dataframe/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/dataframe",
|
| 3 |
+
"version": "0.20.1",
|
| 4 |
+
"description": "Gradio UI packages",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"author": "",
|
| 7 |
+
"license": "ISC",
|
| 8 |
+
"private": false,
|
| 9 |
+
"main_changeset": true,
|
| 10 |
+
"main": "./Index.svelte",
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"@gradio/atoms": "workspace:^",
|
| 13 |
+
"@gradio/button": "workspace:^",
|
| 14 |
+
"@gradio/checkbox": "workspace:^",
|
| 15 |
+
"@gradio/icons": "workspace:^",
|
| 16 |
+
"@gradio/markdown-code": "workspace:^",
|
| 17 |
+
"@gradio/statustracker": "workspace:^",
|
| 18 |
+
"@gradio/upload": "workspace:^",
|
| 19 |
+
"@gradio/client": "workspace:^",
|
| 20 |
+
"@gradio/utils": "workspace:^",
|
| 21 |
+
"@types/d3-dsv": "^3.0.0",
|
| 22 |
+
"@types/katex": "^0.16.0",
|
| 23 |
+
"d3-dsv": "^3.0.1",
|
| 24 |
+
"dequal": "^2.0.2"
|
| 25 |
+
},
|
| 26 |
+
"exports": {
|
| 27 |
+
".": {
|
| 28 |
+
"gradio": "./Index.svelte",
|
| 29 |
+
"svelte": "./dist/standalone/Index.svelte",
|
| 30 |
+
"types": "./dist/standalone/Index.svelte.d.ts"
|
| 31 |
+
},
|
| 32 |
+
"./example": {
|
| 33 |
+
"gradio": "./Example.svelte",
|
| 34 |
+
"svelte": "./dist/Example.svelte",
|
| 35 |
+
"types": "./dist/Example.svelte.d.ts"
|
| 36 |
+
},
|
| 37 |
+
"./package.json": "./package.json"
|
| 38 |
+
},
|
| 39 |
+
"peerDependencies": {
|
| 40 |
+
"svelte": ">=4.0.0 <6.0.0"
|
| 41 |
+
},
|
| 42 |
+
"devDependencies": {
|
| 43 |
+
"@gradio/preview": "workspace:^"
|
| 44 |
+
},
|
| 45 |
+
"repository": {
|
| 46 |
+
"type": "git",
|
| 47 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 48 |
+
"directory": "js/dataframe"
|
| 49 |
+
}
|
| 50 |
+
}
|
5.49.1/dataframe/shared/BooleanCell.svelte
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { BaseCheckbox } from "@gradio/checkbox";
|
| 3 |
+
|
| 4 |
+
export let value = false;
|
| 5 |
+
export let editable = true;
|
| 6 |
+
export let on_change: (value: boolean) => void;
|
| 7 |
+
|
| 8 |
+
function handle_change(event: CustomEvent<boolean>): void {
|
| 9 |
+
if (editable) {
|
| 10 |
+
on_change(event.detail);
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
</script>
|
| 14 |
+
|
| 15 |
+
<div class="bool-cell" role="button" tabindex="-1">
|
| 16 |
+
<BaseCheckbox
|
| 17 |
+
bind:value
|
| 18 |
+
label=""
|
| 19 |
+
interactive={editable}
|
| 20 |
+
on:change={handle_change}
|
| 21 |
+
/>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<style>
|
| 25 |
+
.bool-cell {
|
| 26 |
+
display: flex;
|
| 27 |
+
align-items: center;
|
| 28 |
+
justify-content: center;
|
| 29 |
+
width: min-content;
|
| 30 |
+
height: var(--size-full);
|
| 31 |
+
margin: 0 auto;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.bool-cell :global(input:disabled) {
|
| 35 |
+
cursor: not-allowed;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.bool-cell :global(label) {
|
| 39 |
+
margin: 0;
|
| 40 |
+
width: 100%;
|
| 41 |
+
display: flex;
|
| 42 |
+
justify-content: center;
|
| 43 |
+
align-items: center;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.bool-cell :global(span) {
|
| 47 |
+
display: none;
|
| 48 |
+
}
|
| 49 |
+
</style>
|
5.49.1/dataframe/shared/CellMenu.svelte
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount } from "svelte";
|
| 3 |
+
import CellMenuIcons from "./CellMenuIcons.svelte";
|
| 4 |
+
import FilterMenu from "./FilterMenu.svelte";
|
| 5 |
+
import type { I18nFormatter } from "@gradio/utils";
|
| 6 |
+
import type {
|
| 7 |
+
SortDirection,
|
| 8 |
+
FilterDatatype
|
| 9 |
+
} from "./context/dataframe_context";
|
| 10 |
+
|
| 11 |
+
export let x: number;
|
| 12 |
+
export let y: number;
|
| 13 |
+
export let on_add_row_above: () => void;
|
| 14 |
+
export let on_add_row_below: () => void;
|
| 15 |
+
export let on_add_column_left: () => void;
|
| 16 |
+
export let on_add_column_right: () => void;
|
| 17 |
+
export let row: number;
|
| 18 |
+
export let col_count: [number, "fixed" | "dynamic"];
|
| 19 |
+
export let row_count: [number, "fixed" | "dynamic"];
|
| 20 |
+
export let on_delete_row: () => void;
|
| 21 |
+
export let on_delete_col: () => void;
|
| 22 |
+
export let can_delete_rows: boolean;
|
| 23 |
+
export let can_delete_cols: boolean;
|
| 24 |
+
export let on_sort: (direction: SortDirection) => void = () => {};
|
| 25 |
+
export let on_clear_sort: () => void = () => {};
|
| 26 |
+
export let sort_direction: SortDirection | null = null;
|
| 27 |
+
export let sort_priority: number | null = null;
|
| 28 |
+
export let on_filter: (
|
| 29 |
+
datatype: FilterDatatype,
|
| 30 |
+
selected_filter: string,
|
| 31 |
+
value: string
|
| 32 |
+
) => void = () => {};
|
| 33 |
+
export let on_clear_filter: () => void = () => {};
|
| 34 |
+
export let filter_active: boolean | null = null;
|
| 35 |
+
export let editable = true;
|
| 36 |
+
|
| 37 |
+
export let i18n: I18nFormatter;
|
| 38 |
+
let menu_element: HTMLDivElement;
|
| 39 |
+
let active_filter_menu: { x: number; y: number } | null = null;
|
| 40 |
+
|
| 41 |
+
$: is_header = row === -1;
|
| 42 |
+
$: can_add_rows = editable && row_count[1] === "dynamic";
|
| 43 |
+
$: can_add_columns = editable && col_count[1] === "dynamic";
|
| 44 |
+
|
| 45 |
+
onMount(() => {
|
| 46 |
+
position_menu();
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
function position_menu(): void {
|
| 50 |
+
if (!menu_element) return;
|
| 51 |
+
|
| 52 |
+
const viewport_width = window.innerWidth;
|
| 53 |
+
const viewport_height = window.innerHeight;
|
| 54 |
+
const menu_rect = menu_element.getBoundingClientRect();
|
| 55 |
+
|
| 56 |
+
let new_x = x - 30;
|
| 57 |
+
let new_y = y - 20;
|
| 58 |
+
|
| 59 |
+
if (new_x + menu_rect.width > viewport_width) {
|
| 60 |
+
new_x = x - menu_rect.width + 10;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (new_y + menu_rect.height > viewport_height) {
|
| 64 |
+
new_y = y - menu_rect.height + 10;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
menu_element.style.left = `${new_x}px`;
|
| 68 |
+
menu_element.style.top = `${new_y}px`;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function toggle_filter_menu(): void {
|
| 72 |
+
if (filter_active) {
|
| 73 |
+
on_filter("string", "", "");
|
| 74 |
+
return;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
const menu_rect = menu_element.getBoundingClientRect();
|
| 78 |
+
active_filter_menu = {
|
| 79 |
+
x: menu_rect.right,
|
| 80 |
+
y: menu_rect.top + menu_rect.height / 2
|
| 81 |
+
};
|
| 82 |
+
}
|
| 83 |
+
</script>
|
| 84 |
+
|
| 85 |
+
<div bind:this={menu_element} class="cell-menu" role="menu">
|
| 86 |
+
{#if is_header}
|
| 87 |
+
<button
|
| 88 |
+
role="menuitem"
|
| 89 |
+
on:click={() => on_sort("asc")}
|
| 90 |
+
class:active={sort_direction === "asc"}
|
| 91 |
+
>
|
| 92 |
+
<CellMenuIcons icon="sort-asc" />
|
| 93 |
+
{i18n("dataframe.sort_ascending")}
|
| 94 |
+
{#if sort_direction === "asc" && sort_priority !== null}
|
| 95 |
+
<span class="priority">{sort_priority}</span>
|
| 96 |
+
{/if}
|
| 97 |
+
</button>
|
| 98 |
+
<button
|
| 99 |
+
role="menuitem"
|
| 100 |
+
on:click={() => on_sort("desc")}
|
| 101 |
+
class:active={sort_direction === "desc"}
|
| 102 |
+
>
|
| 103 |
+
<CellMenuIcons icon="sort-desc" />
|
| 104 |
+
{i18n("dataframe.sort_descending")}
|
| 105 |
+
{#if sort_direction === "desc" && sort_priority !== null}
|
| 106 |
+
<span class="priority">{sort_priority}</span>
|
| 107 |
+
{/if}
|
| 108 |
+
</button>
|
| 109 |
+
<button role="menuitem" on:click={on_clear_sort}>
|
| 110 |
+
<CellMenuIcons icon="clear-sort" />
|
| 111 |
+
{i18n("dataframe.clear_sort")}
|
| 112 |
+
</button>
|
| 113 |
+
<button
|
| 114 |
+
role="menuitem"
|
| 115 |
+
on:click|stopPropagation={toggle_filter_menu}
|
| 116 |
+
class:active={filter_active || active_filter_menu}
|
| 117 |
+
>
|
| 118 |
+
<CellMenuIcons icon="filter" />
|
| 119 |
+
{i18n("dataframe.filter")}
|
| 120 |
+
{#if filter_active}
|
| 121 |
+
<span class="priority">1</span>
|
| 122 |
+
{/if}
|
| 123 |
+
</button>
|
| 124 |
+
<button role="menuitem" on:click={on_clear_filter}>
|
| 125 |
+
<CellMenuIcons icon="clear-filter" />
|
| 126 |
+
{i18n("dataframe.clear_filter")}
|
| 127 |
+
</button>
|
| 128 |
+
{/if}
|
| 129 |
+
|
| 130 |
+
{#if !is_header && can_add_rows}
|
| 131 |
+
<button
|
| 132 |
+
role="menuitem"
|
| 133 |
+
on:click={() => on_add_row_above()}
|
| 134 |
+
aria-label="Add row above"
|
| 135 |
+
>
|
| 136 |
+
<CellMenuIcons icon="add-row-above" />
|
| 137 |
+
{i18n("dataframe.add_row_above")}
|
| 138 |
+
</button>
|
| 139 |
+
<button
|
| 140 |
+
role="menuitem"
|
| 141 |
+
on:click={() => on_add_row_below()}
|
| 142 |
+
aria-label="Add row below"
|
| 143 |
+
>
|
| 144 |
+
<CellMenuIcons icon="add-row-below" />
|
| 145 |
+
{i18n("dataframe.add_row_below")}
|
| 146 |
+
</button>
|
| 147 |
+
{#if can_delete_rows}
|
| 148 |
+
<button
|
| 149 |
+
role="menuitem"
|
| 150 |
+
on:click={on_delete_row}
|
| 151 |
+
class="delete"
|
| 152 |
+
aria-label="Delete row"
|
| 153 |
+
>
|
| 154 |
+
<CellMenuIcons icon="delete-row" />
|
| 155 |
+
{i18n("dataframe.delete_row")}
|
| 156 |
+
</button>
|
| 157 |
+
{/if}
|
| 158 |
+
{/if}
|
| 159 |
+
{#if can_add_columns}
|
| 160 |
+
<button
|
| 161 |
+
role="menuitem"
|
| 162 |
+
on:click={() => on_add_column_left()}
|
| 163 |
+
aria-label="Add column to the left"
|
| 164 |
+
>
|
| 165 |
+
<CellMenuIcons icon="add-column-left" />
|
| 166 |
+
{i18n("dataframe.add_column_left")}
|
| 167 |
+
</button>
|
| 168 |
+
<button
|
| 169 |
+
role="menuitem"
|
| 170 |
+
on:click={() => on_add_column_right()}
|
| 171 |
+
aria-label="Add column to the right"
|
| 172 |
+
>
|
| 173 |
+
<CellMenuIcons icon="add-column-right" />
|
| 174 |
+
{i18n("dataframe.add_column_right")}
|
| 175 |
+
</button>
|
| 176 |
+
{#if can_delete_cols}
|
| 177 |
+
<button
|
| 178 |
+
role="menuitem"
|
| 179 |
+
on:click={on_delete_col}
|
| 180 |
+
class="delete"
|
| 181 |
+
aria-label="Delete column"
|
| 182 |
+
>
|
| 183 |
+
<CellMenuIcons icon="delete-column" />
|
| 184 |
+
{i18n("dataframe.delete_column")}
|
| 185 |
+
</button>
|
| 186 |
+
{/if}
|
| 187 |
+
{/if}
|
| 188 |
+
</div>
|
| 189 |
+
|
| 190 |
+
{#if active_filter_menu}
|
| 191 |
+
<FilterMenu {on_filter} />
|
| 192 |
+
{/if}
|
| 193 |
+
|
| 194 |
+
<style>
|
| 195 |
+
.cell-menu {
|
| 196 |
+
position: fixed;
|
| 197 |
+
z-index: 9;
|
| 198 |
+
background: var(--background-fill-primary);
|
| 199 |
+
border: 1px solid var(--border-color-primary);
|
| 200 |
+
border-radius: var(--radius-sm);
|
| 201 |
+
padding: var(--size-1);
|
| 202 |
+
display: flex;
|
| 203 |
+
flex-direction: column;
|
| 204 |
+
gap: var(--size-1);
|
| 205 |
+
box-shadow: var(--shadow-drop-lg);
|
| 206 |
+
min-width: 150px;
|
| 207 |
+
z-index: var(--layer-1);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.cell-menu button {
|
| 211 |
+
background: none;
|
| 212 |
+
border: none;
|
| 213 |
+
cursor: pointer;
|
| 214 |
+
text-align: left;
|
| 215 |
+
padding: var(--size-1) var(--size-2);
|
| 216 |
+
border-radius: var(--radius-sm);
|
| 217 |
+
color: var(--body-text-color);
|
| 218 |
+
font-size: var(--text-sm);
|
| 219 |
+
transition:
|
| 220 |
+
background-color 0.2s,
|
| 221 |
+
color 0.2s;
|
| 222 |
+
display: flex;
|
| 223 |
+
align-items: center;
|
| 224 |
+
gap: var(--size-2);
|
| 225 |
+
position: relative;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.cell-menu button.active {
|
| 229 |
+
background-color: var(--background-fill-secondary);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.cell-menu button:hover {
|
| 233 |
+
background-color: var(--background-fill-secondary);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
.cell-menu button :global(svg) {
|
| 237 |
+
fill: currentColor;
|
| 238 |
+
transition: fill 0.2s;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
.priority {
|
| 242 |
+
display: flex;
|
| 243 |
+
align-items: center;
|
| 244 |
+
justify-content: center;
|
| 245 |
+
margin-left: auto;
|
| 246 |
+
font-size: var(--size-2);
|
| 247 |
+
background-color: var(--button-secondary-background-fill);
|
| 248 |
+
color: var(--body-text-color);
|
| 249 |
+
border-radius: var(--radius-sm);
|
| 250 |
+
width: var(--size-2-5);
|
| 251 |
+
height: var(--size-2-5);
|
| 252 |
+
}
|
| 253 |
+
</style>
|
5.49.1/dataframe/shared/CellMenuButton.svelte
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let on_click: (event: MouseEvent) => void;
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<button
|
| 6 |
+
aria-label="Open cell menu"
|
| 7 |
+
class="cell-menu-button"
|
| 8 |
+
aria-haspopup="menu"
|
| 9 |
+
on:click={on_click}
|
| 10 |
+
on:touchstart={(event) => {
|
| 11 |
+
event.preventDefault();
|
| 12 |
+
const touch = event.touches[0];
|
| 13 |
+
const mouseEvent = new MouseEvent("click", {
|
| 14 |
+
clientX: touch.clientX,
|
| 15 |
+
clientY: touch.clientY,
|
| 16 |
+
bubbles: true,
|
| 17 |
+
cancelable: true,
|
| 18 |
+
view: window
|
| 19 |
+
});
|
| 20 |
+
on_click(mouseEvent);
|
| 21 |
+
}}
|
| 22 |
+
>
|
| 23 |
+
⋮
|
| 24 |
+
</button>
|
| 25 |
+
|
| 26 |
+
<style>
|
| 27 |
+
.cell-menu-button {
|
| 28 |
+
flex-shrink: 0;
|
| 29 |
+
display: none;
|
| 30 |
+
align-items: center;
|
| 31 |
+
justify-content: center;
|
| 32 |
+
background-color: var(--block-background-fill);
|
| 33 |
+
border: 1px solid var(--border-color-primary);
|
| 34 |
+
border-radius: var(--block-radius);
|
| 35 |
+
width: var(--size-5);
|
| 36 |
+
height: var(--size-5);
|
| 37 |
+
min-width: var(--size-5);
|
| 38 |
+
padding: 0;
|
| 39 |
+
margin-right: var(--spacing-sm);
|
| 40 |
+
z-index: 2;
|
| 41 |
+
position: absolute;
|
| 42 |
+
right: var(--size-1);
|
| 43 |
+
top: 50%;
|
| 44 |
+
transform: translateY(-50%);
|
| 45 |
+
}
|
| 46 |
+
</style>
|
5.49.1/dataframe/shared/CellMenuIcons.svelte
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let icon: string;
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
{#if icon == "add-column-right"}
|
| 6 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 7 |
+
<rect
|
| 8 |
+
x="4"
|
| 9 |
+
y="6"
|
| 10 |
+
width="4"
|
| 11 |
+
height="12"
|
| 12 |
+
stroke="currentColor"
|
| 13 |
+
stroke-width="2"
|
| 14 |
+
fill="none"
|
| 15 |
+
/>
|
| 16 |
+
<path
|
| 17 |
+
d="M12 12H19M16 8L19 12L16 16"
|
| 18 |
+
stroke="currentColor"
|
| 19 |
+
stroke-width="2"
|
| 20 |
+
fill="none"
|
| 21 |
+
stroke-linecap="round"
|
| 22 |
+
/>
|
| 23 |
+
</svg>
|
| 24 |
+
{:else if icon == "add-column-left"}
|
| 25 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 26 |
+
<rect
|
| 27 |
+
x="16"
|
| 28 |
+
y="6"
|
| 29 |
+
width="4"
|
| 30 |
+
height="12"
|
| 31 |
+
stroke="currentColor"
|
| 32 |
+
stroke-width="2"
|
| 33 |
+
fill="none"
|
| 34 |
+
/>
|
| 35 |
+
<path
|
| 36 |
+
d="M12 12H5M8 8L5 12L8 16"
|
| 37 |
+
stroke="currentColor"
|
| 38 |
+
stroke-width="2"
|
| 39 |
+
fill="none"
|
| 40 |
+
stroke-linecap="round"
|
| 41 |
+
/>
|
| 42 |
+
</svg>
|
| 43 |
+
{:else if icon == "add-row-above"}
|
| 44 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 45 |
+
<rect
|
| 46 |
+
x="6"
|
| 47 |
+
y="16"
|
| 48 |
+
width="12"
|
| 49 |
+
height="4"
|
| 50 |
+
stroke="currentColor"
|
| 51 |
+
stroke-width="2"
|
| 52 |
+
/>
|
| 53 |
+
<path
|
| 54 |
+
d="M12 12V5M8 8L12 5L16 8"
|
| 55 |
+
stroke="currentColor"
|
| 56 |
+
stroke-width="2"
|
| 57 |
+
fill="none"
|
| 58 |
+
stroke-linecap="round"
|
| 59 |
+
/>
|
| 60 |
+
</svg>
|
| 61 |
+
{:else if icon == "add-row-below"}
|
| 62 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 63 |
+
<rect
|
| 64 |
+
x="6"
|
| 65 |
+
y="4"
|
| 66 |
+
width="12"
|
| 67 |
+
height="4"
|
| 68 |
+
stroke="currentColor"
|
| 69 |
+
stroke-width="2"
|
| 70 |
+
/>
|
| 71 |
+
<path
|
| 72 |
+
d="M12 12V19M8 16L12 19L16 16"
|
| 73 |
+
stroke="currentColor"
|
| 74 |
+
stroke-width="2"
|
| 75 |
+
fill="none"
|
| 76 |
+
stroke-linecap="round"
|
| 77 |
+
/>
|
| 78 |
+
</svg>
|
| 79 |
+
{:else if icon == "delete-row"}
|
| 80 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 81 |
+
<rect
|
| 82 |
+
x="5"
|
| 83 |
+
y="10"
|
| 84 |
+
width="14"
|
| 85 |
+
height="4"
|
| 86 |
+
stroke="currentColor"
|
| 87 |
+
stroke-width="2"
|
| 88 |
+
/>
|
| 89 |
+
<path
|
| 90 |
+
d="M8 7L16 17M16 7L8 17"
|
| 91 |
+
stroke="currentColor"
|
| 92 |
+
stroke-width="2"
|
| 93 |
+
stroke-linecap="round"
|
| 94 |
+
/>
|
| 95 |
+
</svg>
|
| 96 |
+
{:else if icon == "delete-column"}
|
| 97 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 98 |
+
<rect
|
| 99 |
+
x="10"
|
| 100 |
+
y="5"
|
| 101 |
+
width="4"
|
| 102 |
+
height="14"
|
| 103 |
+
stroke="currentColor"
|
| 104 |
+
stroke-width="2"
|
| 105 |
+
/>
|
| 106 |
+
<path
|
| 107 |
+
d="M7 8L17 16M17 8L7 16"
|
| 108 |
+
stroke="currentColor"
|
| 109 |
+
stroke-width="2"
|
| 110 |
+
stroke-linecap="round"
|
| 111 |
+
/>
|
| 112 |
+
</svg>
|
| 113 |
+
{:else if icon == "sort-asc"}
|
| 114 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 115 |
+
<path
|
| 116 |
+
d="M8 16L12 12L16 16"
|
| 117 |
+
stroke="currentColor"
|
| 118 |
+
stroke-width="2"
|
| 119 |
+
fill="none"
|
| 120 |
+
stroke-linecap="round"
|
| 121 |
+
stroke-linejoin="round"
|
| 122 |
+
/>
|
| 123 |
+
<path
|
| 124 |
+
d="M12 12V19"
|
| 125 |
+
stroke="currentColor"
|
| 126 |
+
stroke-width="2"
|
| 127 |
+
stroke-linecap="round"
|
| 128 |
+
/>
|
| 129 |
+
<path
|
| 130 |
+
d="M5 7H19"
|
| 131 |
+
stroke="currentColor"
|
| 132 |
+
stroke-width="2"
|
| 133 |
+
stroke-linecap="round"
|
| 134 |
+
/>
|
| 135 |
+
</svg>
|
| 136 |
+
{:else if icon == "sort-desc"}
|
| 137 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 138 |
+
<path
|
| 139 |
+
d="M8 12L12 16L16 12"
|
| 140 |
+
stroke="currentColor"
|
| 141 |
+
stroke-width="2"
|
| 142 |
+
fill="none"
|
| 143 |
+
stroke-linecap="round"
|
| 144 |
+
stroke-linejoin="round"
|
| 145 |
+
/>
|
| 146 |
+
<path
|
| 147 |
+
d="M12 16V9"
|
| 148 |
+
stroke="currentColor"
|
| 149 |
+
stroke-width="2"
|
| 150 |
+
stroke-linecap="round"
|
| 151 |
+
/>
|
| 152 |
+
<path
|
| 153 |
+
d="M5 5H19"
|
| 154 |
+
stroke="currentColor"
|
| 155 |
+
stroke-width="2"
|
| 156 |
+
stroke-linecap="round"
|
| 157 |
+
/>
|
| 158 |
+
</svg>
|
| 159 |
+
{:else if icon == "clear-sort"}
|
| 160 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 161 |
+
<path
|
| 162 |
+
d="M5 5H19"
|
| 163 |
+
stroke="currentColor"
|
| 164 |
+
stroke-width="2"
|
| 165 |
+
stroke-linecap="round"
|
| 166 |
+
/>
|
| 167 |
+
<path
|
| 168 |
+
d="M5 9H15"
|
| 169 |
+
stroke="currentColor"
|
| 170 |
+
stroke-width="2"
|
| 171 |
+
stroke-linecap="round"
|
| 172 |
+
/>
|
| 173 |
+
<path
|
| 174 |
+
d="M5 13H11"
|
| 175 |
+
stroke="currentColor"
|
| 176 |
+
stroke-width="2"
|
| 177 |
+
stroke-linecap="round"
|
| 178 |
+
/>
|
| 179 |
+
<path
|
| 180 |
+
d="M5 17H7"
|
| 181 |
+
stroke="currentColor"
|
| 182 |
+
stroke-width="2"
|
| 183 |
+
stroke-linecap="round"
|
| 184 |
+
/>
|
| 185 |
+
<path
|
| 186 |
+
d="M17 17L21 21M21 17L17 21"
|
| 187 |
+
stroke="currentColor"
|
| 188 |
+
stroke-width="2"
|
| 189 |
+
stroke-linecap="round"
|
| 190 |
+
/>
|
| 191 |
+
</svg>
|
| 192 |
+
{:else if icon == "filter"}
|
| 193 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 194 |
+
<path
|
| 195 |
+
d="M5 5H19"
|
| 196 |
+
stroke="currentColor"
|
| 197 |
+
stroke-width="2"
|
| 198 |
+
stroke-linecap="round"
|
| 199 |
+
/>
|
| 200 |
+
<path
|
| 201 |
+
d="M8 9H16"
|
| 202 |
+
stroke="currentColor"
|
| 203 |
+
stroke-width="2"
|
| 204 |
+
stroke-linecap="round"
|
| 205 |
+
/>
|
| 206 |
+
<path
|
| 207 |
+
d="M11 13H13"
|
| 208 |
+
stroke="currentColor"
|
| 209 |
+
stroke-width="2"
|
| 210 |
+
stroke-linecap="round"
|
| 211 |
+
/>
|
| 212 |
+
</svg>
|
| 213 |
+
{:else if icon == "clear-filter"}
|
| 214 |
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
| 215 |
+
<path
|
| 216 |
+
d="M5 5H19"
|
| 217 |
+
stroke="currentColor"
|
| 218 |
+
stroke-width="2"
|
| 219 |
+
stroke-linecap="round"
|
| 220 |
+
/>
|
| 221 |
+
<path
|
| 222 |
+
d="M8 9H16"
|
| 223 |
+
stroke="currentColor"
|
| 224 |
+
stroke-width="2"
|
| 225 |
+
stroke-linecap="round"
|
| 226 |
+
/>
|
| 227 |
+
<path
|
| 228 |
+
d="M11 13H13"
|
| 229 |
+
stroke="currentColor"
|
| 230 |
+
stroke-width="2"
|
| 231 |
+
stroke-linecap="round"
|
| 232 |
+
/>
|
| 233 |
+
<path
|
| 234 |
+
d="M17 17L21 21M21 17L17 21"
|
| 235 |
+
stroke="currentColor"
|
| 236 |
+
stroke-width="2"
|
| 237 |
+
stroke-linecap="round"
|
| 238 |
+
/>
|
| 239 |
+
</svg>
|
| 240 |
+
{/if}
|
5.49.1/dataframe/shared/EditableCell.svelte
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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 |
+
export let edit: boolean;
|
| 10 |
+
export let value: CellValue = "";
|
| 11 |
+
export let display_value: string | null = null;
|
| 12 |
+
export let styling = "";
|
| 13 |
+
export let header = false;
|
| 14 |
+
export let datatype:
|
| 15 |
+
| "str"
|
| 16 |
+
| "markdown"
|
| 17 |
+
| "html"
|
| 18 |
+
| "number"
|
| 19 |
+
| "bool"
|
| 20 |
+
| "date"
|
| 21 |
+
| "image" = "str";
|
| 22 |
+
export let latex_delimiters: {
|
| 23 |
+
left: string;
|
| 24 |
+
right: string;
|
| 25 |
+
display: boolean;
|
| 26 |
+
}[];
|
| 27 |
+
export let line_breaks = true;
|
| 28 |
+
export let editable = true;
|
| 29 |
+
export let is_static = false;
|
| 30 |
+
export let max_chars: number | null = null;
|
| 31 |
+
export let components: Record<string, any> = {};
|
| 32 |
+
export let i18n: I18nFormatter;
|
| 33 |
+
export let is_dragging = false;
|
| 34 |
+
export let wrap_text = false;
|
| 35 |
+
|
| 36 |
+
export let show_selection_buttons = false;
|
| 37 |
+
export let coords: [number, number];
|
| 38 |
+
export let on_select_column: ((col: number) => void) | null = null;
|
| 39 |
+
export let on_select_row: ((row: number) => void) | null = null;
|
| 40 |
+
export let el: HTMLTextAreaElement | null;
|
| 41 |
+
|
| 42 |
+
const dispatch = createEventDispatcher<{
|
| 43 |
+
blur: { blur_event: FocusEvent; coords: [number, number] };
|
| 44 |
+
keydown: KeyboardEvent;
|
| 45 |
+
}>();
|
| 46 |
+
|
| 47 |
+
function truncate_text(
|
| 48 |
+
text: CellValue,
|
| 49 |
+
max_length: number | null = null,
|
| 50 |
+
is_image = false
|
| 51 |
+
): string {
|
| 52 |
+
if (is_image) return String(text);
|
| 53 |
+
const str = String(text);
|
| 54 |
+
if (!max_length || max_length <= 0) return str;
|
| 55 |
+
if (str.length <= max_length) return str;
|
| 56 |
+
return str.slice(0, max_length) + "...";
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
$: should_truncate = !edit && max_chars !== null && max_chars > 0;
|
| 60 |
+
|
| 61 |
+
$: display_content = editable
|
| 62 |
+
? value
|
| 63 |
+
: display_value !== null
|
| 64 |
+
? display_value
|
| 65 |
+
: value;
|
| 66 |
+
|
| 67 |
+
$: display_text = should_truncate
|
| 68 |
+
? truncate_text(display_content, max_chars, datatype === "image")
|
| 69 |
+
: display_content;
|
| 70 |
+
|
| 71 |
+
function use_focus(node: HTMLTextAreaElement): any {
|
| 72 |
+
requestAnimationFrame(() => {
|
| 73 |
+
node.focus();
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
return {};
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function handle_blur(event: FocusEvent): void {
|
| 80 |
+
dispatch("blur", {
|
| 81 |
+
blur_event: event,
|
| 82 |
+
coords: coords
|
| 83 |
+
});
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function handle_keydown(event: KeyboardEvent): void {
|
| 87 |
+
dispatch("keydown", event);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
function commit_change(checked: boolean): void {
|
| 91 |
+
handle_blur({ target: { value } } as unknown as FocusEvent);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
$: if (!edit) {
|
| 95 |
+
// Shim blur on removal for Safari and Firefox
|
| 96 |
+
handle_blur({ target: { value } } as unknown as FocusEvent);
|
| 97 |
+
}
|
| 98 |
+
</script>
|
| 99 |
+
|
| 100 |
+
{#if edit && datatype !== "bool"}
|
| 101 |
+
<textarea
|
| 102 |
+
readonly={is_static}
|
| 103 |
+
aria-readonly={is_static}
|
| 104 |
+
aria-label={is_static ? "Cell is read-only" : "Edit cell"}
|
| 105 |
+
bind:this={el}
|
| 106 |
+
bind:value
|
| 107 |
+
class:header
|
| 108 |
+
tabindex="-1"
|
| 109 |
+
on:blur={handle_blur}
|
| 110 |
+
on:mousedown|stopPropagation
|
| 111 |
+
on:click|stopPropagation
|
| 112 |
+
use:use_focus
|
| 113 |
+
on:keydown={handle_keydown}
|
| 114 |
+
/>
|
| 115 |
+
{/if}
|
| 116 |
+
|
| 117 |
+
{#if datatype === "bool" && typeof value === "boolean"}
|
| 118 |
+
<BooleanCell bind:value {editable} on_change={commit_change} />
|
| 119 |
+
{:else}
|
| 120 |
+
<span
|
| 121 |
+
class:dragging={is_dragging}
|
| 122 |
+
on:keydown={handle_keydown}
|
| 123 |
+
tabindex="0"
|
| 124 |
+
role="button"
|
| 125 |
+
class:edit
|
| 126 |
+
class:expanded={edit}
|
| 127 |
+
class:multiline={header}
|
| 128 |
+
on:focus|preventDefault
|
| 129 |
+
style={styling}
|
| 130 |
+
data-editable={editable}
|
| 131 |
+
data-max-chars={max_chars}
|
| 132 |
+
data-expanded={edit}
|
| 133 |
+
placeholder=" "
|
| 134 |
+
class:text={datatype === "str"}
|
| 135 |
+
class:wrap={wrap_text}
|
| 136 |
+
>
|
| 137 |
+
{#if datatype === "image" && components.image}
|
| 138 |
+
<svelte:component
|
| 139 |
+
this={components.image}
|
| 140 |
+
value={{ url: display_text }}
|
| 141 |
+
show_label={false}
|
| 142 |
+
label="cell-image"
|
| 143 |
+
show_download_button={false}
|
| 144 |
+
{i18n}
|
| 145 |
+
gradio={{ dispatch: () => {} }}
|
| 146 |
+
/>
|
| 147 |
+
{:else if datatype === "html"}
|
| 148 |
+
{@html display_text}
|
| 149 |
+
{:else if datatype === "markdown"}
|
| 150 |
+
<MarkdownCode
|
| 151 |
+
message={display_text.toLocaleString()}
|
| 152 |
+
{latex_delimiters}
|
| 153 |
+
{line_breaks}
|
| 154 |
+
chatbot={false}
|
| 155 |
+
/>
|
| 156 |
+
{:else}
|
| 157 |
+
{display_text}
|
| 158 |
+
{/if}
|
| 159 |
+
</span>
|
| 160 |
+
{/if}
|
| 161 |
+
|
| 162 |
+
{#if show_selection_buttons && coords && on_select_column && on_select_row}
|
| 163 |
+
<SelectionButtons
|
| 164 |
+
position="column"
|
| 165 |
+
{coords}
|
| 166 |
+
on_click={() => on_select_column(coords[1])}
|
| 167 |
+
/>
|
| 168 |
+
<SelectionButtons
|
| 169 |
+
position="row"
|
| 170 |
+
{coords}
|
| 171 |
+
on_click={() => on_select_row(coords[0])}
|
| 172 |
+
/>
|
| 173 |
+
{/if}
|
| 174 |
+
|
| 175 |
+
<style>
|
| 176 |
+
.dragging {
|
| 177 |
+
cursor: crosshair !important;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
textarea {
|
| 181 |
+
position: absolute;
|
| 182 |
+
flex: 1 1 0%;
|
| 183 |
+
transform: translateX(-0.1px);
|
| 184 |
+
outline: none;
|
| 185 |
+
border: none;
|
| 186 |
+
background: transparent;
|
| 187 |
+
cursor: text;
|
| 188 |
+
width: calc(100% - var(--size-2));
|
| 189 |
+
resize: none;
|
| 190 |
+
height: 100%;
|
| 191 |
+
padding-left: 0;
|
| 192 |
+
font-size: inherit;
|
| 193 |
+
font-weight: inherit;
|
| 194 |
+
line-height: var(--line-lg);
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
textarea:focus {
|
| 198 |
+
outline: none;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
span {
|
| 202 |
+
flex: 1 1 0%;
|
| 203 |
+
position: relative;
|
| 204 |
+
display: inline-block;
|
| 205 |
+
outline: none;
|
| 206 |
+
-webkit-user-select: text;
|
| 207 |
+
-moz-user-select: text;
|
| 208 |
+
-ms-user-select: text;
|
| 209 |
+
user-select: text;
|
| 210 |
+
cursor: text;
|
| 211 |
+
width: 100%;
|
| 212 |
+
height: 100%;
|
| 213 |
+
overflow: hidden;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
span.text.expanded {
|
| 217 |
+
height: auto;
|
| 218 |
+
min-height: 100%;
|
| 219 |
+
white-space: pre-wrap;
|
| 220 |
+
word-break: break-word;
|
| 221 |
+
overflow: visible;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.multiline {
|
| 225 |
+
white-space: pre;
|
| 226 |
+
overflow: hidden;
|
| 227 |
+
text-overflow: ellipsis;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.header {
|
| 231 |
+
transform: translateX(0);
|
| 232 |
+
font-weight: var(--weight-bold);
|
| 233 |
+
white-space: nowrap;
|
| 234 |
+
overflow: hidden;
|
| 235 |
+
text-overflow: ellipsis;
|
| 236 |
+
margin-left: var(--size-1);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.edit {
|
| 240 |
+
opacity: 0;
|
| 241 |
+
pointer-events: none;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
span :global(img) {
|
| 245 |
+
max-height: 100px;
|
| 246 |
+
width: auto;
|
| 247 |
+
object-fit: contain;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
textarea:read-only {
|
| 251 |
+
cursor: not-allowed;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.wrap,
|
| 255 |
+
.wrap.expanded {
|
| 256 |
+
white-space: normal;
|
| 257 |
+
word-wrap: break-word;
|
| 258 |
+
overflow-wrap: break-word;
|
| 259 |
+
word-wrap: break-word;
|
| 260 |
+
}
|
| 261 |
+
</style>
|
5.49.1/dataframe/shared/EmptyRowButton.svelte
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let on_click: () => void;
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<button class="add-row-button" on:click={on_click} aria-label="Add row">
|
| 6 |
+
+
|
| 7 |
+
</button>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
.add-row-button {
|
| 11 |
+
width: 100%;
|
| 12 |
+
padding: var(--size-1);
|
| 13 |
+
background: transparent;
|
| 14 |
+
border: 1px dashed var(--border-color-primary);
|
| 15 |
+
border-radius: var(--radius-sm);
|
| 16 |
+
color: var(--body-text-color);
|
| 17 |
+
cursor: pointer;
|
| 18 |
+
transition: all 150ms;
|
| 19 |
+
margin-top: var(--size-2);
|
| 20 |
+
z-index: 10;
|
| 21 |
+
position: relative;
|
| 22 |
+
pointer-events: auto;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.add-row-button:hover {
|
| 26 |
+
background: var(--background-fill-secondary);
|
| 27 |
+
border-style: solid;
|
| 28 |
+
}
|
| 29 |
+
</style>
|
5.49.1/dataframe/shared/Example.svelte
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let value: (string | number)[][];
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<table class="input-dataframe-example">
|
| 6 |
+
{#each value.slice(0, 3) as row}
|
| 7 |
+
<tr>
|
| 8 |
+
{#each row.slice(0, 3) as cell}
|
| 9 |
+
<td class="p-2">{cell}</td>
|
| 10 |
+
{/each}
|
| 11 |
+
{#if row.length > 3}
|
| 12 |
+
<td class="p-2">...</td>
|
| 13 |
+
{/if}
|
| 14 |
+
</tr>
|
| 15 |
+
{/each}
|
| 16 |
+
{#if value.length > 3}
|
| 17 |
+
<tr>
|
| 18 |
+
{#each Array(Math.min(4, value[0].length)) as _}
|
| 19 |
+
<td class="p-2">...</td>
|
| 20 |
+
{/each}
|
| 21 |
+
</tr>
|
| 22 |
+
{/if}
|
| 23 |
+
</table>
|
| 24 |
+
|
| 25 |
+
<style>
|
| 26 |
+
table {
|
| 27 |
+
border-collapse: separate;
|
| 28 |
+
}
|
| 29 |
+
</style>
|
5.49.1/dataframe/shared/FilterMenu.svelte
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount } from "svelte";
|
| 3 |
+
import { Check, DropdownArrow } from "@gradio/icons";
|
| 4 |
+
import type { FilterDatatype } from "./context/dataframe_context";
|
| 5 |
+
|
| 6 |
+
export let on_filter: (
|
| 7 |
+
datatype: FilterDatatype,
|
| 8 |
+
selected_filter: string,
|
| 9 |
+
value: string
|
| 10 |
+
) => void = () => {};
|
| 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: [
|
| 20 |
+
"Contains",
|
| 21 |
+
"Does not contain",
|
| 22 |
+
"Starts with",
|
| 23 |
+
"Ends with",
|
| 24 |
+
"Is",
|
| 25 |
+
"Is not",
|
| 26 |
+
"Is empty",
|
| 27 |
+
"Is not empty"
|
| 28 |
+
],
|
| 29 |
+
number: ["=", "≠", ">", "<", "≥", "≤", "Is empty", "Is not empty"]
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
onMount(() => {
|
| 33 |
+
position_menu();
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
function position_menu(): void {
|
| 37 |
+
if (!menu_element) return;
|
| 38 |
+
|
| 39 |
+
const viewport_width = window.innerWidth;
|
| 40 |
+
const viewport_height = window.innerHeight;
|
| 41 |
+
const menu_rect = menu_element.getBoundingClientRect();
|
| 42 |
+
|
| 43 |
+
const x = (viewport_width - menu_rect.width) / 2;
|
| 44 |
+
const y = (viewport_height - menu_rect.height) / 2;
|
| 45 |
+
|
| 46 |
+
menu_element.style.left = `${x}px`;
|
| 47 |
+
menu_element.style.top = `${y}px`;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function handle_filter_input(e: Event): void {
|
| 51 |
+
const target = e.target as HTMLInputElement;
|
| 52 |
+
filter_input_value = target.value;
|
| 53 |
+
}
|
| 54 |
+
</script>
|
| 55 |
+
|
| 56 |
+
<div>
|
| 57 |
+
<div class="background"></div>
|
| 58 |
+
<div bind:this={menu_element} class="filter-menu">
|
| 59 |
+
<div class="filter-datatype-container">
|
| 60 |
+
<span>Filter as</span>
|
| 61 |
+
<button
|
| 62 |
+
on:click|stopPropagation={() => {
|
| 63 |
+
datatype = datatype === "string" ? "number" : "string";
|
| 64 |
+
current_filter = filter_options[datatype][0];
|
| 65 |
+
}}
|
| 66 |
+
aria-label={`Change filter type. Filtering ${datatype}s`}
|
| 67 |
+
>
|
| 68 |
+
{datatype}
|
| 69 |
+
</button>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<div class="input-container">
|
| 73 |
+
<div class="filter-dropdown">
|
| 74 |
+
<button
|
| 75 |
+
on:click|stopPropagation={() =>
|
| 76 |
+
(filter_dropdown_open = !filter_dropdown_open)}
|
| 77 |
+
aria-label={`Change filter. Using '${current_filter}'`}
|
| 78 |
+
>
|
| 79 |
+
{current_filter}
|
| 80 |
+
<DropdownArrow />
|
| 81 |
+
</button>
|
| 82 |
+
|
| 83 |
+
{#if filter_dropdown_open}
|
| 84 |
+
<div class="dropdown-filter-options">
|
| 85 |
+
{#each filter_options[datatype] as opt}
|
| 86 |
+
<button
|
| 87 |
+
on:click|stopPropagation={() => {
|
| 88 |
+
current_filter = opt;
|
| 89 |
+
filter_dropdown_open = !filter_dropdown_open;
|
| 90 |
+
}}
|
| 91 |
+
class="filter-option"
|
| 92 |
+
>
|
| 93 |
+
{opt}
|
| 94 |
+
</button>
|
| 95 |
+
{/each}
|
| 96 |
+
</div>
|
| 97 |
+
{/if}
|
| 98 |
+
</div>
|
| 99 |
+
|
| 100 |
+
<input
|
| 101 |
+
type="text"
|
| 102 |
+
value={filter_input_value}
|
| 103 |
+
on:click|stopPropagation
|
| 104 |
+
on:input={handle_filter_input}
|
| 105 |
+
placeholder="Type a value"
|
| 106 |
+
class="filter-input"
|
| 107 |
+
/>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<button
|
| 111 |
+
class="check-button"
|
| 112 |
+
on:click={() => on_filter(datatype, current_filter, filter_input_value)}
|
| 113 |
+
>
|
| 114 |
+
<Check />
|
| 115 |
+
</button>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
+
|
| 119 |
+
<style>
|
| 120 |
+
.background {
|
| 121 |
+
position: fixed;
|
| 122 |
+
top: 0;
|
| 123 |
+
left: 0;
|
| 124 |
+
width: 100vw;
|
| 125 |
+
height: 100vh;
|
| 126 |
+
background-color: rgba(0, 0, 0, 0.4);
|
| 127 |
+
z-index: 20;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.filter-menu {
|
| 131 |
+
position: fixed;
|
| 132 |
+
background: var(--background-fill-primary);
|
| 133 |
+
border: 1px solid var(--border-color-primary);
|
| 134 |
+
border-radius: var(--radius-sm);
|
| 135 |
+
padding: var(--size-2);
|
| 136 |
+
display: flex;
|
| 137 |
+
flex-direction: column;
|
| 138 |
+
gap: var(--size-2);
|
| 139 |
+
box-shadow: var(--shadow-drop-lg);
|
| 140 |
+
width: 300px;
|
| 141 |
+
z-index: 21;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.filter-datatype-container {
|
| 145 |
+
display: flex;
|
| 146 |
+
gap: var(--size-2);
|
| 147 |
+
align-items: center;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.filter-menu span {
|
| 151 |
+
font-size: var(--text-sm);
|
| 152 |
+
color: var(--body-text-color);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.filter-menu button {
|
| 156 |
+
height: var(--size-6);
|
| 157 |
+
background: none;
|
| 158 |
+
border: 1px solid var(--border-color-primary);
|
| 159 |
+
border-radius: var(--radius-sm);
|
| 160 |
+
padding: var(--size-1) var(--size-2);
|
| 161 |
+
color: var(--body-text-color);
|
| 162 |
+
font-size: var(--text-sm);
|
| 163 |
+
cursor: pointer;
|
| 164 |
+
display: flex;
|
| 165 |
+
align-items: center;
|
| 166 |
+
justify-content: center;
|
| 167 |
+
gap: var(--size-2);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.filter-menu button:hover {
|
| 171 |
+
background-color: var(--background-fill-secondary);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.filter-input {
|
| 175 |
+
width: var(--size-full);
|
| 176 |
+
height: var(--size-6);
|
| 177 |
+
padding: var(--size-2);
|
| 178 |
+
padding-right: var(--size-8);
|
| 179 |
+
border: 1px solid var(--border-color-primary);
|
| 180 |
+
border-radius: var(--table-radius);
|
| 181 |
+
font-size: var(--text-sm);
|
| 182 |
+
color: var(--body-text-color);
|
| 183 |
+
background: var(--background-fill-secondary);
|
| 184 |
+
transition: all 0.2s ease;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.filter-input:hover {
|
| 188 |
+
border-color: var(--border-color-secondary);
|
| 189 |
+
background: var(--background-fill-primary);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.filter-input:focus {
|
| 193 |
+
outline: none;
|
| 194 |
+
border-color: var(--color-accent);
|
| 195 |
+
background: var(--background-fill-primary);
|
| 196 |
+
box-shadow: 0 0 0 1px var(--color-accent);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.dropdown-filter-options {
|
| 200 |
+
display: flex;
|
| 201 |
+
flex-direction: column;
|
| 202 |
+
background: var(--background-fill-primary);
|
| 203 |
+
border: 1px solid var(--border-color-primary);
|
| 204 |
+
border-radius: var(--radius-sm);
|
| 205 |
+
box-shadow: var(--shadow-drop-md);
|
| 206 |
+
position: absolute;
|
| 207 |
+
z-index: var(--layer-1);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.dropdown-filter-options .filter-option {
|
| 211 |
+
border: none;
|
| 212 |
+
justify-content: flex-start;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.input-container {
|
| 216 |
+
display: flex;
|
| 217 |
+
gap: var(--size-2);
|
| 218 |
+
align-items: center;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.input-container button {
|
| 222 |
+
width: 130px;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
:global(svg.dropdown-arrow) {
|
| 226 |
+
width: var(--size-4);
|
| 227 |
+
height: var(--size-4);
|
| 228 |
+
margin-left: auto;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.filter-menu .check-button {
|
| 232 |
+
background: var(--color-accent);
|
| 233 |
+
color: white;
|
| 234 |
+
border: none;
|
| 235 |
+
width: var(--size-full);
|
| 236 |
+
height: var(--size-6);
|
| 237 |
+
border-radius: var(--radius-sm);
|
| 238 |
+
display: flex;
|
| 239 |
+
align-items: center;
|
| 240 |
+
justify-content: center;
|
| 241 |
+
padding: var(--size-1);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
.check-button:hover {
|
| 245 |
+
background: var(--color-accent-soft);
|
| 246 |
+
}
|
| 247 |
+
</style>
|
5.49.1/dataframe/shared/RowNumber.svelte
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let index: number | null = null;
|
| 3 |
+
export let is_header = false;
|
| 4 |
+
</script>
|
| 5 |
+
|
| 6 |
+
{#if is_header}
|
| 7 |
+
<th tabindex="-1" class="row-number">
|
| 8 |
+
<div class="cell-wrap">
|
| 9 |
+
<div class="header-content">
|
| 10 |
+
<div class="header-text"></div>
|
| 11 |
+
</div>
|
| 12 |
+
</div>
|
| 13 |
+
</th>
|
| 14 |
+
{:else}
|
| 15 |
+
<td class="row-number" tabindex="-1" data-row={index} data-col="row-number">
|
| 16 |
+
{index !== null ? index + 1 : ""}
|
| 17 |
+
</td>
|
| 18 |
+
{/if}
|
| 19 |
+
|
| 20 |
+
<style>
|
| 21 |
+
.row-number {
|
| 22 |
+
text-align: center;
|
| 23 |
+
padding: var(--size-1);
|
| 24 |
+
min-width: var(--size-12);
|
| 25 |
+
width: var(--size-12);
|
| 26 |
+
overflow: hidden;
|
| 27 |
+
text-overflow: ellipsis;
|
| 28 |
+
white-space: nowrap;
|
| 29 |
+
font-weight: var(--weight-semibold);
|
| 30 |
+
border-right: 1px solid var(--border-color-primary);
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 { afterUpdate, createEventDispatcher, tick, onMount } from "svelte";
|
| 11 |
+
import { dequal } from "dequal/lite";
|
| 12 |
+
import { Upload } from "@gradio/upload";
|
| 13 |
+
|
| 14 |
+
import EditableCell from "./EditableCell.svelte";
|
| 15 |
+
import RowNumber from "./RowNumber.svelte";
|
| 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 VirtualTable from "./VirtualTable.svelte";
|
| 23 |
+
import type {
|
| 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 { CellCoordinate, CellValue } from "./types";
|
| 32 |
+
import {
|
| 33 |
+
is_cell_selected,
|
| 34 |
+
should_show_cell_menu,
|
| 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 |
+
copy_table_data,
|
| 41 |
+
get_max,
|
| 42 |
+
handle_file_upload
|
| 43 |
+
} from "./utils/table_utils";
|
| 44 |
+
import { make_headers, process_data } from "./utils/data_processing";
|
| 45 |
+
import { handle_keydown, handle_cell_blur } from "./utils/keyboard_utils";
|
| 46 |
+
import {
|
| 47 |
+
create_drag_handlers,
|
| 48 |
+
type DragState,
|
| 49 |
+
type DragHandlers
|
| 50 |
+
} from "./utils/drag_utils";
|
| 51 |
+
import { sort_data_and_preserve_selection } from "./utils/sort_utils";
|
| 52 |
+
import { filter_data_and_preserve_selection } from "./utils/filter_utils";
|
| 53 |
+
|
| 54 |
+
export let datatype: Datatype | Datatype[];
|
| 55 |
+
export let label: string | null = null;
|
| 56 |
+
export let show_label = true;
|
| 57 |
+
export let headers: Headers = [];
|
| 58 |
+
export let values: CellValue[][] = [];
|
| 59 |
+
export let col_count: [number, "fixed" | "dynamic"];
|
| 60 |
+
export let row_count: [number, "fixed" | "dynamic"];
|
| 61 |
+
export let latex_delimiters: {
|
| 62 |
+
left: string;
|
| 63 |
+
right: string;
|
| 64 |
+
display: boolean;
|
| 65 |
+
}[];
|
| 66 |
+
export let components: Record<string, any> = {};
|
| 67 |
+
|
| 68 |
+
export let editable = true;
|
| 69 |
+
export let wrap = false;
|
| 70 |
+
export let root: string;
|
| 71 |
+
export let i18n: I18nFormatter;
|
| 72 |
+
|
| 73 |
+
export let max_height = 500;
|
| 74 |
+
export let line_breaks = true;
|
| 75 |
+
export let column_widths: string[] = [];
|
| 76 |
+
export let show_row_numbers = false;
|
| 77 |
+
export let upload: Client["upload"];
|
| 78 |
+
export let stream_handler: Client["stream"];
|
| 79 |
+
export let show_fullscreen_button = false;
|
| 80 |
+
export let show_copy_button = false;
|
| 81 |
+
export let value_is_output = false;
|
| 82 |
+
export let max_chars: number | undefined = undefined;
|
| 83 |
+
export let show_search: "none" | "search" | "filter" = "none";
|
| 84 |
+
export let pinned_columns = 0;
|
| 85 |
+
export let static_columns: (string | number)[] = [];
|
| 86 |
+
export let fullscreen = false;
|
| 87 |
+
|
| 88 |
+
const df_ctx = create_dataframe_context({
|
| 89 |
+
show_fullscreen_button,
|
| 90 |
+
show_copy_button,
|
| 91 |
+
show_search,
|
| 92 |
+
show_row_numbers,
|
| 93 |
+
editable,
|
| 94 |
+
pinned_columns,
|
| 95 |
+
show_label,
|
| 96 |
+
line_breaks,
|
| 97 |
+
wrap,
|
| 98 |
+
max_height,
|
| 99 |
+
column_widths,
|
| 100 |
+
max_chars,
|
| 101 |
+
static_columns
|
| 102 |
+
});
|
| 103 |
+
|
| 104 |
+
const { state: df_state, actions: df_actions } = df_ctx;
|
| 105 |
+
|
| 106 |
+
$: selected_cells = $df_state.ui_state.selected_cells;
|
| 107 |
+
$: selected = $df_state.ui_state.selected;
|
| 108 |
+
$: editing = $df_state.ui_state.editing;
|
| 109 |
+
$: header_edit = $df_state.ui_state.header_edit;
|
| 110 |
+
$: selected_header = $df_state.ui_state.selected_header;
|
| 111 |
+
$: active_cell_menu = $df_state.ui_state.active_cell_menu;
|
| 112 |
+
$: active_header_menu = $df_state.ui_state.active_header_menu;
|
| 113 |
+
$: copy_flash = $df_state.ui_state.copy_flash;
|
| 114 |
+
|
| 115 |
+
$: actual_pinned_columns =
|
| 116 |
+
pinned_columns && data?.[0]?.length
|
| 117 |
+
? Math.min(pinned_columns, data[0].length)
|
| 118 |
+
: 0;
|
| 119 |
+
|
| 120 |
+
onMount(() => {
|
| 121 |
+
df_ctx.parent_element = parent;
|
| 122 |
+
df_ctx.get_data_at = get_data_at;
|
| 123 |
+
df_ctx.get_column = get_column;
|
| 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 |
+
observer.observe(parent);
|
| 137 |
+
document.addEventListener("click", handle_click_outside);
|
| 138 |
+
window.addEventListener("resize", handle_resize);
|
| 139 |
+
|
| 140 |
+
const global_mouse_up = (event: MouseEvent): void => {
|
| 141 |
+
if (is_dragging || drag_start) {
|
| 142 |
+
handle_mouse_up(event);
|
| 143 |
+
}
|
| 144 |
+
};
|
| 145 |
+
document.addEventListener("mouseup", global_mouse_up);
|
| 146 |
+
|
| 147 |
+
return () => {
|
| 148 |
+
observer.disconnect();
|
| 149 |
+
document.removeEventListener("click", handle_click_outside);
|
| 150 |
+
window.removeEventListener("resize", handle_resize);
|
| 151 |
+
document.removeEventListener("mouseup", global_mouse_up);
|
| 152 |
+
};
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
$: {
|
| 156 |
+
if (data || _headers || els) {
|
| 157 |
+
df_ctx.data = data;
|
| 158 |
+
df_ctx.headers = _headers;
|
| 159 |
+
df_ctx.els = els;
|
| 160 |
+
df_ctx.display_value = display_value;
|
| 161 |
+
df_ctx.styling = styling;
|
| 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 |
+
const get_data_at = (row: number, col: number): CellValue =>
|
| 204 |
+
data?.[row]?.[col]?.value;
|
| 205 |
+
|
| 206 |
+
const get_column = (col: number): CellValue[] =>
|
| 207 |
+
data?.map((row) => row[col]?.value) ?? [];
|
| 208 |
+
|
| 209 |
+
const get_row = (row: number): CellValue[] =>
|
| 210 |
+
data?.[row]?.map((cell) => cell.value) ?? [];
|
| 211 |
+
|
| 212 |
+
$: {
|
| 213 |
+
if (!dequal(headers, old_headers)) {
|
| 214 |
+
_headers = make_headers(headers, col_count, els, make_id);
|
| 215 |
+
old_headers = JSON.parse(JSON.stringify(headers));
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function make_id(): string {
|
| 220 |
+
return Math.random().toString(36).substring(2, 15);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
export let display_value: string[][] | null = null;
|
| 224 |
+
export let styling: string[][] | null = null;
|
| 225 |
+
|
| 226 |
+
$: if (!dequal(values, old_val)) {
|
| 227 |
+
if (parent) {
|
| 228 |
+
// only clear column widths when the data structure changes
|
| 229 |
+
const is_reset =
|
| 230 |
+
values.length === 0 || (values.length === 1 && values[0].length === 0);
|
| 231 |
+
const is_different_structure =
|
| 232 |
+
old_val !== undefined &&
|
| 233 |
+
(values.length !== old_val.length ||
|
| 234 |
+
(values[0] && old_val[0] && values[0].length !== old_val[0].length));
|
| 235 |
+
|
| 236 |
+
if (is_reset || is_different_structure) {
|
| 237 |
+
for (let i = 0; i < 50; i++) {
|
| 238 |
+
parent.style.removeProperty(`--cell-width-${i}`);
|
| 239 |
+
}
|
| 240 |
+
last_width_data_length = 0;
|
| 241 |
+
last_width_column_count = 0;
|
| 242 |
+
width_calculated = false;
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
// only reset sort state when values are changed
|
| 247 |
+
const is_reset =
|
| 248 |
+
values.length === 0 || (values.length === 1 && values[0].length === 0);
|
| 249 |
+
const is_different_structure =
|
| 250 |
+
old_val !== undefined &&
|
| 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 |
+
if (is_reset || is_different_structure) {
|
| 265 |
+
df_actions.reset_sort_state();
|
| 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 |
+
if ($df_state.filter_state.filter_columns.length > 0) {
|
| 274 |
+
filter_data(data, display_value, styling);
|
| 275 |
+
} else {
|
| 276 |
+
df_actions.reset_filter_state();
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
if ($df_state.current_search_query) {
|
| 280 |
+
df_actions.handle_search(null);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
if (parent && cells.length > 0 && (is_reset || is_different_structure)) {
|
| 284 |
+
width_calculated = false;
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
$: if ($df_state.current_search_query !== undefined) {
|
| 289 |
+
const cell_map = new Map();
|
| 290 |
+
filtered_to_original_map = [];
|
| 291 |
+
|
| 292 |
+
data.forEach((row, row_idx) => {
|
| 293 |
+
if (
|
| 294 |
+
row.some((cell) =>
|
| 295 |
+
String(cell?.value)
|
| 296 |
+
.toLowerCase()
|
| 297 |
+
.includes($df_state.current_search_query?.toLowerCase() || "")
|
| 298 |
+
)
|
| 299 |
+
) {
|
| 300 |
+
filtered_to_original_map.push(row_idx);
|
| 301 |
+
}
|
| 302 |
+
row.forEach((cell, col_idx) => {
|
| 303 |
+
cell_map.set(cell.id, {
|
| 304 |
+
value: cell.value,
|
| 305 |
+
display_value:
|
| 306 |
+
cell.display_value !== undefined
|
| 307 |
+
? cell.display_value
|
| 308 |
+
: String(cell.value),
|
| 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 handle_sort(col: number, direction: SortDirection): void {
|
| 352 |
+
df_actions.handle_sort(col, direction);
|
| 353 |
+
sort_data(data, display_value, styling);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function clear_sort(): void {
|
| 357 |
+
df_actions.reset_sort_state();
|
| 358 |
+
sort_data(data, display_value, styling);
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
$: {
|
| 362 |
+
if ($df_state.filter_state.filter_columns.length > 0) {
|
| 363 |
+
filter_data(data, display_value, styling);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
if ($df_state.sort_state.sort_columns.length > 0) {
|
| 367 |
+
sort_data(data, display_value, styling);
|
| 368 |
+
df_actions.update_row_order(data);
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function handle_filter(
|
| 373 |
+
col: number,
|
| 374 |
+
datatype: FilterDatatype,
|
| 375 |
+
filter: string,
|
| 376 |
+
value: string
|
| 377 |
+
): void {
|
| 378 |
+
df_actions.handle_filter(col, datatype, filter, value);
|
| 379 |
+
filter_data(data, display_value, styling);
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
function clear_filter(): void {
|
| 383 |
+
df_actions.reset_filter_state();
|
| 384 |
+
filter_data(data, display_value, styling);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
async function edit_header(i: number, _select = false): Promise<void> {
|
| 388 |
+
if (!editable || header_edit === i || col_count[1] !== "dynamic") return;
|
| 389 |
+
df_actions.set_header_edit(i);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
function handle_header_click(event: MouseEvent, col: number): void {
|
| 393 |
+
if (event.target instanceof HTMLAnchorElement) {
|
| 394 |
+
return;
|
| 395 |
+
}
|
| 396 |
+
event.preventDefault();
|
| 397 |
+
event.stopPropagation();
|
| 398 |
+
if (!editable) return;
|
| 399 |
+
df_actions.set_editing(false);
|
| 400 |
+
df_actions.handle_header_click(col, editable);
|
| 401 |
+
parent.focus();
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
function end_header_edit(event: CustomEvent<KeyboardEvent>): void {
|
| 405 |
+
if (!editable) return;
|
| 406 |
+
df_actions.end_header_edit(event.detail.key);
|
| 407 |
+
parent.focus();
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
async function add_row(index?: number): Promise<void> {
|
| 411 |
+
parent.focus();
|
| 412 |
+
|
| 413 |
+
if (row_count[1] !== "dynamic") return;
|
| 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 |
+
selected = [index !== undefined ? index : data.length - 1, 0];
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
async function add_col(index?: number): Promise<void> {
|
| 435 |
+
parent.focus();
|
| 436 |
+
if (col_count[1] !== "dynamic") return;
|
| 437 |
+
|
| 438 |
+
const result = df_actions.add_col(data, headers, make_id, index);
|
| 439 |
+
|
| 440 |
+
result.data.forEach((row) => {
|
| 441 |
+
row.forEach((cell) => {
|
| 442 |
+
if (!els[cell.id]) {
|
| 443 |
+
els[cell.id] = { cell: null, input: null };
|
| 444 |
+
}
|
| 445 |
+
});
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
data = result.data;
|
| 449 |
+
headers = result.headers;
|
| 450 |
+
|
| 451 |
+
await tick();
|
| 452 |
+
|
| 453 |
+
requestAnimationFrame(() => {
|
| 454 |
+
edit_header(index !== undefined ? index : data[0].length - 1, true);
|
| 455 |
+
const new_w = parent.querySelectorAll("tbody")[1].offsetWidth;
|
| 456 |
+
parent.querySelectorAll("table")[1].scrollTo({ left: new_w });
|
| 457 |
+
});
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
function handle_click_outside(event: Event): void {
|
| 461 |
+
if (handle_click_outside_util(event, parent)) {
|
| 462 |
+
df_actions.clear_ui_state();
|
| 463 |
+
header_edit = false;
|
| 464 |
+
selected_header = false;
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
$: max = get_max(data);
|
| 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 |
+
if (!parent) {
|
| 501 |
+
return;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
last_width_data_length = data.length;
|
| 505 |
+
last_width_column_count = column_count;
|
| 506 |
+
|
| 507 |
+
const widths = cells.map((el) => el?.clientWidth || 0);
|
| 508 |
+
if (widths.length === 0) return;
|
| 509 |
+
|
| 510 |
+
if (show_row_numbers) {
|
| 511 |
+
parent.style.setProperty(`--cell-width-row-number`, `${widths[0]}px`);
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
for (let i = 0; i < 50; i++) {
|
| 515 |
+
if (!column_widths[i]) {
|
| 516 |
+
parent.style.removeProperty(`--cell-width-${i}`);
|
| 517 |
+
} else if (column_widths[i].endsWith("%")) {
|
| 518 |
+
const percentage = parseFloat(column_widths[i]);
|
| 519 |
+
const pixel_width = Math.floor((percentage / 100) * parent.clientWidth);
|
| 520 |
+
parent.style.setProperty(`--cell-width-${i}`, `${pixel_width}px`);
|
| 521 |
+
} else {
|
| 522 |
+
parent.style.setProperty(`--cell-width-${i}`, column_widths[i]);
|
| 523 |
+
}
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
widths.forEach((width, i) => {
|
| 527 |
+
if (!column_widths[i]) {
|
| 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 (copy_flash && !dequal(selected_cells, previous_selected_cells)) {
|
| 595 |
+
set_copy_flash(false);
|
| 596 |
+
}
|
| 597 |
+
previous_selected_cells = selected_cells;
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
function handle_blur(
|
| 601 |
+
event: CustomEvent<{
|
| 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 toggle_header_menu(event: MouseEvent, col: number): void {
|
| 611 |
+
event.stopPropagation();
|
| 612 |
+
if (active_header_menu && active_header_menu.col === col) {
|
| 613 |
+
df_actions.set_active_header_menu(null);
|
| 614 |
+
} else {
|
| 615 |
+
const header = (event.target as HTMLElement).closest("th");
|
| 616 |
+
if (header) {
|
| 617 |
+
const rect = header.getBoundingClientRect();
|
| 618 |
+
df_actions.set_active_header_menu({
|
| 619 |
+
col,
|
| 620 |
+
x: rect.right,
|
| 621 |
+
y: rect.bottom
|
| 622 |
+
});
|
| 623 |
+
}
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
afterUpdate(() => {
|
| 628 |
+
value_is_output = false;
|
| 629 |
+
});
|
| 630 |
+
|
| 631 |
+
function delete_col_at(index: number): void {
|
| 632 |
+
if (col_count[1] !== "dynamic") return;
|
| 633 |
+
if (data[0].length <= 1) return;
|
| 634 |
+
|
| 635 |
+
const result = df_actions.delete_col_at(data, headers, index);
|
| 636 |
+
data = result.data;
|
| 637 |
+
headers = result.headers;
|
| 638 |
+
_headers = make_headers(headers, col_count, els, make_id);
|
| 639 |
+
df_actions.set_active_cell_menu(null);
|
| 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 |
+
export function reset_sort_state(): void {
|
| 752 |
+
df_actions.reset_sort_state();
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
function handle_select_all(col: number, checked: boolean): void {
|
| 756 |
+
data = data.map((row) => {
|
| 757 |
+
const new_row = [...row];
|
| 758 |
+
if (new_row[col]) {
|
| 759 |
+
new_row[col] = {
|
| 760 |
+
...new_row[col],
|
| 761 |
+
value: checked.toString()
|
| 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 |
+
is_dragging = drag_state.is_dragging;
|
| 780 |
+
drag_start = drag_state.drag_start;
|
| 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 |
+
$: if (parent) init_drag_handlers();
|
| 799 |
+
|
| 800 |
+
$: handle_mouse_down = drag_handlers?.handle_mouse_down || (() => {});
|
| 801 |
+
$: handle_mouse_move = drag_handlers?.handle_mouse_move || (() => {});
|
| 802 |
+
$: handle_mouse_up = drag_handlers?.handle_mouse_up || (() => {});
|
| 803 |
+
|
| 804 |
+
function get_cell_display_value(row: number, col: number): string {
|
| 805 |
+
const is_search_active = $df_state.current_search_query !== undefined;
|
| 806 |
+
|
| 807 |
+
if (is_search_active && search_results?.[row]?.[col]) {
|
| 808 |
+
return search_results[row][col].display_value !== undefined
|
| 809 |
+
? search_results[row][col].display_value
|
| 810 |
+
: String(search_results[row][col].value);
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
if (data?.[row]?.[col]) {
|
| 814 |
+
return data[row][col].display_value !== undefined
|
| 815 |
+
? data[row][col].display_value
|
| 816 |
+
: String(data[row][col].value);
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
return "";
|
| 820 |
+
}
|
| 821 |
+
</script>
|
| 822 |
+
|
| 823 |
+
<svelte:window on:resize={() => set_cell_widths()} />
|
| 824 |
+
|
| 825 |
+
<div class="table-container">
|
| 826 |
+
{#if (label && label.length !== 0 && show_label) || show_fullscreen_button || show_copy_button || 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}
|
| 835 |
+
{fullscreen}
|
| 836 |
+
on_copy={async () => await copy_table_data(data, null)}
|
| 837 |
+
{show_copy_button}
|
| 838 |
+
{show_search}
|
| 839 |
+
on:search={(e) => df_actions.handle_search(e.detail)}
|
| 840 |
+
on:fullscreen
|
| 841 |
+
on_commit_filter={commit_filter}
|
| 842 |
+
current_search_query={$df_state.current_search_query}
|
| 843 |
+
/>
|
| 844 |
+
</div>
|
| 845 |
+
{/if}
|
| 846 |
+
<div
|
| 847 |
+
bind:this={parent}
|
| 848 |
+
class="table-wrap"
|
| 849 |
+
class:dragging={is_dragging}
|
| 850 |
+
class:no-wrap={!wrap}
|
| 851 |
+
class:menu-open={active_cell_menu || active_header_menu}
|
| 852 |
+
on:keydown={(e) => handle_keydown(e, df_ctx)}
|
| 853 |
+
on:mousemove={handle_mouse_move}
|
| 854 |
+
on:mouseup={handle_mouse_up}
|
| 855 |
+
on:mouseleave={handle_mouse_up}
|
| 856 |
+
role="grid"
|
| 857 |
+
tabindex="0"
|
| 858 |
+
>
|
| 859 |
+
<table bind:this={table} aria-hidden="true">
|
| 860 |
+
{#if label && label.length !== 0}
|
| 861 |
+
<caption class="sr-only">{label}</caption>
|
| 862 |
+
{/if}
|
| 863 |
+
<thead>
|
| 864 |
+
<tr>
|
| 865 |
+
{#if show_row_numbers}
|
| 866 |
+
<RowNumber is_header={true} />
|
| 867 |
+
{/if}
|
| 868 |
+
{#each _headers as { value, id }, i (id)}
|
| 869 |
+
<TableHeader
|
| 870 |
+
bind:value={_headers[i].value}
|
| 871 |
+
{i}
|
| 872 |
+
{actual_pinned_columns}
|
| 873 |
+
{header_edit}
|
| 874 |
+
{selected_header}
|
| 875 |
+
{headers}
|
| 876 |
+
{get_cell_width}
|
| 877 |
+
{handle_header_click}
|
| 878 |
+
{toggle_header_menu}
|
| 879 |
+
{end_header_edit}
|
| 880 |
+
sort_columns={$df_state.sort_state.sort_columns}
|
| 881 |
+
filter_columns={$df_state.filter_state.filter_columns}
|
| 882 |
+
{latex_delimiters}
|
| 883 |
+
{line_breaks}
|
| 884 |
+
{max_chars}
|
| 885 |
+
{editable}
|
| 886 |
+
is_static={static_columns.includes(i)}
|
| 887 |
+
{i18n}
|
| 888 |
+
bind:el={els[id].input}
|
| 889 |
+
{col_count}
|
| 890 |
+
datatype={Array.isArray(datatype) ? datatype[i] : datatype}
|
| 891 |
+
{data}
|
| 892 |
+
on_select_all={handle_select_all}
|
| 893 |
+
/>
|
| 894 |
+
{/each}
|
| 895 |
+
</tr>
|
| 896 |
+
</thead>
|
| 897 |
+
<tbody>
|
| 898 |
+
<tr>
|
| 899 |
+
{#if show_row_numbers}
|
| 900 |
+
<RowNumber index={0} />
|
| 901 |
+
{/if}
|
| 902 |
+
{#each max as { value, id }, j (id)}
|
| 903 |
+
<td tabindex="-1" bind:this={cells[j]}>
|
| 904 |
+
<div class="cell-wrap">
|
| 905 |
+
<EditableCell
|
| 906 |
+
{value}
|
| 907 |
+
{latex_delimiters}
|
| 908 |
+
{line_breaks}
|
| 909 |
+
datatype={Array.isArray(datatype) ? datatype[j] : datatype}
|
| 910 |
+
edit={false}
|
| 911 |
+
el={null}
|
| 912 |
+
{editable}
|
| 913 |
+
{i18n}
|
| 914 |
+
show_selection_buttons={selected_cells.length === 1 &&
|
| 915 |
+
selected_cells[0][0] === 0 &&
|
| 916 |
+
selected_cells[0][1] === j}
|
| 917 |
+
coords={selected_cell_coords}
|
| 918 |
+
on_select_column={df_actions.handle_select_column}
|
| 919 |
+
on_select_row={df_actions.handle_select_row}
|
| 920 |
+
{is_dragging}
|
| 921 |
+
on:blur={handle_blur}
|
| 922 |
+
/>
|
| 923 |
+
</div>
|
| 924 |
+
</td>
|
| 925 |
+
{/each}
|
| 926 |
+
</tr>
|
| 927 |
+
</tbody>
|
| 928 |
+
</table>
|
| 929 |
+
<Upload
|
| 930 |
+
{upload}
|
| 931 |
+
{stream_handler}
|
| 932 |
+
flex={false}
|
| 933 |
+
center={false}
|
| 934 |
+
boundedheight={false}
|
| 935 |
+
disable_click={true}
|
| 936 |
+
{root}
|
| 937 |
+
on:load={({ detail }) =>
|
| 938 |
+
handle_file_upload(
|
| 939 |
+
detail.data,
|
| 940 |
+
(head) => {
|
| 941 |
+
_headers = make_headers(
|
| 942 |
+
head.map((h) => h ?? ""),
|
| 943 |
+
col_count,
|
| 944 |
+
els,
|
| 945 |
+
make_id
|
| 946 |
+
);
|
| 947 |
+
return _headers;
|
| 948 |
+
},
|
| 949 |
+
(vals) => {
|
| 950 |
+
values = vals;
|
| 951 |
+
}
|
| 952 |
+
)}
|
| 953 |
+
bind:dragging
|
| 954 |
+
aria_label={i18n("dataframe.drop_to_upload")}
|
| 955 |
+
>
|
| 956 |
+
<div class="table-wrap">
|
| 957 |
+
<VirtualTable
|
| 958 |
+
bind:items={search_results}
|
| 959 |
+
{max_height}
|
| 960 |
+
bind:actual_height={table_height}
|
| 961 |
+
bind:table_scrollbar_width={scrollbar_width}
|
| 962 |
+
selected={selected_index}
|
| 963 |
+
disable_scroll={active_cell_menu !== null ||
|
| 964 |
+
active_header_menu !== null}
|
| 965 |
+
bind:viewport
|
| 966 |
+
bind:show_scroll_button
|
| 967 |
+
{label}
|
| 968 |
+
on:scroll_top={(_) => {}}
|
| 969 |
+
>
|
| 970 |
+
<tr slot="thead">
|
| 971 |
+
{#if show_row_numbers}
|
| 972 |
+
<RowNumber is_header={true} />
|
| 973 |
+
{/if}
|
| 974 |
+
{#each _headers as { value, id }, i (id)}
|
| 975 |
+
<TableHeader
|
| 976 |
+
bind:value={_headers[i].value}
|
| 977 |
+
{i}
|
| 978 |
+
{actual_pinned_columns}
|
| 979 |
+
{header_edit}
|
| 980 |
+
{selected_header}
|
| 981 |
+
{headers}
|
| 982 |
+
{get_cell_width}
|
| 983 |
+
{handle_header_click}
|
| 984 |
+
{toggle_header_menu}
|
| 985 |
+
{end_header_edit}
|
| 986 |
+
sort_columns={$df_state.sort_state.sort_columns}
|
| 987 |
+
filter_columns={$df_state.filter_state.filter_columns}
|
| 988 |
+
{latex_delimiters}
|
| 989 |
+
{line_breaks}
|
| 990 |
+
{max_chars}
|
| 991 |
+
{editable}
|
| 992 |
+
is_static={static_columns.includes(i)}
|
| 993 |
+
{i18n}
|
| 994 |
+
bind:el={els[id].input}
|
| 995 |
+
{col_count}
|
| 996 |
+
datatype={Array.isArray(datatype) ? datatype[i] : datatype}
|
| 997 |
+
{data}
|
| 998 |
+
on_select_all={handle_select_all}
|
| 999 |
+
/>
|
| 1000 |
+
{/each}
|
| 1001 |
+
</tr>
|
| 1002 |
+
<tr slot="tbody" let:item let:index class:row-odd={index % 2 === 0}>
|
| 1003 |
+
{#if show_row_numbers}
|
| 1004 |
+
<RowNumber {index} />
|
| 1005 |
+
{/if}
|
| 1006 |
+
{#each item as { value, id }, j (id)}
|
| 1007 |
+
<TableCell
|
| 1008 |
+
bind:value={search_results[index][j].value}
|
| 1009 |
+
display_value={get_cell_display_value(index, j)}
|
| 1010 |
+
index={$df_state.current_search_query !== undefined &&
|
| 1011 |
+
filtered_to_original_map[index] !== undefined
|
| 1012 |
+
? filtered_to_original_map[index]
|
| 1013 |
+
: index}
|
| 1014 |
+
{j}
|
| 1015 |
+
{actual_pinned_columns}
|
| 1016 |
+
{get_cell_width}
|
| 1017 |
+
handle_cell_click={(e, r, c) => handle_mouse_down(e, r, c)}
|
| 1018 |
+
{handle_blur}
|
| 1019 |
+
toggle_cell_menu={df_actions.toggle_cell_menu}
|
| 1020 |
+
{is_cell_selected}
|
| 1021 |
+
{should_show_cell_menu}
|
| 1022 |
+
{selected_cells}
|
| 1023 |
+
{copy_flash}
|
| 1024 |
+
{active_cell_menu}
|
| 1025 |
+
styling={search_results[index][j].styling}
|
| 1026 |
+
{latex_delimiters}
|
| 1027 |
+
{line_breaks}
|
| 1028 |
+
datatype={Array.isArray(datatype) ? datatype[j] : datatype}
|
| 1029 |
+
{editing}
|
| 1030 |
+
{max_chars}
|
| 1031 |
+
{editable}
|
| 1032 |
+
is_static={static_columns.includes(j)}
|
| 1033 |
+
{i18n}
|
| 1034 |
+
{components}
|
| 1035 |
+
handle_select_column={df_actions.handle_select_column}
|
| 1036 |
+
handle_select_row={df_actions.handle_select_row}
|
| 1037 |
+
bind:el={els[id]}
|
| 1038 |
+
{is_dragging}
|
| 1039 |
+
{wrap}
|
| 1040 |
+
/>
|
| 1041 |
+
{/each}
|
| 1042 |
+
</tr>
|
| 1043 |
+
</VirtualTable>
|
| 1044 |
+
</div>
|
| 1045 |
+
</Upload>
|
| 1046 |
+
{#if show_scroll_button}
|
| 1047 |
+
<button class="scroll-top-button" on:click={scroll_to_top}>
|
| 1048 |
+
↑
|
| 1049 |
+
</button>
|
| 1050 |
+
{/if}
|
| 1051 |
+
</div>
|
| 1052 |
+
</div>
|
| 1053 |
+
{#if data.length === 0 && editable && row_count[1] === "dynamic"}
|
| 1054 |
+
<EmptyRowButton on_click={() => add_row()} />
|
| 1055 |
+
{/if}
|
| 1056 |
+
|
| 1057 |
+
{#if active_cell_menu || active_header_menu}
|
| 1058 |
+
<CellMenu
|
| 1059 |
+
x={active_cell_menu?.x ?? active_header_menu?.x ?? 0}
|
| 1060 |
+
y={active_cell_menu?.y ?? active_header_menu?.y ?? 0}
|
| 1061 |
+
row={active_header_menu ? -1 : active_cell_menu?.row ?? 0}
|
| 1062 |
+
{col_count}
|
| 1063 |
+
{row_count}
|
| 1064 |
+
on_add_row_above={() => add_row_at(active_cell_menu?.row ?? -1, "above")}
|
| 1065 |
+
on_add_row_below={() => add_row_at(active_cell_menu?.row ?? -1, "below")}
|
| 1066 |
+
on_add_column_left={() =>
|
| 1067 |
+
add_col_at(
|
| 1068 |
+
active_cell_menu?.col ?? active_header_menu?.col ?? -1,
|
| 1069 |
+
"left"
|
| 1070 |
+
)}
|
| 1071 |
+
on_add_column_right={() =>
|
| 1072 |
+
add_col_at(
|
| 1073 |
+
active_cell_menu?.col ?? active_header_menu?.col ?? -1,
|
| 1074 |
+
"right"
|
| 1075 |
+
)}
|
| 1076 |
+
on_delete_row={() => delete_row_at(active_cell_menu?.row ?? -1)}
|
| 1077 |
+
on_delete_col={() =>
|
| 1078 |
+
delete_col_at(active_cell_menu?.col ?? active_header_menu?.col ?? -1)}
|
| 1079 |
+
{editable}
|
| 1080 |
+
can_delete_rows={!active_header_menu && data.length > 1 && editable}
|
| 1081 |
+
can_delete_cols={data.length > 0 && data[0]?.length > 1 && editable}
|
| 1082 |
+
{i18n}
|
| 1083 |
+
on_sort={active_header_menu
|
| 1084 |
+
? (direction) => {
|
| 1085 |
+
if (active_header_menu) {
|
| 1086 |
+
handle_sort(active_header_menu.col, direction);
|
| 1087 |
+
df_actions.set_active_header_menu(null);
|
| 1088 |
+
}
|
| 1089 |
+
}
|
| 1090 |
+
: undefined}
|
| 1091 |
+
on_clear_sort={active_header_menu
|
| 1092 |
+
? () => {
|
| 1093 |
+
clear_sort();
|
| 1094 |
+
df_actions.set_active_header_menu(null);
|
| 1095 |
+
}
|
| 1096 |
+
: undefined}
|
| 1097 |
+
sort_direction={active_header_menu
|
| 1098 |
+
? $df_state.sort_state.sort_columns.find(
|
| 1099 |
+
(item) => item.col === (active_header_menu?.col ?? -1)
|
| 1100 |
+
)?.direction ?? null
|
| 1101 |
+
: null}
|
| 1102 |
+
sort_priority={active_header_menu
|
| 1103 |
+
? $df_state.sort_state.sort_columns.findIndex(
|
| 1104 |
+
(item) => item.col === (active_header_menu?.col ?? -1)
|
| 1105 |
+
) + 1 || null
|
| 1106 |
+
: null}
|
| 1107 |
+
on_filter={active_header_menu
|
| 1108 |
+
? (datatype, filter, value) => {
|
| 1109 |
+
if (active_header_menu) {
|
| 1110 |
+
handle_filter(active_header_menu.col, datatype, filter, value);
|
| 1111 |
+
df_actions.set_active_header_menu(null);
|
| 1112 |
+
}
|
| 1113 |
+
}
|
| 1114 |
+
: undefined}
|
| 1115 |
+
on_clear_filter={active_header_menu
|
| 1116 |
+
? () => {
|
| 1117 |
+
clear_filter();
|
| 1118 |
+
df_actions.set_active_header_menu(null);
|
| 1119 |
+
}
|
| 1120 |
+
: undefined}
|
| 1121 |
+
filter_active={active_header_menu
|
| 1122 |
+
? $df_state.filter_state.filter_columns.some(
|
| 1123 |
+
(c) => c.col === (active_header_menu?.col ?? -1)
|
| 1124 |
+
)
|
| 1125 |
+
: null}
|
| 1126 |
+
/>
|
| 1127 |
+
{/if}
|
| 1128 |
+
|
| 1129 |
+
<style>
|
| 1130 |
+
.table-container {
|
| 1131 |
+
display: flex;
|
| 1132 |
+
flex-direction: column;
|
| 1133 |
+
gap: var(--size-2);
|
| 1134 |
+
position: relative;
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
.table-wrap {
|
| 1138 |
+
position: relative;
|
| 1139 |
+
transition: 150ms;
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
.table-wrap.menu-open {
|
| 1143 |
+
overflow: hidden;
|
| 1144 |
+
}
|
| 1145 |
+
|
| 1146 |
+
.table-wrap:focus-within {
|
| 1147 |
+
outline: none;
|
| 1148 |
+
}
|
| 1149 |
+
|
| 1150 |
+
.table-wrap.dragging {
|
| 1151 |
+
cursor: crosshair !important;
|
| 1152 |
+
user-select: none;
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
.table-wrap.dragging * {
|
| 1156 |
+
cursor: crosshair !important;
|
| 1157 |
+
user-select: none;
|
| 1158 |
+
}
|
| 1159 |
+
|
| 1160 |
+
.table-wrap > :global(button) {
|
| 1161 |
+
border: 1px solid var(--border-color-primary);
|
| 1162 |
+
border-radius: var(--table-radius);
|
| 1163 |
+
overflow: hidden;
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
table {
|
| 1167 |
+
position: absolute;
|
| 1168 |
+
opacity: 0;
|
| 1169 |
+
z-index: -1;
|
| 1170 |
+
transition: 150ms;
|
| 1171 |
+
width: var(--size-full);
|
| 1172 |
+
table-layout: auto;
|
| 1173 |
+
color: var(--body-text-color);
|
| 1174 |
+
font-size: var(--input-text-size);
|
| 1175 |
+
line-height: var(--line-md);
|
| 1176 |
+
font-family: var(--font-mono);
|
| 1177 |
+
border-spacing: 0;
|
| 1178 |
+
border-collapse: separate;
|
| 1179 |
+
}
|
| 1180 |
+
|
| 1181 |
+
thead {
|
| 1182 |
+
position: sticky;
|
| 1183 |
+
top: 0;
|
| 1184 |
+
z-index: 5;
|
| 1185 |
+
box-shadow: var(--shadow-drop);
|
| 1186 |
+
}
|
| 1187 |
+
|
| 1188 |
+
thead :global(th.pinned-column) {
|
| 1189 |
+
position: sticky;
|
| 1190 |
+
z-index: 6;
|
| 1191 |
+
background: var(--table-even-background-fill) !important;
|
| 1192 |
+
}
|
| 1193 |
+
|
| 1194 |
+
.dragging {
|
| 1195 |
+
border-color: var(--color-accent);
|
| 1196 |
+
}
|
| 1197 |
+
|
| 1198 |
+
.no-wrap {
|
| 1199 |
+
white-space: nowrap;
|
| 1200 |
+
}
|
| 1201 |
+
|
| 1202 |
+
div:not(.no-wrap) td {
|
| 1203 |
+
overflow-wrap: anywhere;
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
div.no-wrap td {
|
| 1207 |
+
overflow-x: hidden;
|
| 1208 |
+
}
|
| 1209 |
+
|
| 1210 |
+
tr {
|
| 1211 |
+
background: var(--table-even-background-fill);
|
| 1212 |
+
}
|
| 1213 |
+
|
| 1214 |
+
tr.row-odd {
|
| 1215 |
+
background: var(--table-odd-background-fill);
|
| 1216 |
+
}
|
| 1217 |
+
|
| 1218 |
+
.header-row {
|
| 1219 |
+
display: flex;
|
| 1220 |
+
justify-content: flex-end;
|
| 1221 |
+
align-items: center;
|
| 1222 |
+
gap: var(--size-2);
|
| 1223 |
+
min-height: var(--size-6);
|
| 1224 |
+
flex-wrap: nowrap;
|
| 1225 |
+
width: 100%;
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
.header-row .label {
|
| 1229 |
+
flex: 1 1 auto;
|
| 1230 |
+
margin-right: auto;
|
| 1231 |
+
font-family: var(--font-sans);
|
| 1232 |
+
}
|
| 1233 |
+
|
| 1234 |
+
.header-row .label p {
|
| 1235 |
+
margin: 0;
|
| 1236 |
+
color: var(--block-label-text-color);
|
| 1237 |
+
font-size: var(--block-label-text-size);
|
| 1238 |
+
line-height: var(--line-sm);
|
| 1239 |
+
position: relative;
|
| 1240 |
+
z-index: 4;
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
.scroll-top-button {
|
| 1244 |
+
position: absolute;
|
| 1245 |
+
right: var(--size-4);
|
| 1246 |
+
bottom: var(--size-4);
|
| 1247 |
+
width: var(--size-8);
|
| 1248 |
+
height: var(--size-8);
|
| 1249 |
+
border-radius: var(--table-radius);
|
| 1250 |
+
background: var(--color-accent);
|
| 1251 |
+
color: white;
|
| 1252 |
+
border: none;
|
| 1253 |
+
cursor: pointer;
|
| 1254 |
+
display: flex;
|
| 1255 |
+
align-items: center;
|
| 1256 |
+
justify-content: center;
|
| 1257 |
+
font-size: var(--text-lg);
|
| 1258 |
+
z-index: 9;
|
| 1259 |
+
opacity: 0.5;
|
| 1260 |
+
}
|
| 1261 |
+
|
| 1262 |
+
.scroll-top-button:hover {
|
| 1263 |
+
opacity: 1;
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
tr {
|
| 1267 |
+
border-bottom: 1px solid var(--border-color-primary);
|
| 1268 |
+
text-align: left;
|
| 1269 |
+
}
|
| 1270 |
+
</style>
|
5.49.1/dataframe/shared/TableCell.svelte
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 { Datatype } from "./utils/utils";
|
| 6 |
+
import type { CellValue } from "./types";
|
| 7 |
+
import { is_cell_in_selection } from "./utils/selection_utils";
|
| 8 |
+
|
| 9 |
+
export let value: CellValue;
|
| 10 |
+
export let index: number;
|
| 11 |
+
export let j: number;
|
| 12 |
+
export let actual_pinned_columns: number;
|
| 13 |
+
export let get_cell_width: (index: number) => string;
|
| 14 |
+
export let handle_cell_click: (
|
| 15 |
+
event: MouseEvent,
|
| 16 |
+
row: number,
|
| 17 |
+
col: number
|
| 18 |
+
) => void;
|
| 19 |
+
export let handle_blur: (
|
| 20 |
+
event: CustomEvent<{
|
| 21 |
+
blur_event: FocusEvent;
|
| 22 |
+
coords: [number, number];
|
| 23 |
+
}>
|
| 24 |
+
) => void;
|
| 25 |
+
export let toggle_cell_menu: (
|
| 26 |
+
event: MouseEvent,
|
| 27 |
+
row: number,
|
| 28 |
+
col: number
|
| 29 |
+
) => void;
|
| 30 |
+
export let is_cell_selected: (
|
| 31 |
+
coords: [number, number],
|
| 32 |
+
selected_cells: [number, number][]
|
| 33 |
+
) => string;
|
| 34 |
+
export let should_show_cell_menu: (
|
| 35 |
+
coords: [number, number],
|
| 36 |
+
selected_cells: [number, number][],
|
| 37 |
+
editable: boolean
|
| 38 |
+
) => boolean;
|
| 39 |
+
export let selected_cells: [number, number][];
|
| 40 |
+
export let copy_flash: boolean;
|
| 41 |
+
export let active_cell_menu: {
|
| 42 |
+
row: number;
|
| 43 |
+
col: number;
|
| 44 |
+
x: number;
|
| 45 |
+
y: number;
|
| 46 |
+
} | null;
|
| 47 |
+
export let styling: string | undefined;
|
| 48 |
+
export let latex_delimiters: {
|
| 49 |
+
left: string;
|
| 50 |
+
right: string;
|
| 51 |
+
display: boolean;
|
| 52 |
+
}[];
|
| 53 |
+
export let line_breaks: boolean;
|
| 54 |
+
export let datatype: Datatype;
|
| 55 |
+
export let editing: [number, number] | false;
|
| 56 |
+
export let max_chars: number | undefined;
|
| 57 |
+
export let editable: boolean;
|
| 58 |
+
export let is_static = false;
|
| 59 |
+
export let i18n: I18nFormatter;
|
| 60 |
+
export let components: Record<string, any> = {};
|
| 61 |
+
export let el: {
|
| 62 |
+
cell: HTMLTableCellElement | null;
|
| 63 |
+
input: HTMLTextAreaElement | null;
|
| 64 |
+
};
|
| 65 |
+
export let handle_select_column: (col: number) => void;
|
| 66 |
+
export let handle_select_row: (row: number) => void;
|
| 67 |
+
export let is_dragging: boolean;
|
| 68 |
+
export let display_value: string | undefined;
|
| 69 |
+
export let wrap = false;
|
| 70 |
+
|
| 71 |
+
function get_cell_position(col_index: number): string {
|
| 72 |
+
if (col_index >= actual_pinned_columns) {
|
| 73 |
+
return "auto";
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (col_index === 0) {
|
| 77 |
+
return "0";
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
const previous_widths = Array(col_index)
|
| 81 |
+
.fill(0)
|
| 82 |
+
.map((_, idx) => {
|
| 83 |
+
return get_cell_width(idx);
|
| 84 |
+
})
|
| 85 |
+
.join(" + ");
|
| 86 |
+
|
| 87 |
+
return `calc(${previous_widths})`;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
$: cell_classes = is_cell_selected([index, j], selected_cells || []);
|
| 91 |
+
$: is_in_selection = is_cell_in_selection([index, j], selected_cells);
|
| 92 |
+
$: has_no_top = cell_classes.includes("no-top");
|
| 93 |
+
$: has_no_bottom = cell_classes.includes("no-bottom");
|
| 94 |
+
$: has_no_left = cell_classes.includes("no-left");
|
| 95 |
+
$: has_no_right = cell_classes.includes("no-right");
|
| 96 |
+
</script>
|
| 97 |
+
|
| 98 |
+
<td
|
| 99 |
+
class:pinned-column={j < actual_pinned_columns}
|
| 100 |
+
class:last-pinned={j === actual_pinned_columns - 1}
|
| 101 |
+
tabindex={j < actual_pinned_columns ? -1 : 0}
|
| 102 |
+
bind:this={el.cell}
|
| 103 |
+
data-row={index}
|
| 104 |
+
data-col={j}
|
| 105 |
+
data-testid={`cell-${index}-${j}`}
|
| 106 |
+
on:mousedown={(e) => handle_cell_click(e, index, j)}
|
| 107 |
+
on:contextmenu|preventDefault={(e) => toggle_cell_menu(e, index, j)}
|
| 108 |
+
style="width: {get_cell_width(j)}; left: {get_cell_position(j)}; {styling ||
|
| 109 |
+
''}"
|
| 110 |
+
class:flash={copy_flash && is_in_selection}
|
| 111 |
+
class:cell-selected={is_in_selection}
|
| 112 |
+
class:no-top={has_no_top}
|
| 113 |
+
class:no-bottom={has_no_bottom}
|
| 114 |
+
class:no-left={has_no_left}
|
| 115 |
+
class:no-right={has_no_right}
|
| 116 |
+
class:menu-active={active_cell_menu &&
|
| 117 |
+
active_cell_menu.row === index &&
|
| 118 |
+
active_cell_menu.col === j}
|
| 119 |
+
class:dragging={is_dragging}
|
| 120 |
+
>
|
| 121 |
+
<div class="cell-wrap">
|
| 122 |
+
<EditableCell
|
| 123 |
+
bind:value
|
| 124 |
+
bind:el={el.input}
|
| 125 |
+
display_value={display_value !== undefined
|
| 126 |
+
? display_value
|
| 127 |
+
: String(value)}
|
| 128 |
+
{latex_delimiters}
|
| 129 |
+
{line_breaks}
|
| 130 |
+
{editable}
|
| 131 |
+
{is_static}
|
| 132 |
+
edit={editing && editing[0] === index && editing[1] === j}
|
| 133 |
+
{datatype}
|
| 134 |
+
on:focus={() => {
|
| 135 |
+
const row = index;
|
| 136 |
+
const col = j;
|
| 137 |
+
if (!selected_cells.some(([r, c]) => r === row && c === col)) {
|
| 138 |
+
selected_cells = [[row, col]];
|
| 139 |
+
}
|
| 140 |
+
}}
|
| 141 |
+
on:blur={handle_blur}
|
| 142 |
+
{max_chars}
|
| 143 |
+
{i18n}
|
| 144 |
+
{components}
|
| 145 |
+
show_selection_buttons={selected_cells.length === 1 &&
|
| 146 |
+
selected_cells[0][0] === index &&
|
| 147 |
+
selected_cells[0][1] === j}
|
| 148 |
+
coords={[index, j]}
|
| 149 |
+
on_select_column={handle_select_column}
|
| 150 |
+
on_select_row={handle_select_row}
|
| 151 |
+
{is_dragging}
|
| 152 |
+
wrap_text={wrap}
|
| 153 |
+
/>
|
| 154 |
+
{#if editable && should_show_cell_menu([index, j], selected_cells, editable)}
|
| 155 |
+
<CellMenuButton on_click={(event) => toggle_cell_menu(event, index, j)} />
|
| 156 |
+
{/if}
|
| 157 |
+
</div>
|
| 158 |
+
</td>
|
| 159 |
+
|
| 160 |
+
<style>
|
| 161 |
+
td {
|
| 162 |
+
--ring-color: transparent;
|
| 163 |
+
position: relative;
|
| 164 |
+
outline: none;
|
| 165 |
+
box-shadow: inset 0 0 0 1px var(--ring-color);
|
| 166 |
+
padding: 0;
|
| 167 |
+
border-right-width: 0px;
|
| 168 |
+
border-left-width: 1px;
|
| 169 |
+
border-style: solid;
|
| 170 |
+
border-color: var(--border-color-primary);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
.cell-wrap {
|
| 174 |
+
display: flex;
|
| 175 |
+
align-items: center;
|
| 176 |
+
justify-content: flex-start;
|
| 177 |
+
outline: none;
|
| 178 |
+
min-height: var(--size-9);
|
| 179 |
+
position: relative;
|
| 180 |
+
height: 100%;
|
| 181 |
+
padding: var(--size-2);
|
| 182 |
+
box-sizing: border-box;
|
| 183 |
+
margin: 0;
|
| 184 |
+
gap: var(--size-1);
|
| 185 |
+
overflow: visible;
|
| 186 |
+
min-width: 0;
|
| 187 |
+
border-radius: var(--table-radius);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.cell-selected {
|
| 191 |
+
--ring-color: var(--color-accent);
|
| 192 |
+
box-shadow: inset 0 0 0 2px var(--ring-color);
|
| 193 |
+
z-index: 2;
|
| 194 |
+
position: relative;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.cell-selected :global(.cell-menu-button) {
|
| 198 |
+
display: flex;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.flash.cell-selected {
|
| 202 |
+
animation: flash-color 700ms ease-out;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
@keyframes flash-color {
|
| 206 |
+
0%,
|
| 207 |
+
30% {
|
| 208 |
+
background: var(--color-accent-copied);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
100% {
|
| 212 |
+
background: transparent;
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.pinned-column {
|
| 217 |
+
position: sticky;
|
| 218 |
+
z-index: 3;
|
| 219 |
+
border-right: none;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.pinned-column:nth-child(odd) {
|
| 223 |
+
background: var(--table-odd-background-fill);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
.pinned-column:nth-child(even) {
|
| 227 |
+
background: var(--table-even-background-fill);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
td:first-child {
|
| 231 |
+
border-left-width: 0px;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
:global(tr:last-child) td:first-child {
|
| 235 |
+
border-bottom-left-radius: var(--table-radius);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
:global(tr:last-child) td:last-child {
|
| 239 |
+
border-bottom-right-radius: var(--table-radius);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
.dragging {
|
| 243 |
+
cursor: crosshair;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/* Add back the cell selection border styles */
|
| 247 |
+
.cell-selected.no-top {
|
| 248 |
+
box-shadow:
|
| 249 |
+
inset 2px 0 0 var(--ring-color),
|
| 250 |
+
inset -2px 0 0 var(--ring-color),
|
| 251 |
+
inset 0 -2px 0 var(--ring-color);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.cell-selected.no-bottom {
|
| 255 |
+
box-shadow:
|
| 256 |
+
inset 2px 0 0 var(--ring-color),
|
| 257 |
+
inset -2px 0 0 var(--ring-color),
|
| 258 |
+
inset 0 2px 0 var(--ring-color);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
.cell-selected.no-left {
|
| 262 |
+
box-shadow:
|
| 263 |
+
inset 0 2px 0 var(--ring-color),
|
| 264 |
+
inset -2px 0 0 var(--ring-color),
|
| 265 |
+
inset 0 -2px 0 var(--ring-color);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
.cell-selected.no-right {
|
| 269 |
+
box-shadow:
|
| 270 |
+
inset 0 2px 0 var(--ring-color),
|
| 271 |
+
inset 2px 0 0 var(--ring-color),
|
| 272 |
+
inset 0 -2px 0 var(--ring-color);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.cell-selected.no-top.no-left {
|
| 276 |
+
box-shadow:
|
| 277 |
+
inset -2px 0 0 var(--ring-color),
|
| 278 |
+
inset 0 -2px 0 var(--ring-color);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.cell-selected.no-top.no-right {
|
| 282 |
+
box-shadow:
|
| 283 |
+
inset 2px 0 0 var(--ring-color),
|
| 284 |
+
inset 0 -2px 0 var(--ring-color);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.cell-selected.no-bottom.no-left {
|
| 288 |
+
box-shadow:
|
| 289 |
+
inset -2px 0 0 var(--ring-color),
|
| 290 |
+
inset 0 2px 0 var(--ring-color);
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
.cell-selected.no-bottom.no-right {
|
| 294 |
+
box-shadow:
|
| 295 |
+
inset 2px 0 0 var(--ring-color),
|
| 296 |
+
inset 0 2px 0 var(--ring-color);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
.cell-selected.no-top.no-bottom {
|
| 300 |
+
box-shadow:
|
| 301 |
+
inset 2px 0 0 var(--ring-color),
|
| 302 |
+
inset -2px 0 0 var(--ring-color);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
.cell-selected.no-left.no-right {
|
| 306 |
+
box-shadow:
|
| 307 |
+
inset 0 2px 0 var(--ring-color),
|
| 308 |
+
inset 0 -2px 0 var(--ring-color);
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.cell-selected.no-top.no-left.no-right {
|
| 312 |
+
box-shadow: inset 0 -2px 0 var(--ring-color);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.cell-selected.no-bottom.no-left.no-right {
|
| 316 |
+
box-shadow: inset 0 2px 0 var(--ring-color);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.cell-selected.no-left.no-top.no-bottom {
|
| 320 |
+
box-shadow: inset -2px 0 0 var(--ring-color);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.cell-selected.no-right.no-top.no-bottom {
|
| 324 |
+
box-shadow: inset 2px 0 0 var(--ring-color);
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.cell-selected.no-top.no-bottom.no-left.no-right {
|
| 328 |
+
box-shadow: none;
|
| 329 |
+
}
|
| 330 |
+
</style>
|
5.49.1/dataframe/shared/TableHeader.svelte
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 { get_sort_status } from "./utils/sort_utils";
|
| 6 |
+
import Padlock from "./icons/Padlock.svelte";
|
| 7 |
+
import SortArrowUp from "./icons/SortArrowUp.svelte";
|
| 8 |
+
import SortArrowDown from "./icons/SortArrowDown.svelte";
|
| 9 |
+
import type { SortDirection } from "./context/dataframe_context";
|
| 10 |
+
import CellMenuIcons from "./CellMenuIcons.svelte";
|
| 11 |
+
import type { FilterDatatype } from "./context/dataframe_context";
|
| 12 |
+
import type { Datatype } from "./utils/utils";
|
| 13 |
+
import { BaseCheckbox } from "@gradio/checkbox";
|
| 14 |
+
export let value: string;
|
| 15 |
+
export let i: number;
|
| 16 |
+
export let datatype: Datatype = "str";
|
| 17 |
+
export let actual_pinned_columns: number;
|
| 18 |
+
export let header_edit: number | false;
|
| 19 |
+
export let selected_header: number | false;
|
| 20 |
+
export let headers: string[];
|
| 21 |
+
export let get_cell_width: (index: number) => string;
|
| 22 |
+
export let handle_header_click: (event: MouseEvent, col: number) => void;
|
| 23 |
+
export let toggle_header_menu: (event: MouseEvent, col: number) => void;
|
| 24 |
+
export let end_header_edit: (event: CustomEvent<KeyboardEvent>) => void;
|
| 25 |
+
export let sort_columns: { col: number; direction: SortDirection }[] = [];
|
| 26 |
+
export let filter_columns: {
|
| 27 |
+
col: number;
|
| 28 |
+
datatype: FilterDatatype;
|
| 29 |
+
filter: string;
|
| 30 |
+
value: string;
|
| 31 |
+
}[] = [];
|
| 32 |
+
|
| 33 |
+
export let latex_delimiters: {
|
| 34 |
+
left: string;
|
| 35 |
+
right: string;
|
| 36 |
+
display: boolean;
|
| 37 |
+
}[];
|
| 38 |
+
export let line_breaks: boolean;
|
| 39 |
+
export let max_chars: number | undefined;
|
| 40 |
+
export let editable: boolean;
|
| 41 |
+
export let i18n: I18nFormatter;
|
| 42 |
+
export let el: HTMLTextAreaElement | null;
|
| 43 |
+
export let is_static: boolean;
|
| 44 |
+
export let col_count: [number, "fixed" | "dynamic"];
|
| 45 |
+
export let data: any[] = [];
|
| 46 |
+
export let on_select_all:
|
| 47 |
+
| ((col: number, checked: boolean) => void)
|
| 48 |
+
| undefined = undefined;
|
| 49 |
+
|
| 50 |
+
$: can_add_columns = col_count && col_count[1] === "dynamic";
|
| 51 |
+
$: is_bool_column = datatype === "bool";
|
| 52 |
+
|
| 53 |
+
$: select_all_state = (() => {
|
| 54 |
+
if (!is_bool_column || data.length === 0) return "unchecked";
|
| 55 |
+
const true_count = data.filter(
|
| 56 |
+
(row) => row[i]?.value === true || row[i]?.value === "true"
|
| 57 |
+
).length;
|
| 58 |
+
if (true_count === 0) return "unchecked";
|
| 59 |
+
if (true_count === data.length) return "checked";
|
| 60 |
+
return "indeterminate";
|
| 61 |
+
})();
|
| 62 |
+
|
| 63 |
+
$: sort_index = sort_columns.findIndex((item) => item.col === i);
|
| 64 |
+
$: filter_index = filter_columns.findIndex((item) => item.col === i);
|
| 65 |
+
$: sort_priority = sort_index !== -1 ? sort_index + 1 : null;
|
| 66 |
+
$: current_direction =
|
| 67 |
+
sort_index !== -1 ? sort_columns[sort_index].direction : null;
|
| 68 |
+
|
| 69 |
+
function get_header_position(col_index: number): string {
|
| 70 |
+
if (col_index >= actual_pinned_columns) {
|
| 71 |
+
return "auto";
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (col_index === 0) {
|
| 75 |
+
return "0";
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
const previous_widths = Array(col_index)
|
| 79 |
+
.fill(0)
|
| 80 |
+
.map((_, idx) => {
|
| 81 |
+
return get_cell_width(idx);
|
| 82 |
+
})
|
| 83 |
+
.join(" + ");
|
| 84 |
+
|
| 85 |
+
return `calc(${previous_widths})`;
|
| 86 |
+
}
|
| 87 |
+
</script>
|
| 88 |
+
|
| 89 |
+
<th
|
| 90 |
+
class:pinned-column={i < actual_pinned_columns}
|
| 91 |
+
class:last-pinned={i === actual_pinned_columns - 1}
|
| 92 |
+
class:focus={header_edit === i || selected_header === i}
|
| 93 |
+
class:sorted={sort_index !== -1}
|
| 94 |
+
class:filtered={filter_index !== -1}
|
| 95 |
+
aria-sort={get_sort_status(value, sort_columns, headers) === "none"
|
| 96 |
+
? "none"
|
| 97 |
+
: get_sort_status(value, sort_columns, headers) === "asc"
|
| 98 |
+
? "ascending"
|
| 99 |
+
: "descending"}
|
| 100 |
+
style="width: {get_cell_width(i)}; left: {get_header_position(i)};"
|
| 101 |
+
on:click={(event) => handle_header_click(event, i)}
|
| 102 |
+
on:mousedown={(event) => {
|
| 103 |
+
event.preventDefault();
|
| 104 |
+
event.stopPropagation();
|
| 105 |
+
}}
|
| 106 |
+
title={value}
|
| 107 |
+
>
|
| 108 |
+
<div class="cell-wrap">
|
| 109 |
+
<div class="header-content">
|
| 110 |
+
{#if is_bool_column && editable && on_select_all}
|
| 111 |
+
<div
|
| 112 |
+
class="select-all-checkbox"
|
| 113 |
+
role="button"
|
| 114 |
+
tabindex="0"
|
| 115 |
+
on:click|stopPropagation
|
| 116 |
+
on:keydown|stopPropagation={(e) => {
|
| 117 |
+
if (e.key === "Enter" || e.key === " ") {
|
| 118 |
+
e.preventDefault();
|
| 119 |
+
}
|
| 120 |
+
}}
|
| 121 |
+
on:mousedown|stopPropagation
|
| 122 |
+
>
|
| 123 |
+
<BaseCheckbox
|
| 124 |
+
value={select_all_state === "checked"}
|
| 125 |
+
indeterminate={select_all_state === "indeterminate"}
|
| 126 |
+
label=""
|
| 127 |
+
interactive={true}
|
| 128 |
+
on:select={() => {
|
| 129 |
+
if (on_select_all) {
|
| 130 |
+
const new_value = select_all_state !== "checked";
|
| 131 |
+
on_select_all(i, new_value);
|
| 132 |
+
}
|
| 133 |
+
}}
|
| 134 |
+
/>
|
| 135 |
+
</div>
|
| 136 |
+
{/if}
|
| 137 |
+
<button
|
| 138 |
+
class="header-button"
|
| 139 |
+
on:click={(event) => handle_header_click(event, i)}
|
| 140 |
+
on:mousedown={(event) => {
|
| 141 |
+
event.preventDefault();
|
| 142 |
+
event.stopPropagation();
|
| 143 |
+
}}
|
| 144 |
+
title={value}
|
| 145 |
+
>
|
| 146 |
+
<EditableCell
|
| 147 |
+
{max_chars}
|
| 148 |
+
bind:value
|
| 149 |
+
bind:el
|
| 150 |
+
{latex_delimiters}
|
| 151 |
+
{line_breaks}
|
| 152 |
+
edit={header_edit === i}
|
| 153 |
+
on:keydown={(event) => {
|
| 154 |
+
if (
|
| 155 |
+
event.detail.key === "Enter" ||
|
| 156 |
+
event.detail.key === "Escape" ||
|
| 157 |
+
event.detail.key === "Tab"
|
| 158 |
+
) {
|
| 159 |
+
end_header_edit(event);
|
| 160 |
+
}
|
| 161 |
+
}}
|
| 162 |
+
header
|
| 163 |
+
{editable}
|
| 164 |
+
{is_static}
|
| 165 |
+
{i18n}
|
| 166 |
+
coords={[i, 0]}
|
| 167 |
+
/>
|
| 168 |
+
{#if sort_index !== -1}
|
| 169 |
+
<div class="sort-indicators">
|
| 170 |
+
<span class="sort-arrow">
|
| 171 |
+
{#if current_direction === "asc"}
|
| 172 |
+
<SortArrowUp size={12} />
|
| 173 |
+
{:else}
|
| 174 |
+
<SortArrowDown size={12} />
|
| 175 |
+
{/if}
|
| 176 |
+
</span>
|
| 177 |
+
{#if sort_columns.length > 1}
|
| 178 |
+
<span class="sort-priority">
|
| 179 |
+
{sort_priority}
|
| 180 |
+
</span>
|
| 181 |
+
{/if}
|
| 182 |
+
</div>
|
| 183 |
+
{/if}
|
| 184 |
+
{#if filter_index !== -1}
|
| 185 |
+
<div class="filter-indicators">
|
| 186 |
+
<span class="filter-icon">
|
| 187 |
+
<CellMenuIcons icon="filter" />
|
| 188 |
+
</span>
|
| 189 |
+
</div>
|
| 190 |
+
{/if}
|
| 191 |
+
</button>
|
| 192 |
+
{#if is_static}
|
| 193 |
+
<Padlock />
|
| 194 |
+
{/if}
|
| 195 |
+
</div>
|
| 196 |
+
{#if can_add_columns}
|
| 197 |
+
<CellMenuButton on_click={(event) => toggle_header_menu(event, i)} />
|
| 198 |
+
{/if}
|
| 199 |
+
</div>
|
| 200 |
+
</th>
|
| 201 |
+
|
| 202 |
+
<style>
|
| 203 |
+
th {
|
| 204 |
+
--ring-color: transparent;
|
| 205 |
+
position: relative;
|
| 206 |
+
outline: none;
|
| 207 |
+
box-shadow: inset 0 0 0 1px var(--ring-color);
|
| 208 |
+
padding: 0;
|
| 209 |
+
background: var(--table-even-background-fill);
|
| 210 |
+
border-right-width: 0px;
|
| 211 |
+
border-left-width: 1px;
|
| 212 |
+
border-style: solid;
|
| 213 |
+
border-color: var(--border-color-primary);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
th:first-child {
|
| 217 |
+
border-top-left-radius: var(--table-radius);
|
| 218 |
+
border-bottom-left-radius: var(--table-radius);
|
| 219 |
+
border-left-width: 0px;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
th:last-child {
|
| 223 |
+
border-top-right-radius: var(--table-radius);
|
| 224 |
+
border-bottom-right-radius: var(--table-radius);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
th.focus {
|
| 228 |
+
--ring-color: var(--color-accent);
|
| 229 |
+
box-shadow: inset 0 0 0 2px var(--ring-color);
|
| 230 |
+
z-index: 4;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
th.focus :global(.cell-menu-button) {
|
| 234 |
+
display: flex;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
th:hover :global(.cell-menu-button) {
|
| 238 |
+
display: flex;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
.cell-wrap {
|
| 242 |
+
display: flex;
|
| 243 |
+
align-items: center;
|
| 244 |
+
justify-content: flex-start;
|
| 245 |
+
outline: none;
|
| 246 |
+
min-height: var(--size-9);
|
| 247 |
+
position: relative;
|
| 248 |
+
height: 100%;
|
| 249 |
+
padding: var(--size-2);
|
| 250 |
+
box-sizing: border-box;
|
| 251 |
+
margin: 0;
|
| 252 |
+
gap: var(--size-1);
|
| 253 |
+
overflow: visible;
|
| 254 |
+
min-width: 0;
|
| 255 |
+
border-radius: var(--table-radius);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
.header-content {
|
| 259 |
+
display: flex;
|
| 260 |
+
align-items: center;
|
| 261 |
+
overflow: hidden;
|
| 262 |
+
flex-grow: 1;
|
| 263 |
+
min-width: 0;
|
| 264 |
+
white-space: normal;
|
| 265 |
+
overflow-wrap: break-word;
|
| 266 |
+
word-break: normal;
|
| 267 |
+
height: 100%;
|
| 268 |
+
gap: var(--size-1);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.header-button {
|
| 272 |
+
display: flex;
|
| 273 |
+
text-align: left;
|
| 274 |
+
width: 100%;
|
| 275 |
+
overflow: hidden;
|
| 276 |
+
text-overflow: ellipsis;
|
| 277 |
+
display: flex;
|
| 278 |
+
align-items: center;
|
| 279 |
+
position: relative;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
.sort-indicators {
|
| 283 |
+
display: flex;
|
| 284 |
+
align-items: center;
|
| 285 |
+
margin-left: var(--size-1);
|
| 286 |
+
gap: var(--size-1);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
.sort-arrow {
|
| 290 |
+
display: flex;
|
| 291 |
+
align-items: center;
|
| 292 |
+
justify-content: center;
|
| 293 |
+
color: var(--body-text-color);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.sort-priority {
|
| 297 |
+
display: flex;
|
| 298 |
+
align-items: center;
|
| 299 |
+
justify-content: center;
|
| 300 |
+
font-size: var(--size-2);
|
| 301 |
+
background-color: var(--button-secondary-background-fill);
|
| 302 |
+
color: var(--body-text-color);
|
| 303 |
+
border-radius: var(--radius-sm);
|
| 304 |
+
width: var(--size-2-5);
|
| 305 |
+
height: var(--size-2-5);
|
| 306 |
+
padding: var(--size-1-5);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
.filter-indicators {
|
| 310 |
+
display: flex;
|
| 311 |
+
align-items: center;
|
| 312 |
+
margin-left: var(--size-1);
|
| 313 |
+
gap: var(--size-1);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
.filter-icon {
|
| 317 |
+
display: flex;
|
| 318 |
+
align-items: center;
|
| 319 |
+
justify-content: center;
|
| 320 |
+
color: var(--body-text-color);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.pinned-column {
|
| 324 |
+
position: sticky;
|
| 325 |
+
z-index: 5;
|
| 326 |
+
border-right: none;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
.select-all-checkbox {
|
| 330 |
+
display: flex;
|
| 331 |
+
align-items: center;
|
| 332 |
+
justify-content: center;
|
| 333 |
+
margin-right: var(--size-1);
|
| 334 |
+
flex-shrink: 0;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
.select-all-checkbox :global(label) {
|
| 338 |
+
margin: 0;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
.select-all-checkbox :global(span) {
|
| 342 |
+
display: none;
|
| 343 |
+
}
|
| 344 |
+
</style>
|
5.49.1/dataframe/shared/Toolbar.svelte
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
export let show_fullscreen_button = false;
|
| 9 |
+
export let show_copy_button = false;
|
| 10 |
+
export let show_search: "none" | "search" | "filter" = "none";
|
| 11 |
+
export let fullscreen = false;
|
| 12 |
+
export let on_copy: () => Promise<void>;
|
| 13 |
+
export let on_commit_filter: () => void;
|
| 14 |
+
|
| 15 |
+
const dispatch = createEventDispatcher<{
|
| 16 |
+
search: string | null;
|
| 17 |
+
}>();
|
| 18 |
+
|
| 19 |
+
let copied = false;
|
| 20 |
+
let timer: ReturnType<typeof setTimeout>;
|
| 21 |
+
export let current_search_query: string | null = null;
|
| 22 |
+
let input_value = "";
|
| 23 |
+
|
| 24 |
+
function handle_search_input(e: Event): void {
|
| 25 |
+
const target = e.target as HTMLTextAreaElement;
|
| 26 |
+
input_value = target.value;
|
| 27 |
+
const new_query = input_value || null;
|
| 28 |
+
if (current_search_query !== new_query) {
|
| 29 |
+
current_search_query = new_query;
|
| 30 |
+
dispatch("search", current_search_query);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function copy_feedback(): void {
|
| 35 |
+
copied = true;
|
| 36 |
+
if (timer) clearTimeout(timer);
|
| 37 |
+
timer = setTimeout(() => {
|
| 38 |
+
copied = false;
|
| 39 |
+
}, 2000);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
async function handle_copy(): Promise<void> {
|
| 43 |
+
await on_copy();
|
| 44 |
+
copy_feedback();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
onDestroy(() => {
|
| 48 |
+
if (timer) clearTimeout(timer);
|
| 49 |
+
});
|
| 50 |
+
</script>
|
| 51 |
+
|
| 52 |
+
<div class="toolbar" role="toolbar" aria-label="Table actions">
|
| 53 |
+
<div class="toolbar-buttons">
|
| 54 |
+
{#if show_search !== "none"}
|
| 55 |
+
<div class="search-container">
|
| 56 |
+
<input
|
| 57 |
+
type="text"
|
| 58 |
+
value={current_search_query || ""}
|
| 59 |
+
on:input={handle_search_input}
|
| 60 |
+
placeholder={show_search === "filter" ? "Filter..." : "Search..."}
|
| 61 |
+
class="search-input"
|
| 62 |
+
class:filter-mode={show_search === "filter"}
|
| 63 |
+
title={`Enter text to ${show_search} the table`}
|
| 64 |
+
/>
|
| 65 |
+
{#if current_search_query && show_search === "filter"}
|
| 66 |
+
<button
|
| 67 |
+
class="toolbar-button check-button"
|
| 68 |
+
on:click={on_commit_filter}
|
| 69 |
+
aria-label="Apply filter and update dataframe values"
|
| 70 |
+
title="Apply filter and update dataframe values"
|
| 71 |
+
>
|
| 72 |
+
<Check />
|
| 73 |
+
</button>
|
| 74 |
+
{/if}
|
| 75 |
+
</div>
|
| 76 |
+
{/if}
|
| 77 |
+
{#if show_copy_button}
|
| 78 |
+
<IconButton
|
| 79 |
+
Icon={copied ? Check : Copy}
|
| 80 |
+
label={copied ? "Copied to clipboard" : "Copy table data"}
|
| 81 |
+
on:click={handle_copy}
|
| 82 |
+
/>
|
| 83 |
+
{/if}
|
| 84 |
+
{#if show_fullscreen_button}
|
| 85 |
+
<FullscreenButton {fullscreen} on:fullscreen />
|
| 86 |
+
{/if}
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<style>
|
| 91 |
+
.toolbar {
|
| 92 |
+
display: flex;
|
| 93 |
+
align-items: center;
|
| 94 |
+
gap: var(--size-2);
|
| 95 |
+
flex: 0 0 auto;
|
| 96 |
+
font-family: var(--font-sans);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.toolbar-buttons {
|
| 100 |
+
display: flex;
|
| 101 |
+
gap: var(--size-1);
|
| 102 |
+
flex-wrap: nowrap;
|
| 103 |
+
align-items: center;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.toolbar-button {
|
| 107 |
+
display: flex;
|
| 108 |
+
align-items: center;
|
| 109 |
+
justify-content: center;
|
| 110 |
+
width: var(--size-6);
|
| 111 |
+
height: var(--size-6);
|
| 112 |
+
padding: var(--size-1);
|
| 113 |
+
border: none;
|
| 114 |
+
border-radius: var(--radius-sm);
|
| 115 |
+
background: transparent;
|
| 116 |
+
color: var(--body-text-color-subdued);
|
| 117 |
+
cursor: pointer;
|
| 118 |
+
transition: all 0.2s;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.toolbar-button:hover {
|
| 122 |
+
background: var(--background-fill-secondary);
|
| 123 |
+
color: var(--body-text-color);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.toolbar-button :global(svg) {
|
| 127 |
+
width: var(--size-4);
|
| 128 |
+
height: var(--size-4);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.search-container {
|
| 132 |
+
position: relative;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.search-input {
|
| 136 |
+
width: var(--size-full);
|
| 137 |
+
height: var(--size-6);
|
| 138 |
+
padding: var(--size-2);
|
| 139 |
+
padding-right: var(--size-8);
|
| 140 |
+
border: 1px solid var(--border-color-primary);
|
| 141 |
+
border-radius: var(--table-radius);
|
| 142 |
+
font-size: var(--text-sm);
|
| 143 |
+
color: var(--body-text-color);
|
| 144 |
+
background: var(--background-fill-secondary);
|
| 145 |
+
transition: all 0.2s ease;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.search-input:hover {
|
| 149 |
+
border-color: var(--border-color-secondary);
|
| 150 |
+
background: var(--background-fill-primary);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.search-input:focus {
|
| 154 |
+
outline: none;
|
| 155 |
+
border-color: var(--color-accent);
|
| 156 |
+
background: var(--background-fill-primary);
|
| 157 |
+
box-shadow: 0 0 0 1px var(--color-accent);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
.check-button {
|
| 161 |
+
position: absolute;
|
| 162 |
+
right: var(--size-1);
|
| 163 |
+
top: 50%;
|
| 164 |
+
transform: translateY(-50%);
|
| 165 |
+
background: var(--color-accent);
|
| 166 |
+
color: white;
|
| 167 |
+
border: none;
|
| 168 |
+
width: var(--size-4);
|
| 169 |
+
height: var(--size-4);
|
| 170 |
+
border-radius: var(--radius-sm);
|
| 171 |
+
display: flex;
|
| 172 |
+
align-items: center;
|
| 173 |
+
justify-content: center;
|
| 174 |
+
padding: var(--size-1);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.check-button :global(svg) {
|
| 178 |
+
width: var(--size-3);
|
| 179 |
+
height: var(--size-3);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.check-button:hover {
|
| 183 |
+
background: var(--color-accent-soft);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.toolbar-buttons :global(.icon-button) {
|
| 187 |
+
background: transparent !important;
|
| 188 |
+
height: var(--size-6);
|
| 189 |
+
width: var(--size-6);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.toolbar-buttons :global(.icon-button:hover) {
|
| 193 |
+
background: var(--background-fill-secondary) !important;
|
| 194 |
+
color: var(--body-text-color) !important;
|
| 195 |
+
border: 1px solid var(--border-color-primary);
|
| 196 |
+
border-radius: var(--radius-sm) !important;
|
| 197 |
+
}
|
| 198 |
+
</style>
|
5.49.1/dataframe/shared/VirtualTable.svelte
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount, tick, createEventDispatcher } from "svelte";
|
| 3 |
+
|
| 4 |
+
export let items: any[][] = [];
|
| 5 |
+
|
| 6 |
+
export let max_height: number;
|
| 7 |
+
export let actual_height: number;
|
| 8 |
+
export let table_scrollbar_width: number;
|
| 9 |
+
export let start = 0;
|
| 10 |
+
export let end = 20;
|
| 11 |
+
export let selected: number | false;
|
| 12 |
+
export let disable_scroll = false;
|
| 13 |
+
export let show_scroll_button = false;
|
| 14 |
+
export let viewport: HTMLTableElement;
|
| 15 |
+
export let label: string | null = null;
|
| 16 |
+
|
| 17 |
+
const dispatch = createEventDispatcher<{
|
| 18 |
+
scroll_top: number;
|
| 19 |
+
}>();
|
| 20 |
+
|
| 21 |
+
let height = "100%";
|
| 22 |
+
|
| 23 |
+
let average_height = 30;
|
| 24 |
+
let bottom = 0;
|
| 25 |
+
let contents: HTMLTableSectionElement;
|
| 26 |
+
let head_height = 0;
|
| 27 |
+
let foot_height = 0;
|
| 28 |
+
let height_map: number[] = [];
|
| 29 |
+
let mounted: boolean;
|
| 30 |
+
let rows: HTMLCollectionOf<HTMLTableRowElement>;
|
| 31 |
+
let top = 0;
|
| 32 |
+
let viewport_height = 200;
|
| 33 |
+
let visible: { index: number; data: any[] }[] = [];
|
| 34 |
+
let viewport_box: DOMRectReadOnly;
|
| 35 |
+
|
| 36 |
+
$: viewport_height = viewport_box?.height || 200;
|
| 37 |
+
|
| 38 |
+
const is_browser = typeof window !== "undefined";
|
| 39 |
+
const raf = is_browser
|
| 40 |
+
? window.requestAnimationFrame
|
| 41 |
+
: (cb: (...args: any[]) => void) => cb();
|
| 42 |
+
|
| 43 |
+
$: {
|
| 44 |
+
if (mounted && viewport_height && viewport.offsetParent) {
|
| 45 |
+
sortedItems, raf(refresh_height_map);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
async function refresh_height_map(): Promise<void> {
|
| 50 |
+
if (!viewport) {
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (sortedItems.length < start) {
|
| 55 |
+
await scroll_to_index(sortedItems.length - 1, { behavior: "auto" });
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
const scrollTop = Math.max(0, viewport.scrollTop);
|
| 59 |
+
show_scroll_button = scrollTop > 100;
|
| 60 |
+
table_scrollbar_width = viewport.offsetWidth - viewport.clientWidth;
|
| 61 |
+
|
| 62 |
+
// acquire height map for currently visible rows
|
| 63 |
+
for (let v = 0; v < rows.length; v += 1) {
|
| 64 |
+
height_map[start + v] = rows[v].getBoundingClientRect().height;
|
| 65 |
+
}
|
| 66 |
+
let i = 0;
|
| 67 |
+
let y = head_height;
|
| 68 |
+
// loop items to find new start
|
| 69 |
+
while (i < sortedItems.length) {
|
| 70 |
+
const row_height = height_map[i] || average_height;
|
| 71 |
+
// keep a page of rows buffered above
|
| 72 |
+
if (y + row_height > scrollTop - max_height) {
|
| 73 |
+
start = i;
|
| 74 |
+
top = y - head_height;
|
| 75 |
+
break;
|
| 76 |
+
}
|
| 77 |
+
y += row_height;
|
| 78 |
+
i += 1;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
let content_height = head_height;
|
| 82 |
+
while (i < sortedItems.length) {
|
| 83 |
+
const row_height = height_map[i] || average_height;
|
| 84 |
+
content_height += row_height;
|
| 85 |
+
i += 1;
|
| 86 |
+
// keep a page of rows buffered below
|
| 87 |
+
if (content_height - head_height > 3 * max_height) {
|
| 88 |
+
break;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
end = i;
|
| 93 |
+
const remaining = sortedItems.length - end;
|
| 94 |
+
|
| 95 |
+
const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;
|
| 96 |
+
if (scrollbar_height > 0) {
|
| 97 |
+
content_height += scrollbar_height;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
let filtered_height_map = height_map.filter((v) => typeof v === "number");
|
| 101 |
+
average_height =
|
| 102 |
+
filtered_height_map.reduce((a, b) => a + b, 0) /
|
| 103 |
+
filtered_height_map.length || 30;
|
| 104 |
+
|
| 105 |
+
bottom = remaining * average_height;
|
| 106 |
+
if (!isFinite(bottom)) {
|
| 107 |
+
bottom = 200000;
|
| 108 |
+
}
|
| 109 |
+
height_map.length = sortedItems.length;
|
| 110 |
+
while (i < sortedItems.length) {
|
| 111 |
+
i += 1;
|
| 112 |
+
height_map[i] = average_height;
|
| 113 |
+
}
|
| 114 |
+
if (max_height && content_height > max_height) {
|
| 115 |
+
actual_height = max_height;
|
| 116 |
+
} else {
|
| 117 |
+
actual_height = content_height;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
$: scroll_and_render(selected);
|
| 122 |
+
|
| 123 |
+
async function scroll_and_render(n: number | false): Promise<void> {
|
| 124 |
+
raf(async () => {
|
| 125 |
+
if (typeof n !== "number") return;
|
| 126 |
+
const direction = typeof n !== "number" ? false : is_in_view(n);
|
| 127 |
+
if (direction === true) {
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
+
if (direction === "back") {
|
| 131 |
+
await scroll_to_index(n, { behavior: "instant" });
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
if (direction === "forwards") {
|
| 135 |
+
await scroll_to_index(n, { behavior: "instant" }, true);
|
| 136 |
+
}
|
| 137 |
+
});
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function is_in_view(n: number): "back" | "forwards" | true {
|
| 141 |
+
const current = rows && rows[n - start];
|
| 142 |
+
if (!current && n < start) {
|
| 143 |
+
return "back";
|
| 144 |
+
}
|
| 145 |
+
if (!current && n >= end - 1) {
|
| 146 |
+
return "forwards";
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
const { top: viewport_top } = viewport.getBoundingClientRect();
|
| 150 |
+
const { top, bottom } = current.getBoundingClientRect();
|
| 151 |
+
|
| 152 |
+
if (top - viewport_top < 37) {
|
| 153 |
+
return "back";
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
if (bottom - viewport_top > viewport_height) {
|
| 157 |
+
return "forwards";
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
return true;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
export async function scroll_to_index(
|
| 164 |
+
index: number,
|
| 165 |
+
opts: ScrollToOptions,
|
| 166 |
+
align_end = false
|
| 167 |
+
): Promise<void> {
|
| 168 |
+
await tick();
|
| 169 |
+
|
| 170 |
+
const _itemHeight = average_height;
|
| 171 |
+
|
| 172 |
+
let distance = index * _itemHeight;
|
| 173 |
+
if (align_end) {
|
| 174 |
+
distance = distance - viewport_height + _itemHeight + head_height;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;
|
| 178 |
+
if (scrollbar_height > 0) {
|
| 179 |
+
distance += scrollbar_height;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
const _opts = {
|
| 183 |
+
top: distance,
|
| 184 |
+
behavior: "smooth" as ScrollBehavior,
|
| 185 |
+
...opts
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
viewport.scrollTo(_opts);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
$: sortedItems = items;
|
| 192 |
+
|
| 193 |
+
$: visible = is_browser
|
| 194 |
+
? sortedItems.slice(start, end).map((data, i) => {
|
| 195 |
+
return { index: i + start, data };
|
| 196 |
+
})
|
| 197 |
+
: sortedItems
|
| 198 |
+
.slice(0, (max_height / sortedItems.length) * average_height + 1)
|
| 199 |
+
.map((data, i) => {
|
| 200 |
+
return { index: i + start, data };
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
onMount(() => {
|
| 204 |
+
rows = contents.children as HTMLCollectionOf<HTMLTableRowElement>;
|
| 205 |
+
mounted = true;
|
| 206 |
+
});
|
| 207 |
+
</script>
|
| 208 |
+
|
| 209 |
+
<svelte-virtual-table-viewport>
|
| 210 |
+
<div>
|
| 211 |
+
<table
|
| 212 |
+
class="table"
|
| 213 |
+
class:disable-scroll={disable_scroll}
|
| 214 |
+
bind:this={viewport}
|
| 215 |
+
bind:contentRect={viewport_box}
|
| 216 |
+
on:scroll={refresh_height_map}
|
| 217 |
+
style="height: {height}; --bw-svt-p-top: {top}px; --bw-svt-p-bottom: {bottom}px; --bw-svt-head-height: {head_height}px; --bw-svt-foot-height: {foot_height}px; --bw-svt-avg-row-height: {average_height}px; --max-height: {max_height}px"
|
| 218 |
+
>
|
| 219 |
+
{#if label && label.length !== 0}
|
| 220 |
+
<caption class="sr-only">{label}</caption>
|
| 221 |
+
{/if}
|
| 222 |
+
<thead class="thead" bind:offsetHeight={head_height}>
|
| 223 |
+
<slot name="thead" />
|
| 224 |
+
</thead>
|
| 225 |
+
<tbody bind:this={contents} class="tbody">
|
| 226 |
+
{#if visible.length && visible[0].data.length}
|
| 227 |
+
{#each visible as item (item.data[0].id)}
|
| 228 |
+
<slot name="tbody" item={item.data} index={item.index}>
|
| 229 |
+
<tr>
|
| 230 |
+
<td>Missing Table Row</td>
|
| 231 |
+
</tr>
|
| 232 |
+
</slot>
|
| 233 |
+
{/each}
|
| 234 |
+
{/if}
|
| 235 |
+
</tbody>
|
| 236 |
+
<tfoot class="tfoot" bind:offsetHeight={foot_height}>
|
| 237 |
+
<slot name="tfoot" />
|
| 238 |
+
</tfoot>
|
| 239 |
+
</table>
|
| 240 |
+
</div>
|
| 241 |
+
</svelte-virtual-table-viewport>
|
| 242 |
+
|
| 243 |
+
<style type="text/css">
|
| 244 |
+
table {
|
| 245 |
+
position: relative;
|
| 246 |
+
overflow: auto;
|
| 247 |
+
-webkit-overflow-scrolling: touch;
|
| 248 |
+
max-height: var(--max-height);
|
| 249 |
+
box-sizing: border-box;
|
| 250 |
+
display: block;
|
| 251 |
+
padding: 0;
|
| 252 |
+
margin: 0;
|
| 253 |
+
color: var(--body-text-color);
|
| 254 |
+
font-size: var(--input-text-size);
|
| 255 |
+
line-height: var(--line-md);
|
| 256 |
+
font-family: var(--font-mono);
|
| 257 |
+
border-spacing: 0;
|
| 258 |
+
width: 100%;
|
| 259 |
+
scroll-snap-type: x proximity;
|
| 260 |
+
border-collapse: separate;
|
| 261 |
+
scrollbar-width: thin;
|
| 262 |
+
scrollbar-color: rgba(128, 128, 128, 0.5) transparent;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
table::-webkit-scrollbar {
|
| 266 |
+
width: 4px;
|
| 267 |
+
height: 4px;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
table::-webkit-scrollbar-track {
|
| 271 |
+
background: transparent;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
table::-webkit-scrollbar-thumb {
|
| 275 |
+
background-color: rgba(128, 128, 128, 0.5);
|
| 276 |
+
border-radius: 4px;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
table:hover {
|
| 280 |
+
scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
table:hover::-webkit-scrollbar-thumb {
|
| 284 |
+
background-color: rgba(160, 160, 160, 0.7);
|
| 285 |
+
border-radius: 4px;
|
| 286 |
+
width: 4px;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
@media (hover: none) {
|
| 290 |
+
table {
|
| 291 |
+
scrollbar-color: rgba(160, 160, 160, 0.7) transparent;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
table::-webkit-scrollbar-thumb {
|
| 295 |
+
background-color: rgba(160, 160, 160, 0.7);
|
| 296 |
+
border-radius: 4px;
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
@media (pointer: coarse) {
|
| 301 |
+
table::-webkit-scrollbar {
|
| 302 |
+
width: 8px;
|
| 303 |
+
height: 8px;
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
table :is(thead, tfoot, tbody) {
|
| 308 |
+
display: table;
|
| 309 |
+
table-layout: fixed;
|
| 310 |
+
width: 100%;
|
| 311 |
+
box-sizing: border-box;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
tbody {
|
| 315 |
+
overflow-x: scroll;
|
| 316 |
+
overflow-y: hidden;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
table tbody {
|
| 320 |
+
padding-top: var(--bw-svt-p-top);
|
| 321 |
+
padding-bottom: var(--bw-svt-p-bottom);
|
| 322 |
+
}
|
| 323 |
+
tbody {
|
| 324 |
+
position: relative;
|
| 325 |
+
box-sizing: border-box;
|
| 326 |
+
border: 0px solid currentColor;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
tbody > :global(tr:last-child) {
|
| 330 |
+
border: none;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
table :global(td) {
|
| 334 |
+
scroll-snap-align: start;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
tbody :global(td.pinned-column) {
|
| 338 |
+
position: sticky;
|
| 339 |
+
z-index: 3;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
tbody :global(tr:nth-child(odd)) :global(td.pinned-column) {
|
| 343 |
+
background: var(--table-odd-background-fill);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
tbody :global(tr:nth-child(even)) :global(td.pinned-column) {
|
| 347 |
+
background: var(--table-even-background-fill);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
tbody :global(td.last-pinned) {
|
| 351 |
+
border-right: 1px solid var(--border-color-primary);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
thead {
|
| 355 |
+
position: sticky;
|
| 356 |
+
top: 0;
|
| 357 |
+
left: 0;
|
| 358 |
+
background: var(--background-fill-primary);
|
| 359 |
+
z-index: 7;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
thead :global(th) {
|
| 363 |
+
background: var(--table-even-background-fill) !important;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
thead :global(th.pinned-column) {
|
| 367 |
+
position: sticky;
|
| 368 |
+
z-index: 7;
|
| 369 |
+
background: var(--table-even-background-fill) !important;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
thead :global(th.last-pinned) {
|
| 373 |
+
border-right: 1px solid var(--border-color-primary);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
.table.disable-scroll {
|
| 377 |
+
overflow: hidden !important;
|
| 378 |
+
}
|
| 379 |
+
</style>
|
5.49.1/dataframe/shared/context/dataframe_context.ts
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getContext, setContext } from "svelte";
|
| 2 |
+
import { dequal } from "dequal";
|
| 3 |
+
import { writable, get } from "svelte/store";
|
| 4 |
+
import { sort_table_data } from "../utils/table_utils";
|
| 5 |
+
import type { CellValue } from "../types";
|
| 6 |
+
import { tick } from "svelte";
|
| 7 |
+
import {
|
| 8 |
+
handle_selection,
|
| 9 |
+
get_next_cell_coordinates,
|
| 10 |
+
get_range_selection,
|
| 11 |
+
move_cursor
|
| 12 |
+
} from "../utils/selection_utils";
|
| 13 |
+
|
| 14 |
+
export const DATAFRAME_KEY = Symbol("dataframe");
|
| 15 |
+
|
| 16 |
+
export type SortDirection = "asc" | "desc";
|
| 17 |
+
export type FilterDatatype = "string" | "number";
|
| 18 |
+
export type CellCoordinate = [number, number];
|
| 19 |
+
|
| 20 |
+
interface DataFrameState {
|
| 21 |
+
config: {
|
| 22 |
+
show_fullscreen_button: boolean;
|
| 23 |
+
show_copy_button: boolean;
|
| 24 |
+
show_search: "none" | "search" | "filter";
|
| 25 |
+
show_row_numbers: boolean;
|
| 26 |
+
editable: boolean;
|
| 27 |
+
pinned_columns: number;
|
| 28 |
+
show_label: boolean;
|
| 29 |
+
line_breaks: boolean;
|
| 30 |
+
wrap: boolean;
|
| 31 |
+
max_height: number;
|
| 32 |
+
column_widths: string[];
|
| 33 |
+
max_chars?: number;
|
| 34 |
+
static_columns?: CellValue[];
|
| 35 |
+
};
|
| 36 |
+
current_search_query: string | null;
|
| 37 |
+
sort_state: {
|
| 38 |
+
sort_columns: { col: number; direction: SortDirection }[];
|
| 39 |
+
row_order: number[];
|
| 40 |
+
initial_data: {
|
| 41 |
+
data: { id: string; value: CellValue }[][];
|
| 42 |
+
display_value: string[][] | null;
|
| 43 |
+
styling: string[][] | null;
|
| 44 |
+
} | null;
|
| 45 |
+
};
|
| 46 |
+
filter_state: {
|
| 47 |
+
filter_columns: {
|
| 48 |
+
col: number;
|
| 49 |
+
datatype: FilterDatatype;
|
| 50 |
+
filter: string;
|
| 51 |
+
value: string;
|
| 52 |
+
}[];
|
| 53 |
+
initial_data: {
|
| 54 |
+
data: { id: string; value: CellValue }[][];
|
| 55 |
+
display_value: string[][] | null;
|
| 56 |
+
styling: string[][] | null;
|
| 57 |
+
} | null;
|
| 58 |
+
};
|
| 59 |
+
ui_state: {
|
| 60 |
+
active_cell_menu: { row: number; col: number; x: number; y: number } | null;
|
| 61 |
+
active_header_menu: { col: number; x: number; y: number } | null;
|
| 62 |
+
selected_cells: CellCoordinate[];
|
| 63 |
+
selected: CellCoordinate | false;
|
| 64 |
+
editing: CellCoordinate | false;
|
| 65 |
+
header_edit: number | false;
|
| 66 |
+
selected_header: number | false;
|
| 67 |
+
active_button: {
|
| 68 |
+
type: "header" | "cell";
|
| 69 |
+
row?: number;
|
| 70 |
+
col: number;
|
| 71 |
+
} | null;
|
| 72 |
+
copy_flash: boolean;
|
| 73 |
+
};
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
interface DataFrameActions {
|
| 77 |
+
handle_search: (query: string | null) => void;
|
| 78 |
+
handle_sort: (col: number, direction: SortDirection) => void;
|
| 79 |
+
handle_filter: (
|
| 80 |
+
col: number,
|
| 81 |
+
datatype: FilterDatatype,
|
| 82 |
+
filter: string,
|
| 83 |
+
value: string
|
| 84 |
+
) => void;
|
| 85 |
+
get_sort_status: (name: string, headers: string[]) => "none" | "asc" | "desc";
|
| 86 |
+
sort_data: (
|
| 87 |
+
data: any[][],
|
| 88 |
+
display_value: string[][] | null,
|
| 89 |
+
styling: string[][] | null
|
| 90 |
+
) => void;
|
| 91 |
+
update_row_order: (data: any[][]) => void;
|
| 92 |
+
filter_data: (data: any[][]) => any[][];
|
| 93 |
+
add_row: (data: any[][], make_id: () => string, index?: number) => any[][];
|
| 94 |
+
add_col: (
|
| 95 |
+
data: any[][],
|
| 96 |
+
headers: string[],
|
| 97 |
+
make_id: () => string,
|
| 98 |
+
index?: number
|
| 99 |
+
) => { data: any[][]; headers: string[] };
|
| 100 |
+
add_row_at: (
|
| 101 |
+
data: any[][],
|
| 102 |
+
index: number,
|
| 103 |
+
position: "above" | "below",
|
| 104 |
+
make_id: () => string
|
| 105 |
+
) => any[][];
|
| 106 |
+
add_col_at: (
|
| 107 |
+
data: any[][],
|
| 108 |
+
headers: string[],
|
| 109 |
+
index: number,
|
| 110 |
+
position: "left" | "right",
|
| 111 |
+
make_id: () => string
|
| 112 |
+
) => { data: any[][]; headers: string[] };
|
| 113 |
+
delete_row: (data: any[][], index: number) => any[][];
|
| 114 |
+
delete_col: (
|
| 115 |
+
data: any[][],
|
| 116 |
+
headers: string[],
|
| 117 |
+
index: number
|
| 118 |
+
) => { data: any[][]; headers: string[] };
|
| 119 |
+
delete_row_at: (data: any[][], index: number) => any[][];
|
| 120 |
+
delete_col_at: (
|
| 121 |
+
data: any[][],
|
| 122 |
+
headers: string[],
|
| 123 |
+
index: number
|
| 124 |
+
) => { data: any[][]; headers: string[] };
|
| 125 |
+
trigger_change: (
|
| 126 |
+
data: any[][],
|
| 127 |
+
headers: any[],
|
| 128 |
+
previous_data: any[][],
|
| 129 |
+
previous_headers: string[],
|
| 130 |
+
value_is_output: boolean,
|
| 131 |
+
dispatch: (e: "change" | "input" | "edit", detail?: any) => void
|
| 132 |
+
) => Promise<void>;
|
| 133 |
+
reset_sort_state: () => void;
|
| 134 |
+
reset_filter_state: () => void;
|
| 135 |
+
set_active_cell_menu: (
|
| 136 |
+
menu: { row: number; col: number; x: number; y: number } | null
|
| 137 |
+
) => void;
|
| 138 |
+
set_active_header_menu: (
|
| 139 |
+
menu: { col: number; x: number; y: number } | null
|
| 140 |
+
) => void;
|
| 141 |
+
set_selected_cells: (cells: CellCoordinate[]) => void;
|
| 142 |
+
set_selected: (selected: CellCoordinate | false) => void;
|
| 143 |
+
set_editing: (editing: CellCoordinate | false) => void;
|
| 144 |
+
clear_ui_state: () => void;
|
| 145 |
+
set_header_edit: (header_index: number | false) => void;
|
| 146 |
+
set_selected_header: (header_index: number | false) => void;
|
| 147 |
+
handle_header_click: (col: number, editable: boolean) => void;
|
| 148 |
+
end_header_edit: (key: string) => void;
|
| 149 |
+
get_selected_cells: () => CellCoordinate[];
|
| 150 |
+
get_active_cell_menu: () => {
|
| 151 |
+
row: number;
|
| 152 |
+
col: number;
|
| 153 |
+
x: number;
|
| 154 |
+
y: number;
|
| 155 |
+
} | null;
|
| 156 |
+
get_active_button: () => {
|
| 157 |
+
type: "header" | "cell";
|
| 158 |
+
row?: number;
|
| 159 |
+
col: number;
|
| 160 |
+
} | null;
|
| 161 |
+
set_active_button: (
|
| 162 |
+
button: { type: "header" | "cell"; row?: number; col: number } | null
|
| 163 |
+
) => void;
|
| 164 |
+
set_copy_flash: (value: boolean) => void;
|
| 165 |
+
handle_cell_click: (event: MouseEvent, row: number, col: number) => void;
|
| 166 |
+
toggle_cell_menu: (event: MouseEvent, row: number, col: number) => void;
|
| 167 |
+
toggle_cell_button: (row: number, col: number) => void;
|
| 168 |
+
handle_select_column: (col: number) => void;
|
| 169 |
+
handle_select_row: (row: number) => void;
|
| 170 |
+
get_next_cell_coordinates: typeof get_next_cell_coordinates;
|
| 171 |
+
get_range_selection: typeof get_range_selection;
|
| 172 |
+
move_cursor: typeof move_cursor;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
export interface DataFrameContext {
|
| 176 |
+
state: ReturnType<typeof writable<DataFrameState>>;
|
| 177 |
+
actions: DataFrameActions;
|
| 178 |
+
data?: any[][];
|
| 179 |
+
headers?: { id: string; value: string }[];
|
| 180 |
+
display_value?: string[][] | null;
|
| 181 |
+
styling?: string[][] | null;
|
| 182 |
+
els?: Record<
|
| 183 |
+
string,
|
| 184 |
+
{ cell: HTMLTableCellElement | null; input: HTMLTextAreaElement | null }
|
| 185 |
+
>;
|
| 186 |
+
parent_element?: HTMLElement;
|
| 187 |
+
get_data_at?: (row: number, col: number) => CellValue;
|
| 188 |
+
get_column?: (col: number) => CellValue[];
|
| 189 |
+
get_row?: (row: number) => CellValue[];
|
| 190 |
+
dispatch?: (e: "change" | "select" | "search" | "edit", detail?: any) => void;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
function create_actions(
|
| 194 |
+
state: ReturnType<typeof writable<DataFrameState>>,
|
| 195 |
+
context: DataFrameContext
|
| 196 |
+
): DataFrameActions {
|
| 197 |
+
const update_state = (
|
| 198 |
+
updater: (s: DataFrameState) => Partial<DataFrameState>
|
| 199 |
+
): void => state.update((s) => ({ ...s, ...updater(s) }));
|
| 200 |
+
|
| 201 |
+
const add_row = (
|
| 202 |
+
data: any[][],
|
| 203 |
+
make_id: () => string,
|
| 204 |
+
index?: number
|
| 205 |
+
): any[][] => {
|
| 206 |
+
const new_row = data[0]?.length
|
| 207 |
+
? Array(data[0].length)
|
| 208 |
+
.fill(null)
|
| 209 |
+
.map(() => ({ value: "", id: make_id() }))
|
| 210 |
+
: [{ value: "", id: make_id() }];
|
| 211 |
+
const new_data = [...data];
|
| 212 |
+
index !== undefined
|
| 213 |
+
? new_data.splice(index, 0, new_row)
|
| 214 |
+
: new_data.push(new_row);
|
| 215 |
+
return new_data;
|
| 216 |
+
};
|
| 217 |
+
|
| 218 |
+
const add_col = (
|
| 219 |
+
data: any[][],
|
| 220 |
+
headers: string[],
|
| 221 |
+
make_id: () => string,
|
| 222 |
+
index?: number
|
| 223 |
+
): { data: any[][]; headers: string[] } => {
|
| 224 |
+
const new_headers = [...headers, `Header ${headers.length + 1}`];
|
| 225 |
+
const new_data = data.map((row) => [...row, { value: "", id: make_id() }]);
|
| 226 |
+
if (index !== undefined) {
|
| 227 |
+
new_headers.splice(index, 0, new_headers.pop()!);
|
| 228 |
+
new_data.forEach((row) => row.splice(index, 0, row.pop()!));
|
| 229 |
+
}
|
| 230 |
+
return { data: new_data, headers: new_headers };
|
| 231 |
+
};
|
| 232 |
+
|
| 233 |
+
const update_array = (
|
| 234 |
+
source: { id: string; value: CellValue }[][] | string[][] | null,
|
| 235 |
+
target: any[] | null | undefined
|
| 236 |
+
): void => {
|
| 237 |
+
if (source && target) {
|
| 238 |
+
target.splice(0, target.length, ...JSON.parse(JSON.stringify(source)));
|
| 239 |
+
}
|
| 240 |
+
};
|
| 241 |
+
|
| 242 |
+
return {
|
| 243 |
+
handle_search: (query) =>
|
| 244 |
+
update_state((s) => ({ current_search_query: query })),
|
| 245 |
+
handle_sort: (col, direction) =>
|
| 246 |
+
update_state((s) => {
|
| 247 |
+
const sort_cols = s.sort_state.sort_columns.filter(
|
| 248 |
+
(c) => c.col !== col
|
| 249 |
+
);
|
| 250 |
+
if (
|
| 251 |
+
!s.sort_state.sort_columns.some(
|
| 252 |
+
(c) => c.col === col && c.direction === direction
|
| 253 |
+
)
|
| 254 |
+
) {
|
| 255 |
+
sort_cols.push({ col, direction });
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
const initial_data =
|
| 259 |
+
s.sort_state.initial_data ||
|
| 260 |
+
(context.data && sort_cols.length > 0
|
| 261 |
+
? {
|
| 262 |
+
data: JSON.parse(JSON.stringify(context.data)),
|
| 263 |
+
display_value: context.display_value
|
| 264 |
+
? JSON.parse(JSON.stringify(context.display_value))
|
| 265 |
+
: null,
|
| 266 |
+
styling: context.styling
|
| 267 |
+
? JSON.parse(JSON.stringify(context.styling))
|
| 268 |
+
: null
|
| 269 |
+
}
|
| 270 |
+
: null);
|
| 271 |
+
|
| 272 |
+
return {
|
| 273 |
+
sort_state: {
|
| 274 |
+
...s.sort_state,
|
| 275 |
+
sort_columns: sort_cols.slice(-3),
|
| 276 |
+
initial_data: initial_data
|
| 277 |
+
}
|
| 278 |
+
};
|
| 279 |
+
}),
|
| 280 |
+
handle_filter: (col, datatype, filter, value) =>
|
| 281 |
+
update_state((s) => {
|
| 282 |
+
const filter_cols = s.filter_state.filter_columns.some(
|
| 283 |
+
(c) => c.col === col
|
| 284 |
+
)
|
| 285 |
+
? s.filter_state.filter_columns.filter((c) => c.col !== col)
|
| 286 |
+
: [
|
| 287 |
+
...s.filter_state.filter_columns,
|
| 288 |
+
{ col, datatype, filter, value }
|
| 289 |
+
];
|
| 290 |
+
|
| 291 |
+
const initial_data =
|
| 292 |
+
s.filter_state.initial_data ||
|
| 293 |
+
(context.data && filter_cols.length > 0
|
| 294 |
+
? {
|
| 295 |
+
data: JSON.parse(JSON.stringify(context.data)),
|
| 296 |
+
display_value: context.display_value
|
| 297 |
+
? JSON.parse(JSON.stringify(context.display_value))
|
| 298 |
+
: null,
|
| 299 |
+
styling: context.styling
|
| 300 |
+
? JSON.parse(JSON.stringify(context.styling))
|
| 301 |
+
: null
|
| 302 |
+
}
|
| 303 |
+
: null);
|
| 304 |
+
|
| 305 |
+
return {
|
| 306 |
+
filter_state: {
|
| 307 |
+
...s.filter_state,
|
| 308 |
+
filter_columns: filter_cols,
|
| 309 |
+
initial_data: initial_data
|
| 310 |
+
}
|
| 311 |
+
};
|
| 312 |
+
}),
|
| 313 |
+
get_sort_status: (name, headers) => {
|
| 314 |
+
const s = get(state);
|
| 315 |
+
const sort_item = s.sort_state.sort_columns.find(
|
| 316 |
+
(item) => headers[item.col] === name
|
| 317 |
+
);
|
| 318 |
+
return sort_item ? sort_item.direction : "none";
|
| 319 |
+
},
|
| 320 |
+
sort_data: (data, display_value, styling) => {
|
| 321 |
+
const {
|
| 322 |
+
sort_state: { sort_columns }
|
| 323 |
+
} = get(state);
|
| 324 |
+
if (sort_columns.length)
|
| 325 |
+
sort_table_data(data, display_value, styling, sort_columns);
|
| 326 |
+
},
|
| 327 |
+
update_row_order: (data) =>
|
| 328 |
+
update_state((s) => ({
|
| 329 |
+
sort_state: {
|
| 330 |
+
...s.sort_state,
|
| 331 |
+
row_order:
|
| 332 |
+
s.sort_state.sort_columns.length && data[0]
|
| 333 |
+
? [...Array(data.length)]
|
| 334 |
+
.map((_, i) => i)
|
| 335 |
+
.sort((a, b) => {
|
| 336 |
+
for (const { col, direction } of s.sort_state
|
| 337 |
+
.sort_columns) {
|
| 338 |
+
const comp =
|
| 339 |
+
(data[a]?.[col]?.value ?? "") <
|
| 340 |
+
(data[b]?.[col]?.value ?? "")
|
| 341 |
+
? -1
|
| 342 |
+
: 1;
|
| 343 |
+
if (comp) return direction === "asc" ? comp : -comp;
|
| 344 |
+
}
|
| 345 |
+
return 0;
|
| 346 |
+
})
|
| 347 |
+
: [...Array(data.length)].map((_, i) => i)
|
| 348 |
+
}
|
| 349 |
+
})),
|
| 350 |
+
filter_data: (data) => {
|
| 351 |
+
const query = get(state).current_search_query?.toLowerCase();
|
| 352 |
+
return query
|
| 353 |
+
? data.filter((row) =>
|
| 354 |
+
row.some((cell) =>
|
| 355 |
+
String(cell?.value).toLowerCase().includes(query)
|
| 356 |
+
)
|
| 357 |
+
)
|
| 358 |
+
: data;
|
| 359 |
+
},
|
| 360 |
+
add_row,
|
| 361 |
+
add_col,
|
| 362 |
+
add_row_at: (data, index, position, make_id) =>
|
| 363 |
+
add_row(data, make_id, position === "above" ? index : index + 1),
|
| 364 |
+
add_col_at: (data, headers, index, position, make_id) =>
|
| 365 |
+
add_col(data, headers, make_id, position === "left" ? index : index + 1),
|
| 366 |
+
delete_row: (data, index) =>
|
| 367 |
+
data.length > 1 ? data.filter((_, i) => i !== index) : data,
|
| 368 |
+
delete_col: (data, headers, index) =>
|
| 369 |
+
headers.length > 1
|
| 370 |
+
? {
|
| 371 |
+
data: data.map((row) => row.filter((_, i) => i !== index)),
|
| 372 |
+
headers: headers.filter((_, i) => i !== index)
|
| 373 |
+
}
|
| 374 |
+
: { data, headers },
|
| 375 |
+
delete_row_at: (data, index) =>
|
| 376 |
+
data.length > 1
|
| 377 |
+
? [...data.slice(0, index), ...data.slice(index + 1)]
|
| 378 |
+
: data,
|
| 379 |
+
delete_col_at: (data, headers, index) =>
|
| 380 |
+
headers.length > 1
|
| 381 |
+
? {
|
| 382 |
+
data: data.map((row) => [
|
| 383 |
+
...row.slice(0, index),
|
| 384 |
+
...row.slice(index + 1)
|
| 385 |
+
]),
|
| 386 |
+
headers: [...headers.slice(0, index), ...headers.slice(index + 1)]
|
| 387 |
+
}
|
| 388 |
+
: { data, headers },
|
| 389 |
+
trigger_change: async (
|
| 390 |
+
data,
|
| 391 |
+
headers,
|
| 392 |
+
previous_data,
|
| 393 |
+
previous_headers,
|
| 394 |
+
value_is_output,
|
| 395 |
+
dispatch
|
| 396 |
+
) => {
|
| 397 |
+
const s = get(state);
|
| 398 |
+
if (s.current_search_query) return;
|
| 399 |
+
|
| 400 |
+
const current_headers = headers.map((h) => h.value);
|
| 401 |
+
const current_data = data.map((row) => row.map((cell) => cell.value));
|
| 402 |
+
|
| 403 |
+
if (
|
| 404 |
+
!dequal(current_data, previous_data) ||
|
| 405 |
+
!dequal(current_headers, previous_headers)
|
| 406 |
+
) {
|
| 407 |
+
if (!dequal(current_headers, previous_headers)) {
|
| 408 |
+
update_state((s) => ({
|
| 409 |
+
sort_state: { sort_columns: [], row_order: [], initial_data: null },
|
| 410 |
+
filter_state: { filter_columns: [], initial_data: null }
|
| 411 |
+
}));
|
| 412 |
+
}
|
| 413 |
+
dispatch("change", {
|
| 414 |
+
data: data.map((row) => row.map((cell) => cell.value)),
|
| 415 |
+
headers: current_headers,
|
| 416 |
+
metadata: null
|
| 417 |
+
});
|
| 418 |
+
const index = s.ui_state.selected;
|
| 419 |
+
if (index) {
|
| 420 |
+
dispatch("edit", {
|
| 421 |
+
index,
|
| 422 |
+
value: data[index[0]][index[1]].value,
|
| 423 |
+
previous_value: previous_data[index[0]][index[1]]
|
| 424 |
+
});
|
| 425 |
+
}
|
| 426 |
+
if (!value_is_output) dispatch("input");
|
| 427 |
+
}
|
| 428 |
+
},
|
| 429 |
+
reset_sort_state: () =>
|
| 430 |
+
update_state((s) => {
|
| 431 |
+
if (s.sort_state.initial_data && context.data) {
|
| 432 |
+
const original = s.sort_state.initial_data;
|
| 433 |
+
|
| 434 |
+
update_array(original.data, context.data);
|
| 435 |
+
update_array(original.display_value, context.display_value);
|
| 436 |
+
update_array(original.styling, context.styling);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
return {
|
| 440 |
+
sort_state: { sort_columns: [], row_order: [], initial_data: null }
|
| 441 |
+
};
|
| 442 |
+
}),
|
| 443 |
+
reset_filter_state: () =>
|
| 444 |
+
update_state((s) => {
|
| 445 |
+
if (s.filter_state.initial_data && context.data) {
|
| 446 |
+
const original = s.filter_state.initial_data;
|
| 447 |
+
|
| 448 |
+
update_array(original.data, context.data);
|
| 449 |
+
update_array(original.display_value, context.display_value);
|
| 450 |
+
update_array(original.styling, context.styling);
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
return {
|
| 454 |
+
filter_state: { filter_columns: [], initial_data: null }
|
| 455 |
+
};
|
| 456 |
+
}),
|
| 457 |
+
set_active_cell_menu: (menu) =>
|
| 458 |
+
update_state((s) => ({
|
| 459 |
+
ui_state: { ...s.ui_state, active_cell_menu: menu }
|
| 460 |
+
})),
|
| 461 |
+
set_active_header_menu: (menu) =>
|
| 462 |
+
update_state((s) => ({
|
| 463 |
+
ui_state: { ...s.ui_state, active_header_menu: menu }
|
| 464 |
+
})),
|
| 465 |
+
set_selected_cells: (cells) =>
|
| 466 |
+
update_state((s) => ({
|
| 467 |
+
ui_state: { ...s.ui_state, selected_cells: cells }
|
| 468 |
+
})),
|
| 469 |
+
set_selected: (selected) =>
|
| 470 |
+
update_state((s) => ({ ui_state: { ...s.ui_state, selected } })),
|
| 471 |
+
set_editing: (editing) =>
|
| 472 |
+
update_state((s) => ({ ui_state: { ...s.ui_state, editing } })),
|
| 473 |
+
clear_ui_state: () =>
|
| 474 |
+
update_state((s) => ({
|
| 475 |
+
ui_state: {
|
| 476 |
+
active_cell_menu: null,
|
| 477 |
+
active_header_menu: null,
|
| 478 |
+
selected_cells: [],
|
| 479 |
+
selected: false,
|
| 480 |
+
editing: false,
|
| 481 |
+
header_edit: false,
|
| 482 |
+
selected_header: false,
|
| 483 |
+
active_button: null,
|
| 484 |
+
copy_flash: false
|
| 485 |
+
}
|
| 486 |
+
})),
|
| 487 |
+
set_header_edit: (header_index) =>
|
| 488 |
+
update_state((s) => ({
|
| 489 |
+
ui_state: {
|
| 490 |
+
...s.ui_state,
|
| 491 |
+
selected_cells: [],
|
| 492 |
+
selected_header: header_index,
|
| 493 |
+
header_edit: header_index
|
| 494 |
+
}
|
| 495 |
+
})),
|
| 496 |
+
set_selected_header: (header_index) =>
|
| 497 |
+
update_state((s) => ({
|
| 498 |
+
ui_state: {
|
| 499 |
+
...s.ui_state,
|
| 500 |
+
selected_header: header_index,
|
| 501 |
+
selected: false,
|
| 502 |
+
selected_cells: []
|
| 503 |
+
}
|
| 504 |
+
})),
|
| 505 |
+
handle_header_click: (col, editable) =>
|
| 506 |
+
update_state((s) => ({
|
| 507 |
+
ui_state: {
|
| 508 |
+
...s.ui_state,
|
| 509 |
+
active_cell_menu: null,
|
| 510 |
+
active_header_menu: null,
|
| 511 |
+
selected: false,
|
| 512 |
+
selected_cells: [],
|
| 513 |
+
selected_header: col,
|
| 514 |
+
header_edit: editable ? col : false
|
| 515 |
+
}
|
| 516 |
+
})),
|
| 517 |
+
end_header_edit: (key) => {
|
| 518 |
+
if (["Escape", "Enter", "Tab"].includes(key)) {
|
| 519 |
+
update_state((s) => ({
|
| 520 |
+
ui_state: { ...s.ui_state, selected: false, header_edit: false }
|
| 521 |
+
}));
|
| 522 |
+
}
|
| 523 |
+
},
|
| 524 |
+
get_selected_cells: () => get(state).ui_state.selected_cells,
|
| 525 |
+
get_active_cell_menu: () => get(state).ui_state.active_cell_menu,
|
| 526 |
+
get_active_button: () => get(state).ui_state.active_button,
|
| 527 |
+
set_active_button: (button) =>
|
| 528 |
+
update_state((s) => ({
|
| 529 |
+
ui_state: { ...s.ui_state, active_button: button }
|
| 530 |
+
})),
|
| 531 |
+
set_copy_flash: (value) =>
|
| 532 |
+
update_state((s) => ({ ui_state: { ...s.ui_state, copy_flash: value } })),
|
| 533 |
+
handle_cell_click: (event, row, col) => {
|
| 534 |
+
event.preventDefault();
|
| 535 |
+
event.stopPropagation();
|
| 536 |
+
|
| 537 |
+
const s = get(state);
|
| 538 |
+
if (s.config.show_row_numbers && col === -1) return;
|
| 539 |
+
|
| 540 |
+
let actual_row = row;
|
| 541 |
+
if (s.current_search_query && context.data) {
|
| 542 |
+
const filtered_indices: number[] = [];
|
| 543 |
+
context.data.forEach((dataRow, idx) => {
|
| 544 |
+
if (
|
| 545 |
+
dataRow.some((cell) =>
|
| 546 |
+
String(cell?.value)
|
| 547 |
+
.toLowerCase()
|
| 548 |
+
.includes(s.current_search_query?.toLowerCase() || "")
|
| 549 |
+
)
|
| 550 |
+
) {
|
| 551 |
+
filtered_indices.push(idx);
|
| 552 |
+
}
|
| 553 |
+
});
|
| 554 |
+
actual_row = filtered_indices[row] ?? row;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
const cells = handle_selection(
|
| 558 |
+
[actual_row, col],
|
| 559 |
+
s.ui_state.selected_cells,
|
| 560 |
+
event
|
| 561 |
+
);
|
| 562 |
+
update_state((s) => ({
|
| 563 |
+
ui_state: {
|
| 564 |
+
...s.ui_state,
|
| 565 |
+
active_cell_menu: null,
|
| 566 |
+
active_header_menu: null,
|
| 567 |
+
selected_header: false,
|
| 568 |
+
header_edit: false,
|
| 569 |
+
selected_cells: cells,
|
| 570 |
+
selected: cells[0]
|
| 571 |
+
}
|
| 572 |
+
}));
|
| 573 |
+
|
| 574 |
+
if (s.config.editable && cells.length === 1) {
|
| 575 |
+
update_state((s) => ({
|
| 576 |
+
ui_state: { ...s.ui_state, editing: [actual_row, col] }
|
| 577 |
+
}));
|
| 578 |
+
tick().then(() =>
|
| 579 |
+
context.els![context.data![actual_row][col].id]?.input?.focus()
|
| 580 |
+
);
|
| 581 |
+
} else {
|
| 582 |
+
// ensure parent has focus for keyboard navigation
|
| 583 |
+
tick().then(() => {
|
| 584 |
+
if (context.parent_element) {
|
| 585 |
+
context.parent_element.focus();
|
| 586 |
+
}
|
| 587 |
+
});
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
context.dispatch?.("select", {
|
| 591 |
+
index: [actual_row, col],
|
| 592 |
+
col_value: context.get_column!(col),
|
| 593 |
+
row_value: context.get_row!(actual_row),
|
| 594 |
+
value: context.get_data_at!(actual_row, col)
|
| 595 |
+
});
|
| 596 |
+
},
|
| 597 |
+
toggle_cell_menu: (event, row, col) => {
|
| 598 |
+
event.stopPropagation();
|
| 599 |
+
const current_menu = get(state).ui_state.active_cell_menu;
|
| 600 |
+
if (current_menu?.row === row && current_menu.col === col) {
|
| 601 |
+
update_state((s) => ({
|
| 602 |
+
ui_state: { ...s.ui_state, active_cell_menu: null }
|
| 603 |
+
}));
|
| 604 |
+
} else {
|
| 605 |
+
const cell = (event.target as HTMLElement).closest("td");
|
| 606 |
+
if (cell) {
|
| 607 |
+
const rect = cell.getBoundingClientRect();
|
| 608 |
+
update_state((s) => ({
|
| 609 |
+
ui_state: {
|
| 610 |
+
...s.ui_state,
|
| 611 |
+
active_cell_menu: { row, col, x: rect.right, y: rect.bottom }
|
| 612 |
+
}
|
| 613 |
+
}));
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
},
|
| 617 |
+
toggle_cell_button: (row, col) => {
|
| 618 |
+
const current_button = get(state).ui_state.active_button;
|
| 619 |
+
const new_button =
|
| 620 |
+
current_button?.type === "cell" &&
|
| 621 |
+
current_button.row === row &&
|
| 622 |
+
current_button.col === col
|
| 623 |
+
? null
|
| 624 |
+
: { type: "cell" as const, row, col };
|
| 625 |
+
update_state((s) => ({
|
| 626 |
+
ui_state: { ...s.ui_state, active_button: new_button }
|
| 627 |
+
}));
|
| 628 |
+
},
|
| 629 |
+
handle_select_column: (col) => {
|
| 630 |
+
if (!context.data) return;
|
| 631 |
+
const cells = context.data.map((_, row) => [row, col] as CellCoordinate);
|
| 632 |
+
update_state((s) => ({
|
| 633 |
+
ui_state: {
|
| 634 |
+
...s.ui_state,
|
| 635 |
+
selected_cells: cells,
|
| 636 |
+
selected: cells[0],
|
| 637 |
+
editing: false
|
| 638 |
+
}
|
| 639 |
+
}));
|
| 640 |
+
setTimeout(() => context.parent_element?.focus(), 0);
|
| 641 |
+
},
|
| 642 |
+
handle_select_row: (row) => {
|
| 643 |
+
if (!context.data || !context.data[0]) return;
|
| 644 |
+
const cells = context.data[0].map(
|
| 645 |
+
(_, col) => [row, col] as CellCoordinate
|
| 646 |
+
);
|
| 647 |
+
update_state((s) => ({
|
| 648 |
+
ui_state: {
|
| 649 |
+
...s.ui_state,
|
| 650 |
+
selected_cells: cells,
|
| 651 |
+
selected: cells[0],
|
| 652 |
+
editing: false
|
| 653 |
+
}
|
| 654 |
+
}));
|
| 655 |
+
setTimeout(() => context.parent_element?.focus(), 0);
|
| 656 |
+
},
|
| 657 |
+
get_next_cell_coordinates,
|
| 658 |
+
get_range_selection,
|
| 659 |
+
move_cursor
|
| 660 |
+
};
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
export function create_dataframe_context(
|
| 664 |
+
config: DataFrameState["config"]
|
| 665 |
+
): DataFrameContext {
|
| 666 |
+
const state = writable<DataFrameState>({
|
| 667 |
+
config,
|
| 668 |
+
current_search_query: null,
|
| 669 |
+
sort_state: { sort_columns: [], row_order: [], initial_data: null },
|
| 670 |
+
filter_state: { filter_columns: [], initial_data: null },
|
| 671 |
+
ui_state: {
|
| 672 |
+
active_cell_menu: null,
|
| 673 |
+
active_header_menu: null,
|
| 674 |
+
selected_cells: [],
|
| 675 |
+
selected: false,
|
| 676 |
+
editing: false,
|
| 677 |
+
header_edit: false,
|
| 678 |
+
selected_header: false,
|
| 679 |
+
active_button: null,
|
| 680 |
+
copy_flash: false
|
| 681 |
+
}
|
| 682 |
+
});
|
| 683 |
+
|
| 684 |
+
const context: DataFrameContext = { state, actions: null as any };
|
| 685 |
+
context.actions = create_actions(state, context);
|
| 686 |
+
|
| 687 |
+
const instance_id = Symbol(
|
| 688 |
+
`dataframe_${Math.random().toString(36).substring(2)}`
|
| 689 |
+
);
|
| 690 |
+
setContext(instance_id, context);
|
| 691 |
+
setContext(DATAFRAME_KEY, { instance_id, context });
|
| 692 |
+
|
| 693 |
+
return context;
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
export function get_dataframe_context(): DataFrameContext {
|
| 697 |
+
const ctx = getContext<{ instance_id: symbol; context: DataFrameContext }>(
|
| 698 |
+
DATAFRAME_KEY
|
| 699 |
+
);
|
| 700 |
+
return ctx?.context ?? getContext<DataFrameContext>(DATAFRAME_KEY);
|
| 701 |
+
}
|
5.49.1/dataframe/shared/icons/FilterIcon.svelte
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
</script>
|
| 3 |
+
|
| 4 |
+
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 5 |
+
<path
|
| 6 |
+
d="M4 4h16v2.67l-6.67 6.67v8L9.33 19v-5.66L2.67 6.67V4h1.33z"
|
| 7 |
+
stroke="currentColor"
|
| 8 |
+
stroke-width="2"
|
| 9 |
+
stroke-linecap="round"
|
| 10 |
+
stroke-linejoin="round"
|
| 11 |
+
/>
|
| 12 |
+
</svg>
|
5.49.1/dataframe/shared/icons/Padlock.svelte
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div class="wrapper" aria-label="Static column">
|
| 2 |
+
<svg
|
| 3 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 4 |
+
width="13"
|
| 5 |
+
height="13"
|
| 6 |
+
viewBox="0 0 24 24"
|
| 7 |
+
fill="none"
|
| 8 |
+
stroke="currentColor"
|
| 9 |
+
stroke-width="2"
|
| 10 |
+
stroke-linecap="round"
|
| 11 |
+
stroke-linejoin="round"
|
| 12 |
+
>
|
| 13 |
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
|
| 14 |
+
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
|
| 15 |
+
</svg>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<style>
|
| 19 |
+
.wrapper {
|
| 20 |
+
display: flex;
|
| 21 |
+
align-items: center;
|
| 22 |
+
justify-content: center;
|
| 23 |
+
}
|
| 24 |
+
</style>
|
5.49.1/dataframe/shared/icons/SelectionButtons.svelte
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let position: "column" | "row";
|
| 3 |
+
export let coords: [number, number];
|
| 4 |
+
export let on_click: (() => void) | null = null;
|
| 5 |
+
|
| 6 |
+
$: is_first_position =
|
| 7 |
+
position === "column" ? coords[0] === 0 : coords[1] === 0;
|
| 8 |
+
$: direction =
|
| 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 |
+
on:click|stopPropagation={() => on_click && on_click()}
|
| 23 |
+
aria-label={`Select ${position}`}
|
| 24 |
+
>
|
| 25 |
+
<span class={direction}>
|
| 26 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
| 27 |
+
<path
|
| 28 |
+
d="m16.707 13.293-4-4a1 1 0 0 0-1.414 0l-4 4A1 1 0 0 0 8 15h8a1 1 0 0 0 .707-1.707z"
|
| 29 |
+
data-name={direction}
|
| 30 |
+
/>
|
| 31 |
+
</svg>
|
| 32 |
+
</span>
|
| 33 |
+
</button>
|
| 34 |
+
|
| 35 |
+
<style>
|
| 36 |
+
.selection-button {
|
| 37 |
+
position: absolute;
|
| 38 |
+
background: var(--color-accent);
|
| 39 |
+
width: var(--size-3);
|
| 40 |
+
height: var(--size-5);
|
| 41 |
+
color: var(--background-fill-primary);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.selection-button-column {
|
| 45 |
+
top: -15px;
|
| 46 |
+
left: 50%;
|
| 47 |
+
transform: translateX(-50%) rotate(90deg);
|
| 48 |
+
border-radius: var(--radius-sm) 0 0 var(--radius-sm);
|
| 49 |
+
}
|
| 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 |
+
|
| 56 |
+
.move-down {
|
| 57 |
+
bottom: -14px;
|
| 58 |
+
top: auto;
|
| 59 |
+
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
|
| 60 |
+
}
|
| 61 |
+
|
| 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 |
+
|
| 68 |
+
svg {
|
| 69 |
+
fill: currentColor;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
span {
|
| 73 |
+
display: flex;
|
| 74 |
+
width: 100%;
|
| 75 |
+
height: 100%;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.up {
|
| 79 |
+
transform: rotate(-90deg);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.down {
|
| 83 |
+
transform: rotate(90deg);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.left {
|
| 87 |
+
transform: rotate(-90deg);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.right {
|
| 91 |
+
transform: rotate(90deg);
|
| 92 |
+
}
|
| 93 |
+
</style>
|
5.49.1/dataframe/shared/icons/SortArrowDown.svelte
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let size = 16;
|
| 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>
|
5.49.1/dataframe/shared/icons/SortArrowUp.svelte
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export let size = 16;
|
| 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>
|
5.49.1/dataframe/shared/icons/SortButtonDown.svelte
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
viewBox="0 0 24 24"
|
| 3 |
+
fill="none"
|
| 4 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 5 |
+
focusable="false"
|
| 6 |
+
>
|
| 7 |
+
<path
|
| 8 |
+
d="M7 10l5 5 5-5"
|
| 9 |
+
stroke="currentColor"
|
| 10 |
+
stroke-width="2"
|
| 11 |
+
stroke-linecap="round"
|
| 12 |
+
stroke-linejoin="round"
|
| 13 |
+
/>
|
| 14 |
+
</svg>
|
5.49.1/dataframe/shared/icons/SortButtonUp.svelte
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<svg
|
| 2 |
+
viewBox="0 0 24 24"
|
| 3 |
+
fill="none"
|
| 4 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 5 |
+
aria-hidden="true"
|
| 6 |
+
focusable="false"
|
| 7 |
+
>
|
| 8 |
+
<path
|
| 9 |
+
d="M7 14l5-5 5 5"
|
| 10 |
+
stroke="currentColor"
|
| 11 |
+
stroke-width="2"
|
| 12 |
+
stroke-linecap="round"
|
| 13 |
+
stroke-linejoin="round"
|
| 14 |
+
/>
|
| 15 |
+
</svg>
|
5.49.1/dataframe/shared/icons/SortIcon.svelte
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
const dispatch = createEventDispatcher<{ sort: SortDirection }>();
|
| 13 |
+
</script>
|
| 14 |
+
|
| 15 |
+
<div class="sort-icons" role="group" aria-label={i18n("dataframe.sort_column")}>
|
| 16 |
+
{#if (direction === "asc" || direction === "desc") && priority !== null}
|
| 17 |
+
<span aria-label={`Sort priority: ${priority}`} class="priority"
|
| 18 |
+
>{priority}</span
|
| 19 |
+
>
|
| 20 |
+
{/if}
|
| 21 |
+
<IconButton
|
| 22 |
+
size="x-small"
|
| 23 |
+
label={i18n("dataframe.sort_ascending")}
|
| 24 |
+
Icon={SortButtonUp}
|
| 25 |
+
highlight={direction === "asc"}
|
| 26 |
+
on:click={(event) => {
|
| 27 |
+
event.stopPropagation();
|
| 28 |
+
dispatch("sort", "asc");
|
| 29 |
+
}}
|
| 30 |
+
></IconButton>
|
| 31 |
+
<IconButton
|
| 32 |
+
size="x-small"
|
| 33 |
+
label={i18n("dataframe.sort_descending")}
|
| 34 |
+
Icon={SortButtonDown}
|
| 35 |
+
highlight={direction === "desc"}
|
| 36 |
+
on:click={(event) => {
|
| 37 |
+
event.stopPropagation();
|
| 38 |
+
dispatch("sort", "desc");
|
| 39 |
+
}}
|
| 40 |
+
></IconButton>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
<style>
|
| 44 |
+
.sort-icons {
|
| 45 |
+
display: flex;
|
| 46 |
+
flex-direction: column;
|
| 47 |
+
gap: 0;
|
| 48 |
+
margin-right: var(--spacing-sm);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.sort-icons :global(button) {
|
| 52 |
+
margin-bottom: var(--spacing-xs);
|
| 53 |
+
border: 1px solid var(--border-color-primary);
|
| 54 |
+
background: unset;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.priority {
|
| 58 |
+
display: flex;
|
| 59 |
+
align-items: center;
|
| 60 |
+
justify-content: center;
|
| 61 |
+
position: absolute;
|
| 62 |
+
font-size: var(--size-2);
|
| 63 |
+
left: 19px;
|
| 64 |
+
z-index: var(--layer-3);
|
| 65 |
+
top: var(--spacing-xs);
|
| 66 |
+
background-color: var(--button-secondary-background-fill);
|
| 67 |
+
color: var(--body-text-color);
|
| 68 |
+
border-radius: var(--radius-sm);
|
| 69 |
+
width: var(--size-2-5);
|
| 70 |
+
height: var(--size-2-5);
|
| 71 |
+
}
|
| 72 |
+
</style>
|
5.49.1/dataframe/shared/types.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type CellCoordinate = [number, number];
|
| 2 |
+
export type EditingState = CellCoordinate | false;
|
| 3 |
+
|
| 4 |
+
export type Headers = (string | null)[];
|
| 5 |
+
|
| 6 |
+
export interface HeadersWithIDs {
|
| 7 |
+
id: string;
|
| 8 |
+
value: string;
|
| 9 |
+
}
|
| 10 |
+
[];
|
| 11 |
+
|
| 12 |
+
export type CellValue = string | number | boolean;
|
| 13 |
+
|
| 14 |
+
export interface TableCell {
|
| 15 |
+
id: string;
|
| 16 |
+
value: CellValue;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export type TableData = TableCell[][];
|
| 20 |
+
|
| 21 |
+
export type CountConfig = [number, "fixed" | "dynamic"];
|
| 22 |
+
|
| 23 |
+
export type ElementRefs = Record<
|
| 24 |
+
string,
|
| 25 |
+
{
|
| 26 |
+
cell: null | HTMLTableCellElement;
|
| 27 |
+
input: null | HTMLTextAreaElement;
|
| 28 |
+
}
|
| 29 |
+
>;
|
| 30 |
+
|
| 31 |
+
export type DataBinding = Record<string, TableCell>;
|
5.49.1/dataframe/shared/utils/data_processing.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Datatype, Headers, HeadersWithIDs } from "./utils";
|
| 2 |
+
import type { CellValue } from "../types";
|
| 3 |
+
import { cast_value_to_type } from "./utils";
|
| 4 |
+
|
| 5 |
+
export function make_headers(
|
| 6 |
+
_head: Headers,
|
| 7 |
+
col_count: [number, "fixed" | "dynamic"],
|
| 8 |
+
els: Record<
|
| 9 |
+
string,
|
| 10 |
+
{ cell: null | HTMLTableCellElement; input: null | HTMLTextAreaElement }
|
| 11 |
+
>,
|
| 12 |
+
make_id: () => string
|
| 13 |
+
): HeadersWithIDs {
|
| 14 |
+
let _h = _head || [];
|
| 15 |
+
if (col_count[1] === "fixed" && _h.length < col_count[0]) {
|
| 16 |
+
const fill = Array(col_count[0] - _h.length)
|
| 17 |
+
.fill("")
|
| 18 |
+
.map((_, i) => `${i + _h.length}`);
|
| 19 |
+
_h = _h.concat(fill);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if (!_h || _h.length === 0) {
|
| 23 |
+
return Array(col_count[0])
|
| 24 |
+
.fill(0)
|
| 25 |
+
.map((_, i) => {
|
| 26 |
+
const _id = make_id();
|
| 27 |
+
els[_id] = { cell: null, input: null };
|
| 28 |
+
return { id: _id, value: JSON.stringify(i + 1) };
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return _h.map((h, i) => {
|
| 33 |
+
const _id = make_id();
|
| 34 |
+
els[_id] = { cell: null, input: null };
|
| 35 |
+
return { id: _id, value: h ?? "" };
|
| 36 |
+
});
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export function process_data(
|
| 40 |
+
values: CellValue[][],
|
| 41 |
+
els: Record<
|
| 42 |
+
string,
|
| 43 |
+
{ cell: null | HTMLTableCellElement; input: null | HTMLTextAreaElement }
|
| 44 |
+
>,
|
| 45 |
+
data_binding: Record<string, any>,
|
| 46 |
+
make_id: () => string,
|
| 47 |
+
display_value: string[][] | null = null,
|
| 48 |
+
datatype: Datatype | Datatype[]
|
| 49 |
+
): { id: string; value: CellValue; display_value?: string }[][] {
|
| 50 |
+
if (!values || values.length === 0) {
|
| 51 |
+
return [];
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const result = values.map((row, i) => {
|
| 55 |
+
return row.map((value, j) => {
|
| 56 |
+
const _id = make_id();
|
| 57 |
+
els[_id] = { cell: null, input: null };
|
| 58 |
+
data_binding[_id] = value;
|
| 59 |
+
|
| 60 |
+
let display = display_value?.[i]?.[j];
|
| 61 |
+
|
| 62 |
+
if (display === undefined) {
|
| 63 |
+
display = String(value);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
const dtype = Array.isArray(datatype) ? datatype[j] : datatype;
|
| 67 |
+
|
| 68 |
+
return {
|
| 69 |
+
id: _id,
|
| 70 |
+
value: cast_value_to_type(value, dtype),
|
| 71 |
+
display_value: display
|
| 72 |
+
};
|
| 73 |
+
});
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
return result;
|
| 77 |
+
}
|
5.49.1/dataframe/shared/utils/drag_utils.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { CellCoordinate } from "../types";
|
| 2 |
+
import { get_range_selection } from "../utils/selection_utils";
|
| 3 |
+
|
| 4 |
+
export type DragState = {
|
| 5 |
+
is_dragging: boolean;
|
| 6 |
+
drag_start: CellCoordinate | null;
|
| 7 |
+
mouse_down_pos: { x: number; y: number } | null;
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
export type DragHandlers = {
|
| 11 |
+
handle_mouse_down: (event: MouseEvent, row: number, col: number) => void;
|
| 12 |
+
handle_mouse_move: (event: MouseEvent) => void;
|
| 13 |
+
handle_mouse_up: (event: MouseEvent) => void;
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
export function create_drag_handlers(
|
| 17 |
+
state: DragState,
|
| 18 |
+
set_is_dragging: (value: boolean) => void,
|
| 19 |
+
set_selected_cells: (cells: CellCoordinate[]) => void,
|
| 20 |
+
set_selected: (cell: CellCoordinate | false) => void,
|
| 21 |
+
handle_cell_click: (event: MouseEvent, row: number, col: number) => void,
|
| 22 |
+
show_row_numbers: boolean,
|
| 23 |
+
parent_element?: HTMLElement
|
| 24 |
+
): DragHandlers {
|
| 25 |
+
const start_drag = (event: MouseEvent, row: number, col: number): void => {
|
| 26 |
+
const target = event.target as HTMLElement;
|
| 27 |
+
const is_checkbox_click =
|
| 28 |
+
(target as HTMLInputElement).type === "checkbox" ||
|
| 29 |
+
target.closest('input[type="checkbox"]') ||
|
| 30 |
+
target.closest(".bool-cell");
|
| 31 |
+
|
| 32 |
+
if (
|
| 33 |
+
event.target instanceof HTMLAnchorElement ||
|
| 34 |
+
(show_row_numbers && col === -1) ||
|
| 35 |
+
is_checkbox_click
|
| 36 |
+
)
|
| 37 |
+
return;
|
| 38 |
+
|
| 39 |
+
event.preventDefault();
|
| 40 |
+
event.stopPropagation();
|
| 41 |
+
|
| 42 |
+
state.mouse_down_pos = { x: event.clientX, y: event.clientY };
|
| 43 |
+
state.drag_start = [row, col];
|
| 44 |
+
|
| 45 |
+
if (!event.shiftKey && !event.metaKey && !event.ctrlKey) {
|
| 46 |
+
set_selected_cells([[row, col]]);
|
| 47 |
+
set_selected([row, col]);
|
| 48 |
+
handle_cell_click(event, row, col);
|
| 49 |
+
}
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
const update_selection = (event: MouseEvent): void => {
|
| 53 |
+
const cell = (event.target as HTMLElement).closest("td");
|
| 54 |
+
if (!cell) return;
|
| 55 |
+
|
| 56 |
+
const row = parseInt(cell.getAttribute("data-row") || "0");
|
| 57 |
+
const col = parseInt(cell.getAttribute("data-col") || "0");
|
| 58 |
+
|
| 59 |
+
if (isNaN(row) || isNaN(col)) return;
|
| 60 |
+
|
| 61 |
+
const selection_range = get_range_selection(state.drag_start!, [row, col]);
|
| 62 |
+
set_selected_cells(selection_range);
|
| 63 |
+
set_selected([row, col]);
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
const end_drag = (event: MouseEvent): void => {
|
| 67 |
+
if (!state.is_dragging && state.drag_start) {
|
| 68 |
+
handle_cell_click(event, state.drag_start[0], state.drag_start[1]);
|
| 69 |
+
} else if (state.is_dragging && parent_element) {
|
| 70 |
+
parent_element.focus();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
state.is_dragging = false;
|
| 74 |
+
set_is_dragging(false);
|
| 75 |
+
state.drag_start = null;
|
| 76 |
+
state.mouse_down_pos = null;
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
return {
|
| 80 |
+
handle_mouse_down: start_drag,
|
| 81 |
+
|
| 82 |
+
handle_mouse_move(event: MouseEvent): void {
|
| 83 |
+
if (!state.drag_start || !state.mouse_down_pos) return;
|
| 84 |
+
|
| 85 |
+
if (!(event.buttons & 1)) {
|
| 86 |
+
end_drag(event);
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
const dx = Math.abs(event.clientX - state.mouse_down_pos.x);
|
| 91 |
+
const dy = Math.abs(event.clientY - state.mouse_down_pos.y);
|
| 92 |
+
|
| 93 |
+
if (!state.is_dragging && (dx > 3 || dy > 3)) {
|
| 94 |
+
state.is_dragging = true;
|
| 95 |
+
set_is_dragging(true);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if (state.is_dragging) {
|
| 99 |
+
update_selection(event);
|
| 100 |
+
}
|
| 101 |
+
},
|
| 102 |
+
|
| 103 |
+
handle_mouse_up: end_drag
|
| 104 |
+
};
|
| 105 |
+
}
|
5.49.1/dataframe/shared/utils/filter_utils.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
| 1 |
+
import { filter_table_data } from "./table_utils";
|
| 2 |
+
import type { CellValue } from "../types";
|
| 3 |
+
|
| 4 |
+
export type FilterDatatype = "string" | "number";
|
| 5 |
+
|
| 6 |
+
export function filter_data(
|
| 7 |
+
data: { id: string; value: CellValue }[][],
|
| 8 |
+
filter_columns: {
|
| 9 |
+
col: number;
|
| 10 |
+
datatype: FilterDatatype;
|
| 11 |
+
filter: string;
|
| 12 |
+
value: string;
|
| 13 |
+
}[]
|
| 14 |
+
): number[] {
|
| 15 |
+
if (!data || !data.length || !data[0]) {
|
| 16 |
+
return [];
|
| 17 |
+
}
|
| 18 |
+
let row_indices = [...Array(data.length)].map((_, i) => i);
|
| 19 |
+
|
| 20 |
+
if (filter_columns.length > 0) {
|
| 21 |
+
filter_columns.forEach((column) => {
|
| 22 |
+
if (column.datatype === "string") {
|
| 23 |
+
switch (column.filter) {
|
| 24 |
+
case "Contains":
|
| 25 |
+
row_indices = row_indices.filter((i) =>
|
| 26 |
+
data[i][column.col]?.value.toString().includes(column.value)
|
| 27 |
+
);
|
| 28 |
+
break;
|
| 29 |
+
case "Does not contain":
|
| 30 |
+
row_indices = row_indices.filter(
|
| 31 |
+
(i) =>
|
| 32 |
+
!data[i][column.col]?.value.toString().includes(column.value)
|
| 33 |
+
);
|
| 34 |
+
break;
|
| 35 |
+
case "Starts with":
|
| 36 |
+
row_indices = row_indices.filter((i) =>
|
| 37 |
+
data[i][column.col]?.value.toString().startsWith(column.value)
|
| 38 |
+
);
|
| 39 |
+
break;
|
| 40 |
+
case "Ends with":
|
| 41 |
+
row_indices = row_indices.filter((i) =>
|
| 42 |
+
data[i][column.col]?.value.toString().endsWith(column.value)
|
| 43 |
+
);
|
| 44 |
+
break;
|
| 45 |
+
case "Is":
|
| 46 |
+
row_indices = row_indices.filter(
|
| 47 |
+
(i) => data[i][column.col]?.value.toString() === column.value
|
| 48 |
+
);
|
| 49 |
+
break;
|
| 50 |
+
case "Is not":
|
| 51 |
+
row_indices = row_indices.filter(
|
| 52 |
+
(i) => !(data[i][column.col]?.value.toString() === column.value)
|
| 53 |
+
);
|
| 54 |
+
break;
|
| 55 |
+
case "Is empty":
|
| 56 |
+
row_indices = row_indices.filter(
|
| 57 |
+
(i) => data[i][column.col]?.value.toString() === ""
|
| 58 |
+
);
|
| 59 |
+
break;
|
| 60 |
+
case "Is not empty":
|
| 61 |
+
row_indices = row_indices.filter(
|
| 62 |
+
(i) => !(data[i][column.col]?.value.toString() === "")
|
| 63 |
+
);
|
| 64 |
+
break;
|
| 65 |
+
}
|
| 66 |
+
} else if (column.datatype === "number") {
|
| 67 |
+
switch (column.filter) {
|
| 68 |
+
case "=":
|
| 69 |
+
row_indices = row_indices.filter((i) => {
|
| 70 |
+
if (
|
| 71 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 72 |
+
!isNaN(Number(column.value))
|
| 73 |
+
) {
|
| 74 |
+
return (
|
| 75 |
+
Number(data[i][column.col]?.value) === Number(column.value)
|
| 76 |
+
);
|
| 77 |
+
}
|
| 78 |
+
return false;
|
| 79 |
+
});
|
| 80 |
+
break;
|
| 81 |
+
case "≠":
|
| 82 |
+
row_indices = row_indices.filter((i) => {
|
| 83 |
+
if (
|
| 84 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 85 |
+
!isNaN(Number(column.value))
|
| 86 |
+
) {
|
| 87 |
+
return !(
|
| 88 |
+
Number(data[i][column.col]?.value) === Number(column.value)
|
| 89 |
+
);
|
| 90 |
+
}
|
| 91 |
+
return false;
|
| 92 |
+
});
|
| 93 |
+
break;
|
| 94 |
+
case ">":
|
| 95 |
+
row_indices = row_indices.filter((i) => {
|
| 96 |
+
if (
|
| 97 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 98 |
+
!isNaN(Number(column.value))
|
| 99 |
+
) {
|
| 100 |
+
return (
|
| 101 |
+
Number(data[i][column.col]?.value) > Number(column.value)
|
| 102 |
+
);
|
| 103 |
+
}
|
| 104 |
+
return false;
|
| 105 |
+
});
|
| 106 |
+
break;
|
| 107 |
+
case "<":
|
| 108 |
+
row_indices = row_indices.filter((i) => {
|
| 109 |
+
if (
|
| 110 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 111 |
+
!isNaN(Number(column.value))
|
| 112 |
+
) {
|
| 113 |
+
return (
|
| 114 |
+
Number(data[i][column.col]?.value) < Number(column.value)
|
| 115 |
+
);
|
| 116 |
+
}
|
| 117 |
+
return false;
|
| 118 |
+
});
|
| 119 |
+
break;
|
| 120 |
+
case "≥":
|
| 121 |
+
row_indices = row_indices.filter((i) => {
|
| 122 |
+
if (
|
| 123 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 124 |
+
!isNaN(Number(column.value))
|
| 125 |
+
) {
|
| 126 |
+
return (
|
| 127 |
+
Number(data[i][column.col]?.value) >= Number(column.value)
|
| 128 |
+
);
|
| 129 |
+
}
|
| 130 |
+
return false;
|
| 131 |
+
});
|
| 132 |
+
break;
|
| 133 |
+
case "≤":
|
| 134 |
+
row_indices = row_indices.filter((i) => {
|
| 135 |
+
if (
|
| 136 |
+
!isNaN(Number(data[i][column.col]?.value)) &&
|
| 137 |
+
!isNaN(Number(column.value))
|
| 138 |
+
) {
|
| 139 |
+
return (
|
| 140 |
+
Number(data[i][column.col]?.value) <= Number(column.value)
|
| 141 |
+
);
|
| 142 |
+
}
|
| 143 |
+
return false;
|
| 144 |
+
});
|
| 145 |
+
break;
|
| 146 |
+
case "Is empty":
|
| 147 |
+
row_indices = row_indices.filter(
|
| 148 |
+
(i) => data[i][column.col]?.value.toString() === ""
|
| 149 |
+
);
|
| 150 |
+
break;
|
| 151 |
+
case "Is not empty":
|
| 152 |
+
row_indices = row_indices.filter((i) => {
|
| 153 |
+
if (!isNaN(Number(data[i][column.col]?.value))) {
|
| 154 |
+
return !(data[i][column.col]?.value.toString() === "");
|
| 155 |
+
}
|
| 156 |
+
return false;
|
| 157 |
+
});
|
| 158 |
+
break;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
});
|
| 162 |
+
return row_indices;
|
| 163 |
+
}
|
| 164 |
+
return [...Array(data.length)].map((_, i) => i);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
export function filter_data_and_preserve_selection(
|
| 168 |
+
data: { id: string; value: CellValue }[][],
|
| 169 |
+
display_value: string[][] | null,
|
| 170 |
+
styling: string[][] | null,
|
| 171 |
+
filter_columns: {
|
| 172 |
+
col: number;
|
| 173 |
+
datatype: FilterDatatype;
|
| 174 |
+
filter: string;
|
| 175 |
+
value: string;
|
| 176 |
+
}[],
|
| 177 |
+
selected: [number, number] | false,
|
| 178 |
+
get_current_indices: (
|
| 179 |
+
id: string,
|
| 180 |
+
data: { id: string; value: CellValue }[][]
|
| 181 |
+
) => [number, number],
|
| 182 |
+
original_data?: { id: string; value: CellValue }[][],
|
| 183 |
+
original_display_value?: string[][] | null,
|
| 184 |
+
original_styling?: string[][] | null
|
| 185 |
+
): { data: typeof data; selected: [number, number] | false } {
|
| 186 |
+
let id = null;
|
| 187 |
+
if (selected && selected[0] in data && selected[1] in data[selected[0]]) {
|
| 188 |
+
id = data[selected[0]][selected[1]].id;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
filter_table_data(
|
| 192 |
+
data,
|
| 193 |
+
display_value,
|
| 194 |
+
styling,
|
| 195 |
+
filter_columns,
|
| 196 |
+
original_data,
|
| 197 |
+
original_display_value,
|
| 198 |
+
original_styling
|
| 199 |
+
);
|
| 200 |
+
|
| 201 |
+
let new_selected = selected;
|
| 202 |
+
if (id) {
|
| 203 |
+
const [i, j] = get_current_indices(id, data);
|
| 204 |
+
new_selected = [i, j];
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
return { data, selected: new_selected };
|
| 208 |
+
}
|
5.49.1/dataframe/shared/utils/keyboard_utils.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { dequal } from "dequal/lite";
|
| 2 |
+
import { handle_delete_key } from "../utils/selection_utils";
|
| 3 |
+
import type { DataFrameContext } from "../context/dataframe_context";
|
| 4 |
+
import { tick } from "svelte";
|
| 5 |
+
import { get } from "svelte/store";
|
| 6 |
+
import { copy_table_data } from "./table_utils";
|
| 7 |
+
|
| 8 |
+
async function save_cell_value(
|
| 9 |
+
input_value: string,
|
| 10 |
+
ctx: DataFrameContext,
|
| 11 |
+
row: number,
|
| 12 |
+
col: number
|
| 13 |
+
): Promise<void> {
|
| 14 |
+
if (!ctx.data || !ctx.data[row] || !ctx.data[row][col]) return;
|
| 15 |
+
|
| 16 |
+
const old_value = ctx.data[row][col].value;
|
| 17 |
+
ctx.data[row][col].value = input_value;
|
| 18 |
+
if (ctx.data[row][col].display_value !== undefined) {
|
| 19 |
+
ctx.data[row][col].display_value = input_value;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if (old_value !== input_value && ctx.dispatch) {
|
| 23 |
+
ctx.dispatch("change", {
|
| 24 |
+
data: ctx.data.map((row) => row.map((cell) => cell.value)),
|
| 25 |
+
headers: ctx.headers?.map((h) => h.value) || [],
|
| 26 |
+
metadata: null
|
| 27 |
+
});
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
ctx.actions.set_selected([row, col]);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export async function handle_cell_blur(
|
| 34 |
+
event: FocusEvent,
|
| 35 |
+
ctx: DataFrameContext,
|
| 36 |
+
coords: [number, number]
|
| 37 |
+
): Promise<void> {
|
| 38 |
+
if (!ctx.data || !ctx.headers || !ctx.els) return;
|
| 39 |
+
|
| 40 |
+
const input_el = event.target as HTMLInputElement;
|
| 41 |
+
if (!input_el || input_el.value === undefined) return;
|
| 42 |
+
|
| 43 |
+
await save_cell_value(input_el.value, ctx, coords[0], coords[1]);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function handle_header_navigation(
|
| 47 |
+
event: KeyboardEvent,
|
| 48 |
+
ctx: DataFrameContext
|
| 49 |
+
): boolean {
|
| 50 |
+
const state = get(ctx.state);
|
| 51 |
+
const selected_header = state.ui_state.selected_header;
|
| 52 |
+
const header_edit = state.ui_state.header_edit;
|
| 53 |
+
const headers = ctx.headers || [];
|
| 54 |
+
|
| 55 |
+
if (selected_header === false || header_edit !== false) return false;
|
| 56 |
+
|
| 57 |
+
switch (event.key) {
|
| 58 |
+
case "ArrowDown":
|
| 59 |
+
ctx.actions.set_selected_header(false);
|
| 60 |
+
ctx.actions.set_selected([0, selected_header as number]);
|
| 61 |
+
ctx.actions.set_selected_cells([[0, selected_header as number]]);
|
| 62 |
+
return true;
|
| 63 |
+
case "ArrowLeft":
|
| 64 |
+
ctx.actions.set_selected_header(
|
| 65 |
+
selected_header > 0 ? selected_header - 1 : selected_header
|
| 66 |
+
);
|
| 67 |
+
return true;
|
| 68 |
+
case "ArrowRight":
|
| 69 |
+
ctx.actions.set_selected_header(
|
| 70 |
+
selected_header < headers.length - 1
|
| 71 |
+
? selected_header + 1
|
| 72 |
+
: selected_header
|
| 73 |
+
);
|
| 74 |
+
return true;
|
| 75 |
+
case "Escape":
|
| 76 |
+
event.preventDefault();
|
| 77 |
+
ctx.actions.set_selected_header(false);
|
| 78 |
+
return true;
|
| 79 |
+
case "Enter":
|
| 80 |
+
event.preventDefault();
|
| 81 |
+
if (state.config.editable) {
|
| 82 |
+
ctx.actions.set_header_edit(selected_header);
|
| 83 |
+
}
|
| 84 |
+
return true;
|
| 85 |
+
}
|
| 86 |
+
return false;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// eslint-disable-next-line complexity
|
| 90 |
+
function handle_delete_operation(
|
| 91 |
+
event: KeyboardEvent,
|
| 92 |
+
ctx: DataFrameContext
|
| 93 |
+
): boolean {
|
| 94 |
+
if (!ctx.data || !ctx.headers || !ctx.els || !ctx.dispatch) return false;
|
| 95 |
+
|
| 96 |
+
const state = get(ctx.state);
|
| 97 |
+
if (!state.config.editable) return false;
|
| 98 |
+
if (event.key !== "Delete" && event.key !== "Backspace") return false;
|
| 99 |
+
|
| 100 |
+
const editing = state.ui_state.editing;
|
| 101 |
+
const selected_cells = state.ui_state.selected_cells;
|
| 102 |
+
|
| 103 |
+
const static_columns = state.config.static_columns || [];
|
| 104 |
+
if (selected_cells.some(([_, col]) => static_columns.includes(col))) {
|
| 105 |
+
return false;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (editing) {
|
| 109 |
+
const [row, col] = editing;
|
| 110 |
+
const input_el = ctx.els[ctx.data[row][col].id]?.input;
|
| 111 |
+
if (input_el && input_el.selectionStart !== input_el.selectionEnd) {
|
| 112 |
+
return false;
|
| 113 |
+
}
|
| 114 |
+
if (
|
| 115 |
+
event.key === "Delete" &&
|
| 116 |
+
input_el?.selectionStart !== input_el?.value.length
|
| 117 |
+
) {
|
| 118 |
+
return false;
|
| 119 |
+
}
|
| 120 |
+
if (event.key === "Backspace" && input_el?.selectionStart !== 0) {
|
| 121 |
+
return false;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
event.preventDefault();
|
| 126 |
+
if (selected_cells.length > 0) {
|
| 127 |
+
const new_data = handle_delete_key(ctx.data, selected_cells);
|
| 128 |
+
ctx.dispatch("change", {
|
| 129 |
+
data: new_data.map((row) => row.map((cell) => cell.value)),
|
| 130 |
+
headers: ctx.headers.map((h) => h.value),
|
| 131 |
+
metadata: null
|
| 132 |
+
});
|
| 133 |
+
}
|
| 134 |
+
return true;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
function handle_arrow_keys(
|
| 138 |
+
event: KeyboardEvent,
|
| 139 |
+
ctx: DataFrameContext,
|
| 140 |
+
i: number,
|
| 141 |
+
j: number
|
| 142 |
+
): boolean {
|
| 143 |
+
const state = get(ctx.state);
|
| 144 |
+
const editing = state.ui_state.editing;
|
| 145 |
+
const selected_cells = state.ui_state.selected_cells;
|
| 146 |
+
|
| 147 |
+
if (editing) return false;
|
| 148 |
+
if (!ctx.data) return false;
|
| 149 |
+
|
| 150 |
+
event.preventDefault();
|
| 151 |
+
|
| 152 |
+
const next_coords = ctx.actions.move_cursor(event, [i, j], ctx.data);
|
| 153 |
+
if (next_coords) {
|
| 154 |
+
if (event.shiftKey) {
|
| 155 |
+
ctx.actions.set_selected_cells(
|
| 156 |
+
ctx.actions.get_range_selection(
|
| 157 |
+
selected_cells.length > 0 ? selected_cells[0] : [i, j],
|
| 158 |
+
next_coords
|
| 159 |
+
)
|
| 160 |
+
);
|
| 161 |
+
ctx.actions.set_editing(false);
|
| 162 |
+
} else {
|
| 163 |
+
ctx.actions.set_selected_cells([next_coords]);
|
| 164 |
+
ctx.actions.set_editing(false);
|
| 165 |
+
}
|
| 166 |
+
ctx.actions.set_selected(next_coords);
|
| 167 |
+
} else if (next_coords === false && event.key === "ArrowUp" && i === 0) {
|
| 168 |
+
ctx.actions.set_selected_header(j);
|
| 169 |
+
ctx.actions.set_selected(false);
|
| 170 |
+
ctx.actions.set_selected_cells([]);
|
| 171 |
+
ctx.actions.set_editing(false);
|
| 172 |
+
}
|
| 173 |
+
return true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
async function handle_enter_key(
|
| 177 |
+
event: KeyboardEvent,
|
| 178 |
+
ctx: DataFrameContext,
|
| 179 |
+
i: number,
|
| 180 |
+
j: number
|
| 181 |
+
): Promise<boolean> {
|
| 182 |
+
if (!ctx.data || !ctx.els) return false;
|
| 183 |
+
|
| 184 |
+
const state = get(ctx.state);
|
| 185 |
+
if (!state.config.editable) return false;
|
| 186 |
+
|
| 187 |
+
const editing = state.ui_state.editing;
|
| 188 |
+
if (editing && event.shiftKey) return false;
|
| 189 |
+
|
| 190 |
+
event.preventDefault();
|
| 191 |
+
|
| 192 |
+
if (editing && dequal(editing, [i, j])) {
|
| 193 |
+
const cell_id = ctx.data[i][j].id;
|
| 194 |
+
const input_el = ctx.els[cell_id]?.input;
|
| 195 |
+
if (input_el) {
|
| 196 |
+
await save_cell_value(input_el.value, ctx, i, j);
|
| 197 |
+
}
|
| 198 |
+
ctx.actions.set_editing(false);
|
| 199 |
+
await tick();
|
| 200 |
+
ctx.parent_element?.focus();
|
| 201 |
+
} else {
|
| 202 |
+
ctx.actions.set_editing([i, j]);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
return true;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
function handle_tab_key(
|
| 209 |
+
event: KeyboardEvent,
|
| 210 |
+
ctx: DataFrameContext,
|
| 211 |
+
i: number,
|
| 212 |
+
j: number
|
| 213 |
+
): boolean {
|
| 214 |
+
if (!ctx.data) return false;
|
| 215 |
+
|
| 216 |
+
event.preventDefault();
|
| 217 |
+
ctx.actions.set_editing(false);
|
| 218 |
+
const next_cell = ctx.actions.get_next_cell_coordinates(
|
| 219 |
+
[i, j],
|
| 220 |
+
ctx.data,
|
| 221 |
+
event.shiftKey
|
| 222 |
+
);
|
| 223 |
+
if (next_cell) {
|
| 224 |
+
ctx.actions.set_selected_cells([next_cell]);
|
| 225 |
+
ctx.actions.set_selected(next_cell);
|
| 226 |
+
if (get(ctx.state).config.editable) {
|
| 227 |
+
ctx.actions.set_editing(next_cell);
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
return true;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function handle_default_key(
|
| 234 |
+
event: KeyboardEvent,
|
| 235 |
+
ctx: DataFrameContext,
|
| 236 |
+
i: number,
|
| 237 |
+
j: number
|
| 238 |
+
): boolean {
|
| 239 |
+
const state = get(ctx.state);
|
| 240 |
+
if (!state.config.editable) return false;
|
| 241 |
+
|
| 242 |
+
const editing = state.ui_state.editing;
|
| 243 |
+
|
| 244 |
+
if (event.key.length === 1 && (!editing || !dequal(editing, [i, j]))) {
|
| 245 |
+
ctx.actions.set_editing([i, j]);
|
| 246 |
+
return true;
|
| 247 |
+
}
|
| 248 |
+
return false;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
async function handle_cell_navigation(
|
| 252 |
+
event: KeyboardEvent,
|
| 253 |
+
ctx: DataFrameContext
|
| 254 |
+
): Promise<boolean> {
|
| 255 |
+
if (!ctx.data) return false;
|
| 256 |
+
|
| 257 |
+
const state = get(ctx.state);
|
| 258 |
+
const selected = state.ui_state.selected;
|
| 259 |
+
const selected_cells = state.ui_state.selected_cells;
|
| 260 |
+
|
| 261 |
+
if (!selected) return false;
|
| 262 |
+
if (event.key === "c" && (event.metaKey || event.ctrlKey)) {
|
| 263 |
+
event.preventDefault();
|
| 264 |
+
if (selected_cells.length > 0) {
|
| 265 |
+
await copy_table_data(ctx.data, selected_cells);
|
| 266 |
+
}
|
| 267 |
+
ctx.actions.set_copy_flash(true);
|
| 268 |
+
return true;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
const [i, j] = selected;
|
| 272 |
+
|
| 273 |
+
switch (event.key) {
|
| 274 |
+
case "ArrowRight":
|
| 275 |
+
case "ArrowLeft":
|
| 276 |
+
case "ArrowDown":
|
| 277 |
+
case "ArrowUp":
|
| 278 |
+
return handle_arrow_keys(event, ctx, i, j);
|
| 279 |
+
case "Escape":
|
| 280 |
+
if (!state.config.editable) return false;
|
| 281 |
+
event.preventDefault();
|
| 282 |
+
ctx.actions.set_editing(false);
|
| 283 |
+
tick().then(() => {
|
| 284 |
+
if (ctx.parent_element) {
|
| 285 |
+
ctx.parent_element.focus();
|
| 286 |
+
}
|
| 287 |
+
});
|
| 288 |
+
|
| 289 |
+
return true;
|
| 290 |
+
case "Enter":
|
| 291 |
+
return await handle_enter_key(event, ctx, i, j);
|
| 292 |
+
case "Tab":
|
| 293 |
+
return handle_tab_key(event, ctx, i, j);
|
| 294 |
+
case "Delete":
|
| 295 |
+
case "Backspace":
|
| 296 |
+
return handle_delete_operation(event, ctx);
|
| 297 |
+
default:
|
| 298 |
+
return handle_default_key(event, ctx, i, j);
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
export async function handle_keydown(
|
| 303 |
+
event: KeyboardEvent,
|
| 304 |
+
context: DataFrameContext
|
| 305 |
+
): Promise<void> {
|
| 306 |
+
if (handle_header_navigation(event, context)) return;
|
| 307 |
+
if (handle_delete_operation(event, context)) return;
|
| 308 |
+
await handle_cell_navigation(event, context);
|
| 309 |
+
}
|
5.49.1/dataframe/shared/utils/menu_utils.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function toggle_header_menu(
|
| 2 |
+
event: MouseEvent,
|
| 3 |
+
col: number,
|
| 4 |
+
active_header_menu: { col: number; x: number; y: number } | null,
|
| 5 |
+
set_active_header_menu: (
|
| 6 |
+
menu: { col: number; x: number; y: number } | null
|
| 7 |
+
) => void
|
| 8 |
+
): void {
|
| 9 |
+
event.stopPropagation();
|
| 10 |
+
if (active_header_menu && active_header_menu.col === col) {
|
| 11 |
+
set_active_header_menu(null);
|
| 12 |
+
} else {
|
| 13 |
+
const header = (event.target as HTMLElement).closest("th");
|
| 14 |
+
if (header) {
|
| 15 |
+
const rect = header.getBoundingClientRect();
|
| 16 |
+
set_active_header_menu({ col, x: rect.right, y: rect.bottom });
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function toggle_cell_menu(
|
| 22 |
+
event: MouseEvent,
|
| 23 |
+
row: number,
|
| 24 |
+
col: number,
|
| 25 |
+
active_cell_menu: { row: number; col: number; x: number; y: number } | null,
|
| 26 |
+
set_active_cell_menu: (
|
| 27 |
+
menu: { row: number; col: number; x: number; y: number } | null
|
| 28 |
+
) => void
|
| 29 |
+
): void {
|
| 30 |
+
event.stopPropagation();
|
| 31 |
+
if (
|
| 32 |
+
active_cell_menu &&
|
| 33 |
+
active_cell_menu.row === row &&
|
| 34 |
+
active_cell_menu.col === col
|
| 35 |
+
) {
|
| 36 |
+
set_active_cell_menu(null);
|
| 37 |
+
} else {
|
| 38 |
+
const cell = (event.target as HTMLElement).closest("td");
|
| 39 |
+
if (cell) {
|
| 40 |
+
const rect = cell.getBoundingClientRect();
|
| 41 |
+
set_active_cell_menu({ row, col, x: rect.right, y: rect.bottom });
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
export function add_row_at(
|
| 47 |
+
index: number,
|
| 48 |
+
position: "above" | "below",
|
| 49 |
+
add_row: (index?: number) => void,
|
| 50 |
+
clear_menus: () => void
|
| 51 |
+
): void {
|
| 52 |
+
const row_index = position === "above" ? index : index + 1;
|
| 53 |
+
add_row(row_index);
|
| 54 |
+
clear_menus();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
export function add_col_at(
|
| 58 |
+
index: number,
|
| 59 |
+
position: "left" | "right",
|
| 60 |
+
add_col: (index?: number) => void,
|
| 61 |
+
clear_menus: () => void
|
| 62 |
+
): void {
|
| 63 |
+
const col_index = position === "left" ? index : index + 1;
|
| 64 |
+
add_col(col_index);
|
| 65 |
+
clear_menus();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export function delete_row_at(
|
| 69 |
+
index: number,
|
| 70 |
+
delete_row: (index: number) => void,
|
| 71 |
+
clear_menus: () => void
|
| 72 |
+
): void {
|
| 73 |
+
delete_row(index);
|
| 74 |
+
clear_menus();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
export function delete_col_at(
|
| 78 |
+
index: number,
|
| 79 |
+
delete_col: (index: number) => void,
|
| 80 |
+
clear_menus: () => void
|
| 81 |
+
): void {
|
| 82 |
+
delete_col(index);
|
| 83 |
+
clear_menus();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
export function toggle_header_button(
|
| 87 |
+
col: number,
|
| 88 |
+
active_button: { type: "header" | "cell"; row?: number; col: number } | null,
|
| 89 |
+
set_active_button: (
|
| 90 |
+
button: { type: "header" | "cell"; row?: number; col: number } | null
|
| 91 |
+
) => void
|
| 92 |
+
): void {
|
| 93 |
+
set_active_button(
|
| 94 |
+
active_button?.type === "header" && active_button.col === col
|
| 95 |
+
? null
|
| 96 |
+
: { type: "header", col }
|
| 97 |
+
);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
export function toggle_cell_button(
|
| 101 |
+
row: number,
|
| 102 |
+
col: number,
|
| 103 |
+
active_button: { type: "header" | "cell"; row?: number; col: number } | null,
|
| 104 |
+
set_active_button: (
|
| 105 |
+
button: { type: "header" | "cell"; row?: number; col: number } | null
|
| 106 |
+
) => void
|
| 107 |
+
): void {
|
| 108 |
+
set_active_button(
|
| 109 |
+
active_button?.type === "cell" &&
|
| 110 |
+
active_button.row === row &&
|
| 111 |
+
active_button.col === col
|
| 112 |
+
? null
|
| 113 |
+
: { type: "cell", row, col }
|
| 114 |
+
);
|
| 115 |
+
}
|
5.49.1/dataframe/shared/utils/selection_utils.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { CellCoordinate, CellValue } from "./../types";
|
| 2 |
+
|
| 3 |
+
export type CellData = { id: string; value: CellValue };
|
| 4 |
+
|
| 5 |
+
export function is_cell_in_selection(
|
| 6 |
+
coords: [number, number],
|
| 7 |
+
selected_cells: [number, number][]
|
| 8 |
+
): boolean {
|
| 9 |
+
const [row, col] = coords;
|
| 10 |
+
return selected_cells.some(([r, c]) => r === row && c === col);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export function is_cell_selected(
|
| 14 |
+
cell: CellCoordinate,
|
| 15 |
+
selected_cells: CellCoordinate[]
|
| 16 |
+
): string {
|
| 17 |
+
const [row, col] = cell;
|
| 18 |
+
if (!selected_cells.some(([r, c]) => r === row && c === col)) return "";
|
| 19 |
+
|
| 20 |
+
const up = selected_cells.some(([r, c]) => r === row - 1 && c === col);
|
| 21 |
+
const down = selected_cells.some(([r, c]) => r === row + 1 && c === col);
|
| 22 |
+
const left = selected_cells.some(([r, c]) => r === row && c === col - 1);
|
| 23 |
+
const right = selected_cells.some(([r, c]) => r === row && c === col + 1);
|
| 24 |
+
|
| 25 |
+
return `cell-selected${up ? " no-top" : ""}${down ? " no-bottom" : ""}${left ? " no-left" : ""}${right ? " no-right" : ""}`;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
export function get_range_selection(
|
| 29 |
+
start: CellCoordinate,
|
| 30 |
+
end: CellCoordinate
|
| 31 |
+
): CellCoordinate[] {
|
| 32 |
+
const [start_row, start_col] = start;
|
| 33 |
+
const [end_row, end_col] = end;
|
| 34 |
+
const min_row = Math.min(start_row, end_row);
|
| 35 |
+
const max_row = Math.max(start_row, end_row);
|
| 36 |
+
const min_col = Math.min(start_col, end_col);
|
| 37 |
+
const max_col = Math.max(start_col, end_col);
|
| 38 |
+
|
| 39 |
+
const cells: CellCoordinate[] = [];
|
| 40 |
+
// Add the start cell as the "anchor" cell so that when
|
| 41 |
+
// we press shift+arrow keys, the selection will always
|
| 42 |
+
// include the anchor cell.
|
| 43 |
+
cells.push(start);
|
| 44 |
+
|
| 45 |
+
for (let i = min_row; i <= max_row; i++) {
|
| 46 |
+
for (let j = min_col; j <= max_col; j++) {
|
| 47 |
+
if (i === start_row && j === start_col) continue;
|
| 48 |
+
cells.push([i, j]);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
return cells;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
export function handle_selection(
|
| 55 |
+
current: CellCoordinate,
|
| 56 |
+
selected_cells: CellCoordinate[],
|
| 57 |
+
event: { shiftKey: boolean; metaKey: boolean; ctrlKey: boolean }
|
| 58 |
+
): CellCoordinate[] {
|
| 59 |
+
if (event.shiftKey && selected_cells.length > 0) {
|
| 60 |
+
return get_range_selection(
|
| 61 |
+
selected_cells[selected_cells.length - 1],
|
| 62 |
+
current
|
| 63 |
+
);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (event.metaKey || event.ctrlKey) {
|
| 67 |
+
const is_cell_match = ([r, c]: CellCoordinate): boolean =>
|
| 68 |
+
r === current[0] && c === current[1];
|
| 69 |
+
const index = selected_cells.findIndex(is_cell_match);
|
| 70 |
+
return index === -1
|
| 71 |
+
? [...selected_cells, current]
|
| 72 |
+
: selected_cells.filter((_, i) => i !== index);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return [current];
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
export function handle_delete_key(
|
| 79 |
+
data: CellData[][],
|
| 80 |
+
selected_cells: CellCoordinate[]
|
| 81 |
+
): CellData[][] {
|
| 82 |
+
const new_data = data.map((row) => [...row]);
|
| 83 |
+
selected_cells.forEach(([row, col]) => {
|
| 84 |
+
if (new_data[row] && new_data[row][col]) {
|
| 85 |
+
new_data[row][col] = { ...new_data[row][col], value: "" };
|
| 86 |
+
}
|
| 87 |
+
});
|
| 88 |
+
return new_data;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
export function should_show_cell_menu(
|
| 92 |
+
cell: CellCoordinate,
|
| 93 |
+
selected_cells: CellCoordinate[],
|
| 94 |
+
editable: boolean
|
| 95 |
+
): boolean {
|
| 96 |
+
const [row, col] = cell;
|
| 97 |
+
return (
|
| 98 |
+
editable &&
|
| 99 |
+
selected_cells.length === 1 &&
|
| 100 |
+
selected_cells[0][0] === row &&
|
| 101 |
+
selected_cells[0][1] === col
|
| 102 |
+
);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
export function get_next_cell_coordinates(
|
| 106 |
+
current: CellCoordinate,
|
| 107 |
+
data: CellData[][],
|
| 108 |
+
shift_key: boolean
|
| 109 |
+
): CellCoordinate | false {
|
| 110 |
+
const [row, col] = current;
|
| 111 |
+
const direction = shift_key ? -1 : 1;
|
| 112 |
+
|
| 113 |
+
if (data[row]?.[col + direction]) {
|
| 114 |
+
return [row, col + direction];
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
const next_row = row + (direction > 0 ? 1 : 0);
|
| 118 |
+
const prev_row = row + (direction < 0 ? -1 : 0);
|
| 119 |
+
|
| 120 |
+
if (direction > 0 && data[next_row]?.[0]) {
|
| 121 |
+
return [next_row, 0];
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if (direction < 0 && data[prev_row]?.[data[0].length - 1]) {
|
| 125 |
+
return [prev_row, data[0].length - 1];
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
return false;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
export function move_cursor(
|
| 132 |
+
event: KeyboardEvent,
|
| 133 |
+
current_coords: CellCoordinate,
|
| 134 |
+
data: CellData[][]
|
| 135 |
+
): CellCoordinate | false {
|
| 136 |
+
const key = event.key as "ArrowRight" | "ArrowLeft" | "ArrowDown" | "ArrowUp";
|
| 137 |
+
const dir = {
|
| 138 |
+
ArrowRight: [0, 1],
|
| 139 |
+
ArrowLeft: [0, -1],
|
| 140 |
+
ArrowDown: [1, 0],
|
| 141 |
+
ArrowUp: [-1, 0]
|
| 142 |
+
}[key];
|
| 143 |
+
|
| 144 |
+
let i, j;
|
| 145 |
+
if (event.metaKey || event.ctrlKey) {
|
| 146 |
+
if (key === "ArrowRight") {
|
| 147 |
+
i = current_coords[0];
|
| 148 |
+
j = data[0].length - 1;
|
| 149 |
+
} else if (key === "ArrowLeft") {
|
| 150 |
+
i = current_coords[0];
|
| 151 |
+
j = 0;
|
| 152 |
+
} else if (key === "ArrowDown") {
|
| 153 |
+
i = data.length - 1;
|
| 154 |
+
j = current_coords[1];
|
| 155 |
+
} else if (key === "ArrowUp") {
|
| 156 |
+
i = 0;
|
| 157 |
+
j = current_coords[1];
|
| 158 |
+
} else {
|
| 159 |
+
return false;
|
| 160 |
+
}
|
| 161 |
+
} else {
|
| 162 |
+
i = current_coords[0] + dir[0];
|
| 163 |
+
j = current_coords[1] + dir[1];
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
if (i < 0 && j <= 0) {
|
| 167 |
+
return false;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
const is_data = data[i]?.[j];
|
| 171 |
+
if (is_data) {
|
| 172 |
+
return [i, j];
|
| 173 |
+
}
|
| 174 |
+
return false;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
export function get_current_indices(
|
| 178 |
+
id: string,
|
| 179 |
+
data: CellData[][]
|
| 180 |
+
): [number, number] {
|
| 181 |
+
return data.reduce(
|
| 182 |
+
(acc, arr, i) => {
|
| 183 |
+
const j = arr.reduce(
|
| 184 |
+
(_acc, _data, k) => (id === _data.id ? k : _acc),
|
| 185 |
+
-1
|
| 186 |
+
);
|
| 187 |
+
return j === -1 ? acc : [i, j];
|
| 188 |
+
},
|
| 189 |
+
[-1, -1]
|
| 190 |
+
);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
export function handle_click_outside(
|
| 194 |
+
event: Event,
|
| 195 |
+
parent: HTMLElement
|
| 196 |
+
): boolean {
|
| 197 |
+
const [trigger] = event.composedPath() as HTMLElement[];
|
| 198 |
+
return !parent.contains(trigger);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
export function select_column(data: any[][], col: number): CellCoordinate[] {
|
| 202 |
+
return Array.from({ length: data.length }, (_, i) => [i, col]);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
export function select_row(data: any[][], row: number): CellCoordinate[] {
|
| 206 |
+
return Array.from({ length: data[0].length }, (_, i) => [row, i]);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
export function calculate_selection_positions(
|
| 210 |
+
selected: CellCoordinate,
|
| 211 |
+
data: { id: string; value: CellValue }[][],
|
| 212 |
+
els: Record<string, { cell: HTMLTableCellElement | null }>,
|
| 213 |
+
parent: HTMLElement,
|
| 214 |
+
table: HTMLElement
|
| 215 |
+
): { col_pos: string; row_pos: string | undefined } {
|
| 216 |
+
const [row, col] = selected;
|
| 217 |
+
if (!data[row]?.[col]) {
|
| 218 |
+
return { col_pos: "0px", row_pos: undefined };
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
const cell_id = data[row][col].id;
|
| 222 |
+
const cell_el = els[cell_id]?.cell;
|
| 223 |
+
|
| 224 |
+
if (!cell_el) {
|
| 225 |
+
return { col_pos: "0px", row_pos: undefined };
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
const cell_rect = cell_el.getBoundingClientRect();
|
| 229 |
+
const table_rect = table.getBoundingClientRect();
|
| 230 |
+
const col_pos = `${cell_rect.left - table_rect.left + cell_rect.width / 2}px`;
|
| 231 |
+
const row_pos = `${cell_rect.top - table_rect.top + cell_rect.height / 2}px`;
|
| 232 |
+
|
| 233 |
+
return { col_pos, row_pos };
|
| 234 |
+
}
|
5.49.1/dataframe/shared/utils/sort_utils.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Headers, CellValue } from "../types";
|
| 2 |
+
import { sort_table_data } from "./table_utils";
|
| 3 |
+
|
| 4 |
+
export type SortDirection = "asc" | "desc";
|
| 5 |
+
|
| 6 |
+
export function get_sort_status(
|
| 7 |
+
name: string,
|
| 8 |
+
sort_columns: { col: number; direction: SortDirection }[],
|
| 9 |
+
headers: Headers
|
| 10 |
+
): "none" | "asc" | "desc" {
|
| 11 |
+
if (!sort_columns.length) return "none";
|
| 12 |
+
|
| 13 |
+
const sort_item = sort_columns.find((item) => {
|
| 14 |
+
const col = item.col;
|
| 15 |
+
if (col < 0 || col >= headers.length) return false;
|
| 16 |
+
return headers[col] === name;
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
if (!sort_item) return "none";
|
| 20 |
+
return sort_item.direction;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export function sort_data(
|
| 24 |
+
data: { id: string; value: CellValue }[][],
|
| 25 |
+
sort_columns: { col: number; direction: SortDirection }[]
|
| 26 |
+
): number[] {
|
| 27 |
+
if (!data || !data.length || !data[0]) {
|
| 28 |
+
return [];
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if (sort_columns.length > 0) {
|
| 32 |
+
const row_indices = [...Array(data.length)].map((_, i) => i);
|
| 33 |
+
row_indices.sort((row_a_idx, row_b_idx) => {
|
| 34 |
+
const row_a = data[row_a_idx];
|
| 35 |
+
const row_b = data[row_b_idx];
|
| 36 |
+
|
| 37 |
+
for (const { col: sort_by, direction } of sort_columns) {
|
| 38 |
+
if (
|
| 39 |
+
!row_a ||
|
| 40 |
+
!row_b ||
|
| 41 |
+
sort_by < 0 ||
|
| 42 |
+
sort_by >= row_a.length ||
|
| 43 |
+
sort_by >= row_b.length ||
|
| 44 |
+
!row_a[sort_by] ||
|
| 45 |
+
!row_b[sort_by]
|
| 46 |
+
) {
|
| 47 |
+
continue;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
const val_a = row_a[sort_by].value;
|
| 51 |
+
const val_b = row_b[sort_by].value;
|
| 52 |
+
const comparison = val_a < val_b ? -1 : val_a > val_b ? 1 : 0;
|
| 53 |
+
|
| 54 |
+
if (comparison !== 0) {
|
| 55 |
+
return direction === "asc" ? comparison : -comparison;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
return 0;
|
| 60 |
+
});
|
| 61 |
+
return row_indices;
|
| 62 |
+
}
|
| 63 |
+
return [...Array(data.length)].map((_, i) => i);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
export function sort_data_and_preserve_selection(
|
| 67 |
+
data: { id: string; value: CellValue }[][],
|
| 68 |
+
display_value: string[][] | null,
|
| 69 |
+
styling: string[][] | null,
|
| 70 |
+
sort_columns: { col: number; direction: SortDirection }[],
|
| 71 |
+
selected: [number, number] | false,
|
| 72 |
+
get_current_indices: (
|
| 73 |
+
id: string,
|
| 74 |
+
data: { id: string; value: CellValue }[][]
|
| 75 |
+
) => [number, number]
|
| 76 |
+
): { data: typeof data; selected: [number, number] | false } {
|
| 77 |
+
let id = null;
|
| 78 |
+
if (selected && selected[0] in data && selected[1] in data[selected[0]]) {
|
| 79 |
+
id = data[selected[0]][selected[1]].id;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
sort_table_data(data, display_value, styling, sort_columns);
|
| 83 |
+
|
| 84 |
+
let new_selected = selected;
|
| 85 |
+
if (id) {
|
| 86 |
+
const [i, j] = get_current_indices(id, data);
|
| 87 |
+
new_selected = [i, j];
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return { data, selected: new_selected };
|
| 91 |
+
}
|
5.49.1/dataframe/shared/utils/table_utils.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {
|
| 15 |
+
return `cell-${row}-${col}`;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
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
|
| 113 |
+
): Promise<void> {
|
| 114 |
+
if (!data || !data.length) return;
|
| 115 |
+
|
| 116 |
+
const cells_to_copy =
|
| 117 |
+
selected_cells ||
|
| 118 |
+
data.flatMap((row, r) => row.map((_, c) => [r, c] as [number, number]));
|
| 119 |
+
|
| 120 |
+
const csv = cells_to_copy.reduce(
|
| 121 |
+
(acc: { [key: string]: { [key: string]: string } }, [row, col]) => {
|
| 122 |
+
acc[row] = acc[row] || {};
|
| 123 |
+
const value = String(data[row][col].value);
|
| 124 |
+
acc[row][col] =
|
| 125 |
+
value.includes(",") || value.includes('"') || value.includes("\n")
|
| 126 |
+
? `"${value.replace(/"/g, '""')}"`
|
| 127 |
+
: value;
|
| 128 |
+
return acc;
|
| 129 |
+
},
|
| 130 |
+
{}
|
| 131 |
+
);
|
| 132 |
+
|
| 133 |
+
const rows = Object.keys(csv).sort((a, b) => +a - +b);
|
| 134 |
+
if (!rows.length) return;
|
| 135 |
+
|
| 136 |
+
const cols = Object.keys(csv[rows[0]]).sort((a, b) => +a - +b);
|
| 137 |
+
const text = rows
|
| 138 |
+
.map((r) => cols.map((c) => csv[r][c] || "").join(","))
|
| 139 |
+
.join("\n");
|
| 140 |
+
|
| 141 |
+
try {
|
| 142 |
+
await navigator.clipboard.writeText(text);
|
| 143 |
+
} catch (err) {
|
| 144 |
+
throw new Error("Failed to copy to clipboard: " + (err as Error).message);
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// File Import/Export
|
| 149 |
+
export function guess_delimiter(
|
| 150 |
+
text: string,
|
| 151 |
+
possibleDelimiters: string[]
|
| 152 |
+
): string[] {
|
| 153 |
+
return possibleDelimiters.filter(weedOut);
|
| 154 |
+
|
| 155 |
+
function weedOut(delimiter: string): boolean {
|
| 156 |
+
var cache = -1;
|
| 157 |
+
return text.split("\n").every(checkLength);
|
| 158 |
+
|
| 159 |
+
function checkLength(line: string): boolean {
|
| 160 |
+
if (!line) return true;
|
| 161 |
+
var length = line.split(delimiter).length;
|
| 162 |
+
if (cache < 0) cache = length;
|
| 163 |
+
return cache === length && length > 1;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
export function data_uri_to_blob(data_uri: string): Blob {
|
| 169 |
+
const byte_str = atob(data_uri.split(",")[1]);
|
| 170 |
+
const mime_str = data_uri.split(",")[0].split(":")[1].split(";")[0];
|
| 171 |
+
const ab = new ArrayBuffer(byte_str.length);
|
| 172 |
+
const ia = new Uint8Array(ab);
|
| 173 |
+
for (let i = 0; i < byte_str.length; i++) {
|
| 174 |
+
ia[i] = byte_str.charCodeAt(i);
|
| 175 |
+
}
|
| 176 |
+
return new Blob([ab], { type: mime_str });
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
export function handle_file_upload(
|
| 180 |
+
data_uri: string,
|
| 181 |
+
update_headers: (headers: Headers) => HeadersWithIDs[],
|
| 182 |
+
update_values: (values: CellValue[][]) => void
|
| 183 |
+
): void {
|
| 184 |
+
const blob = data_uri_to_blob(data_uri);
|
| 185 |
+
const reader = new FileReader();
|
| 186 |
+
reader.addEventListener("loadend", (e) => {
|
| 187 |
+
if (!e?.target?.result || typeof e.target.result !== "string") return;
|
| 188 |
+
const [delimiter] = guess_delimiter(e.target.result, [",", "\t"]);
|
| 189 |
+
const [head, ...rest] = dsvFormat(delimiter).parseRows(e.target.result);
|
| 190 |
+
update_headers(head);
|
| 191 |
+
update_values(rest);
|
| 192 |
+
});
|
| 193 |
+
reader.readAsText(blob);
|
| 194 |
+
}
|
5.49.1/dataframe/shared/utils/utils.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { CellValue } from "../types";
|
| 2 |
+
|
| 3 |
+
export type Headers = string[];
|
| 4 |
+
export type Data = CellValue[][];
|
| 5 |
+
|
| 6 |
+
export type Datatype =
|
| 7 |
+
| "str"
|
| 8 |
+
| "number"
|
| 9 |
+
| "bool"
|
| 10 |
+
| "date"
|
| 11 |
+
| "markdown"
|
| 12 |
+
| "html"
|
| 13 |
+
| "image";
|
| 14 |
+
|
| 15 |
+
export type Metadata = {
|
| 16 |
+
[key: string]: string[][] | null;
|
| 17 |
+
} | null;
|
| 18 |
+
export type HeadersWithIDs = { value: string; id: string }[];
|
| 19 |
+
export type DataframeValue = {
|
| 20 |
+
data: Data;
|
| 21 |
+
headers: Headers;
|
| 22 |
+
metadata?: Metadata;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Coerce a value to a given type.
|
| 27 |
+
* @param v - The value to coerce.
|
| 28 |
+
* @param t - The type to coerce to.
|
| 29 |
+
* @returns The coerced value.
|
| 30 |
+
*/
|
| 31 |
+
export function cast_value_to_type(v: any, t: Datatype): CellValue {
|
| 32 |
+
if (t === "number") {
|
| 33 |
+
const n = Number(v);
|
| 34 |
+
return isNaN(n) ? v : n;
|
| 35 |
+
}
|
| 36 |
+
if (t === "bool") {
|
| 37 |
+
if (typeof v === "boolean") return v;
|
| 38 |
+
if (typeof v === "number") return v !== 0;
|
| 39 |
+
const s = String(v).toLowerCase();
|
| 40 |
+
if (s === "true" || s === "1") return true;
|
| 41 |
+
if (s === "false" || s === "0") return false;
|
| 42 |
+
return v;
|
| 43 |
+
}
|
| 44 |
+
if (t === "date") {
|
| 45 |
+
const d = new Date(v);
|
| 46 |
+
return isNaN(d.getTime()) ? v : d.toISOString();
|
| 47 |
+
}
|
| 48 |
+
return v;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export interface EditData {
|
| 52 |
+
index: number | [number, number];
|
| 53 |
+
value: string;
|
| 54 |
+
previous_value: string;
|
| 55 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount } from "svelte";
|
| 3 |
+
import Table from "../shared/Table.svelte";
|
| 4 |
+
import type { Datatype, DataframeValue } from "../shared/utils/utils";
|
| 5 |
+
import type { I18nFormatter } from "@gradio/utils";
|
| 6 |
+
import { default_i18n } from "./default_i18n";
|
| 7 |
+
|
| 8 |
+
export let i18n: I18nFormatter | undefined = undefined;
|
| 9 |
+
const i18n_fn = (key: string | null | undefined): string => {
|
| 10 |
+
if (!key) return "";
|
| 11 |
+
if (typeof i18n === "function") return (i18n as any)(key);
|
| 12 |
+
if (i18n && typeof i18n === "object")
|
| 13 |
+
return (i18n as any)[key] ?? default_i18n[key] ?? key;
|
| 14 |
+
return default_i18n[key] ?? key;
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
export let value: DataframeValue = {
|
| 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 show_copy_button = false;
|
| 28 |
+
export let show_fullscreen_button = false;
|
| 29 |
+
export let wrap = false;
|
| 30 |
+
export let line_breaks = true;
|
| 31 |
+
export let column_widths: string[] = [];
|
| 32 |
+
export let max_chars: number | undefined = undefined;
|
| 33 |
+
export let pinned_columns = 0;
|
| 34 |
+
export let static_columns: (string | number)[] = [];
|
| 35 |
+
export let fullscreen = false;
|
| 36 |
+
export let label: string | null = null;
|
| 37 |
+
export let show_label = true;
|
| 38 |
+
export let latex_delimiters: any[] = [];
|
| 39 |
+
export let col_count: [number, "fixed" | "dynamic"] | undefined = undefined;
|
| 40 |
+
export let row_count: [number, "fixed" | "dynamic"] | undefined = undefined;
|
| 41 |
+
|
| 42 |
+
// mirrors default row count and column count logic in dataframe.py
|
| 43 |
+
$: resolved_row_count = (() => {
|
| 44 |
+
if (
|
| 45 |
+
row_count &&
|
| 46 |
+
Array.isArray(row_count) &&
|
| 47 |
+
row_count.length === 2 &&
|
| 48 |
+
typeof row_count[0] === "number" &&
|
| 49 |
+
(row_count[1] === "fixed" || row_count[1] === "dynamic")
|
| 50 |
+
) {
|
| 51 |
+
return row_count as [number, "fixed" | "dynamic"];
|
| 52 |
+
}
|
| 53 |
+
return [1, "dynamic"] as [number, "fixed" | "dynamic"];
|
| 54 |
+
})();
|
| 55 |
+
$: resolved_col_count = (() => {
|
| 56 |
+
if (
|
| 57 |
+
col_count &&
|
| 58 |
+
Array.isArray(col_count) &&
|
| 59 |
+
col_count.length === 2 &&
|
| 60 |
+
typeof col_count[0] === "number" &&
|
| 61 |
+
(col_count[1] === "fixed" || col_count[1] === "dynamic")
|
| 62 |
+
) {
|
| 63 |
+
return col_count as [number, "fixed" | "dynamic"];
|
| 64 |
+
}
|
| 65 |
+
const headerLength =
|
| 66 |
+
value && value.headers && typeof value.headers.length === "number"
|
| 67 |
+
? value.headers.length
|
| 68 |
+
: 3;
|
| 69 |
+
return [headerLength, "dynamic"] as [number, "fixed" | "dynamic"];
|
| 70 |
+
})();
|
| 71 |
+
$: if (
|
| 72 |
+
static_columns &&
|
| 73 |
+
static_columns.length > 0 &&
|
| 74 |
+
resolved_col_count[1] !== "fixed"
|
| 75 |
+
) {
|
| 76 |
+
resolved_col_count = [resolved_col_count[0], "fixed"];
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
let root = "";
|
| 80 |
+
|
| 81 |
+
onMount(() => {
|
| 82 |
+
const handler = (e: KeyboardEvent): void => {
|
| 83 |
+
if (e.key === "Escape") {
|
| 84 |
+
fullscreen = false;
|
| 85 |
+
}
|
| 86 |
+
};
|
| 87 |
+
window.addEventListener("keydown", handler);
|
| 88 |
+
return () => window.removeEventListener("keydown", handler);
|
| 89 |
+
});
|
| 90 |
+
</script>
|
| 91 |
+
|
| 92 |
+
<div class="gradio-dataframe-standalone" class:fullscreen>
|
| 93 |
+
<Table
|
| 94 |
+
values={value.data}
|
| 95 |
+
headers={value.headers}
|
| 96 |
+
display_value={value?.metadata?.display_value}
|
| 97 |
+
styling={value?.metadata?.styling}
|
| 98 |
+
{datatype}
|
| 99 |
+
editable={interactive}
|
| 100 |
+
{show_row_numbers}
|
| 101 |
+
{max_height}
|
| 102 |
+
{show_search}
|
| 103 |
+
{show_copy_button}
|
| 104 |
+
{show_fullscreen_button}
|
| 105 |
+
{wrap}
|
| 106 |
+
{line_breaks}
|
| 107 |
+
{column_widths}
|
| 108 |
+
{max_chars}
|
| 109 |
+
{pinned_columns}
|
| 110 |
+
{static_columns}
|
| 111 |
+
{fullscreen}
|
| 112 |
+
{label}
|
| 113 |
+
{show_label}
|
| 114 |
+
{latex_delimiters}
|
| 115 |
+
col_count={resolved_col_count}
|
| 116 |
+
row_count={resolved_row_count}
|
| 117 |
+
{root}
|
| 118 |
+
i18n={i18n_fn}
|
| 119 |
+
on:change={(e) => {
|
| 120 |
+
value.data = e.detail.data;
|
| 121 |
+
value.headers = e.detail.headers;
|
| 122 |
+
}}
|
| 123 |
+
on:blur
|
| 124 |
+
on:keydown
|
| 125 |
+
on:input
|
| 126 |
+
on:select
|
| 127 |
+
on:fullscreen={(e) => (fullscreen = e.detail)}
|
| 128 |
+
upload={async () => null}
|
| 129 |
+
stream_handler={() => new EventSource("about:blank")}
|
| 130 |
+
/>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<style>
|
| 134 |
+
.gradio-dataframe-standalone {
|
| 135 |
+
--gr-df-font-mono: unset;
|
| 136 |
+
--gr-df-font-sans: unset;
|
| 137 |
+
--gr-df-table-bg-even: unset;
|
| 138 |
+
--gr-df-table-bg-odd: unset;
|
| 139 |
+
--gr-df-table-border: unset;
|
| 140 |
+
--gr-df-table-radius: unset;
|
| 141 |
+
|
| 142 |
+
--gr-df-table-text: unset;
|
| 143 |
+
--gr-df-accent: unset;
|
| 144 |
+
--gr-df-accent-soft: unset;
|
| 145 |
+
|
| 146 |
+
--gr-df-input-background-fill: unset;
|
| 147 |
+
--gr-df-input-background-fill-focus: unset;
|
| 148 |
+
--gr-df-input-background-fill-hover: unset;
|
| 149 |
+
--gr-df-input-border-color: unset;
|
| 150 |
+
--gr-df-input-border-color-focus: unset;
|
| 151 |
+
--gr-df-input-placeholder-color: unset;
|
| 152 |
+
--gr-df-input-radius: unset;
|
| 153 |
+
--gr-df-input-text-size: unset;
|
| 154 |
+
--gr-df-copied-cell-color: unset;
|
| 155 |
+
|
| 156 |
+
--gr-df-checkbox-border-color: unset;
|
| 157 |
+
--gr-df-checkbox-background-color: unset;
|
| 158 |
+
--gr-df-checkbox-border-color-focus: unset;
|
| 159 |
+
--gr-df-checkbox-shadow: unset;
|
| 160 |
+
--gr-df-checkbox-border-radius: unset;
|
| 161 |
+
|
| 162 |
+
/* Dataframe-scoped defaults (only used as fallbacks) */
|
| 163 |
+
--df-font-mono: var(
|
| 164 |
+
--gr-df-font-mono,
|
| 165 |
+
"IBM Plex Mono",
|
| 166 |
+
ui-monospace,
|
| 167 |
+
Consolas,
|
| 168 |
+
monospace
|
| 169 |
+
);
|
| 170 |
+
--df-font-sans: var(
|
| 171 |
+
--gr-df-font-sans,
|
| 172 |
+
"Source Sans Pro",
|
| 173 |
+
ui-sans-serif,
|
| 174 |
+
system-ui,
|
| 175 |
+
sans-serif
|
| 176 |
+
);
|
| 177 |
+
--df-table-radius: var(--df-radius-sm, 4px);
|
| 178 |
+
--df-border-color-primary: var(--gr-df-table-border, var(--df-neutral-200));
|
| 179 |
+
--df-background-fill-primary: #ffffff;
|
| 180 |
+
--df-background-fill-secondary: #f8fafc;
|
| 181 |
+
--df-color-accent: #7c3aed;
|
| 182 |
+
--df-color-accent-soft: #f3e8ff;
|
| 183 |
+
--df-color-accent-copied: #faf5ff;
|
| 184 |
+
--df-body-text-color: #111827;
|
| 185 |
+
--df-block-background-fill: #ffffff;
|
| 186 |
+
--df-block-radius: var(--df-radius-sm, 4px);
|
| 187 |
+
--df-table-even-background-fill: #ffffff;
|
| 188 |
+
--df-table-odd-background-fill: #f9fafb;
|
| 189 |
+
|
| 190 |
+
--df-background-fill-primary-dark: var(--df-neutral-950, #0f0f11);
|
| 191 |
+
--df-background-fill-secondary-dark: var(--df-neutral-900, #18181b);
|
| 192 |
+
--df-body-text-color-dark: var(--df-neutral-100, #f4f4f5);
|
| 193 |
+
--df-block-background-fill-dark: var(--df-neutral-800, #27272a);
|
| 194 |
+
--df-table-even-background-fill-dark: var(--df-neutral-950, #0f0f11);
|
| 195 |
+
--df-table-odd-background-fill-dark: var(--df-neutral-900, #18181b);
|
| 196 |
+
--df-border-color-primary-dark: var(--df-neutral-700, #3f3f46);
|
| 197 |
+
--df-color-accent-dark: var(--df-primary-600, #ea580c);
|
| 198 |
+
--df-color-accent-soft-dark: var(--df-neutral-700, #3f3f46);
|
| 199 |
+
--df-radius-sm: 4px;
|
| 200 |
+
--df-size-1: 4px;
|
| 201 |
+
--df-size-2: 8px;
|
| 202 |
+
--df-size-4: 16px;
|
| 203 |
+
--df-size-6: 24px;
|
| 204 |
+
--df-size-8: 32px;
|
| 205 |
+
--df-size-12: 48px;
|
| 206 |
+
--df-size-3: 12px;
|
| 207 |
+
--df-size-5: 20px;
|
| 208 |
+
--df-size-7: 28px;
|
| 209 |
+
--df-size-9: 36px;
|
| 210 |
+
--df-size-10: 40px;
|
| 211 |
+
--df-size-11: 44px;
|
| 212 |
+
--df-size-14: 56px;
|
| 213 |
+
--df-size-px: 1px;
|
| 214 |
+
--df-size-full: 100%;
|
| 215 |
+
--df-text-sm: 12px;
|
| 216 |
+
--df-size-0-5: 2px;
|
| 217 |
+
--df-size-1-5: 6px;
|
| 218 |
+
--df-size-2-5: 10px;
|
| 219 |
+
--df-text-md: 14px;
|
| 220 |
+
--df-text-lg: 16px;
|
| 221 |
+
--df-radius-100: 100%;
|
| 222 |
+
--df-radius-xs: 2px;
|
| 223 |
+
--df-radius-sm: 4px;
|
| 224 |
+
--df-radius-md: 6px;
|
| 225 |
+
--df-radius-lg: 8px;
|
| 226 |
+
--df-radius-xl: 12px;
|
| 227 |
+
--df-radius-2xl: 16px;
|
| 228 |
+
--df-radius-3xl: 22px;
|
| 229 |
+
--df-input-text-size: var(--df-text-md, 14px);
|
| 230 |
+
|
| 231 |
+
--df-primary-50: #fff7ed;
|
| 232 |
+
--df-primary-100: #ffedd5;
|
| 233 |
+
--df-primary-200: #fed7aa;
|
| 234 |
+
--df-primary-300: #fdba74;
|
| 235 |
+
--df-primary-400: #fb923c;
|
| 236 |
+
--df-primary-500: #f97316;
|
| 237 |
+
--df-primary-600: #ea580c;
|
| 238 |
+
|
| 239 |
+
--df-neutral-50: #fafafa;
|
| 240 |
+
--df-neutral-100: #f4f4f5;
|
| 241 |
+
--df-neutral-200: #e4e4e7;
|
| 242 |
+
--df-neutral-300: #d4d4d8;
|
| 243 |
+
--df-neutral-400: #bbbbc2;
|
| 244 |
+
--df-neutral-500: #71717a;
|
| 245 |
+
--df-neutral-600: #52525b;
|
| 246 |
+
--df-neutral-700: #3f3f46;
|
| 247 |
+
--df-neutral-800: #27272a;
|
| 248 |
+
--df-neutral-900: #18181b;
|
| 249 |
+
--df-neutral-950: #0f0f11;
|
| 250 |
+
|
| 251 |
+
/* Secondary palette (scoped) */
|
| 252 |
+
--df-secondary-50: #eff6ff;
|
| 253 |
+
--df-secondary-100: #dbeafe;
|
| 254 |
+
--df-secondary-200: #bfdbfe;
|
| 255 |
+
--df-secondary-300: #93c5fd;
|
| 256 |
+
--df-secondary-400: #60a5fa;
|
| 257 |
+
--df-secondary-500: #3b82f6;
|
| 258 |
+
|
| 259 |
+
--neutral-50: var(--df-neutral-50, #f9fafb);
|
| 260 |
+
--neutral-100: var(--df-neutral-100, #f3f4f6);
|
| 261 |
+
--neutral-200: var(--df-neutral-200, #e5e7eb);
|
| 262 |
+
--neutral-300: var(--df-neutral-300, #d1d5db);
|
| 263 |
+
--neutral-400: var(--df-neutral-400, #9ca3af);
|
| 264 |
+
--neutral-500: var(--df-neutral-500, #6b7280);
|
| 265 |
+
--neutral-600: var(--df-neutral-600, #4b5563);
|
| 266 |
+
--neutral-700: var(--df-neutral-700, #374151);
|
| 267 |
+
--neutral-800: var(--df-neutral-800, #1f2937);
|
| 268 |
+
--neutral-900: var(--df-neutral-900, #111827);
|
| 269 |
+
--neutral-950: var(--df-neutral-950, #0b0f19);
|
| 270 |
+
|
| 271 |
+
--secondary-50: var(--df-secondary-50, #eff6ff);
|
| 272 |
+
--secondary-100: var(--df-secondary-100, #dbeafe);
|
| 273 |
+
--secondary-200: var(--df-secondary-200, #bfdbfe);
|
| 274 |
+
|
| 275 |
+
--df-spacing-xxs: 1px;
|
| 276 |
+
--df-spacing-xs: 2px;
|
| 277 |
+
--df-spacing-sm: 4px;
|
| 278 |
+
--df-spacing-md: 6px;
|
| 279 |
+
--df-spacing-lg: 8px;
|
| 280 |
+
--df-spacing-xl: 10px;
|
| 281 |
+
--df-spacing-xxl: 16px;
|
| 282 |
+
|
| 283 |
+
--df-radius-xxs: 1px;
|
| 284 |
+
--df-radius-xxl: 22px;
|
| 285 |
+
|
| 286 |
+
--df-text-xxs: 9px;
|
| 287 |
+
--df-text-xs: 10px;
|
| 288 |
+
--df-text-xl: 22px;
|
| 289 |
+
--df-text-xxl: 26px;
|
| 290 |
+
|
| 291 |
+
--df-body-background-fill: var(
|
| 292 |
+
--df-background-fill-primary,
|
| 293 |
+
var(--background-fill-primary, #ffffff)
|
| 294 |
+
);
|
| 295 |
+
--df-body-text-color: var(--gr-df-table-text, --df-neutral-800);
|
| 296 |
+
--df-body-text-size: var(--df-text-md, 14px);
|
| 297 |
+
--df-body-text-weight: 400;
|
| 298 |
+
|
| 299 |
+
--df-color-accent: var(--df-primary-500, #f97316);
|
| 300 |
+
--df-color-accent-soft: var(--df-primary-50, #fff7ed);
|
| 301 |
+
--df-background-fill-primary: white;
|
| 302 |
+
--df-background-fill-secondary: var(--df-neutral-50, #f9fafb);
|
| 303 |
+
--df-border-color-accent: var(--df-primary-300, #fdba74);
|
| 304 |
+
--df-body-text-color-subdued: var(--df-neutral-400, #9ca3af);
|
| 305 |
+
--df-table-text-color: var(--df-body-text-color, #111827);
|
| 306 |
+
--df-shadow-drop: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
|
| 307 |
+
--df-shadow-drop-lg: 0 1px 3px 0 rgb(0 0 0 / 0.1),
|
| 308 |
+
0 1px 2px -1px rgb(0 0 0 / 0.1);
|
| 309 |
+
--df-shadow-inset: rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset;
|
| 310 |
+
--df-shadow-spread: 3px;
|
| 311 |
+
|
| 312 |
+
--df-bw-svt-p-top: 0px;
|
| 313 |
+
--df-bw-svt-p-bottom: 0px;
|
| 314 |
+
|
| 315 |
+
--df-border-color-secondary: var(--df-border-color-accent, #fdba74);
|
| 316 |
+
--df-shadow-md: 0 12px 16px -4px rgba(0, 0, 0, 0.1),
|
| 317 |
+
0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
| 318 |
+
|
| 319 |
+
--df-checkbox-border-radius: var(--df-radius-sm, 4px);
|
| 320 |
+
--df-checkbox-shadow: none;
|
| 321 |
+
--df-checkbox-border-color: var(--df-neutral-300, #d4d4d8);
|
| 322 |
+
--df-checkbox-background-color: var(--df-background-fill-primary, #ffffff);
|
| 323 |
+
--df-checkbox-background-color-selected: var(
|
| 324 |
+
--df-color-accent,
|
| 325 |
+
var(--color-accent)
|
| 326 |
+
);
|
| 327 |
+
--df-checkbox-border-color-focus: var(--df-color-accent, #f97316);
|
| 328 |
+
--df-button-transition: none;
|
| 329 |
+
--df-block-background-fill: var(--df-background-fill-primary, white);
|
| 330 |
+
--df-block-border-color: var(
|
| 331 |
+
--df-border-color-primary,
|
| 332 |
+
var(--df-neutral-200, #e5e7eb)
|
| 333 |
+
);
|
| 334 |
+
--df-block-border-width: 1px;
|
| 335 |
+
--df-input-text-size: 0.95rem;
|
| 336 |
+
--df-line-md: 1.5;
|
| 337 |
+
--df-line-lg: 1.75;
|
| 338 |
+
|
| 339 |
+
--df-input-background-fill: var(--df-background-fill-primary, #ffffff);
|
| 340 |
+
--df-input-background-fill-focus: var(
|
| 341 |
+
--df-input-background-fill,
|
| 342 |
+
var(--df-background-fill-primary, #ffffff)
|
| 343 |
+
);
|
| 344 |
+
--df-input-background-fill-hover: var(
|
| 345 |
+
--df-input-background-fill,
|
| 346 |
+
var(--df-background-fill-primary, #ffffff)
|
| 347 |
+
);
|
| 348 |
+
--df-input-border-color: var(--df-border-color-primary, #e5e7eb);
|
| 349 |
+
--df-input-border-color-focus: var(--secondary-300, #93c5fd);
|
| 350 |
+
--df-input-border-color-hover: var(
|
| 351 |
+
--df-input-border-color,
|
| 352 |
+
var(--df-border-color-primary, #e5e7eb)
|
| 353 |
+
);
|
| 354 |
+
--df-input-border-width: 1px;
|
| 355 |
+
--df-input-padding: var(--df-spacing-xl, 10px);
|
| 356 |
+
--df-input-placeholder-color: var(--neutral-400, #9ca3af);
|
| 357 |
+
--df-input-radius: var(--df-radius-sm, 4px);
|
| 358 |
+
--df-input-shadow: none;
|
| 359 |
+
--df-input-shadow-focus: 0 0 0 var(--shadow-spread, 3px)
|
| 360 |
+
var(--secondary-50, #eff6ff),
|
| 361 |
+
var(--shadow-inset, rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset);
|
| 362 |
+
|
| 363 |
+
--table-radius: var(--gr-df-table-radius, var(--df-table-radius, 4px));
|
| 364 |
+
--table-row-hover: var(--gr-df-table-row-hover, var(--color-accent-soft));
|
| 365 |
+
--cell-padding: var(--gr-df-cell-padding, var(--size-2));
|
| 366 |
+
--df-font-size: var(--gr-df-font-size, var(--text-md));
|
| 367 |
+
--background-fill-primary: var(--df-background-fill-primary, #ffffff);
|
| 368 |
+
--background-fill-primary-dark: var(
|
| 369 |
+
--df-background-fill-primary-dark,
|
| 370 |
+
var(--neutral-950, #0f0f11)
|
| 371 |
+
);
|
| 372 |
+
--background-fill-secondary: var(--df-background-fill-secondary, #f8fafc);
|
| 373 |
+
--background-fill-secondary-dark: var(
|
| 374 |
+
--df-background-fill-secondary-dark,
|
| 375 |
+
var(--neutral-900, #18181b)
|
| 376 |
+
);
|
| 377 |
+
--color-accent: var(--gr-df-accent, var(--df-color-accent, #7c3aed));
|
| 378 |
+
--color-accent-soft: var(
|
| 379 |
+
--gr-df-accent-soft,
|
| 380 |
+
var(--df-color-accent-soft, #f3e8ff)
|
| 381 |
+
);
|
| 382 |
+
--color-accent-copied: var(
|
| 383 |
+
--gr-df-copied-cell-color,
|
| 384 |
+
var(--color-accent-soft)
|
| 385 |
+
);
|
| 386 |
+
--body-text-color: var(--df-body-text-color, #111827);
|
| 387 |
+
--block-background-fill: var(
|
| 388 |
+
--df-block-background-fill,
|
| 389 |
+
var(--background-fill-primary)
|
| 390 |
+
);
|
| 391 |
+
--block-radius: var(--df-block-radius, var(--radius-sm, 4px));
|
| 392 |
+
--table-even-background-fill: var(
|
| 393 |
+
--gr-df-table-bg-even,
|
| 394 |
+
var(--df-table-even-background-fill, #ffffff)
|
| 395 |
+
);
|
| 396 |
+
--table-odd-background-fill: var(
|
| 397 |
+
--gr-df-table-bg-odd,
|
| 398 |
+
var(--df-table-odd-background-fill, #f9fafb)
|
| 399 |
+
);
|
| 400 |
+
--border-color-primary: var(--df-border-color-primary, #e5e7eb);
|
| 401 |
+
--radius-sm: var(--df-radius-sm, 4px);
|
| 402 |
+
--size-1: var(--df-size-1, 4px);
|
| 403 |
+
--size-2: var(--df-size-2, 8px);
|
| 404 |
+
--size-3: var(--df-size-3, 12px);
|
| 405 |
+
--size-4: var(--df-size-4, 16px);
|
| 406 |
+
--size-5: var(--df-size-5, 20px);
|
| 407 |
+
--size-6: var(--df-size-6, 24px);
|
| 408 |
+
--size-7: var(--df-size-7, 28px);
|
| 409 |
+
--size-8: var(--df-size-8, 32px);
|
| 410 |
+
--size-9: var(--df-size-9, 36px);
|
| 411 |
+
--size-10: var(--df-size-10, 40px);
|
| 412 |
+
--size-11: var(--df-size-11, 44px);
|
| 413 |
+
--size-12: var(--df-size-12, 48px);
|
| 414 |
+
--size-14: var(--df-size-14, 56px);
|
| 415 |
+
--size-16: var(--df-size-16, 64px);
|
| 416 |
+
--size-20: var(--df-size-20, 80px);
|
| 417 |
+
--size-24: var(--df-size-24, 96px);
|
| 418 |
+
|
| 419 |
+
--size-px: var(--df-size-px, 1px);
|
| 420 |
+
--size-full: var(--df-size-full, 100%);
|
| 421 |
+
--size-0-5: var(--df-size-0-5, 2px);
|
| 422 |
+
--size-1-5: var(--df-size-1-5, 6px);
|
| 423 |
+
--size-2-5: var(--df-size-2-5, 10px);
|
| 424 |
+
--input-text-size: var(--df-input-text-size, 0.95rem);
|
| 425 |
+
--text-sm: var(--df-text-sm, 12px);
|
| 426 |
+
--text-md: var(--df-text-md, 14px);
|
| 427 |
+
--text-lg: var(--df-text-lg, 16px);
|
| 428 |
+
--text-xl: var(--df-text-xl, 22px);
|
| 429 |
+
--text-xxl: var(--df-text-xxl, 26px);
|
| 430 |
+
|
| 431 |
+
--spacing-xxs: var(--df-spacing-xxs, 1px);
|
| 432 |
+
--spacing-xs: var(--df-spacing-xs, 2px);
|
| 433 |
+
--spacing-sm: var(--df-spacing-sm, 4px);
|
| 434 |
+
--spacing-md: var(--df-spacing-md, 6px);
|
| 435 |
+
--spacing-lg: var(--df-spacing-lg, 8px);
|
| 436 |
+
--spacing-xl: var(--df-spacing-xl, 10px);
|
| 437 |
+
--spacing-xxl: var(--df-spacing-xxl, 16px);
|
| 438 |
+
|
| 439 |
+
--radius-xxs: var(--df-radius-xxs, 1px);
|
| 440 |
+
--radius-xs: var(--df-radius-xs, 2px);
|
| 441 |
+
--radius-sm: var(--df-radius-sm, 4px);
|
| 442 |
+
--radius-md: var(--df-radius-md, 6px);
|
| 443 |
+
--radius-lg: var(--df-radius-lg, 8px);
|
| 444 |
+
--radius-xl: var(--df-radius-xl, 12px);
|
| 445 |
+
--radius-2xl: var(--df-radius-2xl, 16px);
|
| 446 |
+
--radius-3xl: var(--df-radius-3xl, 22px);
|
| 447 |
+
--radius-full: var(--df-radius-full, 9999px);
|
| 448 |
+
--font-mono: var(--df-font-mono, "Courier New", Courier, monospace);
|
| 449 |
+
--font-sans: var(
|
| 450 |
+
--df-font-sans,
|
| 451 |
+
"Source Sans Pro",
|
| 452 |
+
ui-sans-serif,
|
| 453 |
+
system-ui,
|
| 454 |
+
sans-serif
|
| 455 |
+
);
|
| 456 |
+
|
| 457 |
+
--input-background-fill: var(
|
| 458 |
+
--gr-df-input-background-fill,
|
| 459 |
+
var(--df-input-background-fill, var(--background-fill-primary, #ffffff))
|
| 460 |
+
);
|
| 461 |
+
--input-background-fill-focus: var(
|
| 462 |
+
--gr-df-input-background-fill-focus,
|
| 463 |
+
var(
|
| 464 |
+
--df-input-background-fill-focus,
|
| 465 |
+
var(--input-background-fill, var(--background-fill-primary, #ffffff))
|
| 466 |
+
)
|
| 467 |
+
);
|
| 468 |
+
--input-background-fill-hover: var(
|
| 469 |
+
--gr-df-input-background-fill-hover,
|
| 470 |
+
var(
|
| 471 |
+
--df-input-background-fill-hover,
|
| 472 |
+
var(--input-background-fill, var(--background-fill-primary, #ffffff))
|
| 473 |
+
)
|
| 474 |
+
);
|
| 475 |
+
--input-border-color: var(
|
| 476 |
+
--gr-df-input-border-color,
|
| 477 |
+
var(--df-input-border-color, var(--border-color-primary, #e5e7eb))
|
| 478 |
+
);
|
| 479 |
+
--input-border-color-focus: var(
|
| 480 |
+
--gr-df-input-border-color-focus,
|
| 481 |
+
var(--df-input-border-color-focus, var(--secondary-300, #93c5fd))
|
| 482 |
+
);
|
| 483 |
+
--input-border-color-hover: var(
|
| 484 |
+
--gr-df-input-border-color-hover,
|
| 485 |
+
var(
|
| 486 |
+
--df-input-border-color-hover,
|
| 487 |
+
var(--input-border-color, var(--border-color-primary, #e5e7eb))
|
| 488 |
+
)
|
| 489 |
+
);
|
| 490 |
+
--input-border-width: var(
|
| 491 |
+
--gr-df-input-border-width,
|
| 492 |
+
var(--df-input-border-width, 1px)
|
| 493 |
+
);
|
| 494 |
+
|
| 495 |
+
--weight-bold: var(--df-weight-bold, 700);
|
| 496 |
+
--weight-semibold: var(--df-weight-semibold, 600);
|
| 497 |
+
--checkbox-border-radius: var(
|
| 498 |
+
--gr-df-checkbox-border-radius,
|
| 499 |
+
var(--df-checkbox-border-radius, var(--df-radius-sm, 4px))
|
| 500 |
+
);
|
| 501 |
+
--checkbox-shadow: var(
|
| 502 |
+
--gr-df-checkbox-shadow,
|
| 503 |
+
var(--df-checkbox-shadow, none)
|
| 504 |
+
);
|
| 505 |
+
--checkbox-border-color: var(
|
| 506 |
+
--gr-df-checkbox-border-color,
|
| 507 |
+
var(--df-checkbox-border-color, var(--df-neutral-300, #d4d4d8))
|
| 508 |
+
);
|
| 509 |
+
--checkbox-background-color: var(
|
| 510 |
+
--gr-df-checkbox-background-color,
|
| 511 |
+
var(
|
| 512 |
+
--df-checkbox-background-color,
|
| 513 |
+
var(--df-background-fill-primary, #ffffff)
|
| 514 |
+
)
|
| 515 |
+
);
|
| 516 |
+
--checkbox-background-color-selected: var(
|
| 517 |
+
--gr-df-checkbox-background-color,
|
| 518 |
+
var(--df-checkbox-background-color-selected, var(--color-accent))
|
| 519 |
+
);
|
| 520 |
+
--checkbox-border-color-focus: var(
|
| 521 |
+
--gr-df-checkbox-border-color-focus,
|
| 522 |
+
var(--df-checkbox-border-color-focus, var(--df-color-accent, #f97316))
|
| 523 |
+
);
|
| 524 |
+
--checkbox-check: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
|
| 525 |
+
--button-transition: var(--df-button-transition, none);
|
| 526 |
+
--max-height: var(--df-max-height, 500px);
|
| 527 |
+
--df-layer-1: 10;
|
| 528 |
+
--df-layer-2: 20;
|
| 529 |
+
--df-layer-3: 30;
|
| 530 |
+
--df-layer-4: 40;
|
| 531 |
+
--df-layer-5: 50;
|
| 532 |
+
--df-layer-below: -1;
|
| 533 |
+
--df-layer-top: 2147483647;
|
| 534 |
+
|
| 535 |
+
--layer-1: var(--df-layer-1, 10);
|
| 536 |
+
--layer-2: var(--df-layer-2, 20);
|
| 537 |
+
--layer-3: var(--df-layer-3, 30);
|
| 538 |
+
--layer-4: var(--df-layer-4, 40);
|
| 539 |
+
--layer-5: var(--df-layer-5, 50);
|
| 540 |
+
--layer-below: var(--df-layer-below, -1);
|
| 541 |
+
--layer-top: var(--df-layer-top, 2147483647);
|
| 542 |
+
|
| 543 |
+
--line-md: var(--df-line-md, 1.5);
|
| 544 |
+
--line-lg: var(--df-line-lg, 1.75);
|
| 545 |
+
|
| 546 |
+
--shadow-xs: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
| 547 |
+
--shadow-sm: 0 4px 6px -2px rgba(0, 0, 0, 0.1),
|
| 548 |
+
0 2px 4px -2px rgba(0, 0, 0, 0.06);
|
| 549 |
+
--shadow-md: 0 12px 16px -4px rgba(0, 0, 0, 0.1),
|
| 550 |
+
0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
| 551 |
+
--shadow-lg: 0 20px 24px -4px rgba(0, 0, 0, 0.1),
|
| 552 |
+
0 8px 8px -4px rgba(0, 0, 0, 0.04);
|
| 553 |
+
--shadow-drop: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
|
| 554 |
+
--shadow-drop-lg: 0 1px 3px 0 rgb(0 0 0 / 0.1),
|
| 555 |
+
0 1px 2px -1px rgb(0 0 0 / 0.1);
|
| 556 |
+
--shadow-inset: rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset;
|
| 557 |
+
--shadow-spread: 3px;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
.gradio-dataframe-standalone.fullscreen {
|
| 561 |
+
position: fixed;
|
| 562 |
+
top: 0;
|
| 563 |
+
left: 0;
|
| 564 |
+
width: 100vw;
|
| 565 |
+
height: 100vh;
|
| 566 |
+
z-index: 1000;
|
| 567 |
+
overflow: auto;
|
| 568 |
+
border-radius: 0;
|
| 569 |
+
background-color: var(--block-background-fill);
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
:global(.dark) .gradio-dataframe-standalone {
|
| 573 |
+
--df-background-fill-primary: var(--df-background-fill-primary-dark);
|
| 574 |
+
--df-background-fill-secondary: var(--df-background-fill-secondary-dark);
|
| 575 |
+
--df-body-text-color: var(--df-body-text-color-dark);
|
| 576 |
+
--df-block-background-fill: var(--df-block-background-fill-dark);
|
| 577 |
+
--df-table-even-background-fill: var(--df-table-even-background-fill-dark);
|
| 578 |
+
--df-table-odd-background-fill: var(--df-table-odd-background-fill-dark);
|
| 579 |
+
--df-border-color-primary: var(--df-border-color-primary-dark);
|
| 580 |
+
--df-color-accent: var(--df-color-accent-dark);
|
| 581 |
+
--df-color-accent-soft: var(--df-color-accent-soft-dark);
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
:global(.gradio-container),
|
| 585 |
+
:global(*),
|
| 586 |
+
:global(::before),
|
| 587 |
+
:global(::after) {
|
| 588 |
+
box-sizing: border-box;
|
| 589 |
+
border-width: 0;
|
| 590 |
+
border-style: solid;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
:global(.gradio-container) :global(textarea) {
|
| 594 |
+
padding-top: var(--input-padding, var(--df-input-padding, 10px));
|
| 595 |
+
padding-bottom: var(--input-padding, var(--df-input-padding, 10px));
|
| 596 |
+
box-sizing: border-box;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
:global(button),
|
| 600 |
+
:global(input),
|
| 601 |
+
:global(select),
|
| 602 |
+
:global(textarea) {
|
| 603 |
+
margin: 0;
|
| 604 |
+
padding: 0;
|
| 605 |
+
color: inherit;
|
| 606 |
+
font-weight: inherit;
|
| 607 |
+
font-size: 100%;
|
| 608 |
+
line-height: inherit;
|
| 609 |
+
font-family: inherit;
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
:global([type="text"]),
|
| 613 |
+
:global([type="url"]),
|
| 614 |
+
:global([type="number"]),
|
| 615 |
+
:global([multiple]),
|
| 616 |
+
:global(textarea),
|
| 617 |
+
:global(select) {
|
| 618 |
+
--tw-shadow: 0 0 #0000;
|
| 619 |
+
appearance: none;
|
| 620 |
+
border-width: 1px;
|
| 621 |
+
border-color: #6b7280;
|
| 622 |
+
border-radius: 0px;
|
| 623 |
+
background-color: #fff;
|
| 624 |
+
padding-top: 0.5rem;
|
| 625 |
+
padding-right: 0.75rem;
|
| 626 |
+
padding-bottom: 0.5rem;
|
| 627 |
+
padding-left: 0.75rem;
|
| 628 |
+
font-size: 1rem;
|
| 629 |
+
line-height: 1.5rem;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
:global(button),
|
| 633 |
+
:global(input[type="button"]),
|
| 634 |
+
:global(input[type="submit"]) {
|
| 635 |
+
-webkit-appearance: button;
|
| 636 |
+
appearance: button;
|
| 637 |
+
background-image: none;
|
| 638 |
+
background-color: transparent;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
:global(.sr-only) {
|
| 642 |
+
clip: rect(0, 0, 0, 0);
|
| 643 |
+
position: absolute;
|
| 644 |
+
margin: -1px;
|
| 645 |
+
border-width: 0;
|
| 646 |
+
padding: 0;
|
| 647 |
+
width: 1px;
|
| 648 |
+
height: 1px;
|
| 649 |
+
overflow: hidden;
|
| 650 |
+
white-space: nowrap;
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
:global(input[type="checkbox"]) {
|
| 654 |
+
accent-color: var(--color-accent);
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
:global(label) {
|
| 658 |
+
display: flex;
|
| 659 |
+
align-items: center;
|
| 660 |
+
transition: all 0.15s ease;
|
| 661 |
+
cursor: pointer;
|
| 662 |
+
/* default label color */
|
| 663 |
+
color: #111111;
|
| 664 |
+
font-weight: 400;
|
| 665 |
+
font-size: 14px;
|
| 666 |
+
line-height: 1.5;
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
:global(label) > * + * {
|
| 670 |
+
margin-left: 8px;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
:global(input) {
|
| 674 |
+
--ring-color: transparent;
|
| 675 |
+
position: relative;
|
| 676 |
+
/* default shadow */
|
| 677 |
+
box-shadow: none;
|
| 678 |
+
border: 1px solid #888888;
|
| 679 |
+
border-radius: 6px;
|
| 680 |
+
background-color: #ffffff;
|
| 681 |
+
line-height: 1;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
:global(input:checked),
|
| 685 |
+
:global(input:checked:hover),
|
| 686 |
+
:global(input:checked:focus) {
|
| 687 |
+
/* checked state: orange */
|
| 688 |
+
background-image: none;
|
| 689 |
+
background-color: #f97316;
|
| 690 |
+
border-color: #f97316;
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
:global(input:checked:focus) {
|
| 694 |
+
background-image: none;
|
| 695 |
+
background-color: #f97316;
|
| 696 |
+
border-color: #f97316;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
:global(input:hover) {
|
| 700 |
+
border-color: #1e90ff;
|
| 701 |
+
background-color: #e6f0ff;
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
:global(input:focus) {
|
| 705 |
+
border-color: #f97316;
|
| 706 |
+
background-color: #fff4e6;
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
:global(input[disabled]),
|
| 710 |
+
:global(.disabled) {
|
| 711 |
+
cursor: not-allowed !important;
|
| 712 |
+
opacity: 0.6;
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
:global(input:hover) {
|
| 716 |
+
cursor: pointer;
|
| 717 |
+
}
|
| 718 |
+
</style>
|
5.49.1/dataframe/standalone/default_i18n.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const default_i18n: Record<string, string> = {
|
| 2 |
+
"dataframe.add_row_above": "Add row above",
|
| 3 |
+
"dataframe.add_row_below": "Add row below",
|
| 4 |
+
"dataframe.delete_row": "Delete row",
|
| 5 |
+
"dataframe.add_column_left": "Add column left",
|
| 6 |
+
"dataframe.add_column_right": "Add column right",
|
| 7 |
+
"dataframe.delete_column": "Delete column",
|
| 8 |
+
"dataframe.sort_asc": "Sort ascending",
|
| 9 |
+
"dataframe.sort_desc": "Sort descending",
|
| 10 |
+
"dataframe.sort_ascending": "Sort ascending",
|
| 11 |
+
"dataframe.sort_descending": "Sort descending",
|
| 12 |
+
"dataframe.clear_sort": "Clear sort",
|
| 13 |
+
"dataframe.filter": "Filter",
|
| 14 |
+
"dataframe.clear_filter": "Clear filter",
|
| 15 |
+
"dataframe.copy": "Copy",
|
| 16 |
+
"dataframe.paste": "Paste",
|
| 17 |
+
"dataframe.cut": "Cut",
|
| 18 |
+
"dataframe.select_all": "Select all",
|
| 19 |
+
"dataframe.fullscreen": "Fullscreen",
|
| 20 |
+
"dataframe.exit_fullscreen": "Exit fullscreen",
|
| 21 |
+
"dataframe.search": "Search",
|
| 22 |
+
"dataframe.export": "Export",
|
| 23 |
+
"dataframe.import": "Import",
|
| 24 |
+
"dataframe.edit": "Edit",
|
| 25 |
+
"dataframe.save": "Save",
|
| 26 |
+
"dataframe.cancel": "Cancel",
|
| 27 |
+
"dataframe.confirm": "Confirm",
|
| 28 |
+
"dataframe.reset": "Reset",
|
| 29 |
+
"dataframe.clear": "Clear",
|
| 30 |
+
"dataframe.undo": "Undo",
|
| 31 |
+
"dataframe.redo": "Redo"
|
| 32 |
+
};
|
5.49.1/dataframe/standalone/stubs/Upload.svelte
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
export const aria_label = "";
|
| 3 |
+
export const root = "";
|
| 4 |
+
export const upload: any = null;
|
| 5 |
+
export const stream_handler: any = null;
|
| 6 |
+
</script>
|
| 7 |
+
|
| 8 |
+
<div>
|
| 9 |
+
<slot />
|
| 10 |
+
</div>
|
| 11 |
+
|
| 12 |
+
<style>
|
| 13 |
+
div {
|
| 14 |
+
width: 100%;
|
| 15 |
+
border: 1px solid var(--border-color-primary);
|
| 16 |
+
border-radius: var(--table-radius);
|
| 17 |
+
overflow: hidden;
|
| 18 |
+
}
|
| 19 |
+
</style>
|
5.49.1/dataframe/standalone/stubs/upload.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export { default as Upload } from "./Upload.svelte";
|