@super-calendar/native 2.16.0 → 2.18.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.
@@ -0,0 +1,34 @@
1
+ import { type ReactElement, useMemo } from "react";
2
+ import { type WeekStartsOn } from "@super-calendar/core";
3
+ import { DateRows, type DateRowsSource, type MonthViewProps } from "./MonthView";
4
+
5
+ /** Props for the consecutive full-week event grid. */
6
+ export type MultiWeekViewProps<T = unknown> = Omit<
7
+ MonthViewProps<T>,
8
+ "date" | "weekStartsOn" | "showSixWeeks" | "showAdjacentMonths"
9
+ > & {
10
+ /** Any day in the first displayed week. */
11
+ date: Date;
12
+ /** Positive whole number of week rows (default 2). Invalid values throw RangeError. */
13
+ numberOfWeeks?: number;
14
+ /** First weekday, Sunday = 0 (default). */
15
+ weekStartsOn?: WeekStartsOn;
16
+ };
17
+
18
+ /**
19
+ * Consecutive full weeks with event bars and no hourly slots. Rows scroll
20
+ * vertically when they cannot fit. Expand recurring events before passing them,
21
+ * or use Calendar with mode="multiweek" for recurrence and swipe paging.
22
+ */
23
+ export function MultiWeekView<T = unknown>({
24
+ date,
25
+ numberOfWeeks = 2,
26
+ weekStartsOn = 0,
27
+ ...rest
28
+ }: MultiWeekViewProps<T>): ReactElement {
29
+ const source = useMemo<DateRowsSource>(
30
+ () => ({ kind: "multiweek", date, numberOfWeeks }),
31
+ [date, numberOfWeeks],
32
+ );
33
+ return <DateRows {...rest} source={source} weekStartsOn={weekStartsOn} />;
34
+ }
@@ -81,6 +81,7 @@ import type {
81
81
  } from "../types";
82
82
  import {
83
83
  getIsToday,
84
+ nowInTimeZone,
84
85
  getViewDays,
85
86
  isSameCalendarDay,
86
87
  isWeekend,
@@ -481,10 +482,13 @@ function AnimatedEventBoxInner<T>({
481
482
  // Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
482
483
  // above all the others, then back to 0 when it settles.
483
484
  const dragZ = useSharedValue(0);
484
- // 1 while a move gesture is running. Only gates the spill preview: the box's own
485
- // clip is geometric, so it can't disagree with the box during the frames between
486
- // release and the committed re-render.
485
+ // 1 while a move gesture is running. Gates the spill preview and floats the box
486
+ // across its day column; the box's own clip is geometric, so it can't disagree
487
+ // with the box during the frames between release and the committed re-render.
487
488
  const moving = useSharedValue(0);
489
+ // 1 while a finger is down on a resize handle. The move gesture wraps the
490
+ // handles, so a hold on one picks the event up too until the resize takes over.
491
+ const onHandle = useSharedValue(0);
488
492
  // Edge auto-advance: which side the drag has pushed past the visible columns
489
493
  // (-1 left / 0 none / +1 right).
490
494
  const edgeDir = useSharedValue(0);
@@ -520,6 +524,9 @@ function AnimatedEventBoxInner<T>({
520
524
  }),
521
525
  [startHours, ownsStart],
522
526
  );
527
+ // How far into its day column the box sits, mirrored the same way: an overlap
528
+ // group reflows when the consumer updates `events` mid-drag.
529
+ const columnInsetSV = useDerivedValue(() => left - dayLeftPx, [left, dayLeftPx]);
523
530
 
524
531
  // Where a move in progress lands beyond its plain row offset, in hours: a start
525
532
  // in the hour a spring-forward change skips moves on past it (`top`), and the
@@ -596,14 +603,23 @@ function AnimatedEventBoxInner<T>({
596
603
  // drag commits.
597
604
  // Hidden while lifted: the floating ghost stands in for the box until the
598
605
  // drop commits (and, for a multi-day move, while the preview draws it).
606
+ // A picked-up event floats across its whole day column, like the multi-day
607
+ // preview and the spill, instead of keeping its slice of an overlap group. It
608
+ // keeps floating while a dropped move holds its offset, so the box doesn't
609
+ // flash back to its old slice before the committed layout lands. A resize keeps
610
+ // the slice, even when a hold on its handle picked the event up first.
611
+ const floating =
612
+ !onHandle.value && (moving.value || moveOffset.value !== 0 || moveOffsetX.value !== 0);
599
613
  return {
614
+ left: floating ? dayLeftPx : left,
615
+ width: floating ? dayWidth : width,
600
616
  top,
601
617
  height: visibleBoxHeight.value,
602
618
  transform: [{ translateX: moveOffsetX.value }],
603
619
  zIndex: dragZ.value,
604
620
  opacity: hiddenForMove || lifted.value ? 0 : 1,
605
621
  };
606
- }, [startHours, minHour, hiddenForMove]);
622
+ }, [startHours, minHour, hiddenForMove, left, width, dayLeftPx, dayWidth]);
607
623
 
608
624
  // Pixel height of the part of a move that runs past midnight, or 0 when nothing
609
625
  // spills. Measured against the end of the day, not `maxHour`: a narrowed window
@@ -781,7 +797,7 @@ function AnimatedEventBoxInner<T>({
781
797
  // the same gesture keeps tracking after the page changes.
782
798
  if (!lifted.value) {
783
799
  lifted.value = 1;
784
- edgePaging.ghostW.value = width;
800
+ edgePaging.ghostW.value = dayWidth;
785
801
  edgePaging.ghostH.value = boxHeight.value;
786
802
  edgePaging.ghostX.value = liveAbsX.value - grabX.value - edgePaging.pagerLeft.value;
787
803
  edgePaging.ghostY.value = liveAbsY.value - grabY.value - edgePaging.pagerTop.value;
@@ -797,7 +813,7 @@ function AnimatedEventBoxInner<T>({
797
813
  disarmEdge,
798
814
  edgePaging,
799
815
  lifted,
800
- width,
816
+ dayWidth,
801
817
  boxHeight,
802
818
  liveAbsX,
803
819
  liveAbsY,
@@ -816,8 +832,9 @@ function AnimatedEventBoxInner<T>({
816
832
  edgeDir.value = 0;
817
833
  lifted.value = 0;
818
834
  // Where in the box the finger grabbed, and the live finger position, so
819
- // the ghost can be seeded and tracked in window space (see armEdge).
820
- grabX.value = event.x;
835
+ // the ghost can be seeded and tracked in window space (see armEdge). The
836
+ // grab is measured from the day column, where the floating box now starts.
837
+ grabX.value = event.x + columnInsetSV.value;
821
838
  grabY.value = event.y;
822
839
  liveAbsX.value = event.absoluteX;
823
840
  liveAbsY.value = event.absoluteY;
@@ -931,6 +948,7 @@ function AnimatedEventBoxInner<T>({
931
948
  }, [
932
949
  canMove,
933
950
  snapMinutes,
951
+ columnInsetSV,
934
952
  cellHeight,
935
953
  moveOffset,
936
954
  moveOffsetX,
@@ -987,6 +1005,9 @@ function AnimatedEventBoxInner<T>({
987
1005
  const resizeGesture = useMemo(() => {
988
1006
  const pan = Gesture.Pan()
989
1007
  .enabled(resizable)
1008
+ .onBegin(() => {
1009
+ onHandle.value = 1;
1010
+ })
990
1011
  .onStart(() => {
991
1012
  dragZ.value = DRAG_EVENT_Z;
992
1013
  runOnJS(notifyDragStart)();
@@ -1005,6 +1026,7 @@ function AnimatedEventBoxInner<T>({
1005
1026
  })
1006
1027
  .onFinalize(() => {
1007
1028
  dragZ.value = 0;
1029
+ onHandle.value = 0;
1008
1030
  });
1009
1031
  const tap = Gesture.Tap()
1010
1032
  .runOnJS(true)
@@ -1022,6 +1044,7 @@ function AnimatedEventBoxInner<T>({
1022
1044
  resizable,
1023
1045
  snapMinutes,
1024
1046
  cellHeight,
1047
+ onHandle,
1025
1048
  resizeDelta,
1026
1049
  dragZ,
1027
1050
  commitDrag,
@@ -1036,6 +1059,9 @@ function AnimatedEventBoxInner<T>({
1036
1059
  const resizeStartGesture = useMemo(() => {
1037
1060
  const pan = Gesture.Pan()
1038
1061
  .enabled(resizableFromStart)
1062
+ .onBegin(() => {
1063
+ onHandle.value = 1;
1064
+ })
1039
1065
  .onStart(() => {
1040
1066
  dragZ.value = DRAG_EVENT_Z;
1041
1067
  runOnJS(notifyDragStart)();
@@ -1054,6 +1080,7 @@ function AnimatedEventBoxInner<T>({
1054
1080
  })
1055
1081
  .onFinalize(() => {
1056
1082
  dragZ.value = 0;
1083
+ onHandle.value = 0;
1057
1084
  });
1058
1085
  const tap = Gesture.Tap()
1059
1086
  .runOnJS(true)
@@ -1071,6 +1098,7 @@ function AnimatedEventBoxInner<T>({
1071
1098
  resizableFromStart,
1072
1099
  snapMinutes,
1073
1100
  cellHeight,
1101
+ onHandle,
1074
1102
  resizeStartDelta,
1075
1103
  dragZ,
1076
1104
  commitDrag,
@@ -1770,6 +1798,9 @@ function TimetablePageInner<T>({
1770
1798
  const hoursRange = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
1771
1799
 
1772
1800
  const now = useNow(showNowIndicator && isActive, { now: nowProp, timeZone: nowTimeZone });
1801
+ // The day the header marks as today: the indicator's clock while it runs, so
1802
+ // the two can't disagree.
1803
+ const today = showNowIndicator && isActive ? now : nowInTimeZone(nowProp, nowTimeZone);
1773
1804
  // "Today" follows the (possibly zone-shifted or overridden) now, so the line
1774
1805
  // lands in the column the events are displayed in.
1775
1806
  const nowDayIndex = days.findIndex((day) => isSameCalendarDay(day, now));
@@ -2178,6 +2209,7 @@ function TimetablePageInner<T>({
2178
2209
  dayWidth={dayWidth}
2179
2210
  weekdayFormat={weekdayFormat}
2180
2211
  todayLabel={todayLabel}
2212
+ today={today}
2181
2213
  locale={locale}
2182
2214
  activeDate={activeDate}
2183
2215
  onPressDateHeader={onPressDateHeader}
@@ -2480,9 +2512,15 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
2480
2512
  weekEndsOn?: WeekStartsOn;
2481
2513
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
2482
2514
  hiddenDays?: number[];
2483
- /** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
2515
+ /**
2516
+ * Fixed "now" instant for the indicator (doesn't tick) and for the day
2517
+ * highlighted as today. Defaults to the device clock.
2518
+ */
2484
2519
  now?: Date;
2485
- /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
2520
+ /**
2521
+ * Shift the now indicator and the day highlighted as today into this IANA zone
2522
+ * (pair with `eventsInTimeZone`).
2523
+ */
2486
2524
  timeZone?: string;
2487
2525
  date: Date;
2488
2526
  events: CalendarEvent<T>[];
@@ -3503,6 +3541,8 @@ function TimeGridInner<T>(
3503
3541
  // `columnsWidth` resizes the mounted pages when the grid is re-measured.
3504
3542
  // `showDragHandle` refreshes grips without requiring an event-data change, and
3505
3543
  // `renderCreateGhost` swaps the preview content of mounted pages.
3544
+ // `now` and `timeZone` move the today highlight and the now line.
3545
+ const nowTime = now?.getTime();
3506
3546
  const listExtraData = useMemo(
3507
3547
  () => ({
3508
3548
  events,
@@ -3514,6 +3554,8 @@ function TimeGridInner<T>(
3514
3554
  dragStepMinutes,
3515
3555
  minHour,
3516
3556
  maxHour,
3557
+ nowTime,
3558
+ timeZone,
3517
3559
  }),
3518
3560
  [
3519
3561
  events,
@@ -3525,6 +3567,8 @@ function TimeGridInner<T>(
3525
3567
  dragStepMinutes,
3526
3568
  minHour,
3527
3569
  maxHour,
3570
+ nowTime,
3571
+ timeZone,
3528
3572
  ],
3529
3573
  );
3530
3574
 
@@ -3713,6 +3757,7 @@ type DayHeaderRowProps = {
3713
3757
  dayWidth: number;
3714
3758
  weekdayFormat?: WeekdayFormat;
3715
3759
  todayLabel: string;
3760
+ today: Date;
3716
3761
  locale?: Locale;
3717
3762
  activeDate?: Date;
3718
3763
  onPressDateHeader?: (date: Date) => void;
@@ -3726,6 +3771,7 @@ const DayHeaderRow = ({
3726
3771
  dayWidth,
3727
3772
  weekdayFormat,
3728
3773
  todayLabel,
3774
+ today,
3729
3775
  locale,
3730
3776
  activeDate,
3731
3777
  onPressDateHeader,
@@ -3741,6 +3787,7 @@ const DayHeaderRow = ({
3741
3787
  width={dayWidth}
3742
3788
  weekdayFormat={weekdayFormat}
3743
3789
  todayLabel={todayLabel}
3790
+ today={today}
3744
3791
  locale={locale}
3745
3792
  activeDate={activeDate}
3746
3793
  onPressDateHeader={onPressDateHeader}
@@ -3756,6 +3803,7 @@ type DayHeaderProps = {
3756
3803
  width: number;
3757
3804
  weekdayFormat?: WeekdayFormat;
3758
3805
  todayLabel: string;
3806
+ today: Date;
3759
3807
  locale?: Locale;
3760
3808
  activeDate?: Date;
3761
3809
  onPressDateHeader?: (date: Date) => void;
@@ -3766,13 +3814,14 @@ const DayHeader = ({
3766
3814
  width,
3767
3815
  weekdayFormat = "short",
3768
3816
  todayLabel,
3817
+ today,
3769
3818
  locale,
3770
3819
  activeDate,
3771
3820
  onPressDateHeader,
3772
3821
  }: DayHeaderProps) => {
3773
3822
  const theme = useCalendarTheme();
3774
3823
  const slot = useSlots<TimeGridSlot>();
3775
- const isToday = getIsToday(day);
3824
+ const isToday = getIsToday(day, today);
3776
3825
  // Highlight the chosen `activeDate` when supplied, else the real today.
3777
3826
  const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
3778
3827
 
@@ -23,6 +23,7 @@ import {
23
23
  monthCreateRange,
24
24
  daySelectionState,
25
25
  getIsToday,
26
+ nowInTimeZone,
26
27
  filterHiddenDays,
27
28
  getWeekDays,
28
29
  getYearMonths,
@@ -72,6 +73,13 @@ export type YearViewProps<T = unknown> = SlotStyleProps<YearViewSlot> & {
72
73
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
73
74
  hiddenDays?: number[];
74
75
  locale?: Locale;
76
+ /**
77
+ * The instant whose calendar day is highlighted as today. Defaults to the
78
+ * device clock, and is read in `timeZone` when one is set.
79
+ */
80
+ now?: Date;
81
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
82
+ timeZone?: string;
75
83
  /** Translations for the screen-reader words; omitted keys use English. */
76
84
  labels?: Partial<CalendarLabels>;
77
85
  /** Highlight this date instead of the real "today". */
@@ -125,6 +133,8 @@ function YearViewInner<T>({
125
133
  weekStartsOn,
126
134
  hiddenDays,
127
135
  locale,
136
+ now,
137
+ timeZone,
128
138
  labels: labelsProp,
129
139
  activeDate,
130
140
  selectedRange,
@@ -152,6 +162,7 @@ function YearViewInner<T>({
152
162
  setColumns(Math.max(2, Math.min(4, Math.floor(width / minMonthWidth))));
153
163
  };
154
164
 
165
+ const today = nowInTimeZone(now, timeZone);
155
166
  const months = useMemo(() => getYearMonths(date), [date]);
156
167
  // Each mini month's week rows, built once per year rather than per render, so
157
168
  // the drag hit-test (and the pan it is built into) keeps a stable identity.
@@ -332,7 +343,7 @@ function YearViewInner<T>({
332
343
  if (day.getMonth() !== month.getMonth()) {
333
344
  return <View key={day.toISOString()} style={styles.day} />;
334
345
  }
335
- const isToday = getIsToday(day);
346
+ const isToday = getIsToday(day, today);
336
347
  const isHighlighted = activeDate
337
348
  ? isSameCalendarDay(day, activeDate)
338
349
  : isToday;
package/src/index.tsx CHANGED
@@ -23,6 +23,7 @@
23
23
  export { Calendar, type CalendarProps, type CalendarSlot } from "./components/Calendar";
24
24
  export { Agenda, type AgendaProps, type AgendaSlot } from "./components/Agenda";
25
25
  export { MonthView, type MonthViewProps, type MonthViewSlot } from "./components/MonthView";
26
+ export { MultiWeekView, type MultiWeekViewProps } from "./components/MultiWeekView";
26
27
  export { YearView, type YearViewProps, type YearViewSlot } from "./components/YearView";
27
28
  export { type ResolvedSlot, type SlotDefault, type SlotStyleProps } from "./utils/slots";
28
29
  export { MonthPager, type MonthPagerProps } from "./components/MonthPager";
@@ -89,6 +90,7 @@ export {
89
90
  } from "@super-calendar/core";
90
91
  export {
91
92
  buildMonthGrid,
93
+ buildMultiWeekGrid,
92
94
  layoutMonthWeek,
93
95
  type MonthEventSegment,
94
96
  type MonthGrid,
@@ -96,11 +98,16 @@ export {
96
98
  type MonthGridWeek,
97
99
  type MonthGridWeekday,
98
100
  type MonthWeekEvents,
101
+ type MultiWeekGrid,
102
+ type MultiWeekGridDay,
103
+ type MultiWeekGridInterval,
104
+ type MultiWeekGridOptions,
105
+ type MultiWeekGridWeek,
99
106
  type UseMonthGridOptions,
100
107
  useMonthGrid,
101
108
  weekdayFormatToken,
102
109
  } from "@super-calendar/core";
103
- export { expandRecurringEvents } from "@super-calendar/core";
110
+ export { expandRecurringEvents, type ExpandRecurringEventsOptions } from "@super-calendar/core";
104
111
  export { type CalendarLabels, defaultCalendarLabels } from "@super-calendar/core";
105
112
  export {
106
113
  type ICalEvent,
@@ -108,7 +115,15 @@ export {
108
115
  toICalendar,
109
116
  type ToICalendarOptions,
110
117
  } from "@super-calendar/core";
111
- export { eventsInTimeZone, toZonedTime } from "@super-calendar/core";
118
+ export {
119
+ eventsInTimeZone,
120
+ fromZonedRange,
121
+ fromZonedTime,
122
+ nowInTimeZone,
123
+ toZonedTime,
124
+ zonedDragBounds,
125
+ zonedEventSource,
126
+ } from "@super-calendar/core";
112
127
  export {
113
128
  buildMonthWeeks,
114
129
  getViewDays,
package/src/types.ts CHANGED
@@ -67,8 +67,8 @@ export type RenderEventArgs<T = unknown> = {
67
67
  boxHeight?: SharedValue<number>;
68
68
  /**
69
69
  * On the week/day grid, true when this is a clipped segment of a multi-day
70
- * event that started on an earlier day / continues onto a later day. Lets a
71
- * renderer draw "continues" affordances. `undefined` in month mode.
70
+ * timed event. For an all-day bar, these flags refer to the visible date
71
+ * range instead. Lets a renderer draw "continues" affordances.
72
72
  */
73
73
  continuesBefore?: boolean;
74
74
  continuesAfter?: boolean;
@@ -0,0 +1,63 @@
1
+ /** Keep quick swipes scrollable, then let a held pointer own the date-row drag. */
2
+ export function holdWebDateDrag(
3
+ node: HTMLElement,
4
+ pointer: { pointerId: number; clientX: number; clientY: number },
5
+ start: () => void,
6
+ move: (x: number, y: number) => void,
7
+ cancel: () => void,
8
+ release: () => void,
9
+ ): () => void {
10
+ const doc = node.ownerDocument;
11
+ let active = false;
12
+ let finished = false;
13
+ const detach = () => {
14
+ clearTimeout(timer);
15
+ doc.removeEventListener("pointermove", onMove);
16
+ doc.removeEventListener("pointerup", onUp);
17
+ doc.removeEventListener("pointercancel", onCancel);
18
+ doc.removeEventListener("pointerdown", onAnotherPointer);
19
+ doc.removeEventListener("touchmove", onTouchMove);
20
+ doc.removeEventListener("contextmenu", onContextMenu);
21
+ };
22
+ const stop = () => {
23
+ if (finished) return;
24
+ finished = true;
25
+ detach();
26
+ cancel();
27
+ release();
28
+ };
29
+ const onMove = (event: PointerEvent) => {
30
+ if (event.pointerId !== pointer.pointerId) return;
31
+ if (active) move(event.clientX, event.clientY);
32
+ else if (Math.hypot(event.clientX - pointer.clientX, event.clientY - pointer.clientY) > 8)
33
+ stop();
34
+ };
35
+ const onUp = (event: PointerEvent) => {
36
+ if (event.pointerId !== pointer.pointerId) return;
37
+ finished = true;
38
+ detach();
39
+ release();
40
+ // The view's window pointerup listener commits an active drag.
41
+ };
42
+ const onCancel = (event: PointerEvent) => {
43
+ if (event.pointerId === pointer.pointerId) stop();
44
+ };
45
+ const onAnotherPointer = (event: PointerEvent) => {
46
+ if (event.pointerId !== pointer.pointerId) stop();
47
+ };
48
+ const onTouchMove = (event: TouchEvent) => {
49
+ if (active && event.cancelable) event.preventDefault();
50
+ };
51
+ const onContextMenu = (event: Event) => event.preventDefault();
52
+ const timer = setTimeout(() => {
53
+ active = true;
54
+ start();
55
+ }, 400);
56
+ doc.addEventListener("pointermove", onMove);
57
+ doc.addEventListener("pointerup", onUp);
58
+ doc.addEventListener("pointercancel", onCancel);
59
+ doc.addEventListener("pointerdown", onAnotherPointer);
60
+ doc.addEventListener("touchmove", onTouchMove, { passive: false });
61
+ doc.addEventListener("contextmenu", onContextMenu);
62
+ return stop;
63
+ }