@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,183 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { bench, describe } from "vitest";
|
|
3
|
+
import type { TemporalNamespace } from "./types";
|
|
4
|
+
import {
|
|
5
|
+
getMonthWeeks,
|
|
6
|
+
getWeekdayNames,
|
|
7
|
+
computeWeekRangeInfo,
|
|
8
|
+
computeAdjacentMonth,
|
|
9
|
+
isInRange,
|
|
10
|
+
toZonedDateTime,
|
|
11
|
+
fromZonedDateTime,
|
|
12
|
+
resolveFocusTarget,
|
|
13
|
+
} from "./utils";
|
|
14
|
+
|
|
15
|
+
const T: TemporalNamespace = {
|
|
16
|
+
Now: Temporal.Now,
|
|
17
|
+
PlainDate: Temporal.PlainDate,
|
|
18
|
+
PlainDateTime: Temporal.PlainDateTime,
|
|
19
|
+
PlainMonthDay: Temporal.PlainMonthDay,
|
|
20
|
+
PlainYearMonth: Temporal.PlainYearMonth,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const timeZone = "America/New_York";
|
|
24
|
+
|
|
25
|
+
// Pre-computed fixtures
|
|
26
|
+
const marchWeeks = getMonthWeeks(2026, 3, T);
|
|
27
|
+
const rangeStart = Temporal.PlainDate.from("2026-03-05");
|
|
28
|
+
const rangeEnd = Temporal.PlainDate.from("2026-03-20");
|
|
29
|
+
const midWeek = marchWeeks[2]; // a week in the middle of the range
|
|
30
|
+
|
|
31
|
+
describe("getMonthWeeks", () => {
|
|
32
|
+
bench("generate month grid (March 2026)", () => {
|
|
33
|
+
getMonthWeeks(2026, 3, T);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
bench("generate month grid (February — short month)", () => {
|
|
37
|
+
getMonthWeeks(2026, 2, T);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
bench("generate month grid (August — 6-week grid)", () => {
|
|
41
|
+
getMonthWeeks(2026, 8, T);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("computeWeekRangeInfo", () => {
|
|
46
|
+
bench("week fully inside range", () => {
|
|
47
|
+
computeWeekRangeInfo(midWeek, rangeStart, rangeEnd, T);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
bench("week with no overlap", () => {
|
|
51
|
+
const noOverlapWeek = marchWeeks[marchWeeks.length - 1];
|
|
52
|
+
computeWeekRangeInfo(
|
|
53
|
+
noOverlapWeek,
|
|
54
|
+
Temporal.PlainDate.from("2026-03-01"),
|
|
55
|
+
Temporal.PlainDate.from("2026-03-04"),
|
|
56
|
+
T,
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
bench("no range (undefined bounds)", () => {
|
|
61
|
+
computeWeekRangeInfo(midWeek, undefined, undefined, T);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
bench("all 6 weeks of a month", () => {
|
|
65
|
+
for (const week of marchWeeks) {
|
|
66
|
+
computeWeekRangeInfo(week, rangeStart, rangeEnd, T);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("computeAdjacentMonth", () => {
|
|
72
|
+
bench("next month", () => {
|
|
73
|
+
computeAdjacentMonth({ year: 2026, month: 3 }, "next", T);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
bench("prev month", () => {
|
|
77
|
+
computeAdjacentMonth({ year: 2026, month: 3 }, "prev", T);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
bench("year boundary (Dec → Jan)", () => {
|
|
81
|
+
computeAdjacentMonth({ year: 2026, month: 12 }, "next", T);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
bench("year boundary (Jan → Dec)", () => {
|
|
85
|
+
computeAdjacentMonth({ year: 2026, month: 1 }, "prev", T);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("isInRange", () => {
|
|
90
|
+
const allDays = marchWeeks.flat();
|
|
91
|
+
|
|
92
|
+
bench("single date check (in range)", () => {
|
|
93
|
+
isInRange(Temporal.PlainDate.from("2026-03-10"), rangeStart, rangeEnd, T);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
bench("single date check (out of range)", () => {
|
|
97
|
+
isInRange(Temporal.PlainDate.from("2026-03-25"), rangeStart, rangeEnd, T);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
bench("check all 42 grid cells", () => {
|
|
101
|
+
for (const day of allDays) {
|
|
102
|
+
isInRange(day, rangeStart, rangeEnd, T);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
bench("undefined range (early exit)", () => {
|
|
107
|
+
isInRange(Temporal.PlainDate.from("2026-03-10"), undefined, undefined, T);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("toZonedDateTime / fromZonedDateTime", () => {
|
|
112
|
+
const plainDate = Temporal.PlainDate.from("2026-03-15");
|
|
113
|
+
const plainDateTime = Temporal.PlainDateTime.from("2026-03-15T10:30:00");
|
|
114
|
+
const nativeDate = new Date(2026, 2, 15, 10, 30, 0);
|
|
115
|
+
|
|
116
|
+
bench("PlainDate → ZonedDateTime", () => {
|
|
117
|
+
toZonedDateTime({ format: "PlainDate", value: plainDate }, timeZone, T);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
bench("PlainDateTime → ZonedDateTime", () => {
|
|
121
|
+
toZonedDateTime({ format: "PlainDateTime", value: plainDateTime }, timeZone, T);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
bench("Date → ZonedDateTime", () => {
|
|
125
|
+
toZonedDateTime({ format: "Date", value: nativeDate }, timeZone, T);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
bench("ZonedDateTime → PlainDate", () => {
|
|
129
|
+
const zdt = plainDate.toZonedDateTime(timeZone);
|
|
130
|
+
fromZonedDateTime(zdt, "PlainDate", T);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
bench("ZonedDateTime → object", () => {
|
|
134
|
+
const zdt = plainDate.toZonedDateTime(timeZone);
|
|
135
|
+
fromZonedDateTime(zdt, "object", T);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
bench("round-trip PlainDate → ZDT → PlainDate", () => {
|
|
139
|
+
const zdt = toZonedDateTime({ format: "PlainDate", value: plainDate }, timeZone, T);
|
|
140
|
+
fromZonedDateTime(zdt, "PlainDate", T);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("getWeekdayNames", () => {
|
|
145
|
+
bench("en-US locale (7× toLocaleString)", () => {
|
|
146
|
+
getWeekdayNames("en-US", T);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
bench("de-DE locale", () => {
|
|
150
|
+
getWeekdayNames("de-DE", T);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("resolveFocusTarget", () => {
|
|
155
|
+
const selectedDate = Temporal.PlainDate.from("2026-03-15");
|
|
156
|
+
const focusedDate = Temporal.PlainDate.from("2026-03-10");
|
|
157
|
+
const currentMonth = { year: 2026, month: 3 };
|
|
158
|
+
const noDisabled = () => false;
|
|
159
|
+
|
|
160
|
+
bench("focused date in grid (fast path)", () => {
|
|
161
|
+
resolveFocusTarget(focusedDate, selectedDate, marchWeeks, currentMonth, noDisabled, T, true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
bench("selected date fallback", () => {
|
|
165
|
+
// Focus a date outside the grid to force fallback to selectedDate
|
|
166
|
+
const outsideFocus = Temporal.PlainDate.from("2026-05-01");
|
|
167
|
+
resolveFocusTarget(outsideFocus, selectedDate, marchWeeks, currentMonth, noDisabled, T, true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
bench("no match — linear scan to first enabled", () => {
|
|
171
|
+
const outsideFocus = Temporal.PlainDate.from("2026-05-01");
|
|
172
|
+
const outsideSelected = Temporal.PlainDate.from("2026-05-15");
|
|
173
|
+
resolveFocusTarget(
|
|
174
|
+
outsideFocus,
|
|
175
|
+
outsideSelected,
|
|
176
|
+
marchWeeks,
|
|
177
|
+
currentMonth,
|
|
178
|
+
noDisabled,
|
|
179
|
+
T,
|
|
180
|
+
true,
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
});
|