@ankhorage/zora 28.8.3 → 28.10.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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/capabilities/index.js +133 -5
- package/dist/capabilities/index.js.map +8 -7
- package/dist/constants/authoring.d.ts +4 -3
- package/dist/constants/authoring.d.ts.map +1 -1
- package/dist/constants/authoring.js +3 -0
- package/dist/constants/authoring.js.map +1 -1
- package/dist/features/accordion/accordionItemMeta.d.ts +1 -1
- package/dist/features/bottom-sheet/bottomSheetMeta.d.ts +1 -1
- package/dist/features/calendar/adapters/inbound/Calendar.d.ts +1 -1
- package/dist/features/calendar/adapters/inbound/Calendar.d.ts.map +1 -1
- package/dist/features/calendar/adapters/inbound/Calendar.js +207 -75
- package/dist/features/calendar/adapters/inbound/Calendar.js.map +1 -1
- package/dist/features/calendar/calendarMeta.d.ts +106 -4
- package/dist/features/calendar/calendarMeta.d.ts.map +1 -1
- package/dist/features/calendar/calendarMeta.js +44 -4
- package/dist/features/calendar/calendarMeta.js.map +1 -1
- package/dist/features/calendar/public.d.ts +1 -1
- package/dist/features/calendar/public.d.ts.map +1 -1
- package/dist/features/calendar/public.js.map +1 -1
- package/dist/features/card/cardMeta.d.ts +1 -1
- package/dist/features/card/mediaCardMeta.d.ts +1 -1
- package/dist/features/card/postCardMeta.d.ts +1 -1
- package/dist/features/chat/messageBubbleMeta.d.ts +1 -1
- package/dist/features/data-table/dataTableMeta.d.ts +10 -0
- package/dist/features/data-table/dataTableMeta.d.ts.map +1 -1
- package/dist/features/data-table/dataTableMeta.js +7 -0
- package/dist/features/data-table/dataTableMeta.js.map +1 -1
- package/dist/features/dialog/dialogMeta.d.ts +2 -2
- package/dist/features/gradient/gradientMeta.d.ts +1 -1
- package/dist/features/keyboard-avoiding-view/keyboardAvoidingViewMeta.d.ts +1 -1
- package/dist/features/layout/gridMeta.d.ts +1 -1
- package/dist/features/layout/screenMeta.d.ts +1 -1
- package/dist/features/layout/scrollViewMeta.d.ts +1 -1
- package/dist/features/layout/viewMeta.d.ts +1 -1
- package/dist/features/list/flatListMeta.d.ts +1 -1
- package/dist/features/list/sectionListMeta.d.ts +1 -1
- package/dist/features/master-detail/masterDetailMeta.d.ts +1 -1
- package/dist/features/popover/adapters/inbound/Popover.js +6 -3
- package/dist/features/popover/adapters/inbound/Popover.js.map +1 -1
- package/dist/features/popover/popoverMeta.d.ts +101 -0
- package/dist/features/popover/popoverMeta.d.ts.map +1 -0
- package/dist/features/popover/popoverMeta.js +78 -0
- package/dist/features/popover/popoverMeta.js.map +1 -0
- package/dist/features/reader/meta.d.ts +2 -2
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.d.ts.map +1 -1
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js +2 -0
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js.map +1 -1
- package/dist/features/registry/bindableComponentMeta.d.ts +2 -2
- package/dist/features/registry/componentMeta.d.ts.map +1 -1
- package/dist/features/registry/componentMeta.js +2 -0
- package/dist/features/registry/componentMeta.js.map +1 -1
- package/dist/features/scanner/meta.d.ts +2 -2
- package/dist/features/section/screenSectionMeta.d.ts +1 -1
- package/dist/features/surface/surfaceMeta.d.ts +1 -1
- package/dist/features/tabs/tabPanelMeta.d.ts +1 -1
- package/dist/readerFree.d.ts +1 -0
- package/dist/readerFree.d.ts.map +1 -1
- package/dist/readerFree.js +1 -0
- package/dist/readerFree.js.map +1 -1
- package/dist/types/calendar.d.ts +40 -19
- package/dist/types/calendar.d.ts.map +1 -1
- package/dist/types/calendar.js.map +1 -1
- package/dist/types/popover.d.ts +4 -1
- package/dist/types/popover.d.ts.map +1 -1
- package/dist/types/popover.js.map +1 -1
- package/package.json +102 -1
- package/src/constants/authoring.ts +3 -0
- package/src/features/calendar/adapters/inbound/Calendar.interaction.test.tsx +95 -0
- package/src/features/calendar/adapters/inbound/Calendar.tsx +425 -135
- package/src/features/calendar/calendarMeta.ts +44 -4
- package/src/features/calendar/public.test.ts +8 -5
- package/src/features/calendar/public.ts +4 -0
- package/src/features/data-table/adapters/inbound/DataTable.test.tsx +52 -1
- package/src/features/data-table/dataTableMeta.test.ts +8 -1
- package/src/features/data-table/dataTableMeta.ts +7 -0
- package/src/features/popover/adapters/inbound/Popover.tsx +17 -2
- package/src/features/popover/manifest.test.tsx +153 -0
- package/src/features/popover/popoverMeta.ts +79 -0
- package/src/features/popover/public.test.ts +2 -1
- package/src/features/registry/ZORA_BASE_COMPONENT_REGISTRY.ts +2 -0
- package/src/features/registry/componentMeta.test.ts +2 -0
- package/src/features/registry/componentMeta.ts +2 -0
- package/src/features/registry/featureManifest.test.ts +11 -0
- package/src/readerFree.ts +6 -0
- package/src/types/calendar.ts +44 -19
- package/src/types/popover.ts +5 -1
- package/src/webPackageExports.test.ts +1 -0
- package/web-dist/chunks/Accordion-59x6e7bs.js +200 -0
- package/web-dist/chunks/Accordion-q2yxtdzc.js +426 -0
- package/web-dist/components/calendar/Calendar.d.ts +2 -2
- package/web-dist/components/calendar/Calendar.dependency-2.d.ts +165 -0
- package/web-dist/components/calendar/Calendar.js +2 -1
- package/web-dist/components/calendar/Calendar.types-0.d.ts +45 -19
- package/web-dist/components/calendar/index.d.ts +1 -1
- package/web-dist/components/date-picker/DatePicker.js +2 -1
- package/web-dist/components/popover/Popover.js +10 -2
- package/web-dist/components/popover/Popover.types-0.d.ts +4 -1
- package/web-dist/components/time-grid/TimeGrid.js +4 -198
- package/web-dist/manifest.json +6 -2
- package/web-dist/chunks/Accordion-v3bmbnfh.js +0 -237
|
@@ -1,107 +1,219 @@
|
|
|
1
1
|
import type { GridRectItem } from '@ankhorage/grid-view';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
-
import type { CalendarProps } from '../../../../types/calendar';
|
|
4
|
+
import type { CalendarProps, CalendarView } from '../../../../types/calendar';
|
|
5
|
+
import type {
|
|
6
|
+
TemporalDate,
|
|
7
|
+
TemporalEvent,
|
|
8
|
+
TemporalTimedEvent,
|
|
9
|
+
TemporalTimeZone,
|
|
10
|
+
} from '../../../../types/temporal';
|
|
5
11
|
import { Button } from '../../../button/public';
|
|
6
12
|
import { GridView } from '../../../grid-view/public';
|
|
7
13
|
import { View } from '../../../layout/public';
|
|
8
14
|
import { withZoraThemeScope } from '../../../theme/adapters/inbound/withZoraThemeScope';
|
|
15
|
+
import { TimeGrid } from '../../../time-grid/public';
|
|
9
16
|
import { Text } from '../../../typography/public';
|
|
10
17
|
import { createCalendarMonth } from '../../application/createCalendarMonth';
|
|
11
18
|
import { isCalendarDateDisabled } from '../../application/isCalendarDateDisabled';
|
|
12
19
|
|
|
13
20
|
const GRID_COLUMNS = 7;
|
|
14
21
|
const GRID_ROWS = 6;
|
|
22
|
+
const MINUTES_PER_DAY = 24 * 60;
|
|
15
23
|
|
|
16
|
-
/*** Renders
|
|
24
|
+
/*** Renders controlled month, week, and day Calendar views through GridView and TimeGrid. */
|
|
17
25
|
export const Calendar = withZoraThemeScope(CalendarInner);
|
|
18
26
|
|
|
19
|
-
/*** Connects
|
|
20
|
-
function CalendarInner({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const displayedMonth = startOfLocalMonth(controlledDisplayedMonth ?? uncontrolledDisplayedMonth);
|
|
40
|
-
const cellSize = density === 'compact' ? 42 : 48;
|
|
41
|
-
const gridWidth = cellSize * GRID_COLUMNS;
|
|
42
|
-
const gridHeight = cellSize * GRID_ROWS;
|
|
43
|
-
const cells = React.useMemo(
|
|
44
|
-
() => createCalendarMonth(displayedMonth, weekStartsOn),
|
|
45
|
-
[displayedMonth, weekStartsOn],
|
|
46
|
-
);
|
|
47
|
-
const gridItems = React.useMemo<readonly GridRectItem[]>(
|
|
27
|
+
/*** Connects serializable manifest state and the DatePicker-compatible code API to Calendar views. */
|
|
28
|
+
function CalendarInner(props: CalendarProps) {
|
|
29
|
+
const {
|
|
30
|
+
defaultDisplayedDate,
|
|
31
|
+
defaultDisplayedMonth,
|
|
32
|
+
defaultView = 'month',
|
|
33
|
+
density = 'regular',
|
|
34
|
+
displayedDate: controlledDisplayedDate,
|
|
35
|
+
displayedMonth: controlledDisplayedMonth,
|
|
36
|
+
events = [],
|
|
37
|
+
locale,
|
|
38
|
+
onDateChange,
|
|
39
|
+
onDisplayedMonthChange,
|
|
40
|
+
onEventActivate,
|
|
41
|
+
onViewChange,
|
|
42
|
+
timeZone,
|
|
43
|
+
view: controlledView,
|
|
44
|
+
weekStartsOn = 0,
|
|
45
|
+
} = props;
|
|
46
|
+
const [uncontrolledDate, setUncontrolledDate] = React.useState(
|
|
48
47
|
() =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
id: cell.id,
|
|
52
|
-
width: cellSize,
|
|
53
|
-
x: (index % GRID_COLUMNS) * cellSize,
|
|
54
|
-
y: Math.floor(index / GRID_COLUMNS) * cellSize,
|
|
55
|
-
})),
|
|
56
|
-
[cellSize, cells],
|
|
48
|
+
parseCalendarDate(defaultDisplayedDate) ??
|
|
49
|
+
startOfLocalDay(defaultDisplayedMonth ?? props.selectedDate ?? props.minDate ?? new Date()),
|
|
57
50
|
);
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
()
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
() =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (controlledDisplayedMonth === undefined) setUncontrolledDisplayedMonth(nextMonth);
|
|
71
|
-
onDisplayedMonthChange?.(nextMonth);
|
|
51
|
+
const [uncontrolledView, setUncontrolledView] = React.useState<CalendarView>(defaultView);
|
|
52
|
+
const displayedDate =
|
|
53
|
+
parseCalendarDate(controlledDisplayedDate) ??
|
|
54
|
+
startOfLocalDay(controlledDisplayedMonth ?? uncontrolledDate);
|
|
55
|
+
const view = controlledView ?? uncontrolledView;
|
|
56
|
+
const setDisplayedDate = React.useCallback(
|
|
57
|
+
(value: Date) => {
|
|
58
|
+
const next = startOfLocalDay(value);
|
|
59
|
+
if (controlledDisplayedDate === undefined && controlledDisplayedMonth === undefined)
|
|
60
|
+
setUncontrolledDate(next);
|
|
61
|
+
onDisplayedMonthChange?.(startOfLocalMonth(next));
|
|
62
|
+
onDateChange?.({ date: formatCalendarDate(next) });
|
|
72
63
|
},
|
|
73
|
-
[controlledDisplayedMonth, onDisplayedMonthChange],
|
|
64
|
+
[controlledDisplayedDate, controlledDisplayedMonth, onDateChange, onDisplayedMonthChange],
|
|
65
|
+
);
|
|
66
|
+
const setView = React.useCallback(
|
|
67
|
+
(next: CalendarView) => {
|
|
68
|
+
if (controlledView === undefined) setUncontrolledView(next);
|
|
69
|
+
onViewChange?.({ view: next });
|
|
70
|
+
},
|
|
71
|
+
[controlledView, onViewChange],
|
|
72
|
+
);
|
|
73
|
+
const navigate = React.useCallback(
|
|
74
|
+
(offset: number) =>
|
|
75
|
+
setDisplayedDate(
|
|
76
|
+
view === 'month'
|
|
77
|
+
? addMonths(displayedDate, offset)
|
|
78
|
+
: addDays(displayedDate, offset * (view === 'week' ? 7 : 1)),
|
|
79
|
+
),
|
|
80
|
+
[displayedDate, setDisplayedDate, view],
|
|
74
81
|
);
|
|
75
|
-
const previousMonth = addMonths(displayedMonth, -1);
|
|
76
|
-
const nextMonth = addMonths(displayedMonth, 1);
|
|
77
|
-
|
|
78
82
|
return (
|
|
79
|
-
<View
|
|
83
|
+
<View
|
|
84
|
+
accessibilityLabel="Calendar"
|
|
85
|
+
gap={density === 'compact' ? 's' : 'm'}
|
|
86
|
+
testID={props.testID}
|
|
87
|
+
>
|
|
80
88
|
<View align="center" direction="row" justify="space-between">
|
|
81
89
|
<Button
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
onPress={() => setDisplayedMonth(previousMonth)}
|
|
90
|
+
interactionPolicy={props.interactionPolicy}
|
|
91
|
+
onPress={() => navigate(-1)}
|
|
85
92
|
size="s"
|
|
93
|
+
testID={withTestId(props.testID, 'previous')}
|
|
86
94
|
variant="ghost"
|
|
87
95
|
>
|
|
88
96
|
Previous
|
|
89
97
|
</Button>
|
|
90
98
|
<Text accessibilityRole="header" align="center" variant="label" weight="semiBold">
|
|
91
|
-
{
|
|
99
|
+
{formatViewLabel(displayedDate, locale, view)}
|
|
92
100
|
</Text>
|
|
93
101
|
<Button
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
onPress={() => setDisplayedMonth(nextMonth)}
|
|
102
|
+
interactionPolicy={props.interactionPolicy}
|
|
103
|
+
onPress={() => navigate(1)}
|
|
97
104
|
size="s"
|
|
105
|
+
testID={withTestId(props.testID, 'next')}
|
|
98
106
|
variant="ghost"
|
|
99
107
|
>
|
|
100
108
|
Next
|
|
101
109
|
</Button>
|
|
102
110
|
</View>
|
|
111
|
+
<View direction="row" justify="space-between">
|
|
112
|
+
{(['day', 'week', 'month'] as const).map((candidate) => (
|
|
113
|
+
<Button
|
|
114
|
+
key={candidate}
|
|
115
|
+
interactionPolicy={props.interactionPolicy}
|
|
116
|
+
onPress={() => setView(candidate)}
|
|
117
|
+
size="s"
|
|
118
|
+
testID={withTestId(props.testID, `view-${candidate}`)}
|
|
119
|
+
variant={view === candidate ? 'solid' : 'ghost'}
|
|
120
|
+
>
|
|
121
|
+
{candidate}
|
|
122
|
+
</Button>
|
|
123
|
+
))}
|
|
124
|
+
<Button
|
|
125
|
+
interactionPolicy={props.interactionPolicy}
|
|
126
|
+
onPress={() => setDisplayedDate(new Date())}
|
|
127
|
+
size="s"
|
|
128
|
+
testID={withTestId(props.testID, 'today')}
|
|
129
|
+
variant="ghost"
|
|
130
|
+
>
|
|
131
|
+
Today
|
|
132
|
+
</Button>
|
|
133
|
+
</View>
|
|
134
|
+
{view === 'month' ? (
|
|
135
|
+
<CalendarMonth
|
|
136
|
+
{...props}
|
|
137
|
+
activateEvent={(id) => onEventActivate?.({ eventId: id })}
|
|
138
|
+
cellSize={density === 'compact' ? 42 : 48}
|
|
139
|
+
displayedDate={displayedDate}
|
|
140
|
+
events={events}
|
|
141
|
+
timeZone={timeZone}
|
|
142
|
+
weekStartsOn={weekStartsOn}
|
|
143
|
+
onSelectDate={(date) => {
|
|
144
|
+
setDisplayedDate(date);
|
|
145
|
+
props.onSelectedDateChange?.(date);
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
) : (
|
|
149
|
+
<CalendarTimeView
|
|
150
|
+
activateEvent={(id) => onEventActivate?.({ eventId: id })}
|
|
151
|
+
displayedDate={displayedDate}
|
|
152
|
+
events={events}
|
|
153
|
+
interactionPolicy={props.interactionPolicy}
|
|
154
|
+
locale={locale}
|
|
155
|
+
testID={props.testID}
|
|
156
|
+
timeZone={timeZone}
|
|
157
|
+
view={view}
|
|
158
|
+
weekStartsOn={weekStartsOn}
|
|
159
|
+
/>
|
|
160
|
+
)}
|
|
161
|
+
</View>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/*** Renders the canonical GridView month geometry with stable event activation. */
|
|
166
|
+
function CalendarMonth({
|
|
167
|
+
activateEvent,
|
|
168
|
+
cellSize,
|
|
169
|
+
displayedDate,
|
|
170
|
+
events,
|
|
171
|
+
onSelectDate,
|
|
172
|
+
timeZone,
|
|
173
|
+
weekStartsOn,
|
|
174
|
+
...props
|
|
175
|
+
}: Omit<CalendarProps, 'displayedDate'> & {
|
|
176
|
+
readonly activateEvent: (eventId: string) => void;
|
|
177
|
+
readonly cellSize: number;
|
|
178
|
+
readonly displayedDate: Date;
|
|
179
|
+
readonly events: readonly TemporalEvent[];
|
|
180
|
+
readonly onSelectDate: (date: Date) => void;
|
|
181
|
+
readonly timeZone: TemporalTimeZone | undefined;
|
|
182
|
+
readonly weekStartsOn: number;
|
|
183
|
+
}) {
|
|
184
|
+
const cells = React.useMemo(
|
|
185
|
+
() => createCalendarMonth(displayedDate, weekStartsOn),
|
|
186
|
+
[displayedDate, weekStartsOn],
|
|
187
|
+
);
|
|
188
|
+
const gridItems = React.useMemo<readonly GridRectItem[]>(
|
|
189
|
+
() =>
|
|
190
|
+
cells.map((cell, index) => ({
|
|
191
|
+
height: cellSize,
|
|
192
|
+
id: cell.id,
|
|
193
|
+
width: cellSize,
|
|
194
|
+
x: (index % GRID_COLUMNS) * cellSize,
|
|
195
|
+
y: Math.floor(index / GRID_COLUMNS) * cellSize,
|
|
196
|
+
})),
|
|
197
|
+
[cellSize, cells],
|
|
198
|
+
);
|
|
199
|
+
const cellsById = React.useMemo(() => new Map(cells.map((cell) => [cell.id, cell])), [cells]);
|
|
200
|
+
const disabledDateIds = React.useMemo(
|
|
201
|
+
() => new Set((props.disabledDates ?? []).map(formatCalendarDate)),
|
|
202
|
+
[props.disabledDates],
|
|
203
|
+
);
|
|
204
|
+
const eventsByDate = React.useMemo(
|
|
205
|
+
() =>
|
|
206
|
+
createEventsByDate(
|
|
207
|
+
events,
|
|
208
|
+
cells.map((cell) => cell.date),
|
|
209
|
+
timeZone,
|
|
210
|
+
),
|
|
211
|
+
[cells, events, timeZone],
|
|
212
|
+
);
|
|
213
|
+
return (
|
|
214
|
+
<>
|
|
103
215
|
<View direction="row">
|
|
104
|
-
{
|
|
216
|
+
{createWeekdayLabels(props.locale, weekStartsOn).map((weekday) => (
|
|
105
217
|
<View key={weekday.id} width={cellSize}>
|
|
106
218
|
<Text align="center" emphasis="muted" variant="caption" weight="semiBold">
|
|
107
219
|
{weekday.label}
|
|
@@ -110,110 +222,288 @@ function CalendarInner({
|
|
|
110
222
|
))}
|
|
111
223
|
</View>
|
|
112
224
|
<GridView
|
|
113
|
-
contentHeight={
|
|
114
|
-
contentWidth={
|
|
115
|
-
height={
|
|
116
|
-
interactionPolicy={interactionPolicy}
|
|
225
|
+
contentHeight={cellSize * GRID_ROWS}
|
|
226
|
+
contentWidth={cellSize * GRID_COLUMNS}
|
|
227
|
+
height={cellSize * GRID_ROWS}
|
|
228
|
+
interactionPolicy={props.interactionPolicy}
|
|
117
229
|
items={gridItems}
|
|
118
230
|
overscanPixels={0}
|
|
119
231
|
renderItem={(item) => {
|
|
120
232
|
const cell = cellsById.get(item.id);
|
|
121
233
|
if (!cell) return null;
|
|
122
234
|
const selected =
|
|
123
|
-
selectedDate !== null &&
|
|
124
|
-
selectedDate !== undefined &&
|
|
125
|
-
isSameLocalDay(selectedDate, cell.date);
|
|
235
|
+
props.selectedDate !== null &&
|
|
236
|
+
props.selectedDate !== undefined &&
|
|
237
|
+
isSameLocalDay(props.selectedDate, cell.date);
|
|
126
238
|
const disabled = isCalendarDateDisabled({
|
|
127
239
|
date: cell.date,
|
|
128
240
|
disabledDateIds,
|
|
129
|
-
isDateDisabled,
|
|
130
|
-
maxDate,
|
|
131
|
-
minDate,
|
|
241
|
+
isDateDisabled: props.isDateDisabled,
|
|
242
|
+
maxDate: props.maxDate,
|
|
243
|
+
minDate: props.minDate,
|
|
132
244
|
});
|
|
133
|
-
const
|
|
134
|
-
if (!cell.inDisplayedMonth) setDisplayedMonth(cell.date);
|
|
135
|
-
onSelectedDateChange?.(cell.date);
|
|
136
|
-
};
|
|
245
|
+
const event = eventsByDate.get(cell.id)?.[0];
|
|
137
246
|
return (
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
247
|
+
<View gap="xxs">
|
|
248
|
+
<Button
|
|
249
|
+
accessibilityState={{ disabled, selected }}
|
|
250
|
+
color={selected ? 'primary' : 'neutral'}
|
|
251
|
+
disabled={disabled}
|
|
252
|
+
interactionPolicy={props.interactionPolicy}
|
|
253
|
+
onPress={() => onSelectDate(cell.date)}
|
|
254
|
+
size="s"
|
|
255
|
+
testID={withTestId(props.testID, `day-${cell.id}`)}
|
|
256
|
+
variant={selected ? 'solid' : cell.inDisplayedMonth ? 'ghost' : 'outline'}
|
|
257
|
+
>
|
|
258
|
+
{cell.date.getDate()}
|
|
259
|
+
</Button>
|
|
260
|
+
{props.density !== 'compact' && event ? (
|
|
261
|
+
<Button
|
|
262
|
+
interactionPolicy={props.interactionPolicy}
|
|
263
|
+
onPress={() => activateEvent(event.id)}
|
|
264
|
+
size="s"
|
|
265
|
+
testID={withTestId(props.testID, `event-${event.id}`)}
|
|
266
|
+
variant="outline"
|
|
267
|
+
>
|
|
268
|
+
{event.title}
|
|
269
|
+
</Button>
|
|
270
|
+
) : null}
|
|
271
|
+
</View>
|
|
150
272
|
);
|
|
151
273
|
}}
|
|
152
|
-
testID={testID
|
|
274
|
+
testID={withTestId(props.testID, 'grid')}
|
|
153
275
|
viewportInteraction="locked"
|
|
154
|
-
width={
|
|
276
|
+
width={cellSize * GRID_COLUMNS}
|
|
155
277
|
/>
|
|
156
|
-
|
|
278
|
+
</>
|
|
157
279
|
);
|
|
158
280
|
}
|
|
159
281
|
|
|
160
|
-
/***
|
|
282
|
+
/*** Renders day and week event lanes through the existing TimeGrid foundation. */
|
|
283
|
+
function CalendarTimeView({
|
|
284
|
+
activateEvent,
|
|
285
|
+
displayedDate,
|
|
286
|
+
events,
|
|
287
|
+
interactionPolicy,
|
|
288
|
+
locale,
|
|
289
|
+
testID,
|
|
290
|
+
timeZone,
|
|
291
|
+
view,
|
|
292
|
+
weekStartsOn,
|
|
293
|
+
}: {
|
|
294
|
+
readonly activateEvent: (eventId: string) => void;
|
|
295
|
+
readonly displayedDate: Date;
|
|
296
|
+
readonly events: readonly TemporalEvent[];
|
|
297
|
+
readonly interactionPolicy: CalendarProps['interactionPolicy'];
|
|
298
|
+
readonly locale: string | undefined;
|
|
299
|
+
readonly testID: string | undefined;
|
|
300
|
+
readonly timeZone: TemporalTimeZone | undefined;
|
|
301
|
+
readonly view: Exclude<CalendarView, 'month'>;
|
|
302
|
+
readonly weekStartsOn: number;
|
|
303
|
+
}) {
|
|
304
|
+
const dates = view === 'day' ? [displayedDate] : createWeek(displayedDate, weekStartsOn);
|
|
305
|
+
const eventById = new Map(events.map((event) => [event.id, event]));
|
|
306
|
+
return (
|
|
307
|
+
<TimeGrid
|
|
308
|
+
contentWidth={MINUTES_PER_DAY}
|
|
309
|
+
height={Math.min(56 * dates.length, 336)}
|
|
310
|
+
interactionPolicy={interactionPolicy}
|
|
311
|
+
intervals={createTimeGridIntervals(events, dates, timeZone)}
|
|
312
|
+
lanes={dates.map((date) => ({ height: 56, id: formatCalendarDate(date) }))}
|
|
313
|
+
onIntervalPress={(interval) => activateEvent(interval.id)}
|
|
314
|
+
overscanPixels={0}
|
|
315
|
+
renderInterval={(interval) => (
|
|
316
|
+
<Text variant="caption">{eventById.get(interval.id)?.title}</Text>
|
|
317
|
+
)}
|
|
318
|
+
renderLaneLabel={(lane) => (
|
|
319
|
+
<Text variant="caption">
|
|
320
|
+
{formatDayLabel(parseCalendarDate(lane.id) ?? displayedDate, locale)}
|
|
321
|
+
</Text>
|
|
322
|
+
)}
|
|
323
|
+
testID={withTestId(testID, view)}
|
|
324
|
+
width={320}
|
|
325
|
+
/>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/*** Produces weekday labels for one local calendar week. */
|
|
161
330
|
function createWeekdayLabels(locale: string | undefined, weekStartsOn: number) {
|
|
162
331
|
const formatter = new Intl.DateTimeFormat(locale, { weekday: 'short' });
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
sunday.getMonth(),
|
|
168
|
-
sunday.getDate() + ((weekStartsOn + index) % GRID_COLUMNS),
|
|
169
|
-
);
|
|
170
|
-
return { id: String(index), label: formatter.format(day) };
|
|
171
|
-
});
|
|
332
|
+
return Array.from({ length: GRID_COLUMNS }, (_, index) => ({
|
|
333
|
+
id: String(index),
|
|
334
|
+
label: formatter.format(addDays(new Date(2023, 0, 1), (weekStartsOn + index) % GRID_COLUMNS)),
|
|
335
|
+
}));
|
|
172
336
|
}
|
|
173
337
|
|
|
174
|
-
/***
|
|
175
|
-
function
|
|
176
|
-
|
|
338
|
+
/*** Creates the visible local dates for a week view. */
|
|
339
|
+
function createWeek(date: Date, weekStartsOn: number): readonly Date[] {
|
|
340
|
+
const first = addDays(date, -((date.getDay() - weekStartsOn + GRID_COLUMNS) % GRID_COLUMNS));
|
|
341
|
+
return Array.from({ length: GRID_COLUMNS }, (_, index) => addDays(first, index));
|
|
177
342
|
}
|
|
178
343
|
|
|
179
|
-
/***
|
|
180
|
-
function
|
|
181
|
-
|
|
344
|
+
/*** Indexes events by each displayed local date they intersect in the Calendar timezone. */
|
|
345
|
+
function createEventsByDate(
|
|
346
|
+
events: readonly TemporalEvent[],
|
|
347
|
+
dates: readonly Date[],
|
|
348
|
+
timeZone: TemporalTimeZone | undefined,
|
|
349
|
+
): ReadonlyMap<string, readonly TemporalEvent[]> {
|
|
350
|
+
return new Map(
|
|
351
|
+
dates.map((date) => [
|
|
352
|
+
formatCalendarDate(date),
|
|
353
|
+
events.filter((event) => eventIntersectsDate(event, formatCalendarDate(date), timeZone)),
|
|
354
|
+
]),
|
|
355
|
+
);
|
|
182
356
|
}
|
|
183
357
|
|
|
184
|
-
/***
|
|
185
|
-
function
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
358
|
+
/*** Maps timed events into TimeGrid lane-local minute coordinates. */
|
|
359
|
+
function createTimeGridIntervals(
|
|
360
|
+
events: readonly TemporalEvent[],
|
|
361
|
+
dates: readonly Date[],
|
|
362
|
+
timeZone: TemporalTimeZone | undefined,
|
|
363
|
+
) {
|
|
364
|
+
return dates.flatMap((date) =>
|
|
365
|
+
events.flatMap((event) => {
|
|
366
|
+
const dateId = formatCalendarDate(date);
|
|
367
|
+
if (!isTemporalTimedEvent(event)) return [];
|
|
368
|
+
if (!eventIntersectsDate(event, dateId, timeZone)) return [];
|
|
369
|
+
const zone = timeZone ?? event.range.timeZone;
|
|
370
|
+
const start = getZonedDateTimeParts(event.range.start, zone);
|
|
371
|
+
const end = getZonedDateTimeParts(resolveTimedEnd(event), zone);
|
|
372
|
+
const startMinute = start.date === dateId ? start.hour * 60 + start.minute : 0;
|
|
373
|
+
const endMinute = end.date === dateId ? end.hour * 60 + end.minute : MINUTES_PER_DAY;
|
|
374
|
+
return [
|
|
375
|
+
{
|
|
376
|
+
extent: Math.max(1, endMinute - startMinute),
|
|
377
|
+
id: event.id,
|
|
378
|
+
laneId: dateId,
|
|
379
|
+
start: startMinute,
|
|
380
|
+
},
|
|
381
|
+
];
|
|
382
|
+
}),
|
|
383
|
+
);
|
|
190
384
|
}
|
|
191
385
|
|
|
192
|
-
/***
|
|
193
|
-
function
|
|
194
|
-
|
|
386
|
+
/*** Reports whether an event overlaps one local Calendar date. */
|
|
387
|
+
function eventIntersectsDate(
|
|
388
|
+
event: TemporalEvent,
|
|
389
|
+
date: TemporalDate,
|
|
390
|
+
timeZone: TemporalTimeZone | undefined,
|
|
391
|
+
): boolean {
|
|
392
|
+
if (!isTemporalTimedEvent(event))
|
|
393
|
+
return (
|
|
394
|
+
event.range.start <= date &&
|
|
395
|
+
date < (event.range.end ?? addDaysToDate(event.range.start, event.range.duration))
|
|
396
|
+
);
|
|
397
|
+
const zone = timeZone ?? event.range.timeZone;
|
|
398
|
+
return (
|
|
399
|
+
getZonedDateTimeParts(event.range.start, zone).date <= date &&
|
|
400
|
+
date <= getZonedDateTimeParts(resolveTimedEnd(event), zone).date
|
|
401
|
+
);
|
|
195
402
|
}
|
|
196
403
|
|
|
197
|
-
/***
|
|
198
|
-
function
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const last = new Date(first.getFullYear(), first.getMonth() + 1, 0);
|
|
404
|
+
/*** Narrows a serializable Calendar event to the instant-based timed variant. */
|
|
405
|
+
function isTemporalTimedEvent(event: TemporalEvent): event is TemporalTimedEvent {
|
|
406
|
+
return event.range.allDay === false;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/*** Resolves the exclusive timed end, including the existing duration alternative. */
|
|
410
|
+
function resolveTimedEnd(event: TemporalTimedEvent): string {
|
|
205
411
|
return (
|
|
206
|
-
|
|
207
|
-
|
|
412
|
+
event.range.end ??
|
|
413
|
+
new Date(
|
|
414
|
+
Date.parse(event.range.start) + parseDurationMinutes(event.range.duration) * 60_000,
|
|
415
|
+
).toISOString()
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/*** Reads a UTC instant as a local date and wall-clock time in an IANA timezone. */
|
|
420
|
+
function getZonedDateTimeParts(
|
|
421
|
+
instant: string,
|
|
422
|
+
timeZone: TemporalTimeZone,
|
|
423
|
+
): { date: TemporalDate; hour: number; minute: number } {
|
|
424
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
425
|
+
day: '2-digit',
|
|
426
|
+
hour: '2-digit',
|
|
427
|
+
hourCycle: 'h23',
|
|
428
|
+
minute: '2-digit',
|
|
429
|
+
month: '2-digit',
|
|
430
|
+
timeZone,
|
|
431
|
+
year: 'numeric',
|
|
432
|
+
}).formatToParts(new Date(instant));
|
|
433
|
+
const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));
|
|
434
|
+
return {
|
|
435
|
+
date: `${values.year}-${values.month}-${values.day}` as TemporalDate,
|
|
436
|
+
hour: Number(values.hour),
|
|
437
|
+
minute: Number(values.minute),
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/*** Parses the bounded hour-and-minute duration form used for Calendar placement. */
|
|
442
|
+
function parseDurationMinutes(duration: string | undefined): number {
|
|
443
|
+
const match = /^PT(?:(\d+)H)?(?:(\d+)M)?$/.exec(duration ?? 'PT60M');
|
|
444
|
+
return match ? Number(match[1] ?? 0) * 60 + Number(match[2] ?? 0) : 60;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/*** Adds a date-only duration without introducing a timezone. */
|
|
448
|
+
function addDaysToDate(start: TemporalDate, duration: string | undefined): TemporalDate {
|
|
449
|
+
return formatCalendarDate(
|
|
450
|
+
addDays(
|
|
451
|
+
parseCalendarDate(start) ?? new Date(),
|
|
452
|
+
Math.max(1, Math.ceil(parseDurationMinutes(duration) / MINUTES_PER_DAY)),
|
|
453
|
+
),
|
|
208
454
|
);
|
|
209
455
|
}
|
|
210
456
|
|
|
211
|
-
/***
|
|
457
|
+
/*** Parses a local YYYY-MM-DD date without UTC conversion. */
|
|
458
|
+
function parseCalendarDate(value: string | undefined): Date | undefined {
|
|
459
|
+
if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return undefined;
|
|
460
|
+
const [year, month, day] = value.split('-').map(Number);
|
|
461
|
+
return year === undefined || month === undefined || day === undefined
|
|
462
|
+
? undefined
|
|
463
|
+
: new Date(year, month - 1, day);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/*** Moves a local calendar day. */
|
|
467
|
+
function addDays(date: Date, count: number): Date {
|
|
468
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + count);
|
|
469
|
+
}
|
|
470
|
+
/*** Moves a local month without day overflow. */
|
|
471
|
+
function addMonths(month: Date, count: number): Date {
|
|
472
|
+
const year = month.getFullYear();
|
|
473
|
+
const targetMonth = month.getMonth() + count;
|
|
474
|
+
const lastDay = new Date(year, targetMonth + 1, 0).getDate();
|
|
475
|
+
return new Date(year, targetMonth, Math.min(month.getDate(), lastDay));
|
|
476
|
+
}
|
|
477
|
+
/*** Normalizes a value to the first local day of its month. */
|
|
478
|
+
function startOfLocalMonth(value: Date): Date {
|
|
479
|
+
return new Date(value.getFullYear(), value.getMonth(), 1);
|
|
480
|
+
}
|
|
481
|
+
/*** Normalizes a value to its local calendar date. */
|
|
482
|
+
function startOfLocalDay(value: Date): Date {
|
|
483
|
+
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
|
|
484
|
+
}
|
|
485
|
+
/*** Formats a Date as a timezone-independent local calendar identifier. */
|
|
486
|
+
function formatCalendarDate(value: Date): TemporalDate {
|
|
487
|
+
return `${String(value.getFullYear()).padStart(4, '0')}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}` as TemporalDate;
|
|
488
|
+
}
|
|
489
|
+
/*** Compares local calendar dates using their canonical date-only identifiers. */
|
|
212
490
|
function isSameLocalDay(left: Date, right: Date): boolean {
|
|
213
491
|
return formatCalendarDate(left) === formatCalendarDate(right);
|
|
214
492
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
493
|
+
/*** Formats the controlled view title. */
|
|
494
|
+
function formatViewLabel(value: Date, locale: string | undefined, view: CalendarView): string {
|
|
495
|
+
return new Intl.DateTimeFormat(
|
|
496
|
+
locale,
|
|
497
|
+
view === 'month'
|
|
498
|
+
? { month: 'long', year: 'numeric' }
|
|
499
|
+
: { day: 'numeric', month: 'short', year: 'numeric' },
|
|
500
|
+
).format(value);
|
|
501
|
+
}
|
|
502
|
+
/*** Formats a compact lane label for day and week views. */
|
|
503
|
+
function formatDayLabel(value: Date, locale: string | undefined): string {
|
|
504
|
+
return new Intl.DateTimeFormat(locale, { day: 'numeric', weekday: 'short' }).format(value);
|
|
505
|
+
}
|
|
506
|
+
/*** Resolves a test identifier suffix only when a test root is provided. */
|
|
507
|
+
function withTestId(testID: string | undefined, suffix: string): string | undefined {
|
|
508
|
+
return testID === undefined ? undefined : `${testID}-${suffix}`;
|
|
219
509
|
}
|