@macrostrat/data-sheet 4.2.1 → 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.
Files changed (95) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/actions/types.d.ts +10 -0
  3. package/dist/components/indicators/filter-and-sort.cjs +61 -9
  4. package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
  5. package/dist/components/indicators/filter-and-sort.d.ts +49 -7
  6. package/dist/components/indicators/filter-and-sort.js +62 -10
  7. package/dist/components/indicators/filter-and-sort.js.map +1 -1
  8. package/dist/components/indicators/filter-and-sort.module.sass.cjs +7 -3
  9. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -1
  10. package/dist/components/indicators/filter-and-sort.module.sass.js +7 -3
  11. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -1
  12. package/dist/components/indicators/selection.cjs +7 -12
  13. package/dist/components/indicators/selection.cjs.map +1 -1
  14. package/dist/components/indicators/selection.d.ts +5 -0
  15. package/dist/components/indicators/selection.js +9 -14
  16. package/dist/components/indicators/selection.js.map +1 -1
  17. package/dist/components/indicators/unified-filters.cjs +135 -22
  18. package/dist/components/indicators/unified-filters.cjs.map +1 -1
  19. package/dist/components/indicators/unified-filters.d.ts +17 -8
  20. package/dist/components/indicators/unified-filters.js +137 -24
  21. package/dist/components/indicators/unified-filters.js.map +1 -1
  22. package/dist/components/indicators/view-info.cjs +6 -0
  23. package/dist/components/indicators/view-info.cjs.map +1 -1
  24. package/dist/components/indicators/view-info.d.ts +2 -2
  25. package/dist/components/indicators/view-info.js +7 -1
  26. package/dist/components/indicators/view-info.js.map +1 -1
  27. package/dist/components/toolbars/actions-toolbar.cjs +7 -1
  28. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
  29. package/dist/components/toolbars/actions-toolbar.js +7 -1
  30. package/dist/components/toolbars/actions-toolbar.js.map +1 -1
  31. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +12 -12
  32. package/dist/components/toolbars/actions-toolbar.module.sass.js +12 -12
  33. package/dist/data-panel.cjs +62 -9
  34. package/dist/data-panel.cjs.map +1 -1
  35. package/dist/data-panel.d.ts +14 -2
  36. package/dist/data-panel.js +64 -11
  37. package/dist/data-panel.js.map +1 -1
  38. package/dist/data-panel.module.sass.cjs +25 -21
  39. package/dist/data-panel.module.sass.cjs.map +1 -1
  40. package/dist/data-panel.module.sass.js +25 -21
  41. package/dist/data-panel.module.sass.js.map +1 -1
  42. package/dist/data-sheet.cjs +3 -1
  43. package/dist/data-sheet.cjs.map +1 -1
  44. package/dist/data-sheet.css +75 -50
  45. package/dist/data-sheet.d.ts +1 -1
  46. package/dist/data-sheet.js +3 -1
  47. package/dist/data-sheet.js.map +1 -1
  48. package/dist/index.cjs +6 -0
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.js +9 -3
  51. package/dist/postgrest-table/data-loaders.cjs +20 -3
  52. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  53. package/dist/postgrest-table/data-loaders.d.ts +10 -0
  54. package/dist/postgrest-table/data-loaders.js +21 -4
  55. package/dist/postgrest-table/data-loaders.js.map +1 -1
  56. package/dist/provider/core.cjs +27 -56
  57. package/dist/provider/core.cjs.map +1 -1
  58. package/dist/provider/core.d.ts +7 -9
  59. package/dist/provider/core.js +19 -48
  60. package/dist/provider/core.js.map +1 -1
  61. package/dist/provider/interactions.cjs +14 -0
  62. package/dist/provider/interactions.cjs.map +1 -1
  63. package/dist/provider/interactions.d.ts +20 -1
  64. package/dist/provider/interactions.js +15 -1
  65. package/dist/provider/interactions.js.map +1 -1
  66. package/dist/provider/selection.cjs +2 -2
  67. package/dist/provider/selection.cjs.map +1 -1
  68. package/dist/provider/selection.d.ts +1 -1
  69. package/dist/provider/selection.js +3 -3
  70. package/dist/provider/selection.js.map +1 -1
  71. package/dist/provider/zustand-store.cjs +13 -6
  72. package/dist/provider/zustand-store.cjs.map +1 -1
  73. package/dist/provider/zustand-store.js +13 -6
  74. package/dist/provider/zustand-store.js.map +1 -1
  75. package/dist/types.cjs.map +1 -1
  76. package/dist/types.d.ts +4 -0
  77. package/dist/types.js.map +1 -1
  78. package/package.json +5 -6
  79. package/src/actions/types.ts +11 -0
  80. package/src/components/indicators/filter-and-sort.module.sass +7 -0
  81. package/src/components/indicators/filter-and-sort.ts +102 -13
  82. package/src/components/indicators/selection.ts +10 -15
  83. package/src/components/indicators/unified-filters.ts +215 -32
  84. package/src/components/indicators/view-info.ts +10 -0
  85. package/src/components/toolbars/actions-toolbar.module.sass +1 -1
  86. package/src/components/toolbars/actions-toolbar.ts +10 -1
  87. package/src/data-panel.module.sass +26 -4
  88. package/src/data-panel.ts +92 -9
  89. package/src/data-sheet.ts +2 -0
  90. package/src/postgrest-table/data-loaders.ts +40 -4
  91. package/src/provider/core.ts +29 -53
  92. package/src/provider/interactions.ts +31 -0
  93. package/src/provider/selection.ts +3 -3
  94. package/src/provider/zustand-store.ts +23 -5
  95. package/src/types.ts +4 -0
@@ -1,47 +1,22 @@
1
- import { useRef, useMemo, useEffect, useState } from "react";
1
+ import { useRef, useMemo, useEffect } from "react";
2
2
  import h from "@macrostrat/hyper";
3
- import { useStore, createStore } from "zustand";
4
3
  import { generateColumnSpec, postprocessColumnSpec } from "./column-spec.js";
5
- import { createScopedStore } from "@macrostrat/data-components";
4
+ import { zustandAPIAtom, zustandStoreAtom, atom, createScopedStore, useZustandSelector, useZustandStoreAPI, ZustandStoreProvider } from "@macrostrat/scoped-store";
6
5
  import { TableElementStatus, DS_ROW_ID } from "./types.js";
7
6
  import { createZustandStore } from "./zustand-store.js";
8
- import { atomWithStore } from "jotai-zustand";
9
7
  import { toasterAtom } from "../notifications.js";
10
- import { atom } from "jotai";
11
8
  import { dataRefreshTokenAtom, createLocalProvider } from "./table-data.js";
12
9
  import { ToasterContext, ErrorBoundary } from "@macrostrat/ui-components";
13
10
  import { resolveInteractionOptions, DataViewRendererType, interactionOptionsAtom, interactionOptionsKeys } from "./interactions.js";
14
11
  import { splitProps } from "../utils/atoms.js";
15
12
  const ctx = createScopedStore();
16
- const storeAPIAtom = atom();
17
- const storeWrapperAtom = atom((get) => {
18
- const _storeAPIAtom = get(storeAPIAtom);
19
- if (_storeAPIAtom == null) {
20
- return void 0;
21
- }
22
- return atomWithStore(_storeAPIAtom);
23
- });
24
- const storeAtom = atom(
25
- (get) => {
26
- const storeWrapper = get(storeWrapperAtom);
27
- if (storeWrapper == null) {
28
- return void 0;
29
- }
30
- return get(storeWrapper);
31
- },
32
- (get, set, action) => {
33
- const storeWrapper = get(storeWrapperAtom);
34
- if (storeWrapper == null) {
35
- throw new Error("Missing DataSheetProvider");
36
- }
37
- return set(storeWrapper, action);
38
- }
39
- );
13
+ const storeAPIAtom = zustandAPIAtom;
14
+ const storeAtom = zustandStoreAtom;
40
15
  const EMPTY_SPEC = [];
41
16
  const initializeStoreAtom = atom(
42
17
  null,
43
18
  (get, set, payload) => {
44
- set(storeAtom, (state) => {
19
+ set(zustandStoreAtom, (state) => {
45
20
  return {
46
21
  ...state,
47
22
  ...payload
@@ -94,16 +69,13 @@ function useResolvedProvider(props) {
94
69
  }
95
70
  function DataSheetStoreWrapper(props) {
96
71
  const { toaster, ...rest } = props;
97
- const [store] = useState(() => {
98
- return createStore(createZustandStore);
99
- });
100
72
  return h(
101
- ctx.Provider,
73
+ ZustandStoreProvider,
102
74
  {
103
- atoms: [
104
- [storeAPIAtom, store],
105
- [toasterAtom, toaster]
106
- ]
75
+ ctx,
76
+ initializeStore: createZustandStore,
77
+ atoms: [[toasterAtom, toaster]],
78
+ debugName: "DataSheetProvider"
107
79
  },
108
80
  h(DataSheetProviderInner, rest)
109
81
  );
@@ -172,9 +144,13 @@ function DataSheetProviderInner(props) {
172
144
  useEffect(() => {
173
145
  initializeStore({
174
146
  columnSpec: postprocessColumnSpec(baseSpec),
175
- // A function spec is derived from the loaded rows in `_DataSheet`; tell
176
- // the loader not to auto-generate a plain spec from the first chunk.
177
- deferColumnSpec: isFnSpec,
147
+ // Suppress the loader's first-chunk auto-generation whenever the consumer
148
+ // provided a spec at all — a function (derived later in `_DataSheet`) OR
149
+ // an explicit array, *including an empty one*. An empty array means "no
150
+ // facet columns" (e.g. a browse panel whose only control is a sheet-level
151
+ // search), not "please generate from the data". Auto-gen runs only when
152
+ // no `columnSpec` was passed.
153
+ deferColumnSpec: columnSpec != null,
178
154
  editable: interactionOptions.enableEditing,
179
155
  enableColumnReordering,
180
156
  data,
@@ -235,15 +211,10 @@ function DataSheetProviderInner(props) {
235
211
  return children;
236
212
  }
237
213
  function useStoreAPI() {
238
- const store = ctx.useValue(storeAPIAtom);
239
- if (!store) {
240
- throw new Error("Missing DataSheetProvider");
241
- }
242
- return store;
214
+ return useZustandStoreAPI(ctx);
243
215
  }
244
216
  function useSelector(selector) {
245
- const store = useStoreAPI();
246
- return useStore(store, selector);
217
+ return useZustandSelector(ctx, selector);
247
218
  }
248
219
  const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);
249
220
  const tableDataAtom = atom(
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sources":["../../src/provider/core.ts"],"sourcesContent":["import { SetStateAction, useEffect, useMemo, useRef, useState } from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createStore, StoreApi, useStore } from \"zustand\";\nimport { Table } from \"@blueprintjs/table\";\nimport {\n type ColumnSpec,\n generateColumnSpec,\n postprocessColumnSpec,\n} from \"./column-spec.ts\";\nimport { splitProps } from \"../utils\";\nimport { createScopedStore } from \"@macrostrat/data-components\";\nimport {\n DataSheetProviderProps,\n DataSheetState,\n DataSheetStore,\n DS_ROW_ID,\n TableElementStatus,\n} from \"./types.ts\";\nimport { createZustandStore } from \"./zustand-store.ts\";\nimport { atomWithStore } from \"jotai-zustand\";\nimport { toasterAtom } from \"../notifications.ts\";\nimport { TableAction } from \"../actions\";\nimport { atom } from \"jotai\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n TableDataProvider,\n} from \"./table-data.ts\";\nimport { ErrorBoundary, ToasterContext } from \"@macrostrat/ui-components\";\nimport {\n DataViewRendererType,\n InteractionOptions,\n interactionOptionsAtom,\n interactionOptionsKeys,\n resolveInteractionOptions,\n} from \"./interactions.ts\";\nimport { DataViewProps } from \"../data-view.ts\";\nimport { DataSheetProps } from \"../types.ts\";\nimport { DataPanelProps } from \"../data-panel.ts\";\n\n/** Create a Jotai scoped store */\nexport const ctx = createScopedStore();\n\nexport const storeAPIAtom = atom<StoreApi<DataSheetStore<any>>>();\n\nconst storeWrapperAtom = atom((get) => {\n const _storeAPIAtom = get(storeAPIAtom);\n if (_storeAPIAtom == null) {\n return undefined;\n }\n return atomWithStore(_storeAPIAtom);\n});\n\n/** This is the basis for all other atoms that manipulate the store. */\nexport const storeAtom = atom(\n (get) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n return undefined;\n }\n return get(storeWrapper);\n },\n (get, set, action: SetStateAction<any>) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return set(storeWrapper, action);\n },\n);\n\n/** Stable empty spec so a function `columnSpec` yields a constant init value\n * (see `DataSheetProviderInner`). */\nconst EMPTY_SPEC: ColumnSpec[] = [];\n\nconst initializeStoreAtom = atom(\n null,\n (get, set, payload: Partial<DataSheetStore<any>>) => {\n set(storeAtom, (state) => {\n return {\n ...state,\n ...payload,\n };\n });\n },\n);\n\nexport const tableActionsAtom = atom<TableAction[]>([]);\n\n/** The resolved data source for the table, held in the provider layer (next to\n * the store) rather than resolved inside the render loop. `provider` is the\n * unified `TableDataProvider` (explicit, loose-`fetchData`-wrapped, or a local\n * in-memory provider); `isLocalProvider` distinguishes the in-memory case (it\n * loads the whole array at once and shows no load progress). `isExplicitProvider`\n * distinguishes an explicit `provider` object from a loose `fetchData`/`data`\n * source — only an explicit provider without `deleteRows` disables row\n * deletion; loose sources keep the local delete overlay. */\nexport interface ResolvedDataProvider {\n provider: TableDataProvider<any> | null;\n isLocalProvider: boolean;\n isExplicitProvider: boolean;\n /** Row count of an in-memory (local) source, so a renderer can size the\n * loader's page to \"all of it\" without also receiving the `data` prop. `0`\n * for non-local sources. */\n localCount: number;\n}\n\nconst DEFAULT_DATA_PROVIDER: ResolvedDataProvider = {\n provider: null,\n isLocalProvider: true,\n isExplicitProvider: false,\n localCount: 0,\n};\n\nexport const dataProviderAtom = atom<ResolvedDataProvider>(\n DEFAULT_DATA_PROVIDER,\n);\n\nconst EMPTY_ARRAY: any[] = [];\n\n/** Resolve a table's data source from the loose `provider` / `fetchData` /\n * `data` props (an explicit `provider` wins; else a loose `fetchData` (+\n * `identity`) is wrapped as one; else in-memory `data` becomes a local\n * provider). Shared by `DataSheet`, `DataPanel`, and `DataView` so all three\n * resolve identically. */\nexport function useResolvedProvider<T>(props: {\n provider?: TableDataProvider<T>;\n fetchData?: FetchData<T>;\n data?: T[];\n identity?: (row: T) => string | number | null | undefined;\n}): {\n data: T[];\n isLocalProvider: boolean;\n activeProvider: TableDataProvider<any> | null;\n dataProvider: ResolvedDataProvider;\n} {\n const _data = props.data ?? (EMPTY_ARRAY as T[]);\n const isLocalProvider = props.provider == null && props.fetchData == null;\n const isExplicitProvider = props.provider != null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (props.provider != null) return props.provider;\n if (props.fetchData != null) {\n return {\n fetchData: props.fetchData,\n identity: props.identity ?? ((r: any) => r?.id),\n } as TableDataProvider<any>;\n }\n if (_data.length > 0) {\n return createLocalProvider(\n _data,\n props.identity != null\n ? { identity: props.identity as (row: any) => string | number }\n : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.provider, props.fetchData, _data, props.identity]);\n const localCount = isLocalProvider ? _data.length : 0;\n const dataProvider = useMemo(\n () => ({\n provider: activeProvider,\n isLocalProvider,\n isExplicitProvider,\n localCount,\n }),\n [activeProvider, isLocalProvider, isExplicitProvider, localCount],\n );\n return { data: _data, isLocalProvider, activeProvider, dataProvider };\n}\n\nfunction DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {\n const { toaster, ...rest } = props;\n const [store] = useState(() => {\n return createStore<DataSheetStore<T>>(createZustandStore);\n });\n return h(\n ctx.Provider,\n {\n atoms: [\n [storeAPIAtom, store],\n [toasterAtom, toaster],\n ],\n },\n h(DataSheetProviderInner, rest),\n );\n}\n\nconst tableDataProviderKeys = new Set([\n \"provider\",\n \"fetchData\",\n \"data\",\n \"identity\",\n]);\n\nconst dataProviderKeys = new Set([\n \"columnSpec\",\n \"columnSpecOptions\",\n \"name\",\n \"itemLabel\",\n \"enableColumnReordering\",\n \"defaultColumnWidth\",\n \"refreshToken\",\n \"identity\",\n \"toaster\",\n \"viewType\",\n \"interactionOptions\",\n]);\n\ntype AnyDataSheetProps<T> =\n | DataViewProps<T>\n | DataPanelProps<T>\n | DataSheetProps<T>;\n\nexport function splitDataProviderProps<T>(props: AnyDataSheetProps<T>) {\n /** Split provided props based on provider's needs */\n return splitProps<AnyDataSheetProps<T>, DataSheetProviderProps<T>>(\n props,\n dataProviderKeys\n .union(interactionOptionsKeys)\n .union(tableDataProviderKeys) as Set<keyof DataSheetProviderProps<T>>,\n );\n}\n\nexport function DataSheetProvider<T>(\n props: DataSheetProviderProps<T> & { children: React.ReactNode },\n) {\n return h(\n ToasterContext,\n h(ErrorBoundary, h(DataSheetStoreWrapper<T>, props)),\n );\n}\n\ntype DataSheetProviderInnerProps<T> = DataSheetProviderProps<T> & {\n dataProvider?: ResolvedDataProvider;\n};\n\nexport function DataSheetProviderInner<T>(\n props: DataSheetProviderInnerProps<T>,\n) {\n const tableRef = useRef<Table>(null);\n\n const [interactionOptionsProps, providerProps] = splitProps<\n DataSheetProviderInnerProps<T>,\n InteractionOptions\n >(props, interactionOptionsKeys);\n const interactionOptions = resolveInteractionOptions(\n interactionOptionsProps,\n props.viewType ?? DataViewRendererType.TABLE,\n );\n\n const {\n children,\n columnSpec,\n columnSpecOptions,\n name,\n itemLabel,\n enableColumnReordering,\n defaultColumnWidth = 150,\n refreshToken,\n identity,\n } = providerProps;\n\n const { data, dataProvider } = useResolvedProvider<T>(providerProps);\n\n const initializeStore = ctx.useSet(initializeStoreAtom);\n const storeAPI = useStoreAPI<T>();\n\n // The wrapper resolves the data source (see `DataSheet`); publish it into the\n // scoped atom so the loader/store read it, rather than the inner render\n // component resolving it each render. Kept updated as `data`/`provider`\n // changes.\n\n ctx.useSync(dataProviderAtom, dataProvider ?? DEFAULT_DATA_PROVIDER);\n ctx.useSync(interactionOptionsAtom, interactionOptions);\n\n const contentLabels = useMemo(() => {\n return { tableName: name, itemLabel };\n }, [name, itemLabel]);\n\n ctx.useSync(contentLabelsAtom, contentLabels);\n\n // A function `columnSpec` is derived from the loaded rows later (in\n // `_DataSheet`), not here — start it empty. Crucially it's kept OUT of the\n // init effect's deps: re-running init also resets `data`, so re-initializing\n // when the function's identity changes (e.g. a consumer hiding a column)\n // would wipe the loaded rows. `staticSpec` is a stable value in that case.\n const isFnSpec = typeof columnSpec === \"function\";\n\n const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;\n // Not sure how required this initialization is\n const baseSpec = staticSpec ?? generateColumnSpec(data, columnSpecOptions);\n\n useEffect(() => {\n initializeStore({\n columnSpec: postprocessColumnSpec(baseSpec),\n // A function spec is derived from the loaded rows in `_DataSheet`; tell\n // the loader not to auto-generate a plain spec from the first chunk.\n deferColumnSpec: isFnSpec,\n editable: interactionOptions.enableEditing,\n enableColumnReordering,\n data,\n defaultColumnWidth,\n tableRef,\n });\n }, [\n data,\n interactionOptions.enableEditing,\n staticSpec,\n isFnSpec,\n columnSpecOptions,\n enableColumnReordering,\n ]);\n\n // Function `columnSpec`: derive the spec from the loaded rows (no separate\n // fetch of sample data), here at the provider level so BOTH renderers get it\n // — the sheet's cell grid and the panel's `FacetControls` read the same\n // derived spec. Derive once the first rows arrive, and re-derive when the\n // function's identity changes (a consumer memoizes it over its own view state\n // — hidden columns, order, overrides). Guarded by the function identity, so\n // it never re-runs as more rows page in (which would clobber in-store column\n // state on scroll).\n const loadedData = useSelector<T, T[]>((s) => s.data ?? []);\n const derivedSpecFor = useRef<unknown>(null);\n useEffect(() => {\n if (typeof columnSpec !== \"function\") return;\n if (derivedSpecFor.current === columnSpec) return;\n const rows = loadedData.filter((r) => r != null);\n if (rows.length === 0) return;\n derivedSpecFor.current = columnSpec;\n storeAPI.setState({ columnSpec: columnSpec(rows) });\n }, [columnSpec, loadedData, storeAPI]);\n\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n\n // Imperative re-fetch: bump `refreshToken` to reload the provider (e.g.\n // after a save). Skips the initial mount (the loader does its own first\n // fetch). Shared by `_DataSheet` and `_DataPanel` — driven off this one\n // provider-level `refreshToken`, whichever renderer is mounted.\n const firstRefreshToken = useRef(true);\n useEffect(() => {\n if (firstRefreshToken.current) {\n firstRefreshToken.current = false;\n return;\n }\n bumpRefresh((v) => v + 1);\n }, [refreshToken, bumpRefresh]);\n\n // Provider-backed, auto-refreshing row mutations on the action context\n // (`ctx.saveRows` / `deleteRows` / `insertRow`) — shared by `_DataSheet` and\n // `_DataPanel` (the basis of a table/cards toggle) — so an immediate-edit\n // action persists through the active provider and then re-fetches. Only the\n // capabilities the provider supports are present.\n useEffect(() => {\n const p = dataProvider?.provider ?? null;\n const refresh = () => bumpRefresh((v) => v + 1);\n const withRefresh = <A extends any[]>(\n fn?: (...args: A) => Promise<void>,\n ) =>\n fn == null\n ? undefined\n : async (...args: A) => {\n await fn(...args);\n refresh();\n };\n storeAPI.setState({\n rowEditing: {\n saveRows: withRefresh(p?.saveRows?.bind(p)),\n deleteRows: withRefresh(p?.deleteRows?.bind(p)),\n insertRow: withRefresh(p?.insertRow?.bind(p)),\n refresh,\n },\n });\n }, [storeAPI, dataProvider, bumpRefresh]);\n\n // The active provider supplies the row identity for the edit overlay\n // (`tableDataAtom`'s remap-by-identity), shared by `_DataSheet` and\n // `_DataPanel` — falls back to the loose `identity` prop when the resolved\n // provider doesn't carry its own (e.g. before the first row loads).\n useEffect(() => {\n const id = dataProvider?.provider?.identity ?? identity;\n if (id != null) storeAPI.setState({ identity: id });\n }, [storeAPI, dataProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` (not a loose\n // `fetchData`/`data` source) without `deleteRows` disables deletion\n // entirely. Loose/local sources keep the in-table delete overlay. Shared by\n // `_DataSheet` and `_DataPanel` — gates the delete action's disabled state\n // read by the shared `ActionsToolbar`.\n useEffect(() => {\n const canDeleteRows =\n !dataProvider?.isExplicitProvider ||\n dataProvider.provider?.deleteRows != null;\n storeAPI.setState({ canDeleteRows });\n }, [storeAPI, dataProvider]);\n\n return children;\n}\n\nexport function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {\n const store = ctx.useValue(storeAPIAtom);\n if (!store) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return store;\n}\n\nexport function useSelector<T = any, A = any>(\n selector: (state: DataSheetStore<T>) => A,\n): A {\n const store = useStoreAPI<T>();\n return useStore(store, selector);\n}\n/** Atoms for efficient sub-selection of state */\n\nexport const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);\n\nexport const tableDataAtom = atom(\n (get) => {\n return get(storeAtom)?.data ?? [];\n },\n (get, set, newData: any[]) => {\n set(storeAtom, (state: DataSheetState<any>): DataSheetState<any> => {\n let next: DataSheetState<any> = { ...state, data: newData };\n // Auto-generate a plain column spec the first time real rows arrive — no\n // spec yet and none deferred to a function (a function spec is derived\n // separately). Keyed on \"spec still empty + a non-null row present\", NOT\n // on `data.length == 0`: the loader pre-fills `data` with a page of `null`\n // ghost rows on reset, so the array is non-empty before the first chunk.\n if (state.columnSpec.length == 0 && !state.deferColumnSpec) {\n const sample = newData.filter((row) => row != null);\n if (sample.length > 0) {\n next.columnSpec = generateColumnSpec(sample, state.columnSpecOptions);\n }\n }\n\n // Re-attach the edit overlay by identity. The loader replaces `data` with\n // re-ordered windows on sort/filter, so an index-keyed overlay would\n // smear; keying by identity keeps edits (and deletes) on their rows, holds\n // edits for not-yet-loaded rows, and re-appends locally-added rows (which\n // aren't in the provider's data) after it. Skipped when the consumer\n // controls the overlay (they own reconciliation).\n if (!state.controlledOverlay) {\n const remap = remapOverlayByIdentity(state, newData);\n next.data = remap.data;\n next.updatedData = remap.updatedData;\n next.rowStatus = remap.rowStatus;\n next.pendingOverlayById = remap.pending;\n }\n\n return next;\n });\n },\n);\n\ntype OverlayEntry = { edit?: any; status?: any };\n\n/** Row identity used by the overlay: an in-table-added row's synthetic id\n * (stable across its edits), else the provider/consumer `identity`. */\nfunction overlayIdentity(\n state: DataSheetState<any>,\n row: any,\n): string | number | null | undefined {\n if (row == null) return undefined;\n const added = row[DS_ROW_ID];\n if (added != null) return added;\n return state.identity(row);\n}\n\n/** Re-project the (index-keyed) edit overlay from the old `data` order onto a\n * new one, matching rows by identity. Edits/statuses whose row is absent from\n * `newData` are held in `pending` and re-applied when the row loads; rows added\n * in-table (status `ADDED`) are re-appended after the provider data (they have\n * no provider row). Starts from the prior pending set so edits survive multiple\n * re-sorts. Returns the reconstructed data (provider rows + re-appended added\n * rows) alongside the re-aligned overlay. */\nfunction remapOverlayByIdentity(\n state: DataSheetState<any>,\n newData: any[],\n): {\n data: any[];\n updatedData: any[];\n rowStatus: any[];\n pending: Map<string | number, OverlayEntry>;\n} {\n const { data: oldData, updatedData, rowStatus } = state;\n\n // Collect current overlay entries by identity, seeded with prior pending.\n const byId = new Map<string | number, OverlayEntry>(state.pendingOverlayById);\n const n = Math.max(\n oldData.length,\n updatedData?.length ?? 0,\n rowStatus?.length ?? 0,\n );\n for (let i = 0; i < n; i++) {\n const row = oldData[i];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const edit = updatedData?.[i];\n const status = rowStatus?.[i];\n if (edit != null || status != null) byId.set(id, { edit, status });\n }\n\n // Project onto the new data order.\n const resultData = newData.slice();\n const nextUpdated: any[] = [];\n const nextStatus: any[] = [];\n const attached = new Set<string | number>();\n for (let j = 0; j < resultData.length; j++) {\n const row = resultData[j];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const entry = byId.get(id);\n if (entry == null) continue;\n if (entry.edit != null) nextUpdated[j] = entry.edit;\n if (entry.status != null) nextStatus[j] = entry.status;\n attached.add(id);\n }\n\n // Re-append in-table-added rows (not present in the provider data), then hold\n // anything still unattached (rows not currently loaded) as pending.\n const pending = new Map<string | number, OverlayEntry>();\n for (const [id, entry] of byId) {\n if (attached.has(id)) continue;\n if (entry.status === TableElementStatus.ADDED) {\n const idx = resultData.length;\n resultData.push(entry.edit ?? {});\n nextUpdated[idx] = entry.edit;\n nextStatus[idx] = entry.status;\n } else {\n pending.set(id, entry);\n }\n }\n\n return {\n data: resultData,\n updatedData: nextUpdated,\n rowStatus: nextStatus,\n pending,\n };\n}\n\ninterface ContentLabels {\n tableName: string | null | undefined;\n itemLabel: string | null | undefined;\n}\n\nconst contentLabelsAtom = atom<ContentLabels>({\n tableName: null,\n itemLabel: null,\n});\n\nexport const itemLabelAtom = atom<string>((get) => {\n return get(contentLabelsAtom).itemLabel ?? \"row\";\n});\nexport const tableNameAtom = atom<string | null>((get) => {\n let { tableName, itemLabel } = get(contentLabelsAtom);\n if (tableName != null) return tableName;\n if (itemLabel != null) capitalize(pluralize(itemLabel, 2));\n return \"Table\";\n});\n\nexport function useItemCount(n: number) {\n const dataKind = ctx.useValue(itemLabelAtom);\n return itemCount(n, dataKind ?? \"row\");\n}\n\nfunction itemCount(n: number, dataKind: string) {\n const base = n == 0 ? \"No\" : `${n}`;\n return base + \" \" + pluralize(dataKind, n);\n}\n\nexport function pluralize(singularForm: string, n: number) {\n const pluralForm = singularForm + \"s\";\n if (n == 0) return `${pluralForm}`;\n if (n == 1) return singularForm;\n return pluralForm;\n}\n\nexport function capitalize(s: string) {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA0CO,MAAM,MAAM,kBAAA;A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,OAAO;AAC7C,YAAM,MAAM,WAAW;AACvB,iBAAW,KAAK,MAAM,QAAQ,CAAA,CAAE;AAChC,kBAAY,GAAG,IAAI,MAAM;AACzB,iBAAW,GAAG,IAAI,MAAM;AAAA,IAC1B,OAAO;AACL,cAAQ,IAAI,IAAI,KAAK;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX;AAAA,EAAA;AAEJ;AAOA,MAAM,oBAAoB,KAAoB;AAAA,EAC5C,WAAW;AAAA,EACX,WAAW;AACb,CAAC;AAEM,MAAM,gBAAgB,KAAa,CAAC,QAAQ;AACjD,SAAO,IAAI,iBAAiB,EAAE,aAAa;AAC7C,CAAC;AACM,MAAM,gBAAgB,KAAoB,CAAC,QAAQ;AACxD,MAAI,EAAE,WAAW,cAAc,IAAI,iBAAiB;AACpD,MAAI,aAAa,KAAM,QAAO;AAC9B,MAAI,aAAa,KAAM,YAAW,UAAU,WAAW,CAAC,CAAC;AACzD,SAAO;AACT,CAAC;AAEM,SAAS,aAAa,GAAW;AACtC,QAAM,WAAW,IAAI,SAAS,aAAa;AAC3C,SAAO,UAAU,GAAG,YAAY,KAAK;AACvC;AAEA,SAAS,UAAU,GAAW,UAAkB;AAC9C,QAAM,OAAO,KAAK,IAAI,OAAO,GAAG,CAAC;AACjC,SAAO,OAAO,MAAM,UAAU,UAAU,CAAC;AAC3C;AAEO,SAAS,UAAU,cAAsB,GAAW;AACzD,QAAM,aAAa,eAAe;AAClC,MAAI,KAAK,EAAG,QAAO,GAAG,UAAU;AAChC,MAAI,KAAK,EAAG,QAAO;AACnB,SAAO;AACT;AAEO,SAAS,WAAW,GAAW;AACpC,SAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC;AAC9C;"}
1
+ {"version":3,"file":"core.js","sources":["../../src/provider/core.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { Table } from \"@blueprintjs/table\";\nimport {\n type ColumnSpec,\n generateColumnSpec,\n postprocessColumnSpec,\n} from \"./column-spec.ts\";\nimport { splitProps } from \"../utils\";\nimport {\n createScopedStore,\n zustandAPIAtom,\n zustandStoreAtom,\n atom,\n ZustandStoreProvider,\n useZustandSelector,\n useZustandStoreAPI,\n} from \"@macrostrat/scoped-store\";\nimport {\n DataSheetProviderProps,\n DataSheetState,\n DataSheetStore,\n DS_ROW_ID,\n TableElementStatus,\n} from \"./types.ts\";\nimport { createZustandStore } from \"./zustand-store.ts\";\nimport { toasterAtom } from \"../notifications.ts\";\nimport { TableAction } from \"../actions\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n TableDataProvider,\n} from \"./table-data.ts\";\nimport { ErrorBoundary, ToasterContext } from \"@macrostrat/ui-components\";\nimport {\n DataViewRendererType,\n InteractionOptions,\n interactionOptionsAtom,\n interactionOptionsKeys,\n resolveInteractionOptions,\n} from \"./interactions.ts\";\nimport { DataViewProps } from \"../data-view.ts\";\nimport { DataSheetProps } from \"../types.ts\";\nimport { DataPanelProps } from \"../data-panel.ts\";\n\n/** Create a Jotai scoped store */\nexport const ctx = createScopedStore();\n\nexport const storeAPIAtom = zustandAPIAtom;\n\n/** This is the basis for all other atoms that manipulate the store. */\nexport const storeAtom = zustandStoreAtom;\n\n/** Stable empty spec so a function `columnSpec` yields a constant init value\n * (see `DataSheetProviderInner`). */\nconst EMPTY_SPEC: ColumnSpec[] = [];\n\nconst initializeStoreAtom = atom(\n null,\n (get, set, payload: Partial<DataSheetStore<any>>) => {\n set(zustandStoreAtom, (state) => {\n return {\n ...state,\n ...payload,\n };\n });\n },\n);\n\nexport const tableActionsAtom = atom<TableAction[]>([]);\n\n/** The resolved data source for the table, held in the provider layer (next to\n * the store) rather than resolved inside the render loop. `provider` is the\n * unified `TableDataProvider` (explicit, loose-`fetchData`-wrapped, or a local\n * in-memory provider); `isLocalProvider` distinguishes the in-memory case (it\n * loads the whole array at once and shows no load progress). `isExplicitProvider`\n * distinguishes an explicit `provider` object from a loose `fetchData`/`data`\n * source — only an explicit provider without `deleteRows` disables row\n * deletion; loose sources keep the local delete overlay. */\nexport interface ResolvedDataProvider {\n provider: TableDataProvider<any> | null;\n isLocalProvider: boolean;\n isExplicitProvider: boolean;\n /** Row count of an in-memory (local) source, so a renderer can size the\n * loader's page to \"all of it\" without also receiving the `data` prop. `0`\n * for non-local sources. */\n localCount: number;\n}\n\nconst DEFAULT_DATA_PROVIDER: ResolvedDataProvider = {\n provider: null,\n isLocalProvider: true,\n isExplicitProvider: false,\n localCount: 0,\n};\n\nexport const dataProviderAtom = atom<ResolvedDataProvider>(\n DEFAULT_DATA_PROVIDER,\n);\n\nconst EMPTY_ARRAY: any[] = [];\n\n/** Resolve a table's data source from the loose `provider` / `fetchData` /\n * `data` props (an explicit `provider` wins; else a loose `fetchData` (+\n * `identity`) is wrapped as one; else in-memory `data` becomes a local\n * provider). Shared by `DataSheet`, `DataPanel`, and `DataView` so all three\n * resolve identically. */\nexport function useResolvedProvider<T>(props: {\n provider?: TableDataProvider<T>;\n fetchData?: FetchData<T>;\n data?: T[];\n identity?: (row: T) => string | number | null | undefined;\n}): {\n data: T[];\n isLocalProvider: boolean;\n activeProvider: TableDataProvider<any> | null;\n dataProvider: ResolvedDataProvider;\n} {\n const _data = props.data ?? (EMPTY_ARRAY as T[]);\n const isLocalProvider = props.provider == null && props.fetchData == null;\n const isExplicitProvider = props.provider != null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (props.provider != null) return props.provider;\n if (props.fetchData != null) {\n return {\n fetchData: props.fetchData,\n identity: props.identity ?? ((r: any) => r?.id),\n } as TableDataProvider<any>;\n }\n if (_data.length > 0) {\n return createLocalProvider(\n _data,\n props.identity != null\n ? { identity: props.identity as (row: any) => string | number }\n : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.provider, props.fetchData, _data, props.identity]);\n const localCount = isLocalProvider ? _data.length : 0;\n const dataProvider = useMemo(\n () => ({\n provider: activeProvider,\n isLocalProvider,\n isExplicitProvider,\n localCount,\n }),\n [activeProvider, isLocalProvider, isExplicitProvider, localCount],\n );\n return { data: _data, isLocalProvider, activeProvider, dataProvider };\n}\n\nfunction DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {\n const { toaster, ...rest } = props;\n return h(\n ZustandStoreProvider,\n {\n ctx,\n initializeStore: createZustandStore,\n atoms: [[toasterAtom, toaster]],\n debugName: \"DataSheetProvider\",\n },\n h(DataSheetProviderInner, rest),\n );\n}\n\nconst tableDataProviderKeys = new Set([\n \"provider\",\n \"fetchData\",\n \"data\",\n \"identity\",\n]);\n\nconst dataProviderKeys = new Set([\n \"columnSpec\",\n \"columnSpecOptions\",\n \"name\",\n \"itemLabel\",\n \"enableColumnReordering\",\n \"defaultColumnWidth\",\n \"refreshToken\",\n \"identity\",\n \"toaster\",\n \"viewType\",\n \"interactionOptions\",\n]);\n\ntype AnyDataSheetProps<T> =\n DataViewProps<T> | DataPanelProps<T> | DataSheetProps<T>;\n\nexport function splitDataProviderProps<T>(props: AnyDataSheetProps<T>) {\n /** Split provided props based on provider's needs */\n return splitProps<AnyDataSheetProps<T>, DataSheetProviderProps<T>>(\n props,\n dataProviderKeys\n .union(interactionOptionsKeys)\n .union(tableDataProviderKeys) as Set<keyof DataSheetProviderProps<T>>,\n );\n}\n\nexport function DataSheetProvider<T>(\n props: DataSheetProviderProps<T> & { children: React.ReactNode },\n) {\n return h(\n ToasterContext,\n h(ErrorBoundary, h(DataSheetStoreWrapper<T>, props)),\n );\n}\n\ntype DataSheetProviderInnerProps<T> = DataSheetProviderProps<T> & {\n dataProvider?: ResolvedDataProvider;\n};\n\nexport function DataSheetProviderInner<T>(\n props: DataSheetProviderInnerProps<T>,\n) {\n const tableRef = useRef<Table>(null);\n\n const [interactionOptionsProps, providerProps] = splitProps<\n DataSheetProviderInnerProps<T>,\n InteractionOptions\n >(props, interactionOptionsKeys);\n const interactionOptions = resolveInteractionOptions(\n interactionOptionsProps,\n props.viewType ?? DataViewRendererType.TABLE,\n );\n\n const {\n children,\n columnSpec,\n columnSpecOptions,\n name,\n itemLabel,\n enableColumnReordering,\n defaultColumnWidth = 150,\n refreshToken,\n identity,\n } = providerProps;\n\n const { data, dataProvider } = useResolvedProvider<T>(providerProps);\n\n const initializeStore = ctx.useSet(initializeStoreAtom);\n const storeAPI = useStoreAPI<T>();\n\n // The wrapper resolves the data source (see `DataSheet`); publish it into the\n // scoped atom so the loader/store read it, rather than the inner render\n // component resolving it each render. Kept updated as `data`/`provider`\n // changes.\n\n ctx.useSync(dataProviderAtom, dataProvider ?? DEFAULT_DATA_PROVIDER);\n ctx.useSync(interactionOptionsAtom, interactionOptions);\n\n const contentLabels = useMemo(() => {\n return { tableName: name, itemLabel };\n }, [name, itemLabel]);\n\n ctx.useSync(contentLabelsAtom, contentLabels);\n\n // A function `columnSpec` is derived from the loaded rows later (in\n // `_DataSheet`), not here — start it empty. Crucially it's kept OUT of the\n // init effect's deps: re-running init also resets `data`, so re-initializing\n // when the function's identity changes (e.g. a consumer hiding a column)\n // would wipe the loaded rows. `staticSpec` is a stable value in that case.\n const isFnSpec = typeof columnSpec === \"function\";\n\n const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;\n // Not sure how required this initialization is\n const baseSpec = staticSpec ?? generateColumnSpec(data, columnSpecOptions);\n\n useEffect(() => {\n initializeStore({\n columnSpec: postprocessColumnSpec(baseSpec),\n // Suppress the loader's first-chunk auto-generation whenever the consumer\n // provided a spec at all — a function (derived later in `_DataSheet`) OR\n // an explicit array, *including an empty one*. An empty array means \"no\n // facet columns\" (e.g. a browse panel whose only control is a sheet-level\n // search), not \"please generate from the data\". Auto-gen runs only when\n // no `columnSpec` was passed.\n deferColumnSpec: columnSpec != null,\n editable: interactionOptions.enableEditing,\n enableColumnReordering,\n data,\n defaultColumnWidth,\n tableRef,\n });\n }, [\n data,\n interactionOptions.enableEditing,\n staticSpec,\n isFnSpec,\n columnSpecOptions,\n enableColumnReordering,\n ]);\n\n // Function `columnSpec`: derive the spec from the loaded rows (no separate\n // fetch of sample data), here at the provider level so BOTH renderers get it\n // — the sheet's cell grid and the panel's `FacetControls` read the same\n // derived spec. Derive once the first rows arrive, and re-derive when the\n // function's identity changes (a consumer memoizes it over its own view state\n // — hidden columns, order, overrides). Guarded by the function identity, so\n // it never re-runs as more rows page in (which would clobber in-store column\n // state on scroll).\n const loadedData = useSelector<T, T[]>((s) => s.data ?? []);\n const derivedSpecFor = useRef<unknown>(null);\n useEffect(() => {\n if (typeof columnSpec !== \"function\") return;\n if (derivedSpecFor.current === columnSpec) return;\n const rows = loadedData.filter((r) => r != null);\n if (rows.length === 0) return;\n derivedSpecFor.current = columnSpec;\n storeAPI.setState({ columnSpec: columnSpec(rows) });\n }, [columnSpec, loadedData, storeAPI]);\n\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n\n // Imperative re-fetch: bump `refreshToken` to reload the provider (e.g.\n // after a save). Skips the initial mount (the loader does its own first\n // fetch). Shared by `_DataSheet` and `_DataPanel` — driven off this one\n // provider-level `refreshToken`, whichever renderer is mounted.\n const firstRefreshToken = useRef(true);\n useEffect(() => {\n if (firstRefreshToken.current) {\n firstRefreshToken.current = false;\n return;\n }\n bumpRefresh((v) => v + 1);\n }, [refreshToken, bumpRefresh]);\n\n // Provider-backed, auto-refreshing row mutations on the action context\n // (`ctx.saveRows` / `deleteRows` / `insertRow`) — shared by `_DataSheet` and\n // `_DataPanel` (the basis of a table/cards toggle) — so an immediate-edit\n // action persists through the active provider and then re-fetches. Only the\n // capabilities the provider supports are present.\n useEffect(() => {\n const p = dataProvider?.provider ?? null;\n const refresh = () => bumpRefresh((v) => v + 1);\n const withRefresh = <A extends any[]>(\n fn?: (...args: A) => Promise<void>,\n ) =>\n fn == null\n ? undefined\n : async (...args: A) => {\n await fn(...args);\n refresh();\n };\n storeAPI.setState({\n rowEditing: {\n saveRows: withRefresh(p?.saveRows?.bind(p)),\n deleteRows: withRefresh(p?.deleteRows?.bind(p)),\n insertRow: withRefresh(p?.insertRow?.bind(p)),\n refresh,\n },\n });\n }, [storeAPI, dataProvider, bumpRefresh]);\n\n // The active provider supplies the row identity for the edit overlay\n // (`tableDataAtom`'s remap-by-identity), shared by `_DataSheet` and\n // `_DataPanel` — falls back to the loose `identity` prop when the resolved\n // provider doesn't carry its own (e.g. before the first row loads).\n useEffect(() => {\n const id = dataProvider?.provider?.identity ?? identity;\n if (id != null) storeAPI.setState({ identity: id });\n }, [storeAPI, dataProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` (not a loose\n // `fetchData`/`data` source) without `deleteRows` disables deletion\n // entirely. Loose/local sources keep the in-table delete overlay. Shared by\n // `_DataSheet` and `_DataPanel` — gates the delete action's disabled state\n // read by the shared `ActionsToolbar`.\n useEffect(() => {\n const canDeleteRows =\n !dataProvider?.isExplicitProvider ||\n dataProvider.provider?.deleteRows != null;\n storeAPI.setState({ canDeleteRows });\n }, [storeAPI, dataProvider]);\n\n return children;\n}\n\nexport function useStoreAPI<T>() {\n return useZustandStoreAPI<DataSheetStore<T>>(ctx);\n}\n\nexport function useSelector<T = any, A = any>(\n selector: (state: DataSheetStore<T>) => A,\n): A {\n return useZustandSelector<T, A>(ctx, selector);\n}\n/** Atoms for efficient sub-selection of state */\n\nexport const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);\n\nexport const tableDataAtom = atom(\n (get) => {\n return get(storeAtom)?.data ?? [];\n },\n (get, set, newData: any[]) => {\n set(storeAtom, (state: DataSheetState<any>): DataSheetState<any> => {\n let next: DataSheetState<any> = { ...state, data: newData };\n // Auto-generate a plain column spec the first time real rows arrive — no\n // spec yet and none deferred to a function (a function spec is derived\n // separately). Keyed on \"spec still empty + a non-null row present\", NOT\n // on `data.length == 0`: the loader pre-fills `data` with a page of `null`\n // ghost rows on reset, so the array is non-empty before the first chunk.\n if (state.columnSpec.length == 0 && !state.deferColumnSpec) {\n const sample = newData.filter((row) => row != null);\n if (sample.length > 0) {\n next.columnSpec = generateColumnSpec(sample, state.columnSpecOptions);\n }\n }\n\n // Re-attach the edit overlay by identity. The loader replaces `data` with\n // re-ordered windows on sort/filter, so an index-keyed overlay would\n // smear; keying by identity keeps edits (and deletes) on their rows, holds\n // edits for not-yet-loaded rows, and re-appends locally-added rows (which\n // aren't in the provider's data) after it. Skipped when the consumer\n // controls the overlay (they own reconciliation).\n if (!state.controlledOverlay) {\n const remap = remapOverlayByIdentity(state, newData);\n next.data = remap.data;\n next.updatedData = remap.updatedData;\n next.rowStatus = remap.rowStatus;\n next.pendingOverlayById = remap.pending;\n }\n\n return next;\n });\n },\n);\n\ntype OverlayEntry = { edit?: any; status?: any };\n\n/** Row identity used by the overlay: an in-table-added row's synthetic id\n * (stable across its edits), else the provider/consumer `identity`. */\nfunction overlayIdentity(\n state: DataSheetState<any>,\n row: any,\n): string | number | null | undefined {\n if (row == null) return undefined;\n const added = row[DS_ROW_ID];\n if (added != null) return added;\n return state.identity(row);\n}\n\n/** Re-project the (index-keyed) edit overlay from the old `data` order onto a\n * new one, matching rows by identity. Edits/statuses whose row is absent from\n * `newData` are held in `pending` and re-applied when the row loads; rows added\n * in-table (status `ADDED`) are re-appended after the provider data (they have\n * no provider row). Starts from the prior pending set so edits survive multiple\n * re-sorts. Returns the reconstructed data (provider rows + re-appended added\n * rows) alongside the re-aligned overlay. */\nfunction remapOverlayByIdentity(\n state: DataSheetState<any>,\n newData: any[],\n): {\n data: any[];\n updatedData: any[];\n rowStatus: any[];\n pending: Map<string | number, OverlayEntry>;\n} {\n const { data: oldData, updatedData, rowStatus } = state;\n\n // Collect current overlay entries by identity, seeded with prior pending.\n const byId = new Map<string | number, OverlayEntry>(state.pendingOverlayById);\n const n = Math.max(\n oldData.length,\n updatedData?.length ?? 0,\n rowStatus?.length ?? 0,\n );\n for (let i = 0; i < n; i++) {\n const row = oldData[i];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const edit = updatedData?.[i];\n const status = rowStatus?.[i];\n if (edit != null || status != null) byId.set(id, { edit, status });\n }\n\n // Project onto the new data order.\n const resultData = newData.slice();\n const nextUpdated: any[] = [];\n const nextStatus: any[] = [];\n const attached = new Set<string | number>();\n for (let j = 0; j < resultData.length; j++) {\n const row = resultData[j];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const entry = byId.get(id);\n if (entry == null) continue;\n if (entry.edit != null) nextUpdated[j] = entry.edit;\n if (entry.status != null) nextStatus[j] = entry.status;\n attached.add(id);\n }\n\n // Re-append in-table-added rows (not present in the provider data), then hold\n // anything still unattached (rows not currently loaded) as pending.\n const pending = new Map<string | number, OverlayEntry>();\n for (const [id, entry] of byId) {\n if (attached.has(id)) continue;\n if (entry.status === TableElementStatus.ADDED) {\n const idx = resultData.length;\n resultData.push(entry.edit ?? {});\n nextUpdated[idx] = entry.edit;\n nextStatus[idx] = entry.status;\n } else {\n pending.set(id, entry);\n }\n }\n\n return {\n data: resultData,\n updatedData: nextUpdated,\n rowStatus: nextStatus,\n pending,\n };\n}\n\ninterface ContentLabels {\n tableName: string | null | undefined;\n itemLabel: string | null | undefined;\n}\n\nconst contentLabelsAtom = atom<ContentLabels>({\n tableName: null,\n itemLabel: null,\n});\n\nexport const itemLabelAtom = atom<string>((get) => {\n return get(contentLabelsAtom).itemLabel ?? \"row\";\n});\nexport const tableNameAtom = atom<string | null>((get) => {\n let { tableName, itemLabel } = get(contentLabelsAtom);\n if (tableName != null) return tableName;\n if (itemLabel != null) capitalize(pluralize(itemLabel, 2));\n return \"Table\";\n});\n\nexport function useItemCount(n: number) {\n const dataKind = ctx.useValue(itemLabelAtom);\n return itemCount(n, dataKind ?? \"row\");\n}\n\nfunction itemCount(n: number, dataKind: string) {\n const base = n == 0 ? \"No\" : `${n}`;\n return base + \" \" + pluralize(dataKind, n);\n}\n\nexport function pluralize(singularForm: string, n: number) {\n const pluralForm = singularForm + \"s\";\n if (n == 0) return `${pluralForm}`;\n if (n == 1) return singularForm;\n return pluralForm;\n}\n\nexport function capitalize(s: string) {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA+CO,MAAM,MAAM,kBAAA;AAEZ,MAAM,eAAe;AAGrB,MAAM,YAAY;AAIzB,MAAM,aAA2B,CAAA;AAEjC,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA,CAAC,KAAK,KAAK,YAA0C;AACnD,QAAI,kBAAkB,CAAC,UAAU;AAC/B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MAAA;AAAA,IAEP,CAAC;AAAA,EACH;AACF;AAEO,MAAM,mBAAmB,KAAoB,CAAA,CAAE;AAoBtD,MAAM,wBAA8C;AAAA,EAClD,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,YAAY;AACd;AAEO,MAAM,mBAAmB;AAAA,EAC9B;AACF;AAEA,MAAM,cAAqB,CAAA;AAOpB,SAAS,oBAAuB,OAUrC;AACA,QAAM,QAAQ,MAAM,QAAS;AAC7B,QAAM,kBAAkB,MAAM,YAAY,QAAQ,MAAM,aAAa;AACrE,QAAM,qBAAqB,MAAM,YAAY;AAC7C,QAAM,iBAAiB,QAAuC,MAAM;AAClE,QAAI,MAAM,YAAY,KAAM,QAAO,MAAM;AACzC,QAAI,MAAM,aAAa,MAAM;AAC3B,aAAO;AAAA,QACL,WAAW,MAAM;AAAA,QACjB,UAAU,MAAM,aAAa,CAAC,MAAW,GAAG;AAAA,MAAA;AAAA,IAEhD;AACA,QAAI,MAAM,SAAS,GAAG;AACpB,aAAO;AAAA,QACL;AAAA,QACA,MAAM,YAAY,OACd,EAAE,UAAU,MAAM,aAClB;AAAA,MAAA;AAAA,IAER;AACA,WAAO;AAAA,EAET,GAAG,CAAC,MAAM,UAAU,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC;AAC3D,QAAM,aAAa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M,MAAM,gBAAgB,KAAoB,CAAC,QAAQ;AACxD,MAAI,EAAE,WAAW,cAAc,IAAI,iBAAiB;AACpD,MAAI,aAAa,KAAM,QAAO;AAC9B,MAAI,aAAa,KAAM,YAAW,UAAU,WAAW,CAAC,CAAC;AACzD,SAAO;AACT,CAAC;AAEM,SAAS,aAAa,GAAW;AACtC,QAAM,WAAW,IAAI,SAAS,aAAa;AAC3C,SAAO,UAAU,GAAG,YAAY,KAAK;AACvC;AAEA,SAAS,UAAU,GAAW,UAAkB;AAC9C,QAAM,OAAO,KAAK,IAAI,OAAO,GAAG,CAAC;AACjC,SAAO,OAAO,MAAM,UAAU,UAAU,CAAC;AAC3C;AAEO,SAAS,UAAU,cAAsB,GAAW;AACzD,QAAM,aAAa,eAAe;AAClC,MAAI,KAAK,EAAG,QAAO,GAAG,UAAU;AAChC,MAAI,KAAK,EAAG,QAAO;AACnB,SAAO;AACT;AAEO,SAAS,WAAW,GAAW;AACpC,SAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC;AAC9C;"}
@@ -111,6 +111,18 @@ function resolveInteractionOptions(opts, renderer) {
111
111
  enableSelection
112
112
  };
113
113
  }
114
+ const selectionModeActiveAtom = jotai.atom(false);
115
+ const enableSelectionAtom = jotai.atom(
116
+ (get) => {
117
+ const options = get(interactionOptionsAtom);
118
+ if (options.enableModalSelection) return get(selectionModeActiveAtom);
119
+ return options.enableSelection;
120
+ },
121
+ (get, set, next) => {
122
+ if (!get(interactionOptionsAtom).enableModalSelection) return;
123
+ set(selectionModeActiveAtom, next);
124
+ }
125
+ );
114
126
  const enableDragValueAtom = jotai.atom((get) => {
115
127
  return get(interactionOptionsAtom).enableDragValue;
116
128
  });
@@ -122,7 +134,9 @@ exports.DataViewRendererType = DataViewRendererType;
122
134
  exports.SelectionInteractionStyle = SelectionInteractionStyle;
123
135
  exports.dragValueHandlerAtom = dragValueHandlerAtom;
124
136
  exports.enableDragValueAtom = enableDragValueAtom;
137
+ exports.enableSelectionAtom = enableSelectionAtom;
125
138
  exports.interactionOptionsAtom = interactionOptionsAtom;
126
139
  exports.interactionOptionsKeys = interactionOptionsKeys;
127
140
  exports.resolveInteractionOptions = resolveInteractionOptions;
141
+ exports.selectionModeActiveAtom = selectionModeActiveAtom;
128
142
  //# sourceMappingURL=interactions.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"interactions.cjs","sources":["../../src/provider/interactions.ts"],"sourcesContent":["import { RegionCardinality } from \"@blueprintjs/table\";\nimport { atom } from \"jotai\";\nimport { storeAtom } from \"./core.ts\";\n\nexport enum DataViewRendererType {\n CARDS = \"cards\",\n TABLE = \"table\",\n}\n\nexport interface InteractionOptionsResolved {\n enableEditing: boolean;\n enableSelection: boolean;\n // We have a potentially modal selection\n enableModalSelection: boolean;\n /** Options for data interaction (editing and selection) */\n enableMultipleSelection: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue: boolean;\n selectionModes: RegionCardinality[];\n}\n\nconst defaultInteractionOptions: InteractionOptionsResolved = {\n enableEditing: false,\n enableSelection: false,\n enableModalSelection: false,\n enableMultipleSelection: false,\n enableDragValue: false,\n selectionModes: [],\n};\n\n/** Atom to store interaction options state */\nexport const interactionOptionsAtom = atom<InteractionOptionsResolved>(\n defaultInteractionOptions,\n);\n\nexport enum SelectionInteractionStyle {\n ALWAYS = \"always\",\n NEVER = \"never\",\n MODAL = \"modal\",\n}\n\nexport interface InteractionOptions {\n /** Options for data interaction (editing and selection) */\n /** @deprecated: Use enableEditing instead */\n editable?: boolean;\n enableEditing?: boolean;\n enableSelection?: boolean | SelectionInteractionStyle;\n enableMultipleSelection?: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue?: boolean;\n selectionModes?: RegionCardinality[];\n interactionOptions?: InteractionOptionsResolved;\n}\n\nexport const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([\n \"editable\",\n \"enableEditing\",\n \"enableSelection\",\n \"enableMultipleSelection\",\n \"enableDragValue\",\n \"selectionModes\",\n \"interactionOptions\",\n]);\n\n/** Resolve the granular interaction options for a particular editing domain */\nexport function resolveInteractionOptions(\n opts: InteractionOptions,\n renderer: DataViewRendererType,\n): InteractionOptionsResolved {\n // If the user has provided interaction options, use them.\n if (opts.interactionOptions) return opts.interactionOptions;\n\n /** Resolve a unified set of interaction options for the table and cards */\n let {\n enableEditing,\n selectionModes,\n enableSelection: _enableSelection,\n enableDragValue,\n enableMultipleSelection,\n } = opts;\n\n if (renderer == DataViewRendererType.CARDS) {\n _enableSelection ??= true;\n }\n\n let enableSelection: boolean;\n let enableModalSelection = false;\n if (typeof _enableSelection === \"string\") {\n switch (_enableSelection) {\n case SelectionInteractionStyle.ALWAYS:\n enableSelection = true;\n break;\n case SelectionInteractionStyle.NEVER:\n enableSelection = false;\n break;\n case SelectionInteractionStyle.MODAL:\n enableSelection = false;\n enableModalSelection = true;\n break;\n }\n } else {\n enableSelection ??= _enableSelection ?? true;\n }\n\n enableEditing ??= opts.editable ?? enableSelection ?? true;\n enableMultipleSelection ??= true;\n if (renderer == DataViewRendererType.TABLE) {\n if (selectionModes != null) {\n enableSelection = new Set(selectionModes).size > 0;\n }\n enableSelection ??= true;\n if (enableSelection) {\n selectionModes ??= [\n RegionCardinality.FULL_TABLE,\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n ];\n enableEditing ??= true;\n enableDragValue ??= true;\n } else {\n selectionModes ??= [RegionCardinality.FULL_TABLE];\n }\n if (!selectionModes.includes(RegionCardinality.CELLS)) {\n enableEditing = false;\n }\n enableDragValue ??= enableEditing;\n } else if (renderer == DataViewRendererType.CARDS) {\n if (enableSelection) {\n // Only one selection mode possible\n selectionModes = [\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_TABLE,\n ];\n enableEditing ??= true;\n } else {\n selectionModes = [RegionCardinality.FULL_TABLE];\n }\n enableDragValue = false;\n }\n if (!enableEditing) {\n enableDragValue = false;\n }\n\n return {\n enableEditing,\n enableDragValue: enableDragValue ?? false,\n enableMultipleSelection,\n selectionModes: selectionModes as RegionCardinality[],\n enableModalSelection,\n enableSelection,\n };\n}\n\nexport const enableDragValueAtom = atom((get) => {\n return get(interactionOptionsAtom).enableDragValue;\n});\nexport const dragValueHandlerAtom = atom((get) => {\n if (!get(enableDragValueAtom)) return undefined;\n return get(storeAtom)?.onDragValue;\n});\n"],"names":["DataViewRendererType","atom","SelectionInteractionStyle","RegionCardinality","storeAtom"],"mappings":";;;;;AAIO,IAAK,yCAAAA,0BAAL;AACLA,wBAAA,OAAA,IAAQ;AACRA,wBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,wBAAA,CAAA,CAAA;AAiBZ,MAAM,4BAAwD;AAAA,EAC5D,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,yBAAyB;AAAA,EACzB,iBAAiB;AAAA,EACjB,gBAAgB,CAAA;AAClB;AAGO,MAAM,yBAAyBC,MAAAA;AAAAA,EACpC;AACF;AAEO,IAAK,8CAAAC,+BAAL;AACLA,6BAAA,QAAA,IAAS;AACTA,6BAAA,OAAA,IAAQ;AACRA,6BAAA,OAAA,IAAQ;AAHE,SAAAA;AAAA,GAAA,6BAAA,CAAA,CAAA;AAmBL,MAAM,6CAA4D,IAAI;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,0BACd,MACA,UAC4B;AAE5B,MAAI,KAAK,mBAAoB,QAAO,KAAK;AAGzC,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,MAAI,YAAY,SAA4B;AAC1C,yBAAqB;AAAA,EACvB;AAEA,MAAI;AACJ,MAAI,uBAAuB;AAC3B,MAAI,OAAO,qBAAqB,UAAU;AACxC,YAAQ,kBAAA;AAAA,MACN,KAAK;AACH,0BAAkB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AChD,MAAI,CAAC,IAAI,mBAAmB,EAAG,QAAO;AACtC,SAAO,IAAIG,KAAAA,SAAS,GAAG;AACzB,CAAC;;;;;;;;"}
1
+ {"version":3,"file":"interactions.cjs","sources":["../../src/provider/interactions.ts"],"sourcesContent":["import { RegionCardinality } from \"@blueprintjs/table\";\nimport { atom } from \"jotai\";\nimport { storeAtom } from \"./core.ts\";\n\nexport enum DataViewRendererType {\n CARDS = \"cards\",\n TABLE = \"table\",\n}\n\nexport interface InteractionOptionsResolved {\n enableEditing: boolean;\n enableSelection: boolean;\n // We have a potentially modal selection\n enableModalSelection: boolean;\n /** Options for data interaction (editing and selection) */\n enableMultipleSelection: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue: boolean;\n selectionModes: RegionCardinality[];\n}\n\nconst defaultInteractionOptions: InteractionOptionsResolved = {\n enableEditing: false,\n enableSelection: false,\n enableModalSelection: false,\n enableMultipleSelection: false,\n enableDragValue: false,\n selectionModes: [],\n};\n\n/** Atom to store interaction options state */\nexport const interactionOptionsAtom = atom<InteractionOptionsResolved>(\n defaultInteractionOptions,\n);\n\nexport enum SelectionInteractionStyle {\n ALWAYS = \"always\",\n NEVER = \"never\",\n MODAL = \"modal\",\n}\n\nexport interface InteractionOptions {\n /** Options for data interaction (editing and selection) */\n /** @deprecated: Use enableEditing instead */\n editable?: boolean;\n enableEditing?: boolean;\n enableSelection?: boolean | SelectionInteractionStyle;\n enableMultipleSelection?: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue?: boolean;\n selectionModes?: RegionCardinality[];\n interactionOptions?: InteractionOptionsResolved;\n}\n\nexport const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([\n \"editable\",\n \"enableEditing\",\n \"enableSelection\",\n \"enableMultipleSelection\",\n \"enableDragValue\",\n \"selectionModes\",\n \"interactionOptions\",\n]);\n\n/** Resolve the granular interaction options for a particular editing domain */\nexport function resolveInteractionOptions(\n opts: InteractionOptions,\n renderer: DataViewRendererType,\n): InteractionOptionsResolved {\n // If the user has provided interaction options, use them.\n if (opts.interactionOptions) return opts.interactionOptions;\n\n /** Resolve a unified set of interaction options for the table and cards */\n let {\n enableEditing,\n selectionModes,\n enableSelection: _enableSelection,\n enableDragValue,\n enableMultipleSelection,\n } = opts;\n\n if (renderer == DataViewRendererType.CARDS) {\n _enableSelection ??= true;\n }\n\n let enableSelection: boolean;\n let enableModalSelection = false;\n if (typeof _enableSelection === \"string\") {\n switch (_enableSelection) {\n case SelectionInteractionStyle.ALWAYS:\n enableSelection = true;\n break;\n case SelectionInteractionStyle.NEVER:\n enableSelection = false;\n break;\n case SelectionInteractionStyle.MODAL:\n enableSelection = false;\n enableModalSelection = true;\n break;\n }\n } else {\n enableSelection ??= _enableSelection ?? true;\n }\n\n enableEditing ??= opts.editable ?? enableSelection ?? true;\n enableMultipleSelection ??= true;\n if (renderer == DataViewRendererType.TABLE) {\n if (selectionModes != null) {\n enableSelection = new Set(selectionModes).size > 0;\n }\n enableSelection ??= true;\n if (enableSelection) {\n selectionModes ??= [\n RegionCardinality.FULL_TABLE,\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n ];\n enableEditing ??= true;\n enableDragValue ??= true;\n } else {\n selectionModes ??= [RegionCardinality.FULL_TABLE];\n }\n if (!selectionModes.includes(RegionCardinality.CELLS)) {\n enableEditing = false;\n }\n enableDragValue ??= enableEditing;\n } else if (renderer == DataViewRendererType.CARDS) {\n if (enableSelection) {\n // Only one selection mode possible\n selectionModes = [\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_TABLE,\n ];\n enableEditing ??= true;\n } else {\n selectionModes = [RegionCardinality.FULL_TABLE];\n }\n enableDragValue = false;\n }\n if (!enableEditing) {\n enableDragValue = false;\n }\n\n return {\n enableEditing,\n enableDragValue: enableDragValue ?? false,\n enableMultipleSelection,\n selectionModes: selectionModes as RegionCardinality[],\n enableModalSelection,\n enableSelection,\n };\n}\n\n/**\n * Whether **modal** selection is currently switched on.\n *\n * This is *runtime view state*, not configuration, so it lives in its own atom\n * rather than inside `interactionOptionsAtom`: the latter is re-synced from the\n * view's props (`resolveInteractionOptions` builds a fresh object on every\n * render of the provider), so a runtime override stored there is reset by any\n * provider re-render that happens to fire. Keeping the flag separate makes\n * select mode stable, and gives consumers a single, safe thing to read and set.\n */\nexport const selectionModeActiveAtom = atom(false);\n\n/**\n * The effective \"is selection live right now\" flag — the one every selection\n * path should read. For a modal view it follows {@link selectionModeActiveAtom};\n * otherwise it's the configured `enableSelection`.\n */\nexport const enableSelectionAtom = atom(\n (get) => {\n const options = get(interactionOptionsAtom);\n if (options.enableModalSelection) return get(selectionModeActiveAtom);\n return options.enableSelection;\n },\n (get, set, next: boolean) => {\n /** Turn selection on/off. Only meaningful for a modal view; a view with a\n * fixed selection style ignores it. */\n if (!get(interactionOptionsAtom).enableModalSelection) return;\n set(selectionModeActiveAtom, next);\n },\n);\n\nexport const enableDragValueAtom = atom((get) => {\n return get(interactionOptionsAtom).enableDragValue;\n});\nexport const dragValueHandlerAtom = atom((get) => {\n if (!get(enableDragValueAtom)) return undefined;\n return get(storeAtom)?.onDragValue;\n});\n"],"names":["DataViewRendererType","atom","SelectionInteractionStyle","RegionCardinality","storeAtom"],"mappings":";;;;;AAIO,IAAK,yCAAAA,0BAAL;AACLA,wBAAA,OAAA,IAAQ;AACRA,wBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,wBAAA,CAAA,CAAA;AAiBZ,MAAM,4BAAwD;AAAA,EAC5D,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,yBAAyB;AAAA,EACzB,iBAAiB;AAAA,EACjB,gBAAgB,CAAA;AAClB;AAGO,MAAM,yBAAyBC,MAAAA;AAAAA,EACpC;AACF;AAEO,IAAK,8CAAAC,+BAAL;AACLA,6BAAA,QAAA,IAAS;AACTA,6BAAA,OAAA,IAAQ;AACRA,6BAAA,OAAA,IAAQ;AAHE,SAAAA;AAAA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AA,QACfA,MAAAA,kBAAkB;AAAA,QAClBA,wBAAkB;AAAA,MAAA;AAEpB,wBAAkB;AAAA,IACpB,OAAO;AACL,uBAAiB,CAACA,MAAAA,kBAAkB,UAAU;AAAA,IAChD;AACA,sBAAkB;AAAA,EACpB;AACA,MAAI,CAAC,eAAe;AAClB,sBAAkB;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB,mBAAmB;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAYO,MAAM,0BAA0BF,MAAAA,KAAK,KAAK;AAO1C,MAAM,sBAAsBA,MAAAA;AAAAA,EACjC,CAAC,QAAQ;AACP,UAAM,UAAU,IAAI,sBAAsB;AAC1C,QAAI,QAAQ,qBAAsB,QAAO,IAAI,uBAAuB;AACpE,WAAO,QAAQ;AAAA,EACjB;AAAA,EACA,CAAC,KAAK,KAAK,SAAkB;AAG3B,QAAI,CAAC,IAAI,sBAAsB,EAAE,qBAAsB;AACvD,QAAI,yBAAyB,IAAI;AAAA,EACnC;AACF;AAEO,MAAM,sBAAsBA,MAAAA,KAAK,CAAC,QAAQ;AAC/C,SAAO,IAAI,sBAAsB,EAAE;AACrC,CAAC;AACM,MAAM,uBAAuBA,MAAAA,KAAK,CAAC,QAAQ;AAChD,MAAI,CAAC,IAAI,mBAAmB,EAAG,QAAO;AACtC,SAAO,IAAIG,KAAAA,SAAS,GAAG;AACzB,CAAC;;;;;;;;;;"}
@@ -35,5 +35,24 @@ export interface InteractionOptions {
35
35
  export declare const interactionOptionsKeys: Set<keyof InteractionOptions>;
36
36
  /** Resolve the granular interaction options for a particular editing domain */
37
37
  export declare function resolveInteractionOptions(opts: InteractionOptions, renderer: DataViewRendererType): InteractionOptionsResolved;
38
+ /**
39
+ * Whether **modal** selection is currently switched on.
40
+ *
41
+ * This is *runtime view state*, not configuration, so it lives in its own atom
42
+ * rather than inside `interactionOptionsAtom`: the latter is re-synced from the
43
+ * view's props (`resolveInteractionOptions` builds a fresh object on every
44
+ * render of the provider), so a runtime override stored there is reset by any
45
+ * provider re-render that happens to fire. Keeping the flag separate makes
46
+ * select mode stable, and gives consumers a single, safe thing to read and set.
47
+ */
48
+ export declare const selectionModeActiveAtom: import('jotai').PrimitiveAtom<boolean> & {
49
+ init: boolean;
50
+ };
51
+ /**
52
+ * The effective "is selection live right now" flag — the one every selection
53
+ * path should read. For a modal view it follows {@link selectionModeActiveAtom};
54
+ * otherwise it's the configured `enableSelection`.
55
+ */
56
+ export declare const enableSelectionAtom: import('jotai').WritableAtom<boolean, [next: boolean], void>;
38
57
  export declare const enableDragValueAtom: import('jotai').Atom<boolean>;
39
- export declare const dragValueHandlerAtom: import('jotai').Atom<((event: MouseEvent) => void) | undefined>;
58
+ export declare const dragValueHandlerAtom: import('jotai').Atom<any>;
@@ -109,6 +109,18 @@ function resolveInteractionOptions(opts, renderer) {
109
109
  enableSelection
110
110
  };
111
111
  }
112
+ const selectionModeActiveAtom = atom(false);
113
+ const enableSelectionAtom = atom(
114
+ (get) => {
115
+ const options = get(interactionOptionsAtom);
116
+ if (options.enableModalSelection) return get(selectionModeActiveAtom);
117
+ return options.enableSelection;
118
+ },
119
+ (get, set, next) => {
120
+ if (!get(interactionOptionsAtom).enableModalSelection) return;
121
+ set(selectionModeActiveAtom, next);
122
+ }
123
+ );
112
124
  const enableDragValueAtom = atom((get) => {
113
125
  return get(interactionOptionsAtom).enableDragValue;
114
126
  });
@@ -121,8 +133,10 @@ export {
121
133
  SelectionInteractionStyle,
122
134
  dragValueHandlerAtom,
123
135
  enableDragValueAtom,
136
+ enableSelectionAtom,
124
137
  interactionOptionsAtom,
125
138
  interactionOptionsKeys,
126
- resolveInteractionOptions
139
+ resolveInteractionOptions,
140
+ selectionModeActiveAtom
127
141
  };
128
142
  //# sourceMappingURL=interactions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interactions.js","sources":["../../src/provider/interactions.ts"],"sourcesContent":["import { RegionCardinality } from \"@blueprintjs/table\";\nimport { atom } from \"jotai\";\nimport { storeAtom } from \"./core.ts\";\n\nexport enum DataViewRendererType {\n CARDS = \"cards\",\n TABLE = \"table\",\n}\n\nexport interface InteractionOptionsResolved {\n enableEditing: boolean;\n enableSelection: boolean;\n // We have a potentially modal selection\n enableModalSelection: boolean;\n /** Options for data interaction (editing and selection) */\n enableMultipleSelection: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue: boolean;\n selectionModes: RegionCardinality[];\n}\n\nconst defaultInteractionOptions: InteractionOptionsResolved = {\n enableEditing: false,\n enableSelection: false,\n enableModalSelection: false,\n enableMultipleSelection: false,\n enableDragValue: false,\n selectionModes: [],\n};\n\n/** Atom to store interaction options state */\nexport const interactionOptionsAtom = atom<InteractionOptionsResolved>(\n defaultInteractionOptions,\n);\n\nexport enum SelectionInteractionStyle {\n ALWAYS = \"always\",\n NEVER = \"never\",\n MODAL = \"modal\",\n}\n\nexport interface InteractionOptions {\n /** Options for data interaction (editing and selection) */\n /** @deprecated: Use enableEditing instead */\n editable?: boolean;\n enableEditing?: boolean;\n enableSelection?: boolean | SelectionInteractionStyle;\n enableMultipleSelection?: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue?: boolean;\n selectionModes?: RegionCardinality[];\n interactionOptions?: InteractionOptionsResolved;\n}\n\nexport const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([\n \"editable\",\n \"enableEditing\",\n \"enableSelection\",\n \"enableMultipleSelection\",\n \"enableDragValue\",\n \"selectionModes\",\n \"interactionOptions\",\n]);\n\n/** Resolve the granular interaction options for a particular editing domain */\nexport function resolveInteractionOptions(\n opts: InteractionOptions,\n renderer: DataViewRendererType,\n): InteractionOptionsResolved {\n // If the user has provided interaction options, use them.\n if (opts.interactionOptions) return opts.interactionOptions;\n\n /** Resolve a unified set of interaction options for the table and cards */\n let {\n enableEditing,\n selectionModes,\n enableSelection: _enableSelection,\n enableDragValue,\n enableMultipleSelection,\n } = opts;\n\n if (renderer == DataViewRendererType.CARDS) {\n _enableSelection ??= true;\n }\n\n let enableSelection: boolean;\n let enableModalSelection = false;\n if (typeof _enableSelection === \"string\") {\n switch (_enableSelection) {\n case SelectionInteractionStyle.ALWAYS:\n enableSelection = true;\n break;\n case SelectionInteractionStyle.NEVER:\n enableSelection = false;\n break;\n case SelectionInteractionStyle.MODAL:\n enableSelection = false;\n enableModalSelection = true;\n break;\n }\n } else {\n enableSelection ??= _enableSelection ?? true;\n }\n\n enableEditing ??= opts.editable ?? enableSelection ?? true;\n enableMultipleSelection ??= true;\n if (renderer == DataViewRendererType.TABLE) {\n if (selectionModes != null) {\n enableSelection = new Set(selectionModes).size > 0;\n }\n enableSelection ??= true;\n if (enableSelection) {\n selectionModes ??= [\n RegionCardinality.FULL_TABLE,\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n ];\n enableEditing ??= true;\n enableDragValue ??= true;\n } else {\n selectionModes ??= [RegionCardinality.FULL_TABLE];\n }\n if (!selectionModes.includes(RegionCardinality.CELLS)) {\n enableEditing = false;\n }\n enableDragValue ??= enableEditing;\n } else if (renderer == DataViewRendererType.CARDS) {\n if (enableSelection) {\n // Only one selection mode possible\n selectionModes = [\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_TABLE,\n ];\n enableEditing ??= true;\n } else {\n selectionModes = [RegionCardinality.FULL_TABLE];\n }\n enableDragValue = false;\n }\n if (!enableEditing) {\n enableDragValue = false;\n }\n\n return {\n enableEditing,\n enableDragValue: enableDragValue ?? false,\n enableMultipleSelection,\n selectionModes: selectionModes as RegionCardinality[],\n enableModalSelection,\n enableSelection,\n };\n}\n\nexport const enableDragValueAtom = atom((get) => {\n return get(interactionOptionsAtom).enableDragValue;\n});\nexport const dragValueHandlerAtom = atom((get) => {\n if (!get(enableDragValueAtom)) return undefined;\n return get(storeAtom)?.onDragValue;\n});\n"],"names":["DataViewRendererType","SelectionInteractionStyle"],"mappings":";;;AAIO,IAAK,yCAAAA,0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pB,QAAI,iBAAiB;AACnB,yBAAmB;AAAA,QACjB,kBAAkB;AAAA,QAClB,kBAAkB;AAAA,QAClB,kBAAkB;AAAA,QAClB,kBAAkB;AAAA,MAAA;AAEpB,wBAAkB;AAClB,0BAAoB;AAAA,IACtB,OAAO;AACL,yBAAmB,CAAC,kBAAkB,UAAU;AAAA,IAClD;AACA,QAAI,CAAC,eAAe,SAAS,kBAAkB,KAAK,GAAG;AACrD,sBAAgB;AAAA,IAClB;AACA,wBAAoB;AAAA,EACtB,WAAW,YAAY,SAA4B;AACjD,QAAI,iBAAiB;AAEnB,uBAAiB;AAAA,QACf,kBAAkB;AAAA,QAClB,kBAAkB;AAAA,MAAA;AAEpB,wBAAkB;AAAA,IACpB,OAAO;AACL,uBAAiB,CAAC,kBAAkB,UAAU;AAAA,IAChD;AACA,sBAAkB;AAAA,EACpB;AACA,MAAI,CAAC,eAAe;AAClB,sBAAkB;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB,mBAAmB;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEO,MAAM,sBAAsB,KAAK,CAAC,QAAQ;AAC/C,SAAO,IAAI,sBAAsB,EAAE;AACrC,CAAC;AACM,MAAM,uBAAuB,KAAK,CAAC,QAAQ;AAChD,MAAI,CAAC,IAAI,mBAAmB,EAAG,QAAO;AACtC,SAAO,IAAI,SAAS,GAAG;AACzB,CAAC;"}
1
+ {"version":3,"file":"interactions.js","sources":["../../src/provider/interactions.ts"],"sourcesContent":["import { RegionCardinality } from \"@blueprintjs/table\";\nimport { atom } from \"jotai\";\nimport { storeAtom } from \"./core.ts\";\n\nexport enum DataViewRendererType {\n CARDS = \"cards\",\n TABLE = \"table\",\n}\n\nexport interface InteractionOptionsResolved {\n enableEditing: boolean;\n enableSelection: boolean;\n // We have a potentially modal selection\n enableModalSelection: boolean;\n /** Options for data interaction (editing and selection) */\n enableMultipleSelection: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue: boolean;\n selectionModes: RegionCardinality[];\n}\n\nconst defaultInteractionOptions: InteractionOptionsResolved = {\n enableEditing: false,\n enableSelection: false,\n enableModalSelection: false,\n enableMultipleSelection: false,\n enableDragValue: false,\n selectionModes: [],\n};\n\n/** Atom to store interaction options state */\nexport const interactionOptionsAtom = atom<InteractionOptionsResolved>(\n defaultInteractionOptions,\n);\n\nexport enum SelectionInteractionStyle {\n ALWAYS = \"always\",\n NEVER = \"never\",\n MODAL = \"modal\",\n}\n\nexport interface InteractionOptions {\n /** Options for data interaction (editing and selection) */\n /** @deprecated: Use enableEditing instead */\n editable?: boolean;\n enableEditing?: boolean;\n enableSelection?: boolean | SelectionInteractionStyle;\n enableMultipleSelection?: boolean;\n // Enable drag-to-select (data table only)\n enableDragValue?: boolean;\n selectionModes?: RegionCardinality[];\n interactionOptions?: InteractionOptionsResolved;\n}\n\nexport const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([\n \"editable\",\n \"enableEditing\",\n \"enableSelection\",\n \"enableMultipleSelection\",\n \"enableDragValue\",\n \"selectionModes\",\n \"interactionOptions\",\n]);\n\n/** Resolve the granular interaction options for a particular editing domain */\nexport function resolveInteractionOptions(\n opts: InteractionOptions,\n renderer: DataViewRendererType,\n): InteractionOptionsResolved {\n // If the user has provided interaction options, use them.\n if (opts.interactionOptions) return opts.interactionOptions;\n\n /** Resolve a unified set of interaction options for the table and cards */\n let {\n enableEditing,\n selectionModes,\n enableSelection: _enableSelection,\n enableDragValue,\n enableMultipleSelection,\n } = opts;\n\n if (renderer == DataViewRendererType.CARDS) {\n _enableSelection ??= true;\n }\n\n let enableSelection: boolean;\n let enableModalSelection = false;\n if (typeof _enableSelection === \"string\") {\n switch (_enableSelection) {\n case SelectionInteractionStyle.ALWAYS:\n enableSelection = true;\n break;\n case SelectionInteractionStyle.NEVER:\n enableSelection = false;\n break;\n case SelectionInteractionStyle.MODAL:\n enableSelection = false;\n enableModalSelection = true;\n break;\n }\n } else {\n enableSelection ??= _enableSelection ?? true;\n }\n\n enableEditing ??= opts.editable ?? enableSelection ?? true;\n enableMultipleSelection ??= true;\n if (renderer == DataViewRendererType.TABLE) {\n if (selectionModes != null) {\n enableSelection = new Set(selectionModes).size > 0;\n }\n enableSelection ??= true;\n if (enableSelection) {\n selectionModes ??= [\n RegionCardinality.FULL_TABLE,\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n ];\n enableEditing ??= true;\n enableDragValue ??= true;\n } else {\n selectionModes ??= [RegionCardinality.FULL_TABLE];\n }\n if (!selectionModes.includes(RegionCardinality.CELLS)) {\n enableEditing = false;\n }\n enableDragValue ??= enableEditing;\n } else if (renderer == DataViewRendererType.CARDS) {\n if (enableSelection) {\n // Only one selection mode possible\n selectionModes = [\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_TABLE,\n ];\n enableEditing ??= true;\n } else {\n selectionModes = [RegionCardinality.FULL_TABLE];\n }\n enableDragValue = false;\n }\n if (!enableEditing) {\n enableDragValue = false;\n }\n\n return {\n enableEditing,\n enableDragValue: enableDragValue ?? false,\n enableMultipleSelection,\n selectionModes: selectionModes as RegionCardinality[],\n enableModalSelection,\n enableSelection,\n };\n}\n\n/**\n * Whether **modal** selection is currently switched on.\n *\n * This is *runtime view state*, not configuration, so it lives in its own atom\n * rather than inside `interactionOptionsAtom`: the latter is re-synced from the\n * view's props (`resolveInteractionOptions` builds a fresh object on every\n * render of the provider), so a runtime override stored there is reset by any\n * provider re-render that happens to fire. Keeping the flag separate makes\n * select mode stable, and gives consumers a single, safe thing to read and set.\n */\nexport const selectionModeActiveAtom = atom(false);\n\n/**\n * The effective \"is selection live right now\" flag — the one every selection\n * path should read. For a modal view it follows {@link selectionModeActiveAtom};\n * otherwise it's the configured `enableSelection`.\n */\nexport const enableSelectionAtom = atom(\n (get) => {\n const options = get(interactionOptionsAtom);\n if (options.enableModalSelection) return get(selectionModeActiveAtom);\n return options.enableSelection;\n },\n (get, set, next: boolean) => {\n /** Turn selection on/off. Only meaningful for a modal view; a view with a\n * fixed selection style ignores it. */\n if (!get(interactionOptionsAtom).enableModalSelection) return;\n set(selectionModeActiveAtom, next);\n },\n);\n\nexport const enableDragValueAtom = atom((get) => {\n return get(interactionOptionsAtom).enableDragValue;\n});\nexport const dragValueHandlerAtom = atom((get) => {\n if (!get(enableDragValueAtom)) return undefined;\n return get(storeAtom)?.onDragValue;\n});\n"],"names":["DataViewRendererType","SelectionInteractionStyle"],"mappings":";;;AAIO,IAAK,yCAAAA,0BAAL;AACLA,wBAAA,OAAA,IAAQ;AACRA,wBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,wBAAA,CAAA,CAAA;AAiBZ,MAAM,4BAAwD;AAAA,EAC5D,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,yBAAyB;AAAA,EACzB,iBAAiB;AAAA,EACjB,gBAAgB,CAAA;AAClB;AAGO,MAAM,yBAAyB;AAAA,EACpC;AACF;AAEO,IAAK,8CAAAC,+BAAL;AACLA,6BAAA,QAAA,IAAS;AACTA,6BAAA,OAAA,IAAQ;AACRA,6BAAA,OAAA,IAAQ;AAHE,SAAAA;AAAA,GAAA,6BAAA,CAAA,CAAA;AAmBL,MAAM,6CAA4D,IAAI;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,0BACd,MACA,UAC4B;AAE5B,MAAI,KAAK,mBAAoB,QAAO,KAAK;AAGzC,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,MAAI,YAAY,SAA4B;AAC1C,yBAAqB;AAAA,EACvB;AAEA,MAAI;AACJ,MAAI,uBAAuB;AAC3B,MAAI,OAAO,qBAAqB,UAAU;AACxC,YAAQ,kBAAA;AAAA,MACN,KAA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EACjB;AAAA,EACA,CAAC,KAAK,KAAK,SAAkB;AAG3B,QAAI,CAAC,IAAI,sBAAsB,EAAE,qBAAsB;AACvD,QAAI,yBAAyB,IAAI;AAAA,EACnC;AACF;AAEO,MAAM,sBAAsB,KAAK,CAAC,QAAQ;AAC/C,SAAO,IAAI,sBAAsB,EAAE;AACrC,CAAC;AACM,MAAM,uBAAuB,KAAK,CAAC,QAAQ;AAChD,MAAI,CAAC,IAAI,mBAAmB,EAAG,QAAO;AACtC,SAAO,IAAI,SAAS,GAAG;AACzB,CAAC;"}
@@ -8,11 +8,11 @@ const anchorRefAtom = jotai.atom({
8
8
  });
9
9
  const selectionAtom = jotai.atom(
10
10
  (get) => {
11
- if (!get(interactions.interactionOptionsAtom).enableSelection) return [];
11
+ if (!get(interactions.enableSelectionAtom)) return [];
12
12
  return get(core.storeAtom)?.selection ?? [];
13
13
  },
14
14
  (get, set, regions = []) => {
15
- if (!get(interactions.interactionOptionsAtom).enableSelection) return;
15
+ if (!get(interactions.enableSelectionAtom)) return;
16
16
  if (regions.length === 0) {
17
17
  get(anchorRefAtom).current = null;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"selection.cjs","sources":["../../src/provider/selection.ts"],"sourcesContent":["import { atom } from \"jotai\";\nimport { interactionOptionsAtom } from \"./interactions.ts\";\nimport { storeAtom } from \"./core.ts\";\nimport type { Region } from \"@blueprintjs/table\";\n\n// The anchor for shift-range selection: the last row clicked without shift.\n// Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).\nexport const anchorRefAtom = atom<{ current: number | null }>({\n current: null,\n});\n\nexport const selectionAtom = atom(\n (get) => {\n if (!get(interactionOptionsAtom).enableSelection) return [];\n return get(storeAtom)?.selection ?? [];\n },\n (get, set, regions: Region[] = []) => {\n /** Don't do anything if selection isn't enabled */\n if (!get(interactionOptionsAtom).enableSelection) return;\n /** Reset the selection anchor ref */\n if (regions.length === 0) {\n get(anchorRefAtom).current = null;\n }\n set(storeAtom, (s) => ({\n ...s,\n selection: regions,\n focusedCell: null,\n topLeftCell: null,\n }));\n },\n);\n"],"names":["atom","interactionOptionsAtom","storeAtom"],"mappings":";;;;;AAOO,MAAM,gBAAgBA,MAAAA,KAAiC;AAAA,EAC5D,SAAS;AACX,CAAC;AAEM,MAAM,gBAAgBA,MAAAA;AAAAA,EAC3B,CAAC,QAAQ;AACP,QAAI,CAAC,IAAIC,aAAAA,sBAAsB,EAAE,wBAAwB,CAAA;AACzD,WAAO,IAAIC,KAAAA,SAAS,GAAG,aAAa,CAAA;AAAA,EACtC;AAAA,EACA,CAAC,KAAK,KAAK,UAAoB,OAAO;AAEpC,QAAI,CAAC,IAAID,mCAAsB,EAAE,gBAAiB;AAElD,QAAI,QAAQ,WAAW,GAAG;AACxB,UAAI,aAAa,EAAE,UAAU;AAAA,IAC/B;AACA,QAAIC,KAAAA,WAAW,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,aAAa;AAAA,MACb,aAAa;AAAA,IAAA,EACb;AAAA,EACJ;AACF;;;"}
1
+ {"version":3,"file":"selection.cjs","sources":["../../src/provider/selection.ts"],"sourcesContent":["import { atom } from \"jotai\";\nimport { enableSelectionAtom } from \"./interactions.ts\";\nimport { storeAtom } from \"./core.ts\";\nimport type { Region } from \"@blueprintjs/table\";\n\n// The anchor for shift-range selection: the last row clicked without shift.\n// Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).\nexport const anchorRefAtom = atom<{ current: number | null }>({\n current: null,\n});\n\nexport const selectionAtom = atom(\n (get) => {\n if (!get(enableSelectionAtom)) return [];\n return get(storeAtom)?.selection ?? [];\n },\n (get, set, regions: Region[] = []) => {\n /** Don't do anything if selection isn't enabled */\n if (!get(enableSelectionAtom)) return;\n /** Reset the selection anchor ref */\n if (regions.length === 0) {\n get(anchorRefAtom).current = null;\n }\n set(storeAtom, (s) => ({\n ...s,\n selection: regions,\n focusedCell: null,\n topLeftCell: null,\n }));\n },\n);\n"],"names":["atom","enableSelectionAtom","storeAtom"],"mappings":";;;;;AAOO,MAAM,gBAAgBA,MAAAA,KAAiC;AAAA,EAC5D,SAAS;AACX,CAAC;AAEM,MAAM,gBAAgBA,MAAAA;AAAAA,EAC3B,CAAC,QAAQ;AACP,QAAI,CAAC,IAAIC,gCAAmB,UAAU,CAAA;AACtC,WAAO,IAAIC,KAAAA,SAAS,GAAG,aAAa,CAAA;AAAA,EACtC;AAAA,EACA,CAAC,KAAK,KAAK,UAAoB,OAAO;AAEpC,QAAI,CAAC,IAAID,aAAAA,mBAAmB,EAAG;AAE/B,QAAI,QAAQ,WAAW,GAAG;AACxB,UAAI,aAAa,EAAE,UAAU;AAAA,IAC/B;AACA,QAAIC,KAAAA,WAAW,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,aAAa;AAAA,MACb,aAAa;AAAA,IAAA,EACb;AAAA,EACJ;AACF;;;"}
@@ -6,4 +6,4 @@ export declare const anchorRefAtom: import('jotai').PrimitiveAtom<{
6
6
  current: number | null;
7
7
  };
8
8
  };
9
- export declare const selectionAtom: import('jotai').WritableAtom<Region[], [regions?: Region[] | undefined], void>;
9
+ export declare const selectionAtom: import('jotai').WritableAtom<any, [regions?: Region[] | undefined], void>;
@@ -1,16 +1,16 @@
1
1
  import { atom } from "jotai";
2
- import { interactionOptionsAtom } from "./interactions.js";
2
+ import { enableSelectionAtom } from "./interactions.js";
3
3
  import { storeAtom } from "./core.js";
4
4
  const anchorRefAtom = atom({
5
5
  current: null
6
6
  });
7
7
  const selectionAtom = atom(
8
8
  (get) => {
9
- if (!get(interactionOptionsAtom).enableSelection) return [];
9
+ if (!get(enableSelectionAtom)) return [];
10
10
  return get(storeAtom)?.selection ?? [];
11
11
  },
12
12
  (get, set, regions = []) => {
13
- if (!get(interactionOptionsAtom).enableSelection) return;
13
+ if (!get(enableSelectionAtom)) return;
14
14
  if (regions.length === 0) {
15
15
  get(anchorRefAtom).current = null;
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"selection.js","sources":["../../src/provider/selection.ts"],"sourcesContent":["import { atom } from \"jotai\";\nimport { interactionOptionsAtom } from \"./interactions.ts\";\nimport { storeAtom } from \"./core.ts\";\nimport type { Region } from \"@blueprintjs/table\";\n\n// The anchor for shift-range selection: the last row clicked without shift.\n// Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).\nexport const anchorRefAtom = atom<{ current: number | null }>({\n current: null,\n});\n\nexport const selectionAtom = atom(\n (get) => {\n if (!get(interactionOptionsAtom).enableSelection) return [];\n return get(storeAtom)?.selection ?? [];\n },\n (get, set, regions: Region[] = []) => {\n /** Don't do anything if selection isn't enabled */\n if (!get(interactionOptionsAtom).enableSelection) return;\n /** Reset the selection anchor ref */\n if (regions.length === 0) {\n get(anchorRefAtom).current = null;\n }\n set(storeAtom, (s) => ({\n ...s,\n selection: regions,\n focusedCell: null,\n topLeftCell: null,\n }));\n },\n);\n"],"names":[],"mappings":";;;AAOO,MAAM,gBAAgB,KAAiC;AAAA,EAC5D,SAAS;AACX,CAAC;AAEM,MAAM,gBAAgB;AAAA,EAC3B,CAAC,QAAQ;AACP,QAAI,CAAC,IAAI,sBAAsB,EAAE,wBAAwB,CAAA;AACzD,WAAO,IAAI,SAAS,GAAG,aAAa,CAAA;AAAA,EACtC;AAAA,EACA,CAAC,KAAK,KAAK,UAAoB,OAAO;AAEpC,QAAI,CAAC,IAAI,sBAAsB,EAAE,gBAAiB;AAElD,QAAI,QAAQ,WAAW,GAAG;AACxB,UAAI,aAAa,EAAE,UAAU;AAAA,IAC/B;AACA,QAAI,WAAW,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,aAAa;AAAA,MACb,aAAa;AAAA,IAAA,EACb;AAAA,EACJ;AACF;"}
1
+ {"version":3,"file":"selection.js","sources":["../../src/provider/selection.ts"],"sourcesContent":["import { atom } from \"jotai\";\nimport { enableSelectionAtom } from \"./interactions.ts\";\nimport { storeAtom } from \"./core.ts\";\nimport type { Region } from \"@blueprintjs/table\";\n\n// The anchor for shift-range selection: the last row clicked without shift.\n// Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).\nexport const anchorRefAtom = atom<{ current: number | null }>({\n current: null,\n});\n\nexport const selectionAtom = atom(\n (get) => {\n if (!get(enableSelectionAtom)) return [];\n return get(storeAtom)?.selection ?? [];\n },\n (get, set, regions: Region[] = []) => {\n /** Don't do anything if selection isn't enabled */\n if (!get(enableSelectionAtom)) return;\n /** Reset the selection anchor ref */\n if (regions.length === 0) {\n get(anchorRefAtom).current = null;\n }\n set(storeAtom, (s) => ({\n ...s,\n selection: regions,\n focusedCell: null,\n topLeftCell: null,\n }));\n },\n);\n"],"names":[],"mappings":";;;AAOO,MAAM,gBAAgB,KAAiC;AAAA,EAC5D,SAAS;AACX,CAAC;AAEM,MAAM,gBAAgB;AAAA,EAC3B,CAAC,QAAQ;AACP,QAAI,CAAC,IAAI,mBAAmB,UAAU,CAAA;AACtC,WAAO,IAAI,SAAS,GAAG,aAAa,CAAA;AAAA,EACtC;AAAA,EACA,CAAC,KAAK,KAAK,UAAoB,OAAO;AAEpC,QAAI,CAAC,IAAI,mBAAmB,EAAG;AAE/B,QAAI,QAAQ,WAAW,GAAG;AACxB,UAAI,aAAa,EAAE,UAAU;AAAA,IAC/B;AACA,QAAI,WAAW,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,aAAa;AAAA,MACb,aAAa;AAAA,IAAA,EACb;AAAA,EACJ;AACF;"}
@@ -344,7 +344,7 @@ function createZustandStore(set, get) {
344
344
  state.activeFilters
345
345
  );
346
346
  newFilters.set(filterId, { filter, state: filterState });
347
- return { activeFilters: newFilters };
347
+ return { activeFilters: newFilters, ...dropRowSelection(state) };
348
348
  });
349
349
  },
350
350
  removeFilter(filterId) {
@@ -353,12 +353,13 @@ function createZustandStore(set, get) {
353
353
  state.activeFilters
354
354
  );
355
355
  newFilters.delete(filterId);
356
- return { activeFilters: newFilters };
356
+ return { activeFilters: newFilters, ...dropRowSelection(state) };
357
357
  });
358
358
  },
359
359
  clearFilters() {
360
- set(() => ({
361
- activeFilters: /* @__PURE__ */ new Map()
360
+ set((state) => ({
361
+ activeFilters: /* @__PURE__ */ new Map(),
362
+ ...dropRowSelection(state)
362
363
  }));
363
364
  },
364
365
  setColumnSort(key, ascending) {
@@ -370,17 +371,23 @@ function createZustandStore(set, get) {
370
371
  const without = state.columnSorts.filter((s) => s.key !== key);
371
372
  newSorts = [...without, { key, ascending }];
372
373
  }
373
- return { columnSorts: newSorts };
374
+ return { columnSorts: newSorts, ...dropRowSelection(state) };
374
375
  });
375
376
  },
376
377
  clearColumnSorts() {
377
- set(() => ({ columnSorts: [] }));
378
+ set((state) => ({ columnSorts: [], ...dropRowSelection(state) }));
378
379
  },
379
380
  setClipboardProxy(proxy) {
380
381
  set({ clipboardProxy: proxy });
381
382
  }
382
383
  };
383
384
  }
385
+ function dropRowSelection(state) {
386
+ const selection2 = state.selection ?? [];
387
+ const kept = selection2.filter((region) => region.rows == null);
388
+ if (kept.length === selection2.length) return {};
389
+ return { selection: kept, focusedCell: null, topLeftCell: null };
390
+ }
384
391
  function updateSelection(selection2) {
385
392
  const focusedCell = singleFocusedCell(selection2);
386
393
  let spec = {