@klinking/colander 3.1.0-alpha.4 → 3.1.0-alpha.6

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 (55) hide show
  1. package/dist/formats/date.cjs +1 -1
  2. package/dist/formats/date.d.cts +1 -1
  3. package/dist/formats/date.d.mts +1 -1
  4. package/dist/formats/date.mjs +1 -1
  5. package/dist/formats/object.cjs +1 -1
  6. package/dist/formats/object.d.cts +1 -1
  7. package/dist/formats/object.d.mts +1 -1
  8. package/dist/formats/object.mjs +1 -1
  9. package/dist/formats/plain-date-time.cjs +1 -1
  10. package/dist/formats/plain-date-time.d.cts +1 -1
  11. package/dist/formats/plain-date-time.d.mts +1 -1
  12. package/dist/formats/plain-date-time.mjs +1 -1
  13. package/dist/formats/plain-date.cjs +1 -1
  14. package/dist/formats/plain-date.d.cts +1 -1
  15. package/dist/formats/plain-date.d.mts +1 -1
  16. package/dist/formats/plain-date.mjs +1 -1
  17. package/dist/formats/plain-month-day.cjs +1 -1
  18. package/dist/formats/plain-month-day.d.cts +1 -1
  19. package/dist/formats/plain-month-day.d.mts +1 -1
  20. package/dist/formats/plain-month-day.mjs +1 -1
  21. package/dist/formats/plain-year-month.cjs +1 -1
  22. package/dist/formats/plain-year-month.d.cts +1 -1
  23. package/dist/formats/plain-year-month.d.mts +1 -1
  24. package/dist/formats/plain-year-month.mjs +1 -1
  25. package/dist/formats/zoned-date-time.cjs +1 -1
  26. package/dist/formats/zoned-date-time.d.cts +1 -1
  27. package/dist/formats/zoned-date-time.d.mts +1 -1
  28. package/dist/formats/zoned-date-time.mjs +1 -1
  29. package/dist/{weeks-view-context-CUCy8njs.d.cts → index-DnFCKyyw.d.cts} +71 -8
  30. package/dist/{weeks-view-context-E1NwyNgQ.d.mts → index-q3cQKJdA.d.mts} +71 -8
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +2 -11
  33. package/dist/index.d.mts +2 -11
  34. package/dist/index.mjs +1 -1
  35. package/dist/{weeks-navigation-elCpdfQ3.mjs → weeks-navigation-Dn3UtG76.mjs} +578 -589
  36. package/dist/{weeks-navigation-DV538__x.cjs → weeks-navigation-SuKJZJCM.cjs} +578 -589
  37. package/package.json +1 -1
  38. package/src/calendar-provider.tsx +10 -55
  39. package/src/day-cell-state.test.ts +214 -0
  40. package/src/day-cell-state.ts +314 -0
  41. package/src/day-cell.tsx +29 -383
  42. package/src/month-view-navigation.ts +180 -0
  43. package/src/month-view-types.ts +3 -0
  44. package/src/month-view.bounds.test.tsx +136 -0
  45. package/src/month-view.tsx +37 -205
  46. package/src/month-window.test.ts +207 -0
  47. package/src/month-window.ts +93 -0
  48. package/src/navigation.tsx +15 -74
  49. package/src/range-preview.test.ts +120 -0
  50. package/src/root-selection.ts +99 -97
  51. package/src/weeks-navigation.tsx +7 -32
  52. package/src/weeks-view-state.ts +24 -81
  53. package/src/weeks-view-types.ts +4 -1
  54. package/src/weeks-window.test.ts +43 -0
  55. package/src/weeks-window.ts +64 -0
@@ -485,6 +485,18 @@ function tagRaw(raw, format) {
485
485
  value: raw
486
486
  };
487
487
  }
488
+ /**
489
+ * Decodes a range value into committed dates. An empty range is `[]`; a range
490
+ * with only an end is `[end, null]` (pending start, so the end is still the
491
+ * anchor of the next click).
492
+ */
493
+ function decodeRange(range, toPlain) {
494
+ const start = range.start != null ? toPlain(range.start) : null;
495
+ const end = range.end != null ? toPlain(range.end) : null;
496
+ if (start === null && end === null) return [];
497
+ if (start === null && end !== null) return [end, null];
498
+ return [start, end];
499
+ }
488
500
  /** Resolve a `RangeMode` to a concrete "start" | "end" | "reset" action for inside-range clicks. */
489
501
  function resolveInsideAction(mode, date, start, end) {
490
502
  if (mode === "adjust-start") return "start";
@@ -763,23 +775,19 @@ function truncateDatesForMode(opts) {
763
775
  return clamped;
764
776
  }
765
777
  /**
766
- * Pure utility that computes the preview range for a hovered date, using the
767
- * same logic as the internal hook. Useful for deriving the preview in an
768
- * `onHoveredDateChange` handler without needing a controlled `previewRange`.
778
+ * The range a click on `hoveredDate` would produce, or `null` when the click
779
+ * would do nothing (read-only, disabled date). One path for both the
780
+ * provider's own preview and the public {@link computePreviewRange}.
769
781
  */
770
- function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T) {
771
- const Temporal = T ?? globalThis.Temporal;
772
- if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
773
- const rawStart = currentRange?.start != null ? Temporal.PlainDate.from(currentRange.start) : null;
774
- const rawEnd = currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end) : null;
775
- const committedDates = currentRange ? rawStart === null && rawEnd !== null ? [rawEnd, null] : [rawStart, rawEnd] : [];
782
+ function computeRangePreview(input) {
783
+ const { hoveredDate, committedDates, rangeMode, allowRangeReversal, readOnly, isDateDisabled, T } = input;
776
784
  const committedStart = committedDates[0] ?? void 0;
777
- const committedEnd = committedDates[1] ?? void 0;
778
- const noop = () => [];
785
+ const committedEnd = committedDates.length > 1 ? committedDates[committedDates.length - 1] ?? void 0 : committedStart;
786
+ const unused = () => [];
779
787
  const result = computeSelectionUpdate({
780
788
  date: hoveredDate,
781
- readOnly: false,
782
- isDateDisabled: () => false,
789
+ readOnly,
790
+ isDateDisabled,
783
791
  isMultiple: false,
784
792
  isRange: true,
785
793
  committedDates,
@@ -787,20 +795,42 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
787
795
  committedEnd,
788
796
  selectedZdt: void 0,
789
797
  rangeMode,
790
- allowRangeReversal: !preventRangeReversal,
791
- sortDates: (d) => [...d].sort((a, b) => Temporal.PlainDate.compare(a, b)),
792
- currentSingleFormatted: noop,
793
- currentRangeFormatted: () => currentRange,
794
- currentMultipleFormatted: noop,
798
+ allowRangeReversal,
799
+ sortDates: (d) => [...d].sort((a, b) => T.PlainDate.compare(a, b)),
800
+ currentSingleFormatted: unused,
801
+ currentRangeFormatted: unused,
802
+ currentMultipleFormatted: unused,
795
803
  resolvedFormat: "PlainDate",
796
804
  timeZone: "UTC",
797
- T: Temporal
805
+ T
798
806
  });
799
807
  if (result.skip || result.newDates.length === 0) return null;
800
808
  const start = result.newDates[0];
801
809
  const end = result.newDates.length > 1 ? result.newDates[1] : start;
802
810
  if (start == null || end == null) return null;
803
- return mkRange(start, end);
811
+ return [start, end];
812
+ }
813
+ /**
814
+ * Pure utility that computes the preview range for a hovered date, using the
815
+ * same logic as the built-in hover preview. Useful for deriving the preview in
816
+ * an `onHoveredDateChange` handler without needing a controlled `previewRange`.
817
+ *
818
+ * Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
819
+ * disables dates or is read-only; by default every date is selectable.
820
+ */
821
+ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T, options = {}) {
822
+ const Temporal = T ?? globalThis.Temporal;
823
+ if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
824
+ const preview = computeRangePreview({
825
+ hoveredDate,
826
+ committedDates: currentRange ? decodeRange(currentRange, (raw) => Temporal.PlainDate.from(raw)) : [],
827
+ rangeMode,
828
+ allowRangeReversal: !preventRangeReversal,
829
+ readOnly: options.readOnly ?? false,
830
+ isDateDisabled: options.isDateDisabled ?? (() => false),
831
+ T: Temporal
832
+ });
833
+ return preview ? mkRange(preview[0], preview[1]) : null;
804
834
  }
805
835
  //#endregion
806
836
  //#region src/calendar-provider.tsx
@@ -892,13 +922,7 @@ function CalendarProvider(props) {
892
922
  }
893
923
  if (isRange) {
894
924
  if (rangeValue === null) return [];
895
- if (rangeValue) {
896
- const start = rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
897
- const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
898
- if (start === null && end === null) return [];
899
- if (start === null && end !== null) return [end, null];
900
- return [start, end];
901
- }
925
+ if (rangeValue) return decodeRange(rangeValue, rawToPlain);
902
926
  return;
903
927
  }
904
928
  if (singleValue === null) return [];
@@ -932,13 +956,7 @@ function CalendarProvider(props) {
932
956
  if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
933
957
  return [];
934
958
  }
935
- if (rangeDefault) {
936
- const start = rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
937
- const end = rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
938
- if (start === null && end === null) return [];
939
- if (start === null && end !== null) return [end, null];
940
- return [start, end];
941
- }
959
+ if (rangeDefault) return decodeRange(rangeDefault, rawToPlain);
942
960
  if (singleDefault != null) return [rawToPlain(singleDefault)];
943
961
  return [];
944
962
  }, [
@@ -1024,40 +1042,18 @@ function CalendarProvider(props) {
1024
1042
  const [previewStart, previewEnd] = useMemo(() => {
1025
1043
  if (previewRangeProp !== void 0) {
1026
1044
  if (!previewRangeProp) return [void 0, void 0];
1027
- const rawToPlainLocal = (raw) => {
1028
- return toZonedDateTime({
1029
- format: resolvedFormat,
1030
- value: raw
1031
- }, timeZone, T).toPlainDate();
1032
- };
1033
- return [previewRangeProp.start != null ? rawToPlainLocal(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlainLocal(previewRangeProp.end) : void 0];
1045
+ return [previewRangeProp.start != null ? rawToPlain(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlain(previewRangeProp.end) : void 0];
1034
1046
  }
1035
1047
  if (!hoveredDate || !isRange) return [void 0, void 0];
1036
- const result = computeSelectionUpdate({
1037
- date: hoveredDate,
1048
+ return computeRangePreview({
1049
+ hoveredDate,
1038
1050
  readOnly,
1039
1051
  isDateDisabled,
1040
- isMultiple: false,
1041
- isRange: true,
1042
1052
  committedDates,
1043
- committedStart,
1044
- committedEnd,
1045
- selectedZdt: void 0,
1046
1053
  rangeMode,
1047
1054
  allowRangeReversal,
1048
- sortDates,
1049
- currentSingleFormatted,
1050
- currentRangeFormatted,
1051
- currentMultipleFormatted,
1052
- resolvedFormat,
1053
- timeZone,
1054
1055
  T
1055
- });
1056
- if (result.skip || result.newDates.length === 0) return [void 0, void 0];
1057
- const ps = result.newDates[0];
1058
- const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
1059
- if (ps == null || pe == null) return [void 0, void 0];
1060
- return [ps, pe];
1056
+ }) ?? [void 0, void 0];
1061
1057
  }, [
1062
1058
  previewRangeProp,
1063
1059
  hoveredDate,
@@ -1065,16 +1061,9 @@ function CalendarProvider(props) {
1065
1061
  readOnly,
1066
1062
  isDateDisabled,
1067
1063
  committedDates,
1068
- committedStart,
1069
- committedEnd,
1070
1064
  rangeMode,
1071
1065
  allowRangeReversal,
1072
- sortDates,
1073
- currentSingleFormatted,
1074
- currentRangeFormatted,
1075
- currentMultipleFormatted,
1076
- resolvedFormat,
1077
- timeZone,
1066
+ rawToPlain,
1078
1067
  T
1079
1068
  ]);
1080
1069
  const prevModeRef = useRef(selectionMode);
@@ -1307,6 +1296,177 @@ function useMonthViewState() {
1307
1296
  return ctx;
1308
1297
  }
1309
1298
  //#endregion
1299
+ //#region src/month-view-navigation.ts
1300
+ /**
1301
+ * Owns which month the view shows, in both controlled and uncontrolled mode:
1302
+ * the month state, the Prev/Next steps, and syncing the window with focus.
1303
+ *
1304
+ * `onMonthChange` fires exactly once per move: from the effect below when
1305
+ * uncontrolled, and from the step or the focus-sync effect when controlled.
1306
+ */
1307
+ function useMonthNavigation(input) {
1308
+ const { month, defaultMonth, initialAnchor, onMonthChange, policy, focusedDate, setFocusedDate, T } = input;
1309
+ const isControlled = month !== void 0;
1310
+ const [internalMonth, setInternalMonth] = useState(() => {
1311
+ if (month) return {
1312
+ year: month.year,
1313
+ month: month.month
1314
+ };
1315
+ if (defaultMonth) return {
1316
+ year: defaultMonth.year,
1317
+ month: defaultMonth.month
1318
+ };
1319
+ const anchor = initialAnchor();
1320
+ return {
1321
+ year: anchor.year,
1322
+ month: anchor.month
1323
+ };
1324
+ });
1325
+ const year = isControlled ? month.year : internalMonth.year;
1326
+ const monthNumber = isControlled ? month.month : internalMonth.month;
1327
+ const currentMonth = useMemo(() => ({
1328
+ year,
1329
+ month: monthNumber
1330
+ }), [year, monthNumber]);
1331
+ const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
1332
+ year,
1333
+ month: monthNumber
1334
+ }), [
1335
+ year,
1336
+ monthNumber,
1337
+ T
1338
+ ]);
1339
+ const onMonthChangeRef = useRef(onMonthChange);
1340
+ onMonthChangeRef.current = onMonthChange;
1341
+ const notifyMonth = useCallback((target) => {
1342
+ onMonthChangeRef.current?.(T.PlainYearMonth.from(target));
1343
+ }, [T]);
1344
+ const skipFocusSyncForRef = useRef(null);
1345
+ const prevFocusedRef = useRef(focusedDate);
1346
+ useEffect(() => {
1347
+ skipFocusSyncForRef.current = null;
1348
+ }, [month?.year, month?.month]);
1349
+ useEffect(() => {
1350
+ const prevFocused = prevFocusedRef.current;
1351
+ prevFocusedRef.current = focusedDate;
1352
+ const target = {
1353
+ year: focusedDate.year,
1354
+ month: focusedDate.month
1355
+ };
1356
+ if (isControlled) {
1357
+ if (skipFocusSyncForRef.current === focusedDate) {
1358
+ skipFocusSyncForRef.current = null;
1359
+ return;
1360
+ }
1361
+ if (prevFocused === focusedDate) return;
1362
+ if (policy.isVisible(currentMonth, target)) return;
1363
+ notifyMonth(policy.reveal(currentMonth, target));
1364
+ return;
1365
+ }
1366
+ setInternalMonth((prev) => {
1367
+ const next = policy.reveal(prev, target);
1368
+ if (next.year === prev.year && next.month === prev.month) return prev;
1369
+ return next;
1370
+ });
1371
+ }, [
1372
+ focusedDate,
1373
+ isControlled,
1374
+ policy,
1375
+ currentMonth,
1376
+ notifyMonth
1377
+ ]);
1378
+ const mountedRef = useRef(false);
1379
+ useEffect(() => {
1380
+ if (!mountedRef.current) {
1381
+ mountedRef.current = true;
1382
+ return;
1383
+ }
1384
+ if (isControlled) return;
1385
+ onMonthChangeRef.current?.(viewingYearMonth);
1386
+ }, [viewingYearMonth, isControlled]);
1387
+ const go = useCallback((direction) => {
1388
+ if (isControlled) {
1389
+ const step = policy.step(month, direction);
1390
+ if (step.blocked) return;
1391
+ const nextFocus = focusedDateForMonth(focusedDate, step.start, step.firstDay);
1392
+ skipFocusSyncForRef.current = nextFocus;
1393
+ notifyMonth(step.start);
1394
+ setFocusedDate(nextFocus);
1395
+ return;
1396
+ }
1397
+ setInternalMonth((m) => {
1398
+ const step = policy.step(m, direction);
1399
+ if (step.blocked) return m;
1400
+ setFocusedDate((prev) => focusedDateForMonth(prev, step.start, step.firstDay));
1401
+ return step.start;
1402
+ });
1403
+ }, [
1404
+ isControlled,
1405
+ month,
1406
+ policy,
1407
+ notifyMonth,
1408
+ focusedDate,
1409
+ setFocusedDate
1410
+ ]);
1411
+ return {
1412
+ currentMonth,
1413
+ viewingYearMonth,
1414
+ goNextMonth: useCallback(() => go("next"), [go]),
1415
+ goPrevMonth: useCallback(() => go("prev"), [go])
1416
+ };
1417
+ }
1418
+ //#endregion
1419
+ //#region src/month-window.ts
1420
+ const monthIndex = (m) => m.year * 12 + (m.month - 1);
1421
+ /**
1422
+ * Builds the policy for a MonthView window of `numberOfMonths` months.
1423
+ *
1424
+ * `unbounded` never blocks a step: `min`/`max` only gate which days are
1425
+ * selectable, not which months can be viewed. Any other behavior is `stop`,
1426
+ * which blocks a step whose entering month lies beyond the bound's month.
1427
+ */
1428
+ function createMonthWindowPolicy(input) {
1429
+ const { numberOfMonths, behavior, min, max, T } = input;
1430
+ return {
1431
+ step(start, direction) {
1432
+ const adjacent = computeAdjacentMonth(start, direction, T);
1433
+ const newStart = {
1434
+ year: adjacent.year,
1435
+ month: adjacent.month
1436
+ };
1437
+ const entering = direction === "prev" ? newStart : monthAt(newStart, numberOfMonths - 1);
1438
+ let blocked = false;
1439
+ if (behavior !== "unbounded") {
1440
+ const bound = direction === "prev" ? min : max;
1441
+ if (bound) {
1442
+ const diff = monthIndex(entering) - monthIndex(bound);
1443
+ blocked = direction === "prev" ? diff < 0 : diff > 0;
1444
+ }
1445
+ }
1446
+ return {
1447
+ start: newStart,
1448
+ entering,
1449
+ firstDay: adjacent.firstDay,
1450
+ blocked
1451
+ };
1452
+ },
1453
+ isVisible(start, target) {
1454
+ const offset = monthIndex(target) - monthIndex(start);
1455
+ return offset >= 0 && offset < numberOfMonths;
1456
+ },
1457
+ reveal(start, target) {
1458
+ return shiftWindowToMonth(start, target, numberOfMonths);
1459
+ }
1460
+ };
1461
+ }
1462
+ function monthAt(start, offset) {
1463
+ const index = monthIndex(start) + offset;
1464
+ return {
1465
+ year: Math.floor(index / 12),
1466
+ month: index % 12 + 1
1467
+ };
1468
+ }
1469
+ //#endregion
1310
1470
  //#region src/view-context.ts
1311
1471
  /** @internal React context for the active view (MonthView or WeeksView). */
1312
1472
  const ViewContext = createContext(null);
@@ -1344,29 +1504,38 @@ function MonthViewRoot(props) {
1344
1504
  const calState = useCalendarState();
1345
1505
  const T = calStable.temporal;
1346
1506
  const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
1347
- const isMonthControlled = monthProp !== void 0;
1348
- const [internalMonth, setInternalMonth] = useState(() => {
1349
- if (monthProp) return {
1350
- year: monthProp.year,
1351
- month: monthProp.month
1352
- };
1353
- if (defaultMonthProp) return {
1354
- year: defaultMonthProp.year,
1355
- month: defaultMonthProp.month
1356
- };
1357
- const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
1358
- return {
1359
- year: anchor.year,
1360
- month: anchor.month
1361
- };
1362
- });
1363
- const currentMonth = isMonthControlled ? {
1364
- year: monthProp.year,
1365
- month: monthProp.month
1366
- } : internalMonth;
1367
1507
  const [focusedDate, setFocusedDate] = useState(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
1368
1508
  const [gridHasFocus, setGridHasFocus] = useState(false);
1369
1509
  const gridFocusedRef = useRef(false);
1510
+ const { minValue, maxValue } = calStable;
1511
+ const windowPolicy = useMemo(() => createMonthWindowPolicy({
1512
+ numberOfMonths,
1513
+ behavior: outOfRangeBehavior,
1514
+ min: minValue,
1515
+ max: maxValue,
1516
+ T
1517
+ }), [
1518
+ numberOfMonths,
1519
+ outOfRangeBehavior,
1520
+ minValue,
1521
+ maxValue,
1522
+ T
1523
+ ]);
1524
+ const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
1525
+ month: monthProp,
1526
+ defaultMonth: defaultMonthProp,
1527
+ initialAnchor: useCallback(() => resolveInitialAnchor(calState.selected, today, timeZone, T), [
1528
+ calState.selected,
1529
+ today,
1530
+ timeZone,
1531
+ T
1532
+ ]),
1533
+ onMonthChange,
1534
+ policy: windowPolicy,
1535
+ focusedDate,
1536
+ setFocusedDate,
1537
+ T
1538
+ });
1370
1539
  const [gridLabelIds, setGridLabelIds] = useState({});
1371
1540
  const setGridLabelId = useCallback((monthIndex, id) => {
1372
1541
  setGridLabelIds((prev) => {
@@ -1383,140 +1552,6 @@ function MonthViewRoot(props) {
1383
1552
  };
1384
1553
  });
1385
1554
  }, []);
1386
- const onMonthChangeRef = useRef(onMonthChange);
1387
- onMonthChangeRef.current = onMonthChange;
1388
- const notifyMonth = useCallback((year, month) => {
1389
- onMonthChangeRef.current?.(T.PlainYearMonth.from({
1390
- year,
1391
- month
1392
- }));
1393
- }, [T]);
1394
- const isMonthVisible = useCallback((targetYear, targetMonth) => {
1395
- for (let i = 0; i < numberOfMonths; i++) {
1396
- const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1397
- const y = Math.floor(totalMonths / 12);
1398
- const m = totalMonths % 12 + 1;
1399
- if (targetYear === y && targetMonth === m) return true;
1400
- }
1401
- return false;
1402
- }, [
1403
- currentMonth.year,
1404
- currentMonth.month,
1405
- numberOfMonths
1406
- ]);
1407
- const navigateToMonth = useCallback((targetYear, targetMonth) => {
1408
- if (isMonthControlled) return;
1409
- setInternalMonth((prev) => {
1410
- const next = shiftWindowToMonth(prev, {
1411
- year: targetYear,
1412
- month: targetMonth
1413
- }, numberOfMonths);
1414
- if (next.year === prev.year && next.month === prev.month) return prev;
1415
- return next;
1416
- });
1417
- }, [isMonthControlled, numberOfMonths]);
1418
- const skipFocusSyncForRef = useRef(null);
1419
- const prevFocusedRef = useRef(focusedDate);
1420
- useEffect(() => {
1421
- skipFocusSyncForRef.current = null;
1422
- }, [monthProp?.year, monthProp?.month]);
1423
- useEffect(() => {
1424
- const prevFocused = prevFocusedRef.current;
1425
- prevFocusedRef.current = focusedDate;
1426
- if (isMonthControlled) {
1427
- if (skipFocusSyncForRef.current === focusedDate) {
1428
- skipFocusSyncForRef.current = null;
1429
- return;
1430
- }
1431
- if (prevFocused === focusedDate) return;
1432
- if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
1433
- const next = shiftWindowToMonth({
1434
- year: currentMonth.year,
1435
- month: currentMonth.month
1436
- }, {
1437
- year: focusedDate.year,
1438
- month: focusedDate.month
1439
- }, numberOfMonths);
1440
- notifyMonth(next.year, next.month);
1441
- return;
1442
- }
1443
- navigateToMonth(focusedDate.year, focusedDate.month);
1444
- }, [
1445
- focusedDate,
1446
- navigateToMonth,
1447
- isMonthControlled,
1448
- isMonthVisible,
1449
- notifyMonth,
1450
- currentMonth.year,
1451
- currentMonth.month,
1452
- numberOfMonths
1453
- ]);
1454
- const goNextMonth = useCallback(() => {
1455
- if (isMonthControlled) {
1456
- const { year, month, firstDay } = computeAdjacentMonth({
1457
- year: monthProp.year,
1458
- month: monthProp.month
1459
- }, "next", T);
1460
- const nextFocus = focusedDateForMonth(focusedDate, {
1461
- year,
1462
- month
1463
- }, firstDay);
1464
- skipFocusSyncForRef.current = nextFocus;
1465
- notifyMonth(year, month);
1466
- setFocusedDate(nextFocus);
1467
- return;
1468
- }
1469
- setInternalMonth((m) => {
1470
- const { year, month, firstDay } = computeAdjacentMonth(m, "next", T);
1471
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1472
- year,
1473
- month
1474
- }, firstDay));
1475
- return {
1476
- year,
1477
- month
1478
- };
1479
- });
1480
- }, [
1481
- T,
1482
- isMonthControlled,
1483
- monthProp,
1484
- notifyMonth,
1485
- focusedDate
1486
- ]);
1487
- const goPrevMonth = useCallback(() => {
1488
- if (isMonthControlled) {
1489
- const { year, month, firstDay } = computeAdjacentMonth({
1490
- year: monthProp.year,
1491
- month: monthProp.month
1492
- }, "prev", T);
1493
- const nextFocus = focusedDateForMonth(focusedDate, {
1494
- year,
1495
- month
1496
- }, firstDay);
1497
- skipFocusSyncForRef.current = nextFocus;
1498
- notifyMonth(year, month);
1499
- setFocusedDate(nextFocus);
1500
- return;
1501
- }
1502
- setInternalMonth((m) => {
1503
- const { year, month, firstDay } = computeAdjacentMonth(m, "prev", T);
1504
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1505
- year,
1506
- month
1507
- }, firstDay));
1508
- return {
1509
- year,
1510
- month
1511
- };
1512
- });
1513
- }, [
1514
- T,
1515
- isMonthControlled,
1516
- monthProp,
1517
- notifyMonth,
1518
- focusedDate
1519
- ]);
1520
1555
  const allMonths = useMemo(() => {
1521
1556
  const opts = {
1522
1557
  weekStartDay,
@@ -1576,19 +1611,6 @@ function MonthViewRoot(props) {
1576
1611
  T,
1577
1612
  gridHasFocus
1578
1613
  ]);
1579
- const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
1580
- year: currentMonth.year,
1581
- month: currentMonth.month
1582
- }), [currentMonth, T]);
1583
- const mountedRef = useRef(false);
1584
- useEffect(() => {
1585
- if (!mountedRef.current) {
1586
- mountedRef.current = true;
1587
- return;
1588
- }
1589
- if (isMonthControlled) return;
1590
- onMonthChangeRef.current?.(viewingYearMonth);
1591
- }, [viewingYearMonth, isMonthControlled]);
1592
1614
  const rootState = useMemo(() => ({
1593
1615
  ...calState.baseRootState,
1594
1616
  focused: focusedDate,
@@ -1603,6 +1625,7 @@ function MonthViewRoot(props) {
1603
1625
  fixedWeeks,
1604
1626
  outsideDays,
1605
1627
  outOfRangeBehavior,
1628
+ windowPolicy,
1606
1629
  goNextMonth,
1607
1630
  goPrevMonth,
1608
1631
  setGridLabelId,
@@ -1612,6 +1635,7 @@ function MonthViewRoot(props) {
1612
1635
  fixedWeeks,
1613
1636
  outsideDays,
1614
1637
  outOfRangeBehavior,
1638
+ windowPolicy,
1615
1639
  goNextMonth,
1616
1640
  goPrevMonth,
1617
1641
  setGridLabelId
@@ -2254,130 +2278,180 @@ function computeWeeksKeyNav(input) {
2254
2278
  }
2255
2279
  }
2256
2280
  //#endregion
2257
- //#region src/day-cell.tsx
2258
- /** Computes derived day cell state from context values. Pure function, no hooks. */
2259
- function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, today, T, selectionMode, outsideDays, previewStart, previewEnd) {
2260
- const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
2261
- if (!isCurrentMonth && outsideDays === "hidden") return {
2262
- root: rootState,
2281
+ //#region src/day-cell-state.ts
2282
+ const NO_RANGE = {
2283
+ rangeStart: false,
2284
+ rangeEnd: false,
2285
+ rangeBoundary: false,
2286
+ inRange: false,
2287
+ rangeIndex: false,
2288
+ rangeLength: false,
2289
+ rangeHasStart: false,
2290
+ rangeHasEnd: false,
2291
+ rangePreviewStart: false,
2292
+ rangePreviewEnd: false,
2293
+ rangePreviewBoundary: false,
2294
+ rangePreviewInRange: false,
2295
+ rangePreviewIndex: false,
2296
+ rangePreviewLength: false,
2297
+ rangePreviewHasStart: false,
2298
+ rangePreviewHasEnd: false
2299
+ };
2300
+ function computeRangeState(date, inputs) {
2301
+ const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
2302
+ if (selectionMode !== "range") return NO_RANGE;
2303
+ const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
2304
+ const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
2305
+ const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
2306
+ const effectiveStart = rangeStart ?? rangeEnd;
2307
+ const effectiveEnd = rangeEnd ?? rangeStart;
2308
+ const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
2309
+ const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
2310
+ const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
2311
+ return {
2312
+ rangeStart: isRangeStart,
2313
+ rangeEnd: isRangeEnd,
2314
+ rangeBoundary: isRangeStart || isRangeEnd,
2315
+ inRange,
2316
+ rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
2317
+ rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
2318
+ rangeHasStart: inRange && rangeStart !== void 0,
2319
+ rangeHasEnd: inRange && rangeEnd !== void 0,
2320
+ rangePreviewStart: isPreviewStart,
2321
+ rangePreviewEnd: isPreviewEnd,
2322
+ rangePreviewBoundary: isPreviewStart || isPreviewEnd,
2323
+ rangePreviewInRange: inPreview,
2324
+ rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
2325
+ rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
2326
+ rangePreviewHasStart: inPreview && previewStart !== void 0,
2327
+ rangePreviewHasEnd: inPreview && previewEnd !== void 0
2328
+ };
2329
+ }
2330
+ /** Derives the state of one day cell. Pure function, no hooks. */
2331
+ function computeDayCellState(date, position, inputs) {
2332
+ const { T, outsideDays } = inputs;
2333
+ const { columnIndex, month } = position;
2334
+ const isCurrentMonth = date.year === month.year && date.month === month.month;
2335
+ const base = {
2336
+ root: inputs.rootState,
2263
2337
  date,
2264
2338
  columnIndex,
2265
- orientation,
2339
+ orientation: inputs.orientation
2340
+ };
2341
+ if (!isCurrentMonth && outsideDays === "hidden") return {
2342
+ ...base,
2343
+ ...NO_RANGE,
2266
2344
  outsideMonth: true,
2267
2345
  hidden: true,
2268
2346
  selected: false,
2269
2347
  today: false,
2270
2348
  disabled: true,
2271
2349
  focused: false,
2272
- rangeStart: false,
2273
- rangeEnd: false,
2274
- rangeBoundary: false,
2275
- inRange: false,
2276
- rangeIndex: false,
2277
- rangeLength: false,
2278
- rangeHasStart: false,
2279
- rangeHasEnd: false,
2280
- rangePreviewStart: false,
2281
- rangePreviewEnd: false,
2282
- rangePreviewBoundary: false,
2283
- rangePreviewInRange: false,
2284
- rangePreviewIndex: false,
2285
- rangePreviewLength: false,
2286
- rangePreviewHasStart: false,
2287
- rangePreviewHasEnd: false,
2288
2350
  isTabTarget: false
2289
2351
  };
2290
- const isToday = T.PlainDate.compare(date, today) === 0;
2291
- const isRange = selectionMode === "range";
2292
- let isRangeStart = false;
2293
- let isRangeEnd = false;
2294
- let isInRangeDay = false;
2295
- let rangeIdx = false;
2296
- let rangeLen = false;
2297
- let isPreviewRangeStart = false;
2298
- let isPreviewRangeEnd = false;
2299
- let isInPreviewRange = false;
2300
- let previewIdx = false;
2301
- let previewLen = false;
2302
- if (isRange) {
2303
- isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
2304
- isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
2305
- isInRangeDay = isInRange(date, rangeStart, rangeEnd, T) !== false;
2306
- const effectiveStart = rangeStart ?? rangeEnd;
2307
- const effectiveEnd = rangeEnd ?? rangeStart;
2308
- rangeIdx = isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
2309
- rangeLen = isInRangeDay && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false;
2310
- isPreviewRangeStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
2311
- isPreviewRangeEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
2312
- isInPreviewRange = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
2313
- previewIdx = isInPreviewRange && previewStart ? date.since(previewStart).days : false;
2314
- previewLen = isInPreviewRange && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false;
2352
+ const isToday = T.PlainDate.compare(date, inputs.today) === 0;
2353
+ if (!isCurrentMonth && outsideDays !== "enabled") {
2354
+ const suppressRange = outsideDays === "disabled";
2355
+ return {
2356
+ ...base,
2357
+ ...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
2358
+ outsideMonth: true,
2359
+ hidden: false,
2360
+ selected: false,
2361
+ today: isToday,
2362
+ disabled: true,
2363
+ focused: false,
2364
+ isTabTarget: false
2365
+ };
2315
2366
  }
2316
- const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
2317
- const suppressRange = !isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
2318
- if (outsideNonInteractive) return {
2319
- root: rootState,
2320
- date,
2321
- columnIndex,
2322
- orientation,
2323
- outsideMonth: true,
2367
+ return {
2368
+ ...base,
2369
+ ...computeRangeState(date, inputs),
2370
+ outsideMonth: !isCurrentMonth,
2324
2371
  hidden: false,
2325
- selected: false,
2372
+ selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
2326
2373
  today: isToday,
2327
- disabled: true,
2328
- focused: false,
2329
- rangeStart: suppressRange ? false : isRangeStart,
2330
- rangeEnd: suppressRange ? false : isRangeEnd,
2331
- rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
2332
- inRange: suppressRange ? false : isInRangeDay,
2333
- rangeIndex: suppressRange ? false : rangeIdx,
2334
- rangeLength: suppressRange ? false : rangeLen,
2335
- rangeHasStart: suppressRange ? false : isInRangeDay && rangeStart !== void 0,
2336
- rangeHasEnd: suppressRange ? false : isInRangeDay && rangeEnd !== void 0,
2337
- rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
2338
- rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
2339
- rangePreviewBoundary: suppressRange ? false : isPreviewRangeStart || isPreviewRangeEnd,
2340
- rangePreviewInRange: suppressRange ? false : isInPreviewRange,
2341
- rangePreviewIndex: suppressRange ? false : previewIdx,
2342
- rangePreviewLength: suppressRange ? false : previewLen,
2343
- rangePreviewHasStart: suppressRange ? false : isInPreviewRange && previewStart !== void 0,
2344
- rangePreviewHasEnd: suppressRange ? false : isInPreviewRange && previewEnd !== void 0,
2345
- isTabTarget: false
2374
+ disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
2375
+ focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
2376
+ isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
2346
2377
  };
2347
- const isSelected = selectionMode !== "range" ? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false;
2348
- const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
2349
- const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
2350
- const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
2351
- return {
2352
- root: rootState,
2353
- date,
2354
- columnIndex,
2378
+ }
2379
+ const COMPARED_KEYS = Object.keys({
2380
+ outsideMonth: true,
2381
+ hidden: true,
2382
+ selected: true,
2383
+ today: true,
2384
+ disabled: true,
2385
+ focused: true,
2386
+ rangeStart: true,
2387
+ rangeEnd: true,
2388
+ rangeBoundary: true,
2389
+ inRange: true,
2390
+ rangeIndex: true,
2391
+ rangeLength: true,
2392
+ rangeHasStart: true,
2393
+ rangeHasEnd: true,
2394
+ rangePreviewStart: true,
2395
+ rangePreviewEnd: true,
2396
+ rangePreviewBoundary: true,
2397
+ rangePreviewInRange: true,
2398
+ rangePreviewIndex: true,
2399
+ rangePreviewLength: true,
2400
+ rangePreviewHasStart: true,
2401
+ rangePreviewHasEnd: true,
2402
+ isTabTarget: true
2403
+ });
2404
+ /** Whether two cell states render the same cell. */
2405
+ function dayCellStateEqual(a, b) {
2406
+ for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
2407
+ return true;
2408
+ }
2409
+ /**
2410
+ * Reads the contexts a day cell depends on and returns a function that derives
2411
+ * the state of any cell. `columnIndex` defaults to the date's column in a
2412
+ * week starting on the calendar's `weekStartDay`.
2413
+ */
2414
+ function useDayCellDeriver() {
2415
+ const { orientation } = useContext(GridContext);
2416
+ const weekData = useContext(WeekDataContext);
2417
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2418
+ const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2419
+ const viewCtx = useViewContext();
2420
+ const { focusedDate, tabTargetDate } = viewCtx;
2421
+ const { rootState, currentDateTime } = useViewState();
2422
+ const { outsideDays } = useViewStable();
2423
+ const inputs = {
2424
+ T,
2425
+ today: today(),
2355
2426
  orientation,
2356
- selected: isSelected,
2357
- today: isToday,
2358
- disabled: isDisabled,
2359
- outsideMonth: !isCurrentMonth,
2360
- hidden: false,
2361
- focused: isFocused,
2362
- rangeStart: isRangeStart,
2363
- rangeEnd: isRangeEnd,
2364
- rangeBoundary: isRangeStart || isRangeEnd,
2365
- inRange: isInRangeDay,
2366
- rangeIndex: rangeIdx,
2367
- rangeLength: rangeLen,
2368
- rangeHasStart: isInRangeDay && rangeStart !== void 0,
2369
- rangeHasEnd: isInRangeDay && rangeEnd !== void 0,
2370
- rangePreviewStart: isPreviewRangeStart,
2371
- rangePreviewEnd: isPreviewRangeEnd,
2372
- rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
2373
- rangePreviewInRange: isInPreviewRange,
2374
- rangePreviewIndex: previewIdx,
2375
- rangePreviewLength: previewLen,
2376
- rangePreviewHasStart: isInPreviewRange && previewStart !== void 0,
2377
- rangePreviewHasEnd: isInPreviewRange && previewEnd !== void 0,
2378
- isTabTarget
2427
+ rootState,
2428
+ selectionMode,
2429
+ selectedDates,
2430
+ rangeStart,
2431
+ rangeEnd,
2432
+ previewStart,
2433
+ previewEnd,
2434
+ disabled,
2435
+ isDateDisabled,
2436
+ focusedDate,
2437
+ tabTargetDate,
2438
+ outsideDays
2439
+ };
2440
+ const isWeeksView = viewCtx.viewType === "weeks";
2441
+ const gridMonth = weekData?.gridMonth ?? currentDateTime;
2442
+ return (date, columnIndex) => {
2443
+ const daysInWeek = date.daysInWeek;
2444
+ return computeDayCellState(date, {
2445
+ columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek,
2446
+ month: isWeeksView ? {
2447
+ year: date.year,
2448
+ month: date.month
2449
+ } : gridMonth
2450
+ }, inputs);
2379
2451
  };
2380
2452
  }
2453
+ //#endregion
2454
+ //#region src/day-cell.tsx
2381
2455
  const dayStateAttributesMapping = {
2382
2456
  root: () => null,
2383
2457
  date: (v) => v ? { "data-date": v.toString() } : null,
@@ -2464,9 +2538,7 @@ const DAY_BUTTON_HANDLED_KEYS = new Set([
2464
2538
  ]);
2465
2539
  function dayCellInstancePropsAreEqual(prev, next) {
2466
2540
  if (prev.date !== next.date || prev.render !== next.render || prev.columnIndex !== next.columnIndex) return false;
2467
- const a = prev._derivedState;
2468
- const b = next._derivedState;
2469
- return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
2541
+ return dayCellStateEqual(prev._derivedState, next._derivedState) && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
2470
2542
  }
2471
2543
  const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
2472
2544
  /**
@@ -2477,47 +2549,24 @@ const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
2477
2549
  * When used inside a {@link WeekTemplate}, iterates over that week's days.
2478
2550
  * An explicit `date` prop renders a single cell.
2479
2551
  */
2480
- function DayCellTemplate(props) {
2481
- const { date: dateProp, ...restProps } = props;
2482
- const weekData = useContext(WeekDataContext);
2483
- const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2484
- const todayDate = today();
2485
- const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2486
- const viewCtx = useViewContext();
2487
- const { focusedDate, tabTargetDate } = viewCtx;
2488
- const { rootState, currentDateTime } = useViewState();
2489
- const { outsideDays } = useViewStable();
2490
- const monthState = useContext(MonthViewStateContext);
2491
- const isWeeksView = viewCtx.viewType === "weeks";
2492
- const cellMonth = isWeeksView ? null : weekData?.gridMonth ?? currentDateTime;
2493
- const { orientation } = useContext(GridContext);
2494
- if (dateProp) {
2495
- const daysInWeek = dateProp.daysInWeek;
2496
- const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2497
- year: dateProp.year,
2498
- month: dateProp.month
2499
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2500
- return /* @__PURE__ */ jsx(DayCellInstance, {
2501
- ...restProps,
2502
- date: dateProp,
2503
- _derivedState: derived
2504
- });
2505
- }
2552
+ function DayCellTemplate(props) {
2553
+ const { date: dateProp, ...restProps } = props;
2554
+ const weekData = useContext(WeekDataContext);
2555
+ const monthState = useContext(MonthViewStateContext);
2556
+ const derive = useDayCellDeriver();
2557
+ if (dateProp) return /* @__PURE__ */ jsx(DayCellInstance, {
2558
+ ...restProps,
2559
+ date: dateProp,
2560
+ _derivedState: derive(dateProp)
2561
+ });
2506
2562
  const days = weekData ? weekData.days : monthState?.weeks.flat() ?? [];
2507
2563
  const perWeek = weekData != null;
2508
- return /* @__PURE__ */ jsx(Fragment, { children: days.map((day, i) => {
2509
- const daysInWeek = day.daysInWeek;
2510
- const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2511
- year: day.year,
2512
- month: day.month
2513
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2514
- return /* @__PURE__ */ jsx(DayCellInstance, {
2515
- ...restProps,
2516
- date: day,
2517
- columnIndex: perWeek ? i : void 0,
2518
- _derivedState: derived
2519
- }, day.toString());
2520
- }) });
2564
+ return /* @__PURE__ */ jsx(Fragment, { children: days.map((day, i) => /* @__PURE__ */ jsx(DayCellInstance, {
2565
+ ...restProps,
2566
+ date: day,
2567
+ columnIndex: perWeek ? i : void 0,
2568
+ _derivedState: derive(day, perWeek ? i : void 0)
2569
+ }, day.toString())) });
2521
2570
  }
2522
2571
  function DayButtonInnerFn(props, ref) {
2523
2572
  const { render, date, _derivedState, ...otherProps } = props;
@@ -2569,7 +2618,7 @@ function dayButtonInnerPropsAreEqual(prev, next) {
2569
2618
  const a = prev._derivedState;
2570
2619
  const b = next._derivedState;
2571
2620
  if (!a || !b) return a === b;
2572
- return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget;
2621
+ return dayCellStateEqual(a, b);
2573
2622
  }
2574
2623
  const DayButtonInner = memo(forwardRef(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
2575
2624
  /**
@@ -2601,26 +2650,12 @@ const DayButton = forwardRef(DayButtonFn);
2601
2650
  /** Fallback for standalone DayButton usage that needs to read context. */
2602
2651
  function DayButtonFallbackFn(props, ref) {
2603
2652
  const { date, ...restProps } = props;
2604
- const { orientation } = useContext(GridContext);
2605
- const weekData = useContext(WeekDataContext);
2606
- const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2607
- const todayDate = today();
2608
- const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2609
- const viewCtx = useViewContext();
2610
- const { focusedDate, tabTargetDate } = viewCtx;
2611
- const { rootState, currentDateTime } = useViewState();
2612
- const { outsideDays } = useViewStable();
2613
- const cellMonth = viewCtx.viewType === "weeks" ? {
2614
- year: date.year,
2615
- month: date.month
2616
- } : weekData?.gridMonth ?? currentDateTime;
2617
- const daysInWeek = date.daysInWeek;
2618
- const derived = computeDayCellState(date, orientation, (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2653
+ const derive = useDayCellDeriver();
2619
2654
  return /* @__PURE__ */ jsx(DayButtonInner, {
2620
2655
  ...restProps,
2621
2656
  ref,
2622
2657
  date,
2623
- _derivedState: derived
2658
+ _derivedState: derive(date)
2624
2659
  });
2625
2660
  }
2626
2661
  const DayButtonFallback = forwardRef(DayButtonFallbackFn);
@@ -3171,37 +3206,16 @@ function MonthYearStringFn(props, ref) {
3171
3206
  */
3172
3207
  const MonthYearString = forwardRef(MonthYearStringFn);
3173
3208
  function useNavButton(direction) {
3174
- const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
3175
- const monthViewStable = useMonthViewStable();
3176
- const monthViewState = useMonthViewState();
3177
- const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths, outOfRangeBehavior } = monthViewStable;
3178
- const { currentMonth: currentDateTime, allMonths, rootState } = monthViewState;
3179
- const refMonth = direction === "next" ? allMonths[numberOfMonths - 1] ?? currentDateTime : currentDateTime;
3180
- const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
3181
- const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
3182
- const boundValue = direction === "prev" ? minValue : maxValue;
3183
- const isDisabled = useMemo(() => {
3184
- if (globalDisabled) return true;
3185
- if (outOfRangeBehavior === "unbounded") return false;
3186
- if (!boundValue) return false;
3187
- if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
3188
- return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
3189
- }, [
3190
- globalDisabled,
3191
- outOfRangeBehavior,
3192
- destYear,
3193
- destMonth,
3194
- boundValue,
3209
+ const { disabled: globalDisabled, temporal: T } = useCalendarStable();
3210
+ const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, windowPolicy } = useMonthViewStable();
3211
+ const { currentMonth, rootState } = useMonthViewState();
3212
+ const step = useMemo(() => windowPolicy.step(currentMonth, direction), [
3213
+ windowPolicy,
3214
+ currentMonth,
3195
3215
  direction
3196
3216
  ]);
3197
- const target = useMemo(() => T.PlainYearMonth.from({
3198
- year: destYear,
3199
- month: destMonth
3200
- }), [
3201
- destYear,
3202
- destMonth,
3203
- T
3204
- ]);
3217
+ const isDisabled = globalDisabled || step.blocked;
3218
+ const target = useMemo(() => T.PlainYearMonth.from(step.entering), [step.entering, T]);
3205
3219
  return {
3206
3220
  state: useMemo(() => ({
3207
3221
  root: rootState,
@@ -3633,6 +3647,98 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
3633
3647
  return weeks;
3634
3648
  }
3635
3649
  //#endregion
3650
+ //#region src/resolve-first-week.ts
3651
+ /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3652
+ function snapToWeekStart(date, weekStartDay) {
3653
+ const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3654
+ return date.subtract({ days: offset });
3655
+ }
3656
+ /**
3657
+ * Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
3658
+ * containing week's start (snapped to `weekStartDay`).
3659
+ *
3660
+ * @param spec - The week specifier to resolve.
3661
+ * @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
3662
+ * @param T - Temporal namespace.
3663
+ * @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
3664
+ */
3665
+ function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
3666
+ if ("calendarId" in spec) {
3667
+ const pd = spec;
3668
+ return snapToWeekStart(pd.calendarId === "iso8601" ? pd : pd.withCalendar("iso8601"), weekStartDay);
3669
+ }
3670
+ if (spec instanceof Date) {
3671
+ const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
3672
+ const parts = new Intl.DateTimeFormat("en-US", {
3673
+ timeZone: tz,
3674
+ year: "numeric",
3675
+ month: "numeric",
3676
+ day: "numeric"
3677
+ }).formatToParts(spec);
3678
+ const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
3679
+ return snapToWeekStart(T.PlainDate.from({
3680
+ year: get("year"),
3681
+ month: get("month"),
3682
+ day: get("day")
3683
+ }), weekStartDay);
3684
+ }
3685
+ if ("isoWeek" in spec) {
3686
+ const { isoWeek, isoYear } = spec;
3687
+ const jan4 = T.PlainDate.from({
3688
+ year: isoYear,
3689
+ month: 1,
3690
+ day: 4
3691
+ });
3692
+ const jan4dow = jan4.dayOfWeek;
3693
+ return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
3694
+ }
3695
+ if ("week" in spec && !("month" in spec)) {
3696
+ const { week, year } = spec;
3697
+ const jan1 = T.PlainDate.from({
3698
+ year,
3699
+ month: 1,
3700
+ day: 1
3701
+ });
3702
+ const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
3703
+ return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
3704
+ }
3705
+ const { month, year, day } = spec;
3706
+ const targetDay = day ?? 1;
3707
+ return snapToWeekStart(T.PlainDate.from({
3708
+ year,
3709
+ month,
3710
+ day: targetDay
3711
+ }), weekStartDay);
3712
+ }
3713
+ /**
3714
+ * Computes a new `firstWeek` date given a scroll target and snap mode.
3715
+ *
3716
+ * The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
3717
+ *
3718
+ * @param currentFirstWeek - The current first visible week (a week-start date).
3719
+ * @param weekCount - Number of visible week rows.
3720
+ * @param target - The week-start date to scroll to.
3721
+ * @param options - Optional snap mode (default `"start"`).
3722
+ */
3723
+ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3724
+ switch (options?.snap ?? "start") {
3725
+ case "start": return target;
3726
+ case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
3727
+ case "end": return target.subtract({ weeks: weekCount - 1 });
3728
+ case "nearest": {
3729
+ const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
3730
+ const cmp = (a, b) => {
3731
+ if (a.year !== b.year) return a.year - b.year;
3732
+ if (a.month !== b.month) return a.month - b.month;
3733
+ return a.day - b.day;
3734
+ };
3735
+ if (cmp(target, currentFirstWeek) < 0) return target;
3736
+ if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
3737
+ return currentFirstWeek;
3738
+ }
3739
+ }
3740
+ }
3741
+ //#endregion
3636
3742
  //#region src/out-of-range.ts
3637
3743
  /** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
3638
3744
  function weekHasValidDay(weekStart, min, max, T) {
@@ -3740,96 +3846,28 @@ function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, m
3740
3846
  return true;
3741
3847
  }
3742
3848
  //#endregion
3743
- //#region src/resolve-first-week.ts
3744
- /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3745
- function snapToWeekStart(date, weekStartDay) {
3746
- const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3747
- return date.subtract({ days: offset });
3748
- }
3749
- /**
3750
- * Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
3751
- * containing week's start (snapped to `weekStartDay`).
3752
- *
3753
- * @param spec - The week specifier to resolve.
3754
- * @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
3755
- * @param T - Temporal namespace.
3756
- * @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
3757
- */
3758
- function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
3759
- if ("calendarId" in spec) {
3760
- const pd = spec;
3761
- return snapToWeekStart(pd.calendarId === "iso8601" ? pd : pd.withCalendar("iso8601"), weekStartDay);
3762
- }
3763
- if (spec instanceof Date) {
3764
- const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
3765
- const parts = new Intl.DateTimeFormat("en-US", {
3766
- timeZone: tz,
3767
- year: "numeric",
3768
- month: "numeric",
3769
- day: "numeric"
3770
- }).formatToParts(spec);
3771
- const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
3772
- return snapToWeekStart(T.PlainDate.from({
3773
- year: get("year"),
3774
- month: get("month"),
3775
- day: get("day")
3776
- }), weekStartDay);
3777
- }
3778
- if ("isoWeek" in spec) {
3779
- const { isoWeek, isoYear } = spec;
3780
- const jan4 = T.PlainDate.from({
3781
- year: isoYear,
3782
- month: 1,
3783
- day: 4
3784
- });
3785
- const jan4dow = jan4.dayOfWeek;
3786
- return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
3787
- }
3788
- if ("week" in spec && !("month" in spec)) {
3789
- const { week, year } = spec;
3790
- const jan1 = T.PlainDate.from({
3791
- year,
3792
- month: 1,
3793
- day: 1
3794
- });
3795
- const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
3796
- return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
3797
- }
3798
- const { month, year, day } = spec;
3799
- const targetDay = day ?? 1;
3800
- return snapToWeekStart(T.PlainDate.from({
3801
- year,
3802
- month,
3803
- day: targetDay
3804
- }), weekStartDay);
3805
- }
3806
- /**
3807
- * Computes a new `firstWeek` date given a scroll target and snap mode.
3808
- *
3809
- * The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
3810
- *
3811
- * @param currentFirstWeek - The current first visible week (a week-start date).
3812
- * @param weekCount - Number of visible week rows.
3813
- * @param target - The week-start date to scroll to.
3814
- * @param options - Optional snap mode (default `"start"`).
3815
- */
3816
- function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3817
- switch (options?.snap ?? "start") {
3818
- case "start": return target;
3819
- case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
3820
- case "end": return target.subtract({ weeks: weekCount - 1 });
3821
- case "nearest": {
3822
- const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
3823
- const cmp = (a, b) => {
3824
- if (a.year !== b.year) return a.year - b.year;
3825
- if (a.month !== b.month) return a.month - b.month;
3826
- return a.day - b.day;
3827
- };
3828
- if (cmp(target, currentFirstWeek) < 0) return target;
3829
- if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
3830
- return currentFirstWeek;
3831
- }
3832
- }
3849
+ //#region src/weeks-window.ts
3850
+ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
3851
+ const bounds = {
3852
+ weekCount,
3853
+ behavior,
3854
+ ...min !== void 0 && { min },
3855
+ ...max !== void 0 && { max },
3856
+ weekStartDay,
3857
+ T
3858
+ };
3859
+ return {
3860
+ resolve: (requestedFirstWeek) => applyOutOfRange({
3861
+ ...bounds,
3862
+ targetFirstWeek: requestedFirstWeek
3863
+ }),
3864
+ canShift: (currentFirstWeek, direction, shiftBy) => canShift({
3865
+ ...bounds,
3866
+ currentFirstWeek,
3867
+ direction,
3868
+ ...shiftBy !== void 0 && { shiftBy }
3869
+ })
3870
+ };
3833
3871
  }
3834
3872
  //#endregion
3835
3873
  //#region src/weeks-view-state.ts
@@ -3859,16 +3897,14 @@ function useWeeksViewRootState(props) {
3859
3897
  weekStartDay,
3860
3898
  T
3861
3899
  ]);
3862
- const outOfRangeResult = useMemo(() => applyOutOfRange({
3863
- targetFirstWeek: resolvedFirstWeek,
3900
+ const windowPolicy = useMemo(() => createWeekWindowPolicy({
3864
3901
  weekCount,
3865
3902
  behavior: outOfRangeBehavior,
3866
- ...minValue !== void 0 && { min: minValue },
3867
- ...maxValue !== void 0 && { max: maxValue },
3903
+ min: minValue,
3904
+ max: maxValue,
3868
3905
  weekStartDay,
3869
3906
  T
3870
3907
  }), [
3871
- resolvedFirstWeek,
3872
3908
  weekCount,
3873
3909
  outOfRangeBehavior,
3874
3910
  minValue,
@@ -3876,6 +3912,7 @@ function useWeeksViewRootState(props) {
3876
3912
  weekStartDay,
3877
3913
  T
3878
3914
  ]);
3915
+ const outOfRangeResult = useMemo(() => windowPolicy.resolve(resolvedFirstWeek), [windowPolicy, resolvedFirstWeek]);
3879
3916
  const adjustedWeeks = useMemo(() => {
3880
3917
  const sameFirst = T.PlainDate.compare(outOfRangeResult.firstWeek, resolvedFirstWeek) === 0;
3881
3918
  const sameCount = outOfRangeResult.weekCount === weekCount;
@@ -4054,66 +4091,31 @@ function useWeeksViewRootState(props) {
4054
4091
  onFirstWeekChange?.(newFirstWeek);
4055
4092
  }, [isControlled, onFirstWeekChange]);
4056
4093
  const goNext = useCallback((shiftBy) => {
4057
- const shift = shiftBy ?? weekCount;
4058
- updateFirstWeek(applyOutOfRange({
4059
- targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
4060
- weekCount,
4061
- behavior: outOfRangeBehavior,
4062
- ...minValue !== void 0 && { min: minValue },
4063
- ...maxValue !== void 0 && { max: maxValue },
4064
- weekStartDay,
4065
- T
4066
- }).firstWeek);
4094
+ const target = resolvedFirstWeek.add({ weeks: shiftBy ?? weekCount });
4095
+ updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4067
4096
  }, [
4068
4097
  resolvedFirstWeek,
4069
4098
  weekCount,
4070
- outOfRangeBehavior,
4071
- minValue,
4072
- maxValue,
4073
- weekStartDay,
4074
- T,
4099
+ windowPolicy,
4075
4100
  updateFirstWeek
4076
4101
  ]);
4077
4102
  const goPrev = useCallback((shiftBy) => {
4078
- const shift = shiftBy ?? weekCount;
4079
- updateFirstWeek(applyOutOfRange({
4080
- targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
4081
- weekCount,
4082
- behavior: outOfRangeBehavior,
4083
- ...minValue !== void 0 && { min: minValue },
4084
- ...maxValue !== void 0 && { max: maxValue },
4085
- weekStartDay,
4086
- T
4087
- }).firstWeek);
4103
+ const target = resolvedFirstWeek.subtract({ weeks: shiftBy ?? weekCount });
4104
+ updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4088
4105
  }, [
4089
4106
  resolvedFirstWeek,
4090
4107
  weekCount,
4091
- outOfRangeBehavior,
4092
- minValue,
4093
- maxValue,
4094
- weekStartDay,
4095
- T,
4108
+ windowPolicy,
4096
4109
  updateFirstWeek
4097
4110
  ]);
4098
4111
  const scrollToWeek = useCallback((target, options) => {
4099
- updateFirstWeek(applyOutOfRange({
4100
- targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
4101
- weekCount,
4102
- behavior: outOfRangeBehavior,
4103
- ...minValue !== void 0 && { min: minValue },
4104
- ...maxValue !== void 0 && { max: maxValue },
4105
- weekStartDay,
4106
- T
4107
- }).firstWeek);
4112
+ const newFirstWeek = resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options);
4113
+ updateFirstWeek(windowPolicy.resolve(newFirstWeek).firstWeek);
4108
4114
  }, [
4109
4115
  resolvedFirstWeek,
4110
4116
  weekCount,
4111
4117
  resolveSpec,
4112
- outOfRangeBehavior,
4113
- minValue,
4114
- maxValue,
4115
- weekStartDay,
4116
- T,
4118
+ windowPolicy,
4117
4119
  updateFirstWeek
4118
4120
  ]);
4119
4121
  const onWindowChangeRef = useRef(onWindowChange);
@@ -4130,6 +4132,7 @@ function useWeeksViewRootState(props) {
4130
4132
  weekCount,
4131
4133
  scrollBy,
4132
4134
  outOfRangeBehavior,
4135
+ windowPolicy,
4133
4136
  goNext,
4134
4137
  goPrev,
4135
4138
  scrollToWeek,
@@ -4139,6 +4142,7 @@ function useWeeksViewRootState(props) {
4139
4142
  weekCount,
4140
4143
  scrollBy,
4141
4144
  outOfRangeBehavior,
4145
+ windowPolicy,
4142
4146
  goNext,
4143
4147
  goPrev,
4144
4148
  scrollToWeek,
@@ -4252,35 +4256,20 @@ const weekCountStateAttributesMapping = {
4252
4256
  weekCount: () => null
4253
4257
  };
4254
4258
  function useWeeksNavButton(direction, shiftByProp) {
4255
- const { disabled: globalDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
4256
- const { weekCount, outOfRangeBehavior, goNext, goPrev } = useWeeksViewStable();
4259
+ const { disabled: globalDisabled } = useCalendarStable();
4260
+ const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
4257
4261
  const { windowInfo } = useWeeksViewState();
4258
4262
  const { rootState } = useViewState();
4259
4263
  const currentFirstWeek = windowInfo.windowStart;
4260
4264
  const isDisabled = useMemo(() => {
4261
4265
  if (globalDisabled) return true;
4262
- return !canShift({
4263
- currentFirstWeek,
4264
- weekCount,
4265
- direction: direction === "next" ? 1 : -1,
4266
- ...shiftByProp !== void 0 && { shiftBy: shiftByProp },
4267
- behavior: outOfRangeBehavior,
4268
- ...minValue !== void 0 && { min: minValue },
4269
- ...maxValue !== void 0 && { max: maxValue },
4270
- weekStartDay,
4271
- T
4272
- });
4266
+ return !windowPolicy.canShift(currentFirstWeek, direction === "next" ? 1 : -1, shiftByProp);
4273
4267
  }, [
4274
4268
  globalDisabled,
4269
+ windowPolicy,
4275
4270
  currentFirstWeek,
4276
- weekCount,
4277
4271
  direction,
4278
- shiftByProp,
4279
- outOfRangeBehavior,
4280
- minValue,
4281
- maxValue,
4282
- weekStartDay,
4283
- T
4272
+ shiftByProp
4284
4273
  ]);
4285
4274
  const state = useMemo(() => ({
4286
4275
  root: rootState,