@macrostrat/data-sheet 4.1.1 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/dist/actions/builtin.cjs +1 -1
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +0 -2
- package/dist/actions/builtin.js +1 -1
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/clipboard.cjs +1 -1
- package/dist/actions/clipboard.cjs.map +1 -1
- package/dist/actions/clipboard.d.ts +3 -2
- package/dist/actions/clipboard.js +1 -1
- package/dist/actions/clipboard.js.map +1 -1
- package/dist/actions/column-controls.cjs +7 -196
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.d.ts +1 -1
- package/dist/actions/column-controls.js +5 -194
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +24 -73
- package/dist/actions/column-filter.cjs.map +1 -1
- package/dist/actions/column-filter.d.ts +6 -4
- package/dist/actions/column-filter.js +25 -74
- package/dist/actions/column-filter.js.map +1 -1
- package/dist/actions/context.cjs +147 -0
- package/dist/actions/context.cjs.map +1 -0
- package/dist/actions/context.d.ts +93 -0
- package/dist/actions/context.js +145 -0
- package/dist/actions/context.js.map +1 -0
- package/dist/actions/edit-actions.cjs.map +1 -1
- package/dist/actions/edit-actions.d.ts +3 -1
- package/dist/actions/edit-actions.js.map +1 -1
- package/dist/actions/index.d.ts +2 -3
- package/dist/actions/selection.cjs +70 -115
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +22 -12
- package/dist/actions/selection.js +71 -114
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-actions.cjs +41 -0
- package/dist/actions/table-actions.cjs.map +1 -0
- package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
- package/dist/actions/{table-controls.js → table-actions.js} +2 -23
- package/dist/actions/table-actions.js.map +1 -0
- package/dist/actions/types.d.ts +11 -89
- package/dist/components/cell-detail.cjs +6 -6
- package/dist/components/cell-detail.cjs.map +1 -1
- package/dist/components/cell-detail.js +1 -1
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +7 -7
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/indicators/filter-and-sort.cjs +378 -0
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.d.ts +59 -0
- package/dist/components/indicators/filter-and-sort.js +376 -0
- package/dist/components/indicators/filter-and-sort.js.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
- package/dist/components/indicators/index.d.ts +4 -0
- package/dist/components/indicators/selection.cjs +113 -0
- package/dist/components/indicators/selection.cjs.map +1 -0
- package/dist/components/indicators/selection.d.ts +3 -0
- package/dist/components/indicators/selection.js +111 -0
- package/dist/components/indicators/selection.js.map +1 -0
- package/dist/components/indicators/selection.module.sass.cjs +19 -0
- package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
- package/dist/components/indicators/selection.module.sass.js +17 -0
- package/dist/components/indicators/selection.module.sass.js.map +1 -0
- package/dist/components/indicators/unified-filters.cjs +130 -0
- package/dist/components/indicators/unified-filters.cjs.map +1 -0
- package/dist/components/indicators/unified-filters.d.ts +10 -0
- package/dist/components/indicators/unified-filters.js +130 -0
- package/dist/components/indicators/unified-filters.js.map +1 -0
- package/dist/components/indicators/view-info.cjs +59 -0
- package/dist/components/indicators/view-info.cjs.map +1 -0
- package/dist/components/indicators/view-info.d.ts +11 -0
- package/dist/components/{view-info.js → indicators/view-info.js} +20 -16
- package/dist/components/indicators/view-info.js.map +1 -0
- package/dist/components/text-areas.cjs +5 -5
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.js +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs +185 -0
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
- package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
- package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
- package/dist/components/toolbars/actions-toolbar.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
- package/dist/components/toolbars/active-filters.cjs +120 -0
- package/dist/components/toolbars/active-filters.cjs.map +1 -0
- package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
- package/dist/components/toolbars/active-filters.js +120 -0
- package/dist/components/toolbars/active-filters.js.map +1 -0
- package/dist/components/toolbars/index.d.ts +2 -0
- package/dist/data-panel.cjs +291 -0
- package/dist/data-panel.cjs.map +1 -0
- package/dist/data-panel.d.ts +110 -0
- package/dist/data-panel.js +289 -0
- package/dist/data-panel.js.map +1 -0
- package/dist/data-panel.module.sass.cjs +40 -0
- package/dist/data-panel.module.sass.cjs.map +1 -0
- package/dist/data-panel.module.sass.js +38 -0
- package/dist/data-panel.module.sass.js.map +1 -0
- package/dist/{core.cjs → data-sheet.cjs} +126 -188
- package/dist/data-sheet.cjs.map +1 -0
- package/dist/data-sheet.css +241 -13
- package/dist/data-sheet.d.ts +16 -0
- package/dist/{core.js → data-sheet.js} +95 -157
- package/dist/data-sheet.js.map +1 -0
- package/dist/data-view.cjs +47 -0
- package/dist/data-view.cjs.map +1 -0
- package/dist/data-view.d.ts +15 -0
- package/dist/data-view.js +45 -0
- package/dist/data-view.js.map +1 -0
- package/dist/filters/operators.cjs +19 -2
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +4 -3
- package/dist/filters/operators.js +19 -2
- package/dist/filters/operators.js.map +1 -1
- package/dist/index.cjs +106 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +76 -17
- package/dist/index.js.map +1 -1
- package/dist/notifications.cjs +4 -4
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.js +1 -1
- package/dist/postgrest-table/data-loaders.cjs +128 -95
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -82
- package/dist/postgrest-table/data-loaders.js +109 -76
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +18 -17
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +4 -3
- package/dist/postgrest-table/index.js +9 -8
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/{utils → provider}/column-spec.cjs +23 -9
- package/dist/provider/column-spec.cjs.map +1 -0
- package/dist/{utils → provider}/column-spec.d.ts +73 -2
- package/dist/{utils → provider}/column-spec.js +24 -10
- package/dist/provider/column-spec.js.map +1 -0
- package/dist/provider/core.cjs +382 -0
- package/dist/provider/core.cjs.map +1 -0
- package/dist/provider/core.d.ts +74 -0
- package/dist/provider/core.js +380 -0
- package/dist/provider/core.js.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/interactions.cjs +128 -0
- package/dist/provider/interactions.cjs.map +1 -0
- package/dist/provider/interactions.d.ts +39 -0
- package/dist/provider/interactions.js +128 -0
- package/dist/provider/interactions.js.map +1 -0
- package/dist/provider/selection.cjs +29 -0
- package/dist/provider/selection.cjs.map +1 -0
- package/dist/provider/selection.d.ts +9 -0
- package/dist/provider/selection.js +29 -0
- package/dist/provider/selection.js.map +1 -0
- package/dist/provider/table-data.cjs +92 -0
- package/dist/provider/table-data.cjs.map +1 -0
- package/dist/provider/table-data.d.ts +81 -0
- package/dist/provider/table-data.js +92 -0
- package/dist/provider/table-data.js.map +1 -0
- package/dist/provider/types.cjs +22 -0
- package/dist/provider/types.cjs.map +1 -0
- package/dist/provider/types.d.ts +256 -0
- package/dist/provider/types.js +22 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
- package/dist/provider/zustand-store.cjs.map +1 -0
- package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
- package/dist/provider/zustand-store.js.map +1 -0
- package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
- package/dist/renderers/cell-renderer.cjs.map +1 -0
- package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
- package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
- package/dist/renderers/cell-renderer.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +21 -13
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -2
- package/dist/renderers/column-header-cell.js +20 -12
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +1 -0
- package/dist/types.cjs +7 -19
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +117 -229
- package/dist/types.js +7 -19
- package/dist/types.js.map +1 -1
- package/dist/utils/atoms.cjs +24 -0
- package/dist/utils/atoms.cjs.map +1 -0
- package/dist/utils/atoms.d.ts +4 -0
- package/dist/utils/atoms.js +24 -0
- package/dist/utils/atoms.js.map +1 -0
- package/dist/utils/debug-overlay.cjs.map +1 -1
- package/dist/utils/debug-overlay.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/key-handling.cjs +140 -139
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +4 -2
- package/dist/utils/key-handling.js +136 -135
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +6 -1
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.js +6 -1
- package/dist/utils/validation.js.map +1 -1
- package/package.json +4 -3
- package/src/actions/builtin.ts +1 -4
- package/src/actions/clipboard.ts +4 -3
- package/src/actions/column-controls.ts +12 -245
- package/src/actions/column-filter.ts +28 -92
- package/src/actions/context.ts +299 -0
- package/src/actions/edit-actions.ts +3 -1
- package/src/actions/index.ts +2 -3
- package/src/actions/selection.ts +109 -156
- package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
- package/src/actions/types.ts +17 -101
- package/src/components/colors.ts +1 -1
- package/src/components/index.ts +2 -1
- package/src/components/indicators/filter-and-sort.module.sass +13 -0
- package/src/components/indicators/filter-and-sort.ts +478 -0
- package/src/components/indicators/index.ts +4 -0
- package/src/components/indicators/selection.module.sass +22 -0
- package/src/components/indicators/selection.ts +141 -0
- package/src/components/indicators/unified-filters.ts +161 -0
- package/src/components/{view-info.ts → indicators/view-info.ts} +19 -30
- package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
- package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
- package/src/components/toolbars/active-filters.ts +150 -0
- package/src/components/toolbars/index.ts +2 -0
- package/src/data-panel.module.sass +185 -0
- package/src/data-panel.ts +556 -0
- package/src/{core.ts → data-sheet.ts} +156 -327
- package/src/data-view.ts +70 -0
- package/src/filters/operators.ts +33 -3
- package/src/index.ts +4 -3
- package/src/postgrest-table/data-loaders.ts +244 -171
- package/src/postgrest-table/index.ts +10 -9
- package/src/{utils → provider}/column-spec.ts +30 -15
- package/src/provider/core.ts +585 -0
- package/src/provider/index.ts +7 -0
- package/src/provider/interactions.ts +161 -0
- package/src/provider/selection.ts +31 -0
- package/src/provider/table-data.ts +178 -0
- package/src/provider/types.ts +273 -0
- package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
- package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
- package/src/renderers/column-header-cell.ts +21 -14
- package/src/renderers/index.ts +1 -0
- package/src/types.ts +137 -239
- package/src/utils/atoms.ts +28 -0
- package/src/utils/debug-overlay.ts +1 -1
- package/src/utils/index.ts +2 -8
- package/src/utils/key-handling.ts +170 -164
- package/src/utils/validation.ts +7 -2
- package/dist/actions/filters.cjs +0 -139
- package/dist/actions/filters.cjs.map +0 -1
- package/dist/actions/filters.js +0 -139
- package/dist/actions/filters.js.map +0 -1
- package/dist/actions/table-controls.cjs +0 -62
- package/dist/actions/table-controls.cjs.map +0 -1
- package/dist/actions/table-controls.js.map +0 -1
- package/dist/actions/toolbar.cjs +0 -260
- package/dist/actions/toolbar.cjs.map +0 -1
- package/dist/actions/toolbar.js.map +0 -1
- package/dist/actions/toolbar.module.sass.cjs +0 -27
- package/dist/actions/toolbar.module.sass.cjs.map +0 -1
- package/dist/actions/toolbar.module.sass.js +0 -25
- package/dist/actions/toolbar.module.sass.js.map +0 -1
- package/dist/cell-renderer.cjs.map +0 -1
- package/dist/cell-renderer.js.map +0 -1
- package/dist/components/view-info.cjs +0 -55
- package/dist/components/view-info.cjs.map +0 -1
- package/dist/components/view-info.d.ts +0 -5
- package/dist/components/view-info.js.map +0 -1
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -117
- package/dist/core.js.map +0 -1
- package/dist/provider.cjs +0 -197
- package/dist/provider.cjs.map +0 -1
- package/dist/provider.d.ts +0 -26
- package/dist/provider.js +0 -195
- package/dist/provider.js.map +0 -1
- package/dist/table-updates/data-parameter.d.ts +0 -14
- package/dist/table-updates/filter.d.ts +0 -16
- package/dist/table-updates/index.d.ts +0 -19
- package/dist/utils/column-spec.cjs.map +0 -1
- package/dist/utils/column-spec.js.map +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js +0 -9
- package/dist/utils/index.js.map +0 -1
- package/dist/zustand-store.cjs.map +0 -1
- package/dist/zustand-store.js.map +0 -1
- package/src/actions/filters.ts +0 -176
- package/src/components/actions.module.sass +0 -8
- package/src/provider.ts +0 -267
- package/src/table-updates/data-parameter.ts +0 -44
- package/src/table-updates/filter.ts +0 -124
- package/src/table-updates/index.ts +0 -239
- /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PostgrestFilterBuilder } from '@supabase/postgrest-js';
|
|
2
2
|
import { RowRegion } from './loading-utils.ts';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { FetchData, FetchDataFilter, TableDataProvider } from '../provider';
|
|
4
|
+
import { FetchDataOptions, FetchMode } from '../types.ts';
|
|
5
5
|
export interface PostgrestOrder<T> {
|
|
6
6
|
key: string;
|
|
7
7
|
ascending?: boolean;
|
|
8
8
|
nullsFirst?: boolean;
|
|
9
9
|
}
|
|
10
|
-
/** Operators available for server-side column filtering via PostgREST.
|
|
11
|
-
|
|
10
|
+
/** Operators available for server-side column filtering via PostgREST.
|
|
11
|
+
* `cs`/`ov` target array columns (contains / overlaps). */
|
|
12
|
+
export type PostgrestFilterOperator = "eq" | "neq" | "like" | "ilike" | "gt" | "lt" | "gte" | "lte" | "is" | "cs" | "ov";
|
|
12
13
|
/** A single column sort entry. */
|
|
13
14
|
export interface ColumnSortEntry {
|
|
14
15
|
key: string;
|
|
@@ -21,6 +22,7 @@ export interface PostgrestColumnFilter {
|
|
|
21
22
|
value: string;
|
|
22
23
|
}
|
|
23
24
|
export interface PostgrestFilter {
|
|
25
|
+
id?: string;
|
|
24
26
|
type: "filter";
|
|
25
27
|
apply(req: PostgrestFilterBuilder<any, any, any, any>): PostgrestFilterBuilder<any, any, any, any>;
|
|
26
28
|
}
|
|
@@ -30,11 +32,6 @@ export declare function applyColumnFilters(req: PostgrestFilterBuilder<any, any,
|
|
|
30
32
|
export declare const chunkPageAtom: import('jotai').PrimitiveAtom<number> & {
|
|
31
33
|
init: number;
|
|
32
34
|
};
|
|
33
|
-
/** Bump this to force the active chunk loader to reset and re-fetch from
|
|
34
|
-
* scratch — e.g. after a mutation (save/delete) that invalidates loaded rows. */
|
|
35
|
-
export declare const dataRefreshTokenAtom: import('jotai').PrimitiveAtom<number> & {
|
|
36
|
-
init: number;
|
|
37
|
-
};
|
|
38
35
|
/** Footer state for the optional bottom-of-table indicator: rows loaded, the
|
|
39
36
|
* source total when known, load status, and — in paged mode — the current
|
|
40
37
|
* page and total pages. */
|
|
@@ -48,6 +45,44 @@ export interface TableFooterInfo {
|
|
|
48
45
|
totalPages: number | null;
|
|
49
46
|
}
|
|
50
47
|
export declare const tableFooterAtom: import('jotai').Atom<TableFooterInfo>;
|
|
48
|
+
/** Auto-load this many pages per burst, then pause (null ⇒ unbounded). Set by
|
|
49
|
+
* a consumer (e.g. `DataPanel`'s `autoLoadPages` prop). */
|
|
50
|
+
export declare const autoLoadPagesAtom: import('jotai').PrimitiveAtom<number | null> & {
|
|
51
|
+
init: number | null;
|
|
52
|
+
};
|
|
53
|
+
/** Row count at the last manual "load more" — the point auto-load resumes
|
|
54
|
+
* counting a fresh burst from. */
|
|
55
|
+
export declare const resumeBaselineAtom: import('jotai').PrimitiveAtom<number> & {
|
|
56
|
+
init: number;
|
|
57
|
+
};
|
|
58
|
+
/** Live loading controls, read from the store rather than passed down a
|
|
59
|
+
* boundary contract. Any component inside the provider can call
|
|
60
|
+
* `useLoadControls()` — a footer, a toolbar button, a status line — without the
|
|
61
|
+
* renderer wiring a specific prop shape to it. */
|
|
62
|
+
export interface LoadControls {
|
|
63
|
+
/** Load the next page and resume auto-loading (clears a paused state). */
|
|
64
|
+
loadMore: () => void;
|
|
65
|
+
/** A fetch is in flight. */
|
|
66
|
+
loading: boolean;
|
|
67
|
+
/** More rows remain to load. */
|
|
68
|
+
hasMore: boolean;
|
|
69
|
+
/** Rows loaded so far. */
|
|
70
|
+
loaded: number;
|
|
71
|
+
/** Source total when known, else `null`. */
|
|
72
|
+
total: number | null;
|
|
73
|
+
/** Auto-load is paused at the `autoLoadPages` checkpoint. */
|
|
74
|
+
paused: boolean;
|
|
75
|
+
/** Auto-load is currently permitted (`hasMore && !loading && !paused`) —
|
|
76
|
+
* used to gate an infinite-scroll sentinel. */
|
|
77
|
+
canLoadMore: boolean;
|
|
78
|
+
/** Advance one page *without* resuming a paused auto-load (the sentinel
|
|
79
|
+
* uses this; `loadMore` is the manual, un-pausing variant). */
|
|
80
|
+
advance: () => void;
|
|
81
|
+
}
|
|
82
|
+
/** Store-managed load controls (see `LoadControls`). Reads the loader's footer
|
|
83
|
+
* state, the loaded rows, and the pause atoms; `loadMore`/`advance` set the
|
|
84
|
+
* visible region so the loader fetches the next chunk. */
|
|
85
|
+
export declare function useLoadControls(): LoadControls;
|
|
51
86
|
export interface ViewInfo {
|
|
52
87
|
visibleRegion: RowRegion;
|
|
53
88
|
totalCount: number | null;
|
|
@@ -56,79 +91,6 @@ export interface ViewInfo {
|
|
|
56
91
|
}
|
|
57
92
|
export declare const viewInfoAtom: import('jotai').Atom<ViewInfo>;
|
|
58
93
|
export declare function useScrollHandler(): ((visibleCells: RowRegion) => void) & import('underscore').Cancelable;
|
|
59
|
-
/** The active view state (a filter's id / column / config), passed to a
|
|
60
|
-
* `fetchChunk`. A server provider translates `columnKey` + `state` into a
|
|
61
|
-
* query; a local (in-memory) provider applies `predicate` directly. Both come
|
|
62
|
-
* from the same `TableFilter`, so one filter definition serves either target. */
|
|
63
|
-
export interface FetchDataFilter {
|
|
64
|
-
id: string;
|
|
65
|
-
columnKey?: string;
|
|
66
|
-
state: any;
|
|
67
|
-
/** Client-side row predicate (from the `TableFilter`). Server providers
|
|
68
|
-
* ignore it and translate `columnKey` + `state` instead. */
|
|
69
|
-
predicate?: (row: any, state: any) => boolean;
|
|
70
|
-
}
|
|
71
|
-
/** Parameters passed to a `fetchChunk` implementation for one window. */
|
|
72
|
-
export interface FetchDataParams {
|
|
73
|
-
/** Row offset of the requested chunk (chunk-aligned). */
|
|
74
|
-
offset: number;
|
|
75
|
-
/** Maximum rows to return. */
|
|
76
|
-
limit: number;
|
|
77
|
-
/** Aborts when the request is superseded (view change / unmount). */
|
|
78
|
-
signal: AbortSignal;
|
|
79
|
-
/** Active sorts, in priority order. */
|
|
80
|
-
sorts: ColumnSort[];
|
|
81
|
-
/** Active filters (id + column + config). */
|
|
82
|
-
filters: FetchDataFilter[];
|
|
83
|
-
/** In scroll mode, the already-loaded row immediately before this chunk
|
|
84
|
-
* (and its data-array index), or `null` at the start / in paged mode. Keyset
|
|
85
|
-
* sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a
|
|
86
|
-
* slow `OFFSET`; offset-based sources can ignore it. */
|
|
87
|
-
cursor?: {
|
|
88
|
-
row: any;
|
|
89
|
-
index: number;
|
|
90
|
-
} | null;
|
|
91
|
-
}
|
|
92
|
-
/** Result of a `fetchChunk` call. `totalCount` reports the source length when
|
|
93
|
-
* known (drives sparse-array pre-sizing and a proportional scrollbar); omit it
|
|
94
|
-
* for unknown-length sources (the array grows as chunks arrive). */
|
|
95
|
-
export interface FetchDataResult<T = any> {
|
|
96
|
-
rows: T[];
|
|
97
|
-
totalCount?: number | null;
|
|
98
|
-
}
|
|
99
|
-
export type FetchData<T = any> = (params: FetchDataParams) => Promise<FetchDataResult<T>>;
|
|
100
|
-
/**
|
|
101
|
-
* A table's data source, addressed uniformly whether it's an in-memory array or
|
|
102
|
-
* a remote backend. `fetchChunk` returns a window with the active sorts/filters
|
|
103
|
-
* already applied (in memory by the local provider, in SQL by a server one);
|
|
104
|
-
* `identity` addresses a row for edits/mutations — stable across re-sorts,
|
|
105
|
-
* unlike an array index. The mutation ops are present only for editable /
|
|
106
|
-
* persisting sources. The in-memory case (`createLocalProvider`) is just the
|
|
107
|
-
* degenerate implementation, so local and server tables share one path.
|
|
108
|
-
*/
|
|
109
|
-
export interface TableDataProvider<T = any> {
|
|
110
|
-
fetchData(params: FetchDataParams): Promise<FetchDataResult<T>>;
|
|
111
|
-
identity(row: T): string | number;
|
|
112
|
-
saveRows?(rows: T[]): Promise<void>;
|
|
113
|
-
deleteRows?(ids: Array<string | number>): Promise<void>;
|
|
114
|
-
insertRow?(row: Partial<T>): Promise<void>;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* The degenerate provider: an in-memory array. `fetchChunk` applies the active
|
|
118
|
-
* filter predicates and sorts over the array and returns the requested slice
|
|
119
|
-
* plus the (fully-known) total — the same view engine used for client-side
|
|
120
|
-
* tables, expressed as a provider.
|
|
121
|
-
*/
|
|
122
|
-
export declare function createLocalProvider<T = any>(data: T[], options?: {
|
|
123
|
-
identity?: (row: T) => string | number;
|
|
124
|
-
}): TableDataProvider<T>;
|
|
125
|
-
/** Multi-key row comparator (priority order; nulls first when ascending),
|
|
126
|
-
* shared by the local provider and any other in-memory sort. */
|
|
127
|
-
export declare function compareRowsBySorts(sorts: ColumnSort[]): (a: any, b: any) => number;
|
|
128
|
-
export interface FetchDataOptions {
|
|
129
|
-
pageSize?: number;
|
|
130
|
-
fetchMode?: FetchMode;
|
|
131
|
-
}
|
|
132
94
|
/**
|
|
133
95
|
* A generic, backend-agnostic windowed data source. Give it a `fetchChunk`
|
|
134
96
|
* function and it drives the sheet's lazy loading: it loads the chunk covering
|
|
@@ -157,6 +119,11 @@ export declare function createPostgRESTFetchChunk<T = any>(config: {
|
|
|
157
119
|
endpoint: string;
|
|
158
120
|
table: string;
|
|
159
121
|
identityKey: string;
|
|
122
|
+
/** Default ordering direction of the identity key (applied when no active
|
|
123
|
+
* sort targets it). `false` ⇒ the table defaults to identity-descending
|
|
124
|
+
* (e.g. newest `source_id` first) without a redundant `baseOrder` entry that
|
|
125
|
+
* would otherwise collide with the identity tiebreaker. Defaults to `true`. */
|
|
126
|
+
identityAscending?: boolean;
|
|
160
127
|
columns?: string | string[];
|
|
161
128
|
/** Order applied before the active column sorts (identity key appended last). */
|
|
162
129
|
baseOrder?: PostgrestOrder<any>[];
|
|
@@ -176,6 +143,9 @@ export declare function createPostgRESTProvider<T = any>(config: {
|
|
|
176
143
|
endpoint: string;
|
|
177
144
|
table: string;
|
|
178
145
|
identityKey: string;
|
|
146
|
+
/** Default ordering direction of the identity key (see
|
|
147
|
+
* `createPostgRESTFetchChunk`). `false` ⇒ identity-descending by default. */
|
|
148
|
+
identityAscending?: boolean;
|
|
179
149
|
columns?: string | string[];
|
|
180
150
|
baseOrder?: PostgrestOrder<any>[];
|
|
181
151
|
baseFilter?: (q: PostgrestFilterBuilder<any, any, any, any>) => PostgrestFilterBuilder<any, any, any, any>;
|
|
@@ -4,8 +4,9 @@ import { useRef, useMemo, useEffect, useCallback } from "react";
|
|
|
4
4
|
import update from "immutability-helper";
|
|
5
5
|
import { PostgrestClient } from "@supabase/postgrest-js";
|
|
6
6
|
import { adjustArraySize } from "./loading-utils.js";
|
|
7
|
-
import { tableDataAtom, ctx, useSelector } from "../provider.js";
|
|
8
7
|
import { atom } from "jotai";
|
|
8
|
+
import { tableDataAtom, ctx, dataProviderAtom, useSelector } from "../provider/core.js";
|
|
9
|
+
import { dataRefreshTokenAtom } from "../provider/table-data.js";
|
|
9
10
|
function standardizeFilter(columnFilter) {
|
|
10
11
|
return {
|
|
11
12
|
type: "filter",
|
|
@@ -17,11 +18,22 @@ function standardizeFilter(columnFilter) {
|
|
|
17
18
|
function applyColumnFilters(req, filters) {
|
|
18
19
|
for (const cf of filters) {
|
|
19
20
|
if (cf.value === "" || cf.value == null) continue;
|
|
21
|
+
if (cf.operator === "cs") {
|
|
22
|
+
req = req.contains(cf.key, splitFilterList(cf.value));
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (cf.operator === "ov") {
|
|
26
|
+
req = req.overlaps(cf.key, splitFilterList(cf.value));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
20
29
|
const val = cf.operator === "like" || cf.operator === "ilike" ? `*${cf.value}*` : cf.value;
|
|
21
30
|
req = req.filter(cf.key, cf.operator, val);
|
|
22
31
|
}
|
|
23
32
|
return req;
|
|
24
33
|
}
|
|
34
|
+
function splitFilterList(value) {
|
|
35
|
+
return String(value).split(",").map((s) => s.trim()).filter((s) => s !== "");
|
|
36
|
+
}
|
|
25
37
|
function lazyLoadingReducer(state, action) {
|
|
26
38
|
switch (action.type) {
|
|
27
39
|
case "start-loading":
|
|
@@ -78,6 +90,31 @@ function lazyLoadingReducer(state, action) {
|
|
|
78
90
|
return state;
|
|
79
91
|
}
|
|
80
92
|
}
|
|
93
|
+
function formatKeysetValue(v) {
|
|
94
|
+
const s = String(v);
|
|
95
|
+
if (s === "" || /[,.:()"\\ ]/.test(s)) {
|
|
96
|
+
return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
97
|
+
}
|
|
98
|
+
return s;
|
|
99
|
+
}
|
|
100
|
+
function keysetEq(key, v) {
|
|
101
|
+
return v == null ? `${key}.is.null` : `${key}.eq.${formatKeysetValue(v)}`;
|
|
102
|
+
}
|
|
103
|
+
function buildKeysetPredicate(clauses, lastRow) {
|
|
104
|
+
const terms = [];
|
|
105
|
+
for (let i = 0; i < clauses.length; i++) {
|
|
106
|
+
const v = lastRow[clauses[i].key];
|
|
107
|
+
if (v == null) continue;
|
|
108
|
+
const conds = [];
|
|
109
|
+
for (let j = 0; j < i; j++) {
|
|
110
|
+
conds.push(keysetEq(clauses[j].key, lastRow[clauses[j].key]));
|
|
111
|
+
}
|
|
112
|
+
const op = clauses[i].ascending ?? true ? "gt" : "lt";
|
|
113
|
+
conds.push(`${clauses[i].key}.${op}.${formatKeysetValue(v)}`);
|
|
114
|
+
terms.push(conds.length === 1 ? conds[0] : `and(${conds.join(",")})`);
|
|
115
|
+
}
|
|
116
|
+
return terms.length > 0 ? terms.join(",") : null;
|
|
117
|
+
}
|
|
81
118
|
function buildQuery(client, config) {
|
|
82
119
|
const { columns = "*", count, lastLoadedRowIndex } = config;
|
|
83
120
|
const opts = { count };
|
|
@@ -94,18 +131,17 @@ function buildQuery(client, config) {
|
|
|
94
131
|
}
|
|
95
132
|
const orderClauses = buildPostgrestOrderClauses(
|
|
96
133
|
config.order ?? [],
|
|
97
|
-
config.identityKey
|
|
134
|
+
config.identityOrder ?? config.identityKey
|
|
98
135
|
);
|
|
99
136
|
let hasOrdering = false;
|
|
100
137
|
for (const clause of orderClauses) {
|
|
101
138
|
query = query.order(clause.key, clause);
|
|
102
|
-
if (config.lastLoadedRow != null) {
|
|
103
|
-
const op = clause.ascending ?? true ? "gt" : "lt";
|
|
104
|
-
const value = config.lastLoadedRow[clause.key];
|
|
105
|
-
query = query[op](clause.key, value);
|
|
106
|
-
}
|
|
107
139
|
hasOrdering = true;
|
|
108
140
|
}
|
|
141
|
+
if (config.lastLoadedRow != null && hasOrdering) {
|
|
142
|
+
const pred = buildKeysetPredicate(orderClauses, config.lastLoadedRow);
|
|
143
|
+
if (pred != null) query = query.or(pred);
|
|
144
|
+
}
|
|
109
145
|
let offset = null;
|
|
110
146
|
if (!hasOrdering && lastLoadedRowIndex > 0) {
|
|
111
147
|
offset = lastLoadedRowIndex + 1;
|
|
@@ -118,7 +154,6 @@ function buildQuery(client, config) {
|
|
|
118
154
|
query = query.limit(config.limit);
|
|
119
155
|
}
|
|
120
156
|
}
|
|
121
|
-
console.log("query", query.url.search);
|
|
122
157
|
return query;
|
|
123
158
|
}
|
|
124
159
|
const defaultVisibleRegion = {
|
|
@@ -135,7 +170,6 @@ const lazyLoaderCoreStateAtom = atom({
|
|
|
135
170
|
pageSize: 100
|
|
136
171
|
});
|
|
137
172
|
const chunkPageAtom = atom(0);
|
|
138
|
-
const dataRefreshTokenAtom = atom(0);
|
|
139
173
|
const tableFooterAtom = atom((get) => {
|
|
140
174
|
const core = get(lazyLoaderCoreStateAtom);
|
|
141
175
|
const data = get(tableDataAtom) ?? [];
|
|
@@ -157,6 +191,44 @@ const tableFooterAtom = atom((get) => {
|
|
|
157
191
|
totalPages
|
|
158
192
|
};
|
|
159
193
|
});
|
|
194
|
+
const autoLoadPagesAtom = atom(null);
|
|
195
|
+
const resumeBaselineAtom = atom(0);
|
|
196
|
+
function useLoadControls() {
|
|
197
|
+
const footer = ctx.useValue(tableFooterAtom);
|
|
198
|
+
const data = ctx.useValue(tableDataAtom) ?? [];
|
|
199
|
+
const { isLocalProvider } = ctx.useValue(dataProviderAtom);
|
|
200
|
+
const resumeBaseline = ctx.useValue(resumeBaselineAtom);
|
|
201
|
+
const autoLoadPages = ctx.useValue(autoLoadPagesAtom);
|
|
202
|
+
const setResumeBaseline = ctx.useSet(resumeBaselineAtom);
|
|
203
|
+
const setVisibleRegion = ctx.useSet(visibleRegionAtom);
|
|
204
|
+
let loadedCount = 0;
|
|
205
|
+
for (const row of data) if (row != null) loadedCount++;
|
|
206
|
+
const pageSize = footer.pageSize || 100;
|
|
207
|
+
const dataLength = data.length;
|
|
208
|
+
const hasMore = !isLocalProvider && loadedCount < dataLength;
|
|
209
|
+
const paused = autoLoadPages != null && loadedCount - resumeBaseline >= autoLoadPages * pageSize;
|
|
210
|
+
const canLoadMore = hasMore && !footer.loading && !paused;
|
|
211
|
+
const advance = useCallback(() => {
|
|
212
|
+
setVisibleRegion({
|
|
213
|
+
rowIndexStart: 0,
|
|
214
|
+
rowIndexEnd: Math.min(loadedCount + pageSize, dataLength)
|
|
215
|
+
});
|
|
216
|
+
}, [setVisibleRegion, loadedCount, pageSize, dataLength]);
|
|
217
|
+
const loadMore = useCallback(() => {
|
|
218
|
+
setResumeBaseline(loadedCount);
|
|
219
|
+
advance();
|
|
220
|
+
}, [setResumeBaseline, loadedCount, advance]);
|
|
221
|
+
return {
|
|
222
|
+
loadMore,
|
|
223
|
+
loading: footer.loading,
|
|
224
|
+
hasMore,
|
|
225
|
+
loaded: footer.loaded,
|
|
226
|
+
total: footer.total,
|
|
227
|
+
paused,
|
|
228
|
+
canLoadMore,
|
|
229
|
+
advance
|
|
230
|
+
};
|
|
231
|
+
}
|
|
160
232
|
const viewInfoAtom = atom((get) => {
|
|
161
233
|
const state = get(lazyLoaderStateAtom);
|
|
162
234
|
return {
|
|
@@ -204,22 +276,27 @@ function useLazyLoaderReducer() {
|
|
|
204
276
|
function buildPostgrestOrderClauses(sorts, identityOrder) {
|
|
205
277
|
const identitySort = typeof identityOrder == "string" ? { key: identityOrder, ascending: true } : identityOrder;
|
|
206
278
|
const identityKey = identitySort.key;
|
|
207
|
-
const
|
|
208
|
-
|
|
279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
280
|
+
const clauses = [];
|
|
281
|
+
for (const sort of sorts) {
|
|
282
|
+
if (seen.has(sort.key)) continue;
|
|
283
|
+
seen.add(sort.key);
|
|
284
|
+
clauses.push({
|
|
209
285
|
key: sort.key,
|
|
210
286
|
ascending: sort.ascending,
|
|
211
287
|
nullsFirst: "nullsFirst" in sort ? sort.nullsFirst : false
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
const hasIdentityClause = clauses.some((d) => d.key === identityKey);
|
|
215
|
-
if (hasIdentityClause) {
|
|
216
|
-
clauses.sort((a, b) => {
|
|
217
|
-
if (a.key === identityKey) return 1;
|
|
218
|
-
if (b.key === identityKey) return -1;
|
|
219
|
-
return 0;
|
|
220
288
|
});
|
|
289
|
+
}
|
|
290
|
+
if (seen.has(identityKey)) {
|
|
291
|
+
const idx = clauses.findIndex((c) => c.key === identityKey);
|
|
292
|
+
const [idClause] = clauses.splice(idx, 1);
|
|
293
|
+
clauses.push(idClause);
|
|
221
294
|
} else {
|
|
222
|
-
clauses.push(
|
|
295
|
+
clauses.push({
|
|
296
|
+
key: identitySort.key,
|
|
297
|
+
ascending: identitySort.ascending ?? true,
|
|
298
|
+
nullsFirst: identitySort.nullsFirst ?? false
|
|
299
|
+
});
|
|
223
300
|
}
|
|
224
301
|
return clauses;
|
|
225
302
|
}
|
|
@@ -237,59 +314,10 @@ function useScrollHandler() {
|
|
|
237
314
|
[setVisibleRegion]
|
|
238
315
|
);
|
|
239
316
|
}
|
|
240
|
-
function createLocalProvider(data, options = {}) {
|
|
241
|
-
const identity = options.identity ?? defaultLocalIdentity;
|
|
242
|
-
return {
|
|
243
|
-
identity,
|
|
244
|
-
async fetchData({ offset, limit, sorts, filters }) {
|
|
245
|
-
let rows = data;
|
|
246
|
-
if (filters != null && filters.length > 0) {
|
|
247
|
-
rows = rows.filter(
|
|
248
|
-
(row) => filters.every(
|
|
249
|
-
(f) => f.predicate != null ? f.predicate(row, f.state) : true
|
|
250
|
-
)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (sorts != null && sorts.length > 0) {
|
|
254
|
-
rows = [...rows].sort(compareRowsBySorts(sorts));
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
rows: rows.slice(offset, offset + limit),
|
|
258
|
-
totalCount: rows.length
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
const _syntheticRowIds = /* @__PURE__ */ new WeakMap();
|
|
264
|
-
let _syntheticRowCounter = 0;
|
|
265
|
-
function defaultLocalIdentity(row) {
|
|
266
|
-
if (row == null) return void 0;
|
|
267
|
-
if (row.id != null) return row.id;
|
|
268
|
-
if (typeof row !== "object") return row;
|
|
269
|
-
let id = _syntheticRowIds.get(row);
|
|
270
|
-
if (id == null) {
|
|
271
|
-
id = `__row_${_syntheticRowCounter++}`;
|
|
272
|
-
_syntheticRowIds.set(row, id);
|
|
273
|
-
}
|
|
274
|
-
return id;
|
|
275
|
-
}
|
|
276
|
-
function compareRowsBySorts(sorts) {
|
|
277
|
-
return (a, b) => {
|
|
278
|
-
for (const sort of sorts) {
|
|
279
|
-
const av = a?.[sort.key];
|
|
280
|
-
const bv = b?.[sort.key];
|
|
281
|
-
if (av == null && bv == null) continue;
|
|
282
|
-
if (av == null) return sort.ascending ? -1 : 1;
|
|
283
|
-
if (bv == null) return sort.ascending ? 1 : -1;
|
|
284
|
-
const cmp = av < bv ? -1 : av > bv ? 1 : 0;
|
|
285
|
-
if (cmp !== 0) return sort.ascending ? cmp : -cmp;
|
|
286
|
-
}
|
|
287
|
-
return 0;
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
317
|
function useDataLoader(fetchChunk, options = {}) {
|
|
291
318
|
const { pageSize = 100, fetchMode = "scroll" } = options;
|
|
292
319
|
const [state, dispatch] = useLazyLoaderReducer();
|
|
320
|
+
const { isLocalProvider, provider } = ctx.useValue(dataProviderAtom);
|
|
293
321
|
const visibleRegion = ctx.useValue(visibleRegionAtom);
|
|
294
322
|
const page = ctx.useValue(chunkPageAtom);
|
|
295
323
|
const setPage = ctx.useSet(chunkPageAtom);
|
|
@@ -396,8 +424,8 @@ function createPostgRESTFetchChunk(config) {
|
|
|
396
424
|
return async ({ limit, signal, sorts, filters, cursor }) => {
|
|
397
425
|
const client = new PostgrestClient(config.endpoint).from(config.table);
|
|
398
426
|
const order = [
|
|
399
|
-
...
|
|
400
|
-
...
|
|
427
|
+
...sorts.map((s) => ({ key: s.key, ascending: s.ascending })),
|
|
428
|
+
...config.baseOrder ?? []
|
|
401
429
|
];
|
|
402
430
|
const pgFilters = [];
|
|
403
431
|
if (config.baseFilter != null) {
|
|
@@ -414,6 +442,10 @@ function createPostgRESTFetchChunk(config) {
|
|
|
414
442
|
count: cursor == null ? "exact" : void 0,
|
|
415
443
|
limit,
|
|
416
444
|
identityKey: config.identityKey,
|
|
445
|
+
identityOrder: {
|
|
446
|
+
key: config.identityKey,
|
|
447
|
+
ascending: config.identityAscending ?? true
|
|
448
|
+
},
|
|
417
449
|
order,
|
|
418
450
|
filters: pgFilters,
|
|
419
451
|
lastLoadedRow: cursor?.row ?? null,
|
|
@@ -453,7 +485,8 @@ function standardColumnFilter(f) {
|
|
|
453
485
|
return null;
|
|
454
486
|
}
|
|
455
487
|
function indexOfFirstNullInRegion(data, region) {
|
|
456
|
-
|
|
488
|
+
const end = Math.min(region.rowIndexEnd, data.length);
|
|
489
|
+
for (let i = region.rowIndexStart; i < end; i++) {
|
|
457
490
|
if (data[i] == null) {
|
|
458
491
|
return i;
|
|
459
492
|
}
|
|
@@ -462,15 +495,15 @@ function indexOfFirstNullInRegion(data, region) {
|
|
|
462
495
|
}
|
|
463
496
|
export {
|
|
464
497
|
applyColumnFilters,
|
|
498
|
+
autoLoadPagesAtom,
|
|
465
499
|
chunkPageAtom,
|
|
466
|
-
compareRowsBySorts,
|
|
467
|
-
createLocalProvider,
|
|
468
500
|
createPostgRESTFetchChunk,
|
|
469
501
|
createPostgRESTProvider,
|
|
470
|
-
|
|
502
|
+
resumeBaselineAtom,
|
|
471
503
|
standardizeFilter,
|
|
472
504
|
tableFooterAtom,
|
|
473
505
|
useDataLoader,
|
|
506
|
+
useLoadControls,
|
|
474
507
|
useScrollHandler,
|
|
475
508
|
viewInfoAtom
|
|
476
509
|
};
|