@dloizides/ui-layout 1.62.0 → 1.64.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/dist/index.mjs CHANGED
@@ -3444,6 +3444,39 @@ var SectionDensity = /* @__PURE__ */ ((SectionDensity2) => {
3444
3444
  SectionDensity2["Dense"] = "dense";
3445
3445
  return SectionDensity2;
3446
3446
  })(SectionDensity || {});
3447
+ var INDICATOR_MS = 180;
3448
+ var slide = (value, toValue) => Animated.timing(value, { toValue, duration: INDICATOR_MS, easing: Easing.out(Easing.cubic), useNativeDriver: false });
3449
+ function useSlidingIndicator(activeIndex) {
3450
+ const reduced = useReducedMotion();
3451
+ const [rows, setRows] = useState([]);
3452
+ const top = useRef(new Animated.Value(0)).current;
3453
+ const height = useRef(new Animated.Value(0)).current;
3454
+ const placed = useRef(false);
3455
+ const targetY = rows[activeIndex]?.y;
3456
+ const targetHeight = rows[activeIndex]?.height;
3457
+ useEffect(() => {
3458
+ if (targetY === void 0 || targetHeight === void 0) return;
3459
+ if (reduced || !placed.current) {
3460
+ top.setValue(targetY);
3461
+ height.setValue(targetHeight);
3462
+ placed.current = true;
3463
+ return;
3464
+ }
3465
+ Animated.parallel([slide(top, targetY), slide(height, targetHeight)]).start();
3466
+ }, [targetY, targetHeight, reduced, top, height]);
3467
+ const onRowLayout = useCallback(
3468
+ (index) => (event) => {
3469
+ const { y, height: rowHeight } = event.nativeEvent.layout;
3470
+ setRows((prev) => {
3471
+ const next = [...prev];
3472
+ next[index] = { y, height: rowHeight };
3473
+ return next;
3474
+ });
3475
+ },
3476
+ []
3477
+ );
3478
+ return { measured: targetY !== void 0, top, height, onRowLayout };
3479
+ }
3447
3480
  var SECTION_INDEX_WIDTH = 200;
3448
3481
  var ACTIVE_BAR = 3;
3449
3482
  var TRANSPARENT3 = "transparent";
@@ -3459,7 +3492,8 @@ var styles30 = StyleSheet.create({
3459
3492
  denseHeading: { fontSize: 11, fontWeight: "600", letterSpacing: 0.66, lineHeight: 16, paddingBottom: 6 },
3460
3493
  denseItem: { minHeight: DENSE_TARGET_PX, paddingVertical: 6, paddingLeft: 7, paddingRight: 10, borderRadius: 7 },
3461
3494
  denseLabel: { fontSize: 13, lineHeight: DENSE_LINE },
3462
- denseLabelActive: { fontWeight: "600" }
3495
+ denseLabelActive: { fontWeight: "600" },
3496
+ indicator: { position: "absolute", left: 0, width: ACTIVE_BAR, borderRadius: ACTIVE_BAR }
3463
3497
  });
3464
3498
  function ariaCurrent(active) {
3465
3499
  return active ? { "aria-current": "location" } : {};
@@ -3468,9 +3502,12 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3468
3502
  const { theme } = useUi();
3469
3503
  const { colors } = theme;
3470
3504
  const bar = activeColor ?? colors.text;
3505
+ const indicator = useSlidingIndicator(sections.findIndex((entry) => entry.key === activeKey));
3506
+ const staticBar = indicator.measured ? TRANSPARENT3 : bar;
3471
3507
  return /* @__PURE__ */ jsxs(View, { role: "navigation", accessibilityLabel: heading, style: [styles30.root, dense && styles30.denseRoot, { width }], testID: `${testID}-index`, children: [
3508
+ indicator.measured ? /* @__PURE__ */ jsx(Animated.View, { pointerEvents: "none", style: [styles30.indicator, { backgroundColor: bar, top: indicator.top, height: indicator.height }], testID: `${testID}-index-indicator` }) : null,
3472
3509
  /* @__PURE__ */ jsx(Text, { style: [styles30.heading, dense && styles30.denseHeading, { color: colors.textSecondary }], children: heading }),
3473
- sections.map((entry) => {
3510
+ sections.map((entry, index) => {
3474
3511
  const active = entry.key === activeKey;
3475
3512
  return /* @__PURE__ */ jsx(
3476
3513
  Pressable,
@@ -3479,8 +3516,9 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3479
3516
  accessibilityRole: "link",
3480
3517
  accessibilityLabel: entry.title,
3481
3518
  accessibilityHint: itemHint,
3482
- style: [styles30.item, dense && styles30.denseItem, { borderLeftColor: active ? bar : TRANSPARENT3, backgroundColor: active ? colors.surface : TRANSPARENT3 }],
3519
+ style: [styles30.item, dense && styles30.denseItem, { borderLeftColor: active ? staticBar : TRANSPARENT3, backgroundColor: active ? colors.surface : TRANSPARENT3 }],
3483
3520
  testID: `${testID}-index-${entry.key}`,
3521
+ onLayout: indicator.onRowLayout(index),
3484
3522
  onPress: () => onSelect(entry.key),
3485
3523
  children: /* @__PURE__ */ jsx(Text, { style: [styles30.label, active && styles30.labelActive, dense && styles30.denseLabel, dense && active && styles30.denseLabelActive, { color: active ? colors.text : colors.textSecondary }], children: entry.title })
3486
3524
  },
@@ -3490,6 +3528,27 @@ var SectionIndex = ({ sections, activeKey, heading, itemHint, onSelect, testID,
3490
3528
  ] });
3491
3529
  };
3492
3530
 
3531
+ // src/SectionIndexLayout/scrollSpy.ts
3532
+ var SPY_ACTIVATION_RATIO = 0.3;
3533
+ var SPY_CLICK_LOCK_MS = 900;
3534
+ function resolveSticky(value) {
3535
+ if (value === void 0 || value === false) return { sticky: false, spy: false, activationRatio: SPY_ACTIVATION_RATIO, clickLockMs: SPY_CLICK_LOCK_MS };
3536
+ const config = value === true ? {} : value;
3537
+ return {
3538
+ sticky: true,
3539
+ spy: config.scrollSpy ?? true,
3540
+ activationRatio: config.activationRatio ?? SPY_ACTIVATION_RATIO,
3541
+ clickLockMs: config.clickLockMs ?? SPY_CLICK_LOCK_MS
3542
+ };
3543
+ }
3544
+ function pickActiveIndex(tops, line) {
3545
+ return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
3546
+ }
3547
+ function pickSpyIndex(tops, viewport, activationRatio) {
3548
+ if (viewport.atEnd) return Math.max(tops.length - 1, 0);
3549
+ return pickActiveIndex(tops, viewport.top + viewport.height * activationRatio);
3550
+ }
3551
+
3493
3552
  // src/SectionIndexLayout/sectionKeys.ts
3494
3553
  var SECTION_INDEX_BREAKPOINT = 1024;
3495
3554
  function resolveActiveKey(sections, wanted) {
@@ -3505,6 +3564,100 @@ function scrollToSection(anchorId) {
3505
3564
  const target = document.getElementById(anchorId);
3506
3565
  target?.scrollIntoView?.({ behavior: "smooth", block: "start" });
3507
3566
  }
3567
+
3568
+ // src/SectionIndexLayout/scrollViewport.ts
3569
+ var SCROLLABLE_OVERFLOW = /^(auto|scroll|overlay)$/;
3570
+ var END_TOLERANCE_PX = 2;
3571
+ function scrollParent(element) {
3572
+ for (let node = element.parentElement; node !== null; node = node.parentElement) {
3573
+ if (SCROLLABLE_OVERFLOW.test(getComputedStyle(node).overflowY) && node.scrollHeight > node.clientHeight) return node;
3574
+ }
3575
+ return null;
3576
+ }
3577
+ function isAtEnd(scrolled, visible, total) {
3578
+ return scrolled > 0 && scrolled + visible >= total - END_TOLERANCE_PX;
3579
+ }
3580
+ function scrollViewport(anchor) {
3581
+ const parent = scrollParent(anchor);
3582
+ if (parent === null) {
3583
+ const root = document.scrollingElement ?? document.documentElement;
3584
+ return { top: 0, height: window.innerHeight, atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
3585
+ }
3586
+ return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
3587
+ }
3588
+
3589
+ // src/SectionIndexLayout/useScrollSpy.ts
3590
+ var UNPRIMED = -2;
3591
+ var STALE = -1;
3592
+ var ID_SEPARATOR = "\n";
3593
+ var LISTEN_OPTIONS = { capture: true, passive: true };
3594
+ function canObserve() {
3595
+ return typeof document !== "undefined" && typeof window !== "undefined";
3596
+ }
3597
+ function findAnchors(ids) {
3598
+ return ids.flatMap((id, index) => {
3599
+ const element = document.getElementById(id);
3600
+ return element === null ? [] : [{ index, element }];
3601
+ });
3602
+ }
3603
+ function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
3604
+ const onActiveRef = useRef(onActive);
3605
+ onActiveRef.current = onActive;
3606
+ const pausedUntil = useRef(0);
3607
+ const last = useRef(UNPRIMED);
3608
+ const idsKey = anchorIds.join(ID_SEPARATOR);
3609
+ useEffect(() => {
3610
+ if (!enabled || !canObserve()) return void 0;
3611
+ const anchors = findAnchors(idsKey.split(ID_SEPARATOR));
3612
+ const first = anchors[0];
3613
+ if (first === void 0 || anchors.length < 2) return void 0;
3614
+ last.current = UNPRIMED;
3615
+ const evaluate = () => {
3616
+ if (Date.now() < pausedUntil.current) return;
3617
+ const tops = anchors.map((anchor) => anchor.element.getBoundingClientRect().top);
3618
+ const picked = pickSpyIndex(tops, scrollViewport(first.element), activationRatio);
3619
+ const index = anchors[picked]?.index ?? 0;
3620
+ const primed = last.current !== UNPRIMED;
3621
+ if (index === last.current) return;
3622
+ last.current = index;
3623
+ if (primed || index > 0) onActiveRef.current(index);
3624
+ };
3625
+ document.addEventListener("scroll", evaluate, LISTEN_OPTIONS);
3626
+ window.addEventListener("resize", evaluate, LISTEN_OPTIONS);
3627
+ evaluate();
3628
+ return () => {
3629
+ document.removeEventListener("scroll", evaluate, LISTEN_OPTIONS);
3630
+ window.removeEventListener("resize", evaluate, LISTEN_OPTIONS);
3631
+ };
3632
+ }, [enabled, activationRatio, idsKey]);
3633
+ const pause = useCallback((ms) => {
3634
+ pausedUntil.current = Date.now() + ms;
3635
+ last.current = STALE;
3636
+ }, []);
3637
+ return useMemo(() => ({ pause }), [pause]);
3638
+ }
3639
+
3640
+ // src/SectionIndexLayout/useSectionSelection.ts
3641
+ function useSectionSelection({ sections, testID, preferredKey, spyEnabled, sticky }) {
3642
+ const [current, setCurrent] = useState(void 0);
3643
+ const spy = useScrollSpy({
3644
+ anchorIds: sections.map((entry) => sectionAnchorId(testID, entry.key)),
3645
+ enabled: spyEnabled && sticky.spy,
3646
+ activationRatio: sticky.activationRatio,
3647
+ onActive: (index) => setCurrent(sections[index]?.key)
3648
+ });
3649
+ const { pause } = spy;
3650
+ const { clickLockMs } = sticky;
3651
+ const select = useCallback(
3652
+ (key) => {
3653
+ setCurrent(key);
3654
+ pause(clickLockMs);
3655
+ scrollToSection(sectionAnchorId(testID, key));
3656
+ },
3657
+ [pause, clickLockMs, testID]
3658
+ );
3659
+ return { activeKey: resolveActiveKey(sections, current ?? preferredKey), pick: setCurrent, select };
3660
+ }
3508
3661
  var COMFORTABLE_GAP = 12;
3509
3662
  var DENSE_GAP = 8;
3510
3663
  var DENSE_WIDE_GAP = 16;
@@ -3535,8 +3688,9 @@ var SectionIndexLayout = ({
3535
3688
  const fold = toFold(breakpoint);
3536
3689
  const wide = useIsWideViewport(fold.wide);
3537
3690
  const stacked = useIsWideViewport(fold.stackFrom);
3538
- const [picked, setPicked] = useState(void 0);
3539
- const activeKey = resolveActiveKey(sections, picked ?? (wide ? initialKey : collapsedKey ?? initialKey));
3691
+ const sticky = resolveSticky(stickyIndex);
3692
+ const preferredKey = wide ? initialKey : collapsedKey ?? initialKey;
3693
+ const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
3540
3694
  const dense = density === "dense" /* Dense */;
3541
3695
  const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };
3542
3696
  if (sections.length < 2) return /* @__PURE__ */ jsx(View, { testID, children: sections[0]?.content });
@@ -3555,19 +3709,15 @@ var SectionIndexLayout = ({
3555
3709
  overflow: chipOverflow,
3556
3710
  sections,
3557
3711
  testID,
3558
- onSelect: setPicked
3712
+ onSelect: pick
3559
3713
  }
3560
3714
  ),
3561
3715
  /* @__PURE__ */ jsx(View, { nativeID: sectionAnchorId(testID, activeKey), testID: sectionAnchorId(testID, activeKey), children: active?.content })
3562
3716
  ] });
3563
3717
  }
3564
- const select = (key) => {
3565
- setPicked(key);
3566
- scrollToSection(sectionAnchorId(testID, key));
3567
- };
3568
- const sticky = stickyIndex && Platform.OS === "web" ? WEB_STICKY : null;
3718
+ const stickyStyle = sticky.sticky && Platform.OS === "web" ? WEB_STICKY : null;
3569
3719
  return /* @__PURE__ */ jsxs(View, { style: [styles31.wide, dense && { gap: DENSE_WIDE_GAP }], testID, children: [
3570
- /* @__PURE__ */ jsx(View, { style: sticky, children: /* @__PURE__ */ jsx(SectionIndex, { activeColor, activeKey, dense, heading: indexHeading, itemHint, sections, testID, width: indexWidth, onSelect: select }) }),
3720
+ /* @__PURE__ */ jsx(View, { style: stickyStyle, children: /* @__PURE__ */ jsx(SectionIndex, { activeColor, activeKey, dense, heading: indexHeading, itemHint, sections, testID, width: indexWidth, onSelect: select }) }),
3571
3721
  /* @__PURE__ */ jsx(SectionColumn, { sections, style: StyleSheet.flatten([styles31.column, gap]), testID })
3572
3722
  ] });
3573
3723
  };
@@ -4185,6 +4335,6 @@ var ListDetailLayout = ({
4185
4335
  return /* @__PURE__ */ jsx(SplitPanes, { end: null, layout: "stack" /* Stack */, start: panes.detail ? detail : list, testID });
4186
4336
  };
4187
4337
 
4188
- export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeSize, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyControl, CopyRowEmphasis, CopyStatus, CopyValueRow, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayBadgeFill, DayCard, DayCardLayout, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListDetailLayout, ListDetailPane, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, PageHead, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, SECTION_INDEX_WIDTH, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SegmentedVariant, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyActionBar, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TabsVariant, TextKind, Timeline, ToggleSection, TotalsStrip, TotalsTone, TransferSlip, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyActionLabel, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, resolveActiveKey, resolveListDetailPanes, resolveRowLook, resolveTintColors, resolveToneColors, rowSelection, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
4338
+ export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeSize, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyControl, CopyRowEmphasis, CopyStatus, CopyValueRow, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayBadgeFill, DayCard, DayCardLayout, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListDetailLayout, ListDetailPane, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, PageHead, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, SECTION_INDEX_WIDTH, SPY_ACTIVATION_RATIO, SPY_CLICK_LOCK_MS, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SegmentedVariant, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyActionBar, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TabsVariant, TextKind, Timeline, ToggleSection, TotalsStrip, TotalsTone, TransferSlip, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyActionLabel, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, pickActiveIndex, resolveActiveKey, resolveListDetailPanes, resolveRowLook, resolveTintColors, resolveToneColors, rowSelection, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useScrollSpy, useVisibleViewport };
4189
4339
  //# sourceMappingURL=index.mjs.map
4190
4340
  //# sourceMappingURL=index.mjs.map