@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/day-cell.tsx
CHANGED
|
@@ -9,7 +9,6 @@ import { MonthViewStableContext } from "./month-view-context";
|
|
|
9
9
|
import { useMonthViewState } from "./month-view-context";
|
|
10
10
|
import type { StateAttributesMapping } from "./types";
|
|
11
11
|
import type {
|
|
12
|
-
ValueFormat,
|
|
13
12
|
DayCellTemplateProps,
|
|
14
13
|
DayButtonProps,
|
|
15
14
|
DayCellTemplateState,
|
|
@@ -39,7 +38,8 @@ export function computeDayCellState(
|
|
|
39
38
|
previewStart?: TemporalPoly.PlainDate,
|
|
40
39
|
previewEnd?: TemporalPoly.PlainDate,
|
|
41
40
|
): DayCellTemplateState & { isTabTarget: boolean } {
|
|
42
|
-
const isCurrentMonth =
|
|
41
|
+
const isCurrentMonth =
|
|
42
|
+
date.year === currentDateTime.year && date.month === currentDateTime.month;
|
|
43
43
|
const hidden = !isCurrentMonth && outsideDays === "hidden";
|
|
44
44
|
|
|
45
45
|
if (hidden) {
|
|
@@ -90,24 +90,32 @@ export function computeDayCellState(
|
|
|
90
90
|
let previewLen: number | false = false;
|
|
91
91
|
|
|
92
92
|
if (isRange) {
|
|
93
|
-
isRangeStart = rangeStart
|
|
93
|
+
isRangeStart = rangeStart
|
|
94
|
+
? T.PlainDate.compare(date, rangeStart) === 0
|
|
95
|
+
: false;
|
|
94
96
|
isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
95
97
|
isInRangeDay = isInRangeUtil(date, rangeStart, rangeEnd, T) !== false;
|
|
96
98
|
const effectiveStart = rangeStart ?? rangeEnd;
|
|
97
99
|
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
98
|
-
rangeIdx =
|
|
100
|
+
rangeIdx =
|
|
101
|
+
isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
|
|
99
102
|
rangeLen =
|
|
100
103
|
isInRangeDay && effectiveStart && effectiveEnd
|
|
101
104
|
? effectiveEnd.since(effectiveStart).days + 1
|
|
102
105
|
: false;
|
|
103
106
|
|
|
104
|
-
isPreviewRangeStart = previewStart
|
|
105
|
-
|
|
107
|
+
isPreviewRangeStart = previewStart
|
|
108
|
+
? T.PlainDate.compare(date, previewStart) === 0
|
|
109
|
+
: false;
|
|
110
|
+
isPreviewRangeEnd = previewEnd
|
|
111
|
+
? T.PlainDate.compare(date, previewEnd) === 0
|
|
112
|
+
: false;
|
|
106
113
|
isInPreviewRange =
|
|
107
114
|
previewStart && previewEnd
|
|
108
115
|
? isInRangeUtil(date, previewStart, previewEnd, T) !== false
|
|
109
116
|
: false;
|
|
110
|
-
previewIdx =
|
|
117
|
+
previewIdx =
|
|
118
|
+
isInPreviewRange && previewStart ? date.since(previewStart).days : false;
|
|
111
119
|
previewLen =
|
|
112
120
|
isInPreviewRange && previewStart && previewEnd
|
|
113
121
|
? previewEnd.since(previewStart).days + 1
|
|
@@ -115,7 +123,8 @@ export function computeDayCellState(
|
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
|
|
118
|
-
const suppressRange =
|
|
126
|
+
const suppressRange =
|
|
127
|
+
!isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
|
|
119
128
|
|
|
120
129
|
if (outsideNonInteractive) {
|
|
121
130
|
return {
|
|
@@ -135,16 +144,26 @@ export function computeDayCellState(
|
|
|
135
144
|
inRange: suppressRange ? false : isInRangeDay,
|
|
136
145
|
rangeIndex: suppressRange ? false : rangeIdx,
|
|
137
146
|
rangeLength: suppressRange ? false : rangeLen,
|
|
138
|
-
rangeHasStart: suppressRange
|
|
139
|
-
|
|
147
|
+
rangeHasStart: suppressRange
|
|
148
|
+
? false
|
|
149
|
+
: isInRangeDay && rangeStart !== undefined,
|
|
150
|
+
rangeHasEnd: suppressRange
|
|
151
|
+
? false
|
|
152
|
+
: isInRangeDay && rangeEnd !== undefined,
|
|
140
153
|
rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
|
|
141
154
|
rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
|
|
142
|
-
rangePreviewBoundary: suppressRange
|
|
155
|
+
rangePreviewBoundary: suppressRange
|
|
156
|
+
? false
|
|
157
|
+
: isPreviewRangeStart || isPreviewRangeEnd,
|
|
143
158
|
rangePreviewInRange: suppressRange ? false : isInPreviewRange,
|
|
144
159
|
rangePreviewIndex: suppressRange ? false : previewIdx,
|
|
145
160
|
rangePreviewLength: suppressRange ? false : previewLen,
|
|
146
|
-
rangePreviewHasStart: suppressRange
|
|
147
|
-
|
|
161
|
+
rangePreviewHasStart: suppressRange
|
|
162
|
+
? false
|
|
163
|
+
: isInPreviewRange && previewStart !== undefined,
|
|
164
|
+
rangePreviewHasEnd: suppressRange
|
|
165
|
+
? false
|
|
166
|
+
: isInPreviewRange && previewEnd !== undefined,
|
|
148
167
|
isTabTarget: false,
|
|
149
168
|
};
|
|
150
169
|
}
|
|
@@ -190,7 +209,8 @@ export function computeDayCellState(
|
|
|
190
209
|
|
|
191
210
|
export const dayStateAttributesMapping = {
|
|
192
211
|
root: () => null,
|
|
193
|
-
date: (v: TemporalPoly.PlainDate) =>
|
|
212
|
+
date: (v: TemporalPoly.PlainDate) =>
|
|
213
|
+
v ? { "data-date": v.toString() } : null,
|
|
194
214
|
columnIndex: () => null,
|
|
195
215
|
orientation: (v) => (v ? { "data-orientation": v } : null),
|
|
196
216
|
selected: (v) => (v ? { "data-selected": "" } : null),
|
|
@@ -209,28 +229,34 @@ export const dayStateAttributesMapping = {
|
|
|
209
229
|
rangeHasEnd: (v) => (v ? { "data-range-has-end": "" } : null),
|
|
210
230
|
rangePreviewStart: (v) => (v ? { "data-range-preview-start": "" } : null),
|
|
211
231
|
rangePreviewEnd: (v) => (v ? { "data-range-preview-end": "" } : null),
|
|
212
|
-
rangePreviewBoundary: (v) =>
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
232
|
+
rangePreviewBoundary: (v) =>
|
|
233
|
+
v ? { "data-range-preview-boundary": "" } : null,
|
|
234
|
+
rangePreviewInRange: (v) =>
|
|
235
|
+
v ? { "data-range-preview-in-range": "" } : null,
|
|
236
|
+
rangePreviewIndex: (v) =>
|
|
237
|
+
v !== false ? { "data-range-preview-index": String(v) } : null,
|
|
238
|
+
rangePreviewLength: (v) =>
|
|
239
|
+
v !== false ? { "data-range-preview-length": String(v) } : null,
|
|
240
|
+
rangePreviewHasStart: (v) =>
|
|
241
|
+
v ? { "data-range-preview-has-start": "" } : null,
|
|
217
242
|
rangePreviewHasEnd: (v) => (v ? { "data-range-preview-has-end": "" } : null),
|
|
218
243
|
} as const satisfies StateAttributesMapping<DayCellTemplateState>;
|
|
219
244
|
|
|
220
245
|
/** Props for the memoized DayCellInstance. */
|
|
221
|
-
interface DayCellInstanceProps
|
|
222
|
-
render?: DayCellTemplateProps
|
|
246
|
+
interface DayCellInstanceProps {
|
|
247
|
+
render?: DayCellTemplateProps["render"];
|
|
223
248
|
date: TemporalPoly.PlainDate;
|
|
224
|
-
columnIndex?: number;
|
|
249
|
+
columnIndex?: number | undefined;
|
|
225
250
|
children?: React.ReactNode;
|
|
226
251
|
_derivedState: DayCellTemplateState & { isTabTarget: boolean };
|
|
227
252
|
[key: string]: unknown;
|
|
228
253
|
}
|
|
229
254
|
|
|
230
|
-
function DayCellInstanceFn
|
|
231
|
-
const { render, date, columnIndex, children, _derivedState, ...otherProps } =
|
|
255
|
+
function DayCellInstanceFn(props: DayCellInstanceProps) {
|
|
256
|
+
const { render, date, columnIndex, children, _derivedState, ...otherProps } =
|
|
257
|
+
props;
|
|
232
258
|
|
|
233
|
-
const state = _derivedState as unknown as DayCellTemplateState
|
|
259
|
+
const state = _derivedState as unknown as DayCellTemplateState;
|
|
234
260
|
|
|
235
261
|
const defaultProps: Record<string, unknown> = state.hidden
|
|
236
262
|
? {
|
|
@@ -254,7 +280,8 @@ function DayCellInstanceFn<F extends ValueFormat = ValueFormat>(props: DayCellIn
|
|
|
254
280
|
props: mergeProps<"td">(defaultProps, otherProps),
|
|
255
281
|
});
|
|
256
282
|
|
|
257
|
-
const outsideDisabled =
|
|
283
|
+
const outsideDisabled =
|
|
284
|
+
state.hidden || (state.outsideMonth && state.disabled);
|
|
258
285
|
|
|
259
286
|
return (
|
|
260
287
|
<DayCellDataContext.Provider value={{ date, columnIndex, outsideDisabled }}>
|
|
@@ -318,9 +345,7 @@ const DayCellInstance = memo(
|
|
|
318
345
|
* When used inside a {@link WeekTemplate}, iterates over that week's days.
|
|
319
346
|
* An explicit `date` prop renders a single cell.
|
|
320
347
|
*/
|
|
321
|
-
export function DayCellTemplate
|
|
322
|
-
props: DayCellTemplateProps<F>,
|
|
323
|
-
) {
|
|
348
|
+
export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
324
349
|
const { date: dateProp, ...restProps } = props;
|
|
325
350
|
const weekData = useContext(WeekDataContext);
|
|
326
351
|
|
|
@@ -332,7 +357,8 @@ export function DayCellTemplate<F extends ValueFormat = ValueFormat>(
|
|
|
332
357
|
weekStartDay,
|
|
333
358
|
} = useCalendarStable();
|
|
334
359
|
|
|
335
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
360
|
+
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
361
|
+
useCalendarState();
|
|
336
362
|
|
|
337
363
|
const viewCtx = useViewContext();
|
|
338
364
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
@@ -354,7 +380,9 @@ export function DayCellTemplate<F extends ValueFormat = ValueFormat>(
|
|
|
354
380
|
|
|
355
381
|
if (dateProp) {
|
|
356
382
|
const daysInWeek = dateProp.daysInWeek;
|
|
357
|
-
const colIdx =
|
|
383
|
+
const colIdx =
|
|
384
|
+
((dateProp.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
|
|
385
|
+
daysInWeek;
|
|
358
386
|
const derived = computeDayCellState(
|
|
359
387
|
dateProp,
|
|
360
388
|
orientation,
|
|
@@ -374,7 +402,9 @@ export function DayCellTemplate<F extends ValueFormat = ValueFormat>(
|
|
|
374
402
|
previewStart,
|
|
375
403
|
previewEnd,
|
|
376
404
|
);
|
|
377
|
-
return
|
|
405
|
+
return (
|
|
406
|
+
<DayCellInstance {...restProps} date={dateProp} _derivedState={derived} />
|
|
407
|
+
);
|
|
378
408
|
}
|
|
379
409
|
|
|
380
410
|
const days = weekData ? weekData.days : weeks.flat();
|
|
@@ -386,7 +416,8 @@ export function DayCellTemplate<F extends ValueFormat = ValueFormat>(
|
|
|
386
416
|
const daysInWeek = day.daysInWeek;
|
|
387
417
|
const colIdx = perWeek
|
|
388
418
|
? i
|
|
389
|
-
: ((day.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
|
|
419
|
+
: ((day.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) %
|
|
420
|
+
daysInWeek;
|
|
390
421
|
const derived = computeDayCellState(
|
|
391
422
|
day,
|
|
392
423
|
orientation,
|
|
@@ -421,14 +452,17 @@ export function DayCellTemplate<F extends ValueFormat = ValueFormat>(
|
|
|
421
452
|
}
|
|
422
453
|
|
|
423
454
|
/** Props for the memoized DayButtonInstance. */
|
|
424
|
-
interface DayButtonInnerProps
|
|
425
|
-
render?: DayButtonProps
|
|
455
|
+
interface DayButtonInnerProps {
|
|
456
|
+
render?: DayButtonProps["render"];
|
|
426
457
|
date: TemporalPoly.PlainDate;
|
|
427
458
|
_derivedState?: DayCellTemplateState & { isTabTarget: boolean };
|
|
428
459
|
[key: string]: unknown;
|
|
429
460
|
}
|
|
430
461
|
|
|
431
|
-
function DayButtonInnerFn(
|
|
462
|
+
function DayButtonInnerFn(
|
|
463
|
+
props: DayButtonInnerProps,
|
|
464
|
+
ref: React.ForwardedRef<HTMLButtonElement>,
|
|
465
|
+
) {
|
|
432
466
|
const { render, date, _derivedState, ...otherProps } = props;
|
|
433
467
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
434
468
|
const { setFocusedDate } = useViewContext();
|
|
@@ -443,7 +477,10 @@ function DayButtonInnerFn(props: DayButtonInnerProps, ref: React.ForwardedRef<HT
|
|
|
443
477
|
const isDisabled = _derivedState?.disabled ?? false;
|
|
444
478
|
|
|
445
479
|
useEffect(() => {
|
|
446
|
-
if (
|
|
480
|
+
if (
|
|
481
|
+
shouldMoveDomFocus(isFocused, gridFocusedRef.current) &&
|
|
482
|
+
internalRef.current
|
|
483
|
+
) {
|
|
447
484
|
internalRef.current.focus();
|
|
448
485
|
}
|
|
449
486
|
}, [isFocused, gridFocusedRef]);
|
|
@@ -528,8 +565,8 @@ function dayButtonInnerPropsAreEqual(
|
|
|
528
565
|
const DayButtonInner = memo(
|
|
529
566
|
forwardRef(DayButtonInnerFn as any) as any,
|
|
530
567
|
dayButtonInnerPropsAreEqual as any,
|
|
531
|
-
) as unknown as
|
|
532
|
-
props: DayButtonInnerProps
|
|
568
|
+
) as unknown as (
|
|
569
|
+
props: DayButtonInnerProps & React.RefAttributes<HTMLButtonElement>,
|
|
533
570
|
) => React.ReactElement | null;
|
|
534
571
|
|
|
535
572
|
/**
|
|
@@ -570,8 +607,8 @@ function DayButtonFn(
|
|
|
570
607
|
);
|
|
571
608
|
}
|
|
572
609
|
|
|
573
|
-
export const DayButton = forwardRef(DayButtonFn) as
|
|
574
|
-
props: DayButtonProps
|
|
610
|
+
export const DayButton = forwardRef(DayButtonFn) as (
|
|
611
|
+
props: DayButtonProps & {
|
|
575
612
|
_derivedState?: DayCellTemplateState & { isTabTarget: boolean };
|
|
576
613
|
} & React.RefAttributes<HTMLButtonElement>,
|
|
577
614
|
) => React.ReactElement | null;
|
|
@@ -591,7 +628,8 @@ function DayButtonFallbackFn(
|
|
|
591
628
|
temporal: T,
|
|
592
629
|
weekStartDay,
|
|
593
630
|
} = useCalendarStable();
|
|
594
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
631
|
+
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } =
|
|
632
|
+
useCalendarState();
|
|
595
633
|
const viewCtx = useViewContext();
|
|
596
634
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
597
635
|
const monthStable = useContext(MonthViewStableContext);
|
|
@@ -604,7 +642,8 @@ function DayButtonFallbackFn(
|
|
|
604
642
|
? { year: date.year, month: date.month }
|
|
605
643
|
: (weekData?.gridMonth ?? currentDateTime);
|
|
606
644
|
const daysInWeek = date.daysInWeek;
|
|
607
|
-
const colIdx =
|
|
645
|
+
const colIdx =
|
|
646
|
+
((date.dayOfWeek % daysInWeek) - weekStartDay + daysInWeek) % daysInWeek;
|
|
608
647
|
const derived = computeDayCellState(
|
|
609
648
|
date,
|
|
610
649
|
orientation,
|
|
@@ -625,11 +664,18 @@ function DayButtonFallbackFn(
|
|
|
625
664
|
previewEnd,
|
|
626
665
|
);
|
|
627
666
|
|
|
628
|
-
return
|
|
667
|
+
return (
|
|
668
|
+
<DayButtonInner
|
|
669
|
+
{...restProps}
|
|
670
|
+
ref={ref}
|
|
671
|
+
date={date}
|
|
672
|
+
_derivedState={derived}
|
|
673
|
+
/>
|
|
674
|
+
);
|
|
629
675
|
}
|
|
630
676
|
|
|
631
|
-
const DayButtonFallback = forwardRef(DayButtonFallbackFn) as
|
|
632
|
-
props: Omit<DayButtonProps
|
|
677
|
+
const DayButtonFallback = forwardRef(DayButtonFallbackFn) as (
|
|
678
|
+
props: Omit<DayButtonProps, "date"> & {
|
|
633
679
|
date: TemporalPoly.PlainDate;
|
|
634
680
|
} & React.RefAttributes<HTMLButtonElement>,
|
|
635
681
|
) => React.ReactElement | null;
|
package/src/drag-handle.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import { DayCellDataContext, GridContext } from "./context";
|
|
|
6
6
|
import { useMonthViewState } from "./month-view-context";
|
|
7
7
|
import type { StateAttributesMapping } from "./types";
|
|
8
8
|
import type {
|
|
9
|
-
ValueFormat,
|
|
10
9
|
DragHandleState,
|
|
11
10
|
RangeStartDragHandleProps,
|
|
12
11
|
RangeEndDragHandleProps,
|
|
@@ -21,11 +20,16 @@ const dragHandleStateAttributesMapping = {
|
|
|
21
20
|
orientation: (v) => ({ "data-orientation": v }),
|
|
22
21
|
} as const satisfies StateAttributesMapping<DragHandleState>;
|
|
23
22
|
|
|
24
|
-
function useDragHandle
|
|
23
|
+
function useDragHandle(
|
|
25
24
|
edge: "start" | "end",
|
|
26
|
-
{ dragging: draggingProp }: { dragging?: boolean },
|
|
25
|
+
{ dragging: draggingProp }: { dragging?: boolean | undefined },
|
|
27
26
|
) {
|
|
28
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
temporal: T,
|
|
29
|
+
setHoveredDate,
|
|
30
|
+
readOnly,
|
|
31
|
+
disabled,
|
|
32
|
+
} = useCalendarStable();
|
|
29
33
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
30
34
|
const { rootState } = useMonthViewState();
|
|
31
35
|
const cellData = useContext(DayCellDataContext);
|
|
@@ -40,13 +44,12 @@ function useDragHandle<F extends ValueFormat = ValueFormat>(
|
|
|
40
44
|
? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0)
|
|
41
45
|
: !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
|
|
42
46
|
|
|
43
|
-
const isDragging =
|
|
44
|
-
|
|
47
|
+
const isDragging = !!draggingProp && isActive;
|
|
45
48
|
const handleRef = useRef<HTMLSpanElement>(null);
|
|
46
49
|
|
|
47
|
-
const state = useMemo<DragHandleState
|
|
50
|
+
const state = useMemo<DragHandleState>(
|
|
48
51
|
() => ({
|
|
49
|
-
root: rootState
|
|
52
|
+
root: rootState,
|
|
50
53
|
active: isActive,
|
|
51
54
|
dragging: isDragging,
|
|
52
55
|
edge,
|
|
@@ -75,11 +78,13 @@ function useDragHandle<F extends ValueFormat = ValueFormat>(
|
|
|
75
78
|
};
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
function RangeDragHandleFn(
|
|
81
|
+
function RangeDragHandleFn(
|
|
82
|
+
props: RangeDragHandleProps,
|
|
83
|
+
ref: React.ForwardedRef<HTMLSpanElement>,
|
|
84
|
+
) {
|
|
79
85
|
const { render, dragging, edge, ...otherProps } = props;
|
|
80
|
-
const { state, stateAttributesMapping, defaultProps, handleRef } =
|
|
81
|
-
dragging
|
|
82
|
-
});
|
|
86
|
+
const { state, stateAttributesMapping, defaultProps, handleRef } =
|
|
87
|
+
useDragHandle(edge, { dragging });
|
|
83
88
|
const { selectionMode } = useCalendarStable();
|
|
84
89
|
const { rangeStart: rs, rangeEnd: re } = useCalendarState();
|
|
85
90
|
const rangeIncomplete = !rs || !re;
|
|
@@ -102,10 +107,8 @@ function RangeDragHandleFn(props: RangeDragHandleProps, ref: React.ForwardedRef<
|
|
|
102
107
|
* Drag handle (`<span>`) rendered at a range boundary. Exposes
|
|
103
108
|
* `data-active`, `data-dragging`, and `data-edge` attributes.
|
|
104
109
|
*/
|
|
105
|
-
export const RangeDragHandle = forwardRef(RangeDragHandleFn) as
|
|
106
|
-
|
|
107
|
-
>(
|
|
108
|
-
props: RangeDragHandleProps<F> & React.RefAttributes<HTMLSpanElement>,
|
|
110
|
+
export const RangeDragHandle = forwardRef(RangeDragHandleFn) as (
|
|
111
|
+
props: RangeDragHandleProps & React.RefAttributes<HTMLSpanElement>,
|
|
109
112
|
) => React.ReactElement | null;
|
|
110
113
|
|
|
111
114
|
function RangeStartDragHandleFn(
|
|
@@ -116,10 +119,8 @@ function RangeStartDragHandleFn(
|
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
/** Convenience wrapper for {@link RangeDragHandle} with `edge="start"`. */
|
|
119
|
-
export const RangeStartDragHandle = forwardRef(RangeStartDragHandleFn) as
|
|
120
|
-
|
|
121
|
-
>(
|
|
122
|
-
props: RangeStartDragHandleProps<F> & React.RefAttributes<HTMLSpanElement>,
|
|
122
|
+
export const RangeStartDragHandle = forwardRef(RangeStartDragHandleFn) as (
|
|
123
|
+
props: RangeStartDragHandleProps & React.RefAttributes<HTMLSpanElement>,
|
|
123
124
|
) => React.ReactElement | null;
|
|
124
125
|
|
|
125
126
|
function RangeEndDragHandleFn(
|
|
@@ -130,8 +131,6 @@ function RangeEndDragHandleFn(
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
/** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
|
|
133
|
-
export const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn) as
|
|
134
|
-
|
|
135
|
-
>(
|
|
136
|
-
props: RangeEndDragHandleProps<F> & React.RefAttributes<HTMLSpanElement>,
|
|
134
|
+
export const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn) as (
|
|
135
|
+
props: RangeEndDragHandleProps & React.RefAttributes<HTMLSpanElement>,
|
|
137
136
|
) => React.ReactElement | null;
|
package/src/formats/date.ts
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
// @generated by scripts/generate-formats.ts — do not edit manually
|
|
2
2
|
type F = "Date";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { CalendarProvider as _CalendarProvider } from "../calendar-provider";
|
|
5
|
+
const CalendarProvider = _CalendarProvider<F>;
|
|
6
|
+
export { CalendarProvider };
|
|
7
|
+
|
|
8
|
+
import { MonthView as _MonthView } from "../month-view";
|
|
9
|
+
const MonthView = _MonthView<F>;
|
|
10
|
+
export { MonthView };
|
|
11
|
+
export { MonthViewRoot } from "../month-view";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
Grid,
|
|
15
|
+
GridBody,
|
|
16
|
+
WeekTemplate,
|
|
17
|
+
DayCellTemplate,
|
|
18
|
+
DayButton,
|
|
19
|
+
} from "../grid";
|
|
9
20
|
|
|
10
21
|
export { GridHeader, GridHeaderCell } from "../grid-header";
|
|
11
22
|
|
|
12
|
-
export {
|
|
23
|
+
export {
|
|
24
|
+
DateString,
|
|
25
|
+
TimeString,
|
|
26
|
+
MonthYearString,
|
|
27
|
+
PrevMonthButton,
|
|
28
|
+
NextMonthButton,
|
|
29
|
+
} from "../navigation";
|
|
13
30
|
|
|
14
31
|
export { RangeSelected } from "../selected-range";
|
|
15
32
|
|
|
@@ -21,9 +38,20 @@ export { WeekNumberCell, WeekNumberHeader } from "../week-number";
|
|
|
21
38
|
|
|
22
39
|
export { WeeksView, WeeksViewRoot } from "../weeks-view";
|
|
23
40
|
|
|
24
|
-
export {
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
export {
|
|
42
|
+
PrevWeeksButton,
|
|
43
|
+
NextWeeksButton,
|
|
44
|
+
WeekCount,
|
|
45
|
+
} from "../weeks-navigation";
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
MonthSeparator,
|
|
49
|
+
MonthSeparatorRow,
|
|
50
|
+
MonthSeparatorCell,
|
|
51
|
+
MonthSeparatorMonth,
|
|
52
|
+
MonthSeparatorYear,
|
|
53
|
+
MonthSeparatorWeekCount,
|
|
54
|
+
} from "../month-separator";
|
|
27
55
|
|
|
28
56
|
export { computePreviewRange } from "../root-selection";
|
|
29
57
|
|
|
@@ -31,8 +59,6 @@ export { computeWeeksInWindow } from "../compute-weeks-in-window";
|
|
|
31
59
|
|
|
32
60
|
export { resolveFirstWeek, resolveFirstWeekSpec } from "../resolve-first-week";
|
|
33
61
|
|
|
34
|
-
export { Temporal } from "../temporal-polyfill";
|
|
35
|
-
|
|
36
62
|
export { useCalendarStable, useCalendarState } from "../calendar-context";
|
|
37
63
|
|
|
38
64
|
export { useMonthViewStable, useMonthViewState } from "../month-view-context";
|
|
@@ -41,63 +67,101 @@ export { useViewContext } from "../view-context";
|
|
|
41
67
|
|
|
42
68
|
export { DayCellDataContext, WeekDataContext, GridContext } from "../context";
|
|
43
69
|
|
|
44
|
-
import type {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export type GridHeaderState = _GridHeaderState<F>;
|
|
50
|
-
export type GridHeaderCellProps = _GridHeaderCellProps<F>;
|
|
51
|
-
export type GridHeaderCellState = _GridHeaderCellState<F>;
|
|
52
|
-
export type GridBodyProps = _GridBodyProps<F>;
|
|
53
|
-
export type GridBodyState = _GridBodyState<F>;
|
|
54
|
-
export type WeekTemplateProps = _WeekTemplateProps<F>;
|
|
55
|
-
export type WeekTemplateState = _WeekTemplateState<F>;
|
|
56
|
-
export type DayCellTemplateProps = _DayCellTemplateProps<F>;
|
|
57
|
-
export type DayCellTemplateState = _DayCellTemplateState<F>;
|
|
58
|
-
export type DayButtonProps = _DayButtonProps<F>;
|
|
59
|
-
export type DayButtonState = _DayButtonState<F>;
|
|
60
|
-
export type RangeSelectedProps = _RangeSelectedProps<F>;
|
|
61
|
-
export type RangeSelectedState = _RangeSelectedState<F>;
|
|
62
|
-
export type RangePreviewProps = _RangePreviewProps<F>;
|
|
63
|
-
export type RangePreviewState = _RangePreviewState<F>;
|
|
64
|
-
export type DragHandleState = _DragHandleState<F>;
|
|
65
|
-
export type RangeStartDragHandleProps = _RangeStartDragHandleProps<F>;
|
|
66
|
-
export type RangeEndDragHandleProps = _RangeEndDragHandleProps<F>;
|
|
67
|
-
export type DateStringProps = _DateStringProps<F>;
|
|
68
|
-
export type DateStringState = _DateStringState<F>;
|
|
69
|
-
export type TimeStringProps = _TimeStringProps<F>;
|
|
70
|
-
export type TimeStringState = _TimeStringState<F>;
|
|
71
|
-
export type MonthYearStringProps = _MonthYearStringProps<F>;
|
|
72
|
-
export type MonthYearStringState = _MonthYearStringState<F>;
|
|
73
|
-
export type PrevMonthButtonProps = _PrevMonthButtonProps<F>;
|
|
74
|
-
export type NextMonthButtonProps = _NextMonthButtonProps<F>;
|
|
75
|
-
export type NavButtonState = _NavButtonState<F>;
|
|
70
|
+
import type {
|
|
71
|
+
DateRange as _DateRange,
|
|
72
|
+
ValueForFormat as _ValueForFormat,
|
|
73
|
+
RawValueForFormat as _RawValueForFormat,
|
|
74
|
+
} from "../types";
|
|
76
75
|
export type DateRange = _DateRange<F>;
|
|
77
76
|
export type ValueForFormat = _ValueForFormat<F>;
|
|
78
77
|
export type RawValueForFormat = _RawValueForFormat<F>;
|
|
79
|
-
export type
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
export type {
|
|
79
|
+
RootState,
|
|
80
|
+
GridProps,
|
|
81
|
+
GridState,
|
|
82
|
+
GridHeaderProps,
|
|
83
|
+
GridHeaderState,
|
|
84
|
+
GridHeaderCellProps,
|
|
85
|
+
GridHeaderCellState,
|
|
86
|
+
GridBodyProps,
|
|
87
|
+
GridBodyState,
|
|
88
|
+
WeekTemplateProps,
|
|
89
|
+
WeekTemplateState,
|
|
90
|
+
DayCellTemplateProps,
|
|
91
|
+
DayCellTemplateState,
|
|
92
|
+
DayButtonProps,
|
|
93
|
+
DayButtonState,
|
|
94
|
+
RangeSelectedProps,
|
|
95
|
+
RangeSelectedState,
|
|
96
|
+
RangePreviewProps,
|
|
97
|
+
RangePreviewState,
|
|
98
|
+
DragHandleOwnProps,
|
|
99
|
+
DragHandleState,
|
|
100
|
+
RangeStartDragHandleProps,
|
|
101
|
+
RangeEndDragHandleProps,
|
|
102
|
+
DateStringProps,
|
|
103
|
+
DateStringState,
|
|
104
|
+
TimeStringProps,
|
|
105
|
+
TimeStringState,
|
|
106
|
+
MonthYearStringProps,
|
|
107
|
+
MonthYearStringState,
|
|
108
|
+
PrevMonthButtonProps,
|
|
109
|
+
NextMonthButtonProps,
|
|
110
|
+
NavButtonState,
|
|
111
|
+
ValueFormat,
|
|
112
|
+
DateValueObject,
|
|
113
|
+
PlainDateObject,
|
|
114
|
+
TemporalNamespace,
|
|
115
|
+
WeekStartDay,
|
|
116
|
+
RangeMode,
|
|
117
|
+
OutsideDays,
|
|
118
|
+
ValueChangeMeta,
|
|
119
|
+
WeekNumberCellProps,
|
|
120
|
+
WeekNumberCellState,
|
|
121
|
+
WeekNumberHeaderProps,
|
|
122
|
+
WeekNumberHeaderState,
|
|
123
|
+
MonthData,
|
|
124
|
+
} from "../types";
|
|
84
125
|
|
|
85
126
|
import type { CalendarProviderProps as _CalendarProviderProps } from "../calendar-types";
|
|
86
127
|
export type CalendarProviderProps = _CalendarProviderProps<F>;
|
|
87
128
|
|
|
88
|
-
export type {
|
|
129
|
+
export type {
|
|
130
|
+
CalendarStableContextValue,
|
|
131
|
+
CalendarStateContextValue,
|
|
132
|
+
} from "../calendar-types";
|
|
89
133
|
|
|
90
|
-
export type {
|
|
134
|
+
export type {
|
|
135
|
+
MonthViewRootProps,
|
|
136
|
+
MonthViewStableContextValue,
|
|
137
|
+
MonthViewStateContextValue,
|
|
138
|
+
} from "../month-view-types";
|
|
91
139
|
|
|
92
|
-
|
|
140
|
+
import type { MonthViewProps as _MonthViewProps } from "../month-view";
|
|
141
|
+
export type MonthViewProps = _MonthViewProps<F>;
|
|
93
142
|
|
|
94
143
|
export type { ViewContextValue } from "../view-context";
|
|
95
144
|
|
|
96
|
-
export type {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
145
|
+
export type {
|
|
146
|
+
WeeksViewRootProps,
|
|
147
|
+
WeeksViewStableContextValue,
|
|
148
|
+
WeeksViewStateContextValue,
|
|
149
|
+
WindowInfo,
|
|
150
|
+
VisibleMonth,
|
|
151
|
+
} from "../weeks-view-types";
|
|
152
|
+
|
|
153
|
+
import type { WeeksViewProps as _WeeksViewProps } from "../weeks-view";
|
|
154
|
+
export type WeeksViewProps = _WeeksViewProps<F>;
|
|
155
|
+
export type { WeeksViewRootHandle } from "../weeks-view";
|
|
156
|
+
|
|
157
|
+
export type {
|
|
158
|
+
WeeksNavButtonState,
|
|
159
|
+
WeeksNavButtonOwnProps,
|
|
160
|
+
PrevWeeksButtonProps,
|
|
161
|
+
NextWeeksButtonProps,
|
|
162
|
+
WeekCountState,
|
|
163
|
+
WeekCountProps,
|
|
164
|
+
} from "../weeks-navigation";
|
|
101
165
|
|
|
102
166
|
export { useWeeksViewStable, useWeeksViewState } from "../weeks-view-context";
|
|
103
167
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import * as root from "@klinking/colander";
|
|
2
3
|
import { describe, it, expect } from "vitest";
|
|
3
4
|
|
|
4
|
-
const formatModules = import.meta.glob<Record<string, unknown>>(
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const formatModules = import.meta.glob<Record<string, unknown>>(
|
|
6
|
+
["./*.ts", "!./*.test.ts"],
|
|
7
|
+
{
|
|
8
|
+
eager: true,
|
|
9
|
+
},
|
|
10
|
+
);
|
|
7
11
|
|
|
8
12
|
describe("format subpath exports", () => {
|
|
9
13
|
const rootKeys = Object.keys(root).sort();
|