@macrostrat/data-sheet 4.1.1 → 4.2.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.
- package/CHANGELOG.md +34 -0
- package/dist/actions/builtin.cjs +1 -1
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +0 -2
- package/dist/actions/builtin.js +1 -1
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/clipboard.cjs +1 -1
- package/dist/actions/clipboard.cjs.map +1 -1
- package/dist/actions/clipboard.d.ts +3 -2
- package/dist/actions/clipboard.js +1 -1
- package/dist/actions/clipboard.js.map +1 -1
- package/dist/actions/column-controls.cjs +7 -196
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.d.ts +1 -1
- package/dist/actions/column-controls.js +5 -194
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +24 -73
- package/dist/actions/column-filter.cjs.map +1 -1
- package/dist/actions/column-filter.d.ts +6 -4
- package/dist/actions/column-filter.js +25 -74
- package/dist/actions/column-filter.js.map +1 -1
- package/dist/actions/context.cjs +147 -0
- package/dist/actions/context.cjs.map +1 -0
- package/dist/actions/context.d.ts +93 -0
- package/dist/actions/context.js +145 -0
- package/dist/actions/context.js.map +1 -0
- package/dist/actions/edit-actions.cjs.map +1 -1
- package/dist/actions/edit-actions.d.ts +3 -1
- package/dist/actions/edit-actions.js.map +1 -1
- package/dist/actions/index.d.ts +2 -3
- package/dist/actions/selection.cjs +70 -115
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +22 -12
- package/dist/actions/selection.js +71 -114
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-actions.cjs +41 -0
- package/dist/actions/table-actions.cjs.map +1 -0
- package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
- package/dist/actions/{table-controls.js → table-actions.js} +2 -23
- package/dist/actions/table-actions.js.map +1 -0
- package/dist/actions/types.d.ts +11 -89
- package/dist/components/cell-detail.cjs +6 -6
- package/dist/components/cell-detail.cjs.map +1 -1
- package/dist/components/cell-detail.js +1 -1
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +7 -7
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/indicators/filter-and-sort.cjs +378 -0
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.d.ts +59 -0
- package/dist/components/indicators/filter-and-sort.js +376 -0
- package/dist/components/indicators/filter-and-sort.js.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
- package/dist/components/indicators/index.d.ts +4 -0
- package/dist/components/indicators/selection.cjs +113 -0
- package/dist/components/indicators/selection.cjs.map +1 -0
- package/dist/components/indicators/selection.d.ts +3 -0
- package/dist/components/indicators/selection.js +111 -0
- package/dist/components/indicators/selection.js.map +1 -0
- package/dist/components/indicators/selection.module.sass.cjs +19 -0
- package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
- package/dist/components/indicators/selection.module.sass.js +17 -0
- package/dist/components/indicators/selection.module.sass.js.map +1 -0
- package/dist/components/indicators/unified-filters.cjs +130 -0
- package/dist/components/indicators/unified-filters.cjs.map +1 -0
- package/dist/components/indicators/unified-filters.d.ts +10 -0
- package/dist/components/indicators/unified-filters.js +130 -0
- package/dist/components/indicators/unified-filters.js.map +1 -0
- package/dist/components/indicators/view-info.cjs +59 -0
- package/dist/components/indicators/view-info.cjs.map +1 -0
- package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
- package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
- package/dist/components/indicators/view-info.js.map +1 -0
- package/dist/components/text-areas.cjs +5 -5
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.js +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs +185 -0
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
- package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
- package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
- package/dist/components/toolbars/actions-toolbar.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
- package/dist/components/toolbars/active-filters.cjs +120 -0
- package/dist/components/toolbars/active-filters.cjs.map +1 -0
- package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
- package/dist/components/toolbars/active-filters.js +120 -0
- package/dist/components/toolbars/active-filters.js.map +1 -0
- package/dist/components/toolbars/index.d.ts +2 -0
- package/dist/data-panel.cjs +291 -0
- package/dist/data-panel.cjs.map +1 -0
- package/dist/data-panel.d.ts +110 -0
- package/dist/data-panel.js +289 -0
- package/dist/data-panel.js.map +1 -0
- package/dist/data-panel.module.sass.cjs +40 -0
- package/dist/data-panel.module.sass.cjs.map +1 -0
- package/dist/data-panel.module.sass.js +38 -0
- package/dist/data-panel.module.sass.js.map +1 -0
- package/dist/{core.cjs → data-sheet.cjs} +123 -190
- package/dist/data-sheet.cjs.map +1 -0
- package/dist/data-sheet.css +241 -13
- package/dist/data-sheet.d.ts +16 -0
- package/dist/{core.js → data-sheet.js} +92 -159
- package/dist/data-sheet.js.map +1 -0
- package/dist/data-view.cjs +47 -0
- package/dist/data-view.cjs.map +1 -0
- package/dist/data-view.d.ts +15 -0
- package/dist/data-view.js +45 -0
- package/dist/data-view.js.map +1 -0
- package/dist/filters/operators.cjs +19 -2
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +4 -3
- package/dist/filters/operators.js +19 -2
- package/dist/filters/operators.js.map +1 -1
- package/dist/index.cjs +106 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +76 -17
- package/dist/index.js.map +1 -1
- package/dist/notifications.cjs +4 -4
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.js +1 -1
- package/dist/postgrest-table/data-loaders.cjs +128 -95
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -82
- package/dist/postgrest-table/data-loaders.js +109 -76
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +18 -17
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +4 -3
- package/dist/postgrest-table/index.js +9 -8
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/{utils → provider}/column-spec.cjs +23 -9
- package/dist/provider/column-spec.cjs.map +1 -0
- package/dist/{utils → provider}/column-spec.d.ts +73 -2
- package/dist/{utils → provider}/column-spec.js +24 -10
- package/dist/provider/column-spec.js.map +1 -0
- package/dist/provider/core.cjs +382 -0
- package/dist/provider/core.cjs.map +1 -0
- package/dist/provider/core.d.ts +74 -0
- package/dist/provider/core.js +380 -0
- package/dist/provider/core.js.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/interactions.cjs +128 -0
- package/dist/provider/interactions.cjs.map +1 -0
- package/dist/provider/interactions.d.ts +39 -0
- package/dist/provider/interactions.js +128 -0
- package/dist/provider/interactions.js.map +1 -0
- package/dist/provider/selection.cjs +29 -0
- package/dist/provider/selection.cjs.map +1 -0
- package/dist/provider/selection.d.ts +9 -0
- package/dist/provider/selection.js +29 -0
- package/dist/provider/selection.js.map +1 -0
- package/dist/provider/table-data.cjs +92 -0
- package/dist/provider/table-data.cjs.map +1 -0
- package/dist/provider/table-data.d.ts +81 -0
- package/dist/provider/table-data.js +92 -0
- package/dist/provider/table-data.js.map +1 -0
- package/dist/provider/types.cjs +22 -0
- package/dist/provider/types.cjs.map +1 -0
- package/dist/provider/types.d.ts +256 -0
- package/dist/provider/types.js +22 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
- package/dist/provider/zustand-store.cjs.map +1 -0
- package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
- package/dist/provider/zustand-store.js.map +1 -0
- package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
- package/dist/renderers/cell-renderer.cjs.map +1 -0
- package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
- package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
- package/dist/renderers/cell-renderer.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +21 -13
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -2
- package/dist/renderers/column-header-cell.js +20 -12
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +1 -0
- package/dist/types.cjs +7 -19
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +117 -229
- package/dist/types.js +7 -19
- package/dist/types.js.map +1 -1
- package/dist/utils/atoms.cjs +24 -0
- package/dist/utils/atoms.cjs.map +1 -0
- package/dist/utils/atoms.d.ts +4 -0
- package/dist/utils/atoms.js +24 -0
- package/dist/utils/atoms.js.map +1 -0
- package/dist/utils/debug-overlay.cjs.map +1 -1
- package/dist/utils/debug-overlay.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/key-handling.cjs +140 -139
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +4 -2
- package/dist/utils/key-handling.js +136 -135
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +6 -1
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.js +6 -1
- package/dist/utils/validation.js.map +1 -1
- package/package.json +4 -3
- package/src/actions/builtin.ts +1 -4
- package/src/actions/clipboard.ts +4 -3
- package/src/actions/column-controls.ts +12 -245
- package/src/actions/column-filter.ts +28 -92
- package/src/actions/context.ts +299 -0
- package/src/actions/edit-actions.ts +3 -1
- package/src/actions/index.ts +2 -3
- package/src/actions/selection.ts +109 -156
- package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
- package/src/actions/types.ts +17 -101
- package/src/components/colors.ts +1 -1
- package/src/components/index.ts +2 -1
- package/src/components/indicators/filter-and-sort.module.sass +13 -0
- package/src/components/indicators/filter-and-sort.ts +478 -0
- package/src/components/indicators/index.ts +4 -0
- package/src/components/indicators/selection.module.sass +22 -0
- package/src/components/indicators/selection.ts +141 -0
- package/src/components/indicators/unified-filters.ts +161 -0
- package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
- package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
- package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
- package/src/components/toolbars/active-filters.ts +150 -0
- package/src/components/toolbars/index.ts +2 -0
- package/src/data-panel.module.sass +185 -0
- package/src/data-panel.ts +556 -0
- package/src/{core.ts → data-sheet.ts} +145 -330
- package/src/data-view.ts +70 -0
- package/src/filters/operators.ts +33 -3
- package/src/index.ts +4 -3
- package/src/postgrest-table/data-loaders.ts +244 -171
- package/src/postgrest-table/index.ts +10 -9
- package/src/{utils → provider}/column-spec.ts +30 -15
- package/src/provider/core.ts +585 -0
- package/src/provider/index.ts +7 -0
- package/src/provider/interactions.ts +161 -0
- package/src/provider/selection.ts +31 -0
- package/src/provider/table-data.ts +178 -0
- package/src/provider/types.ts +273 -0
- package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
- package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
- package/src/renderers/column-header-cell.ts +21 -14
- package/src/renderers/index.ts +1 -0
- package/src/types.ts +137 -239
- package/src/utils/atoms.ts +28 -0
- package/src/utils/debug-overlay.ts +1 -1
- package/src/utils/index.ts +2 -8
- package/src/utils/key-handling.ts +170 -164
- package/src/utils/validation.ts +7 -2
- package/dist/actions/filters.cjs +0 -139
- package/dist/actions/filters.cjs.map +0 -1
- package/dist/actions/filters.js +0 -139
- package/dist/actions/filters.js.map +0 -1
- package/dist/actions/table-controls.cjs +0 -62
- package/dist/actions/table-controls.cjs.map +0 -1
- package/dist/actions/table-controls.js.map +0 -1
- package/dist/actions/toolbar.cjs +0 -260
- package/dist/actions/toolbar.cjs.map +0 -1
- package/dist/actions/toolbar.js.map +0 -1
- package/dist/actions/toolbar.module.sass.cjs +0 -27
- package/dist/actions/toolbar.module.sass.cjs.map +0 -1
- package/dist/actions/toolbar.module.sass.js +0 -25
- package/dist/actions/toolbar.module.sass.js.map +0 -1
- package/dist/cell-renderer.cjs.map +0 -1
- package/dist/cell-renderer.js.map +0 -1
- package/dist/components/view-info.cjs +0 -55
- package/dist/components/view-info.cjs.map +0 -1
- package/dist/components/view-info.js.map +0 -1
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -117
- package/dist/core.js.map +0 -1
- package/dist/provider.cjs +0 -197
- package/dist/provider.cjs.map +0 -1
- package/dist/provider.d.ts +0 -26
- package/dist/provider.js +0 -195
- package/dist/provider.js.map +0 -1
- package/dist/table-updates/data-parameter.d.ts +0 -14
- package/dist/table-updates/filter.d.ts +0 -16
- package/dist/table-updates/index.d.ts +0 -19
- package/dist/utils/column-spec.cjs.map +0 -1
- package/dist/utils/column-spec.js.map +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js +0 -9
- package/dist/utils/index.js.map +0 -1
- package/dist/zustand-store.cjs.map +0 -1
- package/dist/zustand-store.js.map +0 -1
- package/src/actions/filters.ts +0 -176
- package/src/components/actions.module.sass +0 -8
- package/src/provider.ts +0 -267
- package/src/table-updates/data-parameter.ts +0 -44
- package/src/table-updates/filter.ts +0 -124
- package/src/table-updates/index.ts +0 -239
- /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CellEdit,
|
|
3
|
+
ClipboardProxy,
|
|
4
|
+
RowStatusValue,
|
|
5
|
+
tableDataAtom,
|
|
6
|
+
} from "../provider";
|
|
7
|
+
import { type Region, RegionCardinality } from "@blueprintjs/table";
|
|
8
|
+
import update from "immutability-helper";
|
|
9
|
+
import {
|
|
10
|
+
computeFilteredRowIndices,
|
|
11
|
+
computeSelectionShape,
|
|
12
|
+
getSelectedColumnKeys,
|
|
13
|
+
getSelectedRowIndices,
|
|
14
|
+
SelectionCardinality,
|
|
15
|
+
SelectionShape,
|
|
16
|
+
} from "./selection.ts";
|
|
17
|
+
import { Getter, Setter } from "jotai";
|
|
18
|
+
import type { Store as JotaiStore } from "jotai/vanilla/store";
|
|
19
|
+
import { storeAPIAtom } from "../provider";
|
|
20
|
+
import type { ColumnSpec } from "../provider";
|
|
21
|
+
import type { TableAction } from "./types.ts";
|
|
22
|
+
|
|
23
|
+
interface ActionContextOptions {
|
|
24
|
+
/** Override the action context to scope to a single column.
|
|
25
|
+
This is needed for actions that are invoked for a column header
|
|
26
|
+
drop-down, for instance */
|
|
27
|
+
singleColumn: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type StoreInterface = Omit<JotaiStore, "sub">;
|
|
31
|
+
|
|
32
|
+
/** Context passed to an action's `run` function, providing both data access
|
|
33
|
+
* and store manipulation methods. Constructed fresh at action-run time
|
|
34
|
+
* to ensure current state. */
|
|
35
|
+
export interface TableActionContext<T = any> {
|
|
36
|
+
/** Current selection regions */
|
|
37
|
+
selection: Region[];
|
|
38
|
+
/** Derived cardinality of the current selection */
|
|
39
|
+
selectionCardinality: SelectionCardinality;
|
|
40
|
+
/** Concrete shape of the current selection (cardinality + column/row counts). */
|
|
41
|
+
selectionShape: SelectionShape;
|
|
42
|
+
/** The single selected column's key when exactly one column is scoped
|
|
43
|
+
* (a single full column, or cells within one column); otherwise `null`. */
|
|
44
|
+
columnKey: string | null;
|
|
45
|
+
/** The single selected data-row index when exactly one row is scoped;
|
|
46
|
+
* otherwise `null`. */
|
|
47
|
+
rowIndex: number | null;
|
|
48
|
+
/** The single selected cell (data-row index + column key) when exactly one
|
|
49
|
+
* cell is selected; otherwise `null`. Presence of these resolved fields is
|
|
50
|
+
* how actions discriminate selection shape — e.g. `appliesTo: ctx =>
|
|
51
|
+
* ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`
|
|
52
|
+
* within a `FULL_COLUMNS` target for a single-column control. */
|
|
53
|
+
cell: { rowIndex: number; columnKey: string } | null;
|
|
54
|
+
/** The table's base data */
|
|
55
|
+
data: T[];
|
|
56
|
+
/** Sparse overlay of edited data */
|
|
57
|
+
updatedData: (T | null | undefined)[];
|
|
58
|
+
/** Row status tracking added/deleted rows */
|
|
59
|
+
rowStatus: (RowStatusValue | null | undefined)[];
|
|
60
|
+
/** Column definitions */
|
|
61
|
+
columnSpec: ColumnSpec[];
|
|
62
|
+
/** Whether the table is in edit mode */
|
|
63
|
+
editable: boolean;
|
|
64
|
+
/** Whether row deletion is available (false when the provider can't delete). */
|
|
65
|
+
canDeleteRows: boolean;
|
|
66
|
+
|
|
67
|
+
// Convenience methods (derived from selection)
|
|
68
|
+
/** Row indices covered by the current selection */
|
|
69
|
+
getSelectedRowIndices(): number[];
|
|
70
|
+
/** The selected rows as resolved objects (not indices) — the natural input
|
|
71
|
+
* for an immediate-edit action. Only loaded rows are returned. */
|
|
72
|
+
getSelectedRows(): T[];
|
|
73
|
+
/** Column keys covered by the current selection */
|
|
74
|
+
getSelectedColumnKeys(): string[];
|
|
75
|
+
|
|
76
|
+
// Immediate-edit persistence (present when a persisting provider is wired,
|
|
77
|
+
// e.g. via DataPanel). Each mutates through the provider and auto-refreshes,
|
|
78
|
+
// so a selection action can edit rows without touching a `refreshToken`.
|
|
79
|
+
/** Persist edited rows (upsert), then refresh. */
|
|
80
|
+
saveRows?: (rows: T[]) => Promise<void>;
|
|
81
|
+
/** Delete rows by identity, then refresh. */
|
|
82
|
+
deleteRows?: (ids: Array<string | number>) => Promise<void>;
|
|
83
|
+
/** Insert a row, then refresh. */
|
|
84
|
+
insertRow?: (row: Partial<T>) => Promise<void>;
|
|
85
|
+
/** Force a re-fetch from scratch. */
|
|
86
|
+
refresh?: () => void;
|
|
87
|
+
|
|
88
|
+
// Store manipulation methods
|
|
89
|
+
onCellEdited(rowIndex: number, columnKey: string, value: any): void;
|
|
90
|
+
/** Edit multiple cells in a single batch update. Preferred over calling
|
|
91
|
+
* `onCellEdited` in a loop, which triggers separate store updates
|
|
92
|
+
* and may produce inconsistent intermediate states. */
|
|
93
|
+
editCells(edits: CellEdit[]): void;
|
|
94
|
+
deleteSelectedRows(): void;
|
|
95
|
+
addRow(row?: Partial<T>): void;
|
|
96
|
+
setUpdatedData(data: any): void;
|
|
97
|
+
resetChanges(region?: Region[]): void;
|
|
98
|
+
clearSelection(): void;
|
|
99
|
+
scrollToRow(rowIndex: number): void;
|
|
100
|
+
/** Direct store mutation for cases not covered by the convenience methods
|
|
101
|
+
* above (e.g., modifying `columnSpec` or `deletedRows`). */
|
|
102
|
+
setState(partial: Record<string, any>): void;
|
|
103
|
+
|
|
104
|
+
// Clipboard proxy support
|
|
105
|
+
/** Active clipboard proxy from a prior copy, if any */
|
|
106
|
+
clipboardProxy: ClipboardProxy | null;
|
|
107
|
+
/** Store a clipboard proxy for potential backend-mediated paste */
|
|
108
|
+
setClipboardProxy(proxy: ClipboardProxy | null): void;
|
|
109
|
+
|
|
110
|
+
// Filter support
|
|
111
|
+
/** Row index mapping when filters are active. When non-null,
|
|
112
|
+
* visible row `i` maps to data row `filteredRowIndices[i]`. */
|
|
113
|
+
filteredRowIndices: number[] | null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Construct a `TableActionContext` from the current store state.
|
|
117
|
+
* Call this at action-run time (not render time) to ensure
|
|
118
|
+
* the context reflects the latest state.
|
|
119
|
+
* @param setState - Optional store setState for direct mutation. Omit for
|
|
120
|
+
* read-only contexts (e.g., disabled checks). */
|
|
121
|
+
export function buildActionContext<T>(
|
|
122
|
+
get: Getter,
|
|
123
|
+
set: Setter,
|
|
124
|
+
options?: ActionContextOptions,
|
|
125
|
+
): TableActionContext<T> {
|
|
126
|
+
const storeAPI = get(storeAPIAtom);
|
|
127
|
+
if (storeAPI == null) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
"No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.",
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const data = get(tableDataAtom) as T[];
|
|
134
|
+
|
|
135
|
+
let state = storeAPI.getState();
|
|
136
|
+
if (options?.singleColumn != null) {
|
|
137
|
+
const colIndex = options.singleColumn;
|
|
138
|
+
state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];
|
|
139
|
+
}
|
|
140
|
+
const setState = storeAPI.setState;
|
|
141
|
+
|
|
142
|
+
// Lazy-compute filteredRowIndices to avoid cost during disabled checks
|
|
143
|
+
let _filteredRowIndices: number[] | null | undefined = undefined;
|
|
144
|
+
function getFilteredRowIndices(): number[] | null {
|
|
145
|
+
if (_filteredRowIndices === undefined) {
|
|
146
|
+
_filteredRowIndices = computeFilteredRowIndices(
|
|
147
|
+
data,
|
|
148
|
+
state.updatedData,
|
|
149
|
+
state.activeFilters,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return _filteredRowIndices;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const { selection, updatedData, rowStatus, rowEditing = {} } = state;
|
|
156
|
+
|
|
157
|
+
const shape = computeSelectionShape(selection);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
selection,
|
|
161
|
+
selectionCardinality: shape.cardinality,
|
|
162
|
+
selectionShape: shape,
|
|
163
|
+
data,
|
|
164
|
+
updatedData,
|
|
165
|
+
rowStatus,
|
|
166
|
+
// Immediate-edit persistence, wired by the consumer (DataPanel) when a
|
|
167
|
+
// persisting provider is present; each already auto-refreshes.
|
|
168
|
+
...rowEditing,
|
|
169
|
+
// Resolved single-target identity (lazy — mapping rows through filters is
|
|
170
|
+
// only paid when accessed).
|
|
171
|
+
get columnKey() {
|
|
172
|
+
return shape.columns === 1
|
|
173
|
+
? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)
|
|
174
|
+
: null;
|
|
175
|
+
},
|
|
176
|
+
get rowIndex() {
|
|
177
|
+
return shape.rows === 1
|
|
178
|
+
? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
|
|
179
|
+
null)
|
|
180
|
+
: null;
|
|
181
|
+
},
|
|
182
|
+
get cell() {
|
|
183
|
+
if (
|
|
184
|
+
shape.cardinality !== RegionCardinality.CELLS ||
|
|
185
|
+
shape.columns !== 1 ||
|
|
186
|
+
shape.rows !== 1
|
|
187
|
+
) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const columnKey =
|
|
191
|
+
getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;
|
|
192
|
+
const rowIndex =
|
|
193
|
+
getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
|
|
194
|
+
null;
|
|
195
|
+
return columnKey != null && rowIndex != null
|
|
196
|
+
? { rowIndex, columnKey }
|
|
197
|
+
: null;
|
|
198
|
+
},
|
|
199
|
+
columnSpec: state.columnSpec,
|
|
200
|
+
editable: state.editable,
|
|
201
|
+
canDeleteRows: state.canDeleteRows,
|
|
202
|
+
getSelectedRowIndices: () =>
|
|
203
|
+
getSelectedRowIndices(state.selection, getFilteredRowIndices()),
|
|
204
|
+
getSelectedRows: () =>
|
|
205
|
+
getSelectedRowIndices(state.selection, getFilteredRowIndices())
|
|
206
|
+
.map((i) => data[i])
|
|
207
|
+
.filter((r) => r != null),
|
|
208
|
+
getSelectedColumnKeys: () =>
|
|
209
|
+
getSelectedColumnKeys(state.selection, state.columnSpec),
|
|
210
|
+
onCellEdited: state.onCellEdited,
|
|
211
|
+
editCells(edits: CellEdit[]) {
|
|
212
|
+
state.setUpdatedData((updatedData: T[]) => {
|
|
213
|
+
const spec: Record<number, any> = {};
|
|
214
|
+
for (const e of edits) {
|
|
215
|
+
const rowIndex = e.rowIndex;
|
|
216
|
+
const columnKey = (e as any).columnKey ?? e.column;
|
|
217
|
+
if (spec[rowIndex] == null) {
|
|
218
|
+
const op = updatedData[rowIndex] != null ? "$merge" : "$set";
|
|
219
|
+
spec[rowIndex] = { [op]: {} };
|
|
220
|
+
}
|
|
221
|
+
const opKey = Object.keys(spec[rowIndex])[0];
|
|
222
|
+
spec[rowIndex][opKey][columnKey] = e.value;
|
|
223
|
+
}
|
|
224
|
+
return update(updatedData, spec);
|
|
225
|
+
});
|
|
226
|
+
// Emit a structured edit event so controlled consumers capture programmatic
|
|
227
|
+
// batch edits (clipboard paste, fill) the same as inline edits.
|
|
228
|
+
state.onEdit?.({
|
|
229
|
+
type: "setCells",
|
|
230
|
+
cells: edits.map((e) => ({
|
|
231
|
+
rowIndex: e.rowIndex,
|
|
232
|
+
column: (e as any).columnKey ?? e.column,
|
|
233
|
+
value: e.value,
|
|
234
|
+
row: data[e.rowIndex],
|
|
235
|
+
})),
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
deleteSelectedRows: state.deleteSelectedRows,
|
|
239
|
+
addRow: state.addRow,
|
|
240
|
+
setUpdatedData: state.setUpdatedData,
|
|
241
|
+
resetChanges: state.resetChanges,
|
|
242
|
+
clearSelection: state.clearSelection,
|
|
243
|
+
scrollToRow: state.scrollToRow,
|
|
244
|
+
setState,
|
|
245
|
+
clipboardProxy: state.clipboardProxy,
|
|
246
|
+
setClipboardProxy(proxy) {
|
|
247
|
+
state.setClipboardProxy(proxy);
|
|
248
|
+
},
|
|
249
|
+
get filteredRowIndices() {
|
|
250
|
+
return getFilteredRowIndices();
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function getMessageForError(e: any) {
|
|
256
|
+
if (e instanceof Error) return e.message;
|
|
257
|
+
if (typeof e === "string") return e;
|
|
258
|
+
if (e instanceof Object) return JSON.stringify(e);
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function runActionWrapper<T>(
|
|
263
|
+
action: TableAction<T>,
|
|
264
|
+
get: Getter,
|
|
265
|
+
set: Setter,
|
|
266
|
+
toaster: any,
|
|
267
|
+
configState: any = undefined,
|
|
268
|
+
) {
|
|
269
|
+
console.log("runActionWrapper", action.id, configState);
|
|
270
|
+
const ctx = buildActionContext(get, set) as TableActionContext<T>;
|
|
271
|
+
if (action.disabled instanceof Function) {
|
|
272
|
+
if (action.disabled(ctx)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
} else if (action.disabled) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
const res = action.run?.(ctx, configState);
|
|
280
|
+
if (res instanceof Promise) {
|
|
281
|
+
res
|
|
282
|
+
.then(() => {})
|
|
283
|
+
.catch((e) => {
|
|
284
|
+
displayErrorForAction(action, e, toaster);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
} catch (e) {
|
|
288
|
+
displayErrorForAction(action, e, toaster);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function displayErrorForAction(action: TableAction, error: any, toaster: any) {
|
|
293
|
+
const message =
|
|
294
|
+
getMessageForError(error) ?? action.errorMessage ?? "Action failed";
|
|
295
|
+
toaster.show({
|
|
296
|
+
message,
|
|
297
|
+
intent: "danger",
|
|
298
|
+
});
|
|
299
|
+
}
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { RegionCardinality } from "@blueprintjs/table";
|
|
9
9
|
import { collectValidationErrors } from "../utils/validation";
|
|
10
|
-
import type {
|
|
10
|
+
import type { TableAction } from "./types";
|
|
11
|
+
import { SelectionCardinality } from "./selection.ts";
|
|
12
|
+
import { TableActionContext } from "./context.ts";
|
|
11
13
|
|
|
12
14
|
/** Every selection cardinality — an action targeting all of these is always
|
|
13
15
|
* applicable, so the toolbar never empties out. */
|
package/src/actions/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export * from "./selection";
|
|
3
3
|
export * from "./builtin";
|
|
4
|
-
export * from "./toolbar";
|
|
5
4
|
export * from "./clipboard";
|
|
6
|
-
export * from "./filters";
|
|
7
5
|
export * from "./column-controls";
|
|
8
6
|
export * from "./edit-actions";
|
|
9
7
|
export * from "./column-filter";
|
|
10
|
-
export * from "./table-
|
|
8
|
+
export * from "./table-actions.ts";
|
|
9
|
+
export * from "./context.ts";
|
package/src/actions/selection.ts
CHANGED
|
@@ -1,18 +1,82 @@
|
|
|
1
1
|
import { type Region, RegionCardinality } from "@blueprintjs/table";
|
|
2
|
-
import type { ColumnSpec } from "../
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import type { ColumnSpec } from "../provider";
|
|
3
|
+
import type { TableAction } from "./types";
|
|
4
|
+
import { RefObject } from "react";
|
|
5
|
+
import { SelectModifiers } from "../data-panel.ts";
|
|
6
|
+
|
|
7
|
+
export function buildDataViewSelection(
|
|
8
|
+
// index of selected item
|
|
9
|
+
index: number,
|
|
10
|
+
mods: SelectModifiers,
|
|
11
|
+
selection: Region[],
|
|
12
|
+
anchorRef: RefObject<number | null>,
|
|
13
|
+
enableMultipleSelection: boolean,
|
|
14
|
+
): Region[] {
|
|
15
|
+
/** Build the selection for data views */
|
|
16
|
+
const current = new Set(getSelectedRowIndices(selection));
|
|
17
|
+
let next: Set<number>;
|
|
18
|
+
|
|
19
|
+
const isSingleSelect = current.size === 1;
|
|
20
|
+
const isCurrentlySelected = current.has(index);
|
|
21
|
+
|
|
22
|
+
if (!enableMultipleSelection) {
|
|
23
|
+
// Simpler path for single selection
|
|
24
|
+
next = new Set();
|
|
25
|
+
if (!isCurrentlySelected) {
|
|
26
|
+
next.add(index);
|
|
27
|
+
}
|
|
28
|
+
return rowIndicesToRegions(next);
|
|
29
|
+
}
|
|
30
|
+
// multiple selection
|
|
31
|
+
if (isSingleSelect && isCurrentlySelected && !mods.additive && !mods.range) {
|
|
32
|
+
// Clicking the only selected row with no modifiers clears the selection.
|
|
33
|
+
next = new Set();
|
|
34
|
+
} else if (mods.range && anchorRef.current != null) {
|
|
35
|
+
// We have a range select and an anchor: select the range between the anchor and the clicked row.
|
|
36
|
+
const a = anchorRef.current;
|
|
37
|
+
const [lo, hi] = a <= index ? [a, index] : [index, a];
|
|
38
|
+
// Shift extends the existing selection when combined with cmd/ctrl,
|
|
39
|
+
// otherwise replaces it with the range. The anchor stays put so the
|
|
40
|
+
// range can be re-dragged from the same origin.
|
|
41
|
+
next = mods.additive ? new Set(current) : new Set();
|
|
42
|
+
for (let i = lo; i <= hi; i++) next.add(i);
|
|
43
|
+
} else if (mods.additive) {
|
|
44
|
+
// We are adding or removing to the selection with the ctrl key
|
|
45
|
+
next = new Set(current);
|
|
46
|
+
if (next.has(index)) next.delete(index);
|
|
47
|
+
else next.add(index);
|
|
48
|
+
anchorRef.current = index;
|
|
49
|
+
} else {
|
|
50
|
+
next = new Set([index]);
|
|
51
|
+
anchorRef.current = index;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return rowIndicesToRegions(next);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Collapse a set of selected row indices into `FULL_ROWS` regions, merging
|
|
58
|
+
* contiguous runs into a single `{ rows: [start, end] }` range. */
|
|
59
|
+
export function rowIndicesToRegions(indices: Set<number>): Region[] {
|
|
60
|
+
const sorted = Array.from(indices).sort((a, b) => a - b);
|
|
61
|
+
const regions: Region[] = [];
|
|
62
|
+
let start: number | null = null;
|
|
63
|
+
let prev: number | null = null;
|
|
64
|
+
for (const i of sorted) {
|
|
65
|
+
if (start == null) {
|
|
66
|
+
start = prev = i;
|
|
67
|
+
} else if (i === prev! + 1) {
|
|
68
|
+
prev = i;
|
|
69
|
+
} else {
|
|
70
|
+
regions.push({ rows: [start, prev!] });
|
|
71
|
+
start = prev = i;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (start != null) regions.push({ rows: [start, prev!] });
|
|
75
|
+
return regions;
|
|
76
|
+
}
|
|
13
77
|
|
|
14
78
|
/** Derive the selection cardinality from the current set of selected regions.
|
|
15
|
-
* Returns "
|
|
79
|
+
* Returns "null" when there is no active selection. */
|
|
16
80
|
export function getSelectionCardinality(
|
|
17
81
|
regions: Region[],
|
|
18
82
|
): RegionCardinality | null {
|
|
@@ -26,16 +90,39 @@ export function getSelectionCardinality(
|
|
|
26
90
|
return RegionCardinality.FULL_TABLE;
|
|
27
91
|
}
|
|
28
92
|
|
|
93
|
+
/** Selection cardinality including the case of no active selection */
|
|
94
|
+
export type SelectionCardinality = RegionCardinality | "none";
|
|
95
|
+
|
|
96
|
+
/** The concrete *shape* of the current selection — richer than cardinality
|
|
97
|
+
* alone. The "single X" cases are exposed as resolved identity fields on the
|
|
98
|
+
* action context (`columnKey`, `rowIndex`, `cell`); this carries the counts. */
|
|
99
|
+
export interface SelectionShape {
|
|
100
|
+
cardinality: SelectionCardinality;
|
|
101
|
+
/** Number of columns the selection spans (0 when not column-scoped). */
|
|
102
|
+
columns: number;
|
|
103
|
+
/** Number of rows the selection spans (0 when not row-scoped). */
|
|
104
|
+
rows: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
29
107
|
/** Compute the concrete shape of a selection (cardinality + column/row spans). */
|
|
30
108
|
export function computeSelectionShape(regions: Region[]): SelectionShape {
|
|
31
109
|
const cardinality = getSelectionCardinality(regions) ?? "none";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
110
|
+
let columns = 0;
|
|
111
|
+
let rows = 0;
|
|
112
|
+
for (const region of regions) {
|
|
113
|
+
const c = region.cols;
|
|
114
|
+
if (c != null) {
|
|
115
|
+
columns += c[1] - c[0] + 1;
|
|
116
|
+
}
|
|
117
|
+
const r = region.rows;
|
|
118
|
+
if (r != null) {
|
|
119
|
+
rows += r[1] - r[0] + 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
35
122
|
return {
|
|
36
123
|
cardinality,
|
|
37
|
-
columns
|
|
38
|
-
rows
|
|
124
|
+
columns,
|
|
125
|
+
rows,
|
|
39
126
|
};
|
|
40
127
|
}
|
|
41
128
|
|
|
@@ -47,7 +134,7 @@ export function getApplicableActions<T>(
|
|
|
47
134
|
editable: boolean,
|
|
48
135
|
): TableAction<T>[] {
|
|
49
136
|
return actions.filter((action) => {
|
|
50
|
-
if (action.requiresEditable
|
|
137
|
+
if (action.requiresEditable && !editable) return false;
|
|
51
138
|
return action.targets.includes(cardinality);
|
|
52
139
|
});
|
|
53
140
|
}
|
|
@@ -96,119 +183,6 @@ export function getSelectedColumnKeys(
|
|
|
96
183
|
return Array.from(keys);
|
|
97
184
|
}
|
|
98
185
|
|
|
99
|
-
/** Construct a `TableActionContext` from the current store state.
|
|
100
|
-
* Call this at action-run time (not render time) to ensure
|
|
101
|
-
* the context reflects the latest state.
|
|
102
|
-
* @param setState - Optional store setState for direct mutation. Omit for
|
|
103
|
-
* read-only contexts (e.g., disabled checks). */
|
|
104
|
-
export function buildActionContext<T>(
|
|
105
|
-
state: DataSheetStore<T>,
|
|
106
|
-
setState: (partial: Record<string, any>) => void = () => {},
|
|
107
|
-
): TableActionContext<T> {
|
|
108
|
-
// Lazy-compute filteredRowIndices to avoid cost during disabled checks
|
|
109
|
-
let _filteredRowIndices: number[] | null | undefined = undefined;
|
|
110
|
-
function getFilteredRowIndices(): number[] | null {
|
|
111
|
-
if (_filteredRowIndices === undefined) {
|
|
112
|
-
_filteredRowIndices = computeFilteredRowIndices(
|
|
113
|
-
state.data,
|
|
114
|
-
state.updatedData,
|
|
115
|
-
state.activeFilters,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
return _filteredRowIndices;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const shape = computeSelectionShape(state.selection);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
selection: state.selection,
|
|
125
|
-
selectionCardinality: getSelectionCardinality(state.selection),
|
|
126
|
-
selectionShape: shape,
|
|
127
|
-
// Resolved single-target identity (lazy — mapping rows through filters is
|
|
128
|
-
// only paid when accessed).
|
|
129
|
-
get columnKey() {
|
|
130
|
-
return shape.columns === 1
|
|
131
|
-
? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)
|
|
132
|
-
: null;
|
|
133
|
-
},
|
|
134
|
-
get rowIndex() {
|
|
135
|
-
return shape.rows === 1
|
|
136
|
-
? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
|
|
137
|
-
null)
|
|
138
|
-
: null;
|
|
139
|
-
},
|
|
140
|
-
get cell() {
|
|
141
|
-
if (
|
|
142
|
-
shape.cardinality !== RegionCardinality.CELLS ||
|
|
143
|
-
shape.columns !== 1 ||
|
|
144
|
-
shape.rows !== 1
|
|
145
|
-
) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
const columnKey =
|
|
149
|
-
getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;
|
|
150
|
-
const rowIndex =
|
|
151
|
-
getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
|
|
152
|
-
null;
|
|
153
|
-
return columnKey != null && rowIndex != null
|
|
154
|
-
? { rowIndex, columnKey }
|
|
155
|
-
: null;
|
|
156
|
-
},
|
|
157
|
-
data: state.data,
|
|
158
|
-
updatedData: state.updatedData,
|
|
159
|
-
rowStatus: state.rowStatus,
|
|
160
|
-
columnSpec: state.columnSpec,
|
|
161
|
-
editable: state.editable,
|
|
162
|
-
canDeleteRows: state.canDeleteRows,
|
|
163
|
-
getSelectedRowIndices: () =>
|
|
164
|
-
getSelectedRowIndices(state.selection, getFilteredRowIndices()),
|
|
165
|
-
getSelectedColumnKeys: () =>
|
|
166
|
-
getSelectedColumnKeys(state.selection, state.columnSpec),
|
|
167
|
-
onCellEdited: state.onCellEdited,
|
|
168
|
-
editCells(edits: CellEdit[]) {
|
|
169
|
-
state.setUpdatedData((updatedData: T[]) => {
|
|
170
|
-
const spec: Record<number, any> = {};
|
|
171
|
-
for (const e of edits) {
|
|
172
|
-
const rowIndex = e.rowIndex;
|
|
173
|
-
const columnKey = (e as any).columnKey ?? e.column;
|
|
174
|
-
if (spec[rowIndex] == null) {
|
|
175
|
-
const op = updatedData[rowIndex] != null ? "$merge" : "$set";
|
|
176
|
-
spec[rowIndex] = { [op]: {} };
|
|
177
|
-
}
|
|
178
|
-
const opKey = Object.keys(spec[rowIndex])[0];
|
|
179
|
-
spec[rowIndex][opKey][columnKey] = e.value;
|
|
180
|
-
}
|
|
181
|
-
return update(updatedData, spec);
|
|
182
|
-
});
|
|
183
|
-
// Emit a structured edit event so controlled consumers capture programmatic
|
|
184
|
-
// batch edits (clipboard paste, fill) the same as inline edits.
|
|
185
|
-
state.onEdit?.({
|
|
186
|
-
type: "setCells",
|
|
187
|
-
cells: edits.map((e) => ({
|
|
188
|
-
rowIndex: e.rowIndex,
|
|
189
|
-
column: (e as any).columnKey ?? e.column,
|
|
190
|
-
value: e.value,
|
|
191
|
-
row: state.data[e.rowIndex],
|
|
192
|
-
})),
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
deleteSelectedRows: state.deleteSelectedRows,
|
|
196
|
-
addRow: state.addRow,
|
|
197
|
-
setUpdatedData: state.setUpdatedData,
|
|
198
|
-
resetChanges: state.resetChanges,
|
|
199
|
-
clearSelection: state.clearSelection,
|
|
200
|
-
scrollToRow: state.scrollToRow,
|
|
201
|
-
setState,
|
|
202
|
-
clipboardProxy: state.clipboardProxy,
|
|
203
|
-
setClipboardProxy(proxy) {
|
|
204
|
-
state.setClipboardProxy(proxy);
|
|
205
|
-
},
|
|
206
|
-
get filteredRowIndices() {
|
|
207
|
-
return getFilteredRowIndices();
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
186
|
/** Compute which data row indices are visible given the active filters.
|
|
213
187
|
* Returns `null` when no filters are active (all rows visible). */
|
|
214
188
|
export function computeFilteredRowIndices<T>(
|
|
@@ -263,29 +237,8 @@ export function mergeColumnActions<T>(
|
|
|
263
237
|
return [...globalActions, ...columnActions];
|
|
264
238
|
}
|
|
265
239
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
): TableFilter<T>[] {
|
|
271
|
-
const result: TableFilter<T>[] = [...globalFilters];
|
|
272
|
-
for (const col of columnSpec) {
|
|
273
|
-
if (col.filters != null) {
|
|
274
|
-
for (const f of col.filters as TableFilter<T>[]) {
|
|
275
|
-
const withKey: TableFilter<T> = {
|
|
276
|
-
...f,
|
|
277
|
-
columnKey: f.columnKey ?? col.key,
|
|
278
|
-
};
|
|
279
|
-
if (!result.some((r) => r.id === withKey.id)) {
|
|
280
|
-
result.push(withKey);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// Auto-generate the built-in operator filter for a `filterable` column,
|
|
285
|
-
// unless the column already supplies an explicit filter.
|
|
286
|
-
if (col.filterable && !result.some((r) => r.columnKey === col.key)) {
|
|
287
|
-
result.push(columnFilter(col) as TableFilter<T>);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return result;
|
|
240
|
+
export function range(arr: number[]) {
|
|
241
|
+
if (arr.length != 2) throw new Error("Range must have two elements");
|
|
242
|
+
const [start, end] = arr;
|
|
243
|
+
return Array.from({ length: end - start + 1 }, (_, i) => i + start);
|
|
291
244
|
}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import h from "@macrostrat/hyper";
|
|
8
8
|
import { useState } from "react";
|
|
9
9
|
import { Button, ControlGroup, InputGroup } from "@blueprintjs/core";
|
|
10
|
-
import { RegionCardinality } from "@blueprintjs/table";
|
|
11
10
|
import { useSelector } from "../provider";
|
|
12
11
|
import type { TableAction } from "./types";
|
|
13
12
|
import { ALL_CARDINALITIES } from "./edit-actions";
|
|
@@ -35,29 +34,6 @@ function ScrollToRowControl() {
|
|
|
35
34
|
]);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
/** Clear the current selection. Auto-included: appears (on the right, being a
|
|
39
|
-
* general action) whenever something is selected — targets every cardinality
|
|
40
|
-
* except `"none"`. */
|
|
41
|
-
export const clearSelectionAction: TableAction = {
|
|
42
|
-
id: "clear-selection",
|
|
43
|
-
name: "Clear selection",
|
|
44
|
-
icon: "cross",
|
|
45
|
-
requiresEditable: false,
|
|
46
|
-
targets: [
|
|
47
|
-
RegionCardinality.CELLS,
|
|
48
|
-
RegionCardinality.FULL_ROWS,
|
|
49
|
-
RegionCardinality.FULL_COLUMNS,
|
|
50
|
-
RegionCardinality.FULL_TABLE,
|
|
51
|
-
],
|
|
52
|
-
// Empty selection maps to the FULL_TABLE cardinality, so the action still
|
|
53
|
-
// shows with nothing selected — grey it out there rather than act on nothing.
|
|
54
|
-
// (`disabled` is probed with a bare state, hence the `?? []`.)
|
|
55
|
-
disabled: (s: any) => (s.selection?.length ?? 0) === 0,
|
|
56
|
-
run(ctx) {
|
|
57
|
-
ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
37
|
/** Scroll to a 1-based row number. Meaningful for large, addressable sources;
|
|
62
38
|
* add it to `actions`. Present in the toolbar regardless of selection. */
|
|
63
39
|
export const scrollToRowAction: TableAction = {
|