@super-calendar/dom 2.8.1 → 2.9.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.js CHANGED
@@ -241,12 +241,56 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
241
241
  * highlighted and a dot under days that hold events. It's the view `Calendar`
242
242
  * renders for `mode="year"`.
243
243
  */
244
- function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDate, minMonthWidth = 150, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }) {
244
+ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, theme: themeOverrides, className, style, classNames, styles }) {
245
245
  const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
246
246
  const slot = createSlots({
247
247
  classNames,
248
248
  styles
249
249
  });
250
+ const sweepEnabled = onSelectDrag != null || onCreateEvent != null;
251
+ const [creating, setCreating] = (0, react.useState)(null);
252
+ const creatingRef = (0, react.useRef)(creating);
253
+ creatingRef.current = creating;
254
+ const movedRef = (0, react.useRef)(false);
255
+ const suppressClickRef = (0, react.useRef)(false);
256
+ const beginPress = () => {
257
+ suppressClickRef.current = false;
258
+ movedRef.current = false;
259
+ };
260
+ const beginCreate = (day) => {
261
+ const t = (0, date_fns.startOfDay)(day).getTime();
262
+ setCreating({
263
+ anchor: t,
264
+ hover: t
265
+ });
266
+ };
267
+ const extendCreate = (day) => {
268
+ const current = creatingRef.current;
269
+ if (!current) return;
270
+ const t = (0, date_fns.startOfDay)(day).getTime();
271
+ if (t === current.hover) return;
272
+ movedRef.current = true;
273
+ setCreating((c) => c ? {
274
+ ...c,
275
+ hover: t
276
+ } : c);
277
+ const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
278
+ onSelectDrag?.(new Date(lo), new Date(hi));
279
+ };
280
+ const isCreating = creating !== null;
281
+ (0, react.useEffect)(() => {
282
+ if (!isCreating) return;
283
+ const finish = () => {
284
+ const c = creatingRef.current;
285
+ setCreating(null);
286
+ if (!c || !movedRef.current) return;
287
+ suppressClickRef.current = true;
288
+ const range = (0, _super_calendar_core.monthCreateRange)(new Date(c.anchor), new Date(c.hover));
289
+ onCreateEvent?.(range.start, range.end);
290
+ };
291
+ window.addEventListener("pointerup", finish);
292
+ return () => window.removeEventListener("pointerup", finish);
293
+ }, [isCreating, onCreateEvent]);
250
294
  const months = (0, react.useMemo)(() => (0, _super_calendar_core.getYearMonths)(date), [date]);
251
295
  const weekdayLabels = (0, react.useMemo)(() => (0, _super_calendar_core.filterHiddenDays)((0, _super_calendar_core.getWeekDays)(date, weekStartsOn), hiddenDays).map((d) => (0, date_fns.format)(d, (0, _super_calendar_core.weekdayFormatToken)("narrow"), { locale })), [
252
296
  date,
@@ -343,9 +387,21 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDa
343
387
  "aria-hidden": true,
344
388
  style: { aspectRatio: "1" }
345
389
  }, day.toISOString());
346
- const isHighlighted = activeDate ? (0, _super_calendar_core.isSameCalendarDay)(day, activeDate) : (0, _super_calendar_core.getIsToday)(day);
390
+ const isToday = (0, _super_calendar_core.getIsToday)(day);
391
+ const isHighlighted = activeDate ? (0, _super_calendar_core.isSameCalendarDay)(day, activeDate) : isToday;
347
392
  const hasEvents = eventDays.has((0, date_fns.startOfDay)(day).toISOString());
348
- const label = `${(0, date_fns.format)(day, "EEEE, d LLLL yyyy", { locale })}${(0, _super_calendar_core.getIsToday)(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
393
+ const state = (0, _super_calendar_core.daySelectionState)(day, {
394
+ selectedDates,
395
+ selectedRange
396
+ }, {
397
+ minDate,
398
+ maxDate,
399
+ isDateDisabled
400
+ });
401
+ const dayTime = (0, date_fns.startOfDay)(day).getTime();
402
+ const inCreate = creating != null && dayTime >= Math.min(creating.anchor, creating.hover) && dayTime <= Math.max(creating.anchor, creating.hover);
403
+ const label = `${(0, date_fns.format)(day, "EEEE, d LLLL yyyy", { locale })}${isToday ? ", today" : ""}${state.isSelected ? ", selected" : ""}${state.isDisabled ? ", unavailable" : ""}${hasEvents ? ", has events" : ""}`;
404
+ const badge = (0, _super_calendar_core.dayBadgeKind)(state, isHighlighted);
349
405
  const daySlot = slot("day", {
350
406
  base: {
351
407
  position: "relative",
@@ -357,21 +413,40 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDa
357
413
  border: "none",
358
414
  background: "transparent",
359
415
  font: "inherit",
360
- cursor: onPressDay ? "pointer" : "default",
361
- boxSizing: "border-box"
416
+ cursor: state.isDisabled ? "default" : onPressDay || sweepEnabled ? "pointer" : "default",
417
+ boxSizing: "border-box",
418
+ ...sweepEnabled ? { touchAction: "pan-y" } : null
362
419
  },
363
420
  themed: {
364
421
  fontSize: 11,
365
- borderRadius: "50%",
366
- ...isHighlighted ? {
367
- background: theme.todayBackground,
368
- color: theme.todayText
369
- } : { color: theme.text }
422
+ color: state.isDisabled ? theme.textDisabled : theme.text
370
423
  }
371
424
  });
372
425
  const states = dataState({
373
- "data-today": (0, _super_calendar_core.getIsToday)(day),
374
- "data-events": hasEvents
426
+ "data-today": isToday,
427
+ "data-events": hasEvents,
428
+ "data-selected": state.isSelected,
429
+ "data-range": state.isInRange,
430
+ "data-disabled": state.isDisabled,
431
+ "data-creating": inCreate
432
+ });
433
+ const bandKind = (0, _super_calendar_core.rangeBandKind)(state, true);
434
+ const rounding = (0, _super_calendar_core.bandRounding)((0, _super_calendar_core.rangeBandKind)(state, false));
435
+ const band = bandKind === "none" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
436
+ "data-band": true,
437
+ "aria-hidden": true,
438
+ ...slot("rangeBand", {
439
+ base: {
440
+ position: "absolute",
441
+ inset: 0,
442
+ zIndex: 0,
443
+ borderTopLeftRadius: rounding.start ? "50%" : 0,
444
+ borderBottomLeftRadius: rounding.start ? "50%" : 0,
445
+ borderTopRightRadius: rounding.end ? "50%" : 0,
446
+ borderBottomRightRadius: rounding.end ? "50%" : 0
447
+ },
448
+ themed: { background: theme.rangeBackground }
449
+ })
375
450
  });
376
451
  const dot = hasEvents ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
377
452
  "aria-hidden": true,
@@ -381,27 +456,77 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, activeDa
381
456
  bottom: 1,
382
457
  left: "50%",
383
458
  marginLeft: -1.5,
459
+ zIndex: 2,
384
460
  width: 3,
385
461
  height: 3,
386
462
  borderRadius: 2
387
463
  },
388
- themed: { background: isHighlighted ? theme.todayText : theme.todayBackground }
464
+ themed: { background: badge === "none" ? theme.todayBackground : theme.todayText }
389
465
  })
390
466
  }) : null;
391
- return onPressDay ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
467
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
468
+ band,
469
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
470
+ ...slot("dayBadge", {
471
+ base: {
472
+ position: "relative",
473
+ zIndex: 1,
474
+ width: "100%",
475
+ height: "100%",
476
+ borderRadius: "50%",
477
+ display: "flex",
478
+ alignItems: "center",
479
+ justifyContent: "center"
480
+ },
481
+ themed: badge === "today" ? {
482
+ background: theme.todayBackground,
483
+ color: theme.todayText
484
+ } : badge === "selected" ? {
485
+ background: theme.selectedBackground,
486
+ color: theme.selectedText
487
+ } : {}
488
+ }),
489
+ children: day.getDate()
490
+ }),
491
+ dot
492
+ ] });
493
+ const sweepHandlers = sweepEnabled ? {
494
+ onPointerDown: (e) => {
495
+ beginPress();
496
+ if (e.button === 0 && !state.isDisabled) beginCreate(day);
497
+ },
498
+ onPointerEnter: state.isDisabled ? void 0 : () => extendCreate(day)
499
+ } : null;
500
+ return onPressDay ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
392
501
  type: "button",
393
502
  role: "gridcell",
394
- onClick: () => onPressDay(day),
503
+ disabled: state.isDisabled,
395
504
  "aria-label": label,
505
+ onClick: () => {
506
+ if (suppressClickRef.current) {
507
+ suppressClickRef.current = false;
508
+ return;
509
+ }
510
+ onPressDay(day);
511
+ },
512
+ ...sweepHandlers,
396
513
  ...states,
397
514
  ...daySlot,
398
- children: [day.getDate(), dot]
399
- }, day.toISOString()) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
515
+ children: content
516
+ }, day.toISOString()) : sweepEnabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
400
517
  role: "gridcell",
518
+ "aria-disabled": state.isDisabled || void 0,
401
519
  "aria-label": label,
520
+ ...sweepHandlers,
402
521
  ...states,
403
522
  ...daySlot,
404
- children: [day.getDate(), dot]
523
+ children: content
524
+ }, day.toISOString()) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
525
+ role: "gridcell",
526
+ "aria-label": label,
527
+ ...states,
528
+ ...daySlot,
529
+ children: content
405
530
  }, day.toISOString());
406
531
  })
407
532
  }, week[0].toISOString()))
@@ -422,6 +547,7 @@ const DATE_ROW = 24;
422
547
  const CHIP_HEIGHT = 18;
423
548
  const CHIP_GAP = 2;
424
549
  const CELL_PAD = 4;
550
+ const DRAGGED_CHIP_OPACITY = .4;
425
551
  function dayCellDefault(day, theme, highlightWeekends) {
426
552
  return {
427
553
  base: {
@@ -448,21 +574,27 @@ function dayCellDefault(day, theme, highlightWeekends) {
448
574
  * rounded strip (the default) or fill the whole cell (`fillCell`). Returns null
449
575
  * for days with no band. Endpoints get the leading/trailing pill rounding. Its
450
576
  * geometry is structural; only the fill colour is themed.
577
+ *
578
+ * In events mode the strip tracks the compact date badge instead of the picker's
579
+ * tall cell, so it reads as a band across the dates rather than a block over the
580
+ * event chips (and matches the native renderer's month grid).
451
581
  */
452
- function rangeBandDefault(day, theme, fillCell) {
582
+ function rangeBandDefault(day, theme, fillCell, eventsMode) {
453
583
  const kind = (0, _super_calendar_core.rangeBandKind)(day, fillCell);
454
584
  if (kind === "none") return null;
455
585
  const fill = kind === "fill";
456
- const inset = fill ? 0 : Math.max(0, (theme.cellHeight - theme.rangeBandHeight) / 2);
457
- const radius = fill ? 0 : theme.rangeBandHeight / 2;
586
+ const badgeSize = eventsMode ? DATE_ROW - 2 : theme.dayBadgeSize;
587
+ const bandHeight = eventsMode ? badgeSize : theme.rangeBandHeight;
588
+ const inset = fill ? 0 : eventsMode ? CELL_PAD : Math.max(0, (theme.cellHeight - bandHeight) / 2);
589
+ const radius = fill ? 0 : bandHeight / 2;
458
590
  const rounding = (0, _super_calendar_core.bandRounding)(kind);
459
- const cap = `calc(50% - ${theme.dayBadgeSize / 2}px)`;
591
+ const cap = eventsMode ? 0 : `calc(50% - ${badgeSize / 2}px)`;
460
592
  const base = {
461
593
  position: "absolute",
462
594
  left: rounding.start ? cap : 0,
463
595
  right: rounding.end ? cap : 0,
464
596
  top: inset,
465
- bottom: inset,
597
+ ...fill || !eventsMode ? { bottom: inset } : { height: bandHeight },
466
598
  zIndex: 0
467
599
  };
468
600
  if (rounding.start) {
@@ -499,7 +631,7 @@ function badgeDefault(day, theme, hovered) {
499
631
  }
500
632
  };
501
633
  }
502
- function eventCellDefault(day, theme, height, highlightWeekends) {
634
+ function eventCellDefault(day, theme, height, highlightWeekends, isDragTarget) {
503
635
  return {
504
636
  base: {
505
637
  position: "relative",
@@ -517,7 +649,7 @@ function eventCellDefault(day, theme, height, highlightWeekends) {
517
649
  },
518
650
  themed: {
519
651
  borderTop: `1px solid ${theme.gridLine}`,
520
- background: highlightWeekends && day.isWeekend && !day.isInRange ? theme.weekendBackground : "transparent",
652
+ background: isDragTarget ? theme.rangeBackground : highlightWeekends && day.isWeekend && !day.isInRange ? theme.weekendBackground : "transparent",
521
653
  color: day.isDisabled ? theme.textDisabled : theme.text
522
654
  }
523
655
  };
@@ -617,7 +749,7 @@ function collectRowEvents(week, eventsByDay) {
617
749
  * <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
618
750
  * ```
619
751
  */
620
- function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, highlightWeekends = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onCreateEvent, keyboardDayNavigation = false, className, style, classNames, styles }) {
752
+ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, 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 }) {
621
753
  const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
622
754
  const slot = createSlots({
623
755
  classNames,
@@ -707,46 +839,87 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
707
839
  const [hoveredKey, setHoveredKey] = (0, react.useState)(null);
708
840
  const gridRef = (0, react.useRef)(null);
709
841
  const focusKey = (0, date_fns.format)(focusedDate, "yyyy-MM-dd");
710
- const [creating, setCreating] = (0, react.useState)(null);
711
- const creatingRef = (0, react.useRef)(creating);
712
- creatingRef.current = creating;
842
+ const [drag, setDrag] = (0, react.useState)(null);
843
+ const dragRef = (0, react.useRef)(drag);
844
+ dragRef.current = drag;
713
845
  const movedRef = (0, react.useRef)(false);
714
846
  const suppressClickRef = (0, react.useRef)(false);
847
+ const consumeSuppressedClick = () => {
848
+ if (!suppressClickRef.current) return false;
849
+ suppressClickRef.current = false;
850
+ return true;
851
+ };
852
+ const canMove = (event) => onDragEvent != null && !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable);
853
+ const beginPress = () => {
854
+ suppressClickRef.current = false;
855
+ movedRef.current = false;
856
+ };
715
857
  const beginCreate = (day) => {
716
- if (!onCreateEvent) return;
858
+ if (!onCreateEvent && !onSelectDrag) return;
717
859
  const t = (0, date_fns.startOfDay)(day).getTime();
718
- movedRef.current = false;
719
- setCreating({
860
+ setDrag({
861
+ kind: "create",
720
862
  anchor: t,
721
863
  hover: t
722
864
  });
723
865
  };
724
- const extendCreate = (day) => {
725
- if (!creatingRef.current) return;
866
+ const beginMove = (event, day) => {
867
+ if (!canMove(event)) return;
726
868
  const t = (0, date_fns.startOfDay)(day).getTime();
727
- if (t !== creatingRef.current.hover) {
728
- movedRef.current = true;
729
- setCreating((c) => c ? {
730
- ...c,
731
- hover: t
732
- } : c);
869
+ setDrag({
870
+ kind: "move",
871
+ event,
872
+ from: t,
873
+ to: t
874
+ });
875
+ onDragStart?.(event);
876
+ };
877
+ const extendDrag = (day) => {
878
+ const current = dragRef.current;
879
+ if (!current) return;
880
+ const t = (0, date_fns.startOfDay)(day).getTime();
881
+ if (t === (current.kind === "create" ? current.hover : current.to)) return;
882
+ movedRef.current = true;
883
+ setDrag(current.kind === "create" ? {
884
+ ...current,
885
+ hover: t
886
+ } : {
887
+ ...current,
888
+ to: t
889
+ });
890
+ if (current.kind === "create") {
891
+ const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
892
+ onSelectDrag?.(new Date(lo), new Date(hi));
733
893
  }
734
894
  };
735
- const isCreating = creating !== null;
895
+ const isDragging = drag !== null;
896
+ const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
736
897
  (0, react.useEffect)(() => {
737
- if (!isCreating) return;
898
+ if (!isDragging) return;
738
899
  const finish = () => {
739
- const c = creatingRef.current;
740
- setCreating(null);
741
- if (!c || !movedRef.current) return;
900
+ const current = dragRef.current;
901
+ setDrag(null);
902
+ if (!current || !movedRef.current) return;
742
903
  suppressClickRef.current = true;
743
- const lo = Math.min(c.anchor, c.hover);
744
- const hi = Math.max(c.anchor, c.hover);
745
- onCreateEvent?.(new Date(lo), (0, date_fns.addDays)(new Date(hi), 1));
904
+ if (current.kind === "create") {
905
+ const range = (0, _super_calendar_core.monthCreateRange)(new Date(current.anchor), new Date(current.hover));
906
+ onCreateEvent?.(range.start, range.end);
907
+ return;
908
+ }
909
+ const next = (0, _super_calendar_core.monthDropBounds)(current.event, new Date(current.from), new Date(current.to));
910
+ if (!next) return;
911
+ if (eventOverlap === false && (0, _super_calendar_core.overlapsOtherEvents)(events ?? [], current.event, next.start, next.end)) return;
912
+ onDragEvent?.(current.event, next.start, next.end);
746
913
  };
747
914
  window.addEventListener("pointerup", finish);
748
915
  return () => window.removeEventListener("pointerup", finish);
749
- }, [isCreating, onCreateEvent]);
916
+ }, [
917
+ isDragging,
918
+ onCreateEvent,
919
+ onDragEvent,
920
+ eventOverlap,
921
+ events
922
+ ]);
750
923
  const onKeyDown = (e) => {
751
924
  let next = null;
752
925
  if (e.key === "ArrowLeft") next = (0, date_fns.addDays)(focusedDate, -1);
@@ -846,10 +1019,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
846
1019
  "aria-hidden": true,
847
1020
  style: { height: cellHeight }
848
1021
  }, day.id);
849
- const band = rangeBandDefault(day, theme, fillCellOnSelection);
1022
+ const band = rangeBandDefault(day, theme, fillCellOnSelection, eventsMode);
850
1023
  const label = (0, date_fns.format)(day.date, "EEEE, d MMMM yyyy", locale ? { locale } : void 0);
851
1024
  const dayTime = (0, date_fns.startOfDay)(day.date).getTime();
852
- const inCreate = creating != null && dayTime >= Math.min(creating.anchor, creating.hover) && dayTime <= Math.max(creating.anchor, creating.hover);
1025
+ const inCreate = drag?.kind === "create" && dayTime >= Math.min(drag.anchor, drag.hover) && dayTime <= Math.max(drag.anchor, drag.hover);
1026
+ const isDropTarget = drag?.kind === "move" && dayTime === drag.to && drag.to !== drag.from;
853
1027
  const dayData = dataState({
854
1028
  "data-today": day.isToday,
855
1029
  "data-selected": day.isSelected,
@@ -857,13 +1031,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
857
1031
  "data-weekend": day.isWeekend,
858
1032
  "data-outside": !day.isCurrentMonth,
859
1033
  "data-disabled": day.isDisabled,
860
- "data-creating": inCreate
1034
+ "data-creating": inCreate,
1035
+ "data-drop": isDropTarget
861
1036
  });
862
1037
  if (eventsMode) {
863
1038
  const dayEvents = eventsByDay.get((0, date_fns.startOfDay)(day.date).toISOString()) ?? [];
864
1039
  const hiddenEvents = rowLayout.segments.filter((s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes).map((s) => s.event);
865
1040
  const dayLabel = (0, date_fns.format)(day.date, "d MMMM", locale ? { locale } : void 0);
866
- const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight, highlightWeekends));
1041
+ const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight, highlightWeekends, inCreate || isDropTarget));
867
1042
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
868
1043
  role: "gridcell",
869
1044
  "data-day": day.id,
@@ -872,26 +1047,28 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
872
1047
  "aria-disabled": day.isDisabled || void 0,
873
1048
  "aria-label": label,
874
1049
  ...dayCellProps,
875
- style: onCreateEvent ? {
1050
+ style: dragWired ? {
876
1051
  ...dayCellProps.style,
877
- touchAction: "none"
1052
+ touchAction: "none",
1053
+ userSelect: "none"
878
1054
  } : dayCellProps.style,
879
- onPointerDown: onCreateEvent && !day.isDisabled ? (e) => {
880
- if (e.button === 0) beginCreate(day.date);
1055
+ onPointerDown: dragWired && !day.isDisabled ? (e) => {
1056
+ if (e.button !== 0) return;
1057
+ beginPress();
1058
+ beginCreate(day.date);
881
1059
  } : void 0,
882
- onPointerEnter: onCreateEvent ? () => extendCreate(day.date) : void 0,
1060
+ onPointerEnter: dragWired && !day.isDisabled ? () => extendDrag(day.date) : void 0,
883
1061
  onClick: day.isDisabled ? void 0 : () => {
884
- if (suppressClickRef.current) {
885
- suppressClickRef.current = false;
886
- return;
887
- }
1062
+ if (consumeSuppressedClick()) return;
888
1063
  onPressDay?.(day.date);
1064
+ onPressCell?.((0, date_fns.startOfDay)(day.date));
889
1065
  },
890
1066
  onKeyDown: keyboardDayNavigation && !day.isDisabled ? (e) => {
891
1067
  if (e.target !== e.currentTarget) return;
892
1068
  if (e.key === "Enter" || e.key === " ") {
893
1069
  e.preventDefault();
894
1070
  onPressDay?.(day.date);
1071
+ onPressCell?.((0, date_fns.startOfDay)(day.date));
895
1072
  }
896
1073
  } : void 0,
897
1074
  children: [
@@ -907,10 +1084,18 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
907
1084
  }),
908
1085
  barSegs.filter((b) => b.startCol === dayCol).map((b) => {
909
1086
  const span = b.endCol - b.startCol + 1;
1087
+ const isDragged = drag?.kind === "move" && drag.event === b.seg.event;
910
1088
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
911
1089
  type: "button",
1090
+ onPointerDown: canMove(b.seg.event) ? (e) => {
1091
+ if (e.button !== 0) return;
1092
+ e.stopPropagation();
1093
+ beginPress();
1094
+ beginMove(b.seg.event, day.date);
1095
+ } : void 0,
912
1096
  onClick: (e) => {
913
1097
  e.stopPropagation();
1098
+ if (consumeSuppressedClick()) return;
914
1099
  onPressEvent?.(b.seg.event);
915
1100
  },
916
1101
  ...barChipButton,
@@ -927,7 +1112,10 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
927
1112
  width: `calc(${span * 100}% - 4px)`,
928
1113
  top: 30 + b.seg.lane * 20,
929
1114
  height: CHIP_HEIGHT,
930
- pointerEvents: isCreating ? "none" : "auto",
1115
+ pointerEvents: isDragging ? "none" : "auto",
1116
+ opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
1117
+ cursor: canMove(b.seg.event) ? "grab" : void 0,
1118
+ touchAction: dragWired ? "none" : void 0,
931
1119
  zIndex: 2
932
1120
  },
933
1121
  children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
@@ -1064,7 +1252,10 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1064
1252
  "aria-label": label,
1065
1253
  "aria-pressed": day.isSelected || day.isInRange,
1066
1254
  ...slot("day", dayCellDefault(day, theme, highlightWeekends)),
1067
- onClick: day.isDisabled ? void 0 : () => onPressDay?.(day.date),
1255
+ onClick: day.isDisabled ? void 0 : () => {
1256
+ onPressDay?.(day.date);
1257
+ onPressCell?.((0, date_fns.startOfDay)(day.date));
1258
+ },
1068
1259
  onMouseEnter: day.isDisabled ? void 0 : () => setHoveredKey(day.id),
1069
1260
  onMouseLeave: () => setHoveredKey((k) => k === day.id ? null : k),
1070
1261
  children: [band ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -1087,6 +1278,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1087
1278
  //#endregion
1088
1279
  //#region src/TimeGrid.tsx
1089
1280
  const GUTTER_WIDTH$1 = 56;
1281
+ const HOURS_PER_DAY = 24;
1090
1282
  const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
1091
1283
  const EDGE_ZONE = 32;
1092
1284
  const EDGE_DWELL_MS = 600;
@@ -1192,7 +1384,8 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1192
1384
  });
1193
1385
  const scrollRef = (0, react.useRef)(null);
1194
1386
  const dfns = locale ? { locale } : void 0;
1195
- const snapHours = dragStepMinutes / 60;
1387
+ const snapMinutes = Math.max(1, dragStepMinutes);
1388
+ const snapHours = snapMinutes / 60;
1196
1389
  const windowStart = Math.max(0, Math.min(minHour, 23));
1197
1390
  const windowEnd = Math.max(windowStart + 1, Math.min(maxHour, 24));
1198
1391
  const windowHours = windowEnd - windowStart;
@@ -1355,15 +1548,22 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1355
1548
  const dHours = (e.clientY - dragOrigin.current.pointerY) / hourHeightRef.current;
1356
1549
  const snap = (v) => Math.round(v / snapHours) * snapHours;
1357
1550
  if (d.kind === "move") {
1358
- const startHours = clamp$1(snap(dragOrigin.current.startHours + dHours), windowStart, Math.max(windowStart, windowEnd - d.durationHours));
1551
+ const raw = snap(dragOrigin.current.startHours + dHours);
1552
+ const startHours = d.continuesBefore ? raw : (0, _super_calendar_core.clampMoveStartMinutes)(raw * 60, windowStart, windowEnd, snapMinutes) / 60;
1359
1553
  const o = dragOrigin.current;
1360
1554
  const rawDayDelta = o.dayWidth > 0 ? Math.round((e.clientX - o.pointerX) / o.dayWidth) : 0;
1361
- const dayDelta = clamp$1(o.dayIndex + rawDayDelta, 0, daysRef.current.length - 1) - o.dayIndex;
1555
+ const targetDay = clamp$1(o.dayIndex + rawDayDelta, 0, daysRef.current.length - 1);
1556
+ const dayDelta = targetDay - o.dayIndex;
1557
+ const spillHours = Math.min(Math.max(startHours + d.durationHours - HOURS_PER_DAY, 0), windowHours);
1558
+ const nextDay = daysRef.current[targetDay + 1];
1559
+ const spillDayIndex = spillHours > 0 && nextDay && (0, date_fns.differenceInCalendarDays)(nextDay, daysRef.current[targetDay]) === 1 && !d.continuesAfter ? targetDay + 1 : -1;
1362
1560
  applyDrag({
1363
1561
  ...d,
1364
1562
  startHours,
1365
1563
  dayDelta,
1366
1564
  dayOffsetPx: dayDelta * o.dayWidth,
1565
+ spillHours,
1566
+ spillDayIndex,
1367
1567
  moved: true
1368
1568
  });
1369
1569
  const g = ghostRef.current;
@@ -1412,25 +1612,31 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1412
1612
  held?.onPress();
1413
1613
  return;
1414
1614
  }
1415
- const originIndex = dragOrigin.current?.dayIndex ?? 0;
1615
+ const origin = dragOrigin.current;
1616
+ const originIndex = origin?.dayIndex ?? 0;
1416
1617
  let base = null;
1417
1618
  if (d.kind === "move") if (pagedRef.current) {
1418
1619
  const day = dayAt(e.clientX, e.clientY);
1419
1620
  base = day ? (0, date_fns.startOfDay)(day) : null;
1420
1621
  } else base = (0, date_fns.startOfDay)(daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex]);
1421
1622
  else base = (0, date_fns.startOfDay)(daysRef.current[originIndex] ?? daysRef.current[0]);
1422
- if (base && held) {
1423
- const start = (0, date_fns.addMinutes)(base, Math.round(d.startHours * 60));
1424
- const end = (0, date_fns.addMinutes)(base, Math.round((d.startHours + d.durationHours) * 60));
1425
- onDragEventRef.current?.(held.event, start, end);
1623
+ if (base && held && origin) {
1624
+ const segmentStart = (0, date_fns.addMinutes)(base, Math.round(d.startHours * 60));
1625
+ const segmentEnd = (0, date_fns.addMinutes)(base, Math.round((d.startHours + d.durationHours) * 60));
1626
+ const startShift = d.kind === "resize" ? 0 : segmentStart.getTime() - origin.segmentStart.getTime();
1627
+ const endShift = d.kind === "resize-start" ? 0 : segmentEnd.getTime() - origin.segmentEnd.getTime();
1628
+ const start = new Date(held.event.start.getTime() + startShift);
1629
+ const end = new Date(held.event.end.getTime() + endShift);
1630
+ if (end > start) onDragEventRef.current?.(held.event, start, end);
1426
1631
  }
1427
1632
  finishDrag();
1428
1633
  };
1429
1634
  const cancelDrag = () => {
1430
1635
  finishDrag();
1431
1636
  };
1432
- const beginDrag = (e, event, key, kind, startHours, durationHours, dayIndex, onPress) => {
1637
+ const beginDrag = (e, pe, key, kind, dayIndex, onPress) => {
1433
1638
  if (!onDragEvent) return;
1639
+ const { event, startHours, durationHours, continuesBefore, continuesAfter } = pe;
1434
1640
  e.stopPropagation();
1435
1641
  try {
1436
1642
  e.target.setPointerCapture?.(e.pointerId);
@@ -1439,13 +1645,16 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1439
1645
  const column = kind === "move" ? boxEl.parentElement : null;
1440
1646
  const dayWidth = column ? column.getBoundingClientRect().width : 0;
1441
1647
  const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
1648
+ const originBase = (0, date_fns.startOfDay)(days[dayIndex] ?? days[0]);
1442
1649
  dragOrigin.current = {
1443
1650
  pointerX: e.clientX,
1444
1651
  pointerY: e.clientY,
1445
1652
  startHours,
1446
1653
  durationHours,
1447
1654
  dayIndex,
1448
- dayWidth
1655
+ dayWidth,
1656
+ segmentStart: (0, date_fns.addMinutes)(originBase, Math.round(startHours * 60)),
1657
+ segmentEnd: (0, date_fns.addMinutes)(originBase, Math.round((startHours + durationHours) * 60))
1449
1658
  };
1450
1659
  draggedRef.current = {
1451
1660
  event,
@@ -1468,8 +1677,12 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1468
1677
  kind,
1469
1678
  startHours,
1470
1679
  durationHours,
1680
+ continuesBefore,
1681
+ continuesAfter,
1471
1682
  dayDelta: 0,
1472
1683
  dayOffsetPx: 0,
1684
+ spillHours: 0,
1685
+ spillDayIndex: -1,
1473
1686
  moved: false
1474
1687
  });
1475
1688
  onDragStart?.(event);
@@ -1529,10 +1742,10 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1529
1742
  const moved = Math.abs(endPx - o.startPx) > 4;
1530
1743
  const h = hourHeightRef.current;
1531
1744
  if (moved && onCreateEvent) {
1532
- const range = (0, _super_calendar_core.cellRangeFromDrag)(day, o.startPx, endPx, h, windowStart, dragStepMinutes);
1745
+ const range = (0, _super_calendar_core.cellRangeFromDrag)(day, o.startPx, endPx, h, windowStart, snapMinutes);
1533
1746
  if (range) onCreateEvent(range.start, range.end);
1534
1747
  } else if (onPressCell) {
1535
- const at = (0, _super_calendar_core.cellRangeFromDrag)(day, o.startPx, o.startPx, h, windowStart, dragStepMinutes);
1748
+ const at = (0, _super_calendar_core.cellRangeFromDrag)(day, o.startPx, o.startPx, h, windowStart, snapMinutes);
1536
1749
  if (at) onPressCell(at.start);
1537
1750
  }
1538
1751
  createOrigin.current = null;
@@ -1543,6 +1756,21 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1543
1756
  setCreateBox(null);
1544
1757
  };
1545
1758
  const positionedByDay = (0, react.useMemo)(() => days.map((day) => (0, _super_calendar_core.layoutDayEvents)(events, day)), [days, events]);
1759
+ const spillPreviewFor = (dayIndex) => {
1760
+ if (paged || !drag || drag.kind !== "move" || drag.spillDayIndex !== dayIndex) return null;
1761
+ const dragged = draggedRef.current?.event;
1762
+ if (!dragged) return null;
1763
+ return {
1764
+ event: dragged,
1765
+ mode,
1766
+ isAllDay: false,
1767
+ boxHeight: Math.max(drag.spillHours * hourHeight, 14),
1768
+ continuesBefore: true,
1769
+ continuesAfter: false,
1770
+ ampm,
1771
+ onPress: () => {}
1772
+ };
1773
+ };
1546
1774
  const navByDay = (0, react.useMemo)(() => positionedByDay.map((list, day) => list.map((pe, idx) => ({
1547
1775
  key: `${day}:${idx}`,
1548
1776
  start: pe.startHours,
@@ -1850,6 +2078,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1850
2078
  const nowTop = (nowHours - windowStart) * hourHeight;
1851
2079
  const bands = bandsByDay[dayIndex];
1852
2080
  const ghost = createBox?.dayIndex === dayIndex ? createBox : null;
2081
+ const spill = spillPreviewFor(dayIndex);
1853
2082
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1854
2083
  "data-date": day.toISOString(),
1855
2084
  onPointerDown: cellEnabled ? (e) => beginCreate(e, dayIndex) : void 0,
@@ -1926,7 +2155,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1926
2155
  const durationHours = active ? active.durationHours : pe.durationHours;
1927
2156
  if (!active && (pe.startHours >= windowEnd || pe.startHours + pe.durationHours <= windowStart)) return null;
1928
2157
  const top = (startHours - windowStart) * hourHeight;
1929
- const boxHeight = Math.max(durationHours * hourHeight, 14);
2158
+ const boxHeight = Math.max(Math.min(durationHours, HOURS_PER_DAY - startHours) * hourHeight, 14);
1930
2159
  const widthPct = 100 / pe.columns;
1931
2160
  const onPress = () => onPressEvent?.(pe.event);
1932
2161
  const args = {
@@ -1965,7 +2194,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1965
2194
  }
1966
2195
  if (keyboardEventNavigation) onEventKeyDown(key, e);
1967
2196
  },
1968
- onPointerDown: canMove ? (e) => beginDrag(e, pe.event, key, "move", pe.startHours, pe.durationHours, dayIndex, onPress) : void 0,
2197
+ onPointerDown: canMove ? (e) => beginDrag(e, pe, key, "move", dayIndex, onPress) : void 0,
1969
2198
  onClick: canMove ? void 0 : onPress,
1970
2199
  ...dataState({ "data-dragging": !!active }),
1971
2200
  ...slot("event", { base: {
@@ -1989,7 +2218,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1989
2218
  canResize && !pe.continuesBefore ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1990
2219
  onPointerDown: (e) => {
1991
2220
  e.stopPropagation();
1992
- beginDrag(e, pe.event, key, "resize-start", pe.startHours, pe.durationHours, dayIndex);
2221
+ beginDrag(e, pe, key, "resize-start", dayIndex);
1993
2222
  },
1994
2223
  style: {
1995
2224
  position: "absolute",
@@ -2001,10 +2230,10 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2001
2230
  touchAction: "none"
2002
2231
  }
2003
2232
  }) : null,
2004
- canResize ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2233
+ canResize && !pe.continuesAfter ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2005
2234
  onPointerDown: (e) => {
2006
2235
  e.stopPropagation();
2007
- beginDrag(e, pe.event, key, "resize", pe.startHours, pe.durationHours, dayIndex);
2236
+ beginDrag(e, pe, key, "resize", dayIndex);
2008
2237
  },
2009
2238
  style: {
2010
2239
  position: "absolute",
@@ -2019,6 +2248,25 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2019
2248
  ]
2020
2249
  }, idx);
2021
2250
  }),
2251
+ spill ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2252
+ "aria-hidden": true,
2253
+ ...dataState({ "data-dragging": true }),
2254
+ ...slot("event", { base: {
2255
+ position: "absolute",
2256
+ top: -windowStart * hourHeight,
2257
+ left: 1,
2258
+ right: 1,
2259
+ height: spill.boxHeight,
2260
+ pointerEvents: "none",
2261
+ zIndex: 3,
2262
+ opacity: .85
2263
+ } }),
2264
+ children: Renderer ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Renderer, { ...spill }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultDomEvent, {
2265
+ ...spill,
2266
+ theme,
2267
+ boxProps: slot("eventBox")
2268
+ })
2269
+ }) : null,
2022
2270
  showNow ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2023
2271
  ...slot("nowIndicator", { base: {
2024
2272
  position: "absolute",
@@ -2129,7 +2377,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
2129
2377
  * <Calendar mode="week" date={new Date()} events={events} />
2130
2378
  * ```
2131
2379
  */
2132
- function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, showNowIndicator, showAllDayEventCell, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
2380
+ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, showNowIndicator, showAllDayEventCell, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, showTitle, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onSelectDrag, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
2133
2381
  const displayEvents = (0, react.useMemo)(() => {
2134
2382
  let out = events ?? EMPTY_EVENTS;
2135
2383
  if (out.some((e) => e.recurrence)) {
@@ -2172,8 +2420,15 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2172
2420
  } : style,
2173
2421
  classNames,
2174
2422
  styles,
2423
+ selectedRange,
2424
+ selectedDates,
2425
+ minDate,
2426
+ maxDate,
2427
+ isDateDisabled,
2175
2428
  onPressDay,
2176
- onPressMonth
2429
+ onPressMonth,
2430
+ onSelectDrag,
2431
+ onCreateEvent
2177
2432
  });
2178
2433
  else if (mode === "schedule") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
2179
2434
  events: displayEvents,
@@ -2207,6 +2462,7 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2207
2462
  maxVisibleEventCount,
2208
2463
  moreLabel,
2209
2464
  showAdjacentMonths,
2465
+ showTitle,
2210
2466
  fillCellOnSelection,
2211
2467
  selectedRange,
2212
2468
  selectedDates,
@@ -2215,7 +2471,13 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2215
2471
  isDateDisabled,
2216
2472
  keyboardDayNavigation,
2217
2473
  onPressDay,
2474
+ onPressCell,
2218
2475
  onCreateEvent,
2476
+ onSelectDrag,
2477
+ onDragEvent,
2478
+ onDragStart,
2479
+ eventStartEditable,
2480
+ eventOverlap,
2219
2481
  onPressEvent,
2220
2482
  onPressMore,
2221
2483
  renderEvent: renderMonthEvent,