@super-calendar/dom 2.12.1 → 2.14.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,6 +1,6 @@
1
1
  import { LegendList } from "@legendapp/list/react";
2
2
  import { addDays, addMinutes, addMonths, addYears, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
3
- import { useEffect, useId, useMemo, useRef, useState } from "react";
3
+ import { forwardRef, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import { backgroundBandsForDay, backgroundBandsForDay as backgroundBandsForDay$1, bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, 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, nextDateRange, nextDateRange as nextDateRange$1, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, titleNumberOfLines, toICalendar, useDateRange, useEventSource, useMonthGrid, useNow, useNow as useNow$1, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  //#region src/slots.ts
@@ -637,7 +637,7 @@ function badgeDefault(day, theme, hovered) {
637
637
  }
638
638
  };
639
639
  }
640
- function eventCellDefault(day, theme, height, highlightWeekends, isDragTarget) {
640
+ function eventCellDefault(day, theme, height, highlightWeekends, isDragTarget, chipGap) {
641
641
  return {
642
642
  base: {
643
643
  position: "relative",
@@ -647,7 +647,7 @@ function eventCellDefault(day, theme, height, highlightWeekends, isDragTarget) {
647
647
  cursor: day.isDisabled ? "default" : "pointer",
648
648
  display: "flex",
649
649
  flexDirection: "column",
650
- gap: CHIP_GAP,
650
+ gap: chipGap,
651
651
  padding: CELL_PAD,
652
652
  boxSizing: "border-box",
653
653
  textAlign: "left",
@@ -693,12 +693,12 @@ const chipButtonDefault = { base: {
693
693
  textAlign: "left",
694
694
  fontFamily: "inherit"
695
695
  } };
696
- function chipDefault(theme) {
696
+ function chipDefault(theme, chipHeight) {
697
697
  return {
698
698
  base: {
699
699
  display: "block",
700
- height: CHIP_HEIGHT,
701
- lineHeight: `${CHIP_HEIGHT}px`,
700
+ height: chipHeight,
701
+ lineHeight: `${chipHeight}px`,
702
702
  whiteSpace: "nowrap",
703
703
  overflow: "hidden",
704
704
  textOverflow: "ellipsis"
@@ -713,7 +713,7 @@ function chipDefault(theme) {
713
713
  }
714
714
  };
715
715
  }
716
- function moreButtonDefault(theme) {
716
+ function moreButtonDefault(theme, chipHeight) {
717
717
  return {
718
718
  base: {
719
719
  position: "relative",
@@ -722,8 +722,8 @@ function moreButtonDefault(theme) {
722
722
  background: "transparent",
723
723
  cursor: "pointer",
724
724
  textAlign: "left",
725
- height: CHIP_HEIGHT,
726
- lineHeight: `${CHIP_HEIGHT}px`,
725
+ height: chipHeight,
726
+ lineHeight: `${chipHeight}px`,
727
727
  fontFamily: "inherit"
728
728
  },
729
729
  themed: {
@@ -755,7 +755,7 @@ function collectRowEvents(week, eventsByDay) {
755
755
  * <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
756
756
  * ```
757
757
  */
758
- function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", labels: labelsProp, 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 }) {
758
+ function MonthView({ date, 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, 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 }) {
759
759
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
760
760
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
761
761
  const slot = createSlots({
@@ -800,7 +800,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
800
800
  document.removeEventListener("keydown", onKey);
801
801
  };
802
802
  }, [moreOpenFor]);
803
- const eventRowHeight = 32 + maxVisibleEventCount * 20;
803
+ const eventRowHeight = 32 + maxVisibleEventCount * (chipHeight + chipGap);
804
804
  const { weeks, weekdays } = useMemo(() => buildMonthGrid$1(date, {
805
805
  weekStartsOn,
806
806
  hiddenDays,
@@ -1012,7 +1012,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1012
1012
  };
1013
1013
  }).filter((b) => b.startCol <= b.endCol);
1014
1014
  const barChipButton = slot("chipButton", chipButtonDefault);
1015
- const barChip = slot("chip", chipDefault(theme));
1015
+ const barChip = slot("chip", chipDefault(theme, chipHeight));
1016
1016
  return /* @__PURE__ */ jsx("div", {
1017
1017
  role: "row",
1018
1018
  ...slot("week", { base: {
@@ -1051,7 +1051,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1051
1051
  const dayEvents = eventsByDay.get(startOfDay(day.date).toISOString()) ?? [];
1052
1052
  const hiddenEvents = rowLayout.segments.filter((s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes).map((s) => s.event);
1053
1053
  const dayLabel = format(day.date, "d MMMM", locale ? { locale } : void 0);
1054
- const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight, highlightWeekends, inCreate || isDropTarget));
1054
+ const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight, highlightWeekends, inCreate || isDropTarget, chipGap));
1055
1055
  return /* @__PURE__ */ jsxs("div", {
1056
1056
  role: "gridcell",
1057
1057
  "data-day": day.id,
@@ -1129,8 +1129,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1129
1129
  position: "absolute",
1130
1130
  left: 2,
1131
1131
  width: `calc(${span * 100}% - 4px)`,
1132
- top: 30 + b.seg.lane * 20,
1133
- height: CHIP_HEIGHT,
1132
+ top: 28 + chipGap + b.seg.lane * (chipHeight + chipGap),
1133
+ height: chipHeight,
1134
1134
  pointerEvents: isDragging ? "none" : "auto",
1135
1135
  opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
1136
1136
  cursor: canMove(b.seg.event) ? "grab" : void 0,
@@ -1161,12 +1161,12 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1161
1161
  ...slot("events", { base: {
1162
1162
  display: "flex",
1163
1163
  flexDirection: "column",
1164
- gap: CHIP_GAP
1164
+ gap: chipGap
1165
1165
  } }),
1166
1166
  children: [
1167
1167
  Array.from({ length: visibleLanes }, (_, i) => /* @__PURE__ */ jsx("div", {
1168
1168
  "aria-hidden": true,
1169
- style: { height: CHIP_HEIGHT }
1169
+ style: { height: chipHeight }
1170
1170
  }, `lane-${i}`)),
1171
1171
  hiddenEvents.length > 0 ? /* @__PURE__ */ jsx("button", {
1172
1172
  type: "button",
@@ -1179,7 +1179,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1179
1179
  setMoreOpenFor((open) => open === day.id ? null : day.id);
1180
1180
  }
1181
1181
  },
1182
- ...slot("more", moreButtonDefault(theme)),
1182
+ ...slot("more", moreButtonDefault(theme, chipHeight)),
1183
1183
  "aria-label": `${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`,
1184
1184
  "aria-expanded": onPressMore ? void 0 : moreOpenFor === day.id,
1185
1185
  children: moreLabel.replace("{moreCount}", String(hiddenEvents.length))
@@ -1251,7 +1251,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1251
1251
  event,
1252
1252
  onPress: () => onPressEvent?.(event)
1253
1253
  }) : /* @__PURE__ */ jsx("span", {
1254
- ...slot("chip", chipDefault(theme)),
1254
+ ...slot("chip", chipDefault(theme, chipHeight)),
1255
1255
  children: event.title
1256
1256
  })
1257
1257
  }, i))]
@@ -1295,6 +1295,45 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
1295
1295
  });
1296
1296
  }
1297
1297
  //#endregion
1298
+ //#region src/touch.ts
1299
+ function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
1300
+ const detach = () => {
1301
+ clearTimeout(timer);
1302
+ document.removeEventListener("pointermove", move);
1303
+ document.removeEventListener("pointerup", up);
1304
+ document.removeEventListener("pointercancel", cancelPointer);
1305
+ document.removeEventListener("pointerdown", anotherPointer);
1306
+ };
1307
+ const cancel = () => {
1308
+ detach();
1309
+ onCancel();
1310
+ };
1311
+ const move = (event) => {
1312
+ if (event.pointerId === grab.pointerId && Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold) cancel();
1313
+ };
1314
+ const up = (event) => {
1315
+ if (event.pointerId === grab.pointerId) {
1316
+ detach();
1317
+ onTap();
1318
+ }
1319
+ };
1320
+ const cancelPointer = (event) => {
1321
+ if (event.pointerId === grab.pointerId) cancel();
1322
+ };
1323
+ const anotherPointer = (event) => {
1324
+ if (event.pointerId !== grab.pointerId) cancel();
1325
+ };
1326
+ const timer = setTimeout(() => {
1327
+ detach();
1328
+ onHold();
1329
+ }, delay);
1330
+ document.addEventListener("pointermove", move);
1331
+ document.addEventListener("pointerup", up);
1332
+ document.addEventListener("pointercancel", cancelPointer);
1333
+ document.addEventListener("pointerdown", anotherPointer);
1334
+ return cancel;
1335
+ }
1336
+ //#endregion
1298
1337
  //#region src/TimeGrid.tsx
1299
1338
  const GUTTER_WIDTH$1 = 56;
1300
1339
  const HOURS_PER_DAY = 24;
@@ -1304,6 +1343,7 @@ const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
1304
1343
  const EDGE_ZONE = 32;
1305
1344
  const EDGE_DWELL_MS = 600;
1306
1345
  const EDGE_REPEAT_MS = 600;
1346
+ const CELL_TOUCH_SLOP_PX = 8;
1307
1347
  const VISUALLY_HIDDEN = {
1308
1348
  position: "absolute",
1309
1349
  width: 1,
@@ -1397,7 +1437,8 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
1397
1437
  * <TimeGrid mode="week" date={new Date()} events={events} />
1398
1438
  * ```
1399
1439
  */
1400
- function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, minEventHeight = DEFAULT_MIN_EVENT_HEIGHT, eventGap = DEFAULT_EVENT_GAP, dragStepMinutes = 15, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", hiddenDays, keyboardEventNavigation = false, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator = true, highlightWeekends = true, eventStartEditable = true, eventDurationEditable = true, eventOverlap = true, now: nowProp, timeZone, showAllDayEventCell = true, showAllDayLabel = false, labels: labelsProp, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel: eventAccessibilityLabel$1, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, onChangeDate, className, style, classNames, styles }) {
1440
+ const TimeGrid = forwardRef(TimeGridInner);
1441
+ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, weekdayFormat = "short", hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, minEventHeight = DEFAULT_MIN_EVENT_HEIGHT, eventGap = DEFAULT_EVENT_GAP, dragStepMinutes = 15, touchDragDelay = 300, touchDragThreshold = 8, ampm = false, timeslots = 1, minHour = 0, maxHour = 24, hideHours = false, showWeekNumber = false, weekNumberPrefix = "W", hiddenDays, keyboardEventNavigation = false, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator = true, highlightWeekends = true, eventStartEditable = true, eventDurationEditable = true, eventOverlap = true, now: nowProp, timeZone, showAllDayEventCell = true, showAllDayLabel = false, labels: labelsProp, locale, theme: themeOverrides, height = 600, renderEvent, eventAccessibilityLabel: eventAccessibilityLabel$1, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, onChangeDate, className, style, classNames, styles }, ref) {
1401
1442
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
1402
1443
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
1403
1444
  const slot = createSlots({
@@ -1431,6 +1472,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1431
1472
  };
1432
1473
  const [createBox, setCreateBox] = useState(null);
1433
1474
  const createOrigin = useRef(null);
1475
+ const cellTouchRef = useRef(null);
1434
1476
  const cellEnabled = !!onPressCell || !!onCreateEvent;
1435
1477
  const days = useMemo(() => getViewDays$1(mode, date, weekStartsOn, numberOfDays, false, void 0, hiddenDays), [
1436
1478
  mode,
@@ -1451,6 +1493,10 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1451
1493
  const [paged, setPaged] = useState(false);
1452
1494
  const draggedRef = useRef(null);
1453
1495
  const ghostRef = useRef(null);
1496
+ const touchDragRef = useRef(false);
1497
+ const activeGrabRef = useRef(null);
1498
+ const cancelHoldRef = useRef(null);
1499
+ const tappedRef = useRef(null);
1454
1500
  const docHandlersRef = useRef(null);
1455
1501
  const daysRef = useRef(days);
1456
1502
  daysRef.current = days;
@@ -1479,6 +1525,16 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1479
1525
  useEffect(() => {
1480
1526
  if (scrollRef.current) scrollRef.current.scrollTop = Math.max(0, (scrollOffsetMinutes / 60 - windowStart) * hourHeightRef.current);
1481
1527
  }, [scrollOffsetMinutes, windowStart]);
1528
+ useImperativeHandle(ref, () => ({ scrollToTime: (minutes, { animated = true } = {}) => {
1529
+ const el = scrollRef.current;
1530
+ if (!el) return;
1531
+ const top = Math.max(0, (minutes / 60 - windowStart) * hourHeightRef.current);
1532
+ if (animated && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches && typeof el.scrollTo === "function") el.scrollTo({
1533
+ top,
1534
+ behavior: "smooth"
1535
+ });
1536
+ else el.scrollTop = top;
1537
+ } }), [windowStart]);
1482
1538
  useEffect(() => {
1483
1539
  const el = scrollRef.current;
1484
1540
  if (!el || !zoomable) return;
@@ -1494,6 +1550,22 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1494
1550
  minHourHeight,
1495
1551
  maxHourHeight
1496
1552
  ]);
1553
+ useEffect(() => {
1554
+ const el = scrollRef.current;
1555
+ if (!el) return;
1556
+ const onTouchMove = (e) => {
1557
+ if (touchDragRef.current && e.cancelable) e.preventDefault();
1558
+ };
1559
+ const onContextMenu = (e) => {
1560
+ if (touchDragRef.current || cancelHoldRef.current) e.preventDefault();
1561
+ };
1562
+ el.addEventListener("touchmove", onTouchMove, { passive: false });
1563
+ el.addEventListener("contextmenu", onContextMenu);
1564
+ return () => {
1565
+ el.removeEventListener("touchmove", onTouchMove);
1566
+ el.removeEventListener("contextmenu", onContextMenu);
1567
+ };
1568
+ }, []);
1497
1569
  const pinch = useRef(/* @__PURE__ */ new Map());
1498
1570
  const pinchBase = useRef(null);
1499
1571
  const onBodyPointerDown = (e) => {
@@ -1557,6 +1629,8 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1557
1629
  edgeSide.current = 0;
1558
1630
  pagedRef.current = false;
1559
1631
  setPaged(false);
1632
+ touchDragRef.current = false;
1633
+ activeGrabRef.current = null;
1560
1634
  draggedRef.current = null;
1561
1635
  dragOrigin.current = null;
1562
1636
  applyDrag(null);
@@ -1564,6 +1638,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1564
1638
  const moveDrag = (e) => {
1565
1639
  const d = dragRef.current;
1566
1640
  if (!d || !dragOrigin.current) return;
1641
+ if (touchDragRef.current && !d.moved && Math.hypot(e.clientX - dragOrigin.current.pointerX, e.clientY - dragOrigin.current.pointerY) <= touchDragThreshold) return;
1567
1642
  ptr.current = {
1568
1643
  x: e.clientX,
1569
1644
  y: e.clientY
@@ -1592,7 +1667,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1592
1667
  const g = ghostRef.current;
1593
1668
  const held = draggedRef.current;
1594
1669
  if (g && held) g.style.transform = `translate(${e.clientX - held.grabX}px, ${e.clientY - held.grabY}px)`;
1595
- if (edgeAdvanceEnabled) {
1670
+ if (edgeAdvanceEnabled && o.pointerType === "mouse") {
1596
1671
  const rect = columnsRef.current?.getBoundingClientRect();
1597
1672
  if (rect && rect.right > rect.left) {
1598
1673
  const left = rect.left + gutterWidth;
@@ -1627,12 +1702,15 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1627
1702
  const d = dragRef.current;
1628
1703
  if (!d) return;
1629
1704
  try {
1630
- e.target?.releasePointerCapture?.(e.pointerId);
1705
+ activeGrabRef.current?.box.releasePointerCapture?.(e.pointerId);
1631
1706
  } catch {}
1632
1707
  const held = draggedRef.current;
1633
1708
  if (!d.moved) {
1709
+ const wasTouch = touchDragRef.current;
1710
+ const tapBox = activeGrabRef.current?.box ?? null;
1634
1711
  finishDrag();
1635
- held?.onPress();
1712
+ if (wasTouch) tappedRef.current = tapBox;
1713
+ else held?.onPress();
1636
1714
  return;
1637
1715
  }
1638
1716
  const origin = dragOrigin.current;
@@ -1659,13 +1737,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1659
1737
  finishDrag();
1660
1738
  };
1661
1739
  const beginDrag = (e, pe, key, kind, dayIndex, onPress) => {
1662
- if (!onDragEvent) return;
1663
1740
  const { event, startHours, durationHours, continuesBefore, continuesAfter } = pe;
1664
- e.stopPropagation();
1665
1741
  try {
1666
- e.target.setPointerCapture?.(e.pointerId);
1742
+ e.box.setPointerCapture?.(e.pointerId);
1667
1743
  } catch {}
1668
- const boxEl = e.currentTarget;
1744
+ touchDragRef.current = e.pointerType !== "mouse";
1745
+ activeGrabRef.current = e;
1746
+ const boxEl = e.box;
1669
1747
  const column = kind === "move" ? boxEl.parentElement : null;
1670
1748
  const dayWidth = column ? column.getBoundingClientRect().width : 0;
1671
1749
  const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
@@ -1673,6 +1751,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1673
1751
  dragOrigin.current = {
1674
1752
  pointerX: e.clientX,
1675
1753
  pointerY: e.clientY,
1754
+ pointerType: e.pointerType,
1676
1755
  startHours,
1677
1756
  durationHours,
1678
1757
  dayIndex,
@@ -1712,21 +1791,68 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1712
1791
  onDragStart?.(event);
1713
1792
  detachDocListeners();
1714
1793
  const handlers = {
1715
- move: moveDrag,
1716
- up: endDrag,
1717
- cancel: cancelDrag
1794
+ move: (event) => {
1795
+ if (event.pointerId === e.pointerId) moveDrag(event);
1796
+ },
1797
+ up: (event) => {
1798
+ if (event.pointerId === e.pointerId) endDrag(event);
1799
+ },
1800
+ cancel: (event) => {
1801
+ if (event.pointerId === e.pointerId) cancelDrag();
1802
+ }
1718
1803
  };
1719
1804
  docHandlersRef.current = handlers;
1720
1805
  document.addEventListener("pointermove", handlers.move);
1721
1806
  document.addEventListener("pointerup", handlers.up);
1722
1807
  document.addEventListener("pointercancel", handlers.cancel);
1723
1808
  };
1809
+ const pressEvent = (e, pe, key, kind, dayIndex, onPress) => {
1810
+ if (!onDragEvent || e.button > 0) return;
1811
+ e.stopPropagation();
1812
+ const hadPendingHold = cancelHoldRef.current !== null;
1813
+ cancelHoldRef.current?.();
1814
+ tappedRef.current = null;
1815
+ if (hadPendingHold || activeGrabRef.current || e.pointerType !== "mouse" && !e.isPrimary) return;
1816
+ const grab = {
1817
+ box: e.currentTarget,
1818
+ pointerId: e.pointerId,
1819
+ pointerType: e.pointerType,
1820
+ clientX: e.clientX,
1821
+ clientY: e.clientY
1822
+ };
1823
+ if (e.pointerType === "mouse") {
1824
+ beginDrag(grab, pe, key, kind, dayIndex, onPress);
1825
+ return;
1826
+ }
1827
+ cancelHoldRef.current = waitForHold(grab, touchDragDelay, touchDragThreshold, () => {
1828
+ cancelHoldRef.current = null;
1829
+ beginDrag(grab, pe, key, kind, dayIndex, onPress);
1830
+ }, () => {
1831
+ cancelHoldRef.current = null;
1832
+ tappedRef.current = grab.box;
1833
+ }, () => {
1834
+ cancelHoldRef.current = null;
1835
+ });
1836
+ };
1724
1837
  useEffect(() => () => {
1838
+ cancelHoldRef.current?.();
1725
1839
  detachDocListeners();
1726
1840
  clearEdgeTimer();
1727
1841
  }, []);
1842
+ useEffect(() => {
1843
+ cancelHoldRef.current?.();
1844
+ }, [
1845
+ date,
1846
+ events,
1847
+ onDragEvent
1848
+ ]);
1728
1849
  const pxFromTop = (el, clientY) => clientY - el.getBoundingClientRect().top;
1729
1850
  const beginCreate = (e, dayIndex) => {
1851
+ cellTouchRef.current = e.pointerType === "touch" && e.target === e.currentTarget ? {
1852
+ pointerId: e.pointerId,
1853
+ x: e.clientX,
1854
+ y: e.clientY
1855
+ } : null;
1730
1856
  if (!cellEnabled || e.pointerType === "touch") return;
1731
1857
  if (e.target !== e.currentTarget || e.button > 0) return;
1732
1858
  const el = e.currentTarget;
@@ -1746,6 +1872,8 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1746
1872
  });
1747
1873
  };
1748
1874
  const moveCreate = (e) => {
1875
+ const touch = cellTouchRef.current;
1876
+ if (touch && e.pointerId === touch.pointerId && Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX) cellTouchRef.current = null;
1749
1877
  const o = createOrigin.current;
1750
1878
  if (!o) return;
1751
1879
  const cur = pxFromTop(o.el, e.clientY);
@@ -1775,7 +1903,17 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1775
1903
  createOrigin.current = null;
1776
1904
  setCreateBox(null);
1777
1905
  };
1906
+ const tapCell = (e, dayIndex) => {
1907
+ const touch = cellTouchRef.current;
1908
+ cellTouchRef.current = null;
1909
+ const day = days[dayIndex];
1910
+ if (!touch || !onPressCell || !day || e.target !== e.currentTarget) return;
1911
+ const px = pxFromTop(e.currentTarget, e.clientY);
1912
+ const at = cellRangeFromDrag(day, px, px, hourHeightRef.current, windowStart, snapMinutes);
1913
+ if (at) onPressCell(at.start);
1914
+ };
1778
1915
  const cancelCreate = () => {
1916
+ cellTouchRef.current = null;
1779
1917
  createOrigin.current = null;
1780
1918
  setCreateBox(null);
1781
1919
  };
@@ -2135,6 +2273,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2135
2273
  onPointerMove: cellEnabled ? moveCreate : void 0,
2136
2274
  onPointerUp: cellEnabled ? endCreate : void 0,
2137
2275
  onPointerCancel: cellEnabled ? cancelCreate : void 0,
2276
+ onClick: cellEnabled ? (e) => tapCell(e, dayIndex) : void 0,
2138
2277
  ...dataState({
2139
2278
  "data-today": getIsToday(day),
2140
2279
  "data-weekend": isWeekend(day)
@@ -2270,8 +2409,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2270
2409
  }
2271
2410
  if (keyboardEventNavigation) onEventKeyDown(key, e);
2272
2411
  },
2273
- onPointerDown: canMove ? (e) => beginDrag(e, pe, key, "move", dayIndex, onPress) : void 0,
2274
- onClick: canMove ? void 0 : onPress,
2412
+ onPointerDown: canMove ? (e) => pressEvent(e, pe, key, "move", dayIndex, onPress) : void 0,
2413
+ onClick: canMove ? (e) => {
2414
+ if (e.detail === 0 || tappedRef.current && e.currentTarget.contains(tappedRef.current)) {
2415
+ tappedRef.current = null;
2416
+ onPress();
2417
+ }
2418
+ } : onPress,
2275
2419
  ...dataState({ "data-dragging": !!active && !hiddenForMove }),
2276
2420
  ...slot("event", { base: {
2277
2421
  position: "absolute",
@@ -2280,7 +2424,9 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2280
2424
  left: `calc(${pe.column * widthPct}% + ${eventGap}px)`,
2281
2425
  width: `calc(${widthPct}% - ${eventGap * 2}px)`,
2282
2426
  cursor: canMove ? "grab" : "pointer",
2283
- touchAction: canMove ? "none" : "auto",
2427
+ touchAction: canMove ? "pan-y" : "auto",
2428
+ userSelect: canMove ? "none" : void 0,
2429
+ WebkitTouchCallout: canMove ? "none" : void 0,
2284
2430
  zIndex: active ? 3 : 1,
2285
2431
  opacity: active ? .85 : 1,
2286
2432
  visibility: hiddenForMove ? "hidden" : void 0,
@@ -2294,8 +2440,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2294
2440
  }),
2295
2441
  canResize && !pe.continuesBefore ? /* @__PURE__ */ jsx("div", {
2296
2442
  onPointerDown: (e) => {
2297
- e.stopPropagation();
2298
- beginDrag(e, pe, key, "resize-start", dayIndex, canMove ? onPress : void 0);
2443
+ pressEvent(e, pe, key, "resize-start", dayIndex, canMove ? onPress : void 0);
2299
2444
  },
2300
2445
  style: {
2301
2446
  position: "absolute",
@@ -2304,13 +2449,12 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2304
2449
  top: 0,
2305
2450
  height: 8,
2306
2451
  cursor: "ns-resize",
2307
- touchAction: "none"
2452
+ touchAction: "pan-y"
2308
2453
  }
2309
2454
  }) : null,
2310
2455
  canResize && !pe.continuesAfter ? /* @__PURE__ */ jsx("div", {
2311
2456
  onPointerDown: (e) => {
2312
- e.stopPropagation();
2313
- beginDrag(e, pe, key, "resize", dayIndex, canMove ? onPress : void 0);
2457
+ pressEvent(e, pe, key, "resize", dayIndex, canMove ? onPress : void 0);
2314
2458
  },
2315
2459
  style: {
2316
2460
  position: "absolute",
@@ -2319,7 +2463,7 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
2319
2463
  bottom: 0,
2320
2464
  height: 8,
2321
2465
  cursor: "ns-resize",
2322
- touchAction: "none"
2466
+ touchAction: "pan-y"
2323
2467
  }
2324
2468
  }) : null
2325
2469
  ]
@@ -2485,7 +2629,10 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
2485
2629
  * <Calendar mode="week" date={new Date()} events={events} />
2486
2630
  * ```
2487
2631
  */
2488
- function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, minEventHeight, eventGap, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator, showAllDayEventCell, showAllDayLabel, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, labels, showAdjacentMonths, showTitle, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onSelectDrag, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
2632
+ const Calendar = forwardRef(CalendarInner);
2633
+ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, minEventHeight, eventGap, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, renderBusinessHours, renderBackgroundEvent, showNowIndicator, showAllDayEventCell, showAllDayLabel, highlightWeekends, eventStartEditable, eventDurationEditable, eventOverlap, dragStepMinutes, touchDragDelay, touchDragThreshold, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, chipHeight, chipGap, moreLabel, labels, showAdjacentMonths, showTitle, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onSelectDrag, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }, ref) {
2634
+ const timeGridRef = useRef(null);
2635
+ useImperativeHandle(ref, () => ({ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options) }), []);
2489
2636
  const displayEvents = useMemo(() => {
2490
2637
  let out = events ?? EMPTY_EVENTS;
2491
2638
  if (out.some((e) => e.recurrence)) {
@@ -2570,6 +2717,8 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2570
2717
  classNames,
2571
2718
  styles,
2572
2719
  maxVisibleEventCount,
2720
+ chipHeight,
2721
+ chipGap,
2573
2722
  moreLabel,
2574
2723
  showAdjacentMonths,
2575
2724
  showTitle,
@@ -2594,6 +2743,7 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2594
2743
  eventAccessibilityLabel
2595
2744
  });
2596
2745
  else view = /* @__PURE__ */ jsx(TimeGrid, {
2746
+ ref: timeGridRef,
2597
2747
  date,
2598
2748
  mode,
2599
2749
  events: displayEvents,
@@ -2633,6 +2783,8 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2633
2783
  eventDurationEditable,
2634
2784
  eventOverlap,
2635
2785
  dragStepMinutes,
2786
+ touchDragDelay,
2787
+ touchDragThreshold,
2636
2788
  onPressEvent,
2637
2789
  onPressCell,
2638
2790
  onCreateEvent,
@@ -2658,7 +2810,7 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
2658
2810
  * Legend List's DOM renderer and the library's headless grid logic. Selection is
2659
2811
  * controlled, pass `selectedRange` (or `selectedDates`) and handle `onPressDay`.
2660
2812
  */
2661
- function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "short", highlightWeekends = true, weekStartsOn = 0, events, renderEvent, eventAccessibilityLabel, maxVisibleEventCount, moreLabel, labels, onPressEvent, onPressMore, selectedRange, selectedDates, fillCellOnSelection = false, locale, theme: themeOverrides, height = 480, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, className, style, classNames, styles }) {
2813
+ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "short", highlightWeekends = true, weekStartsOn = 0, events, renderEvent, eventAccessibilityLabel, maxVisibleEventCount, chipHeight, chipGap, moreLabel, labels, onPressEvent, onPressMore, selectedRange, selectedDates, fillCellOnSelection = false, locale, theme: themeOverrides, height = 480, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, className, style, classNames, styles }) {
2662
2814
  const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
2663
2815
  const slot = createSlots({
2664
2816
  classNames,
@@ -2692,11 +2844,15 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
2692
2844
  const extraData = useMemo(() => [
2693
2845
  selectedRange,
2694
2846
  selectedDates,
2695
- events
2847
+ events,
2848
+ chipHeight,
2849
+ chipGap
2696
2850
  ], [
2697
2851
  selectedRange,
2698
2852
  selectedDates,
2699
- events
2853
+ events,
2854
+ chipHeight,
2855
+ chipGap
2700
2856
  ]);
2701
2857
  return /* @__PURE__ */ jsxs("div", {
2702
2858
  className,
@@ -2745,6 +2901,8 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
2745
2901
  renderEvent,
2746
2902
  eventAccessibilityLabel,
2747
2903
  maxVisibleEventCount,
2904
+ chipHeight,
2905
+ chipGap,
2748
2906
  moreLabel,
2749
2907
  labels,
2750
2908
  onPressEvent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/dom",
3
- "version": "2.12.1",
3
+ "version": "2.14.0",
4
4
  "description": "Virtualized month / week / day calendar and date picker for react-dom. No React Native, no react-native-web.",
5
5
  "keywords": [
6
6
  "calendar",
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@super-calendar/core": "2.12.1"
51
+ "@super-calendar/core": "2.14.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@legendapp/list": ">=3",