@react-x11/components 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,8 +24,14 @@ export declare class RowHeights {
24
24
  private rows;
25
25
  /** Fenwick tree over the heights, 1-based. */
26
26
  private tree;
27
- /** What an unmeasured row is assumed to be. */
27
+ /** What an unmeasured row is assumed to be, effectively: the caller's
28
+ * `base`, until `adapt` has seen enough real rows to know better. */
28
29
  private estimate;
30
+ /** The estimate the caller declared. A caller changing it is a caller
31
+ * changing their mind, and it wins back over adaptation. */
32
+ private base;
33
+ /** Running sum of the measured map's values, so `adapt` is O(1). */
34
+ private sum;
29
35
  /** Largest power of two <= n, for the O(log n) descent in `indexAt`. */
30
36
  private power;
31
37
  /** Set when a measurement could not be applied in place, so the next
@@ -42,6 +48,8 @@ export declare class RowHeights {
42
48
  * arrive, when a sort flips, when a filter runs, all O(n) events already.
43
49
  */
44
50
  sync(rows: readonly Keyed[], estimate: number): void;
51
+ /** Rebuild the tree from the measured map and the current estimate. */
52
+ private rebuild;
45
53
  /**
46
54
  * Record what a row actually laid out at. Returns whether this changed
47
55
  * anything — which is what tells the component whether to re-render, and
@@ -64,8 +72,32 @@ export declare class RowHeights {
64
72
  * twice.
65
73
  */
66
74
  indexAt(offset: number): number;
75
+ /**
76
+ * Whether anything has ever been measured — O(1), and the question a
77
+ * component that may not measure at all has to ask before it waits on a
78
+ * measurement. `measuredCount` answers a different, costlier question:
79
+ * how many of the rows *currently indexed* have one.
80
+ */
81
+ hasMeasurements(): boolean;
67
82
  /** How many of the current rows have a real measurement. */
68
83
  measuredCount(): number;
84
+ /**
85
+ * Let the estimate learn from the rows that have been measured.
86
+ *
87
+ * The fixed guess is why a measured list converges slowly: every row not
88
+ * yet seen is assumed `estimate`, the scrollbar believes the sum, and each
89
+ * newly measured row moves everything. Once enough rows have real numbers,
90
+ * their mean is a far better guess for the rest — one O(n) rebuild brings
91
+ * every unmeasured offset close to where measuring will find it, so the
92
+ * corrections that follow are small.
93
+ *
94
+ * Returns whether anything changed. **Every offset of every unmeasured row
95
+ * moves when it does** — the caller owns keeping what is on screen still,
96
+ * the same anchor arithmetic a measurement pass does. Deliberately not
97
+ * called from `measure`: the caller decides when a wholesale move is safe
98
+ * to make, which is while nothing is scrolling.
99
+ */
100
+ adapt(): boolean;
69
101
  /**
70
102
  * Forget every measurement, keeping the row list.
71
103
  *
@@ -1 +1 @@
1
- {"version":3,"file":"heights.d.ts","sourceRoot":"","sources":["../../src/internal/heights.ts"],"names":[],"mappings":"AAyCA;;sBAEsB;AACtB,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErC;;qEAEqE;AACrE,UAAU,KAAK;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;GAQG;AACH,qBAAa,UAAU;IACrB,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,iDAAiD;IACjD,OAAO,CAAC,IAAI,CAAwB;IACpC,8CAA8C;IAC9C,OAAO,CAAC,IAAI,CAAiB;IAC7B,+CAA+C;IAC/C,OAAO,CAAC,QAAQ,CAAK;IACrB,wEAAwE;IACxE,OAAO,CAAC,KAAK,CAAK;IAClB;uEACmE;IACnE,OAAO,CAAC,KAAK,CAAS;IAEtB,YAAY,QAAQ,EAAE,MAAM,EAE3B;IAED,OAAO,CAAC,QAAQ;IAKhB;;;;;;;OAOG;IACH,IAAI,CAAC,IAAI,EAAE,SAAS,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAkBnD;IAED;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAkB1D;IAED,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9B;IAED,uEAAuE;IACvE,UAAU,CAAC,KAAK,EAAE,MAA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EAAE,MAAM,GAAG,OAAO,CAmB1D;IAED,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9B;IAED,uEAAuE;IACvE,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGjC;IAED,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAU9B;IAED,gEAAgE;IAChE,KAAK,IAAI,MAAM,CAEd;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAa9B;IAED;;;;;OAKG;IACH,eAAe,IAAI,OAAO,CAEzB;IAED,4DAA4D;IAC5D,aAAa,IAAI,MAAM,CAItB;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,IAAI,OAAO,CAUf;IAED;;;;;;;;OAQG;IACH,KAAK,IAAI,IAAI,CAMZ;CACF"}
@@ -1,10 +1,11 @@
1
1
  // Where every row starts, when rows are not all the same height.
2
2
  //
3
- // **Shared between `<Tree>` and `<Table>`** — the one piece of machinery
4
- // both virtualizers stand on, promoted here from the vendored copy the
5
- // table briefly carried (docs/prd-table.md records the decision). "No
6
- // component imports another component" holds: this is shared code, not a
7
- // component, and both import it.
3
+ // **Shared between `<Tree>` and `<Table>`** — the first piece of machinery
4
+ // both virtualizers stand on (`./timers.ts` and `./scroll.ts` are the other
5
+ // two), promoted here from the vendored copy the table briefly carried
6
+ // (docs/prd-table.md records the decision). "No component imports another
7
+ // component" holds: this is shared code, not a component, and both import
8
+ // it.
8
9
  //
9
10
  // **Deliberately not a shared *module*.** The directory has no `index.ts`,
10
11
  // so it has no subpath, no docs page, and is not public API — the repo's
@@ -54,15 +55,22 @@ export class RowHeights {
54
55
  rows = [];
55
56
  /** Fenwick tree over the heights, 1-based. */
56
57
  tree = [0];
57
- /** What an unmeasured row is assumed to be. */
58
+ /** What an unmeasured row is assumed to be, effectively: the caller's
59
+ * `base`, until `adapt` has seen enough real rows to know better. */
58
60
  estimate = 1;
61
+ /** The estimate the caller declared. A caller changing it is a caller
62
+ * changing their mind, and it wins back over adaptation. */
63
+ base = 1;
64
+ /** Running sum of the measured map's values, so `adapt` is O(1). */
65
+ sum = 0;
59
66
  /** Largest power of two <= n, for the O(log n) descent in `indexAt`. */
60
67
  power = 0;
61
68
  /** Set when a measurement could not be applied in place, so the next
62
69
  * `sync` must rebuild even though the row list did not change. */
63
70
  dirty = false;
64
71
  constructor(estimate) {
65
- this.estimate = Math.max(1, estimate);
72
+ this.base = Math.max(1, estimate);
73
+ this.estimate = this.base;
66
74
  }
67
75
  heightOf(index) {
68
76
  const measured = this.measured.get(this.rows[index].id);
@@ -78,12 +86,23 @@ export class RowHeights {
78
86
  */
79
87
  sync(rows, estimate) {
80
88
  const next = Math.max(1, estimate);
81
- if (!this.dirty && this.rows === rows && next === this.estimate)
89
+ if (next !== this.base) {
90
+ // The caller changed their declared estimate: that wins back over
91
+ // whatever `adapt` had learnt — it is the same caller telling us the
92
+ // rows changed character.
93
+ this.base = next;
94
+ this.estimate = next;
95
+ this.dirty = true;
96
+ }
97
+ if (!this.dirty && this.rows === rows)
82
98
  return;
83
- this.dirty = false;
84
99
  this.rows = rows;
85
- this.estimate = next;
86
- const n = rows.length;
100
+ this.rebuild();
101
+ }
102
+ /** Rebuild the tree from the measured map and the current estimate. */
103
+ rebuild() {
104
+ this.dirty = false;
105
+ const n = this.rows.length;
87
106
  // Build in O(n): write each height at its own slot, then push every slot
88
107
  // into its parent. The textbook loop of point-updates is O(n log n) and
89
108
  // arrives at the same tree.
@@ -110,6 +129,7 @@ export class RowHeights {
110
129
  if (before === height)
111
130
  return false;
112
131
  this.measured.set(id, height);
132
+ this.sum += height - (before ?? 0);
113
133
  if (this.rows[index]?.id !== id) {
114
134
  // The caller's index is stale — the rows moved under a measurement
115
135
  // that was already in flight. Applying a delta at the wrong slot would
@@ -168,6 +188,15 @@ export class RowHeights {
168
188
  }
169
189
  return Math.max(0, Math.min(n - 1, index));
170
190
  }
191
+ /**
192
+ * Whether anything has ever been measured — O(1), and the question a
193
+ * component that may not measure at all has to ask before it waits on a
194
+ * measurement. `measuredCount` answers a different, costlier question:
195
+ * how many of the rows *currently indexed* have one.
196
+ */
197
+ hasMeasurements() {
198
+ return this.measured.size > 0;
199
+ }
171
200
  /** How many of the current rows have a real measurement. */
172
201
  measuredCount() {
173
202
  let count = 0;
@@ -176,6 +205,35 @@ export class RowHeights {
176
205
  count++;
177
206
  return count;
178
207
  }
208
+ /**
209
+ * Let the estimate learn from the rows that have been measured.
210
+ *
211
+ * The fixed guess is why a measured list converges slowly: every row not
212
+ * yet seen is assumed `estimate`, the scrollbar believes the sum, and each
213
+ * newly measured row moves everything. Once enough rows have real numbers,
214
+ * their mean is a far better guess for the rest — one O(n) rebuild brings
215
+ * every unmeasured offset close to where measuring will find it, so the
216
+ * corrections that follow are small.
217
+ *
218
+ * Returns whether anything changed. **Every offset of every unmeasured row
219
+ * moves when it does** — the caller owns keeping what is on screen still,
220
+ * the same anchor arithmetic a measurement pass does. Deliberately not
221
+ * called from `measure`: the caller decides when a wholesale move is safe
222
+ * to make, which is while nothing is scrolling.
223
+ */
224
+ adapt() {
225
+ const n = this.measured.size;
226
+ if (n < 8)
227
+ return false; // too few rows to say anything about the rest
228
+ const mean = Math.round(this.sum / n);
229
+ // ±1 is noise — the mean drifts by that much as single rows arrive, and
230
+ // a rebuild per drift would run at the measure rate for no visible gain.
231
+ if (Math.abs(mean - this.estimate) <= 1)
232
+ return false;
233
+ this.estimate = Math.max(1, mean);
234
+ this.rebuild();
235
+ return true;
236
+ }
179
237
  /**
180
238
  * Forget every measurement, keeping the row list.
181
239
  *
@@ -187,6 +245,9 @@ export class RowHeights {
187
245
  */
188
246
  reset() {
189
247
  this.measured.clear();
248
+ this.sum = 0;
249
+ // adaptation came from the measurements just forgotten
250
+ this.estimate = this.base;
190
251
  this.dirty = true;
191
252
  }
192
253
  }
@@ -1 +1 @@
1
- {"version":3,"file":"heights.js","sourceRoot":"","sources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H,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;QACb,uDAAuD;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,73 @@
1
+ import type { DrawnNode, ScrollableNode } from 'react-x11';
2
+ import type { RowHeights, RowKey } from './heights.js';
3
+ /** All a reveal needs of a row: `<TreeRow>` and `<TableRow>` are both this. */
4
+ interface Keyed {
5
+ id: RowKey;
6
+ }
7
+ /** A row on screen, and the index it was drawn at — the shape both
8
+ * components already keep their mounted rows in. */
9
+ interface Drawn {
10
+ node: DrawnNode;
11
+ at: number;
12
+ }
13
+ /** What the component lends the reveal: everything it already has, by ref,
14
+ * so nothing here goes stale between a render and the tick after layout. */
15
+ export interface RevealSources {
16
+ /** The scroll pane. `<Table>`'s body; `<Tree>`'s own root. */
17
+ box: {
18
+ readonly current: ScrollableNode | null;
19
+ };
20
+ /** The rows in display order. */
21
+ rows: {
22
+ readonly current: readonly Keyed[];
23
+ };
24
+ /** The rows on screen, by id. */
25
+ nodes: {
26
+ readonly current: ReadonlyMap<RowKey, Drawn>;
27
+ };
28
+ /** Where the rows that are *not* on screen are — and how tall a row that
29
+ * has never been drawn is assumed to be. */
30
+ heights: RowHeights;
31
+ }
32
+ export interface Reveal {
33
+ /** Owe a scroll to this row, and try to pay it now. */
34
+ to(id: RowKey): void;
35
+ /**
36
+ * The content above the viewport just changed size by `px` — measurements
37
+ * came in — and the offset must absorb the difference or what is on screen
38
+ * jumps. A debt rather than a one-shot for the same reason a reveal is:
39
+ * the pane clamps against the content height of the *last* layout, so a
40
+ * nudge made just after rows above grew taller lands short — near the
41
+ * bottom of the list, all of it lands short — and the remainder must be
42
+ * re-tried once the layout that admits the growth has run. Retried by
43
+ * `retry`, dropped by `heard`: a user mid-scroll keeps the pane.
44
+ */
45
+ nudge(px: number): void;
46
+ /**
47
+ * Try again: after a layout, or when the content changed size.
48
+ *
49
+ * Pass `provisional` on a pass where the height index just moved. The rows
50
+ * are still laid out at the heights it no longer believes, so a row that
51
+ * looks in view is not proof of anything yet — a row measured taller than
52
+ * the guess pushes everything after it down, and the row that was reached a
53
+ * moment ago ends up under the fold. The debt is kept until a pass that
54
+ * measured nothing new confirms it, which is exactly when the heights have
55
+ * converged.
56
+ */
57
+ retry(provisional?: boolean): void;
58
+ /** Scroll the pane, recording that this component is the one that asked. */
59
+ scrollTo(y: number): void;
60
+ /** An `onScroll` arrived. One this component did not ask for is the user
61
+ * taking over, and it cancels whatever was owed. */
62
+ heard(scrollY: number): void;
63
+ }
64
+ /**
65
+ * The scroll a component owes a row, and the bookkeeping that pays it.
66
+ *
67
+ * Stable across renders — every method reads through the refs it was handed,
68
+ * so an event handler or a layout tick built in an earlier render still sees
69
+ * the current rows.
70
+ */
71
+ export declare function useReveal(sources: RevealSources): Reveal;
72
+ export {};
73
+ //# sourceMappingURL=scroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/internal/scroll.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAIvD,+EAA+E;AAC/E,UAAU,KAAK;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;qDACqD;AACrD,UAAU,KAAK;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;6EAC6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,GAAG,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;KAAE,CAAC;IACjD,iCAAiC;IACjC,IAAI,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAA;KAAE,CAAC;IAC7C,iCAAiC;IACjC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;IACxD;iDAC6C;IAC7C,OAAO,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,uDAAuD;IACvD,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACnC,4EAA4E;IAC5E,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;yDACqD;IACrD,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAsOxD"}
@@ -0,0 +1,264 @@
1
+ // Scrolling a row into view, when neither the row nor the scroll pane is
2
+ // ready to be asked yet.
3
+ //
4
+ // **Shared between `<Tree>` and `<Table>`** — the third piece both
5
+ // virtualizers stand on, beside `./heights.ts` and `./timers.ts`, and here
6
+ // for the same reason: the logic is subtle, it is identical in both, and a
7
+ // second copy of it is a second place for the bug below to come back.
8
+ //
9
+ // Two things a scroll pane does silently, both of them in the gap between a
10
+ // commit and the layout it causes, and both of them enough on their own to
11
+ // leave a virtualized list drawing rows the viewport is no longer looking at:
12
+ //
13
+ // 1. **`scrollTo` clamps against the content height the *last* layout
14
+ // measured.** A row appended in the commit now being laid out is past
15
+ // the bottom that clamp knows about, so the request lands short — and
16
+ // short *for good*, because nothing about it is retried. That is the
17
+ // live tail: a list that scrolls to its newest row on every update and
18
+ // settles one update behind, permanently. On mount, where no content
19
+ // has been laid out at all, the scroll simply never happens.
20
+ //
21
+ // 2. **The pane moves without saying so.** It resolves a queued
22
+ // `scrollIntoView` during layout, and it re-clamps an offset the
23
+ // content has outgrown or outshrunk — neither of which fires
24
+ // `onScroll`. A component that learns the offset only from that event
25
+ // keeps building its slice from where the pane *was*: the rows are
26
+ // drawn off-viewport, there is a blank band where they should be, and
27
+ // nothing puts it right until a scroll of your own re-syncs it by
28
+ // accident.
29
+ //
30
+ // So a reveal here is not a one-shot: it is a **debt**, kept by row id,
31
+ // attempted at once and re-tried on the layout that makes the rest of the
32
+ // move possible. It is dropped as soon as the row is in view, leaves the
33
+ // list, or the user scrolls somewhere themselves — an owed scroll must never
34
+ // yank the list back out from under a hand on the wheel.
35
+ //
36
+ // The offset is read back from the pane rather than trusted to the event;
37
+ // `useReveal` does not do that itself, because what a component *does* with
38
+ // the offset differs (a slice to rebuild, a header to shift), but it is the
39
+ // other half of the same fix and both components run it on the same tick.
40
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
41
+ import { afterLayout, cancelAfterLayout } from './timers.js';
42
+ /**
43
+ * The scroll a component owes a row, and the bookkeeping that pays it.
44
+ *
45
+ * Stable across renders — every method reads through the refs it was handed,
46
+ * so an event handler or a layout tick built in an earlier render still sees
47
+ * the current rows.
48
+ */
49
+ export function useReveal(sources) {
50
+ const src = useRef(sources);
51
+ src.current = sources;
52
+ /** The row still owed a scroll, by id. */
53
+ const owed = useRef(null);
54
+ /**
55
+ * The row the last reveal settled on, kept for one reason: a measurement
56
+ * pass can move the heights that settlement was judged against. A row that
57
+ * was in view when the debt was paid is not in view any more once the rows
58
+ * around it turn out taller than the index believed, and the honest answer
59
+ * to "is that still true?" is to owe it again and look. Measurement
60
+ * converges, so this stops asking.
61
+ */
62
+ const settled = useRef(null);
63
+ /** The offset the last scroll *this component* asked for, so the
64
+ * `onScroll` that answers it is not read as the user taking over. */
65
+ const asked = useRef(null);
66
+ /**
67
+ * What the pane looked like at the last attempt that could not move.
68
+ *
69
+ * An attempt clamped by a content height that is a layout out of date has
70
+ * to be looked at again — and nothing else will schedule that look: the
71
+ * scroll that did not happen renders nothing, so the component's own tick
72
+ * after layout never comes. One is queued here instead, and only while the
73
+ * pane keeps changing under it: an attempt that finds the same offset and
74
+ * the same content as the last one has nothing new to try, and stops.
75
+ */
76
+ const stuck = useRef(null);
77
+ const look = useRef(null);
78
+ useEffect(() => () => cancelAfterLayout(look.current), []);
79
+ /** Pixels the pane still owes the content that grew or shrank above the
80
+ * viewport — the unpaid remainder of `nudge`. */
81
+ const owedShift = useRef(0);
82
+ const scrollTo = useCallback((y) => {
83
+ const box = src.current.box.current;
84
+ if (!box)
85
+ return;
86
+ // Clamped here rather than left to the container, so what comes back on
87
+ // `onScroll` is the number that was asked for and can be recognised.
88
+ const to = Math.min(Math.max(0, y), Math.max(0, box.contentHeight - box.abs.height));
89
+ if (to === box.scrollY)
90
+ return;
91
+ asked.current = to;
92
+ box.scrollTo({ y: to });
93
+ }, []);
94
+ /** Pay as much of the owed shift as the pane will take right now. What it
95
+ * refuses — a clamp still measuring the last layout's content — stays
96
+ * owed, and the `retry` after the next layout tries again. */
97
+ const payShift = useCallback(() => {
98
+ const box = src.current.box.current;
99
+ const want = owedShift.current;
100
+ if (!box || want === 0)
101
+ return;
102
+ const was = box.scrollY;
103
+ scrollTo(was + want);
104
+ owedShift.current = want - (box.scrollY - was);
105
+ }, [scrollTo]);
106
+ const nudge = useCallback((px) => {
107
+ // Either the reveal owns the pane or the anchor does. While a row is
108
+ // owed — or settled and still being confirmed — the reveal re-places
109
+ // it against the heights as they settle, so preserving the anchor
110
+ // would fight it: a remainder paid out after the reveal has already
111
+ // put its row where it belongs scrolls straight past it.
112
+ if (owed.current !== null || settled.current !== null)
113
+ return;
114
+ if (px === 0)
115
+ return;
116
+ owedShift.current += px;
117
+ payShift();
118
+ }, [payShift]);
119
+ const retry = useCallback((provisional) => {
120
+ const { box: boxRef, rows: rowsRef, nodes, heights } = src.current;
121
+ const box = boxRef.current;
122
+ // The shift first: the reveal below judges placement from the offset,
123
+ // and an offset still owing the content above it is the wrong one to
124
+ // judge anything from.
125
+ payShift();
126
+ // The heights just moved, so what the last reveal settled on was settled
127
+ // against numbers that have changed: owe it again until it can be
128
+ // confirmed at the new ones.
129
+ if (provisional && owed.current === null)
130
+ owed.current = settled.current;
131
+ const id = owed.current;
132
+ if (!box || id === null)
133
+ return;
134
+ const rows = rowsRef.current;
135
+ const at = rows.findIndex((r) => r.id === id);
136
+ if (at < 0) {
137
+ // the row left the list
138
+ owed.current = null;
139
+ settled.current = null;
140
+ return;
141
+ }
142
+ const viewport = box.abs.height;
143
+ if (viewport <= 0)
144
+ return; // nothing laid out to scroll inside yet
145
+ // How far the row is outside the pane, in pixels of scrolling. The row's
146
+ // own rect answers when it is mounted — it knows what it really laid out
147
+ // at, and the arithmetic stays in screen coordinates, so a pane with
148
+ // padding on it needs no correction. The height index answers when the
149
+ // row is not mounted, which while virtualizing is the normal case.
150
+ const drawn = nodes.current.get(id);
151
+ const mounted = drawn && drawn.node.abs.height > 0 && rows[drawn.at]?.id === id
152
+ ? drawn.node
153
+ : null;
154
+ const placed = mounted
155
+ ? {
156
+ above: box.abs.y - mounted.abs.y,
157
+ below: mounted.abs.y + mounted.abs.height - (box.abs.y + viewport),
158
+ height: mounted.abs.height,
159
+ }
160
+ : {
161
+ above: box.scrollY - heights.offsetAt(at),
162
+ below: heights.offsetAt(at) +
163
+ heights.heightAt(at) -
164
+ (box.scrollY + viewport),
165
+ height: heights.heightAt(at),
166
+ };
167
+ /**
168
+ * Whether this is worth *settling* on, or only worth acting on.
169
+ *
170
+ * Two ways a row can look in view and not stay there. Its own placement
171
+ * may be a guess — the index's answer for a row nothing has measured —
172
+ * and "in view" judged from a guess is how a tail lands short of a bottom
173
+ * that has not been measured yet. Or a row *between* the viewport and it
174
+ * may still be a guess, and every one of those that turns out taller than
175
+ * the index believed pushes this row down by the difference, out of the
176
+ * view it had just been brought into.
177
+ *
178
+ * Both are settled by the same thing: measurement converges, so the rows
179
+ * that matter stop being guesses. A component that measures nothing at all
180
+ * has no guesses to wait on — `hasMeasurements` is how that is told
181
+ * apart, and it is what keeps a declared-uniform table from owing a debt
182
+ * for ever.
183
+ */
184
+ let certain = mounted !== null || heights.isMeasured(at);
185
+ if (certain && heights.hasMeasurements()) {
186
+ const from = Math.min(at, heights.indexAt(box.scrollY));
187
+ const to = Math.max(at, heights.indexAt(box.scrollY + viewport));
188
+ for (let i = from; i <= to && certain; i++) {
189
+ certain = heights.isMeasured(i);
190
+ }
191
+ }
192
+ let move = 0;
193
+ if (placed.height >= viewport) {
194
+ // A row taller than the pane is never *fully* in view, and asking for
195
+ // both its edges in turn is a debt that alternates for ever. Its top is
196
+ // the part worth showing — a wrapped row reads from its first line —
197
+ // and arriving there settles it.
198
+ move = -placed.above;
199
+ }
200
+ else if (placed.above > 0)
201
+ move = -placed.above;
202
+ else if (placed.below > 0)
203
+ move = placed.below;
204
+ if (move === 0) {
205
+ // As far in view as it can be — settled, unless what that was judged
206
+ // against is still moving: a placement that came from a guess, or a
207
+ // pass that has just changed the heights under it.
208
+ if (certain && !provisional) {
209
+ settled.current = id;
210
+ owed.current = null;
211
+ }
212
+ return;
213
+ }
214
+ // A move the pane cannot make yet leaves the debt standing: the layout
215
+ // that admits the rows just appended is the one that will let it finish.
216
+ const was = box.scrollY;
217
+ scrollTo(was + move);
218
+ if (box.scrollY !== was) {
219
+ stuck.current = null; // it moved; the scroll it caused brings us back
220
+ return;
221
+ }
222
+ const seen = stuck.current;
223
+ const now = { y: box.scrollY, content: box.contentHeight };
224
+ stuck.current = now;
225
+ if (seen && seen.y === now.y && seen.content === now.content)
226
+ return;
227
+ cancelAfterLayout(look.current);
228
+ look.current = afterLayout(() => {
229
+ look.current = null;
230
+ retryRef.current?.();
231
+ });
232
+ }, [scrollTo, payShift]);
233
+ /** `retry` referring to itself through a ref, so the queued look calls the
234
+ * current one rather than closing over the render that queued it. */
235
+ const retryRef = useRef(null);
236
+ retryRef.current = retry;
237
+ const to = useCallback((id) => {
238
+ // Recorded before the attempt rather than after it, because the
239
+ // interesting case is the one that cannot succeed yet.
240
+ owed.current = id;
241
+ settled.current = null;
242
+ stuck.current = null;
243
+ // the reveal owns the pane now — see `nudge`
244
+ owedShift.current = 0;
245
+ retry();
246
+ }, [retry]);
247
+ const heard = useCallback((scrollY) => {
248
+ // A scroll this component did not ask for ends the whole chase, not just
249
+ // the outstanding half of it.
250
+ if (scrollY !== asked.current) {
251
+ owed.current = null;
252
+ settled.current = null;
253
+ owedShift.current = 0;
254
+ }
255
+ asked.current = null;
256
+ }, []);
257
+ // One stable object, not a fresh literal per render: callbacks built on
258
+ // this handle (`revealAt`, and the row handlers behind it) keep their
259
+ // identity, which is what lets a memoized row bail out of a scroll
260
+ // render. A literal here made every row re-render on every notch — the
261
+ // exact cost the memo exists to remove — with nothing anywhere naming it.
262
+ return useMemo(() => ({ to, retry, scrollTo, nudge, heard }), [to, retry, scrollTo, nudge, heard]);
263
+ }
264
+ //# sourceMappingURL=scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/internal/scroll.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yBAAyB;AACzB,EAAE;AACF,mEAAmE;AACnE,2EAA2E;AAC3E,2EAA2E;AAC3E,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,0EAA0E;AAC1E,kEAAkE;AAClE,EAAE;AACF,kEAAkE;AAClE,sEAAsE;AACtE,kEAAkE;AAClE,2EAA2E;AAC3E,wEAAwE;AACxE,2EAA2E;AAC3E,uEAAuE;AACvE,iBAAiB;AACjB,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,yDAAyD;A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AsE;IACtE,mEAAmE;IACnE,uEAAuE;IACvE,0EAA0E;IAC1E,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAC7C,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;AACJ,CAAC"}
@@ -5,4 +5,12 @@ export type LayoutTick = {
5
5
  /** Run `fn` after the layout pass this commit will cause. */
6
6
  export declare function afterLayout(fn: () => void): LayoutTick;
7
7
  export declare function cancelAfterLayout(tick: LayoutTick): void;
8
+ export type DelayTick = {
9
+ id: unknown;
10
+ } | null;
11
+ /** Run `fn` after `ms` — the idle clock prefetch paces itself on. Typed here
12
+ * for the same reason `afterLayout` is: `src/` compiles with `types: []`,
13
+ * and a bare `setTimeout` would demand `@types/node`. */
14
+ export declare function later(fn: () => void, ms: number): DelayTick;
15
+ export declare function cancelLater(tick: DelayTick): void;
8
16
  //# sourceMappingURL=timers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/internal/timers.ts"],"names":[],"mappings":"AA0BA,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAEpE,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,UAAU,CAQtD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAIxD"}
1
+ {"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/internal/timers.ts"],"names":[],"mappings":"AA0BA,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAEpE,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,UAAU,CAQtD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAIxD;AAED,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAE/C;;0DAE0D;AAC1D,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAE3D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAEjD"}
@@ -19,4 +19,14 @@ export function cancelAfterLayout(tick) {
19
19
  else
20
20
  g.clearTimeout?.(tick.id);
21
21
  }
22
+ /** Run `fn` after `ms` — the idle clock prefetch paces itself on. Typed here
23
+ * for the same reason `afterLayout` is: `src/` compiles with `types: []`,
24
+ * and a bare `setTimeout` would demand `@types/node`. */
25
+ export function later(fn, ms) {
26
+ return g.setTimeout ? { id: g.setTimeout(fn, ms) } : null;
27
+ }
28
+ export function cancelLater(tick) {
29
+ if (tick)
30
+ g.clearTimeout?.(tick.id);
31
+ }
22
32
  //# sourceMappingURL=timers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timers.js","sourceRoot":"","sources":["../../src/internal/timers.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,GAAG,UAAsB,CAAC;AAIjC,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,EAAc;IACxC,yEAAyE;IACzE,2EAA2E;IAC3E,oEAAoE;IACpE,wEAAwE;IACxE,IAAI,CAAC,CAAC,YAAY;QAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACvE,IAAI,CAAC,CAAC,UAAU;QAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,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