@macrostrat/data-sheet 4.5.2 → 4.7.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 +18 -0
- package/dist/data-panel.cjs +9 -4
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.d.ts +7 -0
- package/dist/data-panel.js +9 -4
- package/dist/data-panel.js.map +1 -1
- package/dist/data-sheet.css +25 -0
- package/dist/data-sheet.d.ts +1 -0
- package/dist/data-view.d.ts +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/masonry.cjs +118 -0
- package/dist/masonry.cjs.map +1 -0
- package/dist/masonry.d.ts +17 -0
- package/dist/masonry.js +118 -0
- package/dist/masonry.js.map +1 -0
- package/dist/masonry.module.sass.cjs +14 -0
- package/dist/masonry.module.sass.cjs.map +1 -0
- package/dist/masonry.module.sass.js +13 -0
- package/dist/masonry.module.sass.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +16 -26
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.js +12 -22
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/provider/core.cjs +22 -6
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +1 -1
- package/dist/provider/core.js +22 -6
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/loader-state.cjs +47 -0
- package/dist/provider/loader-state.cjs.map +1 -0
- package/dist/provider/loader-state.d.ts +33 -0
- package/dist/provider/loader-state.js +47 -0
- package/dist/provider/loader-state.js.map +1 -0
- package/dist/provider/types.cjs.map +1 -1
- package/dist/provider/types.d.ts +5 -1
- package/dist/provider/types.js.map +1 -1
- package/package.json +3 -3
- package/src/data-panel.ts +17 -5
- package/src/index.ts +1 -0
- package/src/masonry.module.sass +29 -0
- package/src/masonry.ts +217 -0
- package/src/postgrest-table/data-loaders.ts +22 -41
- package/src/provider/core.ts +48 -6
- package/src/provider/loader-state.ts +82 -0
- package/src/provider/types.ts +5 -1
package/dist/masonry.cjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const masonry_module = require("./masonry.module.sass.cjs");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const FALLBACK_ITEM_HEIGHT = 160;
|
|
6
|
+
function MasonryScrollBody(props) {
|
|
7
|
+
const { children, placeholders, columns = 2, minColumnWidth } = props;
|
|
8
|
+
const containerRef = react.useRef(null);
|
|
9
|
+
const nCols = useColumnCount(containerRef, columns, minColumnWidth);
|
|
10
|
+
const stateRef = react.useRef(null);
|
|
11
|
+
stateRef.current ??= {
|
|
12
|
+
columns: nCols,
|
|
13
|
+
assign: /* @__PURE__ */ new Map(),
|
|
14
|
+
heights: /* @__PURE__ */ new Map(),
|
|
15
|
+
els: /* @__PURE__ */ new Map(),
|
|
16
|
+
refs: /* @__PURE__ */ new Map()
|
|
17
|
+
};
|
|
18
|
+
const state = stateRef.current;
|
|
19
|
+
const [, bump] = react.useReducer((x) => x + 1, 0);
|
|
20
|
+
const items = react.Children.toArray(children).filter(
|
|
21
|
+
react.isValidElement
|
|
22
|
+
);
|
|
23
|
+
react.useLayoutEffect(() => {
|
|
24
|
+
if (state.columns !== nCols) {
|
|
25
|
+
state.columns = nCols;
|
|
26
|
+
state.assign.clear();
|
|
27
|
+
}
|
|
28
|
+
for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);
|
|
29
|
+
const present = new Set(items.map(keyOf));
|
|
30
|
+
for (const key of [...state.assign.keys()]) {
|
|
31
|
+
if (!present.has(key)) state.assign.delete(key);
|
|
32
|
+
}
|
|
33
|
+
for (const key of [...state.heights.keys()]) {
|
|
34
|
+
if (!present.has(key)) state.heights.delete(key);
|
|
35
|
+
}
|
|
36
|
+
const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));
|
|
37
|
+
if (unassigned.length === 0) return;
|
|
38
|
+
const colHeights = new Array(nCols).fill(0);
|
|
39
|
+
for (const [key, col] of state.assign) {
|
|
40
|
+
colHeights[col] += state.heights.get(key) ?? 0;
|
|
41
|
+
}
|
|
42
|
+
for (const child of unassigned) {
|
|
43
|
+
const key = keyOf(child);
|
|
44
|
+
let col = 0;
|
|
45
|
+
for (let c = 1; c < nCols; c++) {
|
|
46
|
+
if (colHeights[c] < colHeights[col]) col = c;
|
|
47
|
+
}
|
|
48
|
+
state.assign.set(key, col);
|
|
49
|
+
colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;
|
|
50
|
+
}
|
|
51
|
+
bump();
|
|
52
|
+
});
|
|
53
|
+
const stale = state.columns !== nCols;
|
|
54
|
+
const columnItems = Array.from({ length: nCols }, () => []);
|
|
55
|
+
items.forEach((child, i) => {
|
|
56
|
+
const key = keyOf(child);
|
|
57
|
+
let assigned = void 0;
|
|
58
|
+
if (!stale) {
|
|
59
|
+
assigned = state.assign.get(key);
|
|
60
|
+
}
|
|
61
|
+
const col = assigned ?? i % nCols;
|
|
62
|
+
columnItems[col].push(
|
|
63
|
+
react.cloneElement(child, { ref: refFor(state, key) })
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
return masonry_module("div.data-panel-masonry-body", [
|
|
67
|
+
masonry_module(
|
|
68
|
+
"div.data-panel-masonry",
|
|
69
|
+
{ ref: containerRef },
|
|
70
|
+
columnItems.map(
|
|
71
|
+
(col, c) => masonry_module("div.data-panel-masonry-column", { key: c }, col)
|
|
72
|
+
)
|
|
73
|
+
),
|
|
74
|
+
masonry_module.if(placeholders != null)(
|
|
75
|
+
"div.data-panel-masonry-placeholders",
|
|
76
|
+
placeholders
|
|
77
|
+
)
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
function createMasonryScrollBody(options = {}) {
|
|
81
|
+
return function MasonryScrollBodyWithOptions(props) {
|
|
82
|
+
return masonry_module(MasonryScrollBody, { ...options, ...props });
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function keyOf(child) {
|
|
86
|
+
return String(child.key);
|
|
87
|
+
}
|
|
88
|
+
function refFor(state, key) {
|
|
89
|
+
let cb = state.refs.get(key);
|
|
90
|
+
if (cb == null) {
|
|
91
|
+
cb = (el) => {
|
|
92
|
+
if (el == null) {
|
|
93
|
+
state.els.delete(key);
|
|
94
|
+
} else {
|
|
95
|
+
state.els.set(key, el);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
state.refs.set(key, cb);
|
|
99
|
+
}
|
|
100
|
+
return cb;
|
|
101
|
+
}
|
|
102
|
+
function useColumnCount(ref, columns, minColumnWidth) {
|
|
103
|
+
const [width, setWidth] = react.useState(null);
|
|
104
|
+
react.useEffect(() => {
|
|
105
|
+
const el = ref.current;
|
|
106
|
+
if (minColumnWidth == null || el == null) return;
|
|
107
|
+
const obs = new ResizeObserver(([entry]) => {
|
|
108
|
+
setWidth(entry.contentRect.width);
|
|
109
|
+
});
|
|
110
|
+
obs.observe(el);
|
|
111
|
+
return () => obs.disconnect();
|
|
112
|
+
}, [minColumnWidth]);
|
|
113
|
+
if (minColumnWidth == null || width == null) return Math.max(1, columns);
|
|
114
|
+
return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));
|
|
115
|
+
}
|
|
116
|
+
exports.MasonryScrollBody = MasonryScrollBody;
|
|
117
|
+
exports.createMasonryScrollBody = createMasonryScrollBody;
|
|
118
|
+
//# sourceMappingURL=masonry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masonry.cjs","sources":["../src/masonry.ts"],"sourcesContent":["/**\n * Masonry scroll body for the `DataPanel` — variable-height cards laid out in\n * equal-width columns, balanced by *measured* height rather than a flat\n * estimate or CSS multi-column.\n *\n * The problem it solves is paging: CSS `columns` re-flows the whole list every\n * time a page is appended, so the cards under the user's cursor move. Here each\n * item is placed in the running-shortest column **once**, keyed by its React\n * key, and then frozen — appending a page never reshuffles what is on screen.\n *\n * Placement is measured: a freshly-appended batch mounts in provisional\n * columns, a `useLayoutEffect` reads each card's real `offsetHeight`, then the\n * batch is greedily assigned from those real heights and re-rendered — all\n * before paint, so only the balanced result is seen.\n *\n * Two things keep the balance honest over many pages:\n *\n * - **Placeholders are not items.** The panel's loading skeletons arrive as\n * `placeholders`, not `children`, and render below the columns. Freezing a\n * column assignment for a skeleton (measured at skeleton height, then\n * replaced by real content) is what makes a masonry drift, one page at a\n * time, into \"this whole page went into one column\".\n * - **Identity is the React key, not the array index.** A sort, filter or\n * refresh replaces the keys, and assignments for keys that are gone are\n * pruned — so column heights are always recomputed from items that are\n * actually on screen.\n */\nimport h from \"./masonry.module.sass\";\nimport {\n Children,\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n useEffect,\n useLayoutEffect,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { ScrollBodyProps } from \"./data-panel\";\n\n/** Height assumed for an item that hasn't been measured yet (it always is, by\n * the time it matters — this only guards a torn-down/hidden container). */\nconst FALLBACK_ITEM_HEIGHT = 160;\n\nexport interface MasonryOptions {\n /** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */\n columns?: number;\n /** If set, the column count drops below `columns` when the container is too\n * narrow to give every column at least this many pixels. */\n minColumnWidth?: number;\n}\n\ninterface MasonryState {\n /** Column count the current assignments were computed for. */\n columns: number;\n /** Frozen key → column. */\n assign: Map<string, number>;\n /** Last measured height per key. */\n heights: Map<string, number>;\n /** Mounted element per key, for measurement. */\n els: Map<string, HTMLElement>;\n /** Stable ref callbacks, so an item isn't detached/reattached every render. */\n refs: Map<string, (el: HTMLElement | null) => void>;\n}\n\n/**\n * A `scrollBody` component for `DataPanel` with the default two columns. For\n * anything else — a different column count, or responsive columns — build one\n * with `createMasonryScrollBody`.\n */\nexport function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions) {\n const { children, placeholders, columns = 2, minColumnWidth } = props;\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const nCols = useColumnCount(containerRef, columns, minColumnWidth);\n\n const stateRef = useRef<MasonryState | null>(null);\n stateRef.current ??= {\n columns: nCols,\n assign: new Map(),\n heights: new Map(),\n els: new Map(),\n refs: new Map(),\n };\n const state = stateRef.current;\n const [, bump] = useReducer((x: number) => x + 1, 0);\n\n const items = Children.toArray(children).filter(\n isValidElement,\n ) as ReactElement[];\n\n // Runs on every commit (no deps): measurement has to see the layout that was\n // just produced, including one caused by a resize or a card's own content\n // settling. It is cheap when nothing is unassigned, and re-renders only when\n // it actually assigns something — so there's no render loop.\n useLayoutEffect(() => {\n // A column-count change invalidates every assignment (a column may no\n // longer exist). Handled here, not in render, so render stays pure.\n if (state.columns !== nCols) {\n state.columns = nCols;\n state.assign.clear();\n }\n\n for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);\n\n const present = new Set(items.map(keyOf));\n for (const key of [...state.assign.keys()]) {\n if (!present.has(key)) state.assign.delete(key);\n }\n for (const key of [...state.heights.keys()]) {\n if (!present.has(key)) state.heights.delete(key);\n }\n\n const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));\n if (unassigned.length === 0) return;\n\n // Column heights from the items already frozen into them…\n const colHeights = new Array(nCols).fill(0);\n for (const [key, col] of state.assign) {\n colHeights[col] += state.heights.get(key) ?? 0;\n }\n // …then greedily place the new batch by its just-measured real heights.\n for (const child of unassigned) {\n const key = keyOf(child);\n let col = 0;\n for (let c = 1; c < nCols; c++) {\n if (colHeights[c] < colHeights[col]) col = c;\n }\n state.assign.set(key, col);\n colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;\n }\n bump(); // move the new batch into its balanced columns, before paint\n });\n\n // Items without an assignment yet render in a provisional column so they\n // mount and can be measured; the layout effect above then places them.\n const stale = state.columns !== nCols;\n const columnItems: ReactNode[][] = Array.from({ length: nCols }, () => []);\n items.forEach((child, i) => {\n const key = keyOf(child);\n let assigned: number | undefined = undefined;\n if (!stale) {\n assigned = state.assign.get(key);\n }\n const col = assigned ?? i % nCols;\n columnItems[col].push(\n cloneElement(child, { ref: refFor(state, key) } as any),\n );\n });\n\n return h(\"div.data-panel-masonry-body\", [\n h(\n \"div.data-panel-masonry\",\n { ref: containerRef },\n columnItems.map((col, c) =>\n h(\"div.data-panel-masonry-column\", { key: c }, col),\n ),\n ),\n h.if(placeholders != null)(\n \"div.data-panel-masonry-placeholders\",\n placeholders,\n ),\n ]);\n}\n\n/** Build a `scrollBody` masonry component with a fixed or responsive column\n * count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */\nexport function createMasonryScrollBody(options: MasonryOptions = {}) {\n return function MasonryScrollBodyWithOptions(props: ScrollBodyProps) {\n return h(MasonryScrollBody, { ...options, ...props });\n };\n}\n\nfunction keyOf(child: ReactElement): string {\n return String(child.key);\n}\n\n/** One stable ref callback per key — a fresh closure each render would detach\n * and reattach every card on every render. */\nfunction refFor(state: MasonryState, key: string) {\n let cb = state.refs.get(key);\n if (cb == null) {\n cb = (el: HTMLElement | null) => {\n if (el == null) {\n state.els.delete(key);\n } else {\n state.els.set(key, el);\n }\n };\n state.refs.set(key, cb);\n }\n return cb;\n}\n\n/** The effective column count: `columns`, reduced to fit `minColumnWidth`. */\nfunction useColumnCount(\n ref: { current: HTMLElement | null },\n columns: number,\n minColumnWidth: number | undefined,\n): number {\n const [width, setWidth] = useState<number | null>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (minColumnWidth == null || el == null) return;\n const obs = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n obs.observe(el);\n return () => obs.disconnect();\n }, [minColumnWidth]);\n\n if (minColumnWidth == null || width == null) return Math.max(1, columns);\n return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));\n}\n"],"names":["useRef","useReducer","Children","isValidElement","useLayoutEffect","cloneElement","h","useState","useEffect"],"mappings":";;;;AA4CA,MAAM,uBAAuB;AA4BtB,SAAS,kBAA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E,mBAAmB,EAAE,GAAG,SAAS,GAAG,OAAO;AAAA,EACtD;AACF;AAEA,SAAS,MAAM,OAA6B;AAC1C,SAAO,OAAO,MAAM,GAAG;AACzB;AAIA,SAAS,OAAO,OAAqB,KAAa;AAChD,MAAI,KAAK,MAAM,KAAK,IAAI,GAAG;AAC3B,MAAI,MAAM,MAAM;AACd,SAAK,CAAC,OAA2B;AAC/B,UAAI,MAAM,MAAM;AACd,cAAM,IAAI,OAAO,GAAG;AAAA,MACtB,OAAO;AACL,cAAM,IAAI,IAAI,KAAK,EAAE;AAAA,MACvB;AAAA,IACF;AACA,UAAM,KAAK,IAAI,KAAK,EAAE;AAAA,EACxB;AACA,SAAO;AACT;AAGA,SAAS,eACP,KACA,SACA,gBACQ;AACR,QAAM,CAAC,OAAO,QAAQ,IAAIC,MAAAA,SAAwB,IAAI;AAEtDC,QAAAA,UAAU,MAAM;AACd,UAAM,KAAK,IAAI;AACf,QAAI,kBAAkB,QAAQ,MAAM,KAAM;AAC1C,UAAM,MAAM,IAAI,eAAe,CAAC,CAAC,KAAK,MAAM;AAC1C,eAAS,MAAM,YAAY,KAAK;AAAA,IAClC,CAAC;AACD,QAAI,QAAQ,EAAE;AACd,WAAO,MAAM,IAAI,WAAA;AAAA,EACnB,GAAG,CAAC,cAAc,CAAC;AAEnB,MAAI,kBAAkB,QAAQ,SAAS,aAAa,KAAK,IAAI,GAAG,OAAO;AACvE,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,QAAQ,cAAc,CAAC,CAAC;AAC1E;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ScrollBodyProps } from './data-panel';
|
|
2
|
+
export interface MasonryOptions {
|
|
3
|
+
/** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */
|
|
4
|
+
columns?: number;
|
|
5
|
+
/** If set, the column count drops below `columns` when the container is too
|
|
6
|
+
* narrow to give every column at least this many pixels. */
|
|
7
|
+
minColumnWidth?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A `scrollBody` component for `DataPanel` with the default two columns. For
|
|
11
|
+
* anything else — a different column count, or responsive columns — build one
|
|
12
|
+
* with `createMasonryScrollBody`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions): import('react').DOMElement<import('react').DOMAttributes<Element>, Element>;
|
|
15
|
+
/** Build a `scrollBody` masonry component with a fixed or responsive column
|
|
16
|
+
* count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */
|
|
17
|
+
export declare function createMasonryScrollBody(options?: MasonryOptions): (props: ScrollBodyProps) => import('react').FunctionComponentElement<ScrollBodyProps & MasonryOptions>;
|
package/dist/masonry.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import h from "./masonry.module.sass.js";
|
|
2
|
+
import { useRef, useReducer, Children, isValidElement, useLayoutEffect, cloneElement, useState, useEffect } from "react";
|
|
3
|
+
const FALLBACK_ITEM_HEIGHT = 160;
|
|
4
|
+
function MasonryScrollBody(props) {
|
|
5
|
+
const { children, placeholders, columns = 2, minColumnWidth } = props;
|
|
6
|
+
const containerRef = useRef(null);
|
|
7
|
+
const nCols = useColumnCount(containerRef, columns, minColumnWidth);
|
|
8
|
+
const stateRef = useRef(null);
|
|
9
|
+
stateRef.current ??= {
|
|
10
|
+
columns: nCols,
|
|
11
|
+
assign: /* @__PURE__ */ new Map(),
|
|
12
|
+
heights: /* @__PURE__ */ new Map(),
|
|
13
|
+
els: /* @__PURE__ */ new Map(),
|
|
14
|
+
refs: /* @__PURE__ */ new Map()
|
|
15
|
+
};
|
|
16
|
+
const state = stateRef.current;
|
|
17
|
+
const [, bump] = useReducer((x) => x + 1, 0);
|
|
18
|
+
const items = Children.toArray(children).filter(
|
|
19
|
+
isValidElement
|
|
20
|
+
);
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
if (state.columns !== nCols) {
|
|
23
|
+
state.columns = nCols;
|
|
24
|
+
state.assign.clear();
|
|
25
|
+
}
|
|
26
|
+
for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);
|
|
27
|
+
const present = new Set(items.map(keyOf));
|
|
28
|
+
for (const key of [...state.assign.keys()]) {
|
|
29
|
+
if (!present.has(key)) state.assign.delete(key);
|
|
30
|
+
}
|
|
31
|
+
for (const key of [...state.heights.keys()]) {
|
|
32
|
+
if (!present.has(key)) state.heights.delete(key);
|
|
33
|
+
}
|
|
34
|
+
const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));
|
|
35
|
+
if (unassigned.length === 0) return;
|
|
36
|
+
const colHeights = new Array(nCols).fill(0);
|
|
37
|
+
for (const [key, col] of state.assign) {
|
|
38
|
+
colHeights[col] += state.heights.get(key) ?? 0;
|
|
39
|
+
}
|
|
40
|
+
for (const child of unassigned) {
|
|
41
|
+
const key = keyOf(child);
|
|
42
|
+
let col = 0;
|
|
43
|
+
for (let c = 1; c < nCols; c++) {
|
|
44
|
+
if (colHeights[c] < colHeights[col]) col = c;
|
|
45
|
+
}
|
|
46
|
+
state.assign.set(key, col);
|
|
47
|
+
colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;
|
|
48
|
+
}
|
|
49
|
+
bump();
|
|
50
|
+
});
|
|
51
|
+
const stale = state.columns !== nCols;
|
|
52
|
+
const columnItems = Array.from({ length: nCols }, () => []);
|
|
53
|
+
items.forEach((child, i) => {
|
|
54
|
+
const key = keyOf(child);
|
|
55
|
+
let assigned = void 0;
|
|
56
|
+
if (!stale) {
|
|
57
|
+
assigned = state.assign.get(key);
|
|
58
|
+
}
|
|
59
|
+
const col = assigned ?? i % nCols;
|
|
60
|
+
columnItems[col].push(
|
|
61
|
+
cloneElement(child, { ref: refFor(state, key) })
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
return h("div.data-panel-masonry-body", [
|
|
65
|
+
h(
|
|
66
|
+
"div.data-panel-masonry",
|
|
67
|
+
{ ref: containerRef },
|
|
68
|
+
columnItems.map(
|
|
69
|
+
(col, c) => h("div.data-panel-masonry-column", { key: c }, col)
|
|
70
|
+
)
|
|
71
|
+
),
|
|
72
|
+
h.if(placeholders != null)(
|
|
73
|
+
"div.data-panel-masonry-placeholders",
|
|
74
|
+
placeholders
|
|
75
|
+
)
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
function createMasonryScrollBody(options = {}) {
|
|
79
|
+
return function MasonryScrollBodyWithOptions(props) {
|
|
80
|
+
return h(MasonryScrollBody, { ...options, ...props });
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function keyOf(child) {
|
|
84
|
+
return String(child.key);
|
|
85
|
+
}
|
|
86
|
+
function refFor(state, key) {
|
|
87
|
+
let cb = state.refs.get(key);
|
|
88
|
+
if (cb == null) {
|
|
89
|
+
cb = (el) => {
|
|
90
|
+
if (el == null) {
|
|
91
|
+
state.els.delete(key);
|
|
92
|
+
} else {
|
|
93
|
+
state.els.set(key, el);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
state.refs.set(key, cb);
|
|
97
|
+
}
|
|
98
|
+
return cb;
|
|
99
|
+
}
|
|
100
|
+
function useColumnCount(ref, columns, minColumnWidth) {
|
|
101
|
+
const [width, setWidth] = useState(null);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const el = ref.current;
|
|
104
|
+
if (minColumnWidth == null || el == null) return;
|
|
105
|
+
const obs = new ResizeObserver(([entry]) => {
|
|
106
|
+
setWidth(entry.contentRect.width);
|
|
107
|
+
});
|
|
108
|
+
obs.observe(el);
|
|
109
|
+
return () => obs.disconnect();
|
|
110
|
+
}, [minColumnWidth]);
|
|
111
|
+
if (minColumnWidth == null || width == null) return Math.max(1, columns);
|
|
112
|
+
return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
MasonryScrollBody,
|
|
116
|
+
createMasonryScrollBody
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=masonry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masonry.js","sources":["../src/masonry.ts"],"sourcesContent":["/**\n * Masonry scroll body for the `DataPanel` — variable-height cards laid out in\n * equal-width columns, balanced by *measured* height rather than a flat\n * estimate or CSS multi-column.\n *\n * The problem it solves is paging: CSS `columns` re-flows the whole list every\n * time a page is appended, so the cards under the user's cursor move. Here each\n * item is placed in the running-shortest column **once**, keyed by its React\n * key, and then frozen — appending a page never reshuffles what is on screen.\n *\n * Placement is measured: a freshly-appended batch mounts in provisional\n * columns, a `useLayoutEffect` reads each card's real `offsetHeight`, then the\n * batch is greedily assigned from those real heights and re-rendered — all\n * before paint, so only the balanced result is seen.\n *\n * Two things keep the balance honest over many pages:\n *\n * - **Placeholders are not items.** The panel's loading skeletons arrive as\n * `placeholders`, not `children`, and render below the columns. Freezing a\n * column assignment for a skeleton (measured at skeleton height, then\n * replaced by real content) is what makes a masonry drift, one page at a\n * time, into \"this whole page went into one column\".\n * - **Identity is the React key, not the array index.** A sort, filter or\n * refresh replaces the keys, and assignments for keys that are gone are\n * pruned — so column heights are always recomputed from items that are\n * actually on screen.\n */\nimport h from \"./masonry.module.sass\";\nimport {\n Children,\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n useEffect,\n useLayoutEffect,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { ScrollBodyProps } from \"./data-panel\";\n\n/** Height assumed for an item that hasn't been measured yet (it always is, by\n * the time it matters — this only guards a torn-down/hidden container). */\nconst FALLBACK_ITEM_HEIGHT = 160;\n\nexport interface MasonryOptions {\n /** Number of columns (the maximum, when `minColumnWidth` is set). Default 2. */\n columns?: number;\n /** If set, the column count drops below `columns` when the container is too\n * narrow to give every column at least this many pixels. */\n minColumnWidth?: number;\n}\n\ninterface MasonryState {\n /** Column count the current assignments were computed for. */\n columns: number;\n /** Frozen key → column. */\n assign: Map<string, number>;\n /** Last measured height per key. */\n heights: Map<string, number>;\n /** Mounted element per key, for measurement. */\n els: Map<string, HTMLElement>;\n /** Stable ref callbacks, so an item isn't detached/reattached every render. */\n refs: Map<string, (el: HTMLElement | null) => void>;\n}\n\n/**\n * A `scrollBody` component for `DataPanel` with the default two columns. For\n * anything else — a different column count, or responsive columns — build one\n * with `createMasonryScrollBody`.\n */\nexport function MasonryScrollBody(props: ScrollBodyProps & MasonryOptions) {\n const { children, placeholders, columns = 2, minColumnWidth } = props;\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const nCols = useColumnCount(containerRef, columns, minColumnWidth);\n\n const stateRef = useRef<MasonryState | null>(null);\n stateRef.current ??= {\n columns: nCols,\n assign: new Map(),\n heights: new Map(),\n els: new Map(),\n refs: new Map(),\n };\n const state = stateRef.current;\n const [, bump] = useReducer((x: number) => x + 1, 0);\n\n const items = Children.toArray(children).filter(\n isValidElement,\n ) as ReactElement[];\n\n // Runs on every commit (no deps): measurement has to see the layout that was\n // just produced, including one caused by a resize or a card's own content\n // settling. It is cheap when nothing is unassigned, and re-renders only when\n // it actually assigns something — so there's no render loop.\n useLayoutEffect(() => {\n // A column-count change invalidates every assignment (a column may no\n // longer exist). Handled here, not in render, so render stays pure.\n if (state.columns !== nCols) {\n state.columns = nCols;\n state.assign.clear();\n }\n\n for (const [key, el] of state.els) state.heights.set(key, el.offsetHeight);\n\n const present = new Set(items.map(keyOf));\n for (const key of [...state.assign.keys()]) {\n if (!present.has(key)) state.assign.delete(key);\n }\n for (const key of [...state.heights.keys()]) {\n if (!present.has(key)) state.heights.delete(key);\n }\n\n const unassigned = items.filter((c) => !state.assign.has(keyOf(c)));\n if (unassigned.length === 0) return;\n\n // Column heights from the items already frozen into them…\n const colHeights = new Array(nCols).fill(0);\n for (const [key, col] of state.assign) {\n colHeights[col] += state.heights.get(key) ?? 0;\n }\n // …then greedily place the new batch by its just-measured real heights.\n for (const child of unassigned) {\n const key = keyOf(child);\n let col = 0;\n for (let c = 1; c < nCols; c++) {\n if (colHeights[c] < colHeights[col]) col = c;\n }\n state.assign.set(key, col);\n colHeights[col] += state.heights.get(key) ?? FALLBACK_ITEM_HEIGHT;\n }\n bump(); // move the new batch into its balanced columns, before paint\n });\n\n // Items without an assignment yet render in a provisional column so they\n // mount and can be measured; the layout effect above then places them.\n const stale = state.columns !== nCols;\n const columnItems: ReactNode[][] = Array.from({ length: nCols }, () => []);\n items.forEach((child, i) => {\n const key = keyOf(child);\n let assigned: number | undefined = undefined;\n if (!stale) {\n assigned = state.assign.get(key);\n }\n const col = assigned ?? i % nCols;\n columnItems[col].push(\n cloneElement(child, { ref: refFor(state, key) } as any),\n );\n });\n\n return h(\"div.data-panel-masonry-body\", [\n h(\n \"div.data-panel-masonry\",\n { ref: containerRef },\n columnItems.map((col, c) =>\n h(\"div.data-panel-masonry-column\", { key: c }, col),\n ),\n ),\n h.if(placeholders != null)(\n \"div.data-panel-masonry-placeholders\",\n placeholders,\n ),\n ]);\n}\n\n/** Build a `scrollBody` masonry component with a fixed or responsive column\n * count: `scrollBody: createMasonryScrollBody({ columns: 3 })`. */\nexport function createMasonryScrollBody(options: MasonryOptions = {}) {\n return function MasonryScrollBodyWithOptions(props: ScrollBodyProps) {\n return h(MasonryScrollBody, { ...options, ...props });\n };\n}\n\nfunction keyOf(child: ReactElement): string {\n return String(child.key);\n}\n\n/** One stable ref callback per key — a fresh closure each render would detach\n * and reattach every card on every render. */\nfunction refFor(state: MasonryState, key: string) {\n let cb = state.refs.get(key);\n if (cb == null) {\n cb = (el: HTMLElement | null) => {\n if (el == null) {\n state.els.delete(key);\n } else {\n state.els.set(key, el);\n }\n };\n state.refs.set(key, cb);\n }\n return cb;\n}\n\n/** The effective column count: `columns`, reduced to fit `minColumnWidth`. */\nfunction useColumnCount(\n ref: { current: HTMLElement | null },\n columns: number,\n minColumnWidth: number | undefined,\n): number {\n const [width, setWidth] = useState<number | null>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (minColumnWidth == null || el == null) return;\n const obs = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n obs.observe(el);\n return () => obs.disconnect();\n }, [minColumnWidth]);\n\n if (minColumnWidth == null || width == null) return Math.max(1, columns);\n return Math.max(1, Math.min(columns, Math.floor(width / minColumnWidth)));\n}\n"],"names":[],"mappings":";;AA4CA,MAAM,uBAAuB;AA4BtB,SAAS,kBAAkB,OAAyC;AACzE,QAAM,EAAE,UAAU,cAAc,UAAU,GAAG,mBAAmB;AAEhE,QAAM,eAAe,OAA8B,IAAI;AACvD,QAAM,QAAQ,eAAe,cAAc,SAAS,cAAc;AAElE,QAAM,WAAW,OAA4B,IAAI;AACjD,WAAS,YAAY;AAAA,IACnB,SAAS;AAAA,IACT,4BAAY,IAAA;AAAA,IACZ,6BAAa,IAAA;AAAA,IACb,yBAAS,IAAA;AAAA,IACT,0BAAU,IAAA;AAAA,EAAI;AAEhB,QAAM,QAAQ,SAAS;AACvB,QAAM,CAAA,EAAG,IAAI,IAAI,WAAW,CAAC,MAAc,IAAI,GAAG,CAAC;AAEnD,QAAM,QAAQ,SAAS,QAAQ,QAAQ,EAAE;AAAA,IACvC;AAAA,EAAA;AAOF,kBAAgB,MAAM;AAGpB,QAAI,MAAM,YAAY,OAAO;AAC3B,YAAM,UAAU;AAChB,YAAM,OAAO,MAAA;AAAA,IACf;AAEA,eAAW,CAAC,KAAK,EAAE,KAAK,MAAM,IAAK,OAAM,QAAQ,IAAI,KAAK,GAAG,YAAY;AAEzE,UAAM,UAAU,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACxC,eAAW,OAAO,CAAC,GAAG,MAAM,OAAO,KAAA,CAAM,GAAG;AAC1C,UAAI,CAAC,QAAQ,IAAI,GAAG,EAAG,OAAM,OAAO,OAAO,GAAG;AAAA,IAChD;AACA,eAAW,OAAO,CAAC,GAAG,MAAM,QAAQ,KAAA,CAAM,GAAG;AAC3C,UAAI,CAAC,QAAQ,IAAI,GAAG,EAAG,OAAM,QAAQ,OAAO,GAAG;AAAA,IACjD;AAEA,UAAM,aAA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
const h__default = /* @__PURE__ */ _interopDefault(h$1);
|
|
5
|
+
const styles = {
|
|
6
|
+
"data-panel-masonry-body": "_data-panel-masonry-body_1oiqg_1",
|
|
7
|
+
"data-panel-masonry": "_data-panel-masonry_1oiqg_1",
|
|
8
|
+
"data-panel-masonry-column": "_data-panel-masonry-column_1oiqg_13",
|
|
9
|
+
"data-panel-masonry-placeholders": "_data-panel-masonry-placeholders_1oiqg_21"
|
|
10
|
+
};
|
|
11
|
+
let h = h__default.default.styled(styles);
|
|
12
|
+
Object.assign(h, styles);
|
|
13
|
+
module.exports = h;
|
|
14
|
+
//# sourceMappingURL=masonry.module.sass.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masonry.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import h$1 from "@macrostrat/hyper";
|
|
2
|
+
const styles = {
|
|
3
|
+
"data-panel-masonry-body": "_data-panel-masonry-body_1oiqg_1",
|
|
4
|
+
"data-panel-masonry": "_data-panel-masonry_1oiqg_1",
|
|
5
|
+
"data-panel-masonry-column": "_data-panel-masonry-column_1oiqg_13",
|
|
6
|
+
"data-panel-masonry-placeholders": "_data-panel-masonry-placeholders_1oiqg_21"
|
|
7
|
+
};
|
|
8
|
+
let h = h$1.styled(styles);
|
|
9
|
+
Object.assign(h, styles);
|
|
10
|
+
export {
|
|
11
|
+
h as default
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=masonry.module.sass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masonry.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -7,6 +7,7 @@ const update = require("immutability-helper");
|
|
|
7
7
|
const postgrestJs = require("@supabase/postgrest-js");
|
|
8
8
|
const loadingUtils = require("./loading-utils.cjs");
|
|
9
9
|
const jotai = require("jotai");
|
|
10
|
+
const loaderState = require("../provider/loader-state.cjs");
|
|
10
11
|
const core = require("../provider/core.cjs");
|
|
11
12
|
const tableData = require("../provider/table-data.cjs");
|
|
12
13
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
@@ -85,10 +86,10 @@ function lazyLoadingReducer(state, action) {
|
|
|
85
86
|
pageSize: state.pageSize
|
|
86
87
|
};
|
|
87
88
|
case "seed": {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const data2 = loaderState.seededRows({
|
|
90
|
+
rows: action.data ?? [],
|
|
91
|
+
totalCount: action.totalCount
|
|
92
|
+
});
|
|
92
93
|
return {
|
|
93
94
|
visibleRegion: defaultVisibleRegion,
|
|
94
95
|
data: data2,
|
|
@@ -181,17 +182,9 @@ const defaultVisibleRegion = {
|
|
|
181
182
|
rowIndexEnd: 0
|
|
182
183
|
};
|
|
183
184
|
const visibleRegionAtom = jotai.atom(defaultVisibleRegion);
|
|
184
|
-
const lazyLoaderCoreStateAtom = jotai.atom({
|
|
185
|
-
loading: false,
|
|
186
|
-
error: null,
|
|
187
|
-
initialized: false,
|
|
188
|
-
totalCount: null,
|
|
189
|
-
fetchMode: "scroll",
|
|
190
|
-
pageSize: 100
|
|
191
|
-
});
|
|
192
185
|
const chunkPageAtom = jotai.atom(0);
|
|
193
186
|
const tableFooterAtom = jotai.atom((get) => {
|
|
194
|
-
const core$1 = get(lazyLoaderCoreStateAtom);
|
|
187
|
+
const core$1 = get(loaderState.lazyLoaderCoreStateAtom);
|
|
195
188
|
const data = get(core.tableDataAtom) ?? [];
|
|
196
189
|
let loaded = 0;
|
|
197
190
|
let hasGaps = false;
|
|
@@ -272,7 +265,7 @@ const viewInfoAtom = jotai.atom((get) => {
|
|
|
272
265
|
});
|
|
273
266
|
const lazyLoaderStateAtom = jotai.atom(
|
|
274
267
|
(get) => {
|
|
275
|
-
const core$1 = get(lazyLoaderCoreStateAtom);
|
|
268
|
+
const core$1 = get(loaderState.lazyLoaderCoreStateAtom);
|
|
276
269
|
const data = get(core.tableDataAtom);
|
|
277
270
|
const visibleRegion = get(visibleRegionAtom);
|
|
278
271
|
return {
|
|
@@ -293,7 +286,7 @@ const lazyLoaderStateAtom = jotai.atom(
|
|
|
293
286
|
set(core.tableDataAtom, data);
|
|
294
287
|
}
|
|
295
288
|
if (Object.keys(rest).length > 1) {
|
|
296
|
-
set(lazyLoaderCoreStateAtom, (v) => ({ ...v, ...rest }));
|
|
289
|
+
set(loaderState.lazyLoaderCoreStateAtom, (v) => ({ ...v, ...rest }));
|
|
297
290
|
}
|
|
298
291
|
}
|
|
299
292
|
);
|
|
@@ -385,13 +378,19 @@ function useDataLoader(fetchChunk, options = {}) {
|
|
|
385
378
|
[columnSorts, filters]
|
|
386
379
|
);
|
|
387
380
|
const debouncedViewKey = useDebouncedValue(viewKey, filterDebounce);
|
|
388
|
-
const seedRef = react.useRef(resolveInitialData(initialData));
|
|
381
|
+
const seedRef = react.useRef(loaderState.resolveInitialData(initialData));
|
|
389
382
|
const awaitingSeedRef = react.useRef(seedRef.current != null);
|
|
390
383
|
react.useEffect(() => {
|
|
391
384
|
const seed = seedRef.current;
|
|
392
385
|
seedRef.current = null;
|
|
393
386
|
if (seed != null) {
|
|
394
|
-
|
|
387
|
+
if (!state.initialized) {
|
|
388
|
+
dispatch({
|
|
389
|
+
type: "seed",
|
|
390
|
+
data: seed.rows,
|
|
391
|
+
totalCount: seed.totalCount
|
|
392
|
+
});
|
|
393
|
+
}
|
|
395
394
|
setPage(0);
|
|
396
395
|
loadedRef.current = { page: 0, viewKey };
|
|
397
396
|
return;
|
|
@@ -471,15 +470,6 @@ function useDataLoader(fetchChunk, options = {}) {
|
|
|
471
470
|
}, [state.data, visibleRegion, debouncedViewKey, page, fetchMode]);
|
|
472
471
|
return { data: state.data, loading: state.loading, error: state.error };
|
|
473
472
|
}
|
|
474
|
-
function resolveInitialData(initialData) {
|
|
475
|
-
if (initialData == null) return null;
|
|
476
|
-
if (Array.isArray(initialData)) {
|
|
477
|
-
if (initialData.length === 0) return null;
|
|
478
|
-
return { rows: initialData };
|
|
479
|
-
}
|
|
480
|
-
if ((initialData.rows ?? []).length === 0) return null;
|
|
481
|
-
return initialData;
|
|
482
|
-
}
|
|
483
473
|
function useDebouncedValue(value, delay) {
|
|
484
474
|
const [debounced, setDebounced] = react.useState(value);
|
|
485
475
|
react.useEffect(() => {
|