react-modal-sheet 5.2.1 → 5.2.3

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 CHANGED
@@ -6,7 +6,8 @@ type CommonProps = {
6
6
  className?: string;
7
7
  unstyled?: boolean;
8
8
  };
9
- type MotionCommonProps = Omit<ComponentPropsWithoutRef<typeof motion.div>, 'initial' | 'animate' | 'exit'>;
9
+ type MotionDivProps = ComponentPropsWithoutRef<typeof motion.div>;
10
+ type MotionCommonProps = Omit<MotionDivProps, 'initial' | 'animate' | 'exit'>;
10
11
  interface SheetTweenConfig {
11
12
  ease: EasingDefinition;
12
13
  duration: number;
@@ -50,7 +51,7 @@ type SheetContentProps = MotionCommonProps & CommonProps & {
50
51
  scrollClassName?: string;
51
52
  scrollStyle?: MotionProps['style'];
52
53
  };
53
- type SheetBackdropProps = MotionCommonProps & CommonProps;
54
+ type SheetBackdropProps = MotionDivProps & CommonProps;
54
55
  type SheetDragIndicatorProps = HTMLAttributes<HTMLDivElement> & CommonProps;
55
56
  type SheetStateInfo = {
56
57
  scrollPosition?: 'top' | 'bottom' | 'middle';
package/dist/index.d.ts CHANGED
@@ -6,7 +6,8 @@ type CommonProps = {
6
6
  className?: string;
7
7
  unstyled?: boolean;
8
8
  };
9
- type MotionCommonProps = Omit<ComponentPropsWithoutRef<typeof motion.div>, 'initial' | 'animate' | 'exit'>;
9
+ type MotionDivProps = ComponentPropsWithoutRef<typeof motion.div>;
10
+ type MotionCommonProps = Omit<MotionDivProps, 'initial' | 'animate' | 'exit'>;
10
11
  interface SheetTweenConfig {
11
12
  ease: EasingDefinition;
12
13
  duration: number;
@@ -50,7 +51,7 @@ type SheetContentProps = MotionCommonProps & CommonProps & {
50
51
  scrollClassName?: string;
51
52
  scrollStyle?: MotionProps['style'];
52
53
  };
53
- type SheetBackdropProps = MotionCommonProps & CommonProps;
54
+ type SheetBackdropProps = MotionDivProps & CommonProps;
54
55
  type SheetDragIndicatorProps = HTMLAttributes<HTMLDivElement> & CommonProps;
55
56
  type SheetStateInfo = {
56
57
  scrollPosition?: 'top' | 'bottom' | 'middle';
package/dist/index.js CHANGED
@@ -221,14 +221,14 @@ var SheetBackdrop = React4.forwardRef(
221
221
  return /* @__PURE__ */ React4__default.default.createElement(
222
222
  Comp,
223
223
  {
224
- ...rest,
225
- ref,
226
- className: `react-modal-sheet-backdrop ${className}`,
227
- style: backdropStyle,
228
224
  initial: { opacity: 0 },
229
225
  animate: { opacity: 1 },
230
226
  exit: { opacity: 0 },
231
- transition: { duration: 1 }
227
+ transition: { duration: 1 },
228
+ ...rest,
229
+ ref,
230
+ className: `react-modal-sheet-backdrop ${className}`,
231
+ style: backdropStyle
232
232
  }
233
233
  );
234
234
  }
@@ -277,63 +277,88 @@ function useDragConstraints() {
277
277
  const onMeasure = React4.useCallback(() => constraints, []);
278
278
  return { ref, onMeasure };
279
279
  }
280
+ var useIsomorphicLayoutEffect = IS_SSR ? React4.useEffect : React4.useLayoutEffect;
281
+
282
+ // src/hooks/use-stable-callback.ts
283
+ function useStableCallback(handler) {
284
+ const handlerRef = React4.useRef(void 0);
285
+ useIsomorphicLayoutEffect(() => {
286
+ handlerRef.current = handler;
287
+ });
288
+ return React4.useCallback((...args) => {
289
+ const fn = handlerRef.current;
290
+ return fn == null ? void 0 : fn(...args);
291
+ }, []);
292
+ }
293
+
294
+ // src/hooks/use-scroll-position.ts
280
295
  function useScrollPosition(options = {}) {
281
296
  const { debounceDelay = 32, isEnabled = true } = options;
297
+ const scrollTimeoutRef = React4.useRef(null);
282
298
  const [element, setElement] = React4.useState(null);
283
299
  const [scrollPosition, setScrollPosition] = React4.useState(void 0);
284
- React4.useEffect(() => {
285
- if (!element || !isEnabled) return;
286
- let scrollTimeout = null;
287
- function determineScrollPosition(element2) {
288
- const { scrollTop, scrollHeight, clientHeight } = element2;
289
- const isScrollable2 = scrollHeight > clientHeight;
290
- if (!isScrollable2) {
291
- if (scrollPosition) setScrollPosition(void 0);
292
- return;
293
- }
294
- const isAtTop = scrollTop <= 0;
295
- const isAtBottom = Math.ceil(scrollHeight) - Math.ceil(scrollTop) === Math.ceil(clientHeight);
296
- let position;
297
- if (isAtTop) {
298
- position = "top";
299
- } else if (isAtBottom) {
300
- position = "bottom";
301
- } else {
302
- position = "middle";
303
- }
304
- if (position === scrollPosition) return;
305
- setScrollPosition(position);
300
+ const scrollRef = React4.useMemo(
301
+ () => (element2) => {
302
+ setElement(element2);
303
+ },
304
+ []
305
+ );
306
+ const determineScrollPosition = useStableCallback((element2) => {
307
+ const { scrollTop, scrollHeight, clientHeight } = element2;
308
+ const isScrollable2 = scrollHeight > clientHeight;
309
+ if (!isScrollable2) {
310
+ if (scrollPosition) setScrollPosition(void 0);
311
+ return;
306
312
  }
307
- function onScroll(event) {
308
- if (event.currentTarget instanceof HTMLElement) {
309
- const el = event.currentTarget;
310
- if (scrollTimeout) clearTimeout(scrollTimeout);
311
- if (debounceDelay === 0) {
312
- determineScrollPosition(el);
313
- } else {
314
- scrollTimeout = setTimeout(
315
- () => determineScrollPosition(el),
316
- debounceDelay
317
- );
318
- }
319
- }
313
+ const isAtTop = scrollTop <= 0;
314
+ const isAtBottom = Math.ceil(scrollHeight) - Math.ceil(scrollTop) === Math.ceil(clientHeight);
315
+ let position;
316
+ if (isAtTop) {
317
+ position = "top";
318
+ } else if (isAtBottom) {
319
+ position = "bottom";
320
+ } else {
321
+ position = "middle";
320
322
  }
321
- function onTouchStart(event) {
322
- if (event.currentTarget instanceof HTMLElement) {
323
- determineScrollPosition(event.currentTarget);
323
+ element2.style.touchAction = isAtTop ? "pan-down" : "";
324
+ if (position === scrollPosition) return;
325
+ setScrollPosition(position);
326
+ });
327
+ const onScroll = useStableCallback((event) => {
328
+ if (event.currentTarget instanceof HTMLElement) {
329
+ const el = event.currentTarget;
330
+ if (scrollTimeoutRef.current) clearTimeout(scrollTimeoutRef.current);
331
+ if (debounceDelay === 0) {
332
+ determineScrollPosition(el);
333
+ } else {
334
+ scrollTimeoutRef.current = setTimeout(
335
+ () => determineScrollPosition(el),
336
+ debounceDelay
337
+ );
324
338
  }
325
339
  }
340
+ });
341
+ const onTouchStart = useStableCallback((event) => {
342
+ if (event.currentTarget instanceof HTMLElement) {
343
+ const element2 = event.currentTarget;
344
+ requestAnimationFrame(() => {
345
+ determineScrollPosition(element2);
346
+ });
347
+ }
348
+ });
349
+ React4.useEffect(() => {
350
+ if (!element || !isEnabled) return;
326
351
  determineScrollPosition(element);
327
352
  element.addEventListener("scroll", onScroll);
328
353
  element.addEventListener("touchstart", onTouchStart);
329
354
  return () => {
330
- if (scrollTimeout) clearTimeout(scrollTimeout);
355
+ if (scrollTimeoutRef.current) clearTimeout(scrollTimeoutRef.current);
331
356
  element.removeEventListener("scroll", onScroll);
332
357
  element.removeEventListener("touchstart", onTouchStart);
333
358
  };
334
359
  }, [element, isEnabled]);
335
360
  return {
336
- scrollRef: (element2) => setElement(element2),
361
+ scrollRef,
337
362
  scrollPosition
338
363
  };
339
364
  }
@@ -354,7 +379,9 @@ var SheetContent = React4.forwardRef(
354
379
  }, ref) => {
355
380
  const sheetContext = useSheetContext();
356
381
  const dragConstraints = useDragConstraints();
357
- const scroll = useScrollPosition();
382
+ const scroll = useScrollPosition({
383
+ isEnabled: typeof disableScrollProp === "function" ? true : !disableScrollProp
384
+ });
358
385
  const disableScroll = typeof disableScrollProp === "function" ? disableScrollProp({
359
386
  scrollPosition: scroll.scrollPosition,
360
387
  currentSnap: sheetContext.currentSnap
@@ -378,6 +405,9 @@ var SheetContent = React4.forwardRef(
378
405
  if (disableScroll) {
379
406
  scrollStyle.overflowY = "hidden";
380
407
  }
408
+ if (dragProps !== void 0) {
409
+ scrollStyle.touchAction = "pan-down";
410
+ }
381
411
  return /* @__PURE__ */ React4__default.default.createElement(
382
412
  react.motion.div,
383
413
  {
@@ -473,9 +503,6 @@ var SheetHeader = React4.forwardRef(
473
503
  }
474
504
  );
475
505
  SheetHeader.displayName = "SheetHeader";
476
- var useIsomorphicLayoutEffect = IS_SSR ? React4.useEffect : React4.useLayoutEffect;
477
-
478
- // src/hooks/use-dimensions.ts
479
506
  function useDimensions() {
480
507
  const [dimensions, setDimensions] = React4.useState(() => ({
481
508
  windowHeight: !IS_SSR ? window.innerHeight : 0,
@@ -836,18 +863,6 @@ function scrollIntoView(target) {
836
863
  function willOpenKeyboard(target) {
837
864
  return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
838
865
  }
839
- function useStableCallback(handler) {
840
- const handlerRef = React4.useRef(void 0);
841
- useIsomorphicLayoutEffect(() => {
842
- handlerRef.current = handler;
843
- });
844
- return React4.useCallback((...args) => {
845
- const fn = handlerRef.current;
846
- return fn == null ? void 0 : fn(...args);
847
- }, []);
848
- }
849
-
850
- // src/hooks/use-sheet-state.ts
851
866
  function useSheetState({
852
867
  isOpen,
853
868
  onClosed: _onClosed,