@klinking/colander 3.0.1-alpha.1 → 3.1.0-alpha.10
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/dist/formats/date.cjs +2 -3
- package/dist/formats/date.d.cts +10 -14
- package/dist/formats/date.d.mts +10 -14
- package/dist/formats/date.mjs +2 -3
- package/dist/formats/object.cjs +2 -3
- package/dist/formats/object.d.cts +10 -14
- package/dist/formats/object.d.mts +10 -14
- package/dist/formats/object.mjs +2 -3
- package/dist/formats/plain-date-time.cjs +2 -3
- package/dist/formats/plain-date-time.d.cts +10 -14
- package/dist/formats/plain-date-time.d.mts +10 -14
- package/dist/formats/plain-date-time.mjs +2 -3
- package/dist/formats/plain-date.cjs +2 -3
- package/dist/formats/plain-date.d.cts +10 -14
- package/dist/formats/plain-date.d.mts +10 -14
- package/dist/formats/plain-date.mjs +2 -3
- package/dist/formats/plain-month-day.cjs +2 -3
- package/dist/formats/plain-month-day.d.cts +10 -14
- package/dist/formats/plain-month-day.d.mts +10 -14
- package/dist/formats/plain-month-day.mjs +2 -3
- package/dist/formats/plain-year-month.cjs +2 -3
- package/dist/formats/plain-year-month.d.cts +10 -14
- package/dist/formats/plain-year-month.d.mts +10 -14
- package/dist/formats/plain-year-month.mjs +2 -3
- package/dist/formats/zoned-date-time.cjs +2 -3
- package/dist/formats/zoned-date-time.d.cts +10 -14
- package/dist/formats/zoned-date-time.d.mts +10 -14
- package/dist/formats/zoned-date-time.mjs +2 -3
- package/dist/{weeks-view-context-CNAq2Hiu.d.cts → index-K1_zOIpa.d.mts} +198 -114
- package/dist/{weeks-view-context-CsP3PBiu.d.mts → index-bRoYX03d.d.cts} +198 -114
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -11
- package/dist/index.d.mts +2 -11
- package/dist/index.mjs +1 -2
- package/dist/{weeks-navigation-CJzhxbgj.cjs → weeks-navigation-3UTRiTUP.cjs} +1102 -952
- package/dist/{weeks-navigation-Bg0nZLgh.mjs → weeks-navigation-BoHqK5fq.mjs} +1102 -951
- package/package.json +21 -18
- package/src/calendar-provider.test.tsx +88 -1
- package/src/calendar-provider.tsx +89 -73
- package/src/calendar-types.ts +2 -0
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +214 -0
- package/src/day-cell-state.ts +244 -0
- package/src/day-cell-store.test.tsx +273 -0
- package/src/day-cell-store.tsx +204 -0
- package/src/day-cell.test.tsx +73 -90
- package/src/day-cell.tsx +106 -444
- package/src/drag-handle.tsx +2 -2
- package/src/formats/date.ts +2 -0
- package/src/formats/formats.test.ts +1 -1
- package/src/formats/object.ts +2 -0
- package/src/formats/plain-date-time.ts +2 -0
- package/src/formats/plain-date.ts +2 -0
- package/src/formats/plain-month-day.ts +2 -0
- package/src/formats/plain-year-month.ts +2 -0
- package/src/formats/zoned-date-time.ts +2 -0
- package/src/grid-header.tsx +3 -3
- package/src/grid.event-perf.test.tsx +7 -1
- package/src/grid.perf.test.tsx +7 -1
- package/src/grid.tsx +38 -77
- package/src/index.ts +2 -0
- package/src/keyboard.test.ts +1 -1
- package/src/month-separator.test.tsx +1 -1
- package/src/month-view-navigation.ts +180 -0
- package/src/month-view-types.ts +3 -0
- package/src/month-view.bounds.test.tsx +136 -0
- package/src/month-view.test.tsx +89 -1
- package/src/month-view.tsx +74 -217
- package/src/month-window.test.ts +207 -0
- package/src/month-window.ts +93 -0
- package/src/navigation.tsx +18 -76
- package/src/out-of-range.test.ts +34 -54
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +120 -0
- package/src/range-preview.tsx +3 -5
- package/src/resolve-first-week.test.ts +1 -1
- package/src/root-selection.ts +99 -97
- package/src/selected-range.tsx +3 -5
- package/src/store.ts +72 -0
- package/src/today.test.tsx +105 -0
- package/src/types.ts +24 -1
- package/src/utils.bench.ts +158 -106
- package/src/utils.test.ts +26 -1
- package/src/utils.ts +40 -9
- package/src/view-context.test.tsx +126 -0
- package/src/view-context.ts +45 -0
- package/src/week-number.test.tsx +76 -0
- package/src/week-number.tsx +48 -19
- package/src/weeks-grid.tsx +20 -10
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-navigation.tsx +15 -31
- package/src/weeks-view-state.ts +67 -101
- package/src/weeks-view-types.ts +4 -1
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-view.test.tsx +116 -14
- package/src/weeks-view.tsx +24 -52
- package/src/weeks-window.test.ts +131 -0
- package/src/weeks-window.ts +102 -0
package/src/day-cell.tsx
CHANGED
|
@@ -1,211 +1,28 @@
|
|
|
1
1
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
3
|
import type { Temporal as TemporalPoly } from "@js-temporal/polyfill";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
memo,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
} from "react";
|
|
13
|
+
import { useCalendarStable } from "./calendar-context";
|
|
14
|
+
import { WeekDataContext, DayCellDataContext } from "./context";
|
|
15
|
+
import type { DayCellState } from "./day-cell-state";
|
|
16
|
+
import { useDayCellState, useStandaloneDayCellState } from "./day-cell-store";
|
|
17
|
+
import { MonthViewStateContext } from "./month-view-context";
|
|
10
18
|
import type { StateAttributesMapping } from "./types";
|
|
11
19
|
import type {
|
|
12
20
|
DayCellTemplateProps,
|
|
13
21
|
DayButtonProps,
|
|
14
22
|
DayCellTemplateState,
|
|
15
|
-
TemporalNamespace,
|
|
16
|
-
OutsideDays,
|
|
17
23
|
} from "./types";
|
|
18
|
-
import { shouldMoveDomFocus
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
/** Computes derived day cell state from context values. Pure function, no hooks. */
|
|
22
|
-
export function computeDayCellState(
|
|
23
|
-
date: TemporalPoly.PlainDate,
|
|
24
|
-
orientation: GridOrientation,
|
|
25
|
-
columnIndex: number,
|
|
26
|
-
rootState: DayCellTemplateState["root"],
|
|
27
|
-
selectedDates: TemporalPoly.PlainDate[],
|
|
28
|
-
currentDateTime: { year: number; month: number },
|
|
29
|
-
disabled: boolean,
|
|
30
|
-
isDateDisabled: ((date: TemporalPoly.PlainDate) => boolean) | undefined,
|
|
31
|
-
focusedDate: TemporalPoly.PlainDate,
|
|
32
|
-
rangeStart: TemporalPoly.PlainDate | undefined,
|
|
33
|
-
rangeEnd: TemporalPoly.PlainDate | undefined,
|
|
34
|
-
tabTargetDate: TemporalPoly.PlainDate,
|
|
35
|
-
T: TemporalNamespace,
|
|
36
|
-
selectionMode: "single" | "range" | "multiple",
|
|
37
|
-
outsideDays: OutsideDays,
|
|
38
|
-
previewStart?: TemporalPoly.PlainDate,
|
|
39
|
-
previewEnd?: TemporalPoly.PlainDate,
|
|
40
|
-
): DayCellTemplateState & { isTabTarget: boolean } {
|
|
41
|
-
const isCurrentMonth =
|
|
42
|
-
date.year === currentDateTime.year && date.month === currentDateTime.month;
|
|
43
|
-
const hidden = !isCurrentMonth && outsideDays === "hidden";
|
|
44
|
-
|
|
45
|
-
if (hidden) {
|
|
46
|
-
return {
|
|
47
|
-
root: rootState,
|
|
48
|
-
date,
|
|
49
|
-
columnIndex,
|
|
50
|
-
orientation,
|
|
51
|
-
outsideMonth: true,
|
|
52
|
-
hidden: true,
|
|
53
|
-
selected: false,
|
|
54
|
-
today: false,
|
|
55
|
-
disabled: true,
|
|
56
|
-
focused: false,
|
|
57
|
-
rangeStart: false,
|
|
58
|
-
rangeEnd: false,
|
|
59
|
-
rangeBoundary: false,
|
|
60
|
-
inRange: false,
|
|
61
|
-
rangeIndex: false,
|
|
62
|
-
rangeLength: false,
|
|
63
|
-
rangeHasStart: false,
|
|
64
|
-
rangeHasEnd: false,
|
|
65
|
-
rangePreviewStart: false,
|
|
66
|
-
rangePreviewEnd: false,
|
|
67
|
-
rangePreviewBoundary: false,
|
|
68
|
-
rangePreviewInRange: false,
|
|
69
|
-
rangePreviewIndex: false,
|
|
70
|
-
rangePreviewLength: false,
|
|
71
|
-
rangePreviewHasStart: false,
|
|
72
|
-
rangePreviewHasEnd: false,
|
|
73
|
-
isTabTarget: false,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const today = T.Now.plainDateISO();
|
|
78
|
-
const isToday = T.PlainDate.compare(date, today) === 0;
|
|
79
|
-
const isRange = selectionMode === "range";
|
|
80
|
-
|
|
81
|
-
let isRangeStart: boolean = false;
|
|
82
|
-
let isRangeEnd: boolean = false;
|
|
83
|
-
let isInRangeDay: boolean = false;
|
|
84
|
-
let rangeIdx: number | false = false;
|
|
85
|
-
let rangeLen: number | false = false;
|
|
86
|
-
let isPreviewRangeStart: boolean = false;
|
|
87
|
-
let isPreviewRangeEnd: boolean = false;
|
|
88
|
-
let isInPreviewRange: boolean = false;
|
|
89
|
-
let previewIdx: number | false = false;
|
|
90
|
-
let previewLen: number | false = false;
|
|
91
|
-
|
|
92
|
-
if (isRange) {
|
|
93
|
-
isRangeStart = rangeStart
|
|
94
|
-
? T.PlainDate.compare(date, rangeStart) === 0
|
|
95
|
-
: false;
|
|
96
|
-
isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
97
|
-
isInRangeDay = isInRangeUtil(date, rangeStart, rangeEnd, T) !== false;
|
|
98
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
99
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
100
|
-
rangeIdx =
|
|
101
|
-
isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
|
|
102
|
-
rangeLen =
|
|
103
|
-
isInRangeDay && effectiveStart && effectiveEnd
|
|
104
|
-
? effectiveEnd.since(effectiveStart).days + 1
|
|
105
|
-
: false;
|
|
106
|
-
|
|
107
|
-
isPreviewRangeStart = previewStart
|
|
108
|
-
? T.PlainDate.compare(date, previewStart) === 0
|
|
109
|
-
: false;
|
|
110
|
-
isPreviewRangeEnd = previewEnd
|
|
111
|
-
? T.PlainDate.compare(date, previewEnd) === 0
|
|
112
|
-
: false;
|
|
113
|
-
isInPreviewRange =
|
|
114
|
-
previewStart && previewEnd
|
|
115
|
-
? isInRangeUtil(date, previewStart, previewEnd, T) !== false
|
|
116
|
-
: false;
|
|
117
|
-
previewIdx =
|
|
118
|
-
isInPreviewRange && previewStart ? date.since(previewStart).days : false;
|
|
119
|
-
previewLen =
|
|
120
|
-
isInPreviewRange && previewStart && previewEnd
|
|
121
|
-
? previewEnd.since(previewStart).days + 1
|
|
122
|
-
: false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
|
|
126
|
-
const suppressRange =
|
|
127
|
-
!isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
|
|
128
|
-
|
|
129
|
-
if (outsideNonInteractive) {
|
|
130
|
-
return {
|
|
131
|
-
root: rootState,
|
|
132
|
-
date,
|
|
133
|
-
columnIndex,
|
|
134
|
-
orientation,
|
|
135
|
-
outsideMonth: true,
|
|
136
|
-
hidden: false,
|
|
137
|
-
selected: false,
|
|
138
|
-
today: isToday,
|
|
139
|
-
disabled: true,
|
|
140
|
-
focused: false,
|
|
141
|
-
rangeStart: suppressRange ? false : isRangeStart,
|
|
142
|
-
rangeEnd: suppressRange ? false : isRangeEnd,
|
|
143
|
-
rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
|
|
144
|
-
inRange: suppressRange ? false : isInRangeDay,
|
|
145
|
-
rangeIndex: suppressRange ? false : rangeIdx,
|
|
146
|
-
rangeLength: suppressRange ? false : rangeLen,
|
|
147
|
-
rangeHasStart: suppressRange
|
|
148
|
-
? false
|
|
149
|
-
: isInRangeDay && rangeStart !== undefined,
|
|
150
|
-
rangeHasEnd: suppressRange
|
|
151
|
-
? false
|
|
152
|
-
: isInRangeDay && rangeEnd !== undefined,
|
|
153
|
-
rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
|
|
154
|
-
rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
|
|
155
|
-
rangePreviewBoundary: suppressRange
|
|
156
|
-
? false
|
|
157
|
-
: isPreviewRangeStart || isPreviewRangeEnd,
|
|
158
|
-
rangePreviewInRange: suppressRange ? false : isInPreviewRange,
|
|
159
|
-
rangePreviewIndex: suppressRange ? false : previewIdx,
|
|
160
|
-
rangePreviewLength: suppressRange ? false : previewLen,
|
|
161
|
-
rangePreviewHasStart: suppressRange
|
|
162
|
-
? false
|
|
163
|
-
: isInPreviewRange && previewStart !== undefined,
|
|
164
|
-
rangePreviewHasEnd: suppressRange
|
|
165
|
-
? false
|
|
166
|
-
: isInPreviewRange && previewEnd !== undefined,
|
|
167
|
-
isTabTarget: false,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const isSelected =
|
|
172
|
-
selectionMode !== "range"
|
|
173
|
-
? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0)
|
|
174
|
-
: false;
|
|
175
|
-
const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
|
|
176
|
-
const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
|
|
177
|
-
const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
root: rootState,
|
|
181
|
-
date,
|
|
182
|
-
columnIndex,
|
|
183
|
-
orientation,
|
|
184
|
-
selected: isSelected,
|
|
185
|
-
today: isToday,
|
|
186
|
-
disabled: isDisabled,
|
|
187
|
-
outsideMonth: !isCurrentMonth,
|
|
188
|
-
hidden: false,
|
|
189
|
-
focused: isFocused,
|
|
190
|
-
rangeStart: isRangeStart,
|
|
191
|
-
rangeEnd: isRangeEnd,
|
|
192
|
-
rangeBoundary: isRangeStart || isRangeEnd,
|
|
193
|
-
inRange: isInRangeDay,
|
|
194
|
-
rangeIndex: rangeIdx,
|
|
195
|
-
rangeLength: rangeLen,
|
|
196
|
-
rangeHasStart: isInRangeDay && rangeStart !== undefined,
|
|
197
|
-
rangeHasEnd: isInRangeDay && rangeEnd !== undefined,
|
|
198
|
-
rangePreviewStart: isPreviewRangeStart,
|
|
199
|
-
rangePreviewEnd: isPreviewRangeEnd,
|
|
200
|
-
rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
|
|
201
|
-
rangePreviewInRange: isInPreviewRange,
|
|
202
|
-
rangePreviewIndex: previewIdx,
|
|
203
|
-
rangePreviewLength: previewLen,
|
|
204
|
-
rangePreviewHasStart: isInPreviewRange && previewStart !== undefined,
|
|
205
|
-
rangePreviewHasEnd: isInPreviewRange && previewEnd !== undefined,
|
|
206
|
-
isTabTarget,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
24
|
+
import { shouldMoveDomFocus } from "./utils";
|
|
25
|
+
import { useViewStable } from "./view-context";
|
|
209
26
|
|
|
210
27
|
export const dayStateAttributesMapping = {
|
|
211
28
|
root: () => null,
|
|
@@ -242,21 +59,27 @@ export const dayStateAttributesMapping = {
|
|
|
242
59
|
rangePreviewHasEnd: (v) => (v ? { "data-range-preview-has-end": "" } : null),
|
|
243
60
|
} as const satisfies StateAttributesMapping<DayCellTemplateState>;
|
|
244
61
|
|
|
62
|
+
/** @internal The enclosing day cell's state, read by its `DayButton`. */
|
|
63
|
+
const DayCellStateContext = createContext<DayCellState | null>(null);
|
|
64
|
+
|
|
65
|
+
type MonthKey = { year: number; month: number };
|
|
66
|
+
|
|
245
67
|
/** Props for the memoized DayCellInstance. */
|
|
246
68
|
interface DayCellInstanceProps {
|
|
247
69
|
render?: DayCellTemplateProps["render"];
|
|
248
70
|
date: TemporalPoly.PlainDate;
|
|
249
71
|
columnIndex?: number | undefined;
|
|
72
|
+
gridMonth?: MonthKey | undefined;
|
|
250
73
|
children?: React.ReactNode;
|
|
251
|
-
_derivedState: DayCellTemplateState & { isTabTarget: boolean };
|
|
252
74
|
[key: string]: unknown;
|
|
253
75
|
}
|
|
254
76
|
|
|
255
77
|
function DayCellInstanceFn(props: DayCellInstanceProps) {
|
|
256
|
-
const { render, date, columnIndex,
|
|
78
|
+
const { render, date, columnIndex, gridMonth, children, ...otherProps } =
|
|
257
79
|
props;
|
|
258
80
|
|
|
259
|
-
const
|
|
81
|
+
const derived = useDayCellState(date, columnIndex, gridMonth);
|
|
82
|
+
const state = derived as unknown as DayCellTemplateState;
|
|
260
83
|
|
|
261
84
|
const defaultProps: Record<string, unknown> = state.hidden
|
|
262
85
|
? {
|
|
@@ -268,7 +91,7 @@ function DayCellInstanceFn(props: DayCellInstanceProps) {
|
|
|
268
91
|
role: "gridcell",
|
|
269
92
|
"aria-selected": state.selected || undefined,
|
|
270
93
|
"aria-disabled": state.disabled || undefined,
|
|
271
|
-
children: children ?? <DayButton
|
|
94
|
+
children: children ?? <DayButton />,
|
|
272
95
|
};
|
|
273
96
|
|
|
274
97
|
const cell = useRender({
|
|
@@ -282,10 +105,16 @@ function DayCellInstanceFn(props: DayCellInstanceProps) {
|
|
|
282
105
|
|
|
283
106
|
const outsideDisabled =
|
|
284
107
|
state.hidden || (state.outsideMonth && state.disabled);
|
|
108
|
+
const cellData = useMemo(
|
|
109
|
+
() => ({ date, columnIndex, outsideDisabled }),
|
|
110
|
+
[date, columnIndex, outsideDisabled],
|
|
111
|
+
);
|
|
285
112
|
|
|
286
113
|
return (
|
|
287
|
-
<DayCellDataContext.Provider value={
|
|
288
|
-
{
|
|
114
|
+
<DayCellDataContext.Provider value={cellData}>
|
|
115
|
+
<DayCellStateContext.Provider value={derived}>
|
|
116
|
+
{cell}
|
|
117
|
+
</DayCellStateContext.Provider>
|
|
289
118
|
</DayCellDataContext.Provider>
|
|
290
119
|
);
|
|
291
120
|
}
|
|
@@ -314,56 +143,30 @@ const DAY_CELL_HANDLED_KEYS: ReadonlySet<string> = new Set([
|
|
|
314
143
|
"render",
|
|
315
144
|
"date",
|
|
316
145
|
"columnIndex",
|
|
146
|
+
"gridMonth",
|
|
317
147
|
"children",
|
|
318
|
-
"_derivedState",
|
|
319
148
|
]);
|
|
320
149
|
|
|
321
150
|
const DAY_BUTTON_HANDLED_KEYS: ReadonlySet<string> = new Set([
|
|
322
151
|
"render",
|
|
323
152
|
"date",
|
|
324
153
|
"children",
|
|
325
|
-
"
|
|
154
|
+
"_state",
|
|
326
155
|
]);
|
|
327
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Whether a day cell can skip a parent re-render. Its own state comes from
|
|
159
|
+
* the store, so only props are compared here.
|
|
160
|
+
*/
|
|
328
161
|
export function dayCellInstancePropsAreEqual(
|
|
329
162
|
prev: DayCellInstanceProps,
|
|
330
163
|
next: DayCellInstanceProps,
|
|
331
164
|
): boolean {
|
|
332
|
-
// Skip `children` — React elements are always new objects. Child components
|
|
333
|
-
// that subscribe to context (e.g. DayButton fallback) get their own
|
|
334
|
-
// re-render via context; the optimised internal DayButton reads only
|
|
335
|
-
// stable context and is separately memo'd.
|
|
336
|
-
if (
|
|
337
|
-
prev.date !== next.date ||
|
|
338
|
-
prev.render !== next.render ||
|
|
339
|
-
prev.columnIndex !== next.columnIndex
|
|
340
|
-
)
|
|
341
|
-
return false;
|
|
342
|
-
const a = prev._derivedState;
|
|
343
|
-
const b = next._derivedState;
|
|
344
165
|
return (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
a.hidden === b.hidden &&
|
|
350
|
-
a.focused === b.focused &&
|
|
351
|
-
a.rangeStart === b.rangeStart &&
|
|
352
|
-
a.rangeEnd === b.rangeEnd &&
|
|
353
|
-
a.inRange === b.inRange &&
|
|
354
|
-
a.rangeIndex === b.rangeIndex &&
|
|
355
|
-
a.rangeLength === b.rangeLength &&
|
|
356
|
-
a.rangeHasStart === b.rangeHasStart &&
|
|
357
|
-
a.rangeHasEnd === b.rangeHasEnd &&
|
|
358
|
-
a.rangePreviewStart === b.rangePreviewStart &&
|
|
359
|
-
a.rangePreviewEnd === b.rangePreviewEnd &&
|
|
360
|
-
a.rangePreviewBoundary === b.rangePreviewBoundary &&
|
|
361
|
-
a.rangePreviewInRange === b.rangePreviewInRange &&
|
|
362
|
-
a.rangePreviewIndex === b.rangePreviewIndex &&
|
|
363
|
-
a.rangePreviewLength === b.rangePreviewLength &&
|
|
364
|
-
a.rangePreviewHasStart === b.rangePreviewHasStart &&
|
|
365
|
-
a.rangePreviewHasEnd === b.rangePreviewHasEnd &&
|
|
366
|
-
a.isTabTarget === b.isTabTarget &&
|
|
166
|
+
prev.date === next.date &&
|
|
167
|
+
prev.render === next.render &&
|
|
168
|
+
prev.columnIndex === next.columnIndex &&
|
|
169
|
+
prev.gridMonth === next.gridMonth &&
|
|
367
170
|
passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS)
|
|
368
171
|
);
|
|
369
172
|
}
|
|
@@ -373,6 +176,19 @@ const DayCellInstance = memo(
|
|
|
373
176
|
dayCellInstancePropsAreEqual,
|
|
374
177
|
) as typeof DayCellInstanceFn;
|
|
375
178
|
|
|
179
|
+
/** The cells of a whole month, for a `DayCellTemplate` outside any week row. */
|
|
180
|
+
function MonthDayCells(props: Omit<DayCellTemplateProps, "date">) {
|
|
181
|
+
const monthState = useContext(MonthViewStateContext);
|
|
182
|
+
const days = monthState?.weeks.flat() ?? [];
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
{days.map((day) => (
|
|
186
|
+
<DayCellInstance key={day.toString()} {...props} date={day} />
|
|
187
|
+
))}
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
376
192
|
/**
|
|
377
193
|
* Renders one `<td role="gridcell">` per day. Exposes data-attributes for
|
|
378
194
|
* `selected`, `today`, `disabled`, `outside-month`, `focused`,
|
|
@@ -385,104 +201,29 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
385
201
|
const { date: dateProp, ...restProps } = props;
|
|
386
202
|
const weekData = useContext(WeekDataContext);
|
|
387
203
|
|
|
388
|
-
const {
|
|
389
|
-
disabled,
|
|
390
|
-
isDateDisabled,
|
|
391
|
-
selectionMode,
|
|
392
|
-
temporal: T,
|
|
393
|
-
weekStartDay,
|
|
394
|
-
} = useCalendarStable();
|
|
395
|
-
|
|
396
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
397
|
-
useCalendarState();
|
|
398
|
-
|
|
399
|
-
const viewCtx = useViewContext();
|
|
400
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
401
|
-
|
|
402
|
-
const monthStable = useContext(MonthViewStableContext);
|
|
403
|
-
const monthState = useMonthViewState();
|
|
404
|
-
const { rootState, weeks, currentMonth: currentDateTime } = monthState;
|
|
405
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
406
|
-
|
|
407
|
-
// Use the grid-specific month for outsideMonth checks, falling back to currentMonth.
|
|
408
|
-
// In multi-month mode, gridMonth is set by WeekTemplate from GridMonthContext.
|
|
409
|
-
// In weeks view, cellMonth is computed per-day (see below) so outsideMonth is always false.
|
|
410
|
-
const isWeeksView = viewCtx.viewType === "weeks";
|
|
411
|
-
const cellMonth = isWeeksView
|
|
412
|
-
? null // per-day below
|
|
413
|
-
: (weekData?.gridMonth ?? currentDateTime);
|
|
414
|
-
|
|
415
|
-
const { orientation } = useContext(GridContext);
|
|
416
|
-
|
|
417
204
|
if (dateProp) {
|
|
418
|
-
const daysInWeek = dateProp.daysInWeek;
|
|
419
|
-
const colIdx =
|
|
420
|
-
((dateProp.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
|
|
421
|
-
daysInWeek;
|
|
422
|
-
const derived = computeDayCellState(
|
|
423
|
-
dateProp,
|
|
424
|
-
orientation,
|
|
425
|
-
colIdx,
|
|
426
|
-
rootState,
|
|
427
|
-
selectedDates,
|
|
428
|
-
isWeeksView ? { year: dateProp.year, month: dateProp.month } : cellMonth!,
|
|
429
|
-
disabled,
|
|
430
|
-
isDateDisabled,
|
|
431
|
-
focusedDate,
|
|
432
|
-
rangeStart,
|
|
433
|
-
rangeEnd,
|
|
434
|
-
tabTargetDate,
|
|
435
|
-
T,
|
|
436
|
-
selectionMode,
|
|
437
|
-
outsideDays,
|
|
438
|
-
previewStart,
|
|
439
|
-
previewEnd,
|
|
440
|
-
);
|
|
441
205
|
return (
|
|
442
|
-
<DayCellInstance
|
|
206
|
+
<DayCellInstance
|
|
207
|
+
{...restProps}
|
|
208
|
+
date={dateProp}
|
|
209
|
+
gridMonth={weekData?.gridMonth}
|
|
210
|
+
/>
|
|
443
211
|
);
|
|
444
212
|
}
|
|
445
213
|
|
|
446
|
-
|
|
447
|
-
const perWeek = weekData != null;
|
|
214
|
+
if (!weekData) return <MonthDayCells {...restProps} />;
|
|
448
215
|
|
|
449
216
|
return (
|
|
450
217
|
<>
|
|
451
|
-
{days.map((day, i) =>
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
colIdx,
|
|
461
|
-
rootState,
|
|
462
|
-
selectedDates,
|
|
463
|
-
isWeeksView ? { year: day.year, month: day.month } : cellMonth!,
|
|
464
|
-
disabled,
|
|
465
|
-
isDateDisabled,
|
|
466
|
-
focusedDate,
|
|
467
|
-
rangeStart,
|
|
468
|
-
rangeEnd,
|
|
469
|
-
tabTargetDate,
|
|
470
|
-
T,
|
|
471
|
-
selectionMode,
|
|
472
|
-
outsideDays,
|
|
473
|
-
previewStart,
|
|
474
|
-
previewEnd,
|
|
475
|
-
);
|
|
476
|
-
return (
|
|
477
|
-
<DayCellInstance
|
|
478
|
-
key={day.toString()}
|
|
479
|
-
{...restProps}
|
|
480
|
-
date={day}
|
|
481
|
-
columnIndex={perWeek ? i : undefined}
|
|
482
|
-
_derivedState={derived}
|
|
483
|
-
/>
|
|
484
|
-
);
|
|
485
|
-
})}
|
|
218
|
+
{weekData.days.map((day, i) => (
|
|
219
|
+
<DayCellInstance
|
|
220
|
+
key={day.toString()}
|
|
221
|
+
{...restProps}
|
|
222
|
+
date={day}
|
|
223
|
+
columnIndex={i}
|
|
224
|
+
gridMonth={weekData.gridMonth}
|
|
225
|
+
/>
|
|
226
|
+
))}
|
|
486
227
|
</>
|
|
487
228
|
);
|
|
488
229
|
}
|
|
@@ -491,7 +232,7 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
491
232
|
interface DayButtonInnerProps {
|
|
492
233
|
render?: DayButtonProps["render"];
|
|
493
234
|
date: TemporalPoly.PlainDate;
|
|
494
|
-
|
|
235
|
+
_state: DayCellState;
|
|
495
236
|
[key: string]: unknown;
|
|
496
237
|
}
|
|
497
238
|
|
|
@@ -499,18 +240,16 @@ function DayButtonInnerFn(
|
|
|
499
240
|
props: DayButtonInnerProps,
|
|
500
241
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
501
242
|
) {
|
|
502
|
-
const { render, date,
|
|
243
|
+
const { render, date, _state, ...otherProps } = props;
|
|
503
244
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
504
|
-
const { setFocusedDate } =
|
|
505
|
-
const monthStable = useContext(MonthViewStableContext);
|
|
506
|
-
const gridFocusedRef = monthStable!.gridFocusedRef;
|
|
245
|
+
const { gridFocusedRef, setFocusedDate } = useViewStable();
|
|
507
246
|
|
|
508
247
|
const internalRef = useRef<HTMLButtonElement>(null);
|
|
509
248
|
|
|
510
|
-
const isHidden =
|
|
511
|
-
const isFocused =
|
|
512
|
-
const isTabTarget =
|
|
513
|
-
const isDisabled =
|
|
249
|
+
const isHidden = _state.hidden;
|
|
250
|
+
const isFocused = _state.focused;
|
|
251
|
+
const isTabTarget = _state.isTabTarget;
|
|
252
|
+
const isDisabled = _state.disabled;
|
|
514
253
|
|
|
515
254
|
useEffect(() => {
|
|
516
255
|
if (
|
|
@@ -521,7 +260,7 @@ function DayButtonInnerFn(
|
|
|
521
260
|
}
|
|
522
261
|
}, [isFocused, gridFocusedRef]);
|
|
523
262
|
|
|
524
|
-
const state =
|
|
263
|
+
const state = _state as unknown as DayCellTemplateState;
|
|
525
264
|
|
|
526
265
|
const defaultProps: Record<string, unknown> = isHidden
|
|
527
266
|
? {}
|
|
@@ -565,34 +304,11 @@ export function dayButtonInnerPropsAreEqual(
|
|
|
565
304
|
prev: DayButtonInnerProps,
|
|
566
305
|
next: DayButtonInnerProps,
|
|
567
306
|
): boolean {
|
|
568
|
-
if (prev.date !== next.date || prev.render !== next.render) return false;
|
|
569
|
-
if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
|
|
570
|
-
const a = prev._derivedState;
|
|
571
|
-
const b = next._derivedState;
|
|
572
|
-
if (!a || !b) return a === b;
|
|
573
307
|
return (
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
a.hidden === b.hidden &&
|
|
579
|
-
a.focused === b.focused &&
|
|
580
|
-
a.rangeStart === b.rangeStart &&
|
|
581
|
-
a.rangeEnd === b.rangeEnd &&
|
|
582
|
-
a.inRange === b.inRange &&
|
|
583
|
-
a.rangeIndex === b.rangeIndex &&
|
|
584
|
-
a.rangeLength === b.rangeLength &&
|
|
585
|
-
a.rangeHasStart === b.rangeHasStart &&
|
|
586
|
-
a.rangeHasEnd === b.rangeHasEnd &&
|
|
587
|
-
a.rangePreviewStart === b.rangePreviewStart &&
|
|
588
|
-
a.rangePreviewEnd === b.rangePreviewEnd &&
|
|
589
|
-
a.rangePreviewBoundary === b.rangePreviewBoundary &&
|
|
590
|
-
a.rangePreviewInRange === b.rangePreviewInRange &&
|
|
591
|
-
a.rangePreviewIndex === b.rangePreviewIndex &&
|
|
592
|
-
a.rangePreviewLength === b.rangePreviewLength &&
|
|
593
|
-
a.rangePreviewHasStart === b.rangePreviewHasStart &&
|
|
594
|
-
a.rangePreviewHasEnd === b.rangePreviewHasEnd &&
|
|
595
|
-
a.isTabTarget === b.isTabTarget
|
|
308
|
+
prev.date === next.date &&
|
|
309
|
+
prev.render === next.render &&
|
|
310
|
+
prev._state === next._state &&
|
|
311
|
+
passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)
|
|
596
312
|
);
|
|
597
313
|
}
|
|
598
314
|
|
|
@@ -613,30 +329,28 @@ const DayButtonInner = memo(
|
|
|
613
329
|
* Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
|
|
614
330
|
*/
|
|
615
331
|
function DayButtonFn(
|
|
616
|
-
props: DayButtonProps
|
|
617
|
-
_derivedState?: DayCellTemplateState & { isTabTarget: boolean };
|
|
618
|
-
},
|
|
332
|
+
props: DayButtonProps,
|
|
619
333
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
620
334
|
) {
|
|
621
|
-
const { date: dateProp,
|
|
335
|
+
const { date: dateProp, ...restProps } = props;
|
|
336
|
+
const cellState = useContext(DayCellStateContext);
|
|
622
337
|
const cellData = useContext(DayCellDataContext);
|
|
623
338
|
|
|
624
|
-
|
|
339
|
+
// Inside a cell for the same date, reuse the cell's state.
|
|
340
|
+
if (cellState && (!dateProp || dateProp.equals(cellState.date))) {
|
|
341
|
+
return (
|
|
342
|
+
<DayButtonInner
|
|
343
|
+
{...restProps}
|
|
344
|
+
ref={ref}
|
|
345
|
+
date={cellState.date}
|
|
346
|
+
_state={cellState}
|
|
347
|
+
/>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
625
350
|
|
|
351
|
+
const resolvedDate = dateProp ?? cellData?.date;
|
|
626
352
|
if (resolvedDate) {
|
|
627
|
-
|
|
628
|
-
if (_derivedState) {
|
|
629
|
-
return (
|
|
630
|
-
<DayButtonInner
|
|
631
|
-
{...restProps}
|
|
632
|
-
ref={ref}
|
|
633
|
-
date={resolvedDate}
|
|
634
|
-
_derivedState={_derivedState}
|
|
635
|
-
/>
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
// Fallback: compute state (for standalone DayButton usage with explicit date)
|
|
639
|
-
return <DayButtonFallback ref={ref} {...restProps} date={resolvedDate} />;
|
|
353
|
+
return <StandaloneDayButton {...restProps} ref={ref} date={resolvedDate} />;
|
|
640
354
|
}
|
|
641
355
|
|
|
642
356
|
throw new Error(
|
|
@@ -645,73 +359,21 @@ function DayButtonFn(
|
|
|
645
359
|
}
|
|
646
360
|
|
|
647
361
|
export const DayButton = forwardRef(DayButtonFn) as (
|
|
648
|
-
props: DayButtonProps &
|
|
649
|
-
_derivedState?: DayCellTemplateState & { isTabTarget: boolean };
|
|
650
|
-
} & React.RefAttributes<HTMLButtonElement>,
|
|
362
|
+
props: DayButtonProps & React.RefAttributes<HTMLButtonElement>,
|
|
651
363
|
) => React.ReactElement | null;
|
|
652
364
|
|
|
653
|
-
/**
|
|
654
|
-
function
|
|
365
|
+
/** A `DayButton` outside any day cell: subscribes to its own date's state. */
|
|
366
|
+
function StandaloneDayButtonFn(
|
|
655
367
|
props: Omit<DayButtonProps, "date"> & { date: TemporalPoly.PlainDate },
|
|
656
368
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
657
369
|
) {
|
|
658
370
|
const { date, ...restProps } = props;
|
|
659
|
-
const
|
|
660
|
-
const weekData = useContext(WeekDataContext);
|
|
661
|
-
const {
|
|
662
|
-
disabled,
|
|
663
|
-
isDateDisabled,
|
|
664
|
-
selectionMode,
|
|
665
|
-
temporal: T,
|
|
666
|
-
weekStartDay,
|
|
667
|
-
} = useCalendarStable();
|
|
668
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
669
|
-
useCalendarState();
|
|
670
|
-
const viewCtx = useViewContext();
|
|
671
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
672
|
-
const monthStable = useContext(MonthViewStableContext);
|
|
673
|
-
const monthState = useMonthViewState();
|
|
674
|
-
const { rootState, currentMonth: currentDateTime } = monthState;
|
|
675
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
676
|
-
|
|
677
|
-
const isWeeksView = viewCtx.viewType === "weeks";
|
|
678
|
-
const cellMonth = isWeeksView
|
|
679
|
-
? { year: date.year, month: date.month }
|
|
680
|
-
: (weekData?.gridMonth ?? currentDateTime);
|
|
681
|
-
const daysInWeek = date.daysInWeek;
|
|
682
|
-
const colIdx =
|
|
683
|
-
((date.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) % daysInWeek;
|
|
684
|
-
const derived = computeDayCellState(
|
|
685
|
-
date,
|
|
686
|
-
orientation,
|
|
687
|
-
colIdx,
|
|
688
|
-
rootState,
|
|
689
|
-
selectedDates,
|
|
690
|
-
cellMonth,
|
|
691
|
-
disabled,
|
|
692
|
-
isDateDisabled,
|
|
693
|
-
focusedDate,
|
|
694
|
-
rangeStart,
|
|
695
|
-
rangeEnd,
|
|
696
|
-
tabTargetDate,
|
|
697
|
-
T,
|
|
698
|
-
selectionMode,
|
|
699
|
-
outsideDays,
|
|
700
|
-
previewStart,
|
|
701
|
-
previewEnd,
|
|
702
|
-
);
|
|
371
|
+
const state = useStandaloneDayCellState(date);
|
|
703
372
|
|
|
704
|
-
return
|
|
705
|
-
<DayButtonInner
|
|
706
|
-
{...restProps}
|
|
707
|
-
ref={ref}
|
|
708
|
-
date={date}
|
|
709
|
-
_derivedState={derived}
|
|
710
|
-
/>
|
|
711
|
-
);
|
|
373
|
+
return <DayButtonInner {...restProps} ref={ref} date={date} _state={state} />;
|
|
712
374
|
}
|
|
713
375
|
|
|
714
|
-
const
|
|
376
|
+
const StandaloneDayButton = forwardRef(StandaloneDayButtonFn) as (
|
|
715
377
|
props: Omit<DayButtonProps, "date"> & {
|
|
716
378
|
date: TemporalPoly.PlainDate;
|
|
717
379
|
} & React.RefAttributes<HTMLButtonElement>,
|