@super-calendar/native 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/README.md +59 -0
- package/dist/{DefaultMonthEvent-ClIxUp__.d.ts → DefaultMonthEvent-B7xVeY7Q.d.ts} +29 -10
- package/dist/{DefaultMonthEvent-No5YhOcV.d.mts → DefaultMonthEvent-hGk7wSrr.d.mts} +29 -10
- package/dist/{MonthList-Dmp8JXvj.js → MonthList-C_NTufaK.js} +462 -92
- package/dist/{MonthList-D97JhM4F.mjs → MonthList-DdQxRhUy.mjs} +453 -95
- package/dist/index.d.mts +54 -13
- package/dist/index.d.ts +54 -13
- package/dist/index.js +245 -72
- package/dist/index.mjs +210 -74
- package/dist/picker.d.mts +1 -1
- package/dist/picker.d.ts +1 -1
- package/dist/picker.js +1 -1
- package/dist/picker.mjs +1 -1
- package/package.json +2 -2
- package/src/components/Agenda.tsx +19 -2
- package/src/components/AllDayLane.tsx +64 -37
- package/src/components/Calendar.tsx +173 -34
- package/src/components/MonthPager.tsx +212 -21
- package/src/components/MonthView.tsx +419 -118
- package/src/components/MultiWeekView.tsx +34 -0
- package/src/components/TimeGrid.tsx +60 -11
- package/src/components/YearView.tsx +12 -1
- package/src/index.tsx +17 -2
- package/src/types.ts +2 -2
- package/src/utils/holdWebDateDrag.ts +63 -0
package/dist/picker.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as mergeTheme, g as defaultTheme, h as darkTheme, i as MonthPager, m as CalendarThemeProvider, n as DefaultMonthEvent, o as MonthView, t as MonthList, v as useCalendarTheme } from "./MonthList-DdQxRhUy.mjs";
|
|
2
2
|
import { buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
|
|
3
3
|
export { CalendarThemeProvider, DefaultMonthEvent, MonthList, MonthPager, MonthView, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"description": "Gesture-driven, virtualized month / week / day calendar and date picker for React Native (and web via react-native-web).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agenda",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@super-calendar/core": "2.
|
|
67
|
+
"@super-calendar/core": "2.18.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@legendapp/list": ">=3",
|
|
@@ -5,7 +5,7 @@ import { StyleSheet, Text, type TextStyle, View, type ScrollViewProps } from "re
|
|
|
5
5
|
import { useCalendarTheme } from "../theme";
|
|
6
6
|
import type { CalendarEvent, EventKeyExtractor, RenderEvent } from "../types";
|
|
7
7
|
import { createSlots, type SlotStyleProps } from "../utils/slots";
|
|
8
|
-
import { getIsToday } from "@super-calendar/core";
|
|
8
|
+
import { getIsToday, nowInTimeZone } from "@super-calendar/core";
|
|
9
9
|
import { isAllDayEvent, isBackgroundEvent } from "@super-calendar/core";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -18,6 +18,13 @@ export type AgendaSlot = "dayHeader" | "eventRow" | "empty";
|
|
|
18
18
|
export type AgendaProps<T> = SlotStyleProps<AgendaSlot> & {
|
|
19
19
|
events: CalendarEvent<T>[];
|
|
20
20
|
locale?: Locale;
|
|
21
|
+
/**
|
|
22
|
+
* The instant whose calendar day is highlighted as today. Defaults to the
|
|
23
|
+
* device clock, and is read in `timeZone` when one is set.
|
|
24
|
+
*/
|
|
25
|
+
now?: Date;
|
|
26
|
+
/** Highlight today as it is in this IANA time zone (default: the device's). */
|
|
27
|
+
timeZone?: string;
|
|
21
28
|
renderEvent: RenderEvent<T>;
|
|
22
29
|
keyExtractor: EventKeyExtractor<T>;
|
|
23
30
|
onPressEvent: (event: CalendarEvent<T>) => void;
|
|
@@ -43,6 +50,8 @@ type Row<T> =
|
|
|
43
50
|
export function Agenda<T>({
|
|
44
51
|
events,
|
|
45
52
|
locale,
|
|
53
|
+
now,
|
|
54
|
+
timeZone,
|
|
46
55
|
renderEvent,
|
|
47
56
|
keyExtractor,
|
|
48
57
|
onPressEvent,
|
|
@@ -80,10 +89,14 @@ export function Agenda<T>({
|
|
|
80
89
|
}, [events, keyExtractor]);
|
|
81
90
|
|
|
82
91
|
const keyExtractorRow = useCallback((row: Row<T>) => row.key, []);
|
|
92
|
+
// The day, not the instant, so the rows re-render once a day.
|
|
93
|
+
const todayKey = startOfDay(nowInTimeZone(now, timeZone)).getTime();
|
|
83
94
|
const renderItem = useCallback(
|
|
84
95
|
({ item }: LegendListRenderItemProps<Row<T>>) => {
|
|
85
96
|
if (item.kind === "header") {
|
|
86
|
-
const isHighlighted = activeDate
|
|
97
|
+
const isHighlighted = activeDate
|
|
98
|
+
? isSameDay(item.date, activeDate)
|
|
99
|
+
: getIsToday(item.date, new Date(todayKey));
|
|
87
100
|
return (
|
|
88
101
|
<Text
|
|
89
102
|
{...slot<TextStyle>("dayHeader", {
|
|
@@ -116,6 +129,7 @@ export function Agenda<T>({
|
|
|
116
129
|
theme,
|
|
117
130
|
locale,
|
|
118
131
|
activeDate,
|
|
132
|
+
todayKey,
|
|
119
133
|
onPressDay,
|
|
120
134
|
onPressEvent,
|
|
121
135
|
onLongPressEvent,
|
|
@@ -143,6 +157,9 @@ export function Agenda<T>({
|
|
|
143
157
|
data={rows}
|
|
144
158
|
keyExtractor={keyExtractorRow}
|
|
145
159
|
renderItem={renderItem}
|
|
160
|
+
// LegendList keeps rendered rows until `data` or `extraData` changes, so
|
|
161
|
+
// the day that is today has to invalidate them.
|
|
162
|
+
extraData={todayKey}
|
|
146
163
|
// The public prop is data-agnostic; LegendList types the separator by row.
|
|
147
164
|
ItemSeparatorComponent={
|
|
148
165
|
(itemSeparatorComponent ?? undefined) as ComponentType<{ leadingItem: Row<T> }> | undefined
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { addDays, startOfDay } from "date-fns";
|
|
2
3
|
import { type LayoutChangeEvent, StyleSheet, View } from "react-native";
|
|
3
4
|
import { useCalendarTheme } from "../theme";
|
|
4
5
|
import type { CalendarEvent, CalendarMode, EventKeyExtractor, RenderEvent } from "../types";
|
|
5
6
|
import { useSlots } from "../utils/slots";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isAllDayEvent,
|
|
9
|
+
isBackgroundEvent,
|
|
10
|
+
layoutMonthWeek,
|
|
11
|
+
type MonthEventSegment,
|
|
12
|
+
} from "@super-calendar/core";
|
|
7
13
|
|
|
8
14
|
// The lane's slots are a subset of the TimeGrid slot union; typed locally so
|
|
9
15
|
// this file doesn't import the full TimeGrid type.
|
|
@@ -25,7 +31,7 @@ type AllDayLaneProps<T> = {
|
|
|
25
31
|
/**
|
|
26
32
|
* The all-day lane of one page, pinned above the scrolling hours. All-day
|
|
27
33
|
* events are excluded from the timed columns (see `layoutDayEvents`) and shown
|
|
28
|
-
* here, stacked
|
|
34
|
+
* here as continuous spans, stacked only when their dates overlap. Always rendered so every page reports a
|
|
29
35
|
* height, zero when the week has none, which the band above the grid follows
|
|
30
36
|
* live as you swipe; the "all-day" label lives in the hour column.
|
|
31
37
|
*/
|
|
@@ -44,60 +50,81 @@ export function AllDayLane<T>({
|
|
|
44
50
|
const slot = useSlots<AllDayLaneSlot>();
|
|
45
51
|
const RenderEventComponent = renderEvent;
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const spans = useMemo(() => {
|
|
54
|
+
const allDay = events.filter(
|
|
55
|
+
(event) =>
|
|
56
|
+
isAllDayEvent(event) &&
|
|
57
|
+
!isBackgroundEvent(event) &&
|
|
58
|
+
days.some(
|
|
59
|
+
(day) => event.start < addDays(startOfDay(day), 1) && event.end > startOfDay(day),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
const { segments, laneCount } = layoutMonthWeek(days, allDay);
|
|
63
|
+
const lanes: MonthEventSegment<T>[][] = Array.from({ length: laneCount }, () => []);
|
|
64
|
+
for (const segment of segments) lanes[segment.lane].push(segment);
|
|
65
|
+
return lanes.flat();
|
|
66
|
+
}, [days, events]);
|
|
54
67
|
|
|
55
68
|
return (
|
|
56
69
|
<View
|
|
57
70
|
{...slot("allDayLane", {
|
|
58
|
-
base: styles.lane,
|
|
71
|
+
base: [styles.lane, spans.length > 0 && { paddingVertical: 2 }],
|
|
59
72
|
themed: theme.containers.allDayLane,
|
|
60
73
|
})}
|
|
61
74
|
onLayout={onLayout}
|
|
62
75
|
>
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
{spans.map((segment, index) => {
|
|
77
|
+
const { event, startCol, endCol, lane, continuesBefore, continuesAfter } = segment;
|
|
78
|
+
const previous = spans[index - 1];
|
|
79
|
+
const previousEnd = previous?.lane === lane ? previous.endCol : -1;
|
|
80
|
+
const lastInLane = spans[index + 1]?.lane !== lane;
|
|
81
|
+
const remaining = lastInLane ? days.length - endCol - 1 : 0;
|
|
82
|
+
// Yoga wraps before pixel rounding. Leave subpixel slack at the row end
|
|
83
|
+
// so float32 accumulation cannot push a bar onto the following line.
|
|
84
|
+
const wrapSlack = lastInLane ? Math.min(0.5, dayWidth / 4) : 0;
|
|
85
|
+
return (
|
|
86
|
+
<View
|
|
87
|
+
key={keyExtractor(event, index)}
|
|
88
|
+
{...slot("allDayColumn", {
|
|
89
|
+
base: [
|
|
90
|
+
styles.column,
|
|
91
|
+
{
|
|
92
|
+
width: dayWidth * (endCol - startCol + 1),
|
|
93
|
+
marginLeft: dayWidth * (startCol - previousEnd - 1),
|
|
94
|
+
marginRight: dayWidth * remaining - wrapSlack,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
themed: theme.containers.allDayColumn,
|
|
98
|
+
})}
|
|
99
|
+
>
|
|
100
|
+
<View {...slot("allDayEvent", { base: styles.chip })}>
|
|
101
|
+
<RenderEventComponent
|
|
102
|
+
event={event}
|
|
103
|
+
mode={mode}
|
|
104
|
+
isAllDay
|
|
105
|
+
continuesBefore={continuesBefore}
|
|
106
|
+
continuesAfter={continuesAfter}
|
|
107
|
+
onPress={() => onPressEvent(event)}
|
|
108
|
+
onLongPress={onLongPressEvent ? () => onLongPressEvent(event) : undefined}
|
|
109
|
+
/>
|
|
87
110
|
</View>
|
|
88
|
-
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
})}
|
|
89
114
|
</View>
|
|
90
115
|
);
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
const styles = StyleSheet.create({
|
|
94
119
|
lane: {
|
|
120
|
+
// Keep keyed events as siblings so changing lanes preserves renderer state.
|
|
95
121
|
flexDirection: "row",
|
|
122
|
+
flexWrap: "wrap",
|
|
123
|
+
alignItems: "flex-start",
|
|
124
|
+
rowGap: 2,
|
|
96
125
|
},
|
|
97
126
|
column: {
|
|
98
|
-
paddingVertical: 2,
|
|
99
127
|
paddingHorizontal: 1,
|
|
100
|
-
gap: 2,
|
|
101
128
|
},
|
|
102
129
|
chip: {
|
|
103
130
|
minHeight: 18,
|
|
@@ -38,9 +38,14 @@ import type {
|
|
|
38
38
|
WeekStartsOn,
|
|
39
39
|
} from "../types";
|
|
40
40
|
import {
|
|
41
|
+
buildMultiWeekGrid,
|
|
41
42
|
type DateRange,
|
|
42
43
|
type EventAccessibilityLabeler,
|
|
43
44
|
eventsInTimeZone,
|
|
45
|
+
fromZonedRange,
|
|
46
|
+
fromZonedTime,
|
|
47
|
+
zonedDragBounds,
|
|
48
|
+
zonedEventSource,
|
|
44
49
|
expandRecurringEvents,
|
|
45
50
|
type WeekdayFormat,
|
|
46
51
|
getViewDays,
|
|
@@ -55,7 +60,7 @@ import { type SlotStyleProps } from "../utils/slots";
|
|
|
55
60
|
import { YearView, type YearViewSlot } from "./YearView";
|
|
56
61
|
import { Agenda, type AgendaSlot } from "./Agenda";
|
|
57
62
|
import { DefaultEvent } from "./DefaultEvent";
|
|
58
|
-
import {
|
|
63
|
+
import { DateRowsPager } from "./MonthPager";
|
|
59
64
|
import type { MonthViewSlot } from "./MonthView";
|
|
60
65
|
import {
|
|
61
66
|
DEFAULT_HOUR_HEIGHT,
|
|
@@ -142,8 +147,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
142
147
|
*/
|
|
143
148
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
144
149
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
150
|
+
* Content inside the drag-to-create preview in time grids, month, and multiweek.
|
|
151
|
+
* Month grids receive an all-day range with an exclusive end, repeated for
|
|
152
|
+
* each row the span covers. Requires `onCreateEvent`.
|
|
147
153
|
*/
|
|
148
154
|
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
149
155
|
/**
|
|
@@ -195,15 +201,18 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
195
201
|
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
196
202
|
hiddenDays?: number[];
|
|
197
203
|
/**
|
|
198
|
-
* Fixed "now" instant for the current-time indicator (doesn't tick)
|
|
199
|
-
*
|
|
200
|
-
*
|
|
204
|
+
* Fixed "now" instant for the current-time indicator (doesn't tick) and for
|
|
205
|
+
* the day highlighted as today in every mode, e.g. a server-synced clock.
|
|
206
|
+
* Defaults to the device clock, shifted into `timeZone` when one is set so
|
|
207
|
+
* both match the displayed events.
|
|
201
208
|
*/
|
|
202
209
|
now?: Date;
|
|
203
210
|
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
204
211
|
weekdayFormat?: WeekdayFormat;
|
|
205
212
|
/** Number of day columns when `mode="custom"`. Ignored by other modes. Default 1. */
|
|
206
213
|
numberOfDays?: number;
|
|
214
|
+
/** Consecutive full week rows for `mode="multiweek"` (default 2). */
|
|
215
|
+
numberOfWeeks?: number;
|
|
207
216
|
/**
|
|
208
217
|
* Last weekday of a `custom` partial-week view (0–6). When set, `custom` shows
|
|
209
218
|
* `weekStartsOn`…`weekEndsOn` of the visible week and pages by week, taking
|
|
@@ -344,7 +353,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
344
353
|
/**
|
|
345
354
|
* Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
|
|
346
355
|
* and independent of the device zone. Display-only: it shifts the wall-clock the
|
|
347
|
-
* grid lays out from, it doesn't change your `Date`s
|
|
356
|
+
* grid lays out from, it doesn't change your `Date`s, and callbacks report your
|
|
357
|
+
* own events and real instants. All-day events stay on their days. Uses
|
|
358
|
+
* `eventsInTimeZone`.
|
|
348
359
|
*/
|
|
349
360
|
timeZone?: string;
|
|
350
361
|
/** Highlight this date (header/cell/agenda) instead of the real "today". */
|
|
@@ -389,7 +400,13 @@ function visibleRange(
|
|
|
389
400
|
weekStartsOn: WeekStartsOn,
|
|
390
401
|
numberOfDays: number,
|
|
391
402
|
weekEndsOn?: WeekStartsOn,
|
|
403
|
+
numberOfWeeks = 2,
|
|
404
|
+
hiddenDays?: number[],
|
|
392
405
|
): [Date, Date] {
|
|
406
|
+
if (mode === "multiweek") {
|
|
407
|
+
const { visibleRange } = buildMultiWeekGrid(date, { numberOfWeeks, weekStartsOn, hiddenDays });
|
|
408
|
+
return [visibleRange.start, endOfDay(addDays(visibleRange.endExclusive, -1))];
|
|
409
|
+
}
|
|
393
410
|
if (mode === "month") {
|
|
394
411
|
return [
|
|
395
412
|
startOfWeek(startOfMonth(date), { weekStartsOn }),
|
|
@@ -415,7 +432,17 @@ function expansionRange(
|
|
|
415
432
|
weekStartsOn: WeekStartsOn,
|
|
416
433
|
numberOfDays: number,
|
|
417
434
|
weekEndsOn?: WeekStartsOn,
|
|
435
|
+
numberOfWeeks = 2,
|
|
418
436
|
): [Date, Date] {
|
|
437
|
+
if (mode === "multiweek") {
|
|
438
|
+
const { period } = buildMultiWeekGrid(date, { numberOfWeeks, weekStartsOn });
|
|
439
|
+
const previous = addWeeks(period.start, -numberOfWeeks);
|
|
440
|
+
const following = addWeeks(period.endExclusive, numberOfWeeks);
|
|
441
|
+
return [
|
|
442
|
+
Number.isFinite(previous.getTime()) ? previous : period.start,
|
|
443
|
+
endOfDay(addDays(Number.isFinite(following.getTime()) ? following : period.endExclusive, -1)),
|
|
444
|
+
];
|
|
445
|
+
}
|
|
419
446
|
if (mode === "month") {
|
|
420
447
|
return [
|
|
421
448
|
startOfWeek(startOfMonth(addMonths(date, -1)), { weekStartsOn }),
|
|
@@ -513,6 +540,7 @@ function CalendarInner<T>(
|
|
|
513
540
|
now,
|
|
514
541
|
weekdayFormat,
|
|
515
542
|
numberOfDays,
|
|
543
|
+
numberOfWeeks = 2,
|
|
516
544
|
weekEndsOn,
|
|
517
545
|
renderEvent = DefaultEvent,
|
|
518
546
|
eventAccessibilityLabel,
|
|
@@ -589,44 +617,138 @@ function CalendarInner<T>(
|
|
|
589
617
|
const displayEvents = useMemo(() => {
|
|
590
618
|
let out = events;
|
|
591
619
|
if (out.some((e) => e.recurrence)) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
620
|
+
const [start, end] = expansionRange(
|
|
621
|
+
mode,
|
|
622
|
+
date,
|
|
623
|
+
weekStartsOn,
|
|
624
|
+
numberOfDays ?? 1,
|
|
625
|
+
weekEndsOn,
|
|
626
|
+
numberOfWeeks,
|
|
627
|
+
);
|
|
628
|
+
// The range is the days on screen, which under a display zone are that
|
|
629
|
+
// zone's days: expand on its clock, over the instants those days cover.
|
|
630
|
+
out = timeZone
|
|
631
|
+
? expandRecurringEvents(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), {
|
|
632
|
+
timeZone,
|
|
633
|
+
})
|
|
634
|
+
: expandRecurringEvents(out, start, end);
|
|
600
635
|
}
|
|
601
636
|
if (timeZone) out = eventsInTimeZone(out, timeZone);
|
|
602
637
|
return out;
|
|
603
638
|
// `date.getTime()`: recompute on the instant, not a re-created Date identity.
|
|
604
|
-
}, [
|
|
639
|
+
}, [
|
|
640
|
+
events,
|
|
641
|
+
mode,
|
|
642
|
+
date.getTime(),
|
|
643
|
+
weekStartsOn,
|
|
644
|
+
numberOfDays,
|
|
645
|
+
weekEndsOn,
|
|
646
|
+
timeZone,
|
|
647
|
+
numberOfWeeks,
|
|
648
|
+
]);
|
|
605
649
|
|
|
606
650
|
// Swallow presses on disabled events once, so every view inherits the guard.
|
|
651
|
+
// With a display zone the views hold wall-clock copies of the events, so hand
|
|
652
|
+
// back the consumer's own event. Without one, events pass through untouched,
|
|
653
|
+
// including copies the consumer zoned themselves.
|
|
607
654
|
const handlePressEvent = useCallback(
|
|
608
655
|
(event: CalendarEvent<T>) => {
|
|
609
|
-
if (!event.disabled) onPressEvent(event);
|
|
656
|
+
if (!event.disabled) onPressEvent(timeZone ? zonedEventSource(event) : event);
|
|
610
657
|
},
|
|
611
|
-
[onPressEvent],
|
|
658
|
+
[onPressEvent, timeZone],
|
|
612
659
|
);
|
|
613
660
|
const handleLongPressEvent = useMemo(
|
|
614
661
|
() =>
|
|
615
662
|
onLongPressEvent
|
|
616
663
|
? (event: CalendarEvent<T>) => {
|
|
617
|
-
if (!event.disabled) onLongPressEvent(event);
|
|
664
|
+
if (!event.disabled) onLongPressEvent(timeZone ? zonedEventSource(event) : event);
|
|
618
665
|
}
|
|
619
666
|
: undefined,
|
|
620
|
-
[onLongPressEvent],
|
|
667
|
+
[onLongPressEvent, timeZone],
|
|
621
668
|
);
|
|
622
669
|
|
|
670
|
+
// The views also report wall-clock dates under a display zone. Convert them to
|
|
671
|
+
// real instants. Whole days (`onPressDay`, a month sweep, ...) stay
|
|
672
|
+
// device-local dates, as `date` is, so only the time grid's cell callbacks
|
|
673
|
+
// convert.
|
|
674
|
+
// A time-grid move keeps the event's elapsed duration; a month drop keeps the
|
|
675
|
+
// clock time of both edges.
|
|
676
|
+
const timeGridMode = mode !== "month" && mode !== "multiweek";
|
|
677
|
+
const zoned = useMemo(() => {
|
|
678
|
+
if (!timeZone) {
|
|
679
|
+
return {
|
|
680
|
+
onDragStart,
|
|
681
|
+
onDragEvent,
|
|
682
|
+
onPressMore,
|
|
683
|
+
onPressTime: onPressCell,
|
|
684
|
+
onLongPressTime: onLongPressCell,
|
|
685
|
+
onCreateTimed: onCreateEvent,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const instant = (wallClock: Date) => fromZonedTime(wallClock, timeZone);
|
|
689
|
+
return {
|
|
690
|
+
onDragStart:
|
|
691
|
+
onDragStart && ((event: CalendarEvent<T>) => onDragStart(zonedEventSource(event))),
|
|
692
|
+
onDragEvent:
|
|
693
|
+
onDragEvent &&
|
|
694
|
+
((event: CalendarEvent<T>, start: Date, end: Date) => {
|
|
695
|
+
const bounds = zonedDragBounds(event, start, end, { keepDuration: timeGridMode });
|
|
696
|
+
// An edge dropped into an hour the zone's clock skips can leave no
|
|
697
|
+
// usable span; reject the drop, so the event snaps back.
|
|
698
|
+
if (!bounds) return false;
|
|
699
|
+
return onDragEvent(zonedEventSource(event), bounds.start, bounds.end);
|
|
700
|
+
}),
|
|
701
|
+
onPressMore:
|
|
702
|
+
onPressMore &&
|
|
703
|
+
((dayEvents: CalendarEvent<T>[], day: Date) =>
|
|
704
|
+
onPressMore(dayEvents.map(zonedEventSource), day)),
|
|
705
|
+
onPressTime: onPressCell && ((time: Date) => onPressCell(instant(time))),
|
|
706
|
+
onLongPressTime: onLongPressCell && ((time: Date) => onLongPressCell(instant(time))),
|
|
707
|
+
onCreateTimed:
|
|
708
|
+
onCreateEvent &&
|
|
709
|
+
((start: Date, end: Date) => {
|
|
710
|
+
// A sweep that collapses inside a skipped hour creates nothing.
|
|
711
|
+
const range = fromZonedRange(start, end, timeZone);
|
|
712
|
+
if (range) onCreateEvent(range.start, range.end);
|
|
713
|
+
}),
|
|
714
|
+
};
|
|
715
|
+
}, [
|
|
716
|
+
timeZone,
|
|
717
|
+
timeGridMode,
|
|
718
|
+
onDragStart,
|
|
719
|
+
onDragEvent,
|
|
720
|
+
onPressMore,
|
|
721
|
+
onPressCell,
|
|
722
|
+
onLongPressCell,
|
|
723
|
+
onCreateEvent,
|
|
724
|
+
]);
|
|
725
|
+
|
|
623
726
|
// Echo every date change and, when asked, the full visible range derived from it.
|
|
624
727
|
const handleChangeDate = useCallback(
|
|
625
728
|
(next: Date) => {
|
|
626
729
|
onChangeDate(next);
|
|
627
|
-
onChangeDateRange?.(
|
|
730
|
+
onChangeDateRange?.(
|
|
731
|
+
visibleRange(
|
|
732
|
+
mode,
|
|
733
|
+
next,
|
|
734
|
+
weekStartsOn,
|
|
735
|
+
numberOfDays ?? 1,
|
|
736
|
+
weekEndsOn,
|
|
737
|
+
numberOfWeeks,
|
|
738
|
+
hiddenDays,
|
|
739
|
+
),
|
|
740
|
+
);
|
|
628
741
|
},
|
|
629
|
-
[
|
|
742
|
+
[
|
|
743
|
+
onChangeDate,
|
|
744
|
+
onChangeDateRange,
|
|
745
|
+
mode,
|
|
746
|
+
weekStartsOn,
|
|
747
|
+
numberOfDays,
|
|
748
|
+
weekEndsOn,
|
|
749
|
+
numberOfWeeks,
|
|
750
|
+
hiddenDays,
|
|
751
|
+
],
|
|
630
752
|
);
|
|
631
753
|
|
|
632
754
|
// Inject `eventCellStyle`, `ampm`, `showTime`, `ellipsizeTitle` and
|
|
@@ -677,13 +799,25 @@ function CalendarInner<T>(
|
|
|
677
799
|
eventAccessibilityLabel,
|
|
678
800
|
]);
|
|
679
801
|
|
|
802
|
+
const rowSpec = useMemo(
|
|
803
|
+
() =>
|
|
804
|
+
mode === "multiweek"
|
|
805
|
+
? { kind: "multiweek" as const, numberOfWeeks }
|
|
806
|
+
: {
|
|
807
|
+
kind: "month" as const,
|
|
808
|
+
showAdjacentMonths: showAdjacentMonths ?? true,
|
|
809
|
+
showSixWeeks: showSixWeeks ?? false,
|
|
810
|
+
},
|
|
811
|
+
[mode, numberOfWeeks, showAdjacentMonths, showSixWeeks],
|
|
812
|
+
);
|
|
680
813
|
const resolvedLabels = useMemo(() => resolveCalendarLabels(labels), [labels]);
|
|
681
814
|
|
|
682
815
|
return (
|
|
683
816
|
<CalendarThemeProvider value={mergedTheme}>
|
|
684
817
|
<CalendarLabelsContext.Provider value={resolvedLabels}>
|
|
685
|
-
{mode === "month" ? (
|
|
686
|
-
<
|
|
818
|
+
{mode === "month" || mode === "multiweek" ? (
|
|
819
|
+
<DateRowsPager
|
|
820
|
+
spec={rowSpec}
|
|
687
821
|
date={date}
|
|
688
822
|
events={displayEvents}
|
|
689
823
|
maxVisibleEventCount={maxVisibleEventCount}
|
|
@@ -693,14 +827,14 @@ function CalendarInner<T>(
|
|
|
693
827
|
hiddenDays={hiddenDays}
|
|
694
828
|
weekdayFormat={weekdayFormat}
|
|
695
829
|
locale={locale}
|
|
830
|
+
now={now}
|
|
831
|
+
timeZone={timeZone}
|
|
696
832
|
labels={labels}
|
|
697
833
|
sortedMonthView={sortedMonthView}
|
|
698
834
|
moreLabel={moreLabel}
|
|
699
|
-
showAdjacentMonths={showAdjacentMonths}
|
|
700
835
|
highlightWeekends={highlightWeekends}
|
|
701
836
|
disableMonthEventCellPress={disableMonthEventCellPress}
|
|
702
837
|
isRTL={isRTL}
|
|
703
|
-
showSixWeeks={showSixWeeks}
|
|
704
838
|
showTitle={showTitle}
|
|
705
839
|
activeDate={activeDate}
|
|
706
840
|
renderHeaderForMonthView={renderHeaderForMonthView}
|
|
@@ -713,11 +847,12 @@ function CalendarInner<T>(
|
|
|
713
847
|
onPressCell={onPressCell}
|
|
714
848
|
onPressEvent={handlePressEvent}
|
|
715
849
|
onLongPressEvent={handleLongPressEvent}
|
|
716
|
-
onPressMore={onPressMore}
|
|
850
|
+
onPressMore={zoned.onPressMore}
|
|
717
851
|
onCreateEvent={onCreateEvent}
|
|
852
|
+
renderCreateGhost={renderCreateGhost}
|
|
718
853
|
onSelectDrag={onSelectDrag}
|
|
719
|
-
onDragEvent={onDragEvent}
|
|
720
|
-
onDragStart={onDragStart}
|
|
854
|
+
onDragEvent={zoned.onDragEvent}
|
|
855
|
+
onDragStart={zoned.onDragStart}
|
|
721
856
|
eventStartEditable={eventStartEditable}
|
|
722
857
|
eventOverlap={eventOverlap}
|
|
723
858
|
selectedDates={selectedDates}
|
|
@@ -740,6 +875,8 @@ function CalendarInner<T>(
|
|
|
740
875
|
weekStartsOn={weekStartsOn}
|
|
741
876
|
hiddenDays={hiddenDays}
|
|
742
877
|
locale={locale}
|
|
878
|
+
now={now}
|
|
879
|
+
timeZone={timeZone}
|
|
743
880
|
labels={labels}
|
|
744
881
|
activeDate={activeDate}
|
|
745
882
|
selectedDates={selectedDates}
|
|
@@ -758,6 +895,8 @@ function CalendarInner<T>(
|
|
|
758
895
|
<Agenda
|
|
759
896
|
events={displayEvents}
|
|
760
897
|
locale={locale}
|
|
898
|
+
now={now}
|
|
899
|
+
timeZone={timeZone}
|
|
761
900
|
renderEvent={resolvedRenderEvent}
|
|
762
901
|
keyExtractor={keyExtractor}
|
|
763
902
|
onPressEvent={handlePressEvent}
|
|
@@ -823,14 +962,14 @@ function CalendarInner<T>(
|
|
|
823
962
|
swipeEnabled={swipeEnabled}
|
|
824
963
|
onPressEvent={handlePressEvent}
|
|
825
964
|
onLongPressEvent={handleLongPressEvent}
|
|
826
|
-
onDragEvent={onDragEvent}
|
|
965
|
+
onDragEvent={zoned.onDragEvent}
|
|
827
966
|
showDragHandle={showDragHandle}
|
|
828
|
-
onDragStart={onDragStart}
|
|
967
|
+
onDragStart={zoned.onDragStart}
|
|
829
968
|
dragStepMinutes={dragStepMinutes}
|
|
830
|
-
onPressCell={
|
|
969
|
+
onPressCell={zoned.onPressTime}
|
|
831
970
|
resetPageOnPressCell={resetPageOnPressCell}
|
|
832
|
-
onLongPressCell={
|
|
833
|
-
onCreateEvent={
|
|
971
|
+
onLongPressCell={zoned.onLongPressTime}
|
|
972
|
+
onCreateEvent={zoned.onCreateTimed}
|
|
834
973
|
renderCreateGhost={renderCreateGhost}
|
|
835
974
|
onPressDateHeader={onPressDateHeader}
|
|
836
975
|
onChangeDate={handleChangeDate}
|