@macrostrat/data-sheet 4.2.0 → 4.3.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 (71) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/actions/types.d.ts +10 -0
  3. package/dist/components/indicators/filter-and-sort.cjs +47 -6
  4. package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
  5. package/dist/components/indicators/filter-and-sort.d.ts +28 -6
  6. package/dist/components/indicators/filter-and-sort.js +48 -7
  7. package/dist/components/indicators/filter-and-sort.js.map +1 -1
  8. package/dist/components/indicators/filter-and-sort.module.sass.cjs +5 -3
  9. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -1
  10. package/dist/components/indicators/filter-and-sort.module.sass.js +5 -3
  11. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -1
  12. package/dist/components/indicators/unified-filters.cjs +36 -22
  13. package/dist/components/indicators/unified-filters.cjs.map +1 -1
  14. package/dist/components/indicators/unified-filters.d.ts +10 -8
  15. package/dist/components/indicators/unified-filters.js +37 -23
  16. package/dist/components/indicators/unified-filters.js.map +1 -1
  17. package/dist/components/indicators/view-info.cjs +11 -5
  18. package/dist/components/indicators/view-info.cjs.map +1 -1
  19. package/dist/components/indicators/view-info.d.ts +6 -1
  20. package/dist/components/indicators/view-info.js +12 -6
  21. package/dist/components/indicators/view-info.js.map +1 -1
  22. package/dist/components/toolbars/actions-toolbar.cjs +7 -1
  23. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
  24. package/dist/components/toolbars/actions-toolbar.js +7 -1
  25. package/dist/components/toolbars/actions-toolbar.js.map +1 -1
  26. package/dist/data-panel.cjs +53 -8
  27. package/dist/data-panel.cjs.map +1 -1
  28. package/dist/data-panel.d.ts +1 -1
  29. package/dist/data-panel.js +54 -9
  30. package/dist/data-panel.js.map +1 -1
  31. package/dist/data-panel.module.sass.cjs +24 -21
  32. package/dist/data-panel.module.sass.cjs.map +1 -1
  33. package/dist/data-panel.module.sass.js +24 -21
  34. package/dist/data-panel.module.sass.js.map +1 -1
  35. package/dist/data-sheet.cjs +9 -2
  36. package/dist/data-sheet.cjs.map +1 -1
  37. package/dist/data-sheet.css +56 -35
  38. package/dist/data-sheet.d.ts +1 -1
  39. package/dist/data-sheet.js +9 -2
  40. package/dist/data-sheet.js.map +1 -1
  41. package/dist/index.cjs +2 -0
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.js +3 -1
  44. package/dist/postgrest-table/data-loaders.cjs +20 -3
  45. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  46. package/dist/postgrest-table/data-loaders.d.ts +10 -0
  47. package/dist/postgrest-table/data-loaders.js +21 -4
  48. package/dist/postgrest-table/data-loaders.js.map +1 -1
  49. package/dist/provider/core.cjs +27 -56
  50. package/dist/provider/core.cjs.map +1 -1
  51. package/dist/provider/core.d.ts +7 -9
  52. package/dist/provider/core.js +19 -48
  53. package/dist/provider/core.js.map +1 -1
  54. package/dist/provider/interactions.d.ts +1 -1
  55. package/dist/provider/selection.d.ts +1 -1
  56. package/dist/types.cjs.map +1 -1
  57. package/dist/types.d.ts +4 -0
  58. package/dist/types.js.map +1 -1
  59. package/package.json +6 -7
  60. package/src/actions/types.ts +11 -0
  61. package/src/components/indicators/filter-and-sort.module.sass +7 -0
  62. package/src/components/indicators/filter-and-sort.ts +71 -11
  63. package/src/components/indicators/unified-filters.ts +66 -29
  64. package/src/components/indicators/view-info.ts +15 -5
  65. package/src/components/toolbars/actions-toolbar.ts +10 -1
  66. package/src/data-panel.module.sass +18 -1
  67. package/src/data-panel.ts +67 -8
  68. package/src/data-sheet.ts +18 -2
  69. package/src/postgrest-table/data-loaders.ts +40 -4
  70. package/src/provider/core.ts +29 -53
  71. package/src/types.ts +4 -0
@@ -1,6 +1,5 @@
1
- import { SetStateAction, useEffect, useMemo, useRef, useState } from "react";
1
+ import { useEffect, useMemo, useRef } from "react";
2
2
  import h from "@macrostrat/hyper";
3
- import { createStore, StoreApi, useStore } from "zustand";
4
3
  import { Table } from "@blueprintjs/table";
5
4
  import {
6
5
  type ColumnSpec,
@@ -8,7 +7,15 @@ import {
8
7
  postprocessColumnSpec,
9
8
  } from "./column-spec.ts";
10
9
  import { splitProps } from "../utils";
11
- import { createScopedStore } from "@macrostrat/data-components";
10
+ import {
11
+ createScopedStore,
12
+ zustandAPIAtom,
13
+ zustandStoreAtom,
14
+ atom,
15
+ ZustandStoreProvider,
16
+ useZustandSelector,
17
+ useZustandStoreAPI,
18
+ } from "@macrostrat/scoped-store";
12
19
  import {
13
20
  DataSheetProviderProps,
14
21
  DataSheetState,
@@ -17,10 +24,8 @@ import {
17
24
  TableElementStatus,
18
25
  } from "./types.ts";
19
26
  import { createZustandStore } from "./zustand-store.ts";
20
- import { atomWithStore } from "jotai-zustand";
21
27
  import { toasterAtom } from "../notifications.ts";
22
28
  import { TableAction } from "../actions";
23
- import { atom } from "jotai";
24
29
  import {
25
30
  createLocalProvider,
26
31
  dataRefreshTokenAtom,
@@ -42,33 +47,10 @@ import { DataPanelProps } from "../data-panel.ts";
42
47
  /** Create a Jotai scoped store */
43
48
  export const ctx = createScopedStore();
44
49
 
45
- export const storeAPIAtom = atom<StoreApi<DataSheetStore<any>>>();
46
-
47
- const storeWrapperAtom = atom((get) => {
48
- const _storeAPIAtom = get(storeAPIAtom);
49
- if (_storeAPIAtom == null) {
50
- return undefined;
51
- }
52
- return atomWithStore(_storeAPIAtom);
53
- });
50
+ export const storeAPIAtom = zustandAPIAtom;
54
51
 
55
52
  /** This is the basis for all other atoms that manipulate the store. */
56
- export const storeAtom = atom(
57
- (get) => {
58
- const storeWrapper = get(storeWrapperAtom);
59
- if (storeWrapper == null) {
60
- return undefined;
61
- }
62
- return get(storeWrapper);
63
- },
64
- (get, set, action: SetStateAction<any>) => {
65
- const storeWrapper = get(storeWrapperAtom);
66
- if (storeWrapper == null) {
67
- throw new Error("Missing DataSheetProvider");
68
- }
69
- return set(storeWrapper, action);
70
- },
71
- );
53
+ export const storeAtom = zustandStoreAtom;
72
54
 
73
55
  /** Stable empty spec so a function `columnSpec` yields a constant init value
74
56
  * (see `DataSheetProviderInner`). */
@@ -77,7 +59,7 @@ const EMPTY_SPEC: ColumnSpec[] = [];
77
59
  const initializeStoreAtom = atom(
78
60
  null,
79
61
  (get, set, payload: Partial<DataSheetStore<any>>) => {
80
- set(storeAtom, (state) => {
62
+ set(zustandStoreAtom, (state) => {
81
63
  return {
82
64
  ...state,
83
65
  ...payload,
@@ -172,16 +154,13 @@ export function useResolvedProvider<T>(props: {
172
154
 
173
155
  function DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {
174
156
  const { toaster, ...rest } = props;
175
- const [store] = useState(() => {
176
- return createStore<DataSheetStore<T>>(createZustandStore);
177
- });
178
157
  return h(
179
- ctx.Provider,
158
+ ZustandStoreProvider,
180
159
  {
181
- atoms: [
182
- [storeAPIAtom, store],
183
- [toasterAtom, toaster],
184
- ],
160
+ ctx,
161
+ initializeStore: createZustandStore,
162
+ atoms: [[toasterAtom, toaster]],
163
+ debugName: "DataSheetProvider",
185
164
  },
186
165
  h(DataSheetProviderInner, rest),
187
166
  );
@@ -209,9 +188,7 @@ const dataProviderKeys = new Set([
209
188
  ]);
210
189
 
211
190
  type AnyDataSheetProps<T> =
212
- | DataViewProps<T>
213
- | DataPanelProps<T>
214
- | DataSheetProps<T>;
191
+ DataViewProps<T> | DataPanelProps<T> | DataSheetProps<T>;
215
192
 
216
193
  export function splitDataProviderProps<T>(props: AnyDataSheetProps<T>) {
217
194
  /** Split provided props based on provider's needs */
@@ -295,9 +272,13 @@ export function DataSheetProviderInner<T>(
295
272
  useEffect(() => {
296
273
  initializeStore({
297
274
  columnSpec: postprocessColumnSpec(baseSpec),
298
- // A function spec is derived from the loaded rows in `_DataSheet`; tell
299
- // the loader not to auto-generate a plain spec from the first chunk.
300
- deferColumnSpec: isFnSpec,
275
+ // Suppress the loader's first-chunk auto-generation whenever the consumer
276
+ // provided a spec at all — a function (derived later in `_DataSheet`) OR
277
+ // an explicit array, *including an empty one*. An empty array means "no
278
+ // facet columns" (e.g. a browse panel whose only control is a sheet-level
279
+ // search), not "please generate from the data". Auto-gen runs only when
280
+ // no `columnSpec` was passed.
281
+ deferColumnSpec: columnSpec != null,
301
282
  editable: interactionOptions.enableEditing,
302
283
  enableColumnReordering,
303
284
  data,
@@ -398,19 +379,14 @@ export function DataSheetProviderInner<T>(
398
379
  return children;
399
380
  }
400
381
 
401
- export function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {
402
- const store = ctx.useValue(storeAPIAtom);
403
- if (!store) {
404
- throw new Error("Missing DataSheetProvider");
405
- }
406
- return store;
382
+ export function useStoreAPI<T>() {
383
+ return useZustandStoreAPI<DataSheetStore<T>>(ctx);
407
384
  }
408
385
 
409
386
  export function useSelector<T = any, A = any>(
410
387
  selector: (state: DataSheetStore<T>) => A,
411
388
  ): A {
412
- const store = useStoreAPI<T>();
413
- return useStore(store, selector);
389
+ return useZustandSelector<T, A>(ctx, selector);
414
390
  }
415
391
  /** Atoms for efficient sub-selection of state */
416
392
 
package/src/types.ts CHANGED
@@ -18,6 +18,10 @@ export type FetchMode = "scroll" | "paged";
18
18
  export interface FetchDataOptions {
19
19
  pageSize?: number;
20
20
  fetchMode?: FetchMode;
21
+ /** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a
22
+ * text filter) collapse into one fetch once the view settles. The input stays
23
+ * instant; only the fetch waits. `0` (default) keeps immediate refetching. */
24
+ filterDebounce?: number;
21
25
  }
22
26
 
23
27
  /** Props shared between the wrapper components and the provider */