@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
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
  //#endregion
23
23
  let react = require("react");
24
- react = __toESM(react);
24
+ react = __toESM(react, 1);
25
25
  let react_jsx_runtime = require("react/jsx-runtime");
26
26
  let _base_ui_react_merge_props = require("@base-ui/react/merge-props");
27
27
  let _base_ui_react_use_render = require("@base-ui/react/use-render");
@@ -45,25 +45,21 @@ function useCalendarState() {
45
45
  //#endregion
46
46
  //#region src/utils.ts
47
47
  /**
48
- * Returns the default calendar system for a given locale (e.g. `"gregory"` for `"en-US"`).
49
- *
50
- * @param locale - A BCP 47 locale string. Falls back to the runtime default when empty.
51
- */
52
- function calendarForLocale(locale) {
53
- return new Intl.DateTimeFormat(locale || void 0).resolvedOptions().calendar;
54
- }
55
- /**
56
48
  * Resolves a {@link TemporalNamespace} instance.
57
49
  *
58
- * Returns `provided` when given, otherwise checks `globalThis.Temporal`.
59
- * Throws if neither is available.
50
+ * Returns `provided` when given, otherwise native `globalThis.Temporal`. This
51
+ * library does not bundle a `Temporal` implementation — if neither is
52
+ * available, it throws. Provide one via the `temporal` prop, e.g. the
53
+ * `Temporal` export from `temporal-polyfill`
54
+ * (https://github.com/fullcalendar/temporal-polyfill) or `@js-temporal/polyfill`
55
+ * (https://github.com/js-temporal/temporal-polyfill).
60
56
  *
61
57
  * @param provided - An explicit Temporal polyfill or namespace.
62
58
  */
63
59
  function resolveTemporal(provided) {
64
60
  if (provided) return provided;
65
61
  if (typeof globalThis !== "undefined" && globalThis.Temporal) return globalThis.Temporal;
66
- 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.");
62
+ 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.");
67
63
  }
68
64
  /**
69
65
  * Returns the IANA time zone identifier of the host environment (e.g. `"America/New_York"`).
@@ -284,6 +280,40 @@ function computeAdjacentMonth(current, direction, T) {
284
280
  };
285
281
  }
286
282
  /**
283
+ * Computes the new first-visible month after the **minimum** shift needed to
284
+ * bring `focused` into a window of `numberOfMonths` months that currently
285
+ * starts at `start`.
286
+ *
287
+ * - Already visible → returns `start` unchanged (by value).
288
+ * - Before the window → `focused` becomes the first (leftmost) pane.
289
+ * - After the window → `focused` becomes the last (rightmost) pane.
290
+ *
291
+ * This keeps keyboard focus-crossing symmetric with single-month stepping: a
292
+ * Gregorian-style window only ever scrolls as far as it must, never jumping
293
+ * the focused month to the leftmost slot. Pure month arithmetic — calendar
294
+ * agnostic, since `{year, month}` indices are computed by the caller.
295
+ *
296
+ * @param start - The current first-visible month.
297
+ * @param focused - The month that must become visible.
298
+ * @param numberOfMonths - Number of month panes displayed (>= 1).
299
+ */
300
+ function shiftWindowToMonth(start, focused, numberOfMonths) {
301
+ const startIndex = start.year * 12 + (start.month - 1);
302
+ const focusedIndex = focused.year * 12 + (focused.month - 1);
303
+ if (focusedIndex < startIndex) return {
304
+ year: focused.year,
305
+ month: focused.month
306
+ };
307
+ if (focusedIndex > startIndex + numberOfMonths - 1) {
308
+ const newStartIndex = focusedIndex - (numberOfMonths - 1);
309
+ return {
310
+ year: Math.floor(newStartIndex / 12),
311
+ month: newStartIndex % 12 + 1
312
+ };
313
+ }
314
+ return start;
315
+ }
316
+ /**
287
317
  * Determines the focused date after navigating to a new month.
288
318
  *
289
319
  * If `currentFocused` is already within `targetMonth`, it is preserved.
@@ -303,7 +333,8 @@ function focusedDateForMonth(currentFocused, targetMonth, firstDay) {
303
333
  * Priority when `gridHasFocus` is `true` (keyboard navigation):
304
334
  * 1. `focusedDate` if it exists in the grid.
305
335
  * 2. `selectedDate` if it exists in the grid.
306
- * 3. First enabled day of `currentMonth`, or first grid day as last resort.
336
+ * 3. First enabled day of `currentMonth`, then first grid day, then
337
+ * `focusedDate` itself (empty grid) as last resorts.
307
338
  *
308
339
  * When `gridHasFocus` is `false` (tab-in), `selectedDate` takes priority
309
340
  * over `focusedDate`.
@@ -322,7 +353,7 @@ function resolveFocusTarget(focusedDate, selectedDate, weeks, currentMonth, isDa
322
353
  if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
323
354
  if (selectedDate && inGrid(selectedDate)) return selectedDate;
324
355
  if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
325
- return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0];
356
+ return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0] ?? focusedDate;
326
357
  }
327
358
  /**
328
359
  * Determines whether a day cell should imperatively receive DOM focus.
@@ -356,6 +387,13 @@ function isInRange(date, rangeStart, rangeEnd, T) {
356
387
  if (totalDays === 0) return 0;
357
388
  return date.since(effectiveStart).days / totalDays;
358
389
  }
390
+ const INACTIVE_RANGE_INFO = {
391
+ active: false,
392
+ startIndex: -1,
393
+ endIndex: -1,
394
+ extendsBefore: false,
395
+ extendsAfter: false
396
+ };
359
397
  /**
360
398
  * Computes how a date range intersects with a single calendar week row.
361
399
  *
@@ -370,31 +408,24 @@ function isInRange(date, rangeStart, rangeEnd, T) {
370
408
  * `extendsBefore` / `extendsAfter` (whether the range continues beyond the week).
371
409
  */
372
410
  function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
373
- const inactive = {
374
- active: false,
375
- startIndex: 0,
376
- endIndex: 0,
377
- extendsBefore: false,
378
- extendsAfter: false
379
- };
380
- if (weekDays.length === 0) return inactive;
381
- if (!rangeStart && !rangeEnd) return inactive;
382
- const effectiveStart = rangeStart ?? rangeEnd;
383
- const effectiveEnd = rangeEnd ?? rangeStart;
411
+ if (!rangeStart && !rangeEnd) return INACTIVE_RANGE_INFO;
384
412
  const weekStart = weekDays[0];
385
413
  const weekEnd = weekDays[weekDays.length - 1];
386
- if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return inactive;
414
+ if (!weekStart || !weekEnd) return INACTIVE_RANGE_INFO;
415
+ const effectiveStart = rangeStart ?? rangeEnd;
416
+ const effectiveEnd = rangeEnd ?? rangeStart;
417
+ if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return INACTIVE_RANGE_INFO;
387
418
  const extendsBefore = T.PlainDate.compare(effectiveStart, weekStart) < 0;
388
419
  const extendsAfter = T.PlainDate.compare(effectiveEnd, weekEnd) > 0;
389
420
  let startIndex = 0;
390
421
  if (!extendsBefore) {
391
422
  startIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveStart) === 0);
392
- if (startIndex === -1) return inactive;
423
+ if (startIndex === -1) return INACTIVE_RANGE_INFO;
393
424
  }
394
425
  let endIndex = weekDays.length - 1;
395
426
  if (!extendsAfter) {
396
427
  endIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveEnd) === 0);
397
- if (endIndex === -1) return inactive;
428
+ if (endIndex === -1) return INACTIVE_RANGE_INFO;
398
429
  }
399
430
  return {
400
431
  active: true,
@@ -410,7 +441,9 @@ function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
410
441
  * @param locale - BCP 47 locale string (e.g. `"en-US"`).
411
442
  * @param T - Temporal namespace.
412
443
  * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
413
- * @returns An array of 7 objects with `long`, `short`, and `narrow` name variants.
444
+ * @returns An array of objects with `long`, `short`, and `narrow` name variants,
445
+ * one per day in the calendar's week (typically 7, but may differ for
446
+ * non-Gregorian calendars).
414
447
  */
415
448
  function getWeekdayNames(locale, T, weekStartDay = 0) {
416
449
  const refStart = getReferenceWeekStart(T, weekStartDay);
@@ -552,8 +585,8 @@ function computeSelectionUpdate(opts) {
552
585
  if (isComplete) {
553
586
  const start = committedDates[0];
554
587
  const end = committedDates[1];
555
- const isOnStart = T.PlainDate.compare(date, start) === 0;
556
- const isOnEnd = T.PlainDate.compare(date, end) === 0;
588
+ const isOnStart = start != null && T.PlainDate.compare(date, start) === 0;
589
+ const isOnEnd = end != null && T.PlainDate.compare(date, end) === 0;
557
590
  if (isOnStart || isOnEnd) return {
558
591
  newDates: [],
559
592
  fireCallback: (onValueChange) => {
@@ -602,19 +635,31 @@ function computeSelectionUpdate(opts) {
602
635
  }
603
636
  const beforeStart = T.PlainDate.compare(date, committedStart) < 0;
604
637
  const afterEnd = T.PlainDate.compare(date, committedEnd) > 0;
605
- let newDates;
606
- if (beforeStart) newDates = [date, committedEnd];
607
- else if (afterEnd) newDates = [committedStart, date];
608
- else {
638
+ let newStart;
639
+ let newEnd;
640
+ if (beforeStart) {
641
+ newStart = date;
642
+ newEnd = committedEnd;
643
+ } else if (afterEnd) {
644
+ newStart = committedStart;
645
+ newEnd = date;
646
+ } else {
609
647
  const action = resolveInsideAction(rangeMode, date, committedStart, committedEnd);
610
- if (action === "start") newDates = [date, committedEnd];
611
- else if (action === "end") newDates = [committedStart, date];
612
- else newDates = [date, date];
648
+ if (action === "start") {
649
+ newStart = date;
650
+ newEnd = committedEnd;
651
+ } else if (action === "end") {
652
+ newStart = committedStart;
653
+ newEnd = date;
654
+ } else {
655
+ newStart = date;
656
+ newEnd = date;
657
+ }
613
658
  }
614
659
  return {
615
- newDates,
660
+ newDates: [newStart, newEnd],
616
661
  fireCallback: (onValueChange, plainToFormatValue) => {
617
- onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
662
+ onValueChange?.(mkRange(plainToFormatValue(newStart), plainToFormatValue(newEnd)), {
618
663
  date,
619
664
  previous: prevRange
620
665
  });
@@ -623,11 +668,10 @@ function computeSelectionUpdate(opts) {
623
668
  }
624
669
  if (isRange) {
625
670
  const prevRange = currentRangeFormatted();
626
- const newDates = [date, date];
627
671
  return {
628
- newDates,
672
+ newDates: [date, date],
629
673
  fireCallback: (onValueChange, plainToFormatValue) => {
630
- onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
674
+ onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(date)), {
631
675
  date,
632
676
  previous: prevRange
633
677
  });
@@ -1151,9 +1195,9 @@ function CalendarProvider(props) {
1151
1195
  selectionMode,
1152
1196
  disabled,
1153
1197
  readOnly,
1154
- isDateDisabled,
1155
- minValue,
1156
- maxValue,
1198
+ ...isDateDisabled !== void 0 && { isDateDisabled },
1199
+ ...minValue !== void 0 && { minValue },
1200
+ ...maxValue !== void 0 && { maxValue },
1157
1201
  timeZone,
1158
1202
  locale,
1159
1203
  temporal: T,
@@ -1180,6 +1224,23 @@ function CalendarProvider(props) {
1180
1224
  resolvedFormat,
1181
1225
  setHoveredDate
1182
1226
  ]);
1227
+ const baseRootState = (0, react.useMemo)(() => ({
1228
+ hasSelection: nonNullDates.length > 0,
1229
+ selected: nonNullDates[0],
1230
+ selectedDates: nonNullDates,
1231
+ rangeStart,
1232
+ rangeEnd,
1233
+ timeZone,
1234
+ locale,
1235
+ readOnly
1236
+ }), [
1237
+ nonNullDates,
1238
+ rangeStart,
1239
+ rangeEnd,
1240
+ timeZone,
1241
+ locale,
1242
+ readOnly
1243
+ ]);
1183
1244
  const stateCtx = (0, react.useMemo)(() => ({
1184
1245
  selected,
1185
1246
  selectedDates: nonNullDates,
@@ -1187,7 +1248,8 @@ function CalendarProvider(props) {
1187
1248
  rangeEnd,
1188
1249
  hoveredDate,
1189
1250
  previewStart,
1190
- previewEnd
1251
+ previewEnd,
1252
+ baseRootState
1191
1253
  }), [
1192
1254
  selected,
1193
1255
  nonNullDates,
@@ -1195,7 +1257,8 @@ function CalendarProvider(props) {
1195
1257
  rangeEnd,
1196
1258
  hoveredDate,
1197
1259
  previewStart,
1198
- previewEnd
1260
+ previewEnd,
1261
+ baseRootState
1199
1262
  ]);
1200
1263
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarStableContext.Provider, {
1201
1264
  value: stableCtx,
@@ -1244,7 +1307,7 @@ function MonthViewRoot(props) {
1244
1307
  const calStable = useCalendarStable();
1245
1308
  const calState = useCalendarState();
1246
1309
  const T = calStable.temporal;
1247
- const { timeZone, locale, weekStartDay, isDateDisabled } = calStable;
1310
+ const { timeZone, weekStartDay, isDateDisabled } = calStable;
1248
1311
  const isMonthControlled = monthProp !== void 0;
1249
1312
  const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
1250
1313
  if (monthProp) return {
@@ -1294,34 +1357,87 @@ function MonthViewRoot(props) {
1294
1357
  };
1295
1358
  });
1296
1359
  }, []);
1360
+ const onMonthChangeRef = (0, react.useRef)(onMonthChange);
1361
+ onMonthChangeRef.current = onMonthChange;
1362
+ const notifyMonth = (0, react.useCallback)((year, month) => {
1363
+ onMonthChangeRef.current?.(T.PlainYearMonth.from({
1364
+ year,
1365
+ month
1366
+ }));
1367
+ }, [T]);
1368
+ const isMonthVisible = (0, react.useCallback)((targetYear, targetMonth) => {
1369
+ for (let i = 0; i < numberOfMonths; i++) {
1370
+ const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1371
+ const y = Math.floor(totalMonths / 12);
1372
+ const m = totalMonths % 12 + 1;
1373
+ if (targetYear === y && targetMonth === m) return true;
1374
+ }
1375
+ return false;
1376
+ }, [
1377
+ currentMonth.year,
1378
+ currentMonth.month,
1379
+ numberOfMonths
1380
+ ]);
1297
1381
  const navigateToMonth = (0, react.useCallback)((targetYear, targetMonth) => {
1298
1382
  if (isMonthControlled) return;
1299
1383
  setInternalMonth((prev) => {
1300
- for (let i = 0; i < numberOfMonths; i++) {
1301
- const totalMonths = prev.year * 12 + (prev.month - 1) + i;
1302
- const y = Math.floor(totalMonths / 12);
1303
- const m = totalMonths % 12 + 1;
1304
- if (targetYear === y && targetMonth === m) return prev;
1305
- }
1306
- return {
1384
+ const next = shiftWindowToMonth(prev, {
1307
1385
  year: targetYear,
1308
1386
  month: targetMonth
1309
- };
1387
+ }, numberOfMonths);
1388
+ if (next.year === prev.year && next.month === prev.month) return prev;
1389
+ return next;
1310
1390
  });
1311
1391
  }, [isMonthControlled, numberOfMonths]);
1392
+ const skipFocusSyncForRef = (0, react.useRef)(null);
1393
+ const prevFocusedRef = (0, react.useRef)(focusedDate);
1312
1394
  (0, react.useEffect)(() => {
1395
+ skipFocusSyncForRef.current = null;
1396
+ }, [monthProp?.year, monthProp?.month]);
1397
+ (0, react.useEffect)(() => {
1398
+ const prevFocused = prevFocusedRef.current;
1399
+ prevFocusedRef.current = focusedDate;
1400
+ if (isMonthControlled) {
1401
+ if (skipFocusSyncForRef.current === focusedDate) {
1402
+ skipFocusSyncForRef.current = null;
1403
+ return;
1404
+ }
1405
+ if (prevFocused === focusedDate) return;
1406
+ if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
1407
+ const next = shiftWindowToMonth({
1408
+ year: currentMonth.year,
1409
+ month: currentMonth.month
1410
+ }, {
1411
+ year: focusedDate.year,
1412
+ month: focusedDate.month
1413
+ }, numberOfMonths);
1414
+ notifyMonth(next.year, next.month);
1415
+ return;
1416
+ }
1313
1417
  navigateToMonth(focusedDate.year, focusedDate.month);
1314
- }, [focusedDate, navigateToMonth]);
1418
+ }, [
1419
+ focusedDate,
1420
+ navigateToMonth,
1421
+ isMonthControlled,
1422
+ isMonthVisible,
1423
+ notifyMonth,
1424
+ currentMonth.year,
1425
+ currentMonth.month,
1426
+ numberOfMonths
1427
+ ]);
1315
1428
  const goNextMonth = (0, react.useCallback)(() => {
1316
1429
  if (isMonthControlled) {
1317
1430
  const { year, month, firstDay } = computeAdjacentMonth({
1318
1431
  year: monthProp.year,
1319
1432
  month: monthProp.month
1320
1433
  }, "next", T);
1321
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1434
+ const nextFocus = focusedDateForMonth(focusedDate, {
1322
1435
  year,
1323
1436
  month
1324
- }, firstDay));
1437
+ }, firstDay);
1438
+ skipFocusSyncForRef.current = nextFocus;
1439
+ notifyMonth(year, month);
1440
+ setFocusedDate(nextFocus);
1325
1441
  return;
1326
1442
  }
1327
1443
  setInternalMonth((m) => {
@@ -1338,7 +1454,9 @@ function MonthViewRoot(props) {
1338
1454
  }, [
1339
1455
  T,
1340
1456
  isMonthControlled,
1341
- monthProp
1457
+ monthProp,
1458
+ notifyMonth,
1459
+ focusedDate
1342
1460
  ]);
1343
1461
  const goPrevMonth = (0, react.useCallback)(() => {
1344
1462
  if (isMonthControlled) {
@@ -1346,10 +1464,13 @@ function MonthViewRoot(props) {
1346
1464
  year: monthProp.year,
1347
1465
  month: monthProp.month
1348
1466
  }, "prev", T);
1349
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1467
+ const nextFocus = focusedDateForMonth(focusedDate, {
1350
1468
  year,
1351
1469
  month
1352
- }, firstDay));
1470
+ }, firstDay);
1471
+ skipFocusSyncForRef.current = nextFocus;
1472
+ notifyMonth(year, month);
1473
+ setFocusedDate(nextFocus);
1353
1474
  return;
1354
1475
  }
1355
1476
  setInternalMonth((m) => {
@@ -1366,7 +1487,9 @@ function MonthViewRoot(props) {
1366
1487
  }, [
1367
1488
  T,
1368
1489
  isMonthControlled,
1369
- monthProp
1490
+ monthProp,
1491
+ notifyMonth,
1492
+ focusedDate
1370
1493
  ]);
1371
1494
  const allMonths = (0, react.useMemo)(() => {
1372
1495
  const opts = {
@@ -1393,7 +1516,9 @@ function MonthViewRoot(props) {
1393
1516
  fixedWeeks,
1394
1517
  numberOfMonths
1395
1518
  ]);
1396
- const weeks = allMonths[0].weeks;
1519
+ const firstMonth = allMonths[0];
1520
+ if (firstMonth === void 0) throw new Error("MonthView: numberOfMonths must be at least 1.");
1521
+ const weeks = firstMonth.weeks;
1397
1522
  const selectedZdt = (0, react.useMemo)(() => selectedToZdt(calState.selected, timeZone, T), [
1398
1523
  calState.selected,
1399
1524
  timeZone,
@@ -1425,48 +1550,27 @@ function MonthViewRoot(props) {
1425
1550
  T,
1426
1551
  gridHasFocus
1427
1552
  ]);
1428
- const localeCalendar = (0, react.useMemo)(() => calendarForLocale(locale), [locale]);
1429
1553
  const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
1430
1554
  year: currentMonth.year,
1431
- month: currentMonth.month,
1432
- calendar: localeCalendar
1433
- }), [
1434
- currentMonth,
1435
- T,
1436
- localeCalendar
1437
- ]);
1438
- const onMonthChangeRef = (0, react.useRef)(onMonthChange);
1439
- onMonthChangeRef.current = onMonthChange;
1555
+ month: currentMonth.month
1556
+ }), [currentMonth, T]);
1440
1557
  const mountedRef = (0, react.useRef)(false);
1441
1558
  (0, react.useEffect)(() => {
1442
1559
  if (!mountedRef.current) {
1443
1560
  mountedRef.current = true;
1444
1561
  return;
1445
1562
  }
1563
+ if (isMonthControlled) return;
1446
1564
  onMonthChangeRef.current?.(viewingYearMonth);
1447
- }, [viewingYearMonth]);
1448
- const { selected, selectedDates, rangeStart, rangeEnd } = calState;
1565
+ }, [viewingYearMonth, isMonthControlled]);
1449
1566
  const rootState = (0, react.useMemo)(() => ({
1450
- hasSelection: selectedDates.length > 0,
1451
- selected: selected?.value,
1452
- selectedDates,
1453
- rangeStart,
1454
- rangeEnd,
1567
+ ...calState.baseRootState,
1455
1568
  focused: focusedDate,
1456
- viewing: viewingYearMonth,
1457
- timeZone,
1458
- locale,
1459
- readOnly: calStable.readOnly
1569
+ viewing: viewingYearMonth
1460
1570
  }), [
1461
- selectedDates,
1462
- selected,
1463
- rangeStart,
1464
- rangeEnd,
1571
+ calState.baseRootState,
1465
1572
  focusedDate,
1466
- viewingYearMonth,
1467
- timeZone,
1468
- locale,
1469
- calStable.readOnly
1573
+ viewingYearMonth
1470
1574
  ]);
1471
1575
  const stableCtx = (0, react.useMemo)(() => ({
1472
1576
  numberOfMonths,
@@ -1561,13 +1665,17 @@ function useGridHeaderCellState(index) {
1561
1665
  T,
1562
1666
  weekStartDay
1563
1667
  ]);
1564
- const state = (0, react.useMemo)(() => ({
1565
- root: rootState,
1566
- dayOfWeek: index,
1567
- long: weekdayNames[index].long,
1568
- short: weekdayNames[index].short,
1569
- narrow: weekdayNames[index].narrow
1570
- }), [
1668
+ const state = (0, react.useMemo)(() => {
1669
+ const names = weekdayNames[index];
1670
+ if (names === void 0) throw new Error(`GridHeaderCell: index must be between 0 and ${weekdayNames.length - 1}, got ${index}.`);
1671
+ return {
1672
+ root: rootState,
1673
+ dayOfWeek: index,
1674
+ long: names.long,
1675
+ short: names.short,
1676
+ narrow: names.narrow
1677
+ };
1678
+ }, [
1571
1679
  rootState,
1572
1680
  index,
1573
1681
  weekdayNames
@@ -1917,8 +2025,7 @@ function WeeksGrid(props) {
1917
2025
  const monthBoundaries = (0, react.useMemo)(() => {
1918
2026
  const boundaries = [];
1919
2027
  const seenMonths = /* @__PURE__ */ new Set();
1920
- for (let i = 0; i < weeks.length; i++) {
1921
- const days = weekDaysArrays[i];
2028
+ for (const [i, days] of weekDaysArrays.entries()) {
1922
2029
  const isFirstWeek = i === 0;
1923
2030
  const monthsInWeek = [];
1924
2031
  for (const day of days) {
@@ -1942,12 +2049,21 @@ function WeeksGrid(props) {
1942
2049
  const windowEnd = weekDaysArrays[weekDaysArrays.length - 1]?.[6];
1943
2050
  const firstDayVisible = windowStart && windowEnd ? T.PlainDate.compare(firstOfMonth, windowStart) >= 0 && T.PlainDate.compare(firstOfMonth, windowEnd) <= 0 : false;
1944
2051
  let weeksVisibleBefore = 0;
1945
- for (let j = i - 1; j >= 0; j--) if (!weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
1946
- else break;
2052
+ for (let j = i - 1; j >= 0; j--) {
2053
+ const prevDays = weekDaysArrays[j];
2054
+ if (prevDays === void 0) break;
2055
+ if (!prevDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
2056
+ else break;
2057
+ }
1947
2058
  let weeksVisibleAfter = 0;
1948
- for (let j = i; j < weeks.length; j++) if (weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
1949
- else break;
1950
- const isNewYear = boundaries.length > 0 ? boundaries[boundaries.length - 1].data.year !== newYear : newMonth === 1;
2059
+ for (let j = i; j < weekDaysArrays.length; j++) {
2060
+ const wDays = weekDaysArrays[j];
2061
+ if (wDays === void 0) break;
2062
+ if (wDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
2063
+ else break;
2064
+ }
2065
+ const lastBoundary = boundaries[boundaries.length - 1];
2066
+ const isNewYear = lastBoundary !== void 0 ? lastBoundary.data.year !== newYear : newMonth === 1;
1951
2067
  boundaries.push({
1952
2068
  index: i,
1953
2069
  data: {
@@ -1966,9 +2082,9 @@ function WeeksGrid(props) {
1966
2082
  });
1967
2083
  }
1968
2084
  }
1969
- for (let b = 0; b < boundaries.length; b++) {
1970
- const current = boundaries[b];
1971
- const nextIndex = b + 1 < boundaries.length ? boundaries[b + 1].index : weeks.length;
2085
+ for (const [b, current] of boundaries.entries()) {
2086
+ const next = boundaries[b + 1];
2087
+ const nextIndex = next !== void 0 ? next.index : weeks.length;
1972
2088
  current.data.fullWeeksVisibleAfter = nextIndex - current.index;
1973
2089
  current.data.gridRowStart = current.index + 2;
1974
2090
  }
@@ -1991,9 +2107,9 @@ function WeeksGrid(props) {
1991
2107
  return map;
1992
2108
  }, [monthBoundaries]);
1993
2109
  const rows = [];
1994
- for (let i = 0; i < weeks.length; i++) {
1995
- const week = weeks[i];
2110
+ for (const [i, week] of weeks.entries()) {
1996
2111
  const days = weekDaysArrays[i];
2112
+ if (days === void 0) continue;
1997
2113
  const separators = boundariesAtIndex.get(i);
1998
2114
  if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorDataContext.Provider, {
1999
2115
  value: separatorData,
@@ -2455,7 +2571,7 @@ function useGridKeyboard() {
2455
2571
  maxValue,
2456
2572
  disabled,
2457
2573
  readOnly,
2458
- isDateDisabled,
2574
+ ...isDateDisabled !== void 0 && { isDateDisabled },
2459
2575
  T,
2460
2576
  weekStartDay
2461
2577
  });
@@ -2495,7 +2611,7 @@ function useWeeksGridKeyboard() {
2495
2611
  maxValue,
2496
2612
  disabled,
2497
2613
  readOnly,
2498
- isDateDisabled,
2614
+ ...isDateDisabled !== void 0 && { isDateDisabled },
2499
2615
  scrollBy: weeksStable.scrollBy,
2500
2616
  T,
2501
2617
  weekStartDay
@@ -2749,8 +2865,12 @@ function WeeksViewGridFn(props, ref) {
2749
2865
  allMonths: [],
2750
2866
  currentDateTime,
2751
2867
  gridLabelIds,
2752
- rootState: {}
2753
- }), [currentDateTime, gridLabelIds]);
2868
+ rootState: weeksState.rootState
2869
+ }), [
2870
+ currentDateTime,
2871
+ gridLabelIds,
2872
+ weeksState.rootState
2873
+ ]);
2754
2874
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
2755
2875
  value: monthViewStableShim,
2756
2876
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
@@ -2836,15 +2956,19 @@ function WeekTemplate(props) {
2836
2956
  month: gridMonthCtx.month
2837
2957
  } : void 0, [gridMonthCtx]);
2838
2958
  const Instance = WeekInstance;
2839
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: weeks.map((weekDays, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
2840
- value: {
2841
- days: weekDays,
2842
- weekIndex: i,
2843
- gridMonth,
2844
- gridRowIndex: outerWeekData?.gridRowIndex
2845
- },
2846
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, { ...props })
2847
- }, weekDays[0].toString())) });
2959
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: weeks.map((weekDays, i) => {
2960
+ const firstDay = weekDays[0];
2961
+ if (firstDay === void 0) return null;
2962
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
2963
+ value: {
2964
+ days: weekDays,
2965
+ weekIndex: i,
2966
+ ...gridMonth !== void 0 && { gridMonth },
2967
+ ...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
2968
+ },
2969
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, { ...props })
2970
+ }, firstDay.toString());
2971
+ }) });
2848
2972
  }
2849
2973
  //#endregion
2850
2974
  //#region src/navigation.tsx
@@ -2952,7 +3076,7 @@ const TimeString = (0, react.forwardRef)(TimeStringFn);
2952
3076
  function MonthYearStringFn(props, ref) {
2953
3077
  const { render, locales, options, monthIndex: monthIndexProp, ...otherProps } = props;
2954
3078
  const monthIndex = monthIndexProp ?? 0;
2955
- const { locale } = useCalendarStable();
3079
+ const { locale, temporal: T } = useCalendarStable();
2956
3080
  const monthViewStable = useMonthViewStable();
2957
3081
  const { currentMonth: currentDateTime, allMonths, rootState } = useMonthViewState();
2958
3082
  const { setGridLabelId } = monthViewStable;
@@ -2968,12 +3092,15 @@ function MonthYearStringFn(props, ref) {
2968
3092
  const monthData = allMonths[monthIndex];
2969
3093
  const displayYear = monthData?.year ?? currentDateTime.year;
2970
3094
  const displayMonth = monthData?.month ?? currentDateTime.month;
2971
- const displayDate = new Date(displayYear, displayMonth - 1, 1);
2972
3095
  const defaultOptions = options ?? {
2973
3096
  month: "long",
2974
3097
  year: "numeric"
2975
3098
  };
2976
- const formatted = displayDate.toLocaleDateString(locales ?? locale, defaultOptions);
3099
+ const formatted = T.PlainDate.from({
3100
+ year: displayYear,
3101
+ month: displayMonth,
3102
+ day: 1
3103
+ }).toLocaleString(locales ?? locale, defaultOptions);
2977
3104
  const state = (0, react.useMemo)(() => ({
2978
3105
  root: rootState,
2979
3106
  month: displayMonth,
@@ -3010,7 +3137,7 @@ function MonthYearStringFn(props, ref) {
3010
3137
  */
3011
3138
  const MonthYearString = (0, react.forwardRef)(MonthYearStringFn);
3012
3139
  function useNavButton(direction) {
3013
- const { disabled: globalDisabled, minValue, maxValue, locale, temporal: T } = useCalendarStable();
3140
+ const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
3014
3141
  const monthViewStable = useMonthViewStable();
3015
3142
  const monthViewState = useMonthViewState();
3016
3143
  const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths } = monthViewStable;
@@ -3031,16 +3158,13 @@ function useNavButton(direction) {
3031
3158
  boundValue,
3032
3159
  direction
3033
3160
  ]);
3034
- const localeCalendar = (0, react.useMemo)(() => calendarForLocale(locale), [locale]);
3035
3161
  const target = (0, react.useMemo)(() => T.PlainYearMonth.from({
3036
3162
  year: destYear,
3037
- month: destMonth,
3038
- calendar: localeCalendar
3163
+ month: destMonth
3039
3164
  }), [
3040
3165
  destYear,
3041
3166
  destMonth,
3042
- T,
3043
- localeCalendar
3167
+ T
3044
3168
  ]);
3045
3169
  return {
3046
3170
  state: (0, react.useMemo)(() => ({
@@ -3122,11 +3246,15 @@ function computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gri
3122
3246
  const raw = computeWeekRangeInfo(days, rangeStart, rangeEnd, T);
3123
3247
  if ((outsideDays === "disabled" || outsideDays === "hidden") && raw.active && gridMonth) {
3124
3248
  let { startIndex, endIndex, extendsBefore, extendsAfter } = raw;
3125
- while (startIndex <= endIndex && (days[startIndex].year !== gridMonth.year || days[startIndex].month !== gridMonth.month)) {
3249
+ const inMonth = (i) => {
3250
+ const day = days[i];
3251
+ return day !== void 0 && day.year === gridMonth.year && day.month === gridMonth.month;
3252
+ };
3253
+ while (startIndex <= endIndex && !inMonth(startIndex)) {
3126
3254
  startIndex++;
3127
3255
  extendsBefore = true;
3128
3256
  }
3129
- while (endIndex >= startIndex && (days[endIndex].year !== gridMonth.year || days[endIndex].month !== gridMonth.month)) {
3257
+ while (endIndex >= startIndex && !inMonth(endIndex)) {
3130
3258
  endIndex--;
3131
3259
  extendsAfter = true;
3132
3260
  }
@@ -3181,8 +3309,8 @@ function RangeSelectedInnerFn(props, ref) {
3181
3309
  outsideDays,
3182
3310
  gridMonth
3183
3311
  ]);
3184
- const startDate = info.active ? days[info.startIndex].toString() : "";
3185
- const endDate = info.active ? days[info.endIndex].toString() : "";
3312
+ const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
3313
+ const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
3186
3314
  const weekIndex = weekData?.weekIndex ?? 0;
3187
3315
  const state = (0, react.useMemo)(() => ({
3188
3316
  root: rootState,
@@ -3256,8 +3384,8 @@ function RangePreviewInnerFn(props, ref) {
3256
3384
  outsideDays,
3257
3385
  gridMonth
3258
3386
  ]);
3259
- const startDate = info.active ? days[info.startIndex].toString() : "";
3260
- const endDate = info.active ? days[info.endIndex].toString() : "";
3387
+ const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
3388
+ const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
3261
3389
  const weekIndex = weekData?.weekIndex ?? 0;
3262
3390
  const state = (0, react.useMemo)(() => ({
3263
3391
  root: rootState,
@@ -3313,7 +3441,7 @@ function useDragHandle(edge, { dragging: draggingProp }) {
3313
3441
  const date = cellData?.date;
3314
3442
  const outsideDisabled = cellData?.outsideDisabled ?? false;
3315
3443
  const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
3316
- const isDragging = (draggingProp ?? false) && isActive;
3444
+ const isDragging = !!draggingProp && isActive;
3317
3445
  const handleRef = (0, react.useRef)(null);
3318
3446
  return {
3319
3447
  state: (0, react.useMemo)(() => ({
@@ -3394,8 +3522,8 @@ function WeekNumberCellFn(props, ref) {
3394
3522
  const { temporal: T } = useCalendarStable();
3395
3523
  const days = weekData?.days ?? [];
3396
3524
  const weekNumber = (0, react.useMemo)(() => {
3397
- if (days.length === 0) return 0;
3398
3525
  let thursday = days[0];
3526
+ if (thursday === void 0) return 0;
3399
3527
  for (const d of days) if (d.dayOfWeek === 4) {
3400
3528
  thursday = d;
3401
3529
  break;
@@ -3699,8 +3827,8 @@ function useWeeksViewRootState(props) {
3699
3827
  targetFirstWeek: resolvedFirstWeek,
3700
3828
  weekCount,
3701
3829
  behavior: overflowBehavior,
3702
- min: minValue,
3703
- max: maxValue,
3830
+ ...minValue !== void 0 && { min: minValue },
3831
+ ...maxValue !== void 0 && { max: maxValue },
3704
3832
  weekStartDay,
3705
3833
  T
3706
3834
  }), [
@@ -3738,7 +3866,9 @@ function useWeeksViewRootState(props) {
3738
3866
  ]);
3739
3867
  const windowInfo = (0, react.useMemo)(() => {
3740
3868
  const weeks = adjustedWeeks;
3741
- if (weeks.length === 0) {
3869
+ const firstWeek = weeks[0];
3870
+ const lastWeek = weeks[weeks.length - 1];
3871
+ if (firstWeek === void 0 || lastWeek === void 0) {
3742
3872
  const today = T.Now.plainDateISO();
3743
3873
  return {
3744
3874
  windowStart: today,
@@ -3750,8 +3880,8 @@ function useWeeksViewRootState(props) {
3750
3880
  visibleMonths: []
3751
3881
  };
3752
3882
  }
3753
- const windowStart = weeks[0].startDate;
3754
- const windowEnd = weeks[weeks.length - 1].endDate;
3883
+ const windowStart = firstWeek.startDate;
3884
+ const windowEnd = lastWeek.endDate;
3755
3885
  const wc = weeks.length;
3756
3886
  const dayCount = wc * 7;
3757
3887
  let enabledDayCount = 0;
@@ -3893,8 +4023,8 @@ function useWeeksViewRootState(props) {
3893
4023
  targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
3894
4024
  weekCount,
3895
4025
  behavior: overflowBehavior,
3896
- min: minValue,
3897
- max: maxValue,
4026
+ ...minValue !== void 0 && { min: minValue },
4027
+ ...maxValue !== void 0 && { max: maxValue },
3898
4028
  weekStartDay,
3899
4029
  T
3900
4030
  }).firstWeek);
@@ -3914,8 +4044,8 @@ function useWeeksViewRootState(props) {
3914
4044
  targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
3915
4045
  weekCount,
3916
4046
  behavior: overflowBehavior,
3917
- min: minValue,
3918
- max: maxValue,
4047
+ ...minValue !== void 0 && { min: minValue },
4048
+ ...maxValue !== void 0 && { max: maxValue },
3919
4049
  weekStartDay,
3920
4050
  T
3921
4051
  }).firstWeek);
@@ -3934,8 +4064,8 @@ function useWeeksViewRootState(props) {
3934
4064
  targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
3935
4065
  weekCount,
3936
4066
  behavior: overflowBehavior,
3937
- min: minValue,
3938
- max: maxValue,
4067
+ ...minValue !== void 0 && { min: minValue },
4068
+ ...maxValue !== void 0 && { max: maxValue },
3939
4069
  weekStartDay,
3940
4070
  T
3941
4071
  }).firstWeek);
@@ -3960,37 +4090,53 @@ function useWeeksViewRootState(props) {
3960
4090
  onWindowChangeRef.current?.(windowInfo);
3961
4091
  }
3962
4092
  }, [windowInfo, T]);
4093
+ const stableCtx = (0, react.useMemo)(() => ({
4094
+ weekCount,
4095
+ scrollBy,
4096
+ overflowBehavior,
4097
+ goNext,
4098
+ goPrev,
4099
+ scrollToWeek,
4100
+ gridFocusedRef,
4101
+ setGridLabelId
4102
+ }), [
4103
+ weekCount,
4104
+ scrollBy,
4105
+ overflowBehavior,
4106
+ goNext,
4107
+ goPrev,
4108
+ scrollToWeek,
4109
+ setGridLabelId
4110
+ ]);
4111
+ const rootState = (0, react.useMemo)(() => ({
4112
+ ...calState.baseRootState,
4113
+ focused: focusedDate,
4114
+ viewing: T.PlainYearMonth.from({
4115
+ year: currentDateTime.year,
4116
+ month: currentDateTime.month
4117
+ })
4118
+ }), [
4119
+ calState.baseRootState,
4120
+ focusedDate,
4121
+ currentDateTime,
4122
+ T
4123
+ ]);
3963
4124
  return {
3964
- stableCtx: (0, react.useMemo)(() => ({
3965
- weekCount,
3966
- scrollBy,
3967
- overflowBehavior,
3968
- goNext,
3969
- goPrev,
3970
- scrollToWeek,
3971
- gridFocusedRef,
3972
- setGridLabelId
3973
- }), [
3974
- weekCount,
3975
- scrollBy,
3976
- overflowBehavior,
3977
- goNext,
3978
- goPrev,
3979
- scrollToWeek,
3980
- setGridLabelId
3981
- ]),
4125
+ stableCtx,
3982
4126
  stateCtx: (0, react.useMemo)(() => ({
3983
4127
  focusedDate,
3984
4128
  windowInfo,
3985
4129
  gridLabelIds,
3986
4130
  weeks: adjustedWeeks,
3987
- currentDateTime
4131
+ currentDateTime,
4132
+ rootState
3988
4133
  }), [
3989
4134
  focusedDate,
3990
4135
  windowInfo,
3991
4136
  gridLabelIds,
3992
4137
  adjustedWeeks,
3993
- currentDateTime
4138
+ currentDateTime,
4139
+ rootState
3994
4140
  ]),
3995
4141
  viewCtx: (0, react.useMemo)(() => ({
3996
4142
  viewType: "weeks",
@@ -4033,8 +4179,12 @@ function WeeksViewRootFn(props, ref) {
4033
4179
  allMonths: [],
4034
4180
  currentDateTime: stateCtx.currentDateTime,
4035
4181
  gridLabelIds: stateCtx.gridLabelIds,
4036
- rootState: {}
4037
- }), [stateCtx.currentDateTime, stateCtx.gridLabelIds]);
4182
+ rootState: stateCtx.rootState
4183
+ }), [
4184
+ stateCtx.currentDateTime,
4185
+ stateCtx.gridLabelIds,
4186
+ stateCtx.rootState
4187
+ ]);
4038
4188
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
4039
4189
  value: monthViewStableShim,
4040
4190
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
@@ -4095,10 +4245,10 @@ function useWeeksNavButton(direction, shiftByProp) {
4095
4245
  currentFirstWeek,
4096
4246
  weekCount,
4097
4247
  direction: direction === "next" ? 1 : -1,
4098
- shiftBy: shiftByProp,
4248
+ ...shiftByProp !== void 0 && { shiftBy: shiftByProp },
4099
4249
  behavior: overflowBehavior,
4100
- min: minValue,
4101
- max: maxValue,
4250
+ ...minValue !== void 0 && { min: minValue },
4251
+ ...maxValue !== void 0 && { max: maxValue },
4102
4252
  weekStartDay,
4103
4253
  T
4104
4254
  });
@@ -4194,388 +4344,6 @@ function WeekCountFn(props, ref) {
4194
4344
  */
4195
4345
  const WeekCount = (0, react.forwardRef)(WeekCountFn);
4196
4346
  //#endregion
4197
- //#region src/temporal-polyfill.ts
4198
- function daysInMonth(year, month) {
4199
- return new Date(year, month, 0).getDate();
4200
- }
4201
- function toUTC(y, m, d) {
4202
- return Date.UTC(y, m - 1, d);
4203
- }
4204
- function isoWeekday(utcDate) {
4205
- const dow = utcDate.getUTCDay();
4206
- return dow === 0 ? 7 : dow;
4207
- }
4208
- function pad2(n) {
4209
- return n < 10 ? `0${n}` : `${n}`;
4210
- }
4211
- function clamp(val, min, max) {
4212
- return val < min ? min : val > max ? max : val;
4213
- }
4214
- function parseDateISO(str) {
4215
- const [datePart] = str.split("T");
4216
- const [y, m, d] = datePart.split("-").map(Number);
4217
- return {
4218
- year: y,
4219
- month: m,
4220
- day: d
4221
- };
4222
- }
4223
- function parseDateTimeISO(str) {
4224
- const [datePart, timePart] = str.split("T");
4225
- const [y, m, d] = datePart.split("-").map(Number);
4226
- if (!timePart) return {
4227
- year: y,
4228
- month: m,
4229
- day: d,
4230
- hour: 0,
4231
- minute: 0,
4232
- second: 0
4233
- };
4234
- const [h, min, s] = timePart.split(":").map(Number);
4235
- return {
4236
- year: y,
4237
- month: m,
4238
- day: d,
4239
- hour: h || 0,
4240
- minute: min || 0,
4241
- second: s || 0
4242
- };
4243
- }
4244
- const dtfCache = /* @__PURE__ */ new Map();
4245
- function getDTF(tz) {
4246
- let dtf = dtfCache.get(tz);
4247
- if (!dtf) {
4248
- dtf = new Intl.DateTimeFormat("en-US", {
4249
- timeZone: tz,
4250
- year: "numeric",
4251
- month: "numeric",
4252
- day: "numeric",
4253
- hour: "numeric",
4254
- minute: "numeric",
4255
- second: "numeric",
4256
- hour12: false
4257
- });
4258
- dtfCache.set(tz, dtf);
4259
- }
4260
- return dtf;
4261
- }
4262
- function extractTzParts(epochMs, tz) {
4263
- const parts = getDTF(tz).formatToParts(new Date(epochMs));
4264
- const vals = {};
4265
- for (const p of parts) if (p.type !== "literal") vals[p.type] = Number(p.value);
4266
- return {
4267
- year: vals.year,
4268
- month: vals.month,
4269
- day: vals.day,
4270
- hour: vals.hour === 24 ? 0 : vals.hour,
4271
- minute: vals.minute,
4272
- second: vals.second
4273
- };
4274
- }
4275
- function wallToEpoch(y, m, d, h, min, s, tz) {
4276
- const utcGuess = Date.UTC(y, m - 1, d, h, min, s);
4277
- const inTz = extractTzParts(utcGuess, tz);
4278
- return utcGuess - (Date.UTC(inTz.year, inTz.month - 1, inTz.day, inTz.hour, inTz.minute, inTz.second) - utcGuess);
4279
- }
4280
- var MiniPlainDate = class MiniPlainDate {
4281
- year;
4282
- month;
4283
- day;
4284
- constructor(year, month, day) {
4285
- this.year = year;
4286
- this.month = month;
4287
- this.day = day;
4288
- }
4289
- get dayOfWeek() {
4290
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4291
- }
4292
- get daysInWeek() {
4293
- return 7;
4294
- }
4295
- get daysInMonth() {
4296
- return daysInMonth(this.year, this.month);
4297
- }
4298
- get monthCode() {
4299
- return `M${pad2(this.month)}`;
4300
- }
4301
- add(dur) {
4302
- let y = this.year + (dur.years || 0);
4303
- let m = this.month + (dur.months || 0);
4304
- while (m > 12) {
4305
- m -= 12;
4306
- y += 1;
4307
- }
4308
- while (m < 1) {
4309
- m += 12;
4310
- y -= 1;
4311
- }
4312
- const d = Math.min(this.day, daysInMonth(y, m));
4313
- const totalDays = (dur.days || 0) + (dur.weeks || 0) * 7;
4314
- if (totalDays === 0) return new MiniPlainDate(y, m, d);
4315
- const epoch = toUTC(y, m, d) + totalDays * 864e5;
4316
- const ud = new Date(epoch);
4317
- return new MiniPlainDate(ud.getUTCFullYear(), ud.getUTCMonth() + 1, ud.getUTCDate());
4318
- }
4319
- subtract(dur) {
4320
- return this.add({
4321
- days: dur.days ? -dur.days : void 0,
4322
- weeks: dur.weeks ? -dur.weeks : void 0,
4323
- months: dur.months ? -dur.months : void 0,
4324
- years: dur.years ? -dur.years : void 0
4325
- });
4326
- }
4327
- since(other, _opts) {
4328
- const thisUTC = toUTC(this.year, this.month, this.day);
4329
- const otherUTC = toUTC(other.year, other.month, other.day);
4330
- return { days: Math.round((thisUTC - otherUTC) / 864e5) };
4331
- }
4332
- until(other, _opts) {
4333
- const thisUTC = toUTC(this.year, this.month, this.day);
4334
- const otherUTC = toUTC(other.year, other.month, other.day);
4335
- return { days: Math.round((otherUTC - thisUTC) / 864e5) };
4336
- }
4337
- equals(other) {
4338
- return this.year === other.year && this.month === other.month && this.day === other.day;
4339
- }
4340
- toString() {
4341
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}`;
4342
- }
4343
- toZonedDateTime(tz) {
4344
- const tzId = typeof tz === "string" ? tz : tz.timeZone;
4345
- return this.toPlainDateTime().toZonedDateTime(tzId);
4346
- }
4347
- toPlainDateTime(timeLike) {
4348
- return new MiniPlainDateTime(this.year, this.month, this.day, timeLike?.hour ?? 0, timeLike?.minute ?? 0, timeLike?.second ?? 0);
4349
- }
4350
- toPlainMonthDay() {
4351
- return new MiniPlainMonthDay(this.month, this.day);
4352
- }
4353
- toPlainYearMonth() {
4354
- return new MiniPlainYearMonth(this.year, this.month);
4355
- }
4356
- toLocaleString(locale, options) {
4357
- return new Date(toUTC(this.year, this.month, this.day)).toLocaleDateString(locale, {
4358
- timeZone: "UTC",
4359
- ...options
4360
- });
4361
- }
4362
- };
4363
- var MiniPlainDateTime = class {
4364
- year;
4365
- month;
4366
- day;
4367
- hour;
4368
- minute;
4369
- second;
4370
- constructor(year, month, day, hour = 0, minute = 0, second = 0) {
4371
- this.year = year;
4372
- this.month = month;
4373
- this.day = day;
4374
- this.hour = hour;
4375
- this.minute = minute;
4376
- this.second = second;
4377
- }
4378
- get dayOfWeek() {
4379
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4380
- }
4381
- get daysInMonth() {
4382
- return daysInMonth(this.year, this.month);
4383
- }
4384
- toZonedDateTime(tz) {
4385
- const tzId = typeof tz === "string" ? tz : tz.timeZone;
4386
- return new MiniZonedDateTime(wallToEpoch(this.year, this.month, this.day, this.hour, this.minute, this.second, tzId), tzId);
4387
- }
4388
- toPlainDate() {
4389
- return new MiniPlainDate(this.year, this.month, this.day);
4390
- }
4391
- toString() {
4392
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}`;
4393
- }
4394
- };
4395
- var MiniPlainMonthDay = class {
4396
- monthCode;
4397
- month;
4398
- day;
4399
- constructor(month, day) {
4400
- this.month = month;
4401
- this.day = day;
4402
- this.monthCode = `M${pad2(month)}`;
4403
- }
4404
- toPlainDate(fields) {
4405
- return new MiniPlainDate(fields.year, this.month, this.day);
4406
- }
4407
- equals(other) {
4408
- return this.month === other.month && this.day === other.day;
4409
- }
4410
- toString() {
4411
- return `${pad2(this.month)}-${pad2(this.day)}`;
4412
- }
4413
- };
4414
- var MiniPlainYearMonth = class MiniPlainYearMonth {
4415
- year;
4416
- month;
4417
- constructor(year, month) {
4418
- this.year = year;
4419
- this.month = month;
4420
- }
4421
- get monthCode() {
4422
- return `M${pad2(this.month)}`;
4423
- }
4424
- get daysInMonth() {
4425
- return daysInMonth(this.year, this.month);
4426
- }
4427
- toPlainDate(fields) {
4428
- return new MiniPlainDate(this.year, this.month, fields.day);
4429
- }
4430
- add(dur) {
4431
- let y = this.year + (dur.years || 0);
4432
- let m = this.month + (dur.months || 0);
4433
- while (m > 12) {
4434
- m -= 12;
4435
- y += 1;
4436
- }
4437
- while (m < 1) {
4438
- m += 12;
4439
- y -= 1;
4440
- }
4441
- return new MiniPlainYearMonth(y, m);
4442
- }
4443
- subtract(dur) {
4444
- return this.add({
4445
- months: dur.months ? -dur.months : void 0,
4446
- years: dur.years ? -dur.years : void 0
4447
- });
4448
- }
4449
- equals(other) {
4450
- return this.year === other.year && this.month === other.month;
4451
- }
4452
- toString() {
4453
- return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}`;
4454
- }
4455
- };
4456
- var MiniZonedDateTime = class {
4457
- epochMilliseconds;
4458
- timeZoneId;
4459
- _parts;
4460
- constructor(epochMs, timeZoneId) {
4461
- this.epochMilliseconds = epochMs;
4462
- this.timeZoneId = timeZoneId;
4463
- }
4464
- get parts() {
4465
- if (!this._parts) this._parts = extractTzParts(this.epochMilliseconds, this.timeZoneId);
4466
- return this._parts;
4467
- }
4468
- get year() {
4469
- return this.parts.year;
4470
- }
4471
- get month() {
4472
- return this.parts.month;
4473
- }
4474
- get day() {
4475
- return this.parts.day;
4476
- }
4477
- get hour() {
4478
- return this.parts.hour;
4479
- }
4480
- get minute() {
4481
- return this.parts.minute;
4482
- }
4483
- get second() {
4484
- return this.parts.second;
4485
- }
4486
- get dayOfWeek() {
4487
- return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4488
- }
4489
- toPlainDate() {
4490
- return new MiniPlainDate(this.year, this.month, this.day);
4491
- }
4492
- toPlainDateTime() {
4493
- return new MiniPlainDateTime(this.year, this.month, this.day, this.hour, this.minute, this.second);
4494
- }
4495
- toPlainTime() {
4496
- return {
4497
- hour: this.hour,
4498
- minute: this.minute,
4499
- second: this.second
4500
- };
4501
- }
4502
- toPlainYearMonth() {
4503
- return new MiniPlainYearMonth(this.year, this.month);
4504
- }
4505
- toString() {
4506
- 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}]`;
4507
- }
4508
- };
4509
- const PlainDate = {
4510
- from(item, options) {
4511
- if (typeof item === "string") {
4512
- const { year, month, day } = parseDateISO(item);
4513
- if (options?.overflow === "constrain") return new MiniPlainDate(year, month, clamp(day, 1, daysInMonth(year, month)));
4514
- return new MiniPlainDate(year, month, day);
4515
- }
4516
- const year = item.year;
4517
- const month = item.month;
4518
- let day = item.day;
4519
- if (options?.overflow === "constrain") day = clamp(day, 1, daysInMonth(year, month));
4520
- return new MiniPlainDate(year, month, day);
4521
- },
4522
- compare(a, b) {
4523
- if (a.year !== b.year) return Math.sign(a.year - b.year);
4524
- if (a.month !== b.month) return Math.sign(a.month - b.month);
4525
- if (a.day !== b.day) return Math.sign(a.day - b.day);
4526
- return 0;
4527
- }
4528
- };
4529
- const PlainDateTime = { from(item, _options) {
4530
- if (typeof item === "string") {
4531
- const { year, month, day, hour, minute, second } = parseDateTimeISO(item);
4532
- return new MiniPlainDateTime(year, month, day, hour, minute, second);
4533
- }
4534
- return new MiniPlainDateTime(item.year, item.month, item.day, item.hour ?? 0, item.minute ?? 0, item.second ?? 0);
4535
- } };
4536
- const PlainMonthDay = { from(item) {
4537
- if (typeof item === "string") {
4538
- const parts = item.split("-").map(Number);
4539
- if (parts.length >= 3) return new MiniPlainMonthDay(parts[1], parts[2]);
4540
- return new MiniPlainMonthDay(parts[0], parts[1]);
4541
- }
4542
- return new MiniPlainMonthDay(item.month ?? (item.monthCode ? Number.parseInt(item.monthCode.slice(1), 10) : 1), item.day);
4543
- } };
4544
- const PlainYearMonth = {
4545
- from(item) {
4546
- if (typeof item === "string") {
4547
- const [y, m] = item.split("-").map(Number);
4548
- return new MiniPlainYearMonth(y, m);
4549
- }
4550
- return new MiniPlainYearMonth(item.year, item.month);
4551
- },
4552
- compare(a, b) {
4553
- if (a.year !== b.year) return Math.sign(a.year - b.year);
4554
- if (a.month !== b.month) return Math.sign(a.month - b.month);
4555
- return 0;
4556
- }
4557
- };
4558
- const Now = {
4559
- timeZoneId() {
4560
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
4561
- },
4562
- zonedDateTimeISO(tz) {
4563
- return new MiniZonedDateTime(Date.now(), tz ?? Now.timeZoneId());
4564
- },
4565
- plainDateISO() {
4566
- const tz = Now.timeZoneId();
4567
- const parts = extractTzParts(Date.now(), tz);
4568
- return new MiniPlainDate(parts.year, parts.month, parts.day);
4569
- }
4570
- };
4571
- const Temporal = {
4572
- Now,
4573
- PlainDate,
4574
- PlainDateTime,
4575
- PlainMonthDay,
4576
- PlainYearMonth
4577
- };
4578
- //#endregion
4579
4347
  Object.defineProperty(exports, "CalendarProvider", {
4580
4348
  enumerable: true,
4581
4349
  get: function() {
@@ -4738,12 +4506,6 @@ Object.defineProperty(exports, "RangeStartDragHandle", {
4738
4506
  return RangeStartDragHandle;
4739
4507
  }
4740
4508
  });
4741
- Object.defineProperty(exports, "Temporal", {
4742
- enumerable: true,
4743
- get: function() {
4744
- return Temporal;
4745
- }
4746
- });
4747
4509
  Object.defineProperty(exports, "TimeString", {
4748
4510
  enumerable: true,
4749
4511
  get: function() {