@particle-academy/react-fancy 5.71.1 → 5.71.2
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 +26 -0
- package/dist/{chunk-Q72VHIBI.js → chunk-ARNFT23K.js} +8 -3
- package/dist/chunk-ARNFT23K.js.map +1 -0
- package/dist/{chunk-AQ3NPK2X.cjs → chunk-L5AI4MGV.cjs} +4 -4
- package/dist/{chunk-AQ3NPK2X.cjs.map → chunk-L5AI4MGV.cjs.map} +1 -1
- package/dist/{chunk-K7SPT7YF.js → chunk-LYG2NLSV.js} +3 -3
- package/dist/{chunk-K7SPT7YF.js.map → chunk-LYG2NLSV.js.map} +1 -1
- package/dist/{chunk-4TK3IYR6.cjs → chunk-MF2DCMOA.cjs} +8 -3
- package/dist/chunk-MF2DCMOA.cjs.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/tree-nav.cjs +4 -4
- package/dist/tree-nav.js +2 -2
- package/dist/virtual-list.cjs +2 -2
- package/dist/virtual-list.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4TK3IYR6.cjs.map +0 -1
- package/dist/chunk-Q72VHIBI.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [5.71.2] - 2026-10-30
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`VirtualList` performance: following the tail no longer reads `scrollTop`
|
|
19
|
+
in every commit** (genie#1340 follow-up). With 5.71.1 measuring each row
|
|
20
|
+
once, the follow-tail layout effect became the first layout read after each
|
|
21
|
+
commit, so its `vp.scrollTop` read paid the forced synchronous layout the
|
|
22
|
+
measuring loop used to absorb. Genie profiled it in its real window (11
|
|
23
|
+
agents streaming, a list following the tail, two 120 s windows): the
|
|
24
|
+
measuring effect fell to 292 / 791 ms, and the follow-tail line rose to
|
|
25
|
+
1,521 / 1,826 ms per 120 s, against about 10 ms on 5.70.0. The effect now
|
|
26
|
+
compares against the position the list already tracks (the last `scroll`
|
|
27
|
+
event, plus every scroll it sets itself, including `scrollToId`), so it only
|
|
28
|
+
writes `scrollTop` when the bottom actually moved (rows, row heights or the
|
|
29
|
+
viewport changed) or someone scrolled, and never reads it. In a real browser
|
|
30
|
+
(Chromium, tail-following, 60 appends) `scrollTop` reads inside a commit
|
|
31
|
+
went from 3 per append to 0, and a re-render that moves nothing went from
|
|
32
|
+
1 read to 0; the one read per append left is in the `scroll` handler, which
|
|
33
|
+
is where the position comes from. Follow, stop-on-scroll-away, resume at the
|
|
34
|
+
bottom, deep links, mount, empty-to-filled and viewport resize behave as
|
|
35
|
+
before. Without a ResizeObserver (old runtimes, jsdom) the effect still
|
|
36
|
+
reads `scrollTop`, as that path already pays for a layout every render.
|
|
37
|
+
**Consumer action: none.** No prop, type, data attribute or behaviour
|
|
38
|
+
changed.
|
|
39
|
+
|
|
14
40
|
## [5.71.1] - 2026-10-30
|
|
15
41
|
|
|
16
42
|
### Fixed
|
|
@@ -23,6 +23,7 @@ function VirtualList({
|
|
|
23
23
|
const [measured, setMeasured] = useState(0);
|
|
24
24
|
const [scrollTop, setScrollTop] = useState(0);
|
|
25
25
|
const [clientHeight, setClientHeight] = useState(0);
|
|
26
|
+
const knownTop = useRef(0);
|
|
26
27
|
const attachViewport = useCallback(
|
|
27
28
|
(el) => {
|
|
28
29
|
viewportRef.current = el;
|
|
@@ -147,6 +148,7 @@ function VirtualList({
|
|
|
147
148
|
if (anchored.current !== target) {
|
|
148
149
|
anchored.current = target;
|
|
149
150
|
vp.scrollTop = target;
|
|
151
|
+
knownTop.current = target;
|
|
150
152
|
setScrollTop(target);
|
|
151
153
|
return;
|
|
152
154
|
}
|
|
@@ -173,10 +175,12 @@ function VirtualList({
|
|
|
173
175
|
if (scrollToId !== null && resolved.current !== scrollToId) return;
|
|
174
176
|
const vp = viewportRef.current;
|
|
175
177
|
if (!vp) return;
|
|
178
|
+
const current = observer.current ? knownTop.current : vp.scrollTop;
|
|
176
179
|
const bottom = Math.max(0, total - viewport);
|
|
177
|
-
if (Math.abs(
|
|
180
|
+
if (Math.abs(current - bottom) > 0.5) {
|
|
178
181
|
programmatic.current = true;
|
|
179
182
|
vp.scrollTop = bottom;
|
|
183
|
+
knownTop.current = bottom;
|
|
180
184
|
setScrollTop(bottom);
|
|
181
185
|
}
|
|
182
186
|
});
|
|
@@ -184,6 +188,7 @@ function VirtualList({
|
|
|
184
188
|
const vp = viewportRef.current;
|
|
185
189
|
if (!vp) return;
|
|
186
190
|
const next = vp.scrollTop;
|
|
191
|
+
knownTop.current = next;
|
|
187
192
|
const previous = scrollTop;
|
|
188
193
|
setScrollTop(next);
|
|
189
194
|
const bottom = Math.max(0, total - viewport);
|
|
@@ -277,5 +282,5 @@ var TOUCH_SLOP = 4;
|
|
|
277
282
|
var UPWARD_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "PageUp", "Home"]);
|
|
278
283
|
|
|
279
284
|
export { VirtualList };
|
|
280
|
-
//# sourceMappingURL=chunk-
|
|
281
|
-
//# sourceMappingURL=chunk-
|
|
285
|
+
//# sourceMappingURL=chunk-ARNFT23K.js.map
|
|
286
|
+
//# sourceMappingURL=chunk-ARNFT23K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/VirtualList/VirtualList.tsx"],"names":[],"mappings":";;;;AA4DO,SAAS,WAAA,CAAsC;AAAA,EACpD,KAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA,GAAS,MAAA;AAAA,EACT,iBAAA,GAAoB,EAAA;AAAA,EACpB,QAAA,GAAW,CAAA;AAAA,EACX,UAAA,GAAa,KAAA;AAAA,EACb,cAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,oBAAA;AAAA,EACA,SAAA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EAAW;AAAA,UAEpD,QAAA,kBAAA,GAAA;AAAA,YAAC,KAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,SAAA;AAAA,cACL,sCAAA,EAAqC,EAAA;AAAA,cACrC,qCAAA,EAAqC,KAAA;AAAA,cACrC,KAAA,EAAO,EAAE,SAAA,EAAW,CAAA,WAAA,EAAc,QAAQ,KAAK,CAAA,IAAK,CAAC,CAAA,GAAA,CAAA,EAAM;AAAA,cAE1D,kBAAQ,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,yBACjB,KAAA,EAAA,EAAkB,iCAAA,EAAiC,IAAA,CAAK,EAAA,EACtD,oBAAU,IAAA,EAAM,KAAA,GAAQ,CAAC,CAAA,EAAA,EADlB,IAAA,CAAK,EAEf,CACD;AAAA;AAAA;AACH;AAAA;AACF;AAAA,GACF;AAEJ;AAEA,IAAM,WAAA,GAAc,iCAAA;AAQpB,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,MAAM,MAAM,KAAA,CAAM,aAAA;AAClB,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,GAAI,GAAA,CAAI,CAAC,CAAA,GAAK,GAAA;AAC7C,EAAA,IAAI,SAAS,OAAO,KAAA,CAAM,SAAA,KAAc,QAAA,SAAiB,KAAA,CAAM,SAAA;AAE/D,EAAA,OAAO,KAAA,CAAM,aAAa,MAAA,IAAU,CAAA;AACtC;AAEA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,UAAA,GAAa,CAAA;AACnB,IAAM,8BAAc,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA","file":"chunk-ARNFT23K.js","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, TouchEvent, WheelEvent } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { VirtualListProps, VirtualListRow } from \"./VirtualList.types\";\n\n/**\n * A windowed list for ledgers that run to tens of thousands of rows — only the\n * visible slice is in the DOM, with **measured** variable row heights, deep\n * links by row id, and sticky-bottom tail-following.\n *\n * Built for an agent event stream, where every one of those three is load\n * bearing at once: message rows wrap and event rows do not, a link carries\n * `?at=<rowId>` to the exact row under discussion, and new rows arrive while\n * the human is reading older ones.\n *\n * ## Heights are measured, never predicted\n *\n * `estimateRowHeight` only seeds rows that have never been on screen. The\n * moment a row renders, its real height is measured and replaces the estimate,\n * and every offset after it moves. The alternative — a `rowHeight(item)`\n * callback — is a prediction about text wrapping, font loading and container\n * width, and when it is wrong the error accumulates down the list: rows draw in\n * the wrong place and `scrollToId` lands on a neighbour. Measuring is slower to\n * settle and correct when it does.\n *\n * ## Tail-follow breaks on INTENT, not on position\n *\n * Any upward gesture — wheel, drag, PageUp, Home — stops following\n * immediately, even when the list is still pinned to the bottom and\n * `scrollTop` has not changed yet. Position cannot tell \"the human scrolled\n * up\" from \"content grew downward\", so a position-only implementation keeps\n * following through a wheel-up and yanks the reader back on the next append.\n *\n * ## It is controlled\n *\n * `followTail` is the consumer's state. This component only ever *asks* via\n * `onFollowChange`, so the follow state is readable and writable by an agent\n * over a bridge, as the Human+ component contract requires. The `↓ n new` pill\n * is the consumer's to render, from `onUnseenChange`.\n *\n * @example\n * ```tsx\n * const [following, setFollowing] = useState(true);\n * const [unseen, setUnseen] = useState(0);\n *\n * <VirtualList\n * items={events}\n * renderRow={(e) => <StreamRow event={e} />}\n * height=\"100%\"\n * estimateRowHeight={28}\n * followTail={following}\n * onFollowChange={setFollowing}\n * onUnseenChange={setUnseen}\n * scrollToId={params.at}\n * />\n * {!following && unseen > 0 && (\n * <Button onClick={() => setFollowing(true)}>↓ {unseen} new</Button>\n * )}\n * ```\n */\nexport function VirtualList<T extends VirtualListRow>({\n items,\n renderRow,\n height = \"100%\",\n estimateRowHeight = 32,\n overscan = 6,\n followTail = false,\n onFollowChange,\n onUnseenChange,\n scrollToId = null,\n onScrollToIdResolved,\n className,\n ref,\n ...props\n}: VirtualListProps<T>) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n\n /** Measured heights by row id, so a height follows its row across a reindex. */\n const heights = useRef(new Map<string, number>());\n /** Bumped when a measurement actually changed, to recompute offsets. */\n const [measured, setMeasured] = useState(0);\n\n const [scrollTop, setScrollTop] = useState(0);\n const [clientHeight, setClientHeight] = useState(0);\n\n /**\n * Where the viewport is scrolled, as far as this list knows: the value from\n * the last `scroll` event, or the last position it set itself. Every change\n * to scrollTop raises a scroll event, so this is never wrong for longer than\n * one frame — and reading it, unlike reading `vp.scrollTop` inside a commit,\n * never forces a synchronous layout.\n */\n const knownTop = useRef(0);\n\n const attachViewport = useCallback(\n (el: HTMLDivElement | null) => {\n viewportRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) (ref as { current: HTMLDivElement | null }).current = el;\n },\n [ref],\n );\n\n // A number `height` IS the viewport height, and is usable before the element\n // has been measured. Without one, render a conservative first window so there\n // is something on screen for the measurement pass to work from.\n const viewport =\n clientHeight > 0 ? clientHeight : typeof height === \"number\" ? height : estimateRowHeight * 20;\n\n /**\n * Prefix sums of row heights: `offsets[i]` is where row `i` starts, and the\n * last entry is the total. Rebuilt whenever rows or measurements change —\n * O(n) once per change, against O(log n) per scroll from the binary search,\n * rather than O(n) on every scroll frame.\n */\n const { offsets, total } = useMemo(() => {\n const offs = new Float64Array(items.length + 1);\n for (let i = 0; i < items.length; i += 1) {\n offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);\n }\n\n return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };\n }, [items, measured, estimateRowHeight]);\n\n /** First row whose span contains `y`. */\n const indexAt = useCallback(\n (y: number): number => {\n let lo = 0;\n let hi = items.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (offsets[mid] <= y) lo = mid;\n else hi = mid - 1;\n }\n\n return Math.max(0, lo);\n },\n [items.length, offsets],\n );\n\n const start = Math.max(0, indexAt(scrollTop) - overscan);\n const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);\n const visible = useMemo(() => items.slice(start, end), [items, start, end]);\n\n // ---------------------------------------------------------------- measuring\n\n //\n // Every getBoundingClientRect() / clientHeight read after a commit forces a\n // synchronous layout, and this list re-renders on every appended row. So a\n // row is measured ONCE, when its element first appears, and from then on the\n // ResizeObserver reports when it changes, with the size in the entry: no read\n // that forces layout. An append costs one measurement; a render where nothing\n // changed costs none. (Measured in genie#1340: re-measuring every visible row\n // on every render was 472 forced row measurements/s with 11 agents streaming.)\n\n const observer = useRef<ResizeObserver | null>(null);\n /** Row elements currently observed, so each is observed once and released. */\n const observed = useRef(new Set<Element>());\n\n // A layout effect, declared before the measuring one, so the observer exists\n // by the time the first window is measured and the first rows are observed.\n useLayoutEffect(() => {\n // Absent in jsdom and in older runtimes. Without it the list measures every\n // visible row on every render instead, which is the only way it can notice\n // a row reflowing in place.\n if (typeof ResizeObserver === \"undefined\") return;\n\n const ro = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const el = entry.target as HTMLElement;\n\n if (el === viewportRef.current) {\n // The viewport's own resize changes how many rows fit. Reading\n // clientHeight here is free: the browser has just done layout.\n const ch = el.clientHeight;\n if (ch > 0) setClientHeight(ch);\n continue;\n }\n\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n const h = entryHeight(entry);\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n observer.current = ro;\n\n const vp = viewportRef.current;\n if (vp) ro.observe(vp);\n\n const tracked = observed.current;\n\n return () => {\n ro.disconnect();\n observer.current = null;\n tracked.clear();\n };\n }, []);\n\n // No dependency array on purpose: every render looks at what is on screen.\n // That LOOK is cheap — walking the window's children reads no layout. Only a\n // row seen for the first time is measured (or, with no ResizeObserver, every\n // row, as nothing else would notice a reflow). A render that learns nothing\n // new sets no state, which is what stops it looping.\n useLayoutEffect(() => {\n const win = windowRef.current;\n if (!win) return;\n\n const ro = observer.current;\n const tracked = observed.current;\n const present = ro ? new Set<Element>() : null;\n\n let changed = false;\n let measuredAny = false;\n for (const el of Array.from(win.children) as HTMLElement[]) {\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n if (ro && present) {\n present.add(el);\n // Already observed: the observer reports its resizes.\n if (tracked.has(el)) continue;\n\n ro.observe(el);\n tracked.add(el);\n // A row scrolling back into view: its height is known, and the\n // observer's first report for the new element corrects it if it moved.\n if (heights.current.has(id)) continue;\n }\n\n const h = el.getBoundingClientRect().height;\n measuredAny = true;\n // A zero height is \"not laid out yet\", not a 0px row. Recording it would\n // collapse the list and make every offset after it wrong.\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (ro && present) {\n for (const el of tracked) {\n if (!present.has(el)) {\n ro.unobserve(el);\n tracked.delete(el);\n }\n }\n }\n\n // With an observer, the viewport's resizes arrive through it; read it here\n // only when this pass has already paid for a layout, so it is free.\n const vp = viewportRef.current;\n if (vp && (!ro || measuredAny) && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) {\n setClientHeight(vp.clientHeight);\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n\n // ------------------------------------------------------------- deep linking\n\n /** The target this component last moved to, to detect that it has settled. */\n const anchored = useRef<number | null>(null);\n const resolved = useRef<string | null>(null);\n\n useEffect(() => {\n // A new id is a new request, even if the old one had resolved.\n anchored.current = null;\n resolved.current = null;\n }, [scrollToId]);\n\n useLayoutEffect(() => {\n if (scrollToId === null || resolved.current === scrollToId) return;\n\n const index = items.findIndex((item) => item.id === scrollToId);\n if (index < 0) {\n // A link to a row that is no longer in the list. Leaving the viewport\n // where it is and SAYING SO is the only honest outcome — scrolling to the\n // top would be indistinguishable from a successful landing.\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, false);\n\n return;\n }\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // Clamped the way the browser clamps: a row inside the final viewport-height\n // of the list cannot be brought to the top, and pretending otherwise would\n // leave this waiting for a position that can never be reached.\n const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));\n\n if (anchored.current !== target) {\n anchored.current = target;\n vp.scrollTop = target;\n knownTop.current = target;\n setScrollTop(target);\n\n return;\n }\n\n // The target stopped moving as rows above it were measured, and we are on\n // it. Only now is the deep link actually honoured.\n if (Math.abs(vp.scrollTop - target) <= 1) {\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, true);\n }\n });\n\n // ------------------------------------------------------------- tail-follow\n\n const reportedFollow = useRef(followTail);\n const programmatic = useRef(false);\n\n useEffect(() => {\n // The prop is the truth, so adopt it rather than remembering what we asked\n // for. Otherwise a consumer that declines an `onFollowChange(false)` would\n // never be asked again.\n reportedFollow.current = followTail;\n }, [followTail]);\n\n const askFollow = useCallback(\n (next: boolean) => {\n if (reportedFollow.current === next) return;\n reportedFollow.current = next;\n onFollowChange?.(next);\n },\n [onFollowChange],\n );\n\n useLayoutEffect(() => {\n if (!followTail) return;\n // A pending deep link wins while it resolves; otherwise the two would fight\n // over the same scrollTop and the link would lose.\n if (scrollToId !== null && resolved.current !== scrollToId) return;\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // This is the first layout read after most commits, so reading\n // `vp.scrollTop` here paid the forced synchronous layout on every append\n // (genie#1340 follow-up: 1.5 to 1.8 s per 120 s with 11 agents streaming).\n // Compare against the position the list already tracks instead, which only\n // differs from `bottom` when the bottom moved (rows, measurements or the\n // viewport changed) or someone scrolled — so a commit that moved nothing\n // neither reads nor writes. Without a ResizeObserver the measuring pass has\n // already paid for a layout this commit, so reading is free and keeps the\n // fallback exactly as it was.\n const current = observer.current ? knownTop.current : vp.scrollTop;\n const bottom = Math.max(0, total - viewport);\n if (Math.abs(current - bottom) > 0.5) {\n programmatic.current = true;\n vp.scrollTop = bottom;\n knownTop.current = bottom;\n setScrollTop(bottom);\n }\n });\n\n const onScroll = useCallback(() => {\n const vp = viewportRef.current;\n if (!vp) return;\n\n const next = vp.scrollTop;\n knownTop.current = next;\n const previous = scrollTop;\n setScrollTop(next);\n\n const bottom = Math.max(0, total - viewport);\n const wasProgrammatic = programmatic.current;\n programmatic.current = false;\n\n if (next <= bottom - BOTTOM_SLACK) {\n // Moved up, and not because we moved it.\n if (!wasProgrammatic && next < previous) askFollow(false);\n } else {\n askFollow(true);\n }\n }, [scrollTop, total, viewport, askFollow]);\n\n /** Any upward gesture is a statement of intent, whatever scrollTop says. */\n const onWheel = useCallback(\n (e: WheelEvent<HTMLDivElement>) => {\n if (e.deltaY < 0) askFollow(false);\n },\n [askFollow],\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (UPWARD_KEYS.has(e.key)) askFollow(false);\n },\n [askFollow],\n );\n\n const touchStart = useRef<number | null>(null);\n\n const onTouchStart = useCallback((e: TouchEvent<HTMLDivElement>) => {\n touchStart.current = e.touches[0]?.clientY ?? null;\n }, []);\n\n const onTouchMove = useCallback(\n (e: TouchEvent<HTMLDivElement>) => {\n const from = touchStart.current;\n const y = e.touches[0]?.clientY;\n // Finger travelling DOWN drags the content down, which scrolls up.\n if (from !== null && y !== undefined && y - from > TOUCH_SLOP) askFollow(false);\n },\n [askFollow],\n );\n\n // ------------------------------------------------------------ unseen count\n\n const seen = useRef(items.length);\n const reportedUnseen = useRef<number | null>(null);\n\n useEffect(() => {\n const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);\n if (followTail) seen.current = items.length;\n\n if (reportedUnseen.current === unseen) return;\n reportedUnseen.current = unseen;\n onUnseenChange?.(unseen);\n }, [items.length, followTail, onUnseenChange]);\n\n // ------------------------------------------------------------------ render\n\n return (\n <div\n ref={attachViewport}\n data-react-fancy-virtual-list=\"\"\n data-react-fancy-virtual-list-following={followTail ? \"true\" : \"false\"}\n data-react-fancy-virtual-list-rows={items.length}\n role=\"log\"\n tabIndex={0}\n className={cn(\"relative overflow-y-auto overflow-x-hidden outline-none\", className)}\n style={{ height }}\n onScroll={onScroll}\n onWheel={onWheel}\n onKeyDown={onKeyDown}\n onTouchStart={onTouchStart}\n onTouchMove={onTouchMove}\n {...props}\n >\n {/* Holds the full scroll range so the scrollbar is honest from the first\n paint, instead of growing as rows are discovered. */}\n <div\n data-react-fancy-virtual-list-sizer=\"\"\n style={{ height: `${total}px`, position: \"relative\" }}\n >\n <div\n ref={windowRef}\n data-react-fancy-virtual-list-window=\"\"\n data-react-fancy-virtual-list-start={start}\n style={{ transform: `translateY(${offsets[start] ?? 0}px)` }}\n >\n {visible.map((item, i) => (\n <div key={item.id} data-react-fancy-virtual-row-id={item.id}>\n {renderRow(item, start + i)}\n </div>\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nconst ROW_ID_ATTR = \"data-react-fancy-virtual-row-id\";\n\n/**\n * A row's border-box height from a ResizeObserver entry. `borderBoxSize` is\n * what getBoundingClientRect() would report; older engines lack it (and early\n * Firefox gave a single object, not an array), so fall back to `contentRect`,\n * which equals it for the row wrapper, as that carries no padding or border.\n */\nfunction entryHeight(entry: ResizeObserverEntry): number {\n const box = entry.borderBoxSize as ReadonlyArray<ResizeObserverSize> | ResizeObserverSize | undefined;\n const first = Array.isArray(box) ? box[0] : (box as ResizeObserverSize | undefined);\n if (first && typeof first.blockSize === \"number\") return first.blockSize;\n\n return entry.contentRect?.height ?? 0;\n}\n/** Within this many px of the bottom counts as \"at the bottom\". */\nconst BOTTOM_SLACK = 4;\n/** Ignore a touch jitter smaller than this before calling it an upward drag. */\nconst TOUCH_SLOP = 4;\nconst UPWARD_KEYS = new Set([\"ArrowUp\", \"PageUp\", \"Home\"]);\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMF2DCMOA_cjs = require('./chunk-MF2DCMOA.cjs');
|
|
4
4
|
var chunkZU5Q77OT_cjs = require('./chunk-ZU5Q77OT.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -484,7 +484,7 @@ function TreeNavRoot({
|
|
|
484
484
|
className: chunkZU5Q77OT_cjs.cn("flex flex-col gap-0.5 py-1 text-sm", className),
|
|
485
485
|
onDragEnd: dropEnabled ? handleDragEnd : void 0,
|
|
486
486
|
children: virtualize ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
487
|
-
|
|
487
|
+
chunkMF2DCMOA_cjs.VirtualList,
|
|
488
488
|
{
|
|
489
489
|
items: rows,
|
|
490
490
|
height,
|
|
@@ -502,5 +502,5 @@ var TreeNav = Object.assign(TreeNavRoot, {
|
|
|
502
502
|
|
|
503
503
|
exports.TreeNav = TreeNav;
|
|
504
504
|
exports.useTreeNav = useTreeNav;
|
|
505
|
-
//# sourceMappingURL=chunk-
|
|
506
|
-
//# sourceMappingURL=chunk-
|
|
505
|
+
//# sourceMappingURL=chunk-L5AI4MGV.cjs.map
|
|
506
|
+
//# sourceMappingURL=chunk-L5AI4MGV.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/TreeNav/TreeNav.context.ts","../src/components/TreeNav/tree-store.ts","../src/components/TreeNav/TreeNode.tsx","../src/components/TreeNav/TreeNav.tsx"],"names":["createContext","useContext","useSyncExternalStore","jsxs","jsx","cn","useRef","useCallback","useEffect","memo","useState","useMemo","useLayoutEffect","VirtualList"],"mappings":";;;;;;;AAGO,IAAM,cAAA,GAAiBA,oBAA0C,IAAI,CAAA;AAErE,SAAS,UAAA,GAAkC;AAChD,EAAA,MAAM,GAAA,GAAMC,iBAAW,cAAc,CAAA;AACrC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAAA,EACxE;AACA,EAAA,OAAO,GAAA;AACT;ACKO,SAAS,gBAAgB,OAAA,EAA+B;AAC7D,EAAA,IAAI,K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AAA,MAAM,cAAc,SAAA,IAAa,mBAAA;AAEjC,EAAA,uBACEH,cAAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,GAAA,EAC9B,QAAA,kBAAAA,cAAAA,CAAC,oBAAA,CAAqB,QAAA,EAArB,EAA8B,KAAA,EAAO,WACpC,QAAA,kBAAAA,cAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,2BAAA,EAA0B,EAAA;AAAA,MAC1B,mCAAA,EAAmC,aAAa,EAAA,GAAK,MAAA;AAAA,MACrD,SAAA,EAAWC,oBAAA,CAAG,oCAAA,EAAsC,SAAS,CAAA;AAAA,MAC7D,SAAA,EAAW,cAAc,aAAA,GAAgB,MAAA;AAAA,MAExC,uCACCD,cAAAA;AAAA,QAACS,6BAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO,IAAA;AAAA,UACP,MAAA;AAAA,UACA,iBAAA,EAAmB,SAAA;AAAA,UACnB,SAAA,EAAW,CAAC,GAAA,qBAAQT,cAAAA,CAAC,QAAA,EAAA,EAAS,IAAA,EAAM,GAAA,CAAI,IAAA,EAAM,KAAA,EAAO,GAAA,CAAI,KAAA,EAAO;AAAA;AAAA,OAClE,GAEA,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,qBAASA,cAAAA,CAAC,QAAA,EAAA,EAAuB,IAAA,EAAY,KAAA,EAAO,CAAA,EAAA,EAA5B,IAAA,CAAK,EAA0B,CAAE;AAAA;AAAA,KAG1E,CAAA,EACF,CAAA;AAEJ;AAEA,WAAA,CAAY,WAAA,GAAc,SAAA;AAEnB,IAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,WAAA,EAAa;AAAA,EAChD,IAAA,EAAM;AACR,CAAC","file":"chunk-AQ3NPK2X.cjs","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { TreeNavContextValue } from \"./TreeNav.types\";\n\nexport const TreeNavContext = createContext<TreeNavContextValue | null>(null);\n\nexport function useTreeNav(): TreeNavContextValue {\n const ctx = useContext(TreeNavContext);\n if (!ctx) {\n throw new Error(\"useTreeNav must be used within a <TreeNav> component\");\n }\n return ctx;\n}\n","import { createContext, useContext, useSyncExternalStore } from \"react\";\nimport type { DragState, DropPosition, TreeNodeData } from \"./TreeNav.types\";\n\n/** What changes as someone clicks, toggles and drags — the state rows subscribe to. */\nexport interface TreeState {\n selectedId?: string;\n expanded: ReadonlySet<string>;\n dragState: DragState;\n}\n\nexport interface TreeStore {\n get(): TreeState;\n set(next: TreeState): void;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTreeStore(initial: TreeState): TreeStore {\n let state = initial;\n const listeners = new Set<() => void>();\n return {\n get: () => state,\n set(next) {\n state = next;\n for (const listener of listeners) listener();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\n/**\n * Everything a row needs that does NOT change on a click. Handlers are stable\n * (they read the latest props and state when called), so this value only changes\n * when the tree's data or configuration does.\n *\n * Kept apart from the public `TreeNavContext` on purpose: that one still carries\n * live `selectedId` / `expandedIds` for `useTreeNav()` callers, and any component\n * reading it re-renders on every click. Rows no longer read it — which is the\n * whole fix: a click used to re-render every row in the tree.\n */\nexport interface TreeInternals {\n store: TreeStore;\n nodes: TreeNodeData[];\n select: (node: TreeNodeData) => void;\n toggle: (id: string) => void;\n expandNode: (id: string) => void;\n setDragState: (state: DragState) => void;\n contextMenu?: (e: React.MouseEvent, node: TreeNodeData) => void;\n moveNode?: (sourceId: string, targetId: string, position: DropPosition) => void;\n externalDrop?: (event: React.DragEvent, target: TreeNodeData, position: DropPosition) => void;\n indentSize: number;\n showIcons: boolean;\n draggable: boolean;\n dragCursor: \"grab\" | \"none\";\n acceptExternalDrops: boolean;\n /** Rows are rendered flat by a virtual list, so a row never renders its children. */\n flat: boolean;\n}\n\nexport const TreeInternalsContext = createContext<TreeInternals | null>(null);\n\nexport function useTreeInternals(): TreeInternals {\n const internals = useContext(TreeInternalsContext);\n if (!internals) throw new Error(\"TreeNav.Node must be used within a <TreeNav> component\");\n return internals;\n}\n\n/** Subscribe to ONE derived value; the row re-renders only when that value changes. */\nexport function useTreeSlice<T>(select: (state: TreeState) => T): T {\n const { store } = useTreeInternals();\n return useSyncExternalStore(\n store.subscribe,\n () => select(store.get()),\n () => select(store.get()),\n );\n}\n","import { memo, useRef, useEffect, useCallback } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useTreeInternals, useTreeSlice } from \"./tree-store\";\nimport type { TreeNodeProps, TreeNodeData, DropPosition } from \"./TreeNav.types\";\n\nconst EXT_COLORS: Record<string, string> = {\n ts: \"#3178c6\",\n tsx: \"#3178c6\",\n js: \"#f7df1e\",\n jsx: \"#f7df1e\",\n php: \"#777bb4\",\n html: \"#e34c26\",\n htm: \"#e34c26\",\n css: \"#264de4\",\n json: \"#a1a1aa\",\n md: \"#71717a\",\n yaml: \"#cb171e\",\n yml: \"#cb171e\",\n};\n\nfunction FileIcon({ ext }: { ext?: string }) {\n const color = (ext && EXT_COLORS[ext.toLowerCase()]) || \"#71717a\";\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M4 1h5.5L13 4.5V14a1 1 0 01-1 1H4a1 1 0 01-1-1V2a1 1 0 011-1z\" stroke={color} strokeWidth=\"1.2\" />\n <path d=\"M9 1v4h4\" stroke={color} strokeWidth=\"1.2\" />\n </svg>\n );\n}\n\nfunction FolderIcon({ open }: { open: boolean }) {\n if (open) {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3.5a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1V5H2.5V3.5z\" fill=\"#fbbf24\" />\n <path d=\"M1 6h13l-1.5 7.5H2.5L1 6z\" fill=\"#fbbf24\" opacity=\"0.7\" />\n </svg>\n );\n }\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1v8a1 1 0 01-1 1H2.5a1 1 0 01-1-1V3z\" fill=\"#fbbf24\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ open }: { open: boolean }) {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={cn(\"shrink-0 transition-transform duration-150\", open && \"rotate-90\")}\n >\n <polyline points=\"9 18 15 12 9 6\" />\n </svg>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isDescendantOf(\n nodes: TreeNodeData[],\n ancestorId: string,\n targetId: string,\n): boolean {\n function findNode(haystack: TreeNodeData[], id: string): TreeNodeData | undefined {\n for (const n of haystack) {\n if (n.id === id) return n;\n if (n.children) {\n const found = findNode(n.children, id);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n function hasDescendant(node: TreeNodeData, id: string): boolean {\n if (!node.children) return false;\n for (const child of node.children) {\n if (child.id === id) return true;\n if (hasDescendant(child, id)) return true;\n }\n return false;\n }\n\n const ancestor = findNode(nodes, ancestorId);\n return ancestor ? hasDescendant(ancestor, targetId) : false;\n}\n\nfunction computeDropPosition(\n e: React.DragEvent,\n isFolder: boolean,\n): DropPosition {\n const rect = e.currentTarget.getBoundingClientRect();\n const offsetY = e.clientY - rect.top;\n const third = rect.height / 3;\n\n if (offsetY < third) return \"before\";\n if (offsetY > third * 2) return \"after\";\n return isFolder ? \"inside\" : \"after\";\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n\n/**\n * One row (and, when nested, its expanded children).\n *\n * Reads what changes on a click — selection, expansion, drag — as per-row slices\n * of a store, so a click re-renders only the rows whose slice changed. It used to\n * read one context holding all of it, so every click re-rendered every row:\n * 175-267 ms per click on a 5,000-node tree. `memo` keeps a parent's re-render\n * from reaching rows whose `node` and `depth` did not change.\n */\nfunction TreeNodeImpl({ node, depth }: TreeNodeProps) {\n const {\n store, nodes, select, toggle, expandNode, setDragState, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, flat,\n } = useTreeInternals();\n\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n const isExpanded = useTreeSlice((s) => s.expanded.has(node.id));\n const isSelected = useTreeSlice((s) => s.selectedId === node.id);\n const isDragging = useTreeSlice((s) => s.dragState.draggedNodeId === node.id);\n const dropPosition = useTreeSlice((s) =>\n s.dragState.dropTargetId === node.id ? s.dragState.dropPosition : null,\n );\n const isDropTarget = dropPosition !== null;\n const paddingLeft = depth * indentSize + 4;\n\n // Auto-expand timer for folders during drag\n const autoExpandTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearAutoExpand = useCallback(() => {\n if (autoExpandTimer.current) {\n clearTimeout(autoExpandTimer.current);\n autoExpandTimer.current = null;\n }\n }, []);\n\n useEffect(() => clearAutoExpand, [clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Click handlers\n // ---------------------------------------------------------------------------\n\n const handleClick = () => {\n if (node.disabled) return;\n if (isFolder) {\n toggle(node.id);\n }\n select(node);\n };\n\n const handleContextMenu = (e: React.MouseEvent) => {\n if (contextMenu) {\n e.preventDefault();\n contextMenu(e, node);\n }\n };\n\n // ---------------------------------------------------------------------------\n // Drag source handlers\n // ---------------------------------------------------------------------------\n\n const handleDragStart = useCallback((e: React.DragEvent) => {\n e.dataTransfer.setData(\"text/plain\", node.id);\n e.dataTransfer.effectAllowed = \"move\";\n // Set state async so the browser captures the element for the drag ghost first\n requestAnimationFrame(() => {\n setDragState({ draggedNodeId: node.id, dropTargetId: null, dropPosition: null });\n });\n }, [node.id, setDragState]);\n\n const handleDragEnd = useCallback(() => {\n clearAutoExpand();\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [clearAutoExpand, setDragState]);\n\n // ---------------------------------------------------------------------------\n // Drop target handlers (on outer div). Drag state is read from the store when\n // the event fires, so a row does not re-render as a drag moves elsewhere.\n // ---------------------------------------------------------------------------\n\n const handleDragOver = useCallback((e: React.DragEvent) => {\n const { dragState } = store.get();\n const isExternalDrag = !dragState.draggedNodeId;\n if (isExternalDrag) {\n // External drop accepted only when host opted in.\n if (!acceptExternalDrops) return;\n } else {\n const sourceId = dragState.draggedNodeId!;\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = isExternalDrag ? \"copy\" : \"move\";\n\n const position = computeDropPosition(e, !!isFolder);\n\n // Auto-expand collapsed folders when hovering \"inside\"\n if (isFolder && !store.get().expanded.has(node.id) && position === \"inside\") {\n if (!autoExpandTimer.current) {\n autoExpandTimer.current = setTimeout(() => {\n expandNode(node.id);\n autoExpandTimer.current = null;\n }, 500);\n }\n } else {\n clearAutoExpand();\n }\n\n if (dragState.dropTargetId !== node.id || dragState.dropPosition !== position) {\n setDragState({ draggedNodeId: dragState.draggedNodeId, dropTargetId: node.id, dropPosition: position });\n }\n }, [store, acceptExternalDrops, node.id, isFolder, nodes, setDragState, expandNode, clearAutoExpand]);\n\n const handleDragLeave = useCallback((e: React.DragEvent) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n clearAutoExpand();\n const { dragState } = store.get();\n if (dragState.dropTargetId === node.id) {\n setDragState({ ...dragState, dropTargetId: null, dropPosition: null });\n }\n }\n }, [store, node.id, setDragState, clearAutoExpand]);\n\n const handleDrop = useCallback((e: React.DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n clearAutoExpand();\n\n const { dragState } = store.get();\n const sourceId = dragState.draggedNodeId;\n const position = dragState.dropPosition ?? computeDropPosition(e, !!isFolder);\n\n if (sourceId) {\n // Internal node move.\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n moveNode?.(sourceId, node.id, position);\n } else if (acceptExternalDrops) {\n // External drop — files, items from other components, etc.\n externalDrop?.(e, node, position);\n }\n\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [store, node, isFolder, nodes, moveNode, acceptExternalDrops, externalDrop, setDragState, clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Render\n // ---------------------------------------------------------------------------\n\n const canDrag = draggable && !node.disabled;\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <div\n data-react-fancy-tree-node=\"\"\n onDragOver={dropEnabled ? handleDragOver : undefined}\n onDragLeave={dropEnabled ? handleDragLeave : undefined}\n onDrop={dropEnabled ? handleDrop : undefined}\n >\n {/* Before drop indicator */}\n {isDropTarget && dropPosition === \"before\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"before\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n <button\n type=\"button\"\n draggable={canDrag}\n onDragStart={canDrag ? handleDragStart : undefined}\n onDragEnd={canDrag ? handleDragEnd : undefined}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n disabled={node.disabled}\n className={cn(\n \"flex w-full items-center gap-1 rounded-md py-0.5 text-left text-[13px] transition-colors\",\n isSelected\n ? \"bg-blue-500/15 text-blue-600 dark:text-blue-400\"\n : \"text-[color:var(--fancy-text-soft,var(--color-zinc-700))] hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:text-[color:var(--fancy-text-soft-dark,var(--color-zinc-300))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n node.disabled && \"pointer-events-none opacity-40\",\n isDragging && \"opacity-50\",\n // Grab affordance. By default (`dragCursor=\"none\"`) the row keeps its\n // normal click cursor on hover — no open-hand \"move me\" cursor before\n // any drag — and only shows the closed-hand `grabbing` cursor while a\n // drag is actually underway (mousedown/drag). `dragCursor=\"grab\"` opts\n // back into the always-on grab cursor for whole-row drag handles (#14).\n canDrag &&\n (dragCursor === \"grab\" ? \"cursor-grab active:cursor-grabbing\" : \"active:cursor-grabbing\"),\n isDropTarget && dropPosition === \"inside\" && \"bg-blue-500/10 ring-1 ring-blue-500/30 ring-inset\",\n )}\n style={{ paddingLeft }}\n >\n {isFolder && <ChevronIcon open={isExpanded} />}\n {!isFolder && <span className=\"w-3.5 shrink-0\" />}\n {showIcons && (\n node.icon ?? (isFolder\n ? <FolderIcon open={isExpanded} />\n : <FileIcon ext={node.ext ?? node.label.split(\".\").pop()} />)\n )}\n <span className=\"truncate\">{node.label}</span>\n </button>\n\n {/* After drop indicator */}\n {isDropTarget && dropPosition === \"after\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"after\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n {/* A virtual list renders rows flat, so a row never renders its own children there. */}\n {!flat && isFolder && isExpanded && node.children && (\n <div data-react-fancy-tree-node-children=\"\">\n {node.children.map((child) => (\n <TreeNode key={child.id} node={child} depth={depth + 1} />\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport const TreeNode = memo(TreeNodeImpl);\n\nTreeNode.displayName = \"TreeNode\";\n","import { useMemo, useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { VirtualList } from \"../VirtualList\";\nimport { TreeNavContext } from \"./TreeNav.context\";\nimport { TreeNode } from \"./TreeNode\";\nimport { createTreeStore, TreeInternalsContext, type TreeInternals } from \"./tree-store\";\nimport type { TreeNavProps, TreeNodeData, DragState } from \"./TreeNav.types\";\n\nfunction collectFolderIds(nodes: TreeNodeData[]): string[] {\n const ids: string[] = [];\n for (const node of nodes) {\n if (node.children && node.children.length > 0) {\n ids.push(node.id);\n ids.push(...collectFolderIds(node.children));\n }\n }\n return ids;\n}\n\nconst EMPTY_DRAG_STATE: DragState = {\n draggedNodeId: null,\n dropTargetId: null,\n dropPosition: null,\n};\n\ninterface FlatRow {\n id: string;\n node: TreeNodeData;\n depth: number;\n}\n\n/** The rows currently visible — every node, descending only into expanded folders. */\nfunction flattenVisible(nodes: TreeNodeData[], expanded: ReadonlySet<string>): FlatRow[] {\n const rows: FlatRow[] = [];\n const walk = (list: TreeNodeData[], depth: number) => {\n for (const node of list) {\n rows.push({ id: node.id, node, depth });\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n if (isFolder && node.children && expanded.has(node.id)) walk(node.children, depth + 1);\n }\n };\n walk(nodes, 0);\n return rows;\n}\n\nfunction TreeNavRoot({\n nodes,\n selectedId,\n onSelect,\n onNodeContextMenu,\n draggable = false,\n onNodeMove,\n acceptExternalDrops = false,\n onExternalDrop,\n expandedIds: controlledExpanded,\n defaultExpandedIds,\n onExpandedChange,\n defaultExpandAll = false,\n indentSize = 16,\n showIcons = true,\n dragCursor = \"none\",\n virtualize = false,\n height = 400,\n rowHeight = 26,\n className,\n}: TreeNavProps) {\n const [internalExpanded, setInternalExpanded] = useState<string[]>(() => {\n if (defaultExpandedIds) return defaultExpandedIds;\n if (defaultExpandAll) return collectFolderIds(nodes);\n return [];\n });\n\n const isControlled = controlledExpanded !== undefined;\n const expandedIds = isControlled ? controlledExpanded : internalExpanded;\n // One Set per change, so a row's \"am I expanded?\" is a lookup, not a scan.\n const expanded = useMemo(() => new Set(expandedIds), [expandedIds]);\n\n const [dragState, setDragState] = useState<DragState>(EMPTY_DRAG_STATE);\n\n /*\n * The latest props and state, for handlers that must stay STABLE. A handler\n * whose identity changes on every click would change the context rows read,\n * and re-render every row — the exact cost this component is avoiding.\n */\n const latest = useRef({ expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop });\n latest.current = { expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop };\n\n const setExpanded = useCallback((next: string[]) => {\n if (!latest.current.isControlled) setInternalExpanded(next);\n latest.current.onExpandedChange?.(next);\n }, []);\n\n const toggle = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n setExpanded(current.includes(id) ? current.filter((v) => v !== id) : [...current, id]);\n },\n [setExpanded],\n );\n\n const expandNode = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n if (!current.includes(id)) setExpanded([...current, id]);\n },\n [setExpanded],\n );\n\n const select = useCallback((node: TreeNodeData) => latest.current.onSelect?.(node.id, node), []);\n const contextMenu = useCallback(\n (e: React.MouseEvent, node: TreeNodeData) => latest.current.onNodeContextMenu?.(e, node),\n [],\n );\n const moveNode = useCallback(\n (sourceId: string, targetId: string, position: Parameters<NonNullable<TreeNavProps[\"onNodeMove\"]>>[2]) =>\n latest.current.onNodeMove?.(sourceId, targetId, position),\n [],\n );\n const externalDrop = useCallback(\n (event: React.DragEvent, target: TreeNodeData, position: Parameters<NonNullable<TreeNavProps[\"onExternalDrop\"]>>[2]) =>\n latest.current.onExternalDrop?.(event, target, position),\n [],\n );\n\n // What rows subscribe to. Seeded with this render's values so the first paint\n // is right; kept current after each render that changes them.\n const [store] = useState(() => createTreeStore({ selectedId, expanded, dragState }));\n useLayoutEffect(() => {\n const current = store.get();\n if (current.selectedId !== selectedId || current.expanded !== expanded || current.dragState !== dragState) {\n store.set({ selectedId, expanded, dragState });\n }\n }, [store, selectedId, expanded, dragState]);\n\n const hasContextMenu = onNodeContextMenu !== undefined;\n const internals = useMemo<TreeInternals>(\n () => ({\n store,\n nodes,\n select,\n toggle,\n expandNode,\n setDragState,\n // Present only when the host gave one: a row then claims the right-click.\n contextMenu: hasContextMenu ? contextMenu : undefined,\n moveNode,\n externalDrop,\n indentSize,\n showIcons,\n draggable,\n dragCursor,\n acceptExternalDrops,\n flat: virtualize,\n }),\n [store, nodes, select, toggle, expandNode, hasContextMenu, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, virtualize],\n );\n\n // Unchanged public context, still live for `useTreeNav()` callers. Rows no\n // longer read it, so its changing on a click re-renders only those callers.\n const ctx = useMemo(\n () => ({\n selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, setDragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode,\n }),\n [selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode],\n );\n\n const rows = useMemo(\n () => (virtualize ? flattenVisible(nodes, expanded) : []),\n [virtualize, nodes, expanded],\n );\n\n const handleDragEnd = useCallback(() => {\n setDragState(EMPTY_DRAG_STATE);\n }, []);\n\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <TreeNavContext.Provider value={ctx}>\n <TreeInternalsContext.Provider value={internals}>\n <nav\n data-react-fancy-tree-nav=\"\"\n data-react-fancy-tree-nav-virtual={virtualize ? \"\" : undefined}\n className={cn(\"flex flex-col gap-0.5 py-1 text-sm\", className)}\n onDragEnd={dropEnabled ? handleDragEnd : undefined}\n >\n {virtualize ? (\n <VirtualList\n items={rows}\n height={height}\n estimateRowHeight={rowHeight}\n renderRow={(row) => <TreeNode node={row.node} depth={row.depth} />}\n />\n ) : (\n nodes.map((node) => <TreeNode key={node.id} node={node} depth={0} />)\n )}\n </nav>\n </TreeInternalsContext.Provider>\n </TreeNavContext.Provider>\n );\n}\n\nTreeNavRoot.displayName = \"TreeNav\";\n\nexport const TreeNav = Object.assign(TreeNavRoot, {\n Node: TreeNode,\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/TreeNav/TreeNav.context.ts","../src/components/TreeNav/tree-store.ts","../src/components/TreeNav/TreeNode.tsx","../src/components/TreeNav/TreeNav.tsx"],"names":["createContext","useContext","useSyncExternalStore","jsxs","jsx","cn","useRef","useCallback","useEffect","memo","useState","useMemo","useLayoutEffect","VirtualList"],"mappings":";;;;;;;AAGO,IAAM,cAAA,GAAiBA,oBAA0C,IAAI,CAAA;AAErE,SAAS,UA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M,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,WAAA,EAAa;AAAA,EAChD,IAAA,EAAM;AACR,CAAC","file":"chunk-L5AI4MGV.cjs","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { TreeNavContextValue } from \"./TreeNav.types\";\n\nexport const TreeNavContext = createContext<TreeNavContextValue | null>(null);\n\nexport function useTreeNav(): TreeNavContextValue {\n const ctx = useContext(TreeNavContext);\n if (!ctx) {\n throw new Error(\"useTreeNav must be used within a <TreeNav> component\");\n }\n return ctx;\n}\n","import { createContext, useContext, useSyncExternalStore } from \"react\";\nimport type { DragState, DropPosition, TreeNodeData } from \"./TreeNav.types\";\n\n/** What changes as someone clicks, toggles and drags — the state rows subscribe to. */\nexport interface TreeState {\n selectedId?: string;\n expanded: ReadonlySet<string>;\n dragState: DragState;\n}\n\nexport interface TreeStore {\n get(): TreeState;\n set(next: TreeState): void;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTreeStore(initial: TreeState): TreeStore {\n let state = initial;\n const listeners = new Set<() => void>();\n return {\n get: () => state,\n set(next) {\n state = next;\n for (const listener of listeners) listener();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\n/**\n * Everything a row needs that does NOT change on a click. Handlers are stable\n * (they read the latest props and state when called), so this value only changes\n * when the tree's data or configuration does.\n *\n * Kept apart from the public `TreeNavContext` on purpose: that one still carries\n * live `selectedId` / `expandedIds` for `useTreeNav()` callers, and any component\n * reading it re-renders on every click. Rows no longer read it — which is the\n * whole fix: a click used to re-render every row in the tree.\n */\nexport interface TreeInternals {\n store: TreeStore;\n nodes: TreeNodeData[];\n select: (node: TreeNodeData) => void;\n toggle: (id: string) => void;\n expandNode: (id: string) => void;\n setDragState: (state: DragState) => void;\n contextMenu?: (e: React.MouseEvent, node: TreeNodeData) => void;\n moveNode?: (sourceId: string, targetId: string, position: DropPosition) => void;\n externalDrop?: (event: React.DragEvent, target: TreeNodeData, position: DropPosition) => void;\n indentSize: number;\n showIcons: boolean;\n draggable: boolean;\n dragCursor: \"grab\" | \"none\";\n acceptExternalDrops: boolean;\n /** Rows are rendered flat by a virtual list, so a row never renders its children. */\n flat: boolean;\n}\n\nexport const TreeInternalsContext = createContext<TreeInternals | null>(null);\n\nexport function useTreeInternals(): TreeInternals {\n const internals = useContext(TreeInternalsContext);\n if (!internals) throw new Error(\"TreeNav.Node must be used within a <TreeNav> component\");\n return internals;\n}\n\n/** Subscribe to ONE derived value; the row re-renders only when that value changes. */\nexport function useTreeSlice<T>(select: (state: TreeState) => T): T {\n const { store } = useTreeInternals();\n return useSyncExternalStore(\n store.subscribe,\n () => select(store.get()),\n () => select(store.get()),\n );\n}\n","import { memo, useRef, useEffect, useCallback } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useTreeInternals, useTreeSlice } from \"./tree-store\";\nimport type { TreeNodeProps, TreeNodeData, DropPosition } from \"./TreeNav.types\";\n\nconst EXT_COLORS: Record<string, string> = {\n ts: \"#3178c6\",\n tsx: \"#3178c6\",\n js: \"#f7df1e\",\n jsx: \"#f7df1e\",\n php: \"#777bb4\",\n html: \"#e34c26\",\n htm: \"#e34c26\",\n css: \"#264de4\",\n json: \"#a1a1aa\",\n md: \"#71717a\",\n yaml: \"#cb171e\",\n yml: \"#cb171e\",\n};\n\nfunction FileIcon({ ext }: { ext?: string }) {\n const color = (ext && EXT_COLORS[ext.toLowerCase()]) || \"#71717a\";\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M4 1h5.5L13 4.5V14a1 1 0 01-1 1H4a1 1 0 01-1-1V2a1 1 0 011-1z\" stroke={color} strokeWidth=\"1.2\" />\n <path d=\"M9 1v4h4\" stroke={color} strokeWidth=\"1.2\" />\n </svg>\n );\n}\n\nfunction FolderIcon({ open }: { open: boolean }) {\n if (open) {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3.5a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1V5H2.5V3.5z\" fill=\"#fbbf24\" />\n <path d=\"M1 6h13l-1.5 7.5H2.5L1 6z\" fill=\"#fbbf24\" opacity=\"0.7\" />\n </svg>\n );\n }\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1v8a1 1 0 01-1 1H2.5a1 1 0 01-1-1V3z\" fill=\"#fbbf24\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ open }: { open: boolean }) {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={cn(\"shrink-0 transition-transform duration-150\", open && \"rotate-90\")}\n >\n <polyline points=\"9 18 15 12 9 6\" />\n </svg>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isDescendantOf(\n nodes: TreeNodeData[],\n ancestorId: string,\n targetId: string,\n): boolean {\n function findNode(haystack: TreeNodeData[], id: string): TreeNodeData | undefined {\n for (const n of haystack) {\n if (n.id === id) return n;\n if (n.children) {\n const found = findNode(n.children, id);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n function hasDescendant(node: TreeNodeData, id: string): boolean {\n if (!node.children) return false;\n for (const child of node.children) {\n if (child.id === id) return true;\n if (hasDescendant(child, id)) return true;\n }\n return false;\n }\n\n const ancestor = findNode(nodes, ancestorId);\n return ancestor ? hasDescendant(ancestor, targetId) : false;\n}\n\nfunction computeDropPosition(\n e: React.DragEvent,\n isFolder: boolean,\n): DropPosition {\n const rect = e.currentTarget.getBoundingClientRect();\n const offsetY = e.clientY - rect.top;\n const third = rect.height / 3;\n\n if (offsetY < third) return \"before\";\n if (offsetY > third * 2) return \"after\";\n return isFolder ? \"inside\" : \"after\";\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n\n/**\n * One row (and, when nested, its expanded children).\n *\n * Reads what changes on a click — selection, expansion, drag — as per-row slices\n * of a store, so a click re-renders only the rows whose slice changed. It used to\n * read one context holding all of it, so every click re-rendered every row:\n * 175-267 ms per click on a 5,000-node tree. `memo` keeps a parent's re-render\n * from reaching rows whose `node` and `depth` did not change.\n */\nfunction TreeNodeImpl({ node, depth }: TreeNodeProps) {\n const {\n store, nodes, select, toggle, expandNode, setDragState, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, flat,\n } = useTreeInternals();\n\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n const isExpanded = useTreeSlice((s) => s.expanded.has(node.id));\n const isSelected = useTreeSlice((s) => s.selectedId === node.id);\n const isDragging = useTreeSlice((s) => s.dragState.draggedNodeId === node.id);\n const dropPosition = useTreeSlice((s) =>\n s.dragState.dropTargetId === node.id ? s.dragState.dropPosition : null,\n );\n const isDropTarget = dropPosition !== null;\n const paddingLeft = depth * indentSize + 4;\n\n // Auto-expand timer for folders during drag\n const autoExpandTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearAutoExpand = useCallback(() => {\n if (autoExpandTimer.current) {\n clearTimeout(autoExpandTimer.current);\n autoExpandTimer.current = null;\n }\n }, []);\n\n useEffect(() => clearAutoExpand, [clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Click handlers\n // ---------------------------------------------------------------------------\n\n const handleClick = () => {\n if (node.disabled) return;\n if (isFolder) {\n toggle(node.id);\n }\n select(node);\n };\n\n const handleContextMenu = (e: React.MouseEvent) => {\n if (contextMenu) {\n e.preventDefault();\n contextMenu(e, node);\n }\n };\n\n // ---------------------------------------------------------------------------\n // Drag source handlers\n // ---------------------------------------------------------------------------\n\n const handleDragStart = useCallback((e: React.DragEvent) => {\n e.dataTransfer.setData(\"text/plain\", node.id);\n e.dataTransfer.effectAllowed = \"move\";\n // Set state async so the browser captures the element for the drag ghost first\n requestAnimationFrame(() => {\n setDragState({ draggedNodeId: node.id, dropTargetId: null, dropPosition: null });\n });\n }, [node.id, setDragState]);\n\n const handleDragEnd = useCallback(() => {\n clearAutoExpand();\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [clearAutoExpand, setDragState]);\n\n // ---------------------------------------------------------------------------\n // Drop target handlers (on outer div). Drag state is read from the store when\n // the event fires, so a row does not re-render as a drag moves elsewhere.\n // ---------------------------------------------------------------------------\n\n const handleDragOver = useCallback((e: React.DragEvent) => {\n const { dragState } = store.get();\n const isExternalDrag = !dragState.draggedNodeId;\n if (isExternalDrag) {\n // External drop accepted only when host opted in.\n if (!acceptExternalDrops) return;\n } else {\n const sourceId = dragState.draggedNodeId!;\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = isExternalDrag ? \"copy\" : \"move\";\n\n const position = computeDropPosition(e, !!isFolder);\n\n // Auto-expand collapsed folders when hovering \"inside\"\n if (isFolder && !store.get().expanded.has(node.id) && position === \"inside\") {\n if (!autoExpandTimer.current) {\n autoExpandTimer.current = setTimeout(() => {\n expandNode(node.id);\n autoExpandTimer.current = null;\n }, 500);\n }\n } else {\n clearAutoExpand();\n }\n\n if (dragState.dropTargetId !== node.id || dragState.dropPosition !== position) {\n setDragState({ draggedNodeId: dragState.draggedNodeId, dropTargetId: node.id, dropPosition: position });\n }\n }, [store, acceptExternalDrops, node.id, isFolder, nodes, setDragState, expandNode, clearAutoExpand]);\n\n const handleDragLeave = useCallback((e: React.DragEvent) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n clearAutoExpand();\n const { dragState } = store.get();\n if (dragState.dropTargetId === node.id) {\n setDragState({ ...dragState, dropTargetId: null, dropPosition: null });\n }\n }\n }, [store, node.id, setDragState, clearAutoExpand]);\n\n const handleDrop = useCallback((e: React.DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n clearAutoExpand();\n\n const { dragState } = store.get();\n const sourceId = dragState.draggedNodeId;\n const position = dragState.dropPosition ?? computeDropPosition(e, !!isFolder);\n\n if (sourceId) {\n // Internal node move.\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n moveNode?.(sourceId, node.id, position);\n } else if (acceptExternalDrops) {\n // External drop — files, items from other components, etc.\n externalDrop?.(e, node, position);\n }\n\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [store, node, isFolder, nodes, moveNode, acceptExternalDrops, externalDrop, setDragState, clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Render\n // ---------------------------------------------------------------------------\n\n const canDrag = draggable && !node.disabled;\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <div\n data-react-fancy-tree-node=\"\"\n onDragOver={dropEnabled ? handleDragOver : undefined}\n onDragLeave={dropEnabled ? handleDragLeave : undefined}\n onDrop={dropEnabled ? handleDrop : undefined}\n >\n {/* Before drop indicator */}\n {isDropTarget && dropPosition === \"before\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"before\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n <button\n type=\"button\"\n draggable={canDrag}\n onDragStart={canDrag ? handleDragStart : undefined}\n onDragEnd={canDrag ? handleDragEnd : undefined}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n disabled={node.disabled}\n className={cn(\n \"flex w-full items-center gap-1 rounded-md py-0.5 text-left text-[13px] transition-colors\",\n isSelected\n ? \"bg-blue-500/15 text-blue-600 dark:text-blue-400\"\n : \"text-[color:var(--fancy-text-soft,var(--color-zinc-700))] hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:text-[color:var(--fancy-text-soft-dark,var(--color-zinc-300))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n node.disabled && \"pointer-events-none opacity-40\",\n isDragging && \"opacity-50\",\n // Grab affordance. By default (`dragCursor=\"none\"`) the row keeps its\n // normal click cursor on hover — no open-hand \"move me\" cursor before\n // any drag — and only shows the closed-hand `grabbing` cursor while a\n // drag is actually underway (mousedown/drag). `dragCursor=\"grab\"` opts\n // back into the always-on grab cursor for whole-row drag handles (#14).\n canDrag &&\n (dragCursor === \"grab\" ? \"cursor-grab active:cursor-grabbing\" : \"active:cursor-grabbing\"),\n isDropTarget && dropPosition === \"inside\" && \"bg-blue-500/10 ring-1 ring-blue-500/30 ring-inset\",\n )}\n style={{ paddingLeft }}\n >\n {isFolder && <ChevronIcon open={isExpanded} />}\n {!isFolder && <span className=\"w-3.5 shrink-0\" />}\n {showIcons && (\n node.icon ?? (isFolder\n ? <FolderIcon open={isExpanded} />\n : <FileIcon ext={node.ext ?? node.label.split(\".\").pop()} />)\n )}\n <span className=\"truncate\">{node.label}</span>\n </button>\n\n {/* After drop indicator */}\n {isDropTarget && dropPosition === \"after\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"after\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n {/* A virtual list renders rows flat, so a row never renders its own children there. */}\n {!flat && isFolder && isExpanded && node.children && (\n <div data-react-fancy-tree-node-children=\"\">\n {node.children.map((child) => (\n <TreeNode key={child.id} node={child} depth={depth + 1} />\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport const TreeNode = memo(TreeNodeImpl);\n\nTreeNode.displayName = \"TreeNode\";\n","import { useMemo, useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { VirtualList } from \"../VirtualList\";\nimport { TreeNavContext } from \"./TreeNav.context\";\nimport { TreeNode } from \"./TreeNode\";\nimport { createTreeStore, TreeInternalsContext, type TreeInternals } from \"./tree-store\";\nimport type { TreeNavProps, TreeNodeData, DragState } from \"./TreeNav.types\";\n\nfunction collectFolderIds(nodes: TreeNodeData[]): string[] {\n const ids: string[] = [];\n for (const node of nodes) {\n if (node.children && node.children.length > 0) {\n ids.push(node.id);\n ids.push(...collectFolderIds(node.children));\n }\n }\n return ids;\n}\n\nconst EMPTY_DRAG_STATE: DragState = {\n draggedNodeId: null,\n dropTargetId: null,\n dropPosition: null,\n};\n\ninterface FlatRow {\n id: string;\n node: TreeNodeData;\n depth: number;\n}\n\n/** The rows currently visible — every node, descending only into expanded folders. */\nfunction flattenVisible(nodes: TreeNodeData[], expanded: ReadonlySet<string>): FlatRow[] {\n const rows: FlatRow[] = [];\n const walk = (list: TreeNodeData[], depth: number) => {\n for (const node of list) {\n rows.push({ id: node.id, node, depth });\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n if (isFolder && node.children && expanded.has(node.id)) walk(node.children, depth + 1);\n }\n };\n walk(nodes, 0);\n return rows;\n}\n\nfunction TreeNavRoot({\n nodes,\n selectedId,\n onSelect,\n onNodeContextMenu,\n draggable = false,\n onNodeMove,\n acceptExternalDrops = false,\n onExternalDrop,\n expandedIds: controlledExpanded,\n defaultExpandedIds,\n onExpandedChange,\n defaultExpandAll = false,\n indentSize = 16,\n showIcons = true,\n dragCursor = \"none\",\n virtualize = false,\n height = 400,\n rowHeight = 26,\n className,\n}: TreeNavProps) {\n const [internalExpanded, setInternalExpanded] = useState<string[]>(() => {\n if (defaultExpandedIds) return defaultExpandedIds;\n if (defaultExpandAll) return collectFolderIds(nodes);\n return [];\n });\n\n const isControlled = controlledExpanded !== undefined;\n const expandedIds = isControlled ? controlledExpanded : internalExpanded;\n // One Set per change, so a row's \"am I expanded?\" is a lookup, not a scan.\n const expanded = useMemo(() => new Set(expandedIds), [expandedIds]);\n\n const [dragState, setDragState] = useState<DragState>(EMPTY_DRAG_STATE);\n\n /*\n * The latest props and state, for handlers that must stay STABLE. A handler\n * whose identity changes on every click would change the context rows read,\n * and re-render every row — the exact cost this component is avoiding.\n */\n const latest = useRef({ expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop });\n latest.current = { expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop };\n\n const setExpanded = useCallback((next: string[]) => {\n if (!latest.current.isControlled) setInternalExpanded(next);\n latest.current.onExpandedChange?.(next);\n }, []);\n\n const toggle = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n setExpanded(current.includes(id) ? current.filter((v) => v !== id) : [...current, id]);\n },\n [setExpanded],\n );\n\n const expandNode = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n if (!current.includes(id)) setExpanded([...current, id]);\n },\n [setExpanded],\n );\n\n const select = useCallback((node: TreeNodeData) => latest.current.onSelect?.(node.id, node), []);\n const contextMenu = useCallback(\n (e: React.MouseEvent, node: TreeNodeData) => latest.current.onNodeContextMenu?.(e, node),\n [],\n );\n const moveNode = useCallback(\n (sourceId: string, targetId: string, position: Parameters<NonNullable<TreeNavProps[\"onNodeMove\"]>>[2]) =>\n latest.current.onNodeMove?.(sourceId, targetId, position),\n [],\n );\n const externalDrop = useCallback(\n (event: React.DragEvent, target: TreeNodeData, position: Parameters<NonNullable<TreeNavProps[\"onExternalDrop\"]>>[2]) =>\n latest.current.onExternalDrop?.(event, target, position),\n [],\n );\n\n // What rows subscribe to. Seeded with this render's values so the first paint\n // is right; kept current after each render that changes them.\n const [store] = useState(() => createTreeStore({ selectedId, expanded, dragState }));\n useLayoutEffect(() => {\n const current = store.get();\n if (current.selectedId !== selectedId || current.expanded !== expanded || current.dragState !== dragState) {\n store.set({ selectedId, expanded, dragState });\n }\n }, [store, selectedId, expanded, dragState]);\n\n const hasContextMenu = onNodeContextMenu !== undefined;\n const internals = useMemo<TreeInternals>(\n () => ({\n store,\n nodes,\n select,\n toggle,\n expandNode,\n setDragState,\n // Present only when the host gave one: a row then claims the right-click.\n contextMenu: hasContextMenu ? contextMenu : undefined,\n moveNode,\n externalDrop,\n indentSize,\n showIcons,\n draggable,\n dragCursor,\n acceptExternalDrops,\n flat: virtualize,\n }),\n [store, nodes, select, toggle, expandNode, hasContextMenu, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, virtualize],\n );\n\n // Unchanged public context, still live for `useTreeNav()` callers. Rows no\n // longer read it, so its changing on a click re-renders only those callers.\n const ctx = useMemo(\n () => ({\n selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, setDragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode,\n }),\n [selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode],\n );\n\n const rows = useMemo(\n () => (virtualize ? flattenVisible(nodes, expanded) : []),\n [virtualize, nodes, expanded],\n );\n\n const handleDragEnd = useCallback(() => {\n setDragState(EMPTY_DRAG_STATE);\n }, []);\n\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <TreeNavContext.Provider value={ctx}>\n <TreeInternalsContext.Provider value={internals}>\n <nav\n data-react-fancy-tree-nav=\"\"\n data-react-fancy-tree-nav-virtual={virtualize ? \"\" : undefined}\n className={cn(\"flex flex-col gap-0.5 py-1 text-sm\", className)}\n onDragEnd={dropEnabled ? handleDragEnd : undefined}\n >\n {virtualize ? (\n <VirtualList\n items={rows}\n height={height}\n estimateRowHeight={rowHeight}\n renderRow={(row) => <TreeNode node={row.node} depth={row.depth} />}\n />\n ) : (\n nodes.map((node) => <TreeNode key={node.id} node={node} depth={0} />)\n )}\n </nav>\n </TreeInternalsContext.Provider>\n </TreeNavContext.Provider>\n );\n}\n\nTreeNavRoot.displayName = \"TreeNav\";\n\nexport const TreeNav = Object.assign(TreeNavRoot, {\n Node: TreeNode,\n});\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VirtualList } from './chunk-
|
|
1
|
+
import { VirtualList } from './chunk-ARNFT23K.js';
|
|
2
2
|
import { cn } from './chunk-MMW2JGKZ.js';
|
|
3
3
|
import { createContext, memo, useRef, useCallback, useEffect, useState, useMemo, useLayoutEffect, useContext, useSyncExternalStore } from 'react';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
@@ -499,5 +499,5 @@ var TreeNav = Object.assign(TreeNavRoot, {
|
|
|
499
499
|
});
|
|
500
500
|
|
|
501
501
|
export { TreeNav, useTreeNav };
|
|
502
|
-
//# sourceMappingURL=chunk-
|
|
503
|
-
//# sourceMappingURL=chunk-
|
|
502
|
+
//# sourceMappingURL=chunk-LYG2NLSV.js.map
|
|
503
|
+
//# sourceMappingURL=chunk-LYG2NLSV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/TreeNav/TreeNav.context.ts","../src/components/TreeNav/tree-store.ts","../src/components/TreeNav/TreeNode.tsx","../src/components/TreeNav/TreeNav.tsx"],"names":["createContext","useContext","useRef","useCallback","jsx"],"mappings":";;;;;AAGO,IAAM,cAAA,GAAiB,cAA0C,IAAI,CAAA;AAErE,SAAS,UAAA,GAAkC;AAChD,EAAA,MAAM,GAAA,GAAM,WAAW,cAAc,CAAA;AACrC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAAA,EACxE;AACA,EAAA,OAAO,GAAA;AACT;ACKO,SAAS,gBAAgB,OAAA,EAA+B;AAC7D,EAAA,IAAI,KAAA,GAAQ,OAAA;AACZ,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAgB;AACtC,EAAA,OAAO;AAAA,IACL,KAAK,MAAM,KAAA;AAAA,IACX,IAAI,IAAA,EAAM;AACR,MAAA,KAAA,GAAQ,IAAA;AACR,MAAA,KAAA,MAAW,QAAA,IAAY,WAAW,QAAA,EAAS;AAAA,IAC7C,CAAA;AAAA,IACA,UAAU,QAAA,EAAU;AAClB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A,MACrD,SAAA,EAAW,EAAA,CAAG,oCAAA,EAAsC,SAAS,CAAA;AAAA,MAC7D,SAAA,EAAW,cAAc,aAAA,GAAgB,MAAA;AAAA,MAExC,uCACCA,GAAAA;AAAA,QAAC,WAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO,IAAA;AAAA,UACP,MAAA;AAAA,UACA,iBAAA,EAAmB,SAAA;AAAA,UACnB,SAAA,EAAW,CAAC,GAAA,qBAAQA,GAAAA,CAAC,QAAA,EAAA,EAAS,IAAA,EAAM,GAAA,CAAI,IAAA,EAAM,KAAA,EAAO,GAAA,CAAI,KAAA,EAAO;AAAA;AAAA,OAClE,GAEA,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,qBAASA,GAAAA,CAAC,QAAA,EAAA,EAAuB,IAAA,EAAY,KAAA,EAAO,CAAA,EAAA,EAA5B,IAAA,CAAK,EAA0B,CAAE;AAAA;AAAA,KAG1E,CAAA,EACF,CAAA;AAEJ;AAEA,WAAA,CAAY,WAAA,GAAc,SAAA;AAEnB,IAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,WAAA,EAAa;AAAA,EAChD,IAAA,EAAM;AACR,CAAC","file":"chunk-K7SPT7YF.js","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { TreeNavContextValue } from \"./TreeNav.types\";\n\nexport const TreeNavContext = createContext<TreeNavContextValue | null>(null);\n\nexport function useTreeNav(): TreeNavContextValue {\n const ctx = useContext(TreeNavContext);\n if (!ctx) {\n throw new Error(\"useTreeNav must be used within a <TreeNav> component\");\n }\n return ctx;\n}\n","import { createContext, useContext, useSyncExternalStore } from \"react\";\nimport type { DragState, DropPosition, TreeNodeData } from \"./TreeNav.types\";\n\n/** What changes as someone clicks, toggles and drags — the state rows subscribe to. */\nexport interface TreeState {\n selectedId?: string;\n expanded: ReadonlySet<string>;\n dragState: DragState;\n}\n\nexport interface TreeStore {\n get(): TreeState;\n set(next: TreeState): void;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTreeStore(initial: TreeState): TreeStore {\n let state = initial;\n const listeners = new Set<() => void>();\n return {\n get: () => state,\n set(next) {\n state = next;\n for (const listener of listeners) listener();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\n/**\n * Everything a row needs that does NOT change on a click. Handlers are stable\n * (they read the latest props and state when called), so this value only changes\n * when the tree's data or configuration does.\n *\n * Kept apart from the public `TreeNavContext` on purpose: that one still carries\n * live `selectedId` / `expandedIds` for `useTreeNav()` callers, and any component\n * reading it re-renders on every click. Rows no longer read it — which is the\n * whole fix: a click used to re-render every row in the tree.\n */\nexport interface TreeInternals {\n store: TreeStore;\n nodes: TreeNodeData[];\n select: (node: TreeNodeData) => void;\n toggle: (id: string) => void;\n expandNode: (id: string) => void;\n setDragState: (state: DragState) => void;\n contextMenu?: (e: React.MouseEvent, node: TreeNodeData) => void;\n moveNode?: (sourceId: string, targetId: string, position: DropPosition) => void;\n externalDrop?: (event: React.DragEvent, target: TreeNodeData, position: DropPosition) => void;\n indentSize: number;\n showIcons: boolean;\n draggable: boolean;\n dragCursor: \"grab\" | \"none\";\n acceptExternalDrops: boolean;\n /** Rows are rendered flat by a virtual list, so a row never renders its children. */\n flat: boolean;\n}\n\nexport const TreeInternalsContext = createContext<TreeInternals | null>(null);\n\nexport function useTreeInternals(): TreeInternals {\n const internals = useContext(TreeInternalsContext);\n if (!internals) throw new Error(\"TreeNav.Node must be used within a <TreeNav> component\");\n return internals;\n}\n\n/** Subscribe to ONE derived value; the row re-renders only when that value changes. */\nexport function useTreeSlice<T>(select: (state: TreeState) => T): T {\n const { store } = useTreeInternals();\n return useSyncExternalStore(\n store.subscribe,\n () => select(store.get()),\n () => select(store.get()),\n );\n}\n","import { memo, useRef, useEffect, useCallback } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useTreeInternals, useTreeSlice } from \"./tree-store\";\nimport type { TreeNodeProps, TreeNodeData, DropPosition } from \"./TreeNav.types\";\n\nconst EXT_COLORS: Record<string, string> = {\n ts: \"#3178c6\",\n tsx: \"#3178c6\",\n js: \"#f7df1e\",\n jsx: \"#f7df1e\",\n php: \"#777bb4\",\n html: \"#e34c26\",\n htm: \"#e34c26\",\n css: \"#264de4\",\n json: \"#a1a1aa\",\n md: \"#71717a\",\n yaml: \"#cb171e\",\n yml: \"#cb171e\",\n};\n\nfunction FileIcon({ ext }: { ext?: string }) {\n const color = (ext && EXT_COLORS[ext.toLowerCase()]) || \"#71717a\";\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M4 1h5.5L13 4.5V14a1 1 0 01-1 1H4a1 1 0 01-1-1V2a1 1 0 011-1z\" stroke={color} strokeWidth=\"1.2\" />\n <path d=\"M9 1v4h4\" stroke={color} strokeWidth=\"1.2\" />\n </svg>\n );\n}\n\nfunction FolderIcon({ open }: { open: boolean }) {\n if (open) {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3.5a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1V5H2.5V3.5z\" fill=\"#fbbf24\" />\n <path d=\"M1 6h13l-1.5 7.5H2.5L1 6z\" fill=\"#fbbf24\" opacity=\"0.7\" />\n </svg>\n );\n }\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1v8a1 1 0 01-1 1H2.5a1 1 0 01-1-1V3z\" fill=\"#fbbf24\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ open }: { open: boolean }) {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={cn(\"shrink-0 transition-transform duration-150\", open && \"rotate-90\")}\n >\n <polyline points=\"9 18 15 12 9 6\" />\n </svg>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isDescendantOf(\n nodes: TreeNodeData[],\n ancestorId: string,\n targetId: string,\n): boolean {\n function findNode(haystack: TreeNodeData[], id: string): TreeNodeData | undefined {\n for (const n of haystack) {\n if (n.id === id) return n;\n if (n.children) {\n const found = findNode(n.children, id);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n function hasDescendant(node: TreeNodeData, id: string): boolean {\n if (!node.children) return false;\n for (const child of node.children) {\n if (child.id === id) return true;\n if (hasDescendant(child, id)) return true;\n }\n return false;\n }\n\n const ancestor = findNode(nodes, ancestorId);\n return ancestor ? hasDescendant(ancestor, targetId) : false;\n}\n\nfunction computeDropPosition(\n e: React.DragEvent,\n isFolder: boolean,\n): DropPosition {\n const rect = e.currentTarget.getBoundingClientRect();\n const offsetY = e.clientY - rect.top;\n const third = rect.height / 3;\n\n if (offsetY < third) return \"before\";\n if (offsetY > third * 2) return \"after\";\n return isFolder ? \"inside\" : \"after\";\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n\n/**\n * One row (and, when nested, its expanded children).\n *\n * Reads what changes on a click — selection, expansion, drag — as per-row slices\n * of a store, so a click re-renders only the rows whose slice changed. It used to\n * read one context holding all of it, so every click re-rendered every row:\n * 175-267 ms per click on a 5,000-node tree. `memo` keeps a parent's re-render\n * from reaching rows whose `node` and `depth` did not change.\n */\nfunction TreeNodeImpl({ node, depth }: TreeNodeProps) {\n const {\n store, nodes, select, toggle, expandNode, setDragState, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, flat,\n } = useTreeInternals();\n\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n const isExpanded = useTreeSlice((s) => s.expanded.has(node.id));\n const isSelected = useTreeSlice((s) => s.selectedId === node.id);\n const isDragging = useTreeSlice((s) => s.dragState.draggedNodeId === node.id);\n const dropPosition = useTreeSlice((s) =>\n s.dragState.dropTargetId === node.id ? s.dragState.dropPosition : null,\n );\n const isDropTarget = dropPosition !== null;\n const paddingLeft = depth * indentSize + 4;\n\n // Auto-expand timer for folders during drag\n const autoExpandTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearAutoExpand = useCallback(() => {\n if (autoExpandTimer.current) {\n clearTimeout(autoExpandTimer.current);\n autoExpandTimer.current = null;\n }\n }, []);\n\n useEffect(() => clearAutoExpand, [clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Click handlers\n // ---------------------------------------------------------------------------\n\n const handleClick = () => {\n if (node.disabled) return;\n if (isFolder) {\n toggle(node.id);\n }\n select(node);\n };\n\n const handleContextMenu = (e: React.MouseEvent) => {\n if (contextMenu) {\n e.preventDefault();\n contextMenu(e, node);\n }\n };\n\n // ---------------------------------------------------------------------------\n // Drag source handlers\n // ---------------------------------------------------------------------------\n\n const handleDragStart = useCallback((e: React.DragEvent) => {\n e.dataTransfer.setData(\"text/plain\", node.id);\n e.dataTransfer.effectAllowed = \"move\";\n // Set state async so the browser captures the element for the drag ghost first\n requestAnimationFrame(() => {\n setDragState({ draggedNodeId: node.id, dropTargetId: null, dropPosition: null });\n });\n }, [node.id, setDragState]);\n\n const handleDragEnd = useCallback(() => {\n clearAutoExpand();\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [clearAutoExpand, setDragState]);\n\n // ---------------------------------------------------------------------------\n // Drop target handlers (on outer div). Drag state is read from the store when\n // the event fires, so a row does not re-render as a drag moves elsewhere.\n // ---------------------------------------------------------------------------\n\n const handleDragOver = useCallback((e: React.DragEvent) => {\n const { dragState } = store.get();\n const isExternalDrag = !dragState.draggedNodeId;\n if (isExternalDrag) {\n // External drop accepted only when host opted in.\n if (!acceptExternalDrops) return;\n } else {\n const sourceId = dragState.draggedNodeId!;\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = isExternalDrag ? \"copy\" : \"move\";\n\n const position = computeDropPosition(e, !!isFolder);\n\n // Auto-expand collapsed folders when hovering \"inside\"\n if (isFolder && !store.get().expanded.has(node.id) && position === \"inside\") {\n if (!autoExpandTimer.current) {\n autoExpandTimer.current = setTimeout(() => {\n expandNode(node.id);\n autoExpandTimer.current = null;\n }, 500);\n }\n } else {\n clearAutoExpand();\n }\n\n if (dragState.dropTargetId !== node.id || dragState.dropPosition !== position) {\n setDragState({ draggedNodeId: dragState.draggedNodeId, dropTargetId: node.id, dropPosition: position });\n }\n }, [store, acceptExternalDrops, node.id, isFolder, nodes, setDragState, expandNode, clearAutoExpand]);\n\n const handleDragLeave = useCallback((e: React.DragEvent) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n clearAutoExpand();\n const { dragState } = store.get();\n if (dragState.dropTargetId === node.id) {\n setDragState({ ...dragState, dropTargetId: null, dropPosition: null });\n }\n }\n }, [store, node.id, setDragState, clearAutoExpand]);\n\n const handleDrop = useCallback((e: React.DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n clearAutoExpand();\n\n const { dragState } = store.get();\n const sourceId = dragState.draggedNodeId;\n const position = dragState.dropPosition ?? computeDropPosition(e, !!isFolder);\n\n if (sourceId) {\n // Internal node move.\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n moveNode?.(sourceId, node.id, position);\n } else if (acceptExternalDrops) {\n // External drop — files, items from other components, etc.\n externalDrop?.(e, node, position);\n }\n\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [store, node, isFolder, nodes, moveNode, acceptExternalDrops, externalDrop, setDragState, clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Render\n // ---------------------------------------------------------------------------\n\n const canDrag = draggable && !node.disabled;\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <div\n data-react-fancy-tree-node=\"\"\n onDragOver={dropEnabled ? handleDragOver : undefined}\n onDragLeave={dropEnabled ? handleDragLeave : undefined}\n onDrop={dropEnabled ? handleDrop : undefined}\n >\n {/* Before drop indicator */}\n {isDropTarget && dropPosition === \"before\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"before\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n <button\n type=\"button\"\n draggable={canDrag}\n onDragStart={canDrag ? handleDragStart : undefined}\n onDragEnd={canDrag ? handleDragEnd : undefined}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n disabled={node.disabled}\n className={cn(\n \"flex w-full items-center gap-1 rounded-md py-0.5 text-left text-[13px] transition-colors\",\n isSelected\n ? \"bg-blue-500/15 text-blue-600 dark:text-blue-400\"\n : \"text-[color:var(--fancy-text-soft,var(--color-zinc-700))] hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:text-[color:var(--fancy-text-soft-dark,var(--color-zinc-300))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n node.disabled && \"pointer-events-none opacity-40\",\n isDragging && \"opacity-50\",\n // Grab affordance. By default (`dragCursor=\"none\"`) the row keeps its\n // normal click cursor on hover — no open-hand \"move me\" cursor before\n // any drag — and only shows the closed-hand `grabbing` cursor while a\n // drag is actually underway (mousedown/drag). `dragCursor=\"grab\"` opts\n // back into the always-on grab cursor for whole-row drag handles (#14).\n canDrag &&\n (dragCursor === \"grab\" ? \"cursor-grab active:cursor-grabbing\" : \"active:cursor-grabbing\"),\n isDropTarget && dropPosition === \"inside\" && \"bg-blue-500/10 ring-1 ring-blue-500/30 ring-inset\",\n )}\n style={{ paddingLeft }}\n >\n {isFolder && <ChevronIcon open={isExpanded} />}\n {!isFolder && <span className=\"w-3.5 shrink-0\" />}\n {showIcons && (\n node.icon ?? (isFolder\n ? <FolderIcon open={isExpanded} />\n : <FileIcon ext={node.ext ?? node.label.split(\".\").pop()} />)\n )}\n <span className=\"truncate\">{node.label}</span>\n </button>\n\n {/* After drop indicator */}\n {isDropTarget && dropPosition === \"after\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"after\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n {/* A virtual list renders rows flat, so a row never renders its own children there. */}\n {!flat && isFolder && isExpanded && node.children && (\n <div data-react-fancy-tree-node-children=\"\">\n {node.children.map((child) => (\n <TreeNode key={child.id} node={child} depth={depth + 1} />\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport const TreeNode = memo(TreeNodeImpl);\n\nTreeNode.displayName = \"TreeNode\";\n","import { useMemo, useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { VirtualList } from \"../VirtualList\";\nimport { TreeNavContext } from \"./TreeNav.context\";\nimport { TreeNode } from \"./TreeNode\";\nimport { createTreeStore, TreeInternalsContext, type TreeInternals } from \"./tree-store\";\nimport type { TreeNavProps, TreeNodeData, DragState } from \"./TreeNav.types\";\n\nfunction collectFolderIds(nodes: TreeNodeData[]): string[] {\n const ids: string[] = [];\n for (const node of nodes) {\n if (node.children && node.children.length > 0) {\n ids.push(node.id);\n ids.push(...collectFolderIds(node.children));\n }\n }\n return ids;\n}\n\nconst EMPTY_DRAG_STATE: DragState = {\n draggedNodeId: null,\n dropTargetId: null,\n dropPosition: null,\n};\n\ninterface FlatRow {\n id: string;\n node: TreeNodeData;\n depth: number;\n}\n\n/** The rows currently visible — every node, descending only into expanded folders. */\nfunction flattenVisible(nodes: TreeNodeData[], expanded: ReadonlySet<string>): FlatRow[] {\n const rows: FlatRow[] = [];\n const walk = (list: TreeNodeData[], depth: number) => {\n for (const node of list) {\n rows.push({ id: node.id, node, depth });\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n if (isFolder && node.children && expanded.has(node.id)) walk(node.children, depth + 1);\n }\n };\n walk(nodes, 0);\n return rows;\n}\n\nfunction TreeNavRoot({\n nodes,\n selectedId,\n onSelect,\n onNodeContextMenu,\n draggable = false,\n onNodeMove,\n acceptExternalDrops = false,\n onExternalDrop,\n expandedIds: controlledExpanded,\n defaultExpandedIds,\n onExpandedChange,\n defaultExpandAll = false,\n indentSize = 16,\n showIcons = true,\n dragCursor = \"none\",\n virtualize = false,\n height = 400,\n rowHeight = 26,\n className,\n}: TreeNavProps) {\n const [internalExpanded, setInternalExpanded] = useState<string[]>(() => {\n if (defaultExpandedIds) return defaultExpandedIds;\n if (defaultExpandAll) return collectFolderIds(nodes);\n return [];\n });\n\n const isControlled = controlledExpanded !== undefined;\n const expandedIds = isControlled ? controlledExpanded : internalExpanded;\n // One Set per change, so a row's \"am I expanded?\" is a lookup, not a scan.\n const expanded = useMemo(() => new Set(expandedIds), [expandedIds]);\n\n const [dragState, setDragState] = useState<DragState>(EMPTY_DRAG_STATE);\n\n /*\n * The latest props and state, for handlers that must stay STABLE. A handler\n * whose identity changes on every click would change the context rows read,\n * and re-render every row — the exact cost this component is avoiding.\n */\n const latest = useRef({ expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop });\n latest.current = { expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop };\n\n const setExpanded = useCallback((next: string[]) => {\n if (!latest.current.isControlled) setInternalExpanded(next);\n latest.current.onExpandedChange?.(next);\n }, []);\n\n const toggle = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n setExpanded(current.includes(id) ? current.filter((v) => v !== id) : [...current, id]);\n },\n [setExpanded],\n );\n\n const expandNode = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n if (!current.includes(id)) setExpanded([...current, id]);\n },\n [setExpanded],\n );\n\n const select = useCallback((node: TreeNodeData) => latest.current.onSelect?.(node.id, node), []);\n const contextMenu = useCallback(\n (e: React.MouseEvent, node: TreeNodeData) => latest.current.onNodeContextMenu?.(e, node),\n [],\n );\n const moveNode = useCallback(\n (sourceId: string, targetId: string, position: Parameters<NonNullable<TreeNavProps[\"onNodeMove\"]>>[2]) =>\n latest.current.onNodeMove?.(sourceId, targetId, position),\n [],\n );\n const externalDrop = useCallback(\n (event: React.DragEvent, target: TreeNodeData, position: Parameters<NonNullable<TreeNavProps[\"onExternalDrop\"]>>[2]) =>\n latest.current.onExternalDrop?.(event, target, position),\n [],\n );\n\n // What rows subscribe to. Seeded with this render's values so the first paint\n // is right; kept current after each render that changes them.\n const [store] = useState(() => createTreeStore({ selectedId, expanded, dragState }));\n useLayoutEffect(() => {\n const current = store.get();\n if (current.selectedId !== selectedId || current.expanded !== expanded || current.dragState !== dragState) {\n store.set({ selectedId, expanded, dragState });\n }\n }, [store, selectedId, expanded, dragState]);\n\n const hasContextMenu = onNodeContextMenu !== undefined;\n const internals = useMemo<TreeInternals>(\n () => ({\n store,\n nodes,\n select,\n toggle,\n expandNode,\n setDragState,\n // Present only when the host gave one: a row then claims the right-click.\n contextMenu: hasContextMenu ? contextMenu : undefined,\n moveNode,\n externalDrop,\n indentSize,\n showIcons,\n draggable,\n dragCursor,\n acceptExternalDrops,\n flat: virtualize,\n }),\n [store, nodes, select, toggle, expandNode, hasContextMenu, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, virtualize],\n );\n\n // Unchanged public context, still live for `useTreeNav()` callers. Rows no\n // longer read it, so its changing on a click re-renders only those callers.\n const ctx = useMemo(\n () => ({\n selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, setDragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode,\n }),\n [selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode],\n );\n\n const rows = useMemo(\n () => (virtualize ? flattenVisible(nodes, expanded) : []),\n [virtualize, nodes, expanded],\n );\n\n const handleDragEnd = useCallback(() => {\n setDragState(EMPTY_DRAG_STATE);\n }, []);\n\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <TreeNavContext.Provider value={ctx}>\n <TreeInternalsContext.Provider value={internals}>\n <nav\n data-react-fancy-tree-nav=\"\"\n data-react-fancy-tree-nav-virtual={virtualize ? \"\" : undefined}\n className={cn(\"flex flex-col gap-0.5 py-1 text-sm\", className)}\n onDragEnd={dropEnabled ? handleDragEnd : undefined}\n >\n {virtualize ? (\n <VirtualList\n items={rows}\n height={height}\n estimateRowHeight={rowHeight}\n renderRow={(row) => <TreeNode node={row.node} depth={row.depth} />}\n />\n ) : (\n nodes.map((node) => <TreeNode key={node.id} node={node} depth={0} />)\n )}\n </nav>\n </TreeInternalsContext.Provider>\n </TreeNavContext.Provider>\n );\n}\n\nTreeNavRoot.displayName = \"TreeNav\";\n\nexport const TreeNav = Object.assign(TreeNavRoot, {\n Node: TreeNode,\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/TreeNav/TreeNav.context.ts","../src/components/TreeNav/tree-store.ts","../src/components/TreeNav/TreeNode.tsx","../src/components/TreeNav/TreeNav.tsx"],"names":["createContext","useContext","useRef","useCallback","jsx"],"mappings":";;;;;AAGO,IAAM,cAAA,GAAiB,cAA0C,IAAI,CAAA;AAErE,SAAS,UAAA,GAAkC;AAChD,EAAA,MAAM,GAAA,GAAM,WAAW,cAAc,CAAA;AACrC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAAA,EACxE;AACA,EAAA,OAAO,GAAA;AACT;ACKO,SAAS,gBAAgB,OAAA,EAA+B;AAC7D,EAAA,IAAI,KAAA,GAAQ,OAAA;AACZ,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAgB;AACtC,EAAA,OAAO;AAAA,IACL,KAAK,MAAM,KAAA;AAAA,IACX,IAAI,IAAA,EAAM;AACR,MAAA,KAAA,GAAQ,IAAA;AACR,MAAA,KA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IAAA;AAAA,MACC,2BAAA,EAA0B,EAAA;AAAA,MAC1B,mCAAA,EAAmC,aAAa,EAAA,GAAK,MAAA;AAAA,MACrD,SAAA,EAAW,EAAA,CAAG,oCAAA,EAAsC,SAAS,CAAA;AAAA,MAC7D,SAAA,EAAW,cAAc,aAAA,GAAgB,MAAA;AAAA,MAExC,uCACCA,GAAAA;AAAA,QAAC,WAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO,IAAA;AAAA,UACP,MAAA;AAAA,UACA,iBAAA,EAAmB,SAAA;AAAA,UACnB,SAAA,EAAW,CAAC,GAAA,qBAAQA,GAAAA,CAAC,QAAA,EAAA,EAAS,IAAA,EAAM,GAAA,CAAI,IAAA,EAAM,KAAA,EAAO,GAAA,CAAI,KAAA,EAAO;AAAA;AAAA,OAClE,GAEA,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,qBAASA,GAAAA,CAAC,QAAA,EAAA,EAAuB,IAAA,EAAY,KAAA,EAAO,CAAA,EAAA,EAA5B,IAAA,CAAK,EAA0B,CAAE;AAAA;AAAA,KAG1E,CAAA,EACF,CAAA;AAEJ;AAEA,WAAA,CAAY,WAAA,GAAc,SAAA;AAEnB,IAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,WAAA,EAAa;AAAA,EAChD,IAAA,EAAM;AACR,CAAC","file":"chunk-LYG2NLSV.js","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { TreeNavContextValue } from \"./TreeNav.types\";\n\nexport const TreeNavContext = createContext<TreeNavContextValue | null>(null);\n\nexport function useTreeNav(): TreeNavContextValue {\n const ctx = useContext(TreeNavContext);\n if (!ctx) {\n throw new Error(\"useTreeNav must be used within a <TreeNav> component\");\n }\n return ctx;\n}\n","import { createContext, useContext, useSyncExternalStore } from \"react\";\nimport type { DragState, DropPosition, TreeNodeData } from \"./TreeNav.types\";\n\n/** What changes as someone clicks, toggles and drags — the state rows subscribe to. */\nexport interface TreeState {\n selectedId?: string;\n expanded: ReadonlySet<string>;\n dragState: DragState;\n}\n\nexport interface TreeStore {\n get(): TreeState;\n set(next: TreeState): void;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTreeStore(initial: TreeState): TreeStore {\n let state = initial;\n const listeners = new Set<() => void>();\n return {\n get: () => state,\n set(next) {\n state = next;\n for (const listener of listeners) listener();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\n/**\n * Everything a row needs that does NOT change on a click. Handlers are stable\n * (they read the latest props and state when called), so this value only changes\n * when the tree's data or configuration does.\n *\n * Kept apart from the public `TreeNavContext` on purpose: that one still carries\n * live `selectedId` / `expandedIds` for `useTreeNav()` callers, and any component\n * reading it re-renders on every click. Rows no longer read it — which is the\n * whole fix: a click used to re-render every row in the tree.\n */\nexport interface TreeInternals {\n store: TreeStore;\n nodes: TreeNodeData[];\n select: (node: TreeNodeData) => void;\n toggle: (id: string) => void;\n expandNode: (id: string) => void;\n setDragState: (state: DragState) => void;\n contextMenu?: (e: React.MouseEvent, node: TreeNodeData) => void;\n moveNode?: (sourceId: string, targetId: string, position: DropPosition) => void;\n externalDrop?: (event: React.DragEvent, target: TreeNodeData, position: DropPosition) => void;\n indentSize: number;\n showIcons: boolean;\n draggable: boolean;\n dragCursor: \"grab\" | \"none\";\n acceptExternalDrops: boolean;\n /** Rows are rendered flat by a virtual list, so a row never renders its children. */\n flat: boolean;\n}\n\nexport const TreeInternalsContext = createContext<TreeInternals | null>(null);\n\nexport function useTreeInternals(): TreeInternals {\n const internals = useContext(TreeInternalsContext);\n if (!internals) throw new Error(\"TreeNav.Node must be used within a <TreeNav> component\");\n return internals;\n}\n\n/** Subscribe to ONE derived value; the row re-renders only when that value changes. */\nexport function useTreeSlice<T>(select: (state: TreeState) => T): T {\n const { store } = useTreeInternals();\n return useSyncExternalStore(\n store.subscribe,\n () => select(store.get()),\n () => select(store.get()),\n );\n}\n","import { memo, useRef, useEffect, useCallback } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useTreeInternals, useTreeSlice } from \"./tree-store\";\nimport type { TreeNodeProps, TreeNodeData, DropPosition } from \"./TreeNav.types\";\n\nconst EXT_COLORS: Record<string, string> = {\n ts: \"#3178c6\",\n tsx: \"#3178c6\",\n js: \"#f7df1e\",\n jsx: \"#f7df1e\",\n php: \"#777bb4\",\n html: \"#e34c26\",\n htm: \"#e34c26\",\n css: \"#264de4\",\n json: \"#a1a1aa\",\n md: \"#71717a\",\n yaml: \"#cb171e\",\n yml: \"#cb171e\",\n};\n\nfunction FileIcon({ ext }: { ext?: string }) {\n const color = (ext && EXT_COLORS[ext.toLowerCase()]) || \"#71717a\";\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M4 1h5.5L13 4.5V14a1 1 0 01-1 1H4a1 1 0 01-1-1V2a1 1 0 011-1z\" stroke={color} strokeWidth=\"1.2\" />\n <path d=\"M9 1v4h4\" stroke={color} strokeWidth=\"1.2\" />\n </svg>\n );\n}\n\nfunction FolderIcon({ open }: { open: boolean }) {\n if (open) {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3.5a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1V5H2.5V3.5z\" fill=\"#fbbf24\" />\n <path d=\"M1 6h13l-1.5 7.5H2.5L1 6z\" fill=\"#fbbf24\" opacity=\"0.7\" />\n </svg>\n );\n }\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\">\n <path d=\"M1.5 3a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1v8a1 1 0 01-1 1H2.5a1 1 0 01-1-1V3z\" fill=\"#fbbf24\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ open }: { open: boolean }) {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={cn(\"shrink-0 transition-transform duration-150\", open && \"rotate-90\")}\n >\n <polyline points=\"9 18 15 12 9 6\" />\n </svg>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isDescendantOf(\n nodes: TreeNodeData[],\n ancestorId: string,\n targetId: string,\n): boolean {\n function findNode(haystack: TreeNodeData[], id: string): TreeNodeData | undefined {\n for (const n of haystack) {\n if (n.id === id) return n;\n if (n.children) {\n const found = findNode(n.children, id);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n function hasDescendant(node: TreeNodeData, id: string): boolean {\n if (!node.children) return false;\n for (const child of node.children) {\n if (child.id === id) return true;\n if (hasDescendant(child, id)) return true;\n }\n return false;\n }\n\n const ancestor = findNode(nodes, ancestorId);\n return ancestor ? hasDescendant(ancestor, targetId) : false;\n}\n\nfunction computeDropPosition(\n e: React.DragEvent,\n isFolder: boolean,\n): DropPosition {\n const rect = e.currentTarget.getBoundingClientRect();\n const offsetY = e.clientY - rect.top;\n const third = rect.height / 3;\n\n if (offsetY < third) return \"before\";\n if (offsetY > third * 2) return \"after\";\n return isFolder ? \"inside\" : \"after\";\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n\n/**\n * One row (and, when nested, its expanded children).\n *\n * Reads what changes on a click — selection, expansion, drag — as per-row slices\n * of a store, so a click re-renders only the rows whose slice changed. It used to\n * read one context holding all of it, so every click re-rendered every row:\n * 175-267 ms per click on a 5,000-node tree. `memo` keeps a parent's re-render\n * from reaching rows whose `node` and `depth` did not change.\n */\nfunction TreeNodeImpl({ node, depth }: TreeNodeProps) {\n const {\n store, nodes, select, toggle, expandNode, setDragState, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, flat,\n } = useTreeInternals();\n\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n const isExpanded = useTreeSlice((s) => s.expanded.has(node.id));\n const isSelected = useTreeSlice((s) => s.selectedId === node.id);\n const isDragging = useTreeSlice((s) => s.dragState.draggedNodeId === node.id);\n const dropPosition = useTreeSlice((s) =>\n s.dragState.dropTargetId === node.id ? s.dragState.dropPosition : null,\n );\n const isDropTarget = dropPosition !== null;\n const paddingLeft = depth * indentSize + 4;\n\n // Auto-expand timer for folders during drag\n const autoExpandTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearAutoExpand = useCallback(() => {\n if (autoExpandTimer.current) {\n clearTimeout(autoExpandTimer.current);\n autoExpandTimer.current = null;\n }\n }, []);\n\n useEffect(() => clearAutoExpand, [clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Click handlers\n // ---------------------------------------------------------------------------\n\n const handleClick = () => {\n if (node.disabled) return;\n if (isFolder) {\n toggle(node.id);\n }\n select(node);\n };\n\n const handleContextMenu = (e: React.MouseEvent) => {\n if (contextMenu) {\n e.preventDefault();\n contextMenu(e, node);\n }\n };\n\n // ---------------------------------------------------------------------------\n // Drag source handlers\n // ---------------------------------------------------------------------------\n\n const handleDragStart = useCallback((e: React.DragEvent) => {\n e.dataTransfer.setData(\"text/plain\", node.id);\n e.dataTransfer.effectAllowed = \"move\";\n // Set state async so the browser captures the element for the drag ghost first\n requestAnimationFrame(() => {\n setDragState({ draggedNodeId: node.id, dropTargetId: null, dropPosition: null });\n });\n }, [node.id, setDragState]);\n\n const handleDragEnd = useCallback(() => {\n clearAutoExpand();\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [clearAutoExpand, setDragState]);\n\n // ---------------------------------------------------------------------------\n // Drop target handlers (on outer div). Drag state is read from the store when\n // the event fires, so a row does not re-render as a drag moves elsewhere.\n // ---------------------------------------------------------------------------\n\n const handleDragOver = useCallback((e: React.DragEvent) => {\n const { dragState } = store.get();\n const isExternalDrag = !dragState.draggedNodeId;\n if (isExternalDrag) {\n // External drop accepted only when host opted in.\n if (!acceptExternalDrops) return;\n } else {\n const sourceId = dragState.draggedNodeId!;\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = isExternalDrag ? \"copy\" : \"move\";\n\n const position = computeDropPosition(e, !!isFolder);\n\n // Auto-expand collapsed folders when hovering \"inside\"\n if (isFolder && !store.get().expanded.has(node.id) && position === \"inside\") {\n if (!autoExpandTimer.current) {\n autoExpandTimer.current = setTimeout(() => {\n expandNode(node.id);\n autoExpandTimer.current = null;\n }, 500);\n }\n } else {\n clearAutoExpand();\n }\n\n if (dragState.dropTargetId !== node.id || dragState.dropPosition !== position) {\n setDragState({ draggedNodeId: dragState.draggedNodeId, dropTargetId: node.id, dropPosition: position });\n }\n }, [store, acceptExternalDrops, node.id, isFolder, nodes, setDragState, expandNode, clearAutoExpand]);\n\n const handleDragLeave = useCallback((e: React.DragEvent) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n clearAutoExpand();\n const { dragState } = store.get();\n if (dragState.dropTargetId === node.id) {\n setDragState({ ...dragState, dropTargetId: null, dropPosition: null });\n }\n }\n }, [store, node.id, setDragState, clearAutoExpand]);\n\n const handleDrop = useCallback((e: React.DragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n clearAutoExpand();\n\n const { dragState } = store.get();\n const sourceId = dragState.draggedNodeId;\n const position = dragState.dropPosition ?? computeDropPosition(e, !!isFolder);\n\n if (sourceId) {\n // Internal node move.\n if (sourceId === node.id) return;\n if (isDescendantOf(nodes, sourceId, node.id)) return;\n moveNode?.(sourceId, node.id, position);\n } else if (acceptExternalDrops) {\n // External drop — files, items from other components, etc.\n externalDrop?.(e, node, position);\n }\n\n setDragState({ draggedNodeId: null, dropTargetId: null, dropPosition: null });\n }, [store, node, isFolder, nodes, moveNode, acceptExternalDrops, externalDrop, setDragState, clearAutoExpand]);\n\n // ---------------------------------------------------------------------------\n // Render\n // ---------------------------------------------------------------------------\n\n const canDrag = draggable && !node.disabled;\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <div\n data-react-fancy-tree-node=\"\"\n onDragOver={dropEnabled ? handleDragOver : undefined}\n onDragLeave={dropEnabled ? handleDragLeave : undefined}\n onDrop={dropEnabled ? handleDrop : undefined}\n >\n {/* Before drop indicator */}\n {isDropTarget && dropPosition === \"before\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"before\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n <button\n type=\"button\"\n draggable={canDrag}\n onDragStart={canDrag ? handleDragStart : undefined}\n onDragEnd={canDrag ? handleDragEnd : undefined}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n disabled={node.disabled}\n className={cn(\n \"flex w-full items-center gap-1 rounded-md py-0.5 text-left text-[13px] transition-colors\",\n isSelected\n ? \"bg-blue-500/15 text-blue-600 dark:text-blue-400\"\n : \"text-[color:var(--fancy-text-soft,var(--color-zinc-700))] hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:text-[color:var(--fancy-text-soft-dark,var(--color-zinc-300))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n node.disabled && \"pointer-events-none opacity-40\",\n isDragging && \"opacity-50\",\n // Grab affordance. By default (`dragCursor=\"none\"`) the row keeps its\n // normal click cursor on hover — no open-hand \"move me\" cursor before\n // any drag — and only shows the closed-hand `grabbing` cursor while a\n // drag is actually underway (mousedown/drag). `dragCursor=\"grab\"` opts\n // back into the always-on grab cursor for whole-row drag handles (#14).\n canDrag &&\n (dragCursor === \"grab\" ? \"cursor-grab active:cursor-grabbing\" : \"active:cursor-grabbing\"),\n isDropTarget && dropPosition === \"inside\" && \"bg-blue-500/10 ring-1 ring-blue-500/30 ring-inset\",\n )}\n style={{ paddingLeft }}\n >\n {isFolder && <ChevronIcon open={isExpanded} />}\n {!isFolder && <span className=\"w-3.5 shrink-0\" />}\n {showIcons && (\n node.icon ?? (isFolder\n ? <FolderIcon open={isExpanded} />\n : <FileIcon ext={node.ext ?? node.label.split(\".\").pop()} />)\n )}\n <span className=\"truncate\">{node.label}</span>\n </button>\n\n {/* After drop indicator */}\n {isDropTarget && dropPosition === \"after\" && (\n <div\n data-react-fancy-tree-drop-indicator=\"after\"\n className=\"pointer-events-none h-0.5 rounded-full bg-blue-500\"\n style={{ marginLeft: paddingLeft }}\n />\n )}\n\n {/* A virtual list renders rows flat, so a row never renders its own children there. */}\n {!flat && isFolder && isExpanded && node.children && (\n <div data-react-fancy-tree-node-children=\"\">\n {node.children.map((child) => (\n <TreeNode key={child.id} node={child} depth={depth + 1} />\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport const TreeNode = memo(TreeNodeImpl);\n\nTreeNode.displayName = \"TreeNode\";\n","import { useMemo, useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { VirtualList } from \"../VirtualList\";\nimport { TreeNavContext } from \"./TreeNav.context\";\nimport { TreeNode } from \"./TreeNode\";\nimport { createTreeStore, TreeInternalsContext, type TreeInternals } from \"./tree-store\";\nimport type { TreeNavProps, TreeNodeData, DragState } from \"./TreeNav.types\";\n\nfunction collectFolderIds(nodes: TreeNodeData[]): string[] {\n const ids: string[] = [];\n for (const node of nodes) {\n if (node.children && node.children.length > 0) {\n ids.push(node.id);\n ids.push(...collectFolderIds(node.children));\n }\n }\n return ids;\n}\n\nconst EMPTY_DRAG_STATE: DragState = {\n draggedNodeId: null,\n dropTargetId: null,\n dropPosition: null,\n};\n\ninterface FlatRow {\n id: string;\n node: TreeNodeData;\n depth: number;\n}\n\n/** The rows currently visible — every node, descending only into expanded folders. */\nfunction flattenVisible(nodes: TreeNodeData[], expanded: ReadonlySet<string>): FlatRow[] {\n const rows: FlatRow[] = [];\n const walk = (list: TreeNodeData[], depth: number) => {\n for (const node of list) {\n rows.push({ id: node.id, node, depth });\n const isFolder = node.type === \"folder\" || (node.children && node.children.length > 0);\n if (isFolder && node.children && expanded.has(node.id)) walk(node.children, depth + 1);\n }\n };\n walk(nodes, 0);\n return rows;\n}\n\nfunction TreeNavRoot({\n nodes,\n selectedId,\n onSelect,\n onNodeContextMenu,\n draggable = false,\n onNodeMove,\n acceptExternalDrops = false,\n onExternalDrop,\n expandedIds: controlledExpanded,\n defaultExpandedIds,\n onExpandedChange,\n defaultExpandAll = false,\n indentSize = 16,\n showIcons = true,\n dragCursor = \"none\",\n virtualize = false,\n height = 400,\n rowHeight = 26,\n className,\n}: TreeNavProps) {\n const [internalExpanded, setInternalExpanded] = useState<string[]>(() => {\n if (defaultExpandedIds) return defaultExpandedIds;\n if (defaultExpandAll) return collectFolderIds(nodes);\n return [];\n });\n\n const isControlled = controlledExpanded !== undefined;\n const expandedIds = isControlled ? controlledExpanded : internalExpanded;\n // One Set per change, so a row's \"am I expanded?\" is a lookup, not a scan.\n const expanded = useMemo(() => new Set(expandedIds), [expandedIds]);\n\n const [dragState, setDragState] = useState<DragState>(EMPTY_DRAG_STATE);\n\n /*\n * The latest props and state, for handlers that must stay STABLE. A handler\n * whose identity changes on every click would change the context rows read,\n * and re-render every row — the exact cost this component is avoiding.\n */\n const latest = useRef({ expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop });\n latest.current = { expandedIds, isControlled, onExpandedChange, onSelect, onNodeContextMenu, onNodeMove, onExternalDrop };\n\n const setExpanded = useCallback((next: string[]) => {\n if (!latest.current.isControlled) setInternalExpanded(next);\n latest.current.onExpandedChange?.(next);\n }, []);\n\n const toggle = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n setExpanded(current.includes(id) ? current.filter((v) => v !== id) : [...current, id]);\n },\n [setExpanded],\n );\n\n const expandNode = useCallback(\n (id: string) => {\n const current = latest.current.expandedIds;\n if (!current.includes(id)) setExpanded([...current, id]);\n },\n [setExpanded],\n );\n\n const select = useCallback((node: TreeNodeData) => latest.current.onSelect?.(node.id, node), []);\n const contextMenu = useCallback(\n (e: React.MouseEvent, node: TreeNodeData) => latest.current.onNodeContextMenu?.(e, node),\n [],\n );\n const moveNode = useCallback(\n (sourceId: string, targetId: string, position: Parameters<NonNullable<TreeNavProps[\"onNodeMove\"]>>[2]) =>\n latest.current.onNodeMove?.(sourceId, targetId, position),\n [],\n );\n const externalDrop = useCallback(\n (event: React.DragEvent, target: TreeNodeData, position: Parameters<NonNullable<TreeNavProps[\"onExternalDrop\"]>>[2]) =>\n latest.current.onExternalDrop?.(event, target, position),\n [],\n );\n\n // What rows subscribe to. Seeded with this render's values so the first paint\n // is right; kept current after each render that changes them.\n const [store] = useState(() => createTreeStore({ selectedId, expanded, dragState }));\n useLayoutEffect(() => {\n const current = store.get();\n if (current.selectedId !== selectedId || current.expanded !== expanded || current.dragState !== dragState) {\n store.set({ selectedId, expanded, dragState });\n }\n }, [store, selectedId, expanded, dragState]);\n\n const hasContextMenu = onNodeContextMenu !== undefined;\n const internals = useMemo<TreeInternals>(\n () => ({\n store,\n nodes,\n select,\n toggle,\n expandNode,\n setDragState,\n // Present only when the host gave one: a row then claims the right-click.\n contextMenu: hasContextMenu ? contextMenu : undefined,\n moveNode,\n externalDrop,\n indentSize,\n showIcons,\n draggable,\n dragCursor,\n acceptExternalDrops,\n flat: virtualize,\n }),\n [store, nodes, select, toggle, expandNode, hasContextMenu, contextMenu, moveNode, externalDrop,\n indentSize, showIcons, draggable, dragCursor, acceptExternalDrops, virtualize],\n );\n\n // Unchanged public context, still live for `useTreeNav()` callers. Rows no\n // longer read it, so its changing on a click re-renders only those callers.\n const ctx = useMemo(\n () => ({\n selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, setDragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode,\n }),\n [selectedId, onSelect, onNodeContextMenu, expandedIds, toggle, indentSize, showIcons,\n draggable, dragCursor, dragState, onNodeMove, acceptExternalDrops, onExternalDrop, nodes, expandNode],\n );\n\n const rows = useMemo(\n () => (virtualize ? flattenVisible(nodes, expanded) : []),\n [virtualize, nodes, expanded],\n );\n\n const handleDragEnd = useCallback(() => {\n setDragState(EMPTY_DRAG_STATE);\n }, []);\n\n const dropEnabled = draggable || acceptExternalDrops;\n\n return (\n <TreeNavContext.Provider value={ctx}>\n <TreeInternalsContext.Provider value={internals}>\n <nav\n data-react-fancy-tree-nav=\"\"\n data-react-fancy-tree-nav-virtual={virtualize ? \"\" : undefined}\n className={cn(\"flex flex-col gap-0.5 py-1 text-sm\", className)}\n onDragEnd={dropEnabled ? handleDragEnd : undefined}\n >\n {virtualize ? (\n <VirtualList\n items={rows}\n height={height}\n estimateRowHeight={rowHeight}\n renderRow={(row) => <TreeNode node={row.node} depth={row.depth} />}\n />\n ) : (\n nodes.map((node) => <TreeNode key={node.id} node={node} depth={0} />)\n )}\n </nav>\n </TreeInternalsContext.Provider>\n </TreeNavContext.Provider>\n );\n}\n\nTreeNavRoot.displayName = \"TreeNav\";\n\nexport const TreeNav = Object.assign(TreeNavRoot, {\n Node: TreeNode,\n});\n"]}
|
|
@@ -25,6 +25,7 @@ function VirtualList({
|
|
|
25
25
|
const [measured, setMeasured] = react.useState(0);
|
|
26
26
|
const [scrollTop, setScrollTop] = react.useState(0);
|
|
27
27
|
const [clientHeight, setClientHeight] = react.useState(0);
|
|
28
|
+
const knownTop = react.useRef(0);
|
|
28
29
|
const attachViewport = react.useCallback(
|
|
29
30
|
(el) => {
|
|
30
31
|
viewportRef.current = el;
|
|
@@ -149,6 +150,7 @@ function VirtualList({
|
|
|
149
150
|
if (anchored.current !== target) {
|
|
150
151
|
anchored.current = target;
|
|
151
152
|
vp.scrollTop = target;
|
|
153
|
+
knownTop.current = target;
|
|
152
154
|
setScrollTop(target);
|
|
153
155
|
return;
|
|
154
156
|
}
|
|
@@ -175,10 +177,12 @@ function VirtualList({
|
|
|
175
177
|
if (scrollToId !== null && resolved.current !== scrollToId) return;
|
|
176
178
|
const vp = viewportRef.current;
|
|
177
179
|
if (!vp) return;
|
|
180
|
+
const current = observer.current ? knownTop.current : vp.scrollTop;
|
|
178
181
|
const bottom = Math.max(0, total - viewport);
|
|
179
|
-
if (Math.abs(
|
|
182
|
+
if (Math.abs(current - bottom) > 0.5) {
|
|
180
183
|
programmatic.current = true;
|
|
181
184
|
vp.scrollTop = bottom;
|
|
185
|
+
knownTop.current = bottom;
|
|
182
186
|
setScrollTop(bottom);
|
|
183
187
|
}
|
|
184
188
|
});
|
|
@@ -186,6 +190,7 @@ function VirtualList({
|
|
|
186
190
|
const vp = viewportRef.current;
|
|
187
191
|
if (!vp) return;
|
|
188
192
|
const next = vp.scrollTop;
|
|
193
|
+
knownTop.current = next;
|
|
189
194
|
const previous = scrollTop;
|
|
190
195
|
setScrollTop(next);
|
|
191
196
|
const bottom = Math.max(0, total - viewport);
|
|
@@ -279,5 +284,5 @@ var TOUCH_SLOP = 4;
|
|
|
279
284
|
var UPWARD_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "PageUp", "Home"]);
|
|
280
285
|
|
|
281
286
|
exports.VirtualList = VirtualList;
|
|
282
|
-
//# sourceMappingURL=chunk-
|
|
283
|
-
//# sourceMappingURL=chunk-
|
|
287
|
+
//# sourceMappingURL=chunk-MF2DCMOA.cjs.map
|
|
288
|
+
//# sourceMappingURL=chunk-MF2DCMOA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/VirtualList/VirtualList.tsx"],"names":["useRef","useState","useCallback","useMemo","useLayoutEffect","useEffect","jsx","cn"],"mappings":";;;;;;AA4DO,SAAS,WAAA,CAAsC;AAAA,EACpD,KAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA,GAAS,MAAA;AAAA,EACT,iBAAA,GAAoB,EAAA;AAAA,EACpB,QAAA,GAAW,CAAA;AAAA,EACX,UAAA,GAAa,KAAA;AAAA,EACb,cAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAA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EAAA;AAAA,UACpC,OAAO,EAAE,MAAA,EAAQ,GAAG,KAAK,CAAA,EAAA,CAAA,EAAM,UAAU,UAAA,EAAW;AAAA,UAEpD,QAAA,kBAAAA,cAAA;AAAA,YAAC,KAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,SAAA;AAAA,cACL,sCAAA,EAAqC,EAAA;AAAA,cACrC,qCAAA,EAAqC,KAAA;AAAA,cACrC,KAAA,EAAO,EAAE,SAAA,EAAW,CAAA,WAAA,EAAc,QAAQ,KAAK,CAAA,IAAK,CAAC,CAAA,GAAA,CAAA,EAAM;AAAA,cAE1D,kBAAQ,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,oCACjB,KAAA,EAAA,EAAkB,iCAAA,EAAiC,IAAA,CAAK,EAAA,EACtD,oBAAU,IAAA,EAAM,KAAA,GAAQ,CAAC,CAAA,EAAA,EADlB,IAAA,CAAK,EAEf,CACD;AAAA;AAAA;AACH;AAAA;AACF;AAAA,GACF;AAEJ;AAEA,IAAM,WAAA,GAAc,iCAAA;AAQpB,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,MAAM,MAAM,KAAA,CAAM,aAAA;AAClB,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,GAAI,GAAA,CAAI,CAAC,CAAA,GAAK,GAAA;AAC7C,EAAA,IAAI,SAAS,OAAO,KAAA,CAAM,SAAA,KAAc,QAAA,SAAiB,KAAA,CAAM,SAAA;AAE/D,EAAA,OAAO,KAAA,CAAM,aAAa,MAAA,IAAU,CAAA;AACtC;AAEA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,UAAA,GAAa,CAAA;AACnB,IAAM,8BAAc,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA","file":"chunk-MF2DCMOA.cjs","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, TouchEvent, WheelEvent } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { VirtualListProps, VirtualListRow } from \"./VirtualList.types\";\n\n/**\n * A windowed list for ledgers that run to tens of thousands of rows — only the\n * visible slice is in the DOM, with **measured** variable row heights, deep\n * links by row id, and sticky-bottom tail-following.\n *\n * Built for an agent event stream, where every one of those three is load\n * bearing at once: message rows wrap and event rows do not, a link carries\n * `?at=<rowId>` to the exact row under discussion, and new rows arrive while\n * the human is reading older ones.\n *\n * ## Heights are measured, never predicted\n *\n * `estimateRowHeight` only seeds rows that have never been on screen. The\n * moment a row renders, its real height is measured and replaces the estimate,\n * and every offset after it moves. The alternative — a `rowHeight(item)`\n * callback — is a prediction about text wrapping, font loading and container\n * width, and when it is wrong the error accumulates down the list: rows draw in\n * the wrong place and `scrollToId` lands on a neighbour. Measuring is slower to\n * settle and correct when it does.\n *\n * ## Tail-follow breaks on INTENT, not on position\n *\n * Any upward gesture — wheel, drag, PageUp, Home — stops following\n * immediately, even when the list is still pinned to the bottom and\n * `scrollTop` has not changed yet. Position cannot tell \"the human scrolled\n * up\" from \"content grew downward\", so a position-only implementation keeps\n * following through a wheel-up and yanks the reader back on the next append.\n *\n * ## It is controlled\n *\n * `followTail` is the consumer's state. This component only ever *asks* via\n * `onFollowChange`, so the follow state is readable and writable by an agent\n * over a bridge, as the Human+ component contract requires. The `↓ n new` pill\n * is the consumer's to render, from `onUnseenChange`.\n *\n * @example\n * ```tsx\n * const [following, setFollowing] = useState(true);\n * const [unseen, setUnseen] = useState(0);\n *\n * <VirtualList\n * items={events}\n * renderRow={(e) => <StreamRow event={e} />}\n * height=\"100%\"\n * estimateRowHeight={28}\n * followTail={following}\n * onFollowChange={setFollowing}\n * onUnseenChange={setUnseen}\n * scrollToId={params.at}\n * />\n * {!following && unseen > 0 && (\n * <Button onClick={() => setFollowing(true)}>↓ {unseen} new</Button>\n * )}\n * ```\n */\nexport function VirtualList<T extends VirtualListRow>({\n items,\n renderRow,\n height = \"100%\",\n estimateRowHeight = 32,\n overscan = 6,\n followTail = false,\n onFollowChange,\n onUnseenChange,\n scrollToId = null,\n onScrollToIdResolved,\n className,\n ref,\n ...props\n}: VirtualListProps<T>) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n\n /** Measured heights by row id, so a height follows its row across a reindex. */\n const heights = useRef(new Map<string, number>());\n /** Bumped when a measurement actually changed, to recompute offsets. */\n const [measured, setMeasured] = useState(0);\n\n const [scrollTop, setScrollTop] = useState(0);\n const [clientHeight, setClientHeight] = useState(0);\n\n /**\n * Where the viewport is scrolled, as far as this list knows: the value from\n * the last `scroll` event, or the last position it set itself. Every change\n * to scrollTop raises a scroll event, so this is never wrong for longer than\n * one frame — and reading it, unlike reading `vp.scrollTop` inside a commit,\n * never forces a synchronous layout.\n */\n const knownTop = useRef(0);\n\n const attachViewport = useCallback(\n (el: HTMLDivElement | null) => {\n viewportRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) (ref as { current: HTMLDivElement | null }).current = el;\n },\n [ref],\n );\n\n // A number `height` IS the viewport height, and is usable before the element\n // has been measured. Without one, render a conservative first window so there\n // is something on screen for the measurement pass to work from.\n const viewport =\n clientHeight > 0 ? clientHeight : typeof height === \"number\" ? height : estimateRowHeight * 20;\n\n /**\n * Prefix sums of row heights: `offsets[i]` is where row `i` starts, and the\n * last entry is the total. Rebuilt whenever rows or measurements change —\n * O(n) once per change, against O(log n) per scroll from the binary search,\n * rather than O(n) on every scroll frame.\n */\n const { offsets, total } = useMemo(() => {\n const offs = new Float64Array(items.length + 1);\n for (let i = 0; i < items.length; i += 1) {\n offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);\n }\n\n return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };\n }, [items, measured, estimateRowHeight]);\n\n /** First row whose span contains `y`. */\n const indexAt = useCallback(\n (y: number): number => {\n let lo = 0;\n let hi = items.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (offsets[mid] <= y) lo = mid;\n else hi = mid - 1;\n }\n\n return Math.max(0, lo);\n },\n [items.length, offsets],\n );\n\n const start = Math.max(0, indexAt(scrollTop) - overscan);\n const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);\n const visible = useMemo(() => items.slice(start, end), [items, start, end]);\n\n // ---------------------------------------------------------------- measuring\n\n //\n // Every getBoundingClientRect() / clientHeight read after a commit forces a\n // synchronous layout, and this list re-renders on every appended row. So a\n // row is measured ONCE, when its element first appears, and from then on the\n // ResizeObserver reports when it changes, with the size in the entry: no read\n // that forces layout. An append costs one measurement; a render where nothing\n // changed costs none. (Measured in genie#1340: re-measuring every visible row\n // on every render was 472 forced row measurements/s with 11 agents streaming.)\n\n const observer = useRef<ResizeObserver | null>(null);\n /** Row elements currently observed, so each is observed once and released. */\n const observed = useRef(new Set<Element>());\n\n // A layout effect, declared before the measuring one, so the observer exists\n // by the time the first window is measured and the first rows are observed.\n useLayoutEffect(() => {\n // Absent in jsdom and in older runtimes. Without it the list measures every\n // visible row on every render instead, which is the only way it can notice\n // a row reflowing in place.\n if (typeof ResizeObserver === \"undefined\") return;\n\n const ro = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const el = entry.target as HTMLElement;\n\n if (el === viewportRef.current) {\n // The viewport's own resize changes how many rows fit. Reading\n // clientHeight here is free: the browser has just done layout.\n const ch = el.clientHeight;\n if (ch > 0) setClientHeight(ch);\n continue;\n }\n\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n const h = entryHeight(entry);\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n observer.current = ro;\n\n const vp = viewportRef.current;\n if (vp) ro.observe(vp);\n\n const tracked = observed.current;\n\n return () => {\n ro.disconnect();\n observer.current = null;\n tracked.clear();\n };\n }, []);\n\n // No dependency array on purpose: every render looks at what is on screen.\n // That LOOK is cheap — walking the window's children reads no layout. Only a\n // row seen for the first time is measured (or, with no ResizeObserver, every\n // row, as nothing else would notice a reflow). A render that learns nothing\n // new sets no state, which is what stops it looping.\n useLayoutEffect(() => {\n const win = windowRef.current;\n if (!win) return;\n\n const ro = observer.current;\n const tracked = observed.current;\n const present = ro ? new Set<Element>() : null;\n\n let changed = false;\n let measuredAny = false;\n for (const el of Array.from(win.children) as HTMLElement[]) {\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n if (ro && present) {\n present.add(el);\n // Already observed: the observer reports its resizes.\n if (tracked.has(el)) continue;\n\n ro.observe(el);\n tracked.add(el);\n // A row scrolling back into view: its height is known, and the\n // observer's first report for the new element corrects it if it moved.\n if (heights.current.has(id)) continue;\n }\n\n const h = el.getBoundingClientRect().height;\n measuredAny = true;\n // A zero height is \"not laid out yet\", not a 0px row. Recording it would\n // collapse the list and make every offset after it wrong.\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (ro && present) {\n for (const el of tracked) {\n if (!present.has(el)) {\n ro.unobserve(el);\n tracked.delete(el);\n }\n }\n }\n\n // With an observer, the viewport's resizes arrive through it; read it here\n // only when this pass has already paid for a layout, so it is free.\n const vp = viewportRef.current;\n if (vp && (!ro || measuredAny) && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) {\n setClientHeight(vp.clientHeight);\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n\n // ------------------------------------------------------------- deep linking\n\n /** The target this component last moved to, to detect that it has settled. */\n const anchored = useRef<number | null>(null);\n const resolved = useRef<string | null>(null);\n\n useEffect(() => {\n // A new id is a new request, even if the old one had resolved.\n anchored.current = null;\n resolved.current = null;\n }, [scrollToId]);\n\n useLayoutEffect(() => {\n if (scrollToId === null || resolved.current === scrollToId) return;\n\n const index = items.findIndex((item) => item.id === scrollToId);\n if (index < 0) {\n // A link to a row that is no longer in the list. Leaving the viewport\n // where it is and SAYING SO is the only honest outcome — scrolling to the\n // top would be indistinguishable from a successful landing.\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, false);\n\n return;\n }\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // Clamped the way the browser clamps: a row inside the final viewport-height\n // of the list cannot be brought to the top, and pretending otherwise would\n // leave this waiting for a position that can never be reached.\n const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));\n\n if (anchored.current !== target) {\n anchored.current = target;\n vp.scrollTop = target;\n knownTop.current = target;\n setScrollTop(target);\n\n return;\n }\n\n // The target stopped moving as rows above it were measured, and we are on\n // it. Only now is the deep link actually honoured.\n if (Math.abs(vp.scrollTop - target) <= 1) {\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, true);\n }\n });\n\n // ------------------------------------------------------------- tail-follow\n\n const reportedFollow = useRef(followTail);\n const programmatic = useRef(false);\n\n useEffect(() => {\n // The prop is the truth, so adopt it rather than remembering what we asked\n // for. Otherwise a consumer that declines an `onFollowChange(false)` would\n // never be asked again.\n reportedFollow.current = followTail;\n }, [followTail]);\n\n const askFollow = useCallback(\n (next: boolean) => {\n if (reportedFollow.current === next) return;\n reportedFollow.current = next;\n onFollowChange?.(next);\n },\n [onFollowChange],\n );\n\n useLayoutEffect(() => {\n if (!followTail) return;\n // A pending deep link wins while it resolves; otherwise the two would fight\n // over the same scrollTop and the link would lose.\n if (scrollToId !== null && resolved.current !== scrollToId) return;\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // This is the first layout read after most commits, so reading\n // `vp.scrollTop` here paid the forced synchronous layout on every append\n // (genie#1340 follow-up: 1.5 to 1.8 s per 120 s with 11 agents streaming).\n // Compare against the position the list already tracks instead, which only\n // differs from `bottom` when the bottom moved (rows, measurements or the\n // viewport changed) or someone scrolled — so a commit that moved nothing\n // neither reads nor writes. Without a ResizeObserver the measuring pass has\n // already paid for a layout this commit, so reading is free and keeps the\n // fallback exactly as it was.\n const current = observer.current ? knownTop.current : vp.scrollTop;\n const bottom = Math.max(0, total - viewport);\n if (Math.abs(current - bottom) > 0.5) {\n programmatic.current = true;\n vp.scrollTop = bottom;\n knownTop.current = bottom;\n setScrollTop(bottom);\n }\n });\n\n const onScroll = useCallback(() => {\n const vp = viewportRef.current;\n if (!vp) return;\n\n const next = vp.scrollTop;\n knownTop.current = next;\n const previous = scrollTop;\n setScrollTop(next);\n\n const bottom = Math.max(0, total - viewport);\n const wasProgrammatic = programmatic.current;\n programmatic.current = false;\n\n if (next <= bottom - BOTTOM_SLACK) {\n // Moved up, and not because we moved it.\n if (!wasProgrammatic && next < previous) askFollow(false);\n } else {\n askFollow(true);\n }\n }, [scrollTop, total, viewport, askFollow]);\n\n /** Any upward gesture is a statement of intent, whatever scrollTop says. */\n const onWheel = useCallback(\n (e: WheelEvent<HTMLDivElement>) => {\n if (e.deltaY < 0) askFollow(false);\n },\n [askFollow],\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (UPWARD_KEYS.has(e.key)) askFollow(false);\n },\n [askFollow],\n );\n\n const touchStart = useRef<number | null>(null);\n\n const onTouchStart = useCallback((e: TouchEvent<HTMLDivElement>) => {\n touchStart.current = e.touches[0]?.clientY ?? null;\n }, []);\n\n const onTouchMove = useCallback(\n (e: TouchEvent<HTMLDivElement>) => {\n const from = touchStart.current;\n const y = e.touches[0]?.clientY;\n // Finger travelling DOWN drags the content down, which scrolls up.\n if (from !== null && y !== undefined && y - from > TOUCH_SLOP) askFollow(false);\n },\n [askFollow],\n );\n\n // ------------------------------------------------------------ unseen count\n\n const seen = useRef(items.length);\n const reportedUnseen = useRef<number | null>(null);\n\n useEffect(() => {\n const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);\n if (followTail) seen.current = items.length;\n\n if (reportedUnseen.current === unseen) return;\n reportedUnseen.current = unseen;\n onUnseenChange?.(unseen);\n }, [items.length, followTail, onUnseenChange]);\n\n // ------------------------------------------------------------------ render\n\n return (\n <div\n ref={attachViewport}\n data-react-fancy-virtual-list=\"\"\n data-react-fancy-virtual-list-following={followTail ? \"true\" : \"false\"}\n data-react-fancy-virtual-list-rows={items.length}\n role=\"log\"\n tabIndex={0}\n className={cn(\"relative overflow-y-auto overflow-x-hidden outline-none\", className)}\n style={{ height }}\n onScroll={onScroll}\n onWheel={onWheel}\n onKeyDown={onKeyDown}\n onTouchStart={onTouchStart}\n onTouchMove={onTouchMove}\n {...props}\n >\n {/* Holds the full scroll range so the scrollbar is honest from the first\n paint, instead of growing as rows are discovered. */}\n <div\n data-react-fancy-virtual-list-sizer=\"\"\n style={{ height: `${total}px`, position: \"relative\" }}\n >\n <div\n ref={windowRef}\n data-react-fancy-virtual-list-window=\"\"\n data-react-fancy-virtual-list-start={start}\n style={{ transform: `translateY(${offsets[start] ?? 0}px)` }}\n >\n {visible.map((item, i) => (\n <div key={item.id} data-react-fancy-virtual-row-id={item.id}>\n {renderRow(item, start + i)}\n </div>\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nconst ROW_ID_ATTR = \"data-react-fancy-virtual-row-id\";\n\n/**\n * A row's border-box height from a ResizeObserver entry. `borderBoxSize` is\n * what getBoundingClientRect() would report; older engines lack it (and early\n * Firefox gave a single object, not an array), so fall back to `contentRect`,\n * which equals it for the row wrapper, as that carries no padding or border.\n */\nfunction entryHeight(entry: ResizeObserverEntry): number {\n const box = entry.borderBoxSize as ReadonlyArray<ResizeObserverSize> | ResizeObserverSize | undefined;\n const first = Array.isArray(box) ? box[0] : (box as ResizeObserverSize | undefined);\n if (first && typeof first.blockSize === \"number\") return first.blockSize;\n\n return entry.contentRect?.height ?? 0;\n}\n/** Within this many px of the bottom counts as \"at the bottom\". */\nconst BOTTOM_SLACK = 4;\n/** Ignore a touch jitter smaller than this before calling it an upward drag. */\nconst TOUCH_SLOP = 4;\nconst UPWARD_KEYS = new Set([\"ArrowUp\", \"PageUp\", \"Home\"]);\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -16,8 +16,8 @@ var chunk4DL2U23D_cjs = require('./chunk-4DL2U23D.cjs');
|
|
|
16
16
|
var chunkYH75G6SP_cjs = require('./chunk-YH75G6SP.cjs');
|
|
17
17
|
var chunkUXYFM2XT_cjs = require('./chunk-UXYFM2XT.cjs');
|
|
18
18
|
var chunkH2YRZYKK_cjs = require('./chunk-H2YRZYKK.cjs');
|
|
19
|
-
var
|
|
20
|
-
var
|
|
19
|
+
var chunkL5AI4MGV_cjs = require('./chunk-L5AI4MGV.cjs');
|
|
20
|
+
var chunkMF2DCMOA_cjs = require('./chunk-MF2DCMOA.cjs');
|
|
21
21
|
var chunkEZA6GWZL_cjs = require('./chunk-EZA6GWZL.cjs');
|
|
22
22
|
var chunkFNIHCNVD_cjs = require('./chunk-FNIHCNVD.cjs');
|
|
23
23
|
var chunk7DDUMW4R_cjs = require('./chunk-7DDUMW4R.cjs');
|
|
@@ -272,15 +272,15 @@ Object.defineProperty(exports, "useToast", {
|
|
|
272
272
|
});
|
|
273
273
|
Object.defineProperty(exports, "TreeNav", {
|
|
274
274
|
enumerable: true,
|
|
275
|
-
get: function () { return
|
|
275
|
+
get: function () { return chunkL5AI4MGV_cjs.TreeNav; }
|
|
276
276
|
});
|
|
277
277
|
Object.defineProperty(exports, "useTreeNav", {
|
|
278
278
|
enumerable: true,
|
|
279
|
-
get: function () { return
|
|
279
|
+
get: function () { return chunkL5AI4MGV_cjs.useTreeNav; }
|
|
280
280
|
});
|
|
281
281
|
Object.defineProperty(exports, "VirtualList", {
|
|
282
282
|
enumerable: true,
|
|
283
|
-
get: function () { return
|
|
283
|
+
get: function () { return chunkMF2DCMOA_cjs.VirtualList; }
|
|
284
284
|
});
|
|
285
285
|
Object.defineProperty(exports, "Sidebar", {
|
|
286
286
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@ export { TimeGrid } from './chunk-MLZGGAXQ.js';
|
|
|
14
14
|
export { TimePicker } from './chunk-AZQXPI5S.js';
|
|
15
15
|
export { Timeline } from './chunk-QGY5FPVM.js';
|
|
16
16
|
export { Toast, useToast } from './chunk-BQFPC5FL.js';
|
|
17
|
-
export { TreeNav, useTreeNav } from './chunk-
|
|
18
|
-
export { VirtualList } from './chunk-
|
|
17
|
+
export { TreeNav, useTreeNav } from './chunk-LYG2NLSV.js';
|
|
18
|
+
export { VirtualList } from './chunk-ARNFT23K.js';
|
|
19
19
|
export { Sidebar, useSidebar } from './chunk-YJHP5FVA.js';
|
|
20
20
|
export { Skeleton } from './chunk-X7VIIM2P.js';
|
|
21
21
|
export { Stat, StatBand } from './chunk-KC3PYCBO.js';
|
package/dist/tree-nav.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkL5AI4MGV_cjs = require('./chunk-L5AI4MGV.cjs');
|
|
4
|
+
require('./chunk-MF2DCMOA.cjs');
|
|
5
5
|
require('./chunk-ZU5Q77OT.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "TreeNav", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkL5AI4MGV_cjs.TreeNav; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "useTreeNav", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkL5AI4MGV_cjs.useTreeNav; }
|
|
16
16
|
});
|
|
17
17
|
//# sourceMappingURL=tree-nav.cjs.map
|
|
18
18
|
//# sourceMappingURL=tree-nav.cjs.map
|
package/dist/tree-nav.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { TreeNav, useTreeNav } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { TreeNav, useTreeNav } from './chunk-LYG2NLSV.js';
|
|
2
|
+
import './chunk-ARNFT23K.js';
|
|
3
3
|
import './chunk-MMW2JGKZ.js';
|
|
4
4
|
//# sourceMappingURL=tree-nav.js.map
|
|
5
5
|
//# sourceMappingURL=tree-nav.js.map
|
package/dist/virtual-list.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMF2DCMOA_cjs = require('./chunk-MF2DCMOA.cjs');
|
|
4
4
|
require('./chunk-ZU5Q77OT.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "VirtualList", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkMF2DCMOA_cjs.VirtualList; }
|
|
11
11
|
});
|
|
12
12
|
//# sourceMappingURL=virtual-list.cjs.map
|
|
13
13
|
//# sourceMappingURL=virtual-list.cjs.map
|
package/dist/virtual-list.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/VirtualList/VirtualList.tsx"],"names":["useRef","useState","useCallback","useMemo","useLayoutEffect","useEffect","jsx","cn"],"mappings":";;;;;;AA4DO,SAAS,WAAA,CAAsC;AAAA,EACpD,KAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA,GAAS,MAAA;AAAA,EACT,iBAAA,GAAoB,EAAA;AAAA,EACpB,QAAA,GAAW,CAAA;AAAA,EACX,UAAA,GAAa,KAAA;AAAA,EACb,cAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,MAAM,WAAA,GAAcA,aAA8B,IAAI,CAAA;AACtD,EAAA,MAAM,SAAA,GAAYA,aAA8B,IAAI,CAAA;AAGpD,EAAA,MAAM,OAAA,GAAUA,YAAA,iBAAO,IAAI,GAAA,EAAqB,CAAA;AAEhD,EAAA,MAAM,CAAC,QAAA,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IAAA,CAAK,EAEf,CACD;AAAA;AAAA;AACH;AAAA;AACF;AAAA,GACF;AAEJ;AAEA,IAAM,WAAA,GAAc,iCAAA;AAQpB,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,MAAM,MAAM,KAAA,CAAM,aAAA;AAClB,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,GAAI,GAAA,CAAI,CAAC,CAAA,GAAK,GAAA;AAC7C,EAAA,IAAI,SAAS,OAAO,KAAA,CAAM,SAAA,KAAc,QAAA,SAAiB,KAAA,CAAM,SAAA;AAE/D,EAAA,OAAO,KAAA,CAAM,aAAa,MAAA,IAAU,CAAA;AACtC;AAEA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,UAAA,GAAa,CAAA;AACnB,IAAM,8BAAc,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA","file":"chunk-4TK3IYR6.cjs","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, TouchEvent, WheelEvent } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { VirtualListProps, VirtualListRow } from \"./VirtualList.types\";\n\n/**\n * A windowed list for ledgers that run to tens of thousands of rows — only the\n * visible slice is in the DOM, with **measured** variable row heights, deep\n * links by row id, and sticky-bottom tail-following.\n *\n * Built for an agent event stream, where every one of those three is load\n * bearing at once: message rows wrap and event rows do not, a link carries\n * `?at=<rowId>` to the exact row under discussion, and new rows arrive while\n * the human is reading older ones.\n *\n * ## Heights are measured, never predicted\n *\n * `estimateRowHeight` only seeds rows that have never been on screen. The\n * moment a row renders, its real height is measured and replaces the estimate,\n * and every offset after it moves. The alternative — a `rowHeight(item)`\n * callback — is a prediction about text wrapping, font loading and container\n * width, and when it is wrong the error accumulates down the list: rows draw in\n * the wrong place and `scrollToId` lands on a neighbour. Measuring is slower to\n * settle and correct when it does.\n *\n * ## Tail-follow breaks on INTENT, not on position\n *\n * Any upward gesture — wheel, drag, PageUp, Home — stops following\n * immediately, even when the list is still pinned to the bottom and\n * `scrollTop` has not changed yet. Position cannot tell \"the human scrolled\n * up\" from \"content grew downward\", so a position-only implementation keeps\n * following through a wheel-up and yanks the reader back on the next append.\n *\n * ## It is controlled\n *\n * `followTail` is the consumer's state. This component only ever *asks* via\n * `onFollowChange`, so the follow state is readable and writable by an agent\n * over a bridge, as the Human+ component contract requires. The `↓ n new` pill\n * is the consumer's to render, from `onUnseenChange`.\n *\n * @example\n * ```tsx\n * const [following, setFollowing] = useState(true);\n * const [unseen, setUnseen] = useState(0);\n *\n * <VirtualList\n * items={events}\n * renderRow={(e) => <StreamRow event={e} />}\n * height=\"100%\"\n * estimateRowHeight={28}\n * followTail={following}\n * onFollowChange={setFollowing}\n * onUnseenChange={setUnseen}\n * scrollToId={params.at}\n * />\n * {!following && unseen > 0 && (\n * <Button onClick={() => setFollowing(true)}>↓ {unseen} new</Button>\n * )}\n * ```\n */\nexport function VirtualList<T extends VirtualListRow>({\n items,\n renderRow,\n height = \"100%\",\n estimateRowHeight = 32,\n overscan = 6,\n followTail = false,\n onFollowChange,\n onUnseenChange,\n scrollToId = null,\n onScrollToIdResolved,\n className,\n ref,\n ...props\n}: VirtualListProps<T>) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n\n /** Measured heights by row id, so a height follows its row across a reindex. */\n const heights = useRef(new Map<string, number>());\n /** Bumped when a measurement actually changed, to recompute offsets. */\n const [measured, setMeasured] = useState(0);\n\n const [scrollTop, setScrollTop] = useState(0);\n const [clientHeight, setClientHeight] = useState(0);\n\n const attachViewport = useCallback(\n (el: HTMLDivElement | null) => {\n viewportRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) (ref as { current: HTMLDivElement | null }).current = el;\n },\n [ref],\n );\n\n // A number `height` IS the viewport height, and is usable before the element\n // has been measured. Without one, render a conservative first window so there\n // is something on screen for the measurement pass to work from.\n const viewport =\n clientHeight > 0 ? clientHeight : typeof height === \"number\" ? height : estimateRowHeight * 20;\n\n /**\n * Prefix sums of row heights: `offsets[i]` is where row `i` starts, and the\n * last entry is the total. Rebuilt whenever rows or measurements change —\n * O(n) once per change, against O(log n) per scroll from the binary search,\n * rather than O(n) on every scroll frame.\n */\n const { offsets, total } = useMemo(() => {\n const offs = new Float64Array(items.length + 1);\n for (let i = 0; i < items.length; i += 1) {\n offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);\n }\n\n return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };\n }, [items, measured, estimateRowHeight]);\n\n /** First row whose span contains `y`. */\n const indexAt = useCallback(\n (y: number): number => {\n let lo = 0;\n let hi = items.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (offsets[mid] <= y) lo = mid;\n else hi = mid - 1;\n }\n\n return Math.max(0, lo);\n },\n [items.length, offsets],\n );\n\n const start = Math.max(0, indexAt(scrollTop) - overscan);\n const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);\n const visible = useMemo(() => items.slice(start, end), [items, start, end]);\n\n // ---------------------------------------------------------------- measuring\n\n //\n // Every getBoundingClientRect() / clientHeight read after a commit forces a\n // synchronous layout, and this list re-renders on every appended row. So a\n // row is measured ONCE, when its element first appears, and from then on the\n // ResizeObserver reports when it changes, with the size in the entry: no read\n // that forces layout. An append costs one measurement; a render where nothing\n // changed costs none. (Measured in genie#1340: re-measuring every visible row\n // on every render was 472 forced row measurements/s with 11 agents streaming.)\n\n const observer = useRef<ResizeObserver | null>(null);\n /** Row elements currently observed, so each is observed once and released. */\n const observed = useRef(new Set<Element>());\n\n // A layout effect, declared before the measuring one, so the observer exists\n // by the time the first window is measured and the first rows are observed.\n useLayoutEffect(() => {\n // Absent in jsdom and in older runtimes. Without it the list measures every\n // visible row on every render instead, which is the only way it can notice\n // a row reflowing in place.\n if (typeof ResizeObserver === \"undefined\") return;\n\n const ro = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const el = entry.target as HTMLElement;\n\n if (el === viewportRef.current) {\n // The viewport's own resize changes how many rows fit. Reading\n // clientHeight here is free: the browser has just done layout.\n const ch = el.clientHeight;\n if (ch > 0) setClientHeight(ch);\n continue;\n }\n\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n const h = entryHeight(entry);\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n observer.current = ro;\n\n const vp = viewportRef.current;\n if (vp) ro.observe(vp);\n\n const tracked = observed.current;\n\n return () => {\n ro.disconnect();\n observer.current = null;\n tracked.clear();\n };\n }, []);\n\n // No dependency array on purpose: every render looks at what is on screen.\n // That LOOK is cheap — walking the window's children reads no layout. Only a\n // row seen for the first time is measured (or, with no ResizeObserver, every\n // row, as nothing else would notice a reflow). A render that learns nothing\n // new sets no state, which is what stops it looping.\n useLayoutEffect(() => {\n const win = windowRef.current;\n if (!win) return;\n\n const ro = observer.current;\n const tracked = observed.current;\n const present = ro ? new Set<Element>() : null;\n\n let changed = false;\n let measuredAny = false;\n for (const el of Array.from(win.children) as HTMLElement[]) {\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n if (ro && present) {\n present.add(el);\n // Already observed: the observer reports its resizes.\n if (tracked.has(el)) continue;\n\n ro.observe(el);\n tracked.add(el);\n // A row scrolling back into view: its height is known, and the\n // observer's first report for the new element corrects it if it moved.\n if (heights.current.has(id)) continue;\n }\n\n const h = el.getBoundingClientRect().height;\n measuredAny = true;\n // A zero height is \"not laid out yet\", not a 0px row. Recording it would\n // collapse the list and make every offset after it wrong.\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (ro && present) {\n for (const el of tracked) {\n if (!present.has(el)) {\n ro.unobserve(el);\n tracked.delete(el);\n }\n }\n }\n\n // With an observer, the viewport's resizes arrive through it; read it here\n // only when this pass has already paid for a layout, so it is free.\n const vp = viewportRef.current;\n if (vp && (!ro || measuredAny) && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) {\n setClientHeight(vp.clientHeight);\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n\n // ------------------------------------------------------------- deep linking\n\n /** The target this component last moved to, to detect that it has settled. */\n const anchored = useRef<number | null>(null);\n const resolved = useRef<string | null>(null);\n\n useEffect(() => {\n // A new id is a new request, even if the old one had resolved.\n anchored.current = null;\n resolved.current = null;\n }, [scrollToId]);\n\n useLayoutEffect(() => {\n if (scrollToId === null || resolved.current === scrollToId) return;\n\n const index = items.findIndex((item) => item.id === scrollToId);\n if (index < 0) {\n // A link to a row that is no longer in the list. Leaving the viewport\n // where it is and SAYING SO is the only honest outcome — scrolling to the\n // top would be indistinguishable from a successful landing.\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, false);\n\n return;\n }\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // Clamped the way the browser clamps: a row inside the final viewport-height\n // of the list cannot be brought to the top, and pretending otherwise would\n // leave this waiting for a position that can never be reached.\n const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));\n\n if (anchored.current !== target) {\n anchored.current = target;\n vp.scrollTop = target;\n setScrollTop(target);\n\n return;\n }\n\n // The target stopped moving as rows above it were measured, and we are on\n // it. Only now is the deep link actually honoured.\n if (Math.abs(vp.scrollTop - target) <= 1) {\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, true);\n }\n });\n\n // ------------------------------------------------------------- tail-follow\n\n const reportedFollow = useRef(followTail);\n const programmatic = useRef(false);\n\n useEffect(() => {\n // The prop is the truth, so adopt it rather than remembering what we asked\n // for. Otherwise a consumer that declines an `onFollowChange(false)` would\n // never be asked again.\n reportedFollow.current = followTail;\n }, [followTail]);\n\n const askFollow = useCallback(\n (next: boolean) => {\n if (reportedFollow.current === next) return;\n reportedFollow.current = next;\n onFollowChange?.(next);\n },\n [onFollowChange],\n );\n\n useLayoutEffect(() => {\n if (!followTail) return;\n // A pending deep link wins while it resolves; otherwise the two would fight\n // over the same scrollTop and the link would lose.\n if (scrollToId !== null && resolved.current !== scrollToId) return;\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n const bottom = Math.max(0, total - viewport);\n if (Math.abs(vp.scrollTop - bottom) > 0.5) {\n programmatic.current = true;\n vp.scrollTop = bottom;\n setScrollTop(bottom);\n }\n });\n\n const onScroll = useCallback(() => {\n const vp = viewportRef.current;\n if (!vp) return;\n\n const next = vp.scrollTop;\n const previous = scrollTop;\n setScrollTop(next);\n\n const bottom = Math.max(0, total - viewport);\n const wasProgrammatic = programmatic.current;\n programmatic.current = false;\n\n if (next <= bottom - BOTTOM_SLACK) {\n // Moved up, and not because we moved it.\n if (!wasProgrammatic && next < previous) askFollow(false);\n } else {\n askFollow(true);\n }\n }, [scrollTop, total, viewport, askFollow]);\n\n /** Any upward gesture is a statement of intent, whatever scrollTop says. */\n const onWheel = useCallback(\n (e: WheelEvent<HTMLDivElement>) => {\n if (e.deltaY < 0) askFollow(false);\n },\n [askFollow],\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (UPWARD_KEYS.has(e.key)) askFollow(false);\n },\n [askFollow],\n );\n\n const touchStart = useRef<number | null>(null);\n\n const onTouchStart = useCallback((e: TouchEvent<HTMLDivElement>) => {\n touchStart.current = e.touches[0]?.clientY ?? null;\n }, []);\n\n const onTouchMove = useCallback(\n (e: TouchEvent<HTMLDivElement>) => {\n const from = touchStart.current;\n const y = e.touches[0]?.clientY;\n // Finger travelling DOWN drags the content down, which scrolls up.\n if (from !== null && y !== undefined && y - from > TOUCH_SLOP) askFollow(false);\n },\n [askFollow],\n );\n\n // ------------------------------------------------------------ unseen count\n\n const seen = useRef(items.length);\n const reportedUnseen = useRef<number | null>(null);\n\n useEffect(() => {\n const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);\n if (followTail) seen.current = items.length;\n\n if (reportedUnseen.current === unseen) return;\n reportedUnseen.current = unseen;\n onUnseenChange?.(unseen);\n }, [items.length, followTail, onUnseenChange]);\n\n // ------------------------------------------------------------------ render\n\n return (\n <div\n ref={attachViewport}\n data-react-fancy-virtual-list=\"\"\n data-react-fancy-virtual-list-following={followTail ? \"true\" : \"false\"}\n data-react-fancy-virtual-list-rows={items.length}\n role=\"log\"\n tabIndex={0}\n className={cn(\"relative overflow-y-auto overflow-x-hidden outline-none\", className)}\n style={{ height }}\n onScroll={onScroll}\n onWheel={onWheel}\n onKeyDown={onKeyDown}\n onTouchStart={onTouchStart}\n onTouchMove={onTouchMove}\n {...props}\n >\n {/* Holds the full scroll range so the scrollbar is honest from the first\n paint, instead of growing as rows are discovered. */}\n <div\n data-react-fancy-virtual-list-sizer=\"\"\n style={{ height: `${total}px`, position: \"relative\" }}\n >\n <div\n ref={windowRef}\n data-react-fancy-virtual-list-window=\"\"\n data-react-fancy-virtual-list-start={start}\n style={{ transform: `translateY(${offsets[start] ?? 0}px)` }}\n >\n {visible.map((item, i) => (\n <div key={item.id} data-react-fancy-virtual-row-id={item.id}>\n {renderRow(item, start + i)}\n </div>\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nconst ROW_ID_ATTR = \"data-react-fancy-virtual-row-id\";\n\n/**\n * A row's border-box height from a ResizeObserver entry. `borderBoxSize` is\n * what getBoundingClientRect() would report; older engines lack it (and early\n * Firefox gave a single object, not an array), so fall back to `contentRect`,\n * which equals it for the row wrapper, as that carries no padding or border.\n */\nfunction entryHeight(entry: ResizeObserverEntry): number {\n const box = entry.borderBoxSize as ReadonlyArray<ResizeObserverSize> | ResizeObserverSize | undefined;\n const first = Array.isArray(box) ? box[0] : (box as ResizeObserverSize | undefined);\n if (first && typeof first.blockSize === \"number\") return first.blockSize;\n\n return entry.contentRect?.height ?? 0;\n}\n/** Within this many px of the bottom counts as \"at the bottom\". */\nconst BOTTOM_SLACK = 4;\n/** Ignore a touch jitter smaller than this before calling it an upward drag. */\nconst TOUCH_SLOP = 4;\nconst UPWARD_KEYS = new Set([\"ArrowUp\", \"PageUp\", \"Home\"]);\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/VirtualList/VirtualList.tsx"],"names":[],"mappings":";;;;AA4DO,SAAS,WAAA,CAAsC;AAAA,EACpD,KAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA,GAAS,MAAA;AAAA,EACT,iBAAA,GAAoB,EAAA;AAAA,EACpB,QAAA,GAAW,CAAA;AAAA,EACX,UAAA,GAAa,KAAA;AAAA,EACb,cAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,MAAM,WAAA,GAAc,OAA8B,IAAI,CAAA;AACtD,EAAA,MAAM,SAAA,GAAY,OAA8B,IAAI,CAAA;AAGpD,EAAA,MAAM,OAAA,GAAU,MAAA,iBAAO,IAAI,GAAA,EAAqB,CAAA;AAEhD,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,CAAC,CAAA;AAE1C,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,CAAC,CAAA;AAC5C,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,CAAA,GAAI,SAAS,CAAC,CAAA;AAElD,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,EAAA,KAA8B;AAC7B,MAAA,WAAA,CAAY,OAAA,GAAU,EAAA;AACtB,MAAA,IAAI,OAAO,GAAA,KAAQ,UAAA,EAAY,GAAA,CAAI,EAAE,CAAA;AAAA,WAAA,IAC5B,GAAA,EAAM,GAAA,CAA2C,OAAA,GAAU,EAAA;AAAA,IACtE,CAAA;AAAA,IACA,CAAC,GAAG;AAAA,GACN;AAKA,EAAA,MAAM,QAA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AAA","file":"chunk-Q72VHIBI.js","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, TouchEvent, WheelEvent } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport type { VirtualListProps, VirtualListRow } from \"./VirtualList.types\";\n\n/**\n * A windowed list for ledgers that run to tens of thousands of rows — only the\n * visible slice is in the DOM, with **measured** variable row heights, deep\n * links by row id, and sticky-bottom tail-following.\n *\n * Built for an agent event stream, where every one of those three is load\n * bearing at once: message rows wrap and event rows do not, a link carries\n * `?at=<rowId>` to the exact row under discussion, and new rows arrive while\n * the human is reading older ones.\n *\n * ## Heights are measured, never predicted\n *\n * `estimateRowHeight` only seeds rows that have never been on screen. The\n * moment a row renders, its real height is measured and replaces the estimate,\n * and every offset after it moves. The alternative — a `rowHeight(item)`\n * callback — is a prediction about text wrapping, font loading and container\n * width, and when it is wrong the error accumulates down the list: rows draw in\n * the wrong place and `scrollToId` lands on a neighbour. Measuring is slower to\n * settle and correct when it does.\n *\n * ## Tail-follow breaks on INTENT, not on position\n *\n * Any upward gesture — wheel, drag, PageUp, Home — stops following\n * immediately, even when the list is still pinned to the bottom and\n * `scrollTop` has not changed yet. Position cannot tell \"the human scrolled\n * up\" from \"content grew downward\", so a position-only implementation keeps\n * following through a wheel-up and yanks the reader back on the next append.\n *\n * ## It is controlled\n *\n * `followTail` is the consumer's state. This component only ever *asks* via\n * `onFollowChange`, so the follow state is readable and writable by an agent\n * over a bridge, as the Human+ component contract requires. The `↓ n new` pill\n * is the consumer's to render, from `onUnseenChange`.\n *\n * @example\n * ```tsx\n * const [following, setFollowing] = useState(true);\n * const [unseen, setUnseen] = useState(0);\n *\n * <VirtualList\n * items={events}\n * renderRow={(e) => <StreamRow event={e} />}\n * height=\"100%\"\n * estimateRowHeight={28}\n * followTail={following}\n * onFollowChange={setFollowing}\n * onUnseenChange={setUnseen}\n * scrollToId={params.at}\n * />\n * {!following && unseen > 0 && (\n * <Button onClick={() => setFollowing(true)}>↓ {unseen} new</Button>\n * )}\n * ```\n */\nexport function VirtualList<T extends VirtualListRow>({\n items,\n renderRow,\n height = \"100%\",\n estimateRowHeight = 32,\n overscan = 6,\n followTail = false,\n onFollowChange,\n onUnseenChange,\n scrollToId = null,\n onScrollToIdResolved,\n className,\n ref,\n ...props\n}: VirtualListProps<T>) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n\n /** Measured heights by row id, so a height follows its row across a reindex. */\n const heights = useRef(new Map<string, number>());\n /** Bumped when a measurement actually changed, to recompute offsets. */\n const [measured, setMeasured] = useState(0);\n\n const [scrollTop, setScrollTop] = useState(0);\n const [clientHeight, setClientHeight] = useState(0);\n\n const attachViewport = useCallback(\n (el: HTMLDivElement | null) => {\n viewportRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) (ref as { current: HTMLDivElement | null }).current = el;\n },\n [ref],\n );\n\n // A number `height` IS the viewport height, and is usable before the element\n // has been measured. Without one, render a conservative first window so there\n // is something on screen for the measurement pass to work from.\n const viewport =\n clientHeight > 0 ? clientHeight : typeof height === \"number\" ? height : estimateRowHeight * 20;\n\n /**\n * Prefix sums of row heights: `offsets[i]` is where row `i` starts, and the\n * last entry is the total. Rebuilt whenever rows or measurements change —\n * O(n) once per change, against O(log n) per scroll from the binary search,\n * rather than O(n) on every scroll frame.\n */\n const { offsets, total } = useMemo(() => {\n const offs = new Float64Array(items.length + 1);\n for (let i = 0; i < items.length; i += 1) {\n offs[i + 1] = offs[i] + (heights.current.get(items[i].id) ?? estimateRowHeight);\n }\n\n return { offsets: offs, total: items.length === 0 ? 0 : offs[items.length] };\n }, [items, measured, estimateRowHeight]);\n\n /** First row whose span contains `y`. */\n const indexAt = useCallback(\n (y: number): number => {\n let lo = 0;\n let hi = items.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (offsets[mid] <= y) lo = mid;\n else hi = mid - 1;\n }\n\n return Math.max(0, lo);\n },\n [items.length, offsets],\n );\n\n const start = Math.max(0, indexAt(scrollTop) - overscan);\n const end = Math.min(items.length, indexAt(scrollTop + viewport) + 1 + overscan);\n const visible = useMemo(() => items.slice(start, end), [items, start, end]);\n\n // ---------------------------------------------------------------- measuring\n\n //\n // Every getBoundingClientRect() / clientHeight read after a commit forces a\n // synchronous layout, and this list re-renders on every appended row. So a\n // row is measured ONCE, when its element first appears, and from then on the\n // ResizeObserver reports when it changes, with the size in the entry: no read\n // that forces layout. An append costs one measurement; a render where nothing\n // changed costs none. (Measured in genie#1340: re-measuring every visible row\n // on every render was 472 forced row measurements/s with 11 agents streaming.)\n\n const observer = useRef<ResizeObserver | null>(null);\n /** Row elements currently observed, so each is observed once and released. */\n const observed = useRef(new Set<Element>());\n\n // A layout effect, declared before the measuring one, so the observer exists\n // by the time the first window is measured and the first rows are observed.\n useLayoutEffect(() => {\n // Absent in jsdom and in older runtimes. Without it the list measures every\n // visible row on every render instead, which is the only way it can notice\n // a row reflowing in place.\n if (typeof ResizeObserver === \"undefined\") return;\n\n const ro = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const el = entry.target as HTMLElement;\n\n if (el === viewportRef.current) {\n // The viewport's own resize changes how many rows fit. Reading\n // clientHeight here is free: the browser has just done layout.\n const ch = el.clientHeight;\n if (ch > 0) setClientHeight(ch);\n continue;\n }\n\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n const h = entryHeight(entry);\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n observer.current = ro;\n\n const vp = viewportRef.current;\n if (vp) ro.observe(vp);\n\n const tracked = observed.current;\n\n return () => {\n ro.disconnect();\n observer.current = null;\n tracked.clear();\n };\n }, []);\n\n // No dependency array on purpose: every render looks at what is on screen.\n // That LOOK is cheap — walking the window's children reads no layout. Only a\n // row seen for the first time is measured (or, with no ResizeObserver, every\n // row, as nothing else would notice a reflow). A render that learns nothing\n // new sets no state, which is what stops it looping.\n useLayoutEffect(() => {\n const win = windowRef.current;\n if (!win) return;\n\n const ro = observer.current;\n const tracked = observed.current;\n const present = ro ? new Set<Element>() : null;\n\n let changed = false;\n let measuredAny = false;\n for (const el of Array.from(win.children) as HTMLElement[]) {\n const id = el.getAttribute(ROW_ID_ATTR);\n if (id === null) continue;\n\n if (ro && present) {\n present.add(el);\n // Already observed: the observer reports its resizes.\n if (tracked.has(el)) continue;\n\n ro.observe(el);\n tracked.add(el);\n // A row scrolling back into view: its height is known, and the\n // observer's first report for the new element corrects it if it moved.\n if (heights.current.has(id)) continue;\n }\n\n const h = el.getBoundingClientRect().height;\n measuredAny = true;\n // A zero height is \"not laid out yet\", not a 0px row. Recording it would\n // collapse the list and make every offset after it wrong.\n if (h > 0 && heights.current.get(id) !== h) {\n heights.current.set(id, h);\n changed = true;\n }\n }\n\n if (ro && present) {\n for (const el of tracked) {\n if (!present.has(el)) {\n ro.unobserve(el);\n tracked.delete(el);\n }\n }\n }\n\n // With an observer, the viewport's resizes arrive through it; read it here\n // only when this pass has already paid for a layout, so it is free.\n const vp = viewportRef.current;\n if (vp && (!ro || measuredAny) && vp.clientHeight > 0 && vp.clientHeight !== clientHeight) {\n setClientHeight(vp.clientHeight);\n }\n\n if (changed) setMeasured((v) => v + 1);\n });\n\n // ------------------------------------------------------------- deep linking\n\n /** The target this component last moved to, to detect that it has settled. */\n const anchored = useRef<number | null>(null);\n const resolved = useRef<string | null>(null);\n\n useEffect(() => {\n // A new id is a new request, even if the old one had resolved.\n anchored.current = null;\n resolved.current = null;\n }, [scrollToId]);\n\n useLayoutEffect(() => {\n if (scrollToId === null || resolved.current === scrollToId) return;\n\n const index = items.findIndex((item) => item.id === scrollToId);\n if (index < 0) {\n // A link to a row that is no longer in the list. Leaving the viewport\n // where it is and SAYING SO is the only honest outcome — scrolling to the\n // top would be indistinguishable from a successful landing.\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, false);\n\n return;\n }\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n // Clamped the way the browser clamps: a row inside the final viewport-height\n // of the list cannot be brought to the top, and pretending otherwise would\n // leave this waiting for a position that can never be reached.\n const target = Math.max(0, Math.min(offsets[index], Math.max(0, total - viewport)));\n\n if (anchored.current !== target) {\n anchored.current = target;\n vp.scrollTop = target;\n setScrollTop(target);\n\n return;\n }\n\n // The target stopped moving as rows above it were measured, and we are on\n // it. Only now is the deep link actually honoured.\n if (Math.abs(vp.scrollTop - target) <= 1) {\n resolved.current = scrollToId;\n onScrollToIdResolved?.(scrollToId, true);\n }\n });\n\n // ------------------------------------------------------------- tail-follow\n\n const reportedFollow = useRef(followTail);\n const programmatic = useRef(false);\n\n useEffect(() => {\n // The prop is the truth, so adopt it rather than remembering what we asked\n // for. Otherwise a consumer that declines an `onFollowChange(false)` would\n // never be asked again.\n reportedFollow.current = followTail;\n }, [followTail]);\n\n const askFollow = useCallback(\n (next: boolean) => {\n if (reportedFollow.current === next) return;\n reportedFollow.current = next;\n onFollowChange?.(next);\n },\n [onFollowChange],\n );\n\n useLayoutEffect(() => {\n if (!followTail) return;\n // A pending deep link wins while it resolves; otherwise the two would fight\n // over the same scrollTop and the link would lose.\n if (scrollToId !== null && resolved.current !== scrollToId) return;\n\n const vp = viewportRef.current;\n if (!vp) return;\n\n const bottom = Math.max(0, total - viewport);\n if (Math.abs(vp.scrollTop - bottom) > 0.5) {\n programmatic.current = true;\n vp.scrollTop = bottom;\n setScrollTop(bottom);\n }\n });\n\n const onScroll = useCallback(() => {\n const vp = viewportRef.current;\n if (!vp) return;\n\n const next = vp.scrollTop;\n const previous = scrollTop;\n setScrollTop(next);\n\n const bottom = Math.max(0, total - viewport);\n const wasProgrammatic = programmatic.current;\n programmatic.current = false;\n\n if (next <= bottom - BOTTOM_SLACK) {\n // Moved up, and not because we moved it.\n if (!wasProgrammatic && next < previous) askFollow(false);\n } else {\n askFollow(true);\n }\n }, [scrollTop, total, viewport, askFollow]);\n\n /** Any upward gesture is a statement of intent, whatever scrollTop says. */\n const onWheel = useCallback(\n (e: WheelEvent<HTMLDivElement>) => {\n if (e.deltaY < 0) askFollow(false);\n },\n [askFollow],\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (UPWARD_KEYS.has(e.key)) askFollow(false);\n },\n [askFollow],\n );\n\n const touchStart = useRef<number | null>(null);\n\n const onTouchStart = useCallback((e: TouchEvent<HTMLDivElement>) => {\n touchStart.current = e.touches[0]?.clientY ?? null;\n }, []);\n\n const onTouchMove = useCallback(\n (e: TouchEvent<HTMLDivElement>) => {\n const from = touchStart.current;\n const y = e.touches[0]?.clientY;\n // Finger travelling DOWN drags the content down, which scrolls up.\n if (from !== null && y !== undefined && y - from > TOUCH_SLOP) askFollow(false);\n },\n [askFollow],\n );\n\n // ------------------------------------------------------------ unseen count\n\n const seen = useRef(items.length);\n const reportedUnseen = useRef<number | null>(null);\n\n useEffect(() => {\n const unseen = followTail ? 0 : Math.max(0, items.length - seen.current);\n if (followTail) seen.current = items.length;\n\n if (reportedUnseen.current === unseen) return;\n reportedUnseen.current = unseen;\n onUnseenChange?.(unseen);\n }, [items.length, followTail, onUnseenChange]);\n\n // ------------------------------------------------------------------ render\n\n return (\n <div\n ref={attachViewport}\n data-react-fancy-virtual-list=\"\"\n data-react-fancy-virtual-list-following={followTail ? \"true\" : \"false\"}\n data-react-fancy-virtual-list-rows={items.length}\n role=\"log\"\n tabIndex={0}\n className={cn(\"relative overflow-y-auto overflow-x-hidden outline-none\", className)}\n style={{ height }}\n onScroll={onScroll}\n onWheel={onWheel}\n onKeyDown={onKeyDown}\n onTouchStart={onTouchStart}\n onTouchMove={onTouchMove}\n {...props}\n >\n {/* Holds the full scroll range so the scrollbar is honest from the first\n paint, instead of growing as rows are discovered. */}\n <div\n data-react-fancy-virtual-list-sizer=\"\"\n style={{ height: `${total}px`, position: \"relative\" }}\n >\n <div\n ref={windowRef}\n data-react-fancy-virtual-list-window=\"\"\n data-react-fancy-virtual-list-start={start}\n style={{ transform: `translateY(${offsets[start] ?? 0}px)` }}\n >\n {visible.map((item, i) => (\n <div key={item.id} data-react-fancy-virtual-row-id={item.id}>\n {renderRow(item, start + i)}\n </div>\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nconst ROW_ID_ATTR = \"data-react-fancy-virtual-row-id\";\n\n/**\n * A row's border-box height from a ResizeObserver entry. `borderBoxSize` is\n * what getBoundingClientRect() would report; older engines lack it (and early\n * Firefox gave a single object, not an array), so fall back to `contentRect`,\n * which equals it for the row wrapper, as that carries no padding or border.\n */\nfunction entryHeight(entry: ResizeObserverEntry): number {\n const box = entry.borderBoxSize as ReadonlyArray<ResizeObserverSize> | ResizeObserverSize | undefined;\n const first = Array.isArray(box) ? box[0] : (box as ResizeObserverSize | undefined);\n if (first && typeof first.blockSize === \"number\") return first.blockSize;\n\n return entry.contentRect?.height ?? 0;\n}\n/** Within this many px of the bottom counts as \"at the bottom\". */\nconst BOTTOM_SLACK = 4;\n/** Ignore a touch jitter smaller than this before calling it an upward drag. */\nconst TOUCH_SLOP = 4;\nconst UPWARD_KEYS = new Set([\"ArrowUp\", \"PageUp\", \"Home\"]);\n"]}
|