@ankhorage/zora 28.9.0 → 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 +10 -0
- package/README.md +1 -1
- package/dist/capabilities/index.js +52 -5
- package/dist/capabilities/index.js.map +4 -4
- 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/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/types/calendar.d.ts +40 -19
- package/dist/types/calendar.d.ts.map +1 -1
- package/dist/types/calendar.js.map +1 -1
- package/package.json +76 -1
- 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/registry/componentMeta.test.ts +1 -0
- package/src/types/calendar.ts +44 -19
- 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/time-grid/TimeGrid.js +4 -198
- package/web-dist/manifest.json +6 -2
- package/web-dist/chunks/Accordion-v3bmbnfh.js +0 -237
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Calendar } from './Calendar.js';
|
|
2
|
-
export type { CalendarDensity, CalendarProps, CalendarView, CalendarWeekStart, TemporalAllDayEvent, TemporalAllDayRange, TemporalAvailability, TemporalDataValue, TemporalDate, TemporalDuration, TemporalEvent, TemporalEventStatus, TemporalInstant, TemporalInteroperabilityData, TemporalParticipant, TemporalRange, TemporalRecurrence, TemporalRecurrenceException, TemporalRecurrenceRule, TemporalReminder, TemporalTimedEvent, TemporalTimedRange, TemporalTimeZone, TemporalTone } from './Calendar.js';
|
|
2
|
+
export type { CalendarDateChangeEvent, CalendarDensity, CalendarEventActivateEvent, CalendarManifestProps, CalendarProps, CalendarView, CalendarViewChangeEvent, CalendarWeekStart, TemporalAllDayEvent, TemporalAllDayRange, TemporalAvailability, TemporalDataValue, TemporalDate, TemporalDuration, TemporalEvent, TemporalEventStatus, TemporalInstant, TemporalInteroperabilityData, TemporalParticipant, TemporalRange, TemporalRecurrence, TemporalRecurrenceException, TemporalRecurrenceRule, TemporalReminder, TemporalTimedEvent, TemporalTimedRange, TemporalTimeZone, TemporalTone } from './Calendar.js';
|
|
@@ -15,10 +15,11 @@ import {
|
|
|
15
15
|
View2
|
|
16
16
|
} from "../../chunks/Accordion-k9n1yse4.js";
|
|
17
17
|
import"../../chunks/Accordion-0zk0xp73.js";
|
|
18
|
+
import"../../chunks/Accordion-59x6e7bs.js";
|
|
18
19
|
import"../../chunks/Accordion-6gc0jw1n.js";
|
|
19
20
|
import {
|
|
20
21
|
Calendar2
|
|
21
|
-
} from "../../chunks/Accordion-
|
|
22
|
+
} from "../../chunks/Accordion-q2yxtdzc.js";
|
|
22
23
|
import {
|
|
23
24
|
PickerHeader,
|
|
24
25
|
PickerField
|
|
@@ -1,202 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import"../../chunks/Accordion-0zk0xp73.js";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../../chunks/Accordion-
|
|
5
|
-
import {
|
|
6
|
-
getLaneIntervalPlacement,
|
|
7
|
-
getVisibleLaneIntervals
|
|
8
|
-
} from "../../chunks/Accordion-tnyqv1xv.js";
|
|
9
|
-
|
|
10
|
-
// src/features/time-grid/adapters/inbound/TimeGrid.tsx
|
|
11
|
-
import React from "react";
|
|
12
|
-
import { Pressable, View } from "react-native-web";
|
|
13
|
-
|
|
14
|
-
// src/features/time-grid/application/resolveTimeGridNextFocusId.ts
|
|
15
|
-
function resolveTimeGridNextFocusId(placements, focusedId, direction) {
|
|
16
|
-
const focused = placements.find((placement) => placement.id === focusedId);
|
|
17
|
-
if (!focused)
|
|
18
|
-
return;
|
|
19
|
-
const candidates = placements.filter((placement) => {
|
|
20
|
-
if (direction === "left")
|
|
21
|
-
return placement.laneId === focused.laneId && placement.x < focused.x;
|
|
22
|
-
if (direction === "right")
|
|
23
|
-
return placement.laneId === focused.laneId && placement.x > focused.x;
|
|
24
|
-
if (direction === "up")
|
|
25
|
-
return placement.laneIndex < focused.laneIndex;
|
|
26
|
-
return placement.laneIndex > focused.laneIndex;
|
|
27
|
-
});
|
|
28
|
-
return candidates.sort((first, second) => resolveFocusDistance(first, focused, direction) - resolveFocusDistance(second, focused, direction)).at(0)?.id;
|
|
29
|
-
}
|
|
30
|
-
function resolveFocusDistance(candidate, focused, direction) {
|
|
31
|
-
const horizontal = direction === "left" || direction === "right";
|
|
32
|
-
const primary = horizontal ? Math.abs(candidate.x - focused.x) : Math.abs(candidate.laneIndex - focused.laneIndex);
|
|
33
|
-
const secondary = horizontal ? Math.abs(candidate.laneIndex - focused.laneIndex) : Math.abs(candidate.x - focused.x);
|
|
34
|
-
return primary * 1e6 + secondary;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/features/time-grid/application/resolveTimeGridVisibleIntervals.ts
|
|
38
|
-
function resolveTimeGridVisibleIntervals(lanes, intervals, viewport, overscanPixels) {
|
|
39
|
-
return getVisibleLaneIntervals(lanes, intervals, viewport, overscanPixels);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/features/time-grid/adapters/inbound/TimeGridKeyboardProxy.web.tsx
|
|
43
|
-
import { jsx } from "react/jsx-runtime";
|
|
44
|
-
function TimeGridKeyboardProxy({ children, onKeyDown }) {
|
|
45
|
-
return /* @__PURE__ */ jsx("div", {
|
|
46
|
-
onKeyDown: (event) => {
|
|
47
|
-
if (onKeyDown(event.key))
|
|
48
|
-
event.preventDefault();
|
|
49
|
-
},
|
|
50
|
-
style: { display: "flex", flex: 1 },
|
|
51
|
-
children
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/features/time-grid/adapters/inbound/TimeGrid.tsx
|
|
56
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
57
|
-
function TimeGrid({
|
|
58
|
-
contentWidth,
|
|
59
|
-
focusedIntervalId,
|
|
60
|
-
height,
|
|
61
|
-
interactionPolicy,
|
|
62
|
-
intervals,
|
|
63
|
-
lanes,
|
|
64
|
-
onFocusedIntervalIdChange,
|
|
65
|
-
onIntervalPress,
|
|
66
|
-
onViewportChange,
|
|
67
|
-
onVisibleIntervalIdsChange,
|
|
68
|
-
overscanPixels,
|
|
69
|
-
renderInterval,
|
|
70
|
-
renderLaneLabel,
|
|
71
|
-
revealPaddingPixels,
|
|
72
|
-
selectedIntervalIds = [],
|
|
73
|
-
testID,
|
|
74
|
-
width,
|
|
75
|
-
zoom
|
|
76
|
-
}) {
|
|
77
|
-
const scale = Math.max(0.01, zoom ?? 1);
|
|
78
|
-
const [scrollOffsets, setScrollOffsets] = React.useState(() => ({
|
|
79
|
-
offsetX: 0,
|
|
80
|
-
offsetY: 0
|
|
81
|
-
}));
|
|
82
|
-
const viewport = React.useMemo(() => ({
|
|
83
|
-
...scrollOffsets,
|
|
84
|
-
height,
|
|
85
|
-
pixelsPerUnitX: scale,
|
|
86
|
-
pixelsPerUnitY: scale,
|
|
87
|
-
width
|
|
88
|
-
}), [height, scale, scrollOffsets, width]);
|
|
89
|
-
const intervalById = React.useMemo(() => new Map(intervals.map((interval) => [interval.id, interval])), [intervals]);
|
|
90
|
-
const selectedIds = React.useMemo(() => new Set(selectedIntervalIds), [selectedIntervalIds]);
|
|
91
|
-
const contentHeight = React.useMemo(() => lanes.reduce((total, lane) => total + lane.height, 0), [lanes]);
|
|
92
|
-
const visibleIntervals = React.useMemo(() => resolveTimeGridVisibleIntervals(lanes, intervals, viewport, overscanPixels), [intervals, lanes, overscanPixels, viewport]);
|
|
93
|
-
const focusedPlacement = React.useMemo(() => {
|
|
94
|
-
const focusedInterval = intervals.find((interval) => interval.id === focusedIntervalId);
|
|
95
|
-
return focusedInterval ? getLaneIntervalPlacement(lanes, focusedInterval) : undefined;
|
|
96
|
-
}, [focusedIntervalId, intervals, lanes]);
|
|
97
|
-
const gridItems = React.useMemo(() => focusedPlacement && !visibleIntervals.some((interval) => interval.id === focusedPlacement.id) ? [...visibleIntervals, focusedPlacement] : visibleIntervals, [focusedPlacement, visibleIntervals]);
|
|
98
|
-
const labelIntervals = React.useMemo(() => lanes.map((lane) => ({
|
|
99
|
-
extent: contentWidth,
|
|
100
|
-
id: `lane-label-${lane.id}`,
|
|
101
|
-
laneId: lane.id,
|
|
102
|
-
start: 0
|
|
103
|
-
})), [contentWidth, lanes]);
|
|
104
|
-
const visibleLabels = React.useMemo(() => resolveTimeGridVisibleIntervals(lanes, labelIntervals, viewport, overscanPixels), [labelIntervals, lanes, overscanPixels, viewport]);
|
|
105
|
-
const handleViewportChange = React.useCallback((nextViewport) => {
|
|
106
|
-
setScrollOffsets((current) => current.offsetX === nextViewport.offsetX && current.offsetY === nextViewport.offsetY ? current : { offsetX: nextViewport.offsetX, offsetY: nextViewport.offsetY });
|
|
107
|
-
onViewportChange?.(nextViewport);
|
|
108
|
-
}, [onViewportChange]);
|
|
109
|
-
const resolveNextFocusId = React.useCallback((intervalId, direction) => {
|
|
110
|
-
const allIntervals = resolveTimeGridVisibleIntervals(lanes, intervals, {
|
|
111
|
-
height: contentHeight,
|
|
112
|
-
offsetX: 0,
|
|
113
|
-
offsetY: 0,
|
|
114
|
-
pixelsPerUnitX: 1,
|
|
115
|
-
pixelsPerUnitY: 1,
|
|
116
|
-
width: contentWidth
|
|
117
|
-
});
|
|
118
|
-
return resolveTimeGridNextFocusId(allIntervals, intervalId, direction);
|
|
119
|
-
}, [contentHeight, contentWidth, intervals, lanes]);
|
|
120
|
-
return /* @__PURE__ */ jsxs(View, {
|
|
121
|
-
style: { flexDirection: "row", height, width },
|
|
122
|
-
testID,
|
|
123
|
-
children: [
|
|
124
|
-
renderLaneLabel ? /* @__PURE__ */ jsx2(View, {
|
|
125
|
-
accessibilityElementsHidden: true,
|
|
126
|
-
pointerEvents: "none",
|
|
127
|
-
style: { height, overflow: "hidden" },
|
|
128
|
-
children: visibleLabels.map((placement) => {
|
|
129
|
-
const lane = lanes[placement.laneIndex];
|
|
130
|
-
if (!lane)
|
|
131
|
-
return null;
|
|
132
|
-
return /* @__PURE__ */ jsx2(View, {
|
|
133
|
-
style: {
|
|
134
|
-
height: placement.height * scale,
|
|
135
|
-
position: "absolute",
|
|
136
|
-
top: (placement.y - viewport.offsetY) * scale
|
|
137
|
-
},
|
|
138
|
-
testID: testID === undefined ? undefined : `${testID}-lane-label-${lane.id}`,
|
|
139
|
-
children: renderLaneLabel(lane)
|
|
140
|
-
}, lane.id);
|
|
141
|
-
})
|
|
142
|
-
}) : null,
|
|
143
|
-
/* @__PURE__ */ jsx2(GridView2, {
|
|
144
|
-
contentHeight,
|
|
145
|
-
contentWidth,
|
|
146
|
-
focusedItemId: focusedIntervalId,
|
|
147
|
-
height,
|
|
148
|
-
interactionPolicy,
|
|
149
|
-
items: gridItems,
|
|
150
|
-
onViewportChange: handleViewportChange,
|
|
151
|
-
onVisibleItemIdsChange: onVisibleIntervalIdsChange,
|
|
152
|
-
overscanPixels,
|
|
153
|
-
renderItem: (placement) => {
|
|
154
|
-
const interval = intervalById.get(placement.id);
|
|
155
|
-
if (!interval)
|
|
156
|
-
return null;
|
|
157
|
-
const selected = selectedIds.has(interval.id);
|
|
158
|
-
return /* @__PURE__ */ jsx2(TimeGridKeyboardProxy, {
|
|
159
|
-
onKeyDown: (key) => {
|
|
160
|
-
const direction = resolveKeyboardDirection(key);
|
|
161
|
-
const nextId = direction === undefined ? undefined : resolveNextFocusId(interval.id, direction);
|
|
162
|
-
if (!nextId)
|
|
163
|
-
return false;
|
|
164
|
-
onFocusedIntervalIdChange?.(nextId);
|
|
165
|
-
return true;
|
|
166
|
-
},
|
|
167
|
-
children: /* @__PURE__ */ jsx2(Pressable, {
|
|
168
|
-
accessibilityLabel: `Interval ${interval.id}`,
|
|
169
|
-
accessibilityRole: "button",
|
|
170
|
-
disabled: interactionPolicy === "passive",
|
|
171
|
-
onPress: () => {
|
|
172
|
-
onFocusedIntervalIdChange?.(interval.id);
|
|
173
|
-
onIntervalPress?.(interval);
|
|
174
|
-
},
|
|
175
|
-
style: { flex: 1 },
|
|
176
|
-
testID: testID === undefined ? undefined : `${testID}-interval-${interval.id}`,
|
|
177
|
-
children: renderInterval(interval, selected)
|
|
178
|
-
})
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
revealPaddingPixels,
|
|
182
|
-
testID: testID === undefined ? undefined : `${testID}-viewport`,
|
|
183
|
-
width,
|
|
184
|
-
zoom
|
|
185
|
-
})
|
|
186
|
-
]
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
function resolveKeyboardDirection(key) {
|
|
190
|
-
if (key === "ArrowDown")
|
|
191
|
-
return "down";
|
|
192
|
-
if (key === "ArrowLeft")
|
|
193
|
-
return "left";
|
|
194
|
-
if (key === "ArrowRight")
|
|
195
|
-
return "right";
|
|
196
|
-
if (key === "ArrowUp")
|
|
197
|
-
return "up";
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
4
|
+
TimeGrid2
|
|
5
|
+
} from "../../chunks/Accordion-59x6e7bs.js";
|
|
200
6
|
export {
|
|
201
|
-
TimeGrid
|
|
7
|
+
TimeGrid2 as TimeGrid
|
|
202
8
|
};
|
package/web-dist/manifest.json
CHANGED
|
@@ -483,18 +483,20 @@
|
|
|
483
483
|
"components/calendar/Calendar.d.ts",
|
|
484
484
|
"components/calendar/Calendar.dependency-0.d.ts",
|
|
485
485
|
"components/calendar/Calendar.dependency-1.d.ts",
|
|
486
|
+
"components/calendar/Calendar.dependency-2.d.ts",
|
|
486
487
|
"components/calendar/Calendar.types-0.d.ts",
|
|
487
488
|
"components/calendar/Calendar.types-1.d.ts",
|
|
488
489
|
"components/calendar/index.js",
|
|
489
490
|
"components/calendar/index.d.ts",
|
|
490
491
|
"chunks/Accordion-0zk0xp73.js",
|
|
492
|
+
"chunks/Accordion-59x6e7bs.js",
|
|
491
493
|
"chunks/Accordion-6gc0jw1n.js",
|
|
492
494
|
"chunks/Accordion-e6ettgh0.js",
|
|
493
495
|
"chunks/Accordion-e8tapf5a.js",
|
|
494
496
|
"chunks/Accordion-fkftnxgw.js",
|
|
495
497
|
"chunks/Accordion-k9n1yse4.js",
|
|
498
|
+
"chunks/Accordion-q2yxtdzc.js",
|
|
496
499
|
"chunks/Accordion-tnyqv1xv.js",
|
|
497
|
-
"chunks/Accordion-v3bmbnfh.js",
|
|
498
500
|
"chunks/Accordion-x1ze1wvk.js",
|
|
499
501
|
"chunks/Accordion-zhgty1ae.js"
|
|
500
502
|
],
|
|
@@ -1011,6 +1013,7 @@
|
|
|
1011
1013
|
"components/date-picker/index.js",
|
|
1012
1014
|
"components/date-picker/index.d.ts",
|
|
1013
1015
|
"chunks/Accordion-0zk0xp73.js",
|
|
1016
|
+
"chunks/Accordion-59x6e7bs.js",
|
|
1014
1017
|
"chunks/Accordion-6gc0jw1n.js",
|
|
1015
1018
|
"chunks/Accordion-7pgh8q4h.js",
|
|
1016
1019
|
"chunks/Accordion-e6ettgh0.js",
|
|
@@ -1018,8 +1021,8 @@
|
|
|
1018
1021
|
"chunks/Accordion-fkftnxgw.js",
|
|
1019
1022
|
"chunks/Accordion-k9n1yse4.js",
|
|
1020
1023
|
"chunks/Accordion-pr1tv6jx.js",
|
|
1024
|
+
"chunks/Accordion-q2yxtdzc.js",
|
|
1021
1025
|
"chunks/Accordion-tnyqv1xv.js",
|
|
1022
|
-
"chunks/Accordion-v3bmbnfh.js",
|
|
1023
1026
|
"chunks/Accordion-x1ze1wvk.js",
|
|
1024
1027
|
"chunks/Accordion-zhgty1ae.js"
|
|
1025
1028
|
],
|
|
@@ -3143,6 +3146,7 @@
|
|
|
3143
3146
|
"components/time-grid/index.js",
|
|
3144
3147
|
"components/time-grid/index.d.ts",
|
|
3145
3148
|
"chunks/Accordion-0zk0xp73.js",
|
|
3149
|
+
"chunks/Accordion-59x6e7bs.js",
|
|
3146
3150
|
"chunks/Accordion-tnyqv1xv.js"
|
|
3147
3151
|
],
|
|
3148
3152
|
"sourceKind": "public"
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {
|
|
3
|
-
withZoraThemeScope
|
|
4
|
-
} from "./Accordion-zhgty1ae.js";
|
|
5
|
-
import {
|
|
6
|
-
Button2
|
|
7
|
-
} from "./Accordion-e6ettgh0.js";
|
|
8
|
-
import {
|
|
9
|
-
View2
|
|
10
|
-
} from "./Accordion-k9n1yse4.js";
|
|
11
|
-
import {
|
|
12
|
-
GridView2
|
|
13
|
-
} from "./Accordion-0zk0xp73.js";
|
|
14
|
-
import {
|
|
15
|
-
Text2
|
|
16
|
-
} from "./Accordion-6gc0jw1n.js";
|
|
17
|
-
|
|
18
|
-
// src/features/calendar/adapters/inbound/Calendar.tsx
|
|
19
|
-
import React from "react";
|
|
20
|
-
|
|
21
|
-
// src/features/calendar/application/createCalendarMonth.ts
|
|
22
|
-
function createCalendarMonth(month, weekStartsOn) {
|
|
23
|
-
const firstDay = startOfLocalMonth(month);
|
|
24
|
-
const leadingDays = (firstDay.getDay() - weekStartsOn + 7) % 7;
|
|
25
|
-
return Array.from({ length: 42 }, (_, index) => {
|
|
26
|
-
const date = new Date(firstDay.getFullYear(), firstDay.getMonth(), index - leadingDays + 1);
|
|
27
|
-
return {
|
|
28
|
-
date,
|
|
29
|
-
id: formatLocalDate(date),
|
|
30
|
-
inDisplayedMonth: date.getMonth() === firstDay.getMonth()
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function formatLocalDate(value) {
|
|
35
|
-
const year = String(value.getFullYear()).padStart(4, "0");
|
|
36
|
-
const month = String(value.getMonth() + 1).padStart(2, "0");
|
|
37
|
-
const day = String(value.getDate()).padStart(2, "0");
|
|
38
|
-
return `${year}-${month}-${day}`;
|
|
39
|
-
}
|
|
40
|
-
function startOfLocalMonth(value) {
|
|
41
|
-
return new Date(value.getFullYear(), value.getMonth(), 1);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/features/calendar/application/isCalendarDateDisabled.ts
|
|
45
|
-
function isCalendarDateDisabled({
|
|
46
|
-
date,
|
|
47
|
-
disabledDateIds,
|
|
48
|
-
isDateDisabled,
|
|
49
|
-
maxDate,
|
|
50
|
-
minDate
|
|
51
|
-
}) {
|
|
52
|
-
return minDate !== undefined && compareLocalDates(date, minDate) < 0 || maxDate !== undefined && compareLocalDates(date, maxDate) > 0 || disabledDateIds.has(formatCalendarDate(date)) || isDateDisabled?.(date) === true;
|
|
53
|
-
}
|
|
54
|
-
function compareLocalDates(left, right) {
|
|
55
|
-
return startOfLocalDay(left).getTime() - startOfLocalDay(right).getTime();
|
|
56
|
-
}
|
|
57
|
-
function startOfLocalDay(value) {
|
|
58
|
-
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
|
|
59
|
-
}
|
|
60
|
-
function formatCalendarDate(value) {
|
|
61
|
-
const year = String(value.getFullYear()).padStart(4, "0");
|
|
62
|
-
const month = String(value.getMonth() + 1).padStart(2, "0");
|
|
63
|
-
const day = String(value.getDate()).padStart(2, "0");
|
|
64
|
-
return `${year}-${month}-${day}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/features/calendar/adapters/inbound/Calendar.tsx
|
|
68
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
69
|
-
var GRID_COLUMNS = 7;
|
|
70
|
-
var GRID_ROWS = 6;
|
|
71
|
-
var Calendar2 = withZoraThemeScope(CalendarInner);
|
|
72
|
-
function CalendarInner({
|
|
73
|
-
defaultDisplayedMonth,
|
|
74
|
-
density = "regular",
|
|
75
|
-
disabledDates = [],
|
|
76
|
-
displayedMonth: controlledDisplayedMonth,
|
|
77
|
-
interactionPolicy,
|
|
78
|
-
isDateDisabled,
|
|
79
|
-
locale,
|
|
80
|
-
maxDate,
|
|
81
|
-
minDate,
|
|
82
|
-
onDisplayedMonthChange,
|
|
83
|
-
onSelectedDateChange,
|
|
84
|
-
selectedDate,
|
|
85
|
-
testID,
|
|
86
|
-
weekStartsOn = 0
|
|
87
|
-
}) {
|
|
88
|
-
const [uncontrolledDisplayedMonth, setUncontrolledDisplayedMonth] = React.useState(() => startOfLocalMonth2(defaultDisplayedMonth ?? selectedDate ?? minDate ?? new Date));
|
|
89
|
-
const displayedMonth = startOfLocalMonth2(controlledDisplayedMonth ?? uncontrolledDisplayedMonth);
|
|
90
|
-
const cellSize = density === "compact" ? 42 : 48;
|
|
91
|
-
const gridWidth = cellSize * GRID_COLUMNS;
|
|
92
|
-
const gridHeight = cellSize * GRID_ROWS;
|
|
93
|
-
const cells = React.useMemo(() => createCalendarMonth(displayedMonth, weekStartsOn), [displayedMonth, weekStartsOn]);
|
|
94
|
-
const gridItems = React.useMemo(() => cells.map((cell, index) => ({
|
|
95
|
-
height: cellSize,
|
|
96
|
-
id: cell.id,
|
|
97
|
-
width: cellSize,
|
|
98
|
-
x: index % GRID_COLUMNS * cellSize,
|
|
99
|
-
y: Math.floor(index / GRID_COLUMNS) * cellSize
|
|
100
|
-
})), [cellSize, cells]);
|
|
101
|
-
const cellsById = React.useMemo(() => new Map(cells.map((cell) => [cell.id, cell])), [cells]);
|
|
102
|
-
const disabledDateIds = React.useMemo(() => new Set(disabledDates.map(formatCalendarDate2)), [disabledDates]);
|
|
103
|
-
const weekdays = React.useMemo(() => createWeekdayLabels(locale, weekStartsOn), [locale, weekStartsOn]);
|
|
104
|
-
const setDisplayedMonth = React.useCallback((month) => {
|
|
105
|
-
const nextMonth = startOfLocalMonth2(month);
|
|
106
|
-
if (controlledDisplayedMonth === undefined)
|
|
107
|
-
setUncontrolledDisplayedMonth(nextMonth);
|
|
108
|
-
onDisplayedMonthChange?.(nextMonth);
|
|
109
|
-
}, [controlledDisplayedMonth, onDisplayedMonthChange]);
|
|
110
|
-
const previousMonth = addMonths(displayedMonth, -1);
|
|
111
|
-
const nextMonth = addMonths(displayedMonth, 1);
|
|
112
|
-
return /* @__PURE__ */ jsxs(View2, {
|
|
113
|
-
accessibilityLabel: "Calendar",
|
|
114
|
-
gap: density === "compact" ? "s" : "m",
|
|
115
|
-
testID,
|
|
116
|
-
children: [
|
|
117
|
-
/* @__PURE__ */ jsxs(View2, {
|
|
118
|
-
align: "center",
|
|
119
|
-
direction: "row",
|
|
120
|
-
justify: "space-between",
|
|
121
|
-
children: [
|
|
122
|
-
/* @__PURE__ */ jsx(Button2, {
|
|
123
|
-
disabled: !monthIntersectsRange(previousMonth, minDate, maxDate),
|
|
124
|
-
interactionPolicy,
|
|
125
|
-
onPress: () => setDisplayedMonth(previousMonth),
|
|
126
|
-
size: "s",
|
|
127
|
-
variant: "ghost",
|
|
128
|
-
children: "Previous"
|
|
129
|
-
}),
|
|
130
|
-
/* @__PURE__ */ jsx(Text2, {
|
|
131
|
-
accessibilityRole: "header",
|
|
132
|
-
align: "center",
|
|
133
|
-
variant: "label",
|
|
134
|
-
weight: "semiBold",
|
|
135
|
-
children: formatMonthLabel(displayedMonth, locale)
|
|
136
|
-
}),
|
|
137
|
-
/* @__PURE__ */ jsx(Button2, {
|
|
138
|
-
disabled: !monthIntersectsRange(nextMonth, minDate, maxDate),
|
|
139
|
-
interactionPolicy,
|
|
140
|
-
onPress: () => setDisplayedMonth(nextMonth),
|
|
141
|
-
size: "s",
|
|
142
|
-
variant: "ghost",
|
|
143
|
-
children: "Next"
|
|
144
|
-
})
|
|
145
|
-
]
|
|
146
|
-
}),
|
|
147
|
-
/* @__PURE__ */ jsx(View2, {
|
|
148
|
-
direction: "row",
|
|
149
|
-
children: weekdays.map((weekday) => /* @__PURE__ */ jsx(View2, {
|
|
150
|
-
width: cellSize,
|
|
151
|
-
children: /* @__PURE__ */ jsx(Text2, {
|
|
152
|
-
align: "center",
|
|
153
|
-
emphasis: "muted",
|
|
154
|
-
variant: "caption",
|
|
155
|
-
weight: "semiBold",
|
|
156
|
-
children: weekday.label
|
|
157
|
-
})
|
|
158
|
-
}, weekday.id))
|
|
159
|
-
}),
|
|
160
|
-
/* @__PURE__ */ jsx(GridView2, {
|
|
161
|
-
contentHeight: gridHeight,
|
|
162
|
-
contentWidth: gridWidth,
|
|
163
|
-
height: gridHeight,
|
|
164
|
-
interactionPolicy,
|
|
165
|
-
items: gridItems,
|
|
166
|
-
overscanPixels: 0,
|
|
167
|
-
renderItem: (item) => {
|
|
168
|
-
const cell = cellsById.get(item.id);
|
|
169
|
-
if (!cell)
|
|
170
|
-
return null;
|
|
171
|
-
const selected = selectedDate !== null && selectedDate !== undefined && isSameLocalDay(selectedDate, cell.date);
|
|
172
|
-
const disabled = isCalendarDateDisabled({
|
|
173
|
-
date: cell.date,
|
|
174
|
-
disabledDateIds,
|
|
175
|
-
isDateDisabled,
|
|
176
|
-
maxDate,
|
|
177
|
-
minDate
|
|
178
|
-
});
|
|
179
|
-
const selectCell = () => {
|
|
180
|
-
if (!cell.inDisplayedMonth)
|
|
181
|
-
setDisplayedMonth(cell.date);
|
|
182
|
-
onSelectedDateChange?.(cell.date);
|
|
183
|
-
};
|
|
184
|
-
return /* @__PURE__ */ jsx(Button2, {
|
|
185
|
-
accessibilityState: { disabled, selected },
|
|
186
|
-
color: selected ? "primary" : "neutral",
|
|
187
|
-
disabled,
|
|
188
|
-
interactionPolicy,
|
|
189
|
-
onPress: selectCell,
|
|
190
|
-
size: "s",
|
|
191
|
-
testID: testID ? `${testID}-day-${cell.id}` : undefined,
|
|
192
|
-
variant: selected ? "solid" : cell.inDisplayedMonth ? "ghost" : "outline",
|
|
193
|
-
children: cell.date.getDate()
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
testID: testID ? `${testID}-grid` : undefined,
|
|
197
|
-
viewportInteraction: "locked",
|
|
198
|
-
width: gridWidth
|
|
199
|
-
})
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
function createWeekdayLabels(locale, weekStartsOn) {
|
|
204
|
-
const formatter = new Intl.DateTimeFormat(locale, { weekday: "short" });
|
|
205
|
-
const sunday = new Date(2023, 0, 1);
|
|
206
|
-
return Array.from({ length: GRID_COLUMNS }, (_, index) => {
|
|
207
|
-
const day = new Date(sunday.getFullYear(), sunday.getMonth(), sunday.getDate() + (weekStartsOn + index) % GRID_COLUMNS);
|
|
208
|
-
return { id: String(index), label: formatter.format(day) };
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
function addMonths(month, count) {
|
|
212
|
-
return new Date(month.getFullYear(), month.getMonth() + count, 1);
|
|
213
|
-
}
|
|
214
|
-
function startOfLocalMonth2(value) {
|
|
215
|
-
return new Date(value.getFullYear(), value.getMonth(), 1);
|
|
216
|
-
}
|
|
217
|
-
function formatCalendarDate2(value) {
|
|
218
|
-
const year = String(value.getFullYear()).padStart(4, "0");
|
|
219
|
-
const month = String(value.getMonth() + 1).padStart(2, "0");
|
|
220
|
-
const day = String(value.getDate()).padStart(2, "0");
|
|
221
|
-
return `${year}-${month}-${day}`;
|
|
222
|
-
}
|
|
223
|
-
function compareLocalDates2(left, right) {
|
|
224
|
-
return formatCalendarDate2(left).localeCompare(formatCalendarDate2(right));
|
|
225
|
-
}
|
|
226
|
-
function monthIntersectsRange(month, minDate, maxDate) {
|
|
227
|
-
const first = startOfLocalMonth2(month);
|
|
228
|
-
const last = new Date(first.getFullYear(), first.getMonth() + 1, 0);
|
|
229
|
-
return (!minDate || compareLocalDates2(last, minDate) >= 0) && (!maxDate || compareLocalDates2(first, maxDate) <= 0);
|
|
230
|
-
}
|
|
231
|
-
function isSameLocalDay(left, right) {
|
|
232
|
-
return formatCalendarDate2(left) === formatCalendarDate2(right);
|
|
233
|
-
}
|
|
234
|
-
function formatMonthLabel(value, locale) {
|
|
235
|
-
return new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(value);
|
|
236
|
-
}
|
|
237
|
-
export { Calendar2 };
|