@super-calendar/core 2.6.0 → 2.8.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/dist/index.d.mts +216 -11
- package/dist/index.d.ts +216 -11
- package/dist/index.js +331 -42
- package/dist/index.mjs +324 -44
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/tokens.ts +4 -0
- package/src/types.ts +60 -7
- package/src/utils/dates.ts +35 -9
- package/src/utils/drag.ts +41 -0
- package/src/utils/layout.ts +56 -8
- package/src/utils/monthGrid.ts +118 -3
- package/src/utils/recurrence.ts +16 -3
- package/src/utils/useEventSource.ts +125 -0
- package/src/utils/useNow.ts +47 -0
package/dist/index.js
CHANGED
|
@@ -19,7 +19,8 @@ const lightColors = {
|
|
|
19
19
|
textMuted: "#6B7280",
|
|
20
20
|
textDisabled: "#B5B9C0",
|
|
21
21
|
eventBackground: "#DCE7FF",
|
|
22
|
-
eventText: "#1A1B1E"
|
|
22
|
+
eventText: "#1A1B1E",
|
|
23
|
+
backgroundEvent: "#E3F4E4"
|
|
23
24
|
};
|
|
24
25
|
/** The default dark-theme colour palette. */
|
|
25
26
|
const darkColors = {
|
|
@@ -38,7 +39,8 @@ const darkColors = {
|
|
|
38
39
|
textMuted: "#9BA1A6",
|
|
39
40
|
textDisabled: "#4B4F58",
|
|
40
41
|
eventBackground: "#243B53",
|
|
41
|
-
eventText: "#EAF2FF"
|
|
42
|
+
eventText: "#EAF2FF",
|
|
43
|
+
backgroundEvent: "#17301F"
|
|
42
44
|
};
|
|
43
45
|
//#endregion
|
|
44
46
|
//#region src/presentation.ts
|
|
@@ -106,14 +108,23 @@ const weekDaysCount = (weekStartsOn, weekEndsOn) => {
|
|
|
106
108
|
* from `weekStartsOn` to `weekEndsOn` (anchored to `date`'s week, paging by week);
|
|
107
109
|
* otherwise every mode shows `viewDayCount` consecutive days starting at `date`.
|
|
108
110
|
*/
|
|
109
|
-
const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false, weekEndsOn) => {
|
|
111
|
+
const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false, weekEndsOn, hiddenDays) => {
|
|
112
|
+
const hidden = hiddenDays && hiddenDays.length > 0 && hiddenDays.length < 7 ? hiddenDays : [];
|
|
110
113
|
let days;
|
|
111
|
-
if (mode === "week") days = getWeekDays(date, weekStartsOn);
|
|
114
|
+
if (mode === "week") days = filterHiddenDays(getWeekDays(date, weekStartsOn), hidden);
|
|
112
115
|
else if (mode === "custom" && weekEndsOn != null) {
|
|
113
116
|
const subject = (0, date_fns.startOfDay)(date);
|
|
114
117
|
const offset = weekStartsOn - subject.getDay();
|
|
115
|
-
days = Array.from({ length: weekDaysCount(weekStartsOn, weekEndsOn) }, (_, index) => (0, date_fns.addDays)(subject, index + offset));
|
|
116
|
-
} else
|
|
118
|
+
days = filterHiddenDays(Array.from({ length: weekDaysCount(weekStartsOn, weekEndsOn) }, (_, index) => (0, date_fns.addDays)(subject, index + offset)), hidden);
|
|
119
|
+
} else {
|
|
120
|
+
const count = viewDayCount(mode, numberOfDays);
|
|
121
|
+
days = [];
|
|
122
|
+
let cursor = (0, date_fns.startOfDay)(date);
|
|
123
|
+
while (days.length < count) {
|
|
124
|
+
if (!hidden.includes(cursor.getDay())) days.push(cursor);
|
|
125
|
+
cursor = (0, date_fns.addDays)(cursor, 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
117
128
|
return isRTL ? days.reverse() : days;
|
|
118
129
|
};
|
|
119
130
|
/**
|
|
@@ -121,7 +132,7 @@ const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false,
|
|
|
121
132
|
* `weekStartsOn`. `showSixWeeks` always returns six rows (42 days) for a
|
|
122
133
|
* fixed-height grid; `isRTL` reverses each week's day order.
|
|
123
134
|
*/
|
|
124
|
-
const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = false } = {}) => {
|
|
135
|
+
const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = false, hiddenDays } = {}) => {
|
|
125
136
|
const start = (0, date_fns.startOfWeek)((0, date_fns.startOfMonth)(month), { weekStartsOn });
|
|
126
137
|
const days = (0, date_fns.eachDayOfInterval)({
|
|
127
138
|
start,
|
|
@@ -129,11 +140,17 @@ const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = fa
|
|
|
129
140
|
});
|
|
130
141
|
const weeks = [];
|
|
131
142
|
for (let index = 0; index < days.length; index += 7) {
|
|
132
|
-
const week = days.slice(index, index + 7);
|
|
133
|
-
weeks.push(isRTL ? week.reverse() : week);
|
|
143
|
+
const week = filterHiddenDays(days.slice(index, index + 7), hiddenDays);
|
|
144
|
+
if (week.length > 0) weeks.push(isRTL ? week.reverse() : week);
|
|
134
145
|
}
|
|
135
146
|
return weeks;
|
|
136
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Drop the days whose weekday (0=Sunday…6=Saturday) is listed in `hiddenDays`.
|
|
150
|
+
* Hiding all seven weekdays is treated as hiding nothing (matching
|
|
151
|
+
* `getViewDays`), so a misconfiguration degrades to the full grid, not a blank.
|
|
152
|
+
*/
|
|
153
|
+
const filterHiddenDays = (days, hiddenDays) => hiddenDays && hiddenDays.length > 0 && new Set(hiddenDays).size < 7 ? days.filter((day) => !hiddenDays.includes(day.getDay())) : days;
|
|
137
154
|
/** True when `date` is a Saturday or Sunday. */
|
|
138
155
|
const isWeekend = (date) => {
|
|
139
156
|
const day = date.getDay();
|
|
@@ -261,6 +278,31 @@ function useDateRange(options = {}) {
|
|
|
261
278
|
//#endregion
|
|
262
279
|
//#region src/utils/drag.ts
|
|
263
280
|
/**
|
|
281
|
+
* True when two time ranges overlap. Edges touching (one ends exactly when the
|
|
282
|
+
* next begins) do not count as an overlap. Compares absolute instants, so events
|
|
283
|
+
* at the same wall-clock time on different days do not overlap.
|
|
284
|
+
*/
|
|
285
|
+
function eventsOverlap(aStart, aEnd, bStart, bEnd) {
|
|
286
|
+
return aStart.getTime() < bEnd.getTime() && bStart.getTime() < aEnd.getTime();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* True when the range `[start, end)` would overlap any event in `events` other
|
|
290
|
+
* than `moved` (compared by reference). Used by the `eventOverlap` guard to reject
|
|
291
|
+
* a drag/resize that would land an event on top of another.
|
|
292
|
+
*/
|
|
293
|
+
function overlapsOtherEvents(events, moved, start, end) {
|
|
294
|
+
return events.some((e) => e !== moved && eventsOverlap(e.start, e.end, start, end));
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* How many calendar days one time-grid page spans, used to advance the view by a
|
|
298
|
+
* whole page (e.g. when dragging an event past the edge into the next week).
|
|
299
|
+
* Deliberately ignores `hiddenDays` so a week always steps 7, matching the
|
|
300
|
+
* keyboard PageUp/PageDown paging and `Calendar`'s own page step.
|
|
301
|
+
*/
|
|
302
|
+
function pageStepDays(mode, date, weekStartsOn, numberOfDays = 1) {
|
|
303
|
+
return getViewDays(mode, date, weekStartsOn, numberOfDays).length;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
264
306
|
* Minutes to shift an event, snapping a vertical pixel drag to the nearest
|
|
265
307
|
* `stepMinutes`. Runs on the UI thread inside the drag gesture. Returns 0 for a
|
|
266
308
|
* degenerate grid (non-positive height/step).
|
|
@@ -806,6 +848,128 @@ function toICalendar(events, options = {}) {
|
|
|
806
848
|
return out.join("\r\n");
|
|
807
849
|
}
|
|
808
850
|
//#endregion
|
|
851
|
+
//#region src/utils/useNow.ts
|
|
852
|
+
const MINUTE_MS = 6e4;
|
|
853
|
+
const resolveNow = (now, timeZone) => {
|
|
854
|
+
const instant = now ?? /* @__PURE__ */ new Date();
|
|
855
|
+
return timeZone ? toZonedTime(instant, timeZone) : instant;
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* The current wall-clock time, re-read every `tickMs` while `enabled`, shifted
|
|
859
|
+
* into `timeZone` when given, or pinned to a fixed `now` override. Drives the
|
|
860
|
+
* now indicator on both renderers so it can't disagree with zone-shifted events.
|
|
861
|
+
*/
|
|
862
|
+
function useNow(enabled, { now, timeZone, tickMs = MINUTE_MS } = {}) {
|
|
863
|
+
const [value, setValue] = (0, react.useState)(() => resolveNow(now, timeZone));
|
|
864
|
+
const nowMs = now?.getTime();
|
|
865
|
+
(0, react.useEffect)(() => {
|
|
866
|
+
if (!enabled) return;
|
|
867
|
+
setValue(resolveNow(nowMs != null ? new Date(nowMs) : void 0, timeZone));
|
|
868
|
+
if (nowMs != null) return;
|
|
869
|
+
const id = setInterval(() => setValue(resolveNow(void 0, timeZone)), tickMs);
|
|
870
|
+
return () => clearInterval(id);
|
|
871
|
+
}, [
|
|
872
|
+
enabled,
|
|
873
|
+
nowMs,
|
|
874
|
+
timeZone,
|
|
875
|
+
tickMs
|
|
876
|
+
]);
|
|
877
|
+
return value;
|
|
878
|
+
}
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/utils/useEventSource.ts
|
|
881
|
+
const defaultMap = (items) => items.map((raw) => {
|
|
882
|
+
const item = raw;
|
|
883
|
+
return {
|
|
884
|
+
...item,
|
|
885
|
+
start: new Date(item.start),
|
|
886
|
+
end: new Date(item.end)
|
|
887
|
+
};
|
|
888
|
+
});
|
|
889
|
+
/**
|
|
890
|
+
* Load events from a refreshable source: a JSON feed URL, an iCalendar feed
|
|
891
|
+
* URL, or your own async function. The hook owns fetching, optional interval
|
|
892
|
+
* refetching, and loading/error state; hand the returned `events` to any view.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```tsx
|
|
896
|
+
* const { events, loading, refetch } = useEventSource(
|
|
897
|
+
* "https://example.com/feed.ics",
|
|
898
|
+
* { refetchIntervalMs: 5 * 60_000 },
|
|
899
|
+
* );
|
|
900
|
+
* <Calendar mode="week" date={date} events={events} onChangeDate={setDate} />;
|
|
901
|
+
* ```
|
|
902
|
+
*/
|
|
903
|
+
function useEventSource(source, { format, map, refetchIntervalMs } = {}) {
|
|
904
|
+
const [events, setEvents] = (0, react.useState)([]);
|
|
905
|
+
const [loading, setLoading] = (0, react.useState)(true);
|
|
906
|
+
const [error, setError] = (0, react.useState)(null);
|
|
907
|
+
const generation = (0, react.useRef)(0);
|
|
908
|
+
const abortRef = (0, react.useRef)(null);
|
|
909
|
+
const latest = (0, react.useRef)({
|
|
910
|
+
source,
|
|
911
|
+
format,
|
|
912
|
+
map
|
|
913
|
+
});
|
|
914
|
+
latest.current = {
|
|
915
|
+
source,
|
|
916
|
+
format,
|
|
917
|
+
map
|
|
918
|
+
};
|
|
919
|
+
const load = (0, react.useCallback)(async (isManual) => {
|
|
920
|
+
const gen = ++generation.current;
|
|
921
|
+
abortRef.current?.abort();
|
|
922
|
+
const controller = typeof AbortController === "undefined" ? null : new AbortController();
|
|
923
|
+
abortRef.current = controller;
|
|
924
|
+
const { source: src, format: fmt, map: mapper } = latest.current;
|
|
925
|
+
if (isManual) setLoading(true);
|
|
926
|
+
try {
|
|
927
|
+
let next;
|
|
928
|
+
if (typeof src === "function") next = await src();
|
|
929
|
+
else {
|
|
930
|
+
const response = await fetch(src, controller ? { signal: controller.signal } : void 0);
|
|
931
|
+
if (!response.ok) throw new Error(`Event source responded ${response.status}`);
|
|
932
|
+
if (fmt === "ics" || fmt == null && /\.ics(\?|$)/.test(src)) next = parseICalendar(await response.text());
|
|
933
|
+
else {
|
|
934
|
+
const body = await response.json();
|
|
935
|
+
next = (mapper ?? defaultMap)(body);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
if (gen !== generation.current) return;
|
|
939
|
+
setEvents(next);
|
|
940
|
+
setError(null);
|
|
941
|
+
} catch (cause) {
|
|
942
|
+
if (gen !== generation.current) return;
|
|
943
|
+
setError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
944
|
+
} finally {
|
|
945
|
+
if (gen === generation.current) setLoading(false);
|
|
946
|
+
}
|
|
947
|
+
}, []);
|
|
948
|
+
(0, react.useEffect)(() => {
|
|
949
|
+
load(true);
|
|
950
|
+
if (!refetchIntervalMs) return () => {
|
|
951
|
+
generation.current++;
|
|
952
|
+
abortRef.current?.abort();
|
|
953
|
+
};
|
|
954
|
+
const id = setInterval(() => void load(false), refetchIntervalMs);
|
|
955
|
+
return () => {
|
|
956
|
+
clearInterval(id);
|
|
957
|
+
generation.current++;
|
|
958
|
+
abortRef.current?.abort();
|
|
959
|
+
};
|
|
960
|
+
}, [
|
|
961
|
+
load,
|
|
962
|
+
typeof source === "string" ? source : "fn",
|
|
963
|
+
refetchIntervalMs
|
|
964
|
+
]);
|
|
965
|
+
return {
|
|
966
|
+
events,
|
|
967
|
+
loading,
|
|
968
|
+
error,
|
|
969
|
+
refetch: (0, react.useCallback)(() => load(true), [load])
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
//#endregion
|
|
809
973
|
//#region src/utils/layout.ts
|
|
810
974
|
const MINUTES_PER_HOUR = 60;
|
|
811
975
|
const MIN_DURATION_HOURS = .25;
|
|
@@ -818,7 +982,7 @@ const MIN_DURATION_HOURS = .25;
|
|
|
818
982
|
function layoutDayEvents(events, day) {
|
|
819
983
|
const dayStart = (0, date_fns.startOfDay)(day);
|
|
820
984
|
const nextDayStart = (0, date_fns.addDays)(dayStart, 1);
|
|
821
|
-
const segments = events.filter((event) => !isAllDayEvent(event)).filter((event) => event.start < nextDayStart && event.end > dayStart).map((event) => {
|
|
985
|
+
const segments = events.filter((event) => !isAllDayEvent(event) && !isBackgroundEvent(event)).filter((event) => event.start < nextDayStart && event.end > dayStart).map((event) => {
|
|
822
986
|
const segStart = (0, date_fns.max)([event.start, dayStart]);
|
|
823
987
|
const segEnd = (0, date_fns.min)([event.end, nextDayStart]);
|
|
824
988
|
return {
|
|
@@ -924,25 +1088,132 @@ function closedHourBands(day, businessHours, minHour = 0, maxHour = 24) {
|
|
|
924
1088
|
start: minHour,
|
|
925
1089
|
end: maxHour
|
|
926
1090
|
}];
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
1091
|
+
const windows = (Array.isArray(open) ? open : [open]).map((w) => ({
|
|
1092
|
+
start: Math.max(minHour, Math.min(maxHour, w.start)),
|
|
1093
|
+
end: Math.max(minHour, Math.min(maxHour, w.end))
|
|
1094
|
+
})).filter((w) => w.end > w.start).sort((a, b) => a.start - b.start);
|
|
1095
|
+
if (windows.length === 0) return [{
|
|
930
1096
|
start: minHour,
|
|
931
1097
|
end: maxHour
|
|
932
1098
|
}];
|
|
1099
|
+
const merged = [];
|
|
1100
|
+
for (const w of windows) {
|
|
1101
|
+
const last = merged[merged.length - 1];
|
|
1102
|
+
if (last && w.start <= last.end) last.end = Math.max(last.end, w.end);
|
|
1103
|
+
else merged.push({ ...w });
|
|
1104
|
+
}
|
|
933
1105
|
const bands = [];
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1106
|
+
let cursor = minHour;
|
|
1107
|
+
for (const w of merged) {
|
|
1108
|
+
if (w.start > cursor) bands.push({
|
|
1109
|
+
start: cursor,
|
|
1110
|
+
end: w.start
|
|
1111
|
+
});
|
|
1112
|
+
cursor = w.end;
|
|
1113
|
+
}
|
|
1114
|
+
if (cursor < maxHour) bands.push({
|
|
1115
|
+
start: cursor,
|
|
940
1116
|
end: maxHour
|
|
941
1117
|
});
|
|
942
1118
|
return bands;
|
|
943
1119
|
}
|
|
1120
|
+
/** True when the event paints as a shaded background band, not an event box. */
|
|
1121
|
+
function isBackgroundEvent(event) {
|
|
1122
|
+
return event.display === "background";
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* The background events of `events` sliced to `day`, as fractional-hour bands
|
|
1126
|
+
* (an all-day or multi-day background covers the day's full window). Shared by
|
|
1127
|
+
* both renderers so the shading can't disagree.
|
|
1128
|
+
*/
|
|
1129
|
+
function backgroundBandsForDay(events, day) {
|
|
1130
|
+
const dayStart = (0, date_fns.startOfDay)(day);
|
|
1131
|
+
const nextDayStart = (0, date_fns.addDays)(dayStart, 1);
|
|
1132
|
+
const out = [];
|
|
1133
|
+
for (const event of events) {
|
|
1134
|
+
if (!isBackgroundEvent(event)) continue;
|
|
1135
|
+
if (event.start >= nextDayStart || event.end <= dayStart) continue;
|
|
1136
|
+
const from = event.start > dayStart ? event.start : dayStart;
|
|
1137
|
+
const to = event.end < nextDayStart ? event.end : nextDayStart;
|
|
1138
|
+
const startHours = (from.getTime() - dayStart.getTime()) / 36e5;
|
|
1139
|
+
const endHours = (to.getTime() - dayStart.getTime()) / 36e5;
|
|
1140
|
+
if (endHours > startHours) out.push({
|
|
1141
|
+
event,
|
|
1142
|
+
startHours,
|
|
1143
|
+
endHours
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
return out;
|
|
1147
|
+
}
|
|
944
1148
|
//#endregion
|
|
945
1149
|
//#region src/utils/monthGrid.ts
|
|
1150
|
+
/** The last calendar day an event visibly covers (a midnight end ends the day before). */
|
|
1151
|
+
function lastCoveredDay(event) {
|
|
1152
|
+
const endMs = event.end.getTime();
|
|
1153
|
+
return (0, date_fns.startOfDay)(new Date(Math.max(event.start.getTime(), endMs - 1))).getTime();
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Lay out one week row's events as continuous horizontal bars: each event becomes
|
|
1157
|
+
* a single segment spanning the columns it covers (not a chip repeated per day),
|
|
1158
|
+
* stacked into lanes so overlapping events sit on separate rows. Multi-day events
|
|
1159
|
+
* that cross the row edges are marked `continuesBefore`/`continuesAfter`. Shared by
|
|
1160
|
+
* both renderers so the month grid draws identical spanning bars.
|
|
1161
|
+
*
|
|
1162
|
+
* Column indices map into the given `days` array in whatever display order it uses,
|
|
1163
|
+
* so this is order-independent: a right-to-left (reversed) week lays out correctly,
|
|
1164
|
+
* and `continuesBefore`/`continuesAfter` track the array's first/last column edge
|
|
1165
|
+
* (not chronology), so the clipped end is squared on the right visual side.
|
|
1166
|
+
*
|
|
1167
|
+
* Lanes are packed greedily after sorting by start column then longest span first,
|
|
1168
|
+
* matching how calendars keep long events on the upper lanes.
|
|
1169
|
+
*/
|
|
1170
|
+
function layoutMonthWeek(days, events) {
|
|
1171
|
+
if (days.length === 0) return {
|
|
1172
|
+
segments: [],
|
|
1173
|
+
laneCount: 0
|
|
1174
|
+
};
|
|
1175
|
+
const dayStarts = days.map((d) => (0, date_fns.startOfDay)(d).getTime());
|
|
1176
|
+
const rowStart = Math.min(...dayStarts);
|
|
1177
|
+
const rowEnd = Math.max(...dayStarts);
|
|
1178
|
+
const ascending = dayStarts[0] <= dayStarts[dayStarts.length - 1];
|
|
1179
|
+
const placed = [];
|
|
1180
|
+
for (const event of events) {
|
|
1181
|
+
const evStart = (0, date_fns.startOfDay)(event.start).getTime();
|
|
1182
|
+
const evLast = lastCoveredDay(event);
|
|
1183
|
+
if (evLast < rowStart || evStart > rowEnd) continue;
|
|
1184
|
+
let startCol = -1;
|
|
1185
|
+
let endCol = -1;
|
|
1186
|
+
for (let i = 0; i < dayStarts.length; i++) if (dayStarts[i] >= evStart && dayStarts[i] <= evLast) {
|
|
1187
|
+
if (startCol === -1) startCol = i;
|
|
1188
|
+
endCol = i;
|
|
1189
|
+
}
|
|
1190
|
+
if (startCol === -1) continue;
|
|
1191
|
+
const startsBefore = evStart < rowStart;
|
|
1192
|
+
const endsAfter = evLast > rowEnd;
|
|
1193
|
+
placed.push({
|
|
1194
|
+
event,
|
|
1195
|
+
startCol,
|
|
1196
|
+
endCol,
|
|
1197
|
+
lane: 0,
|
|
1198
|
+
continuesBefore: ascending ? startsBefore : endsAfter,
|
|
1199
|
+
continuesAfter: ascending ? endsAfter : startsBefore
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
placed.sort((a, b) => a.startCol - b.startCol || b.endCol - b.startCol - (a.endCol - a.startCol));
|
|
1203
|
+
const laneEnds = [];
|
|
1204
|
+
for (const seg of placed) {
|
|
1205
|
+
let lane = laneEnds.findIndex((end) => end < seg.startCol);
|
|
1206
|
+
if (lane === -1) {
|
|
1207
|
+
lane = laneEnds.length;
|
|
1208
|
+
laneEnds.push(seg.endCol);
|
|
1209
|
+
} else laneEnds[lane] = seg.endCol;
|
|
1210
|
+
seg.lane = lane;
|
|
1211
|
+
}
|
|
1212
|
+
return {
|
|
1213
|
+
segments: placed,
|
|
1214
|
+
laneCount: laneEnds.length
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
946
1217
|
/** date-fns tokens for each {@link WeekdayFormat}. */
|
|
947
1218
|
const WEEKDAY_TOKENS = {
|
|
948
1219
|
narrow: "EEEEE",
|
|
@@ -963,31 +1234,37 @@ function weekdayFormatToken(format) {
|
|
|
963
1234
|
* data outside React; inside a component prefer {@link useMonthGrid}.
|
|
964
1235
|
*/
|
|
965
1236
|
function buildMonthGrid(month, options = {}) {
|
|
966
|
-
const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
|
|
1237
|
+
const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
|
|
967
1238
|
const rows = buildMonthWeeks(month, weekStartsOn, {
|
|
968
1239
|
showSixWeeks,
|
|
969
|
-
isRTL
|
|
1240
|
+
isRTL,
|
|
1241
|
+
hiddenDays
|
|
970
1242
|
});
|
|
1243
|
+
const weeks = rows.map((days) => ({
|
|
1244
|
+
id: days[0].toISOString(),
|
|
1245
|
+
days: days.map((date) => ({
|
|
1246
|
+
date,
|
|
1247
|
+
id: (0, date_fns.format)(date, "yyyy-MM-dd"),
|
|
1248
|
+
label: (0, date_fns.format)(date, "d"),
|
|
1249
|
+
isCurrentMonth: (0, date_fns.isSameMonth)(date, month),
|
|
1250
|
+
isToday: getIsToday(date),
|
|
1251
|
+
isWeekend: isWeekend(date),
|
|
1252
|
+
...daySelectionState(date, {
|
|
1253
|
+
selectedDates,
|
|
1254
|
+
selectedRange
|
|
1255
|
+
}, {
|
|
1256
|
+
minDate,
|
|
1257
|
+
maxDate,
|
|
1258
|
+
isDateDisabled
|
|
1259
|
+
})
|
|
1260
|
+
}))
|
|
1261
|
+
}));
|
|
1262
|
+
if (rows.length === 0) return {
|
|
1263
|
+
weeks: [],
|
|
1264
|
+
weekdays: []
|
|
1265
|
+
};
|
|
971
1266
|
return {
|
|
972
|
-
weeks
|
|
973
|
-
id: days[0].toISOString(),
|
|
974
|
-
days: days.map((date) => ({
|
|
975
|
-
date,
|
|
976
|
-
id: (0, date_fns.format)(date, "yyyy-MM-dd"),
|
|
977
|
-
label: (0, date_fns.format)(date, "d"),
|
|
978
|
-
isCurrentMonth: (0, date_fns.isSameMonth)(date, month),
|
|
979
|
-
isToday: getIsToday(date),
|
|
980
|
-
isWeekend: isWeekend(date),
|
|
981
|
-
...daySelectionState(date, {
|
|
982
|
-
selectedDates,
|
|
983
|
-
selectedRange
|
|
984
|
-
}, {
|
|
985
|
-
minDate,
|
|
986
|
-
maxDate,
|
|
987
|
-
isDateDisabled
|
|
988
|
-
})
|
|
989
|
-
}))
|
|
990
|
-
})),
|
|
1267
|
+
weeks,
|
|
991
1268
|
weekdays: rows[0].map((date) => ({
|
|
992
1269
|
date,
|
|
993
1270
|
label: (0, date_fns.format)(date, WEEKDAY_TOKENS[weekdayFormat], { locale })
|
|
@@ -1181,7 +1458,10 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
|
|
|
1181
1458
|
}
|
|
1182
1459
|
const durationMs = event.end.getTime() - event.start.getTime();
|
|
1183
1460
|
const dayKey = (d) => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
|
1184
|
-
const
|
|
1461
|
+
const excludedDays = /* @__PURE__ */ new Set();
|
|
1462
|
+
const excludedInstants = /* @__PURE__ */ new Set();
|
|
1463
|
+
for (const exdate of event.recurrence.exdates ?? []) if (exdate.getHours() === 0 && exdate.getMinutes() === 0 && exdate.getSeconds() === 0 && exdate.getMilliseconds() === 0) excludedDays.add(dayKey(exdate));
|
|
1464
|
+
else excludedInstants.add(exdate.getTime());
|
|
1185
1465
|
const starts = /* @__PURE__ */ new Map();
|
|
1186
1466
|
const earliestStart = new Date(rangeStart.getTime() - durationMs);
|
|
1187
1467
|
for (const start of occurrenceStarts(event.start, event.recurrence, earliestStart, rangeEnd)) starts.set(start.getTime(), start);
|
|
@@ -1189,7 +1469,7 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
|
|
|
1189
1469
|
const ordered = [...starts.values()].sort((a, b) => a.getTime() - b.getTime());
|
|
1190
1470
|
for (const start of ordered) {
|
|
1191
1471
|
if (start.getTime() + durationMs < rangeStart.getTime()) continue;
|
|
1192
|
-
if (
|
|
1472
|
+
if (excludedDays.has(dayKey(start)) || excludedInstants.has(start.getTime())) continue;
|
|
1193
1473
|
out.push(instanceAt(event, start, durationMs));
|
|
1194
1474
|
}
|
|
1195
1475
|
}
|
|
@@ -1198,6 +1478,7 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
|
|
|
1198
1478
|
//#endregion
|
|
1199
1479
|
exports.CalendarSelectionProvider = CalendarSelectionProvider;
|
|
1200
1480
|
exports.MIN_BOX_HEIGHT_FOR_TIME = MIN_BOX_HEIGHT_FOR_TIME;
|
|
1481
|
+
exports.backgroundBandsForDay = backgroundBandsForDay;
|
|
1201
1482
|
exports.bandRounding = bandRounding;
|
|
1202
1483
|
exports.buildMonthGrid = buildMonthGrid;
|
|
1203
1484
|
exports.buildMonthWeeks = buildMonthWeeks;
|
|
@@ -1212,7 +1493,9 @@ exports.eventChipLayout = eventChipLayout;
|
|
|
1212
1493
|
exports.eventDayKeys = eventDayKeys;
|
|
1213
1494
|
exports.eventTimeLabel = eventTimeLabel;
|
|
1214
1495
|
exports.eventsInTimeZone = eventsInTimeZone;
|
|
1496
|
+
exports.eventsOverlap = eventsOverlap;
|
|
1215
1497
|
exports.expandRecurringEvents = expandRecurringEvents;
|
|
1498
|
+
exports.filterHiddenDays = filterHiddenDays;
|
|
1216
1499
|
exports.formatHour = formatHour;
|
|
1217
1500
|
exports.getIsToday = getIsToday;
|
|
1218
1501
|
exports.getViewDays = getViewDays;
|
|
@@ -1220,6 +1503,7 @@ exports.getWeekDays = getWeekDays;
|
|
|
1220
1503
|
exports.getYearMonths = getYearMonths;
|
|
1221
1504
|
exports.groupEventsByDay = groupEventsByDay;
|
|
1222
1505
|
exports.isAllDayEvent = isAllDayEvent;
|
|
1506
|
+
exports.isBackgroundEvent = isBackgroundEvent;
|
|
1223
1507
|
exports.isDateSelectable = isDateSelectable;
|
|
1224
1508
|
exports.isRangeEndpoint = isRangeEndpoint;
|
|
1225
1509
|
exports.isSameCalendarDay = isSameCalendarDay;
|
|
@@ -1227,11 +1511,14 @@ exports.isTimeVisibleAtHeight = isTimeVisibleAtHeight;
|
|
|
1227
1511
|
exports.isWeekend = isWeekend;
|
|
1228
1512
|
exports.isWithinDateRange = isWithinDateRange;
|
|
1229
1513
|
exports.layoutDayEvents = layoutDayEvents;
|
|
1514
|
+
exports.layoutMonthWeek = layoutMonthWeek;
|
|
1230
1515
|
exports.lightColors = lightColors;
|
|
1231
1516
|
exports.minutesIntoDay = minutesIntoDay;
|
|
1232
1517
|
exports.monthEventCapacity = monthEventCapacity;
|
|
1233
1518
|
exports.monthVisibleCount = monthVisibleCount;
|
|
1234
1519
|
exports.nextDateRange = nextDateRange;
|
|
1520
|
+
exports.overlapsOtherEvents = overlapsOtherEvents;
|
|
1521
|
+
exports.pageStepDays = pageStepDays;
|
|
1235
1522
|
exports.parseICalendar = parseICalendar;
|
|
1236
1523
|
exports.rangeBandKind = rangeBandKind;
|
|
1237
1524
|
exports.resolveDraggedBounds = resolveDraggedBounds;
|
|
@@ -1243,7 +1530,9 @@ exports.toICalendar = toICalendar;
|
|
|
1243
1530
|
exports.toZonedTime = toZonedTime;
|
|
1244
1531
|
exports.useCalendarSelection = useCalendarSelection;
|
|
1245
1532
|
exports.useDateRange = useDateRange;
|
|
1533
|
+
exports.useEventSource = useEventSource;
|
|
1246
1534
|
exports.useMonthGrid = useMonthGrid;
|
|
1535
|
+
exports.useNow = useNow;
|
|
1247
1536
|
exports.viewDayCount = viewDayCount;
|
|
1248
1537
|
exports.weekDaysCount = weekDaysCount;
|
|
1249
1538
|
exports.weekdayFormatToken = weekdayFormatToken;
|