@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
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { render, act, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { Profiler, type ProfilerOnRenderCallback } from "react";
|
|
4
|
+
// @vitest-environment jsdom
|
|
5
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
6
|
+
import { Grid } from "./grid";
|
|
7
|
+
import { MonthView } from "./month-view";
|
|
8
|
+
|
|
9
|
+
type RenderEntry = {
|
|
10
|
+
id: string;
|
|
11
|
+
phase: "mount" | "update" | "nested-update";
|
|
12
|
+
actualDuration: number;
|
|
13
|
+
baseDuration: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function createProfiler() {
|
|
17
|
+
const entries: RenderEntry[] = [];
|
|
18
|
+
const onRender: ProfilerOnRenderCallback = (id, phase, actualDuration, baseDuration) => {
|
|
19
|
+
entries.push({
|
|
20
|
+
id,
|
|
21
|
+
phase: phase as RenderEntry["phase"],
|
|
22
|
+
actualDuration,
|
|
23
|
+
baseDuration,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return { entries, onRender };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const temporal = {
|
|
30
|
+
Now: Temporal.Now,
|
|
31
|
+
PlainDate: Temporal.PlainDate,
|
|
32
|
+
PlainDateTime: Temporal.PlainDateTime,
|
|
33
|
+
PlainMonthDay: Temporal.PlainMonthDay,
|
|
34
|
+
PlainYearMonth: Temporal.PlainYearMonth,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const defaultProps = {
|
|
38
|
+
temporal,
|
|
39
|
+
locale: "en-US",
|
|
40
|
+
timeZone: "America/New_York",
|
|
41
|
+
format: "PlainDate" as const,
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
45
|
+
const march10 = Temporal.PlainDate.from("2026-03-10");
|
|
46
|
+
const march20 = Temporal.PlainDate.from("2026-03-20");
|
|
47
|
+
|
|
48
|
+
// Generous thresholds — for comparison, not regression.
|
|
49
|
+
const CLICK_THRESHOLD_MS = 60;
|
|
50
|
+
const HOVER_THRESHOLD_MS = 40;
|
|
51
|
+
const SWEEP_THRESHOLD_MS = 200;
|
|
52
|
+
const MOUNT_THRESHOLD_MS = 100;
|
|
53
|
+
|
|
54
|
+
const ITERATIONS = 5;
|
|
55
|
+
|
|
56
|
+
function median(values: number[]): number {
|
|
57
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
58
|
+
const mid = Math.floor(sorted.length / 2);
|
|
59
|
+
return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function p95(values: number[]): number {
|
|
63
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
64
|
+
return sorted[Math.ceil(sorted.length * 0.95) - 1];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe("Grid event dispatch profiling", () => {
|
|
68
|
+
beforeAll(() => {
|
|
69
|
+
const { unmount } = render(
|
|
70
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
71
|
+
<Grid />
|
|
72
|
+
</MonthView>,
|
|
73
|
+
);
|
|
74
|
+
unmount();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("click event → selection update render cost", () => {
|
|
78
|
+
const durations: number[] = [];
|
|
79
|
+
|
|
80
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
81
|
+
const { entries, onRender } = createProfiler();
|
|
82
|
+
|
|
83
|
+
const { container, unmount } = render(
|
|
84
|
+
<Profiler id="click-event" onRender={onRender}>
|
|
85
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
86
|
+
<Grid />
|
|
87
|
+
</MonthView>
|
|
88
|
+
</Profiler>,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
entries.length = 0;
|
|
92
|
+
|
|
93
|
+
const button = container.querySelector<HTMLElement>('button[data-date="2026-03-20"]')!;
|
|
94
|
+
expect(button).toBeTruthy();
|
|
95
|
+
|
|
96
|
+
act(() => {
|
|
97
|
+
fireEvent.click(button);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const update = entries.find((e) => e.phase === "update");
|
|
101
|
+
if (update) durations.push(update.actualDuration);
|
|
102
|
+
|
|
103
|
+
unmount();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
expect(durations.length).toBeGreaterThan(0);
|
|
107
|
+
const med = median(durations);
|
|
108
|
+
const p = p95(durations);
|
|
109
|
+
expect(med).toBeLessThan(CLICK_THRESHOLD_MS);
|
|
110
|
+
|
|
111
|
+
console.log(
|
|
112
|
+
`[perf] click→selection: median=${med.toFixed(2)}ms p95=${p.toFixed(2)}ms (${ITERATIONS} runs)`,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("pointerenter event → hover preview render cost", () => {
|
|
117
|
+
const durations: number[] = [];
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
120
|
+
const { entries, onRender } = createProfiler();
|
|
121
|
+
|
|
122
|
+
const { container, unmount } = render(
|
|
123
|
+
<Profiler id="hover-event" onRender={onRender}>
|
|
124
|
+
<MonthView
|
|
125
|
+
{...defaultProps}
|
|
126
|
+
selectionMode="range"
|
|
127
|
+
value={{ start: march10, end: march20 }}
|
|
128
|
+
>
|
|
129
|
+
<Grid />
|
|
130
|
+
</MonthView>
|
|
131
|
+
</Profiler>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
entries.length = 0;
|
|
135
|
+
|
|
136
|
+
const button = container.querySelector<HTMLElement>('button[data-date="2026-03-25"]')!;
|
|
137
|
+
expect(button).toBeTruthy();
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
fireEvent.pointerEnter(button);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const update = entries.find((e) => e.phase === "update");
|
|
144
|
+
if (update) durations.push(update.actualDuration);
|
|
145
|
+
|
|
146
|
+
unmount();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
expect(durations.length).toBeGreaterThan(0);
|
|
150
|
+
const med = median(durations);
|
|
151
|
+
const p = p95(durations);
|
|
152
|
+
expect(med).toBeLessThan(HOVER_THRESHOLD_MS);
|
|
153
|
+
|
|
154
|
+
console.log(
|
|
155
|
+
`[perf] pointerenter→hover: median=${med.toFixed(2)}ms p95=${p.toFixed(2)}ms (${ITERATIONS} runs)`,
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("rapid hover across 7 cells (simulate mouse sweep)", () => {
|
|
160
|
+
const sweepDurations: number[] = [];
|
|
161
|
+
|
|
162
|
+
for (let iter = 0; iter < ITERATIONS; iter++) {
|
|
163
|
+
const { entries, onRender } = createProfiler();
|
|
164
|
+
|
|
165
|
+
const { container, unmount } = render(
|
|
166
|
+
<Profiler id="sweep-event" onRender={onRender}>
|
|
167
|
+
<MonthView
|
|
168
|
+
{...defaultProps}
|
|
169
|
+
selectionMode="range"
|
|
170
|
+
value={{ start: march10, end: march20 }}
|
|
171
|
+
>
|
|
172
|
+
<Grid />
|
|
173
|
+
</MonthView>
|
|
174
|
+
</Profiler>,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
entries.length = 0;
|
|
178
|
+
|
|
179
|
+
const days = Array.from({ length: 7 }, (_, i) => {
|
|
180
|
+
const day = String(i + 16).padStart(2, "0");
|
|
181
|
+
return container.querySelector<HTMLElement>(`button[data-date="2026-03-${day}"]`)!;
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
for (const d of days) expect(d).toBeTruthy();
|
|
185
|
+
|
|
186
|
+
act(() => {
|
|
187
|
+
for (const d of days) {
|
|
188
|
+
fireEvent.pointerEnter(d);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const updates = entries.filter((e) => e.phase === "update");
|
|
193
|
+
const total = updates.reduce((sum, e) => sum + e.actualDuration, 0);
|
|
194
|
+
sweepDurations.push(total);
|
|
195
|
+
|
|
196
|
+
unmount();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const med = median(sweepDurations);
|
|
200
|
+
const p = p95(sweepDurations);
|
|
201
|
+
expect(med).toBeLessThan(SWEEP_THRESHOLD_MS);
|
|
202
|
+
|
|
203
|
+
console.log(
|
|
204
|
+
`[perf] 7-cell sweep: median=${med.toFixed(2)}ms p95=${p.toFixed(2)}ms (${ITERATIONS} runs)`,
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("click in range mode → range update render cost", () => {
|
|
209
|
+
const durations: number[] = [];
|
|
210
|
+
|
|
211
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
212
|
+
const { entries, onRender } = createProfiler();
|
|
213
|
+
|
|
214
|
+
// Mount with a committed range, then click a day to start a new selection
|
|
215
|
+
const { container, unmount } = render(
|
|
216
|
+
<Profiler id="range-click" onRender={onRender}>
|
|
217
|
+
<MonthView
|
|
218
|
+
{...defaultProps}
|
|
219
|
+
selectionMode="range"
|
|
220
|
+
defaultValue={{ start: march10, end: march15 }}
|
|
221
|
+
>
|
|
222
|
+
<Grid />
|
|
223
|
+
</MonthView>
|
|
224
|
+
</Profiler>,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
entries.length = 0;
|
|
228
|
+
|
|
229
|
+
// Click a day outside the current range to trigger a new range selection
|
|
230
|
+
const button = container.querySelector<HTMLElement>('button[data-date="2026-03-25"]')!;
|
|
231
|
+
expect(button).toBeTruthy();
|
|
232
|
+
|
|
233
|
+
act(() => {
|
|
234
|
+
fireEvent.click(button);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const update = entries.find((e) => e.phase === "update");
|
|
238
|
+
if (update) durations.push(update.actualDuration);
|
|
239
|
+
|
|
240
|
+
unmount();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
expect(durations.length).toBeGreaterThan(0);
|
|
244
|
+
const med = median(durations);
|
|
245
|
+
const p = p95(durations);
|
|
246
|
+
expect(med).toBeLessThan(CLICK_THRESHOLD_MS);
|
|
247
|
+
|
|
248
|
+
console.log(
|
|
249
|
+
`[perf] range click→update: median=${med.toFixed(2)}ms p95=${p.toFixed(2)}ms (${ITERATIONS} runs)`,
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("mount cost: 42 cells with event listeners", () => {
|
|
254
|
+
const mountDurations: number[] = [];
|
|
255
|
+
|
|
256
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
257
|
+
const { entries, onRender } = createProfiler();
|
|
258
|
+
|
|
259
|
+
const { unmount } = render(
|
|
260
|
+
<Profiler id="mount-cost" onRender={onRender}>
|
|
261
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
262
|
+
<Grid />
|
|
263
|
+
</MonthView>
|
|
264
|
+
</Profiler>,
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const mount = entries.find((e) => e.phase === "mount");
|
|
268
|
+
if (mount) mountDurations.push(mount.actualDuration);
|
|
269
|
+
|
|
270
|
+
unmount();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
expect(mountDurations.length).toBeGreaterThan(0);
|
|
274
|
+
const med = median(mountDurations);
|
|
275
|
+
const p = p95(mountDurations);
|
|
276
|
+
expect(med).toBeLessThan(MOUNT_THRESHOLD_MS);
|
|
277
|
+
|
|
278
|
+
console.log(
|
|
279
|
+
`[perf] mount (42 cells): median=${med.toFixed(2)}ms p95=${p.toFixed(2)}ms (${ITERATIONS} runs)`,
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
});
|