@klinking/colander 0.0.0 → 2.0.1
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 +51 -48
- package/dist/formats/date.d.cts +10 -37
- package/dist/formats/date.d.mts +10 -37
- package/dist/formats/date.mjs +6 -2
- package/dist/formats/object.cjs +51 -48
- package/dist/formats/object.d.cts +10 -37
- package/dist/formats/object.d.mts +10 -37
- package/dist/formats/object.mjs +6 -2
- package/dist/formats/plain-date-time.cjs +51 -48
- package/dist/formats/plain-date-time.d.cts +10 -37
- package/dist/formats/plain-date-time.d.mts +10 -37
- package/dist/formats/plain-date-time.mjs +6 -2
- package/dist/formats/plain-date.cjs +51 -48
- package/dist/formats/plain-date.d.cts +10 -37
- package/dist/formats/plain-date.d.mts +10 -37
- package/dist/formats/plain-date.mjs +6 -2
- package/dist/formats/plain-month-day.cjs +51 -48
- package/dist/formats/plain-month-day.d.cts +10 -37
- package/dist/formats/plain-month-day.d.mts +10 -37
- package/dist/formats/plain-month-day.mjs +6 -2
- package/dist/formats/plain-year-month.cjs +51 -48
- package/dist/formats/plain-year-month.d.cts +10 -37
- package/dist/formats/plain-year-month.d.mts +10 -37
- package/dist/formats/plain-year-month.mjs +6 -2
- package/dist/formats/zoned-date-time.cjs +51 -48
- package/dist/formats/zoned-date-time.d.cts +10 -37
- package/dist/formats/zoned-date-time.d.mts +10 -37
- package/dist/formats/zoned-date-time.mjs +6 -2
- package/dist/index.cjs +47 -48
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +2 -2
- package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-B-Nch3LS.mjs} +357 -562
- package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-FxcECgCR.cjs} +357 -568
- package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
- package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
- package/package.json +20 -20
- package/src/calendar-context.ts +12 -5
- package/src/calendar-provider.test.tsx +18 -4
- package/src/calendar-provider.tsx +130 -35
- package/src/calendar-types.ts +21 -4
- package/src/compute-weeks-in-window.test.ts +9 -7
- package/src/context.ts +1 -1
- package/src/day-cell.test.tsx +109 -0
- package/src/day-cell.tsx +132 -49
- package/src/drag-handle.tsx +23 -24
- package/src/formats/date.ts +120 -56
- package/src/formats/formats.test.ts +8 -4
- package/src/formats/object.ts +120 -56
- package/src/formats/plain-date-time.ts +120 -56
- package/src/formats/plain-date.ts +120 -56
- package/src/formats/plain-month-day.ts +120 -56
- package/src/formats/plain-year-month.ts +120 -56
- package/src/formats/zoned-date-time.ts +120 -56
- package/src/grid-header.tsx +24 -18
- package/src/grid.event-perf.test.tsx +30 -13
- package/src/grid.perf.test.tsx +97 -33
- package/src/grid.tsx +75 -43
- package/src/index.ts +16 -4
- package/src/keyboard.test.ts +110 -42
- package/src/keyboard.ts +18 -7
- package/src/month-separator.test.tsx +3 -1
- package/src/month-separator.tsx +30 -9
- package/src/month-view-context.ts +8 -3
- package/src/month-view-types.ts +14 -10
- package/src/month-view.test.tsx +687 -68
- package/src/month-view.tsx +176 -71
- package/src/navigation.tsx +77 -47
- package/src/overflow.test.ts +15 -13
- package/src/overflow.ts +10 -2
- package/src/range-preview.tsx +37 -12
- package/src/resolve-first-week.test.ts +14 -10
- package/src/resolve-first-week.ts +6 -2
- package/src/root-selection.ts +185 -101
- package/src/selected-range.tsx +47 -22
- package/src/test-temporal.ts +0 -2
- package/src/types.ts +126 -103
- package/src/utils.bench.ts +30 -6
- package/src/utils.test.ts +203 -55
- package/src/utils.ts +156 -54
- package/src/view-context.ts +4 -1
- package/src/week-number.tsx +5 -8
- package/src/weeks-grid.tsx +45 -19
- package/src/weeks-keyboard.test.ts +6 -7
- package/src/weeks-keyboard.ts +8 -3
- package/src/weeks-navigation.tsx +21 -9
- package/src/weeks-view-context.ts +8 -3
- package/src/weeks-view-state.ts +100 -33
- package/src/weeks-view-types.ts +14 -8
- package/src/weeks-view.test.tsx +127 -19
- package/src/weeks-view.tsx +30 -12
- package/src/temporal-polyfill.test.ts +0 -317
- package/src/temporal-polyfill.ts +0 -566
package/src/range-preview.tsx
CHANGED
|
@@ -5,10 +5,16 @@ import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
|
5
5
|
import { WeekDataContext, GridContext } from "./context";
|
|
6
6
|
import { useMonthViewState } from "./month-view-context";
|
|
7
7
|
import { MonthViewStableContext } from "./month-view-context";
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
computeClippedRangeInfo,
|
|
10
|
+
rangeOverlayStateAttributesMapping,
|
|
11
|
+
} from "./selected-range";
|
|
12
|
+
import type { RangePreviewState, RangePreviewProps } from "./types";
|
|
10
13
|
|
|
11
|
-
function RangePreviewFn(
|
|
14
|
+
function RangePreviewFn(
|
|
15
|
+
props: RangePreviewProps,
|
|
16
|
+
ref: React.ForwardedRef<HTMLTableCellElement>,
|
|
17
|
+
) {
|
|
12
18
|
const { selectionMode } = useCalendarStable();
|
|
13
19
|
if (selectionMode !== "range") {
|
|
14
20
|
return null;
|
|
@@ -22,8 +28,8 @@ function RangePreviewFn(props: RangePreviewProps, ref: React.ForwardedRef<HTMLTa
|
|
|
22
28
|
* {@link RangeSelected} but reads `previewStart`/`previewEnd` instead of
|
|
23
29
|
* the committed range boundaries.
|
|
24
30
|
*/
|
|
25
|
-
export const RangePreview = forwardRef(RangePreviewFn) as
|
|
26
|
-
props: RangePreviewProps
|
|
31
|
+
export const RangePreview = forwardRef(RangePreviewFn) as (
|
|
32
|
+
props: RangePreviewProps & React.RefAttributes<HTMLTableCellElement>,
|
|
27
33
|
) => React.ReactElement | null;
|
|
28
34
|
|
|
29
35
|
function RangePreviewInnerFn(
|
|
@@ -43,18 +49,28 @@ function RangePreviewInnerFn(
|
|
|
43
49
|
const gridMonth = weekData?.gridMonth;
|
|
44
50
|
|
|
45
51
|
const info = useMemo(
|
|
46
|
-
() =>
|
|
52
|
+
() =>
|
|
53
|
+
computeClippedRangeInfo(
|
|
54
|
+
days,
|
|
55
|
+
previewStart,
|
|
56
|
+
previewEnd,
|
|
57
|
+
T,
|
|
58
|
+
outsideDays,
|
|
59
|
+
gridMonth,
|
|
60
|
+
),
|
|
47
61
|
[days, previewStart, previewEnd, T, outsideDays, gridMonth],
|
|
48
62
|
);
|
|
49
63
|
|
|
50
|
-
const startDate = info.active
|
|
51
|
-
|
|
64
|
+
const startDate = info.active
|
|
65
|
+
? (days[info.startIndex]?.toString() ?? "")
|
|
66
|
+
: "";
|
|
67
|
+
const endDate = info.active ? (days[info.endIndex]?.toString() ?? "") : "";
|
|
52
68
|
|
|
53
69
|
const weekIndex = weekData?.weekIndex ?? 0;
|
|
54
70
|
|
|
55
71
|
const state = useMemo<RangePreviewState>(
|
|
56
72
|
() => ({
|
|
57
|
-
root: rootState
|
|
73
|
+
root: rootState,
|
|
58
74
|
active: info.active,
|
|
59
75
|
weekIndex,
|
|
60
76
|
startIndex: info.startIndex,
|
|
@@ -67,7 +83,16 @@ function RangePreviewInnerFn(
|
|
|
67
83
|
hasEnd: previewEnd !== undefined,
|
|
68
84
|
orientation,
|
|
69
85
|
}),
|
|
70
|
-
[
|
|
86
|
+
[
|
|
87
|
+
rootState,
|
|
88
|
+
info,
|
|
89
|
+
weekIndex,
|
|
90
|
+
startDate,
|
|
91
|
+
endDate,
|
|
92
|
+
previewStart,
|
|
93
|
+
previewEnd,
|
|
94
|
+
orientation,
|
|
95
|
+
],
|
|
71
96
|
);
|
|
72
97
|
|
|
73
98
|
const defaultProps: Record<string, unknown> = {
|
|
@@ -85,6 +110,6 @@ function RangePreviewInnerFn(
|
|
|
85
110
|
});
|
|
86
111
|
}
|
|
87
112
|
|
|
88
|
-
const RangePreviewInner = forwardRef(RangePreviewInnerFn) as
|
|
89
|
-
props: RangePreviewProps
|
|
113
|
+
const RangePreviewInner = forwardRef(RangePreviewInnerFn) as (
|
|
114
|
+
props: RangePreviewProps & React.RefAttributes<HTMLTableCellElement>,
|
|
90
115
|
) => React.ReactElement | null;
|
|
@@ -39,7 +39,8 @@ describe("resolveFirstWeekSpec", () => {
|
|
|
39
39
|
expected: "2026-01-04",
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
description:
|
|
42
|
+
description:
|
|
43
|
+
"month+year spec — first week containing a day in that month",
|
|
43
44
|
spec: { month: 3, year: 2026 },
|
|
44
45
|
weekStartDay: 0 as const,
|
|
45
46
|
expected: "2026-03-01",
|
|
@@ -120,13 +121,16 @@ describe("resolveFirstWeek", () => {
|
|
|
120
121
|
snap: undefined,
|
|
121
122
|
expected: "2026-03-15",
|
|
122
123
|
},
|
|
123
|
-
])(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
])(
|
|
125
|
+
"$description",
|
|
126
|
+
({ currentFirstWeek, weekCount, target, snap, expected }) => {
|
|
127
|
+
const result = resolveFirstWeek(
|
|
128
|
+
currentFirstWeek,
|
|
129
|
+
weekCount,
|
|
130
|
+
target,
|
|
131
|
+
snap ? { snap } : undefined,
|
|
132
|
+
);
|
|
133
|
+
expect(result.toString()).toBe(expected);
|
|
134
|
+
},
|
|
135
|
+
);
|
|
132
136
|
});
|
|
@@ -16,7 +16,10 @@ export type FirstWeekSpec =
|
|
|
16
16
|
export type ScrollToWeekSnap = "start" | "center" | "end" | "nearest";
|
|
17
17
|
|
|
18
18
|
/** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
|
|
19
|
-
function snapToWeekStart(
|
|
19
|
+
function snapToWeekStart(
|
|
20
|
+
date: Temporal.PlainDate,
|
|
21
|
+
weekStartDay: WeekStartDay,
|
|
22
|
+
): Temporal.PlainDate {
|
|
20
23
|
const dow = date.dayOfWeek % 7; // 0=Sun..6=Sat
|
|
21
24
|
const offset = (dow - weekStartDay + 7) % 7;
|
|
22
25
|
return date.subtract({ days: offset });
|
|
@@ -52,7 +55,8 @@ export function resolveFirstWeekSpec(
|
|
|
52
55
|
day: "numeric",
|
|
53
56
|
});
|
|
54
57
|
const parts = fmt.formatToParts(spec);
|
|
55
|
-
const get = (type: string) =>
|
|
58
|
+
const get = (type: string) =>
|
|
59
|
+
Number(parts.find((p) => p.type === type)?.value ?? 0);
|
|
56
60
|
const plain = T.PlainDate.from({
|
|
57
61
|
year: get("year"),
|
|
58
62
|
month: get("month"),
|
package/src/root-selection.ts
CHANGED
|
@@ -29,43 +29,47 @@ export interface UseRootStateParamsBase<F extends ValueFormat> {
|
|
|
29
29
|
onMonthChange?: (month: Temporal.PlainYearMonth) => void;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export type UseRootStateParams<F extends ValueFormat> =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
export type UseRootStateParams<F extends ValueFormat> =
|
|
33
|
+
UseRootStateParamsBase<F> &
|
|
34
|
+
(
|
|
35
|
+
| {
|
|
36
|
+
selectionMode: "single";
|
|
37
|
+
value?: RawValueForFormat<F> | null;
|
|
38
|
+
defaultValue?: RawValueForFormat<F>;
|
|
39
|
+
onValueChange?: (
|
|
40
|
+
value: RawValueForFormat<F> | null,
|
|
41
|
+
meta: ValueChangeMeta<RawValueForFormat<F> | null>,
|
|
42
|
+
) => void;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
selectionMode: "range";
|
|
46
|
+
value?: DateRange<F> | null;
|
|
47
|
+
defaultValue?: DateRange<F>;
|
|
48
|
+
onValueChange?: (
|
|
49
|
+
value: DateRange<F> | null,
|
|
50
|
+
meta: ValueChangeMeta<DateRange<F> | null>,
|
|
51
|
+
) => void;
|
|
52
|
+
rangeMode?: RangeMode;
|
|
53
|
+
preventRangeReversal?: boolean;
|
|
54
|
+
previewRange?: DateRange<F> | null;
|
|
55
|
+
onHoveredDateChange?: (date: Temporal.PlainDate | undefined) => void;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
selectionMode: "multiple";
|
|
59
|
+
value?: RawValueForFormat<F>[] | null;
|
|
60
|
+
defaultValue?: RawValueForFormat<F>[];
|
|
61
|
+
onValueChange?: (
|
|
62
|
+
value: RawValueForFormat<F>[],
|
|
63
|
+
meta: ValueChangeMeta<RawValueForFormat<F>[]>,
|
|
64
|
+
) => void;
|
|
65
|
+
}
|
|
66
|
+
);
|
|
66
67
|
|
|
67
68
|
/** Construct a DateRange (workaround for TS generic conditional type widening). */
|
|
68
|
-
function mkRange<F extends ValueFormat>(
|
|
69
|
+
function mkRange<F extends ValueFormat>(
|
|
70
|
+
start: unknown,
|
|
71
|
+
end: unknown,
|
|
72
|
+
): DateRange<F> {
|
|
69
73
|
return { start, end } as DateRange<F>;
|
|
70
74
|
}
|
|
71
75
|
|
|
@@ -124,7 +128,7 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
124
128
|
isDateDisabled: (date: Temporal.PlainDate) => boolean;
|
|
125
129
|
isMultiple: boolean;
|
|
126
130
|
isRange: boolean;
|
|
127
|
-
committedDates: (Temporal.PlainDate | null)[];
|
|
131
|
+
committedDates: readonly (Temporal.PlainDate | null)[];
|
|
128
132
|
committedStart: Temporal.PlainDate | undefined;
|
|
129
133
|
committedEnd: Temporal.PlainDate | undefined;
|
|
130
134
|
selectedZdt: Temporal.ZonedDateTime | undefined;
|
|
@@ -163,7 +167,9 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
163
167
|
if (isDateDisabled(date)) return { skip: true };
|
|
164
168
|
|
|
165
169
|
if (isMultiple) {
|
|
166
|
-
const dates = committedDates.filter(
|
|
170
|
+
const dates = committedDates.filter(
|
|
171
|
+
(d): d is Temporal.PlainDate => d != null,
|
|
172
|
+
);
|
|
167
173
|
const prevArr = currentMultipleFormatted();
|
|
168
174
|
const idx = dates.findIndex((d) => T.PlainDate.compare(d, date) === 0);
|
|
169
175
|
let newDates: (Temporal.PlainDate | null)[];
|
|
@@ -177,7 +183,10 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
177
183
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
178
184
|
(
|
|
179
185
|
onValueChange as
|
|
180
|
-
| ((
|
|
186
|
+
| ((
|
|
187
|
+
v: RawValueForFormat<F>[],
|
|
188
|
+
m: ValueChangeMeta<RawValueForFormat<F>[]>,
|
|
189
|
+
) => void)
|
|
181
190
|
| undefined
|
|
182
191
|
)?.((newDates as Temporal.PlainDate[]).map(plainToFormatValue), {
|
|
183
192
|
date,
|
|
@@ -191,12 +200,18 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
191
200
|
if (isRange && rangeMode === "start-end") {
|
|
192
201
|
const prevRange = currentRangeFormatted();
|
|
193
202
|
const isPending =
|
|
194
|
-
committedDates.length === 2 &&
|
|
203
|
+
committedDates.length === 2 &&
|
|
204
|
+
(committedDates[0] === null || committedDates[1] === null);
|
|
195
205
|
const isComplete =
|
|
196
|
-
committedDates.length === 2 &&
|
|
206
|
+
committedDates.length === 2 &&
|
|
207
|
+
committedDates[0] != null &&
|
|
208
|
+
committedDates[1] != null;
|
|
197
209
|
|
|
198
210
|
type RangeCb =
|
|
199
|
-
| ((
|
|
211
|
+
| ((
|
|
212
|
+
v: DateRange<F> | null,
|
|
213
|
+
m: ValueChangeMeta<DateRange<F> | null>,
|
|
214
|
+
) => void)
|
|
200
215
|
| undefined;
|
|
201
216
|
|
|
202
217
|
// No selection → first click: fire partial range {start, end: null}
|
|
@@ -204,10 +219,13 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
204
219
|
return {
|
|
205
220
|
newDates: [date, null],
|
|
206
221
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
207
|
-
(onValueChange as RangeCb)?.(
|
|
208
|
-
date,
|
|
209
|
-
|
|
210
|
-
|
|
222
|
+
(onValueChange as RangeCb)?.(
|
|
223
|
+
mkRange<F>(plainToFormatValue(date), null),
|
|
224
|
+
{
|
|
225
|
+
date,
|
|
226
|
+
previous: prevRange,
|
|
227
|
+
},
|
|
228
|
+
);
|
|
211
229
|
},
|
|
212
230
|
};
|
|
213
231
|
}
|
|
@@ -268,10 +286,10 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
268
286
|
|
|
269
287
|
// Complete range [date1, date2]
|
|
270
288
|
if (isComplete) {
|
|
271
|
-
const start = committedDates[0]
|
|
272
|
-
const end = committedDates[1]
|
|
273
|
-
const isOnStart = T.PlainDate.compare(date, start) === 0;
|
|
274
|
-
const isOnEnd = T.PlainDate.compare(date, end) === 0;
|
|
289
|
+
const start = committedDates[0];
|
|
290
|
+
const end = committedDates[1];
|
|
291
|
+
const isOnStart = start != null && T.PlainDate.compare(date, start) === 0;
|
|
292
|
+
const isOnEnd = end != null && T.PlainDate.compare(date, end) === 0;
|
|
275
293
|
|
|
276
294
|
// Click boundary → deselect
|
|
277
295
|
if (isOnStart || isOnEnd) {
|
|
@@ -290,10 +308,13 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
290
308
|
return {
|
|
291
309
|
newDates: [date, null],
|
|
292
310
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
293
|
-
(onValueChange as RangeCb)?.(
|
|
294
|
-
date,
|
|
295
|
-
|
|
296
|
-
|
|
311
|
+
(onValueChange as RangeCb)?.(
|
|
312
|
+
mkRange<F>(plainToFormatValue(date), null),
|
|
313
|
+
{
|
|
314
|
+
date,
|
|
315
|
+
previous: prevRange,
|
|
316
|
+
},
|
|
317
|
+
);
|
|
297
318
|
},
|
|
298
319
|
};
|
|
299
320
|
}
|
|
@@ -313,7 +334,10 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
313
334
|
fireCallback: (onValueChange) => {
|
|
314
335
|
(
|
|
315
336
|
onValueChange as
|
|
316
|
-
| ((
|
|
337
|
+
| ((
|
|
338
|
+
v: DateRange<F> | null,
|
|
339
|
+
m: ValueChangeMeta<DateRange<F> | null>,
|
|
340
|
+
) => void)
|
|
317
341
|
| undefined
|
|
318
342
|
)?.(null, { date, previous: prevRange });
|
|
319
343
|
},
|
|
@@ -331,12 +355,18 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
331
355
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
332
356
|
(
|
|
333
357
|
onValueChange as
|
|
334
|
-
| ((
|
|
358
|
+
| ((
|
|
359
|
+
v: DateRange<F> | null,
|
|
360
|
+
m: ValueChangeMeta<DateRange<F> | null>,
|
|
361
|
+
) => void)
|
|
335
362
|
| undefined
|
|
336
|
-
)?.(
|
|
337
|
-
date,
|
|
338
|
-
|
|
339
|
-
|
|
363
|
+
)?.(
|
|
364
|
+
mkRange<F>(plainToFormatValue(date), plainToFormatValue(date)),
|
|
365
|
+
{
|
|
366
|
+
date,
|
|
367
|
+
previous: prevRange,
|
|
368
|
+
},
|
|
369
|
+
);
|
|
340
370
|
},
|
|
341
371
|
};
|
|
342
372
|
}
|
|
@@ -345,48 +375,67 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
345
375
|
const beforeStart = T.PlainDate.compare(date, committedStart) < 0;
|
|
346
376
|
const afterEnd = T.PlainDate.compare(date, committedEnd) > 0;
|
|
347
377
|
|
|
348
|
-
let
|
|
378
|
+
let newStart: Temporal.PlainDate;
|
|
379
|
+
let newEnd: Temporal.PlainDate;
|
|
349
380
|
if (beforeStart) {
|
|
350
|
-
|
|
381
|
+
newStart = date;
|
|
382
|
+
newEnd = committedEnd;
|
|
351
383
|
} else if (afterEnd) {
|
|
352
|
-
|
|
384
|
+
newStart = committedStart;
|
|
385
|
+
newEnd = date;
|
|
353
386
|
} else {
|
|
354
|
-
const action = resolveInsideAction(
|
|
387
|
+
const action = resolveInsideAction(
|
|
388
|
+
rangeMode,
|
|
389
|
+
date,
|
|
390
|
+
committedStart,
|
|
391
|
+
committedEnd,
|
|
392
|
+
);
|
|
355
393
|
if (action === "start") {
|
|
356
|
-
|
|
394
|
+
newStart = date;
|
|
395
|
+
newEnd = committedEnd;
|
|
357
396
|
} else if (action === "end") {
|
|
358
|
-
|
|
397
|
+
newStart = committedStart;
|
|
398
|
+
newEnd = date;
|
|
359
399
|
} else {
|
|
360
|
-
|
|
400
|
+
newStart = date;
|
|
401
|
+
newEnd = date;
|
|
361
402
|
}
|
|
362
403
|
}
|
|
363
404
|
|
|
364
405
|
return {
|
|
365
|
-
newDates,
|
|
406
|
+
newDates: [newStart, newEnd],
|
|
366
407
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
367
408
|
(
|
|
368
409
|
onValueChange as
|
|
369
|
-
| ((
|
|
410
|
+
| ((
|
|
411
|
+
v: DateRange<F> | null,
|
|
412
|
+
m: ValueChangeMeta<DateRange<F> | null>,
|
|
413
|
+
) => void)
|
|
370
414
|
| undefined
|
|
371
|
-
)?.(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
415
|
+
)?.(
|
|
416
|
+
mkRange<F>(plainToFormatValue(newStart), plainToFormatValue(newEnd)),
|
|
417
|
+
{
|
|
418
|
+
date,
|
|
419
|
+
previous: prevRange,
|
|
420
|
+
},
|
|
421
|
+
);
|
|
375
422
|
},
|
|
376
423
|
};
|
|
377
424
|
}
|
|
378
425
|
|
|
379
426
|
if (isRange) {
|
|
380
427
|
const prevRange = currentRangeFormatted();
|
|
381
|
-
const newDates = [date, date];
|
|
382
428
|
return {
|
|
383
|
-
newDates,
|
|
429
|
+
newDates: [date, date],
|
|
384
430
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
385
431
|
(
|
|
386
432
|
onValueChange as
|
|
387
|
-
| ((
|
|
433
|
+
| ((
|
|
434
|
+
v: DateRange<F> | null,
|
|
435
|
+
m: ValueChangeMeta<DateRange<F> | null>,
|
|
436
|
+
) => void)
|
|
388
437
|
| undefined
|
|
389
|
-
)?.(mkRange<F>(plainToFormatValue(
|
|
438
|
+
)?.(mkRange<F>(plainToFormatValue(date), plainToFormatValue(date)), {
|
|
390
439
|
date,
|
|
391
440
|
previous: prevRange,
|
|
392
441
|
});
|
|
@@ -432,7 +481,10 @@ export function computeSelectionUpdate<F extends ValueFormat>(opts: {
|
|
|
432
481
|
const newTagged = fromZonedDateTime(newZdt, resolvedFormat, T);
|
|
433
482
|
(
|
|
434
483
|
onValueChange as
|
|
435
|
-
| ((
|
|
484
|
+
| ((
|
|
485
|
+
v: DateValueObject["value"],
|
|
486
|
+
m: ValueChangeMeta<RawValueForFormat<F> | null>,
|
|
487
|
+
) => void)
|
|
436
488
|
| undefined
|
|
437
489
|
)?.(newTagged.value, { date, previous: prevSingle });
|
|
438
490
|
},
|
|
@@ -467,7 +519,8 @@ export function computeSetRangeUpdate<F extends ValueFormat>(opts: {
|
|
|
467
519
|
|
|
468
520
|
if (readOnly || isMultiple) return { skip: true };
|
|
469
521
|
|
|
470
|
-
const [lo, hi] =
|
|
522
|
+
const [lo, hi] =
|
|
523
|
+
T.PlainDate.compare(start, end) <= 0 ? [start, end] : [end, start];
|
|
471
524
|
const effectiveEnd = isRange ? hi : lo;
|
|
472
525
|
const newDates = isRange ? [lo, effectiveEnd] : [lo];
|
|
473
526
|
|
|
@@ -478,21 +531,29 @@ export function computeSetRangeUpdate<F extends ValueFormat>(opts: {
|
|
|
478
531
|
const prevRange = currentRangeFormatted();
|
|
479
532
|
(
|
|
480
533
|
onValueChange as
|
|
481
|
-
| ((
|
|
534
|
+
| ((
|
|
535
|
+
v: DateRange<F> | null,
|
|
536
|
+
m: { date: undefined; previous: DateRange<F> | null },
|
|
537
|
+
) => void)
|
|
482
538
|
| undefined
|
|
483
|
-
)?.(
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
539
|
+
)?.(
|
|
540
|
+
mkRange<F>(plainToFormatValue(lo), plainToFormatValue(effectiveEnd)),
|
|
541
|
+
{
|
|
542
|
+
date: undefined,
|
|
543
|
+
previous: prevRange,
|
|
544
|
+
},
|
|
545
|
+
);
|
|
487
546
|
} else {
|
|
488
547
|
const prevSingle = currentSingleFormatted();
|
|
489
|
-
const zdt = lo
|
|
548
|
+
const zdt = lo
|
|
549
|
+
.toPlainDateTime({ hour: 0, minute: 0, second: 0 })
|
|
550
|
+
.toZonedDateTime(timeZone);
|
|
490
551
|
const tagged = fromZonedDateTime(zdt, resolvedFormat, T);
|
|
491
552
|
(
|
|
492
553
|
onValueChange as
|
|
493
554
|
| ((
|
|
494
555
|
v: DateValueObject["value"],
|
|
495
|
-
m:
|
|
556
|
+
m: { date: undefined; previous: RawValueForFormat<F> | null },
|
|
496
557
|
) => void)
|
|
497
558
|
| undefined
|
|
498
559
|
)?.(tagged.value, { date: undefined, previous: prevSingle });
|
|
@@ -509,22 +570,33 @@ export function truncateDatesForMode<F extends ValueFormat>(opts: {
|
|
|
509
570
|
plainToFormatValue: (d: Temporal.PlainDate) => RawValueForFormat<F>;
|
|
510
571
|
onValueChange: unknown;
|
|
511
572
|
}): (Temporal.PlainDate | null)[] {
|
|
512
|
-
const {
|
|
573
|
+
const {
|
|
574
|
+
prev,
|
|
575
|
+
maxDatesForMode,
|
|
576
|
+
selectionMode,
|
|
577
|
+
plainToFormatValue,
|
|
578
|
+
onValueChange,
|
|
579
|
+
} = opts;
|
|
513
580
|
|
|
514
581
|
const clamped = prev.slice(0, maxDatesForMode);
|
|
515
582
|
if (clamped.length === prev.length) return prev;
|
|
516
583
|
|
|
517
584
|
const noDate = { date: undefined };
|
|
518
|
-
const fmt = (d: Temporal.PlainDate | null
|
|
585
|
+
const fmt = (d: Temporal.PlainDate | null | undefined) =>
|
|
586
|
+
d != null ? plainToFormatValue(d) : null;
|
|
519
587
|
|
|
520
588
|
if (selectionMode === "single") {
|
|
521
|
-
const prevVal =
|
|
522
|
-
|
|
589
|
+
const prevVal =
|
|
590
|
+
prev.length > 0 && prev[0] != null ? plainToFormatValue(prev[0]) : null;
|
|
591
|
+
const newVal =
|
|
592
|
+
clamped.length > 0 && clamped[0] != null
|
|
593
|
+
? plainToFormatValue(clamped[0])
|
|
594
|
+
: null;
|
|
523
595
|
(
|
|
524
596
|
onValueChange as
|
|
525
597
|
| ((
|
|
526
598
|
v: RawValueForFormat<F> | null,
|
|
527
|
-
m:
|
|
599
|
+
m: { date: undefined; previous: RawValueForFormat<F> | null },
|
|
528
600
|
) => void)
|
|
529
601
|
| undefined
|
|
530
602
|
)?.(newVal, { ...noDate, previous: prevVal });
|
|
@@ -540,16 +612,24 @@ export function truncateDatesForMode<F extends ValueFormat>(opts: {
|
|
|
540
612
|
}
|
|
541
613
|
(
|
|
542
614
|
onValueChange as
|
|
543
|
-
| ((
|
|
615
|
+
| ((
|
|
616
|
+
v: DateRange<F> | null,
|
|
617
|
+
m: { date: undefined; previous: DateRange<F> | null },
|
|
618
|
+
) => void)
|
|
544
619
|
| undefined
|
|
545
620
|
)?.(newRange, { ...noDate, previous: prevRange });
|
|
546
621
|
} else {
|
|
547
622
|
const nonNull = prev.filter((d): d is Temporal.PlainDate => d != null);
|
|
548
623
|
const prevArr = nonNull.map(plainToFormatValue);
|
|
549
|
-
const clampedNonNull = clamped.filter(
|
|
624
|
+
const clampedNonNull = clamped.filter(
|
|
625
|
+
(d): d is Temporal.PlainDate => d != null,
|
|
626
|
+
);
|
|
550
627
|
(
|
|
551
628
|
onValueChange as
|
|
552
|
-
| ((
|
|
629
|
+
| ((
|
|
630
|
+
v: RawValueForFormat<F>[],
|
|
631
|
+
m: { date: undefined; previous: RawValueForFormat<F>[] },
|
|
632
|
+
) => void)
|
|
553
633
|
| undefined
|
|
554
634
|
)?.(clampedNonNull.map(plainToFormatValue), {
|
|
555
635
|
...noDate,
|
|
@@ -579,17 +659,21 @@ export function computePreviewRange(
|
|
|
579
659
|
}
|
|
580
660
|
|
|
581
661
|
const rawStart =
|
|
582
|
-
currentRange?.start != null
|
|
662
|
+
currentRange?.start != null
|
|
663
|
+
? Temporal.PlainDate.from(currentRange.start as any)
|
|
664
|
+
: null;
|
|
583
665
|
const rawEnd =
|
|
584
|
-
currentRange?.end != null
|
|
666
|
+
currentRange?.end != null
|
|
667
|
+
? Temporal.PlainDate.from(currentRange.end as any)
|
|
668
|
+
: null;
|
|
585
669
|
// Normalize {start: null, end} → [end, null] (pending start)
|
|
586
|
-
const committedDates
|
|
670
|
+
const committedDates = currentRange
|
|
587
671
|
? rawStart === null && rawEnd !== null
|
|
588
|
-
? [rawEnd, null]
|
|
589
|
-
: [rawStart, rawEnd]
|
|
590
|
-
: [];
|
|
591
|
-
const committedStart =
|
|
592
|
-
const committedEnd =
|
|
672
|
+
? ([rawEnd, null] as const)
|
|
673
|
+
: ([rawStart, rawEnd] as const)
|
|
674
|
+
: ([] as const);
|
|
675
|
+
const committedStart = committedDates[0] ?? undefined;
|
|
676
|
+
const committedEnd = committedDates[1] ?? undefined;
|
|
593
677
|
|
|
594
678
|
const noop = () => [] as any;
|
|
595
679
|
const result = computeSelectionUpdate<"PlainDate">({
|