@samline/drawer 2.0.3 → 2.0.5
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/browser/{components-client-CZSt5H60.mjs → components-client-BnT3P9Or.mjs} +164 -28
- package/dist/{svelte/components-client-DXeaMmfk.js → browser/components-client-D4tSixHM.js} +163 -27
- package/dist/browser/index.cjs +211 -34
- package/dist/browser/index.js +211 -34
- package/dist/browser/index.mjs +211 -34
- package/dist/{svelte/components-client-CZSt5H60.mjs → components-client-BnT3P9Or.mjs} +164 -28
- package/dist/{browser/components-client-DXeaMmfk.js → components-client-D4tSixHM.js} +163 -27
- package/dist/index.js +211 -34
- package/dist/index.mjs +211 -34
- package/dist/react/index.js +229 -37
- package/dist/react/index.mjs +230 -38
- package/dist/{components-client-CZSt5H60.mjs → svelte/components-client-BnT3P9Or.mjs} +164 -28
- package/dist/{vue/components-client-DXeaMmfk.js → svelte/components-client-D4tSixHM.js} +163 -27
- package/dist/svelte/index.js +211 -34
- package/dist/svelte/index.mjs +211 -34
- package/dist/vue/{components-client-DZfql3-W.mjs → components-client-CvNPHVej.mjs} +164 -28
- package/dist/{components-client-DXeaMmfk.js → vue/components-client-D4tSixHM.js} +163 -27
- package/dist/vue/index.js +211 -34
- package/dist/vue/index.mjs +211 -34
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -215,30 +215,38 @@ const nonTextInputTypes = new Set([
|
|
|
215
215
|
'submit',
|
|
216
216
|
'reset'
|
|
217
217
|
]);
|
|
218
|
-
|
|
219
|
-
let
|
|
220
|
-
|
|
218
|
+
const activePreventScrollLocks = new Set();
|
|
219
|
+
let activePreventScrollRestore = null;
|
|
220
|
+
function acquirePreventScrollLock(lockId) {
|
|
221
|
+
activePreventScrollLocks.add(lockId);
|
|
222
|
+
if (activePreventScrollLocks.size === 1 && isIOS()) {
|
|
223
|
+
activePreventScrollRestore = preventScrollMobileSafari();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function releasePreventScrollLock(lockId) {
|
|
227
|
+
activePreventScrollLocks.delete(lockId);
|
|
228
|
+
if (activePreventScrollLocks.size === 0) {
|
|
229
|
+
activePreventScrollRestore == null ? void 0 : activePreventScrollRestore();
|
|
230
|
+
activePreventScrollRestore = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
221
233
|
/**
|
|
222
234
|
* Prevents scrolling on the document body on mount, and
|
|
223
235
|
* restores it on unmount. Also ensures that content does not
|
|
224
236
|
* shift due to the scrollbars disappearing.
|
|
225
237
|
*/ function usePreventScroll(options = {}) {
|
|
226
238
|
let { isDisabled } = options;
|
|
239
|
+
const lockIdRef = React.useRef();
|
|
240
|
+
if (!lockIdRef.current) {
|
|
241
|
+
lockIdRef.current = Symbol('drawer-prevent-scroll-lock');
|
|
242
|
+
}
|
|
227
243
|
useIsomorphicLayoutEffect(()=>{
|
|
228
244
|
if (isDisabled) {
|
|
229
245
|
return;
|
|
230
246
|
}
|
|
231
|
-
|
|
232
|
-
if (preventScrollCount === 1) {
|
|
233
|
-
if (isIOS()) {
|
|
234
|
-
restore = preventScrollMobileSafari();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
247
|
+
acquirePreventScrollLock(lockIdRef.current);
|
|
237
248
|
return ()=>{
|
|
238
|
-
|
|
239
|
-
if (preventScrollCount === 0) {
|
|
240
|
-
restore == null ? void 0 : restore();
|
|
241
|
-
}
|
|
249
|
+
releasePreventScrollLock(lockIdRef.current);
|
|
242
250
|
};
|
|
243
251
|
}, [
|
|
244
252
|
isDisabled
|
|
@@ -973,12 +981,23 @@ function useScaleBackground() {
|
|
|
973
981
|
const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();
|
|
974
982
|
const timeoutIdRef = React__namespace.default.useRef(null);
|
|
975
983
|
const initialBackgroundColor = React.useMemo(()=>document.body.style.backgroundColor, []);
|
|
984
|
+
React__namespace.default.useEffect(()=>{
|
|
985
|
+
return ()=>{
|
|
986
|
+
if (timeoutIdRef.current !== null) {
|
|
987
|
+
window.clearTimeout(timeoutIdRef.current);
|
|
988
|
+
timeoutIdRef.current = null;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
}, []);
|
|
976
992
|
function getScale() {
|
|
977
993
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
978
994
|
}
|
|
979
995
|
React__namespace.default.useEffect(()=>{
|
|
980
996
|
if (isOpen && shouldScaleBackground) {
|
|
981
|
-
if (timeoutIdRef.current)
|
|
997
|
+
if (timeoutIdRef.current !== null) {
|
|
998
|
+
clearTimeout(timeoutIdRef.current);
|
|
999
|
+
timeoutIdRef.current = null;
|
|
1000
|
+
}
|
|
982
1001
|
const wrapper = document.querySelector('[data-drawer-wrapper]');
|
|
983
1002
|
if (!wrapper) return;
|
|
984
1003
|
chain(setBackgroundColorOnScale && !noBodyStyles ? assignStyle(document.body, {
|
|
@@ -1006,6 +1025,7 @@ function useScaleBackground() {
|
|
|
1006
1025
|
} else {
|
|
1007
1026
|
document.body.style.removeProperty('background');
|
|
1008
1027
|
}
|
|
1028
|
+
timeoutIdRef.current = null;
|
|
1009
1029
|
}, TRANSITIONS.DURATION * 1000);
|
|
1010
1030
|
};
|
|
1011
1031
|
}
|
|
@@ -1017,6 +1037,14 @@ function useScaleBackground() {
|
|
|
1017
1037
|
}
|
|
1018
1038
|
|
|
1019
1039
|
let previousBodyPosition = null;
|
|
1040
|
+
const activeBodyPositionLocks = new Set();
|
|
1041
|
+
let bodyPositionTimeoutId = null;
|
|
1042
|
+
function clearBodyPositionTimeout() {
|
|
1043
|
+
if (bodyPositionTimeoutId !== null) {
|
|
1044
|
+
window.clearTimeout(bodyPositionTimeoutId);
|
|
1045
|
+
bodyPositionTimeoutId = null;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1020
1048
|
/**
|
|
1021
1049
|
* This hook is necessary to prevent buggy behavior on iOS devices (need to test on Android).
|
|
1022
1050
|
* I won't get into too much detail about what bugs it solves, but so far I've found that setting the body to `position: fixed` is the most reliable way to prevent those bugs.
|
|
@@ -1024,9 +1052,18 @@ let previousBodyPosition = null;
|
|
|
1024
1052
|
*/ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollRestoration, noBodyStyles }) {
|
|
1025
1053
|
const [activeUrl, setActiveUrl] = React__namespace.default.useState(()=>typeof window !== 'undefined' ? window.location.href : '');
|
|
1026
1054
|
const scrollPos = React__namespace.default.useRef(0);
|
|
1055
|
+
const lockIdRef = React__namespace.default.useRef();
|
|
1056
|
+
if (!lockIdRef.current) {
|
|
1057
|
+
lockIdRef.current = Symbol('drawer-body-position-lock');
|
|
1058
|
+
}
|
|
1027
1059
|
const setPositionFixed = React__namespace.default.useCallback(()=>{
|
|
1028
1060
|
// All browsers on iOS will return true here.
|
|
1029
1061
|
if (!isSafari()) return;
|
|
1062
|
+
const lockId = lockIdRef.current;
|
|
1063
|
+
if (activeBodyPositionLocks.has(lockId)) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
activeBodyPositionLocks.add(lockId);
|
|
1030
1067
|
// If previousBodyPosition is already set, don't set it again.
|
|
1031
1068
|
if (previousBodyPosition === null && isOpen && !noBodyStyles) {
|
|
1032
1069
|
previousBodyPosition = {
|
|
@@ -1045,7 +1082,8 @@ let previousBodyPosition = null;
|
|
|
1045
1082
|
right: '0px',
|
|
1046
1083
|
height: 'auto'
|
|
1047
1084
|
});
|
|
1048
|
-
|
|
1085
|
+
clearBodyPositionTimeout();
|
|
1086
|
+
bodyPositionTimeoutId = window.setTimeout(()=>window.requestAnimationFrame(()=>{
|
|
1049
1087
|
// Attempt to check if the bottom bar appeared due to the position change
|
|
1050
1088
|
const bottomBarHeight = innerHeight - window.innerHeight;
|
|
1051
1089
|
if (bottomBarHeight && scrollPos.current >= innerHeight) {
|
|
@@ -1055,12 +1093,19 @@ let previousBodyPosition = null;
|
|
|
1055
1093
|
}), 300);
|
|
1056
1094
|
}
|
|
1057
1095
|
}, [
|
|
1058
|
-
isOpen
|
|
1096
|
+
isOpen,
|
|
1097
|
+
noBodyStyles
|
|
1059
1098
|
]);
|
|
1060
1099
|
const restorePositionSetting = React__namespace.default.useCallback(()=>{
|
|
1061
1100
|
// All browsers on iOS will return true here.
|
|
1062
1101
|
if (!isSafari()) return;
|
|
1102
|
+
const lockId = lockIdRef.current;
|
|
1103
|
+
activeBodyPositionLocks.delete(lockId);
|
|
1104
|
+
if (activeBodyPositionLocks.size > 0) {
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1063
1107
|
if (previousBodyPosition !== null && !noBodyStyles) {
|
|
1108
|
+
clearBodyPositionTimeout();
|
|
1064
1109
|
// Convert the position from "px" to Int
|
|
1065
1110
|
const y = -parseInt(document.body.style.top, 10);
|
|
1066
1111
|
const x = -parseInt(document.body.style.left, 10);
|
|
@@ -1076,7 +1121,9 @@ let previousBodyPosition = null;
|
|
|
1076
1121
|
previousBodyPosition = null;
|
|
1077
1122
|
}
|
|
1078
1123
|
}, [
|
|
1079
|
-
activeUrl
|
|
1124
|
+
activeUrl,
|
|
1125
|
+
noBodyStyles,
|
|
1126
|
+
setActiveUrl
|
|
1080
1127
|
]);
|
|
1081
1128
|
React__namespace.default.useEffect(()=>{
|
|
1082
1129
|
function onScroll() {
|
|
@@ -1428,6 +1475,12 @@ function getDragPermission({ targetTagName, hasNoDragAttribute, direction, timeS
|
|
|
1428
1475
|
|
|
1429
1476
|
function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground = false, setBackgroundColorOnScale = true, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = false, direction = 'bottom', defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false }) {
|
|
1430
1477
|
var _drawerRef_current, _drawerRef_current1;
|
|
1478
|
+
const animationEndTimeoutRef = React__namespace.default.useRef(null);
|
|
1479
|
+
const nonModalPointerEventsRafRef = React__namespace.default.useRef(null);
|
|
1480
|
+
const shouldAnimateRafRef = React__namespace.default.useRef(null);
|
|
1481
|
+
const snapPointsResetTimeoutRef = React__namespace.default.useRef(null);
|
|
1482
|
+
const justReleasedTimeoutRef = React__namespace.default.useRef(null);
|
|
1483
|
+
const touchEndHandlerRef = React__namespace.default.useRef(null);
|
|
1431
1484
|
const [isOpen = false, setIsOpen] = useControllableState({
|
|
1432
1485
|
defaultProp: defaultOpen,
|
|
1433
1486
|
prop: openProp,
|
|
@@ -1436,13 +1489,20 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1436
1489
|
if (!o && !nested) {
|
|
1437
1490
|
restorePositionSetting();
|
|
1438
1491
|
}
|
|
1439
|
-
|
|
1492
|
+
if (animationEndTimeoutRef.current !== null) {
|
|
1493
|
+
window.clearTimeout(animationEndTimeoutRef.current);
|
|
1494
|
+
}
|
|
1495
|
+
animationEndTimeoutRef.current = window.setTimeout(()=>{
|
|
1440
1496
|
onAnimationEnd == null ? void 0 : onAnimationEnd(o);
|
|
1441
1497
|
}, TRANSITIONS.DURATION * 1000);
|
|
1442
1498
|
if (o && !modal) {
|
|
1443
1499
|
if (typeof window !== 'undefined') {
|
|
1444
|
-
|
|
1500
|
+
if (nonModalPointerEventsRafRef.current !== null) {
|
|
1501
|
+
window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
|
|
1502
|
+
}
|
|
1503
|
+
nonModalPointerEventsRafRef.current = window.requestAnimationFrame(()=>{
|
|
1445
1504
|
document.body.style.pointerEvents = 'auto';
|
|
1505
|
+
nonModalPointerEventsRafRef.current = null;
|
|
1446
1506
|
});
|
|
1447
1507
|
}
|
|
1448
1508
|
}
|
|
@@ -1551,7 +1611,15 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1551
1611
|
dragStartTime.current = new Date();
|
|
1552
1612
|
// iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging
|
|
1553
1613
|
if (isIOS()) {
|
|
1554
|
-
|
|
1614
|
+
if (touchEndHandlerRef.current) {
|
|
1615
|
+
window.removeEventListener('touchend', touchEndHandlerRef.current);
|
|
1616
|
+
}
|
|
1617
|
+
const handleTouchEnd = ()=>{
|
|
1618
|
+
isAllowedToDrag.current = false;
|
|
1619
|
+
touchEndHandlerRef.current = null;
|
|
1620
|
+
};
|
|
1621
|
+
touchEndHandlerRef.current = handleTouchEnd;
|
|
1622
|
+
window.addEventListener('touchend', handleTouchEnd, {
|
|
1555
1623
|
once: true
|
|
1556
1624
|
});
|
|
1557
1625
|
}
|
|
@@ -1668,9 +1736,15 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1668
1736
|
}
|
|
1669
1737
|
}
|
|
1670
1738
|
React__namespace.default.useEffect(()=>{
|
|
1671
|
-
window.requestAnimationFrame(()=>{
|
|
1739
|
+
shouldAnimateRafRef.current = window.requestAnimationFrame(()=>{
|
|
1672
1740
|
shouldAnimate.current = true;
|
|
1673
1741
|
});
|
|
1742
|
+
return ()=>{
|
|
1743
|
+
if (shouldAnimateRafRef.current !== null) {
|
|
1744
|
+
window.cancelAnimationFrame(shouldAnimateRafRef.current);
|
|
1745
|
+
shouldAnimateRafRef.current = null;
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1674
1748
|
}, []);
|
|
1675
1749
|
React__namespace.default.useEffect(()=>{
|
|
1676
1750
|
var _window_visualViewport;
|
|
@@ -1720,10 +1794,14 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1720
1794
|
if (!fromWithin) {
|
|
1721
1795
|
setIsOpen(false);
|
|
1722
1796
|
}
|
|
1723
|
-
|
|
1797
|
+
if (snapPointsResetTimeoutRef.current !== null) {
|
|
1798
|
+
window.clearTimeout(snapPointsResetTimeoutRef.current);
|
|
1799
|
+
}
|
|
1800
|
+
snapPointsResetTimeoutRef.current = window.setTimeout(()=>{
|
|
1724
1801
|
if (snapPoints) {
|
|
1725
1802
|
setActiveSnapPoint(snapPoints[0]);
|
|
1726
1803
|
}
|
|
1804
|
+
snapPointsResetTimeoutRef.current = null;
|
|
1727
1805
|
}, TRANSITIONS.DURATION * 1000); // seconds to ms
|
|
1728
1806
|
}
|
|
1729
1807
|
function resetDrawer() {
|
|
@@ -1797,8 +1875,12 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1797
1875
|
if (releaseResult.shouldPreventFocus) {
|
|
1798
1876
|
// `justReleased` is needed to prevent the drawer from focusing on an input when the drag ends, as it's not the intent most of the time.
|
|
1799
1877
|
setJustReleased(true);
|
|
1800
|
-
|
|
1878
|
+
if (justReleasedTimeoutRef.current !== null) {
|
|
1879
|
+
window.clearTimeout(justReleasedTimeoutRef.current);
|
|
1880
|
+
}
|
|
1881
|
+
justReleasedTimeoutRef.current = window.setTimeout(()=>{
|
|
1801
1882
|
setJustReleased(false);
|
|
1883
|
+
justReleasedTimeoutRef.current = null;
|
|
1802
1884
|
}, 200);
|
|
1803
1885
|
}
|
|
1804
1886
|
if (releaseResult.action === 'close') {
|
|
@@ -1875,12 +1957,45 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1875
1957
|
});
|
|
1876
1958
|
}
|
|
1877
1959
|
}
|
|
1960
|
+
React__namespace.default.useEffect(()=>{
|
|
1961
|
+
return ()=>{
|
|
1962
|
+
if (animationEndTimeoutRef.current !== null) {
|
|
1963
|
+
window.clearTimeout(animationEndTimeoutRef.current);
|
|
1964
|
+
}
|
|
1965
|
+
if (nonModalPointerEventsRafRef.current !== null) {
|
|
1966
|
+
window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
|
|
1967
|
+
}
|
|
1968
|
+
if (snapPointsResetTimeoutRef.current !== null) {
|
|
1969
|
+
window.clearTimeout(snapPointsResetTimeoutRef.current);
|
|
1970
|
+
}
|
|
1971
|
+
if (justReleasedTimeoutRef.current !== null) {
|
|
1972
|
+
window.clearTimeout(justReleasedTimeoutRef.current);
|
|
1973
|
+
}
|
|
1974
|
+
if (nestedOpenChangeTimer.current) {
|
|
1975
|
+
window.clearTimeout(nestedOpenChangeTimer.current);
|
|
1976
|
+
}
|
|
1977
|
+
if (touchEndHandlerRef.current) {
|
|
1978
|
+
window.removeEventListener('touchend', touchEndHandlerRef.current);
|
|
1979
|
+
touchEndHandlerRef.current = null;
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
}, []);
|
|
1878
1983
|
React__namespace.default.useEffect(()=>{
|
|
1879
1984
|
if (!modal) {
|
|
1880
1985
|
// Need to do this manually unfortunately
|
|
1881
|
-
|
|
1986
|
+
if (nonModalPointerEventsRafRef.current !== null) {
|
|
1987
|
+
window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
|
|
1988
|
+
}
|
|
1989
|
+
nonModalPointerEventsRafRef.current = window.requestAnimationFrame(()=>{
|
|
1882
1990
|
document.body.style.pointerEvents = 'auto';
|
|
1991
|
+
nonModalPointerEventsRafRef.current = null;
|
|
1883
1992
|
});
|
|
1993
|
+
return ()=>{
|
|
1994
|
+
if (nonModalPointerEventsRafRef.current !== null) {
|
|
1995
|
+
window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
|
|
1996
|
+
nonModalPointerEventsRafRef.current = null;
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1884
1999
|
}
|
|
1885
2000
|
}, [
|
|
1886
2001
|
modal
|
|
@@ -1964,15 +2079,25 @@ const Content = /*#__PURE__*/ React__namespace.default.forwardRef(function({ onP
|
|
|
1964
2079
|
const pointerStartRef = React__namespace.default.useRef(null);
|
|
1965
2080
|
const lastKnownPointerEventRef = React__namespace.default.useRef(null);
|
|
1966
2081
|
const wasBeyondThePointRef = React__namespace.default.useRef(false);
|
|
2082
|
+
const delayedSnapPointsRafRef = React__namespace.default.useRef(null);
|
|
1967
2083
|
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
1968
2084
|
useScaleBackground();
|
|
1969
2085
|
React__namespace.default.useEffect(()=>{
|
|
1970
2086
|
if (hasSnapPoints) {
|
|
1971
|
-
window.requestAnimationFrame(()=>{
|
|
2087
|
+
delayedSnapPointsRafRef.current = window.requestAnimationFrame(()=>{
|
|
1972
2088
|
setDelayedSnapPoints(true);
|
|
2089
|
+
delayedSnapPointsRafRef.current = null;
|
|
1973
2090
|
});
|
|
1974
2091
|
}
|
|
1975
|
-
|
|
2092
|
+
return ()=>{
|
|
2093
|
+
if (delayedSnapPointsRafRef.current !== null) {
|
|
2094
|
+
window.cancelAnimationFrame(delayedSnapPointsRafRef.current);
|
|
2095
|
+
delayedSnapPointsRafRef.current = null;
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
}, [
|
|
2099
|
+
hasSnapPoints
|
|
2100
|
+
]);
|
|
1976
2101
|
function handleOnPointerUp(event) {
|
|
1977
2102
|
pointerStartRef.current = null;
|
|
1978
2103
|
wasBeyondThePointRef.current = false;
|
|
@@ -2073,6 +2198,7 @@ const DOUBLE_TAP_TIMEOUT = 120;
|
|
|
2073
2198
|
const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ preventCycle = false, children, ...rest }, ref) {
|
|
2074
2199
|
const { closeDrawer, isDragging, snapPoints, activeSnapPoint, setActiveSnapPoint, dismissible, handleOnly, isOpen, onPress, onDrag } = useDrawerContext();
|
|
2075
2200
|
const closeTimeoutIdRef = React__namespace.default.useRef(null);
|
|
2201
|
+
const cycleTimeoutIdRef = React__namespace.default.useRef(null);
|
|
2076
2202
|
const shouldCancelInteractionRef = React__namespace.default.useRef(false);
|
|
2077
2203
|
function handleStartCycle() {
|
|
2078
2204
|
// Stop if this is the second click of a double click
|
|
@@ -2080,7 +2206,7 @@ const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ prev
|
|
|
2080
2206
|
handleCancelInteraction();
|
|
2081
2207
|
return;
|
|
2082
2208
|
}
|
|
2083
|
-
window.setTimeout(()=>{
|
|
2209
|
+
cycleTimeoutIdRef.current = window.setTimeout(()=>{
|
|
2084
2210
|
handleCycleSnapPoints();
|
|
2085
2211
|
}, DOUBLE_TAP_TIMEOUT);
|
|
2086
2212
|
}
|
|
@@ -2113,9 +2239,19 @@ const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ prev
|
|
|
2113
2239
|
function handleCancelInteraction() {
|
|
2114
2240
|
if (closeTimeoutIdRef.current) {
|
|
2115
2241
|
window.clearTimeout(closeTimeoutIdRef.current);
|
|
2242
|
+
closeTimeoutIdRef.current = null;
|
|
2243
|
+
}
|
|
2244
|
+
if (cycleTimeoutIdRef.current) {
|
|
2245
|
+
window.clearTimeout(cycleTimeoutIdRef.current);
|
|
2246
|
+
cycleTimeoutIdRef.current = null;
|
|
2116
2247
|
}
|
|
2117
2248
|
shouldCancelInteractionRef.current = false;
|
|
2118
2249
|
}
|
|
2250
|
+
React__namespace.default.useEffect(()=>{
|
|
2251
|
+
return ()=>{
|
|
2252
|
+
handleCancelInteraction();
|
|
2253
|
+
};
|
|
2254
|
+
}, []);
|
|
2119
2255
|
return /*#__PURE__*/ React__namespace.default.createElement("div", {
|
|
2120
2256
|
onClick: handleStartCycle,
|
|
2121
2257
|
onPointerCancel: handleCancelInteraction,
|
|
@@ -2254,7 +2390,9 @@ function VanillaNode({ value, dataAttribute }) {
|
|
|
2254
2390
|
const ref = React__namespace.default.useRef(null);
|
|
2255
2391
|
useSafeLayoutEffect(()=>{
|
|
2256
2392
|
const element = ref.current;
|
|
2257
|
-
if (!element)
|
|
2393
|
+
if (!element) {
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2258
2396
|
element.innerHTML = '';
|
|
2259
2397
|
if (value instanceof HTMLElement) {
|
|
2260
2398
|
element.appendChild(value);
|
|
@@ -2282,11 +2420,60 @@ function VanillaNode({ value, dataAttribute }) {
|
|
|
2282
2420
|
ref: ref
|
|
2283
2421
|
});
|
|
2284
2422
|
}
|
|
2423
|
+
function readAccessibleTextFromRoot(root, elementId) {
|
|
2424
|
+
var _root_textContent;
|
|
2425
|
+
if (!root || !elementId) {
|
|
2426
|
+
return undefined;
|
|
2427
|
+
}
|
|
2428
|
+
const elements = Array.from(root.querySelectorAll('[id]'));
|
|
2429
|
+
for (const element of elements){
|
|
2430
|
+
if (element instanceof HTMLElement && element.id === elementId) {
|
|
2431
|
+
var _element_textContent;
|
|
2432
|
+
const value = (_element_textContent = element.textContent) == null ? void 0 : _element_textContent.trim();
|
|
2433
|
+
return value ? value : undefined;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
return root.id === elementId ? ((_root_textContent = root.textContent) == null ? void 0 : _root_textContent.trim()) || undefined : undefined;
|
|
2437
|
+
}
|
|
2285
2438
|
function VanillaDrawerRenderer({ options, open, onOpenChange, onDragChange, onReleaseChange }) {
|
|
2439
|
+
var _resolvedContent_proxyTitle;
|
|
2286
2440
|
const { mountElement: _mountElement, triggerElement: _triggerElement, triggerText, showHandle, handleClassName, ariaLabel, ariaLabelledBy, ariaDescribedBy, title, titleVisuallyHidden, description, descriptionVisuallyHidden, content, overlayClassName, contentClassName, ...drawerOptions } = options;
|
|
2287
2441
|
const rootProps = toReactDrawerProps(drawerOptions, open, onOpenChange, onDragChange, onReleaseChange);
|
|
2288
2442
|
const shouldRenderHandle = Boolean(drawerOptions.handleOnly || showHandle);
|
|
2289
2443
|
const shouldRenderVanillaContent = title != null || description != null || content != null;
|
|
2444
|
+
const resolvedContent = React__namespace.default.useMemo(()=>{
|
|
2445
|
+
if (content instanceof HTMLElement) {
|
|
2446
|
+
return {
|
|
2447
|
+
value: content,
|
|
2448
|
+
proxyTitle: title == null ? readAccessibleTextFromRoot(content, ariaLabelledBy) : undefined,
|
|
2449
|
+
proxyDescription: description == null ? readAccessibleTextFromRoot(content, ariaDescribedBy) : undefined
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
if (typeof content === 'function') {
|
|
2453
|
+
const result = content();
|
|
2454
|
+
return {
|
|
2455
|
+
value: result,
|
|
2456
|
+
proxyTitle: title == null && result instanceof HTMLElement ? readAccessibleTextFromRoot(result, ariaLabelledBy) : undefined,
|
|
2457
|
+
proxyDescription: description == null && result instanceof HTMLElement ? readAccessibleTextFromRoot(result, ariaDescribedBy) : undefined
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
return {
|
|
2461
|
+
value: content,
|
|
2462
|
+
proxyTitle: undefined,
|
|
2463
|
+
proxyDescription: undefined
|
|
2464
|
+
};
|
|
2465
|
+
}, [
|
|
2466
|
+
ariaDescribedBy,
|
|
2467
|
+
ariaLabelledBy,
|
|
2468
|
+
content,
|
|
2469
|
+
description,
|
|
2470
|
+
title
|
|
2471
|
+
]);
|
|
2472
|
+
const proxyTitle = (_resolvedContent_proxyTitle = resolvedContent.proxyTitle) != null ? _resolvedContent_proxyTitle : title == null ? ariaLabel : undefined;
|
|
2473
|
+
const proxyDescription = resolvedContent.proxyDescription;
|
|
2474
|
+
const contentAriaLabel = title == null && !proxyTitle ? ariaLabel : undefined;
|
|
2475
|
+
const contentAriaLabelledBy = title == null && !proxyTitle ? ariaLabelledBy : undefined;
|
|
2476
|
+
const contentAriaDescribedBy = description == null && !proxyDescription ? ariaDescribedBy : undefined;
|
|
2290
2477
|
return /*#__PURE__*/ React__namespace.default.createElement(Drawer.Root, rootProps, triggerText ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Trigger, {
|
|
2291
2478
|
asChild: true
|
|
2292
2479
|
}, /*#__PURE__*/ React__namespace.default.createElement("button", {
|
|
@@ -2296,25 +2483,30 @@ function VanillaDrawerRenderer({ options, open, onOpenChange, onDragChange, onRe
|
|
|
2296
2483
|
className: overlayClassName
|
|
2297
2484
|
}), /*#__PURE__*/ React__namespace.default.createElement(Drawer.Content, {
|
|
2298
2485
|
className: contentClassName,
|
|
2299
|
-
"aria-label":
|
|
2300
|
-
"aria-labelledby":
|
|
2301
|
-
"aria-describedby":
|
|
2486
|
+
"aria-label": contentAriaLabel,
|
|
2487
|
+
"aria-labelledby": contentAriaLabelledBy,
|
|
2488
|
+
"aria-describedby": contentAriaDescribedBy
|
|
2302
2489
|
}, shouldRenderHandle ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Handle, {
|
|
2303
2490
|
className: handleClassName
|
|
2304
2491
|
}) : null, shouldRenderVanillaContent ? /*#__PURE__*/ React__namespace.default.createElement("div", {
|
|
2305
2492
|
"data-drawer-vanilla-node": ""
|
|
2306
|
-
},
|
|
2493
|
+
}, proxyTitle ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Title, {
|
|
2494
|
+
style: VISUALLY_HIDDEN_STYLE
|
|
2495
|
+
}, proxyTitle) : null, title != null ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Title, {
|
|
2307
2496
|
style: titleVisuallyHidden ? VISUALLY_HIDDEN_STYLE : undefined
|
|
2308
2497
|
}, /*#__PURE__*/ React__namespace.default.createElement(VanillaNode, {
|
|
2309
2498
|
value: title
|
|
2310
|
-
})) : null,
|
|
2499
|
+
})) : null, proxyDescription ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Description, {
|
|
2500
|
+
style: VISUALLY_HIDDEN_STYLE
|
|
2501
|
+
}, proxyDescription) : null, description != null ? /*#__PURE__*/ React__namespace.default.createElement(Drawer.Description, {
|
|
2311
2502
|
style: descriptionVisuallyHidden ? VISUALLY_HIDDEN_STYLE : undefined
|
|
2312
2503
|
}, /*#__PURE__*/ React__namespace.default.createElement(VanillaNode, {
|
|
2313
2504
|
value: description
|
|
2314
|
-
})) : null, /*#__PURE__*/ React__namespace.default.createElement(
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2505
|
+
})) : null, /*#__PURE__*/ React__namespace.default.createElement("div", {
|
|
2506
|
+
"data-drawer-vanilla-body": ""
|
|
2507
|
+
}, /*#__PURE__*/ React__namespace.default.createElement(VanillaNode, {
|
|
2508
|
+
value: resolvedContent.value
|
|
2509
|
+
}))) : null)));
|
|
2318
2510
|
}
|
|
2319
2511
|
|
|
2320
2512
|
function canUseDOM$1() {
|