@super-calendar/dom 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/index.d.mts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +424 -87
- package/dist/index.mjs +420 -90
- package/package.json +2 -2
- package/src/Calendar.tsx +78 -13
- package/src/MonthView.tsx +388 -65
- package/src/MultiWeekView.tsx +54 -0
- 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";
|
|
2
|
+
import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
|
|
3
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";
|
|
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, 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";
|
|
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). */
|
|
@@ -541,6 +541,99 @@ function YearView({ date, events, weekStartsOn = 0, hiddenDays, locale, labels:
|
|
|
541
541
|
})
|
|
542
542
|
});
|
|
543
543
|
}
|
|
544
|
+
// src/touch.ts
|
|
545
|
+
function waitForHold(grab, delay, threshold, onHold, onTap, onCancel) {
|
|
546
|
+
const detach = () => {
|
|
547
|
+
clearTimeout(timer);
|
|
548
|
+
document.removeEventListener("pointermove", move);
|
|
549
|
+
document.removeEventListener("pointerup", up);
|
|
550
|
+
document.removeEventListener("pointercancel", cancelPointer);
|
|
551
|
+
document.removeEventListener("pointerdown", anotherPointer);
|
|
552
|
+
};
|
|
553
|
+
const cancel = () => {
|
|
554
|
+
detach();
|
|
555
|
+
onCancel();
|
|
556
|
+
};
|
|
557
|
+
const move = (event) => {
|
|
558
|
+
if (event.pointerId === grab.pointerId && Math.hypot(event.clientX - grab.clientX, event.clientY - grab.clientY) > threshold) cancel();
|
|
559
|
+
};
|
|
560
|
+
const up = (event) => {
|
|
561
|
+
if (event.pointerId === grab.pointerId) {
|
|
562
|
+
detach();
|
|
563
|
+
onTap();
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
const cancelPointer = (event) => {
|
|
567
|
+
if (event.pointerId === grab.pointerId) cancel();
|
|
568
|
+
};
|
|
569
|
+
const anotherPointer = (event) => {
|
|
570
|
+
if (event.pointerId !== grab.pointerId) cancel();
|
|
571
|
+
};
|
|
572
|
+
const timer = setTimeout(() => {
|
|
573
|
+
detach();
|
|
574
|
+
onHold();
|
|
575
|
+
}, delay);
|
|
576
|
+
document.addEventListener("pointermove", move);
|
|
577
|
+
document.addEventListener("pointerup", up);
|
|
578
|
+
document.addEventListener("pointercancel", cancelPointer);
|
|
579
|
+
document.addEventListener("pointerdown", anotherPointer);
|
|
580
|
+
return cancel;
|
|
581
|
+
}
|
|
582
|
+
/** A quick swipe scrolls; a held pointer owns a date-row drag until release. */
|
|
583
|
+
function holdDateDrag(grab, start, move, cancel, release) {
|
|
584
|
+
const doc = grab.box.ownerDocument;
|
|
585
|
+
let active = false;
|
|
586
|
+
let finished = false;
|
|
587
|
+
let cancelWait;
|
|
588
|
+
const detach = () => {
|
|
589
|
+
doc.removeEventListener("pointermove", onMove);
|
|
590
|
+
doc.removeEventListener("pointerup", onUp);
|
|
591
|
+
doc.removeEventListener("pointercancel", onCancel);
|
|
592
|
+
doc.removeEventListener("pointerdown", onAnotherPointer);
|
|
593
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
594
|
+
doc.removeEventListener("contextmenu", onContextMenu);
|
|
595
|
+
};
|
|
596
|
+
const stop = () => {
|
|
597
|
+
if (finished) return;
|
|
598
|
+
finished = true;
|
|
599
|
+
detach();
|
|
600
|
+
cancelWait?.();
|
|
601
|
+
cancel();
|
|
602
|
+
release();
|
|
603
|
+
};
|
|
604
|
+
const onMove = (event) => {
|
|
605
|
+
if (active && event.pointerId === grab.pointerId) move(event.clientX, event.clientY);
|
|
606
|
+
};
|
|
607
|
+
const onUp = (event) => {
|
|
608
|
+
if (event.pointerId !== grab.pointerId) return;
|
|
609
|
+
finished = true;
|
|
610
|
+
detach();
|
|
611
|
+
release();
|
|
612
|
+
};
|
|
613
|
+
const onCancel = (event) => {
|
|
614
|
+
if (event.pointerId === grab.pointerId) stop();
|
|
615
|
+
};
|
|
616
|
+
const onAnotherPointer = (event) => {
|
|
617
|
+
if (event.pointerId !== grab.pointerId) stop();
|
|
618
|
+
};
|
|
619
|
+
const onTouchMove = (event) => {
|
|
620
|
+
if (active && event.cancelable) event.preventDefault();
|
|
621
|
+
};
|
|
622
|
+
const onContextMenu = (event) => {
|
|
623
|
+
event.preventDefault();
|
|
624
|
+
};
|
|
625
|
+
doc.addEventListener("pointermove", onMove);
|
|
626
|
+
doc.addEventListener("pointerup", onUp);
|
|
627
|
+
doc.addEventListener("pointercancel", onCancel);
|
|
628
|
+
doc.addEventListener("pointerdown", onAnotherPointer);
|
|
629
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
630
|
+
doc.addEventListener("contextmenu", onContextMenu);
|
|
631
|
+
cancelWait = waitForHold(grab, 400, 8, () => {
|
|
632
|
+
active = true;
|
|
633
|
+
start();
|
|
634
|
+
}, release, stop);
|
|
635
|
+
return stop;
|
|
636
|
+
}
|
|
544
637
|
// src/MonthView.tsx
|
|
545
638
|
const EMPTY_LAYOUT = {
|
|
546
639
|
segments: [],
|
|
@@ -550,6 +643,7 @@ const CHIP_HEIGHT = 18;
|
|
|
550
643
|
const CHIP_GAP = 2;
|
|
551
644
|
const CELL_PAD = 4;
|
|
552
645
|
const DRAGGED_CHIP_OPACITY = .4;
|
|
646
|
+
const isOutsidePeriod = (day) => day.isCurrentMonth === false;
|
|
553
647
|
function dayCellDefault(day, theme, highlightWeekends) {
|
|
554
648
|
return {
|
|
555
649
|
base: {
|
|
@@ -709,7 +803,7 @@ function chipDefault(theme, chipHeight) {
|
|
|
709
803
|
}
|
|
710
804
|
};
|
|
711
805
|
}
|
|
712
|
-
function moreButtonDefault(theme, chipHeight) {
|
|
806
|
+
function moreButtonDefault(theme, chipHeight, multiWeek = false) {
|
|
713
807
|
return {
|
|
714
808
|
base: {
|
|
715
809
|
position: "relative",
|
|
@@ -720,7 +814,12 @@ function moreButtonDefault(theme, chipHeight) {
|
|
|
720
814
|
textAlign: "left",
|
|
721
815
|
height: chipHeight,
|
|
722
816
|
lineHeight: `${chipHeight}px`,
|
|
723
|
-
fontFamily: "inherit"
|
|
817
|
+
fontFamily: "inherit",
|
|
818
|
+
...multiWeek ? {
|
|
819
|
+
whiteSpace: "nowrap",
|
|
820
|
+
overflow: "hidden",
|
|
821
|
+
textOverflow: "ellipsis"
|
|
822
|
+
} : {}
|
|
724
823
|
},
|
|
725
824
|
themed: {
|
|
726
825
|
padding: "0 6px",
|
|
@@ -743,6 +842,10 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
743
842
|
}
|
|
744
843
|
return out;
|
|
745
844
|
}
|
|
845
|
+
function rangeTitle(start, endExclusive, locale) {
|
|
846
|
+
const options = locale ? { locale } : void 0;
|
|
847
|
+
return `${format(start, "PP", options)} – ${format(addDays(endExclusive, -1), "PP", options)}`;
|
|
848
|
+
}
|
|
746
849
|
/**
|
|
747
850
|
* A single static month grid, rendered with plain DOM elements.
|
|
748
851
|
*
|
|
@@ -751,14 +854,33 @@ function collectRowEvents(week, eventsByDay) {
|
|
|
751
854
|
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
752
855
|
* ```
|
|
753
856
|
*/
|
|
754
|
-
function MonthView({ date,
|
|
857
|
+
function MonthView({ date, showAdjacentMonths = true, ...rest }) {
|
|
858
|
+
return /* @__PURE__ */ jsx(DateRows, {
|
|
859
|
+
...rest,
|
|
860
|
+
source: {
|
|
861
|
+
kind: "month",
|
|
862
|
+
date,
|
|
863
|
+
showAdjacentMonths
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
869
|
+
* spanning event bars, overflow, selection, drag, and keyboard handling.
|
|
870
|
+
*/
|
|
871
|
+
function DateRows({ source, weekStartsOn = 0, hiddenDays, weekdayFormat = "short", events, eventsByDay: eventsByDayProp, renderEvent, eventAccessibilityLabel, maxVisibleEventCount = 3, chipHeight = CHIP_HEIGHT, chipGap = CHIP_GAP, moreLabel = "{moreCount} More", labels: labelsProp, onPressEvent, onPressMore, selectedRange, selectedDates, highlightWeekends = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, onPressCell, onCreateEvent, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, keyboardDayNavigation = false, className, style, classNames, styles }) {
|
|
872
|
+
const { date } = source;
|
|
873
|
+
const multiWeek = source.kind === "multiweek";
|
|
874
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
875
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : void 0;
|
|
876
|
+
const viewMode = multiWeek ? "multiweek" : "month";
|
|
755
877
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
756
878
|
const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
|
|
757
879
|
const slot = createSlots({
|
|
758
880
|
classNames,
|
|
759
881
|
styles
|
|
760
882
|
});
|
|
761
|
-
const eventsMode = events !== void 0;
|
|
883
|
+
const eventsMode = events !== void 0 || multiWeek;
|
|
762
884
|
const dayRoving = !eventsMode || keyboardDayNavigation;
|
|
763
885
|
const eventsByDay = useMemo(() => {
|
|
764
886
|
if (eventsByDayProp) return eventsByDayProp;
|
|
@@ -796,20 +918,39 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
796
918
|
document.removeEventListener("keydown", onKey);
|
|
797
919
|
};
|
|
798
920
|
}, [moreOpenFor]);
|
|
799
|
-
const eventRowHeight = 32 + maxVisibleEventCount * (chipHeight + chipGap);
|
|
800
|
-
const { weeks, weekdays } = useMemo(() =>
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
921
|
+
const eventRowHeight = 32 + (multiWeek ? Math.max(1, maxVisibleEventCount) : maxVisibleEventCount) * (chipHeight + chipGap);
|
|
922
|
+
const { weeks, weekdays, title, period } = useMemo(() => {
|
|
923
|
+
const options = {
|
|
924
|
+
weekStartsOn,
|
|
925
|
+
hiddenDays,
|
|
926
|
+
weekdayFormat,
|
|
927
|
+
selectedRange,
|
|
928
|
+
selectedDates,
|
|
929
|
+
minDate,
|
|
930
|
+
maxDate,
|
|
931
|
+
isDateDisabled,
|
|
932
|
+
locale
|
|
933
|
+
};
|
|
934
|
+
if (numberOfWeeks === void 0) return {
|
|
935
|
+
...buildMonthGrid$1(date, options),
|
|
936
|
+
title: format(date, "MMMM yyyy", locale ? { locale } : void 0),
|
|
937
|
+
period: null
|
|
938
|
+
};
|
|
939
|
+
const grid = buildMultiWeekGrid$1(date, {
|
|
940
|
+
...options,
|
|
941
|
+
numberOfWeeks
|
|
942
|
+
});
|
|
943
|
+
return {
|
|
944
|
+
weeks: grid.weeks,
|
|
945
|
+
weekdays: grid.weekdays,
|
|
946
|
+
title: rangeTitle(grid.visibleRange.start, grid.visibleRange.endExclusive, locale),
|
|
947
|
+
period: grid.period
|
|
948
|
+
};
|
|
949
|
+
}, [
|
|
811
950
|
date,
|
|
951
|
+
numberOfWeeks,
|
|
812
952
|
weekStartsOn,
|
|
953
|
+
hiddenDays,
|
|
813
954
|
weekdayFormat,
|
|
814
955
|
selectedRange,
|
|
815
956
|
selectedDates,
|
|
@@ -823,7 +964,18 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
823
964
|
weeks,
|
|
824
965
|
eventsByDay
|
|
825
966
|
]);
|
|
967
|
+
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]);
|
|
968
|
+
const focusableKeys = useMemo(() => focusableDays ? new Set(focusableDays.map((d) => format(d, "yyyy-MM-dd"))) : null, [focusableDays]);
|
|
826
969
|
const initialFocus = useMemo(() => {
|
|
970
|
+
if (focusableDays && focusableKeys) {
|
|
971
|
+
const rendered = (d) => !!d && focusableKeys.has(format(d, "yyyy-MM-dd"));
|
|
972
|
+
if (rendered(selectedRange?.start)) return startOfDay(selectedRange.start);
|
|
973
|
+
const picked = selectedDates?.find(rendered);
|
|
974
|
+
if (picked) return startOfDay(picked);
|
|
975
|
+
const today = /* @__PURE__ */ new Date();
|
|
976
|
+
if (rendered(today)) return startOfDay(today);
|
|
977
|
+
return focusableDays[0] ?? null;
|
|
978
|
+
}
|
|
827
979
|
const inMonth = (d) => !!d && isSameMonth(d, date);
|
|
828
980
|
if (inMonth(selectedRange?.start)) return startOfDay(selectedRange.start);
|
|
829
981
|
const picked = selectedDates?.find(inMonth);
|
|
@@ -831,6 +983,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
831
983
|
const today = /* @__PURE__ */ new Date();
|
|
832
984
|
return isSameMonth(today, date) ? startOfDay(today) : startOfMonth(date);
|
|
833
985
|
}, [
|
|
986
|
+
focusableDays,
|
|
987
|
+
focusableKeys,
|
|
834
988
|
date,
|
|
835
989
|
selectedRange,
|
|
836
990
|
selectedDates
|
|
@@ -838,16 +992,36 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
838
992
|
const [focusedDate, setFocusedDate] = useState(initialFocus);
|
|
839
993
|
const initialFocusRef = useRef(initialFocus);
|
|
840
994
|
initialFocusRef.current = initialFocus;
|
|
841
|
-
const
|
|
842
|
-
const
|
|
995
|
+
const windowKey = period ? `${format(period.start, "yyyy-MM-dd")}+${numberOfWeeks}:${weekdays.map((day) => day.date.getDay()).join(",")}` : format(date, "yyyy-MM");
|
|
996
|
+
const windowKeyRef = useRef(windowKey);
|
|
997
|
+
windowKeyRef.current = windowKey;
|
|
998
|
+
const focusedWindow = useRef(windowKey);
|
|
999
|
+
const gridRef = useRef(null);
|
|
1000
|
+
const restoreDayFocus = useRef(false);
|
|
1001
|
+
if (multiWeek && windowKey !== focusedWindow.current) {
|
|
1002
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1003
|
+
restoreDayFocus.current = !!active?.hasAttribute("data-day") && !!gridRef.current?.contains(active);
|
|
1004
|
+
}
|
|
843
1005
|
useEffect(() => {
|
|
844
|
-
if (
|
|
845
|
-
|
|
1006
|
+
if (windowKey === focusedWindow.current) return;
|
|
1007
|
+
focusedWindow.current = windowKey;
|
|
846
1008
|
setFocusedDate(initialFocusRef.current);
|
|
847
|
-
|
|
1009
|
+
if (restoreDayFocus.current) {
|
|
1010
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1011
|
+
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();
|
|
1012
|
+
}
|
|
1013
|
+
restoreDayFocus.current = false;
|
|
1014
|
+
}, [windowKey]);
|
|
848
1015
|
const [hoveredKey, setHoveredKey] = useState(null);
|
|
849
|
-
const
|
|
850
|
-
const focusKey = format(
|
|
1016
|
+
const storedFocusKey = focusedDate ? format(focusedDate, "yyyy-MM-dd") : null;
|
|
1017
|
+
const focusKey = focusableKeys && (storedFocusKey === null || !focusableKeys.has(storedFocusKey)) ? initialFocus && format(initialFocus, "yyyy-MM-dd") : storedFocusKey;
|
|
1018
|
+
useEffect(() => {
|
|
1019
|
+
if (!multiWeek) return;
|
|
1020
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
1021
|
+
if (!active?.hasAttribute("data-day") || !gridRef.current?.contains(active)) return;
|
|
1022
|
+
if (active.getAttribute("data-day") === focusKey && active.getAttribute("aria-disabled") !== "true") return;
|
|
1023
|
+
(focusKey ? gridRef.current.querySelector(`[data-day="${focusKey}"]`) : gridRef.current)?.focus();
|
|
1024
|
+
}, [multiWeek, focusKey]);
|
|
851
1025
|
const [drag, setDrag] = useState(null);
|
|
852
1026
|
const dragRef = useRef(drag);
|
|
853
1027
|
dragRef.current = drag;
|
|
@@ -869,7 +1043,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
869
1043
|
setDrag({
|
|
870
1044
|
kind: "create",
|
|
871
1045
|
anchor: t,
|
|
872
|
-
hover: t
|
|
1046
|
+
hover: t,
|
|
1047
|
+
windowKey
|
|
873
1048
|
});
|
|
874
1049
|
};
|
|
875
1050
|
const beginMove = (event, day) => {
|
|
@@ -879,7 +1054,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
879
1054
|
kind: "move",
|
|
880
1055
|
event,
|
|
881
1056
|
from: t,
|
|
882
|
-
to: t
|
|
1057
|
+
to: t,
|
|
1058
|
+
windowKey
|
|
883
1059
|
});
|
|
884
1060
|
onDragStart?.(event);
|
|
885
1061
|
};
|
|
@@ -901,6 +1077,70 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
901
1077
|
onSelectDrag?.(new Date(lo), new Date(hi));
|
|
902
1078
|
}
|
|
903
1079
|
};
|
|
1080
|
+
const heldTouch = useRef(null);
|
|
1081
|
+
const heldOrigin = useRef(null);
|
|
1082
|
+
const dayLookup = useMemo(() => new Map(weeks.flatMap((week) => week.days).map((day) => [day.id, day])), [weeks]);
|
|
1083
|
+
const touchHandlers = useRef({
|
|
1084
|
+
beginCreate,
|
|
1085
|
+
beginMove,
|
|
1086
|
+
extendDrag,
|
|
1087
|
+
dayLookup
|
|
1088
|
+
});
|
|
1089
|
+
touchHandlers.current = {
|
|
1090
|
+
beginCreate,
|
|
1091
|
+
beginMove,
|
|
1092
|
+
extendDrag,
|
|
1093
|
+
dayLookup
|
|
1094
|
+
};
|
|
1095
|
+
const pressRow = (event, day, moving) => {
|
|
1096
|
+
if (event.button !== 0 || event.isPrimary === false || heldTouch.current) return;
|
|
1097
|
+
beginPress();
|
|
1098
|
+
const start = () => {
|
|
1099
|
+
if (moving) touchHandlers.current.beginMove(moving, day);
|
|
1100
|
+
else touchHandlers.current.beginCreate(day);
|
|
1101
|
+
};
|
|
1102
|
+
if (!multiWeek || !event.pointerType || event.pointerType === "mouse") {
|
|
1103
|
+
start();
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
heldOrigin.current = {
|
|
1107
|
+
day,
|
|
1108
|
+
event: moving
|
|
1109
|
+
};
|
|
1110
|
+
heldTouch.current = holdDateDrag({
|
|
1111
|
+
box: event.currentTarget,
|
|
1112
|
+
pointerId: event.pointerId,
|
|
1113
|
+
pointerType: event.pointerType,
|
|
1114
|
+
clientX: event.clientX,
|
|
1115
|
+
clientY: event.clientY
|
|
1116
|
+
}, start, (x, y) => {
|
|
1117
|
+
const element = gridRef.current?.ownerDocument.elementFromPoint(x, y)?.closest("[data-day]");
|
|
1118
|
+
if (!element || !gridRef.current?.contains(element)) return;
|
|
1119
|
+
const day = touchHandlers.current.dayLookup.get(element.dataset.day ?? "");
|
|
1120
|
+
if (day && !day.isDisabled) touchHandlers.current.extendDrag(day.date);
|
|
1121
|
+
}, () => {
|
|
1122
|
+
dragRef.current = null;
|
|
1123
|
+
setDrag(null);
|
|
1124
|
+
movedRef.current = false;
|
|
1125
|
+
}, () => {
|
|
1126
|
+
heldTouch.current = null;
|
|
1127
|
+
heldOrigin.current = null;
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
useEffect(() => () => {
|
|
1131
|
+
heldTouch.current?.();
|
|
1132
|
+
}, [windowKey]);
|
|
1133
|
+
useEffect(() => {
|
|
1134
|
+
const origin = heldOrigin.current;
|
|
1135
|
+
if (!origin) return;
|
|
1136
|
+
const current = dragRef.current;
|
|
1137
|
+
const destination = current ? new Date(current.kind === "create" ? current.hover : current.to) : origin.day;
|
|
1138
|
+
const enabled = (day) => {
|
|
1139
|
+
const cell = dayLookup.get(format(day, "yyyy-MM-dd"));
|
|
1140
|
+
return cell != null && !cell.isDisabled;
|
|
1141
|
+
};
|
|
1142
|
+
if (!enabled(origin.day) || !enabled(destination) || (origin.event ? !events?.includes(origin.event) || !canMove(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
|
|
1143
|
+
});
|
|
904
1144
|
const isDragging = drag !== null;
|
|
905
1145
|
const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
906
1146
|
useEffect(() => {
|
|
@@ -909,6 +1149,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
909
1149
|
const current = dragRef.current;
|
|
910
1150
|
setDrag(null);
|
|
911
1151
|
if (!current || !movedRef.current) return;
|
|
1152
|
+
if (multiWeek && current.windowKey !== windowKeyRef.current) return;
|
|
912
1153
|
suppressClickRef.current = true;
|
|
913
1154
|
if (current.kind === "create") {
|
|
914
1155
|
const range = monthCreateRange(new Date(current.anchor), new Date(current.hover));
|
|
@@ -924,12 +1165,51 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
924
1165
|
return () => window.removeEventListener("pointerup", finish);
|
|
925
1166
|
}, [
|
|
926
1167
|
isDragging,
|
|
1168
|
+
multiWeek,
|
|
927
1169
|
onCreateEvent,
|
|
928
1170
|
onDragEvent,
|
|
929
1171
|
eventOverlap,
|
|
930
1172
|
events
|
|
931
1173
|
]);
|
|
1174
|
+
const transientWindow = useRef(windowKey);
|
|
1175
|
+
useEffect(() => {
|
|
1176
|
+
if (transientWindow.current === windowKey) return;
|
|
1177
|
+
transientWindow.current = windowKey;
|
|
1178
|
+
if (!multiWeek) return;
|
|
1179
|
+
setDrag(null);
|
|
1180
|
+
setMoreOpenFor(null);
|
|
1181
|
+
}, [multiWeek, windowKey]);
|
|
1182
|
+
const nextMultiWeekFocus = (key) => {
|
|
1183
|
+
if (!focusableDays || !focusableKeys || !period) return void 0;
|
|
1184
|
+
const index = focusableDays.findIndex((d) => format(d, "yyyy-MM-dd") === focusKey);
|
|
1185
|
+
if (index === -1) return null;
|
|
1186
|
+
if (key === "ArrowLeft") return focusableDays[index - 1] ?? null;
|
|
1187
|
+
if (key === "ArrowRight") return focusableDays[index + 1] ?? null;
|
|
1188
|
+
if (key === "Home") return focusableDays[0];
|
|
1189
|
+
if (key === "End") return focusableDays[focusableDays.length - 1];
|
|
1190
|
+
const step = key === "ArrowUp" ? -7 : 7;
|
|
1191
|
+
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;
|
|
1192
|
+
return null;
|
|
1193
|
+
};
|
|
932
1194
|
const onKeyDown = (e) => {
|
|
1195
|
+
if (multiWeek) {
|
|
1196
|
+
if (![
|
|
1197
|
+
"ArrowLeft",
|
|
1198
|
+
"ArrowRight",
|
|
1199
|
+
"ArrowUp",
|
|
1200
|
+
"ArrowDown",
|
|
1201
|
+
"Home",
|
|
1202
|
+
"End"
|
|
1203
|
+
].includes(e.key)) return;
|
|
1204
|
+
e.preventDefault();
|
|
1205
|
+
const target = nextMultiWeekFocus(e.key);
|
|
1206
|
+
if (!target) return;
|
|
1207
|
+
setFocusedDate(target);
|
|
1208
|
+
const targetKey = format(target, "yyyy-MM-dd");
|
|
1209
|
+
gridRef.current?.querySelector(`[data-day="${targetKey}"]`)?.focus();
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
if (!focusedDate) return;
|
|
933
1213
|
let next = null;
|
|
934
1214
|
if (e.key === "ArrowLeft") next = addDays(focusedDate, -1);
|
|
935
1215
|
else if (e.key === "ArrowRight") next = addDays(focusedDate, 1);
|
|
@@ -949,6 +1229,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
949
1229
|
style: {
|
|
950
1230
|
fontFamily: theme.fontFamily,
|
|
951
1231
|
color: theme.text,
|
|
1232
|
+
...multiWeek ? {
|
|
1233
|
+
display: "flex",
|
|
1234
|
+
flexDirection: "column",
|
|
1235
|
+
minHeight: 0
|
|
1236
|
+
} : null,
|
|
952
1237
|
...style
|
|
953
1238
|
},
|
|
954
1239
|
children: [
|
|
@@ -958,13 +1243,13 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
958
1243
|
fontWeight: 700,
|
|
959
1244
|
padding: "10px 14px 6px"
|
|
960
1245
|
} }),
|
|
961
|
-
children:
|
|
1246
|
+
children: title
|
|
962
1247
|
}) : null,
|
|
963
1248
|
showWeekdays ? /* @__PURE__ */ jsx("div", {
|
|
964
1249
|
...slot("weekdays", {
|
|
965
1250
|
base: {
|
|
966
1251
|
display: "grid",
|
|
967
|
-
gridTemplateColumns:
|
|
1252
|
+
gridTemplateColumns: `repeat(${weekdays.length}, minmax(0, 1fr))`
|
|
968
1253
|
},
|
|
969
1254
|
themed: {
|
|
970
1255
|
borderBottom: `1px solid ${theme.gridLine}`,
|
|
@@ -984,9 +1269,14 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
984
1269
|
/* @__PURE__ */ jsx("div", {
|
|
985
1270
|
ref: gridRef,
|
|
986
1271
|
role: "grid",
|
|
987
|
-
|
|
1272
|
+
tabIndex: multiWeek ? -1 : void 0,
|
|
1273
|
+
"aria-label": title,
|
|
988
1274
|
onKeyDown: dayRoving ? onKeyDown : void 0,
|
|
989
|
-
...slot("grid"
|
|
1275
|
+
...slot("grid", multiWeek ? { base: {
|
|
1276
|
+
flex: "1 1 auto",
|
|
1277
|
+
minHeight: 0,
|
|
1278
|
+
overflowY: "auto"
|
|
1279
|
+
} } : void 0),
|
|
990
1280
|
children: weeks.map((week, weekIndex) => {
|
|
991
1281
|
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
992
1282
|
const visibleLanes = rowLayout.laneCount > maxVisibleEventCount ? Math.max(maxVisibleEventCount - 1, 1) : rowLayout.laneCount;
|
|
@@ -994,8 +1284,8 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
994
1284
|
let firstVisCol = 0;
|
|
995
1285
|
let lastVisCol = cols - 1;
|
|
996
1286
|
if (eventsMode && !showAdjacentMonths) {
|
|
997
|
-
const first = week.days.findIndex((d) => d
|
|
998
|
-
const lastFromEnd = [...week.days].reverse().findIndex((d) => d
|
|
1287
|
+
const first = week.days.findIndex((d) => !isOutsidePeriod(d));
|
|
1288
|
+
const lastFromEnd = [...week.days].reverse().findIndex((d) => !isOutsidePeriod(d));
|
|
999
1289
|
if (first !== -1) {
|
|
1000
1290
|
firstVisCol = first;
|
|
1001
1291
|
lastVisCol = cols - 1 - lastFromEnd;
|
|
@@ -1018,10 +1308,10 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1018
1308
|
role: "row",
|
|
1019
1309
|
...slot("week", { base: {
|
|
1020
1310
|
display: "grid",
|
|
1021
|
-
gridTemplateColumns:
|
|
1311
|
+
gridTemplateColumns: `repeat(${week.days.length}, minmax(0, 1fr))`
|
|
1022
1312
|
} }),
|
|
1023
1313
|
children: week.days.map((day, dayCol) => {
|
|
1024
|
-
const hidden = !showAdjacentMonths &&
|
|
1314
|
+
const hidden = !showAdjacentMonths && isOutsidePeriod(day);
|
|
1025
1315
|
const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
|
|
1026
1316
|
if (hidden) return /* @__PURE__ */ jsx("div", {
|
|
1027
1317
|
role: "gridcell",
|
|
@@ -1043,7 +1333,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1043
1333
|
"data-selected": day.isSelected,
|
|
1044
1334
|
"data-range": day.isInRange,
|
|
1045
1335
|
"data-weekend": day.isWeekend,
|
|
1046
|
-
"data-outside":
|
|
1336
|
+
"data-outside": isOutsidePeriod(day),
|
|
1047
1337
|
"data-disabled": day.isDisabled,
|
|
1048
1338
|
"data-creating": inCreate,
|
|
1049
1339
|
"data-drop": isDropTarget
|
|
@@ -1072,13 +1362,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1072
1362
|
...dayCellProps,
|
|
1073
1363
|
style: dragWired ? {
|
|
1074
1364
|
...dayCellProps.style,
|
|
1075
|
-
touchAction: "none",
|
|
1365
|
+
touchAction: multiWeek ? "pan-y" : "none",
|
|
1076
1366
|
userSelect: "none"
|
|
1077
1367
|
} : dayCellProps.style,
|
|
1078
1368
|
onPointerDown: dragWired && !day.isDisabled ? (e) => {
|
|
1079
|
-
|
|
1080
|
-
beginPress();
|
|
1081
|
-
beginCreate(day.date);
|
|
1369
|
+
pressRow(e, day.date);
|
|
1082
1370
|
} : void 0,
|
|
1083
1371
|
onPointerEnter: dragWired && !day.isDisabled ? () => extendDrag(day.date) : void 0,
|
|
1084
1372
|
onClick: day.isDisabled ? void 0 : () => {
|
|
@@ -1113,8 +1401,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1113
1401
|
onPointerDown: canMove(b.seg.event) ? (e) => {
|
|
1114
1402
|
if (e.button !== 0) return;
|
|
1115
1403
|
e.stopPropagation();
|
|
1116
|
-
|
|
1117
|
-
beginMove(b.seg.event, day.date);
|
|
1404
|
+
pressRow(e, day.date, b.seg.event);
|
|
1118
1405
|
} : void 0,
|
|
1119
1406
|
onClick: (e) => {
|
|
1120
1407
|
e.stopPropagation();
|
|
@@ -1124,7 +1411,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1124
1411
|
...barChipButton,
|
|
1125
1412
|
title: b.seg.event.title,
|
|
1126
1413
|
"aria-label": eventAccessibilityLabel ? eventAccessibilityLabel(b.seg.event, {
|
|
1127
|
-
mode:
|
|
1414
|
+
mode: viewMode,
|
|
1128
1415
|
isAllDay: isAllDayEvent$1(b.seg.event),
|
|
1129
1416
|
ampm: false
|
|
1130
1417
|
}) : `${b.seg.event.title}, ${dayLabel}`,
|
|
@@ -1138,10 +1425,11 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1138
1425
|
pointerEvents: isDragging ? "none" : "auto",
|
|
1139
1426
|
opacity: isDragged ? DRAGGED_CHIP_OPACITY : void 0,
|
|
1140
1427
|
cursor: canMove(b.seg.event) ? "grab" : void 0,
|
|
1141
|
-
touchAction: dragWired ? "none" : void 0,
|
|
1428
|
+
touchAction: dragWired ? multiWeek ? "pan-y" : "none" : void 0,
|
|
1142
1429
|
zIndex: 2
|
|
1143
1430
|
},
|
|
1144
1431
|
children: Chip ? /* @__PURE__ */ jsx(Chip, {
|
|
1432
|
+
mode: viewMode,
|
|
1145
1433
|
event: b.seg.event,
|
|
1146
1434
|
onPress: () => onPressEvent?.(b.seg.event)
|
|
1147
1435
|
}) : /* @__PURE__ */ jsx("span", {
|
|
@@ -1183,7 +1471,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1183
1471
|
setMoreOpenFor((open) => open === day.id ? null : day.id);
|
|
1184
1472
|
}
|
|
1185
1473
|
},
|
|
1186
|
-
...slot("more", moreButtonDefault(theme, chipHeight)),
|
|
1474
|
+
...slot("more", moreButtonDefault(theme, chipHeight, multiWeek)),
|
|
1187
1475
|
"aria-label": `${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`,
|
|
1188
1476
|
"aria-expanded": onPressMore ? void 0 : moreOpenFor === day.id,
|
|
1189
1477
|
children: moreLabel.replace("{moreCount}", String(hiddenEvents.length))
|
|
@@ -1252,6 +1540,7 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1252
1540
|
cursor: "pointer"
|
|
1253
1541
|
},
|
|
1254
1542
|
children: Chip ? /* @__PURE__ */ jsx(Chip, {
|
|
1543
|
+
mode: viewMode,
|
|
1255
1544
|
event,
|
|
1256
1545
|
onPress: () => onPressEvent?.(event)
|
|
1257
1546
|
}) : /* @__PURE__ */ jsx("span", {
|
|
@@ -1301,6 +1590,33 @@ function MonthView({ date, weekStartsOn = 0, hiddenDays, weekdayFormat = "short"
|
|
|
1301
1590
|
]
|
|
1302
1591
|
});
|
|
1303
1592
|
}
|
|
1593
|
+
// src/MultiWeekView.tsx
|
|
1594
|
+
/**
|
|
1595
|
+
* Consecutive full weeks as stacked seven-day rows, with event chips and no hour
|
|
1596
|
+
* slots. It has the month grid's event bars, overflow, selection, and drag
|
|
1597
|
+
* interactions, and the month slots, `renderEvent`, and theme style it. Every
|
|
1598
|
+
* row is kept at full height; when the view is given less room, the rows scroll
|
|
1599
|
+
* under the title and weekday header.
|
|
1600
|
+
*
|
|
1601
|
+
* Standalone, it shows `events` as given; expand recurring events first with
|
|
1602
|
+
* `expandRecurringEvents`, or use `Calendar` with `mode="multiweek"`.
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```tsx
|
|
1606
|
+
* <MultiWeekView date={new Date()} numberOfWeeks={3} events={events} />
|
|
1607
|
+
* ```
|
|
1608
|
+
*/
|
|
1609
|
+
function MultiWeekView({ date, numberOfWeeks = 2, chipHeight = 24, ...rest }) {
|
|
1610
|
+
return /* @__PURE__ */ jsx(DateRows, {
|
|
1611
|
+
...rest,
|
|
1612
|
+
chipHeight,
|
|
1613
|
+
source: {
|
|
1614
|
+
kind: "multiweek",
|
|
1615
|
+
date,
|
|
1616
|
+
numberOfWeeks
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1304
1620
|
// src/EventActions.tsx
|
|
1305
1621
|
function moveFocus(event, container) {
|
|
1306
1622
|
const buttons = [...container?.querySelectorAll("button") ?? []];
|
|
@@ -1667,44 +1983,6 @@ function InertDiv(props) {
|
|
|
1667
1983
|
inert: props.inert ? "inert" : void 0
|
|
1668
1984
|
});
|
|
1669
1985
|
}
|
|
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
1986
|
// src/TimeGrid.tsx
|
|
1709
1987
|
const GUTTER_WIDTH$1 = 56;
|
|
1710
1988
|
const HOURS_PER_DAY = 24;
|
|
@@ -3137,16 +3415,24 @@ function TimeGridInner({ date, events = [], mode = "day", numberOfDays = 1, week
|
|
|
3137
3415
|
}
|
|
3138
3416
|
// src/Calendar.tsx
|
|
3139
3417
|
const EMPTY_EVENTS = [];
|
|
3140
|
-
function expansionRange(mode, date, weekStartsOn, numberOfDays) {
|
|
3418
|
+
function expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
3419
|
+
if (mode === "multiweek") {
|
|
3420
|
+
const { period } = buildMultiWeekGrid$1(date, {
|
|
3421
|
+
weekStartsOn,
|
|
3422
|
+
numberOfWeeks
|
|
3423
|
+
});
|
|
3424
|
+
return [period.start, endOfDay(addDays(period.endExclusive, -1))];
|
|
3425
|
+
}
|
|
3141
3426
|
if (mode === "month") return [startOfWeek(startOfMonth(date), { weekStartsOn }), endOfWeek(endOfMonth(date), { weekStartsOn })];
|
|
3142
3427
|
if (mode === "year") return [startOfWeek(startOfYear(date), { weekStartsOn }), endOfWeek(endOfYear(date), { weekStartsOn })];
|
|
3143
3428
|
if (mode === "schedule") return [startOfDay(date), endOfDay(addMonths(date, 3))];
|
|
3144
3429
|
const days = getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1);
|
|
3145
3430
|
return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
|
|
3146
3431
|
}
|
|
3147
|
-
function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
3432
|
+
function pageStep(mode, date, direction, weekStartsOn, numberOfDays, numberOfWeeks) {
|
|
3148
3433
|
if (mode === "year") return addYears(date, direction);
|
|
3149
3434
|
if (mode === "month") return addMonths(date, direction);
|
|
3435
|
+
if (mode === "multiweek") return addWeeks(date, direction * numberOfWeeks);
|
|
3150
3436
|
if (mode === "schedule") return addDays(date, direction * 7);
|
|
3151
3437
|
return addDays(date, direction * getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1).length);
|
|
3152
3438
|
}
|
|
@@ -3162,13 +3448,13 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
|
|
|
3162
3448
|
* ```
|
|
3163
3449
|
*/
|
|
3164
3450
|
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) {
|
|
3451
|
+
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
3452
|
const timeGridRef = useRef(null);
|
|
3167
3453
|
useImperativeHandle(ref, () => ({ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options) }), []);
|
|
3168
3454
|
const displayEvents = useMemo(() => {
|
|
3169
3455
|
let out = events ?? EMPTY_EVENTS;
|
|
3170
3456
|
if (out.some((e) => e.recurrence)) {
|
|
3171
|
-
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays);
|
|
3457
|
+
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
|
|
3172
3458
|
if (timeZone) {
|
|
3173
3459
|
start = addDays(start, -1);
|
|
3174
3460
|
end = addDays(end, 1);
|
|
@@ -3183,12 +3469,13 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3183
3469
|
date.getTime(),
|
|
3184
3470
|
weekStartsOn,
|
|
3185
3471
|
numberOfDays,
|
|
3472
|
+
numberOfWeeks,
|
|
3186
3473
|
timeZone
|
|
3187
3474
|
]);
|
|
3188
3475
|
const handlePageKeys = (e) => {
|
|
3189
3476
|
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));
|
|
3477
|
+
if (e.key === "PageDown") onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
3478
|
+
else if (e.key === "PageUp") onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
3192
3479
|
else return;
|
|
3193
3480
|
e.preventDefault();
|
|
3194
3481
|
};
|
|
@@ -3274,6 +3561,49 @@ function CalendarInner({ mode = "week", date, events, onChangeDate, weekStartsOn
|
|
|
3274
3561
|
renderEvent: renderMonthEvent,
|
|
3275
3562
|
eventAccessibilityLabel
|
|
3276
3563
|
});
|
|
3564
|
+
else if (mode === "multiweek") view = /* @__PURE__ */ jsx(MultiWeekView, {
|
|
3565
|
+
date,
|
|
3566
|
+
numberOfWeeks,
|
|
3567
|
+
events: displayEvents,
|
|
3568
|
+
weekStartsOn,
|
|
3569
|
+
hiddenDays,
|
|
3570
|
+
weekdayFormat,
|
|
3571
|
+
highlightWeekends,
|
|
3572
|
+
locale,
|
|
3573
|
+
labels,
|
|
3574
|
+
theme,
|
|
3575
|
+
className,
|
|
3576
|
+
style: height != null ? {
|
|
3577
|
+
height,
|
|
3578
|
+
...style
|
|
3579
|
+
} : style,
|
|
3580
|
+
classNames,
|
|
3581
|
+
styles,
|
|
3582
|
+
maxVisibleEventCount,
|
|
3583
|
+
chipHeight,
|
|
3584
|
+
chipGap,
|
|
3585
|
+
moreLabel,
|
|
3586
|
+
showTitle,
|
|
3587
|
+
fillCellOnSelection,
|
|
3588
|
+
selectedRange,
|
|
3589
|
+
selectedDates,
|
|
3590
|
+
minDate,
|
|
3591
|
+
maxDate,
|
|
3592
|
+
isDateDisabled,
|
|
3593
|
+
keyboardDayNavigation,
|
|
3594
|
+
onPressDay,
|
|
3595
|
+
onPressCell,
|
|
3596
|
+
onCreateEvent,
|
|
3597
|
+
onSelectDrag,
|
|
3598
|
+
onDragEvent,
|
|
3599
|
+
onDragStart,
|
|
3600
|
+
eventStartEditable,
|
|
3601
|
+
eventOverlap,
|
|
3602
|
+
onPressEvent,
|
|
3603
|
+
onPressMore,
|
|
3604
|
+
renderEvent: renderMonthEvent,
|
|
3605
|
+
eventAccessibilityLabel
|
|
3606
|
+
});
|
|
3277
3607
|
else view = /* @__PURE__ */ jsx(TimeGrid, {
|
|
3278
3608
|
ref: timeGridRef,
|
|
3279
3609
|
date,
|
|
@@ -4750,4 +5080,4 @@ function ResourceTimeline({ date, orientation = "horizontal", resources: allReso
|
|
|
4750
5080
|
]
|
|
4751
5081
|
});
|
|
4752
5082
|
}
|
|
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 };
|
|
5083
|
+
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 };
|