@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
package/src/utils.ts CHANGED
@@ -1,30 +1,32 @@
1
1
  import type { Temporal } from "@js-temporal/polyfill";
2
- import type { TemporalNamespace, DateValueObject, ValueFormat, WeekStartDay } from "./types";
3
-
4
- /**
5
- * Returns the default calendar system for a given locale (e.g. `"gregory"` for `"en-US"`).
6
- *
7
- * @param locale - A BCP 47 locale string. Falls back to the runtime default when empty.
8
- */
9
- export function calendarForLocale(locale: string): string {
10
- return new Intl.DateTimeFormat(locale || undefined).resolvedOptions().calendar;
11
- }
2
+ import type {
3
+ TemporalNamespace,
4
+ DateValueObject,
5
+ ValueFormat,
6
+ WeekStartDay,
7
+ } from "./types";
12
8
 
13
9
  /**
14
10
  * Resolves a {@link TemporalNamespace} instance.
15
11
  *
16
- * Returns `provided` when given, otherwise checks `globalThis.Temporal`.
17
- * Throws if neither is available.
12
+ * Returns `provided` when given, otherwise native `globalThis.Temporal`. This
13
+ * library does not bundle a `Temporal` implementation — if neither is
14
+ * available, it throws. Provide one via the `temporal` prop, e.g. the
15
+ * `Temporal` export from `temporal-polyfill`
16
+ * (https://github.com/fullcalendar/temporal-polyfill) or `@js-temporal/polyfill`
17
+ * (https://github.com/js-temporal/temporal-polyfill).
18
18
  *
19
19
  * @param provided - An explicit Temporal polyfill or namespace.
20
20
  */
21
- export function resolveTemporal(provided?: TemporalNamespace): TemporalNamespace {
21
+ export function resolveTemporal(
22
+ provided?: TemporalNamespace,
23
+ ): TemporalNamespace {
22
24
  if (provided) return provided;
23
25
  if (typeof globalThis !== "undefined" && (globalThis as any).Temporal) {
24
26
  return (globalThis as any).Temporal;
25
27
  }
26
28
  throw new Error(
27
- "DatePicker: Temporal is not available. Pass a Temporal polyfill via the `temporal` prop, or use a browser that supports the Temporal API natively.",
29
+ "DatePicker: Temporal is not available. Pass a Temporal implementation via the `temporal` prop — e.g. `temporal-polyfill` or `@js-temporal/polyfill` — or run where the native Temporal API exists.",
28
30
  );
29
31
  }
30
32
 
@@ -65,7 +67,10 @@ export function toZonedDateTime(
65
67
  return pd.toZonedDateTime(timeZone);
66
68
  }
67
69
  case "PlainTime":
68
- return now.toPlainDate().toPlainDateTime(tagged.value).toZonedDateTime(timeZone);
70
+ return now
71
+ .toPlainDate()
72
+ .toPlainDateTime(tagged.value)
73
+ .toZonedDateTime(timeZone);
69
74
  case "PlainYearMonth":
70
75
  return tagged.value.toPlainDate({ day: 1 }).toZonedDateTime(timeZone);
71
76
  case "ZonedDateTime":
@@ -193,11 +198,13 @@ export function getMonthWeeks(
193
198
  const lastOfMonth = T.PlainDate.from({ year, month, day: daysInMonth });
194
199
 
195
200
  const adjustedFirst =
196
- ((firstOfMonth.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) % daysInWeek;
201
+ ((firstOfMonth.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
202
+ daysInWeek;
197
203
  const gridStart = firstOfMonth.subtract({ days: adjustedFirst });
198
204
 
199
205
  const adjustedLast =
200
- ((lastOfMonth.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) % daysInWeek;
206
+ ((lastOfMonth.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
207
+ daysInWeek;
201
208
  const daysAfter = daysInWeek - 1 - adjustedLast;
202
209
  const gridEnd = lastOfMonth.add({ days: daysAfter });
203
210
 
@@ -242,7 +249,10 @@ export function zdtToNativeDate(zdt: Temporal.ZonedDateTime): Date {
242
249
  * @param a - A zoned date-time.
243
250
  * @param b - A plain date.
244
251
  */
245
- export function sameCalendarDay(a: Temporal.ZonedDateTime, b: Temporal.PlainDate): boolean {
252
+ export function sameCalendarDay(
253
+ a: Temporal.ZonedDateTime,
254
+ b: Temporal.PlainDate,
255
+ ): boolean {
246
256
  return a.year === b.year && a.month === b.month && a.day === b.day;
247
257
  }
248
258
 
@@ -253,7 +263,10 @@ export function sameCalendarDay(a: Temporal.ZonedDateTime, b: Temporal.PlainDate
253
263
  * @param T - Temporal namespace.
254
264
  * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
255
265
  */
256
- export function getReferenceWeekStart(T: TemporalNamespace, weekStartDay = 0): Temporal.PlainDate {
266
+ export function getReferenceWeekStart(
267
+ T: TemporalNamespace,
268
+ weekStartDay = 0,
269
+ ): Temporal.PlainDate {
257
270
  const refSunday = T.PlainDate.from("2024-01-07");
258
271
  return refSunday.add({ days: weekStartDay });
259
272
  }
@@ -280,6 +293,48 @@ export function computeAdjacentMonth(
280
293
  return { year: d.year, month: d.month, firstDay: d };
281
294
  }
282
295
 
296
+ /**
297
+ * Computes the new first-visible month after the **minimum** shift needed to
298
+ * bring `focused` into a window of `numberOfMonths` months that currently
299
+ * starts at `start`.
300
+ *
301
+ * - Already visible → returns `start` unchanged (by value).
302
+ * - Before the window → `focused` becomes the first (leftmost) pane.
303
+ * - After the window → `focused` becomes the last (rightmost) pane.
304
+ *
305
+ * This keeps keyboard focus-crossing symmetric with single-month stepping: a
306
+ * Gregorian-style window only ever scrolls as far as it must, never jumping
307
+ * the focused month to the leftmost slot. Pure month arithmetic — calendar
308
+ * agnostic, since `{year, month}` indices are computed by the caller.
309
+ *
310
+ * @param start - The current first-visible month.
311
+ * @param focused - The month that must become visible.
312
+ * @param numberOfMonths - Number of month panes displayed (>= 1).
313
+ */
314
+ export function shiftWindowToMonth(
315
+ start: { year: number; month: number },
316
+ focused: { year: number; month: number },
317
+ numberOfMonths: number,
318
+ ): { year: number; month: number } {
319
+ const startIndex = start.year * 12 + (start.month - 1);
320
+ const focusedIndex = focused.year * 12 + (focused.month - 1);
321
+
322
+ // Before the window: focused becomes the first pane.
323
+ if (focusedIndex < startIndex) {
324
+ return { year: focused.year, month: focused.month };
325
+ }
326
+ // After the window: focused becomes the last pane.
327
+ if (focusedIndex > startIndex + numberOfMonths - 1) {
328
+ const newStartIndex = focusedIndex - (numberOfMonths - 1);
329
+ return {
330
+ year: Math.floor(newStartIndex / 12),
331
+ month: (newStartIndex % 12) + 1,
332
+ };
333
+ }
334
+ // Already visible.
335
+ return start;
336
+ }
337
+
283
338
  /**
284
339
  * Determines the focused date after navigating to a new month.
285
340
  *
@@ -295,7 +350,10 @@ export function focusedDateForMonth(
295
350
  targetMonth: { year: number; month: number },
296
351
  firstDay: Temporal.PlainDate,
297
352
  ): Temporal.PlainDate {
298
- if (currentFocused.year === targetMonth.year && currentFocused.month === targetMonth.month) {
353
+ if (
354
+ currentFocused.year === targetMonth.year &&
355
+ currentFocused.month === targetMonth.month
356
+ ) {
299
357
  return currentFocused;
300
358
  }
301
359
  return firstDay;
@@ -307,7 +365,8 @@ export function focusedDateForMonth(
307
365
  * Priority when `gridHasFocus` is `true` (keyboard navigation):
308
366
  * 1. `focusedDate` if it exists in the grid.
309
367
  * 2. `selectedDate` if it exists in the grid.
310
- * 3. First enabled day of `currentMonth`, or first grid day as last resort.
368
+ * 3. First enabled day of `currentMonth`, then first grid day, then
369
+ * `focusedDate` itself (empty grid) as last resorts.
311
370
  *
312
371
  * When `gridHasFocus` is `false` (tab-in), `selectedDate` takes priority
313
372
  * over `focusedDate`.
@@ -330,7 +389,8 @@ export function resolveFocusTarget(
330
389
  gridHasFocus = true,
331
390
  ): Temporal.PlainDate {
332
391
  const allDays = weeks.flat();
333
- const inGrid = (d: Temporal.PlainDate) => allDays.some((g) => T.PlainDate.compare(g, d) === 0);
392
+ const inGrid = (d: Temporal.PlainDate) =>
393
+ allDays.some((g) => T.PlainDate.compare(g, d) === 0);
334
394
 
335
395
  if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
336
396
 
@@ -339,9 +399,12 @@ export function resolveFocusTarget(
339
399
  if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
340
400
 
341
401
  const firstEnabled = allDays.find(
342
- (d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d),
402
+ (d) =>
403
+ d.year === currentMonth.year &&
404
+ d.month === currentMonth.month &&
405
+ !isDateDisabled(d),
343
406
  );
344
- return firstEnabled ?? allDays[0];
407
+ return firstEnabled ?? allDays[0] ?? focusedDate;
345
408
  }
346
409
 
347
410
  /**
@@ -353,7 +416,10 @@ export function resolveFocusTarget(
353
416
  * @param isFocused - Whether this cell is the logically focused date.
354
417
  * @param gridHasFocus - Whether the grid currently holds DOM focus.
355
418
  */
356
- export function shouldMoveDomFocus(isFocused: boolean, gridHasFocus: boolean): boolean {
419
+ export function shouldMoveDomFocus(
420
+ isFocused: boolean,
421
+ gridHasFocus: boolean,
422
+ ): boolean {
357
423
  return isFocused && gridHasFocus;
358
424
  }
359
425
 
@@ -377,7 +443,10 @@ export function isInRange(
377
443
  if (!rangeStart && !rangeEnd) return false;
378
444
  const effectiveStart = rangeStart ?? rangeEnd!;
379
445
  const effectiveEnd = rangeEnd ?? rangeStart!;
380
- if (T.PlainDate.compare(date, effectiveStart) < 0 || T.PlainDate.compare(date, effectiveEnd) > 0)
446
+ if (
447
+ T.PlainDate.compare(date, effectiveStart) < 0 ||
448
+ T.PlainDate.compare(date, effectiveEnd) > 0
449
+ )
381
450
  return false;
382
451
  const totalDays = effectiveEnd.since(effectiveStart).days;
383
452
  if (totalDays === 0) return 0;
@@ -385,6 +454,30 @@ export function isInRange(
385
454
  return offsetDays / totalDays;
386
455
  }
387
456
 
457
+ type RangeInfo =
458
+ | {
459
+ active: true;
460
+ startIndex: number;
461
+ endIndex: number;
462
+ extendsBefore: boolean;
463
+ extendsAfter: boolean;
464
+ }
465
+ | {
466
+ active: false;
467
+ startIndex: -1;
468
+ endIndex: -1;
469
+ extendsBefore: false;
470
+ extendsAfter: false;
471
+ };
472
+
473
+ const INACTIVE_RANGE_INFO = {
474
+ active: false,
475
+ startIndex: -1,
476
+ endIndex: -1,
477
+ extendsBefore: false,
478
+ extendsAfter: false,
479
+ } as const satisfies RangeInfo;
480
+
388
481
  /**
389
482
  * Computes how a date range intersects with a single calendar week row.
390
483
  *
@@ -403,33 +496,23 @@ export function computeWeekRangeInfo(
403
496
  rangeStart: Temporal.PlainDate | undefined,
404
497
  rangeEnd: Temporal.PlainDate | undefined,
405
498
  T: TemporalNamespace,
406
- ): {
407
- active: boolean;
408
- startIndex: number;
409
- endIndex: number;
410
- extendsBefore: boolean;
411
- extendsAfter: boolean;
412
- } {
413
- const inactive = {
414
- active: false,
415
- startIndex: 0,
416
- endIndex: 0,
417
- extendsBefore: false,
418
- extendsAfter: false,
419
- };
420
- if (weekDays.length === 0) return inactive;
421
- if (!rangeStart && !rangeEnd) return inactive;
422
- const effectiveStart = rangeStart ?? rangeEnd!;
423
- const effectiveEnd = rangeEnd ?? rangeStart!;
424
-
499
+ ) {
500
+ if (!rangeStart && !rangeEnd) {
501
+ return INACTIVE_RANGE_INFO;
502
+ }
425
503
  const weekStart = weekDays[0];
426
504
  const weekEnd = weekDays[weekDays.length - 1];
505
+ if (!weekStart || !weekEnd) {
506
+ return INACTIVE_RANGE_INFO;
507
+ }
427
508
 
509
+ const effectiveStart = rangeStart ?? rangeEnd!;
510
+ const effectiveEnd = rangeEnd ?? rangeStart!;
428
511
  if (
429
512
  T.PlainDate.compare(effectiveEnd, weekStart) < 0 ||
430
513
  T.PlainDate.compare(effectiveStart, weekEnd) > 0
431
514
  ) {
432
- return inactive;
515
+ return INACTIVE_RANGE_INFO;
433
516
  }
434
517
 
435
518
  const extendsBefore = T.PlainDate.compare(effectiveStart, weekStart) < 0;
@@ -437,17 +520,27 @@ export function computeWeekRangeInfo(
437
520
 
438
521
  let startIndex = 0;
439
522
  if (!extendsBefore) {
440
- startIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveStart) === 0);
441
- if (startIndex === -1) return inactive;
523
+ startIndex = weekDays.findIndex(
524
+ (d) => T.PlainDate.compare(d, effectiveStart) === 0,
525
+ );
526
+ if (startIndex === -1) return INACTIVE_RANGE_INFO;
442
527
  }
443
528
 
444
529
  let endIndex = weekDays.length - 1;
445
530
  if (!extendsAfter) {
446
- endIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveEnd) === 0);
447
- if (endIndex === -1) return inactive;
531
+ endIndex = weekDays.findIndex(
532
+ (d) => T.PlainDate.compare(d, effectiveEnd) === 0,
533
+ );
534
+ if (endIndex === -1) return INACTIVE_RANGE_INFO;
448
535
  }
449
536
 
450
- return { active: true, startIndex, endIndex, extendsBefore, extendsAfter };
537
+ return {
538
+ active: true,
539
+ startIndex,
540
+ endIndex,
541
+ extendsBefore,
542
+ extendsAfter,
543
+ } as const satisfies RangeInfo;
451
544
  }
452
545
 
453
546
  /**
@@ -456,9 +549,15 @@ export function computeWeekRangeInfo(
456
549
  * @param locale - BCP 47 locale string (e.g. `"en-US"`).
457
550
  * @param T - Temporal namespace.
458
551
  * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
459
- * @returns An array of 7 objects with `long`, `short`, and `narrow` name variants.
552
+ * @returns An array of objects with `long`, `short`, and `narrow` name variants,
553
+ * one per day in the calendar's week (typically 7, but may differ for
554
+ * non-Gregorian calendars).
460
555
  */
461
- export function getWeekdayNames(locale: string, T: TemporalNamespace, weekStartDay = 0) {
556
+ export function getWeekdayNames(
557
+ locale: string,
558
+ T: TemporalNamespace,
559
+ weekStartDay = 0,
560
+ ) {
462
561
  const refStart = getReferenceWeekStart(T, weekStartDay);
463
562
  const daysInWeek = refStart.daysInWeek;
464
563
  const names: { long: string; short: string; narrow: string }[] = [];
@@ -481,7 +580,10 @@ export function getWeekdayNames(locale: string, T: TemporalNamespace, weekStartD
481
580
  * @param date - The date to compute the week number for.
482
581
  * @param T - Temporal namespace.
483
582
  */
484
- export function getISOWeekNumber(date: Temporal.PlainDate, T: TemporalNamespace): number {
583
+ export function getISOWeekNumber(
584
+ date: Temporal.PlainDate,
585
+ T: TemporalNamespace,
586
+ ): number {
485
587
  // ISO dayOfWeek: 1=Mon...7=Sun
486
588
  // Find the Thursday of this ISO week
487
589
  const thursday = date.add({ days: 4 - date.dayOfWeek });
@@ -23,6 +23,9 @@ export const ViewContext = createContext<ViewContextValue | null>(null);
23
23
  /** Returns the nearest view context (MonthView or WeeksView). */
24
24
  export function useViewContext(): ViewContextValue {
25
25
  const ctx = useContext(ViewContext);
26
- if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
26
+ if (!ctx)
27
+ throw new Error(
28
+ "useViewContext must be used within MonthView or WeeksView",
29
+ );
27
30
  return ctx;
28
31
  }
@@ -6,7 +6,6 @@ import { WeekDataContext } from "./context";
6
6
  import { useMonthViewState } from "./month-view-context";
7
7
  import type { StateAttributesMapping } from "./types";
8
8
  import type {
9
- ValueFormat,
10
9
  WeekNumberCellState,
11
10
  WeekNumberCellProps,
12
11
  WeekNumberHeaderState,
@@ -32,9 +31,9 @@ function WeekNumberCellFn(
32
31
 
33
32
  // ISO week number is determined by the Thursday of the week
34
33
  const weekNumber = useMemo(() => {
35
- if (days.length === 0) return 0;
36
34
  // Find the Thursday in this week row — it determines the ISO week number
37
35
  let thursday = days[0];
36
+ if (thursday === undefined) return 0;
38
37
  for (const d of days) {
39
38
  if (d.dayOfWeek === 4) {
40
39
  thursday = d;
@@ -72,8 +71,8 @@ function WeekNumberCellFn(
72
71
  * Renders the ISO 8601 week number for a week row. Must be used inside
73
72
  * a {@link WeekTemplate}. Renders a `<td>` with `role="rowheader"`.
74
73
  */
75
- export const WeekNumberCell = forwardRef(WeekNumberCellFn) as <F extends ValueFormat = ValueFormat>(
76
- props: WeekNumberCellProps<F> & React.RefAttributes<HTMLTableCellElement>,
74
+ export const WeekNumberCell = forwardRef(WeekNumberCellFn) as (
75
+ props: WeekNumberCellProps & React.RefAttributes<HTMLTableCellElement>,
77
76
  ) => React.ReactElement | null;
78
77
 
79
78
  const weekNumberHeaderStateAttributesMapping = {
@@ -111,8 +110,6 @@ function WeekNumberHeaderFn(
111
110
  /**
112
111
  * Column header for the week number column. Renders a `<th scope="col">`.
113
112
  */
114
- export const WeekNumberHeader = forwardRef(WeekNumberHeaderFn) as <
115
- F extends ValueFormat = ValueFormat,
116
- >(
117
- props: WeekNumberHeaderProps<F> & React.RefAttributes<HTMLTableCellElement>,
113
+ export const WeekNumberHeader = forwardRef(WeekNumberHeaderFn) as (
114
+ props: WeekNumberHeaderProps & React.RefAttributes<HTMLTableCellElement>,
118
115
  ) => React.ReactElement | null;
@@ -7,7 +7,11 @@ import React, { useMemo, Children, isValidElement } from "react";
7
7
  import { useCalendarStable } from "./calendar-context";
8
8
  import type { WeekDescriptor } from "./compute-weeks-in-window";
9
9
  import { WeekDataContext, GridMonthContext } from "./context";
10
- import { MonthSeparatorDataContext, MonthSeparator, MonthSeparatorRow } from "./month-separator";
10
+ import {
11
+ MonthSeparatorDataContext,
12
+ MonthSeparator,
13
+ MonthSeparatorRow,
14
+ } from "./month-separator";
11
15
  import type { MonthSeparatorState } from "./month-separator";
12
16
  import type { TemporalNamespace, WeekStartDay } from "./types";
13
17
  import { useWeeksViewState } from "./weeks-view-context";
@@ -15,7 +19,10 @@ import { useWeeksViewState } from "./weeks-view-context";
15
19
  /**
16
20
  * Expand a WeekDescriptor into the 7 PlainDate values for that week.
17
21
  */
18
- function weekDays(week: WeekDescriptor, _T: TemporalNamespace): Temporal.PlainDate[] {
22
+ function weekDays(
23
+ week: WeekDescriptor,
24
+ _T: TemporalNamespace,
25
+ ): Temporal.PlainDate[] {
19
26
  const days: Temporal.PlainDate[] = [];
20
27
  let d = week.startDate;
21
28
  for (let i = 0; i < 7; i++) {
@@ -80,7 +87,10 @@ export function WeeksGrid(props: {
80
87
  });
81
88
 
82
89
  // Pre-compute days arrays for all weeks (memoised on weeks identity).
83
- const weekDaysArrays = useMemo(() => weeks.map((w) => weekDays(w, T)), [weeks, T]);
90
+ const weekDaysArrays = useMemo(
91
+ () => weeks.map((w) => weekDays(w, T)),
92
+ [weeks, T],
93
+ );
84
94
 
85
95
  const totalColumns = hasWeekNumbers ? 8 : 7;
86
96
 
@@ -91,15 +101,18 @@ export function WeeksGrid(props: {
91
101
  // Track which months we've already created separators for
92
102
  const seenMonths = new Set<string>();
93
103
 
94
- for (let i = 0; i < weeks.length; i++) {
95
- const days = weekDaysArrays[i];
104
+ for (const [i, days] of weekDaysArrays.entries()) {
96
105
  const isFirstWeek = i === 0;
97
106
 
98
107
  // Find all distinct months in this week's days
99
- const monthsInWeek: Array<{ month: number; year: number; key: string }> = [];
108
+ const monthsInWeek: Array<{ month: number; year: number; key: string }> =
109
+ [];
100
110
  for (const day of days) {
101
111
  const monthKey = `${day.year}-${day.month}`;
102
- if (!seenMonths.has(monthKey) && !monthsInWeek.some((m) => m.key === monthKey)) {
112
+ if (
113
+ !seenMonths.has(monthKey) &&
114
+ !monthsInWeek.some((m) => m.key === monthKey)
115
+ ) {
103
116
  monthsInWeek.push({
104
117
  month: day.month,
105
118
  year: day.year,
@@ -110,7 +123,9 @@ export function WeeksGrid(props: {
110
123
 
111
124
  // If the first week spans two months, only show the second (newer) month
112
125
  const monthsToShow =
113
- isFirstWeek && monthsInWeek.length > 1 ? monthsInWeek.slice(1) : monthsInWeek;
126
+ isFirstWeek && monthsInWeek.length > 1
127
+ ? monthsInWeek.slice(1)
128
+ : monthsInWeek;
114
129
 
115
130
  // Mark all months in this week as seen (even skipped ones)
116
131
  for (const m of monthsInWeek) {
@@ -124,7 +139,11 @@ export function WeeksGrid(props: {
124
139
  month: newMonth,
125
140
  day: 1,
126
141
  });
127
- const firstDayCol = dayColumnIndex(firstOfMonth, weekStartDay, hasWeekNumbers);
142
+ const firstDayCol = dayColumnIndex(
143
+ firstOfMonth,
144
+ weekStartDay,
145
+ hasWeekNumbers,
146
+ );
128
147
 
129
148
  // Check if the 1st day of this month is actually visible in the window
130
149
  const windowStart = weekDaysArrays[0]?.[0];
@@ -140,7 +159,10 @@ export function WeeksGrid(props: {
140
159
  for (let j = i - 1; j >= 0; j--) {
141
160
  // Check if all days in that week are before this month
142
161
  const prevDays = weekDaysArrays[j];
143
- const hasThisMonth = prevDays.some((d) => d.month === newMonth && d.year === newYear);
162
+ if (prevDays === undefined) break;
163
+ const hasThisMonth = prevDays.some(
164
+ (d) => d.month === newMonth && d.year === newYear,
165
+ );
144
166
  if (!hasThisMonth) {
145
167
  weeksVisibleBefore++;
146
168
  } else {
@@ -150,9 +172,12 @@ export function WeeksGrid(props: {
150
172
 
151
173
  // Count weeks visible after (weeks containing days of this month)
152
174
  let weeksVisibleAfter = 0;
153
- for (let j = i; j < weeks.length; j++) {
175
+ for (let j = i; j < weekDaysArrays.length; j++) {
154
176
  const wDays = weekDaysArrays[j];
155
- const hasThisMonth = wDays.some((d) => d.month === newMonth && d.year === newYear);
177
+ if (wDays === undefined) break;
178
+ const hasThisMonth = wDays.some(
179
+ (d) => d.month === newMonth && d.year === newYear,
180
+ );
156
181
  if (hasThisMonth) {
157
182
  weeksVisibleAfter++;
158
183
  } else {
@@ -161,9 +186,10 @@ export function WeeksGrid(props: {
161
186
  }
162
187
 
163
188
  // Determine firstOfYear
189
+ const lastBoundary = boundaries[boundaries.length - 1];
164
190
  const isNewYear =
165
- boundaries.length > 0
166
- ? boundaries[boundaries.length - 1].data.year !== newYear
191
+ lastBoundary !== undefined
192
+ ? lastBoundary.data.year !== newYear
167
193
  : newMonth === 1;
168
194
 
169
195
  boundaries.push({
@@ -189,9 +215,9 @@ export function WeeksGrid(props: {
189
215
  // fullWeeksVisibleAfter = week rows between this separator and the next
190
216
  // (or end of window). gridRowStart = 1-based row in the grid body
191
217
  // (accounting for header row offset +1).
192
- for (let b = 0; b < boundaries.length; b++) {
193
- const current = boundaries[b];
194
- const nextIndex = b + 1 < boundaries.length ? boundaries[b + 1].index : weeks.length;
218
+ for (const [b, current] of boundaries.entries()) {
219
+ const next = boundaries[b + 1];
220
+ const nextIndex = next !== undefined ? next.index : weeks.length;
195
221
  current.data.fullWeeksVisibleAfter = nextIndex - current.index;
196
222
  // Grid row: header is row 1, week rows start at row 2.
197
223
  // gridRowStart matches the week row it labels: index + 2 (1-based + header).
@@ -217,9 +243,9 @@ export function WeeksGrid(props: {
217
243
 
218
244
  const rows: React.ReactNode[] = [];
219
245
 
220
- for (let i = 0; i < weeks.length; i++) {
221
- const week = weeks[i];
246
+ for (const [i, week] of weeks.entries()) {
222
247
  const days = weekDaysArrays[i];
248
+ if (days === undefined) continue;
223
249
  const separators = boundariesAtIndex.get(i);
224
250
 
225
251
  // Render separators at month boundaries
@@ -15,7 +15,6 @@ const baseInput: WeeksKeyNavInput = {
15
15
  maxValue: undefined,
16
16
  disabled: false,
17
17
  readOnly: false,
18
- isDateDisabled: undefined,
19
18
  scrollBy: "row",
20
19
  T,
21
20
  weekStartDay: 0,
@@ -94,9 +93,9 @@ describe("computeWeeksKeyNav", () => {
94
93
  shiftKey: true,
95
94
  });
96
95
  expect(result.action).toBe("move");
97
- expect((result as Extract<typeof result, { action: "move" }>).date.toString()).toBe(
98
- "2027-03-15",
99
- );
96
+ expect(
97
+ (result as Extract<typeof result, { action: "move" }>).date.toString(),
98
+ ).toBe("2027-03-15");
100
99
  expect(result.followFocus).toBe(true);
101
100
  expect(result.windowShift).toBe(0);
102
101
  });
@@ -214,9 +213,9 @@ describe("computeWeeksKeyNav", () => {
214
213
  shiftKey: true,
215
214
  });
216
215
  expect(result.action).toBe("move");
217
- expect((result as Extract<typeof result, { action: "move" }>).date.toString()).toBe(
218
- "2025-03-15",
219
- );
216
+ expect(
217
+ (result as Extract<typeof result, { action: "move" }>).date.toString(),
218
+ ).toBe("2025-03-15");
220
219
  expect(result.followFocus).toBe(true);
221
220
  });
222
221
  });
@@ -77,7 +77,10 @@ export function computeWeeksKeyNav(input: WeeksKeyNavInput): WeeksKeyNavResult {
77
77
  const windowEnd = windowStart.add({ weeks: weekCount }).subtract({ days: 1 });
78
78
 
79
79
  function isOutsideWindow(date: Temporal.PlainDate): boolean {
80
- return T.PlainDate.compare(date, windowStart) < 0 || T.PlainDate.compare(date, windowEnd) > 0;
80
+ return (
81
+ T.PlainDate.compare(date, windowStart) < 0 ||
82
+ T.PlainDate.compare(date, windowEnd) > 0
83
+ );
81
84
  }
82
85
 
83
86
  function windowShiftFor(target: Temporal.PlainDate): number {
@@ -96,8 +99,10 @@ export function computeWeeksKeyNav(input: WeeksKeyNavInput): WeeksKeyNavResult {
96
99
  followFocus: boolean,
97
100
  ): WeeksKeyNavResult {
98
101
  let clamped = target;
99
- if (minValue && T.PlainDate.compare(clamped, minValue) < 0) clamped = minValue;
100
- if (maxValue && T.PlainDate.compare(clamped, maxValue) > 0) clamped = maxValue;
102
+ if (minValue && T.PlainDate.compare(clamped, minValue) < 0)
103
+ clamped = minValue;
104
+ if (maxValue && T.PlainDate.compare(clamped, maxValue) > 0)
105
+ clamped = maxValue;
101
106
  if (T.PlainDate.compare(clamped, focusedDate) === 0) return NONE;
102
107
  return { action: "move", date: clamped, windowShift, followFocus };
103
108
  }
@@ -25,11 +25,17 @@ export interface WeeksNavButtonOwnProps {
25
25
  }
26
26
 
27
27
  /** Full props for the `PrevWeeksButton` component. */
28
- export type PrevWeeksButtonProps = useRender.ComponentProps<"button", WeeksNavButtonState> &
28
+ export type PrevWeeksButtonProps = useRender.ComponentProps<
29
+ "button",
30
+ WeeksNavButtonState
31
+ > &
29
32
  WeeksNavButtonOwnProps;
30
33
 
31
34
  /** Full props for the `NextWeeksButton` component. */
32
- export type NextWeeksButtonProps = useRender.ComponentProps<"button", WeeksNavButtonState> &
35
+ export type NextWeeksButtonProps = useRender.ComponentProps<
36
+ "button",
37
+ WeeksNavButtonState
38
+ > &
33
39
  WeeksNavButtonOwnProps;
34
40
 
35
41
  /** State exposed by `WeeksView.WeekCount`. */
@@ -60,7 +66,10 @@ const weekCountStateAttributesMapping = {
60
66
  // Shared hook
61
67
  // ---------------------------------------------------------------------------
62
68
 
63
- function useWeeksNavButton(direction: "prev" | "next", shiftByProp: number | undefined) {
69
+ function useWeeksNavButton(
70
+ direction: "prev" | "next",
71
+ shiftByProp: number | undefined,
72
+ ) {
64
73
  const {
65
74
  disabled: globalDisabled,
66
75
  minValue,
@@ -80,10 +89,10 @@ function useWeeksNavButton(direction: "prev" | "next", shiftByProp: number | und
80
89
  currentFirstWeek,
81
90
  weekCount,
82
91
  direction: direction === "next" ? 1 : -1,
83
- shiftBy: shiftByProp,
92
+ ...(shiftByProp !== undefined && { shiftBy: shiftByProp }),
84
93
  behavior: overflowBehavior,
85
- min: minValue,
86
- max: maxValue,
94
+ ...(minValue !== undefined && { min: minValue }),
95
+ ...(maxValue !== undefined && { max: maxValue }),
87
96
  weekStartDay,
88
97
  T,
89
98
  });
@@ -101,7 +110,7 @@ function useWeeksNavButton(direction: "prev" | "next", shiftByProp: number | und
101
110
  ]);
102
111
 
103
112
  const state = useMemo<WeeksNavButtonState>(
104
- () => ({ root: rootState as any, direction, disabled: isDisabled }),
113
+ () => ({ root: rootState, direction, disabled: isDisabled }),
105
114
  [rootState, direction, isDisabled],
106
115
  );
107
116
 
@@ -177,14 +186,17 @@ export const NextWeeksButton = forwardRef(NextWeeksButtonFn);
177
186
  // WeekCount
178
187
  // ---------------------------------------------------------------------------
179
188
 
180
- function WeekCountFn(props: WeekCountProps, ref: React.ForwardedRef<HTMLSpanElement>) {
189
+ function WeekCountFn(
190
+ props: WeekCountProps,
191
+ ref: React.ForwardedRef<HTMLSpanElement>,
192
+ ) {
181
193
  const { render, ...otherProps } = props;
182
194
  const { windowInfo } = useWeeksViewState();
183
195
  const { rootState } = useMonthViewState();
184
196
  const count = windowInfo.weekCount;
185
197
 
186
198
  const state = useMemo<WeekCountState>(
187
- () => ({ root: rootState as any, weekCount: count }),
199
+ () => ({ root: rootState, weekCount: count }),
188
200
  [rootState, count],
189
201
  );
190
202