@klinking/colander 0.0.0 → 2.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 +51 -48
- package/dist/formats/date.d.cts +10 -37
- package/dist/formats/date.d.mts +10 -37
- package/dist/formats/date.mjs +6 -2
- package/dist/formats/object.cjs +51 -48
- package/dist/formats/object.d.cts +10 -37
- package/dist/formats/object.d.mts +10 -37
- package/dist/formats/object.mjs +6 -2
- package/dist/formats/plain-date-time.cjs +51 -48
- package/dist/formats/plain-date-time.d.cts +10 -37
- package/dist/formats/plain-date-time.d.mts +10 -37
- package/dist/formats/plain-date-time.mjs +6 -2
- package/dist/formats/plain-date.cjs +51 -48
- package/dist/formats/plain-date.d.cts +10 -37
- package/dist/formats/plain-date.d.mts +10 -37
- package/dist/formats/plain-date.mjs +6 -2
- package/dist/formats/plain-month-day.cjs +51 -48
- package/dist/formats/plain-month-day.d.cts +10 -37
- package/dist/formats/plain-month-day.d.mts +10 -37
- package/dist/formats/plain-month-day.mjs +6 -2
- package/dist/formats/plain-year-month.cjs +51 -48
- package/dist/formats/plain-year-month.d.cts +10 -37
- package/dist/formats/plain-year-month.d.mts +10 -37
- package/dist/formats/plain-year-month.mjs +6 -2
- package/dist/formats/zoned-date-time.cjs +51 -48
- package/dist/formats/zoned-date-time.d.cts +10 -37
- package/dist/formats/zoned-date-time.d.mts +10 -37
- package/dist/formats/zoned-date-time.mjs +6 -2
- package/dist/index.cjs +47 -48
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +2 -2
- package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-CtbaTTmA.cjs} +329 -567
- package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-D5GjCwNm.mjs} +329 -561
- package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
- package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
- package/package.json +20 -20
- package/src/calendar-context.ts +12 -5
- package/src/calendar-provider.test.tsx +18 -4
- package/src/calendar-provider.tsx +130 -35
- package/src/calendar-types.ts +21 -4
- package/src/compute-weeks-in-window.test.ts +9 -7
- package/src/context.ts +1 -1
- package/src/day-cell.tsx +92 -46
- package/src/drag-handle.tsx +23 -24
- package/src/formats/date.ts +120 -56
- package/src/formats/formats.test.ts +8 -4
- package/src/formats/object.ts +120 -56
- package/src/formats/plain-date-time.ts +120 -56
- package/src/formats/plain-date.ts +120 -56
- package/src/formats/plain-month-day.ts +120 -56
- package/src/formats/plain-year-month.ts +120 -56
- package/src/formats/zoned-date-time.ts +120 -56
- package/src/grid-header.tsx +24 -18
- package/src/grid.event-perf.test.tsx +30 -13
- package/src/grid.perf.test.tsx +97 -33
- package/src/grid.tsx +75 -43
- package/src/index.ts +16 -4
- package/src/keyboard.test.ts +110 -42
- package/src/keyboard.ts +18 -7
- package/src/month-separator.test.tsx +3 -1
- package/src/month-separator.tsx +30 -9
- package/src/month-view-context.ts +8 -3
- package/src/month-view-types.ts +14 -10
- package/src/month-view.test.tsx +687 -68
- package/src/month-view.tsx +176 -71
- package/src/navigation.tsx +77 -47
- package/src/overflow.test.ts +15 -13
- package/src/overflow.ts +10 -2
- package/src/range-preview.tsx +37 -12
- package/src/resolve-first-week.test.ts +14 -10
- package/src/resolve-first-week.ts +6 -2
- package/src/root-selection.ts +185 -101
- package/src/selected-range.tsx +47 -22
- package/src/test-temporal.ts +0 -2
- package/src/types.ts +126 -103
- package/src/utils.bench.ts +30 -6
- package/src/utils.test.ts +203 -55
- package/src/utils.ts +156 -54
- package/src/view-context.ts +4 -1
- package/src/week-number.tsx +5 -8
- package/src/weeks-grid.tsx +45 -19
- package/src/weeks-keyboard.test.ts +6 -7
- package/src/weeks-keyboard.ts +8 -3
- package/src/weeks-navigation.tsx +21 -9
- package/src/weeks-view-context.ts +8 -3
- package/src/weeks-view-state.ts +100 -33
- package/src/weeks-view-types.ts +14 -8
- package/src/weeks-view.test.tsx +127 -19
- package/src/weeks-view.tsx +30 -12
- package/src/temporal-polyfill.test.ts +0 -317
- package/src/temporal-polyfill.ts +0 -566
package/src/selected-range.tsx
CHANGED
|
@@ -8,7 +8,6 @@ import { useMonthViewState } from "./month-view-context";
|
|
|
8
8
|
import { MonthViewStableContext } from "./month-view-context";
|
|
9
9
|
import type { StateAttributesMapping } from "./types";
|
|
10
10
|
import type {
|
|
11
|
-
ValueFormat,
|
|
12
11
|
RangeSelectedState,
|
|
13
12
|
RangeSelectedProps,
|
|
14
13
|
OutsideDays,
|
|
@@ -48,20 +47,26 @@ export function computeClippedRangeInfo(
|
|
|
48
47
|
gridMonth: { year: number; month: number } | undefined,
|
|
49
48
|
): RangeInfo {
|
|
50
49
|
const raw = computeWeekRangeInfo(days, rangeStart, rangeEnd, T);
|
|
51
|
-
if (
|
|
50
|
+
if (
|
|
51
|
+
(outsideDays === "disabled" || outsideDays === "hidden") &&
|
|
52
|
+
raw.active &&
|
|
53
|
+
gridMonth
|
|
54
|
+
) {
|
|
52
55
|
let { startIndex, endIndex, extendsBefore, extendsAfter } = raw;
|
|
56
|
+
const inMonth = (i: number) => {
|
|
57
|
+
const day = days[i];
|
|
58
|
+
return (
|
|
59
|
+
day !== undefined &&
|
|
60
|
+
day.year === gridMonth.year &&
|
|
61
|
+
day.month === gridMonth.month
|
|
62
|
+
);
|
|
63
|
+
};
|
|
53
64
|
// Clip range to only in-month cells
|
|
54
|
-
while (
|
|
55
|
-
startIndex <= endIndex &&
|
|
56
|
-
(days[startIndex].year !== gridMonth.year || days[startIndex].month !== gridMonth.month)
|
|
57
|
-
) {
|
|
65
|
+
while (startIndex <= endIndex && !inMonth(startIndex)) {
|
|
58
66
|
startIndex++;
|
|
59
67
|
extendsBefore = true;
|
|
60
68
|
}
|
|
61
|
-
while (
|
|
62
|
-
endIndex >= startIndex &&
|
|
63
|
-
(days[endIndex].year !== gridMonth.year || days[endIndex].month !== gridMonth.month)
|
|
64
|
-
) {
|
|
69
|
+
while (endIndex >= startIndex && !inMonth(endIndex)) {
|
|
65
70
|
endIndex--;
|
|
66
71
|
extendsAfter = true;
|
|
67
72
|
}
|
|
@@ -79,7 +84,10 @@ export function computeClippedRangeInfo(
|
|
|
79
84
|
return raw;
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
function RangeSelectedFn(
|
|
87
|
+
function RangeSelectedFn(
|
|
88
|
+
props: RangeSelectedProps,
|
|
89
|
+
ref: React.ForwardedRef<HTMLTableCellElement>,
|
|
90
|
+
) {
|
|
83
91
|
const { selectionMode } = useCalendarStable();
|
|
84
92
|
if (selectionMode !== "range") {
|
|
85
93
|
return null;
|
|
@@ -93,8 +101,8 @@ function RangeSelectedFn(props: RangeSelectedProps, ref: React.ForwardedRef<HTML
|
|
|
93
101
|
* `active`, `week-index`, `start-index`, `end-index`, `start-date`,
|
|
94
102
|
* `end-date`, `extends-before`, and `extends-after`.
|
|
95
103
|
*/
|
|
96
|
-
export const RangeSelected = forwardRef(RangeSelectedFn) as
|
|
97
|
-
props: RangeSelectedProps
|
|
104
|
+
export const RangeSelected = forwardRef(RangeSelectedFn) as (
|
|
105
|
+
props: RangeSelectedProps & React.RefAttributes<HTMLTableCellElement>,
|
|
98
106
|
) => React.ReactElement | null;
|
|
99
107
|
|
|
100
108
|
function RangeSelectedInnerFn(
|
|
@@ -114,18 +122,28 @@ function RangeSelectedInnerFn(
|
|
|
114
122
|
const gridMonth = weekData?.gridMonth;
|
|
115
123
|
|
|
116
124
|
const info = useMemo(
|
|
117
|
-
() =>
|
|
125
|
+
() =>
|
|
126
|
+
computeClippedRangeInfo(
|
|
127
|
+
days,
|
|
128
|
+
rangeStart,
|
|
129
|
+
rangeEnd,
|
|
130
|
+
T,
|
|
131
|
+
outsideDays,
|
|
132
|
+
gridMonth,
|
|
133
|
+
),
|
|
118
134
|
[days, rangeStart, rangeEnd, T, outsideDays, gridMonth],
|
|
119
135
|
);
|
|
120
136
|
|
|
121
|
-
const startDate = info.active
|
|
122
|
-
|
|
137
|
+
const startDate = info.active
|
|
138
|
+
? (days[info.startIndex]?.toString() ?? "")
|
|
139
|
+
: "";
|
|
140
|
+
const endDate = info.active ? (days[info.endIndex]?.toString() ?? "") : "";
|
|
123
141
|
|
|
124
142
|
const weekIndex = weekData?.weekIndex ?? 0;
|
|
125
143
|
|
|
126
144
|
const state = useMemo<RangeSelectedState>(
|
|
127
145
|
() => ({
|
|
128
|
-
root: rootState
|
|
146
|
+
root: rootState,
|
|
129
147
|
active: info.active,
|
|
130
148
|
weekIndex,
|
|
131
149
|
startIndex: info.startIndex,
|
|
@@ -138,7 +156,16 @@ function RangeSelectedInnerFn(
|
|
|
138
156
|
hasEnd: rangeEnd !== undefined,
|
|
139
157
|
orientation,
|
|
140
158
|
}),
|
|
141
|
-
[
|
|
159
|
+
[
|
|
160
|
+
rootState,
|
|
161
|
+
info,
|
|
162
|
+
weekIndex,
|
|
163
|
+
startDate,
|
|
164
|
+
endDate,
|
|
165
|
+
rangeStart,
|
|
166
|
+
rangeEnd,
|
|
167
|
+
orientation,
|
|
168
|
+
],
|
|
142
169
|
);
|
|
143
170
|
|
|
144
171
|
const defaultProps: Record<string, unknown> = {
|
|
@@ -156,8 +183,6 @@ function RangeSelectedInnerFn(
|
|
|
156
183
|
});
|
|
157
184
|
}
|
|
158
185
|
|
|
159
|
-
const RangeSelectedInner = forwardRef(RangeSelectedInnerFn) as
|
|
160
|
-
|
|
161
|
-
>(
|
|
162
|
-
props: RangeSelectedProps<F> & React.RefAttributes<HTMLTableCellElement>,
|
|
186
|
+
const RangeSelectedInner = forwardRef(RangeSelectedInnerFn) as (
|
|
187
|
+
props: RangeSelectedProps & React.RefAttributes<HTMLTableCellElement>,
|
|
163
188
|
) => React.ReactElement | null;
|
package/src/test-temporal.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Temporal as FullTemporal } from "@js-temporal/polyfill";
|
|
2
|
-
import { Temporal as MiniTemporal } from "./temporal-polyfill";
|
|
3
2
|
import type { TemporalNamespace } from "./types";
|
|
4
3
|
|
|
5
4
|
export const temporalVariants: { name: string; T: TemporalNamespace }[] = [
|
|
@@ -13,5 +12,4 @@ export const temporalVariants: { name: string; T: TemporalNamespace }[] = [
|
|
|
13
12
|
PlainYearMonth: FullTemporal.PlainYearMonth,
|
|
14
13
|
},
|
|
15
14
|
},
|
|
16
|
-
{ name: "mini polyfill", T: MiniTemporal },
|
|
17
15
|
];
|
package/src/types.ts
CHANGED
|
@@ -88,10 +88,14 @@ export type DateValueObject =
|
|
|
88
88
|
export type ValueFormat = DateValueObject["format"];
|
|
89
89
|
|
|
90
90
|
/** Extracts the {@link DateValueObject} variant matching a given format `F`. */
|
|
91
|
-
export type ValueForFormat<F extends ValueFormat> = Extract<
|
|
91
|
+
export type ValueForFormat<F extends ValueFormat> = Extract<
|
|
92
|
+
DateValueObject,
|
|
93
|
+
{ format: F }
|
|
94
|
+
>;
|
|
92
95
|
|
|
93
96
|
/** The runtime value type for a given format `F` (e.g. `Temporal.PlainDate` for `"PlainDate"`). */
|
|
94
|
-
export type RawValueForFormat<F extends ValueFormat> =
|
|
97
|
+
export type RawValueForFormat<F extends ValueFormat> =
|
|
98
|
+
ValueForFormat<F>["value"];
|
|
95
99
|
|
|
96
100
|
/** A start/end date pair for range selection, typed to the given format `F`. */
|
|
97
101
|
export type DateRange<F extends ValueFormat = ValueFormat> = {
|
|
@@ -208,18 +212,25 @@ export interface DatePickerStateContextValue {
|
|
|
208
212
|
export interface DatePickerContextValue
|
|
209
213
|
extends DatePickerStableContextValue, DatePickerStateContextValue {}
|
|
210
214
|
|
|
211
|
-
/**
|
|
212
|
-
|
|
215
|
+
/**
|
|
216
|
+
* State exposed by the `Root` component to its render function and descendants.
|
|
217
|
+
*
|
|
218
|
+
* All date values are `Temporal` objects (the internal representation), not the
|
|
219
|
+
* configured value `format`. The format-typed values are delivered through the
|
|
220
|
+
* `value`/`defaultValue`/`onValueChange` props; this state is for rendering, so
|
|
221
|
+
* use e.g. `selected?.toLocaleString(locale)` to display.
|
|
222
|
+
*/
|
|
223
|
+
export type RootState = {
|
|
213
224
|
/** `true` when at least one date is selected. */
|
|
214
225
|
hasSelection: boolean;
|
|
215
|
-
/** The primary selected
|
|
216
|
-
selected:
|
|
217
|
-
/** All selected dates in
|
|
218
|
-
selectedDates:
|
|
219
|
-
/** Range start
|
|
220
|
-
rangeStart:
|
|
221
|
-
/** Range end
|
|
222
|
-
rangeEnd:
|
|
226
|
+
/** The primary selected date (the first committed date), or `undefined`. */
|
|
227
|
+
selected: Temporal.PlainDate | undefined;
|
|
228
|
+
/** All currently selected dates (chronological in `multiple` mode). */
|
|
229
|
+
selectedDates: Temporal.PlainDate[];
|
|
230
|
+
/** Range start, or `undefined`. */
|
|
231
|
+
rangeStart: Temporal.PlainDate | undefined;
|
|
232
|
+
/** Range end, or `undefined`. */
|
|
233
|
+
rangeEnd: Temporal.PlainDate | undefined;
|
|
223
234
|
/** The currently focused `PlainDate` in the grid. */
|
|
224
235
|
focused: Temporal.PlainDate;
|
|
225
236
|
/** The month/year currently being viewed. */
|
|
@@ -232,6 +243,13 @@ export type RootState<F extends ValueFormat = ValueFormat> = {
|
|
|
232
243
|
readOnly: boolean;
|
|
233
244
|
};
|
|
234
245
|
|
|
246
|
+
/**
|
|
247
|
+
* The view-independent part of {@link RootState} (everything except `focused`
|
|
248
|
+
* and `viewing`, which each view supplies). Built once by the provider and
|
|
249
|
+
* shared so MonthView and WeeksView expose identical selection state.
|
|
250
|
+
*/
|
|
251
|
+
export type BaseRootState = Omit<RootState, "focused" | "viewing">;
|
|
252
|
+
|
|
235
253
|
interface RootOwnPropsBase<F extends ValueFormat = ValueFormat> {
|
|
236
254
|
/**
|
|
237
255
|
* The value format used for date serialization. Determines the type of
|
|
@@ -272,9 +290,16 @@ interface RootOwnPropsBase<F extends ValueFormat = ValueFormat> {
|
|
|
272
290
|
*/
|
|
273
291
|
locale?: string;
|
|
274
292
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
293
|
+
* The `Temporal` implementation to use. This library does not bundle one:
|
|
294
|
+
* provide a `Temporal` namespace here unless the host already exposes the
|
|
295
|
+
* native `Temporal` API. Two well-supported polyfills:
|
|
296
|
+
*
|
|
297
|
+
* - `temporal-polyfill` — https://github.com/fullcalendar/temporal-polyfill
|
|
298
|
+
* - `@js-temporal/polyfill` — https://github.com/js-temporal/temporal-polyfill
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* import { Temporal } from "temporal-polyfill";
|
|
302
|
+
* <MonthView temporal={Temporal} … />
|
|
278
303
|
*/
|
|
279
304
|
temporal?: TemporalNamespace;
|
|
280
305
|
/**
|
|
@@ -360,7 +385,10 @@ interface RangeControlledProps<F extends ValueFormat = ValueFormat> {
|
|
|
360
385
|
/** Not allowed in controlled mode. */
|
|
361
386
|
defaultValue?: never;
|
|
362
387
|
/** Called when the selected range changes. `null` means the selection was cleared. */
|
|
363
|
-
onValueChange?: (
|
|
388
|
+
onValueChange?: (
|
|
389
|
+
value: DateRange<F> | null,
|
|
390
|
+
meta: ValueChangeMeta<DateRange<F> | null>,
|
|
391
|
+
) => void;
|
|
364
392
|
/**
|
|
365
393
|
* Controls how clicking inside an existing range behaves.
|
|
366
394
|
* @default "nearest-end"
|
|
@@ -392,7 +420,10 @@ interface RangeUncontrolledProps<F extends ValueFormat = ValueFormat> {
|
|
|
392
420
|
/** The initial selected range (uncontrolled). */
|
|
393
421
|
defaultValue?: DateRange<F>;
|
|
394
422
|
/** Called when the selected range changes. `null` means the selection was cleared. */
|
|
395
|
-
onValueChange?: (
|
|
423
|
+
onValueChange?: (
|
|
424
|
+
value: DateRange<F> | null,
|
|
425
|
+
meta: ValueChangeMeta<DateRange<F> | null>,
|
|
426
|
+
) => void;
|
|
396
427
|
/**
|
|
397
428
|
* Controls how clicking inside an existing range behaves.
|
|
398
429
|
* @default "nearest-end"
|
|
@@ -448,15 +479,16 @@ interface MultipleUncontrolledProps<F extends ValueFormat = ValueFormat> {
|
|
|
448
479
|
}
|
|
449
480
|
|
|
450
481
|
/** Own props accepted by `Root`, combining base config with selection-mode-specific props. */
|
|
451
|
-
export type RootOwnProps<F extends ValueFormat = ValueFormat> =
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
482
|
+
export type RootOwnProps<F extends ValueFormat = ValueFormat> =
|
|
483
|
+
RootOwnPropsBase<F> &
|
|
484
|
+
(
|
|
485
|
+
| SingleControlledProps<F>
|
|
486
|
+
| SingleUncontrolledProps<F>
|
|
487
|
+
| RangeControlledProps<F>
|
|
488
|
+
| RangeUncontrolledProps<F>
|
|
489
|
+
| MultipleControlledProps<F>
|
|
490
|
+
| MultipleUncontrolledProps<F>
|
|
491
|
+
);
|
|
460
492
|
|
|
461
493
|
type AllRootOwnPropKeys =
|
|
462
494
|
| keyof RootOwnPropsBase
|
|
@@ -469,14 +501,14 @@ type AllRootOwnPropKeys =
|
|
|
469
501
|
|
|
470
502
|
/** Full props for the `Root` component (own props + render element props). */
|
|
471
503
|
export type RootProps<F extends ValueFormat = ValueFormat> = Omit<
|
|
472
|
-
useRender.ComponentProps<"div", RootState
|
|
504
|
+
useRender.ComponentProps<"div", RootState>,
|
|
473
505
|
AllRootOwnPropKeys
|
|
474
506
|
> &
|
|
475
507
|
RootOwnProps<F>;
|
|
476
508
|
|
|
477
509
|
/** State exposed by the `DateString` component. */
|
|
478
|
-
export type DateStringState
|
|
479
|
-
root: RootState
|
|
510
|
+
export type DateStringState = {
|
|
511
|
+
root: RootState;
|
|
480
512
|
month: number;
|
|
481
513
|
year: number;
|
|
482
514
|
day: number;
|
|
@@ -491,15 +523,15 @@ export interface DateStringOwnProps {
|
|
|
491
523
|
}
|
|
492
524
|
|
|
493
525
|
/** Full props for the `DateString` component. */
|
|
494
|
-
export type DateStringProps
|
|
526
|
+
export type DateStringProps = useRender.ComponentProps<
|
|
495
527
|
"span",
|
|
496
|
-
DateStringState
|
|
528
|
+
DateStringState
|
|
497
529
|
> &
|
|
498
530
|
DateStringOwnProps;
|
|
499
531
|
|
|
500
532
|
/** State exposed by the `TimeString` component. */
|
|
501
|
-
export type TimeStringState
|
|
502
|
-
root: RootState
|
|
533
|
+
export type TimeStringState = {
|
|
534
|
+
root: RootState;
|
|
503
535
|
hour: number;
|
|
504
536
|
minute: number;
|
|
505
537
|
second: number;
|
|
@@ -514,15 +546,15 @@ export interface TimeStringOwnProps {
|
|
|
514
546
|
}
|
|
515
547
|
|
|
516
548
|
/** Full props for the `TimeString` component. */
|
|
517
|
-
export type TimeStringProps
|
|
549
|
+
export type TimeStringProps = useRender.ComponentProps<
|
|
518
550
|
"span",
|
|
519
|
-
TimeStringState
|
|
551
|
+
TimeStringState
|
|
520
552
|
> &
|
|
521
553
|
TimeStringOwnProps;
|
|
522
554
|
|
|
523
555
|
/** State exposed by the `MonthYearString` component. */
|
|
524
|
-
export type MonthYearStringState
|
|
525
|
-
root: RootState
|
|
556
|
+
export type MonthYearStringState = {
|
|
557
|
+
root: RootState;
|
|
526
558
|
month: number;
|
|
527
559
|
year: number;
|
|
528
560
|
};
|
|
@@ -538,34 +570,34 @@ export interface MonthYearStringOwnProps {
|
|
|
538
570
|
}
|
|
539
571
|
|
|
540
572
|
/** Full props for the `MonthYearString` component. */
|
|
541
|
-
export type MonthYearStringProps
|
|
573
|
+
export type MonthYearStringProps = useRender.ComponentProps<
|
|
542
574
|
"span",
|
|
543
|
-
MonthYearStringState
|
|
575
|
+
MonthYearStringState
|
|
544
576
|
> &
|
|
545
577
|
MonthYearStringOwnProps;
|
|
546
578
|
|
|
547
579
|
/** State exposed by `PrevMonthButton` and `NextMonthButton`. */
|
|
548
|
-
export type NavButtonState
|
|
549
|
-
root: RootState
|
|
580
|
+
export type NavButtonState = {
|
|
581
|
+
root: RootState;
|
|
550
582
|
direction: "next" | "prev";
|
|
551
583
|
disabled: boolean;
|
|
552
584
|
target: Temporal.PlainYearMonth;
|
|
553
585
|
};
|
|
554
586
|
|
|
555
587
|
/** Full props for the `PrevMonthButton` component. */
|
|
556
|
-
export type PrevMonthButtonProps
|
|
588
|
+
export type PrevMonthButtonProps = useRender.ComponentProps<
|
|
557
589
|
"button",
|
|
558
|
-
NavButtonState
|
|
590
|
+
NavButtonState
|
|
559
591
|
>;
|
|
560
592
|
/** Full props for the `NextMonthButton` component. */
|
|
561
|
-
export type NextMonthButtonProps
|
|
593
|
+
export type NextMonthButtonProps = useRender.ComponentProps<
|
|
562
594
|
"button",
|
|
563
|
-
NavButtonState
|
|
595
|
+
NavButtonState
|
|
564
596
|
>;
|
|
565
597
|
|
|
566
598
|
/** State exposed by the `GridHeaderCell` component. */
|
|
567
|
-
export type GridHeaderCellState
|
|
568
|
-
root: RootState
|
|
599
|
+
export type GridHeaderCellState = {
|
|
600
|
+
root: RootState;
|
|
569
601
|
dayOfWeek: number;
|
|
570
602
|
long: string;
|
|
571
603
|
short: string;
|
|
@@ -579,37 +611,34 @@ export interface GridHeaderCellOwnProps {
|
|
|
579
611
|
}
|
|
580
612
|
|
|
581
613
|
/** Full props for the `GridHeaderCell` component. */
|
|
582
|
-
export type GridHeaderCellProps
|
|
614
|
+
export type GridHeaderCellProps = useRender.ComponentProps<
|
|
583
615
|
"th",
|
|
584
|
-
GridHeaderCellState
|
|
616
|
+
GridHeaderCellState
|
|
585
617
|
> &
|
|
586
618
|
GridHeaderCellOwnProps;
|
|
587
619
|
|
|
588
620
|
/** State exposed by the `GridHeader` component. */
|
|
589
|
-
export type GridHeaderState
|
|
590
|
-
root: RootState
|
|
621
|
+
export type GridHeaderState = {
|
|
622
|
+
root: RootState;
|
|
591
623
|
};
|
|
592
624
|
|
|
593
625
|
/** Full props for the `GridHeader` component. */
|
|
594
|
-
export type GridHeaderProps
|
|
626
|
+
export type GridHeaderProps = useRender.ComponentProps<
|
|
595
627
|
"thead",
|
|
596
|
-
GridHeaderState
|
|
628
|
+
GridHeaderState
|
|
597
629
|
>;
|
|
598
630
|
|
|
599
631
|
/** State exposed by the `GridBody` component. */
|
|
600
|
-
export type GridBodyState
|
|
601
|
-
root: RootState
|
|
632
|
+
export type GridBodyState = {
|
|
633
|
+
root: RootState;
|
|
602
634
|
};
|
|
603
635
|
|
|
604
636
|
/** Full props for the `GridBody` component. */
|
|
605
|
-
export type GridBodyProps
|
|
606
|
-
"tbody",
|
|
607
|
-
GridBodyState<F>
|
|
608
|
-
>;
|
|
637
|
+
export type GridBodyProps = useRender.ComponentProps<"tbody", GridBodyState>;
|
|
609
638
|
|
|
610
639
|
/** State exposed by the `Grid` component. */
|
|
611
|
-
export type GridState
|
|
612
|
-
root: RootState
|
|
640
|
+
export type GridState = {
|
|
641
|
+
root: RootState;
|
|
613
642
|
month: number;
|
|
614
643
|
year: number;
|
|
615
644
|
orientation: GridOrientation;
|
|
@@ -628,29 +657,26 @@ export interface GridOwnProps {
|
|
|
628
657
|
}
|
|
629
658
|
|
|
630
659
|
/** Full props for the `Grid` component. */
|
|
631
|
-
export type GridProps
|
|
632
|
-
"table",
|
|
633
|
-
GridState<F>
|
|
634
|
-
> &
|
|
660
|
+
export type GridProps = useRender.ComponentProps<"table", GridState> &
|
|
635
661
|
GridOwnProps;
|
|
636
662
|
|
|
637
663
|
/** State exposed by the `WeekTemplate` component. */
|
|
638
|
-
export type WeekTemplateState
|
|
639
|
-
root: RootState
|
|
664
|
+
export type WeekTemplateState = {
|
|
665
|
+
root: RootState;
|
|
640
666
|
weekIndex: number;
|
|
641
667
|
/** 1-based CSS grid row index for this week row (WeeksView only, undefined in MonthView). */
|
|
642
668
|
gridRowIndex: number | undefined;
|
|
643
669
|
};
|
|
644
670
|
|
|
645
671
|
/** Full props for the `WeekTemplate` component. */
|
|
646
|
-
export type WeekTemplateProps
|
|
672
|
+
export type WeekTemplateProps = useRender.ComponentProps<
|
|
647
673
|
"tr",
|
|
648
|
-
WeekTemplateState
|
|
674
|
+
WeekTemplateState
|
|
649
675
|
>;
|
|
650
676
|
|
|
651
677
|
/** State exposed by the `DayCellTemplate` component. */
|
|
652
|
-
export type DayCellTemplateState
|
|
653
|
-
root: RootState
|
|
678
|
+
export type DayCellTemplateState = {
|
|
679
|
+
root: RootState;
|
|
654
680
|
date: Temporal.PlainDate;
|
|
655
681
|
columnIndex: number;
|
|
656
682
|
orientation: GridOrientation;
|
|
@@ -692,7 +718,7 @@ export type DayCellTemplateState<F extends ValueFormat = ValueFormat> = {
|
|
|
692
718
|
};
|
|
693
719
|
|
|
694
720
|
/** State exposed by the `DayButton` component (same as `DayCellTemplateState`). */
|
|
695
|
-
export type DayButtonState
|
|
721
|
+
export type DayButtonState = DayCellTemplateState;
|
|
696
722
|
|
|
697
723
|
/** Own props for the `DayCellTemplate` component. */
|
|
698
724
|
export interface DayCellTemplateOwnProps {
|
|
@@ -701,9 +727,9 @@ export interface DayCellTemplateOwnProps {
|
|
|
701
727
|
}
|
|
702
728
|
|
|
703
729
|
/** Full props for the `DayCellTemplate` component. */
|
|
704
|
-
export type DayCellTemplateProps
|
|
730
|
+
export type DayCellTemplateProps = useRender.ComponentProps<
|
|
705
731
|
"td",
|
|
706
|
-
DayCellTemplateState
|
|
732
|
+
DayCellTemplateState
|
|
707
733
|
> &
|
|
708
734
|
DayCellTemplateOwnProps;
|
|
709
735
|
|
|
@@ -714,15 +740,15 @@ export interface DayButtonOwnProps {
|
|
|
714
740
|
}
|
|
715
741
|
|
|
716
742
|
/** Full props for the `DayButton` component. */
|
|
717
|
-
export type DayButtonProps
|
|
743
|
+
export type DayButtonProps = useRender.ComponentProps<
|
|
718
744
|
"button",
|
|
719
|
-
DayButtonState
|
|
745
|
+
DayButtonState
|
|
720
746
|
> &
|
|
721
747
|
DayButtonOwnProps;
|
|
722
748
|
|
|
723
749
|
/** State exposed by the `RangeSelected` component. */
|
|
724
|
-
export type RangeSelectedState
|
|
725
|
-
root: RootState
|
|
750
|
+
export type RangeSelectedState = {
|
|
751
|
+
root: RootState;
|
|
726
752
|
active: boolean;
|
|
727
753
|
weekIndex: number;
|
|
728
754
|
startIndex: number;
|
|
@@ -737,23 +763,23 @@ export type RangeSelectedState<F extends ValueFormat = ValueFormat> = {
|
|
|
737
763
|
};
|
|
738
764
|
|
|
739
765
|
/** Full props for the `RangeSelected` component. */
|
|
740
|
-
export type RangeSelectedProps
|
|
766
|
+
export type RangeSelectedProps = useRender.ComponentProps<
|
|
741
767
|
"td",
|
|
742
|
-
RangeSelectedState
|
|
768
|
+
RangeSelectedState
|
|
743
769
|
>;
|
|
744
770
|
|
|
745
771
|
/** State exposed by the `RangePreview` component (same shape as `RangeSelectedState`). */
|
|
746
|
-
export type RangePreviewState
|
|
772
|
+
export type RangePreviewState = RangeSelectedState;
|
|
747
773
|
|
|
748
774
|
/** Full props for the `RangePreview` component (same shape as `RangeSelectedProps`). */
|
|
749
|
-
export type RangePreviewProps
|
|
775
|
+
export type RangePreviewProps = RangeSelectedProps;
|
|
750
776
|
|
|
751
777
|
/** Which end of a range the drag handle controls. */
|
|
752
778
|
export type DragHandleEdge = "start" | "end";
|
|
753
779
|
|
|
754
780
|
/** State exposed by the `RangeDragHandle` components. */
|
|
755
|
-
export type DragHandleState
|
|
756
|
-
root: RootState
|
|
781
|
+
export type DragHandleState = {
|
|
782
|
+
root: RootState;
|
|
757
783
|
active: boolean;
|
|
758
784
|
dragging: boolean;
|
|
759
785
|
edge: DragHandleEdge;
|
|
@@ -769,46 +795,43 @@ export interface DragHandleOwnProps {
|
|
|
769
795
|
}
|
|
770
796
|
|
|
771
797
|
/** Full props for the `RangeDragHandle` component. */
|
|
772
|
-
export type RangeDragHandleProps
|
|
798
|
+
export type RangeDragHandleProps = useRender.ComponentProps<
|
|
773
799
|
"span",
|
|
774
|
-
DragHandleState
|
|
800
|
+
DragHandleState
|
|
775
801
|
> &
|
|
776
802
|
DragHandleOwnProps;
|
|
777
803
|
|
|
778
804
|
/** Props for `RangeStartDragHandle` (edge is fixed to `"start"`). */
|
|
779
|
-
export type RangeStartDragHandleProps
|
|
780
|
-
RangeDragHandleProps<F>,
|
|
781
|
-
"edge"
|
|
782
|
-
>;
|
|
805
|
+
export type RangeStartDragHandleProps = Omit<RangeDragHandleProps, "edge">;
|
|
783
806
|
|
|
784
807
|
/** Props for `RangeEndDragHandle` (edge is fixed to `"end"`). */
|
|
785
|
-
export type RangeEndDragHandleProps
|
|
786
|
-
RangeDragHandleProps<F>,
|
|
787
|
-
"edge"
|
|
788
|
-
>;
|
|
808
|
+
export type RangeEndDragHandleProps = Omit<RangeDragHandleProps, "edge">;
|
|
789
809
|
|
|
790
810
|
/** State exposed by the `WeekNumberCell` component. */
|
|
791
|
-
export type WeekNumberCellState
|
|
792
|
-
root: RootState
|
|
811
|
+
export type WeekNumberCellState = {
|
|
812
|
+
root: RootState;
|
|
793
813
|
weekNumber: number;
|
|
794
814
|
};
|
|
795
815
|
|
|
796
816
|
/** Full props for the `WeekNumberCell` component. */
|
|
797
|
-
export type WeekNumberCellProps
|
|
817
|
+
export type WeekNumberCellProps = useRender.ComponentProps<
|
|
798
818
|
"td",
|
|
799
|
-
WeekNumberCellState
|
|
819
|
+
WeekNumberCellState
|
|
800
820
|
>;
|
|
801
821
|
|
|
802
822
|
/** State exposed by the `WeekNumberHeader` component. */
|
|
803
|
-
export type WeekNumberHeaderState
|
|
804
|
-
root: RootState
|
|
823
|
+
export type WeekNumberHeaderState = {
|
|
824
|
+
root: RootState;
|
|
805
825
|
};
|
|
806
826
|
|
|
807
827
|
/** Full props for the `WeekNumberHeader` component. */
|
|
808
|
-
export type WeekNumberHeaderProps
|
|
828
|
+
export type WeekNumberHeaderProps = useRender.ComponentProps<
|
|
809
829
|
"th",
|
|
810
|
-
WeekNumberHeaderState
|
|
830
|
+
WeekNumberHeaderState
|
|
811
831
|
>;
|
|
812
832
|
|
|
813
833
|
/** Root props pre-narrowed to a specific format. */
|
|
814
|
-
export type TypedRootProps<F extends ValueFormat> = Omit<
|
|
834
|
+
export type TypedRootProps<F extends ValueFormat> = Omit<
|
|
835
|
+
RootProps<F>,
|
|
836
|
+
"format" | "temporal"
|
|
837
|
+
>;
|
package/src/utils.bench.ts
CHANGED
|
@@ -26,7 +26,7 @@ const timeZone = "America/New_York";
|
|
|
26
26
|
const marchWeeks = getMonthWeeks(2026, 3, T);
|
|
27
27
|
const rangeStart = Temporal.PlainDate.from("2026-03-05");
|
|
28
28
|
const rangeEnd = Temporal.PlainDate.from("2026-03-20");
|
|
29
|
-
const midWeek = marchWeeks[2]
|
|
29
|
+
const midWeek = marchWeeks[2]!; // a week in the middle of the range
|
|
30
30
|
|
|
31
31
|
describe("getMonthWeeks", () => {
|
|
32
32
|
bench("generate month grid (March 2026)", () => {
|
|
@@ -48,7 +48,7 @@ describe("computeWeekRangeInfo", () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
bench("week with no overlap", () => {
|
|
51
|
-
const noOverlapWeek = marchWeeks[marchWeeks.length - 1]
|
|
51
|
+
const noOverlapWeek = marchWeeks[marchWeeks.length - 1]!;
|
|
52
52
|
computeWeekRangeInfo(
|
|
53
53
|
noOverlapWeek,
|
|
54
54
|
Temporal.PlainDate.from("2026-03-01"),
|
|
@@ -118,7 +118,11 @@ describe("toZonedDateTime / fromZonedDateTime", () => {
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
bench("PlainDateTime → ZonedDateTime", () => {
|
|
121
|
-
toZonedDateTime(
|
|
121
|
+
toZonedDateTime(
|
|
122
|
+
{ format: "PlainDateTime", value: plainDateTime },
|
|
123
|
+
timeZone,
|
|
124
|
+
T,
|
|
125
|
+
);
|
|
122
126
|
});
|
|
123
127
|
|
|
124
128
|
bench("Date → ZonedDateTime", () => {
|
|
@@ -136,7 +140,11 @@ describe("toZonedDateTime / fromZonedDateTime", () => {
|
|
|
136
140
|
});
|
|
137
141
|
|
|
138
142
|
bench("round-trip PlainDate → ZDT → PlainDate", () => {
|
|
139
|
-
const zdt = toZonedDateTime(
|
|
143
|
+
const zdt = toZonedDateTime(
|
|
144
|
+
{ format: "PlainDate", value: plainDate },
|
|
145
|
+
timeZone,
|
|
146
|
+
T,
|
|
147
|
+
);
|
|
140
148
|
fromZonedDateTime(zdt, "PlainDate", T);
|
|
141
149
|
});
|
|
142
150
|
});
|
|
@@ -158,13 +166,29 @@ describe("resolveFocusTarget", () => {
|
|
|
158
166
|
const noDisabled = () => false;
|
|
159
167
|
|
|
160
168
|
bench("focused date in grid (fast path)", () => {
|
|
161
|
-
resolveFocusTarget(
|
|
169
|
+
resolveFocusTarget(
|
|
170
|
+
focusedDate,
|
|
171
|
+
selectedDate,
|
|
172
|
+
marchWeeks,
|
|
173
|
+
currentMonth,
|
|
174
|
+
noDisabled,
|
|
175
|
+
T,
|
|
176
|
+
true,
|
|
177
|
+
);
|
|
162
178
|
});
|
|
163
179
|
|
|
164
180
|
bench("selected date fallback", () => {
|
|
165
181
|
// Focus a date outside the grid to force fallback to selectedDate
|
|
166
182
|
const outsideFocus = Temporal.PlainDate.from("2026-05-01");
|
|
167
|
-
resolveFocusTarget(
|
|
183
|
+
resolveFocusTarget(
|
|
184
|
+
outsideFocus,
|
|
185
|
+
selectedDate,
|
|
186
|
+
marchWeeks,
|
|
187
|
+
currentMonth,
|
|
188
|
+
noDisabled,
|
|
189
|
+
T,
|
|
190
|
+
true,
|
|
191
|
+
);
|
|
168
192
|
});
|
|
169
193
|
|
|
170
194
|
bench("no match — linear scan to first enabled", () => {
|