@super-calendar/dom 2.15.0 → 2.17.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 +92 -0
- package/dist/index.d.mts +94 -31
- package/dist/index.d.ts +94 -31
- package/dist/index.js +1675 -526
- package/dist/index.mjs +1672 -530
- package/package.json +2 -2
- package/src/Calendar.tsx +91 -13
- package/src/DateRangePicker.tsx +60 -6
- package/src/EventActions.tsx +470 -0
- package/src/InertDiv.ts +7 -0
- package/src/MonthList.tsx +64 -38
- package/src/MonthView.tsx +398 -63
- package/src/MultiWeekView.tsx +54 -0
- package/src/ResourceTimeline.tsx +438 -98
- package/src/TimeGrid.tsx +305 -35
- package/src/index.ts +8 -0
- package/src/touch.ts +70 -0
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ let date_fns = require("date-fns");
|
|
|
4
4
|
let react = require("react");
|
|
5
5
|
let _super_calendar_core = require("@super-calendar/core");
|
|
6
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
|
|
7
|
+
// src/slots.ts
|
|
8
8
|
/** Join truthy class names (a dependency-free clsx-lite). */
|
|
9
9
|
function cn(...parts) {
|
|
10
10
|
return parts.filter(Boolean).join(" ") || void 0;
|
|
@@ -40,8 +40,7 @@ function dataState(flags) {
|
|
|
40
40
|
for (const key in flags) if (flags[key]) out[key] = "";
|
|
41
41
|
return out;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
//#region src/theme.ts
|
|
43
|
+
// src/theme.ts
|
|
45
44
|
const METRICS = {
|
|
46
45
|
cellHeight: 48,
|
|
47
46
|
dayBadgeSize: 34,
|
|
@@ -65,8 +64,7 @@ function mergeDomTheme(overrides, base = defaultDomTheme) {
|
|
|
65
64
|
...overrides
|
|
66
65
|
} : base;
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
//#region src/Agenda.tsx
|
|
67
|
+
// src/Agenda.tsx
|
|
70
68
|
function DefaultAgendaRow({ event, isAllDay, ampm = false, cardProps }) {
|
|
71
69
|
const time = (0, _super_calendar_core.eventTimeLabel)({
|
|
72
70
|
mode: "schedule",
|
|
@@ -234,8 +232,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
|
|
|
234
232
|
}) : null]
|
|
235
233
|
});
|
|
236
234
|
}
|
|
237
|
-
|
|
238
|
-
//#region src/YearView.tsx
|
|
235
|
+
// src/YearView.tsx
|
|
239
236
|
/**
|
|
240
237
|
* A year at a glance: the twelve months as compact mini grids, with today
|
|
241
238
|
* highlighted and a dot under days that hold events. It's the view `Calendar`
|
|
@@ -545,8 +542,100 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
|
|
|
545
542
|
})
|
|
546
543
|
});
|
|
547
544
|
}
|
|
548
|
-
|
|
549
|
-
|
|
545
|
+
// src/touch.ts
|
|
546
|
+
function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
|
|
547
|
+
const detach = () => {
|
|
548
|
+
clearTimeout(timer);
|
|
549
|
+
document.removeEventListener("pointermove", move);
|
|
550
|
+
document.removeEventListener("pointerup", up);
|
|
551
|
+
document.removeEventListener("pointercancel", cancelPointer);
|
|
552
|
+
document.removeEventListener("pointerdown", anotherPointer);
|
|
553
|
+
};
|
|
554
|
+
const cancel = () => {
|
|
555
|
+
detach();
|
|
556
|
+
onCancel();
|
|
557
|
+
};
|
|
558
|
+
const move = (event) => {
|
|
559
|
+
if (event.pointerId === grab.pointerId && Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold) cancel();
|
|
560
|
+
};
|
|
561
|
+
const up = (event) => {
|
|
562
|
+
if (event.pointerId === grab.pointerId) {
|
|
563
|
+
detach();
|
|
564
|
+
onTap();
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
const cancelPointer = (event) => {
|
|
568
|
+
if (event.pointerId === grab.pointerId) cancel();
|
|
569
|
+
};
|
|
570
|
+
const anotherPointer = (event) => {
|
|
571
|
+
if (event.pointerId !== grab.pointerId) cancel();
|
|
572
|
+
};
|
|
573
|
+
const timer = setTimeout(() => {
|
|
574
|
+
detach();
|
|
575
|
+
onHold();
|
|
576
|
+
}, delay);
|
|
577
|
+
document.addEventListener("pointermove", move);
|
|
578
|
+
document.addEventListener("pointerup", up);
|
|
579
|
+
document.addEventListener("pointercancel", cancelPointer);
|
|
580
|
+
document.addEventListener("pointerdown", anotherPointer);
|
|
581
|
+
return cancel;
|
|
582
|
+
}
|
|
583
|
+
/** A quick swipe scrolls; a held pointer owns a date-row drag until release. */
|
|
584
|
+
function holdDateDrag(grab, start, move, cancel, release) {
|
|
585
|
+
const doc = grab.box.ownerDocument;
|
|
586
|
+
let active = false;
|
|
587
|
+
let finished = false;
|
|
588
|
+
let cancelWait;
|
|
589
|
+
const detach = () => {
|
|
590
|
+
doc.removeEventListener("pointermove", onMove);
|
|
591
|
+
doc.removeEventListener("pointerup", onUp);
|
|
592
|
+
doc.removeEventListener("pointercancel", onCancel);
|
|
593
|
+
doc.removeEventListener("pointerdown", onAnotherPointer);
|
|
594
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
595
|
+
doc.removeEventListener("contextmenu", onContextMenu);
|
|
596
|
+
};
|
|
597
|
+
const stop = () => {
|
|
598
|
+
if (finished) return;
|
|
599
|
+
finished = true;
|
|
600
|
+
detach();
|
|
601
|
+
cancelWait?.();
|
|
602
|
+
cancel();
|
|
603
|
+
release();
|
|
604
|
+
};
|
|
605
|
+
const onMove = (event) => {
|
|
606
|
+
if (active && event.pointerId === grab.pointerId) move(event.clientX, event.clientY);
|
|
607
|
+
};
|
|
608
|
+
const onUp = (event) => {
|
|
609
|
+
if (event.pointerId !== grab.pointerId) return;
|
|
610
|
+
finished = true;
|
|
611
|
+
detach();
|
|
612
|
+
release();
|
|
613
|
+
};
|
|
614
|
+
const onCancel = (event) => {
|
|
615
|
+
if (event.pointerId === grab.pointerId) stop();
|
|
616
|
+
};
|
|
617
|
+
const onAnotherPointer = (event) => {
|
|
618
|
+
if (event.pointerId !== grab.pointerId) stop();
|
|
619
|
+
};
|
|
620
|
+
const onTouchMove = (event) => {
|
|
621
|
+
if (active && event.cancelable) event.preventDefault();
|
|
622
|
+
};
|
|
623
|
+
const onContextMenu = (event) => {
|
|
624
|
+
event.preventDefault();
|
|
625
|
+
};
|
|
626
|
+
doc.addEventListener("pointermove", onMove);
|
|
627
|
+
doc.addEventListener("pointerup", onUp);
|
|
628
|
+
doc.addEventListener("pointercancel", onCancel);
|
|
629
|
+
doc.addEventListener("pointerdown", onAnotherPointer);
|
|
630
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
631
|
+
doc.addEventListener("contextmenu", onContextMenu);
|
|
632
|
+
cancelWait = waitForHold(grab, 400, 8, () => {
|
|
633
|
+
active = true;
|
|
634
|
+
start();
|
|
635
|
+
}, release, stop);
|
|
636
|
+
return stop;
|
|
637
|
+
}
|
|
638
|
+
// src/MonthView.tsx
|
|
550
639
|
const EMPTY_LAYOUT = {
|
|
551
640
|
segments: [],
|
|
552
641
|
laneCount: 0
|
|
@@ -555,6 +644,7 @@ const CHIP_HEIGHT = 18;
|
|
|
555
644
|
const CHIP_GAP = 2;
|
|
556
645
|
const CELL_PAD = 4;
|
|
557
646
|
const DRAGGED_CHIP_OPACITY = .4;
|
|
647
|
+
const isOutsidePeriod = (day) => day.isCurrentMonth === false;
|
|
558
648
|
function dayCellDefault(day, theme, highlightWeekends) {
|
|
559
649
|
return {
|
|
560
650
|
base: {
|
|
@@ -714,7 +804,7 @@ function chipDefault(theme, chipHeight) {
|
|
|
714
804
|
}
|
|
715
805
|
};
|
|
716
806
|
}
|
|
717
|
-
function moreButtonDefault(theme, chipHeight) {
|
|
807
|
+
function moreButtonDefault(theme, chipHeight, multiWeek = false) {
|
|
718
808
|
return {
|
|
719
809
|
base: {
|
|
720
810
|
position: "relative",
|
|
@@ -725,7 +815,12 @@ function moreButtonDefault(theme, chipHeight) {
|
|
|
725
815
|
textAlign: "left",
|
|
726
816
|
height: chipHeight,
|
|
727
817
|
lineHeight: `${chipHeight}px`,
|
|
728
|
-
fontFamily: "inherit"
|
|
818
|
+
fontFamily: "inherit",
|
|
819
|
+
...multiWeek ? {
|
|
820
|
+
whiteSpace: "nowrap",
|
|
821
|
+
overflow: "hidden",
|
|
822
|
+
textOverflow: "ellipsis"
|
|
823
|
+
} : {}
|
|
729
824
|
},
|
|
730
825
|
themed: {
|
|
731
826
|
padding: "0 6px",
|
|
@@ -748,6 +843,10 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
748
843
|
}
|
|
749
844
|
return out;
|
|
750
845
|
}
|
|
846
|
+
function rangeTitle(start, endExclusive, locale) {
|
|
847
|
+
const options = locale ? { locale } : void 0;
|
|
848
|
+
return `${(0, date_fns.format)(start, "PP", options)} – ${(0, date_fns.format)((0, date_fns.addDays)(endExclusive, -1), "PP", options)}`;
|
|
849
|
+
}
|
|
751
850
|
/**
|
|
752
851
|
* A single static month grid, rendered with plain DOM elements.
|
|
753
852
|
*
|
|
@@ -756,14 +855,33 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
756
855
|
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
757
856
|
* ```
|
|
758
857
|
*/
|
|
759
|
-
function MonthView({ date,
|
|
858
|
+
function MonthView({ date, showAdjacentMonths = true, ...rest }) {
|
|
859
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateRows, {
|
|
860
|
+
...rest,
|
|
861
|
+
source: {
|
|
862
|
+
kind: "month",
|
|
863
|
+
date,
|
|
864
|
+
showAdjacentMonths
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
870
|
+
* spanning event bars, overflow, selection, drag, and keyboard handling.
|
|
871
|
+
*/
|
|
872
|
+
function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, chipHeight = CHIP_HEIGHT, chipGap = CHIP_GAP, moreLabel = "{moreCount} More", labels: labelsProp, onPressEvent, onPressMore, selectedRange, selectedDates, highlightWeekends = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onPressCell, onCreateEvent, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, keyboardDayNavigation = false, className, style, classNames, styles }) {
|
|
873
|
+
const { date } = source;
|
|
874
|
+
const multiWeek = source.kind === "multiweek";
|
|
875
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
876
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : void 0;
|
|
877
|
+
const viewMode = multiWeek ? "multiweek" : "month";
|
|
760
878
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
761
879
|
const labels = (0, react.useMemo)(() => (0, _super_calendar_core.resolveCalendarLabels)(labelsProp), [labelsProp]);
|
|
762
880
|
const slot = createSlots({
|
|
763
881
|
classNames,
|
|
764
882
|
styles
|
|
765
883
|
});
|
|
766
|
-
const eventsMode = events !== void 0;
|
|
884
|
+
const eventsMode = events !== void 0 || multiWeek;
|
|
767
885
|
const dayRoving = !eventsMode || keyboardDayNavigation;
|
|
768
886
|
const eventsByDay = (0, react.useMemo)(() => {
|
|
769
887
|
if (eventsByDayProp) return eventsByDayProp;
|
|
@@ -801,20 +919,39 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
801
919
|
document.removeEventListener("keydown", onKey);
|
|
802
920
|
};
|
|
803
921
|
}, [moreOpenFor]);
|
|
804
|
-
const eventRowHeight = 32 + maxVisibleEventCount * (chipHeight + chipGap);
|
|
805
|
-
const { weeks, weekdays } = (0, react.useMemo)(() =>
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
922
|
+
const eventRowHeight = 32 + (multiWeek ? Math.max(1, maxVisibleEventCount) : maxVisibleEventCount) * (chipHeight + chipGap);
|
|
923
|
+
const { weeks, weekdays, title, period } = (0, react.useMemo)(() => {
|
|
924
|
+
const options = {
|
|
925
|
+
weekStartsOn,
|
|
926
|
+
hiddenDays,
|
|
927
|
+
weekdayFormat,
|
|
928
|
+
selectedRange,
|
|
929
|
+
selectedDates,
|
|
930
|
+
minDate,
|
|
931
|
+
maxDate,
|
|
932
|
+
isDateDisabled,
|
|
933
|
+
locale
|
|
934
|
+
};
|
|
935
|
+
if (numberOfWeeks === void 0) return {
|
|
936
|
+
...(0, _super_calendar_core.buildMonthGrid)(date, options),
|
|
937
|
+
title: (0, date_fns.format)(date, "MMMM yyyy", locale ? { locale } : void 0),
|
|
938
|
+
period: null
|
|
939
|
+
};
|
|
940
|
+
const grid = (0, _super_calendar_core.buildMultiWeekGrid)(date, {
|
|
941
|
+
...options,
|
|
942
|
+
numberOfWeeks
|
|
943
|
+
});
|
|
944
|
+
return {
|
|
945
|
+
weeks: grid.weeks,
|
|
946
|
+
weekdays: grid.weekdays,
|
|
947
|
+
title: rangeTitle(grid.visibleRange.start, grid.visibleRange.endExclusive, locale),
|
|
948
|
+
period: grid.period
|
|
949
|
+
};
|
|
950
|
+
}, [
|
|
816
951
|
date,
|
|
952
|
+
numberOfWeeks,
|
|
817
953
|
weekStartsOn,
|
|
954
|
+
hiddenDays,
|
|
818
955
|
weekdayFormat,
|
|
819
956
|
selectedRange,
|
|
820
957
|
selectedDates,
|
|
@@ -828,7 +965,18 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
828
965
|
weeks,
|
|
829
966
|
eventsByDay
|
|
830
967
|
]);
|
|
968
|
+
const focusableDays = (0, react.useMemo)(() => period ? weeks.flatMap((week) => week.days).filter((day) => !day.isDisabled).map((day) => (0, date_fns.startOfDay)(day.date)).sort((a, b) => a.getTime() - b.getTime()) : null, [period, weeks]);
|
|
969
|
+
const focusableKeys = (0, react.useMemo)(() => focusableDays ? new Set(focusableDays.map((d) => (0, date_fns.format)(d, "yyyy-MM-dd"))) : null, [focusableDays]);
|
|
831
970
|
const initialFocus = (0, react.useMemo)(() => {
|
|
971
|
+
if (focusableDays && focusableKeys) {
|
|
972
|
+
const rendered = (d) => !!d && focusableKeys.has((0, date_fns.format)(d, "yyyy-MM-dd"));
|
|
973
|
+
if (rendered(selectedRange?.start)) return (0, date_fns.startOfDay)(selectedRange.start);
|
|
974
|
+
const picked = selectedDates?.find(rendered);
|
|
975
|
+
if (picked) return (0, date_fns.startOfDay)(picked);
|
|
976
|
+
const today = /* @__PURE__ */ new Date();
|
|
977
|
+
if (rendered(today)) return (0, date_fns.startOfDay)(today);
|
|
978
|
+
return focusableDays[0] ?? null;
|
|
979
|
+
}
|
|
832
980
|
const inMonth = (d) => !!d && (0, date_fns.isSameMonth)(d, date);
|
|
833
981
|
if (inMonth(selectedRange?.start)) return (0, date_fns.startOfDay)(selectedRange.start);
|
|
834
982
|
const picked = selectedDates?.find(inMonth);
|
|
@@ -836,6 +984,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
836
984
|
const today = /* @__PURE__ */ new Date();
|
|
837
985
|
return (0, date_fns.isSameMonth)(today, date) ? (0, date_fns.startOfDay)(today) : (0, date_fns.startOfMonth)(date);
|
|
838
986
|
}, [
|
|
987
|
+
focusableDays,
|
|
988
|
+
focusableKeys,
|
|
839
989
|
date,
|
|
840
990
|
selectedRange,
|
|
841
991
|
selectedDates
|
|
@@ -843,11 +993,36 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
843
993
|
const [focusedDate, setFocusedDate] = (0, react.useState)(initialFocus);
|
|
844
994
|
const initialFocusRef = (0, react.useRef)(initialFocus);
|
|
845
995
|
initialFocusRef.current = initialFocus;
|
|
846
|
-
const
|
|
847
|
-
(0, react.
|
|
848
|
-
|
|
996
|
+
const windowKey = period ? `${(0, date_fns.format)(period.start, "yyyy-MM-dd")}+${numberOfWeeks}:${weekdays.map((day) => day.date.getDay()).join(",")}` : (0, date_fns.format)(date, "yyyy-MM");
|
|
997
|
+
const windowKeyRef = (0, react.useRef)(windowKey);
|
|
998
|
+
windowKeyRef.current = windowKey;
|
|
999
|
+
const focusedWindow = (0, react.useRef)(windowKey);
|
|
849
1000
|
const gridRef = (0, react.useRef)(null);
|
|
850
|
-
const
|
|
1001
|
+
const restoreDayFocus = (0, react.useRef)(false);
|
|
1002
|
+
if (multiWeek && windowKey !== focusedWindow.current) {
|
|
1003
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1004
|
+
restoreDayFocus.current = !!active?.hasAttribute("data-day") && !!gridRef.current?.contains(active);
|
|
1005
|
+
}
|
|
1006
|
+
(0, react.useEffect)(() => {
|
|
1007
|
+
if (windowKey === focusedWindow.current) return;
|
|
1008
|
+
focusedWindow.current = windowKey;
|
|
1009
|
+
setFocusedDate(initialFocusRef.current);
|
|
1010
|
+
if (restoreDayFocus.current) {
|
|
1011
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1012
|
+
if (active === gridRef.current?.ownerDocument.body || active && gridRef.current?.contains(active)) (initialFocusRef.current ? gridRef.current?.querySelector(`[data-day="${(0, date_fns.format)(initialFocusRef.current, "yyyy-MM-dd")}"]`) : gridRef.current)?.focus();
|
|
1013
|
+
}
|
|
1014
|
+
restoreDayFocus.current = false;
|
|
1015
|
+
}, [windowKey]);
|
|
1016
|
+
const [hoveredKey, setHoveredKey] = (0, react.useState)(null);
|
|
1017
|
+
const storedFocusKey = focusedDate ? (0, date_fns.format)(focusedDate, "yyyy-MM-dd") : null;
|
|
1018
|
+
const focusKey = focusableKeys && (storedFocusKey === null || !focusableKeys.has(storedFocusKey)) ? initialFocus && (0, date_fns.format)(initialFocus, "yyyy-MM-dd") : storedFocusKey;
|
|
1019
|
+
(0, react.useEffect)(() => {
|
|
1020
|
+
if (!multiWeek) return;
|
|
1021
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1022
|
+
if (!active?.hasAttribute("data-day") || !gridRef.current?.contains(active)) return;
|
|
1023
|
+
if (active.getAttribute("data-day") === focusKey && active.getAttribute("aria-disabled") !== "true") return;
|
|
1024
|
+
(focusKey ? gridRef.current.querySelector(`[data-day="${focusKey}"]`) : gridRef.current)?.focus();
|
|
1025
|
+
}, [multiWeek, focusKey]);
|
|
851
1026
|
const [drag, setDrag] = (0, react.useState)(null);
|
|
852
1027
|
const dragRef = (0, react.useRef)(drag);
|
|
853
1028
|
dragRef.current = drag;
|
|
@@ -869,7 +1044,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
869
1044
|
setDrag({
|
|
870
1045
|
kind: "create",
|
|
871
1046
|
anchor: t,
|
|
872
|
-
hover: t
|
|
1047
|
+
hover: t,
|
|
1048
|
+
windowKey
|
|
873
1049
|
});
|
|
874
1050
|
};
|
|
875
1051
|
const beginMove = (event, day) => {
|
|
@@ -879,7 +1055,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
879
1055
|
kind: "move",
|
|
880
1056
|
event,
|
|
881
1057
|
from: t,
|
|
882
|
-
to: t
|
|
1058
|
+
to: t,
|
|
1059
|
+
windowKey
|
|
883
1060
|
});
|
|
884
1061
|
onDragStart?.(event);
|
|
885
1062
|
};
|
|
@@ -901,6 +1078,70 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
901
1078
|
onSelectDrag?.(new Date(lo), new Date(hi));
|
|
902
1079
|
}
|
|
903
1080
|
};
|
|
1081
|
+
const heldTouch = (0, react.useRef)(null);
|
|
1082
|
+
const heldOrigin = (0, react.useRef)(null);
|
|
1083
|
+
const dayLookup = (0, react.useMemo)(() => new Map(weeks.flatMap((week) => week.days).map((day) => [day.id, day])), [weeks]);
|
|
1084
|
+
const touchHandlers = (0, react.useRef)({
|
|
1085
|
+
beginCreate,
|
|
1086
|
+
beginMove,
|
|
1087
|
+
extendDrag,
|
|
1088
|
+
dayLookup
|
|
1089
|
+
});
|
|
1090
|
+
touchHandlers.current = {
|
|
1091
|
+
beginCreate,
|
|
1092
|
+
beginMove,
|
|
1093
|
+
extendDrag,
|
|
1094
|
+
dayLookup
|
|
1095
|
+
};
|
|
1096
|
+
const pressRow = (event, day, moving) => {
|
|
1097
|
+
if (event.button !== 0 || event.isPrimary === false || heldTouch.current) return;
|
|
1098
|
+
beginPress();
|
|
1099
|
+
const start = () => {
|
|
1100
|
+
if (moving) touchHandlers.current.beginMove(moving, day);
|
|
1101
|
+
else touchHandlers.current.beginCreate(day);
|
|
1102
|
+
};
|
|
1103
|
+
if (!multiWeek || !event.pointerType || event.pointerType === "mouse") {
|
|
1104
|
+
start();
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
heldOrigin.current = {
|
|
1108
|
+
day,
|
|
1109
|
+
event: moving
|
|
1110
|
+
};
|
|
1111
|
+
heldTouch.current = holdDateDrag({
|
|
1112
|
+
box: event.currentTarget,
|
|
1113
|
+
pointerId: event.pointerId,
|
|
1114
|
+
pointerType: event.pointerType,
|
|
1115
|
+
clientX: event.clientX,
|
|
1116
|
+
clientY: event.clientY
|
|
1117
|
+
}, start, (x, y) => {
|
|
1118
|
+
const element = gridRef.current?.ownerDocument.elementFromPoint(x, y)?.closest("[data-day]");
|
|
1119
|
+
if (!element || !gridRef.current?.contains(element)) return;
|
|
1120
|
+
const day = touchHandlers.current.dayLookup.get(element.dataset.day ?? "");
|
|
1121
|
+
if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date);
|
|
1122
|
+
}, () => {
|
|
1123
|
+
dragRef.current = null;
|
|
1124
|
+
setDrag(null);
|
|
1125
|
+
movedRef.current = false;
|
|
1126
|
+
}, () => {
|
|
1127
|
+
heldTouch.current = null;
|
|
1128
|
+
heldOrigin.current = null;
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
(0, react.useEffect)(() => () => {
|
|
1132
|
+
heldTouch.current?.();
|
|
1133
|
+
}, [windowKey]);
|
|
1134
|
+
(0, react.useEffect)(() => {
|
|
1135
|
+
const origin = heldOrigin.current;
|
|
1136
|
+
if (!origin) return;
|
|
1137
|
+
const current = dragRef.current;
|
|
1138
|
+
const destination = current ? new Date(current.kind === "create" ? current.hover : current.to) : origin.day;
|
|
1139
|
+
const enabled = (day) => {
|
|
1140
|
+
const cell = dayLookup.get((0, date_fns.format)(day, "yyyy-MM-dd"));
|
|
1141
|
+
return cell != null && !cell.isDisabled;
|
|
1142
|
+
};
|
|
1143
|
+
if (!enabled(origin.day) || !enabled(destination) || (origin.event ? !events?.includes(origin.event) || !canMove(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
|
|
1144
|
+
});
|
|
904
1145
|
const isDragging = drag !== null;
|
|
905
1146
|
const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
906
1147
|
(0, react.useEffect)(() => {
|
|
@@ -909,6 +1150,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
909
1150
|
const current = dragRef.current;
|
|
910
1151
|
setDrag(null);
|
|
911
1152
|
if (!current || !movedRef.current) return;
|
|
1153
|
+
if (multiWeek && current.windowKey !== windowKeyRef.current) return;
|
|
912
1154
|
suppressClickRef.current = true;
|
|
913
1155
|
if (current.kind === "create") {
|
|
914
1156
|
const range = (0, _super_calendar_core.monthCreateRange)(new Date(current.anchor), new Date(current.hover));
|
|
@@ -924,12 +1166,51 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
924
1166
|
return () => window.removeEventListener("pointerup", finish);
|
|
925
1167
|
}, [
|
|
926
1168
|
isDragging,
|
|
1169
|
+
multiWeek,
|
|
927
1170
|
onCreateEvent,
|
|
928
1171
|
onDragEvent,
|
|
929
1172
|
eventOverlap,
|
|
930
1173
|
events
|
|
931
1174
|
]);
|
|
1175
|
+
const transientWindow = (0, react.useRef)(windowKey);
|
|
1176
|
+
(0, react.useEffect)(() => {
|
|
1177
|
+
if (transientWindow.current === windowKey) return;
|
|
1178
|
+
transientWindow.current = windowKey;
|
|
1179
|
+
if (!multiWeek) return;
|
|
1180
|
+
setDrag(null);
|
|
1181
|
+
setMoreOpenFor(null);
|
|
1182
|
+
}, [multiWeek, windowKey]);
|
|
1183
|
+
const nextMultiWeekFocus = (key) => {
|
|
1184
|
+
if (!focusableDays || !focusableKeys || !period) return void 0;
|
|
1185
|
+
const index = focusableDays.findIndex((d) => (0, date_fns.format)(d, "yyyy-MM-dd") === focusKey);
|
|
1186
|
+
if (index === -1) return null;
|
|
1187
|
+
if (key === "ArrowLeft") return focusableDays[index - 1] ?? null;
|
|
1188
|
+
if (key === "ArrowRight") return focusableDays[index + 1] ?? null;
|
|
1189
|
+
if (key === "Home") return focusableDays[0];
|
|
1190
|
+
if (key === "End") return focusableDays[focusableDays.length - 1];
|
|
1191
|
+
const step = key === "ArrowUp" ? -7 : 7;
|
|
1192
|
+
for (let cursor = (0, date_fns.addDays)(focusableDays[index], step); cursor >= period.start && cursor < period.endExclusive; cursor = (0, date_fns.addDays)(cursor, step)) if (focusableKeys.has((0, date_fns.format)(cursor, "yyyy-MM-dd"))) return cursor;
|
|
1193
|
+
return null;
|
|
1194
|
+
};
|
|
932
1195
|
const onKeyDown = (e) => {
|
|
1196
|
+
if (multiWeek) {
|
|
1197
|
+
if (![
|
|
1198
|
+
"ArrowLeft",
|
|
1199
|
+
"ArrowRight",
|
|
1200
|
+
"ArrowUp",
|
|
1201
|
+
"ArrowDown",
|
|
1202
|
+
"Home",
|
|
1203
|
+
"End"
|
|
1204
|
+
].includes(e.key)) return;
|
|
1205
|
+
e.preventDefault();
|
|
1206
|
+
const target = nextMultiWeekFocus(e.key);
|
|
1207
|
+
if (!target) return;
|
|
1208
|
+
setFocusedDate(target);
|
|
1209
|
+
const targetKey = (0, date_fns.format)(target, "yyyy-MM-dd");
|
|
1210
|
+
gridRef.current?.querySelector(`[data-day="${targetKey}"]`)?.focus();
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
if (!focusedDate) return;
|
|
933
1214
|
let next = null;
|
|
934
1215
|
if (e.key === "ArrowLeft") next = (0, date_fns.addDays)(focusedDate, -1);
|
|
935
1216
|
else if (e.key === "ArrowRight") next = (0, date_fns.addDays)(focusedDate, 1);
|
|
@@ -949,6 +1230,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
949
1230
|
style: {
|
|
950
1231
|
fontFamily: theme.fontFamily,
|
|
951
1232
|
color: theme.text,
|
|
1233
|
+
...multiWeek ? {
|
|
1234
|
+
display: "flex",
|
|
1235
|
+
flexDirection: "column",
|
|
1236
|
+
minHeight: 0
|
|
1237
|
+
} : null,
|
|
952
1238
|
...style
|
|
953
1239
|
},
|
|
954
1240
|
children: [
|
|
@@ -958,13 +1244,13 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
958
1244
|
fontWeight: 700,
|
|
959
1245
|
padding: "10px 14px 6px"
|
|
960
1246
|
} }),
|
|
961
|
-
children:
|
|
1247
|
+
children: title
|
|
962
1248
|
}) : null,
|
|
963
1249
|
showWeekdays ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
964
1250
|
...slot("weekdays", {
|
|
965
1251
|
base: {
|
|
966
1252
|
display: "grid",
|
|
967
|
-
gridTemplateColumns:
|
|
1253
|
+
gridTemplateColumns: `repeat(${weekdays.length}, minmax(0, 1fr))`
|
|
968
1254
|
},
|
|
969
1255
|
themed: {
|
|
970
1256
|
borderBottom: `1px solid ${theme.gridLine}`,
|
|
@@ -984,9 +1270,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
984
1270
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
985
1271
|
ref: gridRef,
|
|
986
1272
|
role: "grid",
|
|
987
|
-
|
|
1273
|
+
tabIndex: multiWeek ? -1 : void 0,
|
|
1274
|
+
"aria-label": title,
|
|
988
1275
|
onKeyDown: dayRoving ? onKeyDown : void 0,
|
|
989
|
-
...slot("grid"
|
|
1276
|
+
...slot("grid", multiWeek ? { base: {
|
|
1277
|
+
flex: "1 1 auto",
|
|
1278
|
+
minHeight: 0,
|
|
1279
|
+
overflowY: "auto"
|
|
1280
|
+
} } : void 0),
|
|
990
1281
|
children: weeks.map((week, weekIndex) => {
|
|
991
1282
|
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
992
1283
|
const visibleLanes = rowLayout.laneCount > maxVisibleEventCount ? Math.max(maxVisibleEventCount - 1, 1) : rowLayout.laneCount;
|
|
@@ -994,8 +1285,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
994
1285
|
let firstVisCol = 0;
|
|
995
1286
|
let lastVisCol = cols - 1;
|
|
996
1287
|
if (eventsMode && !showAdjacentMonths) {
|
|
997
|
-
const first = week.days.findIndex((d) => d
|
|
998
|
-
const lastFromEnd = [...week.days].reverse().findIndex((d) => d
|
|
1288
|
+
const first = week.days.findIndex((d) => !isOutsidePeriod(d));
|
|
1289
|
+
const lastFromEnd = [...week.days].reverse().findIndex((d) => !isOutsidePeriod(d));
|
|
999
1290
|
if (first !== -1) {
|
|
1000
1291
|
firstVisCol = first;
|
|
1001
1292
|
lastVisCol = cols - 1 - lastFromEnd;
|
|
@@ -1018,10 +1309,10 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1018
1309
|
role: "row",
|
|
1019
1310
|
...slot("week", { base: {
|
|
1020
1311
|
display: "grid",
|
|
1021
|
-
gridTemplateColumns:
|
|
1312
|
+
gridTemplateColumns: `repeat(${week.days.length}, minmax(0, 1fr))`
|
|
1022
1313
|
} }),
|
|
1023
1314
|
children: week.days.map((day, dayCol) => {
|
|
1024
|
-
const hidden = !showAdjacentMonths &&
|
|
1315
|
+
const hidden = !showAdjacentMonths && isOutsidePeriod(day);
|
|
1025
1316
|
const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
|
|
1026
1317
|
if (hidden) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1027
1318
|
role: "gridcell",
|
|
@@ -1043,7 +1334,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1043
1334
|
"data-selected": day.isSelected,
|
|
1044
1335
|
"data-range": day.isInRange,
|
|
1045
1336
|
"data-weekend": day.isWeekend,
|
|
1046
|
-
"data-outside":
|
|
1337
|
+
"data-outside": isOutsidePeriod(day),
|
|
1047
1338
|
"data-disabled": day.isDisabled,
|
|
1048
1339
|
"data-creating": inCreate,
|
|
1049
1340
|
"data-drop": isDropTarget
|
|
@@ -1056,6 +1347,9 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1056
1347
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1057
1348
|
role: "gridcell",
|
|
1058
1349
|
"data-day": day.id,
|
|
1350
|
+
onFocus: (event) => {
|
|
1351
|
+
if (event.target === event.currentTarget) setFocusedDate(day.date);
|
|
1352
|
+
},
|
|
1059
1353
|
...dayData,
|
|
1060
1354
|
tabIndex: keyboardDayNavigation ? day.id === focusKey ? 0 : -1 : void 0,
|
|
1061
1355
|
"aria-disabled": day.isDisabled || void 0,
|
|
@@ -1069,13 +1363,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1069
1363
|
...dayCellProps,
|
|
1070
1364
|
style: dragWired ? {
|
|
1071
1365
|
...dayCellProps.style,
|
|
1072
|
-
touchAction: "none",
|
|
1366
|
+
touchAction: multiWeek ? "pan-y" : "none",
|
|
1073
1367
|
userSelect: "none"
|
|
1074
1368
|
} : dayCellProps.style,
|
|
1075
1369
|
onPointerDown: dragWired && !day.isDisabled ? (e) => {
|
|
1076
|
-
|
|
1077
|
-
beginPress();
|
|
1078
|
-
beginCreate(day.date);
|
|
1370
|
+
pressRow(e, day.date);
|
|
1079
1371
|
} : void 0,
|
|
1080
1372
|
onPointerEnter: dragWired && !day.isDisabled ? () => extendDrag(day.date) : void 0,
|
|
1081
1373
|
onClick: day.isDisabled ? void 0 : () => {
|
|
@@ -1110,8 +1402,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1110
1402
|
onPointerDown: canMove(b.seg.event) ? (e) => {
|
|
1111
1403
|
if (e.button !== 0) return;
|
|
1112
1404
|
e.stopPropagation();
|
|
1113
|
-
|
|
1114
|
-
beginMove(b.seg.event, day.date);
|
|
1405
|
+
pressRow(e, day.date, b.seg.event);
|
|
1115
1406
|
} : void 0,
|
|
1116
1407
|
onClick: (e) => {
|
|
1117
1408
|
e.stopPropagation();
|
|
@@ -1121,7 +1412,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1121
1412
|
...barChipButton,
|
|
1122
1413
|
title: b.seg.event.title,
|
|
1123
1414
|
"aria-label": eventAccessibilityLabel ? eventAccessibilityLabel(b.seg.event, {
|
|
1124
|
-
mode:
|
|
1415
|
+
mode: viewMode,
|
|
1125
1416
|
isAllDay: (0, _super_calendar_core.isAllDayEvent)(b.seg.event),
|
|
1126
1417
|
ampm: false
|
|
1127
1418
|
}) : `${b.seg.event.title}, ${dayLabel}`,
|
|
@@ -1135,10 +1426,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1135
1426
|
pointerEvents: isDragging ? "none" : "auto",
|
|
1136
1427
|
opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
|
|
1137
1428
|
cursor: canMove(b.seg.event) ? "grab" : void 0,
|
|
1138
|
-
touchAction: dragWired ? "none" : void 0,
|
|
1429
|
+
touchAction: dragWired ? multiWeek ? "pan-y" : "none" : void 0,
|
|
1139
1430
|
zIndex: 2
|
|
1140
1431
|
},
|
|
1141
1432
|
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
1433
|
+
mode: viewMode,
|
|
1142
1434
|
event: b.seg.event,
|
|
1143
1435
|
onPress: () => onPressEvent?.(b.seg.event)
|
|
1144
1436
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -1180,7 +1472,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1180
1472
|
setMoreOpenFor((open) => open === day.id ? null : day.id);
|
|
1181
1473
|
}
|
|
1182
1474
|
},
|
|
1183
|
-
...slot("more", moreButtonDefault(theme, chipHeight)),
|
|
1475
|
+
...slot("more", moreButtonDefault(theme, chipHeight, multiWeek)),
|
|
1184
1476
|
"aria-label": `${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`,
|
|
1185
1477
|
"aria-expanded": onPressMore ? void 0 : moreOpenFor === day.id,
|
|
1186
1478
|
children: moreLabel.replace("{moreCount}", String(hiddenEvents.length))
|
|
@@ -1249,6 +1541,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1249
1541
|
cursor: "pointer"
|
|
1250
1542
|
},
|
|
1251
1543
|
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
1544
|
+
mode: viewMode,
|
|
1252
1545
|
event,
|
|
1253
1546
|
onPress: () => onPressEvent?.(event)
|
|
1254
1547
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -1266,11 +1559,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1266
1559
|
type: "button",
|
|
1267
1560
|
role: "gridcell",
|
|
1268
1561
|
"data-day": day.id,
|
|
1562
|
+
onFocus: (event) => {
|
|
1563
|
+
if (event.target === event.currentTarget) setFocusedDate(day.date);
|
|
1564
|
+
},
|
|
1269
1565
|
...dayData,
|
|
1270
1566
|
tabIndex: day.id === focusKey ? 0 : -1,
|
|
1271
1567
|
"aria-disabled": day.isDisabled || void 0,
|
|
1272
1568
|
"aria-label": label,
|
|
1273
|
-
"aria-
|
|
1569
|
+
"aria-selected": day.isSelected || day.isInRange,
|
|
1274
1570
|
...slot("day", dayCellDefault(day, theme, highlightWeekends)),
|
|
1275
1571
|
onClick: day.isDisabled ? void 0 : () => {
|
|
1276
1572
|
onPressDay?.(day.date);
|
|
@@ -1295,52 +1591,419 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1295
1591
|
]
|
|
1296
1592
|
});
|
|
1297
1593
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1594
|
+
// src/MultiWeekView.tsx
|
|
1595
|
+
/**
|
|
1596
|
+
* Consecutive full weeks as stacked seven-day rows, with event chips and no hour
|
|
1597
|
+
* slots. It has the month grid's event bars, overflow, selection, and drag
|
|
1598
|
+
* interactions, and the month slots, `renderEvent`, and theme style it. Every
|
|
1599
|
+
* row is kept at full height; when the view is given less room, the rows scroll
|
|
1600
|
+
* under the title and weekday header.
|
|
1601
|
+
*
|
|
1602
|
+
* Standalone, it shows `events` as given; expand recurring events first with
|
|
1603
|
+
* `expandRecurringEvents`, or use `Calendar` with `mode="multiweek"`.
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```tsx
|
|
1607
|
+
* <MultiWeekView date={new Date()} numberOfWeeks={3} events={events} />
|
|
1608
|
+
* ```
|
|
1609
|
+
*/
|
|
1610
|
+
function MultiWeekView({ date, numberOfWeeks = 2, chipHeight = 24, ...rest }) {
|
|
1611
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateRows, {
|
|
1612
|
+
...rest,
|
|
1613
|
+
chipHeight,
|
|
1614
|
+
source: {
|
|
1615
|
+
kind: "multiweek",
|
|
1616
|
+
date,
|
|
1617
|
+
numberOfWeeks
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
// src/EventActions.tsx
|
|
1622
|
+
function moveFocus(event, container) {
|
|
1623
|
+
const buttons = [...container?.querySelectorAll("button") ?? []];
|
|
1624
|
+
const index = buttons.indexOf(document.activeElement);
|
|
1625
|
+
const target = event.key === "ArrowDown" ? buttons[(index + 1) % buttons.length] : event.key === "ArrowUp" ? buttons[index < 0 ? buttons.length - 1 : (index - 1 + buttons.length) % buttons.length] : event.key === "Home" ? buttons[0] : event.key === "End" ? buttons[buttons.length - 1] : void 0;
|
|
1626
|
+
if (!target) return;
|
|
1627
|
+
event.preventDefault();
|
|
1628
|
+
target.focus();
|
|
1629
|
+
}
|
|
1630
|
+
function describeEventDates(event) {
|
|
1631
|
+
const start = (0, date_fns.format)(event.start, "yyyy-MM-dd");
|
|
1632
|
+
const end = (0, date_fns.format)(event.end, "yyyy-MM-dd");
|
|
1633
|
+
return start === end ? start : `${start} - ${end}`;
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Open/close state for one component's actions dialog. `commit` applies an
|
|
1637
|
+
* action through the component's drag path and returns a matcher for the event
|
|
1638
|
+
* the consumer will render in its place, or null when the change was refused.
|
|
1639
|
+
* The dialog follows that replacement so repeated steps keep working, and
|
|
1640
|
+
* closes when its event disappears or can no longer be edited.
|
|
1641
|
+
*/
|
|
1642
|
+
function useEventActions(events, actionsFor, commit, getEventId) {
|
|
1643
|
+
const [openEvent, setOpenEvent] = (0, react.useState)(null);
|
|
1644
|
+
const [rejections, setRejections] = (0, react.useState)(0);
|
|
1645
|
+
const identity = (0, react.useRef)(null);
|
|
1646
|
+
const openRef = (0, react.useRef)(null);
|
|
1647
|
+
const show = (event) => {
|
|
1648
|
+
openRef.current = event;
|
|
1649
|
+
setOpenEvent(event);
|
|
1307
1650
|
};
|
|
1308
|
-
const
|
|
1309
|
-
|
|
1310
|
-
|
|
1651
|
+
const triggers = (0, react.useRef)(/* @__PURE__ */ new WeakMap());
|
|
1652
|
+
const dialogRef = (0, react.useRef)(null);
|
|
1653
|
+
const rootRef = (0, react.useRef)(null);
|
|
1654
|
+
const pending = (0, react.useRef)(null);
|
|
1655
|
+
const current = () => {
|
|
1656
|
+
const event = openRef.current;
|
|
1657
|
+
if (!event) return void 0;
|
|
1658
|
+
if (identity.current) {
|
|
1659
|
+
if (!getEventId) return void 0;
|
|
1660
|
+
const id = identity.current.id;
|
|
1661
|
+
const matches = events.filter((candidate) => getEventId(candidate) === id);
|
|
1662
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
1663
|
+
}
|
|
1664
|
+
if (getEventId) return void 0;
|
|
1665
|
+
if (events.includes(event)) return event;
|
|
1666
|
+
const committed = pending.current;
|
|
1667
|
+
if (committed?.from !== event) return void 0;
|
|
1668
|
+
if (committed.events.some((previous) => previous !== event && !events.includes(previous))) return void 0;
|
|
1669
|
+
const replacements = events.filter((candidate) => !committed.events.includes(candidate) && committed.matches(candidate));
|
|
1670
|
+
return replacements.length === 1 ? replacements[0] : void 0;
|
|
1311
1671
|
};
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1672
|
+
const close = (restoreFocus, fallbackToRoot = false) => {
|
|
1673
|
+
const event = openRef.current;
|
|
1674
|
+
if (!event) return;
|
|
1675
|
+
const shown = current() ?? event;
|
|
1676
|
+
pending.current = null;
|
|
1677
|
+
const dialog = dialogRef.current;
|
|
1678
|
+
if (dialog?.open) {
|
|
1679
|
+
if (typeof dialog.close === "function") dialog.close();
|
|
1680
|
+
else dialog.removeAttribute("open");
|
|
1681
|
+
}
|
|
1682
|
+
if (restoreFocus) {
|
|
1683
|
+
const trigger = triggers.current.get(shown);
|
|
1684
|
+
(fallbackToRoot ? rootRef.current : trigger?.isConnected ? trigger : [...rootRef.current?.querySelectorAll("button:not(:disabled), [tabindex=\"0\"]") ?? []].find((element) => !dialog?.contains(element)) ?? rootRef.current)?.focus();
|
|
1685
|
+
}
|
|
1686
|
+
show(null);
|
|
1314
1687
|
};
|
|
1315
|
-
|
|
1316
|
-
if (
|
|
1317
|
-
|
|
1318
|
-
|
|
1688
|
+
(0, react.useEffect)(() => {
|
|
1689
|
+
if (!openRef.current) return;
|
|
1690
|
+
const next = current();
|
|
1691
|
+
if (pending.current && pending.current.events !== events) pending.current = null;
|
|
1692
|
+
if (next && actionsFor(next).length > 0) {
|
|
1693
|
+
if (next !== openEvent) show(next);
|
|
1694
|
+
return;
|
|
1319
1695
|
}
|
|
1696
|
+
close(document.activeElement === document.body || !!dialogRef.current?.contains(document.activeElement), true);
|
|
1697
|
+
});
|
|
1698
|
+
const run = (actionId) => {
|
|
1699
|
+
const event = current();
|
|
1700
|
+
if (!event) return;
|
|
1701
|
+
openRef.current = event;
|
|
1702
|
+
pending.current = null;
|
|
1703
|
+
const matches = commit(event, actionId);
|
|
1704
|
+
setRejections((count) => matches ? 0 : count + 1);
|
|
1705
|
+
if (matches) pending.current = {
|
|
1706
|
+
from: event,
|
|
1707
|
+
events,
|
|
1708
|
+
matches
|
|
1709
|
+
};
|
|
1320
1710
|
};
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1711
|
+
const select = (event, trigger) => {
|
|
1712
|
+
const id = getEventId?.(event);
|
|
1713
|
+
identity.current = typeof id === "string" || typeof id === "number" ? { id } : null;
|
|
1714
|
+
setRejections(0);
|
|
1715
|
+
triggers.current.set(event, trigger);
|
|
1716
|
+
show(event);
|
|
1323
1717
|
};
|
|
1324
|
-
|
|
1325
|
-
|
|
1718
|
+
return {
|
|
1719
|
+
openEvent,
|
|
1720
|
+
close,
|
|
1721
|
+
run,
|
|
1722
|
+
select,
|
|
1723
|
+
dialogRef,
|
|
1724
|
+
rootRef,
|
|
1725
|
+
rejections
|
|
1326
1726
|
};
|
|
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
1727
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1728
|
+
function EventActionsMenu({ events, label, labelFor, descriptionFor, onSelect, rootRef, slot, theme }) {
|
|
1729
|
+
const [expanded, setExpanded] = (0, react.useState)(false);
|
|
1730
|
+
const trigger = (0, react.useRef)(null);
|
|
1731
|
+
const listRef = (0, react.useRef)(null);
|
|
1732
|
+
(0, react.useEffect)(() => {
|
|
1733
|
+
if (expanded) listRef.current?.querySelector("button")?.focus();
|
|
1734
|
+
}, [expanded]);
|
|
1735
|
+
const id = (0, react.useId)();
|
|
1736
|
+
const focused = (0, react.useRef)(null);
|
|
1737
|
+
const keys = (0, react.useRef)(/* @__PURE__ */ new WeakMap());
|
|
1738
|
+
const nextKey = (0, react.useRef)(0);
|
|
1739
|
+
const keyFor = (event) => {
|
|
1740
|
+
let key = keys.current.get(event);
|
|
1741
|
+
if (key === void 0) {
|
|
1742
|
+
key = nextKey.current++;
|
|
1743
|
+
keys.current.set(event, key);
|
|
1744
|
+
}
|
|
1745
|
+
return key;
|
|
1746
|
+
};
|
|
1747
|
+
(0, react.useEffect)(() => {
|
|
1748
|
+
const previous = focused.current;
|
|
1749
|
+
if (!previous || document.activeElement !== document.body) return;
|
|
1750
|
+
(previous.isConnected ? previous : trigger.current ?? rootRef.current)?.focus();
|
|
1751
|
+
});
|
|
1752
|
+
if (!events.length) return null;
|
|
1753
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1754
|
+
onFocusCapture: (e) => {
|
|
1755
|
+
focused.current = e.target;
|
|
1756
|
+
},
|
|
1757
|
+
onBlurCapture: (e) => {
|
|
1758
|
+
if (e.relatedTarget && !e.currentTarget.contains(e.relatedTarget)) focused.current = null;
|
|
1759
|
+
},
|
|
1760
|
+
onKeyDown: (e) => {
|
|
1761
|
+
if (!expanded) return;
|
|
1762
|
+
if (e.key !== "Escape") {
|
|
1763
|
+
moveFocus(e, listRef.current);
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
e.preventDefault();
|
|
1767
|
+
e.stopPropagation();
|
|
1768
|
+
setExpanded(false);
|
|
1769
|
+
trigger.current?.focus();
|
|
1770
|
+
},
|
|
1771
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1772
|
+
ref: trigger,
|
|
1773
|
+
id,
|
|
1774
|
+
type: "button",
|
|
1775
|
+
"aria-expanded": expanded,
|
|
1776
|
+
"aria-controls": expanded ? id + "-list" : void 0,
|
|
1777
|
+
onClick: () => setExpanded(!expanded),
|
|
1778
|
+
...slot("eventActionsTrigger", {
|
|
1779
|
+
base: {
|
|
1780
|
+
minHeight: 32,
|
|
1781
|
+
font: "inherit",
|
|
1782
|
+
cursor: "pointer"
|
|
1783
|
+
},
|
|
1784
|
+
themed: {
|
|
1785
|
+
margin: "4px 0",
|
|
1786
|
+
padding: "4px 10px",
|
|
1787
|
+
border: `1px solid ${theme.gridLine}`,
|
|
1788
|
+
borderRadius: 6,
|
|
1789
|
+
background: theme.surface,
|
|
1790
|
+
color: theme.text
|
|
1791
|
+
}
|
|
1792
|
+
}),
|
|
1793
|
+
children: label
|
|
1794
|
+
}), expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1795
|
+
ref: listRef,
|
|
1796
|
+
id: id + "-list",
|
|
1797
|
+
role: "group",
|
|
1798
|
+
"aria-labelledby": id,
|
|
1799
|
+
...slot("eventActionsList", {
|
|
1800
|
+
base: {
|
|
1801
|
+
display: "flex",
|
|
1802
|
+
flexDirection: "column",
|
|
1803
|
+
gap: 4,
|
|
1804
|
+
maxHeight: "min(20rem, 50vh)",
|
|
1805
|
+
overflowY: "auto"
|
|
1806
|
+
},
|
|
1807
|
+
themed: {
|
|
1808
|
+
padding: 4,
|
|
1809
|
+
background: theme.surface,
|
|
1810
|
+
border: `1px solid ${theme.gridLine}`,
|
|
1811
|
+
borderRadius: 6
|
|
1812
|
+
}
|
|
1813
|
+
}),
|
|
1814
|
+
children: events.map((event, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1815
|
+
type: "button",
|
|
1816
|
+
"aria-haspopup": "dialog",
|
|
1817
|
+
"aria-label": labelFor(event),
|
|
1818
|
+
"aria-describedby": id + "-" + index,
|
|
1819
|
+
onClick: () => {
|
|
1820
|
+
setExpanded(false);
|
|
1821
|
+
focused.current = null;
|
|
1822
|
+
onSelect(event, trigger.current);
|
|
1823
|
+
},
|
|
1824
|
+
...slot("eventAction", {
|
|
1825
|
+
base: {
|
|
1826
|
+
minHeight: 32,
|
|
1827
|
+
flexShrink: 0,
|
|
1828
|
+
overflowWrap: "anywhere",
|
|
1829
|
+
font: "inherit",
|
|
1830
|
+
cursor: "pointer",
|
|
1831
|
+
textAlign: "left"
|
|
1832
|
+
},
|
|
1833
|
+
themed: {
|
|
1834
|
+
padding: "6px 10px",
|
|
1835
|
+
border: `1px solid ${theme.gridLine}`,
|
|
1836
|
+
borderRadius: 6,
|
|
1837
|
+
background: theme.surface,
|
|
1838
|
+
color: theme.text
|
|
1839
|
+
}
|
|
1840
|
+
}),
|
|
1841
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: labelFor(event) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
1842
|
+
id: id + "-" + index,
|
|
1843
|
+
style: { display: "block" },
|
|
1844
|
+
children: descriptionFor(event)
|
|
1845
|
+
})]
|
|
1846
|
+
}, keyFor(event)))
|
|
1847
|
+
}) : null]
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
/** The modal dialog listing an event's move and resize actions. */
|
|
1851
|
+
function EventActionsDialog({ dialogRef, title, description, actions, closeLabel, rejectedLabel, rejections, onAction, onClose, slot, theme }) {
|
|
1852
|
+
const titleId = (0, react.useId)();
|
|
1853
|
+
const descriptionId = (0, react.useId)();
|
|
1854
|
+
(0, react.useEffect)(() => {
|
|
1855
|
+
const dialog = dialogRef.current;
|
|
1856
|
+
if (!dialog || dialog.open) return;
|
|
1857
|
+
if (typeof dialog.showModal === "function") dialog.showModal();
|
|
1858
|
+
else dialog.setAttribute("open", "");
|
|
1859
|
+
}, [dialogRef]);
|
|
1860
|
+
(0, react.useEffect)(() => {
|
|
1861
|
+
const dialog = dialogRef.current;
|
|
1862
|
+
if (dialog && !dialog.contains(document.activeElement)) dialog.querySelector("button")?.focus();
|
|
1863
|
+
});
|
|
1864
|
+
const buttonSlot = (available) => slot("eventAction", {
|
|
1865
|
+
base: {
|
|
1866
|
+
display: "block",
|
|
1867
|
+
width: "100%",
|
|
1868
|
+
minHeight: 32,
|
|
1869
|
+
boxSizing: "border-box",
|
|
1870
|
+
textAlign: "left",
|
|
1871
|
+
font: "inherit",
|
|
1872
|
+
cursor: available ? "pointer" : "default"
|
|
1873
|
+
},
|
|
1874
|
+
themed: {
|
|
1875
|
+
padding: "6px 10px",
|
|
1876
|
+
border: `1px solid ${theme.gridLine}`,
|
|
1877
|
+
borderRadius: 8,
|
|
1878
|
+
background: theme.surface,
|
|
1879
|
+
color: theme.text,
|
|
1880
|
+
fontSize: 13,
|
|
1881
|
+
opacity: available ? 1 : .5
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dialog", {
|
|
1885
|
+
ref: dialogRef,
|
|
1886
|
+
"aria-labelledby": titleId,
|
|
1887
|
+
"aria-describedby": descriptionId,
|
|
1888
|
+
onClose: () => onClose(),
|
|
1889
|
+
onCancel: (e) => {
|
|
1890
|
+
e.preventDefault();
|
|
1891
|
+
onClose();
|
|
1892
|
+
},
|
|
1893
|
+
onClick: (e) => {
|
|
1894
|
+
if (e.target === e.currentTarget) onClose();
|
|
1895
|
+
},
|
|
1896
|
+
onKeyDown: (e) => {
|
|
1897
|
+
if (e.key === "PageUp" || e.key === "PageDown") e.stopPropagation();
|
|
1898
|
+
if (e.key === "Escape") {
|
|
1899
|
+
e.preventDefault();
|
|
1900
|
+
e.stopPropagation();
|
|
1901
|
+
onClose();
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
moveFocus(e, e.currentTarget);
|
|
1905
|
+
},
|
|
1906
|
+
...slot("eventActions", {
|
|
1907
|
+
base: {
|
|
1908
|
+
margin: "auto",
|
|
1909
|
+
overflowWrap: "anywhere",
|
|
1910
|
+
padding: 0,
|
|
1911
|
+
width: "max-content",
|
|
1912
|
+
maxWidth: "min(22rem, calc(100vw - 32px))",
|
|
1913
|
+
maxHeight: "calc(100vh - 32px)",
|
|
1914
|
+
overflowY: "auto",
|
|
1915
|
+
boxSizing: "border-box"
|
|
1916
|
+
},
|
|
1917
|
+
themed: {
|
|
1918
|
+
fontFamily: theme.fontFamily,
|
|
1919
|
+
background: theme.surface,
|
|
1920
|
+
color: theme.text,
|
|
1921
|
+
border: `1px solid ${theme.gridLine}`,
|
|
1922
|
+
borderRadius: 12,
|
|
1923
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.18)"
|
|
1924
|
+
}
|
|
1925
|
+
}),
|
|
1926
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1927
|
+
style: {
|
|
1928
|
+
display: "flex",
|
|
1929
|
+
flexDirection: "column",
|
|
1930
|
+
gap: 6,
|
|
1931
|
+
padding: 12
|
|
1932
|
+
},
|
|
1933
|
+
children: [
|
|
1934
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1935
|
+
id: titleId,
|
|
1936
|
+
style: {
|
|
1937
|
+
margin: 0,
|
|
1938
|
+
fontWeight: 600,
|
|
1939
|
+
fontSize: 14
|
|
1940
|
+
},
|
|
1941
|
+
children: title
|
|
1942
|
+
}),
|
|
1943
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1944
|
+
id: descriptionId,
|
|
1945
|
+
"aria-live": "polite",
|
|
1946
|
+
style: {
|
|
1947
|
+
margin: "0 0 4px",
|
|
1948
|
+
fontSize: 12,
|
|
1949
|
+
color: theme.textMuted
|
|
1950
|
+
},
|
|
1951
|
+
children: description
|
|
1952
|
+
}),
|
|
1953
|
+
actions.map((action) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1954
|
+
type: "button",
|
|
1955
|
+
"data-action": action.id,
|
|
1956
|
+
"aria-disabled": action.available ? void 0 : true,
|
|
1957
|
+
onClick: () => {
|
|
1958
|
+
if (action.available) onAction(action.id);
|
|
1959
|
+
},
|
|
1960
|
+
...buttonSlot(action.available),
|
|
1961
|
+
children: action.label
|
|
1962
|
+
}, action.id)),
|
|
1963
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1964
|
+
role: "status",
|
|
1965
|
+
"aria-atomic": "true",
|
|
1966
|
+
style: { fontSize: 13 },
|
|
1967
|
+
children: rejections > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: rejectedLabel }, rejections) : null
|
|
1968
|
+
}),
|
|
1969
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1970
|
+
type: "button",
|
|
1971
|
+
"data-action": "close",
|
|
1972
|
+
onClick: () => onClose(),
|
|
1973
|
+
...buttonSlot(true),
|
|
1974
|
+
children: closeLabel
|
|
1975
|
+
})
|
|
1976
|
+
]
|
|
1977
|
+
})
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
// src/InertDiv.ts
|
|
1981
|
+
function InertDiv(props) {
|
|
1982
|
+
return (0, react.createElement)("div", {
|
|
1983
|
+
...props,
|
|
1984
|
+
inert: props.inert ? "inert" : void 0
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
// src/TimeGrid.tsx
|
|
1339
1988
|
const GUTTER_WIDTH$1 = 56;
|
|
1340
1989
|
const HOURS_PER_DAY = 24;
|
|
1341
1990
|
const DEFAULT_MIN_EVENT_HEIGHT = 14;
|
|
1342
1991
|
const DEFAULT_EVENT_GAP = 1;
|
|
1343
1992
|
const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
1993
|
+
const CREATE_PREVIEW_MIN_HEIGHT = 2;
|
|
1994
|
+
function createPreviewPlacement(topPx, heightPx, gridHeight) {
|
|
1995
|
+
const start = clamp$1(topPx, 0, gridHeight);
|
|
1996
|
+
const end = clamp$1(topPx + heightPx, 0, gridHeight);
|
|
1997
|
+
const height = Math.min(gridHeight, Math.max(end - start, CREATE_PREVIEW_MIN_HEIGHT));
|
|
1998
|
+
const top = Math.min(start, gridHeight - height);
|
|
1999
|
+
return top + height / 2 > gridHeight / 2 ? {
|
|
2000
|
+
bottom: gridHeight - top - height,
|
|
2001
|
+
height
|
|
2002
|
+
} : {
|
|
2003
|
+
top,
|
|
2004
|
+
height
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
1344
2007
|
const EDGE_ZONE = 32;
|
|
1345
2008
|
const EDGE_DWELL_MS = 600;
|
|
1346
2009
|
const EDGE_REPEAT_MS = 600;
|
|
@@ -1443,7 +2106,7 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
|
|
|
1443
2106
|
* ```
|
|
1444
2107
|
*/
|
|
1445
2108
|
const TimeGrid = (0, react.forwardRef)(TimeGridInner);
|
|
1446
|
-
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) {
|
|
2109
|
+
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, renderCreateGhost, onDragStart, onDragEvent, getEventId, onChangeDate, className, style, classNames, styles }, ref) {
|
|
1447
2110
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
1448
2111
|
const labels = (0, react.useMemo)(() => (0, _super_calendar_core.resolveCalendarLabels)(labelsProp), [labelsProp]);
|
|
1449
2112
|
const slot = createSlots({
|
|
@@ -1459,6 +2122,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1459
2122
|
const windowHours = windowEnd - windowStart;
|
|
1460
2123
|
const gutterWidth = hideHours ? 0 : GUTTER_WIDTH$1;
|
|
1461
2124
|
const RenderBackground = renderBackgroundEvent;
|
|
2125
|
+
const RenderCreateGhost = renderCreateGhost;
|
|
1462
2126
|
const visibleHours = (0, react.useMemo)(() => Array.from({ length: windowHours }, (_, i) => windowStart + i), [windowStart, windowHours]);
|
|
1463
2127
|
const now = (0, _super_calendar_core.useNow)(showNowIndicator, {
|
|
1464
2128
|
now: nowProp,
|
|
@@ -1477,7 +2141,22 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1477
2141
|
};
|
|
1478
2142
|
const [createBox, setCreateBox] = (0, react.useState)(null);
|
|
1479
2143
|
const createOrigin = (0, react.useRef)(null);
|
|
1480
|
-
const
|
|
2144
|
+
const createActive = createBox !== null;
|
|
2145
|
+
(0, react.useEffect)(() => {
|
|
2146
|
+
if (!createActive) return;
|
|
2147
|
+
const onScroll = () => {
|
|
2148
|
+
const origin = createOrigin.current;
|
|
2149
|
+
if (!origin) return;
|
|
2150
|
+
const curPx = origin.clientY - origin.el.getBoundingClientRect().top;
|
|
2151
|
+
setCreateBox((current) => current && current.curPx !== curPx ? {
|
|
2152
|
+
...current,
|
|
2153
|
+
curPx
|
|
2154
|
+
} : current);
|
|
2155
|
+
};
|
|
2156
|
+
window.addEventListener("scroll", onScroll, true);
|
|
2157
|
+
return () => window.removeEventListener("scroll", onScroll, true);
|
|
2158
|
+
}, [createActive]);
|
|
2159
|
+
const cellTouchRef = (0, react.useRef)(null);
|
|
1481
2160
|
const cellEnabled = !!onPressCell || !!onCreateEvent;
|
|
1482
2161
|
const days = (0, react.useMemo)(() => (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays, false, void 0, hiddenDays), [
|
|
1483
2162
|
mode,
|
|
@@ -1521,6 +2200,62 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1521
2200
|
onChangeDateRef.current = onChangeDate;
|
|
1522
2201
|
const onDragEventRef = (0, react.useRef)(onDragEvent);
|
|
1523
2202
|
onDragEventRef.current = onDragEvent && eventOverlap === false ? (event, start, end) => (0, _super_calendar_core.overlapsOtherEvents)(events, event, start, end) ? false : onDragEvent(event, start, end) : onDragEvent;
|
|
2203
|
+
const editability = (event) => {
|
|
2204
|
+
const editable = !!onDragEvent && event.draggable !== false;
|
|
2205
|
+
return {
|
|
2206
|
+
canMove: editable && (event.startEditable ?? eventStartEditable),
|
|
2207
|
+
canResize: editable && (event.durationEditable ?? eventDurationEditable)
|
|
2208
|
+
};
|
|
2209
|
+
};
|
|
2210
|
+
const eventLabel = (event) => eventAccessibilityLabel ? eventAccessibilityLabel(event, {
|
|
2211
|
+
mode,
|
|
2212
|
+
isAllDay: false,
|
|
2213
|
+
ampm
|
|
2214
|
+
}) : (0, _super_calendar_core.eventAccessibilityLabel)({
|
|
2215
|
+
title: event.title,
|
|
2216
|
+
isAllDay: false,
|
|
2217
|
+
start: event.start,
|
|
2218
|
+
end: event.end,
|
|
2219
|
+
ampm,
|
|
2220
|
+
labels
|
|
2221
|
+
});
|
|
2222
|
+
const eventDescription = (event) => `${describeEventDates(event)}, ${eventLabel(event)}`;
|
|
2223
|
+
const pageDays = (0, _super_calendar_core.pageStepDays)(mode, date, weekStartsOn, numberOfDays);
|
|
2224
|
+
const actionDelta = (id) => {
|
|
2225
|
+
const page = pageDays * HOURS_PER_DAY * 60;
|
|
2226
|
+
switch (id) {
|
|
2227
|
+
case "move-later": return [snapMinutes, snapMinutes];
|
|
2228
|
+
case "move-earlier": return [-snapMinutes, -snapMinutes];
|
|
2229
|
+
case "extend": return [0, snapMinutes];
|
|
2230
|
+
case "shorten": return [0, -snapMinutes];
|
|
2231
|
+
case "move-next-page": return [page, page];
|
|
2232
|
+
case "move-previous-page": return [-page, -page];
|
|
2233
|
+
default: return null;
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
const editActions = (event) => {
|
|
2237
|
+
if ((0, _super_calendar_core.isAllDayEvent)(event) || (0, _super_calendar_core.isBackgroundEvent)(event)) return [];
|
|
2238
|
+
const { canMove, canResize } = editability(event);
|
|
2239
|
+
const action = (id, label) => {
|
|
2240
|
+
const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
|
|
2241
|
+
return {
|
|
2242
|
+
id,
|
|
2243
|
+
label,
|
|
2244
|
+
available: (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, startDelta, endDelta, snapMinutes) !== null
|
|
2245
|
+
};
|
|
2246
|
+
};
|
|
2247
|
+
return [
|
|
2248
|
+
...canMove ? [action("move-later", labels.moveLater(snapMinutes)), action("move-earlier", labels.moveEarlier(snapMinutes))] : [],
|
|
2249
|
+
...canResize ? [action("extend", labels.extend(snapMinutes)), action("shorten", labels.shorten(snapMinutes))] : [],
|
|
2250
|
+
...canMove ? [action("move-next-page", labels.moveToNextPage(pageDays, mode)), action("move-previous-page", labels.moveToPreviousPage(pageDays, mode))] : []
|
|
2251
|
+
];
|
|
2252
|
+
};
|
|
2253
|
+
const eventActions = useEventActions(events, editActions, (event, id) => {
|
|
2254
|
+
const delta = actionDelta(id);
|
|
2255
|
+
const next = delta && (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, delta[0], delta[1], snapMinutes);
|
|
2256
|
+
if (!next || onDragEventRef.current?.(event, next.start, next.end) === false) return null;
|
|
2257
|
+
return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title;
|
|
2258
|
+
}, getEventId);
|
|
1524
2259
|
const allDayByDay = (0, react.useMemo)(() => days.map((day) => {
|
|
1525
2260
|
const dayStart = (0, date_fns.startOfDay)(day);
|
|
1526
2261
|
const dayEnd = (0, date_fns.addDays)(dayStart, 1);
|
|
@@ -1877,15 +2612,21 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1877
2612
|
try {
|
|
1878
2613
|
el.setPointerCapture?.(e.pointerId);
|
|
1879
2614
|
} catch {}
|
|
2615
|
+
const dayTime = days[dayIndex].getTime();
|
|
1880
2616
|
createOrigin.current = {
|
|
2617
|
+
pointerId: e.pointerId,
|
|
2618
|
+
clientY: e.clientY,
|
|
1881
2619
|
el,
|
|
1882
2620
|
dayIndex,
|
|
2621
|
+
dayTime,
|
|
2622
|
+
creating: !!onCreateEvent,
|
|
1883
2623
|
startPx
|
|
1884
2624
|
};
|
|
1885
2625
|
setCreateBox({
|
|
1886
2626
|
dayIndex,
|
|
1887
|
-
|
|
1888
|
-
|
|
2627
|
+
dayTime,
|
|
2628
|
+
startPx,
|
|
2629
|
+
curPx: startPx
|
|
1889
2630
|
});
|
|
1890
2631
|
};
|
|
1891
2632
|
const moveCreate = (e) => {
|
|
@@ -1893,11 +2634,12 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1893
2634
|
if (touch && e.pointerId === touch.pointerId && Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX) cellTouchRef.current = null;
|
|
1894
2635
|
const o = createOrigin.current;
|
|
1895
2636
|
if (!o) return;
|
|
1896
|
-
|
|
2637
|
+
o.clientY = e.clientY;
|
|
1897
2638
|
setCreateBox({
|
|
1898
2639
|
dayIndex: o.dayIndex,
|
|
1899
|
-
|
|
1900
|
-
|
|
2640
|
+
dayTime: o.dayTime,
|
|
2641
|
+
startPx: o.startPx,
|
|
2642
|
+
curPx: pxFromTop(o.el, e.clientY)
|
|
1901
2643
|
});
|
|
1902
2644
|
};
|
|
1903
2645
|
const endCreate = (e) => {
|
|
@@ -1929,11 +2671,43 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1929
2671
|
const at = (0, _super_calendar_core.cellRangeFromDrag)(day, px, px, hourHeightRef.current, windowStart, snapMinutes);
|
|
1930
2672
|
if (at) onPressCell(at.start);
|
|
1931
2673
|
};
|
|
1932
|
-
const
|
|
1933
|
-
|
|
2674
|
+
const clearCreate = (0, react.useCallback)(() => {
|
|
2675
|
+
const previous = createOrigin.current;
|
|
1934
2676
|
createOrigin.current = null;
|
|
1935
2677
|
setCreateBox(null);
|
|
2678
|
+
try {
|
|
2679
|
+
previous?.el.releasePointerCapture?.(previous.pointerId);
|
|
2680
|
+
} catch {}
|
|
2681
|
+
}, []);
|
|
2682
|
+
const cancelCreate = () => {
|
|
2683
|
+
cellTouchRef.current = null;
|
|
2684
|
+
clearCreate();
|
|
2685
|
+
};
|
|
2686
|
+
const loseCreateCapture = (e) => {
|
|
2687
|
+
if (createOrigin.current?.pointerId !== e.pointerId) return;
|
|
2688
|
+
clearCreate();
|
|
1936
2689
|
};
|
|
2690
|
+
(0, react.useEffect)(() => {
|
|
2691
|
+
const onKeyDown = (event) => {
|
|
2692
|
+
if (event.key !== "Escape" || !createOrigin.current) return;
|
|
2693
|
+
event.preventDefault();
|
|
2694
|
+
event.stopPropagation();
|
|
2695
|
+
clearCreate();
|
|
2696
|
+
};
|
|
2697
|
+
document.addEventListener("keydown", onKeyDown);
|
|
2698
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
2699
|
+
}, [clearCreate]);
|
|
2700
|
+
const liveRange = createBox && RenderCreateGhost && onCreateEvent && days[createBox.dayIndex]?.getTime() === createBox.dayTime ? (0, _super_calendar_core.cellRangeFromDrag)(days[createBox.dayIndex], createBox.startPx, createBox.curPx, hourHeight, windowStart, snapMinutes) : null;
|
|
2701
|
+
const liveStart = liveRange?.start.getTime();
|
|
2702
|
+
const liveEnd = liveRange?.end.getTime();
|
|
2703
|
+
const createRange = (0, react.useMemo)(() => liveStart === void 0 || liveEnd === void 0 ? null : {
|
|
2704
|
+
start: new Date(liveStart),
|
|
2705
|
+
end: new Date(liveEnd)
|
|
2706
|
+
}, [liveStart, liveEnd]);
|
|
2707
|
+
(0, react.useEffect)(() => {
|
|
2708
|
+
const origin = createOrigin.current;
|
|
2709
|
+
if (origin && (!origin.el.isConnected || !cellEnabled || origin.creating && !onCreateEvent || days[origin.dayIndex]?.getTime() !== origin.dayTime)) clearCreate();
|
|
2710
|
+
});
|
|
1937
2711
|
const positionedByDay = (0, react.useMemo)(() => days.map((day) => (0, _super_calendar_core.layoutDayEvents)(events, day)), [days, events]);
|
|
1938
2712
|
const moveOrigin = dragOrigin.current;
|
|
1939
2713
|
const heldEvent = draggedRef.current?.event;
|
|
@@ -2060,7 +2834,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2060
2834
|
timeslots,
|
|
2061
2835
|
theme.gridLine
|
|
2062
2836
|
]);
|
|
2837
|
+
const openActionsEvent = eventActions.openEvent;
|
|
2063
2838
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2839
|
+
ref: eventActions.rootRef,
|
|
2840
|
+
tabIndex: -1,
|
|
2064
2841
|
className,
|
|
2065
2842
|
style: {
|
|
2066
2843
|
fontFamily: theme.fontFamily,
|
|
@@ -2070,6 +2847,16 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2070
2847
|
...style
|
|
2071
2848
|
},
|
|
2072
2849
|
children: [
|
|
2850
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsMenu, {
|
|
2851
|
+
events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
|
|
2852
|
+
label: labels.editEvents,
|
|
2853
|
+
labelFor: (event) => labels.eventActions(event.title ?? ""),
|
|
2854
|
+
descriptionFor: eventDescription,
|
|
2855
|
+
onSelect: eventActions.select,
|
|
2856
|
+
rootRef: eventActions.rootRef,
|
|
2857
|
+
slot,
|
|
2858
|
+
theme
|
|
2859
|
+
}),
|
|
2073
2860
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2074
2861
|
...slot("header", {
|
|
2075
2862
|
base: { display: "flex" },
|
|
@@ -2281,7 +3068,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2281
3068
|
const showNow = showNowIndicator && (0, _super_calendar_core.isSameCalendarDay)(day, now) && nowHours >= windowStart && nowHours <= windowEnd;
|
|
2282
3069
|
const nowTop = (nowHours - windowStart) * hourHeight;
|
|
2283
3070
|
const bands = bandsByDay[dayIndex];
|
|
2284
|
-
const ghost = createBox?.dayIndex === dayIndex ? createBox : null;
|
|
3071
|
+
const ghost = createBox?.dayIndex === dayIndex && createBox.dayTime === day.getTime() ? createBox : null;
|
|
3072
|
+
const ghostRange = ghost ? createRange : null;
|
|
2285
3073
|
const spill = multiDayMove ? null : spillPreviewFor(dayIndex);
|
|
2286
3074
|
const moveSegment = multiDayMove ? (0, _super_calendar_core.layoutDayEvents)([multiDayMove], day)[0] : void 0;
|
|
2287
3075
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -2290,6 +3078,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2290
3078
|
onPointerMove: cellEnabled ? moveCreate : void 0,
|
|
2291
3079
|
onPointerUp: cellEnabled ? endCreate : void 0,
|
|
2292
3080
|
onPointerCancel: cellEnabled ? cancelCreate : void 0,
|
|
3081
|
+
onLostPointerCapture: cellEnabled ? loseCreateCapture : void 0,
|
|
2293
3082
|
onClick: cellEnabled ? (e) => tapCell(e, dayIndex) : void 0,
|
|
2294
3083
|
...dataState({
|
|
2295
3084
|
"data-today": (0, _super_calendar_core.getIsToday)(day),
|
|
@@ -2399,25 +3188,12 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2399
3188
|
ampm,
|
|
2400
3189
|
onPress
|
|
2401
3190
|
};
|
|
2402
|
-
const
|
|
2403
|
-
const canMove = editable && (pe.event.startEditable ?? eventStartEditable);
|
|
2404
|
-
const canResize = editable && (pe.event.durationEditable ?? eventDurationEditable);
|
|
3191
|
+
const { canMove, canResize } = editability(pe.event);
|
|
2405
3192
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2406
3193
|
role: "button",
|
|
2407
3194
|
tabIndex: 0,
|
|
2408
3195
|
"data-event-key": keyboardEventNavigation ? key : void 0,
|
|
2409
|
-
"aria-label":
|
|
2410
|
-
mode,
|
|
2411
|
-
isAllDay: false,
|
|
2412
|
-
ampm
|
|
2413
|
-
}) : (0, _super_calendar_core.eventAccessibilityLabel)({
|
|
2414
|
-
title: pe.event.title,
|
|
2415
|
-
isAllDay: false,
|
|
2416
|
-
start: pe.event.start,
|
|
2417
|
-
end: pe.event.end,
|
|
2418
|
-
ampm,
|
|
2419
|
-
labels
|
|
2420
|
-
}),
|
|
3196
|
+
"aria-label": eventLabel(pe.event),
|
|
2421
3197
|
onKeyDown: (e) => {
|
|
2422
3198
|
if (e.key === "Enter" || e.key === " ") {
|
|
2423
3199
|
e.preventDefault();
|
|
@@ -2559,15 +3335,17 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2559
3335
|
background: theme.nowIndicator
|
|
2560
3336
|
} })]
|
|
2561
3337
|
}) : null,
|
|
2562
|
-
ghost ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
3338
|
+
ghost ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InertDiv, {
|
|
2563
3339
|
"aria-hidden": true,
|
|
3340
|
+
inert: !!ghostRange,
|
|
2564
3341
|
...slot("createGhost", {
|
|
2565
3342
|
base: {
|
|
2566
3343
|
position: "absolute",
|
|
2567
3344
|
left: eventGap,
|
|
2568
3345
|
right: eventGap,
|
|
2569
|
-
|
|
2570
|
-
|
|
3346
|
+
...createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
|
|
3347
|
+
boxSizing: "border-box",
|
|
3348
|
+
...ghostRange ? { overflow: "hidden" } : null,
|
|
2571
3349
|
opacity: .7,
|
|
2572
3350
|
pointerEvents: "none",
|
|
2573
3351
|
zIndex: 2
|
|
@@ -2577,7 +3355,11 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2577
3355
|
border: `1px solid ${theme.selectedBackground}`,
|
|
2578
3356
|
borderRadius: 6
|
|
2579
3357
|
}
|
|
2580
|
-
})
|
|
3358
|
+
}),
|
|
3359
|
+
children: ghostRange && RenderCreateGhost ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderCreateGhost, {
|
|
3360
|
+
start: ghostRange.start,
|
|
3361
|
+
end: ghostRange.end
|
|
3362
|
+
}) : null
|
|
2581
3363
|
}) : null
|
|
2582
3364
|
]
|
|
2583
3365
|
}, day.toISOString());
|
|
@@ -2615,23 +3397,43 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2615
3397
|
theme,
|
|
2616
3398
|
boxProps: slot("eventBox")
|
|
2617
3399
|
})
|
|
3400
|
+
}) : null,
|
|
3401
|
+
openActionsEvent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsDialog, {
|
|
3402
|
+
dialogRef: eventActions.dialogRef,
|
|
3403
|
+
title: labels.eventActions(openActionsEvent.title ?? ""),
|
|
3404
|
+
description: eventDescription(openActionsEvent),
|
|
3405
|
+
actions: editActions(openActionsEvent),
|
|
3406
|
+
closeLabel: labels.close,
|
|
3407
|
+
rejectedLabel: labels.eventChangeRejected,
|
|
3408
|
+
rejections: eventActions.rejections,
|
|
3409
|
+
onAction: eventActions.run,
|
|
3410
|
+
onClose: () => eventActions.close(true),
|
|
3411
|
+
slot,
|
|
3412
|
+
theme
|
|
2618
3413
|
}) : null
|
|
2619
3414
|
]
|
|
2620
3415
|
});
|
|
2621
3416
|
}
|
|
2622
|
-
|
|
2623
|
-
//#region src/Calendar.tsx
|
|
3417
|
+
// src/Calendar.tsx
|
|
2624
3418
|
const EMPTY_EVENTS = [];
|
|
2625
|
-
function expansionRange(mode, date, weekStartsOn, numberOfDays) {
|
|
3419
|
+
function expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
3420
|
+
if (mode === "multiweek") {
|
|
3421
|
+
const { period } = (0, _super_calendar_core.buildMultiWeekGrid)(date, {
|
|
3422
|
+
weekStartsOn,
|
|
3423
|
+
numberOfWeeks
|
|
3424
|
+
});
|
|
3425
|
+
return [period.start, (0, date_fns.endOfDay)((0, date_fns.addDays)(period.endExclusive, -1))];
|
|
3426
|
+
}
|
|
2626
3427
|
if (mode === "month") return [(0, date_fns.startOfWeek)((0, date_fns.startOfMonth)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfMonth)(date), { weekStartsOn })];
|
|
2627
3428
|
if (mode === "year") return [(0, date_fns.startOfWeek)((0, date_fns.startOfYear)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfYear)(date), { weekStartsOn })];
|
|
2628
3429
|
if (mode === "schedule") return [(0, date_fns.startOfDay)(date), (0, date_fns.endOfDay)((0, date_fns.addMonths)(date, 3))];
|
|
2629
3430
|
const days = (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1);
|
|
2630
3431
|
return [(0, date_fns.startOfDay)(days[0]), (0, date_fns.endOfDay)(days[days.length - 1])];
|
|
2631
3432
|
}
|
|
2632
|
-
function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
3433
|
+
function pageStep(mode, date, direction, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
2633
3434
|
if (mode === "year") return (0, date_fns.addYears)(date, direction);
|
|
2634
3435
|
if (mode === "month") return (0, date_fns.addMonths)(date, direction);
|
|
3436
|
+
if (mode === "multiweek") return (0, date_fns.addWeeks)(date, direction * numberOfWeeks);
|
|
2635
3437
|
if (mode === "schedule") return (0, date_fns.addDays)(date, direction * 7);
|
|
2636
3438
|
return (0, date_fns.addDays)(date, direction * (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1).length);
|
|
2637
3439
|
}
|
|
@@ -2647,13 +3449,13 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
|
2647
3449
|
* ```
|
|
2648
3450
|
*/
|
|
2649
3451
|
const Calendar = (0, react.forwardRef)(CalendarInner);
|
|
2650
|
-
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) {
|
|
3452
|
+
function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, hiddenDays, now, numberOfDays, numberOfWeeks = 2, 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, renderCreateGhost, onDragStart, onDragEvent, getEventId, 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) {
|
|
2651
3453
|
const timeGridRef = (0, react.useRef)(null);
|
|
2652
3454
|
(0, react.useImperativeHandle)(ref, () => ({ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options) }), []);
|
|
2653
3455
|
const displayEvents = (0, react.useMemo)(() => {
|
|
2654
3456
|
let out = events ?? EMPTY_EVENTS;
|
|
2655
3457
|
if (out.some((e) => e.recurrence)) {
|
|
2656
|
-
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays);
|
|
3458
|
+
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
|
|
2657
3459
|
if (timeZone) {
|
|
2658
3460
|
start = (0, date_fns.addDays)(start, -1);
|
|
2659
3461
|
end = (0, date_fns.addDays)(end, 1);
|
|
@@ -2668,12 +3470,13 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
2668
3470
|
date.getTime(),
|
|
2669
3471
|
weekStartsOn,
|
|
2670
3472
|
numberOfDays,
|
|
3473
|
+
numberOfWeeks,
|
|
2671
3474
|
timeZone
|
|
2672
3475
|
]);
|
|
2673
3476
|
const handlePageKeys = (e) => {
|
|
2674
3477
|
if (!onChangeDate) return;
|
|
2675
|
-
if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays));
|
|
2676
|
-
else if (e.key === "PageUp") onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays));
|
|
3478
|
+
if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
3479
|
+
else if (e.key === "PageUp") onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
2677
3480
|
else return;
|
|
2678
3481
|
e.preventDefault();
|
|
2679
3482
|
};
|
|
@@ -2759,6 +3562,49 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
2759
3562
|
renderEvent: renderMonthEvent,
|
|
2760
3563
|
eventAccessibilityLabel
|
|
2761
3564
|
});
|
|
3565
|
+
else if (mode === "multiweek") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MultiWeekView, {
|
|
3566
|
+
date,
|
|
3567
|
+
numberOfWeeks,
|
|
3568
|
+
events: displayEvents,
|
|
3569
|
+
weekStartsOn,
|
|
3570
|
+
hiddenDays,
|
|
3571
|
+
weekdayFormat,
|
|
3572
|
+
highlightWeekends,
|
|
3573
|
+
locale,
|
|
3574
|
+
labels,
|
|
3575
|
+
theme,
|
|
3576
|
+
className,
|
|
3577
|
+
style: height != null ? {
|
|
3578
|
+
height,
|
|
3579
|
+
...style
|
|
3580
|
+
} : style,
|
|
3581
|
+
classNames,
|
|
3582
|
+
styles,
|
|
3583
|
+
maxVisibleEventCount,
|
|
3584
|
+
chipHeight,
|
|
3585
|
+
chipGap,
|
|
3586
|
+
moreLabel,
|
|
3587
|
+
showTitle,
|
|
3588
|
+
fillCellOnSelection,
|
|
3589
|
+
selectedRange,
|
|
3590
|
+
selectedDates,
|
|
3591
|
+
minDate,
|
|
3592
|
+
maxDate,
|
|
3593
|
+
isDateDisabled,
|
|
3594
|
+
keyboardDayNavigation,
|
|
3595
|
+
onPressDay,
|
|
3596
|
+
onPressCell,
|
|
3597
|
+
onCreateEvent,
|
|
3598
|
+
onSelectDrag,
|
|
3599
|
+
onDragEvent,
|
|
3600
|
+
onDragStart,
|
|
3601
|
+
eventStartEditable,
|
|
3602
|
+
eventOverlap,
|
|
3603
|
+
onPressEvent,
|
|
3604
|
+
onPressMore,
|
|
3605
|
+
renderEvent: renderMonthEvent,
|
|
3606
|
+
eventAccessibilityLabel
|
|
3607
|
+
});
|
|
2762
3608
|
else view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TimeGrid, {
|
|
2763
3609
|
ref: timeGridRef,
|
|
2764
3610
|
date,
|
|
@@ -2805,8 +3651,10 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
2805
3651
|
onPressEvent,
|
|
2806
3652
|
onPressCell,
|
|
2807
3653
|
onCreateEvent,
|
|
3654
|
+
renderCreateGhost,
|
|
2808
3655
|
onDragStart,
|
|
2809
3656
|
onDragEvent,
|
|
3657
|
+
getEventId,
|
|
2810
3658
|
onChangeDate,
|
|
2811
3659
|
onPressDateHeader,
|
|
2812
3660
|
renderEvent: renderTimeEvent,
|
|
@@ -2820,8 +3668,7 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
2820
3668
|
children: view
|
|
2821
3669
|
});
|
|
2822
3670
|
}
|
|
2823
|
-
|
|
2824
|
-
//#region src/MonthList.tsx
|
|
3671
|
+
// src/MonthList.tsx
|
|
2825
3672
|
/**
|
|
2826
3673
|
* A vertically scrolling, virtualized list of months: the date picker. Built on
|
|
2827
3674
|
* Legend List's DOM renderer and the library's headless grid logic. Selection is
|
|
@@ -2858,18 +3705,61 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
|
|
|
2858
3705
|
for (const list of map.values()) list.sort(_super_calendar_core.compareDayEvents);
|
|
2859
3706
|
return map;
|
|
2860
3707
|
}, [events]);
|
|
2861
|
-
const
|
|
2862
|
-
|
|
2863
|
-
|
|
3708
|
+
const renderMonth = (0, react.useCallback)(({ item }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthView, {
|
|
3709
|
+
date: item,
|
|
3710
|
+
weekStartsOn,
|
|
3711
|
+
highlightWeekends,
|
|
2864
3712
|
events,
|
|
3713
|
+
eventsByDay,
|
|
3714
|
+
renderEvent,
|
|
3715
|
+
eventAccessibilityLabel,
|
|
3716
|
+
maxVisibleEventCount,
|
|
2865
3717
|
chipHeight,
|
|
2866
|
-
chipGap
|
|
2867
|
-
|
|
3718
|
+
chipGap,
|
|
3719
|
+
moreLabel,
|
|
3720
|
+
labels,
|
|
3721
|
+
onPressEvent,
|
|
3722
|
+
onPressMore,
|
|
2868
3723
|
selectedRange,
|
|
2869
3724
|
selectedDates,
|
|
3725
|
+
fillCellOnSelection,
|
|
3726
|
+
showAdjacentMonths: false,
|
|
3727
|
+
showWeekdays: false,
|
|
3728
|
+
locale,
|
|
3729
|
+
theme: themeOverrides,
|
|
3730
|
+
minDate,
|
|
3731
|
+
maxDate,
|
|
3732
|
+
isDateDisabled,
|
|
3733
|
+
keyboardDayNavigation,
|
|
3734
|
+
onPressDay,
|
|
3735
|
+
classNames,
|
|
3736
|
+
styles
|
|
3737
|
+
}), [
|
|
3738
|
+
weekStartsOn,
|
|
3739
|
+
highlightWeekends,
|
|
2870
3740
|
events,
|
|
3741
|
+
eventsByDay,
|
|
3742
|
+
renderEvent,
|
|
3743
|
+
eventAccessibilityLabel,
|
|
3744
|
+
maxVisibleEventCount,
|
|
2871
3745
|
chipHeight,
|
|
2872
|
-
chipGap
|
|
3746
|
+
chipGap,
|
|
3747
|
+
moreLabel,
|
|
3748
|
+
labels,
|
|
3749
|
+
onPressEvent,
|
|
3750
|
+
onPressMore,
|
|
3751
|
+
selectedRange,
|
|
3752
|
+
selectedDates,
|
|
3753
|
+
fillCellOnSelection,
|
|
3754
|
+
locale,
|
|
3755
|
+
themeOverrides,
|
|
3756
|
+
minDate,
|
|
3757
|
+
maxDate,
|
|
3758
|
+
isDateDisabled,
|
|
3759
|
+
keyboardDayNavigation,
|
|
3760
|
+
onPressDay,
|
|
3761
|
+
classNames,
|
|
3762
|
+
styles
|
|
2873
3763
|
]);
|
|
2874
3764
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2875
3765
|
className,
|
|
@@ -2900,7 +3790,7 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
|
|
|
2900
3790
|
}, wd.label))
|
|
2901
3791
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_legendapp_list_react.LegendList, {
|
|
2902
3792
|
data: months,
|
|
2903
|
-
extraData,
|
|
3793
|
+
extraData: renderMonth,
|
|
2904
3794
|
keyExtractor: (m) => m.toISOString(),
|
|
2905
3795
|
recycleItems: false,
|
|
2906
3796
|
estimatedItemSize: theme.cellHeight * 7 + 40,
|
|
@@ -2909,41 +3799,11 @@ function MonthList({ date, pastMonths = 1, futureMonths = 12, weekdayFormat = "s
|
|
|
2909
3799
|
height,
|
|
2910
3800
|
overflowY: "auto"
|
|
2911
3801
|
},
|
|
2912
|
-
renderItem:
|
|
2913
|
-
date: item,
|
|
2914
|
-
weekStartsOn,
|
|
2915
|
-
highlightWeekends,
|
|
2916
|
-
events,
|
|
2917
|
-
eventsByDay,
|
|
2918
|
-
renderEvent,
|
|
2919
|
-
eventAccessibilityLabel,
|
|
2920
|
-
maxVisibleEventCount,
|
|
2921
|
-
chipHeight,
|
|
2922
|
-
chipGap,
|
|
2923
|
-
moreLabel,
|
|
2924
|
-
labels,
|
|
2925
|
-
onPressEvent,
|
|
2926
|
-
onPressMore,
|
|
2927
|
-
selectedRange,
|
|
2928
|
-
selectedDates,
|
|
2929
|
-
fillCellOnSelection,
|
|
2930
|
-
showAdjacentMonths: false,
|
|
2931
|
-
showWeekdays: false,
|
|
2932
|
-
locale,
|
|
2933
|
-
theme: themeOverrides,
|
|
2934
|
-
minDate,
|
|
2935
|
-
maxDate,
|
|
2936
|
-
isDateDisabled,
|
|
2937
|
-
keyboardDayNavigation,
|
|
2938
|
-
onPressDay,
|
|
2939
|
-
classNames,
|
|
2940
|
-
styles
|
|
2941
|
-
})
|
|
3802
|
+
renderItem: renderMonth
|
|
2942
3803
|
})]
|
|
2943
3804
|
});
|
|
2944
3805
|
}
|
|
2945
|
-
|
|
2946
|
-
//#region src/DateRangePicker.tsx
|
|
3806
|
+
// src/DateRangePicker.tsx
|
|
2947
3807
|
const triggerDefault = {
|
|
2948
3808
|
display: "inline-flex",
|
|
2949
3809
|
alignItems: "center",
|
|
@@ -2964,17 +3824,25 @@ const popoverDefault = {
|
|
|
2964
3824
|
borderRadius: 12,
|
|
2965
3825
|
minWidth: 300
|
|
2966
3826
|
};
|
|
3827
|
+
function initialPickerFocus(dialog, day) {
|
|
3828
|
+
const usable = ":not([aria-disabled=\"true\"]):not([data-outside])";
|
|
3829
|
+
return dialog.querySelector(`[data-day="${day}"]${usable}`) ?? dialog.querySelector(`[data-day^="${day.slice(0, 7)}"][tabindex="0"]${usable}`) ?? dialog.querySelector(`[data-day^="${day.slice(0, 7)}"]${usable}`);
|
|
3830
|
+
}
|
|
2967
3831
|
/**
|
|
2968
3832
|
* The shared popover shell: a trigger button and a calendar panel that closes on
|
|
2969
3833
|
* outside-click and Escape, and returns focus to the trigger. `renderCalendar`
|
|
2970
3834
|
* gets a close callback so a single-date pick can dismiss immediately.
|
|
2971
3835
|
*/
|
|
2972
|
-
function usePopover() {
|
|
3836
|
+
function usePopover(disabled) {
|
|
2973
3837
|
const [open, setOpen] = (0, react.useState)(false);
|
|
2974
3838
|
const rootRef = (0, react.useRef)(null);
|
|
2975
3839
|
const triggerRef = (0, react.useRef)(null);
|
|
2976
3840
|
(0, react.useEffect)(() => {
|
|
2977
3841
|
if (!open) return;
|
|
3842
|
+
if (disabled) {
|
|
3843
|
+
setOpen(false);
|
|
3844
|
+
return;
|
|
3845
|
+
}
|
|
2978
3846
|
const onDown = (e) => {
|
|
2979
3847
|
if (!rootRef.current?.contains(e.target)) setOpen(false);
|
|
2980
3848
|
};
|
|
@@ -2990,16 +3858,43 @@ function usePopover() {
|
|
|
2990
3858
|
document.removeEventListener("mousedown", onDown);
|
|
2991
3859
|
document.removeEventListener("keydown", onKey);
|
|
2992
3860
|
};
|
|
2993
|
-
}, [open]);
|
|
3861
|
+
}, [open, disabled]);
|
|
2994
3862
|
return {
|
|
2995
|
-
open,
|
|
3863
|
+
open: open && !disabled,
|
|
2996
3864
|
setOpen,
|
|
2997
3865
|
rootRef,
|
|
2998
3866
|
triggerRef
|
|
2999
3867
|
};
|
|
3000
3868
|
}
|
|
3001
|
-
function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, hasValue, placeholder, disabled, className, style, ariaLabel, children }) {
|
|
3869
|
+
function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, hasValue, placeholder, disabled, className, style, ariaLabel, focusDay, children }) {
|
|
3002
3870
|
const dialogId = (0, react.useId)();
|
|
3871
|
+
const dialogRef = (0, react.useRef)(null);
|
|
3872
|
+
const focusDayRef = (0, react.useRef)(focusDay);
|
|
3873
|
+
focusDayRef.current = focusDay;
|
|
3874
|
+
(0, react.useEffect)(() => {
|
|
3875
|
+
if (!open) return;
|
|
3876
|
+
const dialog = dialogRef.current;
|
|
3877
|
+
if (!dialog) return;
|
|
3878
|
+
const place = () => {
|
|
3879
|
+
if (dialog.contains(document.activeElement)) {
|
|
3880
|
+
observer.disconnect();
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
const target = initialPickerFocus(dialog, focusDayRef.current);
|
|
3884
|
+
const monthMounted = dialog.querySelector(`[data-day^="${focusDayRef.current.slice(0, 7)}"]:not([data-outside])`);
|
|
3885
|
+
if (target || monthMounted) {
|
|
3886
|
+
(target ?? dialog).focus();
|
|
3887
|
+
observer.disconnect();
|
|
3888
|
+
}
|
|
3889
|
+
};
|
|
3890
|
+
const observer = new MutationObserver(place);
|
|
3891
|
+
observer.observe(dialog, {
|
|
3892
|
+
childList: true,
|
|
3893
|
+
subtree: true
|
|
3894
|
+
});
|
|
3895
|
+
place();
|
|
3896
|
+
return () => observer.disconnect();
|
|
3897
|
+
}, [open]);
|
|
3003
3898
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3004
3899
|
ref: rootRef,
|
|
3005
3900
|
className,
|
|
@@ -3031,8 +3926,10 @@ function PickerShell({ open, setOpen, rootRef, triggerRef, theme, slot, label, h
|
|
|
3031
3926
|
children: "▾"
|
|
3032
3927
|
})]
|
|
3033
3928
|
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3929
|
+
ref: dialogRef,
|
|
3034
3930
|
id: dialogId,
|
|
3035
3931
|
role: "dialog",
|
|
3932
|
+
tabIndex: -1,
|
|
3036
3933
|
"aria-label": ariaLabel,
|
|
3037
3934
|
...slot("popover", {
|
|
3038
3935
|
base: popoverDefault,
|
|
@@ -3062,7 +3959,7 @@ function DatePicker({ value, onChange, formatLabel = (d) => (0, date_fns.format)
|
|
|
3062
3959
|
classNames,
|
|
3063
3960
|
styles
|
|
3064
3961
|
});
|
|
3065
|
-
const { open, setOpen, rootRef, triggerRef } = usePopover();
|
|
3962
|
+
const { open, setOpen, rootRef, triggerRef } = usePopover(disabled);
|
|
3066
3963
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PickerShell, {
|
|
3067
3964
|
open,
|
|
3068
3965
|
setOpen,
|
|
@@ -3077,7 +3974,9 @@ function DatePicker({ value, onChange, formatLabel = (d) => (0, date_fns.format)
|
|
|
3077
3974
|
className,
|
|
3078
3975
|
style,
|
|
3079
3976
|
ariaLabel: "Choose a date",
|
|
3977
|
+
focusDay: (0, date_fns.format)(value ?? /* @__PURE__ */ new Date(), "yyyy-MM-dd"),
|
|
3080
3978
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthList, {
|
|
3979
|
+
theme: themeOverrides,
|
|
3081
3980
|
date: value ?? /* @__PURE__ */ new Date(),
|
|
3082
3981
|
weekStartsOn,
|
|
3083
3982
|
selectedDates: value ? [value] : [],
|
|
@@ -3116,7 +4015,7 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
|
|
|
3116
4015
|
classNames,
|
|
3117
4016
|
styles
|
|
3118
4017
|
});
|
|
3119
|
-
const { open, setOpen, rootRef, triggerRef } = usePopover();
|
|
4018
|
+
const { open, setOpen, rootRef, triggerRef } = usePopover(disabled);
|
|
3120
4019
|
const constraints = {
|
|
3121
4020
|
minDate,
|
|
3122
4021
|
maxDate,
|
|
@@ -3136,7 +4035,9 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
|
|
|
3136
4035
|
className,
|
|
3137
4036
|
style,
|
|
3138
4037
|
ariaLabel: "Choose a date range",
|
|
4038
|
+
focusDay: (0, date_fns.format)(value?.start ?? /* @__PURE__ */ new Date(), "yyyy-MM-dd"),
|
|
3139
4039
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthList, {
|
|
4040
|
+
theme: themeOverrides,
|
|
3140
4041
|
date: value?.start ?? /* @__PURE__ */ new Date(),
|
|
3141
4042
|
weekStartsOn,
|
|
3142
4043
|
selectedRange: value ?? void 0,
|
|
@@ -3180,8 +4081,7 @@ function DateRangePicker({ value, onChange, formatLabel = defaultRangeLabel, wee
|
|
|
3180
4081
|
})]
|
|
3181
4082
|
});
|
|
3182
4083
|
}
|
|
3183
|
-
|
|
3184
|
-
//#region src/ResourceTimeline.tsx
|
|
4084
|
+
// src/ResourceTimeline.tsx
|
|
3185
4085
|
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
3186
4086
|
const GUTTER_WIDTH = 56;
|
|
3187
4087
|
function DefaultBar({ event, height, boxProps, theme }) {
|
|
@@ -3250,7 +4150,7 @@ function DefaultBar({ event, height, boxProps, theme }) {
|
|
|
3250
4150
|
* />
|
|
3251
4151
|
* ```
|
|
3252
4152
|
*/
|
|
3253
|
-
function ResourceTimeline({ date, orientation = "horizontal", resources: allResources, resourcesPerPage, resourcePage = 0, events, resourceId = (event) => event.resourceId, startHour = 0, endHour = 24, hourWidth = 80, hourHeight = 48, rowHeight = 56, labelWidth = 140, ampm = false, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, onPressCell, onCreateEvent, businessHours, renderBusinessHours, renderResourceHeader, dragStepMinutes = 15, showNowIndicator = true, now: nowProp, timeZone, className, style, classNames, styles }) {
|
|
4153
|
+
function ResourceTimeline({ date, orientation = "horizontal", resources: allResources, resourcesPerPage, resourcePage = 0, events, resourceId = (event) => event.resourceId, startHour = 0, endHour = 24, hourWidth = 80, hourHeight = 48, rowHeight = 56, labelWidth = 140, ampm = false, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, getEventId, onPressCell, onCreateEvent, renderCreateGhost, businessHours, renderBusinessHours, renderResourceHeader, dragStepMinutes = 15, labels: labelsProp, showNowIndicator = true, now: nowProp, timeZone, className, style, classNames, styles }) {
|
|
3254
4154
|
const resources = (0, react.useMemo)(() => {
|
|
3255
4155
|
if (!resourcesPerPage || resourcesPerPage <= 0) return allResources;
|
|
3256
4156
|
const pages = Math.max(1, Math.ceil(allResources.length / resourcesPerPage));
|
|
@@ -3262,6 +4162,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3262
4162
|
resourcePage
|
|
3263
4163
|
]);
|
|
3264
4164
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
4165
|
+
const labels = (0, react.useMemo)(() => (0, _super_calendar_core.resolveCalendarLabels)(labelsProp), [labelsProp]);
|
|
3265
4166
|
const slot = createSlots({
|
|
3266
4167
|
classNames,
|
|
3267
4168
|
styles
|
|
@@ -3301,19 +4202,33 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3301
4202
|
}, `now-${resourceKey}`) : null;
|
|
3302
4203
|
const [drag, setDrag] = (0, react.useState)(null);
|
|
3303
4204
|
const dragRef = (0, react.useRef)(null);
|
|
4205
|
+
const handledClick = (0, react.useRef)(null);
|
|
3304
4206
|
const origin = (0, react.useRef)(null);
|
|
3305
4207
|
const applyDrag = (next) => {
|
|
3306
4208
|
dragRef.current = next;
|
|
3307
4209
|
setDrag(next);
|
|
3308
4210
|
};
|
|
3309
|
-
const
|
|
4211
|
+
const clearDrag = () => {
|
|
4212
|
+
const previous = dragRef.current;
|
|
4213
|
+
const element = origin.current?.element;
|
|
4214
|
+
applyDrag(null);
|
|
4215
|
+
origin.current = null;
|
|
4216
|
+
try {
|
|
4217
|
+
if (previous) element?.releasePointerCapture?.(previous.pointerId);
|
|
4218
|
+
} catch {}
|
|
4219
|
+
};
|
|
4220
|
+
const beginDrag = (e, resource, kind, pe) => {
|
|
3310
4221
|
const { startHours, durationHours } = pe;
|
|
3311
|
-
if (!
|
|
4222
|
+
if (e.button === 0 && e.isPrimary !== false && !dragRef.current) handledClick.current = null;
|
|
4223
|
+
if (!onDragEvent || pe.event.draggable === false || dragRef.current || createOrigin.current || e.isPrimary === false || e.button !== 0) return;
|
|
4224
|
+
const element = e.currentTarget.closest("button");
|
|
4225
|
+
if (!element) return;
|
|
3312
4226
|
e.stopPropagation();
|
|
3313
4227
|
try {
|
|
3314
|
-
|
|
4228
|
+
element.setPointerCapture?.(e.pointerId);
|
|
3315
4229
|
} catch {}
|
|
3316
4230
|
origin.current = {
|
|
4231
|
+
element,
|
|
3317
4232
|
x: vertical ? e.clientY : e.clientX,
|
|
3318
4233
|
cross: vertical ? e.clientX : e.clientY,
|
|
3319
4234
|
startHours,
|
|
@@ -3324,8 +4239,9 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3324
4239
|
}
|
|
3325
4240
|
};
|
|
3326
4241
|
applyDrag({
|
|
3327
|
-
|
|
3328
|
-
|
|
4242
|
+
pointerId: e.pointerId,
|
|
4243
|
+
event: pe.event,
|
|
4244
|
+
resource,
|
|
3329
4245
|
kind,
|
|
3330
4246
|
startHours,
|
|
3331
4247
|
durationHours,
|
|
@@ -3335,7 +4251,7 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3335
4251
|
};
|
|
3336
4252
|
const moveDrag = (e) => {
|
|
3337
4253
|
const d = dragRef.current;
|
|
3338
|
-
if (!d || !origin.current) return;
|
|
4254
|
+
if (!d || d.pointerId !== e.pointerId || !origin.current) return;
|
|
3339
4255
|
const dHours = ((vertical ? e.clientY : e.clientX) - origin.current.x) / hourSize;
|
|
3340
4256
|
const snap = (v) => Math.round(v / snapHours) * snapHours;
|
|
3341
4257
|
if (d.kind === "move") {
|
|
@@ -3376,39 +4292,76 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3376
4292
|
const id = (hit?.closest?.("[data-resource-id]"))?.getAttribute("data-resource-id");
|
|
3377
4293
|
return id && resources.find((r) => r.id === id) || fallback;
|
|
3378
4294
|
};
|
|
3379
|
-
const endDrag = (e
|
|
4295
|
+
const endDrag = (e) => {
|
|
3380
4296
|
const d = dragRef.current;
|
|
3381
|
-
if (!d) return;
|
|
3382
|
-
|
|
3383
|
-
e.target.releasePointerCapture?.(e.pointerId);
|
|
3384
|
-
} catch {}
|
|
4297
|
+
if (!d || d.pointerId !== e.pointerId) return;
|
|
4298
|
+
handledClick.current = origin.current?.element ?? null;
|
|
3385
4299
|
if (!d.moved) {
|
|
3386
|
-
|
|
3387
|
-
|
|
4300
|
+
clearDrag();
|
|
4301
|
+
onPressEvent?.(d.event);
|
|
4302
|
+
return;
|
|
4303
|
+
}
|
|
4304
|
+
const resource = resources.find((resource) => resource.id === d.resource.id);
|
|
4305
|
+
if (!resource) {
|
|
4306
|
+
clearDrag();
|
|
3388
4307
|
return;
|
|
3389
4308
|
}
|
|
3390
4309
|
const target = d.kind === "move" ? laneAt(e, resource) : resource;
|
|
3391
4310
|
const o = origin.current;
|
|
3392
4311
|
const startDelta = o ? Math.round((d.startHours - o.startHours) * 60) : 0;
|
|
3393
4312
|
const endDelta = d.kind === "move" ? startDelta : o ? Math.round((d.durationHours - o.durationHours) * 60) : 0;
|
|
3394
|
-
const next = (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, startDelta, endDelta, dragStepMinutes);
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
origin.current = null;
|
|
4313
|
+
const next = (0, _super_calendar_core.resolveDraggedBounds)(d.event.start, d.event.end, startDelta, endDelta, dragStepMinutes);
|
|
4314
|
+
clearDrag();
|
|
4315
|
+
if (next) onDragEvent?.(d.event, next.start, next.end, target);
|
|
3398
4316
|
};
|
|
3399
|
-
const cancelDrag = () => {
|
|
3400
|
-
|
|
3401
|
-
|
|
4317
|
+
const cancelDrag = (e) => {
|
|
4318
|
+
if (dragRef.current?.pointerId !== e.pointerId) return;
|
|
4319
|
+
handledClick.current = origin.current?.element ?? null;
|
|
4320
|
+
clearDrag();
|
|
3402
4321
|
};
|
|
3403
4322
|
const [createBox, setCreateBox] = (0, react.useState)(null);
|
|
3404
4323
|
const createOrigin = (0, react.useRef)(null);
|
|
4324
|
+
const createActive = createBox !== null;
|
|
4325
|
+
(0, react.useEffect)(() => {
|
|
4326
|
+
if (!createActive) return;
|
|
4327
|
+
const onScroll = () => {
|
|
4328
|
+
const origin = createOrigin.current;
|
|
4329
|
+
if (!origin) return;
|
|
4330
|
+
const rect = origin.el.getBoundingClientRect();
|
|
4331
|
+
const curPx = vertical ? origin.clientY - rect.top : origin.clientX - rect.left;
|
|
4332
|
+
setCreateBox((current) => current && current.curPx !== curPx ? {
|
|
4333
|
+
...current,
|
|
4334
|
+
curPx
|
|
4335
|
+
} : current);
|
|
4336
|
+
};
|
|
4337
|
+
window.addEventListener("scroll", onScroll, true);
|
|
4338
|
+
return () => window.removeEventListener("scroll", onScroll, true);
|
|
4339
|
+
}, [createActive, vertical]);
|
|
4340
|
+
const clearCreate = (0, react.useCallback)(() => {
|
|
4341
|
+
const previous = createOrigin.current;
|
|
4342
|
+
createOrigin.current = null;
|
|
4343
|
+
setCreateBox(null);
|
|
4344
|
+
try {
|
|
4345
|
+
previous?.el.releasePointerCapture?.(previous.pointerId);
|
|
4346
|
+
} catch {}
|
|
4347
|
+
}, []);
|
|
4348
|
+
(0, react.useEffect)(() => {
|
|
4349
|
+
const onKeyDown = (event) => {
|
|
4350
|
+
if (event.key !== "Escape" || !createOrigin.current) return;
|
|
4351
|
+
event.preventDefault();
|
|
4352
|
+
event.stopPropagation();
|
|
4353
|
+
clearCreate();
|
|
4354
|
+
};
|
|
4355
|
+
document.addEventListener("keydown", onKeyDown);
|
|
4356
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
4357
|
+
}, [clearCreate]);
|
|
3405
4358
|
const cellEnabled = !!onPressCell || !!onCreateEvent;
|
|
3406
4359
|
const pxAlongAxis = (el, e) => {
|
|
3407
4360
|
const rect = el.getBoundingClientRect();
|
|
3408
4361
|
return vertical ? e.clientY - rect.top : e.clientX - rect.left;
|
|
3409
4362
|
};
|
|
3410
4363
|
const beginCreate = (e, resource) => {
|
|
3411
|
-
if (!cellEnabled || e.pointerType === "touch") return;
|
|
4364
|
+
if (!cellEnabled || e.pointerType === "touch" || e.isPrimary === false || createOrigin.current || dragRef.current) return;
|
|
3412
4365
|
if (e.target !== e.currentTarget || e.button > 0) return;
|
|
3413
4366
|
const el = e.currentTarget;
|
|
3414
4367
|
const startPx = pxAlongAxis(el, e);
|
|
@@ -3416,9 +4369,14 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3416
4369
|
el.setPointerCapture?.(e.pointerId);
|
|
3417
4370
|
} catch {}
|
|
3418
4371
|
createOrigin.current = {
|
|
4372
|
+
pointerId: e.pointerId,
|
|
4373
|
+
clientX: e.clientX,
|
|
4374
|
+
clientY: e.clientY,
|
|
3419
4375
|
el,
|
|
3420
4376
|
resource,
|
|
3421
|
-
startPx
|
|
4377
|
+
startPx,
|
|
4378
|
+
dayKey: date.toDateString(),
|
|
4379
|
+
creating: !!onCreateEvent
|
|
3422
4380
|
};
|
|
3423
4381
|
if (onCreateEvent) setCreateBox({
|
|
3424
4382
|
resourceKey: resource.id,
|
|
@@ -3428,7 +4386,9 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3428
4386
|
};
|
|
3429
4387
|
const moveCreate = (e) => {
|
|
3430
4388
|
const o = createOrigin.current;
|
|
3431
|
-
if (!o || !onCreateEvent) return;
|
|
4389
|
+
if (!o || o.pointerId !== e.pointerId || !onCreateEvent) return;
|
|
4390
|
+
o.clientX = e.clientX;
|
|
4391
|
+
o.clientY = e.clientY;
|
|
3432
4392
|
setCreateBox({
|
|
3433
4393
|
resourceKey: o.resource.id,
|
|
3434
4394
|
startPx: o.startPx,
|
|
@@ -3437,31 +4397,155 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3437
4397
|
};
|
|
3438
4398
|
const endCreate = (e) => {
|
|
3439
4399
|
const o = createOrigin.current;
|
|
3440
|
-
if (!o) return;
|
|
3441
|
-
try {
|
|
3442
|
-
o.el.releasePointerCapture?.(e.pointerId);
|
|
3443
|
-
} catch {}
|
|
4400
|
+
if (!o || o.pointerId !== e.pointerId) return;
|
|
3444
4401
|
const endPx = pxAlongAxis(o.el, e);
|
|
3445
|
-
|
|
4402
|
+
const moved = Math.abs(endPx - o.startPx) > 4;
|
|
4403
|
+
clearCreate();
|
|
4404
|
+
const resource = resources.find((resource) => resource.id === o.resource.id);
|
|
4405
|
+
if (!resource) return;
|
|
4406
|
+
if (moved && onCreateEvent) {
|
|
3446
4407
|
const range = (0, _super_calendar_core.cellRangeFromDrag)(date, o.startPx, endPx, hourSize, startHour, dragStepMinutes);
|
|
3447
|
-
if (range) onCreateEvent(range.start, range.end,
|
|
4408
|
+
if (range) onCreateEvent(range.start, range.end, resource);
|
|
3448
4409
|
} else if (onPressCell) {
|
|
3449
4410
|
const at = (0, _super_calendar_core.cellRangeFromDrag)(date, o.startPx, o.startPx, hourSize, startHour, dragStepMinutes);
|
|
3450
|
-
if (at) onPressCell(at.start,
|
|
4411
|
+
if (at) onPressCell(at.start, resource);
|
|
3451
4412
|
}
|
|
3452
|
-
createOrigin.current = null;
|
|
3453
|
-
setCreateBox(null);
|
|
3454
4413
|
};
|
|
3455
|
-
const cancelCreate = () => {
|
|
3456
|
-
createOrigin.current
|
|
3457
|
-
|
|
4414
|
+
const cancelCreate = (e) => {
|
|
4415
|
+
if (createOrigin.current?.pointerId !== e.pointerId) return;
|
|
4416
|
+
clearCreate();
|
|
3458
4417
|
};
|
|
3459
|
-
const
|
|
4418
|
+
const RenderCreateGhost = renderCreateGhost;
|
|
4419
|
+
const liveRange = createBox && RenderCreateGhost && onCreateEvent ? (0, _super_calendar_core.cellRangeFromDrag)(date, createBox.startPx, createBox.curPx, hourSize, startHour, dragStepMinutes) : null;
|
|
4420
|
+
const liveStart = liveRange?.start.getTime();
|
|
4421
|
+
const liveEnd = liveRange?.end.getTime();
|
|
4422
|
+
const createRange = (0, react.useMemo)(() => liveStart === void 0 || liveEnd === void 0 ? null : {
|
|
4423
|
+
start: new Date(liveStart),
|
|
4424
|
+
end: new Date(liveEnd)
|
|
4425
|
+
}, [liveStart, liveEnd]);
|
|
4426
|
+
const trackInteractionProps = (resource) => ({
|
|
3460
4427
|
onPointerDown: (e) => beginCreate(e, resource),
|
|
3461
4428
|
onPointerMove: moveCreate,
|
|
3462
4429
|
onPointerUp: endCreate,
|
|
3463
|
-
onPointerCancel: cancelCreate
|
|
3464
|
-
|
|
4430
|
+
onPointerCancel: cancelCreate,
|
|
4431
|
+
onLostPointerCapture: cancelCreate
|
|
4432
|
+
});
|
|
4433
|
+
(0, react.useEffect)(() => {
|
|
4434
|
+
if (dragRef.current && (!origin.current?.element.isConnected || !events.includes(dragRef.current.event))) clearDrag();
|
|
4435
|
+
const creating = createOrigin.current;
|
|
4436
|
+
if (creating && (!creating.el.isConnected || !cellEnabled || creating.creating && !onCreateEvent || creating.dayKey !== date.toDateString())) clearCreate();
|
|
4437
|
+
});
|
|
4438
|
+
(0, react.useEffect)(() => () => {
|
|
4439
|
+
const captured = origin.current;
|
|
4440
|
+
const currentDrag = dragRef.current;
|
|
4441
|
+
const currentCreate = createOrigin.current;
|
|
4442
|
+
origin.current = null;
|
|
4443
|
+
dragRef.current = null;
|
|
4444
|
+
createOrigin.current = null;
|
|
4445
|
+
try {
|
|
4446
|
+
if (currentDrag) captured?.element.releasePointerCapture?.(currentDrag.pointerId);
|
|
4447
|
+
currentCreate?.el.releasePointerCapture?.(currentCreate.pointerId);
|
|
4448
|
+
} catch {}
|
|
4449
|
+
}, []);
|
|
4450
|
+
const eventKeys = (0, react.useRef)(/* @__PURE__ */ new WeakMap());
|
|
4451
|
+
const nextEventKey = (0, react.useRef)(0);
|
|
4452
|
+
const eventKey = (event) => {
|
|
4453
|
+
let key = eventKeys.current.get(event);
|
|
4454
|
+
if (key === void 0) {
|
|
4455
|
+
key = nextEventKey.current++;
|
|
4456
|
+
eventKeys.current.set(event, key);
|
|
4457
|
+
}
|
|
4458
|
+
return key;
|
|
4459
|
+
};
|
|
4460
|
+
const laneOf = (event) => resources.findIndex((resource) => resource.id === resourceId(event));
|
|
4461
|
+
const eventDescription = (event) => `${resources.find((resource) => resource.id === resourceId(event))?.title ?? ""}, ${describeEventDates(event)}, ${(0, _super_calendar_core.eventAccessibilityLabel)({
|
|
4462
|
+
title: event.title,
|
|
4463
|
+
isAllDay: false,
|
|
4464
|
+
start: event.start,
|
|
4465
|
+
end: event.end,
|
|
4466
|
+
ampm,
|
|
4467
|
+
labels
|
|
4468
|
+
})}`;
|
|
4469
|
+
const actionDelta = (id) => {
|
|
4470
|
+
switch (id) {
|
|
4471
|
+
case "move-later": return [
|
|
4472
|
+
dragStepMinutes,
|
|
4473
|
+
dragStepMinutes,
|
|
4474
|
+
0
|
|
4475
|
+
];
|
|
4476
|
+
case "move-earlier": return [
|
|
4477
|
+
-dragStepMinutes,
|
|
4478
|
+
-dragStepMinutes,
|
|
4479
|
+
0
|
|
4480
|
+
];
|
|
4481
|
+
case "extend": return [
|
|
4482
|
+
0,
|
|
4483
|
+
dragStepMinutes,
|
|
4484
|
+
0
|
|
4485
|
+
];
|
|
4486
|
+
case "shorten": return [
|
|
4487
|
+
0,
|
|
4488
|
+
-dragStepMinutes,
|
|
4489
|
+
0
|
|
4490
|
+
];
|
|
4491
|
+
case "move-next-resource": return [
|
|
4492
|
+
0,
|
|
4493
|
+
0,
|
|
4494
|
+
1
|
|
4495
|
+
];
|
|
4496
|
+
case "move-previous-resource": return [
|
|
4497
|
+
0,
|
|
4498
|
+
0,
|
|
4499
|
+
-1
|
|
4500
|
+
];
|
|
4501
|
+
default: return null;
|
|
4502
|
+
}
|
|
4503
|
+
};
|
|
4504
|
+
const editActions = (event) => {
|
|
4505
|
+
if ((0, _super_calendar_core.isAllDayEvent)(event) || (0, _super_calendar_core.isBackgroundEvent)(event)) return [];
|
|
4506
|
+
const lane = laneOf(event);
|
|
4507
|
+
if (!onDragEvent || event.draggable === false || lane < 0) return [];
|
|
4508
|
+
const action = (id, label) => {
|
|
4509
|
+
const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
|
|
4510
|
+
return {
|
|
4511
|
+
id,
|
|
4512
|
+
label,
|
|
4513
|
+
available: (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, startDelta, endDelta, dragStepMinutes) !== null
|
|
4514
|
+
};
|
|
4515
|
+
};
|
|
4516
|
+
const laneTitle = (resource) => resource && (resource.title || resource.id);
|
|
4517
|
+
const nextLane = laneTitle(resources[lane + 1]);
|
|
4518
|
+
const previousLane = laneTitle(resources[lane - 1]);
|
|
4519
|
+
return [
|
|
4520
|
+
action("move-later", labels.moveLater(dragStepMinutes)),
|
|
4521
|
+
action("move-earlier", labels.moveEarlier(dragStepMinutes)),
|
|
4522
|
+
action("extend", labels.extend(dragStepMinutes)),
|
|
4523
|
+
action("shorten", labels.shorten(dragStepMinutes)),
|
|
4524
|
+
...nextLane ? [action("move-next-resource", labels.moveToResource(nextLane))] : [],
|
|
4525
|
+
...previousLane ? [action("move-previous-resource", labels.moveToResource(previousLane))] : []
|
|
4526
|
+
];
|
|
4527
|
+
};
|
|
4528
|
+
const eventActions = useEventActions(events, editActions, (event, id) => {
|
|
4529
|
+
const delta = actionDelta(id);
|
|
4530
|
+
const target = delta ? resources[laneOf(event) + delta[2]] : void 0;
|
|
4531
|
+
const next = delta && target && (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, delta[0], delta[1], dragStepMinutes);
|
|
4532
|
+
if (!next || !target || onDragEvent?.(event, next.start, next.end, target) === false) return null;
|
|
4533
|
+
return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title && resourceId(candidate) === target.id;
|
|
4534
|
+
}, getEventId);
|
|
4535
|
+
const openActionsEvent = eventActions.openEvent;
|
|
4536
|
+
const actionsDialog = openActionsEvent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsDialog, {
|
|
4537
|
+
dialogRef: eventActions.dialogRef,
|
|
4538
|
+
title: labels.eventActions(openActionsEvent.title ?? ""),
|
|
4539
|
+
description: eventDescription(openActionsEvent),
|
|
4540
|
+
actions: editActions(openActionsEvent),
|
|
4541
|
+
closeLabel: labels.close,
|
|
4542
|
+
rejectedLabel: labels.eventChangeRejected,
|
|
4543
|
+
rejections: eventActions.rejections,
|
|
4544
|
+
onAction: eventActions.run,
|
|
4545
|
+
onClose: () => eventActions.close(true),
|
|
4546
|
+
slot,
|
|
4547
|
+
theme
|
|
4548
|
+
}) : null;
|
|
3465
4549
|
const bandsFor = (resource) => businessHours ? (0, _super_calendar_core.closedHourBands)(date, (d) => businessHours(d, resource), startHour, endHour) : [];
|
|
3466
4550
|
const backgroundBandsFor = (resource) => (0, _super_calendar_core.backgroundBandsForDay)(events.filter((e) => resourceId(e) === resource.id), date).map((b) => ({
|
|
3467
4551
|
...b,
|
|
@@ -3483,11 +4567,13 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3483
4567
|
resourceId,
|
|
3484
4568
|
date
|
|
3485
4569
|
]);
|
|
3486
|
-
const dragLaneId = drag?.kind === "move" && drag.moved ? drag.
|
|
4570
|
+
const dragLaneId = drag?.kind === "move" && drag.moved ? drag.resource.id : null;
|
|
3487
4571
|
if (vertical) {
|
|
3488
4572
|
const trackHeight = (endHour - startHour) * hourHeight;
|
|
3489
4573
|
const vGridLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight - 1}px, ${theme.gridLine} ${hourHeight}px)`;
|
|
3490
4574
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4575
|
+
ref: eventActions.rootRef,
|
|
4576
|
+
tabIndex: -1,
|
|
3491
4577
|
className,
|
|
3492
4578
|
style: {
|
|
3493
4579
|
fontFamily: theme.fontFamily,
|
|
@@ -3495,85 +4581,347 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3495
4581
|
overflowY: "auto",
|
|
3496
4582
|
...style
|
|
3497
4583
|
},
|
|
3498
|
-
children: [
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
background: theme.surface
|
|
3509
|
-
}
|
|
4584
|
+
children: [
|
|
4585
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsMenu, {
|
|
4586
|
+
events: [...new Set([...byResource.values()].flat().map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
|
|
4587
|
+
label: labels.editEvents,
|
|
4588
|
+
labelFor: (event) => labels.eventActions(event.title ?? ""),
|
|
4589
|
+
descriptionFor: eventDescription,
|
|
4590
|
+
onSelect: eventActions.select,
|
|
4591
|
+
rootRef: eventActions.rootRef,
|
|
4592
|
+
slot,
|
|
4593
|
+
theme
|
|
3510
4594
|
}),
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
flex: "none"
|
|
3514
|
-
} }) }), resources.map((resource, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3515
|
-
...slot("resourceLabel", {
|
|
4595
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4596
|
+
...slot("header", {
|
|
3516
4597
|
base: {
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
overflow: "hidden",
|
|
3522
|
-
textOverflow: "ellipsis",
|
|
3523
|
-
whiteSpace: "nowrap",
|
|
3524
|
-
boxSizing: "border-box"
|
|
4598
|
+
display: "flex",
|
|
4599
|
+
position: "sticky",
|
|
4600
|
+
top: 0,
|
|
4601
|
+
zIndex: 2
|
|
3525
4602
|
},
|
|
3526
4603
|
themed: {
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
borderLeft: `1px solid ${theme.gridLine}`
|
|
4604
|
+
borderBottom: `1px solid ${theme.gridLine}`,
|
|
4605
|
+
background: theme.surface
|
|
3530
4606
|
}
|
|
3531
4607
|
}),
|
|
3532
|
-
children:
|
|
3533
|
-
}, resource.id))]
|
|
3534
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3535
|
-
style: { display: "flex" },
|
|
3536
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3537
|
-
...slot("timeAxis", { base: {
|
|
3538
|
-
position: "relative",
|
|
4608
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...slot("corner", { base: {
|
|
3539
4609
|
width: GUTTER_WIDTH,
|
|
3540
|
-
flex: "none"
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
children: hours.map((h) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3544
|
-
...slot("hourTick", {
|
|
4610
|
+
flex: "none"
|
|
4611
|
+
} }) }), resources.map((resource, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4612
|
+
...slot("resourceLabel", {
|
|
3545
4613
|
base: {
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
4614
|
+
flex: 1,
|
|
4615
|
+
minWidth: 0,
|
|
4616
|
+
padding: "6px 4px",
|
|
4617
|
+
textAlign: "center",
|
|
4618
|
+
overflow: "hidden",
|
|
4619
|
+
textOverflow: "ellipsis",
|
|
4620
|
+
whiteSpace: "nowrap",
|
|
4621
|
+
boxSizing: "border-box"
|
|
3549
4622
|
},
|
|
3550
4623
|
themed: {
|
|
3551
|
-
fontSize:
|
|
3552
|
-
|
|
4624
|
+
fontSize: 13,
|
|
4625
|
+
fontWeight: 600,
|
|
4626
|
+
borderLeft: `1px solid ${theme.gridLine}`
|
|
3553
4627
|
}
|
|
3554
4628
|
}),
|
|
3555
|
-
children: (
|
|
3556
|
-
},
|
|
3557
|
-
}),
|
|
4629
|
+
children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
|
|
4630
|
+
}, resource.id))]
|
|
4631
|
+
}),
|
|
4632
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4633
|
+
style: { display: "flex" },
|
|
4634
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4635
|
+
...slot("timeAxis", { base: {
|
|
4636
|
+
position: "relative",
|
|
4637
|
+
width: GUTTER_WIDTH,
|
|
4638
|
+
flex: "none",
|
|
4639
|
+
height: trackHeight
|
|
4640
|
+
} }),
|
|
4641
|
+
children: hours.map((h) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4642
|
+
...slot("hourTick", {
|
|
4643
|
+
base: {
|
|
4644
|
+
position: "absolute",
|
|
4645
|
+
top: Math.max(0, (h - startHour) * hourHeight - 6),
|
|
4646
|
+
right: 6
|
|
4647
|
+
},
|
|
4648
|
+
themed: {
|
|
4649
|
+
fontSize: 10,
|
|
4650
|
+
color: theme.textMuted
|
|
4651
|
+
}
|
|
4652
|
+
}),
|
|
4653
|
+
children: (0, _super_calendar_core.formatHour)(h, { ampm })
|
|
4654
|
+
}, h))
|
|
4655
|
+
}), resources.map((resource) => {
|
|
4656
|
+
const positioned = byResource.get(resource.id) ?? [];
|
|
4657
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4658
|
+
...slot("row", {
|
|
4659
|
+
base: {
|
|
4660
|
+
flex: 1,
|
|
4661
|
+
minWidth: 0,
|
|
4662
|
+
...dragLaneId === resource.id ? {
|
|
4663
|
+
position: "relative",
|
|
4664
|
+
zIndex: 5
|
|
4665
|
+
} : null
|
|
4666
|
+
},
|
|
4667
|
+
themed: { borderLeft: `1px solid ${theme.gridLine}` }
|
|
4668
|
+
}),
|
|
4669
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4670
|
+
"data-resource-id": resource.id,
|
|
4671
|
+
...trackInteractionProps(resource),
|
|
4672
|
+
...slot("track", { base: {
|
|
4673
|
+
position: "relative",
|
|
4674
|
+
height: trackHeight
|
|
4675
|
+
} }),
|
|
4676
|
+
children: [
|
|
4677
|
+
bandsFor(resource).map((b) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4678
|
+
"aria-hidden": true,
|
|
4679
|
+
...slot("businessHours", {
|
|
4680
|
+
base: {
|
|
4681
|
+
position: "absolute",
|
|
4682
|
+
left: 0,
|
|
4683
|
+
right: 0,
|
|
4684
|
+
top: (b.start - startHour) * hourHeight,
|
|
4685
|
+
height: (b.end - b.start) * hourHeight,
|
|
4686
|
+
pointerEvents: "none",
|
|
4687
|
+
zIndex: 0
|
|
4688
|
+
},
|
|
4689
|
+
themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
|
|
4690
|
+
}),
|
|
4691
|
+
children: renderBusinessHours?.({
|
|
4692
|
+
date,
|
|
4693
|
+
start: b.start,
|
|
4694
|
+
end: b.end,
|
|
4695
|
+
resource
|
|
4696
|
+
})
|
|
4697
|
+
}, b.start)),
|
|
4698
|
+
backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4699
|
+
"aria-hidden": true,
|
|
4700
|
+
title: b.event.title,
|
|
4701
|
+
...slot("backgroundEvent", {
|
|
4702
|
+
base: {
|
|
4703
|
+
position: "absolute",
|
|
4704
|
+
left: 0,
|
|
4705
|
+
right: 0,
|
|
4706
|
+
top: (b.startHours - startHour) * hourHeight,
|
|
4707
|
+
height: (b.endHours - b.startHours) * hourHeight,
|
|
4708
|
+
pointerEvents: "none",
|
|
4709
|
+
zIndex: 0
|
|
4710
|
+
},
|
|
4711
|
+
themed: { background: theme.backgroundEvent }
|
|
4712
|
+
})
|
|
4713
|
+
}, `bg-${i}`)),
|
|
4714
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4715
|
+
"aria-hidden": true,
|
|
4716
|
+
...slot("gridLines", {
|
|
4717
|
+
base: {
|
|
4718
|
+
position: "absolute",
|
|
4719
|
+
inset: 0,
|
|
4720
|
+
pointerEvents: "none"
|
|
4721
|
+
},
|
|
4722
|
+
themed: { backgroundImage: vGridLines }
|
|
4723
|
+
})
|
|
4724
|
+
}),
|
|
4725
|
+
positioned.map((pe) => {
|
|
4726
|
+
const key = eventKey(pe.event);
|
|
4727
|
+
const active = drag?.event === pe.event && drag.resource.id === resource.id ? drag : null;
|
|
4728
|
+
const startH = active ? active.startHours : pe.startHours;
|
|
4729
|
+
const durH = active ? active.durationHours : pe.durationHours;
|
|
4730
|
+
const top = clamp(startH - startHour, 0, endHour - startHour) * hourHeight;
|
|
4731
|
+
const bottom = clamp(startH + durH - startHour, 0, endHour - startHour) * hourHeight;
|
|
4732
|
+
const height = Math.max(bottom - top, 2);
|
|
4733
|
+
const lanePct = 100 / pe.columns;
|
|
4734
|
+
const onPress = () => onPressEvent?.(pe.event);
|
|
4735
|
+
const args = {
|
|
4736
|
+
event: pe.event,
|
|
4737
|
+
width: 0,
|
|
4738
|
+
height,
|
|
4739
|
+
onPress
|
|
4740
|
+
};
|
|
4741
|
+
const draggable = !!onDragEvent && pe.event.draggable !== false;
|
|
4742
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4743
|
+
type: "button",
|
|
4744
|
+
onClick: (e) => {
|
|
4745
|
+
if (e.detail !== 0 && handledClick.current === e.currentTarget) {
|
|
4746
|
+
handledClick.current = null;
|
|
4747
|
+
return;
|
|
4748
|
+
}
|
|
4749
|
+
if (!draggable || e.detail === 0) onPress();
|
|
4750
|
+
},
|
|
4751
|
+
"aria-label": pe.event.title,
|
|
4752
|
+
...dataState({ "data-dragging": !!active }),
|
|
4753
|
+
onPointerDown: (e) => beginDrag(e, resource, "move", pe),
|
|
4754
|
+
onPointerMove: moveDrag,
|
|
4755
|
+
onPointerUp: endDrag,
|
|
4756
|
+
onPointerCancel: cancelDrag,
|
|
4757
|
+
onLostPointerCapture: cancelDrag,
|
|
4758
|
+
...slot("event", { base: {
|
|
4759
|
+
position: "absolute",
|
|
4760
|
+
top,
|
|
4761
|
+
height,
|
|
4762
|
+
left: `${pe.column * lanePct}%`,
|
|
4763
|
+
width: `${lanePct}%`,
|
|
4764
|
+
transform: active?.kind === "move" ? `translateX(${active.crossPx}px)` : void 0,
|
|
4765
|
+
padding: 1,
|
|
4766
|
+
border: "none",
|
|
4767
|
+
background: "transparent",
|
|
4768
|
+
cursor: draggable ? "grab" : "pointer",
|
|
4769
|
+
touchAction: draggable ? "none" : "auto",
|
|
4770
|
+
font: "inherit",
|
|
4771
|
+
textAlign: "left",
|
|
4772
|
+
boxSizing: "border-box",
|
|
4773
|
+
zIndex: active ? 3 : 1,
|
|
4774
|
+
opacity: active ? .85 : 1
|
|
4775
|
+
} }),
|
|
4776
|
+
children: [Renderer ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Renderer, { ...args }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultBar, {
|
|
4777
|
+
...args,
|
|
4778
|
+
theme,
|
|
4779
|
+
boxProps: slot("eventBox")
|
|
4780
|
+
}), draggable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4781
|
+
"aria-hidden": true,
|
|
4782
|
+
onPointerDown: (e) => {
|
|
4783
|
+
e.stopPropagation();
|
|
4784
|
+
beginDrag(e, resource, "resize", pe);
|
|
4785
|
+
},
|
|
4786
|
+
style: {
|
|
4787
|
+
position: "absolute",
|
|
4788
|
+
left: 0,
|
|
4789
|
+
right: 0,
|
|
4790
|
+
bottom: 0,
|
|
4791
|
+
height: 8,
|
|
4792
|
+
cursor: "ns-resize",
|
|
4793
|
+
touchAction: "none"
|
|
4794
|
+
}
|
|
4795
|
+
}) : null]
|
|
4796
|
+
}, key);
|
|
4797
|
+
}),
|
|
4798
|
+
nowLine(resource.id),
|
|
4799
|
+
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InertDiv, {
|
|
4800
|
+
"aria-hidden": true,
|
|
4801
|
+
inert: !!createRange,
|
|
4802
|
+
...slot("createGhost", {
|
|
4803
|
+
base: {
|
|
4804
|
+
position: "absolute",
|
|
4805
|
+
left: 1,
|
|
4806
|
+
right: 1,
|
|
4807
|
+
top: Math.min(createBox.startPx, createBox.curPx),
|
|
4808
|
+
height: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
|
|
4809
|
+
...createRange ? { overflow: "hidden" } : null,
|
|
4810
|
+
opacity: .7,
|
|
4811
|
+
pointerEvents: "none",
|
|
4812
|
+
zIndex: 2
|
|
4813
|
+
},
|
|
4814
|
+
themed: {
|
|
4815
|
+
background: theme.rangeBackground,
|
|
4816
|
+
border: `1px solid ${theme.selectedBackground}`,
|
|
4817
|
+
borderRadius: 6
|
|
4818
|
+
}
|
|
4819
|
+
}),
|
|
4820
|
+
children: createRange && RenderCreateGhost ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderCreateGhost, {
|
|
4821
|
+
start: createRange.start,
|
|
4822
|
+
end: createRange.end,
|
|
4823
|
+
resource
|
|
4824
|
+
}) : null
|
|
4825
|
+
}) : null
|
|
4826
|
+
]
|
|
4827
|
+
})
|
|
4828
|
+
}, resource.id);
|
|
4829
|
+
})]
|
|
4830
|
+
}),
|
|
4831
|
+
actionsDialog
|
|
4832
|
+
]
|
|
4833
|
+
});
|
|
4834
|
+
}
|
|
4835
|
+
const gridLines = `repeating-linear-gradient(to right, transparent 0, transparent ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth}px)`;
|
|
4836
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4837
|
+
ref: eventActions.rootRef,
|
|
4838
|
+
tabIndex: -1,
|
|
4839
|
+
className,
|
|
4840
|
+
style: {
|
|
4841
|
+
fontFamily: theme.fontFamily,
|
|
4842
|
+
color: theme.text,
|
|
4843
|
+
overflowX: "auto",
|
|
4844
|
+
...style
|
|
4845
|
+
},
|
|
4846
|
+
children: [
|
|
4847
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsMenu, {
|
|
4848
|
+
events: [...new Set([...byResource.values()].flat().map((pe) => pe.event))].filter((event) => editActions(event).length > 0),
|
|
4849
|
+
label: labels.editEvents,
|
|
4850
|
+
labelFor: (event) => labels.eventActions(event.title ?? ""),
|
|
4851
|
+
descriptionFor: eventDescription,
|
|
4852
|
+
onSelect: eventActions.select,
|
|
4853
|
+
rootRef: eventActions.rootRef,
|
|
4854
|
+
slot,
|
|
4855
|
+
theme
|
|
4856
|
+
}),
|
|
4857
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4858
|
+
style: { minWidth: labelWidth + trackWidth },
|
|
4859
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4860
|
+
...slot("header", {
|
|
4861
|
+
base: { display: "flex" },
|
|
4862
|
+
themed: { borderBottom: `1px solid ${theme.gridLine}` }
|
|
4863
|
+
}),
|
|
4864
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...slot("corner", { base: {
|
|
4865
|
+
width: labelWidth,
|
|
4866
|
+
flex: "none"
|
|
4867
|
+
} }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4868
|
+
...slot("timeAxis", { base: {
|
|
4869
|
+
position: "relative",
|
|
4870
|
+
height: 24,
|
|
4871
|
+
width: trackWidth
|
|
4872
|
+
} }),
|
|
4873
|
+
children: hours.map((h) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4874
|
+
...slot("hourTick", {
|
|
4875
|
+
base: {
|
|
4876
|
+
position: "absolute",
|
|
4877
|
+
left: (h - startHour) * hourWidth,
|
|
4878
|
+
top: 4
|
|
4879
|
+
},
|
|
4880
|
+
themed: {
|
|
4881
|
+
fontSize: 10,
|
|
4882
|
+
color: theme.textMuted
|
|
4883
|
+
}
|
|
4884
|
+
}),
|
|
4885
|
+
children: (0, _super_calendar_core.formatHour)(h, { ampm })
|
|
4886
|
+
}, h))
|
|
4887
|
+
})]
|
|
4888
|
+
}), resources.map((resource, index) => {
|
|
3558
4889
|
const positioned = byResource.get(resource.id) ?? [];
|
|
3559
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
4890
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3560
4891
|
...slot("row", {
|
|
3561
4892
|
base: {
|
|
3562
|
-
|
|
3563
|
-
|
|
4893
|
+
display: "flex",
|
|
4894
|
+
height: rowHeight,
|
|
3564
4895
|
...dragLaneId === resource.id ? {
|
|
3565
4896
|
position: "relative",
|
|
3566
4897
|
zIndex: 5
|
|
3567
4898
|
} : null
|
|
3568
4899
|
},
|
|
3569
|
-
themed: {
|
|
4900
|
+
themed: { borderBottom: `1px solid ${theme.gridLine}` }
|
|
3570
4901
|
}),
|
|
3571
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.
|
|
4902
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4903
|
+
...slot("resourceLabel", {
|
|
4904
|
+
base: {
|
|
4905
|
+
width: labelWidth,
|
|
4906
|
+
flex: "none",
|
|
4907
|
+
display: "flex",
|
|
4908
|
+
alignItems: "center",
|
|
4909
|
+
padding: "0 10px",
|
|
4910
|
+
boxSizing: "border-box"
|
|
4911
|
+
},
|
|
4912
|
+
themed: {
|
|
4913
|
+
fontSize: 13,
|
|
4914
|
+
fontWeight: 600,
|
|
4915
|
+
borderRight: `1px solid ${theme.gridLine}`
|
|
4916
|
+
}
|
|
4917
|
+
}),
|
|
4918
|
+
children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
|
|
4919
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3572
4920
|
"data-resource-id": resource.id,
|
|
3573
4921
|
...trackInteractionProps(resource),
|
|
3574
4922
|
...slot("track", { base: {
|
|
3575
4923
|
position: "relative",
|
|
3576
|
-
|
|
4924
|
+
width: trackWidth
|
|
3577
4925
|
} }),
|
|
3578
4926
|
children: [
|
|
3579
4927
|
bandsFor(resource).map((b) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -3581,10 +4929,10 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3581
4929
|
...slot("businessHours", {
|
|
3582
4930
|
base: {
|
|
3583
4931
|
position: "absolute",
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
4932
|
+
top: 0,
|
|
4933
|
+
bottom: 0,
|
|
4934
|
+
left: (b.start - startHour) * hourWidth,
|
|
4935
|
+
width: (b.end - b.start) * hourWidth,
|
|
3588
4936
|
pointerEvents: "none",
|
|
3589
4937
|
zIndex: 0
|
|
3590
4938
|
},
|
|
@@ -3603,10 +4951,10 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3603
4951
|
...slot("backgroundEvent", {
|
|
3604
4952
|
base: {
|
|
3605
4953
|
position: "absolute",
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
4954
|
+
top: 0,
|
|
4955
|
+
bottom: 0,
|
|
4956
|
+
left: (b.startHours - startHour) * hourWidth,
|
|
4957
|
+
width: (b.endHours - b.startHours) * hourWidth,
|
|
3610
4958
|
pointerEvents: "none",
|
|
3611
4959
|
zIndex: 0
|
|
3612
4960
|
},
|
|
@@ -3621,42 +4969,48 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3621
4969
|
inset: 0,
|
|
3622
4970
|
pointerEvents: "none"
|
|
3623
4971
|
},
|
|
3624
|
-
themed: { backgroundImage:
|
|
4972
|
+
themed: { backgroundImage: gridLines }
|
|
3625
4973
|
})
|
|
3626
4974
|
}),
|
|
3627
|
-
positioned.map((pe
|
|
3628
|
-
const key =
|
|
3629
|
-
const active = drag?.
|
|
4975
|
+
positioned.map((pe) => {
|
|
4976
|
+
const key = eventKey(pe.event);
|
|
4977
|
+
const active = drag?.event === pe.event && drag.resource.id === resource.id ? drag : null;
|
|
3630
4978
|
const startH = active ? active.startHours : pe.startHours;
|
|
3631
4979
|
const durH = active ? active.durationHours : pe.durationHours;
|
|
3632
|
-
const
|
|
3633
|
-
const
|
|
3634
|
-
const
|
|
3635
|
-
const
|
|
4980
|
+
const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
|
|
4981
|
+
const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
|
|
4982
|
+
const width = Math.max(right - left, 2);
|
|
4983
|
+
const laneHeight = rowHeight / pe.columns;
|
|
3636
4984
|
const onPress = () => onPressEvent?.(pe.event);
|
|
3637
4985
|
const args = {
|
|
3638
4986
|
event: pe.event,
|
|
3639
|
-
width
|
|
3640
|
-
height,
|
|
4987
|
+
width,
|
|
3641
4988
|
onPress
|
|
3642
4989
|
};
|
|
3643
4990
|
const draggable = !!onDragEvent && pe.event.draggable !== false;
|
|
3644
4991
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3645
4992
|
type: "button",
|
|
3646
|
-
onClick:
|
|
4993
|
+
onClick: (e) => {
|
|
4994
|
+
if (e.detail !== 0 && handledClick.current === e.currentTarget) {
|
|
4995
|
+
handledClick.current = null;
|
|
4996
|
+
return;
|
|
4997
|
+
}
|
|
4998
|
+
if (!draggable || e.detail === 0) onPress();
|
|
4999
|
+
},
|
|
3647
5000
|
"aria-label": pe.event.title,
|
|
3648
5001
|
...dataState({ "data-dragging": !!active }),
|
|
3649
|
-
onPointerDown:
|
|
3650
|
-
onPointerMove:
|
|
3651
|
-
onPointerUp:
|
|
3652
|
-
onPointerCancel:
|
|
5002
|
+
onPointerDown: (e) => beginDrag(e, resource, "move", pe),
|
|
5003
|
+
onPointerMove: moveDrag,
|
|
5004
|
+
onPointerUp: endDrag,
|
|
5005
|
+
onPointerCancel: cancelDrag,
|
|
5006
|
+
onLostPointerCapture: cancelDrag,
|
|
3653
5007
|
...slot("event", { base: {
|
|
3654
5008
|
position: "absolute",
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
transform: active?.kind === "move" ? `
|
|
5009
|
+
left,
|
|
5010
|
+
width,
|
|
5011
|
+
top: pe.column * laneHeight,
|
|
5012
|
+
height: laneHeight,
|
|
5013
|
+
transform: active?.kind === "move" ? `translateY(${active.crossPx}px)` : void 0,
|
|
3660
5014
|
padding: 1,
|
|
3661
5015
|
border: "none",
|
|
3662
5016
|
background: "transparent",
|
|
@@ -3676,30 +5030,32 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3676
5030
|
"aria-hidden": true,
|
|
3677
5031
|
onPointerDown: (e) => {
|
|
3678
5032
|
e.stopPropagation();
|
|
3679
|
-
beginDrag(e,
|
|
5033
|
+
beginDrag(e, resource, "resize", pe);
|
|
3680
5034
|
},
|
|
3681
5035
|
style: {
|
|
3682
5036
|
position: "absolute",
|
|
3683
|
-
|
|
3684
|
-
right: 0,
|
|
5037
|
+
top: 0,
|
|
3685
5038
|
bottom: 0,
|
|
3686
|
-
|
|
3687
|
-
|
|
5039
|
+
right: 0,
|
|
5040
|
+
width: 8,
|
|
5041
|
+
cursor: "ew-resize",
|
|
3688
5042
|
touchAction: "none"
|
|
3689
5043
|
}
|
|
3690
5044
|
}) : null]
|
|
3691
|
-
},
|
|
5045
|
+
}, key);
|
|
3692
5046
|
}),
|
|
3693
5047
|
nowLine(resource.id),
|
|
3694
|
-
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
5048
|
+
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InertDiv, {
|
|
3695
5049
|
"aria-hidden": true,
|
|
5050
|
+
inert: !!createRange,
|
|
3696
5051
|
...slot("createGhost", {
|
|
3697
5052
|
base: {
|
|
3698
5053
|
position: "absolute",
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
5054
|
+
top: 1,
|
|
5055
|
+
bottom: 1,
|
|
5056
|
+
left: Math.min(createBox.startPx, createBox.curPx),
|
|
5057
|
+
width: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
|
|
5058
|
+
...createRange ? { overflow: "hidden" } : null,
|
|
3703
5059
|
opacity: .7,
|
|
3704
5060
|
pointerEvents: "none",
|
|
3705
5061
|
zIndex: 2
|
|
@@ -3709,242 +5065,29 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
3709
5065
|
border: `1px solid ${theme.selectedBackground}`,
|
|
3710
5066
|
borderRadius: 6
|
|
3711
5067
|
}
|
|
3712
|
-
})
|
|
5068
|
+
}),
|
|
5069
|
+
children: createRange && RenderCreateGhost ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderCreateGhost, {
|
|
5070
|
+
start: createRange.start,
|
|
5071
|
+
end: createRange.end,
|
|
5072
|
+
resource
|
|
5073
|
+
}) : null
|
|
3713
5074
|
}) : null
|
|
3714
5075
|
]
|
|
3715
|
-
})
|
|
5076
|
+
})]
|
|
3716
5077
|
}, resource.id);
|
|
3717
5078
|
})]
|
|
3718
|
-
})
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
const gridLines = `repeating-linear-gradient(to right, transparent 0, transparent ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth - 1}px, ${theme.gridLine} ${hourWidth}px)`;
|
|
3722
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3723
|
-
className,
|
|
3724
|
-
style: {
|
|
3725
|
-
fontFamily: theme.fontFamily,
|
|
3726
|
-
color: theme.text,
|
|
3727
|
-
overflowX: "auto",
|
|
3728
|
-
...style
|
|
3729
|
-
},
|
|
3730
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3731
|
-
style: { minWidth: labelWidth + trackWidth },
|
|
3732
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3733
|
-
...slot("header", {
|
|
3734
|
-
base: { display: "flex" },
|
|
3735
|
-
themed: { borderBottom: `1px solid ${theme.gridLine}` }
|
|
3736
|
-
}),
|
|
3737
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...slot("corner", { base: {
|
|
3738
|
-
width: labelWidth,
|
|
3739
|
-
flex: "none"
|
|
3740
|
-
} }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3741
|
-
...slot("timeAxis", { base: {
|
|
3742
|
-
position: "relative",
|
|
3743
|
-
height: 24,
|
|
3744
|
-
width: trackWidth
|
|
3745
|
-
} }),
|
|
3746
|
-
children: hours.map((h) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3747
|
-
...slot("hourTick", {
|
|
3748
|
-
base: {
|
|
3749
|
-
position: "absolute",
|
|
3750
|
-
left: (h - startHour) * hourWidth,
|
|
3751
|
-
top: 4
|
|
3752
|
-
},
|
|
3753
|
-
themed: {
|
|
3754
|
-
fontSize: 10,
|
|
3755
|
-
color: theme.textMuted
|
|
3756
|
-
}
|
|
3757
|
-
}),
|
|
3758
|
-
children: (0, _super_calendar_core.formatHour)(h, { ampm })
|
|
3759
|
-
}, h))
|
|
3760
|
-
})]
|
|
3761
|
-
}), resources.map((resource, index) => {
|
|
3762
|
-
const positioned = byResource.get(resource.id) ?? [];
|
|
3763
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3764
|
-
...slot("row", {
|
|
3765
|
-
base: {
|
|
3766
|
-
display: "flex",
|
|
3767
|
-
height: rowHeight,
|
|
3768
|
-
...dragLaneId === resource.id ? {
|
|
3769
|
-
position: "relative",
|
|
3770
|
-
zIndex: 5
|
|
3771
|
-
} : null
|
|
3772
|
-
},
|
|
3773
|
-
themed: { borderBottom: `1px solid ${theme.gridLine}` }
|
|
3774
|
-
}),
|
|
3775
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3776
|
-
...slot("resourceLabel", {
|
|
3777
|
-
base: {
|
|
3778
|
-
width: labelWidth,
|
|
3779
|
-
flex: "none",
|
|
3780
|
-
display: "flex",
|
|
3781
|
-
alignItems: "center",
|
|
3782
|
-
padding: "0 10px",
|
|
3783
|
-
boxSizing: "border-box"
|
|
3784
|
-
},
|
|
3785
|
-
themed: {
|
|
3786
|
-
fontSize: 13,
|
|
3787
|
-
fontWeight: 600,
|
|
3788
|
-
borderRight: `1px solid ${theme.gridLine}`
|
|
3789
|
-
}
|
|
3790
|
-
}),
|
|
3791
|
-
children: renderResourceHeader ? renderResourceHeader(resource, index) : resource.title ?? resource.id
|
|
3792
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3793
|
-
"data-resource-id": resource.id,
|
|
3794
|
-
...trackInteractionProps(resource),
|
|
3795
|
-
...slot("track", { base: {
|
|
3796
|
-
position: "relative",
|
|
3797
|
-
width: trackWidth
|
|
3798
|
-
} }),
|
|
3799
|
-
children: [
|
|
3800
|
-
bandsFor(resource).map((b) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3801
|
-
"aria-hidden": true,
|
|
3802
|
-
...slot("businessHours", {
|
|
3803
|
-
base: {
|
|
3804
|
-
position: "absolute",
|
|
3805
|
-
top: 0,
|
|
3806
|
-
bottom: 0,
|
|
3807
|
-
left: (b.start - startHour) * hourWidth,
|
|
3808
|
-
width: (b.end - b.start) * hourWidth,
|
|
3809
|
-
pointerEvents: "none",
|
|
3810
|
-
zIndex: 0
|
|
3811
|
-
},
|
|
3812
|
-
themed: renderBusinessHours ? void 0 : { background: theme.outsideHoursBackground }
|
|
3813
|
-
}),
|
|
3814
|
-
children: renderBusinessHours?.({
|
|
3815
|
-
date,
|
|
3816
|
-
start: b.start,
|
|
3817
|
-
end: b.end,
|
|
3818
|
-
resource
|
|
3819
|
-
})
|
|
3820
|
-
}, b.start)),
|
|
3821
|
-
backgroundBandsFor(resource).map((b, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3822
|
-
"aria-hidden": true,
|
|
3823
|
-
title: b.event.title,
|
|
3824
|
-
...slot("backgroundEvent", {
|
|
3825
|
-
base: {
|
|
3826
|
-
position: "absolute",
|
|
3827
|
-
top: 0,
|
|
3828
|
-
bottom: 0,
|
|
3829
|
-
left: (b.startHours - startHour) * hourWidth,
|
|
3830
|
-
width: (b.endHours - b.startHours) * hourWidth,
|
|
3831
|
-
pointerEvents: "none",
|
|
3832
|
-
zIndex: 0
|
|
3833
|
-
},
|
|
3834
|
-
themed: { background: theme.backgroundEvent }
|
|
3835
|
-
})
|
|
3836
|
-
}, `bg-${i}`)),
|
|
3837
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3838
|
-
"aria-hidden": true,
|
|
3839
|
-
...slot("gridLines", {
|
|
3840
|
-
base: {
|
|
3841
|
-
position: "absolute",
|
|
3842
|
-
inset: 0,
|
|
3843
|
-
pointerEvents: "none"
|
|
3844
|
-
},
|
|
3845
|
-
themed: { backgroundImage: gridLines }
|
|
3846
|
-
})
|
|
3847
|
-
}),
|
|
3848
|
-
positioned.map((pe, idx) => {
|
|
3849
|
-
const key = `${resource.id}:${idx}`;
|
|
3850
|
-
const active = drag?.key === key ? drag : null;
|
|
3851
|
-
const startH = active ? active.startHours : pe.startHours;
|
|
3852
|
-
const durH = active ? active.durationHours : pe.durationHours;
|
|
3853
|
-
const left = clamp(startH - startHour, 0, endHour - startHour) * hourWidth;
|
|
3854
|
-
const right = clamp(startH + durH - startHour, 0, endHour - startHour) * hourWidth;
|
|
3855
|
-
const width = Math.max(right - left, 2);
|
|
3856
|
-
const laneHeight = rowHeight / pe.columns;
|
|
3857
|
-
const onPress = () => onPressEvent?.(pe.event);
|
|
3858
|
-
const args = {
|
|
3859
|
-
event: pe.event,
|
|
3860
|
-
width,
|
|
3861
|
-
onPress
|
|
3862
|
-
};
|
|
3863
|
-
const draggable = !!onDragEvent;
|
|
3864
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3865
|
-
type: "button",
|
|
3866
|
-
onClick: draggable ? void 0 : onPress,
|
|
3867
|
-
"aria-label": pe.event.title,
|
|
3868
|
-
...dataState({ "data-dragging": !!active }),
|
|
3869
|
-
onPointerDown: draggable ? (e) => beginDrag(e, key, resource.id, "move", pe) : void 0,
|
|
3870
|
-
onPointerMove: draggable ? moveDrag : void 0,
|
|
3871
|
-
onPointerUp: draggable ? (e) => endDrag(e, pe.event, resource, onPress) : void 0,
|
|
3872
|
-
onPointerCancel: draggable ? cancelDrag : void 0,
|
|
3873
|
-
...slot("event", { base: {
|
|
3874
|
-
position: "absolute",
|
|
3875
|
-
left,
|
|
3876
|
-
width,
|
|
3877
|
-
top: pe.column * laneHeight,
|
|
3878
|
-
height: laneHeight,
|
|
3879
|
-
transform: active?.kind === "move" ? `translateY(${active.crossPx}px)` : void 0,
|
|
3880
|
-
padding: 1,
|
|
3881
|
-
border: "none",
|
|
3882
|
-
background: "transparent",
|
|
3883
|
-
cursor: draggable ? "grab" : "pointer",
|
|
3884
|
-
touchAction: draggable ? "none" : "auto",
|
|
3885
|
-
font: "inherit",
|
|
3886
|
-
textAlign: "left",
|
|
3887
|
-
boxSizing: "border-box",
|
|
3888
|
-
zIndex: active ? 3 : 1,
|
|
3889
|
-
opacity: active ? .85 : 1
|
|
3890
|
-
} }),
|
|
3891
|
-
children: [Renderer ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Renderer, { ...args }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultBar, {
|
|
3892
|
-
...args,
|
|
3893
|
-
theme,
|
|
3894
|
-
boxProps: slot("eventBox")
|
|
3895
|
-
}), draggable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3896
|
-
"aria-hidden": true,
|
|
3897
|
-
onPointerDown: (e) => {
|
|
3898
|
-
e.stopPropagation();
|
|
3899
|
-
beginDrag(e, key, resource.id, "resize", pe);
|
|
3900
|
-
},
|
|
3901
|
-
style: {
|
|
3902
|
-
position: "absolute",
|
|
3903
|
-
top: 0,
|
|
3904
|
-
bottom: 0,
|
|
3905
|
-
right: 0,
|
|
3906
|
-
width: 8,
|
|
3907
|
-
cursor: "ew-resize",
|
|
3908
|
-
touchAction: "none"
|
|
3909
|
-
}
|
|
3910
|
-
}) : null]
|
|
3911
|
-
}, idx);
|
|
3912
|
-
}),
|
|
3913
|
-
nowLine(resource.id),
|
|
3914
|
-
createBox?.resourceKey === resource.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3915
|
-
"aria-hidden": true,
|
|
3916
|
-
...slot("createGhost", {
|
|
3917
|
-
base: {
|
|
3918
|
-
position: "absolute",
|
|
3919
|
-
top: 1,
|
|
3920
|
-
bottom: 1,
|
|
3921
|
-
left: Math.min(createBox.startPx, createBox.curPx),
|
|
3922
|
-
width: Math.max(Math.abs(createBox.curPx - createBox.startPx), 2),
|
|
3923
|
-
opacity: .7,
|
|
3924
|
-
pointerEvents: "none",
|
|
3925
|
-
zIndex: 2
|
|
3926
|
-
},
|
|
3927
|
-
themed: {
|
|
3928
|
-
background: theme.rangeBackground,
|
|
3929
|
-
border: `1px solid ${theme.selectedBackground}`,
|
|
3930
|
-
borderRadius: 6
|
|
3931
|
-
}
|
|
3932
|
-
})
|
|
3933
|
-
}) : null
|
|
3934
|
-
]
|
|
3935
|
-
})]
|
|
3936
|
-
}, resource.id);
|
|
3937
|
-
})]
|
|
3938
|
-
})
|
|
5079
|
+
}),
|
|
5080
|
+
actionsDialog
|
|
5081
|
+
]
|
|
3939
5082
|
});
|
|
3940
5083
|
}
|
|
3941
|
-
//#endregion
|
|
3942
5084
|
exports.Agenda = Agenda;
|
|
3943
5085
|
exports.Calendar = Calendar;
|
|
3944
5086
|
exports.DatePicker = DatePicker;
|
|
3945
5087
|
exports.DateRangePicker = DateRangePicker;
|
|
3946
5088
|
exports.MonthList = MonthList;
|
|
3947
5089
|
exports.MonthView = MonthView;
|
|
5090
|
+
exports.MultiWeekView = MultiWeekView;
|
|
3948
5091
|
exports.ResourceTimeline = ResourceTimeline;
|
|
3949
5092
|
exports.TimeGrid = TimeGrid;
|
|
3950
5093
|
exports.YearView = YearView;
|
|
@@ -3960,6 +5103,12 @@ Object.defineProperty(exports, "buildMonthGrid", {
|
|
|
3960
5103
|
return _super_calendar_core.buildMonthGrid;
|
|
3961
5104
|
}
|
|
3962
5105
|
});
|
|
5106
|
+
Object.defineProperty(exports, "buildMultiWeekGrid", {
|
|
5107
|
+
enumerable: true,
|
|
5108
|
+
get: function() {
|
|
5109
|
+
return _super_calendar_core.buildMultiWeekGrid;
|
|
5110
|
+
}
|
|
5111
|
+
});
|
|
3963
5112
|
exports.darkDomTheme = darkDomTheme;
|
|
3964
5113
|
Object.defineProperty(exports, "daySelectionState", {
|
|
3965
5114
|
enumerable: true,
|