@dloizides/ui-layout 1.64.0 → 1.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.65.0
4
+
5
+ - MODC-1 "Module C unified console" scroll-0 fix. With the scroll spy on, the scroller at its top marks the first section current, even when `initialKey` names a later one or a short first section lets the second cross the activation line (`ScrollViewport` gains `atStart`). The collapsed (chips) layout opens on `collapsedKey` only, else the first chip; `initialKey` no longer applies below the index breakpoint.
6
+
3
7
  ## 1.60.1
4
8
 
5
9
  - Ships the 1.60.0 `SectionIndexLayout` `collapsedKey` change; 1.60.0 never reached npm (its test used a wrong index testID).
package/dist/index.js CHANGED
@@ -3551,6 +3551,7 @@ function pickActiveIndex(tops, line) {
3551
3551
  return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
3552
3552
  }
3553
3553
  function pickSpyIndex(tops, viewport, activationRatio) {
3554
+ if (viewport.atStart) return 0;
3554
3555
  if (viewport.atEnd) return Math.max(tops.length - 1, 0);
3555
3556
  return pickActiveIndex(tops, viewport.top + viewport.height * activationRatio);
3556
3557
  }
@@ -3580,6 +3581,9 @@ function scrollParent(element) {
3580
3581
  }
3581
3582
  return null;
3582
3583
  }
3584
+ function isAtStart(scrolled) {
3585
+ return scrolled <= 0;
3586
+ }
3583
3587
  function isAtEnd(scrolled, visible, total) {
3584
3588
  return scrolled > 0 && scrolled + visible >= total - END_TOLERANCE_PX;
3585
3589
  }
@@ -3587,9 +3591,9 @@ function scrollViewport(anchor) {
3587
3591
  const parent = scrollParent(anchor);
3588
3592
  if (parent === null) {
3589
3593
  const root = document.scrollingElement ?? document.documentElement;
3590
- return { top: 0, height: window.innerHeight, atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
3594
+ return { top: 0, height: window.innerHeight, atStart: isAtStart(window.scrollY), atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
3591
3595
  }
3592
- return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
3596
+ return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atStart: isAtStart(parent.scrollTop), atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
3593
3597
  }
3594
3598
 
3595
3599
  // src/SectionIndexLayout/useScrollSpy.ts
@@ -3623,10 +3627,9 @@ function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
3623
3627
  const tops = anchors.map((anchor) => anchor.element.getBoundingClientRect().top);
3624
3628
  const picked = pickSpyIndex(tops, scrollViewport(first.element), activationRatio);
3625
3629
  const index = anchors[picked]?.index ?? 0;
3626
- const primed = last.current !== UNPRIMED;
3627
3630
  if (index === last.current) return;
3628
3631
  last.current = index;
3629
- if (primed || index > 0) onActiveRef.current(index);
3632
+ onActiveRef.current(index);
3630
3633
  };
3631
3634
  document.addEventListener("scroll", evaluate, LISTEN_OPTIONS);
3632
3635
  window.addEventListener("resize", evaluate, LISTEN_OPTIONS);
@@ -3695,7 +3698,7 @@ var SectionIndexLayout = ({
3695
3698
  const wide = useIsWideViewport(fold.wide);
3696
3699
  const stacked = useIsWideViewport(fold.stackFrom);
3697
3700
  const sticky = resolveSticky(stickyIndex);
3698
- const preferredKey = wide ? initialKey : collapsedKey ?? initialKey;
3701
+ const preferredKey = wide ? initialKey : collapsedKey;
3699
3702
  const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
3700
3703
  const dense = density === "dense" /* Dense */;
3701
3704
  const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };