@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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { addDays, addMonths, addWeeks, addYears, differenceInMinutes, eachDayOfInterval, endOfMonth, endOfWeek, format, getHours, getMinutes, isAfter, isBefore, isSameDay, isSameMonth, isToday, max, min, startOfDay, startOfMonth, startOfWeek } from "date-fns";
2
- import { createContext, useCallback, useContext, useMemo, useState } from "react";
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
3
  //#region src/tokens.ts
4
4
  /** The default light-theme colour palette. */
5
5
  const lightColors = {
@@ -18,7 +18,8 @@ const lightColors = {
18
18
  textMuted: "#6B7280",
19
19
  textDisabled: "#B5B9C0",
20
20
  eventBackground: "#DCE7FF",
21
- eventText: "#1A1B1E"
21
+ eventText: "#1A1B1E",
22
+ backgroundEvent: "#E3F4E4"
22
23
  };
23
24
  /** The default dark-theme colour palette. */
24
25
  const darkColors = {
@@ -37,7 +38,8 @@ const darkColors = {
37
38
  textMuted: "#9BA1A6",
38
39
  textDisabled: "#4B4F58",
39
40
  eventBackground: "#243B53",
40
- eventText: "#EAF2FF"
41
+ eventText: "#EAF2FF",
42
+ backgroundEvent: "#17301F"
41
43
  };
42
44
  //#endregion
43
45
  //#region src/presentation.ts
@@ -105,14 +107,23 @@ const weekDaysCount = (weekStartsOn, weekEndsOn) => {
105
107
  * from `weekStartsOn` to `weekEndsOn` (anchored to `date`'s week, paging by week);
106
108
  * otherwise every mode shows `viewDayCount` consecutive days starting at `date`.
107
109
  */
108
- const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false, weekEndsOn) => {
110
+ const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false, weekEndsOn, hiddenDays) => {
111
+ const hidden = hiddenDays && hiddenDays.length > 0 && hiddenDays.length < 7 ? hiddenDays : [];
109
112
  let days;
110
- if (mode === "week") days = getWeekDays(date, weekStartsOn);
113
+ if (mode === "week") days = filterHiddenDays(getWeekDays(date, weekStartsOn), hidden);
111
114
  else if (mode === "custom" && weekEndsOn != null) {
112
115
  const subject = startOfDay(date);
113
116
  const offset = weekStartsOn - subject.getDay();
114
- days = Array.from({ length: weekDaysCount(weekStartsOn, weekEndsOn) }, (_, index) => addDays(subject, index + offset));
115
- } else days = Array.from({ length: viewDayCount(mode, numberOfDays) }, (_, index) => addDays(startOfDay(date), index));
117
+ days = filterHiddenDays(Array.from({ length: weekDaysCount(weekStartsOn, weekEndsOn) }, (_, index) => addDays(subject, index + offset)), hidden);
118
+ } else {
119
+ const count = viewDayCount(mode, numberOfDays);
120
+ days = [];
121
+ let cursor = startOfDay(date);
122
+ while (days.length < count) {
123
+ if (!hidden.includes(cursor.getDay())) days.push(cursor);
124
+ cursor = addDays(cursor, 1);
125
+ }
126
+ }
116
127
  return isRTL ? days.reverse() : days;
117
128
  };
118
129
  /**
@@ -120,7 +131,7 @@ const getViewDays = (mode, date, weekStartsOn, numberOfDays = 1, isRTL = false,
120
131
  * `weekStartsOn`. `showSixWeeks` always returns six rows (42 days) for a
121
132
  * fixed-height grid; `isRTL` reverses each week's day order.
122
133
  */
123
- const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = false } = {}) => {
134
+ const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = false, hiddenDays } = {}) => {
124
135
  const start = startOfWeek(startOfMonth(month), { weekStartsOn });
125
136
  const days = eachDayOfInterval({
126
137
  start,
@@ -128,11 +139,17 @@ const buildMonthWeeks = (month, weekStartsOn, { showSixWeeks = false, isRTL = fa
128
139
  });
129
140
  const weeks = [];
130
141
  for (let index = 0; index < days.length; index += 7) {
131
- const week = days.slice(index, index + 7);
132
- weeks.push(isRTL ? week.reverse() : week);
142
+ const week = filterHiddenDays(days.slice(index, index + 7), hiddenDays);
143
+ if (week.length > 0) weeks.push(isRTL ? week.reverse() : week);
133
144
  }
134
145
  return weeks;
135
146
  };
147
+ /**
148
+ * Drop the days whose weekday (0=Sunday…6=Saturday) is listed in `hiddenDays`.
149
+ * Hiding all seven weekdays is treated as hiding nothing (matching
150
+ * `getViewDays`), so a misconfiguration degrades to the full grid, not a blank.
151
+ */
152
+ const filterHiddenDays = (days, hiddenDays) => hiddenDays && hiddenDays.length > 0 && new Set(hiddenDays).size < 7 ? days.filter((day) => !hiddenDays.includes(day.getDay())) : days;
136
153
  /** True when `date` is a Saturday or Sunday. */
137
154
  const isWeekend = (date) => {
138
155
  const day = date.getDay();
@@ -260,6 +277,31 @@ function useDateRange(options = {}) {
260
277
  //#endregion
261
278
  //#region src/utils/drag.ts
262
279
  /**
280
+ * True when two time ranges overlap. Edges touching (one ends exactly when the
281
+ * next begins) do not count as an overlap. Compares absolute instants, so events
282
+ * at the same wall-clock time on different days do not overlap.
283
+ */
284
+ function eventsOverlap(aStart, aEnd, bStart, bEnd) {
285
+ return aStart.getTime() < bEnd.getTime() && bStart.getTime() < aEnd.getTime();
286
+ }
287
+ /**
288
+ * True when the range `[start, end)` would overlap any event in `events` other
289
+ * than `moved` (compared by reference). Used by the `eventOverlap` guard to reject
290
+ * a drag/resize that would land an event on top of another.
291
+ */
292
+ function overlapsOtherEvents(events, moved, start, end) {
293
+ return events.some((e) => e !== moved && eventsOverlap(e.start, e.end, start, end));
294
+ }
295
+ /**
296
+ * How many calendar days one time-grid page spans, used to advance the view by a
297
+ * whole page (e.g. when dragging an event past the edge into the next week).
298
+ * Deliberately ignores `hiddenDays` so a week always steps 7, matching the
299
+ * keyboard PageUp/PageDown paging and `Calendar`'s own page step.
300
+ */
301
+ function pageStepDays(mode, date, weekStartsOn, numberOfDays = 1) {
302
+ return getViewDays(mode, date, weekStartsOn, numberOfDays).length;
303
+ }
304
+ /**
263
305
  * Minutes to shift an event, snapping a vertical pixel drag to the nearest
264
306
  * `stepMinutes`. Runs on the UI thread inside the drag gesture. Returns 0 for a
265
307
  * degenerate grid (non-positive height/step).
@@ -805,6 +847,128 @@ function toICalendar(events, options = {}) {
805
847
  return out.join("\r\n");
806
848
  }
807
849
  //#endregion
850
+ //#region src/utils/useNow.ts
851
+ const MINUTE_MS = 6e4;
852
+ const resolveNow = (now, timeZone) => {
853
+ const instant = now ?? /* @__PURE__ */ new Date();
854
+ return timeZone ? toZonedTime(instant, timeZone) : instant;
855
+ };
856
+ /**
857
+ * The current wall-clock time, re-read every `tickMs` while `enabled`, shifted
858
+ * into `timeZone` when given, or pinned to a fixed `now` override. Drives the
859
+ * now indicator on both renderers so it can't disagree with zone-shifted events.
860
+ */
861
+ function useNow(enabled, { now, timeZone, tickMs = MINUTE_MS } = {}) {
862
+ const [value, setValue] = useState(() => resolveNow(now, timeZone));
863
+ const nowMs = now?.getTime();
864
+ useEffect(() => {
865
+ if (!enabled) return;
866
+ setValue(resolveNow(nowMs != null ? new Date(nowMs) : void 0, timeZone));
867
+ if (nowMs != null) return;
868
+ const id = setInterval(() => setValue(resolveNow(void 0, timeZone)), tickMs);
869
+ return () => clearInterval(id);
870
+ }, [
871
+ enabled,
872
+ nowMs,
873
+ timeZone,
874
+ tickMs
875
+ ]);
876
+ return value;
877
+ }
878
+ //#endregion
879
+ //#region src/utils/useEventSource.ts
880
+ const defaultMap = (items) => items.map((raw) => {
881
+ const item = raw;
882
+ return {
883
+ ...item,
884
+ start: new Date(item.start),
885
+ end: new Date(item.end)
886
+ };
887
+ });
888
+ /**
889
+ * Load events from a refreshable source: a JSON feed URL, an iCalendar feed
890
+ * URL, or your own async function. The hook owns fetching, optional interval
891
+ * refetching, and loading/error state; hand the returned `events` to any view.
892
+ *
893
+ * @example
894
+ * ```tsx
895
+ * const { events, loading, refetch } = useEventSource(
896
+ * "https://example.com/feed.ics",
897
+ * { refetchIntervalMs: 5 * 60_000 },
898
+ * );
899
+ * <Calendar mode="week" date={date} events={events} onChangeDate={setDate} />;
900
+ * ```
901
+ */
902
+ function useEventSource(source, { format, map, refetchIntervalMs } = {}) {
903
+ const [events, setEvents] = useState([]);
904
+ const [loading, setLoading] = useState(true);
905
+ const [error, setError] = useState(null);
906
+ const generation = useRef(0);
907
+ const abortRef = useRef(null);
908
+ const latest = useRef({
909
+ source,
910
+ format,
911
+ map
912
+ });
913
+ latest.current = {
914
+ source,
915
+ format,
916
+ map
917
+ };
918
+ const load = useCallback(async (isManual) => {
919
+ const gen = ++generation.current;
920
+ abortRef.current?.abort();
921
+ const controller = typeof AbortController === "undefined" ? null : new AbortController();
922
+ abortRef.current = controller;
923
+ const { source: src, format: fmt, map: mapper } = latest.current;
924
+ if (isManual) setLoading(true);
925
+ try {
926
+ let next;
927
+ if (typeof src === "function") next = await src();
928
+ else {
929
+ const response = await fetch(src, controller ? { signal: controller.signal } : void 0);
930
+ if (!response.ok) throw new Error(`Event source responded ${response.status}`);
931
+ if (fmt === "ics" || fmt == null && /\.ics(\?|$)/.test(src)) next = parseICalendar(await response.text());
932
+ else {
933
+ const body = await response.json();
934
+ next = (mapper ?? defaultMap)(body);
935
+ }
936
+ }
937
+ if (gen !== generation.current) return;
938
+ setEvents(next);
939
+ setError(null);
940
+ } catch (cause) {
941
+ if (gen !== generation.current) return;
942
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
943
+ } finally {
944
+ if (gen === generation.current) setLoading(false);
945
+ }
946
+ }, []);
947
+ useEffect(() => {
948
+ load(true);
949
+ if (!refetchIntervalMs) return () => {
950
+ generation.current++;
951
+ abortRef.current?.abort();
952
+ };
953
+ const id = setInterval(() => void load(false), refetchIntervalMs);
954
+ return () => {
955
+ clearInterval(id);
956
+ generation.current++;
957
+ abortRef.current?.abort();
958
+ };
959
+ }, [
960
+ load,
961
+ typeof source === "string" ? source : "fn",
962
+ refetchIntervalMs
963
+ ]);
964
+ return {
965
+ events,
966
+ loading,
967
+ error,
968
+ refetch: useCallback(() => load(true), [load])
969
+ };
970
+ }
971
+ //#endregion
808
972
  //#region src/utils/layout.ts
809
973
  const MINUTES_PER_HOUR = 60;
810
974
  const MIN_DURATION_HOURS = .25;
@@ -817,7 +981,7 @@ const MIN_DURATION_HOURS = .25;
817
981
  function layoutDayEvents(events, day) {
818
982
  const dayStart = startOfDay(day);
819
983
  const nextDayStart = addDays(dayStart, 1);
820
- const segments = events.filter((event) => !isAllDayEvent(event)).filter((event) => event.start < nextDayStart && event.end > dayStart).map((event) => {
984
+ const segments = events.filter((event) => !isAllDayEvent(event) && !isBackgroundEvent(event)).filter((event) => event.start < nextDayStart && event.end > dayStart).map((event) => {
821
985
  const segStart = max([event.start, dayStart]);
822
986
  const segEnd = min([event.end, nextDayStart]);
823
987
  return {
@@ -923,25 +1087,132 @@ function closedHourBands(day, businessHours, minHour = 0, maxHour = 24) {
923
1087
  start: minHour,
924
1088
  end: maxHour
925
1089
  }];
926
- const start = Math.max(minHour, Math.min(maxHour, open.start));
927
- const end = Math.max(minHour, Math.min(maxHour, open.end));
928
- if (start >= end) return [{
1090
+ const windows = (Array.isArray(open) ? open : [open]).map((w) => ({
1091
+ start: Math.max(minHour, Math.min(maxHour, w.start)),
1092
+ end: Math.max(minHour, Math.min(maxHour, w.end))
1093
+ })).filter((w) => w.end > w.start).sort((a, b) => a.start - b.start);
1094
+ if (windows.length === 0) return [{
929
1095
  start: minHour,
930
1096
  end: maxHour
931
1097
  }];
1098
+ const merged = [];
1099
+ for (const w of windows) {
1100
+ const last = merged[merged.length - 1];
1101
+ if (last && w.start <= last.end) last.end = Math.max(last.end, w.end);
1102
+ else merged.push({ ...w });
1103
+ }
932
1104
  const bands = [];
933
- if (start > minHour) bands.push({
934
- start: minHour,
935
- end: start
936
- });
937
- if (end < maxHour) bands.push({
938
- start: end,
1105
+ let cursor = minHour;
1106
+ for (const w of merged) {
1107
+ if (w.start > cursor) bands.push({
1108
+ start: cursor,
1109
+ end: w.start
1110
+ });
1111
+ cursor = w.end;
1112
+ }
1113
+ if (cursor < maxHour) bands.push({
1114
+ start: cursor,
939
1115
  end: maxHour
940
1116
  });
941
1117
  return bands;
942
1118
  }
1119
+ /** True when the event paints as a shaded background band, not an event box. */
1120
+ function isBackgroundEvent(event) {
1121
+ return event.display === "background";
1122
+ }
1123
+ /**
1124
+ * The background events of `events` sliced to `day`, as fractional-hour bands
1125
+ * (an all-day or multi-day background covers the day's full window). Shared by
1126
+ * both renderers so the shading can't disagree.
1127
+ */
1128
+ function backgroundBandsForDay(events, day) {
1129
+ const dayStart = startOfDay(day);
1130
+ const nextDayStart = addDays(dayStart, 1);
1131
+ const out = [];
1132
+ for (const event of events) {
1133
+ if (!isBackgroundEvent(event)) continue;
1134
+ if (event.start >= nextDayStart || event.end <= dayStart) continue;
1135
+ const from = event.start > dayStart ? event.start : dayStart;
1136
+ const to = event.end < nextDayStart ? event.end : nextDayStart;
1137
+ const startHours = (from.getTime() - dayStart.getTime()) / 36e5;
1138
+ const endHours = (to.getTime() - dayStart.getTime()) / 36e5;
1139
+ if (endHours > startHours) out.push({
1140
+ event,
1141
+ startHours,
1142
+ endHours
1143
+ });
1144
+ }
1145
+ return out;
1146
+ }
943
1147
  //#endregion
944
1148
  //#region src/utils/monthGrid.ts
1149
+ /** The last calendar day an event visibly covers (a midnight end ends the day before). */
1150
+ function lastCoveredDay(event) {
1151
+ const endMs = event.end.getTime();
1152
+ return startOfDay(new Date(Math.max(event.start.getTime(), endMs - 1))).getTime();
1153
+ }
1154
+ /**
1155
+ * Lay out one week row's events as continuous horizontal bars: each event becomes
1156
+ * a single segment spanning the columns it covers (not a chip repeated per day),
1157
+ * stacked into lanes so overlapping events sit on separate rows. Multi-day events
1158
+ * that cross the row edges are marked `continuesBefore`/`continuesAfter`. Shared by
1159
+ * both renderers so the month grid draws identical spanning bars.
1160
+ *
1161
+ * Column indices map into the given `days` array in whatever display order it uses,
1162
+ * so this is order-independent: a right-to-left (reversed) week lays out correctly,
1163
+ * and `continuesBefore`/`continuesAfter` track the array's first/last column edge
1164
+ * (not chronology), so the clipped end is squared on the right visual side.
1165
+ *
1166
+ * Lanes are packed greedily after sorting by start column then longest span first,
1167
+ * matching how calendars keep long events on the upper lanes.
1168
+ */
1169
+ function layoutMonthWeek(days, events) {
1170
+ if (days.length === 0) return {
1171
+ segments: [],
1172
+ laneCount: 0
1173
+ };
1174
+ const dayStarts = days.map((d) => startOfDay(d).getTime());
1175
+ const rowStart = Math.min(...dayStarts);
1176
+ const rowEnd = Math.max(...dayStarts);
1177
+ const ascending = dayStarts[0] <= dayStarts[dayStarts.length - 1];
1178
+ const placed = [];
1179
+ for (const event of events) {
1180
+ const evStart = startOfDay(event.start).getTime();
1181
+ const evLast = lastCoveredDay(event);
1182
+ if (evLast < rowStart || evStart > rowEnd) continue;
1183
+ let startCol = -1;
1184
+ let endCol = -1;
1185
+ for (let i = 0; i < dayStarts.length; i++) if (dayStarts[i] >= evStart && dayStarts[i] <= evLast) {
1186
+ if (startCol === -1) startCol = i;
1187
+ endCol = i;
1188
+ }
1189
+ if (startCol === -1) continue;
1190
+ const startsBefore = evStart < rowStart;
1191
+ const endsAfter = evLast > rowEnd;
1192
+ placed.push({
1193
+ event,
1194
+ startCol,
1195
+ endCol,
1196
+ lane: 0,
1197
+ continuesBefore: ascending ? startsBefore : endsAfter,
1198
+ continuesAfter: ascending ? endsAfter : startsBefore
1199
+ });
1200
+ }
1201
+ placed.sort((a, b) => a.startCol - b.startCol || b.endCol - b.startCol - (a.endCol - a.startCol));
1202
+ const laneEnds = [];
1203
+ for (const seg of placed) {
1204
+ let lane = laneEnds.findIndex((end) => end < seg.startCol);
1205
+ if (lane === -1) {
1206
+ lane = laneEnds.length;
1207
+ laneEnds.push(seg.endCol);
1208
+ } else laneEnds[lane] = seg.endCol;
1209
+ seg.lane = lane;
1210
+ }
1211
+ return {
1212
+ segments: placed,
1213
+ laneCount: laneEnds.length
1214
+ };
1215
+ }
945
1216
  /** date-fns tokens for each {@link WeekdayFormat}. */
946
1217
  const WEEKDAY_TOKENS = {
947
1218
  narrow: "EEEEE",
@@ -962,31 +1233,37 @@ function weekdayFormatToken(format) {
962
1233
  * data outside React; inside a component prefer {@link useMonthGrid}.
963
1234
  */
964
1235
  function buildMonthGrid(month, options = {}) {
965
- const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
1236
+ const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
966
1237
  const rows = buildMonthWeeks(month, weekStartsOn, {
967
1238
  showSixWeeks,
968
- isRTL
1239
+ isRTL,
1240
+ hiddenDays
969
1241
  });
1242
+ const weeks = rows.map((days) => ({
1243
+ id: days[0].toISOString(),
1244
+ days: days.map((date) => ({
1245
+ date,
1246
+ id: format(date, "yyyy-MM-dd"),
1247
+ label: format(date, "d"),
1248
+ isCurrentMonth: isSameMonth(date, month),
1249
+ isToday: getIsToday(date),
1250
+ isWeekend: isWeekend(date),
1251
+ ...daySelectionState(date, {
1252
+ selectedDates,
1253
+ selectedRange
1254
+ }, {
1255
+ minDate,
1256
+ maxDate,
1257
+ isDateDisabled
1258
+ })
1259
+ }))
1260
+ }));
1261
+ if (rows.length === 0) return {
1262
+ weeks: [],
1263
+ weekdays: []
1264
+ };
970
1265
  return {
971
- weeks: rows.map((days) => ({
972
- id: days[0].toISOString(),
973
- days: days.map((date) => ({
974
- date,
975
- id: format(date, "yyyy-MM-dd"),
976
- label: format(date, "d"),
977
- isCurrentMonth: isSameMonth(date, month),
978
- isToday: getIsToday(date),
979
- isWeekend: isWeekend(date),
980
- ...daySelectionState(date, {
981
- selectedDates,
982
- selectedRange
983
- }, {
984
- minDate,
985
- maxDate,
986
- isDateDisabled
987
- })
988
- }))
989
- })),
1266
+ weeks,
990
1267
  weekdays: rows[0].map((date) => ({
991
1268
  date,
992
1269
  label: format(date, WEEKDAY_TOKENS[weekdayFormat], { locale })
@@ -1180,7 +1457,10 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
1180
1457
  }
1181
1458
  const durationMs = event.end.getTime() - event.start.getTime();
1182
1459
  const dayKey = (d) => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
1183
- const excluded = new Set((event.recurrence.exdates ?? []).map(dayKey));
1460
+ const excludedDays = /* @__PURE__ */ new Set();
1461
+ const excludedInstants = /* @__PURE__ */ new Set();
1462
+ for (const exdate of event.recurrence.exdates ?? []) if (exdate.getHours() === 0 && exdate.getMinutes() === 0 && exdate.getSeconds() === 0 && exdate.getMilliseconds() === 0) excludedDays.add(dayKey(exdate));
1463
+ else excludedInstants.add(exdate.getTime());
1184
1464
  const starts = /* @__PURE__ */ new Map();
1185
1465
  const earliestStart = new Date(rangeStart.getTime() - durationMs);
1186
1466
  for (const start of occurrenceStarts(event.start, event.recurrence, earliestStart, rangeEnd)) starts.set(start.getTime(), start);
@@ -1188,11 +1468,11 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
1188
1468
  const ordered = [...starts.values()].sort((a, b) => a.getTime() - b.getTime());
1189
1469
  for (const start of ordered) {
1190
1470
  if (start.getTime() + durationMs < rangeStart.getTime()) continue;
1191
- if (excluded.has(dayKey(start))) continue;
1471
+ if (excludedDays.has(dayKey(start)) || excludedInstants.has(start.getTime())) continue;
1192
1472
  out.push(instanceAt(event, start, durationMs));
1193
1473
  }
1194
1474
  }
1195
1475
  return out;
1196
1476
  }
1197
1477
  //#endregion
1198
- export { CalendarSelectionProvider, MIN_BOX_HEIGHT_FOR_TIME, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useMonthGrid, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
1478
+ export { CalendarSelectionProvider, MIN_BOX_HEIGHT_FOR_TIME, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useEventSource, useMonthGrid, useNow, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/core",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "Render-agnostic core for super-calendar: date math, selection model, event layout, the month-grid builder, headless hooks, and neutral theme tokens. No renderer.",
5
5
  "keywords": [
6
6
  "calendar",
package/src/index.ts CHANGED
@@ -24,6 +24,8 @@ export * from "./utils/dates";
24
24
  export * from "./utils/drag";
25
25
  export * from "./utils/eventDisplay";
26
26
  export * from "./utils/ical";
27
+ export * from "./utils/useNow";
28
+ export * from "./utils/useEventSource";
27
29
  export * from "./utils/layout";
28
30
  export * from "./utils/monthGrid";
29
31
  export * from "./utils/recurrence";
package/src/tokens.ts CHANGED
@@ -37,6 +37,8 @@ export interface CalendarColors {
37
37
  eventBackground: string;
38
38
  /** Default event chip text. */
39
39
  eventText: string;
40
+ /** Shaded band behind a `display: "background"` event. */
41
+ backgroundEvent: string;
40
42
  }
41
43
 
42
44
  /** The default light-theme colour palette. */
@@ -57,6 +59,7 @@ export const lightColors: CalendarColors = {
57
59
  textDisabled: "#B5B9C0",
58
60
  eventBackground: "#DCE7FF",
59
61
  eventText: "#1A1B1E",
62
+ backgroundEvent: "#E3F4E4",
60
63
  };
61
64
 
62
65
  /** The default dark-theme colour palette. */
@@ -77,4 +80,5 @@ export const darkColors: CalendarColors = {
77
80
  textDisabled: "#4B4F58",
78
81
  eventBackground: "#243B53",
79
82
  eventText: "#EAF2FF",
83
+ backgroundEvent: "#17301F",
80
84
  };
package/src/types.ts CHANGED
@@ -25,6 +25,35 @@ export interface ICalendarEvent {
25
25
  allDay?: boolean;
26
26
  /** Ignore taps/long-presses on this event (the built-in renderer also dims it). */
27
27
  disabled?: boolean;
28
+ /**
29
+ * Whether this event can be dragged to move or resize. Defaults to `true`, so
30
+ * enabling drag with `onDragEvent` makes every event movable. Set `false` to
31
+ * lock a specific event (a confirmed booking, someone else's event): it keeps
32
+ * its normal look and still responds to taps, it just can't be picked up. Use
33
+ * this for events that can *never* move; to reject a move only for certain
34
+ * targets (an overlap, an out-of-bounds slot), return `false` from `onDragEvent`
35
+ * instead so the event drags and snaps back.
36
+ */
37
+ draggable?: boolean;
38
+ /**
39
+ * Whether this event can be moved (dragged to a new time/day). Defaults to the
40
+ * grid's `eventStartEditable` (itself `true`). Set `false` to allow only resize.
41
+ * A `draggable: false` event ignores this (it can neither move nor resize).
42
+ */
43
+ startEditable?: boolean;
44
+ /**
45
+ * Whether this event can be resized (its start or end edge dragged). Defaults to
46
+ * the grid's `eventDurationEditable` (itself `true`). Set `false` to allow only
47
+ * move. A `draggable: false` event ignores this (it can neither move nor resize).
48
+ */
49
+ durationEditable?: boolean;
50
+ /**
51
+ * How the event renders. `"auto"` (default) is a normal event box/chip;
52
+ * `"background"` paints the event's time range as a non-interactive shaded
53
+ * band behind the grid instead (blocked time, holidays). Background events
54
+ * are excluded from chips, the agenda, and year-view dots.
55
+ */
56
+ display?: "auto" | "background";
28
57
  /**
29
58
  * Repeat rule. Pass the event to `expandRecurringEvents(events, start, end)` to
30
59
  * materialise its occurrences within a range; the calendar itself doesn't
@@ -73,8 +102,11 @@ export interface RecurrenceRule {
73
102
  */
74
103
  months?: number[];
75
104
  /**
76
- * Dates to skip (exceptions). An occurrence whose day matches one of these is
77
- * dropped by `expandRecurringEvents`. Maps to iCal `EXDATE`.
105
+ * Dates to skip (exceptions), dropped by `expandRecurringEvents`. A date at
106
+ * local midnight drops every occurrence on that calendar day (iCal
107
+ * `EXDATE;VALUE=DATE`); a date with a time drops only the occurrence starting
108
+ * at that exact instant. Corollary: an occurrence that itself starts at
109
+ * midnight can only be excluded day-wide. Maps to iCal `EXDATE`.
78
110
  */
79
111
  exdates?: Date[];
80
112
  /**
@@ -99,9 +131,30 @@ export type EventKeyExtractor<T = unknown> = (event: CalendarEvent<T>, index: nu
99
131
  export type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
100
132
 
101
133
  /**
102
- * A day's open hours for `businessHours` shading on the time grid: `{ start, end }`
103
- * in hours (fractions allowed, e.g. 9.5), or `null` when the day is closed (fully
104
- * shaded). `undefined` from the callback means "no business-hours shading". Shared
105
- * by both renderers; pair with `closedHourBands` to get the spans to shade.
134
+ * A day's open hours for `businessHours` shading, as hours (fractions allowed,
135
+ * e.g. `9.5`): a single window `{ start, end }`, or an array of windows to leave
136
+ * a closed gap between them (a lunch break: `[{ start: 9, end: 12 }, { start: 13,
137
+ * end: 17 }]`). Everything outside the window(s) is shaded closed.
138
+ */
139
+ export type BusinessHoursValue =
140
+ | { start: number; end: number }
141
+ | { start: number; end: number }[]
142
+ | null;
143
+ /**
144
+ * The `businessHours` callback: return the open hours for `date` (see
145
+ * {@link BusinessHoursValue}), `null` when the day is fully closed (all shaded),
146
+ * or `undefined` for no business-hours shading. Shared by both renderers; pair
147
+ * with `closedHourBands` to get the spans to shade.
106
148
  */
107
- export type BusinessHours = (date: Date) => { start: number; end: number } | null;
149
+ export type BusinessHours = (date: Date) => BusinessHoursValue;
150
+
151
+ /**
152
+ * One closed-hours band handed to a `renderBusinessHours` override: the day it
153
+ * belongs to and its span as fractional hours, already clamped to the visible
154
+ * window. `ResourceTimeline` extends it with the lane's resource.
155
+ */
156
+ export interface BusinessHoursBand {
157
+ date: Date;
158
+ start: number;
159
+ end: number;
160
+ }