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

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 (66) hide show
  1. package/dist/formats/date.cjs +2 -3
  2. package/dist/formats/date.d.cts +10 -14
  3. package/dist/formats/date.d.mts +10 -14
  4. package/dist/formats/date.mjs +2 -3
  5. package/dist/formats/object.cjs +2 -3
  6. package/dist/formats/object.d.cts +10 -14
  7. package/dist/formats/object.d.mts +10 -14
  8. package/dist/formats/object.mjs +2 -3
  9. package/dist/formats/plain-date-time.cjs +2 -3
  10. package/dist/formats/plain-date-time.d.cts +10 -14
  11. package/dist/formats/plain-date-time.d.mts +10 -14
  12. package/dist/formats/plain-date-time.mjs +2 -3
  13. package/dist/formats/plain-date.cjs +2 -3
  14. package/dist/formats/plain-date.d.cts +10 -14
  15. package/dist/formats/plain-date.d.mts +10 -14
  16. package/dist/formats/plain-date.mjs +2 -3
  17. package/dist/formats/plain-month-day.cjs +2 -3
  18. package/dist/formats/plain-month-day.d.cts +10 -14
  19. package/dist/formats/plain-month-day.d.mts +10 -14
  20. package/dist/formats/plain-month-day.mjs +2 -3
  21. package/dist/formats/plain-year-month.cjs +2 -3
  22. package/dist/formats/plain-year-month.d.cts +10 -14
  23. package/dist/formats/plain-year-month.d.mts +10 -14
  24. package/dist/formats/plain-year-month.mjs +2 -3
  25. package/dist/formats/zoned-date-time.cjs +2 -3
  26. package/dist/formats/zoned-date-time.d.cts +10 -14
  27. package/dist/formats/zoned-date-time.d.mts +10 -14
  28. package/dist/formats/zoned-date-time.mjs +2 -3
  29. package/dist/{index-DnFCKyyw.d.cts → index-BqzrxYgn.d.cts} +106 -116
  30. package/dist/{index-q3cQKJdA.d.mts → index-CkhYFmf4.d.mts} +106 -116
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +2 -2
  33. package/dist/index.d.mts +2 -2
  34. package/dist/index.mjs +1 -2
  35. package/dist/{weeks-navigation-Dn3UtG76.mjs → weeks-navigation-BWB5OvqW.mjs} +151 -188
  36. package/dist/{weeks-navigation-SuKJZJCM.cjs → weeks-navigation-CatYJIKb.cjs} +153 -191
  37. package/package.json +17 -18
  38. package/src/calendar-provider.test.tsx +1 -1
  39. package/src/compute-weeks-in-window.test.ts +1 -1
  40. package/src/day-cell-state.test.ts +1 -1
  41. package/src/day-cell.test.tsx +1 -1
  42. package/src/formats/formats.test.ts +1 -1
  43. package/src/grid.event-perf.test.tsx +7 -1
  44. package/src/grid.perf.test.tsx +7 -1
  45. package/src/grid.tsx +1 -1
  46. package/src/keyboard.test.ts +1 -1
  47. package/src/month-separator.test.tsx +1 -1
  48. package/src/month-view.bounds.test.tsx +1 -1
  49. package/src/month-view.test.tsx +89 -1
  50. package/src/month-view.tsx +14 -5
  51. package/src/month-window.test.ts +1 -1
  52. package/src/out-of-range.test.ts +34 -54
  53. package/src/out-of-range.ts +47 -123
  54. package/src/range-preview.test.ts +1 -1
  55. package/src/resolve-first-week.test.ts +1 -1
  56. package/src/today.test.tsx +8 -1
  57. package/src/utils.bench.ts +158 -106
  58. package/src/utils.test.ts +1 -1
  59. package/src/view-context.test.tsx +1 -1
  60. package/src/weeks-keyboard.test.ts +1 -1
  61. package/src/weeks-navigation.tsx +15 -6
  62. package/src/weeks-view-state.ts +21 -12
  63. package/src/weeks-view.bounds.test.tsx +246 -0
  64. package/src/weeks-view.test.tsx +1 -1
  65. package/src/weeks-window.test.ts +110 -22
  66. package/src/weeks-window.ts +57 -19
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -15,17 +15,16 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
- //#endregion
23
22
  let react = require("react");
24
23
  react = __toESM(react, 1);
25
24
  let react_jsx_runtime = require("react/jsx-runtime");
26
25
  let _base_ui_react_merge_props = require("@base-ui/react/merge-props");
27
26
  let _base_ui_react_use_render = require("@base-ui/react/use-render");
28
- //#region src/calendar-context.ts
27
+ // src/calendar-context.ts
29
28
  /** @internal React context carrying stable CalendarProvider values (callbacks, config). */
30
29
  const CalendarStableContext = (0, react.createContext)(null);
31
30
  /** @internal React context carrying volatile CalendarProvider state. */
@@ -42,8 +41,7 @@ function useCalendarState() {
42
41
  if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
43
42
  return ctx;
44
43
  }
45
- //#endregion
46
- //#region src/utils.ts
44
+ // src/utils.ts
47
45
  /**
48
46
  * Resolves a {@link TemporalNamespace} instance.
49
47
  *
@@ -489,8 +487,7 @@ function getISOWeekNumber(date, T) {
489
487
  const daysDiff = thursday.since(jan4Thursday, { largestUnit: "days" }).days;
490
488
  return Math.round(daysDiff / 7) + 1;
491
489
  }
492
- //#endregion
493
- //#region src/root-selection.ts
490
+ // src/root-selection.ts
494
491
  /** Construct a DateRange (workaround for TS generic conditional type widening). */
495
492
  function mkRange(start, end) {
496
493
  return {
@@ -855,8 +852,7 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
855
852
  });
856
853
  return preview ? mkRange(preview[0], preview[1]) : null;
857
854
  }
858
- //#endregion
859
- //#region src/calendar-provider.tsx
855
+ // src/calendar-provider.tsx
860
856
  /**
861
857
  * Provides shared calendar state (selection, config, range preview) to all
862
858
  * descendant view components. Does NOT manage focus, navigation, or grid data.
@@ -974,7 +970,7 @@ function CalendarProvider(props) {
974
970
  isRange,
975
971
  isMultiple
976
972
  ]);
977
- const [internalDates, setInternalDates] = (0, react.useState)((0, react.useMemo)(() => {
973
+ const defaultDates = (0, react.useMemo)(() => {
978
974
  if (isMultiple) {
979
975
  if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
980
976
  return [];
@@ -989,7 +985,8 @@ function CalendarProvider(props) {
989
985
  singleDefault,
990
986
  rawToPlain,
991
987
  sortDates
992
- ]));
988
+ ]);
989
+ const [internalDates, setInternalDates] = (0, react.useState)(defaultDates);
993
990
  const isControlled = controlledDates !== void 0;
994
991
  const committedDates = isControlled ? controlledDates : internalDates;
995
992
  const rangeStart = !isMultiple && committedDates.length > 0 ? committedDates[0] ?? void 0 : void 0;
@@ -1300,8 +1297,7 @@ function CalendarProvider(props) {
1300
1297
  })
1301
1298
  });
1302
1299
  }
1303
- //#endregion
1304
- //#region src/month-view-context.ts
1300
+ // src/month-view-context.ts
1305
1301
  /** @internal React context for MonthView stable values (config + callbacks). */
1306
1302
  const MonthViewStableContext = (0, react.createContext)(null);
1307
1303
  /** @internal React context for MonthView volatile state. */
@@ -1318,8 +1314,7 @@ function useMonthViewState() {
1318
1314
  if (!ctx) throw new Error("useMonthViewState must be used within MonthView.Root");
1319
1315
  return ctx;
1320
1316
  }
1321
- //#endregion
1322
- //#region src/month-view-navigation.ts
1317
+ // src/month-view-navigation.ts
1323
1318
  /**
1324
1319
  * Owns which month the view shows, in both controlled and uncontrolled mode:
1325
1320
  * the month state, the Prev/Next steps, and syncing the window with focus.
@@ -1438,8 +1433,7 @@ function useMonthNavigation(input) {
1438
1433
  goPrevMonth: (0, react.useCallback)(() => go("prev"), [go])
1439
1434
  };
1440
1435
  }
1441
- //#endregion
1442
- //#region src/month-window.ts
1436
+ // src/month-window.ts
1443
1437
  const monthIndex = (m) => m.year * 12 + (m.month - 1);
1444
1438
  /**
1445
1439
  * Builds the policy for a MonthView window of `numberOfMonths` months.
@@ -1489,8 +1483,7 @@ function monthAt(start, offset) {
1489
1483
  month: index % 12 + 1
1490
1484
  };
1491
1485
  }
1492
- //#endregion
1493
- //#region src/view-context.ts
1486
+ // src/view-context.ts
1494
1487
  /** @internal React context for the active view (MonthView or WeeksView). */
1495
1488
  const ViewContext = (0, react.createContext)(null);
1496
1489
  /** Returns the nearest view context (MonthView or WeeksView). */
@@ -1515,8 +1508,7 @@ function useViewState() {
1515
1508
  if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
1516
1509
  return ctx;
1517
1510
  }
1518
- //#endregion
1519
- //#region src/month-view.tsx
1511
+ // src/month-view.tsx
1520
1512
  function MonthViewRoot(props) {
1521
1513
  const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
1522
1514
  const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
@@ -1527,7 +1519,6 @@ function MonthViewRoot(props) {
1527
1519
  const calState = useCalendarState();
1528
1520
  const T = calStable.temporal;
1529
1521
  const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
1530
- const [focusedDate, setFocusedDate] = (0, react.useState)(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
1531
1522
  const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
1532
1523
  const gridFocusedRef = (0, react.useRef)(false);
1533
1524
  const { minValue, maxValue } = calStable;
@@ -1544,6 +1535,16 @@ function MonthViewRoot(props) {
1544
1535
  maxValue,
1545
1536
  T
1546
1537
  ]);
1538
+ const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
1539
+ const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
1540
+ const opening = monthProp ?? defaultMonthProp;
1541
+ if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
1542
+ return T.PlainDate.from({
1543
+ year: opening.year,
1544
+ month: opening.month,
1545
+ day: 1
1546
+ });
1547
+ });
1547
1548
  const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
1548
1549
  month: monthProp,
1549
1550
  defaultMonth: defaultMonthProp,
@@ -1732,8 +1733,7 @@ function MonthView(props) {
1732
1733
  });
1733
1734
  }
1734
1735
  MonthView.Root = MonthViewRoot;
1735
- //#endregion
1736
- //#region src/context.ts
1736
+ // src/context.ts
1737
1737
  /** @internal Provides the days and index of the current week row to child components. */
1738
1738
  const WeekDataContext = (0, react.createContext)(null);
1739
1739
  /** @internal Provides the resolved grid orientation to descendant cells. */
@@ -1742,8 +1742,7 @@ const GridContext = (0, react.createContext)({ orientation: "horizontal" });
1742
1742
  const DayCellDataContext = (0, react.createContext)(null);
1743
1743
  /** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
1744
1744
  const GridMonthContext = (0, react.createContext)(null);
1745
- //#endregion
1746
- //#region src/grid-header.tsx
1745
+ // src/grid-header.tsx
1747
1746
  function useGridHeaderCellState(index) {
1748
1747
  const { locale, temporal: T, weekStartDay } = useCalendarStable();
1749
1748
  const { rootState } = useViewState();
@@ -1835,8 +1834,7 @@ function GridHeaderFn(props, ref) {
1835
1834
  }
1836
1835
  /** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
1837
1836
  const GridHeader = (0, react.forwardRef)(GridHeaderFn);
1838
- //#endregion
1839
- //#region src/keyboard.ts
1837
+ // src/keyboard.ts
1840
1838
  /**
1841
1839
  * Computes the target date when jumping by `months` from `focusedDate`.
1842
1840
  *
@@ -1909,8 +1907,7 @@ function computeNextFocusDate(input) {
1909
1907
  if (nextDate) return clampToBounds(nextDate, focusedDate, minValue, maxValue, T);
1910
1908
  return { action: "none" };
1911
1909
  }
1912
- //#endregion
1913
- //#region src/month-separator.tsx
1910
+ // src/month-separator.tsx
1914
1911
  /** Context providing MonthSeparator data to child components. */
1915
1912
  const MonthSeparatorDataContext = (0, react.createContext)(null);
1916
1913
  function useMonthSeparatorData() {
@@ -2040,8 +2037,7 @@ function MonthSeparatorFn(props, ref) {
2040
2037
  * Default children: `<Month /> <Year />`.
2041
2038
  */
2042
2039
  const MonthSeparator = (0, react.forwardRef)(MonthSeparatorFn);
2043
- //#endregion
2044
- //#region src/weeks-view-context.ts
2040
+ // src/weeks-view-context.ts
2045
2041
  /** @internal React context for WeeksView stable values (config + callbacks). */
2046
2042
  const WeeksViewStableContext = (0, react.createContext)(null);
2047
2043
  /** @internal React context for WeeksView volatile state. */
@@ -2058,8 +2054,7 @@ function useWeeksViewState() {
2058
2054
  if (!ctx) throw new Error("useWeeksViewState must be used within WeeksView.Root");
2059
2055
  return ctx;
2060
2056
  }
2061
- //#endregion
2062
- //#region src/weeks-grid.tsx
2057
+ // src/weeks-grid.tsx
2063
2058
  /**
2064
2059
  * @internal WeeksGrid — renders continuous week rows for WeeksView.
2065
2060
  * Not exported from the public API.
@@ -2225,8 +2220,7 @@ function WeeksGrid(props) {
2225
2220
  children: rows
2226
2221
  });
2227
2222
  }
2228
- //#endregion
2229
- //#region src/weeks-keyboard.ts
2223
+ // src/weeks-keyboard.ts
2230
2224
  const NONE = {
2231
2225
  action: "none",
2232
2226
  windowShift: 0,
@@ -2300,8 +2294,7 @@ function computeWeeksKeyNav(input) {
2300
2294
  default: return NONE;
2301
2295
  }
2302
2296
  }
2303
- //#endregion
2304
- //#region src/day-cell-state.ts
2297
+ // src/day-cell-state.ts
2305
2298
  const NO_RANGE = {
2306
2299
  rangeStart: false,
2307
2300
  rangeEnd: false,
@@ -2473,8 +2466,7 @@ function useDayCellDeriver() {
2473
2466
  }, inputs);
2474
2467
  };
2475
2468
  }
2476
- //#endregion
2477
- //#region src/day-cell.tsx
2469
+ // src/day-cell.tsx
2478
2470
  const dayStateAttributesMapping = {
2479
2471
  root: () => null,
2480
2472
  date: (v) => v ? { "data-date": v.toString() } : null,
@@ -2506,22 +2498,23 @@ const dayStateAttributesMapping = {
2506
2498
  function DayCellInstanceFn(props) {
2507
2499
  const { render, date, columnIndex, children, _derivedState, ...otherProps } = props;
2508
2500
  const state = _derivedState;
2501
+ const defaultProps = state.hidden ? {
2502
+ role: "gridcell",
2503
+ "aria-hidden": true,
2504
+ children: null
2505
+ } : {
2506
+ role: "gridcell",
2507
+ "aria-selected": state.selected || void 0,
2508
+ "aria-disabled": state.disabled || void 0,
2509
+ children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, { _derivedState })
2510
+ };
2509
2511
  const cell = (0, _base_ui_react_use_render.useRender)({
2510
2512
  defaultTagName: "td",
2511
2513
  render,
2512
2514
  ref: [],
2513
2515
  state,
2514
2516
  stateAttributesMapping: dayStateAttributesMapping,
2515
- props: (0, _base_ui_react_merge_props.mergeProps)(state.hidden ? {
2516
- role: "gridcell",
2517
- "aria-hidden": true,
2518
- children: null
2519
- } : {
2520
- role: "gridcell",
2521
- "aria-selected": state.selected || void 0,
2522
- "aria-disabled": state.disabled || void 0,
2523
- children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, { _derivedState })
2524
- }, otherProps)
2517
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
2525
2518
  });
2526
2519
  const outsideDisabled = state.hidden || state.outsideMonth && state.disabled;
2527
2520
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellDataContext.Provider, {
@@ -2546,14 +2539,14 @@ function passThroughPropsEqual(prev, next, handledKeys) {
2546
2539
  for (const key of prevKeys) if (prev[key] !== next[key]) return false;
2547
2540
  return true;
2548
2541
  }
2549
- const DAY_CELL_HANDLED_KEYS = new Set([
2542
+ const DAY_CELL_HANDLED_KEYS = /* @__PURE__ */ new Set([
2550
2543
  "render",
2551
2544
  "date",
2552
2545
  "columnIndex",
2553
2546
  "children",
2554
2547
  "_derivedState"
2555
2548
  ]);
2556
- const DAY_BUTTON_HANDLED_KEYS = new Set([
2549
+ const DAY_BUTTON_HANDLED_KEYS = /* @__PURE__ */ new Set([
2557
2550
  "render",
2558
2551
  "date",
2559
2552
  "children",
@@ -2682,8 +2675,7 @@ function DayButtonFallbackFn(props, ref) {
2682
2675
  });
2683
2676
  }
2684
2677
  const DayButtonFallback = (0, react.forwardRef)(DayButtonFallbackFn);
2685
- //#endregion
2686
- //#region src/grid.tsx
2678
+ // src/grid.tsx
2687
2679
  function useGridKeyboard() {
2688
2680
  const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
2689
2681
  const { focusedDate, setFocusedDate } = useViewContext();
@@ -2731,7 +2723,7 @@ function useWeeksGridKeyboard() {
2731
2723
  shiftKey: e.shiftKey,
2732
2724
  focusedDate,
2733
2725
  windowStart: weeksState.windowInfo.windowStart,
2734
- weekCount: weeksStable.weekCount,
2726
+ weekCount: weeksState.windowInfo.weekCount,
2735
2727
  minValue,
2736
2728
  maxValue,
2737
2729
  disabled,
@@ -3017,19 +3009,20 @@ function WeekInstance(props) {
3017
3009
  const { render, ...otherProps } = props;
3018
3010
  const weekData = (0, react.useContext)(WeekDataContext);
3019
3011
  const { rootState } = useViewState();
3012
+ const state = (0, react.useMemo)(() => ({
3013
+ root: rootState,
3014
+ weekIndex: weekData.weekIndex,
3015
+ gridRowIndex: weekData.gridRowIndex
3016
+ }), [
3017
+ rootState,
3018
+ weekData.weekIndex,
3019
+ weekData.gridRowIndex
3020
+ ]);
3020
3021
  return (0, _base_ui_react_use_render.useRender)({
3021
3022
  defaultTagName: "tr",
3022
3023
  render,
3023
3024
  ref: [],
3024
- state: (0, react.useMemo)(() => ({
3025
- root: rootState,
3026
- weekIndex: weekData.weekIndex,
3027
- gridRowIndex: weekData.gridRowIndex
3028
- }), [
3029
- rootState,
3030
- weekData.weekIndex,
3031
- weekData.gridRowIndex
3032
- ]),
3025
+ state,
3033
3026
  stateAttributesMapping: weekInstanceStateAttributesMapping,
3034
3027
  props: (0, _base_ui_react_merge_props.mergeProps)({}, otherProps)
3035
3028
  });
@@ -3062,8 +3055,7 @@ function WeekTemplate(props) {
3062
3055
  }, firstDay.toString());
3063
3056
  }) });
3064
3057
  }
3065
- //#endregion
3066
- //#region src/navigation.tsx
3058
+ // src/navigation.tsx
3067
3059
  const dateStringStateAttributesMapping = {
3068
3060
  root: () => null,
3069
3061
  month: () => null,
@@ -3299,8 +3291,7 @@ function NextMonthButtonFn(props, ref) {
3299
3291
  * when the next month falls after `max`. Exposes `data-direction="next"`.
3300
3292
  */
3301
3293
  const NextMonthButton = (0, react.forwardRef)(NextMonthButtonFn);
3302
- //#endregion
3303
- //#region src/selected-range.tsx
3294
+ // src/selected-range.tsx
3304
3295
  const rangeOverlayStateAttributesMapping = {
3305
3296
  root: () => null,
3306
3297
  active: (v) => v ? { "data-active": "" } : null,
@@ -3420,8 +3411,7 @@ function RangeSelectedInnerFn(props, ref) {
3420
3411
  });
3421
3412
  }
3422
3413
  const RangeSelectedInner = (0, react.forwardRef)(RangeSelectedInnerFn);
3423
- //#endregion
3424
- //#region src/range-preview.tsx
3414
+ // src/range-preview.tsx
3425
3415
  function RangePreviewFn(props, ref) {
3426
3416
  const { selectionMode } = useCalendarStable();
3427
3417
  if (selectionMode !== "range") return null;
@@ -3494,8 +3484,7 @@ function RangePreviewInnerFn(props, ref) {
3494
3484
  });
3495
3485
  }
3496
3486
  const RangePreviewInner = (0, react.forwardRef)(RangePreviewInnerFn);
3497
- //#endregion
3498
- //#region src/drag-handle.tsx
3487
+ // src/drag-handle.tsx
3499
3488
  const dragHandleStateAttributesMapping = {
3500
3489
  root: () => null,
3501
3490
  active: (v) => v ? { "data-active": "" } : null,
@@ -3514,32 +3503,34 @@ function useDragHandle(edge, { dragging: draggingProp }) {
3514
3503
  const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
3515
3504
  const isDragging = !!draggingProp && isActive;
3516
3505
  const handleRef = (0, react.useRef)(null);
3506
+ const state = (0, react.useMemo)(() => ({
3507
+ root: rootState,
3508
+ active: isActive,
3509
+ dragging: isDragging,
3510
+ edge,
3511
+ orientation
3512
+ }), [
3513
+ rootState,
3514
+ isActive,
3515
+ isDragging,
3516
+ edge,
3517
+ orientation
3518
+ ]);
3519
+ const defaultProps = {
3520
+ role: "slider",
3521
+ "aria-roledescription": "drag handle",
3522
+ "aria-label": edge === "start" ? "Range start date" : "Range end date",
3523
+ "aria-valuetext": date?.toString(),
3524
+ "aria-grabbed": isActive ? isDragging : void 0,
3525
+ "aria-hidden": isActive ? void 0 : true,
3526
+ onPointerEnter: () => {
3527
+ if (date && !outsideDisabled) setHoveredDate(date);
3528
+ }
3529
+ };
3517
3530
  return {
3518
- state: (0, react.useMemo)(() => ({
3519
- root: rootState,
3520
- active: isActive,
3521
- dragging: isDragging,
3522
- edge,
3523
- orientation
3524
- }), [
3525
- rootState,
3526
- isActive,
3527
- isDragging,
3528
- edge,
3529
- orientation
3530
- ]),
3531
+ state,
3531
3532
  stateAttributesMapping: dragHandleStateAttributesMapping,
3532
- defaultProps: {
3533
- role: "slider",
3534
- "aria-roledescription": "drag handle",
3535
- "aria-label": edge === "start" ? "Range start date" : "Range end date",
3536
- "aria-valuetext": date?.toString(),
3537
- "aria-grabbed": isActive ? isDragging : void 0,
3538
- "aria-hidden": isActive ? void 0 : true,
3539
- onPointerEnter: () => {
3540
- if (date && !outsideDisabled) setHoveredDate(date);
3541
- }
3542
- },
3533
+ defaultProps,
3543
3534
  handleRef
3544
3535
  };
3545
3536
  }
@@ -3580,8 +3571,7 @@ function RangeEndDragHandleFn(props, ref) {
3580
3571
  }
3581
3572
  /** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
3582
3573
  const RangeEndDragHandle = (0, react.forwardRef)(RangeEndDragHandleFn);
3583
- //#endregion
3584
- //#region src/week-number.tsx
3574
+ // src/week-number.tsx
3585
3575
  const weekNumberCellStateAttributesMapping = {
3586
3576
  root: () => null,
3587
3577
  weekNumber: (v) => ({ "data-week-number": String(v) })
@@ -3646,8 +3636,7 @@ function WeekNumberHeaderFn(props, ref) {
3646
3636
  * Column header for the week number column. Renders a `<th scope="col">`.
3647
3637
  */
3648
3638
  const WeekNumberHeader = (0, react.forwardRef)(WeekNumberHeaderFn);
3649
- //#endregion
3650
- //#region src/compute-weeks-in-window.ts
3639
+ // src/compute-weeks-in-window.ts
3651
3640
  /**
3652
3641
  * Computes an array of week descriptors for a continuous window.
3653
3642
  * `firstWeek` is snapped back to the nearest `weekStartDay`.
@@ -3669,8 +3658,7 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
3669
3658
  }
3670
3659
  return weeks;
3671
3660
  }
3672
- //#endregion
3673
- //#region src/resolve-first-week.ts
3661
+ // src/resolve-first-week.ts
3674
3662
  /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3675
3663
  function snapToWeekStart(date, weekStartDay) {
3676
3664
  const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
@@ -3761,29 +3749,25 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3761
3749
  }
3762
3750
  }
3763
3751
  }
3764
- //#endregion
3765
- //#region src/out-of-range.ts
3752
+ // src/out-of-range.ts
3766
3753
  /** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
3767
3754
  function weekHasValidDay(weekStart, min, max, T) {
3768
3755
  const weekEnd = weekStart.add({ days: 6 });
3769
- return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
3756
+ return (!max || T.PlainDate.compare(weekStart, max) <= 0) && (!min || T.PlainDate.compare(weekEnd, min) >= 0);
3757
+ }
3758
+ /** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
3759
+ function windowHasValidWeek(firstWeek, weekCount, min, max, T) {
3760
+ for (let i = 0; i < weekCount; i++) if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
3761
+ return false;
3770
3762
  }
3771
3763
  /**
3772
3764
  * Returns the start of the week (per weekStartDay) that contains the given date.
3773
3765
  * Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
3774
3766
  */
3775
- function weekStartContaining(date, weekStartDay, _T) {
3767
+ function weekStartContaining(date, weekStartDay) {
3776
3768
  const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3777
3769
  return date.subtract({ days: daysFromStart });
3778
3770
  }
3779
- /** Find the week start (per weekStartDay) whose 7-day span contains min. */
3780
- function findFirstValidWeekStart(min, weekStartDay, T) {
3781
- return weekStartContaining(min, weekStartDay, T);
3782
- }
3783
- /** Find the week start (per weekStartDay) whose 7-day span contains max. */
3784
- function findLastValidWeekStart(max, weekStartDay, T) {
3785
- return weekStartContaining(max, weekStartDay, T);
3786
- }
3787
3771
  /**
3788
3772
  * Trim leading and trailing fully-disabled weeks from a window.
3789
3773
  * Returns new { firstWeek, weekCount }.
@@ -3813,7 +3797,7 @@ function shrinkWindow(firstWeek, weekCount, min, max, T) {
3813
3797
  * the adjusted { firstWeek, weekCount }.
3814
3798
  */
3815
3799
  function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
3816
- if (!min || !max || behavior === "unbounded") return {
3800
+ if (!min && !max || behavior === "unbounded") return {
3817
3801
  firstWeek: targetFirstWeek,
3818
3802
  weekCount
3819
3803
  };
@@ -3822,54 +3806,19 @@ function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekS
3822
3806
  weekCount
3823
3807
  };
3824
3808
  if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
3825
- if (behavior === "snap" || behavior === "snap-shrink") {
3826
- const lastValid = findLastValidWeekStart(max, weekStartDay, T);
3827
- const snappedFirst = lastValid.subtract({ days: (weekCount - 1) * 7 });
3828
- const targetLastWeek = targetFirstWeek.add({ days: (weekCount - 1) * 7 });
3829
- let resolvedFirst;
3830
- if (T.PlainDate.compare(targetLastWeek, lastValid) <= 0) {
3831
- const firstValid = findFirstValidWeekStart(min, weekStartDay, T);
3832
- if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
3833
- else resolvedFirst = firstValid;
3834
- } else resolvedFirst = snappedFirst;
3835
- if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
3836
- return {
3837
- firstWeek: resolvedFirst,
3838
- weekCount
3839
- };
3840
- }
3809
+ const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
3810
+ const lastValid = max && weekStartContaining(max, weekStartDay);
3811
+ const firstValid = min && weekStartContaining(min, weekStartDay);
3812
+ let resolvedFirst = targetFirstWeek;
3813
+ if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
3814
+ else if (firstValid && T.PlainDate.compare(targetFirstWeek, firstValid) < 0) resolvedFirst = firstValid;
3815
+ if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
3841
3816
  return {
3842
- firstWeek: targetFirstWeek,
3817
+ firstWeek: resolvedFirst,
3843
3818
  weekCount
3844
3819
  };
3845
3820
  }
3846
- /**
3847
- * Returns whether the navigation button for the given direction should be enabled.
3848
- */
3849
- function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
3850
- if (behavior === "unbounded" || !min || !max) return true;
3851
- const shift = shiftBy ?? weekCount;
3852
- const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
3853
- if (behavior === "stop" || behavior === "stop-shrink") {
3854
- for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
3855
- return false;
3856
- }
3857
- if (behavior === "snap" || behavior === "snap-shrink") {
3858
- const applied = applyOutOfRange({
3859
- targetFirstWeek,
3860
- weekCount,
3861
- behavior,
3862
- min,
3863
- max,
3864
- weekStartDay,
3865
- T
3866
- });
3867
- return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
3868
- }
3869
- return true;
3870
- }
3871
- //#endregion
3872
- //#region src/weeks-window.ts
3821
+ // src/weeks-window.ts
3873
3822
  function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
3874
3823
  const bounds = {
3875
3824
  weekCount,
@@ -3879,21 +3828,30 @@ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T
3879
3828
  weekStartDay,
3880
3829
  T
3881
3830
  };
3831
+ const isStop = behavior === "stop" || behavior === "stop-shrink";
3832
+ const isBounded = min !== void 0 || max !== void 0;
3833
+ const resolve = (requestedFirstWeek) => applyOutOfRange({
3834
+ ...bounds,
3835
+ targetFirstWeek: requestedFirstWeek
3836
+ });
3837
+ const moveTo = (requestedFirstWeek) => {
3838
+ if (isStop && isBounded && !windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)) return null;
3839
+ return resolve(requestedFirstWeek);
3840
+ };
3882
3841
  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
- })
3842
+ resolve,
3843
+ moveTo,
3844
+ shift: (current, direction, shiftBy) => {
3845
+ const by = shiftBy ?? current.weekCount;
3846
+ const target = current.firstWeek.add({ weeks: direction * by });
3847
+ const next = moveTo(target);
3848
+ if (next === null) return null;
3849
+ if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
3850
+ return next;
3851
+ }
3893
3852
  };
3894
3853
  }
3895
- //#endregion
3896
- //#region src/weeks-view-state.ts
3854
+ // src/weeks-view-state.ts
3897
3855
  /**
3898
3856
  * Core state management hook for WeeksView.Root.
3899
3857
  * Reads calendar-level context and manages weeks-specific state.
@@ -4113,29 +4071,32 @@ function useWeeksViewRootState(props) {
4113
4071
  if (!isControlled) setInternalFirstWeek(newFirstWeek);
4114
4072
  onFirstWeekChange?.(newFirstWeek);
4115
4073
  }, [isControlled, onFirstWeekChange]);
4074
+ const shownWindow = (0, react.useMemo)(() => ({
4075
+ firstWeek: windowInfo.windowStart,
4076
+ weekCount: windowInfo.weekCount
4077
+ }), [windowInfo.windowStart, windowInfo.weekCount]);
4116
4078
  const goNext = (0, react.useCallback)((shiftBy) => {
4117
- const target = resolvedFirstWeek.add({ weeks: shiftBy ?? weekCount });
4118
- updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4079
+ const next = windowPolicy.shift(shownWindow, 1, shiftBy);
4080
+ if (next) updateFirstWeek(next.firstWeek);
4119
4081
  }, [
4120
- resolvedFirstWeek,
4121
- weekCount,
4082
+ shownWindow,
4122
4083
  windowPolicy,
4123
4084
  updateFirstWeek
4124
4085
  ]);
4125
4086
  const goPrev = (0, react.useCallback)((shiftBy) => {
4126
- const target = resolvedFirstWeek.subtract({ weeks: shiftBy ?? weekCount });
4127
- updateFirstWeek(windowPolicy.resolve(target).firstWeek);
4087
+ const next = windowPolicy.shift(shownWindow, -1, shiftBy);
4088
+ if (next) updateFirstWeek(next.firstWeek);
4128
4089
  }, [
4129
- resolvedFirstWeek,
4130
- weekCount,
4090
+ shownWindow,
4131
4091
  windowPolicy,
4132
4092
  updateFirstWeek
4133
4093
  ]);
4134
4094
  const scrollToWeek = (0, react.useCallback)((target, options) => {
4135
- const newFirstWeek = resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options);
4136
- updateFirstWeek(windowPolicy.resolve(newFirstWeek).firstWeek);
4095
+ const requested = resolveFirstWeek(shownWindow.firstWeek, weekCount, resolveSpec(target), options);
4096
+ const next = windowPolicy.moveTo(requested);
4097
+ if (next) updateFirstWeek(next.firstWeek);
4137
4098
  }, [
4138
- resolvedFirstWeek,
4099
+ shownWindow,
4139
4100
  weekCount,
4140
4101
  resolveSpec,
4141
4102
  windowPolicy,
@@ -4224,8 +4185,7 @@ function useWeeksViewRootState(props) {
4224
4185
  scrollToWeek
4225
4186
  };
4226
4187
  }
4227
- //#endregion
4228
- //#region src/weeks-view.tsx
4188
+ // src/weeks-view.tsx
4229
4189
  function WeeksViewRootFn(props, ref) {
4230
4190
  const { children } = props;
4231
4191
  const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
@@ -4267,8 +4227,7 @@ function WeeksViewFn(props, ref) {
4267
4227
  }
4268
4228
  const WeeksView = (0, react.forwardRef)(WeeksViewFn);
4269
4229
  WeeksView.Root = WeeksViewRoot;
4270
- //#endregion
4271
- //#region src/weeks-navigation.tsx
4230
+ // src/weeks-navigation.tsx
4272
4231
  const weeksNavButtonStateAttributesMapping = {
4273
4232
  root: () => null,
4274
4233
  direction: (v) => ({ "data-direction": v }),
@@ -4283,14 +4242,18 @@ function useWeeksNavButton(direction, shiftByProp) {
4283
4242
  const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
4284
4243
  const { windowInfo } = useWeeksViewState();
4285
4244
  const { rootState } = useViewState();
4286
- const currentFirstWeek = windowInfo.windowStart;
4245
+ const { windowStart, weekCount } = windowInfo;
4287
4246
  const isDisabled = (0, react.useMemo)(() => {
4288
4247
  if (globalDisabled) return true;
4289
- return !windowPolicy.canShift(currentFirstWeek, direction === "next" ? 1 : -1, shiftByProp);
4248
+ return windowPolicy.shift({
4249
+ firstWeek: windowStart,
4250
+ weekCount
4251
+ }, direction === "next" ? 1 : -1, shiftByProp) === null;
4290
4252
  }, [
4291
4253
  globalDisabled,
4292
4254
  windowPolicy,
4293
- currentFirstWeek,
4255
+ windowStart,
4256
+ weekCount,
4294
4257
  direction,
4295
4258
  shiftByProp
4296
4259
  ]);
@@ -4373,7 +4336,6 @@ function WeekCountFn(props, ref) {
4373
4336
  * out-of-range modes where the actual count may be less than the `weekCount` prop.
4374
4337
  */
4375
4338
  const WeekCount = (0, react.forwardRef)(WeekCountFn);
4376
- //#endregion
4377
4339
  Object.defineProperty(exports, "CalendarProvider", {
4378
4340
  enumerable: true,
4379
4341
  get: function() {