@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
@@ -22,25 +22,21 @@ function useCalendarState() {
22
22
  //#endregion
23
23
  //#region src/utils.ts
24
24
  /**
25
- * Returns the default calendar system for a given locale (e.g. `"gregory"` for `"en-US"`).
26
- *
27
- * @param locale - A BCP 47 locale string. Falls back to the runtime default when empty.
28
- */
29
- function calendarForLocale(locale) {
30
- return new Intl.DateTimeFormat(locale || void 0).resolvedOptions().calendar;
31
- }
32
- /**
33
25
  * Resolves a {@link TemporalNamespace} instance.
34
26
  *
35
- * Returns `provided` when given, otherwise checks `globalThis.Temporal`.
36
- * Throws if neither is available.
27
+ * Returns `provided` when given, otherwise native `globalThis.Temporal`. This
28
+ * library does not bundle a `Temporal` implementation — if neither is
29
+ * available, it throws. Provide one via the `temporal` prop, e.g. the
30
+ * `Temporal` export from `temporal-polyfill`
31
+ * (https://github.com/fullcalendar/temporal-polyfill) or `@js-temporal/polyfill`
32
+ * (https://github.com/js-temporal/temporal-polyfill).
37
33
  *
38
34
  * @param provided - An explicit Temporal polyfill or namespace.
39
35
  */
40
36
  function resolveTemporal(provided) {
41
37
  if (provided) return provided;
42
38
  if (typeof globalThis !== "undefined" && globalThis.Temporal) return globalThis.Temporal;
43
- throw new Error("DatePicker: Temporal is not available. Pass a Temporal polyfill via the `temporal` prop, or use a browser that supports the Temporal API natively.");
39
+ throw new Error("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.");
44
40
  }
45
41
  /**
46
42
  * Returns the IANA time zone identifier of the host environment (e.g. `"America/New_York"`).
@@ -261,6 +257,40 @@ function computeAdjacentMonth(current, direction, T) {
261
257
  };
262
258
  }
263
259
  /**
260
+ * Computes the new first-visible month after the **minimum** shift needed to
261
+ * bring `focused` into a window of `numberOfMonths` months that currently
262
+ * starts at `start`.
263
+ *
264
+ * - Already visible → returns `start` unchanged (by value).
265
+ * - Before the window → `focused` becomes the first (leftmost) pane.
266
+ * - After the window → `focused` becomes the last (rightmost) pane.
267
+ *
268
+ * This keeps keyboard focus-crossing symmetric with single-month stepping: a
269
+ * Gregorian-style window only ever scrolls as far as it must, never jumping
270
+ * the focused month to the leftmost slot. Pure month arithmetic — calendar
271
+ * agnostic, since `{year, month}` indices are computed by the caller.
272
+ *
273
+ * @param start - The current first-visible month.
274
+ * @param focused - The month that must become visible.
275
+ * @param numberOfMonths - Number of month panes displayed (>= 1).
276
+ */
277
+ function shiftWindowToMonth(start, focused, numberOfMonths) {
278
+ const startIndex = start.year * 12 + (start.month - 1);
279
+ const focusedIndex = focused.year * 12 + (focused.month - 1);
280
+ if (focusedIndex < startIndex) return {
281
+ year: focused.year,
282
+ month: focused.month
283
+ };
284
+ if (focusedIndex > startIndex + numberOfMonths - 1) {
285
+ const newStartIndex = focusedIndex - (numberOfMonths - 1);
286
+ return {
287
+ year: Math.floor(newStartIndex / 12),
288
+ month: newStartIndex % 12 + 1
289
+ };
290
+ }
291
+ return start;
292
+ }
293
+ /**
264
294
  * Determines the focused date after navigating to a new month.
265
295
  *
266
296
  * If `currentFocused` is already within `targetMonth`, it is preserved.
@@ -280,7 +310,8 @@ function focusedDateForMonth(currentFocused, targetMonth, firstDay) {
280
310
  * Priority when `gridHasFocus` is `true` (keyboard navigation):
281
311
  * 1. `focusedDate` if it exists in the grid.
282
312
  * 2. `selectedDate` if it exists in the grid.
283
- * 3. First enabled day of `currentMonth`, or first grid day as last resort.
313
+ * 3. First enabled day of `currentMonth`, then first grid day, then
314
+ * `focusedDate` itself (empty grid) as last resorts.
284
315
  *
285
316
  * When `gridHasFocus` is `false` (tab-in), `selectedDate` takes priority
286
317
  * over `focusedDate`.
@@ -299,7 +330,7 @@ function resolveFocusTarget(focusedDate, selectedDate, weeks, currentMonth, isDa
299
330
  if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
300
331
  if (selectedDate && inGrid(selectedDate)) return selectedDate;
301
332
  if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
302
- return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0];
333
+ return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0] ?? focusedDate;
303
334
  }
304
335
  /**
305
336
  * Determines whether a day cell should imperatively receive DOM focus.
@@ -333,6 +364,13 @@ function isInRange(date, rangeStart, rangeEnd, T) {
333
364
  if (totalDays === 0) return 0;
334
365
  return date.since(effectiveStart).days / totalDays;
335
366
  }
367
+ const INACTIVE_RANGE_INFO = {
368
+ active: false,
369
+ startIndex: -1,
370
+ endIndex: -1,
371
+ extendsBefore: false,
372
+ extendsAfter: false
373
+ };
336
374
  /**
337
375
  * Computes how a date range intersects with a single calendar week row.
338
376
  *
@@ -347,31 +385,24 @@ function isInRange(date, rangeStart, rangeEnd, T) {
347
385
  * `extendsBefore` / `extendsAfter` (whether the range continues beyond the week).
348
386
  */
349
387
  function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
350
- const inactive = {
351
- active: false,
352
- startIndex: 0,
353
- endIndex: 0,
354
- extendsBefore: false,
355
- extendsAfter: false
356
- };
357
- if (weekDays.length === 0) return inactive;
358
- if (!rangeStart && !rangeEnd) return inactive;
359
- const effectiveStart = rangeStart ?? rangeEnd;
360
- const effectiveEnd = rangeEnd ?? rangeStart;
388
+ if (!rangeStart && !rangeEnd) return INACTIVE_RANGE_INFO;
361
389
  const weekStart = weekDays[0];
362
390
  const weekEnd = weekDays[weekDays.length - 1];
363
- if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return inactive;
391
+ if (!weekStart || !weekEnd) return INACTIVE_RANGE_INFO;
392
+ const effectiveStart = rangeStart ?? rangeEnd;
393
+ const effectiveEnd = rangeEnd ?? rangeStart;
394
+ if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return INACTIVE_RANGE_INFO;
364
395
  const extendsBefore = T.PlainDate.compare(effectiveStart, weekStart) < 0;
365
396
  const extendsAfter = T.PlainDate.compare(effectiveEnd, weekEnd) > 0;
366
397
  let startIndex = 0;
367
398
  if (!extendsBefore) {
368
399
  startIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveStart) === 0);
369
- if (startIndex === -1) return inactive;
400
+ if (startIndex === -1) return INACTIVE_RANGE_INFO;
370
401
  }
371
402
  let endIndex = weekDays.length - 1;
372
403
  if (!extendsAfter) {
373
404
  endIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveEnd) === 0);
374
- if (endIndex === -1) return inactive;
405
+ if (endIndex === -1) return INACTIVE_RANGE_INFO;
375
406
  }
376
407
  return {
377
408
  active: true,
@@ -387,7 +418,9 @@ function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
387
418
  * @param locale - BCP 47 locale string (e.g. `"en-US"`).
388
419
  * @param T - Temporal namespace.
389
420
  * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
390
- * @returns An array of 7 objects with `long`, `short`, and `narrow` name variants.
421
+ * @returns An array of objects with `long`, `short`, and `narrow` name variants,
422
+ * one per day in the calendar's week (typically 7, but may differ for
423
+ * non-Gregorian calendars).
391
424
  */
392
425
  function getWeekdayNames(locale, T, weekStartDay = 0) {
393
426
  const refStart = getReferenceWeekStart(T, weekStartDay);
@@ -529,8 +562,8 @@ function computeSelectionUpdate(opts) {
529
562
  if (isComplete) {
530
563
  const start = committedDates[0];
531
564
  const end = committedDates[1];
532
- const isOnStart = T.PlainDate.compare(date, start) === 0;
533
- const isOnEnd = T.PlainDate.compare(date, end) === 0;
565
+ const isOnStart = start != null && T.PlainDate.compare(date, start) === 0;
566
+ const isOnEnd = end != null && T.PlainDate.compare(date, end) === 0;
534
567
  if (isOnStart || isOnEnd) return {
535
568
  newDates: [],
536
569
  fireCallback: (onValueChange) => {
@@ -579,19 +612,31 @@ function computeSelectionUpdate(opts) {
579
612
  }
580
613
  const beforeStart = T.PlainDate.compare(date, committedStart) < 0;
581
614
  const afterEnd = T.PlainDate.compare(date, committedEnd) > 0;
582
- let newDates;
583
- if (beforeStart) newDates = [date, committedEnd];
584
- else if (afterEnd) newDates = [committedStart, date];
585
- else {
615
+ let newStart;
616
+ let newEnd;
617
+ if (beforeStart) {
618
+ newStart = date;
619
+ newEnd = committedEnd;
620
+ } else if (afterEnd) {
621
+ newStart = committedStart;
622
+ newEnd = date;
623
+ } else {
586
624
  const action = resolveInsideAction(rangeMode, date, committedStart, committedEnd);
587
- if (action === "start") newDates = [date, committedEnd];
588
- else if (action === "end") newDates = [committedStart, date];
589
- else newDates = [date, date];
625
+ if (action === "start") {
626
+ newStart = date;
627
+ newEnd = committedEnd;
628
+ } else if (action === "end") {
629
+ newStart = committedStart;
630
+ newEnd = date;
631
+ } else {
632
+ newStart = date;
633
+ newEnd = date;
634
+ }
590
635
  }
591
636
  return {
592
- newDates,
637
+ newDates: [newStart, newEnd],
593
638
  fireCallback: (onValueChange, plainToFormatValue) => {
594
- onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
639
+ onValueChange?.(mkRange(plainToFormatValue(newStart), plainToFormatValue(newEnd)), {
595
640
  date,
596
641
  previous: prevRange
597
642
  });
@@ -600,11 +645,10 @@ function computeSelectionUpdate(opts) {
600
645
  }
601
646
  if (isRange) {
602
647
  const prevRange = currentRangeFormatted();
603
- const newDates = [date, date];
604
648
  return {
605
- newDates,
649
+ newDates: [date, date],
606
650
  fireCallback: (onValueChange, plainToFormatValue) => {
607
- onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
651
+ onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(date)), {
608
652
  date,
609
653
  previous: prevRange
610
654
  });
@@ -1128,9 +1172,9 @@ function CalendarProvider(props) {
1128
1172
  selectionMode,
1129
1173
  disabled,
1130
1174
  readOnly,
1131
- isDateDisabled,
1132
- minValue,
1133
- maxValue,
1175
+ ...isDateDisabled !== void 0 && { isDateDisabled },
1176
+ ...minValue !== void 0 && { minValue },
1177
+ ...maxValue !== void 0 && { maxValue },
1134
1178
  timeZone,
1135
1179
  locale,
1136
1180
  temporal: T,
@@ -1157,6 +1201,23 @@ function CalendarProvider(props) {
1157
1201
  resolvedFormat,
1158
1202
  setHoveredDate
1159
1203
  ]);
1204
+ const baseRootState = useMemo(() => ({
1205
+ hasSelection: nonNullDates.length > 0,
1206
+ selected: nonNullDates[0],
1207
+ selectedDates: nonNullDates,
1208
+ rangeStart,
1209
+ rangeEnd,
1210
+ timeZone,
1211
+ locale,
1212
+ readOnly
1213
+ }), [
1214
+ nonNullDates,
1215
+ rangeStart,
1216
+ rangeEnd,
1217
+ timeZone,
1218
+ locale,
1219
+ readOnly
1220
+ ]);
1160
1221
  const stateCtx = useMemo(() => ({
1161
1222
  selected,
1162
1223
  selectedDates: nonNullDates,
@@ -1164,7 +1225,8 @@ function CalendarProvider(props) {
1164
1225
  rangeEnd,
1165
1226
  hoveredDate,
1166
1227
  previewStart,
1167
- previewEnd
1228
+ previewEnd,
1229
+ baseRootState
1168
1230
  }), [
1169
1231
  selected,
1170
1232
  nonNullDates,
@@ -1172,7 +1234,8 @@ function CalendarProvider(props) {
1172
1234
  rangeEnd,
1173
1235
  hoveredDate,
1174
1236
  previewStart,
1175
- previewEnd
1237
+ previewEnd,
1238
+ baseRootState
1176
1239
  ]);
1177
1240
  return /* @__PURE__ */ jsx(CalendarStableContext.Provider, {
1178
1241
  value: stableCtx,
@@ -1221,7 +1284,7 @@ function MonthViewRoot(props) {
1221
1284
  const calStable = useCalendarStable();
1222
1285
  const calState = useCalendarState();
1223
1286
  const T = calStable.temporal;
1224
- const { timeZone, locale, weekStartDay, isDateDisabled } = calStable;
1287
+ const { timeZone, weekStartDay, isDateDisabled } = calStable;
1225
1288
  const isMonthControlled = monthProp !== void 0;
1226
1289
  const [internalMonth, setInternalMonth] = useState(() => {
1227
1290
  if (monthProp) return {
@@ -1271,34 +1334,87 @@ function MonthViewRoot(props) {
1271
1334
  };
1272
1335
  });
1273
1336
  }, []);
1337
+ const onMonthChangeRef = useRef(onMonthChange);
1338
+ onMonthChangeRef.current = onMonthChange;
1339
+ const notifyMonth = useCallback((year, month) => {
1340
+ onMonthChangeRef.current?.(T.PlainYearMonth.from({
1341
+ year,
1342
+ month
1343
+ }));
1344
+ }, [T]);
1345
+ const isMonthVisible = useCallback((targetYear, targetMonth) => {
1346
+ for (let i = 0; i < numberOfMonths; i++) {
1347
+ const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1348
+ const y = Math.floor(totalMonths / 12);
1349
+ const m = totalMonths % 12 + 1;
1350
+ if (targetYear === y && targetMonth === m) return true;
1351
+ }
1352
+ return false;
1353
+ }, [
1354
+ currentMonth.year,
1355
+ currentMonth.month,
1356
+ numberOfMonths
1357
+ ]);
1274
1358
  const navigateToMonth = useCallback((targetYear, targetMonth) => {
1275
1359
  if (isMonthControlled) return;
1276
1360
  setInternalMonth((prev) => {
1277
- for (let i = 0; i < numberOfMonths; i++) {
1278
- const totalMonths = prev.year * 12 + (prev.month - 1) + i;
1279
- const y = Math.floor(totalMonths / 12);
1280
- const m = totalMonths % 12 + 1;
1281
- if (targetYear === y && targetMonth === m) return prev;
1282
- }
1283
- return {
1361
+ const next = shiftWindowToMonth(prev, {
1284
1362
  year: targetYear,
1285
1363
  month: targetMonth
1286
- };
1364
+ }, numberOfMonths);
1365
+ if (next.year === prev.year && next.month === prev.month) return prev;
1366
+ return next;
1287
1367
  });
1288
1368
  }, [isMonthControlled, numberOfMonths]);
1369
+ const skipFocusSyncForRef = useRef(null);
1370
+ const prevFocusedRef = useRef(focusedDate);
1371
+ useEffect(() => {
1372
+ skipFocusSyncForRef.current = null;
1373
+ }, [monthProp?.year, monthProp?.month]);
1289
1374
  useEffect(() => {
1375
+ const prevFocused = prevFocusedRef.current;
1376
+ prevFocusedRef.current = focusedDate;
1377
+ if (isMonthControlled) {
1378
+ if (skipFocusSyncForRef.current === focusedDate) {
1379
+ skipFocusSyncForRef.current = null;
1380
+ return;
1381
+ }
1382
+ if (prevFocused === focusedDate) return;
1383
+ if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
1384
+ const next = shiftWindowToMonth({
1385
+ year: currentMonth.year,
1386
+ month: currentMonth.month
1387
+ }, {
1388
+ year: focusedDate.year,
1389
+ month: focusedDate.month
1390
+ }, numberOfMonths);
1391
+ notifyMonth(next.year, next.month);
1392
+ return;
1393
+ }
1290
1394
  navigateToMonth(focusedDate.year, focusedDate.month);
1291
- }, [focusedDate, navigateToMonth]);
1395
+ }, [
1396
+ focusedDate,
1397
+ navigateToMonth,
1398
+ isMonthControlled,
1399
+ isMonthVisible,
1400
+ notifyMonth,
1401
+ currentMonth.year,
1402
+ currentMonth.month,
1403
+ numberOfMonths
1404
+ ]);
1292
1405
  const goNextMonth = useCallback(() => {
1293
1406
  if (isMonthControlled) {
1294
1407
  const { year, month, firstDay } = computeAdjacentMonth({
1295
1408
  year: monthProp.year,
1296
1409
  month: monthProp.month
1297
1410
  }, "next", T);
1298
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1411
+ const nextFocus = focusedDateForMonth(focusedDate, {
1299
1412
  year,
1300
1413
  month
1301
- }, firstDay));
1414
+ }, firstDay);
1415
+ skipFocusSyncForRef.current = nextFocus;
1416
+ notifyMonth(year, month);
1417
+ setFocusedDate(nextFocus);
1302
1418
  return;
1303
1419
  }
1304
1420
  setInternalMonth((m) => {
@@ -1315,7 +1431,9 @@ function MonthViewRoot(props) {
1315
1431
  }, [
1316
1432
  T,
1317
1433
  isMonthControlled,
1318
- monthProp
1434
+ monthProp,
1435
+ notifyMonth,
1436
+ focusedDate
1319
1437
  ]);
1320
1438
  const goPrevMonth = useCallback(() => {
1321
1439
  if (isMonthControlled) {
@@ -1323,10 +1441,13 @@ function MonthViewRoot(props) {
1323
1441
  year: monthProp.year,
1324
1442
  month: monthProp.month
1325
1443
  }, "prev", T);
1326
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1444
+ const nextFocus = focusedDateForMonth(focusedDate, {
1327
1445
  year,
1328
1446
  month
1329
- }, firstDay));
1447
+ }, firstDay);
1448
+ skipFocusSyncForRef.current = nextFocus;
1449
+ notifyMonth(year, month);
1450
+ setFocusedDate(nextFocus);
1330
1451
  return;
1331
1452
  }
1332
1453
  setInternalMonth((m) => {
@@ -1343,7 +1464,9 @@ function MonthViewRoot(props) {
1343
1464
  }, [
1344
1465
  T,
1345
1466
  isMonthControlled,
1346
- monthProp
1467
+ monthProp,
1468
+ notifyMonth,
1469
+ focusedDate
1347
1470
  ]);
1348
1471
  const allMonths = useMemo(() => {
1349
1472
  const opts = {
@@ -1370,7 +1493,9 @@ function MonthViewRoot(props) {
1370
1493
  fixedWeeks,
1371
1494
  numberOfMonths
1372
1495
  ]);
1373
- const weeks = allMonths[0].weeks;
1496
+ const firstMonth = allMonths[0];
1497
+ if (firstMonth === void 0) throw new Error("MonthView: numberOfMonths must be at least 1.");
1498
+ const weeks = firstMonth.weeks;
1374
1499
  const selectedZdt = useMemo(() => selectedToZdt(calState.selected, timeZone, T), [
1375
1500
  calState.selected,
1376
1501
  timeZone,
@@ -1402,48 +1527,27 @@ function MonthViewRoot(props) {
1402
1527
  T,
1403
1528
  gridHasFocus
1404
1529
  ]);
1405
- const localeCalendar = useMemo(() => calendarForLocale(locale), [locale]);
1406
1530
  const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
1407
1531
  year: currentMonth.year,
1408
- month: currentMonth.month,
1409
- calendar: localeCalendar
1410
- }), [
1411
- currentMonth,
1412
- T,
1413
- localeCalendar
1414
- ]);
1415
- const onMonthChangeRef = useRef(onMonthChange);
1416
- onMonthChangeRef.current = onMonthChange;
1532
+ month: currentMonth.month
1533
+ }), [currentMonth, T]);
1417
1534
  const mountedRef = useRef(false);
1418
1535
  useEffect(() => {
1419
1536
  if (!mountedRef.current) {
1420
1537
  mountedRef.current = true;
1421
1538
  return;
1422
1539
  }
1540
+ if (isMonthControlled) return;
1423
1541
  onMonthChangeRef.current?.(viewingYearMonth);
1424
- }, [viewingYearMonth]);
1425
- const { selected, selectedDates, rangeStart, rangeEnd } = calState;
1542
+ }, [viewingYearMonth, isMonthControlled]);
1426
1543
  const rootState = useMemo(() => ({
1427
- hasSelection: selectedDates.length > 0,
1428
- selected: selected?.value,
1429
- selectedDates,
1430
- rangeStart,
1431
- rangeEnd,
1544
+ ...calState.baseRootState,
1432
1545
  focused: focusedDate,
1433
- viewing: viewingYearMonth,
1434
- timeZone,
1435
- locale,
1436
- readOnly: calStable.readOnly
1546
+ viewing: viewingYearMonth
1437
1547
  }), [
1438
- selectedDates,
1439
- selected,
1440
- rangeStart,
1441
- rangeEnd,
1548
+ calState.baseRootState,
1442
1549
  focusedDate,
1443
- viewingYearMonth,
1444
- timeZone,
1445
- locale,
1446
- calStable.readOnly
1550
+ viewingYearMonth
1447
1551
  ]);
1448
1552
  const stableCtx = useMemo(() => ({
1449
1553
  numberOfMonths,
@@ -1538,13 +1642,17 @@ function useGridHeaderCellState(index) {
1538
1642
  T,
1539
1643
  weekStartDay
1540
1644
  ]);
1541
- const state = useMemo(() => ({
1542
- root: rootState,
1543
- dayOfWeek: index,
1544
- long: weekdayNames[index].long,
1545
- short: weekdayNames[index].short,
1546
- narrow: weekdayNames[index].narrow
1547
- }), [
1645
+ const state = useMemo(() => {
1646
+ const names = weekdayNames[index];
1647
+ if (names === void 0) throw new Error(`GridHeaderCell: index must be between 0 and ${weekdayNames.length - 1}, got ${index}.`);
1648
+ return {
1649
+ root: rootState,
1650
+ dayOfWeek: index,
1651
+ long: names.long,
1652
+ short: names.short,
1653
+ narrow: names.narrow
1654
+ };
1655
+ }, [
1548
1656
  rootState,
1549
1657
  index,
1550
1658
  weekdayNames
@@ -1894,8 +2002,7 @@ function WeeksGrid(props) {
1894
2002
  const monthBoundaries = useMemo(() => {
1895
2003
  const boundaries = [];
1896
2004
  const seenMonths = /* @__PURE__ */ new Set();
1897
- for (let i = 0; i < weeks.length; i++) {
1898
- const days = weekDaysArrays[i];
2005
+ for (const [i, days] of weekDaysArrays.entries()) {
1899
2006
  const isFirstWeek = i === 0;
1900
2007
  const monthsInWeek = [];
1901
2008
  for (const day of days) {
@@ -1919,12 +2026,21 @@ function WeeksGrid(props) {
1919
2026
  const windowEnd = weekDaysArrays[weekDaysArrays.length - 1]?.[6];
1920
2027
  const firstDayVisible = windowStart && windowEnd ? T.PlainDate.compare(firstOfMonth, windowStart) >= 0 && T.PlainDate.compare(firstOfMonth, windowEnd) <= 0 : false;
1921
2028
  let weeksVisibleBefore = 0;
1922
- for (let j = i - 1; j >= 0; j--) if (!weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
1923
- else break;
2029
+ for (let j = i - 1; j >= 0; j--) {
2030
+ const prevDays = weekDaysArrays[j];
2031
+ if (prevDays === void 0) break;
2032
+ if (!prevDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
2033
+ else break;
2034
+ }
1924
2035
  let weeksVisibleAfter = 0;
1925
- for (let j = i; j < weeks.length; j++) if (weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
1926
- else break;
1927
- const isNewYear = boundaries.length > 0 ? boundaries[boundaries.length - 1].data.year !== newYear : newMonth === 1;
2036
+ for (let j = i; j < weekDaysArrays.length; j++) {
2037
+ const wDays = weekDaysArrays[j];
2038
+ if (wDays === void 0) break;
2039
+ if (wDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
2040
+ else break;
2041
+ }
2042
+ const lastBoundary = boundaries[boundaries.length - 1];
2043
+ const isNewYear = lastBoundary !== void 0 ? lastBoundary.data.year !== newYear : newMonth === 1;
1928
2044
  boundaries.push({
1929
2045
  index: i,
1930
2046
  data: {
@@ -1943,9 +2059,9 @@ function WeeksGrid(props) {
1943
2059
  });
1944
2060
  }
1945
2061
  }
1946
- for (let b = 0; b < boundaries.length; b++) {
1947
- const current = boundaries[b];
1948
- const nextIndex = b + 1 < boundaries.length ? boundaries[b + 1].index : weeks.length;
2062
+ for (const [b, current] of boundaries.entries()) {
2063
+ const next = boundaries[b + 1];
2064
+ const nextIndex = next !== void 0 ? next.index : weeks.length;
1949
2065
  current.data.fullWeeksVisibleAfter = nextIndex - current.index;
1950
2066
  current.data.gridRowStart = current.index + 2;
1951
2067
  }
@@ -1968,9 +2084,9 @@ function WeeksGrid(props) {
1968
2084
  return map;
1969
2085
  }, [monthBoundaries]);
1970
2086
  const rows = [];
1971
- for (let i = 0; i < weeks.length; i++) {
1972
- const week = weeks[i];
2087
+ for (const [i, week] of weeks.entries()) {
1973
2088
  const days = weekDaysArrays[i];
2089
+ if (days === void 0) continue;
1974
2090
  const separators = boundariesAtIndex.get(i);
1975
2091
  if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ jsx(MonthSeparatorDataContext.Provider, {
1976
2092
  value: separatorData,
@@ -2432,7 +2548,7 @@ function useGridKeyboard() {
2432
2548
  maxValue,
2433
2549
  disabled,
2434
2550
  readOnly,
2435
- isDateDisabled,
2551
+ ...isDateDisabled !== void 0 && { isDateDisabled },
2436
2552
  T,
2437
2553
  weekStartDay
2438
2554
  });
@@ -2472,7 +2588,7 @@ function useWeeksGridKeyboard() {
2472
2588
  maxValue,
2473
2589
  disabled,
2474
2590
  readOnly,
2475
- isDateDisabled,
2591
+ ...isDateDisabled !== void 0 && { isDateDisabled },
2476
2592
  scrollBy: weeksStable.scrollBy,
2477
2593
  T,
2478
2594
  weekStartDay
@@ -2726,8 +2842,12 @@ function WeeksViewGridFn(props, ref) {
2726
2842
  allMonths: [],
2727
2843
  currentDateTime,
2728
2844
  gridLabelIds,
2729
- rootState: {}
2730
- }), [currentDateTime, gridLabelIds]);
2845
+ rootState: weeksState.rootState
2846
+ }), [
2847
+ currentDateTime,
2848
+ gridLabelIds,
2849
+ weeksState.rootState
2850
+ ]);
2731
2851
  return /* @__PURE__ */ jsx(MonthViewStableContext.Provider, {
2732
2852
  value: monthViewStableShim,
2733
2853
  children: /* @__PURE__ */ jsx(MonthViewStateContext.Provider, {
@@ -2813,15 +2933,19 @@ function WeekTemplate(props) {
2813
2933
  month: gridMonthCtx.month
2814
2934
  } : void 0, [gridMonthCtx]);
2815
2935
  const Instance = WeekInstance;
2816
- return /* @__PURE__ */ jsx(Fragment, { children: weeks.map((weekDays, i) => /* @__PURE__ */ jsx(WeekDataContext.Provider, {
2817
- value: {
2818
- days: weekDays,
2819
- weekIndex: i,
2820
- gridMonth,
2821
- gridRowIndex: outerWeekData?.gridRowIndex
2822
- },
2823
- children: /* @__PURE__ */ jsx(Instance, { ...props })
2824
- }, weekDays[0].toString())) });
2936
+ return /* @__PURE__ */ jsx(Fragment, { children: weeks.map((weekDays, i) => {
2937
+ const firstDay = weekDays[0];
2938
+ if (firstDay === void 0) return null;
2939
+ return /* @__PURE__ */ jsx(WeekDataContext.Provider, {
2940
+ value: {
2941
+ days: weekDays,
2942
+ weekIndex: i,
2943
+ ...gridMonth !== void 0 && { gridMonth },
2944
+ ...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
2945
+ },
2946
+ children: /* @__PURE__ */ jsx(Instance, { ...props })
2947
+ }, firstDay.toString());
2948
+ }) });
2825
2949
  }
2826
2950
  //#endregion
2827
2951
  //#region src/navigation.tsx
@@ -2929,7 +3053,7 @@ const TimeString = forwardRef(TimeStringFn);
2929
3053
  function MonthYearStringFn(props, ref) {
2930
3054
  const { render, locales, options, monthIndex: monthIndexProp, ...otherProps } = props;
2931
3055
  const monthIndex = monthIndexProp ?? 0;
2932
- const { locale } = useCalendarStable();
3056
+ const { locale, temporal: T } = useCalendarStable();
2933
3057
  const monthViewStable = useMonthViewStable();
2934
3058
  const { currentMonth: currentDateTime, allMonths, rootState } = useMonthViewState();
2935
3059
  const { setGridLabelId } = monthViewStable;
@@ -2945,12 +3069,15 @@ function MonthYearStringFn(props, ref) {
2945
3069
  const monthData = allMonths[monthIndex];
2946
3070
  const displayYear = monthData?.year ?? currentDateTime.year;
2947
3071
  const displayMonth = monthData?.month ?? currentDateTime.month;
2948
- const displayDate = new Date(displayYear, displayMonth - 1, 1);
2949
3072
  const defaultOptions = options ?? {
2950
3073
  month: "long",
2951
3074
  year: "numeric"
2952
3075
  };
2953
- const formatted = displayDate.toLocaleDateString(locales ?? locale, defaultOptions);
3076
+ const formatted = T.PlainDate.from({
3077
+ year: displayYear,
3078
+ month: displayMonth,
3079
+ day: 1
3080
+ }).toLocaleString(locales ?? locale, defaultOptions);
2954
3081
  const state = useMemo(() => ({
2955
3082
  root: rootState,
2956
3083
  month: displayMonth,
@@ -2987,7 +3114,7 @@ function MonthYearStringFn(props, ref) {
2987
3114
  */
2988
3115
  const MonthYearString = forwardRef(MonthYearStringFn);
2989
3116
  function useNavButton(direction) {
2990
- const { disabled: globalDisabled, minValue, maxValue, locale, temporal: T } = useCalendarStable();
3117
+ const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
2991
3118
  const monthViewStable = useMonthViewStable();
2992
3119
  const monthViewState = useMonthViewState();
2993
3120
  const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths } = monthViewStable;
@@ -3008,16 +3135,13 @@ function useNavButton(direction) {
3008
3135
  boundValue,
3009
3136
  direction
3010
3137
  ]);
3011
- const localeCalendar = useMemo(() => calendarForLocale(locale), [locale]);
3012
3138
  const target = useMemo(() => T.PlainYearMonth.from({
3013
3139
  year: destYear,
3014
- month: destMonth,
3015
- calendar: localeCalendar
3140
+ month: destMonth
3016
3141
  }), [
3017
3142
  destYear,
3018
3143
  destMonth,
3019
- T,
3020
- localeCalendar
3144
+ T
3021
3145
  ]);
3022
3146
  return {
3023
3147
  state: useMemo(() => ({
@@ -3099,11 +3223,15 @@ function computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gri
3099
3223
  const raw = computeWeekRangeInfo(days, rangeStart, rangeEnd, T);
3100
3224
  if ((outsideDays === "disabled" || outsideDays === "hidden") && raw.active && gridMonth) {
3101
3225
  let { startIndex, endIndex, extendsBefore, extendsAfter } = raw;
3102
- while (startIndex <= endIndex && (days[startIndex].year !== gridMonth.year || days[startIndex].month !== gridMonth.month)) {
3226
+ const inMonth = (i) => {
3227
+ const day = days[i];
3228
+ return day !== void 0 && day.year === gridMonth.year && day.month === gridMonth.month;
3229
+ };
3230
+ while (startIndex <= endIndex && !inMonth(startIndex)) {
3103
3231
  startIndex++;
3104
3232
  extendsBefore = true;
3105
3233
  }
3106
- while (endIndex >= startIndex && (days[endIndex].year !== gridMonth.year || days[endIndex].month !== gridMonth.month)) {
3234
+ while (endIndex >= startIndex && !inMonth(endIndex)) {
3107
3235
  endIndex--;
3108
3236
  extendsAfter = true;
3109
3237
  }
@@ -3158,8 +3286,8 @@ function RangeSelectedInnerFn(props, ref) {
3158
3286
  outsideDays,
3159
3287
  gridMonth
3160
3288
  ]);
3161
- const startDate = info.active ? days[info.startIndex].toString() : "";
3162
- const endDate = info.active ? days[info.endIndex].toString() : "";
3289
+ const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
3290
+ const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
3163
3291
  const weekIndex = weekData?.weekIndex ?? 0;
3164
3292
  const state = useMemo(() => ({
3165
3293
  root: rootState,
@@ -3233,8 +3361,8 @@ function RangePreviewInnerFn(props, ref) {
3233
3361
  outsideDays,
3234
3362
  gridMonth
3235
3363
  ]);
3236
- const startDate = info.active ? days[info.startIndex].toString() : "";
3237
- const endDate = info.active ? days[info.endIndex].toString() : "";
3364
+ const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
3365
+ const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
3238
3366
  const weekIndex = weekData?.weekIndex ?? 0;
3239
3367
  const state = useMemo(() => ({
3240
3368
  root: rootState,
@@ -3290,7 +3418,7 @@ function useDragHandle(edge, { dragging: draggingProp }) {
3290
3418
  const date = cellData?.date;
3291
3419
  const outsideDisabled = cellData?.outsideDisabled ?? false;
3292
3420
  const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
3293
- const isDragging = (draggingProp ?? false) && isActive;
3421
+ const isDragging = !!draggingProp && isActive;
3294
3422
  const handleRef = useRef(null);
3295
3423
  return {
3296
3424
  state: useMemo(() => ({
@@ -3371,8 +3499,8 @@ function WeekNumberCellFn(props, ref) {
3371
3499
  const { temporal: T } = useCalendarStable();
3372
3500
  const days = weekData?.days ?? [];
3373
3501
  const weekNumber = useMemo(() => {
3374
- if (days.length === 0) return 0;
3375
3502
  let thursday = days[0];
3503
+ if (thursday === void 0) return 0;
3376
3504
  for (const d of days) if (d.dayOfWeek === 4) {
3377
3505
  thursday = d;
3378
3506
  break;
@@ -3676,8 +3804,8 @@ function useWeeksViewRootState(props) {
3676
3804
  targetFirstWeek: resolvedFirstWeek,
3677
3805
  weekCount,
3678
3806
  behavior: overflowBehavior,
3679
- min: minValue,
3680
- max: maxValue,
3807
+ ...minValue !== void 0 && { min: minValue },
3808
+ ...maxValue !== void 0 && { max: maxValue },
3681
3809
  weekStartDay,
3682
3810
  T
3683
3811
  }), [
@@ -3715,7 +3843,9 @@ function useWeeksViewRootState(props) {
3715
3843
  ]);
3716
3844
  const windowInfo = useMemo(() => {
3717
3845
  const weeks = adjustedWeeks;
3718
- if (weeks.length === 0) {
3846
+ const firstWeek = weeks[0];
3847
+ const lastWeek = weeks[weeks.length - 1];
3848
+ if (firstWeek === void 0 || lastWeek === void 0) {
3719
3849
  const today = T.Now.plainDateISO();
3720
3850
  return {
3721
3851
  windowStart: today,
@@ -3727,8 +3857,8 @@ function useWeeksViewRootState(props) {
3727
3857
  visibleMonths: []
3728
3858
  };
3729
3859
  }
3730
- const windowStart = weeks[0].startDate;
3731
- const windowEnd = weeks[weeks.length - 1].endDate;
3860
+ const windowStart = firstWeek.startDate;
3861
+ const windowEnd = lastWeek.endDate;
3732
3862
  const wc = weeks.length;
3733
3863
  const dayCount = wc * 7;
3734
3864
  let enabledDayCount = 0;
@@ -3870,8 +4000,8 @@ function useWeeksViewRootState(props) {
3870
4000
  targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
3871
4001
  weekCount,
3872
4002
  behavior: overflowBehavior,
3873
- min: minValue,
3874
- max: maxValue,
4003
+ ...minValue !== void 0 && { min: minValue },
4004
+ ...maxValue !== void 0 && { max: maxValue },
3875
4005
  weekStartDay,
3876
4006
  T
3877
4007
  }).firstWeek);
@@ -3891,8 +4021,8 @@ function useWeeksViewRootState(props) {
3891
4021
  targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
3892
4022
  weekCount,
3893
4023
  behavior: overflowBehavior,
3894
- min: minValue,
3895
- max: maxValue,
4024
+ ...minValue !== void 0 && { min: minValue },
4025
+ ...maxValue !== void 0 && { max: maxValue },
3896
4026
  weekStartDay,
3897
4027
  T
3898
4028
  }).firstWeek);
@@ -3911,8 +4041,8 @@ function useWeeksViewRootState(props) {
3911
4041
  targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
3912
4042
  weekCount,
3913
4043
  behavior: overflowBehavior,
3914
- min: minValue,
3915
- max: maxValue,
4044
+ ...minValue !== void 0 && { min: minValue },
4045
+ ...maxValue !== void 0 && { max: maxValue },
3916
4046
  weekStartDay,
3917
4047
  T
3918
4048
  }).firstWeek);
@@ -3937,37 +4067,53 @@ function useWeeksViewRootState(props) {
3937
4067
  onWindowChangeRef.current?.(windowInfo);
3938
4068
  }
3939
4069
  }, [windowInfo, T]);
4070
+ const stableCtx = useMemo(() => ({
4071
+ weekCount,
4072
+ scrollBy,
4073
+ overflowBehavior,
4074
+ goNext,
4075
+ goPrev,
4076
+ scrollToWeek,
4077
+ gridFocusedRef,
4078
+ setGridLabelId
4079
+ }), [
4080
+ weekCount,
4081
+ scrollBy,
4082
+ overflowBehavior,
4083
+ goNext,
4084
+ goPrev,
4085
+ scrollToWeek,
4086
+ setGridLabelId
4087
+ ]);
4088
+ const rootState = useMemo(() => ({
4089
+ ...calState.baseRootState,
4090
+ focused: focusedDate,
4091
+ viewing: T.PlainYearMonth.from({
4092
+ year: currentDateTime.year,
4093
+ month: currentDateTime.month
4094
+ })
4095
+ }), [
4096
+ calState.baseRootState,
4097
+ focusedDate,
4098
+ currentDateTime,
4099
+ T
4100
+ ]);
3940
4101
  return {
3941
- stableCtx: useMemo(() => ({
3942
- weekCount,
3943
- scrollBy,
3944
- overflowBehavior,
3945
- goNext,
3946
- goPrev,
3947
- scrollToWeek,
3948
- gridFocusedRef,
3949
- setGridLabelId
3950
- }), [
3951
- weekCount,
3952
- scrollBy,
3953
- overflowBehavior,
3954
- goNext,
3955
- goPrev,
3956
- scrollToWeek,
3957
- setGridLabelId
3958
- ]),
4102
+ stableCtx,
3959
4103
  stateCtx: useMemo(() => ({
3960
4104
  focusedDate,
3961
4105
  windowInfo,
3962
4106
  gridLabelIds,
3963
4107
  weeks: adjustedWeeks,
3964
- currentDateTime
4108
+ currentDateTime,
4109
+ rootState
3965
4110
  }), [
3966
4111
  focusedDate,
3967
4112
  windowInfo,
3968
4113
  gridLabelIds,
3969
4114
  adjustedWeeks,
3970
- currentDateTime
4115
+ currentDateTime,
4116
+ rootState
3971
4117
  ]),
3972
4118
  viewCtx: useMemo(() => ({
3973
4119
  viewType: "weeks",
@@ -4010,8 +4156,12 @@ function WeeksViewRootFn(props, ref) {
4010
4156
  allMonths: [],
4011
4157
  currentDateTime: stateCtx.currentDateTime,
4012
4158
  gridLabelIds: stateCtx.gridLabelIds,
4013
- rootState: {}
4014
- }), [stateCtx.currentDateTime, stateCtx.gridLabelIds]);
4159
+ rootState: stateCtx.rootState
4160
+ }), [
4161
+ stateCtx.currentDateTime,
4162
+ stateCtx.gridLabelIds,
4163
+ stateCtx.rootState
4164
+ ]);
4015
4165
  return /* @__PURE__ */ jsx(MonthViewStableContext.Provider, {
4016
4166
  value: monthViewStableShim,
4017
4167
  children: /* @__PURE__ */ jsx(MonthViewStateContext.Provider, {
@@ -4072,10 +4222,10 @@ function useWeeksNavButton(direction, shiftByProp) {
4072
4222
  currentFirstWeek,
4073
4223
  weekCount,
4074
4224
  direction: direction === "next" ? 1 : -1,
4075
- shiftBy: shiftByProp,
4225
+ ...shiftByProp !== void 0 && { shiftBy: shiftByProp },
4076
4226
  behavior: overflowBehavior,
4077
- min: minValue,
4078
- max: maxValue,
4227
+ ...minValue !== void 0 && { min: minValue },
4228
+ ...maxValue !== void 0 && { max: maxValue },
4079
4229
  weekStartDay,
4080
4230
  T
4081
4231
  });
@@ -4171,386 +4321,4 @@ function WeekCountFn(props, ref) {
4171
4321
  */
4172
4322
  const WeekCount = forwardRef(WeekCountFn);
4173
4323
  //#endregion
4174
- //#region src/temporal-polyfill.ts
4175
- function daysInMonth(year, month) {
4176
- return new Date(year, month, 0).getDate();
4177
- }
4178
- function toUTC(y, m, d) {
4179
- return Date.UTC(y, m - 1, d);
4180
- }
4181
- function isoWeekday(utcDate) {
4182
- const dow = utcDate.getUTCDay();
4183
- return dow === 0 ? 7 : dow;
4184
- }
4185
- function pad2(n) {
4186
- return n < 10 ? `0${n}` : `${n}`;
4187
- }
4188
- function clamp(val, min, max) {
4189
- return val < min ? min : val > max ? max : val;
4190
- }
4191
- function parseDateISO(str) {
4192
- const [datePart] = str.split("T");
4193
- const [y, m, d] = datePart.split("-").map(Number);
4194
- return {
4195
- year: y,
4196
- month: m,
4197
- day: d
4198
- };
4199
- }
4200
- function parseDateTimeISO(str) {
4201
- const [datePart, timePart] = str.split("T");
4202
- const [y, m, d] = datePart.split("-").map(Number);
4203
- if (!timePart) return {
4204
- year: y,
4205
- month: m,
4206
- day: d,
4207
- hour: 0,
4208
- minute: 0,
4209
- second: 0
4210
- };
4211
- const [h, min, s] = timePart.split(":").map(Number);
4212
- return {
4213
- year: y,
4214
- month: m,
4215
- day: d,
4216
- hour: h || 0,
4217
- minute: min || 0,
4218
- second: s || 0
4219
- };
4220
- }
4221
- const dtfCache = /* @__PURE__ */ new Map();
4222
- function getDTF(tz) {
4223
- let dtf = dtfCache.get(tz);
4224
- if (!dtf) {
4225
- dtf = new Intl.DateTimeFormat("en-US", {
4226
- timeZone: tz,
4227
- year: "numeric",
4228
- month: "numeric",
4229
- day: "numeric",
4230
- hour: "numeric",
4231
- minute: "numeric",
4232
- second: "numeric",
4233
- hour12: false
4234
- });
4235
- dtfCache.set(tz, dtf);
4236
- }
4237
- return dtf;
4238
- }
4239
- function extractTzParts(epochMs, tz) {
4240
- const parts = getDTF(tz).formatToParts(new Date(epochMs));
4241
- const vals = {};
4242
- for (const p of parts) if (p.type !== "literal") vals[p.type] = Number(p.value);
4243
- return {
4244
- year: vals.year,
4245
- month: vals.month,
4246
- day: vals.day,
4247
- hour: vals.hour === 24 ? 0 : vals.hour,
4248
- minute: vals.minute,
4249
- second: vals.second
4250
- };
4251
- }
4252
- function wallToEpoch(y, m, d, h, min, s, tz) {
4253
- const utcGuess = Date.UTC(y, m - 1, d, h, min, s);
4254
- const inTz = extractTzParts(utcGuess, tz);
4255
- return utcGuess - (Date.UTC(inTz.year, inTz.month - 1, inTz.day, inTz.hour, inTz.minute, inTz.second) - utcGuess);
4256
- }
4257
- var MiniPlainDate = class MiniPlainDate {
4258
- year;
4259
- month;
4260
- day;
4261
- constructor(year, month, day) {
4262
- this.year = year;
4263
- this.month = month;
4264
- this.day = day;
4265
- }
4266
- get dayOfWeek() {
4267
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4268
- }
4269
- get daysInWeek() {
4270
- return 7;
4271
- }
4272
- get daysInMonth() {
4273
- return daysInMonth(this.year, this.month);
4274
- }
4275
- get monthCode() {
4276
- return `M${pad2(this.month)}`;
4277
- }
4278
- add(dur) {
4279
- let y = this.year + (dur.years || 0);
4280
- let m = this.month + (dur.months || 0);
4281
- while (m > 12) {
4282
- m -= 12;
4283
- y += 1;
4284
- }
4285
- while (m < 1) {
4286
- m += 12;
4287
- y -= 1;
4288
- }
4289
- const d = Math.min(this.day, daysInMonth(y, m));
4290
- const totalDays = (dur.days || 0) + (dur.weeks || 0) * 7;
4291
- if (totalDays === 0) return new MiniPlainDate(y, m, d);
4292
- const epoch = toUTC(y, m, d) + totalDays * 864e5;
4293
- const ud = new Date(epoch);
4294
- return new MiniPlainDate(ud.getUTCFullYear(), ud.getUTCMonth() + 1, ud.getUTCDate());
4295
- }
4296
- subtract(dur) {
4297
- return this.add({
4298
- days: dur.days ? -dur.days : void 0,
4299
- weeks: dur.weeks ? -dur.weeks : void 0,
4300
- months: dur.months ? -dur.months : void 0,
4301
- years: dur.years ? -dur.years : void 0
4302
- });
4303
- }
4304
- since(other, _opts) {
4305
- const thisUTC = toUTC(this.year, this.month, this.day);
4306
- const otherUTC = toUTC(other.year, other.month, other.day);
4307
- return { days: Math.round((thisUTC - otherUTC) / 864e5) };
4308
- }
4309
- until(other, _opts) {
4310
- const thisUTC = toUTC(this.year, this.month, this.day);
4311
- const otherUTC = toUTC(other.year, other.month, other.day);
4312
- return { days: Math.round((otherUTC - thisUTC) / 864e5) };
4313
- }
4314
- equals(other) {
4315
- return this.year === other.year && this.month === other.month && this.day === other.day;
4316
- }
4317
- toString() {
4318
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}`;
4319
- }
4320
- toZonedDateTime(tz) {
4321
- const tzId = typeof tz === "string" ? tz : tz.timeZone;
4322
- return this.toPlainDateTime().toZonedDateTime(tzId);
4323
- }
4324
- toPlainDateTime(timeLike) {
4325
- return new MiniPlainDateTime(this.year, this.month, this.day, timeLike?.hour ?? 0, timeLike?.minute ?? 0, timeLike?.second ?? 0);
4326
- }
4327
- toPlainMonthDay() {
4328
- return new MiniPlainMonthDay(this.month, this.day);
4329
- }
4330
- toPlainYearMonth() {
4331
- return new MiniPlainYearMonth(this.year, this.month);
4332
- }
4333
- toLocaleString(locale, options) {
4334
- return new Date(toUTC(this.year, this.month, this.day)).toLocaleDateString(locale, {
4335
- timeZone: "UTC",
4336
- ...options
4337
- });
4338
- }
4339
- };
4340
- var MiniPlainDateTime = class {
4341
- year;
4342
- month;
4343
- day;
4344
- hour;
4345
- minute;
4346
- second;
4347
- constructor(year, month, day, hour = 0, minute = 0, second = 0) {
4348
- this.year = year;
4349
- this.month = month;
4350
- this.day = day;
4351
- this.hour = hour;
4352
- this.minute = minute;
4353
- this.second = second;
4354
- }
4355
- get dayOfWeek() {
4356
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4357
- }
4358
- get daysInMonth() {
4359
- return daysInMonth(this.year, this.month);
4360
- }
4361
- toZonedDateTime(tz) {
4362
- const tzId = typeof tz === "string" ? tz : tz.timeZone;
4363
- return new MiniZonedDateTime(wallToEpoch(this.year, this.month, this.day, this.hour, this.minute, this.second, tzId), tzId);
4364
- }
4365
- toPlainDate() {
4366
- return new MiniPlainDate(this.year, this.month, this.day);
4367
- }
4368
- toString() {
4369
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}`;
4370
- }
4371
- };
4372
- var MiniPlainMonthDay = class {
4373
- monthCode;
4374
- month;
4375
- day;
4376
- constructor(month, day) {
4377
- this.month = month;
4378
- this.day = day;
4379
- this.monthCode = `M${pad2(month)}`;
4380
- }
4381
- toPlainDate(fields) {
4382
- return new MiniPlainDate(fields.year, this.month, this.day);
4383
- }
4384
- equals(other) {
4385
- return this.month === other.month && this.day === other.day;
4386
- }
4387
- toString() {
4388
- return `${pad2(this.month)}-${pad2(this.day)}`;
4389
- }
4390
- };
4391
- var MiniPlainYearMonth = class MiniPlainYearMonth {
4392
- year;
4393
- month;
4394
- constructor(year, month) {
4395
- this.year = year;
4396
- this.month = month;
4397
- }
4398
- get monthCode() {
4399
- return `M${pad2(this.month)}`;
4400
- }
4401
- get daysInMonth() {
4402
- return daysInMonth(this.year, this.month);
4403
- }
4404
- toPlainDate(fields) {
4405
- return new MiniPlainDate(this.year, this.month, fields.day);
4406
- }
4407
- add(dur) {
4408
- let y = this.year + (dur.years || 0);
4409
- let m = this.month + (dur.months || 0);
4410
- while (m > 12) {
4411
- m -= 12;
4412
- y += 1;
4413
- }
4414
- while (m < 1) {
4415
- m += 12;
4416
- y -= 1;
4417
- }
4418
- return new MiniPlainYearMonth(y, m);
4419
- }
4420
- subtract(dur) {
4421
- return this.add({
4422
- months: dur.months ? -dur.months : void 0,
4423
- years: dur.years ? -dur.years : void 0
4424
- });
4425
- }
4426
- equals(other) {
4427
- return this.year === other.year && this.month === other.month;
4428
- }
4429
- toString() {
4430
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}`;
4431
- }
4432
- };
4433
- var MiniZonedDateTime = class {
4434
- epochMilliseconds;
4435
- timeZoneId;
4436
- _parts;
4437
- constructor(epochMs, timeZoneId) {
4438
- this.epochMilliseconds = epochMs;
4439
- this.timeZoneId = timeZoneId;
4440
- }
4441
- get parts() {
4442
- if (!this._parts) this._parts = extractTzParts(this.epochMilliseconds, this.timeZoneId);
4443
- return this._parts;
4444
- }
4445
- get year() {
4446
- return this.parts.year;
4447
- }
4448
- get month() {
4449
- return this.parts.month;
4450
- }
4451
- get day() {
4452
- return this.parts.day;
4453
- }
4454
- get hour() {
4455
- return this.parts.hour;
4456
- }
4457
- get minute() {
4458
- return this.parts.minute;
4459
- }
4460
- get second() {
4461
- return this.parts.second;
4462
- }
4463
- get dayOfWeek() {
4464
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4465
- }
4466
- toPlainDate() {
4467
- return new MiniPlainDate(this.year, this.month, this.day);
4468
- }
4469
- toPlainDateTime() {
4470
- return new MiniPlainDateTime(this.year, this.month, this.day, this.hour, this.minute, this.second);
4471
- }
4472
- toPlainTime() {
4473
- return {
4474
- hour: this.hour,
4475
- minute: this.minute,
4476
- second: this.second
4477
- };
4478
- }
4479
- toPlainYearMonth() {
4480
- return new MiniPlainYearMonth(this.year, this.month);
4481
- }
4482
- toString() {
4483
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}[${this.timeZoneId}]`;
4484
- }
4485
- };
4486
- const PlainDate = {
4487
- from(item, options) {
4488
- if (typeof item === "string") {
4489
- const { year, month, day } = parseDateISO(item);
4490
- if (options?.overflow === "constrain") return new MiniPlainDate(year, month, clamp(day, 1, daysInMonth(year, month)));
4491
- return new MiniPlainDate(year, month, day);
4492
- }
4493
- const year = item.year;
4494
- const month = item.month;
4495
- let day = item.day;
4496
- if (options?.overflow === "constrain") day = clamp(day, 1, daysInMonth(year, month));
4497
- return new MiniPlainDate(year, month, day);
4498
- },
4499
- compare(a, b) {
4500
- if (a.year !== b.year) return Math.sign(a.year - b.year);
4501
- if (a.month !== b.month) return Math.sign(a.month - b.month);
4502
- if (a.day !== b.day) return Math.sign(a.day - b.day);
4503
- return 0;
4504
- }
4505
- };
4506
- const PlainDateTime = { from(item, _options) {
4507
- if (typeof item === "string") {
4508
- const { year, month, day, hour, minute, second } = parseDateTimeISO(item);
4509
- return new MiniPlainDateTime(year, month, day, hour, minute, second);
4510
- }
4511
- return new MiniPlainDateTime(item.year, item.month, item.day, item.hour ?? 0, item.minute ?? 0, item.second ?? 0);
4512
- } };
4513
- const PlainMonthDay = { from(item) {
4514
- if (typeof item === "string") {
4515
- const parts = item.split("-").map(Number);
4516
- if (parts.length >= 3) return new MiniPlainMonthDay(parts[1], parts[2]);
4517
- return new MiniPlainMonthDay(parts[0], parts[1]);
4518
- }
4519
- return new MiniPlainMonthDay(item.month ?? (item.monthCode ? Number.parseInt(item.monthCode.slice(1), 10) : 1), item.day);
4520
- } };
4521
- const PlainYearMonth = {
4522
- from(item) {
4523
- if (typeof item === "string") {
4524
- const [y, m] = item.split("-").map(Number);
4525
- return new MiniPlainYearMonth(y, m);
4526
- }
4527
- return new MiniPlainYearMonth(item.year, item.month);
4528
- },
4529
- compare(a, b) {
4530
- if (a.year !== b.year) return Math.sign(a.year - b.year);
4531
- if (a.month !== b.month) return Math.sign(a.month - b.month);
4532
- return 0;
4533
- }
4534
- };
4535
- const Now = {
4536
- timeZoneId() {
4537
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
4538
- },
4539
- zonedDateTimeISO(tz) {
4540
- return new MiniZonedDateTime(Date.now(), tz ?? Now.timeZoneId());
4541
- },
4542
- plainDateISO() {
4543
- const tz = Now.timeZoneId();
4544
- const parts = extractTzParts(Date.now(), tz);
4545
- return new MiniPlainDate(parts.year, parts.month, parts.day);
4546
- }
4547
- };
4548
- const Temporal = {
4549
- Now,
4550
- PlainDate,
4551
- PlainDateTime,
4552
- PlainMonthDay,
4553
- PlainYearMonth
4554
- };
4555
- //#endregion
4556
- export { MonthSeparatorMonth as A, MonthViewRoot as B, WeekTemplate as C, useWeeksViewState as D, useWeeksViewStable as E, GridHeaderCell as F, computePreviewRange as G, useMonthViewStable as H, DayCellDataContext as I, useCalendarStable as K, GridContext as L, MonthSeparatorWeekCount as M, MonthSeparatorYear as N, MonthSeparator as O, GridHeader as P, WeekDataContext as R, GridBody as S, DayCellTemplate as T, useMonthViewState as U, useViewContext as V, CalendarProvider as W, MonthYearString as _, WeeksView as a, TimeString as b, resolveFirstWeekSpec as c, WeekNumberHeader as d, RangeEndDragHandle as f, DateString as g, RangeSelected as h, WeekCount as i, MonthSeparatorRow as j, MonthSeparatorCell as k, computeWeeksInWindow as l, RangePreview as m, NextWeeksButton as n, WeeksViewRoot as o, RangeStartDragHandle as p, useCalendarState as q, PrevWeeksButton as r, resolveFirstWeek as s, Temporal as t, WeekNumberCell as u, NextMonthButton as v, DayButton as w, Grid as x, PrevMonthButton as y, MonthView as z };
4324
+ export { MonthSeparatorRow as A, useViewContext as B, DayButton as C, MonthSeparator as D, useWeeksViewState as E, DayCellDataContext as F, useCalendarStable as G, useMonthViewState as H, GridContext as I, useCalendarState as K, WeekDataContext as L, MonthSeparatorYear as M, GridHeader as N, MonthSeparatorCell as O, GridHeaderCell as P, MonthView as R, WeekTemplate as S, useWeeksViewStable as T, CalendarProvider as U, useMonthViewStable as V, computePreviewRange as W, NextMonthButton as _, WeeksViewRoot as a, Grid as b, computeWeeksInWindow as c, RangeEndDragHandle as d, RangeStartDragHandle as f, MonthYearString as g, DateString as h, WeeksView as i, MonthSeparatorWeekCount as j, MonthSeparatorMonth as k, WeekNumberCell as l, RangeSelected as m, PrevWeeksButton as n, resolveFirstWeek as o, RangePreview as p, WeekCount as r, resolveFirstWeekSpec as s, NextWeeksButton as t, WeekNumberHeader as u, PrevMonthButton as v, DayCellTemplate as w, GridBody as x, TimeString as y, MonthViewRoot as z };