@klinking/colander 3.1.0-alpha.3 → 3.1.0-alpha.5

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 (51) 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/index.cjs +1 -1
  30. package/dist/index.d.cts +1 -1
  31. package/dist/index.d.mts +1 -1
  32. package/dist/index.mjs +1 -1
  33. package/dist/{weeks-navigation-DEaASUAh.mjs → weeks-navigation-CEV8w_69.mjs} +239 -221
  34. package/dist/{weeks-navigation-DvryOSWF.cjs → weeks-navigation-q3beZn2n.cjs} +239 -221
  35. package/dist/{weeks-view-context-CNAq2Hiu.d.cts → weeks-view-context-BLZZm1fq.d.mts} +33 -2
  36. package/dist/{weeks-view-context-CsP3PBiu.d.mts → weeks-view-context-CkTcdZpj.d.cts} +33 -2
  37. package/package.json +1 -1
  38. package/src/calendar-provider.tsx +6 -0
  39. package/src/calendar-types.ts +2 -0
  40. package/src/day-cell.tsx +8 -1
  41. package/src/month-view-navigation.ts +180 -0
  42. package/src/month-view-types.ts +3 -0
  43. package/src/month-view.bounds.test.tsx +136 -0
  44. package/src/month-view.tsx +41 -217
  45. package/src/month-window.test.ts +207 -0
  46. package/src/month-window.ts +93 -0
  47. package/src/navigation.tsx +15 -74
  48. package/src/today.test.tsx +98 -0
  49. package/src/utils.test.ts +25 -0
  50. package/src/utils.ts +17 -0
  51. package/src/weeks-view-state.ts +8 -15
@@ -47,6 +47,17 @@ function getSystemTimeZone(T) {
47
47
  return T.Now.timeZoneId();
48
48
  }
49
49
  /**
50
+ * The date a view opens on: the selected date, else today in the provider's time zone.
51
+ *
52
+ * @param selected - The currently selected value, or `undefined`.
53
+ * @param today - Reads today's date in the provider's time zone.
54
+ * @param timeZone - IANA time zone.
55
+ * @param T - Temporal namespace.
56
+ */
57
+ function resolveInitialAnchor(selected, today, timeZone, T) {
58
+ return selectedToZdt(selected, timeZone, T)?.toPlainDate() ?? today();
59
+ }
60
+ /**
50
61
  * Converts any {@link DateValueObject} into a `Temporal.ZonedDateTime`.
51
62
  *
52
63
  * Handles all supported value formats (`PlainDate`, `PlainDateTime`,
@@ -803,6 +814,7 @@ function CalendarProvider(props) {
803
814
  const locale = localeProp ?? "en-US";
804
815
  const timeZone = timeZoneProp ?? getSystemTimeZone(T);
805
816
  const weekStartDay = weekStartDayProp ?? 0;
817
+ const today = useCallback(() => T.Now.zonedDateTimeISO(timeZone).toPlainDate(), [T, timeZone]);
806
818
  const resolvedFormat = formatProp ?? "PlainDate";
807
819
  const selectionMode = selectionModeProp ?? "single";
808
820
  const disabled = disabledProp ?? false;
@@ -1205,6 +1217,7 @@ function CalendarProvider(props) {
1205
1217
  ...minValue !== void 0 && { minValue },
1206
1218
  ...maxValue !== void 0 && { maxValue },
1207
1219
  timeZone,
1220
+ today,
1208
1221
  locale,
1209
1222
  temporal: T,
1210
1223
  weekStartDay,
@@ -1222,6 +1235,7 @@ function CalendarProvider(props) {
1222
1235
  minValue,
1223
1236
  maxValue,
1224
1237
  timeZone,
1238
+ today,
1225
1239
  locale,
1226
1240
  T,
1227
1241
  weekStartDay,
@@ -1293,6 +1307,177 @@ function useMonthViewState() {
1293
1307
  return ctx;
1294
1308
  }
1295
1309
  //#endregion
1310
+ //#region src/month-view-navigation.ts
1311
+ /**
1312
+ * Owns which month the view shows, in both controlled and uncontrolled mode:
1313
+ * the month state, the Prev/Next steps, and syncing the window with focus.
1314
+ *
1315
+ * `onMonthChange` fires exactly once per move: from the effect below when
1316
+ * uncontrolled, and from the step or the focus-sync effect when controlled.
1317
+ */
1318
+ function useMonthNavigation(input) {
1319
+ const { month, defaultMonth, initialAnchor, onMonthChange, policy, focusedDate, setFocusedDate, T } = input;
1320
+ const isControlled = month !== void 0;
1321
+ const [internalMonth, setInternalMonth] = useState(() => {
1322
+ if (month) return {
1323
+ year: month.year,
1324
+ month: month.month
1325
+ };
1326
+ if (defaultMonth) return {
1327
+ year: defaultMonth.year,
1328
+ month: defaultMonth.month
1329
+ };
1330
+ const anchor = initialAnchor();
1331
+ return {
1332
+ year: anchor.year,
1333
+ month: anchor.month
1334
+ };
1335
+ });
1336
+ const year = isControlled ? month.year : internalMonth.year;
1337
+ const monthNumber = isControlled ? month.month : internalMonth.month;
1338
+ const currentMonth = useMemo(() => ({
1339
+ year,
1340
+ month: monthNumber
1341
+ }), [year, monthNumber]);
1342
+ const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
1343
+ year,
1344
+ month: monthNumber
1345
+ }), [
1346
+ year,
1347
+ monthNumber,
1348
+ T
1349
+ ]);
1350
+ const onMonthChangeRef = useRef(onMonthChange);
1351
+ onMonthChangeRef.current = onMonthChange;
1352
+ const notifyMonth = useCallback((target) => {
1353
+ onMonthChangeRef.current?.(T.PlainYearMonth.from(target));
1354
+ }, [T]);
1355
+ const skipFocusSyncForRef = useRef(null);
1356
+ const prevFocusedRef = useRef(focusedDate);
1357
+ useEffect(() => {
1358
+ skipFocusSyncForRef.current = null;
1359
+ }, [month?.year, month?.month]);
1360
+ useEffect(() => {
1361
+ const prevFocused = prevFocusedRef.current;
1362
+ prevFocusedRef.current = focusedDate;
1363
+ const target = {
1364
+ year: focusedDate.year,
1365
+ month: focusedDate.month
1366
+ };
1367
+ if (isControlled) {
1368
+ if (skipFocusSyncForRef.current === focusedDate) {
1369
+ skipFocusSyncForRef.current = null;
1370
+ return;
1371
+ }
1372
+ if (prevFocused === focusedDate) return;
1373
+ if (policy.isVisible(currentMonth, target)) return;
1374
+ notifyMonth(policy.reveal(currentMonth, target));
1375
+ return;
1376
+ }
1377
+ setInternalMonth((prev) => {
1378
+ const next = policy.reveal(prev, target);
1379
+ if (next.year === prev.year && next.month === prev.month) return prev;
1380
+ return next;
1381
+ });
1382
+ }, [
1383
+ focusedDate,
1384
+ isControlled,
1385
+ policy,
1386
+ currentMonth,
1387
+ notifyMonth
1388
+ ]);
1389
+ const mountedRef = useRef(false);
1390
+ useEffect(() => {
1391
+ if (!mountedRef.current) {
1392
+ mountedRef.current = true;
1393
+ return;
1394
+ }
1395
+ if (isControlled) return;
1396
+ onMonthChangeRef.current?.(viewingYearMonth);
1397
+ }, [viewingYearMonth, isControlled]);
1398
+ const go = useCallback((direction) => {
1399
+ if (isControlled) {
1400
+ const step = policy.step(month, direction);
1401
+ if (step.blocked) return;
1402
+ const nextFocus = focusedDateForMonth(focusedDate, step.start, step.firstDay);
1403
+ skipFocusSyncForRef.current = nextFocus;
1404
+ notifyMonth(step.start);
1405
+ setFocusedDate(nextFocus);
1406
+ return;
1407
+ }
1408
+ setInternalMonth((m) => {
1409
+ const step = policy.step(m, direction);
1410
+ if (step.blocked) return m;
1411
+ setFocusedDate((prev) => focusedDateForMonth(prev, step.start, step.firstDay));
1412
+ return step.start;
1413
+ });
1414
+ }, [
1415
+ isControlled,
1416
+ month,
1417
+ policy,
1418
+ notifyMonth,
1419
+ focusedDate,
1420
+ setFocusedDate
1421
+ ]);
1422
+ return {
1423
+ currentMonth,
1424
+ viewingYearMonth,
1425
+ goNextMonth: useCallback(() => go("next"), [go]),
1426
+ goPrevMonth: useCallback(() => go("prev"), [go])
1427
+ };
1428
+ }
1429
+ //#endregion
1430
+ //#region src/month-window.ts
1431
+ const monthIndex = (m) => m.year * 12 + (m.month - 1);
1432
+ /**
1433
+ * Builds the policy for a MonthView window of `numberOfMonths` months.
1434
+ *
1435
+ * `unbounded` never blocks a step: `min`/`max` only gate which days are
1436
+ * selectable, not which months can be viewed. Any other behavior is `stop`,
1437
+ * which blocks a step whose entering month lies beyond the bound's month.
1438
+ */
1439
+ function createMonthWindowPolicy(input) {
1440
+ const { numberOfMonths, behavior, min, max, T } = input;
1441
+ return {
1442
+ step(start, direction) {
1443
+ const adjacent = computeAdjacentMonth(start, direction, T);
1444
+ const newStart = {
1445
+ year: adjacent.year,
1446
+ month: adjacent.month
1447
+ };
1448
+ const entering = direction === "prev" ? newStart : monthAt(newStart, numberOfMonths - 1);
1449
+ let blocked = false;
1450
+ if (behavior !== "unbounded") {
1451
+ const bound = direction === "prev" ? min : max;
1452
+ if (bound) {
1453
+ const diff = monthIndex(entering) - monthIndex(bound);
1454
+ blocked = direction === "prev" ? diff < 0 : diff > 0;
1455
+ }
1456
+ }
1457
+ return {
1458
+ start: newStart,
1459
+ entering,
1460
+ firstDay: adjacent.firstDay,
1461
+ blocked
1462
+ };
1463
+ },
1464
+ isVisible(start, target) {
1465
+ const offset = monthIndex(target) - monthIndex(start);
1466
+ return offset >= 0 && offset < numberOfMonths;
1467
+ },
1468
+ reveal(start, target) {
1469
+ return shiftWindowToMonth(start, target, numberOfMonths);
1470
+ }
1471
+ };
1472
+ }
1473
+ function monthAt(start, offset) {
1474
+ const index = monthIndex(start) + offset;
1475
+ return {
1476
+ year: Math.floor(index / 12),
1477
+ month: index % 12 + 1
1478
+ };
1479
+ }
1480
+ //#endregion
1296
1481
  //#region src/view-context.ts
1297
1482
  /** @internal React context for the active view (MonthView or WeeksView). */
1298
1483
  const ViewContext = createContext(null);
@@ -1329,40 +1514,39 @@ function MonthViewRoot(props) {
1329
1514
  const calStable = useCalendarStable();
1330
1515
  const calState = useCalendarState();
1331
1516
  const T = calStable.temporal;
1332
- const { timeZone, weekStartDay, isDateDisabled } = calStable;
1333
- const isMonthControlled = monthProp !== void 0;
1334
- const [internalMonth, setInternalMonth] = useState(() => {
1335
- if (monthProp) return {
1336
- year: monthProp.year,
1337
- month: monthProp.month
1338
- };
1339
- if (defaultMonthProp) return {
1340
- year: defaultMonthProp.year,
1341
- month: defaultMonthProp.month
1342
- };
1343
- if (calState.selected) {
1344
- const zdt = toZonedDateTime(calState.selected, timeZone, T);
1345
- return {
1346
- year: zdt.year,
1347
- month: zdt.month
1348
- };
1349
- }
1350
- const now = T.Now.zonedDateTimeISO(timeZone);
1351
- return {
1352
- year: now.year,
1353
- month: now.month
1354
- };
1355
- });
1356
- const currentMonth = isMonthControlled ? {
1357
- year: monthProp.year,
1358
- month: monthProp.month
1359
- } : internalMonth;
1360
- const [focusedDate, setFocusedDate] = useState(() => {
1361
- if (calState.selected) return toZonedDateTime(calState.selected, timeZone, T).toPlainDate();
1362
- return T.Now.plainDateISO();
1363
- });
1517
+ const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
1518
+ const [focusedDate, setFocusedDate] = useState(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
1364
1519
  const [gridHasFocus, setGridHasFocus] = useState(false);
1365
1520
  const gridFocusedRef = useRef(false);
1521
+ const { minValue, maxValue } = calStable;
1522
+ const windowPolicy = useMemo(() => createMonthWindowPolicy({
1523
+ numberOfMonths,
1524
+ behavior: outOfRangeBehavior,
1525
+ min: minValue,
1526
+ max: maxValue,
1527
+ T
1528
+ }), [
1529
+ numberOfMonths,
1530
+ outOfRangeBehavior,
1531
+ minValue,
1532
+ maxValue,
1533
+ T
1534
+ ]);
1535
+ const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
1536
+ month: monthProp,
1537
+ defaultMonth: defaultMonthProp,
1538
+ initialAnchor: useCallback(() => resolveInitialAnchor(calState.selected, today, timeZone, T), [
1539
+ calState.selected,
1540
+ today,
1541
+ timeZone,
1542
+ T
1543
+ ]),
1544
+ onMonthChange,
1545
+ policy: windowPolicy,
1546
+ focusedDate,
1547
+ setFocusedDate,
1548
+ T
1549
+ });
1366
1550
  const [gridLabelIds, setGridLabelIds] = useState({});
1367
1551
  const setGridLabelId = useCallback((monthIndex, id) => {
1368
1552
  setGridLabelIds((prev) => {
@@ -1379,140 +1563,6 @@ function MonthViewRoot(props) {
1379
1563
  };
1380
1564
  });
1381
1565
  }, []);
1382
- const onMonthChangeRef = useRef(onMonthChange);
1383
- onMonthChangeRef.current = onMonthChange;
1384
- const notifyMonth = useCallback((year, month) => {
1385
- onMonthChangeRef.current?.(T.PlainYearMonth.from({
1386
- year,
1387
- month
1388
- }));
1389
- }, [T]);
1390
- const isMonthVisible = useCallback((targetYear, targetMonth) => {
1391
- for (let i = 0; i < numberOfMonths; i++) {
1392
- const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1393
- const y = Math.floor(totalMonths / 12);
1394
- const m = totalMonths % 12 + 1;
1395
- if (targetYear === y && targetMonth === m) return true;
1396
- }
1397
- return false;
1398
- }, [
1399
- currentMonth.year,
1400
- currentMonth.month,
1401
- numberOfMonths
1402
- ]);
1403
- const navigateToMonth = useCallback((targetYear, targetMonth) => {
1404
- if (isMonthControlled) return;
1405
- setInternalMonth((prev) => {
1406
- const next = shiftWindowToMonth(prev, {
1407
- year: targetYear,
1408
- month: targetMonth
1409
- }, numberOfMonths);
1410
- if (next.year === prev.year && next.month === prev.month) return prev;
1411
- return next;
1412
- });
1413
- }, [isMonthControlled, numberOfMonths]);
1414
- const skipFocusSyncForRef = useRef(null);
1415
- const prevFocusedRef = useRef(focusedDate);
1416
- useEffect(() => {
1417
- skipFocusSyncForRef.current = null;
1418
- }, [monthProp?.year, monthProp?.month]);
1419
- useEffect(() => {
1420
- const prevFocused = prevFocusedRef.current;
1421
- prevFocusedRef.current = focusedDate;
1422
- if (isMonthControlled) {
1423
- if (skipFocusSyncForRef.current === focusedDate) {
1424
- skipFocusSyncForRef.current = null;
1425
- return;
1426
- }
1427
- if (prevFocused === focusedDate) return;
1428
- if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
1429
- const next = shiftWindowToMonth({
1430
- year: currentMonth.year,
1431
- month: currentMonth.month
1432
- }, {
1433
- year: focusedDate.year,
1434
- month: focusedDate.month
1435
- }, numberOfMonths);
1436
- notifyMonth(next.year, next.month);
1437
- return;
1438
- }
1439
- navigateToMonth(focusedDate.year, focusedDate.month);
1440
- }, [
1441
- focusedDate,
1442
- navigateToMonth,
1443
- isMonthControlled,
1444
- isMonthVisible,
1445
- notifyMonth,
1446
- currentMonth.year,
1447
- currentMonth.month,
1448
- numberOfMonths
1449
- ]);
1450
- const goNextMonth = useCallback(() => {
1451
- if (isMonthControlled) {
1452
- const { year, month, firstDay } = computeAdjacentMonth({
1453
- year: monthProp.year,
1454
- month: monthProp.month
1455
- }, "next", T);
1456
- const nextFocus = focusedDateForMonth(focusedDate, {
1457
- year,
1458
- month
1459
- }, firstDay);
1460
- skipFocusSyncForRef.current = nextFocus;
1461
- notifyMonth(year, month);
1462
- setFocusedDate(nextFocus);
1463
- return;
1464
- }
1465
- setInternalMonth((m) => {
1466
- const { year, month, firstDay } = computeAdjacentMonth(m, "next", T);
1467
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1468
- year,
1469
- month
1470
- }, firstDay));
1471
- return {
1472
- year,
1473
- month
1474
- };
1475
- });
1476
- }, [
1477
- T,
1478
- isMonthControlled,
1479
- monthProp,
1480
- notifyMonth,
1481
- focusedDate
1482
- ]);
1483
- const goPrevMonth = useCallback(() => {
1484
- if (isMonthControlled) {
1485
- const { year, month, firstDay } = computeAdjacentMonth({
1486
- year: monthProp.year,
1487
- month: monthProp.month
1488
- }, "prev", T);
1489
- const nextFocus = focusedDateForMonth(focusedDate, {
1490
- year,
1491
- month
1492
- }, firstDay);
1493
- skipFocusSyncForRef.current = nextFocus;
1494
- notifyMonth(year, month);
1495
- setFocusedDate(nextFocus);
1496
- return;
1497
- }
1498
- setInternalMonth((m) => {
1499
- const { year, month, firstDay } = computeAdjacentMonth(m, "prev", T);
1500
- setFocusedDate((prev) => focusedDateForMonth(prev, {
1501
- year,
1502
- month
1503
- }, firstDay));
1504
- return {
1505
- year,
1506
- month
1507
- };
1508
- });
1509
- }, [
1510
- T,
1511
- isMonthControlled,
1512
- monthProp,
1513
- notifyMonth,
1514
- focusedDate
1515
- ]);
1516
1566
  const allMonths = useMemo(() => {
1517
1567
  const opts = {
1518
1568
  weekStartDay,
@@ -1572,19 +1622,6 @@ function MonthViewRoot(props) {
1572
1622
  T,
1573
1623
  gridHasFocus
1574
1624
  ]);
1575
- const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
1576
- year: currentMonth.year,
1577
- month: currentMonth.month
1578
- }), [currentMonth, T]);
1579
- const mountedRef = useRef(false);
1580
- useEffect(() => {
1581
- if (!mountedRef.current) {
1582
- mountedRef.current = true;
1583
- return;
1584
- }
1585
- if (isMonthControlled) return;
1586
- onMonthChangeRef.current?.(viewingYearMonth);
1587
- }, [viewingYearMonth, isMonthControlled]);
1588
1625
  const rootState = useMemo(() => ({
1589
1626
  ...calState.baseRootState,
1590
1627
  focused: focusedDate,
@@ -1599,6 +1636,7 @@ function MonthViewRoot(props) {
1599
1636
  fixedWeeks,
1600
1637
  outsideDays,
1601
1638
  outOfRangeBehavior,
1639
+ windowPolicy,
1602
1640
  goNextMonth,
1603
1641
  goPrevMonth,
1604
1642
  setGridLabelId,
@@ -1608,6 +1646,7 @@ function MonthViewRoot(props) {
1608
1646
  fixedWeeks,
1609
1647
  outsideDays,
1610
1648
  outOfRangeBehavior,
1649
+ windowPolicy,
1611
1650
  goNextMonth,
1612
1651
  goPrevMonth,
1613
1652
  setGridLabelId
@@ -2252,7 +2291,7 @@ function computeWeeksKeyNav(input) {
2252
2291
  //#endregion
2253
2292
  //#region src/day-cell.tsx
2254
2293
  /** Computes derived day cell state from context values. Pure function, no hooks. */
2255
- function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd) {
2294
+ function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, today, T, selectionMode, outsideDays, previewStart, previewEnd) {
2256
2295
  const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
2257
2296
  if (!isCurrentMonth && outsideDays === "hidden") return {
2258
2297
  root: rootState,
@@ -2283,7 +2322,6 @@ function computeDayCellState(date, orientation, columnIndex, rootState, selected
2283
2322
  rangePreviewHasEnd: false,
2284
2323
  isTabTarget: false
2285
2324
  };
2286
- const today = T.Now.plainDateISO();
2287
2325
  const isToday = T.PlainDate.compare(date, today) === 0;
2288
2326
  const isRange = selectionMode === "range";
2289
2327
  let isRangeStart = false;
@@ -2477,7 +2515,8 @@ const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
2477
2515
  function DayCellTemplate(props) {
2478
2516
  const { date: dateProp, ...restProps } = props;
2479
2517
  const weekData = useContext(WeekDataContext);
2480
- const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2518
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2519
+ const todayDate = today();
2481
2520
  const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2482
2521
  const viewCtx = useViewContext();
2483
2522
  const { focusedDate, tabTargetDate } = viewCtx;
@@ -2492,7 +2531,7 @@ function DayCellTemplate(props) {
2492
2531
  const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2493
2532
  year: dateProp.year,
2494
2533
  month: dateProp.month
2495
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2534
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2496
2535
  return /* @__PURE__ */ jsx(DayCellInstance, {
2497
2536
  ...restProps,
2498
2537
  date: dateProp,
@@ -2506,7 +2545,7 @@ function DayCellTemplate(props) {
2506
2545
  const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2507
2546
  year: day.year,
2508
2547
  month: day.month
2509
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2548
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2510
2549
  return /* @__PURE__ */ jsx(DayCellInstance, {
2511
2550
  ...restProps,
2512
2551
  date: day,
@@ -2599,7 +2638,8 @@ function DayButtonFallbackFn(props, ref) {
2599
2638
  const { date, ...restProps } = props;
2600
2639
  const { orientation } = useContext(GridContext);
2601
2640
  const weekData = useContext(WeekDataContext);
2602
- const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2641
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2642
+ const todayDate = today();
2603
2643
  const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2604
2644
  const viewCtx = useViewContext();
2605
2645
  const { focusedDate, tabTargetDate } = viewCtx;
@@ -2610,7 +2650,7 @@ function DayButtonFallbackFn(props, ref) {
2610
2650
  month: date.month
2611
2651
  } : weekData?.gridMonth ?? currentDateTime;
2612
2652
  const daysInWeek = date.daysInWeek;
2613
- const derived = computeDayCellState(date, orientation, (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2653
+ 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);
2614
2654
  return /* @__PURE__ */ jsx(DayButtonInner, {
2615
2655
  ...restProps,
2616
2656
  ref,
@@ -3166,37 +3206,16 @@ function MonthYearStringFn(props, ref) {
3166
3206
  */
3167
3207
  const MonthYearString = forwardRef(MonthYearStringFn);
3168
3208
  function useNavButton(direction) {
3169
- const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
3170
- const monthViewStable = useMonthViewStable();
3171
- const monthViewState = useMonthViewState();
3172
- const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths, outOfRangeBehavior } = monthViewStable;
3173
- const { currentMonth: currentDateTime, allMonths, rootState } = monthViewState;
3174
- const refMonth = direction === "next" ? allMonths[numberOfMonths - 1] ?? currentDateTime : currentDateTime;
3175
- const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
3176
- const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
3177
- const boundValue = direction === "prev" ? minValue : maxValue;
3178
- const isDisabled = useMemo(() => {
3179
- if (globalDisabled) return true;
3180
- if (outOfRangeBehavior === "unbounded") return false;
3181
- if (!boundValue) return false;
3182
- if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
3183
- return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
3184
- }, [
3185
- globalDisabled,
3186
- outOfRangeBehavior,
3187
- destYear,
3188
- destMonth,
3189
- 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,
3190
3215
  direction
3191
3216
  ]);
3192
- const target = useMemo(() => T.PlainYearMonth.from({
3193
- year: destYear,
3194
- month: destMonth
3195
- }), [
3196
- destYear,
3197
- destMonth,
3198
- T
3199
- ]);
3217
+ const isDisabled = globalDisabled || step.blocked;
3218
+ const target = useMemo(() => T.PlainYearMonth.from(step.entering), [step.entering, T]);
3200
3219
  return {
3201
3220
  state: useMemo(() => ({
3202
3221
  root: rootState,
@@ -3839,14 +3858,13 @@ function useWeeksViewRootState(props) {
3839
3858
  const calStable = useCalendarStable();
3840
3859
  const calState = useCalendarState();
3841
3860
  const T = calStable.temporal;
3842
- const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } = calStable;
3861
+ const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone, today } = calStable;
3843
3862
  const isControlled = firstWeekProp !== void 0;
3844
3863
  const resolveSpec = useCallback((spec) => resolveFirstWeekSpec(spec, weekStartDay, T), [weekStartDay, T]);
3845
3864
  const [internalFirstWeek, setInternalFirstWeek] = useState(() => {
3846
3865
  if (firstWeekProp !== void 0) return resolveSpec(firstWeekProp);
3847
3866
  if (defaultFirstWeekProp !== void 0) return resolveSpec(defaultFirstWeekProp);
3848
- if (calState.selected) return resolveSpec(toZonedDateTime(calState.selected, timeZone, T).toPlainDate());
3849
- return resolveSpec(T.Now.plainDateISO());
3867
+ return resolveSpec(resolveInitialAnchor(calState.selected, today, timeZone, T));
3850
3868
  });
3851
3869
  const resolvedFirstWeek = isControlled ? resolveSpec(firstWeekProp) : internalFirstWeek;
3852
3870
  const rawWeeks = useMemo(() => computeWeeksInWindow(resolvedFirstWeek, weekCount, weekStartDay, T), [
@@ -3901,10 +3919,10 @@ function useWeeksViewRootState(props) {
3901
3919
  const firstWeek = weeks[0];
3902
3920
  const lastWeek = weeks[weeks.length - 1];
3903
3921
  if (firstWeek === void 0 || lastWeek === void 0) {
3904
- const today = T.Now.plainDateISO();
3922
+ const now = today();
3905
3923
  return {
3906
- windowStart: today,
3907
- windowEnd: today,
3924
+ windowStart: now,
3925
+ windowEnd: now,
3908
3926
  weekCount: 0,
3909
3927
  dayCount: 0,
3910
3928
  enabledWeekCount: 0,