@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
@@ -508,6 +508,18 @@ function tagRaw(raw, format) {
508
508
  value: raw
509
509
  };
510
510
  }
511
+ /**
512
+ * Decodes a range value into committed dates. An empty range is `[]`; a range
513
+ * with only an end is `[end, null]` (pending start, so the end is still the
514
+ * anchor of the next click).
515
+ */
516
+ function decodeRange(range, toPlain) {
517
+ const start = range.start != null ? toPlain(range.start) : null;
518
+ const end = range.end != null ? toPlain(range.end) : null;
519
+ if (start === null && end === null) return [];
520
+ if (start === null && end !== null) return [end, null];
521
+ return [start, end];
522
+ }
511
523
  /** Resolve a `RangeMode` to a concrete "start" | "end" | "reset" action for inside-range clicks. */
512
524
  function resolveInsideAction(mode, date, start, end) {
513
525
  if (mode === "adjust-start") return "start";
@@ -786,23 +798,19 @@ function truncateDatesForMode(opts) {
786
798
  return clamped;
787
799
  }
788
800
  /**
789
- * Pure utility that computes the preview range for a hovered date, using the
790
- * same logic as the internal hook. Useful for deriving the preview in an
791
- * `onHoveredDateChange` handler without needing a controlled `previewRange`.
801
+ * The range a click on `hoveredDate` would produce, or `null` when the click
802
+ * would do nothing (read-only, disabled date). One path for both the
803
+ * provider's own preview and the public {@link computePreviewRange}.
792
804
  */
793
- function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T) {
794
- const Temporal = T ?? globalThis.Temporal;
795
- if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
796
- const rawStart = currentRange?.start != null ? Temporal.PlainDate.from(currentRange.start) : null;
797
- const rawEnd = currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end) : null;
798
- const committedDates = currentRange ? rawStart === null && rawEnd !== null ? [rawEnd, null] : [rawStart, rawEnd] : [];
805
+ function computeRangePreview(input) {
806
+ const { hoveredDate, committedDates, rangeMode, allowRangeReversal, readOnly, isDateDisabled, T } = input;
799
807
  const committedStart = committedDates[0] ?? void 0;
800
- const committedEnd = committedDates[1] ?? void 0;
801
- const noop = () => [];
808
+ const committedEnd = committedDates.length > 1 ? committedDates[committedDates.length - 1] ?? void 0 : committedStart;
809
+ const unused = () => [];
802
810
  const result = computeSelectionUpdate({
803
811
  date: hoveredDate,
804
- readOnly: false,
805
- isDateDisabled: () => false,
812
+ readOnly,
813
+ isDateDisabled,
806
814
  isMultiple: false,
807
815
  isRange: true,
808
816
  committedDates,
@@ -810,20 +818,42 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
810
818
  committedEnd,
811
819
  selectedZdt: void 0,
812
820
  rangeMode,
813
- allowRangeReversal: !preventRangeReversal,
814
- sortDates: (d) => [...d].sort((a, b) => Temporal.PlainDate.compare(a, b)),
815
- currentSingleFormatted: noop,
816
- currentRangeFormatted: () => currentRange,
817
- currentMultipleFormatted: noop,
821
+ allowRangeReversal,
822
+ sortDates: (d) => [...d].sort((a, b) => T.PlainDate.compare(a, b)),
823
+ currentSingleFormatted: unused,
824
+ currentRangeFormatted: unused,
825
+ currentMultipleFormatted: unused,
818
826
  resolvedFormat: "PlainDate",
819
827
  timeZone: "UTC",
820
- T: Temporal
828
+ T
821
829
  });
822
830
  if (result.skip || result.newDates.length === 0) return null;
823
831
  const start = result.newDates[0];
824
832
  const end = result.newDates.length > 1 ? result.newDates[1] : start;
825
833
  if (start == null || end == null) return null;
826
- return mkRange(start, end);
834
+ return [start, end];
835
+ }
836
+ /**
837
+ * Pure utility that computes the preview range for a hovered date, using the
838
+ * same logic as the built-in hover preview. Useful for deriving the preview in
839
+ * an `onHoveredDateChange` handler without needing a controlled `previewRange`.
840
+ *
841
+ * Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
842
+ * disables dates or is read-only; by default every date is selectable.
843
+ */
844
+ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T, options = {}) {
845
+ const Temporal = T ?? globalThis.Temporal;
846
+ if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
847
+ const preview = computeRangePreview({
848
+ hoveredDate,
849
+ committedDates: currentRange ? decodeRange(currentRange, (raw) => Temporal.PlainDate.from(raw)) : [],
850
+ rangeMode,
851
+ allowRangeReversal: !preventRangeReversal,
852
+ readOnly: options.readOnly ?? false,
853
+ isDateDisabled: options.isDateDisabled ?? (() => false),
854
+ T: Temporal
855
+ });
856
+ return preview ? mkRange(preview[0], preview[1]) : null;
827
857
  }
828
858
  //#endregion
829
859
  //#region src/calendar-provider.tsx
@@ -915,13 +945,7 @@ function CalendarProvider(props) {
915
945
  }
916
946
  if (isRange) {
917
947
  if (rangeValue === null) return [];
918
- if (rangeValue) {
919
- const start = rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
920
- const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
921
- if (start === null && end === null) return [];
922
- if (start === null && end !== null) return [end, null];
923
- return [start, end];
924
- }
948
+ if (rangeValue) return decodeRange(rangeValue, rawToPlain);
925
949
  return;
926
950
  }
927
951
  if (singleValue === null) return [];
@@ -955,13 +979,7 @@ function CalendarProvider(props) {
955
979
  if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
956
980
  return [];
957
981
  }
958
- if (rangeDefault) {
959
- const start = rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
960
- const end = rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
961
- if (start === null && end === null) return [];
962
- if (start === null && end !== null) return [end, null];
963
- return [start, end];
964
- }
982
+ if (rangeDefault) return decodeRange(rangeDefault, rawToPlain);
965
983
  if (singleDefault != null) return [rawToPlain(singleDefault)];
966
984
  return [];
967
985
  }, [
@@ -1047,40 +1065,18 @@ function CalendarProvider(props) {
1047
1065
  const [previewStart, previewEnd] = (0, react.useMemo)(() => {
1048
1066
  if (previewRangeProp !== void 0) {
1049
1067
  if (!previewRangeProp) return [void 0, void 0];
1050
- const rawToPlainLocal = (raw) => {
1051
- return toZonedDateTime({
1052
- format: resolvedFormat,
1053
- value: raw
1054
- }, timeZone, T).toPlainDate();
1055
- };
1056
- return [previewRangeProp.start != null ? rawToPlainLocal(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlainLocal(previewRangeProp.end) : void 0];
1068
+ return [previewRangeProp.start != null ? rawToPlain(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlain(previewRangeProp.end) : void 0];
1057
1069
  }
1058
1070
  if (!hoveredDate || !isRange) return [void 0, void 0];
1059
- const result = computeSelectionUpdate({
1060
- date: hoveredDate,
1071
+ return computeRangePreview({
1072
+ hoveredDate,
1061
1073
  readOnly,
1062
1074
  isDateDisabled,
1063
- isMultiple: false,
1064
- isRange: true,
1065
1075
  committedDates,
1066
- committedStart,
1067
- committedEnd,
1068
- selectedZdt: void 0,
1069
1076
  rangeMode,
1070
1077
  allowRangeReversal,
1071
- sortDates,
1072
- currentSingleFormatted,
1073
- currentRangeFormatted,
1074
- currentMultipleFormatted,
1075
- resolvedFormat,
1076
- timeZone,
1077
1078
  T
1078
- });
1079
- if (result.skip || result.newDates.length === 0) return [void 0, void 0];
1080
- const ps = result.newDates[0];
1081
- const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
1082
- if (ps == null || pe == null) return [void 0, void 0];
1083
- return [ps, pe];
1079
+ }) ?? [void 0, void 0];
1084
1080
  }, [
1085
1081
  previewRangeProp,
1086
1082
  hoveredDate,
@@ -1088,16 +1084,9 @@ function CalendarProvider(props) {
1088
1084
  readOnly,
1089
1085
  isDateDisabled,
1090
1086
  committedDates,
1091
- committedStart,
1092
- committedEnd,
1093
1087
  rangeMode,
1094
1088
  allowRangeReversal,
1095
- sortDates,
1096
- currentSingleFormatted,
1097
- currentRangeFormatted,
1098
- currentMultipleFormatted,
1099
- resolvedFormat,
1100
- timeZone,
1089
+ rawToPlain,
1101
1090
  T
1102
1091
  ]);
1103
1092
  const prevModeRef = (0, react.useRef)(selectionMode);
@@ -1330,6 +1319,177 @@ function useMonthViewState() {
1330
1319
  return ctx;
1331
1320
  }
1332
1321
  //#endregion
1322
+ //#region src/month-view-navigation.ts
1323
+ /**
1324
+ * Owns which month the view shows, in both controlled and uncontrolled mode:
1325
+ * the month state, the Prev/Next steps, and syncing the window with focus.
1326
+ *
1327
+ * `onMonthChange` fires exactly once per move: from the effect below when
1328
+ * uncontrolled, and from the step or the focus-sync effect when controlled.
1329
+ */
1330
+ function useMonthNavigation(input) {
1331
+ const { month, defaultMonth, initialAnchor, onMonthChange, policy, focusedDate, setFocusedDate, T } = input;
1332
+ const isControlled = month !== void 0;
1333
+ const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
1334
+ if (month) return {
1335
+ year: month.year,
1336
+ month: month.month
1337
+ };
1338
+ if (defaultMonth) return {
1339
+ year: defaultMonth.year,
1340
+ month: defaultMonth.month
1341
+ };
1342
+ const anchor = initialAnchor();
1343
+ return {
1344
+ year: anchor.year,
1345
+ month: anchor.month
1346
+ };
1347
+ });
1348
+ const year = isControlled ? month.year : internalMonth.year;
1349
+ const monthNumber = isControlled ? month.month : internalMonth.month;
1350
+ const currentMonth = (0, react.useMemo)(() => ({
1351
+ year,
1352
+ month: monthNumber
1353
+ }), [year, monthNumber]);
1354
+ const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
1355
+ year,
1356
+ month: monthNumber
1357
+ }), [
1358
+ year,
1359
+ monthNumber,
1360
+ T
1361
+ ]);
1362
+ const onMonthChangeRef = (0, react.useRef)(onMonthChange);
1363
+ onMonthChangeRef.current = onMonthChange;
1364
+ const notifyMonth = (0, react.useCallback)((target) => {
1365
+ onMonthChangeRef.current?.(T.PlainYearMonth.from(target));
1366
+ }, [T]);
1367
+ const skipFocusSyncForRef = (0, react.useRef)(null);
1368
+ const prevFocusedRef = (0, react.useRef)(focusedDate);
1369
+ (0, react.useEffect)(() => {
1370
+ skipFocusSyncForRef.current = null;
1371
+ }, [month?.year, month?.month]);
1372
+ (0, react.useEffect)(() => {
1373
+ const prevFocused = prevFocusedRef.current;
1374
+ prevFocusedRef.current = focusedDate;
1375
+ const target = {
1376
+ year: focusedDate.year,
1377
+ month: focusedDate.month
1378
+ };
1379
+ if (isControlled) {
1380
+ if (skipFocusSyncForRef.current === focusedDate) {
1381
+ skipFocusSyncForRef.current = null;
1382
+ return;
1383
+ }
1384
+ if (prevFocused === focusedDate) return;
1385
+ if (policy.isVisible(currentMonth, target)) return;
1386
+ notifyMonth(policy.reveal(currentMonth, target));
1387
+ return;
1388
+ }
1389
+ setInternalMonth((prev) => {
1390
+ const next = policy.reveal(prev, target);
1391
+ if (next.year === prev.year && next.month === prev.month) return prev;
1392
+ return next;
1393
+ });
1394
+ }, [
1395
+ focusedDate,
1396
+ isControlled,
1397
+ policy,
1398
+ currentMonth,
1399
+ notifyMonth
1400
+ ]);
1401
+ const mountedRef = (0, react.useRef)(false);
1402
+ (0, react.useEffect)(() => {
1403
+ if (!mountedRef.current) {
1404
+ mountedRef.current = true;
1405
+ return;
1406
+ }
1407
+ if (isControlled) return;
1408
+ onMonthChangeRef.current?.(viewingYearMonth);
1409
+ }, [viewingYearMonth, isControlled]);
1410
+ const go = (0, react.useCallback)((direction) => {
1411
+ if (isControlled) {
1412
+ const step = policy.step(month, direction);
1413
+ if (step.blocked) return;
1414
+ const nextFocus = focusedDateForMonth(focusedDate, step.start, step.firstDay);
1415
+ skipFocusSyncForRef.current = nextFocus;
1416
+ notifyMonth(step.start);
1417
+ setFocusedDate(nextFocus);
1418
+ return;
1419
+ }
1420
+ setInternalMonth((m) => {
1421
+ const step = policy.step(m, direction);
1422
+ if (step.blocked) return m;
1423
+ setFocusedDate((prev) => focusedDateForMonth(prev, step.start, step.firstDay));
1424
+ return step.start;
1425
+ });
1426
+ }, [
1427
+ isControlled,
1428
+ month,
1429
+ policy,
1430
+ notifyMonth,
1431
+ focusedDate,
1432
+ setFocusedDate
1433
+ ]);
1434
+ return {
1435
+ currentMonth,
1436
+ viewingYearMonth,
1437
+ goNextMonth: (0, react.useCallback)(() => go("next"), [go]),
1438
+ goPrevMonth: (0, react.useCallback)(() => go("prev"), [go])
1439
+ };
1440
+ }
1441
+ //#endregion
1442
+ //#region src/month-window.ts
1443
+ const monthIndex = (m) => m.year * 12 + (m.month - 1);
1444
+ /**
1445
+ * Builds the policy for a MonthView window of `numberOfMonths` months.
1446
+ *
1447
+ * `unbounded` never blocks a step: `min`/`max` only gate which days are
1448
+ * selectable, not which months can be viewed. Any other behavior is `stop`,
1449
+ * which blocks a step whose entering month lies beyond the bound's month.
1450
+ */
1451
+ function createMonthWindowPolicy(input) {
1452
+ const { numberOfMonths, behavior, min, max, T } = input;
1453
+ return {
1454
+ step(start, direction) {
1455
+ const adjacent = computeAdjacentMonth(start, direction, T);
1456
+ const newStart = {
1457
+ year: adjacent.year,
1458
+ month: adjacent.month
1459
+ };
1460
+ const entering = direction === "prev" ? newStart : monthAt(newStart, numberOfMonths - 1);
1461
+ let blocked = false;
1462
+ if (behavior !== "unbounded") {
1463
+ const bound = direction === "prev" ? min : max;
1464
+ if (bound) {
1465
+ const diff = monthIndex(entering) - monthIndex(bound);
1466
+ blocked = direction === "prev" ? diff < 0 : diff > 0;
1467
+ }
1468
+ }
1469
+ return {
1470
+ start: newStart,
1471
+ entering,
1472
+ firstDay: adjacent.firstDay,
1473
+ blocked
1474
+ };
1475
+ },
1476
+ isVisible(start, target) {
1477
+ const offset = monthIndex(target) - monthIndex(start);
1478
+ return offset >= 0 && offset < numberOfMonths;
1479
+ },
1480
+ reveal(start, target) {
1481
+ return shiftWindowToMonth(start, target, numberOfMonths);
1482
+ }
1483
+ };
1484
+ }
1485
+ function monthAt(start, offset) {
1486
+ const index = monthIndex(start) + offset;
1487
+ return {
1488
+ year: Math.floor(index / 12),
1489
+ month: index % 12 + 1
1490
+ };
1491
+ }
1492
+ //#endregion
1333
1493
  //#region src/view-context.ts
1334
1494
  /** @internal React context for the active view (MonthView or WeeksView). */
1335
1495
  const ViewContext = (0, react.createContext)(null);
@@ -1367,29 +1527,38 @@ function MonthViewRoot(props) {
1367
1527
  const calState = useCalendarState();
1368
1528
  const T = calStable.temporal;
1369
1529
  const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
1370
- const isMonthControlled = monthProp !== void 0;
1371
- const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
1372
- if (monthProp) return {
1373
- year: monthProp.year,
1374
- month: monthProp.month
1375
- };
1376
- if (defaultMonthProp) return {
1377
- year: defaultMonthProp.year,
1378
- month: defaultMonthProp.month
1379
- };
1380
- const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
1381
- return {
1382
- year: anchor.year,
1383
- month: anchor.month
1384
- };
1385
- });
1386
- const currentMonth = isMonthControlled ? {
1387
- year: monthProp.year,
1388
- month: monthProp.month
1389
- } : internalMonth;
1390
1530
  const [focusedDate, setFocusedDate] = (0, react.useState)(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
1391
1531
  const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
1392
1532
  const gridFocusedRef = (0, react.useRef)(false);
1533
+ const { minValue, maxValue } = calStable;
1534
+ const windowPolicy = (0, react.useMemo)(() => createMonthWindowPolicy({
1535
+ numberOfMonths,
1536
+ behavior: outOfRangeBehavior,
1537
+ min: minValue,
1538
+ max: maxValue,
1539
+ T
1540
+ }), [
1541
+ numberOfMonths,
1542
+ outOfRangeBehavior,
1543
+ minValue,
1544
+ maxValue,
1545
+ T
1546
+ ]);
1547
+ const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
1548
+ month: monthProp,
1549
+ defaultMonth: defaultMonthProp,
1550
+ initialAnchor: (0, react.useCallback)(() => resolveInitialAnchor(calState.selected, today, timeZone, T), [
1551
+ calState.selected,
1552
+ today,
1553
+ timeZone,
1554
+ T
1555
+ ]),
1556
+ onMonthChange,
1557
+ policy: windowPolicy,
1558
+ focusedDate,
1559
+ setFocusedDate,
1560
+ T
1561
+ });
1393
1562
  const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
1394
1563
  const setGridLabelId = (0, react.useCallback)((monthIndex, id) => {
1395
1564
  setGridLabelIds((prev) => {
@@ -1406,140 +1575,6 @@ function MonthViewRoot(props) {
1406
1575
  };
1407
1576
  });
1408
1577
  }, []);
1409
- const onMonthChangeRef = (0, react.useRef)(onMonthChange);
1410
- onMonthChangeRef.current = onMonthChange;
1411
- const notifyMonth = (0, react.useCallback)((year, month) => {
1412
- onMonthChangeRef.current?.(T.PlainYearMonth.from({
1413
- year,
1414
- month
1415
- }));
1416
- }, [T]);
1417
- const isMonthVisible = (0, react.useCallback)((targetYear, targetMonth) => {
1418
- for (let i = 0; i < numberOfMonths; i++) {
1419
- const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1420
- const y = Math.floor(totalMonths / 12);
1421
- const m = totalMonths % 12 + 1;
1422
- if (targetYear === y && targetMonth === m) return true;
1423
- }
1424
- return false;
1425
- }, [
1426
- currentMonth.year,
1427
- currentMonth.month,
1428
- numberOfMonths
1429
- ]);
1430
- const navigateToMonth = (0, react.useCallback)((targetYear, targetMonth) => {
1431
- if (isMonthControlled) return;
1432
- setInternalMonth((prev) => {
1433
- const next = shiftWindowToMonth(prev, {
1434
- year: targetYear,
1435
- month: targetMonth
1436
- }, numberOfMonths);
1437
- if (next.year === prev.year && next.month === prev.month) return prev;
1438
- return next;
1439
- });
1440
- }, [isMonthControlled, numberOfMonths]);
1441
- const skipFocusSyncForRef = (0, react.useRef)(null);
1442
- const prevFocusedRef = (0, react.useRef)(focusedDate);
1443
- (0, react.useEffect)(() => {
1444
- skipFocusSyncForRef.current = null;
1445
- }, [monthProp?.year, monthProp?.month]);
1446
- (0, react.useEffect)(() => {
1447
- const prevFocused = prevFocusedRef.current;
1448
- prevFocusedRef.current = focusedDate;
1449
- if (isMonthControlled) {
1450
- if (skipFocusSyncForRef.current === focusedDate) {
1451
- skipFocusSyncForRef.current = null;
1452
- return;
1453
- }
1454
- if (prevFocused === focusedDate) return;
1455
- if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
1456
- const next = shiftWindowToMonth({
1457
- year: currentMonth.year,
1458
- month: currentMonth.month
1459
- }, {
1460
- year: focusedDate.year,
1461
- month: focusedDate.month
1462
- }, numberOfMonths);
1463
- notifyMonth(next.year, next.month);
1464
- return;
1465
- }
1466
- navigateToMonth(focusedDate.year, focusedDate.month);
1467
- }, [
1468
- focusedDate,
1469
- navigateToMonth,
1470
- isMonthControlled,
1471
- isMonthVisible,
1472
- notifyMonth,
1473
- currentMonth.year,
1474
- currentMonth.month,
1475
- numberOfMonths
1476
- ]);
1477
- const goNextMonth = (0, react.useCallback)(() => {
1478
- if (isMonthControlled) {
1479
- const { year, month, firstDay } = computeAdjacentMonth({
1480
- year: monthProp.year,
1481
- month: monthProp.month
1482
- }, "next", T);
1483
- const nextFocus = focusedDateForMonth(focusedDate, {
1484
- year,
1485
- month
1486
- }, firstDay);
1487
- skipFocusSyncForRef.current = nextFocus;
1488
- notifyMonth(year, month);
1489
- setFocusedDate(nextFocus);
1490
- return;
1491
- }
1492
- setInternalMonth((m) => {
1493
- const { year, month, firstDay } = computeAdjacentMonth(m, "next", T);
1494
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1495
- year,
1496
- month
1497
- }, firstDay));
1498
- return {
1499
- year,
1500
- month
1501
- };
1502
- });
1503
- }, [
1504
- T,
1505
- isMonthControlled,
1506
- monthProp,
1507
- notifyMonth,
1508
- focusedDate
1509
- ]);
1510
- const goPrevMonth = (0, react.useCallback)(() => {
1511
- if (isMonthControlled) {
1512
- const { year, month, firstDay } = computeAdjacentMonth({
1513
- year: monthProp.year,
1514
- month: monthProp.month
1515
- }, "prev", T);
1516
- const nextFocus = focusedDateForMonth(focusedDate, {
1517
- year,
1518
- month
1519
- }, firstDay);
1520
- skipFocusSyncForRef.current = nextFocus;
1521
- notifyMonth(year, month);
1522
- setFocusedDate(nextFocus);
1523
- return;
1524
- }
1525
- setInternalMonth((m) => {
1526
- const { year, month, firstDay } = computeAdjacentMonth(m, "prev", T);
1527
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1528
- year,
1529
- month
1530
- }, firstDay));
1531
- return {
1532
- year,
1533
- month
1534
- };
1535
- });
1536
- }, [
1537
- T,
1538
- isMonthControlled,
1539
- monthProp,
1540
- notifyMonth,
1541
- focusedDate
1542
- ]);
1543
1578
  const allMonths = (0, react.useMemo)(() => {
1544
1579
  const opts = {
1545
1580
  weekStartDay,
@@ -1599,19 +1634,6 @@ function MonthViewRoot(props) {
1599
1634
  T,
1600
1635
  gridHasFocus
1601
1636
  ]);
1602
- const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
1603
- year: currentMonth.year,
1604
- month: currentMonth.month
1605
- }), [currentMonth, T]);
1606
- const mountedRef = (0, react.useRef)(false);
1607
- (0, react.useEffect)(() => {
1608
- if (!mountedRef.current) {
1609
- mountedRef.current = true;
1610
- return;
1611
- }
1612
- if (isMonthControlled) return;
1613
- onMonthChangeRef.current?.(viewingYearMonth);
1614
- }, [viewingYearMonth, isMonthControlled]);
1615
1637
  const rootState = (0, react.useMemo)(() => ({
1616
1638
  ...calState.baseRootState,
1617
1639
  focused: focusedDate,
@@ -1626,6 +1648,7 @@ function MonthViewRoot(props) {
1626
1648
  fixedWeeks,
1627
1649
  outsideDays,
1628
1650
  outOfRangeBehavior,
1651
+ windowPolicy,
1629
1652
  goNextMonth,
1630
1653
  goPrevMonth,
1631
1654
  setGridLabelId,
@@ -1635,6 +1658,7 @@ function MonthViewRoot(props) {
1635
1658
  fixedWeeks,
1636
1659
  outsideDays,
1637
1660
  outOfRangeBehavior,
1661
+ windowPolicy,
1638
1662
  goNextMonth,
1639
1663
  goPrevMonth,
1640
1664
  setGridLabelId
@@ -2277,130 +2301,180 @@ function computeWeeksKeyNav(input) {
2277
2301
  }
2278
2302
  }
2279
2303
  //#endregion
2280
- //#region src/day-cell.tsx
2281
- /** Computes derived day cell state from context values. Pure function, no hooks. */
2282
- function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, today, T, selectionMode, outsideDays, previewStart, previewEnd) {
2283
- const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
2284
- if (!isCurrentMonth && outsideDays === "hidden") return {
2285
- root: rootState,
2304
+ //#region src/day-cell-state.ts
2305
+ const NO_RANGE = {
2306
+ rangeStart: false,
2307
+ rangeEnd: false,
2308
+ rangeBoundary: false,
2309
+ inRange: false,
2310
+ rangeIndex: false,
2311
+ rangeLength: false,
2312
+ rangeHasStart: false,
2313
+ rangeHasEnd: false,
2314
+ rangePreviewStart: false,
2315
+ rangePreviewEnd: false,
2316
+ rangePreviewBoundary: false,
2317
+ rangePreviewInRange: false,
2318
+ rangePreviewIndex: false,
2319
+ rangePreviewLength: false,
2320
+ rangePreviewHasStart: false,
2321
+ rangePreviewHasEnd: false
2322
+ };
2323
+ function computeRangeState(date, inputs) {
2324
+ const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
2325
+ if (selectionMode !== "range") return NO_RANGE;
2326
+ const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
2327
+ const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
2328
+ const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
2329
+ const effectiveStart = rangeStart ?? rangeEnd;
2330
+ const effectiveEnd = rangeEnd ?? rangeStart;
2331
+ const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
2332
+ const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
2333
+ const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
2334
+ return {
2335
+ rangeStart: isRangeStart,
2336
+ rangeEnd: isRangeEnd,
2337
+ rangeBoundary: isRangeStart || isRangeEnd,
2338
+ inRange,
2339
+ rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
2340
+ rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
2341
+ rangeHasStart: inRange && rangeStart !== void 0,
2342
+ rangeHasEnd: inRange && rangeEnd !== void 0,
2343
+ rangePreviewStart: isPreviewStart,
2344
+ rangePreviewEnd: isPreviewEnd,
2345
+ rangePreviewBoundary: isPreviewStart || isPreviewEnd,
2346
+ rangePreviewInRange: inPreview,
2347
+ rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
2348
+ rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
2349
+ rangePreviewHasStart: inPreview && previewStart !== void 0,
2350
+ rangePreviewHasEnd: inPreview && previewEnd !== void 0
2351
+ };
2352
+ }
2353
+ /** Derives the state of one day cell. Pure function, no hooks. */
2354
+ function computeDayCellState(date, position, inputs) {
2355
+ const { T, outsideDays } = inputs;
2356
+ const { columnIndex, month } = position;
2357
+ const isCurrentMonth = date.year === month.year && date.month === month.month;
2358
+ const base = {
2359
+ root: inputs.rootState,
2286
2360
  date,
2287
2361
  columnIndex,
2288
- orientation,
2362
+ orientation: inputs.orientation
2363
+ };
2364
+ if (!isCurrentMonth && outsideDays === "hidden") return {
2365
+ ...base,
2366
+ ...NO_RANGE,
2289
2367
  outsideMonth: true,
2290
2368
  hidden: true,
2291
2369
  selected: false,
2292
2370
  today: false,
2293
2371
  disabled: true,
2294
2372
  focused: false,
2295
- rangeStart: false,
2296
- rangeEnd: false,
2297
- rangeBoundary: false,
2298
- inRange: false,
2299
- rangeIndex: false,
2300
- rangeLength: false,
2301
- rangeHasStart: false,
2302
- rangeHasEnd: false,
2303
- rangePreviewStart: false,
2304
- rangePreviewEnd: false,
2305
- rangePreviewBoundary: false,
2306
- rangePreviewInRange: false,
2307
- rangePreviewIndex: false,
2308
- rangePreviewLength: false,
2309
- rangePreviewHasStart: false,
2310
- rangePreviewHasEnd: false,
2311
2373
  isTabTarget: false
2312
2374
  };
2313
- const isToday = T.PlainDate.compare(date, today) === 0;
2314
- const isRange = selectionMode === "range";
2315
- let isRangeStart = false;
2316
- let isRangeEnd = false;
2317
- let isInRangeDay = false;
2318
- let rangeIdx = false;
2319
- let rangeLen = false;
2320
- let isPreviewRangeStart = false;
2321
- let isPreviewRangeEnd = false;
2322
- let isInPreviewRange = false;
2323
- let previewIdx = false;
2324
- let previewLen = false;
2325
- if (isRange) {
2326
- isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
2327
- isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
2328
- isInRangeDay = isInRange(date, rangeStart, rangeEnd, T) !== false;
2329
- const effectiveStart = rangeStart ?? rangeEnd;
2330
- const effectiveEnd = rangeEnd ?? rangeStart;
2331
- rangeIdx = isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
2332
- rangeLen = isInRangeDay && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false;
2333
- isPreviewRangeStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
2334
- isPreviewRangeEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
2335
- isInPreviewRange = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
2336
- previewIdx = isInPreviewRange && previewStart ? date.since(previewStart).days : false;
2337
- previewLen = isInPreviewRange && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false;
2375
+ const isToday = T.PlainDate.compare(date, inputs.today) === 0;
2376
+ if (!isCurrentMonth && outsideDays !== "enabled") {
2377
+ const suppressRange = outsideDays === "disabled";
2378
+ return {
2379
+ ...base,
2380
+ ...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
2381
+ outsideMonth: true,
2382
+ hidden: false,
2383
+ selected: false,
2384
+ today: isToday,
2385
+ disabled: true,
2386
+ focused: false,
2387
+ isTabTarget: false
2388
+ };
2338
2389
  }
2339
- const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
2340
- const suppressRange = !isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
2341
- if (outsideNonInteractive) return {
2342
- root: rootState,
2343
- date,
2344
- columnIndex,
2345
- orientation,
2346
- outsideMonth: true,
2390
+ return {
2391
+ ...base,
2392
+ ...computeRangeState(date, inputs),
2393
+ outsideMonth: !isCurrentMonth,
2347
2394
  hidden: false,
2348
- selected: false,
2395
+ selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
2349
2396
  today: isToday,
2350
- disabled: true,
2351
- focused: false,
2352
- rangeStart: suppressRange ? false : isRangeStart,
2353
- rangeEnd: suppressRange ? false : isRangeEnd,
2354
- rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
2355
- inRange: suppressRange ? false : isInRangeDay,
2356
- rangeIndex: suppressRange ? false : rangeIdx,
2357
- rangeLength: suppressRange ? false : rangeLen,
2358
- rangeHasStart: suppressRange ? false : isInRangeDay && rangeStart !== void 0,
2359
- rangeHasEnd: suppressRange ? false : isInRangeDay && rangeEnd !== void 0,
2360
- rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
2361
- rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
2362
- rangePreviewBoundary: suppressRange ? false : isPreviewRangeStart || isPreviewRangeEnd,
2363
- rangePreviewInRange: suppressRange ? false : isInPreviewRange,
2364
- rangePreviewIndex: suppressRange ? false : previewIdx,
2365
- rangePreviewLength: suppressRange ? false : previewLen,
2366
- rangePreviewHasStart: suppressRange ? false : isInPreviewRange && previewStart !== void 0,
2367
- rangePreviewHasEnd: suppressRange ? false : isInPreviewRange && previewEnd !== void 0,
2368
- isTabTarget: false
2397
+ disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
2398
+ focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
2399
+ isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
2369
2400
  };
2370
- const isSelected = selectionMode !== "range" ? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false;
2371
- const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
2372
- const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
2373
- const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
2374
- return {
2375
- root: rootState,
2376
- date,
2377
- columnIndex,
2401
+ }
2402
+ const COMPARED_KEYS = Object.keys({
2403
+ outsideMonth: true,
2404
+ hidden: true,
2405
+ selected: true,
2406
+ today: true,
2407
+ disabled: true,
2408
+ focused: true,
2409
+ rangeStart: true,
2410
+ rangeEnd: true,
2411
+ rangeBoundary: true,
2412
+ inRange: true,
2413
+ rangeIndex: true,
2414
+ rangeLength: true,
2415
+ rangeHasStart: true,
2416
+ rangeHasEnd: true,
2417
+ rangePreviewStart: true,
2418
+ rangePreviewEnd: true,
2419
+ rangePreviewBoundary: true,
2420
+ rangePreviewInRange: true,
2421
+ rangePreviewIndex: true,
2422
+ rangePreviewLength: true,
2423
+ rangePreviewHasStart: true,
2424
+ rangePreviewHasEnd: true,
2425
+ isTabTarget: true
2426
+ });
2427
+ /** Whether two cell states render the same cell. */
2428
+ function dayCellStateEqual(a, b) {
2429
+ for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
2430
+ return true;
2431
+ }
2432
+ /**
2433
+ * Reads the contexts a day cell depends on and returns a function that derives
2434
+ * the state of any cell. `columnIndex` defaults to the date's column in a
2435
+ * week starting on the calendar's `weekStartDay`.
2436
+ */
2437
+ function useDayCellDeriver() {
2438
+ const { orientation } = (0, react.useContext)(GridContext);
2439
+ const weekData = (0, react.useContext)(WeekDataContext);
2440
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2441
+ const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2442
+ const viewCtx = useViewContext();
2443
+ const { focusedDate, tabTargetDate } = viewCtx;
2444
+ const { rootState, currentDateTime } = useViewState();
2445
+ const { outsideDays } = useViewStable();
2446
+ const inputs = {
2447
+ T,
2448
+ today: today(),
2378
2449
  orientation,
2379
- selected: isSelected,
2380
- today: isToday,
2381
- disabled: isDisabled,
2382
- outsideMonth: !isCurrentMonth,
2383
- hidden: false,
2384
- focused: isFocused,
2385
- rangeStart: isRangeStart,
2386
- rangeEnd: isRangeEnd,
2387
- rangeBoundary: isRangeStart || isRangeEnd,
2388
- inRange: isInRangeDay,
2389
- rangeIndex: rangeIdx,
2390
- rangeLength: rangeLen,
2391
- rangeHasStart: isInRangeDay && rangeStart !== void 0,
2392
- rangeHasEnd: isInRangeDay && rangeEnd !== void 0,
2393
- rangePreviewStart: isPreviewRangeStart,
2394
- rangePreviewEnd: isPreviewRangeEnd,
2395
- rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
2396
- rangePreviewInRange: isInPreviewRange,
2397
- rangePreviewIndex: previewIdx,
2398
- rangePreviewLength: previewLen,
2399
- rangePreviewHasStart: isInPreviewRange && previewStart !== void 0,
2400
- rangePreviewHasEnd: isInPreviewRange && previewEnd !== void 0,
2401
- isTabTarget
2450
+ rootState,
2451
+ selectionMode,
2452
+ selectedDates,
2453
+ rangeStart,
2454
+ rangeEnd,
2455
+ previewStart,
2456
+ previewEnd,
2457
+ disabled,
2458
+ isDateDisabled,
2459
+ focusedDate,
2460
+ tabTargetDate,
2461
+ outsideDays
2462
+ };
2463
+ const isWeeksView = viewCtx.viewType === "weeks";
2464
+ const gridMonth = weekData?.gridMonth ?? currentDateTime;
2465
+ return (date, columnIndex) => {
2466
+ const daysInWeek = date.daysInWeek;
2467
+ return computeDayCellState(date, {
2468
+ columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek,
2469
+ month: isWeeksView ? {
2470
+ year: date.year,
2471
+ month: date.month
2472
+ } : gridMonth
2473
+ }, inputs);
2402
2474
  };
2403
2475
  }
2476
+ //#endregion
2477
+ //#region src/day-cell.tsx
2404
2478
  const dayStateAttributesMapping = {
2405
2479
  root: () => null,
2406
2480
  date: (v) => v ? { "data-date": v.toString() } : null,
@@ -2487,9 +2561,7 @@ const DAY_BUTTON_HANDLED_KEYS = new Set([
2487
2561
  ]);
2488
2562
  function dayCellInstancePropsAreEqual(prev, next) {
2489
2563
  if (prev.date !== next.date || prev.render !== next.render || prev.columnIndex !== next.columnIndex) return false;
2490
- const a = prev._derivedState;
2491
- const b = next._derivedState;
2492
- 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);
2564
+ return dayCellStateEqual(prev._derivedState, next._derivedState) && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
2493
2565
  }
2494
2566
  const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsAreEqual);
2495
2567
  /**
@@ -2500,47 +2572,24 @@ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsA
2500
2572
  * When used inside a {@link WeekTemplate}, iterates over that week's days.
2501
2573
  * An explicit `date` prop renders a single cell.
2502
2574
  */
2503
- function DayCellTemplate(props) {
2504
- const { date: dateProp, ...restProps } = props;
2505
- const weekData = (0, react.useContext)(WeekDataContext);
2506
- const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2507
- const todayDate = today();
2508
- const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2509
- const viewCtx = useViewContext();
2510
- const { focusedDate, tabTargetDate } = viewCtx;
2511
- const { rootState, currentDateTime } = useViewState();
2512
- const { outsideDays } = useViewStable();
2513
- const monthState = (0, react.useContext)(MonthViewStateContext);
2514
- const isWeeksView = viewCtx.viewType === "weeks";
2515
- const cellMonth = isWeeksView ? null : weekData?.gridMonth ?? currentDateTime;
2516
- const { orientation } = (0, react.useContext)(GridContext);
2517
- if (dateProp) {
2518
- const daysInWeek = dateProp.daysInWeek;
2519
- const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2520
- year: dateProp.year,
2521
- month: dateProp.month
2522
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2523
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2524
- ...restProps,
2525
- date: dateProp,
2526
- _derivedState: derived
2527
- });
2528
- }
2575
+ function DayCellTemplate(props) {
2576
+ const { date: dateProp, ...restProps } = props;
2577
+ const weekData = (0, react.useContext)(WeekDataContext);
2578
+ const monthState = (0, react.useContext)(MonthViewStateContext);
2579
+ const derive = useDayCellDeriver();
2580
+ if (dateProp) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2581
+ ...restProps,
2582
+ date: dateProp,
2583
+ _derivedState: derive(dateProp)
2584
+ });
2529
2585
  const days = weekData ? weekData.days : monthState?.weeks.flat() ?? [];
2530
2586
  const perWeek = weekData != null;
2531
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
2532
- const daysInWeek = day.daysInWeek;
2533
- const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2534
- year: day.year,
2535
- month: day.month
2536
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2537
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2538
- ...restProps,
2539
- date: day,
2540
- columnIndex: perWeek ? i : void 0,
2541
- _derivedState: derived
2542
- }, day.toString());
2543
- }) });
2587
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2588
+ ...restProps,
2589
+ date: day,
2590
+ columnIndex: perWeek ? i : void 0,
2591
+ _derivedState: derive(day, perWeek ? i : void 0)
2592
+ }, day.toString())) });
2544
2593
  }
2545
2594
  function DayButtonInnerFn(props, ref) {
2546
2595
  const { render, date, _derivedState, ...otherProps } = props;
@@ -2592,7 +2641,7 @@ function dayButtonInnerPropsAreEqual(prev, next) {
2592
2641
  const a = prev._derivedState;
2593
2642
  const b = next._derivedState;
2594
2643
  if (!a || !b) return a === b;
2595
- 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;
2644
+ return dayCellStateEqual(a, b);
2596
2645
  }
2597
2646
  const DayButtonInner = (0, react.memo)((0, react.forwardRef)(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
2598
2647
  /**
@@ -2624,26 +2673,12 @@ const DayButton = (0, react.forwardRef)(DayButtonFn);
2624
2673
  /** Fallback for standalone DayButton usage that needs to read context. */
2625
2674
  function DayButtonFallbackFn(props, ref) {
2626
2675
  const { date, ...restProps } = props;
2627
- const { orientation } = (0, react.useContext)(GridContext);
2628
- const weekData = (0, react.useContext)(WeekDataContext);
2629
- const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2630
- const todayDate = today();
2631
- const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2632
- const viewCtx = useViewContext();
2633
- const { focusedDate, tabTargetDate } = viewCtx;
2634
- const { rootState, currentDateTime } = useViewState();
2635
- const { outsideDays } = useViewStable();
2636
- const cellMonth = viewCtx.viewType === "weeks" ? {
2637
- year: date.year,
2638
- month: date.month
2639
- } : weekData?.gridMonth ?? currentDateTime;
2640
- const daysInWeek = date.daysInWeek;
2641
- 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);
2676
+ const derive = useDayCellDeriver();
2642
2677
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
2643
2678
  ...restProps,
2644
2679
  ref,
2645
2680
  date,
2646
- _derivedState: derived
2681
+ _derivedState: derive(date)
2647
2682
  });
2648
2683
  }
2649
2684
  const DayButtonFallback = (0, react.forwardRef)(DayButtonFallbackFn);
@@ -3194,37 +3229,16 @@ function MonthYearStringFn(props, ref) {
3194
3229
  */
3195
3230
  const MonthYearString = (0, react.forwardRef)(MonthYearStringFn);
3196
3231
  function useNavButton(direction) {
3197
- const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
3198
- const monthViewStable = useMonthViewStable();
3199
- const monthViewState = useMonthViewState();
3200
- const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths, outOfRangeBehavior } = monthViewStable;
3201
- const { currentMonth: currentDateTime, allMonths, rootState } = monthViewState;
3202
- const refMonth = direction === "next" ? allMonths[numberOfMonths - 1] ?? currentDateTime : currentDateTime;
3203
- const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
3204
- const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
3205
- const boundValue = direction === "prev" ? minValue : maxValue;
3206
- const isDisabled = (0, react.useMemo)(() => {
3207
- if (globalDisabled) return true;
3208
- if (outOfRangeBehavior === "unbounded") return false;
3209
- if (!boundValue) return false;
3210
- if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
3211
- return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
3212
- }, [
3213
- globalDisabled,
3214
- outOfRangeBehavior,
3215
- destYear,
3216
- destMonth,
3217
- boundValue,
3232
+ const { disabled: globalDisabled, temporal: T } = useCalendarStable();
3233
+ const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, windowPolicy } = useMonthViewStable();
3234
+ const { currentMonth, rootState } = useMonthViewState();
3235
+ const step = (0, react.useMemo)(() => windowPolicy.step(currentMonth, direction), [
3236
+ windowPolicy,
3237
+ currentMonth,
3218
3238
  direction
3219
3239
  ]);
3220
- const target = (0, react.useMemo)(() => T.PlainYearMonth.from({
3221
- year: destYear,
3222
- month: destMonth
3223
- }), [
3224
- destYear,
3225
- destMonth,
3226
- T
3227
- ]);
3240
+ const isDisabled = globalDisabled || step.blocked;
3241
+ const target = (0, react.useMemo)(() => T.PlainYearMonth.from(step.entering), [step.entering, T]);
3228
3242
  return {
3229
3243
  state: (0, react.useMemo)(() => ({
3230
3244
  root: rootState,
@@ -3656,6 +3670,98 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
3656
3670
  return weeks;
3657
3671
  }
3658
3672
  //#endregion
3673
+ //#region src/resolve-first-week.ts
3674
+ /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3675
+ function snapToWeekStart(date, weekStartDay) {
3676
+ const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3677
+ return date.subtract({ days: offset });
3678
+ }
3679
+ /**
3680
+ * Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
3681
+ * containing week's start (snapped to `weekStartDay`).
3682
+ *
3683
+ * @param spec - The week specifier to resolve.
3684
+ * @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
3685
+ * @param T - Temporal namespace.
3686
+ * @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
3687
+ */
3688
+ function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
3689
+ if ("calendarId" in spec) {
3690
+ const pd = spec;
3691
+ return snapToWeekStart(pd.calendarId === "iso8601" ? pd : pd.withCalendar("iso8601"), weekStartDay);
3692
+ }
3693
+ if (spec instanceof Date) {
3694
+ const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
3695
+ const parts = new Intl.DateTimeFormat("en-US", {
3696
+ timeZone: tz,
3697
+ year: "numeric",
3698
+ month: "numeric",
3699
+ day: "numeric"
3700
+ }).formatToParts(spec);
3701
+ const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
3702
+ return snapToWeekStart(T.PlainDate.from({
3703
+ year: get("year"),
3704
+ month: get("month"),
3705
+ day: get("day")
3706
+ }), weekStartDay);
3707
+ }
3708
+ if ("isoWeek" in spec) {
3709
+ const { isoWeek, isoYear } = spec;
3710
+ const jan4 = T.PlainDate.from({
3711
+ year: isoYear,
3712
+ month: 1,
3713
+ day: 4
3714
+ });
3715
+ const jan4dow = jan4.dayOfWeek;
3716
+ return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
3717
+ }
3718
+ if ("week" in spec && !("month" in spec)) {
3719
+ const { week, year } = spec;
3720
+ const jan1 = T.PlainDate.from({
3721
+ year,
3722
+ month: 1,
3723
+ day: 1
3724
+ });
3725
+ const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
3726
+ return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
3727
+ }
3728
+ const { month, year, day } = spec;
3729
+ const targetDay = day ?? 1;
3730
+ return snapToWeekStart(T.PlainDate.from({
3731
+ year,
3732
+ month,
3733
+ day: targetDay
3734
+ }), weekStartDay);
3735
+ }
3736
+ /**
3737
+ * Computes a new `firstWeek` date given a scroll target and snap mode.
3738
+ *
3739
+ * The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
3740
+ *
3741
+ * @param currentFirstWeek - The current first visible week (a week-start date).
3742
+ * @param weekCount - Number of visible week rows.
3743
+ * @param target - The week-start date to scroll to.
3744
+ * @param options - Optional snap mode (default `"start"`).
3745
+ */
3746
+ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3747
+ switch (options?.snap ?? "start") {
3748
+ case "start": return target;
3749
+ case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
3750
+ case "end": return target.subtract({ weeks: weekCount - 1 });
3751
+ case "nearest": {
3752
+ const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
3753
+ const cmp = (a, b) => {
3754
+ if (a.year !== b.year) return a.year - b.year;
3755
+ if (a.month !== b.month) return a.month - b.month;
3756
+ return a.day - b.day;
3757
+ };
3758
+ if (cmp(target, currentFirstWeek) < 0) return target;
3759
+ if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
3760
+ return currentFirstWeek;
3761
+ }
3762
+ }
3763
+ }
3764
+ //#endregion
3659
3765
  //#region src/out-of-range.ts
3660
3766
  /** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
3661
3767
  function weekHasValidDay(weekStart, min, max, T) {
@@ -3763,96 +3869,28 @@ function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, m
3763
3869
  return true;
3764
3870
  }
3765
3871
  //#endregion
3766
- //#region src/resolve-first-week.ts
3767
- /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3768
- function snapToWeekStart(date, weekStartDay) {
3769
- const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3770
- return date.subtract({ days: offset });
3771
- }
3772
- /**
3773
- * Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
3774
- * containing week's start (snapped to `weekStartDay`).
3775
- *
3776
- * @param spec - The week specifier to resolve.
3777
- * @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
3778
- * @param T - Temporal namespace.
3779
- * @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
3780
- */
3781
- function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
3782
- if ("calendarId" in spec) {
3783
- const pd = spec;
3784
- return snapToWeekStart(pd.calendarId === "iso8601" ? pd : pd.withCalendar("iso8601"), weekStartDay);
3785
- }
3786
- if (spec instanceof Date) {
3787
- const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
3788
- const parts = new Intl.DateTimeFormat("en-US", {
3789
- timeZone: tz,
3790
- year: "numeric",
3791
- month: "numeric",
3792
- day: "numeric"
3793
- }).formatToParts(spec);
3794
- const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
3795
- return snapToWeekStart(T.PlainDate.from({
3796
- year: get("year"),
3797
- month: get("month"),
3798
- day: get("day")
3799
- }), weekStartDay);
3800
- }
3801
- if ("isoWeek" in spec) {
3802
- const { isoWeek, isoYear } = spec;
3803
- const jan4 = T.PlainDate.from({
3804
- year: isoYear,
3805
- month: 1,
3806
- day: 4
3807
- });
3808
- const jan4dow = jan4.dayOfWeek;
3809
- return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
3810
- }
3811
- if ("week" in spec && !("month" in spec)) {
3812
- const { week, year } = spec;
3813
- const jan1 = T.PlainDate.from({
3814
- year,
3815
- month: 1,
3816
- day: 1
3817
- });
3818
- const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
3819
- return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
3820
- }
3821
- const { month, year, day } = spec;
3822
- const targetDay = day ?? 1;
3823
- return snapToWeekStart(T.PlainDate.from({
3824
- year,
3825
- month,
3826
- day: targetDay
3827
- }), weekStartDay);
3828
- }
3829
- /**
3830
- * Computes a new `firstWeek` date given a scroll target and snap mode.
3831
- *
3832
- * The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
3833
- *
3834
- * @param currentFirstWeek - The current first visible week (a week-start date).
3835
- * @param weekCount - Number of visible week rows.
3836
- * @param target - The week-start date to scroll to.
3837
- * @param options - Optional snap mode (default `"start"`).
3838
- */
3839
- function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3840
- switch (options?.snap ?? "start") {
3841
- case "start": return target;
3842
- case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
3843
- case "end": return target.subtract({ weeks: weekCount - 1 });
3844
- case "nearest": {
3845
- const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
3846
- const cmp = (a, b) => {
3847
- if (a.year !== b.year) return a.year - b.year;
3848
- if (a.month !== b.month) return a.month - b.month;
3849
- return a.day - b.day;
3850
- };
3851
- if (cmp(target, currentFirstWeek) < 0) return target;
3852
- if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
3853
- return currentFirstWeek;
3854
- }
3855
- }
3872
+ //#region src/weeks-window.ts
3873
+ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
3874
+ const bounds = {
3875
+ weekCount,
3876
+ behavior,
3877
+ ...min !== void 0 && { min },
3878
+ ...max !== void 0 && { max },
3879
+ weekStartDay,
3880
+ T
3881
+ };
3882
+ return {
3883
+ resolve: (requestedFirstWeek) => applyOutOfRange({
3884
+ ...bounds,
3885
+ targetFirstWeek: requestedFirstWeek
3886
+ }),
3887
+ canShift: (currentFirstWeek, direction, shiftBy) => canShift({
3888
+ ...bounds,
3889
+ currentFirstWeek,
3890
+ direction,
3891
+ ...shiftBy !== void 0 && { shiftBy }
3892
+ })
3893
+ };
3856
3894
  }
3857
3895
  //#endregion
3858
3896
  //#region src/weeks-view-state.ts
@@ -3882,16 +3920,14 @@ function useWeeksViewRootState(props) {
3882
3920
  weekStartDay,
3883
3921
  T
3884
3922
  ]);
3885
- const outOfRangeResult = (0, react.useMemo)(() => applyOutOfRange({
3886
- targetFirstWeek: resolvedFirstWeek,
3923
+ const windowPolicy = (0, react.useMemo)(() => createWeekWindowPolicy({
3887
3924
  weekCount,
3888
3925
  behavior: outOfRangeBehavior,
3889
- ...minValue !== void 0 && { min: minValue },
3890
- ...maxValue !== void 0 && { max: maxValue },
3926
+ min: minValue,
3927
+ max: maxValue,
3891
3928
  weekStartDay,
3892
3929
  T
3893
3930
  }), [
3894
- resolvedFirstWeek,
3895
3931
  weekCount,
3896
3932
  outOfRangeBehavior,
3897
3933
  minValue,
@@ -3899,6 +3935,7 @@ function useWeeksViewRootState(props) {
3899
3935
  weekStartDay,
3900
3936
  T
3901
3937
  ]);
3938
+ const outOfRangeResult = (0, react.useMemo)(() => windowPolicy.resolve(resolvedFirstWeek), [windowPolicy, resolvedFirstWeek]);
3902
3939
  const adjustedWeeks = (0, react.useMemo)(() => {
3903
3940
  const sameFirst = T.PlainDate.compare(outOfRangeResult.firstWeek, resolvedFirstWeek) === 0;
3904
3941
  const sameCount = outOfRangeResult.weekCount === weekCount;
@@ -4077,66 +4114,31 @@ function useWeeksViewRootState(props) {
4077
4114
  onFirstWeekChange?.(newFirstWeek);
4078
4115
  }, [isControlled, onFirstWeekChange]);
4079
4116
  const goNext = (0, react.useCallback)((shiftBy) => {
4080
- const shift = shiftBy ?? weekCount;
4081
- updateFirstWeek(applyOutOfRange({
4082
- targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
4083
- weekCount,
4084
- behavior: outOfRangeBehavior,
4085
- ...minValue !== void 0 && { min: minValue },
4086
- ...maxValue !== void 0 && { max: maxValue },
4087
- weekStartDay,
4088
- T
4089
- }).firstWeek);
4117
+ const target = resolvedFirstWeek.add({ weeks: shiftBy ?? weekCount });
4118
+ updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4090
4119
  }, [
4091
4120
  resolvedFirstWeek,
4092
4121
  weekCount,
4093
- outOfRangeBehavior,
4094
- minValue,
4095
- maxValue,
4096
- weekStartDay,
4097
- T,
4122
+ windowPolicy,
4098
4123
  updateFirstWeek
4099
4124
  ]);
4100
4125
  const goPrev = (0, react.useCallback)((shiftBy) => {
4101
- const shift = shiftBy ?? weekCount;
4102
- updateFirstWeek(applyOutOfRange({
4103
- targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
4104
- weekCount,
4105
- behavior: outOfRangeBehavior,
4106
- ...minValue !== void 0 && { min: minValue },
4107
- ...maxValue !== void 0 && { max: maxValue },
4108
- weekStartDay,
4109
- T
4110
- }).firstWeek);
4126
+ const target = resolvedFirstWeek.subtract({ weeks: shiftBy ?? weekCount });
4127
+ updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4111
4128
  }, [
4112
4129
  resolvedFirstWeek,
4113
4130
  weekCount,
4114
- outOfRangeBehavior,
4115
- minValue,
4116
- maxValue,
4117
- weekStartDay,
4118
- T,
4131
+ windowPolicy,
4119
4132
  updateFirstWeek
4120
4133
  ]);
4121
4134
  const scrollToWeek = (0, react.useCallback)((target, options) => {
4122
- updateFirstWeek(applyOutOfRange({
4123
- targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
4124
- weekCount,
4125
- behavior: outOfRangeBehavior,
4126
- ...minValue !== void 0 && { min: minValue },
4127
- ...maxValue !== void 0 && { max: maxValue },
4128
- weekStartDay,
4129
- T
4130
- }).firstWeek);
4135
+ const newFirstWeek = resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options);
4136
+ updateFirstWeek(windowPolicy.resolve(newFirstWeek).firstWeek);
4131
4137
  }, [
4132
4138
  resolvedFirstWeek,
4133
4139
  weekCount,
4134
4140
  resolveSpec,
4135
- outOfRangeBehavior,
4136
- minValue,
4137
- maxValue,
4138
- weekStartDay,
4139
- T,
4141
+ windowPolicy,
4140
4142
  updateFirstWeek
4141
4143
  ]);
4142
4144
  const onWindowChangeRef = (0, react.useRef)(onWindowChange);
@@ -4153,6 +4155,7 @@ function useWeeksViewRootState(props) {
4153
4155
  weekCount,
4154
4156
  scrollBy,
4155
4157
  outOfRangeBehavior,
4158
+ windowPolicy,
4156
4159
  goNext,
4157
4160
  goPrev,
4158
4161
  scrollToWeek,
@@ -4162,6 +4165,7 @@ function useWeeksViewRootState(props) {
4162
4165
  weekCount,
4163
4166
  scrollBy,
4164
4167
  outOfRangeBehavior,
4168
+ windowPolicy,
4165
4169
  goNext,
4166
4170
  goPrev,
4167
4171
  scrollToWeek,
@@ -4275,35 +4279,20 @@ const weekCountStateAttributesMapping = {
4275
4279
  weekCount: () => null
4276
4280
  };
4277
4281
  function useWeeksNavButton(direction, shiftByProp) {
4278
- const { disabled: globalDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
4279
- const { weekCount, outOfRangeBehavior, goNext, goPrev } = useWeeksViewStable();
4282
+ const { disabled: globalDisabled } = useCalendarStable();
4283
+ const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
4280
4284
  const { windowInfo } = useWeeksViewState();
4281
4285
  const { rootState } = useViewState();
4282
4286
  const currentFirstWeek = windowInfo.windowStart;
4283
4287
  const isDisabled = (0, react.useMemo)(() => {
4284
4288
  if (globalDisabled) return true;
4285
- return !canShift({
4286
- currentFirstWeek,
4287
- weekCount,
4288
- direction: direction === "next" ? 1 : -1,
4289
- ...shiftByProp !== void 0 && { shiftBy: shiftByProp },
4290
- behavior: outOfRangeBehavior,
4291
- ...minValue !== void 0 && { min: minValue },
4292
- ...maxValue !== void 0 && { max: maxValue },
4293
- weekStartDay,
4294
- T
4295
- });
4289
+ return !windowPolicy.canShift(currentFirstWeek, direction === "next" ? 1 : -1, shiftByProp);
4296
4290
  }, [
4297
4291
  globalDisabled,
4292
+ windowPolicy,
4298
4293
  currentFirstWeek,
4299
- weekCount,
4300
4294
  direction,
4301
- shiftByProp,
4302
- outOfRangeBehavior,
4303
- minValue,
4304
- maxValue,
4305
- weekStartDay,
4306
- T
4295
+ shiftByProp
4307
4296
  ]);
4308
4297
  const state = (0, react.useMemo)(() => ({
4309
4298
  root: rootState,