@klinking/colander 3.1.0-alpha.7 → 3.1.0-alpha.9
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/{weeks-view-context-BTojXkys.d.cts → index-B5VJ_WF2.d.mts} +91 -114
- package/dist/{weeks-view-context-CFXV8orh.d.mts → index-BMsxaq1s.d.cts} +91 -114
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -10
- package/dist/index.d.mts +1 -10
- package/dist/index.mjs +1 -2
- package/dist/{weeks-navigation-CPevz3Xg.cjs → weeks-navigation-CUQApLMk.cjs} +531 -400
- package/dist/{weeks-navigation-BSKwFvdP.mjs → weeks-navigation-CWNpF_6M.mjs} +531 -399
- package/package.json +21 -18
- package/src/calendar-provider.test.tsx +1 -1
- package/src/calendar-provider.tsx +8 -2
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +1 -1
- package/src/day-cell-state.ts +0 -70
- package/src/day-cell-store.test.tsx +273 -0
- package/src/day-cell-store.tsx +204 -0
- package/src/day-cell.test.tsx +73 -90
- package/src/day-cell.tsx +93 -78
- 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 +17 -15
- 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 +17 -7
- package/src/month-window.test.ts +1 -1
- package/src/out-of-range.test.ts +1 -1
- package/src/range-preview.test.ts +1 -1
- package/src/resolve-first-week.test.ts +1 -1
- package/src/store.ts +72 -0
- 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/view-context.ts +2 -0
- package/src/weeks-grid.tsx +20 -10
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-view-state.ts +1 -1
- package/src/weeks-view.bounds.test.tsx +1 -1
- package/src/weeks-view.test.tsx +1 -1
- package/src/weeks-view.tsx +2 -1
- package/src/weeks-window.test.ts +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Children, createContext, forwardRef, isValidElement, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
1
|
+
import { Children, createContext, forwardRef, isValidElement, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
2
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
4
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
4
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
5
|
-
|
|
6
|
+
// src/calendar-context.ts
|
|
6
7
|
/** @internal React context carrying stable CalendarProvider values (callbacks, config). */
|
|
7
8
|
const CalendarStableContext = createContext(null);
|
|
8
9
|
/** @internal React context carrying volatile CalendarProvider state. */
|
|
@@ -19,8 +20,7 @@ function useCalendarState() {
|
|
|
19
20
|
if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
|
|
20
21
|
return ctx;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
//#region src/utils.ts
|
|
23
|
+
// src/utils.ts
|
|
24
24
|
/**
|
|
25
25
|
* Resolves a {@link TemporalNamespace} instance.
|
|
26
26
|
*
|
|
@@ -466,8 +466,7 @@ function getISOWeekNumber(date, T) {
|
|
|
466
466
|
const daysDiff = thursday.since(jan4Thursday, { largestUnit: "days" }).days;
|
|
467
467
|
return Math.round(daysDiff / 7) + 1;
|
|
468
468
|
}
|
|
469
|
-
|
|
470
|
-
//#region src/root-selection.ts
|
|
469
|
+
// src/root-selection.ts
|
|
471
470
|
/** Construct a DateRange (workaround for TS generic conditional type widening). */
|
|
472
471
|
function mkRange(start, end) {
|
|
473
472
|
return {
|
|
@@ -832,8 +831,46 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
|
|
|
832
831
|
});
|
|
833
832
|
return preview ? mkRange(preview[0], preview[1]) : null;
|
|
834
833
|
}
|
|
835
|
-
|
|
836
|
-
|
|
834
|
+
// src/store.ts
|
|
835
|
+
function createStore(initial) {
|
|
836
|
+
let state = initial;
|
|
837
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
838
|
+
return {
|
|
839
|
+
get: () => state,
|
|
840
|
+
set: (next) => {
|
|
841
|
+
if (Object.is(state, next)) return;
|
|
842
|
+
state = next;
|
|
843
|
+
for (const listener of listeners) listener();
|
|
844
|
+
},
|
|
845
|
+
subscribe: (listener) => {
|
|
846
|
+
listeners.add(listener);
|
|
847
|
+
return () => listeners.delete(listener);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
/** `useLayoutEffect` in the browser, `useEffect` on the server (no warning). */
|
|
852
|
+
const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
853
|
+
/**
|
|
854
|
+
* Subscribes to the slice of `store` that `select` picks. The component
|
|
855
|
+
* re-renders only when `isEqual` says the slice changed; otherwise the
|
|
856
|
+
* previously returned slice is handed back, keeping its identity.
|
|
857
|
+
*/
|
|
858
|
+
function useStoreSelector(store, select, isEqual) {
|
|
859
|
+
return useSyncExternalStoreWithSelector(store.subscribe, store.get, store.get, select, isEqual);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Returns a function with a stable identity that always calls the latest
|
|
863
|
+
* `fn`, so contexts holding it don't change when its closure does. Call it
|
|
864
|
+
* from event handlers and effects, not during render.
|
|
865
|
+
*/
|
|
866
|
+
function useStableCallback(fn) {
|
|
867
|
+
const latest = useRef(fn);
|
|
868
|
+
useInsertionEffect(() => {
|
|
869
|
+
latest.current = fn;
|
|
870
|
+
});
|
|
871
|
+
return useCallback((...args) => latest.current(...args), []);
|
|
872
|
+
}
|
|
873
|
+
// src/calendar-provider.tsx
|
|
837
874
|
/**
|
|
838
875
|
* Provides shared calendar state (selection, config, range preview) to all
|
|
839
876
|
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
@@ -951,7 +988,7 @@ function CalendarProvider(props) {
|
|
|
951
988
|
isRange,
|
|
952
989
|
isMultiple
|
|
953
990
|
]);
|
|
954
|
-
const
|
|
991
|
+
const defaultDates = useMemo(() => {
|
|
955
992
|
if (isMultiple) {
|
|
956
993
|
if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
|
|
957
994
|
return [];
|
|
@@ -966,7 +1003,8 @@ function CalendarProvider(props) {
|
|
|
966
1003
|
singleDefault,
|
|
967
1004
|
rawToPlain,
|
|
968
1005
|
sortDates
|
|
969
|
-
])
|
|
1006
|
+
]);
|
|
1007
|
+
const [internalDates, setInternalDates] = useState(defaultDates);
|
|
970
1008
|
const isControlled = controlledDates !== void 0;
|
|
971
1009
|
const committedDates = isControlled ? controlledDates : internalDates;
|
|
972
1010
|
const rangeStart = !isMultiple && committedDates.length > 0 ? committedDates[0] ?? void 0 : void 0;
|
|
@@ -1125,7 +1163,7 @@ function CalendarProvider(props) {
|
|
|
1125
1163
|
isMultiple,
|
|
1126
1164
|
isControlled
|
|
1127
1165
|
]);
|
|
1128
|
-
const
|
|
1166
|
+
const onSelectLatest = useCallback((date) => {
|
|
1129
1167
|
const result = computeSelectionUpdate({
|
|
1130
1168
|
date,
|
|
1131
1169
|
readOnly,
|
|
@@ -1169,7 +1207,7 @@ function CalendarProvider(props) {
|
|
|
1169
1207
|
currentRangeFormatted,
|
|
1170
1208
|
currentMultipleFormatted
|
|
1171
1209
|
]);
|
|
1172
|
-
const
|
|
1210
|
+
const setRangeLatest = useCallback((start, end) => {
|
|
1173
1211
|
const result = computeSetRangeUpdate({
|
|
1174
1212
|
start,
|
|
1175
1213
|
end,
|
|
@@ -1195,6 +1233,8 @@ function CalendarProvider(props) {
|
|
|
1195
1233
|
resolvedFormat,
|
|
1196
1234
|
T
|
|
1197
1235
|
]);
|
|
1236
|
+
const onSelect = useStableCallback(onSelectLatest);
|
|
1237
|
+
const setRange = useStableCallback(setRangeLatest);
|
|
1198
1238
|
const nonNullDates = useMemo(() => committedDates.filter((d) => d != null), [committedDates]);
|
|
1199
1239
|
const stableCtx = useMemo(() => ({
|
|
1200
1240
|
onSelect,
|
|
@@ -1277,8 +1317,293 @@ function CalendarProvider(props) {
|
|
|
1277
1317
|
})
|
|
1278
1318
|
});
|
|
1279
1319
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1320
|
+
// src/context.ts
|
|
1321
|
+
/** @internal Provides the days and index of the current week row to child components. */
|
|
1322
|
+
const WeekDataContext = createContext(null);
|
|
1323
|
+
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
1324
|
+
const GridContext = createContext({ orientation: "horizontal" });
|
|
1325
|
+
/** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
|
|
1326
|
+
const DayCellDataContext = createContext(null);
|
|
1327
|
+
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1328
|
+
const GridMonthContext = createContext(null);
|
|
1329
|
+
// src/day-cell-state.ts
|
|
1330
|
+
const NO_RANGE = {
|
|
1331
|
+
rangeStart: false,
|
|
1332
|
+
rangeEnd: false,
|
|
1333
|
+
rangeBoundary: false,
|
|
1334
|
+
inRange: false,
|
|
1335
|
+
rangeIndex: false,
|
|
1336
|
+
rangeLength: false,
|
|
1337
|
+
rangeHasStart: false,
|
|
1338
|
+
rangeHasEnd: false,
|
|
1339
|
+
rangePreviewStart: false,
|
|
1340
|
+
rangePreviewEnd: false,
|
|
1341
|
+
rangePreviewBoundary: false,
|
|
1342
|
+
rangePreviewInRange: false,
|
|
1343
|
+
rangePreviewIndex: false,
|
|
1344
|
+
rangePreviewLength: false,
|
|
1345
|
+
rangePreviewHasStart: false,
|
|
1346
|
+
rangePreviewHasEnd: false
|
|
1347
|
+
};
|
|
1348
|
+
function computeRangeState(date, inputs) {
|
|
1349
|
+
const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
|
|
1350
|
+
if (selectionMode !== "range") return NO_RANGE;
|
|
1351
|
+
const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
1352
|
+
const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
1353
|
+
const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
1354
|
+
const effectiveStart = rangeStart ?? rangeEnd;
|
|
1355
|
+
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
1356
|
+
const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
1357
|
+
const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
1358
|
+
const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
1359
|
+
return {
|
|
1360
|
+
rangeStart: isRangeStart,
|
|
1361
|
+
rangeEnd: isRangeEnd,
|
|
1362
|
+
rangeBoundary: isRangeStart || isRangeEnd,
|
|
1363
|
+
inRange,
|
|
1364
|
+
rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
|
|
1365
|
+
rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
|
|
1366
|
+
rangeHasStart: inRange && rangeStart !== void 0,
|
|
1367
|
+
rangeHasEnd: inRange && rangeEnd !== void 0,
|
|
1368
|
+
rangePreviewStart: isPreviewStart,
|
|
1369
|
+
rangePreviewEnd: isPreviewEnd,
|
|
1370
|
+
rangePreviewBoundary: isPreviewStart || isPreviewEnd,
|
|
1371
|
+
rangePreviewInRange: inPreview,
|
|
1372
|
+
rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
|
|
1373
|
+
rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
|
|
1374
|
+
rangePreviewHasStart: inPreview && previewStart !== void 0,
|
|
1375
|
+
rangePreviewHasEnd: inPreview && previewEnd !== void 0
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
/** Derives the state of one day cell. Pure function, no hooks. */
|
|
1379
|
+
function computeDayCellState(date, position, inputs) {
|
|
1380
|
+
const { T, outsideDays } = inputs;
|
|
1381
|
+
const { columnIndex, month } = position;
|
|
1382
|
+
const isCurrentMonth = date.year === month.year && date.month === month.month;
|
|
1383
|
+
const base = {
|
|
1384
|
+
root: inputs.rootState,
|
|
1385
|
+
date,
|
|
1386
|
+
columnIndex,
|
|
1387
|
+
orientation: inputs.orientation
|
|
1388
|
+
};
|
|
1389
|
+
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
1390
|
+
...base,
|
|
1391
|
+
...NO_RANGE,
|
|
1392
|
+
outsideMonth: true,
|
|
1393
|
+
hidden: true,
|
|
1394
|
+
selected: false,
|
|
1395
|
+
today: false,
|
|
1396
|
+
disabled: true,
|
|
1397
|
+
focused: false,
|
|
1398
|
+
isTabTarget: false
|
|
1399
|
+
};
|
|
1400
|
+
const isToday = T.PlainDate.compare(date, inputs.today) === 0;
|
|
1401
|
+
if (!isCurrentMonth && outsideDays !== "enabled") {
|
|
1402
|
+
const suppressRange = outsideDays === "disabled";
|
|
1403
|
+
return {
|
|
1404
|
+
...base,
|
|
1405
|
+
...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
|
|
1406
|
+
outsideMonth: true,
|
|
1407
|
+
hidden: false,
|
|
1408
|
+
selected: false,
|
|
1409
|
+
today: isToday,
|
|
1410
|
+
disabled: true,
|
|
1411
|
+
focused: false,
|
|
1412
|
+
isTabTarget: false
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
return {
|
|
1416
|
+
...base,
|
|
1417
|
+
...computeRangeState(date, inputs),
|
|
1418
|
+
outsideMonth: !isCurrentMonth,
|
|
1419
|
+
hidden: false,
|
|
1420
|
+
selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
|
|
1421
|
+
today: isToday,
|
|
1422
|
+
disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
|
|
1423
|
+
focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
|
|
1424
|
+
isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
const COMPARED_KEYS = Object.keys({
|
|
1428
|
+
outsideMonth: true,
|
|
1429
|
+
hidden: true,
|
|
1430
|
+
selected: true,
|
|
1431
|
+
today: true,
|
|
1432
|
+
disabled: true,
|
|
1433
|
+
focused: true,
|
|
1434
|
+
rangeStart: true,
|
|
1435
|
+
rangeEnd: true,
|
|
1436
|
+
rangeBoundary: true,
|
|
1437
|
+
inRange: true,
|
|
1438
|
+
rangeIndex: true,
|
|
1439
|
+
rangeLength: true,
|
|
1440
|
+
rangeHasStart: true,
|
|
1441
|
+
rangeHasEnd: true,
|
|
1442
|
+
rangePreviewStart: true,
|
|
1443
|
+
rangePreviewEnd: true,
|
|
1444
|
+
rangePreviewBoundary: true,
|
|
1445
|
+
rangePreviewInRange: true,
|
|
1446
|
+
rangePreviewIndex: true,
|
|
1447
|
+
rangePreviewLength: true,
|
|
1448
|
+
rangePreviewHasStart: true,
|
|
1449
|
+
rangePreviewHasEnd: true,
|
|
1450
|
+
isTabTarget: true
|
|
1451
|
+
});
|
|
1452
|
+
/** Whether two cell states render the same cell. */
|
|
1453
|
+
function dayCellStateEqual(a, b) {
|
|
1454
|
+
for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
// src/view-context.ts
|
|
1458
|
+
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1459
|
+
const ViewContext = createContext(null);
|
|
1460
|
+
/** Returns the nearest view context (MonthView or WeeksView). */
|
|
1461
|
+
function useViewContext() {
|
|
1462
|
+
const ctx = useContext(ViewContext);
|
|
1463
|
+
if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
|
|
1464
|
+
return ctx;
|
|
1465
|
+
}
|
|
1466
|
+
/** @internal Context for {@link ViewStableContextValue}. */
|
|
1467
|
+
const ViewStableContext = createContext(null);
|
|
1468
|
+
/** @internal Context for {@link ViewStateContextValue}. */
|
|
1469
|
+
const ViewStateContext = createContext(null);
|
|
1470
|
+
/** Returns the nearest view's stable values. */
|
|
1471
|
+
function useViewStable() {
|
|
1472
|
+
const ctx = useContext(ViewStableContext);
|
|
1473
|
+
if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
|
|
1474
|
+
return ctx;
|
|
1475
|
+
}
|
|
1476
|
+
/** Returns the nearest view's volatile state. */
|
|
1477
|
+
function useViewState() {
|
|
1478
|
+
const ctx = useContext(ViewStateContext);
|
|
1479
|
+
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1480
|
+
return ctx;
|
|
1481
|
+
}
|
|
1482
|
+
// src/day-cell-store.tsx
|
|
1483
|
+
/** @internal The view's day-cell store. Its identity never changes. */
|
|
1484
|
+
const DayCellStoreContext = createContext(null);
|
|
1485
|
+
/**
|
|
1486
|
+
* Publishes the calendar and view state that day cells derive from. Cells
|
|
1487
|
+
* subscribe per date, so a change re-renders only the cells it affects instead
|
|
1488
|
+
* of every cell under a context.
|
|
1489
|
+
*
|
|
1490
|
+
* The store is seeded on the first render and updated only after a change
|
|
1491
|
+
* commits, never during render: a render React discards (a suspended
|
|
1492
|
+
* transition) must not leak into cells that re-render meanwhile. Cells that
|
|
1493
|
+
* render in the same pass as a change read the previous state first, then
|
|
1494
|
+
* re-render from the layout effect before the browser paints.
|
|
1495
|
+
*/
|
|
1496
|
+
function DayCellStoreProvider(props) {
|
|
1497
|
+
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
1498
|
+
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
1499
|
+
const { viewType, focusedDate, tabTargetDate } = useViewContext();
|
|
1500
|
+
const { rootState, currentDateTime } = useViewState();
|
|
1501
|
+
const { outsideDays } = useViewStable();
|
|
1502
|
+
const todayKey = today().toString();
|
|
1503
|
+
const { year, month } = currentDateTime;
|
|
1504
|
+
const snapshot = useMemo(() => ({
|
|
1505
|
+
inputs: {
|
|
1506
|
+
T,
|
|
1507
|
+
today: T.PlainDate.from(todayKey),
|
|
1508
|
+
rootState,
|
|
1509
|
+
selectionMode,
|
|
1510
|
+
selectedDates,
|
|
1511
|
+
rangeStart,
|
|
1512
|
+
rangeEnd,
|
|
1513
|
+
previewStart,
|
|
1514
|
+
previewEnd,
|
|
1515
|
+
disabled,
|
|
1516
|
+
isDateDisabled,
|
|
1517
|
+
focusedDate,
|
|
1518
|
+
tabTargetDate,
|
|
1519
|
+
outsideDays
|
|
1520
|
+
},
|
|
1521
|
+
viewType,
|
|
1522
|
+
viewMonth: {
|
|
1523
|
+
year,
|
|
1524
|
+
month
|
|
1525
|
+
},
|
|
1526
|
+
weekStartDay
|
|
1527
|
+
}), [
|
|
1528
|
+
T,
|
|
1529
|
+
todayKey,
|
|
1530
|
+
rootState,
|
|
1531
|
+
selectionMode,
|
|
1532
|
+
selectedDates,
|
|
1533
|
+
rangeStart,
|
|
1534
|
+
rangeEnd,
|
|
1535
|
+
previewStart,
|
|
1536
|
+
previewEnd,
|
|
1537
|
+
disabled,
|
|
1538
|
+
isDateDisabled,
|
|
1539
|
+
focusedDate,
|
|
1540
|
+
tabTargetDate,
|
|
1541
|
+
outsideDays,
|
|
1542
|
+
viewType,
|
|
1543
|
+
year,
|
|
1544
|
+
month,
|
|
1545
|
+
weekStartDay
|
|
1546
|
+
]);
|
|
1547
|
+
const [store] = useState(() => createStore(snapshot));
|
|
1548
|
+
useIsoLayoutEffect(() => store.set(snapshot), [store, snapshot]);
|
|
1549
|
+
return /* @__PURE__ */ jsx(DayCellStoreContext.Provider, {
|
|
1550
|
+
value: store,
|
|
1551
|
+
children: props.children
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Hands `state` to render functions with `root` as a non-enumerable getter
|
|
1556
|
+
* that calls `onReadRoot`. Base UI's data-attribute pass only walks
|
|
1557
|
+
* enumerable keys, so `root` counts as read only when user code reads it.
|
|
1558
|
+
*/
|
|
1559
|
+
function withLazyRoot(state, onReadRoot) {
|
|
1560
|
+
const { root, ...rest } = state;
|
|
1561
|
+
return Object.defineProperty(rest, "root", {
|
|
1562
|
+
get() {
|
|
1563
|
+
onReadRoot();
|
|
1564
|
+
return root;
|
|
1565
|
+
},
|
|
1566
|
+
enumerable: false
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Subscribes to one day cell's state. The cell re-renders only when a field
|
|
1571
|
+
* it renders changes; `root` joins that comparison once a render function has
|
|
1572
|
+
* read `state.root`, so cells that never read it ignore focus and selection
|
|
1573
|
+
* changes elsewhere in the grid.
|
|
1574
|
+
*/
|
|
1575
|
+
function useDayCellState(date, columnIndex, gridMonth) {
|
|
1576
|
+
const store = useContext(DayCellStoreContext);
|
|
1577
|
+
if (!store) throw new Error("Day cells must be used inside MonthView or WeeksView.");
|
|
1578
|
+
const { orientation } = useContext(GridContext);
|
|
1579
|
+
const readsRoot = useRef(false);
|
|
1580
|
+
const state = useStoreSelector(store, useCallback((s) => {
|
|
1581
|
+
const daysInWeek = date.daysInWeek;
|
|
1582
|
+
return computeDayCellState(date, {
|
|
1583
|
+
columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - s.weekStartDay + daysInWeek) % daysInWeek,
|
|
1584
|
+
month: s.viewType === "weeks" ? {
|
|
1585
|
+
year: date.year,
|
|
1586
|
+
month: date.month
|
|
1587
|
+
} : gridMonth ?? s.viewMonth
|
|
1588
|
+
}, {
|
|
1589
|
+
...s.inputs,
|
|
1590
|
+
orientation
|
|
1591
|
+
});
|
|
1592
|
+
}, [
|
|
1593
|
+
date,
|
|
1594
|
+
columnIndex,
|
|
1595
|
+
gridMonth,
|
|
1596
|
+
orientation
|
|
1597
|
+
]), useCallback((a, b) => a.date === b.date && a.columnIndex === b.columnIndex && a.orientation === b.orientation && dayCellStateEqual(a, b) && (!readsRoot.current || a.root === b.root), []));
|
|
1598
|
+
return useMemo(() => withLazyRoot(state, () => {
|
|
1599
|
+
readsRoot.current = true;
|
|
1600
|
+
}), [state]);
|
|
1601
|
+
}
|
|
1602
|
+
/** Like {@link useDayCellState}, taking the grid month from the enclosing week. */
|
|
1603
|
+
function useStandaloneDayCellState(date) {
|
|
1604
|
+
return useDayCellState(date, void 0, useContext(WeekDataContext)?.gridMonth);
|
|
1605
|
+
}
|
|
1606
|
+
// src/month-view-context.ts
|
|
1282
1607
|
/** @internal React context for MonthView stable values (config + callbacks). */
|
|
1283
1608
|
const MonthViewStableContext = createContext(null);
|
|
1284
1609
|
/** @internal React context for MonthView volatile state. */
|
|
@@ -1295,8 +1620,7 @@ function useMonthViewState() {
|
|
|
1295
1620
|
if (!ctx) throw new Error("useMonthViewState must be used within MonthView.Root");
|
|
1296
1621
|
return ctx;
|
|
1297
1622
|
}
|
|
1298
|
-
|
|
1299
|
-
//#region src/month-view-navigation.ts
|
|
1623
|
+
// src/month-view-navigation.ts
|
|
1300
1624
|
/**
|
|
1301
1625
|
* Owns which month the view shows, in both controlled and uncontrolled mode:
|
|
1302
1626
|
* the month state, the Prev/Next steps, and syncing the window with focus.
|
|
@@ -1415,8 +1739,7 @@ function useMonthNavigation(input) {
|
|
|
1415
1739
|
goPrevMonth: useCallback(() => go("prev"), [go])
|
|
1416
1740
|
};
|
|
1417
1741
|
}
|
|
1418
|
-
|
|
1419
|
-
//#region src/month-window.ts
|
|
1742
|
+
// src/month-window.ts
|
|
1420
1743
|
const monthIndex = (m) => m.year * 12 + (m.month - 1);
|
|
1421
1744
|
/**
|
|
1422
1745
|
* Builds the policy for a MonthView window of `numberOfMonths` months.
|
|
@@ -1466,34 +1789,7 @@ function monthAt(start, offset) {
|
|
|
1466
1789
|
month: index % 12 + 1
|
|
1467
1790
|
};
|
|
1468
1791
|
}
|
|
1469
|
-
|
|
1470
|
-
//#region src/view-context.ts
|
|
1471
|
-
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1472
|
-
const ViewContext = createContext(null);
|
|
1473
|
-
/** Returns the nearest view context (MonthView or WeeksView). */
|
|
1474
|
-
function useViewContext() {
|
|
1475
|
-
const ctx = useContext(ViewContext);
|
|
1476
|
-
if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
|
|
1477
|
-
return ctx;
|
|
1478
|
-
}
|
|
1479
|
-
/** @internal Context for {@link ViewStableContextValue}. */
|
|
1480
|
-
const ViewStableContext = createContext(null);
|
|
1481
|
-
/** @internal Context for {@link ViewStateContextValue}. */
|
|
1482
|
-
const ViewStateContext = createContext(null);
|
|
1483
|
-
/** Returns the nearest view's stable values. */
|
|
1484
|
-
function useViewStable() {
|
|
1485
|
-
const ctx = useContext(ViewStableContext);
|
|
1486
|
-
if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
|
|
1487
|
-
return ctx;
|
|
1488
|
-
}
|
|
1489
|
-
/** Returns the nearest view's volatile state. */
|
|
1490
|
-
function useViewState() {
|
|
1491
|
-
const ctx = useContext(ViewStateContext);
|
|
1492
|
-
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1493
|
-
return ctx;
|
|
1494
|
-
}
|
|
1495
|
-
//#endregion
|
|
1496
|
-
//#region src/month-view.tsx
|
|
1792
|
+
// src/month-view.tsx
|
|
1497
1793
|
function MonthViewRoot(props) {
|
|
1498
1794
|
const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
|
|
1499
1795
|
const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
|
|
@@ -1504,7 +1800,6 @@ function MonthViewRoot(props) {
|
|
|
1504
1800
|
const calState = useCalendarState();
|
|
1505
1801
|
const T = calStable.temporal;
|
|
1506
1802
|
const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
|
|
1507
|
-
const [focusedDate, setFocusedDate] = useState(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
|
|
1508
1803
|
const [gridHasFocus, setGridHasFocus] = useState(false);
|
|
1509
1804
|
const gridFocusedRef = useRef(false);
|
|
1510
1805
|
const { minValue, maxValue } = calStable;
|
|
@@ -1521,6 +1816,16 @@ function MonthViewRoot(props) {
|
|
|
1521
1816
|
maxValue,
|
|
1522
1817
|
T
|
|
1523
1818
|
]);
|
|
1819
|
+
const [focusedDate, setFocusedDate] = useState(() => {
|
|
1820
|
+
const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
|
|
1821
|
+
const opening = monthProp ?? defaultMonthProp;
|
|
1822
|
+
if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
|
|
1823
|
+
return T.PlainDate.from({
|
|
1824
|
+
year: opening.year,
|
|
1825
|
+
month: opening.month,
|
|
1826
|
+
day: 1
|
|
1827
|
+
});
|
|
1828
|
+
});
|
|
1524
1829
|
const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
|
|
1525
1830
|
month: monthProp,
|
|
1526
1831
|
defaultMonth: defaultMonthProp,
|
|
@@ -1669,7 +1974,8 @@ function MonthViewRoot(props) {
|
|
|
1669
1974
|
]);
|
|
1670
1975
|
const viewStableCtx = useMemo(() => ({
|
|
1671
1976
|
gridFocusedRef,
|
|
1672
|
-
outsideDays
|
|
1977
|
+
outsideDays,
|
|
1978
|
+
setFocusedDate
|
|
1673
1979
|
}), [outsideDays]);
|
|
1674
1980
|
const viewStateCtx = useMemo(() => ({
|
|
1675
1981
|
currentDateTime,
|
|
@@ -1685,7 +1991,7 @@ function MonthViewRoot(props) {
|
|
|
1685
1991
|
value: viewStateCtx,
|
|
1686
1992
|
children: /* @__PURE__ */ jsx(ViewContext.Provider, {
|
|
1687
1993
|
value: viewCtx,
|
|
1688
|
-
children
|
|
1994
|
+
children: /* @__PURE__ */ jsx(DayCellStoreProvider, { children })
|
|
1689
1995
|
})
|
|
1690
1996
|
})
|
|
1691
1997
|
})
|
|
@@ -1709,18 +2015,7 @@ function MonthView(props) {
|
|
|
1709
2015
|
});
|
|
1710
2016
|
}
|
|
1711
2017
|
MonthView.Root = MonthViewRoot;
|
|
1712
|
-
|
|
1713
|
-
//#region src/context.ts
|
|
1714
|
-
/** @internal Provides the days and index of the current week row to child components. */
|
|
1715
|
-
const WeekDataContext = createContext(null);
|
|
1716
|
-
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
1717
|
-
const GridContext = createContext({ orientation: "horizontal" });
|
|
1718
|
-
/** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
|
|
1719
|
-
const DayCellDataContext = createContext(null);
|
|
1720
|
-
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1721
|
-
const GridMonthContext = createContext(null);
|
|
1722
|
-
//#endregion
|
|
1723
|
-
//#region src/grid-header.tsx
|
|
2018
|
+
// src/grid-header.tsx
|
|
1724
2019
|
function useGridHeaderCellState(index) {
|
|
1725
2020
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
1726
2021
|
const { rootState } = useViewState();
|
|
@@ -1812,8 +2107,7 @@ function GridHeaderFn(props, ref) {
|
|
|
1812
2107
|
}
|
|
1813
2108
|
/** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
|
|
1814
2109
|
const GridHeader = forwardRef(GridHeaderFn);
|
|
1815
|
-
|
|
1816
|
-
//#region src/keyboard.ts
|
|
2110
|
+
// src/keyboard.ts
|
|
1817
2111
|
/**
|
|
1818
2112
|
* Computes the target date when jumping by `months` from `focusedDate`.
|
|
1819
2113
|
*
|
|
@@ -1886,8 +2180,7 @@ function computeNextFocusDate(input) {
|
|
|
1886
2180
|
if (nextDate) return clampToBounds(nextDate, focusedDate, minValue, maxValue, T);
|
|
1887
2181
|
return { action: "none" };
|
|
1888
2182
|
}
|
|
1889
|
-
|
|
1890
|
-
//#region src/month-separator.tsx
|
|
2183
|
+
// src/month-separator.tsx
|
|
1891
2184
|
/** Context providing MonthSeparator data to child components. */
|
|
1892
2185
|
const MonthSeparatorDataContext = createContext(null);
|
|
1893
2186
|
function useMonthSeparatorData() {
|
|
@@ -2017,8 +2310,7 @@ function MonthSeparatorFn(props, ref) {
|
|
|
2017
2310
|
* Default children: `<Month /> <Year />`.
|
|
2018
2311
|
*/
|
|
2019
2312
|
const MonthSeparator = forwardRef(MonthSeparatorFn);
|
|
2020
|
-
|
|
2021
|
-
//#region src/weeks-view-context.ts
|
|
2313
|
+
// src/weeks-view-context.ts
|
|
2022
2314
|
/** @internal React context for WeeksView stable values (config + callbacks). */
|
|
2023
2315
|
const WeeksViewStableContext = createContext(null);
|
|
2024
2316
|
/** @internal React context for WeeksView volatile state. */
|
|
@@ -2035,8 +2327,7 @@ function useWeeksViewState() {
|
|
|
2035
2327
|
if (!ctx) throw new Error("useWeeksViewState must be used within WeeksView.Root");
|
|
2036
2328
|
return ctx;
|
|
2037
2329
|
}
|
|
2038
|
-
|
|
2039
|
-
//#region src/weeks-grid.tsx
|
|
2330
|
+
// src/weeks-grid.tsx
|
|
2040
2331
|
/**
|
|
2041
2332
|
* @internal WeeksGrid — renders continuous week rows for WeeksView.
|
|
2042
2333
|
* Not exported from the public API.
|
|
@@ -2170,28 +2461,35 @@ function WeeksGrid(props) {
|
|
|
2170
2461
|
}
|
|
2171
2462
|
return map;
|
|
2172
2463
|
}, [monthBoundaries]);
|
|
2464
|
+
const rowValues = useMemo(() => weeks.map((week, i) => {
|
|
2465
|
+
const days = weekDaysArrays[i] ?? [];
|
|
2466
|
+
return {
|
|
2467
|
+
weekData: {
|
|
2468
|
+
days,
|
|
2469
|
+
weekIndex: week.weekIndex,
|
|
2470
|
+
gridRowIndex: i + 2
|
|
2471
|
+
},
|
|
2472
|
+
gridMonth: {
|
|
2473
|
+
weeks: [days],
|
|
2474
|
+
year: week.year,
|
|
2475
|
+
month: week.month
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
}), [weeks, weekDaysArrays]);
|
|
2173
2479
|
const rows = [];
|
|
2174
2480
|
for (const [i, week] of weeks.entries()) {
|
|
2175
|
-
|
|
2176
|
-
if (days === void 0) continue;
|
|
2481
|
+
if (weekDaysArrays[i] === void 0) continue;
|
|
2177
2482
|
const separators = boundariesAtIndex.get(i);
|
|
2178
2483
|
if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ jsx(MonthSeparatorDataContext.Provider, {
|
|
2179
2484
|
value: separatorData,
|
|
2180
2485
|
children: separatorTemplate
|
|
2181
2486
|
}, `sep-${separatorData.year}-${separatorData.month}`));
|
|
2182
|
-
const
|
|
2487
|
+
const rowValue = rowValues[i];
|
|
2488
|
+
if (rowValue === void 0) continue;
|
|
2183
2489
|
rows.push(/* @__PURE__ */ jsx(WeekDataContext.Provider, {
|
|
2184
|
-
value:
|
|
2185
|
-
days,
|
|
2186
|
-
weekIndex: week.weekIndex,
|
|
2187
|
-
gridRowIndex: weekGridRow
|
|
2188
|
-
},
|
|
2490
|
+
value: rowValue.weekData,
|
|
2189
2491
|
children: /* @__PURE__ */ jsx(GridMonthContext.Provider, {
|
|
2190
|
-
value:
|
|
2191
|
-
weeks: [days],
|
|
2192
|
-
year: week.year,
|
|
2193
|
-
month: week.month
|
|
2194
|
-
},
|
|
2492
|
+
value: rowValue.gridMonth,
|
|
2195
2493
|
children: weekRowChildren
|
|
2196
2494
|
})
|
|
2197
2495
|
}, week.startDate.toString()));
|
|
@@ -2202,8 +2500,7 @@ function WeeksGrid(props) {
|
|
|
2202
2500
|
children: rows
|
|
2203
2501
|
});
|
|
2204
2502
|
}
|
|
2205
|
-
|
|
2206
|
-
//#region src/weeks-keyboard.ts
|
|
2503
|
+
// src/weeks-keyboard.ts
|
|
2207
2504
|
const NONE = {
|
|
2208
2505
|
action: "none",
|
|
2209
2506
|
windowShift: 0,
|
|
@@ -2277,181 +2574,7 @@ function computeWeeksKeyNav(input) {
|
|
|
2277
2574
|
default: return NONE;
|
|
2278
2575
|
}
|
|
2279
2576
|
}
|
|
2280
|
-
|
|
2281
|
-
//#region src/day-cell-state.ts
|
|
2282
|
-
const NO_RANGE = {
|
|
2283
|
-
rangeStart: false,
|
|
2284
|
-
rangeEnd: false,
|
|
2285
|
-
rangeBoundary: false,
|
|
2286
|
-
inRange: false,
|
|
2287
|
-
rangeIndex: false,
|
|
2288
|
-
rangeLength: false,
|
|
2289
|
-
rangeHasStart: false,
|
|
2290
|
-
rangeHasEnd: false,
|
|
2291
|
-
rangePreviewStart: false,
|
|
2292
|
-
rangePreviewEnd: false,
|
|
2293
|
-
rangePreviewBoundary: false,
|
|
2294
|
-
rangePreviewInRange: false,
|
|
2295
|
-
rangePreviewIndex: false,
|
|
2296
|
-
rangePreviewLength: false,
|
|
2297
|
-
rangePreviewHasStart: false,
|
|
2298
|
-
rangePreviewHasEnd: false
|
|
2299
|
-
};
|
|
2300
|
-
function computeRangeState(date, inputs) {
|
|
2301
|
-
const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
|
|
2302
|
-
if (selectionMode !== "range") return NO_RANGE;
|
|
2303
|
-
const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
2304
|
-
const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
2305
|
-
const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
2306
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
2307
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
2308
|
-
const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
2309
|
-
const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
2310
|
-
const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
2311
|
-
return {
|
|
2312
|
-
rangeStart: isRangeStart,
|
|
2313
|
-
rangeEnd: isRangeEnd,
|
|
2314
|
-
rangeBoundary: isRangeStart || isRangeEnd,
|
|
2315
|
-
inRange,
|
|
2316
|
-
rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
|
|
2317
|
-
rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
|
|
2318
|
-
rangeHasStart: inRange && rangeStart !== void 0,
|
|
2319
|
-
rangeHasEnd: inRange && rangeEnd !== void 0,
|
|
2320
|
-
rangePreviewStart: isPreviewStart,
|
|
2321
|
-
rangePreviewEnd: isPreviewEnd,
|
|
2322
|
-
rangePreviewBoundary: isPreviewStart || isPreviewEnd,
|
|
2323
|
-
rangePreviewInRange: inPreview,
|
|
2324
|
-
rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
|
|
2325
|
-
rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
|
|
2326
|
-
rangePreviewHasStart: inPreview && previewStart !== void 0,
|
|
2327
|
-
rangePreviewHasEnd: inPreview && previewEnd !== void 0
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
/** Derives the state of one day cell. Pure function, no hooks. */
|
|
2331
|
-
function computeDayCellState(date, position, inputs) {
|
|
2332
|
-
const { T, outsideDays } = inputs;
|
|
2333
|
-
const { columnIndex, month } = position;
|
|
2334
|
-
const isCurrentMonth = date.year === month.year && date.month === month.month;
|
|
2335
|
-
const base = {
|
|
2336
|
-
root: inputs.rootState,
|
|
2337
|
-
date,
|
|
2338
|
-
columnIndex,
|
|
2339
|
-
orientation: inputs.orientation
|
|
2340
|
-
};
|
|
2341
|
-
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
2342
|
-
...base,
|
|
2343
|
-
...NO_RANGE,
|
|
2344
|
-
outsideMonth: true,
|
|
2345
|
-
hidden: true,
|
|
2346
|
-
selected: false,
|
|
2347
|
-
today: false,
|
|
2348
|
-
disabled: true,
|
|
2349
|
-
focused: false,
|
|
2350
|
-
isTabTarget: false
|
|
2351
|
-
};
|
|
2352
|
-
const isToday = T.PlainDate.compare(date, inputs.today) === 0;
|
|
2353
|
-
if (!isCurrentMonth && outsideDays !== "enabled") {
|
|
2354
|
-
const suppressRange = outsideDays === "disabled";
|
|
2355
|
-
return {
|
|
2356
|
-
...base,
|
|
2357
|
-
...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
|
|
2358
|
-
outsideMonth: true,
|
|
2359
|
-
hidden: false,
|
|
2360
|
-
selected: false,
|
|
2361
|
-
today: isToday,
|
|
2362
|
-
disabled: true,
|
|
2363
|
-
focused: false,
|
|
2364
|
-
isTabTarget: false
|
|
2365
|
-
};
|
|
2366
|
-
}
|
|
2367
|
-
return {
|
|
2368
|
-
...base,
|
|
2369
|
-
...computeRangeState(date, inputs),
|
|
2370
|
-
outsideMonth: !isCurrentMonth,
|
|
2371
|
-
hidden: false,
|
|
2372
|
-
selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
|
|
2373
|
-
today: isToday,
|
|
2374
|
-
disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
|
|
2375
|
-
focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
|
|
2376
|
-
isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
|
|
2377
|
-
};
|
|
2378
|
-
}
|
|
2379
|
-
const COMPARED_KEYS = Object.keys({
|
|
2380
|
-
outsideMonth: true,
|
|
2381
|
-
hidden: true,
|
|
2382
|
-
selected: true,
|
|
2383
|
-
today: true,
|
|
2384
|
-
disabled: true,
|
|
2385
|
-
focused: true,
|
|
2386
|
-
rangeStart: true,
|
|
2387
|
-
rangeEnd: true,
|
|
2388
|
-
rangeBoundary: true,
|
|
2389
|
-
inRange: true,
|
|
2390
|
-
rangeIndex: true,
|
|
2391
|
-
rangeLength: true,
|
|
2392
|
-
rangeHasStart: true,
|
|
2393
|
-
rangeHasEnd: true,
|
|
2394
|
-
rangePreviewStart: true,
|
|
2395
|
-
rangePreviewEnd: true,
|
|
2396
|
-
rangePreviewBoundary: true,
|
|
2397
|
-
rangePreviewInRange: true,
|
|
2398
|
-
rangePreviewIndex: true,
|
|
2399
|
-
rangePreviewLength: true,
|
|
2400
|
-
rangePreviewHasStart: true,
|
|
2401
|
-
rangePreviewHasEnd: true,
|
|
2402
|
-
isTabTarget: true
|
|
2403
|
-
});
|
|
2404
|
-
/** Whether two cell states render the same cell. */
|
|
2405
|
-
function dayCellStateEqual(a, b) {
|
|
2406
|
-
for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
|
|
2407
|
-
return true;
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* Reads the contexts a day cell depends on and returns a function that derives
|
|
2411
|
-
* the state of any cell. `columnIndex` defaults to the date's column in a
|
|
2412
|
-
* week starting on the calendar's `weekStartDay`.
|
|
2413
|
-
*/
|
|
2414
|
-
function useDayCellDeriver() {
|
|
2415
|
-
const { orientation } = useContext(GridContext);
|
|
2416
|
-
const weekData = useContext(WeekDataContext);
|
|
2417
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2418
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2419
|
-
const viewCtx = useViewContext();
|
|
2420
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2421
|
-
const { rootState, currentDateTime } = useViewState();
|
|
2422
|
-
const { outsideDays } = useViewStable();
|
|
2423
|
-
const inputs = {
|
|
2424
|
-
T,
|
|
2425
|
-
today: today(),
|
|
2426
|
-
orientation,
|
|
2427
|
-
rootState,
|
|
2428
|
-
selectionMode,
|
|
2429
|
-
selectedDates,
|
|
2430
|
-
rangeStart,
|
|
2431
|
-
rangeEnd,
|
|
2432
|
-
previewStart,
|
|
2433
|
-
previewEnd,
|
|
2434
|
-
disabled,
|
|
2435
|
-
isDateDisabled,
|
|
2436
|
-
focusedDate,
|
|
2437
|
-
tabTargetDate,
|
|
2438
|
-
outsideDays
|
|
2439
|
-
};
|
|
2440
|
-
const isWeeksView = viewCtx.viewType === "weeks";
|
|
2441
|
-
const gridMonth = weekData?.gridMonth ?? currentDateTime;
|
|
2442
|
-
return (date, columnIndex) => {
|
|
2443
|
-
const daysInWeek = date.daysInWeek;
|
|
2444
|
-
return computeDayCellState(date, {
|
|
2445
|
-
columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek,
|
|
2446
|
-
month: isWeeksView ? {
|
|
2447
|
-
year: date.year,
|
|
2448
|
-
month: date.month
|
|
2449
|
-
} : gridMonth
|
|
2450
|
-
}, inputs);
|
|
2451
|
-
};
|
|
2452
|
-
}
|
|
2453
|
-
//#endregion
|
|
2454
|
-
//#region src/day-cell.tsx
|
|
2577
|
+
// src/day-cell.tsx
|
|
2455
2578
|
const dayStateAttributesMapping = {
|
|
2456
2579
|
root: () => null,
|
|
2457
2580
|
date: (v) => v ? { "data-date": v.toString() } : null,
|
|
@@ -2480,34 +2603,46 @@ const dayStateAttributesMapping = {
|
|
|
2480
2603
|
rangePreviewHasStart: (v) => v ? { "data-range-preview-has-start": "" } : null,
|
|
2481
2604
|
rangePreviewHasEnd: (v) => v ? { "data-range-preview-has-end": "" } : null
|
|
2482
2605
|
};
|
|
2606
|
+
/** @internal The enclosing day cell's state, read by its `DayButton`. */
|
|
2607
|
+
const DayCellStateContext = createContext(null);
|
|
2483
2608
|
function DayCellInstanceFn(props) {
|
|
2484
|
-
const { render, date, columnIndex,
|
|
2485
|
-
const
|
|
2609
|
+
const { render, date, columnIndex, gridMonth, children, ...otherProps } = props;
|
|
2610
|
+
const derived = useDayCellState(date, columnIndex, gridMonth);
|
|
2611
|
+
const state = derived;
|
|
2612
|
+
const defaultProps = state.hidden ? {
|
|
2613
|
+
role: "gridcell",
|
|
2614
|
+
"aria-hidden": true,
|
|
2615
|
+
children: null
|
|
2616
|
+
} : {
|
|
2617
|
+
role: "gridcell",
|
|
2618
|
+
"aria-selected": state.selected || void 0,
|
|
2619
|
+
"aria-disabled": state.disabled || void 0,
|
|
2620
|
+
children: children ?? /* @__PURE__ */ jsx(DayButton, {})
|
|
2621
|
+
};
|
|
2486
2622
|
const cell = useRender({
|
|
2487
2623
|
defaultTagName: "td",
|
|
2488
2624
|
render,
|
|
2489
2625
|
ref: [],
|
|
2490
2626
|
state,
|
|
2491
2627
|
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)
|
|
2628
|
+
props: mergeProps(defaultProps, otherProps)
|
|
2502
2629
|
});
|
|
2503
2630
|
const outsideDisabled = state.hidden || state.outsideMonth && state.disabled;
|
|
2631
|
+
const cellData = useMemo(() => ({
|
|
2632
|
+
date,
|
|
2633
|
+
columnIndex,
|
|
2634
|
+
outsideDisabled
|
|
2635
|
+
}), [
|
|
2636
|
+
date,
|
|
2637
|
+
columnIndex,
|
|
2638
|
+
outsideDisabled
|
|
2639
|
+
]);
|
|
2504
2640
|
return /* @__PURE__ */ jsx(DayCellDataContext.Provider, {
|
|
2505
|
-
value:
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
}
|
|
2510
|
-
children: cell
|
|
2641
|
+
value: cellData,
|
|
2642
|
+
children: /* @__PURE__ */ jsx(DayCellStateContext.Provider, {
|
|
2643
|
+
value: derived,
|
|
2644
|
+
children: cell
|
|
2645
|
+
})
|
|
2511
2646
|
});
|
|
2512
2647
|
}
|
|
2513
2648
|
/**
|
|
@@ -2523,24 +2658,35 @@ function passThroughPropsEqual(prev, next, handledKeys) {
|
|
|
2523
2658
|
for (const key of prevKeys) if (prev[key] !== next[key]) return false;
|
|
2524
2659
|
return true;
|
|
2525
2660
|
}
|
|
2526
|
-
const DAY_CELL_HANDLED_KEYS = new Set([
|
|
2661
|
+
const DAY_CELL_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2527
2662
|
"render",
|
|
2528
2663
|
"date",
|
|
2529
2664
|
"columnIndex",
|
|
2530
|
-
"
|
|
2531
|
-
"
|
|
2665
|
+
"gridMonth",
|
|
2666
|
+
"children"
|
|
2532
2667
|
]);
|
|
2533
|
-
const DAY_BUTTON_HANDLED_KEYS = new Set([
|
|
2668
|
+
const DAY_BUTTON_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2534
2669
|
"render",
|
|
2535
2670
|
"date",
|
|
2536
2671
|
"children",
|
|
2537
|
-
"
|
|
2672
|
+
"_state"
|
|
2538
2673
|
]);
|
|
2674
|
+
/**
|
|
2675
|
+
* Whether a day cell can skip a parent re-render. Its own state comes from
|
|
2676
|
+
* the store, so only props are compared here.
|
|
2677
|
+
*/
|
|
2539
2678
|
function dayCellInstancePropsAreEqual(prev, next) {
|
|
2540
|
-
|
|
2541
|
-
return dayCellStateEqual(prev._derivedState, next._derivedState) && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2679
|
+
return prev.date === next.date && prev.render === next.render && prev.columnIndex === next.columnIndex && prev.gridMonth === next.gridMonth && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2542
2680
|
}
|
|
2543
2681
|
const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
2682
|
+
/** The cells of a whole month, for a `DayCellTemplate` outside any week row. */
|
|
2683
|
+
function MonthDayCells(props) {
|
|
2684
|
+
const days = useContext(MonthViewStateContext)?.weeks.flat() ?? [];
|
|
2685
|
+
return /* @__PURE__ */ jsx(Fragment, { children: days.map((day) => /* @__PURE__ */ jsx(DayCellInstance, {
|
|
2686
|
+
...props,
|
|
2687
|
+
date: day
|
|
2688
|
+
}, day.toString())) });
|
|
2689
|
+
}
|
|
2544
2690
|
/**
|
|
2545
2691
|
* Renders one `<td role="gridcell">` per day. Exposes data-attributes for
|
|
2546
2692
|
* `selected`, `today`, `disabled`, `outside-month`, `focused`,
|
|
@@ -2552,36 +2698,32 @@ const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
|
2552
2698
|
function DayCellTemplate(props) {
|
|
2553
2699
|
const { date: dateProp, ...restProps } = props;
|
|
2554
2700
|
const weekData = useContext(WeekDataContext);
|
|
2555
|
-
const monthState = useContext(MonthViewStateContext);
|
|
2556
|
-
const derive = useDayCellDeriver();
|
|
2557
2701
|
if (dateProp) return /* @__PURE__ */ jsx(DayCellInstance, {
|
|
2558
2702
|
...restProps,
|
|
2559
2703
|
date: dateProp,
|
|
2560
|
-
|
|
2704
|
+
gridMonth: weekData?.gridMonth
|
|
2561
2705
|
});
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
return /* @__PURE__ */ jsx(Fragment, { children: days.map((day, i) => /* @__PURE__ */ jsx(DayCellInstance, {
|
|
2706
|
+
if (!weekData) return /* @__PURE__ */ jsx(MonthDayCells, { ...restProps });
|
|
2707
|
+
return /* @__PURE__ */ jsx(Fragment, { children: weekData.days.map((day, i) => /* @__PURE__ */ jsx(DayCellInstance, {
|
|
2565
2708
|
...restProps,
|
|
2566
2709
|
date: day,
|
|
2567
|
-
columnIndex:
|
|
2568
|
-
|
|
2710
|
+
columnIndex: i,
|
|
2711
|
+
gridMonth: weekData.gridMonth
|
|
2569
2712
|
}, day.toString())) });
|
|
2570
2713
|
}
|
|
2571
2714
|
function DayButtonInnerFn(props, ref) {
|
|
2572
|
-
const { render, date,
|
|
2715
|
+
const { render, date, _state, ...otherProps } = props;
|
|
2573
2716
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
2574
|
-
const { setFocusedDate } =
|
|
2575
|
-
const { gridFocusedRef } = useViewStable();
|
|
2717
|
+
const { gridFocusedRef, setFocusedDate } = useViewStable();
|
|
2576
2718
|
const internalRef = useRef(null);
|
|
2577
|
-
const isHidden =
|
|
2578
|
-
const isFocused =
|
|
2579
|
-
const isTabTarget =
|
|
2580
|
-
const isDisabled =
|
|
2719
|
+
const isHidden = _state.hidden;
|
|
2720
|
+
const isFocused = _state.focused;
|
|
2721
|
+
const isTabTarget = _state.isTabTarget;
|
|
2722
|
+
const isDisabled = _state.disabled;
|
|
2581
2723
|
useEffect(() => {
|
|
2582
2724
|
if (shouldMoveDomFocus(isFocused, gridFocusedRef.current) && internalRef.current) internalRef.current.focus();
|
|
2583
2725
|
}, [isFocused, gridFocusedRef]);
|
|
2584
|
-
const state =
|
|
2726
|
+
const state = _state;
|
|
2585
2727
|
const defaultProps = isHidden ? {} : {
|
|
2586
2728
|
type: "button",
|
|
2587
2729
|
tabIndex: isTabTarget ? 0 : -1,
|
|
@@ -2613,12 +2755,7 @@ function DayButtonInnerFn(props, ref) {
|
|
|
2613
2755
|
});
|
|
2614
2756
|
}
|
|
2615
2757
|
function dayButtonInnerPropsAreEqual(prev, next) {
|
|
2616
|
-
|
|
2617
|
-
if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
|
|
2618
|
-
const a = prev._derivedState;
|
|
2619
|
-
const b = next._derivedState;
|
|
2620
|
-
if (!a || !b) return a === b;
|
|
2621
|
-
return dayCellStateEqual(a, b);
|
|
2758
|
+
return prev.date === next.date && prev.render === next.render && prev._state === next._state && passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS);
|
|
2622
2759
|
}
|
|
2623
2760
|
const DayButtonInner = memo(forwardRef(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
|
|
2624
2761
|
/**
|
|
@@ -2628,39 +2765,37 @@ const DayButtonInner = memo(forwardRef(DayButtonInnerFn), dayButtonInnerPropsAre
|
|
|
2628
2765
|
* Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
|
|
2629
2766
|
*/
|
|
2630
2767
|
function DayButtonFn(props, ref) {
|
|
2631
|
-
const { date: dateProp,
|
|
2768
|
+
const { date: dateProp, ...restProps } = props;
|
|
2769
|
+
const cellState = useContext(DayCellStateContext);
|
|
2632
2770
|
const cellData = useContext(DayCellDataContext);
|
|
2771
|
+
if (cellState && (!dateProp || dateProp.equals(cellState.date))) return /* @__PURE__ */ jsx(DayButtonInner, {
|
|
2772
|
+
...restProps,
|
|
2773
|
+
ref,
|
|
2774
|
+
date: cellState.date,
|
|
2775
|
+
_state: cellState
|
|
2776
|
+
});
|
|
2633
2777
|
const resolvedDate = dateProp ?? cellData?.date;
|
|
2634
|
-
if (resolvedDate) {
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
_derivedState
|
|
2640
|
-
});
|
|
2641
|
-
return /* @__PURE__ */ jsx(DayButtonFallback, {
|
|
2642
|
-
ref,
|
|
2643
|
-
...restProps,
|
|
2644
|
-
date: resolvedDate
|
|
2645
|
-
});
|
|
2646
|
-
}
|
|
2778
|
+
if (resolvedDate) return /* @__PURE__ */ jsx(StandaloneDayButton, {
|
|
2779
|
+
...restProps,
|
|
2780
|
+
ref,
|
|
2781
|
+
date: resolvedDate
|
|
2782
|
+
});
|
|
2647
2783
|
throw new Error("DayButton must be used inside DayCellTemplate or receive an explicit date prop.");
|
|
2648
2784
|
}
|
|
2649
2785
|
const DayButton = forwardRef(DayButtonFn);
|
|
2650
|
-
/**
|
|
2651
|
-
function
|
|
2786
|
+
/** A `DayButton` outside any day cell: subscribes to its own date's state. */
|
|
2787
|
+
function StandaloneDayButtonFn(props, ref) {
|
|
2652
2788
|
const { date, ...restProps } = props;
|
|
2653
|
-
const
|
|
2789
|
+
const state = useStandaloneDayCellState(date);
|
|
2654
2790
|
return /* @__PURE__ */ jsx(DayButtonInner, {
|
|
2655
2791
|
...restProps,
|
|
2656
2792
|
ref,
|
|
2657
2793
|
date,
|
|
2658
|
-
|
|
2794
|
+
_state: state
|
|
2659
2795
|
});
|
|
2660
2796
|
}
|
|
2661
|
-
const
|
|
2662
|
-
|
|
2663
|
-
//#region src/grid.tsx
|
|
2797
|
+
const StandaloneDayButton = forwardRef(StandaloneDayButtonFn);
|
|
2798
|
+
// src/grid.tsx
|
|
2664
2799
|
function useGridKeyboard() {
|
|
2665
2800
|
const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
|
|
2666
2801
|
const { focusedDate, setFocusedDate } = useViewContext();
|
|
@@ -2994,19 +3129,20 @@ function WeekInstance(props) {
|
|
|
2994
3129
|
const { render, ...otherProps } = props;
|
|
2995
3130
|
const weekData = useContext(WeekDataContext);
|
|
2996
3131
|
const { rootState } = useViewState();
|
|
3132
|
+
const state = useMemo(() => ({
|
|
3133
|
+
root: rootState,
|
|
3134
|
+
weekIndex: weekData.weekIndex,
|
|
3135
|
+
gridRowIndex: weekData.gridRowIndex
|
|
3136
|
+
}), [
|
|
3137
|
+
rootState,
|
|
3138
|
+
weekData.weekIndex,
|
|
3139
|
+
weekData.gridRowIndex
|
|
3140
|
+
]);
|
|
2997
3141
|
return useRender({
|
|
2998
3142
|
defaultTagName: "tr",
|
|
2999
3143
|
render,
|
|
3000
3144
|
ref: [],
|
|
3001
|
-
state
|
|
3002
|
-
root: rootState,
|
|
3003
|
-
weekIndex: weekData.weekIndex,
|
|
3004
|
-
gridRowIndex: weekData.gridRowIndex
|
|
3005
|
-
}), [
|
|
3006
|
-
rootState,
|
|
3007
|
-
weekData.weekIndex,
|
|
3008
|
-
weekData.gridRowIndex
|
|
3009
|
-
]),
|
|
3145
|
+
state,
|
|
3010
3146
|
stateAttributesMapping: weekInstanceStateAttributesMapping,
|
|
3011
3147
|
props: mergeProps({}, otherProps)
|
|
3012
3148
|
});
|
|
@@ -3024,23 +3160,27 @@ function WeekTemplate(props) {
|
|
|
3024
3160
|
year: gridMonthCtx.year,
|
|
3025
3161
|
month: gridMonthCtx.month
|
|
3026
3162
|
} : void 0, [gridMonthCtx]);
|
|
3027
|
-
const
|
|
3028
|
-
|
|
3029
|
-
|
|
3163
|
+
const gridRowIndex = outerWeekData?.gridRowIndex;
|
|
3164
|
+
const weekValues = useMemo(() => weeks.map((weekDays, i) => ({
|
|
3165
|
+
days: weekDays,
|
|
3166
|
+
weekIndex: i,
|
|
3167
|
+
...gridMonth !== void 0 && { gridMonth },
|
|
3168
|
+
...gridRowIndex !== void 0 && { gridRowIndex }
|
|
3169
|
+
})), [
|
|
3170
|
+
weeks,
|
|
3171
|
+
gridMonth,
|
|
3172
|
+
gridRowIndex
|
|
3173
|
+
]);
|
|
3174
|
+
return /* @__PURE__ */ jsx(Fragment, { children: weekValues.map((value) => {
|
|
3175
|
+
const firstDay = value.days[0];
|
|
3030
3176
|
if (firstDay === void 0) return null;
|
|
3031
3177
|
return /* @__PURE__ */ jsx(WeekDataContext.Provider, {
|
|
3032
|
-
value
|
|
3033
|
-
|
|
3034
|
-
weekIndex: i,
|
|
3035
|
-
...gridMonth !== void 0 && { gridMonth },
|
|
3036
|
-
...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
|
|
3037
|
-
},
|
|
3038
|
-
children: /* @__PURE__ */ jsx(Instance, { ...props })
|
|
3178
|
+
value,
|
|
3179
|
+
children: /* @__PURE__ */ jsx(WeekInstance, { ...props })
|
|
3039
3180
|
}, firstDay.toString());
|
|
3040
3181
|
}) });
|
|
3041
3182
|
}
|
|
3042
|
-
|
|
3043
|
-
//#region src/navigation.tsx
|
|
3183
|
+
// src/navigation.tsx
|
|
3044
3184
|
const dateStringStateAttributesMapping = {
|
|
3045
3185
|
root: () => null,
|
|
3046
3186
|
month: () => null,
|
|
@@ -3276,8 +3416,7 @@ function NextMonthButtonFn(props, ref) {
|
|
|
3276
3416
|
* when the next month falls after `max`. Exposes `data-direction="next"`.
|
|
3277
3417
|
*/
|
|
3278
3418
|
const NextMonthButton = forwardRef(NextMonthButtonFn);
|
|
3279
|
-
|
|
3280
|
-
//#region src/selected-range.tsx
|
|
3419
|
+
// src/selected-range.tsx
|
|
3281
3420
|
const rangeOverlayStateAttributesMapping = {
|
|
3282
3421
|
root: () => null,
|
|
3283
3422
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3397,8 +3536,7 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3397
3536
|
});
|
|
3398
3537
|
}
|
|
3399
3538
|
const RangeSelectedInner = forwardRef(RangeSelectedInnerFn);
|
|
3400
|
-
|
|
3401
|
-
//#region src/range-preview.tsx
|
|
3539
|
+
// src/range-preview.tsx
|
|
3402
3540
|
function RangePreviewFn(props, ref) {
|
|
3403
3541
|
const { selectionMode } = useCalendarStable();
|
|
3404
3542
|
if (selectionMode !== "range") return null;
|
|
@@ -3471,8 +3609,7 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3471
3609
|
});
|
|
3472
3610
|
}
|
|
3473
3611
|
const RangePreviewInner = forwardRef(RangePreviewInnerFn);
|
|
3474
|
-
|
|
3475
|
-
//#region src/drag-handle.tsx
|
|
3612
|
+
// src/drag-handle.tsx
|
|
3476
3613
|
const dragHandleStateAttributesMapping = {
|
|
3477
3614
|
root: () => null,
|
|
3478
3615
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3491,32 +3628,34 @@ function useDragHandle(edge, { dragging: draggingProp }) {
|
|
|
3491
3628
|
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
3629
|
const isDragging = !!draggingProp && isActive;
|
|
3493
3630
|
const handleRef = useRef(null);
|
|
3631
|
+
const state = useMemo(() => ({
|
|
3632
|
+
root: rootState,
|
|
3633
|
+
active: isActive,
|
|
3634
|
+
dragging: isDragging,
|
|
3635
|
+
edge,
|
|
3636
|
+
orientation
|
|
3637
|
+
}), [
|
|
3638
|
+
rootState,
|
|
3639
|
+
isActive,
|
|
3640
|
+
isDragging,
|
|
3641
|
+
edge,
|
|
3642
|
+
orientation
|
|
3643
|
+
]);
|
|
3644
|
+
const defaultProps = {
|
|
3645
|
+
role: "slider",
|
|
3646
|
+
"aria-roledescription": "drag handle",
|
|
3647
|
+
"aria-label": edge === "start" ? "Range start date" : "Range end date",
|
|
3648
|
+
"aria-valuetext": date?.toString(),
|
|
3649
|
+
"aria-grabbed": isActive ? isDragging : void 0,
|
|
3650
|
+
"aria-hidden": isActive ? void 0 : true,
|
|
3651
|
+
onPointerEnter: () => {
|
|
3652
|
+
if (date && !outsideDisabled) setHoveredDate(date);
|
|
3653
|
+
}
|
|
3654
|
+
};
|
|
3494
3655
|
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
|
-
]),
|
|
3656
|
+
state,
|
|
3508
3657
|
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
|
-
},
|
|
3658
|
+
defaultProps,
|
|
3520
3659
|
handleRef
|
|
3521
3660
|
};
|
|
3522
3661
|
}
|
|
@@ -3557,8 +3696,7 @@ function RangeEndDragHandleFn(props, ref) {
|
|
|
3557
3696
|
}
|
|
3558
3697
|
/** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
|
|
3559
3698
|
const RangeEndDragHandle = forwardRef(RangeEndDragHandleFn);
|
|
3560
|
-
|
|
3561
|
-
//#region src/week-number.tsx
|
|
3699
|
+
// src/week-number.tsx
|
|
3562
3700
|
const weekNumberCellStateAttributesMapping = {
|
|
3563
3701
|
root: () => null,
|
|
3564
3702
|
weekNumber: (v) => ({ "data-week-number": String(v) })
|
|
@@ -3623,8 +3761,7 @@ function WeekNumberHeaderFn(props, ref) {
|
|
|
3623
3761
|
* Column header for the week number column. Renders a `<th scope="col">`.
|
|
3624
3762
|
*/
|
|
3625
3763
|
const WeekNumberHeader = forwardRef(WeekNumberHeaderFn);
|
|
3626
|
-
|
|
3627
|
-
//#region src/compute-weeks-in-window.ts
|
|
3764
|
+
// src/compute-weeks-in-window.ts
|
|
3628
3765
|
/**
|
|
3629
3766
|
* Computes an array of week descriptors for a continuous window.
|
|
3630
3767
|
* `firstWeek` is snapped back to the nearest `weekStartDay`.
|
|
@@ -3646,8 +3783,7 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
|
|
|
3646
3783
|
}
|
|
3647
3784
|
return weeks;
|
|
3648
3785
|
}
|
|
3649
|
-
|
|
3650
|
-
//#region src/resolve-first-week.ts
|
|
3786
|
+
// src/resolve-first-week.ts
|
|
3651
3787
|
/** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
|
|
3652
3788
|
function snapToWeekStart(date, weekStartDay) {
|
|
3653
3789
|
const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
@@ -3738,8 +3874,7 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
|
3738
3874
|
}
|
|
3739
3875
|
}
|
|
3740
3876
|
}
|
|
3741
|
-
|
|
3742
|
-
//#region src/out-of-range.ts
|
|
3877
|
+
// src/out-of-range.ts
|
|
3743
3878
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3744
3879
|
function weekHasValidDay(weekStart, min, max, T) {
|
|
3745
3880
|
const weekEnd = weekStart.add({ days: 6 });
|
|
@@ -3808,8 +3943,7 @@ function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekS
|
|
|
3808
3943
|
weekCount
|
|
3809
3944
|
};
|
|
3810
3945
|
}
|
|
3811
|
-
|
|
3812
|
-
//#region src/weeks-window.ts
|
|
3946
|
+
// src/weeks-window.ts
|
|
3813
3947
|
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3814
3948
|
const bounds = {
|
|
3815
3949
|
weekCount,
|
|
@@ -3834,15 +3968,15 @@ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T
|
|
|
3834
3968
|
moveTo,
|
|
3835
3969
|
shift: (current, direction, shiftBy) => {
|
|
3836
3970
|
const by = shiftBy ?? current.weekCount;
|
|
3837
|
-
const
|
|
3971
|
+
const target = current.firstWeek.add({ weeks: direction * by });
|
|
3972
|
+
const next = moveTo(target);
|
|
3838
3973
|
if (next === null) return null;
|
|
3839
3974
|
if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
|
|
3840
3975
|
return next;
|
|
3841
3976
|
}
|
|
3842
3977
|
};
|
|
3843
3978
|
}
|
|
3844
|
-
|
|
3845
|
-
//#region src/weeks-view-state.ts
|
|
3979
|
+
// src/weeks-view-state.ts
|
|
3846
3980
|
/**
|
|
3847
3981
|
* Core state management hook for WeeksView.Root.
|
|
3848
3982
|
* Reads calendar-level context and manages weeks-specific state.
|
|
@@ -4167,7 +4301,8 @@ function useWeeksViewRootState(props) {
|
|
|
4167
4301
|
]),
|
|
4168
4302
|
viewStableCtx: useMemo(() => ({
|
|
4169
4303
|
gridFocusedRef,
|
|
4170
|
-
outsideDays: "enabled"
|
|
4304
|
+
outsideDays: "enabled",
|
|
4305
|
+
setFocusedDate
|
|
4171
4306
|
}), []),
|
|
4172
4307
|
viewStateCtx: useMemo(() => ({
|
|
4173
4308
|
currentDateTime,
|
|
@@ -4176,8 +4311,7 @@ function useWeeksViewRootState(props) {
|
|
|
4176
4311
|
scrollToWeek
|
|
4177
4312
|
};
|
|
4178
4313
|
}
|
|
4179
|
-
|
|
4180
|
-
//#region src/weeks-view.tsx
|
|
4314
|
+
// src/weeks-view.tsx
|
|
4181
4315
|
function WeeksViewRootFn(props, ref) {
|
|
4182
4316
|
const { children } = props;
|
|
4183
4317
|
const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
@@ -4192,7 +4326,7 @@ function WeeksViewRootFn(props, ref) {
|
|
|
4192
4326
|
value: viewStateCtx,
|
|
4193
4327
|
children: /* @__PURE__ */ jsx(ViewContext.Provider, {
|
|
4194
4328
|
value: viewCtx,
|
|
4195
|
-
children
|
|
4329
|
+
children: /* @__PURE__ */ jsx(DayCellStoreProvider, { children })
|
|
4196
4330
|
})
|
|
4197
4331
|
})
|
|
4198
4332
|
})
|
|
@@ -4219,8 +4353,7 @@ function WeeksViewFn(props, ref) {
|
|
|
4219
4353
|
}
|
|
4220
4354
|
const WeeksView = forwardRef(WeeksViewFn);
|
|
4221
4355
|
WeeksView.Root = WeeksViewRoot;
|
|
4222
|
-
|
|
4223
|
-
//#region src/weeks-navigation.tsx
|
|
4356
|
+
// src/weeks-navigation.tsx
|
|
4224
4357
|
const weeksNavButtonStateAttributesMapping = {
|
|
4225
4358
|
root: () => null,
|
|
4226
4359
|
direction: (v) => ({ "data-direction": v }),
|
|
@@ -4329,5 +4462,4 @@ function WeekCountFn(props, ref) {
|
|
|
4329
4462
|
* out-of-range modes where the actual count may be less than the `weekCount` prop.
|
|
4330
4463
|
*/
|
|
4331
4464
|
const WeekCount = forwardRef(WeekCountFn);
|
|
4332
|
-
|
|
4333
|
-
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 };
|
|
4465
|
+
export { MonthSeparatorRow as A, DayCellDataContext as B, DayButton as C, MonthSeparator as D, useWeeksViewState as E, MonthView as F, useCalendarStable as G, WeekDataContext as H, MonthViewRoot as I, useCalendarState as K, useMonthViewStable as L, MonthSeparatorYear as M, GridHeader as N, MonthSeparatorCell as O, GridHeaderCell as P, useMonthViewState as R, WeekTemplate as S, useWeeksViewStable as T, CalendarProvider as U, GridContext 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, useViewContext as z };
|