@dloizides/ui-layout 1.63.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 +4 -0
- package/dist/index.js +45 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
@@ -3537,7 +3537,6 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
|
|
|
3537
3537
|
// src/SectionIndexLayout/scrollSpy.ts
|
|
3538
3538
|
var SPY_ACTIVATION_RATIO = 0.3;
|
|
3539
3539
|
var SPY_CLICK_LOCK_MS = 900;
|
|
3540
|
-
var PERCENT2 = 100;
|
|
3541
3540
|
function resolveSticky(value) {
|
|
3542
3541
|
if (value === void 0 || value === false) return { sticky: false, spy: false, activationRatio: SPY_ACTIVATION_RATIO, clickLockMs: SPY_CLICK_LOCK_MS };
|
|
3543
3542
|
const config = value === true ? {} : value;
|
|
@@ -3551,8 +3550,10 @@ function resolveSticky(value) {
|
|
|
3551
3550
|
function pickActiveIndex(tops, line) {
|
|
3552
3551
|
return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
|
|
3553
3552
|
}
|
|
3554
|
-
function
|
|
3555
|
-
|
|
3553
|
+
function pickSpyIndex(tops, viewport, activationRatio) {
|
|
3554
|
+
if (viewport.atStart) return 0;
|
|
3555
|
+
if (viewport.atEnd) return Math.max(tops.length - 1, 0);
|
|
3556
|
+
return pickActiveIndex(tops, viewport.top + viewport.height * activationRatio);
|
|
3556
3557
|
}
|
|
3557
3558
|
|
|
3558
3559
|
// src/SectionIndexLayout/sectionKeys.ts
|
|
@@ -3570,11 +3571,38 @@ function scrollToSection(anchorId) {
|
|
|
3570
3571
|
const target = document.getElementById(anchorId);
|
|
3571
3572
|
target?.scrollIntoView?.({ behavior: "smooth", block: "start" });
|
|
3572
3573
|
}
|
|
3574
|
+
|
|
3575
|
+
// src/SectionIndexLayout/scrollViewport.ts
|
|
3576
|
+
var SCROLLABLE_OVERFLOW = /^(auto|scroll|overlay)$/;
|
|
3577
|
+
var END_TOLERANCE_PX = 2;
|
|
3578
|
+
function scrollParent(element) {
|
|
3579
|
+
for (let node = element.parentElement; node !== null; node = node.parentElement) {
|
|
3580
|
+
if (SCROLLABLE_OVERFLOW.test(getComputedStyle(node).overflowY) && node.scrollHeight > node.clientHeight) return node;
|
|
3581
|
+
}
|
|
3582
|
+
return null;
|
|
3583
|
+
}
|
|
3584
|
+
function isAtStart(scrolled) {
|
|
3585
|
+
return scrolled <= 0;
|
|
3586
|
+
}
|
|
3587
|
+
function isAtEnd(scrolled, visible, total) {
|
|
3588
|
+
return scrolled > 0 && scrolled + visible >= total - END_TOLERANCE_PX;
|
|
3589
|
+
}
|
|
3590
|
+
function scrollViewport(anchor) {
|
|
3591
|
+
const parent = scrollParent(anchor);
|
|
3592
|
+
if (parent === null) {
|
|
3593
|
+
const root = document.scrollingElement ?? document.documentElement;
|
|
3594
|
+
return { top: 0, height: window.innerHeight, atStart: isAtStart(window.scrollY), atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
|
|
3595
|
+
}
|
|
3596
|
+
return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atStart: isAtStart(parent.scrollTop), atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
// src/SectionIndexLayout/useScrollSpy.ts
|
|
3573
3600
|
var UNPRIMED = -2;
|
|
3574
3601
|
var STALE = -1;
|
|
3575
3602
|
var ID_SEPARATOR = "\n";
|
|
3603
|
+
var LISTEN_OPTIONS = { capture: true, passive: true };
|
|
3576
3604
|
function canObserve() {
|
|
3577
|
-
return typeof document !== "undefined" && typeof window !== "undefined"
|
|
3605
|
+
return typeof document !== "undefined" && typeof window !== "undefined";
|
|
3578
3606
|
}
|
|
3579
3607
|
function findAnchors(ids) {
|
|
3580
3608
|
return ids.flatMap((id, index) => {
|
|
@@ -3591,20 +3619,25 @@ function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
|
|
|
3591
3619
|
React16.useEffect(() => {
|
|
3592
3620
|
if (!enabled || !canObserve()) return void 0;
|
|
3593
3621
|
const anchors = findAnchors(idsKey.split(ID_SEPARATOR));
|
|
3594
|
-
|
|
3622
|
+
const first = anchors[0];
|
|
3623
|
+
if (first === void 0 || anchors.length < 2) return void 0;
|
|
3595
3624
|
last.current = UNPRIMED;
|
|
3596
3625
|
const evaluate = () => {
|
|
3597
3626
|
if (Date.now() < pausedUntil.current) return;
|
|
3598
|
-
const
|
|
3627
|
+
const tops = anchors.map((anchor) => anchor.element.getBoundingClientRect().top);
|
|
3628
|
+
const picked = pickSpyIndex(tops, scrollViewport(first.element), activationRatio);
|
|
3599
3629
|
const index = anchors[picked]?.index ?? 0;
|
|
3600
|
-
const primed = last.current !== UNPRIMED;
|
|
3601
3630
|
if (index === last.current) return;
|
|
3602
3631
|
last.current = index;
|
|
3603
|
-
|
|
3632
|
+
onActiveRef.current(index);
|
|
3633
|
+
};
|
|
3634
|
+
document.addEventListener("scroll", evaluate, LISTEN_OPTIONS);
|
|
3635
|
+
window.addEventListener("resize", evaluate, LISTEN_OPTIONS);
|
|
3636
|
+
evaluate();
|
|
3637
|
+
return () => {
|
|
3638
|
+
document.removeEventListener("scroll", evaluate, LISTEN_OPTIONS);
|
|
3639
|
+
window.removeEventListener("resize", evaluate, LISTEN_OPTIONS);
|
|
3604
3640
|
};
|
|
3605
|
-
const observer = new IntersectionObserver(evaluate, { rootMargin: spyRootMargin(activationRatio), threshold: 0 });
|
|
3606
|
-
anchors.forEach((anchor) => observer.observe(anchor.element));
|
|
3607
|
-
return () => observer.disconnect();
|
|
3608
3641
|
}, [enabled, activationRatio, idsKey]);
|
|
3609
3642
|
const pause = React16.useCallback((ms) => {
|
|
3610
3643
|
pausedUntil.current = Date.now() + ms;
|
|
@@ -3665,7 +3698,7 @@ var SectionIndexLayout = ({
|
|
|
3665
3698
|
const wide = useIsWideViewport(fold.wide);
|
|
3666
3699
|
const stacked = useIsWideViewport(fold.stackFrom);
|
|
3667
3700
|
const sticky = resolveSticky(stickyIndex);
|
|
3668
|
-
const preferredKey = wide ? initialKey : collapsedKey
|
|
3701
|
+
const preferredKey = wide ? initialKey : collapsedKey;
|
|
3669
3702
|
const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
|
|
3670
3703
|
const dense = density === "dense" /* Dense */;
|
|
3671
3704
|
const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };
|