@klinking/colander 3.1.0-alpha.1 → 3.1.0-alpha.3
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 +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-Bg0nZLgh.mjs → weeks-navigation-DEaASUAh.mjs} +125 -120
- package/dist/{weeks-navigation-CJzhxbgj.cjs → weeks-navigation-DvryOSWF.cjs} +125 -120
- package/package.json +1 -1
- package/src/calendar-provider.test.tsx +87 -0
- package/src/calendar-provider.tsx +65 -16
- package/src/day-cell.tsx +9 -15
- package/src/drag-handle.tsx +2 -2
- package/src/grid-header.tsx +3 -3
- package/src/grid.tsx +20 -61
- package/src/month-view.tsx +25 -2
- package/src/navigation.tsx +3 -2
- package/src/range-preview.tsx +3 -5
- package/src/selected-range.tsx +3 -5
- package/src/view-context.test.tsx +126 -0
- package/src/view-context.ts +43 -0
- package/src/week-number.tsx +3 -3
- package/src/weeks-navigation.tsx +3 -3
- package/src/weeks-view-state.ts +23 -2
- package/src/weeks-view.test.tsx +115 -13
- package/src/weeks-view.tsx +22 -51
package/src/weeks-view-state.ts
CHANGED
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
} from "./resolve-first-week";
|
|
11
11
|
import type { RootState } from "./types";
|
|
12
12
|
import { selectedToZdt, toZonedDateTime } from "./utils";
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
ViewContextValue,
|
|
15
|
+
ViewStableContextValue,
|
|
16
|
+
ViewStateContextValue,
|
|
17
|
+
} from "./view-context";
|
|
14
18
|
import type {
|
|
15
19
|
WeeksViewRootProps,
|
|
16
20
|
WeeksViewStableContextValue,
|
|
@@ -491,5 +495,22 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
|
|
|
491
495
|
[focusedDate, tabTargetDate, gridHasFocus],
|
|
492
496
|
);
|
|
493
497
|
|
|
494
|
-
|
|
498
|
+
const viewStableCtx = useMemo<ViewStableContextValue>(
|
|
499
|
+
() => ({ gridFocusedRef, outsideDays: "enabled" }),
|
|
500
|
+
[],
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const viewStateCtx = useMemo<ViewStateContextValue>(
|
|
504
|
+
() => ({ currentDateTime, rootState }),
|
|
505
|
+
[currentDateTime, rootState],
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
return {
|
|
509
|
+
stableCtx,
|
|
510
|
+
stateCtx,
|
|
511
|
+
viewCtx,
|
|
512
|
+
viewStableCtx,
|
|
513
|
+
viewStateCtx,
|
|
514
|
+
scrollToWeek,
|
|
515
|
+
};
|
|
495
516
|
}
|
package/src/weeks-view.test.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
render,
|
|
4
|
+
screen,
|
|
5
|
+
act,
|
|
6
|
+
cleanup,
|
|
7
|
+
fireEvent,
|
|
8
|
+
within,
|
|
9
|
+
} from "@testing-library/react";
|
|
3
10
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
4
11
|
import {
|
|
5
12
|
Grid,
|
|
@@ -16,7 +23,7 @@ import {
|
|
|
16
23
|
MonthSeparatorWeekCount,
|
|
17
24
|
} from "./month-separator";
|
|
18
25
|
import { useMonthViewState } from "./month-view-context";
|
|
19
|
-
import { useViewContext } from "./view-context";
|
|
26
|
+
import { useViewContext, useViewState } from "./view-context";
|
|
20
27
|
import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation";
|
|
21
28
|
import { WeeksView } from "./weeks-view";
|
|
22
29
|
import { useWeeksViewState, useWeeksViewStable } from "./weeks-view-context";
|
|
@@ -538,21 +545,19 @@ describe("WeeksView regression: goNext/goPrev shift by weekCount (Bug #3)", () =
|
|
|
538
545
|
});
|
|
539
546
|
});
|
|
540
547
|
|
|
541
|
-
describe("WeeksView regression: rootState
|
|
542
|
-
function
|
|
548
|
+
describe("WeeksView regression: rootState is populated", () => {
|
|
549
|
+
function RootStateCapture({
|
|
543
550
|
onCapture,
|
|
544
551
|
}: {
|
|
545
|
-
onCapture: (
|
|
546
|
-
root: ReturnType<typeof useMonthViewState>["rootState"],
|
|
547
|
-
) => void;
|
|
552
|
+
onCapture: (root: ReturnType<typeof useViewState>["rootState"]) => void;
|
|
548
553
|
}) {
|
|
549
|
-
const { rootState } =
|
|
554
|
+
const { rootState } = useViewState();
|
|
550
555
|
onCapture(rootState);
|
|
551
556
|
return null;
|
|
552
557
|
}
|
|
553
558
|
|
|
554
|
-
it("exposes a real rootState to components reading
|
|
555
|
-
let root: ReturnType<typeof
|
|
559
|
+
it("exposes a real rootState to components reading useViewState()", () => {
|
|
560
|
+
let root: ReturnType<typeof useViewState>["rootState"] | undefined;
|
|
556
561
|
render(
|
|
557
562
|
<WeeksView
|
|
558
563
|
temporal={T}
|
|
@@ -560,7 +565,7 @@ describe("WeeksView regression: rootState shim is populated", () => {
|
|
|
560
565
|
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
561
566
|
defaultValue={T.PlainDate.from("2026-03-15")}
|
|
562
567
|
>
|
|
563
|
-
<
|
|
568
|
+
<RootStateCapture
|
|
564
569
|
onCapture={(r) => {
|
|
565
570
|
root = r;
|
|
566
571
|
}}
|
|
@@ -568,7 +573,6 @@ describe("WeeksView regression: rootState shim is populated", () => {
|
|
|
568
573
|
</WeeksView>,
|
|
569
574
|
);
|
|
570
575
|
|
|
571
|
-
// Pre-fix this shim was `{} as RootState` — every field undefined at runtime.
|
|
572
576
|
expect(root).toBeDefined();
|
|
573
577
|
expect(root!.viewing).toBeInstanceOf(Temporal.PlainYearMonth);
|
|
574
578
|
expect(root!.focused).toBeInstanceOf(Temporal.PlainDate);
|
|
@@ -576,7 +580,7 @@ describe("WeeksView regression: rootState shim is populated", () => {
|
|
|
576
580
|
expect(root!.timeZone.length).toBeGreaterThan(0);
|
|
577
581
|
expect(typeof root!.locale).toBe("string");
|
|
578
582
|
expect(typeof root!.readOnly).toBe("boolean");
|
|
579
|
-
// Selection flows through the shared baseRootState
|
|
583
|
+
// Selection flows through the shared baseRootState.
|
|
580
584
|
expect(root!.hasSelection).toBe(true);
|
|
581
585
|
expect(root!.selected).toBeInstanceOf(Temporal.PlainDate);
|
|
582
586
|
expect(root!.selected!.toString()).toBe("2026-03-15");
|
|
@@ -585,3 +589,101 @@ describe("WeeksView regression: rootState shim is populated", () => {
|
|
|
585
589
|
).toBe(true);
|
|
586
590
|
});
|
|
587
591
|
});
|
|
592
|
+
|
|
593
|
+
describe("WeeksView does not provide MonthView contexts", () => {
|
|
594
|
+
function MonthStateProbe() {
|
|
595
|
+
useMonthViewState();
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
it("useMonthViewState throws instead of returning placeholder values", () => {
|
|
600
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
601
|
+
expect(() =>
|
|
602
|
+
render(
|
|
603
|
+
<WeeksView temporal={T} weekCount={4}>
|
|
604
|
+
<MonthStateProbe />
|
|
605
|
+
</WeeksView>,
|
|
606
|
+
),
|
|
607
|
+
).toThrow();
|
|
608
|
+
error.mockRestore();
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
describe("WeeksView: Grid renders the weeks grid shell", () => {
|
|
613
|
+
function renderWeeksGrid() {
|
|
614
|
+
return render(
|
|
615
|
+
<WeeksView
|
|
616
|
+
temporal={T}
|
|
617
|
+
weekCount={4}
|
|
618
|
+
defaultFirstWeek={T.PlainDate.from("2026-03-01")}
|
|
619
|
+
defaultValue={T.PlainDate.from("2026-03-15")}
|
|
620
|
+
>
|
|
621
|
+
<FocusDisplay />
|
|
622
|
+
<WindowDisplay />
|
|
623
|
+
<Grid>
|
|
624
|
+
<GridBody>
|
|
625
|
+
<WeekTemplate>
|
|
626
|
+
<DayCellTemplate>
|
|
627
|
+
<DayButton />
|
|
628
|
+
</DayCellTemplate>
|
|
629
|
+
</WeekTemplate>
|
|
630
|
+
</GridBody>
|
|
631
|
+
</Grid>
|
|
632
|
+
</WeeksView>,
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
it("reports the window's week count on the grid", () => {
|
|
637
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
638
|
+
renderWeeksGrid();
|
|
639
|
+
|
|
640
|
+
const grid = screen.getByRole("grid");
|
|
641
|
+
expect(grid.getAttribute("data-weeks-in-month")).toBe("4");
|
|
642
|
+
expect(grid.style.getPropertyValue("--calendar-weeks-in-month")).toBe("4");
|
|
643
|
+
expect(warn).not.toHaveBeenCalled();
|
|
644
|
+
warn.mockRestore();
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it.each([
|
|
648
|
+
{
|
|
649
|
+
description: "PageDown moves focus by weekCount weeks",
|
|
650
|
+
key: "PageDown",
|
|
651
|
+
shiftKey: false,
|
|
652
|
+
expected: { focus: "2026-04-12" },
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
description: "Shift+PageDown moves focus by a year",
|
|
656
|
+
key: "PageDown",
|
|
657
|
+
shiftKey: true,
|
|
658
|
+
expected: { focus: "2027-03-15" },
|
|
659
|
+
},
|
|
660
|
+
])("$description", ({ key, shiftKey, expected }) => {
|
|
661
|
+
renderWeeksGrid();
|
|
662
|
+
|
|
663
|
+
fireEvent.keyDown(screen.getByRole("grid"), { key, shiftKey });
|
|
664
|
+
|
|
665
|
+
expect(screen.getByTestId("focus").textContent).toBe(expected.focus);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it("moves DOM focus to the newly focused day after an arrow key", () => {
|
|
669
|
+
renderWeeksGrid();
|
|
670
|
+
const start = screen.getByRole("button", { name: /15/ });
|
|
671
|
+
act(() => start.focus());
|
|
672
|
+
|
|
673
|
+
fireEvent.keyDown(start, { key: "ArrowRight" });
|
|
674
|
+
|
|
675
|
+
expect(screen.getByTestId("focus").textContent).toBe("2026-03-16");
|
|
676
|
+
expect(document.activeElement).toBe(
|
|
677
|
+
screen.getByRole("button", { name: /16/ }),
|
|
678
|
+
);
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
it("End moves focus to the last day of the window and keeps the window", () => {
|
|
682
|
+
renderWeeksGrid();
|
|
683
|
+
|
|
684
|
+
fireEvent.keyDown(screen.getByRole("grid"), { key: "End" });
|
|
685
|
+
|
|
686
|
+
expect(screen.getByTestId("focus").textContent).toBe("2026-03-28");
|
|
687
|
+
expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
|
|
688
|
+
});
|
|
689
|
+
});
|
package/src/weeks-view.tsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
|
|
1
|
+
import React, { forwardRef, useImperativeHandle } from "react";
|
|
3
2
|
import { CalendarProvider } from "./calendar-provider";
|
|
4
3
|
import type { CalendarProviderProps } from "./calendar-types";
|
|
5
|
-
import {
|
|
6
|
-
MonthViewStableContext,
|
|
7
|
-
MonthViewStateContext,
|
|
8
|
-
} from "./month-view-context";
|
|
9
4
|
import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
|
|
10
5
|
import type { ValueFormat } from "./types";
|
|
11
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ViewContext,
|
|
8
|
+
ViewStableContext,
|
|
9
|
+
ViewStateContext,
|
|
10
|
+
} from "./view-context";
|
|
12
11
|
import {
|
|
13
12
|
WeeksViewStableContext,
|
|
14
13
|
WeeksViewStateContext,
|
|
@@ -33,57 +32,29 @@ function WeeksViewRootFn(
|
|
|
33
32
|
ref: React.ForwardedRef<WeeksViewRootHandle>,
|
|
34
33
|
) {
|
|
35
34
|
const { children } = props;
|
|
36
|
-
const {
|
|
37
|
-
|
|
35
|
+
const {
|
|
36
|
+
stableCtx,
|
|
37
|
+
stateCtx,
|
|
38
|
+
viewCtx,
|
|
39
|
+
viewStableCtx,
|
|
40
|
+
viewStateCtx,
|
|
41
|
+
scrollToWeek,
|
|
42
|
+
} = useWeeksViewRootState(props);
|
|
38
43
|
|
|
39
44
|
useImperativeHandle(ref, () => ({ scrollToWeek }), [scrollToWeek]);
|
|
40
45
|
|
|
41
|
-
const gridFocusedRef = useRef(false);
|
|
42
|
-
|
|
43
|
-
// Provide MonthViewStableContext/MonthViewStateContext shims so shared
|
|
44
|
-
// components (WeeksNavButton, WeekCount, etc.) that read rootState via
|
|
45
|
-
// useMonthViewState() can function outside the Grid in WeeksView.
|
|
46
|
-
const monthViewStableShim = useMemo(
|
|
47
|
-
() => ({
|
|
48
|
-
numberOfMonths: 1,
|
|
49
|
-
fixedWeeks: false,
|
|
50
|
-
outsideDays: "enabled" as const,
|
|
51
|
-
outOfRangeBehavior: "unbounded" as const,
|
|
52
|
-
goNextMonth: () => {},
|
|
53
|
-
goPrevMonth: () => {},
|
|
54
|
-
setGridLabelId: () => {},
|
|
55
|
-
gridFocusedRef,
|
|
56
|
-
}),
|
|
57
|
-
[],
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const monthViewStateShim = useMemo(
|
|
61
|
-
() => ({
|
|
62
|
-
currentMonth: {
|
|
63
|
-
year: stateCtx.currentDateTime.year,
|
|
64
|
-
month: stateCtx.currentDateTime.month,
|
|
65
|
-
},
|
|
66
|
-
weeks: [] as Temporal.PlainDate[][],
|
|
67
|
-
allMonths: [],
|
|
68
|
-
currentDateTime: stateCtx.currentDateTime,
|
|
69
|
-
gridLabelIds: stateCtx.gridLabelIds,
|
|
70
|
-
rootState: stateCtx.rootState,
|
|
71
|
-
}),
|
|
72
|
-
[stateCtx.currentDateTime, stateCtx.gridLabelIds, stateCtx.rootState],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
46
|
return (
|
|
76
|
-
<
|
|
77
|
-
<
|
|
78
|
-
<
|
|
79
|
-
<
|
|
47
|
+
<WeeksViewStableContext.Provider value={stableCtx}>
|
|
48
|
+
<WeeksViewStateContext.Provider value={stateCtx}>
|
|
49
|
+
<ViewStableContext.Provider value={viewStableCtx}>
|
|
50
|
+
<ViewStateContext.Provider value={viewStateCtx}>
|
|
80
51
|
<ViewContext.Provider value={viewCtx}>
|
|
81
52
|
{children}
|
|
82
53
|
</ViewContext.Provider>
|
|
83
|
-
</
|
|
84
|
-
</
|
|
85
|
-
</
|
|
86
|
-
</
|
|
54
|
+
</ViewStateContext.Provider>
|
|
55
|
+
</ViewStableContext.Provider>
|
|
56
|
+
</WeeksViewStateContext.Provider>
|
|
57
|
+
</WeeksViewStableContext.Provider>
|
|
87
58
|
);
|
|
88
59
|
}
|
|
89
60
|
|