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