@super-calendar/dom 2.17.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.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LegendList } from "@legendapp/list/react";
2
2
  import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
3
- import { createElement, forwardRef, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
4
- import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, buildMultiWeekGrid, buildMultiWeekGrid as buildMultiWeekGrid$1, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, daySelectionState as daySelectionState$1, defaultCalendarLabels, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, filterHiddenDays, formatHour, getIsToday, getViewDays, getViewDays as getViewDays$1, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isBackgroundEvent, isBackgroundEvent as isBackgroundEvent$1, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, layoutMonthWeek, layoutMonthWeek as layoutMonthWeek$1, lightColors, monthCreateRange, monthDropBounds, movedClockSpan, nextDateRange, nextDateRange as nextDateRange$1, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, titleNumberOfLines, toICalendar, useDateRange, useEventSource, useMonthGrid, useNow, useNow as useNow$1, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
3
+ import { createElement, forwardRef, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, buildMultiWeekGrid, buildMultiWeekGrid as buildMultiWeekGrid$1, cellRangeFromDrag, clampMoveStartMinutes, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, daySelectionState as daySelectionState$1, defaultCalendarLabels, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, filterHiddenDays, formatHour, fromZonedRange, fromZonedTime, getIsToday, getViewDays, getViewDays as getViewDays$1, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isBackgroundEvent, isBackgroundEvent as isBackgroundEvent$1, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, layoutMonthWeek, layoutMonthWeek as layoutMonthWeek$1, lightColors, monthCreateRange, monthDropBounds, movedClockSpan, nextDateRange, nextDateRange as nextDateRange$1, nowInTimeZone, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, titleNumberOfLines, toICalendar, useDateRange, useEventSource, useMonthGrid, useNow, useNow as useNow$1, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1, zonedDragBounds, zonedEventSource } from "@super-calendar/core";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/slots.ts
7
7
  /** Join truthy class names (a dependency-free clsx-lite). */
@@ -101,8 +101,9 @@ function DefaultAgendaRow({ event, isAllDay, ampm = false, cardProps }) {
101
101
  * <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
102
102
  * ```
103
103
  */
104
- function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }) {
104
+ function Agenda({ events, locale, now, timeZone, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }) {
105
105
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
106
+ const today = nowInTimeZone(now, timeZone);
106
107
  const slot = createSlots({
107
108
  classNames,
108
109
  styles
@@ -147,7 +148,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
147
148
  },
148
149
  renderItem: ({ item }) => {
149
150
  if (item.kind === "header") {
150
- const highlighted = activeDate ? isSameDay(item.date, activeDate) : getIsToday(item.date);
151
+ const highlighted = activeDate ? isSameDay(item.date, activeDate) : getIsToday(item.date, today);
151
152
  const label = format(item.date, "EEEE, d LLLL", locale ? { locale } : void 0);
152
153
  const color = highlighted ? theme.todayBackground : theme.textMuted;
153
154
  const headerProps = slot("dayHeader", {
@@ -237,7 +238,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
237
238
  * highlighted and a dot under days that hold events. It's the view `Calendar`
238
239
  * renders for `mode="year"`.
239
240
  */
240
- function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels: labelsProp, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, theme: themeOverrides, className, style, classNames, styles }) {
241
+ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, now, timeZone, labels: labelsProp, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, theme: themeOverrides, className, style, classNames, styles }) {
241
242
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
242
243
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
243
244
  const slot = createSlots({
@@ -288,6 +289,7 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
288
289
  window.addEventListener("pointerup", finish);
289
290
  return () => window.removeEventListener("pointerup", finish);
290
291
  }, [isCreating, onCreateEvent]);
292
+ const today = nowInTimeZone(now, timeZone);
291
293
  const months = useMemo(() => getYearMonths(date), [date]);
292
294
  const weekdayLabels = useMemo(() => filterHiddenDays(getWeekDays(date, weekStartsOn), hiddenDays).map((d) => format(d, weekdayFormatToken$1("narrow"), { locale })), [
293
295
  date,
@@ -384,7 +386,7 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
384
386
  "aria-hidden": true,
385
387
  style: { aspectRatio: "1" }
386
388
  }, day.toISOString());
387
- const isToday = getIsToday(day);
389
+ const isToday = getIsToday(day, today);
388
390
  const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
389
391
  const hasEvents = eventDays.has(startOfDay(day).toISOString());
390
392
  const state = daySelectionState$1(day, {
@@ -634,6 +636,13 @@ function holdDateDrag(grab, start, move, cancel, release) {
634
636
  }, release, stop);
635
637
  return stop;
636
638
  }
639
+ // src/InertDiv.ts
640
+ function InertDiv(props) {
641
+ return createElement("div", {
642
+ ...props,
643
+ inert: props.inert ? "inert" : void 0
644
+ });
645
+ }
637
646
  // src/MonthView.tsx
638
647
  const EMPTY_LAYOUT = {
639
648
  segments: [],
@@ -643,6 +652,8 @@ const CHIP_HEIGHT = 18;
643
652
  const CHIP_GAP = 2;
644
653
  const CELL_PAD = 4;
645
654
  const DRAGGED_CHIP_OPACITY = .4;
655
+ const DRAG_SLOP_PX = 4;
656
+ const TOUCH_DRAG_SLOP_PX = 8;
646
657
  const isOutsidePeriod = (day) => day.isCurrentMonth === false;
647
658
  function dayCellDefault(day, theme, highlightWeekends) {
648
659
  return {
@@ -868,7 +879,7 @@ function MonthView({ date, showAdjacentMonths = true, ...rest }) {
868
879
  * The day-row grid behind the public row views: week rows of day cells with
869
880
  * spanning event bars, overflow, selection, drag, and keyboard handling.
870
881
  */
871
- function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, chipHeight = CHIP_HEIGHT, chipGap = CHIP_GAP, moreLabel = "{moreCount} More", labels: labelsProp, onPressEvent, onPressMore, selectedRange, selectedDates, highlightWeekends = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onPressCell, onCreateEvent, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, keyboardDayNavigation = false, className, style, classNames, styles }) {
882
+ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, chipHeight = CHIP_HEIGHT, chipGap = CHIP_GAP, moreLabel = "{moreCount} More", labels: labelsProp, onPressEvent, onPressMore, selectedRange, selectedDates, highlightWeekends = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, now, timeZone, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onPressCell, onCreateEvent, renderCreateGhost: RenderCreateGhost, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, keyboardDayNavigation = false, className, style, classNames, styles }) {
872
883
  const { date } = source;
873
884
  const multiWeek = source.kind === "multiweek";
874
885
  const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
@@ -880,8 +891,10 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
880
891
  classNames,
881
892
  styles
882
893
  });
883
- const eventsMode = events !== void 0 || multiWeek;
894
+ const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
895
+ const eventsMode = events !== void 0 || multiWeek || createContentEnabled;
884
896
  const dayRoving = !eventsMode || keyboardDayNavigation;
897
+ const todayKey = startOfDay(nowInTimeZone(now, timeZone)).getTime();
885
898
  const eventsByDay = useMemo(() => {
886
899
  if (eventsByDayProp) return eventsByDayProp;
887
900
  const map = groupEventsByDay((events ?? []).filter((event) => !isBackgroundEvent$1(event)));
@@ -929,7 +942,8 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
929
942
  minDate,
930
943
  maxDate,
931
944
  isDateDisabled,
932
- locale
945
+ locale,
946
+ today: new Date(todayKey)
933
947
  };
934
948
  if (numberOfWeeks === void 0) return {
935
949
  ...buildMonthGrid$1(date, options),
@@ -957,7 +971,8 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
957
971
  minDate,
958
972
  maxDate,
959
973
  isDateDisabled,
960
- locale
974
+ locale,
975
+ todayKey
961
976
  ]);
962
977
  const weekLayouts = useMemo(() => eventsMode ? weeks.map((week) => layoutMonthWeek$1(week.days.map((d) => d.date), collectRowEvents(week, eventsByDay))) : [], [
963
978
  eventsMode,
@@ -1023,54 +1038,75 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1023
1038
  (focusKey ? gridRef.current.querySelector(`[data-day="${focusKey}"]`) : gridRef.current)?.focus();
1024
1039
  }, [multiWeek, focusKey]);
1025
1040
  const [drag, setDrag] = useState(null);
1026
- const dragRef = useRef(drag);
1027
- dragRef.current = drag;
1041
+ const dragRef = useRef(null);
1042
+ const applyDrag = useCallback((next) => {
1043
+ dragRef.current = next;
1044
+ setDrag(next);
1045
+ }, []);
1046
+ const createStart = drag?.kind === "create" ? drag.anchor : null;
1047
+ const createEnd = drag?.kind === "create" ? drag.hover : null;
1048
+ const createRange = useMemo(() => createContentEnabled && createStart !== null && createEnd !== null ? monthCreateRange(new Date(createStart), new Date(createEnd)) : null, [
1049
+ createContentEnabled,
1050
+ createStart,
1051
+ createEnd
1052
+ ]);
1028
1053
  const movedRef = useRef(false);
1029
1054
  const suppressClickRef = useRef(false);
1030
- const consumeSuppressedClick = () => {
1031
- if (!suppressClickRef.current) return false;
1055
+ const consumeSuppressedClick = (detail) => {
1056
+ if (detail === 0 || !suppressClickRef.current) return false;
1032
1057
  suppressClickRef.current = false;
1033
1058
  return true;
1034
1059
  };
1035
1060
  const canMove = (event) => onDragEvent != null && !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable);
1061
+ const pressOrigin = useRef({
1062
+ x: 0,
1063
+ y: 0,
1064
+ slop: DRAG_SLOP_PX
1065
+ });
1036
1066
  const beginPress = () => {
1037
1067
  suppressClickRef.current = false;
1038
1068
  movedRef.current = false;
1039
1069
  };
1040
- const beginCreate = (day) => {
1070
+ const beginCreate = (day, pointerId, armed) => {
1041
1071
  if (!onCreateEvent && !onSelectDrag) return;
1042
1072
  const t = startOfDay(day).getTime();
1043
- setDrag({
1073
+ applyDrag({
1044
1074
  kind: "create",
1045
1075
  anchor: t,
1046
1076
  hover: t,
1047
- windowKey
1077
+ windowKey,
1078
+ pointerId,
1079
+ armed
1048
1080
  });
1049
1081
  };
1050
- const beginMove = (event, day) => {
1082
+ const beginMove = (event, day, pointerId, armed) => {
1051
1083
  if (!canMove(event)) return;
1052
1084
  const t = startOfDay(day).getTime();
1053
- setDrag({
1085
+ applyDrag({
1054
1086
  kind: "move",
1055
1087
  event,
1056
1088
  from: t,
1057
1089
  to: t,
1058
- windowKey
1090
+ windowKey,
1091
+ pointerId,
1092
+ armed
1059
1093
  });
1060
1094
  onDragStart?.(event);
1061
1095
  };
1062
- const extendDrag = (day) => {
1096
+ const extendDrag = (day, pointerId) => {
1063
1097
  const current = dragRef.current;
1064
- if (!current) return;
1098
+ if (!current || current.pointerId !== pointerId) return;
1065
1099
  const t = startOfDay(day).getTime();
1066
1100
  if (t === (current.kind === "create" ? current.hover : current.to)) return;
1067
1101
  movedRef.current = true;
1068
- setDrag(current.kind === "create" ? {
1102
+ applyDrag(current.kind === "create" ? {
1069
1103
  ...current,
1070
- hover: t
1104
+ hover: t,
1105
+ armed: true
1071
1106
  } : {
1072
1107
  ...current,
1073
- to: t
1108
+ to: t,
1109
+ armed: true
1074
1110
  });
1075
1111
  if (current.kind === "create") {
1076
1112
  const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
@@ -1095,12 +1131,17 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1095
1131
  const pressRow = (event, day, moving) => {
1096
1132
  if (event.button !== 0 || event.isPrimary === false || heldTouch.current) return;
1097
1133
  beginPress();
1098
- const start = () => {
1099
- if (moving) touchHandlers.current.beginMove(moving, day);
1100
- else touchHandlers.current.beginCreate(day);
1134
+ pressOrigin.current = {
1135
+ x: event.clientX,
1136
+ y: event.clientY,
1137
+ slop: event.pointerType === "touch" ? TOUCH_DRAG_SLOP_PX : DRAG_SLOP_PX
1138
+ };
1139
+ const start = (armed) => {
1140
+ if (moving) touchHandlers.current.beginMove(moving, day, event.pointerId, armed);
1141
+ else touchHandlers.current.beginCreate(day, event.pointerId, armed);
1101
1142
  };
1102
1143
  if (!multiWeek || !event.pointerType || event.pointerType === "mouse") {
1103
- start();
1144
+ start(false);
1104
1145
  return;
1105
1146
  }
1106
1147
  heldOrigin.current = {
@@ -1113,14 +1154,13 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1113
1154
  pointerType: event.pointerType,
1114
1155
  clientX: event.clientX,
1115
1156
  clientY: event.clientY
1116
- }, start, (x, y) => {
1157
+ }, () => start(true), (x, y) => {
1117
1158
  const element = gridRef.current?.ownerDocument.elementFromPoint(x, y)?.closest("[data-day]");
1118
1159
  if (!element || !gridRef.current?.contains(element)) return;
1119
1160
  const day = touchHandlers.current.dayLookup.get(element.dataset.day ?? "");
1120
- if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date);
1161
+ if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date, event.pointerId);
1121
1162
  }, () => {
1122
- dragRef.current = null;
1123
- setDrag(null);
1163
+ applyDrag(null);
1124
1164
  movedRef.current = false;
1125
1165
  }, () => {
1126
1166
  heldTouch.current = null;
@@ -1142,13 +1182,18 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1142
1182
  if (!enabled(origin.day) || !enabled(destination) || (origin.event ? !events?.includes(origin.event) || !canMove(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
1143
1183
  });
1144
1184
  const isDragging = drag !== null;
1185
+ const dragArmed = drag?.armed === true;
1145
1186
  const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
1146
1187
  useEffect(() => {
1147
1188
  if (!isDragging) return;
1148
- const finish = () => {
1189
+ const finish = (event) => {
1149
1190
  const current = dragRef.current;
1150
- setDrag(null);
1151
- if (!current || !movedRef.current) return;
1191
+ if (!current || current.pointerId !== event.pointerId) return;
1192
+ applyDrag(null);
1193
+ if (!movedRef.current) {
1194
+ if (current.kind === "move" && current.armed) suppressClickRef.current = true;
1195
+ return;
1196
+ }
1152
1197
  if (multiWeek && current.windowKey !== windowKeyRef.current) return;
1153
1198
  suppressClickRef.current = true;
1154
1199
  if (current.kind === "create") {
@@ -1161,24 +1206,61 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1161
1206
  if (eventOverlap === false && overlapsOtherEvents(events ?? [], current.event, next.start, next.end)) return;
1162
1207
  onDragEvent?.(current.event, next.start, next.end);
1163
1208
  };
1209
+ const clear = () => {
1210
+ heldTouch.current?.();
1211
+ applyDrag(null);
1212
+ movedRef.current = false;
1213
+ suppressClickRef.current = true;
1214
+ };
1215
+ const cancel = (event) => {
1216
+ if (dragRef.current?.pointerId === event.pointerId) clear();
1217
+ };
1218
+ const arm = (event) => {
1219
+ const current = dragRef.current;
1220
+ if (!current || current.armed || current.pointerId !== event.pointerId) return;
1221
+ const origin = pressOrigin.current;
1222
+ if (Math.hypot(event.clientX - origin.x, event.clientY - origin.y) <= origin.slop) return;
1223
+ applyDrag({
1224
+ ...current,
1225
+ armed: true
1226
+ });
1227
+ };
1228
+ const keyDown = (event) => {
1229
+ if (event.key !== "Escape") return;
1230
+ event.preventDefault();
1231
+ clear();
1232
+ };
1233
+ window.addEventListener("pointermove", arm);
1164
1234
  window.addEventListener("pointerup", finish);
1165
- return () => window.removeEventListener("pointerup", finish);
1235
+ window.addEventListener("pointercancel", cancel);
1236
+ window.addEventListener("keydown", keyDown);
1237
+ return () => {
1238
+ window.removeEventListener("pointermove", arm);
1239
+ window.removeEventListener("pointerup", finish);
1240
+ window.removeEventListener("pointercancel", cancel);
1241
+ window.removeEventListener("keydown", keyDown);
1242
+ };
1166
1243
  }, [
1167
1244
  isDragging,
1168
1245
  multiWeek,
1169
1246
  onCreateEvent,
1170
1247
  onDragEvent,
1171
1248
  eventOverlap,
1172
- events
1249
+ events,
1250
+ applyDrag
1173
1251
  ]);
1174
1252
  const transientWindow = useRef(windowKey);
1175
1253
  useEffect(() => {
1176
1254
  if (transientWindow.current === windowKey) return;
1177
1255
  transientWindow.current = windowKey;
1178
1256
  if (!multiWeek) return;
1179
- setDrag(null);
1257
+ applyDrag(null);
1180
1258
  setMoreOpenFor(null);
1181
- }, [multiWeek, windowKey]);
1259
+ }, [
1260
+ multiWeek,
1261
+ windowKey,
1262
+ applyDrag
1263
+ ]);
1182
1264
  const nextMultiWeekFocus = (key) => {
1183
1265
  if (!focusableDays || !focusableKeys || !period) return void 0;
1184
1266
  const index = focusableDays.findIndex((d) => format(d, "yyyy-MM-dd") === focusKey);
@@ -1302,6 +1384,11 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1302
1384
  continuesAfter: s.continuesAfter || endCol < s.endCol
1303
1385
  };
1304
1386
  }).filter((b) => b.startCol <= b.endCol);
1387
+ const draftColumns = createRange ? week.days.flatMap((day, index) => !showAdjacentMonths && isOutsidePeriod(day) || day.date < createRange.start || day.date >= createRange.end ? [] : [index]) : [];
1388
+ const draftStart = draftColumns[0];
1389
+ const draftEnd = draftColumns.at(-1);
1390
+ const draftTop = 28 + chipGap + Math.min(visibleLanes, Math.max(0, maxVisibleEventCount - 1)) * (chipHeight + chipGap);
1391
+ const draftHeight = Math.min(chipHeight, Math.max(0, eventRowHeight - draftTop));
1305
1392
  const barChipButton = slot("chipButton", chipButtonDefault);
1306
1393
  const barChip = slot("chip", chipDefault(theme, chipHeight));
1307
1394
  return /* @__PURE__ */ jsx("div", {
@@ -1368,9 +1455,9 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1368
1455
  onPointerDown: dragWired && !day.isDisabled ? (e) => {
1369
1456
  pressRow(e, day.date);
1370
1457
  } : void 0,
1371
- onPointerEnter: dragWired && !day.isDisabled ? () => extendDrag(day.date) : void 0,
1372
- onClick: day.isDisabled ? void 0 : () => {
1373
- if (consumeSuppressedClick()) return;
1458
+ onPointerEnter: dragWired && !day.isDisabled ? (event) => extendDrag(day.date, event.pointerId) : void 0,
1459
+ onClick: day.isDisabled ? void 0 : (e) => {
1460
+ if (consumeSuppressedClick(e.detail)) return;
1374
1461
  onPressDay?.(day.date);
1375
1462
  onPressCell?.(startOfDay(day.date));
1376
1463
  },
@@ -1395,7 +1482,7 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1395
1482
  }),
1396
1483
  barSegs.filter((b) => b.startCol === dayCol).map((b) => {
1397
1484
  const span = b.endCol - b.startCol + 1;
1398
- const isDragged = drag?.kind === "move" && drag.event === b.seg.event;
1485
+ const isDragged = dragArmed && drag?.kind === "move" && drag.event === b.seg.event;
1399
1486
  return /* @__PURE__ */ jsx("button", {
1400
1487
  type: "button",
1401
1488
  onPointerDown: canMove(b.seg.event) ? (e) => {
@@ -1405,7 +1492,7 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1405
1492
  } : void 0,
1406
1493
  onClick: (e) => {
1407
1494
  e.stopPropagation();
1408
- if (consumeSuppressedClick()) return;
1495
+ if (consumeSuppressedClick(e.detail)) return;
1409
1496
  onPressEvent?.(b.seg.event);
1410
1497
  },
1411
1498
  ...barChipButton,
@@ -1422,7 +1509,7 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1422
1509
  width: `calc(${span * 100}% - 4px)`,
1423
1510
  top: 28 + chipGap + b.seg.lane * (chipHeight + chipGap),
1424
1511
  height: chipHeight,
1425
- pointerEvents: isDragging ? "none" : "auto",
1512
+ pointerEvents: dragArmed ? "none" : "auto",
1426
1513
  opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
1427
1514
  cursor: canMove(b.seg.event) ? "grab" : void 0,
1428
1515
  touchAction: dragWired ? multiWeek ? "pan-y" : "none" : void 0,
@@ -1449,6 +1536,34 @@ function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short
1449
1536
  })
1450
1537
  }, `bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`);
1451
1538
  }),
1539
+ RenderCreateGhost && createRange && draftStart === dayCol && draftEnd !== void 0 && draftHeight > 0 ? /* @__PURE__ */ jsx(InertDiv, {
1540
+ ...slot("createGhost", {
1541
+ base: {
1542
+ position: "absolute",
1543
+ left: 2,
1544
+ width: `calc(${(draftEnd - draftStart + 1) * 100}% - 4px)`,
1545
+ top: draftTop,
1546
+ height: draftHeight,
1547
+ boxSizing: "border-box",
1548
+ pointerEvents: "none",
1549
+ overflow: "hidden",
1550
+ zIndex: 3
1551
+ },
1552
+ themed: {
1553
+ background: theme.rangeBackground,
1554
+ border: `1px solid ${theme.selectedBackground}`,
1555
+ borderRadius: 4,
1556
+ fontSize: 12,
1557
+ color: theme.text
1558
+ }
1559
+ }),
1560
+ inert: true,
1561
+ "aria-hidden": "true",
1562
+ children: /* @__PURE__ */ jsx(RenderCreateGhost, {
1563
+ start: createRange.start,
1564
+ end: createRange.end
1565
+ })
1566
+ }) : null,
1452
1567
  /* @__PURE__ */ jsxs("div", {
1453
1568
  ...slot("events", { base: {
1454
1569
  display: "flex",
@@ -1976,19 +2091,13 @@ function EventActionsDialog({ dialogRef, title, description, actions, closeLabel
1976
2091
  })
1977
2092
  });
1978
2093
  }
1979
- // src/InertDiv.ts
1980
- function InertDiv(props) {
1981
- return createElement("div", {
1982
- ...props,
1983
- inert: props.inert ? "inert" : void 0
1984
- });
1985
- }
1986
2094
  // src/TimeGrid.tsx
1987
2095
  const GUTTER_WIDTH$1 = 56;
1988
2096
  const HOURS_PER_DAY = 24;
1989
2097
  const DEFAULT_MIN_EVENT_HEIGHT = 14;
1990
2098
  const DEFAULT_EVENT_GAP = 1;
1991
2099
  const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
2100
+ const useClientLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
1992
2101
  const CREATE_PREVIEW_MIN_HEIGHT = 2;
1993
2102
  function createPreviewPlacement(topPx, heightPx, gridHeight) {
1994
2103
  const start = clamp$1(topPx, 0, gridHeight);
@@ -2003,6 +2112,11 @@ function createPreviewPlacement(topPx, heightPx, gridHeight) {
2003
2112
  height
2004
2113
  };
2005
2114
  }
2115
+ function createRangePlacement(range, day, hourHeight, minHour, gridHeight, minEventHeight) {
2116
+ const at = (time) => (differenceInCalendarDays(time, day) * 24 + time.getHours() + time.getMinutes() / 60 - minHour) * hourHeight;
2117
+ const top = at(range.start);
2118
+ return createPreviewPlacement(top, Math.max(minEventHeight, at(range.end) - top), gridHeight);
2119
+ }
2006
2120
  const EDGE_ZONE = 32;
2007
2121
  const EDGE_DWELL_MS = 600;
2008
2122
  const EDGE_REPEAT_MS = 600;
@@ -2026,6 +2140,20 @@ function movedSegmentStart(origin, base, startHours) {
2026
2140
  const dayMinutes = differenceInCalendarDays(base, origin.base) * HOURS_PER_DAY * 60;
2027
2141
  return shiftMinutes(origin.segmentStart, dayMinutes + Math.round((startHours - origin.startHours) * 60));
2028
2142
  }
2143
+ function draggedEventBounds(d, origin, event, base, snapMinutes) {
2144
+ if (d.kind === "resize") {
2145
+ const endDelta = Math.round((d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60);
2146
+ return resolveDraggedBounds(event.start, event.end, 0, endDelta, snapMinutes);
2147
+ }
2148
+ const startShift = movedSegmentStart(origin, base, d.kind === "move" ? d.requestedStartHours : d.startHours).getTime() - origin.segmentStart.getTime();
2149
+ const endShift = d.kind === "move" ? startShift : 0;
2150
+ const start = new Date(event.start.getTime() + startShift);
2151
+ const end = new Date(event.end.getTime() + endShift);
2152
+ return end > start || d.kind === "move" && end.getTime() === start.getTime() ? {
2153
+ start,
2154
+ end
2155
+ } : null;
2156
+ }
2029
2157
  function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme, boxProps }) {
2030
2158
  const timeLabel = eventTimeLabel({
2031
2159
  mode,
@@ -2127,6 +2255,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2127
2255
  now: nowProp,
2128
2256
  timeZone
2129
2257
  });
2258
+ const todayDate = showNowIndicator ? now : nowInTimeZone(nowProp, timeZone);
2130
2259
  const [hourHeight, setHourHeight] = useState(initialHourHeight);
2131
2260
  useEffect(() => setHourHeight(initialHourHeight), [initialHourHeight]);
2132
2261
  const hourHeightRef = useRef(hourHeight);
@@ -2141,6 +2270,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2141
2270
  const [createBox, setCreateBox] = useState(null);
2142
2271
  const createOrigin = useRef(null);
2143
2272
  const createActive = createBox !== null;
2273
+ const detachCreateListeners = useRef(null);
2274
+ const createRelease = useRef(null);
2144
2275
  useEffect(() => {
2145
2276
  if (!createActive) return;
2146
2277
  const onScroll = () => {
@@ -2206,6 +2337,11 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2206
2337
  canResize: editable && (event.durationEditable ?? eventDurationEditable)
2207
2338
  };
2208
2339
  };
2340
+ const hasEditActions = (event) => {
2341
+ if (isAllDayEvent$1(event) || isBackgroundEvent$1(event)) return false;
2342
+ const { canMove, canResize } = editability(event);
2343
+ return canMove || canResize;
2344
+ };
2209
2345
  const eventLabel = (event) => eventAccessibilityLabel$1 ? eventAccessibilityLabel$1(event, {
2210
2346
  mode,
2211
2347
  isAllDay: false,
@@ -2233,7 +2369,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2233
2369
  }
2234
2370
  };
2235
2371
  const editActions = (event) => {
2236
- if (isAllDayEvent$1(event) || isBackgroundEvent$1(event)) return [];
2372
+ if (!hasEditActions(event)) return [];
2237
2373
  const { canMove, canResize } = editability(event);
2238
2374
  const action = (id, label) => {
2239
2375
  const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
@@ -2255,12 +2391,36 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2255
2391
  if (!next || onDragEventRef.current?.(event, next.start, next.end) === false) return null;
2256
2392
  return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title;
2257
2393
  }, getEventId);
2258
- const allDayByDay = useMemo(() => days.map((day) => {
2259
- const dayStart = startOfDay(day);
2260
- const dayEnd = addDays(dayStart, 1);
2261
- return events.filter((e) => isAllDayEvent$1(e) && !isBackgroundEvent$1(e) && e.start < dayEnd && e.end > dayStart);
2262
- }), [days, events]);
2263
- const hasAllDay = allDayByDay.some((list) => list.length > 0);
2394
+ const allDayLayout = useMemo(() => layoutMonthWeek$1(days, events.filter((event) => isAllDayEvent$1(event) && !isBackgroundEvent$1(event) && days.some((day) => event.start < addDays(startOfDay(day), 1) && event.end > startOfDay(day)))), [days, events]);
2395
+ const hasAllDay = allDayLayout.segments.length > 0;
2396
+ const allDayIds = useMemo(() => {
2397
+ const keys = /* @__PURE__ */ new Map();
2398
+ const seen = /* @__PURE__ */ new Map();
2399
+ for (const { event } of allDayLayout.segments) {
2400
+ const id = getEventId?.(event);
2401
+ if (typeof id !== "string" && typeof id !== "number") continue;
2402
+ const key = `${typeof id}:${id}`;
2403
+ const previous = seen.get(key);
2404
+ if (previous) keys.delete(previous);
2405
+ else {
2406
+ seen.set(key, event);
2407
+ keys.set(event, key);
2408
+ }
2409
+ }
2410
+ return keys;
2411
+ }, [allDayLayout, getEventId]);
2412
+ const allDayKeys = useRef(/* @__PURE__ */ new WeakMap());
2413
+ const nextAllDayKey = useRef(0);
2414
+ const allDayKey = (event) => {
2415
+ const id = allDayIds.get(event);
2416
+ if (id !== void 0) return id;
2417
+ let key = allDayKeys.current.get(event);
2418
+ if (key === void 0) {
2419
+ key = nextAllDayKey.current++;
2420
+ allDayKeys.current.set(event, key);
2421
+ }
2422
+ return `object:${key}`;
2423
+ };
2264
2424
  useEffect(() => {
2265
2425
  if (scrollRef.current) scrollRef.current.scrollTop = Math.max(0, (scrollOffsetMinutes / 60 - windowStart) * hourHeightRef.current);
2266
2426
  }, [scrollOffsetMinutes, windowStart]);
@@ -2360,6 +2520,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2360
2520
  document.removeEventListener("pointermove", h.move);
2361
2521
  document.removeEventListener("pointerup", h.up);
2362
2522
  document.removeEventListener("pointercancel", h.cancel);
2523
+ document.removeEventListener("selectstart", h.preventNative, true);
2524
+ document.removeEventListener("dragstart", h.preventNative, true);
2363
2525
  docHandlersRef.current = null;
2364
2526
  };
2365
2527
  const finishDrag = () => {
@@ -2467,18 +2629,14 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2467
2629
  base = day ? startOfDay(day) : null;
2468
2630
  } else base = startOfDay(daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex]);
2469
2631
  } else base = startOfDay(daysRef.current[originIndex] ?? daysRef.current[0]);
2470
- if (held && origin && d.kind === "resize") {
2471
- const endDelta = Math.round((d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60);
2472
- const next = resolveDraggedBounds(held.event.start, held.event.end, 0, endDelta, snapMinutes);
2473
- if (next) onDragEventRef.current?.(held.event, next.start, next.end);
2474
- } else if (base && held && origin) {
2475
- const startShift = movedSegmentStart(origin, base, d.kind === "move" ? d.requestedStartHours : d.startHours).getTime() - origin.segmentStart.getTime();
2476
- const endShift = d.kind === "move" ? startShift : 0;
2477
- const start = new Date(held.event.start.getTime() + startShift);
2478
- const end = new Date(held.event.end.getTime() + endShift);
2479
- if (end > start) onDragEventRef.current?.(held.event, start, end);
2632
+ try {
2633
+ if (base && held && origin) {
2634
+ const next = draggedEventBounds(d, origin, held.event, base, snapMinutes);
2635
+ if (next) onDragEventRef.current?.(held.event, next.start, next.end);
2636
+ }
2637
+ } finally {
2638
+ finishDrag();
2480
2639
  }
2481
- finishDrag();
2482
2640
  };
2483
2641
  const cancelDrag = () => {
2484
2642
  finishDrag();
@@ -2492,7 +2650,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2492
2650
  activeGrabRef.current = e;
2493
2651
  const boxEl = e.box;
2494
2652
  const column = kind === "move" ? boxEl.parentElement : null;
2495
- const dayWidth = column ? column.getBoundingClientRect().width : 0;
2653
+ const columnRect = column ? column.getBoundingClientRect() : null;
2654
+ const dayWidth = columnRect ? columnRect.width : 0;
2496
2655
  const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
2497
2656
  const originBase = startOfDay(days[dayIndex] ?? days[0]);
2498
2657
  const originNextDay = addDays(originBase, 1);
@@ -2512,9 +2671,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2512
2671
  draggedRef.current = {
2513
2672
  event,
2514
2673
  onPress: onPress ?? (() => {}),
2515
- grabX: boxRect ? e.clientX - boxRect.left : 0,
2674
+ grabX: column && columnRect ? e.clientX - columnRect.left - column.clientLeft - eventGap : 0,
2516
2675
  grabY: boxRect ? e.clientY - boxRect.top : 0,
2517
- w: boxRect ? boxRect.width : 0,
2676
+ w: column ? Math.max(column.clientWidth - eventGap * 2, 0) : 0,
2518
2677
  h: boxRect ? boxRect.height : 0
2519
2678
  };
2520
2679
  ptr.current = {
@@ -2550,12 +2709,15 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2550
2709
  },
2551
2710
  cancel: (event) => {
2552
2711
  if (event.pointerId === e.pointerId) cancelDrag();
2553
- }
2712
+ },
2713
+ preventNative: (event) => event.preventDefault()
2554
2714
  };
2555
2715
  docHandlersRef.current = handlers;
2556
2716
  document.addEventListener("pointermove", handlers.move);
2557
2717
  document.addEventListener("pointerup", handlers.up);
2558
2718
  document.addEventListener("pointercancel", handlers.cancel);
2719
+ document.addEventListener("selectstart", handlers.preventNative, true);
2720
+ document.addEventListener("dragstart", handlers.preventNative, true);
2559
2721
  };
2560
2722
  const pressEvent = (e, pe, key, kind, dayIndex, onPress) => {
2561
2723
  if (!onDragEvent || e.button > 0) return;
@@ -2589,6 +2751,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2589
2751
  cancelHoldRef.current?.();
2590
2752
  detachDocListeners();
2591
2753
  clearEdgeTimer();
2754
+ if (createOrigin.current?.captureLoss !== void 0) clearTimeout(createOrigin.current.captureLoss);
2755
+ createOrigin.current = null;
2756
+ detachCreateListeners.current?.();
2757
+ detachCreateListeners.current = null;
2592
2758
  }, []);
2593
2759
  useEffect(() => {
2594
2760
  cancelHoldRef.current?.();
@@ -2599,6 +2765,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2599
2765
  ]);
2600
2766
  const pxFromTop = (el, clientY) => clientY - el.getBoundingClientRect().top;
2601
2767
  const beginCreate = (e, dayIndex) => {
2768
+ if (createOrigin.current || activeGrabRef.current || e.isPrimary === false) return;
2602
2769
  cellTouchRef.current = e.pointerType === "touch" && e.target === e.currentTarget ? {
2603
2770
  pointerId: e.pointerId,
2604
2771
  x: e.clientX,
@@ -2627,12 +2794,33 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2627
2794
  startPx,
2628
2795
  curPx: startPx
2629
2796
  });
2797
+ const document = el.ownerDocument;
2798
+ const release = (event) => createRelease.current?.(event);
2799
+ const cancel = (event) => {
2800
+ if (createOrigin.current?.pointerId === event.pointerId) clearCreate();
2801
+ };
2802
+ const restart = (event) => {
2803
+ if (event.isPrimary && event.pointerType !== "touch" || createOrigin.current?.pointerId === event.pointerId) clearCreate();
2804
+ };
2805
+ const preventSelection = (event) => event.preventDefault();
2806
+ document.addEventListener("pointerup", release, true);
2807
+ document.addEventListener("pointercancel", cancel, true);
2808
+ document.addEventListener("pointerdown", restart, true);
2809
+ document.addEventListener("selectstart", preventSelection, true);
2810
+ document.addEventListener("dragstart", preventSelection, true);
2811
+ detachCreateListeners.current = () => {
2812
+ document.removeEventListener("pointerup", release, true);
2813
+ document.removeEventListener("pointercancel", cancel, true);
2814
+ document.removeEventListener("pointerdown", restart, true);
2815
+ document.removeEventListener("selectstart", preventSelection, true);
2816
+ document.removeEventListener("dragstart", preventSelection, true);
2817
+ };
2630
2818
  };
2631
2819
  const moveCreate = (e) => {
2632
2820
  const touch = cellTouchRef.current;
2633
2821
  if (touch && e.pointerId === touch.pointerId && Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX) cellTouchRef.current = null;
2634
2822
  const o = createOrigin.current;
2635
- if (!o) return;
2823
+ if (!o || o.pointerId !== e.pointerId) return;
2636
2824
  o.clientY = e.clientY;
2637
2825
  setCreateBox({
2638
2826
  dayIndex: o.dayIndex,
@@ -2643,10 +2831,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2643
2831
  };
2644
2832
  const endCreate = (e) => {
2645
2833
  const o = createOrigin.current;
2646
- if (!o) return;
2647
- try {
2648
- o.el.releasePointerCapture?.(e.pointerId);
2649
- } catch {}
2834
+ if (!o || o.pointerId !== e.pointerId) return;
2835
+ clearCreate();
2836
+ if (!o.el.isConnected || !cellEnabled || o.creating && !onCreateEvent || days[o.dayIndex]?.getTime() !== o.dayTime) return;
2650
2837
  const endPx = pxFromTop(o.el, e.clientY);
2651
2838
  const day = days[o.dayIndex];
2652
2839
  const moved = Math.abs(endPx - o.startPx) > 4;
@@ -2658,9 +2845,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2658
2845
  const at = cellRangeFromDrag(day, o.startPx, o.startPx, h, windowStart, snapMinutes);
2659
2846
  if (at) onPressCell(at.start);
2660
2847
  }
2661
- createOrigin.current = null;
2662
- setCreateBox(null);
2663
2848
  };
2849
+ useClientLayoutEffect(() => {
2850
+ createRelease.current = endCreate;
2851
+ });
2664
2852
  const tapCell = (e, dayIndex) => {
2665
2853
  const touch = cellTouchRef.current;
2666
2854
  cellTouchRef.current = null;
@@ -2673,18 +2861,26 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2673
2861
  const clearCreate = useCallback(() => {
2674
2862
  const previous = createOrigin.current;
2675
2863
  createOrigin.current = null;
2864
+ if (previous?.captureLoss !== void 0) clearTimeout(previous.captureLoss);
2865
+ detachCreateListeners.current?.();
2866
+ detachCreateListeners.current = null;
2676
2867
  setCreateBox(null);
2677
2868
  try {
2678
2869
  previous?.el.releasePointerCapture?.(previous.pointerId);
2679
2870
  } catch {}
2680
2871
  }, []);
2681
- const cancelCreate = () => {
2682
- cellTouchRef.current = null;
2872
+ const cancelCreate = (e) => {
2873
+ if (cellTouchRef.current?.pointerId === e.pointerId) cellTouchRef.current = null;
2874
+ if (createOrigin.current?.pointerId !== e.pointerId) return;
2683
2875
  clearCreate();
2684
2876
  };
2685
2877
  const loseCreateCapture = (e) => {
2686
- if (createOrigin.current?.pointerId !== e.pointerId) return;
2687
- clearCreate();
2878
+ const origin = createOrigin.current;
2879
+ if (!origin || origin.pointerId !== e.pointerId) return;
2880
+ if (origin.captureLoss !== void 0) clearTimeout(origin.captureLoss);
2881
+ origin.captureLoss = setTimeout(() => {
2882
+ if (createOrigin.current === origin) clearCreate();
2883
+ }, 0);
2688
2884
  };
2689
2885
  useEffect(() => {
2690
2886
  const onKeyDown = (event) => {
@@ -2696,7 +2892,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2696
2892
  document.addEventListener("keydown", onKeyDown);
2697
2893
  return () => document.removeEventListener("keydown", onKeyDown);
2698
2894
  }, [clearCreate]);
2699
- const liveRange = createBox && RenderCreateGhost && onCreateEvent && days[createBox.dayIndex]?.getTime() === createBox.dayTime ? cellRangeFromDrag(days[createBox.dayIndex], createBox.startPx, createBox.curPx, hourHeight, windowStart, snapMinutes) : null;
2895
+ const liveRange = createBox && onCreateEvent && days[createBox.dayIndex]?.getTime() === createBox.dayTime ? cellRangeFromDrag(days[createBox.dayIndex], createBox.startPx, createBox.curPx, hourHeight, windowStart, snapMinutes) : null;
2700
2896
  const liveStart = liveRange?.start.getTime();
2701
2897
  const liveEnd = liveRange?.end.getTime();
2702
2898
  const createRange = useMemo(() => liveStart === void 0 || liveEnd === void 0 ? null : {
@@ -2711,7 +2907,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2711
2907
  const moveOrigin = dragOrigin.current;
2712
2908
  const heldEvent = draggedRef.current?.event;
2713
2909
  const movingEvent = heldEvent && (events.includes(heldEvent) ? heldEvent : events.find((event) => event.start.getTime() === heldEvent.start.getTime() && event.end.getTime() === heldEvent.end.getTime() && event.title === heldEvent.title) ?? heldEvent);
2714
- const multiDayMove = !paged && drag?.kind === "move" && (drag.continuesBefore || drag.continuesAfter) && moveOrigin && movingEvent ? (() => {
2910
+ const multiDayHeld = !paged && drag?.kind === "move" && (drag.continuesBefore || drag.continuesAfter) && !!movingEvent;
2911
+ const multiDayMove = !paged && drag?.kind === "move" && drag.moved && (drag.continuesBefore || drag.continuesAfter) && moveOrigin && movingEvent ? (() => {
2715
2912
  const target = days[moveOrigin.dayIndex + drag.dayDelta];
2716
2913
  const shift = movedSegmentStart(moveOrigin, startOfDay(target), drag.requestedStartHours).getTime() - moveOrigin.segmentStart.getTime();
2717
2914
  return {
@@ -2721,12 +2918,18 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2721
2918
  allDay: false
2722
2919
  };
2723
2920
  })() : null;
2921
+ const liveBounds = !paged && drag?.moved && !multiDayMove && moveOrigin && draggedRef.current ? draggedEventBounds(drag, moveOrigin, draggedRef.current.event, startOfDay(days[moveOrigin.dayIndex + (drag.kind === "move" ? drag.dayDelta : 0)] ?? days[moveOrigin.dayIndex]), snapMinutes) : null;
2922
+ const withLiveBounds = (event) => liveBounds ? {
2923
+ ...event,
2924
+ start: liveBounds.start,
2925
+ end: liveBounds.end
2926
+ } : event;
2724
2927
  const spillPreviewFor = (dayIndex) => {
2725
2928
  if (paged || !drag || drag.kind !== "move" || drag.spillDayIndex !== dayIndex) return null;
2726
2929
  const dragged = draggedRef.current?.event;
2727
2930
  if (!dragged) return null;
2728
2931
  return {
2729
- event: dragged,
2932
+ event: withLiveBounds(dragged),
2730
2933
  mode,
2731
2934
  isAllDay: false,
2732
2935
  boxHeight: Math.max(drag.spillHours * hourHeight, minEventHeight),
@@ -2847,7 +3050,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2847
3050
  },
2848
3051
  children: [
2849
3052
  /* @__PURE__ */ jsx(EventActionsMenu, {
2850
- events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
3053
+ events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter(hasEditActions),
2851
3054
  label: labels.editEvents,
2852
3055
  labelFor: (event) => labels.eventActions(event.title ?? ""),
2853
3056
  descriptionFor: eventDescription,
@@ -2878,7 +3081,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2878
3081
  }),
2879
3082
  children: showWeekNumber && gutterWidth > 0 && days[0] ? `${weekNumberPrefix}${getISOWeek(days.find((d) => d.getDay() === 4) ?? days[0])}` : null
2880
3083
  }), days.map((day) => {
2881
- const today = getIsToday(day);
3084
+ const today = getIsToday(day, todayDate);
2882
3085
  const dateLabel = format(day, "EEEE, d MMMM yyyy", dfns);
2883
3086
  const headerProps = slot("columnHeader", {
2884
3087
  base: {
@@ -2955,6 +3158,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2955
3158
  base: {
2956
3159
  width: gutterWidth,
2957
3160
  flex: "none",
3161
+ boxSizing: "border-box",
2958
3162
  minWidth: 0,
2959
3163
  overflow: "hidden",
2960
3164
  textAlign: "right"
@@ -2962,34 +3166,41 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
2962
3166
  themed: {
2963
3167
  fontSize: 10,
2964
3168
  color: theme.textMuted,
2965
- padding: "4px 6px 0 0"
3169
+ padding: hideHours ? 0 : "4px 6px 0 0"
2966
3170
  }
2967
3171
  }),
2968
3172
  children: showAllDayLabel ? labels.allDay : null
2969
- }), allDayByDay.map((list, i) => {
2970
- const dayStart = startOfDay(days[i]);
2971
- const dayEnd = addDays(dayStart, 1);
2972
- return /* @__PURE__ */ jsx("div", {
2973
- ...slot("allDayColumn", { base: {
2974
- flex: 1,
2975
- minWidth: 0,
2976
- borderLeft: "1px solid transparent",
2977
- padding: "2px 1px",
2978
- display: "flex",
2979
- flexDirection: "column",
2980
- gap: 2
2981
- } }),
2982
- children: list.map((event) => {
2983
- const args = {
2984
- event,
2985
- mode,
2986
- isAllDay: true,
2987
- continuesBefore: event.start < dayStart,
2988
- continuesAfter: event.end > dayEnd,
2989
- ampm,
2990
- onPress: () => onPressEvent?.(event)
2991
- };
2992
- return /* @__PURE__ */ jsx("button", {
3173
+ }), /* @__PURE__ */ jsx("div", {
3174
+ style: {
3175
+ flex: 1,
3176
+ minWidth: 0,
3177
+ display: "grid",
3178
+ gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
3179
+ gap: "2px 0",
3180
+ padding: "2px 0"
3181
+ },
3182
+ children: allDayLayout.segments.map((segment) => {
3183
+ const { event, startCol, endCol, lane, continuesBefore, continuesAfter } = segment;
3184
+ const args = {
3185
+ event,
3186
+ mode,
3187
+ isAllDay: true,
3188
+ continuesBefore,
3189
+ continuesAfter,
3190
+ ampm,
3191
+ onPress: () => onPressEvent?.(event)
3192
+ };
3193
+ return /* @__PURE__ */ jsx("div", {
3194
+ ...slot("allDayColumn", { base: {
3195
+ gridColumn: `${startCol + 1} / span ${endCol - startCol + 1}`,
3196
+ gridRow: lane + 1,
3197
+ minWidth: 0,
3198
+ borderLeft: "1px solid transparent",
3199
+ padding: "0 1px",
3200
+ display: "flex",
3201
+ flexDirection: "column"
3202
+ } }),
3203
+ children: /* @__PURE__ */ jsx("button", {
2993
3204
  type: "button",
2994
3205
  onClick: () => onPressEvent?.(event),
2995
3206
  "aria-label": eventAccessibilityLabel$1 ? eventAccessibilityLabel$1(event, {
@@ -3017,9 +3228,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3017
3228
  theme,
3018
3229
  boxProps: slot("eventBox")
3019
3230
  })
3020
- }, `${event.start.toISOString()}:${event.title}`);
3021
- })
3022
- }, days[i].toISOString());
3231
+ })
3232
+ }, allDayKey(event));
3233
+ })
3023
3234
  })]
3024
3235
  }) : null,
3025
3236
  /* @__PURE__ */ jsx("div", {
@@ -3068,7 +3279,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3068
3279
  const nowTop = (nowHours - windowStart) * hourHeight;
3069
3280
  const bands = bandsByDay[dayIndex];
3070
3281
  const ghost = createBox?.dayIndex === dayIndex && createBox.dayTime === day.getTime() ? createBox : null;
3071
- const ghostRange = ghost ? createRange : null;
3282
+ const ghostRange = ghost && RenderCreateGhost ? createRange : null;
3072
3283
  const spill = multiDayMove ? null : spillPreviewFor(dayIndex);
3073
3284
  const moveSegment = multiDayMove ? layoutDayEvents$1([multiDayMove], day)[0] : void 0;
3074
3285
  return /* @__PURE__ */ jsxs("div", {
@@ -3080,7 +3291,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3080
3291
  onLostPointerCapture: cellEnabled ? loseCreateCapture : void 0,
3081
3292
  onClick: cellEnabled ? (e) => tapCell(e, dayIndex) : void 0,
3082
3293
  ...dataState({
3083
- "data-today": getIsToday(day),
3294
+ "data-today": getIsToday(day, todayDate),
3084
3295
  "data-weekend": isWeekend(day)
3085
3296
  }),
3086
3297
  ...slot("dayColumn", {
@@ -3168,7 +3379,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3168
3379
  }),
3169
3380
  positioned.map((pe, idx) => {
3170
3381
  const key = `${dayIndex}:${idx}`;
3171
- const active = !paged && drag?.key === key && (!multiDayMove || pe.event === movingEvent) ? drag : null;
3382
+ const active = !paged && drag?.key === key && (!multiDayHeld || pe.event === movingEvent) ? drag : null;
3172
3383
  const hiddenForMove = !!multiDayMove && pe.event === movingEvent;
3173
3384
  const startHours = active ? active.startHours : pe.startHours;
3174
3385
  const durationHours = active ? active.durationHours : pe.durationHours;
@@ -3176,9 +3387,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3176
3387
  const top = (startHours - windowStart) * hourHeight;
3177
3388
  const boxHeight = Math.max(Math.min(durationHours, HOURS_PER_DAY - startHours) * hourHeight, minEventHeight);
3178
3389
  const widthPct = 100 / pe.columns;
3390
+ const floating = active?.kind === "move" && active.moved;
3179
3391
  const onPress = () => onPressEvent?.(pe.event);
3180
3392
  const args = {
3181
- event: pe.event,
3393
+ event: active ? withLiveBounds(pe.event) : pe.event,
3182
3394
  mode,
3183
3395
  isAllDay: false,
3184
3396
  boxHeight,
@@ -3213,8 +3425,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3213
3425
  position: "absolute",
3214
3426
  top,
3215
3427
  height: boxHeight,
3216
- left: `calc(${pe.column * widthPct}% + ${eventGap}px)`,
3217
- width: `calc(${widthPct}% - ${eventGap * 2}px)`,
3428
+ left: floating ? eventGap : `calc(${pe.column * widthPct}% + ${eventGap}px)`,
3429
+ width: floating ? `calc(100% - ${eventGap * 2}px)` : `calc(${widthPct}% - ${eventGap * 2}px)`,
3218
3430
  cursor: canMove ? "grab" : "pointer",
3219
3431
  touchAction: canMove ? "pan-y" : "auto",
3220
3432
  userSelect: canMove ? "none" : void 0,
@@ -3342,7 +3554,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
3342
3554
  position: "absolute",
3343
3555
  left: eventGap,
3344
3556
  right: eventGap,
3345
- ...createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
3557
+ ...createRange ? createRangePlacement(createRange, day, hourHeight, windowStart, totalHeight, minEventHeight) : createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
3346
3558
  boxSizing: "border-box",
3347
3559
  ...ghostRange ? { overflow: "hidden" } : null,
3348
3560
  opacity: .7,
@@ -3454,12 +3666,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3454
3666
  const displayEvents = useMemo(() => {
3455
3667
  let out = events ?? EMPTY_EVENTS;
3456
3668
  if (out.some((e) => e.recurrence)) {
3457
- let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
3458
- if (timeZone) {
3459
- start = addDays(start, -1);
3460
- end = addDays(end, 1);
3461
- }
3462
- out = expandRecurringEvents$1(out, start, end);
3669
+ const [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
3670
+ out = timeZone ? expandRecurringEvents$1(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), { timeZone }) : expandRecurringEvents$1(out, start, end);
3463
3671
  }
3464
3672
  if (timeZone) out = eventsInTimeZone(out, timeZone);
3465
3673
  return out;
@@ -3472,6 +3680,42 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3472
3680
  numberOfWeeks,
3473
3681
  timeZone
3474
3682
  ]);
3683
+ const timeGridMode = mode !== "month" && mode !== "multiweek";
3684
+ const zoned = useMemo(() => {
3685
+ if (!timeZone) return {
3686
+ onPressEvent,
3687
+ onDragStart,
3688
+ onDragEvent,
3689
+ onPressMore,
3690
+ onPressTime: onPressCell,
3691
+ onCreateTimed: onCreateEvent
3692
+ };
3693
+ const instant = (wallClock) => fromZonedTime(wallClock, timeZone);
3694
+ return {
3695
+ onPressEvent: onPressEvent && ((event) => onPressEvent(zonedEventSource(event))),
3696
+ onDragStart: onDragStart && ((event) => onDragStart(zonedEventSource(event))),
3697
+ onDragEvent: onDragEvent && ((event, start, end) => {
3698
+ const bounds = zonedDragBounds(event, start, end, { keepDuration: timeGridMode });
3699
+ if (!bounds) return false;
3700
+ return onDragEvent(zonedEventSource(event), bounds.start, bounds.end);
3701
+ }),
3702
+ onPressMore: onPressMore && ((dayEvents, day) => onPressMore(dayEvents.map(zonedEventSource), day)),
3703
+ onPressTime: onPressCell && ((time) => onPressCell(instant(time))),
3704
+ onCreateTimed: onCreateEvent && ((start, end) => {
3705
+ const range = fromZonedRange(start, end, timeZone);
3706
+ if (range) onCreateEvent(range.start, range.end);
3707
+ })
3708
+ };
3709
+ }, [
3710
+ timeZone,
3711
+ timeGridMode,
3712
+ onPressEvent,
3713
+ onDragStart,
3714
+ onDragEvent,
3715
+ onPressMore,
3716
+ onPressCell,
3717
+ onCreateEvent
3718
+ ]);
3475
3719
  const handlePageKeys = (e) => {
3476
3720
  if (!onChangeDate) return;
3477
3721
  if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays, numberOfWeeks));
@@ -3486,6 +3730,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3486
3730
  weekStartsOn,
3487
3731
  hiddenDays,
3488
3732
  locale,
3733
+ now,
3734
+ timeZone,
3489
3735
  labels,
3490
3736
  theme,
3491
3737
  className,
@@ -3508,6 +3754,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3508
3754
  else if (mode === "schedule") view = /* @__PURE__ */ jsx(Agenda, {
3509
3755
  events: displayEvents,
3510
3756
  locale,
3757
+ now,
3758
+ timeZone,
3511
3759
  ampm,
3512
3760
  theme,
3513
3761
  height,
@@ -3518,7 +3766,7 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3518
3766
  styles,
3519
3767
  renderEvent: renderScheduleEvent,
3520
3768
  eventAccessibilityLabel,
3521
- onPressEvent,
3769
+ onPressEvent: zoned.onPressEvent,
3522
3770
  onPressDay
3523
3771
  });
3524
3772
  else if (mode === "month") view = /* @__PURE__ */ jsx(MonthView, {
@@ -3529,6 +3777,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3529
3777
  weekdayFormat,
3530
3778
  highlightWeekends,
3531
3779
  locale,
3780
+ now,
3781
+ timeZone,
3532
3782
  labels,
3533
3783
  theme,
3534
3784
  className,
@@ -3551,13 +3801,14 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3551
3801
  onPressDay,
3552
3802
  onPressCell,
3553
3803
  onCreateEvent,
3804
+ renderCreateGhost,
3554
3805
  onSelectDrag,
3555
- onDragEvent,
3556
- onDragStart,
3806
+ onDragEvent: zoned.onDragEvent,
3807
+ onDragStart: zoned.onDragStart,
3557
3808
  eventStartEditable,
3558
3809
  eventOverlap,
3559
- onPressEvent,
3560
- onPressMore,
3810
+ onPressEvent: zoned.onPressEvent,
3811
+ onPressMore: zoned.onPressMore,
3561
3812
  renderEvent: renderMonthEvent,
3562
3813
  eventAccessibilityLabel
3563
3814
  });
@@ -3570,6 +3821,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3570
3821
  weekdayFormat,
3571
3822
  highlightWeekends,
3572
3823
  locale,
3824
+ now,
3825
+ timeZone,
3573
3826
  labels,
3574
3827
  theme,
3575
3828
  className,
@@ -3594,13 +3847,14 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3594
3847
  onPressDay,
3595
3848
  onPressCell,
3596
3849
  onCreateEvent,
3850
+ renderCreateGhost,
3597
3851
  onSelectDrag,
3598
- onDragEvent,
3599
- onDragStart,
3852
+ onDragEvent: zoned.onDragEvent,
3853
+ onDragStart: zoned.onDragStart,
3600
3854
  eventStartEditable,
3601
3855
  eventOverlap,
3602
- onPressEvent,
3603
- onPressMore,
3856
+ onPressEvent: zoned.onPressEvent,
3857
+ onPressMore: zoned.onPressMore,
3604
3858
  renderEvent: renderMonthEvent,
3605
3859
  eventAccessibilityLabel
3606
3860
  });
@@ -3647,12 +3901,12 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
3647
3901
  dragStepMinutes,
3648
3902
  touchDragDelay,
3649
3903
  touchDragThreshold,
3650
- onPressEvent,
3651
- onPressCell,
3652
- onCreateEvent,
3904
+ onPressEvent: zoned.onPressEvent,
3905
+ onPressCell: zoned.onPressTime,
3906
+ onCreateEvent: zoned.onCreateTimed,
3653
3907
  renderCreateGhost,
3654
- onDragStart,
3655
- onDragEvent,
3908
+ onDragStart: zoned.onDragStart,
3909
+ onDragEvent: zoned.onDragEvent,
3656
3910
  getEventId,
3657
3911
  onChangeDate,
3658
3912
  onPressDateHeader,