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

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 (57) 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 +11 -2
  31. package/dist/index.d.mts +11 -2
  32. package/dist/index.mjs +1 -1
  33. package/dist/{weeks-navigation-BRxzsy0z.cjs → weeks-navigation-DV538__x.cjs} +115 -135
  34. package/dist/{weeks-navigation-CXRaVP02.mjs → weeks-navigation-elCpdfQ3.mjs} +115 -135
  35. package/dist/{index-CJgr0MEp.d.cts → weeks-view-context-CUCy8njs.d.cts} +3 -8
  36. package/dist/{index-DB6V_Y6x.d.mts → weeks-view-context-E1NwyNgQ.d.mts} +3 -8
  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 +17 -16
  41. package/src/drag-handle.tsx +2 -2
  42. package/src/grid-header.tsx +3 -3
  43. package/src/grid.tsx +20 -61
  44. package/src/month-view.tsx +32 -17
  45. package/src/navigation.tsx +3 -2
  46. package/src/range-preview.tsx +3 -5
  47. package/src/selected-range.tsx +3 -5
  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/view-context.test.tsx +126 -0
  52. package/src/view-context.ts +43 -0
  53. package/src/week-number.tsx +3 -3
  54. package/src/weeks-navigation.tsx +3 -3
  55. package/src/weeks-view-state.ts +31 -17
  56. package/src/weeks-view.test.tsx +115 -13
  57. package/src/weeks-view.tsx +22 -51
@@ -70,6 +70,17 @@ function getSystemTimeZone(T) {
70
70
  return T.Now.timeZoneId();
71
71
  }
72
72
  /**
73
+ * The date a view opens on: the selected date, else today in the provider's time zone.
74
+ *
75
+ * @param selected - The currently selected value, or `undefined`.
76
+ * @param today - Reads today's date in the provider's time zone.
77
+ * @param timeZone - IANA time zone.
78
+ * @param T - Temporal namespace.
79
+ */
80
+ function resolveInitialAnchor(selected, today, timeZone, T) {
81
+ return selectedToZdt(selected, timeZone, T)?.toPlainDate() ?? today();
82
+ }
83
+ /**
73
84
  * Converts any {@link DateValueObject} into a `Temporal.ZonedDateTime`.
74
85
  *
75
86
  * Handles all supported value formats (`PlainDate`, `PlainDateTime`,
@@ -826,6 +837,7 @@ function CalendarProvider(props) {
826
837
  const locale = localeProp ?? "en-US";
827
838
  const timeZone = timeZoneProp ?? getSystemTimeZone(T);
828
839
  const weekStartDay = weekStartDayProp ?? 0;
840
+ const today = (0, react.useCallback)(() => T.Now.zonedDateTimeISO(timeZone).toPlainDate(), [T, timeZone]);
829
841
  const resolvedFormat = formatProp ?? "PlainDate";
830
842
  const selectionMode = selectionModeProp ?? "single";
831
843
  const disabled = disabledProp ?? false;
@@ -1228,6 +1240,7 @@ function CalendarProvider(props) {
1228
1240
  ...minValue !== void 0 && { minValue },
1229
1241
  ...maxValue !== void 0 && { maxValue },
1230
1242
  timeZone,
1243
+ today,
1231
1244
  locale,
1232
1245
  temporal: T,
1233
1246
  weekStartDay,
@@ -1245,6 +1258,7 @@ function CalendarProvider(props) {
1245
1258
  minValue,
1246
1259
  maxValue,
1247
1260
  timeZone,
1261
+ today,
1248
1262
  locale,
1249
1263
  T,
1250
1264
  weekStartDay,
@@ -1325,6 +1339,22 @@ function useViewContext() {
1325
1339
  if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
1326
1340
  return ctx;
1327
1341
  }
1342
+ /** @internal Context for {@link ViewStableContextValue}. */
1343
+ const ViewStableContext = (0, react.createContext)(null);
1344
+ /** @internal Context for {@link ViewStateContextValue}. */
1345
+ const ViewStateContext = (0, react.createContext)(null);
1346
+ /** Returns the nearest view's stable values. */
1347
+ function useViewStable() {
1348
+ const ctx = (0, react.useContext)(ViewStableContext);
1349
+ if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
1350
+ return ctx;
1351
+ }
1352
+ /** Returns the nearest view's volatile state. */
1353
+ function useViewState() {
1354
+ const ctx = (0, react.useContext)(ViewStateContext);
1355
+ if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
1356
+ return ctx;
1357
+ }
1328
1358
  //#endregion
1329
1359
  //#region src/month-view.tsx
1330
1360
  function MonthViewRoot(props) {
@@ -1336,7 +1366,7 @@ function MonthViewRoot(props) {
1336
1366
  const calStable = useCalendarStable();
1337
1367
  const calState = useCalendarState();
1338
1368
  const T = calStable.temporal;
1339
- const { timeZone, weekStartDay, isDateDisabled } = calStable;
1369
+ const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
1340
1370
  const isMonthControlled = monthProp !== void 0;
1341
1371
  const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
1342
1372
  if (monthProp) return {
@@ -1347,27 +1377,17 @@ function MonthViewRoot(props) {
1347
1377
  year: defaultMonthProp.year,
1348
1378
  month: defaultMonthProp.month
1349
1379
  };
1350
- if (calState.selected) {
1351
- const zdt = toZonedDateTime(calState.selected, timeZone, T);
1352
- return {
1353
- year: zdt.year,
1354
- month: zdt.month
1355
- };
1356
- }
1357
- const now = T.Now.zonedDateTimeISO(timeZone);
1380
+ const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
1358
1381
  return {
1359
- year: now.year,
1360
- month: now.month
1382
+ year: anchor.year,
1383
+ month: anchor.month
1361
1384
  };
1362
1385
  });
1363
1386
  const currentMonth = isMonthControlled ? {
1364
1387
  year: monthProp.year,
1365
1388
  month: monthProp.month
1366
1389
  } : internalMonth;
1367
- const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
1368
- if (calState.selected) return toZonedDateTime(calState.selected, timeZone, T).toPlainDate();
1369
- return T.Now.plainDateISO();
1370
- });
1390
+ const [focusedDate, setFocusedDate] = (0, react.useState)(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
1371
1391
  const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
1372
1392
  const gridFocusedRef = (0, react.useRef)(false);
1373
1393
  const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
@@ -1646,13 +1666,27 @@ function MonthViewRoot(props) {
1646
1666
  tabTargetDate,
1647
1667
  gridHasFocus
1648
1668
  ]);
1669
+ const viewStableCtx = (0, react.useMemo)(() => ({
1670
+ gridFocusedRef,
1671
+ outsideDays
1672
+ }), [outsideDays]);
1673
+ const viewStateCtx = (0, react.useMemo)(() => ({
1674
+ currentDateTime,
1675
+ rootState
1676
+ }), [currentDateTime, rootState]);
1649
1677
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
1650
1678
  value: stableCtx,
1651
1679
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
1652
1680
  value: stateCtx,
1653
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
1654
- value: viewCtx,
1655
- children
1681
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
1682
+ value: viewStableCtx,
1683
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
1684
+ value: viewStateCtx,
1685
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
1686
+ value: viewCtx,
1687
+ children
1688
+ })
1689
+ })
1656
1690
  })
1657
1691
  })
1658
1692
  });
@@ -1688,7 +1722,7 @@ const GridMonthContext = (0, react.createContext)(null);
1688
1722
  //#region src/grid-header.tsx
1689
1723
  function useGridHeaderCellState(index) {
1690
1724
  const { locale, temporal: T, weekStartDay } = useCalendarStable();
1691
- const { rootState } = useMonthViewState();
1725
+ const { rootState } = useViewState();
1692
1726
  const weekdayNames = (0, react.useMemo)(() => getWeekdayNames(locale, T, weekStartDay), [
1693
1727
  locale,
1694
1728
  T,
@@ -1764,7 +1798,7 @@ function GridHeaderCellFn(props, ref) {
1764
1798
  const GridHeaderCell = (0, react.forwardRef)(GridHeaderCellFn);
1765
1799
  function GridHeaderFn(props, ref) {
1766
1800
  const { render, children, ...otherProps } = props;
1767
- const { rootState } = useMonthViewState();
1801
+ const { rootState } = useViewState();
1768
1802
  const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
1769
1803
  return (0, _base_ui_react_use_render.useRender)({
1770
1804
  defaultTagName: "thead",
@@ -2245,7 +2279,7 @@ function computeWeeksKeyNav(input) {
2245
2279
  //#endregion
2246
2280
  //#region src/day-cell.tsx
2247
2281
  /** Computes derived day cell state from context values. Pure function, no hooks. */
2248
- function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd) {
2282
+ function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, today, T, selectionMode, outsideDays, previewStart, previewEnd) {
2249
2283
  const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
2250
2284
  if (!isCurrentMonth && outsideDays === "hidden") return {
2251
2285
  root: rootState,
@@ -2276,7 +2310,6 @@ function computeDayCellState(date, orientation, columnIndex, rootState, selected
2276
2310
  rangePreviewHasEnd: false,
2277
2311
  isTabTarget: false
2278
2312
  };
2279
- const today = T.Now.plainDateISO();
2280
2313
  const isToday = T.PlainDate.compare(date, today) === 0;
2281
2314
  const isRange = selectionMode === "range";
2282
2315
  let isRangeStart = false;
@@ -2470,13 +2503,14 @@ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsA
2470
2503
  function DayCellTemplate(props) {
2471
2504
  const { date: dateProp, ...restProps } = props;
2472
2505
  const weekData = (0, react.useContext)(WeekDataContext);
2473
- const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2506
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2507
+ const todayDate = today();
2474
2508
  const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2475
2509
  const viewCtx = useViewContext();
2476
2510
  const { focusedDate, tabTargetDate } = viewCtx;
2477
- const monthStable = (0, react.useContext)(MonthViewStableContext);
2478
- const { rootState, weeks, currentMonth: currentDateTime } = useMonthViewState();
2479
- const outsideDays = monthStable?.outsideDays ?? "enabled";
2511
+ const { rootState, currentDateTime } = useViewState();
2512
+ const { outsideDays } = useViewStable();
2513
+ const monthState = (0, react.useContext)(MonthViewStateContext);
2480
2514
  const isWeeksView = viewCtx.viewType === "weeks";
2481
2515
  const cellMonth = isWeeksView ? null : weekData?.gridMonth ?? currentDateTime;
2482
2516
  const { orientation } = (0, react.useContext)(GridContext);
@@ -2485,21 +2519,21 @@ function DayCellTemplate(props) {
2485
2519
  const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2486
2520
  year: dateProp.year,
2487
2521
  month: dateProp.month
2488
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2522
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2489
2523
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2490
2524
  ...restProps,
2491
2525
  date: dateProp,
2492
2526
  _derivedState: derived
2493
2527
  });
2494
2528
  }
2495
- const days = weekData ? weekData.days : weeks.flat();
2529
+ const days = weekData ? weekData.days : monthState?.weeks.flat() ?? [];
2496
2530
  const perWeek = weekData != null;
2497
2531
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
2498
2532
  const daysInWeek = day.daysInWeek;
2499
2533
  const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2500
2534
  year: day.year,
2501
2535
  month: day.month
2502
- } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2536
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2503
2537
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2504
2538
  ...restProps,
2505
2539
  date: day,
@@ -2512,7 +2546,7 @@ function DayButtonInnerFn(props, ref) {
2512
2546
  const { render, date, _derivedState, ...otherProps } = props;
2513
2547
  const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
2514
2548
  const { setFocusedDate } = useViewContext();
2515
- const gridFocusedRef = (0, react.useContext)(MonthViewStableContext).gridFocusedRef;
2549
+ const { gridFocusedRef } = useViewStable();
2516
2550
  const internalRef = (0, react.useRef)(null);
2517
2551
  const isHidden = _derivedState?.hidden ?? false;
2518
2552
  const isFocused = _derivedState?.focused ?? false;
@@ -2592,19 +2626,19 @@ function DayButtonFallbackFn(props, ref) {
2592
2626
  const { date, ...restProps } = props;
2593
2627
  const { orientation } = (0, react.useContext)(GridContext);
2594
2628
  const weekData = (0, react.useContext)(WeekDataContext);
2595
- const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2629
+ const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
2630
+ const todayDate = today();
2596
2631
  const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2597
2632
  const viewCtx = useViewContext();
2598
2633
  const { focusedDate, tabTargetDate } = viewCtx;
2599
- const monthStable = (0, react.useContext)(MonthViewStableContext);
2600
- const { rootState, currentMonth: currentDateTime } = useMonthViewState();
2601
- const outsideDays = monthStable?.outsideDays ?? "enabled";
2634
+ const { rootState, currentDateTime } = useViewState();
2635
+ const { outsideDays } = useViewStable();
2602
2636
  const cellMonth = viewCtx.viewType === "weeks" ? {
2603
2637
  year: date.year,
2604
2638
  month: date.month
2605
2639
  } : weekData?.gridMonth ?? currentDateTime;
2606
2640
  const daysInWeek = date.daysInWeek;
2607
- 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);
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);
2608
2642
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
2609
2643
  ...restProps,
2610
2644
  ref,
@@ -2714,17 +2748,15 @@ const gridStateAttributesMapping = {
2714
2748
  * delegates to the appropriate internal renderer.
2715
2749
  */
2716
2750
  function GridFn(props, ref) {
2717
- const monthState = (0, react.useContext)(MonthViewStableContext);
2718
- const weeksState = (0, react.useContext)(WeeksViewStateContext);
2719
- if (monthState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGrid, {
2751
+ const view = (0, react.useContext)(ViewContext);
2752
+ if (!view) throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
2753
+ return view.viewType === "weeks" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
2720
2754
  ref,
2721
2755
  ...props
2722
- });
2723
- if (weeksState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
2756
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGrid, {
2724
2757
  ref,
2725
2758
  ...props
2726
2759
  });
2727
- throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
2728
2760
  }
2729
2761
  const Grid = (0, react.forwardRef)(GridFn);
2730
2762
  function MonthGridFn(props, ref) {
@@ -2831,7 +2863,7 @@ function WeeksViewGridFn(props, ref) {
2831
2863
  const weeksStable = useWeeksViewStable();
2832
2864
  const weeksState = useWeeksViewState();
2833
2865
  const { gridFocusedRef } = weeksStable;
2834
- const { gridLabelIds, weeks, currentDateTime } = weeksState;
2866
+ const { gridLabelIds, weeks } = weeksState;
2835
2867
  const handleKeyDown = useWeeksGridKeyboard();
2836
2868
  const gridRef = (0, react.useRef)(null);
2837
2869
  (0, react.useEffect)(() => {
@@ -2902,47 +2934,16 @@ function WeeksViewGridFn(props, ref) {
2902
2934
  props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
2903
2935
  });
2904
2936
  const orientationCtx = (0, react.useMemo)(() => ({ orientation: resolvedOrientation }), [resolvedOrientation]);
2905
- const monthViewStableShim = (0, react.useMemo)(() => ({
2906
- numberOfMonths: 1,
2907
- fixedWeeks: false,
2908
- outsideDays: "enabled",
2909
- outOfRangeBehavior: "unbounded",
2910
- goNextMonth: () => {},
2911
- goPrevMonth: () => {},
2912
- setGridLabelId: () => {},
2913
- gridFocusedRef
2914
- }), [gridFocusedRef]);
2915
- const monthViewStateShim = (0, react.useMemo)(() => ({
2916
- currentMonth: {
2917
- year: currentDateTime.year,
2918
- month: currentDateTime.month
2919
- },
2920
- weeks: [],
2921
- allMonths: [],
2922
- currentDateTime,
2923
- gridLabelIds,
2924
- rootState: weeksState.rootState
2925
- }), [
2926
- currentDateTime,
2927
- gridLabelIds,
2928
- weeksState.rootState
2929
- ]);
2930
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
2931
- value: monthViewStableShim,
2932
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
2933
- value: monthViewStateShim,
2934
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
2935
- value: orientationCtx,
2936
- children: el
2937
- })
2938
- })
2937
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
2938
+ value: orientationCtx,
2939
+ children: el
2939
2940
  });
2940
2941
  }
2941
2942
  const WeeksViewGrid = (0, react.forwardRef)(WeeksViewGridFn);
2942
2943
  const gridBodyStateAttributesMapping = { root: () => null };
2943
2944
  /** Table body wrapping the week rows. Renders a `<tbody>` by default. */
2944
2945
  function GridBodyFn(props, ref) {
2945
- if ((0, react.useContext)(WeeksViewStateContext)) {
2946
+ if ((0, react.useContext)(ViewContext)?.viewType === "weeks") {
2946
2947
  const { children, className, style } = props;
2947
2948
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksGrid, {
2948
2949
  className,
@@ -2958,7 +2959,7 @@ function GridBodyFn(props, ref) {
2958
2959
  const GridBody = (0, react.forwardRef)(GridBodyFn);
2959
2960
  function MonthGridBodyFn(props, ref) {
2960
2961
  const { render, ...otherProps } = props;
2961
- const { rootState } = useMonthViewState();
2962
+ const { rootState } = useViewState();
2962
2963
  const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
2963
2964
  const defaultProps = { children: props.children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) };
2964
2965
  const { children: _children, ...restOtherProps } = otherProps;
@@ -2980,7 +2981,7 @@ const weekInstanceStateAttributesMapping = {
2980
2981
  function WeekInstance(props) {
2981
2982
  const { render, ...otherProps } = props;
2982
2983
  const weekData = (0, react.useContext)(WeekDataContext);
2983
- const { rootState } = useMonthViewState();
2984
+ const { rootState } = useViewState();
2984
2985
  return (0, _base_ui_react_use_render.useRender)({
2985
2986
  defaultTagName: "tr",
2986
2987
  render,
@@ -3005,8 +3006,8 @@ function WeekInstance(props) {
3005
3006
  function WeekTemplate(props) {
3006
3007
  const outerWeekData = (0, react.useContext)(WeekDataContext);
3007
3008
  const gridMonthCtx = (0, react.useContext)(GridMonthContext);
3008
- const { weeks: defaultWeeks } = useMonthViewState();
3009
- const weeks = gridMonthCtx?.weeks ?? defaultWeeks;
3009
+ const monthState = (0, react.useContext)(MonthViewStateContext);
3010
+ const weeks = gridMonthCtx?.weeks ?? monthState?.weeks ?? [];
3010
3011
  const gridMonth = (0, react.useMemo)(() => gridMonthCtx ? {
3011
3012
  year: gridMonthCtx.year,
3012
3013
  month: gridMonthCtx.month
@@ -3049,7 +3050,7 @@ function DateStringFn(props, ref) {
3049
3050
  const { render, locales, options, ...otherProps } = props;
3050
3051
  const { locale, temporal: T, timeZone } = useCalendarStable();
3051
3052
  const { selected } = useCalendarState();
3052
- const { currentDateTime, rootState } = useMonthViewState();
3053
+ const { currentDateTime, rootState } = useViewState();
3053
3054
  const selectedZdt = selectedToZdt(selected, timeZone, T);
3054
3055
  const displayDate = selectedZdt ? zdtToNativeDate(selectedZdt) : new Date(currentDateTime.year, currentDateTime.month - 1, 1);
3055
3056
  const formatted = displayDate.toLocaleDateString(locales ?? locale, options);
@@ -3088,7 +3089,7 @@ function TimeStringFn(props, ref) {
3088
3089
  const { render, locales, options, ...otherProps } = props;
3089
3090
  const { locale, temporal: T, timeZone } = useCalendarStable();
3090
3091
  const { selected } = useCalendarState();
3091
- const { rootState } = useMonthViewState();
3092
+ const { rootState } = useViewState();
3092
3093
  const selZdt = selectedToZdt(selected, timeZone, T);
3093
3094
  const displayDate = selZdt ? zdtToNativeDate(selZdt) : zdtToNativeDate(T.Now.zonedDateTimeISO(timeZone));
3094
3095
  const mergedOptions = {
@@ -3354,9 +3355,8 @@ function RangeSelectedInnerFn(props, ref) {
3354
3355
  const { orientation } = (0, react.useContext)(GridContext);
3355
3356
  const { temporal: T } = useCalendarStable();
3356
3357
  const { rangeStart, rangeEnd } = useCalendarState();
3357
- const monthStable = (0, react.useContext)(MonthViewStableContext);
3358
- const { rootState } = useMonthViewState();
3359
- const outsideDays = monthStable?.outsideDays ?? "enabled";
3358
+ const { rootState } = useViewState();
3359
+ const { outsideDays } = useViewStable();
3360
3360
  const days = weekData?.days ?? [];
3361
3361
  const gridMonth = weekData?.gridMonth;
3362
3362
  const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gridMonth), [
@@ -3429,9 +3429,8 @@ function RangePreviewInnerFn(props, ref) {
3429
3429
  const { orientation } = (0, react.useContext)(GridContext);
3430
3430
  const { temporal: T } = useCalendarStable();
3431
3431
  const { previewStart, previewEnd } = useCalendarState();
3432
- const monthStable = (0, react.useContext)(MonthViewStableContext);
3433
- const { rootState } = useMonthViewState();
3434
- const outsideDays = monthStable?.outsideDays ?? "enabled";
3432
+ const { rootState } = useViewState();
3433
+ const { outsideDays } = useViewStable();
3435
3434
  const days = weekData?.days ?? [];
3436
3435
  const gridMonth = weekData?.gridMonth;
3437
3436
  const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, previewStart, previewEnd, T, outsideDays, gridMonth), [
@@ -3493,7 +3492,7 @@ const dragHandleStateAttributesMapping = {
3493
3492
  function useDragHandle(edge, { dragging: draggingProp }) {
3494
3493
  const { temporal: T, setHoveredDate, readOnly, disabled } = useCalendarStable();
3495
3494
  const { rangeStart, rangeEnd } = useCalendarState();
3496
- const { rootState } = useMonthViewState();
3495
+ const { rootState } = useViewState();
3497
3496
  const cellData = (0, react.useContext)(DayCellDataContext);
3498
3497
  const { orientation } = (0, react.useContext)(GridContext);
3499
3498
  const date = cellData?.date;
@@ -3576,7 +3575,7 @@ const weekNumberCellStateAttributesMapping = {
3576
3575
  function WeekNumberCellFn(props, ref) {
3577
3576
  const { render, ...otherProps } = props;
3578
3577
  const weekData = (0, react.useContext)(WeekDataContext);
3579
- const { rootState } = useMonthViewState();
3578
+ const { rootState } = useViewState();
3580
3579
  const { temporal: T } = useCalendarStable();
3581
3580
  const days = weekData?.days ?? [];
3582
3581
  const weekNumber = (0, react.useMemo)(() => {
@@ -3614,7 +3613,7 @@ const WeekNumberCell = (0, react.forwardRef)(WeekNumberCellFn);
3614
3613
  const weekNumberHeaderStateAttributesMapping = { root: () => null };
3615
3614
  function WeekNumberHeaderFn(props, ref) {
3616
3615
  const { render, ...otherProps } = props;
3617
- const { rootState } = useMonthViewState();
3616
+ const { rootState } = useViewState();
3618
3617
  const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
3619
3618
  return (0, _base_ui_react_use_render.useRender)({
3620
3619
  defaultTagName: "th",
@@ -3868,14 +3867,13 @@ function useWeeksViewRootState(props) {
3868
3867
  const calStable = useCalendarStable();
3869
3868
  const calState = useCalendarState();
3870
3869
  const T = calStable.temporal;
3871
- const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } = calStable;
3870
+ const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone, today } = calStable;
3872
3871
  const isControlled = firstWeekProp !== void 0;
3873
3872
  const resolveSpec = (0, react.useCallback)((spec) => resolveFirstWeekSpec(spec, weekStartDay, T), [weekStartDay, T]);
3874
3873
  const [internalFirstWeek, setInternalFirstWeek] = (0, react.useState)(() => {
3875
3874
  if (firstWeekProp !== void 0) return resolveSpec(firstWeekProp);
3876
3875
  if (defaultFirstWeekProp !== void 0) return resolveSpec(defaultFirstWeekProp);
3877
- if (calState.selected) return resolveSpec(toZonedDateTime(calState.selected, timeZone, T).toPlainDate());
3878
- return resolveSpec(T.Now.plainDateISO());
3876
+ return resolveSpec(resolveInitialAnchor(calState.selected, today, timeZone, T));
3879
3877
  });
3880
3878
  const resolvedFirstWeek = isControlled ? resolveSpec(firstWeekProp) : internalFirstWeek;
3881
3879
  const rawWeeks = (0, react.useMemo)(() => computeWeeksInWindow(resolvedFirstWeek, weekCount, weekStartDay, T), [
@@ -3930,10 +3928,10 @@ function useWeeksViewRootState(props) {
3930
3928
  const firstWeek = weeks[0];
3931
3929
  const lastWeek = weeks[weeks.length - 1];
3932
3930
  if (firstWeek === void 0 || lastWeek === void 0) {
3933
- const today = T.Now.plainDateISO();
3931
+ const now = today();
3934
3932
  return {
3935
- windowStart: today,
3936
- windowEnd: today,
3933
+ windowStart: now,
3934
+ windowEnd: now,
3937
3935
  weekCount: 0,
3938
3936
  dayCount: 0,
3939
3937
  enabledWeekCount: 0,
@@ -4211,6 +4209,14 @@ function useWeeksViewRootState(props) {
4211
4209
  tabTargetDate,
4212
4210
  gridHasFocus
4213
4211
  ]),
4212
+ viewStableCtx: (0, react.useMemo)(() => ({
4213
+ gridFocusedRef,
4214
+ outsideDays: "enabled"
4215
+ }), []),
4216
+ viewStateCtx: (0, react.useMemo)(() => ({
4217
+ currentDateTime,
4218
+ rootState
4219
+ }), [currentDateTime, rootState]),
4214
4220
  scrollToWeek
4215
4221
  };
4216
4222
  }
@@ -4218,42 +4224,16 @@ function useWeeksViewRootState(props) {
4218
4224
  //#region src/weeks-view.tsx
4219
4225
  function WeeksViewRootFn(props, ref) {
4220
4226
  const { children } = props;
4221
- const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
4227
+ const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
4222
4228
  (0, react.useImperativeHandle)(ref, () => ({ scrollToWeek }), [scrollToWeek]);
4223
- const gridFocusedRef = (0, react.useRef)(false);
4224
- const monthViewStableShim = (0, react.useMemo)(() => ({
4225
- numberOfMonths: 1,
4226
- fixedWeeks: false,
4227
- outsideDays: "enabled",
4228
- outOfRangeBehavior: "unbounded",
4229
- goNextMonth: () => {},
4230
- goPrevMonth: () => {},
4231
- setGridLabelId: () => {},
4232
- gridFocusedRef
4233
- }), []);
4234
- const monthViewStateShim = (0, react.useMemo)(() => ({
4235
- currentMonth: {
4236
- year: stateCtx.currentDateTime.year,
4237
- month: stateCtx.currentDateTime.month
4238
- },
4239
- weeks: [],
4240
- allMonths: [],
4241
- currentDateTime: stateCtx.currentDateTime,
4242
- gridLabelIds: stateCtx.gridLabelIds,
4243
- rootState: stateCtx.rootState
4244
- }), [
4245
- stateCtx.currentDateTime,
4246
- stateCtx.gridLabelIds,
4247
- stateCtx.rootState
4248
- ]);
4249
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
4250
- value: monthViewStableShim,
4251
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
4252
- value: monthViewStateShim,
4253
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
4254
- value: stableCtx,
4255
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
4256
- value: stateCtx,
4229
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
4230
+ value: stableCtx,
4231
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
4232
+ value: stateCtx,
4233
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
4234
+ value: viewStableCtx,
4235
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
4236
+ value: viewStateCtx,
4257
4237
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
4258
4238
  value: viewCtx,
4259
4239
  children
@@ -4298,7 +4278,7 @@ function useWeeksNavButton(direction, shiftByProp) {
4298
4278
  const { disabled: globalDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
4299
4279
  const { weekCount, outOfRangeBehavior, goNext, goPrev } = useWeeksViewStable();
4300
4280
  const { windowInfo } = useWeeksViewState();
4301
- const { rootState } = useMonthViewState();
4281
+ const { rootState } = useViewState();
4302
4282
  const currentFirstWeek = windowInfo.windowStart;
4303
4283
  const isDisabled = (0, react.useMemo)(() => {
4304
4284
  if (globalDisabled) return true;
@@ -4384,7 +4364,7 @@ const NextWeeksButton = (0, react.forwardRef)(NextWeeksButtonFn);
4384
4364
  function WeekCountFn(props, ref) {
4385
4365
  const { render, ...otherProps } = props;
4386
4366
  const { windowInfo } = useWeeksViewState();
4387
- const { rootState } = useMonthViewState();
4367
+ const { rootState } = useViewState();
4388
4368
  const count = windowInfo.weekCount;
4389
4369
  const state = (0, react.useMemo)(() => ({
4390
4370
  root: rootState,