@klinking/colander 3.1.0-alpha.2 → 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.
Files changed (52) hide show
  1. package/dist/formats/date.cjs +1 -1
  2. package/dist/formats/date.d.cts +1 -1
  3. package/dist/formats/date.d.mts +1 -1
  4. package/dist/formats/date.mjs +1 -1
  5. package/dist/formats/object.cjs +1 -1
  6. package/dist/formats/object.d.cts +1 -1
  7. package/dist/formats/object.d.mts +1 -1
  8. package/dist/formats/object.mjs +1 -1
  9. package/dist/formats/plain-date-time.cjs +1 -1
  10. package/dist/formats/plain-date-time.d.cts +1 -1
  11. package/dist/formats/plain-date-time.d.mts +1 -1
  12. package/dist/formats/plain-date-time.mjs +1 -1
  13. package/dist/formats/plain-date.cjs +1 -1
  14. package/dist/formats/plain-date.d.cts +1 -1
  15. package/dist/formats/plain-date.d.mts +1 -1
  16. package/dist/formats/plain-date.mjs +1 -1
  17. package/dist/formats/plain-month-day.cjs +1 -1
  18. package/dist/formats/plain-month-day.d.cts +1 -1
  19. package/dist/formats/plain-month-day.d.mts +1 -1
  20. package/dist/formats/plain-month-day.mjs +1 -1
  21. package/dist/formats/plain-year-month.cjs +1 -1
  22. package/dist/formats/plain-year-month.d.cts +1 -1
  23. package/dist/formats/plain-year-month.d.mts +1 -1
  24. package/dist/formats/plain-year-month.mjs +1 -1
  25. package/dist/formats/zoned-date-time.cjs +1 -1
  26. package/dist/formats/zoned-date-time.d.cts +1 -1
  27. package/dist/formats/zoned-date-time.d.mts +1 -1
  28. package/dist/formats/zoned-date-time.mjs +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.cts +11 -2
  31. package/dist/index.d.mts +11 -2
  32. package/dist/index.mjs +1 -1
  33. package/dist/{weeks-navigation-CXRaVP02.mjs → weeks-navigation-DEaASUAh.mjs} +83 -107
  34. package/dist/{weeks-navigation-BRxzsy0z.cjs → weeks-navigation-DvryOSWF.cjs} +83 -107
  35. package/dist/{index-CJgr0MEp.d.cts → weeks-view-context-CNAq2Hiu.d.cts} +1 -8
  36. package/dist/{index-DB6V_Y6x.d.mts → weeks-view-context-CsP3PBiu.d.mts} +1 -8
  37. package/package.json +1 -1
  38. package/src/day-cell.tsx +9 -15
  39. package/src/drag-handle.tsx +2 -2
  40. package/src/grid-header.tsx +3 -3
  41. package/src/grid.tsx +20 -61
  42. package/src/month-view.tsx +25 -2
  43. package/src/navigation.tsx +3 -2
  44. package/src/range-preview.tsx +3 -5
  45. package/src/selected-range.tsx +3 -5
  46. package/src/view-context.test.tsx +126 -0
  47. package/src/view-context.ts +43 -0
  48. package/src/week-number.tsx +3 -3
  49. package/src/weeks-navigation.tsx +3 -3
  50. package/src/weeks-view-state.ts +23 -2
  51. package/src/weeks-view.test.tsx +115 -13
  52. package/src/weeks-view.tsx +22 -51
@@ -1,5 +1,12 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { render, screen, act, cleanup, within } from "@testing-library/react";
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 shim is populated", () => {
542
- function ShimRootStateCapture({
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 } = useMonthViewState();
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 useMonthViewState()", () => {
555
- let root: ReturnType<typeof useMonthViewState>["rootState"] | undefined;
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
- <ShimRootStateCapture
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 into the shim.
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
+ });
@@ -1,14 +1,13 @@
1
- import type { Temporal } from "@js-temporal/polyfill";
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 { ViewContext } from "./view-context";
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 { stableCtx, stateCtx, viewCtx, scrollToWeek } =
37
- useWeeksViewRootState(props);
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
- <MonthViewStableContext.Provider value={monthViewStableShim}>
77
- <MonthViewStateContext.Provider value={monthViewStateShim}>
78
- <WeeksViewStableContext.Provider value={stableCtx}>
79
- <WeeksViewStateContext.Provider value={stateCtx}>
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
- </WeeksViewStateContext.Provider>
84
- </WeeksViewStableContext.Provider>
85
- </MonthViewStateContext.Provider>
86
- </MonthViewStableContext.Provider>
54
+ </ViewStateContext.Provider>
55
+ </ViewStableContext.Provider>
56
+ </WeeksViewStateContext.Provider>
57
+ </WeeksViewStableContext.Provider>
87
58
  );
88
59
  }
89
60