@super-calendar/core 2.15.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -2
- package/dist/index.d.mts +29 -1021
- package/dist/index.d.ts +29 -1021
- package/dist/index.js +125 -1599
- package/dist/index.mjs +58 -1534
- package/dist/recurrence-CvIJfSMl.mjs +1625 -0
- package/dist/recurrence-D_oJ7A9D.js +2026 -0
- package/dist/timezone-vbd68uRS.d.mts +1056 -0
- package/dist/timezone-vbd68uRS.d.ts +1056 -0
- package/dist/vanilla.d.mts +2 -0
- package/dist/vanilla.d.ts +2 -0
- package/dist/vanilla.js +69 -0
- package/dist/vanilla.mjs +1 -0
- package/package.json +18 -2
- package/src/index.ts +4 -0
- package/src/types.ts +33 -6
- package/src/utils/dateRange.ts +0 -71
- package/src/utils/dates.ts +10 -1
- package/src/utils/eventDisplay.ts +5 -5
- package/src/utils/eventSource.ts +166 -0
- package/src/utils/labels.ts +15 -2
- package/src/utils/monthGrid.ts +0 -41
- package/src/utils/multiWeekGrid.ts +139 -0
- package/src/utils/recurrence.ts +9 -10
- package/src/utils/useDateRange.ts +80 -0
- package/src/utils/useEventSource.ts +20 -41
- package/src/utils/useMonthGrid.ts +42 -0
- package/src/vanilla.ts +16 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as titleEllipsizeMode, $t as ICalendarEvent, A as isAllDayEvent, At as DaySelectionState, B as toICalendar, Bt as dayBadgeKind, C as backgroundBandsForDay, Ct as isWeekend, D as drawnEnd, Dt as CalendarSelection, E as compareDayEvents, Et as weekDaysCount, F as EventSourceOptions, Ft as isWithinDateRange, G as MonthEventCapacity, Gt as BusinessHours, H as EventAccessibilityLabeler, Ht as CalendarColors, I as loadEventSource, It as nextDateRange, J as eventTimeLabel, Jt as CalendarEvent, K as eventAccessibilityLabel, Kt as BusinessHoursBand, L as ICalEvent, Lt as DayBadgeKind, M as layoutDayEvents, Mt as daySelectionState, N as wallClockHours, Nt as isDateSelectable, O as eventDayKeys, Ot as DateRange, P as EventSource, Pt as isRangeEndpoint, Q as monthVisibleCount, Qt as EventKeyExtractor, R as ToICalendarOptions, Rt as RangeBandKind, S as PositionedEvent, St as isSameCalendarDay, T as closedHourBands, Tt as viewDayCount, U as EventChipLayout, Ut as darkColors, V as EventAccessibilityLabelContext, Vt as rangeBandKind, W as MIN_BOX_HEIGHT_FOR_TIME, Wt as lightColors, X as isTimeVisibleAtHeight, Xt as CalendarMode, Y as formatHour, Yt as CalendarHandle, Z as monthEventCapacity, Zt as CreateGhostArgs, _ as UseMonthGridOptions, _t as filterHiddenDays, a as MultiWeekGrid, at as cellRangeFromDrag, b as layoutMonthWeek, bt as getWeekDays, c as MultiWeekGridOptions, ct as monthCreateRange, d as MonthEventSegment, dt as overlapsOtherEvents, en as RecurrenceFrequency, et as titleNumberOfLines, f as MonthGrid, ft as pageStepDays, g as MonthWeekEvents, gt as buildMonthWeeks, h as MonthGridWeekday, ht as snapDeltaMinutes, i as expandRecurringEvents, in as WeekStartsOn, it as resolveCalendarLabels, j as isBackgroundEvent, jt as UseDateRangeOptions, k as groupEventsByDay, kt as DateSelectionConstraints, l as MultiWeekGridWeek, lt as monthDropBounds, m as MonthGridWeek, mt as shiftMinutes, n as toZonedTime, nn as ScrollToTimeOptions, nt as dayAccessibilityLabel, o as MultiWeekGridDay, ot as clampMoveStartMinutes, p as MonthGridDay, pt as resolveDraggedBounds, q as eventChipLayout, qt as BusinessHoursValue, r as zonedTimeToUtc, rn as TimeGridMode, rt as defaultCalendarLabels, s as MultiWeekGridInterval, st as eventsOverlap, t as eventsInTimeZone, tn as RecurrenceRule, tt as CalendarLabels, u as buildMultiWeekGrid, ut as movedClockSpan, v as WeekdayFormat, vt as getIsToday, w as clockHoursBetween, wt as minutesIntoDay, x as weekdayFormatToken, xt as getYearMonths, y as buildMonthGrid, yt as getViewDays, z as parseICalendar, zt as bandRounding } from "./timezone-vbd68uRS.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, MultiWeekGrid, MultiWeekGridDay, MultiWeekGridInterval, MultiWeekGridOptions, MultiWeekGridWeek, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, ScrollToTimeOptions, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, 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, 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 titleEllipsizeMode, $t as ICalendarEvent, A as isAllDayEvent, At as DaySelectionState, B as toICalendar, Bt as dayBadgeKind, C as backgroundBandsForDay, Ct as isWeekend, D as drawnEnd, Dt as CalendarSelection, E as compareDayEvents, Et as weekDaysCount, F as EventSourceOptions, Ft as isWithinDateRange, G as MonthEventCapacity, Gt as BusinessHours, H as EventAccessibilityLabeler, Ht as CalendarColors, I as loadEventSource, It as nextDateRange, J as eventTimeLabel, Jt as CalendarEvent, K as eventAccessibilityLabel, Kt as BusinessHoursBand, L as ICalEvent, Lt as DayBadgeKind, M as layoutDayEvents, Mt as daySelectionState, N as wallClockHours, Nt as isDateSelectable, O as eventDayKeys, Ot as DateRange, P as EventSource, Pt as isRangeEndpoint, Q as monthVisibleCount, Qt as EventKeyExtractor, R as ToICalendarOptions, Rt as RangeBandKind, S as PositionedEvent, St as isSameCalendarDay, T as closedHourBands, Tt as viewDayCount, U as EventChipLayout, Ut as darkColors, V as EventAccessibilityLabelContext, Vt as rangeBandKind, W as MIN_BOX_HEIGHT_FOR_TIME, Wt as lightColors, X as isTimeVisibleAtHeight, Xt as CalendarMode, Y as formatHour, Yt as CalendarHandle, Z as monthEventCapacity, Zt as CreateGhostArgs, _ as UseMonthGridOptions, _t as filterHiddenDays, a as MultiWeekGrid, at as cellRangeFromDrag, b as layoutMonthWeek, bt as getWeekDays, c as MultiWeekGridOptions, ct as monthCreateRange, d as MonthEventSegment, dt as overlapsOtherEvents, en as RecurrenceFrequency, et as titleNumberOfLines, f as MonthGrid, ft as pageStepDays, g as MonthWeekEvents, gt as buildMonthWeeks, h as MonthGridWeekday, ht as snapDeltaMinutes, i as expandRecurringEvents, in as WeekStartsOn, it as resolveCalendarLabels, j as isBackgroundEvent, jt as UseDateRangeOptions, k as groupEventsByDay, kt as DateSelectionConstraints, l as MultiWeekGridWeek, lt as monthDropBounds, m as MonthGridWeek, mt as shiftMinutes, n as toZonedTime, nn as ScrollToTimeOptions, nt as dayAccessibilityLabel, o as MultiWeekGridDay, ot as clampMoveStartMinutes, p as MonthGridDay, pt as resolveDraggedBounds, q as eventChipLayout, qt as BusinessHoursValue, r as zonedTimeToUtc, rn as TimeGridMode, rt as defaultCalendarLabels, s as MultiWeekGridInterval, st as eventsOverlap, t as eventsInTimeZone, tn as RecurrenceRule, tt as CalendarLabels, u as buildMultiWeekGrid, ut as movedClockSpan, v as WeekdayFormat, vt as getIsToday, w as clockHoursBetween, wt as minutesIntoDay, x as weekdayFormatToken, xt as getYearMonths, y as buildMonthGrid, yt as getViewDays, z as parseICalendar, zt as bandRounding } from "./timezone-vbd68uRS.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, MultiWeekGrid, MultiWeekGridDay, MultiWeekGridInterval, MultiWeekGridOptions, MultiWeekGridWeek, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, ScrollToTimeOptions, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, 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, 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 };
|
package/dist/vanilla.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_recurrence = require("./recurrence-D_oJ7A9D.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.buildMultiWeekGrid = require_recurrence.buildMultiWeekGrid;
|
|
9
|
+
exports.cellRangeFromDrag = require_recurrence.cellRangeFromDrag;
|
|
10
|
+
exports.clampMoveStartMinutes = require_recurrence.clampMoveStartMinutes;
|
|
11
|
+
exports.clockHoursBetween = require_recurrence.clockHoursBetween;
|
|
12
|
+
exports.closedHourBands = require_recurrence.closedHourBands;
|
|
13
|
+
exports.compareDayEvents = require_recurrence.compareDayEvents;
|
|
14
|
+
exports.darkColors = require_recurrence.darkColors;
|
|
15
|
+
exports.dayAccessibilityLabel = require_recurrence.dayAccessibilityLabel;
|
|
16
|
+
exports.dayBadgeKind = require_recurrence.dayBadgeKind;
|
|
17
|
+
exports.daySelectionState = require_recurrence.daySelectionState;
|
|
18
|
+
exports.defaultCalendarLabels = require_recurrence.defaultCalendarLabels;
|
|
19
|
+
exports.drawnEnd = require_recurrence.drawnEnd;
|
|
20
|
+
exports.eventAccessibilityLabel = require_recurrence.eventAccessibilityLabel;
|
|
21
|
+
exports.eventChipLayout = require_recurrence.eventChipLayout;
|
|
22
|
+
exports.eventDayKeys = require_recurrence.eventDayKeys;
|
|
23
|
+
exports.eventTimeLabel = require_recurrence.eventTimeLabel;
|
|
24
|
+
exports.eventsInTimeZone = require_recurrence.eventsInTimeZone;
|
|
25
|
+
exports.eventsOverlap = require_recurrence.eventsOverlap;
|
|
26
|
+
exports.expandRecurringEvents = require_recurrence.expandRecurringEvents;
|
|
27
|
+
exports.filterHiddenDays = require_recurrence.filterHiddenDays;
|
|
28
|
+
exports.formatHour = require_recurrence.formatHour;
|
|
29
|
+
exports.getIsToday = require_recurrence.getIsToday;
|
|
30
|
+
exports.getViewDays = require_recurrence.getViewDays;
|
|
31
|
+
exports.getWeekDays = require_recurrence.getWeekDays;
|
|
32
|
+
exports.getYearMonths = require_recurrence.getYearMonths;
|
|
33
|
+
exports.groupEventsByDay = require_recurrence.groupEventsByDay;
|
|
34
|
+
exports.isAllDayEvent = require_recurrence.isAllDayEvent;
|
|
35
|
+
exports.isBackgroundEvent = require_recurrence.isBackgroundEvent;
|
|
36
|
+
exports.isDateSelectable = require_recurrence.isDateSelectable;
|
|
37
|
+
exports.isRangeEndpoint = require_recurrence.isRangeEndpoint;
|
|
38
|
+
exports.isSameCalendarDay = require_recurrence.isSameCalendarDay;
|
|
39
|
+
exports.isTimeVisibleAtHeight = require_recurrence.isTimeVisibleAtHeight;
|
|
40
|
+
exports.isWeekend = require_recurrence.isWeekend;
|
|
41
|
+
exports.isWithinDateRange = require_recurrence.isWithinDateRange;
|
|
42
|
+
exports.layoutDayEvents = require_recurrence.layoutDayEvents;
|
|
43
|
+
exports.layoutMonthWeek = require_recurrence.layoutMonthWeek;
|
|
44
|
+
exports.lightColors = require_recurrence.lightColors;
|
|
45
|
+
exports.loadEventSource = require_recurrence.loadEventSource;
|
|
46
|
+
exports.minutesIntoDay = require_recurrence.minutesIntoDay;
|
|
47
|
+
exports.monthCreateRange = require_recurrence.monthCreateRange;
|
|
48
|
+
exports.monthDropBounds = require_recurrence.monthDropBounds;
|
|
49
|
+
exports.monthEventCapacity = require_recurrence.monthEventCapacity;
|
|
50
|
+
exports.monthVisibleCount = require_recurrence.monthVisibleCount;
|
|
51
|
+
exports.movedClockSpan = require_recurrence.movedClockSpan;
|
|
52
|
+
exports.nextDateRange = require_recurrence.nextDateRange;
|
|
53
|
+
exports.overlapsOtherEvents = require_recurrence.overlapsOtherEvents;
|
|
54
|
+
exports.pageStepDays = require_recurrence.pageStepDays;
|
|
55
|
+
exports.parseICalendar = require_recurrence.parseICalendar;
|
|
56
|
+
exports.rangeBandKind = require_recurrence.rangeBandKind;
|
|
57
|
+
exports.resolveCalendarLabels = require_recurrence.resolveCalendarLabels;
|
|
58
|
+
exports.resolveDraggedBounds = require_recurrence.resolveDraggedBounds;
|
|
59
|
+
exports.shiftMinutes = require_recurrence.shiftMinutes;
|
|
60
|
+
exports.snapDeltaMinutes = require_recurrence.snapDeltaMinutes;
|
|
61
|
+
exports.titleEllipsizeMode = require_recurrence.titleEllipsizeMode;
|
|
62
|
+
exports.titleNumberOfLines = require_recurrence.titleNumberOfLines;
|
|
63
|
+
exports.toICalendar = require_recurrence.toICalendar;
|
|
64
|
+
exports.toZonedTime = require_recurrence.toZonedTime;
|
|
65
|
+
exports.viewDayCount = require_recurrence.viewDayCount;
|
|
66
|
+
exports.wallClockHours = require_recurrence.wallClockHours;
|
|
67
|
+
exports.weekDaysCount = require_recurrence.weekDaysCount;
|
|
68
|
+
exports.weekdayFormatToken = require_recurrence.weekdayFormatToken;
|
|
69
|
+
exports.zonedTimeToUtc = require_recurrence.zonedTimeToUtc;
|
package/dist/vanilla.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { f as MIN_BOX_HEIGHT_FOR_TIME, I as backgroundBandsForDay, lt as bandRounding, r as buildMonthGrid, Q as buildMonthWeeks, n as buildMultiWeekGrid, T as cellRangeFromDrag, E as clampMoveStartMinutes, L as clockHoursBetween, R as closedHourBands, z as compareDayEvents, ft as darkColors, S as dayAccessibilityLabel, ut as dayBadgeKind, q as daySelectionState, C as defaultCalendarLabels, B as drawnEnd, p as eventAccessibilityLabel, m as eventChipLayout, V as eventDayKeys, h as eventTimeLabel, l as eventsInTimeZone, D as eventsOverlap, t as expandRecurringEvents, $ as filterHiddenDays, g as formatHour, et as getIsToday, tt as getViewDays, nt as getWeekDays, rt as getYearMonths, H as groupEventsByDay, U as isAllDayEvent, W as isBackgroundEvent, J as isDateSelectable, Y as isRangeEndpoint, it as isSameCalendarDay, _ as isTimeVisibleAtHeight, at as isWeekend, X as isWithinDateRange, G as layoutDayEvents, i as layoutMonthWeek, pt as lightColors, o as loadEventSource, ot as minutesIntoDay, O as monthCreateRange, k as monthDropBounds, v as monthEventCapacity, y as monthVisibleCount, A as movedClockSpan, Z as nextDateRange, j as overlapsOtherEvents, M as pageStepDays, s as parseICalendar, dt as rangeBandKind, w as resolveCalendarLabels, N as resolveDraggedBounds, P as shiftMinutes, F as snapDeltaMinutes, b as titleEllipsizeMode, x as titleNumberOfLines, c as toICalendar, u as toZonedTime, st as viewDayCount, K as wallClockHours, ct as weekDaysCount, a as weekdayFormatToken, d as zonedTimeToUtc } from "./recurrence-CvIJfSMl.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.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
|
@@ -29,5 +29,9 @@ 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";
|
|
35
|
+
export * from "./utils/useDateRange";
|
|
36
|
+
export * from "./utils/useMonthGrid";
|
|
37
|
+
export * from "./utils/eventSource";
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
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
|
|
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,
|
|
@@ -58,8 +70,8 @@ export interface ICalendarEvent {
|
|
|
58
70
|
display?: "auto" | "background";
|
|
59
71
|
/**
|
|
60
72
|
* Repeat rule. Pass the event to `expandRecurringEvents(events, start, end)` to
|
|
61
|
-
* materialise its occurrences within a range
|
|
62
|
-
*
|
|
73
|
+
* materialise its occurrences within a range. Calendar expands rules for its
|
|
74
|
+
* visible range; standalone views expect already expanded events.
|
|
63
75
|
*/
|
|
64
76
|
recurrence?: RecurrenceRule;
|
|
65
77
|
}
|
|
@@ -161,6 +173,21 @@ export interface BusinessHoursBand {
|
|
|
161
173
|
end: number;
|
|
162
174
|
}
|
|
163
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Props passed to a `renderCreateGhost` component while a drag-to-create sweep is
|
|
178
|
+
* in progress. `start` and `end` are the snapped range `onCreateEvent` would
|
|
179
|
+
* receive if the pointer were released at its current position: ordered, at
|
|
180
|
+
* least one snap step long, and clamped to the pressed day. They can extend past
|
|
181
|
+
* a narrowed visible-hour window, where the preview box itself stops at the edge.
|
|
182
|
+
* `ResourceTimeline` adds the lane's resource.
|
|
183
|
+
*/
|
|
184
|
+
export interface CreateGhostArgs {
|
|
185
|
+
/** Start of the range the sweep would create. */
|
|
186
|
+
start: Date;
|
|
187
|
+
/** End of the range the sweep would create. */
|
|
188
|
+
end: Date;
|
|
189
|
+
}
|
|
190
|
+
|
|
164
191
|
/** Options for {@link CalendarHandle.scrollToTime}. */
|
|
165
192
|
export interface ScrollToTimeOptions {
|
|
166
193
|
/** Animate the scroll. Default true; off when the OS asks to reduce motion. */
|
package/src/utils/dateRange.ts
CHANGED
|
@@ -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
|
-
}
|
package/src/utils/dates.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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,
|
|
@@ -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;
|
|
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)}`;
|
|
@@ -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
|
+
}
|
package/src/utils/labels.ts
CHANGED
|
@@ -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
|
|
package/src/utils/monthGrid.ts
CHANGED
|
@@ -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
|
-
}
|