From eb1cdcd1ed26cc9b39eb85cd0e1de126cc859fae Mon Sep 17 00:00:00 2001 From: Klink <85062+dogmar@users.noreply.github.com> Date: Sun, 14 Jun 2026 13:57:23 -0700 Subject: [PATCH 1/2] fix!: expose honest Temporal values in RootState; remove type lies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: the render-prop `RootState` (`state.root`) now exposes all selection values as `Temporal.PlainDate` instead of the configured value `format`. The format-typed values still flow via `value`/`defaultValue`/`onValueChange`; `RootState` is for rendering (e.g. `selected?.toLocaleString(locale)`). `focused`/`viewing` were already Temporal. `RootState` is now non-generic. Fixes two runtime lies the audit flagged: - MonthView built `selectedDates`/`rangeStart`/`rangeEnd` with `as any` (PlainDate behind a format type) and `selected` as the format value; now all are honest PlainDate. - WeeksView's MonthViewState shims used `{} as RootState`, so every `state.root` field read `undefined` inside WeeksView. Now both the WeeksView-root and inner-Grid shims expose a real, populated rootState. The selection part of rootState is built once in CalendarProvider (`baseRootState`, on the calendar state context) and spread by each view, which adds its own `focused`/`viewing` — so MonthView and WeeksView are identical. `selected` is the first committed date (the PlainDate behind the old `selected` DateValueObject). Because the date fields are no longer format-typed, `RootState` and the ~15 leaf component State/Props types that referenced `RootState` lose their now-unused `` generic (the leaf display components become non-generic). Genuinely format-generic types (Root/MonthView/WeeksView/ CalendarProvider, DateRange, RawValueForFormat) keep `F`. Removes ~12 `as any` and 2 `{} as RootState` casts; format subpaths regenerated. Adds regression tests: MonthView rootState exposes PlainDate under format="Date" (was a JS Date); WeeksView shim rootState is populated (was all undefined). Co-Authored-By: Claude Opus 4.8 --- package/src/calendar-provider.tsx | 17 ++ package/src/calendar-types.ts | 7 + package/src/day-cell.tsx | 35 ++-- package/src/drag-handle.tsx | 25 +-- package/src/formats/date.ts | 181 +++++------------ package/src/formats/object.ts | 181 +++++------------ package/src/formats/plain-date-time.ts | 181 +++++------------ package/src/formats/plain-date.ts | 181 +++++------------ package/src/formats/plain-month-day.ts | 181 +++++------------ package/src/formats/plain-year-month.ts | 181 +++++------------ package/src/formats/zoned-date-time.ts | 181 +++++------------ package/src/grid-header.tsx | 19 +- package/src/grid.tsx | 48 ++--- package/src/month-view.test.tsx | 43 ++++ package/src/month-view.tsx | 25 +-- package/src/navigation.tsx | 45 ++--- package/src/range-preview.tsx | 20 +- package/src/selected-range.tsx | 15 +- package/src/types.ts | 210 ++++++++++++-------- package/src/week-number.tsx | 13 +- package/src/weeks-navigation.tsx | 4 +- package/src/weeks-view-state.ts | 26 ++- package/src/weeks-view-types.ts | 3 + package/src/weeks-view.test.tsx | 49 +++++ package/src/weeks-view.tsx | 6 +- website/src/examples/date-picker-styled.tsx | 49 +++-- website/src/lib/drag-components.tsx | 6 +- 27 files changed, 750 insertions(+), 1182 deletions(-) diff --git a/package/src/calendar-provider.tsx b/package/src/calendar-provider.tsx index f12641f..95e5f8b 100644 --- a/package/src/calendar-provider.tsx +++ b/package/src/calendar-provider.tsx @@ -18,6 +18,7 @@ import { type SelectionResult, } from "./root-selection"; import type { + BaseRootState, DateRange, DateValueObject, RangeMode, @@ -582,6 +583,20 @@ function CalendarProvider( ], ); + const baseRootState = useMemo( + () => ({ + hasSelection: nonNullDates.length > 0, + selected: nonNullDates[0], + selectedDates: nonNullDates, + rangeStart, + rangeEnd, + timeZone, + locale, + readOnly, + }), + [nonNullDates, rangeStart, rangeEnd, timeZone, locale, readOnly], + ); + const stateCtx = useMemo( () => ({ selected, @@ -591,6 +606,7 @@ function CalendarProvider( hoveredDate, previewStart, previewEnd, + baseRootState, }), [ selected, @@ -600,6 +616,7 @@ function CalendarProvider( hoveredDate, previewStart, previewEnd, + baseRootState, ], ); diff --git a/package/src/calendar-types.ts b/package/src/calendar-types.ts index 3ff8d47..dda7833 100644 --- a/package/src/calendar-types.ts +++ b/package/src/calendar-types.ts @@ -1,5 +1,6 @@ import type { Temporal } from "@js-temporal/polyfill"; import type { + BaseRootState, DateRange, DateValueObject, RangeMode, @@ -219,4 +220,10 @@ export interface CalendarStateContextValue { previewStart: Temporal.PlainDate | undefined; /** End of the computed preview range. */ previewEnd: Temporal.PlainDate | undefined; + /** + * View-independent part of the render-prop `RootState` (selection + resolved + * config), built once here so MonthView and WeeksView expose identical state. + * Each view adds its own `focused`/`viewing`. + */ + baseRootState: BaseRootState; } diff --git a/package/src/day-cell.tsx b/package/src/day-cell.tsx index 83b6996..846ba39 100644 --- a/package/src/day-cell.tsx +++ b/package/src/day-cell.tsx @@ -9,7 +9,6 @@ import { MonthViewStableContext } from "./month-view-context"; import { useMonthViewState } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, DayCellTemplateProps, DayButtonProps, DayCellTemplateState, @@ -244,8 +243,8 @@ export const dayStateAttributesMapping = { } as const satisfies StateAttributesMapping; /** Props for the memoized DayCellInstance. */ -interface DayCellInstanceProps { - render?: DayCellTemplateProps["render"]; +interface DayCellInstanceProps { + render?: DayCellTemplateProps["render"]; date: TemporalPoly.PlainDate; columnIndex?: number | undefined; children?: React.ReactNode; @@ -253,13 +252,11 @@ interface DayCellInstanceProps { [key: string]: unknown; } -function DayCellInstanceFn( - props: DayCellInstanceProps, -) { +function DayCellInstanceFn(props: DayCellInstanceProps) { const { render, date, columnIndex, children, _derivedState, ...otherProps } = props; - const state = _derivedState as unknown as DayCellTemplateState; + const state = _derivedState as unknown as DayCellTemplateState; const defaultProps: Record = state.hidden ? { @@ -348,9 +345,7 @@ const DayCellInstance = memo( * When used inside a {@link WeekTemplate}, iterates over that week's days. * An explicit `date` prop renders a single cell. */ -export function DayCellTemplate( - props: DayCellTemplateProps, -) { +export function DayCellTemplate(props: DayCellTemplateProps) { const { date: dateProp, ...restProps } = props; const weekData = useContext(WeekDataContext); @@ -457,8 +452,8 @@ export function DayCellTemplate( } /** Props for the memoized DayButtonInstance. */ -interface DayButtonInnerProps { - render?: DayButtonProps["render"]; +interface DayButtonInnerProps { + render?: DayButtonProps["render"]; date: TemporalPoly.PlainDate; _derivedState?: DayCellTemplateState & { isTabTarget: boolean }; [key: string]: unknown; @@ -570,8 +565,8 @@ function dayButtonInnerPropsAreEqual( const DayButtonInner = memo( forwardRef(DayButtonInnerFn as any) as any, dayButtonInnerPropsAreEqual as any, -) as unknown as ( - props: DayButtonInnerProps & React.RefAttributes, +) as unknown as ( + props: DayButtonInnerProps & React.RefAttributes, ) => React.ReactElement | null; /** @@ -612,10 +607,8 @@ function DayButtonFn( ); } -export const DayButton = forwardRef(DayButtonFn) as < - F extends ValueFormat = ValueFormat, ->( - props: DayButtonProps & { +export const DayButton = forwardRef(DayButtonFn) as ( + props: DayButtonProps & { _derivedState?: DayCellTemplateState & { isTabTarget: boolean }; } & React.RefAttributes, ) => React.ReactElement | null; @@ -681,10 +674,8 @@ function DayButtonFallbackFn( ); } -const DayButtonFallback = forwardRef(DayButtonFallbackFn) as < - F extends ValueFormat = ValueFormat, ->( - props: Omit, "date"> & { +const DayButtonFallback = forwardRef(DayButtonFallbackFn) as ( + props: Omit & { date: TemporalPoly.PlainDate; } & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/drag-handle.tsx b/package/src/drag-handle.tsx index a1f78f5..6e6c4a7 100644 --- a/package/src/drag-handle.tsx +++ b/package/src/drag-handle.tsx @@ -6,7 +6,6 @@ import { DayCellDataContext, GridContext } from "./context"; import { useMonthViewState } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, DragHandleState, RangeStartDragHandleProps, RangeEndDragHandleProps, @@ -21,7 +20,7 @@ const dragHandleStateAttributesMapping = { orientation: (v) => ({ "data-orientation": v }), } as const satisfies StateAttributesMapping; -function useDragHandle( +function useDragHandle( edge: "start" | "end", { dragging: draggingProp }: { dragging?: boolean | undefined }, ) { @@ -48,9 +47,9 @@ function useDragHandle( const isDragging = !!draggingProp && isActive; const handleRef = useRef(null); - const state = useMemo>( + const state = useMemo( () => ({ - root: rootState as any, + root: rootState, active: isActive, dragging: isDragging, edge, @@ -108,10 +107,8 @@ function RangeDragHandleFn( * Drag handle (``) rendered at a range boundary. Exposes * `data-active`, `data-dragging`, and `data-edge` attributes. */ -export const RangeDragHandle = forwardRef(RangeDragHandleFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangeDragHandleProps & React.RefAttributes, +export const RangeDragHandle = forwardRef(RangeDragHandleFn) as ( + props: RangeDragHandleProps & React.RefAttributes, ) => React.ReactElement | null; function RangeStartDragHandleFn( @@ -122,10 +119,8 @@ function RangeStartDragHandleFn( } /** Convenience wrapper for {@link RangeDragHandle} with `edge="start"`. */ -export const RangeStartDragHandle = forwardRef(RangeStartDragHandleFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangeStartDragHandleProps & React.RefAttributes, +export const RangeStartDragHandle = forwardRef(RangeStartDragHandleFn) as ( + props: RangeStartDragHandleProps & React.RefAttributes, ) => React.ReactElement | null; function RangeEndDragHandleFn( @@ -136,8 +131,6 @@ function RangeEndDragHandleFn( } /** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */ -export const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangeEndDragHandleProps & React.RefAttributes, +export const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn) as ( + props: RangeEndDragHandleProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/formats/date.ts b/package/src/formats/date.ts index dd51723..2d3868c 100644 --- a/package/src/formats/date.ts +++ b/package/src/formats/date.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/object.ts b/package/src/formats/object.ts index 6418475..f33948a 100644 --- a/package/src/formats/object.ts +++ b/package/src/formats/object.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/plain-date-time.ts b/package/src/formats/plain-date-time.ts index cad6d6c..6793aa0 100644 --- a/package/src/formats/plain-date-time.ts +++ b/package/src/formats/plain-date-time.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/plain-date.ts b/package/src/formats/plain-date.ts index d9154b4..953345b 100644 --- a/package/src/formats/plain-date.ts +++ b/package/src/formats/plain-date.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/plain-month-day.ts b/package/src/formats/plain-month-day.ts index 6c985a7..1af2049 100644 --- a/package/src/formats/plain-month-day.ts +++ b/package/src/formats/plain-month-day.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/plain-year-month.ts b/package/src/formats/plain-year-month.ts index 1e18aae..d9a38c2 100644 --- a/package/src/formats/plain-year-month.ts +++ b/package/src/formats/plain-year-month.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/formats/zoned-date-time.ts b/package/src/formats/zoned-date-time.ts index 85b833b..8146710 100644 --- a/package/src/formats/zoned-date-time.ts +++ b/package/src/formats/zoned-date-time.ts @@ -10,71 +10,31 @@ const MonthView = _MonthView; export { MonthView }; export { MonthViewRoot } from "../month-view"; -import { - Grid as _Grid, - GridBody as _GridBody, - WeekTemplate as _WeekTemplate, - DayCellTemplate as _DayCellTemplate, - DayButton as _DayButton, +export { + Grid, + GridBody, + WeekTemplate, + DayCellTemplate, + DayButton, } from "../grid"; -const Grid = _Grid; -const GridBody = _GridBody; -const WeekTemplate = _WeekTemplate; -const DayCellTemplate = _DayCellTemplate; -const DayButton = _DayButton; -export { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton }; - -import { - GridHeader as _GridHeader, - GridHeaderCell as _GridHeaderCell, -} from "../grid-header"; -const GridHeader = _GridHeader; -const GridHeaderCell = _GridHeaderCell; -export { GridHeader, GridHeaderCell }; - -import { - DateString as _DateString, - TimeString as _TimeString, - MonthYearString as _MonthYearString, - PrevMonthButton as _PrevMonthButton, - NextMonthButton as _NextMonthButton, -} from "../navigation"; -const DateString = _DateString; -const TimeString = _TimeString; -const MonthYearString = _MonthYearString; -const PrevMonthButton = _PrevMonthButton; -const NextMonthButton = _NextMonthButton; + +export { GridHeader, GridHeaderCell } from "../grid-header"; + export { DateString, TimeString, MonthYearString, PrevMonthButton, NextMonthButton, -}; - -import { RangeSelected as _RangeSelected } from "../selected-range"; -const RangeSelected = _RangeSelected; -export { RangeSelected }; - -import { RangePreview as _RangePreview } from "../range-preview"; -const RangePreview = _RangePreview; -export { RangePreview }; - -import { - RangeStartDragHandle as _RangeStartDragHandle, - RangeEndDragHandle as _RangeEndDragHandle, -} from "../drag-handle"; -const RangeStartDragHandle = _RangeStartDragHandle; -const RangeEndDragHandle = _RangeEndDragHandle; -export { RangeStartDragHandle, RangeEndDragHandle }; - -import { - WeekNumberCell as _WeekNumberCell, - WeekNumberHeader as _WeekNumberHeader, -} from "../week-number"; -const WeekNumberCell = _WeekNumberCell; -const WeekNumberHeader = _WeekNumberHeader; -export { WeekNumberCell, WeekNumberHeader }; +} from "../navigation"; + +export { RangeSelected } from "../selected-range"; + +export { RangePreview } from "../range-preview"; + +export { RangeStartDragHandle, RangeEndDragHandle } from "../drag-handle"; + +export { WeekNumberCell, WeekNumberHeader } from "../week-number"; export { WeeksView, WeeksViewRoot } from "../weeks-view"; @@ -108,85 +68,46 @@ export { useViewContext } from "../view-context"; export { DayCellDataContext, WeekDataContext, GridContext } from "../context"; import type { - RootState as _RootState, - GridProps as _GridProps, - GridState as _GridState, - GridHeaderProps as _GridHeaderProps, - GridHeaderState as _GridHeaderState, - GridHeaderCellProps as _GridHeaderCellProps, - GridHeaderCellState as _GridHeaderCellState, - GridBodyProps as _GridBodyProps, - GridBodyState as _GridBodyState, - WeekTemplateProps as _WeekTemplateProps, - WeekTemplateState as _WeekTemplateState, - DayCellTemplateProps as _DayCellTemplateProps, - DayCellTemplateState as _DayCellTemplateState, - DayButtonProps as _DayButtonProps, - DayButtonState as _DayButtonState, - RangeSelectedProps as _RangeSelectedProps, - RangeSelectedState as _RangeSelectedState, - RangePreviewProps as _RangePreviewProps, - RangePreviewState as _RangePreviewState, - DragHandleState as _DragHandleState, - RangeStartDragHandleProps as _RangeStartDragHandleProps, - RangeEndDragHandleProps as _RangeEndDragHandleProps, - DateStringProps as _DateStringProps, - DateStringState as _DateStringState, - TimeStringProps as _TimeStringProps, - TimeStringState as _TimeStringState, - MonthYearStringProps as _MonthYearStringProps, - MonthYearStringState as _MonthYearStringState, - PrevMonthButtonProps as _PrevMonthButtonProps, - NextMonthButtonProps as _NextMonthButtonProps, - NavButtonState as _NavButtonState, DateRange as _DateRange, ValueForFormat as _ValueForFormat, RawValueForFormat as _RawValueForFormat, - WeekNumberCellProps as _WeekNumberCellProps, - WeekNumberCellState as _WeekNumberCellState, - WeekNumberHeaderProps as _WeekNumberHeaderProps, - WeekNumberHeaderState as _WeekNumberHeaderState, } from "../types"; -export type RootState = _RootState; -export type GridProps = _GridProps; -export type GridState = _GridState; -export type GridHeaderProps = _GridHeaderProps; -export type GridHeaderState = _GridHeaderState; -export type GridHeaderCellProps = _GridHeaderCellProps; -export type GridHeaderCellState = _GridHeaderCellState; -export type GridBodyProps = _GridBodyProps; -export type GridBodyState = _GridBodyState; -export type WeekTemplateProps = _WeekTemplateProps; -export type WeekTemplateState = _WeekTemplateState; -export type DayCellTemplateProps = _DayCellTemplateProps; -export type DayCellTemplateState = _DayCellTemplateState; -export type DayButtonProps = _DayButtonProps; -export type DayButtonState = _DayButtonState; -export type RangeSelectedProps = _RangeSelectedProps; -export type RangeSelectedState = _RangeSelectedState; -export type RangePreviewProps = _RangePreviewProps; -export type RangePreviewState = _RangePreviewState; -export type DragHandleState = _DragHandleState; -export type RangeStartDragHandleProps = _RangeStartDragHandleProps; -export type RangeEndDragHandleProps = _RangeEndDragHandleProps; -export type DateStringProps = _DateStringProps; -export type DateStringState = _DateStringState; -export type TimeStringProps = _TimeStringProps; -export type TimeStringState = _TimeStringState; -export type MonthYearStringProps = _MonthYearStringProps; -export type MonthYearStringState = _MonthYearStringState; -export type PrevMonthButtonProps = _PrevMonthButtonProps; -export type NextMonthButtonProps = _NextMonthButtonProps; -export type NavButtonState = _NavButtonState; export type DateRange = _DateRange; export type ValueForFormat = _ValueForFormat; export type RawValueForFormat = _RawValueForFormat; -export type WeekNumberCellProps = _WeekNumberCellProps; -export type WeekNumberCellState = _WeekNumberCellState; -export type WeekNumberHeaderProps = _WeekNumberHeaderProps; -export type WeekNumberHeaderState = _WeekNumberHeaderState; export type { + RootState, + GridProps, + GridState, + GridHeaderProps, + GridHeaderState, + GridHeaderCellProps, + GridHeaderCellState, + GridBodyProps, + GridBodyState, + WeekTemplateProps, + WeekTemplateState, + DayCellTemplateProps, + DayCellTemplateState, + DayButtonProps, + DayButtonState, + RangeSelectedProps, + RangeSelectedState, + RangePreviewProps, + RangePreviewState, DragHandleOwnProps, + DragHandleState, + RangeStartDragHandleProps, + RangeEndDragHandleProps, + DateStringProps, + DateStringState, + TimeStringProps, + TimeStringState, + MonthYearStringProps, + MonthYearStringState, + PrevMonthButtonProps, + NextMonthButtonProps, + NavButtonState, ValueFormat, DateValueObject, PlainDateObject, @@ -195,6 +116,10 @@ export type { RangeMode, OutsideDays, ValueChangeMeta, + WeekNumberCellProps, + WeekNumberCellState, + WeekNumberHeaderProps, + WeekNumberHeaderState, MonthData, } from "../types"; diff --git a/package/src/grid-header.tsx b/package/src/grid-header.tsx index 9028e79..da97a77 100644 --- a/package/src/grid-header.tsx +++ b/package/src/grid-header.tsx @@ -5,7 +5,6 @@ import { useCalendarStable } from "./calendar-context"; import { useMonthViewState } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, GridHeaderCellProps, GridHeaderState, GridHeaderProps, @@ -78,10 +77,8 @@ function GridHeaderCellInstanceFn( }); } -const GridHeaderCellInstance = forwardRef(GridHeaderCellInstanceFn) as < - F extends ValueFormat = ValueFormat, ->( - props: Omit, "index"> & { +const GridHeaderCellInstance = forwardRef(GridHeaderCellInstanceFn) as ( + props: Omit & { index: number; } & React.RefAttributes, ) => React.ReactElement | null; @@ -114,10 +111,8 @@ function GridHeaderCellFn( * renders all 7 days (Sunday–Saturday). Each cell includes `abbr` and * `aria-label` with the full weekday name. */ -export const GridHeaderCell = forwardRef(GridHeaderCellFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridHeaderCellProps & React.RefAttributes, +export const GridHeaderCell = forwardRef(GridHeaderCellFn) as ( + props: GridHeaderCellProps & React.RefAttributes, ) => React.ReactElement | null; function GridHeaderFn( @@ -147,8 +142,6 @@ function GridHeaderFn( } /** Table header section (``) wrapping a row of {@link GridHeaderCell}s. */ -export const GridHeader = forwardRef(GridHeaderFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridHeaderProps & React.RefAttributes, +export const GridHeader = forwardRef(GridHeaderFn) as ( + props: GridHeaderProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/grid.tsx b/package/src/grid.tsx index ec50154..1c41c60 100644 --- a/package/src/grid.tsx +++ b/package/src/grid.tsx @@ -22,8 +22,6 @@ import { } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, - RootState, GridState, GridProps, GridBodyState, @@ -192,8 +190,8 @@ function GridFn(props: GridProps, ref: React.ForwardedRef) { throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root."); } -export const Grid = forwardRef(GridFn) as ( - props: GridProps & React.RefAttributes, +export const Grid = forwardRef(GridFn) as ( + props: GridProps & React.RefAttributes, ) => React.ReactElement | null; // --------------------------------------------------------------------------- @@ -337,10 +335,8 @@ function MonthGridFn( ); } -const MonthGrid = forwardRef(MonthGridFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridProps & React.RefAttributes, +const MonthGrid = forwardRef(MonthGridFn) as ( + props: GridProps & React.RefAttributes, ) => React.ReactElement | null; // --------------------------------------------------------------------------- @@ -485,9 +481,9 @@ function WeeksViewGridFn( allMonths: [], currentDateTime, gridLabelIds, - rootState: {} as RootState, + rootState: weeksState.rootState, }), - [currentDateTime, gridLabelIds], + [currentDateTime, gridLabelIds, weeksState.rootState], ); return ( @@ -499,10 +495,8 @@ function WeeksViewGridFn( ); } -const WeeksViewGrid = forwardRef(WeeksViewGridFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridProps & React.RefAttributes, +const WeeksViewGrid = forwardRef(WeeksViewGridFn) as ( + props: GridProps & React.RefAttributes, ) => React.ReactElement | null; const gridBodyStateAttributesMapping = { @@ -530,10 +524,8 @@ function GridBodyFn( return ; } -export const GridBody = forwardRef(GridBodyFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridBodyProps & React.RefAttributes, +export const GridBody = forwardRef(GridBodyFn) as ( + props: GridBodyProps & React.RefAttributes, ) => React.ReactElement | null; function MonthGridBodyFn( @@ -570,10 +562,8 @@ function MonthGridBodyFn( }); } -const MonthGridBody = forwardRef(MonthGridBodyFn) as < - F extends ValueFormat = ValueFormat, ->( - props: GridBodyProps & React.RefAttributes, +const MonthGridBody = forwardRef(MonthGridBodyFn) as ( + props: GridBodyProps & React.RefAttributes, ) => React.ReactElement | null; const weekInstanceStateAttributesMapping = { @@ -582,16 +572,14 @@ const weekInstanceStateAttributesMapping = { gridRowIndex: () => null, } as const satisfies StateAttributesMapping; -function WeekInstance( - props: WeekTemplateProps, -) { +function WeekInstance(props: WeekTemplateProps) { const { render, ...otherProps } = props; const weekData = useContext(WeekDataContext)!; const { rootState } = useMonthViewState(); - const state = useMemo>( + const state = useMemo( () => ({ - root: rootState as unknown as WeekTemplateState["root"], + root: rootState, weekIndex: weekData.weekIndex, gridRowIndex: weekData.gridRowIndex, }), @@ -612,9 +600,7 @@ function WeekInstance( * Iterates over the weeks in the current month and renders one `` per week. * Each instance receives its week's days and index via {@link WeekDataContext}. */ -export function WeekTemplate( - props: WeekTemplateProps, -) { +export function WeekTemplate(props: WeekTemplateProps) { const outerWeekData = useContext(WeekDataContext); const gridMonthCtx = useContext(GridMonthContext); const { weeks: defaultWeeks } = useMonthViewState(); @@ -626,7 +612,7 @@ export function WeekTemplate( : undefined, [gridMonthCtx], ); - const Instance = WeekInstance; + const Instance = WeekInstance; return ( <> diff --git a/package/src/month-view.test.tsx b/package/src/month-view.test.tsx index 1dcabea..43581e0 100644 --- a/package/src/month-view.test.tsx +++ b/package/src/month-view.test.tsx @@ -1633,6 +1633,49 @@ describe("non-Gregorian locale (th-TH)", () => { }); }); +describe("rootState values", () => { + function RootStateCapture({ + onCapture, + }: { + onCapture: ( + root: ReturnType["rootState"], + ) => void; + }) { + const { rootState } = useMonthViewState(); + onCapture(rootState); + return null; + } + + it("exposes the selection as Temporal.PlainDate even when format is Date", () => { + let root: ReturnType["rootState"] | undefined; + const { unmount } = render( + // format="Date" → defaultValue is a native Date; rootState must still + // expose Temporal.PlainDate. Pre-fix `selected` was the format value (a + // JS Date here), and selectedDates were PlainDate behind an `as any`. + + { + root = r; + }} + /> + , + ); + + expect(root!.selected).toBeInstanceOf(Temporal.PlainDate); + expect(root!.selected).not.toBeInstanceOf(Date); + expect( + root!.selectedDates.every((d) => d instanceof Temporal.PlainDate), + ).toBe(true); + expect(root!.hasSelection).toBe(true); + + unmount(); + }); +}); + describe("outsideDays", () => { const march15 = Temporal.PlainDate.from("2026-03-15"); diff --git a/package/src/month-view.tsx b/package/src/month-view.tsx index 9476d9c..a6bbcde 100644 --- a/package/src/month-view.tsx +++ b/package/src/month-view.tsx @@ -50,7 +50,7 @@ function MonthViewRoot(props: MonthViewRootProps) { const calState = useCalendarState(); const T = calStable.temporal; - const { timeZone, locale, weekStartDay, isDateDisabled } = calStable; + const { timeZone, weekStartDay, isDateDisabled } = calStable; // --- Month navigation state (controlled/uncontrolled) --- const isMonthControlled = monthProp !== undefined; @@ -368,32 +368,13 @@ function MonthViewRoot(props: MonthViewRootProps) { }, [viewingYearMonth, isMonthControlled]); // --- rootState (for render functions) --- - const { selected, selectedDates, rangeStart, rangeEnd } = calState; - const rootState = useMemo( () => ({ - hasSelection: selectedDates.length > 0, - selected: selected?.value, - selectedDates: selectedDates as any, - rangeStart: rangeStart as any, - rangeEnd: rangeEnd as any, + ...calState.baseRootState, focused: focusedDate, viewing: viewingYearMonth, - timeZone, - locale, - readOnly: calStable.readOnly, }), - [ - selectedDates, - selected, - rangeStart, - rangeEnd, - focusedDate, - viewingYearMonth, - timeZone, - locale, - calStable.readOnly, - ], + [calState.baseRootState, focusedDate, viewingYearMonth], ); // --- Context values --- diff --git a/package/src/navigation.tsx b/package/src/navigation.tsx index 6cba259..9275a9e 100644 --- a/package/src/navigation.tsx +++ b/package/src/navigation.tsx @@ -5,7 +5,6 @@ import { useCalendarStable, useCalendarState } from "./calendar-context"; import { useMonthViewStable, useMonthViewState } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, DateStringState, DateStringProps, TimeStringState, @@ -60,7 +59,7 @@ function DateStringFn( const state = useMemo( () => ({ - root: rootState as any, + root: rootState, month, year, day, @@ -87,10 +86,8 @@ function DateStringFn( * Displays the currently selected (or current) date as localized text. * Renders a `` with `aria-live="polite"`. */ -export const DateString = forwardRef(DateStringFn) as < - F extends ValueFormat = ValueFormat, ->( - props: DateStringProps & React.RefAttributes, +export const DateString = forwardRef(DateStringFn) as ( + props: DateStringProps & React.RefAttributes, ) => React.ReactElement | null; function TimeStringFn( @@ -120,7 +117,7 @@ function TimeStringFn( const state = useMemo( () => ({ - root: rootState as any, + root: rootState, hour, minute, second, @@ -148,10 +145,8 @@ function TimeStringFn( * Falls back to the current time when nothing is selected. * Renders a `` with `aria-live="polite"`. */ -export const TimeString = forwardRef(TimeStringFn) as < - F extends ValueFormat = ValueFormat, ->( - props: TimeStringProps & React.RefAttributes, +export const TimeString = forwardRef(TimeStringFn) as ( + props: TimeStringProps & React.RefAttributes, ) => React.ReactElement | null; function MonthYearStringFn( @@ -202,7 +197,7 @@ function MonthYearStringFn( const state = useMemo( () => ({ - root: rootState as any, + root: rootState, month: displayMonth, year: displayYear, }), @@ -237,15 +232,11 @@ function MonthYearStringFn( * referenced by the calendar grid's `aria-labelledby` and serves as its * accessible name. */ -export const MonthYearString = forwardRef(MonthYearStringFn) as < - F extends ValueFormat = ValueFormat, ->( - props: MonthYearStringProps & React.RefAttributes, +export const MonthYearString = forwardRef(MonthYearStringFn) as ( + props: MonthYearStringProps & React.RefAttributes, ) => React.ReactElement | null; -function useNavButton( - direction: "prev" | "next", -) { +function useNavButton(direction: "prev" | "next") { const { disabled: globalDisabled, minValue, @@ -314,8 +305,8 @@ function useNavButton( [destYear, destMonth, T], ); - const state = useMemo>( - () => ({ root: rootState as any, direction, disabled: isDisabled, target }), + const state = useMemo( + () => ({ root: rootState, direction, disabled: isDisabled, target }), [rootState, direction, isDisabled, target], ); @@ -359,10 +350,8 @@ function PrevMonthButtonFn( * Button that navigates to the previous month. Automatically disabled * when the previous month falls before `min`. Exposes `data-direction="prev"`. */ -export const PrevMonthButton = forwardRef(PrevMonthButtonFn) as < - F extends ValueFormat = ValueFormat, ->( - props: PrevMonthButtonProps & React.RefAttributes, +export const PrevMonthButton = forwardRef(PrevMonthButtonFn) as ( + props: PrevMonthButtonProps & React.RefAttributes, ) => React.ReactElement | null; function NextMonthButtonFn( @@ -386,8 +375,6 @@ function NextMonthButtonFn( * Button that navigates to the next month. Automatically disabled * when the next month falls after `max`. Exposes `data-direction="next"`. */ -export const NextMonthButton = forwardRef(NextMonthButtonFn) as < - F extends ValueFormat = ValueFormat, ->( - props: NextMonthButtonProps & React.RefAttributes, +export const NextMonthButton = forwardRef(NextMonthButtonFn) as ( + props: NextMonthButtonProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/range-preview.tsx b/package/src/range-preview.tsx index 6fc9d8d..a9b38d6 100644 --- a/package/src/range-preview.tsx +++ b/package/src/range-preview.tsx @@ -9,11 +9,7 @@ import { computeClippedRangeInfo, rangeOverlayStateAttributesMapping, } from "./selected-range"; -import type { - ValueFormat, - RangePreviewState, - RangePreviewProps, -} from "./types"; +import type { RangePreviewState, RangePreviewProps } from "./types"; function RangePreviewFn( props: RangePreviewProps, @@ -32,10 +28,8 @@ function RangePreviewFn( * {@link RangeSelected} but reads `previewStart`/`previewEnd` instead of * the committed range boundaries. */ -export const RangePreview = forwardRef(RangePreviewFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangePreviewProps & React.RefAttributes, +export const RangePreview = forwardRef(RangePreviewFn) as ( + props: RangePreviewProps & React.RefAttributes, ) => React.ReactElement | null; function RangePreviewInnerFn( @@ -76,7 +70,7 @@ function RangePreviewInnerFn( const state = useMemo( () => ({ - root: rootState as any, + root: rootState, active: info.active, weekIndex, startIndex: info.startIndex, @@ -116,8 +110,6 @@ function RangePreviewInnerFn( }); } -const RangePreviewInner = forwardRef(RangePreviewInnerFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangePreviewProps & React.RefAttributes, +const RangePreviewInner = forwardRef(RangePreviewInnerFn) as ( + props: RangePreviewProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/selected-range.tsx b/package/src/selected-range.tsx index 576de1f..cb5e54d 100644 --- a/package/src/selected-range.tsx +++ b/package/src/selected-range.tsx @@ -8,7 +8,6 @@ import { useMonthViewState } from "./month-view-context"; import { MonthViewStableContext } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, RangeSelectedState, RangeSelectedProps, OutsideDays, @@ -102,10 +101,8 @@ function RangeSelectedFn( * `active`, `week-index`, `start-index`, `end-index`, `start-date`, * `end-date`, `extends-before`, and `extends-after`. */ -export const RangeSelected = forwardRef(RangeSelectedFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangeSelectedProps & React.RefAttributes, +export const RangeSelected = forwardRef(RangeSelectedFn) as ( + props: RangeSelectedProps & React.RefAttributes, ) => React.ReactElement | null; function RangeSelectedInnerFn( @@ -146,7 +143,7 @@ function RangeSelectedInnerFn( const state = useMemo( () => ({ - root: rootState as any, + root: rootState, active: info.active, weekIndex, startIndex: info.startIndex, @@ -186,8 +183,6 @@ function RangeSelectedInnerFn( }); } -const RangeSelectedInner = forwardRef(RangeSelectedInnerFn) as < - F extends ValueFormat = ValueFormat, ->( - props: RangeSelectedProps & React.RefAttributes, +const RangeSelectedInner = forwardRef(RangeSelectedInnerFn) as ( + props: RangeSelectedProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/types.ts b/package/src/types.ts index ff9d2b7..e19f8f9 100644 --- a/package/src/types.ts +++ b/package/src/types.ts @@ -212,18 +212,25 @@ export interface DatePickerStateContextValue { export interface DatePickerContextValue extends DatePickerStableContextValue, DatePickerStateContextValue {} -/** State exposed by the `Root` component to its render function and descendants. */ -export type RootState = { +/** + * State exposed by the `Root` component to its render function and descendants. + * + * All date values are `Temporal` objects (the internal representation), not the + * configured value `format`. The format-typed values are delivered through the + * `value`/`defaultValue`/`onValueChange` props; this state is for rendering, so + * use e.g. `selected?.toLocaleString(locale)` to display. + */ +export type RootState = { /** `true` when at least one date is selected. */ hasSelection: boolean; - /** The primary selected value in the configured format, or `undefined`. */ - selected: RawValueForFormat | undefined; - /** All selected dates in the configured format (sorted oldest-first). */ - selectedDates: RawValueForFormat[]; - /** Range start in the configured format, or `undefined`. */ - rangeStart: RawValueForFormat | undefined; - /** Range end in the configured format, or `undefined`. */ - rangeEnd: RawValueForFormat | undefined; + /** The primary selected date (the first committed date), or `undefined`. */ + selected: Temporal.PlainDate | undefined; + /** All currently selected dates (chronological in `multiple` mode). */ + selectedDates: Temporal.PlainDate[]; + /** Range start, or `undefined`. */ + rangeStart: Temporal.PlainDate | undefined; + /** Range end, or `undefined`. */ + rangeEnd: Temporal.PlainDate | undefined; /** The currently focused `PlainDate` in the grid. */ focused: Temporal.PlainDate; /** The month/year currently being viewed. */ @@ -236,6 +243,13 @@ export type RootState = { readOnly: boolean; }; +/** + * The view-independent part of {@link RootState} (everything except `focused` + * and `viewing`, which each view supplies). Built once by the provider and + * shared so MonthView and WeeksView expose identical selection state. + */ +export type BaseRootState = Omit; + interface RootOwnPropsBase { /** * The value format used for date serialization. Determines the type of @@ -487,14 +501,14 @@ type AllRootOwnPropKeys = /** Full props for the `Root` component (own props + render element props). */ export type RootProps = Omit< - useRender.ComponentProps<"div", RootState>, + useRender.ComponentProps<"div", RootState>, AllRootOwnPropKeys > & RootOwnProps; /** State exposed by the `DateString` component. */ -export type DateStringState = { - root: RootState; +export type DateStringState = { + root: RootState; month: number; year: number; day: number; @@ -509,12 +523,15 @@ export interface DateStringOwnProps { } /** Full props for the `DateString` component. */ -export type DateStringProps = - useRender.ComponentProps<"span", DateStringState> & DateStringOwnProps; +export type DateStringProps = useRender.ComponentProps< + "span", + DateStringState +> & + DateStringOwnProps; /** State exposed by the `TimeString` component. */ -export type TimeStringState = { - root: RootState; +export type TimeStringState = { + root: RootState; hour: number; minute: number; second: number; @@ -529,12 +546,15 @@ export interface TimeStringOwnProps { } /** Full props for the `TimeString` component. */ -export type TimeStringProps = - useRender.ComponentProps<"span", TimeStringState> & TimeStringOwnProps; +export type TimeStringProps = useRender.ComponentProps< + "span", + TimeStringState +> & + TimeStringOwnProps; /** State exposed by the `MonthYearString` component. */ -export type MonthYearStringState = { - root: RootState; +export type MonthYearStringState = { + root: RootState; month: number; year: number; }; @@ -550,28 +570,34 @@ export interface MonthYearStringOwnProps { } /** Full props for the `MonthYearString` component. */ -export type MonthYearStringProps = - useRender.ComponentProps<"span", MonthYearStringState> & - MonthYearStringOwnProps; +export type MonthYearStringProps = useRender.ComponentProps< + "span", + MonthYearStringState +> & + MonthYearStringOwnProps; /** State exposed by `PrevMonthButton` and `NextMonthButton`. */ -export type NavButtonState = { - root: RootState; +export type NavButtonState = { + root: RootState; direction: "next" | "prev"; disabled: boolean; target: Temporal.PlainYearMonth; }; /** Full props for the `PrevMonthButton` component. */ -export type PrevMonthButtonProps = - useRender.ComponentProps<"button", NavButtonState>; +export type PrevMonthButtonProps = useRender.ComponentProps< + "button", + NavButtonState +>; /** Full props for the `NextMonthButton` component. */ -export type NextMonthButtonProps = - useRender.ComponentProps<"button", NavButtonState>; +export type NextMonthButtonProps = useRender.ComponentProps< + "button", + NavButtonState +>; /** State exposed by the `GridHeaderCell` component. */ -export type GridHeaderCellState = { - root: RootState; +export type GridHeaderCellState = { + root: RootState; dayOfWeek: number; long: string; short: string; @@ -585,31 +611,34 @@ export interface GridHeaderCellOwnProps { } /** Full props for the `GridHeaderCell` component. */ -export type GridHeaderCellProps = - useRender.ComponentProps<"th", GridHeaderCellState> & - GridHeaderCellOwnProps; +export type GridHeaderCellProps = useRender.ComponentProps< + "th", + GridHeaderCellState +> & + GridHeaderCellOwnProps; /** State exposed by the `GridHeader` component. */ -export type GridHeaderState = { - root: RootState; +export type GridHeaderState = { + root: RootState; }; /** Full props for the `GridHeader` component. */ -export type GridHeaderProps = - useRender.ComponentProps<"thead", GridHeaderState>; +export type GridHeaderProps = useRender.ComponentProps< + "thead", + GridHeaderState +>; /** State exposed by the `GridBody` component. */ -export type GridBodyState = { - root: RootState; +export type GridBodyState = { + root: RootState; }; /** Full props for the `GridBody` component. */ -export type GridBodyProps = - useRender.ComponentProps<"tbody", GridBodyState>; +export type GridBodyProps = useRender.ComponentProps<"tbody", GridBodyState>; /** State exposed by the `Grid` component. */ -export type GridState = { - root: RootState; +export type GridState = { + root: RootState; month: number; year: number; orientation: GridOrientation; @@ -628,24 +657,26 @@ export interface GridOwnProps { } /** Full props for the `Grid` component. */ -export type GridProps = - useRender.ComponentProps<"table", GridState> & GridOwnProps; +export type GridProps = useRender.ComponentProps<"table", GridState> & + GridOwnProps; /** State exposed by the `WeekTemplate` component. */ -export type WeekTemplateState = { - root: RootState; +export type WeekTemplateState = { + root: RootState; weekIndex: number; /** 1-based CSS grid row index for this week row (WeeksView only, undefined in MonthView). */ gridRowIndex: number | undefined; }; /** Full props for the `WeekTemplate` component. */ -export type WeekTemplateProps = - useRender.ComponentProps<"tr", WeekTemplateState>; +export type WeekTemplateProps = useRender.ComponentProps< + "tr", + WeekTemplateState +>; /** State exposed by the `DayCellTemplate` component. */ -export type DayCellTemplateState = { - root: RootState; +export type DayCellTemplateState = { + root: RootState; date: Temporal.PlainDate; columnIndex: number; orientation: GridOrientation; @@ -687,8 +718,7 @@ export type DayCellTemplateState = { }; /** State exposed by the `DayButton` component (same as `DayCellTemplateState`). */ -export type DayButtonState = - DayCellTemplateState; +export type DayButtonState = DayCellTemplateState; /** Own props for the `DayCellTemplate` component. */ export interface DayCellTemplateOwnProps { @@ -697,9 +727,11 @@ export interface DayCellTemplateOwnProps { } /** Full props for the `DayCellTemplate` component. */ -export type DayCellTemplateProps = - useRender.ComponentProps<"td", DayCellTemplateState> & - DayCellTemplateOwnProps; +export type DayCellTemplateProps = useRender.ComponentProps< + "td", + DayCellTemplateState +> & + DayCellTemplateOwnProps; /** Own props for the `DayButton` component. */ export interface DayButtonOwnProps { @@ -708,12 +740,15 @@ export interface DayButtonOwnProps { } /** Full props for the `DayButton` component. */ -export type DayButtonProps = - useRender.ComponentProps<"button", DayButtonState> & DayButtonOwnProps; +export type DayButtonProps = useRender.ComponentProps< + "button", + DayButtonState +> & + DayButtonOwnProps; /** State exposed by the `RangeSelected` component. */ -export type RangeSelectedState = { - root: RootState; +export type RangeSelectedState = { + root: RootState; active: boolean; weekIndex: number; startIndex: number; @@ -728,23 +763,23 @@ export type RangeSelectedState = { }; /** Full props for the `RangeSelected` component. */ -export type RangeSelectedProps = - useRender.ComponentProps<"td", RangeSelectedState>; +export type RangeSelectedProps = useRender.ComponentProps< + "td", + RangeSelectedState +>; /** State exposed by the `RangePreview` component (same shape as `RangeSelectedState`). */ -export type RangePreviewState = - RangeSelectedState; +export type RangePreviewState = RangeSelectedState; /** Full props for the `RangePreview` component (same shape as `RangeSelectedProps`). */ -export type RangePreviewProps = - RangeSelectedProps; +export type RangePreviewProps = RangeSelectedProps; /** Which end of a range the drag handle controls. */ export type DragHandleEdge = "start" | "end"; /** State exposed by the `RangeDragHandle` components. */ -export type DragHandleState = { - root: RootState; +export type DragHandleState = { + root: RootState; active: boolean; dragging: boolean; edge: DragHandleEdge; @@ -760,37 +795,40 @@ export interface DragHandleOwnProps { } /** Full props for the `RangeDragHandle` component. */ -export type RangeDragHandleProps = - useRender.ComponentProps<"span", DragHandleState> & DragHandleOwnProps; +export type RangeDragHandleProps = useRender.ComponentProps< + "span", + DragHandleState +> & + DragHandleOwnProps; /** Props for `RangeStartDragHandle` (edge is fixed to `"start"`). */ -export type RangeStartDragHandleProps = - Omit, "edge">; +export type RangeStartDragHandleProps = Omit; /** Props for `RangeEndDragHandle` (edge is fixed to `"end"`). */ -export type RangeEndDragHandleProps = Omit< - RangeDragHandleProps, - "edge" ->; +export type RangeEndDragHandleProps = Omit; /** State exposed by the `WeekNumberCell` component. */ -export type WeekNumberCellState = { - root: RootState; +export type WeekNumberCellState = { + root: RootState; weekNumber: number; }; /** Full props for the `WeekNumberCell` component. */ -export type WeekNumberCellProps = - useRender.ComponentProps<"td", WeekNumberCellState>; +export type WeekNumberCellProps = useRender.ComponentProps< + "td", + WeekNumberCellState +>; /** State exposed by the `WeekNumberHeader` component. */ -export type WeekNumberHeaderState = { - root: RootState; +export type WeekNumberHeaderState = { + root: RootState; }; /** Full props for the `WeekNumberHeader` component. */ -export type WeekNumberHeaderProps = - useRender.ComponentProps<"th", WeekNumberHeaderState>; +export type WeekNumberHeaderProps = useRender.ComponentProps< + "th", + WeekNumberHeaderState +>; /** Root props pre-narrowed to a specific format. */ export type TypedRootProps = Omit< diff --git a/package/src/week-number.tsx b/package/src/week-number.tsx index aa49b53..208c0db 100644 --- a/package/src/week-number.tsx +++ b/package/src/week-number.tsx @@ -6,7 +6,6 @@ import { WeekDataContext } from "./context"; import { useMonthViewState } from "./month-view-context"; import type { StateAttributesMapping } from "./types"; import type { - ValueFormat, WeekNumberCellState, WeekNumberCellProps, WeekNumberHeaderState, @@ -72,10 +71,8 @@ function WeekNumberCellFn( * Renders the ISO 8601 week number for a week row. Must be used inside * a {@link WeekTemplate}. Renders a `` with `role="rowheader"`. */ -export const WeekNumberCell = forwardRef(WeekNumberCellFn) as < - F extends ValueFormat = ValueFormat, ->( - props: WeekNumberCellProps & React.RefAttributes, +export const WeekNumberCell = forwardRef(WeekNumberCellFn) as ( + props: WeekNumberCellProps & React.RefAttributes, ) => React.ReactElement | null; const weekNumberHeaderStateAttributesMapping = { @@ -113,8 +110,6 @@ function WeekNumberHeaderFn( /** * Column header for the week number column. Renders a ``. */ -export const WeekNumberHeader = forwardRef(WeekNumberHeaderFn) as < - F extends ValueFormat = ValueFormat, ->( - props: WeekNumberHeaderProps & React.RefAttributes, +export const WeekNumberHeader = forwardRef(WeekNumberHeaderFn) as ( + props: WeekNumberHeaderProps & React.RefAttributes, ) => React.ReactElement | null; diff --git a/package/src/weeks-navigation.tsx b/package/src/weeks-navigation.tsx index b841d66..e72df08 100644 --- a/package/src/weeks-navigation.tsx +++ b/package/src/weeks-navigation.tsx @@ -110,7 +110,7 @@ function useWeeksNavButton( ]); const state = useMemo( - () => ({ root: rootState as any, direction, disabled: isDisabled }), + () => ({ root: rootState, direction, disabled: isDisabled }), [rootState, direction, isDisabled], ); @@ -196,7 +196,7 @@ function WeekCountFn( const count = windowInfo.weekCount; const state = useMemo( - () => ({ root: rootState as any, weekCount: count }), + () => ({ root: rootState, weekCount: count }), [rootState, count], ); diff --git a/package/src/weeks-view-state.ts b/package/src/weeks-view-state.ts index 6c85394..20f6a8a 100644 --- a/package/src/weeks-view-state.ts +++ b/package/src/weeks-view-state.ts @@ -8,6 +8,7 @@ import { resolveFirstWeek, type FirstWeekSpec, } from "./resolve-first-week"; +import type { RootState } from "./types"; import { selectedToZdt, toZonedDateTime } from "./utils"; import type { ViewContextValue } from "./view-context"; import type { @@ -437,6 +438,21 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) { ], ); + // Real render-prop rootState shared by the MonthViewState shims (WeeksView + // root + the inner Grid), so components reading `state.root` inside WeeksView + // see populated values instead of an empty cast. + const rootState = useMemo( + () => ({ + ...calState.baseRootState, + focused: focusedDate, + viewing: T.PlainYearMonth.from({ + year: currentDateTime.year, + month: currentDateTime.month, + }), + }), + [calState.baseRootState, focusedDate, currentDateTime, T], + ); + const stateCtx = useMemo( () => ({ focusedDate, @@ -444,8 +460,16 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) { gridLabelIds, weeks: adjustedWeeks, currentDateTime, + rootState, }), - [focusedDate, windowInfo, gridLabelIds, adjustedWeeks, currentDateTime], + [ + focusedDate, + windowInfo, + gridLabelIds, + adjustedWeeks, + currentDateTime, + rootState, + ], ); const viewCtx = useMemo( diff --git a/package/src/weeks-view-types.ts b/package/src/weeks-view-types.ts index c78cdd2..2ea5b47 100644 --- a/package/src/weeks-view-types.ts +++ b/package/src/weeks-view-types.ts @@ -2,6 +2,7 @@ import type { Temporal } from "@js-temporal/polyfill"; import type { WeekDescriptor } from "./compute-weeks-in-window"; import type { OverflowBehavior } from "./overflow"; import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week"; +import type { RootState } from "./types"; // --------------------------------------------------------------------------- // WeeksView.Root props @@ -102,4 +103,6 @@ export interface WeeksViewStateContextValue { weeks: WeekDescriptor[]; /** Date-time representing the current moment (for "today" highlighting). */ currentDateTime: Temporal.PlainDateTime; + /** Render-prop `RootState` exposed to components inside WeeksView. */ + rootState: RootState; } diff --git a/package/src/weeks-view.test.tsx b/package/src/weeks-view.test.tsx index ac19320..632b4dc 100644 --- a/package/src/weeks-view.test.tsx +++ b/package/src/weeks-view.test.tsx @@ -15,6 +15,7 @@ import { MonthSeparatorYear, MonthSeparatorWeekCount, } from "./month-separator"; +import { useMonthViewState } from "./month-view-context"; import { useViewContext } from "./view-context"; import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation"; import { WeeksView } from "./weeks-view"; @@ -536,3 +537,51 @@ describe("WeeksView regression: goNext/goPrev shift by weekCount (Bug #3)", () = expect(screen.getByTestId("start").textContent).toBe("2026-03-15"); }); }); + +describe("WeeksView regression: rootState shim is populated", () => { + function ShimRootStateCapture({ + onCapture, + }: { + onCapture: ( + root: ReturnType["rootState"], + ) => void; + }) { + const { rootState } = useMonthViewState(); + onCapture(rootState); + return null; + } + + it("exposes a real rootState to components reading useMonthViewState()", () => { + let root: ReturnType["rootState"] | undefined; + render( + + { + root = r; + }} + /> + , + ); + + // Pre-fix this shim was `{} as RootState` — every field undefined at runtime. + expect(root).toBeDefined(); + expect(root!.viewing).toBeInstanceOf(Temporal.PlainYearMonth); + expect(root!.focused).toBeInstanceOf(Temporal.PlainDate); + expect(typeof root!.timeZone).toBe("string"); + expect(root!.timeZone.length).toBeGreaterThan(0); + expect(typeof root!.locale).toBe("string"); + expect(typeof root!.readOnly).toBe("boolean"); + // Selection flows through the shared baseRootState into the shim. + expect(root!.hasSelection).toBe(true); + expect(root!.selected).toBeInstanceOf(Temporal.PlainDate); + expect(root!.selected!.toString()).toBe("2026-03-15"); + expect( + root!.selectedDates.every((d) => d instanceof Temporal.PlainDate), + ).toBe(true); + }); +}); diff --git a/package/src/weeks-view.tsx b/package/src/weeks-view.tsx index 1dca22f..7806204 100644 --- a/package/src/weeks-view.tsx +++ b/package/src/weeks-view.tsx @@ -7,7 +7,7 @@ import { MonthViewStateContext, } from "./month-view-context"; import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week"; -import type { RootState, ValueFormat } from "./types"; +import type { ValueFormat } from "./types"; import { ViewContext } from "./view-context"; import { WeeksViewStableContext, @@ -67,9 +67,9 @@ function WeeksViewRootFn( allMonths: [], currentDateTime: stateCtx.currentDateTime, gridLabelIds: stateCtx.gridLabelIds, - rootState: {} as RootState, + rootState: stateCtx.rootState, }), - [stateCtx.currentDateTime, stateCtx.gridLabelIds], + [stateCtx.currentDateTime, stateCtx.gridLabelIds, stateCtx.rootState], ); return ( diff --git a/website/src/examples/date-picker-styled.tsx b/website/src/examples/date-picker-styled.tsx index 498f837..60d6d4c 100644 --- a/website/src/examples/date-picker-styled.tsx +++ b/website/src/examples/date-picker-styled.tsx @@ -18,7 +18,6 @@ import { GridContext, } from "@klinking/colander"; import type { - ValueFormat, GridProps, GridBodyProps, WeekTemplateProps, @@ -35,10 +34,10 @@ import type { import { DragHandle, DragDayButton } from "#/lib/drag-components"; import { cn } from "#/lib/utils"; -export function StyledPrevMonthButton({ +export function StyledPrevMonthButton({ className, ...props -}: PrevMonthButtonProps & { ref?: Ref }) { +}: PrevMonthButtonProps & { ref?: Ref }) { return ( ({ ); } -export function StyledNextMonthButton({ +export function StyledNextMonthButton({ className, ...props -}: NextMonthButtonProps & { ref?: Ref }) { +}: NextMonthButtonProps & { ref?: Ref }) { return ( ({ ); } -export function StyledMonthYearString({ +export function StyledMonthYearString({ className, ...props -}: MonthYearStringProps & { ref?: Ref }) { +}: MonthYearStringProps & { ref?: Ref }) { return ( ({ ); } -export function StyledGrid({ +export function StyledGrid({ className, ...props -}: GridProps & { ref?: Ref }) { +}: GridProps & { ref?: Ref }) { return ( ({ ); } -export function StyledGridHeader({ +export function StyledGridHeader({ className, ...props -}: GridHeaderProps & { ref?: Ref }) { +}: GridHeaderProps & { ref?: Ref }) { return ( ({ ); } -export function StyledGridHeaderCell({ +export function StyledGridHeaderCell({ className, ...props -}: GridHeaderCellProps & { ref?: Ref }) { +}: GridHeaderCellProps & { ref?: Ref }) { return ( ({ ); } -export function StyledGridBody({ +export function StyledGridBody({ className, ...props -}: GridBodyProps & { ref?: Ref }) { +}: GridBodyProps & { ref?: Ref }) { return ( ({ ); } -export function StyledWeekTemplate({ +export function StyledWeekTemplate({ className, ...props -}: WeekTemplateProps & { ref?: Ref }) { +}: WeekTemplateProps & { ref?: Ref }) { return ( ({ ); } -export function StyledDayCellTemplate( - allProps: DayCellTemplateProps & { +export function StyledDayCellTemplate( + allProps: DayCellTemplateProps & { ref?: Ref; columnOffset?: number; preventRangeReversal?: boolean; @@ -223,12 +222,12 @@ export function StyledDayCellTemplate( ); } -export function StyledDayButton({ +export function StyledDayButton({ className, date, preventRangeReversal, ...props -}: DayButtonProps & { +}: DayButtonProps & { ref?: Ref; preventRangeReversal?: boolean; }) { @@ -334,8 +333,8 @@ export function StyledDragHandle({ ); } -export function StyledRangePreview( - allProps: RangePreviewProps & { +export function StyledRangePreview( + allProps: RangePreviewProps & { ref?: Ref; columnOffset?: number; }, @@ -388,8 +387,8 @@ export function StyledRangePreview( ); } -export function StyledRangeSelected( - allProps: RangeSelectedProps & { +export function StyledRangeSelected( + allProps: RangeSelectedProps & { ref?: Ref; columnOffset?: number; }, diff --git a/website/src/lib/drag-components.tsx b/website/src/lib/drag-components.tsx index 753c645..6dfdfd4 100644 --- a/website/src/lib/drag-components.tsx +++ b/website/src/lib/drag-components.tsx @@ -10,7 +10,7 @@ import { RangeEndDragHandle, DayButton, } from "@klinking/colander"; -import type { DayButtonProps, ValueFormat } from "@klinking/colander"; +import type { DayButtonProps } from "@klinking/colander"; import { useRef } from "react"; import { useDragHandleDnD, useDayDropTarget } from "./use-drag-range"; @@ -78,8 +78,8 @@ export function DragHandleEnd(props: Omit) { return ; } -export function DragDayButton( - props: DayButtonProps & { ref?: React.Ref }, +export function DragDayButton( + props: DayButtonProps & { ref?: React.Ref }, ) { const dropRef = useRef(null); useDayDropTarget(dropRef, props.date); From 6b14d39d191700454ed937f3e2a1aeffb6cf71a3 Mon Sep 17 00:00:00 2001 From: Klink <85062+dogmar@users.noreply.github.com> Date: Sun, 14 Jun 2026 19:34:27 -0700 Subject: [PATCH 2/2] fix: add repository field to package.json for npm provenance The semantic-release publish failed npm provenance validation ("repository.url" is "", expected to match the GitHub repo). Add the repository (with monorepo directory), homepage, and bugs fields so the published package's provenance bundle validates. Co-Authored-By: Claude Opus 4.8 --- package/package.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package/package.json b/package/package.json index e6fb33e..a70af90 100644 --- a/package/package.json +++ b/package/package.json @@ -1,7 +1,14 @@ { "name": "@klinking/colander", "version": "0.0.0", + "homepage": "https://github.com/klink-ing/colander#readme", + "bugs": "https://github.com/klink-ing/colander/issues", "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/klink-ing/colander.git", + "directory": "package" + }, "files": [ "dist", "src"