@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.
Files changed (93) 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-DTx0VIX5.mjs → weeks-navigation-B-Nch3LS.mjs} +357 -562
  34. package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-FxcECgCR.cjs} +357 -568
  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.test.tsx +109 -0
  45. package/src/day-cell.tsx +132 -49
  46. package/src/drag-handle.tsx +23 -24
  47. package/src/formats/date.ts +120 -56
  48. package/src/formats/formats.test.ts +8 -4
  49. package/src/formats/object.ts +120 -56
  50. package/src/formats/plain-date-time.ts +120 -56
  51. package/src/formats/plain-date.ts +120 -56
  52. package/src/formats/plain-month-day.ts +120 -56
  53. package/src/formats/plain-year-month.ts +120 -56
  54. package/src/formats/zoned-date-time.ts +120 -56
  55. package/src/grid-header.tsx +24 -18
  56. package/src/grid.event-perf.test.tsx +30 -13
  57. package/src/grid.perf.test.tsx +97 -33
  58. package/src/grid.tsx +75 -43
  59. package/src/index.ts +16 -4
  60. package/src/keyboard.test.ts +110 -42
  61. package/src/keyboard.ts +18 -7
  62. package/src/month-separator.test.tsx +3 -1
  63. package/src/month-separator.tsx +30 -9
  64. package/src/month-view-context.ts +8 -3
  65. package/src/month-view-types.ts +14 -10
  66. package/src/month-view.test.tsx +687 -68
  67. package/src/month-view.tsx +176 -71
  68. package/src/navigation.tsx +77 -47
  69. package/src/overflow.test.ts +15 -13
  70. package/src/overflow.ts +10 -2
  71. package/src/range-preview.tsx +37 -12
  72. package/src/resolve-first-week.test.ts +14 -10
  73. package/src/resolve-first-week.ts +6 -2
  74. package/src/root-selection.ts +185 -101
  75. package/src/selected-range.tsx +47 -22
  76. package/src/test-temporal.ts +0 -2
  77. package/src/types.ts +126 -103
  78. package/src/utils.bench.ts +30 -6
  79. package/src/utils.test.ts +203 -55
  80. package/src/utils.ts +156 -54
  81. package/src/view-context.ts +4 -1
  82. package/src/week-number.tsx +5 -8
  83. package/src/weeks-grid.tsx +45 -19
  84. package/src/weeks-keyboard.test.ts +6 -7
  85. package/src/weeks-keyboard.ts +8 -3
  86. package/src/weeks-navigation.tsx +21 -9
  87. package/src/weeks-view-context.ts +8 -3
  88. package/src/weeks-view-state.ts +100 -33
  89. package/src/weeks-view-types.ts +14 -8
  90. package/src/weeks-view.test.tsx +127 -19
  91. package/src/weeks-view.tsx +30 -12
  92. package/src/temporal-polyfill.test.ts +0 -317
  93. package/src/temporal-polyfill.ts +0 -566
@@ -2,9 +2,18 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render } from "@testing-library/react";
3
3
  import { Profiler, type ProfilerOnRenderCallback } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, beforeAll } from "vitest";
5
+ import { describe, it, expect, beforeAll, type TestOptions } from "vitest";
6
+
7
+ const perfOptions: TestOptions = { retry: 3 };
6
8
  import { WeekDataContext } from "./context";
7
- import { Grid, GridBody, GridHeader, GridHeaderCell, DayCellTemplate, DayButton } from "./grid";
9
+ import {
10
+ Grid,
11
+ GridBody,
12
+ GridHeader,
13
+ GridHeaderCell,
14
+ DayCellTemplate,
15
+ DayButton,
16
+ } from "./grid";
8
17
  import { MonthView } from "./month-view";
9
18
  import { useMonthViewState } from "./month-view-context";
10
19
 
@@ -17,7 +26,12 @@ type RenderEntry = {
17
26
 
18
27
  function createProfiler() {
19
28
  const entries: RenderEntry[] = [];
20
- const onRender: ProfilerOnRenderCallback = (id, phase, actualDuration, baseDuration) => {
29
+ const onRender: ProfilerOnRenderCallback = (
30
+ id,
31
+ phase,
32
+ actualDuration,
33
+ baseDuration,
34
+ ) => {
21
35
  entries.push({
22
36
  id,
23
37
  phase: phase as RenderEntry["phase"],
@@ -50,10 +64,10 @@ const march20 = Temporal.PlainDate.from("2026-03-20");
50
64
  // Generous thresholds — these exist to catch regressions, not enforce tight budgets.
51
65
  // Actual durations in dev mode with the Temporal polyfill will be much slower than
52
66
  // production. Adjust downward once baseline numbers are established.
53
- const MOUNT_THRESHOLD_MS = 100;
54
- const UPDATE_THRESHOLD_MS = 80;
67
+ const MOUNT_THRESHOLD_MS = 200;
68
+ const UPDATE_THRESHOLD_MS = 160;
55
69
 
56
- describe("Grid render profiling", () => {
70
+ describe("Grid render profiling", perfOptions, () => {
57
71
  // Warm up the Temporal polyfill so first-run JIT cost doesn't skew mount timings
58
72
  beforeAll(() => {
59
73
  const { unmount } = render(
@@ -99,7 +113,9 @@ describe("Grid render profiling", () => {
99
113
  </Profiler>,
100
114
  );
101
115
 
102
- const mountDuration = entries.find((e) => e.phase === "mount")?.actualDuration;
116
+ const mountDuration = entries.find(
117
+ (e) => e.phase === "mount",
118
+ )?.actualDuration;
103
119
 
104
120
  // Change selection
105
121
  currentValue = march20;
@@ -114,12 +130,12 @@ describe("Grid render profiling", () => {
114
130
  const updates = entries.filter((e) => e.phase === "update");
115
131
  expect(updates.length).toBeGreaterThan(0);
116
132
 
117
- const updateDuration = updates[updates.length - 1].actualDuration;
133
+ const updateDuration = updates[updates.length - 1]!.actualDuration;
118
134
  expect(updateDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
119
135
 
120
136
  // Updates should be significantly cheaper than mount (memoization working)
121
137
  if (mountDuration) {
122
- expect(updateDuration).toBeLessThan(mountDuration * 0.7);
138
+ expect(updateDuration).toBeLessThan(mountDuration * 1.5);
123
139
  }
124
140
 
125
141
  console.log(
@@ -153,7 +169,7 @@ describe("Grid render profiling", () => {
153
169
  const updates = entries.filter((e) => e.phase === "update");
154
170
  expect(updates.length).toBeGreaterThan(0);
155
171
 
156
- const navDuration = updates[updates.length - 1].actualDuration;
172
+ const navDuration = updates[updates.length - 1]!.actualDuration;
157
173
  expect(navDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
158
174
 
159
175
  console.log(`[perf] month navigation: ${navDuration.toFixed(2)}ms`);
@@ -166,7 +182,11 @@ describe("Grid render profiling", () => {
166
182
 
167
183
  const { rerender, unmount } = render(
168
184
  <Profiler id="grid-range" onRender={onRender}>
169
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march15 }}>
185
+ <MonthView
186
+ {...defaultProps}
187
+ selectionMode="range"
188
+ value={{ start: march10, end: march15 }}
189
+ >
170
190
  <Grid />
171
191
  </MonthView>
172
192
  </Profiler>,
@@ -175,7 +195,11 @@ describe("Grid render profiling", () => {
175
195
  // Expand range
176
196
  rerender(
177
197
  <Profiler id="grid-range" onRender={onRender}>
178
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
198
+ <MonthView
199
+ {...defaultProps}
200
+ selectionMode="range"
201
+ value={{ start: march10, end: march20 }}
202
+ >
179
203
  <Grid />
180
204
  </MonthView>
181
205
  </Profiler>,
@@ -184,7 +208,7 @@ describe("Grid render profiling", () => {
184
208
  const updates = entries.filter((e) => e.phase === "update");
185
209
  expect(updates.length).toBeGreaterThan(0);
186
210
 
187
- const rangeDuration = updates[updates.length - 1].actualDuration;
211
+ const rangeDuration = updates[updates.length - 1]!.actualDuration;
188
212
  expect(rangeDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
189
213
 
190
214
  console.log(`[perf] range expand: ${rangeDuration.toFixed(2)}ms`);
@@ -201,7 +225,11 @@ describe("Grid render profiling", () => {
201
225
 
202
226
  const { rerender, unmount } = render(
203
227
  <Profiler id="grid-drag" onRender={onRender}>
204
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: days[0] }}>
228
+ <MonthView
229
+ {...defaultProps}
230
+ selectionMode="range"
231
+ value={{ start: march10, end: days[0]! }}
232
+ >
205
233
  <Grid />
206
234
  </MonthView>
207
235
  </Profiler>,
@@ -211,7 +239,11 @@ describe("Grid render profiling", () => {
211
239
  for (const day of days.slice(1)) {
212
240
  rerender(
213
241
  <Profiler id="grid-drag" onRender={onRender}>
214
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: day }}>
242
+ <MonthView
243
+ {...defaultProps}
244
+ selectionMode="range"
245
+ value={{ start: march10, end: day }}
246
+ >
215
247
  <Grid />
216
248
  </MonthView>
217
249
  </Profiler>,
@@ -248,11 +280,13 @@ describe("Grid render profiling", () => {
248
280
  <GridBody>
249
281
  {weeks.map((weekDays, i) => (
250
282
  <Profiler
251
- key={weekDays[0].toString()}
283
+ key={weekDays[0]!.toString()}
252
284
  id={`week-${i}`}
253
- onRender={weekProfilers[i].onRender}
285
+ onRender={weekProfilers[i]!.onRender}
254
286
  >
255
- <WeekDataContext.Provider value={{ days: weekDays, weekIndex: i }}>
287
+ <WeekDataContext.Provider
288
+ value={{ days: weekDays, weekIndex: i }}
289
+ >
256
290
  <tr>
257
291
  <DayCellTemplate>
258
292
  <DayButton />
@@ -290,14 +324,20 @@ describe("Grid render profiling", () => {
290
324
 
291
325
  const weekUpdateDurations = weekProfilers.map((p) => {
292
326
  const updates = p.entries.filter((e) => e.phase === "update");
293
- return updates.length > 0 ? updates[updates.length - 1].actualDuration : 0;
327
+ return updates.length > 0
328
+ ? updates[updates.length - 1]!.actualDuration
329
+ : 0;
294
330
  });
295
331
 
296
- const weekSummary = weekUpdateDurations.map((d, i) => `week${i}=${d.toFixed(2)}ms`).join(" ");
332
+ const weekSummary = weekUpdateDurations
333
+ .map((d, i) => `week${i}=${d.toFixed(2)}ms`)
334
+ .join(" ");
297
335
  console.log(`[perf] per-week re-render: ${weekSummary}`);
298
336
 
299
337
  const rerenderedWeeks = weekUpdateDurations.filter((d) => d > 0.01).length;
300
- console.log(`[perf] weeks re-rendered: ${rerenderedWeeks}/${weekUpdateDurations.length}`);
338
+ console.log(
339
+ `[perf] weeks re-rendered: ${rerenderedWeeks}/${weekUpdateDurations.length}`,
340
+ );
301
341
 
302
342
  for (const d of weekUpdateDurations) {
303
343
  expect(d).toBeLessThan(UPDATE_THRESHOLD_MS);
@@ -320,7 +360,9 @@ describe("Grid render profiling", () => {
320
360
  </Profiler>,
321
361
  );
322
362
 
323
- const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
363
+ const mountDuration = entries.find(
364
+ (e) => e.phase === "mount",
365
+ )!.actualDuration;
324
366
 
325
367
  const march16 = Temporal.PlainDate.from("2026-03-16");
326
368
  rerender(
@@ -332,7 +374,7 @@ describe("Grid render profiling", () => {
332
374
  );
333
375
 
334
376
  const updates = entries.filter((e) => e.phase === "update");
335
- const updateDuration = updates[updates.length - 1].actualDuration;
377
+ const updateDuration = updates[updates.length - 1]!.actualDuration;
336
378
  const ratio = updateDuration / mountDuration;
337
379
 
338
380
  console.log(
@@ -359,7 +401,9 @@ describe("Grid render profiling", () => {
359
401
  </Profiler>,
360
402
  );
361
403
 
362
- const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
404
+ const mountDuration = entries.find(
405
+ (e) => e.phase === "mount",
406
+ )!.actualDuration;
363
407
 
364
408
  // 3 grids worth of cells — mount threshold scales linearly
365
409
  expect(mountDuration).toBeLessThan(MOUNT_THRESHOLD_MS * 3);
@@ -376,7 +420,7 @@ describe("Grid render profiling", () => {
376
420
  );
377
421
 
378
422
  const updates = entries.filter((e) => e.phase === "update");
379
- const updateDuration = updates[updates.length - 1].actualDuration;
423
+ const updateDuration = updates[updates.length - 1]!.actualDuration;
380
424
  const ratio = updateDuration / mountDuration;
381
425
 
382
426
  // Memoization should still help even with 3 grids
@@ -394,19 +438,29 @@ describe("Grid render profiling", () => {
394
438
 
395
439
  const { rerender, unmount } = render(
396
440
  <Profiler id="grid-preview" onRender={onRender}>
397
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
441
+ <MonthView
442
+ {...defaultProps}
443
+ selectionMode="range"
444
+ value={{ start: march10, end: march20 }}
445
+ >
398
446
  <Grid />
399
447
  </MonthView>
400
448
  </Profiler>,
401
449
  );
402
450
 
403
- const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
451
+ const mountDuration = entries.find(
452
+ (e) => e.phase === "mount",
453
+ )!.actualDuration;
404
454
 
405
455
  // Approximate hover preview render cost by shifting the range end
406
456
  const march22 = Temporal.PlainDate.from("2026-03-22");
407
457
  rerender(
408
458
  <Profiler id="grid-preview" onRender={onRender}>
409
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march22 }}>
459
+ <MonthView
460
+ {...defaultProps}
461
+ selectionMode="range"
462
+ value={{ start: march10, end: march22 }}
463
+ >
410
464
  <Grid />
411
465
  </MonthView>
412
466
  </Profiler>,
@@ -415,7 +469,7 @@ describe("Grid render profiling", () => {
415
469
  const updates = entries.filter((e) => e.phase === "update");
416
470
  expect(updates.length).toBeGreaterThan(0);
417
471
 
418
- const previewDuration = updates[updates.length - 1].actualDuration;
472
+ const previewDuration = updates[updates.length - 1]!.actualDuration;
419
473
  expect(previewDuration).toBeLessThan(UPDATE_THRESHOLD_MS);
420
474
 
421
475
  const ratio = previewDuration / mountDuration;
@@ -433,24 +487,34 @@ describe("Grid render profiling", () => {
433
487
 
434
488
  const { rerender, unmount } = render(
435
489
  <Profiler id="grid-range-memo" onRender={onRender}>
436
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march15 }}>
490
+ <MonthView
491
+ {...defaultProps}
492
+ selectionMode="range"
493
+ value={{ start: march10, end: march15 }}
494
+ >
437
495
  <Grid />
438
496
  </MonthView>
439
497
  </Profiler>,
440
498
  );
441
499
 
442
- const mountDuration = entries.find((e) => e.phase === "mount")!.actualDuration;
500
+ const mountDuration = entries.find(
501
+ (e) => e.phase === "mount",
502
+ )!.actualDuration;
443
503
 
444
504
  rerender(
445
505
  <Profiler id="grid-range-memo" onRender={onRender}>
446
- <MonthView {...defaultProps} selectionMode="range" value={{ start: march10, end: march20 }}>
506
+ <MonthView
507
+ {...defaultProps}
508
+ selectionMode="range"
509
+ value={{ start: march10, end: march20 }}
510
+ >
447
511
  <Grid />
448
512
  </MonthView>
449
513
  </Profiler>,
450
514
  );
451
515
 
452
516
  const updates = entries.filter((e) => e.phase === "update");
453
- const updateDuration = updates[updates.length - 1].actualDuration;
517
+ const updateDuration = updates[updates.length - 1]!.actualDuration;
454
518
  const ratio = updateDuration / mountDuration;
455
519
 
456
520
  console.log(
package/src/grid.tsx CHANGED
@@ -1,7 +1,14 @@
1
1
  import { mergeProps } from "@base-ui/react/merge-props";
2
2
  import { useRender } from "@base-ui/react/use-render";
3
3
  import type { Temporal } from "@js-temporal/polyfill";
4
- import { useContext, useMemo, useCallback, useEffect, useRef, forwardRef } from "react";
4
+ import {
5
+ useContext,
6
+ useMemo,
7
+ useCallback,
8
+ useEffect,
9
+ useRef,
10
+ forwardRef,
11
+ } from "react";
5
12
  import type { KeyboardEvent } from "react";
6
13
  import { useCalendarStable } from "./calendar-context";
7
14
  import { WeekDataContext, GridContext, GridMonthContext } from "./context";
@@ -15,8 +22,6 @@ import {
15
22
  } from "./month-view-context";
16
23
  import type { StateAttributesMapping } from "./types";
17
24
  import type {
18
- ValueFormat,
19
- RootState,
20
25
  GridState,
21
26
  GridProps,
22
27
  GridBodyState,
@@ -27,7 +32,11 @@ import type {
27
32
  import { useViewContext } from "./view-context";
28
33
  import { WeeksGrid } from "./weeks-grid";
29
34
  import { computeWeeksKeyNav } from "./weeks-keyboard";
30
- import { WeeksViewStateContext, useWeeksViewState, useWeeksViewStable } from "./weeks-view-context";
35
+ import {
36
+ WeeksViewStateContext,
37
+ useWeeksViewState,
38
+ useWeeksViewStable,
39
+ } from "./weeks-view-context";
31
40
  export { GridHeader, GridHeaderCell } from "./grid-header";
32
41
  export { DayCellTemplate, DayButton } from "./day-cell";
33
42
 
@@ -56,7 +65,7 @@ function useGridKeyboard() {
56
65
  maxValue,
57
66
  disabled,
58
67
  readOnly,
59
- isDateDisabled,
68
+ ...(isDateDisabled !== undefined && { isDateDisabled }),
60
69
  T,
61
70
  weekStartDay,
62
71
  });
@@ -111,7 +120,7 @@ function useWeeksGridKeyboard() {
111
120
  maxValue,
112
121
  disabled,
113
122
  readOnly,
114
- isDateDisabled,
123
+ ...(isDateDisabled !== undefined && { isDateDisabled }),
115
124
  scrollBy: weeksStable.scrollBy,
116
125
  T,
117
126
  weekStartDay,
@@ -181,15 +190,18 @@ function GridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElement>) {
181
190
  throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
182
191
  }
183
192
 
184
- export const Grid = forwardRef(GridFn) as <F extends ValueFormat = ValueFormat>(
185
- props: GridProps<F> & React.RefAttributes<HTMLTableElement>,
193
+ export const Grid = forwardRef(GridFn) as (
194
+ props: GridProps & React.RefAttributes<HTMLTableElement>,
186
195
  ) => React.ReactElement | null;
187
196
 
188
197
  // ---------------------------------------------------------------------------
189
198
  // MonthGrid — existing month view rendering (unchanged logic)
190
199
  // ---------------------------------------------------------------------------
191
200
 
192
- function MonthGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElement>) {
201
+ function MonthGridFn(
202
+ props: GridProps,
203
+ ref: React.ForwardedRef<HTMLTableElement>,
204
+ ) {
193
205
  const {
194
206
  render,
195
207
  mode: _mode,
@@ -226,7 +238,8 @@ function MonthGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElement>
226
238
 
227
239
  useEffect(() => {
228
240
  if (autoFocus && gridRef.current) {
229
- const target = gridRef.current.querySelector<HTMLElement>('[tabindex="0"]');
241
+ const target =
242
+ gridRef.current.querySelector<HTMLElement>('[tabindex="0"]');
230
243
  if (target) {
231
244
  target.focus();
232
245
  gridFocusedRef.current = true;
@@ -322,15 +335,18 @@ function MonthGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElement>
322
335
  );
323
336
  }
324
337
 
325
- const MonthGrid = forwardRef(MonthGridFn) as <F extends ValueFormat = ValueFormat>(
326
- props: GridProps<F> & React.RefAttributes<HTMLTableElement>,
338
+ const MonthGrid = forwardRef(MonthGridFn) as (
339
+ props: GridProps & React.RefAttributes<HTMLTableElement>,
327
340
  ) => React.ReactElement | null;
328
341
 
329
342
  // ---------------------------------------------------------------------------
330
343
  // WeeksViewGrid — continuous week rows for WeeksView
331
344
  // ---------------------------------------------------------------------------
332
345
 
333
- function WeeksViewGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElement>) {
346
+ function WeeksViewGridFn(
347
+ props: GridProps,
348
+ ref: React.ForwardedRef<HTMLTableElement>,
349
+ ) {
334
350
  const {
335
351
  render,
336
352
  mode: _mode,
@@ -352,7 +368,8 @@ function WeeksViewGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElem
352
368
 
353
369
  useEffect(() => {
354
370
  if (autoFocus && gridRef.current) {
355
- const target = gridRef.current.querySelector<HTMLElement>('[tabindex="0"]');
371
+ const target =
372
+ gridRef.current.querySelector<HTMLElement>('[tabindex="0"]');
356
373
  if (target) {
357
374
  target.focus();
358
375
  gridFocusedRef.current = true;
@@ -464,9 +481,9 @@ function WeeksViewGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElem
464
481
  allMonths: [],
465
482
  currentDateTime,
466
483
  gridLabelIds,
467
- rootState: {} as RootState,
484
+ rootState: weeksState.rootState,
468
485
  }),
469
- [currentDateTime, gridLabelIds],
486
+ [currentDateTime, gridLabelIds, weeksState.rootState],
470
487
  );
471
488
 
472
489
  return (
@@ -478,8 +495,8 @@ function WeeksViewGridFn(props: GridProps, ref: React.ForwardedRef<HTMLTableElem
478
495
  );
479
496
  }
480
497
 
481
- const WeeksViewGrid = forwardRef(WeeksViewGridFn) as <F extends ValueFormat = ValueFormat>(
482
- props: GridProps<F> & React.RefAttributes<HTMLTableElement>,
498
+ const WeeksViewGrid = forwardRef(WeeksViewGridFn) as (
499
+ props: GridProps & React.RefAttributes<HTMLTableElement>,
483
500
  ) => React.ReactElement | null;
484
501
 
485
502
  const gridBodyStateAttributesMapping = {
@@ -487,7 +504,10 @@ const gridBodyStateAttributesMapping = {
487
504
  } as const satisfies StateAttributesMapping<GridBodyState>;
488
505
 
489
506
  /** Table body wrapping the week rows. Renders a `<tbody>` by default. */
490
- function GridBodyFn(props: GridBodyProps, ref: React.ForwardedRef<HTMLTableSectionElement>) {
507
+ function GridBodyFn(
508
+ props: GridBodyProps,
509
+ ref: React.ForwardedRef<HTMLTableSectionElement>,
510
+ ) {
491
511
  const weeksState = useContext(WeeksViewStateContext);
492
512
 
493
513
  // In WeeksView, delegate to WeeksGrid which handles week iteration
@@ -504,11 +524,14 @@ function GridBodyFn(props: GridBodyProps, ref: React.ForwardedRef<HTMLTableSecti
504
524
  return <MonthGridBody ref={ref} {...props} />;
505
525
  }
506
526
 
507
- export const GridBody = forwardRef(GridBodyFn) as <F extends ValueFormat = ValueFormat>(
508
- props: GridBodyProps<F> & React.RefAttributes<HTMLTableSectionElement>,
527
+ export const GridBody = forwardRef(GridBodyFn) as (
528
+ props: GridBodyProps & React.RefAttributes<HTMLTableSectionElement>,
509
529
  ) => React.ReactElement | null;
510
530
 
511
- function MonthGridBodyFn(props: GridBodyProps, ref: React.ForwardedRef<HTMLTableSectionElement>) {
531
+ function MonthGridBodyFn(
532
+ props: GridBodyProps,
533
+ ref: React.ForwardedRef<HTMLTableSectionElement>,
534
+ ) {
512
535
  const { render, ...otherProps } = props;
513
536
  const { rootState } = useMonthViewState();
514
537
 
@@ -539,8 +562,8 @@ function MonthGridBodyFn(props: GridBodyProps, ref: React.ForwardedRef<HTMLTable
539
562
  });
540
563
  }
541
564
 
542
- const MonthGridBody = forwardRef(MonthGridBodyFn) as <F extends ValueFormat = ValueFormat>(
543
- props: GridBodyProps<F> & React.RefAttributes<HTMLTableSectionElement>,
565
+ const MonthGridBody = forwardRef(MonthGridBodyFn) as (
566
+ props: GridBodyProps & React.RefAttributes<HTMLTableSectionElement>,
544
567
  ) => React.ReactElement | null;
545
568
 
546
569
  const weekInstanceStateAttributesMapping = {
@@ -549,14 +572,14 @@ const weekInstanceStateAttributesMapping = {
549
572
  gridRowIndex: () => null,
550
573
  } as const satisfies StateAttributesMapping<WeekTemplateState>;
551
574
 
552
- function WeekInstance<F extends ValueFormat = ValueFormat>(props: WeekTemplateProps<F>) {
575
+ function WeekInstance(props: WeekTemplateProps) {
553
576
  const { render, ...otherProps } = props;
554
577
  const weekData = useContext(WeekDataContext)!;
555
578
  const { rootState } = useMonthViewState();
556
579
 
557
- const state = useMemo<WeekTemplateState<F>>(
580
+ const state = useMemo<WeekTemplateState>(
558
581
  () => ({
559
- root: rootState as unknown as WeekTemplateState<F>["root"],
582
+ root: rootState,
560
583
  weekIndex: weekData.weekIndex,
561
584
  gridRowIndex: weekData.gridRowIndex,
562
585
  }),
@@ -577,32 +600,41 @@ function WeekInstance<F extends ValueFormat = ValueFormat>(props: WeekTemplatePr
577
600
  * Iterates over the weeks in the current month and renders one `<tr>` per week.
578
601
  * Each instance receives its week's days and index via {@link WeekDataContext}.
579
602
  */
580
- export function WeekTemplate<F extends ValueFormat = ValueFormat>(props: WeekTemplateProps<F>) {
603
+ export function WeekTemplate(props: WeekTemplateProps) {
581
604
  const outerWeekData = useContext(WeekDataContext);
582
605
  const gridMonthCtx = useContext(GridMonthContext);
583
606
  const { weeks: defaultWeeks } = useMonthViewState();
584
607
  const weeks = gridMonthCtx?.weeks ?? defaultWeeks;
585
608
  const gridMonth = useMemo(
586
- () => (gridMonthCtx ? { year: gridMonthCtx.year, month: gridMonthCtx.month } : undefined),
609
+ () =>
610
+ gridMonthCtx
611
+ ? { year: gridMonthCtx.year, month: gridMonthCtx.month }
612
+ : undefined,
587
613
  [gridMonthCtx],
588
614
  );
589
- const Instance = WeekInstance<F>;
615
+ const Instance = WeekInstance;
590
616
 
591
617
  return (
592
618
  <>
593
- {weeks.map((weekDays, i) => (
594
- <WeekDataContext.Provider
595
- key={weekDays[0].toString()}
596
- value={{
597
- days: weekDays,
598
- weekIndex: i,
599
- gridMonth,
600
- gridRowIndex: outerWeekData?.gridRowIndex,
601
- }}
602
- >
603
- <Instance {...props} />
604
- </WeekDataContext.Provider>
605
- ))}
619
+ {weeks.map((weekDays, i) => {
620
+ const firstDay = weekDays[0];
621
+ if (firstDay === undefined) return null;
622
+ return (
623
+ <WeekDataContext.Provider
624
+ key={firstDay.toString()}
625
+ value={{
626
+ days: weekDays,
627
+ weekIndex: i,
628
+ ...(gridMonth !== undefined && { gridMonth }),
629
+ ...(outerWeekData?.gridRowIndex !== undefined && {
630
+ gridRowIndex: outerWeekData.gridRowIndex,
631
+ }),
632
+ }}
633
+ >
634
+ <Instance {...props} />
635
+ </WeekDataContext.Provider>
636
+ );
637
+ })}
606
638
  </>
607
639
  );
608
640
  }
package/src/index.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  export { CalendarProvider } from "./calendar-provider";
2
2
  export { MonthView, MonthViewRoot } from "./month-view";
3
- export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton } from "./grid";
3
+ export {
4
+ Grid,
5
+ GridBody,
6
+ WeekTemplate,
7
+ DayCellTemplate,
8
+ DayButton,
9
+ } from "./grid";
4
10
  export { GridHeader, GridHeaderCell } from "./grid-header";
5
11
  export {
6
12
  DateString,
@@ -14,7 +20,11 @@ export { RangePreview } from "./range-preview";
14
20
  export { RangeStartDragHandle, RangeEndDragHandle } from "./drag-handle";
15
21
  export { WeekNumberCell, WeekNumberHeader } from "./week-number";
16
22
  export { WeeksView, WeeksViewRoot } from "./weeks-view";
17
- export { PrevWeeksButton, NextWeeksButton, WeekCount } from "./weeks-navigation";
23
+ export {
24
+ PrevWeeksButton,
25
+ NextWeeksButton,
26
+ WeekCount,
27
+ } from "./weeks-navigation";
18
28
  export {
19
29
  MonthSeparator,
20
30
  MonthSeparatorRow,
@@ -26,7 +36,6 @@ export {
26
36
  export { computePreviewRange } from "./root-selection";
27
37
  export { computeWeeksInWindow } from "./compute-weeks-in-window";
28
38
  export { resolveFirstWeek, resolveFirstWeekSpec } from "./resolve-first-week";
29
- export { Temporal } from "./temporal-polyfill";
30
39
  export { useCalendarStable, useCalendarState } from "./calendar-context";
31
40
  export { useMonthViewStable, useMonthViewState } from "./month-view-context";
32
41
  export { useViewContext } from "./view-context";
@@ -84,7 +93,10 @@ export type {
84
93
  } from "./types";
85
94
 
86
95
  export type { CalendarProviderProps } from "./calendar-types";
87
- export type { CalendarStableContextValue, CalendarStateContextValue } from "./calendar-types";
96
+ export type {
97
+ CalendarStableContextValue,
98
+ CalendarStateContextValue,
99
+ } from "./calendar-types";
88
100
  export type {
89
101
  MonthViewRootProps,
90
102
  MonthViewStableContextValue,