@klinking/colander 0.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 (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. package/src/weeks-view.tsx +127 -0
package/src/index.ts ADDED
@@ -0,0 +1,116 @@
1
+ export { CalendarProvider } from "./calendar-provider";
2
+ export { MonthView, MonthViewRoot } from "./month-view";
3
+ export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton } from "./grid";
4
+ export { GridHeader, GridHeaderCell } from "./grid-header";
5
+ export {
6
+ DateString,
7
+ TimeString,
8
+ MonthYearString,
9
+ PrevMonthButton,
10
+ NextMonthButton,
11
+ } from "./navigation";
12
+ export { RangeSelected } from "./selected-range";
13
+ export { RangePreview } from "./range-preview";
14
+ export { RangeStartDragHandle, RangeEndDragHandle } from "./drag-handle";
15
+ export { WeekNumberCell, WeekNumberHeader } from "./week-number";
16
+ export { WeeksView, WeeksViewRoot } from "./weeks-view";
17
+ export { PrevWeeksButton, NextWeeksButton, WeekCount } from "./weeks-navigation";
18
+ export {
19
+ MonthSeparator,
20
+ MonthSeparatorRow,
21
+ MonthSeparatorCell,
22
+ MonthSeparatorMonth,
23
+ MonthSeparatorYear,
24
+ MonthSeparatorWeekCount,
25
+ } from "./month-separator";
26
+ export { computePreviewRange } from "./root-selection";
27
+ export { computeWeeksInWindow } from "./compute-weeks-in-window";
28
+ export { resolveFirstWeek, resolveFirstWeekSpec } from "./resolve-first-week";
29
+ export { Temporal } from "./temporal-polyfill";
30
+ export { useCalendarStable, useCalendarState } from "./calendar-context";
31
+ export { useMonthViewStable, useMonthViewState } from "./month-view-context";
32
+ export { useViewContext } from "./view-context";
33
+ export { DayCellDataContext, WeekDataContext, GridContext } from "./context";
34
+
35
+ export type {
36
+ RootState,
37
+ GridProps,
38
+ GridState,
39
+ GridHeaderProps,
40
+ GridHeaderState,
41
+ GridHeaderCellProps,
42
+ GridHeaderCellState,
43
+ GridBodyProps,
44
+ GridBodyState,
45
+ WeekTemplateProps,
46
+ WeekTemplateState,
47
+ DayCellTemplateProps,
48
+ DayCellTemplateState,
49
+ DayButtonProps,
50
+ DayButtonState,
51
+ RangeSelectedProps,
52
+ RangeSelectedState,
53
+ RangePreviewProps,
54
+ RangePreviewState,
55
+ DragHandleOwnProps,
56
+ DragHandleState,
57
+ RangeStartDragHandleProps,
58
+ RangeEndDragHandleProps,
59
+ DateStringProps,
60
+ DateStringState,
61
+ TimeStringProps,
62
+ TimeStringState,
63
+ MonthYearStringProps,
64
+ MonthYearStringState,
65
+ PrevMonthButtonProps,
66
+ NextMonthButtonProps,
67
+ NavButtonState,
68
+ ValueFormat,
69
+ DateRange,
70
+ DateValueObject,
71
+ ValueForFormat,
72
+ RawValueForFormat,
73
+ PlainDateObject,
74
+ TemporalNamespace,
75
+ WeekStartDay,
76
+ RangeMode,
77
+ OutsideDays,
78
+ ValueChangeMeta,
79
+ WeekNumberCellProps,
80
+ WeekNumberCellState,
81
+ WeekNumberHeaderProps,
82
+ WeekNumberHeaderState,
83
+ MonthData,
84
+ } from "./types";
85
+
86
+ export type { CalendarProviderProps } from "./calendar-types";
87
+ export type { CalendarStableContextValue, CalendarStateContextValue } from "./calendar-types";
88
+ export type {
89
+ MonthViewRootProps,
90
+ MonthViewStableContextValue,
91
+ MonthViewStateContextValue,
92
+ } from "./month-view-types";
93
+ export type { MonthViewProps } from "./month-view";
94
+ export type { ViewContextValue } from "./view-context";
95
+ export type {
96
+ WeeksViewRootProps,
97
+ WeeksViewStableContextValue,
98
+ WeeksViewStateContextValue,
99
+ WindowInfo,
100
+ VisibleMonth,
101
+ } from "./weeks-view-types";
102
+ export type { WeeksViewProps, WeeksViewRootHandle } from "./weeks-view";
103
+ export type {
104
+ WeeksNavButtonState,
105
+ WeeksNavButtonOwnProps,
106
+ PrevWeeksButtonProps,
107
+ NextWeeksButtonProps,
108
+ WeekCountState,
109
+ WeekCountProps,
110
+ } from "./weeks-navigation";
111
+ export { useWeeksViewStable, useWeeksViewState } from "./weeks-view-context";
112
+
113
+ export type { WeekDescriptor } from "./compute-weeks-in-window";
114
+ export type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
115
+ export type { OverflowBehavior, MonthOverflowBehavior } from "./overflow";
116
+ export type { MonthSeparatorState } from "./month-separator";
@@ -0,0 +1,498 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { computeNextFocusDate, computeMonthJumpTarget } from "./keyboard";
3
+ import type { KeyboardNavInput } from "./keyboard";
4
+ import { temporalVariants } from "./test-temporal";
5
+
6
+ describe.each(temporalVariants)("computeNextFocusDate ($name)", ({ T }) => {
7
+ const d = (iso: string) => T.PlainDate.from(iso);
8
+
9
+ function nav(overrides: Partial<KeyboardNavInput> & { key: string }): KeyboardNavInput {
10
+ return {
11
+ shiftKey: false,
12
+ focusedDate: d("2026-03-15"),
13
+ minValue: undefined,
14
+ maxValue: undefined,
15
+ disabled: false,
16
+ T,
17
+ ...overrides,
18
+ };
19
+ }
20
+
21
+ function expectMove(input: KeyboardNavInput, expected: string) {
22
+ const result = computeNextFocusDate(input);
23
+ expect(result.action).toBe("move");
24
+ if (result.action === "move") {
25
+ expect(result.date.toString()).toBe(expected);
26
+ }
27
+ }
28
+
29
+ function expectNone(input: KeyboardNavInput) {
30
+ expect(computeNextFocusDate(input).action).toBe("none");
31
+ }
32
+
33
+ describe("computeNextFocusDate", () => {
34
+ describe("arrow keys", () => {
35
+ it.each([
36
+ ["ArrowRight", "2026-03-15", "2026-03-16"],
37
+ ["ArrowLeft", "2026-03-15", "2026-03-14"],
38
+ ["ArrowDown", "2026-03-15", "2026-03-22"],
39
+ ["ArrowUp", "2026-03-15", "2026-03-08"],
40
+ ["ArrowRight", "2026-03-31", "2026-04-01"],
41
+ ["ArrowLeft", "2026-04-01", "2026-03-31"],
42
+ ["ArrowDown", "2026-03-29", "2026-04-05"],
43
+ ["ArrowUp", "2026-04-05", "2026-03-29"],
44
+ ["ArrowRight", "2026-12-31", "2027-01-01"],
45
+ ["ArrowLeft", "2027-01-01", "2026-12-31"],
46
+ ] as const)("%s from %s → %s", (key, focused, expected) => {
47
+ expectMove(nav({ key, focusedDate: d(focused) }), expected);
48
+ });
49
+ });
50
+
51
+ describe("Home — move to Sunday of current week", () => {
52
+ it.each([
53
+ ["2026-03-16", "2026-03-15"],
54
+ ["2026-03-17", "2026-03-15"],
55
+ ["2026-03-18", "2026-03-15"],
56
+ ["2026-03-19", "2026-03-15"],
57
+ ["2026-03-20", "2026-03-15"],
58
+ ["2026-03-21", "2026-03-15"],
59
+ ["2026-04-01", "2026-03-29"],
60
+ ] as const)("from %s → %s", (focused, expected) => {
61
+ expectMove(nav({ key: "Home", focusedDate: d(focused) }), expected);
62
+ });
63
+
64
+ it.each(["2026-03-15", "2026-03-22"] as const)(
65
+ "from %s (already Sunday) → none",
66
+ (focused) => {
67
+ expectNone(nav({ key: "Home", focusedDate: d(focused) }));
68
+ },
69
+ );
70
+ });
71
+
72
+ describe("End — move to Saturday of current week", () => {
73
+ it.each([
74
+ ["2026-03-15", "2026-03-21"],
75
+ ["2026-03-16", "2026-03-21"],
76
+ ["2026-03-22", "2026-03-28"],
77
+ ["2026-03-29", "2026-04-04"],
78
+ ] as const)("from %s → %s", (focused, expected) => {
79
+ expectMove(nav({ key: "End", focusedDate: d(focused) }), expected);
80
+ });
81
+
82
+ it("from 2026-03-21 (already Saturday) → none", () => {
83
+ expectNone(nav({ key: "End", focusedDate: d("2026-03-21") }));
84
+ });
85
+ });
86
+
87
+ describe("PageDown — next month", () => {
88
+ it.each([
89
+ ["2026-03-15", "2026-04-15"],
90
+ ["2026-01-31", "2026-02-28"],
91
+ ["2024-01-31", "2024-02-29"],
92
+ ["2026-12-15", "2027-01-15"],
93
+ ["2026-03-31", "2026-04-30"],
94
+ ["2026-05-31", "2026-06-30"],
95
+ ] as const)("from %s → %s (day constrained)", (focused, expected) => {
96
+ expectMove(nav({ key: "PageDown", focusedDate: d(focused) }), expected);
97
+ });
98
+ });
99
+
100
+ describe("PageUp — previous month", () => {
101
+ it.each([
102
+ ["2026-03-15", "2026-02-15"],
103
+ ["2026-03-31", "2026-02-28"],
104
+ ["2024-03-31", "2024-02-29"],
105
+ ["2026-01-15", "2025-12-15"],
106
+ ["2026-05-31", "2026-04-30"],
107
+ ] as const)("from %s → %s (day constrained)", (focused, expected) => {
108
+ expectMove(nav({ key: "PageUp", focusedDate: d(focused) }), expected);
109
+ });
110
+ });
111
+
112
+ describe("Shift+PageDown — next year", () => {
113
+ it.each([
114
+ ["2026-03-15", "2027-03-15"],
115
+ ["2024-02-29", "2025-02-28"],
116
+ ["2026-12-31", "2027-12-31"],
117
+ ] as const)("from %s → %s (day constrained for leap year)", (focused, expected) => {
118
+ expectMove(nav({ key: "PageDown", shiftKey: true, focusedDate: d(focused) }), expected);
119
+ });
120
+ });
121
+
122
+ describe("Shift+PageUp — previous year", () => {
123
+ it.each([
124
+ ["2026-03-15", "2025-03-15"],
125
+ ["2024-02-29", "2023-02-28"],
126
+ ["2027-01-01", "2026-01-01"],
127
+ ] as const)("from %s → %s (day constrained for leap year)", (focused, expected) => {
128
+ expectMove(nav({ key: "PageUp", shiftKey: true, focusedDate: d(focused) }), expected);
129
+ });
130
+ });
131
+
132
+ describe("Enter and Space — select", () => {
133
+ it.each(["Enter", " "] as const)("%s selects focused date", (key) => {
134
+ const result = computeNextFocusDate(nav({ key }));
135
+ expect(result.action).toBe("select");
136
+ });
137
+
138
+ it.each(["Enter", " "] as const)(
139
+ "%s does not select when isDateDisabled returns true",
140
+ (key) => {
141
+ expectNone(nav({ key, isDateDisabled: () => true }));
142
+ },
143
+ );
144
+ });
145
+
146
+ describe("disabled calendar ignores all keys", () => {
147
+ it.each([
148
+ "ArrowRight",
149
+ "ArrowLeft",
150
+ "ArrowUp",
151
+ "ArrowDown",
152
+ "Home",
153
+ "End",
154
+ "PageUp",
155
+ "PageDown",
156
+ "Enter",
157
+ " ",
158
+ ] as const)("%s returns none when disabled", (key) => {
159
+ expectNone(nav({ key, disabled: true }));
160
+ });
161
+ });
162
+
163
+ describe("unrecognized keys return none", () => {
164
+ it.each(["Tab", "Escape", "a", "Delete", "F1"] as const)("%s returns none", (key) => {
165
+ expectNone(nav({ key }));
166
+ });
167
+ });
168
+
169
+ describe("min bound clamping", () => {
170
+ const min = d("2026-03-10");
171
+
172
+ it.each([
173
+ ["ArrowLeft", "2026-03-10"],
174
+ ["ArrowUp", "2026-03-10"],
175
+ ["Home", "2026-03-10"],
176
+ ] as const)("%s from %s is none (already at min boundary)", (key, focused) => {
177
+ expectNone(nav({ key, focusedDate: d(focused), minValue: min }));
178
+ });
179
+
180
+ it.each([
181
+ ["ArrowLeft", "2026-03-11", "2026-03-10"],
182
+ ["ArrowRight", "2026-03-10", "2026-03-11"],
183
+ ] as const)("%s from %s → %s (at or above min)", (key, focused, expected) => {
184
+ expectMove(nav({ key, focusedDate: d(focused), minValue: min }), expected);
185
+ });
186
+
187
+ it("ArrowUp clamps to min when target is below min", () => {
188
+ expectMove(
189
+ nav({ key: "ArrowUp", focusedDate: d("2026-03-12"), minValue: min }),
190
+ "2026-03-10",
191
+ );
192
+ });
193
+
194
+ it("Home clamps to min when start-of-week is below min", () => {
195
+ expectMove(nav({ key: "Home", focusedDate: d("2026-03-12"), minValue: min }), "2026-03-10");
196
+ });
197
+
198
+ it("PageUp clamps to min when target month is before min", () => {
199
+ expectMove(
200
+ nav({
201
+ key: "PageUp",
202
+ focusedDate: d("2026-03-05"),
203
+ minValue: d("2026-03-01"),
204
+ }),
205
+ "2026-03-01",
206
+ );
207
+ });
208
+
209
+ it("Shift+PageUp clamps to min when target year is before min", () => {
210
+ expectMove(
211
+ nav({
212
+ key: "PageUp",
213
+ shiftKey: true,
214
+ focusedDate: d("2026-03-15"),
215
+ minValue: d("2026-01-01"),
216
+ }),
217
+ "2026-01-01",
218
+ );
219
+ });
220
+
221
+ it("PageUp is none when already at min", () => {
222
+ expectNone(
223
+ nav({
224
+ key: "PageUp",
225
+ focusedDate: d("2026-03-01"),
226
+ minValue: d("2026-03-01"),
227
+ }),
228
+ );
229
+ });
230
+ });
231
+
232
+ describe("max bound clamping", () => {
233
+ const max = d("2026-03-20");
234
+
235
+ it.each([
236
+ ["ArrowRight", "2026-03-20"],
237
+ ["ArrowDown", "2026-03-20"],
238
+ ["End", "2026-03-20"],
239
+ ] as const)("%s from %s is none (already at max boundary)", (key, focused) => {
240
+ expectNone(nav({ key, focusedDate: d(focused), maxValue: max }));
241
+ });
242
+
243
+ it.each([
244
+ ["ArrowRight", "2026-03-19", "2026-03-20"],
245
+ ["ArrowLeft", "2026-03-20", "2026-03-19"],
246
+ ] as const)("%s from %s → %s (at or below max)", (key, focused, expected) => {
247
+ expectMove(nav({ key, focusedDate: d(focused), maxValue: max }), expected);
248
+ });
249
+
250
+ it("ArrowDown clamps to max when target exceeds max", () => {
251
+ expectMove(
252
+ nav({
253
+ key: "ArrowDown",
254
+ focusedDate: d("2026-03-18"),
255
+ maxValue: max,
256
+ }),
257
+ "2026-03-20",
258
+ );
259
+ });
260
+
261
+ it("End clamps to max when end-of-week exceeds max", () => {
262
+ expectMove(nav({ key: "End", focusedDate: d("2026-03-16"), maxValue: max }), "2026-03-20");
263
+ });
264
+
265
+ it("PageDown clamps to max when target month exceeds max", () => {
266
+ expectMove(
267
+ nav({
268
+ key: "PageDown",
269
+ focusedDate: d("2026-03-15"),
270
+ maxValue: d("2026-03-31"),
271
+ }),
272
+ "2026-03-31",
273
+ );
274
+ });
275
+
276
+ it("Shift+PageDown clamps to max when target year exceeds max", () => {
277
+ expectMove(
278
+ nav({
279
+ key: "PageDown",
280
+ shiftKey: true,
281
+ focusedDate: d("2026-03-15"),
282
+ maxValue: d("2026-12-31"),
283
+ }),
284
+ "2026-12-31",
285
+ );
286
+ });
287
+
288
+ it("PageDown is none when already at max", () => {
289
+ expectNone(
290
+ nav({
291
+ key: "PageDown",
292
+ focusedDate: d("2026-03-31"),
293
+ maxValue: d("2026-03-31"),
294
+ }),
295
+ );
296
+ });
297
+ });
298
+
299
+ describe("min and max together — narrow window", () => {
300
+ const min = d("2026-03-14");
301
+ const max = d("2026-03-16");
302
+
303
+ it("ArrowRight from 2026-03-15 → 2026-03-16 (within window)", () => {
304
+ expectMove(
305
+ nav({
306
+ key: "ArrowRight",
307
+ focusedDate: d("2026-03-15"),
308
+ minValue: min,
309
+ maxValue: max,
310
+ }),
311
+ "2026-03-16",
312
+ );
313
+ });
314
+
315
+ it("ArrowLeft from 2026-03-15 → 2026-03-14 (within window)", () => {
316
+ expectMove(
317
+ nav({
318
+ key: "ArrowLeft",
319
+ focusedDate: d("2026-03-15"),
320
+ minValue: min,
321
+ maxValue: max,
322
+ }),
323
+ "2026-03-14",
324
+ );
325
+ });
326
+
327
+ it("ArrowRight from max boundary is none", () => {
328
+ expectNone(
329
+ nav({
330
+ key: "ArrowRight",
331
+ focusedDate: max,
332
+ minValue: min,
333
+ maxValue: max,
334
+ }),
335
+ );
336
+ });
337
+
338
+ it("ArrowLeft from min boundary is none", () => {
339
+ expectNone(
340
+ nav({
341
+ key: "ArrowLeft",
342
+ focusedDate: min,
343
+ minValue: min,
344
+ maxValue: max,
345
+ }),
346
+ );
347
+ });
348
+
349
+ it("PageDown clamps to max in narrow window", () => {
350
+ expectMove(
351
+ nav({
352
+ key: "PageDown",
353
+ focusedDate: d("2026-03-15"),
354
+ minValue: min,
355
+ maxValue: max,
356
+ }),
357
+ "2026-03-16",
358
+ );
359
+ });
360
+
361
+ it("PageUp clamps to min in narrow window", () => {
362
+ expectMove(
363
+ nav({
364
+ key: "PageUp",
365
+ focusedDate: d("2026-03-15"),
366
+ minValue: min,
367
+ maxValue: max,
368
+ }),
369
+ "2026-03-14",
370
+ );
371
+ });
372
+
373
+ it("ArrowDown from 2026-03-15 clamps to max", () => {
374
+ expectMove(
375
+ nav({
376
+ key: "ArrowDown",
377
+ focusedDate: d("2026-03-15"),
378
+ minValue: min,
379
+ maxValue: max,
380
+ }),
381
+ "2026-03-16",
382
+ );
383
+ });
384
+
385
+ it("ArrowUp from 2026-03-15 clamps to min", () => {
386
+ expectMove(
387
+ nav({
388
+ key: "ArrowUp",
389
+ focusedDate: d("2026-03-15"),
390
+ minValue: min,
391
+ maxValue: max,
392
+ }),
393
+ "2026-03-14",
394
+ );
395
+ });
396
+ });
397
+
398
+ describe("readOnly suppresses select but allows move", () => {
399
+ it.each(["Enter", " "] as const)("%s returns none when readOnly", (key) => {
400
+ expectNone(nav({ key, readOnly: true }));
401
+ });
402
+
403
+ it.each(["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown", "PageUp", "PageDown"] as const)(
404
+ "%s still works when readOnly",
405
+ (key) => {
406
+ const result = computeNextFocusDate(nav({ key, readOnly: true }));
407
+ expect(result.action).toBe("move");
408
+ },
409
+ );
410
+
411
+ it("Home still works when readOnly (from mid-week)", () => {
412
+ const result = computeNextFocusDate(
413
+ nav({ key: "Home", readOnly: true, focusedDate: d("2026-03-18") }),
414
+ );
415
+ expect(result.action).toBe("move");
416
+ });
417
+
418
+ it("End still works when readOnly (from mid-week)", () => {
419
+ const result = computeNextFocusDate(
420
+ nav({ key: "End", readOnly: true, focusedDate: d("2026-03-18") }),
421
+ );
422
+ expect(result.action).toBe("move");
423
+ });
424
+ });
425
+
426
+ describe("Home/End with weekStartDay=1 (Monday start)", () => {
427
+ it.each([
428
+ ["2026-03-17", "2026-03-16"],
429
+ ["2026-03-18", "2026-03-16"],
430
+ ["2026-03-21", "2026-03-16"],
431
+ ["2026-03-22", "2026-03-16"],
432
+ ] as const)("Home from %s → %s (Monday start of week)", (focused, expected) => {
433
+ expectMove(nav({ key: "Home", focusedDate: d(focused), weekStartDay: 1 }), expected);
434
+ });
435
+
436
+ it("Home from Monday (already at start) → none", () => {
437
+ expectNone(nav({ key: "Home", focusedDate: d("2026-03-16"), weekStartDay: 1 }));
438
+ });
439
+
440
+ it.each([
441
+ ["2026-03-16", "2026-03-22"],
442
+ ["2026-03-17", "2026-03-22"],
443
+ ["2026-03-21", "2026-03-22"],
444
+ ] as const)("End from %s → %s (Sunday end of week)", (focused, expected) => {
445
+ expectMove(nav({ key: "End", focusedDate: d(focused), weekStartDay: 1 }), expected);
446
+ });
447
+
448
+ it("End from Sunday (already at end) → none", () => {
449
+ expectNone(nav({ key: "End", focusedDate: d("2026-03-22"), weekStartDay: 1 }));
450
+ });
451
+ });
452
+
453
+ describe("Home/End with weekStartDay=6 (Saturday start)", () => {
454
+ it("Home from Sunday (2026-03-15) → Saturday (2026-03-14)", () => {
455
+ expectMove(
456
+ nav({ key: "Home", focusedDate: d("2026-03-15"), weekStartDay: 6 }),
457
+ "2026-03-14",
458
+ );
459
+ });
460
+
461
+ it("Home from Saturday (already at start) → none", () => {
462
+ expectNone(nav({ key: "Home", focusedDate: d("2026-03-14"), weekStartDay: 6 }));
463
+ });
464
+
465
+ it("End from Saturday (2026-03-14) → Friday (2026-03-20)", () => {
466
+ expectMove(
467
+ nav({ key: "End", focusedDate: d("2026-03-14"), weekStartDay: 6 }),
468
+ "2026-03-20",
469
+ );
470
+ });
471
+
472
+ it("End from Friday (already at end) → none", () => {
473
+ expectNone(nav({ key: "End", focusedDate: d("2026-03-20"), weekStartDay: 6 }));
474
+ });
475
+ });
476
+
477
+ describe("computeMonthJumpTarget", () => {
478
+ it.each([
479
+ ["2026-03-15", 1, "2026-04-15"],
480
+ ["2026-03-15", -1, "2026-02-15"],
481
+ ["2026-03-31", 1, "2026-04-30"],
482
+ ["2026-01-31", 1, "2026-02-28"],
483
+ ["2024-01-31", 1, "2024-02-29"],
484
+ ["2026-12-15", 1, "2027-01-15"],
485
+ ["2026-01-15", -1, "2025-12-15"],
486
+ ["2026-03-15", 12, "2027-03-15"],
487
+ ["2026-03-15", -12, "2025-03-15"],
488
+ ["2024-02-29", 12, "2025-02-28"],
489
+ ["2024-02-29", -12, "2023-02-28"],
490
+ ["2026-03-15", 24, "2028-03-15"],
491
+ ["2026-03-15", -24, "2024-03-15"],
492
+ ] as const)("from %s + %d months → %s", (focused, months, expected) => {
493
+ const result = computeMonthJumpTarget(d(focused), months, T);
494
+ expect(result.toString()).toBe(expected);
495
+ });
496
+ });
497
+ });
498
+ });