@klinking/colander 3.1.0-alpha.3 → 3.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +1 -1
- package/dist/formats/date.d.cts +1 -1
- package/dist/formats/date.d.mts +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.d.cts +1 -1
- package/dist/formats/object.d.mts +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.d.cts +1 -1
- package/dist/formats/plain-date-time.d.mts +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.d.cts +1 -1
- package/dist/formats/plain-date.d.mts +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.d.cts +1 -1
- package/dist/formats/plain-month-day.d.mts +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.d.cts +1 -1
- package/dist/formats/plain-year-month.d.mts +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.d.cts +1 -1
- package/dist/formats/zoned-date-time.d.mts +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-DEaASUAh.mjs → weeks-navigation-CEV8w_69.mjs} +239 -221
- package/dist/{weeks-navigation-DvryOSWF.cjs → weeks-navigation-q3beZn2n.cjs} +239 -221
- package/dist/{weeks-view-context-CNAq2Hiu.d.cts → weeks-view-context-BLZZm1fq.d.mts} +33 -2
- package/dist/{weeks-view-context-CsP3PBiu.d.mts → weeks-view-context-CkTcdZpj.d.cts} +33 -2
- package/package.json +1 -1
- package/src/calendar-provider.tsx +6 -0
- package/src/calendar-types.ts +2 -0
- package/src/day-cell.tsx +8 -1
- package/src/month-view-navigation.ts +180 -0
- package/src/month-view-types.ts +3 -0
- package/src/month-view.bounds.test.tsx +136 -0
- package/src/month-view.tsx +41 -217
- package/src/month-window.test.ts +207 -0
- package/src/month-window.ts +93 -0
- package/src/navigation.tsx +15 -74
- package/src/today.test.tsx +98 -0
- package/src/utils.test.ts +25 -0
- package/src/utils.ts +17 -0
- package/src/weeks-view-state.ts +8 -15
|
@@ -70,6 +70,17 @@ function getSystemTimeZone(T) {
|
|
|
70
70
|
return T.Now.timeZoneId();
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
+
* The date a view opens on: the selected date, else today in the provider's time zone.
|
|
74
|
+
*
|
|
75
|
+
* @param selected - The currently selected value, or `undefined`.
|
|
76
|
+
* @param today - Reads today's date in the provider's time zone.
|
|
77
|
+
* @param timeZone - IANA time zone.
|
|
78
|
+
* @param T - Temporal namespace.
|
|
79
|
+
*/
|
|
80
|
+
function resolveInitialAnchor(selected, today, timeZone, T) {
|
|
81
|
+
return selectedToZdt(selected, timeZone, T)?.toPlainDate() ?? today();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
73
84
|
* Converts any {@link DateValueObject} into a `Temporal.ZonedDateTime`.
|
|
74
85
|
*
|
|
75
86
|
* Handles all supported value formats (`PlainDate`, `PlainDateTime`,
|
|
@@ -826,6 +837,7 @@ function CalendarProvider(props) {
|
|
|
826
837
|
const locale = localeProp ?? "en-US";
|
|
827
838
|
const timeZone = timeZoneProp ?? getSystemTimeZone(T);
|
|
828
839
|
const weekStartDay = weekStartDayProp ?? 0;
|
|
840
|
+
const today = (0, react.useCallback)(() => T.Now.zonedDateTimeISO(timeZone).toPlainDate(), [T, timeZone]);
|
|
829
841
|
const resolvedFormat = formatProp ?? "PlainDate";
|
|
830
842
|
const selectionMode = selectionModeProp ?? "single";
|
|
831
843
|
const disabled = disabledProp ?? false;
|
|
@@ -1228,6 +1240,7 @@ function CalendarProvider(props) {
|
|
|
1228
1240
|
...minValue !== void 0 && { minValue },
|
|
1229
1241
|
...maxValue !== void 0 && { maxValue },
|
|
1230
1242
|
timeZone,
|
|
1243
|
+
today,
|
|
1231
1244
|
locale,
|
|
1232
1245
|
temporal: T,
|
|
1233
1246
|
weekStartDay,
|
|
@@ -1245,6 +1258,7 @@ function CalendarProvider(props) {
|
|
|
1245
1258
|
minValue,
|
|
1246
1259
|
maxValue,
|
|
1247
1260
|
timeZone,
|
|
1261
|
+
today,
|
|
1248
1262
|
locale,
|
|
1249
1263
|
T,
|
|
1250
1264
|
weekStartDay,
|
|
@@ -1316,6 +1330,177 @@ function useMonthViewState() {
|
|
|
1316
1330
|
return ctx;
|
|
1317
1331
|
}
|
|
1318
1332
|
//#endregion
|
|
1333
|
+
//#region src/month-view-navigation.ts
|
|
1334
|
+
/**
|
|
1335
|
+
* Owns which month the view shows, in both controlled and uncontrolled mode:
|
|
1336
|
+
* the month state, the Prev/Next steps, and syncing the window with focus.
|
|
1337
|
+
*
|
|
1338
|
+
* `onMonthChange` fires exactly once per move: from the effect below when
|
|
1339
|
+
* uncontrolled, and from the step or the focus-sync effect when controlled.
|
|
1340
|
+
*/
|
|
1341
|
+
function useMonthNavigation(input) {
|
|
1342
|
+
const { month, defaultMonth, initialAnchor, onMonthChange, policy, focusedDate, setFocusedDate, T } = input;
|
|
1343
|
+
const isControlled = month !== void 0;
|
|
1344
|
+
const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
|
|
1345
|
+
if (month) return {
|
|
1346
|
+
year: month.year,
|
|
1347
|
+
month: month.month
|
|
1348
|
+
};
|
|
1349
|
+
if (defaultMonth) return {
|
|
1350
|
+
year: defaultMonth.year,
|
|
1351
|
+
month: defaultMonth.month
|
|
1352
|
+
};
|
|
1353
|
+
const anchor = initialAnchor();
|
|
1354
|
+
return {
|
|
1355
|
+
year: anchor.year,
|
|
1356
|
+
month: anchor.month
|
|
1357
|
+
};
|
|
1358
|
+
});
|
|
1359
|
+
const year = isControlled ? month.year : internalMonth.year;
|
|
1360
|
+
const monthNumber = isControlled ? month.month : internalMonth.month;
|
|
1361
|
+
const currentMonth = (0, react.useMemo)(() => ({
|
|
1362
|
+
year,
|
|
1363
|
+
month: monthNumber
|
|
1364
|
+
}), [year, monthNumber]);
|
|
1365
|
+
const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
|
|
1366
|
+
year,
|
|
1367
|
+
month: monthNumber
|
|
1368
|
+
}), [
|
|
1369
|
+
year,
|
|
1370
|
+
monthNumber,
|
|
1371
|
+
T
|
|
1372
|
+
]);
|
|
1373
|
+
const onMonthChangeRef = (0, react.useRef)(onMonthChange);
|
|
1374
|
+
onMonthChangeRef.current = onMonthChange;
|
|
1375
|
+
const notifyMonth = (0, react.useCallback)((target) => {
|
|
1376
|
+
onMonthChangeRef.current?.(T.PlainYearMonth.from(target));
|
|
1377
|
+
}, [T]);
|
|
1378
|
+
const skipFocusSyncForRef = (0, react.useRef)(null);
|
|
1379
|
+
const prevFocusedRef = (0, react.useRef)(focusedDate);
|
|
1380
|
+
(0, react.useEffect)(() => {
|
|
1381
|
+
skipFocusSyncForRef.current = null;
|
|
1382
|
+
}, [month?.year, month?.month]);
|
|
1383
|
+
(0, react.useEffect)(() => {
|
|
1384
|
+
const prevFocused = prevFocusedRef.current;
|
|
1385
|
+
prevFocusedRef.current = focusedDate;
|
|
1386
|
+
const target = {
|
|
1387
|
+
year: focusedDate.year,
|
|
1388
|
+
month: focusedDate.month
|
|
1389
|
+
};
|
|
1390
|
+
if (isControlled) {
|
|
1391
|
+
if (skipFocusSyncForRef.current === focusedDate) {
|
|
1392
|
+
skipFocusSyncForRef.current = null;
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (prevFocused === focusedDate) return;
|
|
1396
|
+
if (policy.isVisible(currentMonth, target)) return;
|
|
1397
|
+
notifyMonth(policy.reveal(currentMonth, target));
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
setInternalMonth((prev) => {
|
|
1401
|
+
const next = policy.reveal(prev, target);
|
|
1402
|
+
if (next.year === prev.year && next.month === prev.month) return prev;
|
|
1403
|
+
return next;
|
|
1404
|
+
});
|
|
1405
|
+
}, [
|
|
1406
|
+
focusedDate,
|
|
1407
|
+
isControlled,
|
|
1408
|
+
policy,
|
|
1409
|
+
currentMonth,
|
|
1410
|
+
notifyMonth
|
|
1411
|
+
]);
|
|
1412
|
+
const mountedRef = (0, react.useRef)(false);
|
|
1413
|
+
(0, react.useEffect)(() => {
|
|
1414
|
+
if (!mountedRef.current) {
|
|
1415
|
+
mountedRef.current = true;
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
if (isControlled) return;
|
|
1419
|
+
onMonthChangeRef.current?.(viewingYearMonth);
|
|
1420
|
+
}, [viewingYearMonth, isControlled]);
|
|
1421
|
+
const go = (0, react.useCallback)((direction) => {
|
|
1422
|
+
if (isControlled) {
|
|
1423
|
+
const step = policy.step(month, direction);
|
|
1424
|
+
if (step.blocked) return;
|
|
1425
|
+
const nextFocus = focusedDateForMonth(focusedDate, step.start, step.firstDay);
|
|
1426
|
+
skipFocusSyncForRef.current = nextFocus;
|
|
1427
|
+
notifyMonth(step.start);
|
|
1428
|
+
setFocusedDate(nextFocus);
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
setInternalMonth((m) => {
|
|
1432
|
+
const step = policy.step(m, direction);
|
|
1433
|
+
if (step.blocked) return m;
|
|
1434
|
+
setFocusedDate((prev) => focusedDateForMonth(prev, step.start, step.firstDay));
|
|
1435
|
+
return step.start;
|
|
1436
|
+
});
|
|
1437
|
+
}, [
|
|
1438
|
+
isControlled,
|
|
1439
|
+
month,
|
|
1440
|
+
policy,
|
|
1441
|
+
notifyMonth,
|
|
1442
|
+
focusedDate,
|
|
1443
|
+
setFocusedDate
|
|
1444
|
+
]);
|
|
1445
|
+
return {
|
|
1446
|
+
currentMonth,
|
|
1447
|
+
viewingYearMonth,
|
|
1448
|
+
goNextMonth: (0, react.useCallback)(() => go("next"), [go]),
|
|
1449
|
+
goPrevMonth: (0, react.useCallback)(() => go("prev"), [go])
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
//#endregion
|
|
1453
|
+
//#region src/month-window.ts
|
|
1454
|
+
const monthIndex = (m) => m.year * 12 + (m.month - 1);
|
|
1455
|
+
/**
|
|
1456
|
+
* Builds the policy for a MonthView window of `numberOfMonths` months.
|
|
1457
|
+
*
|
|
1458
|
+
* `unbounded` never blocks a step: `min`/`max` only gate which days are
|
|
1459
|
+
* selectable, not which months can be viewed. Any other behavior is `stop`,
|
|
1460
|
+
* which blocks a step whose entering month lies beyond the bound's month.
|
|
1461
|
+
*/
|
|
1462
|
+
function createMonthWindowPolicy(input) {
|
|
1463
|
+
const { numberOfMonths, behavior, min, max, T } = input;
|
|
1464
|
+
return {
|
|
1465
|
+
step(start, direction) {
|
|
1466
|
+
const adjacent = computeAdjacentMonth(start, direction, T);
|
|
1467
|
+
const newStart = {
|
|
1468
|
+
year: adjacent.year,
|
|
1469
|
+
month: adjacent.month
|
|
1470
|
+
};
|
|
1471
|
+
const entering = direction === "prev" ? newStart : monthAt(newStart, numberOfMonths - 1);
|
|
1472
|
+
let blocked = false;
|
|
1473
|
+
if (behavior !== "unbounded") {
|
|
1474
|
+
const bound = direction === "prev" ? min : max;
|
|
1475
|
+
if (bound) {
|
|
1476
|
+
const diff = monthIndex(entering) - monthIndex(bound);
|
|
1477
|
+
blocked = direction === "prev" ? diff < 0 : diff > 0;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
start: newStart,
|
|
1482
|
+
entering,
|
|
1483
|
+
firstDay: adjacent.firstDay,
|
|
1484
|
+
blocked
|
|
1485
|
+
};
|
|
1486
|
+
},
|
|
1487
|
+
isVisible(start, target) {
|
|
1488
|
+
const offset = monthIndex(target) - monthIndex(start);
|
|
1489
|
+
return offset >= 0 && offset < numberOfMonths;
|
|
1490
|
+
},
|
|
1491
|
+
reveal(start, target) {
|
|
1492
|
+
return shiftWindowToMonth(start, target, numberOfMonths);
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
function monthAt(start, offset) {
|
|
1497
|
+
const index = monthIndex(start) + offset;
|
|
1498
|
+
return {
|
|
1499
|
+
year: Math.floor(index / 12),
|
|
1500
|
+
month: index % 12 + 1
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
//#endregion
|
|
1319
1504
|
//#region src/view-context.ts
|
|
1320
1505
|
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1321
1506
|
const ViewContext = (0, react.createContext)(null);
|
|
@@ -1352,40 +1537,39 @@ function MonthViewRoot(props) {
|
|
|
1352
1537
|
const calStable = useCalendarStable();
|
|
1353
1538
|
const calState = useCalendarState();
|
|
1354
1539
|
const T = calStable.temporal;
|
|
1355
|
-
const { timeZone, weekStartDay, isDateDisabled } = calStable;
|
|
1356
|
-
const
|
|
1357
|
-
const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
|
|
1358
|
-
if (monthProp) return {
|
|
1359
|
-
year: monthProp.year,
|
|
1360
|
-
month: monthProp.month
|
|
1361
|
-
};
|
|
1362
|
-
if (defaultMonthProp) return {
|
|
1363
|
-
year: defaultMonthProp.year,
|
|
1364
|
-
month: defaultMonthProp.month
|
|
1365
|
-
};
|
|
1366
|
-
if (calState.selected) {
|
|
1367
|
-
const zdt = toZonedDateTime(calState.selected, timeZone, T);
|
|
1368
|
-
return {
|
|
1369
|
-
year: zdt.year,
|
|
1370
|
-
month: zdt.month
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
|
-
const now = T.Now.zonedDateTimeISO(timeZone);
|
|
1374
|
-
return {
|
|
1375
|
-
year: now.year,
|
|
1376
|
-
month: now.month
|
|
1377
|
-
};
|
|
1378
|
-
});
|
|
1379
|
-
const currentMonth = isMonthControlled ? {
|
|
1380
|
-
year: monthProp.year,
|
|
1381
|
-
month: monthProp.month
|
|
1382
|
-
} : internalMonth;
|
|
1383
|
-
const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
|
|
1384
|
-
if (calState.selected) return toZonedDateTime(calState.selected, timeZone, T).toPlainDate();
|
|
1385
|
-
return T.Now.plainDateISO();
|
|
1386
|
-
});
|
|
1540
|
+
const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
|
|
1541
|
+
const [focusedDate, setFocusedDate] = (0, react.useState)(() => resolveInitialAnchor(calState.selected, today, timeZone, T));
|
|
1387
1542
|
const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
|
|
1388
1543
|
const gridFocusedRef = (0, react.useRef)(false);
|
|
1544
|
+
const { minValue, maxValue } = calStable;
|
|
1545
|
+
const windowPolicy = (0, react.useMemo)(() => createMonthWindowPolicy({
|
|
1546
|
+
numberOfMonths,
|
|
1547
|
+
behavior: outOfRangeBehavior,
|
|
1548
|
+
min: minValue,
|
|
1549
|
+
max: maxValue,
|
|
1550
|
+
T
|
|
1551
|
+
}), [
|
|
1552
|
+
numberOfMonths,
|
|
1553
|
+
outOfRangeBehavior,
|
|
1554
|
+
minValue,
|
|
1555
|
+
maxValue,
|
|
1556
|
+
T
|
|
1557
|
+
]);
|
|
1558
|
+
const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
|
|
1559
|
+
month: monthProp,
|
|
1560
|
+
defaultMonth: defaultMonthProp,
|
|
1561
|
+
initialAnchor: (0, react.useCallback)(() => resolveInitialAnchor(calState.selected, today, timeZone, T), [
|
|
1562
|
+
calState.selected,
|
|
1563
|
+
today,
|
|
1564
|
+
timeZone,
|
|
1565
|
+
T
|
|
1566
|
+
]),
|
|
1567
|
+
onMonthChange,
|
|
1568
|
+
policy: windowPolicy,
|
|
1569
|
+
focusedDate,
|
|
1570
|
+
setFocusedDate,
|
|
1571
|
+
T
|
|
1572
|
+
});
|
|
1389
1573
|
const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
|
|
1390
1574
|
const setGridLabelId = (0, react.useCallback)((monthIndex, id) => {
|
|
1391
1575
|
setGridLabelIds((prev) => {
|
|
@@ -1402,140 +1586,6 @@ function MonthViewRoot(props) {
|
|
|
1402
1586
|
};
|
|
1403
1587
|
});
|
|
1404
1588
|
}, []);
|
|
1405
|
-
const onMonthChangeRef = (0, react.useRef)(onMonthChange);
|
|
1406
|
-
onMonthChangeRef.current = onMonthChange;
|
|
1407
|
-
const notifyMonth = (0, react.useCallback)((year, month) => {
|
|
1408
|
-
onMonthChangeRef.current?.(T.PlainYearMonth.from({
|
|
1409
|
-
year,
|
|
1410
|
-
month
|
|
1411
|
-
}));
|
|
1412
|
-
}, [T]);
|
|
1413
|
-
const isMonthVisible = (0, react.useCallback)((targetYear, targetMonth) => {
|
|
1414
|
-
for (let i = 0; i < numberOfMonths; i++) {
|
|
1415
|
-
const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
|
|
1416
|
-
const y = Math.floor(totalMonths / 12);
|
|
1417
|
-
const m = totalMonths % 12 + 1;
|
|
1418
|
-
if (targetYear === y && targetMonth === m) return true;
|
|
1419
|
-
}
|
|
1420
|
-
return false;
|
|
1421
|
-
}, [
|
|
1422
|
-
currentMonth.year,
|
|
1423
|
-
currentMonth.month,
|
|
1424
|
-
numberOfMonths
|
|
1425
|
-
]);
|
|
1426
|
-
const navigateToMonth = (0, react.useCallback)((targetYear, targetMonth) => {
|
|
1427
|
-
if (isMonthControlled) return;
|
|
1428
|
-
setInternalMonth((prev) => {
|
|
1429
|
-
const next = shiftWindowToMonth(prev, {
|
|
1430
|
-
year: targetYear,
|
|
1431
|
-
month: targetMonth
|
|
1432
|
-
}, numberOfMonths);
|
|
1433
|
-
if (next.year === prev.year && next.month === prev.month) return prev;
|
|
1434
|
-
return next;
|
|
1435
|
-
});
|
|
1436
|
-
}, [isMonthControlled, numberOfMonths]);
|
|
1437
|
-
const skipFocusSyncForRef = (0, react.useRef)(null);
|
|
1438
|
-
const prevFocusedRef = (0, react.useRef)(focusedDate);
|
|
1439
|
-
(0, react.useEffect)(() => {
|
|
1440
|
-
skipFocusSyncForRef.current = null;
|
|
1441
|
-
}, [monthProp?.year, monthProp?.month]);
|
|
1442
|
-
(0, react.useEffect)(() => {
|
|
1443
|
-
const prevFocused = prevFocusedRef.current;
|
|
1444
|
-
prevFocusedRef.current = focusedDate;
|
|
1445
|
-
if (isMonthControlled) {
|
|
1446
|
-
if (skipFocusSyncForRef.current === focusedDate) {
|
|
1447
|
-
skipFocusSyncForRef.current = null;
|
|
1448
|
-
return;
|
|
1449
|
-
}
|
|
1450
|
-
if (prevFocused === focusedDate) return;
|
|
1451
|
-
if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
|
|
1452
|
-
const next = shiftWindowToMonth({
|
|
1453
|
-
year: currentMonth.year,
|
|
1454
|
-
month: currentMonth.month
|
|
1455
|
-
}, {
|
|
1456
|
-
year: focusedDate.year,
|
|
1457
|
-
month: focusedDate.month
|
|
1458
|
-
}, numberOfMonths);
|
|
1459
|
-
notifyMonth(next.year, next.month);
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
navigateToMonth(focusedDate.year, focusedDate.month);
|
|
1463
|
-
}, [
|
|
1464
|
-
focusedDate,
|
|
1465
|
-
navigateToMonth,
|
|
1466
|
-
isMonthControlled,
|
|
1467
|
-
isMonthVisible,
|
|
1468
|
-
notifyMonth,
|
|
1469
|
-
currentMonth.year,
|
|
1470
|
-
currentMonth.month,
|
|
1471
|
-
numberOfMonths
|
|
1472
|
-
]);
|
|
1473
|
-
const goNextMonth = (0, react.useCallback)(() => {
|
|
1474
|
-
if (isMonthControlled) {
|
|
1475
|
-
const { year, month, firstDay } = computeAdjacentMonth({
|
|
1476
|
-
year: monthProp.year,
|
|
1477
|
-
month: monthProp.month
|
|
1478
|
-
}, "next", T);
|
|
1479
|
-
const nextFocus = focusedDateForMonth(focusedDate, {
|
|
1480
|
-
year,
|
|
1481
|
-
month
|
|
1482
|
-
}, firstDay);
|
|
1483
|
-
skipFocusSyncForRef.current = nextFocus;
|
|
1484
|
-
notifyMonth(year, month);
|
|
1485
|
-
setFocusedDate(nextFocus);
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
setInternalMonth((m) => {
|
|
1489
|
-
const { year, month, firstDay } = computeAdjacentMonth(m, "next", T);
|
|
1490
|
-
setFocusedDate((prev) => focusedDateForMonth(prev, {
|
|
1491
|
-
year,
|
|
1492
|
-
month
|
|
1493
|
-
}, firstDay));
|
|
1494
|
-
return {
|
|
1495
|
-
year,
|
|
1496
|
-
month
|
|
1497
|
-
};
|
|
1498
|
-
});
|
|
1499
|
-
}, [
|
|
1500
|
-
T,
|
|
1501
|
-
isMonthControlled,
|
|
1502
|
-
monthProp,
|
|
1503
|
-
notifyMonth,
|
|
1504
|
-
focusedDate
|
|
1505
|
-
]);
|
|
1506
|
-
const goPrevMonth = (0, react.useCallback)(() => {
|
|
1507
|
-
if (isMonthControlled) {
|
|
1508
|
-
const { year, month, firstDay } = computeAdjacentMonth({
|
|
1509
|
-
year: monthProp.year,
|
|
1510
|
-
month: monthProp.month
|
|
1511
|
-
}, "prev", T);
|
|
1512
|
-
const nextFocus = focusedDateForMonth(focusedDate, {
|
|
1513
|
-
year,
|
|
1514
|
-
month
|
|
1515
|
-
}, firstDay);
|
|
1516
|
-
skipFocusSyncForRef.current = nextFocus;
|
|
1517
|
-
notifyMonth(year, month);
|
|
1518
|
-
setFocusedDate(nextFocus);
|
|
1519
|
-
return;
|
|
1520
|
-
}
|
|
1521
|
-
setInternalMonth((m) => {
|
|
1522
|
-
const { year, month, firstDay } = computeAdjacentMonth(m, "prev", T);
|
|
1523
|
-
setFocusedDate((prev) => focusedDateForMonth(prev, {
|
|
1524
|
-
year,
|
|
1525
|
-
month
|
|
1526
|
-
}, firstDay));
|
|
1527
|
-
return {
|
|
1528
|
-
year,
|
|
1529
|
-
month
|
|
1530
|
-
};
|
|
1531
|
-
});
|
|
1532
|
-
}, [
|
|
1533
|
-
T,
|
|
1534
|
-
isMonthControlled,
|
|
1535
|
-
monthProp,
|
|
1536
|
-
notifyMonth,
|
|
1537
|
-
focusedDate
|
|
1538
|
-
]);
|
|
1539
1589
|
const allMonths = (0, react.useMemo)(() => {
|
|
1540
1590
|
const opts = {
|
|
1541
1591
|
weekStartDay,
|
|
@@ -1595,19 +1645,6 @@ function MonthViewRoot(props) {
|
|
|
1595
1645
|
T,
|
|
1596
1646
|
gridHasFocus
|
|
1597
1647
|
]);
|
|
1598
|
-
const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
|
|
1599
|
-
year: currentMonth.year,
|
|
1600
|
-
month: currentMonth.month
|
|
1601
|
-
}), [currentMonth, T]);
|
|
1602
|
-
const mountedRef = (0, react.useRef)(false);
|
|
1603
|
-
(0, react.useEffect)(() => {
|
|
1604
|
-
if (!mountedRef.current) {
|
|
1605
|
-
mountedRef.current = true;
|
|
1606
|
-
return;
|
|
1607
|
-
}
|
|
1608
|
-
if (isMonthControlled) return;
|
|
1609
|
-
onMonthChangeRef.current?.(viewingYearMonth);
|
|
1610
|
-
}, [viewingYearMonth, isMonthControlled]);
|
|
1611
1648
|
const rootState = (0, react.useMemo)(() => ({
|
|
1612
1649
|
...calState.baseRootState,
|
|
1613
1650
|
focused: focusedDate,
|
|
@@ -1622,6 +1659,7 @@ function MonthViewRoot(props) {
|
|
|
1622
1659
|
fixedWeeks,
|
|
1623
1660
|
outsideDays,
|
|
1624
1661
|
outOfRangeBehavior,
|
|
1662
|
+
windowPolicy,
|
|
1625
1663
|
goNextMonth,
|
|
1626
1664
|
goPrevMonth,
|
|
1627
1665
|
setGridLabelId,
|
|
@@ -1631,6 +1669,7 @@ function MonthViewRoot(props) {
|
|
|
1631
1669
|
fixedWeeks,
|
|
1632
1670
|
outsideDays,
|
|
1633
1671
|
outOfRangeBehavior,
|
|
1672
|
+
windowPolicy,
|
|
1634
1673
|
goNextMonth,
|
|
1635
1674
|
goPrevMonth,
|
|
1636
1675
|
setGridLabelId
|
|
@@ -2275,7 +2314,7 @@ function computeWeeksKeyNav(input) {
|
|
|
2275
2314
|
//#endregion
|
|
2276
2315
|
//#region src/day-cell.tsx
|
|
2277
2316
|
/** Computes derived day cell state from context values. Pure function, no hooks. */
|
|
2278
|
-
function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd) {
|
|
2317
|
+
function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, today, T, selectionMode, outsideDays, previewStart, previewEnd) {
|
|
2279
2318
|
const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
|
|
2280
2319
|
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
2281
2320
|
root: rootState,
|
|
@@ -2306,7 +2345,6 @@ function computeDayCellState(date, orientation, columnIndex, rootState, selected
|
|
|
2306
2345
|
rangePreviewHasEnd: false,
|
|
2307
2346
|
isTabTarget: false
|
|
2308
2347
|
};
|
|
2309
|
-
const today = T.Now.plainDateISO();
|
|
2310
2348
|
const isToday = T.PlainDate.compare(date, today) === 0;
|
|
2311
2349
|
const isRange = selectionMode === "range";
|
|
2312
2350
|
let isRangeStart = false;
|
|
@@ -2500,7 +2538,8 @@ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsA
|
|
|
2500
2538
|
function DayCellTemplate(props) {
|
|
2501
2539
|
const { date: dateProp, ...restProps } = props;
|
|
2502
2540
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2503
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
|
|
2541
|
+
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2542
|
+
const todayDate = today();
|
|
2504
2543
|
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2505
2544
|
const viewCtx = useViewContext();
|
|
2506
2545
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
@@ -2515,7 +2554,7 @@ function DayCellTemplate(props) {
|
|
|
2515
2554
|
const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
|
|
2516
2555
|
year: dateProp.year,
|
|
2517
2556
|
month: dateProp.month
|
|
2518
|
-
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2557
|
+
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2519
2558
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2520
2559
|
...restProps,
|
|
2521
2560
|
date: dateProp,
|
|
@@ -2529,7 +2568,7 @@ function DayCellTemplate(props) {
|
|
|
2529
2568
|
const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
|
|
2530
2569
|
year: day.year,
|
|
2531
2570
|
month: day.month
|
|
2532
|
-
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2571
|
+
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2533
2572
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2534
2573
|
...restProps,
|
|
2535
2574
|
date: day,
|
|
@@ -2622,7 +2661,8 @@ function DayButtonFallbackFn(props, ref) {
|
|
|
2622
2661
|
const { date, ...restProps } = props;
|
|
2623
2662
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
2624
2663
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2625
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
|
|
2664
|
+
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2665
|
+
const todayDate = today();
|
|
2626
2666
|
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2627
2667
|
const viewCtx = useViewContext();
|
|
2628
2668
|
const { focusedDate, tabTargetDate } = viewCtx;
|
|
@@ -2633,7 +2673,7 @@ function DayButtonFallbackFn(props, ref) {
|
|
|
2633
2673
|
month: date.month
|
|
2634
2674
|
} : weekData?.gridMonth ?? currentDateTime;
|
|
2635
2675
|
const daysInWeek = date.daysInWeek;
|
|
2636
|
-
const derived = computeDayCellState(date, orientation, (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2676
|
+
const derived = computeDayCellState(date, orientation, (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2637
2677
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
|
|
2638
2678
|
...restProps,
|
|
2639
2679
|
ref,
|
|
@@ -3189,37 +3229,16 @@ function MonthYearStringFn(props, ref) {
|
|
|
3189
3229
|
*/
|
|
3190
3230
|
const MonthYearString = (0, react.forwardRef)(MonthYearStringFn);
|
|
3191
3231
|
function useNavButton(direction) {
|
|
3192
|
-
const { disabled: globalDisabled,
|
|
3193
|
-
const
|
|
3194
|
-
const
|
|
3195
|
-
const
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
|
|
3199
|
-
const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
|
|
3200
|
-
const boundValue = direction === "prev" ? minValue : maxValue;
|
|
3201
|
-
const isDisabled = (0, react.useMemo)(() => {
|
|
3202
|
-
if (globalDisabled) return true;
|
|
3203
|
-
if (outOfRangeBehavior === "unbounded") return false;
|
|
3204
|
-
if (!boundValue) return false;
|
|
3205
|
-
if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
|
|
3206
|
-
return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
|
|
3207
|
-
}, [
|
|
3208
|
-
globalDisabled,
|
|
3209
|
-
outOfRangeBehavior,
|
|
3210
|
-
destYear,
|
|
3211
|
-
destMonth,
|
|
3212
|
-
boundValue,
|
|
3232
|
+
const { disabled: globalDisabled, temporal: T } = useCalendarStable();
|
|
3233
|
+
const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, windowPolicy } = useMonthViewStable();
|
|
3234
|
+
const { currentMonth, rootState } = useMonthViewState();
|
|
3235
|
+
const step = (0, react.useMemo)(() => windowPolicy.step(currentMonth, direction), [
|
|
3236
|
+
windowPolicy,
|
|
3237
|
+
currentMonth,
|
|
3213
3238
|
direction
|
|
3214
3239
|
]);
|
|
3215
|
-
const
|
|
3216
|
-
|
|
3217
|
-
month: destMonth
|
|
3218
|
-
}), [
|
|
3219
|
-
destYear,
|
|
3220
|
-
destMonth,
|
|
3221
|
-
T
|
|
3222
|
-
]);
|
|
3240
|
+
const isDisabled = globalDisabled || step.blocked;
|
|
3241
|
+
const target = (0, react.useMemo)(() => T.PlainYearMonth.from(step.entering), [step.entering, T]);
|
|
3223
3242
|
return {
|
|
3224
3243
|
state: (0, react.useMemo)(() => ({
|
|
3225
3244
|
root: rootState,
|
|
@@ -3862,14 +3881,13 @@ function useWeeksViewRootState(props) {
|
|
|
3862
3881
|
const calStable = useCalendarStable();
|
|
3863
3882
|
const calState = useCalendarState();
|
|
3864
3883
|
const T = calStable.temporal;
|
|
3865
|
-
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } = calStable;
|
|
3884
|
+
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone, today } = calStable;
|
|
3866
3885
|
const isControlled = firstWeekProp !== void 0;
|
|
3867
3886
|
const resolveSpec = (0, react.useCallback)((spec) => resolveFirstWeekSpec(spec, weekStartDay, T), [weekStartDay, T]);
|
|
3868
3887
|
const [internalFirstWeek, setInternalFirstWeek] = (0, react.useState)(() => {
|
|
3869
3888
|
if (firstWeekProp !== void 0) return resolveSpec(firstWeekProp);
|
|
3870
3889
|
if (defaultFirstWeekProp !== void 0) return resolveSpec(defaultFirstWeekProp);
|
|
3871
|
-
|
|
3872
|
-
return resolveSpec(T.Now.plainDateISO());
|
|
3890
|
+
return resolveSpec(resolveInitialAnchor(calState.selected, today, timeZone, T));
|
|
3873
3891
|
});
|
|
3874
3892
|
const resolvedFirstWeek = isControlled ? resolveSpec(firstWeekProp) : internalFirstWeek;
|
|
3875
3893
|
const rawWeeks = (0, react.useMemo)(() => computeWeeksInWindow(resolvedFirstWeek, weekCount, weekStartDay, T), [
|
|
@@ -3924,10 +3942,10 @@ function useWeeksViewRootState(props) {
|
|
|
3924
3942
|
const firstWeek = weeks[0];
|
|
3925
3943
|
const lastWeek = weeks[weeks.length - 1];
|
|
3926
3944
|
if (firstWeek === void 0 || lastWeek === void 0) {
|
|
3927
|
-
const
|
|
3945
|
+
const now = today();
|
|
3928
3946
|
return {
|
|
3929
|
-
windowStart:
|
|
3930
|
-
windowEnd:
|
|
3947
|
+
windowStart: now,
|
|
3948
|
+
windowEnd: now,
|
|
3931
3949
|
weekCount: 0,
|
|
3932
3950
|
dayCount: 0,
|
|
3933
3951
|
enabledWeekCount: 0,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
3
1
|
import * as _$react from "react";
|
|
4
2
|
import React$1 from "react";
|
|
3
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
5
5
|
|
|
6
6
|
//#region ../node_modules/.pnpm/@js-temporal+polyfill@0.5.1/node_modules/@js-temporal/polyfill/index.d.ts
|
|
7
7
|
declare namespace Temporal {
|
|
@@ -1505,6 +1505,8 @@ interface CalendarStableContextValue {
|
|
|
1505
1505
|
maxValue?: Temporal.PlainDate;
|
|
1506
1506
|
/** Resolved IANA time zone. */
|
|
1507
1507
|
timeZone: string;
|
|
1508
|
+
/** Today's date in the resolved {@link timeZone}. Reads the clock on every call. */
|
|
1509
|
+
today: () => Temporal.PlainDate;
|
|
1508
1510
|
/** Resolved BCP 47 locale. */
|
|
1509
1511
|
locale: string;
|
|
1510
1512
|
/** Resolved Temporal namespace. */
|
|
@@ -1594,6 +1596,33 @@ type OutOfRangeBehavior = "unbounded" | "stop" | "stop-shrink" | "snap" | "snap-
|
|
|
1594
1596
|
*/
|
|
1595
1597
|
type MonthOutOfRangeBehavior = "unbounded" | "stop";
|
|
1596
1598
|
//#endregion
|
|
1599
|
+
//#region src/month-window.d.ts
|
|
1600
|
+
/** An ISO year + month. */
|
|
1601
|
+
interface MonthRef {
|
|
1602
|
+
year: number;
|
|
1603
|
+
month: number;
|
|
1604
|
+
}
|
|
1605
|
+
/** One step of the visible month window. */
|
|
1606
|
+
interface MonthStep {
|
|
1607
|
+
/** The window's first month after the step. */
|
|
1608
|
+
start: MonthRef;
|
|
1609
|
+
/** The month that enters view (before the window for `prev`, after it for `next`). */
|
|
1610
|
+
entering: MonthRef;
|
|
1611
|
+
/** First day of `start`, the focus target when focus isn't already in `start`. */
|
|
1612
|
+
firstDay: Temporal.PlainDate;
|
|
1613
|
+
/** Whether `stop` forbids the step because `entering` lies beyond `min`/`max`. */
|
|
1614
|
+
blocked: boolean;
|
|
1615
|
+
}
|
|
1616
|
+
/** The one seam for moving the MonthView window. */
|
|
1617
|
+
interface MonthWindowPolicy {
|
|
1618
|
+
/** Steps the window one month towards `direction`. */
|
|
1619
|
+
step(start: MonthRef, direction: "prev" | "next"): MonthStep;
|
|
1620
|
+
/** Whether `target` is inside the window starting at `start`. */
|
|
1621
|
+
isVisible(start: MonthRef, target: MonthRef): boolean;
|
|
1622
|
+
/** The window start that reveals `target` with the smallest shift. */
|
|
1623
|
+
reveal(start: MonthRef, target: MonthRef): MonthRef;
|
|
1624
|
+
}
|
|
1625
|
+
//#endregion
|
|
1597
1626
|
//#region src/month-view-types.d.ts
|
|
1598
1627
|
/** Props accepted by `MonthView.Root`. */
|
|
1599
1628
|
interface MonthViewRootProps {
|
|
@@ -1655,6 +1684,8 @@ interface MonthViewStableContextValue {
|
|
|
1655
1684
|
outsideDays: OutsideDays;
|
|
1656
1685
|
/** How month navigation behaves at bounds. */
|
|
1657
1686
|
outOfRangeBehavior: MonthOutOfRangeBehavior;
|
|
1687
|
+
/** Steps and reveals the visible month window. */
|
|
1688
|
+
windowPolicy: MonthWindowPolicy;
|
|
1658
1689
|
/** Navigate to the next month(s). */
|
|
1659
1690
|
goNextMonth: () => void;
|
|
1660
1691
|
/** Navigate to the previous month(s). */
|