@macrostrat/data-sheet 4.1.0 → 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 +40 -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 -184
- 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 -182
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +24 -50
- 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 -51
- 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-controls.cjs → table-actions.cjs} +7 -24
- 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 -19
- 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} +36 -97
- 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 -181
- 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 -150
- 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 +21 -4
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +5 -4
- package/dist/filters/operators.js +21 -4
- 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 +129 -103
- 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 +110 -84
- 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 +77 -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} +37 -23
- package/dist/provider/zustand-store.cjs.map +1 -0
- package/dist/{zustand-store.js → provider/zustand-store.js} +22 -8
- package/dist/provider/zustand-store.js.map +1 -0
- package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +68 -35
- 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} +66 -33
- package/dist/renderers/cell-renderer.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +40 -17
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +2 -2
- package/dist/renderers/column-header-cell.js +40 -17
- 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 +123 -226
- 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 -228
- package/src/actions/column-filter.ts +28 -63
- 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 -20
- 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} +53 -126
- 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} +144 -306
- package/src/data-view.ts +70 -0
- package/src/filters/operators.ts +38 -6
- package/src/index.ts +4 -3
- package/src/postgrest-table/data-loaders.ts +250 -181
- package/src/postgrest-table/index.ts +10 -9
- package/src/{utils → provider}/column-spec.ts +34 -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} +36 -14
- package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +146 -58
- package/src/renderers/column-header-cell.ts +51 -17
- package/src/renderers/index.ts +1 -0
- package/src/types.ts +143 -236
- 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.map +0 -1
- package/dist/actions/table-controls.js.map +0 -1
- package/dist/actions/toolbar.cjs +0 -246
- 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 -113
- package/dist/core.js.map +0 -1
- package/dist/provider.cjs +0 -191
- package/dist/provider.cjs.map +0 -1
- package/dist/provider.d.ts +0 -25
- package/dist/provider.js +0 -189
- 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 -250
- 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,256 @@
|
|
|
1
|
+
import { FocusedCellCoordinates, Region, RegionCardinality, Table2 } from '@blueprintjs/table';
|
|
2
|
+
import { ColumnSpec, ColumnSpecOptions } from './column-spec';
|
|
3
|
+
import { OverlayToaster } from '@blueprintjs/core';
|
|
4
|
+
import { DataViewCoreProps } from '../types';
|
|
5
|
+
import { DataViewRendererType } from './interactions.ts';
|
|
6
|
+
/** A single column sort entry for client-side sorting.
|
|
7
|
+
* Defined here (rather than in actions/types) to avoid circular imports. */
|
|
8
|
+
export interface ColumnSort {
|
|
9
|
+
key: string;
|
|
10
|
+
ascending: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Direction of keyboard navigation between cells. */
|
|
13
|
+
export type NavDirection = "up" | "down" | "left" | "right";
|
|
14
|
+
/**
|
|
15
|
+
* A structured, revertible description of a user edit. Emitted via the
|
|
16
|
+
* `onEdit` hook so a consumer can capture edits as operations (and, with the
|
|
17
|
+
* controlled-overlay API, own the edited state) instead of diffing
|
|
18
|
+
* `updatedData`. This is the write half of the data-sheet's read/write
|
|
19
|
+
* contract — the mirror of how data flows in.
|
|
20
|
+
*/
|
|
21
|
+
export type EditEvent<T = any> = {
|
|
22
|
+
type: "setCells";
|
|
23
|
+
cells: CellEdit[];
|
|
24
|
+
} | {
|
|
25
|
+
type: "deleteRows";
|
|
26
|
+
rowIndices: number[];
|
|
27
|
+
} | {
|
|
28
|
+
type: "restoreRows";
|
|
29
|
+
rowIndices: number[];
|
|
30
|
+
} | {
|
|
31
|
+
type: "addRow";
|
|
32
|
+
rowIndex: number;
|
|
33
|
+
value: Partial<T>;
|
|
34
|
+
} | {
|
|
35
|
+
type: "resetChanges";
|
|
36
|
+
};
|
|
37
|
+
export declare enum TableElementStatus {
|
|
38
|
+
DELETED = "deleted",
|
|
39
|
+
ADDED = "added"
|
|
40
|
+
}
|
|
41
|
+
/** A row's status value. The built-in `TableElementStatus` members
|
|
42
|
+
* (`"deleted"` / `"added"`) plus any consumer-defined status string (e.g.
|
|
43
|
+
* `"omitted"`). The `(string & {})` keeps autocomplete for the enum members
|
|
44
|
+
* while still accepting arbitrary strings. */
|
|
45
|
+
export type RowStatusValue = TableElementStatus | (string & {});
|
|
46
|
+
/** Presentation for a row status: applied to the row's cells and its header
|
|
47
|
+
* cell. Keyed by status value in `rowStatusStyles`. The library ships a
|
|
48
|
+
* default for `"deleted"` (dimmed + struck through, danger intent); consumers
|
|
49
|
+
* merge in styles for their own statuses (and may override the defaults). */
|
|
50
|
+
export interface RowStatusStyle {
|
|
51
|
+
/** Style merged onto each cell in a row with this status. */
|
|
52
|
+
cellStyle?: import('react').CSSProperties;
|
|
53
|
+
/** Style applied to the row's header cell. */
|
|
54
|
+
headerStyle?: import('react').CSSProperties;
|
|
55
|
+
/** Blueprint intent applied to the row's cells (precedence: validation >
|
|
56
|
+
* this > edited-green). */
|
|
57
|
+
intent?: import('@blueprintjs/core').Intent;
|
|
58
|
+
}
|
|
59
|
+
export type RowStatusStyles = Record<string, RowStatusStyle>;
|
|
60
|
+
/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged
|
|
61
|
+
* over this, so `"deleted"` keeps its look unless explicitly overridden. */
|
|
62
|
+
export declare const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles;
|
|
63
|
+
/** Context passed to a custom `rowHeaderRenderer`, so it can label and style
|
|
64
|
+
* the row header from the row's data and status (group-key labels, an
|
|
65
|
+
* omit indicator, etc.). Return a node to use as the header's name, or a
|
|
66
|
+
* nullish value to fall back to the default (1-based row number). */
|
|
67
|
+
export interface RowHeaderRenderContext<T = any> {
|
|
68
|
+
/** Data-row index (stable under sort/filter). */
|
|
69
|
+
rowIndex: number;
|
|
70
|
+
/** Visible (display) row index. */
|
|
71
|
+
visibleIndex: number;
|
|
72
|
+
/** The row's data (base, overlaid with edits if present). */
|
|
73
|
+
row: T | undefined;
|
|
74
|
+
/** The row's status, if any. */
|
|
75
|
+
status: RowStatusValue | undefined;
|
|
76
|
+
/** Convenience: `status === TableElementStatus.DELETED`. */
|
|
77
|
+
isDeleted: boolean;
|
|
78
|
+
/** The default label (`"${rowIndex + 1}"`). */
|
|
79
|
+
defaultLabel: string;
|
|
80
|
+
}
|
|
81
|
+
/** Property key holding a stable synthetic id on rows added in-table. Added
|
|
82
|
+
* rows aren't in the data provider, so they need their own identity to survive
|
|
83
|
+
* a provider re-fetch; it's carried on the row and preserved through edits. */
|
|
84
|
+
export declare const DS_ROW_ID = "__dsRowId";
|
|
85
|
+
/** Proxy stored during a copy operation, enabling backend-mediated paste
|
|
86
|
+
* for lazy-loaded tables where not all data is available locally. */
|
|
87
|
+
export interface ClipboardProxy {
|
|
88
|
+
cardinality: RegionCardinality;
|
|
89
|
+
/** Source row indices (for row/cell copies) */
|
|
90
|
+
rowIndices?: number[];
|
|
91
|
+
/** Source column keys (for column/cell copies) */
|
|
92
|
+
columnKeys?: string[];
|
|
93
|
+
/** The plain text written to the clipboard, used to verify the proxy
|
|
94
|
+
* is still valid on paste (i.e., clipboard hasn't been overwritten). */
|
|
95
|
+
text: string;
|
|
96
|
+
}
|
|
97
|
+
export interface DataSheetState<T> {
|
|
98
|
+
selection: Region[];
|
|
99
|
+
columnSpec: ColumnSpec[];
|
|
100
|
+
columnSpecOptions?: ColumnSpecOptions<T>;
|
|
101
|
+
/** When `true`, the loader's first-chunk auto-generation of `columnSpec` is
|
|
102
|
+
* suppressed — a function `columnSpec` derives it from the loaded rows
|
|
103
|
+
* instead (in `_DataSheet`). Set at init from the prop's shape. */
|
|
104
|
+
deferColumnSpec: boolean;
|
|
105
|
+
fillValueBaseCell: FocusedCellCoordinates | null;
|
|
106
|
+
focusedCell: FocusedCellCoordinates | null;
|
|
107
|
+
topLeftCell: FocusedCellCoordinates | null;
|
|
108
|
+
/**
|
|
109
|
+
* Set of row indices that have been added to the table,
|
|
110
|
+
* but not yet committed to the underlying data array.
|
|
111
|
+
*
|
|
112
|
+
* This is used to track which rows should be reverted when
|
|
113
|
+
* a "reset" action is performed.
|
|
114
|
+
*/
|
|
115
|
+
rowStatus: (RowStatusValue | undefined)[];
|
|
116
|
+
/** Presentation per row-status value (merged: defaults + the
|
|
117
|
+
* `rowStatusStyles` prop). Read by the cell renderer and row-header renderer
|
|
118
|
+
* to style rows by status. */
|
|
119
|
+
rowStatusStyles: RowStatusStyles;
|
|
120
|
+
updatedData: (T | null | undefined)[];
|
|
121
|
+
data: T[];
|
|
122
|
+
initialized: boolean;
|
|
123
|
+
columnWidthsIndex: Map<string, number>;
|
|
124
|
+
/** Active column/table filters. Keys are filter IDs, values carry the
|
|
125
|
+
* filter definition and its current configuration state. */
|
|
126
|
+
activeFilters: Map<string, {
|
|
127
|
+
filter: any;
|
|
128
|
+
state: any;
|
|
129
|
+
}>;
|
|
130
|
+
/** Clipboard proxy from the last copy operation */
|
|
131
|
+
clipboardProxy: ClipboardProxy | null;
|
|
132
|
+
/** Visible row indices when filters are active. `null` means show all rows. */
|
|
133
|
+
filteredRowIndices: number[] | null;
|
|
134
|
+
/** Active column sort entries for client-side sorting. */
|
|
135
|
+
columnSorts: ColumnSort[];
|
|
136
|
+
/** Whether selecting a cell automatically activates its surface (opens an
|
|
137
|
+
* editor/detail panel and, for editors, focuses it). `"manual"` opens only
|
|
138
|
+
* on click. */
|
|
139
|
+
cellInteraction: "auto" | "manual";
|
|
140
|
+
/** Runtime override of `cellInteraction`: while `false`, auto-activation is
|
|
141
|
+
* suppressed (set by pressing Escape, re-armed by clicking a cell) so the
|
|
142
|
+
* keyboard prioritizes navigation. */
|
|
143
|
+
autoActivateArmed: boolean;
|
|
144
|
+
/** Direction of the last keyboard navigation, used to place an editor's
|
|
145
|
+
* cursor on the side the user is travelling toward. `null` after a click. */
|
|
146
|
+
lastNavDirection: NavDirection | null;
|
|
147
|
+
/** The table's focusable holder element; editors return focus here when the
|
|
148
|
+
* cursor leaves them so arrow-key navigation resumes. */
|
|
149
|
+
tableElement: HTMLElement | null;
|
|
150
|
+
/** Whether the focused cell's surface (editor or detail panel) is open.
|
|
151
|
+
* Owned by the store — not per-popover — so navigation, clicks, and the
|
|
152
|
+
* Escape handler all agree on it. */
|
|
153
|
+
cellSurfaceOpen: boolean;
|
|
154
|
+
/** Optional observer called for every user edit as a structured
|
|
155
|
+
* `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a
|
|
156
|
+
* consumer capture edits as revertible operations. */
|
|
157
|
+
onEdit?: (event: EditEvent<T>) => void;
|
|
158
|
+
/** Row identity for the edit overlay — stable across a provider re-sort,
|
|
159
|
+
* unlike an array index. Defaults to `(row) => row?.id`; a data provider
|
|
160
|
+
* supplies its own (e.g. a PostgREST identity key). Used to re-attach edits
|
|
161
|
+
* when the loader replaces `data` with a re-ordered window. */
|
|
162
|
+
identity: (row: any) => string | number | null | undefined;
|
|
163
|
+
/** Edits/statuses held by identity for rows not currently loaded (server
|
|
164
|
+
* sources), re-attached when their row next arrives. */
|
|
165
|
+
pendingOverlayById: Map<string | number, {
|
|
166
|
+
edit?: any;
|
|
167
|
+
status?: TableElementStatus;
|
|
168
|
+
}>;
|
|
169
|
+
/** True when the consumer controls the `updatedData`/`rowStatus` overlay; the
|
|
170
|
+
* loader-boundary identity remap is skipped (the consumer owns it). */
|
|
171
|
+
controlledOverlay: boolean;
|
|
172
|
+
/** Whether row deletion is available. Set from the data provider: an explicit
|
|
173
|
+
* `provider` without `deleteRows` disables deletion entirely (the delete
|
|
174
|
+
* affordance greys out and the delete key is a no-op). Defaults to `true`. */
|
|
175
|
+
canDeleteRows: boolean;
|
|
176
|
+
/** Provider-backed, auto-refreshing row mutations for immediate-edit consumers
|
|
177
|
+
* (chiefly `DataPanel`). Each persists through the data provider and then
|
|
178
|
+
* re-fetches. Wired by the consumer that owns the provider + loader; exposed
|
|
179
|
+
* on the action context as `saveRows` / `deleteRows` / `insertRow` /
|
|
180
|
+
* `refresh`, so a selection action can edit without hand-wiring persistence.
|
|
181
|
+
* Absent when no persisting provider. */
|
|
182
|
+
rowEditing?: {
|
|
183
|
+
saveRows?: (rows: any[]) => Promise<void>;
|
|
184
|
+
deleteRows?: (ids: Array<string | number>) => Promise<void>;
|
|
185
|
+
insertRow?: (row: any) => Promise<void>;
|
|
186
|
+
refresh?: () => void;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
type DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;
|
|
190
|
+
export type StateUpdater<T> = T[] | ((state: T[]) => T[]);
|
|
191
|
+
export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
|
|
192
|
+
setSelection(selection: Region[]): void;
|
|
193
|
+
onDragValue(event: MouseEvent): void;
|
|
194
|
+
setUpdatedData(data: StateUpdater<T>): void;
|
|
195
|
+
onCellEdited(rowIndex: number, columnName: string, value: any): void;
|
|
196
|
+
onSelectionEdited(value: any): void;
|
|
197
|
+
onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
|
|
198
|
+
onColumnWidthChanged(columnIndex: number, newWidth: number): void;
|
|
199
|
+
moveFocusedCell(direction: NavDirection): void;
|
|
200
|
+
/** Suppress auto-activation until the next click (Escape enters nav mode). */
|
|
201
|
+
suppressAutoActivate(): void;
|
|
202
|
+
/** Re-arm auto-activation (a click re-enables auto-focus). */
|
|
203
|
+
armAutoActivate(): void;
|
|
204
|
+
/** Open the focused cell's surface (editor or detail panel). */
|
|
205
|
+
openCellSurface(): void;
|
|
206
|
+
/** Close the focused cell's surface. When `suppress` is true (the default,
|
|
207
|
+
* as for Escape), auto mode also enters navigation mode (auto-activation is
|
|
208
|
+
* suppressed until the next click). A click-dismiss passes `suppress: false`
|
|
209
|
+
* so it just closes without changing the global mode. */
|
|
210
|
+
closeCellSurface(opts?: {
|
|
211
|
+
suppress?: boolean;
|
|
212
|
+
}): void;
|
|
213
|
+
deleteSelectedRows(): void;
|
|
214
|
+
clearSelection(): void;
|
|
215
|
+
resetChanges(): void;
|
|
216
|
+
addRow(): void;
|
|
217
|
+
/** Activate or update a column/table filter.
|
|
218
|
+
* Filter is any object satisfying `TableFilter` from the actions module. */
|
|
219
|
+
setFilter(filterId: string, filter: any, filterState: any): void;
|
|
220
|
+
/** Remove a filter by ID */
|
|
221
|
+
removeFilter(filterId: string): void;
|
|
222
|
+
/** Remove all active filters */
|
|
223
|
+
clearFilters(): void;
|
|
224
|
+
/** Set or clear a column sort. Pass `null` for ascending to clear. */
|
|
225
|
+
setColumnSort(key: string, ascending: boolean | null): void;
|
|
226
|
+
/** Remove all active column sorts */
|
|
227
|
+
clearColumnSorts(): void;
|
|
228
|
+
/** Store a clipboard proxy for potential backend-mediated paste */
|
|
229
|
+
setClipboardProxy(proxy: ClipboardProxy | null): void;
|
|
230
|
+
onSelection(selection: Region[]): void;
|
|
231
|
+
scrollToRow(rowIndex: number): void;
|
|
232
|
+
tableRef: React.MutableRefObject<Table2> | null;
|
|
233
|
+
columnWidthsIndex: Map<string, number>;
|
|
234
|
+
defaultColumnWidth: number;
|
|
235
|
+
editable: boolean;
|
|
236
|
+
}
|
|
237
|
+
export type DataSheetProviderProps<T> = DataViewCoreProps<T> & {
|
|
238
|
+
toaster?: OverlayToaster;
|
|
239
|
+
viewType?: DataViewRendererType;
|
|
240
|
+
children?: React.ReactNode;
|
|
241
|
+
};
|
|
242
|
+
export interface VisibleCells {
|
|
243
|
+
rowIndexStart: number;
|
|
244
|
+
rowIndexEnd: number;
|
|
245
|
+
}
|
|
246
|
+
export type DataSheetStore<T> = DataSheetStoreMain<T>;
|
|
247
|
+
/** A single cell edit, used with `editCells` for batch updates. */
|
|
248
|
+
export interface CellEdit {
|
|
249
|
+
rowIndex: number;
|
|
250
|
+
column: string;
|
|
251
|
+
value: any;
|
|
252
|
+
/** The underlying row (base data). Populated on emitted `onEdit` events so a
|
|
253
|
+
* handler can address the row (identity) without reaching into the store. */
|
|
254
|
+
row?: any;
|
|
255
|
+
}
|
|
256
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var TableElementStatus = /* @__PURE__ */ ((TableElementStatus2) => {
|
|
2
|
+
TableElementStatus2["DELETED"] = "deleted";
|
|
3
|
+
TableElementStatus2["ADDED"] = "added";
|
|
4
|
+
return TableElementStatus2;
|
|
5
|
+
})(TableElementStatus || {});
|
|
6
|
+
const DEFAULT_ROW_STATUS_STYLES = {
|
|
7
|
+
[
|
|
8
|
+
"deleted"
|
|
9
|
+
/* DELETED */
|
|
10
|
+
]: {
|
|
11
|
+
cellStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
12
|
+
headerStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
13
|
+
intent: "danger"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const DS_ROW_ID = "__dsRowId";
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_ROW_STATUS_STYLES,
|
|
19
|
+
DS_ROW_ID,
|
|
20
|
+
TableElementStatus
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/provider/types.ts"],"sourcesContent":["import type {\n FocusedCellCoordinates,\n Region,\n RegionCardinality,\n Table2,\n} from \"@blueprintjs/table\";\nimport type { ColumnSpec, ColumnSpecOptions } from \"./column-spec\";\nimport { OverlayToaster } from \"@blueprintjs/core\";\nimport { DataViewCoreProps } from \"../types\";\nimport { DataViewRendererType } from \"./interactions.ts\";\n\n/** A single column sort entry for client-side sorting.\n * Defined here (rather than in actions/types) to avoid circular imports. */\nexport interface ColumnSort {\n key: string;\n ascending: boolean;\n}\n\n/** Direction of keyboard navigation between cells. */\nexport type NavDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\n/**\n * A structured, revertible description of a user edit. Emitted via the\n * `onEdit` hook so a consumer can capture edits as operations (and, with the\n * controlled-overlay API, own the edited state) instead of diffing\n * `updatedData`. This is the write half of the data-sheet's read/write\n * contract — the mirror of how data flows in.\n */\nexport type EditEvent<T = any> =\n | { type: \"setCells\"; cells: CellEdit[] }\n | { type: \"deleteRows\"; rowIndices: number[] }\n | { type: \"restoreRows\"; rowIndices: number[] }\n | { type: \"addRow\"; rowIndex: number; value: Partial<T> }\n | { type: \"resetChanges\" };\n\nexport enum TableElementStatus {\n DELETED = \"deleted\",\n ADDED = \"added\",\n}\n\n/** A row's status value. The built-in `TableElementStatus` members\n * (`\"deleted\"` / `\"added\"`) plus any consumer-defined status string (e.g.\n * `\"omitted\"`). The `(string & {})` keeps autocomplete for the enum members\n * while still accepting arbitrary strings. */\nexport type RowStatusValue = TableElementStatus | (string & {});\n\n/** Presentation for a row status: applied to the row's cells and its header\n * cell. Keyed by status value in `rowStatusStyles`. The library ships a\n * default for `\"deleted\"` (dimmed + struck through, danger intent); consumers\n * merge in styles for their own statuses (and may override the defaults). */\nexport interface RowStatusStyle {\n /** Style merged onto each cell in a row with this status. */\n cellStyle?: import(\"react\").CSSProperties;\n /** Style applied to the row's header cell. */\n headerStyle?: import(\"react\").CSSProperties;\n /** Blueprint intent applied to the row's cells (precedence: validation >\n * this > edited-green). */\n intent?: import(\"@blueprintjs/core\").Intent;\n}\n\nexport type RowStatusStyles = Record<string, RowStatusStyle>;\n\n/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged\n * over this, so `\"deleted\"` keeps its look unless explicitly overridden. */\nexport const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {\n [TableElementStatus.DELETED]: {\n cellStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n headerStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n intent: \"danger\",\n },\n};\n\n/** Context passed to a custom `rowHeaderRenderer`, so it can label and style\n * the row header from the row's data and status (group-key labels, an\n * omit indicator, etc.). Return a node to use as the header's name, or a\n * nullish value to fall back to the default (1-based row number). */\nexport interface RowHeaderRenderContext<T = any> {\n /** Data-row index (stable under sort/filter). */\n rowIndex: number;\n /** Visible (display) row index. */\n visibleIndex: number;\n /** The row's data (base, overlaid with edits if present). */\n row: T | undefined;\n /** The row's status, if any. */\n status: RowStatusValue | undefined;\n /** Convenience: `status === TableElementStatus.DELETED`. */\n isDeleted: boolean;\n /** The default label (`\"${rowIndex + 1}\"`). */\n defaultLabel: string;\n}\n\n/** Property key holding a stable synthetic id on rows added in-table. Added\n * rows aren't in the data provider, so they need their own identity to survive\n * a provider re-fetch; it's carried on the row and preserved through edits. */\nexport const DS_ROW_ID = \"__dsRowId\";\n\n/** Proxy stored during a copy operation, enabling backend-mediated paste\n * for lazy-loaded tables where not all data is available locally. */\nexport interface ClipboardProxy {\n cardinality: RegionCardinality;\n /** Source row indices (for row/cell copies) */\n rowIndices?: number[];\n /** Source column keys (for column/cell copies) */\n columnKeys?: string[];\n /** The plain text written to the clipboard, used to verify the proxy\n * is still valid on paste (i.e., clipboard hasn't been overwritten). */\n text: string;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n columnSpecOptions?: ColumnSpecOptions<T>;\n /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is\n * suppressed — a function `columnSpec` derives it from the loaded rows\n * instead (in `_DataSheet`). Set at init from the prop's shape. */\n deferColumnSpec: boolean;\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n /**\n * Set of row indices that have been added to the table,\n * but not yet committed to the underlying data array.\n *\n * This is used to track which rows should be reverted when\n * a \"reset\" action is performed.\n */\n rowStatus: (RowStatusValue | undefined)[];\n /** Presentation per row-status value (merged: defaults + the\n * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer\n * to style rows by status. */\n rowStatusStyles: RowStatusStyles;\n // Sparse data structure for updated data\n updatedData: (T | null | undefined)[];\n data: T[];\n initialized: boolean;\n columnWidthsIndex: Map<string, number>;\n /** Active column/table filters. Keys are filter IDs, values carry the\n * filter definition and its current configuration state. */\n activeFilters: Map<string, { filter: any; state: any }>;\n /** Clipboard proxy from the last copy operation */\n clipboardProxy: ClipboardProxy | null;\n /** Visible row indices when filters are active. `null` means show all rows. */\n filteredRowIndices: number[] | null;\n /** Active column sort entries for client-side sorting. */\n columnSorts: ColumnSort[];\n /** Whether selecting a cell automatically activates its surface (opens an\n * editor/detail panel and, for editors, focuses it). `\"manual\"` opens only\n * on click. */\n cellInteraction: \"auto\" | \"manual\";\n /** Runtime override of `cellInteraction`: while `false`, auto-activation is\n * suppressed (set by pressing Escape, re-armed by clicking a cell) so the\n * keyboard prioritizes navigation. */\n autoActivateArmed: boolean;\n /** Direction of the last keyboard navigation, used to place an editor's\n * cursor on the side the user is travelling toward. `null` after a click. */\n lastNavDirection: NavDirection | null;\n /** The table's focusable holder element; editors return focus here when the\n * cursor leaves them so arrow-key navigation resumes. */\n tableElement: HTMLElement | null;\n /** Whether the focused cell's surface (editor or detail panel) is open.\n * Owned by the store — not per-popover — so navigation, clicks, and the\n * Escape handler all agree on it. */\n cellSurfaceOpen: boolean;\n /** Optional observer called for every user edit as a structured\n * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a\n * consumer capture edits as revertible operations. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Row identity for the edit overlay — stable across a provider re-sort,\n * unlike an array index. Defaults to `(row) => row?.id`; a data provider\n * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits\n * when the loader replaces `data` with a re-ordered window. */\n identity: (row: any) => string | number | null | undefined;\n /** Edits/statuses held by identity for rows not currently loaded (server\n * sources), re-attached when their row next arrives. */\n pendingOverlayById: Map<\n string | number,\n { edit?: any; status?: TableElementStatus }\n >;\n /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the\n * loader-boundary identity remap is skipped (the consumer owns it). */\n controlledOverlay: boolean;\n /** Whether row deletion is available. Set from the data provider: an explicit\n * `provider` without `deleteRows` disables deletion entirely (the delete\n * affordance greys out and the delete key is a no-op). Defaults to `true`. */\n canDeleteRows: boolean;\n /** Provider-backed, auto-refreshing row mutations for immediate-edit consumers\n * (chiefly `DataPanel`). Each persists through the data provider and then\n * re-fetches. Wired by the consumer that owns the provider + loader; exposed\n * on the action context as `saveRows` / `deleteRows` / `insertRow` /\n * `refresh`, so a selection action can edit without hand-wiring persistence.\n * Absent when no persisting provider. */\n rowEditing?: {\n saveRows?: (rows: any[]) => Promise<void>;\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n insertRow?: (row: any) => Promise<void>;\n refresh?: () => void;\n };\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;\nexport type StateUpdater<T> = T[] | ((state: T[]) => T[]);\n\nexport interface DataSheetStoreMain<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(event: MouseEvent): void;\n setUpdatedData(data: StateUpdater<T>): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n onSelectionEdited(value: any): void;\n onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;\n onColumnWidthChanged(columnIndex: number, newWidth: number): void;\n moveFocusedCell(direction: NavDirection): void;\n /** Suppress auto-activation until the next click (Escape enters nav mode). */\n suppressAutoActivate(): void;\n /** Re-arm auto-activation (a click re-enables auto-focus). */\n armAutoActivate(): void;\n /** Open the focused cell's surface (editor or detail panel). */\n openCellSurface(): void;\n /** Close the focused cell's surface. When `suppress` is true (the default,\n * as for Escape), auto mode also enters navigation mode (auto-activation is\n * suppressed until the next click). A click-dismiss passes `suppress: false`\n * so it just closes without changing the global mode. */\n closeCellSurface(opts?: { suppress?: boolean }): void;\n deleteSelectedRows(): void;\n clearSelection(): void;\n resetChanges(): void;\n addRow(): void;\n /** Activate or update a column/table filter.\n * Filter is any object satisfying `TableFilter` from the actions module. */\n setFilter(filterId: string, filter: any, filterState: any): void;\n /** Remove a filter by ID */\n removeFilter(filterId: string): void;\n /** Remove all active filters */\n clearFilters(): void;\n /** Set or clear a column sort. Pass `null` for ascending to clear. */\n setColumnSort(key: string, ascending: boolean | null): void;\n /** Remove all active column sorts */\n clearColumnSorts(): void;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n //initialize(props: Partial<DataSheetStoreMain<T>>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2> | null;\n columnWidthsIndex: Map<string, number>;\n defaultColumnWidth: number;\n // Editable is not optional on store\n editable: boolean;\n}\n\nexport type DataSheetProviderProps<T> = DataViewCoreProps<T> & {\n toaster?: OverlayToaster;\n viewType?: DataViewRendererType;\n children?: React.ReactNode;\n};\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport type DataSheetStore<T> = DataSheetStoreMain<T>;\n\n/** A single cell edit, used with `editCells` for batch updates. */\nexport interface CellEdit {\n rowIndex: number;\n column: string;\n value: any;\n /** The underlying row (base data). Populated on emitted `onEdit` events so a\n * handler can address the row (identity) without reaching into the store. */\n row?: any;\n}\n"],"names":["TableElementStatus"],"mappings":"AAmCO,IAAK,uCAAAA,wBAAL;AACLA,sBAAA,SAAA,IAAU;AACVA,sBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AA6BL,MAAM,4BAA6C;AAAA,EACxD;AAAA,IAAC;AAAA;AAAA,KAA6B;AAAA,IAC5B,WAAW,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC3C,aAAa,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC7C,QAAQ;AAAA,EAAA;AAEZ;AAwBO,MAAM,YAAY;"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const types = require("./types.cjs");
|
|
4
4
|
const table = require("@blueprintjs/table");
|
|
5
|
-
const index = require("./utils/index.cjs");
|
|
6
5
|
const update = require("immutability-helper");
|
|
7
|
-
const selection = require("
|
|
6
|
+
const selection = require("../actions/selection.cjs");
|
|
8
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
9
8
|
const update__default = /* @__PURE__ */ _interopDefault(update);
|
|
10
9
|
let _addedRowCounter = 0;
|
|
@@ -16,6 +15,7 @@ function createZustandStore(set, get) {
|
|
|
16
15
|
rowStatus: [],
|
|
17
16
|
rowStatusStyles: types.DEFAULT_ROW_STATUS_STYLES,
|
|
18
17
|
columnSpec: [],
|
|
18
|
+
deferColumnSpec: false,
|
|
19
19
|
defaultColumnWidth: 150,
|
|
20
20
|
editable: false,
|
|
21
21
|
selection: [],
|
|
@@ -170,7 +170,7 @@ function createZustandStore(set, get) {
|
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
resetChanges(regions) {
|
|
173
|
-
set((state) => resetChangesForSelection(state, regions));
|
|
173
|
+
set((state) => resetChangesForSelection(state, regions ?? []));
|
|
174
174
|
get().onEdit?.({ type: "resetChanges" });
|
|
175
175
|
},
|
|
176
176
|
onColumnWidthChanged(columnIx, newWidth) {
|
|
@@ -217,13 +217,13 @@ function createZustandStore(set, get) {
|
|
|
217
217
|
clearSelection() {
|
|
218
218
|
const edits = [];
|
|
219
219
|
set((state) => {
|
|
220
|
-
const { selection:
|
|
220
|
+
const { selection: selection$1, updatedData, columnSpec, data } = state;
|
|
221
221
|
const numVisible = visibleRowCount(state);
|
|
222
222
|
let spec = {};
|
|
223
|
-
for (const region of
|
|
223
|
+
for (const region of selection$1) {
|
|
224
224
|
const { cols, rows } = region;
|
|
225
|
-
const rowRange =
|
|
226
|
-
const colRange =
|
|
225
|
+
const rowRange = selection.range(rows ?? [0, numVisible - 1]);
|
|
226
|
+
const colRange = selection.range(cols ?? [0, columnSpec.length - 1]);
|
|
227
227
|
for (const visibleRow of rowRange) {
|
|
228
228
|
const row = toDataRowIndex(state, visibleRow);
|
|
229
229
|
const rowIsDeleted = state.rowStatus[row] === types.TableElementStatus.DELETED;
|
|
@@ -234,7 +234,12 @@ function createZustandStore(set, get) {
|
|
|
234
234
|
const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
|
|
235
235
|
if (currentValue != null && currentValue !== "") {
|
|
236
236
|
vals[key] = "";
|
|
237
|
-
edits.push({
|
|
237
|
+
edits.push({
|
|
238
|
+
rowIndex: row,
|
|
239
|
+
column: key,
|
|
240
|
+
value: "",
|
|
241
|
+
row: data[row]
|
|
242
|
+
});
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
245
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
@@ -251,7 +256,11 @@ function createZustandStore(set, get) {
|
|
|
251
256
|
},
|
|
252
257
|
onSelection(selection2) {
|
|
253
258
|
set((state) => {
|
|
254
|
-
|
|
259
|
+
const isSameAsPrevSelection = selectionEquals(
|
|
260
|
+
selection2,
|
|
261
|
+
state.selection
|
|
262
|
+
);
|
|
263
|
+
if (isSameAsPrevSelection && singleFocusedCell(selection2) == null) {
|
|
255
264
|
return {
|
|
256
265
|
selection: [],
|
|
257
266
|
focusedCell: null,
|
|
@@ -275,21 +284,26 @@ function createZustandStore(set, get) {
|
|
|
275
284
|
onSelectionEdited(value) {
|
|
276
285
|
const edits = [];
|
|
277
286
|
set((state) => {
|
|
278
|
-
const { selection:
|
|
287
|
+
const { selection: selection$1, updatedData, columnSpec, editable } = state;
|
|
279
288
|
if (!editable) return {};
|
|
280
289
|
const numVisible = visibleRowCount(state);
|
|
281
290
|
let spec = {};
|
|
282
|
-
for (const region of
|
|
291
|
+
for (const region of selection$1) {
|
|
283
292
|
const { cols, rows } = region;
|
|
284
|
-
const rowRange =
|
|
285
|
-
const colRange =
|
|
293
|
+
const rowRange = selection.range(rows ?? [0, numVisible - 1]);
|
|
294
|
+
const colRange = selection.range(cols ?? [0, columnSpec.length - 1]);
|
|
286
295
|
for (const visibleRow of rowRange) {
|
|
287
296
|
const row = toDataRowIndex(state, visibleRow);
|
|
288
297
|
let vals = {};
|
|
289
298
|
for (const col of colRange) {
|
|
290
299
|
const key = columnSpec[col].key;
|
|
291
300
|
vals[key] = value;
|
|
292
|
-
edits.push({
|
|
301
|
+
edits.push({
|
|
302
|
+
rowIndex: row,
|
|
303
|
+
column: key,
|
|
304
|
+
value,
|
|
305
|
+
row: state.data[row]
|
|
306
|
+
});
|
|
293
307
|
}
|
|
294
308
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
295
309
|
spec[row] = { [op]: vals };
|
|
@@ -433,11 +447,11 @@ function singleFocusedCell(sel) {
|
|
|
433
447
|
if (sel?.length !== 1) return null;
|
|
434
448
|
return topLeftCell(sel, true);
|
|
435
449
|
}
|
|
436
|
-
function fillValues(state,
|
|
450
|
+
function fillValues(state, selection$1) {
|
|
437
451
|
const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;
|
|
438
|
-
let regions =
|
|
452
|
+
let regions = selection$1.map((region) => {
|
|
439
453
|
const { cols, rows } = region;
|
|
440
|
-
const [col2] = cols;
|
|
454
|
+
const [col2] = cols ?? [];
|
|
441
455
|
return { cols: [col2, col2], rows };
|
|
442
456
|
});
|
|
443
457
|
if (!editable || fillValueBaseCell == null) return updatedData;
|
|
@@ -448,7 +462,7 @@ function fillValues(state, selection2) {
|
|
|
448
462
|
const spec = {};
|
|
449
463
|
for (const region of regions) {
|
|
450
464
|
const { rows } = region;
|
|
451
|
-
for (const visibleRow of
|
|
465
|
+
for (const visibleRow of selection.range(rows ?? [])) {
|
|
452
466
|
const row = toDataRowIndex(state, visibleRow);
|
|
453
467
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
454
468
|
spec[row] = { [op]: { [key]: value } };
|
|
@@ -530,14 +544,14 @@ function resetChangesForSelection(state, selection$1) {
|
|
|
530
544
|
};
|
|
531
545
|
}
|
|
532
546
|
}
|
|
533
|
-
function insertItemAtIndex(arr,
|
|
534
|
-
if (arr.length <
|
|
547
|
+
function insertItemAtIndex(arr, index, item) {
|
|
548
|
+
if (arr.length < index) {
|
|
535
549
|
const newArr = [...arr];
|
|
536
|
-
newArr.length =
|
|
537
|
-
newArr[
|
|
550
|
+
newArr.length = index;
|
|
551
|
+
newArr[index] = item;
|
|
538
552
|
return newArr;
|
|
539
553
|
}
|
|
540
|
-
return [...arr.slice(0,
|
|
554
|
+
return [...arr.slice(0, index), item, ...arr.slice(index)];
|
|
541
555
|
}
|
|
542
556
|
exports.createZustandStore = createZustandStore;
|
|
543
557
|
exports.singleFocusedCell = singleFocusedCell;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zustand-store.cjs","sources":["../../src/provider/zustand-store.ts"],"sourcesContent":["import {\n DataSheetState,\n DataSheetStore,\n DataSheetStoreMain,\n DEFAULT_ROW_STATUS_STYLES,\n DS_ROW_ID,\n StateUpdater,\n TableElementStatus,\n} from \"./types.ts\";\nimport {\n type FocusedCellCoordinates,\n type Region,\n RegionCardinality,\n} from \"@blueprintjs/table\";\nimport update, { Spec } from \"immutability-helper\";\nimport {\n getSelectedColumnKeys,\n getSelectedRowIndices,\n getSelectionCardinality,\n range,\n} from \"../actions\";\n\n/** Monotonic counter for synthetic ids on in-table-added rows. */\nlet _addedRowCounter = 0;\n\nexport function createZustandStore<T>(set, get): DataSheetStoreMain<T> {\n return {\n /** All the data in the table */\n data: [],\n updatedData: [],\n rowStatus: [],\n rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,\n columnSpec: [],\n deferColumnSpec: false,\n defaultColumnWidth: 150,\n editable: false,\n selection: [],\n fillValueBaseCell: null,\n focusedCell: null,\n topLeftCell: null,\n initialized: false,\n tableRef: null,\n // This is a placeholder\n enableColumnReordering: false,\n activeFilters: new Map<string, { filter: any; state: any }>(),\n columnSorts: [],\n clipboardProxy: null,\n filteredRowIndices: null,\n cellInteraction: \"auto\",\n autoActivateArmed: true,\n lastNavDirection: null,\n tableElement: null,\n cellSurfaceOpen: false,\n identity: (row: any) => row?.id,\n pendingOverlayById: new Map(),\n controlledOverlay: false,\n canDeleteRows: true,\n setSelection(selection: Region[]) {\n set(updateSelection(selection));\n },\n columnWidthsIndex: new Map<string, number>(),\n suppressAutoActivate() {\n set({ autoActivateArmed: false });\n },\n armAutoActivate() {\n set({ autoActivateArmed: true });\n },\n openCellSurface() {\n set({ cellSurfaceOpen: true });\n },\n closeCellSurface(opts?: { suppress?: boolean }) {\n const suppress = opts?.suppress ?? true;\n set((state) => ({\n cellSurfaceOpen: false,\n // Escape (suppress) drops auto mode into navigation mode so surfaces\n // stop auto-opening until the next click. A click-dismiss doesn't.\n autoActivateArmed:\n suppress && state.cellInteraction === \"auto\"\n ? false\n : state.autoActivateArmed,\n }));\n },\n moveFocusedCell(direction: \"up\" | \"down\" | \"left\" | \"right\") {\n set((state) => {\n const { topLeftCell } = state;\n if (topLeftCell == null) return {};\n let { col, row } = topLeftCell;\n switch (direction) {\n case \"up\":\n row = Math.max(0, row - 1);\n break;\n case \"down\":\n row = Math.min(\n row + 1,\n Math.max(state.data.length, state.updatedData.length) - 1,\n );\n break;\n case \"left\":\n col = Math.max(0, col - 1);\n break;\n case \"right\":\n col = Math.min(col + 1, state.columnSpec.length - 1);\n break;\n }\n const region: Region = { cols: [col, col], rows: [row, row] };\n // Record the travel direction (so the next editor places its cursor on\n // the side we're moving toward) and open the new cell's surface only\n // when auto-activation is armed.\n return {\n ...updateSelection([region]),\n lastNavDirection: direction,\n cellSurfaceOpen:\n state.cellInteraction === \"auto\" && state.autoActivateArmed,\n };\n });\n },\n addRow(row: Partial<T> = {} as T) {\n /** Add a new row. If there is a selection, use the last row index to determine\n * where to insert the new row. Otherwise, append to the end of the data. */\n let newIndex = -1;\n set((state) => {\n const { updatedData, data, selection, rowStatus } = state;\n\n const lastRowIndex =\n getLastRowIndex(selection) ??\n Math.max(data.length, updatedData.length) - 1;\n // Use $set at a specific index to correctly extend the sparse array.\n // $splice fails when the target index exceeds the array length.\n newIndex = lastRowIndex + 1;\n\n // Stamp a stable synthetic id so the added row survives a provider\n // re-fetch (it has no provider row to match on). Its values live in the\n // overlay (`updatedData`), which the loader-boundary remap re-appends.\n const newRow = {\n ...(row as any),\n [DS_ROW_ID]: `__added_${_addedRowCounter++}`,\n } as T;\n\n return {\n updatedData: insertItemAtIndex(updatedData, newIndex, newRow),\n data: insertItemAtIndex(data, newIndex, newRow),\n rowStatus: insertItemAtIndex(\n rowStatus,\n newIndex,\n TableElementStatus.ADDED,\n ),\n };\n });\n get().onEdit?.({ type: \"addRow\", rowIndex: newIndex, value: row });\n },\n setUpdatedData(data: StateUpdater<T>) {\n if (Array.isArray(data)) {\n set({ updatedData: data });\n } else {\n set((state) => {\n return { updatedData: data(state.updatedData) };\n });\n }\n },\n deleteSelectedRows() {\n // Deletion is a provider capability: if the active data provider can't\n // delete (no `deleteRows`), the whole affordance is disabled.\n if (!get().canDeleteRows) return;\n // Remove selected rows from the data and updatedData arrays\n let deletedIndices: number[] = [];\n set((state) => {\n const { selection, deletedRows } = state;\n const rowIndices = getRowIndices(selection);\n deletedIndices = rowIndices;\n\n // Delete rows from both updatedData and data\n\n // If rows are in addedRows, we just delete them outright from the data and updatedData arrays\n const { addedRows } = state;\n\n const rowsNewlyDeleted = new Set(rowIndices);\n\n // We outright remove rows that have not been added to the data array\n const rowsToRemoveFromDataArrays = new Set(\n rowIndices.filter(\n (d) => state.rowStatus[d] == TableElementStatus.ADDED,\n ),\n );\n // ...otherwise we set them to 'deleted'\n const rowsToMarkAsDeleted = rowsNewlyDeleted.difference(\n rowsToRemoveFromDataArrays,\n );\n\n let data = state.data;\n let updatedData = state.updatedData;\n let rowStatus = state.rowStatus;\n if (rowsToMarkAsDeleted.size > 0) {\n let spec: Spec<TableElementStatus[]> = {};\n for (const ix of rowsToMarkAsDeleted) {\n spec[ix] = { $set: TableElementStatus.DELETED };\n }\n rowStatus = update(rowStatus, spec);\n }\n\n if (rowsToRemoveFromDataArrays.size > 0) {\n const filterFunc = (_, i) => !rowsToRemoveFromDataArrays.has(i);\n data = data.filter(filterFunc);\n updatedData = updatedData.filter(filterFunc);\n rowStatus = rowStatus.filter(filterFunc);\n }\n\n // Remove selected rows and reset selection\n return {\n selection: [],\n data,\n updatedData,\n rowStatus,\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n });\n if (deletedIndices.length > 0) {\n get().onEdit?.({ type: \"deleteRows\", rowIndices: deletedIndices });\n }\n },\n resetChanges(regions?: Region[]) {\n // Reset the updated data to the initial data\n set((state) => resetChangesForSelection(state, regions ?? []));\n get().onEdit?.({ type: \"resetChanges\" });\n },\n onColumnWidthChanged(columnIx: number, newWidth: number) {\n set((state) => {\n const { columnSpec, columnWidthsIndex } = state;\n const colKey = columnSpec[columnIx].key;\n const newColumnWidths = new Map(columnWidthsIndex);\n newColumnWidths.set(colKey, newWidth);\n return { columnWidthsIndex: newColumnWidths };\n });\n },\n onDragValue(event: MouseEvent) {\n set((state) => {\n return { fillValueBaseCell: state.focusedCell };\n });\n event.preventDefault();\n },\n onCellEdited(rowIndex: number, columnName: string, value: any) {\n set((state) => {\n const { editable, updatedData, data } = state;\n if (!editable) return {};\n let rowSpec: any;\n\n // Check to see if the new value is meaningfully different from the old\n // one. Empty string and null/undefined are treated as equivalent, so\n // focusing (and blurring) an empty cell doesn't record a phantom edit.\n const oldValue = data[rowIndex]?.[columnName];\n if (!valuesAreEquivalent(value, oldValue)) {\n const rowOp = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n rowSpec = { [rowOp]: { [columnName]: value } };\n } else if (updatedData[rowIndex] != null) {\n // No change — drop any prior override for this cell.\n rowSpec = { $unset: [columnName] };\n } else {\n // No change and no prior override: nothing to do. (`$unset` on an\n // absent row would throw in immutability-helper.)\n return {};\n }\n const spec: Spec<T[]> = { [rowIndex]: rowSpec };\n return { updatedData: update(updatedData, spec) };\n });\n if (get().editable) {\n get().onEdit?.({\n type: \"setCells\",\n cells: [\n { rowIndex, column: columnName, value, row: get().data[rowIndex] },\n ],\n });\n }\n },\n clearSelection() {\n const edits: {\n rowIndex: number;\n column: string;\n value: any;\n row?: any;\n }[] = [];\n set((state) => {\n // Delete all selected cells\n const { selection, updatedData, columnSpec, data } = state;\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n // Don't clear row if it has been deleted\n const rowIsDeleted =\n state.rowStatus[row] === TableElementStatus.DELETED;\n if (rowIsDeleted) continue;\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];\n if (currentValue != null && currentValue !== \"\") {\n vals[key] = \"\";\n edits.push({\n rowIndex: row,\n column: key,\n value: \"\",\n row: data[row],\n });\n }\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onSelection(selection: Region[]) {\n set((state) => {\n const isSameAsPrevSelection = selectionEquals(\n selection,\n state.selection,\n );\n if (\n isSameAsPrevSelection &&\n singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode\n ) {\n // If the selection is the same as the current selection, remove the selection.\n // In practice this only happens for whole-row and whole-column selections\n return {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n cellSurfaceOpen: false,\n };\n }\n\n let spec = updateSelection(selection);\n if (state.fillValueBaseCell != null) {\n spec.updatedData = fillValues(state, selection);\n }\n // A click (user selection) re-arms auto-activation and clears the\n // travel direction so the editor opens with a default cursor.\n spec.autoActivateArmed = true;\n spec.lastNavDirection = null;\n // Only open when the selection actually MOVES to a (single) cell.\n // A click on the already-selected cell leaves open-state to the\n // target's click toggle — this avoids racing the selection event\n // (which fires on mousedown, possibly more than once) and is what\n // makes both re-focus-to-open and click-to-close reliable.\n if (!selectionEquals(selection, state.selection)) {\n spec.cellSurfaceOpen = singleFocusedCell(selection) != null;\n }\n return spec;\n });\n },\n onSelectionEdited(value: any) {\n // Apply the same value to all selected cells\n const edits: {\n rowIndex: number;\n column: string;\n value: any;\n row?: any;\n }[] = [];\n set((state) => {\n const { selection, updatedData, columnSpec, editable } = state;\n if (!editable) return {};\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n vals[key] = value;\n edits.push({\n rowIndex: row,\n column: key,\n value,\n row: state.data[row],\n });\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onColumnsReordered(oldIndex: number, newIndex: number, length: number) {\n set((state) => {\n if (!state.enableColumnReordering) return {};\n const { columnSpec } = state;\n const newSpec = [...columnSpec];\n const removed = newSpec.splice(oldIndex, length);\n newSpec.splice(newIndex, 0, ...removed);\n return { columnSpec: newSpec };\n });\n },\n scrollToRow(rowIndex: number) {\n const tableRef = get().tableRef;\n if (tableRef.current == null) return;\n tableRef.current.scrollToRegion({\n rows: [rowIndex, rowIndex],\n });\n },\n // Sort/filter state changes flow to the data provider (via the loader,\n // which reads `activeFilters`/`columnSorts` and re-fetches). The library no\n // longer computes a client-side `filteredRowIndices` view — `data` arrives\n // already ordered from the provider (in memory for a local source).\n setFilter(filterId: string, filter: any, filterState: any) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.set(filterId, { filter, state: filterState });\n return { activeFilters: newFilters };\n });\n },\n removeFilter(filterId: string) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.delete(filterId);\n return { activeFilters: newFilters };\n });\n },\n clearFilters() {\n set(() => ({\n activeFilters: new Map<string, { filter: any; state: any }>(),\n }));\n },\n setColumnSort(key: string, ascending: boolean | null) {\n set((state) => {\n let newSorts;\n if (ascending == null) {\n newSorts = state.columnSorts.filter((s) => s.key !== key);\n } else {\n const without = state.columnSorts.filter((s) => s.key !== key);\n newSorts = [...without, { key, ascending }];\n }\n return { columnSorts: newSorts };\n });\n },\n clearColumnSorts() {\n set(() => ({ columnSorts: [] }));\n },\n setClipboardProxy(proxy) {\n set({ clipboardProxy: proxy });\n },\n };\n}\n\nexport function updateSelection<T>(selection: Region[]) {\n const focusedCell = singleFocusedCell(selection);\n let spec: Partial<DataSheetState<T>> = {\n selection,\n focusedCell,\n topLeftCell: topLeftCell(selection),\n };\n if (focusedCell != null) {\n spec.fillValueBaseCell = null;\n }\n return spec;\n}\n\nfunction getLastRowIndex(regions: Region[]): number | null {\n /** Get the last row index from a selection of regions */\n if (regions == null || regions.length === 0) return null;\n let lastRow = -1;\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n lastRow = Math.max(lastRow, rows[1]);\n }\n if (lastRow < 0) {\n /** If no valid rows are found, return null */\n return null;\n }\n return lastRow;\n}\n\nfunction getRowIndices(regions: Region[]): number[] {\n /** Get the row indices from a selection of regions */\n if (regions == null || regions.length === 0) return [];\n const rowIndices = new Set<number>();\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n for (let i = rows[0]; i <= rows[1]; i++) {\n rowIndices.add(i);\n }\n }\n return Array.from(rowIndices).sort((a, b) => a - b);\n}\n\nexport function topLeftCell(\n regions: Region[],\n requireSolitaryCell: boolean = false,\n): FocusedCellCoordinates | null {\n /** Top left cell of a ranged selection */\n if (regions == null) return null;\n const [region] = regions;\n if (region == null) return null;\n const { cols, rows } = region;\n if (cols == null || rows == null) return null;\n if (requireSolitaryCell && (cols[0] !== cols[1] || rows[0] !== rows[1]))\n return null;\n return { col: cols[0], row: rows[0], focusSelectionIndex: 0 };\n}\n\nfunction selectionEquals(a: Region[], b: Region[]): boolean {\n /** Check if two selections are equal */\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n const regionA = a[i];\n const regionB = b[i];\n\n const colsA = regionA.cols ?? [];\n const colsB = regionB.cols ?? [];\n\n const rowsA = regionA.rows ?? [];\n const rowsB = regionB.rows ?? [];\n\n if (\n colsA.length !== colsB.length ||\n rowsA.length !== rowsB.length ||\n colsA[0] !== colsB[0] ||\n colsA[1] !== colsB[1] ||\n rowsA[0] !== rowsB[0] ||\n rowsA[1] !== rowsB[1]\n ) {\n return false;\n }\n }\n return true;\n}\n\nexport function singleFocusedCell(\n sel: Region[],\n): FocusedCellCoordinates | null {\n /** Derive a single focused cell from a selected region, if possible */\n if (sel?.length !== 1) return null;\n return topLeftCell(sel, true);\n}\n\nfunction fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {\n const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;\n\n // Prepare regions by unnesting columns\n let regions = selection.map((region) => {\n const { cols, rows } = region;\n // Get the first column (maybe should be the last)\n const [col] = cols ?? [];\n return { cols: [col, col], rows };\n });\n\n // Fill values downwards\n if (!editable || fillValueBaseCell == null) return updatedData;\n const { col, row: baseVisibleRow } = fillValueBaseCell;\n // The base cell and target rows are visible positions; map to data rows.\n const baseRow = toDataRowIndex(state, baseVisibleRow);\n const key = columnSpec[col].key;\n const value = updatedData[baseRow]?.[key] ?? data[baseRow]?.[key];\n const spec = {};\n for (const region of regions) {\n const { rows } = region;\n for (const visibleRow of range(rows ?? [])) {\n const row = toDataRowIndex(state, visibleRow);\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: { [key]: value } };\n }\n }\n return update(updatedData, spec);\n}\n\n/** Number of rows currently visible (post-filter/sort), or the full data\n * length when no view transform is active. Uses the max of `data` and\n * `updatedData` lengths because `updatedData` is sparse — keying off it alone\n * would stop a whole-column edit at the last already-edited row. */\nfunction visibleRowCount<T>(state: DataSheetStore<T>): number {\n const { filteredRowIndices, updatedData, data } = state;\n return filteredRowIndices != null\n ? filteredRowIndices.length\n : Math.max(data.length, updatedData.length);\n}\n\n/** Map a visible (post-filter/sort) row position to its underlying data\n * index. Edit methods receive selection indices in visible space, so they\n * must translate before writing to `updatedData`/`data`. */\nfunction toDataRowIndex<T>(\n state: DataSheetStore<T>,\n visibleRow: number,\n): number {\n const { filteredRowIndices } = state;\n if (filteredRowIndices == null) return visibleRow;\n return filteredRowIndices[visibleRow] ?? visibleRow;\n}\n\n/** Whether two cell values are equivalent for edit-tracking. Empty string and\n * null/undefined are equivalent (so clearing an empty cell is a no-op), and\n * non-blank values are compared by string form so a text editor's `\"42\"`\n * matches a numeric base `42` (otherwise the cell reads as edited when its\n * value didn't actually change). */\nfunction valuesAreEquivalent(a: any, b: any): boolean {\n if (a === b) return true;\n const aBlank = a == null || a === \"\";\n const bBlank = b == null || b === \"\";\n if (aBlank || bBlank) return aBlank && bBlank;\n return String(a) === String(b);\n}\n\nfunction resetChangesForSelection<T>(\n state: DataSheetStore<T>,\n selection: Region[],\n): Partial<DataSheetStore<T>> {\n const emptySelection = {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n\n const { data } = state;\n const cardinality =\n getSelectionCardinality(selection ?? []) ?? RegionCardinality.FULL_TABLE;\n\n const rowStatus = [...state.rowStatus];\n const updatedData = [...state.updatedData];\n const addedRows = new Set<number>();\n\n // Global reset\n switch (cardinality) {\n case RegionCardinality.FULL_TABLE:\n for (let i = 0; i < rowStatus.length; i++) {\n if (rowStatus[i] === TableElementStatus.ADDED) {\n addedRows.add(i);\n }\n }\n\n return {\n updatedData: [],\n rowStatus: [],\n data: data.filter((_, i) => !addedRows.has(i)),\n ...emptySelection,\n };\n case RegionCardinality.FULL_COLUMNS:\n case RegionCardinality.CELLS:\n /** Columns or cells. Note, these only work the same because we don't\n * allow column deletion, only unsetting all values.\n */\n const columnKeys = getSelectedColumnKeys(selection, state.columnSpec);\n const spec: Spec<Record<string, any>[]> = {};\n const rowIndices =\n cardinality == RegionCardinality.FULL_COLUMNS\n ? Array.from({ length: updatedData.length }, (_, i) => i)\n : getSelectedRowIndices(selection);\n for (const row of rowIndices) {\n if (updatedData[row] == null) continue;\n spec[row] = { $unset: columnKeys };\n }\n // TODO: if we allow column addition/deletion, this will require more adjustment\n return {\n updatedData: update(updatedData, spec as any),\n ...emptySelection,\n };\n case RegionCardinality.FULL_ROWS:\n for (const row of getSelectedRowIndices(selection)) {\n updatedData[row] = undefined;\n if (state.rowStatus[row] === TableElementStatus.DELETED) {\n rowStatus[row] = undefined;\n } else if (state.rowStatus[row] === TableElementStatus.ADDED) {\n addedRows.add(row);\n }\n }\n\n const removeCandidateRows = (arr: any[]) => {\n return arr.filter((d, i) => !addedRows.has(i));\n };\n\n return {\n updatedData: removeCandidateRows(updatedData),\n data: removeCandidateRows(state.data),\n rowStatus: removeCandidateRows(rowStatus),\n ...emptySelection,\n };\n }\n}\n\nfunction insertItemAtIndex<T>(arr: T[], index: number, item: T) {\n if (arr.length < index) {\n const newArr = [...arr];\n newArr.length = index;\n newArr[index] = item;\n return newArr;\n }\n\n return [...arr.slice(0, index), item, ...arr.slice(index)];\n}\n"],"names":["DEFAULT_ROW_STATUS_STYLES","selection","topLeftCell","DS_ROW_ID","TableElementStatus","update","range","col","getSelectionCardinality","RegionCardinality","getSelectedColumnKeys","getSelectedRowIndices"],"mappings":";;;;;;;;AAuBA,IAAI,mBAAmB;AAEhB,SAAS,mBAAsB,KAAK,KAA4B;AACrE,SAAO;AAAA;AAAA,IAEL,MAAM,CAAA;AAAA,IACN,aAAa,CAAA;AAAA,IACb,WAAW,CAAA;AAAA,IACX,iBAAiBA,MAAAA;AAAAA,IACjB,YAAY,CAAA;AAAA,IACZ,iBAAiB;AAAA,IAC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AAS;AAAA,QACxC,GAAG;AAAA,MAAA;AAAA,EACL;AAEN;AAEA,SAAS,kBAAqB,KAAU,OAAe,MAAS;AAC9D,MAAI,IAAI,SAAS,OAAO;AACtB,UAAM,SAAS,CAAC,GAAG,GAAG;AACtB,WAAO,SAAS;AAChB,WAAO,KAAK,IAAI;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,GAAG,IAAI,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,IAAI,MAAM,KAAK,CAAC;AAC3D;;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_ROW_STATUS_STYLES, TableElementStatus, DS_ROW_ID } from "./types.js";
|
|
2
2
|
import { RegionCardinality } from "@blueprintjs/table";
|
|
3
|
-
import { range } from "./utils/index.js";
|
|
4
3
|
import update from "immutability-helper";
|
|
5
|
-
import { getSelectionCardinality, getSelectedRowIndices, getSelectedColumnKeys } from "
|
|
4
|
+
import { range, getSelectionCardinality, getSelectedRowIndices, getSelectedColumnKeys } from "../actions/selection.js";
|
|
6
5
|
let _addedRowCounter = 0;
|
|
7
6
|
function createZustandStore(set, get) {
|
|
8
7
|
return {
|
|
@@ -12,6 +11,7 @@ function createZustandStore(set, get) {
|
|
|
12
11
|
rowStatus: [],
|
|
13
12
|
rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,
|
|
14
13
|
columnSpec: [],
|
|
14
|
+
deferColumnSpec: false,
|
|
15
15
|
defaultColumnWidth: 150,
|
|
16
16
|
editable: false,
|
|
17
17
|
selection: [],
|
|
@@ -166,7 +166,7 @@ function createZustandStore(set, get) {
|
|
|
166
166
|
}
|
|
167
167
|
},
|
|
168
168
|
resetChanges(regions) {
|
|
169
|
-
set((state) => resetChangesForSelection(state, regions));
|
|
169
|
+
set((state) => resetChangesForSelection(state, regions ?? []));
|
|
170
170
|
get().onEdit?.({ type: "resetChanges" });
|
|
171
171
|
},
|
|
172
172
|
onColumnWidthChanged(columnIx, newWidth) {
|
|
@@ -230,7 +230,12 @@ function createZustandStore(set, get) {
|
|
|
230
230
|
const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
|
|
231
231
|
if (currentValue != null && currentValue !== "") {
|
|
232
232
|
vals[key] = "";
|
|
233
|
-
edits.push({
|
|
233
|
+
edits.push({
|
|
234
|
+
rowIndex: row,
|
|
235
|
+
column: key,
|
|
236
|
+
value: "",
|
|
237
|
+
row: data[row]
|
|
238
|
+
});
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
241
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
@@ -247,7 +252,11 @@ function createZustandStore(set, get) {
|
|
|
247
252
|
},
|
|
248
253
|
onSelection(selection) {
|
|
249
254
|
set((state) => {
|
|
250
|
-
|
|
255
|
+
const isSameAsPrevSelection = selectionEquals(
|
|
256
|
+
selection,
|
|
257
|
+
state.selection
|
|
258
|
+
);
|
|
259
|
+
if (isSameAsPrevSelection && singleFocusedCell(selection) == null) {
|
|
251
260
|
return {
|
|
252
261
|
selection: [],
|
|
253
262
|
focusedCell: null,
|
|
@@ -285,7 +294,12 @@ function createZustandStore(set, get) {
|
|
|
285
294
|
for (const col of colRange) {
|
|
286
295
|
const key = columnSpec[col].key;
|
|
287
296
|
vals[key] = value;
|
|
288
|
-
edits.push({
|
|
297
|
+
edits.push({
|
|
298
|
+
rowIndex: row,
|
|
299
|
+
column: key,
|
|
300
|
+
value,
|
|
301
|
+
row: state.data[row]
|
|
302
|
+
});
|
|
289
303
|
}
|
|
290
304
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
291
305
|
spec[row] = { [op]: vals };
|
|
@@ -433,7 +447,7 @@ function fillValues(state, selection) {
|
|
|
433
447
|
const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;
|
|
434
448
|
let regions = selection.map((region) => {
|
|
435
449
|
const { cols, rows } = region;
|
|
436
|
-
const [col2] = cols;
|
|
450
|
+
const [col2] = cols ?? [];
|
|
437
451
|
return { cols: [col2, col2], rows };
|
|
438
452
|
});
|
|
439
453
|
if (!editable || fillValueBaseCell == null) return updatedData;
|
|
@@ -444,7 +458,7 @@ function fillValues(state, selection) {
|
|
|
444
458
|
const spec = {};
|
|
445
459
|
for (const region of regions) {
|
|
446
460
|
const { rows } = region;
|
|
447
|
-
for (const visibleRow of range(rows)) {
|
|
461
|
+
for (const visibleRow of range(rows ?? [])) {
|
|
448
462
|
const row = toDataRowIndex(state, visibleRow);
|
|
449
463
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
450
464
|
spec[row] = { [op]: { [key]: value } };
|