@super-calendar/native 2.20.0 → 2.20.1

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/README.md CHANGED
@@ -29,7 +29,7 @@ npm install @super-calendar/native
29
29
 
30
30
  Also on [JSR](https://jsr.io/@super-calendar/native): `deno add jsr:@super-calendar/native`.
31
31
 
32
- Peer dependencies: `@legendapp/list` (>=3), `date-fns` (>=3), `react` (>=19), `react-native` (>=0.74 <2), `react-native-gesture-handler` (>=2), `react-native-reanimated` (>=4), and `react-native-worklets` (>=0.8).
32
+ Peer dependencies: `@legendapp/list` (>=3.7.1), `date-fns` (>=3), `react` (>=19), `react-native` (>=0.74 <2), `react-native-gesture-handler` (>=2), `react-native-reanimated` (>=4), and `react-native-worklets` (>=0.8).
33
33
 
34
34
  For a picker-only bundle that does not require Reanimated, import from the `@super-calendar/native/picker` subpath.
35
35
 
@@ -816,17 +816,19 @@ function DateRowsInner({ source, events, maxVisibleEventCount, chipHeight, chipG
816
816
  if (!(0, _super_calendar_core.isDateSelectable)(origin.day, constraints) || !(0, _super_calendar_core.isDateSelectable)(destination, constraints) || (origin.event ? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
817
817
  });
818
818
  const hitTest = (0, react.useCallback)((x, y) => {
819
- const { width, height } = gridSize;
819
+ let { width, height } = gridSize;
820
+ if ((width <= 0 || height <= 0) && isWeb$2 && gridRef.current instanceof Element) ({width, height} = gridRef.current.getBoundingClientRect());
820
821
  if (width <= 0 || height <= 0 || weeks.length === 0) return null;
821
- let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
822
- let rowTop = row * rowHeight;
822
+ const pitch = rowHeight > 0 ? rowHeight : height / weeks.length;
823
+ let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / pitch)));
824
+ let rowTop = row * pitch;
823
825
  if (multiWeek) {
824
826
  const grid = isWeb$2 && typeof Element !== "undefined" && gridRef.current instanceof Element ? gridRef.current : null;
825
827
  const gridTop = grid?.getBoundingClientRect().top ?? 0;
826
828
  const topOf = (index) => {
827
829
  const node = grid?.children[index];
828
830
  const borderTop = node ? node.getBoundingClientRect().top - gridTop : weekTops.current[index];
829
- return borderTop == null ? index * rowHeight : borderTop - cellGeometry.weekMarginTop;
831
+ return borderTop == null ? index * pitch : borderTop - cellGeometry.weekMarginTop;
830
832
  };
831
833
  row = weekAtOffset(y, weeks.length, topOf);
832
834
  rowTop = topOf(row);
@@ -1664,6 +1666,15 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1664
1666
  animated: false
1665
1667
  });
1666
1668
  }, [activeIndex]);
1669
+ const laidOutWidthRef = (0, react.useRef)(containerWidth);
1670
+ (0, react.useLayoutEffect)(() => {
1671
+ if (containerWidth === laidOutWidthRef.current) return;
1672
+ laidOutWidthRef.current = containerWidth;
1673
+ listRef.current?.scrollToIndex({
1674
+ index: activeIndex,
1675
+ animated: false
1676
+ });
1677
+ }, [containerWidth, activeIndex]);
1667
1678
  useWebPagerKeys(swipeEnabled, (0, react.useCallback)((delta) => {
1668
1679
  const target = monthDates[activeIndex + delta];
1669
1680
  if (target) onChangeDate(target);
@@ -1683,6 +1694,8 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1683
1694
  ]);
1684
1695
  const nowTime = now?.getTime();
1685
1696
  const monthExtraData = (0, react.useMemo)(() => ({
1697
+ containerWidth,
1698
+ pageHeight,
1686
1699
  events,
1687
1700
  activeDate,
1688
1701
  nowTime,
@@ -1696,6 +1709,8 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1696
1709
  createGhostClassName: classNames?.createGhost,
1697
1710
  createGhostStyle: styleOverrides?.createGhost
1698
1711
  }), [
1712
+ containerWidth,
1713
+ pageHeight,
1699
1714
  events,
1700
1715
  activeDate,
1701
1716
  nowTime,
@@ -1740,6 +1755,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1740
1755
  const keyExtractorList = (0, react.useCallback)((item) => item.toISOString(), []);
1741
1756
  const getFixedItemSize = (0, react.useCallback)(() => containerWidth, [containerWidth]);
1742
1757
  const renderItem = (0, react.useCallback)(({ item }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
1758
+ testID: "month-pager-page",
1743
1759
  style: {
1744
1760
  width: containerWidth,
1745
1761
  height: pageHeight
@@ -1863,6 +1879,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1863
1879
  slot
1864
1880
  }),
1865
1881
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
1882
+ testID: "month-pager",
1866
1883
  style: styles$2.pager,
1867
1884
  onLayout: (event) => {
1868
1885
  setPageHeight(event.nativeEvent.layout.height);
@@ -1887,7 +1904,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1887
1904
  viewabilityConfig: PAGE_VIEWABILITY,
1888
1905
  onViewableItemsChanged: handleViewableItemsChanged,
1889
1906
  renderItem
1890
- }, pageHeight)
1907
+ })
1891
1908
  })
1892
1909
  ]
1893
1910
  })
@@ -2101,13 +2118,17 @@ function MonthListInner({ date, events = NO_EVENTS, weekStartsOn, weekdayFormat
2101
2118
  activeDate,
2102
2119
  firstViewableIndex,
2103
2120
  chipHeight,
2104
- chipGap
2121
+ chipGap,
2122
+ weekRowHeight,
2123
+ monthHeaderHeight
2105
2124
  }), [
2106
2125
  events,
2107
2126
  activeDate,
2108
2127
  firstViewableIndex,
2109
2128
  chipHeight,
2110
- chipGap
2129
+ chipGap,
2130
+ weekRowHeight,
2131
+ monthHeaderHeight
2111
2132
  ]);
2112
2133
  const [anchorDate] = (0, react.useState)(date);
2113
2134
  const anchor = (0, react.useMemo)(() => (0, date_fns.startOfMonth)(anchorDate), [anchorDate]);
@@ -816,17 +816,19 @@ function DateRowsInner({ source, events, maxVisibleEventCount, chipHeight, chipG
816
816
  if (!isDateSelectable(origin.day, constraints) || !isDateSelectable(destination, constraints) || (origin.event ? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
817
817
  });
818
818
  const hitTest = useCallback((x, y) => {
819
- const { width, height } = gridSize;
819
+ let { width, height } = gridSize;
820
+ if ((width <= 0 || height <= 0) && isWeb$2 && gridRef.current instanceof Element) ({width, height} = gridRef.current.getBoundingClientRect());
820
821
  if (width <= 0 || height <= 0 || weeks.length === 0) return null;
821
- let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
822
- let rowTop = row * rowHeight;
822
+ const pitch = rowHeight > 0 ? rowHeight : height / weeks.length;
823
+ let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / pitch)));
824
+ let rowTop = row * pitch;
823
825
  if (multiWeek) {
824
826
  const grid = isWeb$2 && typeof Element !== "undefined" && gridRef.current instanceof Element ? gridRef.current : null;
825
827
  const gridTop = grid?.getBoundingClientRect().top ?? 0;
826
828
  const topOf = (index) => {
827
829
  const node = grid?.children[index];
828
830
  const borderTop = node ? node.getBoundingClientRect().top - gridTop : weekTops.current[index];
829
- return borderTop == null ? index * rowHeight : borderTop - cellGeometry.weekMarginTop;
831
+ return borderTop == null ? index * pitch : borderTop - cellGeometry.weekMarginTop;
830
832
  };
831
833
  row = weekAtOffset(y, weeks.length, topOf);
832
834
  rowTop = topOf(row);
@@ -1664,6 +1666,15 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1664
1666
  animated: false
1665
1667
  });
1666
1668
  }, [activeIndex]);
1669
+ const laidOutWidthRef = useRef(containerWidth);
1670
+ useLayoutEffect(() => {
1671
+ if (containerWidth === laidOutWidthRef.current) return;
1672
+ laidOutWidthRef.current = containerWidth;
1673
+ listRef.current?.scrollToIndex({
1674
+ index: activeIndex,
1675
+ animated: false
1676
+ });
1677
+ }, [containerWidth, activeIndex]);
1667
1678
  useWebPagerKeys(swipeEnabled, useCallback((delta) => {
1668
1679
  const target = monthDates[activeIndex + delta];
1669
1680
  if (target) onChangeDate(target);
@@ -1683,6 +1694,8 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1683
1694
  ]);
1684
1695
  const nowTime = now?.getTime();
1685
1696
  const monthExtraData = useMemo(() => ({
1697
+ containerWidth,
1698
+ pageHeight,
1686
1699
  events,
1687
1700
  activeDate,
1688
1701
  nowTime,
@@ -1696,6 +1709,8 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1696
1709
  createGhostClassName: classNames?.createGhost,
1697
1710
  createGhostStyle: styleOverrides?.createGhost
1698
1711
  }), [
1712
+ containerWidth,
1713
+ pageHeight,
1699
1714
  events,
1700
1715
  activeDate,
1701
1716
  nowTime,
@@ -1740,6 +1755,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1740
1755
  const keyExtractorList = useCallback((item) => item.toISOString(), []);
1741
1756
  const getFixedItemSize = useCallback(() => containerWidth, [containerWidth]);
1742
1757
  const renderItem = useCallback(({ item }) => /* @__PURE__ */ jsx(View, {
1758
+ testID: "month-pager-page",
1743
1759
  style: {
1744
1760
  width: containerWidth,
1745
1761
  height: pageHeight
@@ -1863,6 +1879,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1863
1879
  slot
1864
1880
  }),
1865
1881
  /* @__PURE__ */ jsx(View, {
1882
+ testID: "month-pager",
1866
1883
  style: styles$2.pager,
1867
1884
  onLayout: (event) => {
1868
1885
  setPageHeight(event.nativeEvent.layout.height);
@@ -1887,7 +1904,7 @@ function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEvent
1887
1904
  viewabilityConfig: PAGE_VIEWABILITY,
1888
1905
  onViewableItemsChanged: handleViewableItemsChanged,
1889
1906
  renderItem
1890
- }, pageHeight)
1907
+ })
1891
1908
  })
1892
1909
  ]
1893
1910
  })
@@ -2101,13 +2118,17 @@ function MonthListInner({ date, events = NO_EVENTS, weekStartsOn, weekdayFormat
2101
2118
  activeDate,
2102
2119
  firstViewableIndex,
2103
2120
  chipHeight,
2104
- chipGap
2121
+ chipGap,
2122
+ weekRowHeight,
2123
+ monthHeaderHeight
2105
2124
  }), [
2106
2125
  events,
2107
2126
  activeDate,
2108
2127
  firstViewableIndex,
2109
2128
  chipHeight,
2110
- chipGap
2129
+ chipGap,
2130
+ weekRowHeight,
2131
+ monthHeaderHeight
2111
2132
  ]);
2112
2133
  const [anchorDate] = useState(date);
2113
2134
  const anchor = useMemo(() => startOfMonth(anchorDate), [anchorDate]);
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- const require_MonthList = require("./MonthList-DeO-x5VW.js");
23
+ const require_MonthList = require("./MonthList-CGgy0Juh.js");
24
24
  let date_fns = require("date-fns");
25
25
  let react = require("react");
26
26
  let react_native_reanimated = require("react-native-reanimated");
@@ -2605,9 +2605,25 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2605
2605
  animated: false
2606
2606
  });
2607
2607
  }, [activeIndex]);
2608
- (0, react.useEffect)(() => {
2608
+ const laidOutWidthRef = (0, react.useRef)(null);
2609
+ (0, react.useLayoutEffect)(() => {
2609
2610
  pagerOffset.value = activeIndex * columnsWidth;
2610
- }, [columnsWidth, pagerOffset]);
2611
+ if (!pagerReady) {
2612
+ laidOutWidthRef.current = null;
2613
+ return;
2614
+ }
2615
+ const previous = laidOutWidthRef.current;
2616
+ laidOutWidthRef.current = columnsWidth;
2617
+ if (previous == null || previous === columnsWidth) return;
2618
+ listRef.current?.scrollToIndex({
2619
+ index: activeIndex,
2620
+ animated: false
2621
+ });
2622
+ }, [
2623
+ columnsWidth,
2624
+ pagerOffset,
2625
+ pagerReady
2626
+ ]);
2611
2627
  (0, react.useEffect)(() => {
2612
2628
  if (!isWeb$1) return;
2613
2629
  let attempts = 0;
@@ -2701,8 +2717,12 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2701
2717
  pageDates,
2702
2718
  onChangeDate
2703
2719
  ]);
2720
+ const pagerDraggingRef = (0, react.useRef)(false);
2721
+ const pagerUserScrollRef = (0, react.useRef)(false);
2704
2722
  const handlePagerSettled = (0, react.useCallback)((event) => {
2705
2723
  if (columnsWidth <= 0) return;
2724
+ if (!pagerUserScrollRef.current || pagerDraggingRef.current) return;
2725
+ pagerUserScrollRef.current = false;
2706
2726
  if (pendingScrollIndexRef.current != null) return;
2707
2727
  const index = commitNearestPage(event.nativeEvent.contentOffset.x);
2708
2728
  pagerOffset.value = index * columnsWidth;
@@ -2717,7 +2737,6 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2717
2737
  commitNearestPage,
2718
2738
  pagerOffset
2719
2739
  ]);
2720
- const pagerDraggingRef = (0, react.useRef)(false);
2721
2740
  const lastPagerScrollRef = (0, react.useRef)({
2722
2741
  offsetX: 0,
2723
2742
  at: 0
@@ -2766,6 +2785,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2766
2785
  }, [armPagerIdleTimer]);
2767
2786
  const handlePagerDragStart = (0, react.useCallback)(() => {
2768
2787
  pagerDraggingRef.current = true;
2788
+ pagerUserScrollRef.current = true;
2769
2789
  }, []);
2770
2790
  const handlePagerDragEnd = (0, react.useCallback)(() => {
2771
2791
  pagerDraggingRef.current = false;
@@ -3018,18 +3038,16 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
3018
3038
  disableIntervalMomentum: !freeSwipe,
3019
3039
  scrollEventThrottle: 16,
3020
3040
  onMomentumScrollEnd: handlePagerSettled,
3021
- ...react_native.Platform.OS === "android" ? {
3022
- onScroll: handlePagerScroll,
3023
- onScrollBeginDrag: handlePagerDragStart,
3024
- onScrollEndDrag: handlePagerDragEnd
3025
- } : null
3041
+ onScrollBeginDrag: handlePagerDragStart,
3042
+ onScrollEndDrag: handlePagerDragEnd,
3043
+ ...react_native.Platform.OS === "android" ? { onScroll: handlePagerScroll } : null
3026
3044
  },
3027
3045
  initialScrollIndex: activeIndex,
3028
3046
  showsHorizontalScrollIndicator: false,
3029
3047
  viewabilityConfig: PAGE_VIEWABILITY,
3030
3048
  onViewableItemsChanged: handleViewableItemsChanged,
3031
3049
  renderItem
3032
- }, `grid-${columnsWidth}`) : null, liftedEvent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DragGhost, {
3050
+ }) : null, liftedEvent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DragGhost, {
3033
3051
  x: ghostX,
3034
3052
  y: ghostY,
3035
3053
  w: ghostW,
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as mergeTheme, a as DateRows, c as useWebPagerKeys, d as useSlots, f as CalendarLabelsContext, g as defaultTheme, h as darkTheme, i as MonthPager, l as SlotStylesProvider, m as CalendarThemeProvider, n as DefaultMonthEvent, o as MonthView, p as useCalendarLabels, r as DateRowsPager, s as withEventAccessibilityLabel, t as MonthList, u as createSlots, v as useCalendarTheme } from "./MonthList-BGl1gTDr.mjs";
1
+ import { _ as mergeTheme, a as DateRows, c as useWebPagerKeys, d as useSlots, f as CalendarLabelsContext, g as defaultTheme, h as darkTheme, i as MonthPager, l as SlotStylesProvider, m as CalendarThemeProvider, n as DefaultMonthEvent, o as MonthView, p as useCalendarLabels, r as DateRowsPager, s as withEventAccessibilityLabel, t as MonthList, u as createSlots, v as useCalendarTheme } from "./MonthList-CPpsr5Oa.mjs";
2
2
  import { addDays, addMonths, addWeeks, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getHours, getISOWeek, getMinutes, isSameDay, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
3
3
  import { createContext, forwardRef, memo, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
4
4
  import Animated, { runOnJS, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useReducedMotion, useSharedValue } from "react-native-reanimated";
@@ -2582,9 +2582,25 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2582
2582
  animated: false
2583
2583
  });
2584
2584
  }, [activeIndex]);
2585
- useEffect(() => {
2585
+ const laidOutWidthRef = useRef(null);
2586
+ useLayoutEffect(() => {
2586
2587
  pagerOffset.value = activeIndex * columnsWidth;
2587
- }, [columnsWidth, pagerOffset]);
2588
+ if (!pagerReady) {
2589
+ laidOutWidthRef.current = null;
2590
+ return;
2591
+ }
2592
+ const previous = laidOutWidthRef.current;
2593
+ laidOutWidthRef.current = columnsWidth;
2594
+ if (previous == null || previous === columnsWidth) return;
2595
+ listRef.current?.scrollToIndex({
2596
+ index: activeIndex,
2597
+ animated: false
2598
+ });
2599
+ }, [
2600
+ columnsWidth,
2601
+ pagerOffset,
2602
+ pagerReady
2603
+ ]);
2588
2604
  useEffect(() => {
2589
2605
  if (!isWeb$1) return;
2590
2606
  let attempts = 0;
@@ -2678,8 +2694,12 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2678
2694
  pageDates,
2679
2695
  onChangeDate
2680
2696
  ]);
2697
+ const pagerDraggingRef = useRef(false);
2698
+ const pagerUserScrollRef = useRef(false);
2681
2699
  const handlePagerSettled = useCallback((event) => {
2682
2700
  if (columnsWidth <= 0) return;
2701
+ if (!pagerUserScrollRef.current || pagerDraggingRef.current) return;
2702
+ pagerUserScrollRef.current = false;
2683
2703
  if (pendingScrollIndexRef.current != null) return;
2684
2704
  const index = commitNearestPage(event.nativeEvent.contentOffset.x);
2685
2705
  pagerOffset.value = index * columnsWidth;
@@ -2694,7 +2714,6 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2694
2714
  commitNearestPage,
2695
2715
  pagerOffset
2696
2716
  ]);
2697
- const pagerDraggingRef = useRef(false);
2698
2717
  const lastPagerScrollRef = useRef({
2699
2718
  offsetX: 0,
2700
2719
  at: 0
@@ -2743,6 +2762,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2743
2762
  }, [armPagerIdleTimer]);
2744
2763
  const handlePagerDragStart = useCallback(() => {
2745
2764
  pagerDraggingRef.current = true;
2765
+ pagerUserScrollRef.current = true;
2746
2766
  }, []);
2747
2767
  const handlePagerDragEnd = useCallback(() => {
2748
2768
  pagerDraggingRef.current = false;
@@ -2995,18 +3015,16 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
2995
3015
  disableIntervalMomentum: !freeSwipe,
2996
3016
  scrollEventThrottle: 16,
2997
3017
  onMomentumScrollEnd: handlePagerSettled,
2998
- ...Platform.OS === "android" ? {
2999
- onScroll: handlePagerScroll,
3000
- onScrollBeginDrag: handlePagerDragStart,
3001
- onScrollEndDrag: handlePagerDragEnd
3002
- } : null
3018
+ onScrollBeginDrag: handlePagerDragStart,
3019
+ onScrollEndDrag: handlePagerDragEnd,
3020
+ ...Platform.OS === "android" ? { onScroll: handlePagerScroll } : null
3003
3021
  },
3004
3022
  initialScrollIndex: activeIndex,
3005
3023
  showsHorizontalScrollIndicator: false,
3006
3024
  viewabilityConfig: PAGE_VIEWABILITY,
3007
3025
  onViewableItemsChanged: handleViewableItemsChanged,
3008
3026
  renderItem
3009
- }, `grid-${columnsWidth}`) : null, liftedEvent ? /* @__PURE__ */ jsx(DragGhost, {
3027
+ }) : null, liftedEvent ? /* @__PURE__ */ jsx(DragGhost, {
3010
3028
  x: ghostX,
3011
3029
  y: ghostY,
3012
3030
  w: ghostW,
package/dist/picker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_MonthList = require("./MonthList-DeO-x5VW.js");
2
+ const require_MonthList = require("./MonthList-CGgy0Juh.js");
3
3
  let _super_calendar_core = require("@super-calendar/core");
4
4
  exports.CalendarThemeProvider = require_MonthList.CalendarThemeProvider;
5
5
  exports.DefaultMonthEvent = require_MonthList.DefaultMonthEvent;
package/dist/picker.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { _ as mergeTheme, g as defaultTheme, h as darkTheme, i as MonthPager, m as CalendarThemeProvider, n as DefaultMonthEvent, o as MonthView, t as MonthList, v as useCalendarTheme } from "./MonthList-BGl1gTDr.mjs";
1
+ import { _ as mergeTheme, g as defaultTheme, h as darkTheme, i as MonthPager, m as CalendarThemeProvider, n as DefaultMonthEvent, o as MonthView, t as MonthList, v as useCalendarTheme } from "./MonthList-CPpsr5Oa.mjs";
2
2
  import { buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { CalendarThemeProvider, DefaultMonthEvent, MonthList, MonthPager, MonthView, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/native",
3
- "version": "2.20.0",
3
+ "version": "2.20.1",
4
4
  "description": "Gesture-driven, virtualized month / week / day calendar and date picker for React Native (and web via react-native-web).",
5
5
  "keywords": [
6
6
  "agenda",
@@ -64,10 +64,10 @@
64
64
  "access": "public"
65
65
  },
66
66
  "dependencies": {
67
- "@super-calendar/core": "2.20.0"
67
+ "@super-calendar/core": "2.20.1"
68
68
  },
69
69
  "peerDependencies": {
70
- "@legendapp/list": ">=3",
70
+ "@legendapp/list": ">=3.7.1",
71
71
  "date-fns": ">=3",
72
72
  "react": ">=18",
73
73
  "react-native": ">=0.74 <2",
@@ -224,10 +224,20 @@ function MonthListInner<T>({
224
224
  // `events` and `activeDate` (renderItem captures them; without this, events
225
225
  // that arrive after mount never paint, same bug as the MonthPager had) plus
226
226
  // `firstViewableIndex` (the web `inert` cutoff must stay current). Selection
227
- // needs no entry: it reaches MonthView through context.
227
+ // needs no entry: it reaches MonthView through context. `weekRowHeight` and
228
+ // `monthHeaderHeight` size each month, and LegendList re-resolves
229
+ // `getFixedItemSize` only when `extraData` changes.
228
230
  const listExtraData = useMemo(
229
- () => ({ events, activeDate, firstViewableIndex, chipHeight, chipGap }),
230
- [events, activeDate, firstViewableIndex, chipHeight, chipGap],
231
+ () => ({
232
+ events,
233
+ activeDate,
234
+ firstViewableIndex,
235
+ chipHeight,
236
+ chipGap,
237
+ weekRowHeight,
238
+ monthHeaderHeight,
239
+ }),
240
+ [events, activeDate, firstViewableIndex, chipHeight, chipGap, weekRowHeight, monthHeaderHeight],
231
241
  );
232
242
 
233
243
  // A fixed window of months anchored once, aligned to the month start.
@@ -22,6 +22,7 @@ import {
22
22
  type ReactElement,
23
23
  useCallback,
24
24
  useEffect,
25
+ useLayoutEffect,
25
26
  useMemo,
26
27
  useRef,
27
28
  useState,
@@ -352,6 +353,18 @@ function DateRowsPagerInner<T>({
352
353
  void listRef.current?.scrollToIndex({ index: activeIndex, animated: false });
353
354
  }, [activeIndex]);
354
355
 
356
+ // A new container width resizes every page (see `listExtraData`), but the
357
+ // native scroll offset stays at the old `index * width`, which now points at a
358
+ // different month or between two. Scroll back to the committed page.
359
+ // Before paint, so the one frame Android shows between the resize and the scroll
360
+ // is blank rather than a wrong month.
361
+ const laidOutWidthRef = useRef(containerWidth);
362
+ useLayoutEffect(() => {
363
+ if (containerWidth === laidOutWidthRef.current) return;
364
+ laidOutWidthRef.current = containerWidth;
365
+ void listRef.current?.scrollToIndex({ index: activeIndex, animated: false });
366
+ }, [containerWidth, activeIndex]);
367
+
355
368
  // Web arrow-key paging (swipe is disabled there); the effect above scrolls to
356
369
  // the new month once `onChangeDate` updates `date`.
357
370
  const goToPage = useCallback(
@@ -381,9 +394,13 @@ function DateRowsPagerInner<T>({
381
394
  // grids as renderItem props, not through the selection context below: toggling
382
395
  // a "pick dates" mode on must reach the pages already rendered.
383
396
  // `now` and `timeZone` move the today highlight on the pages already rendered.
397
+ // `containerWidth` and `pageHeight` resize them: LegendList re-resolves
398
+ // `getFixedItemSize` only when `extraData` changes.
384
399
  const nowTime = now?.getTime();
385
400
  const monthExtraData = useMemo(
386
401
  () => ({
402
+ containerWidth,
403
+ pageHeight,
387
404
  events,
388
405
  activeDate,
389
406
  nowTime,
@@ -398,6 +415,8 @@ function DateRowsPagerInner<T>({
398
415
  createGhostStyle: styleOverrides?.createGhost,
399
416
  }),
400
417
  [
418
+ containerWidth,
419
+ pageHeight,
401
420
  events,
402
421
  activeDate,
403
422
  nowTime,
@@ -440,7 +459,7 @@ function DateRowsPagerInner<T>({
440
459
  const getFixedItemSize = useCallback(() => containerWidth, [containerWidth]);
441
460
  const renderItem = useCallback(
442
461
  ({ item }: LegendListRenderItemProps<Date>) => (
443
- <View style={{ width: containerWidth, height: pageHeight }}>
462
+ <View testID="month-pager-page" style={{ width: containerWidth, height: pageHeight }}>
444
463
  <DateRows
445
464
  source={sourceFor(item)}
446
465
  events={events}
@@ -574,6 +593,7 @@ function DateRowsPagerInner<T>({
574
593
  />
575
594
  )}
576
595
  <View
596
+ testID="month-pager"
577
597
  style={styles.pager}
578
598
  onLayout={(event) => {
579
599
  setPageHeight(event.nativeEvent.layout.height);
@@ -581,10 +601,6 @@ function DateRowsPagerInner<T>({
581
601
  }}
582
602
  >
583
603
  <LegendList
584
- // Remount when the measured page height changes so the list adopts the
585
- // corrected item height. Without this the list can keep the oversized
586
- // initial (window-height) seed and clip the last week row.
587
- key={pageHeight}
588
604
  ref={listRef}
589
605
  style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
590
606
  data={monthDates}
@@ -858,10 +858,17 @@ function DateRowsInner<T>({
858
858
  // day, so neither can be a drag's origin or its drop target.
859
859
  const hitTest = useCallback(
860
860
  (x: number, y: number): { day: Date; event: CalendarEvent<T> | null } | null => {
861
- const { width, height } = gridSize;
861
+ // On the web `onLayout` reaches state a few frames after the grid gets its
862
+ // size, so a press right after the pager resizes a page can land on a grid
863
+ // that was never measured. Its box (the space `gridPoint` maps into) is current.
864
+ let { width, height } = gridSize;
865
+ if ((width <= 0 || height <= 0) && isWeb && gridRef.current instanceof Element) {
866
+ ({ width, height } = gridRef.current.getBoundingClientRect());
867
+ }
862
868
  if (width <= 0 || height <= 0 || weeks.length === 0) return null;
863
- let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
864
- let rowTop = row * rowHeight;
869
+ const pitch = rowHeight > 0 ? rowHeight : height / weeks.length;
870
+ let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / pitch)));
871
+ let rowTop = row * pitch;
865
872
  if (multiWeek) {
866
873
  // A styled grid can have padding, space between weeks, or overflowing rows.
867
874
  // Web layout notifications can miss a move that does not resize the row.
@@ -875,7 +882,7 @@ function DateRowsInner<T>({
875
882
  const borderTop = node
876
883
  ? node.getBoundingClientRect().top - gridTop
877
884
  : weekTops.current[index];
878
- return borderTop == null ? index * rowHeight : borderTop - cellGeometry.weekMarginTop;
885
+ return borderTop == null ? index * pitch : borderTop - cellGeometry.weekMarginTop;
879
886
  };
880
887
  row = weekAtOffset(y, weeks.length, topOf);
881
888
  rowTop = topOf(row);
@@ -3309,13 +3309,27 @@ function TimeGridInner<T>(
3309
3309
  // eslint-disable-next-line react-hooks/exhaustive-deps -- columnsWidth/pagerOffset are stable per width
3310
3310
  }, [activeIndex]);
3311
3311
 
3312
- // The list reports its offset only as it scrolls; seed it whenever the list is
3313
- // (re)laid out at a new width, where it opens on the active page.
3314
- useEffect(() => {
3312
+ // The list reports its offset only as it scrolls; seed it whenever the pages are
3313
+ // laid out at a new width. A mounted list resizes its pages in place (see
3314
+ // `listExtraData`), but its native offset keeps the old `index * width`, so
3315
+ // scroll back to the active page. Before paint, so Android's one frame between
3316
+ // the resize and the scroll is blank rather than another page.
3317
+ const laidOutWidthRef = useRef<number | null>(null);
3318
+ useLayoutEffect(() => {
3315
3319
  // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
3316
3320
  pagerOffset.value = activeIndex * columnsWidth;
3321
+ // The list unmounts at width 0 and remounts on the active page at the next width.
3322
+ if (!pagerReady) {
3323
+ laidOutWidthRef.current = null;
3324
+ return;
3325
+ }
3326
+ const previous = laidOutWidthRef.current;
3327
+ laidOutWidthRef.current = columnsWidth;
3328
+ // The list mounts on its first measured width and opens on the active page.
3329
+ if (previous == null || previous === columnsWidth) return;
3330
+ void listRef.current?.scrollToIndex({ index: activeIndex, animated: false });
3317
3331
  // eslint-disable-next-line react-hooks/exhaustive-deps -- reseed on width only; scroll events track index changes
3318
- }, [columnsWidth, pagerOffset]);
3332
+ }, [columnsWidth, pagerOffset, pagerReady]);
3319
3333
 
3320
3334
  // react-native-web ignores `contentOffset`: retry the seed each frame until the
3321
3335
  // scroll view can hold it (the viewport's `onLayout` also tries).
@@ -3372,7 +3386,7 @@ function TimeGridInner<T>(
3372
3386
  };
3373
3387
  const raf = requestAnimationFrame(lockHorizontal);
3374
3388
  return () => cancelAnimationFrame(raf);
3375
- // Re-run once the list exists at its real size (it remounts per width).
3389
+ // Re-run once the list exists at its measured width, and after each resize.
3376
3390
  // eslint-disable-next-line react-hooks/exhaustive-deps -- containerRef is stable
3377
3391
  }, [columnsWidth]);
3378
3392
 
@@ -3426,6 +3440,11 @@ function TimeGridInner<T>(
3426
3440
  [columnsWidth, pageDates, onChangeDate],
3427
3441
  );
3428
3442
 
3443
+ // Whether a finger is on the pager, between its drag begin and end.
3444
+ const pagerDraggingRef = useRef(false);
3445
+ // Set when the user starts dragging the pager and cleared by the settle it leads to.
3446
+ const pagerUserScrollRef = useRef(false);
3447
+
3429
3448
  // A fast fling can outrun the list's on-demand mounting and leave the pager
3430
3449
  // blank until something nudges it. When momentum ends, re-anchor the list on
3431
3450
  // the page the offset landed on: `scrollToIndex` forces it to recompute its
@@ -3435,6 +3454,13 @@ function TimeGridInner<T>(
3435
3454
  const handlePagerSettled = useCallback(
3436
3455
  (event: NativeSyntheticEvent<NativeScrollEvent>) => {
3437
3456
  if (columnsWidth <= 0) return;
3457
+ // iOS also ends momentum for a programmatic, non-animated scroll, including
3458
+ // the re-anchor below. Settling those would re-anchor every frame and report
3459
+ // a stale page back as the date, so only settle a scroll the user started.
3460
+ // A momentum end while the finger is still down (a snap the new drag cut
3461
+ // short) is not that scroll's settle; keep the flag for the fling that follows.
3462
+ if (!pagerUserScrollRef.current || pagerDraggingRef.current) return;
3463
+ pagerUserScrollRef.current = false;
3438
3464
  // Only a user fling can leave the pager blank; a programmatic scroll
3439
3465
  // (goToPage, realign) sets `pendingScrollIndexRef` and repaints itself, so
3440
3466
  // skip those to avoid a redundant re-anchor during held edge paging.
@@ -3453,7 +3479,6 @@ function TimeGridInner<T>(
3453
3479
  // offset left between pages back onto the nearest page (or onto the target of
3454
3480
  // an interrupted programmatic scroll). A drag that began and has not reported
3455
3481
  // its end waits longer, in case a finger is still holding it.
3456
- const pagerDraggingRef = useRef(false);
3457
3482
  const lastPagerScrollRef = useRef({ offsetX: 0, at: 0 });
3458
3483
  const pagerIdleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
3459
3484
  useEffect(
@@ -3501,6 +3526,7 @@ function TimeGridInner<T>(
3501
3526
  );
3502
3527
  const handlePagerDragStart = useCallback(() => {
3503
3528
  pagerDraggingRef.current = true;
3529
+ pagerUserScrollRef.current = true;
3504
3530
  }, []);
3505
3531
  const handlePagerDragEnd = useCallback(() => {
3506
3532
  pagerDraggingRef.current = false;
@@ -3759,9 +3785,7 @@ function TimeGridInner<T>(
3759
3785
  {pagerReady ? (
3760
3786
  <AnimatedLegendList
3761
3787
  // Mounts once the pager has measured, so the fixed item size is
3762
- // right from the list's first layout; the key remounts it on a
3763
- // later width change (a rotation, a re-measured container).
3764
- key={`grid-${columnsWidth}`}
3788
+ // right from the list's first layout.
3765
3789
  ref={listRef}
3766
3790
  style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
3767
3791
  data={pageDates}
@@ -3797,12 +3821,10 @@ function TimeGridInner<T>(
3797
3821
  disableIntervalMomentum: !freeSwipe,
3798
3822
  scrollEventThrottle: 16,
3799
3823
  onMomentumScrollEnd: handlePagerSettled,
3824
+ onScrollBeginDrag: handlePagerDragStart,
3825
+ onScrollEndDrag: handlePagerDragEnd,
3800
3826
  ...(Platform.OS === "android"
3801
- ? {
3802
- onScroll: handlePagerScroll,
3803
- onScrollBeginDrag: handlePagerDragStart,
3804
- onScrollEndDrag: handlePagerDragEnd,
3805
- }
3827
+ ? { onScroll: handlePagerScroll }
3806
3828
  : null),
3807
3829
  })}
3808
3830
  initialScrollIndex={activeIndex}