@macrostrat/data-sheet 4.4.0 → 4.5.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 (57) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/components/indicators/unified-filters.cjs +30 -10
  3. package/dist/components/indicators/unified-filters.cjs.map +1 -1
  4. package/dist/components/indicators/unified-filters.js +30 -10
  5. package/dist/components/indicators/unified-filters.js.map +1 -1
  6. package/dist/data-panel.cjs +3 -1
  7. package/dist/data-panel.cjs.map +1 -1
  8. package/dist/data-panel.d.ts +1 -1
  9. package/dist/data-panel.js +3 -1
  10. package/dist/data-panel.js.map +1 -1
  11. package/dist/data-panel.module.sass.cjs +25 -25
  12. package/dist/data-panel.module.sass.js +25 -25
  13. package/dist/data-sheet.cjs +3 -1
  14. package/dist/data-sheet.cjs.map +1 -1
  15. package/dist/data-sheet.css +37 -38
  16. package/dist/data-sheet.d.ts +1 -1
  17. package/dist/data-sheet.js +3 -1
  18. package/dist/data-sheet.js.map +1 -1
  19. package/dist/index.cjs +4 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +5 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/postgrest-table/data-loaders.cjs +67 -2
  24. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  25. package/dist/postgrest-table/data-loaders.d.ts +8 -1
  26. package/dist/postgrest-table/data-loaders.js +67 -2
  27. package/dist/postgrest-table/data-loaders.js.map +1 -1
  28. package/dist/provider/core.cjs +23 -2
  29. package/dist/provider/core.cjs.map +1 -1
  30. package/dist/provider/core.d.ts +2 -2
  31. package/dist/provider/core.js +23 -2
  32. package/dist/provider/core.js.map +1 -1
  33. package/dist/provider/distinct-values.cjs +65 -0
  34. package/dist/provider/distinct-values.cjs.map +1 -0
  35. package/dist/provider/distinct-values.d.ts +21 -0
  36. package/dist/provider/distinct-values.js +65 -0
  37. package/dist/provider/distinct-values.js.map +1 -0
  38. package/dist/provider/index.d.ts +1 -0
  39. package/dist/provider/table-data.cjs +21 -0
  40. package/dist/provider/table-data.cjs.map +1 -1
  41. package/dist/provider/table-data.d.ts +22 -0
  42. package/dist/provider/table-data.js +21 -0
  43. package/dist/provider/table-data.js.map +1 -1
  44. package/dist/types.cjs.map +1 -1
  45. package/dist/types.d.ts +27 -4
  46. package/dist/types.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/components/indicators/unified-filters.ts +40 -10
  49. package/src/data-panel.module.sass +2 -3
  50. package/src/data-panel.ts +3 -1
  51. package/src/data-sheet.ts +3 -1
  52. package/src/postgrest-table/data-loaders.ts +106 -3
  53. package/src/provider/core.ts +36 -3
  54. package/src/provider/distinct-values.ts +127 -0
  55. package/src/provider/index.ts +1 -0
  56. package/src/provider/table-data.ts +51 -0
  57. package/src/types.ts +33 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,78 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.5.0] - 2026-08-26 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.4.1...@macrostrat/data-sheet-v4.5.0)
4
+
5
+ ### Minor Changes
6
+
7
+ - Starting a view somewhere other than the beginning — three additions that each
8
+ [051e06fb](https://github.com/UW-Macrostrat/web-components/commit/051e06fb5b29bdeb2a2239829f5429b272ff5ab1)
9
+ remove a wasted request:
10
+
11
+ - **`TableDataProvider.distinctValues(columnKey, options?)`** — the values a
12
+ column actually holds, with frequencies where the source reports them. A
13
+ value picker can then offer only choices that match something, instead of a
14
+ free-text box (or a hand-rolled scan of the table). Implemented for both
15
+ built-in providers: `createLocalProvider` counts in memory, and
16
+ `createPostgRESTProvider` uses a grouped aggregate query
17
+ (`select=col,count()`), so one small request returns the whole vocabulary.
18
+ `baseFilter` applies to it; the _active_ filters deliberately don't — a
19
+ picker whose options vanish as you narrow the view can't be used to widen it
20
+ again. New `useDistinctValues(columnKey)` /
21
+ `useDistinctValueList(columnKey)` hooks read it, cached per (provider,
22
+ column, refresh token) so controls that mount and unmount with a menu don't
23
+ each pay for a request, and a provider mutation refreshes the vocabulary.
24
+ Also exported: `distinctValuesOf(rows, columnKey)` for in-memory sources.
25
+ - **`initialFilters` / `initialSorts`** on any data view — view state applied
26
+ when the store is _created_, so a restored view (a link, a saved query, a
27
+ server render) issues one correct fetch. Applying the same state from an
28
+ effect, which was the only option before, always let the unfiltered first
29
+ page go out and immediately superseded it: a wasted round-trip and a flash
30
+ of the wrong rows on every linked view. Uncontrolled — later user changes
31
+ win.
32
+ - **`initialData`** — rows already in hand for the first window, so a
33
+ server-rendered page doesn't re-request what it just shipped. Accepts bare
34
+ rows or `{ rows, totalCount }`; with a total, the sparse array is pre-sized,
35
+ so the scrollbar and the counter are right from the first paint. The loader
36
+ starts `initialized` (no empty-state flash, no mount fetch); scrolling past
37
+ the seed loads normally, and any view change discards it — the seed only
38
+ describes the view it was fetched for, so pair it with matching
39
+ `initialFilters` / `initialSorts`.
40
+
41
+ Also: **`useLoadControls()` now exposes `page`, `pageSize`, and `totalPages`**
42
+ (the loader already computed them; the footer contract dropped them). A footer
43
+ can now render a real _link_ to the next page rather than only a button that
44
+ calls `loadMore` — which is what a crawler, or a client with no JavaScript,
45
+ can actually follow.
46
+
47
+ New story `Data sheet/Data panel/Initial state` demonstrates all three against
48
+ a provider that logs every request, so the saving is visible rather than
49
+ asserted — including the realistic combination (server resolves the view from
50
+ the URL, fetches that page, ships both) where the client mounts with no
51
+ request at all.
52
+
53
+ ## [4.4.1] - 2026-08-26 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.4.0...@macrostrat/data-sheet-v4.4.1)
54
+
55
+ ### Patch Changes
56
+
57
+ - Fix the Filter tag's scope, and make the clear buttons drop stale row
58
+ selections:
59
+
60
+ - **The "Filter" tag no longer speaks for `"inline"` filters.** Its active
61
+ state and its clear button covered _every_ active filter, including ones
62
+ with `presentation: "inline"` — which have their own always-visible toolbar
63
+ control. So an open search box lit up the Filter tag it isn't in, and the
64
+ tag's ✕ (which reads as "clear the filters in here") silently emptied the
65
+ search box too. Both are now scoped to the filters the menu actually holds.
66
+ - **The Filter and Sort clear buttons go through the store's actions**
67
+ (`clearFilters` / `clearColumnSorts`) instead of writing state directly, so
68
+ they also drop a row selection the cleared view made meaningless — the same
69
+ guarantee `setFilter` and `setColumnSort` got in 4.4.0. Reachable on a view
70
+ with non-modal selection, where selecting and filtering coexist.
71
+ - Tidied a `??`/`>` precedence accident in the two indicator atoms
72
+ (`x?.size ?? 0 > 0` parses as `x?.size ?? (0 > 0)`; it happened to behave).
73
+
74
+ - Improve styles for the inline filter menu.
75
+
3
76
  ## [4.4.0] - 2026-08-26 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.3.0...@macrostrat/data-sheet-v4.4.0)
4
77
 
5
78
  ### Minor Changes
@@ -139,8 +139,28 @@ function useExitSelectionAction() {
139
139
  function presentationOf(filter) {
140
140
  return filter.presentation ?? "menu";
141
141
  }
142
- function useDisplayIntent(atom2) {
143
- const [hasActive, clearActive] = core.ctx.use(atom2);
142
+ function useFilterSubsetState(entries) {
143
+ const ids = entries.map((e) => e.filter.id);
144
+ const key = ids.join("\0");
145
+ const subsetAtom = react.useMemo(
146
+ () => jotai.atom(
147
+ (get) => {
148
+ const active = get(core.storeAtom)?.activeFilters;
149
+ if (active == null) return false;
150
+ return ids.some((id) => active.has(id));
151
+ },
152
+ (get) => {
153
+ const store = get(core.storeAtom);
154
+ if (store == null) return;
155
+ for (const id of ids) store.removeFilter(id);
156
+ }
157
+ ),
158
+ [key]
159
+ );
160
+ const [hasActive, clear] = core.ctx.use(subsetAtom);
161
+ return [hasActive, clear];
162
+ }
163
+ function useDisplayIntent([hasActive, clearActive]) {
144
164
  const intent = hasActive ? "primary" : "none";
145
165
  let rightIcon = "caret-down";
146
166
  let onRemove = void 0;
@@ -154,7 +174,7 @@ function useDisplayIntent(atom2) {
154
174
  return { intent, rightIcon, onRemove, hasActive };
155
175
  }
156
176
  function useFilterMenuAction(entries) {
157
- const rest = useDisplayIntent(hasActiveFiltersAtom);
177
+ const rest = useDisplayIntent(useFilterSubsetState(entries));
158
178
  if (entries.length === 0) return null;
159
179
  const filterMenu = dataPanel_module.default(
160
180
  core$1.Menu,
@@ -193,7 +213,7 @@ function useFilterMenuAction(entries) {
193
213
  }
194
214
  function useSortAction() {
195
215
  const columnSpec = core.useSelector((s) => s.columnSpec);
196
- const rest = useDisplayIntent(hasActiveSortsAtom);
216
+ const rest = useDisplayIntent(core.ctx.use(hasActiveSortsAtom));
197
217
  const sortableCols = react.useMemo(
198
218
  () => columnSpec.filter((c) => c.sortable),
199
219
  [columnSpec]
@@ -228,15 +248,15 @@ function useSortAction() {
228
248
  };
229
249
  }
230
250
  const hasActiveFiltersAtom = jotai.atom(
231
- (get) => get(core.storeAtom)?.activeFilters.size ?? 0 > 0,
232
- (get, set) => {
233
- set(core.storeAtom, (s) => ({ ...s, activeFilters: /* @__PURE__ */ new Map([]) }));
251
+ (get) => (get(core.storeAtom)?.activeFilters?.size ?? 0) > 0,
252
+ (get) => {
253
+ get(core.storeAtom)?.clearFilters?.();
234
254
  }
235
255
  );
236
256
  const hasActiveSortsAtom = jotai.atom(
237
- (get) => get(core.storeAtom)?.columnSorts.length ?? 0 > 0,
238
- (get, set) => {
239
- set(core.storeAtom, (s) => ({ ...s, columnSorts: [] }));
257
+ (get) => (get(core.storeAtom)?.columnSorts?.length ?? 0) > 0,
258
+ (get) => {
259
+ get(core.storeAtom)?.clearColumnSorts?.();
240
260
  }
241
261
  );
242
262
  exports.useDataPanelControls = useDataPanelControls;
@@ -1 +1 @@
1
- {"version":3,"file":"unified-filters.cjs","sources":["../../../src/components/indicators/unified-filters.ts"],"sourcesContent":["import {\n ALL_CARDINALITIES,\n isColumnFilterable,\n TableAction,\n TableFilter,\n} from \"../../actions\";\nimport {\n ctx,\n enableSelectionAtom,\n interactionOptionsAtom,\n storeAtom,\n useSelector,\n} from \"../../provider\";\nimport { type ReactNode, useMemo } from \"react\";\nimport h from \"../../data-panel.module.sass\";\nimport { Button, Menu, MenuDivider, Tag } from \"@blueprintjs/core\";\nimport {\n ColumnFilterMenuItem,\n ColumnSortMenu,\n InlineFilterControl,\n MenuDropdown,\n MenuFormItem,\n MenuInlineFilterItem,\n resolveColumnFilter,\n} from \"./filter-and-sort.ts\";\nimport { toggleModalSelectionAtom } from \"./selection.ts\";\nimport { atom } from \"jotai\";\n\n/** How the built-in view controls (inline filters, Filter menu, Sort menu) are\n * placed in the toolbar:\n * - `\"inline\"` (default): each control sits in the toolbar.\n * - `\"popover\"`: all of them collapse behind a single button — for a narrow or\n * deliberately chrome-light toolbar.\n * In both cases the controls, state, and provider seam are identical. */\nexport type ViewControlsPresentation = \"inline\" | \"popover\";\n\n/** A filter to surface, plus the label to show for it. */\ninterface FilterEntry {\n filter: TableFilter;\n label: string;\n}\n\n/**\n * Stand-in for the column-header dropdown the card list lacks. Surfaces every\n * available filter (column-declared `filterable` + any table-level `filters`)\n * and sort, honoring each filter's `presentation`:\n * - `\"inline\"` → an always-visible toolbar control (its `filterForm` directly),\n * - `\"menu\"` (default) → a \"Filter\" menu item that opens the form in a submenu,\n * - `\"menu-inline\"` → the form rendered directly in the \"Filter\" menu.\n * Every case reuses the *same* controls and store/provider seam — only\n * placement changes. Sort still comes from the column-declared `sortable` set.\n */\nexport function useDataPanelControls(\n tableFilters: TableFilter[] = [],\n presentation: ViewControlsPresentation = \"inline\",\n): TableAction[] {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n // All filters, table-level first, then column-derived (each with a label).\n const entries = useMemo<FilterEntry[]>(() => {\n const fromColumns = columnSpec\n .filter((c) => isColumnFilterable(c))\n .map((c) => ({ filter: resolveColumnFilter(c), label: c.name }));\n const fromTable = tableFilters.map((f) => ({ filter: f, label: f.name }));\n return [...fromTable, ...fromColumns];\n }, [columnSpec, tableFilters]);\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n // Hooks first (stable order), then assemble.\n const filterMenuAction = useFilterMenuAction(menuEntries);\n const sortAction = useSortAction();\n const collapsedAction = useCollapsedControlsAction(entries);\n const exitSelectionAction = useExitSelectionAction();\n\n // While a modal view is *selecting*, the toolbar belongs to the selection and\n // its set-actions. Changing the view would also invalidate the selection\n // (rows are addressed by index — see `dropRowSelection`), so rather than\n // competing for space, the view controls collapse to a single affordance that\n // **leaves select mode** and hands the toolbar back.\n if (exitSelectionAction != null) return [exitSelectionAction];\n\n // One button holding every control, for a toolbar with no room for them (or a\n // deliberately chrome-light layout).\n if (presentation === \"popover\" && collapsedAction != null) {\n return [collapsedAction];\n }\n\n const actions: TableAction[] = [];\n // Inline filters: one always-visible toolbar control each.\n for (const { filter } of inlineEntries) {\n actions.push({\n id: `filter:${filter.id}`,\n name: filter.name,\n icon: filter.icon,\n targets: ALL_CARDINALITIES,\n render: () => h(InlineFilterControl, { filter }),\n });\n }\n if (filterMenuAction != null) actions.push(filterMenuAction);\n if (sortAction != null) actions.push(sortAction);\n return actions;\n}\n\n/**\n * The whole view-control set behind one button: inline filters as titled\n * sections, then the filters, then the sorts. Same controls, same store seam —\n * only placement changes (the `presentation` idea from `TableFilter`, applied to\n * the toolbar as a whole).\n */\nfunction useCollapsedControlsAction(\n entries: FilterEntry[],\n): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n const hasActiveFilters = ctx.useValue(hasActiveFiltersAtom);\n const hasActiveSorts = ctx.useValue(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (entries.length === 0 && sortableCols.length === 0) return null;\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n const items: ReactNode[] = [];\n for (const { filter, label } of inlineEntries) {\n items.push(\n h(MenuFormItem, { key: filter.id, title: label }, [\n h(InlineFilterControl, { filter }),\n ]),\n );\n }\n if (menuEntries.length > 0) {\n items.push(h(MenuDivider, { key: \"filter-divider\", title: \"Filter\" }));\n for (const { filter, label } of menuEntries) {\n if (presentationOf(filter) === \"menu-inline\") {\n items.push(h(MenuInlineFilterItem, { key: filter.id, filter, label }));\n } else {\n items.push(h(ColumnFilterMenuItem, { key: filter.id, filter, label }));\n }\n }\n }\n if (sortableCols.length > 0) {\n items.push(h(MenuDivider, { key: \"sort-divider\", title: \"Sort\" }));\n for (const col of sortableCols) {\n items.push(\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n );\n }\n }\n\n let intent: \"primary\" | \"none\" = \"none\";\n if (hasActiveFilters || hasActiveSorts) intent = \"primary\";\n\n return {\n id: \"view-controls\",\n name: \"View\",\n icon: \"filter-list\",\n description: \"Search, filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n MenuDropdown,\n { content: h(Menu, { className: \"collapsed-controls\" }, items) },\n [\n h(Button, {\n minimal: true,\n small: true,\n icon: \"filter-list\",\n intent,\n title: \"Search, filter and sort\",\n }),\n ],\n ),\n };\n}\n\n/** While selecting on a modal view: one control that leaves select mode (and so\n * restores the view controls). Labelled for where it takes you, not what it\n * does to the selection. */\nfunction useExitSelectionAction(): TableAction | null {\n const { enableModalSelection } = ctx.useValue(interactionOptionsAtom);\n const selecting = ctx.useValue(enableSelectionAtom);\n const toggleSelectMode = ctx.useSet(toggleModalSelectionAtom);\n\n if (!enableModalSelection || !selecting) return null;\n\n return {\n id: \"exit-selection\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Leave select mode to filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n Tag,\n {\n minimal: true,\n large: true,\n interactive: true,\n icon: \"filter\",\n title: \"Filter and sort (leaves select mode)\",\n onClick: () => toggleSelectMode(),\n },\n \"Filter\",\n ),\n };\n}\n\nfunction presentationOf(filter: TableFilter): string {\n return filter.presentation ?? \"menu\";\n}\n\nfunction useDisplayIntent(atom) {\n const [hasActive, clearActive] = ctx.use(atom);\n const intent = hasActive ? \"primary\" : \"none\";\n\n let rightIcon: \"caret-down\" | undefined = \"caret-down\";\n let onRemove: any = undefined;\n if (hasActive) {\n rightIcon = undefined;\n onRemove = (evt) => {\n clearActive();\n evt.stopPropagation();\n };\n }\n\n return { intent, rightIcon, onRemove, hasActive };\n}\n\nfunction useFilterMenuAction(entries: FilterEntry[]): TableAction | null {\n const rest = useDisplayIntent(hasActiveFiltersAtom);\n\n if (entries.length === 0) return null;\n\n const filterMenu = h(\n Menu,\n entries.map(({ filter, label }) => {\n // A `menu-inline` filter renders its form directly in the menu (no\n // submenu); the default `menu` presentation uses the submenu item.\n if (presentationOf(filter) === \"menu-inline\") {\n return h(MenuInlineFilterItem, { key: filter.id, filter, label });\n }\n return h(ColumnFilterMenuItem, { key: filter.id, filter, label });\n }),\n );\n\n const filterIndicator = h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"filter\",\n ...rest,\n },\n \"Filter\",\n );\n\n return {\n id: \"filter\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Add a filter to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(\n MenuDropdown,\n {\n content: filterMenu,\n placement: \"bottom-start\",\n },\n [filterIndicator],\n ),\n };\n}\n\nfunction useSortAction(): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n const rest = useDisplayIntent(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (sortableCols.length == 0) {\n return null;\n }\n const sortMenu = h(\n Menu,\n sortableCols.map((col) =>\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n ),\n );\n\n return {\n id: \"sort\",\n name: \"Sort\",\n icon: \"sort\",\n description: \"Add a sort to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(MenuDropdown, { content: sortMenu }, [\n h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"sort\",\n ...rest,\n },\n \"Sort\",\n ),\n ]),\n };\n}\n\nconst hasActiveFiltersAtom = atom(\n (get) => get(storeAtom)?.activeFilters.size ?? 0 > 0,\n (get, set) => {\n set(storeAtom, (s) => ({ ...s, activeFilters: new Map([]) }));\n },\n);\nconst hasActiveSortsAtom = atom(\n (get) => get(storeAtom)?.columnSorts.length ?? 0 > 0,\n (get, set) => {\n set(storeAtom, (s) => ({ ...s, columnSorts: [] }));\n },\n);\n"],"names":["useSelector","useMemo","isColumnFilterable","resolveColumnFilter","ALL_CARDINALITIES","h","InlineFilterControl","ctx","MenuFormItem","MenuDivider","MenuInlineFilterItem","ColumnFilterMenuItem","ColumnSortMenu","MenuDropdown","Menu","Button","interactionOptionsAtom","enableSelectionAtom","toggleModalSelectionAtom","Tag","atom","storeAtom"],"mappings":";;;;;;;;;;;;AAoDO,SAAS,qBACd,eAA8B,IAC9B,eAAyC,UAC1B;AACf,QAAM,aAAaA,KAAAA,YAAY,CAAC,MAAM,EAAE,UAAU;AAGlD,QAAM,UAAUC,MAAAA,QAAuB,MAAM;AAC3C,UAAM,cAAc,WACjB,OAAO,CAAC,MAAMC,kCAAmB,CAAC,CAAC,EACnC,IAAI,CAAC,OAAO,EAAE,QAAQC,cAAAA,oBAAoB,CAAC,GAAG,OAAO,EAAE,OAAO;AACjE,UAAM,YAAY,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,EAAE,KAAA,EAAO;AACxE,WAAO,CAAC,GAAG,WAAW,GAAG,WAAW;AAAA,EACtC,GAAG,CAAC,YAAY,YAAY,CAAC;AAE7B,QAAM,gBAAgB,QAAQ;AAAA,IAC5B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;AAAA,EAAA;AAEtC,QAAM,cAAc,QAAQ;AAAA,IAC1B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;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QAChBT,iBAAAA,QAAEO,8BAAgB,EAAE,KAAK,IAAI,KAAK,WAAW,IAAI,KAAK,MAAM,IAAI,MAAM;AAAA,IAAA;AAAA,EACxE;AAGF,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAASR,YAAAA;AAAAA,IACT,QAAQ,CAACG,SACPF,iBAAAA,QAAEQ,cAAAA,cAAc,EAAE,SAAS,YAAY;AAAA,MACrCR,iBAAAA;AAAAA,QACEc,OAAAA;AAAAA,QACA;AAAA,UACE,SAAS;AAAA,UACT,OAAO;AAAA,UACP,MAAM;AAAA,UACN,GAAG;AAAA,QAAA;AAAA,QAEL;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EAAA;AAEP;AAEA,MAAM,uBAAuBC,MAAAA;AAAAA,EAC3B,CAAC,QAAQ,IAAIC,KAAAA,SAAS,GAAG,cAAc,QAAQ,IAAI;AAAA,EACnD,CAAC,KAAK,QAAQ;AACZ,QAAIA,KAAAA,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,eAAe,oBAAI,IAAI,EAAE,EAAA,EAAI;AAAA,EAC9D;AACF;AACA,MAAM,qBAAqBD,MAAAA;AAAAA,EACzB,CAAC,QAAQ,IAAIC,KAAAA,SAAS,GAAG,YAAY,UAAU,IAAI;AAAA,EACnD,CAAC,KAAK,QAAQ;AACZ,QAAIA,KAAAA,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,aAAa,CAAA,EAAC,EAAI;AAAA,EACnD;AACF;;"}
1
+ {"version":3,"file":"unified-filters.cjs","sources":["../../../src/components/indicators/unified-filters.ts"],"sourcesContent":["import {\n ALL_CARDINALITIES,\n isColumnFilterable,\n TableAction,\n TableFilter,\n} from \"../../actions\";\nimport {\n ctx,\n enableSelectionAtom,\n interactionOptionsAtom,\n storeAtom,\n useSelector,\n} from \"../../provider\";\nimport { type ReactNode, useMemo } from \"react\";\nimport h from \"../../data-panel.module.sass\";\nimport { Button, Menu, MenuDivider, Tag } from \"@blueprintjs/core\";\nimport {\n ColumnFilterMenuItem,\n ColumnSortMenu,\n InlineFilterControl,\n MenuDropdown,\n MenuFormItem,\n MenuInlineFilterItem,\n resolveColumnFilter,\n} from \"./filter-and-sort.ts\";\nimport { toggleModalSelectionAtom } from \"./selection.ts\";\nimport { atom } from \"jotai\";\n\n/** How the built-in view controls (inline filters, Filter menu, Sort menu) are\n * placed in the toolbar:\n * - `\"inline\"` (default): each control sits in the toolbar.\n * - `\"popover\"`: all of them collapse behind a single button — for a narrow or\n * deliberately chrome-light toolbar.\n * In both cases the controls, state, and provider seam are identical. */\nexport type ViewControlsPresentation = \"inline\" | \"popover\";\n\n/** A filter to surface, plus the label to show for it. */\ninterface FilterEntry {\n filter: TableFilter;\n label: string;\n}\n\n/**\n * Stand-in for the column-header dropdown the card list lacks. Surfaces every\n * available filter (column-declared `filterable` + any table-level `filters`)\n * and sort, honoring each filter's `presentation`:\n * - `\"inline\"` → an always-visible toolbar control (its `filterForm` directly),\n * - `\"menu\"` (default) → a \"Filter\" menu item that opens the form in a submenu,\n * - `\"menu-inline\"` → the form rendered directly in the \"Filter\" menu.\n * Every case reuses the *same* controls and store/provider seam — only\n * placement changes. Sort still comes from the column-declared `sortable` set.\n */\nexport function useDataPanelControls(\n tableFilters: TableFilter[] = [],\n presentation: ViewControlsPresentation = \"inline\",\n): TableAction[] {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n // All filters, table-level first, then column-derived (each with a label).\n const entries = useMemo<FilterEntry[]>(() => {\n const fromColumns = columnSpec\n .filter((c) => isColumnFilterable(c))\n .map((c) => ({ filter: resolveColumnFilter(c), label: c.name }));\n const fromTable = tableFilters.map((f) => ({ filter: f, label: f.name }));\n return [...fromTable, ...fromColumns];\n }, [columnSpec, tableFilters]);\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n // Hooks first (stable order), then assemble.\n const filterMenuAction = useFilterMenuAction(menuEntries);\n const sortAction = useSortAction();\n const collapsedAction = useCollapsedControlsAction(entries);\n const exitSelectionAction = useExitSelectionAction();\n\n // While a modal view is *selecting*, the toolbar belongs to the selection and\n // its set-actions. Changing the view would also invalidate the selection\n // (rows are addressed by index — see `dropRowSelection`), so rather than\n // competing for space, the view controls collapse to a single affordance that\n // **leaves select mode** and hands the toolbar back.\n if (exitSelectionAction != null) return [exitSelectionAction];\n\n // One button holding every control, for a toolbar with no room for them (or a\n // deliberately chrome-light layout).\n if (presentation === \"popover\" && collapsedAction != null) {\n return [collapsedAction];\n }\n\n const actions: TableAction[] = [];\n // Inline filters: one always-visible toolbar control each.\n for (const { filter } of inlineEntries) {\n actions.push({\n id: `filter:${filter.id}`,\n name: filter.name,\n icon: filter.icon,\n targets: ALL_CARDINALITIES,\n render: () => h(InlineFilterControl, { filter }),\n });\n }\n if (filterMenuAction != null) actions.push(filterMenuAction);\n if (sortAction != null) actions.push(sortAction);\n return actions;\n}\n\n/**\n * The whole view-control set behind one button: inline filters as titled\n * sections, then the filters, then the sorts. Same controls, same store seam —\n * only placement changes (the `presentation` idea from `TableFilter`, applied to\n * the toolbar as a whole).\n */\nfunction useCollapsedControlsAction(\n entries: FilterEntry[],\n): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n const hasActiveFilters = ctx.useValue(hasActiveFiltersAtom);\n const hasActiveSorts = ctx.useValue(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (entries.length === 0 && sortableCols.length === 0) return null;\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n const items: ReactNode[] = [];\n for (const { filter, label } of inlineEntries) {\n items.push(\n h(MenuFormItem, { key: filter.id, title: label }, [\n h(InlineFilterControl, { filter }),\n ]),\n );\n }\n if (menuEntries.length > 0) {\n items.push(h(MenuDivider, { key: \"filter-divider\", title: \"Filter\" }));\n for (const { filter, label } of menuEntries) {\n if (presentationOf(filter) === \"menu-inline\") {\n items.push(h(MenuInlineFilterItem, { key: filter.id, filter, label }));\n } else {\n items.push(h(ColumnFilterMenuItem, { key: filter.id, filter, label }));\n }\n }\n }\n if (sortableCols.length > 0) {\n items.push(h(MenuDivider, { key: \"sort-divider\", title: \"Sort\" }));\n for (const col of sortableCols) {\n items.push(\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n );\n }\n }\n\n let intent: \"primary\" | \"none\" = \"none\";\n if (hasActiveFilters || hasActiveSorts) intent = \"primary\";\n\n return {\n id: \"view-controls\",\n name: \"View\",\n icon: \"filter-list\",\n description: \"Search, filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n MenuDropdown,\n { content: h(Menu, { className: \"collapsed-controls\" }, items) },\n [\n h(Button, {\n minimal: true,\n small: true,\n icon: \"filter-list\",\n intent,\n title: \"Search, filter and sort\",\n }),\n ],\n ),\n };\n}\n\n/** While selecting on a modal view: one control that leaves select mode (and so\n * restores the view controls). Labelled for where it takes you, not what it\n * does to the selection. */\nfunction useExitSelectionAction(): TableAction | null {\n const { enableModalSelection } = ctx.useValue(interactionOptionsAtom);\n const selecting = ctx.useValue(enableSelectionAtom);\n const toggleSelectMode = ctx.useSet(toggleModalSelectionAtom);\n\n if (!enableModalSelection || !selecting) return null;\n\n return {\n id: \"exit-selection\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Leave select mode to filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n Tag,\n {\n minimal: true,\n large: true,\n interactive: true,\n icon: \"filter\",\n title: \"Filter and sort (leaves select mode)\",\n onClick: () => toggleSelectMode(),\n },\n \"Filter\",\n ),\n };\n}\n\nfunction presentationOf(filter: TableFilter): string {\n return filter.presentation ?? \"menu\";\n}\n\n/** Active-state + clear for a subset of filters, keyed by id. */\nfunction useFilterSubsetState(entries: FilterEntry[]): [boolean, () => void] {\n const ids = entries.map((e) => e.filter.id);\n const key = ids.join(\"\\u0000\");\n const subsetAtom = useMemo(\n () =>\n atom(\n (get) => {\n const active = get(storeAtom)?.activeFilters;\n if (active == null) return false;\n return ids.some((id) => active.has(id));\n },\n (get) => {\n const store = get(storeAtom);\n if (store == null) return;\n for (const id of ids) store.removeFilter(id);\n },\n ),\n [key],\n );\n const [hasActive, clear] = ctx.use(subsetAtom);\n return [hasActive, clear as () => void];\n}\n\nfunction useDisplayIntent([hasActive, clearActive]: [boolean, () => void]) {\n const intent = hasActive ? \"primary\" : \"none\";\n\n let rightIcon: \"caret-down\" | undefined = \"caret-down\";\n let onRemove: any = undefined;\n if (hasActive) {\n rightIcon = undefined;\n onRemove = (evt) => {\n clearActive();\n evt.stopPropagation();\n };\n }\n\n return { intent, rightIcon, onRemove, hasActive };\n}\n\nfunction useFilterMenuAction(entries: FilterEntry[]): TableAction | null {\n // Scoped to the filters this menu actually holds. An `\"inline\"` filter has\n // its own always-visible control, so it must not light up the Filter tag —\n // nor be wiped by its clear button, which reads as \"clear the filters in\n // here\".\n const rest = useDisplayIntent(useFilterSubsetState(entries));\n\n if (entries.length === 0) return null;\n\n const filterMenu = h(\n Menu,\n entries.map(({ filter, label }) => {\n // A `menu-inline` filter renders its form directly in the menu (no\n // submenu); the default `menu` presentation uses the submenu item.\n if (presentationOf(filter) === \"menu-inline\") {\n return h(MenuInlineFilterItem, { key: filter.id, filter, label });\n }\n return h(ColumnFilterMenuItem, { key: filter.id, filter, label });\n }),\n );\n\n const filterIndicator = h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"filter\",\n ...rest,\n },\n \"Filter\",\n );\n\n return {\n id: \"filter\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Add a filter to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(\n MenuDropdown,\n {\n content: filterMenu,\n placement: \"bottom-start\",\n },\n [filterIndicator],\n ),\n };\n}\n\nfunction useSortAction(): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n const rest = useDisplayIntent(ctx.use(hasActiveSortsAtom));\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (sortableCols.length == 0) {\n return null;\n }\n const sortMenu = h(\n Menu,\n sortableCols.map((col) =>\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n ),\n );\n\n return {\n id: \"sort\",\n name: \"Sort\",\n icon: \"sort\",\n description: \"Add a sort to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(MenuDropdown, { content: sortMenu }, [\n h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"sort\",\n ...rest,\n },\n \"Sort\",\n ),\n ]),\n };\n}\n\n// Both of these clear through the store's *actions* rather than writing the\n// state directly: the actions are what also drop a now-meaningless row\n// selection (see `dropRowSelection`).\nconst hasActiveFiltersAtom = atom(\n (get) => (get(storeAtom)?.activeFilters?.size ?? 0) > 0,\n (get) => {\n get(storeAtom)?.clearFilters?.();\n },\n);\nconst hasActiveSortsAtom = atom(\n (get) => (get(storeAtom)?.columnSorts?.length ?? 0) > 0,\n (get) => {\n get(storeAtom)?.clearColumnSorts?.();\n },\n);\n"],"names":["useSelector","useMemo","isColumnFilterable","resolveColumnFilter","ALL_CARDINALITIES","h","InlineFilterControl","ctx","MenuFormItem","MenuDivider","MenuInlineFilterItem","ColumnFilterMenuItem","ColumnSortMenu","MenuDropdown","Menu","Button","interactionOptionsAtom","enableSelectionAtom","toggleModalSelectionAtom","Tag","atom","storeAtom"],"mappings":";;;;;;;;;;;;AAoDO,SAAS,qBACd,eAA8B,IAC9B,eAAyC,UAC1B;AACf,QAAM,aAAaA,KAAAA,YAAY,CAAC,MAAM,EAAE,UAAU;AAGlD,QAAM,UAAUC,MAAAA,QAAuB,MAAM;AAC3C,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F,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAASR,YAAAA;AAAAA,IACT,QAAQ,CAACG,SACPF,iBAAAA,QAAEQ,cAAAA,cAAc,EAAE,SAAS,YAAY;AAAA,MACrCR,iBAAAA;AAAAA,QACEc,OAAAA;AAAAA,QACA;AAAA,UACE,SAAS;AAAA,UACT,OAAO;AAAA,UACP,MAAM;AAAA,UACN,GAAG;AAAA,QAAA;AAAA,QAEL;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EAAA;AAEP;AAKA,MAAM,uBAAuBC,MAAAA;AAAAA,EAC3B,CAAC,SAAS,IAAIC,KAAAA,SAAS,GAAG,eAAe,QAAQ,KAAK;AAAA,EACtD,CAAC,QAAQ;AACP,QAAIA,KAAAA,SAAS,GAAG,eAAA;AAAA,EAClB;AACF;AACA,MAAM,qBAAqBD,MAAAA;AAAAA,EACzB,CAAC,SAAS,IAAIC,KAAAA,SAAS,GAAG,aAAa,UAAU,KAAK;AAAA,EACtD,CAAC,QAAQ;AACP,QAAIA,KAAAA,SAAS,GAAG,mBAAA;AAAA,EAClB;AACF;;"}
@@ -137,8 +137,28 @@ function useExitSelectionAction() {
137
137
  function presentationOf(filter) {
138
138
  return filter.presentation ?? "menu";
139
139
  }
140
- function useDisplayIntent(atom2) {
141
- const [hasActive, clearActive] = ctx.use(atom2);
140
+ function useFilterSubsetState(entries) {
141
+ const ids = entries.map((e) => e.filter.id);
142
+ const key = ids.join("\0");
143
+ const subsetAtom = useMemo(
144
+ () => atom(
145
+ (get) => {
146
+ const active = get(storeAtom)?.activeFilters;
147
+ if (active == null) return false;
148
+ return ids.some((id) => active.has(id));
149
+ },
150
+ (get) => {
151
+ const store = get(storeAtom);
152
+ if (store == null) return;
153
+ for (const id of ids) store.removeFilter(id);
154
+ }
155
+ ),
156
+ [key]
157
+ );
158
+ const [hasActive, clear] = ctx.use(subsetAtom);
159
+ return [hasActive, clear];
160
+ }
161
+ function useDisplayIntent([hasActive, clearActive]) {
142
162
  const intent = hasActive ? "primary" : "none";
143
163
  let rightIcon = "caret-down";
144
164
  let onRemove = void 0;
@@ -152,7 +172,7 @@ function useDisplayIntent(atom2) {
152
172
  return { intent, rightIcon, onRemove, hasActive };
153
173
  }
154
174
  function useFilterMenuAction(entries) {
155
- const rest = useDisplayIntent(hasActiveFiltersAtom);
175
+ const rest = useDisplayIntent(useFilterSubsetState(entries));
156
176
  if (entries.length === 0) return null;
157
177
  const filterMenu = h(
158
178
  Menu,
@@ -191,7 +211,7 @@ function useFilterMenuAction(entries) {
191
211
  }
192
212
  function useSortAction() {
193
213
  const columnSpec = useSelector((s) => s.columnSpec);
194
- const rest = useDisplayIntent(hasActiveSortsAtom);
214
+ const rest = useDisplayIntent(ctx.use(hasActiveSortsAtom));
195
215
  const sortableCols = useMemo(
196
216
  () => columnSpec.filter((c) => c.sortable),
197
217
  [columnSpec]
@@ -226,15 +246,15 @@ function useSortAction() {
226
246
  };
227
247
  }
228
248
  const hasActiveFiltersAtom = atom(
229
- (get) => get(storeAtom)?.activeFilters.size ?? 0 > 0,
230
- (get, set) => {
231
- set(storeAtom, (s) => ({ ...s, activeFilters: /* @__PURE__ */ new Map([]) }));
249
+ (get) => (get(storeAtom)?.activeFilters?.size ?? 0) > 0,
250
+ (get) => {
251
+ get(storeAtom)?.clearFilters?.();
232
252
  }
233
253
  );
234
254
  const hasActiveSortsAtom = atom(
235
- (get) => get(storeAtom)?.columnSorts.length ?? 0 > 0,
236
- (get, set) => {
237
- set(storeAtom, (s) => ({ ...s, columnSorts: [] }));
255
+ (get) => (get(storeAtom)?.columnSorts?.length ?? 0) > 0,
256
+ (get) => {
257
+ get(storeAtom)?.clearColumnSorts?.();
238
258
  }
239
259
  );
240
260
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"unified-filters.js","sources":["../../../src/components/indicators/unified-filters.ts"],"sourcesContent":["import {\n ALL_CARDINALITIES,\n isColumnFilterable,\n TableAction,\n TableFilter,\n} from \"../../actions\";\nimport {\n ctx,\n enableSelectionAtom,\n interactionOptionsAtom,\n storeAtom,\n useSelector,\n} from \"../../provider\";\nimport { type ReactNode, useMemo } from \"react\";\nimport h from \"../../data-panel.module.sass\";\nimport { Button, Menu, MenuDivider, Tag } from \"@blueprintjs/core\";\nimport {\n ColumnFilterMenuItem,\n ColumnSortMenu,\n InlineFilterControl,\n MenuDropdown,\n MenuFormItem,\n MenuInlineFilterItem,\n resolveColumnFilter,\n} from \"./filter-and-sort.ts\";\nimport { toggleModalSelectionAtom } from \"./selection.ts\";\nimport { atom } from \"jotai\";\n\n/** How the built-in view controls (inline filters, Filter menu, Sort menu) are\n * placed in the toolbar:\n * - `\"inline\"` (default): each control sits in the toolbar.\n * - `\"popover\"`: all of them collapse behind a single button — for a narrow or\n * deliberately chrome-light toolbar.\n * In both cases the controls, state, and provider seam are identical. */\nexport type ViewControlsPresentation = \"inline\" | \"popover\";\n\n/** A filter to surface, plus the label to show for it. */\ninterface FilterEntry {\n filter: TableFilter;\n label: string;\n}\n\n/**\n * Stand-in for the column-header dropdown the card list lacks. Surfaces every\n * available filter (column-declared `filterable` + any table-level `filters`)\n * and sort, honoring each filter's `presentation`:\n * - `\"inline\"` → an always-visible toolbar control (its `filterForm` directly),\n * - `\"menu\"` (default) → a \"Filter\" menu item that opens the form in a submenu,\n * - `\"menu-inline\"` → the form rendered directly in the \"Filter\" menu.\n * Every case reuses the *same* controls and store/provider seam — only\n * placement changes. Sort still comes from the column-declared `sortable` set.\n */\nexport function useDataPanelControls(\n tableFilters: TableFilter[] = [],\n presentation: ViewControlsPresentation = \"inline\",\n): TableAction[] {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n // All filters, table-level first, then column-derived (each with a label).\n const entries = useMemo<FilterEntry[]>(() => {\n const fromColumns = columnSpec\n .filter((c) => isColumnFilterable(c))\n .map((c) => ({ filter: resolveColumnFilter(c), label: c.name }));\n const fromTable = tableFilters.map((f) => ({ filter: f, label: f.name }));\n return [...fromTable, ...fromColumns];\n }, [columnSpec, tableFilters]);\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n // Hooks first (stable order), then assemble.\n const filterMenuAction = useFilterMenuAction(menuEntries);\n const sortAction = useSortAction();\n const collapsedAction = useCollapsedControlsAction(entries);\n const exitSelectionAction = useExitSelectionAction();\n\n // While a modal view is *selecting*, the toolbar belongs to the selection and\n // its set-actions. Changing the view would also invalidate the selection\n // (rows are addressed by index — see `dropRowSelection`), so rather than\n // competing for space, the view controls collapse to a single affordance that\n // **leaves select mode** and hands the toolbar back.\n if (exitSelectionAction != null) return [exitSelectionAction];\n\n // One button holding every control, for a toolbar with no room for them (or a\n // deliberately chrome-light layout).\n if (presentation === \"popover\" && collapsedAction != null) {\n return [collapsedAction];\n }\n\n const actions: TableAction[] = [];\n // Inline filters: one always-visible toolbar control each.\n for (const { filter } of inlineEntries) {\n actions.push({\n id: `filter:${filter.id}`,\n name: filter.name,\n icon: filter.icon,\n targets: ALL_CARDINALITIES,\n render: () => h(InlineFilterControl, { filter }),\n });\n }\n if (filterMenuAction != null) actions.push(filterMenuAction);\n if (sortAction != null) actions.push(sortAction);\n return actions;\n}\n\n/**\n * The whole view-control set behind one button: inline filters as titled\n * sections, then the filters, then the sorts. Same controls, same store seam —\n * only placement changes (the `presentation` idea from `TableFilter`, applied to\n * the toolbar as a whole).\n */\nfunction useCollapsedControlsAction(\n entries: FilterEntry[],\n): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n const hasActiveFilters = ctx.useValue(hasActiveFiltersAtom);\n const hasActiveSorts = ctx.useValue(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (entries.length === 0 && sortableCols.length === 0) return null;\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n const items: ReactNode[] = [];\n for (const { filter, label } of inlineEntries) {\n items.push(\n h(MenuFormItem, { key: filter.id, title: label }, [\n h(InlineFilterControl, { filter }),\n ]),\n );\n }\n if (menuEntries.length > 0) {\n items.push(h(MenuDivider, { key: \"filter-divider\", title: \"Filter\" }));\n for (const { filter, label } of menuEntries) {\n if (presentationOf(filter) === \"menu-inline\") {\n items.push(h(MenuInlineFilterItem, { key: filter.id, filter, label }));\n } else {\n items.push(h(ColumnFilterMenuItem, { key: filter.id, filter, label }));\n }\n }\n }\n if (sortableCols.length > 0) {\n items.push(h(MenuDivider, { key: \"sort-divider\", title: \"Sort\" }));\n for (const col of sortableCols) {\n items.push(\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n );\n }\n }\n\n let intent: \"primary\" | \"none\" = \"none\";\n if (hasActiveFilters || hasActiveSorts) intent = \"primary\";\n\n return {\n id: \"view-controls\",\n name: \"View\",\n icon: \"filter-list\",\n description: \"Search, filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n MenuDropdown,\n { content: h(Menu, { className: \"collapsed-controls\" }, items) },\n [\n h(Button, {\n minimal: true,\n small: true,\n icon: \"filter-list\",\n intent,\n title: \"Search, filter and sort\",\n }),\n ],\n ),\n };\n}\n\n/** While selecting on a modal view: one control that leaves select mode (and so\n * restores the view controls). Labelled for where it takes you, not what it\n * does to the selection. */\nfunction useExitSelectionAction(): TableAction | null {\n const { enableModalSelection } = ctx.useValue(interactionOptionsAtom);\n const selecting = ctx.useValue(enableSelectionAtom);\n const toggleSelectMode = ctx.useSet(toggleModalSelectionAtom);\n\n if (!enableModalSelection || !selecting) return null;\n\n return {\n id: \"exit-selection\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Leave select mode to filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n Tag,\n {\n minimal: true,\n large: true,\n interactive: true,\n icon: \"filter\",\n title: \"Filter and sort (leaves select mode)\",\n onClick: () => toggleSelectMode(),\n },\n \"Filter\",\n ),\n };\n}\n\nfunction presentationOf(filter: TableFilter): string {\n return filter.presentation ?? \"menu\";\n}\n\nfunction useDisplayIntent(atom) {\n const [hasActive, clearActive] = ctx.use(atom);\n const intent = hasActive ? \"primary\" : \"none\";\n\n let rightIcon: \"caret-down\" | undefined = \"caret-down\";\n let onRemove: any = undefined;\n if (hasActive) {\n rightIcon = undefined;\n onRemove = (evt) => {\n clearActive();\n evt.stopPropagation();\n };\n }\n\n return { intent, rightIcon, onRemove, hasActive };\n}\n\nfunction useFilterMenuAction(entries: FilterEntry[]): TableAction | null {\n const rest = useDisplayIntent(hasActiveFiltersAtom);\n\n if (entries.length === 0) return null;\n\n const filterMenu = h(\n Menu,\n entries.map(({ filter, label }) => {\n // A `menu-inline` filter renders its form directly in the menu (no\n // submenu); the default `menu` presentation uses the submenu item.\n if (presentationOf(filter) === \"menu-inline\") {\n return h(MenuInlineFilterItem, { key: filter.id, filter, label });\n }\n return h(ColumnFilterMenuItem, { key: filter.id, filter, label });\n }),\n );\n\n const filterIndicator = h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"filter\",\n ...rest,\n },\n \"Filter\",\n );\n\n return {\n id: \"filter\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Add a filter to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(\n MenuDropdown,\n {\n content: filterMenu,\n placement: \"bottom-start\",\n },\n [filterIndicator],\n ),\n };\n}\n\nfunction useSortAction(): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n const rest = useDisplayIntent(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (sortableCols.length == 0) {\n return null;\n }\n const sortMenu = h(\n Menu,\n sortableCols.map((col) =>\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n ),\n );\n\n return {\n id: \"sort\",\n name: \"Sort\",\n icon: \"sort\",\n description: \"Add a sort to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(MenuDropdown, { content: sortMenu }, [\n h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"sort\",\n ...rest,\n },\n \"Sort\",\n ),\n ]),\n };\n}\n\nconst hasActiveFiltersAtom = atom(\n (get) => get(storeAtom)?.activeFilters.size ?? 0 > 0,\n (get, set) => {\n set(storeAtom, (s) => ({ ...s, activeFilters: new Map([]) }));\n },\n);\nconst hasActiveSortsAtom = atom(\n (get) => get(storeAtom)?.columnSorts.length ?? 0 > 0,\n (get, set) => {\n set(storeAtom, (s) => ({ ...s, columnSorts: [] }));\n },\n);\n"],"names":["atom","ctx"],"mappings":";;;;;;;;;;AAoDO,SAAS,qBACd,eAA8B,IAC9B,eAAyC,UAC1B;AACf,QAAM,aAAa,YAAY,CAAC,MAAM,EAAE,UAAU;AAGlD,QAAM,UAAU,QAAuB,MAAM;AAC3C,UAAM,cAAc,WACjB,OAAO,CAAC,MAAM,mBAAmB,CAAC,CAAC,EACnC,IAAI,CAAC,OAAO,EAAE,QAAQ,oBAAoB,CAAC,GAAG,OAAO,EAAE,OAAO;AACjE,UAAM,YAAY,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,EAAE,KAAA,EAAO;AACxE,WAAO,CAAC,GAAG,WAAW,GAAG,WAAW;AAAA,EACtC,GAAG,CAAC,YAAY,YAAY,CAAC;AAE7B,QAAM,gBAAgB,QAAQ;AAAA,IAC5B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;AAAA,EAAA;AAEtC,QAAM,cAAc,QAAQ;AAAA,IAC1B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;AAAA,EAAA;AAItC,QAAM,mBAAmB,oBAAoB,WAAW;AACxD,QAAM,aAAa,cAAA;AACnB,QAAM,kBAAkB,2BAA2B,OA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,CAAC,KAAK,QAAQ;AACZ,QAAI,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,eAAe,oBAAI,IAAI,EAAE,EAAA,EAAI;AAAA,EAC9D;AACF;AACA,MAAM,qBAAqB;AAAA,EACzB,CAAC,QAAQ,IAAI,SAAS,GAAG,YAAY,UAAU,IAAI;AAAA,EACnD,CAAC,KAAK,QAAQ;AACZ,QAAI,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,aAAa,CAAA,EAAC,EAAI;AAAA,EACnD;AACF;"}
1
+ {"version":3,"file":"unified-filters.js","sources":["../../../src/components/indicators/unified-filters.ts"],"sourcesContent":["import {\n ALL_CARDINALITIES,\n isColumnFilterable,\n TableAction,\n TableFilter,\n} from \"../../actions\";\nimport {\n ctx,\n enableSelectionAtom,\n interactionOptionsAtom,\n storeAtom,\n useSelector,\n} from \"../../provider\";\nimport { type ReactNode, useMemo } from \"react\";\nimport h from \"../../data-panel.module.sass\";\nimport { Button, Menu, MenuDivider, Tag } from \"@blueprintjs/core\";\nimport {\n ColumnFilterMenuItem,\n ColumnSortMenu,\n InlineFilterControl,\n MenuDropdown,\n MenuFormItem,\n MenuInlineFilterItem,\n resolveColumnFilter,\n} from \"./filter-and-sort.ts\";\nimport { toggleModalSelectionAtom } from \"./selection.ts\";\nimport { atom } from \"jotai\";\n\n/** How the built-in view controls (inline filters, Filter menu, Sort menu) are\n * placed in the toolbar:\n * - `\"inline\"` (default): each control sits in the toolbar.\n * - `\"popover\"`: all of them collapse behind a single button — for a narrow or\n * deliberately chrome-light toolbar.\n * In both cases the controls, state, and provider seam are identical. */\nexport type ViewControlsPresentation = \"inline\" | \"popover\";\n\n/** A filter to surface, plus the label to show for it. */\ninterface FilterEntry {\n filter: TableFilter;\n label: string;\n}\n\n/**\n * Stand-in for the column-header dropdown the card list lacks. Surfaces every\n * available filter (column-declared `filterable` + any table-level `filters`)\n * and sort, honoring each filter's `presentation`:\n * - `\"inline\"` → an always-visible toolbar control (its `filterForm` directly),\n * - `\"menu\"` (default) → a \"Filter\" menu item that opens the form in a submenu,\n * - `\"menu-inline\"` → the form rendered directly in the \"Filter\" menu.\n * Every case reuses the *same* controls and store/provider seam — only\n * placement changes. Sort still comes from the column-declared `sortable` set.\n */\nexport function useDataPanelControls(\n tableFilters: TableFilter[] = [],\n presentation: ViewControlsPresentation = \"inline\",\n): TableAction[] {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n // All filters, table-level first, then column-derived (each with a label).\n const entries = useMemo<FilterEntry[]>(() => {\n const fromColumns = columnSpec\n .filter((c) => isColumnFilterable(c))\n .map((c) => ({ filter: resolveColumnFilter(c), label: c.name }));\n const fromTable = tableFilters.map((f) => ({ filter: f, label: f.name }));\n return [...fromTable, ...fromColumns];\n }, [columnSpec, tableFilters]);\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n // Hooks first (stable order), then assemble.\n const filterMenuAction = useFilterMenuAction(menuEntries);\n const sortAction = useSortAction();\n const collapsedAction = useCollapsedControlsAction(entries);\n const exitSelectionAction = useExitSelectionAction();\n\n // While a modal view is *selecting*, the toolbar belongs to the selection and\n // its set-actions. Changing the view would also invalidate the selection\n // (rows are addressed by index — see `dropRowSelection`), so rather than\n // competing for space, the view controls collapse to a single affordance that\n // **leaves select mode** and hands the toolbar back.\n if (exitSelectionAction != null) return [exitSelectionAction];\n\n // One button holding every control, for a toolbar with no room for them (or a\n // deliberately chrome-light layout).\n if (presentation === \"popover\" && collapsedAction != null) {\n return [collapsedAction];\n }\n\n const actions: TableAction[] = [];\n // Inline filters: one always-visible toolbar control each.\n for (const { filter } of inlineEntries) {\n actions.push({\n id: `filter:${filter.id}`,\n name: filter.name,\n icon: filter.icon,\n targets: ALL_CARDINALITIES,\n render: () => h(InlineFilterControl, { filter }),\n });\n }\n if (filterMenuAction != null) actions.push(filterMenuAction);\n if (sortAction != null) actions.push(sortAction);\n return actions;\n}\n\n/**\n * The whole view-control set behind one button: inline filters as titled\n * sections, then the filters, then the sorts. Same controls, same store seam —\n * only placement changes (the `presentation` idea from `TableFilter`, applied to\n * the toolbar as a whole).\n */\nfunction useCollapsedControlsAction(\n entries: FilterEntry[],\n): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n const hasActiveFilters = ctx.useValue(hasActiveFiltersAtom);\n const hasActiveSorts = ctx.useValue(hasActiveSortsAtom);\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (entries.length === 0 && sortableCols.length === 0) return null;\n\n const inlineEntries = entries.filter(\n (e) => presentationOf(e.filter) === \"inline\",\n );\n const menuEntries = entries.filter(\n (e) => presentationOf(e.filter) !== \"inline\",\n );\n\n const items: ReactNode[] = [];\n for (const { filter, label } of inlineEntries) {\n items.push(\n h(MenuFormItem, { key: filter.id, title: label }, [\n h(InlineFilterControl, { filter }),\n ]),\n );\n }\n if (menuEntries.length > 0) {\n items.push(h(MenuDivider, { key: \"filter-divider\", title: \"Filter\" }));\n for (const { filter, label } of menuEntries) {\n if (presentationOf(filter) === \"menu-inline\") {\n items.push(h(MenuInlineFilterItem, { key: filter.id, filter, label }));\n } else {\n items.push(h(ColumnFilterMenuItem, { key: filter.id, filter, label }));\n }\n }\n }\n if (sortableCols.length > 0) {\n items.push(h(MenuDivider, { key: \"sort-divider\", title: \"Sort\" }));\n for (const col of sortableCols) {\n items.push(\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n );\n }\n }\n\n let intent: \"primary\" | \"none\" = \"none\";\n if (hasActiveFilters || hasActiveSorts) intent = \"primary\";\n\n return {\n id: \"view-controls\",\n name: \"View\",\n icon: \"filter-list\",\n description: \"Search, filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n MenuDropdown,\n { content: h(Menu, { className: \"collapsed-controls\" }, items) },\n [\n h(Button, {\n minimal: true,\n small: true,\n icon: \"filter-list\",\n intent,\n title: \"Search, filter and sort\",\n }),\n ],\n ),\n };\n}\n\n/** While selecting on a modal view: one control that leaves select mode (and so\n * restores the view controls). Labelled for where it takes you, not what it\n * does to the selection. */\nfunction useExitSelectionAction(): TableAction | null {\n const { enableModalSelection } = ctx.useValue(interactionOptionsAtom);\n const selecting = ctx.useValue(enableSelectionAtom);\n const toggleSelectMode = ctx.useSet(toggleModalSelectionAtom);\n\n if (!enableModalSelection || !selecting) return null;\n\n return {\n id: \"exit-selection\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Leave select mode to filter and sort.\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () =>\n h(\n Tag,\n {\n minimal: true,\n large: true,\n interactive: true,\n icon: \"filter\",\n title: \"Filter and sort (leaves select mode)\",\n onClick: () => toggleSelectMode(),\n },\n \"Filter\",\n ),\n };\n}\n\nfunction presentationOf(filter: TableFilter): string {\n return filter.presentation ?? \"menu\";\n}\n\n/** Active-state + clear for a subset of filters, keyed by id. */\nfunction useFilterSubsetState(entries: FilterEntry[]): [boolean, () => void] {\n const ids = entries.map((e) => e.filter.id);\n const key = ids.join(\"\\u0000\");\n const subsetAtom = useMemo(\n () =>\n atom(\n (get) => {\n const active = get(storeAtom)?.activeFilters;\n if (active == null) return false;\n return ids.some((id) => active.has(id));\n },\n (get) => {\n const store = get(storeAtom);\n if (store == null) return;\n for (const id of ids) store.removeFilter(id);\n },\n ),\n [key],\n );\n const [hasActive, clear] = ctx.use(subsetAtom);\n return [hasActive, clear as () => void];\n}\n\nfunction useDisplayIntent([hasActive, clearActive]: [boolean, () => void]) {\n const intent = hasActive ? \"primary\" : \"none\";\n\n let rightIcon: \"caret-down\" | undefined = \"caret-down\";\n let onRemove: any = undefined;\n if (hasActive) {\n rightIcon = undefined;\n onRemove = (evt) => {\n clearActive();\n evt.stopPropagation();\n };\n }\n\n return { intent, rightIcon, onRemove, hasActive };\n}\n\nfunction useFilterMenuAction(entries: FilterEntry[]): TableAction | null {\n // Scoped to the filters this menu actually holds. An `\"inline\"` filter has\n // its own always-visible control, so it must not light up the Filter tag —\n // nor be wiped by its clear button, which reads as \"clear the filters in\n // here\".\n const rest = useDisplayIntent(useFilterSubsetState(entries));\n\n if (entries.length === 0) return null;\n\n const filterMenu = h(\n Menu,\n entries.map(({ filter, label }) => {\n // A `menu-inline` filter renders its form directly in the menu (no\n // submenu); the default `menu` presentation uses the submenu item.\n if (presentationOf(filter) === \"menu-inline\") {\n return h(MenuInlineFilterItem, { key: filter.id, filter, label });\n }\n return h(ColumnFilterMenuItem, { key: filter.id, filter, label });\n }),\n );\n\n const filterIndicator = h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"filter\",\n ...rest,\n },\n \"Filter\",\n );\n\n return {\n id: \"filter\",\n name: \"Filter\",\n icon: \"filter\",\n description: \"Add a filter to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(\n MenuDropdown,\n {\n content: filterMenu,\n placement: \"bottom-start\",\n },\n [filterIndicator],\n ),\n };\n}\n\nfunction useSortAction(): TableAction | null {\n const columnSpec = useSelector((s) => s.columnSpec);\n\n const rest = useDisplayIntent(ctx.use(hasActiveSortsAtom));\n\n const sortableCols = useMemo(\n () => columnSpec.filter((c) => c.sortable),\n [columnSpec],\n );\n\n if (sortableCols.length == 0) {\n return null;\n }\n const sortMenu = h(\n Menu,\n sortableCols.map((col) =>\n h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),\n ),\n );\n\n return {\n id: \"sort\",\n name: \"Sort\",\n icon: \"sort\",\n description: \"Add a sort to the data panel.\",\n targets: ALL_CARDINALITIES,\n render: (ctx) =>\n h(MenuDropdown, { content: sortMenu }, [\n h(\n Tag,\n {\n minimal: true,\n large: true,\n icon: \"sort\",\n ...rest,\n },\n \"Sort\",\n ),\n ]),\n };\n}\n\n// Both of these clear through the store's *actions* rather than writing the\n// state directly: the actions are what also drop a now-meaningless row\n// selection (see `dropRowSelection`).\nconst hasActiveFiltersAtom = atom(\n (get) => (get(storeAtom)?.activeFilters?.size ?? 0) > 0,\n (get) => {\n get(storeAtom)?.clearFilters?.();\n },\n);\nconst hasActiveSortsAtom = atom(\n (get) => (get(storeAtom)?.columnSorts?.length ?? 0) > 0,\n (get) => {\n get(storeAtom)?.clearColumnSorts?.();\n },\n);\n"],"names":["ctx"],"mappings":";;;;;;;;;;AAoDO,SAAS,qBACd,eAA8B,IAC9B,eAAyC,UAC1B;AACf,QAAM,aAAa,YAAY,CAAC,MAAM,EAAE,UAAU;AAGlD,QAAM,UAAU,QAAuB,MAAM;AAC3C,UAAM,cAAc,WACjB,OAAO,CAAC,MAAM,mBAAmB,CAAC,CAAC,EACnC,IAAI,CAAC,OAAO,EAAE,QAAQ,oBAAoB,CAAC,GAAG,OAAO,EAAE,OAAO;AACjE,UAAM,YAAY,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,EAAE,KAAA,EAAO;AACxE,WAAO,CAAC,GAAG,WAAW,GAAG,WAAW;AAAA,EACtC,GAAG,CAAC,YAAY,YAAY,CAAC;AAE7B,QAAM,gBAAgB,QAAQ;AAAA,IAC5B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;AAAA,EAAA;AAEtC,QAAM,cAAc,QAAQ;AAAA,IAC1B,CAAC,MAAM,eAAe,EAAE,MAAM,MAAM;AAAA,EAAA;AAItC,QAAM,mBAAmB,oBAAoB,WAAW;AACxD,QAAM,aAAa,cAAA;AACnB,QAAM,kBAAkB,2BAA2B,OAAO;AAC1D,QAAM,sBAAsB,uBAAA;AAO5B,MAAI,uBAAuB,KAAM,QAAO,CAAC,mBAAmB;AAI5D,MAAI,iBAAiB,aAAa,mBAAmB,MAAM;AACzD,WAAO,CAAC,eAAe;AAAA,EACzB;AAEA,QAAM,UAAyB,CAAA;AAE/B,aAAW,EAAE,OAAA,KAAY,eAAe;AACtC,YAAQ,KAAK;AAAA,MACX,IAAI,UAAU,OAAO,EAAE;AAAA,MACvB,MA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,CAACA,SACP,EAAE,cAAc,EAAE,SAAS,YAAY;AAAA,MACrC;AAAA,QACE;AAAA,QACA;AAAA,UACE,SAAS;AAAA,UACT,OAAO;AAAA,UACP,MAAM;AAAA,UACN,GAAG;AAAA,QAAA;AAAA,QAEL;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EAAA;AAEP;AAKA,MAAM,uBAAuB;AAAA,EAC3B,CAAC,SAAS,IAAI,SAAS,GAAG,eAAe,QAAQ,KAAK;AAAA,EACtD,CAAC,QAAQ;AACP,QAAI,SAAS,GAAG,eAAA;AAAA,EAClB;AACF;AACA,MAAM,qBAAqB;AAAA,EACzB,CAAC,SAAS,IAAI,SAAS,GAAG,aAAa,UAAU,KAAK;AAAA,EACtD,CAAC,QAAQ;AACP,QAAI,SAAS,GAAG,mBAAA;AAAA,EAClB;AACF;"}
@@ -40,6 +40,7 @@ function DataPanelRenderer({
40
40
  filters = [],
41
41
  pageSize = 50,
42
42
  filterDebounce,
43
+ initialData,
43
44
  name,
44
45
  // Bottom bar
45
46
  statusBar,
@@ -142,7 +143,8 @@ function DataPanelRenderer({
142
143
  fetchData: activeProvider.fetchData,
143
144
  pageSize: loaderPageSize,
144
145
  fetchMode: isLocalProvider ? void 0 : "scroll",
145
- filterDebounce
146
+ filterDebounce,
147
+ initialData
146
148
  });
147
149
  }
148
150
  const coreActions = unifiedFilters.useDataPanelControls(filters, viewControls);
@@ -1 +1 @@
1
- {"version":3,"file":"data-panel.cjs","sources":["../src/data-panel.ts"],"sourcesContent":["/**\n * DataPanel — a card/list renderer over the same headless core as `DataSheet`.\n *\n * The two components differ in only two dimensions: the **view** (cards vs. the\n * Blueprint cell grid) and **edit granularity** (immediate per-item vs. a\n * batched pending-ops stack). Everything else — provider-driven windowed\n * loading, `{sorts, filters}` view state, the selection set, and set-based\n * actions — is the shared substrate, reused here unchanged:\n *\n * - `DataSheetProvider` supplies the jotai+zustand store.\n * - `useDataLoader(provider.fetchData)` drives windowed loading and threads the\n * active store sorts/filters through so a server provider applies them.\n * - `ActionsToolbar` + `FilterBar` render selection-aware actions and the\n * active sort/filter tags — they read the store, not the table.\n *\n * The only list-specific pieces are: rows rendered as cards via a consumer\n * `itemComponent`; selection expressed as `FULL_ROWS` regions (so the existing\n * row-targeted `TableAction`s apply); an infinite-scroll sentinel that advances\n * the loader's visible region; and `FacetControls`, which stands in for the\n * column-header dropdown the list doesn't have (a menu to add a column filter /\n * sort from the column-declared `filterable` / `sortable` capabilities).\n *\n * See [[Data list editors]] in the Macrostrat workbench for the design.\n */\nimport h from \"./data-panel.module.sass\";\nimport {\n ComponentType,\n CSSProperties,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n UIEvent as ReactUIEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Classes, Icon, NonIdealState, Spinner } from \"@blueprintjs/core\";\nimport {\n anchorRefAtom,\n ctx,\n dataProviderAtom,\n DataSheetProvider,\n DataViewRendererType,\n FetchData,\n enableSelectionAtom,\n interactionOptionsAtom,\n selectionAtom,\n splitDataProviderProps,\n useSelector,\n} from \"./provider\";\nimport {\n buildDataViewSelection,\n getSelectedRowIndices,\n rowIndicesToRegions,\n TableAction,\n} from \"./actions\";\nimport {\n autoLoadPagesAtom,\n useDataLoader,\n useLoadControls,\n} from \"./postgrest-table\";\nimport classNames from \"classnames\";\nimport {\n ActionsToolbar,\n LoadProgressIndicator,\n useDataPanelControls,\n type ViewControlsPresentation,\n} from \"./components\";\nimport { DataViewSharedProps, FetchDataOptions } from \"./types\";\nimport { atom } from \"jotai\";\nimport { passThroughSet } from \"./utils\";\n\nexport enum DataPanelToolbarStyle {\n BORDERED = \"bordered\",\n FADE = \"fade\",\n MINIMAL = \"minimal\",\n /** Toolbar (and footer) sized to their contents and lifted over the scroll\n * body, rather than occupying a full-width band. Pairs with\n * `viewControls: \"popover\"`, since inline controls cost real space here. */\n FLOATING = \"floating\",\n}\n\n/** Props for a custom scroll-body layout component. It receives the\n * already-rendered, selection-wrapped item cards and lays them out however it\n * likes (a grid, sections, sticky headers, its own windowing). The panel owns\n * the surrounding scroll container and the loading sentinel; the scroll body\n * only arranges the items. */\nexport interface ScrollBodyProps {\n /** The rendered item cards (each wrapped for selection styling). */\n children: ReactNode;\n}\n\n/** Props handed to a consumer's card renderer for one row. */\nexport interface ItemComponentProps<T = any> {\n /** The row's data. */\n data: T;\n /** Underlying data-row index (stable within a loaded window). */\n index: number;\n /** Whether this row is in the current selection. */\n selected: boolean;\n /** Whether the row can be selected */\n selectable: boolean;\n /** Select this row. Pass the click's `MouseEvent` (or `React.MouseEvent`) to\n * honor shift / cmd / ctrl automatically — the usual wiring is\n * `onClick: onSelect`. Or pass an explicit `SelectModifiers` object; no\n * argument means a plain (replace) select. */\n onSelect: (arg?: SelectModifiers | ReactMouseEvent) => void;\n}\n\nexport interface DataPanelProps<T = any> extends DataViewSharedProps<T> {\n /** Renders one row as a card. */\n itemComponent: ComponentType<ItemComponentProps<T>>;\n /** Arbitrary nodes for the bottom status row (beside the loaded/total\n * counter). Pass `false` to drop the status row entirely — e.g. when the\n * counter is folded into an inline footer instead. */\n statusBar?: ReactNode | false;\n /** Custom header controls, replacing the default `FacetControls` +\n * `FilterBar`. Rendered inside the provider, so it can drive sort/filter via\n * the exported building blocks (`FacetControls`, `FilterBar`) and the store\n * hooks (`useStoreAPI` / `useSelector`). The selection `ActionsToolbar` still\n * renders above it. Omit for the sane default. */\n toolbar?: ReactNode;\n /** A filter/detail sidebar beside the scroll body (its own scroll). Rendered\n * inside the provider, so a custom filter panel drives sort/filter through\n * the store hooks — the alternative placement to the top `toolbar`. */\n sidebar?: ReactNode;\n /** Footer content. Rendered inside the provider, so it reads live load state\n * from the store via `useLoadControls()` (loadMore / loading / hasMore /\n * loaded / total / paused) rather than a passed-down contract — a footer, a\n * status line, or a \"Load more\" button all just call the hook. */\n contentFooter?: ReactNode;\n /** Auto-load this many pages per burst, then pause: a paused panel stops\n * fetching on scroll until `useLoadControls().loadMore()` starts the next\n * burst (e.g. a footer \"Load more\" button). Omit for unbounded auto-scroll. */\n // TODO: we may deprecate this for opt-in scrolling\n autoLoadPages?: number;\n /** Custom layout for the item cards — the seam for anything other than a\n * vertical list (a CSS grid for several per row, grouped sections, sticky\n * sub-headers, a windowed renderer). Receives the rendered cards as\n * `children`; the panel still owns the scroll container and the loading\n * sentinel, so paging and selection keep working. Defaults to a vertical\n * flex list. */\n scrollBody?: ComponentType<ScrollBodyProps>;\n className?: string;\n toolbarStyle?: DataPanelToolbarStyle | string;\n /** Where the built-in view controls (inline filters, Filter menu, Sort menu)\n * sit in the toolbar: `\"inline\"` (default) places each in the toolbar;\n * `\"popover\"` collapses all of them behind a single button — for a narrow or\n * deliberately chrome-light toolbar. Same controls and state either way.\n * Ignored while a modal view is selecting: the toolbar then carries a single\n * control that leaves select mode. */\n viewControls?: ViewControlsPresentation;\n /** Arbitrary children rendered inside the provider, after the panel. */\n children?: ReactNode;\n}\n\n/**\n * Resolve the data source (shared with `DataSheet` / `DataView` via\n * `useResolvedProvider`), wrap in the shared provider, and render the inner\n * panel.\n */\nexport function DataPanel<T>(props: DataPanelProps<T>) {\n const [providerProps, rendererProps] = splitDataProviderProps({\n ...props,\n viewType: DataViewRendererType.CARDS,\n });\n return h(\n DataSheetProvider<T>,\n providerProps,\n h(DataPanelRenderer<any>, rendererProps),\n );\n}\n\n/** Selection modifier keys, following the familiar list idiom. */\nexport interface SelectModifiers {\n /** cmd/ctrl — toggle this row in/out of the selection (or extend a range). */\n additive?: boolean;\n /** shift — select the range from the anchor (last plain/cmd click) to here. */\n range?: boolean;\n}\n\n/** The card-list renderer. Assumes it is rendered inside a `DataSheetProvider`\n * (the `DataPanel` wrapper, or `DataView`). Exported so a shared-store\n * `DataView` can mount it directly alongside `_DataSheet`. */\nexport function DataPanelRenderer<T>({\n itemComponent,\n actions = [],\n filters = [],\n pageSize = 50,\n filterDebounce,\n name,\n // Bottom bar\n statusBar,\n toolbar,\n sidebar,\n // Footer within content flow\n contentFooter,\n autoLoadPages,\n scrollBody,\n className,\n toolbarStyle = DataPanelToolbarStyle.BORDERED,\n viewControls = \"inline\",\n children,\n}: Omit<DataPanelProps<T>, \"provider\" | \"fetchData\" | \"data\" | \"identity\">) {\n const {\n provider: activeProvider,\n isLocalProvider,\n localCount,\n } = ctx.useValue(dataProviderAtom);\n\n // The loader is mounted as a child component (below), NOT called as a hook\n // here, and only once `activeProvider` resolves. This mirrors `_DataSheet`:\n // `dataProviderAtom` is synced by a parent effect that fires *after* this\n // component's effects, so a hook call here would capture the placeholder\n // provider on first render and — since `fetchData` isn't one of its effect\n // deps — never re-fetch with the real one. A child that mounts with the real\n // `fetchData` already in hand sidesteps that entirely.\n // A local (in-memory) source loads all of its rows in one page; its count\n // rides on the resolved provider, so the renderer no longer takes a `data`\n // prop (the store is the single source of live rows).\n const loaderPageSize = isLocalProvider ? Math.max(localCount, 1) : pageSize;\n\n const data = useSelector((s) => s.data);\n\n // Load state + pause/resume live in the store, read via `useLoadControls`\n // (also available to the caller's `footer` via the same hook). The panel's\n // `autoLoadPages` prop is the store's configuration input.\n ctx.useSync(autoLoadPagesAtom, autoLoadPages ?? null);\n const {\n loading,\n initialized,\n error,\n hasMore,\n loaded,\n total,\n paused,\n canLoadMore,\n advance,\n } = useLoadControls();\n\n // Track whether the body is scrolled off the top, to gate the top fade.\n // `setState` with an unchanged value is a no-op, so this only re-renders on\n // the at-top ↔ scrolled transition.\n const [scrolled, setScrolled] = useState(false);\n const onScroll = useCallback((e: ReactUIEvent<HTMLDivElement>) => {\n setScrolled(e.currentTarget.scrollTop > 4);\n }, []);\n\n const enableSelection = ctx.useValue(enableSelectionAtom);\n const selectedIndices = ctx.useValue(selectedRowIndicesAtom);\n const select = ctx.useSet(updateSelectionAtom);\n\n const loadedCount = useMemo(() => {\n let n = 0;\n for (const r of data) if (r != null) n++;\n return n;\n }, [data]);\n\n // Refresh-token, rowEditing, and load controls (loadMore / pause) are all\n // store-managed (see `useLoadControls`), shared with `_DataSheet` — so both\n // renderers, and any footer, drive loading off one source.\n\n // Infinite scroll. A naive \"load a page when the bottom sentinel is visible\"\n // over-fetches: when a page's rows commit, this component re-renders\n // (loadedCount changed) *before* the IntersectionObserver has re-evaluated\n // the sentinel's new position, so a stale \"still visible\" fires a second\n // load. `useBottomSentinel` re-observes the sentinel whenever the pass-through\n // deps change, so every trigger reflects the *current* post-layout\n // visibility — it loads one page, and only loads another if the sentinel is\n // genuinely still on screen. `advance` (from the store) moves the loader one\n // page without resuming a paused auto-load.\n const sentinelRef = useBottomSentinel(canLoadMore ? advance : null, [\n loadedCount,\n canLoadMore,\n ]);\n\n const cards: ReactNode[] = [];\n data.forEach((row, i) => {\n if (row == null) return;\n const selected = enableSelection && selectedIndices.has(i);\n cards.push(\n h(\n \"div.data-panel-item-container\",\n { key: `item-${i}`, className: classNames({ selected }) },\n h(itemComponent, {\n data: row,\n index: i,\n selected,\n selectable: enableSelection,\n onSelect: (arg?: SelectModifiers | ReactMouseEvent) =>\n select(i, modifiersOf(arg)),\n }),\n ),\n );\n });\n\n // Body-level empty/error state: when nothing has loaded, show a clear message\n // instead of a blank list — an errored source (e.g. a 401 on the whole route)\n // degrades gracefully, and a genuinely empty result reads as \"no results\"\n // rather than a perpetual spinner.\n // A load is pending whenever a fetch is in flight OR the view was just reset\n // and hasn't fetched yet (`!initialized`) — the window that would otherwise\n // flash \"No results\" before the request starts.\n const loadPending = (loading || !initialized) && error == null;\n\n let emptyState: ReactNode = null;\n if (cards.length === 0) {\n if (error != null) {\n emptyState = h(NonIdealState, {\n icon: \"error\",\n title: \"Couldn't load data\",\n description: error.message ?? \"The data source returned an error.\",\n });\n } else if (initialized && !loading) {\n // Only after a fetch settled with no rows — not during the reset gap.\n emptyState = h(NonIdealState, {\n icon: \"search\",\n title: \"No results\",\n });\n }\n }\n\n // Skeleton placeholders for the page being fetched — on a view change (the\n // reset pre-sizes to a page of `null` slots) or the next scroll page — so the\n // body shows shimmer where rows will land instead of a blank flash or a\n // footer pinging up into the gap. Bounded to a viewport's worth of cards.\n if (loadPending) {\n const pending = Math.min(Math.max(data.length - loadedCount, 0), 24);\n for (let i = 0; i < pending; i++) {\n cards.push(\n h(\n \"div.data-panel-item-container.is-skeleton\",\n { key: `skeleton-${i}`, \"aria-hidden\": true },\n h(\"div.data-panel-skeleton\", { className: Classes.SKELETON }),\n ),\n );\n }\n }\n\n // The default spinner sentinel (below-placement): hidden while paused so the\n // pinned footer's \"Load more\" takes over.\n const shouldLoadNextPage = (hasMore || loading) && !paused && error == null;\n\n // Mount the loader only once the provider resolves (see `PanelLoader`). Built\n // as a real conditional — `h.if(...)` evaluates its arguments eagerly, so\n // `activeProvider.fetchData` can't be referenced inside it while null.\n let loaderNode: ReactNode = null;\n if (activeProvider != null) {\n loaderNode = h(PanelLoader, {\n fetchData: activeProvider.fetchData,\n pageSize: loaderPageSize,\n fetchMode: isLocalProvider ? undefined : \"scroll\",\n filterDebounce,\n });\n }\n\n const coreActions = useDataPanelControls(filters, viewControls);\n\n // Merge consumer actions with the synthesized Filter/Sort controls, deduped\n // by id — consumer actions come first, so passing an action with id `filter`\n // or `sort` *replaces* the built-in one (a hybrid set keeps the others).\n // Mirrors the sheet's action registry contract (see `data-sheet.ts`).\n const _actions = useMemo(() => {\n const merged: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!merged.some((x) => x.id === a.id)) merged.push(a);\n }\n };\n add(actions);\n add(coreActions);\n return merged;\n }, [actions, coreActions]);\n\n const ScrollBody = scrollBody ?? DefaultScrollBody;\n\n // The panel owns the scroll container + the loading sentinel; the (custom or\n // default) scroll body only lays out the cards. So a grid / grouped / windowed\n // body composes without reimplementing paging or selection. The end-of-scroll\n // region is either the default spinner sentinel or the caller's inline\n // footer — both carry the sentinel ref that drives auto-load.\n // The top fade is gated on being scrolled (via `.is-scrolled`), so the first\n // item isn't clipped at rest.\n\n const showStatusBar = statusBar !== false;\n\n let defaultFooter: ReactNode = null;\n if (shouldLoadNextPage) {\n defaultFooter = h(\"div.sentinel\", [h(Spinner, { size: 16 }), \"Loading...\"]);\n } else if (!showStatusBar) {\n defaultFooter = h(\"div.sentinel\", [\n h(Icon, { size: 16, icon: \"tick\" }),\n \"Loaded\",\n ]);\n }\n\n const _contentFooter = h(\n \"div.content-footer-holder\",\n { ref: sentinelRef },\n contentFooter ?? defaultFooter,\n );\n\n // Body + optional filter/detail sidebar share a horizontal row so each\n // scrolls independently.\n\n // Bottom status row (counter + extras). `statusBar === false` drops it — e.g.\n // when an inline footer carries the counter itself.\n let footer: ReactNode = null;\n let _statusBarContent = statusBar ?? h(DataPanelStatusBar);\n if (showStatusBar) {\n footer = h(\n \"div.data-panel-footer\",\n h(\"div.data-panel-footer-content\", [_statusBarContent]),\n );\n }\n\n return h(\n \"div.data-panel\",\n { className: classNames(className, \"toolbar-style-\" + toolbarStyle) },\n [\n h(\"div.data-panel-main\", [\n loaderNode,\n h(\n \"div.data-panel-toolbar\",\n h(\n ActionsToolbar,\n {\n actions: _actions,\n tableName: name,\n className: \"data-panel-toolbar-content\",\n // In the panel the title doubles as the modal-selection control,\n // so only render it when modal selection is toggle-able (or a\n // selection is active) — not as a bare label otherwise.\n compact: true,\n },\n toolbar,\n ),\n ),\n h(\n \"div.data-panel-body\",\n {\n onScroll,\n className: classNames({ \"is-scrolled\": scrolled }),\n },\n h(\"div.data-panel-body-content\", [\n emptyState ?? h(ScrollBody, cards),\n _contentFooter,\n ]),\n ),\n footer,\n ]),\n h.if(sidebar != null)(\"div.data-panel-sidebar-container\", sidebar),\n children,\n ],\n );\n}\n\nfunction DataPanelStatusBar({ children }) {\n /** Default status bar for the Data Panel */\n return h(\"div.data-panel-status-bar\", [children, h(LoadProgressIndicator)]);\n}\n\n/** Default scroll-body layout: a vertical flex list of cards. */\nfunction DefaultScrollBody({ children }: { children: ReactNode }) {\n return h(\"div.data-panel-list\", children);\n}\n\n/** Runs the shared windowed loader from inside the panel (renders nothing).\n * Mounted only once the real provider is resolved, so `useDataLoader` captures\n * the real `fetchData` from the start (see `_DataPanel`). */\nfunction PanelLoader<T = any>({\n fetchData,\n ...options\n}: { fetchData: FetchData<T> } & FetchDataOptions) {\n useDataLoader(fetchData, options);\n return null;\n}\n\n/** Resolve the selection modifiers from either a click event (reads shift /\n * cmd / ctrl) or an explicit modifier object; no argument ⇒ a plain select. */\nfunction modifiersOf(arg?: SelectModifiers | ReactMouseEvent): SelectModifiers {\n if (arg == null) return {};\n if (\"shiftKey\" in arg) {\n return { additive: arg.metaKey || arg.ctrlKey, range: arg.shiftKey };\n }\n return arg;\n}\n\n/**\n * Bottom-sentinel infinite-scroll hook (no `react-intersection-observer`\n * dependency). Calls `onVisible` when the observed element is on screen, and —\n * crucially — **re-observes on every `deps` change** so the callback reflects\n * the *current* post-layout visibility rather than the pre-load render.\n *\n * This is what avoids the double-load: a plain observer whose visibility is\n * mirrored into React state lags a render behind the DOM, so a load-driven\n * re-render fires a second `onVisible` before the observer catches up. By\n * re-arming after each load (`deps = [loadedCount, canLoadMore]`), the observer\n * emits a fresh callback for the settled layout: it fires again only if the\n * sentinel is *still* visible (viewport not yet filled), so it loads exactly\n * one page per bottom-reach and self-fills an underfull viewport without\n * overshooting. Pass `onVisible = null` to disarm (loading / no more data).\n */\nfunction useBottomSentinel<E extends HTMLElement>(\n onVisible: (() => void) | null,\n deps: unknown[],\n): (el: E | null) => void {\n const elRef = useRef<E | null>(null);\n const observerRef = useRef<IntersectionObserver | null>(null);\n const cbRef = useRef(onVisible);\n cbRef.current = onVisible;\n\n const setRef = useCallback((el: E | null) => {\n elRef.current = el;\n observerRef.current?.disconnect();\n observerRef.current = null;\n if (el == null) return;\n const observer = new IntersectionObserver(\n ([entry]) => {\n if (entry.isIntersecting) cbRef.current?.();\n },\n { rootMargin: \"300px\" },\n );\n observer.observe(el);\n observerRef.current = observer;\n }, []);\n\n // Re-arm after each load so the observer re-checks the settled layout.\n useEffect(() => {\n const el = elRef.current;\n const observer = observerRef.current;\n if (el == null || observer == null) return;\n observer.disconnect();\n observer.observe(el);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n useEffect(() => () => observerRef.current?.disconnect(), []);\n return setRef;\n}\n\nconst rowSelectionAtom = atom((get) => {\n /** Coerce selection to full rows, for use with data panel instead of data sheet. */\n const selection = get(selectionAtom);\n if (selection.some((r) => r.cols != null)) {\n // A card list has no cells or columns. When the selection carries columns —\n // inherited from a shared store the sheet also drives (a `DataView` toggle) —\n // coerce it to the full rows it covers, so the toolbar shows row-scoped\n // actions rather than column/cell ones for a column that isn't visible here.\n // Column-only selections (no rows) collapse to nothing.\n return rowIndicesToRegions(new Set(getSelectedRowIndices(selection)));\n } else {\n return selection;\n }\n}, passThroughSet(selectionAtom));\n\nconst updateSelectionAtom = atom(\n null,\n (get, set, index: number, mods: SelectModifiers) => {\n /** Update selection from a row index and modifiers. */\n const { enableMultipleSelection, enableModalSelection } = get(\n interactionOptionsAtom,\n );\n let enableSelection = get(enableSelectionAtom);\n if (!enableSelection) {\n // Cmd/ctrl-click *enters* select mode on a modal view and selects the\n // row, the familiar list idiom — so a bulk action doesn't require finding\n // the Select control first. The flag is read back below rather than\n // trusted from this scope: the write goes through the store synchronously.\n if (!enableModalSelection || !mods.additive) return;\n set(enableSelectionAtom, true);\n enableSelection = get(enableSelectionAtom);\n if (!enableSelection) return;\n }\n const selection = get(rowSelectionAtom);\n const anchorRef = get(anchorRefAtom);\n const res = buildDataViewSelection(\n index,\n mods,\n selection,\n anchorRef,\n enableMultipleSelection,\n );\n set(selectionAtom, res);\n },\n);\n\nconst selectedRowIndicesAtom = atom((get) => {\n const sel = get(selectionAtom);\n return new Set(getSelectedRowIndices(sel));\n});\n\ntype ItemSelectionKeys = \"onSelect\" | \"selected\" | \"selectable\";\n\ntype DataCardProps = {\n children: ReactNode;\n className: string;\n style?: CSSProperties;\n} & Pick<ItemComponentProps, ItemSelectionKeys>;\n\nexport function DataCard<T = any>(props: DataCardProps) {\n /** A basic card that implements the data panel's selection behavior. */\n return h(\n \"div.data-card.data-panel-item\",\n {\n className: classNames(props.className, {\n selected: props.selected,\n selectable: props.selectable,\n }),\n onClick: props.onSelect,\n style: props.style,\n },\n props.children,\n );\n}\n\ntype DataCardInnerComponent<T> = (\n props: ItemComponentProps<T>,\n) => React.ReactNode;\n\nexport function createDataCard<T>(\n component: DataCardInnerComponent<T>,\n extraProps = {},\n) {\n return (props: ItemComponentProps<T>) => {\n const { selected, selectable, onSelect } = props;\n return h(\n DataCard,\n {\n selected,\n selectable,\n onSelect,\n ...extraProps,\n },\n h(component, props),\n );\n };\n}\n"],"names":["DataPanelToolbarStyle","splitDataProviderProps","DataViewRendererType","h","DataSheetProvider","ctx","dataProviderAtom","useSelector","autoLoadPagesAtom","useLoadControls","useState","useCallback","enableSelectionAtom","useMemo","classNames","NonIdealState","Classes","useDataPanelControls","Spinner","Icon","ActionsToolbar","LoadProgressIndicator","useDataLoader","useRef","useEffect","atom","selection","selectionAtom","rowIndicesToRegions","getSelectedRowIndices","passThroughSet","interactionOptionsAtom","anchorRefAtom","buildDataViewSelection"],"mappings":";;;;;;;;;;;;;;;;;;AAyEO,IAAK,0CAAAA,2BAAL;AACLA,yBAAA,UAAA,IAAW;AACXA,yBAAA,MAAA,IAAO;AACPA,yBAAA,SAAA,IAAU;AAIVA,yBAAA,UAAA,IAAW;AAPD,SAAAA;AAAA,GAAA,yBAAA,CAAA,CAAA;AAyFL,SAAS,UAAa,OAA0B;AACrD,QAAM,CAAC,eAAe,aAAa,IAAIC,4BAAuB;AAAA,IAC5D,GAAG;AAAA,IACH,UAAUC,aAAAA,qBAAqB;AAAA,EAAA,CAChC;AACD,SAAOC,iBAAAA;AAAAA,IACLC,KAAAA;AAAAA,IACA;AAAA,IACAD,iBAAAA,QAAE,mBAAwB,aAAa;AAAA,EAAA;AAE3C;AAaO,SAAS,kBAAqB;AAAA,EACnC;AAAA,EACA,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,WAAW;AAAA,EACX;AAAA,EAC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AAEF,QAAI,kBAAkB,IAAInB,gCAAmB;AAC7C,QAAI,CAAC,iBAAiB;AAKpB,UAAI,CAAC,wBAAwB,CAAC,KAAK,SAAU;AAC7C,UAAIA,aAAAA,qBAAqB,IAAI;AAC7B,wBAAkB,IAAIA,gCAAmB;AACzC,UAAI,CAAC,gBAAiB;AAAA,IACxB;AACA,UAAMc,cAAY,IAAI,gBAAgB;AACtC,UAAM,YAAY,IAAIM,uBAAa;AACnC,UAAM,MAAMC,YAAAA;AAAAA,MACV;AAAA,MACA;AAAA,MACAP;AAAAA,MACA;AAAA,MACA;AAAA,IAAA;AAEF,QAAIC,UAAAA,eAAe,GAAG;AAAA,EACxB;AACF;AAEA,MAAM,yBAAyBF,MAAAA,KAAK,CAAC,QAAQ;AAC3C,QAAM,MAAM,IAAIE,uBAAa;AAC7B,SAAO,IAAI,IAAIE,kCAAsB,GAAG,CAAC;AAC3C,CAAC;AAUM,SAAS,SAAkB,OAAsB;AAEtD,SAAO1B,iBAAAA;AAAAA,IACL;AAAA,IACA;AAAA,MACE,WAAWW,oBAAAA,QAAW,MAAM,WAAW;AAAA,QACrC,UAAU,MAAM;AAAA,QAChB,YAAY,MAAM;AAAA,MAAA,CACnB;AAAA,MACD,SAAS,MAAM;AAAA,MACf,OAAO,MAAM;AAAA,IAAA;AAAA,IAEf,MAAM;AAAA,EAAA;AAEV;AAMO,SAAS,eACd,WACA,aAAa,IACb;AACA,SAAO,CAAC,UAAiC;AACvC,UAAM,EAAE,UAAU,YAAY,SAAA,IAAa;AAC3C,WAAOX,iBAAAA;AAAAA,MACL;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MAAA;AAAA,MAELA,iBAAAA,QAAE,WAAW,KAAK;AAAA,IAAA;AAAA,EAEtB;AACF;;;;;;"}
1
+ {"version":3,"file":"data-panel.cjs","sources":["../src/data-panel.ts"],"sourcesContent":["/**\n * DataPanel — a card/list renderer over the same headless core as `DataSheet`.\n *\n * The two components differ in only two dimensions: the **view** (cards vs. the\n * Blueprint cell grid) and **edit granularity** (immediate per-item vs. a\n * batched pending-ops stack). Everything else — provider-driven windowed\n * loading, `{sorts, filters}` view state, the selection set, and set-based\n * actions — is the shared substrate, reused here unchanged:\n *\n * - `DataSheetProvider` supplies the jotai+zustand store.\n * - `useDataLoader(provider.fetchData)` drives windowed loading and threads the\n * active store sorts/filters through so a server provider applies them.\n * - `ActionsToolbar` + `FilterBar` render selection-aware actions and the\n * active sort/filter tags — they read the store, not the table.\n *\n * The only list-specific pieces are: rows rendered as cards via a consumer\n * `itemComponent`; selection expressed as `FULL_ROWS` regions (so the existing\n * row-targeted `TableAction`s apply); an infinite-scroll sentinel that advances\n * the loader's visible region; and `FacetControls`, which stands in for the\n * column-header dropdown the list doesn't have (a menu to add a column filter /\n * sort from the column-declared `filterable` / `sortable` capabilities).\n *\n * See [[Data list editors]] in the Macrostrat workbench for the design.\n */\nimport h from \"./data-panel.module.sass\";\nimport {\n ComponentType,\n CSSProperties,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n UIEvent as ReactUIEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Classes, Icon, NonIdealState, Spinner } from \"@blueprintjs/core\";\nimport {\n anchorRefAtom,\n ctx,\n dataProviderAtom,\n DataSheetProvider,\n DataViewRendererType,\n FetchData,\n enableSelectionAtom,\n interactionOptionsAtom,\n selectionAtom,\n splitDataProviderProps,\n useSelector,\n} from \"./provider\";\nimport {\n buildDataViewSelection,\n getSelectedRowIndices,\n rowIndicesToRegions,\n TableAction,\n} from \"./actions\";\nimport {\n autoLoadPagesAtom,\n useDataLoader,\n useLoadControls,\n} from \"./postgrest-table\";\nimport classNames from \"classnames\";\nimport {\n ActionsToolbar,\n LoadProgressIndicator,\n useDataPanelControls,\n type ViewControlsPresentation,\n} from \"./components\";\nimport { DataViewSharedProps, FetchDataOptions } from \"./types\";\nimport { atom } from \"jotai\";\nimport { passThroughSet } from \"./utils\";\n\nexport enum DataPanelToolbarStyle {\n BORDERED = \"bordered\",\n FADE = \"fade\",\n MINIMAL = \"minimal\",\n /** Toolbar (and footer) sized to their contents and lifted over the scroll\n * body, rather than occupying a full-width band. Pairs with\n * `viewControls: \"popover\"`, since inline controls cost real space here. */\n FLOATING = \"floating\",\n}\n\n/** Props for a custom scroll-body layout component. It receives the\n * already-rendered, selection-wrapped item cards and lays them out however it\n * likes (a grid, sections, sticky headers, its own windowing). The panel owns\n * the surrounding scroll container and the loading sentinel; the scroll body\n * only arranges the items. */\nexport interface ScrollBodyProps {\n /** The rendered item cards (each wrapped for selection styling). */\n children: ReactNode;\n}\n\n/** Props handed to a consumer's card renderer for one row. */\nexport interface ItemComponentProps<T = any> {\n /** The row's data. */\n data: T;\n /** Underlying data-row index (stable within a loaded window). */\n index: number;\n /** Whether this row is in the current selection. */\n selected: boolean;\n /** Whether the row can be selected */\n selectable: boolean;\n /** Select this row. Pass the click's `MouseEvent` (or `React.MouseEvent`) to\n * honor shift / cmd / ctrl automatically — the usual wiring is\n * `onClick: onSelect`. Or pass an explicit `SelectModifiers` object; no\n * argument means a plain (replace) select. */\n onSelect: (arg?: SelectModifiers | ReactMouseEvent) => void;\n}\n\nexport interface DataPanelProps<T = any> extends DataViewSharedProps<T> {\n /** Renders one row as a card. */\n itemComponent: ComponentType<ItemComponentProps<T>>;\n /** Arbitrary nodes for the bottom status row (beside the loaded/total\n * counter). Pass `false` to drop the status row entirely — e.g. when the\n * counter is folded into an inline footer instead. */\n statusBar?: ReactNode | false;\n /** Custom header controls, replacing the default `FacetControls` +\n * `FilterBar`. Rendered inside the provider, so it can drive sort/filter via\n * the exported building blocks (`FacetControls`, `FilterBar`) and the store\n * hooks (`useStoreAPI` / `useSelector`). The selection `ActionsToolbar` still\n * renders above it. Omit for the sane default. */\n toolbar?: ReactNode;\n /** A filter/detail sidebar beside the scroll body (its own scroll). Rendered\n * inside the provider, so a custom filter panel drives sort/filter through\n * the store hooks — the alternative placement to the top `toolbar`. */\n sidebar?: ReactNode;\n /** Footer content. Rendered inside the provider, so it reads live load state\n * from the store via `useLoadControls()` (loadMore / loading / hasMore /\n * loaded / total / paused) rather than a passed-down contract — a footer, a\n * status line, or a \"Load more\" button all just call the hook. */\n contentFooter?: ReactNode;\n /** Auto-load this many pages per burst, then pause: a paused panel stops\n * fetching on scroll until `useLoadControls().loadMore()` starts the next\n * burst (e.g. a footer \"Load more\" button). Omit for unbounded auto-scroll. */\n // TODO: we may deprecate this for opt-in scrolling\n autoLoadPages?: number;\n /** Custom layout for the item cards — the seam for anything other than a\n * vertical list (a CSS grid for several per row, grouped sections, sticky\n * sub-headers, a windowed renderer). Receives the rendered cards as\n * `children`; the panel still owns the scroll container and the loading\n * sentinel, so paging and selection keep working. Defaults to a vertical\n * flex list. */\n scrollBody?: ComponentType<ScrollBodyProps>;\n className?: string;\n toolbarStyle?: DataPanelToolbarStyle | string;\n /** Where the built-in view controls (inline filters, Filter menu, Sort menu)\n * sit in the toolbar: `\"inline\"` (default) places each in the toolbar;\n * `\"popover\"` collapses all of them behind a single button — for a narrow or\n * deliberately chrome-light toolbar. Same controls and state either way.\n * Ignored while a modal view is selecting: the toolbar then carries a single\n * control that leaves select mode. */\n viewControls?: ViewControlsPresentation;\n /** Arbitrary children rendered inside the provider, after the panel. */\n children?: ReactNode;\n}\n\n/**\n * Resolve the data source (shared with `DataSheet` / `DataView` via\n * `useResolvedProvider`), wrap in the shared provider, and render the inner\n * panel.\n */\nexport function DataPanel<T>(props: DataPanelProps<T>) {\n const [providerProps, rendererProps] = splitDataProviderProps({\n ...props,\n viewType: DataViewRendererType.CARDS,\n });\n return h(\n DataSheetProvider<T>,\n providerProps,\n h(DataPanelRenderer<any>, rendererProps),\n );\n}\n\n/** Selection modifier keys, following the familiar list idiom. */\nexport interface SelectModifiers {\n /** cmd/ctrl — toggle this row in/out of the selection (or extend a range). */\n additive?: boolean;\n /** shift — select the range from the anchor (last plain/cmd click) to here. */\n range?: boolean;\n}\n\n/** The card-list renderer. Assumes it is rendered inside a `DataSheetProvider`\n * (the `DataPanel` wrapper, or `DataView`). Exported so a shared-store\n * `DataView` can mount it directly alongside `_DataSheet`. */\nexport function DataPanelRenderer<T>({\n itemComponent,\n actions = [],\n filters = [],\n pageSize = 50,\n filterDebounce,\n initialData,\n name,\n // Bottom bar\n statusBar,\n toolbar,\n sidebar,\n // Footer within content flow\n contentFooter,\n autoLoadPages,\n scrollBody,\n className,\n toolbarStyle = DataPanelToolbarStyle.BORDERED,\n viewControls = \"inline\",\n children,\n}: Omit<DataPanelProps<T>, \"provider\" | \"fetchData\" | \"data\" | \"identity\">) {\n const {\n provider: activeProvider,\n isLocalProvider,\n localCount,\n } = ctx.useValue(dataProviderAtom);\n\n // The loader is mounted as a child component (below), NOT called as a hook\n // here, and only once `activeProvider` resolves. This mirrors `_DataSheet`:\n // `dataProviderAtom` is synced by a parent effect that fires *after* this\n // component's effects, so a hook call here would capture the placeholder\n // provider on first render and — since `fetchData` isn't one of its effect\n // deps — never re-fetch with the real one. A child that mounts with the real\n // `fetchData` already in hand sidesteps that entirely.\n // A local (in-memory) source loads all of its rows in one page; its count\n // rides on the resolved provider, so the renderer no longer takes a `data`\n // prop (the store is the single source of live rows).\n const loaderPageSize = isLocalProvider ? Math.max(localCount, 1) : pageSize;\n\n const data = useSelector((s) => s.data);\n\n // Load state + pause/resume live in the store, read via `useLoadControls`\n // (also available to the caller's `footer` via the same hook). The panel's\n // `autoLoadPages` prop is the store's configuration input.\n ctx.useSync(autoLoadPagesAtom, autoLoadPages ?? null);\n const {\n loading,\n initialized,\n error,\n hasMore,\n loaded,\n total,\n paused,\n canLoadMore,\n advance,\n } = useLoadControls();\n\n // Track whether the body is scrolled off the top, to gate the top fade.\n // `setState` with an unchanged value is a no-op, so this only re-renders on\n // the at-top ↔ scrolled transition.\n const [scrolled, setScrolled] = useState(false);\n const onScroll = useCallback((e: ReactUIEvent<HTMLDivElement>) => {\n setScrolled(e.currentTarget.scrollTop > 4);\n }, []);\n\n const enableSelection = ctx.useValue(enableSelectionAtom);\n const selectedIndices = ctx.useValue(selectedRowIndicesAtom);\n const select = ctx.useSet(updateSelectionAtom);\n\n const loadedCount = useMemo(() => {\n let n = 0;\n for (const r of data) if (r != null) n++;\n return n;\n }, [data]);\n\n // Refresh-token, rowEditing, and load controls (loadMore / pause) are all\n // store-managed (see `useLoadControls`), shared with `_DataSheet` — so both\n // renderers, and any footer, drive loading off one source.\n\n // Infinite scroll. A naive \"load a page when the bottom sentinel is visible\"\n // over-fetches: when a page's rows commit, this component re-renders\n // (loadedCount changed) *before* the IntersectionObserver has re-evaluated\n // the sentinel's new position, so a stale \"still visible\" fires a second\n // load. `useBottomSentinel` re-observes the sentinel whenever the pass-through\n // deps change, so every trigger reflects the *current* post-layout\n // visibility — it loads one page, and only loads another if the sentinel is\n // genuinely still on screen. `advance` (from the store) moves the loader one\n // page without resuming a paused auto-load.\n const sentinelRef = useBottomSentinel(canLoadMore ? advance : null, [\n loadedCount,\n canLoadMore,\n ]);\n\n const cards: ReactNode[] = [];\n data.forEach((row, i) => {\n if (row == null) return;\n const selected = enableSelection && selectedIndices.has(i);\n cards.push(\n h(\n \"div.data-panel-item-container\",\n { key: `item-${i}`, className: classNames({ selected }) },\n h(itemComponent, {\n data: row,\n index: i,\n selected,\n selectable: enableSelection,\n onSelect: (arg?: SelectModifiers | ReactMouseEvent) =>\n select(i, modifiersOf(arg)),\n }),\n ),\n );\n });\n\n // Body-level empty/error state: when nothing has loaded, show a clear message\n // instead of a blank list — an errored source (e.g. a 401 on the whole route)\n // degrades gracefully, and a genuinely empty result reads as \"no results\"\n // rather than a perpetual spinner.\n // A load is pending whenever a fetch is in flight OR the view was just reset\n // and hasn't fetched yet (`!initialized`) — the window that would otherwise\n // flash \"No results\" before the request starts.\n const loadPending = (loading || !initialized) && error == null;\n\n let emptyState: ReactNode = null;\n if (cards.length === 0) {\n if (error != null) {\n emptyState = h(NonIdealState, {\n icon: \"error\",\n title: \"Couldn't load data\",\n description: error.message ?? \"The data source returned an error.\",\n });\n } else if (initialized && !loading) {\n // Only after a fetch settled with no rows — not during the reset gap.\n emptyState = h(NonIdealState, {\n icon: \"search\",\n title: \"No results\",\n });\n }\n }\n\n // Skeleton placeholders for the page being fetched — on a view change (the\n // reset pre-sizes to a page of `null` slots) or the next scroll page — so the\n // body shows shimmer where rows will land instead of a blank flash or a\n // footer pinging up into the gap. Bounded to a viewport's worth of cards.\n if (loadPending) {\n const pending = Math.min(Math.max(data.length - loadedCount, 0), 24);\n for (let i = 0; i < pending; i++) {\n cards.push(\n h(\n \"div.data-panel-item-container.is-skeleton\",\n { key: `skeleton-${i}`, \"aria-hidden\": true },\n h(\"div.data-panel-skeleton\", { className: Classes.SKELETON }),\n ),\n );\n }\n }\n\n // The default spinner sentinel (below-placement): hidden while paused so the\n // pinned footer's \"Load more\" takes over.\n const shouldLoadNextPage = (hasMore || loading) && !paused && error == null;\n\n // Mount the loader only once the provider resolves (see `PanelLoader`). Built\n // as a real conditional — `h.if(...)` evaluates its arguments eagerly, so\n // `activeProvider.fetchData` can't be referenced inside it while null.\n let loaderNode: ReactNode = null;\n if (activeProvider != null) {\n loaderNode = h(PanelLoader, {\n fetchData: activeProvider.fetchData,\n pageSize: loaderPageSize,\n fetchMode: isLocalProvider ? undefined : \"scroll\",\n filterDebounce,\n initialData,\n });\n }\n\n const coreActions = useDataPanelControls(filters, viewControls);\n\n // Merge consumer actions with the synthesized Filter/Sort controls, deduped\n // by id — consumer actions come first, so passing an action with id `filter`\n // or `sort` *replaces* the built-in one (a hybrid set keeps the others).\n // Mirrors the sheet's action registry contract (see `data-sheet.ts`).\n const _actions = useMemo(() => {\n const merged: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!merged.some((x) => x.id === a.id)) merged.push(a);\n }\n };\n add(actions);\n add(coreActions);\n return merged;\n }, [actions, coreActions]);\n\n const ScrollBody = scrollBody ?? DefaultScrollBody;\n\n // The panel owns the scroll container + the loading sentinel; the (custom or\n // default) scroll body only lays out the cards. So a grid / grouped / windowed\n // body composes without reimplementing paging or selection. The end-of-scroll\n // region is either the default spinner sentinel or the caller's inline\n // footer — both carry the sentinel ref that drives auto-load.\n // The top fade is gated on being scrolled (via `.is-scrolled`), so the first\n // item isn't clipped at rest.\n\n const showStatusBar = statusBar !== false;\n\n let defaultFooter: ReactNode = null;\n if (shouldLoadNextPage) {\n defaultFooter = h(\"div.sentinel\", [h(Spinner, { size: 16 }), \"Loading...\"]);\n } else if (!showStatusBar) {\n defaultFooter = h(\"div.sentinel\", [\n h(Icon, { size: 16, icon: \"tick\" }),\n \"Loaded\",\n ]);\n }\n\n const _contentFooter = h(\n \"div.content-footer-holder\",\n { ref: sentinelRef },\n contentFooter ?? defaultFooter,\n );\n\n // Body + optional filter/detail sidebar share a horizontal row so each\n // scrolls independently.\n\n // Bottom status row (counter + extras). `statusBar === false` drops it — e.g.\n // when an inline footer carries the counter itself.\n let footer: ReactNode = null;\n let _statusBarContent = statusBar ?? h(DataPanelStatusBar);\n if (showStatusBar) {\n footer = h(\n \"div.data-panel-footer\",\n h(\"div.data-panel-footer-content\", [_statusBarContent]),\n );\n }\n\n return h(\n \"div.data-panel\",\n { className: classNames(className, \"toolbar-style-\" + toolbarStyle) },\n [\n h(\"div.data-panel-main\", [\n loaderNode,\n h(\n \"div.data-panel-toolbar\",\n h(\n ActionsToolbar,\n {\n actions: _actions,\n tableName: name,\n className: \"data-panel-toolbar-content\",\n // In the panel the title doubles as the modal-selection control,\n // so only render it when modal selection is toggle-able (or a\n // selection is active) — not as a bare label otherwise.\n compact: true,\n },\n toolbar,\n ),\n ),\n h(\n \"div.data-panel-body\",\n {\n onScroll,\n className: classNames({ \"is-scrolled\": scrolled }),\n },\n h(\"div.data-panel-body-content\", [\n emptyState ?? h(ScrollBody, cards),\n _contentFooter,\n ]),\n ),\n footer,\n ]),\n h.if(sidebar != null)(\"div.data-panel-sidebar-container\", sidebar),\n children,\n ],\n );\n}\n\nfunction DataPanelStatusBar({ children }) {\n /** Default status bar for the Data Panel */\n return h(\"div.data-panel-status-bar\", [children, h(LoadProgressIndicator)]);\n}\n\n/** Default scroll-body layout: a vertical flex list of cards. */\nfunction DefaultScrollBody({ children }: { children: ReactNode }) {\n return h(\"div.data-panel-list\", children);\n}\n\n/** Runs the shared windowed loader from inside the panel (renders nothing).\n * Mounted only once the real provider is resolved, so `useDataLoader` captures\n * the real `fetchData` from the start (see `_DataPanel`). */\nfunction PanelLoader<T = any>({\n fetchData,\n ...options\n}: { fetchData: FetchData<T> } & FetchDataOptions<T>) {\n useDataLoader(fetchData, options);\n return null;\n}\n\n/** Resolve the selection modifiers from either a click event (reads shift /\n * cmd / ctrl) or an explicit modifier object; no argument ⇒ a plain select. */\nfunction modifiersOf(arg?: SelectModifiers | ReactMouseEvent): SelectModifiers {\n if (arg == null) return {};\n if (\"shiftKey\" in arg) {\n return { additive: arg.metaKey || arg.ctrlKey, range: arg.shiftKey };\n }\n return arg;\n}\n\n/**\n * Bottom-sentinel infinite-scroll hook (no `react-intersection-observer`\n * dependency). Calls `onVisible` when the observed element is on screen, and —\n * crucially — **re-observes on every `deps` change** so the callback reflects\n * the *current* post-layout visibility rather than the pre-load render.\n *\n * This is what avoids the double-load: a plain observer whose visibility is\n * mirrored into React state lags a render behind the DOM, so a load-driven\n * re-render fires a second `onVisible` before the observer catches up. By\n * re-arming after each load (`deps = [loadedCount, canLoadMore]`), the observer\n * emits a fresh callback for the settled layout: it fires again only if the\n * sentinel is *still* visible (viewport not yet filled), so it loads exactly\n * one page per bottom-reach and self-fills an underfull viewport without\n * overshooting. Pass `onVisible = null` to disarm (loading / no more data).\n */\nfunction useBottomSentinel<E extends HTMLElement>(\n onVisible: (() => void) | null,\n deps: unknown[],\n): (el: E | null) => void {\n const elRef = useRef<E | null>(null);\n const observerRef = useRef<IntersectionObserver | null>(null);\n const cbRef = useRef(onVisible);\n cbRef.current = onVisible;\n\n const setRef = useCallback((el: E | null) => {\n elRef.current = el;\n observerRef.current?.disconnect();\n observerRef.current = null;\n if (el == null) return;\n const observer = new IntersectionObserver(\n ([entry]) => {\n if (entry.isIntersecting) cbRef.current?.();\n },\n { rootMargin: \"300px\" },\n );\n observer.observe(el);\n observerRef.current = observer;\n }, []);\n\n // Re-arm after each load so the observer re-checks the settled layout.\n useEffect(() => {\n const el = elRef.current;\n const observer = observerRef.current;\n if (el == null || observer == null) return;\n observer.disconnect();\n observer.observe(el);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n useEffect(() => () => observerRef.current?.disconnect(), []);\n return setRef;\n}\n\nconst rowSelectionAtom = atom((get) => {\n /** Coerce selection to full rows, for use with data panel instead of data sheet. */\n const selection = get(selectionAtom);\n if (selection.some((r) => r.cols != null)) {\n // A card list has no cells or columns. When the selection carries columns —\n // inherited from a shared store the sheet also drives (a `DataView` toggle) —\n // coerce it to the full rows it covers, so the toolbar shows row-scoped\n // actions rather than column/cell ones for a column that isn't visible here.\n // Column-only selections (no rows) collapse to nothing.\n return rowIndicesToRegions(new Set(getSelectedRowIndices(selection)));\n } else {\n return selection;\n }\n}, passThroughSet(selectionAtom));\n\nconst updateSelectionAtom = atom(\n null,\n (get, set, index: number, mods: SelectModifiers) => {\n /** Update selection from a row index and modifiers. */\n const { enableMultipleSelection, enableModalSelection } = get(\n interactionOptionsAtom,\n );\n let enableSelection = get(enableSelectionAtom);\n if (!enableSelection) {\n // Cmd/ctrl-click *enters* select mode on a modal view and selects the\n // row, the familiar list idiom — so a bulk action doesn't require finding\n // the Select control first. The flag is read back below rather than\n // trusted from this scope: the write goes through the store synchronously.\n if (!enableModalSelection || !mods.additive) return;\n set(enableSelectionAtom, true);\n enableSelection = get(enableSelectionAtom);\n if (!enableSelection) return;\n }\n const selection = get(rowSelectionAtom);\n const anchorRef = get(anchorRefAtom);\n const res = buildDataViewSelection(\n index,\n mods,\n selection,\n anchorRef,\n enableMultipleSelection,\n );\n set(selectionAtom, res);\n },\n);\n\nconst selectedRowIndicesAtom = atom((get) => {\n const sel = get(selectionAtom);\n return new Set(getSelectedRowIndices(sel));\n});\n\ntype ItemSelectionKeys = \"onSelect\" | \"selected\" | \"selectable\";\n\ntype DataCardProps = {\n children: ReactNode;\n className: string;\n style?: CSSProperties;\n} & Pick<ItemComponentProps, ItemSelectionKeys>;\n\nexport function DataCard<T = any>(props: DataCardProps) {\n /** A basic card that implements the data panel's selection behavior. */\n return h(\n \"div.data-card.data-panel-item\",\n {\n className: classNames(props.className, {\n selected: props.selected,\n selectable: props.selectable,\n }),\n onClick: props.onSelect,\n style: props.style,\n },\n props.children,\n );\n}\n\ntype DataCardInnerComponent<T> = (\n props: ItemComponentProps<T>,\n) => React.ReactNode;\n\nexport function createDataCard<T>(\n component: DataCardInnerComponent<T>,\n extraProps = {},\n) {\n return (props: ItemComponentProps<T>) => {\n const { selected, selectable, onSelect } = props;\n return h(\n DataCard,\n {\n selected,\n selectable,\n onSelect,\n ...extraProps,\n },\n h(component, props),\n );\n };\n}\n"],"names":["DataPanelToolbarStyle","splitDataProviderProps","DataViewRendererType","h","DataSheetProvider","ctx","dataProviderAtom","useSelector","autoLoadPagesAtom","useLoadControls","useState","useCallback","enableSelectionAtom","useMemo","classNames","NonIdealState","Classes","useDataPanelControls","Spinner","Icon","ActionsToolbar","LoadProgressIndicator","useDataLoader","useRef","useEffect","atom","selection","selectionAtom","rowIndicesToRegions","getSelectedRowIndices","passThroughSet","interactionOptionsAtom","anchorRefAtom","buildDataViewSelection"],"mappings":";;;;;;;;;;;;;;;;;;AAyEO,IAAK,0CAAAA,2BAAL;AACLA,yBAAA,UAAA,IAAW;AACXA,yBAAA,MAAA,IAAO;AACPA,yBAAA,SAAA,IAAU;AAIVA,yBAAA,UAAA,IAAW;AAPD,SAAAA;AAAA,GAAA,yBAAA,CAAA,CAAA;AAyFL,SAAS,UAAa,OAA0B;AACrD,QAAM,CAAC,eAAe,aAAa,IAAIC,4BAAuB;AAAA,IAC5D,GAAG;AAAA,IACH,UAA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AC3C,WAAOX,iBAAAA;AAAAA,MACL;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MAAA;AAAA,MAELA,iBAAAA,QAAE,WAAW,KAAK;AAAA,IAAA;AAAA,EAEtB;AACF;;;;;;"}
@@ -103,7 +103,7 @@ export interface SelectModifiers {
103
103
  /** The card-list renderer. Assumes it is rendered inside a `DataSheetProvider`
104
104
  * (the `DataPanel` wrapper, or `DataView`). Exported so a shared-store
105
105
  * `DataView` can mount it directly alongside `_DataSheet`. */
106
- export declare function DataPanelRenderer<T>({ itemComponent, actions, filters, pageSize, filterDebounce, name, statusBar, toolbar, sidebar, contentFooter, autoLoadPages, scrollBody, className, toolbarStyle, viewControls, children, }: Omit<DataPanelProps<T>, "provider" | "fetchData" | "data" | "identity">): import('react').ReactElement<{
106
+ export declare function DataPanelRenderer<T>({ itemComponent, actions, filters, pageSize, filterDebounce, initialData, name, statusBar, toolbar, sidebar, contentFooter, autoLoadPages, scrollBody, className, toolbarStyle, viewControls, children, }: Omit<DataPanelProps<T>, "provider" | "fetchData" | "data" | "identity">): import('react').ReactElement<{
107
107
  className: string;
108
108
  }, string | import('react').JSXElementConstructor<any>>;
109
109
  type ItemSelectionKeys = "onSelect" | "selected" | "selectable";
@@ -36,6 +36,7 @@ function DataPanelRenderer({
36
36
  filters = [],
37
37
  pageSize = 50,
38
38
  filterDebounce,
39
+ initialData,
39
40
  name,
40
41
  // Bottom bar
41
42
  statusBar,
@@ -138,7 +139,8 @@ function DataPanelRenderer({
138
139
  fetchData: activeProvider.fetchData,
139
140
  pageSize: loaderPageSize,
140
141
  fetchMode: isLocalProvider ? void 0 : "scroll",
141
- filterDebounce
142
+ filterDebounce,
143
+ initialData
142
144
  });
143
145
  }
144
146
  const coreActions = useDataPanelControls(filters, viewControls);