@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,127 @@
|
|
|
1
|
+
import type { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
|
|
3
|
+
import { CalendarProvider } from "./calendar-provider";
|
|
4
|
+
import type { CalendarProviderProps } from "./calendar-types";
|
|
5
|
+
import { MonthViewStableContext, MonthViewStateContext } from "./month-view-context";
|
|
6
|
+
import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
|
|
7
|
+
import type { RootState, ValueFormat } from "./types";
|
|
8
|
+
import { ViewContext } from "./view-context";
|
|
9
|
+
import { WeeksViewStableContext, WeeksViewStateContext } from "./weeks-view-context";
|
|
10
|
+
import { useWeeksViewRootState } from "./weeks-view-state";
|
|
11
|
+
import type { WeeksViewRootProps } from "./weeks-view-types";
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// WeeksView.Root — placed inside CalendarProvider
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
/** Imperative handle exposed by WeeksView.Root via ref. */
|
|
18
|
+
export interface WeeksViewRootHandle {
|
|
19
|
+
scrollToWeek: (target: FirstWeekSpec, options?: { snap?: ScrollToWeekSnap }) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function WeeksViewRootFn(props: WeeksViewRootProps, ref: React.ForwardedRef<WeeksViewRootHandle>) {
|
|
23
|
+
const { children } = props;
|
|
24
|
+
const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
25
|
+
|
|
26
|
+
useImperativeHandle(ref, () => ({ scrollToWeek }), [scrollToWeek]);
|
|
27
|
+
|
|
28
|
+
const gridFocusedRef = useRef(false);
|
|
29
|
+
|
|
30
|
+
// Provide MonthViewStableContext/MonthViewStateContext shims so shared
|
|
31
|
+
// components (WeeksNavButton, WeekCount, etc.) that read rootState via
|
|
32
|
+
// useMonthViewState() can function outside the Grid in WeeksView.
|
|
33
|
+
const monthViewStableShim = useMemo(
|
|
34
|
+
() => ({
|
|
35
|
+
numberOfMonths: 1,
|
|
36
|
+
fixedWeeks: false,
|
|
37
|
+
outsideDays: "enabled" as const,
|
|
38
|
+
overflowBehavior: "unbounded" as const,
|
|
39
|
+
goNextMonth: () => {},
|
|
40
|
+
goPrevMonth: () => {},
|
|
41
|
+
setGridLabelId: () => {},
|
|
42
|
+
gridFocusedRef,
|
|
43
|
+
}),
|
|
44
|
+
[],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const monthViewStateShim = useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
currentMonth: {
|
|
50
|
+
year: stateCtx.currentDateTime.year,
|
|
51
|
+
month: stateCtx.currentDateTime.month,
|
|
52
|
+
},
|
|
53
|
+
weeks: [] as Temporal.PlainDate[][],
|
|
54
|
+
allMonths: [],
|
|
55
|
+
currentDateTime: stateCtx.currentDateTime,
|
|
56
|
+
gridLabelIds: stateCtx.gridLabelIds,
|
|
57
|
+
rootState: {} as RootState,
|
|
58
|
+
}),
|
|
59
|
+
[stateCtx.currentDateTime, stateCtx.gridLabelIds],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<MonthViewStableContext.Provider value={monthViewStableShim}>
|
|
64
|
+
<MonthViewStateContext.Provider value={monthViewStateShim}>
|
|
65
|
+
<WeeksViewStableContext.Provider value={stableCtx}>
|
|
66
|
+
<WeeksViewStateContext.Provider value={stateCtx}>
|
|
67
|
+
<ViewContext.Provider value={viewCtx}>{children}</ViewContext.Provider>
|
|
68
|
+
</WeeksViewStateContext.Provider>
|
|
69
|
+
</WeeksViewStableContext.Provider>
|
|
70
|
+
</MonthViewStateContext.Provider>
|
|
71
|
+
</MonthViewStableContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const WeeksViewRoot = forwardRef(WeeksViewRootFn);
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// WeeksView convenience wrapper — composes CalendarProvider + WeeksView.Root
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
type WeeksViewProps<F extends ValueFormat = "PlainDate"> = CalendarProviderProps<F> &
|
|
82
|
+
WeeksViewRootProps;
|
|
83
|
+
|
|
84
|
+
function WeeksViewFn(props: WeeksViewProps, ref: React.ForwardedRef<WeeksViewRootHandle>) {
|
|
85
|
+
const {
|
|
86
|
+
weekCount,
|
|
87
|
+
firstWeek,
|
|
88
|
+
defaultFirstWeek,
|
|
89
|
+
onFirstWeekChange,
|
|
90
|
+
scrollBy,
|
|
91
|
+
overflowBehavior,
|
|
92
|
+
onWindowChange,
|
|
93
|
+
children,
|
|
94
|
+
...calendarProps
|
|
95
|
+
} = props as WeeksViewProps & { children?: React.ReactNode };
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<CalendarProvider {...(calendarProps as CalendarProviderProps)}>
|
|
99
|
+
<WeeksViewRoot
|
|
100
|
+
ref={ref}
|
|
101
|
+
weekCount={weekCount}
|
|
102
|
+
firstWeek={firstWeek}
|
|
103
|
+
defaultFirstWeek={defaultFirstWeek}
|
|
104
|
+
onFirstWeekChange={onFirstWeekChange}
|
|
105
|
+
scrollBy={scrollBy}
|
|
106
|
+
overflowBehavior={overflowBehavior}
|
|
107
|
+
onWindowChange={onWindowChange}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</WeeksViewRoot>
|
|
111
|
+
</CalendarProvider>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const WeeksView = forwardRef(WeeksViewFn) as WeeksViewComponent;
|
|
116
|
+
|
|
117
|
+
// Attach Root as a static property
|
|
118
|
+
interface WeeksViewComponent extends React.ForwardRefExoticComponent<
|
|
119
|
+
WeeksViewProps & React.RefAttributes<WeeksViewRootHandle>
|
|
120
|
+
> {
|
|
121
|
+
Root: typeof WeeksViewRoot;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
(WeeksView as WeeksViewComponent).Root = WeeksViewRoot;
|
|
125
|
+
|
|
126
|
+
export { WeeksView, WeeksViewRoot };
|
|
127
|
+
export type { WeeksViewProps };
|