@klinking/colander 3.1.0-alpha.5 → 3.1.0-alpha.7
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 +1 -1
- package/dist/formats/date.d.cts +1 -1
- package/dist/formats/date.d.mts +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.d.cts +1 -1
- package/dist/formats/object.d.mts +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.d.cts +1 -1
- package/dist/formats/plain-date-time.d.mts +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.d.cts +1 -1
- package/dist/formats/plain-date.d.mts +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.d.cts +1 -1
- package/dist/formats/plain-month-day.d.mts +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.d.cts +1 -1
- package/dist/formats/plain-year-month.d.mts +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.d.cts +1 -1
- package/dist/formats/zoned-date-time.d.mts +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-CEV8w_69.mjs → weeks-navigation-BSKwFvdP.mjs} +367 -413
- package/dist/{weeks-navigation-q3beZn2n.cjs → weeks-navigation-CPevz3Xg.cjs} +367 -413
- package/dist/{weeks-view-context-BLZZm1fq.d.mts → weeks-view-context-BTojXkys.d.cts} +51 -10
- package/dist/{weeks-view-context-CkTcdZpj.d.cts → weeks-view-context-CFXV8orh.d.mts} +51 -10
- package/package.json +1 -1
- package/src/calendar-provider.tsx +10 -55
- package/src/day-cell-state.test.ts +214 -0
- package/src/day-cell-state.ts +314 -0
- package/src/day-cell.tsx +29 -383
- package/src/grid.tsx +1 -1
- package/src/out-of-range.test.ts +33 -53
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +120 -0
- package/src/root-selection.ts +99 -97
- package/src/weeks-navigation.tsx +12 -28
- package/src/weeks-view-state.ts +36 -84
- package/src/weeks-view-types.ts +4 -1
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-window.test.ts +131 -0
- package/src/weeks-window.ts +102 -0
package/src/day-cell.tsx
CHANGED
|
@@ -2,209 +2,19 @@ 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
4
|
import { useContext, useEffect, useRef, memo, forwardRef } from "react";
|
|
5
|
-
import { useCalendarStable
|
|
6
|
-
import { WeekDataContext, DayCellDataContext
|
|
7
|
-
import
|
|
5
|
+
import { useCalendarStable } from "./calendar-context";
|
|
6
|
+
import { WeekDataContext, DayCellDataContext } from "./context";
|
|
7
|
+
import { dayCellStateEqual, useDayCellDeriver } from "./day-cell-state";
|
|
8
|
+
import type { DayCellState } from "./day-cell-state";
|
|
8
9
|
import { MonthViewStateContext } from "./month-view-context";
|
|
9
10
|
import type { StateAttributesMapping } from "./types";
|
|
10
11
|
import type {
|
|
11
12
|
DayCellTemplateProps,
|
|
12
13
|
DayButtonProps,
|
|
13
14
|
DayCellTemplateState,
|
|
14
|
-
TemporalNamespace,
|
|
15
|
-
OutsideDays,
|
|
16
15
|
} from "./types";
|
|
17
|
-
import { shouldMoveDomFocus
|
|
18
|
-
import { useViewContext, useViewStable
|
|
19
|
-
|
|
20
|
-
/** Computes derived day cell state from context values. Pure function, no hooks. */
|
|
21
|
-
export function computeDayCellState(
|
|
22
|
-
date: TemporalPoly.PlainDate,
|
|
23
|
-
orientation: GridOrientation,
|
|
24
|
-
columnIndex: number,
|
|
25
|
-
rootState: DayCellTemplateState["root"],
|
|
26
|
-
selectedDates: TemporalPoly.PlainDate[],
|
|
27
|
-
currentDateTime: { year: number; month: number },
|
|
28
|
-
disabled: boolean,
|
|
29
|
-
isDateDisabled: ((date: TemporalPoly.PlainDate) => boolean) | undefined,
|
|
30
|
-
focusedDate: TemporalPoly.PlainDate,
|
|
31
|
-
rangeStart: TemporalPoly.PlainDate | undefined,
|
|
32
|
-
rangeEnd: TemporalPoly.PlainDate | undefined,
|
|
33
|
-
tabTargetDate: TemporalPoly.PlainDate,
|
|
34
|
-
today: 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 isToday = T.PlainDate.compare(date, today) === 0;
|
|
78
|
-
const isRange = selectionMode === "range";
|
|
79
|
-
|
|
80
|
-
let isRangeStart: boolean = false;
|
|
81
|
-
let isRangeEnd: boolean = false;
|
|
82
|
-
let isInRangeDay: boolean = false;
|
|
83
|
-
let rangeIdx: number | false = false;
|
|
84
|
-
let rangeLen: number | false = false;
|
|
85
|
-
let isPreviewRangeStart: boolean = false;
|
|
86
|
-
let isPreviewRangeEnd: boolean = false;
|
|
87
|
-
let isInPreviewRange: boolean = false;
|
|
88
|
-
let previewIdx: number | false = false;
|
|
89
|
-
let previewLen: number | false = false;
|
|
90
|
-
|
|
91
|
-
if (isRange) {
|
|
92
|
-
isRangeStart = rangeStart
|
|
93
|
-
? T.PlainDate.compare(date, rangeStart) === 0
|
|
94
|
-
: false;
|
|
95
|
-
isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
96
|
-
isInRangeDay = isInRangeUtil(date, rangeStart, rangeEnd, T) !== false;
|
|
97
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
98
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
99
|
-
rangeIdx =
|
|
100
|
-
isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
|
|
101
|
-
rangeLen =
|
|
102
|
-
isInRangeDay && effectiveStart && effectiveEnd
|
|
103
|
-
? effectiveEnd.since(effectiveStart).days + 1
|
|
104
|
-
: false;
|
|
105
|
-
|
|
106
|
-
isPreviewRangeStart = previewStart
|
|
107
|
-
? T.PlainDate.compare(date, previewStart) === 0
|
|
108
|
-
: false;
|
|
109
|
-
isPreviewRangeEnd = previewEnd
|
|
110
|
-
? T.PlainDate.compare(date, previewEnd) === 0
|
|
111
|
-
: false;
|
|
112
|
-
isInPreviewRange =
|
|
113
|
-
previewStart && previewEnd
|
|
114
|
-
? isInRangeUtil(date, previewStart, previewEnd, T) !== false
|
|
115
|
-
: false;
|
|
116
|
-
previewIdx =
|
|
117
|
-
isInPreviewRange && previewStart ? date.since(previewStart).days : false;
|
|
118
|
-
previewLen =
|
|
119
|
-
isInPreviewRange && previewStart && previewEnd
|
|
120
|
-
? previewEnd.since(previewStart).days + 1
|
|
121
|
-
: false;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
|
|
125
|
-
const suppressRange =
|
|
126
|
-
!isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
|
|
127
|
-
|
|
128
|
-
if (outsideNonInteractive) {
|
|
129
|
-
return {
|
|
130
|
-
root: rootState,
|
|
131
|
-
date,
|
|
132
|
-
columnIndex,
|
|
133
|
-
orientation,
|
|
134
|
-
outsideMonth: true,
|
|
135
|
-
hidden: false,
|
|
136
|
-
selected: false,
|
|
137
|
-
today: isToday,
|
|
138
|
-
disabled: true,
|
|
139
|
-
focused: false,
|
|
140
|
-
rangeStart: suppressRange ? false : isRangeStart,
|
|
141
|
-
rangeEnd: suppressRange ? false : isRangeEnd,
|
|
142
|
-
rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
|
|
143
|
-
inRange: suppressRange ? false : isInRangeDay,
|
|
144
|
-
rangeIndex: suppressRange ? false : rangeIdx,
|
|
145
|
-
rangeLength: suppressRange ? false : rangeLen,
|
|
146
|
-
rangeHasStart: suppressRange
|
|
147
|
-
? false
|
|
148
|
-
: isInRangeDay && rangeStart !== undefined,
|
|
149
|
-
rangeHasEnd: suppressRange
|
|
150
|
-
? false
|
|
151
|
-
: isInRangeDay && rangeEnd !== undefined,
|
|
152
|
-
rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
|
|
153
|
-
rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
|
|
154
|
-
rangePreviewBoundary: suppressRange
|
|
155
|
-
? false
|
|
156
|
-
: isPreviewRangeStart || isPreviewRangeEnd,
|
|
157
|
-
rangePreviewInRange: suppressRange ? false : isInPreviewRange,
|
|
158
|
-
rangePreviewIndex: suppressRange ? false : previewIdx,
|
|
159
|
-
rangePreviewLength: suppressRange ? false : previewLen,
|
|
160
|
-
rangePreviewHasStart: suppressRange
|
|
161
|
-
? false
|
|
162
|
-
: isInPreviewRange && previewStart !== undefined,
|
|
163
|
-
rangePreviewHasEnd: suppressRange
|
|
164
|
-
? false
|
|
165
|
-
: isInPreviewRange && previewEnd !== undefined,
|
|
166
|
-
isTabTarget: false,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const isSelected =
|
|
171
|
-
selectionMode !== "range"
|
|
172
|
-
? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0)
|
|
173
|
-
: false;
|
|
174
|
-
const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
|
|
175
|
-
const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
|
|
176
|
-
const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
root: rootState,
|
|
180
|
-
date,
|
|
181
|
-
columnIndex,
|
|
182
|
-
orientation,
|
|
183
|
-
selected: isSelected,
|
|
184
|
-
today: isToday,
|
|
185
|
-
disabled: isDisabled,
|
|
186
|
-
outsideMonth: !isCurrentMonth,
|
|
187
|
-
hidden: false,
|
|
188
|
-
focused: isFocused,
|
|
189
|
-
rangeStart: isRangeStart,
|
|
190
|
-
rangeEnd: isRangeEnd,
|
|
191
|
-
rangeBoundary: isRangeStart || isRangeEnd,
|
|
192
|
-
inRange: isInRangeDay,
|
|
193
|
-
rangeIndex: rangeIdx,
|
|
194
|
-
rangeLength: rangeLen,
|
|
195
|
-
rangeHasStart: isInRangeDay && rangeStart !== undefined,
|
|
196
|
-
rangeHasEnd: isInRangeDay && rangeEnd !== undefined,
|
|
197
|
-
rangePreviewStart: isPreviewRangeStart,
|
|
198
|
-
rangePreviewEnd: isPreviewRangeEnd,
|
|
199
|
-
rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
|
|
200
|
-
rangePreviewInRange: isInPreviewRange,
|
|
201
|
-
rangePreviewIndex: previewIdx,
|
|
202
|
-
rangePreviewLength: previewLen,
|
|
203
|
-
rangePreviewHasStart: isInPreviewRange && previewStart !== undefined,
|
|
204
|
-
rangePreviewHasEnd: isInPreviewRange && previewEnd !== undefined,
|
|
205
|
-
isTabTarget,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
16
|
+
import { shouldMoveDomFocus } from "./utils";
|
|
17
|
+
import { useViewContext, useViewStable } from "./view-context";
|
|
208
18
|
|
|
209
19
|
export const dayStateAttributesMapping = {
|
|
210
20
|
root: () => null,
|
|
@@ -247,7 +57,7 @@ interface DayCellInstanceProps {
|
|
|
247
57
|
date: TemporalPoly.PlainDate;
|
|
248
58
|
columnIndex?: number | undefined;
|
|
249
59
|
children?: React.ReactNode;
|
|
250
|
-
_derivedState:
|
|
60
|
+
_derivedState: DayCellState;
|
|
251
61
|
[key: string]: unknown;
|
|
252
62
|
}
|
|
253
63
|
|
|
@@ -338,31 +148,8 @@ export function dayCellInstancePropsAreEqual(
|
|
|
338
148
|
prev.columnIndex !== next.columnIndex
|
|
339
149
|
)
|
|
340
150
|
return false;
|
|
341
|
-
const a = prev._derivedState;
|
|
342
|
-
const b = next._derivedState;
|
|
343
151
|
return (
|
|
344
|
-
|
|
345
|
-
a.today === b.today &&
|
|
346
|
-
a.disabled === b.disabled &&
|
|
347
|
-
a.outsideMonth === b.outsideMonth &&
|
|
348
|
-
a.hidden === b.hidden &&
|
|
349
|
-
a.focused === b.focused &&
|
|
350
|
-
a.rangeStart === b.rangeStart &&
|
|
351
|
-
a.rangeEnd === b.rangeEnd &&
|
|
352
|
-
a.inRange === b.inRange &&
|
|
353
|
-
a.rangeIndex === b.rangeIndex &&
|
|
354
|
-
a.rangeLength === b.rangeLength &&
|
|
355
|
-
a.rangeHasStart === b.rangeHasStart &&
|
|
356
|
-
a.rangeHasEnd === b.rangeHasEnd &&
|
|
357
|
-
a.rangePreviewStart === b.rangePreviewStart &&
|
|
358
|
-
a.rangePreviewEnd === b.rangePreviewEnd &&
|
|
359
|
-
a.rangePreviewBoundary === b.rangePreviewBoundary &&
|
|
360
|
-
a.rangePreviewInRange === b.rangePreviewInRange &&
|
|
361
|
-
a.rangePreviewIndex === b.rangePreviewIndex &&
|
|
362
|
-
a.rangePreviewLength === b.rangePreviewLength &&
|
|
363
|
-
a.rangePreviewHasStart === b.rangePreviewHasStart &&
|
|
364
|
-
a.rangePreviewHasEnd === b.rangePreviewHasEnd &&
|
|
365
|
-
a.isTabTarget === b.isTabTarget &&
|
|
152
|
+
dayCellStateEqual(prev._derivedState, next._derivedState) &&
|
|
366
153
|
passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS)
|
|
367
154
|
);
|
|
368
155
|
}
|
|
@@ -383,63 +170,16 @@ const DayCellInstance = memo(
|
|
|
383
170
|
export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
384
171
|
const { date: dateProp, ...restProps } = props;
|
|
385
172
|
const weekData = useContext(WeekDataContext);
|
|
386
|
-
|
|
387
|
-
const {
|
|
388
|
-
disabled,
|
|
389
|
-
isDateDisabled,
|
|
390
|
-
selectionMode,
|
|
391
|
-
temporal: T,
|
|
392
|
-
today,
|
|
393
|
-
weekStartDay,
|
|
394
|
-
} = useCalendarStable();
|
|
395
|
-
const todayDate = today();
|
|
396
|
-
|
|
397
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
398
|
-
useCalendarState();
|
|
399
|
-
|
|
400
|
-
const viewCtx = useViewContext();
|
|
401
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
402
|
-
const { rootState, currentDateTime } = useViewState();
|
|
403
|
-
const { outsideDays } = useViewStable();
|
|
404
173
|
const monthState = useContext(MonthViewStateContext);
|
|
405
|
-
|
|
406
|
-
// Use the grid-specific month for outsideMonth checks, falling back to currentMonth.
|
|
407
|
-
// In multi-month mode, gridMonth is set by WeekTemplate from GridMonthContext.
|
|
408
|
-
// In weeks view, cellMonth is computed per-day (see below) so outsideMonth is always false.
|
|
409
|
-
const isWeeksView = viewCtx.viewType === "weeks";
|
|
410
|
-
const cellMonth = isWeeksView
|
|
411
|
-
? null // per-day below
|
|
412
|
-
: (weekData?.gridMonth ?? currentDateTime);
|
|
413
|
-
|
|
414
|
-
const { orientation } = useContext(GridContext);
|
|
174
|
+
const derive = useDayCellDeriver();
|
|
415
175
|
|
|
416
176
|
if (dateProp) {
|
|
417
|
-
const daysInWeek = dateProp.daysInWeek;
|
|
418
|
-
const colIdx =
|
|
419
|
-
((dateProp.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
|
|
420
|
-
daysInWeek;
|
|
421
|
-
const derived = computeDayCellState(
|
|
422
|
-
dateProp,
|
|
423
|
-
orientation,
|
|
424
|
-
colIdx,
|
|
425
|
-
rootState,
|
|
426
|
-
selectedDates,
|
|
427
|
-
isWeeksView ? { year: dateProp.year, month: dateProp.month } : cellMonth!,
|
|
428
|
-
disabled,
|
|
429
|
-
isDateDisabled,
|
|
430
|
-
focusedDate,
|
|
431
|
-
rangeStart,
|
|
432
|
-
rangeEnd,
|
|
433
|
-
tabTargetDate,
|
|
434
|
-
todayDate,
|
|
435
|
-
T,
|
|
436
|
-
selectionMode,
|
|
437
|
-
outsideDays,
|
|
438
|
-
previewStart,
|
|
439
|
-
previewEnd,
|
|
440
|
-
);
|
|
441
177
|
return (
|
|
442
|
-
<DayCellInstance
|
|
178
|
+
<DayCellInstance
|
|
179
|
+
{...restProps}
|
|
180
|
+
date={dateProp}
|
|
181
|
+
_derivedState={derive(dateProp)}
|
|
182
|
+
/>
|
|
443
183
|
);
|
|
444
184
|
}
|
|
445
185
|
|
|
@@ -448,42 +188,15 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
448
188
|
|
|
449
189
|
return (
|
|
450
190
|
<>
|
|
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
|
-
todayDate,
|
|
471
|
-
T,
|
|
472
|
-
selectionMode,
|
|
473
|
-
outsideDays,
|
|
474
|
-
previewStart,
|
|
475
|
-
previewEnd,
|
|
476
|
-
);
|
|
477
|
-
return (
|
|
478
|
-
<DayCellInstance
|
|
479
|
-
key={day.toString()}
|
|
480
|
-
{...restProps}
|
|
481
|
-
date={day}
|
|
482
|
-
columnIndex={perWeek ? i : undefined}
|
|
483
|
-
_derivedState={derived}
|
|
484
|
-
/>
|
|
485
|
-
);
|
|
486
|
-
})}
|
|
191
|
+
{days.map((day, i) => (
|
|
192
|
+
<DayCellInstance
|
|
193
|
+
key={day.toString()}
|
|
194
|
+
{...restProps}
|
|
195
|
+
date={day}
|
|
196
|
+
columnIndex={perWeek ? i : undefined}
|
|
197
|
+
_derivedState={derive(day, perWeek ? i : undefined)}
|
|
198
|
+
/>
|
|
199
|
+
))}
|
|
487
200
|
</>
|
|
488
201
|
);
|
|
489
202
|
}
|
|
@@ -492,7 +205,7 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
492
205
|
interface DayButtonInnerProps {
|
|
493
206
|
render?: DayButtonProps["render"];
|
|
494
207
|
date: TemporalPoly.PlainDate;
|
|
495
|
-
_derivedState?:
|
|
208
|
+
_derivedState?: DayCellState;
|
|
496
209
|
[key: string]: unknown;
|
|
497
210
|
}
|
|
498
211
|
|
|
@@ -570,30 +283,7 @@ export function dayButtonInnerPropsAreEqual(
|
|
|
570
283
|
const a = prev._derivedState;
|
|
571
284
|
const b = next._derivedState;
|
|
572
285
|
if (!a || !b) return a === b;
|
|
573
|
-
return (
|
|
574
|
-
a.selected === b.selected &&
|
|
575
|
-
a.today === b.today &&
|
|
576
|
-
a.disabled === b.disabled &&
|
|
577
|
-
a.outsideMonth === b.outsideMonth &&
|
|
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
|
|
596
|
-
);
|
|
286
|
+
return dayCellStateEqual(a, b);
|
|
597
287
|
}
|
|
598
288
|
|
|
599
289
|
// The `as any` casts are needed because DayButtonInnerProps uses an index
|
|
@@ -614,7 +304,7 @@ const DayButtonInner = memo(
|
|
|
614
304
|
*/
|
|
615
305
|
function DayButtonFn(
|
|
616
306
|
props: DayButtonProps & {
|
|
617
|
-
_derivedState?:
|
|
307
|
+
_derivedState?: DayCellState;
|
|
618
308
|
},
|
|
619
309
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
620
310
|
) {
|
|
@@ -646,7 +336,7 @@ function DayButtonFn(
|
|
|
646
336
|
|
|
647
337
|
export const DayButton = forwardRef(DayButtonFn) as (
|
|
648
338
|
props: DayButtonProps & {
|
|
649
|
-
_derivedState?:
|
|
339
|
+
_derivedState?: DayCellState;
|
|
650
340
|
} & React.RefAttributes<HTMLButtonElement>,
|
|
651
341
|
) => React.ReactElement | null;
|
|
652
342
|
|
|
@@ -656,58 +346,14 @@ function DayButtonFallbackFn(
|
|
|
656
346
|
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
657
347
|
) {
|
|
658
348
|
const { date, ...restProps } = props;
|
|
659
|
-
const
|
|
660
|
-
const weekData = useContext(WeekDataContext);
|
|
661
|
-
const {
|
|
662
|
-
disabled,
|
|
663
|
-
isDateDisabled,
|
|
664
|
-
selectionMode,
|
|
665
|
-
temporal: T,
|
|
666
|
-
today,
|
|
667
|
-
weekStartDay,
|
|
668
|
-
} = useCalendarStable();
|
|
669
|
-
const todayDate = today();
|
|
670
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
671
|
-
useCalendarState();
|
|
672
|
-
const viewCtx = useViewContext();
|
|
673
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
674
|
-
const { rootState, currentDateTime } = useViewState();
|
|
675
|
-
const { outsideDays } = useViewStable();
|
|
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
|
-
todayDate,
|
|
698
|
-
T,
|
|
699
|
-
selectionMode,
|
|
700
|
-
outsideDays,
|
|
701
|
-
previewStart,
|
|
702
|
-
previewEnd,
|
|
703
|
-
);
|
|
349
|
+
const derive = useDayCellDeriver();
|
|
704
350
|
|
|
705
351
|
return (
|
|
706
352
|
<DayButtonInner
|
|
707
353
|
{...restProps}
|
|
708
354
|
ref={ref}
|
|
709
355
|
date={date}
|
|
710
|
-
_derivedState={
|
|
356
|
+
_derivedState={derive(date)}
|
|
711
357
|
/>
|
|
712
358
|
);
|
|
713
359
|
}
|
package/src/grid.tsx
CHANGED
|
@@ -109,7 +109,7 @@ function useWeeksGridKeyboard() {
|
|
|
109
109
|
shiftKey: e.shiftKey,
|
|
110
110
|
focusedDate,
|
|
111
111
|
windowStart: weeksState.windowInfo.windowStart,
|
|
112
|
-
weekCount:
|
|
112
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
113
113
|
minValue,
|
|
114
114
|
maxValue,
|
|
115
115
|
disabled,
|
package/src/out-of-range.test.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { describe, it, expect } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
applyOutOfRange,
|
|
5
|
-
canShift,
|
|
6
|
-
type OutOfRangeBehavior,
|
|
7
|
-
} from "./out-of-range";
|
|
3
|
+
import { applyOutOfRange, type OutOfRangeBehavior } from "./out-of-range";
|
|
8
4
|
|
|
9
5
|
const T = Temporal;
|
|
10
6
|
const pd = (s: string) => T.PlainDate.from(s);
|
|
@@ -19,7 +15,7 @@ describe("applyOutOfRange", () => {
|
|
|
19
15
|
targetFirstWeek: pd("2026-02-01"),
|
|
20
16
|
weekCount: 8,
|
|
21
17
|
behavior: "unbounded" as OutOfRangeBehavior,
|
|
22
|
-
useMinMax:
|
|
18
|
+
useMinMax: "both" as const,
|
|
23
19
|
expected: { firstWeek: "2026-02-01", weekCount: 8 },
|
|
24
20
|
},
|
|
25
21
|
{
|
|
@@ -27,7 +23,7 @@ describe("applyOutOfRange", () => {
|
|
|
27
23
|
targetFirstWeek: pd("2025-12-07"),
|
|
28
24
|
weekCount: 8,
|
|
29
25
|
behavior: "stop" as OutOfRangeBehavior,
|
|
30
|
-
useMinMax:
|
|
26
|
+
useMinMax: "both" as const,
|
|
31
27
|
expected: { firstWeek: "2025-12-07", weekCount: 8 },
|
|
32
28
|
},
|
|
33
29
|
{
|
|
@@ -35,7 +31,7 @@ describe("applyOutOfRange", () => {
|
|
|
35
31
|
targetFirstWeek: pd("2026-01-11"),
|
|
36
32
|
weekCount: 8,
|
|
37
33
|
behavior: "snap" as OutOfRangeBehavior,
|
|
38
|
-
useMinMax:
|
|
34
|
+
useMinMax: "both" as const,
|
|
39
35
|
expected: {
|
|
40
36
|
firstWeek: "2025-11-16",
|
|
41
37
|
weekCount: 8,
|
|
@@ -46,7 +42,7 @@ describe("applyOutOfRange", () => {
|
|
|
46
42
|
targetFirstWeek: pd("2026-01-11"),
|
|
47
43
|
weekCount: 8,
|
|
48
44
|
behavior: "snap-shrink" as OutOfRangeBehavior,
|
|
49
|
-
useMinMax:
|
|
45
|
+
useMinMax: "both" as const,
|
|
50
46
|
expected: {
|
|
51
47
|
firstWeek: "2025-11-30",
|
|
52
48
|
weekCount: 6,
|
|
@@ -57,18 +53,42 @@ describe("applyOutOfRange", () => {
|
|
|
57
53
|
targetFirstWeek: pd("2025-12-07"),
|
|
58
54
|
weekCount: 8,
|
|
59
55
|
behavior: "stop-shrink" as OutOfRangeBehavior,
|
|
60
|
-
useMinMax:
|
|
56
|
+
useMinMax: "both" as const,
|
|
61
57
|
expected: {
|
|
62
58
|
firstWeek: "2025-12-07",
|
|
63
59
|
weekCount: 5,
|
|
64
60
|
},
|
|
65
61
|
},
|
|
62
|
+
{
|
|
63
|
+
description: "max only, snap — pulls back when target overshoots max",
|
|
64
|
+
targetFirstWeek: pd("2026-01-11"),
|
|
65
|
+
weekCount: 8,
|
|
66
|
+
behavior: "snap" as OutOfRangeBehavior,
|
|
67
|
+
useMinMax: "max" as const,
|
|
68
|
+
expected: { firstWeek: "2025-11-16", weekCount: 8 },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
description: "min only, snap — pulls forward when target undershoots min",
|
|
72
|
+
targetFirstWeek: pd("2025-10-01"),
|
|
73
|
+
weekCount: 8,
|
|
74
|
+
behavior: "snap" as OutOfRangeBehavior,
|
|
75
|
+
useMinMax: "min" as const,
|
|
76
|
+
expected: { firstWeek: "2025-11-30", weekCount: 8 },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
description: "min only, stop-shrink — trims leading disabled rows",
|
|
80
|
+
targetFirstWeek: pd("2025-11-16"),
|
|
81
|
+
weekCount: 8,
|
|
82
|
+
behavior: "stop-shrink" as OutOfRangeBehavior,
|
|
83
|
+
useMinMax: "min" as const,
|
|
84
|
+
expected: { firstWeek: "2025-11-30", weekCount: 6 },
|
|
85
|
+
},
|
|
66
86
|
{
|
|
67
87
|
description: "no min/max — all modes behave as unbounded",
|
|
68
88
|
targetFirstWeek: pd("2026-06-01"),
|
|
69
89
|
weekCount: 8,
|
|
70
90
|
behavior: "snap" as OutOfRangeBehavior,
|
|
71
|
-
useMinMax:
|
|
91
|
+
useMinMax: "none" as const,
|
|
72
92
|
expected: { firstWeek: "2026-06-01", weekCount: 8 },
|
|
73
93
|
},
|
|
74
94
|
])(
|
|
@@ -78,7 +98,8 @@ describe("applyOutOfRange", () => {
|
|
|
78
98
|
targetFirstWeek,
|
|
79
99
|
weekCount,
|
|
80
100
|
behavior,
|
|
81
|
-
...(useMinMax && { min
|
|
101
|
+
...((useMinMax === "both" || useMinMax === "min") && { min }),
|
|
102
|
+
...((useMinMax === "both" || useMinMax === "max") && { max }),
|
|
82
103
|
weekStartDay: 0,
|
|
83
104
|
T,
|
|
84
105
|
});
|
|
@@ -87,44 +108,3 @@ describe("applyOutOfRange", () => {
|
|
|
87
108
|
},
|
|
88
109
|
);
|
|
89
110
|
});
|
|
90
|
-
|
|
91
|
-
describe("canShift", () => {
|
|
92
|
-
const min = pd("2025-12-01");
|
|
93
|
-
const max = pd("2026-01-10");
|
|
94
|
-
|
|
95
|
-
it.each([
|
|
96
|
-
{
|
|
97
|
-
description: "unbounded — always true",
|
|
98
|
-
behavior: "unbounded" as OutOfRangeBehavior,
|
|
99
|
-
currentFirstWeek: pd("2026-06-01"),
|
|
100
|
-
direction: 1 as const,
|
|
101
|
-
expected: true,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
description: "stop — false when target has no valid weeks",
|
|
105
|
-
behavior: "stop" as OutOfRangeBehavior,
|
|
106
|
-
currentFirstWeek: pd("2025-12-28"),
|
|
107
|
-
direction: 1 as const,
|
|
108
|
-
expected: false,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
description: "snap — false when already at clamp position",
|
|
112
|
-
behavior: "snap" as OutOfRangeBehavior,
|
|
113
|
-
currentFirstWeek: pd("2025-11-16"),
|
|
114
|
-
direction: 1 as const,
|
|
115
|
-
expected: false,
|
|
116
|
-
},
|
|
117
|
-
])("$description", ({ behavior, currentFirstWeek, direction, expected }) => {
|
|
118
|
-
const result = canShift({
|
|
119
|
-
currentFirstWeek,
|
|
120
|
-
weekCount: 8,
|
|
121
|
-
direction,
|
|
122
|
-
behavior,
|
|
123
|
-
min,
|
|
124
|
-
max,
|
|
125
|
-
weekStartDay: 0,
|
|
126
|
-
T,
|
|
127
|
-
});
|
|
128
|
-
expect(result).toBe(expected);
|
|
129
|
-
});
|
|
130
|
-
});
|