@klinking/colander 3.0.1-alpha.1 → 3.1.0-alpha.10

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 (98) 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/{weeks-view-context-CNAq2Hiu.d.cts → index-K1_zOIpa.d.mts} +198 -114
  30. package/dist/{weeks-view-context-CsP3PBiu.d.mts → index-bRoYX03d.d.cts} +198 -114
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +2 -11
  33. package/dist/index.d.mts +2 -11
  34. package/dist/index.mjs +1 -2
  35. package/dist/{weeks-navigation-CJzhxbgj.cjs → weeks-navigation-3UTRiTUP.cjs} +1102 -952
  36. package/dist/{weeks-navigation-Bg0nZLgh.mjs → weeks-navigation-BoHqK5fq.mjs} +1102 -951
  37. package/package.json +21 -18
  38. package/src/calendar-provider.test.tsx +88 -1
  39. package/src/calendar-provider.tsx +89 -73
  40. package/src/calendar-types.ts +2 -0
  41. package/src/compute-weeks-in-window.test.ts +1 -1
  42. package/src/day-cell-state.test.ts +214 -0
  43. package/src/day-cell-state.ts +244 -0
  44. package/src/day-cell-store.test.tsx +273 -0
  45. package/src/day-cell-store.tsx +204 -0
  46. package/src/day-cell.test.tsx +73 -90
  47. package/src/day-cell.tsx +106 -444
  48. package/src/drag-handle.tsx +2 -2
  49. package/src/formats/date.ts +2 -0
  50. package/src/formats/formats.test.ts +1 -1
  51. package/src/formats/object.ts +2 -0
  52. package/src/formats/plain-date-time.ts +2 -0
  53. package/src/formats/plain-date.ts +2 -0
  54. package/src/formats/plain-month-day.ts +2 -0
  55. package/src/formats/plain-year-month.ts +2 -0
  56. package/src/formats/zoned-date-time.ts +2 -0
  57. package/src/grid-header.tsx +3 -3
  58. package/src/grid.event-perf.test.tsx +7 -1
  59. package/src/grid.perf.test.tsx +7 -1
  60. package/src/grid.tsx +38 -77
  61. package/src/index.ts +2 -0
  62. package/src/keyboard.test.ts +1 -1
  63. package/src/month-separator.test.tsx +1 -1
  64. package/src/month-view-navigation.ts +180 -0
  65. package/src/month-view-types.ts +3 -0
  66. package/src/month-view.bounds.test.tsx +136 -0
  67. package/src/month-view.test.tsx +89 -1
  68. package/src/month-view.tsx +74 -217
  69. package/src/month-window.test.ts +207 -0
  70. package/src/month-window.ts +93 -0
  71. package/src/navigation.tsx +18 -76
  72. package/src/out-of-range.test.ts +34 -54
  73. package/src/out-of-range.ts +47 -123
  74. package/src/range-preview.test.ts +120 -0
  75. package/src/range-preview.tsx +3 -5
  76. package/src/resolve-first-week.test.ts +1 -1
  77. package/src/root-selection.ts +99 -97
  78. package/src/selected-range.tsx +3 -5
  79. package/src/store.ts +72 -0
  80. package/src/today.test.tsx +105 -0
  81. package/src/types.ts +24 -1
  82. package/src/utils.bench.ts +158 -106
  83. package/src/utils.test.ts +26 -1
  84. package/src/utils.ts +40 -9
  85. package/src/view-context.test.tsx +126 -0
  86. package/src/view-context.ts +45 -0
  87. package/src/week-number.test.tsx +76 -0
  88. package/src/week-number.tsx +48 -19
  89. package/src/weeks-grid.tsx +20 -10
  90. package/src/weeks-keyboard.test.ts +1 -1
  91. package/src/weeks-navigation.tsx +15 -31
  92. package/src/weeks-view-state.ts +67 -101
  93. package/src/weeks-view-types.ts +4 -1
  94. package/src/weeks-view.bounds.test.tsx +246 -0
  95. package/src/weeks-view.test.tsx +116 -14
  96. package/src/weeks-view.tsx +24 -52
  97. package/src/weeks-window.test.ts +131 -0
  98. package/src/weeks-window.ts +102 -0
@@ -0,0 +1,126 @@
1
+ // @vitest-environment jsdom
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { act, fireEvent, render, screen } from "@testing-library/react";
4
+ import type { ReactNode } from "react";
5
+ import { describe, expect, it } from "vite-plus/test";
6
+ import {
7
+ DayButton,
8
+ DayCellTemplate,
9
+ Grid,
10
+ GridBody,
11
+ WeekTemplate,
12
+ } from "./grid";
13
+ import { MonthView } from "./month-view";
14
+ import { useViewStable, useViewState } from "./view-context";
15
+ import { WeeksView } from "./weeks-view";
16
+
17
+ const T = Temporal;
18
+
19
+ const counts = { stable: 0, state: 0 };
20
+
21
+ function StableProbe() {
22
+ useViewStable();
23
+ counts.stable++;
24
+ return null;
25
+ }
26
+
27
+ function StateProbe() {
28
+ useViewState();
29
+ counts.state++;
30
+ return null;
31
+ }
32
+
33
+ const grid = (
34
+ <Grid>
35
+ <GridBody>
36
+ <WeekTemplate>
37
+ <DayCellTemplate>
38
+ <DayButton />
39
+ </DayCellTemplate>
40
+ </WeekTemplate>
41
+ </GridBody>
42
+ </Grid>
43
+ );
44
+
45
+ const views: {
46
+ description: string;
47
+ view: (children: ReactNode) => ReactNode;
48
+ }[] = [
49
+ {
50
+ description: "MonthView",
51
+ view: (children) => (
52
+ <MonthView
53
+ temporal={T}
54
+ defaultValue={T.PlainDate.from("2026-03-15")}
55
+ defaultMonth={T.PlainYearMonth.from("2026-03")}
56
+ >
57
+ {children}
58
+ </MonthView>
59
+ ),
60
+ },
61
+ {
62
+ description: "WeeksView",
63
+ view: (children) => (
64
+ <WeeksView
65
+ temporal={T}
66
+ weekCount={4}
67
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
68
+ defaultValue={T.PlainDate.from("2026-03-15")}
69
+ >
70
+ {children}
71
+ </WeeksView>
72
+ ),
73
+ },
74
+ ];
75
+
76
+ describe.each(views)("$description stable/state view contexts", ({ view }) => {
77
+ function setup() {
78
+ render(
79
+ view(
80
+ <>
81
+ <StableProbe />
82
+ <StateProbe />
83
+ {grid}
84
+ </>,
85
+ ),
86
+ );
87
+ const day = (n: number) =>
88
+ screen.getAllByRole("button").find((b) => b.textContent === String(n))!;
89
+ const reset = () => {
90
+ counts.stable = 0;
91
+ counts.state = 0;
92
+ };
93
+ return { day, reset };
94
+ }
95
+
96
+ it.each([
97
+ {
98
+ description: "grid focus does not re-render either context's consumers",
99
+ act: (day: (n: number) => HTMLElement) => day(15).focus(),
100
+ expected: { stable: 0, state: 0 },
101
+ },
102
+ {
103
+ description: "hovering a day does not re-render either",
104
+ act: (day: (n: number) => HTMLElement) => {
105
+ fireEvent.pointerEnter(day(20));
106
+ fireEvent.mouseOver(day(20));
107
+ },
108
+ expected: { stable: 0, state: 0 },
109
+ },
110
+ {
111
+ description: "moving focus re-renders state consumers only",
112
+ act: (day: (n: number) => HTMLElement) => {
113
+ fireEvent.keyDown(day(15), { key: "ArrowRight" });
114
+ },
115
+ expected: { stable: 0, state: 1 },
116
+ },
117
+ ])("$description", ({ act: action, expected }) => {
118
+ const { day, reset } = setup();
119
+ act(() => day(15).focus());
120
+ reset();
121
+
122
+ act(() => action(day));
123
+
124
+ expect(counts).toEqual(expected);
125
+ });
126
+ });
@@ -1,5 +1,6 @@
1
1
  import type { Temporal } from "@js-temporal/polyfill";
2
2
  import { createContext, useContext } from "react";
3
+ import type { OutsideDays, RootState } from "./types";
3
4
 
4
5
  /** Shared context provided by both MonthView.Root and WeeksView.Root. */
5
6
  export interface ViewContextValue {
@@ -17,6 +18,24 @@ export interface ViewContextValue {
17
18
  setGridHasFocus: (v: boolean) => void;
18
19
  }
19
20
 
21
+ /** @internal Rarely-changing values shared by both views' parts. */
22
+ export interface ViewStableContextValue {
23
+ /** Ref mirroring whether the grid holds DOM focus, without triggering re-renders. */
24
+ gridFocusedRef: React.RefObject<boolean>;
25
+ /** How days outside the viewed month are displayed. Always `"enabled"` in WeeksView. */
26
+ outsideDays: OutsideDays;
27
+ /** Moves the logically focused date (same function as {@link ViewContextValue.setFocusedDate}). */
28
+ setFocusedDate: (date: Temporal.PlainDate) => void;
29
+ }
30
+
31
+ /** @internal Volatile values shared by both views' parts. */
32
+ export interface ViewStateContextValue {
33
+ /** The viewed month with the selection's time, used for "today" highlighting and labels. */
34
+ currentDateTime: Temporal.PlainDateTime;
35
+ /** The root component's state object for render functions. */
36
+ rootState: RootState;
37
+ }
38
+
20
39
  /** @internal React context for the active view (MonthView or WeeksView). */
21
40
  export const ViewContext = createContext<ViewContextValue | null>(null);
22
41
 
@@ -29,3 +48,29 @@ export function useViewContext(): ViewContextValue {
29
48
  );
30
49
  return ctx;
31
50
  }
51
+
52
+ /** @internal Context for {@link ViewStableContextValue}. */
53
+ export const ViewStableContext = createContext<ViewStableContextValue | null>(
54
+ null,
55
+ );
56
+
57
+ /** @internal Context for {@link ViewStateContextValue}. */
58
+ export const ViewStateContext = createContext<ViewStateContextValue | null>(
59
+ null,
60
+ );
61
+
62
+ /** Returns the nearest view's stable values. */
63
+ export function useViewStable(): ViewStableContextValue {
64
+ const ctx = useContext(ViewStableContext);
65
+ if (!ctx)
66
+ throw new Error("useViewStable must be used within MonthView or WeeksView");
67
+ return ctx;
68
+ }
69
+
70
+ /** Returns the nearest view's volatile state. */
71
+ export function useViewState(): ViewStateContextValue {
72
+ const ctx = useContext(ViewStateContext);
73
+ if (!ctx)
74
+ throw new Error("useViewState must be used within MonthView or WeeksView");
75
+ return ctx;
76
+ }
@@ -0,0 +1,76 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { cleanup, render } from "@testing-library/react";
3
+ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
+ import {
5
+ DayButton,
6
+ DayCellTemplate,
7
+ Grid,
8
+ GridBody,
9
+ WeekTemplate,
10
+ } from "./grid";
11
+ import type { WeekNumberStrategy } from "./types";
12
+ import { WeekNumberCell } from "./week-number";
13
+ import { WeeksView } from "./weeks-view";
14
+
15
+ const T = Temporal;
16
+
17
+ afterEach(cleanup);
18
+
19
+ function weekNumbers(firstWeek: string, getWeekNumber?: WeekNumberStrategy) {
20
+ const { container } = render(
21
+ <WeeksView
22
+ temporal={T}
23
+ weekCount={3}
24
+ defaultFirstWeek={T.PlainDate.from(firstWeek)}
25
+ >
26
+ <Grid>
27
+ <GridBody>
28
+ <WeekTemplate>
29
+ <WeekNumberCell {...(getWeekNumber && { getWeekNumber })} />
30
+ <DayCellTemplate>
31
+ <DayButton />
32
+ </DayCellTemplate>
33
+ </WeekTemplate>
34
+ </GridBody>
35
+ </Grid>
36
+ </WeeksView>,
37
+ );
38
+ return [...container.querySelectorAll("[data-week-number]")].map((el) =>
39
+ el.getAttribute("data-week-number"),
40
+ );
41
+ }
42
+
43
+ describe("WeekNumberCell", () => {
44
+ it.each([
45
+ {
46
+ description: "default: numbers each row by its Thursday (ISO 8601)",
47
+ firstWeek: "2026-03-01",
48
+ expected: { numbers: ["10", "11", "12"] },
49
+ },
50
+ {
51
+ description:
52
+ "default: a Sunday-start row spanning New Year belongs to week 1",
53
+ firstWeek: "2025-12-28",
54
+ expected: { numbers: ["1", "2", "3"] },
55
+ },
56
+ ])("$description", ({ firstWeek, expected }) => {
57
+ expect(weekNumbers(firstWeek)).toEqual(expected.numbers);
58
+ });
59
+
60
+ it("getWeekNumber replaces the default and receives the row's days and the Temporal namespace", () => {
61
+ const getWeekNumber = vi.fn<WeekNumberStrategy>((days) => days[0]!.day);
62
+ const numbers = weekNumbers("2026-03-01", getWeekNumber);
63
+
64
+ expect(numbers).toEqual(["1", "8", "15"]);
65
+ const [days, temporal] = getWeekNumber.mock.calls[0]!;
66
+ expect({
67
+ length: days.length,
68
+ first: days[0]!.toString(),
69
+ temporal,
70
+ }).toEqual({
71
+ length: 7,
72
+ first: "2026-03-01",
73
+ temporal: T,
74
+ });
75
+ });
76
+ });
@@ -3,45 +3,56 @@ import { useRender } from "@base-ui/react/use-render";
3
3
  import { forwardRef, useContext, useMemo } from "react";
4
4
  import { useCalendarStable } from "./calendar-context";
5
5
  import { WeekDataContext } from "./context";
6
- import { useMonthViewState } from "./month-view-context";
7
6
  import type { StateAttributesMapping } from "./types";
8
7
  import type {
9
8
  WeekNumberCellState,
10
9
  WeekNumberCellProps,
11
10
  WeekNumberHeaderState,
12
11
  WeekNumberHeaderProps,
12
+ WeekNumberStrategy,
13
13
  } from "./types";
14
14
  import { getISOWeekNumber } from "./utils";
15
+ import { useViewState } from "./view-context";
15
16
 
16
17
  const weekNumberCellStateAttributesMapping = {
17
18
  root: () => null,
18
19
  weekNumber: (v) => ({ "data-week-number": String(v) }),
19
20
  } as const satisfies StateAttributesMapping<WeekNumberCellState>;
20
21
 
22
+ /**
23
+ * Default strategy: ISO 8601, generalized to the week's midpoint day.
24
+ *
25
+ * A week belongs to the year containing the majority of its days, i.e. the
26
+ * year containing its midpoint day (day ⌈N/2⌉ of an N-day week — Thursday
27
+ * for 7-day ISO weeks). The midpoint day of the row is located and its week
28
+ * number computed via {@link getISOWeekNumber}.
29
+ */
30
+ const defaultWeekNumberStrategy: WeekNumberStrategy = (weekDays, T) => {
31
+ let midDay = weekDays[0];
32
+ if (midDay === undefined) return 0;
33
+ const midpoint = Math.ceil(midDay.daysInWeek / 2);
34
+ for (const d of weekDays) {
35
+ if (d.dayOfWeek === midpoint) {
36
+ midDay = d;
37
+ break;
38
+ }
39
+ }
40
+ return getISOWeekNumber(midDay, T);
41
+ };
42
+
21
43
  function WeekNumberCellFn(
22
44
  props: WeekNumberCellProps,
23
45
  ref: React.ForwardedRef<HTMLTableCellElement>,
24
46
  ) {
25
- const { render, ...otherProps } = props;
47
+ const { render, getWeekNumber, ...otherProps } = props;
26
48
  const weekData = useContext(WeekDataContext);
27
- const { rootState } = useMonthViewState();
49
+ const { rootState } = useViewState();
28
50
  const { temporal: T } = useCalendarStable();
29
51
 
30
52
  const days = weekData?.days ?? [];
31
53
 
32
- // ISO week number is determined by the Thursday of the week
33
- const weekNumber = useMemo(() => {
34
- // Find the Thursday in this week row — it determines the ISO week number
35
- let thursday = days[0];
36
- if (thursday === undefined) return 0;
37
- for (const d of days) {
38
- if (d.dayOfWeek === 4) {
39
- thursday = d;
40
- break;
41
- }
42
- }
43
- return getISOWeekNumber(thursday, T);
44
- }, [days, T]);
54
+ const strategy = getWeekNumber ?? defaultWeekNumberStrategy;
55
+ const weekNumber = useMemo(() => strategy(days, T), [strategy, days, T]);
45
56
 
46
57
  const state = useMemo<WeekNumberCellState>(
47
58
  () => ({
@@ -68,8 +79,26 @@ function WeekNumberCellFn(
68
79
  }
69
80
 
70
81
  /**
71
- * Renders the ISO 8601 week number for a week row. Must be used inside
72
- * a {@link WeekTemplate}. Renders a `<td>` with `role="rowheader"`.
82
+ * Renders the week number for a week row. Must be used inside a
83
+ * {@link WeekTemplate}. Renders a `<td>` with `role="rowheader"`.
84
+ *
85
+ * ## Week numbering
86
+ *
87
+ * By default, week numbers follow ISO 8601: a week belongs to the year that
88
+ * contains the majority of its days, which is the year containing the week's
89
+ * midpoint day (Thursday for a Monday–Sunday 7-day week), and week 1 is the
90
+ * week containing the year's first midpoint day (equivalently, January 4).
91
+ * This holds regardless of which day the displayed week row starts on.
92
+ *
93
+ * For calendars whose weeks are not 7 days, the default generalizes the same
94
+ * rule: the midpoint is day ⌈N/2⌉ of an N-day week and the week-1 anchor is
95
+ * January (N − ⌈N/2⌉ + 1). Note that no standard defines week numbering for
96
+ * such calendars, so the default is a best-effort extrapolation.
97
+ *
98
+ * Pass `getWeekNumber` to override the numbering entirely (e.g. US-style
99
+ * numbering where week 1 contains January 1, or fiscal-year weeks). It
100
+ * receives the week row's dates in display order plus the calendar's
101
+ * Temporal namespace, and must return the number to display.
73
102
  */
74
103
  export const WeekNumberCell = forwardRef(WeekNumberCellFn) as (
75
104
  props: WeekNumberCellProps & React.RefAttributes<HTMLTableCellElement>,
@@ -84,7 +113,7 @@ function WeekNumberHeaderFn(
84
113
  ref: React.ForwardedRef<HTMLTableCellElement>,
85
114
  ) {
86
115
  const { render, ...otherProps } = props;
87
- const { rootState } = useMonthViewState();
116
+ const { rootState } = useViewState();
88
117
 
89
118
  const state = useMemo<WeekNumberHeaderState>(
90
119
  () => ({ root: rootState as unknown as WeekNumberHeaderState["root"] }),
@@ -241,6 +241,22 @@ export function WeeksGrid(props: {
241
241
  return map;
242
242
  }, [monthBoundaries]);
243
243
 
244
+ // Per-row context values, built once per set of weeks so a focus or
245
+ // selection change leaves the day cells' context untouched.
246
+ const rowValues = useMemo(
247
+ () =>
248
+ weeks.map((week, i) => {
249
+ const days = weekDaysArrays[i] ?? [];
250
+ return {
251
+ // gridRowIndex: 1-based row index in the CSS grid (header is row 1,
252
+ // weeks start at row 2).
253
+ weekData: { days, weekIndex: week.weekIndex, gridRowIndex: i + 2 },
254
+ gridMonth: { weeks: [days], year: week.year, month: week.month },
255
+ };
256
+ }),
257
+ [weeks, weekDaysArrays],
258
+ );
259
+
244
260
  const rows: React.ReactNode[] = [];
245
261
 
246
262
  for (const [i, week] of weeks.entries()) {
@@ -263,20 +279,14 @@ export function WeeksGrid(props: {
263
279
  }
264
280
 
265
281
  // Provide WeekDataContext so DayCellTemplate and children work.
266
- // gridRowIndex: 1-based row index in the CSS grid (header is row 1, weeks start at row 2).
267
- const weekGridRow = i + 2; // +1 for 1-based, +1 for header
282
+ const rowValue = rowValues[i];
283
+ if (rowValue === undefined) continue;
268
284
  rows.push(
269
285
  <WeekDataContext.Provider
270
286
  key={week.startDate.toString()}
271
- value={{ days, weekIndex: week.weekIndex, gridRowIndex: weekGridRow }}
287
+ value={rowValue.weekData}
272
288
  >
273
- <GridMonthContext.Provider
274
- value={{
275
- weeks: [days],
276
- year: week.year,
277
- month: week.month,
278
- }}
279
- >
289
+ <GridMonthContext.Provider value={rowValue.gridMonth}>
280
290
  {weekRowChildren}
281
291
  </GridMonthContext.Provider>
282
292
  </WeekDataContext.Provider>,
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { describe, it, expect } from "vitest";
2
+ import { describe, it, expect } from "vite-plus/test";
3
3
  import { computeWeeksKeyNav, type WeeksKeyNavInput } from "./weeks-keyboard";
4
4
 
5
5
  const T = Temporal;
@@ -2,9 +2,8 @@ import { mergeProps } from "@base-ui/react/merge-props";
2
2
  import { useRender } from "@base-ui/react/use-render";
3
3
  import React, { forwardRef, useMemo } from "react";
4
4
  import { useCalendarStable } from "./calendar-context";
5
- import { useMonthViewState } from "./month-view-context";
6
- import { canShift } from "./out-of-range";
7
5
  import type { RootState, StateAttributesMapping } from "./types";
6
+ import { useViewState } from "./view-context";
8
7
  import { useWeeksViewStable, useWeeksViewState } from "./weeks-view-context";
9
8
 
10
9
  // ---------------------------------------------------------------------------
@@ -70,44 +69,29 @@ function useWeeksNavButton(
70
69
  direction: "prev" | "next",
71
70
  shiftByProp: number | undefined,
72
71
  ) {
73
- const {
74
- disabled: globalDisabled,
75
- minValue,
76
- maxValue,
77
- temporal: T,
78
- weekStartDay,
79
- } = useCalendarStable();
80
- const { weekCount, outOfRangeBehavior, goNext, goPrev } =
81
- useWeeksViewStable();
72
+ const { disabled: globalDisabled } = useCalendarStable();
73
+ const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
82
74
  const { windowInfo } = useWeeksViewState();
83
- const { rootState } = useMonthViewState();
75
+ const { rootState } = useViewState();
84
76
 
85
- const currentFirstWeek = windowInfo.windowStart;
77
+ const { windowStart, weekCount } = windowInfo;
86
78
 
87
79
  const isDisabled = useMemo(() => {
88
80
  if (globalDisabled) return true;
89
- return !canShift({
90
- currentFirstWeek,
91
- weekCount,
92
- direction: direction === "next" ? 1 : -1,
93
- ...(shiftByProp !== undefined && { shiftBy: shiftByProp }),
94
- behavior: outOfRangeBehavior,
95
- ...(minValue !== undefined && { min: minValue }),
96
- ...(maxValue !== undefined && { max: maxValue }),
97
- weekStartDay,
98
- T,
99
- });
81
+ return (
82
+ windowPolicy.shift(
83
+ { firstWeek: windowStart, weekCount },
84
+ direction === "next" ? 1 : -1,
85
+ shiftByProp,
86
+ ) === null
87
+ );
100
88
  }, [
101
89
  globalDisabled,
102
- currentFirstWeek,
90
+ windowPolicy,
91
+ windowStart,
103
92
  weekCount,
104
93
  direction,
105
94
  shiftByProp,
106
- outOfRangeBehavior,
107
- minValue,
108
- maxValue,
109
- weekStartDay,
110
- T,
111
95
  ]);
112
96
 
113
97
  const state = useMemo<WeeksNavButtonState>(
@@ -193,7 +177,7 @@ function WeekCountFn(
193
177
  ) {
194
178
  const { render, ...otherProps } = props;
195
179
  const { windowInfo } = useWeeksViewState();
196
- const { rootState } = useMonthViewState();
180
+ const { rootState } = useViewState();
197
181
  const count = windowInfo.weekCount;
198
182
 
199
183
  const state = useMemo<WeekCountState>(