@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.
Files changed (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. 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
+ });