@macrostrat/data-sheet 4.1.1 → 4.2.1
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 +46 -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/indicators/view-info.d.ts +11 -0
- package/dist/components/{view-info.js → indicators/view-info.js} +20 -16
- 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} +126 -188
- 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} +95 -157
- 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} +19 -30
- 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} +156 -327
- 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.d.ts +0 -5
- 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,161 @@
|
|
|
1
|
+
import { RegionCardinality } from "@blueprintjs/table";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
import { storeAtom } from "./core.ts";
|
|
4
|
+
|
|
5
|
+
export enum DataViewRendererType {
|
|
6
|
+
CARDS = "cards",
|
|
7
|
+
TABLE = "table",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface InteractionOptionsResolved {
|
|
11
|
+
enableEditing: boolean;
|
|
12
|
+
enableSelection: boolean;
|
|
13
|
+
// We have a potentially modal selection
|
|
14
|
+
enableModalSelection: boolean;
|
|
15
|
+
/** Options for data interaction (editing and selection) */
|
|
16
|
+
enableMultipleSelection: boolean;
|
|
17
|
+
// Enable drag-to-select (data table only)
|
|
18
|
+
enableDragValue: boolean;
|
|
19
|
+
selectionModes: RegionCardinality[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const defaultInteractionOptions: InteractionOptionsResolved = {
|
|
23
|
+
enableEditing: false,
|
|
24
|
+
enableSelection: false,
|
|
25
|
+
enableModalSelection: false,
|
|
26
|
+
enableMultipleSelection: false,
|
|
27
|
+
enableDragValue: false,
|
|
28
|
+
selectionModes: [],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Atom to store interaction options state */
|
|
32
|
+
export const interactionOptionsAtom = atom<InteractionOptionsResolved>(
|
|
33
|
+
defaultInteractionOptions,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export enum SelectionInteractionStyle {
|
|
37
|
+
ALWAYS = "always",
|
|
38
|
+
NEVER = "never",
|
|
39
|
+
MODAL = "modal",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface InteractionOptions {
|
|
43
|
+
/** Options for data interaction (editing and selection) */
|
|
44
|
+
/** @deprecated: Use enableEditing instead */
|
|
45
|
+
editable?: boolean;
|
|
46
|
+
enableEditing?: boolean;
|
|
47
|
+
enableSelection?: boolean | SelectionInteractionStyle;
|
|
48
|
+
enableMultipleSelection?: boolean;
|
|
49
|
+
// Enable drag-to-select (data table only)
|
|
50
|
+
enableDragValue?: boolean;
|
|
51
|
+
selectionModes?: RegionCardinality[];
|
|
52
|
+
interactionOptions?: InteractionOptionsResolved;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([
|
|
56
|
+
"editable",
|
|
57
|
+
"enableEditing",
|
|
58
|
+
"enableSelection",
|
|
59
|
+
"enableMultipleSelection",
|
|
60
|
+
"enableDragValue",
|
|
61
|
+
"selectionModes",
|
|
62
|
+
"interactionOptions",
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
/** Resolve the granular interaction options for a particular editing domain */
|
|
66
|
+
export function resolveInteractionOptions(
|
|
67
|
+
opts: InteractionOptions,
|
|
68
|
+
renderer: DataViewRendererType,
|
|
69
|
+
): InteractionOptionsResolved {
|
|
70
|
+
// If the user has provided interaction options, use them.
|
|
71
|
+
if (opts.interactionOptions) return opts.interactionOptions;
|
|
72
|
+
|
|
73
|
+
/** Resolve a unified set of interaction options for the table and cards */
|
|
74
|
+
let {
|
|
75
|
+
enableEditing,
|
|
76
|
+
selectionModes,
|
|
77
|
+
enableSelection: _enableSelection,
|
|
78
|
+
enableDragValue,
|
|
79
|
+
enableMultipleSelection,
|
|
80
|
+
} = opts;
|
|
81
|
+
|
|
82
|
+
if (renderer == DataViewRendererType.CARDS) {
|
|
83
|
+
_enableSelection ??= true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let enableSelection: boolean;
|
|
87
|
+
let enableModalSelection = false;
|
|
88
|
+
if (typeof _enableSelection === "string") {
|
|
89
|
+
switch (_enableSelection) {
|
|
90
|
+
case SelectionInteractionStyle.ALWAYS:
|
|
91
|
+
enableSelection = true;
|
|
92
|
+
break;
|
|
93
|
+
case SelectionInteractionStyle.NEVER:
|
|
94
|
+
enableSelection = false;
|
|
95
|
+
break;
|
|
96
|
+
case SelectionInteractionStyle.MODAL:
|
|
97
|
+
enableSelection = false;
|
|
98
|
+
enableModalSelection = true;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
enableSelection ??= _enableSelection ?? true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
enableEditing ??= opts.editable ?? enableSelection ?? true;
|
|
106
|
+
enableMultipleSelection ??= true;
|
|
107
|
+
if (renderer == DataViewRendererType.TABLE) {
|
|
108
|
+
if (selectionModes != null) {
|
|
109
|
+
enableSelection = new Set(selectionModes).size > 0;
|
|
110
|
+
}
|
|
111
|
+
enableSelection ??= true;
|
|
112
|
+
if (enableSelection) {
|
|
113
|
+
selectionModes ??= [
|
|
114
|
+
RegionCardinality.FULL_TABLE,
|
|
115
|
+
RegionCardinality.CELLS,
|
|
116
|
+
RegionCardinality.FULL_ROWS,
|
|
117
|
+
RegionCardinality.FULL_COLUMNS,
|
|
118
|
+
];
|
|
119
|
+
enableEditing ??= true;
|
|
120
|
+
enableDragValue ??= true;
|
|
121
|
+
} else {
|
|
122
|
+
selectionModes ??= [RegionCardinality.FULL_TABLE];
|
|
123
|
+
}
|
|
124
|
+
if (!selectionModes.includes(RegionCardinality.CELLS)) {
|
|
125
|
+
enableEditing = false;
|
|
126
|
+
}
|
|
127
|
+
enableDragValue ??= enableEditing;
|
|
128
|
+
} else if (renderer == DataViewRendererType.CARDS) {
|
|
129
|
+
if (enableSelection) {
|
|
130
|
+
// Only one selection mode possible
|
|
131
|
+
selectionModes = [
|
|
132
|
+
RegionCardinality.FULL_ROWS,
|
|
133
|
+
RegionCardinality.FULL_TABLE,
|
|
134
|
+
];
|
|
135
|
+
enableEditing ??= true;
|
|
136
|
+
} else {
|
|
137
|
+
selectionModes = [RegionCardinality.FULL_TABLE];
|
|
138
|
+
}
|
|
139
|
+
enableDragValue = false;
|
|
140
|
+
}
|
|
141
|
+
if (!enableEditing) {
|
|
142
|
+
enableDragValue = false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
enableEditing,
|
|
147
|
+
enableDragValue: enableDragValue ?? false,
|
|
148
|
+
enableMultipleSelection,
|
|
149
|
+
selectionModes: selectionModes as RegionCardinality[],
|
|
150
|
+
enableModalSelection,
|
|
151
|
+
enableSelection,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const enableDragValueAtom = atom((get) => {
|
|
156
|
+
return get(interactionOptionsAtom).enableDragValue;
|
|
157
|
+
});
|
|
158
|
+
export const dragValueHandlerAtom = atom((get) => {
|
|
159
|
+
if (!get(enableDragValueAtom)) return undefined;
|
|
160
|
+
return get(storeAtom)?.onDragValue;
|
|
161
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { atom } from "jotai";
|
|
2
|
+
import { interactionOptionsAtom } from "./interactions.ts";
|
|
3
|
+
import { storeAtom } from "./core.ts";
|
|
4
|
+
import type { Region } from "@blueprintjs/table";
|
|
5
|
+
|
|
6
|
+
// The anchor for shift-range selection: the last row clicked without shift.
|
|
7
|
+
// Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).
|
|
8
|
+
export const anchorRefAtom = atom<{ current: number | null }>({
|
|
9
|
+
current: null,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const selectionAtom = atom(
|
|
13
|
+
(get) => {
|
|
14
|
+
if (!get(interactionOptionsAtom).enableSelection) return [];
|
|
15
|
+
return get(storeAtom)?.selection ?? [];
|
|
16
|
+
},
|
|
17
|
+
(get, set, regions: Region[] = []) => {
|
|
18
|
+
/** Don't do anything if selection isn't enabled */
|
|
19
|
+
if (!get(interactionOptionsAtom).enableSelection) return;
|
|
20
|
+
/** Reset the selection anchor ref */
|
|
21
|
+
if (regions.length === 0) {
|
|
22
|
+
get(anchorRefAtom).current = null;
|
|
23
|
+
}
|
|
24
|
+
set(storeAtom, (s) => ({
|
|
25
|
+
...s,
|
|
26
|
+
selection: regions,
|
|
27
|
+
focusedCell: null,
|
|
28
|
+
topLeftCell: null,
|
|
29
|
+
}));
|
|
30
|
+
},
|
|
31
|
+
);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { ColumnSort, TableElementStatus } from "./types.ts";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
import { TableActionContext } from "../actions";
|
|
4
|
+
|
|
5
|
+
/** The active view state (a filter's id / column / config), passed to a
|
|
6
|
+
* `fetchChunk`. A server provider translates `columnKey` + `state` into a
|
|
7
|
+
* query; a local (in-memory) provider applies `predicate` directly. Both come
|
|
8
|
+
* from the same `TableFilter`, so one filter definition serves either target. */
|
|
9
|
+
export interface FetchDataFilter {
|
|
10
|
+
id: string;
|
|
11
|
+
columnKey?: string;
|
|
12
|
+
state: any;
|
|
13
|
+
/** Client-side row predicate (from the `TableFilter`). Server providers
|
|
14
|
+
* ignore it and translate `columnKey` + `state` instead. */
|
|
15
|
+
predicate?: (row: any, state: any) => boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Parameters passed to a `fetchChunk` implementation for one window. */
|
|
19
|
+
export interface FetchDataParams {
|
|
20
|
+
/** Row offset of the requested chunk (chunk-aligned). */
|
|
21
|
+
offset: number;
|
|
22
|
+
/** Maximum rows to return. */
|
|
23
|
+
limit: number;
|
|
24
|
+
/** Aborts when the request is superseded (view change / unmount). */
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
/** Active sorts, in priority order. */
|
|
27
|
+
sorts: ColumnSort[];
|
|
28
|
+
/** Active filters (id + column + config). */
|
|
29
|
+
filters: FetchDataFilter[];
|
|
30
|
+
/** In scroll mode, the already-loaded row immediately before this chunk
|
|
31
|
+
* (and its data-array index), or `null` at the start / in paged mode. Keyset
|
|
32
|
+
* sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a
|
|
33
|
+
* slow `OFFSET`; offset-based sources can ignore it. */
|
|
34
|
+
cursor?: { row: any; index: number } | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Result of a `fetchChunk` call. `totalCount` reports the source length when
|
|
38
|
+
* known (drives sparse-array pre-sizing and a proportional scrollbar); omit it
|
|
39
|
+
* for unknown-length sources (the array grows as chunks arrive). */
|
|
40
|
+
export interface FetchDataResult<T = any> {
|
|
41
|
+
rows: T[];
|
|
42
|
+
totalCount?: number | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type FetchData<T = any> = (
|
|
46
|
+
params: FetchDataParams,
|
|
47
|
+
) => Promise<FetchDataResult<T>>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A table's data source, addressed uniformly whether it's an in-memory array or
|
|
51
|
+
* a remote backend. `fetchChunk` returns a window with the active sorts/filters
|
|
52
|
+
* already applied (in memory by the local provider, in SQL by a server one);
|
|
53
|
+
* `identity` addresses a row for edits/mutations — stable across re-sorts,
|
|
54
|
+
* unlike an array index. The mutation ops are present only for editable /
|
|
55
|
+
* persisting sources. The in-memory case (`createLocalProvider`) is just the
|
|
56
|
+
* degenerate implementation, so local and server tables share one path.
|
|
57
|
+
*/
|
|
58
|
+
export interface TableDataProvider<T = any> {
|
|
59
|
+
fetchData(params: FetchDataParams): Promise<FetchDataResult<T>>;
|
|
60
|
+
identity(row: T): string | number;
|
|
61
|
+
saveRows?(rows: T[]): Promise<void>;
|
|
62
|
+
deleteRows?(ids: Array<string | number>): Promise<void>;
|
|
63
|
+
insertRow?(row: Partial<T>): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The degenerate provider: an in-memory array. `fetchChunk` applies the active
|
|
68
|
+
* filter predicates and sorts over the array and returns the requested slice
|
|
69
|
+
* plus the (fully-known) total — the same view engine used for client-side
|
|
70
|
+
* tables, expressed as a provider.
|
|
71
|
+
*/
|
|
72
|
+
export function createLocalProvider<T = any>(
|
|
73
|
+
data: T[],
|
|
74
|
+
options: { identity?: (row: T) => string | number } = {},
|
|
75
|
+
): TableDataProvider<T> {
|
|
76
|
+
const identity: any = options.identity ?? defaultLocalIdentity;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
identity,
|
|
80
|
+
async fetchData({ offset, limit, sorts, filters }) {
|
|
81
|
+
let rows = data;
|
|
82
|
+
if (filters != null && filters.length > 0) {
|
|
83
|
+
rows = rows.filter((row) =>
|
|
84
|
+
filters.every((f) =>
|
|
85
|
+
f.predicate != null ? f.predicate(row, f.state) : true,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (sorts != null && sorts.length > 0) {
|
|
90
|
+
rows = [...rows].sort(compareRowsBySorts(sorts));
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
rows: rows.slice(offset, offset + limit),
|
|
94
|
+
totalCount: rows.length,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Stable synthetic identity for in-memory rows lacking a natural `id`. Keyed by
|
|
101
|
+
// object reference (a local data array keeps the same row objects across
|
|
102
|
+
// re-sorts), so edits survive re-ordering even without an id field.
|
|
103
|
+
const _syntheticRowIds = new WeakMap<object, string>();
|
|
104
|
+
let _syntheticRowCounter = 0;
|
|
105
|
+
|
|
106
|
+
function defaultLocalIdentity(row: any): string | number | undefined {
|
|
107
|
+
if (row == null) return undefined;
|
|
108
|
+
if (row.id != null) return row.id;
|
|
109
|
+
if (typeof row !== "object") return row;
|
|
110
|
+
let id = _syntheticRowIds.get(row);
|
|
111
|
+
if (id == null) {
|
|
112
|
+
id = `__row_${_syntheticRowCounter++}`;
|
|
113
|
+
_syntheticRowIds.set(row, id);
|
|
114
|
+
}
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Multi-key row comparator (priority order; nulls first when ascending),
|
|
119
|
+
* shared by the local provider and any other in-memory sort. */
|
|
120
|
+
export function compareRowsBySorts(sorts: ColumnSort[]) {
|
|
121
|
+
return (a: any, b: any): number => {
|
|
122
|
+
for (const sort of sorts) {
|
|
123
|
+
const av = a?.[sort.key];
|
|
124
|
+
const bv = b?.[sort.key];
|
|
125
|
+
if (av == null && bv == null) continue;
|
|
126
|
+
if (av == null) return sort.ascending ? -1 : 1;
|
|
127
|
+
if (bv == null) return sort.ascending ? 1 : -1;
|
|
128
|
+
const cmp = av < bv ? -1 : av > bv ? 1 : 0;
|
|
129
|
+
if (cmp !== 0) return sort.ascending ? cmp : -cmp;
|
|
130
|
+
}
|
|
131
|
+
return 0;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Bump this to force the active chunk loader to reset and re-fetch from
|
|
136
|
+
* scratch — e.g. after a mutation (save/delete) that invalidates loaded rows. */
|
|
137
|
+
export const dataRefreshTokenAtom = atom(0);
|
|
138
|
+
|
|
139
|
+
/** Persist all pending changes through a data provider: added rows via
|
|
140
|
+
* `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`
|
|
141
|
+
* (addressed by `provider.identity`). Used by the built-in Save action when an
|
|
142
|
+
* explicit provider owns persistence. */
|
|
143
|
+
export async function persistViaProvider<T>(
|
|
144
|
+
provider: TableDataProvider<T>,
|
|
145
|
+
ctx: TableActionContext<T>,
|
|
146
|
+
): Promise<void> {
|
|
147
|
+
const base = (ctx.data ?? []) as any[];
|
|
148
|
+
const updates = (ctx.updatedData ?? []) as any[];
|
|
149
|
+
const status = (ctx.rowStatus ?? []) as any[];
|
|
150
|
+
const n = Math.max(base.length, updates.length, status.length);
|
|
151
|
+
const toSave: T[] = [];
|
|
152
|
+
const toInsert: T[] = [];
|
|
153
|
+
const toDelete: Array<string | number> = [];
|
|
154
|
+
for (let i = 0; i < n; i++) {
|
|
155
|
+
if (status[i] === TableElementStatus.DELETED) {
|
|
156
|
+
const id = provider.identity(base[i]);
|
|
157
|
+
if (id != null) toDelete.push(id);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const upd = updates[i];
|
|
161
|
+
const hasEdit =
|
|
162
|
+
upd != null && typeof upd === "object" && Object.keys(upd).length > 0;
|
|
163
|
+
if (status[i] === TableElementStatus.ADDED) {
|
|
164
|
+
toInsert.push({ ...base[i], ...upd } as T);
|
|
165
|
+
} else if (hasEdit) {
|
|
166
|
+
toSave.push({ ...base[i], ...upd } as T);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (toDelete.length > 0 && provider.deleteRows != null) {
|
|
170
|
+
await provider.deleteRows(toDelete);
|
|
171
|
+
}
|
|
172
|
+
for (const row of toInsert) {
|
|
173
|
+
if (provider.insertRow != null) await provider.insertRow(row);
|
|
174
|
+
}
|
|
175
|
+
if (toSave.length > 0 && provider.saveRows != null) {
|
|
176
|
+
await provider.saveRows(toSave);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FocusedCellCoordinates,
|
|
3
|
+
Region,
|
|
4
|
+
RegionCardinality,
|
|
5
|
+
Table2,
|
|
6
|
+
} from "@blueprintjs/table";
|
|
7
|
+
import type { ColumnSpec, ColumnSpecOptions } from "./column-spec";
|
|
8
|
+
import { OverlayToaster } from "@blueprintjs/core";
|
|
9
|
+
import { DataViewCoreProps } from "../types";
|
|
10
|
+
import { DataViewRendererType } from "./interactions.ts";
|
|
11
|
+
|
|
12
|
+
/** A single column sort entry for client-side sorting.
|
|
13
|
+
* Defined here (rather than in actions/types) to avoid circular imports. */
|
|
14
|
+
export interface ColumnSort {
|
|
15
|
+
key: string;
|
|
16
|
+
ascending: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Direction of keyboard navigation between cells. */
|
|
20
|
+
export type NavDirection = "up" | "down" | "left" | "right";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A structured, revertible description of a user edit. Emitted via the
|
|
24
|
+
* `onEdit` hook so a consumer can capture edits as operations (and, with the
|
|
25
|
+
* controlled-overlay API, own the edited state) instead of diffing
|
|
26
|
+
* `updatedData`. This is the write half of the data-sheet's read/write
|
|
27
|
+
* contract — the mirror of how data flows in.
|
|
28
|
+
*/
|
|
29
|
+
export type EditEvent<T = any> =
|
|
30
|
+
| { type: "setCells"; cells: CellEdit[] }
|
|
31
|
+
| { type: "deleteRows"; rowIndices: number[] }
|
|
32
|
+
| { type: "restoreRows"; rowIndices: number[] }
|
|
33
|
+
| { type: "addRow"; rowIndex: number; value: Partial<T> }
|
|
34
|
+
| { type: "resetChanges" };
|
|
35
|
+
|
|
36
|
+
export enum TableElementStatus {
|
|
37
|
+
DELETED = "deleted",
|
|
38
|
+
ADDED = "added",
|
|
39
|
+
}
|
|
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
|
+
|
|
47
|
+
/** Presentation for a row status: applied to the row's cells and its header
|
|
48
|
+
* cell. Keyed by status value in `rowStatusStyles`. The library ships a
|
|
49
|
+
* default for `"deleted"` (dimmed + struck through, danger intent); consumers
|
|
50
|
+
* merge in styles for their own statuses (and may override the defaults). */
|
|
51
|
+
export interface RowStatusStyle {
|
|
52
|
+
/** Style merged onto each cell in a row with this status. */
|
|
53
|
+
cellStyle?: import("react").CSSProperties;
|
|
54
|
+
/** Style applied to the row's header cell. */
|
|
55
|
+
headerStyle?: import("react").CSSProperties;
|
|
56
|
+
/** Blueprint intent applied to the row's cells (precedence: validation >
|
|
57
|
+
* this > edited-green). */
|
|
58
|
+
intent?: import("@blueprintjs/core").Intent;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type RowStatusStyles = Record<string, RowStatusStyle>;
|
|
62
|
+
|
|
63
|
+
/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged
|
|
64
|
+
* over this, so `"deleted"` keeps its look unless explicitly overridden. */
|
|
65
|
+
export const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {
|
|
66
|
+
[TableElementStatus.DELETED]: {
|
|
67
|
+
cellStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
68
|
+
headerStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
69
|
+
intent: "danger",
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Context passed to a custom `rowHeaderRenderer`, so it can label and style
|
|
74
|
+
* the row header from the row's data and status (group-key labels, an
|
|
75
|
+
* omit indicator, etc.). Return a node to use as the header's name, or a
|
|
76
|
+
* nullish value to fall back to the default (1-based row number). */
|
|
77
|
+
export interface RowHeaderRenderContext<T = any> {
|
|
78
|
+
/** Data-row index (stable under sort/filter). */
|
|
79
|
+
rowIndex: number;
|
|
80
|
+
/** Visible (display) row index. */
|
|
81
|
+
visibleIndex: number;
|
|
82
|
+
/** The row's data (base, overlaid with edits if present). */
|
|
83
|
+
row: T | undefined;
|
|
84
|
+
/** The row's status, if any. */
|
|
85
|
+
status: RowStatusValue | undefined;
|
|
86
|
+
/** Convenience: `status === TableElementStatus.DELETED`. */
|
|
87
|
+
isDeleted: boolean;
|
|
88
|
+
/** The default label (`"${rowIndex + 1}"`). */
|
|
89
|
+
defaultLabel: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Property key holding a stable synthetic id on rows added in-table. Added
|
|
93
|
+
* rows aren't in the data provider, so they need their own identity to survive
|
|
94
|
+
* a provider re-fetch; it's carried on the row and preserved through edits. */
|
|
95
|
+
export const DS_ROW_ID = "__dsRowId";
|
|
96
|
+
|
|
97
|
+
/** Proxy stored during a copy operation, enabling backend-mediated paste
|
|
98
|
+
* for lazy-loaded tables where not all data is available locally. */
|
|
99
|
+
export interface ClipboardProxy {
|
|
100
|
+
cardinality: RegionCardinality;
|
|
101
|
+
/** Source row indices (for row/cell copies) */
|
|
102
|
+
rowIndices?: number[];
|
|
103
|
+
/** Source column keys (for column/cell copies) */
|
|
104
|
+
columnKeys?: string[];
|
|
105
|
+
/** The plain text written to the clipboard, used to verify the proxy
|
|
106
|
+
* is still valid on paste (i.e., clipboard hasn't been overwritten). */
|
|
107
|
+
text: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface DataSheetState<T> {
|
|
111
|
+
selection: Region[];
|
|
112
|
+
columnSpec: ColumnSpec[];
|
|
113
|
+
columnSpecOptions?: ColumnSpecOptions<T>;
|
|
114
|
+
/** When `true`, the loader's first-chunk auto-generation of `columnSpec` is
|
|
115
|
+
* suppressed — a function `columnSpec` derives it from the loaded rows
|
|
116
|
+
* instead (in `_DataSheet`). Set at init from the prop's shape. */
|
|
117
|
+
deferColumnSpec: boolean;
|
|
118
|
+
fillValueBaseCell: FocusedCellCoordinates | null;
|
|
119
|
+
focusedCell: FocusedCellCoordinates | null;
|
|
120
|
+
topLeftCell: FocusedCellCoordinates | null;
|
|
121
|
+
/**
|
|
122
|
+
* Set of row indices that have been added to the table,
|
|
123
|
+
* but not yet committed to the underlying data array.
|
|
124
|
+
*
|
|
125
|
+
* This is used to track which rows should be reverted when
|
|
126
|
+
* a "reset" action is performed.
|
|
127
|
+
*/
|
|
128
|
+
rowStatus: (RowStatusValue | undefined)[];
|
|
129
|
+
/** Presentation per row-status value (merged: defaults + the
|
|
130
|
+
* `rowStatusStyles` prop). Read by the cell renderer and row-header renderer
|
|
131
|
+
* to style rows by status. */
|
|
132
|
+
rowStatusStyles: RowStatusStyles;
|
|
133
|
+
// Sparse data structure for updated data
|
|
134
|
+
updatedData: (T | null | undefined)[];
|
|
135
|
+
data: T[];
|
|
136
|
+
initialized: boolean;
|
|
137
|
+
columnWidthsIndex: Map<string, number>;
|
|
138
|
+
/** Active column/table filters. Keys are filter IDs, values carry the
|
|
139
|
+
* filter definition and its current configuration state. */
|
|
140
|
+
activeFilters: Map<string, { filter: any; state: any }>;
|
|
141
|
+
/** Clipboard proxy from the last copy operation */
|
|
142
|
+
clipboardProxy: ClipboardProxy | null;
|
|
143
|
+
/** Visible row indices when filters are active. `null` means show all rows. */
|
|
144
|
+
filteredRowIndices: number[] | null;
|
|
145
|
+
/** Active column sort entries for client-side sorting. */
|
|
146
|
+
columnSorts: ColumnSort[];
|
|
147
|
+
/** Whether selecting a cell automatically activates its surface (opens an
|
|
148
|
+
* editor/detail panel and, for editors, focuses it). `"manual"` opens only
|
|
149
|
+
* on click. */
|
|
150
|
+
cellInteraction: "auto" | "manual";
|
|
151
|
+
/** Runtime override of `cellInteraction`: while `false`, auto-activation is
|
|
152
|
+
* suppressed (set by pressing Escape, re-armed by clicking a cell) so the
|
|
153
|
+
* keyboard prioritizes navigation. */
|
|
154
|
+
autoActivateArmed: boolean;
|
|
155
|
+
/** Direction of the last keyboard navigation, used to place an editor's
|
|
156
|
+
* cursor on the side the user is travelling toward. `null` after a click. */
|
|
157
|
+
lastNavDirection: NavDirection | null;
|
|
158
|
+
/** The table's focusable holder element; editors return focus here when the
|
|
159
|
+
* cursor leaves them so arrow-key navigation resumes. */
|
|
160
|
+
tableElement: HTMLElement | null;
|
|
161
|
+
/** Whether the focused cell's surface (editor or detail panel) is open.
|
|
162
|
+
* Owned by the store — not per-popover — so navigation, clicks, and the
|
|
163
|
+
* Escape handler all agree on it. */
|
|
164
|
+
cellSurfaceOpen: boolean;
|
|
165
|
+
/** Optional observer called for every user edit as a structured
|
|
166
|
+
* `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a
|
|
167
|
+
* consumer capture edits as revertible operations. */
|
|
168
|
+
onEdit?: (event: EditEvent<T>) => void;
|
|
169
|
+
/** Row identity for the edit overlay — stable across a provider re-sort,
|
|
170
|
+
* unlike an array index. Defaults to `(row) => row?.id`; a data provider
|
|
171
|
+
* supplies its own (e.g. a PostgREST identity key). Used to re-attach edits
|
|
172
|
+
* when the loader replaces `data` with a re-ordered window. */
|
|
173
|
+
identity: (row: any) => string | number | null | undefined;
|
|
174
|
+
/** Edits/statuses held by identity for rows not currently loaded (server
|
|
175
|
+
* sources), re-attached when their row next arrives. */
|
|
176
|
+
pendingOverlayById: Map<
|
|
177
|
+
string | number,
|
|
178
|
+
{ edit?: any; status?: TableElementStatus }
|
|
179
|
+
>;
|
|
180
|
+
/** True when the consumer controls the `updatedData`/`rowStatus` overlay; the
|
|
181
|
+
* loader-boundary identity remap is skipped (the consumer owns it). */
|
|
182
|
+
controlledOverlay: boolean;
|
|
183
|
+
/** Whether row deletion is available. Set from the data provider: an explicit
|
|
184
|
+
* `provider` without `deleteRows` disables deletion entirely (the delete
|
|
185
|
+
* affordance greys out and the delete key is a no-op). Defaults to `true`. */
|
|
186
|
+
canDeleteRows: boolean;
|
|
187
|
+
/** Provider-backed, auto-refreshing row mutations for immediate-edit consumers
|
|
188
|
+
* (chiefly `DataPanel`). Each persists through the data provider and then
|
|
189
|
+
* re-fetches. Wired by the consumer that owns the provider + loader; exposed
|
|
190
|
+
* on the action context as `saveRows` / `deleteRows` / `insertRow` /
|
|
191
|
+
* `refresh`, so a selection action can edit without hand-wiring persistence.
|
|
192
|
+
* Absent when no persisting provider. */
|
|
193
|
+
rowEditing?: {
|
|
194
|
+
saveRows?: (rows: any[]) => Promise<void>;
|
|
195
|
+
deleteRows?: (ids: Array<string | number>) => Promise<void>;
|
|
196
|
+
insertRow?: (row: any) => Promise<void>;
|
|
197
|
+
refresh?: () => void;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;
|
|
202
|
+
export type StateUpdater<T> = T[] | ((state: T[]) => T[]);
|
|
203
|
+
|
|
204
|
+
export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
|
|
205
|
+
setSelection(selection: Region[]): void;
|
|
206
|
+
onDragValue(event: MouseEvent): void;
|
|
207
|
+
setUpdatedData(data: StateUpdater<T>): void;
|
|
208
|
+
onCellEdited(rowIndex: number, columnName: string, value: any): void;
|
|
209
|
+
onSelectionEdited(value: any): void;
|
|
210
|
+
onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
|
|
211
|
+
onColumnWidthChanged(columnIndex: number, newWidth: number): void;
|
|
212
|
+
moveFocusedCell(direction: NavDirection): void;
|
|
213
|
+
/** Suppress auto-activation until the next click (Escape enters nav mode). */
|
|
214
|
+
suppressAutoActivate(): void;
|
|
215
|
+
/** Re-arm auto-activation (a click re-enables auto-focus). */
|
|
216
|
+
armAutoActivate(): void;
|
|
217
|
+
/** Open the focused cell's surface (editor or detail panel). */
|
|
218
|
+
openCellSurface(): void;
|
|
219
|
+
/** Close the focused cell's surface. When `suppress` is true (the default,
|
|
220
|
+
* as for Escape), auto mode also enters navigation mode (auto-activation is
|
|
221
|
+
* suppressed until the next click). A click-dismiss passes `suppress: false`
|
|
222
|
+
* so it just closes without changing the global mode. */
|
|
223
|
+
closeCellSurface(opts?: { suppress?: boolean }): void;
|
|
224
|
+
deleteSelectedRows(): void;
|
|
225
|
+
clearSelection(): void;
|
|
226
|
+
resetChanges(): void;
|
|
227
|
+
addRow(): void;
|
|
228
|
+
/** Activate or update a column/table filter.
|
|
229
|
+
* Filter is any object satisfying `TableFilter` from the actions module. */
|
|
230
|
+
setFilter(filterId: string, filter: any, filterState: any): void;
|
|
231
|
+
/** Remove a filter by ID */
|
|
232
|
+
removeFilter(filterId: string): void;
|
|
233
|
+
/** Remove all active filters */
|
|
234
|
+
clearFilters(): void;
|
|
235
|
+
/** Set or clear a column sort. Pass `null` for ascending to clear. */
|
|
236
|
+
setColumnSort(key: string, ascending: boolean | null): void;
|
|
237
|
+
/** Remove all active column sorts */
|
|
238
|
+
clearColumnSorts(): void;
|
|
239
|
+
/** Store a clipboard proxy for potential backend-mediated paste */
|
|
240
|
+
setClipboardProxy(proxy: ClipboardProxy | null): void;
|
|
241
|
+
//initialize(props: Partial<DataSheetStoreMain<T>>): void;
|
|
242
|
+
onSelection(selection: Region[]): void;
|
|
243
|
+
// Internal method used for infinite scrolling
|
|
244
|
+
scrollToRow(rowIndex: number): void;
|
|
245
|
+
tableRef: React.MutableRefObject<Table2> | null;
|
|
246
|
+
columnWidthsIndex: Map<string, number>;
|
|
247
|
+
defaultColumnWidth: number;
|
|
248
|
+
// Editable is not optional on store
|
|
249
|
+
editable: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type DataSheetProviderProps<T> = DataViewCoreProps<T> & {
|
|
253
|
+
toaster?: OverlayToaster;
|
|
254
|
+
viewType?: DataViewRendererType;
|
|
255
|
+
children?: React.ReactNode;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export interface VisibleCells {
|
|
259
|
+
rowIndexStart: number;
|
|
260
|
+
rowIndexEnd: number;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export type DataSheetStore<T> = DataSheetStoreMain<T>;
|
|
264
|
+
|
|
265
|
+
/** A single cell edit, used with `editCells` for batch updates. */
|
|
266
|
+
export interface CellEdit {
|
|
267
|
+
rowIndex: number;
|
|
268
|
+
column: string;
|
|
269
|
+
value: any;
|
|
270
|
+
/** The underlying row (base data). Populated on emitted `onEdit` events so a
|
|
271
|
+
* handler can address the row (identity) without reaching into the store. */
|
|
272
|
+
row?: any;
|
|
273
|
+
}
|