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