@klinking/colander 3.1.0-alpha.8 → 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 +1 -1
- package/dist/formats/date.d.cts +1 -1
- package/dist/formats/date.d.mts +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.d.cts +1 -1
- package/dist/formats/object.d.mts +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.d.cts +1 -1
- package/dist/formats/plain-date-time.d.mts +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.d.cts +1 -1
- package/dist/formats/plain-date.d.mts +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.d.cts +1 -1
- package/dist/formats/plain-month-day.d.mts +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.d.cts +1 -1
- package/dist/formats/plain-year-month.d.mts +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.d.cts +1 -1
- package/dist/formats/zoned-date-time.d.mts +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/{index-BqzrxYgn.d.cts → index-B5VJ_WF2.d.mts} +2 -8
- package/dist/{index-CkhYFmf4.d.mts → index-BMsxaq1s.d.cts} +2 -8
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-CatYJIKb.cjs → weeks-navigation-CUQApLMk.cjs} +438 -290
- package/dist/{weeks-navigation-BWB5OvqW.mjs → weeks-navigation-CWNpF_6M.mjs} +440 -292
- package/package.json +5 -1
- package/src/calendar-provider.tsx +8 -2
- 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 +72 -89
- package/src/day-cell.tsx +93 -78
- package/src/grid.tsx +17 -15
- package/src/month-view.tsx +3 -2
- package/src/store.ts +72 -0
- package/src/view-context.ts +2 -0
- package/src/weeks-grid.tsx +20 -10
- package/src/weeks-view-state.ts +1 -1
- package/src/weeks-view.tsx +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
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";
|
|
@@ -830,6 +831,45 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
|
|
|
830
831
|
});
|
|
831
832
|
return preview ? mkRange(preview[0], preview[1]) : null;
|
|
832
833
|
}
|
|
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
|
+
}
|
|
833
873
|
// src/calendar-provider.tsx
|
|
834
874
|
/**
|
|
835
875
|
* Provides shared calendar state (selection, config, range preview) to all
|
|
@@ -1123,7 +1163,7 @@ function CalendarProvider(props) {
|
|
|
1123
1163
|
isMultiple,
|
|
1124
1164
|
isControlled
|
|
1125
1165
|
]);
|
|
1126
|
-
const
|
|
1166
|
+
const onSelectLatest = useCallback((date) => {
|
|
1127
1167
|
const result = computeSelectionUpdate({
|
|
1128
1168
|
date,
|
|
1129
1169
|
readOnly,
|
|
@@ -1167,7 +1207,7 @@ function CalendarProvider(props) {
|
|
|
1167
1207
|
currentRangeFormatted,
|
|
1168
1208
|
currentMultipleFormatted
|
|
1169
1209
|
]);
|
|
1170
|
-
const
|
|
1210
|
+
const setRangeLatest = useCallback((start, end) => {
|
|
1171
1211
|
const result = computeSetRangeUpdate({
|
|
1172
1212
|
start,
|
|
1173
1213
|
end,
|
|
@@ -1193,6 +1233,8 @@ function CalendarProvider(props) {
|
|
|
1193
1233
|
resolvedFormat,
|
|
1194
1234
|
T
|
|
1195
1235
|
]);
|
|
1236
|
+
const onSelect = useStableCallback(onSelectLatest);
|
|
1237
|
+
const setRange = useStableCallback(setRangeLatest);
|
|
1196
1238
|
const nonNullDates = useMemo(() => committedDates.filter((d) => d != null), [committedDates]);
|
|
1197
1239
|
const stableCtx = useMemo(() => ({
|
|
1198
1240
|
onSelect,
|
|
@@ -1275,6 +1317,292 @@ function CalendarProvider(props) {
|
|
|
1275
1317
|
})
|
|
1276
1318
|
});
|
|
1277
1319
|
}
|
|
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
|
+
}
|
|
1278
1606
|
// src/month-view-context.ts
|
|
1279
1607
|
/** @internal React context for MonthView stable values (config + callbacks). */
|
|
1280
1608
|
const MonthViewStableContext = createContext(null);
|
|
@@ -1461,31 +1789,6 @@ function monthAt(start, offset) {
|
|
|
1461
1789
|
month: index % 12 + 1
|
|
1462
1790
|
};
|
|
1463
1791
|
}
|
|
1464
|
-
// src/view-context.ts
|
|
1465
|
-
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1466
|
-
const ViewContext = createContext(null);
|
|
1467
|
-
/** Returns the nearest view context (MonthView or WeeksView). */
|
|
1468
|
-
function useViewContext() {
|
|
1469
|
-
const ctx = useContext(ViewContext);
|
|
1470
|
-
if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
|
|
1471
|
-
return ctx;
|
|
1472
|
-
}
|
|
1473
|
-
/** @internal Context for {@link ViewStableContextValue}. */
|
|
1474
|
-
const ViewStableContext = createContext(null);
|
|
1475
|
-
/** @internal Context for {@link ViewStateContextValue}. */
|
|
1476
|
-
const ViewStateContext = createContext(null);
|
|
1477
|
-
/** Returns the nearest view's stable values. */
|
|
1478
|
-
function useViewStable() {
|
|
1479
|
-
const ctx = useContext(ViewStableContext);
|
|
1480
|
-
if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
|
|
1481
|
-
return ctx;
|
|
1482
|
-
}
|
|
1483
|
-
/** Returns the nearest view's volatile state. */
|
|
1484
|
-
function useViewState() {
|
|
1485
|
-
const ctx = useContext(ViewStateContext);
|
|
1486
|
-
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1487
|
-
return ctx;
|
|
1488
|
-
}
|
|
1489
1792
|
// src/month-view.tsx
|
|
1490
1793
|
function MonthViewRoot(props) {
|
|
1491
1794
|
const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
|
|
@@ -1671,7 +1974,8 @@ function MonthViewRoot(props) {
|
|
|
1671
1974
|
]);
|
|
1672
1975
|
const viewStableCtx = useMemo(() => ({
|
|
1673
1976
|
gridFocusedRef,
|
|
1674
|
-
outsideDays
|
|
1977
|
+
outsideDays,
|
|
1978
|
+
setFocusedDate
|
|
1675
1979
|
}), [outsideDays]);
|
|
1676
1980
|
const viewStateCtx = useMemo(() => ({
|
|
1677
1981
|
currentDateTime,
|
|
@@ -1687,7 +1991,7 @@ function MonthViewRoot(props) {
|
|
|
1687
1991
|
value: viewStateCtx,
|
|
1688
1992
|
children: /* @__PURE__ */ jsx(ViewContext.Provider, {
|
|
1689
1993
|
value: viewCtx,
|
|
1690
|
-
children
|
|
1994
|
+
children: /* @__PURE__ */ jsx(DayCellStoreProvider, { children })
|
|
1691
1995
|
})
|
|
1692
1996
|
})
|
|
1693
1997
|
})
|
|
@@ -1711,15 +2015,6 @@ function MonthView(props) {
|
|
|
1711
2015
|
});
|
|
1712
2016
|
}
|
|
1713
2017
|
MonthView.Root = MonthViewRoot;
|
|
1714
|
-
// src/context.ts
|
|
1715
|
-
/** @internal Provides the days and index of the current week row to child components. */
|
|
1716
|
-
const WeekDataContext = createContext(null);
|
|
1717
|
-
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
1718
|
-
const GridContext = createContext({ orientation: "horizontal" });
|
|
1719
|
-
/** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
|
|
1720
|
-
const DayCellDataContext = createContext(null);
|
|
1721
|
-
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1722
|
-
const GridMonthContext = createContext(null);
|
|
1723
2018
|
// src/grid-header.tsx
|
|
1724
2019
|
function useGridHeaderCellState(index) {
|
|
1725
2020
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
@@ -2166,28 +2461,35 @@ function WeeksGrid(props) {
|
|
|
2166
2461
|
}
|
|
2167
2462
|
return map;
|
|
2168
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]);
|
|
2169
2479
|
const rows = [];
|
|
2170
2480
|
for (const [i, week] of weeks.entries()) {
|
|
2171
|
-
|
|
2172
|
-
if (days === void 0) continue;
|
|
2481
|
+
if (weekDaysArrays[i] === void 0) continue;
|
|
2173
2482
|
const separators = boundariesAtIndex.get(i);
|
|
2174
2483
|
if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ jsx(MonthSeparatorDataContext.Provider, {
|
|
2175
2484
|
value: separatorData,
|
|
2176
2485
|
children: separatorTemplate
|
|
2177
2486
|
}, `sep-${separatorData.year}-${separatorData.month}`));
|
|
2178
|
-
const
|
|
2487
|
+
const rowValue = rowValues[i];
|
|
2488
|
+
if (rowValue === void 0) continue;
|
|
2179
2489
|
rows.push(/* @__PURE__ */ jsx(WeekDataContext.Provider, {
|
|
2180
|
-
value:
|
|
2181
|
-
days,
|
|
2182
|
-
weekIndex: week.weekIndex,
|
|
2183
|
-
gridRowIndex: weekGridRow
|
|
2184
|
-
},
|
|
2490
|
+
value: rowValue.weekData,
|
|
2185
2491
|
children: /* @__PURE__ */ jsx(GridMonthContext.Provider, {
|
|
2186
|
-
value:
|
|
2187
|
-
weeks: [days],
|
|
2188
|
-
year: week.year,
|
|
2189
|
-
month: week.month
|
|
2190
|
-
},
|
|
2492
|
+
value: rowValue.gridMonth,
|
|
2191
2493
|
children: weekRowChildren
|
|
2192
2494
|
})
|
|
2193
2495
|
}, week.startDate.toString()));
|
|
@@ -2272,178 +2574,6 @@ function computeWeeksKeyNav(input) {
|
|
|
2272
2574
|
default: return NONE;
|
|
2273
2575
|
}
|
|
2274
2576
|
}
|
|
2275
|
-
// src/day-cell-state.ts
|
|
2276
|
-
const NO_RANGE = {
|
|
2277
|
-
rangeStart: false,
|
|
2278
|
-
rangeEnd: false,
|
|
2279
|
-
rangeBoundary: false,
|
|
2280
|
-
inRange: false,
|
|
2281
|
-
rangeIndex: false,
|
|
2282
|
-
rangeLength: false,
|
|
2283
|
-
rangeHasStart: false,
|
|
2284
|
-
rangeHasEnd: false,
|
|
2285
|
-
rangePreviewStart: false,
|
|
2286
|
-
rangePreviewEnd: false,
|
|
2287
|
-
rangePreviewBoundary: false,
|
|
2288
|
-
rangePreviewInRange: false,
|
|
2289
|
-
rangePreviewIndex: false,
|
|
2290
|
-
rangePreviewLength: false,
|
|
2291
|
-
rangePreviewHasStart: false,
|
|
2292
|
-
rangePreviewHasEnd: false
|
|
2293
|
-
};
|
|
2294
|
-
function computeRangeState(date, inputs) {
|
|
2295
|
-
const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
|
|
2296
|
-
if (selectionMode !== "range") return NO_RANGE;
|
|
2297
|
-
const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
2298
|
-
const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
2299
|
-
const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
2300
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
2301
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
2302
|
-
const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
2303
|
-
const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
2304
|
-
const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
2305
|
-
return {
|
|
2306
|
-
rangeStart: isRangeStart,
|
|
2307
|
-
rangeEnd: isRangeEnd,
|
|
2308
|
-
rangeBoundary: isRangeStart || isRangeEnd,
|
|
2309
|
-
inRange,
|
|
2310
|
-
rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
|
|
2311
|
-
rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
|
|
2312
|
-
rangeHasStart: inRange && rangeStart !== void 0,
|
|
2313
|
-
rangeHasEnd: inRange && rangeEnd !== void 0,
|
|
2314
|
-
rangePreviewStart: isPreviewStart,
|
|
2315
|
-
rangePreviewEnd: isPreviewEnd,
|
|
2316
|
-
rangePreviewBoundary: isPreviewStart || isPreviewEnd,
|
|
2317
|
-
rangePreviewInRange: inPreview,
|
|
2318
|
-
rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
|
|
2319
|
-
rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
|
|
2320
|
-
rangePreviewHasStart: inPreview && previewStart !== void 0,
|
|
2321
|
-
rangePreviewHasEnd: inPreview && previewEnd !== void 0
|
|
2322
|
-
};
|
|
2323
|
-
}
|
|
2324
|
-
/** Derives the state of one day cell. Pure function, no hooks. */
|
|
2325
|
-
function computeDayCellState(date, position, inputs) {
|
|
2326
|
-
const { T, outsideDays } = inputs;
|
|
2327
|
-
const { columnIndex, month } = position;
|
|
2328
|
-
const isCurrentMonth = date.year === month.year && date.month === month.month;
|
|
2329
|
-
const base = {
|
|
2330
|
-
root: inputs.rootState,
|
|
2331
|
-
date,
|
|
2332
|
-
columnIndex,
|
|
2333
|
-
orientation: inputs.orientation
|
|
2334
|
-
};
|
|
2335
|
-
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
2336
|
-
...base,
|
|
2337
|
-
...NO_RANGE,
|
|
2338
|
-
outsideMonth: true,
|
|
2339
|
-
hidden: true,
|
|
2340
|
-
selected: false,
|
|
2341
|
-
today: false,
|
|
2342
|
-
disabled: true,
|
|
2343
|
-
focused: false,
|
|
2344
|
-
isTabTarget: false
|
|
2345
|
-
};
|
|
2346
|
-
const isToday = T.PlainDate.compare(date, inputs.today) === 0;
|
|
2347
|
-
if (!isCurrentMonth && outsideDays !== "enabled") {
|
|
2348
|
-
const suppressRange = outsideDays === "disabled";
|
|
2349
|
-
return {
|
|
2350
|
-
...base,
|
|
2351
|
-
...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
|
|
2352
|
-
outsideMonth: true,
|
|
2353
|
-
hidden: false,
|
|
2354
|
-
selected: false,
|
|
2355
|
-
today: isToday,
|
|
2356
|
-
disabled: true,
|
|
2357
|
-
focused: false,
|
|
2358
|
-
isTabTarget: false
|
|
2359
|
-
};
|
|
2360
|
-
}
|
|
2361
|
-
return {
|
|
2362
|
-
...base,
|
|
2363
|
-
...computeRangeState(date, inputs),
|
|
2364
|
-
outsideMonth: !isCurrentMonth,
|
|
2365
|
-
hidden: false,
|
|
2366
|
-
selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
|
|
2367
|
-
today: isToday,
|
|
2368
|
-
disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
|
|
2369
|
-
focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
|
|
2370
|
-
isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
|
|
2371
|
-
};
|
|
2372
|
-
}
|
|
2373
|
-
const COMPARED_KEYS = Object.keys({
|
|
2374
|
-
outsideMonth: true,
|
|
2375
|
-
hidden: true,
|
|
2376
|
-
selected: true,
|
|
2377
|
-
today: true,
|
|
2378
|
-
disabled: true,
|
|
2379
|
-
focused: true,
|
|
2380
|
-
rangeStart: true,
|
|
2381
|
-
rangeEnd: true,
|
|
2382
|
-
rangeBoundary: true,
|
|
2383
|
-
inRange: true,
|
|
2384
|
-
rangeIndex: true,
|
|
2385
|
-
rangeLength: true,
|
|
2386
|
-
rangeHasStart: true,
|
|
2387
|
-
rangeHasEnd: true,
|
|
2388
|
-
rangePreviewStart: true,
|
|
2389
|
-
rangePreviewEnd: true,
|
|
2390
|
-
rangePreviewBoundary: true,
|
|
2391
|
-
rangePreviewInRange: true,
|
|
2392
|
-
rangePreviewIndex: true,
|
|
2393
|
-
rangePreviewLength: true,
|
|
2394
|
-
rangePreviewHasStart: true,
|
|
2395
|
-
rangePreviewHasEnd: true,
|
|
2396
|
-
isTabTarget: true
|
|
2397
|
-
});
|
|
2398
|
-
/** Whether two cell states render the same cell. */
|
|
2399
|
-
function dayCellStateEqual(a, b) {
|
|
2400
|
-
for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
|
|
2401
|
-
return true;
|
|
2402
|
-
}
|
|
2403
|
-
/**
|
|
2404
|
-
* Reads the contexts a day cell depends on and returns a function that derives
|
|
2405
|
-
* the state of any cell. `columnIndex` defaults to the date's column in a
|
|
2406
|
-
* week starting on the calendar's `weekStartDay`.
|
|
2407
|
-
*/
|
|
2408
|
-
function useDayCellDeriver() {
|
|
2409
|
-
const { orientation } = useContext(GridContext);
|
|
2410
|
-
const weekData = useContext(WeekDataContext);
|
|
2411
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2412
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2413
|
-
const viewCtx = useViewContext();
|
|
2414
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2415
|
-
const { rootState, currentDateTime } = useViewState();
|
|
2416
|
-
const { outsideDays } = useViewStable();
|
|
2417
|
-
const inputs = {
|
|
2418
|
-
T,
|
|
2419
|
-
today: today(),
|
|
2420
|
-
orientation,
|
|
2421
|
-
rootState,
|
|
2422
|
-
selectionMode,
|
|
2423
|
-
selectedDates,
|
|
2424
|
-
rangeStart,
|
|
2425
|
-
rangeEnd,
|
|
2426
|
-
previewStart,
|
|
2427
|
-
previewEnd,
|
|
2428
|
-
disabled,
|
|
2429
|
-
isDateDisabled,
|
|
2430
|
-
focusedDate,
|
|
2431
|
-
tabTargetDate,
|
|
2432
|
-
outsideDays
|
|
2433
|
-
};
|
|
2434
|
-
const isWeeksView = viewCtx.viewType === "weeks";
|
|
2435
|
-
const gridMonth = weekData?.gridMonth ?? currentDateTime;
|
|
2436
|
-
return (date, columnIndex) => {
|
|
2437
|
-
const daysInWeek = date.daysInWeek;
|
|
2438
|
-
return computeDayCellState(date, {
|
|
2439
|
-
columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek,
|
|
2440
|
-
month: isWeeksView ? {
|
|
2441
|
-
year: date.year,
|
|
2442
|
-
month: date.month
|
|
2443
|
-
} : gridMonth
|
|
2444
|
-
}, inputs);
|
|
2445
|
-
};
|
|
2446
|
-
}
|
|
2447
2577
|
// src/day-cell.tsx
|
|
2448
2578
|
const dayStateAttributesMapping = {
|
|
2449
2579
|
root: () => null,
|
|
@@ -2473,9 +2603,12 @@ const dayStateAttributesMapping = {
|
|
|
2473
2603
|
rangePreviewHasStart: (v) => v ? { "data-range-preview-has-start": "" } : null,
|
|
2474
2604
|
rangePreviewHasEnd: (v) => v ? { "data-range-preview-has-end": "" } : null
|
|
2475
2605
|
};
|
|
2606
|
+
/** @internal The enclosing day cell's state, read by its `DayButton`. */
|
|
2607
|
+
const DayCellStateContext = createContext(null);
|
|
2476
2608
|
function DayCellInstanceFn(props) {
|
|
2477
|
-
const { render, date, columnIndex,
|
|
2478
|
-
const
|
|
2609
|
+
const { render, date, columnIndex, gridMonth, children, ...otherProps } = props;
|
|
2610
|
+
const derived = useDayCellState(date, columnIndex, gridMonth);
|
|
2611
|
+
const state = derived;
|
|
2479
2612
|
const defaultProps = state.hidden ? {
|
|
2480
2613
|
role: "gridcell",
|
|
2481
2614
|
"aria-hidden": true,
|
|
@@ -2484,7 +2617,7 @@ function DayCellInstanceFn(props) {
|
|
|
2484
2617
|
role: "gridcell",
|
|
2485
2618
|
"aria-selected": state.selected || void 0,
|
|
2486
2619
|
"aria-disabled": state.disabled || void 0,
|
|
2487
|
-
children: children ?? /* @__PURE__ */ jsx(DayButton, {
|
|
2620
|
+
children: children ?? /* @__PURE__ */ jsx(DayButton, {})
|
|
2488
2621
|
};
|
|
2489
2622
|
const cell = useRender({
|
|
2490
2623
|
defaultTagName: "td",
|
|
@@ -2495,13 +2628,21 @@ function DayCellInstanceFn(props) {
|
|
|
2495
2628
|
props: mergeProps(defaultProps, otherProps)
|
|
2496
2629
|
});
|
|
2497
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
|
+
]);
|
|
2498
2640
|
return /* @__PURE__ */ jsx(DayCellDataContext.Provider, {
|
|
2499
|
-
value:
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
}
|
|
2504
|
-
children: cell
|
|
2641
|
+
value: cellData,
|
|
2642
|
+
children: /* @__PURE__ */ jsx(DayCellStateContext.Provider, {
|
|
2643
|
+
value: derived,
|
|
2644
|
+
children: cell
|
|
2645
|
+
})
|
|
2505
2646
|
});
|
|
2506
2647
|
}
|
|
2507
2648
|
/**
|
|
@@ -2521,20 +2662,31 @@ const DAY_CELL_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
|
2521
2662
|
"render",
|
|
2522
2663
|
"date",
|
|
2523
2664
|
"columnIndex",
|
|
2524
|
-
"
|
|
2525
|
-
"
|
|
2665
|
+
"gridMonth",
|
|
2666
|
+
"children"
|
|
2526
2667
|
]);
|
|
2527
2668
|
const DAY_BUTTON_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2528
2669
|
"render",
|
|
2529
2670
|
"date",
|
|
2530
2671
|
"children",
|
|
2531
|
-
"
|
|
2672
|
+
"_state"
|
|
2532
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
|
+
*/
|
|
2533
2678
|
function dayCellInstancePropsAreEqual(prev, next) {
|
|
2534
|
-
|
|
2535
|
-
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);
|
|
2536
2680
|
}
|
|
2537
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
|
+
}
|
|
2538
2690
|
/**
|
|
2539
2691
|
* Renders one `<td role="gridcell">` per day. Exposes data-attributes for
|
|
2540
2692
|
* `selected`, `today`, `disabled`, `outside-month`, `focused`,
|
|
@@ -2546,36 +2698,32 @@ const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
|
2546
2698
|
function DayCellTemplate(props) {
|
|
2547
2699
|
const { date: dateProp, ...restProps } = props;
|
|
2548
2700
|
const weekData = useContext(WeekDataContext);
|
|
2549
|
-
const monthState = useContext(MonthViewStateContext);
|
|
2550
|
-
const derive = useDayCellDeriver();
|
|
2551
2701
|
if (dateProp) return /* @__PURE__ */ jsx(DayCellInstance, {
|
|
2552
2702
|
...restProps,
|
|
2553
2703
|
date: dateProp,
|
|
2554
|
-
|
|
2704
|
+
gridMonth: weekData?.gridMonth
|
|
2555
2705
|
});
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
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, {
|
|
2559
2708
|
...restProps,
|
|
2560
2709
|
date: day,
|
|
2561
|
-
columnIndex:
|
|
2562
|
-
|
|
2710
|
+
columnIndex: i,
|
|
2711
|
+
gridMonth: weekData.gridMonth
|
|
2563
2712
|
}, day.toString())) });
|
|
2564
2713
|
}
|
|
2565
2714
|
function DayButtonInnerFn(props, ref) {
|
|
2566
|
-
const { render, date,
|
|
2715
|
+
const { render, date, _state, ...otherProps } = props;
|
|
2567
2716
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
2568
|
-
const { setFocusedDate } =
|
|
2569
|
-
const { gridFocusedRef } = useViewStable();
|
|
2717
|
+
const { gridFocusedRef, setFocusedDate } = useViewStable();
|
|
2570
2718
|
const internalRef = useRef(null);
|
|
2571
|
-
const isHidden =
|
|
2572
|
-
const isFocused =
|
|
2573
|
-
const isTabTarget =
|
|
2574
|
-
const isDisabled =
|
|
2719
|
+
const isHidden = _state.hidden;
|
|
2720
|
+
const isFocused = _state.focused;
|
|
2721
|
+
const isTabTarget = _state.isTabTarget;
|
|
2722
|
+
const isDisabled = _state.disabled;
|
|
2575
2723
|
useEffect(() => {
|
|
2576
2724
|
if (shouldMoveDomFocus(isFocused, gridFocusedRef.current) && internalRef.current) internalRef.current.focus();
|
|
2577
2725
|
}, [isFocused, gridFocusedRef]);
|
|
2578
|
-
const state =
|
|
2726
|
+
const state = _state;
|
|
2579
2727
|
const defaultProps = isHidden ? {} : {
|
|
2580
2728
|
type: "button",
|
|
2581
2729
|
tabIndex: isTabTarget ? 0 : -1,
|
|
@@ -2607,12 +2755,7 @@ function DayButtonInnerFn(props, ref) {
|
|
|
2607
2755
|
});
|
|
2608
2756
|
}
|
|
2609
2757
|
function dayButtonInnerPropsAreEqual(prev, next) {
|
|
2610
|
-
|
|
2611
|
-
if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
|
|
2612
|
-
const a = prev._derivedState;
|
|
2613
|
-
const b = next._derivedState;
|
|
2614
|
-
if (!a || !b) return a === b;
|
|
2615
|
-
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);
|
|
2616
2759
|
}
|
|
2617
2760
|
const DayButtonInner = memo(forwardRef(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
|
|
2618
2761
|
/**
|
|
@@ -2622,37 +2765,36 @@ const DayButtonInner = memo(forwardRef(DayButtonInnerFn), dayButtonInnerPropsAre
|
|
|
2622
2765
|
* Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
|
|
2623
2766
|
*/
|
|
2624
2767
|
function DayButtonFn(props, ref) {
|
|
2625
|
-
const { date: dateProp,
|
|
2768
|
+
const { date: dateProp, ...restProps } = props;
|
|
2769
|
+
const cellState = useContext(DayCellStateContext);
|
|
2626
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
|
+
});
|
|
2627
2777
|
const resolvedDate = dateProp ?? cellData?.date;
|
|
2628
|
-
if (resolvedDate) {
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
_derivedState
|
|
2634
|
-
});
|
|
2635
|
-
return /* @__PURE__ */ jsx(DayButtonFallback, {
|
|
2636
|
-
ref,
|
|
2637
|
-
...restProps,
|
|
2638
|
-
date: resolvedDate
|
|
2639
|
-
});
|
|
2640
|
-
}
|
|
2778
|
+
if (resolvedDate) return /* @__PURE__ */ jsx(StandaloneDayButton, {
|
|
2779
|
+
...restProps,
|
|
2780
|
+
ref,
|
|
2781
|
+
date: resolvedDate
|
|
2782
|
+
});
|
|
2641
2783
|
throw new Error("DayButton must be used inside DayCellTemplate or receive an explicit date prop.");
|
|
2642
2784
|
}
|
|
2643
2785
|
const DayButton = forwardRef(DayButtonFn);
|
|
2644
|
-
/**
|
|
2645
|
-
function
|
|
2786
|
+
/** A `DayButton` outside any day cell: subscribes to its own date's state. */
|
|
2787
|
+
function StandaloneDayButtonFn(props, ref) {
|
|
2646
2788
|
const { date, ...restProps } = props;
|
|
2647
|
-
const
|
|
2789
|
+
const state = useStandaloneDayCellState(date);
|
|
2648
2790
|
return /* @__PURE__ */ jsx(DayButtonInner, {
|
|
2649
2791
|
...restProps,
|
|
2650
2792
|
ref,
|
|
2651
2793
|
date,
|
|
2652
|
-
|
|
2794
|
+
_state: state
|
|
2653
2795
|
});
|
|
2654
2796
|
}
|
|
2655
|
-
const
|
|
2797
|
+
const StandaloneDayButton = forwardRef(StandaloneDayButtonFn);
|
|
2656
2798
|
// src/grid.tsx
|
|
2657
2799
|
function useGridKeyboard() {
|
|
2658
2800
|
const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
|
|
@@ -3018,18 +3160,23 @@ function WeekTemplate(props) {
|
|
|
3018
3160
|
year: gridMonthCtx.year,
|
|
3019
3161
|
month: gridMonthCtx.month
|
|
3020
3162
|
} : void 0, [gridMonthCtx]);
|
|
3021
|
-
const
|
|
3022
|
-
|
|
3023
|
-
|
|
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];
|
|
3024
3176
|
if (firstDay === void 0) return null;
|
|
3025
3177
|
return /* @__PURE__ */ jsx(WeekDataContext.Provider, {
|
|
3026
|
-
value
|
|
3027
|
-
|
|
3028
|
-
weekIndex: i,
|
|
3029
|
-
...gridMonth !== void 0 && { gridMonth },
|
|
3030
|
-
...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
|
|
3031
|
-
},
|
|
3032
|
-
children: /* @__PURE__ */ jsx(Instance, { ...props })
|
|
3178
|
+
value,
|
|
3179
|
+
children: /* @__PURE__ */ jsx(WeekInstance, { ...props })
|
|
3033
3180
|
}, firstDay.toString());
|
|
3034
3181
|
}) });
|
|
3035
3182
|
}
|
|
@@ -4154,7 +4301,8 @@ function useWeeksViewRootState(props) {
|
|
|
4154
4301
|
]),
|
|
4155
4302
|
viewStableCtx: useMemo(() => ({
|
|
4156
4303
|
gridFocusedRef,
|
|
4157
|
-
outsideDays: "enabled"
|
|
4304
|
+
outsideDays: "enabled",
|
|
4305
|
+
setFocusedDate
|
|
4158
4306
|
}), []),
|
|
4159
4307
|
viewStateCtx: useMemo(() => ({
|
|
4160
4308
|
currentDateTime,
|
|
@@ -4178,7 +4326,7 @@ function WeeksViewRootFn(props, ref) {
|
|
|
4178
4326
|
value: viewStateCtx,
|
|
4179
4327
|
children: /* @__PURE__ */ jsx(ViewContext.Provider, {
|
|
4180
4328
|
value: viewCtx,
|
|
4181
|
-
children
|
|
4329
|
+
children: /* @__PURE__ */ jsx(DayCellStoreProvider, { children })
|
|
4182
4330
|
})
|
|
4183
4331
|
})
|
|
4184
4332
|
})
|
|
@@ -4314,4 +4462,4 @@ function WeekCountFn(props, ref) {
|
|
|
4314
4462
|
* out-of-range modes where the actual count may be less than the `weekCount` prop.
|
|
4315
4463
|
*/
|
|
4316
4464
|
const WeekCount = forwardRef(WeekCountFn);
|
|
4317
|
-
export { MonthSeparatorRow as A,
|
|
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 };
|