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