@super-calendar/native 2.8.2 → 2.9.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/index.mjs CHANGED
@@ -1,15 +1,17 @@
1
- import { a as withEventAccessibilityLabel, c as createSlots, d as darkTheme, f as defaultTheme, i as MonthView, l as useSlots, m as useCalendarTheme, n as DefaultMonthEvent, o as useWebPagerKeys, p as mergeTheme, r as MonthPager, s as SlotStylesProvider, t as MonthList, u as CalendarThemeProvider } from "./MonthList-DjAz4xoi.mjs";
1
+ import { a as withEventAccessibilityLabel, c as createSlots, d as darkTheme, f as defaultTheme, i as MonthView, l as useSlots, m as useCalendarTheme, n as DefaultMonthEvent, o as useWebPagerKeys, p as mergeTheme, r as MonthPager, s as SlotStylesProvider, t as MonthList, u as CalendarThemeProvider } from "./MonthList-CjKhzOJX.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, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
4
4
  import Animated, { runOnJS, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useReducedMotion, useSharedValue } from "react-native-reanimated";
5
- import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, buildMonthGrid, buildMonthWeeks, buildMonthWeeks as buildMonthWeeks$1, cellRangeFromDrag, closedHourBands, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, eventsInTimeZone as eventsInTimeZone$1, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, filterHiddenDays, formatHour, getIsToday, getIsToday as getIsToday$1, getViewDays, getViewDays as getViewDays$1, getWeekDays, getWeekDays as getWeekDays$1, getYearMonths, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isBackgroundEvent, isBackgroundEvent as isBackgroundEvent$1, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isSameCalendarDay as isSameCalendarDay$1, isWeekend, isWeekend as isWeekend$1, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, layoutMonthWeek, minutesIntoDay, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, resolveDraggedBounds, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useDateRange, useEventSource, useMonthGrid, useNow, useNow as useNow$1, viewDayCount, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
5
+ import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, bandRounding, buildMonthGrid, buildMonthWeeks, buildMonthWeeks as buildMonthWeeks$1, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, dayBadgeKind, daySelectionState, daySelectionState as daySelectionState$1, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, eventsInTimeZone as eventsInTimeZone$1, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, filterHiddenDays, formatHour, getIsToday, getIsToday as getIsToday$1, getViewDays, getViewDays as getViewDays$1, getWeekDays, getWeekDays as getWeekDays$1, getYearMonths, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isBackgroundEvent, isBackgroundEvent as isBackgroundEvent$1, isDateSelectable, isDateSelectable as isDateSelectable$1, isRangeEndpoint, isSameCalendarDay, isSameCalendarDay as isSameCalendarDay$1, isWeekend, isWeekend as isWeekend$1, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, layoutMonthWeek, minutesIntoDay, monthCreateRange, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useDateRange, useEventSource, useMonthGrid, useNow, useNow as useNow$1, viewDayCount, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
6
6
  import { Platform, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View, useWindowDimensions } from "react-native";
7
+ import { Gesture, GestureDetector } from "react-native-gesture-handler";
7
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
9
  import { LegendList } from "@legendapp/list/react-native";
9
- import { Gesture, GestureDetector } from "react-native-gesture-handler";
10
10
  //#region src/components/YearView.tsx
11
+ const isWeb$2 = Platform.OS === "web";
12
+ const DRAG_HOLD_MS = 400;
11
13
  const FALLBACK_COLUMNS = 3;
12
- function YearViewInner({ date, events, weekStartsOn, hiddenDays, locale, activeDate, minMonthWidth = 150, onPressDay, onPressMonth, classNames, styles: styleOverrides }) {
14
+ function YearViewInner({ date, events, weekStartsOn, hiddenDays, locale, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, classNames, styles: styleOverrides }) {
13
15
  const theme = useCalendarTheme();
14
16
  const slot = createSlots({
15
17
  classNames,
@@ -22,6 +24,11 @@ function YearViewInner({ date, events, weekStartsOn, hiddenDays, locale, activeD
22
24
  setColumns(Math.max(2, Math.min(4, Math.floor(width / minMonthWidth))));
23
25
  };
24
26
  const months = useMemo(() => getYearMonths(date), [date]);
27
+ const monthWeeks = useMemo(() => months.map((month) => buildMonthWeeks$1(month, weekStartsOn, { hiddenDays })), [
28
+ months,
29
+ weekStartsOn,
30
+ hiddenDays
31
+ ]);
25
32
  const weekdayLabels = useMemo(() => filterHiddenDays(getWeekDays$1(date, weekStartsOn), hiddenDays).map((d) => format(d, weekdayFormatToken$1("narrow"), { locale })), [
26
33
  date,
27
34
  weekStartsOn,
@@ -29,13 +36,72 @@ function YearViewInner({ date, events, weekStartsOn, hiddenDays, locale, activeD
29
36
  hiddenDays
30
37
  ]);
31
38
  const eventDays = useMemo(() => new Set(events && events.length > 0 ? groupEventsByDay(events.filter((e) => !isBackgroundEvent$1(e))).keys() : []), [events]);
39
+ const sweepEnabled = onSelectDrag != null || onCreateEvent != null;
40
+ const [sweep, setSweep] = useState(null);
41
+ const sweepRef = useRef(sweep);
42
+ sweepRef.current = sweep;
43
+ const movedRef = useRef(false);
44
+ const suppressPressRef = useRef(false);
45
+ const isSelectable = useCallback((day) => isDateSelectable$1(day, {
46
+ minDate,
47
+ maxDate,
48
+ isDateDisabled
49
+ }), [
50
+ minDate,
51
+ maxDate,
52
+ isDateDisabled
53
+ ]);
54
+ const beginSweep = useCallback((day) => {
55
+ const time = startOfDay(day).getTime();
56
+ suppressPressRef.current = false;
57
+ movedRef.current = false;
58
+ setSweep({
59
+ anchor: time,
60
+ hover: time
61
+ });
62
+ }, []);
63
+ const extendSweep = useCallback((day) => {
64
+ const current = sweepRef.current;
65
+ if (!current || !isSelectable(day)) return;
66
+ const time = startOfDay(day).getTime();
67
+ if (time === current.hover) return;
68
+ movedRef.current = true;
69
+ setSweep((c) => c ? {
70
+ ...c,
71
+ hover: time
72
+ } : c);
73
+ const [lo, hi] = current.anchor <= time ? [current.anchor, time] : [time, current.anchor];
74
+ onSelectDrag?.(new Date(lo), new Date(hi));
75
+ }, [isSelectable, onSelectDrag]);
76
+ const finishSweep = useCallback(() => {
77
+ const current = sweepRef.current;
78
+ setSweep(null);
79
+ if (!current || !movedRef.current) return;
80
+ if (isWeb$2) suppressPressRef.current = true;
81
+ const range = monthCreateRange(new Date(current.anchor), new Date(current.hover));
82
+ onCreateEvent?.(range.start, range.end);
83
+ }, [onCreateEvent]);
84
+ useEffect(() => {
85
+ if (!isWeb$2 || !sweepEnabled) return;
86
+ const target = globalThis;
87
+ target.addEventListener?.("pointerup", finishSweep);
88
+ return () => target.removeEventListener?.("pointerup", finishSweep);
89
+ }, [sweepEnabled, finishSweep]);
90
+ const pressDay = useCallback((day) => {
91
+ if (suppressPressRef.current) {
92
+ suppressPressRef.current = false;
93
+ return;
94
+ }
95
+ onPressDay?.(day);
96
+ }, [onPressDay]);
32
97
  return /* @__PURE__ */ jsx(ScrollView, {
33
98
  onLayout: handleLayout,
34
99
  showsVerticalScrollIndicator: true,
100
+ scrollEnabled: isWeb$2 || sweep == null,
35
101
  children: /* @__PURE__ */ jsx(View, {
36
102
  ...slot("grid", { base: styles$5.grid }),
37
- children: months.map((month) => {
38
- const weeks = buildMonthWeeks$1(month, weekStartsOn, { hiddenDays });
103
+ children: months.map((month, monthIndex) => {
104
+ const weeks = monthWeeks[monthIndex];
39
105
  const title = format(month, "MMMM", { locale });
40
106
  const monthLabel = format(month, "MMMM yyyy", { locale });
41
107
  const titleText = /* @__PURE__ */ jsx(Text, {
@@ -73,53 +139,158 @@ function YearViewInner({ date, events, weekStartsOn, hiddenDays, locale, activeD
73
139
  children: label
74
140
  }, i))
75
141
  }),
76
- weeks.map((week) => /* @__PURE__ */ jsx(View, {
77
- ...slot("week", { base: styles$5.week }),
78
- children: week.map((day) => {
79
- if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ jsx(View, { style: styles$5.day }, day.toISOString());
80
- const isHighlighted = activeDate ? isSameCalendarDay$1(day, activeDate) : getIsToday$1(day);
81
- const hasEvents = eventDays.has(startOfDay(day).toISOString());
82
- const label = `${format(day, "EEEE, d LLLL yyyy", { locale })}${getIsToday$1(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
83
- const daySlot = slot("day", {
84
- base: styles$5.day,
85
- themed: isHighlighted ? {
86
- backgroundColor: theme.colors.todayBackground,
87
- borderRadius: theme.todayBadgeRadius
88
- } : void 0
89
- });
90
- const content = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Text, {
91
- ...slot("dayText", { themed: [styles$5.dayText, { color: isHighlighted ? theme.colors.todayText : theme.colors.text }] }),
92
- allowFontScaling: false,
93
- children: day.getDate()
94
- }), hasEvents ? /* @__PURE__ */ jsx(View, { ...slot("eventDot", {
95
- base: styles$5.eventDot,
96
- themed: { backgroundColor: isHighlighted ? theme.colors.todayText : theme.colors.todayBackground }
97
- }) }) : null] });
98
- return onPressDay ? /* @__PURE__ */ jsx(Pressable, {
99
- onPress: () => onPressDay(day),
100
- accessibilityRole: "button",
101
- accessibilityLabel: label,
102
- ...daySlot,
103
- children: content
104
- }, day.toISOString()) : /* @__PURE__ */ jsx(View, {
105
- accessible: true,
106
- accessibilityLabel: label,
107
- ...daySlot,
108
- children: content
109
- }, day.toISOString());
110
- })
111
- }, week[0].toISOString()))
142
+ /* @__PURE__ */ jsx(MiniMonthGrid, {
143
+ testID: `year-month-grid-${month.getMonth()}`,
144
+ month,
145
+ weeks,
146
+ sweepEnabled: sweepEnabled && !isWeb$2,
147
+ isSelectable,
148
+ onBeginSweep: beginSweep,
149
+ onExtendSweep: extendSweep,
150
+ onFinishSweep: finishSweep,
151
+ children: weeks.map((week) => /* @__PURE__ */ jsx(View, {
152
+ ...slot("week", { base: styles$5.week }),
153
+ children: week.map((day) => {
154
+ if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ jsx(View, { style: styles$5.day }, day.toISOString());
155
+ const isToday = getIsToday$1(day);
156
+ const isHighlighted = activeDate ? isSameCalendarDay$1(day, activeDate) : isToday;
157
+ const hasEvents = eventDays.has(startOfDay(day).toISOString());
158
+ const state = daySelectionState$1(day, {
159
+ selectedDates,
160
+ selectedRange
161
+ }, {
162
+ minDate,
163
+ maxDate,
164
+ isDateDisabled
165
+ });
166
+ const dayTime = startOfDay(day).getTime();
167
+ const inSweep = sweep != null && dayTime >= Math.min(sweep.anchor, sweep.hover) && dayTime <= Math.max(sweep.anchor, sweep.hover);
168
+ const label = `${format(day, "EEEE, d LLLL yyyy", { locale })}${isToday ? ", today" : ""}${state.isSelected ? ", selected" : ""}${state.isDisabled ? ", unavailable" : ""}${hasEvents ? ", has events" : ""}`;
169
+ const badge = dayBadgeKind(state, isHighlighted);
170
+ const daySlot = slot("day", { base: styles$5.day });
171
+ const showBand = rangeBandKind(state, true) !== "none";
172
+ const rounding = bandRounding(rangeBandKind(state, false));
173
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
174
+ showBand || inSweep ? /* @__PURE__ */ jsx(View, { ...slot("rangeBand", {
175
+ base: [
176
+ styles$5.rangeBand,
177
+ rounding.start && styles$5.rangeBandStart,
178
+ rounding.end && styles$5.rangeBandEnd
179
+ ],
180
+ themed: { backgroundColor: theme.colors.rangeBackground }
181
+ }) }) : null,
182
+ /* @__PURE__ */ jsx(View, {
183
+ ...slot("dayBadge", {
184
+ base: styles$5.dayBadge,
185
+ themed: badge === "none" ? void 0 : {
186
+ backgroundColor: badge === "today" ? theme.colors.todayBackground : theme.colors.selectedBackground,
187
+ borderRadius: theme.todayBadgeRadius
188
+ }
189
+ }),
190
+ children: /* @__PURE__ */ jsx(Text, {
191
+ ...slot("dayText", { themed: [styles$5.dayText, { color: state.isDisabled ? theme.colors.textDisabled : badge === "today" ? theme.colors.todayText : badge === "selected" ? theme.colors.selectedText : theme.colors.text }] }),
192
+ allowFontScaling: false,
193
+ children: day.getDate()
194
+ })
195
+ }),
196
+ hasEvents ? /* @__PURE__ */ jsx(View, { ...slot("eventDot", {
197
+ base: styles$5.eventDot,
198
+ themed: { backgroundColor: badge === "none" ? theme.colors.todayBackground : theme.colors.todayText }
199
+ }) }) : null
200
+ ] });
201
+ return onPressDay || sweepEnabled ? /* @__PURE__ */ jsx(Pressable, {
202
+ onPress: () => pressDay(day),
203
+ disabled: state.isDisabled,
204
+ accessibilityRole: "button",
205
+ accessibilityLabel: label,
206
+ ...isWeb$2 && sweepEnabled ? {
207
+ onPointerDown: () => {
208
+ if (isSelectable(day)) beginSweep(day);
209
+ },
210
+ onPointerEnter: () => extendSweep(day)
211
+ } : null,
212
+ ...daySlot,
213
+ children: content
214
+ }, day.toISOString()) : /* @__PURE__ */ jsx(View, {
215
+ accessible: true,
216
+ accessibilityLabel: label,
217
+ ...daySlot,
218
+ children: content
219
+ }, day.toISOString());
220
+ })
221
+ }, week[0].toISOString()))
222
+ })
112
223
  ]
113
224
  }, month.toISOString());
114
225
  })
115
226
  })
116
227
  });
117
228
  }
229
+ function MiniMonthGrid({ testID, month, weeks, sweepEnabled, isSelectable, onBeginSweep, onExtendSweep, onFinishSweep, children }) {
230
+ const sizeRef = useRef({
231
+ width: 0,
232
+ height: 0
233
+ });
234
+ const onLayout = useCallback((event) => {
235
+ const { width, height } = event.nativeEvent.layout;
236
+ sizeRef.current = {
237
+ width,
238
+ height
239
+ };
240
+ }, []);
241
+ const latest = useRef({
242
+ month,
243
+ weeks,
244
+ isSelectable,
245
+ onBeginSweep,
246
+ onExtendSweep,
247
+ onFinishSweep
248
+ });
249
+ latest.current = {
250
+ month,
251
+ weeks,
252
+ isSelectable,
253
+ onBeginSweep,
254
+ onExtendSweep,
255
+ onFinishSweep
256
+ };
257
+ const dayAt = useCallback((x, y) => {
258
+ const { width, height } = sizeRef.current;
259
+ const { month: current, weeks: rows, isSelectable: selectable } = latest.current;
260
+ if (width <= 0 || height <= 0 || rows.length === 0) return null;
261
+ const row = Math.min(rows.length - 1, Math.max(0, Math.floor(y / (height / rows.length))));
262
+ const cols = rows[row].length;
263
+ const col = Math.min(cols - 1, Math.max(0, Math.floor(x / (width / cols))));
264
+ const day = rows[row][col];
265
+ if (!day) return null;
266
+ if (day.getMonth() !== current.getMonth()) return null;
267
+ return selectable(day) ? day : null;
268
+ }, []);
269
+ const gesture = useMemo(() => {
270
+ if (!sweepEnabled) return void 0;
271
+ return Gesture.Pan().activateAfterLongPress(DRAG_HOLD_MS).runOnJS(true).onStart((event) => {
272
+ const day = dayAt(event.x, event.y);
273
+ if (day) latest.current.onBeginSweep(day);
274
+ }).onUpdate((event) => {
275
+ const day = dayAt(event.x, event.y);
276
+ if (day) latest.current.onExtendSweep(day);
277
+ }).onFinalize(() => latest.current.onFinishSweep());
278
+ }, [sweepEnabled, dayAt]);
279
+ const grid = /* @__PURE__ */ jsx(View, {
280
+ testID,
281
+ onLayout,
282
+ children
283
+ });
284
+ return gesture ? /* @__PURE__ */ jsx(GestureDetector, {
285
+ gesture,
286
+ children: grid
287
+ }) : grid;
288
+ }
118
289
  /**
119
290
  * A year at a glance: the twelve months as compact mini grids, with today
120
291
  * highlighted and a dot under days that hold events. Tap a day or a month
121
- * title to drill into a denser view. It's the view `Calendar` renders for
122
- * `mode="year"`.
292
+ * title to drill into a denser view, or hold and drag to sweep out a date
293
+ * range. It's the view `Calendar` renders for `mode="year"`.
123
294
  *
124
295
  * @example
125
296
  * ```tsx
@@ -161,7 +332,28 @@ const styles$5 = StyleSheet.create({
161
332
  alignItems: "center",
162
333
  justifyContent: "center"
163
334
  },
335
+ dayBadge: {
336
+ width: "100%",
337
+ height: "100%",
338
+ alignItems: "center",
339
+ justifyContent: "center"
340
+ },
164
341
  dayText: { fontSize: 11 },
342
+ rangeBand: {
343
+ position: "absolute",
344
+ top: 0,
345
+ bottom: 0,
346
+ left: 0,
347
+ right: 0
348
+ },
349
+ rangeBandStart: {
350
+ borderTopLeftRadius: 999,
351
+ borderBottomLeftRadius: 999
352
+ },
353
+ rangeBandEnd: {
354
+ borderTopRightRadius: 999,
355
+ borderBottomRightRadius: 999
356
+ },
165
357
  eventDot: {
166
358
  position: "absolute",
167
359
  bottom: 1,
@@ -566,6 +758,49 @@ const EDGE_ZONE_PX = 36;
566
758
  const EdgePagingContext = createContext(null);
567
759
  const noop = () => {};
568
760
  /**
761
+ * The tail of a move that runs past midnight, drawn at the top of the next day's
762
+ * column so the drop reads on both days before the finger lifts. Mounted only
763
+ * while a drag is actually spilling (see `spillHeight`), so an idle grid pays
764
+ * nothing for it; its geometry is driven on the UI thread from there.
765
+ */
766
+ function MoveSpillPreview({ spillHeight, moveOffsetX, cellHeight, dayLeftPx, dayWidth, nextDayDirection, minHour, event, mode, renderEvent, slotProps }) {
767
+ const RenderEventComponent = renderEvent;
768
+ const style = useAnimatedStyle(() => ({
769
+ height: spillHeight.value,
770
+ opacity: spillHeight.value > 0 ? 1 : 0,
771
+ zIndex: spillHeight.value > 0 ? DRAG_EVENT_Z : 0,
772
+ transform: [{ translateX: moveOffsetX.value + nextDayDirection * dayWidth }, { translateY: -minHour * cellHeight.value }]
773
+ }), [
774
+ dayWidth,
775
+ nextDayDirection,
776
+ minHour
777
+ ]);
778
+ return /* @__PURE__ */ jsx(Animated.View, {
779
+ ...slotProps,
780
+ accessibilityElementsHidden: true,
781
+ importantForAccessibility: "no-hide-descendants",
782
+ style: [
783
+ styles$1.eventBox,
784
+ styles$1.nonInteractive,
785
+ {
786
+ left: dayLeftPx,
787
+ width: dayWidth,
788
+ top: 0
789
+ },
790
+ slotProps.style,
791
+ style
792
+ ],
793
+ children: /* @__PURE__ */ jsx(RenderEventComponent, {
794
+ event,
795
+ mode,
796
+ boxHeight: spillHeight,
797
+ continuesBefore: true,
798
+ continuesAfter: false,
799
+ onPress: noop
800
+ })
801
+ });
802
+ }
803
+ /**
569
804
  * The floating copy of a dragged event, rendered above the pager so a cross-week
570
805
  * drag stays visible after its source page pages away. Position, size, and
571
806
  * visibility are driven on the UI thread by the shared values so it tracks the
@@ -595,7 +830,7 @@ function DragGhost({ x, y, w, h, visible, event, mode, renderEvent }) {
595
830
  });
596
831
  }
597
832
  const HOUR_LABEL_TOP_INSET = 12;
598
- function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWidth, dayIndex, dayCount, dayOrdinals, mode, daysPerPage, renderEvent, snapMinutes, onPress, onLongPress, onDragEvent, onDragStart, onEdgeAdvance, showDragHandle, eventStartEditable, eventDurationEditable }) {
833
+ function AnimatedEventBox({ positioned, cellHeight, minHour, maxHour, left, width, dayLeftPx, nextDayDirection, dayWidth, dayIndex, dayCount, dayOrdinals, mode, daysPerPage, renderEvent, snapMinutes, onPress, onLongPress, onDragEvent, onDragStart, onEdgeAdvance, showDragHandle, eventStartEditable, eventDurationEditable }) {
599
834
  const RenderEventComponent = renderEvent;
600
835
  const theme = useCalendarTheme();
601
836
  const slot = useSlots();
@@ -616,6 +851,7 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
616
851
  const resizeDelta = useSharedValue(0);
617
852
  const resizeStartDelta = useSharedValue(0);
618
853
  const dragZ = useSharedValue(0);
854
+ const moving = useSharedValue(0);
619
855
  const edgeDir = useSharedValue(0);
620
856
  const lifted = useSharedValue(0);
621
857
  const grabX = useSharedValue(0);
@@ -624,17 +860,49 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
624
860
  const liveAbsY = useSharedValue(0);
625
861
  const startHours = positioned.startHours;
626
862
  const durationHours = positioned.durationHours;
863
+ const ownsStart = !positioned.continuesBefore;
864
+ const dragStartSV = useDerivedValue(() => ({
865
+ minutes: startHours * MINUTES_PER_HOUR$1,
866
+ ownsStart
867
+ }), [startHours, ownsStart]);
627
868
  const boxHeight = useDerivedValue(() => Math.max(durationHours * cellHeight.value + resizeDelta.value - resizeStartDelta.value, MIN_EVENT_HEIGHT), [durationHours]);
628
- const boxStyle = useAnimatedStyle(() => ({
629
- top: (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value,
630
- height: boxHeight.value,
631
- transform: [{ translateX: moveOffsetX.value }],
632
- zIndex: dragZ.value
633
- }), [
869
+ const visibleBoxHeight = useDerivedValue(() => {
870
+ const top = (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value;
871
+ const dayEnd = (HOURS_PER_DAY - minHour) * cellHeight.value;
872
+ return Math.max(Math.min(boxHeight.value, dayEnd - top), MIN_EVENT_HEIGHT);
873
+ }, [startHours, minHour]);
874
+ const boxStyle = useAnimatedStyle(() => {
875
+ return {
876
+ top: (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value,
877
+ height: visibleBoxHeight.value,
878
+ transform: [{ translateX: moveOffsetX.value }],
879
+ zIndex: dragZ.value
880
+ };
881
+ }, [startHours, minHour]);
882
+ const spillHeight = useDerivedValue(() => {
883
+ if (!moving.value || lifted.value || cellHeight.value <= 0) return 0;
884
+ const overflowHours = startHours + moveOffset.value / cellHeight.value + durationHours - HOURS_PER_DAY;
885
+ if (overflowHours <= 0) return 0;
886
+ const columnDelta = dayWidth > 0 ? Math.round(moveOffsetX.value / dayWidth) : 0;
887
+ const target = Math.min(Math.max(dayIndex + columnDelta, 0), dayCount - 1);
888
+ const next = target + nextDayDirection;
889
+ if (next < 0 || next >= dayCount || dayOrdinals[next] - dayOrdinals[target] !== 1) return 0;
890
+ return Math.min(overflowHours, maxHour - minHour) * cellHeight.value;
891
+ }, [
634
892
  startHours,
635
893
  durationHours,
636
- minHour
894
+ minHour,
895
+ maxHour,
896
+ dayWidth,
897
+ dayIndex,
898
+ dayCount,
899
+ dayOrdinals,
900
+ nextDayDirection
637
901
  ]);
902
+ const [previewMounted, setPreviewMounted] = useState(false);
903
+ useAnimatedReaction(() => spillHeight.value > 0, (spilling, previous) => {
904
+ if (previous !== null && spilling !== previous) runOnJS(setPreviewMounted)(spilling);
905
+ });
638
906
  useEffect(() => {
639
907
  moveOffset.value = 0;
640
908
  moveOffsetX.value = 0;
@@ -725,6 +993,7 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
725
993
  const moveGesture = useMemo(() => {
726
994
  const pan = Gesture.Pan().enabled(canMove).onStart((event) => {
727
995
  dragZ.value = DRAG_EVENT_Z;
996
+ moving.value = 1;
728
997
  edgeDir.value = 0;
729
998
  lifted.value = 0;
730
999
  grabX.value = event.x;
@@ -738,8 +1007,11 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
738
1007
  if (lifted.value && pagerLeftSV && pagerTopSV && ghostXSV && ghostYSV) {
739
1008
  ghostXSV.value = event.absoluteX - grabX.value - pagerLeftSV.value;
740
1009
  ghostYSV.value = event.absoluteY - grabY.value - pagerTopSV.value;
741
- } else {
742
- moveOffset.value = event.translationY;
1010
+ } else if (cellHeight.value > 0) {
1011
+ const { minutes: startMinutes, ownsStart } = dragStartSV.value;
1012
+ const dragged = startMinutes + event.translationY / cellHeight.value * MINUTES_PER_HOUR$1;
1013
+ const held = ownsStart ? clampMoveStartMinutes(dragged, minHour, maxHour, snapMinutes) : dragged;
1014
+ moveOffset.value = (held - startMinutes) / MINUTES_PER_HOUR$1 * cellHeight.value;
743
1015
  moveOffsetX.value = event.translationX;
744
1016
  }
745
1017
  if (onEdgeAdvance && pagerLeftSV && pagerWidthSV) {
@@ -753,7 +1025,9 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
753
1025
  }
754
1026
  }).onEnd((event) => {
755
1027
  if (lifted.value) return;
756
- const minuteDelta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
1028
+ const { minutes: startMinutes, ownsStart } = dragStartSV.value;
1029
+ const snapped = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
1030
+ const minuteDelta = ownsStart ? clampMoveStartMinutes(startMinutes + snapped, minHour, maxHour, snapMinutes) - startMinutes : snapped;
757
1031
  const rawDayDelta = dayWidth > 0 ? Math.round(event.translationX / dayWidth) : 0;
758
1032
  const targetDay = Math.min(Math.max(dayIndex + rawDayDelta, 0), dayCount - 1);
759
1033
  const dayDelta = targetDay - dayIndex;
@@ -774,6 +1048,7 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
774
1048
  moveOffsetX.value = 0;
775
1049
  lifted.value = 0;
776
1050
  }
1051
+ moving.value = 0;
777
1052
  runOnJS(releaseEdge)();
778
1053
  });
779
1054
  return isWeb$1 ? pan.activeOffsetX([-8, DRAG_ACTIVATE_PX$1]).activeOffsetY([-8, DRAG_ACTIVATE_PX$1]) : pan.activateAfterLongPress(MOVE_ACTIVATE_MS$1);
@@ -784,6 +1059,10 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
784
1059
  moveOffset,
785
1060
  moveOffsetX,
786
1061
  dragZ,
1062
+ moving,
1063
+ dragStartSV,
1064
+ minHour,
1065
+ maxHour,
787
1066
  edgeDir,
788
1067
  lifted,
789
1068
  grabX,
@@ -919,7 +1198,7 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
919
1198
  /* @__PURE__ */ jsx(RenderEventComponent, {
920
1199
  event: positioned.event,
921
1200
  mode,
922
- boxHeight,
1201
+ boxHeight: visibleBoxHeight,
923
1202
  continuesBefore: positioned.continuesBefore,
924
1203
  continuesAfter: positioned.continuesAfter,
925
1204
  accessibilityActions,
@@ -944,10 +1223,22 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
944
1223
  ]
945
1224
  });
946
1225
  if (!canMove) return box;
947
- return /* @__PURE__ */ jsx(GestureDetector, {
1226
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(GestureDetector, {
948
1227
  gesture: moveGesture,
949
1228
  children: box
950
- });
1229
+ }), previewMounted && !positioned.continuesAfter ? /* @__PURE__ */ jsx(MoveSpillPreview, {
1230
+ spillHeight,
1231
+ moveOffsetX,
1232
+ cellHeight,
1233
+ dayLeftPx,
1234
+ dayWidth,
1235
+ nextDayDirection,
1236
+ minHour,
1237
+ event: positioned.event,
1238
+ mode,
1239
+ renderEvent,
1240
+ slotProps: slot("event", { themed: theme.containers.timeGridEvent })
1241
+ }) : null] });
951
1242
  }
952
1243
  const HourRow = ({ hour, minHour, cellHeight, hourColumnWidth, label, ampm, hourComponent }) => {
953
1244
  const theme = useCalendarTheme();
@@ -1419,8 +1710,11 @@ function TimetablePageInner({ mode, numberOfDays, hiddenDays, now: nowProp, nowT
1419
1710
  positioned,
1420
1711
  cellHeight: heightSource,
1421
1712
  minHour,
1713
+ maxHour,
1422
1714
  left: dayLeft(dayIndex) + positioned.column * columnWidth,
1423
1715
  width: columnWidth,
1716
+ dayLeftPx: dayLeft(dayIndex),
1717
+ nextDayDirection: isRTL ? -1 : 1,
1424
1718
  dayWidth,
1425
1719
  dayIndex,
1426
1720
  dayCount: days.length,
@@ -1504,6 +1798,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1504
1798
  containerWidth,
1505
1799
  hourColumnWidth,
1506
1800
  minHour: clampedMinHour,
1801
+ maxHour: clampedMaxHour,
1507
1802
  snapMinutes: Math.max(1, dragStepMinutes),
1508
1803
  onDragEvent,
1509
1804
  onChangeDate
@@ -1519,7 +1814,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1519
1814
  setEdgePagingLock(false);
1520
1815
  }, [ghostVisible]);
1521
1816
  const commitLiftedDrop = useCallback((ghostLocalX, ghostLocalY) => {
1522
- const { headerDays: days, containerWidth: cw, hourColumnWidth: hcw, minHour: min, snapMinutes: snap, onDragEvent: onDrag, onChangeDate: onDate } = dropRef.current;
1817
+ const { headerDays: days, containerWidth: cw, hourColumnWidth: hcw, minHour: min, maxHour: max, snapMinutes: snap, onDragEvent: onDrag, onChangeDate: onDate } = dropRef.current;
1523
1818
  const ev = liftedEventRef.current;
1524
1819
  const duration = ev ? ev.end.getTime() - ev.start.getTime() : 0;
1525
1820
  clearLift();
@@ -1527,7 +1822,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1527
1822
  const dayWidth = (cw - hcw) / days.length;
1528
1823
  const col = Math.min(Math.max(Math.floor((ghostLocalX - hcw) / dayWidth), 0), days.length - 1);
1529
1824
  const rawMinutes = (min + (ghostLocalY - gridTop.value - HOUR_LABEL_TOP_INSET + scrollY.value) / cellHeight.value) * MINUTES_PER_HOUR$1;
1530
- const minutes = Math.round(rawMinutes / snap) * snap;
1825
+ const minutes = clampMoveStartMinutes(Math.round(rawMinutes / snap) * snap, min, max, snap);
1531
1826
  const start = new Date(days[col]);
1532
1827
  start.setHours(0, 0, 0, 0);
1533
1828
  start.setMinutes(minutes);
@@ -1605,6 +1900,7 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1605
1900
  containerWidth,
1606
1901
  hourColumnWidth,
1607
1902
  minHour: clampedMinHour,
1903
+ maxHour: clampedMaxHour,
1608
1904
  snapMinutes: Math.max(1, dragStepMinutes),
1609
1905
  onDragEvent,
1610
1906
  onChangeDate
@@ -2147,7 +2443,7 @@ function expansionRange(mode, date, weekStartsOn, numberOfDays, weekEndsOn) {
2147
2443
  * }
2148
2444
  * ```
2149
2445
  */
2150
- function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPressEvent, onLongPressEvent, onDragEvent, onDragStart, dragStepMinutes, showDragHandle, onPressDay, onPressMonth, onLongPressDay, onPressMore, onPressCell, resetPageOnPressCell, onLongPressCell, onCreateEvent, onPressDateHeader, maxVisibleEventCount, sortedMonthView, moreLabel, showAdjacentMonths, disableMonthEventCellPress, weekStartsOn = 0, hiddenDays, now, weekdayFormat, numberOfDays, weekEndsOn, renderEvent = DefaultEvent, eventAccessibilityLabel, eventCellStyle, calendarCellStyle, businessHours, renderBusinessHours, keyExtractor = defaultKeyExtractor, theme, cellHeight: cellHeightProp, hourHeight = 48, minHourHeight, maxHourHeight, hourColumnWidth, hideHours, timeslots, showAllDayEventCell, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, showWeekNumber, weekNumberPrefix, hourComponent, showSixWeeks, swipeEnabled, showVerticalScrollIndicator, verticalScrollEnabled, headerComponent, minHour, maxHour, ampm, showTime, ellipsizeTitle, allDayLabel, scrollOffsetMinutes, showNowIndicator, locale, timeZone, activeDate, isRTL, freeSwipe, renderTimeGridHeader, renderHeaderForMonthView, renderCustomDateForMonth, itemSeparatorComponent, classNames, styles: styleOverrides }) {
2446
+ function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPressEvent, onLongPressEvent, onDragEvent, onDragStart, dragStepMinutes, showDragHandle, onPressDay, onPressMonth, onLongPressDay, onPressMore, onPressCell, resetPageOnPressCell, onLongPressCell, onCreateEvent, onSelectDrag, selectedDates, selectedRange, fillCellOnSelection, minDate, maxDate, isDateDisabled, onPressDateHeader, maxVisibleEventCount, sortedMonthView, moreLabel, showAdjacentMonths, disableMonthEventCellPress, weekStartsOn = 0, hiddenDays, now, weekdayFormat, numberOfDays, weekEndsOn, renderEvent = DefaultEvent, eventAccessibilityLabel, eventCellStyle, calendarCellStyle, businessHours, renderBusinessHours, keyExtractor = defaultKeyExtractor, theme, cellHeight: cellHeightProp, hourHeight = 48, minHourHeight, maxHourHeight, hourColumnWidth, hideHours, timeslots, showAllDayEventCell, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, showWeekNumber, weekNumberPrefix, hourComponent, showSixWeeks, showTitle, swipeEnabled, showVerticalScrollIndicator, verticalScrollEnabled, headerComponent, minHour, maxHour, ampm, showTime, ellipsizeTitle, allDayLabel, scrollOffsetMinutes, showNowIndicator, locale, timeZone, activeDate, isRTL, freeSwipe, renderTimeGridHeader, renderHeaderForMonthView, renderCustomDateForMonth, itemSeparatorComponent, classNames, styles: styleOverrides }) {
2151
2447
  const mergedTheme = useMemo(() => mergeTheme(theme), [theme]);
2152
2448
  const internalCellHeight = useSharedValue(hourHeight);
2153
2449
  const cellHeight = cellHeightProp ?? internalCellHeight;
@@ -2234,6 +2530,7 @@ function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPress
2234
2530
  disableMonthEventCellPress,
2235
2531
  isRTL,
2236
2532
  showSixWeeks,
2533
+ showTitle,
2237
2534
  activeDate,
2238
2535
  renderHeaderForMonthView,
2239
2536
  renderCustomDateForMonth,
@@ -2242,9 +2539,22 @@ function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPress
2242
2539
  keyExtractor,
2243
2540
  onPressDay,
2244
2541
  onLongPressDay,
2542
+ onPressCell,
2245
2543
  onPressEvent: handlePressEvent,
2246
2544
  onLongPressEvent: handleLongPressEvent,
2247
2545
  onPressMore,
2546
+ onCreateEvent,
2547
+ onSelectDrag,
2548
+ onDragEvent,
2549
+ onDragStart,
2550
+ eventStartEditable,
2551
+ eventOverlap,
2552
+ selectedDates,
2553
+ selectedRange,
2554
+ fillCellOnSelection,
2555
+ minDate,
2556
+ maxDate,
2557
+ isDateDisabled,
2248
2558
  onChangeDate: handleChangeDate,
2249
2559
  freeSwipe,
2250
2560
  swipeEnabled,
@@ -2257,8 +2567,15 @@ function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPress
2257
2567
  hiddenDays,
2258
2568
  locale,
2259
2569
  activeDate,
2570
+ selectedDates,
2571
+ selectedRange,
2572
+ minDate,
2573
+ maxDate,
2574
+ isDateDisabled,
2260
2575
  onPressDay,
2261
2576
  onPressMonth,
2577
+ onSelectDrag,
2578
+ onCreateEvent,
2262
2579
  classNames,
2263
2580
  styles: styleOverrides
2264
2581
  }) : mode === "schedule" ? /* @__PURE__ */ jsx(Agenda, {
package/dist/picker.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { A as PartialCalendarTheme, C as RenderEvent, E as WeekStartsOn, M as defaultTheme, N as mergeTheme, O as CalendarTheme, P as useCalendarTheme, a as MonthPager, b as ICalendarEvent, c as MonthViewProps, g as CalendarMode, h as CalendarEvent, j as darkTheme, k as CalendarThemeProvider, n as MonthList, o as MonthPagerProps, r as MonthListProps, s as MonthView, t as DefaultMonthEvent, w as RenderEventArgs, y as EventKeyExtractor } from "./DefaultMonthEvent-Cewbec1K.mjs";
1
+ import { A as CalendarTheme, E as RenderEventArgs, F as mergeTheme, I as useCalendarTheme, M as PartialCalendarTheme, N as darkTheme, O as WeekStartsOn, P as defaultTheme, S as ICalendarEvent, T as RenderEvent, a as MonthPager, c as MonthViewProps, g as CalendarMode, h as CalendarEvent, j as CalendarThemeProvider, n as MonthList, o as MonthPagerProps, r as MonthListProps, s as MonthView, t as DefaultMonthEvent, x as EventKeyExtractor } from "./DefaultMonthEvent-BlnKHaq2.mjs";
2
2
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { type CalendarEvent, type CalendarMode, type CalendarTheme, CalendarThemeProvider, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultMonthEvent, type EventKeyExtractor, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type RenderEvent, type RenderEventArgs, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
package/dist/picker.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { A as PartialCalendarTheme, C as RenderEvent, E as WeekStartsOn, M as defaultTheme, N as mergeTheme, O as CalendarTheme, P as useCalendarTheme, a as MonthPager, b as ICalendarEvent, c as MonthViewProps, g as CalendarMode, h as CalendarEvent, j as darkTheme, k as CalendarThemeProvider, n as MonthList, o as MonthPagerProps, r as MonthListProps, s as MonthView, t as DefaultMonthEvent, w as RenderEventArgs, y as EventKeyExtractor } from "./DefaultMonthEvent-C_T4thzu.js";
1
+ import { A as CalendarTheme, E as RenderEventArgs, F as mergeTheme, I as useCalendarTheme, M as PartialCalendarTheme, N as darkTheme, O as WeekStartsOn, P as defaultTheme, S as ICalendarEvent, T as RenderEvent, a as MonthPager, c as MonthViewProps, g as CalendarMode, h as CalendarEvent, j as CalendarThemeProvider, n as MonthList, o as MonthPagerProps, r as MonthListProps, s as MonthView, t as DefaultMonthEvent, x as EventKeyExtractor } from "./DefaultMonthEvent--9Jg6w-x.js";
2
2
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { type CalendarEvent, type CalendarMode, type CalendarTheme, CalendarThemeProvider, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultMonthEvent, type EventKeyExtractor, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type RenderEvent, type RenderEventArgs, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };