@klinking/colander 0.0.0 → 2.0.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.
Files changed (92) hide show
  1. package/dist/formats/date.cjs +51 -48
  2. package/dist/formats/date.d.cts +10 -37
  3. package/dist/formats/date.d.mts +10 -37
  4. package/dist/formats/date.mjs +6 -2
  5. package/dist/formats/object.cjs +51 -48
  6. package/dist/formats/object.d.cts +10 -37
  7. package/dist/formats/object.d.mts +10 -37
  8. package/dist/formats/object.mjs +6 -2
  9. package/dist/formats/plain-date-time.cjs +51 -48
  10. package/dist/formats/plain-date-time.d.cts +10 -37
  11. package/dist/formats/plain-date-time.d.mts +10 -37
  12. package/dist/formats/plain-date-time.mjs +6 -2
  13. package/dist/formats/plain-date.cjs +51 -48
  14. package/dist/formats/plain-date.d.cts +10 -37
  15. package/dist/formats/plain-date.d.mts +10 -37
  16. package/dist/formats/plain-date.mjs +6 -2
  17. package/dist/formats/plain-month-day.cjs +51 -48
  18. package/dist/formats/plain-month-day.d.cts +10 -37
  19. package/dist/formats/plain-month-day.d.mts +10 -37
  20. package/dist/formats/plain-month-day.mjs +6 -2
  21. package/dist/formats/plain-year-month.cjs +51 -48
  22. package/dist/formats/plain-year-month.d.cts +10 -37
  23. package/dist/formats/plain-year-month.d.mts +10 -37
  24. package/dist/formats/plain-year-month.mjs +6 -2
  25. package/dist/formats/zoned-date-time.cjs +51 -48
  26. package/dist/formats/zoned-date-time.d.cts +10 -37
  27. package/dist/formats/zoned-date-time.d.mts +10 -37
  28. package/dist/formats/zoned-date-time.mjs +6 -2
  29. package/dist/index.cjs +47 -48
  30. package/dist/index.d.cts +11 -2
  31. package/dist/index.d.mts +11 -2
  32. package/dist/index.mjs +2 -2
  33. package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-CtbaTTmA.cjs} +329 -567
  34. package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-D5GjCwNm.mjs} +329 -561
  35. package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
  36. package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
  37. package/package.json +20 -20
  38. package/src/calendar-context.ts +12 -5
  39. package/src/calendar-provider.test.tsx +18 -4
  40. package/src/calendar-provider.tsx +130 -35
  41. package/src/calendar-types.ts +21 -4
  42. package/src/compute-weeks-in-window.test.ts +9 -7
  43. package/src/context.ts +1 -1
  44. package/src/day-cell.tsx +92 -46
  45. package/src/drag-handle.tsx +23 -24
  46. package/src/formats/date.ts +120 -56
  47. package/src/formats/formats.test.ts +8 -4
  48. package/src/formats/object.ts +120 -56
  49. package/src/formats/plain-date-time.ts +120 -56
  50. package/src/formats/plain-date.ts +120 -56
  51. package/src/formats/plain-month-day.ts +120 -56
  52. package/src/formats/plain-year-month.ts +120 -56
  53. package/src/formats/zoned-date-time.ts +120 -56
  54. package/src/grid-header.tsx +24 -18
  55. package/src/grid.event-perf.test.tsx +30 -13
  56. package/src/grid.perf.test.tsx +97 -33
  57. package/src/grid.tsx +75 -43
  58. package/src/index.ts +16 -4
  59. package/src/keyboard.test.ts +110 -42
  60. package/src/keyboard.ts +18 -7
  61. package/src/month-separator.test.tsx +3 -1
  62. package/src/month-separator.tsx +30 -9
  63. package/src/month-view-context.ts +8 -3
  64. package/src/month-view-types.ts +14 -10
  65. package/src/month-view.test.tsx +687 -68
  66. package/src/month-view.tsx +176 -71
  67. package/src/navigation.tsx +77 -47
  68. package/src/overflow.test.ts +15 -13
  69. package/src/overflow.ts +10 -2
  70. package/src/range-preview.tsx +37 -12
  71. package/src/resolve-first-week.test.ts +14 -10
  72. package/src/resolve-first-week.ts +6 -2
  73. package/src/root-selection.ts +185 -101
  74. package/src/selected-range.tsx +47 -22
  75. package/src/test-temporal.ts +0 -2
  76. package/src/types.ts +126 -103
  77. package/src/utils.bench.ts +30 -6
  78. package/src/utils.test.ts +203 -55
  79. package/src/utils.ts +156 -54
  80. package/src/view-context.ts +4 -1
  81. package/src/week-number.tsx +5 -8
  82. package/src/weeks-grid.tsx +45 -19
  83. package/src/weeks-keyboard.test.ts +6 -7
  84. package/src/weeks-keyboard.ts +8 -3
  85. package/src/weeks-navigation.tsx +21 -9
  86. package/src/weeks-view-context.ts +8 -3
  87. package/src/weeks-view-state.ts +100 -33
  88. package/src/weeks-view-types.ts +14 -8
  89. package/src/weeks-view.test.tsx +127 -19
  90. package/src/weeks-view.tsx +30 -12
  91. package/src/temporal-polyfill.test.ts +0 -317
  92. package/src/temporal-polyfill.ts +0 -566
@@ -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 { computeClippedRangeInfo, rangeOverlayStateAttributesMapping } from "./selected-range";
9
- import type { ValueFormat, RangePreviewState, RangePreviewProps } from "./types";
8
+ import {
9
+ computeClippedRangeInfo,
10
+ rangeOverlayStateAttributesMapping,
11
+ } from "./selected-range";
12
+ import type { RangePreviewState, RangePreviewProps } from "./types";
10
13
 
11
- function RangePreviewFn(props: RangePreviewProps, ref: React.ForwardedRef<HTMLTableCellElement>) {
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 <F extends ValueFormat = ValueFormat>(
26
- props: RangePreviewProps<F> & React.RefAttributes<HTMLTableCellElement>,
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
- () => computeClippedRangeInfo(days, previewStart, previewEnd, T, outsideDays, gridMonth),
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 ? days[info.startIndex].toString() : "";
51
- const endDate = info.active ? days[info.endIndex].toString() : "";
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 as any,
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
- [rootState, info, weekIndex, startDate, endDate, previewStart, previewEnd, orientation],
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 <F extends ValueFormat = ValueFormat>(
89
- props: RangePreviewProps<F> & React.RefAttributes<HTMLTableCellElement>,
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: "month+year spec — first week containing a day in that month",
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
- ])("$description", ({ currentFirstWeek, weekCount, target, snap, expected }) => {
124
- const result = resolveFirstWeek(
125
- currentFirstWeek,
126
- weekCount,
127
- target,
128
- snap ? { snap } : undefined,
129
- );
130
- expect(result.toString()).toBe(expected);
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(date: Temporal.PlainDate, weekStartDay: WeekStartDay): Temporal.PlainDate {
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) => Number(parts.find((p) => p.type === type)?.value ?? 0);
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"),
@@ -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> = UseRootStateParamsBase<F> &
33
- (
34
- | {
35
- selectionMode: "single";
36
- value?: RawValueForFormat<F> | null;
37
- defaultValue?: RawValueForFormat<F>;
38
- onValueChange?: (
39
- value: RawValueForFormat<F> | null,
40
- meta: ValueChangeMeta<RawValueForFormat<F> | null>,
41
- ) => void;
42
- }
43
- | {
44
- selectionMode: "range";
45
- value?: DateRange<F> | null;
46
- defaultValue?: DateRange<F>;
47
- onValueChange?: (
48
- value: DateRange<F> | null,
49
- meta: ValueChangeMeta<DateRange<F> | null>,
50
- ) => void;
51
- rangeMode?: RangeMode;
52
- preventRangeReversal?: boolean;
53
- previewRange?: DateRange<F> | null;
54
- onHoveredDateChange?: (date: Temporal.PlainDate | undefined) => void;
55
- }
56
- | {
57
- selectionMode: "multiple";
58
- value?: RawValueForFormat<F>[] | null;
59
- defaultValue?: RawValueForFormat<F>[];
60
- onValueChange?: (
61
- value: RawValueForFormat<F>[],
62
- meta: ValueChangeMeta<RawValueForFormat<F>[]>,
63
- ) => void;
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>(start: unknown, end: unknown): DateRange<F> {
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((d): d is Temporal.PlainDate => d != null);
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
- | ((v: RawValueForFormat<F>[], m: ValueChangeMeta<RawValueForFormat<F>[]>) => void)
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 && (committedDates[0] === null || committedDates[1] === null);
203
+ committedDates.length === 2 &&
204
+ (committedDates[0] === null || committedDates[1] === null);
195
205
  const isComplete =
196
- committedDates.length === 2 && committedDates[0] != null && committedDates[1] != null;
206
+ committedDates.length === 2 &&
207
+ committedDates[0] != null &&
208
+ committedDates[1] != null;
197
209
 
198
210
  type RangeCb =
199
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
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)?.(mkRange<F>(plainToFormatValue(date), null), {
208
- date,
209
- previous: prevRange,
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)?.(mkRange<F>(plainToFormatValue(date), null), {
294
- date,
295
- previous: prevRange,
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
358
+ | ((
359
+ v: DateRange<F> | null,
360
+ m: ValueChangeMeta<DateRange<F> | null>,
361
+ ) => void)
335
362
  | undefined
336
- )?.(mkRange<F>(plainToFormatValue(date), plainToFormatValue(date)), {
337
- date,
338
- previous: prevRange,
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 newDates: (Temporal.PlainDate | null)[];
378
+ let newStart: Temporal.PlainDate;
379
+ let newEnd: Temporal.PlainDate;
349
380
  if (beforeStart) {
350
- newDates = [date, committedEnd];
381
+ newStart = date;
382
+ newEnd = committedEnd;
351
383
  } else if (afterEnd) {
352
- newDates = [committedStart, date];
384
+ newStart = committedStart;
385
+ newEnd = date;
353
386
  } else {
354
- const action = resolveInsideAction(rangeMode, date, committedStart, committedEnd);
387
+ const action = resolveInsideAction(
388
+ rangeMode,
389
+ date,
390
+ committedStart,
391
+ committedEnd,
392
+ );
355
393
  if (action === "start") {
356
- newDates = [date, committedEnd];
394
+ newStart = date;
395
+ newEnd = committedEnd;
357
396
  } else if (action === "end") {
358
- newDates = [committedStart, date];
397
+ newStart = committedStart;
398
+ newEnd = date;
359
399
  } else {
360
- newDates = [date, date];
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
410
+ | ((
411
+ v: DateRange<F> | null,
412
+ m: ValueChangeMeta<DateRange<F> | null>,
413
+ ) => void)
370
414
  | undefined
371
- )?.(mkRange<F>(plainToFormatValue(newDates[0]!), plainToFormatValue(newDates[1]!)), {
372
- date,
373
- previous: prevRange,
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
433
+ | ((
434
+ v: DateRange<F> | null,
435
+ m: ValueChangeMeta<DateRange<F> | null>,
436
+ ) => void)
388
437
  | undefined
389
- )?.(mkRange<F>(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
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
- | ((v: DateValueObject["value"], m: ValueChangeMeta<RawValueForFormat<F> | null>) => void)
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] = T.PlainDate.compare(start, end) <= 0 ? [start, end] : [end, start];
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
534
+ | ((
535
+ v: DateRange<F> | null,
536
+ m: { date: undefined; previous: DateRange<F> | null },
537
+ ) => void)
482
538
  | undefined
483
- )?.(mkRange<F>(plainToFormatValue(lo), plainToFormatValue(effectiveEnd)), {
484
- date: undefined,
485
- previous: prevRange,
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.toPlainDateTime({ hour: 0, minute: 0, second: 0 }).toZonedDateTime(timeZone);
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: ValueChangeMeta<RawValueForFormat<F> | null>,
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 { prev, maxDatesForMode, selectionMode, plainToFormatValue, onValueChange } = opts;
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) => (d != null ? plainToFormatValue(d) : 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 = prev.length > 0 && prev[0] != null ? plainToFormatValue(prev[0]) : null;
522
- const newVal = clamped.length > 0 && clamped[0] != null ? plainToFormatValue(clamped[0]) : null;
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: ValueChangeMeta<RawValueForFormat<F> | null>,
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
- | ((v: DateRange<F> | null, m: ValueChangeMeta<DateRange<F> | null>) => void)
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((d): d is Temporal.PlainDate => d != null);
624
+ const clampedNonNull = clamped.filter(
625
+ (d): d is Temporal.PlainDate => d != null,
626
+ );
550
627
  (
551
628
  onValueChange as
552
- | ((v: RawValueForFormat<F>[], m: ValueChangeMeta<RawValueForFormat<F>[]>) => void)
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 ? Temporal.PlainDate.from(currentRange.start as any) : null;
662
+ currentRange?.start != null
663
+ ? Temporal.PlainDate.from(currentRange.start as any)
664
+ : null;
583
665
  const rawEnd =
584
- currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end as any) : 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: (Temporal.PlainDate | null)[] = currentRange
670
+ const committedDates = currentRange
587
671
  ? rawStart === null && rawEnd !== null
588
- ? [rawEnd, null]
589
- : [rawStart, rawEnd]
590
- : [];
591
- const committedStart = (committedDates[0] ?? undefined) as Temporal.PlainDate | undefined;
592
- const committedEnd = (committedDates[1] ?? undefined) as Temporal.PlainDate | undefined;
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">({