@super-calendar/dom 2.16.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -2
- package/dist/index.d.mts +107 -23
- package/dist/index.d.ts +107 -23
- package/dist/index.js +802 -211
- package/dist/index.mjs +799 -215
- package/package.json +2 -2
- package/src/Agenda.tsx +18 -2
- package/src/Calendar.tsx +177 -37
- package/src/MonthView.tsx +556 -84
- package/src/MultiWeekView.tsx +54 -0
- package/src/TimeGrid.tsx +363 -153
- package/src/YearView.tsx +12 -1
- package/src/index.ts +7 -0
- package/src/touch.ts +70 -0
package/dist/index.js
CHANGED
|
@@ -102,8 +102,9 @@ function DefaultAgendaRow({ event, isAllDay, ampm = false, cardProps }) {
|
|
|
102
102
|
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
|
-
function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }) {
|
|
105
|
+
function Agenda({ events, locale, now, timeZone, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }) {
|
|
106
106
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
107
|
+
const today = (0, _super_calendar_core.nowInTimeZone)(now, timeZone);
|
|
107
108
|
const slot = createSlots({
|
|
108
109
|
classNames,
|
|
109
110
|
styles
|
|
@@ -148,7 +149,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
|
|
|
148
149
|
},
|
|
149
150
|
renderItem: ({ item }) => {
|
|
150
151
|
if (item.kind === "header") {
|
|
151
|
-
const highlighted = activeDate ? (0, date_fns.isSameDay)(item.date, activeDate) : (0, _super_calendar_core.getIsToday)(item.date);
|
|
152
|
+
const highlighted = activeDate ? (0, date_fns.isSameDay)(item.date, activeDate) : (0, _super_calendar_core.getIsToday)(item.date, today);
|
|
152
153
|
const label = (0, date_fns.format)(item.date, "EEEE, d LLLL", locale ? { locale } : void 0);
|
|
153
154
|
const color = highlighted ? theme.todayBackground : theme.textMuted;
|
|
154
155
|
const headerProps = slot("dayHeader", {
|
|
@@ -238,7 +239,7 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
|
|
|
238
239
|
* highlighted and a dot under days that hold events. It's the view `Calendar`
|
|
239
240
|
* renders for `mode="year"`.
|
|
240
241
|
*/
|
|
241
|
-
function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels: labelsProp, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, theme: themeOverrides, className, style, classNames, styles }) {
|
|
242
|
+
function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, now, timeZone, labels: labelsProp, activeDate, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, minMonthWidth = 150, onPressDay, onPressMonth, onSelectDrag, onCreateEvent, theme: themeOverrides, className, style, classNames, styles }) {
|
|
242
243
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
243
244
|
const labels = (0, react.useMemo)(() => (0, _super_calendar_core.resolveCalendarLabels)(labelsProp), [labelsProp]);
|
|
244
245
|
const slot = createSlots({
|
|
@@ -289,6 +290,7 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
|
|
|
289
290
|
window.addEventListener("pointerup", finish);
|
|
290
291
|
return () => window.removeEventListener("pointerup", finish);
|
|
291
292
|
}, [isCreating, onCreateEvent]);
|
|
293
|
+
const today = (0, _super_calendar_core.nowInTimeZone)(now, timeZone);
|
|
292
294
|
const months = (0, react.useMemo)(() => (0, _super_calendar_core.getYearMonths)(date), [date]);
|
|
293
295
|
const weekdayLabels = (0, react.useMemo)(() => (0, _super_calendar_core.filterHiddenDays)((0, _super_calendar_core.getWeekDays)(date, weekStartsOn), hiddenDays).map((d) => (0, date_fns.format)(d, (0, _super_calendar_core.weekdayFormatToken)("narrow"), { locale })), [
|
|
294
296
|
date,
|
|
@@ -385,7 +387,7 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
|
|
|
385
387
|
"aria-hidden": true,
|
|
386
388
|
style: { aspectRatio: "1" }
|
|
387
389
|
}, day.toISOString());
|
|
388
|
-
const isToday = (0, _super_calendar_core.getIsToday)(day);
|
|
390
|
+
const isToday = (0, _super_calendar_core.getIsToday)(day, today);
|
|
389
391
|
const isHighlighted = activeDate ? (0, _super_calendar_core.isSameCalendarDay)(day, activeDate) : isToday;
|
|
390
392
|
const hasEvents = eventDays.has((0, date_fns.startOfDay)(day).toISOString());
|
|
391
393
|
const state = (0, _super_calendar_core.daySelectionState)(day, {
|
|
@@ -542,6 +544,106 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
|
|
|
542
544
|
})
|
|
543
545
|
});
|
|
544
546
|
}
|
|
547
|
+
// src/touch.ts
|
|
548
|
+
function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
|
|
549
|
+
const detach = () => {
|
|
550
|
+
clearTimeout(timer);
|
|
551
|
+
document.removeEventListener("pointermove", move);
|
|
552
|
+
document.removeEventListener("pointerup", up);
|
|
553
|
+
document.removeEventListener("pointercancel", cancelPointer);
|
|
554
|
+
document.removeEventListener("pointerdown", anotherPointer);
|
|
555
|
+
};
|
|
556
|
+
const cancel = () => {
|
|
557
|
+
detach();
|
|
558
|
+
onCancel();
|
|
559
|
+
};
|
|
560
|
+
const move = (event) => {
|
|
561
|
+
if (event.pointerId === grab.pointerId && Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold) cancel();
|
|
562
|
+
};
|
|
563
|
+
const up = (event) => {
|
|
564
|
+
if (event.pointerId === grab.pointerId) {
|
|
565
|
+
detach();
|
|
566
|
+
onTap();
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
const cancelPointer = (event) => {
|
|
570
|
+
if (event.pointerId === grab.pointerId) cancel();
|
|
571
|
+
};
|
|
572
|
+
const anotherPointer = (event) => {
|
|
573
|
+
if (event.pointerId !== grab.pointerId) cancel();
|
|
574
|
+
};
|
|
575
|
+
const timer = setTimeout(() => {
|
|
576
|
+
detach();
|
|
577
|
+
onHold();
|
|
578
|
+
}, delay);
|
|
579
|
+
document.addEventListener("pointermove", move);
|
|
580
|
+
document.addEventListener("pointerup", up);
|
|
581
|
+
document.addEventListener("pointercancel", cancelPointer);
|
|
582
|
+
document.addEventListener("pointerdown", anotherPointer);
|
|
583
|
+
return cancel;
|
|
584
|
+
}
|
|
585
|
+
/** A quick swipe scrolls; a held pointer owns a date-row drag until release. */
|
|
586
|
+
function holdDateDrag(grab, start, move, cancel, release) {
|
|
587
|
+
const doc = grab.box.ownerDocument;
|
|
588
|
+
let active = false;
|
|
589
|
+
let finished = false;
|
|
590
|
+
let cancelWait;
|
|
591
|
+
const detach = () => {
|
|
592
|
+
doc.removeEventListener("pointermove", onMove);
|
|
593
|
+
doc.removeEventListener("pointerup", onUp);
|
|
594
|
+
doc.removeEventListener("pointercancel", onCancel);
|
|
595
|
+
doc.removeEventListener("pointerdown", onAnotherPointer);
|
|
596
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
597
|
+
doc.removeEventListener("contextmenu", onContextMenu);
|
|
598
|
+
};
|
|
599
|
+
const stop = () => {
|
|
600
|
+
if (finished) return;
|
|
601
|
+
finished = true;
|
|
602
|
+
detach();
|
|
603
|
+
cancelWait?.();
|
|
604
|
+
cancel();
|
|
605
|
+
release();
|
|
606
|
+
};
|
|
607
|
+
const onMove = (event) => {
|
|
608
|
+
if (active && event.pointerId === grab.pointerId) move(event.clientX, event.clientY);
|
|
609
|
+
};
|
|
610
|
+
const onUp = (event) => {
|
|
611
|
+
if (event.pointerId !== grab.pointerId) return;
|
|
612
|
+
finished = true;
|
|
613
|
+
detach();
|
|
614
|
+
release();
|
|
615
|
+
};
|
|
616
|
+
const onCancel = (event) => {
|
|
617
|
+
if (event.pointerId === grab.pointerId) stop();
|
|
618
|
+
};
|
|
619
|
+
const onAnotherPointer = (event) => {
|
|
620
|
+
if (event.pointerId !== grab.pointerId) stop();
|
|
621
|
+
};
|
|
622
|
+
const onTouchMove = (event) => {
|
|
623
|
+
if (active && event.cancelable) event.preventDefault();
|
|
624
|
+
};
|
|
625
|
+
const onContextMenu = (event) => {
|
|
626
|
+
event.preventDefault();
|
|
627
|
+
};
|
|
628
|
+
doc.addEventListener("pointermove", onMove);
|
|
629
|
+
doc.addEventListener("pointerup", onUp);
|
|
630
|
+
doc.addEventListener("pointercancel", onCancel);
|
|
631
|
+
doc.addEventListener("pointerdown", onAnotherPointer);
|
|
632
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
633
|
+
doc.addEventListener("contextmenu", onContextMenu);
|
|
634
|
+
cancelWait = waitForHold(grab, 400, 8, () => {
|
|
635
|
+
active = true;
|
|
636
|
+
start();
|
|
637
|
+
}, release, stop);
|
|
638
|
+
return stop;
|
|
639
|
+
}
|
|
640
|
+
// src/InertDiv.ts
|
|
641
|
+
function InertDiv(props) {
|
|
642
|
+
return (0, react.createElement)("div", {
|
|
643
|
+
...props,
|
|
644
|
+
inert: props.inert ? "inert" : void 0
|
|
645
|
+
});
|
|
646
|
+
}
|
|
545
647
|
// src/MonthView.tsx
|
|
546
648
|
const EMPTY_LAYOUT = {
|
|
547
649
|
segments: [],
|
|
@@ -551,6 +653,9 @@ const CHIP_HEIGHT = 18;
|
|
|
551
653
|
const CHIP_GAP = 2;
|
|
552
654
|
const CELL_PAD = 4;
|
|
553
655
|
const DRAGGED_CHIP_OPACITY = .4;
|
|
656
|
+
const DRAG_SLOP_PX = 4;
|
|
657
|
+
const TOUCH_DRAG_SLOP_PX = 8;
|
|
658
|
+
const isOutsidePeriod = (day) => day.isCurrentMonth === false;
|
|
554
659
|
function dayCellDefault(day, theme, highlightWeekends) {
|
|
555
660
|
return {
|
|
556
661
|
base: {
|
|
@@ -710,7 +815,7 @@ function chipDefault(theme, chipHeight) {
|
|
|
710
815
|
}
|
|
711
816
|
};
|
|
712
817
|
}
|
|
713
|
-
function moreButtonDefault(theme, chipHeight) {
|
|
818
|
+
function moreButtonDefault(theme, chipHeight, multiWeek = false) {
|
|
714
819
|
return {
|
|
715
820
|
base: {
|
|
716
821
|
position: "relative",
|
|
@@ -721,7 +826,12 @@ function moreButtonDefault(theme, chipHeight) {
|
|
|
721
826
|
textAlign: "left",
|
|
722
827
|
height: chipHeight,
|
|
723
828
|
lineHeight: `${chipHeight}px`,
|
|
724
|
-
fontFamily: "inherit"
|
|
829
|
+
fontFamily: "inherit",
|
|
830
|
+
...multiWeek ? {
|
|
831
|
+
whiteSpace: "nowrap",
|
|
832
|
+
overflow: "hidden",
|
|
833
|
+
textOverflow: "ellipsis"
|
|
834
|
+
} : {}
|
|
725
835
|
},
|
|
726
836
|
themed: {
|
|
727
837
|
padding: "0 6px",
|
|
@@ -744,6 +854,10 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
744
854
|
}
|
|
745
855
|
return out;
|
|
746
856
|
}
|
|
857
|
+
function rangeTitle(start, endExclusive, locale) {
|
|
858
|
+
const options = locale ? { locale } : void 0;
|
|
859
|
+
return `${(0, date_fns.format)(start, "PP", options)} – ${(0, date_fns.format)((0, date_fns.addDays)(endExclusive, -1), "PP", options)}`;
|
|
860
|
+
}
|
|
747
861
|
/**
|
|
748
862
|
* A single static month grid, rendered with plain DOM elements.
|
|
749
863
|
*
|
|
@@ -752,15 +866,36 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
752
866
|
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
753
867
|
* ```
|
|
754
868
|
*/
|
|
755
|
-
function MonthView({ date,
|
|
869
|
+
function MonthView({ date, showAdjacentMonths = true, ...rest }) {
|
|
870
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateRows, {
|
|
871
|
+
...rest,
|
|
872
|
+
source: {
|
|
873
|
+
kind: "month",
|
|
874
|
+
date,
|
|
875
|
+
showAdjacentMonths
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
881
|
+
* spanning event bars, overflow, selection, drag, and keyboard handling.
|
|
882
|
+
*/
|
|
883
|
+
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, now, timeZone, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onPressCell, onCreateEvent, renderCreateGhost: RenderCreateGhost, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, keyboardDayNavigation = false, className, style, classNames, styles }) {
|
|
884
|
+
const { date } = source;
|
|
885
|
+
const multiWeek = source.kind === "multiweek";
|
|
886
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
887
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : void 0;
|
|
888
|
+
const viewMode = multiWeek ? "multiweek" : "month";
|
|
756
889
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
757
890
|
const labels = (0, react.useMemo)(() => (0, _super_calendar_core.resolveCalendarLabels)(labelsProp), [labelsProp]);
|
|
758
891
|
const slot = createSlots({
|
|
759
892
|
classNames,
|
|
760
893
|
styles
|
|
761
894
|
});
|
|
762
|
-
const
|
|
895
|
+
const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
|
|
896
|
+
const eventsMode = events !== void 0 || multiWeek || createContentEnabled;
|
|
763
897
|
const dayRoving = !eventsMode || keyboardDayNavigation;
|
|
898
|
+
const todayKey = (0, date_fns.startOfDay)((0, _super_calendar_core.nowInTimeZone)(now, timeZone)).getTime();
|
|
764
899
|
const eventsByDay = (0, react.useMemo)(() => {
|
|
765
900
|
if (eventsByDayProp) return eventsByDayProp;
|
|
766
901
|
const map = (0, _super_calendar_core.groupEventsByDay)((events ?? []).filter((event) => !(0, _super_calendar_core.isBackgroundEvent)(event)));
|
|
@@ -797,34 +932,66 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
797
932
|
document.removeEventListener("keydown", onKey);
|
|
798
933
|
};
|
|
799
934
|
}, [moreOpenFor]);
|
|
800
|
-
const eventRowHeight = 32 + maxVisibleEventCount * (chipHeight + chipGap);
|
|
801
|
-
const { weeks, weekdays } = (0, react.useMemo)(() =>
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
935
|
+
const eventRowHeight = 32 + (multiWeek ? Math.max(1, maxVisibleEventCount) : maxVisibleEventCount) * (chipHeight + chipGap);
|
|
936
|
+
const { weeks, weekdays, title, period } = (0, react.useMemo)(() => {
|
|
937
|
+
const options = {
|
|
938
|
+
weekStartsOn,
|
|
939
|
+
hiddenDays,
|
|
940
|
+
weekdayFormat,
|
|
941
|
+
selectedRange,
|
|
942
|
+
selectedDates,
|
|
943
|
+
minDate,
|
|
944
|
+
maxDate,
|
|
945
|
+
isDateDisabled,
|
|
946
|
+
locale,
|
|
947
|
+
today: new Date(todayKey)
|
|
948
|
+
};
|
|
949
|
+
if (numberOfWeeks === void 0) return {
|
|
950
|
+
...(0, _super_calendar_core.buildMonthGrid)(date, options),
|
|
951
|
+
title: (0, date_fns.format)(date, "MMMM yyyy", locale ? { locale } : void 0),
|
|
952
|
+
period: null
|
|
953
|
+
};
|
|
954
|
+
const grid = (0, _super_calendar_core.buildMultiWeekGrid)(date, {
|
|
955
|
+
...options,
|
|
956
|
+
numberOfWeeks
|
|
957
|
+
});
|
|
958
|
+
return {
|
|
959
|
+
weeks: grid.weeks,
|
|
960
|
+
weekdays: grid.weekdays,
|
|
961
|
+
title: rangeTitle(grid.visibleRange.start, grid.visibleRange.endExclusive, locale),
|
|
962
|
+
period: grid.period
|
|
963
|
+
};
|
|
964
|
+
}, [
|
|
812
965
|
date,
|
|
966
|
+
numberOfWeeks,
|
|
813
967
|
weekStartsOn,
|
|
968
|
+
hiddenDays,
|
|
814
969
|
weekdayFormat,
|
|
815
970
|
selectedRange,
|
|
816
971
|
selectedDates,
|
|
817
972
|
minDate,
|
|
818
973
|
maxDate,
|
|
819
974
|
isDateDisabled,
|
|
820
|
-
locale
|
|
975
|
+
locale,
|
|
976
|
+
todayKey
|
|
821
977
|
]);
|
|
822
978
|
const weekLayouts = (0, react.useMemo)(() => eventsMode ? weeks.map((week) => (0, _super_calendar_core.layoutMonthWeek)(week.days.map((d) => d.date), collectRowEvents(week, eventsByDay))) : [], [
|
|
823
979
|
eventsMode,
|
|
824
980
|
weeks,
|
|
825
981
|
eventsByDay
|
|
826
982
|
]);
|
|
983
|
+
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]);
|
|
984
|
+
const focusableKeys = (0, react.useMemo)(() => focusableDays ? new Set(focusableDays.map((d) => (0, date_fns.format)(d, "yyyy-MM-dd"))) : null, [focusableDays]);
|
|
827
985
|
const initialFocus = (0, react.useMemo)(() => {
|
|
986
|
+
if (focusableDays && focusableKeys) {
|
|
987
|
+
const rendered = (d) => !!d && focusableKeys.has((0, date_fns.format)(d, "yyyy-MM-dd"));
|
|
988
|
+
if (rendered(selectedRange?.start)) return (0, date_fns.startOfDay)(selectedRange.start);
|
|
989
|
+
const picked = selectedDates?.find(rendered);
|
|
990
|
+
if (picked) return (0, date_fns.startOfDay)(picked);
|
|
991
|
+
const today = /* @__PURE__ */ new Date();
|
|
992
|
+
if (rendered(today)) return (0, date_fns.startOfDay)(today);
|
|
993
|
+
return focusableDays[0] ?? null;
|
|
994
|
+
}
|
|
828
995
|
const inMonth = (d) => !!d && (0, date_fns.isSameMonth)(d, date);
|
|
829
996
|
if (inMonth(selectedRange?.start)) return (0, date_fns.startOfDay)(selectedRange.start);
|
|
830
997
|
const picked = selectedDates?.find(inMonth);
|
|
@@ -832,6 +999,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
832
999
|
const today = /* @__PURE__ */ new Date();
|
|
833
1000
|
return (0, date_fns.isSameMonth)(today, date) ? (0, date_fns.startOfDay)(today) : (0, date_fns.startOfMonth)(date);
|
|
834
1001
|
}, [
|
|
1002
|
+
focusableDays,
|
|
1003
|
+
focusableKeys,
|
|
835
1004
|
date,
|
|
836
1005
|
selectedRange,
|
|
837
1006
|
selectedDates
|
|
@@ -839,77 +1008,194 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
839
1008
|
const [focusedDate, setFocusedDate] = (0, react.useState)(initialFocus);
|
|
840
1009
|
const initialFocusRef = (0, react.useRef)(initialFocus);
|
|
841
1010
|
initialFocusRef.current = initialFocus;
|
|
842
|
-
const
|
|
843
|
-
const
|
|
1011
|
+
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");
|
|
1012
|
+
const windowKeyRef = (0, react.useRef)(windowKey);
|
|
1013
|
+
windowKeyRef.current = windowKey;
|
|
1014
|
+
const focusedWindow = (0, react.useRef)(windowKey);
|
|
1015
|
+
const gridRef = (0, react.useRef)(null);
|
|
1016
|
+
const restoreDayFocus = (0, react.useRef)(false);
|
|
1017
|
+
if (multiWeek && windowKey !== focusedWindow.current) {
|
|
1018
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1019
|
+
restoreDayFocus.current = !!active?.hasAttribute("data-day") && !!gridRef.current?.contains(active);
|
|
1020
|
+
}
|
|
844
1021
|
(0, react.useEffect)(() => {
|
|
845
|
-
if (
|
|
846
|
-
|
|
1022
|
+
if (windowKey === focusedWindow.current) return;
|
|
1023
|
+
focusedWindow.current = windowKey;
|
|
847
1024
|
setFocusedDate(initialFocusRef.current);
|
|
848
|
-
|
|
1025
|
+
if (restoreDayFocus.current) {
|
|
1026
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1027
|
+
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();
|
|
1028
|
+
}
|
|
1029
|
+
restoreDayFocus.current = false;
|
|
1030
|
+
}, [windowKey]);
|
|
849
1031
|
const [hoveredKey, setHoveredKey] = (0, react.useState)(null);
|
|
850
|
-
const
|
|
851
|
-
const focusKey = (0, date_fns.format)(
|
|
1032
|
+
const storedFocusKey = focusedDate ? (0, date_fns.format)(focusedDate, "yyyy-MM-dd") : null;
|
|
1033
|
+
const focusKey = focusableKeys && (storedFocusKey === null || !focusableKeys.has(storedFocusKey)) ? initialFocus && (0, date_fns.format)(initialFocus, "yyyy-MM-dd") : storedFocusKey;
|
|
1034
|
+
(0, react.useEffect)(() => {
|
|
1035
|
+
if (!multiWeek) return;
|
|
1036
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1037
|
+
if (!active?.hasAttribute("data-day") || !gridRef.current?.contains(active)) return;
|
|
1038
|
+
if (active.getAttribute("data-day") === focusKey && active.getAttribute("aria-disabled") !== "true") return;
|
|
1039
|
+
(focusKey ? gridRef.current.querySelector(`[data-day="${focusKey}"]`) : gridRef.current)?.focus();
|
|
1040
|
+
}, [multiWeek, focusKey]);
|
|
852
1041
|
const [drag, setDrag] = (0, react.useState)(null);
|
|
853
|
-
const dragRef = (0, react.useRef)(
|
|
854
|
-
|
|
1042
|
+
const dragRef = (0, react.useRef)(null);
|
|
1043
|
+
const applyDrag = (0, react.useCallback)((next) => {
|
|
1044
|
+
dragRef.current = next;
|
|
1045
|
+
setDrag(next);
|
|
1046
|
+
}, []);
|
|
1047
|
+
const createStart = drag?.kind === "create" ? drag.anchor : null;
|
|
1048
|
+
const createEnd = drag?.kind === "create" ? drag.hover : null;
|
|
1049
|
+
const createRange = (0, react.useMemo)(() => createContentEnabled && createStart !== null && createEnd !== null ? (0, _super_calendar_core.monthCreateRange)(new Date(createStart), new Date(createEnd)) : null, [
|
|
1050
|
+
createContentEnabled,
|
|
1051
|
+
createStart,
|
|
1052
|
+
createEnd
|
|
1053
|
+
]);
|
|
855
1054
|
const movedRef = (0, react.useRef)(false);
|
|
856
1055
|
const suppressClickRef = (0, react.useRef)(false);
|
|
857
|
-
const consumeSuppressedClick = () => {
|
|
858
|
-
if (!suppressClickRef.current) return false;
|
|
1056
|
+
const consumeSuppressedClick = (detail) => {
|
|
1057
|
+
if (detail === 0 || !suppressClickRef.current) return false;
|
|
859
1058
|
suppressClickRef.current = false;
|
|
860
1059
|
return true;
|
|
861
1060
|
};
|
|
862
1061
|
const canMove = (event) => onDragEvent != null && !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable);
|
|
1062
|
+
const pressOrigin = (0, react.useRef)({
|
|
1063
|
+
x: 0,
|
|
1064
|
+
y: 0,
|
|
1065
|
+
slop: DRAG_SLOP_PX
|
|
1066
|
+
});
|
|
863
1067
|
const beginPress = () => {
|
|
864
1068
|
suppressClickRef.current = false;
|
|
865
1069
|
movedRef.current = false;
|
|
866
1070
|
};
|
|
867
|
-
const beginCreate = (day) => {
|
|
1071
|
+
const beginCreate = (day, pointerId, armed) => {
|
|
868
1072
|
if (!onCreateEvent && !onSelectDrag) return;
|
|
869
1073
|
const t = (0, date_fns.startOfDay)(day).getTime();
|
|
870
|
-
|
|
1074
|
+
applyDrag({
|
|
871
1075
|
kind: "create",
|
|
872
1076
|
anchor: t,
|
|
873
|
-
hover: t
|
|
1077
|
+
hover: t,
|
|
1078
|
+
windowKey,
|
|
1079
|
+
pointerId,
|
|
1080
|
+
armed
|
|
874
1081
|
});
|
|
875
1082
|
};
|
|
876
|
-
const beginMove = (event, day) => {
|
|
1083
|
+
const beginMove = (event, day, pointerId, armed) => {
|
|
877
1084
|
if (!canMove(event)) return;
|
|
878
1085
|
const t = (0, date_fns.startOfDay)(day).getTime();
|
|
879
|
-
|
|
1086
|
+
applyDrag({
|
|
880
1087
|
kind: "move",
|
|
881
1088
|
event,
|
|
882
1089
|
from: t,
|
|
883
|
-
to: t
|
|
1090
|
+
to: t,
|
|
1091
|
+
windowKey,
|
|
1092
|
+
pointerId,
|
|
1093
|
+
armed
|
|
884
1094
|
});
|
|
885
1095
|
onDragStart?.(event);
|
|
886
1096
|
};
|
|
887
|
-
const extendDrag = (day) => {
|
|
1097
|
+
const extendDrag = (day, pointerId) => {
|
|
888
1098
|
const current = dragRef.current;
|
|
889
|
-
if (!current) return;
|
|
1099
|
+
if (!current || current.pointerId !== pointerId) return;
|
|
890
1100
|
const t = (0, date_fns.startOfDay)(day).getTime();
|
|
891
1101
|
if (t === (current.kind === "create" ? current.hover : current.to)) return;
|
|
892
1102
|
movedRef.current = true;
|
|
893
|
-
|
|
1103
|
+
applyDrag(current.kind === "create" ? {
|
|
894
1104
|
...current,
|
|
895
|
-
hover: t
|
|
1105
|
+
hover: t,
|
|
1106
|
+
armed: true
|
|
896
1107
|
} : {
|
|
897
1108
|
...current,
|
|
898
|
-
to: t
|
|
1109
|
+
to: t,
|
|
1110
|
+
armed: true
|
|
899
1111
|
});
|
|
900
1112
|
if (current.kind === "create") {
|
|
901
1113
|
const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
|
|
902
1114
|
onSelectDrag?.(new Date(lo), new Date(hi));
|
|
903
1115
|
}
|
|
904
1116
|
};
|
|
1117
|
+
const heldTouch = (0, react.useRef)(null);
|
|
1118
|
+
const heldOrigin = (0, react.useRef)(null);
|
|
1119
|
+
const dayLookup = (0, react.useMemo)(() => new Map(weeks.flatMap((week) => week.days).map((day) => [day.id, day])), [weeks]);
|
|
1120
|
+
const touchHandlers = (0, react.useRef)({
|
|
1121
|
+
beginCreate,
|
|
1122
|
+
beginMove,
|
|
1123
|
+
extendDrag,
|
|
1124
|
+
dayLookup
|
|
1125
|
+
});
|
|
1126
|
+
touchHandlers.current = {
|
|
1127
|
+
beginCreate,
|
|
1128
|
+
beginMove,
|
|
1129
|
+
extendDrag,
|
|
1130
|
+
dayLookup
|
|
1131
|
+
};
|
|
1132
|
+
const pressRow = (event, day, moving) => {
|
|
1133
|
+
if (event.button !== 0 || event.isPrimary === false || heldTouch.current) return;
|
|
1134
|
+
beginPress();
|
|
1135
|
+
pressOrigin.current = {
|
|
1136
|
+
x: event.clientX,
|
|
1137
|
+
y: event.clientY,
|
|
1138
|
+
slop: event.pointerType === "touch" ? TOUCH_DRAG_SLOP_PX : DRAG_SLOP_PX
|
|
1139
|
+
};
|
|
1140
|
+
const start = (armed) => {
|
|
1141
|
+
if (moving) touchHandlers.current.beginMove(moving, day, event.pointerId, armed);
|
|
1142
|
+
else touchHandlers.current.beginCreate(day, event.pointerId, armed);
|
|
1143
|
+
};
|
|
1144
|
+
if (!multiWeek || !event.pointerType || event.pointerType === "mouse") {
|
|
1145
|
+
start(false);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
heldOrigin.current = {
|
|
1149
|
+
day,
|
|
1150
|
+
event: moving
|
|
1151
|
+
};
|
|
1152
|
+
heldTouch.current = holdDateDrag({
|
|
1153
|
+
box: event.currentTarget,
|
|
1154
|
+
pointerId: event.pointerId,
|
|
1155
|
+
pointerType: event.pointerType,
|
|
1156
|
+
clientX: event.clientX,
|
|
1157
|
+
clientY: event.clientY
|
|
1158
|
+
}, () => start(true), (x, y) => {
|
|
1159
|
+
const element = gridRef.current?.ownerDocument.elementFromPoint(x, y)?.closest("[data-day]");
|
|
1160
|
+
if (!element || !gridRef.current?.contains(element)) return;
|
|
1161
|
+
const day = touchHandlers.current.dayLookup.get(element.dataset.day ?? "");
|
|
1162
|
+
if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date, event.pointerId);
|
|
1163
|
+
}, () => {
|
|
1164
|
+
applyDrag(null);
|
|
1165
|
+
movedRef.current = false;
|
|
1166
|
+
}, () => {
|
|
1167
|
+
heldTouch.current = null;
|
|
1168
|
+
heldOrigin.current = null;
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
(0, react.useEffect)(() => () => {
|
|
1172
|
+
heldTouch.current?.();
|
|
1173
|
+
}, [windowKey]);
|
|
1174
|
+
(0, react.useEffect)(() => {
|
|
1175
|
+
const origin = heldOrigin.current;
|
|
1176
|
+
if (!origin) return;
|
|
1177
|
+
const current = dragRef.current;
|
|
1178
|
+
const destination = current ? new Date(current.kind === "create" ? current.hover : current.to) : origin.day;
|
|
1179
|
+
const enabled = (day) => {
|
|
1180
|
+
const cell = dayLookup.get((0, date_fns.format)(day, "yyyy-MM-dd"));
|
|
1181
|
+
return cell != null && !cell.isDisabled;
|
|
1182
|
+
};
|
|
1183
|
+
if (!enabled(origin.day) || !enabled(destination) || (origin.event ? !events?.includes(origin.event) || !canMove(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
|
|
1184
|
+
});
|
|
905
1185
|
const isDragging = drag !== null;
|
|
1186
|
+
const dragArmed = drag?.armed === true;
|
|
906
1187
|
const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
907
1188
|
(0, react.useEffect)(() => {
|
|
908
1189
|
if (!isDragging) return;
|
|
909
|
-
const finish = () => {
|
|
1190
|
+
const finish = (event) => {
|
|
910
1191
|
const current = dragRef.current;
|
|
911
|
-
|
|
912
|
-
|
|
1192
|
+
if (!current || current.pointerId !== event.pointerId) return;
|
|
1193
|
+
applyDrag(null);
|
|
1194
|
+
if (!movedRef.current) {
|
|
1195
|
+
if (current.kind === "move" && current.armed) suppressClickRef.current = true;
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
if (multiWeek && current.windowKey !== windowKeyRef.current) return;
|
|
913
1199
|
suppressClickRef.current = true;
|
|
914
1200
|
if (current.kind === "create") {
|
|
915
1201
|
const range = (0, _super_calendar_core.monthCreateRange)(new Date(current.anchor), new Date(current.hover));
|
|
@@ -921,16 +1207,92 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
921
1207
|
if (eventOverlap === false && (0, _super_calendar_core.overlapsOtherEvents)(events ?? [], current.event, next.start, next.end)) return;
|
|
922
1208
|
onDragEvent?.(current.event, next.start, next.end);
|
|
923
1209
|
};
|
|
1210
|
+
const clear = () => {
|
|
1211
|
+
heldTouch.current?.();
|
|
1212
|
+
applyDrag(null);
|
|
1213
|
+
movedRef.current = false;
|
|
1214
|
+
suppressClickRef.current = true;
|
|
1215
|
+
};
|
|
1216
|
+
const cancel = (event) => {
|
|
1217
|
+
if (dragRef.current?.pointerId === event.pointerId) clear();
|
|
1218
|
+
};
|
|
1219
|
+
const arm = (event) => {
|
|
1220
|
+
const current = dragRef.current;
|
|
1221
|
+
if (!current || current.armed || current.pointerId !== event.pointerId) return;
|
|
1222
|
+
const origin = pressOrigin.current;
|
|
1223
|
+
if (Math.hypot(event.clientX - origin.x, event.clientY - origin.y) <= origin.slop) return;
|
|
1224
|
+
applyDrag({
|
|
1225
|
+
...current,
|
|
1226
|
+
armed: true
|
|
1227
|
+
});
|
|
1228
|
+
};
|
|
1229
|
+
const keyDown = (event) => {
|
|
1230
|
+
if (event.key !== "Escape") return;
|
|
1231
|
+
event.preventDefault();
|
|
1232
|
+
clear();
|
|
1233
|
+
};
|
|
1234
|
+
window.addEventListener("pointermove", arm);
|
|
924
1235
|
window.addEventListener("pointerup", finish);
|
|
925
|
-
|
|
1236
|
+
window.addEventListener("pointercancel", cancel);
|
|
1237
|
+
window.addEventListener("keydown", keyDown);
|
|
1238
|
+
return () => {
|
|
1239
|
+
window.removeEventListener("pointermove", arm);
|
|
1240
|
+
window.removeEventListener("pointerup", finish);
|
|
1241
|
+
window.removeEventListener("pointercancel", cancel);
|
|
1242
|
+
window.removeEventListener("keydown", keyDown);
|
|
1243
|
+
};
|
|
926
1244
|
}, [
|
|
927
1245
|
isDragging,
|
|
1246
|
+
multiWeek,
|
|
928
1247
|
onCreateEvent,
|
|
929
1248
|
onDragEvent,
|
|
930
1249
|
eventOverlap,
|
|
931
|
-
events
|
|
1250
|
+
events,
|
|
1251
|
+
applyDrag
|
|
1252
|
+
]);
|
|
1253
|
+
const transientWindow = (0, react.useRef)(windowKey);
|
|
1254
|
+
(0, react.useEffect)(() => {
|
|
1255
|
+
if (transientWindow.current === windowKey) return;
|
|
1256
|
+
transientWindow.current = windowKey;
|
|
1257
|
+
if (!multiWeek) return;
|
|
1258
|
+
applyDrag(null);
|
|
1259
|
+
setMoreOpenFor(null);
|
|
1260
|
+
}, [
|
|
1261
|
+
multiWeek,
|
|
1262
|
+
windowKey,
|
|
1263
|
+
applyDrag
|
|
932
1264
|
]);
|
|
1265
|
+
const nextMultiWeekFocus = (key) => {
|
|
1266
|
+
if (!focusableDays || !focusableKeys || !period) return void 0;
|
|
1267
|
+
const index = focusableDays.findIndex((d) => (0, date_fns.format)(d, "yyyy-MM-dd") === focusKey);
|
|
1268
|
+
if (index === -1) return null;
|
|
1269
|
+
if (key === "ArrowLeft") return focusableDays[index - 1] ?? null;
|
|
1270
|
+
if (key === "ArrowRight") return focusableDays[index + 1] ?? null;
|
|
1271
|
+
if (key === "Home") return focusableDays[0];
|
|
1272
|
+
if (key === "End") return focusableDays[focusableDays.length - 1];
|
|
1273
|
+
const step = key === "ArrowUp" ? -7 : 7;
|
|
1274
|
+
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;
|
|
1275
|
+
return null;
|
|
1276
|
+
};
|
|
933
1277
|
const onKeyDown = (e) => {
|
|
1278
|
+
if (multiWeek) {
|
|
1279
|
+
if (![
|
|
1280
|
+
"ArrowLeft",
|
|
1281
|
+
"ArrowRight",
|
|
1282
|
+
"ArrowUp",
|
|
1283
|
+
"ArrowDown",
|
|
1284
|
+
"Home",
|
|
1285
|
+
"End"
|
|
1286
|
+
].includes(e.key)) return;
|
|
1287
|
+
e.preventDefault();
|
|
1288
|
+
const target = nextMultiWeekFocus(e.key);
|
|
1289
|
+
if (!target) return;
|
|
1290
|
+
setFocusedDate(target);
|
|
1291
|
+
const targetKey = (0, date_fns.format)(target, "yyyy-MM-dd");
|
|
1292
|
+
gridRef.current?.querySelector(`[data-day="${targetKey}"]`)?.focus();
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
if (!focusedDate) return;
|
|
934
1296
|
let next = null;
|
|
935
1297
|
if (e.key === "ArrowLeft") next = (0, date_fns.addDays)(focusedDate, -1);
|
|
936
1298
|
else if (e.key === "ArrowRight") next = (0, date_fns.addDays)(focusedDate, 1);
|
|
@@ -950,6 +1312,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
950
1312
|
style: {
|
|
951
1313
|
fontFamily: theme.fontFamily,
|
|
952
1314
|
color: theme.text,
|
|
1315
|
+
...multiWeek ? {
|
|
1316
|
+
display: "flex",
|
|
1317
|
+
flexDirection: "column",
|
|
1318
|
+
minHeight: 0
|
|
1319
|
+
} : null,
|
|
953
1320
|
...style
|
|
954
1321
|
},
|
|
955
1322
|
children: [
|
|
@@ -959,13 +1326,13 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
959
1326
|
fontWeight: 700,
|
|
960
1327
|
padding: "10px 14px 6px"
|
|
961
1328
|
} }),
|
|
962
|
-
children:
|
|
1329
|
+
children: title
|
|
963
1330
|
}) : null,
|
|
964
1331
|
showWeekdays ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
965
1332
|
...slot("weekdays", {
|
|
966
1333
|
base: {
|
|
967
1334
|
display: "grid",
|
|
968
|
-
gridTemplateColumns:
|
|
1335
|
+
gridTemplateColumns: `repeat(${weekdays.length}, minmax(0, 1fr))`
|
|
969
1336
|
},
|
|
970
1337
|
themed: {
|
|
971
1338
|
borderBottom: `1px solid ${theme.gridLine}`,
|
|
@@ -985,9 +1352,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
985
1352
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
986
1353
|
ref: gridRef,
|
|
987
1354
|
role: "grid",
|
|
988
|
-
|
|
1355
|
+
tabIndex: multiWeek ? -1 : void 0,
|
|
1356
|
+
"aria-label": title,
|
|
989
1357
|
onKeyDown: dayRoving ? onKeyDown : void 0,
|
|
990
|
-
...slot("grid"
|
|
1358
|
+
...slot("grid", multiWeek ? { base: {
|
|
1359
|
+
flex: "1 1 auto",
|
|
1360
|
+
minHeight: 0,
|
|
1361
|
+
overflowY: "auto"
|
|
1362
|
+
} } : void 0),
|
|
991
1363
|
children: weeks.map((week, weekIndex) => {
|
|
992
1364
|
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
993
1365
|
const visibleLanes = rowLayout.laneCount > maxVisibleEventCount ? Math.max(maxVisibleEventCount - 1, 1) : rowLayout.laneCount;
|
|
@@ -995,8 +1367,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
995
1367
|
let firstVisCol = 0;
|
|
996
1368
|
let lastVisCol = cols - 1;
|
|
997
1369
|
if (eventsMode && !showAdjacentMonths) {
|
|
998
|
-
const first = week.days.findIndex((d) => d
|
|
999
|
-
const lastFromEnd = [...week.days].reverse().findIndex((d) => d
|
|
1370
|
+
const first = week.days.findIndex((d) => !isOutsidePeriod(d));
|
|
1371
|
+
const lastFromEnd = [...week.days].reverse().findIndex((d) => !isOutsidePeriod(d));
|
|
1000
1372
|
if (first !== -1) {
|
|
1001
1373
|
firstVisCol = first;
|
|
1002
1374
|
lastVisCol = cols - 1 - lastFromEnd;
|
|
@@ -1013,16 +1385,21 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1013
1385
|
continuesAfter: s.continuesAfter || endCol < s.endCol
|
|
1014
1386
|
};
|
|
1015
1387
|
}).filter((b) => b.startCol <= b.endCol);
|
|
1388
|
+
const draftColumns = createRange ? week.days.flatMap((day, index) => !showAdjacentMonths && isOutsidePeriod(day) || day.date < createRange.start || day.date >= createRange.end ? [] : [index]) : [];
|
|
1389
|
+
const draftStart = draftColumns[0];
|
|
1390
|
+
const draftEnd = draftColumns.at(-1);
|
|
1391
|
+
const draftTop = 28 + chipGap + Math.min(visibleLanes, Math.max(0, maxVisibleEventCount - 1)) * (chipHeight + chipGap);
|
|
1392
|
+
const draftHeight = Math.min(chipHeight, Math.max(0, eventRowHeight - draftTop));
|
|
1016
1393
|
const barChipButton = slot("chipButton", chipButtonDefault);
|
|
1017
1394
|
const barChip = slot("chip", chipDefault(theme, chipHeight));
|
|
1018
1395
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1019
1396
|
role: "row",
|
|
1020
1397
|
...slot("week", { base: {
|
|
1021
1398
|
display: "grid",
|
|
1022
|
-
gridTemplateColumns:
|
|
1399
|
+
gridTemplateColumns: `repeat(${week.days.length}, minmax(0, 1fr))`
|
|
1023
1400
|
} }),
|
|
1024
1401
|
children: week.days.map((day, dayCol) => {
|
|
1025
|
-
const hidden = !showAdjacentMonths &&
|
|
1402
|
+
const hidden = !showAdjacentMonths && isOutsidePeriod(day);
|
|
1026
1403
|
const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
|
|
1027
1404
|
if (hidden) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1028
1405
|
role: "gridcell",
|
|
@@ -1044,7 +1421,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1044
1421
|
"data-selected": day.isSelected,
|
|
1045
1422
|
"data-range": day.isInRange,
|
|
1046
1423
|
"data-weekend": day.isWeekend,
|
|
1047
|
-
"data-outside":
|
|
1424
|
+
"data-outside": isOutsidePeriod(day),
|
|
1048
1425
|
"data-disabled": day.isDisabled,
|
|
1049
1426
|
"data-creating": inCreate,
|
|
1050
1427
|
"data-drop": isDropTarget
|
|
@@ -1073,17 +1450,15 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1073
1450
|
...dayCellProps,
|
|
1074
1451
|
style: dragWired ? {
|
|
1075
1452
|
...dayCellProps.style,
|
|
1076
|
-
touchAction: "none",
|
|
1453
|
+
touchAction: multiWeek ? "pan-y" : "none",
|
|
1077
1454
|
userSelect: "none"
|
|
1078
1455
|
} : dayCellProps.style,
|
|
1079
1456
|
onPointerDown: dragWired && !day.isDisabled ? (e) => {
|
|
1080
|
-
|
|
1081
|
-
beginPress();
|
|
1082
|
-
beginCreate(day.date);
|
|
1457
|
+
pressRow(e, day.date);
|
|
1083
1458
|
} : void 0,
|
|
1084
|
-
onPointerEnter: dragWired && !day.isDisabled ? () => extendDrag(day.date) : void 0,
|
|
1085
|
-
onClick: day.isDisabled ? void 0 : () => {
|
|
1086
|
-
if (consumeSuppressedClick()) return;
|
|
1459
|
+
onPointerEnter: dragWired && !day.isDisabled ? (event) => extendDrag(day.date, event.pointerId) : void 0,
|
|
1460
|
+
onClick: day.isDisabled ? void 0 : (e) => {
|
|
1461
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1087
1462
|
onPressDay?.(day.date);
|
|
1088
1463
|
onPressCell?.((0, date_fns.startOfDay)(day.date));
|
|
1089
1464
|
},
|
|
@@ -1108,24 +1483,23 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1108
1483
|
}),
|
|
1109
1484
|
barSegs.filter((b) => b.startCol === dayCol).map((b) => {
|
|
1110
1485
|
const span = b.endCol - b.startCol + 1;
|
|
1111
|
-
const isDragged = drag?.kind === "move" && drag.event === b.seg.event;
|
|
1486
|
+
const isDragged = dragArmed && drag?.kind === "move" && drag.event === b.seg.event;
|
|
1112
1487
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1113
1488
|
type: "button",
|
|
1114
1489
|
onPointerDown: canMove(b.seg.event) ? (e) => {
|
|
1115
1490
|
if (e.button !== 0) return;
|
|
1116
1491
|
e.stopPropagation();
|
|
1117
|
-
|
|
1118
|
-
beginMove(b.seg.event, day.date);
|
|
1492
|
+
pressRow(e, day.date, b.seg.event);
|
|
1119
1493
|
} : void 0,
|
|
1120
1494
|
onClick: (e) => {
|
|
1121
1495
|
e.stopPropagation();
|
|
1122
|
-
if (consumeSuppressedClick()) return;
|
|
1496
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1123
1497
|
onPressEvent?.(b.seg.event);
|
|
1124
1498
|
},
|
|
1125
1499
|
...barChipButton,
|
|
1126
1500
|
title: b.seg.event.title,
|
|
1127
1501
|
"aria-label": eventAccessibilityLabel ? eventAccessibilityLabel(b.seg.event, {
|
|
1128
|
-
mode:
|
|
1502
|
+
mode: viewMode,
|
|
1129
1503
|
isAllDay: (0, _super_calendar_core.isAllDayEvent)(b.seg.event),
|
|
1130
1504
|
ampm: false
|
|
1131
1505
|
}) : `${b.seg.event.title}, ${dayLabel}`,
|
|
@@ -1136,13 +1510,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1136
1510
|
width: `calc(${span * 100}% - 4px)`,
|
|
1137
1511
|
top: 28 + chipGap + b.seg.lane * (chipHeight + chipGap),
|
|
1138
1512
|
height: chipHeight,
|
|
1139
|
-
pointerEvents:
|
|
1513
|
+
pointerEvents: dragArmed ? "none" : "auto",
|
|
1140
1514
|
opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
|
|
1141
1515
|
cursor: canMove(b.seg.event) ? "grab" : void 0,
|
|
1142
|
-
touchAction: dragWired ? "none" : void 0,
|
|
1516
|
+
touchAction: dragWired ? multiWeek ? "pan-y" : "none" : void 0,
|
|
1143
1517
|
zIndex: 2
|
|
1144
1518
|
},
|
|
1145
1519
|
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
1520
|
+
mode: viewMode,
|
|
1146
1521
|
event: b.seg.event,
|
|
1147
1522
|
onPress: () => onPressEvent?.(b.seg.event)
|
|
1148
1523
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -1162,6 +1537,34 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1162
1537
|
})
|
|
1163
1538
|
}, `bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`);
|
|
1164
1539
|
}),
|
|
1540
|
+
RenderCreateGhost && createRange && draftStart === dayCol && draftEnd !== void 0 && draftHeight > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InertDiv, {
|
|
1541
|
+
...slot("createGhost", {
|
|
1542
|
+
base: {
|
|
1543
|
+
position: "absolute",
|
|
1544
|
+
left: 2,
|
|
1545
|
+
width: `calc(${(draftEnd - draftStart + 1) * 100}% - 4px)`,
|
|
1546
|
+
top: draftTop,
|
|
1547
|
+
height: draftHeight,
|
|
1548
|
+
boxSizing: "border-box",
|
|
1549
|
+
pointerEvents: "none",
|
|
1550
|
+
overflow: "hidden",
|
|
1551
|
+
zIndex: 3
|
|
1552
|
+
},
|
|
1553
|
+
themed: {
|
|
1554
|
+
background: theme.rangeBackground,
|
|
1555
|
+
border: `1px solid ${theme.selectedBackground}`,
|
|
1556
|
+
borderRadius: 4,
|
|
1557
|
+
fontSize: 12,
|
|
1558
|
+
color: theme.text
|
|
1559
|
+
}
|
|
1560
|
+
}),
|
|
1561
|
+
inert: true,
|
|
1562
|
+
"aria-hidden": "true",
|
|
1563
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderCreateGhost, {
|
|
1564
|
+
start: createRange.start,
|
|
1565
|
+
end: createRange.end
|
|
1566
|
+
})
|
|
1567
|
+
}) : null,
|
|
1165
1568
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1166
1569
|
...slot("events", { base: {
|
|
1167
1570
|
display: "flex",
|
|
@@ -1184,7 +1587,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1184
1587
|
setMoreOpenFor((open) => open === day.id ? null : day.id);
|
|
1185
1588
|
}
|
|
1186
1589
|
},
|
|
1187
|
-
...slot("more", moreButtonDefault(theme, chipHeight)),
|
|
1590
|
+
...slot("more", moreButtonDefault(theme, chipHeight, multiWeek)),
|
|
1188
1591
|
"aria-label": `${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`,
|
|
1189
1592
|
"aria-expanded": onPressMore ? void 0 : moreOpenFor === day.id,
|
|
1190
1593
|
children: moreLabel.replace("{moreCount}", String(hiddenEvents.length))
|
|
@@ -1253,6 +1656,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1253
1656
|
cursor: "pointer"
|
|
1254
1657
|
},
|
|
1255
1658
|
children: Chip ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chip, {
|
|
1659
|
+
mode: viewMode,
|
|
1256
1660
|
event,
|
|
1257
1661
|
onPress: () => onPressEvent?.(event)
|
|
1258
1662
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -1302,6 +1706,33 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1302
1706
|
]
|
|
1303
1707
|
});
|
|
1304
1708
|
}
|
|
1709
|
+
// src/MultiWeekView.tsx
|
|
1710
|
+
/**
|
|
1711
|
+
* Consecutive full weeks as stacked seven-day rows, with event chips and no hour
|
|
1712
|
+
* slots. It has the month grid's event bars, overflow, selection, and drag
|
|
1713
|
+
* interactions, and the month slots, `renderEvent`, and theme style it. Every
|
|
1714
|
+
* row is kept at full height; when the view is given less room, the rows scroll
|
|
1715
|
+
* under the title and weekday header.
|
|
1716
|
+
*
|
|
1717
|
+
* Standalone, it shows `events` as given; expand recurring events first with
|
|
1718
|
+
* `expandRecurringEvents`, or use `Calendar` with `mode="multiweek"`.
|
|
1719
|
+
*
|
|
1720
|
+
* @example
|
|
1721
|
+
* ```tsx
|
|
1722
|
+
* <MultiWeekView date={new Date()} numberOfWeeks={3} events={events} />
|
|
1723
|
+
* ```
|
|
1724
|
+
*/
|
|
1725
|
+
function MultiWeekView({ date, numberOfWeeks = 2, chipHeight = 24, ...rest }) {
|
|
1726
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateRows, {
|
|
1727
|
+
...rest,
|
|
1728
|
+
chipHeight,
|
|
1729
|
+
source: {
|
|
1730
|
+
kind: "multiweek",
|
|
1731
|
+
date,
|
|
1732
|
+
numberOfWeeks
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1305
1736
|
// src/EventActions.tsx
|
|
1306
1737
|
function moveFocus(event, container) {
|
|
1307
1738
|
const buttons = [...container?.querySelectorAll("button") ?? []];
|
|
@@ -1661,57 +2092,13 @@ function EventActionsDialog({ dialogRef, title, description, actions, closeLabel
|
|
|
1661
2092
|
})
|
|
1662
2093
|
});
|
|
1663
2094
|
}
|
|
1664
|
-
// src/InertDiv.ts
|
|
1665
|
-
function InertDiv(props) {
|
|
1666
|
-
return (0, react.createElement)("div", {
|
|
1667
|
-
...props,
|
|
1668
|
-
inert: props.inert ? "inert" : void 0
|
|
1669
|
-
});
|
|
1670
|
-
}
|
|
1671
|
-
// src/touch.ts
|
|
1672
|
-
function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
|
|
1673
|
-
const detach = () => {
|
|
1674
|
-
clearTimeout(timer);
|
|
1675
|
-
document.removeEventListener("pointermove", move);
|
|
1676
|
-
document.removeEventListener("pointerup", up);
|
|
1677
|
-
document.removeEventListener("pointercancel", cancelPointer);
|
|
1678
|
-
document.removeEventListener("pointerdown", anotherPointer);
|
|
1679
|
-
};
|
|
1680
|
-
const cancel = () => {
|
|
1681
|
-
detach();
|
|
1682
|
-
onCancel();
|
|
1683
|
-
};
|
|
1684
|
-
const move = (event) => {
|
|
1685
|
-
if (event.pointerId === grab.pointerId && Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold) cancel();
|
|
1686
|
-
};
|
|
1687
|
-
const up = (event) => {
|
|
1688
|
-
if (event.pointerId === grab.pointerId) {
|
|
1689
|
-
detach();
|
|
1690
|
-
onTap();
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1693
|
-
const cancelPointer = (event) => {
|
|
1694
|
-
if (event.pointerId === grab.pointerId) cancel();
|
|
1695
|
-
};
|
|
1696
|
-
const anotherPointer = (event) => {
|
|
1697
|
-
if (event.pointerId !== grab.pointerId) cancel();
|
|
1698
|
-
};
|
|
1699
|
-
const timer = setTimeout(() => {
|
|
1700
|
-
detach();
|
|
1701
|
-
onHold();
|
|
1702
|
-
}, delay);
|
|
1703
|
-
document.addEventListener("pointermove", move);
|
|
1704
|
-
document.addEventListener("pointerup", up);
|
|
1705
|
-
document.addEventListener("pointercancel", cancelPointer);
|
|
1706
|
-
document.addEventListener("pointerdown", anotherPointer);
|
|
1707
|
-
return cancel;
|
|
1708
|
-
}
|
|
1709
2095
|
// src/TimeGrid.tsx
|
|
1710
2096
|
const GUTTER_WIDTH$1 = 56;
|
|
1711
2097
|
const HOURS_PER_DAY = 24;
|
|
1712
2098
|
const DEFAULT_MIN_EVENT_HEIGHT = 14;
|
|
1713
2099
|
const DEFAULT_EVENT_GAP = 1;
|
|
1714
2100
|
const clamp$1 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
2101
|
+
const useClientLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
1715
2102
|
const CREATE_PREVIEW_MIN_HEIGHT = 2;
|
|
1716
2103
|
function createPreviewPlacement(topPx, heightPx, gridHeight) {
|
|
1717
2104
|
const start = clamp$1(topPx, 0, gridHeight);
|
|
@@ -1726,6 +2113,11 @@ function createPreviewPlacement(topPx, heightPx, gridHeight) {
|
|
|
1726
2113
|
height
|
|
1727
2114
|
};
|
|
1728
2115
|
}
|
|
2116
|
+
function createRangePlacement(range, day, hourHeight, minHour, gridHeight, minEventHeight) {
|
|
2117
|
+
const at = (time) => ((0, date_fns.differenceInCalendarDays)(time, day) * 24 + time.getHours() + time.getMinutes() / 60 - minHour) * hourHeight;
|
|
2118
|
+
const top = at(range.start);
|
|
2119
|
+
return createPreviewPlacement(top, Math.max(minEventHeight, at(range.end) - top), gridHeight);
|
|
2120
|
+
}
|
|
1729
2121
|
const EDGE_ZONE = 32;
|
|
1730
2122
|
const EDGE_DWELL_MS = 600;
|
|
1731
2123
|
const EDGE_REPEAT_MS = 600;
|
|
@@ -1749,6 +2141,20 @@ function movedSegmentStart(origin, base, startHours) {
|
|
|
1749
2141
|
const dayMinutes = (0, date_fns.differenceInCalendarDays)(base, origin.base) * HOURS_PER_DAY * 60;
|
|
1750
2142
|
return (0, _super_calendar_core.shiftMinutes)(origin.segmentStart, dayMinutes + Math.round((startHours - origin.startHours) * 60));
|
|
1751
2143
|
}
|
|
2144
|
+
function draggedEventBounds(d, origin, event, base, snapMinutes) {
|
|
2145
|
+
if (d.kind === "resize") {
|
|
2146
|
+
const endDelta = Math.round((d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60);
|
|
2147
|
+
return (0, _super_calendar_core.resolveDraggedBounds)(event.start, event.end, 0, endDelta, snapMinutes);
|
|
2148
|
+
}
|
|
2149
|
+
const startShift = movedSegmentStart(origin, base, d.kind === "move" ? d.requestedStartHours : d.startHours).getTime() - origin.segmentStart.getTime();
|
|
2150
|
+
const endShift = d.kind === "move" ? startShift : 0;
|
|
2151
|
+
const start = new Date(event.start.getTime() + startShift);
|
|
2152
|
+
const end = new Date(event.end.getTime() + endShift);
|
|
2153
|
+
return end > start || d.kind === "move" && end.getTime() === start.getTime() ? {
|
|
2154
|
+
start,
|
|
2155
|
+
end
|
|
2156
|
+
} : null;
|
|
2157
|
+
}
|
|
1752
2158
|
function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme, boxProps }) {
|
|
1753
2159
|
const timeLabel = (0, _super_calendar_core.eventTimeLabel)({
|
|
1754
2160
|
mode,
|
|
@@ -1850,6 +2256,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1850
2256
|
now: nowProp,
|
|
1851
2257
|
timeZone
|
|
1852
2258
|
});
|
|
2259
|
+
const todayDate = showNowIndicator ? now : (0, _super_calendar_core.nowInTimeZone)(nowProp, timeZone);
|
|
1853
2260
|
const [hourHeight, setHourHeight] = (0, react.useState)(initialHourHeight);
|
|
1854
2261
|
(0, react.useEffect)(() => setHourHeight(initialHourHeight), [initialHourHeight]);
|
|
1855
2262
|
const hourHeightRef = (0, react.useRef)(hourHeight);
|
|
@@ -1864,6 +2271,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1864
2271
|
const [createBox, setCreateBox] = (0, react.useState)(null);
|
|
1865
2272
|
const createOrigin = (0, react.useRef)(null);
|
|
1866
2273
|
const createActive = createBox !== null;
|
|
2274
|
+
const detachCreateListeners = (0, react.useRef)(null);
|
|
2275
|
+
const createRelease = (0, react.useRef)(null);
|
|
1867
2276
|
(0, react.useEffect)(() => {
|
|
1868
2277
|
if (!createActive) return;
|
|
1869
2278
|
const onScroll = () => {
|
|
@@ -1929,6 +2338,11 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1929
2338
|
canResize: editable && (event.durationEditable ?? eventDurationEditable)
|
|
1930
2339
|
};
|
|
1931
2340
|
};
|
|
2341
|
+
const hasEditActions = (event) => {
|
|
2342
|
+
if ((0, _super_calendar_core.isAllDayEvent)(event) || (0, _super_calendar_core.isBackgroundEvent)(event)) return false;
|
|
2343
|
+
const { canMove, canResize } = editability(event);
|
|
2344
|
+
return canMove || canResize;
|
|
2345
|
+
};
|
|
1932
2346
|
const eventLabel = (event) => eventAccessibilityLabel ? eventAccessibilityLabel(event, {
|
|
1933
2347
|
mode,
|
|
1934
2348
|
isAllDay: false,
|
|
@@ -1956,7 +2370,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1956
2370
|
}
|
|
1957
2371
|
};
|
|
1958
2372
|
const editActions = (event) => {
|
|
1959
|
-
if ((
|
|
2373
|
+
if (!hasEditActions(event)) return [];
|
|
1960
2374
|
const { canMove, canResize } = editability(event);
|
|
1961
2375
|
const action = (id, label) => {
|
|
1962
2376
|
const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
|
|
@@ -1978,12 +2392,36 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
1978
2392
|
if (!next || onDragEventRef.current?.(event, next.start, next.end) === false) return null;
|
|
1979
2393
|
return (candidate) => candidate !== event && candidate.start.getTime() === next.start.getTime() && candidate.end.getTime() === next.end.getTime() && candidate.title === event.title;
|
|
1980
2394
|
}, getEventId);
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2395
|
+
const allDayLayout = (0, react.useMemo)(() => (0, _super_calendar_core.layoutMonthWeek)(days, events.filter((event) => (0, _super_calendar_core.isAllDayEvent)(event) && !(0, _super_calendar_core.isBackgroundEvent)(event) && days.some((day) => event.start < (0, date_fns.addDays)((0, date_fns.startOfDay)(day), 1) && event.end > (0, date_fns.startOfDay)(day)))), [days, events]);
|
|
2396
|
+
const hasAllDay = allDayLayout.segments.length > 0;
|
|
2397
|
+
const allDayIds = (0, react.useMemo)(() => {
|
|
2398
|
+
const keys = /* @__PURE__ */ new Map();
|
|
2399
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2400
|
+
for (const { event } of allDayLayout.segments) {
|
|
2401
|
+
const id = getEventId?.(event);
|
|
2402
|
+
if (typeof id !== "string" && typeof id !== "number") continue;
|
|
2403
|
+
const key = `${typeof id}:${id}`;
|
|
2404
|
+
const previous = seen.get(key);
|
|
2405
|
+
if (previous) keys.delete(previous);
|
|
2406
|
+
else {
|
|
2407
|
+
seen.set(key, event);
|
|
2408
|
+
keys.set(event, key);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
return keys;
|
|
2412
|
+
}, [allDayLayout, getEventId]);
|
|
2413
|
+
const allDayKeys = (0, react.useRef)(/* @__PURE__ */ new WeakMap());
|
|
2414
|
+
const nextAllDayKey = (0, react.useRef)(0);
|
|
2415
|
+
const allDayKey = (event) => {
|
|
2416
|
+
const id = allDayIds.get(event);
|
|
2417
|
+
if (id !== void 0) return id;
|
|
2418
|
+
let key = allDayKeys.current.get(event);
|
|
2419
|
+
if (key === void 0) {
|
|
2420
|
+
key = nextAllDayKey.current++;
|
|
2421
|
+
allDayKeys.current.set(event, key);
|
|
2422
|
+
}
|
|
2423
|
+
return `object:${key}`;
|
|
2424
|
+
};
|
|
1987
2425
|
(0, react.useEffect)(() => {
|
|
1988
2426
|
if (scrollRef.current) scrollRef.current.scrollTop = Math.max(0, (scrollOffsetMinutes / 60 - windowStart) * hourHeightRef.current);
|
|
1989
2427
|
}, [scrollOffsetMinutes, windowStart]);
|
|
@@ -2083,6 +2521,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2083
2521
|
document.removeEventListener("pointermove", h.move);
|
|
2084
2522
|
document.removeEventListener("pointerup", h.up);
|
|
2085
2523
|
document.removeEventListener("pointercancel", h.cancel);
|
|
2524
|
+
document.removeEventListener("selectstart", h.preventNative, true);
|
|
2525
|
+
document.removeEventListener("dragstart", h.preventNative, true);
|
|
2086
2526
|
docHandlersRef.current = null;
|
|
2087
2527
|
};
|
|
2088
2528
|
const finishDrag = () => {
|
|
@@ -2190,18 +2630,14 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2190
2630
|
base = day ? (0, date_fns.startOfDay)(day) : null;
|
|
2191
2631
|
} else base = (0, date_fns.startOfDay)(daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex]);
|
|
2192
2632
|
} else base = (0, date_fns.startOfDay)(daysRef.current[originIndex] ?? daysRef.current[0]);
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
const start = new Date(held.event.start.getTime() + startShift);
|
|
2201
|
-
const end = new Date(held.event.end.getTime() + endShift);
|
|
2202
|
-
if (end > start) onDragEventRef.current?.(held.event, start, end);
|
|
2633
|
+
try {
|
|
2634
|
+
if (base && held && origin) {
|
|
2635
|
+
const next = draggedEventBounds(d, origin, held.event, base, snapMinutes);
|
|
2636
|
+
if (next) onDragEventRef.current?.(held.event, next.start, next.end);
|
|
2637
|
+
}
|
|
2638
|
+
} finally {
|
|
2639
|
+
finishDrag();
|
|
2203
2640
|
}
|
|
2204
|
-
finishDrag();
|
|
2205
2641
|
};
|
|
2206
2642
|
const cancelDrag = () => {
|
|
2207
2643
|
finishDrag();
|
|
@@ -2215,7 +2651,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2215
2651
|
activeGrabRef.current = e;
|
|
2216
2652
|
const boxEl = e.box;
|
|
2217
2653
|
const column = kind === "move" ? boxEl.parentElement : null;
|
|
2218
|
-
const
|
|
2654
|
+
const columnRect = column ? column.getBoundingClientRect() : null;
|
|
2655
|
+
const dayWidth = columnRect ? columnRect.width : 0;
|
|
2219
2656
|
const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
|
|
2220
2657
|
const originBase = (0, date_fns.startOfDay)(days[dayIndex] ?? days[0]);
|
|
2221
2658
|
const originNextDay = (0, date_fns.addDays)(originBase, 1);
|
|
@@ -2235,9 +2672,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2235
2672
|
draggedRef.current = {
|
|
2236
2673
|
event,
|
|
2237
2674
|
onPress: onPress ?? (() => {}),
|
|
2238
|
-
grabX:
|
|
2675
|
+
grabX: column && columnRect ? e.clientX - columnRect.left - column.clientLeft - eventGap : 0,
|
|
2239
2676
|
grabY: boxRect ? e.clientY - boxRect.top : 0,
|
|
2240
|
-
w:
|
|
2677
|
+
w: column ? Math.max(column.clientWidth - eventGap * 2, 0) : 0,
|
|
2241
2678
|
h: boxRect ? boxRect.height : 0
|
|
2242
2679
|
};
|
|
2243
2680
|
ptr.current = {
|
|
@@ -2273,12 +2710,15 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2273
2710
|
},
|
|
2274
2711
|
cancel: (event) => {
|
|
2275
2712
|
if (event.pointerId === e.pointerId) cancelDrag();
|
|
2276
|
-
}
|
|
2713
|
+
},
|
|
2714
|
+
preventNative: (event) => event.preventDefault()
|
|
2277
2715
|
};
|
|
2278
2716
|
docHandlersRef.current = handlers;
|
|
2279
2717
|
document.addEventListener("pointermove", handlers.move);
|
|
2280
2718
|
document.addEventListener("pointerup", handlers.up);
|
|
2281
2719
|
document.addEventListener("pointercancel", handlers.cancel);
|
|
2720
|
+
document.addEventListener("selectstart", handlers.preventNative, true);
|
|
2721
|
+
document.addEventListener("dragstart", handlers.preventNative, true);
|
|
2282
2722
|
};
|
|
2283
2723
|
const pressEvent = (e, pe, key, kind, dayIndex, onPress) => {
|
|
2284
2724
|
if (!onDragEvent || e.button > 0) return;
|
|
@@ -2312,6 +2752,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2312
2752
|
cancelHoldRef.current?.();
|
|
2313
2753
|
detachDocListeners();
|
|
2314
2754
|
clearEdgeTimer();
|
|
2755
|
+
if (createOrigin.current?.captureLoss !== void 0) clearTimeout(createOrigin.current.captureLoss);
|
|
2756
|
+
createOrigin.current = null;
|
|
2757
|
+
detachCreateListeners.current?.();
|
|
2758
|
+
detachCreateListeners.current = null;
|
|
2315
2759
|
}, []);
|
|
2316
2760
|
(0, react.useEffect)(() => {
|
|
2317
2761
|
cancelHoldRef.current?.();
|
|
@@ -2322,6 +2766,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2322
2766
|
]);
|
|
2323
2767
|
const pxFromTop = (el, clientY) => clientY - el.getBoundingClientRect().top;
|
|
2324
2768
|
const beginCreate = (e, dayIndex) => {
|
|
2769
|
+
if (createOrigin.current || activeGrabRef.current || e.isPrimary === false) return;
|
|
2325
2770
|
cellTouchRef.current = e.pointerType === "touch" && e.target === e.currentTarget ? {
|
|
2326
2771
|
pointerId: e.pointerId,
|
|
2327
2772
|
x: e.clientX,
|
|
@@ -2350,12 +2795,33 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2350
2795
|
startPx,
|
|
2351
2796
|
curPx: startPx
|
|
2352
2797
|
});
|
|
2798
|
+
const document = el.ownerDocument;
|
|
2799
|
+
const release = (event) => createRelease.current?.(event);
|
|
2800
|
+
const cancel = (event) => {
|
|
2801
|
+
if (createOrigin.current?.pointerId === event.pointerId) clearCreate();
|
|
2802
|
+
};
|
|
2803
|
+
const restart = (event) => {
|
|
2804
|
+
if (event.isPrimary && event.pointerType !== "touch" || createOrigin.current?.pointerId === event.pointerId) clearCreate();
|
|
2805
|
+
};
|
|
2806
|
+
const preventSelection = (event) => event.preventDefault();
|
|
2807
|
+
document.addEventListener("pointerup", release, true);
|
|
2808
|
+
document.addEventListener("pointercancel", cancel, true);
|
|
2809
|
+
document.addEventListener("pointerdown", restart, true);
|
|
2810
|
+
document.addEventListener("selectstart", preventSelection, true);
|
|
2811
|
+
document.addEventListener("dragstart", preventSelection, true);
|
|
2812
|
+
detachCreateListeners.current = () => {
|
|
2813
|
+
document.removeEventListener("pointerup", release, true);
|
|
2814
|
+
document.removeEventListener("pointercancel", cancel, true);
|
|
2815
|
+
document.removeEventListener("pointerdown", restart, true);
|
|
2816
|
+
document.removeEventListener("selectstart", preventSelection, true);
|
|
2817
|
+
document.removeEventListener("dragstart", preventSelection, true);
|
|
2818
|
+
};
|
|
2353
2819
|
};
|
|
2354
2820
|
const moveCreate = (e) => {
|
|
2355
2821
|
const touch = cellTouchRef.current;
|
|
2356
2822
|
if (touch && e.pointerId === touch.pointerId && Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX) cellTouchRef.current = null;
|
|
2357
2823
|
const o = createOrigin.current;
|
|
2358
|
-
if (!o) return;
|
|
2824
|
+
if (!o || o.pointerId !== e.pointerId) return;
|
|
2359
2825
|
o.clientY = e.clientY;
|
|
2360
2826
|
setCreateBox({
|
|
2361
2827
|
dayIndex: o.dayIndex,
|
|
@@ -2366,10 +2832,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2366
2832
|
};
|
|
2367
2833
|
const endCreate = (e) => {
|
|
2368
2834
|
const o = createOrigin.current;
|
|
2369
|
-
if (!o) return;
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
} catch {}
|
|
2835
|
+
if (!o || o.pointerId !== e.pointerId) return;
|
|
2836
|
+
clearCreate();
|
|
2837
|
+
if (!o.el.isConnected || !cellEnabled || o.creating && !onCreateEvent || days[o.dayIndex]?.getTime() !== o.dayTime) return;
|
|
2373
2838
|
const endPx = pxFromTop(o.el, e.clientY);
|
|
2374
2839
|
const day = days[o.dayIndex];
|
|
2375
2840
|
const moved = Math.abs(endPx - o.startPx) > 4;
|
|
@@ -2381,9 +2846,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2381
2846
|
const at = (0, _super_calendar_core.cellRangeFromDrag)(day, o.startPx, o.startPx, h, windowStart, snapMinutes);
|
|
2382
2847
|
if (at) onPressCell(at.start);
|
|
2383
2848
|
}
|
|
2384
|
-
createOrigin.current = null;
|
|
2385
|
-
setCreateBox(null);
|
|
2386
2849
|
};
|
|
2850
|
+
useClientLayoutEffect(() => {
|
|
2851
|
+
createRelease.current = endCreate;
|
|
2852
|
+
});
|
|
2387
2853
|
const tapCell = (e, dayIndex) => {
|
|
2388
2854
|
const touch = cellTouchRef.current;
|
|
2389
2855
|
cellTouchRef.current = null;
|
|
@@ -2396,18 +2862,26 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2396
2862
|
const clearCreate = (0, react.useCallback)(() => {
|
|
2397
2863
|
const previous = createOrigin.current;
|
|
2398
2864
|
createOrigin.current = null;
|
|
2865
|
+
if (previous?.captureLoss !== void 0) clearTimeout(previous.captureLoss);
|
|
2866
|
+
detachCreateListeners.current?.();
|
|
2867
|
+
detachCreateListeners.current = null;
|
|
2399
2868
|
setCreateBox(null);
|
|
2400
2869
|
try {
|
|
2401
2870
|
previous?.el.releasePointerCapture?.(previous.pointerId);
|
|
2402
2871
|
} catch {}
|
|
2403
2872
|
}, []);
|
|
2404
|
-
const cancelCreate = () => {
|
|
2405
|
-
cellTouchRef.current = null;
|
|
2873
|
+
const cancelCreate = (e) => {
|
|
2874
|
+
if (cellTouchRef.current?.pointerId === e.pointerId) cellTouchRef.current = null;
|
|
2875
|
+
if (createOrigin.current?.pointerId !== e.pointerId) return;
|
|
2406
2876
|
clearCreate();
|
|
2407
2877
|
};
|
|
2408
2878
|
const loseCreateCapture = (e) => {
|
|
2409
|
-
|
|
2410
|
-
|
|
2879
|
+
const origin = createOrigin.current;
|
|
2880
|
+
if (!origin || origin.pointerId !== e.pointerId) return;
|
|
2881
|
+
if (origin.captureLoss !== void 0) clearTimeout(origin.captureLoss);
|
|
2882
|
+
origin.captureLoss = setTimeout(() => {
|
|
2883
|
+
if (createOrigin.current === origin) clearCreate();
|
|
2884
|
+
}, 0);
|
|
2411
2885
|
};
|
|
2412
2886
|
(0, react.useEffect)(() => {
|
|
2413
2887
|
const onKeyDown = (event) => {
|
|
@@ -2419,7 +2893,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2419
2893
|
document.addEventListener("keydown", onKeyDown);
|
|
2420
2894
|
return () => document.removeEventListener("keydown", onKeyDown);
|
|
2421
2895
|
}, [clearCreate]);
|
|
2422
|
-
const liveRange = createBox &&
|
|
2896
|
+
const liveRange = createBox && onCreateEvent && days[createBox.dayIndex]?.getTime() === createBox.dayTime ? (0, _super_calendar_core.cellRangeFromDrag)(days[createBox.dayIndex], createBox.startPx, createBox.curPx, hourHeight, windowStart, snapMinutes) : null;
|
|
2423
2897
|
const liveStart = liveRange?.start.getTime();
|
|
2424
2898
|
const liveEnd = liveRange?.end.getTime();
|
|
2425
2899
|
const createRange = (0, react.useMemo)(() => liveStart === void 0 || liveEnd === void 0 ? null : {
|
|
@@ -2434,7 +2908,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2434
2908
|
const moveOrigin = dragOrigin.current;
|
|
2435
2909
|
const heldEvent = draggedRef.current?.event;
|
|
2436
2910
|
const movingEvent = heldEvent && (events.includes(heldEvent) ? heldEvent : events.find((event) => event.start.getTime() === heldEvent.start.getTime() && event.end.getTime() === heldEvent.end.getTime() && event.title === heldEvent.title) ?? heldEvent);
|
|
2437
|
-
const
|
|
2911
|
+
const multiDayHeld = !paged && drag?.kind === "move" && (drag.continuesBefore || drag.continuesAfter) && !!movingEvent;
|
|
2912
|
+
const multiDayMove = !paged && drag?.kind === "move" && drag.moved && (drag.continuesBefore || drag.continuesAfter) && moveOrigin && movingEvent ? (() => {
|
|
2438
2913
|
const target = days[moveOrigin.dayIndex + drag.dayDelta];
|
|
2439
2914
|
const shift = movedSegmentStart(moveOrigin, (0, date_fns.startOfDay)(target), drag.requestedStartHours).getTime() - moveOrigin.segmentStart.getTime();
|
|
2440
2915
|
return {
|
|
@@ -2444,12 +2919,18 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2444
2919
|
allDay: false
|
|
2445
2920
|
};
|
|
2446
2921
|
})() : null;
|
|
2922
|
+
const liveBounds = !paged && drag?.moved && !multiDayMove && moveOrigin && draggedRef.current ? draggedEventBounds(drag, moveOrigin, draggedRef.current.event, (0, date_fns.startOfDay)(days[moveOrigin.dayIndex + (drag.kind === "move" ? drag.dayDelta : 0)] ?? days[moveOrigin.dayIndex]), snapMinutes) : null;
|
|
2923
|
+
const withLiveBounds = (event) => liveBounds ? {
|
|
2924
|
+
...event,
|
|
2925
|
+
start: liveBounds.start,
|
|
2926
|
+
end: liveBounds.end
|
|
2927
|
+
} : event;
|
|
2447
2928
|
const spillPreviewFor = (dayIndex) => {
|
|
2448
2929
|
if (paged || !drag || drag.kind !== "move" || drag.spillDayIndex !== dayIndex) return null;
|
|
2449
2930
|
const dragged = draggedRef.current?.event;
|
|
2450
2931
|
if (!dragged) return null;
|
|
2451
2932
|
return {
|
|
2452
|
-
event: dragged,
|
|
2933
|
+
event: withLiveBounds(dragged),
|
|
2453
2934
|
mode,
|
|
2454
2935
|
isAllDay: false,
|
|
2455
2936
|
boxHeight: Math.max(drag.spillHours * hourHeight, minEventHeight),
|
|
@@ -2570,7 +3051,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2570
3051
|
},
|
|
2571
3052
|
children: [
|
|
2572
3053
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(EventActionsMenu, {
|
|
2573
|
-
events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter(
|
|
3054
|
+
events: [...new Set(positionedByDay.flat().filter((pe) => pe.startHours < windowEnd && pe.startHours + pe.durationHours > windowStart).map((pe) => pe.event))].filter(hasEditActions),
|
|
2574
3055
|
label: labels.editEvents,
|
|
2575
3056
|
labelFor: (event) => labels.eventActions(event.title ?? ""),
|
|
2576
3057
|
descriptionFor: eventDescription,
|
|
@@ -2601,7 +3082,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2601
3082
|
}),
|
|
2602
3083
|
children: showWeekNumber && gutterWidth > 0 && days[0] ? `${weekNumberPrefix}${(0, date_fns.getISOWeek)(days.find((d) => d.getDay() === 4) ?? days[0])}` : null
|
|
2603
3084
|
}), days.map((day) => {
|
|
2604
|
-
const today = (0, _super_calendar_core.getIsToday)(day);
|
|
3085
|
+
const today = (0, _super_calendar_core.getIsToday)(day, todayDate);
|
|
2605
3086
|
const dateLabel = (0, date_fns.format)(day, "EEEE, d MMMM yyyy", dfns);
|
|
2606
3087
|
const headerProps = slot("columnHeader", {
|
|
2607
3088
|
base: {
|
|
@@ -2678,6 +3159,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2678
3159
|
base: {
|
|
2679
3160
|
width: gutterWidth,
|
|
2680
3161
|
flex: "none",
|
|
3162
|
+
boxSizing: "border-box",
|
|
2681
3163
|
minWidth: 0,
|
|
2682
3164
|
overflow: "hidden",
|
|
2683
3165
|
textAlign: "right"
|
|
@@ -2685,34 +3167,41 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2685
3167
|
themed: {
|
|
2686
3168
|
fontSize: 10,
|
|
2687
3169
|
color: theme.textMuted,
|
|
2688
|
-
padding: "4px 6px 0 0"
|
|
3170
|
+
padding: hideHours ? 0 : "4px 6px 0 0"
|
|
2689
3171
|
}
|
|
2690
3172
|
}),
|
|
2691
3173
|
children: showAllDayLabel ? labels.allDay : null
|
|
2692
|
-
}),
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
3174
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3175
|
+
style: {
|
|
3176
|
+
flex: 1,
|
|
3177
|
+
minWidth: 0,
|
|
3178
|
+
display: "grid",
|
|
3179
|
+
gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
|
|
3180
|
+
gap: "2px 0",
|
|
3181
|
+
padding: "2px 0"
|
|
3182
|
+
},
|
|
3183
|
+
children: allDayLayout.segments.map((segment) => {
|
|
3184
|
+
const { event, startCol, endCol, lane, continuesBefore, continuesAfter } = segment;
|
|
3185
|
+
const args = {
|
|
3186
|
+
event,
|
|
3187
|
+
mode,
|
|
3188
|
+
isAllDay: true,
|
|
3189
|
+
continuesBefore,
|
|
3190
|
+
continuesAfter,
|
|
3191
|
+
ampm,
|
|
3192
|
+
onPress: () => onPressEvent?.(event)
|
|
3193
|
+
};
|
|
3194
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3195
|
+
...slot("allDayColumn", { base: {
|
|
3196
|
+
gridColumn: `${startCol + 1} / span ${endCol - startCol + 1}`,
|
|
3197
|
+
gridRow: lane + 1,
|
|
3198
|
+
minWidth: 0,
|
|
3199
|
+
borderLeft: "1px solid transparent",
|
|
3200
|
+
padding: "0 1px",
|
|
3201
|
+
display: "flex",
|
|
3202
|
+
flexDirection: "column"
|
|
3203
|
+
} }),
|
|
3204
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2716
3205
|
type: "button",
|
|
2717
3206
|
onClick: () => onPressEvent?.(event),
|
|
2718
3207
|
"aria-label": eventAccessibilityLabel ? eventAccessibilityLabel(event, {
|
|
@@ -2740,9 +3229,9 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2740
3229
|
theme,
|
|
2741
3230
|
boxProps: slot("eventBox")
|
|
2742
3231
|
})
|
|
2743
|
-
}
|
|
2744
|
-
})
|
|
2745
|
-
}
|
|
3232
|
+
})
|
|
3233
|
+
}, allDayKey(event));
|
|
3234
|
+
})
|
|
2746
3235
|
})]
|
|
2747
3236
|
}) : null,
|
|
2748
3237
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -2791,7 +3280,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2791
3280
|
const nowTop = (nowHours - windowStart) * hourHeight;
|
|
2792
3281
|
const bands = bandsByDay[dayIndex];
|
|
2793
3282
|
const ghost = createBox?.dayIndex === dayIndex && createBox.dayTime === day.getTime() ? createBox : null;
|
|
2794
|
-
const ghostRange = ghost ? createRange : null;
|
|
3283
|
+
const ghostRange = ghost && RenderCreateGhost ? createRange : null;
|
|
2795
3284
|
const spill = multiDayMove ? null : spillPreviewFor(dayIndex);
|
|
2796
3285
|
const moveSegment = multiDayMove ? (0, _super_calendar_core.layoutDayEvents)([multiDayMove], day)[0] : void 0;
|
|
2797
3286
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -2803,7 +3292,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2803
3292
|
onLostPointerCapture: cellEnabled ? loseCreateCapture : void 0,
|
|
2804
3293
|
onClick: cellEnabled ? (e) => tapCell(e, dayIndex) : void 0,
|
|
2805
3294
|
...dataState({
|
|
2806
|
-
"data-today": (0, _super_calendar_core.getIsToday)(day),
|
|
3295
|
+
"data-today": (0, _super_calendar_core.getIsToday)(day, todayDate),
|
|
2807
3296
|
"data-weekend": (0, _super_calendar_core.isWeekend)(day)
|
|
2808
3297
|
}),
|
|
2809
3298
|
...slot("dayColumn", {
|
|
@@ -2891,7 +3380,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2891
3380
|
}),
|
|
2892
3381
|
positioned.map((pe, idx) => {
|
|
2893
3382
|
const key = `${dayIndex}:${idx}`;
|
|
2894
|
-
const active = !paged && drag?.key === key && (!
|
|
3383
|
+
const active = !paged && drag?.key === key && (!multiDayHeld || pe.event === movingEvent) ? drag : null;
|
|
2895
3384
|
const hiddenForMove = !!multiDayMove && pe.event === movingEvent;
|
|
2896
3385
|
const startHours = active ? active.startHours : pe.startHours;
|
|
2897
3386
|
const durationHours = active ? active.durationHours : pe.durationHours;
|
|
@@ -2899,9 +3388,10 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2899
3388
|
const top = (startHours - windowStart) * hourHeight;
|
|
2900
3389
|
const boxHeight = Math.max(Math.min(durationHours, HOURS_PER_DAY - startHours) * hourHeight, minEventHeight);
|
|
2901
3390
|
const widthPct = 100 / pe.columns;
|
|
3391
|
+
const floating = active?.kind === "move" && active.moved;
|
|
2902
3392
|
const onPress = () => onPressEvent?.(pe.event);
|
|
2903
3393
|
const args = {
|
|
2904
|
-
event: pe.event,
|
|
3394
|
+
event: active ? withLiveBounds(pe.event) : pe.event,
|
|
2905
3395
|
mode,
|
|
2906
3396
|
isAllDay: false,
|
|
2907
3397
|
boxHeight,
|
|
@@ -2936,8 +3426,8 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
2936
3426
|
position: "absolute",
|
|
2937
3427
|
top,
|
|
2938
3428
|
height: boxHeight,
|
|
2939
|
-
left: `calc(${pe.column * widthPct}% + ${eventGap}px)`,
|
|
2940
|
-
width: `calc(${widthPct}% - ${eventGap * 2}px)`,
|
|
3429
|
+
left: floating ? eventGap : `calc(${pe.column * widthPct}% + ${eventGap}px)`,
|
|
3430
|
+
width: floating ? `calc(100% - ${eventGap * 2}px)` : `calc(${widthPct}% - ${eventGap * 2}px)`,
|
|
2941
3431
|
cursor: canMove ? "grab" : "pointer",
|
|
2942
3432
|
touchAction: canMove ? "pan-y" : "auto",
|
|
2943
3433
|
userSelect: canMove ? "none" : void 0,
|
|
@@ -3065,7 +3555,7 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
3065
3555
|
position: "absolute",
|
|
3066
3556
|
left: eventGap,
|
|
3067
3557
|
right: eventGap,
|
|
3068
|
-
...createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
|
|
3558
|
+
...createRange ? createRangePlacement(createRange, day, hourHeight, windowStart, totalHeight, minEventHeight) : createPreviewPlacement(Math.min(ghost.startPx, ghost.curPx), Math.abs(ghost.curPx - ghost.startPx), totalHeight),
|
|
3069
3559
|
boxSizing: "border-box",
|
|
3070
3560
|
...ghostRange ? { overflow: "hidden" } : null,
|
|
3071
3561
|
opacity: .7,
|
|
@@ -3138,16 +3628,24 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
3138
3628
|
}
|
|
3139
3629
|
// src/Calendar.tsx
|
|
3140
3630
|
const EMPTY_EVENTS = [];
|
|
3141
|
-
function expansionRange(mode, date, weekStartsOn, numberOfDays) {
|
|
3631
|
+
function expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
3632
|
+
if (mode === "multiweek") {
|
|
3633
|
+
const { period } = (0, _super_calendar_core.buildMultiWeekGrid)(date, {
|
|
3634
|
+
weekStartsOn,
|
|
3635
|
+
numberOfWeeks
|
|
3636
|
+
});
|
|
3637
|
+
return [period.start, (0, date_fns.endOfDay)((0, date_fns.addDays)(period.endExclusive, -1))];
|
|
3638
|
+
}
|
|
3142
3639
|
if (mode === "month") return [(0, date_fns.startOfWeek)((0, date_fns.startOfMonth)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfMonth)(date), { weekStartsOn })];
|
|
3143
3640
|
if (mode === "year") return [(0, date_fns.startOfWeek)((0, date_fns.startOfYear)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfYear)(date), { weekStartsOn })];
|
|
3144
3641
|
if (mode === "schedule") return [(0, date_fns.startOfDay)(date), (0, date_fns.endOfDay)((0, date_fns.addMonths)(date, 3))];
|
|
3145
3642
|
const days = (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1);
|
|
3146
3643
|
return [(0, date_fns.startOfDay)(days[0]), (0, date_fns.endOfDay)(days[days.length - 1])];
|
|
3147
3644
|
}
|
|
3148
|
-
function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
3645
|
+
function pageStep(mode, date, direction, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
3149
3646
|
if (mode === "year") return (0, date_fns.addYears)(date, direction);
|
|
3150
3647
|
if (mode === "month") return (0, date_fns.addMonths)(date, direction);
|
|
3648
|
+
if (mode === "multiweek") return (0, date_fns.addWeeks)(date, direction * numberOfWeeks);
|
|
3151
3649
|
if (mode === "schedule") return (0, date_fns.addDays)(date, direction * 7);
|
|
3152
3650
|
return (0, date_fns.addDays)(date, direction * (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1).length);
|
|
3153
3651
|
}
|
|
@@ -3163,18 +3661,14 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
|
3163
3661
|
* ```
|
|
3164
3662
|
*/
|
|
3165
3663
|
const Calendar = (0, react.forwardRef)(CalendarInner);
|
|
3166
|
-
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, 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) {
|
|
3664
|
+
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) {
|
|
3167
3665
|
const timeGridRef = (0, react.useRef)(null);
|
|
3168
3666
|
(0, react.useImperativeHandle)(ref, () => ({ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options) }), []);
|
|
3169
3667
|
const displayEvents = (0, react.useMemo)(() => {
|
|
3170
3668
|
let out = events ?? EMPTY_EVENTS;
|
|
3171
3669
|
if (out.some((e) => e.recurrence)) {
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
start = (0, date_fns.addDays)(start, -1);
|
|
3175
|
-
end = (0, date_fns.addDays)(end, 1);
|
|
3176
|
-
}
|
|
3177
|
-
out = (0, _super_calendar_core.expandRecurringEvents)(out, start, end);
|
|
3670
|
+
const [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
|
|
3671
|
+
out = timeZone ? (0, _super_calendar_core.expandRecurringEvents)(out, (0, _super_calendar_core.fromZonedTime)(start, timeZone), (0, _super_calendar_core.fromZonedTime)(end, timeZone), { timeZone }) : (0, _super_calendar_core.expandRecurringEvents)(out, start, end);
|
|
3178
3672
|
}
|
|
3179
3673
|
if (timeZone) out = (0, _super_calendar_core.eventsInTimeZone)(out, timeZone);
|
|
3180
3674
|
return out;
|
|
@@ -3184,12 +3678,49 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3184
3678
|
date.getTime(),
|
|
3185
3679
|
weekStartsOn,
|
|
3186
3680
|
numberOfDays,
|
|
3681
|
+
numberOfWeeks,
|
|
3187
3682
|
timeZone
|
|
3188
3683
|
]);
|
|
3684
|
+
const timeGridMode = mode !== "month" && mode !== "multiweek";
|
|
3685
|
+
const zoned = (0, react.useMemo)(() => {
|
|
3686
|
+
if (!timeZone) return {
|
|
3687
|
+
onPressEvent,
|
|
3688
|
+
onDragStart,
|
|
3689
|
+
onDragEvent,
|
|
3690
|
+
onPressMore,
|
|
3691
|
+
onPressTime: onPressCell,
|
|
3692
|
+
onCreateTimed: onCreateEvent
|
|
3693
|
+
};
|
|
3694
|
+
const instant = (wallClock) => (0, _super_calendar_core.fromZonedTime)(wallClock, timeZone);
|
|
3695
|
+
return {
|
|
3696
|
+
onPressEvent: onPressEvent && ((event) => onPressEvent((0, _super_calendar_core.zonedEventSource)(event))),
|
|
3697
|
+
onDragStart: onDragStart && ((event) => onDragStart((0, _super_calendar_core.zonedEventSource)(event))),
|
|
3698
|
+
onDragEvent: onDragEvent && ((event, start, end) => {
|
|
3699
|
+
const bounds = (0, _super_calendar_core.zonedDragBounds)(event, start, end, { keepDuration: timeGridMode });
|
|
3700
|
+
if (!bounds) return false;
|
|
3701
|
+
return onDragEvent((0, _super_calendar_core.zonedEventSource)(event), bounds.start, bounds.end);
|
|
3702
|
+
}),
|
|
3703
|
+
onPressMore: onPressMore && ((dayEvents, day) => onPressMore(dayEvents.map(_super_calendar_core.zonedEventSource), day)),
|
|
3704
|
+
onPressTime: onPressCell && ((time) => onPressCell(instant(time))),
|
|
3705
|
+
onCreateTimed: onCreateEvent && ((start, end) => {
|
|
3706
|
+
const range = (0, _super_calendar_core.fromZonedRange)(start, end, timeZone);
|
|
3707
|
+
if (range) onCreateEvent(range.start, range.end);
|
|
3708
|
+
})
|
|
3709
|
+
};
|
|
3710
|
+
}, [
|
|
3711
|
+
timeZone,
|
|
3712
|
+
timeGridMode,
|
|
3713
|
+
onPressEvent,
|
|
3714
|
+
onDragStart,
|
|
3715
|
+
onDragEvent,
|
|
3716
|
+
onPressMore,
|
|
3717
|
+
onPressCell,
|
|
3718
|
+
onCreateEvent
|
|
3719
|
+
]);
|
|
3189
3720
|
const handlePageKeys = (e) => {
|
|
3190
3721
|
if (!onChangeDate) return;
|
|
3191
|
-
if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays));
|
|
3192
|
-
else if (e.key === "PageUp") onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays));
|
|
3722
|
+
if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
3723
|
+
else if (e.key === "PageUp") onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
3193
3724
|
else return;
|
|
3194
3725
|
e.preventDefault();
|
|
3195
3726
|
};
|
|
@@ -3200,6 +3731,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3200
3731
|
weekStartsOn,
|
|
3201
3732
|
hiddenDays,
|
|
3202
3733
|
locale,
|
|
3734
|
+
now,
|
|
3735
|
+
timeZone,
|
|
3203
3736
|
labels,
|
|
3204
3737
|
theme,
|
|
3205
3738
|
className,
|
|
@@ -3222,6 +3755,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3222
3755
|
else if (mode === "schedule") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
|
|
3223
3756
|
events: displayEvents,
|
|
3224
3757
|
locale,
|
|
3758
|
+
now,
|
|
3759
|
+
timeZone,
|
|
3225
3760
|
ampm,
|
|
3226
3761
|
theme,
|
|
3227
3762
|
height,
|
|
@@ -3232,7 +3767,7 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3232
3767
|
styles,
|
|
3233
3768
|
renderEvent: renderScheduleEvent,
|
|
3234
3769
|
eventAccessibilityLabel,
|
|
3235
|
-
onPressEvent,
|
|
3770
|
+
onPressEvent: zoned.onPressEvent,
|
|
3236
3771
|
onPressDay
|
|
3237
3772
|
});
|
|
3238
3773
|
else if (mode === "month") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthView, {
|
|
@@ -3243,6 +3778,8 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3243
3778
|
weekdayFormat,
|
|
3244
3779
|
highlightWeekends,
|
|
3245
3780
|
locale,
|
|
3781
|
+
now,
|
|
3782
|
+
timeZone,
|
|
3246
3783
|
labels,
|
|
3247
3784
|
theme,
|
|
3248
3785
|
className,
|
|
@@ -3265,13 +3802,60 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3265
3802
|
onPressDay,
|
|
3266
3803
|
onPressCell,
|
|
3267
3804
|
onCreateEvent,
|
|
3805
|
+
renderCreateGhost,
|
|
3268
3806
|
onSelectDrag,
|
|
3269
|
-
onDragEvent,
|
|
3270
|
-
onDragStart,
|
|
3807
|
+
onDragEvent: zoned.onDragEvent,
|
|
3808
|
+
onDragStart: zoned.onDragStart,
|
|
3271
3809
|
eventStartEditable,
|
|
3272
3810
|
eventOverlap,
|
|
3273
|
-
onPressEvent,
|
|
3274
|
-
onPressMore,
|
|
3811
|
+
onPressEvent: zoned.onPressEvent,
|
|
3812
|
+
onPressMore: zoned.onPressMore,
|
|
3813
|
+
renderEvent: renderMonthEvent,
|
|
3814
|
+
eventAccessibilityLabel
|
|
3815
|
+
});
|
|
3816
|
+
else if (mode === "multiweek") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MultiWeekView, {
|
|
3817
|
+
date,
|
|
3818
|
+
numberOfWeeks,
|
|
3819
|
+
events: displayEvents,
|
|
3820
|
+
weekStartsOn,
|
|
3821
|
+
hiddenDays,
|
|
3822
|
+
weekdayFormat,
|
|
3823
|
+
highlightWeekends,
|
|
3824
|
+
locale,
|
|
3825
|
+
now,
|
|
3826
|
+
timeZone,
|
|
3827
|
+
labels,
|
|
3828
|
+
theme,
|
|
3829
|
+
className,
|
|
3830
|
+
style: height != null ? {
|
|
3831
|
+
height,
|
|
3832
|
+
...style
|
|
3833
|
+
} : style,
|
|
3834
|
+
classNames,
|
|
3835
|
+
styles,
|
|
3836
|
+
maxVisibleEventCount,
|
|
3837
|
+
chipHeight,
|
|
3838
|
+
chipGap,
|
|
3839
|
+
moreLabel,
|
|
3840
|
+
showTitle,
|
|
3841
|
+
fillCellOnSelection,
|
|
3842
|
+
selectedRange,
|
|
3843
|
+
selectedDates,
|
|
3844
|
+
minDate,
|
|
3845
|
+
maxDate,
|
|
3846
|
+
isDateDisabled,
|
|
3847
|
+
keyboardDayNavigation,
|
|
3848
|
+
onPressDay,
|
|
3849
|
+
onPressCell,
|
|
3850
|
+
onCreateEvent,
|
|
3851
|
+
renderCreateGhost,
|
|
3852
|
+
onSelectDrag,
|
|
3853
|
+
onDragEvent: zoned.onDragEvent,
|
|
3854
|
+
onDragStart: zoned.onDragStart,
|
|
3855
|
+
eventStartEditable,
|
|
3856
|
+
eventOverlap,
|
|
3857
|
+
onPressEvent: zoned.onPressEvent,
|
|
3858
|
+
onPressMore: zoned.onPressMore,
|
|
3275
3859
|
renderEvent: renderMonthEvent,
|
|
3276
3860
|
eventAccessibilityLabel
|
|
3277
3861
|
});
|
|
@@ -3318,12 +3902,12 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3318
3902
|
dragStepMinutes,
|
|
3319
3903
|
touchDragDelay,
|
|
3320
3904
|
touchDragThreshold,
|
|
3321
|
-
onPressEvent,
|
|
3322
|
-
onPressCell,
|
|
3323
|
-
onCreateEvent,
|
|
3905
|
+
onPressEvent: zoned.onPressEvent,
|
|
3906
|
+
onPressCell: zoned.onPressTime,
|
|
3907
|
+
onCreateEvent: zoned.onCreateTimed,
|
|
3324
3908
|
renderCreateGhost,
|
|
3325
|
-
onDragStart,
|
|
3326
|
-
onDragEvent,
|
|
3909
|
+
onDragStart: zoned.onDragStart,
|
|
3910
|
+
onDragEvent: zoned.onDragEvent,
|
|
3327
3911
|
getEventId,
|
|
3328
3912
|
onChangeDate,
|
|
3329
3913
|
onPressDateHeader,
|
|
@@ -4757,6 +5341,7 @@ exports.DatePicker = DatePicker;
|
|
|
4757
5341
|
exports.DateRangePicker = DateRangePicker;
|
|
4758
5342
|
exports.MonthList = MonthList;
|
|
4759
5343
|
exports.MonthView = MonthView;
|
|
5344
|
+
exports.MultiWeekView = MultiWeekView;
|
|
4760
5345
|
exports.ResourceTimeline = ResourceTimeline;
|
|
4761
5346
|
exports.TimeGrid = TimeGrid;
|
|
4762
5347
|
exports.YearView = YearView;
|
|
@@ -4772,6 +5357,12 @@ Object.defineProperty(exports, "buildMonthGrid", {
|
|
|
4772
5357
|
return _super_calendar_core.buildMonthGrid;
|
|
4773
5358
|
}
|
|
4774
5359
|
});
|
|
5360
|
+
Object.defineProperty(exports, "buildMultiWeekGrid", {
|
|
5361
|
+
enumerable: true,
|
|
5362
|
+
get: function() {
|
|
5363
|
+
return _super_calendar_core.buildMultiWeekGrid;
|
|
5364
|
+
}
|
|
5365
|
+
});
|
|
4775
5366
|
exports.darkDomTheme = darkDomTheme;
|
|
4776
5367
|
Object.defineProperty(exports, "daySelectionState", {
|
|
4777
5368
|
enumerable: true,
|