@klinking/colander 0.0.0 → 2.0.0
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.
- package/dist/formats/date.cjs +51 -48
- package/dist/formats/date.d.cts +10 -37
- package/dist/formats/date.d.mts +10 -37
- package/dist/formats/date.mjs +6 -2
- package/dist/formats/object.cjs +51 -48
- package/dist/formats/object.d.cts +10 -37
- package/dist/formats/object.d.mts +10 -37
- package/dist/formats/object.mjs +6 -2
- package/dist/formats/plain-date-time.cjs +51 -48
- package/dist/formats/plain-date-time.d.cts +10 -37
- package/dist/formats/plain-date-time.d.mts +10 -37
- package/dist/formats/plain-date-time.mjs +6 -2
- package/dist/formats/plain-date.cjs +51 -48
- package/dist/formats/plain-date.d.cts +10 -37
- package/dist/formats/plain-date.d.mts +10 -37
- package/dist/formats/plain-date.mjs +6 -2
- package/dist/formats/plain-month-day.cjs +51 -48
- package/dist/formats/plain-month-day.d.cts +10 -37
- package/dist/formats/plain-month-day.d.mts +10 -37
- package/dist/formats/plain-month-day.mjs +6 -2
- package/dist/formats/plain-year-month.cjs +51 -48
- package/dist/formats/plain-year-month.d.cts +10 -37
- package/dist/formats/plain-year-month.d.mts +10 -37
- package/dist/formats/plain-year-month.mjs +6 -2
- package/dist/formats/zoned-date-time.cjs +51 -48
- package/dist/formats/zoned-date-time.d.cts +10 -37
- package/dist/formats/zoned-date-time.d.mts +10 -37
- package/dist/formats/zoned-date-time.mjs +6 -2
- package/dist/index.cjs +47 -48
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +2 -2
- package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-CtbaTTmA.cjs} +329 -567
- package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-D5GjCwNm.mjs} +329 -561
- package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
- package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
- package/package.json +20 -20
- package/src/calendar-context.ts +12 -5
- package/src/calendar-provider.test.tsx +18 -4
- package/src/calendar-provider.tsx +130 -35
- package/src/calendar-types.ts +21 -4
- package/src/compute-weeks-in-window.test.ts +9 -7
- package/src/context.ts +1 -1
- package/src/day-cell.tsx +92 -46
- package/src/drag-handle.tsx +23 -24
- package/src/formats/date.ts +120 -56
- package/src/formats/formats.test.ts +8 -4
- package/src/formats/object.ts +120 -56
- package/src/formats/plain-date-time.ts +120 -56
- package/src/formats/plain-date.ts +120 -56
- package/src/formats/plain-month-day.ts +120 -56
- package/src/formats/plain-year-month.ts +120 -56
- package/src/formats/zoned-date-time.ts +120 -56
- package/src/grid-header.tsx +24 -18
- package/src/grid.event-perf.test.tsx +30 -13
- package/src/grid.perf.test.tsx +97 -33
- package/src/grid.tsx +75 -43
- package/src/index.ts +16 -4
- package/src/keyboard.test.ts +110 -42
- package/src/keyboard.ts +18 -7
- package/src/month-separator.test.tsx +3 -1
- package/src/month-separator.tsx +30 -9
- package/src/month-view-context.ts +8 -3
- package/src/month-view-types.ts +14 -10
- package/src/month-view.test.tsx +687 -68
- package/src/month-view.tsx +176 -71
- package/src/navigation.tsx +77 -47
- package/src/overflow.test.ts +15 -13
- package/src/overflow.ts +10 -2
- package/src/range-preview.tsx +37 -12
- package/src/resolve-first-week.test.ts +14 -10
- package/src/resolve-first-week.ts +6 -2
- package/src/root-selection.ts +185 -101
- package/src/selected-range.tsx +47 -22
- package/src/test-temporal.ts +0 -2
- package/src/types.ts +126 -103
- package/src/utils.bench.ts +30 -6
- package/src/utils.test.ts +203 -55
- package/src/utils.ts +156 -54
- package/src/view-context.ts +4 -1
- package/src/week-number.tsx +5 -8
- package/src/weeks-grid.tsx +45 -19
- package/src/weeks-keyboard.test.ts +6 -7
- package/src/weeks-keyboard.ts +8 -3
- package/src/weeks-navigation.tsx +21 -9
- package/src/weeks-view-context.ts +8 -3
- package/src/weeks-view-state.ts +100 -33
- package/src/weeks-view-types.ts +14 -8
- package/src/weeks-view.test.tsx +127 -19
- package/src/weeks-view.tsx +30 -12
- package/src/temporal-polyfill.test.ts +0 -317
- package/src/temporal-polyfill.ts +0 -566
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
WeeksViewStableContextValue,
|
|
4
|
+
WeeksViewStateContextValue,
|
|
5
|
+
} from "./weeks-view-types";
|
|
3
6
|
|
|
4
7
|
/** @internal React context for WeeksView stable values (config + callbacks). */
|
|
5
|
-
export const WeeksViewStableContext =
|
|
8
|
+
export const WeeksViewStableContext =
|
|
9
|
+
createContext<WeeksViewStableContextValue | null>(null);
|
|
6
10
|
|
|
7
11
|
/** @internal React context for WeeksView volatile state. */
|
|
8
|
-
export const WeeksViewStateContext =
|
|
12
|
+
export const WeeksViewStateContext =
|
|
13
|
+
createContext<WeeksViewStateContextValue | null>(null);
|
|
9
14
|
|
|
10
15
|
/** Returns the WeeksView stable context (config + callbacks). */
|
|
11
16
|
export function useWeeksViewStable(): WeeksViewStableContextValue {
|
package/src/weeks-view-state.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
3
3
|
import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
4
4
|
import { computeWeeksInWindow } from "./compute-weeks-in-window";
|
|
5
5
|
import { applyOverflow, type OverflowBehavior } from "./overflow";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
resolveFirstWeekSpec,
|
|
8
|
+
resolveFirstWeek,
|
|
9
|
+
type FirstWeekSpec,
|
|
10
|
+
} from "./resolve-first-week";
|
|
11
|
+
import type { RootState } from "./types";
|
|
7
12
|
import { selectedToZdt, toZonedDateTime } from "./utils";
|
|
8
13
|
import type { ViewContextValue } from "./view-context";
|
|
9
14
|
import type {
|
|
@@ -29,35 +34,46 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
29
34
|
} = props;
|
|
30
35
|
|
|
31
36
|
const scrollBy = scrollByProp ?? "row";
|
|
32
|
-
const overflowBehavior: OverflowBehavior =
|
|
37
|
+
const overflowBehavior: OverflowBehavior =
|
|
38
|
+
overflowBehaviorProp ?? "unbounded";
|
|
33
39
|
|
|
34
40
|
// Read calendar-level context
|
|
35
41
|
const calStable = useCalendarStable();
|
|
36
42
|
const calState = useCalendarState();
|
|
37
43
|
|
|
38
44
|
const T = calStable.temporal;
|
|
39
|
-
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } =
|
|
45
|
+
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } =
|
|
46
|
+
calStable;
|
|
40
47
|
|
|
41
48
|
// --- Controlled/uncontrolled firstWeek ---
|
|
42
49
|
const isControlled = firstWeekProp !== undefined;
|
|
43
50
|
|
|
44
51
|
const resolveSpec = useCallback(
|
|
45
|
-
(spec: FirstWeekSpec): Temporal.PlainDate =>
|
|
52
|
+
(spec: FirstWeekSpec): Temporal.PlainDate =>
|
|
53
|
+
resolveFirstWeekSpec(spec, weekStartDay, T),
|
|
46
54
|
[weekStartDay, T],
|
|
47
55
|
);
|
|
48
56
|
|
|
49
|
-
const [internalFirstWeek, setInternalFirstWeek] =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const [internalFirstWeek, setInternalFirstWeek] =
|
|
58
|
+
useState<Temporal.PlainDate>(() => {
|
|
59
|
+
if (firstWeekProp !== undefined) return resolveSpec(firstWeekProp);
|
|
60
|
+
if (defaultFirstWeekProp !== undefined)
|
|
61
|
+
return resolveSpec(defaultFirstWeekProp);
|
|
62
|
+
// Derive from selection or today
|
|
63
|
+
if (calState.selected) {
|
|
64
|
+
const plain = toZonedDateTime(
|
|
65
|
+
calState.selected,
|
|
66
|
+
timeZone,
|
|
67
|
+
T,
|
|
68
|
+
).toPlainDate();
|
|
69
|
+
return resolveSpec(plain);
|
|
70
|
+
}
|
|
71
|
+
return resolveSpec(T.Now.plainDateISO());
|
|
72
|
+
});
|
|
59
73
|
|
|
60
|
-
const resolvedFirstWeek = isControlled
|
|
74
|
+
const resolvedFirstWeek = isControlled
|
|
75
|
+
? resolveSpec(firstWeekProp)
|
|
76
|
+
: internalFirstWeek;
|
|
61
77
|
|
|
62
78
|
// --- Compute week window ---
|
|
63
79
|
const rawWeeks = useMemo(
|
|
@@ -72,17 +88,26 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
72
88
|
targetFirstWeek: resolvedFirstWeek,
|
|
73
89
|
weekCount,
|
|
74
90
|
behavior: overflowBehavior,
|
|
75
|
-
min: minValue,
|
|
76
|
-
max: maxValue,
|
|
91
|
+
...(minValue !== undefined && { min: minValue }),
|
|
92
|
+
...(maxValue !== undefined && { max: maxValue }),
|
|
77
93
|
weekStartDay,
|
|
78
94
|
T,
|
|
79
95
|
}),
|
|
80
|
-
[
|
|
96
|
+
[
|
|
97
|
+
resolvedFirstWeek,
|
|
98
|
+
weekCount,
|
|
99
|
+
overflowBehavior,
|
|
100
|
+
minValue,
|
|
101
|
+
maxValue,
|
|
102
|
+
weekStartDay,
|
|
103
|
+
T,
|
|
104
|
+
],
|
|
81
105
|
);
|
|
82
106
|
|
|
83
107
|
// Recompute weeks if overflow adjusted the window
|
|
84
108
|
const adjustedWeeks = useMemo(() => {
|
|
85
|
-
const sameFirst =
|
|
109
|
+
const sameFirst =
|
|
110
|
+
T.PlainDate.compare(overflowResult.firstWeek, resolvedFirstWeek) === 0;
|
|
86
111
|
const sameCount = overflowResult.weekCount === weekCount;
|
|
87
112
|
if (sameFirst && sameCount) return rawWeeks;
|
|
88
113
|
return computeWeeksInWindow(
|
|
@@ -106,7 +131,9 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
106
131
|
|
|
107
132
|
const windowInfo = useMemo<WindowInfo>(() => {
|
|
108
133
|
const weeks = adjustedWeeks;
|
|
109
|
-
|
|
134
|
+
const firstWeek = weeks[0];
|
|
135
|
+
const lastWeek = weeks[weeks.length - 1];
|
|
136
|
+
if (firstWeek === undefined || lastWeek === undefined) {
|
|
110
137
|
const today = T.Now.plainDateISO();
|
|
111
138
|
return {
|
|
112
139
|
windowStart: today,
|
|
@@ -118,8 +145,8 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
118
145
|
visibleMonths: [],
|
|
119
146
|
};
|
|
120
147
|
}
|
|
121
|
-
const windowStart =
|
|
122
|
-
const windowEnd =
|
|
148
|
+
const windowStart = firstWeek.startDate;
|
|
149
|
+
const windowEnd = lastWeek.endDate;
|
|
123
150
|
const wc = weeks.length;
|
|
124
151
|
const dayCount = wc * 7;
|
|
125
152
|
|
|
@@ -224,7 +251,8 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
224
251
|
if (d < 6) day = day.add({ days: 1 });
|
|
225
252
|
}
|
|
226
253
|
}
|
|
227
|
-
const inGrid = (d: Temporal.PlainDate) =>
|
|
254
|
+
const inGrid = (d: Temporal.PlainDate) =>
|
|
255
|
+
allDays.some((g) => T.PlainDate.compare(g, d) === 0);
|
|
228
256
|
|
|
229
257
|
if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
|
|
230
258
|
if (selectedPlain && inGrid(selectedPlain)) return selectedPlain;
|
|
@@ -286,8 +314,8 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
286
314
|
targetFirstWeek: target,
|
|
287
315
|
weekCount,
|
|
288
316
|
behavior: overflowBehavior,
|
|
289
|
-
min: minValue,
|
|
290
|
-
max: maxValue,
|
|
317
|
+
...(minValue !== undefined && { min: minValue }),
|
|
318
|
+
...(maxValue !== undefined && { max: maxValue }),
|
|
291
319
|
weekStartDay,
|
|
292
320
|
T,
|
|
293
321
|
});
|
|
@@ -313,8 +341,8 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
313
341
|
targetFirstWeek: target,
|
|
314
342
|
weekCount,
|
|
315
343
|
behavior: overflowBehavior,
|
|
316
|
-
min: minValue,
|
|
317
|
-
max: maxValue,
|
|
344
|
+
...(minValue !== undefined && { min: minValue }),
|
|
345
|
+
...(maxValue !== undefined && { max: maxValue }),
|
|
318
346
|
weekStartDay,
|
|
319
347
|
T,
|
|
320
348
|
});
|
|
@@ -334,15 +362,23 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
334
362
|
|
|
335
363
|
// --- scrollToWeek ---
|
|
336
364
|
const scrollToWeek = useCallback(
|
|
337
|
-
(
|
|
365
|
+
(
|
|
366
|
+
target: FirstWeekSpec,
|
|
367
|
+
options?: { snap?: "start" | "center" | "end" | "nearest" },
|
|
368
|
+
) => {
|
|
338
369
|
const resolvedTarget = resolveSpec(target);
|
|
339
|
-
const newFirstWeek = resolveFirstWeek(
|
|
370
|
+
const newFirstWeek = resolveFirstWeek(
|
|
371
|
+
resolvedFirstWeek,
|
|
372
|
+
weekCount,
|
|
373
|
+
resolvedTarget,
|
|
374
|
+
options,
|
|
375
|
+
);
|
|
340
376
|
const adjusted = applyOverflow({
|
|
341
377
|
targetFirstWeek: newFirstWeek,
|
|
342
378
|
weekCount,
|
|
343
379
|
behavior: overflowBehavior,
|
|
344
|
-
min: minValue,
|
|
345
|
-
max: maxValue,
|
|
380
|
+
...(minValue !== undefined && { min: minValue }),
|
|
381
|
+
...(maxValue !== undefined && { max: maxValue }),
|
|
346
382
|
weekStartDay,
|
|
347
383
|
T,
|
|
348
384
|
});
|
|
@@ -391,7 +427,30 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
391
427
|
gridFocusedRef,
|
|
392
428
|
setGridLabelId,
|
|
393
429
|
}),
|
|
394
|
-
[
|
|
430
|
+
[
|
|
431
|
+
weekCount,
|
|
432
|
+
scrollBy,
|
|
433
|
+
overflowBehavior,
|
|
434
|
+
goNext,
|
|
435
|
+
goPrev,
|
|
436
|
+
scrollToWeek,
|
|
437
|
+
setGridLabelId,
|
|
438
|
+
],
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
// Real render-prop rootState shared by the MonthViewState shims (WeeksView
|
|
442
|
+
// root + the inner Grid), so components reading `state.root` inside WeeksView
|
|
443
|
+
// see populated values instead of an empty cast.
|
|
444
|
+
const rootState = useMemo<RootState>(
|
|
445
|
+
() => ({
|
|
446
|
+
...calState.baseRootState,
|
|
447
|
+
focused: focusedDate,
|
|
448
|
+
viewing: T.PlainYearMonth.from({
|
|
449
|
+
year: currentDateTime.year,
|
|
450
|
+
month: currentDateTime.month,
|
|
451
|
+
}),
|
|
452
|
+
}),
|
|
453
|
+
[calState.baseRootState, focusedDate, currentDateTime, T],
|
|
395
454
|
);
|
|
396
455
|
|
|
397
456
|
const stateCtx = useMemo<WeeksViewStateContextValue>(
|
|
@@ -401,8 +460,16 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
401
460
|
gridLabelIds,
|
|
402
461
|
weeks: adjustedWeeks,
|
|
403
462
|
currentDateTime,
|
|
463
|
+
rootState,
|
|
404
464
|
}),
|
|
405
|
-
[
|
|
465
|
+
[
|
|
466
|
+
focusedDate,
|
|
467
|
+
windowInfo,
|
|
468
|
+
gridLabelIds,
|
|
469
|
+
adjustedWeeks,
|
|
470
|
+
currentDateTime,
|
|
471
|
+
rootState,
|
|
472
|
+
],
|
|
406
473
|
);
|
|
407
474
|
|
|
408
475
|
const viewCtx = useMemo<ViewContextValue>(
|
package/src/weeks-view-types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import type { WeekDescriptor } from "./compute-weeks-in-window";
|
|
3
3
|
import type { OverflowBehavior } from "./overflow";
|
|
4
4
|
import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
|
|
5
|
+
import type { RootState } from "./types";
|
|
5
6
|
|
|
6
7
|
// ---------------------------------------------------------------------------
|
|
7
8
|
// WeeksView.Root props
|
|
@@ -12,27 +13,27 @@ export interface WeeksViewRootProps {
|
|
|
12
13
|
/** Number of week rows to display simultaneously. */
|
|
13
14
|
weekCount: number;
|
|
14
15
|
/** The controlled first visible week. When provided, the component is controlled. */
|
|
15
|
-
firstWeek?: FirstWeekSpec;
|
|
16
|
+
firstWeek?: FirstWeekSpec | undefined;
|
|
16
17
|
/** The initial first visible week (uncontrolled). */
|
|
17
|
-
defaultFirstWeek?: FirstWeekSpec;
|
|
18
|
+
defaultFirstWeek?: FirstWeekSpec | undefined;
|
|
18
19
|
/** Called when the first visible week changes via navigation or focus movement. */
|
|
19
|
-
onFirstWeekChange?: (date: Temporal.PlainDate) => void;
|
|
20
|
+
onFirstWeekChange?: ((date: Temporal.PlainDate) => void) | undefined;
|
|
20
21
|
/**
|
|
21
22
|
* How much to scroll per navigation step.
|
|
22
23
|
* - `"row"` — scroll one week row at a time.
|
|
23
24
|
* - `"page"` — scroll a full page (all visible rows) at a time.
|
|
24
25
|
* @default "row"
|
|
25
26
|
*/
|
|
26
|
-
scrollBy?: "row" | "page";
|
|
27
|
+
scrollBy?: "row" | "page" | undefined;
|
|
27
28
|
/**
|
|
28
29
|
* How navigation behaves at `min`/`max` bounds.
|
|
29
30
|
* @default "unbounded"
|
|
30
31
|
*/
|
|
31
|
-
overflowBehavior?: OverflowBehavior;
|
|
32
|
+
overflowBehavior?: OverflowBehavior | undefined;
|
|
32
33
|
/** Called when the visible window changes. */
|
|
33
|
-
onWindowChange?: (info: WindowInfo) => void;
|
|
34
|
+
onWindowChange?: ((info: WindowInfo) => void) | undefined;
|
|
34
35
|
/** React children. */
|
|
35
|
-
children?: React.ReactNode;
|
|
36
|
+
children?: React.ReactNode | undefined;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// ---------------------------------------------------------------------------
|
|
@@ -80,7 +81,10 @@ export interface WeeksViewStableContextValue {
|
|
|
80
81
|
/** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
|
|
81
82
|
goPrev: (shiftBy?: number) => void;
|
|
82
83
|
/** Imperatively scroll so that the target week is visible at the given snap position. */
|
|
83
|
-
scrollToWeek: (
|
|
84
|
+
scrollToWeek: (
|
|
85
|
+
target: FirstWeekSpec,
|
|
86
|
+
options?: { snap?: ScrollToWeekSnap },
|
|
87
|
+
) => void;
|
|
84
88
|
/** Ref tracking whether the grid currently holds DOM focus (avoids state re-renders). */
|
|
85
89
|
gridFocusedRef: React.MutableRefObject<boolean>;
|
|
86
90
|
/** Register (or clear) the id of a label element for `aria-labelledby`. */
|
|
@@ -99,4 +103,6 @@ export interface WeeksViewStateContextValue {
|
|
|
99
103
|
weeks: WeekDescriptor[];
|
|
100
104
|
/** Date-time representing the current moment (for "today" highlighting). */
|
|
101
105
|
currentDateTime: Temporal.PlainDateTime;
|
|
106
|
+
/** Render-prop `RootState` exposed to components inside WeeksView. */
|
|
107
|
+
rootState: RootState;
|
|
102
108
|
}
|
package/src/weeks-view.test.tsx
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { render, screen, act, cleanup, within } from "@testing-library/react";
|
|
3
3
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Grid,
|
|
6
|
+
GridBody,
|
|
7
|
+
WeekTemplate,
|
|
8
|
+
DayCellTemplate,
|
|
9
|
+
DayButton,
|
|
10
|
+
} from "./grid";
|
|
5
11
|
import { GridHeader, GridHeaderCell } from "./grid-header";
|
|
6
12
|
import {
|
|
7
13
|
MonthSeparator,
|
|
@@ -9,6 +15,7 @@ import {
|
|
|
9
15
|
MonthSeparatorYear,
|
|
10
16
|
MonthSeparatorWeekCount,
|
|
11
17
|
} from "./month-separator";
|
|
18
|
+
import { useMonthViewState } from "./month-view-context";
|
|
12
19
|
import { useViewContext } from "./view-context";
|
|
13
20
|
import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation";
|
|
14
21
|
import { WeeksView } from "./weeks-view";
|
|
@@ -28,8 +35,12 @@ function WindowDisplay() {
|
|
|
28
35
|
<span data-testid="end">{state.windowInfo.windowEnd.toString()}</span>
|
|
29
36
|
<span data-testid="count">{state.windowInfo.weekCount}</span>
|
|
30
37
|
<span data-testid="day-count">{state.windowInfo.dayCount}</span>
|
|
31
|
-
<span data-testid="enabled-week-count">
|
|
32
|
-
|
|
38
|
+
<span data-testid="enabled-week-count">
|
|
39
|
+
{state.windowInfo.enabledWeekCount}
|
|
40
|
+
</span>
|
|
41
|
+
<span data-testid="enabled-day-count">
|
|
42
|
+
{state.windowInfo.enabledDayCount}
|
|
43
|
+
</span>
|
|
33
44
|
</div>
|
|
34
45
|
);
|
|
35
46
|
}
|
|
@@ -69,7 +80,11 @@ afterEach(() => {
|
|
|
69
80
|
describe("WeeksView", () => {
|
|
70
81
|
it("renders 8 weeks starting from firstWeek", () => {
|
|
71
82
|
render(
|
|
72
|
-
<WeeksView
|
|
83
|
+
<WeeksView
|
|
84
|
+
temporal={T}
|
|
85
|
+
weekCount={8}
|
|
86
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
87
|
+
>
|
|
73
88
|
<WindowDisplay />
|
|
74
89
|
</WeeksView>,
|
|
75
90
|
);
|
|
@@ -81,7 +96,11 @@ describe("WeeksView", () => {
|
|
|
81
96
|
|
|
82
97
|
it("provides viewType=weeks", () => {
|
|
83
98
|
render(
|
|
84
|
-
<WeeksView
|
|
99
|
+
<WeeksView
|
|
100
|
+
temporal={T}
|
|
101
|
+
weekCount={4}
|
|
102
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
103
|
+
>
|
|
85
104
|
<ViewTypeDisplay />
|
|
86
105
|
</WeeksView>,
|
|
87
106
|
);
|
|
@@ -90,7 +109,11 @@ describe("WeeksView", () => {
|
|
|
90
109
|
|
|
91
110
|
it("accepts { month, year } as firstWeek", () => {
|
|
92
111
|
render(
|
|
93
|
-
<WeeksView
|
|
112
|
+
<WeeksView
|
|
113
|
+
temporal={T}
|
|
114
|
+
weekCount={4}
|
|
115
|
+
defaultFirstWeek={{ month: 3, year: 2026 }}
|
|
116
|
+
>
|
|
94
117
|
<WindowDisplay />
|
|
95
118
|
</WeeksView>,
|
|
96
119
|
);
|
|
@@ -110,7 +133,7 @@ describe("WeeksView", () => {
|
|
|
110
133
|
</WeeksView>,
|
|
111
134
|
);
|
|
112
135
|
expect(onWindowChange).toHaveBeenCalledTimes(1);
|
|
113
|
-
expect(onWindowChange.mock.calls[0][0].weekCount).toBe(4);
|
|
136
|
+
expect(onWindowChange.mock.calls[0]![0].weekCount).toBe(4);
|
|
114
137
|
});
|
|
115
138
|
|
|
116
139
|
it("navigates forward via goNext (buttons always shift by weekCount)", () => {
|
|
@@ -187,7 +210,11 @@ describe("WeeksView", () => {
|
|
|
187
210
|
|
|
188
211
|
it("focuses first day of window when no selection", () => {
|
|
189
212
|
render(
|
|
190
|
-
<WeeksView
|
|
213
|
+
<WeeksView
|
|
214
|
+
temporal={T}
|
|
215
|
+
weekCount={8}
|
|
216
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
217
|
+
>
|
|
191
218
|
<FocusDisplay />
|
|
192
219
|
</WeeksView>,
|
|
193
220
|
);
|
|
@@ -197,7 +224,11 @@ describe("WeeksView", () => {
|
|
|
197
224
|
it("snaps firstWeek to the start of the week (Sunday)", () => {
|
|
198
225
|
// 2026-03-04 is a Wednesday; should snap back to 2026-03-01 (Sunday)
|
|
199
226
|
render(
|
|
200
|
-
<WeeksView
|
|
227
|
+
<WeeksView
|
|
228
|
+
temporal={T}
|
|
229
|
+
weekCount={4}
|
|
230
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-04")}
|
|
231
|
+
>
|
|
201
232
|
<WindowDisplay />
|
|
202
233
|
</WeeksView>,
|
|
203
234
|
);
|
|
@@ -240,12 +271,16 @@ describe("WeeksView", () => {
|
|
|
240
271
|
});
|
|
241
272
|
expect(onFirstWeekChange).toHaveBeenCalledTimes(1);
|
|
242
273
|
// weekCount=4, so shifts by 4 weeks
|
|
243
|
-
expect(onFirstWeekChange.mock.calls[0][0].toString()).toBe("2026-03-29");
|
|
274
|
+
expect(onFirstWeekChange.mock.calls[0]![0].toString()).toBe("2026-03-29");
|
|
244
275
|
});
|
|
245
276
|
|
|
246
277
|
it("accepts { isoWeek, isoYear } as firstWeek", () => {
|
|
247
278
|
render(
|
|
248
|
-
<WeeksView
|
|
279
|
+
<WeeksView
|
|
280
|
+
temporal={T}
|
|
281
|
+
weekCount={1}
|
|
282
|
+
defaultFirstWeek={{ isoWeek: 10, isoYear: 2026 }}
|
|
283
|
+
>
|
|
249
284
|
<WindowDisplay />
|
|
250
285
|
</WeeksView>,
|
|
251
286
|
);
|
|
@@ -260,7 +295,11 @@ describe("WeeksView", () => {
|
|
|
260
295
|
}
|
|
261
296
|
|
|
262
297
|
render(
|
|
263
|
-
<WeeksView
|
|
298
|
+
<WeeksView
|
|
299
|
+
temporal={T}
|
|
300
|
+
weekCount={6}
|
|
301
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
302
|
+
>
|
|
264
303
|
<WeeksDataDisplay />
|
|
265
304
|
</WeeksView>,
|
|
266
305
|
);
|
|
@@ -299,7 +338,11 @@ describe("WeeksView regression: no spurious data-outside-month (Bug #1)", () =>
|
|
|
299
338
|
// in weeks view, so isCurrentMonth was always false and every day got
|
|
300
339
|
// data-outside-month. Fix passes per-day { year, month }.
|
|
301
340
|
const { container } = render(
|
|
302
|
-
<WeeksView
|
|
341
|
+
<WeeksView
|
|
342
|
+
temporal={T}
|
|
343
|
+
weekCount={4}
|
|
344
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
345
|
+
>
|
|
303
346
|
<Grid>
|
|
304
347
|
<GridHeader>
|
|
305
348
|
<GridHeaderCell />
|
|
@@ -318,14 +361,20 @@ describe("WeeksView regression: no spurious data-outside-month (Bug #1)", () =>
|
|
|
318
361
|
const cells = container.querySelectorAll("td[role='gridcell']");
|
|
319
362
|
expect(cells.length).toBeGreaterThan(0);
|
|
320
363
|
|
|
321
|
-
const outsideMonthCells = container.querySelectorAll(
|
|
364
|
+
const outsideMonthCells = container.querySelectorAll(
|
|
365
|
+
"td[data-outside-month]",
|
|
366
|
+
);
|
|
322
367
|
expect(outsideMonthCells.length).toBe(0);
|
|
323
368
|
});
|
|
324
369
|
|
|
325
370
|
it("days spanning a month boundary still have no data-outside-month", () => {
|
|
326
371
|
// Window: 2026-03-22 through 2026-04-18 (4 weeks crossing March/April)
|
|
327
372
|
const { container } = render(
|
|
328
|
-
<WeeksView
|
|
373
|
+
<WeeksView
|
|
374
|
+
temporal={T}
|
|
375
|
+
weekCount={4}
|
|
376
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-22")}
|
|
377
|
+
>
|
|
329
378
|
<Grid>
|
|
330
379
|
<GridBody>
|
|
331
380
|
<WeekTemplate>
|
|
@@ -336,7 +385,9 @@ describe("WeeksView regression: no spurious data-outside-month (Bug #1)", () =>
|
|
|
336
385
|
</WeeksView>,
|
|
337
386
|
);
|
|
338
387
|
|
|
339
|
-
const outsideMonthCells = container.querySelectorAll(
|
|
388
|
+
const outsideMonthCells = container.querySelectorAll(
|
|
389
|
+
"td[data-outside-month]",
|
|
390
|
+
);
|
|
340
391
|
expect(outsideMonthCells.length).toBe(0);
|
|
341
392
|
});
|
|
342
393
|
});
|
|
@@ -346,7 +397,11 @@ describe("WeeksView regression: MonthSeparator renders in context (Bug #2)", ()
|
|
|
346
397
|
// Window: 2026-03-22 through 2026-04-18 (4 weeks crossing March/April)
|
|
347
398
|
// Should render separators for March and April.
|
|
348
399
|
const { container } = render(
|
|
349
|
-
<WeeksView
|
|
400
|
+
<WeeksView
|
|
401
|
+
temporal={T}
|
|
402
|
+
weekCount={4}
|
|
403
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-22")}
|
|
404
|
+
>
|
|
350
405
|
<Grid>
|
|
351
406
|
<GridBody>
|
|
352
407
|
<MonthSeparator>
|
|
@@ -375,11 +430,16 @@ describe("WeeksView regression: MonthSeparator renders in context (Bug #2)", ()
|
|
|
375
430
|
// March: weeks at index 0 (month=3) and 1 (month=3) -> weeksVisibleAfter=2
|
|
376
431
|
// April: weeks at index 2 (month=4) and 3 (month=4) -> weeksVisibleAfter=2
|
|
377
432
|
const { container } = render(
|
|
378
|
-
<WeeksView
|
|
433
|
+
<WeeksView
|
|
434
|
+
temporal={T}
|
|
435
|
+
weekCount={4}
|
|
436
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-22")}
|
|
437
|
+
>
|
|
379
438
|
<Grid>
|
|
380
439
|
<GridBody>
|
|
381
440
|
<MonthSeparator>
|
|
382
|
-
<MonthSeparatorMonth />
|
|
441
|
+
<MonthSeparatorMonth />{" "}
|
|
442
|
+
<MonthSeparatorWeekCount data-testid="wc" />
|
|
383
443
|
</MonthSeparator>
|
|
384
444
|
<WeekTemplate>
|
|
385
445
|
<DayCellTemplate />
|
|
@@ -477,3 +537,51 @@ describe("WeeksView regression: goNext/goPrev shift by weekCount (Bug #3)", () =
|
|
|
477
537
|
expect(screen.getByTestId("start").textContent).toBe("2026-03-15");
|
|
478
538
|
});
|
|
479
539
|
});
|
|
540
|
+
|
|
541
|
+
describe("WeeksView regression: rootState shim is populated", () => {
|
|
542
|
+
function ShimRootStateCapture({
|
|
543
|
+
onCapture,
|
|
544
|
+
}: {
|
|
545
|
+
onCapture: (
|
|
546
|
+
root: ReturnType<typeof useMonthViewState>["rootState"],
|
|
547
|
+
) => void;
|
|
548
|
+
}) {
|
|
549
|
+
const { rootState } = useMonthViewState();
|
|
550
|
+
onCapture(rootState);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
it("exposes a real rootState to components reading useMonthViewState()", () => {
|
|
555
|
+
let root: ReturnType<typeof useMonthViewState>["rootState"] | undefined;
|
|
556
|
+
render(
|
|
557
|
+
<WeeksView
|
|
558
|
+
temporal={T}
|
|
559
|
+
weekCount={4}
|
|
560
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
561
|
+
defaultValue={T.PlainDate.from("2026-03-15")}
|
|
562
|
+
>
|
|
563
|
+
<ShimRootStateCapture
|
|
564
|
+
onCapture={(r) => {
|
|
565
|
+
root = r;
|
|
566
|
+
}}
|
|
567
|
+
/>
|
|
568
|
+
</WeeksView>,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
// Pre-fix this shim was `{} as RootState` — every field undefined at runtime.
|
|
572
|
+
expect(root).toBeDefined();
|
|
573
|
+
expect(root!.viewing).toBeInstanceOf(Temporal.PlainYearMonth);
|
|
574
|
+
expect(root!.focused).toBeInstanceOf(Temporal.PlainDate);
|
|
575
|
+
expect(typeof root!.timeZone).toBe("string");
|
|
576
|
+
expect(root!.timeZone.length).toBeGreaterThan(0);
|
|
577
|
+
expect(typeof root!.locale).toBe("string");
|
|
578
|
+
expect(typeof root!.readOnly).toBe("boolean");
|
|
579
|
+
// Selection flows through the shared baseRootState into the shim.
|
|
580
|
+
expect(root!.hasSelection).toBe(true);
|
|
581
|
+
expect(root!.selected).toBeInstanceOf(Temporal.PlainDate);
|
|
582
|
+
expect(root!.selected!.toString()).toBe("2026-03-15");
|
|
583
|
+
expect(
|
|
584
|
+
root!.selectedDates.every((d) => d instanceof Temporal.PlainDate),
|
|
585
|
+
).toBe(true);
|
|
586
|
+
});
|
|
587
|
+
});
|
package/src/weeks-view.tsx
CHANGED
|
@@ -2,11 +2,17 @@ import type { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
|
|
3
3
|
import { CalendarProvider } from "./calendar-provider";
|
|
4
4
|
import type { CalendarProviderProps } from "./calendar-types";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
MonthViewStableContext,
|
|
7
|
+
MonthViewStateContext,
|
|
8
|
+
} from "./month-view-context";
|
|
6
9
|
import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
|
|
7
|
-
import type {
|
|
10
|
+
import type { ValueFormat } from "./types";
|
|
8
11
|
import { ViewContext } from "./view-context";
|
|
9
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
WeeksViewStableContext,
|
|
14
|
+
WeeksViewStateContext,
|
|
15
|
+
} from "./weeks-view-context";
|
|
10
16
|
import { useWeeksViewRootState } from "./weeks-view-state";
|
|
11
17
|
import type { WeeksViewRootProps } from "./weeks-view-types";
|
|
12
18
|
|
|
@@ -16,12 +22,19 @@ import type { WeeksViewRootProps } from "./weeks-view-types";
|
|
|
16
22
|
|
|
17
23
|
/** Imperative handle exposed by WeeksView.Root via ref. */
|
|
18
24
|
export interface WeeksViewRootHandle {
|
|
19
|
-
scrollToWeek: (
|
|
25
|
+
scrollToWeek: (
|
|
26
|
+
target: FirstWeekSpec,
|
|
27
|
+
options?: { snap?: ScrollToWeekSnap },
|
|
28
|
+
) => void;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
function WeeksViewRootFn(
|
|
31
|
+
function WeeksViewRootFn(
|
|
32
|
+
props: WeeksViewRootProps,
|
|
33
|
+
ref: React.ForwardedRef<WeeksViewRootHandle>,
|
|
34
|
+
) {
|
|
23
35
|
const { children } = props;
|
|
24
|
-
const { stableCtx, stateCtx, viewCtx, scrollToWeek } =
|
|
36
|
+
const { stableCtx, stateCtx, viewCtx, scrollToWeek } =
|
|
37
|
+
useWeeksViewRootState(props);
|
|
25
38
|
|
|
26
39
|
useImperativeHandle(ref, () => ({ scrollToWeek }), [scrollToWeek]);
|
|
27
40
|
|
|
@@ -54,9 +67,9 @@ function WeeksViewRootFn(props: WeeksViewRootProps, ref: React.ForwardedRef<Week
|
|
|
54
67
|
allMonths: [],
|
|
55
68
|
currentDateTime: stateCtx.currentDateTime,
|
|
56
69
|
gridLabelIds: stateCtx.gridLabelIds,
|
|
57
|
-
rootState:
|
|
70
|
+
rootState: stateCtx.rootState,
|
|
58
71
|
}),
|
|
59
|
-
[stateCtx.currentDateTime, stateCtx.gridLabelIds],
|
|
72
|
+
[stateCtx.currentDateTime, stateCtx.gridLabelIds, stateCtx.rootState],
|
|
60
73
|
);
|
|
61
74
|
|
|
62
75
|
return (
|
|
@@ -64,7 +77,9 @@ function WeeksViewRootFn(props: WeeksViewRootProps, ref: React.ForwardedRef<Week
|
|
|
64
77
|
<MonthViewStateContext.Provider value={monthViewStateShim}>
|
|
65
78
|
<WeeksViewStableContext.Provider value={stableCtx}>
|
|
66
79
|
<WeeksViewStateContext.Provider value={stateCtx}>
|
|
67
|
-
<ViewContext.Provider value={viewCtx}>
|
|
80
|
+
<ViewContext.Provider value={viewCtx}>
|
|
81
|
+
{children}
|
|
82
|
+
</ViewContext.Provider>
|
|
68
83
|
</WeeksViewStateContext.Provider>
|
|
69
84
|
</WeeksViewStableContext.Provider>
|
|
70
85
|
</MonthViewStateContext.Provider>
|
|
@@ -78,10 +93,13 @@ const WeeksViewRoot = forwardRef(WeeksViewRootFn);
|
|
|
78
93
|
// WeeksView convenience wrapper — composes CalendarProvider + WeeksView.Root
|
|
79
94
|
// ---------------------------------------------------------------------------
|
|
80
95
|
|
|
81
|
-
type WeeksViewProps<F extends ValueFormat = "PlainDate"> =
|
|
82
|
-
WeeksViewRootProps;
|
|
96
|
+
type WeeksViewProps<F extends ValueFormat = "PlainDate"> =
|
|
97
|
+
CalendarProviderProps<F> & WeeksViewRootProps;
|
|
83
98
|
|
|
84
|
-
function WeeksViewFn(
|
|
99
|
+
function WeeksViewFn(
|
|
100
|
+
props: WeeksViewProps,
|
|
101
|
+
ref: React.ForwardedRef<WeeksViewRootHandle>,
|
|
102
|
+
) {
|
|
85
103
|
const {
|
|
86
104
|
weekCount,
|
|
87
105
|
firstWeek,
|