@super-calendar/native 2.8.2 → 2.9.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.
@@ -17,8 +17,10 @@ import {
17
17
  } from "date-fns";
18
18
  import {
19
19
  createContext,
20
+ type Dispatch,
20
21
  memo,
21
22
  type ReactElement,
23
+ type SetStateAction,
22
24
  useCallback,
23
25
  useContext,
24
26
  useEffect,
@@ -58,6 +60,8 @@ import type {
58
60
  BusinessHoursBand,
59
61
  CalendarEvent,
60
62
  CalendarMode,
63
+ EventDragHandler,
64
+ EventDragStartHandler,
61
65
  EventKeyExtractor,
62
66
  RenderEvent,
63
67
  TimeGridMode,
@@ -73,6 +77,7 @@ import {
73
77
  import {
74
78
  backgroundBandsForDay,
75
79
  cellRangeFromDrag,
80
+ clampMoveStartMinutes,
76
81
  useNow,
77
82
  closedHourBands,
78
83
  overlapsOtherEvents,
@@ -83,11 +88,17 @@ import {
83
88
  import { formatHour, layoutDayEvents, type PositionedEvent } from "@super-calendar/core";
84
89
  import type { EventAccessibilityLabeler } from "@super-calendar/core";
85
90
  import { type WeekdayFormat, weekdayFormatToken } from "@super-calendar/core";
86
- import { SlotStylesProvider, type SlotStyleProps, useSlots } from "../utils/slots";
91
+ import {
92
+ type ResolvedSlot,
93
+ SlotStylesProvider,
94
+ type SlotStyleProps,
95
+ useSlots,
96
+ } from "../utils/slots";
87
97
  import { useWebGridZoom } from "../utils/useWebGridZoom";
88
98
  import { useWebPagerKeys } from "../utils/useWebPagerKeys";
89
99
  import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
90
100
  import { AllDayLane } from "./AllDayLane";
101
+ import { type MultiDayMove, MultiDayMovePreview } from "./MultiDayMovePreview";
91
102
 
92
103
  // Horizontal swipe paging doesn't translate to web; there we disable it and page
93
104
  // with the arrow keys instead.
@@ -180,6 +191,78 @@ const EdgePagingContext = createContext<EdgePaging | null>(null);
180
191
 
181
192
  const noop = () => {};
182
193
 
194
+ /**
195
+ * The tail of a move that runs past midnight, drawn at the top of the next day's
196
+ * column so the drop reads on both days before the finger lifts. Mounted only
197
+ * while a drag is actually spilling (see `spillHeight`), so an idle grid pays
198
+ * nothing for it; its geometry is driven on the UI thread from there.
199
+ */
200
+ function MoveSpillPreview<T>({
201
+ spillHeight,
202
+ moveOffsetX,
203
+ cellHeight,
204
+ dayLeftPx,
205
+ dayWidth,
206
+ nextDayDirection,
207
+ minHour,
208
+ event,
209
+ mode,
210
+ renderEvent,
211
+ slotProps,
212
+ }: {
213
+ spillHeight: SharedValue<number>;
214
+ moveOffsetX: SharedValue<number>;
215
+ cellHeight: SharedValue<number>;
216
+ dayLeftPx: number;
217
+ dayWidth: number;
218
+ nextDayDirection: number;
219
+ minHour: number;
220
+ event: CalendarEvent<T>;
221
+ mode: CalendarMode;
222
+ renderEvent: RenderEvent<T>;
223
+ slotProps: ResolvedSlot<ViewStyle>;
224
+ }): ReactElement {
225
+ const RenderEventComponent = renderEvent;
226
+ const style = useAnimatedStyle(
227
+ () => ({
228
+ height: spillHeight.value,
229
+ opacity: spillHeight.value > 0 ? 1 : 0,
230
+ zIndex: spillHeight.value > 0 ? DRAG_EVENT_Z : 0,
231
+ transform: [
232
+ { translateX: moveOffsetX.value + nextDayDirection * dayWidth },
233
+ // The box's `top` is the `minHour` gridline, but the tail starts at
234
+ // midnight. With a window that starts after 00:00 this pushes the preview
235
+ // out of view, exactly like the continuation the drop will commit.
236
+ { translateY: -minHour * cellHeight.value },
237
+ ],
238
+ }),
239
+ [dayWidth, nextDayDirection, minHour],
240
+ );
241
+ return (
242
+ <Animated.View
243
+ {...slotProps}
244
+ accessibilityElementsHidden
245
+ importantForAccessibility="no-hide-descendants"
246
+ style={[
247
+ styles.eventBox,
248
+ styles.nonInteractive,
249
+ { left: dayLeftPx, width: dayWidth, top: 0 },
250
+ slotProps.style,
251
+ style,
252
+ ]}
253
+ >
254
+ <RenderEventComponent
255
+ event={event}
256
+ mode={mode}
257
+ boxHeight={spillHeight}
258
+ continuesBefore
259
+ continuesAfter={false}
260
+ onPress={noop}
261
+ />
262
+ </Animated.View>
263
+ );
264
+ }
265
+
183
266
  /**
184
267
  * The floating copy of a dragged event, rendered above the pager so a cross-week
185
268
  * drag stays visible after its source page pages away. Position, size, and
@@ -219,23 +302,10 @@ function DragGhost<T>({
219
302
  );
220
303
  }
221
304
 
222
- /**
223
- * Called when an event is dragged (moved or resized) to new start/end times.
224
- * Return `false` to reject the drop — the event snaps back to where it started
225
- * (e.g. to forbid overlaps or out-of-bounds slots). Any other return accepts it.
226
- */
227
- export type EventDragHandler<T> = (
228
- event: CalendarEvent<T>,
229
- start: Date,
230
- end: Date,
231
- ) => void | boolean;
232
- /**
233
- * Called when a move or resize gesture begins, before any change is committed:
234
- * on grab for a move (after the long-press), and when the resize drag starts.
235
- * Handy for haptic feedback (e.g. `expo-haptics`). Requires drag to be enabled
236
- * via `onDragEvent`.
237
- */
238
- export type EventDragStartHandler<T> = (event: CalendarEvent<T>) => void;
305
+ // The drag handler types live in `../types` so the Reanimated-free month view can
306
+ // share them; re-exported here because both are part of this module's public API.
307
+ export type { EventDragHandler, EventDragStartHandler } from "../types";
308
+
239
309
  // Hour labels are nudged up so the number sits centred on its grid line. Pad the
240
310
  // scroll content by the same amount so the top-most label is never clipped.
241
311
  const HOUR_LABEL_TOP_INSET = 12;
@@ -243,10 +313,19 @@ const HOUR_LABEL_NUDGE = 6;
243
313
 
244
314
  type AnimatedEventBoxProps<T> = {
245
315
  positioned: PositionedEvent<T>;
316
+ eventIndex: number;
317
+ movingEvent: CalendarEvent<T> | null;
318
+ onMovePreview: Dispatch<SetStateAction<MultiDayMove<T> | null>>;
246
319
  cellHeight: SharedValue<number>;
247
320
  minHour: number;
321
+ maxHour: number;
248
322
  left: number;
249
323
  width: number;
324
+ // Left edge of the whole day column (the box's own `left` is inset by its
325
+ // overlap column), so the "runs past midnight" preview can span the next column.
326
+ dayLeftPx: number;
327
+ // Which way the next calendar day lies, in columns: +1 normally, -1 under RTL.
328
+ nextDayDirection: number;
250
329
  // Drag-to-move across days needs the column width and this box's day index
251
330
  // within the visible range, so a horizontal drag maps to (and clamps to) days.
252
331
  dayWidth: number;
@@ -278,10 +357,16 @@ type AnimatedEventBoxProps<T> = {
278
357
 
279
358
  function AnimatedEventBox<T>({
280
359
  positioned,
360
+ eventIndex,
361
+ movingEvent,
362
+ onMovePreview,
281
363
  cellHeight,
282
364
  minHour,
365
+ maxHour,
283
366
  left,
284
367
  width,
368
+ dayLeftPx,
369
+ nextDayDirection,
285
370
  dayWidth,
286
371
  dayIndex,
287
372
  dayCount,
@@ -342,6 +427,10 @@ function AnimatedEventBox<T>({
342
427
  // Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
343
428
  // above all the others, then back to 0 when it settles.
344
429
  const dragZ = useSharedValue(0);
430
+ // 1 while a move gesture is running. Only gates the spill preview: the box's own
431
+ // clip is geometric, so it can't disagree with the box during the frames between
432
+ // release and the committed re-render.
433
+ const moving = useSharedValue(0);
345
434
  // Edge auto-advance: which side the drag has pushed past the visible columns
346
435
  // (-1 left / 0 none / +1 right).
347
436
  const edgeDir = useSharedValue(0);
@@ -361,6 +450,22 @@ function AnimatedEventBox<T>({
361
450
  // ("Cannot copy value of type `Date`").
362
451
  const startHours = positioned.startHours;
363
452
  const durationHours = positioned.durationHours;
453
+ const ownsStart = !positioned.continuesBefore;
454
+ const multiDay = positioned.continuesBefore || positioned.continuesAfter;
455
+ const hiddenForMove = positioned.event === movingEvent;
456
+ // Where the move gesture clamps from, mirrored into a shared value so it isn't a
457
+ // gesture dependency. A gesture memoized on a value the dragged event carries
458
+ // would be rebuilt under the finger, and so torn down mid-drag, the moment a
459
+ // consumer updates `events` (the same reason `commitDrag` reads the event
460
+ // through `latest`). `ownsStart` is false on a segment the layout clipped from
461
+ // an earlier day, whose 00:00 top edge isn't where the event starts.
462
+ const dragStartSV = useDerivedValue(
463
+ () => ({
464
+ minutes: startHours * MINUTES_PER_HOUR,
465
+ ownsStart,
466
+ }),
467
+ [startHours, ownsStart],
468
+ );
364
469
 
365
470
  // Live pixel height of the box, driven on the UI thread by the shared
366
471
  // cellHeight (plus any in-progress resize). Handed to renderEvent so custom
@@ -375,15 +480,77 @@ function AnimatedEventBox<T>({
375
480
  [durationHours],
376
481
  );
377
482
 
378
- const boxStyle = useAnimatedStyle(
379
- () => ({
380
- // A top-edge resize pushes the box down and shortens it (start moves later).
381
- top: (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value,
382
- height: boxHeight.value,
483
+ // The source segment may stop at midnight while the full event continues in
484
+ // the next column. Keep the height passed to custom renderers identical to the
485
+ // wrapper they fill, while `boxHeight` retains the complete duration for drag
486
+ // math and the floating cross-page ghost.
487
+ const visibleBoxHeight = useDerivedValue(() => {
488
+ const top =
489
+ (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value;
490
+ const dayEnd = (HOURS_PER_DAY - minHour) * cellHeight.value;
491
+ return Math.max(Math.min(boxHeight.value, dayEnd - top), MIN_EVENT_HEIGHT);
492
+ }, [startHours, minHour]);
493
+
494
+ const boxStyle = useAnimatedStyle(() => {
495
+ // A top-edge resize pushes the box down and shortens it (start moves later).
496
+ const top =
497
+ (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value;
498
+ // Cut the box off at midnight; whatever runs past it shows in the next column
499
+ // instead (see MoveSpillPreview), the way a committed event spanning midnight
500
+ // already renders. Purely geometric, so a resting box (already clipped to the
501
+ // day by `layoutDayEvents`) is untouched and the height doesn't jump when a
502
+ // drag commits.
503
+ return {
504
+ top,
505
+ height: visibleBoxHeight.value,
383
506
  transform: [{ translateX: moveOffsetX.value }],
384
507
  zIndex: dragZ.value,
385
- }),
386
- [startHours, durationHours, minHour],
508
+ };
509
+ }, [startHours, minHour]);
510
+
511
+ // Pixel height of the part of a move that runs past midnight, or 0 when nothing
512
+ // spills. Measured against the end of the day, not `maxHour`: a narrowed window
513
+ // leaves plenty of events hanging below the last visible hour without them
514
+ // reaching the next day. Bails on the first line for a box that isn't being
515
+ // moved, which is every box but one.
516
+ const spillHeight = useDerivedValue(() => {
517
+ if (multiDay || !moving.value || lifted.value || cellHeight.value <= 0) return 0;
518
+ const liveStartHours = startHours + moveOffset.value / cellHeight.value;
519
+ const overflowHours = liveStartHours + durationHours - HOURS_PER_DAY;
520
+ if (overflowHours <= 0) return 0;
521
+ const columnDelta = dayWidth > 0 ? Math.round(moveOffsetX.value / dayWidth) : 0;
522
+ const target = Math.min(Math.max(dayIndex + columnDelta, 0), dayCount - 1);
523
+ const next = target + nextDayDirection;
524
+ // Only when that column really is the next calendar day (`hiddenDays` can
525
+ // break the run), since the tail would otherwise land off-view.
526
+ if (next < 0 || next >= dayCount || dayOrdinals[next] - dayOrdinals[target] !== 1) return 0;
527
+ return Math.min(overflowHours, maxHour - minHour) * cellHeight.value;
528
+ }, [
529
+ startHours,
530
+ durationHours,
531
+ minHour,
532
+ maxHour,
533
+ dayWidth,
534
+ dayIndex,
535
+ dayCount,
536
+ dayOrdinals,
537
+ nextDayDirection,
538
+ multiDay,
539
+ ]);
540
+
541
+ // Mount the spill preview only while a drag is actually spilling, off the UI
542
+ // thread. It's one extra view plus the consumer's event renderer, so mounting it
543
+ // on every box would inflate the grid's node count for something that is almost
544
+ // never showing. Mounting it at the grab would also re-render at the most
545
+ // jank-sensitive moment of the gesture.
546
+ const [previewMounted, setPreviewMounted] = useState(false);
547
+ useAnimatedReaction(
548
+ () => spillHeight.value > 0,
549
+ (spilling, previous) => {
550
+ // `previous` is null on the reaction's first run, which would otherwise cost
551
+ // every box on every page a thread hop to set the state it already has.
552
+ if (previous !== null && spilling !== previous) runOnJS(setPreviewMounted)(spilling);
553
+ },
387
554
  );
388
555
 
389
556
  // Clear the drag preview once the committed change re-renders this box at its
@@ -410,8 +577,8 @@ function AnimatedEventBox<T>({
410
577
 
411
578
  // Keep the latest event/handler in a ref so the gestures stay memoized but
412
579
  // never call into a stale closure.
413
- const latest = useRef({ event: positioned.event, onDragEvent, onDragStart });
414
- latest.current = { event: positioned.event, onDragEvent, onDragStart };
580
+ const latest = useRef({ event: positioned.event, eventIndex, onDragEvent, onDragStart });
581
+ latest.current = { event: positioned.event, eventIndex, onDragEvent, onDragStart };
415
582
 
416
583
  // Snap the box back to where it started (drop rejected or degenerate).
417
584
  const snapBack = useCallback(() => {
@@ -443,9 +610,14 @@ function AnimatedEventBox<T>({
443
610
  }
444
611
  // A handler may return false to reject the drop (e.g. an overlap or an
445
612
  // out-of-bounds slot); snap the box back to its original place.
446
- if (handler(event, next.start, next.end) === false) snapBack();
613
+ if (handler(event, next.start, next.end) === false) {
614
+ snapBack();
615
+ onMovePreview(null);
616
+ } else if (multiDay && deltaStartMin === deltaEndMin) {
617
+ onMovePreview((move) => (move ? { ...move, phase: "dropped" } : null));
618
+ }
447
619
  },
448
- [snapMinutes, snapBack],
620
+ [snapMinutes, snapBack, multiDay, onMovePreview],
449
621
  );
450
622
 
451
623
  // Fired on the JS thread when the gesture grabs the event, so consumers can
@@ -454,6 +626,21 @@ function AnimatedEventBox<T>({
454
626
  latest.current.onDragStart?.(latest.current.event);
455
627
  }, []);
456
628
 
629
+ const beginMovePreview = useCallback(() => {
630
+ if (multiDay) {
631
+ onMovePreview({
632
+ event: latest.current.event,
633
+ eventIndex: latest.current.eventIndex,
634
+ phase: "dragging",
635
+ dayIndex,
636
+ offsetX: moveOffsetX,
637
+ offsetY: moveOffset,
638
+ lifted,
639
+ });
640
+ }
641
+ }, [multiDay, onMovePreview, dayIndex, moveOffsetX, moveOffset, lifted]);
642
+ const endMovePreview = useCallback(() => onMovePreview(null), [onMovePreview]);
643
+
457
644
  // Edge auto-advance dwell. Dragging the event past the visible columns and
458
645
  // holding there pages the view one period and carries the event onto it: same
459
646
  // weekday, keeping whatever time the vertical drag has reached. It fires once
@@ -519,6 +706,7 @@ function AnimatedEventBox<T>({
519
706
  .enabled(canMove)
520
707
  .onStart((event) => {
521
708
  dragZ.value = DRAG_EVENT_Z;
709
+ moving.value = 1;
522
710
  edgeDir.value = 0;
523
711
  lifted.value = 0;
524
712
  // Where in the box the finger grabbed, and the live finger position, so
@@ -527,6 +715,7 @@ function AnimatedEventBox<T>({
527
715
  grabY.value = event.y;
528
716
  liveAbsX.value = event.absoluteX;
529
717
  liveAbsY.value = event.absoluteY;
718
+ runOnJS(beginMovePreview)();
530
719
  runOnJS(notifyDragStart)();
531
720
  })
532
721
  .onUpdate((event) => {
@@ -537,8 +726,16 @@ function AnimatedEventBox<T>({
537
726
  if (lifted.value && pagerLeftSV && pagerTopSV && ghostXSV && ghostYSV) {
538
727
  ghostXSV.value = event.absoluteX - grabX.value - pagerLeftSV.value;
539
728
  ghostYSV.value = event.absoluteY - grabY.value - pagerTopSV.value;
540
- } else {
541
- moveOffset.value = event.translationY;
729
+ } else if (cellHeight.value > 0) {
730
+ // Hold the start inside the day; the end is free to run past it (the
731
+ // spill preview shows where it lands). Same rule the commit applies, so
732
+ // the box never previews a position it can't be dropped in.
733
+ const { minutes: startMinutes, ownsStart } = dragStartSV.value;
734
+ const dragged = startMinutes + (event.translationY / cellHeight.value) * MINUTES_PER_HOUR;
735
+ const held = ownsStart
736
+ ? clampMoveStartMinutes(dragged, minHour, maxHour, snapMinutes)
737
+ : dragged;
738
+ moveOffset.value = ((held - startMinutes) / MINUTES_PER_HOUR) * cellHeight.value;
542
739
  moveOffsetX.value = event.translationX;
543
740
  }
544
741
  // Dragging the finger to the pager's left/right edge arms an edge dwell
@@ -560,7 +757,17 @@ function AnimatedEventBox<T>({
560
757
  // gesture ends cleanly or is cancelled as the page moves under it), so the
561
758
  // drop lands even when onEnd doesn't fire on device. Nothing to do here.
562
759
  if (lifted.value) return;
563
- const minuteDelta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
760
+ const { minutes: startMinutes, ownsStart } = dragStartSV.value;
761
+ // Snap the vertical drag, then hold the start inside the day: a move keeps
762
+ // its duration, so the end may run past midnight and continue on the next
763
+ // day, but the event still starts in the column it was dropped on. A
764
+ // segment clipped from an earlier day is exempt: it doesn't own the start,
765
+ // so holding it would stop the whole event from being dragged earlier.
766
+ const snapped = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
767
+ const minuteDelta = ownsStart
768
+ ? clampMoveStartMinutes(startMinutes + snapped, minHour, maxHour, snapMinutes) -
769
+ startMinutes
770
+ : snapped;
564
771
  // Map the horizontal drag to whole day columns, clamped so the event
565
772
  // can't leave the visible range.
566
773
  const rawDayDelta = dayWidth > 0 ? Math.round(event.translationX / dayWidth) : 0;
@@ -569,6 +776,7 @@ function AnimatedEventBox<T>({
569
776
  if (minuteDelta === 0 && dayDelta === 0) {
570
777
  moveOffset.value = 0;
571
778
  moveOffsetX.value = 0;
779
+ runOnJS(endMovePreview)();
572
780
  return;
573
781
  }
574
782
  // Hold the snapped position so the box doesn't flash back to the
@@ -583,7 +791,7 @@ function AnimatedEventBox<T>({
583
791
  const totalDelta = minuteDelta + calendarDayDelta * MINUTES_PER_DAY;
584
792
  runOnJS(commitDrag)(totalDelta, totalDelta);
585
793
  })
586
- .onFinalize(() => {
794
+ .onFinalize((_event, success) => {
587
795
  dragZ.value = 0;
588
796
  // Commit the cross-week drop here: onFinalize fires on every gesture end,
589
797
  // including the cancel RNGH reports when the source page moves under the
@@ -594,6 +802,16 @@ function AnimatedEventBox<T>({
594
802
  moveOffset.value = 0;
595
803
  moveOffsetX.value = 0;
596
804
  lifted.value = 0;
805
+ runOnJS(endMovePreview)();
806
+ }
807
+ // The preview unmounts from the `spillHeight` reaction once the commit
808
+ // lands and clears `moveOffset`; this is the safety net for a cancel,
809
+ // where `onEnd` never runs.
810
+ moving.value = 0;
811
+ if (multiDay && !success) {
812
+ moveOffset.value = 0;
813
+ moveOffsetX.value = 0;
814
+ runOnJS(endMovePreview)();
597
815
  }
598
816
  runOnJS(releaseEdge)();
599
817
  });
@@ -611,6 +829,10 @@ function AnimatedEventBox<T>({
611
829
  moveOffset,
612
830
  moveOffsetX,
613
831
  dragZ,
832
+ moving,
833
+ dragStartSV,
834
+ minHour,
835
+ maxHour,
614
836
  edgeDir,
615
837
  lifted,
616
838
  grabX,
@@ -628,6 +850,9 @@ function AnimatedEventBox<T>({
628
850
  dayCount,
629
851
  dayOrdinals,
630
852
  commitDrag,
853
+ multiDay,
854
+ beginMovePreview,
855
+ endMovePreview,
631
856
  notifyDragStart,
632
857
  onEdgeAdvance,
633
858
  armEdge,
@@ -764,11 +989,14 @@ function AnimatedEventBox<T>({
764
989
  themed: theme.containers.timeGridEvent,
765
990
  });
766
991
  const box = (
767
- <Animated.View {...eventSlot} style={[eventSlot.style, boxStyle]}>
992
+ <Animated.View
993
+ {...eventSlot}
994
+ style={[eventSlot.style, boxStyle, hiddenForMove ? { opacity: 0 } : null]}
995
+ >
768
996
  <RenderEventComponent
769
997
  event={positioned.event}
770
998
  mode={mode}
771
- boxHeight={boxHeight}
999
+ boxHeight={visibleBoxHeight}
772
1000
  continuesBefore={positioned.continuesBefore}
773
1001
  continuesAfter={positioned.continuesAfter}
774
1002
  accessibilityActions={accessibilityActions}
@@ -802,7 +1030,28 @@ function AnimatedEventBox<T>({
802
1030
  // Only wrap in the move gesture when movable; the resize grips inside `box`
803
1031
  // carry their own gestures, so a resize-only event still works.
804
1032
  if (!canMove) return box;
805
- return <GestureDetector gesture={moveGesture}>{box}</GestureDetector>;
1033
+ return (
1034
+ <>
1035
+ <GestureDetector gesture={moveGesture}>{box}</GestureDetector>
1036
+ {/* Skipped for a segment that already continues after: it owns a real
1037
+ next-day box, so a preview on top of it would just double up. */}
1038
+ {previewMounted && !positioned.continuesAfter ? (
1039
+ <MoveSpillPreview
1040
+ spillHeight={spillHeight}
1041
+ moveOffsetX={moveOffsetX}
1042
+ cellHeight={cellHeight}
1043
+ dayLeftPx={dayLeftPx}
1044
+ dayWidth={dayWidth}
1045
+ nextDayDirection={nextDayDirection}
1046
+ minHour={minHour}
1047
+ event={positioned.event}
1048
+ mode={mode}
1049
+ renderEvent={renderEvent}
1050
+ slotProps={slot("event", { themed: theme.containers.timeGridEvent })}
1051
+ />
1052
+ ) : null}
1053
+ </>
1054
+ );
806
1055
  }
807
1056
 
808
1057
  /** Replace the hour-axis label. Receives the hour (0–23) and the `ampm` flag. */
@@ -1204,6 +1453,23 @@ function TimetablePageInner<T>({
1204
1453
  );
1205
1454
 
1206
1455
  const dayLayouts = useMemo(() => days.map((day) => layoutDayEvents(events, day)), [days, events]);
1456
+ const [multiDayMove, setMultiDayMove] = useState<MultiDayMove<T> | null>(null);
1457
+ const movingEvent = multiDayMove
1458
+ ? (events.find(
1459
+ (event, index) =>
1460
+ keyExtractor(event, index) === keyExtractor(multiDayMove.event, multiDayMove.eventIndex),
1461
+ ) ?? null)
1462
+ : null;
1463
+ useEffect(() => {
1464
+ if (
1465
+ multiDayMove?.phase === "dropped" &&
1466
+ (!movingEvent ||
1467
+ movingEvent.start.getTime() !== multiDayMove.event.start.getTime() ||
1468
+ movingEvent.end.getTime() !== multiDayMove.event.end.getTime())
1469
+ ) {
1470
+ setMultiDayMove(null);
1471
+ }
1472
+ }, [multiDayMove, movingEvent]);
1207
1473
 
1208
1474
  // Map a tap on empty grid space back to the date+time it represents. Reads the
1209
1475
  // live row height on the JS thread to convert the touch Y into minutes.
@@ -1616,10 +1882,16 @@ function TimetablePageInner<T>({
1616
1882
  // flattened list of all days' boxes.
1617
1883
  key={`${dayIndex}:${keyExtractor(positioned.event, eventIndex)}`}
1618
1884
  positioned={positioned}
1885
+ eventIndex={events.indexOf(positioned.event)}
1886
+ movingEvent={movingEvent}
1887
+ onMovePreview={setMultiDayMove}
1619
1888
  cellHeight={heightSource}
1620
1889
  minHour={minHour}
1890
+ maxHour={maxHour}
1621
1891
  left={dayLeft(dayIndex) + positioned.column * columnWidth}
1622
1892
  width={columnWidth}
1893
+ dayLeftPx={dayLeft(dayIndex)}
1894
+ nextDayDirection={isRTL ? -1 : 1}
1623
1895
  dayWidth={dayWidth}
1624
1896
  dayIndex={dayIndex}
1625
1897
  dayCount={days.length}
@@ -1641,6 +1913,19 @@ function TimetablePageInner<T>({
1641
1913
  }),
1642
1914
  )}
1643
1915
 
1916
+ {multiDayMove ? (
1917
+ <MultiDayMovePreview
1918
+ move={multiDayMove}
1919
+ days={days}
1920
+ cellHeight={heightSource}
1921
+ dayWidth={dayWidth}
1922
+ hourColumnWidth={hourColumnWidth}
1923
+ minHour={minHour}
1924
+ mode={mode}
1925
+ renderEvent={renderEvent}
1926
+ />
1927
+ ) : null}
1928
+
1644
1929
  {showNowIndicator && nowDayIndex >= 0 && nowInWindow ? (
1645
1930
  <NowIndicator
1646
1931
  cellHeight={heightSource}
@@ -1961,6 +2246,7 @@ function TimeGridInner<T>({
1961
2246
  containerWidth,
1962
2247
  hourColumnWidth,
1963
2248
  minHour: clampedMinHour,
2249
+ maxHour: clampedMaxHour,
1964
2250
  snapMinutes: Math.max(1, dragStepMinutes),
1965
2251
  onDragEvent,
1966
2252
  onChangeDate,
@@ -1983,6 +2269,7 @@ function TimeGridInner<T>({
1983
2269
  containerWidth: cw,
1984
2270
  hourColumnWidth: hcw,
1985
2271
  minHour: min,
2272
+ maxHour: max,
1986
2273
  snapMinutes: snap,
1987
2274
  onDragEvent: onDrag,
1988
2275
  onChangeDate: onDate,
@@ -2003,7 +2290,9 @@ function TimeGridInner<T>({
2003
2290
  const hoursFromMin =
2004
2291
  (ghostLocalY - gridTop.value - HOUR_LABEL_TOP_INSET + scrollY.value) / cellHeight.value;
2005
2292
  const rawMinutes = (min + hoursFromMin) * MINUTES_PER_HOUR;
2006
- const minutes = Math.round(rawMinutes / snap) * snap;
2293
+ // Same rule as an in-page move: the start stays in the day it landed on,
2294
+ // while the duration is free to carry the end past midnight.
2295
+ const minutes = clampMoveStartMinutes(Math.round(rawMinutes / snap) * snap, min, max, snap);
2007
2296
  const start = new Date(days[col]);
2008
2297
  start.setHours(0, 0, 0, 0);
2009
2298
  start.setMinutes(minutes);
@@ -2130,6 +2419,7 @@ function TimeGridInner<T>({
2130
2419
  containerWidth,
2131
2420
  hourColumnWidth,
2132
2421
  minHour: clampedMinHour,
2422
+ maxHour: clampedMaxHour,
2133
2423
  snapMinutes: Math.max(1, dragStepMinutes),
2134
2424
  onDragEvent,
2135
2425
  onChangeDate,