@macrostrat/data-sheet 4.7.0 → 4.8.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.
- package/CHANGELOG.md +14 -0
- package/dist/data-panel.cjs +36 -0
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.d.ts +3 -2
- package/dist/data-panel.js +37 -1
- package/dist/data-panel.js.map +1 -1
- package/dist/data-panel.module.sass.cjs +28 -26
- package/dist/data-panel.module.sass.cjs.map +1 -1
- package/dist/data-panel.module.sass.js +28 -26
- package/dist/data-panel.module.sass.js.map +1 -1
- package/dist/data-sheet.css +59 -36
- package/dist/data-sheet.d.ts +2 -1
- package/dist/data-view.d.ts +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -1
- package/dist/postgrest-table/data-loaders.cjs +8 -1
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.js +9 -2
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/provider/core.cjs +16 -3
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +1 -1
- package/dist/provider/core.js +16 -3
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/loader-state.cjs +11 -3
- package/dist/provider/loader-state.cjs.map +1 -1
- package/dist/provider/loader-state.d.ts +8 -1
- package/dist/provider/loader-state.js +12 -4
- package/dist/provider/loader-state.js.map +1 -1
- package/dist/provider/table-data.cjs +10 -1
- package/dist/provider/table-data.cjs.map +1 -1
- package/dist/provider/table-data.d.ts +10 -0
- package/dist/provider/table-data.js +11 -2
- package/dist/provider/table-data.js.map +1 -1
- package/dist/provider/types.cjs.map +1 -1
- package/dist/provider/types.d.ts +3 -0
- package/dist/provider/types.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/data-panel.module.sass +25 -0
- package/src/data-panel.ts +50 -1
- package/src/postgrest-table/data-loaders.ts +13 -0
- package/src/provider/core.ts +22 -5
- package/src/provider/loader-state.ts +15 -2
- package/src/provider/table-data.ts +23 -1
- package/src/provider/types.ts +3 -0
- package/src/types.ts +26 -0
package/src/provider/core.ts
CHANGED
|
@@ -162,7 +162,14 @@ export function useResolvedProvider<T>(props: {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
function DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {
|
|
165
|
-
const {
|
|
165
|
+
const {
|
|
166
|
+
toaster,
|
|
167
|
+
initialFilters,
|
|
168
|
+
initialSorts,
|
|
169
|
+
initialData,
|
|
170
|
+
startAfter,
|
|
171
|
+
...rest
|
|
172
|
+
} = props;
|
|
166
173
|
|
|
167
174
|
// Initial view state is folded into the store's *creation*, not applied in an
|
|
168
175
|
// effect: the loader mounts below this and its effects run first, so an
|
|
@@ -186,7 +193,10 @@ function DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {
|
|
|
186
193
|
{
|
|
187
194
|
ctx,
|
|
188
195
|
initializeStore,
|
|
189
|
-
atoms: [
|
|
196
|
+
atoms: [
|
|
197
|
+
[toasterAtom, toaster],
|
|
198
|
+
...loaderSeedAtoms(initialData, startAfter),
|
|
199
|
+
],
|
|
190
200
|
debugName: "DataSheetProvider",
|
|
191
201
|
},
|
|
192
202
|
h(DataSheetProviderInner, rest),
|
|
@@ -258,12 +268,19 @@ export function splitDataProviderProps<T>(props: AnyDataSheetProps<T>) {
|
|
|
258
268
|
.union(interactionOptionsKeys)
|
|
259
269
|
.union(tableDataProviderKeys) as Set<keyof DataSheetProviderProps<T>>,
|
|
260
270
|
);
|
|
261
|
-
// `initialData`
|
|
262
|
-
// with
|
|
263
|
-
|
|
271
|
+
// `initialData` and `startAfter` go to both sides: the provider creates the
|
|
272
|
+
// store seeded with them, and the loader takes them as the first window it
|
|
273
|
+
// needn't fetch and the cursor its chunks are counted from.
|
|
274
|
+
const { initialData, startAfter } = props as {
|
|
275
|
+
initialData?: any;
|
|
276
|
+
startAfter?: string | number | null;
|
|
277
|
+
};
|
|
264
278
|
if (initialData != null) {
|
|
265
279
|
providerProps.initialData = initialData;
|
|
266
280
|
}
|
|
281
|
+
if (startAfter != null) {
|
|
282
|
+
providerProps.startAfter = startAfter;
|
|
283
|
+
}
|
|
267
284
|
return [providerProps, rendererProps] as const;
|
|
268
285
|
}
|
|
269
286
|
|
|
@@ -70,13 +70,26 @@ export function seededLoaderCore<T>(
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** The identity of the row the current view starts after (`startAfter`), or
|
|
74
|
+
* `null` for a view that starts at the top. Set at store creation so a server
|
|
75
|
+
* render shows the "Return to top" link; the loader clears it on the first view
|
|
76
|
+
* change. */
|
|
77
|
+
export const startAfterAtom = atom<string | number | null>(null);
|
|
78
|
+
|
|
73
79
|
/** Scoped-store atoms that make a store start out seeded. The store's own
|
|
74
80
|
* `data` is seeded alongside (see `DataSheetStoreWrapper`). Empty when there is
|
|
75
81
|
* no seed. */
|
|
76
82
|
export function loaderSeedAtoms<T>(
|
|
77
83
|
initialData: FetchDataOptions<T>["initialData"],
|
|
84
|
+
startAfter: FetchDataOptions<T>["startAfter"] = null,
|
|
78
85
|
): AtomMap {
|
|
86
|
+
const atoms: AtomMap = [];
|
|
87
|
+
if (startAfter != null) {
|
|
88
|
+
atoms.push([startAfterAtom, startAfter]);
|
|
89
|
+
}
|
|
79
90
|
const seed = resolveInitialData(initialData);
|
|
80
|
-
if (seed
|
|
81
|
-
|
|
91
|
+
if (seed != null) {
|
|
92
|
+
atoms.push([lazyLoaderCoreStateAtom, seededLoaderCore(seed)]);
|
|
93
|
+
}
|
|
94
|
+
return atoms;
|
|
82
95
|
}
|
|
@@ -32,6 +32,12 @@ export interface FetchDataParams {
|
|
|
32
32
|
* sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a
|
|
33
33
|
* slow `OFFSET`; offset-based sources can ignore it. */
|
|
34
34
|
cursor?: { row: any; index: number } | null;
|
|
35
|
+
/** Identity of the row the view is counted from: `offset` 0 is the first
|
|
36
|
+
* row *after* it. Set while a view starts mid-list (see `startAfter` in
|
|
37
|
+
* `FetchDataOptions`); absent or `null` when it starts at the top. Keyset
|
|
38
|
+
* sources translate it to `WHERE key > after`; the local provider slices past
|
|
39
|
+
* the row. `totalCount` then reports the rows after it. */
|
|
40
|
+
after?: string | number | null;
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/** Result of a `fetchChunk` call. `totalCount` reports the source length when
|
|
@@ -125,7 +131,7 @@ export function createLocalProvider<T = any>(
|
|
|
125
131
|
|
|
126
132
|
return {
|
|
127
133
|
identity,
|
|
128
|
-
async fetchData({ offset, limit, sorts, filters }) {
|
|
134
|
+
async fetchData({ offset, limit, sorts, filters, after }) {
|
|
129
135
|
let rows = data;
|
|
130
136
|
if (filters != null && filters.length > 0) {
|
|
131
137
|
rows = rows.filter((row) =>
|
|
@@ -137,6 +143,7 @@ export function createLocalProvider<T = any>(
|
|
|
137
143
|
if (sorts != null && sorts.length > 0) {
|
|
138
144
|
rows = [...rows].sort(compareRowsBySorts(sorts));
|
|
139
145
|
}
|
|
146
|
+
rows = rowsAfter(rows, after, identity);
|
|
140
147
|
return {
|
|
141
148
|
rows: rows.slice(offset, offset + limit),
|
|
142
149
|
totalCount: rows.length,
|
|
@@ -148,6 +155,21 @@ export function createLocalProvider<T = any>(
|
|
|
148
155
|
};
|
|
149
156
|
}
|
|
150
157
|
|
|
158
|
+
/** The rows past the one with identity `after` in the (filtered, sorted) view;
|
|
159
|
+
* the whole view when `after` is absent or names no row. Identities are compared
|
|
160
|
+
* as strings, since a cursor read from a URL arrives as one. */
|
|
161
|
+
export function rowsAfter<T>(
|
|
162
|
+
rows: T[],
|
|
163
|
+
after: string | number | null | undefined,
|
|
164
|
+
identity: (row: T) => string | number | null | undefined,
|
|
165
|
+
): T[] {
|
|
166
|
+
if (after == null) return rows;
|
|
167
|
+
const key = String(after);
|
|
168
|
+
const index = rows.findIndex((row) => String(identity(row)) === key);
|
|
169
|
+
if (index < 0) return rows;
|
|
170
|
+
return rows.slice(index + 1);
|
|
171
|
+
}
|
|
172
|
+
|
|
151
173
|
// Stable synthetic identity for in-memory rows lacking a natural `id`. Keyed by
|
|
152
174
|
// object reference (a local data array keeps the same row objects across
|
|
153
175
|
// re-sorts), so edits survive re-ordering even without an id field.
|
package/src/provider/types.ts
CHANGED
|
@@ -255,6 +255,9 @@ export type DataSheetProviderProps<T> = DataViewCoreProps<T> & {
|
|
|
255
255
|
* The provider creates the store seeded with it, so the rows are in the very
|
|
256
256
|
* first render — a server render included. */
|
|
257
257
|
initialData?: FetchDataOptions<T>["initialData"];
|
|
258
|
+
/** The row the view starts after (see `FetchDataOptions`). Seeded into the
|
|
259
|
+
* store at creation alongside `initialData`. */
|
|
260
|
+
startAfter?: FetchDataOptions<T>["startAfter"];
|
|
258
261
|
viewType?: DataViewRendererType;
|
|
259
262
|
children?: React.ReactNode;
|
|
260
263
|
};
|
package/src/types.ts
CHANGED
|
@@ -39,6 +39,14 @@ export interface FetchDataOptions<T = any> {
|
|
|
39
39
|
* Pass `totalCount` when it's known — the array is pre-sized to it, so the
|
|
40
40
|
* scrollbar and the counter are right from the first paint. */
|
|
41
41
|
initialData?: T[] | InitialDataChunk<T>;
|
|
42
|
+
/** Identity of the row the view starts after — the keyset cursor of a view
|
|
43
|
+
* that begins mid-list, as reached through a page link (`?after=<id>`). It is
|
|
44
|
+
* passed to the provider as `after` on every chunk of the view it was created
|
|
45
|
+
* for, and dropped on the first view change (sorts, filters, a refresh), since
|
|
46
|
+
* it only describes that view. Read from the URL when the page loads; the
|
|
47
|
+
* client never writes it back while scrolling. Pair it with an `initialData`
|
|
48
|
+
* seed of the rows after it for a complete server render. */
|
|
49
|
+
startAfter?: string | number | null;
|
|
42
50
|
/** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a
|
|
43
51
|
* text filter) collapse into one fetch once the view settles. The input stays
|
|
44
52
|
* instant; only the fetch waits. `0` (default) keeps immediate refetching. */
|
|
@@ -88,8 +96,26 @@ export interface DataViewCoreProps<T> extends InteractionOptions {
|
|
|
88
96
|
initialSorts?: ColumnSort[];
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
/** Links that make a paged view reachable without JavaScript. */
|
|
100
|
+
export interface PageLinks<T = any> {
|
|
101
|
+
/** The href of the view that starts after `row` (`?after=<id>`). Rendered as
|
|
102
|
+
* a visually hidden `rel="next"` link after the loaded rows, so a crawler
|
|
103
|
+
* following the server-rendered HTML reaches every page of the list while
|
|
104
|
+
* readers keep the infinite scroll. */
|
|
105
|
+
after: (row: T) => string;
|
|
106
|
+
/** The href of the view's first page. Shown as a "Return to top" link at the
|
|
107
|
+
* head of the content while the view starts mid-list (`startAfter`). */
|
|
108
|
+
top?: string;
|
|
109
|
+
/** Label for that link (default "Return to top"). */
|
|
110
|
+
topLabel?: ReactNode;
|
|
111
|
+
}
|
|
112
|
+
|
|
91
113
|
export interface DataViewSharedProps<T = any>
|
|
92
114
|
extends FetchDataOptions<T>, DataViewCoreProps<T> {
|
|
115
|
+
/** Crawlable page links (see `PageLinks`). Neither link is written to the
|
|
116
|
+
* browser's URL as the list is scrolled — deep pages are for crawlers and
|
|
117
|
+
* for whoever follows such a link, not a state the page keeps. */
|
|
118
|
+
pageLinks?: PageLinks<T>;
|
|
93
119
|
/** Configurable table actions shown in a selection-aware toolbar.
|
|
94
120
|
* When provided, the actions toolbar renders alongside the existing
|
|
95
121
|
* edit toolbar. Actions are filtered by the current selection cardinality. */
|