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