@super-calendar/core 2.15.0 → 2.16.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.
@@ -0,0 +1,2 @@
1
+ import { $ as cellRangeFromDrag, A as loadEventSource, At as nextDateRange, B as eventAccessibilityLabel, Bt as BusinessHoursBand, C as groupEventsByDay, Ct as DateSelectionConstraints, D as wallClockHours, Dt as isDateSelectable, E as layoutDayEvents, Et as daySelectionState, F as EventAccessibilityLabelContext, Ft as rangeBandKind, G as monthEventCapacity, Gt as CreateGhostArgs, H as eventTimeLabel, Ht as CalendarEvent, I as EventAccessibilityLabeler, It as CalendarColors, J as titleNumberOfLines, Jt as RecurrenceFrequency, K as monthVisibleCount, Kt as EventKeyExtractor, L as EventChipLayout, Lt as darkColors, M as ToICalendarOptions, Mt as RangeBandKind, N as parseICalendar, Nt as bandRounding, O as EventSource, Ot as isRangeEndpoint, P as toICalendar, Pt as dayBadgeKind, Q as resolveCalendarLabels, Qt as WeekStartsOn, R as MIN_BOX_HEIGHT_FOR_TIME, Rt as lightColors, S as eventDayKeys, St as DateRange, T as isBackgroundEvent, Tt as UseDateRangeOptions, U as formatHour, Ut as CalendarHandle, V as eventChipLayout, Vt as BusinessHoursValue, W as isTimeVisibleAtHeight, Wt as CalendarMode, X as dayAccessibilityLabel, Xt as ScrollToTimeOptions, Y as CalendarLabels, Yt as RecurrenceRule, Z as defaultCalendarLabels, Zt as TimeGridMode, _ as backgroundBandsForDay, _t as isWeekend, a as MonthEventSegment, at as overlapsOtherEvents, b as compareDayEvents, bt as weekDaysCount, c as MonthGridWeek, ct as shiftMinutes, d as UseMonthGridOptions, dt as filterHiddenDays, et as clampMoveStartMinutes, f as WeekdayFormat, ft as getIsToday, g as PositionedEvent, gt as isSameCalendarDay, h as weekdayFormatToken, ht as getYearMonths, i as expandRecurringEvents, it as movedClockSpan, j as ICalEvent, jt as DayBadgeKind, k as EventSourceOptions, kt as isWithinDateRange, l as MonthGridWeekday, lt as snapDeltaMinutes, m as layoutMonthWeek, mt as getWeekDays, n as toZonedTime, nt as monthCreateRange, o as MonthGrid, ot as pageStepDays, p as buildMonthGrid, pt as getViewDays, q as titleEllipsizeMode, qt as ICalendarEvent, r as zonedTimeToUtc, rt as monthDropBounds, s as MonthGridDay, st as resolveDraggedBounds, t as eventsInTimeZone, tt as eventsOverlap, u as MonthWeekEvents, ut as buildMonthWeeks, v as clockHoursBetween, vt as minutesIntoDay, w as isAllDayEvent, wt as DaySelectionState, x as drawnEnd, xt as CalendarSelection, y as closedHourBands, yt as viewDayCount, z as MonthEventCapacity, zt as BusinessHours } from "./timezone-d6EaWlvP.mjs";
2
+ export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarHandle, CalendarLabels, CalendarMode, CalendarSelection, CreateGhostArgs, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSource, EventSourceOptions, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, ScrollToTimeOptions, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, clockHoursBetween, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, defaultCalendarLabels, drawnEnd, 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, loadEventSource, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, movedClockSpan, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, viewDayCount, wallClockHours, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
@@ -0,0 +1,2 @@
1
+ import { $ as cellRangeFromDrag, A as loadEventSource, At as nextDateRange, B as eventAccessibilityLabel, Bt as BusinessHoursBand, C as groupEventsByDay, Ct as DateSelectionConstraints, D as wallClockHours, Dt as isDateSelectable, E as layoutDayEvents, Et as daySelectionState, F as EventAccessibilityLabelContext, Ft as rangeBandKind, G as monthEventCapacity, Gt as CreateGhostArgs, H as eventTimeLabel, Ht as CalendarEvent, I as EventAccessibilityLabeler, It as CalendarColors, J as titleNumberOfLines, Jt as RecurrenceFrequency, K as monthVisibleCount, Kt as EventKeyExtractor, L as EventChipLayout, Lt as darkColors, M as ToICalendarOptions, Mt as RangeBandKind, N as parseICalendar, Nt as bandRounding, O as EventSource, Ot as isRangeEndpoint, P as toICalendar, Pt as dayBadgeKind, Q as resolveCalendarLabels, Qt as WeekStartsOn, R as MIN_BOX_HEIGHT_FOR_TIME, Rt as lightColors, S as eventDayKeys, St as DateRange, T as isBackgroundEvent, Tt as UseDateRangeOptions, U as formatHour, Ut as CalendarHandle, V as eventChipLayout, Vt as BusinessHoursValue, W as isTimeVisibleAtHeight, Wt as CalendarMode, X as dayAccessibilityLabel, Xt as ScrollToTimeOptions, Y as CalendarLabels, Yt as RecurrenceRule, Z as defaultCalendarLabels, Zt as TimeGridMode, _ as backgroundBandsForDay, _t as isWeekend, a as MonthEventSegment, at as overlapsOtherEvents, b as compareDayEvents, bt as weekDaysCount, c as MonthGridWeek, ct as shiftMinutes, d as UseMonthGridOptions, dt as filterHiddenDays, et as clampMoveStartMinutes, f as WeekdayFormat, ft as getIsToday, g as PositionedEvent, gt as isSameCalendarDay, h as weekdayFormatToken, ht as getYearMonths, i as expandRecurringEvents, it as movedClockSpan, j as ICalEvent, jt as DayBadgeKind, k as EventSourceOptions, kt as isWithinDateRange, l as MonthGridWeekday, lt as snapDeltaMinutes, m as layoutMonthWeek, mt as getWeekDays, n as toZonedTime, nt as monthCreateRange, o as MonthGrid, ot as pageStepDays, p as buildMonthGrid, pt as getViewDays, q as titleEllipsizeMode, qt as ICalendarEvent, r as zonedTimeToUtc, rt as monthDropBounds, s as MonthGridDay, st as resolveDraggedBounds, t as eventsInTimeZone, tt as eventsOverlap, u as MonthWeekEvents, ut as buildMonthWeeks, v as clockHoursBetween, vt as minutesIntoDay, w as isAllDayEvent, wt as DaySelectionState, x as drawnEnd, xt as CalendarSelection, y as closedHourBands, yt as viewDayCount, z as MonthEventCapacity, zt as BusinessHours } from "./timezone-d6EaWlvP.js";
2
+ export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarHandle, CalendarLabels, CalendarMode, CalendarSelection, CreateGhostArgs, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSource, EventSourceOptions, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, ScrollToTimeOptions, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, clampMoveStartMinutes, clockHoursBetween, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, defaultCalendarLabels, drawnEnd, 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, loadEventSource, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, movedClockSpan, nextDateRange, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, viewDayCount, wallClockHours, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
@@ -0,0 +1,68 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_recurrence = require("./recurrence-BvmTFytR.js");
3
+ exports.MIN_BOX_HEIGHT_FOR_TIME = require_recurrence.MIN_BOX_HEIGHT_FOR_TIME;
4
+ exports.backgroundBandsForDay = require_recurrence.backgroundBandsForDay;
5
+ exports.bandRounding = require_recurrence.bandRounding;
6
+ exports.buildMonthGrid = require_recurrence.buildMonthGrid;
7
+ exports.buildMonthWeeks = require_recurrence.buildMonthWeeks;
8
+ exports.cellRangeFromDrag = require_recurrence.cellRangeFromDrag;
9
+ exports.clampMoveStartMinutes = require_recurrence.clampMoveStartMinutes;
10
+ exports.clockHoursBetween = require_recurrence.clockHoursBetween;
11
+ exports.closedHourBands = require_recurrence.closedHourBands;
12
+ exports.compareDayEvents = require_recurrence.compareDayEvents;
13
+ exports.darkColors = require_recurrence.darkColors;
14
+ exports.dayAccessibilityLabel = require_recurrence.dayAccessibilityLabel;
15
+ exports.dayBadgeKind = require_recurrence.dayBadgeKind;
16
+ exports.daySelectionState = require_recurrence.daySelectionState;
17
+ exports.defaultCalendarLabels = require_recurrence.defaultCalendarLabels;
18
+ exports.drawnEnd = require_recurrence.drawnEnd;
19
+ exports.eventAccessibilityLabel = require_recurrence.eventAccessibilityLabel;
20
+ exports.eventChipLayout = require_recurrence.eventChipLayout;
21
+ exports.eventDayKeys = require_recurrence.eventDayKeys;
22
+ exports.eventTimeLabel = require_recurrence.eventTimeLabel;
23
+ exports.eventsInTimeZone = require_recurrence.eventsInTimeZone;
24
+ exports.eventsOverlap = require_recurrence.eventsOverlap;
25
+ exports.expandRecurringEvents = require_recurrence.expandRecurringEvents;
26
+ exports.filterHiddenDays = require_recurrence.filterHiddenDays;
27
+ exports.formatHour = require_recurrence.formatHour;
28
+ exports.getIsToday = require_recurrence.getIsToday;
29
+ exports.getViewDays = require_recurrence.getViewDays;
30
+ exports.getWeekDays = require_recurrence.getWeekDays;
31
+ exports.getYearMonths = require_recurrence.getYearMonths;
32
+ exports.groupEventsByDay = require_recurrence.groupEventsByDay;
33
+ exports.isAllDayEvent = require_recurrence.isAllDayEvent;
34
+ exports.isBackgroundEvent = require_recurrence.isBackgroundEvent;
35
+ exports.isDateSelectable = require_recurrence.isDateSelectable;
36
+ exports.isRangeEndpoint = require_recurrence.isRangeEndpoint;
37
+ exports.isSameCalendarDay = require_recurrence.isSameCalendarDay;
38
+ exports.isTimeVisibleAtHeight = require_recurrence.isTimeVisibleAtHeight;
39
+ exports.isWeekend = require_recurrence.isWeekend;
40
+ exports.isWithinDateRange = require_recurrence.isWithinDateRange;
41
+ exports.layoutDayEvents = require_recurrence.layoutDayEvents;
42
+ exports.layoutMonthWeek = require_recurrence.layoutMonthWeek;
43
+ exports.lightColors = require_recurrence.lightColors;
44
+ exports.loadEventSource = require_recurrence.loadEventSource;
45
+ exports.minutesIntoDay = require_recurrence.minutesIntoDay;
46
+ exports.monthCreateRange = require_recurrence.monthCreateRange;
47
+ exports.monthDropBounds = require_recurrence.monthDropBounds;
48
+ exports.monthEventCapacity = require_recurrence.monthEventCapacity;
49
+ exports.monthVisibleCount = require_recurrence.monthVisibleCount;
50
+ exports.movedClockSpan = require_recurrence.movedClockSpan;
51
+ exports.nextDateRange = require_recurrence.nextDateRange;
52
+ exports.overlapsOtherEvents = require_recurrence.overlapsOtherEvents;
53
+ exports.pageStepDays = require_recurrence.pageStepDays;
54
+ exports.parseICalendar = require_recurrence.parseICalendar;
55
+ exports.rangeBandKind = require_recurrence.rangeBandKind;
56
+ exports.resolveCalendarLabels = require_recurrence.resolveCalendarLabels;
57
+ exports.resolveDraggedBounds = require_recurrence.resolveDraggedBounds;
58
+ exports.shiftMinutes = require_recurrence.shiftMinutes;
59
+ exports.snapDeltaMinutes = require_recurrence.snapDeltaMinutes;
60
+ exports.titleEllipsizeMode = require_recurrence.titleEllipsizeMode;
61
+ exports.titleNumberOfLines = require_recurrence.titleNumberOfLines;
62
+ exports.toICalendar = require_recurrence.toICalendar;
63
+ exports.toZonedTime = require_recurrence.toZonedTime;
64
+ exports.viewDayCount = require_recurrence.viewDayCount;
65
+ exports.wallClockHours = require_recurrence.wallClockHours;
66
+ exports.weekDaysCount = require_recurrence.weekDaysCount;
67
+ exports.weekdayFormatToken = require_recurrence.weekdayFormatToken;
68
+ exports.zonedTimeToUtc = require_recurrence.zonedTimeToUtc;
@@ -0,0 +1 @@
1
+ export { d as MIN_BOX_HEIGHT_FOR_TIME, F as backgroundBandsForDay, ct as bandRounding, n as buildMonthGrid, Z as buildMonthWeeks, w as cellRangeFromDrag, T as clampMoveStartMinutes, I as clockHoursBetween, L as closedHourBands, R as compareDayEvents, dt as darkColors, x as dayAccessibilityLabel, lt as dayBadgeKind, K as daySelectionState, S as defaultCalendarLabels, z as drawnEnd, f as eventAccessibilityLabel, p as eventChipLayout, B as eventDayKeys, m as eventTimeLabel, c as eventsInTimeZone, E as eventsOverlap, t as expandRecurringEvents, Q as filterHiddenDays, h as formatHour, $ as getIsToday, et as getViewDays, tt as getWeekDays, nt as getYearMonths, V as groupEventsByDay, H as isAllDayEvent, U as isBackgroundEvent, q as isDateSelectable, J as isRangeEndpoint, rt as isSameCalendarDay, g as isTimeVisibleAtHeight, it as isWeekend, Y as isWithinDateRange, W as layoutDayEvents, r as layoutMonthWeek, ft as lightColors, a as loadEventSource, at as minutesIntoDay, D as monthCreateRange, O as monthDropBounds, _ as monthEventCapacity, v as monthVisibleCount, k as movedClockSpan, X as nextDateRange, A as overlapsOtherEvents, j as pageStepDays, o as parseICalendar, ut as rangeBandKind, C as resolveCalendarLabels, M as resolveDraggedBounds, N as shiftMinutes, P as snapDeltaMinutes, y as titleEllipsizeMode, b as titleNumberOfLines, s as toICalendar, l as toZonedTime, ot as viewDayCount, G as wallClockHours, st as weekDaysCount, i as weekdayFormatToken, u as zonedTimeToUtc } from "./recurrence-CvUX9ncg.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/core",
3
- "version": "2.15.0",
3
+ "version": "2.16.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",
@@ -39,7 +39,18 @@
39
39
  "default": "./dist/index.js"
40
40
  }
41
41
  },
42
- "./package.json": "./package.json"
42
+ "./package.json": "./package.json",
43
+ "./vanilla": {
44
+ "react-native": "./src/vanilla.ts",
45
+ "import": {
46
+ "types": "./dist/vanilla.d.mts",
47
+ "default": "./dist/vanilla.mjs"
48
+ },
49
+ "require": {
50
+ "types": "./dist/vanilla.d.ts",
51
+ "default": "./dist/vanilla.js"
52
+ }
53
+ }
43
54
  },
44
55
  "publishConfig": {
45
56
  "access": "public"
@@ -48,6 +59,11 @@
48
59
  "date-fns": ">=3",
49
60
  "react": ">=18"
50
61
  },
62
+ "peerDependenciesMeta": {
63
+ "react": {
64
+ "optional": true
65
+ }
66
+ },
51
67
  "scripts": {
52
68
  "build": "tsdown",
53
69
  "bench": "bun scripts/bench.ts"
package/src/index.ts CHANGED
@@ -31,3 +31,6 @@ export * from "./utils/layout";
31
31
  export * from "./utils/monthGrid";
32
32
  export * from "./utils/recurrence";
33
33
  export * from "./utils/timezone";
34
+ export * from "./utils/useDateRange";
35
+ export * from "./utils/useMonthGrid";
36
+ export * from "./utils/eventSource";
package/src/types.ts CHANGED
@@ -58,8 +58,8 @@ export interface ICalendarEvent {
58
58
  display?: "auto" | "background";
59
59
  /**
60
60
  * Repeat rule. Pass the event to `expandRecurringEvents(events, start, end)` to
61
- * materialise its occurrences within a range; the calendar itself doesn't
62
- * expand recurrences.
61
+ * materialise its occurrences within a range. Calendar expands rules for its
62
+ * visible range; standalone views expect already expanded events.
63
63
  */
64
64
  recurrence?: RecurrenceRule;
65
65
  }
@@ -161,6 +161,21 @@ export interface BusinessHoursBand {
161
161
  end: number;
162
162
  }
163
163
 
164
+ /**
165
+ * Props passed to a `renderCreateGhost` component while a drag-to-create sweep is
166
+ * in progress. `start` and `end` are the snapped range `onCreateEvent` would
167
+ * receive if the pointer were released at its current position: ordered, at
168
+ * least one snap step long, and clamped to the pressed day. They can extend past
169
+ * a narrowed visible-hour window, where the preview box itself stops at the edge.
170
+ * `ResourceTimeline` adds the lane's resource.
171
+ */
172
+ export interface CreateGhostArgs {
173
+ /** Start of the range the sweep would create. */
174
+ start: Date;
175
+ /** End of the range the sweep would create. */
176
+ end: Date;
177
+ }
178
+
164
179
  /** Options for {@link CalendarHandle.scrollToTime}. */
165
180
  export interface ScrollToTimeOptions {
166
181
  /** Animate the scroll. Default true; off when the OS asks to reduce motion. */
@@ -1,14 +1,4 @@
1
1
  import { isAfter, isBefore, startOfDay } from "date-fns";
2
- import {
3
- type Context,
4
- createContext,
5
- type Dispatch,
6
- type SetStateAction,
7
- useCallback,
8
- useContext,
9
- useMemo,
10
- useState,
11
- } from "react";
12
2
  import { isSameCalendarDay } from "./dates";
13
3
 
14
4
  /** A selected span. `end` is `null` while only the first endpoint has been picked. */
@@ -125,69 +115,8 @@ export interface CalendarSelection extends DateSelectionConstraints {
125
115
  selectedRange?: DateRange;
126
116
  }
127
117
 
128
- const CalendarSelectionContext: Context<CalendarSelection> = createContext<CalendarSelection>({});
129
-
130
- /**
131
- * Provides the active selection to the month grid. Day cells read it via
132
- * {@link useCalendarSelection} so they repaint on selection changes even when
133
- * the virtualized list has cached (and so won't re-render) their page.
134
- */
135
- export const CalendarSelectionProvider = CalendarSelectionContext.Provider;
136
-
137
- /** Reads the active selection provided by {@link CalendarSelectionProvider}. */
138
- export const useCalendarSelection = (): CalendarSelection => useContext(CalendarSelectionContext);
139
-
140
118
  /** Options for {@link useDateRange}. */
141
119
  export interface UseDateRangeOptions extends DateSelectionConstraints {
142
120
  /** Pre-select a range on mount. */
143
121
  initialRange?: DateRange | null;
144
122
  }
145
-
146
- /** The state and handlers returned by {@link useDateRange}. */
147
- export interface UseDateRangeResult {
148
- /** The current selection; `null` until the first endpoint is picked. */
149
- range: DateRange | null;
150
- /** Wire to `onPressDay`: advances the range (start, then end, then restarts). */
151
- onPressDate: (date: Date) => void;
152
- /** Set both endpoints at once (ordered); ignored if either isn't selectable. */
153
- selectRange: (a: Date, b: Date) => void;
154
- /** Clear the selection. */
155
- reset: () => void;
156
- /** The raw state setter, for full control. */
157
- setRange: Dispatch<SetStateAction<DateRange | null>>;
158
- }
159
-
160
- /**
161
- * Controlled-ish range selection state for the month view. Returns the current
162
- * `range` plus an `onPressDate` handler to wire to `Calendar`'s `onPressDay`, a
163
- * `reset`, and the raw `setRange` for full control.
164
- *
165
- * ```tsx
166
- * const { range, onPressDate } = useDateRange({ minDate: new Date() });
167
- * <Calendar mode="month" selectedRange={range ?? undefined} onPressDay={onPressDate} … />
168
- * ```
169
- */
170
- export function useDateRange(options: UseDateRangeOptions = {}): UseDateRangeResult {
171
- const { initialRange = null, minDate, maxDate, isDateDisabled } = options;
172
- const [range, setRange] = useState<DateRange | null>(initialRange);
173
- const constraints = useMemo<DateSelectionConstraints>(
174
- () => ({ minDate, maxDate, isDateDisabled }),
175
- [minDate, maxDate, isDateDisabled],
176
- );
177
- const onPressDate = useCallback(
178
- (date: Date) => setRange((previous) => nextDateRange(previous, date, constraints)),
179
- [constraints],
180
- );
181
- // Set both endpoints at once (ordered), for drag-to-select. Ignores the update
182
- // if either endpoint isn't selectable.
183
- const selectRange = useCallback(
184
- (a: Date, b: Date) => {
185
- if (!isDateSelectable(a, constraints) || !isDateSelectable(b, constraints)) return;
186
- const [start, end] = a.getTime() <= b.getTime() ? [a, b] : [b, a];
187
- setRange({ start: startOfDay(start), end: startOfDay(end) });
188
- },
189
- [constraints],
190
- );
191
- const reset = useCallback(() => setRange(null), []);
192
- return { range, onPressDate, selectRange, reset, setRange };
193
- }
@@ -0,0 +1,166 @@
1
+ import type { CalendarEvent, RecurrenceRule, WeekStartsOn } from "../types";
2
+ import { parseICalendar } from "./ical";
3
+
4
+ /** A JSON or iCalendar URL, or a caller-owned async event loader. */
5
+ export type EventSource<T = unknown> = string | (() => Promise<CalendarEvent<T>[]>);
6
+
7
+ /** Options for loading a calendar event source. */
8
+ export interface EventSourceOptions<T> {
9
+ /**
10
+ * Feed format for URL sources: `"json"` (default) expects an array of event
11
+ * objects with ISO `start`/`end` strings; `"ics"` parses an iCalendar feed.
12
+ * URLs ending in `.ics` default to `"ics"`.
13
+ */
14
+ format?: "json" | "ics";
15
+ /**
16
+ * Map the parsed JSON array into events, for feeds whose shape doesn't match
17
+ * `CalendarEvent` (rename fields, attach `resourceId`, filter). The default
18
+ * validates calendar fields and revives event and recurrence date strings.
19
+ */
20
+ map?: (items: unknown[]) => CalendarEvent<T>[];
21
+ /** Re-fetch every N ms. Values outside (0, 2147483647] or non-finite values disable polling. */
22
+ refetchIntervalMs?: number;
23
+ }
24
+
25
+ function dateFromJSON(value: unknown, field: string): Date {
26
+ if (typeof value !== "string") throw new Error(`Event source ${field} must be a date string`);
27
+ const date = new Date(value);
28
+ if (!Number.isFinite(date.getTime()))
29
+ throw new Error(`Event source ${field} is not a valid date`);
30
+ return date;
31
+ }
32
+
33
+ function objectFromJSON(value: unknown, field: string): Record<string, unknown> {
34
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
35
+ throw new Error(`Event source ${field} must be an object`);
36
+ }
37
+ return value as Record<string, unknown>;
38
+ }
39
+
40
+ function arrayFromJSON(value: unknown, field: string): unknown[] {
41
+ if (!Array.isArray(value)) throw new Error(`Event source ${field} must be an array`);
42
+ return value;
43
+ }
44
+
45
+ function integerFromJSON(
46
+ value: unknown,
47
+ field: string,
48
+ min: number,
49
+ max = Number.MAX_SAFE_INTEGER,
50
+ ): number {
51
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min || value > max) {
52
+ throw new Error(`Event source ${field} must be an integer from ${min} to ${max}`);
53
+ }
54
+ return value;
55
+ }
56
+
57
+ function weekdayFromJSON(value: unknown, field: string): WeekStartsOn {
58
+ switch (value) {
59
+ case 0:
60
+ case 1:
61
+ case 2:
62
+ case 3:
63
+ case 4:
64
+ case 5:
65
+ case 6:
66
+ return value;
67
+ default:
68
+ throw new Error(`Event source ${field} must be a weekday from 0 to 6`);
69
+ }
70
+ }
71
+
72
+ function recurrenceFromJSON(value: unknown, field: string): RecurrenceRule {
73
+ const input = objectFromJSON(value, field);
74
+ const { freq } = input;
75
+ if (freq !== "daily" && freq !== "weekly" && freq !== "monthly" && freq !== "yearly") {
76
+ throw new Error(`Event source ${field}.freq must be daily, weekly, monthly, or yearly`);
77
+ }
78
+ const rule: RecurrenceRule = { freq };
79
+ if (input.interval !== undefined)
80
+ rule.interval = integerFromJSON(input.interval, `${field}.interval`, 1);
81
+ if (input.count !== undefined) rule.count = integerFromJSON(input.count, `${field}.count`, 0);
82
+ if (input.until !== undefined) rule.until = dateFromJSON(input.until, `${field}.until`);
83
+ for (const key of ["exdates", "rdates"] as const) {
84
+ if (input[key] !== undefined)
85
+ rule[key] = arrayFromJSON(input[key], `${field}.${key}`).map((date, index) =>
86
+ dateFromJSON(date, `${field}.${key}[${index}]`),
87
+ );
88
+ }
89
+ if (input.weekdays !== undefined)
90
+ rule.weekdays = arrayFromJSON(input.weekdays, `${field}.weekdays`).map((day) =>
91
+ weekdayFromJSON(day, `${field}.weekdays`),
92
+ );
93
+ if (input.months !== undefined)
94
+ rule.months = arrayFromJSON(input.months, `${field}.months`).map((month) =>
95
+ integerFromJSON(month, `${field}.months`, 1, 12),
96
+ );
97
+ if (input.monthDays !== undefined)
98
+ rule.monthDays = arrayFromJSON(input.monthDays, `${field}.monthDays`).map((day) => {
99
+ const parsed = integerFromJSON(day, `${field}.monthDays`, -31, 31);
100
+ if (parsed === 0) throw new Error(`Event source ${field}.monthDays cannot contain zero`);
101
+ return parsed;
102
+ });
103
+ if (input.nthWeekday !== undefined) {
104
+ const nth = objectFromJSON(input.nthWeekday, `${field}.nthWeekday`);
105
+ rule.nthWeekday = {
106
+ week: nth.week === -1 ? -1 : integerFromJSON(nth.week, `${field}.nthWeekday.week`, 1, 5),
107
+ weekday: weekdayFromJSON(nth.weekday, `${field}.nthWeekday.weekday`),
108
+ };
109
+ }
110
+ return rule;
111
+ }
112
+
113
+ const defaultMap = (items: unknown[]): CalendarEvent[] =>
114
+ items.map((raw, index) => {
115
+ const field = `item ${index}`;
116
+ const item = objectFromJSON(raw, field);
117
+ for (const key of ["title", "dragHandleColor"] as const) {
118
+ if (item[key] !== undefined && typeof item[key] !== "string")
119
+ throw new Error(`Event source ${field}.${key} must be a string`);
120
+ }
121
+ for (const key of [
122
+ "allDay",
123
+ "disabled",
124
+ "draggable",
125
+ "startEditable",
126
+ "durationEditable",
127
+ ] as const) {
128
+ if (item[key] !== undefined && typeof item[key] !== "boolean")
129
+ throw new Error(`Event source ${field}.${key} must be a boolean`);
130
+ }
131
+ if (item.display !== undefined && item.display !== "auto" && item.display !== "background")
132
+ throw new Error(`Event source ${field}.display must be auto or background`);
133
+ return {
134
+ ...item,
135
+ start: dateFromJSON(item.start, `${field}.start`),
136
+ end: dateFromJSON(item.end, `${field}.end`),
137
+ ...(item.recurrence === undefined
138
+ ? {}
139
+ : { recurrence: recurrenceFromJSON(item.recurrence, `${field}.recurrence`) }),
140
+ };
141
+ });
142
+
143
+ /** Load one event batch. A caller can abort URL requests with signal. */
144
+ export async function loadEventSource<T = unknown>({
145
+ source,
146
+ format,
147
+ map,
148
+ signal,
149
+ }: EventSourceOptions<T> & { source: EventSource<T>; signal?: AbortSignal }): Promise<
150
+ CalendarEvent<T>[]
151
+ > {
152
+ if (typeof source === "function") {
153
+ return await source();
154
+ } else {
155
+ const response = await fetch(source, signal ? { signal } : undefined);
156
+ if (!response.ok) throw new Error(`Event source responded ${response.status}`);
157
+ const isIcs = format === "ics" || (format == null && /\.ics(\?|$)/.test(source));
158
+ if (isIcs) {
159
+ return parseICalendar(await response.text()) as CalendarEvent<T>[];
160
+ } else {
161
+ const body: unknown = await response.json();
162
+ const items = arrayFromJSON(body, "JSON");
163
+ return map ? map(items) : (defaultMap(items) as CalendarEvent<T>[]);
164
+ }
165
+ }
166
+ }
@@ -48,6 +48,16 @@ export interface CalendarLabels {
48
48
  moveToPreviousPage: (days: number, mode: CalendarMode) => string;
49
49
  /** Resource timeline action that moves an event to another lane. Default "Move to Room A". */
50
50
  moveToResource: (title: string) => string;
51
+ /**
52
+ * Names the web renderers' move and resize actions button and dialog for an
53
+ * event, given its title (empty when it has none). Default "Move or resize
54
+ * Planning", or "Move or resize event" without a title.
55
+ */
56
+ eventActions?: (title: string) => string;
57
+ /** Opens the web event chooser for move and resize actions. Default "Edit events". */
58
+ editEvents?: string;
59
+ /** Feedback when a web move or resize is rejected. */
60
+ eventChangeRejected?: string;
51
61
  }
52
62
 
53
63
  const minutes = (n: number) => `${n} minute${n === 1 ? "" : "s"}`;
@@ -55,7 +65,7 @@ const page = (days: number, mode: CalendarMode) =>
55
65
  mode === "week" ? "week" : days === 1 ? "day" : `${days} days`;
56
66
 
57
67
  /** The built-in English {@link CalendarLabels}. */
58
- export const defaultCalendarLabels: CalendarLabels = {
68
+ export const defaultCalendarLabels: Required<CalendarLabels> = {
59
69
  today: "today",
60
70
  selected: "selected",
61
71
  unavailable: "unavailable",
@@ -73,10 +83,13 @@ export const defaultCalendarLabels: CalendarLabels = {
73
83
  moveToNextPage: (days, mode) => `Move to next ${page(days, mode)}`,
74
84
  moveToPreviousPage: (days, mode) => `Move to previous ${page(days, mode)}`,
75
85
  moveToResource: (title) => `Move to ${title}`,
86
+ eventActions: (title) => (title ? `Move or resize ${title}` : "Move or resize event"),
87
+ editEvents: "Edit events",
88
+ eventChangeRejected: "This change is not allowed.",
76
89
  };
77
90
 
78
91
  /** Fill the labels a consumer left out with {@link defaultCalendarLabels}. */
79
- export function resolveCalendarLabels(labels?: Partial<CalendarLabels>): CalendarLabels {
92
+ export function resolveCalendarLabels(labels?: Partial<CalendarLabels>): Required<CalendarLabels> {
80
93
  return labels ? { ...defaultCalendarLabels, ...labels } : defaultCalendarLabels;
81
94
  }
82
95
 
@@ -1,5 +1,4 @@
1
1
  import { format, type Locale, isSameMonth, startOfDay } from "date-fns";
2
- import { useMemo } from "react";
3
2
  import type { CalendarEvent, WeekStartsOn } from "../types";
4
3
  import { type DateRange, type DateSelectionConstraints, daySelectionState } from "./dateRange";
5
4
  import { buildMonthWeeks, getIsToday, isWeekend } from "./dates";
@@ -256,43 +255,3 @@ export function buildMonthGrid(month: Date, options: UseMonthGridOptions = {}):
256
255
 
257
256
  return { weeks, weekdays };
258
257
  }
259
-
260
- /**
261
- * Headless month-grid hook. Returns the weeks and weekday headers for `month`,
262
- * each day annotated with selection/disabled/today state, so you can render a
263
- * fully custom calendar without reimplementing the date maths.
264
- *
265
- * ```tsx
266
- * const { weeks, weekdays } = useMonthGrid(month, { selectedRange: range });
267
- * // map weekdays -> header cells, weeks -> rows, days -> your own <DayCell />
268
- * ```
269
- */
270
- export function useMonthGrid(month: Date, options: UseMonthGridOptions = {}): MonthGrid {
271
- const {
272
- weekStartsOn,
273
- showSixWeeks,
274
- isRTL,
275
- selectedDates,
276
- selectedRange,
277
- minDate,
278
- maxDate,
279
- isDateDisabled,
280
- locale,
281
- } = options;
282
- return useMemo(
283
- () => buildMonthGrid(month, options),
284
- // Deps are the destructured option fields, not the (unstable) options object.
285
- [
286
- month,
287
- weekStartsOn,
288
- showSixWeeks,
289
- isRTL,
290
- selectedDates,
291
- selectedRange,
292
- minDate,
293
- maxDate,
294
- isDateDisabled,
295
- locale,
296
- ],
297
- );
298
- }
@@ -71,7 +71,8 @@ function* occurrenceStarts(
71
71
  let emitted = 0;
72
72
  const consider = (date: Date): "skip" | "stop" | "emit" => {
73
73
  if (date.getTime() < start.getTime()) return "skip"; // before the first occurrence
74
- if (date.getTime() > rangeEnd.getTime()) return "stop";
74
+ // A large interval can advance beyond Date's representable range (NaN).
75
+ if (!(date.getTime() <= rangeEnd.getTime())) return "stop";
75
76
  if (rule.until != null && date.getTime() > rule.until.getTime()) return "stop";
76
77
  if (rule.count != null && produced >= rule.count) return "stop";
77
78
  produced += 1;
@@ -85,18 +86,15 @@ function* occurrenceStarts(
85
86
  const weekdays = [...new Set(rule.weekdays)].sort((a, b) => a - b);
86
87
  let weekStart = startOfWeek(start, { weekStartsOn: 0 });
87
88
  while (true) {
88
- let advanced = false;
89
89
  for (const weekday of weekdays) {
90
90
  const date = withTimeOf(addDays(weekStart, weekday), start);
91
91
  const verdict = consider(date);
92
92
  if (verdict === "stop") return;
93
93
  if (verdict === "skip") continue;
94
- advanced = true;
95
94
  yield date;
96
95
  }
97
96
  const nextWeek = addWeeks(weekStart, interval);
98
- // Guard against a week that yielded nothing yet hasn't reached the range.
99
- if (!advanced && nextWeek.getTime() > rangeEnd.getTime()) return;
97
+ if (!(nextWeek.getTime() <= rangeEnd.getTime())) return;
100
98
  weekStart = nextWeek;
101
99
  }
102
100
  }
@@ -122,7 +120,7 @@ function* occurrenceStarts(
122
120
  year += Math.floor(month / 12);
123
121
  month = ((month % 12) + 12) % 12;
124
122
  // No occurrence yielded yet but we've run past the range: stop.
125
- if (new Date(year, month, 1).getTime() > rangeEnd.getTime()) return;
123
+ if (!(new Date(year, month, 1).getTime() <= rangeEnd.getTime())) return;
126
124
  }
127
125
  }
128
126
 
@@ -143,7 +141,7 @@ function* occurrenceStarts(
143
141
  year += Math.floor(month / 12);
144
142
  month = ((month % 12) + 12) % 12;
145
143
  // No occurrence yielded yet but we've run past the range: stop.
146
- if (new Date(year, month, 1).getTime() > rangeEnd.getTime()) return;
144
+ if (!(new Date(year, month, 1).getTime() <= rangeEnd.getTime())) return;
147
145
  }
148
146
  }
149
147
 
@@ -163,7 +161,7 @@ function* occurrenceStarts(
163
161
  yield date;
164
162
  }
165
163
  year += interval;
166
- if (new Date(year, 0, 1).getTime() > rangeEnd.getTime()) return;
164
+ if (!(new Date(year, 0, 1).getTime() <= rangeEnd.getTime())) return;
167
165
  }
168
166
  }
169
167
 
@@ -188,7 +186,7 @@ function* occurrenceStarts(
188
186
  if (rule.count != null && n >= rule.count) return;
189
187
  if (emitted >= MAX_OCCURRENCES) return;
190
188
  const date = occAt(n);
191
- if (date.getTime() > rangeEnd.getTime()) return;
189
+ if (!(date.getTime() <= rangeEnd.getTime())) return;
192
190
  if (rule.until != null && date.getTime() > rule.until.getTime()) return;
193
191
  emitted += 1;
194
192
  n += 1;
@@ -253,7 +251,8 @@ export function expandRecurringEvents<T>(
253
251
  // Skip occurrences that end before the range opens, but keep iterating.
254
252
  if (start.getTime() + durationMs < rangeStart.getTime()) continue;
255
253
  if (excludedDays.has(dayKey(start)) || excludedInstants.has(start.getTime())) continue;
256
- out.push(instanceAt(event, start, durationMs));
254
+ const instance = instanceAt(event, start, durationMs);
255
+ if (Number.isFinite(instance.end.getTime())) out.push(instance);
257
256
  }
258
257
  }
259
258
  return out;