@klinking/colander 3.1.0-alpha.6 → 3.1.0-alpha.8
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 +2 -3
- package/dist/formats/date.d.cts +10 -14
- package/dist/formats/date.d.mts +10 -14
- package/dist/formats/date.mjs +2 -3
- package/dist/formats/object.cjs +2 -3
- package/dist/formats/object.d.cts +10 -14
- package/dist/formats/object.d.mts +10 -14
- package/dist/formats/object.mjs +2 -3
- package/dist/formats/plain-date-time.cjs +2 -3
- package/dist/formats/plain-date-time.d.cts +10 -14
- package/dist/formats/plain-date-time.d.mts +10 -14
- package/dist/formats/plain-date-time.mjs +2 -3
- package/dist/formats/plain-date.cjs +2 -3
- package/dist/formats/plain-date.d.cts +10 -14
- package/dist/formats/plain-date.d.mts +10 -14
- package/dist/formats/plain-date.mjs +2 -3
- package/dist/formats/plain-month-day.cjs +2 -3
- package/dist/formats/plain-month-day.d.cts +10 -14
- package/dist/formats/plain-month-day.d.mts +10 -14
- package/dist/formats/plain-month-day.mjs +2 -3
- package/dist/formats/plain-year-month.cjs +2 -3
- package/dist/formats/plain-year-month.d.cts +10 -14
- package/dist/formats/plain-year-month.d.mts +10 -14
- package/dist/formats/plain-year-month.mjs +2 -3
- package/dist/formats/zoned-date-time.cjs +2 -3
- package/dist/formats/zoned-date-time.d.cts +10 -14
- package/dist/formats/zoned-date-time.d.mts +10 -14
- package/dist/formats/zoned-date-time.mjs +2 -3
- package/dist/{index-DnFCKyyw.d.cts → index-BqzrxYgn.d.cts} +106 -116
- package/dist/{index-q3cQKJdA.d.mts → index-CkhYFmf4.d.mts} +106 -116
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -2
- package/dist/{weeks-navigation-Dn3UtG76.mjs → weeks-navigation-BWB5OvqW.mjs} +151 -188
- package/dist/{weeks-navigation-SuKJZJCM.cjs → weeks-navigation-CatYJIKb.cjs} +153 -191
- package/package.json +17 -18
- package/src/calendar-provider.test.tsx +1 -1
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +1 -1
- package/src/day-cell.test.tsx +1 -1
- package/src/formats/formats.test.ts +1 -1
- package/src/grid.event-perf.test.tsx +7 -1
- package/src/grid.perf.test.tsx +7 -1
- package/src/grid.tsx +1 -1
- package/src/keyboard.test.ts +1 -1
- package/src/month-separator.test.tsx +1 -1
- package/src/month-view.bounds.test.tsx +1 -1
- package/src/month-view.test.tsx +89 -1
- package/src/month-view.tsx +14 -5
- package/src/month-window.test.ts +1 -1
- package/src/out-of-range.test.ts +34 -54
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +1 -1
- package/src/resolve-first-week.test.ts +1 -1
- package/src/today.test.tsx +8 -1
- package/src/utils.bench.ts +158 -106
- package/src/utils.test.ts +1 -1
- package/src/view-context.test.tsx +1 -1
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-navigation.tsx +15 -6
- package/src/weeks-view-state.ts +21 -12
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-view.test.tsx +1 -1
- package/src/weeks-window.test.ts +110 -22
- package/src/weeks-window.ts +57 -19
|
@@ -2,7 +2,7 @@ import { Children, createContext, forwardRef, isValidElement, memo, useCallback,
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
4
4
|
import { useRender } from "@base-ui/react/use-render";
|
|
5
|
-
|
|
5
|
+
// src/calendar-context.ts
|
|
6
6
|
/** @internal React context carrying stable CalendarProvider values (callbacks, config). */
|
|
7
7
|
const CalendarStableContext = createContext(null);
|
|
8
8
|
/** @internal React context carrying volatile CalendarProvider state. */
|
|
@@ -19,8 +19,7 @@ function useCalendarState() {
|
|
|
19
19
|
if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
|
|
20
20
|
return ctx;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
//#region src/utils.ts
|
|
22
|
+
// src/utils.ts
|
|
24
23
|
/**
|
|
25
24
|
* Resolves a {@link TemporalNamespace} instance.
|
|
26
25
|
*
|
|
@@ -466,8 +465,7 @@ function getISOWeekNumber(date, T) {
|
|
|
466
465
|
const daysDiff = thursday.since(jan4Thursday, { largestUnit: "days" }).days;
|
|
467
466
|
return Math.round(daysDiff / 7) + 1;
|
|
468
467
|
}
|
|
469
|
-
|
|
470
|
-
//#region src/root-selection.ts
|
|
468
|
+
// src/root-selection.ts
|
|
471
469
|
/** Construct a DateRange (workaround for TS generic conditional type widening). */
|
|
472
470
|
function mkRange(start, end) {
|
|
473
471
|
return {
|
|
@@ -832,8 +830,7 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
|
|
|
832
830
|
});
|
|
833
831
|
return preview ? mkRange(preview[0], preview[1]) : null;
|
|
834
832
|
}
|
|
835
|
-
|
|
836
|
-
//#region src/calendar-provider.tsx
|
|
833
|
+
// src/calendar-provider.tsx
|
|
837
834
|
/**
|
|
838
835
|
* Provides shared calendar state (selection, config, range preview) to all
|
|
839
836
|
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
@@ -951,7 +948,7 @@ function CalendarProvider(props) {
|
|
|
951
948
|
isRange,
|
|
952
949
|
isMultiple
|
|
953
950
|
]);
|
|
954
|
-
const
|
|
951
|
+
const defaultDates = useMemo(() => {
|
|
955
952
|
if (isMultiple) {
|
|
956
953
|
if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
|
|
957
954
|
return [];
|
|
@@ -966,7 +963,8 @@ function CalendarProvider(props) {
|
|
|
966
963
|
singleDefault,
|
|
967
964
|
rawToPlain,
|
|
968
965
|
sortDates
|
|
969
|
-
])
|
|
966
|
+
]);
|
|
967
|
+
const [internalDates, setInternalDates] = useState(defaultDates);
|
|
970
968
|
const isControlled = controlledDates !== void 0;
|
|
971
969
|
const committedDates = isControlled ? controlledDates : internalDates;
|
|
972
970
|
const rangeStart = !isMultiple && committedDates.length > 0 ? committedDates[0] ?? void 0 : void 0;
|
|
@@ -1277,8 +1275,7 @@ function CalendarProvider(props) {
|
|
|
1277
1275
|
})
|
|
1278
1276
|
});
|
|
1279
1277
|
}
|
|
1280
|
-
|
|
1281
|
-
//#region src/month-view-context.ts
|
|
1278
|
+
// src/month-view-context.ts
|
|
1282
1279
|
/** @internal React context for MonthView stable values (config + callbacks). */
|
|
1283
1280
|
const MonthViewStableContext = createContext(null);
|
|
1284
1281
|
/** @internal React context for MonthView volatile state. */
|
|
@@ -1295,8 +1292,7 @@ function useMonthViewState() {
|
|
|
1295
1292
|
if (!ctx) throw new Error("useMonthViewState must be used within MonthView.Root");
|
|
1296
1293
|
return ctx;
|
|
1297
1294
|
}
|
|
1298
|
-
|
|
1299
|
-
//#region src/month-view-navigation.ts
|
|
1295
|
+
// src/month-view-navigation.ts
|
|
1300
1296
|
/**
|
|
1301
1297
|
* Owns which month the view shows, in both controlled and uncontrolled mode:
|
|
1302
1298
|
* the month state, the Prev/Next steps, and syncing the window with focus.
|
|
@@ -1415,8 +1411,7 @@ function useMonthNavigation(input) {
|
|
|
1415
1411
|
goPrevMonth: useCallback(() => go("prev"), [go])
|
|
1416
1412
|
};
|
|
1417
1413
|
}
|
|
1418
|
-
|
|
1419
|
-
//#region src/month-window.ts
|
|
1414
|
+
// src/month-window.ts
|
|
1420
1415
|
const monthIndex = (m) => m.year * 12 + (m.month - 1);
|
|
1421
1416
|
/**
|
|
1422
1417
|
* Builds the policy for a MonthView window of `numberOfMonths` months.
|
|
@@ -1466,8 +1461,7 @@ function monthAt(start, offset) {
|
|
|
1466
1461
|
month: index % 12 + 1
|
|
1467
1462
|
};
|
|
1468
1463
|
}
|
|
1469
|
-
|
|
1470
|
-
//#region src/view-context.ts
|
|
1464
|
+
// src/view-context.ts
|
|
1471
1465
|
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1472
1466
|
const ViewContext = createContext(null);
|
|
1473
1467
|
/** Returns the nearest view context (MonthView or WeeksView). */
|
|
@@ -1492,8 +1486,7 @@ function useViewState() {
|
|
|
1492
1486
|
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1493
1487
|
return ctx;
|
|
1494
1488
|
}
|
|
1495
|
-
|
|
1496
|
-
//#region src/month-view.tsx
|
|
1489
|
+
// src/month-view.tsx
|
|
1497
1490
|
function MonthViewRoot(props) {
|
|
1498
1491
|
const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
|
|
1499
1492
|
const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
|
|
@@ -1504,7 +1497,6 @@ function MonthViewRoot(props) {
|
|
|
1504
1497
|
const calState = useCalendarState();
|
|
1505
1498
|
const T = calStable.temporal;
|
|
1506
1499
|
const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
|
|
1507
|
-
const [focusedDate, setFocusedDate] = useState(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
|
|
1508
1500
|
const [gridHasFocus, setGridHasFocus] = useState(false);
|
|
1509
1501
|
const gridFocusedRef = useRef(false);
|
|
1510
1502
|
const { minValue, maxValue } = calStable;
|
|
@@ -1521,6 +1513,16 @@ function MonthViewRoot(props) {
|
|
|
1521
1513
|
maxValue,
|
|
1522
1514
|
T
|
|
1523
1515
|
]);
|
|
1516
|
+
const [focusedDate, setFocusedDate] = useState(() => {
|
|
1517
|
+
const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
|
|
1518
|
+
const opening = monthProp ?? defaultMonthProp;
|
|
1519
|
+
if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
|
|
1520
|
+
return T.PlainDate.from({
|
|
1521
|
+
year: opening.year,
|
|
1522
|
+
month: opening.month,
|
|
1523
|
+
day: 1
|
|
1524
|
+
});
|
|
1525
|
+
});
|
|
1524
1526
|
const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
|
|
1525
1527
|
month: monthProp,
|
|
1526
1528
|
defaultMonth: defaultMonthProp,
|
|
@@ -1709,8 +1711,7 @@ function MonthView(props) {
|
|
|
1709
1711
|
});
|
|
1710
1712
|
}
|
|
1711
1713
|
MonthView.Root = MonthViewRoot;
|
|
1712
|
-
|
|
1713
|
-
//#region src/context.ts
|
|
1714
|
+
// src/context.ts
|
|
1714
1715
|
/** @internal Provides the days and index of the current week row to child components. */
|
|
1715
1716
|
const WeekDataContext = createContext(null);
|
|
1716
1717
|
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
@@ -1719,8 +1720,7 @@ const GridContext = createContext({ orientation: "horizontal" });
|
|
|
1719
1720
|
const DayCellDataContext = createContext(null);
|
|
1720
1721
|
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1721
1722
|
const GridMonthContext = createContext(null);
|
|
1722
|
-
|
|
1723
|
-
//#region src/grid-header.tsx
|
|
1723
|
+
// src/grid-header.tsx
|
|
1724
1724
|
function useGridHeaderCellState(index) {
|
|
1725
1725
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
1726
1726
|
const { rootState } = useViewState();
|
|
@@ -1812,8 +1812,7 @@ function GridHeaderFn(props, ref) {
|
|
|
1812
1812
|
}
|
|
1813
1813
|
/** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
|
|
1814
1814
|
const GridHeader = forwardRef(GridHeaderFn);
|
|
1815
|
-
|
|
1816
|
-
//#region src/keyboard.ts
|
|
1815
|
+
// src/keyboard.ts
|
|
1817
1816
|
/**
|
|
1818
1817
|
* Computes the target date when jumping by `months` from `focusedDate`.
|
|
1819
1818
|
*
|
|
@@ -1886,8 +1885,7 @@ function computeNextFocusDate(input) {
|
|
|
1886
1885
|
if (nextDate) return clampToBounds(nextDate, focusedDate, minValue, maxValue, T);
|
|
1887
1886
|
return { action: "none" };
|
|
1888
1887
|
}
|
|
1889
|
-
|
|
1890
|
-
//#region src/month-separator.tsx
|
|
1888
|
+
// src/month-separator.tsx
|
|
1891
1889
|
/** Context providing MonthSeparator data to child components. */
|
|
1892
1890
|
const MonthSeparatorDataContext = createContext(null);
|
|
1893
1891
|
function useMonthSeparatorData() {
|
|
@@ -2017,8 +2015,7 @@ function MonthSeparatorFn(props, ref) {
|
|
|
2017
2015
|
* Default children: `<Month /> <Year />`.
|
|
2018
2016
|
*/
|
|
2019
2017
|
const MonthSeparator = forwardRef(MonthSeparatorFn);
|
|
2020
|
-
|
|
2021
|
-
//#region src/weeks-view-context.ts
|
|
2018
|
+
// src/weeks-view-context.ts
|
|
2022
2019
|
/** @internal React context for WeeksView stable values (config + callbacks). */
|
|
2023
2020
|
const WeeksViewStableContext = createContext(null);
|
|
2024
2021
|
/** @internal React context for WeeksView volatile state. */
|
|
@@ -2035,8 +2032,7 @@ function useWeeksViewState() {
|
|
|
2035
2032
|
if (!ctx) throw new Error("useWeeksViewState must be used within WeeksView.Root");
|
|
2036
2033
|
return ctx;
|
|
2037
2034
|
}
|
|
2038
|
-
|
|
2039
|
-
//#region src/weeks-grid.tsx
|
|
2035
|
+
// src/weeks-grid.tsx
|
|
2040
2036
|
/**
|
|
2041
2037
|
* @internal WeeksGrid — renders continuous week rows for WeeksView.
|
|
2042
2038
|
* Not exported from the public API.
|
|
@@ -2202,8 +2198,7 @@ function WeeksGrid(props) {
|
|
|
2202
2198
|
children: rows
|
|
2203
2199
|
});
|
|
2204
2200
|
}
|
|
2205
|
-
|
|
2206
|
-
//#region src/weeks-keyboard.ts
|
|
2201
|
+
// src/weeks-keyboard.ts
|
|
2207
2202
|
const NONE = {
|
|
2208
2203
|
action: "none",
|
|
2209
2204
|
windowShift: 0,
|
|
@@ -2277,8 +2272,7 @@ function computeWeeksKeyNav(input) {
|
|
|
2277
2272
|
default: return NONE;
|
|
2278
2273
|
}
|
|
2279
2274
|
}
|
|
2280
|
-
|
|
2281
|
-
//#region src/day-cell-state.ts
|
|
2275
|
+
// src/day-cell-state.ts
|
|
2282
2276
|
const NO_RANGE = {
|
|
2283
2277
|
rangeStart: false,
|
|
2284
2278
|
rangeEnd: false,
|
|
@@ -2450,8 +2444,7 @@ function useDayCellDeriver() {
|
|
|
2450
2444
|
}, inputs);
|
|
2451
2445
|
};
|
|
2452
2446
|
}
|
|
2453
|
-
|
|
2454
|
-
//#region src/day-cell.tsx
|
|
2447
|
+
// src/day-cell.tsx
|
|
2455
2448
|
const dayStateAttributesMapping = {
|
|
2456
2449
|
root: () => null,
|
|
2457
2450
|
date: (v) => v ? { "data-date": v.toString() } : null,
|
|
@@ -2483,22 +2476,23 @@ const dayStateAttributesMapping = {
|
|
|
2483
2476
|
function DayCellInstanceFn(props) {
|
|
2484
2477
|
const { render, date, columnIndex, children, _derivedState, ...otherProps } = props;
|
|
2485
2478
|
const state = _derivedState;
|
|
2479
|
+
const defaultProps = state.hidden ? {
|
|
2480
|
+
role: "gridcell",
|
|
2481
|
+
"aria-hidden": true,
|
|
2482
|
+
children: null
|
|
2483
|
+
} : {
|
|
2484
|
+
role: "gridcell",
|
|
2485
|
+
"aria-selected": state.selected || void 0,
|
|
2486
|
+
"aria-disabled": state.disabled || void 0,
|
|
2487
|
+
children: children ?? /* @__PURE__ */ jsx(DayButton, { _derivedState })
|
|
2488
|
+
};
|
|
2486
2489
|
const cell = useRender({
|
|
2487
2490
|
defaultTagName: "td",
|
|
2488
2491
|
render,
|
|
2489
2492
|
ref: [],
|
|
2490
2493
|
state,
|
|
2491
2494
|
stateAttributesMapping: dayStateAttributesMapping,
|
|
2492
|
-
props: mergeProps(
|
|
2493
|
-
role: "gridcell",
|
|
2494
|
-
"aria-hidden": true,
|
|
2495
|
-
children: null
|
|
2496
|
-
} : {
|
|
2497
|
-
role: "gridcell",
|
|
2498
|
-
"aria-selected": state.selected || void 0,
|
|
2499
|
-
"aria-disabled": state.disabled || void 0,
|
|
2500
|
-
children: children ?? /* @__PURE__ */ jsx(DayButton, { _derivedState })
|
|
2501
|
-
}, otherProps)
|
|
2495
|
+
props: mergeProps(defaultProps, otherProps)
|
|
2502
2496
|
});
|
|
2503
2497
|
const outsideDisabled = state.hidden || state.outsideMonth && state.disabled;
|
|
2504
2498
|
return /* @__PURE__ */ jsx(DayCellDataContext.Provider, {
|
|
@@ -2523,14 +2517,14 @@ function passThroughPropsEqual(prev, next, handledKeys) {
|
|
|
2523
2517
|
for (const key of prevKeys) if (prev[key] !== next[key]) return false;
|
|
2524
2518
|
return true;
|
|
2525
2519
|
}
|
|
2526
|
-
const DAY_CELL_HANDLED_KEYS = new Set([
|
|
2520
|
+
const DAY_CELL_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2527
2521
|
"render",
|
|
2528
2522
|
"date",
|
|
2529
2523
|
"columnIndex",
|
|
2530
2524
|
"children",
|
|
2531
2525
|
"_derivedState"
|
|
2532
2526
|
]);
|
|
2533
|
-
const DAY_BUTTON_HANDLED_KEYS = new Set([
|
|
2527
|
+
const DAY_BUTTON_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2534
2528
|
"render",
|
|
2535
2529
|
"date",
|
|
2536
2530
|
"children",
|
|
@@ -2659,8 +2653,7 @@ function DayButtonFallbackFn(props, ref) {
|
|
|
2659
2653
|
});
|
|
2660
2654
|
}
|
|
2661
2655
|
const DayButtonFallback = forwardRef(DayButtonFallbackFn);
|
|
2662
|
-
|
|
2663
|
-
//#region src/grid.tsx
|
|
2656
|
+
// src/grid.tsx
|
|
2664
2657
|
function useGridKeyboard() {
|
|
2665
2658
|
const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
|
|
2666
2659
|
const { focusedDate, setFocusedDate } = useViewContext();
|
|
@@ -2708,7 +2701,7 @@ function useWeeksGridKeyboard() {
|
|
|
2708
2701
|
shiftKey: e.shiftKey,
|
|
2709
2702
|
focusedDate,
|
|
2710
2703
|
windowStart: weeksState.windowInfo.windowStart,
|
|
2711
|
-
weekCount:
|
|
2704
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
2712
2705
|
minValue,
|
|
2713
2706
|
maxValue,
|
|
2714
2707
|
disabled,
|
|
@@ -2994,19 +2987,20 @@ function WeekInstance(props) {
|
|
|
2994
2987
|
const { render, ...otherProps } = props;
|
|
2995
2988
|
const weekData = useContext(WeekDataContext);
|
|
2996
2989
|
const { rootState } = useViewState();
|
|
2990
|
+
const state = useMemo(() => ({
|
|
2991
|
+
root: rootState,
|
|
2992
|
+
weekIndex: weekData.weekIndex,
|
|
2993
|
+
gridRowIndex: weekData.gridRowIndex
|
|
2994
|
+
}), [
|
|
2995
|
+
rootState,
|
|
2996
|
+
weekData.weekIndex,
|
|
2997
|
+
weekData.gridRowIndex
|
|
2998
|
+
]);
|
|
2997
2999
|
return useRender({
|
|
2998
3000
|
defaultTagName: "tr",
|
|
2999
3001
|
render,
|
|
3000
3002
|
ref: [],
|
|
3001
|
-
state
|
|
3002
|
-
root: rootState,
|
|
3003
|
-
weekIndex: weekData.weekIndex,
|
|
3004
|
-
gridRowIndex: weekData.gridRowIndex
|
|
3005
|
-
}), [
|
|
3006
|
-
rootState,
|
|
3007
|
-
weekData.weekIndex,
|
|
3008
|
-
weekData.gridRowIndex
|
|
3009
|
-
]),
|
|
3003
|
+
state,
|
|
3010
3004
|
stateAttributesMapping: weekInstanceStateAttributesMapping,
|
|
3011
3005
|
props: mergeProps({}, otherProps)
|
|
3012
3006
|
});
|
|
@@ -3039,8 +3033,7 @@ function WeekTemplate(props) {
|
|
|
3039
3033
|
}, firstDay.toString());
|
|
3040
3034
|
}) });
|
|
3041
3035
|
}
|
|
3042
|
-
|
|
3043
|
-
//#region src/navigation.tsx
|
|
3036
|
+
// src/navigation.tsx
|
|
3044
3037
|
const dateStringStateAttributesMapping = {
|
|
3045
3038
|
root: () => null,
|
|
3046
3039
|
month: () => null,
|
|
@@ -3276,8 +3269,7 @@ function NextMonthButtonFn(props, ref) {
|
|
|
3276
3269
|
* when the next month falls after `max`. Exposes `data-direction="next"`.
|
|
3277
3270
|
*/
|
|
3278
3271
|
const NextMonthButton = forwardRef(NextMonthButtonFn);
|
|
3279
|
-
|
|
3280
|
-
//#region src/selected-range.tsx
|
|
3272
|
+
// src/selected-range.tsx
|
|
3281
3273
|
const rangeOverlayStateAttributesMapping = {
|
|
3282
3274
|
root: () => null,
|
|
3283
3275
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3397,8 +3389,7 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3397
3389
|
});
|
|
3398
3390
|
}
|
|
3399
3391
|
const RangeSelectedInner = forwardRef(RangeSelectedInnerFn);
|
|
3400
|
-
|
|
3401
|
-
//#region src/range-preview.tsx
|
|
3392
|
+
// src/range-preview.tsx
|
|
3402
3393
|
function RangePreviewFn(props, ref) {
|
|
3403
3394
|
const { selectionMode } = useCalendarStable();
|
|
3404
3395
|
if (selectionMode !== "range") return null;
|
|
@@ -3471,8 +3462,7 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3471
3462
|
});
|
|
3472
3463
|
}
|
|
3473
3464
|
const RangePreviewInner = forwardRef(RangePreviewInnerFn);
|
|
3474
|
-
|
|
3475
|
-
//#region src/drag-handle.tsx
|
|
3465
|
+
// src/drag-handle.tsx
|
|
3476
3466
|
const dragHandleStateAttributesMapping = {
|
|
3477
3467
|
root: () => null,
|
|
3478
3468
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3491,32 +3481,34 @@ function useDragHandle(edge, { dragging: draggingProp }) {
|
|
|
3491
3481
|
const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
|
|
3492
3482
|
const isDragging = !!draggingProp && isActive;
|
|
3493
3483
|
const handleRef = useRef(null);
|
|
3484
|
+
const state = useMemo(() => ({
|
|
3485
|
+
root: rootState,
|
|
3486
|
+
active: isActive,
|
|
3487
|
+
dragging: isDragging,
|
|
3488
|
+
edge,
|
|
3489
|
+
orientation
|
|
3490
|
+
}), [
|
|
3491
|
+
rootState,
|
|
3492
|
+
isActive,
|
|
3493
|
+
isDragging,
|
|
3494
|
+
edge,
|
|
3495
|
+
orientation
|
|
3496
|
+
]);
|
|
3497
|
+
const defaultProps = {
|
|
3498
|
+
role: "slider",
|
|
3499
|
+
"aria-roledescription": "drag handle",
|
|
3500
|
+
"aria-label": edge === "start" ? "Range start date" : "Range end date",
|
|
3501
|
+
"aria-valuetext": date?.toString(),
|
|
3502
|
+
"aria-grabbed": isActive ? isDragging : void 0,
|
|
3503
|
+
"aria-hidden": isActive ? void 0 : true,
|
|
3504
|
+
onPointerEnter: () => {
|
|
3505
|
+
if (date && !outsideDisabled) setHoveredDate(date);
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3494
3508
|
return {
|
|
3495
|
-
state
|
|
3496
|
-
root: rootState,
|
|
3497
|
-
active: isActive,
|
|
3498
|
-
dragging: isDragging,
|
|
3499
|
-
edge,
|
|
3500
|
-
orientation
|
|
3501
|
-
}), [
|
|
3502
|
-
rootState,
|
|
3503
|
-
isActive,
|
|
3504
|
-
isDragging,
|
|
3505
|
-
edge,
|
|
3506
|
-
orientation
|
|
3507
|
-
]),
|
|
3509
|
+
state,
|
|
3508
3510
|
stateAttributesMapping: dragHandleStateAttributesMapping,
|
|
3509
|
-
defaultProps
|
|
3510
|
-
role: "slider",
|
|
3511
|
-
"aria-roledescription": "drag handle",
|
|
3512
|
-
"aria-label": edge === "start" ? "Range start date" : "Range end date",
|
|
3513
|
-
"aria-valuetext": date?.toString(),
|
|
3514
|
-
"aria-grabbed": isActive ? isDragging : void 0,
|
|
3515
|
-
"aria-hidden": isActive ? void 0 : true,
|
|
3516
|
-
onPointerEnter: () => {
|
|
3517
|
-
if (date && !outsideDisabled) setHoveredDate(date);
|
|
3518
|
-
}
|
|
3519
|
-
},
|
|
3511
|
+
defaultProps,
|
|
3520
3512
|
handleRef
|
|
3521
3513
|
};
|
|
3522
3514
|
}
|
|
@@ -3557,8 +3549,7 @@ function RangeEndDragHandleFn(props, ref) {
|
|
|
3557
3549
|
}
|
|
3558
3550
|
/** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
|
|
3559
3551
|
const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn);
|
|
3560
|
-
|
|
3561
|
-
//#region src/week-number.tsx
|
|
3552
|
+
// src/week-number.tsx
|
|
3562
3553
|
const weekNumberCellStateAttributesMapping = {
|
|
3563
3554
|
root: () => null,
|
|
3564
3555
|
weekNumber: (v) => ({ "data-week-number": String(v) })
|
|
@@ -3623,8 +3614,7 @@ function WeekNumberHeaderFn(props, ref) {
|
|
|
3623
3614
|
* Column header for the week number column. Renders a `<th scope="col">`.
|
|
3624
3615
|
*/
|
|
3625
3616
|
const WeekNumberHeader = forwardRef(WeekNumberHeaderFn);
|
|
3626
|
-
|
|
3627
|
-
//#region src/compute-weeks-in-window.ts
|
|
3617
|
+
// src/compute-weeks-in-window.ts
|
|
3628
3618
|
/**
|
|
3629
3619
|
* Computes an array of week descriptors for a continuous window.
|
|
3630
3620
|
* `firstWeek` is snapped back to the nearest `weekStartDay`.
|
|
@@ -3646,8 +3636,7 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
|
|
|
3646
3636
|
}
|
|
3647
3637
|
return weeks;
|
|
3648
3638
|
}
|
|
3649
|
-
|
|
3650
|
-
//#region src/resolve-first-week.ts
|
|
3639
|
+
// src/resolve-first-week.ts
|
|
3651
3640
|
/** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
|
|
3652
3641
|
function snapToWeekStart(date, weekStartDay) {
|
|
3653
3642
|
const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
@@ -3738,29 +3727,25 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
|
3738
3727
|
}
|
|
3739
3728
|
}
|
|
3740
3729
|
}
|
|
3741
|
-
|
|
3742
|
-
//#region src/out-of-range.ts
|
|
3730
|
+
// src/out-of-range.ts
|
|
3743
3731
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3744
3732
|
function weekHasValidDay(weekStart, min, max, T) {
|
|
3745
3733
|
const weekEnd = weekStart.add({ days: 6 });
|
|
3746
|
-
return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
|
|
3734
|
+
return (!max || T.PlainDate.compare(weekStart, max) <= 0) && (!min || T.PlainDate.compare(weekEnd, min) >= 0);
|
|
3735
|
+
}
|
|
3736
|
+
/** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
|
|
3737
|
+
function windowHasValidWeek(firstWeek, weekCount, min, max, T) {
|
|
3738
|
+
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
|
|
3739
|
+
return false;
|
|
3747
3740
|
}
|
|
3748
3741
|
/**
|
|
3749
3742
|
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
3750
3743
|
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
3751
3744
|
*/
|
|
3752
|
-
function weekStartContaining(date, weekStartDay
|
|
3745
|
+
function weekStartContaining(date, weekStartDay) {
|
|
3753
3746
|
const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3754
3747
|
return date.subtract({ days: daysFromStart });
|
|
3755
3748
|
}
|
|
3756
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains min. */
|
|
3757
|
-
function findFirstValidWeekStart(min, weekStartDay, T) {
|
|
3758
|
-
return weekStartContaining(min, weekStartDay, T);
|
|
3759
|
-
}
|
|
3760
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains max. */
|
|
3761
|
-
function findLastValidWeekStart(max, weekStartDay, T) {
|
|
3762
|
-
return weekStartContaining(max, weekStartDay, T);
|
|
3763
|
-
}
|
|
3764
3749
|
/**
|
|
3765
3750
|
* Trim leading and trailing fully-disabled weeks from a window.
|
|
3766
3751
|
* Returns new { firstWeek, weekCount }.
|
|
@@ -3790,7 +3775,7 @@ function shrinkWindow(firstWeek, weekCount, min, max, T) {
|
|
|
3790
3775
|
* the adjusted { firstWeek, weekCount }.
|
|
3791
3776
|
*/
|
|
3792
3777
|
function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3793
|
-
if (!min
|
|
3778
|
+
if (!min && !max || behavior === "unbounded") return {
|
|
3794
3779
|
firstWeek: targetFirstWeek,
|
|
3795
3780
|
weekCount
|
|
3796
3781
|
};
|
|
@@ -3799,54 +3784,19 @@ function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekS
|
|
|
3799
3784
|
weekCount
|
|
3800
3785
|
};
|
|
3801
3786
|
if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
|
|
3810
|
-
else resolvedFirst = firstValid;
|
|
3811
|
-
} else resolvedFirst = snappedFirst;
|
|
3812
|
-
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3813
|
-
return {
|
|
3814
|
-
firstWeek: resolvedFirst,
|
|
3815
|
-
weekCount
|
|
3816
|
-
};
|
|
3817
|
-
}
|
|
3787
|
+
const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
|
|
3788
|
+
const lastValid = max && weekStartContaining(max, weekStartDay);
|
|
3789
|
+
const firstValid = min && weekStartContaining(min, weekStartDay);
|
|
3790
|
+
let resolvedFirst = targetFirstWeek;
|
|
3791
|
+
if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
|
|
3792
|
+
else if (firstValid && T.PlainDate.compare(targetFirstWeek, firstValid) < 0) resolvedFirst = firstValid;
|
|
3793
|
+
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3818
3794
|
return {
|
|
3819
|
-
firstWeek:
|
|
3795
|
+
firstWeek: resolvedFirst,
|
|
3820
3796
|
weekCount
|
|
3821
3797
|
};
|
|
3822
3798
|
}
|
|
3823
|
-
|
|
3824
|
-
* Returns whether the navigation button for the given direction should be enabled.
|
|
3825
|
-
*/
|
|
3826
|
-
function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
|
|
3827
|
-
if (behavior === "unbounded" || !min || !max) return true;
|
|
3828
|
-
const shift = shiftBy ?? weekCount;
|
|
3829
|
-
const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
|
|
3830
|
-
if (behavior === "stop" || behavior === "stop-shrink") {
|
|
3831
|
-
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
|
|
3832
|
-
return false;
|
|
3833
|
-
}
|
|
3834
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
3835
|
-
const applied = applyOutOfRange({
|
|
3836
|
-
targetFirstWeek,
|
|
3837
|
-
weekCount,
|
|
3838
|
-
behavior,
|
|
3839
|
-
min,
|
|
3840
|
-
max,
|
|
3841
|
-
weekStartDay,
|
|
3842
|
-
T
|
|
3843
|
-
});
|
|
3844
|
-
return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
|
|
3845
|
-
}
|
|
3846
|
-
return true;
|
|
3847
|
-
}
|
|
3848
|
-
//#endregion
|
|
3849
|
-
//#region src/weeks-window.ts
|
|
3799
|
+
// src/weeks-window.ts
|
|
3850
3800
|
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3851
3801
|
const bounds = {
|
|
3852
3802
|
weekCount,
|
|
@@ -3856,21 +3806,30 @@ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T
|
|
|
3856
3806
|
weekStartDay,
|
|
3857
3807
|
T
|
|
3858
3808
|
};
|
|
3809
|
+
const isStop = behavior === "stop" || behavior === "stop-shrink";
|
|
3810
|
+
const isBounded = min !== void 0 || max !== void 0;
|
|
3811
|
+
const resolve = (requestedFirstWeek) => applyOutOfRange({
|
|
3812
|
+
...bounds,
|
|
3813
|
+
targetFirstWeek: requestedFirstWeek
|
|
3814
|
+
});
|
|
3815
|
+
const moveTo = (requestedFirstWeek) => {
|
|
3816
|
+
if (isStop && isBounded && !windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)) return null;
|
|
3817
|
+
return resolve(requestedFirstWeek);
|
|
3818
|
+
};
|
|
3859
3819
|
return {
|
|
3860
|
-
resolve
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
}
|
|
3820
|
+
resolve,
|
|
3821
|
+
moveTo,
|
|
3822
|
+
shift: (current, direction, shiftBy) => {
|
|
3823
|
+
const by = shiftBy ?? current.weekCount;
|
|
3824
|
+
const target = current.firstWeek.add({ weeks: direction * by });
|
|
3825
|
+
const next = moveTo(target);
|
|
3826
|
+
if (next === null) return null;
|
|
3827
|
+
if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
|
|
3828
|
+
return next;
|
|
3829
|
+
}
|
|
3870
3830
|
};
|
|
3871
3831
|
}
|
|
3872
|
-
|
|
3873
|
-
//#region src/weeks-view-state.ts
|
|
3832
|
+
// src/weeks-view-state.ts
|
|
3874
3833
|
/**
|
|
3875
3834
|
* Core state management hook for WeeksView.Root.
|
|
3876
3835
|
* Reads calendar-level context and manages weeks-specific state.
|
|
@@ -4090,29 +4049,32 @@ function useWeeksViewRootState(props) {
|
|
|
4090
4049
|
if (!isControlled) setInternalFirstWeek(newFirstWeek);
|
|
4091
4050
|
onFirstWeekChange?.(newFirstWeek);
|
|
4092
4051
|
}, [isControlled, onFirstWeekChange]);
|
|
4052
|
+
const shownWindow = useMemo(() => ({
|
|
4053
|
+
firstWeek: windowInfo.windowStart,
|
|
4054
|
+
weekCount: windowInfo.weekCount
|
|
4055
|
+
}), [windowInfo.windowStart, windowInfo.weekCount]);
|
|
4093
4056
|
const goNext = useCallback((shiftBy) => {
|
|
4094
|
-
const
|
|
4095
|
-
updateFirstWeek(
|
|
4057
|
+
const next = windowPolicy.shift(shownWindow, 1, shiftBy);
|
|
4058
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4096
4059
|
}, [
|
|
4097
|
-
|
|
4098
|
-
weekCount,
|
|
4060
|
+
shownWindow,
|
|
4099
4061
|
windowPolicy,
|
|
4100
4062
|
updateFirstWeek
|
|
4101
4063
|
]);
|
|
4102
4064
|
const goPrev = useCallback((shiftBy) => {
|
|
4103
|
-
const
|
|
4104
|
-
updateFirstWeek(
|
|
4065
|
+
const next = windowPolicy.shift(shownWindow, -1, shiftBy);
|
|
4066
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4105
4067
|
}, [
|
|
4106
|
-
|
|
4107
|
-
weekCount,
|
|
4068
|
+
shownWindow,
|
|
4108
4069
|
windowPolicy,
|
|
4109
4070
|
updateFirstWeek
|
|
4110
4071
|
]);
|
|
4111
4072
|
const scrollToWeek = useCallback((target, options) => {
|
|
4112
|
-
const
|
|
4113
|
-
|
|
4073
|
+
const requested = resolveFirstWeek(shownWindow.firstWeek, weekCount, resolveSpec(target), options);
|
|
4074
|
+
const next = windowPolicy.moveTo(requested);
|
|
4075
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4114
4076
|
}, [
|
|
4115
|
-
|
|
4077
|
+
shownWindow,
|
|
4116
4078
|
weekCount,
|
|
4117
4079
|
resolveSpec,
|
|
4118
4080
|
windowPolicy,
|
|
@@ -4201,8 +4163,7 @@ function useWeeksViewRootState(props) {
|
|
|
4201
4163
|
scrollToWeek
|
|
4202
4164
|
};
|
|
4203
4165
|
}
|
|
4204
|
-
|
|
4205
|
-
//#region src/weeks-view.tsx
|
|
4166
|
+
// src/weeks-view.tsx
|
|
4206
4167
|
function WeeksViewRootFn(props, ref) {
|
|
4207
4168
|
const { children } = props;
|
|
4208
4169
|
const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
@@ -4244,8 +4205,7 @@ function WeeksViewFn(props, ref) {
|
|
|
4244
4205
|
}
|
|
4245
4206
|
const WeeksView = forwardRef(WeeksViewFn);
|
|
4246
4207
|
WeeksView.Root = WeeksViewRoot;
|
|
4247
|
-
|
|
4248
|
-
//#region src/weeks-navigation.tsx
|
|
4208
|
+
// src/weeks-navigation.tsx
|
|
4249
4209
|
const weeksNavButtonStateAttributesMapping = {
|
|
4250
4210
|
root: () => null,
|
|
4251
4211
|
direction: (v) => ({ "data-direction": v }),
|
|
@@ -4260,14 +4220,18 @@ function useWeeksNavButton(direction, shiftByProp) {
|
|
|
4260
4220
|
const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
|
|
4261
4221
|
const { windowInfo } = useWeeksViewState();
|
|
4262
4222
|
const { rootState } = useViewState();
|
|
4263
|
-
const
|
|
4223
|
+
const { windowStart, weekCount } = windowInfo;
|
|
4264
4224
|
const isDisabled = useMemo(() => {
|
|
4265
4225
|
if (globalDisabled) return true;
|
|
4266
|
-
return
|
|
4226
|
+
return windowPolicy.shift({
|
|
4227
|
+
firstWeek: windowStart,
|
|
4228
|
+
weekCount
|
|
4229
|
+
}, direction === "next" ? 1 : -1, shiftByProp) === null;
|
|
4267
4230
|
}, [
|
|
4268
4231
|
globalDisabled,
|
|
4269
4232
|
windowPolicy,
|
|
4270
|
-
|
|
4233
|
+
windowStart,
|
|
4234
|
+
weekCount,
|
|
4271
4235
|
direction,
|
|
4272
4236
|
shiftByProp
|
|
4273
4237
|
]);
|
|
@@ -4350,5 +4314,4 @@ function WeekCountFn(props, ref) {
|
|
|
4350
4314
|
* out-of-range modes where the actual count may be less than the `weekCount` prop.
|
|
4351
4315
|
*/
|
|
4352
4316
|
const WeekCount = forwardRef(WeekCountFn);
|
|
4353
|
-
//#endregion
|
|
4354
4317
|
export { MonthSeparatorRow as A, useViewContext as B, DayButton as C, MonthSeparator as D, useWeeksViewState as E, DayCellDataContext as F, useCalendarStable as G, useMonthViewState as H, GridContext as I, useCalendarState as K, WeekDataContext as L, MonthSeparatorYear as M, GridHeader as N, MonthSeparatorCell as O, GridHeaderCell as P, MonthView as R, WeekTemplate as S, useWeeksViewStable as T, CalendarProvider as U, useMonthViewStable as V, computePreviewRange as W, NextMonthButton as _, WeeksViewRoot as a, Grid as b, computeWeeksInWindow as c, RangeEndDragHandle as d, RangeStartDragHandle as f, MonthYearString as g, DateString as h, WeeksView as i, MonthSeparatorWeekCount as j, MonthSeparatorMonth as k, WeekNumberCell as l, RangeSelected as m, PrevWeeksButton as n, resolveFirstWeek as o, RangePreview as p, WeekCount as r, resolveFirstWeekSpec as s, NextWeeksButton as t, WeekNumberHeader as u, PrevMonthButton as v, DayCellTemplate as w, GridBody as x, TimeString as y, MonthViewRoot as z };
|