@klinking/colander 3.1.0-alpha.2 → 3.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +1 -1
- package/dist/formats/date.d.cts +1 -1
- package/dist/formats/date.d.mts +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.d.cts +1 -1
- package/dist/formats/object.d.mts +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.d.cts +1 -1
- package/dist/formats/plain-date-time.d.mts +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.d.cts +1 -1
- package/dist/formats/plain-date.d.mts +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.d.cts +1 -1
- package/dist/formats/plain-month-day.d.mts +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.d.cts +1 -1
- package/dist/formats/plain-year-month.d.mts +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.d.cts +1 -1
- package/dist/formats/zoned-date-time.d.mts +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-CXRaVP02.mjs → weeks-navigation-DEaASUAh.mjs} +83 -107
- package/dist/{weeks-navigation-BRxzsy0z.cjs → weeks-navigation-DvryOSWF.cjs} +83 -107
- package/dist/{index-CJgr0MEp.d.cts → weeks-view-context-CNAq2Hiu.d.cts} +1 -8
- package/dist/{index-DB6V_Y6x.d.mts → weeks-view-context-CsP3PBiu.d.mts} +1 -8
- package/package.json +1 -1
- package/src/day-cell.tsx +9 -15
- package/src/drag-handle.tsx +2 -2
- package/src/grid-header.tsx +3 -3
- package/src/grid.tsx +20 -61
- package/src/month-view.tsx +25 -2
- package/src/navigation.tsx +3 -2
- package/src/range-preview.tsx +3 -5
- package/src/selected-range.tsx +3 -5
- package/src/view-context.test.tsx +126 -0
- package/src/view-context.ts +43 -0
- package/src/week-number.tsx +3 -3
- package/src/weeks-navigation.tsx +3 -3
- package/src/weeks-view-state.ts +23 -2
- package/src/weeks-view.test.tsx +115 -13
- package/src/weeks-view.tsx +22 -51
|
@@ -1325,6 +1325,22 @@ function useViewContext() {
|
|
|
1325
1325
|
if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
|
|
1326
1326
|
return ctx;
|
|
1327
1327
|
}
|
|
1328
|
+
/** @internal Context for {@link ViewStableContextValue}. */
|
|
1329
|
+
const ViewStableContext = (0, react.createContext)(null);
|
|
1330
|
+
/** @internal Context for {@link ViewStateContextValue}. */
|
|
1331
|
+
const ViewStateContext = (0, react.createContext)(null);
|
|
1332
|
+
/** Returns the nearest view's stable values. */
|
|
1333
|
+
function useViewStable() {
|
|
1334
|
+
const ctx = (0, react.useContext)(ViewStableContext);
|
|
1335
|
+
if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
|
|
1336
|
+
return ctx;
|
|
1337
|
+
}
|
|
1338
|
+
/** Returns the nearest view's volatile state. */
|
|
1339
|
+
function useViewState() {
|
|
1340
|
+
const ctx = (0, react.useContext)(ViewStateContext);
|
|
1341
|
+
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1342
|
+
return ctx;
|
|
1343
|
+
}
|
|
1328
1344
|
//#endregion
|
|
1329
1345
|
//#region src/month-view.tsx
|
|
1330
1346
|
function MonthViewRoot(props) {
|
|
@@ -1646,13 +1662,27 @@ function MonthViewRoot(props) {
|
|
|
1646
1662
|
tabTargetDate,
|
|
1647
1663
|
gridHasFocus
|
|
1648
1664
|
]);
|
|
1665
|
+
const viewStableCtx = (0, react.useMemo)(() => ({
|
|
1666
|
+
gridFocusedRef,
|
|
1667
|
+
outsideDays
|
|
1668
|
+
}), [outsideDays]);
|
|
1669
|
+
const viewStateCtx = (0, react.useMemo)(() => ({
|
|
1670
|
+
currentDateTime,
|
|
1671
|
+
rootState
|
|
1672
|
+
}), [currentDateTime, rootState]);
|
|
1649
1673
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
1650
1674
|
value: stableCtx,
|
|
1651
1675
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
1652
1676
|
value: stateCtx,
|
|
1653
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1654
|
-
value:
|
|
1655
|
-
children
|
|
1677
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
|
|
1678
|
+
value: viewStableCtx,
|
|
1679
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
|
|
1680
|
+
value: viewStateCtx,
|
|
1681
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
|
|
1682
|
+
value: viewCtx,
|
|
1683
|
+
children
|
|
1684
|
+
})
|
|
1685
|
+
})
|
|
1656
1686
|
})
|
|
1657
1687
|
})
|
|
1658
1688
|
});
|
|
@@ -1688,7 +1718,7 @@ const GridMonthContext = (0, react.createContext)(null);
|
|
|
1688
1718
|
//#region src/grid-header.tsx
|
|
1689
1719
|
function useGridHeaderCellState(index) {
|
|
1690
1720
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
1691
|
-
const { rootState } =
|
|
1721
|
+
const { rootState } = useViewState();
|
|
1692
1722
|
const weekdayNames = (0, react.useMemo)(() => getWeekdayNames(locale, T, weekStartDay), [
|
|
1693
1723
|
locale,
|
|
1694
1724
|
T,
|
|
@@ -1764,7 +1794,7 @@ function GridHeaderCellFn(props, ref) {
|
|
|
1764
1794
|
const GridHeaderCell = (0, react.forwardRef)(GridHeaderCellFn);
|
|
1765
1795
|
function GridHeaderFn(props, ref) {
|
|
1766
1796
|
const { render, children, ...otherProps } = props;
|
|
1767
|
-
const { rootState } =
|
|
1797
|
+
const { rootState } = useViewState();
|
|
1768
1798
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
1769
1799
|
return (0, _base_ui_react_use_render.useRender)({
|
|
1770
1800
|
defaultTagName: "thead",
|
|
@@ -2474,9 +2504,9 @@ function DayCellTemplate(props) {
|
|
|
2474
2504
|
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2475
2505
|
const viewCtx = useViewContext();
|
|
2476
2506
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2477
|
-
const
|
|
2478
|
-
const {
|
|
2479
|
-
const
|
|
2507
|
+
const { rootState, currentDateTime } = useViewState();
|
|
2508
|
+
const { outsideDays } = useViewStable();
|
|
2509
|
+
const monthState = (0, react.useContext)(MonthViewStateContext);
|
|
2480
2510
|
const isWeeksView = viewCtx.viewType === "weeks";
|
|
2481
2511
|
const cellMonth = isWeeksView ? null : weekData?.gridMonth ?? currentDateTime;
|
|
2482
2512
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
@@ -2492,7 +2522,7 @@ function DayCellTemplate(props) {
|
|
|
2492
2522
|
_derivedState: derived
|
|
2493
2523
|
});
|
|
2494
2524
|
}
|
|
2495
|
-
const days = weekData ? weekData.days : weeks.flat();
|
|
2525
|
+
const days = weekData ? weekData.days : monthState?.weeks.flat() ?? [];
|
|
2496
2526
|
const perWeek = weekData != null;
|
|
2497
2527
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
|
|
2498
2528
|
const daysInWeek = day.daysInWeek;
|
|
@@ -2512,7 +2542,7 @@ function DayButtonInnerFn(props, ref) {
|
|
|
2512
2542
|
const { render, date, _derivedState, ...otherProps } = props;
|
|
2513
2543
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
2514
2544
|
const { setFocusedDate } = useViewContext();
|
|
2515
|
-
const gridFocusedRef = (
|
|
2545
|
+
const { gridFocusedRef } = useViewStable();
|
|
2516
2546
|
const internalRef = (0, react.useRef)(null);
|
|
2517
2547
|
const isHidden = _derivedState?.hidden ?? false;
|
|
2518
2548
|
const isFocused = _derivedState?.focused ?? false;
|
|
@@ -2596,9 +2626,8 @@ function DayButtonFallbackFn(props, ref) {
|
|
|
2596
2626
|
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2597
2627
|
const viewCtx = useViewContext();
|
|
2598
2628
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2599
|
-
const
|
|
2600
|
-
const {
|
|
2601
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
2629
|
+
const { rootState, currentDateTime } = useViewState();
|
|
2630
|
+
const { outsideDays } = useViewStable();
|
|
2602
2631
|
const cellMonth = viewCtx.viewType === "weeks" ? {
|
|
2603
2632
|
year: date.year,
|
|
2604
2633
|
month: date.month
|
|
@@ -2714,17 +2743,15 @@ const gridStateAttributesMapping = {
|
|
|
2714
2743
|
* delegates to the appropriate internal renderer.
|
|
2715
2744
|
*/
|
|
2716
2745
|
function GridFn(props, ref) {
|
|
2717
|
-
const
|
|
2718
|
-
|
|
2719
|
-
|
|
2746
|
+
const view = (0, react.useContext)(ViewContext);
|
|
2747
|
+
if (!view) throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
|
|
2748
|
+
return view.viewType === "weeks" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
|
|
2720
2749
|
ref,
|
|
2721
2750
|
...props
|
|
2722
|
-
})
|
|
2723
|
-
if (weeksState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
|
|
2751
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGrid, {
|
|
2724
2752
|
ref,
|
|
2725
2753
|
...props
|
|
2726
2754
|
});
|
|
2727
|
-
throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
|
|
2728
2755
|
}
|
|
2729
2756
|
const Grid = (0, react.forwardRef)(GridFn);
|
|
2730
2757
|
function MonthGridFn(props, ref) {
|
|
@@ -2831,7 +2858,7 @@ function WeeksViewGridFn(props, ref) {
|
|
|
2831
2858
|
const weeksStable = useWeeksViewStable();
|
|
2832
2859
|
const weeksState = useWeeksViewState();
|
|
2833
2860
|
const { gridFocusedRef } = weeksStable;
|
|
2834
|
-
const { gridLabelIds, weeks
|
|
2861
|
+
const { gridLabelIds, weeks } = weeksState;
|
|
2835
2862
|
const handleKeyDown = useWeeksGridKeyboard();
|
|
2836
2863
|
const gridRef = (0, react.useRef)(null);
|
|
2837
2864
|
(0, react.useEffect)(() => {
|
|
@@ -2902,47 +2929,16 @@ function WeeksViewGridFn(props, ref) {
|
|
|
2902
2929
|
props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
|
|
2903
2930
|
});
|
|
2904
2931
|
const orientationCtx = (0, react.useMemo)(() => ({ orientation: resolvedOrientation }), [resolvedOrientation]);
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
outsideDays: "enabled",
|
|
2909
|
-
outOfRangeBehavior: "unbounded",
|
|
2910
|
-
goNextMonth: () => {},
|
|
2911
|
-
goPrevMonth: () => {},
|
|
2912
|
-
setGridLabelId: () => {},
|
|
2913
|
-
gridFocusedRef
|
|
2914
|
-
}), [gridFocusedRef]);
|
|
2915
|
-
const monthViewStateShim = (0, react.useMemo)(() => ({
|
|
2916
|
-
currentMonth: {
|
|
2917
|
-
year: currentDateTime.year,
|
|
2918
|
-
month: currentDateTime.month
|
|
2919
|
-
},
|
|
2920
|
-
weeks: [],
|
|
2921
|
-
allMonths: [],
|
|
2922
|
-
currentDateTime,
|
|
2923
|
-
gridLabelIds,
|
|
2924
|
-
rootState: weeksState.rootState
|
|
2925
|
-
}), [
|
|
2926
|
-
currentDateTime,
|
|
2927
|
-
gridLabelIds,
|
|
2928
|
-
weeksState.rootState
|
|
2929
|
-
]);
|
|
2930
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
2931
|
-
value: monthViewStableShim,
|
|
2932
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
2933
|
-
value: monthViewStateShim,
|
|
2934
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
|
|
2935
|
-
value: orientationCtx,
|
|
2936
|
-
children: el
|
|
2937
|
-
})
|
|
2938
|
-
})
|
|
2932
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
|
|
2933
|
+
value: orientationCtx,
|
|
2934
|
+
children: el
|
|
2939
2935
|
});
|
|
2940
2936
|
}
|
|
2941
2937
|
const WeeksViewGrid = (0, react.forwardRef)(WeeksViewGridFn);
|
|
2942
2938
|
const gridBodyStateAttributesMapping = { root: () => null };
|
|
2943
2939
|
/** Table body wrapping the week rows. Renders a `<tbody>` by default. */
|
|
2944
2940
|
function GridBodyFn(props, ref) {
|
|
2945
|
-
if ((0, react.useContext)(
|
|
2941
|
+
if ((0, react.useContext)(ViewContext)?.viewType === "weeks") {
|
|
2946
2942
|
const { children, className, style } = props;
|
|
2947
2943
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksGrid, {
|
|
2948
2944
|
className,
|
|
@@ -2958,7 +2954,7 @@ function GridBodyFn(props, ref) {
|
|
|
2958
2954
|
const GridBody = (0, react.forwardRef)(GridBodyFn);
|
|
2959
2955
|
function MonthGridBodyFn(props, ref) {
|
|
2960
2956
|
const { render, ...otherProps } = props;
|
|
2961
|
-
const { rootState } =
|
|
2957
|
+
const { rootState } = useViewState();
|
|
2962
2958
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
2963
2959
|
const defaultProps = { children: props.children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) };
|
|
2964
2960
|
const { children: _children, ...restOtherProps } = otherProps;
|
|
@@ -2980,7 +2976,7 @@ const weekInstanceStateAttributesMapping = {
|
|
|
2980
2976
|
function WeekInstance(props) {
|
|
2981
2977
|
const { render, ...otherProps } = props;
|
|
2982
2978
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2983
|
-
const { rootState } =
|
|
2979
|
+
const { rootState } = useViewState();
|
|
2984
2980
|
return (0, _base_ui_react_use_render.useRender)({
|
|
2985
2981
|
defaultTagName: "tr",
|
|
2986
2982
|
render,
|
|
@@ -3005,8 +3001,8 @@ function WeekInstance(props) {
|
|
|
3005
3001
|
function WeekTemplate(props) {
|
|
3006
3002
|
const outerWeekData = (0, react.useContext)(WeekDataContext);
|
|
3007
3003
|
const gridMonthCtx = (0, react.useContext)(GridMonthContext);
|
|
3008
|
-
const
|
|
3009
|
-
const weeks = gridMonthCtx?.weeks ??
|
|
3004
|
+
const monthState = (0, react.useContext)(MonthViewStateContext);
|
|
3005
|
+
const weeks = gridMonthCtx?.weeks ?? monthState?.weeks ?? [];
|
|
3010
3006
|
const gridMonth = (0, react.useMemo)(() => gridMonthCtx ? {
|
|
3011
3007
|
year: gridMonthCtx.year,
|
|
3012
3008
|
month: gridMonthCtx.month
|
|
@@ -3049,7 +3045,7 @@ function DateStringFn(props, ref) {
|
|
|
3049
3045
|
const { render, locales, options, ...otherProps } = props;
|
|
3050
3046
|
const { locale, temporal: T, timeZone } = useCalendarStable();
|
|
3051
3047
|
const { selected } = useCalendarState();
|
|
3052
|
-
const { currentDateTime, rootState } =
|
|
3048
|
+
const { currentDateTime, rootState } = useViewState();
|
|
3053
3049
|
const selectedZdt = selectedToZdt(selected, timeZone, T);
|
|
3054
3050
|
const displayDate = selectedZdt ? zdtToNativeDate(selectedZdt) : new Date(currentDateTime.year, currentDateTime.month - 1, 1);
|
|
3055
3051
|
const formatted = displayDate.toLocaleDateString(locales ?? locale, options);
|
|
@@ -3088,7 +3084,7 @@ function TimeStringFn(props, ref) {
|
|
|
3088
3084
|
const { render, locales, options, ...otherProps } = props;
|
|
3089
3085
|
const { locale, temporal: T, timeZone } = useCalendarStable();
|
|
3090
3086
|
const { selected } = useCalendarState();
|
|
3091
|
-
const { rootState } =
|
|
3087
|
+
const { rootState } = useViewState();
|
|
3092
3088
|
const selZdt = selectedToZdt(selected, timeZone, T);
|
|
3093
3089
|
const displayDate = selZdt ? zdtToNativeDate(selZdt) : zdtToNativeDate(T.Now.zonedDateTimeISO(timeZone));
|
|
3094
3090
|
const mergedOptions = {
|
|
@@ -3354,9 +3350,8 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3354
3350
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3355
3351
|
const { temporal: T } = useCalendarStable();
|
|
3356
3352
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
3357
|
-
const
|
|
3358
|
-
const {
|
|
3359
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
3353
|
+
const { rootState } = useViewState();
|
|
3354
|
+
const { outsideDays } = useViewStable();
|
|
3360
3355
|
const days = weekData?.days ?? [];
|
|
3361
3356
|
const gridMonth = weekData?.gridMonth;
|
|
3362
3357
|
const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gridMonth), [
|
|
@@ -3429,9 +3424,8 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3429
3424
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3430
3425
|
const { temporal: T } = useCalendarStable();
|
|
3431
3426
|
const { previewStart, previewEnd } = useCalendarState();
|
|
3432
|
-
const
|
|
3433
|
-
const {
|
|
3434
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
3427
|
+
const { rootState } = useViewState();
|
|
3428
|
+
const { outsideDays } = useViewStable();
|
|
3435
3429
|
const days = weekData?.days ?? [];
|
|
3436
3430
|
const gridMonth = weekData?.gridMonth;
|
|
3437
3431
|
const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, previewStart, previewEnd, T, outsideDays, gridMonth), [
|
|
@@ -3493,7 +3487,7 @@ const dragHandleStateAttributesMapping = {
|
|
|
3493
3487
|
function useDragHandle(edge, { dragging: draggingProp }) {
|
|
3494
3488
|
const { temporal: T, setHoveredDate, readOnly, disabled } = useCalendarStable();
|
|
3495
3489
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
3496
|
-
const { rootState } =
|
|
3490
|
+
const { rootState } = useViewState();
|
|
3497
3491
|
const cellData = (0, react.useContext)(DayCellDataContext);
|
|
3498
3492
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3499
3493
|
const date = cellData?.date;
|
|
@@ -3576,7 +3570,7 @@ const weekNumberCellStateAttributesMapping = {
|
|
|
3576
3570
|
function WeekNumberCellFn(props, ref) {
|
|
3577
3571
|
const { render, ...otherProps } = props;
|
|
3578
3572
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
3579
|
-
const { rootState } =
|
|
3573
|
+
const { rootState } = useViewState();
|
|
3580
3574
|
const { temporal: T } = useCalendarStable();
|
|
3581
3575
|
const days = weekData?.days ?? [];
|
|
3582
3576
|
const weekNumber = (0, react.useMemo)(() => {
|
|
@@ -3614,7 +3608,7 @@ const WeekNumberCell = (0, react.forwardRef)(WeekNumberCellFn);
|
|
|
3614
3608
|
const weekNumberHeaderStateAttributesMapping = { root: () => null };
|
|
3615
3609
|
function WeekNumberHeaderFn(props, ref) {
|
|
3616
3610
|
const { render, ...otherProps } = props;
|
|
3617
|
-
const { rootState } =
|
|
3611
|
+
const { rootState } = useViewState();
|
|
3618
3612
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
3619
3613
|
return (0, _base_ui_react_use_render.useRender)({
|
|
3620
3614
|
defaultTagName: "th",
|
|
@@ -4211,6 +4205,14 @@ function useWeeksViewRootState(props) {
|
|
|
4211
4205
|
tabTargetDate,
|
|
4212
4206
|
gridHasFocus
|
|
4213
4207
|
]),
|
|
4208
|
+
viewStableCtx: (0, react.useMemo)(() => ({
|
|
4209
|
+
gridFocusedRef,
|
|
4210
|
+
outsideDays: "enabled"
|
|
4211
|
+
}), []),
|
|
4212
|
+
viewStateCtx: (0, react.useMemo)(() => ({
|
|
4213
|
+
currentDateTime,
|
|
4214
|
+
rootState
|
|
4215
|
+
}), [currentDateTime, rootState]),
|
|
4214
4216
|
scrollToWeek
|
|
4215
4217
|
};
|
|
4216
4218
|
}
|
|
@@ -4218,42 +4220,16 @@ function useWeeksViewRootState(props) {
|
|
|
4218
4220
|
//#region src/weeks-view.tsx
|
|
4219
4221
|
function WeeksViewRootFn(props, ref) {
|
|
4220
4222
|
const { children } = props;
|
|
4221
|
-
const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
4223
|
+
const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
4222
4224
|
(0, react.useImperativeHandle)(ref, () => ({ scrollToWeek }), [scrollToWeek]);
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
setGridLabelId: () => {},
|
|
4232
|
-
gridFocusedRef
|
|
4233
|
-
}), []);
|
|
4234
|
-
const monthViewStateShim = (0, react.useMemo)(() => ({
|
|
4235
|
-
currentMonth: {
|
|
4236
|
-
year: stateCtx.currentDateTime.year,
|
|
4237
|
-
month: stateCtx.currentDateTime.month
|
|
4238
|
-
},
|
|
4239
|
-
weeks: [],
|
|
4240
|
-
allMonths: [],
|
|
4241
|
-
currentDateTime: stateCtx.currentDateTime,
|
|
4242
|
-
gridLabelIds: stateCtx.gridLabelIds,
|
|
4243
|
-
rootState: stateCtx.rootState
|
|
4244
|
-
}), [
|
|
4245
|
-
stateCtx.currentDateTime,
|
|
4246
|
-
stateCtx.gridLabelIds,
|
|
4247
|
-
stateCtx.rootState
|
|
4248
|
-
]);
|
|
4249
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
4250
|
-
value: monthViewStableShim,
|
|
4251
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
4252
|
-
value: monthViewStateShim,
|
|
4253
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
|
|
4254
|
-
value: stableCtx,
|
|
4255
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
|
|
4256
|
-
value: stateCtx,
|
|
4225
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
|
|
4226
|
+
value: stableCtx,
|
|
4227
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
|
|
4228
|
+
value: stateCtx,
|
|
4229
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
|
|
4230
|
+
value: viewStableCtx,
|
|
4231
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
|
|
4232
|
+
value: viewStateCtx,
|
|
4257
4233
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
|
|
4258
4234
|
value: viewCtx,
|
|
4259
4235
|
children
|
|
@@ -4298,7 +4274,7 @@ function useWeeksNavButton(direction, shiftByProp) {
|
|
|
4298
4274
|
const { disabled: globalDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
|
|
4299
4275
|
const { weekCount, outOfRangeBehavior, goNext, goPrev } = useWeeksViewStable();
|
|
4300
4276
|
const { windowInfo } = useWeeksViewState();
|
|
4301
|
-
const { rootState } =
|
|
4277
|
+
const { rootState } = useViewState();
|
|
4302
4278
|
const currentFirstWeek = windowInfo.windowStart;
|
|
4303
4279
|
const isDisabled = (0, react.useMemo)(() => {
|
|
4304
4280
|
if (globalDisabled) return true;
|
|
@@ -4384,7 +4360,7 @@ const NextWeeksButton = (0, react.forwardRef)(NextWeeksButtonFn);
|
|
|
4384
4360
|
function WeekCountFn(props, ref) {
|
|
4385
4361
|
const { render, ...otherProps } = props;
|
|
4386
4362
|
const { windowInfo } = useWeeksViewState();
|
|
4387
|
-
const { rootState } =
|
|
4363
|
+
const { rootState } = useViewState();
|
|
4388
4364
|
const count = windowInfo.weekCount;
|
|
4389
4365
|
const state = (0, react.useMemo)(() => ({
|
|
4390
4366
|
root: rootState,
|
|
@@ -1544,13 +1544,6 @@ interface CalendarStateContextValue {
|
|
|
1544
1544
|
baseRootState: BaseRootState;
|
|
1545
1545
|
}
|
|
1546
1546
|
//#endregion
|
|
1547
|
-
//#region src/calendar-provider.d.ts
|
|
1548
|
-
/**
|
|
1549
|
-
* Provides shared calendar state (selection, config, range preview) to all
|
|
1550
|
-
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
1551
|
-
*/
|
|
1552
|
-
declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: CalendarProviderProps<F>): _$react_jsx_runtime0.JSX.Element;
|
|
1553
|
-
//#endregion
|
|
1554
1547
|
//#region src/out-of-range.d.ts
|
|
1555
1548
|
/**
|
|
1556
1549
|
* Controls how a {@link WeeksView} window behaves when navigation would move it
|
|
@@ -2105,4 +2098,4 @@ declare function useWeeksViewStable(): WeeksViewStableContextValue;
|
|
|
2105
2098
|
/** Returns the WeeksView state context (volatile grid data). */
|
|
2106
2099
|
declare function useWeeksViewState(): WeeksViewStateContextValue;
|
|
2107
2100
|
//#endregion
|
|
2108
|
-
export { GridBody as $,
|
|
2101
|
+
export { GridBody as $, TimeStringState as $t, VisibleMonth as A, GridHeaderProps as At, resolveFirstWeekSpec as B, PlainDateObject as Bt, WeekCountState as C, DayCellTemplateState as Ct, WeeksViewProps as D, GridBodyState as Dt, WeeksView as E, GridBodyProps as Et, WeekDescriptor as F, MonthYearStringProps as Ft, RangePreview as G, RangePreviewState as Gt, WeekNumberHeader as H, RangeEndDragHandleProps as Ht, computeWeeksInWindow as I, MonthYearStringState as It, MonthYearString as J, RangeStartDragHandleProps as Jt, RangeSelected as K, RangeSelectedProps as Kt, FirstWeekSpec as L, NavButtonState as Lt, WeeksViewStableContextValue as M, GridProps as Mt, WeeksViewStateContextValue as N, GridState as Nt, WeeksViewRoot as O, GridHeaderCellProps as Ot, WindowInfo as P, MonthData as Pt, Grid as Q, TimeStringProps as Qt, ScrollToWeekSnap as R, NextMonthButtonProps as Rt, WeekCountProps as S, DayCellTemplateProps as St, WeeksNavButtonState as T, DragHandleState as Tt, RangeEndDragHandle as U, RangeMode as Ut, WeekNumberCell as V, PrevMonthButtonProps as Vt, RangeStartDragHandle as W, RangePreviewProps as Wt, PrevMonthButton as X, RootState as Xt, NextMonthButton as Y, RawValueForFormat as Yt, TimeString as Z, TemporalNamespace as Zt, NextWeeksButton as _, DateStringProps as _t, useMonthViewStable as a, WeekNumberHeaderProps as an, MonthView as at, PrevWeeksButtonProps as b, DayButtonProps as bt, useCalendarState as c, WeekTemplateProps as cn, MonthViewRootProps as ct, MonthSeparatorCell as d, GridContext as dn, MonthOutOfRangeBehavior as dt, ValueChangeMeta as en, WeekTemplate as et, MonthSeparatorMonth as f, WeekDataContext as fn, OutOfRangeBehavior as ft, MonthSeparatorYear as g, DateRange as gt, MonthSeparatorWeekCount as h, CalendarStateContextValue as ht, useViewContext as i, WeekNumberCellState as in, GridHeaderCell as it, WeeksViewRootProps as j, GridHeaderState as jt, WeeksViewRootHandle as k, GridHeaderCellState as kt, computePreviewRange as l, WeekTemplateState as ln, MonthViewStableContextValue as lt, MonthSeparatorState as m, CalendarStableContextValue as mt, useWeeksViewState as n, ValueFormat as nn, DayCellTemplate as nt, useMonthViewState as o, WeekNumberHeaderState as on, MonthViewProps as ot, MonthSeparatorRow as p, CalendarProviderProps as pt, DateString as q, RangeSelectedState as qt, ViewContextValue as r, WeekNumberCellProps as rn, GridHeader as rt, useCalendarStable as s, WeekStartDay as sn, MonthViewRoot as st, useWeeksViewStable as t, ValueForFormat as tn, DayButton as tt, MonthSeparator as u, DayCellDataContext as un, MonthViewStateContextValue as ut, NextWeeksButtonProps as v, DateStringState as vt, WeeksNavButtonOwnProps as w, DragHandleOwnProps as wt, WeekCount as x, DayButtonState as xt, PrevWeeksButton as y, DateValueObject as yt, resolveFirstWeek as z, OutsideDays as zt };
|
|
@@ -1544,13 +1544,6 @@ interface CalendarStateContextValue {
|
|
|
1544
1544
|
baseRootState: BaseRootState;
|
|
1545
1545
|
}
|
|
1546
1546
|
//#endregion
|
|
1547
|
-
//#region src/calendar-provider.d.ts
|
|
1548
|
-
/**
|
|
1549
|
-
* Provides shared calendar state (selection, config, range preview) to all
|
|
1550
|
-
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
1551
|
-
*/
|
|
1552
|
-
declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: CalendarProviderProps<F>): _$react_jsx_runtime0.JSX.Element;
|
|
1553
|
-
//#endregion
|
|
1554
1547
|
//#region src/out-of-range.d.ts
|
|
1555
1548
|
/**
|
|
1556
1549
|
* Controls how a {@link WeeksView} window behaves when navigation would move it
|
|
@@ -2105,4 +2098,4 @@ declare function useWeeksViewStable(): WeeksViewStableContextValue;
|
|
|
2105
2098
|
/** Returns the WeeksView state context (volatile grid data). */
|
|
2106
2099
|
declare function useWeeksViewState(): WeeksViewStateContextValue;
|
|
2107
2100
|
//#endregion
|
|
2108
|
-
export { GridBody as $,
|
|
2101
|
+
export { GridBody as $, TimeStringState as $t, VisibleMonth as A, GridHeaderProps as At, resolveFirstWeekSpec as B, PlainDateObject as Bt, WeekCountState as C, DayCellTemplateState as Ct, WeeksViewProps as D, GridBodyState as Dt, WeeksView as E, GridBodyProps as Et, WeekDescriptor as F, MonthYearStringProps as Ft, RangePreview as G, RangePreviewState as Gt, WeekNumberHeader as H, RangeEndDragHandleProps as Ht, computeWeeksInWindow as I, MonthYearStringState as It, MonthYearString as J, RangeStartDragHandleProps as Jt, RangeSelected as K, RangeSelectedProps as Kt, FirstWeekSpec as L, NavButtonState as Lt, WeeksViewStableContextValue as M, GridProps as Mt, WeeksViewStateContextValue as N, GridState as Nt, WeeksViewRoot as O, GridHeaderCellProps as Ot, WindowInfo as P, MonthData as Pt, Grid as Q, TimeStringProps as Qt, ScrollToWeekSnap as R, NextMonthButtonProps as Rt, WeekCountProps as S, DayCellTemplateProps as St, WeeksNavButtonState as T, DragHandleState as Tt, RangeEndDragHandle as U, RangeMode as Ut, WeekNumberCell as V, PrevMonthButtonProps as Vt, RangeStartDragHandle as W, RangePreviewProps as Wt, PrevMonthButton as X, RootState as Xt, NextMonthButton as Y, RawValueForFormat as Yt, TimeString as Z, TemporalNamespace as Zt, NextWeeksButton as _, DateStringProps as _t, useMonthViewStable as a, WeekNumberHeaderProps as an, MonthView as at, PrevWeeksButtonProps as b, DayButtonProps as bt, useCalendarState as c, WeekTemplateProps as cn, MonthViewRootProps as ct, MonthSeparatorCell as d, GridContext as dn, MonthOutOfRangeBehavior as dt, ValueChangeMeta as en, WeekTemplate as et, MonthSeparatorMonth as f, WeekDataContext as fn, OutOfRangeBehavior as ft, MonthSeparatorYear as g, DateRange as gt, MonthSeparatorWeekCount as h, CalendarStateContextValue as ht, useViewContext as i, WeekNumberCellState as in, GridHeaderCell as it, WeeksViewRootProps as j, GridHeaderState as jt, WeeksViewRootHandle as k, GridHeaderCellState as kt, computePreviewRange as l, WeekTemplateState as ln, MonthViewStableContextValue as lt, MonthSeparatorState as m, CalendarStableContextValue as mt, useWeeksViewState as n, ValueFormat as nn, DayCellTemplate as nt, useMonthViewState as o, WeekNumberHeaderState as on, MonthViewProps as ot, MonthSeparatorRow as p, CalendarProviderProps as pt, DateString as q, RangeSelectedState as qt, ViewContextValue as r, WeekNumberCellProps as rn, GridHeader as rt, useCalendarStable as s, WeekStartDay as sn, MonthViewRoot as st, useWeeksViewStable as t, ValueForFormat as tn, DayButton as tt, MonthSeparator as u, DayCellDataContext as un, MonthViewStateContextValue as ut, NextWeeksButtonProps as v, DateStringState as vt, WeeksNavButtonOwnProps as w, DragHandleOwnProps as wt, WeekCount as x, DayButtonState as xt, PrevWeeksButton as y, DateValueObject as yt, resolveFirstWeek as z, OutsideDays as zt };
|
package/package.json
CHANGED
package/src/day-cell.tsx
CHANGED
|
@@ -5,8 +5,7 @@ import { useContext, useEffect, useRef, memo, forwardRef } from "react";
|
|
|
5
5
|
import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
6
6
|
import { WeekDataContext, DayCellDataContext, GridContext } from "./context";
|
|
7
7
|
import type { GridOrientation } from "./context";
|
|
8
|
-
import {
|
|
9
|
-
import { useMonthViewState } from "./month-view-context";
|
|
8
|
+
import { MonthViewStateContext } from "./month-view-context";
|
|
10
9
|
import type { StateAttributesMapping } from "./types";
|
|
11
10
|
import type {
|
|
12
11
|
DayCellTemplateProps,
|
|
@@ -16,7 +15,7 @@ import type {
|
|
|
16
15
|
OutsideDays,
|
|
17
16
|
} from "./types";
|
|
18
17
|
import { shouldMoveDomFocus, isInRange as isInRangeUtil } from "./utils";
|
|
19
|
-
import { useViewContext } from "./view-context";
|
|
18
|
+
import { useViewContext, useViewStable, useViewState } from "./view-context";
|
|
20
19
|
|
|
21
20
|
/** Computes derived day cell state from context values. Pure function, no hooks. */
|
|
22
21
|
export function computeDayCellState(
|
|
@@ -398,11 +397,9 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
398
397
|
|
|
399
398
|
const viewCtx = useViewContext();
|
|
400
399
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
const monthState =
|
|
404
|
-
const { rootState, weeks, currentMonth: currentDateTime } = monthState;
|
|
405
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
400
|
+
const { rootState, currentDateTime } = useViewState();
|
|
401
|
+
const { outsideDays } = useViewStable();
|
|
402
|
+
const monthState = useContext(MonthViewStateContext);
|
|
406
403
|
|
|
407
404
|
// Use the grid-specific month for outsideMonth checks, falling back to currentMonth.
|
|
408
405
|
// In multi-month mode, gridMonth is set by WeekTemplate from GridMonthContext.
|
|
@@ -443,7 +440,7 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
|
|
|
443
440
|
);
|
|
444
441
|
}
|
|
445
442
|
|
|
446
|
-
const days = weekData ? weekData.days : weeks.flat();
|
|
443
|
+
const days = weekData ? weekData.days : (monthState?.weeks.flat() ?? []);
|
|
447
444
|
const perWeek = weekData != null;
|
|
448
445
|
|
|
449
446
|
return (
|
|
@@ -502,8 +499,7 @@ function DayButtonInnerFn(
|
|
|
502
499
|
const { render, date, _derivedState, ...otherProps } = props;
|
|
503
500
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
504
501
|
const { setFocusedDate } = useViewContext();
|
|
505
|
-
const
|
|
506
|
-
const gridFocusedRef = monthStable!.gridFocusedRef;
|
|
502
|
+
const { gridFocusedRef } = useViewStable();
|
|
507
503
|
|
|
508
504
|
const internalRef = useRef<HTMLButtonElement>(null);
|
|
509
505
|
|
|
@@ -669,10 +665,8 @@ function DayButtonFallbackFn(
|
|
|
669
665
|
useCalendarState();
|
|
670
666
|
const viewCtx = useViewContext();
|
|
671
667
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
672
|
-
const
|
|
673
|
-
const
|
|
674
|
-
const { rootState, currentMonth: currentDateTime } = monthState;
|
|
675
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
668
|
+
const { rootState, currentDateTime } = useViewState();
|
|
669
|
+
const { outsideDays } = useViewStable();
|
|
676
670
|
|
|
677
671
|
const isWeeksView = viewCtx.viewType === "weeks";
|
|
678
672
|
const cellMonth = isWeeksView
|
package/src/drag-handle.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
3
3
|
import { forwardRef, useContext, useMemo, useRef } from "react";
|
|
4
4
|
import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
5
5
|
import { DayCellDataContext, GridContext } from "./context";
|
|
6
|
-
import { useMonthViewState } from "./month-view-context";
|
|
7
6
|
import type { StateAttributesMapping } from "./types";
|
|
8
7
|
import type {
|
|
9
8
|
DragHandleState,
|
|
@@ -11,6 +10,7 @@ import type {
|
|
|
11
10
|
RangeEndDragHandleProps,
|
|
12
11
|
RangeDragHandleProps,
|
|
13
12
|
} from "./types";
|
|
13
|
+
import { useViewState } from "./view-context";
|
|
14
14
|
|
|
15
15
|
const dragHandleStateAttributesMapping = {
|
|
16
16
|
root: () => null,
|
|
@@ -31,7 +31,7 @@ function useDragHandle(
|
|
|
31
31
|
disabled,
|
|
32
32
|
} = useCalendarStable();
|
|
33
33
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
34
|
-
const { rootState } =
|
|
34
|
+
const { rootState } = useViewState();
|
|
35
35
|
const cellData = useContext(DayCellDataContext);
|
|
36
36
|
const { orientation } = useContext(GridContext);
|
|
37
37
|
const date = cellData?.date;
|
package/src/grid-header.tsx
CHANGED
|
@@ -2,7 +2,6 @@ import { mergeProps } from "@base-ui/react/merge-props";
|
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
3
|
import { forwardRef, useMemo } from "react";
|
|
4
4
|
import { useCalendarStable } from "./calendar-context";
|
|
5
|
-
import { useMonthViewState } from "./month-view-context";
|
|
6
5
|
import type { StateAttributesMapping } from "./types";
|
|
7
6
|
import type {
|
|
8
7
|
GridHeaderCellProps,
|
|
@@ -11,10 +10,11 @@ import type {
|
|
|
11
10
|
GridHeaderCellState,
|
|
12
11
|
} from "./types";
|
|
13
12
|
import { getWeekdayNames, getReferenceWeekStart } from "./utils";
|
|
13
|
+
import { useViewState } from "./view-context";
|
|
14
14
|
|
|
15
15
|
function useGridHeaderCellState(index: number) {
|
|
16
16
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
17
|
-
const { rootState } =
|
|
17
|
+
const { rootState } = useViewState();
|
|
18
18
|
|
|
19
19
|
const weekdayNames = useMemo(
|
|
20
20
|
() => getWeekdayNames(locale, T, weekStartDay),
|
|
@@ -120,7 +120,7 @@ function GridHeaderFn(
|
|
|
120
120
|
ref: React.ForwardedRef<HTMLTableSectionElement>,
|
|
121
121
|
) {
|
|
122
122
|
const { render, children, ...otherProps } = props;
|
|
123
|
-
const { rootState } =
|
|
123
|
+
const { rootState } = useViewState();
|
|
124
124
|
|
|
125
125
|
const state = useMemo<GridHeaderState>(
|
|
126
126
|
() => ({ root: rootState as unknown as GridHeaderState["root"] }),
|