@super-calendar/dom 2.17.0 → 2.19.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/MonthView.tsx CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  type KeyboardEvent as ReactKeyboardEvent,
14
14
  type ReactElement,
15
15
  type PointerEvent as ReactPointerEvent,
16
+ useCallback,
16
17
  useEffect,
17
18
  useMemo,
18
19
  useRef,
@@ -22,7 +23,9 @@ import {
22
23
  bandRounding,
23
24
  buildMonthGrid,
24
25
  buildMultiWeekGrid,
26
+ nowInTimeZone,
25
27
  type CalendarEvent,
28
+ type CreateGhostArgs,
26
29
  compareDayEvents,
27
30
  dayBadgeKind,
28
31
  type DateRange,
@@ -31,22 +34,25 @@ import {
31
34
  groupEventsByDay,
32
35
  isBackgroundEvent,
33
36
  isAllDayEvent,
37
+ keepMonthDraftVisible,
34
38
  layoutMonthWeek,
35
39
  monthCreateRange,
36
40
  monthDropBounds,
41
+ monthExtraLaneColumns,
37
42
  type MonthGridWeekday,
43
+ monthVisibleBars,
44
+ withDraftEventDays,
38
45
  type MultiWeekGridDay,
39
46
  overlapsOtherEvents,
40
47
  rangeBandKind,
41
48
  type WeekdayFormat,
42
49
  type WeekStartsOn,
43
- } from "@super-calendar/core";
44
- import {
45
50
  type CalendarLabels,
46
51
  dayAccessibilityLabel,
47
52
  resolveCalendarLabels,
48
53
  } from "@super-calendar/core";
49
54
  import { holdDateDrag } from "./touch";
55
+ import { InertDiv } from "./InertDiv";
50
56
  import { createSlots, dataState, type SlotDefault, type SlotStyleProps } from "./slots";
51
57
  import { type DomCalendarTheme, mergeDomTheme } from "./theme";
52
58
 
@@ -64,12 +70,16 @@ export type MonthViewSlot =
64
70
  | "dayBadge"
65
71
  | "rangeBand"
66
72
  | "events"
73
+ | "createGhost"
67
74
  | "chipButton"
68
75
  | "chip"
69
76
  | "more"
70
77
  | "morePopover";
71
78
 
72
79
  // Stable empty layout for rows with no events (avoids a fresh object per render).
80
+ // Whether a pointer press began on an event chip inside a day cell.
81
+ const pressedEvent = (event: Event) =>
82
+ event.target instanceof Element && event.target.closest('[data-slot="chipButton"]') !== null;
73
83
  const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
74
84
 
75
85
  // Chip metrics for the events layout (when `events` is provided).
@@ -79,6 +89,10 @@ const CHIP_GAP = 2;
79
89
  const CELL_PAD = 4;
80
90
  // Opacity of an event chip while it is being dragged to another day.
81
91
  const DRAGGED_CHIP_OPACITY = 0.4;
92
+ // How far a press travels before it becomes a drag. Until then the chips stay
93
+ // hit-testable, so a click still reaches the chip it pressed.
94
+ const DRAG_SLOP_PX = 4;
95
+ const TOUCH_DRAG_SLOP_PX = 8;
82
96
 
83
97
  // A day as the shared rows render it. Month days carry `isCurrentMonth`;
84
98
  // multi-week days omit it because every one of them is inside the period.
@@ -110,6 +124,11 @@ type MonthDrag<T> = (
110
124
  ) & {
111
125
  // The rows the drag began in, so a drag never commits into a different window.
112
126
  windowKey: string;
127
+ pointerId: number;
128
+ // Set once the pointer travels past the drag slop (or a touch hold fires).
129
+ // Chips stop taking pointer input only then, so a plain click is not
130
+ // retargeted to the day cell beneath.
131
+ armed: boolean;
113
132
  };
114
133
 
115
134
  /** Props for {@link MonthView}. */
@@ -175,6 +194,13 @@ export interface MonthViewProps<T = unknown>
175
194
  showWeekdays?: boolean;
176
195
  /** date-fns locale for the title and weekday labels. */
177
196
  locale?: Locale;
197
+ /**
198
+ * The instant whose calendar day is highlighted as today. Defaults to the
199
+ * device clock, and is read in `timeZone` when one is set.
200
+ */
201
+ now?: Date;
202
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
203
+ timeZone?: string;
178
204
  /** Theme overrides; falls back to the default light theme. */
179
205
  theme?: Partial<DomCalendarTheme>;
180
206
  /** Fired when a selectable day is clicked. */
@@ -192,6 +218,12 @@ export interface MonthViewProps<T = unknown>
192
218
  * carry `data-creating` for styling.
193
219
  */
194
220
  onCreateEvent?: (start: Date, end: Date) => void;
221
+ /**
222
+ * Custom content for a drag-to-create preview, once per covered week row.
223
+ * Receives the full all-day range with an exclusive end. Requires onCreateEvent.
224
+ * Content is clipped, noninteractive, and hidden from assistive technology.
225
+ */
226
+ renderCreateGhost?: ComponentType<CreateGhostArgs>;
195
227
  /**
196
228
  * Reports the day span of a create sweep **as it happens**, as the ordered
197
229
  * inclusive `[start, end]` days (both at midnight), so a selection highlight can
@@ -571,6 +603,8 @@ export function DateRows<T = unknown>({
571
603
  showTitle = true,
572
604
  showWeekdays = true,
573
605
  locale,
606
+ now,
607
+ timeZone,
574
608
  theme: themeOverrides,
575
609
  minDate,
576
610
  maxDate,
@@ -578,6 +612,7 @@ export function DateRows<T = unknown>({
578
612
  onPressDay,
579
613
  onPressCell,
580
614
  onCreateEvent,
615
+ renderCreateGhost: RenderCreateGhost,
581
616
  onSelectDrag,
582
617
  onDragEvent,
583
618
  onDragStart,
@@ -603,13 +638,16 @@ export function DateRows<T = unknown>({
603
638
  // Calendar layout (date in the corner + event chips) is on whenever `events`
604
639
  // is provided; otherwise the compact picker badge layout is used. Multi-week
605
640
  // rows always use the calendar layout.
606
- const eventsMode = events !== undefined || multiWeek;
641
+ const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
642
+ const eventsMode = events !== undefined || multiWeek || createContentEnabled;
607
643
  // The day cells form a roving tab stop (arrow keys + Enter) in the picker
608
644
  // always, and in events mode only when the consumer opts in. Otherwise events
609
645
  // mode tabs through the event chips alone.
610
646
  const dayRoving = !eventsMode || keyboardDayNavigation;
611
647
  // Use the list-built index when provided (MonthList), else build it for this
612
648
  // month. Either way lookups use startOfDay(date).toISOString().
649
+ // The day, not the instant, so the grid is rebuilt once a day.
650
+ const todayKey = startOfDay(nowInTimeZone(now, timeZone)).getTime();
613
651
  const eventsByDay = useMemo(() => {
614
652
  // The list (MonthList) sorts before passing its index in; only sort here when
615
653
  // building our own, so each day reads all-day events first, then by start.
@@ -679,6 +717,7 @@ export function DateRows<T = unknown>({
679
717
  maxDate,
680
718
  isDateDisabled,
681
719
  locale,
720
+ today: new Date(todayKey),
682
721
  };
683
722
  if (numberOfWeeks === undefined) {
684
723
  return {
@@ -706,6 +745,7 @@ export function DateRows<T = unknown>({
706
745
  maxDate,
707
746
  isDateDisabled,
708
747
  locale,
748
+ todayKey,
709
749
  ]);
710
750
 
711
751
  // Lay out each week row's spanning bars once per data change, not per render, so
@@ -833,8 +873,60 @@ export function DateRows<T = unknown>({
833
873
  // all-day span, or press an event chip and drop it on another day. Both are
834
874
  // released on a window pointerup, so letting go anywhere still commits.
835
875
  const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
836
- const dragRef = useRef(drag);
837
- dragRef.current = drag;
876
+ const dragRef = useRef<MonthDrag<T> | null>(null);
877
+ // Release can arrive before React renders the last pointer movement.
878
+ const applyDrag = useCallback((next: MonthDrag<T> | null) => {
879
+ dragRef.current = next;
880
+ setDrag(next);
881
+ }, []);
882
+ const createStart = drag?.kind === "create" ? drag.anchor : null;
883
+ const createEnd = drag?.kind === "create" ? drag.hover : null;
884
+ const createRange = useMemo(
885
+ () =>
886
+ createContentEnabled && createStart !== null && createEnd !== null
887
+ ? monthCreateRange(new Date(createStart), new Date(createEnd))
888
+ : null,
889
+ [createContentEnabled, createStart, createEnd],
890
+ );
891
+ // Lanes a week row shows: all of them, or one fewer than the cap plus "+more".
892
+ const visibleLanesFor = useCallback(
893
+ (laneCount: number) =>
894
+ laneCount > maxVisibleEventCount ? Math.max(maxVisibleEventCount - 1, 1) : laneCount,
895
+ [maxVisibleEventCount],
896
+ );
897
+ // While a create sweep draws its content, lay the rows it covers out with the
898
+ // draft as an all-day event, so it takes the lane the created event will land on
899
+ // and the other bars move aside the same way.
900
+ const draftEvent = useMemo(
901
+ () =>
902
+ createRange
903
+ ? ({
904
+ title: "",
905
+ start: createRange.start,
906
+ end: createRange.end,
907
+ allDay: true,
908
+ } as CalendarEvent<T>)
909
+ : null,
910
+ [createRange],
911
+ );
912
+ const rowLayouts = useMemo(() => {
913
+ if (!draftEvent) return weekLayouts;
914
+ const days = withDraftEventDays(eventsByDay, draftEvent);
915
+ return weeks.map((week, index) => {
916
+ const base = weekLayouts[index] ?? EMPTY_LAYOUT;
917
+ if (!week.days.some((d) => d.date >= draftEvent.start && d.date < draftEvent.end)) {
918
+ return base;
919
+ }
920
+ const placed = layoutMonthWeek(
921
+ week.days.map((d) => d.date),
922
+ collectRowEvents(week, days),
923
+ );
924
+ return keepMonthDraftVisible(placed, base, draftEvent, {
925
+ visibleLanes: visibleLanesFor,
926
+ extraLaneFits: (visibleLanes) => visibleLanes < maxVisibleEventCount,
927
+ });
928
+ });
929
+ }, [draftEvent, weekLayouts, eventsByDay, weeks, visibleLanesFor, maxVisibleEventCount]);
838
930
  const movedRef = useRef(false);
839
931
  // Set when a drag commits, so the click the browser fires next is swallowed (it
840
932
  // must not also open the day, or the event the drag landed on). A drag that ends
@@ -842,8 +934,9 @@ export function DateRows<T = unknown>({
842
934
  // common ancestor instead, where no handler consumes the guard — so every press
843
935
  // clears it first, keeping it scoped to the one interaction that set it.
844
936
  const suppressClickRef = useRef(false);
845
- const consumeSuppressedClick = () => {
846
- if (!suppressClickRef.current) return false;
937
+ // Keyboard and assistive-technology clicks have detail 0 and never trail a drag.
938
+ const consumeSuppressedClick = (detail: number) => {
939
+ if (detail === 0 || !suppressClickRef.current) return false;
847
940
  suppressClickRef.current = false;
848
941
  return true;
849
942
  };
@@ -854,30 +947,36 @@ export function DateRows<T = unknown>({
854
947
  !event.disabled &&
855
948
  event.draggable !== false &&
856
949
  (event.startEditable ?? eventStartEditable);
950
+ // Where the current press began and how far it may travel before it drags.
951
+ const pressOrigin = useRef({ x: 0, y: 0, slop: DRAG_SLOP_PX });
857
952
  // A fresh press starts a new interaction, so any guard left over from the
858
953
  // previous one is stale.
859
954
  const beginPress = () => {
860
955
  suppressClickRef.current = false;
861
956
  movedRef.current = false;
862
957
  };
863
- const beginCreate = (day: Date) => {
958
+ const beginCreate = (day: Date, pointerId: number, armed: boolean) => {
864
959
  if (!onCreateEvent && !onSelectDrag) return;
865
960
  const t = startOfDay(day).getTime();
866
- setDrag({ kind: "create", anchor: t, hover: t, windowKey });
961
+ applyDrag({ kind: "create", anchor: t, hover: t, windowKey, pointerId, armed });
867
962
  };
868
- const beginMove = (event: CalendarEvent<T>, day: Date) => {
963
+ const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number, armed: boolean) => {
869
964
  if (!canMove(event)) return;
870
965
  const t = startOfDay(day).getTime();
871
- setDrag({ kind: "move", event, from: t, to: t, windowKey });
966
+ applyDrag({ kind: "move", event, from: t, to: t, windowKey, pointerId, armed });
872
967
  onDragStart?.(event);
873
968
  };
874
- const extendDrag = (day: Date) => {
969
+ const extendDrag = (day: Date, pointerId: number) => {
875
970
  const current = dragRef.current;
876
- if (!current) return;
971
+ if (!current || current.pointerId !== pointerId) return;
877
972
  const t = startOfDay(day).getTime();
878
973
  if (t === (current.kind === "create" ? current.hover : current.to)) return;
879
974
  movedRef.current = true;
880
- setDrag(current.kind === "create" ? { ...current, hover: t } : { ...current, to: t });
975
+ applyDrag(
976
+ current.kind === "create"
977
+ ? { ...current, hover: t, armed: true }
978
+ : { ...current, to: t, armed: true },
979
+ );
881
980
  // A sweep reports its span live, so a selection can track the drag; a move
882
981
  // has nothing to report until it is dropped.
883
982
  if (current.kind === "create") {
@@ -900,12 +999,21 @@ export function DateRows<T = unknown>({
900
999
  ) => {
901
1000
  if (event.button !== 0 || event.isPrimary === false || heldTouch.current) return;
902
1001
  beginPress();
903
- const start = () => {
904
- if (moving) touchHandlers.current.beginMove(moving, day);
905
- else touchHandlers.current.beginCreate(day);
1002
+ // A press on an event that can't move starts a fresh interaction but no
1003
+ // sweep: a sweep starts from a day, and its preview would move the row
1004
+ // under the click.
1005
+ if (!moving && pressedEvent(event.nativeEvent)) return;
1006
+ pressOrigin.current = {
1007
+ x: event.clientX,
1008
+ y: event.clientY,
1009
+ slop: event.pointerType === "touch" ? TOUCH_DRAG_SLOP_PX : DRAG_SLOP_PX,
1010
+ };
1011
+ const start = (armed: boolean) => {
1012
+ if (moving) touchHandlers.current.beginMove(moving, day, event.pointerId, armed);
1013
+ else touchHandlers.current.beginCreate(day, event.pointerId, armed);
906
1014
  };
907
1015
  if (!multiWeek || !event.pointerType || event.pointerType === "mouse") {
908
- start();
1016
+ start(false);
909
1017
  return;
910
1018
  }
911
1019
  heldOrigin.current = { day, event: moving };
@@ -917,18 +1025,18 @@ export function DateRows<T = unknown>({
917
1025
  clientX: event.clientX,
918
1026
  clientY: event.clientY,
919
1027
  },
920
- start,
1028
+ // The hold itself is the deliberate gesture, so a held drag starts armed.
1029
+ () => start(true),
921
1030
  (x, y) => {
922
1031
  const element = gridRef.current?.ownerDocument
923
1032
  .elementFromPoint(x, y)
924
1033
  ?.closest<HTMLElement>("[data-day]");
925
1034
  if (!element || !gridRef.current?.contains(element)) return;
926
1035
  const day = touchHandlers.current.dayLookup.get(element.dataset.day ?? "");
927
- if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date);
1036
+ if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date, event.pointerId);
928
1037
  },
929
1038
  () => {
930
- dragRef.current = null;
931
- setDrag(null);
1039
+ applyDrag(null);
932
1040
  movedRef.current = false;
933
1041
  },
934
1042
  () => {
@@ -967,15 +1075,23 @@ export function DateRows<T = unknown>({
967
1075
  }
968
1076
  });
969
1077
  const isDragging = drag !== null;
1078
+ const dragArmed = drag?.armed === true;
970
1079
  // Whether any month drag is wired up at all, so the cells only take over touch
971
1080
  // scrolling and pointer tracking when one of the handlers can actually fire.
972
1081
  const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
973
1082
  useEffect(() => {
974
1083
  if (!isDragging) return;
975
- const finish = () => {
1084
+ const finish = (event: PointerEvent) => {
976
1085
  const current = dragRef.current;
977
- setDrag(null);
978
- if (!current || !movedRef.current) return;
1086
+ if (!current || current.pointerId !== event.pointerId) return;
1087
+ applyDrag(null);
1088
+ if (!movedRef.current) {
1089
+ // An armed move that returns to its day is released over the day cell,
1090
+ // because the chip ignored pointer input mid drag. The click that
1091
+ // follows belongs to the abandoned drag, not to the day.
1092
+ if (current.kind === "move" && current.armed) suppressClickRef.current = true;
1093
+ return;
1094
+ }
979
1095
  // Multi-week rows drop a drag whose window was replaced before release.
980
1096
  if (multiWeek && current.windowKey !== windowKeyRef.current) return;
981
1097
  suppressClickRef.current = true;
@@ -996,9 +1112,38 @@ export function DateRows<T = unknown>({
996
1112
  }
997
1113
  onDragEvent?.(current.event, next.start, next.end);
998
1114
  };
1115
+ const clear = () => {
1116
+ heldTouch.current?.();
1117
+ applyDrag(null);
1118
+ movedRef.current = false;
1119
+ suppressClickRef.current = true;
1120
+ };
1121
+ const cancel = (event: PointerEvent) => {
1122
+ if (dragRef.current?.pointerId === event.pointerId) clear();
1123
+ };
1124
+ const arm = (event: PointerEvent) => {
1125
+ const current = dragRef.current;
1126
+ if (!current || current.armed || current.pointerId !== event.pointerId) return;
1127
+ const origin = pressOrigin.current;
1128
+ if (Math.hypot(event.clientX - origin.x, event.clientY - origin.y) <= origin.slop) return;
1129
+ applyDrag({ ...current, armed: true });
1130
+ };
1131
+ const keyDown = (event: KeyboardEvent) => {
1132
+ if (event.key !== "Escape") return;
1133
+ event.preventDefault();
1134
+ clear();
1135
+ };
1136
+ window.addEventListener("pointermove", arm);
999
1137
  window.addEventListener("pointerup", finish);
1000
- return () => window.removeEventListener("pointerup", finish);
1001
- }, [isDragging, multiWeek, onCreateEvent, onDragEvent, eventOverlap, events]);
1138
+ window.addEventListener("pointercancel", cancel);
1139
+ window.addEventListener("keydown", keyDown);
1140
+ return () => {
1141
+ window.removeEventListener("pointermove", arm);
1142
+ window.removeEventListener("pointerup", finish);
1143
+ window.removeEventListener("pointercancel", cancel);
1144
+ window.removeEventListener("keydown", keyDown);
1145
+ };
1146
+ }, [isDragging, multiWeek, onCreateEvent, onDragEvent, eventOverlap, events, applyDrag]);
1002
1147
  // Replacing the multi-week window cancels a drag and closes the overflow
1003
1148
  // popover, so neither acts on days that are no longer shown.
1004
1149
  const transientWindow = useRef(windowKey);
@@ -1006,9 +1151,9 @@ export function DateRows<T = unknown>({
1006
1151
  if (transientWindow.current === windowKey) return;
1007
1152
  transientWindow.current = windowKey;
1008
1153
  if (!multiWeek) return;
1009
- setDrag(null);
1154
+ applyDrag(null);
1010
1155
  setMoreOpenFor(null);
1011
- }, [multiWeek, windowKey]);
1156
+ }, [multiWeek, windowKey, applyDrag]);
1012
1157
  // Multi-week roving: the neighbouring focusable day, the same weekday in the
1013
1158
  // nearest week that has it enabled, or the first/last focusable day.
1014
1159
  const nextMultiWeekFocus = (key: string): Date | null | undefined => {
@@ -1125,16 +1270,19 @@ export function DateRows<T = unknown>({
1125
1270
  // inside its start-column cell (valid grid content that reads with that day)
1126
1271
  // and overflows right across the days it spans. The cells reserve the lane
1127
1272
  // rows so "+more" sits below the bars.
1128
- const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
1273
+ const rowLayout = rowLayouts[weekIndex] ?? EMPTY_LAYOUT;
1129
1274
  // When lanes overflow, keep the last row for "+more" but always show at
1130
1275
  // least one bar, so a day never collapses to only the overflow row.
1131
- const overflowing = rowLayout.laneCount > maxVisibleEventCount;
1132
- const visibleLanes = overflowing
1133
- ? Math.max(maxVisibleEventCount - 1, 1)
1134
- : rowLayout.laneCount;
1276
+ const visibleLanes = visibleLanesFor(rowLayout.laneCount);
1277
+ const cols = week.days.length;
1278
+ // A day whose only hidden event sits on the "+more" row's lane draws that
1279
+ // event there instead of "+1 more".
1280
+ const extraLane =
1281
+ visibleLanes < maxVisibleEventCount
1282
+ ? monthExtraLaneColumns(rowLayout, visibleLanes, cols)
1283
+ : week.days.map(() => false);
1135
1284
  // With adjacent months hidden, clamp bars to the current-month columns so
1136
1285
  // none draw over the blank leading/trailing cells.
1137
- const cols = week.days.length;
1138
1286
  let firstVisCol = 0;
1139
1287
  let lastVisCol = cols - 1;
1140
1288
  if (eventsMode && !showAdjacentMonths) {
@@ -1145,8 +1293,8 @@ export function DateRows<T = unknown>({
1145
1293
  lastVisCol = cols - 1 - lastFromEnd;
1146
1294
  }
1147
1295
  }
1148
- const barSegs = rowLayout.segments
1149
- .filter((s) => s.lane < visibleLanes)
1296
+ const barSegs = monthVisibleBars(rowLayout, visibleLanes, extraLane)
1297
+ .filter((s) => s.event !== draftEvent)
1150
1298
  .map((s) => {
1151
1299
  const startCol = Math.max(s.startCol, firstVisCol);
1152
1300
  const endCol = Math.min(s.endCol, lastVisCol);
@@ -1159,6 +1307,13 @@ export function DateRows<T = unknown>({
1159
1307
  };
1160
1308
  })
1161
1309
  .filter((b) => b.startCol <= b.endCol);
1310
+ // The draft's own lane and columns, clamped like the bars.
1311
+ const draftSegment = rowLayout.segments.find((s) => s.event === draftEvent);
1312
+ const draftStart = draftSegment ? Math.max(draftSegment.startCol, firstVisCol) : -1;
1313
+ const draftEnd = draftSegment ? Math.min(draftSegment.endCol, lastVisCol) : -1;
1314
+ const draftTop =
1315
+ CELL_PAD + DATE_ROW + chipGap + (draftSegment?.lane ?? 0) * (chipHeight + chipGap);
1316
+ const draftHeight = Math.min(chipHeight, Math.max(0, eventRowHeight - draftTop));
1162
1317
  const barChipButton = slot("chipButton", chipButtonDefault);
1163
1318
  const barChip = slot("chip", chipDefault(theme, chipHeight));
1164
1319
  return (
@@ -1173,6 +1328,9 @@ export function DateRows<T = unknown>({
1173
1328
  })}
1174
1329
  >
1175
1330
  {week.days.map((day, dayCol) => {
1331
+ // Lanes this day shows: the row's, plus the "+more" row's when it holds
1332
+ // the day's only hidden event.
1333
+ const dayLanes = visibleLanes + (extraLane[dayCol] ? 1 : 0);
1176
1334
  const hidden = !showAdjacentMonths && isOutsidePeriod(day);
1177
1335
  const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
1178
1336
  if (hidden) {
@@ -1215,7 +1373,11 @@ export function DateRows<T = unknown>({
1215
1373
  // whole day.
1216
1374
  const hiddenEvents = rowLayout.segments
1217
1375
  .filter(
1218
- (s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes,
1376
+ (s) =>
1377
+ s.startCol <= dayCol &&
1378
+ s.endCol >= dayCol &&
1379
+ s.lane >= dayLanes &&
1380
+ s.event !== draftEvent,
1219
1381
  )
1220
1382
  .map((s) => s.event);
1221
1383
  const dayLabel = format(day.date, "d MMMM", locale ? { locale } : undefined);
@@ -1277,13 +1439,15 @@ export function DateRows<T = unknown>({
1277
1439
  // A disabled day is out of every selection, drag included, so
1278
1440
  // a sweep never extends onto it and no drop lands there.
1279
1441
  onPointerEnter={
1280
- dragWired && !day.isDisabled ? () => extendDrag(day.date) : undefined
1442
+ dragWired && !day.isDisabled
1443
+ ? (event) => extendDrag(day.date, event.pointerId)
1444
+ : undefined
1281
1445
  }
1282
1446
  onClick={
1283
1447
  day.isDisabled
1284
1448
  ? undefined
1285
- : () => {
1286
- if (consumeSuppressedClick()) return;
1449
+ : (e) => {
1450
+ if (consumeSuppressedClick(e.detail)) return;
1287
1451
  onPressDay?.(day.date);
1288
1452
  onPressCell?.(startOfDay(day.date));
1289
1453
  }
@@ -1316,10 +1480,11 @@ export function DateRows<T = unknown>({
1316
1480
  .filter((b) => b.startCol === dayCol)
1317
1481
  .map((b) => {
1318
1482
  const span = b.endCol - b.startCol + 1;
1319
- const isDragged = drag?.kind === "move" && drag.event === b.seg.event;
1483
+ const isDragged =
1484
+ dragArmed && drag?.kind === "move" && drag.event === b.seg.event;
1320
1485
  return (
1321
1486
  <button
1322
- key={`bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`}
1487
+ key={`bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}:${b.startCol}`}
1323
1488
  type="button"
1324
1489
  onPointerDown={
1325
1490
  canMove(b.seg.event)
@@ -1332,7 +1497,7 @@ export function DateRows<T = unknown>({
1332
1497
  }
1333
1498
  onClick={(e) => {
1334
1499
  e.stopPropagation();
1335
- if (consumeSuppressedClick()) return;
1500
+ if (consumeSuppressedClick(e.detail)) return;
1336
1501
  onPressEvent?.(b.seg.event);
1337
1502
  }}
1338
1503
  {...barChipButton}
@@ -1357,7 +1522,7 @@ export function DateRows<T = unknown>({
1357
1522
  chipGap +
1358
1523
  b.seg.lane * (chipHeight + chipGap),
1359
1524
  height: chipHeight,
1360
- pointerEvents: isDragging ? "none" : "auto",
1525
+ pointerEvents: dragArmed ? "none" : "auto",
1361
1526
  // Fade the bar being carried, so the tinted drop
1362
1527
  // target reads as where it is going.
1363
1528
  opacity: isDragged ? DRAGGED_CHIP_OPACITY : undefined,
@@ -1391,6 +1556,38 @@ export function DateRows<T = unknown>({
1391
1556
  </button>
1392
1557
  );
1393
1558
  })}
1559
+ {RenderCreateGhost &&
1560
+ createRange &&
1561
+ draftStart === dayCol &&
1562
+ draftEnd >= draftStart &&
1563
+ draftHeight > 0 ? (
1564
+ <InertDiv
1565
+ {...slot("createGhost", {
1566
+ base: {
1567
+ position: "absolute",
1568
+ left: 2,
1569
+ width: `calc(${(draftEnd - draftStart + 1) * 100}% - 4px)`,
1570
+ top: draftTop,
1571
+ height: draftHeight,
1572
+ boxSizing: "border-box",
1573
+ pointerEvents: "none",
1574
+ overflow: "hidden",
1575
+ zIndex: 3,
1576
+ },
1577
+ themed: {
1578
+ background: theme.rangeBackground,
1579
+ border: `1px solid ${theme.selectedBackground}`,
1580
+ borderRadius: 4,
1581
+ fontSize: 12,
1582
+ color: theme.text,
1583
+ },
1584
+ })}
1585
+ inert
1586
+ aria-hidden="true"
1587
+ >
1588
+ <RenderCreateGhost start={createRange.start} end={createRange.end} />
1589
+ </InertDiv>
1590
+ ) : null}
1394
1591
  <div
1395
1592
  {...slot("events", {
1396
1593
  base: { display: "flex", flexDirection: "column", gap: chipGap },
@@ -1398,7 +1595,7 @@ export function DateRows<T = unknown>({
1398
1595
  >
1399
1596
  {/* Reserve one row per visible lane so the absolute bars have
1400
1597
  space and "+more" sits below them. */}
1401
- {Array.from({ length: visibleLanes }, (_, i) => (
1598
+ {Array.from({ length: dayLanes }, (_, i) => (
1402
1599
  <div key={`lane-${i}`} aria-hidden style={{ height: chipHeight }} />
1403
1600
  ))}
1404
1601
  {hiddenEvents.length > 0 ? (
@@ -1,11 +1,15 @@
1
- import type {
2
- ComponentType,
3
- CSSProperties,
4
- PointerEvent as ReactPointerEvent,
5
- ReactElement,
6
- ReactNode,
1
+ import {
2
+ type ComponentType,
3
+ type CSSProperties,
4
+ type PointerEvent as ReactPointerEvent,
5
+ type ReactElement,
6
+ type ReactNode,
7
+ useCallback,
8
+ useEffect,
9
+ useMemo,
10
+ useRef,
11
+ useState,
7
12
  } from "react";
8
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9
13
  import {
10
14
  backgroundBandsForDay,
11
15
  type BusinessHoursBand,