@macrostrat/data-sheet 4.3.0 → 4.4.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 +51 -0
- package/dist/components/indicators/filter-and-sort.cjs +14 -3
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
- package/dist/components/indicators/filter-and-sort.d.ts +21 -1
- package/dist/components/indicators/filter-and-sort.js +14 -3
- package/dist/components/indicators/filter-and-sort.js.map +1 -1
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +7 -5
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -1
- package/dist/components/indicators/filter-and-sort.module.sass.js +7 -5
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -1
- package/dist/components/indicators/selection.cjs +7 -12
- package/dist/components/indicators/selection.cjs.map +1 -1
- package/dist/components/indicators/selection.d.ts +5 -0
- package/dist/components/indicators/selection.js +9 -14
- package/dist/components/indicators/selection.js.map +1 -1
- package/dist/components/indicators/unified-filters.cjs +100 -1
- package/dist/components/indicators/unified-filters.cjs.map +1 -1
- package/dist/components/indicators/unified-filters.d.ts +8 -1
- package/dist/components/indicators/unified-filters.js +102 -3
- package/dist/components/indicators/unified-filters.js.map +1 -1
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs +12 -12
- package/dist/components/toolbars/actions-toolbar.module.sass.js +12 -12
- package/dist/data-panel.cjs +12 -4
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.d.ts +14 -2
- package/dist/data-panel.js +13 -5
- package/dist/data-panel.js.map +1 -1
- package/dist/data-panel.module.sass.cjs +25 -24
- package/dist/data-panel.module.sass.cjs.map +1 -1
- package/dist/data-panel.module.sass.js +25 -24
- package/dist/data-panel.module.sass.js.map +1 -1
- package/dist/data-sheet.css +58 -54
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -3
- package/dist/provider/interactions.cjs +14 -0
- package/dist/provider/interactions.cjs.map +1 -1
- package/dist/provider/interactions.d.ts +19 -0
- package/dist/provider/interactions.js +15 -1
- package/dist/provider/interactions.js.map +1 -1
- package/dist/provider/selection.cjs +2 -2
- package/dist/provider/selection.cjs.map +1 -1
- package/dist/provider/selection.js +3 -3
- package/dist/provider/selection.js.map +1 -1
- package/dist/provider/zustand-store.cjs +13 -6
- package/dist/provider/zustand-store.cjs.map +1 -1
- package/dist/provider/zustand-store.js +13 -6
- package/dist/provider/zustand-store.js.map +1 -1
- package/package.json +4 -4
- package/src/components/indicators/filter-and-sort.module.sass +2 -2
- package/src/components/indicators/filter-and-sort.ts +31 -2
- package/src/components/indicators/selection.ts +10 -15
- package/src/components/indicators/unified-filters.ts +149 -3
- package/src/components/toolbars/actions-toolbar.module.sass +1 -1
- package/src/data-panel.module.sass +8 -3
- package/src/data-panel.ts +28 -4
- package/src/provider/interactions.ts +31 -0
- package/src/provider/selection.ts +3 -3
- package/src/provider/zustand-store.ts +23 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
columnSpecAtom,
|
|
3
3
|
ctx,
|
|
4
|
+
enableSelectionAtom,
|
|
4
5
|
interactionOptionsAtom,
|
|
5
6
|
itemLabelAtom,
|
|
6
7
|
pluralize,
|
|
@@ -51,20 +52,13 @@ function itemCount(n: number, itemType: string) {
|
|
|
51
52
|
return `${n} ` + pluralize(itemType, n);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
set(interactionOptionsAtom, {
|
|
64
|
-
...interactionState,
|
|
65
|
-
enableSelection,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
55
|
+
/** Enter/leave select mode. Leaving clears the selection — it has to happen
|
|
56
|
+
* *before* selection is switched off, since the selection write is gated on it. */
|
|
57
|
+
export const toggleModalSelectionAtom = atom(null, (get, set) => {
|
|
58
|
+
if (!get(interactionOptionsAtom).enableModalSelection) return;
|
|
59
|
+
const next = !get(enableSelectionAtom);
|
|
60
|
+
if (!next) set(clearableSelectionAtom);
|
|
61
|
+
set(enableSelectionAtom, next);
|
|
68
62
|
});
|
|
69
63
|
const clearableSelectionAtom = atom(
|
|
70
64
|
(get) => get(selectionAtom),
|
|
@@ -89,7 +83,8 @@ export function SelectionIndicator({ minimal = true }: { minimal?: boolean }) {
|
|
|
89
83
|
const tableName = ctx.useValue(tableNameAtom);
|
|
90
84
|
|
|
91
85
|
const toggleModalSelection = ctx.useSet(toggleModalSelectionAtom);
|
|
92
|
-
const { enableModalSelection
|
|
86
|
+
const { enableModalSelection } = interactionState;
|
|
87
|
+
const enableSelection = ctx.useValue(enableSelectionAtom);
|
|
93
88
|
|
|
94
89
|
const hasSelection = selection != null && selection.length > 0;
|
|
95
90
|
|
|
@@ -4,20 +4,36 @@ import {
|
|
|
4
4
|
TableAction,
|
|
5
5
|
TableFilter,
|
|
6
6
|
} from "../../actions";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
ctx,
|
|
9
|
+
enableSelectionAtom,
|
|
10
|
+
interactionOptionsAtom,
|
|
11
|
+
storeAtom,
|
|
12
|
+
useSelector,
|
|
13
|
+
} from "../../provider";
|
|
14
|
+
import { type ReactNode, useMemo } from "react";
|
|
9
15
|
import h from "../../data-panel.module.sass";
|
|
10
|
-
import { Menu, Tag } from "@blueprintjs/core";
|
|
16
|
+
import { Button, Menu, MenuDivider, Tag } from "@blueprintjs/core";
|
|
11
17
|
import {
|
|
12
18
|
ColumnFilterMenuItem,
|
|
13
19
|
ColumnSortMenu,
|
|
14
20
|
InlineFilterControl,
|
|
15
21
|
MenuDropdown,
|
|
22
|
+
MenuFormItem,
|
|
16
23
|
MenuInlineFilterItem,
|
|
17
24
|
resolveColumnFilter,
|
|
18
25
|
} from "./filter-and-sort.ts";
|
|
26
|
+
import { toggleModalSelectionAtom } from "./selection.ts";
|
|
19
27
|
import { atom } from "jotai";
|
|
20
28
|
|
|
29
|
+
/** How the built-in view controls (inline filters, Filter menu, Sort menu) are
|
|
30
|
+
* placed in the toolbar:
|
|
31
|
+
* - `"inline"` (default): each control sits in the toolbar.
|
|
32
|
+
* - `"popover"`: all of them collapse behind a single button — for a narrow or
|
|
33
|
+
* deliberately chrome-light toolbar.
|
|
34
|
+
* In both cases the controls, state, and provider seam are identical. */
|
|
35
|
+
export type ViewControlsPresentation = "inline" | "popover";
|
|
36
|
+
|
|
21
37
|
/** A filter to surface, plus the label to show for it. */
|
|
22
38
|
interface FilterEntry {
|
|
23
39
|
filter: TableFilter;
|
|
@@ -36,6 +52,7 @@ interface FilterEntry {
|
|
|
36
52
|
*/
|
|
37
53
|
export function useDataPanelControls(
|
|
38
54
|
tableFilters: TableFilter[] = [],
|
|
55
|
+
presentation: ViewControlsPresentation = "inline",
|
|
39
56
|
): TableAction[] {
|
|
40
57
|
const columnSpec = useSelector((s) => s.columnSpec);
|
|
41
58
|
|
|
@@ -58,6 +75,21 @@ export function useDataPanelControls(
|
|
|
58
75
|
// Hooks first (stable order), then assemble.
|
|
59
76
|
const filterMenuAction = useFilterMenuAction(menuEntries);
|
|
60
77
|
const sortAction = useSortAction();
|
|
78
|
+
const collapsedAction = useCollapsedControlsAction(entries);
|
|
79
|
+
const exitSelectionAction = useExitSelectionAction();
|
|
80
|
+
|
|
81
|
+
// While a modal view is *selecting*, the toolbar belongs to the selection and
|
|
82
|
+
// its set-actions. Changing the view would also invalidate the selection
|
|
83
|
+
// (rows are addressed by index — see `dropRowSelection`), so rather than
|
|
84
|
+
// competing for space, the view controls collapse to a single affordance that
|
|
85
|
+
// **leaves select mode** and hands the toolbar back.
|
|
86
|
+
if (exitSelectionAction != null) return [exitSelectionAction];
|
|
87
|
+
|
|
88
|
+
// One button holding every control, for a toolbar with no room for them (or a
|
|
89
|
+
// deliberately chrome-light layout).
|
|
90
|
+
if (presentation === "popover" && collapsedAction != null) {
|
|
91
|
+
return [collapsedAction];
|
|
92
|
+
}
|
|
61
93
|
|
|
62
94
|
const actions: TableAction[] = [];
|
|
63
95
|
// Inline filters: one always-visible toolbar control each.
|
|
@@ -75,6 +107,120 @@ export function useDataPanelControls(
|
|
|
75
107
|
return actions;
|
|
76
108
|
}
|
|
77
109
|
|
|
110
|
+
/**
|
|
111
|
+
* The whole view-control set behind one button: inline filters as titled
|
|
112
|
+
* sections, then the filters, then the sorts. Same controls, same store seam —
|
|
113
|
+
* only placement changes (the `presentation` idea from `TableFilter`, applied to
|
|
114
|
+
* the toolbar as a whole).
|
|
115
|
+
*/
|
|
116
|
+
function useCollapsedControlsAction(
|
|
117
|
+
entries: FilterEntry[],
|
|
118
|
+
): TableAction | null {
|
|
119
|
+
const columnSpec = useSelector((s) => s.columnSpec);
|
|
120
|
+
const hasActiveFilters = ctx.useValue(hasActiveFiltersAtom);
|
|
121
|
+
const hasActiveSorts = ctx.useValue(hasActiveSortsAtom);
|
|
122
|
+
|
|
123
|
+
const sortableCols = useMemo(
|
|
124
|
+
() => columnSpec.filter((c) => c.sortable),
|
|
125
|
+
[columnSpec],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (entries.length === 0 && sortableCols.length === 0) return null;
|
|
129
|
+
|
|
130
|
+
const inlineEntries = entries.filter(
|
|
131
|
+
(e) => presentationOf(e.filter) === "inline",
|
|
132
|
+
);
|
|
133
|
+
const menuEntries = entries.filter(
|
|
134
|
+
(e) => presentationOf(e.filter) !== "inline",
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const items: ReactNode[] = [];
|
|
138
|
+
for (const { filter, label } of inlineEntries) {
|
|
139
|
+
items.push(
|
|
140
|
+
h(MenuFormItem, { key: filter.id, title: label }, [
|
|
141
|
+
h(InlineFilterControl, { filter }),
|
|
142
|
+
]),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (menuEntries.length > 0) {
|
|
146
|
+
items.push(h(MenuDivider, { key: "filter-divider", title: "Filter" }));
|
|
147
|
+
for (const { filter, label } of menuEntries) {
|
|
148
|
+
if (presentationOf(filter) === "menu-inline") {
|
|
149
|
+
items.push(h(MenuInlineFilterItem, { key: filter.id, filter, label }));
|
|
150
|
+
} else {
|
|
151
|
+
items.push(h(ColumnFilterMenuItem, { key: filter.id, filter, label }));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (sortableCols.length > 0) {
|
|
156
|
+
items.push(h(MenuDivider, { key: "sort-divider", title: "Sort" }));
|
|
157
|
+
for (const col of sortableCols) {
|
|
158
|
+
items.push(
|
|
159
|
+
h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let intent: "primary" | "none" = "none";
|
|
165
|
+
if (hasActiveFilters || hasActiveSorts) intent = "primary";
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
id: "view-controls",
|
|
169
|
+
name: "View",
|
|
170
|
+
icon: "filter-list",
|
|
171
|
+
description: "Search, filter and sort.",
|
|
172
|
+
targets: ALL_CARDINALITIES,
|
|
173
|
+
requiresEditable: false,
|
|
174
|
+
render: () =>
|
|
175
|
+
h(
|
|
176
|
+
MenuDropdown,
|
|
177
|
+
{ content: h(Menu, { className: "collapsed-controls" }, items) },
|
|
178
|
+
[
|
|
179
|
+
h(Button, {
|
|
180
|
+
minimal: true,
|
|
181
|
+
small: true,
|
|
182
|
+
icon: "filter-list",
|
|
183
|
+
intent,
|
|
184
|
+
title: "Search, filter and sort",
|
|
185
|
+
}),
|
|
186
|
+
],
|
|
187
|
+
),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** While selecting on a modal view: one control that leaves select mode (and so
|
|
192
|
+
* restores the view controls). Labelled for where it takes you, not what it
|
|
193
|
+
* does to the selection. */
|
|
194
|
+
function useExitSelectionAction(): TableAction | null {
|
|
195
|
+
const { enableModalSelection } = ctx.useValue(interactionOptionsAtom);
|
|
196
|
+
const selecting = ctx.useValue(enableSelectionAtom);
|
|
197
|
+
const toggleSelectMode = ctx.useSet(toggleModalSelectionAtom);
|
|
198
|
+
|
|
199
|
+
if (!enableModalSelection || !selecting) return null;
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
id: "exit-selection",
|
|
203
|
+
name: "Filter",
|
|
204
|
+
icon: "filter",
|
|
205
|
+
description: "Leave select mode to filter and sort.",
|
|
206
|
+
targets: ALL_CARDINALITIES,
|
|
207
|
+
requiresEditable: false,
|
|
208
|
+
render: () =>
|
|
209
|
+
h(
|
|
210
|
+
Tag,
|
|
211
|
+
{
|
|
212
|
+
minimal: true,
|
|
213
|
+
large: true,
|
|
214
|
+
interactive: true,
|
|
215
|
+
icon: "filter",
|
|
216
|
+
title: "Filter and sort (leaves select mode)",
|
|
217
|
+
onClick: () => toggleSelectMode(),
|
|
218
|
+
},
|
|
219
|
+
"Filter",
|
|
220
|
+
),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
78
224
|
function presentationOf(filter: TableFilter): string {
|
|
79
225
|
return filter.presentation ?? "menu";
|
|
80
226
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
:root
|
|
5
5
|
--data-panel-content-padding: 0px
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
.data-panel
|
|
9
8
|
display: flex
|
|
10
9
|
flex: 1 1 auto
|
|
@@ -14,7 +13,9 @@
|
|
|
14
13
|
min-width: 0
|
|
15
14
|
--data-panel-content-padding: 12px
|
|
16
15
|
--data-panel-item-gap: 8px
|
|
17
|
-
|
|
16
|
+
// Fallback to percentage
|
|
17
|
+
--data-panel-content-width: 100cqw
|
|
18
|
+
|
|
18
19
|
--data-panel-selected-color: #2d72d2
|
|
19
20
|
--data-panel-selected-background: rgba(45, 114, 210, 0.1)
|
|
20
21
|
|
|
@@ -173,7 +174,7 @@
|
|
|
173
174
|
|
|
174
175
|
.data-panel-toolbar
|
|
175
176
|
left: 50%
|
|
176
|
-
transform: translateX(calc((var(--data-panel-content-width,
|
|
177
|
+
transform: translateX(calc((var(--data-panel-content-width, 100cqw) / -2) + var(--data-panel-content-padding) - 4px))
|
|
177
178
|
top: var(--data-panel-content-padding, 12px)
|
|
178
179
|
background-color: var(--panel-secondary-background-color)
|
|
179
180
|
box-shadow: 0 0 0 1px var(--panel-rule-color)
|
|
@@ -200,3 +201,7 @@
|
|
|
200
201
|
.data-panel-body.is-scrolled
|
|
201
202
|
mask-image: linear-gradient(to bottom, transparent 0, var(--background-color) 20px)
|
|
202
203
|
|
|
204
|
+
|
|
205
|
+
// Every view control behind one button (`viewControls: "popover"`).
|
|
206
|
+
.collapsed-controls
|
|
207
|
+
max-width: 360px
|
package/src/data-panel.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
DataSheetProvider,
|
|
44
44
|
DataViewRendererType,
|
|
45
45
|
FetchData,
|
|
46
|
+
enableSelectionAtom,
|
|
46
47
|
interactionOptionsAtom,
|
|
47
48
|
selectionAtom,
|
|
48
49
|
splitDataProviderProps,
|
|
@@ -64,6 +65,7 @@ import {
|
|
|
64
65
|
ActionsToolbar,
|
|
65
66
|
LoadProgressIndicator,
|
|
66
67
|
useDataPanelControls,
|
|
68
|
+
type ViewControlsPresentation,
|
|
67
69
|
} from "./components";
|
|
68
70
|
import { DataViewSharedProps, FetchDataOptions } from "./types";
|
|
69
71
|
import { atom } from "jotai";
|
|
@@ -73,6 +75,10 @@ export enum DataPanelToolbarStyle {
|
|
|
73
75
|
BORDERED = "bordered",
|
|
74
76
|
FADE = "fade",
|
|
75
77
|
MINIMAL = "minimal",
|
|
78
|
+
/** Toolbar (and footer) sized to their contents and lifted over the scroll
|
|
79
|
+
* body, rather than occupying a full-width band. Pairs with
|
|
80
|
+
* `viewControls: "popover"`, since inline controls cost real space here. */
|
|
81
|
+
FLOATING = "floating",
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
/** Props for a custom scroll-body layout component. It receives the
|
|
@@ -138,6 +144,13 @@ export interface DataPanelProps<T = any> extends DataViewSharedProps<T> {
|
|
|
138
144
|
scrollBody?: ComponentType<ScrollBodyProps>;
|
|
139
145
|
className?: string;
|
|
140
146
|
toolbarStyle?: DataPanelToolbarStyle | string;
|
|
147
|
+
/** Where the built-in view controls (inline filters, Filter menu, Sort menu)
|
|
148
|
+
* sit in the toolbar: `"inline"` (default) places each in the toolbar;
|
|
149
|
+
* `"popover"` collapses all of them behind a single button — for a narrow or
|
|
150
|
+
* deliberately chrome-light toolbar. Same controls and state either way.
|
|
151
|
+
* Ignored while a modal view is selecting: the toolbar then carries a single
|
|
152
|
+
* control that leaves select mode. */
|
|
153
|
+
viewControls?: ViewControlsPresentation;
|
|
141
154
|
/** Arbitrary children rendered inside the provider, after the panel. */
|
|
142
155
|
children?: ReactNode;
|
|
143
156
|
}
|
|
@@ -187,6 +200,7 @@ export function DataPanelRenderer<T>({
|
|
|
187
200
|
scrollBody,
|
|
188
201
|
className,
|
|
189
202
|
toolbarStyle = DataPanelToolbarStyle.BORDERED,
|
|
203
|
+
viewControls = "inline",
|
|
190
204
|
children,
|
|
191
205
|
}: Omit<DataPanelProps<T>, "provider" | "fetchData" | "data" | "identity">) {
|
|
192
206
|
const {
|
|
@@ -233,7 +247,7 @@ export function DataPanelRenderer<T>({
|
|
|
233
247
|
setScrolled(e.currentTarget.scrollTop > 4);
|
|
234
248
|
}, []);
|
|
235
249
|
|
|
236
|
-
const enableSelection = ctx.useValue(
|
|
250
|
+
const enableSelection = ctx.useValue(enableSelectionAtom);
|
|
237
251
|
const selectedIndices = ctx.useValue(selectedRowIndicesAtom);
|
|
238
252
|
const select = ctx.useSet(updateSelectionAtom);
|
|
239
253
|
|
|
@@ -341,7 +355,7 @@ export function DataPanelRenderer<T>({
|
|
|
341
355
|
});
|
|
342
356
|
}
|
|
343
357
|
|
|
344
|
-
const coreActions = useDataPanelControls(filters);
|
|
358
|
+
const coreActions = useDataPanelControls(filters, viewControls);
|
|
345
359
|
|
|
346
360
|
// Merge consumer actions with the synthesized Filter/Sort controls, deduped
|
|
347
361
|
// by id — consumer actions come first, so passing an action with id `filter`
|
|
@@ -545,10 +559,20 @@ const updateSelectionAtom = atom(
|
|
|
545
559
|
null,
|
|
546
560
|
(get, set, index: number, mods: SelectModifiers) => {
|
|
547
561
|
/** Update selection from a row index and modifiers. */
|
|
548
|
-
const { enableMultipleSelection,
|
|
562
|
+
const { enableMultipleSelection, enableModalSelection } = get(
|
|
549
563
|
interactionOptionsAtom,
|
|
550
564
|
);
|
|
551
|
-
|
|
565
|
+
let enableSelection = get(enableSelectionAtom);
|
|
566
|
+
if (!enableSelection) {
|
|
567
|
+
// Cmd/ctrl-click *enters* select mode on a modal view and selects the
|
|
568
|
+
// row, the familiar list idiom — so a bulk action doesn't require finding
|
|
569
|
+
// the Select control first. The flag is read back below rather than
|
|
570
|
+
// trusted from this scope: the write goes through the store synchronously.
|
|
571
|
+
if (!enableModalSelection || !mods.additive) return;
|
|
572
|
+
set(enableSelectionAtom, true);
|
|
573
|
+
enableSelection = get(enableSelectionAtom);
|
|
574
|
+
if (!enableSelection) return;
|
|
575
|
+
}
|
|
552
576
|
const selection = get(rowSelectionAtom);
|
|
553
577
|
const anchorRef = get(anchorRefAtom);
|
|
554
578
|
const res = buildDataViewSelection(
|
|
@@ -152,6 +152,37 @@ export function resolveInteractionOptions(
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Whether **modal** selection is currently switched on.
|
|
157
|
+
*
|
|
158
|
+
* This is *runtime view state*, not configuration, so it lives in its own atom
|
|
159
|
+
* rather than inside `interactionOptionsAtom`: the latter is re-synced from the
|
|
160
|
+
* view's props (`resolveInteractionOptions` builds a fresh object on every
|
|
161
|
+
* render of the provider), so a runtime override stored there is reset by any
|
|
162
|
+
* provider re-render that happens to fire. Keeping the flag separate makes
|
|
163
|
+
* select mode stable, and gives consumers a single, safe thing to read and set.
|
|
164
|
+
*/
|
|
165
|
+
export const selectionModeActiveAtom = atom(false);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The effective "is selection live right now" flag — the one every selection
|
|
169
|
+
* path should read. For a modal view it follows {@link selectionModeActiveAtom};
|
|
170
|
+
* otherwise it's the configured `enableSelection`.
|
|
171
|
+
*/
|
|
172
|
+
export const enableSelectionAtom = atom(
|
|
173
|
+
(get) => {
|
|
174
|
+
const options = get(interactionOptionsAtom);
|
|
175
|
+
if (options.enableModalSelection) return get(selectionModeActiveAtom);
|
|
176
|
+
return options.enableSelection;
|
|
177
|
+
},
|
|
178
|
+
(get, set, next: boolean) => {
|
|
179
|
+
/** Turn selection on/off. Only meaningful for a modal view; a view with a
|
|
180
|
+
* fixed selection style ignores it. */
|
|
181
|
+
if (!get(interactionOptionsAtom).enableModalSelection) return;
|
|
182
|
+
set(selectionModeActiveAtom, next);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
|
|
155
186
|
export const enableDragValueAtom = atom((get) => {
|
|
156
187
|
return get(interactionOptionsAtom).enableDragValue;
|
|
157
188
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { atom } from "jotai";
|
|
2
|
-
import {
|
|
2
|
+
import { enableSelectionAtom } from "./interactions.ts";
|
|
3
3
|
import { storeAtom } from "./core.ts";
|
|
4
4
|
import type { Region } from "@blueprintjs/table";
|
|
5
5
|
|
|
@@ -11,12 +11,12 @@ export const anchorRefAtom = atom<{ current: number | null }>({
|
|
|
11
11
|
|
|
12
12
|
export const selectionAtom = atom(
|
|
13
13
|
(get) => {
|
|
14
|
-
if (!get(
|
|
14
|
+
if (!get(enableSelectionAtom)) return [];
|
|
15
15
|
return get(storeAtom)?.selection ?? [];
|
|
16
16
|
},
|
|
17
17
|
(get, set, regions: Region[] = []) => {
|
|
18
18
|
/** Don't do anything if selection isn't enabled */
|
|
19
|
-
if (!get(
|
|
19
|
+
if (!get(enableSelectionAtom)) return;
|
|
20
20
|
/** Reset the selection anchor ref */
|
|
21
21
|
if (regions.length === 0) {
|
|
22
22
|
get(anchorRefAtom).current = null;
|
|
@@ -431,7 +431,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
431
431
|
state.activeFilters,
|
|
432
432
|
);
|
|
433
433
|
newFilters.set(filterId, { filter, state: filterState });
|
|
434
|
-
return { activeFilters: newFilters };
|
|
434
|
+
return { activeFilters: newFilters, ...dropRowSelection(state) };
|
|
435
435
|
});
|
|
436
436
|
},
|
|
437
437
|
removeFilter(filterId: string) {
|
|
@@ -440,12 +440,13 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
440
440
|
state.activeFilters,
|
|
441
441
|
);
|
|
442
442
|
newFilters.delete(filterId);
|
|
443
|
-
return { activeFilters: newFilters };
|
|
443
|
+
return { activeFilters: newFilters, ...dropRowSelection(state) };
|
|
444
444
|
});
|
|
445
445
|
},
|
|
446
446
|
clearFilters() {
|
|
447
|
-
set(() => ({
|
|
447
|
+
set((state) => ({
|
|
448
448
|
activeFilters: new Map<string, { filter: any; state: any }>(),
|
|
449
|
+
...dropRowSelection(state),
|
|
449
450
|
}));
|
|
450
451
|
},
|
|
451
452
|
setColumnSort(key: string, ascending: boolean | null) {
|
|
@@ -457,11 +458,11 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
457
458
|
const without = state.columnSorts.filter((s) => s.key !== key);
|
|
458
459
|
newSorts = [...without, { key, ascending }];
|
|
459
460
|
}
|
|
460
|
-
return { columnSorts: newSorts };
|
|
461
|
+
return { columnSorts: newSorts, ...dropRowSelection(state) };
|
|
461
462
|
});
|
|
462
463
|
},
|
|
463
464
|
clearColumnSorts() {
|
|
464
|
-
set(() => ({ columnSorts: [] }));
|
|
465
|
+
set((state) => ({ columnSorts: [], ...dropRowSelection(state) }));
|
|
465
466
|
},
|
|
466
467
|
setClipboardProxy(proxy) {
|
|
467
468
|
set({ clipboardProxy: proxy });
|
|
@@ -469,6 +470,23 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
469
470
|
};
|
|
470
471
|
}
|
|
471
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Drop the parts of a selection that are addressed by **row index**, because a
|
|
475
|
+
* filter or sort change re-orders and re-filters the rows underneath them —
|
|
476
|
+
* "rows 3–5" then means different records, and a set-action would silently act
|
|
477
|
+
* on the wrong ones. Column selections are index-stable under a view change, so
|
|
478
|
+
* they survive (and must: the sheet's sort/filter controls are themselves
|
|
479
|
+
* column-scoped, and are invoked *from* that selection).
|
|
480
|
+
*/
|
|
481
|
+
function dropRowSelection<T>(
|
|
482
|
+
state: DataSheetState<T>,
|
|
483
|
+
): Partial<DataSheetState<T>> {
|
|
484
|
+
const selection = state.selection ?? [];
|
|
485
|
+
const kept = selection.filter((region) => region.rows == null);
|
|
486
|
+
if (kept.length === selection.length) return {};
|
|
487
|
+
return { selection: kept, focusedCell: null, topLeftCell: null };
|
|
488
|
+
}
|
|
489
|
+
|
|
472
490
|
export function updateSelection<T>(selection: Region[]) {
|
|
473
491
|
const focusedCell = singleFocusedCell(selection);
|
|
474
492
|
let spec: Partial<DataSheetState<T>> = {
|