@samline/drawer 2.0.4 → 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/vue/index.js CHANGED
@@ -1105,7 +1105,7 @@ var require_react_development = __commonJS({
1105
1105
  var dispatcher = resolveDispatcher();
1106
1106
  return dispatcher.useReducer(reducer, initialArg, init);
1107
1107
  }
1108
- function useRef10(initialValue) {
1108
+ function useRef11(initialValue) {
1109
1109
  var dispatcher = resolveDispatcher();
1110
1110
  return dispatcher.useRef(initialValue);
1111
1111
  }
@@ -1899,7 +1899,7 @@ var require_react_development = __commonJS({
1899
1899
  exports.useLayoutEffect = useLayoutEffect5;
1900
1900
  exports.useMemo = useMemo6;
1901
1901
  exports.useReducer = useReducer3;
1902
- exports.useRef = useRef10;
1902
+ exports.useRef = useRef11;
1903
1903
  exports.useState = useState10;
1904
1904
  exports.useSyncExternalStore = useSyncExternalStore;
1905
1905
  exports.useTransition = useTransition;
@@ -26990,25 +26990,34 @@ var nonTextInputTypes = /* @__PURE__ */ new Set([
26990
26990
  "submit",
26991
26991
  "reset"
26992
26992
  ]);
26993
- var preventScrollCount = 0;
26994
- var restore;
26993
+ var activePreventScrollLocks = /* @__PURE__ */ new Set();
26994
+ var activePreventScrollRestore = null;
26995
+ function acquirePreventScrollLock(lockId) {
26996
+ activePreventScrollLocks.add(lockId);
26997
+ if (activePreventScrollLocks.size === 1 && isIOS()) {
26998
+ activePreventScrollRestore = preventScrollMobileSafari();
26999
+ }
27000
+ }
27001
+ function releasePreventScrollLock(lockId) {
27002
+ activePreventScrollLocks.delete(lockId);
27003
+ if (activePreventScrollLocks.size === 0) {
27004
+ activePreventScrollRestore?.();
27005
+ activePreventScrollRestore = null;
27006
+ }
27007
+ }
26995
27008
  function usePreventScroll(options = {}) {
26996
27009
  let { isDisabled } = options;
27010
+ const lockIdRef = (0, import_react3.useRef)();
27011
+ if (!lockIdRef.current) {
27012
+ lockIdRef.current = /* @__PURE__ */ Symbol("drawer-prevent-scroll-lock");
27013
+ }
26997
27014
  useIsomorphicLayoutEffect2(() => {
26998
27015
  if (isDisabled) {
26999
27016
  return;
27000
27017
  }
27001
- preventScrollCount++;
27002
- if (preventScrollCount === 1) {
27003
- if (isIOS()) {
27004
- restore = preventScrollMobileSafari();
27005
- }
27006
- }
27018
+ acquirePreventScrollLock(lockIdRef.current);
27007
27019
  return () => {
27008
- preventScrollCount--;
27009
- if (preventScrollCount === 0) {
27010
- restore?.();
27011
- }
27020
+ releasePreventScrollLock(lockIdRef.current);
27012
27021
  };
27013
27022
  }, [isDisabled]);
27014
27023
  }
@@ -27582,12 +27591,23 @@ function useScaleBackground() {
27582
27591
  const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();
27583
27592
  const timeoutIdRef = import_react6.default.useRef(null);
27584
27593
  const initialBackgroundColor = (0, import_react6.useMemo)(() => document.body.style.backgroundColor, []);
27594
+ import_react6.default.useEffect(() => {
27595
+ return () => {
27596
+ if (timeoutIdRef.current !== null) {
27597
+ window.clearTimeout(timeoutIdRef.current);
27598
+ timeoutIdRef.current = null;
27599
+ }
27600
+ };
27601
+ }, []);
27585
27602
  function getScale() {
27586
27603
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
27587
27604
  }
27588
27605
  import_react6.default.useEffect(() => {
27589
27606
  if (isOpen && shouldScaleBackground) {
27590
- if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);
27607
+ if (timeoutIdRef.current !== null) {
27608
+ clearTimeout(timeoutIdRef.current);
27609
+ timeoutIdRef.current = null;
27610
+ }
27591
27611
  const wrapper = document.querySelector("[data-drawer-wrapper]");
27592
27612
  if (!wrapper) return;
27593
27613
  chain(
@@ -27616,6 +27636,7 @@ function useScaleBackground() {
27616
27636
  } else {
27617
27637
  document.body.style.removeProperty("background");
27618
27638
  }
27639
+ timeoutIdRef.current = null;
27619
27640
  }, TRANSITIONS.DURATION * 1e3);
27620
27641
  };
27621
27642
  }
@@ -27625,6 +27646,14 @@ function useScaleBackground() {
27625
27646
  // src/use-position-fixed.ts
27626
27647
  var import_react7 = __toESM(require_react());
27627
27648
  var previousBodyPosition = null;
27649
+ var activeBodyPositionLocks = /* @__PURE__ */ new Set();
27650
+ var bodyPositionTimeoutId = null;
27651
+ function clearBodyPositionTimeout() {
27652
+ if (bodyPositionTimeoutId !== null) {
27653
+ window.clearTimeout(bodyPositionTimeoutId);
27654
+ bodyPositionTimeoutId = null;
27655
+ }
27656
+ }
27628
27657
  function usePositionFixed({
27629
27658
  isOpen,
27630
27659
  modal,
@@ -27635,8 +27664,17 @@ function usePositionFixed({
27635
27664
  }) {
27636
27665
  const [activeUrl, setActiveUrl] = import_react7.default.useState(() => typeof window !== "undefined" ? window.location.href : "");
27637
27666
  const scrollPos = import_react7.default.useRef(0);
27667
+ const lockIdRef = import_react7.default.useRef();
27668
+ if (!lockIdRef.current) {
27669
+ lockIdRef.current = /* @__PURE__ */ Symbol("drawer-body-position-lock");
27670
+ }
27638
27671
  const setPositionFixed = import_react7.default.useCallback(() => {
27639
27672
  if (!isSafari()) return;
27673
+ const lockId = lockIdRef.current;
27674
+ if (activeBodyPositionLocks.has(lockId)) {
27675
+ return;
27676
+ }
27677
+ activeBodyPositionLocks.add(lockId);
27640
27678
  if (previousBodyPosition === null && isOpen && !noBodyStyles) {
27641
27679
  previousBodyPosition = {
27642
27680
  position: document.body.style.position,
@@ -27653,7 +27691,8 @@ function usePositionFixed({
27653
27691
  right: "0px",
27654
27692
  height: "auto"
27655
27693
  });
27656
- window.setTimeout(
27694
+ clearBodyPositionTimeout();
27695
+ bodyPositionTimeoutId = window.setTimeout(
27657
27696
  () => window.requestAnimationFrame(() => {
27658
27697
  const bottomBarHeight = innerHeight - window.innerHeight;
27659
27698
  if (bottomBarHeight && scrollPos.current >= innerHeight) {
@@ -27663,10 +27702,16 @@ function usePositionFixed({
27663
27702
  300
27664
27703
  );
27665
27704
  }
27666
- }, [isOpen]);
27705
+ }, [isOpen, noBodyStyles]);
27667
27706
  const restorePositionSetting = import_react7.default.useCallback(() => {
27668
27707
  if (!isSafari()) return;
27708
+ const lockId = lockIdRef.current;
27709
+ activeBodyPositionLocks.delete(lockId);
27710
+ if (activeBodyPositionLocks.size > 0) {
27711
+ return;
27712
+ }
27669
27713
  if (previousBodyPosition !== null && !noBodyStyles) {
27714
+ clearBodyPositionTimeout();
27670
27715
  const y = -parseInt(document.body.style.top, 10);
27671
27716
  const x = -parseInt(document.body.style.left, 10);
27672
27717
  Object.assign(document.body.style, previousBodyPosition);
@@ -27679,7 +27724,7 @@ function usePositionFixed({
27679
27724
  });
27680
27725
  previousBodyPosition = null;
27681
27726
  }
27682
- }, [activeUrl]);
27727
+ }, [activeUrl, noBodyStyles, setActiveUrl]);
27683
27728
  import_react7.default.useEffect(() => {
27684
27729
  function onScroll() {
27685
27730
  scrollPos.current = window.scrollY;
@@ -27977,6 +28022,12 @@ function Root2({
27977
28022
  container,
27978
28023
  autoFocus = false
27979
28024
  }) {
28025
+ const animationEndTimeoutRef = import_react9.default.useRef(null);
28026
+ const nonModalPointerEventsRafRef = import_react9.default.useRef(null);
28027
+ const shouldAnimateRafRef = import_react9.default.useRef(null);
28028
+ const snapPointsResetTimeoutRef = import_react9.default.useRef(null);
28029
+ const justReleasedTimeoutRef = import_react9.default.useRef(null);
28030
+ const touchEndHandlerRef = import_react9.default.useRef(null);
27980
28031
  const [isOpen = false, setIsOpen] = useControllableState2({
27981
28032
  defaultProp: defaultOpen,
27982
28033
  prop: openProp,
@@ -27985,13 +28036,20 @@ function Root2({
27985
28036
  if (!o && !nested) {
27986
28037
  restorePositionSetting();
27987
28038
  }
27988
- setTimeout(() => {
28039
+ if (animationEndTimeoutRef.current !== null) {
28040
+ window.clearTimeout(animationEndTimeoutRef.current);
28041
+ }
28042
+ animationEndTimeoutRef.current = window.setTimeout(() => {
27989
28043
  onAnimationEnd?.(o);
27990
28044
  }, TRANSITIONS.DURATION * 1e3);
27991
28045
  if (o && !modal) {
27992
28046
  if (typeof window !== "undefined") {
27993
- window.requestAnimationFrame(() => {
28047
+ if (nonModalPointerEventsRafRef.current !== null) {
28048
+ window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
28049
+ }
28050
+ nonModalPointerEventsRafRef.current = window.requestAnimationFrame(() => {
27994
28051
  document.body.style.pointerEvents = "auto";
28052
+ nonModalPointerEventsRafRef.current = null;
27995
28053
  });
27996
28054
  }
27997
28055
  }
@@ -28100,7 +28158,15 @@ function Root2({
28100
28158
  setIsDragging(true);
28101
28159
  dragStartTime.current = /* @__PURE__ */ new Date();
28102
28160
  if (isIOS()) {
28103
- window.addEventListener("touchend", () => isAllowedToDrag.current = false, { once: true });
28161
+ if (touchEndHandlerRef.current) {
28162
+ window.removeEventListener("touchend", touchEndHandlerRef.current);
28163
+ }
28164
+ const handleTouchEnd = () => {
28165
+ isAllowedToDrag.current = false;
28166
+ touchEndHandlerRef.current = null;
28167
+ };
28168
+ touchEndHandlerRef.current = handleTouchEnd;
28169
+ window.addEventListener("touchend", handleTouchEnd, { once: true });
28104
28170
  }
28105
28171
  event.target.setPointerCapture(event.pointerId);
28106
28172
  pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
@@ -28207,9 +28273,15 @@ function Root2({
28207
28273
  }
28208
28274
  }
28209
28275
  import_react9.default.useEffect(() => {
28210
- window.requestAnimationFrame(() => {
28276
+ shouldAnimateRafRef.current = window.requestAnimationFrame(() => {
28211
28277
  shouldAnimate.current = true;
28212
28278
  });
28279
+ return () => {
28280
+ if (shouldAnimateRafRef.current !== null) {
28281
+ window.cancelAnimationFrame(shouldAnimateRafRef.current);
28282
+ shouldAnimateRafRef.current = null;
28283
+ }
28284
+ };
28213
28285
  }, []);
28214
28286
  import_react9.default.useEffect(() => {
28215
28287
  function onVisualViewportChange() {
@@ -28250,10 +28322,14 @@ function Root2({
28250
28322
  if (!fromWithin) {
28251
28323
  setIsOpen(false);
28252
28324
  }
28253
- setTimeout(() => {
28325
+ if (snapPointsResetTimeoutRef.current !== null) {
28326
+ window.clearTimeout(snapPointsResetTimeoutRef.current);
28327
+ }
28328
+ snapPointsResetTimeoutRef.current = window.setTimeout(() => {
28254
28329
  if (snapPoints) {
28255
28330
  setActiveSnapPoint(snapPoints[0]);
28256
28331
  }
28332
+ snapPointsResetTimeoutRef.current = null;
28257
28333
  }, TRANSITIONS.DURATION * 1e3);
28258
28334
  }
28259
28335
  function resetDrawer() {
@@ -28328,8 +28404,12 @@ function Root2({
28328
28404
  });
28329
28405
  if (releaseResult.shouldPreventFocus) {
28330
28406
  setJustReleased(true);
28331
- setTimeout(() => {
28407
+ if (justReleasedTimeoutRef.current !== null) {
28408
+ window.clearTimeout(justReleasedTimeoutRef.current);
28409
+ }
28410
+ justReleasedTimeoutRef.current = window.setTimeout(() => {
28332
28411
  setJustReleased(false);
28412
+ justReleasedTimeoutRef.current = null;
28333
28413
  }, 200);
28334
28414
  }
28335
28415
  if (releaseResult.action === "close") {
@@ -28403,11 +28483,44 @@ function Root2({
28403
28483
  });
28404
28484
  }
28405
28485
  }
28486
+ import_react9.default.useEffect(() => {
28487
+ return () => {
28488
+ if (animationEndTimeoutRef.current !== null) {
28489
+ window.clearTimeout(animationEndTimeoutRef.current);
28490
+ }
28491
+ if (nonModalPointerEventsRafRef.current !== null) {
28492
+ window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
28493
+ }
28494
+ if (snapPointsResetTimeoutRef.current !== null) {
28495
+ window.clearTimeout(snapPointsResetTimeoutRef.current);
28496
+ }
28497
+ if (justReleasedTimeoutRef.current !== null) {
28498
+ window.clearTimeout(justReleasedTimeoutRef.current);
28499
+ }
28500
+ if (nestedOpenChangeTimer.current) {
28501
+ window.clearTimeout(nestedOpenChangeTimer.current);
28502
+ }
28503
+ if (touchEndHandlerRef.current) {
28504
+ window.removeEventListener("touchend", touchEndHandlerRef.current);
28505
+ touchEndHandlerRef.current = null;
28506
+ }
28507
+ };
28508
+ }, []);
28406
28509
  import_react9.default.useEffect(() => {
28407
28510
  if (!modal) {
28408
- window.requestAnimationFrame(() => {
28511
+ if (nonModalPointerEventsRafRef.current !== null) {
28512
+ window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
28513
+ }
28514
+ nonModalPointerEventsRafRef.current = window.requestAnimationFrame(() => {
28409
28515
  document.body.style.pointerEvents = "auto";
28516
+ nonModalPointerEventsRafRef.current = null;
28410
28517
  });
28518
+ return () => {
28519
+ if (nonModalPointerEventsRafRef.current !== null) {
28520
+ window.cancelAnimationFrame(nonModalPointerEventsRafRef.current);
28521
+ nonModalPointerEventsRafRef.current = null;
28522
+ }
28523
+ };
28411
28524
  }
28412
28525
  }, [modal]);
28413
28526
  return /* @__PURE__ */ import_react9.default.createElement(
@@ -28514,15 +28627,23 @@ var Content2 = import_react9.default.forwardRef(function({ onPointerDownOutside,
28514
28627
  const pointerStartRef = import_react9.default.useRef(null);
28515
28628
  const lastKnownPointerEventRef = import_react9.default.useRef(null);
28516
28629
  const wasBeyondThePointRef = import_react9.default.useRef(false);
28630
+ const delayedSnapPointsRafRef = import_react9.default.useRef(null);
28517
28631
  const hasSnapPoints = snapPoints && snapPoints.length > 0;
28518
28632
  useScaleBackground();
28519
28633
  import_react9.default.useEffect(() => {
28520
28634
  if (hasSnapPoints) {
28521
- window.requestAnimationFrame(() => {
28635
+ delayedSnapPointsRafRef.current = window.requestAnimationFrame(() => {
28522
28636
  setDelayedSnapPoints(true);
28637
+ delayedSnapPointsRafRef.current = null;
28523
28638
  });
28524
28639
  }
28525
- }, []);
28640
+ return () => {
28641
+ if (delayedSnapPointsRafRef.current !== null) {
28642
+ window.cancelAnimationFrame(delayedSnapPointsRafRef.current);
28643
+ delayedSnapPointsRafRef.current = null;
28644
+ }
28645
+ };
28646
+ }, [hasSnapPoints]);
28526
28647
  function handleOnPointerUp(event) {
28527
28648
  pointerStartRef.current = null;
28528
28649
  wasBeyondThePointRef.current = false;
@@ -28631,13 +28752,14 @@ var Handle = import_react9.default.forwardRef(function({ preventCycle = false, c
28631
28752
  onDrag
28632
28753
  } = useDrawerContext();
28633
28754
  const closeTimeoutIdRef = import_react9.default.useRef(null);
28755
+ const cycleTimeoutIdRef = import_react9.default.useRef(null);
28634
28756
  const shouldCancelInteractionRef = import_react9.default.useRef(false);
28635
28757
  function handleStartCycle() {
28636
28758
  if (shouldCancelInteractionRef.current) {
28637
28759
  handleCancelInteraction();
28638
28760
  return;
28639
28761
  }
28640
- window.setTimeout(() => {
28762
+ cycleTimeoutIdRef.current = window.setTimeout(() => {
28641
28763
  handleCycleSnapPoints();
28642
28764
  }, DOUBLE_TAP_TIMEOUT);
28643
28765
  }
@@ -28668,9 +28790,19 @@ var Handle = import_react9.default.forwardRef(function({ preventCycle = false, c
28668
28790
  function handleCancelInteraction() {
28669
28791
  if (closeTimeoutIdRef.current) {
28670
28792
  window.clearTimeout(closeTimeoutIdRef.current);
28793
+ closeTimeoutIdRef.current = null;
28794
+ }
28795
+ if (cycleTimeoutIdRef.current) {
28796
+ window.clearTimeout(cycleTimeoutIdRef.current);
28797
+ cycleTimeoutIdRef.current = null;
28671
28798
  }
28672
28799
  shouldCancelInteractionRef.current = false;
28673
28800
  }
28801
+ import_react9.default.useEffect(() => {
28802
+ return () => {
28803
+ handleCancelInteraction();
28804
+ };
28805
+ }, []);
28674
28806
  return /* @__PURE__ */ import_react9.default.createElement(
28675
28807
  "div",
28676
28808
  {