@macrostrat/data-sheet 4.3.0 → 4.4.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/components/indicators/filter-and-sort.cjs +14 -3
  3. package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
  4. package/dist/components/indicators/filter-and-sort.d.ts +21 -1
  5. package/dist/components/indicators/filter-and-sort.js +14 -3
  6. package/dist/components/indicators/filter-and-sort.js.map +1 -1
  7. package/dist/components/indicators/filter-and-sort.module.sass.cjs +7 -5
  8. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -1
  9. package/dist/components/indicators/filter-and-sort.module.sass.js +7 -5
  10. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -1
  11. package/dist/components/indicators/selection.cjs +7 -12
  12. package/dist/components/indicators/selection.cjs.map +1 -1
  13. package/dist/components/indicators/selection.d.ts +5 -0
  14. package/dist/components/indicators/selection.js +9 -14
  15. package/dist/components/indicators/selection.js.map +1 -1
  16. package/dist/components/indicators/unified-filters.cjs +130 -11
  17. package/dist/components/indicators/unified-filters.cjs.map +1 -1
  18. package/dist/components/indicators/unified-filters.d.ts +8 -1
  19. package/dist/components/indicators/unified-filters.js +132 -13
  20. package/dist/components/indicators/unified-filters.js.map +1 -1
  21. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +12 -12
  22. package/dist/components/toolbars/actions-toolbar.module.sass.js +12 -12
  23. package/dist/data-panel.cjs +12 -4
  24. package/dist/data-panel.cjs.map +1 -1
  25. package/dist/data-panel.d.ts +14 -2
  26. package/dist/data-panel.js +13 -5
  27. package/dist/data-panel.js.map +1 -1
  28. package/dist/data-panel.module.sass.cjs +25 -24
  29. package/dist/data-panel.module.sass.cjs.map +1 -1
  30. package/dist/data-panel.module.sass.js +25 -24
  31. package/dist/data-panel.module.sass.js.map +1 -1
  32. package/dist/data-sheet.css +57 -54
  33. package/dist/index.cjs +4 -0
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.js +7 -3
  36. package/dist/provider/interactions.cjs +14 -0
  37. package/dist/provider/interactions.cjs.map +1 -1
  38. package/dist/provider/interactions.d.ts +19 -0
  39. package/dist/provider/interactions.js +15 -1
  40. package/dist/provider/interactions.js.map +1 -1
  41. package/dist/provider/selection.cjs +2 -2
  42. package/dist/provider/selection.cjs.map +1 -1
  43. package/dist/provider/selection.js +3 -3
  44. package/dist/provider/selection.js.map +1 -1
  45. package/dist/provider/zustand-store.cjs +13 -6
  46. package/dist/provider/zustand-store.cjs.map +1 -1
  47. package/dist/provider/zustand-store.js +13 -6
  48. package/dist/provider/zustand-store.js.map +1 -1
  49. package/package.json +4 -4
  50. package/src/components/indicators/filter-and-sort.module.sass +2 -2
  51. package/src/components/indicators/filter-and-sort.ts +31 -2
  52. package/src/components/indicators/selection.ts +10 -15
  53. package/src/components/indicators/unified-filters.ts +189 -13
  54. package/src/components/toolbars/actions-toolbar.module.sass +1 -1
  55. package/src/data-panel.module.sass +7 -3
  56. package/src/data-panel.ts +28 -4
  57. package/src/provider/interactions.ts +31 -0
  58. package/src/provider/selection.ts +3 -3
  59. package/src/provider/zustand-store.ts +23 -5
@@ -109,20 +109,49 @@ export function FilterIndicator({
109
109
  );
110
110
  }
111
111
 
112
- export function MenuDropdown({ children, content, isOpen, ...props }: any) {
112
+ /**
113
+ * A dropdown for a panel of controls (not just menu items).
114
+ *
115
+ * Deliberately **not** focus-trapping. These panels hold real form controls,
116
+ * and a control whose own typeahead renders in a separate portal (a
117
+ * `MultiSelect`, a date picker) has focus yanked back out of it by an enclosing
118
+ * trap — which is what makes a nested filter submenu feel unstable. Caller
119
+ * props are passed through (`placement`, `isOpen`, …).
120
+ */
121
+ export function MenuDropdown({ children, content, ...props }: any) {
113
122
  return h(
114
123
  PopoverNext,
115
124
  {
116
125
  content,
117
126
  placement: "bottom-start",
118
- enforceFocus: true,
127
+ enforceFocus: false,
119
128
  autoFocus: false,
120
129
  arrow: false,
130
+ ...props,
121
131
  },
122
132
  children,
123
133
  );
124
134
  }
125
135
 
136
+ /**
137
+ * A titled block *inside* a menu holding an arbitrary form, rather than a menu
138
+ * item that opens a submenu — one click away instead of two, with no nested
139
+ * popover to lose focus to. The building block behind `MenuInlineFilterItem`,
140
+ * exported so a custom control panel can use the same idiom.
141
+ */
142
+ export function MenuFormItem({
143
+ title,
144
+ children,
145
+ }: {
146
+ title?: ReactNode;
147
+ children: ReactNode;
148
+ }) {
149
+ return h("li.menu-form-item", [
150
+ h.if(title != null)(MenuDivider, { title }),
151
+ h("div.menu-form-body", children),
152
+ ]);
153
+ }
154
+
126
155
  function buildFilterTagLabel(
127
156
  filter: TableFilter,
128
157
  valueText: ReactNode | null,
@@ -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
- const toggleModalSelectionAtom = atom(null, (get, set) => {
55
- const interactionState = get(interactionOptionsAtom);
56
- if (interactionState.enableModalSelection) {
57
- const enableSelection = !interactionState.enableSelection;
58
-
59
- if (!enableSelection) {
60
- set(clearableSelectionAtom);
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, enableSelection } = interactionState;
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 { ctx, storeAtom, useSelector } from "../../provider";
8
- import { useMemo } from "react";
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,12 +107,149 @@ 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
  }
81
227
 
82
- function useDisplayIntent(atom) {
83
- const [hasActive, clearActive] = ctx.use(atom);
228
+ /** Active-state + clear for a subset of filters, keyed by id. */
229
+ function useFilterSubsetState(entries: FilterEntry[]): [boolean, () => void] {
230
+ const ids = entries.map((e) => e.filter.id);
231
+ const key = ids.join("\u0000");
232
+ const subsetAtom = useMemo(
233
+ () =>
234
+ atom(
235
+ (get) => {
236
+ const active = get(storeAtom)?.activeFilters;
237
+ if (active == null) return false;
238
+ return ids.some((id) => active.has(id));
239
+ },
240
+ (get) => {
241
+ const store = get(storeAtom);
242
+ if (store == null) return;
243
+ for (const id of ids) store.removeFilter(id);
244
+ },
245
+ ),
246
+ [key],
247
+ );
248
+ const [hasActive, clear] = ctx.use(subsetAtom);
249
+ return [hasActive, clear as () => void];
250
+ }
251
+
252
+ function useDisplayIntent([hasActive, clearActive]: [boolean, () => void]) {
84
253
  const intent = hasActive ? "primary" : "none";
85
254
 
86
255
  let rightIcon: "caret-down" | undefined = "caret-down";
@@ -97,7 +266,11 @@ function useDisplayIntent(atom) {
97
266
  }
98
267
 
99
268
  function useFilterMenuAction(entries: FilterEntry[]): TableAction | null {
100
- const rest = useDisplayIntent(hasActiveFiltersAtom);
269
+ // Scoped to the filters this menu actually holds. An `"inline"` filter has
270
+ // its own always-visible control, so it must not light up the Filter tag —
271
+ // nor be wiped by its clear button, which reads as "clear the filters in
272
+ // here".
273
+ const rest = useDisplayIntent(useFilterSubsetState(entries));
101
274
 
102
275
  if (entries.length === 0) return null;
103
276
 
@@ -145,7 +318,7 @@ function useFilterMenuAction(entries: FilterEntry[]): TableAction | null {
145
318
  function useSortAction(): TableAction | null {
146
319
  const columnSpec = useSelector((s) => s.columnSpec);
147
320
 
148
- const rest = useDisplayIntent(hasActiveSortsAtom);
321
+ const rest = useDisplayIntent(ctx.use(hasActiveSortsAtom));
149
322
 
150
323
  const sortableCols = useMemo(
151
324
  () => columnSpec.filter((c) => c.sortable),
@@ -184,15 +357,18 @@ function useSortAction(): TableAction | null {
184
357
  };
185
358
  }
186
359
 
360
+ // Both of these clear through the store's *actions* rather than writing the
361
+ // state directly: the actions are what also drop a now-meaningless row
362
+ // selection (see `dropRowSelection`).
187
363
  const hasActiveFiltersAtom = atom(
188
- (get) => get(storeAtom)?.activeFilters.size ?? 0 > 0,
189
- (get, set) => {
190
- set(storeAtom, (s) => ({ ...s, activeFilters: new Map([]) }));
364
+ (get) => (get(storeAtom)?.activeFilters?.size ?? 0) > 0,
365
+ (get) => {
366
+ get(storeAtom)?.clearFilters?.();
191
367
  },
192
368
  );
193
369
  const hasActiveSortsAtom = atom(
194
- (get) => get(storeAtom)?.columnSorts.length ?? 0 > 0,
195
- (get, set) => {
196
- set(storeAtom, (s) => ({ ...s, columnSorts: [] }));
370
+ (get) => (get(storeAtom)?.columnSorts?.length ?? 0) > 0,
371
+ (get) => {
372
+ get(storeAtom)?.clearColumnSorts?.();
197
373
  },
198
374
  );
@@ -3,7 +3,7 @@
3
3
  flex-direction: row
4
4
  gap: 8px
5
5
  align-items: center
6
- padding: 0.2em var(--data-panel-content-padding)
6
+ padding: 0.2em
7
7
  min-height: var(--panel-header-height, 40px)
8
8
 
9
9
  // Leading label naming the current selection shape (no icon) — reads as the
@@ -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
16
+ // Fallback to percentage
17
17
  --data-panel-content-width: 100%
18
+
18
19
  --data-panel-selected-color: #2d72d2
19
20
  --data-panel-selected-background: rgba(45, 114, 210, 0.1)
20
21
 
@@ -172,8 +173,7 @@
172
173
  width: unset
173
174
 
174
175
  .data-panel-toolbar
175
- left: 50%
176
- transform: translateX(calc((var(--data-panel-content-width, 100%) / -2) - 4px))
176
+ left: calc(var(--data-panel-content-padding, 12px) - 4px)
177
177
  top: var(--data-panel-content-padding, 12px)
178
178
  background-color: var(--panel-secondary-background-color)
179
179
  box-shadow: 0 0 0 1px var(--panel-rule-color)
@@ -200,3 +200,7 @@
200
200
  .data-panel-body.is-scrolled
201
201
  mask-image: linear-gradient(to bottom, transparent 0, var(--background-color) 20px)
202
202
 
203
+
204
+ // Every view control behind one button (`viewControls: "popover"`).
205
+ .collapsed-controls
206
+ 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(interactionOptionsAtom).enableSelection;
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, enableSelection } = get(
562
+ const { enableMultipleSelection, enableModalSelection } = get(
549
563
  interactionOptionsAtom,
550
564
  );
551
- if (!enableSelection) return;
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 { interactionOptionsAtom } from "./interactions.ts";
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(interactionOptionsAtom).enableSelection) return [];
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(interactionOptionsAtom).enableSelection) return;
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>> = {