@super-calendar/core 2.16.0 → 2.18.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/vanilla.d.ts CHANGED
@@ -1,2 +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 };
1
+ import { $ as eventAccessibilityLabel, $t as BusinessHoursBand, A as backgroundBandsForDay, At as isWeekend, B as wallClockHours, Bt as isDateSelectable, C as MonthWeekEvents, Ct as buildMonthWeeks, D as layoutMonthWeek, Dt as getWeekDays, E as buildMonthGrid, Et as getViewDays, F as eventDayKeys, Ft as DateRange, G as ToICalendarOptions, Gt as RangeBandKind, H as EventSourceOptions, Ht as isWithinDateRange, I as groupEventsByDay, It as DateSelectionConstraints, J as EventAccessibilityLabelContext, Jt as rangeBandKind, K as parseICalendar, Kt as bandRounding, L as isAllDayEvent, Lt as DaySelectionState, M as closedHourBands, Mt as viewDayCount, N as compareDayEvents, Nt as weekDaysCount, O as weekdayFormatToken, Ot as getYearMonths, P as drawnEnd, Pt as CalendarSelection, Q as MonthEventCapacity, Qt as BusinessHours, R as isBackgroundEvent, Rt as UseDateRangeOptions, S as MonthGridWeekday, St as snapDeltaMinutes, T as WeekdayFormat, Tt as getIsToday, U as loadEventSource, Ut as nextDateRange, V as EventSource, Vt as isRangeEndpoint, W as ICalEvent, Wt as DayBadgeKind, X as EventChipLayout, Xt as darkColors, Y as EventAccessibilityLabeler, Yt as CalendarColors, Z as MIN_BOX_HEIGHT_FOR_TIME, Zt as lightColors, _ as buildMultiWeekGrid, _t as movedClockSpan, a as nowInTimeZone, an as EventKeyExtractor, at as monthVisibleCount, b as MonthGridDay, bt as resolveDraggedBounds, c as zonedEventSource, cn as RecurrenceRule, ct as CalendarLabels, d as expandRecurringEvents, dn as WeekStartsOn, dt as resolveCalendarLabels, en as BusinessHoursValue, et as eventChipLayout, f as MultiWeekGrid, ft as cellRangeFromDrag, g as MultiWeekGridWeek, gt as monthDropBounds, h as MultiWeekGridOptions, ht as monthCreateRange, i as fromZonedTime, in as CreateGhostArgs, it as monthEventCapacity, j as clockHoursBetween, jt as minutesIntoDay, k as PositionedEvent, kt as isSameCalendarDay, l as zonedTimeToUtc, ln as ScrollToTimeOptions, lt as dayAccessibilityLabel, m as MultiWeekGridInterval, mt as eventsOverlap, n as eventsInTimeZone, nn as CalendarHandle, nt as formatHour, o as toZonedTime, on as ICalendarEvent, ot as titleEllipsizeMode, p as MultiWeekGridDay, pt as clampMoveStartMinutes, q as toICalendar, qt as dayBadgeKind, r as fromZonedRange, rn as CalendarMode, rt as isTimeVisibleAtHeight, s as zonedDragBounds, sn as RecurrenceFrequency, st as titleNumberOfLines, t as ZonedDragBoundsOptions, tn as CalendarEvent, tt as eventTimeLabel, u as ExpandRecurringEventsOptions, un as TimeGridMode, ut as defaultCalendarLabels, v as MonthEventSegment, vt as overlapsOtherEvents, w as UseMonthGridOptions, wt as filterHiddenDays, x as MonthGridWeek, xt as shiftMinutes, y as MonthGrid, yt as pageStepDays, z as layoutDayEvents, zt as daySelectionState } from "./timezone-BY2vQwRx.js";
2
+ export { BusinessHours, BusinessHoursBand, BusinessHoursValue, CalendarColors, CalendarEvent, CalendarHandle, CalendarLabels, CalendarMode, CalendarSelection, CreateGhostArgs, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, EventSource, EventSourceOptions, ExpandRecurringEventsOptions, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthEventSegment, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, MonthWeekEvents, MultiWeekGrid, MultiWeekGridDay, MultiWeekGridInterval, MultiWeekGridOptions, MultiWeekGridWeek, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, ScrollToTimeOptions, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, ZonedDragBoundsOptions, backgroundBandsForDay, bandRounding, buildMonthGrid, buildMonthWeeks, buildMultiWeekGrid, cellRangeFromDrag, clampMoveStartMinutes, clockHoursBetween, closedHourBands, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, defaultCalendarLabels, drawnEnd, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, eventsOverlap, expandRecurringEvents, filterHiddenDays, formatHour, fromZonedRange, fromZonedTime, getIsToday, getViewDays, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, layoutMonthWeek, lightColors, loadEventSource, minutesIntoDay, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, movedClockSpan, nextDateRange, nowInTimeZone, overlapsOtherEvents, pageStepDays, parseICalendar, rangeBandKind, resolveCalendarLabels, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, viewDayCount, wallClockHours, weekDaysCount, weekdayFormatToken, zonedDragBounds, zonedEventSource, zonedTimeToUtc };
package/dist/vanilla.js CHANGED
@@ -1,10 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_recurrence = require("./recurrence-BvmTFytR.js");
2
+ const require_recurrence = require("./recurrence-M-rJQgqd.js");
3
3
  exports.MIN_BOX_HEIGHT_FOR_TIME = require_recurrence.MIN_BOX_HEIGHT_FOR_TIME;
4
4
  exports.backgroundBandsForDay = require_recurrence.backgroundBandsForDay;
5
5
  exports.bandRounding = require_recurrence.bandRounding;
6
6
  exports.buildMonthGrid = require_recurrence.buildMonthGrid;
7
7
  exports.buildMonthWeeks = require_recurrence.buildMonthWeeks;
8
+ exports.buildMultiWeekGrid = require_recurrence.buildMultiWeekGrid;
8
9
  exports.cellRangeFromDrag = require_recurrence.cellRangeFromDrag;
9
10
  exports.clampMoveStartMinutes = require_recurrence.clampMoveStartMinutes;
10
11
  exports.clockHoursBetween = require_recurrence.clockHoursBetween;
@@ -25,6 +26,8 @@ exports.eventsOverlap = require_recurrence.eventsOverlap;
25
26
  exports.expandRecurringEvents = require_recurrence.expandRecurringEvents;
26
27
  exports.filterHiddenDays = require_recurrence.filterHiddenDays;
27
28
  exports.formatHour = require_recurrence.formatHour;
29
+ exports.fromZonedRange = require_recurrence.fromZonedRange;
30
+ exports.fromZonedTime = require_recurrence.fromZonedTime;
28
31
  exports.getIsToday = require_recurrence.getIsToday;
29
32
  exports.getViewDays = require_recurrence.getViewDays;
30
33
  exports.getWeekDays = require_recurrence.getWeekDays;
@@ -49,6 +52,7 @@ exports.monthEventCapacity = require_recurrence.monthEventCapacity;
49
52
  exports.monthVisibleCount = require_recurrence.monthVisibleCount;
50
53
  exports.movedClockSpan = require_recurrence.movedClockSpan;
51
54
  exports.nextDateRange = require_recurrence.nextDateRange;
55
+ exports.nowInTimeZone = require_recurrence.nowInTimeZone;
52
56
  exports.overlapsOtherEvents = require_recurrence.overlapsOtherEvents;
53
57
  exports.pageStepDays = require_recurrence.pageStepDays;
54
58
  exports.parseICalendar = require_recurrence.parseICalendar;
@@ -65,4 +69,6 @@ exports.viewDayCount = require_recurrence.viewDayCount;
65
69
  exports.wallClockHours = require_recurrence.wallClockHours;
66
70
  exports.weekDaysCount = require_recurrence.weekDaysCount;
67
71
  exports.weekdayFormatToken = require_recurrence.weekdayFormatToken;
72
+ exports.zonedDragBounds = require_recurrence.zonedDragBounds;
73
+ exports.zonedEventSource = require_recurrence.zonedEventSource;
68
74
  exports.zonedTimeToUtc = require_recurrence.zonedTimeToUtc;
package/dist/vanilla.mjs CHANGED
@@ -1 +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";
1
+ export { _ as MIN_BOX_HEIGHT_FOR_TIME, V as backgroundBandsForDay, mt as bandRounding, r as buildMonthGrid, rt as buildMonthWeeks, n as buildMultiWeekGrid, A as cellRangeFromDrag, j as clampMoveStartMinutes, H as clockHoursBetween, U as closedHourBands, W as compareDayEvents, _t as darkColors, D as dayAccessibilityLabel, ht as dayBadgeKind, Q as daySelectionState, O as defaultCalendarLabels, G as drawnEnd, v as eventAccessibilityLabel, y as eventChipLayout, K as eventDayKeys, b as eventTimeLabel, l as eventsInTimeZone, M as eventsOverlap, t as expandRecurringEvents, it as filterHiddenDays, x as formatHour, u as fromZonedRange, d as fromZonedTime, at as getIsToday, ot as getViewDays, st as getWeekDays, ct as getYearMonths, q as groupEventsByDay, J as isAllDayEvent, Y as isBackgroundEvent, $ as isDateSelectable, et as isRangeEndpoint, lt as isSameCalendarDay, S as isTimeVisibleAtHeight, ut as isWeekend, tt as isWithinDateRange, X as layoutDayEvents, i as layoutMonthWeek, vt as lightColors, o as loadEventSource, dt as minutesIntoDay, N as monthCreateRange, P as monthDropBounds, C as monthEventCapacity, w as monthVisibleCount, F as movedClockSpan, nt as nextDateRange, f as nowInTimeZone, I as overlapsOtherEvents, L as pageStepDays, s as parseICalendar, gt as rangeBandKind, k as resolveCalendarLabels, R as resolveDraggedBounds, z as shiftMinutes, B as snapDeltaMinutes, T as titleEllipsizeMode, E as titleNumberOfLines, c as toICalendar, p as toZonedTime, ft as viewDayCount, Z as wallClockHours, pt as weekDaysCount, a as weekdayFormatToken, m as zonedDragBounds, h as zonedEventSource, g as zonedTimeToUtc } from "./recurrence-15B6fu6K.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/core",
3
- "version": "2.16.0",
3
+ "version": "2.18.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
@@ -29,6 +29,7 @@ export * from "./utils/useNow";
29
29
  export * from "./utils/useEventSource";
30
30
  export * from "./utils/layout";
31
31
  export * from "./utils/monthGrid";
32
+ export * from "./utils/multiWeekGrid";
32
33
  export * from "./utils/recurrence";
33
34
  export * from "./utils/timezone";
34
35
  export * from "./utils/useDateRange";
package/src/types.ts CHANGED
@@ -1,8 +1,20 @@
1
- /** The view the calendar renders: a day-column grid (`day`, `3days`, `week`, `custom`), the `month` grid, or the `schedule` list. */
2
- export type CalendarMode = "day" | "3days" | "week" | "custom" | "month" | "schedule" | "year";
1
+ /**
2
+ * The view the calendar renders: a day-column grid (`day`, `3days`, `week`,
3
+ * `custom`), the `month` grid, consecutive week rows (`multiweek`), the
4
+ * `schedule` list, or the `year` overview.
5
+ */
6
+ export type CalendarMode =
7
+ | "day"
8
+ | "3days"
9
+ | "week"
10
+ | "custom"
11
+ | "month"
12
+ | "multiweek"
13
+ | "schedule"
14
+ | "year";
3
15
 
4
- /** The time-grid modes (day-column views, excluding month and schedule). */
5
- export type TimeGridMode = Exclude<CalendarMode, "month" | "schedule" | "year">;
16
+ /** The time-grid modes (day-column views, excluding the month, multi-week, schedule, and year views). */
17
+ export type TimeGridMode = Exclude<CalendarMode, "month" | "multiweek" | "schedule" | "year">;
6
18
 
7
19
  /**
8
20
  * The minimal shape every calendar event must have. Layout (positioning,
@@ -82,6 +94,13 @@ export interface RecurrenceRule {
82
94
  * the event's time of day. Omit to repeat on the start date's own weekday.
83
95
  */
84
96
  weekdays?: WeekStartsOn[];
97
+ /**
98
+ * For `weekly` rules with `weekdays`: the day a week starts on (0 = Sunday …
99
+ * 6 = Saturday). It decides which of the `weekdays` share a week, so it only
100
+ * changes the result when `interval` is greater than 1. Default 1 (Monday),
101
+ * as in RFC 5545. Maps to iCal `WKST`.
102
+ */
103
+ weekStartsOn?: WeekStartsOn;
85
104
  /**
86
105
  * For `monthly`/`yearly`: repeat on the Nth weekday of the period instead of the
87
106
  * start date's day-of-month — e.g. `{ week: 3, weekday: 1 }` is the 3rd Monday.
@@ -19,7 +19,11 @@ export const getWeekDays = (date: Date, weekStartsOn: WeekStartsOn): Date[] => {
19
19
  return Array.from({ length: 7 }, (_, index) => addDays(start, index));
20
20
  };
21
21
 
22
- /** How many day columns a time-grid mode shows. `custom` uses `numberOfDays`. */
22
+ /**
23
+ * How many day columns a time-grid mode shows. `custom` uses `numberOfDays`.
24
+ * Throws a `RangeError` for `multiweek`, which has week rows instead of day
25
+ * columns; use `buildMultiWeekGrid` for it.
26
+ */
23
27
  export const viewDayCount = (mode: CalendarMode, numberOfDays = 1): number => {
24
28
  switch (mode) {
25
29
  case "week":
@@ -28,6 +32,10 @@ export const viewDayCount = (mode: CalendarMode, numberOfDays = 1): number => {
28
32
  return 3;
29
33
  case "custom":
30
34
  return Math.max(1, Math.floor(numberOfDays));
35
+ case "multiweek":
36
+ throw new RangeError(
37
+ "The multiweek mode has week rows, not day columns. Use buildMultiWeekGrid for its days.",
38
+ );
31
39
  default:
32
40
  return 1; // 'day'
33
41
  }
@@ -57,6 +65,7 @@ export const weekDaysCount = (weekStartsOn: WeekStartsOn, weekEndsOn: WeekStarts
57
65
  * (honouring `weekStartsOn`). `custom` with a `weekEndsOn` spans the partial week
58
66
  * from `weekStartsOn` to `weekEndsOn` (anchored to `date`'s week, paging by week);
59
67
  * otherwise every mode shows `viewDayCount` consecutive days starting at `date`.
68
+ * Throws a `RangeError` for `multiweek` (see `viewDayCount`).
60
69
  */
61
70
  export const getViewDays = (
62
71
  mode: CalendarMode,
@@ -137,8 +146,13 @@ export const isWeekend = (date: Date): boolean => {
137
146
  return day === 0 || day === 6;
138
147
  };
139
148
 
140
- /** True when `date` falls on the current calendar day. */
141
- export const getIsToday = (date: Date): boolean => isToday(date);
149
+ /**
150
+ * True when `date` falls on the current calendar day. Pass `today` to compare
151
+ * against that day instead of the device clock, e.g. the result of
152
+ * `nowInTimeZone` for a calendar displayed in another time zone.
153
+ */
154
+ export const getIsToday = (date: Date, today?: Date): boolean =>
155
+ today ? isSameDay(date, today) : isToday(date);
142
156
 
143
157
  /** True when `a` and `b` are the same calendar day (ignoring the time of day). */
144
158
  export const isSameCalendarDay = (a: Date, b: Date): boolean => isSameDay(a, b);
package/src/utils/drag.ts CHANGED
@@ -6,11 +6,19 @@ import { MIN_DURATION_HOURS } from "./minDuration";
6
6
 
7
7
  /**
8
8
  * True when two time ranges overlap. Edges touching (one ends exactly when the
9
- * next begins) do not count as an overlap. Compares absolute instants, so events
10
- * at the same wall-clock time on different days do not overlap.
9
+ * next begins) do not count as an overlap. A zero-length range occupies its own
10
+ * instant: it overlaps a range that contains that instant or starts at it, and
11
+ * another zero-length range at the same instant. Compares absolute instants, so
12
+ * events at the same wall-clock time on different days do not overlap.
11
13
  */
12
14
  export function eventsOverlap(aStart: Date, aEnd: Date, bStart: Date, bEnd: Date): boolean {
13
- return aStart.getTime() < bEnd.getTime() && bStart.getTime() < aEnd.getTime();
15
+ const a0 = aStart.getTime();
16
+ const a1 = aEnd.getTime();
17
+ const b0 = bStart.getTime();
18
+ const b1 = bEnd.getTime();
19
+ if (a0 === a1) return b0 === b1 ? a0 === b0 : b0 <= a0 && a0 < b1;
20
+ if (b0 === b1) return a0 <= b0 && b0 < a1;
21
+ return a0 < b1 && b0 < a1;
14
22
  }
15
23
 
16
24
  /**
@@ -181,8 +189,8 @@ export function resolveDraggedBounds(
181
189
 
182
190
  /**
183
191
  * The all-day range swept out between two day cells of the month grid, ordered
184
- * whichever way the sweep ran: `start` is midnight of the first day and `end` is
185
- * midnight after the last, so a one-day sweep still yields a usable event. Shared
192
+ * whichever way the sweep ran: `start` is the first local day's start and `end` is
193
+ * the next day's start after the last, so a one-day sweep yields a usable event. Shared
186
194
  * by both renderers so a month drag-to-create means the same thing on each.
187
195
  */
188
196
  export function monthCreateRange(anchor: Date, hover: Date): { start: Date; end: Date } {
@@ -190,7 +198,7 @@ export function monthCreateRange(anchor: Date, hover: Date): { start: Date; end:
190
198
  const b = startOfDay(hover);
191
199
  const first = a.getTime() <= b.getTime() ? a : b;
192
200
  const last = a.getTime() <= b.getTime() ? b : a;
193
- return { start: first, end: addDays(last, 1) };
201
+ return { start: first, end: startOfDay(addDays(last, 1)) };
194
202
  }
195
203
 
196
204
  /**
@@ -62,11 +62,11 @@ export type EventAccessibilityLabeler<T = unknown> = (
62
62
  ) => string;
63
63
 
64
64
  /**
65
- * Month cells and the all-day lane show a single clipped line; timed-grid titles
66
- * (`undefined`) wrap to fill the box.
65
+ * Month and multi-week cells and the all-day lane show a single clipped line;
66
+ * timed-grid titles (`undefined`) wrap to fill the box.
67
67
  */
68
68
  export function titleNumberOfLines(mode: CalendarMode, isAllDay: boolean): number | undefined {
69
- return mode === "month" || isAllDay ? 1 : undefined;
69
+ return mode === "month" || mode === "multiweek" || isAllDay ? 1 : undefined;
70
70
  }
71
71
 
72
72
  /**
@@ -74,7 +74,7 @@ export function titleNumberOfLines(mode: CalendarMode, isAllDay: boolean): numbe
74
74
  * none should show. Timed events get their `start - end` range. An all-day event
75
75
  * gets the literal "All day" in the schedule (which has no all-day lane to
76
76
  * signal it positionally) and nothing on the day/week grid (the lane already
77
- * does). Month cells and `showTime={false}` always return `null`.
77
+ * does). Month and multi-week cells and `showTime={false}` always return `null`.
78
78
  */
79
79
  export function eventTimeLabel(args: {
80
80
  mode: CalendarMode;
@@ -86,7 +86,7 @@ export function eventTimeLabel(args: {
86
86
  /** Text for an all-day event in the schedule. Default "All day". */
87
87
  allDayLabel?: string;
88
88
  }): string | null {
89
- if (!args.showTime || args.mode === "month") return null;
89
+ if (!args.showTime || args.mode === "month" || args.mode === "multiweek") return null;
90
90
  if (args.isAllDay) return args.mode === "schedule" ? (args.allDayLabel ?? "All day") : null;
91
91
  const timeFormat = args.ampm ? "h:mm a" : "HH:mm";
92
92
  return `${format(args.start, timeFormat)} - ${format(args.end, timeFormat)}`;
@@ -90,6 +90,8 @@ function recurrenceFromJSON(value: unknown, field: string): RecurrenceRule {
90
90
  rule.weekdays = arrayFromJSON(input.weekdays, `${field}.weekdays`).map((day) =>
91
91
  weekdayFromJSON(day, `${field}.weekdays`),
92
92
  );
93
+ if (input.weekStartsOn !== undefined)
94
+ rule.weekStartsOn = weekdayFromJSON(input.weekStartsOn, `${field}.weekStartsOn`);
93
95
  if (input.months !== undefined)
94
96
  rule.months = arrayFromJSON(input.months, `${field}.months`).map((month) =>
95
97
  integerFromJSON(month, `${field}.months`, 1, 12),
package/src/utils/ical.ts CHANGED
@@ -188,6 +188,8 @@ function parseRRule(value: string): RecurrenceRule | undefined {
188
188
  }
189
189
  if (plain.length) rule.weekdays = plain;
190
190
  }
191
+ const wkst = BYDAY.indexOf(parts.get("WKST")?.trim().toUpperCase() as (typeof BYDAY)[number]);
192
+ if (wkst >= 0) rule.weekStartsOn = wkst as WeekStartsOn;
191
193
  const bymonthday = parts.get("BYMONTHDAY");
192
194
  if (bymonthday) {
193
195
  const days = bymonthday
@@ -217,6 +219,9 @@ function formatRRule(rule: RecurrenceRule): string {
217
219
  } else if (rule.weekdays?.length) {
218
220
  parts.push(`BYDAY=${rule.weekdays.map((d) => BYDAY[d]).join(",")}`);
219
221
  }
222
+ if (rule.weekStartsOn != null && BYDAY[rule.weekStartsOn]) {
223
+ parts.push(`WKST=${BYDAY[rule.weekStartsOn]}`);
224
+ }
220
225
  if (rule.monthDays?.length) parts.push(`BYMONTHDAY=${rule.monthDays.join(",")}`);
221
226
  if (rule.months?.length) parts.push(`BYMONTH=${rule.months.join(",")}`);
222
227
  return parts.join(";");
@@ -106,7 +106,14 @@ export function layoutDayEvents<T>(events: CalendarEvent<T>[], day: Date): Posit
106
106
  // paint as bands (see `backgroundBandsForDay`), not boxes.
107
107
  .filter((event) => !isAllDayEvent(event) && !isBackgroundEvent(event))
108
108
  // Overlaps this day if it starts before the day ends and ends after it begins.
109
- .filter((event) => event.start < nextDayStart && event.end > dayStart)
109
+ // A zero-length event occupies its own instant, so one at midnight belongs to
110
+ // the day it starts.
111
+ .filter(
112
+ (event) =>
113
+ event.start < nextDayStart &&
114
+ (event.end > dayStart ||
115
+ (event.end.getTime() === event.start.getTime() && event.start >= dayStart)),
116
+ )
110
117
  .map((event) => {
111
118
  const segStart = maxDate([event.start, dayStart]);
112
119
  const segEnd = minDate([event.end, nextDayStart]);
@@ -123,6 +130,11 @@ export function layoutDayEvents<T>(events: CalendarEvent<T>[], day: Date): Posit
123
130
  let cluster: Segment<T>[] = [];
124
131
  let clusterEnd = Number.NEGATIVE_INFINITY;
125
132
 
133
+ // Columns are packed by each segment's minimum box (see `durationHours`), so
134
+ // two short events whose minimum boxes would overlap sit side by side even
135
+ // when their times don't.
136
+ const drawnEndOf = (seg: Segment<T>) => Math.max(seg.end, seg.start + MIN_DURATION_HOURS);
137
+
126
138
  const flushCluster = () => {
127
139
  const columnEnds: number[] = [];
128
140
  const columnOf = new Map<Segment<T>, number>();
@@ -130,9 +142,9 @@ export function layoutDayEvents<T>(events: CalendarEvent<T>[], day: Date): Posit
130
142
  let column = columnEnds.findIndex((end) => end <= seg.start);
131
143
  if (column === -1) {
132
144
  column = columnEnds.length;
133
- columnEnds.push(seg.end);
145
+ columnEnds.push(drawnEndOf(seg));
134
146
  } else {
135
- columnEnds[column] = seg.end;
147
+ columnEnds[column] = drawnEndOf(seg);
136
148
  }
137
149
  columnOf.set(seg, column);
138
150
  }
@@ -153,7 +165,7 @@ export function layoutDayEvents<T>(events: CalendarEvent<T>[], day: Date): Posit
153
165
  for (const seg of segments) {
154
166
  if (cluster.length > 0 && seg.start >= clusterEnd) flushCluster();
155
167
  cluster.push(seg);
156
- clusterEnd = Math.max(clusterEnd, seg.end);
168
+ clusterEnd = Math.max(clusterEnd, drawnEndOf(seg));
157
169
  }
158
170
  if (cluster.length > 0) flushCluster();
159
171
 
@@ -189,7 +201,9 @@ export function eventDayKeys<T>(event: CalendarEvent<T>): string[] {
189
201
  const last = startOfDay(lastInstant);
190
202
 
191
203
  const keys: string[] = [];
192
- for (let cursor = first; cursor <= last; cursor = addDays(cursor, 1)) {
204
+ // Midnight can normalize to 01:00 on a clock change. Reset each subsequent
205
+ // day so its index still matches startOfDay(date).
206
+ for (let cursor = first; cursor <= last; cursor = startOfDay(addDays(cursor, 1))) {
193
207
  keys.push(cursor.toISOString());
194
208
  }
195
209
  return keys;
@@ -202,6 +202,11 @@ export interface UseMonthGridOptions extends DateSelectionConstraints {
202
202
  selectedRange?: DateRange;
203
203
  /** A date-fns locale for the weekday labels. */
204
204
  locale?: Locale;
205
+ /**
206
+ * The calendar day flagged `isToday`. Defaults to the device's current day;
207
+ * pass `nowInTimeZone(now, timeZone)` for a grid shown in another time zone.
208
+ */
209
+ today?: Date;
205
210
  }
206
211
 
207
212
  /**
@@ -222,6 +227,7 @@ export function buildMonthGrid(month: Date, options: UseMonthGridOptions = {}):
222
227
  maxDate,
223
228
  isDateDisabled,
224
229
  locale,
230
+ today,
225
231
  } = options;
226
232
 
227
233
  const rows = buildMonthWeeks(month, weekStartsOn, { showSixWeeks, isRTL, hiddenDays });
@@ -233,7 +239,7 @@ export function buildMonthGrid(month: Date, options: UseMonthGridOptions = {}):
233
239
  id: format(date, "yyyy-MM-dd"),
234
240
  label: format(date, "d"),
235
241
  isCurrentMonth: isSameMonth(date, month),
236
- isToday: getIsToday(date),
242
+ isToday: getIsToday(date, today),
237
243
  isWeekend: isWeekend(date),
238
244
  // Shared with MonthView, so the headless grid matches the built-in view.
239
245
  ...daySelectionState(
@@ -0,0 +1,140 @@
1
+ import { addDays, format, startOfWeek } from "date-fns";
2
+ import { daySelectionState } from "./dateRange";
3
+ import { filterHiddenDays, getIsToday, isWeekend } from "./dates";
4
+ import {
5
+ type MonthGridDay,
6
+ type MonthGridWeekday,
7
+ type UseMonthGridOptions,
8
+ weekdayFormatToken,
9
+ } from "./monthGrid";
10
+
11
+ /** Options for {@link buildMultiWeekGrid}. */
12
+ export interface MultiWeekGridOptions extends Omit<UseMonthGridOptions, "showSixWeeks"> {
13
+ /**
14
+ * How many consecutive full weeks to show. A positive whole number; default 2.
15
+ * Other values throw a `RangeError`.
16
+ */
17
+ numberOfWeeks?: number;
18
+ }
19
+
20
+ /**
21
+ * A day in a multi-week grid. Every day of the grid belongs to the requested
22
+ * period, so it carries no month-membership flag.
23
+ */
24
+ export type MultiWeekGridDay = Omit<MonthGridDay, "isCurrentMonth">;
25
+
26
+ /** One week row of a {@link MultiWeekGrid}. */
27
+ export interface MultiWeekGridWeek {
28
+ /** The week's first calendar day as `yyyy-MM-dd`, before hidden days are removed. */
29
+ id: string;
30
+ /** The row's days in display order, without hidden weekdays. */
31
+ days: MultiWeekGridDay[];
32
+ }
33
+
34
+ /** A half-open local calendar interval, `[start, endExclusive)`. */
35
+ export interface MultiWeekGridInterval {
36
+ /** Midnight of the first day. */
37
+ start: Date;
38
+ /** Midnight after the last day. */
39
+ endExclusive: Date;
40
+ }
41
+
42
+ /** The rows, weekday headers, and date bounds of a multi-week grid. */
43
+ export interface MultiWeekGrid {
44
+ /** Every calendar day of the requested weeks, independent of hidden weekdays and RTL. */
45
+ period: MultiWeekGridInterval;
46
+ /** From the earliest to the latest displayed day; hidden days inside it stay hidden. */
47
+ visibleRange: MultiWeekGridInterval;
48
+ /** The week rows, oldest first. */
49
+ weeks: MultiWeekGridWeek[];
50
+ /** The weekday header cells, in display order. */
51
+ weekdays: MonthGridWeekday[];
52
+ }
53
+
54
+ /**
55
+ * Pure multi-week builder: `numberOfWeeks` consecutive full calendar weeks,
56
+ * starting with the week that contains `date` (aligned back to `weekStartsOn`).
57
+ * Each day carries the same selection, disabled, today, and weekend state as
58
+ * {@link buildMonthGrid}. Hidden weekdays shrink the rows without changing the
59
+ * period; `isRTL` reverses each row's display order.
60
+ *
61
+ * The result is fully materialized, so its size grows with `numberOfWeeks`.
62
+ *
63
+ * @throws RangeError when `date` is invalid, `numberOfWeeks` is not a positive
64
+ * safe integer, or the last week falls outside the range `Date` can represent.
65
+ */
66
+ export function buildMultiWeekGrid(date: Date, options: MultiWeekGridOptions = {}): MultiWeekGrid {
67
+ const {
68
+ numberOfWeeks = 2,
69
+ weekStartsOn = 0,
70
+ weekdayFormat = "short",
71
+ isRTL = false,
72
+ hiddenDays,
73
+ selectedDates,
74
+ selectedRange,
75
+ minDate,
76
+ maxDate,
77
+ isDateDisabled,
78
+ locale,
79
+ today,
80
+ } = options;
81
+
82
+ if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
83
+ throw new RangeError("buildMultiWeekGrid: date must be a valid Date.");
84
+ }
85
+ if (!Number.isSafeInteger(numberOfWeeks) || numberOfWeeks < 1) {
86
+ throw new RangeError(
87
+ `buildMultiWeekGrid: numberOfWeeks must be a positive whole number, received ${String(numberOfWeeks)}.`,
88
+ );
89
+ }
90
+ const start = startOfWeek(date, { weekStartsOn });
91
+ const endExclusive = addDays(start, numberOfWeeks * 7);
92
+ if (Number.isNaN(endExclusive.getTime())) {
93
+ throw new RangeError(
94
+ `buildMultiWeekGrid: ${numberOfWeeks} weeks from ${format(start, "yyyy-MM-dd")} cannot be represented as a Date.`,
95
+ );
96
+ }
97
+
98
+ const constraints = { minDate, maxDate, isDateDisabled };
99
+ const selection = { selectedDates, selectedRange };
100
+ let first: Date | null = null;
101
+ let last: Date | null = null;
102
+ const weeks: MultiWeekGridWeek[] = [];
103
+ for (let row = 0; row < numberOfWeeks; row++) {
104
+ const weekStart = addDays(start, row * 7);
105
+ const all = Array.from({ length: 7 }, (_, index) => addDays(weekStart, index));
106
+ const visible = filterHiddenDays(all, hiddenDays);
107
+ if (visible.length > 0) {
108
+ if (first === null) first = visible[0];
109
+ last = visible[visible.length - 1];
110
+ }
111
+ const ordered = isRTL ? [...visible].reverse() : visible;
112
+ weeks.push({
113
+ id: format(weekStart, "yyyy-MM-dd"),
114
+ days: ordered.map((day): MultiWeekGridDay => ({
115
+ date: day,
116
+ id: format(day, "yyyy-MM-dd"),
117
+ label: format(day, "d"),
118
+ isToday: getIsToday(day, today),
119
+ isWeekend: isWeekend(day),
120
+ ...daySelectionState(day, selection, constraints),
121
+ })),
122
+ });
123
+ }
124
+
125
+ const token = weekdayFormatToken(weekdayFormat);
126
+ const weekdays: MonthGridWeekday[] = weeks[0].days.map((day) => ({
127
+ date: day.date,
128
+ label: format(day.date, token, { locale }),
129
+ }));
130
+
131
+ return {
132
+ period: { start, endExclusive },
133
+ visibleRange: {
134
+ start: first ?? start,
135
+ endExclusive: last ? addDays(last, 1) : endExclusive,
136
+ },
137
+ weeks,
138
+ weekdays,
139
+ };
140
+ }