@super-calendar/dom 2.17.0 → 2.19.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 +42 -2
- package/dist/index.d.mts +58 -16
- package/dist/index.d.ts +58 -16
- package/dist/index.js +435 -150
- package/dist/index.mjs +437 -152
- package/package.json +2 -2
- package/src/Agenda.tsx +20 -3
- package/src/Calendar.tsx +106 -30
- package/src/MonthList.tsx +1 -1
- package/src/MonthView.tsx +243 -46
- package/src/ResourceTimeline.tsx +11 -7
- package/src/TimeGrid.tsx +363 -153
- package/src/YearView.tsx +21 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/dom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"description": "Virtualized month / week / day calendar and date picker for react-dom. No React Native, no react-native-web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calendar",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@super-calendar/core": "2.
|
|
51
|
+
"@super-calendar/core": "2.19.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@legendapp/list": ">=3",
|
package/src/Agenda.tsx
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { LegendList } from "@legendapp/list/react";
|
|
2
2
|
import { format, isSameDay, type Locale, startOfDay } from "date-fns";
|
|
3
3
|
import { type ComponentType, type CSSProperties, type ReactElement, useMemo } from "react";
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
type CalendarEvent,
|
|
6
|
+
type EventAccessibilityLabeler,
|
|
7
|
+
eventTimeLabel,
|
|
8
|
+
getIsToday,
|
|
9
|
+
isAllDayEvent,
|
|
10
|
+
isBackgroundEvent,
|
|
11
|
+
nowInTimeZone,
|
|
12
|
+
} from "@super-calendar/core";
|
|
6
13
|
import { createSlots, type ResolvedSlot, type SlotStyleProps } from "./slots";
|
|
7
14
|
import { type DomCalendarTheme, mergeDomTheme } from "./theme";
|
|
8
15
|
|
|
@@ -35,6 +42,13 @@ export interface AgendaProps<T = unknown> extends SlotStyleProps<AgendaSlot> {
|
|
|
35
42
|
events: CalendarEvent<T>[];
|
|
36
43
|
/** date-fns locale for the day headers and time labels. */
|
|
37
44
|
locale?: Locale;
|
|
45
|
+
/**
|
|
46
|
+
* The instant whose calendar day is highlighted as today. Defaults to the
|
|
47
|
+
* device clock, and is read in `timeZone` when one is set.
|
|
48
|
+
*/
|
|
49
|
+
now?: Date;
|
|
50
|
+
/** Highlight today as it is in this IANA time zone (default: the device's). */
|
|
51
|
+
timeZone?: string;
|
|
38
52
|
/** Render times in 12-hour AM/PM (default false, 24h). */
|
|
39
53
|
ampm?: boolean;
|
|
40
54
|
/** Highlight this date's header instead of the real "today". */
|
|
@@ -104,6 +118,8 @@ function DefaultAgendaRow<T>({
|
|
|
104
118
|
export function Agenda<T = unknown>({
|
|
105
119
|
events,
|
|
106
120
|
locale,
|
|
121
|
+
now,
|
|
122
|
+
timeZone,
|
|
107
123
|
ampm = false,
|
|
108
124
|
activeDate,
|
|
109
125
|
theme: themeOverrides,
|
|
@@ -118,6 +134,7 @@ export function Agenda<T = unknown>({
|
|
|
118
134
|
styles,
|
|
119
135
|
}: AgendaProps<T>): ReactElement {
|
|
120
136
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
137
|
+
const today = nowInTimeZone(now, timeZone);
|
|
121
138
|
const slot = createSlots<AgendaSlot>({ classNames, styles });
|
|
122
139
|
const Renderer = renderEvent;
|
|
123
140
|
|
|
@@ -153,7 +170,7 @@ export function Agenda<T = unknown>({
|
|
|
153
170
|
if (item.kind === "header") {
|
|
154
171
|
const highlighted = activeDate
|
|
155
172
|
? isSameDay(item.date, activeDate)
|
|
156
|
-
: getIsToday(item.date);
|
|
173
|
+
: getIsToday(item.date, today);
|
|
157
174
|
const label = format(item.date, "EEEE, d LLLL", locale ? { locale } : undefined);
|
|
158
175
|
const color = highlighted ? theme.todayBackground : theme.textMuted;
|
|
159
176
|
const headerProps = slot("dayHeader", {
|
package/src/Calendar.tsx
CHANGED
|
@@ -37,12 +37,17 @@ import {
|
|
|
37
37
|
type EventAccessibilityLabeler,
|
|
38
38
|
buildMultiWeekGrid,
|
|
39
39
|
eventsInTimeZone,
|
|
40
|
+
fromZonedRange,
|
|
41
|
+
fromZonedTime,
|
|
42
|
+
zonedDragBounds,
|
|
43
|
+
zonedEventSource,
|
|
40
44
|
expandRecurringEvents,
|
|
41
45
|
getViewDays,
|
|
42
46
|
type WeekdayFormat,
|
|
43
47
|
type WeekStartsOn,
|
|
48
|
+
type CalendarHandle,
|
|
49
|
+
type CalendarLabels,
|
|
44
50
|
} from "@super-calendar/core";
|
|
45
|
-
import type { CalendarHandle, CalendarLabels } from "@super-calendar/core";
|
|
46
51
|
import { Agenda, type AgendaSlot, type DomAgendaEvent } from "./Agenda";
|
|
47
52
|
import { YearView, type YearViewSlot } from "./YearView";
|
|
48
53
|
import { type DomMonthEvent, MonthView, type MonthViewSlot } from "./MonthView";
|
|
@@ -90,9 +95,10 @@ export interface CalendarProps<T = unknown>
|
|
|
90
95
|
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
91
96
|
hiddenDays?: number[];
|
|
92
97
|
/**
|
|
93
|
-
* Fixed "now" instant for the current-time indicator (doesn't tick)
|
|
94
|
-
*
|
|
95
|
-
*
|
|
98
|
+
* Fixed "now" instant for the current-time indicator (doesn't tick) and for
|
|
99
|
+
* the day highlighted as today in every mode, e.g. a server-synced clock.
|
|
100
|
+
* Defaults to the device clock, shifted into `timeZone` when one is set so
|
|
101
|
+
* both match the displayed events.
|
|
96
102
|
*/
|
|
97
103
|
now?: Date;
|
|
98
104
|
/** Column count for `mode="custom"`. */
|
|
@@ -107,7 +113,9 @@ export interface CalendarProps<T = unknown>
|
|
|
107
113
|
/**
|
|
108
114
|
* Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
|
|
109
115
|
* and independent of the device zone. Display-only: it shifts the wall-clock the
|
|
110
|
-
* grid lays out from, it doesn't change your `Date`s
|
|
116
|
+
* grid lays out from, it doesn't change your `Date`s, and callbacks report your
|
|
117
|
+
* own events and real instants. All-day events stay on their days. Uses
|
|
118
|
+
* `eventsInTimeZone`.
|
|
111
119
|
*/
|
|
112
120
|
timeZone?: string;
|
|
113
121
|
/** Theme overrides; falls back to the default light theme. */
|
|
@@ -204,8 +212,9 @@ export interface CalendarProps<T = unknown>
|
|
|
204
212
|
*/
|
|
205
213
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
206
214
|
/**
|
|
207
|
-
* A component that draws content inside
|
|
208
|
-
*
|
|
215
|
+
* A component that draws content inside a creation preview in time-grid, month
|
|
216
|
+
* and multi-week modes. Month rows receive the full all-day range with an
|
|
217
|
+
* exclusive end, once per covered row. Requires onCreateEvent.
|
|
209
218
|
*/
|
|
210
219
|
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
211
220
|
/** Fires when an event drag begins. */
|
|
@@ -216,7 +225,7 @@ export interface CalendarProps<T = unknown>
|
|
|
216
225
|
* days dragged so the time of day and duration are kept.
|
|
217
226
|
*/
|
|
218
227
|
onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
|
|
219
|
-
/** Stable, unique
|
|
228
|
+
/** Stable, unique identity for the editing dialog and time-grid all-day bars across data refreshes. */
|
|
220
229
|
getEventId?: (event: CalendarEvent<T>) => string | number;
|
|
221
230
|
/** Tap a day's column header. */
|
|
222
231
|
onPressDateHeader?: (day: Date) => void;
|
|
@@ -453,20 +462,77 @@ function CalendarInner<T = unknown>(
|
|
|
453
462
|
const displayEvents = useMemo(() => {
|
|
454
463
|
let out: CalendarEvent<T>[] = events ?? EMPTY_EVENTS;
|
|
455
464
|
if (out.some((e) => e.recurrence)) {
|
|
456
|
-
|
|
457
|
-
//
|
|
458
|
-
//
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
465
|
+
const [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
|
|
466
|
+
// The range is the days on screen, which under a display zone are that
|
|
467
|
+
// zone's days: expand on its clock, over the instants those days cover.
|
|
468
|
+
out = timeZone
|
|
469
|
+
? expandRecurringEvents(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), {
|
|
470
|
+
timeZone,
|
|
471
|
+
})
|
|
472
|
+
: expandRecurringEvents(out, start, end);
|
|
464
473
|
}
|
|
465
474
|
if (timeZone) out = eventsInTimeZone(out, timeZone);
|
|
466
475
|
return out;
|
|
467
476
|
// `date.getTime()`: recompute on the instant, not a re-created Date identity.
|
|
468
477
|
}, [events, mode, date.getTime(), weekStartsOn, numberOfDays, numberOfWeeks, timeZone]);
|
|
469
478
|
|
|
479
|
+
// With a display zone the views lay out wall-clock copies of the events and
|
|
480
|
+
// report wall-clock dates. Hand back the consumer's own events and real
|
|
481
|
+
// instants. Whole days (`onPressDay`, a month sweep, ...) stay device-local
|
|
482
|
+
// dates, as `date` is, so only the time grid's cell callbacks convert.
|
|
483
|
+
// A time-grid move keeps the event's elapsed duration; a month drop keeps the
|
|
484
|
+
// clock time of both edges.
|
|
485
|
+
const timeGridMode = mode !== "month" && mode !== "multiweek";
|
|
486
|
+
const zoned = useMemo(() => {
|
|
487
|
+
if (!timeZone) {
|
|
488
|
+
return {
|
|
489
|
+
onPressEvent,
|
|
490
|
+
onDragStart,
|
|
491
|
+
onDragEvent,
|
|
492
|
+
onPressMore,
|
|
493
|
+
onPressTime: onPressCell,
|
|
494
|
+
onCreateTimed: onCreateEvent,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
const instant = (wallClock: Date) => fromZonedTime(wallClock, timeZone);
|
|
498
|
+
return {
|
|
499
|
+
onPressEvent:
|
|
500
|
+
onPressEvent && ((event: CalendarEvent<T>) => onPressEvent(zonedEventSource(event))),
|
|
501
|
+
onDragStart:
|
|
502
|
+
onDragStart && ((event: CalendarEvent<T>) => onDragStart(zonedEventSource(event))),
|
|
503
|
+
onDragEvent:
|
|
504
|
+
onDragEvent &&
|
|
505
|
+
((event: CalendarEvent<T>, start: Date, end: Date) => {
|
|
506
|
+
const bounds = zonedDragBounds(event, start, end, { keepDuration: timeGridMode });
|
|
507
|
+
// An edge dropped into an hour the zone's clock skips can leave no
|
|
508
|
+
// usable span; reject the drop, so the event snaps back.
|
|
509
|
+
if (!bounds) return false;
|
|
510
|
+
return onDragEvent(zonedEventSource(event), bounds.start, bounds.end);
|
|
511
|
+
}),
|
|
512
|
+
onPressMore:
|
|
513
|
+
onPressMore &&
|
|
514
|
+
((dayEvents: CalendarEvent<T>[], day: Date) =>
|
|
515
|
+
onPressMore(dayEvents.map(zonedEventSource), day)),
|
|
516
|
+
onPressTime: onPressCell && ((time: Date) => onPressCell(instant(time))),
|
|
517
|
+
onCreateTimed:
|
|
518
|
+
onCreateEvent &&
|
|
519
|
+
((start: Date, end: Date) => {
|
|
520
|
+
// A sweep that collapses inside a skipped hour creates nothing.
|
|
521
|
+
const range = fromZonedRange(start, end, timeZone);
|
|
522
|
+
if (range) onCreateEvent(range.start, range.end);
|
|
523
|
+
}),
|
|
524
|
+
};
|
|
525
|
+
}, [
|
|
526
|
+
timeZone,
|
|
527
|
+
timeGridMode,
|
|
528
|
+
onPressEvent,
|
|
529
|
+
onDragStart,
|
|
530
|
+
onDragEvent,
|
|
531
|
+
onPressMore,
|
|
532
|
+
onPressCell,
|
|
533
|
+
onCreateEvent,
|
|
534
|
+
]);
|
|
535
|
+
|
|
470
536
|
// PageDown / PageUp page the calendar when the consumer opts in with
|
|
471
537
|
// `onChangeDate`; keydowns bubble up from the focused grid to this handler.
|
|
472
538
|
const handlePageKeys = (e: ReactKeyboardEvent) => {
|
|
@@ -488,6 +554,8 @@ function CalendarInner<T = unknown>(
|
|
|
488
554
|
weekStartsOn={weekStartsOn}
|
|
489
555
|
hiddenDays={hiddenDays}
|
|
490
556
|
locale={locale}
|
|
557
|
+
now={now}
|
|
558
|
+
timeZone={timeZone}
|
|
491
559
|
labels={labels}
|
|
492
560
|
theme={theme}
|
|
493
561
|
className={className}
|
|
@@ -510,6 +578,8 @@ function CalendarInner<T = unknown>(
|
|
|
510
578
|
<Agenda<T>
|
|
511
579
|
events={displayEvents}
|
|
512
580
|
locale={locale}
|
|
581
|
+
now={now}
|
|
582
|
+
timeZone={timeZone}
|
|
513
583
|
ampm={ampm}
|
|
514
584
|
theme={theme}
|
|
515
585
|
height={height}
|
|
@@ -520,7 +590,7 @@ function CalendarInner<T = unknown>(
|
|
|
520
590
|
styles={styles}
|
|
521
591
|
renderEvent={renderScheduleEvent}
|
|
522
592
|
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
523
|
-
onPressEvent={onPressEvent}
|
|
593
|
+
onPressEvent={zoned.onPressEvent}
|
|
524
594
|
onPressDay={onPressDay}
|
|
525
595
|
/>
|
|
526
596
|
);
|
|
@@ -534,6 +604,8 @@ function CalendarInner<T = unknown>(
|
|
|
534
604
|
weekdayFormat={weekdayFormat}
|
|
535
605
|
highlightWeekends={highlightWeekends}
|
|
536
606
|
locale={locale}
|
|
607
|
+
now={now}
|
|
608
|
+
timeZone={timeZone}
|
|
537
609
|
labels={labels}
|
|
538
610
|
theme={theme}
|
|
539
611
|
className={className}
|
|
@@ -556,13 +628,14 @@ function CalendarInner<T = unknown>(
|
|
|
556
628
|
onPressDay={onPressDay}
|
|
557
629
|
onPressCell={onPressCell}
|
|
558
630
|
onCreateEvent={onCreateEvent}
|
|
631
|
+
renderCreateGhost={renderCreateGhost}
|
|
559
632
|
onSelectDrag={onSelectDrag}
|
|
560
|
-
onDragEvent={onDragEvent}
|
|
561
|
-
onDragStart={onDragStart}
|
|
633
|
+
onDragEvent={zoned.onDragEvent}
|
|
634
|
+
onDragStart={zoned.onDragStart}
|
|
562
635
|
eventStartEditable={eventStartEditable}
|
|
563
636
|
eventOverlap={eventOverlap}
|
|
564
|
-
onPressEvent={onPressEvent}
|
|
565
|
-
onPressMore={onPressMore}
|
|
637
|
+
onPressEvent={zoned.onPressEvent}
|
|
638
|
+
onPressMore={zoned.onPressMore}
|
|
566
639
|
renderEvent={renderMonthEvent}
|
|
567
640
|
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
568
641
|
/>
|
|
@@ -578,6 +651,8 @@ function CalendarInner<T = unknown>(
|
|
|
578
651
|
weekdayFormat={weekdayFormat}
|
|
579
652
|
highlightWeekends={highlightWeekends}
|
|
580
653
|
locale={locale}
|
|
654
|
+
now={now}
|
|
655
|
+
timeZone={timeZone}
|
|
581
656
|
labels={labels}
|
|
582
657
|
theme={theme}
|
|
583
658
|
className={className}
|
|
@@ -599,13 +674,14 @@ function CalendarInner<T = unknown>(
|
|
|
599
674
|
onPressDay={onPressDay}
|
|
600
675
|
onPressCell={onPressCell}
|
|
601
676
|
onCreateEvent={onCreateEvent}
|
|
677
|
+
renderCreateGhost={renderCreateGhost}
|
|
602
678
|
onSelectDrag={onSelectDrag}
|
|
603
|
-
onDragEvent={onDragEvent}
|
|
604
|
-
onDragStart={onDragStart}
|
|
679
|
+
onDragEvent={zoned.onDragEvent}
|
|
680
|
+
onDragStart={zoned.onDragStart}
|
|
605
681
|
eventStartEditable={eventStartEditable}
|
|
606
682
|
eventOverlap={eventOverlap}
|
|
607
|
-
onPressEvent={onPressEvent}
|
|
608
|
-
onPressMore={onPressMore}
|
|
683
|
+
onPressEvent={zoned.onPressEvent}
|
|
684
|
+
onPressMore={zoned.onPressMore}
|
|
609
685
|
renderEvent={renderMonthEvent}
|
|
610
686
|
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
611
687
|
/>
|
|
@@ -655,12 +731,12 @@ function CalendarInner<T = unknown>(
|
|
|
655
731
|
dragStepMinutes={dragStepMinutes}
|
|
656
732
|
touchDragDelay={touchDragDelay}
|
|
657
733
|
touchDragThreshold={touchDragThreshold}
|
|
658
|
-
onPressEvent={onPressEvent}
|
|
659
|
-
onPressCell={
|
|
660
|
-
onCreateEvent={
|
|
734
|
+
onPressEvent={zoned.onPressEvent}
|
|
735
|
+
onPressCell={zoned.onPressTime}
|
|
736
|
+
onCreateEvent={zoned.onCreateTimed}
|
|
661
737
|
renderCreateGhost={renderCreateGhost}
|
|
662
|
-
onDragStart={onDragStart}
|
|
663
|
-
onDragEvent={onDragEvent}
|
|
738
|
+
onDragStart={zoned.onDragStart}
|
|
739
|
+
onDragEvent={zoned.onDragEvent}
|
|
664
740
|
getEventId={getEventId}
|
|
665
741
|
onChangeDate={onChangeDate}
|
|
666
742
|
onPressDateHeader={onPressDateHeader}
|
package/src/MonthList.tsx
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
isBackgroundEvent,
|
|
13
13
|
type WeekdayFormat,
|
|
14
14
|
type WeekStartsOn,
|
|
15
|
+
type CalendarLabels,
|
|
15
16
|
} from "@super-calendar/core";
|
|
16
|
-
import type { CalendarLabels } from "@super-calendar/core";
|
|
17
17
|
import { type DomMonthEvent, MonthView, type MonthViewSlot } from "./MonthView";
|
|
18
18
|
import { createSlots, type SlotStyleProps } from "./slots";
|
|
19
19
|
import { type DomCalendarTheme, mergeDomTheme } from "./theme";
|