@gradio/dataframe 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/Dataframe.test.ts +697 -32
  3. package/Index.svelte +107 -106
  4. package/dist/Index.svelte +107 -106
  5. package/dist/Index.svelte.d.ts +0 -1
  6. package/dist/shared/BooleanCell.svelte +12 -6
  7. package/dist/shared/BooleanCell.svelte.d.ts +4 -18
  8. package/dist/shared/CellMenu.svelte +74 -49
  9. package/dist/shared/CellMenu.svelte.d.ts +5 -19
  10. package/dist/shared/CellMenuButton.svelte +3 -3
  11. package/dist/shared/CellMenuButton.svelte.d.ts +4 -18
  12. package/dist/shared/CellMenuIcons.svelte +1 -1
  13. package/dist/shared/CellMenuIcons.svelte.d.ts +4 -18
  14. package/dist/shared/DataCell.svelte +189 -0
  15. package/dist/shared/DataCell.svelte.d.ts +44 -0
  16. package/dist/shared/EditableCell.svelte +88 -64
  17. package/dist/shared/EditableCell.svelte.d.ts +8 -26
  18. package/dist/shared/EmptyRowButton.svelte +2 -2
  19. package/dist/shared/EmptyRowButton.svelte.d.ts +4 -18
  20. package/dist/shared/FilterMenu.svelte +26 -18
  21. package/dist/shared/FilterMenu.svelte.d.ts +5 -21
  22. package/dist/shared/HeaderCell.svelte +218 -0
  23. package/dist/shared/HeaderCell.svelte.d.ts +30 -0
  24. package/dist/shared/RowNumber.svelte +4 -2
  25. package/dist/shared/RowNumber.svelte.d.ts +4 -18
  26. package/dist/shared/Table.svelte +1037 -949
  27. package/dist/shared/Table.svelte.d.ts +12 -30
  28. package/dist/shared/Toolbar.svelte +32 -22
  29. package/dist/shared/Toolbar.svelte.d.ts +6 -21
  30. package/dist/shared/column_measurement.svelte.d.ts +20 -0
  31. package/dist/shared/column_measurement.svelte.js +79 -0
  32. package/dist/shared/icons/FilterIcon.svelte +14 -6
  33. package/dist/shared/icons/FilterIcon.svelte.d.ts +14 -6
  34. package/dist/shared/icons/Padlock.svelte +6 -2
  35. package/dist/shared/icons/Padlock.svelte.d.ts +4 -25
  36. package/dist/shared/icons/SelectionButtons.svelte +23 -8
  37. package/dist/shared/icons/SelectionButtons.svelte.d.ts +4 -18
  38. package/dist/shared/icons/SortButtonDown.svelte +15 -4
  39. package/dist/shared/icons/SortButtonDown.svelte.d.ts +4 -25
  40. package/dist/shared/icons/SortButtonUp.svelte +15 -5
  41. package/dist/shared/icons/SortButtonUp.svelte.d.ts +4 -25
  42. package/dist/shared/icons/SortIcon.svelte +13 -7
  43. package/dist/shared/icons/SortIcon.svelte.d.ts +7 -21
  44. package/dist/shared/tanstack/index.d.ts +3 -0
  45. package/dist/shared/tanstack/index.js +3 -0
  46. package/dist/shared/tanstack/table.svelte.d.ts +26 -0
  47. package/dist/shared/tanstack/table.svelte.js +102 -0
  48. package/dist/shared/tanstack/virtual.svelte.d.ts +14 -0
  49. package/dist/shared/tanstack/virtual.svelte.js +76 -0
  50. package/dist/shared/types.d.ts +2 -0
  51. package/dist/shared/utils/filter.d.ts +5 -0
  52. package/dist/shared/utils/filter.js +62 -0
  53. package/dist/shared/utils/selection_utils.js +1 -1
  54. package/dist/shared/utils/table_utils.d.ts +1 -14
  55. package/dist/shared/utils/table_utils.js +0 -61
  56. package/dist/standalone/Index.svelte +71 -46
  57. package/dist/standalone/Index.svelte.d.ts +4 -23
  58. package/dist/types.d.ts +32 -0
  59. package/dist/types.js +1 -0
  60. package/package.json +10 -9
  61. package/shared/BooleanCell.svelte +12 -6
  62. package/shared/CellMenu.svelte +74 -49
  63. package/shared/CellMenuButton.svelte +3 -3
  64. package/shared/CellMenuIcons.svelte +1 -1
  65. package/shared/DataCell.svelte +189 -0
  66. package/shared/EditableCell.svelte +88 -64
  67. package/shared/EmptyRowButton.svelte +2 -2
  68. package/shared/FilterMenu.svelte +26 -18
  69. package/shared/HeaderCell.svelte +218 -0
  70. package/shared/RowNumber.svelte +4 -2
  71. package/shared/Table.svelte +1037 -949
  72. package/shared/Toolbar.svelte +32 -22
  73. package/shared/column_measurement.svelte.ts +103 -0
  74. package/shared/icons/FilterIcon.svelte +14 -6
  75. package/shared/icons/Padlock.svelte +6 -2
  76. package/shared/icons/SelectionButtons.svelte +23 -8
  77. package/shared/icons/SortButtonDown.svelte +15 -4
  78. package/shared/icons/SortButtonUp.svelte +15 -5
  79. package/shared/icons/SortIcon.svelte +13 -7
  80. package/shared/tanstack/index.ts +23 -0
  81. package/shared/tanstack/table.svelte.ts +117 -0
  82. package/shared/tanstack/virtual.svelte.ts +105 -0
  83. package/shared/types.ts +3 -0
  84. package/shared/utils/filter.ts +66 -0
  85. package/shared/utils/selection_utils.ts +1 -1
  86. package/shared/utils/table_utils.ts +1 -100
  87. package/standalone/Index.svelte +71 -46
  88. package/test/filter.test.ts +350 -0
  89. package/test/selection_utils.test.ts +416 -0
  90. package/test/table_utils.test.ts +45 -112
  91. package/types.ts +34 -0
  92. package/dist/shared/TableCell.svelte +0 -330
  93. package/dist/shared/TableCell.svelte.d.ts +0 -66
  94. package/dist/shared/TableHeader.svelte +0 -344
  95. package/dist/shared/TableHeader.svelte.d.ts +0 -61
  96. package/dist/shared/VirtualTable.svelte +0 -379
  97. package/dist/shared/VirtualTable.svelte.d.ts +0 -42
  98. package/dist/shared/context/dataframe_context.d.ts +0 -180
  99. package/dist/shared/context/dataframe_context.js +0 -412
  100. package/dist/shared/icons/SortArrowDown.svelte +0 -25
  101. package/dist/shared/icons/SortArrowDown.svelte.d.ts +0 -20
  102. package/dist/shared/icons/SortArrowUp.svelte +0 -25
  103. package/dist/shared/icons/SortArrowUp.svelte.d.ts +0 -20
  104. package/dist/shared/utils/data_processing.d.ts +0 -14
  105. package/dist/shared/utils/data_processing.js +0 -47
  106. package/dist/shared/utils/drag_utils.d.ts +0 -15
  107. package/dist/shared/utils/drag_utils.js +0 -67
  108. package/dist/shared/utils/filter_utils.d.ts +0 -29
  109. package/dist/shared/utils/filter_utils.js +0 -123
  110. package/dist/shared/utils/keyboard_utils.d.ts +0 -3
  111. package/dist/shared/utils/keyboard_utils.js +0 -236
  112. package/dist/shared/utils/menu_utils.d.ts +0 -42
  113. package/dist/shared/utils/menu_utils.js +0 -58
  114. package/dist/shared/utils/sort_utils.d.ts +0 -26
  115. package/dist/shared/utils/sort_utils.js +0 -59
  116. package/shared/TableCell.svelte +0 -330
  117. package/shared/TableHeader.svelte +0 -344
  118. package/shared/VirtualTable.svelte +0 -379
  119. package/shared/context/dataframe_context.ts +0 -701
  120. package/shared/icons/SortArrowDown.svelte +0 -25
  121. package/shared/icons/SortArrowUp.svelte +0 -25
  122. package/shared/utils/data_processing.ts +0 -77
  123. package/shared/utils/drag_utils.ts +0 -105
  124. package/shared/utils/filter_utils.ts +0 -208
  125. package/shared/utils/keyboard_utils.ts +0 -309
  126. package/shared/utils/menu_utils.ts +0 -115
  127. package/shared/utils/sort_utils.ts +0 -91
  128. package/test/sort_utils.test.ts +0 -323
@@ -1,25 +1,11 @@
1
1
  import type { I18nFormatter } from "@gradio/utils";
2
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: Props & {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const SortIcon: $$__sveltets_2_IsomorphicComponent<{
16
- direction?: ("asc" | "desc") | null;
2
+ type SortDirection = "asc" | "desc";
3
+ type $$ComponentProps = {
4
+ direction?: SortDirection | null;
17
5
  priority?: number | null;
18
6
  i18n: I18nFormatter;
19
- }, {
20
- sort: CustomEvent<"asc" | "desc">;
21
- } & {
22
- [evt: string]: CustomEvent<any>;
23
- }, {}, {}, string>;
24
- type SortIcon = InstanceType<typeof SortIcon>;
7
+ onsort?: (direction: SortDirection) => void;
8
+ };
9
+ declare const SortIcon: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type SortIcon = ReturnType<typeof SortIcon>;
25
11
  export default SortIcon;
@@ -0,0 +1,3 @@
1
+ export { createSvelteTable } from "./table.svelte.js";
2
+ export { createSvelteVirtualizer, type VirtualItem } from "./virtual.svelte.js";
3
+ export { createColumnHelper, getCoreRowModel, getSortedRowModel, getFilteredRowModel, type ColumnDef, type TableOptions, type Table, type Header, type Cell, type Row, type SortingState, type ColumnFiltersState, type ColumnPinningState, type FilterFn, type SortingFn, type CellContext, type HeaderContext } from "@tanstack/table-core";
@@ -0,0 +1,3 @@
1
+ export { createSvelteTable } from "./table.svelte.js";
2
+ export { createSvelteVirtualizer } from "./virtual.svelte.js";
3
+ export { createColumnHelper, getCoreRowModel, getSortedRowModel, getFilteredRowModel } from "@tanstack/table-core";
@@ -0,0 +1,26 @@
1
+ import { type RowData, type TableOptions } from "@tanstack/table-core";
2
+ /**
3
+ * Merges objects while preserving property getters for lazy evaluation.
4
+ * Properties are defined as getters that look up values from sources in
5
+ * reverse order at access time. This is critical: it means reading a
6
+ * property from the merged result doesn't happen until the property is
7
+ * actually accessed, not when mergeObjects is called.
8
+ */
9
+ export declare function mergeObjects(...sources: any): any;
10
+ /**
11
+ * Creates a reactive TanStack Table for Svelte 5.
12
+ *
13
+ * The reactivity works through mergeObjects' lazy getters:
14
+ * - $effect.pre calls table.setOptions() with a merged object
15
+ * - The merged object has lazy getters for `data`, `columns`, `state`, etc.
16
+ * - TanStack stores this object but doesn't deep-read all properties immediately
17
+ * - When getRowModel() is called (in $derived), TanStack reads `data` and `columns`
18
+ * through the lazy getters, which read the reactive $state/$derived values
19
+ * - onStateChange fires when TanStack mutates its own state → bumps version
20
+ * - version is read by getRowModel/getHeaderGroups → $derived re-evaluates
21
+ */
22
+ export declare function createSvelteTable<TData extends RowData>(options: TableOptions<TData>): {
23
+ getRowModel: () => import("@tanstack/table-core").RowModel<TData>;
24
+ getHeaderGroups: () => import("@tanstack/table-core").HeaderGroup<TData>[];
25
+ getColumn: (id: string) => import("@tanstack/table-core").Column<TData, unknown> | undefined;
26
+ };
@@ -0,0 +1,102 @@
1
+ import { createTable } from "@tanstack/table-core";
2
+ /**
3
+ * Merges objects while preserving property getters for lazy evaluation.
4
+ * Properties are defined as getters that look up values from sources in
5
+ * reverse order at access time. This is critical: it means reading a
6
+ * property from the merged result doesn't happen until the property is
7
+ * actually accessed, not when mergeObjects is called.
8
+ */
9
+ export function mergeObjects(...sources) {
10
+ const target = {};
11
+ for (let i = 0; i < sources.length; i++) {
12
+ let source = sources[i];
13
+ if (typeof source === "function")
14
+ source = source();
15
+ if (source) {
16
+ const descriptors = Object.getOwnPropertyDescriptors(source);
17
+ for (const key in descriptors) {
18
+ if (key in target)
19
+ continue;
20
+ Object.defineProperty(target, key, {
21
+ enumerable: true,
22
+ get() {
23
+ for (let j = sources.length - 1; j >= 0; j--) {
24
+ let s = sources[j];
25
+ if (typeof s === "function")
26
+ s = s();
27
+ const v = (s || {})[key];
28
+ if (v !== undefined)
29
+ return v;
30
+ }
31
+ }
32
+ });
33
+ }
34
+ }
35
+ }
36
+ return target;
37
+ }
38
+ /**
39
+ * Creates a reactive TanStack Table for Svelte 5.
40
+ *
41
+ * The reactivity works through mergeObjects' lazy getters:
42
+ * - $effect.pre calls table.setOptions() with a merged object
43
+ * - The merged object has lazy getters for `data`, `columns`, `state`, etc.
44
+ * - TanStack stores this object but doesn't deep-read all properties immediately
45
+ * - When getRowModel() is called (in $derived), TanStack reads `data` and `columns`
46
+ * through the lazy getters, which read the reactive $state/$derived values
47
+ * - onStateChange fires when TanStack mutates its own state → bumps version
48
+ * - version is read by getRowModel/getHeaderGroups → $derived re-evaluates
49
+ */
50
+ export function createSvelteTable(options) {
51
+ const resolvedOptions = mergeObjects({
52
+ state: {},
53
+ onStateChange() { },
54
+ renderFallbackValue: null,
55
+ mergeOptions: (defaultOptions, opts) => {
56
+ return mergeObjects(defaultOptions, opts);
57
+ }
58
+ }, options);
59
+ const table = createTable(resolvedOptions);
60
+ let state = $state(table.initialState);
61
+ let version = $state(0);
62
+ function updateOptions() {
63
+ table.setOptions((prev) => {
64
+ // mergeObjects creates lazy getters — `state` is NOT read here,
65
+ // only when TanStack accesses the `state` property later.
66
+ return mergeObjects(prev, options, {
67
+ state: mergeObjects(state, options.state || {}),
68
+ onStateChange: (updater) => {
69
+ if (updater instanceof Function)
70
+ state = updater(state);
71
+ else
72
+ state = mergeObjects(state, updater);
73
+ version += 1;
74
+ options.onStateChange?.(updater);
75
+ }
76
+ });
77
+ });
78
+ }
79
+ // Initial sync
80
+ updateOptions();
81
+ // Re-sync when options change. Because mergeObjects uses lazy getters,
82
+ // this effect's tracked dependencies are only the properties that
83
+ // table.setOptions() eagerly reads (which is minimal — mostly just
84
+ // checking if the options object reference changed).
85
+ $effect.pre(() => {
86
+ updateOptions();
87
+ });
88
+ return {
89
+ getRowModel: () => {
90
+ void version;
91
+ return table.getRowModel();
92
+ },
93
+ getHeaderGroups: () => {
94
+ void version;
95
+ return table.getHeaderGroups();
96
+ },
97
+ getColumn: (id) => {
98
+ void version;
99
+ return table.getColumn(id);
100
+ }
101
+ };
102
+ }
@@ -0,0 +1,14 @@
1
+ import { Virtualizer, type PartialKeys, type VirtualizerOptions } from "@tanstack/virtual-core";
2
+ export type { VirtualItem } from "@tanstack/virtual-core";
3
+ /**
4
+ * Creates a reactive TanStack Virtualizer for Svelte 5.
5
+ *
6
+ * Returns a getter function that returns the virtualizer instance.
7
+ * Call the getter inside $derived or template expressions to create
8
+ * reactive dependencies on the virtualizer state.
9
+ */
10
+ export declare function createSvelteVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, "observeElementRect" | "observeElementOffset" | "scrollToFn">): {
11
+ instance: Virtualizer<TScrollElement, TItemElement>;
12
+ virtualItems: () => ReturnType<Virtualizer<TScrollElement, TItemElement>["getVirtualItems"]>;
13
+ totalSize: () => number;
14
+ };
@@ -0,0 +1,76 @@
1
+ import { Virtualizer, elementScroll, observeElementOffset, observeElementRect } from "@tanstack/virtual-core";
2
+ import { untrack } from "svelte";
3
+ /**
4
+ * Creates a reactive TanStack Virtualizer for Svelte 5.
5
+ *
6
+ * Returns a getter function that returns the virtualizer instance.
7
+ * Call the getter inside $derived or template expressions to create
8
+ * reactive dependencies on the virtualizer state.
9
+ */
10
+ export function createSvelteVirtualizer(options) {
11
+ let version = $state(0);
12
+ const virtualizer = new Virtualizer({
13
+ observeElementRect: observeElementRect,
14
+ observeElementOffset: observeElementOffset,
15
+ scrollToFn: elementScroll,
16
+ ...options,
17
+ onChange: (instance, sync) => {
18
+ if (sync) {
19
+ version += 1;
20
+ }
21
+ else {
22
+ queueMicrotask(() => {
23
+ version += 1;
24
+ });
25
+ }
26
+ options.onChange?.(instance, sync);
27
+ }
28
+ });
29
+ $effect(() => {
30
+ const cleanup = virtualizer._didMount();
31
+ untrack(() => {
32
+ version += 1;
33
+ });
34
+ return cleanup;
35
+ });
36
+ let prev_count = 0;
37
+ $effect(() => {
38
+ const current_count = options.count;
39
+ virtualizer.setOptions({
40
+ observeElementRect: observeElementRect,
41
+ observeElementOffset: observeElementOffset,
42
+ scrollToFn: elementScroll,
43
+ ...options,
44
+ onChange: (instance, sync) => {
45
+ if (sync) {
46
+ version += 1;
47
+ }
48
+ else {
49
+ queueMicrotask(() => {
50
+ version += 1;
51
+ });
52
+ }
53
+ options.onChange?.(instance, sync);
54
+ }
55
+ });
56
+ if (prev_count === 0 && current_count > 0) {
57
+ virtualizer.measure();
58
+ }
59
+ prev_count = current_count;
60
+ });
61
+ $effect.pre(() => {
62
+ void version;
63
+ virtualizer._willUpdate();
64
+ });
65
+ return {
66
+ instance: virtualizer,
67
+ virtualItems: () => {
68
+ void version;
69
+ return virtualizer.getVirtualItems();
70
+ },
71
+ totalSize: () => {
72
+ void version;
73
+ return virtualizer.getTotalSize();
74
+ }
75
+ };
76
+ }
@@ -17,3 +17,5 @@ export type ElementRefs = Record<string, {
17
17
  input: null | HTMLTextAreaElement;
18
18
  }>;
19
19
  export type DataBinding = Record<string, TableCell>;
20
+ export type SortDirection = "asc" | "desc";
21
+ export type FilterDatatype = "string" | "number";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Custom filter function for TanStack Table that handles Gradio's
3
+ * { dtype, filter, value } column filter format.
4
+ */
5
+ export declare function gradio_filter_fn(row: any, columnId: string, filterValue: any): boolean;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Custom filter function for TanStack Table that handles Gradio's
3
+ * { dtype, filter, value } column filter format.
4
+ */
5
+ export function gradio_filter_fn(row, columnId, filterValue) {
6
+ const { dtype, filter, value: fval } = filterValue;
7
+ const cell_value = String(row.getValue(columnId) ?? "");
8
+ const compare_val = fval ?? "";
9
+ if (dtype === "number") {
10
+ const num = parseFloat(cell_value);
11
+ const target = parseFloat(compare_val);
12
+ if (isNaN(num) || isNaN(target)) {
13
+ if (filter === "Is empty")
14
+ return cell_value.trim() === "";
15
+ if (filter === "Is not empty")
16
+ return cell_value.trim() !== "";
17
+ return true;
18
+ }
19
+ switch (filter) {
20
+ case "=":
21
+ return num === target;
22
+ case "≠":
23
+ return num !== target;
24
+ case ">":
25
+ return num > target;
26
+ case "<":
27
+ return num < target;
28
+ case "≥":
29
+ return num >= target;
30
+ case "≤":
31
+ return num <= target;
32
+ case "Is empty":
33
+ return cell_value.trim() === "";
34
+ case "Is not empty":
35
+ return cell_value.trim() !== "";
36
+ default:
37
+ return true;
38
+ }
39
+ }
40
+ const lower = cell_value.toLowerCase();
41
+ const target_lower = compare_val.toLowerCase();
42
+ switch (filter) {
43
+ case "Contains":
44
+ return lower.includes(target_lower);
45
+ case "Does not contain":
46
+ return !lower.includes(target_lower);
47
+ case "Starts with":
48
+ return lower.startsWith(target_lower);
49
+ case "Ends with":
50
+ return lower.endsWith(target_lower);
51
+ case "Is":
52
+ return lower === target_lower;
53
+ case "Is not":
54
+ return lower !== target_lower;
55
+ case "Is empty":
56
+ return cell_value.trim() === "";
57
+ case "Is not empty":
58
+ return cell_value.trim() !== "";
59
+ default:
60
+ return true;
61
+ }
62
+ }
@@ -20,7 +20,7 @@ export function get_range_selection(start, end) {
20
20
  const min_col = Math.min(start_col, end_col);
21
21
  const max_col = Math.max(start_col, end_col);
22
22
  const cells = [];
23
- // Add the start cell as the "anchor" cell so that when
23
+ // add the start cell as the "anchor" cell so that when
24
24
  // we press shift+arrow keys, the selection will always
25
25
  // include the anchor cell.
26
26
  cells.push(start);
@@ -1,19 +1,6 @@
1
- import type { CellValue, Headers, HeadersWithIDs, TableCell, TableData } from "../types";
2
- import type { SortDirection } from "./sort_utils";
3
- import type { FilterDatatype } from "./filter_utils";
1
+ import type { CellValue, Headers, HeadersWithIDs, TableData } from "../types";
4
2
  export declare function make_cell_id(row: number, col: number): string;
5
3
  export declare function make_header_id(col: number): string;
6
- export declare function get_max(data: TableData): TableCell[];
7
- export declare function sort_table_data(data: TableData, display_value: string[][] | null, styling: string[][] | null, sort_columns: {
8
- col: number;
9
- direction: SortDirection;
10
- }[]): void;
11
- export declare function filter_table_data(data: TableData, display_value: string[][] | null, styling: string[][] | null, filter_columns: {
12
- col: number;
13
- datatype: FilterDatatype;
14
- filter: string;
15
- value: string;
16
- }[], original_data?: TableData, original_display_value?: string[][] | null, original_styling?: string[][] | null): void;
17
4
  export declare function copy_table_data(data: TableData, selected_cells: [number, number][] | null): Promise<void>;
18
5
  export declare function guess_delimiter(text: string, possibleDelimiters: string[]): string[];
19
6
  export declare function data_uri_to_blob(data_uri: string): Blob;
@@ -1,5 +1,3 @@
1
- import { sort_data } from "./sort_utils";
2
- import { filter_data } from "./filter_utils";
3
1
  import { dsvFormat } from "d3-dsv";
4
2
  export function make_cell_id(row, col) {
5
3
  return `cell-${row}-${col}`;
@@ -7,64 +5,6 @@ export function make_cell_id(row, col) {
7
5
  export function make_header_id(col) {
8
6
  return `header-${col}`;
9
7
  }
10
- export function get_max(data) {
11
- if (!data || !data.length)
12
- return [];
13
- let max = data[0].slice();
14
- for (let i = 0; i < data.length; i++) {
15
- for (let j = 0; j < data[i].length; j++) {
16
- if (`${max[j].value}`.length < `${data[i][j].value}`.length) {
17
- max[j] = data[i][j];
18
- }
19
- }
20
- }
21
- return max;
22
- }
23
- export function sort_table_data(data, display_value, styling, sort_columns) {
24
- if (!sort_columns.length)
25
- return;
26
- if (!data || !data.length)
27
- return;
28
- const indices = sort_data(data, sort_columns);
29
- const new_data = indices.map((i) => data[i]);
30
- data.splice(0, data.length, ...new_data);
31
- if (display_value) {
32
- const new_display = indices.map((i) => display_value[i]);
33
- display_value.splice(0, display_value.length, ...new_display);
34
- }
35
- if (styling) {
36
- const new_styling = indices.map((i) => styling[i]);
37
- styling.splice(0, styling.length, ...new_styling);
38
- }
39
- }
40
- export function filter_table_data(data, display_value, styling, filter_columns, original_data, original_display_value, original_styling) {
41
- const base_data = original_data ?? data;
42
- const base_display_value = original_display_value ?? display_value;
43
- const base_styling = original_styling ?? styling;
44
- if (!filter_columns.length) {
45
- data.splice(0, data.length, ...base_data.map((row) => [...row]));
46
- if (display_value && base_display_value) {
47
- display_value.splice(0, display_value.length, ...base_display_value.map((row) => [...row]));
48
- }
49
- if (styling && base_styling) {
50
- styling.splice(0, styling.length, ...base_styling.map((row) => [...row]));
51
- }
52
- return;
53
- }
54
- if (!data || !data.length)
55
- return;
56
- const indices = filter_data(base_data, filter_columns);
57
- const new_data = indices.map((i) => base_data[i]);
58
- data.splice(0, data.length, ...new_data);
59
- if (display_value && base_display_value) {
60
- const new_display = indices.map((i) => base_display_value[i]);
61
- display_value.splice(0, display_value.length, ...new_display);
62
- }
63
- if (styling && base_styling) {
64
- const new_styling = indices.map((i) => base_styling[i]);
65
- styling.splice(0, styling.length, ...new_styling);
66
- }
67
- }
68
8
  export async function copy_table_data(data, selected_cells) {
69
9
  if (!data || !data.length)
70
10
  return;
@@ -93,7 +33,6 @@ export async function copy_table_data(data, selected_cells) {
93
33
  throw new Error("Failed to copy to clipboard: " + err.message);
94
34
  }
95
35
  }
96
- // File Import/Export
97
36
  export function guess_delimiter(text, possibleDelimiters) {
98
37
  return possibleDelimiters.filter(weedOut);
99
38
  function weedOut(delimiter) {
@@ -5,7 +5,52 @@
5
5
  import type { I18nFormatter } from "@gradio/utils";
6
6
  import { default_i18n } from "./default_i18n";
7
7
 
8
- export let i18n: I18nFormatter | undefined = undefined;
8
+ let {
9
+ i18n = undefined,
10
+ value = $bindable({
11
+ data: [["", "", ""]],
12
+ headers: ["1", "2", "3"],
13
+ metadata: null
14
+ }),
15
+ datatype = "str",
16
+ interactive = true,
17
+ show_row_numbers = false,
18
+ max_height = 500,
19
+ show_search = "none",
20
+ wrap = false,
21
+ line_breaks = true,
22
+ column_widths = [],
23
+ max_chars = undefined,
24
+ pinned_columns = 0,
25
+ static_columns = [],
26
+ fullscreen = $bindable(false),
27
+ label = null,
28
+ show_label = true,
29
+ latex_delimiters = [],
30
+ col_count = undefined,
31
+ row_count = undefined
32
+ }: {
33
+ i18n?: I18nFormatter | undefined;
34
+ value?: DataframeValue;
35
+ datatype?: Datatype | Datatype[];
36
+ interactive?: boolean;
37
+ show_row_numbers?: boolean;
38
+ max_height?: number;
39
+ show_search?: "none" | "search" | "filter";
40
+ wrap?: boolean;
41
+ line_breaks?: boolean;
42
+ column_widths?: string[];
43
+ max_chars?: number | undefined;
44
+ pinned_columns?: number;
45
+ static_columns?: (string | number)[];
46
+ fullscreen?: boolean;
47
+ label?: string | null;
48
+ show_label?: boolean;
49
+ latex_delimiters?: any[];
50
+ col_count?: [number, "fixed" | "dynamic"] | undefined;
51
+ row_count?: [number, "fixed" | "dynamic"] | undefined;
52
+ } = $props();
53
+
9
54
  const i18n_fn = (key: string | null | undefined): string => {
10
55
  if (!key) return "";
11
56
  if (typeof i18n === "function") return (i18n as any)(key);
@@ -14,31 +59,7 @@
14
59
  return default_i18n[key] ?? key;
15
60
  };
16
61
 
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 wrap = false;
28
- export let line_breaks = true;
29
- export let column_widths: string[] = [];
30
- export let max_chars: number | undefined = undefined;
31
- export let pinned_columns = 0;
32
- export let static_columns: (string | number)[] = [];
33
- export let fullscreen = false;
34
- export let label: string | null = null;
35
- export let show_label = true;
36
- export let latex_delimiters: any[] = [];
37
- export let col_count: [number, "fixed" | "dynamic"] | undefined = undefined;
38
- export let row_count: [number, "fixed" | "dynamic"] | undefined = undefined;
39
-
40
- // mirrors default row count and column count logic in dataframe.py
41
- $: resolved_row_count = (() => {
62
+ let resolved_row_count = $derived.by(() => {
42
63
  if (
43
64
  row_count &&
44
65
  Array.isArray(row_count) &&
@@ -49,8 +70,9 @@
49
70
  return row_count as [number, "fixed" | "dynamic"];
50
71
  }
51
72
  return [1, "dynamic"] as [number, "fixed" | "dynamic"];
52
- })();
53
- $: resolved_col_count = (() => {
73
+ });
74
+
75
+ let resolved_col_count_base = $derived.by(() => {
54
76
  if (
55
77
  col_count &&
56
78
  Array.isArray(col_count) &&
@@ -65,14 +87,21 @@
65
87
  ? value.headers.length
66
88
  : 3;
67
89
  return [headerLength, "dynamic"] as [number, "fixed" | "dynamic"];
68
- })();
69
- $: if (
70
- static_columns &&
71
- static_columns.length > 0 &&
72
- resolved_col_count[1] !== "fixed"
73
- ) {
74
- resolved_col_count = [resolved_col_count[0], "fixed"];
75
- }
90
+ });
91
+
92
+ let resolved_col_count = $derived.by(() => {
93
+ if (
94
+ static_columns &&
95
+ static_columns.length > 0 &&
96
+ resolved_col_count_base[1] !== "fixed"
97
+ ) {
98
+ return [resolved_col_count_base[0], "fixed"] as [
99
+ number,
100
+ "fixed" | "dynamic"
101
+ ];
102
+ }
103
+ return resolved_col_count_base;
104
+ });
76
105
 
77
106
  let root = "";
78
107
 
@@ -91,8 +120,8 @@
91
120
  <Table
92
121
  values={value.data}
93
122
  headers={value.headers}
94
- display_value={value?.metadata?.display_value}
95
- styling={value?.metadata?.styling}
123
+ display_value={value?.metadata?.display_value ?? null}
124
+ styling={value?.metadata?.styling ?? null}
96
125
  {datatype}
97
126
  editable={interactive}
98
127
  {show_row_numbers}
@@ -113,15 +142,11 @@
113
142
  row_count={resolved_row_count}
114
143
  {root}
115
144
  i18n={i18n_fn}
116
- on:change={(e) => {
117
- value.data = e.detail.data;
118
- value.headers = e.detail.headers;
145
+ onchange={(detail) => {
146
+ value.data = detail.data;
147
+ value.headers = detail.headers;
119
148
  }}
120
- on:blur
121
- on:keydown
122
- on:input
123
- on:select
124
- on:fullscreen={(e) => (fullscreen = e.detail)}
149
+ onfullscreen={() => (fullscreen = !fullscreen)}
125
150
  upload={async () => null}
126
151
  stream_handler={() => new EventSource("about:blank")}
127
152
  />
@@ -1,19 +1,6 @@
1
1
  import type { Datatype, DataframeValue } from "../shared/utils/utils";
2
2
  import type { I18nFormatter } from "@gradio/utils";
3
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
- $$bindings?: Bindings;
6
- } & Exports;
7
- (internal: unknown, props: Props & {
8
- $$events?: Events;
9
- $$slots?: Slots;
10
- }): Exports & {
11
- $set?: any;
12
- $on?: any;
13
- };
14
- z_$$bindings?: Bindings;
15
- }
16
- declare const Index: $$__sveltets_2_IsomorphicComponent<{
3
+ type $$ComponentProps = {
17
4
  i18n?: I18nFormatter | undefined;
18
5
  value?: DataframeValue;
19
6
  datatype?: Datatype | Datatype[];
@@ -33,13 +20,7 @@ declare const Index: $$__sveltets_2_IsomorphicComponent<{
33
20
  latex_delimiters?: any[];
34
21
  col_count?: [number, "fixed" | "dynamic"] | undefined;
35
22
  row_count?: [number, "fixed" | "dynamic"] | undefined;
36
- }, {
37
- blur: CustomEvent<any>;
38
- keydown: CustomEvent<any>;
39
- input: CustomEvent<undefined>;
40
- select: CustomEvent<import("@gradio/utils").SelectData>;
41
- } & {
42
- [evt: string]: CustomEvent<any>;
43
- }, {}, {}, string>;
44
- type Index = InstanceType<typeof Index>;
23
+ };
24
+ declare const Index: import("svelte").Component<$$ComponentProps, {}, "value" | "fullscreen">;
25
+ type Index = ReturnType<typeof Index>;
45
26
  export default Index;