@klinking/colander 0.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 +49 -0
- package/dist/formats/date.d.cts +45 -0
- package/dist/formats/date.d.mts +45 -0
- package/dist/formats/date.mjs +2 -0
- package/dist/formats/object.cjs +49 -0
- package/dist/formats/object.d.cts +45 -0
- package/dist/formats/object.d.mts +45 -0
- package/dist/formats/object.mjs +2 -0
- package/dist/formats/plain-date-time.cjs +49 -0
- package/dist/formats/plain-date-time.d.cts +45 -0
- package/dist/formats/plain-date-time.d.mts +45 -0
- package/dist/formats/plain-date-time.mjs +2 -0
- package/dist/formats/plain-date.cjs +49 -0
- package/dist/formats/plain-date.d.cts +45 -0
- package/dist/formats/plain-date.d.mts +45 -0
- package/dist/formats/plain-date.mjs +2 -0
- package/dist/formats/plain-month-day.cjs +49 -0
- package/dist/formats/plain-month-day.d.cts +45 -0
- package/dist/formats/plain-month-day.d.mts +45 -0
- package/dist/formats/plain-month-day.mjs +2 -0
- package/dist/formats/plain-year-month.cjs +49 -0
- package/dist/formats/plain-year-month.d.cts +45 -0
- package/dist/formats/plain-year-month.d.mts +45 -0
- package/dist/formats/plain-year-month.mjs +2 -0
- package/dist/formats/zoned-date-time.cjs +49 -0
- package/dist/formats/zoned-date-time.d.cts +45 -0
- package/dist/formats/zoned-date-time.d.mts +45 -0
- package/dist/formats/zoned-date-time.mjs +2 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
- package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
- package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
- package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
- package/package.json +89 -0
- package/src/calendar-context.ts +22 -0
- package/src/calendar-provider.test.tsx +123 -0
- package/src/calendar-provider.tsx +538 -0
- package/src/calendar-types.ts +212 -0
- package/src/compute-weeks-in-window.test.ts +83 -0
- package/src/compute-weeks-in-window.ts +40 -0
- package/src/context.ts +34 -0
- package/src/day-cell.tsx +635 -0
- package/src/drag-handle.tsx +137 -0
- package/src/formats/date.ts +110 -0
- package/src/formats/formats.test.ts +18 -0
- package/src/formats/object.ts +110 -0
- package/src/formats/plain-date-time.ts +110 -0
- package/src/formats/plain-date.ts +110 -0
- package/src/formats/plain-month-day.ts +110 -0
- package/src/formats/plain-year-month.ts +110 -0
- package/src/formats/zoned-date-time.ts +110 -0
- package/src/grid-header.tsx +141 -0
- package/src/grid.event-perf.test.tsx +282 -0
- package/src/grid.perf.test.tsx +467 -0
- package/src/grid.tsx +608 -0
- package/src/index.ts +116 -0
- package/src/keyboard.test.ts +498 -0
- package/src/keyboard.ts +142 -0
- package/src/month-separator.test.tsx +183 -0
- package/src/month-separator.tsx +238 -0
- package/src/month-view-context.ts +26 -0
- package/src/month-view-types.ts +89 -0
- package/src/month-view.test.tsx +1433 -0
- package/src/month-view.tsx +373 -0
- package/src/navigation.tsx +350 -0
- package/src/overflow.test.ts +124 -0
- package/src/overflow.ts +233 -0
- package/src/range-preview.tsx +90 -0
- package/src/resolve-first-week.test.ts +132 -0
- package/src/resolve-first-week.ts +145 -0
- package/src/root-selection.ts +621 -0
- package/src/selected-range.tsx +163 -0
- package/src/temporal-polyfill.test.ts +317 -0
- package/src/temporal-polyfill.ts +566 -0
- package/src/test-temporal.ts +17 -0
- package/src/types.ts +814 -0
- package/src/utils.bench.ts +183 -0
- package/src/utils.test.ts +983 -0
- package/src/utils.ts +493 -0
- package/src/view-context.ts +28 -0
- package/src/week-number.tsx +118 -0
- package/src/weeks-grid.tsx +265 -0
- package/src/weeks-keyboard.test.ts +222 -0
- package/src/weeks-keyboard.ts +156 -0
- package/src/weeks-navigation.tsx +209 -0
- package/src/weeks-view-context.ts +26 -0
- package/src/weeks-view-state.ts +421 -0
- package/src/weeks-view-types.ts +102 -0
- package/src/weeks-view.test.tsx +479 -0
- package/src/weeks-view.tsx +127 -0
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"name": "@klinking/colander",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./plain-date": {
|
|
22
|
+
"types": "./dist/formats/plain-date.d.mts",
|
|
23
|
+
"import": "./dist/formats/plain-date.mjs",
|
|
24
|
+
"require": "./dist/formats/plain-date.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./plain-date-time": {
|
|
27
|
+
"types": "./dist/formats/plain-date-time.d.mts",
|
|
28
|
+
"import": "./dist/formats/plain-date-time.mjs",
|
|
29
|
+
"require": "./dist/formats/plain-date-time.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./plain-month-day": {
|
|
32
|
+
"types": "./dist/formats/plain-month-day.d.mts",
|
|
33
|
+
"import": "./dist/formats/plain-month-day.mjs",
|
|
34
|
+
"require": "./dist/formats/plain-month-day.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./plain-year-month": {
|
|
37
|
+
"types": "./dist/formats/plain-year-month.d.mts",
|
|
38
|
+
"import": "./dist/formats/plain-year-month.mjs",
|
|
39
|
+
"require": "./dist/formats/plain-year-month.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./zoned-date-time": {
|
|
42
|
+
"types": "./dist/formats/zoned-date-time.d.mts",
|
|
43
|
+
"import": "./dist/formats/zoned-date-time.mjs",
|
|
44
|
+
"require": "./dist/formats/zoned-date-time.cjs"
|
|
45
|
+
},
|
|
46
|
+
"./object": {
|
|
47
|
+
"types": "./dist/formats/object.d.mts",
|
|
48
|
+
"import": "./dist/formats/object.mjs",
|
|
49
|
+
"require": "./dist/formats/object.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./date": {
|
|
52
|
+
"types": "./dist/formats/date.d.mts",
|
|
53
|
+
"import": "./dist/formats/date.mjs",
|
|
54
|
+
"require": "./dist/formats/date.cjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"prepublishOnly": "vp run build"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@base-ui/react": "^1.2.0",
|
|
62
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
63
|
+
"@playwright/test": "^1.58.2",
|
|
64
|
+
"@size-limit/esbuild": "^12.0.1",
|
|
65
|
+
"@size-limit/esbuild-why": "^12.0.1",
|
|
66
|
+
"@size-limit/file": "^12.0.1",
|
|
67
|
+
"@testing-library/dom": "^10.4.1",
|
|
68
|
+
"@testing-library/react": "^16.3.2",
|
|
69
|
+
"@types/react": "^19.1.0",
|
|
70
|
+
"@types/react-dom": "^19.1.0",
|
|
71
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
72
|
+
"jsdom": "^28.1.0",
|
|
73
|
+
"oxlint": "^1.58.0",
|
|
74
|
+
"react": "^19.1.0",
|
|
75
|
+
"react-dom": "^19.1.0",
|
|
76
|
+
"rollup-plugin-visualizer": "^7.0.1",
|
|
77
|
+
"size-limit": "^12.0.1",
|
|
78
|
+
"tsx": "^4.21.0",
|
|
79
|
+
"typescript": "catalog:",
|
|
80
|
+
"vite": "catalog:",
|
|
81
|
+
"vite-plus": "catalog:",
|
|
82
|
+
"vitest": "catalog:"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"@base-ui/react": ">=1.0.0",
|
|
86
|
+
"react": ">=18",
|
|
87
|
+
"react-dom": ">=18"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import type { CalendarStableContextValue, CalendarStateContextValue } from "./calendar-types";
|
|
3
|
+
|
|
4
|
+
/** @internal React context carrying stable CalendarProvider values (callbacks, config). */
|
|
5
|
+
export const CalendarStableContext = createContext<CalendarStableContextValue | null>(null);
|
|
6
|
+
|
|
7
|
+
/** @internal React context carrying volatile CalendarProvider state. */
|
|
8
|
+
export const CalendarStateContext = createContext<CalendarStateContextValue | null>(null);
|
|
9
|
+
|
|
10
|
+
/** Returns the stable (callbacks/config) part of CalendarProvider context. */
|
|
11
|
+
export function useCalendarStable(): CalendarStableContextValue {
|
|
12
|
+
const ctx = useContext(CalendarStableContext);
|
|
13
|
+
if (!ctx) throw new Error("useCalendarStable must be used within CalendarProvider");
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Returns the volatile state part of CalendarProvider context. */
|
|
18
|
+
export function useCalendarState(): CalendarStateContextValue {
|
|
19
|
+
const ctx = useContext(CalendarStateContext);
|
|
20
|
+
if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { render, act, cleanup } from "@testing-library/react";
|
|
3
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
+
import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
5
|
+
import { CalendarProvider } from "./calendar-provider";
|
|
6
|
+
|
|
7
|
+
afterEach(cleanup);
|
|
8
|
+
|
|
9
|
+
const T = Temporal;
|
|
10
|
+
|
|
11
|
+
function StableConsumer() {
|
|
12
|
+
const stable = useCalendarStable();
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<span data-testid="locale">{stable.locale}</span>
|
|
16
|
+
<span data-testid="mode">{stable.selectionMode}</span>
|
|
17
|
+
<span data-testid="disabled">{String(stable.disabled)}</span>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function StateConsumer() {
|
|
23
|
+
const state = useCalendarState();
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
<span data-testid="has-selection">{state.selected ? "yes" : "no"}</span>
|
|
27
|
+
<span data-testid="range-start">{state.rangeStart?.toString() ?? "none"}</span>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function SelectButton() {
|
|
33
|
+
const stable = useCalendarStable();
|
|
34
|
+
return (
|
|
35
|
+
<button type="button" onClick={() => stable.onSelect(T.PlainDate.from("2026-03-15"))}>
|
|
36
|
+
Select
|
|
37
|
+
</button>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("CalendarProvider", () => {
|
|
42
|
+
it("provides stable context with defaults", () => {
|
|
43
|
+
const { getByTestId } = render(
|
|
44
|
+
<CalendarProvider temporal={T}>
|
|
45
|
+
<StableConsumer />
|
|
46
|
+
</CalendarProvider>,
|
|
47
|
+
);
|
|
48
|
+
expect(getByTestId("locale").textContent).toBe("en-US");
|
|
49
|
+
expect(getByTestId("mode").textContent).toBe("single");
|
|
50
|
+
expect(getByTestId("disabled").textContent).toBe("false");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("provides state context — no selection initially", () => {
|
|
54
|
+
const { getByTestId } = render(
|
|
55
|
+
<CalendarProvider temporal={T}>
|
|
56
|
+
<StateConsumer />
|
|
57
|
+
</CalendarProvider>,
|
|
58
|
+
);
|
|
59
|
+
expect(getByTestId("has-selection").textContent).toBe("no");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("handles uncontrolled single selection", async () => {
|
|
63
|
+
const { getByTestId, getByText } = render(
|
|
64
|
+
<CalendarProvider temporal={T}>
|
|
65
|
+
<StateConsumer />
|
|
66
|
+
<SelectButton />
|
|
67
|
+
</CalendarProvider>,
|
|
68
|
+
);
|
|
69
|
+
expect(getByTestId("has-selection").textContent).toBe("no");
|
|
70
|
+
await act(async () => {
|
|
71
|
+
getByText("Select").click();
|
|
72
|
+
});
|
|
73
|
+
expect(getByTestId("has-selection").textContent).toBe("yes");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("calls onValueChange for controlled single selection", async () => {
|
|
77
|
+
const onChange = vi.fn();
|
|
78
|
+
const { getByText } = render(
|
|
79
|
+
<CalendarProvider temporal={T} selectionMode="single" value={null} onValueChange={onChange}>
|
|
80
|
+
<SelectButton />
|
|
81
|
+
</CalendarProvider>,
|
|
82
|
+
);
|
|
83
|
+
await act(async () => {
|
|
84
|
+
getByText("Select").click();
|
|
85
|
+
});
|
|
86
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("deselects when clicking an already-selected date in single mode", async () => {
|
|
90
|
+
const onChange = vi.fn();
|
|
91
|
+
const { getByTestId, getByText } = render(
|
|
92
|
+
<CalendarProvider temporal={T} selectionMode="single" onValueChange={onChange}>
|
|
93
|
+
<StateConsumer />
|
|
94
|
+
<SelectButton />
|
|
95
|
+
</CalendarProvider>,
|
|
96
|
+
);
|
|
97
|
+
// First click: select
|
|
98
|
+
await act(async () => {
|
|
99
|
+
getByText("Select").click();
|
|
100
|
+
});
|
|
101
|
+
expect(getByTestId("has-selection").textContent).toBe("yes");
|
|
102
|
+
expect(onChange).toHaveBeenLastCalledWith(
|
|
103
|
+
expect.anything(),
|
|
104
|
+
expect.objectContaining({ previous: null }),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// Second click on same date: deselect
|
|
108
|
+
await act(async () => {
|
|
109
|
+
getByText("Select").click();
|
|
110
|
+
});
|
|
111
|
+
expect(getByTestId("has-selection").textContent).toBe("no");
|
|
112
|
+
expect(onChange).toHaveBeenLastCalledWith(
|
|
113
|
+
null,
|
|
114
|
+
expect.objectContaining({ date: T.PlainDate.from("2026-03-15") }),
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("throws when hooks used outside provider", () => {
|
|
119
|
+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
120
|
+
expect(() => render(<StableConsumer />)).toThrow();
|
|
121
|
+
spy.mockRestore();
|
|
122
|
+
});
|
|
123
|
+
});
|