@dloizides/ui-layout 1.62.0 → 1.63.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.d.mts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +136 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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 ?
|
|
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
|
+
var PERCENT2 = 100;
|
|
3535
|
+
function resolveSticky(value) {
|
|
3536
|
+
if (value === void 0 || value === false) return { sticky: false, spy: false, activationRatio: SPY_ACTIVATION_RATIO, clickLockMs: SPY_CLICK_LOCK_MS };
|
|
3537
|
+
const config = value === true ? {} : value;
|
|
3538
|
+
return {
|
|
3539
|
+
sticky: true,
|
|
3540
|
+
spy: config.scrollSpy ?? true,
|
|
3541
|
+
activationRatio: config.activationRatio ?? SPY_ACTIVATION_RATIO,
|
|
3542
|
+
clickLockMs: config.clickLockMs ?? SPY_CLICK_LOCK_MS
|
|
3543
|
+
};
|
|
3544
|
+
}
|
|
3545
|
+
function pickActiveIndex(tops, line) {
|
|
3546
|
+
return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
|
|
3547
|
+
}
|
|
3548
|
+
function spyRootMargin(activationRatio) {
|
|
3549
|
+
return `0px 0px -${Math.round((1 - activationRatio) * PERCENT2)}% 0px`;
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3493
3552
|
// src/SectionIndexLayout/sectionKeys.ts
|
|
3494
3553
|
var SECTION_INDEX_BREAKPOINT = 1024;
|
|
3495
3554
|
function resolveActiveKey(sections, wanted) {
|
|
@@ -3505,6 +3564,70 @@ function scrollToSection(anchorId) {
|
|
|
3505
3564
|
const target = document.getElementById(anchorId);
|
|
3506
3565
|
target?.scrollIntoView?.({ behavior: "smooth", block: "start" });
|
|
3507
3566
|
}
|
|
3567
|
+
var UNPRIMED = -2;
|
|
3568
|
+
var STALE = -1;
|
|
3569
|
+
var ID_SEPARATOR = "\n";
|
|
3570
|
+
function canObserve() {
|
|
3571
|
+
return typeof document !== "undefined" && typeof window !== "undefined" && typeof IntersectionObserver !== "undefined";
|
|
3572
|
+
}
|
|
3573
|
+
function findAnchors(ids) {
|
|
3574
|
+
return ids.flatMap((id, index) => {
|
|
3575
|
+
const element = document.getElementById(id);
|
|
3576
|
+
return element === null ? [] : [{ index, element }];
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
|
|
3580
|
+
const onActiveRef = useRef(onActive);
|
|
3581
|
+
onActiveRef.current = onActive;
|
|
3582
|
+
const pausedUntil = useRef(0);
|
|
3583
|
+
const last = useRef(UNPRIMED);
|
|
3584
|
+
const idsKey = anchorIds.join(ID_SEPARATOR);
|
|
3585
|
+
useEffect(() => {
|
|
3586
|
+
if (!enabled || !canObserve()) return void 0;
|
|
3587
|
+
const anchors = findAnchors(idsKey.split(ID_SEPARATOR));
|
|
3588
|
+
if (anchors.length < 2) return void 0;
|
|
3589
|
+
last.current = UNPRIMED;
|
|
3590
|
+
const evaluate = () => {
|
|
3591
|
+
if (Date.now() < pausedUntil.current) return;
|
|
3592
|
+
const picked = pickActiveIndex(anchors.map((anchor) => anchor.element.getBoundingClientRect().top), window.innerHeight * activationRatio);
|
|
3593
|
+
const index = anchors[picked]?.index ?? 0;
|
|
3594
|
+
const primed = last.current !== UNPRIMED;
|
|
3595
|
+
if (index === last.current) return;
|
|
3596
|
+
last.current = index;
|
|
3597
|
+
if (primed || index > 0) onActiveRef.current(index);
|
|
3598
|
+
};
|
|
3599
|
+
const observer = new IntersectionObserver(evaluate, { rootMargin: spyRootMargin(activationRatio), threshold: 0 });
|
|
3600
|
+
anchors.forEach((anchor) => observer.observe(anchor.element));
|
|
3601
|
+
return () => observer.disconnect();
|
|
3602
|
+
}, [enabled, activationRatio, idsKey]);
|
|
3603
|
+
const pause = useCallback((ms) => {
|
|
3604
|
+
pausedUntil.current = Date.now() + ms;
|
|
3605
|
+
last.current = STALE;
|
|
3606
|
+
}, []);
|
|
3607
|
+
return useMemo(() => ({ pause }), [pause]);
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
// src/SectionIndexLayout/useSectionSelection.ts
|
|
3611
|
+
function useSectionSelection({ sections, testID, preferredKey, spyEnabled, sticky }) {
|
|
3612
|
+
const [current, setCurrent] = useState(void 0);
|
|
3613
|
+
const spy = useScrollSpy({
|
|
3614
|
+
anchorIds: sections.map((entry) => sectionAnchorId(testID, entry.key)),
|
|
3615
|
+
enabled: spyEnabled && sticky.spy,
|
|
3616
|
+
activationRatio: sticky.activationRatio,
|
|
3617
|
+
onActive: (index) => setCurrent(sections[index]?.key)
|
|
3618
|
+
});
|
|
3619
|
+
const { pause } = spy;
|
|
3620
|
+
const { clickLockMs } = sticky;
|
|
3621
|
+
const select = useCallback(
|
|
3622
|
+
(key) => {
|
|
3623
|
+
setCurrent(key);
|
|
3624
|
+
pause(clickLockMs);
|
|
3625
|
+
scrollToSection(sectionAnchorId(testID, key));
|
|
3626
|
+
},
|
|
3627
|
+
[pause, clickLockMs, testID]
|
|
3628
|
+
);
|
|
3629
|
+
return { activeKey: resolveActiveKey(sections, current ?? preferredKey), pick: setCurrent, select };
|
|
3630
|
+
}
|
|
3508
3631
|
var COMFORTABLE_GAP = 12;
|
|
3509
3632
|
var DENSE_GAP = 8;
|
|
3510
3633
|
var DENSE_WIDE_GAP = 16;
|
|
@@ -3535,8 +3658,9 @@ var SectionIndexLayout = ({
|
|
|
3535
3658
|
const fold = toFold(breakpoint);
|
|
3536
3659
|
const wide = useIsWideViewport(fold.wide);
|
|
3537
3660
|
const stacked = useIsWideViewport(fold.stackFrom);
|
|
3538
|
-
const
|
|
3539
|
-
const
|
|
3661
|
+
const sticky = resolveSticky(stickyIndex);
|
|
3662
|
+
const preferredKey = wide ? initialKey : collapsedKey ?? initialKey;
|
|
3663
|
+
const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
|
|
3540
3664
|
const dense = density === "dense" /* Dense */;
|
|
3541
3665
|
const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };
|
|
3542
3666
|
if (sections.length < 2) return /* @__PURE__ */ jsx(View, { testID, children: sections[0]?.content });
|
|
@@ -3555,19 +3679,15 @@ var SectionIndexLayout = ({
|
|
|
3555
3679
|
overflow: chipOverflow,
|
|
3556
3680
|
sections,
|
|
3557
3681
|
testID,
|
|
3558
|
-
onSelect:
|
|
3682
|
+
onSelect: pick
|
|
3559
3683
|
}
|
|
3560
3684
|
),
|
|
3561
3685
|
/* @__PURE__ */ jsx(View, { nativeID: sectionAnchorId(testID, activeKey), testID: sectionAnchorId(testID, activeKey), children: active?.content })
|
|
3562
3686
|
] });
|
|
3563
3687
|
}
|
|
3564
|
-
const
|
|
3565
|
-
setPicked(key);
|
|
3566
|
-
scrollToSection(sectionAnchorId(testID, key));
|
|
3567
|
-
};
|
|
3568
|
-
const sticky = stickyIndex && Platform.OS === "web" ? WEB_STICKY : null;
|
|
3688
|
+
const stickyStyle = sticky.sticky && Platform.OS === "web" ? WEB_STICKY : null;
|
|
3569
3689
|
return /* @__PURE__ */ jsxs(View, { style: [styles31.wide, dense && { gap: DENSE_WIDE_GAP }], testID, children: [
|
|
3570
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
3690
|
+
/* @__PURE__ */ jsx(View, { style: stickyStyle, children: /* @__PURE__ */ jsx(SectionIndex, { activeColor, activeKey, dense, heading: indexHeading, itemHint, sections, testID, width: indexWidth, onSelect: select }) }),
|
|
3571
3691
|
/* @__PURE__ */ jsx(SectionColumn, { sections, style: StyleSheet.flatten([styles31.column, gap]), testID })
|
|
3572
3692
|
] });
|
|
3573
3693
|
};
|
|
@@ -4185,6 +4305,6 @@ var ListDetailLayout = ({
|
|
|
4185
4305
|
return /* @__PURE__ */ jsx(SplitPanes, { end: null, layout: "stack" /* Stack */, start: panes.detail ? detail : list, testID });
|
|
4186
4306
|
};
|
|
4187
4307
|
|
|
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 };
|
|
4308
|
+
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
4309
|
//# sourceMappingURL=index.mjs.map
|
|
4190
4310
|
//# sourceMappingURL=index.mjs.map
|