@super-calendar/solid 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/src/TimeGrid.tsx CHANGED
@@ -17,12 +17,14 @@ import {
17
17
  eventTimeLabel,
18
18
  formatHour,
19
19
  getIsToday,
20
+ nowInTimeZone,
20
21
  getViewDays,
21
22
  isAllDayEvent,
22
23
  isBackgroundEvent,
23
24
  isSameCalendarDay,
24
25
  isWeekend,
25
26
  layoutDayEvents,
27
+ layoutMonthWeek,
26
28
  movedClockSpan,
27
29
  overlapsOtherEvents,
28
30
  pageStepDays,
@@ -114,7 +116,7 @@ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v
114
116
  const sameRange = (a: CreateGhostArgs | null, b: CreateGhostArgs | null) =>
115
117
  a === b ||
116
118
  (!!a && !!b && a.start.getTime() === b.start.getTime() && a.end.getTime() === b.end.getTime());
117
- // Floor for the create-by-drag preview, so a press shows a line before it moves.
119
+ // Keep an empty or fully clipped preview visible at the column edge.
118
120
  const CREATE_PREVIEW_MIN_HEIGHT = 2;
119
121
  // Vertical placement of the create preview inside a day column `gridHeight` px
120
122
  // tall. Both ends are clamped to the visible hours. The preview is anchored to
@@ -130,6 +132,26 @@ function createPreviewPlacement(topPx: number, heightPx: number, gridHeight: num
130
132
  : { top, height };
131
133
  }
132
134
 
135
+ function createRangePlacement(
136
+ range: CreateGhostArgs,
137
+ day: Date,
138
+ hourHeight: number,
139
+ minHour: number,
140
+ gridHeight: number,
141
+ minEventHeight: number,
142
+ ) {
143
+ // Use wall-clock positions, including midnight on the following day. Elapsed
144
+ // milliseconds would shift the preview on daylight-saving transitions.
145
+ const at = (time: Date) =>
146
+ (differenceInCalendarDays(time, day) * 24 +
147
+ time.getHours() +
148
+ time.getMinutes() / 60 -
149
+ minHour) *
150
+ hourHeight;
151
+ const top = at(range.start);
152
+ return createPreviewPlacement(top, Math.max(minEventHeight, at(range.end) - top), gridHeight);
153
+ }
154
+
133
155
  // Edge auto-advance: how close to the day-columns edge (px) counts as "at the
134
156
  // edge", how long to dwell there before paging, and the repeat interval while
135
157
  // the pointer stays in the zone.
@@ -155,7 +177,12 @@ const VISUALLY_HIDDEN: CSSProperties = {
155
177
 
156
178
  /** Props passed to a custom time-grid event renderer. */
157
179
  export interface SolidRenderEventArgs<T = unknown> {
158
- /** The event to render. */
180
+ /**
181
+ * The event to render. While it is being moved or resized, a copy whose
182
+ * `start` and `end` are the times `onDragEvent` would report on release.
183
+ * After a drag pages the view, the floating preview keeps the stored times
184
+ * until release.
185
+ */
159
186
  event: CalendarEvent<T>;
160
187
  /** The current view mode. */
161
188
  mode: CalendarMode;
@@ -163,9 +190,9 @@ export interface SolidRenderEventArgs<T = unknown> {
163
190
  isAllDay: boolean;
164
191
  /** Pixel height of the event box (timed events only). */
165
192
  boxHeight?: number;
166
- /** The event started before the visible day and continues into it. */
193
+ /** Starts before the visible day (timed) or visible date range (all-day). */
167
194
  continuesBefore?: boolean;
168
- /** The event continues past the visible day. */
195
+ /** Ends after the visible day (timed) or visible date range (all-day). */
169
196
  continuesAfter?: boolean;
170
197
  /** Show the time range in 12-hour AM/PM. */
171
198
  ampm?: boolean;
@@ -253,9 +280,15 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
253
280
  renderBackgroundEvent?: SolidRenderEvent<T>;
254
281
  /** Show the current-time indicator on today's column (default true). */
255
282
  showNowIndicator?: boolean;
256
- /** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
283
+ /**
284
+ * Fixed "now" instant for the indicator (doesn't tick) and for the day
285
+ * highlighted as today. Defaults to the device clock.
286
+ */
257
287
  now?: Date;
258
- /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
288
+ /**
289
+ * Shift the now indicator and the day highlighted as today into this IANA zone
290
+ * (pair with `eventsInTimeZone`).
291
+ */
259
292
  timeZone?: string;
260
293
  /** Show the all-day lane above the grid (default true). */
261
294
  showAllDayEventCell?: boolean;
@@ -323,7 +356,7 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
323
356
  * Return `false` to reject the drop (the event snaps back).
324
357
  */
325
358
  onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
326
- /** Stable, unique event identity for the web editing dialog across data refreshes. */
359
+ /** Stable, unique identity for the editing dialog and all-day bars across data refreshes. */
327
360
  getEventId?: (event: CalendarEvent<T>) => string | number;
328
361
  /**
329
362
  * Page the grid to a new anchor date. Supplying it alongside `onDragEvent`
@@ -389,6 +422,40 @@ function movedSegmentStart(
389
422
  dayMinutes + Math.round((startHours - origin.startHours) * 60),
390
423
  );
391
424
  }
425
+ // The start and end a drag reports. A bottom resize re-resolves the end from the
426
+ // edge the layout drew, like the native renderer, so it lands on the row the edge
427
+ // reached on either side of a DST change. A move or a top resize shifts the real
428
+ // instants by how far the segment moved on `base`, the day it lands on, so a
429
+ // move that now spans midnight keeps the parts outside the dragged day. The drop
430
+ // and the live preview share it, so the renderer shows what the drop reports.
431
+ function draggedEventBounds(
432
+ d: DragState,
433
+ origin: { startHours: number; durationHours: number; segmentStart: Date; base: Date },
434
+ event: { start: Date; end: Date },
435
+ base: Date,
436
+ snapMinutes: number,
437
+ ): { start: Date; end: Date } | null {
438
+ if (d.kind === "resize") {
439
+ const endDelta = Math.round(
440
+ (d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60,
441
+ );
442
+ return resolveDraggedBounds(event.start, event.end, 0, endDelta, snapMinutes);
443
+ }
444
+ const segmentStart = movedSegmentStart(
445
+ origin,
446
+ base,
447
+ d.kind === "move" ? d.requestedStartHours : d.startHours,
448
+ );
449
+ const startShift = segmentStart.getTime() - origin.segmentStart.getTime();
450
+ const endShift = d.kind === "move" ? startShift : 0;
451
+ const start = new Date(event.start.getTime() + startShift);
452
+ const end = new Date(event.end.getTime() + endShift);
453
+ // A move keeps the event's duration, so it commits even when that is zero.
454
+ return end > start || (d.kind === "move" && end.getTime() === start.getTime())
455
+ ? { start, end }
456
+ : null;
457
+ }
458
+
392
459
  function DefaultDomEvent<T>(
393
460
  incoming: SolidRenderEventArgs<T> & {
394
461
  theme: SolidCalendarTheme;
@@ -669,6 +736,7 @@ export function TimeGrid<T = unknown>(
669
736
  } | null>(null);
670
737
  const createOrigin: ElementRef<{
671
738
  pointerId: number;
739
+ captureLoss?: ReturnType<typeof setTimeout>;
672
740
  clientY: number;
673
741
  el: HTMLElement;
674
742
  dayIndex: number;
@@ -695,6 +763,7 @@ export function TimeGrid<T = unknown>(
695
763
  return () => window.removeEventListener("scroll", onScroll, true);
696
764
  },
697
765
  );
766
+ const detachCreateListeners: ElementRef<(() => void) | null> = { current: null };
698
767
  // Touch never sweeps, so a tap presses the cell from its click, which the
699
768
  // browser skips when the finger scrolled the grid instead.
700
769
  const cellTouchRef: ElementRef<{
@@ -716,6 +785,14 @@ export function TimeGrid<T = unknown>(
716
785
  props.hiddenDays,
717
786
  ),
718
787
  );
788
+ // The day the headers and columns mark as today: the indicator's clock while
789
+ // it runs, so the two can't disagree. `now` stops ticking with the indicator
790
+ // off, so the clock is read afresh then, and again when the days change.
791
+ const todayKey = createMemo(() => {
792
+ if (props.showNowIndicator) return startOfDay(now()).getTime();
793
+ void days();
794
+ return startOfDay(nowInTimeZone(props.now, props.timeZone)).getTime();
795
+ });
719
796
 
720
797
  // Edge auto-advance. During a move drag the pointer stream is handled at the
721
798
  // document level (attached in beginDrag) so it survives the day columns
@@ -774,6 +851,7 @@ export function TimeGrid<T = unknown>(
774
851
  move: (e: PointerEvent) => void;
775
852
  up: (e: PointerEvent) => void;
776
853
  cancel: (e: PointerEvent) => void;
854
+ preventNative: (e: Event) => void;
777
855
  } | null> = {
778
856
  current: null,
779
857
  };
@@ -840,6 +918,11 @@ export function TimeGrid<T = unknown>(
840
918
  canResize: editable && (event.durationEditable ?? props.eventDurationEditable),
841
919
  };
842
920
  };
921
+ const hasEditActions = (event: CalendarEvent<T>) => {
922
+ if (isAllDayEvent(event) || isBackgroundEvent(event)) return false;
923
+ const { canMove, canResize } = editability(event);
924
+ return canMove || canResize;
925
+ };
843
926
  const eventLabel = (event: CalendarEvent<T>) =>
844
927
  props.eventAccessibilityLabel
845
928
  ? props.eventAccessibilityLabel(event, {
@@ -859,8 +942,9 @@ export function TimeGrid<T = unknown>(
859
942
  `${describeEventDates(event)}, ${eventLabel(event)}`;
860
943
  // The actions dialog's steps, matching the native screen-reader actions: one
861
944
  // snap step, or one page of days, through the same commit path as a drop.
862
- const pageDays = () =>
863
- pageStepDays(props.mode, props.date, props.weekStartsOn, props.numberOfDays);
945
+ const pageDays = createMemo(() =>
946
+ pageStepDays(props.mode, props.date, props.weekStartsOn, props.numberOfDays),
947
+ );
864
948
  const actionDelta = (id: string): [number, number] | null => {
865
949
  const step = snapMinutes();
866
950
  const page = pageDays() * HOURS_PER_DAY * 60;
@@ -882,7 +966,7 @@ export function TimeGrid<T = unknown>(
882
966
  }
883
967
  };
884
968
  const editActions = (event: CalendarEvent<T>): EventEditAction[] => {
885
- if (isAllDayEvent(event) || isBackgroundEvent(event)) return [];
969
+ if (!hasEditActions(event)) return [];
886
970
  const { canMove, canResize } = editability(event);
887
971
  const step = snapMinutes();
888
972
  const words = labels();
@@ -925,19 +1009,40 @@ export function TimeGrid<T = unknown>(
925
1009
  },
926
1010
  () => props.getEventId,
927
1011
  );
928
- const allDayByDay = createMemo(
929
- // A multi-day all-day event shows in every column it overlaps (matching the
930
- // native AllDayLane), not just its start day.
931
- () =>
932
- days().map((day) => {
933
- const dayStart = startOfDay(day);
934
- const dayEnd = addDays(dayStart, 1);
935
- return props.events.filter(
936
- (e) => isAllDayEvent(e) && !isBackgroundEvent(e) && e.start < dayEnd && e.end > dayStart,
937
- );
938
- }),
1012
+ const allDayLayout = createMemo(() =>
1013
+ layoutMonthWeek(
1014
+ days(),
1015
+ props.events.filter(
1016
+ (event) =>
1017
+ isAllDayEvent(event) &&
1018
+ !isBackgroundEvent(event) &&
1019
+ days().some(
1020
+ (day) => event.start < addDays(startOfDay(day), 1) && event.end > startOfDay(day),
1021
+ ),
1022
+ ),
1023
+ ),
939
1024
  );
940
- const hasAllDay = createMemo(() => allDayByDay().some((list) => list.length > 0));
1025
+ const hasAllDay = createMemo(() => allDayLayout().segments.length > 0);
1026
+ const allDaySpans = createMemo(() => {
1027
+ const keys = new Map<CalendarEvent<T>, string>();
1028
+ const seen = new Map<string, CalendarEvent<T>>();
1029
+ for (const { event } of allDayLayout().segments) {
1030
+ const id = props.getEventId?.(event);
1031
+ if (typeof id !== "string" && typeof id !== "number") continue;
1032
+ const key = `${typeof id}:${id}`;
1033
+ const previous = seen.get(key);
1034
+ if (previous) keys.delete(previous);
1035
+ else {
1036
+ seen.set(key, event);
1037
+ keys.set(event, key);
1038
+ }
1039
+ }
1040
+ return allDayLayout().segments.map((segment) => ({
1041
+ ...segment,
1042
+ key: keys.get(segment.event) ?? segment.event,
1043
+ }));
1044
+ });
1045
+
941
1046
  createEffect(
942
1047
  () => [props.scrollOffsetMinutes, windowStart()],
943
1048
  () =>
@@ -1100,6 +1205,8 @@ export function TimeGrid<T = unknown>(
1100
1205
  document.removeEventListener("pointermove", h.move);
1101
1206
  document.removeEventListener("pointerup", h.up);
1102
1207
  document.removeEventListener("pointercancel", h.cancel);
1208
+ document.removeEventListener("selectstart", h.preventNative, true);
1209
+ document.removeEventListener("dragstart", h.preventNative, true);
1103
1210
  docHandlersRef.current = null;
1104
1211
  };
1105
1212
  const finishDrag = () => {
@@ -1283,37 +1390,16 @@ export function TimeGrid<T = unknown>(
1283
1390
  } else {
1284
1391
  base = startOfDay(daysRef.current[originIndex] ?? daysRef.current[0]);
1285
1392
  }
1286
- if (held && origin && d.kind === "resize") {
1287
- // Resolve the end like the native renderer, from the edge the layout drew,
1288
- // so it lands at the row the edge was dragged to on either side of a DST
1289
- // change.
1290
- const endDelta = Math.round(
1291
- (d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60,
1292
- );
1293
- const next = resolveDraggedBounds(
1294
- held.event.start,
1295
- held.event.end,
1296
- 0,
1297
- endDelta,
1298
- snapMinutes(),
1299
- );
1300
- if (next) onDragEventRef.current?.(held.event, next.start, next.end);
1301
- } else if (base && held && origin) {
1302
- // Shift the real event by how far its segment moved, so a move that now
1303
- // spans midnight (and every later drag of the resulting multi-day event)
1304
- // keeps the parts outside the dragged day instead of clipping to it.
1305
- const segmentStart = movedSegmentStart(
1306
- origin,
1307
- base,
1308
- d.kind === "move" ? d.requestedStartHours : d.startHours,
1309
- );
1310
- const startShift = segmentStart.getTime() - origin.segmentStart.getTime();
1311
- const endShift = d.kind === "move" ? startShift : 0;
1312
- const start = new Date(held.event.start.getTime() + startShift);
1313
- const end = new Date(held.event.end.getTime() + endShift);
1314
- if (end > start) onDragEventRef.current?.(held.event, start, end);
1393
+ try {
1394
+ if (base && held && origin) {
1395
+ const next = draggedEventBounds(d, origin, held.event, base, snapMinutes());
1396
+ if (next) onDragEventRef.current?.(held.event, next.start, next.end);
1397
+ }
1398
+ } finally {
1399
+ // A handler that throws must not leave the drag and its document listeners,
1400
+ // which block native selection, in place.
1401
+ finishDrag();
1315
1402
  }
1316
- finishDrag();
1317
1403
  };
1318
1404
  const cancelDrag = () => {
1319
1405
  finishDrag();
@@ -1343,7 +1429,8 @@ export function TimeGrid<T = unknown>(
1343
1429
  // across days, so 0 is fine there.
1344
1430
  const boxEl = e.box;
1345
1431
  const column = kind === "move" ? boxEl.parentElement : null;
1346
- const dayWidth = column ? column.getBoundingClientRect().width : 0;
1432
+ const columnRect = column ? column.getBoundingClientRect() : null;
1433
+ const dayWidth = columnRect ? columnRect.width : 0;
1347
1434
  const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
1348
1435
  const originBase = startOfDay(days()[dayIndex] ?? days()[0]);
1349
1436
  const originNextDay = addDays(originBase, 1);
@@ -1365,9 +1452,13 @@ export function TimeGrid<T = unknown>(
1365
1452
  draggedRef.current = {
1366
1453
  event,
1367
1454
  onPress: onPress ?? (() => {}),
1368
- grabX: boxRect ? e.clientX - boxRect.left : 0,
1455
+ // A moved box spans its whole day column, so the ghost that replaces it
1456
+ // after a page change keeps that width and the pointer's place in it. The
1457
+ // box sits in the column's padding box, inside any border.
1458
+ grabX:
1459
+ column && columnRect ? e.clientX - columnRect.left - column.clientLeft - props.eventGap : 0,
1369
1460
  grabY: boxRect ? e.clientY - boxRect.top : 0,
1370
- w: boxRect ? boxRect.width : 0,
1461
+ w: column ? Math.max(column.clientWidth - props.eventGap * 2, 0) : 0,
1371
1462
  h: boxRect ? boxRect.height : 0,
1372
1463
  };
1373
1464
  ptr.current = {
@@ -1413,11 +1504,16 @@ export function TimeGrid<T = unknown>(
1413
1504
  cancelDrag();
1414
1505
  }
1415
1506
  },
1507
+ // Text selected by an earlier drag can turn this one into a native text
1508
+ // drag, after which the browser stops sending pointer events (WebKit).
1509
+ preventNative: (event: Event) => event.preventDefault(),
1416
1510
  };
1417
1511
  docHandlersRef.current = handlers;
1418
1512
  document.addEventListener("pointermove", handlers.move);
1419
1513
  document.addEventListener("pointerup", handlers.up);
1420
1514
  document.addEventListener("pointercancel", handlers.cancel);
1515
+ document.addEventListener("selectstart", handlers.preventNative, true);
1516
+ document.addEventListener("dragstart", handlers.preventNative, true);
1421
1517
  };
1422
1518
  const pressEvent = (
1423
1519
  e: DomPointerEvent<HTMLElement>,
@@ -1474,6 +1570,11 @@ export function TimeGrid<T = unknown>(
1474
1570
  cancelHoldRef.current?.();
1475
1571
  detachDocListeners();
1476
1572
  clearEdgeTimer();
1573
+ if (createOrigin.current?.captureLoss !== undefined)
1574
+ clearTimeout(createOrigin.current.captureLoss);
1575
+ createOrigin.current = null;
1576
+ detachCreateListeners.current?.();
1577
+ detachCreateListeners.current = null;
1477
1578
  }),
1478
1579
  );
1479
1580
  createEffect(
@@ -1520,6 +1621,36 @@ export function TimeGrid<T = unknown>(
1520
1621
  startPx,
1521
1622
  curPx: startPx,
1522
1623
  });
1624
+ // Capture can be lost before pointerup. Observe release outside the column
1625
+ // too, without depending on the preview having rendered yet.
1626
+ const document = el.ownerDocument;
1627
+ const cancel = (event: PointerEvent) => {
1628
+ if (createOrigin.current?.pointerId === event.pointerId) clearCreate();
1629
+ };
1630
+ const restart = (event: PointerEvent) => {
1631
+ if (
1632
+ (event.isPrimary && event.pointerType !== "touch") ||
1633
+ createOrigin.current?.pointerId === event.pointerId
1634
+ )
1635
+ clearCreate();
1636
+ };
1637
+ // Text selected during a sweep can turn the next sweep into a native drag,
1638
+ // which cancels pointer input before the calendar receives its release.
1639
+ const preventSelection = (event: Event) => event.preventDefault();
1640
+ // If capture failed and release happened outside the window, the next press
1641
+ // belongs to a new gesture and must not complete the old one.
1642
+ document.addEventListener("pointerup", endCreate, true);
1643
+ document.addEventListener("pointercancel", cancel, true);
1644
+ document.addEventListener("pointerdown", restart, true);
1645
+ document.addEventListener("selectstart", preventSelection, true);
1646
+ document.addEventListener("dragstart", preventSelection, true);
1647
+ detachCreateListeners.current = () => {
1648
+ document.removeEventListener("pointerup", endCreate, true);
1649
+ document.removeEventListener("pointercancel", cancel, true);
1650
+ document.removeEventListener("pointerdown", restart, true);
1651
+ document.removeEventListener("selectstart", preventSelection, true);
1652
+ document.removeEventListener("dragstart", preventSelection, true);
1653
+ };
1523
1654
  };
1524
1655
  const moveCreate = (e: DomPointerEvent) => {
1525
1656
  const touch = cellTouchRef.current;
@@ -1540,14 +1671,17 @@ export function TimeGrid<T = unknown>(
1540
1671
  curPx: pxFromTop(o.el, e.clientY),
1541
1672
  });
1542
1673
  };
1543
- const endCreate = (e: DomPointerEvent) => {
1674
+ const endCreate = (e: Pick<PointerEvent, "pointerId" | "clientY">) => {
1544
1675
  const o = createOrigin.current;
1545
1676
  if (!o || o.pointerId !== e.pointerId) return;
1546
- try {
1547
- o.el.releasePointerCapture?.(e.pointerId);
1548
- } catch {
1549
- // Best-effort release.
1550
- }
1677
+ clearCreate();
1678
+ if (
1679
+ !o.el.isConnected ||
1680
+ !cellEnabled() ||
1681
+ (o.creating && !props.onCreateEvent) ||
1682
+ days()[o.dayIndex]?.getTime() !== o.dayTime
1683
+ )
1684
+ return;
1551
1685
  const endPx = pxFromTop(o.el, e.clientY);
1552
1686
  const day = days()[o.dayIndex];
1553
1687
  const moved = Math.abs(endPx - o.startPx) > 4;
@@ -1559,8 +1693,6 @@ export function TimeGrid<T = unknown>(
1559
1693
  const at = cellRangeFromDrag(day, o.startPx, o.startPx, h, windowStart(), snapMinutes());
1560
1694
  if (at) props.onPressCell(at.start);
1561
1695
  }
1562
- createOrigin.current = null;
1563
- setCreateBox(null);
1564
1696
  };
1565
1697
  const tapCell = (e: DomMouseEvent<HTMLDivElement>, dayIndex: number) => {
1566
1698
  const touch = cellTouchRef.current;
@@ -1580,6 +1712,9 @@ export function TimeGrid<T = unknown>(
1580
1712
  const clearCreate = () => {
1581
1713
  const previous = createOrigin.current;
1582
1714
  createOrigin.current = null;
1715
+ if (previous?.captureLoss !== undefined) clearTimeout(previous.captureLoss);
1716
+ detachCreateListeners.current?.();
1717
+ detachCreateListeners.current = null;
1583
1718
  setCreateBox(null);
1584
1719
  try {
1585
1720
  previous?.el.releasePointerCapture?.(previous.pointerId);
@@ -1605,11 +1740,15 @@ export function TimeGrid<T = unknown>(
1605
1740
  if (createOrigin.current?.pointerId !== e.pointerId) return;
1606
1741
  clearCreate();
1607
1742
  };
1608
- // Without capture the column stops seeing the sweep's moves and release, so
1609
- // drop it. Leaves `cellTouchRef` alone: touch taps resolve on the later click.
1743
+ // Capture loss can precede pointerup with either button state. Give release
1744
+ // the rest of this event task to complete, then cancel any remaining sweep.
1610
1745
  const loseCreateCapture = (e: DomPointerEvent) => {
1611
- if (createOrigin.current?.pointerId !== e.pointerId) return;
1612
- clearCreate();
1746
+ const origin = createOrigin.current;
1747
+ if (!origin || origin.pointerId !== e.pointerId) return;
1748
+ if (origin.captureLoss !== undefined) clearTimeout(origin.captureLoss);
1749
+ origin.captureLoss = setTimeout(() => {
1750
+ if (createOrigin.current === origin) clearCreate();
1751
+ }, 0);
1613
1752
  };
1614
1753
  // Pointer capture does not move keyboard focus to the grid.
1615
1754
  createEffect(
@@ -1651,12 +1790,27 @@ export function TimeGrid<T = unknown>(
1651
1790
  }) ?? currentHeldEvent))
1652
1791
  );
1653
1792
  });
1793
+ // A held multi-day event, moved or not. The active box must also be the held
1794
+ // event, because an events refresh can give its `day:index` key to another
1795
+ // event, even before the pointer moves.
1796
+ const multiDayHeld = createMemo(() => {
1797
+ const currentDrag = drag();
1798
+ return (
1799
+ !paged() &&
1800
+ currentDrag?.kind === "move" &&
1801
+ (currentDrag.continuesBefore || currentDrag.continuesAfter) &&
1802
+ !!movingEvent()
1803
+ );
1804
+ });
1654
1805
  const multiDayMove = createMemo(() => {
1655
1806
  const currentDrag = drag();
1656
1807
  const currentMoveOrigin = moveOrigin();
1657
1808
  const currentMovingEvent = movingEvent();
1809
+ // Only once the pointer has moved: a press that may still be a click keeps
1810
+ // the segments in their shared columns instead of swapping in the preview.
1658
1811
  return !paged() &&
1659
1812
  currentDrag?.kind === "move" &&
1813
+ currentDrag.moved &&
1660
1814
  (currentDrag.continuesBefore || currentDrag.continuesAfter) &&
1661
1815
  currentMoveOrigin &&
1662
1816
  currentMovingEvent
@@ -1678,6 +1832,24 @@ export function TimeGrid<T = unknown>(
1678
1832
  : null;
1679
1833
  });
1680
1834
 
1835
+ // Where a single-day drag would land if released now, for the renderer of the
1836
+ // dragged box and its spill. The multi-day preview carries its own shifted
1837
+ // event, and a paged drag resolves its day only on release.
1838
+ const liveBounds = createMemo(() => {
1839
+ const currentDrag = drag();
1840
+ const origin = moveOrigin();
1841
+ const held = draggedRef.current;
1842
+ if (paged() || !currentDrag?.moved || multiDayMove() || !origin || !held) return null;
1843
+ const visibleDays = days();
1844
+ const target = origin.dayIndex + (currentDrag.kind === "move" ? currentDrag.dayDelta : 0);
1845
+ const base = startOfDay(visibleDays[target] ?? visibleDays[origin.dayIndex]);
1846
+ return draggedEventBounds(currentDrag, origin, held.event, base, snapMinutes());
1847
+ });
1848
+ const withLiveBounds = (event: CalendarEvent<T>): CalendarEvent<T> => {
1849
+ const bounds = liveBounds();
1850
+ return bounds ? { ...event, start: bounds.start, end: bounds.end } : event;
1851
+ };
1852
+
1681
1853
  // The tail of an in-progress move that runs past midnight, shown on `dayIndex`
1682
1854
  // so the drop is visible on both days at once. `drag` and `draggedRef` are set
1683
1855
  // together in `beginDrag` and cleared together in `finishDrag`, so the guard on
@@ -1694,7 +1866,7 @@ export function TimeGrid<T = unknown>(
1694
1866
  const dragged = draggedRef.current?.event;
1695
1867
  if (!dragged) return null;
1696
1868
  return {
1697
- event: dragged,
1869
+ event: withLiveBounds(dragged),
1698
1870
  mode: props.mode,
1699
1871
  isAllDay: false,
1700
1872
  boxHeight: Math.max(currentDrag.spillHours * hourHeight(), props.minEventHeight),
@@ -1840,7 +2012,7 @@ export function TimeGrid<T = unknown>(
1840
2012
  )
1841
2013
  .map((pe) => pe.event),
1842
2014
  ),
1843
- ].filter((event) => editActions(event).length > 0)}
2015
+ ].filter(hasEditActions)}
1844
2016
  label={labels().editEvents}
1845
2017
  labelFor={(event) => labels().eventActions(event.title ?? "")}
1846
2018
  descriptionFor={eventDescription}
@@ -1886,7 +2058,7 @@ export function TimeGrid<T = unknown>(
1886
2058
  {
1887
2059
  <For each={days()} keyed={false}>
1888
2060
  {(day) => {
1889
- const today = createMemo(() => getIsToday(day()));
2061
+ const today = createMemo(() => getIsToday(day(), new Date(todayKey())));
1890
2062
  // Full, unambiguous date for assistive tech; the visible weekday + day
1891
2063
  // number below are decorative (aria-hidden) so it isn't read twice.
1892
2064
  const dateLabel = createMemo(() => format(day(), "EEEE, d MMMM yyyy", dfns()));
@@ -2003,6 +2175,7 @@ export function TimeGrid<T = unknown>(
2003
2175
  base: {
2004
2176
  width: gutterWidth(),
2005
2177
  flex: "none",
2178
+ boxSizing: "border-box",
2006
2179
  minWidth: 0,
2007
2180
  overflow: "hidden",
2008
2181
  textAlign: "right",
@@ -2010,98 +2183,89 @@ export function TimeGrid<T = unknown>(
2010
2183
  themed: {
2011
2184
  fontSize: 10,
2012
2185
  color: theme().textMuted,
2013
- padding: "4px 6px 0 0",
2186
+ padding: props.hideHours ? 0 : "4px 6px 0 0",
2014
2187
  },
2015
2188
  })}
2016
2189
  >
2017
2190
  {props.showAllDayLabel ? labels().allDay : null}
2018
2191
  </div>
2019
- {
2020
- <For each={allDayByDay()} keyed={false}>
2021
- {(list, i) => {
2022
- const dayStart = createMemo(() => startOfDay(days()[i]));
2023
- const dayEnd = createMemo(() => addDays(dayStart(), 1));
2192
+ <div
2193
+ style={css({
2194
+ flex: 1,
2195
+ minWidth: 0,
2196
+ display: "grid",
2197
+ gridTemplateColumns: `repeat(${days().length}, minmax(0, 1fr))`,
2198
+ gap: "2px 0",
2199
+ padding: "2px 0",
2200
+ })}
2201
+ >
2202
+ <For each={allDaySpans()} keyed={(segment) => segment.key}>
2203
+ {(segment) => {
2204
+ const args = createMemo<SolidRenderEventArgs<T>>(() => ({
2205
+ event: segment().event,
2206
+ mode: props.mode,
2207
+ isAllDay: true,
2208
+ continuesBefore: segment().continuesBefore,
2209
+ continuesAfter: segment().continuesAfter,
2210
+ ampm: props.ampm,
2211
+ onPress: () => props.onPressEvent?.(segment().event),
2212
+ }));
2024
2213
  return (
2025
2214
  <div
2026
2215
  {...slot("allDayColumn", {
2027
2216
  base: {
2028
- flex: 1,
2217
+ gridColumn: `${segment().startCol + 1} / span ${segment().endCol - segment().startCol + 1}`,
2218
+ gridRow: segment().lane + 1,
2029
2219
  minWidth: 0,
2030
- // Mirror the day column's geometry so the all-day chip lines up
2031
- // exactly with the timed events below it: a 1px left border (the
2032
- // grid line, transparent here) plus a 1px horizontal inset.
2220
+ // Match the timed columns' grid line and horizontal inset.
2033
2221
  borderLeft: "1px solid transparent",
2034
- padding: "2px 1px",
2222
+ padding: "0 1px",
2035
2223
  display: "flex",
2036
2224
  flexDirection: "column",
2037
- gap: 2,
2038
2225
  },
2039
2226
  })}
2040
2227
  >
2041
- {
2042
- <For each={list()} keyed={false}>
2043
- {(event) => {
2044
- const args = createMemo<SolidRenderEventArgs<T>>(() => ({
2045
- event: event(),
2046
- mode: props.mode,
2047
- isAllDay: true,
2048
- // Whether this all-day event continues into the previous/next
2049
- // column, so custom renderers can draw continuation affordances.
2050
- continuesBefore: event().start < dayStart(),
2051
- continuesAfter: event().end > dayEnd(),
2052
- ampm: props.ampm,
2053
- onPress: () => props.onPressEvent?.(event()),
2054
- }));
2055
- return (
2056
- <button
2057
- type="button"
2058
- onClick={() => props.onPressEvent?.(event())}
2059
- aria-label={
2060
- props.eventAccessibilityLabel
2061
- ? props.eventAccessibilityLabel(event(), {
2062
- mode: props.mode,
2063
- isAllDay: true,
2064
- ampm: props.ampm,
2065
- })
2066
- : defaultEventAccessibilityLabel({
2067
- title: event().title,
2068
- isAllDay: true,
2069
- start: event().start,
2070
- end: event().end,
2071
- ampm: props.ampm,
2072
- labels: labels(),
2073
- })
2074
- }
2075
- {...slot("allDayEvent", {
2076
- base: {
2077
- border: "none",
2078
- padding: 0,
2079
- background: "transparent",
2080
- cursor: "pointer",
2081
- textAlign: "left",
2082
- height: 22,
2083
- },
2084
- })}
2085
- >
2086
- {Renderer() ? (
2087
- <Dynamic component={Renderer()} {...args()} />
2088
- ) : (
2089
- <DefaultDomEvent
2090
- {...args()}
2091
- theme={theme()}
2092
- boxProps={slot("eventBox")}
2093
- />
2094
- )}
2095
- </button>
2096
- );
2097
- }}
2098
- </For>
2099
- }
2228
+ <button
2229
+ type="button"
2230
+ onClick={() => props.onPressEvent?.(segment().event)}
2231
+ aria-label={
2232
+ props.eventAccessibilityLabel
2233
+ ? props.eventAccessibilityLabel(segment().event, {
2234
+ mode: props.mode,
2235
+ isAllDay: true,
2236
+ ampm: props.ampm,
2237
+ })
2238
+ : defaultEventAccessibilityLabel({
2239
+ title: segment().event.title,
2240
+ isAllDay: true,
2241
+ start: segment().event.start,
2242
+ end: segment().event.end,
2243
+ ampm: props.ampm,
2244
+ labels: labels(),
2245
+ })
2246
+ }
2247
+ {...slot("allDayEvent", {
2248
+ base: {
2249
+ border: "none",
2250
+ padding: 0,
2251
+ background: "transparent",
2252
+ cursor: "pointer",
2253
+ textAlign: "left",
2254
+ height: 22,
2255
+ },
2256
+ })}
2257
+ >
2258
+ {Renderer() ? (
2259
+ <Dynamic component={Renderer()} {...args()} />
2260
+ ) : (
2261
+ <DefaultDomEvent {...args()} theme={theme()} boxProps={slot("eventBox")} />
2262
+ )}
2263
+ </button>
2100
2264
  </div>
2101
2265
  );
2102
2266
  }}
2103
2267
  </For>
2104
- }
2268
+ </div>
2105
2269
  </div>
2106
2270
  ) : null}
2107
2271
 
@@ -2196,10 +2360,10 @@ export function TimeGrid<T = unknown>(
2196
2360
  });
2197
2361
  // What `onCreateEvent` would receive if the sweep ended here. Kept
2198
2362
  // while the range holds, so content updates only when it changes.
2199
- const ghostRange = createMemo(
2363
+ const createRange = createMemo(
2200
2364
  () => {
2201
2365
  const currentGhost = ghost();
2202
- return currentGhost && props.renderCreateGhost && props.onCreateEvent
2366
+ return currentGhost && props.onCreateEvent
2203
2367
  ? cellRangeFromDrag(
2204
2368
  day(),
2205
2369
  currentGhost.startPx,
@@ -2212,6 +2376,29 @@ export function TimeGrid<T = unknown>(
2212
2376
  },
2213
2377
  { equals: sameRange },
2214
2378
  );
2379
+ const ghostRange = createMemo(() =>
2380
+ props.renderCreateGhost ? createRange() : null,
2381
+ );
2382
+ const previewPlacement = createMemo(() => {
2383
+ const range = createRange();
2384
+ if (range)
2385
+ return createRangePlacement(
2386
+ range,
2387
+ day(),
2388
+ hourHeight(),
2389
+ windowStart(),
2390
+ totalHeight(),
2391
+ props.minEventHeight ?? DEFAULT_MIN_EVENT_HEIGHT,
2392
+ );
2393
+ const current = ghost();
2394
+ return current
2395
+ ? createPreviewPlacement(
2396
+ Math.min(current.startPx, current.curPx),
2397
+ Math.abs(current.curPx - current.startPx),
2398
+ totalHeight(),
2399
+ )
2400
+ : {};
2401
+ });
2215
2402
  // The tail of a move that runs past midnight, previewed at the top of
2216
2403
  // this column. The dragged event is looked up from its `drag.key`
2217
2404
  // ("<originColumn>:<index>"), so no extra state has to track it.
@@ -2236,7 +2423,7 @@ export function TimeGrid<T = unknown>(
2236
2423
  onLostPointerCapture={cellEnabled() ? loseCreateCapture : undefined}
2237
2424
  onClick={cellEnabled() ? (e) => tapCell(e, dayIndex) : undefined}
2238
2425
  {...dataState({
2239
- "data-today": getIsToday(day()),
2426
+ "data-today": getIsToday(day(), new Date(todayKey())),
2240
2427
  "data-weekend": isWeekend(day()),
2241
2428
  })}
2242
2429
  {...slot("dayColumn", {
@@ -2376,10 +2563,18 @@ export function TimeGrid<T = unknown>(
2376
2563
  const currentDrag = drag();
2377
2564
  return !paged() &&
2378
2565
  currentDrag?.key === key() &&
2379
- (!multiDayMove() || pe().event === movingEvent())
2566
+ (!multiDayHeld() || pe().event === movingEvent())
2380
2567
  ? currentDrag
2381
2568
  : null;
2382
2569
  });
2570
+ // A moved event floats across its whole day column, like the
2571
+ // multi-day preview, so a narrow overlapping event shows its
2572
+ // full content while carried. A press or a resize keeps the
2573
+ // shared column.
2574
+ const floating = createMemo(() => {
2575
+ const currentActive = active();
2576
+ return currentActive?.kind === "move" && currentActive.moved;
2577
+ });
2383
2578
  const hiddenForMove = createMemo(
2384
2579
  () => !!multiDayMove() && pe().event === movingEvent(),
2385
2580
  );
@@ -2420,7 +2615,7 @@ export function TimeGrid<T = unknown>(
2420
2615
  const widthPct = createMemo(() => 100 / pe().columns);
2421
2616
  const onPress = () => props.onPressEvent?.(pe().event);
2422
2617
  const args = createMemo<SolidRenderEventArgs<T>>(() => ({
2423
- event: pe().event,
2618
+ event: active() ? withLiveBounds(pe().event) : pe().event,
2424
2619
  mode: props.mode,
2425
2620
  isAllDay: false,
2426
2621
  boxHeight: boxHeight(),
@@ -2499,8 +2694,12 @@ export function TimeGrid<T = unknown>(
2499
2694
  // is the renderer's concern: the built-in one clamps, and a
2500
2695
  // custom renderer should adapt to the `boxHeight` it's given.
2501
2696
  height: boxHeight(),
2502
- left: `calc(${pe().column * widthPct()}% + ${props.eventGap}px)`,
2503
- width: `calc(${widthPct()}% - ${props.eventGap * 2}px)`,
2697
+ left: floating()
2698
+ ? props.eventGap
2699
+ : `calc(${pe().column * widthPct()}% + ${props.eventGap}px)`,
2700
+ width: floating()
2701
+ ? `calc(100% - ${props.eventGap * 2}px)`
2702
+ : `calc(${widthPct()}% - ${props.eventGap * 2}px)`,
2504
2703
  cursor: canMove() ? "grab" : "pointer",
2505
2704
  touchAction: canMove() ? "pan-y" : "auto",
2506
2705
  userSelect: canMove() ? "none" : undefined,
@@ -2718,7 +2917,7 @@ export function TimeGrid<T = unknown>(
2718
2917
  ) : null}
2719
2918
  {
2720
2919
  <Show when={ghost()}>
2721
- {(ghost) => (
2920
+ {(_ghost) => (
2722
2921
  <div
2723
2922
  aria-hidden="true"
2724
2923
  // Custom content stays out of the tab order and pointer input.
@@ -2728,11 +2927,7 @@ export function TimeGrid<T = unknown>(
2728
2927
  position: "absolute",
2729
2928
  left: props.eventGap,
2730
2929
  right: props.eventGap,
2731
- ...createPreviewPlacement(
2732
- Math.min(ghost().startPx, ghost().curPx),
2733
- Math.abs(ghost().curPx - ghost().startPx),
2734
- totalHeight(),
2735
- ),
2930
+ ...previewPlacement(),
2736
2931
  // Borders, including custom ones, stay inside the placed box.
2737
2932
  boxSizing: "border-box",
2738
2933
  ...(ghostRange() ? { overflow: "hidden" } : null),