@super-calendar/dom 2.6.0 → 2.8.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/src/TimeGrid.tsx CHANGED
@@ -13,10 +13,14 @@ import {
13
13
  } from "react";
14
14
  import {
15
15
  type BusinessHours,
16
+ type BusinessHoursBand,
16
17
  type CalendarEvent,
17
18
  type CalendarMode,
18
19
  cellRangeFromDrag,
20
+ pageStepDays,
21
+ backgroundBandsForDay,
19
22
  closedHourBands,
23
+ isBackgroundEvent,
20
24
  eventAccessibilityLabel as defaultEventAccessibilityLabel,
21
25
  type EventAccessibilityLabeler,
22
26
  eventChipLayout,
@@ -28,6 +32,8 @@ import {
28
32
  isSameCalendarDay,
29
33
  isWeekend,
30
34
  layoutDayEvents,
35
+ overlapsOtherEvents,
36
+ useNow,
31
37
  type TimeGridMode,
32
38
  titleNumberOfLines,
33
39
  type WeekdayFormat,
@@ -56,6 +62,7 @@ export type TimeGridSlot =
56
62
  | "dayColumn"
57
63
  | "gridLines"
58
64
  | "businessHours"
65
+ | "backgroundEvent"
59
66
  | "event"
60
67
  | "eventBox"
61
68
  | "nowIndicator"
@@ -64,6 +71,13 @@ export type TimeGridSlot =
64
71
  const GUTTER_WIDTH = 56;
65
72
  const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
66
73
 
74
+ // Edge auto-advance: how close to the day-columns edge (px) counts as "at the
75
+ // edge", how long to dwell there before paging, and the repeat interval while
76
+ // the pointer stays in the zone.
77
+ const EDGE_ZONE = 32;
78
+ const EDGE_DWELL_MS = 600;
79
+ const EDGE_REPEAT_MS = 600;
80
+
67
81
  // Off-screen but readable by assistive tech: gives an element an accessible name
68
82
  // without changing the visible layout.
69
83
  const VISUALLY_HIDDEN: CSSProperties = {
@@ -142,12 +156,35 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
142
156
  showWeekNumber?: boolean;
143
157
  /** Prefix for the week number, e.g. "W" → "W28". Default "W". */
144
158
  weekNumberPrefix?: string;
159
+ /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
160
+ hiddenDays?: number[];
145
161
  /** Shade the hours outside business hours; `null` shades the whole day. */
146
162
  businessHours?: BusinessHours;
163
+ /**
164
+ * Render a closed-hours band's content yourself (a label, icon, pattern).
165
+ * The grid keeps positioning the band; when set, the themed tint is dropped
166
+ * and your output fills the band instead. Decorative only: the
167
+ * band stays non-interactive and hidden from assistive tech.
168
+ */
169
+ renderBusinessHours?: (band: BusinessHoursBand) => ReactNode;
147
170
  /** Show the current-time indicator on today's column (default true). */
148
171
  showNowIndicator?: boolean;
172
+ /** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
173
+ now?: Date;
174
+ /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
175
+ timeZone?: string;
149
176
  /** Show the all-day lane above the grid (default true). */
150
177
  showAllDayEventCell?: boolean;
178
+ /** Tint Saturday/Sunday columns with the weekend background (default true). Set
179
+ * false to treat weekends like any other day. */
180
+ highlightWeekends?: boolean;
181
+ /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
182
+ eventStartEditable?: boolean;
183
+ /** Allow resizing events by default (per-event `durationEditable` overrides). Default true. */
184
+ eventDurationEditable?: boolean;
185
+ /** Allow a dragged/resized event to overlap another (default true). Set false to
186
+ * reject a drop that would collide, snapping the event back. */
187
+ eventOverlap?: boolean;
151
188
  /** date-fns locale for the column headers and time labels. */
152
189
  locale?: Locale;
153
190
  /** Theme overrides; falls back to the default light theme. */
@@ -188,6 +225,13 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
188
225
  * Return `false` to reject the drop (the event snaps back).
189
226
  */
190
227
  onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
228
+ /**
229
+ * Page the grid to a new anchor date. Supplying it alongside `onDragEvent`
230
+ * turns on edge auto-advance: dragging an event to the left/right edge and
231
+ * dwelling briefly pages the view so the event can be dropped on a day in the
232
+ * previous/next period. Controlled, like the native renderer's `onChangeDate`.
233
+ */
234
+ onChangeDate?: (date: Date) => void;
191
235
  /** Class applied to the root element. */
192
236
  className?: string;
193
237
  /** Inline styles applied to the root element. */
@@ -196,7 +240,9 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
196
240
 
197
241
  type DragState = {
198
242
  key: string;
199
- kind: "move" | "resize";
243
+ // "resize" drags the bottom edge (changes the end); "resize-start" drags the
244
+ // top edge (changes the start, end fixed).
245
+ kind: "move" | "resize" | "resize-start";
200
246
  startHours: number;
201
247
  durationHours: number;
202
248
  /** Whole day columns the box has been dragged across, clamped to the view. */
@@ -302,21 +348,8 @@ function DefaultDomEvent<T>({
302
348
  );
303
349
  }
304
350
 
305
- const NOW_TICK_MS = 60_000;
306
-
307
351
  // A `Date` that advances every minute while `enabled`, so the now-indicator
308
352
  // tracks the wall clock instead of freezing at the last render. Mirrors the
309
- // native renderer's `useNow`.
310
- function useNow(enabled: boolean): Date {
311
- const [now, setNow] = useState(() => new Date());
312
- useEffect(() => {
313
- if (!enabled) return;
314
- setNow(new Date());
315
- const id = setInterval(() => setNow(new Date()), NOW_TICK_MS);
316
- return () => clearInterval(id);
317
- }, [enabled]);
318
- return now;
319
- }
320
353
 
321
354
  /**
322
355
  * A day / week / N-day time grid rendered with plain DOM elements. Events are
@@ -349,9 +382,17 @@ export function TimeGrid<T = unknown>({
349
382
  hideHours = false,
350
383
  showWeekNumber = false,
351
384
  weekNumberPrefix = "W",
385
+ hiddenDays,
352
386
  keyboardEventNavigation = false,
353
387
  businessHours,
388
+ renderBusinessHours,
354
389
  showNowIndicator = true,
390
+ highlightWeekends = true,
391
+ eventStartEditable = true,
392
+ eventDurationEditable = true,
393
+ eventOverlap = true,
394
+ now: nowProp,
395
+ timeZone,
355
396
  showAllDayEventCell = true,
356
397
  locale,
357
398
  theme: themeOverrides,
@@ -365,6 +406,7 @@ export function TimeGrid<T = unknown>({
365
406
  onCreateEvent,
366
407
  onDragStart,
367
408
  onDragEvent,
409
+ onChangeDate,
368
410
  className,
369
411
  style,
370
412
  classNames,
@@ -387,8 +429,9 @@ export function TimeGrid<T = unknown>({
387
429
  [windowStart, windowHours],
388
430
  );
389
431
 
390
- // Ticks every minute so the red now-line follows the wall clock.
391
- const now = useNow(showNowIndicator);
432
+ // Ticks every minute so the red now-line follows the wall clock; a `now`
433
+ // override pins it, and `timeZone` shifts it to match zone-shifted events.
434
+ const now = useNow(showNowIndicator, { now: nowProp, timeZone });
392
435
 
393
436
  const [hourHeight, setHourHeight] = useState(initialHourHeight);
394
437
  useEffect(() => setHourHeight(initialHourHeight), [initialHourHeight]);
@@ -423,10 +466,51 @@ export function TimeGrid<T = unknown>({
423
466
  const cellEnabled = !!onPressCell || !!onCreateEvent;
424
467
 
425
468
  const days = useMemo(
426
- () => getViewDays(mode, date, weekStartsOn, numberOfDays),
427
- [mode, date, weekStartsOn, numberOfDays],
469
+ () => getViewDays(mode, date, weekStartsOn, numberOfDays, false, undefined, hiddenDays),
470
+ [mode, date, weekStartsOn, numberOfDays, hiddenDays],
428
471
  );
429
472
 
473
+ // Edge auto-advance. During a move drag the pointer stream is handled at the
474
+ // document level (attached in beginDrag) so it survives the day columns
475
+ // unmounting when a page change swaps `date`. The listeners read these live
476
+ // refs rather than a stale render closure; `daysRef`/`pageDepsRef` update every
477
+ // render so the drop and the next page use the current view.
478
+ const edgeAdvanceEnabled = !!onChangeDate && !!onDragEvent;
479
+ const columnsRef = useRef<HTMLDivElement>(null);
480
+ const edgeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
481
+ const edgeSide = useRef<-1 | 0 | 1>(0);
482
+ const ptr = useRef({ x: 0, y: 0 });
483
+ const pagedRef = useRef(false);
484
+ const [paged, setPaged] = useState(false);
485
+ const draggedRef = useRef<{
486
+ event: CalendarEvent<T>;
487
+ onPress: () => void;
488
+ grabX: number;
489
+ grabY: number;
490
+ w: number;
491
+ h: number;
492
+ } | null>(null);
493
+ const ghostRef = useRef<HTMLDivElement>(null);
494
+ const docHandlersRef = useRef<{
495
+ move: (e: PointerEvent) => void;
496
+ up: (e: PointerEvent) => void;
497
+ cancel: (e: PointerEvent) => void;
498
+ } | null>(null);
499
+ const daysRef = useRef(days);
500
+ daysRef.current = days;
501
+ const pageDepsRef = useRef({ date, mode, weekStartsOn, numberOfDays });
502
+ pageDepsRef.current = { date, mode, weekStartsOn, numberOfDays };
503
+ const onChangeDateRef = useRef(onChangeDate);
504
+ onChangeDateRef.current = onChangeDate;
505
+ // Wrap the handler so a drop that would overlap another event is rejected when
506
+ // `eventOverlap` is false, without the consumer wiring it in `onDragEvent`.
507
+ const onDragEventRef = useRef(onDragEvent);
508
+ onDragEventRef.current =
509
+ onDragEvent && eventOverlap === false
510
+ ? (event, start, end) =>
511
+ overlapsOtherEvents(events, event, start, end) ? false : onDragEvent(event, start, end)
512
+ : onDragEvent;
513
+
430
514
  const allDayByDay = useMemo(
431
515
  // A multi-day all-day event shows in every column it overlaps (matching the
432
516
  // native AllDayLane), not just its start day.
@@ -434,7 +518,9 @@ export function TimeGrid<T = unknown>({
434
518
  days.map((day) => {
435
519
  const dayStart = startOfDay(day);
436
520
  const dayEnd = addDays(dayStart, 1);
437
- return events.filter((e) => isAllDayEvent(e) && e.start < dayEnd && e.end > dayStart);
521
+ return events.filter(
522
+ (e) => isAllDayEvent(e) && !isBackgroundEvent(e) && e.start < dayEnd && e.end > dayStart,
523
+ );
438
524
  }),
439
525
  [days, events],
440
526
  );
@@ -492,45 +578,61 @@ export function TimeGrid<T = unknown>({
492
578
  const Renderer = renderEvent;
493
579
  const totalHeight = windowHours * hourHeight;
494
580
 
495
- const beginDrag = (
496
- e: ReactPointerEvent,
497
- event: CalendarEvent<T>,
498
- key: string,
499
- kind: "move" | "resize",
500
- startHours: number,
501
- durationHours: number,
502
- dayIndex: number,
503
- ) => {
504
- if (!onDragEvent) return;
505
- e.stopPropagation();
506
- try {
507
- (e.target as HTMLElement).setPointerCapture?.(e.pointerId);
508
- } catch {
509
- // Pointer capture is best-effort; some environments reject it.
581
+ // The day under a screen point, from the `data-date` on the column beneath the
582
+ // pointer (the ghost is pointer-transparent, so it doesn't shadow it). Guarded
583
+ // for jsdom, which has no `elementFromPoint`.
584
+ const dayAt = (x: number, y: number): Date | null => {
585
+ if (typeof document === "undefined" || typeof document.elementFromPoint !== "function") {
586
+ return null;
510
587
  }
511
- // The event box is positioned inside its day column, so the parent's width
512
- // is one day; columns are equal-width, so measuring one is enough. Resizes
513
- // never move across days, so 0 is fine there.
514
- const column = kind === "move" ? (e.currentTarget as HTMLElement).parentElement : null;
515
- const dayWidth = column ? column.getBoundingClientRect().width : 0;
516
- dragOrigin.current = {
517
- pointerX: e.clientX,
518
- pointerY: e.clientY,
519
- startHours,
520
- durationHours,
521
- dayIndex,
522
- dayWidth,
523
- };
524
- applyDrag({ key, kind, startHours, durationHours, dayDelta: 0, dayOffsetPx: 0, moved: false });
525
- onDragStart?.(event);
588
+ const el = document.elementFromPoint(x, y)?.closest?.("[data-date]");
589
+ const iso = el?.getAttribute("data-date");
590
+ return iso ? new Date(iso) : null;
526
591
  };
527
- const cancelDrag = () => {
528
- applyDrag(null);
592
+
593
+ const clearEdgeTimer = () => {
594
+ if (edgeTimer.current) {
595
+ clearTimeout(edgeTimer.current);
596
+ edgeTimer.current = null;
597
+ }
598
+ };
599
+
600
+ // Page one period toward the held edge, then re-arm so holding keeps advancing.
601
+ const fireEdge = () => {
602
+ const side = edgeSide.current;
603
+ if (side === 0) return;
604
+ const p = pageDepsRef.current;
605
+ const step = pageStepDays(p.mode, p.date, p.weekStartsOn, p.numberOfDays);
606
+ onChangeDateRef.current?.(addDays(p.date, side * step));
607
+ pagedRef.current = true;
608
+ setPaged(true);
609
+ edgeTimer.current = setTimeout(fireEdge, EDGE_REPEAT_MS);
610
+ };
611
+
612
+ const detachDocListeners = () => {
613
+ const h = docHandlersRef.current;
614
+ if (!h) return;
615
+ document.removeEventListener("pointermove", h.move);
616
+ document.removeEventListener("pointerup", h.up);
617
+ document.removeEventListener("pointercancel", h.cancel);
618
+ docHandlersRef.current = null;
619
+ };
620
+
621
+ const finishDrag = () => {
622
+ detachDocListeners();
623
+ clearEdgeTimer();
624
+ edgeSide.current = 0;
625
+ pagedRef.current = false;
626
+ setPaged(false);
627
+ draggedRef.current = null;
529
628
  dragOrigin.current = null;
629
+ applyDrag(null);
530
630
  };
531
- const moveDrag = (e: ReactPointerEvent) => {
631
+
632
+ const moveDrag = (e: PointerEvent) => {
532
633
  const d = dragRef.current;
533
634
  if (!d || !dragOrigin.current) return;
635
+ ptr.current = { x: e.clientX, y: e.clientY };
534
636
  // Read the live row height (ref, not the state closure) so a mid-drag zoom
535
637
  // keeps the math aligned with what's on screen.
536
638
  const dHours = (e.clientY - dragOrigin.current.pointerY) / hourHeightRef.current;
@@ -543,49 +645,163 @@ export function TimeGrid<T = unknown>({
543
645
  windowStart,
544
646
  Math.max(windowStart, windowEnd - d.durationHours),
545
647
  );
546
- // Map the horizontal drag to whole day columns, clamped so the event
547
- // can't leave the visible range (mirrors the native renderer).
648
+ // Map the horizontal drag to whole day columns, clamped so the in-view box
649
+ // can't leave the visible range (mirrors the native renderer). Once paged,
650
+ // the drop day comes from the hit-test instead.
548
651
  const o = dragOrigin.current;
549
652
  const rawDayDelta = o.dayWidth > 0 ? Math.round((e.clientX - o.pointerX) / o.dayWidth) : 0;
550
- const targetDay = clamp(o.dayIndex + rawDayDelta, 0, days.length - 1);
653
+ const targetDay = clamp(o.dayIndex + rawDayDelta, 0, daysRef.current.length - 1);
551
654
  const dayDelta = targetDay - o.dayIndex;
552
655
  applyDrag({ ...d, startHours, dayDelta, dayOffsetPx: dayDelta * o.dayWidth, moved: true });
553
- } else {
656
+ // Follow the pointer with the floating ghost once the origin column is gone.
657
+ const g = ghostRef.current;
658
+ const held = draggedRef.current;
659
+ if (g && held) {
660
+ g.style.transform = `translate(${e.clientX - held.grabX}px, ${e.clientY - held.grabY}px)`;
661
+ }
662
+ // Edge auto-advance: dwell near a horizontal edge to page the view. Read the
663
+ // columns rect live so a mid-drag scroll/layout shift can't stale it.
664
+ if (edgeAdvanceEnabled) {
665
+ const rect = columnsRef.current?.getBoundingClientRect();
666
+ if (rect && rect.right > rect.left) {
667
+ const left = rect.left + gutterWidth;
668
+ const side: -1 | 0 | 1 =
669
+ e.clientX <= left + EDGE_ZONE ? -1 : e.clientX >= rect.right - EDGE_ZONE ? 1 : 0;
670
+ if (side !== edgeSide.current) {
671
+ clearEdgeTimer();
672
+ edgeSide.current = side;
673
+ if (side !== 0) edgeTimer.current = setTimeout(fireEdge, EDGE_DWELL_MS);
674
+ }
675
+ }
676
+ }
677
+ } else if (d.kind === "resize") {
554
678
  const durationHours = clamp(
555
679
  snap(dragOrigin.current.durationHours + dHours),
556
680
  snapHours,
557
681
  Math.max(snapHours, windowEnd - d.startHours),
558
682
  );
559
683
  applyDrag({ ...d, durationHours, moved: true });
684
+ } else {
685
+ // Top-edge resize: move the start, keep the end fixed. Clamp the start into
686
+ // the window and never past one snap step before the end.
687
+ const o = dragOrigin.current;
688
+ const end = o.startHours + o.durationHours;
689
+ const startHours = clamp(snap(o.startHours + dHours), windowStart, end - snapHours);
690
+ applyDrag({ ...d, startHours, durationHours: end - startHours, moved: true });
560
691
  }
561
692
  };
562
- const endDrag = (
563
- e: ReactPointerEvent,
564
- day: Date,
565
- event: CalendarEvent<T>,
566
- onPress: () => void,
567
- ) => {
693
+
694
+ const endDrag = (e: PointerEvent) => {
568
695
  const d = dragRef.current;
569
696
  if (!d) return;
570
697
  try {
571
- (e.target as HTMLElement).releasePointerCapture?.(e.pointerId);
698
+ (e.target as HTMLElement)?.releasePointerCapture?.(e.pointerId);
572
699
  } catch {
573
700
  // Best-effort release; ignore if the capture was never granted.
574
701
  }
702
+ const held = draggedRef.current;
575
703
  if (!d.moved) {
576
- applyDrag(null);
577
- onPress();
704
+ finishDrag();
705
+ held?.onPress();
578
706
  return;
579
707
  }
580
- // The horizontal delta lands the event on another visible day column.
581
- const base = startOfDay(addDays(day, d.dayDelta));
582
- const start = addMinutes(base, Math.round(d.startHours * 60));
583
- const end = addMinutes(base, Math.round((d.startHours + d.durationHours) * 60));
584
- onDragEvent?.(event, start, end);
585
- applyDrag(null);
586
- dragOrigin.current = null;
708
+ const originIndex = dragOrigin.current?.dayIndex ?? 0;
709
+ let base: Date | null = null;
710
+ if (d.kind === "move") {
711
+ if (pagedRef.current) {
712
+ // The origin column has scrolled off with the page change, so the day
713
+ // under the pointer is authoritative; dropping off the grid snaps back.
714
+ const day = dayAt(e.clientX, e.clientY);
715
+ base = day ? startOfDay(day) : null;
716
+ } else {
717
+ // In view: resolve from the days array (correct under hiddenDays), as
718
+ // before. `dayDelta` is clamped to the visible range at drag time.
719
+ base = startOfDay(
720
+ daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex],
721
+ );
722
+ }
723
+ } else {
724
+ base = startOfDay(daysRef.current[originIndex] ?? daysRef.current[0]);
725
+ }
726
+ if (base && held) {
727
+ const start = addMinutes(base, Math.round(d.startHours * 60));
728
+ const end = addMinutes(base, Math.round((d.startHours + d.durationHours) * 60));
729
+ onDragEventRef.current?.(held.event, start, end);
730
+ }
731
+ finishDrag();
732
+ };
733
+
734
+ const cancelDrag = () => {
735
+ finishDrag();
736
+ };
737
+
738
+ const beginDrag = (
739
+ e: ReactPointerEvent,
740
+ event: CalendarEvent<T>,
741
+ key: string,
742
+ kind: "move" | "resize" | "resize-start",
743
+ startHours: number,
744
+ durationHours: number,
745
+ dayIndex: number,
746
+ onPress?: () => void,
747
+ ) => {
748
+ if (!onDragEvent) return;
749
+ e.stopPropagation();
750
+ try {
751
+ (e.target as HTMLElement).setPointerCapture?.(e.pointerId);
752
+ } catch {
753
+ // Pointer capture is best-effort; some environments reject it.
754
+ }
755
+ // The event box sits inside its day column, so the parent's width is one day;
756
+ // columns are equal-width, so measuring one is enough. Resizes never move
757
+ // across days, so 0 is fine there.
758
+ const boxEl = e.currentTarget as HTMLElement;
759
+ const column = kind === "move" ? boxEl.parentElement : null;
760
+ const dayWidth = column ? column.getBoundingClientRect().width : 0;
761
+ const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
762
+ dragOrigin.current = {
763
+ pointerX: e.clientX,
764
+ pointerY: e.clientY,
765
+ startHours,
766
+ durationHours,
767
+ dayIndex,
768
+ dayWidth,
769
+ };
770
+ draggedRef.current = {
771
+ event,
772
+ onPress: onPress ?? (() => {}),
773
+ grabX: boxRect ? e.clientX - boxRect.left : 0,
774
+ grabY: boxRect ? e.clientY - boxRect.top : 0,
775
+ w: boxRect ? boxRect.width : 0,
776
+ h: boxRect ? boxRect.height : 0,
777
+ };
778
+ ptr.current = { x: e.clientX, y: e.clientY };
779
+ edgeSide.current = 0;
780
+ pagedRef.current = false;
781
+ setPaged(false);
782
+ clearEdgeTimer();
783
+ applyDrag({ key, kind, startHours, durationHours, dayDelta: 0, dayOffsetPx: 0, moved: false });
784
+ onDragStart?.(event);
785
+ // Transport the rest of the drag at the document level so it survives the day
786
+ // columns unmounting on a page change (the dragged box's own node disappears).
787
+ // Detach any prior set first so a second beginDrag can't leak listeners.
788
+ detachDocListeners();
789
+ const handlers = { move: moveDrag, up: endDrag, cancel: cancelDrag };
790
+ docHandlersRef.current = handlers;
791
+ document.addEventListener("pointermove", handlers.move);
792
+ document.addEventListener("pointerup", handlers.up);
793
+ document.addEventListener("pointercancel", handlers.cancel);
587
794
  };
588
795
 
796
+ // Remove any lingering document listeners / dwell timer if we unmount mid-drag.
797
+ useEffect(
798
+ () => () => {
799
+ detachDocListeners();
800
+ clearEdgeTimer();
801
+ },
802
+ [],
803
+ );
804
+
589
805
  const pxFromTop = (el: HTMLElement, clientY: number) => clientY - el.getBoundingClientRect().top;
590
806
  const beginCreate = (e: ReactPointerEvent, dayIndex: number) => {
591
807
  // Mouse / pen only: on touch the column must stay free to scroll the grid.
@@ -731,6 +947,20 @@ export function TimeGrid<T = unknown>({
731
947
  () => days.map((day) => closedHourBands(day, businessHours, windowStart, windowEnd)),
732
948
  [days, businessHours, windowStart, windowEnd],
733
949
  );
950
+ // `display: "background"` events, sliced per day and clipped to the window.
951
+ const backgroundByDay = useMemo(
952
+ () =>
953
+ days.map((day) =>
954
+ backgroundBandsForDay(events, day)
955
+ .map((b) => ({
956
+ ...b,
957
+ startHours: Math.max(b.startHours, windowStart),
958
+ endHours: Math.min(b.endHours, windowEnd),
959
+ }))
960
+ .filter((b) => b.endHours > b.startHours),
961
+ ),
962
+ [days, events, windowStart, windowEnd],
963
+ );
734
964
  const gridLines = useMemo(() => {
735
965
  const hourLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight}px)`;
736
966
  if (timeslots <= 1) return hourLines;
@@ -961,7 +1191,10 @@ export function TimeGrid<T = unknown>({
961
1191
  touchAction: zoomable ? "pan-y" : "auto",
962
1192
  }}
963
1193
  >
964
- <div style={{ display: "flex", height: totalHeight, position: "relative" }}>
1194
+ <div
1195
+ ref={columnsRef}
1196
+ style={{ display: "flex", height: totalHeight, position: "relative" }}
1197
+ >
965
1198
  {/* Hour gutter (hidden when hideHours; the grid lines stay). */}
966
1199
  {hideHours ? null : (
967
1200
  <div
@@ -1004,6 +1237,8 @@ export function TimeGrid<T = unknown>({
1004
1237
  return (
1005
1238
  <div
1006
1239
  key={day.toISOString()}
1240
+ // Identifies the drop day for a cross-page drag hit-test.
1241
+ data-date={day.toISOString()}
1007
1242
  // Empty columns are a pointer-only create surface: drag to sweep
1008
1243
  // out an event. They are deliberately not tab stops, so keyboard
1009
1244
  // focus moves through events only, not every empty day.
@@ -1018,7 +1253,9 @@ export function TimeGrid<T = unknown>({
1018
1253
  // tint sits behind the grid lines, business-hours shade and events.
1019
1254
  themed: {
1020
1255
  borderLeft: `1px solid ${theme.gridLine}`,
1021
- ...(isWeekend(day) ? { background: theme.weekendBackground } : null),
1256
+ ...(highlightWeekends && isWeekend(day)
1257
+ ? { background: theme.weekendBackground }
1258
+ : null),
1022
1259
  },
1023
1260
  })}
1024
1261
  >
@@ -1037,7 +1274,31 @@ export function TimeGrid<T = unknown>({
1037
1274
  pointerEvents: "none",
1038
1275
  zIndex: 0,
1039
1276
  },
1040
- themed: { background: theme.outsideHoursBackground },
1277
+ themed: renderBusinessHours
1278
+ ? undefined
1279
+ : { background: theme.outsideHoursBackground },
1280
+ })}
1281
+ >
1282
+ {renderBusinessHours?.({ date: day, start: b.start, end: b.end })}
1283
+ </div>
1284
+ ))}
1285
+ {/* Background events: shaded, non-interactive time ranges. */}
1286
+ {backgroundByDay[dayIndex].map((b, bandIndex) => (
1287
+ <div
1288
+ key={`bg-${bandIndex}`}
1289
+ aria-hidden
1290
+ title={b.event.title}
1291
+ {...slot("backgroundEvent", {
1292
+ base: {
1293
+ position: "absolute",
1294
+ left: 0,
1295
+ right: 0,
1296
+ top: (b.startHours - windowStart) * hourHeight,
1297
+ height: (b.endHours - b.startHours) * hourHeight,
1298
+ pointerEvents: "none",
1299
+ zIndex: 0,
1300
+ },
1301
+ themed: { background: theme.backgroundEvent },
1041
1302
  })}
1042
1303
  />
1043
1304
  ))}
@@ -1051,7 +1312,10 @@ export function TimeGrid<T = unknown>({
1051
1312
  />
1052
1313
  {positioned.map((pe, idx) => {
1053
1314
  const key = `${dayIndex}:${idx}`;
1054
- const active = drag?.key === key ? drag : null;
1315
+ // Not while paged: after a page change the origin box is gone and
1316
+ // the ghost stands in, so a same-slot event on the new page (e.g. a
1317
+ // recurring one) must not also render lifted.
1318
+ const active = !paged && drag?.key === key ? drag : null;
1055
1319
  const startHours = active ? active.startHours : pe.startHours;
1056
1320
  const durationHours = active ? active.durationHours : pe.durationHours;
1057
1321
  // Drop events that fall entirely outside the visible window; those
@@ -1075,7 +1339,14 @@ export function TimeGrid<T = unknown>({
1075
1339
  ampm,
1076
1340
  onPress,
1077
1341
  };
1078
- const draggable = !!onDragEvent;
1342
+ // `draggable: false` locks a single event: it keeps its normal
1343
+ // look and still responds to clicks, it just can't be dragged.
1344
+ // `startEditable`/`durationEditable` (per-event, falling back to
1345
+ // the grid props) split whether it can be moved vs resized.
1346
+ const editable = !!onDragEvent && pe.event.draggable !== false;
1347
+ const canMove = editable && (pe.event.startEditable ?? eventStartEditable);
1348
+ const canResize =
1349
+ editable && (pe.event.durationEditable ?? eventDurationEditable);
1079
1350
  return (
1080
1351
  <div
1081
1352
  key={idx}
@@ -1103,8 +1374,11 @@ export function TimeGrid<T = unknown>({
1103
1374
  }
1104
1375
  if (keyboardEventNavigation) onEventKeyDown(key, e);
1105
1376
  }}
1377
+ // Pointer move/up/cancel are handled at the document level
1378
+ // (attached in beginDrag) so the drag survives the columns
1379
+ // remounting on a page change.
1106
1380
  onPointerDown={
1107
- draggable
1381
+ canMove
1108
1382
  ? (e) =>
1109
1383
  beginDrag(
1110
1384
  e,
@@ -1114,15 +1388,11 @@ export function TimeGrid<T = unknown>({
1114
1388
  pe.startHours,
1115
1389
  pe.durationHours,
1116
1390
  dayIndex,
1391
+ onPress,
1117
1392
  )
1118
1393
  : undefined
1119
1394
  }
1120
- onPointerMove={draggable ? moveDrag : undefined}
1121
- onPointerUp={
1122
- draggable ? (e) => endDrag(e, day, pe.event, onPress) : undefined
1123
- }
1124
- onPointerCancel={draggable ? cancelDrag : undefined}
1125
- onClick={draggable ? undefined : onPress}
1395
+ onClick={canMove ? undefined : onPress}
1126
1396
  {...dataState({ "data-dragging": !!active })}
1127
1397
  {...slot("event", {
1128
1398
  base: {
@@ -1135,8 +1405,8 @@ export function TimeGrid<T = unknown>({
1135
1405
  height: boxHeight,
1136
1406
  left: `calc(${pe.column * widthPct}% + 1px)`,
1137
1407
  width: `calc(${widthPct}% - 2px)`,
1138
- cursor: draggable ? "grab" : "pointer",
1139
- touchAction: draggable ? "none" : "auto",
1408
+ cursor: canMove ? "grab" : "pointer",
1409
+ touchAction: canMove ? "none" : "auto",
1140
1410
  zIndex: active ? 3 : 1,
1141
1411
  opacity: active ? 0.85 : 1,
1142
1412
  // Snap the dragged box over the target day column so the
@@ -1152,7 +1422,32 @@ export function TimeGrid<T = unknown>({
1152
1422
  ) : (
1153
1423
  <DefaultDomEvent {...args} theme={theme} boxProps={slot("eventBox")} />
1154
1424
  )}
1155
- {draggable ? (
1425
+ {canResize && !pe.continuesBefore ? (
1426
+ <div
1427
+ onPointerDown={(e) => {
1428
+ e.stopPropagation();
1429
+ beginDrag(
1430
+ e,
1431
+ pe.event,
1432
+ key,
1433
+ "resize-start",
1434
+ pe.startHours,
1435
+ pe.durationHours,
1436
+ dayIndex,
1437
+ );
1438
+ }}
1439
+ style={{
1440
+ position: "absolute",
1441
+ left: 0,
1442
+ right: 0,
1443
+ top: 0,
1444
+ height: 8,
1445
+ cursor: "ns-resize",
1446
+ touchAction: "none",
1447
+ }}
1448
+ />
1449
+ ) : null}
1450
+ {canResize ? (
1156
1451
  <div
1157
1452
  onPointerDown={(e) => {
1158
1453
  e.stopPropagation();
@@ -1235,6 +1530,51 @@ export function TimeGrid<T = unknown>({
1235
1530
  })}
1236
1531
  </div>
1237
1532
  </div>
1533
+ {/* Floating drag ghost: shown only after a page change, when the dragged
1534
+ event's own column has unmounted. Positioned imperatively per pointer
1535
+ move (see moveDrag) and pointer-transparent so the drop hit-test reads
1536
+ the column beneath it. */}
1537
+ {paged && draggedRef.current ? (
1538
+ <div
1539
+ ref={ghostRef}
1540
+ aria-hidden
1541
+ style={{
1542
+ position: "fixed",
1543
+ left: 0,
1544
+ top: 0,
1545
+ width: draggedRef.current.w,
1546
+ height: draggedRef.current.h,
1547
+ transform: `translate(${ptr.current.x - draggedRef.current.grabX}px, ${
1548
+ ptr.current.y - draggedRef.current.grabY
1549
+ }px)`,
1550
+ pointerEvents: "none",
1551
+ zIndex: 1000,
1552
+ opacity: 0.85,
1553
+ }}
1554
+ >
1555
+ {Renderer ? (
1556
+ <Renderer
1557
+ event={draggedRef.current.event}
1558
+ mode={mode}
1559
+ isAllDay={false}
1560
+ boxHeight={draggedRef.current.h}
1561
+ ampm={ampm}
1562
+ onPress={() => {}}
1563
+ />
1564
+ ) : (
1565
+ <DefaultDomEvent
1566
+ event={draggedRef.current.event}
1567
+ mode={mode}
1568
+ isAllDay={false}
1569
+ boxHeight={draggedRef.current.h}
1570
+ ampm={ampm}
1571
+ onPress={() => {}}
1572
+ theme={theme}
1573
+ boxProps={slot("eventBox")}
1574
+ />
1575
+ )}
1576
+ </div>
1577
+ ) : null}
1238
1578
  </div>
1239
1579
  );
1240
1580
  }