@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.
@@ -1,6 +1,7 @@
1
- import { format, type Locale, isSameMonth, startOfDay } from "date-fns";
1
+ import { addDays, format, type Locale, isSameMonth, startOfDay } from "date-fns";
2
2
  import {
3
3
  type ComponentRef,
4
+ type ComponentType,
4
5
  memo,
5
6
  type ReactElement,
6
7
  useCallback,
@@ -30,6 +31,8 @@ import { Gesture, GestureDetector } from "react-native-gesture-handler";
30
31
  // Web drag-to-select relays cell pointer events up to MonthList; native drag is
31
32
  // driven by a list-level pan there instead.
32
33
  const isWeb = Platform.OS === "web";
34
+ // React 18 forwards the canonical string; React 19 treats it as a boolean attribute.
35
+ const webPreviewProps = isWeb ? { "aria-hidden": true, inert: "inert" } : {};
33
36
  import { useCalendarTheme } from "../theme";
34
37
  import type {
35
38
  CalendarEvent,
@@ -41,9 +44,11 @@ import type {
41
44
  } from "../types";
42
45
  import { createSlots, type SlotStyleProps } from "../utils/slots";
43
46
  import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
47
+ import { holdWebDateDrag } from "../utils/holdWebDateDrag";
44
48
  import { CalendarLabelsContext } from "../utils/labels";
45
49
  import {
46
50
  type CalendarLabels,
51
+ type CreateGhostArgs,
47
52
  type DateRange,
48
53
  type EventAccessibilityLabeler,
49
54
  dayAccessibilityLabel,
@@ -57,7 +62,9 @@ import {
57
62
  import { dayBadgeKind, rangeBandKind } from "@super-calendar/core";
58
63
  import {
59
64
  buildMonthWeeks,
65
+ buildMultiWeekGrid,
60
66
  getIsToday,
67
+ nowInTimeZone,
61
68
  filterHiddenDays,
62
69
  getWeekDays,
63
70
  isSameCalendarDay,
@@ -151,6 +158,7 @@ export type MonthViewSlot =
151
158
  | "dayBadge"
152
159
  | "dayBadgeText"
153
160
  | "rangeBand"
161
+ | "createGhost"
154
162
  | "more"
155
163
  | "morePopover";
156
164
 
@@ -178,6 +186,13 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
178
186
  /** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
179
187
  weekdayFormat?: WeekdayFormat;
180
188
  locale?: Locale;
189
+ /**
190
+ * The instant whose calendar day is highlighted as today. Defaults to the
191
+ * device clock, and is read in `timeZone` when one is set.
192
+ */
193
+ now?: Date;
194
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
195
+ timeZone?: string;
181
196
  /** Sort each day's events by start time before slicing. Default true. */
182
197
  sortedMonthView?: boolean;
183
198
  /** Template for the overflow label; `{moreCount}` is replaced. Default "{moreCount} More". */
@@ -247,6 +262,14 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
247
262
  * plain tap fires `onPressDay`/`onPressCell` instead.
248
263
  */
249
264
  onCreateEvent?: (start: Date, end: Date) => void;
265
+ /**
266
+ * Content inside the drag-to-create preview. Receives the full all-day range,
267
+ * with an exclusive end, that `onCreateEvent` would receive on release. A span
268
+ * crossing rows renders the component once per row with the same range.
269
+ * Requires `onCreateEvent`; content is clipped, noninteractive, and hidden
270
+ * from screen readers. Omit to keep the day highlight without preview content.
271
+ */
272
+ renderCreateGhost?: ComponentType<CreateGhostArgs>;
250
273
  /**
251
274
  * Reports the day span of a create sweep **as it happens**, as the ordered
252
275
  * inclusive `[start, end]` days (both at midnight), so a selection highlight can
@@ -279,8 +302,41 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
279
302
  renderCustomDateForMonth?: (date: Date) => React.ReactNode;
280
303
  };
281
304
 
305
+ /**
306
+ * Which rows a {@link DateRows} grid shows. Internal to the package: the public
307
+ * views and pagers adapt their own props to it.
308
+ */
309
+ export type DateRowsSource =
310
+ | {
311
+ kind: "month";
312
+ /** Any day within the month to render. */
313
+ date: Date;
314
+ showAdjacentMonths: boolean;
315
+ showSixWeeks: boolean;
316
+ }
317
+ | { kind: "multiweek"; date: Date; numberOfWeeks: number };
318
+
319
+ /** Props for the private {@link DateRows} grid shared by the public row views. */
320
+ export type DateRowsProps<T> = Omit<
321
+ MonthViewProps<T>,
322
+ "date" | "showAdjacentMonths" | "showSixWeeks"
323
+ > & { source: DateRowsSource };
324
+
282
325
  function MonthViewInner<T>({
283
326
  date,
327
+ showAdjacentMonths = true,
328
+ showSixWeeks = false,
329
+ ...rest
330
+ }: MonthViewProps<T>): ReactElement {
331
+ const source = useMemo<DateRowsSource>(
332
+ () => ({ kind: "month", date, showAdjacentMonths, showSixWeeks }),
333
+ [date, showAdjacentMonths, showSixWeeks],
334
+ );
335
+ return <DateRows<T> {...rest} source={source} />;
336
+ }
337
+
338
+ function DateRowsInner<T>({
339
+ source,
284
340
  events,
285
341
  maxVisibleEventCount,
286
342
  chipHeight,
@@ -289,14 +345,14 @@ function MonthViewInner<T>({
289
345
  hiddenDays,
290
346
  weekdayFormat = "short",
291
347
  locale,
348
+ now,
349
+ timeZone,
292
350
  sortedMonthView = true,
293
351
  moreLabel = "{moreCount} More",
294
352
  labels: labelsProp,
295
- showAdjacentMonths = true,
296
353
  highlightWeekends = true,
297
354
  disableMonthEventCellPress = false,
298
355
  isRTL = false,
299
- showSixWeeks = false,
300
356
  showTitle = true,
301
357
  showWeekdays = true,
302
358
  activeDate,
@@ -317,6 +373,7 @@ function MonthViewInner<T>({
317
373
  onLongPressEvent,
318
374
  onPressMore,
319
375
  onCreateEvent,
376
+ renderCreateGhost: RenderCreateGhost,
320
377
  onSelectDrag,
321
378
  onDragEvent,
322
379
  onDragStart,
@@ -327,7 +384,12 @@ function MonthViewInner<T>({
327
384
  onDayPointerEnter,
328
385
  classNames,
329
386
  styles: styleOverrides,
330
- }: MonthViewProps<T>): ReactElement {
387
+ }: DateRowsProps<T>): ReactElement {
388
+ const { date } = source;
389
+ const multiWeek = source.kind === "multiweek";
390
+ const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
391
+ const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
392
+ const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : undefined;
331
393
  const theme = useCalendarTheme();
332
394
  const badgeArea = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT + chipGap;
333
395
  const slot = createSlots<MonthViewSlot>({ classNames, styles: styleOverrides });
@@ -362,10 +424,27 @@ function MonthViewInner<T>({
362
424
  events: CalendarEvent<T>[];
363
425
  } | null>(null);
364
426
 
427
+ const today = nowInTimeZone(now, timeZone);
428
+ const multiWeekGrid = useMemo(
429
+ () =>
430
+ numberOfWeeks === undefined
431
+ ? null
432
+ : buildMultiWeekGrid(date, { numberOfWeeks, weekStartsOn, isRTL, hiddenDays }),
433
+ [date, numberOfWeeks, weekStartsOn, isRTL, hiddenDays],
434
+ );
365
435
  const weeks = useMemo(
366
- () => buildMonthWeeks(date, weekStartsOn, { showSixWeeks, isRTL, hiddenDays }),
367
- [date, weekStartsOn, isRTL, showSixWeeks, hiddenDays],
436
+ () =>
437
+ multiWeekGrid
438
+ ? multiWeekGrid.weeks.map((week) => week.days.map((day) => day.date))
439
+ : buildMonthWeeks(date, weekStartsOn, { showSixWeeks, isRTL, hiddenDays }),
440
+ [multiWeekGrid, date, weekStartsOn, isRTL, showSixWeeks, hiddenDays],
368
441
  );
442
+ const title = multiWeekGrid
443
+ ? `${format(multiWeekGrid.visibleRange.start, "PP", { locale })} – ${format(addDays(multiWeekGrid.visibleRange.endExclusive, -1), "PP", { locale })}`
444
+ : format(date, "MMMM yyyy", { locale });
445
+ const windowKey = multiWeekGrid
446
+ ? `${multiWeekGrid.period.start.getTime()}:${numberOfWeeks}:${hiddenDays?.join(",")}:${isRTL}`
447
+ : null;
369
448
 
370
449
  // Weekday labels for the header row (any week works; reuse this month). Reversed
371
450
  // in RTL so they line up with the mirrored day columns.
@@ -383,6 +462,9 @@ function MonthViewInner<T>({
383
462
  const height = chipHeight ?? lineHeight + CHIP_PADDING_V * 2;
384
463
  return { chipHeight: height, chipRowHeight: height + chipGap };
385
464
  }, [theme, chipHeight, chipGap]);
465
+ const minimumRowHeight =
466
+ badgeArea +
467
+ Math.max(1, maxVisibleEventCount ?? FALLBACK_VISIBLE_COUNT) * chipMetrics.chipRowHeight;
386
468
 
387
469
  // How many chips fit per cell: a fixed cap when `maxVisibleEventCount` is set,
388
470
  // else derived from the measured cell height and the (default) chip metrics.
@@ -414,9 +496,10 @@ function MonthViewInner<T>({
414
496
  return map;
415
497
  }, [events, sortedMonthView]);
416
498
 
417
- // Draw the day-cell grid only for an events calendar; the events-free date
418
- // picker reads cleaner without it (matching the dom renderer).
419
- const showGrid = events.length > 0;
499
+ // Custom drafts need event lanes before the first event exists. Keep the
500
+ // events-free picker layout when no creation content is requested.
501
+ const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
502
+ const showGrid = multiWeek || events.length > 0 || createContentEnabled;
420
503
 
421
504
  // Lay out each week row's spanning bars once per data change, not per render.
422
505
  const weekLayouts = useMemo(
@@ -430,11 +513,30 @@ function MonthViewInner<T>({
430
513
  // ---- drag to create a day span / reschedule an event ----------------------
431
514
  const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
432
515
  const gridRef = useRef<ComponentRef<typeof View>>(null);
516
+ const heldTouch = useRef<(() => void) | null>(null);
517
+ const heldOrigin = useRef<{ day: Date; event: CalendarEvent<T> | null } | null>(null);
433
518
  // The live drag drives the preview; the ref is what the gesture and the web
434
519
  // pointer listeners read, so neither has to be rebuilt as the hover day moves
435
520
  // (rebuilding the gesture mid-drag would cancel it).
436
521
  const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
522
+ const createRange = useMemo(
523
+ () =>
524
+ createContentEnabled && drag?.kind === "create"
525
+ ? monthCreateRange(drag.anchor, drag.hover)
526
+ : null,
527
+ [createContentEnabled, drag],
528
+ );
437
529
  const dragRef = useRef<MonthDrag<T> | null>(null);
530
+ const interactionWindow = useRef(windowKey);
531
+ interactionWindow.current = windowKey;
532
+ const mounted = useRef(true);
533
+ useEffect(() => {
534
+ mounted.current = true;
535
+ return () => {
536
+ mounted.current = false;
537
+ dragRef.current = null;
538
+ };
539
+ }, []);
438
540
  // Whether the pointer has reached a different day than it started on. The web
439
541
  // has no long-press to disambiguate, so a create only commits once it moves.
440
542
  const movedRef = useRef(false);
@@ -446,6 +548,20 @@ function MonthViewInner<T>({
446
548
  dragRef.current = next;
447
549
  setDrag(next);
448
550
  }, []);
551
+ useEffect(() => {
552
+ if (windowKey === null) return;
553
+ applyDrag(null);
554
+ setMoreOpenFor(null);
555
+ return () => {
556
+ dragRef.current = null;
557
+ };
558
+ }, [windowKey, applyDrag]);
559
+ useEffect(
560
+ () => () => {
561
+ heldTouch.current?.();
562
+ },
563
+ [windowKey],
564
+ );
449
565
 
450
566
  // True when this press is the click trailing a just-committed web drag, which
451
567
  // the caller should swallow. Clears the flag so only that one press is eaten.
@@ -462,6 +578,28 @@ function MonthViewInner<T>({
462
578
  !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable),
463
579
  [eventStartEditable],
464
580
  );
581
+ // Live selection can rerender its parent during a held web gesture. Callback
582
+ // identity changes do not invalidate a still-selectable day or movable event.
583
+ useEffect(() => {
584
+ const origin = heldOrigin.current;
585
+ if (!origin) return;
586
+ const current = dragRef.current;
587
+ const destination = current
588
+ ? current.kind === "create"
589
+ ? current.hover
590
+ : current.to
591
+ : origin.day;
592
+ const constraints = { minDate, maxDate, isDateDisabled };
593
+ if (
594
+ !isDateSelectable(origin.day, constraints) ||
595
+ !isDateSelectable(destination, constraints) ||
596
+ (origin.event
597
+ ? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event)
598
+ : !onCreateEvent && !onSelectDrag)
599
+ ) {
600
+ heldTouch.current?.();
601
+ }
602
+ });
465
603
 
466
604
  // The day under a grid-relative point, plus the event bar drawn there (if any).
467
605
  // Returns null for a point on a blanked adjacent-month cell or an unselectable
@@ -504,12 +642,19 @@ function MonthViewInner<T>({
504
642
  );
505
643
 
506
644
  const beginDrag = useCallback(
507
- (x: number, y: number) => {
645
+ (x: number, y: number, origin?: { day: Date; event: CalendarEvent<T> | null }) => {
646
+ if (!mounted.current || (multiWeek && interactionWindow.current !== windowKey)) return;
647
+ if (
648
+ origin &&
649
+ (!isDateSelectable(origin.day, { minDate, maxDate, isDateDisabled }) ||
650
+ (origin.event && !events.includes(origin.event)))
651
+ )
652
+ return;
508
653
  // A fresh press starts a new interaction, so any guard left over from the
509
654
  // previous one (a drag whose trailing click never reached a cell) is stale.
510
655
  suppressPressRef.current = false;
511
656
  movedRef.current = false;
512
- const hit = hitTest(x, y);
657
+ const hit = origin ?? hitTest(x, y);
513
658
  if (!hit) return;
514
659
  if (hit.event) {
515
660
  if (!onDragEvent || !canMoveEvent(hit.event)) return;
@@ -521,7 +666,21 @@ function MonthViewInner<T>({
521
666
  applyDrag({ kind: "create", anchor: hit.day, hover: hit.day });
522
667
  }
523
668
  },
524
- [hitTest, onDragEvent, onCreateEvent, onSelectDrag, onDragStart, canMoveEvent, applyDrag],
669
+ [
670
+ hitTest,
671
+ onDragEvent,
672
+ onCreateEvent,
673
+ onSelectDrag,
674
+ onDragStart,
675
+ canMoveEvent,
676
+ applyDrag,
677
+ multiWeek,
678
+ windowKey,
679
+ minDate,
680
+ maxDate,
681
+ isDateDisabled,
682
+ events,
683
+ ],
525
684
  );
526
685
 
527
686
  const extendDrag = useCallback(
@@ -612,17 +771,63 @@ function MonthViewInner<T>({
612
771
  removeEventListener?: (type: string, cb: () => void) => void;
613
772
  };
614
773
  target.addEventListener?.("pointerup", up);
615
- // Let a touch drag sketch a span instead of scrolling the page under it, and
616
- // stop a sweep from text-selecting the day numbers it passes over.
774
+ // Multi-week touch input scrolls until a hold takes ownership of the drag.
617
775
  const node = gridRef.current as unknown as {
618
776
  style?: { touchAction?: string; userSelect?: string };
619
777
  } | null;
620
778
  if (node?.style) {
621
- node.style.touchAction = "none";
779
+ node.style.touchAction = multiWeek ? "pan-y" : "none";
622
780
  node.style.userSelect = "none";
623
781
  }
624
782
  return () => target.removeEventListener?.("pointerup", up);
625
- }, [dragEnabled, endDrag]);
783
+ }, [dragEnabled, endDrag, multiWeek]);
784
+
785
+ const webDragHandlers = useRef({ beginDrag, extendDrag });
786
+ webDragHandlers.current = { beginDrag, extendDrag };
787
+ const pressWebGrid = (event: RNPointerEvent) => {
788
+ const pointer = event.nativeEvent;
789
+ if (multiWeek && (pointer.button !== 0 || pointer.isPrimary === false || heldTouch.current))
790
+ return;
791
+ if (multiWeek) suppressPressRef.current = false;
792
+ const start = () => {
793
+ const point = gridPoint(pointer.clientX, pointer.clientY);
794
+ if (point) webDragHandlers.current.beginDrag(point.x, point.y);
795
+ };
796
+ if (!multiWeek || !pointer.pointerType || pointer.pointerType === "mouse") {
797
+ start();
798
+ return;
799
+ }
800
+ // A native View ref is the host HTMLElement only on react-native-web.
801
+ const node = gridRef.current as unknown as HTMLElement | null;
802
+ if (!node) return;
803
+ const point = gridPoint(pointer.clientX, pointer.clientY);
804
+ if (!point) return;
805
+ const origin = hitTest(point.x, point.y);
806
+ if (!origin) return;
807
+ heldOrigin.current = origin;
808
+ heldTouch.current = holdWebDateDrag(
809
+ node,
810
+ pointer,
811
+ () => {
812
+ // Lane layout can change during the delay without removing the pressed
813
+ // event. Keep the original day/event instead of hit-testing again.
814
+ if (interactionWindow.current === windowKey)
815
+ webDragHandlers.current.beginDrag(point.x, point.y, origin);
816
+ },
817
+ (x, y) => {
818
+ const point = gridPoint(x, y);
819
+ if (point) webDragHandlers.current.extendDrag(point.x, point.y);
820
+ },
821
+ () => {
822
+ applyDrag(null);
823
+ movedRef.current = false;
824
+ },
825
+ () => {
826
+ heldTouch.current = null;
827
+ heldOrigin.current = null;
828
+ },
829
+ );
830
+ };
626
831
 
627
832
  const renderDay = (
628
833
  day: Date,
@@ -630,7 +835,7 @@ function MonthViewInner<T>({
630
835
  rowLayout: MonthWeekEvents<T>,
631
836
  visibleLanes: number,
632
837
  ) => {
633
- const isCurrentMonth = isSameMonth(day, date);
838
+ const isCurrentMonth = multiWeek || isSameMonth(day, date);
634
839
 
635
840
  // Blank out adjacent-month days when they're hidden, keeping the grid shape.
636
841
  if (!isCurrentMonth && !showAdjacentMonths) {
@@ -655,7 +860,7 @@ function MonthViewInner<T>({
655
860
  }
656
861
 
657
862
  const dayEvents = eventsByDay.get(startOfDay(day).toISOString()) ?? [];
658
- const isToday = getIsToday(day);
863
+ const isToday = getIsToday(day, today);
659
864
  // Highlight the chosen `activeDate` when supplied, else the real today.
660
865
  const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
661
866
  // Selection band wins over the weekend tint; the today badge shows unless the
@@ -914,7 +1119,7 @@ function MonthViewInner<T>({
914
1119
  })}
915
1120
  allowFontScaling={false}
916
1121
  >
917
- {format(date, "MMMM yyyy", locale ? { locale } : undefined)}
1122
+ {title}
918
1123
  </Text>
919
1124
  ) : null}
920
1125
  {showWeekdays ? (
@@ -973,7 +1178,7 @@ function MonthViewInner<T>({
973
1178
  <View key={keyExtractor(event, index)} style={styles.moreCardRow}>
974
1179
  <RenderEventComponent
975
1180
  event={event}
976
- mode="month"
1181
+ mode={multiWeek ? "multiweek" : "month"}
977
1182
  isAllDay={isAllDayEvent(event)}
978
1183
  onPress={() => {
979
1184
  setMoreOpenFor(null);
@@ -987,111 +1192,198 @@ function MonthViewInner<T>({
987
1192
  </Pressable>
988
1193
  </Modal>
989
1194
  ) : null}
990
- <MonthGridSurface gesture={dragGesture}>
991
- <View
992
- ref={gridRef}
993
- testID="month-grid"
994
- {...slot("grid", { base: styles.container })}
995
- onLayout={handleLayout}
996
- {...(isWeb && dragEnabled
997
- ? {
998
- onPointerDown: (event: RNPointerEvent) => {
999
- const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
1000
- if (point) beginDrag(point.x, point.y);
1001
- },
1002
- onPointerMove: (event: RNPointerEvent) => {
1003
- if (!dragRef.current) return;
1004
- const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
1005
- if (point) extendDrag(point.x, point.y);
1006
- },
1007
- }
1008
- : null)}
1009
- >
1010
- {weeks.map((week, weekIndex) => {
1011
- // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
1012
- // event is one bar across its columns, stacked into lanes; the bars render
1013
- // in an overlay so they can span cells, and the cells reserve the lane rows
1014
- // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
1015
- const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
1016
- const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
1017
- const cols = week.length;
1018
- // With adjacent months hidden, clamp bars to the current-month columns so
1019
- // none draw over the blank leading/trailing cells.
1020
- let firstVisCol = 0;
1021
- let lastVisCol = cols - 1;
1022
- if (showGrid && !showAdjacentMonths) {
1023
- const first = week.findIndex((d) => isSameMonth(d, date));
1024
- if (first !== -1) {
1025
- firstVisCol = first;
1026
- lastVisCol =
1027
- cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
1195
+ <DateRowsViewport scrollable={multiWeek}>
1196
+ <MonthGridSurface gesture={dragGesture}>
1197
+ <View
1198
+ ref={gridRef}
1199
+ testID={multiWeek ? "multiweek-grid" : "month-grid"}
1200
+ accessibilityLabel={multiWeek ? title : undefined}
1201
+ {...slot("grid", {
1202
+ base: [
1203
+ styles.container,
1204
+ multiWeek ? { minHeight: minimumRowHeight * weeks.length } : undefined,
1205
+ ],
1206
+ })}
1207
+ onLayout={handleLayout}
1208
+ {...(isWeb && dragEnabled
1209
+ ? {
1210
+ onPointerDown: pressWebGrid,
1211
+ onPointerMove: (event: RNPointerEvent) => {
1212
+ if (heldTouch.current) return;
1213
+ if (!dragRef.current) return;
1214
+ const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
1215
+ if (point) extendDrag(point.x, point.y);
1216
+ },
1217
+ }
1218
+ : null)}
1219
+ >
1220
+ {weeks.map((week, weekIndex) => {
1221
+ // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
1222
+ // event is one bar across its columns, stacked into lanes; the bars render
1223
+ // in an overlay so they can span cells, and the cells reserve the lane rows
1224
+ // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
1225
+ const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
1226
+ const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
1227
+ const cols = week.length;
1228
+ // With adjacent months hidden, clamp bars to the current-month columns so
1229
+ // none draw over the blank leading/trailing cells.
1230
+ let firstVisCol = 0;
1231
+ let lastVisCol = cols - 1;
1232
+ if (showGrid && !showAdjacentMonths) {
1233
+ const first = week.findIndex((d) => isSameMonth(d, date));
1234
+ if (first !== -1) {
1235
+ firstVisCol = first;
1236
+ lastVisCol =
1237
+ cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
1238
+ }
1028
1239
  }
1029
- }
1030
- return (
1031
- <View
1032
- {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
1033
- key={week[0].toISOString()}
1034
- >
1035
- {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
1036
- {showGrid ? (
1037
- <View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
1038
- {rowLayout.segments
1039
- .filter((seg) => seg.lane < visibleLanes)
1040
- .map((seg) => {
1041
- const startCol = Math.max(seg.startCol, firstVisCol);
1042
- const endCol = Math.min(seg.endCol, lastVisCol);
1043
- if (startCol > endCol) return null;
1044
- // Fade the bar being carried, so the tinted drop target reads
1045
- // as where it is going and this as where it came from.
1046
- const isDragged = drag?.kind === "move" && drag.event === seg.event;
1047
- return (
1048
- <View
1049
- key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1050
- style={{
1240
+ const draftColumns = createRange
1241
+ ? week.flatMap((day, index) =>
1242
+ (showAdjacentMonths || isSameMonth(day, date)) &&
1243
+ day >= createRange.start &&
1244
+ day < createRange.end
1245
+ ? [index]
1246
+ : [],
1247
+ )
1248
+ : [];
1249
+ const draftStart = draftColumns[0];
1250
+ const draftEnd = draftColumns.at(-1);
1251
+ // Overlay a free lane when possible, without moving cells under the drag.
1252
+ const draftLane = Math.min(visibleLanes, Math.max(0, capacity.full - 1));
1253
+ const draftTop = badgeArea + draftLane * chipMetrics.chipRowHeight;
1254
+ const draftHeight = Math.min(
1255
+ chipMetrics.chipHeight,
1256
+ Math.max(0, gridHeight / weeks.length - draftTop),
1257
+ );
1258
+ return (
1259
+ <View
1260
+ {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
1261
+ key={multiWeekGrid?.weeks[weekIndex].id ?? week[0].toISOString()}
1262
+ >
1263
+ {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
1264
+ {showGrid ? (
1265
+ <View
1266
+ style={[
1267
+ StyleSheet.absoluteFill,
1268
+ multiWeek
1269
+ ? styles.childrenOnlyPointerEvents
1270
+ : { pointerEvents: "box-none" },
1271
+ ]}
1272
+ >
1273
+ {rowLayout.segments
1274
+ .filter((seg) => seg.lane < visibleLanes)
1275
+ .map((seg) => {
1276
+ const startCol = Math.max(seg.startCol, firstVisCol);
1277
+ const endCol = Math.min(seg.endCol, lastVisCol);
1278
+ if (startCol > endCol) return null;
1279
+ // Fade the bar being carried, so the tinted drop target reads
1280
+ // as where it is going and this as where it came from.
1281
+ const isDragged = drag?.kind === "move" && drag.event === seg.event;
1282
+ return (
1283
+ <View
1284
+ key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1285
+ style={[
1286
+ {
1287
+ position: "absolute",
1288
+ left: pct((startCol / cols) * 100),
1289
+ width: pct(((endCol - startCol + 1) / cols) * 100),
1290
+ top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
1291
+ height: chipMetrics.chipHeight,
1292
+ paddingHorizontal: CHIP_INSET_H,
1293
+ // Let a sweep in progress reach the cells underneath.
1294
+ opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
1295
+ },
1296
+ multiWeek
1297
+ ? drag
1298
+ ? styles.noPointerEvents
1299
+ : styles.childrenOnlyPointerEvents
1300
+ : { pointerEvents: drag ? "none" : "box-none" },
1301
+ ]}
1302
+ >
1303
+ <RenderEventComponent
1304
+ event={seg.event}
1305
+ mode={multiWeek ? "multiweek" : "month"}
1306
+ isAllDay={isAllDayEvent(seg.event)}
1307
+ onPress={
1308
+ disableMonthEventCellPress
1309
+ ? () => {}
1310
+ : () => {
1311
+ if (consumeSuppressedPress()) return;
1312
+ onPressEvent(seg.event);
1313
+ }
1314
+ }
1315
+ onLongPress={
1316
+ disableMonthEventCellPress || !onLongPressEvent
1317
+ ? undefined
1318
+ : () => onLongPressEvent(seg.event)
1319
+ }
1320
+ />
1321
+ </View>
1322
+ );
1323
+ })}
1324
+ {RenderCreateGhost &&
1325
+ createRange &&
1326
+ draftStart !== undefined &&
1327
+ draftEnd !== undefined &&
1328
+ draftHeight > 0 ? (
1329
+ <View
1330
+ testID="month-create-ghost"
1331
+ {...slot("createGhost", {
1332
+ base: {
1051
1333
  position: "absolute",
1052
- left: pct((startCol / cols) * 100),
1053
- width: pct(((endCol - startCol + 1) / cols) * 100),
1054
- top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
1055
- height: chipMetrics.chipHeight,
1056
- paddingHorizontal: CHIP_INSET_H,
1057
- // Let a sweep in progress reach the cells underneath.
1058
- pointerEvents: drag ? "none" : "box-none",
1059
- opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
1060
- }}
1061
- >
1062
- <RenderEventComponent
1063
- event={seg.event}
1064
- mode="month"
1065
- isAllDay={isAllDayEvent(seg.event)}
1066
- onPress={
1067
- disableMonthEventCellPress
1068
- ? () => {}
1069
- : () => {
1070
- if (consumeSuppressedPress()) return;
1071
- onPressEvent(seg.event);
1072
- }
1073
- }
1074
- onLongPress={
1075
- disableMonthEventCellPress || !onLongPressEvent
1076
- ? undefined
1077
- : () => onLongPressEvent(seg.event)
1078
- }
1079
- />
1080
- </View>
1081
- );
1082
- })}
1083
- </View>
1084
- ) : null}
1085
- </View>
1086
- );
1087
- })}
1088
- </View>
1089
- </MonthGridSurface>
1334
+ left: pct((draftStart / cols) * 100),
1335
+ right: pct(((cols - 1 - draftEnd) / cols) * 100),
1336
+ top: draftTop,
1337
+ height: draftHeight,
1338
+ marginHorizontal: CHIP_INSET_H,
1339
+ overflow: "hidden",
1340
+ zIndex: 1,
1341
+ },
1342
+ themed: {
1343
+ backgroundColor: theme.colors.rangeBackground,
1344
+ borderColor: theme.colors.selectedBackground,
1345
+ borderWidth: 1,
1346
+ borderRadius: 4,
1347
+ },
1348
+ })}
1349
+ {...webPreviewProps}
1350
+ pointerEvents="none"
1351
+ accessible={false}
1352
+ accessibilityElementsHidden
1353
+ importantForAccessibility="no-hide-descendants"
1354
+ >
1355
+ <RenderCreateGhost start={createRange.start} end={createRange.end} />
1356
+ </View>
1357
+ ) : null}
1358
+ </View>
1359
+ ) : null}
1360
+ </View>
1361
+ );
1362
+ })}
1363
+ </View>
1364
+ </MonthGridSurface>
1365
+ </DateRowsViewport>
1090
1366
  </View>
1091
1367
  </CalendarLabelsContext.Provider>
1092
1368
  );
1093
1369
  }
1094
1370
 
1371
+ function DateRowsViewport({
1372
+ scrollable,
1373
+ children,
1374
+ }: {
1375
+ scrollable: boolean;
1376
+ children: ReactElement;
1377
+ }): ReactElement {
1378
+ return scrollable ? (
1379
+ <ScrollView style={styles.container} contentContainerStyle={{ flexGrow: 1 }}>
1380
+ {children}
1381
+ </ScrollView>
1382
+ ) : (
1383
+ children
1384
+ );
1385
+ }
1386
+
1095
1387
  // The grid, wrapped in a GestureDetector only when a month drag is wired up, so
1096
1388
  // the picker (and any month without drag handlers) mounts no gesture at all.
1097
1389
  function MonthGridSurface({
@@ -1123,6 +1415,12 @@ function MonthGridSurface({
1123
1415
  */
1124
1416
  export const MonthView = memo(MonthViewInner) as typeof MonthViewInner;
1125
1417
 
1418
+ /**
1419
+ * The day-row grid behind the public row views: week rows of day cells with
1420
+ * spanning event bars, overflow, selection, and drag handling.
1421
+ */
1422
+ export const DateRows = memo(DateRowsInner) as typeof DateRowsInner;
1423
+
1126
1424
  const styles = StyleSheet.create({
1127
1425
  root: {
1128
1426
  flex: 1,
@@ -1144,6 +1442,9 @@ const styles = StyleSheet.create({
1144
1442
  container: {
1145
1443
  flex: 1,
1146
1444
  },
1445
+ // react-native-web needs registered styles to expand the child rules for box-none.
1446
+ childrenOnlyPointerEvents: { pointerEvents: "box-none" },
1447
+ noPointerEvents: { pointerEvents: "none" },
1147
1448
  weekRow: {
1148
1449
  flex: 1,
1149
1450
  flexDirection: "row",