@yahoo/uds 3.114.0-beta.2 → 3.114.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/automated-config/dist/generated/autoVariants.cjs +3 -0
- package/dist/automated-config/dist/generated/autoVariants.d.cts +3 -0
- package/dist/automated-config/dist/generated/autoVariants.d.ts +3 -0
- package/dist/automated-config/dist/generated/autoVariants.js +3 -0
- package/dist/automated-config/dist/generated/generatedConfigs.cjs +1883 -0
- package/dist/automated-config/dist/generated/generatedConfigs.d.cts +175 -1
- package/dist/automated-config/dist/generated/generatedConfigs.d.ts +175 -1
- package/dist/automated-config/dist/generated/generatedConfigs.js +1882 -1
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.cjs +84 -0
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.cts +3 -1
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.ts +3 -1
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.js +84 -0
- package/dist/automated-config/dist/mapTextVariantFixtureToValue.cjs +1 -12
- package/dist/automated-config/dist/mapTextVariantFixtureToValue.js +1 -12
- package/dist/automated-config/dist/properties.cjs +58 -12
- package/dist/automated-config/dist/properties.d.cts +8 -0
- package/dist/automated-config/dist/properties.d.ts +8 -0
- package/dist/automated-config/dist/properties.js +58 -12
- package/dist/automated-config/dist/utils/getConfigVariantProperties.d.cts +2 -2
- package/dist/automated-config/dist/utils/getConfigVariantProperties.d.ts +2 -2
- package/dist/cli/commands/sync.cjs +7 -1
- package/dist/cli/commands/sync.d.cts +1 -1
- package/dist/cli/commands/sync.d.ts +1 -1
- package/dist/cli/commands/sync.js +7 -1
- package/dist/cli/commands/version.cjs +2 -0
- package/dist/cli/commands/version.d.cts +1 -1
- package/dist/cli/commands/version.d.ts +1 -1
- package/dist/cli/commands/version.js +2 -0
- package/dist/cli/dist/cli.cjs +1 -1
- package/dist/cli/dist/cli.js +1 -1
- package/dist/cli/dist/commands/editor-rules.cjs +2 -2
- package/dist/cli/dist/commands/editor-rules.js +2 -2
- package/dist/cli/dist/utils/rules/config.cjs +1 -1
- package/dist/cli/dist/utils/rules/config.js +1 -1
- package/dist/cli/runner.cjs +2 -11
- package/dist/cli/runner.js +2 -11
- package/dist/components/Scrim.cjs +28 -0
- package/dist/components/Scrim.d.cts +14 -0
- package/dist/components/Scrim.d.ts +14 -0
- package/dist/components/Scrim.js +26 -0
- package/dist/components/client/BottomSheet/BottomSheet.cjs +209 -0
- package/dist/components/client/BottomSheet/BottomSheet.d.cts +77 -0
- package/dist/components/client/BottomSheet/BottomSheet.d.ts +77 -0
- package/dist/components/client/BottomSheet/BottomSheet.js +207 -0
- package/dist/components/client/BottomSheet/BottomSheetContent.cjs +26 -0
- package/dist/components/client/BottomSheet/BottomSheetContent.d.cts +15 -0
- package/dist/components/client/BottomSheet/BottomSheetContent.d.ts +15 -0
- package/dist/components/client/BottomSheet/BottomSheetContent.js +24 -0
- package/dist/components/client/BottomSheet/BottomSheetDismiss.cjs +15 -0
- package/dist/components/client/BottomSheet/BottomSheetDismiss.d.cts +12 -0
- package/dist/components/client/BottomSheet/BottomSheetDismiss.d.ts +12 -0
- package/dist/components/client/BottomSheet/BottomSheetDismiss.js +13 -0
- package/dist/components/client/BottomSheet/BottomSheetHandle.cjs +30 -0
- package/dist/components/client/BottomSheet/BottomSheetHandle.d.cts +19 -0
- package/dist/components/client/BottomSheet/BottomSheetHandle.d.ts +19 -0
- package/dist/components/client/BottomSheet/BottomSheetHandle.js +28 -0
- package/dist/components/client/BottomSheet/BottomSheetHeader.cjs +42 -0
- package/dist/components/client/BottomSheet/BottomSheetHeader.d.cts +18 -0
- package/dist/components/client/BottomSheet/BottomSheetHeader.d.ts +18 -0
- package/dist/components/client/BottomSheet/BottomSheetHeader.js +40 -0
- package/dist/components/client/BottomSheet/BottomSheetProvider.cjs +21 -0
- package/dist/components/client/BottomSheet/BottomSheetProvider.d.cts +19 -0
- package/dist/components/client/BottomSheet/BottomSheetProvider.d.ts +19 -0
- package/dist/components/client/BottomSheet/BottomSheetProvider.js +19 -0
- package/dist/components/client/BottomSheet/BottomSheetTrigger.cjs +15 -0
- package/dist/components/client/BottomSheet/BottomSheetTrigger.d.cts +12 -0
- package/dist/components/client/BottomSheet/BottomSheetTrigger.d.ts +12 -0
- package/dist/components/client/BottomSheet/BottomSheetTrigger.js +13 -0
- package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.cjs +32 -0
- package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.d.cts +22 -0
- package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.d.ts +22 -0
- package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.js +29 -0
- package/dist/components/client/BottomSheet/index.cjs +22 -0
- package/dist/components/client/BottomSheet/index.d.cts +10 -0
- package/dist/components/client/BottomSheet/index.d.ts +10 -0
- package/dist/components/client/BottomSheet/index.js +12 -0
- package/dist/components/client/BottomSheet/useBottomSheetDrag.cjs +188 -0
- package/dist/components/client/BottomSheet/useBottomSheetDrag.d.cts +44 -0
- package/dist/components/client/BottomSheet/useBottomSheetDrag.d.ts +44 -0
- package/dist/components/client/BottomSheet/useBottomSheetDrag.js +185 -0
- package/dist/components/client/BottomSheet/useBottomSheetSnapModel.cjs +138 -0
- package/dist/components/client/BottomSheet/useBottomSheetSnapModel.d.cts +46 -0
- package/dist/components/client/BottomSheet/useBottomSheetSnapModel.d.ts +46 -0
- package/dist/components/client/BottomSheet/useBottomSheetSnapModel.js +135 -0
- package/dist/components/client/BottomSheet/useBottomSheetStore.cjs +34 -0
- package/dist/components/client/BottomSheet/useBottomSheetStore.d.cts +38 -0
- package/dist/components/client/BottomSheet/useBottomSheetStore.d.ts +38 -0
- package/dist/components/client/BottomSheet/useBottomSheetStore.js +31 -0
- package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.cjs +17 -0
- package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.d.cts +13 -0
- package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.d.ts +13 -0
- package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.js +15 -0
- package/dist/components/client/BottomSheet/useExpansionMargins.cjs +89 -0
- package/dist/components/client/BottomSheet/useExpansionMargins.d.cts +34 -0
- package/dist/components/client/BottomSheet/useExpansionMargins.d.ts +34 -0
- package/dist/components/client/BottomSheet/useExpansionMargins.js +87 -0
- package/dist/components/client/BottomSheet/useViewportHeight.cjs +32 -0
- package/dist/components/client/BottomSheet/useViewportHeight.d.cts +9 -0
- package/dist/components/client/BottomSheet/useViewportHeight.d.ts +9 -0
- package/dist/components/client/BottomSheet/useViewportHeight.js +30 -0
- package/dist/components/client/BottomSheet/useVirtualKeyboard.cjs +48 -0
- package/dist/components/client/BottomSheet/useVirtualKeyboard.d.cts +10 -0
- package/dist/components/client/BottomSheet/useVirtualKeyboard.d.ts +10 -0
- package/dist/components/client/BottomSheet/useVirtualKeyboard.js +46 -0
- package/dist/components/client/BottomSheet/utils.cjs +128 -0
- package/dist/components/client/BottomSheet/utils.d.cts +61 -0
- package/dist/components/client/BottomSheet/utils.d.ts +61 -0
- package/dist/components/client/BottomSheet/utils.js +118 -0
- package/dist/components/client/Menu/Menu.Content.cjs +1 -1
- package/dist/components/client/Menu/Menu.Content.js +1 -1
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +1 -1
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +1 -1
- package/dist/components/client/Menu/Menu.index.d.cts +1 -1
- package/dist/components/client/index.cjs +16 -0
- package/dist/components/client/index.d.cts +10 -1
- package/dist/components/client/index.d.ts +10 -1
- package/dist/components/client/index.js +9 -1
- package/dist/components/client/providers/UDSConfigProvider.cjs +10 -6
- package/dist/components/client/providers/UDSConfigProvider.d.cts +1 -0
- package/dist/components/client/providers/UDSConfigProvider.d.ts +1 -0
- package/dist/components/client/providers/UDSConfigProvider.js +10 -6
- package/dist/components/index.cjs +24 -0
- package/dist/components/index.d.cts +9 -1
- package/dist/components/index.d.ts +9 -1
- package/dist/components/index.js +17 -1
- package/dist/config/dist/index.cjs +110 -2
- package/dist/config/dist/index.js +110 -2
- package/dist/fixtures/dist/index.cjs +103 -0
- package/dist/fixtures/dist/index.d.cts +3 -2
- package/dist/fixtures/dist/index.d.ts +3 -2
- package/dist/fixtures/dist/index.js +103 -1
- package/dist/fixtures/index.cjs +1 -0
- package/dist/fixtures/index.d.cts +2 -2
- package/dist/fixtures/index.d.ts +2 -2
- package/dist/fixtures/index.js +2 -2
- package/dist/index.cjs +20 -2
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +11 -3
- package/dist/runtime/bottomSheetConfig.cjs +11 -0
- package/dist/runtime/bottomSheetConfig.d.cts +15 -0
- package/dist/runtime/bottomSheetConfig.d.ts +15 -0
- package/dist/runtime/bottomSheetConfig.js +9 -0
- package/dist/runtime/index.cjs +2 -0
- package/dist/runtime/index.d.cts +2 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/udsConfig.cjs +2 -0
- package/dist/runtime/udsConfig.d.cts +2 -0
- package/dist/runtime/udsConfig.d.ts +2 -0
- package/dist/runtime/udsConfig.js +2 -0
- package/dist/styles/styler.d.cts +33 -30
- package/dist/styles/styler.d.ts +33 -30
- package/dist/styles/variants.cjs +278 -278
- package/dist/styles/variants.d.cts +9 -0
- package/dist/styles/variants.d.ts +9 -0
- package/dist/styles/variants.js +278 -278
- package/dist/tailwind/dist/commands/generateComponentData.cjs +31 -33
- package/dist/tailwind/dist/commands/generateComponentData.d.ts +1 -1
- package/dist/tailwind/dist/commands/generateComponentData.js +31 -33
- package/dist/tailwind/dist/commands/generatePurgeCSSData.d.ts +1 -1
- package/dist/tailwind/dist/commands/purge.cjs +4 -3
- package/dist/tailwind/dist/commands/purge.d.ts +1 -1
- package/dist/tailwind/dist/commands/purge.js +4 -3
- package/dist/tailwind/dist/index.d.cts +0 -1
- package/dist/tailwind/dist/index.d.ts +3 -5
- package/dist/tailwind/dist/purger/legacy/purgeCSS.cjs +3 -4
- package/dist/tailwind/dist/purger/legacy/purgeCSS.js +3 -4
- package/dist/tailwind/dist/purger/optimized/ast/expressions.cjs +125 -122
- package/dist/tailwind/dist/purger/optimized/ast/expressions.js +125 -122
- package/dist/tailwind/dist/purger/optimized/ast/jsx.cjs +8 -1
- package/dist/tailwind/dist/purger/optimized/ast/jsx.js +8 -1
- package/dist/tailwind/dist/purger/optimized/purge.cjs +10 -11
- package/dist/tailwind/dist/purger/optimized/purge.js +9 -10
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.cjs +127 -232
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.js +127 -232
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.cjs +262 -330
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.js +262 -329
- package/dist/tailwind/dist/purger/optimized/utils/files.cjs +3 -4
- package/dist/tailwind/dist/purger/optimized/utils/files.js +3 -4
- package/dist/tailwind/dist/purger/optimized/utils/safelist.cjs +21 -13
- package/dist/tailwind/dist/purger/optimized/utils/safelist.js +21 -13
- package/dist/tailwind/dist/tailwind/plugins/components.cjs +2 -0
- package/dist/tailwind/dist/tailwind/plugins/components.js +3 -1
- package/dist/tailwind/dist/tailwind/plugins/typography.cjs +13 -41
- package/dist/tailwind/dist/tailwind/plugins/typography.js +13 -41
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.cjs +2 -4
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.cts +1 -10
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.ts +1 -10
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.js +2 -4
- package/dist/tailwind/dist/utils/tsMorph.cjs +1 -1
- package/dist/tokens/automation/configs/index.cjs +2 -0
- package/dist/tokens/automation/configs/index.d.cts +2 -2
- package/dist/tokens/automation/configs/index.d.ts +2 -2
- package/dist/tokens/automation/configs/index.js +2 -2
- package/dist/tokens/automation/index.cjs +2 -0
- package/dist/tokens/automation/index.d.cts +2 -2
- package/dist/tokens/automation/index.d.ts +2 -2
- package/dist/tokens/automation/index.js +2 -2
- package/dist/tokens/index.cjs +2 -0
- package/dist/tokens/index.d.cts +3 -3
- package/dist/tokens/index.d.ts +3 -3
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/types.d.cts +2 -2
- package/dist/tokens/types.d.ts +2 -2
- package/dist/types/dist/index.d.cts +76 -1
- package/dist/types/dist/index.d.ts +76 -1
- package/dist/uds/generated/componentData.cjs +1187 -961
- package/dist/uds/generated/componentData.js +1111 -939
- package/dist/uds/generated/tailwindPurge.cjs +57 -29
- package/dist/uds/generated/tailwindPurge.js +57 -29
- package/dist/uds/package.cjs +4 -10
- package/dist/uds/package.js +4 -10
- package/package.json +4 -7
- package/dist/cli/dist/lib/logger.cjs +0 -66
- package/dist/cli/dist/lib/logger.js +0 -66
- package/dist/tailwind/dist/commands/css.cjs +0 -79
- package/dist/tailwind/dist/commands/css.d.ts +0 -3
- package/dist/tailwind/dist/commands/css.helpers.cjs +0 -32
- package/dist/tailwind/dist/commands/css.helpers.js +0 -28
- package/dist/tailwind/dist/commands/css.js +0 -79
- package/dist/tailwind/dist/css/generate.cjs +0 -120
- package/dist/tailwind/dist/css/generate.d.cts +0 -30
- package/dist/tailwind/dist/css/generate.d.ts +0 -31
- package/dist/tailwind/dist/css/generate.helpers.cjs +0 -112
- package/dist/tailwind/dist/css/generate.helpers.js +0 -100
- package/dist/tailwind/dist/css/generate.js +0 -115
- package/dist/tailwind/dist/css/postcss.cjs +0 -35
- package/dist/tailwind/dist/css/postcss.helpers.cjs +0 -27
- package/dist/tailwind/dist/css/postcss.helpers.js +0 -26
- package/dist/tailwind/dist/css/postcss.js +0 -35
- package/dist/tailwind/dist/css/runner.cjs +0 -278
- package/dist/tailwind/dist/css/runner.helpers.cjs +0 -26
- package/dist/tailwind/dist/css/runner.helpers.js +0 -23
- package/dist/tailwind/dist/css/runner.js +0 -275
- package/dist/tailwind/dist/css/theme.cjs +0 -12
- package/dist/tailwind/dist/css/theme.d.cts +0 -66
- package/dist/tailwind/dist/css/theme.d.ts +0 -66
- package/dist/tailwind/dist/css/theme.js +0 -11
- package/dist/tailwind/dist/css/utils.cjs +0 -234
- package/dist/tailwind/dist/css/utils.js +0 -223
- package/dist/tailwind/dist/utils/optimizeCSS.cjs +0 -405
- package/dist/tailwind/dist/utils/optimizeCSS.js +0 -403
- package/dist/tailwind/dist/utils/postcssPreserveVars.cjs +0 -67
- package/dist/tailwind/dist/utils/postcssPreserveVars.js +0 -65
- package/generated/componentData.json +0 -2397
- package/generated/tailwindPurge.ts +0 -4560
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
3
|
+
import { clampIndex, isScrollable, shouldPreventDragFromTarget } from "./utils.js";
|
|
4
|
+
import { useCallback, useRef } from "react";
|
|
5
|
+
import { clamp } from "lodash-es";
|
|
6
|
+
|
|
7
|
+
//#region src/components/client/BottomSheet/useBottomSheetDrag.ts
|
|
8
|
+
const DEFAULT_SCROLL_LOCK_TIMEOUT_MS = 100;
|
|
9
|
+
const OPEN_SCROLL_LOCK_TIMEOUT_MS = 500;
|
|
10
|
+
/**
|
|
11
|
+
* Drag-to-dismiss velocity threshold in pixels/second. A fast downward swipe
|
|
12
|
+
* exceeding this speed dismisses the sheet (regardless of distance dragged).
|
|
13
|
+
*/
|
|
14
|
+
const DRAG_DISMISS_VELOCITY_PX_PER_SECOND = 400;
|
|
15
|
+
function useBottomSheetDrag({ enableDrag, dismissible, store, sheetRef, isDraggingRef, activeSnapIndex, snapPointTranslatesPx, maxSnapPointPx, resolvedSnapPointsLength, resolvedDismissThresholdPx, emitSnapPointChange, setTranslateImmediate, openTimeRef, lastTimeDragPreventedRef }) {
|
|
16
|
+
const isAllowedToDragRef = useRef(false);
|
|
17
|
+
const dragStartTimeRef = useRef(null);
|
|
18
|
+
const pointerStartRef = useRef(null);
|
|
19
|
+
const dragStartTranslateRef = useRef(0);
|
|
20
|
+
const dragStartIndexRef = useRef(0);
|
|
21
|
+
const shouldDragFromTarget = useCallback((target, isDraggingUp) => {
|
|
22
|
+
if (!sheetRef.current) return false;
|
|
23
|
+
if (shouldPreventDragFromTarget(target)) return false;
|
|
24
|
+
const selection = window.getSelection();
|
|
25
|
+
if (selection?.toString() && sheetRef.current?.contains(selection.anchorNode)) return false;
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
const openTime = openTimeRef.current;
|
|
28
|
+
if (openTime && now - openTime < OPEN_SCROLL_LOCK_TIMEOUT_MS) return false;
|
|
29
|
+
const currentHeight = sheetRef.current.getBoundingClientRect().height;
|
|
30
|
+
if (currentHeight < maxSnapPointPx) return true;
|
|
31
|
+
const lastPrevented = lastTimeDragPreventedRef.current;
|
|
32
|
+
if (lastPrevented && now - lastPrevented < DEFAULT_SCROLL_LOCK_TIMEOUT_MS && currentHeight >= maxSnapPointPx) return false;
|
|
33
|
+
if (isDraggingUp) {
|
|
34
|
+
lastTimeDragPreventedRef.current = now;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
let element = target instanceof HTMLElement ? target : null;
|
|
38
|
+
while (element) {
|
|
39
|
+
if (isScrollable(element)) {
|
|
40
|
+
if (element.scrollTop !== 0) {
|
|
41
|
+
lastTimeDragPreventedRef.current = now;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (element === sheetRef.current || element.getAttribute("role") === "dialog") return true;
|
|
46
|
+
element = element.parentNode;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}, [
|
|
50
|
+
lastTimeDragPreventedRef,
|
|
51
|
+
maxSnapPointPx,
|
|
52
|
+
openTimeRef,
|
|
53
|
+
sheetRef
|
|
54
|
+
]);
|
|
55
|
+
const cancelDrag = useCallback(() => {
|
|
56
|
+
isDraggingRef.current = false;
|
|
57
|
+
isAllowedToDragRef.current = false;
|
|
58
|
+
dragStartTimeRef.current = null;
|
|
59
|
+
pointerStartRef.current = null;
|
|
60
|
+
sheetRef.current?.style.removeProperty("transition");
|
|
61
|
+
}, [isDraggingRef, sheetRef]);
|
|
62
|
+
const onPointerDown = useCallback((event) => {
|
|
63
|
+
if (!enableDrag) return;
|
|
64
|
+
if (event.button !== 0) return;
|
|
65
|
+
if (shouldPreventDragFromTarget(event.target)) return;
|
|
66
|
+
isDraggingRef.current = false;
|
|
67
|
+
isAllowedToDragRef.current = false;
|
|
68
|
+
dragStartTimeRef.current = performance.now();
|
|
69
|
+
pointerStartRef.current = {
|
|
70
|
+
x: event.pageX,
|
|
71
|
+
y: event.pageY
|
|
72
|
+
};
|
|
73
|
+
dragStartTranslateRef.current = maxSnapPointPx - (sheetRef.current?.getBoundingClientRect().height ?? 0);
|
|
74
|
+
dragStartIndexRef.current = activeSnapIndex;
|
|
75
|
+
}, [
|
|
76
|
+
activeSnapIndex,
|
|
77
|
+
enableDrag,
|
|
78
|
+
isDraggingRef,
|
|
79
|
+
maxSnapPointPx,
|
|
80
|
+
sheetRef
|
|
81
|
+
]);
|
|
82
|
+
const onPointerMove = useCallback((event) => {
|
|
83
|
+
if (!enableDrag) return;
|
|
84
|
+
const startPoint = pointerStartRef.current;
|
|
85
|
+
const sheetEl = sheetRef.current;
|
|
86
|
+
if (!startPoint || !sheetEl) return;
|
|
87
|
+
if (!isAllowedToDragRef.current && event.buttons === 0) {
|
|
88
|
+
cancelDrag();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const { x: startX, y: startY } = startPoint;
|
|
92
|
+
const dx = event.pageX - startX;
|
|
93
|
+
const dy = event.pageY - startY;
|
|
94
|
+
const swipeStartThreshold = event.pointerType === "touch" ? 10 : 2;
|
|
95
|
+
if (!isAllowedToDragRef.current) {
|
|
96
|
+
if (Math.abs(dy) < swipeStartThreshold) return;
|
|
97
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
98
|
+
pointerStartRef.current = null;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const isDraggingUp = startY - event.pageY > 0;
|
|
103
|
+
if (!isAllowedToDragRef.current && !shouldDragFromTarget(event.target, isDraggingUp)) return;
|
|
104
|
+
if (!isAllowedToDragRef.current) {
|
|
105
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
106
|
+
isAllowedToDragRef.current = true;
|
|
107
|
+
isDraggingRef.current = true;
|
|
108
|
+
}
|
|
109
|
+
sheetEl.style.transition = "none";
|
|
110
|
+
setTranslateImmediate(clamp(dragStartTranslateRef.current + dy, 0, maxSnapPointPx));
|
|
111
|
+
}, [
|
|
112
|
+
enableDrag,
|
|
113
|
+
isDraggingRef,
|
|
114
|
+
maxSnapPointPx,
|
|
115
|
+
setTranslateImmediate,
|
|
116
|
+
shouldDragFromTarget,
|
|
117
|
+
sheetRef
|
|
118
|
+
]);
|
|
119
|
+
const onPointerUp = useCallback((event) => {
|
|
120
|
+
if (!enableDrag) return;
|
|
121
|
+
if (!pointerStartRef.current || !sheetRef.current) {
|
|
122
|
+
cancelDrag();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isAllowedToDragRef.current) {
|
|
126
|
+
cancelDrag();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const { y: startY } = pointerStartRef.current;
|
|
130
|
+
const draggedDistance = startY - event.pageY;
|
|
131
|
+
const timeTakenMs = Math.max(performance.now() - (dragStartTimeRef.current ?? performance.now()), 1);
|
|
132
|
+
const velocityPxPerSecond = Math.abs(draggedDistance) / timeTakenMs * 1e3;
|
|
133
|
+
const currentTranslatePx = maxSnapPointPx - sheetRef.current.getBoundingClientRect().height;
|
|
134
|
+
const draggedDownBeyondLowestPx = currentTranslatePx - (snapPointTranslatesPx[dragStartIndexRef.current] ?? maxSnapPointPx);
|
|
135
|
+
const draggedDown = draggedDistance < 0;
|
|
136
|
+
const draggedUp = draggedDistance > 0;
|
|
137
|
+
const isAtLowestSnapPoint = dragStartIndexRef.current === 0;
|
|
138
|
+
if (dismissible && isAtLowestSnapPoint && draggedDown && (velocityPxPerSecond >= DRAG_DISMISS_VELOCITY_PX_PER_SECOND || draggedDownBeyondLowestPx >= resolvedDismissThresholdPx)) {
|
|
139
|
+
cancelDrag();
|
|
140
|
+
store.hide();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const lastIndex = resolvedSnapPointsLength - 1;
|
|
144
|
+
const startIndex = dragStartIndexRef.current;
|
|
145
|
+
if (velocityPxPerSecond >= DRAG_DISMISS_VELOCITY_PX_PER_SECOND && (draggedUp || draggedDown)) {
|
|
146
|
+
const nextIndex = clampIndex(startIndex + (draggedUp ? 1 : -1), resolvedSnapPointsLength);
|
|
147
|
+
cancelDrag();
|
|
148
|
+
emitSnapPointChange(nextIndex);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let closestIndex = 0;
|
|
152
|
+
let closestDist = Number.POSITIVE_INFINITY;
|
|
153
|
+
for (let i = 0; i <= lastIndex; i++) {
|
|
154
|
+
const dist = Math.abs((snapPointTranslatesPx[i] ?? 0) - currentTranslatePx);
|
|
155
|
+
if (dist < closestDist) {
|
|
156
|
+
closestDist = dist;
|
|
157
|
+
closestIndex = i;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
cancelDrag();
|
|
161
|
+
emitSnapPointChange(closestIndex);
|
|
162
|
+
}, [
|
|
163
|
+
cancelDrag,
|
|
164
|
+
dismissible,
|
|
165
|
+
emitSnapPointChange,
|
|
166
|
+
enableDrag,
|
|
167
|
+
maxSnapPointPx,
|
|
168
|
+
resolvedDismissThresholdPx,
|
|
169
|
+
resolvedSnapPointsLength,
|
|
170
|
+
sheetRef,
|
|
171
|
+
snapPointTranslatesPx,
|
|
172
|
+
store
|
|
173
|
+
]);
|
|
174
|
+
return {
|
|
175
|
+
onPointerDown,
|
|
176
|
+
onPointerMove,
|
|
177
|
+
onPointerUp,
|
|
178
|
+
onPointerCancel: useCallback((event) => {
|
|
179
|
+
onPointerUp(event);
|
|
180
|
+
}, [onPointerUp])
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
export { useBottomSheetDrag };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_components_client_BottomSheet_utils = require('./utils.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let lodash_clamp_js = require("lodash/clamp.js");
|
|
8
|
+
lodash_clamp_js = require_runtime.__toESM(lodash_clamp_js);
|
|
9
|
+
|
|
10
|
+
//#region src/components/client/BottomSheet/useBottomSheetSnapModel.ts
|
|
11
|
+
const DEFAULT_SNAP_POINT = "40%";
|
|
12
|
+
const OPEN_SHEET_ENTER_DELAY_MS = 50;
|
|
13
|
+
function useBottomSheetSnapModel({ isOpen, snapPointsProp, height, defaultSnapPointIndex, snapPointIndexProp, onSnapPointChange, viewportHeightPx, maxHeightPx, setTranslateAnimated, isDraggingRef }) {
|
|
14
|
+
const openTimeRef = (0, react.useRef)(null);
|
|
15
|
+
const lastTimeDragPreventedRef = (0, react.useRef)(null);
|
|
16
|
+
const openEnterTimeoutRef = (0, react.useRef)(null);
|
|
17
|
+
const isEnteringRef = (0, react.useRef)(false);
|
|
18
|
+
const resolvedSnapPoints = (0, react.useMemo)(() => {
|
|
19
|
+
if (snapPointsProp?.length) return snapPointsProp;
|
|
20
|
+
if (height !== void 0) return [height];
|
|
21
|
+
return [DEFAULT_SNAP_POINT];
|
|
22
|
+
}, [height, snapPointsProp]);
|
|
23
|
+
const snapPointsPx = (0, react.useMemo)(() => {
|
|
24
|
+
return resolvedSnapPoints.map((sp) => (0, lodash_clamp_js.default)(require_components_client_BottomSheet_utils.resolveHeightToPx(sp, viewportHeightPx), 0, maxHeightPx));
|
|
25
|
+
}, [
|
|
26
|
+
maxHeightPx,
|
|
27
|
+
resolvedSnapPoints,
|
|
28
|
+
viewportHeightPx
|
|
29
|
+
]);
|
|
30
|
+
const maxSnapPointPx = (0, react.useMemo)(() => Math.max(0, ...snapPointsPx), [snapPointsPx]);
|
|
31
|
+
const snapPointTranslatesPx = (0, react.useMemo)(() => {
|
|
32
|
+
return snapPointsPx.map((h) => maxSnapPointPx - h);
|
|
33
|
+
}, [maxSnapPointPx, snapPointsPx]);
|
|
34
|
+
const isSnapPointControlled = snapPointIndexProp !== void 0;
|
|
35
|
+
const [uncontrolledSnapIndex, setUncontrolledSnapIndex] = (0, react.useState)(() => require_components_client_BottomSheet_utils.clampIndex(defaultSnapPointIndex, resolvedSnapPoints.length));
|
|
36
|
+
const activeSnapIndex = require_components_client_BottomSheet_utils.clampIndex(isSnapPointControlled ? snapPointIndexProp ?? 0 : uncontrolledSnapIndex, resolvedSnapPoints.length);
|
|
37
|
+
const activeTranslatePx = snapPointTranslatesPx[activeSnapIndex] ?? maxSnapPointPx;
|
|
38
|
+
const [restTranslatePx, setRestTranslatePx] = (0, react.useState)(() => maxSnapPointPx);
|
|
39
|
+
const lastEmittedTranslateRef = (0, react.useRef)(null);
|
|
40
|
+
const emitSnapPointChange = (0, react.useCallback)((nextIndex) => {
|
|
41
|
+
const clamped = require_components_client_BottomSheet_utils.clampIndex(nextIndex, resolvedSnapPoints.length);
|
|
42
|
+
const nextTranslatePx = snapPointTranslatesPx[clamped] ?? maxSnapPointPx;
|
|
43
|
+
onSnapPointChange?.(clamped, resolvedSnapPoints[clamped]);
|
|
44
|
+
if (!isSnapPointControlled) setUncontrolledSnapIndex(clamped);
|
|
45
|
+
setRestTranslatePx(nextTranslatePx);
|
|
46
|
+
lastEmittedTranslateRef.current = nextTranslatePx;
|
|
47
|
+
setTranslateAnimated(nextTranslatePx);
|
|
48
|
+
}, [
|
|
49
|
+
isSnapPointControlled,
|
|
50
|
+
maxSnapPointPx,
|
|
51
|
+
onSnapPointChange,
|
|
52
|
+
resolvedSnapPoints,
|
|
53
|
+
setTranslateAnimated,
|
|
54
|
+
snapPointTranslatesPx
|
|
55
|
+
]);
|
|
56
|
+
(0, react.useEffect)(() => {
|
|
57
|
+
const wasOpen = openTimeRef.current !== null;
|
|
58
|
+
if (!isOpen) {
|
|
59
|
+
if (openEnterTimeoutRef.current !== null) {
|
|
60
|
+
window.clearTimeout(openEnterTimeoutRef.current);
|
|
61
|
+
openEnterTimeoutRef.current = null;
|
|
62
|
+
}
|
|
63
|
+
isEnteringRef.current = false;
|
|
64
|
+
openTimeRef.current = null;
|
|
65
|
+
setRestTranslatePx(maxSnapPointPx);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (wasOpen) return;
|
|
69
|
+
isEnteringRef.current = true;
|
|
70
|
+
openTimeRef.current = Date.now();
|
|
71
|
+
const initialSnapIndex = isSnapPointControlled ? activeSnapIndex : require_components_client_BottomSheet_utils.clampIndex(defaultSnapPointIndex, resolvedSnapPoints.length);
|
|
72
|
+
if (!isSnapPointControlled) setUncontrolledSnapIndex(initialSnapIndex);
|
|
73
|
+
setRestTranslatePx(maxSnapPointPx);
|
|
74
|
+
const initialTranslatePx = snapPointTranslatesPx[initialSnapIndex] ?? maxSnapPointPx;
|
|
75
|
+
openEnterTimeoutRef.current = window.setTimeout(() => {
|
|
76
|
+
isEnteringRef.current = false;
|
|
77
|
+
setRestTranslatePx(initialTranslatePx);
|
|
78
|
+
setTranslateAnimated(initialTranslatePx);
|
|
79
|
+
openEnterTimeoutRef.current = null;
|
|
80
|
+
}, OPEN_SHEET_ENTER_DELAY_MS);
|
|
81
|
+
}, [
|
|
82
|
+
activeSnapIndex,
|
|
83
|
+
defaultSnapPointIndex,
|
|
84
|
+
isOpen,
|
|
85
|
+
isSnapPointControlled,
|
|
86
|
+
maxSnapPointPx,
|
|
87
|
+
resolvedSnapPoints.length,
|
|
88
|
+
setTranslateAnimated,
|
|
89
|
+
snapPointTranslatesPx
|
|
90
|
+
]);
|
|
91
|
+
(0, react.useEffect)(() => {
|
|
92
|
+
return () => {
|
|
93
|
+
if (openEnterTimeoutRef.current !== null) {
|
|
94
|
+
window.clearTimeout(openEnterTimeoutRef.current);
|
|
95
|
+
openEnterTimeoutRef.current = null;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
(0, react.useEffect)(() => {
|
|
100
|
+
if (!isOpen || isEnteringRef.current || isDraggingRef.current) return;
|
|
101
|
+
setRestTranslatePx(activeTranslatePx);
|
|
102
|
+
if (lastEmittedTranslateRef.current === activeTranslatePx) {
|
|
103
|
+
lastEmittedTranslateRef.current = null;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
setTranslateAnimated(activeTranslatePx);
|
|
107
|
+
}, [
|
|
108
|
+
activeTranslatePx,
|
|
109
|
+
isDraggingRef,
|
|
110
|
+
isOpen,
|
|
111
|
+
setTranslateAnimated
|
|
112
|
+
]);
|
|
113
|
+
(0, react.useEffect)(() => {
|
|
114
|
+
if (!isOpen) return;
|
|
115
|
+
if (activeSnapIndex === resolvedSnapPoints.length - 1) openTimeRef.current = Date.now();
|
|
116
|
+
}, [
|
|
117
|
+
activeSnapIndex,
|
|
118
|
+
isOpen,
|
|
119
|
+
resolvedSnapPoints.length
|
|
120
|
+
]);
|
|
121
|
+
return {
|
|
122
|
+
resolvedSnapPoints,
|
|
123
|
+
snapPointsPx,
|
|
124
|
+
maxSnapPointPx,
|
|
125
|
+
snapPointTranslatesPx,
|
|
126
|
+
activeSnapIndex,
|
|
127
|
+
restTranslatePx,
|
|
128
|
+
setRestTranslatePx,
|
|
129
|
+
isSnapPointControlled,
|
|
130
|
+
emitSnapPointChange,
|
|
131
|
+
openTimeRef,
|
|
132
|
+
lastTimeDragPreventedRef,
|
|
133
|
+
isEnteringRef
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
exports.useBottomSheetSnapModel = useBottomSheetSnapModel;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import { BottomSheetHeight } from "../../../types/dist/index.cjs";
|
|
3
|
+
import "../../../tokens/index.cjs";
|
|
4
|
+
import { MutableRefObject } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/components/client/BottomSheet/useBottomSheetSnapModel.d.ts
|
|
7
|
+
interface UseBottomSheetSnapModelParams {
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
snapPointsProp?: BottomSheetHeight[];
|
|
10
|
+
height?: BottomSheetHeight;
|
|
11
|
+
defaultSnapPointIndex: number;
|
|
12
|
+
snapPointIndexProp?: number;
|
|
13
|
+
onSnapPointChange?: (index: number, height: BottomSheetHeight) => void;
|
|
14
|
+
viewportHeightPx: number;
|
|
15
|
+
maxHeightPx: number;
|
|
16
|
+
setTranslateAnimated: (nextTranslatePx: number) => void;
|
|
17
|
+
isDraggingRef: MutableRefObject<boolean>;
|
|
18
|
+
}
|
|
19
|
+
interface UseBottomSheetSnapModelResult {
|
|
20
|
+
resolvedSnapPoints: BottomSheetHeight[];
|
|
21
|
+
snapPointsPx: number[];
|
|
22
|
+
maxSnapPointPx: number;
|
|
23
|
+
snapPointTranslatesPx: number[];
|
|
24
|
+
activeSnapIndex: number;
|
|
25
|
+
restTranslatePx: number;
|
|
26
|
+
setRestTranslatePx: React.Dispatch<React.SetStateAction<number>>;
|
|
27
|
+
isSnapPointControlled: boolean;
|
|
28
|
+
emitSnapPointChange: (nextIndex: number) => void;
|
|
29
|
+
openTimeRef: MutableRefObject<number | null>;
|
|
30
|
+
lastTimeDragPreventedRef: MutableRefObject<number | null>;
|
|
31
|
+
isEnteringRef: MutableRefObject<boolean>;
|
|
32
|
+
}
|
|
33
|
+
declare function useBottomSheetSnapModel({
|
|
34
|
+
isOpen,
|
|
35
|
+
snapPointsProp,
|
|
36
|
+
height,
|
|
37
|
+
defaultSnapPointIndex,
|
|
38
|
+
snapPointIndexProp,
|
|
39
|
+
onSnapPointChange,
|
|
40
|
+
viewportHeightPx,
|
|
41
|
+
maxHeightPx,
|
|
42
|
+
setTranslateAnimated,
|
|
43
|
+
isDraggingRef
|
|
44
|
+
}: UseBottomSheetSnapModelParams): UseBottomSheetSnapModelResult;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { useBottomSheetSnapModel };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import { BottomSheetHeight } from "../../../types/dist/index.js";
|
|
3
|
+
import "../../../tokens/index.js";
|
|
4
|
+
import { MutableRefObject } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/components/client/BottomSheet/useBottomSheetSnapModel.d.ts
|
|
7
|
+
interface UseBottomSheetSnapModelParams {
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
snapPointsProp?: BottomSheetHeight[];
|
|
10
|
+
height?: BottomSheetHeight;
|
|
11
|
+
defaultSnapPointIndex: number;
|
|
12
|
+
snapPointIndexProp?: number;
|
|
13
|
+
onSnapPointChange?: (index: number, height: BottomSheetHeight) => void;
|
|
14
|
+
viewportHeightPx: number;
|
|
15
|
+
maxHeightPx: number;
|
|
16
|
+
setTranslateAnimated: (nextTranslatePx: number) => void;
|
|
17
|
+
isDraggingRef: MutableRefObject<boolean>;
|
|
18
|
+
}
|
|
19
|
+
interface UseBottomSheetSnapModelResult {
|
|
20
|
+
resolvedSnapPoints: BottomSheetHeight[];
|
|
21
|
+
snapPointsPx: number[];
|
|
22
|
+
maxSnapPointPx: number;
|
|
23
|
+
snapPointTranslatesPx: number[];
|
|
24
|
+
activeSnapIndex: number;
|
|
25
|
+
restTranslatePx: number;
|
|
26
|
+
setRestTranslatePx: React.Dispatch<React.SetStateAction<number>>;
|
|
27
|
+
isSnapPointControlled: boolean;
|
|
28
|
+
emitSnapPointChange: (nextIndex: number) => void;
|
|
29
|
+
openTimeRef: MutableRefObject<number | null>;
|
|
30
|
+
lastTimeDragPreventedRef: MutableRefObject<number | null>;
|
|
31
|
+
isEnteringRef: MutableRefObject<boolean>;
|
|
32
|
+
}
|
|
33
|
+
declare function useBottomSheetSnapModel({
|
|
34
|
+
isOpen,
|
|
35
|
+
snapPointsProp,
|
|
36
|
+
height,
|
|
37
|
+
defaultSnapPointIndex,
|
|
38
|
+
snapPointIndexProp,
|
|
39
|
+
onSnapPointChange,
|
|
40
|
+
viewportHeightPx,
|
|
41
|
+
maxHeightPx,
|
|
42
|
+
setTranslateAnimated,
|
|
43
|
+
isDraggingRef
|
|
44
|
+
}: UseBottomSheetSnapModelParams): UseBottomSheetSnapModelResult;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { useBottomSheetSnapModel };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
3
|
+
import { clampIndex, resolveHeightToPx } from "./utils.js";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { clamp } from "lodash-es";
|
|
6
|
+
|
|
7
|
+
//#region src/components/client/BottomSheet/useBottomSheetSnapModel.ts
|
|
8
|
+
const DEFAULT_SNAP_POINT = "40%";
|
|
9
|
+
const OPEN_SHEET_ENTER_DELAY_MS = 50;
|
|
10
|
+
function useBottomSheetSnapModel({ isOpen, snapPointsProp, height, defaultSnapPointIndex, snapPointIndexProp, onSnapPointChange, viewportHeightPx, maxHeightPx, setTranslateAnimated, isDraggingRef }) {
|
|
11
|
+
const openTimeRef = useRef(null);
|
|
12
|
+
const lastTimeDragPreventedRef = useRef(null);
|
|
13
|
+
const openEnterTimeoutRef = useRef(null);
|
|
14
|
+
const isEnteringRef = useRef(false);
|
|
15
|
+
const resolvedSnapPoints = useMemo(() => {
|
|
16
|
+
if (snapPointsProp?.length) return snapPointsProp;
|
|
17
|
+
if (height !== void 0) return [height];
|
|
18
|
+
return [DEFAULT_SNAP_POINT];
|
|
19
|
+
}, [height, snapPointsProp]);
|
|
20
|
+
const snapPointsPx = useMemo(() => {
|
|
21
|
+
return resolvedSnapPoints.map((sp) => clamp(resolveHeightToPx(sp, viewportHeightPx), 0, maxHeightPx));
|
|
22
|
+
}, [
|
|
23
|
+
maxHeightPx,
|
|
24
|
+
resolvedSnapPoints,
|
|
25
|
+
viewportHeightPx
|
|
26
|
+
]);
|
|
27
|
+
const maxSnapPointPx = useMemo(() => Math.max(0, ...snapPointsPx), [snapPointsPx]);
|
|
28
|
+
const snapPointTranslatesPx = useMemo(() => {
|
|
29
|
+
return snapPointsPx.map((h) => maxSnapPointPx - h);
|
|
30
|
+
}, [maxSnapPointPx, snapPointsPx]);
|
|
31
|
+
const isSnapPointControlled = snapPointIndexProp !== void 0;
|
|
32
|
+
const [uncontrolledSnapIndex, setUncontrolledSnapIndex] = useState(() => clampIndex(defaultSnapPointIndex, resolvedSnapPoints.length));
|
|
33
|
+
const activeSnapIndex = clampIndex(isSnapPointControlled ? snapPointIndexProp ?? 0 : uncontrolledSnapIndex, resolvedSnapPoints.length);
|
|
34
|
+
const activeTranslatePx = snapPointTranslatesPx[activeSnapIndex] ?? maxSnapPointPx;
|
|
35
|
+
const [restTranslatePx, setRestTranslatePx] = useState(() => maxSnapPointPx);
|
|
36
|
+
const lastEmittedTranslateRef = useRef(null);
|
|
37
|
+
const emitSnapPointChange = useCallback((nextIndex) => {
|
|
38
|
+
const clamped = clampIndex(nextIndex, resolvedSnapPoints.length);
|
|
39
|
+
const nextTranslatePx = snapPointTranslatesPx[clamped] ?? maxSnapPointPx;
|
|
40
|
+
onSnapPointChange?.(clamped, resolvedSnapPoints[clamped]);
|
|
41
|
+
if (!isSnapPointControlled) setUncontrolledSnapIndex(clamped);
|
|
42
|
+
setRestTranslatePx(nextTranslatePx);
|
|
43
|
+
lastEmittedTranslateRef.current = nextTranslatePx;
|
|
44
|
+
setTranslateAnimated(nextTranslatePx);
|
|
45
|
+
}, [
|
|
46
|
+
isSnapPointControlled,
|
|
47
|
+
maxSnapPointPx,
|
|
48
|
+
onSnapPointChange,
|
|
49
|
+
resolvedSnapPoints,
|
|
50
|
+
setTranslateAnimated,
|
|
51
|
+
snapPointTranslatesPx
|
|
52
|
+
]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const wasOpen = openTimeRef.current !== null;
|
|
55
|
+
if (!isOpen) {
|
|
56
|
+
if (openEnterTimeoutRef.current !== null) {
|
|
57
|
+
window.clearTimeout(openEnterTimeoutRef.current);
|
|
58
|
+
openEnterTimeoutRef.current = null;
|
|
59
|
+
}
|
|
60
|
+
isEnteringRef.current = false;
|
|
61
|
+
openTimeRef.current = null;
|
|
62
|
+
setRestTranslatePx(maxSnapPointPx);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (wasOpen) return;
|
|
66
|
+
isEnteringRef.current = true;
|
|
67
|
+
openTimeRef.current = Date.now();
|
|
68
|
+
const initialSnapIndex = isSnapPointControlled ? activeSnapIndex : clampIndex(defaultSnapPointIndex, resolvedSnapPoints.length);
|
|
69
|
+
if (!isSnapPointControlled) setUncontrolledSnapIndex(initialSnapIndex);
|
|
70
|
+
setRestTranslatePx(maxSnapPointPx);
|
|
71
|
+
const initialTranslatePx = snapPointTranslatesPx[initialSnapIndex] ?? maxSnapPointPx;
|
|
72
|
+
openEnterTimeoutRef.current = window.setTimeout(() => {
|
|
73
|
+
isEnteringRef.current = false;
|
|
74
|
+
setRestTranslatePx(initialTranslatePx);
|
|
75
|
+
setTranslateAnimated(initialTranslatePx);
|
|
76
|
+
openEnterTimeoutRef.current = null;
|
|
77
|
+
}, OPEN_SHEET_ENTER_DELAY_MS);
|
|
78
|
+
}, [
|
|
79
|
+
activeSnapIndex,
|
|
80
|
+
defaultSnapPointIndex,
|
|
81
|
+
isOpen,
|
|
82
|
+
isSnapPointControlled,
|
|
83
|
+
maxSnapPointPx,
|
|
84
|
+
resolvedSnapPoints.length,
|
|
85
|
+
setTranslateAnimated,
|
|
86
|
+
snapPointTranslatesPx
|
|
87
|
+
]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
return () => {
|
|
90
|
+
if (openEnterTimeoutRef.current !== null) {
|
|
91
|
+
window.clearTimeout(openEnterTimeoutRef.current);
|
|
92
|
+
openEnterTimeoutRef.current = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!isOpen || isEnteringRef.current || isDraggingRef.current) return;
|
|
98
|
+
setRestTranslatePx(activeTranslatePx);
|
|
99
|
+
if (lastEmittedTranslateRef.current === activeTranslatePx) {
|
|
100
|
+
lastEmittedTranslateRef.current = null;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
setTranslateAnimated(activeTranslatePx);
|
|
104
|
+
}, [
|
|
105
|
+
activeTranslatePx,
|
|
106
|
+
isDraggingRef,
|
|
107
|
+
isOpen,
|
|
108
|
+
setTranslateAnimated
|
|
109
|
+
]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!isOpen) return;
|
|
112
|
+
if (activeSnapIndex === resolvedSnapPoints.length - 1) openTimeRef.current = Date.now();
|
|
113
|
+
}, [
|
|
114
|
+
activeSnapIndex,
|
|
115
|
+
isOpen,
|
|
116
|
+
resolvedSnapPoints.length
|
|
117
|
+
]);
|
|
118
|
+
return {
|
|
119
|
+
resolvedSnapPoints,
|
|
120
|
+
snapPointsPx,
|
|
121
|
+
maxSnapPointPx,
|
|
122
|
+
snapPointTranslatesPx,
|
|
123
|
+
activeSnapIndex,
|
|
124
|
+
restTranslatePx,
|
|
125
|
+
setRestTranslatePx,
|
|
126
|
+
isSnapPointControlled,
|
|
127
|
+
emitSnapPointChange,
|
|
128
|
+
openTimeRef,
|
|
129
|
+
lastTimeDragPreventedRef,
|
|
130
|
+
isEnteringRef
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
export { useBottomSheetSnapModel };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_components_client_BottomSheet_useBottomSheetStoreInternal = require('./useBottomSheetStoreInternal.cjs');
|
|
6
|
+
let _ariakit_react = require("@ariakit/react");
|
|
7
|
+
|
|
8
|
+
//#region src/components/client/BottomSheet/useBottomSheetStore.ts
|
|
9
|
+
/** @internal */
|
|
10
|
+
const BOTTOM_SHEET_INTERNAL_STORE_KEY = "__bottomSheetInternal";
|
|
11
|
+
/** @internal */
|
|
12
|
+
function getBottomSheetInternal(controller) {
|
|
13
|
+
const internal = controller[BOTTOM_SHEET_INTERNAL_STORE_KEY];
|
|
14
|
+
if (!internal) throw new Error("Invalid BottomSheet controller. Use `useBottomSheetStore()` to create one.");
|
|
15
|
+
return internal;
|
|
16
|
+
}
|
|
17
|
+
const useBottomSheetStore = ({ animated = true, defaultOpen = false, open: openProp } = {}) => {
|
|
18
|
+
const bottomSheetInternal = require_components_client_BottomSheet_useBottomSheetStoreInternal.useBottomSheetStoreInternal({
|
|
19
|
+
animated,
|
|
20
|
+
open: openProp,
|
|
21
|
+
defaultOpen
|
|
22
|
+
});
|
|
23
|
+
const isOpen = (0, _ariakit_react.useStoreState)(bottomSheetInternal, (state) => state.open);
|
|
24
|
+
return {
|
|
25
|
+
open: bottomSheetInternal.show,
|
|
26
|
+
close: bottomSheetInternal.hide,
|
|
27
|
+
isOpen,
|
|
28
|
+
[BOTTOM_SHEET_INTERNAL_STORE_KEY]: bottomSheetInternal
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.getBottomSheetInternal = getBottomSheetInternal;
|
|
34
|
+
exports.useBottomSheetStore = useBottomSheetStore;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import * as _ariakit_react0 from "@ariakit/react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/client/BottomSheet/useBottomSheetStore.d.ts
|
|
5
|
+
interface UseBottomSheetStoreProps {
|
|
6
|
+
/**
|
|
7
|
+
* The initial state of the bottom sheet.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the bottom sheet is open.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the bottom sheet is animated.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
animated?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface BottomSheetController {
|
|
23
|
+
/** Open the bottom sheet. */
|
|
24
|
+
open: () => void;
|
|
25
|
+
/** Close the bottom sheet. */
|
|
26
|
+
close: () => void;
|
|
27
|
+
/** Whether the bottom sheet is currently open. */
|
|
28
|
+
isOpen: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
declare function getBottomSheetInternal(controller: BottomSheetController): _ariakit_react0.DialogStore;
|
|
32
|
+
declare const useBottomSheetStore: ({
|
|
33
|
+
animated,
|
|
34
|
+
defaultOpen,
|
|
35
|
+
open: openProp
|
|
36
|
+
}?: UseBottomSheetStoreProps) => BottomSheetController;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type BottomSheetController, type UseBottomSheetStoreProps, getBottomSheetInternal, useBottomSheetStore };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import * as _ariakit_react0 from "@ariakit/react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/client/BottomSheet/useBottomSheetStore.d.ts
|
|
5
|
+
interface UseBottomSheetStoreProps {
|
|
6
|
+
/**
|
|
7
|
+
* The initial state of the bottom sheet.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the bottom sheet is open.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the bottom sheet is animated.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
animated?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface BottomSheetController {
|
|
23
|
+
/** Open the bottom sheet. */
|
|
24
|
+
open: () => void;
|
|
25
|
+
/** Close the bottom sheet. */
|
|
26
|
+
close: () => void;
|
|
27
|
+
/** Whether the bottom sheet is currently open. */
|
|
28
|
+
isOpen: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
declare function getBottomSheetInternal(controller: BottomSheetController): _ariakit_react0.DialogStore;
|
|
32
|
+
declare const useBottomSheetStore: ({
|
|
33
|
+
animated,
|
|
34
|
+
defaultOpen,
|
|
35
|
+
open: openProp
|
|
36
|
+
}?: UseBottomSheetStoreProps) => BottomSheetController;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type BottomSheetController, type UseBottomSheetStoreProps, getBottomSheetInternal, useBottomSheetStore };
|