@jsenv/navi 0.29.417 → 0.29.418

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.
@@ -10826,6 +10826,28 @@ const suspendScrollRecording = () => {
10826
10826
  };
10827
10827
  };
10828
10828
 
10829
+ // A list scrolling the document that opens on a row puts the document where
10830
+ // that row is, by measuring it (see placeWhereHeld in list.jsx). The offset kept
10831
+ // for the url is pixels of the page as it was drawn — and a list draws a window
10832
+ // of its rows and holds the room of the others with fillers of an estimated
10833
+ // height, so the same pixels now fall on other rows. Put back after the list
10834
+ // has placed itself, they would undo it, in the very picture a route transition
10835
+ // takes. So the list holds the document while it is placing itself, and the
10836
+ // url's offset is not put back meanwhile. Counted: two lists can share one
10837
+ // document.
10838
+ let documentHoldCount = 0;
10839
+ const holdDocumentScroll = () => {
10840
+ documentHoldCount++;
10841
+ let released = false;
10842
+ return () => {
10843
+ if (released) {
10844
+ return;
10845
+ }
10846
+ released = true;
10847
+ documentHoldCount--;
10848
+ };
10849
+ };
10850
+
10829
10851
  let installed = false;
10830
10852
  const installScrollRestoration = () => {
10831
10853
  if (installed) {
@@ -10860,6 +10882,9 @@ const installScrollRestoration = () => {
10860
10882
  if (positionOnLoad && (positionOnLoad.x || positionOnLoad.y)) {
10861
10883
  const stopListening = observeRouteRender(() => {
10862
10884
  stopListening();
10885
+ if (documentHoldCount) {
10886
+ return;
10887
+ }
10863
10888
  scrollTo(positionOnLoad);
10864
10889
  });
10865
10890
  }
@@ -10874,6 +10899,11 @@ const restoreScrollPosition = (url) => {
10874
10899
  if (!position) {
10875
10900
  return false;
10876
10901
  }
10902
+ if (documentHoldCount) {
10903
+ // There is a place to go back to, and the list holding the document is
10904
+ // putting it back (see holdDocumentScroll).
10905
+ return true;
10906
+ }
10877
10907
  scrollTo(position);
10878
10908
  return true;
10879
10909
  };
@@ -71243,9 +71273,17 @@ const ListUI = props => {
71243
71273
  // why not an effect), and the floor of 30 is its: it protects the scrolling
71244
71274
  // window, not a picture nobody has seen yet.
71245
71275
  const {
71246
- initial: initialRenderBudget,
71276
+ initial: initialRenderBudgetProp,
71247
71277
  after: renderBudgetAfterPaint
71248
71278
  } = resolveRenderBudget(renderBudgetProp);
71279
+ // Opening on a position that says how many rows were on screen from its row
71280
+ // on (the way back to where the list was, see reportPosition): that is what
71281
+ // the first picture shows, whatever `initial` guessed — with the row above
71282
+ // when it stood partly in view. The rest waits for the paint like any
71283
+ // `initial`: a page coming back in a route transition builds it inside the
71284
+ // update callback, and every row below the fold delays the movement.
71285
+ const openingPosition = scrolled ?? defaultScrolled;
71286
+ const initialRenderBudget = openingPosition && typeof openingPosition === "object" && typeof openingPosition.visibleCount === "number" ? openingPosition.visibleCount + (openingPosition.offset > 0 ? 1 : 0) : initialRenderBudgetProp;
71249
71287
  let renderBudget = renderBudgetAfterPaint;
71250
71288
  if (renderBudget < 30 && !renderBudgetSkipCheck) {
71251
71289
  console.warn(`List: renderBudget=${renderBudget} is too low. A renderBudget below 30 is not supported: on large screens or when the list grows, items outside the window would appear as blank space instead of rendered content. Use a value of at least 30, or omit the prop to use the default (${RENDER_BUDGET_DEFAULT}).`);
@@ -71708,11 +71746,23 @@ const useListScrollSync = ({
71708
71746
  horizontal
71709
71747
  });
71710
71748
  };
71749
+
71750
+ // How many rows the window keeps above the row the list is held at. Around it
71751
+ // for the scrolling to come, from the first paint on; before, the window is
71752
+ // the first picture's, and a picture of the list opening on a row shows that
71753
+ // row and what is below it — with the one above when a remembered position
71754
+ // says it stood partly in view.
71755
+ const rowsAboveOpening = (openAt, windowSize) => {
71756
+ if (renderBudget !== renderBudgetSteady) {
71757
+ return openAt && typeof openAt === "object" && openAt.offset > 0 ? 1 : 0;
71758
+ }
71759
+ return Math.floor(windowSize / 2);
71760
+ };
71711
71761
  const [renderWindow, setRenderWindow] = useState(() => {
71712
71762
  // Opening somewhere else than the beginning starts by framing there: the
71713
71763
  // rows the list will draw are the rows it will ask for.
71714
71764
  const openAt = scrolled ?? defaultScrolled;
71715
- const start = typeof openAt === "number" ? openAt - Math.floor(renderBudget / 2) : 0;
71765
+ const start = typeof openAt === "number" ? openAt - rowsAboveOpening(openAt, renderBudget) : 0;
71716
71766
  const startClamped = start < 0 ? 0 : start;
71717
71767
  return {
71718
71768
  start: startClamped,
@@ -71785,8 +71835,12 @@ const useListScrollSync = ({
71785
71835
  // Held somewhere it has not reached yet: what the window frames right now
71786
71836
  // is not what it will frame, so nothing should be fetched for it.
71787
71837
  listRows.holdPending = scrolledWanted !== "start" && scrolledWanted !== undefined;
71838
+ // Zero until the runs have rendered — they count their rows as they do,
71839
+ // after the list — which is not a collection fitting in the window: it is
71840
+ // one whose end is not known yet, and the window then frames the row the
71841
+ // list opens on, already in the first commit.
71788
71842
  const total = listRows.totalSignal.peek();
71789
- if (total <= renderBudget) {
71843
+ if (total > 0 && total <= renderBudget) {
71790
71844
  // The whole collection is what the list draws: wherever in it the list is
71791
71845
  // held, the window is already its place. Nowhere to move to means nothing
71792
71846
  // to wait for — a hold left standing here is a list that never asks for
@@ -71794,21 +71848,21 @@ const useListScrollSync = ({
71794
71848
  listRows.holdPending = false;
71795
71849
  return;
71796
71850
  }
71797
- const half = Math.floor(renderBudget / 2);
71851
+ const above = rowsAboveOpening(scrolledWanted, renderBudget);
71798
71852
  let wantedStart = null;
71799
71853
  if (scrolledWanted === "end") {
71800
71854
  wantedStart = total - renderBudget;
71801
71855
  } else if (typeof scrolledWanted === "number") {
71802
- wantedStart = scrolledWanted - half;
71856
+ wantedStart = scrolledWanted - above;
71803
71857
  } else if (scrolledWanted && scrolledWanted.id !== undefined) {
71804
71858
  const rowIndex = listRows.locateRow(scrolledWanted.id);
71805
71859
  if (rowIndex !== null) {
71806
- wantedStart = rowIndex - half;
71860
+ wantedStart = rowIndex - above;
71807
71861
  } else if (typeof scrolledWanted.index === "number") {
71808
71862
  // The row has not come back yet, but where it stood is known: near
71809
71863
  // enough to frame, and to put the scrollbar roughly where it will end
71810
71864
  // up rather than at the top.
71811
- wantedStart = scrolledWanted.index - half;
71865
+ wantedStart = scrolledWanted.index - above;
71812
71866
  }
71813
71867
  }
71814
71868
  if (wantedStart === null) {
@@ -71817,12 +71871,12 @@ const useListScrollSync = ({
71817
71871
  // back — the run asks for it by name (see useRequestMissing).
71818
71872
  return;
71819
71873
  }
71874
+ if (total > 0 && wantedStart + renderBudget > total) {
71875
+ wantedStart = total - renderBudget;
71876
+ }
71820
71877
  if (wantedStart < 0) {
71821
71878
  wantedStart = 0;
71822
71879
  }
71823
- if (wantedStart + renderBudget > total) {
71824
- wantedStart = total - renderBudget;
71825
- }
71826
71880
  const {
71827
71881
  start,
71828
71882
  end
@@ -72157,8 +72211,8 @@ const useListScrollSync = ({
72157
72211
  end
72158
72212
  } = renderWindowRef.current;
72159
72213
  if (rowIndex < start || rowIndex >= end) {
72160
- const half = Math.floor((end - start) / 2);
72161
- const wantedStart = rowIndex - half < 0 ? 0 : rowIndex - half;
72214
+ const above = rowsAboveOpening(scrolledWanted, end - start);
72215
+ const wantedStart = rowIndex - above < 0 ? 0 : rowIndex - above;
72162
72216
  updateRenderWindow(wantedStart, wantedStart + (end - start), `opening on row ${scrolledWanted.id}`);
72163
72217
  return;
72164
72218
  }
@@ -72204,6 +72258,15 @@ const useListScrollSync = ({
72204
72258
  }
72205
72259
  };
72206
72260
  useLayoutEffect(placeWhereHeld);
72261
+ // Held on a row of a list scrolling the document: where the document goes is
72262
+ // this list's to say, measured on the row, not the url's offset in pixels
72263
+ // (see holdDocumentScroll).
72264
+ useLayoutEffect(() => {
72265
+ if (!heldSomewhere || getScroller() !== document.scrollingElement) {
72266
+ return undefined;
72267
+ }
72268
+ return holdDocumentScroll();
72269
+ }, [heldSomewhere, scrollerElResolved]);
72207
72270
  // What to do when the list's own geometry moves under it, kept fresh for the
72208
72271
  // observer below (which is installed once).
72209
72272
  const onGeometryChangeRef = useRef(null);
@@ -72246,31 +72309,40 @@ const useListScrollSync = ({
72246
72309
  // Where the list was at the last thing that moved it. Kept whether anyone
72247
72310
  // asked for it or not: it is what a resize needs to put things back.
72248
72311
  const positionRef = useRef(null);
72312
+ const captureListAnchor = countVisible => captureScrollAnchor({
72313
+ scrollerEl: getScroller(),
72314
+ listEl: getListEl(),
72315
+ items: listRows.visibleItemsSignal.peek(),
72316
+ horizontal,
72317
+ countVisible
72318
+ });
72319
+ // Said from where the row lands on its own, and with `visibleCount`: the
72320
+ // rows on screen from that one on, which is what a list given this position
72321
+ // back draws first (see ListUI).
72322
+ const toScrolledPosition = position => {
72323
+ const rowEl = findRowElement(getListEl(), position.id);
72324
+ return {
72325
+ id: position.id,
72326
+ index: position.index,
72327
+ offset: position.offset - getRowScrollInset(getScroller(), rowEl, horizontal),
72328
+ visibleCount: position.visibleCount
72329
+ };
72330
+ };
72249
72331
  const reportPosition = () => {
72250
72332
  if (!ref.current) {
72251
72333
  return;
72252
72334
  }
72253
- const position = captureScrollAnchor({
72254
- scrollerEl: getScroller(),
72255
- listEl: getListEl(),
72256
- items: listRows.visibleItemsSignal.peek(),
72257
- horizontal
72258
- });
72335
+ const remember = rememberScrollRef.current;
72336
+ const onScrolledChange = onScrolledChangeRef.current;
72337
+ const position = captureListAnchor(remember || Boolean(onScrolledChange));
72259
72338
  if (!position) {
72260
72339
  return;
72261
72340
  }
72262
72341
  positionRef.current = position;
72263
- const remember = rememberScrollRef.current;
72264
- const onScrolledChange = onScrolledChangeRef.current;
72265
72342
  if (!remember && !onScrolledChange) {
72266
72343
  return;
72267
72344
  }
72268
- const rowEl = findRowElement(getListEl(), position.id);
72269
- const scrolledNow = {
72270
- id: position.id,
72271
- index: position.index,
72272
- offset: position.offset - getRowScrollInset(getScroller(), rowEl, horizontal)
72273
- };
72345
+ const scrolledNow = toScrolledPosition(position);
72274
72346
  if (remember) {
72275
72347
  rememberScrollerPosition(listId, scrolledNow);
72276
72348
  }
@@ -72278,6 +72350,20 @@ const useListScrollSync = ({
72278
72350
  onScrolledChange(scrolledNow);
72279
72351
  }
72280
72352
  };
72353
+ // Nothing scrolled, yet what is on screen changed: the list has just been
72354
+ // laid out, its rows have arrived, one of them grew. A list read where it
72355
+ // opened would otherwise come back with nothing kept — opening again as a
72356
+ // fresh arrival does, all of its window drawn in the first commit instead of
72357
+ // the rows that were on screen. Kept, and told to nobody: nobody scrolled.
72358
+ const rememberPosition = () => {
72359
+ if (!rememberScrollRef.current || !ref.current) {
72360
+ return;
72361
+ }
72362
+ const position = captureListAnchor(true);
72363
+ if (position) {
72364
+ rememberScrollerPosition(listId, toScrolledPosition(position));
72365
+ }
72366
+ };
72281
72367
  // Leaving: with its page, or alone (see forgetScrollerUnlessPageLeft).
72282
72368
  useLayoutEffect(() => {
72283
72369
  return () => {
@@ -72303,6 +72389,7 @@ const useListScrollSync = ({
72303
72389
  // list which has outgrown a bounded ancestor stops holding on to the
72304
72390
  // page.
72305
72391
  resolveScroller();
72392
+ rememberPosition();
72306
72393
  // Two things resize here, and they call for opposite answers. The LIST
72307
72394
  // growing is its own content settling: only a list holding itself
72308
72395
  // somewhere cares (the end it aims at has moved), and a list the user is
@@ -72995,12 +73082,15 @@ const getRowName = rowEl => rowEl.getAttribute("navi-list-item-real");
72995
73082
  // the list is rebuilt around it. Read off the rows' own boxes, not by
72996
73083
  // hit-testing the screen: a scrolling list takes its rows out of hit-testing
72997
73084
  // (see the navi-scrolling rule in the css above), and the scroll event is
72998
- // precisely when this is asked.
73085
+ // precisely when this is asked. `countVisible` adds how many rows are on
73086
+ // screen from that one on: what a list coming back there has to draw before
73087
+ // anything else (see the first paint in ListUI).
72999
73088
  const captureScrollAnchor = ({
73000
73089
  scrollerEl,
73001
73090
  listEl,
73002
73091
  items,
73003
- horizontal
73092
+ horizontal,
73093
+ countVisible
73004
73094
  }) => {
73005
73095
  if (!scrollerEl || !listEl) {
73006
73096
  return null;
@@ -73036,6 +73126,9 @@ const captureScrollAnchor = ({
73036
73126
  offset
73037
73127
  };
73038
73128
  if (offset >= 0) {
73129
+ if (countVisible) {
73130
+ anchor.visibleCount = countRowsStartingBefore(rowEls, i, range.to, horizontal);
73131
+ }
73039
73132
  return anchor;
73040
73133
  }
73041
73134
  // The row under the top of the view starts above it. Good enough to hold
@@ -73044,10 +73137,26 @@ const captureScrollAnchor = ({
73044
73137
  // top" reads, and can be drawn. Keep looking; this one is the fallback.
73045
73138
  if (!fallbackAnchor) {
73046
73139
  fallbackAnchor = anchor;
73140
+ if (countVisible) {
73141
+ anchor.visibleCount = countRowsStartingBefore(rowEls, i, range.to, horizontal);
73142
+ }
73047
73143
  }
73048
73144
  }
73049
73145
  return fallbackAnchor;
73050
73146
  };
73147
+ // How many of the rows from `fromIndex` on start before `to` along the scroll
73148
+ // axis — the ones on screen, when `to` is where the view ends.
73149
+ const countRowsStartingBefore = (rowEls, fromIndex, to, horizontal) => {
73150
+ let index = fromIndex;
73151
+ while (index < rowEls.length) {
73152
+ const rect = rowEls[index].getBoundingClientRect();
73153
+ if ((horizontal ? rect.left : rect.top) >= to) {
73154
+ break;
73155
+ }
73156
+ index++;
73157
+ }
73158
+ return index - fromIndex;
73159
+ };
73051
73160
  // The part of the list that is on screen, along the scrolling axis. Both edges
73052
73161
  // matter: the scroller may be larger than the list (scroller="parent") as well
73053
73162
  // as smaller (the list scrolls inside its own box).
@@ -75403,7 +75512,7 @@ const ListResolved = /*#__PURE__*/createComponentResolver([ListFirstResolver, Li
75403
75512
  * are skeletons, the others hold their room. `0` says the list is already
75404
75513
  * known to be empty: the empty `fallback` shows right away rather than an
75405
75514
  * empty frame.
75406
- * @param {"start"|"end"|number|{id: string, offset?: number}} [props.defaultScrolled="start"]
75515
+ * @param {"start"|"end"|number|{id: string, index?: number, offset?: number, visibleCount?: number}} [props.defaultScrolled="start"]
75407
75516
  * Where the list opens, after which the user owns the scroll — unless it is
75408
75517
  * being come back to (see `scrollResetOnNavigation`). `"end"` is a
75409
75518
  * thread read backwards — the last rows are the ones to show, and the ones
@@ -75415,8 +75524,10 @@ const ListResolved = /*#__PURE__*/createComponentResolver([ListFirstResolver, Li
75415
75524
  * the screen it was saved on. `offset: 0` is where a `scrollIntoView()` puts
75416
75525
  * it — in front of the fixed bar the scroller gives room for, below the
75417
75526
  * sticky header and the group label the row lives under — so nothing of that
75418
- * room has to be restated as a number by whoever asks.
75419
- * @param {"start"|"end"|number|{id: string, offset?: number}} [props.scrolled]
75527
+ * room has to be restated as a number by whoever asks. The `index` and
75528
+ * `visibleCount` it also hands out say where to aim before the row is found,
75529
+ * and how many rows to draw before the first paint (see `renderBudget`).
75530
+ * @param {"start"|"end"|number|{id: string, index?: number, offset?: number, visibleCount?: number}} [props.scrolled]
75420
75531
  * The same, but held: the list goes back there every time this changes, even
75421
75532
  * after the user has scrolled — the caller owns where the list is (see
75422
75533
  * `defaultScrolled` for the uncontrolled form, and `open`/`defaultOpen`
@@ -75427,12 +75538,12 @@ const ListResolved = /*#__PURE__*/createComponentResolver([ListFirstResolver, Li
75427
75538
  * In every form the list holds itself there while it is still finding out
75428
75539
  * how many rows there are and how tall one is, and lets go the moment the
75429
75540
  * user reaches for the list.
75430
- * @param {(scrolled: {id: string, index: number, offset: number}) => void} [props.onScrolledChange]
75541
+ * @param {(scrolled: {id: string, index: number, offset: number, visibleCount: number}) => void} [props.onScrolledChange]
75431
75542
  * Where the list is, as the user scrolls: the row at the top of the view and
75432
75543
  * how far below the place a row lands on its own (see `defaultScrolled`) it
75433
- * starts. Keep it to come back to it
75434
- * later through `scrolled`/`defaultScrolled` — an index would not do, since
75435
- * rows get inserted while a list is being read.
75544
+ * starts, and how many rows are on screen from that one on. Keep it whole to
75545
+ * come back to it later through `scrolled`/`defaultScrolled` — an index alone
75546
+ * would not do, since rows get inserted while a list is being read.
75436
75547
  * @param {number|{initial: number, after: number}} [props.renderBudget=100]
75437
75548
  * How many rows of a `<List.Items>` run are in the DOM at once: the render
75438
75549
  * window, which slides as the user scrolls while fillers hold the room of
@@ -75444,11 +75555,15 @@ const ListResolved = /*#__PURE__*/createComponentResolver([ListFirstResolver, Li
75444
75555
  * once, with room for that lookahead — the list warns below 30, and when a
75445
75556
  * budget leaves fewer than two rows beyond the screen.
75446
75557
  *
75447
- * `{ initial, after }` for a list drawn in the click that opens it (a popup):
75448
- * `initial` rows in the commit the browser paints first — about what a phone
75449
- * screen shows — and `after` from the paint on, where the floor of 30
75450
- * applies. The runs ask their source for `after` rows from the start, so the
75451
- * first picture costs no second request.
75558
+ * `{ initial, after }` for a list whose first picture is taken as it is
75559
+ * built — drawn in the click that opens a popup, or in the update callback
75560
+ * of a route transition bringing its page back: `initial` rows in the commit
75561
+ * the browser paints first — about what a phone screen shows — counted from
75562
+ * the row the list opens on, and `after` from the paint on, around it, where
75563
+ * the floor of 30 applies. Opening on a position that says how many rows were
75564
+ * on screen (`visibleCount`, see `onScrolledChange`) draws those first,
75565
+ * whatever `initial` says. The runs ask their source for `after` rows from
75566
+ * the start, so the first picture costs no second request.
75452
75567
  * @param {number} [props.virtualItemSize]
75453
75568
  * The size of one row along the scroll axis, in px, when every row has the
75454
75569
  * same: what the fillers are sized with and what a scroll position is