@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klinking/colander",
3
- "version": "3.1.0-alpha.6",
3
+ "version": "3.1.0-alpha.8",
4
4
  "homepage": "https://github.com/klink-ing/colander#readme",
5
5
  "bugs": "https://github.com/klink-ing/colander/issues",
6
6
  "license": "MIT",
@@ -127,24 +127,23 @@
127
127
  }
128
128
  },
129
129
  "devDependencies": {
130
- "@base-ui/react": "^1.3.0",
130
+ "@base-ui/react": "^1.9.0",
131
131
  "@js-temporal/polyfill": "^0.5.1",
132
- "@playwright/test": "^1.58.2",
133
- "@testing-library/dom": "^10.4.1",
134
- "@testing-library/react": "^16.3.2",
135
- "@types/react": "^19.2.0",
136
- "@types/react-dom": "^19.2.0",
137
- "@vitejs/plugin-react": "^4.7.0",
138
- "jsdom": "^28.1.0",
139
- "oxlint": "^1.58.0",
140
- "react": "^19.2.0",
141
- "react-dom": "^19.2.0",
142
- "rollup-plugin-visualizer": "^7.0.1",
143
- "tsx": "^4.21.0",
144
- "typescript": "^5",
145
- "vite": "npm:@voidzero-dev/vite-plus-core@^0.1.16",
146
- "vite-plus": "latest",
147
- "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
132
+ "@playwright/test": "^1.65.2",
133
+ "@testing-library/dom": "^10.4.2",
134
+ "@testing-library/react": "^16.3.3",
135
+ "@types/react": "^19.3.3",
136
+ "@types/react-dom": "^19.3.0",
137
+ "@vitejs/plugin-react": "^6.3.0",
138
+ "jsdom": "^31.0.1",
139
+ "react": "^19.3.1",
140
+ "react-dom": "^19.3.1",
141
+ "rollup-plugin-visualizer": "^7.3.0",
142
+ "ts-morph": "^28.0.0",
143
+ "tsx": "^4.23.15",
144
+ "typescript": "^7.0.2",
145
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
146
+ "vite-plus": "1.8.0"
148
147
  },
149
148
  "peerDependencies": {
150
149
  "@base-ui/react": ">=1.0.0",
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render, act, cleanup } from "@testing-library/react";
3
3
  import type { ComponentProps } from "react";
4
- import { describe, it, expect, vi, afterEach } from "vitest";
4
+ import { describe, it, expect, vi, afterEach } from "vite-plus/test";
5
5
  import { useCalendarStable, useCalendarState } from "./calendar-context";
6
6
  import { CalendarProvider } from "./calendar-provider";
7
7
 
@@ -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 { computeWeeksInWindow } from "./compute-weeks-in-window";
4
4
 
5
5
  const T = Temporal;
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { describe, expect, it } from "vitest";
2
+ import { describe, expect, it } from "vite-plus/test";
3
3
  import { computeDayCellState, dayCellStateEqual } from "./day-cell-state";
4
4
  import type { DayCellInputs } from "./day-cell-state";
5
5
  import type { OutsideDays } from "./types";
@@ -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 {
4
4
  dayCellInstancePropsAreEqual,
5
5
  dayButtonInnerPropsAreEqual,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="vite/client" />
2
2
  import * as root from "@klinking/colander";
3
- import { describe, it, expect } from "vitest";
3
+ import { describe, it, expect } from "vite-plus/test";
4
4
 
5
5
  const formatModules = import.meta.glob<Record<string, unknown>>(
6
6
  ["./*.ts", "!./*.test.ts"],
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render, act, fireEvent } from "@testing-library/react";
3
3
  import { Profiler, type ProfilerOnRenderCallback } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, beforeAll, type TestOptions } from "vitest";
5
+ import {
6
+ describe,
7
+ it,
8
+ expect,
9
+ beforeAll,
10
+ type TestOptions,
11
+ } from "vite-plus/test";
6
12
 
7
13
  const perfOptions: TestOptions = { retry: 3 };
8
14
  import { Grid } from "./grid";
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render } from "@testing-library/react";
3
3
  import { Profiler, type ProfilerOnRenderCallback } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, beforeAll, type TestOptions } from "vitest";
5
+ import {
6
+ describe,
7
+ it,
8
+ expect,
9
+ beforeAll,
10
+ type TestOptions,
11
+ } from "vite-plus/test";
6
12
 
7
13
  const perfOptions: TestOptions = { retry: 3 };
8
14
  import { WeekDataContext } from "./context";
package/src/grid.tsx CHANGED
@@ -109,7 +109,7 @@ function useWeeksGridKeyboard() {
109
109
  shiftKey: e.shiftKey,
110
110
  focusedDate,
111
111
  windowStart: weeksState.windowInfo.windowStart,
112
- weekCount: weeksStable.weekCount,
112
+ weekCount: weeksState.windowInfo.weekCount,
113
113
  minValue,
114
114
  maxValue,
115
115
  disabled,
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from "vitest";
1
+ import { describe, it, expect } from "vite-plus/test";
2
2
  import { computeNextFocusDate, computeMonthJumpTarget } from "./keyboard";
3
3
  import type { KeyboardNavInput } from "./keyboard";
4
4
  import { temporalVariants } from "./test-temporal";
@@ -1,5 +1,5 @@
1
1
  import { render, cleanup, within } from "@testing-library/react";
2
- import { describe, it, expect, afterEach } from "vitest";
2
+ import { describe, it, expect, afterEach } from "vite-plus/test";
3
3
  import {
4
4
  MonthSeparator,
5
5
  MonthSeparatorMonth,
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { act, cleanup, render, screen } from "@testing-library/react";
3
- import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
4
  import { MonthView } from "./month-view";
5
5
  import type { MonthViewProps } from "./month-view";
6
6
  import { useMonthViewStable, useMonthViewState } from "./month-view-context";
@@ -2,7 +2,7 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render, act } from "@testing-library/react";
3
3
  import { useState } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, vi } from "vitest";
5
+ import { describe, it, expect, vi } from "vite-plus/test";
6
6
  import { useCalendarStable } from "./calendar-context";
7
7
  import { Grid } from "./grid";
8
8
  import { MonthView } from "./month-view";
@@ -2092,3 +2092,91 @@ describe("outsideDays", () => {
2092
2092
  });
2093
2093
  });
2094
2094
  });
2095
+
2096
+ describe("opening month", () => {
2097
+ // 2020 dates keep the real today out of every window under test.
2098
+ const ym = (s: string) => Temporal.PlainYearMonth.from(s);
2099
+ const day = (s: string) => Temporal.PlainDate.from(s);
2100
+
2101
+ it.each([
2102
+ {
2103
+ description: "defaultMonth opens on that month, not today's",
2104
+ props: { defaultMonth: ym("2020-03") },
2105
+ keys: [],
2106
+ expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
2107
+ },
2108
+ {
2109
+ description: "defaultMonth opens on that month in range mode",
2110
+ props: { selectionMode: "range", defaultMonth: ym("2020-03") },
2111
+ keys: [],
2112
+ expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
2113
+ },
2114
+ {
2115
+ description: "defaultMonth wins over a defaultValue outside it",
2116
+ props: { defaultMonth: ym("2020-03"), defaultValue: day("2020-05-15") },
2117
+ keys: [],
2118
+ expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
2119
+ },
2120
+ {
2121
+ description: "a defaultValue inside a multi-month window keeps focus",
2122
+ props: {
2123
+ defaultMonth: ym("2020-03"),
2124
+ defaultValue: day("2020-04-15"),
2125
+ numberOfMonths: 2,
2126
+ },
2127
+ keys: [],
2128
+ expected: {
2129
+ months: ["2020-03", "2020-04"],
2130
+ focused: "2020-04-15",
2131
+ monthChanges: 0,
2132
+ },
2133
+ },
2134
+ {
2135
+ description: "the first arrow key after defaultMonth moves within it",
2136
+ props: { defaultMonth: ym("2020-03") },
2137
+ keys: ["ArrowRight"],
2138
+ expected: { months: ["2020-03"], focused: "2020-03-02", monthChanges: 0 },
2139
+ },
2140
+ {
2141
+ description: "the first arrow key in a controlled month moves within it",
2142
+ props: { month: ym("2020-03") },
2143
+ keys: ["ArrowRight"],
2144
+ expected: { months: ["2020-03"], focused: "2020-03-02", monthChanges: 0 },
2145
+ },
2146
+ ])("$description", ({ props, keys, expected }) => {
2147
+ const onMonthChange = vi.fn();
2148
+ let captured: { months: string[]; focused: string } | undefined;
2149
+ const { container } = render(
2150
+ <MonthView
2151
+ {...defaultProps}
2152
+ {...(props as object)}
2153
+ onMonthChange={onMonthChange}
2154
+ >
2155
+ <Grid />
2156
+ <MonthDataCapture
2157
+ onCapture={(d) => {
2158
+ captured = {
2159
+ months: d.allMonths.map((m) =>
2160
+ Temporal.PlainYearMonth.from(m).toString(),
2161
+ ),
2162
+ focused: d.focusedDate,
2163
+ };
2164
+ }}
2165
+ />
2166
+ </MonthView>,
2167
+ );
2168
+ const grid = container.querySelector('[role="grid"]')!;
2169
+ for (const key of keys) {
2170
+ act(() => {
2171
+ grid.dispatchEvent(
2172
+ new KeyboardEvent("keydown", { key, bubbles: true }),
2173
+ );
2174
+ });
2175
+ }
2176
+
2177
+ expect({
2178
+ ...captured,
2179
+ monthChanges: onMonthChange.mock.calls.length,
2180
+ }).toEqual(expected);
2181
+ });
2182
+ });
@@ -58,11 +58,6 @@ function MonthViewRoot(props: MonthViewRootProps) {
58
58
  const T = calStable.temporal;
59
59
  const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
60
60
 
61
- // --- Focus state ---
62
- const [focusedDate, setFocusedDate] = useState<Temporal.PlainDate>(() =>
63
- resolveInitialAnchor(calState.selected, today, timeZone, T),
64
- );
65
-
66
61
  const [gridHasFocus, setGridHasFocus] = useState(false);
67
62
  const gridFocusedRef = useRef(false);
68
63
 
@@ -80,6 +75,20 @@ function MonthViewRoot(props: MonthViewRootProps) {
80
75
  [numberOfMonths, outOfRangeBehavior, minValue, maxValue, T],
81
76
  );
82
77
 
78
+ // --- Focus state ---
79
+ // Focus starts inside the window the view opens on. Arrow keys move from
80
+ // the focused date, so focus outside the window would pull the view to it.
81
+ const [focusedDate, setFocusedDate] = useState<Temporal.PlainDate>(() => {
82
+ const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
83
+ const opening = monthProp ?? defaultMonthProp;
84
+ if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
85
+ return T.PlainDate.from({
86
+ year: opening.year,
87
+ month: opening.month,
88
+ day: 1,
89
+ });
90
+ });
91
+
83
92
  const initialAnchor = useCallback(
84
93
  () => resolveInitialAnchor(calState.selected, today, timeZone, T),
85
94
  [calState.selected, today, timeZone, T],
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { describe, expect, it } from "vitest";
2
+ import { describe, expect, it } from "vite-plus/test";
3
3
  import { createMonthWindowPolicy } from "./month-window";
4
4
  import type { MonthWindowPolicyInput } from "./month-window";
5
5
 
@@ -1,10 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { describe, it, expect } from "vitest";
3
- import {
4
- applyOutOfRange,
5
- canShift,
6
- type OutOfRangeBehavior,
7
- } from "./out-of-range";
2
+ import { describe, it, expect } from "vite-plus/test";
3
+ import { applyOutOfRange, type OutOfRangeBehavior } from "./out-of-range";
8
4
 
9
5
  const T = Temporal;
10
6
  const pd = (s: string) => T.PlainDate.from(s);
@@ -19,7 +15,7 @@ describe("applyOutOfRange", () => {
19
15
  targetFirstWeek: pd("2026-02-01"),
20
16
  weekCount: 8,
21
17
  behavior: "unbounded" as OutOfRangeBehavior,
22
- useMinMax: true,
18
+ useMinMax: "both" as const,
23
19
  expected: { firstWeek: "2026-02-01", weekCount: 8 },
24
20
  },
25
21
  {
@@ -27,7 +23,7 @@ describe("applyOutOfRange", () => {
27
23
  targetFirstWeek: pd("2025-12-07"),
28
24
  weekCount: 8,
29
25
  behavior: "stop" as OutOfRangeBehavior,
30
- useMinMax: true,
26
+ useMinMax: "both" as const,
31
27
  expected: { firstWeek: "2025-12-07", weekCount: 8 },
32
28
  },
33
29
  {
@@ -35,7 +31,7 @@ describe("applyOutOfRange", () => {
35
31
  targetFirstWeek: pd("2026-01-11"),
36
32
  weekCount: 8,
37
33
  behavior: "snap" as OutOfRangeBehavior,
38
- useMinMax: true,
34
+ useMinMax: "both" as const,
39
35
  expected: {
40
36
  firstWeek: "2025-11-16",
41
37
  weekCount: 8,
@@ -46,7 +42,7 @@ describe("applyOutOfRange", () => {
46
42
  targetFirstWeek: pd("2026-01-11"),
47
43
  weekCount: 8,
48
44
  behavior: "snap-shrink" as OutOfRangeBehavior,
49
- useMinMax: true,
45
+ useMinMax: "both" as const,
50
46
  expected: {
51
47
  firstWeek: "2025-11-30",
52
48
  weekCount: 6,
@@ -57,18 +53,42 @@ describe("applyOutOfRange", () => {
57
53
  targetFirstWeek: pd("2025-12-07"),
58
54
  weekCount: 8,
59
55
  behavior: "stop-shrink" as OutOfRangeBehavior,
60
- useMinMax: true,
56
+ useMinMax: "both" as const,
61
57
  expected: {
62
58
  firstWeek: "2025-12-07",
63
59
  weekCount: 5,
64
60
  },
65
61
  },
62
+ {
63
+ description: "max only, snap — pulls back when target overshoots max",
64
+ targetFirstWeek: pd("2026-01-11"),
65
+ weekCount: 8,
66
+ behavior: "snap" as OutOfRangeBehavior,
67
+ useMinMax: "max" as const,
68
+ expected: { firstWeek: "2025-11-16", weekCount: 8 },
69
+ },
70
+ {
71
+ description: "min only, snap — pulls forward when target undershoots min",
72
+ targetFirstWeek: pd("2025-10-01"),
73
+ weekCount: 8,
74
+ behavior: "snap" as OutOfRangeBehavior,
75
+ useMinMax: "min" as const,
76
+ expected: { firstWeek: "2025-11-30", weekCount: 8 },
77
+ },
78
+ {
79
+ description: "min only, stop-shrink — trims leading disabled rows",
80
+ targetFirstWeek: pd("2025-11-16"),
81
+ weekCount: 8,
82
+ behavior: "stop-shrink" as OutOfRangeBehavior,
83
+ useMinMax: "min" as const,
84
+ expected: { firstWeek: "2025-11-30", weekCount: 6 },
85
+ },
66
86
  {
67
87
  description: "no min/max — all modes behave as unbounded",
68
88
  targetFirstWeek: pd("2026-06-01"),
69
89
  weekCount: 8,
70
90
  behavior: "snap" as OutOfRangeBehavior,
71
- useMinMax: false,
91
+ useMinMax: "none" as const,
72
92
  expected: { firstWeek: "2026-06-01", weekCount: 8 },
73
93
  },
74
94
  ])(
@@ -78,7 +98,8 @@ describe("applyOutOfRange", () => {
78
98
  targetFirstWeek,
79
99
  weekCount,
80
100
  behavior,
81
- ...(useMinMax && { min, max }),
101
+ ...((useMinMax === "both" || useMinMax === "min") && { min }),
102
+ ...((useMinMax === "both" || useMinMax === "max") && { max }),
82
103
  weekStartDay: 0,
83
104
  T,
84
105
  });
@@ -87,44 +108,3 @@ describe("applyOutOfRange", () => {
87
108
  },
88
109
  );
89
110
  });
90
-
91
- describe("canShift", () => {
92
- const min = pd("2025-12-01");
93
- const max = pd("2026-01-10");
94
-
95
- it.each([
96
- {
97
- description: "unbounded — always true",
98
- behavior: "unbounded" as OutOfRangeBehavior,
99
- currentFirstWeek: pd("2026-06-01"),
100
- direction: 1 as const,
101
- expected: true,
102
- },
103
- {
104
- description: "stop — false when target has no valid weeks",
105
- behavior: "stop" as OutOfRangeBehavior,
106
- currentFirstWeek: pd("2025-12-28"),
107
- direction: 1 as const,
108
- expected: false,
109
- },
110
- {
111
- description: "snap — false when already at clamp position",
112
- behavior: "snap" as OutOfRangeBehavior,
113
- currentFirstWeek: pd("2025-11-16"),
114
- direction: 1 as const,
115
- expected: false,
116
- },
117
- ])("$description", ({ behavior, currentFirstWeek, direction, expected }) => {
118
- const result = canShift({
119
- currentFirstWeek,
120
- weekCount: 8,
121
- direction,
122
- behavior,
123
- min,
124
- max,
125
- weekStartDay: 0,
126
- T,
127
- });
128
- expect(result).toBe(expected);
129
- });
130
- });