@klinking/colander 3.1.0-alpha.5 → 3.1.0-alpha.6
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/{weeks-view-context-BLZZm1fq.d.mts → index-DnFCKyyw.d.cts} +44 -10
- package/dist/{weeks-view-context-CkTcdZpj.d.cts → index-q3cQKJdA.d.mts} +44 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -11
- package/dist/index.d.mts +2 -11
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-CEV8w_69.mjs → weeks-navigation-Dn3UtG76.mjs} +364 -389
- package/dist/{weeks-navigation-q3beZn2n.cjs → weeks-navigation-SuKJZJCM.cjs} +364 -389
- package/package.json +1 -1
- package/src/calendar-provider.tsx +10 -55
- package/src/day-cell-state.test.ts +214 -0
- package/src/day-cell-state.ts +314 -0
- package/src/day-cell.tsx +29 -383
- package/src/range-preview.test.ts +120 -0
- package/src/root-selection.ts +99 -97
- package/src/weeks-navigation.tsx +7 -32
- package/src/weeks-view-state.ts +24 -81
- package/src/weeks-view-types.ts +4 -1
- package/src/weeks-window.test.ts +43 -0
- package/src/weeks-window.ts +64 -0
|
@@ -508,6 +508,18 @@ function tagRaw(raw, format) {
|
|
|
508
508
|
value: raw
|
|
509
509
|
};
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Decodes a range value into committed dates. An empty range is `[]`; a range
|
|
513
|
+
* with only an end is `[end, null]` (pending start, so the end is still the
|
|
514
|
+
* anchor of the next click).
|
|
515
|
+
*/
|
|
516
|
+
function decodeRange(range, toPlain) {
|
|
517
|
+
const start = range.start != null ? toPlain(range.start) : null;
|
|
518
|
+
const end = range.end != null ? toPlain(range.end) : null;
|
|
519
|
+
if (start === null && end === null) return [];
|
|
520
|
+
if (start === null && end !== null) return [end, null];
|
|
521
|
+
return [start, end];
|
|
522
|
+
}
|
|
511
523
|
/** Resolve a `RangeMode` to a concrete "start" | "end" | "reset" action for inside-range clicks. */
|
|
512
524
|
function resolveInsideAction(mode, date, start, end) {
|
|
513
525
|
if (mode === "adjust-start") return "start";
|
|
@@ -786,23 +798,19 @@ function truncateDatesForMode(opts) {
|
|
|
786
798
|
return clamped;
|
|
787
799
|
}
|
|
788
800
|
/**
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
801
|
+
* The range a click on `hoveredDate` would produce, or `null` when the click
|
|
802
|
+
* would do nothing (read-only, disabled date). One path for both the
|
|
803
|
+
* provider's own preview and the public {@link computePreviewRange}.
|
|
792
804
|
*/
|
|
793
|
-
function
|
|
794
|
-
const
|
|
795
|
-
if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
|
|
796
|
-
const rawStart = currentRange?.start != null ? Temporal.PlainDate.from(currentRange.start) : null;
|
|
797
|
-
const rawEnd = currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end) : null;
|
|
798
|
-
const committedDates = currentRange ? rawStart === null && rawEnd !== null ? [rawEnd, null] : [rawStart, rawEnd] : [];
|
|
805
|
+
function computeRangePreview(input) {
|
|
806
|
+
const { hoveredDate, committedDates, rangeMode, allowRangeReversal, readOnly, isDateDisabled, T } = input;
|
|
799
807
|
const committedStart = committedDates[0] ?? void 0;
|
|
800
|
-
const committedEnd = committedDates[1] ?? void 0;
|
|
801
|
-
const
|
|
808
|
+
const committedEnd = committedDates.length > 1 ? committedDates[committedDates.length - 1] ?? void 0 : committedStart;
|
|
809
|
+
const unused = () => [];
|
|
802
810
|
const result = computeSelectionUpdate({
|
|
803
811
|
date: hoveredDate,
|
|
804
|
-
readOnly
|
|
805
|
-
isDateDisabled
|
|
812
|
+
readOnly,
|
|
813
|
+
isDateDisabled,
|
|
806
814
|
isMultiple: false,
|
|
807
815
|
isRange: true,
|
|
808
816
|
committedDates,
|
|
@@ -810,20 +818,42 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
|
|
|
810
818
|
committedEnd,
|
|
811
819
|
selectedZdt: void 0,
|
|
812
820
|
rangeMode,
|
|
813
|
-
allowRangeReversal
|
|
814
|
-
sortDates: (d) => [...d].sort((a, b) =>
|
|
815
|
-
currentSingleFormatted:
|
|
816
|
-
currentRangeFormatted:
|
|
817
|
-
currentMultipleFormatted:
|
|
821
|
+
allowRangeReversal,
|
|
822
|
+
sortDates: (d) => [...d].sort((a, b) => T.PlainDate.compare(a, b)),
|
|
823
|
+
currentSingleFormatted: unused,
|
|
824
|
+
currentRangeFormatted: unused,
|
|
825
|
+
currentMultipleFormatted: unused,
|
|
818
826
|
resolvedFormat: "PlainDate",
|
|
819
827
|
timeZone: "UTC",
|
|
820
|
-
T
|
|
828
|
+
T
|
|
821
829
|
});
|
|
822
830
|
if (result.skip || result.newDates.length === 0) return null;
|
|
823
831
|
const start = result.newDates[0];
|
|
824
832
|
const end = result.newDates.length > 1 ? result.newDates[1] : start;
|
|
825
833
|
if (start == null || end == null) return null;
|
|
826
|
-
return
|
|
834
|
+
return [start, end];
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Pure utility that computes the preview range for a hovered date, using the
|
|
838
|
+
* same logic as the built-in hover preview. Useful for deriving the preview in
|
|
839
|
+
* an `onHoveredDateChange` handler without needing a controlled `previewRange`.
|
|
840
|
+
*
|
|
841
|
+
* Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
|
|
842
|
+
* disables dates or is read-only; by default every date is selectable.
|
|
843
|
+
*/
|
|
844
|
+
function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T, options = {}) {
|
|
845
|
+
const Temporal = T ?? globalThis.Temporal;
|
|
846
|
+
if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
|
|
847
|
+
const preview = computeRangePreview({
|
|
848
|
+
hoveredDate,
|
|
849
|
+
committedDates: currentRange ? decodeRange(currentRange, (raw) => Temporal.PlainDate.from(raw)) : [],
|
|
850
|
+
rangeMode,
|
|
851
|
+
allowRangeReversal: !preventRangeReversal,
|
|
852
|
+
readOnly: options.readOnly ?? false,
|
|
853
|
+
isDateDisabled: options.isDateDisabled ?? (() => false),
|
|
854
|
+
T: Temporal
|
|
855
|
+
});
|
|
856
|
+
return preview ? mkRange(preview[0], preview[1]) : null;
|
|
827
857
|
}
|
|
828
858
|
//#endregion
|
|
829
859
|
//#region src/calendar-provider.tsx
|
|
@@ -915,13 +945,7 @@ function CalendarProvider(props) {
|
|
|
915
945
|
}
|
|
916
946
|
if (isRange) {
|
|
917
947
|
if (rangeValue === null) return [];
|
|
918
|
-
if (rangeValue)
|
|
919
|
-
const start = rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
|
|
920
|
-
const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
|
|
921
|
-
if (start === null && end === null) return [];
|
|
922
|
-
if (start === null && end !== null) return [end, null];
|
|
923
|
-
return [start, end];
|
|
924
|
-
}
|
|
948
|
+
if (rangeValue) return decodeRange(rangeValue, rawToPlain);
|
|
925
949
|
return;
|
|
926
950
|
}
|
|
927
951
|
if (singleValue === null) return [];
|
|
@@ -955,13 +979,7 @@ function CalendarProvider(props) {
|
|
|
955
979
|
if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
|
|
956
980
|
return [];
|
|
957
981
|
}
|
|
958
|
-
if (rangeDefault)
|
|
959
|
-
const start = rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
|
|
960
|
-
const end = rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
|
|
961
|
-
if (start === null && end === null) return [];
|
|
962
|
-
if (start === null && end !== null) return [end, null];
|
|
963
|
-
return [start, end];
|
|
964
|
-
}
|
|
982
|
+
if (rangeDefault) return decodeRange(rangeDefault, rawToPlain);
|
|
965
983
|
if (singleDefault != null) return [rawToPlain(singleDefault)];
|
|
966
984
|
return [];
|
|
967
985
|
}, [
|
|
@@ -1047,40 +1065,18 @@ function CalendarProvider(props) {
|
|
|
1047
1065
|
const [previewStart, previewEnd] = (0, react.useMemo)(() => {
|
|
1048
1066
|
if (previewRangeProp !== void 0) {
|
|
1049
1067
|
if (!previewRangeProp) return [void 0, void 0];
|
|
1050
|
-
|
|
1051
|
-
return toZonedDateTime({
|
|
1052
|
-
format: resolvedFormat,
|
|
1053
|
-
value: raw
|
|
1054
|
-
}, timeZone, T).toPlainDate();
|
|
1055
|
-
};
|
|
1056
|
-
return [previewRangeProp.start != null ? rawToPlainLocal(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlainLocal(previewRangeProp.end) : void 0];
|
|
1068
|
+
return [previewRangeProp.start != null ? rawToPlain(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlain(previewRangeProp.end) : void 0];
|
|
1057
1069
|
}
|
|
1058
1070
|
if (!hoveredDate || !isRange) return [void 0, void 0];
|
|
1059
|
-
|
|
1060
|
-
|
|
1071
|
+
return computeRangePreview({
|
|
1072
|
+
hoveredDate,
|
|
1061
1073
|
readOnly,
|
|
1062
1074
|
isDateDisabled,
|
|
1063
|
-
isMultiple: false,
|
|
1064
|
-
isRange: true,
|
|
1065
1075
|
committedDates,
|
|
1066
|
-
committedStart,
|
|
1067
|
-
committedEnd,
|
|
1068
|
-
selectedZdt: void 0,
|
|
1069
1076
|
rangeMode,
|
|
1070
1077
|
allowRangeReversal,
|
|
1071
|
-
sortDates,
|
|
1072
|
-
currentSingleFormatted,
|
|
1073
|
-
currentRangeFormatted,
|
|
1074
|
-
currentMultipleFormatted,
|
|
1075
|
-
resolvedFormat,
|
|
1076
|
-
timeZone,
|
|
1077
1078
|
T
|
|
1078
|
-
});
|
|
1079
|
-
if (result.skip || result.newDates.length === 0) return [void 0, void 0];
|
|
1080
|
-
const ps = result.newDates[0];
|
|
1081
|
-
const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
|
|
1082
|
-
if (ps == null || pe == null) return [void 0, void 0];
|
|
1083
|
-
return [ps, pe];
|
|
1079
|
+
}) ?? [void 0, void 0];
|
|
1084
1080
|
}, [
|
|
1085
1081
|
previewRangeProp,
|
|
1086
1082
|
hoveredDate,
|
|
@@ -1088,16 +1084,9 @@ function CalendarProvider(props) {
|
|
|
1088
1084
|
readOnly,
|
|
1089
1085
|
isDateDisabled,
|
|
1090
1086
|
committedDates,
|
|
1091
|
-
committedStart,
|
|
1092
|
-
committedEnd,
|
|
1093
1087
|
rangeMode,
|
|
1094
1088
|
allowRangeReversal,
|
|
1095
|
-
|
|
1096
|
-
currentSingleFormatted,
|
|
1097
|
-
currentRangeFormatted,
|
|
1098
|
-
currentMultipleFormatted,
|
|
1099
|
-
resolvedFormat,
|
|
1100
|
-
timeZone,
|
|
1089
|
+
rawToPlain,
|
|
1101
1090
|
T
|
|
1102
1091
|
]);
|
|
1103
1092
|
const prevModeRef = (0, react.useRef)(selectionMode);
|
|
@@ -2312,130 +2301,180 @@ function computeWeeksKeyNav(input) {
|
|
|
2312
2301
|
}
|
|
2313
2302
|
}
|
|
2314
2303
|
//#endregion
|
|
2315
|
-
//#region src/day-cell.
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2304
|
+
//#region src/day-cell-state.ts
|
|
2305
|
+
const NO_RANGE = {
|
|
2306
|
+
rangeStart: false,
|
|
2307
|
+
rangeEnd: false,
|
|
2308
|
+
rangeBoundary: false,
|
|
2309
|
+
inRange: false,
|
|
2310
|
+
rangeIndex: false,
|
|
2311
|
+
rangeLength: false,
|
|
2312
|
+
rangeHasStart: false,
|
|
2313
|
+
rangeHasEnd: false,
|
|
2314
|
+
rangePreviewStart: false,
|
|
2315
|
+
rangePreviewEnd: false,
|
|
2316
|
+
rangePreviewBoundary: false,
|
|
2317
|
+
rangePreviewInRange: false,
|
|
2318
|
+
rangePreviewIndex: false,
|
|
2319
|
+
rangePreviewLength: false,
|
|
2320
|
+
rangePreviewHasStart: false,
|
|
2321
|
+
rangePreviewHasEnd: false
|
|
2322
|
+
};
|
|
2323
|
+
function computeRangeState(date, inputs) {
|
|
2324
|
+
const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
|
|
2325
|
+
if (selectionMode !== "range") return NO_RANGE;
|
|
2326
|
+
const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
2327
|
+
const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
2328
|
+
const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
2329
|
+
const effectiveStart = rangeStart ?? rangeEnd;
|
|
2330
|
+
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
2331
|
+
const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
2332
|
+
const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
2333
|
+
const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
2334
|
+
return {
|
|
2335
|
+
rangeStart: isRangeStart,
|
|
2336
|
+
rangeEnd: isRangeEnd,
|
|
2337
|
+
rangeBoundary: isRangeStart || isRangeEnd,
|
|
2338
|
+
inRange,
|
|
2339
|
+
rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
|
|
2340
|
+
rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
|
|
2341
|
+
rangeHasStart: inRange && rangeStart !== void 0,
|
|
2342
|
+
rangeHasEnd: inRange && rangeEnd !== void 0,
|
|
2343
|
+
rangePreviewStart: isPreviewStart,
|
|
2344
|
+
rangePreviewEnd: isPreviewEnd,
|
|
2345
|
+
rangePreviewBoundary: isPreviewStart || isPreviewEnd,
|
|
2346
|
+
rangePreviewInRange: inPreview,
|
|
2347
|
+
rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
|
|
2348
|
+
rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
|
|
2349
|
+
rangePreviewHasStart: inPreview && previewStart !== void 0,
|
|
2350
|
+
rangePreviewHasEnd: inPreview && previewEnd !== void 0
|
|
2351
|
+
};
|
|
2352
|
+
}
|
|
2353
|
+
/** Derives the state of one day cell. Pure function, no hooks. */
|
|
2354
|
+
function computeDayCellState(date, position, inputs) {
|
|
2355
|
+
const { T, outsideDays } = inputs;
|
|
2356
|
+
const { columnIndex, month } = position;
|
|
2357
|
+
const isCurrentMonth = date.year === month.year && date.month === month.month;
|
|
2358
|
+
const base = {
|
|
2359
|
+
root: inputs.rootState,
|
|
2321
2360
|
date,
|
|
2322
2361
|
columnIndex,
|
|
2323
|
-
orientation
|
|
2362
|
+
orientation: inputs.orientation
|
|
2363
|
+
};
|
|
2364
|
+
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
2365
|
+
...base,
|
|
2366
|
+
...NO_RANGE,
|
|
2324
2367
|
outsideMonth: true,
|
|
2325
2368
|
hidden: true,
|
|
2326
2369
|
selected: false,
|
|
2327
2370
|
today: false,
|
|
2328
2371
|
disabled: true,
|
|
2329
2372
|
focused: false,
|
|
2330
|
-
rangeStart: false,
|
|
2331
|
-
rangeEnd: false,
|
|
2332
|
-
rangeBoundary: false,
|
|
2333
|
-
inRange: false,
|
|
2334
|
-
rangeIndex: false,
|
|
2335
|
-
rangeLength: false,
|
|
2336
|
-
rangeHasStart: false,
|
|
2337
|
-
rangeHasEnd: false,
|
|
2338
|
-
rangePreviewStart: false,
|
|
2339
|
-
rangePreviewEnd: false,
|
|
2340
|
-
rangePreviewBoundary: false,
|
|
2341
|
-
rangePreviewInRange: false,
|
|
2342
|
-
rangePreviewIndex: false,
|
|
2343
|
-
rangePreviewLength: false,
|
|
2344
|
-
rangePreviewHasStart: false,
|
|
2345
|
-
rangePreviewHasEnd: false,
|
|
2346
2373
|
isTabTarget: false
|
|
2347
2374
|
};
|
|
2348
|
-
const isToday = T.PlainDate.compare(date, today) === 0;
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
2363
|
-
isInRangeDay = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
2364
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
2365
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
2366
|
-
rangeIdx = isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
|
|
2367
|
-
rangeLen = isInRangeDay && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false;
|
|
2368
|
-
isPreviewRangeStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
2369
|
-
isPreviewRangeEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
2370
|
-
isInPreviewRange = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
2371
|
-
previewIdx = isInPreviewRange && previewStart ? date.since(previewStart).days : false;
|
|
2372
|
-
previewLen = isInPreviewRange && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false;
|
|
2375
|
+
const isToday = T.PlainDate.compare(date, inputs.today) === 0;
|
|
2376
|
+
if (!isCurrentMonth && outsideDays !== "enabled") {
|
|
2377
|
+
const suppressRange = outsideDays === "disabled";
|
|
2378
|
+
return {
|
|
2379
|
+
...base,
|
|
2380
|
+
...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
|
|
2381
|
+
outsideMonth: true,
|
|
2382
|
+
hidden: false,
|
|
2383
|
+
selected: false,
|
|
2384
|
+
today: isToday,
|
|
2385
|
+
disabled: true,
|
|
2386
|
+
focused: false,
|
|
2387
|
+
isTabTarget: false
|
|
2388
|
+
};
|
|
2373
2389
|
}
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
date,
|
|
2379
|
-
columnIndex,
|
|
2380
|
-
orientation,
|
|
2381
|
-
outsideMonth: true,
|
|
2390
|
+
return {
|
|
2391
|
+
...base,
|
|
2392
|
+
...computeRangeState(date, inputs),
|
|
2393
|
+
outsideMonth: !isCurrentMonth,
|
|
2382
2394
|
hidden: false,
|
|
2383
|
-
selected: false,
|
|
2395
|
+
selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
|
|
2384
2396
|
today: isToday,
|
|
2385
|
-
disabled:
|
|
2386
|
-
focused:
|
|
2387
|
-
|
|
2388
|
-
rangeEnd: suppressRange ? false : isRangeEnd,
|
|
2389
|
-
rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
|
|
2390
|
-
inRange: suppressRange ? false : isInRangeDay,
|
|
2391
|
-
rangeIndex: suppressRange ? false : rangeIdx,
|
|
2392
|
-
rangeLength: suppressRange ? false : rangeLen,
|
|
2393
|
-
rangeHasStart: suppressRange ? false : isInRangeDay && rangeStart !== void 0,
|
|
2394
|
-
rangeHasEnd: suppressRange ? false : isInRangeDay && rangeEnd !== void 0,
|
|
2395
|
-
rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
|
|
2396
|
-
rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
|
|
2397
|
-
rangePreviewBoundary: suppressRange ? false : isPreviewRangeStart || isPreviewRangeEnd,
|
|
2398
|
-
rangePreviewInRange: suppressRange ? false : isInPreviewRange,
|
|
2399
|
-
rangePreviewIndex: suppressRange ? false : previewIdx,
|
|
2400
|
-
rangePreviewLength: suppressRange ? false : previewLen,
|
|
2401
|
-
rangePreviewHasStart: suppressRange ? false : isInPreviewRange && previewStart !== void 0,
|
|
2402
|
-
rangePreviewHasEnd: suppressRange ? false : isInPreviewRange && previewEnd !== void 0,
|
|
2403
|
-
isTabTarget: false
|
|
2397
|
+
disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
|
|
2398
|
+
focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
|
|
2399
|
+
isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
|
|
2404
2400
|
};
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2401
|
+
}
|
|
2402
|
+
const COMPARED_KEYS = Object.keys({
|
|
2403
|
+
outsideMonth: true,
|
|
2404
|
+
hidden: true,
|
|
2405
|
+
selected: true,
|
|
2406
|
+
today: true,
|
|
2407
|
+
disabled: true,
|
|
2408
|
+
focused: true,
|
|
2409
|
+
rangeStart: true,
|
|
2410
|
+
rangeEnd: true,
|
|
2411
|
+
rangeBoundary: true,
|
|
2412
|
+
inRange: true,
|
|
2413
|
+
rangeIndex: true,
|
|
2414
|
+
rangeLength: true,
|
|
2415
|
+
rangeHasStart: true,
|
|
2416
|
+
rangeHasEnd: true,
|
|
2417
|
+
rangePreviewStart: true,
|
|
2418
|
+
rangePreviewEnd: true,
|
|
2419
|
+
rangePreviewBoundary: true,
|
|
2420
|
+
rangePreviewInRange: true,
|
|
2421
|
+
rangePreviewIndex: true,
|
|
2422
|
+
rangePreviewLength: true,
|
|
2423
|
+
rangePreviewHasStart: true,
|
|
2424
|
+
rangePreviewHasEnd: true,
|
|
2425
|
+
isTabTarget: true
|
|
2426
|
+
});
|
|
2427
|
+
/** Whether two cell states render the same cell. */
|
|
2428
|
+
function dayCellStateEqual(a, b) {
|
|
2429
|
+
for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
|
|
2430
|
+
return true;
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* Reads the contexts a day cell depends on and returns a function that derives
|
|
2434
|
+
* the state of any cell. `columnIndex` defaults to the date's column in a
|
|
2435
|
+
* week starting on the calendar's `weekStartDay`.
|
|
2436
|
+
*/
|
|
2437
|
+
function useDayCellDeriver() {
|
|
2438
|
+
const { orientation } = (0, react.useContext)(GridContext);
|
|
2439
|
+
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2440
|
+
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2441
|
+
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2442
|
+
const viewCtx = useViewContext();
|
|
2443
|
+
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2444
|
+
const { rootState, currentDateTime } = useViewState();
|
|
2445
|
+
const { outsideDays } = useViewStable();
|
|
2446
|
+
const inputs = {
|
|
2447
|
+
T,
|
|
2448
|
+
today: today(),
|
|
2413
2449
|
orientation,
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2450
|
+
rootState,
|
|
2451
|
+
selectionMode,
|
|
2452
|
+
selectedDates,
|
|
2453
|
+
rangeStart,
|
|
2454
|
+
rangeEnd,
|
|
2455
|
+
previewStart,
|
|
2456
|
+
previewEnd,
|
|
2457
|
+
disabled,
|
|
2458
|
+
isDateDisabled,
|
|
2459
|
+
focusedDate,
|
|
2460
|
+
tabTargetDate,
|
|
2461
|
+
outsideDays
|
|
2462
|
+
};
|
|
2463
|
+
const isWeeksView = viewCtx.viewType === "weeks";
|
|
2464
|
+
const gridMonth = weekData?.gridMonth ?? currentDateTime;
|
|
2465
|
+
return (date, columnIndex) => {
|
|
2466
|
+
const daysInWeek = date.daysInWeek;
|
|
2467
|
+
return computeDayCellState(date, {
|
|
2468
|
+
columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek,
|
|
2469
|
+
month: isWeeksView ? {
|
|
2470
|
+
year: date.year,
|
|
2471
|
+
month: date.month
|
|
2472
|
+
} : gridMonth
|
|
2473
|
+
}, inputs);
|
|
2437
2474
|
};
|
|
2438
2475
|
}
|
|
2476
|
+
//#endregion
|
|
2477
|
+
//#region src/day-cell.tsx
|
|
2439
2478
|
const dayStateAttributesMapping = {
|
|
2440
2479
|
root: () => null,
|
|
2441
2480
|
date: (v) => v ? { "data-date": v.toString() } : null,
|
|
@@ -2522,9 +2561,7 @@ const DAY_BUTTON_HANDLED_KEYS = new Set([
|
|
|
2522
2561
|
]);
|
|
2523
2562
|
function dayCellInstancePropsAreEqual(prev, next) {
|
|
2524
2563
|
if (prev.date !== next.date || prev.render !== next.render || prev.columnIndex !== next.columnIndex) return false;
|
|
2525
|
-
|
|
2526
|
-
const b = next._derivedState;
|
|
2527
|
-
return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2564
|
+
return dayCellStateEqual(prev._derivedState, next._derivedState) && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2528
2565
|
}
|
|
2529
2566
|
const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
2530
2567
|
/**
|
|
@@ -2538,44 +2575,21 @@ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsA
|
|
|
2538
2575
|
function DayCellTemplate(props) {
|
|
2539
2576
|
const { date: dateProp, ...restProps } = props;
|
|
2540
2577
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2541
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2542
|
-
const todayDate = today();
|
|
2543
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2544
|
-
const viewCtx = useViewContext();
|
|
2545
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2546
|
-
const { rootState, currentDateTime } = useViewState();
|
|
2547
|
-
const { outsideDays } = useViewStable();
|
|
2548
2578
|
const monthState = (0, react.useContext)(MonthViewStateContext);
|
|
2549
|
-
const
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
year: dateProp.year,
|
|
2556
|
-
month: dateProp.month
|
|
2557
|
-
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, todayDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2558
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2559
|
-
...restProps,
|
|
2560
|
-
date: dateProp,
|
|
2561
|
-
_derivedState: derived
|
|
2562
|
-
});
|
|
2563
|
-
}
|
|
2579
|
+
const derive = useDayCellDeriver();
|
|
2580
|
+
if (dateProp) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2581
|
+
...restProps,
|
|
2582
|
+
date: dateProp,
|
|
2583
|
+
_derivedState: derive(dateProp)
|
|
2584
|
+
});
|
|
2564
2585
|
const days = weekData ? weekData.days : monthState?.weeks.flat() ?? [];
|
|
2565
2586
|
const perWeek = weekData != null;
|
|
2566
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2573
|
-
...restProps,
|
|
2574
|
-
date: day,
|
|
2575
|
-
columnIndex: perWeek ? i : void 0,
|
|
2576
|
-
_derivedState: derived
|
|
2577
|
-
}, day.toString());
|
|
2578
|
-
}) });
|
|
2587
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2588
|
+
...restProps,
|
|
2589
|
+
date: day,
|
|
2590
|
+
columnIndex: perWeek ? i : void 0,
|
|
2591
|
+
_derivedState: derive(day, perWeek ? i : void 0)
|
|
2592
|
+
}, day.toString())) });
|
|
2579
2593
|
}
|
|
2580
2594
|
function DayButtonInnerFn(props, ref) {
|
|
2581
2595
|
const { render, date, _derivedState, ...otherProps } = props;
|
|
@@ -2627,7 +2641,7 @@ function dayButtonInnerPropsAreEqual(prev, next) {
|
|
|
2627
2641
|
const a = prev._derivedState;
|
|
2628
2642
|
const b = next._derivedState;
|
|
2629
2643
|
if (!a || !b) return a === b;
|
|
2630
|
-
return a
|
|
2644
|
+
return dayCellStateEqual(a, b);
|
|
2631
2645
|
}
|
|
2632
2646
|
const DayButtonInner = (0, react.memo)((0, react.forwardRef)(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
|
|
2633
2647
|
/**
|
|
@@ -2659,26 +2673,12 @@ const DayButton = (0, react.forwardRef)(DayButtonFn);
|
|
|
2659
2673
|
/** Fallback for standalone DayButton usage that needs to read context. */
|
|
2660
2674
|
function DayButtonFallbackFn(props, ref) {
|
|
2661
2675
|
const { date, ...restProps } = props;
|
|
2662
|
-
const
|
|
2663
|
-
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2664
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
2665
|
-
const todayDate = today();
|
|
2666
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2667
|
-
const viewCtx = useViewContext();
|
|
2668
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2669
|
-
const { rootState, currentDateTime } = useViewState();
|
|
2670
|
-
const { outsideDays } = useViewStable();
|
|
2671
|
-
const cellMonth = viewCtx.viewType === "weeks" ? {
|
|
2672
|
-
year: date.year,
|
|
2673
|
-
month: date.month
|
|
2674
|
-
} : weekData?.gridMonth ?? currentDateTime;
|
|
2675
|
-
const daysInWeek = date.daysInWeek;
|
|
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);
|
|
2676
|
+
const derive = useDayCellDeriver();
|
|
2677
2677
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
|
|
2678
2678
|
...restProps,
|
|
2679
2679
|
ref,
|
|
2680
2680
|
date,
|
|
2681
|
-
_derivedState:
|
|
2681
|
+
_derivedState: derive(date)
|
|
2682
2682
|
});
|
|
2683
2683
|
}
|
|
2684
2684
|
const DayButtonFallback = (0, react.forwardRef)(DayButtonFallbackFn);
|
|
@@ -3670,6 +3670,98 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
|
|
|
3670
3670
|
return weeks;
|
|
3671
3671
|
}
|
|
3672
3672
|
//#endregion
|
|
3673
|
+
//#region src/resolve-first-week.ts
|
|
3674
|
+
/** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
|
|
3675
|
+
function snapToWeekStart(date, weekStartDay) {
|
|
3676
|
+
const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3677
|
+
return date.subtract({ days: offset });
|
|
3678
|
+
}
|
|
3679
|
+
/**
|
|
3680
|
+
* Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
|
|
3681
|
+
* containing week's start (snapped to `weekStartDay`).
|
|
3682
|
+
*
|
|
3683
|
+
* @param spec - The week specifier to resolve.
|
|
3684
|
+
* @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
|
|
3685
|
+
* @param T - Temporal namespace.
|
|
3686
|
+
* @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
|
|
3687
|
+
*/
|
|
3688
|
+
function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
|
|
3689
|
+
if ("calendarId" in spec) {
|
|
3690
|
+
const pd = spec;
|
|
3691
|
+
return snapToWeekStart(pd.calendarId === "iso8601" ? pd : pd.withCalendar("iso8601"), weekStartDay);
|
|
3692
|
+
}
|
|
3693
|
+
if (spec instanceof Date) {
|
|
3694
|
+
const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
3695
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
3696
|
+
timeZone: tz,
|
|
3697
|
+
year: "numeric",
|
|
3698
|
+
month: "numeric",
|
|
3699
|
+
day: "numeric"
|
|
3700
|
+
}).formatToParts(spec);
|
|
3701
|
+
const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
|
|
3702
|
+
return snapToWeekStart(T.PlainDate.from({
|
|
3703
|
+
year: get("year"),
|
|
3704
|
+
month: get("month"),
|
|
3705
|
+
day: get("day")
|
|
3706
|
+
}), weekStartDay);
|
|
3707
|
+
}
|
|
3708
|
+
if ("isoWeek" in spec) {
|
|
3709
|
+
const { isoWeek, isoYear } = spec;
|
|
3710
|
+
const jan4 = T.PlainDate.from({
|
|
3711
|
+
year: isoYear,
|
|
3712
|
+
month: 1,
|
|
3713
|
+
day: 4
|
|
3714
|
+
});
|
|
3715
|
+
const jan4dow = jan4.dayOfWeek;
|
|
3716
|
+
return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
|
|
3717
|
+
}
|
|
3718
|
+
if ("week" in spec && !("month" in spec)) {
|
|
3719
|
+
const { week, year } = spec;
|
|
3720
|
+
const jan1 = T.PlainDate.from({
|
|
3721
|
+
year,
|
|
3722
|
+
month: 1,
|
|
3723
|
+
day: 1
|
|
3724
|
+
});
|
|
3725
|
+
const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
|
|
3726
|
+
return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
|
|
3727
|
+
}
|
|
3728
|
+
const { month, year, day } = spec;
|
|
3729
|
+
const targetDay = day ?? 1;
|
|
3730
|
+
return snapToWeekStart(T.PlainDate.from({
|
|
3731
|
+
year,
|
|
3732
|
+
month,
|
|
3733
|
+
day: targetDay
|
|
3734
|
+
}), weekStartDay);
|
|
3735
|
+
}
|
|
3736
|
+
/**
|
|
3737
|
+
* Computes a new `firstWeek` date given a scroll target and snap mode.
|
|
3738
|
+
*
|
|
3739
|
+
* The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
|
|
3740
|
+
*
|
|
3741
|
+
* @param currentFirstWeek - The current first visible week (a week-start date).
|
|
3742
|
+
* @param weekCount - Number of visible week rows.
|
|
3743
|
+
* @param target - The week-start date to scroll to.
|
|
3744
|
+
* @param options - Optional snap mode (default `"start"`).
|
|
3745
|
+
*/
|
|
3746
|
+
function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
3747
|
+
switch (options?.snap ?? "start") {
|
|
3748
|
+
case "start": return target;
|
|
3749
|
+
case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
|
|
3750
|
+
case "end": return target.subtract({ weeks: weekCount - 1 });
|
|
3751
|
+
case "nearest": {
|
|
3752
|
+
const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
|
|
3753
|
+
const cmp = (a, b) => {
|
|
3754
|
+
if (a.year !== b.year) return a.year - b.year;
|
|
3755
|
+
if (a.month !== b.month) return a.month - b.month;
|
|
3756
|
+
return a.day - b.day;
|
|
3757
|
+
};
|
|
3758
|
+
if (cmp(target, currentFirstWeek) < 0) return target;
|
|
3759
|
+
if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
|
|
3760
|
+
return currentFirstWeek;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
//#endregion
|
|
3673
3765
|
//#region src/out-of-range.ts
|
|
3674
3766
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3675
3767
|
function weekHasValidDay(weekStart, min, max, T) {
|
|
@@ -3777,96 +3869,28 @@ function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, m
|
|
|
3777
3869
|
return true;
|
|
3778
3870
|
}
|
|
3779
3871
|
//#endregion
|
|
3780
|
-
//#region src/
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
3803
|
-
timeZone: tz,
|
|
3804
|
-
year: "numeric",
|
|
3805
|
-
month: "numeric",
|
|
3806
|
-
day: "numeric"
|
|
3807
|
-
}).formatToParts(spec);
|
|
3808
|
-
const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
|
|
3809
|
-
return snapToWeekStart(T.PlainDate.from({
|
|
3810
|
-
year: get("year"),
|
|
3811
|
-
month: get("month"),
|
|
3812
|
-
day: get("day")
|
|
3813
|
-
}), weekStartDay);
|
|
3814
|
-
}
|
|
3815
|
-
if ("isoWeek" in spec) {
|
|
3816
|
-
const { isoWeek, isoYear } = spec;
|
|
3817
|
-
const jan4 = T.PlainDate.from({
|
|
3818
|
-
year: isoYear,
|
|
3819
|
-
month: 1,
|
|
3820
|
-
day: 4
|
|
3821
|
-
});
|
|
3822
|
-
const jan4dow = jan4.dayOfWeek;
|
|
3823
|
-
return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
|
|
3824
|
-
}
|
|
3825
|
-
if ("week" in spec && !("month" in spec)) {
|
|
3826
|
-
const { week, year } = spec;
|
|
3827
|
-
const jan1 = T.PlainDate.from({
|
|
3828
|
-
year,
|
|
3829
|
-
month: 1,
|
|
3830
|
-
day: 1
|
|
3831
|
-
});
|
|
3832
|
-
const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
|
|
3833
|
-
return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
|
|
3834
|
-
}
|
|
3835
|
-
const { month, year, day } = spec;
|
|
3836
|
-
const targetDay = day ?? 1;
|
|
3837
|
-
return snapToWeekStart(T.PlainDate.from({
|
|
3838
|
-
year,
|
|
3839
|
-
month,
|
|
3840
|
-
day: targetDay
|
|
3841
|
-
}), weekStartDay);
|
|
3842
|
-
}
|
|
3843
|
-
/**
|
|
3844
|
-
* Computes a new `firstWeek` date given a scroll target and snap mode.
|
|
3845
|
-
*
|
|
3846
|
-
* The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
|
|
3847
|
-
*
|
|
3848
|
-
* @param currentFirstWeek - The current first visible week (a week-start date).
|
|
3849
|
-
* @param weekCount - Number of visible week rows.
|
|
3850
|
-
* @param target - The week-start date to scroll to.
|
|
3851
|
-
* @param options - Optional snap mode (default `"start"`).
|
|
3852
|
-
*/
|
|
3853
|
-
function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
3854
|
-
switch (options?.snap ?? "start") {
|
|
3855
|
-
case "start": return target;
|
|
3856
|
-
case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
|
|
3857
|
-
case "end": return target.subtract({ weeks: weekCount - 1 });
|
|
3858
|
-
case "nearest": {
|
|
3859
|
-
const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
|
|
3860
|
-
const cmp = (a, b) => {
|
|
3861
|
-
if (a.year !== b.year) return a.year - b.year;
|
|
3862
|
-
if (a.month !== b.month) return a.month - b.month;
|
|
3863
|
-
return a.day - b.day;
|
|
3864
|
-
};
|
|
3865
|
-
if (cmp(target, currentFirstWeek) < 0) return target;
|
|
3866
|
-
if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
|
|
3867
|
-
return currentFirstWeek;
|
|
3868
|
-
}
|
|
3869
|
-
}
|
|
3872
|
+
//#region src/weeks-window.ts
|
|
3873
|
+
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3874
|
+
const bounds = {
|
|
3875
|
+
weekCount,
|
|
3876
|
+
behavior,
|
|
3877
|
+
...min !== void 0 && { min },
|
|
3878
|
+
...max !== void 0 && { max },
|
|
3879
|
+
weekStartDay,
|
|
3880
|
+
T
|
|
3881
|
+
};
|
|
3882
|
+
return {
|
|
3883
|
+
resolve: (requestedFirstWeek) => applyOutOfRange({
|
|
3884
|
+
...bounds,
|
|
3885
|
+
targetFirstWeek: requestedFirstWeek
|
|
3886
|
+
}),
|
|
3887
|
+
canShift: (currentFirstWeek, direction, shiftBy) => canShift({
|
|
3888
|
+
...bounds,
|
|
3889
|
+
currentFirstWeek,
|
|
3890
|
+
direction,
|
|
3891
|
+
...shiftBy !== void 0 && { shiftBy }
|
|
3892
|
+
})
|
|
3893
|
+
};
|
|
3870
3894
|
}
|
|
3871
3895
|
//#endregion
|
|
3872
3896
|
//#region src/weeks-view-state.ts
|
|
@@ -3896,16 +3920,14 @@ function useWeeksViewRootState(props) {
|
|
|
3896
3920
|
weekStartDay,
|
|
3897
3921
|
T
|
|
3898
3922
|
]);
|
|
3899
|
-
const
|
|
3900
|
-
targetFirstWeek: resolvedFirstWeek,
|
|
3923
|
+
const windowPolicy = (0, react.useMemo)(() => createWeekWindowPolicy({
|
|
3901
3924
|
weekCount,
|
|
3902
3925
|
behavior: outOfRangeBehavior,
|
|
3903
|
-
|
|
3904
|
-
|
|
3926
|
+
min: minValue,
|
|
3927
|
+
max: maxValue,
|
|
3905
3928
|
weekStartDay,
|
|
3906
3929
|
T
|
|
3907
3930
|
}), [
|
|
3908
|
-
resolvedFirstWeek,
|
|
3909
3931
|
weekCount,
|
|
3910
3932
|
outOfRangeBehavior,
|
|
3911
3933
|
minValue,
|
|
@@ -3913,6 +3935,7 @@ function useWeeksViewRootState(props) {
|
|
|
3913
3935
|
weekStartDay,
|
|
3914
3936
|
T
|
|
3915
3937
|
]);
|
|
3938
|
+
const outOfRangeResult = (0, react.useMemo)(() => windowPolicy.resolve(resolvedFirstWeek), [windowPolicy, resolvedFirstWeek]);
|
|
3916
3939
|
const adjustedWeeks = (0, react.useMemo)(() => {
|
|
3917
3940
|
const sameFirst = T.PlainDate.compare(outOfRangeResult.firstWeek, resolvedFirstWeek) === 0;
|
|
3918
3941
|
const sameCount = outOfRangeResult.weekCount === weekCount;
|
|
@@ -4091,66 +4114,31 @@ function useWeeksViewRootState(props) {
|
|
|
4091
4114
|
onFirstWeekChange?.(newFirstWeek);
|
|
4092
4115
|
}, [isControlled, onFirstWeekChange]);
|
|
4093
4116
|
const goNext = (0, react.useCallback)((shiftBy) => {
|
|
4094
|
-
const
|
|
4095
|
-
updateFirstWeek(
|
|
4096
|
-
targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
|
|
4097
|
-
weekCount,
|
|
4098
|
-
behavior: outOfRangeBehavior,
|
|
4099
|
-
...minValue !== void 0 && { min: minValue },
|
|
4100
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4101
|
-
weekStartDay,
|
|
4102
|
-
T
|
|
4103
|
-
}).firstWeek);
|
|
4117
|
+
const target = resolvedFirstWeek.add({ weeks: shiftBy ?? weekCount });
|
|
4118
|
+
updateFirstWeek(windowPolicy.resolve(target).firstWeek);
|
|
4104
4119
|
}, [
|
|
4105
4120
|
resolvedFirstWeek,
|
|
4106
4121
|
weekCount,
|
|
4107
|
-
|
|
4108
|
-
minValue,
|
|
4109
|
-
maxValue,
|
|
4110
|
-
weekStartDay,
|
|
4111
|
-
T,
|
|
4122
|
+
windowPolicy,
|
|
4112
4123
|
updateFirstWeek
|
|
4113
4124
|
]);
|
|
4114
4125
|
const goPrev = (0, react.useCallback)((shiftBy) => {
|
|
4115
|
-
const
|
|
4116
|
-
updateFirstWeek(
|
|
4117
|
-
targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
|
|
4118
|
-
weekCount,
|
|
4119
|
-
behavior: outOfRangeBehavior,
|
|
4120
|
-
...minValue !== void 0 && { min: minValue },
|
|
4121
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4122
|
-
weekStartDay,
|
|
4123
|
-
T
|
|
4124
|
-
}).firstWeek);
|
|
4126
|
+
const target = resolvedFirstWeek.subtract({ weeks: shiftBy ?? weekCount });
|
|
4127
|
+
updateFirstWeek(windowPolicy.resolve(target).firstWeek);
|
|
4125
4128
|
}, [
|
|
4126
4129
|
resolvedFirstWeek,
|
|
4127
4130
|
weekCount,
|
|
4128
|
-
|
|
4129
|
-
minValue,
|
|
4130
|
-
maxValue,
|
|
4131
|
-
weekStartDay,
|
|
4132
|
-
T,
|
|
4131
|
+
windowPolicy,
|
|
4133
4132
|
updateFirstWeek
|
|
4134
4133
|
]);
|
|
4135
4134
|
const scrollToWeek = (0, react.useCallback)((target, options) => {
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
weekCount,
|
|
4139
|
-
behavior: outOfRangeBehavior,
|
|
4140
|
-
...minValue !== void 0 && { min: minValue },
|
|
4141
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4142
|
-
weekStartDay,
|
|
4143
|
-
T
|
|
4144
|
-
}).firstWeek);
|
|
4135
|
+
const newFirstWeek = resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options);
|
|
4136
|
+
updateFirstWeek(windowPolicy.resolve(newFirstWeek).firstWeek);
|
|
4145
4137
|
}, [
|
|
4146
4138
|
resolvedFirstWeek,
|
|
4147
4139
|
weekCount,
|
|
4148
4140
|
resolveSpec,
|
|
4149
|
-
|
|
4150
|
-
minValue,
|
|
4151
|
-
maxValue,
|
|
4152
|
-
weekStartDay,
|
|
4153
|
-
T,
|
|
4141
|
+
windowPolicy,
|
|
4154
4142
|
updateFirstWeek
|
|
4155
4143
|
]);
|
|
4156
4144
|
const onWindowChangeRef = (0, react.useRef)(onWindowChange);
|
|
@@ -4167,6 +4155,7 @@ function useWeeksViewRootState(props) {
|
|
|
4167
4155
|
weekCount,
|
|
4168
4156
|
scrollBy,
|
|
4169
4157
|
outOfRangeBehavior,
|
|
4158
|
+
windowPolicy,
|
|
4170
4159
|
goNext,
|
|
4171
4160
|
goPrev,
|
|
4172
4161
|
scrollToWeek,
|
|
@@ -4176,6 +4165,7 @@ function useWeeksViewRootState(props) {
|
|
|
4176
4165
|
weekCount,
|
|
4177
4166
|
scrollBy,
|
|
4178
4167
|
outOfRangeBehavior,
|
|
4168
|
+
windowPolicy,
|
|
4179
4169
|
goNext,
|
|
4180
4170
|
goPrev,
|
|
4181
4171
|
scrollToWeek,
|
|
@@ -4289,35 +4279,20 @@ const weekCountStateAttributesMapping = {
|
|
|
4289
4279
|
weekCount: () => null
|
|
4290
4280
|
};
|
|
4291
4281
|
function useWeeksNavButton(direction, shiftByProp) {
|
|
4292
|
-
const { disabled: globalDisabled
|
|
4293
|
-
const {
|
|
4282
|
+
const { disabled: globalDisabled } = useCalendarStable();
|
|
4283
|
+
const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
|
|
4294
4284
|
const { windowInfo } = useWeeksViewState();
|
|
4295
4285
|
const { rootState } = useViewState();
|
|
4296
4286
|
const currentFirstWeek = windowInfo.windowStart;
|
|
4297
4287
|
const isDisabled = (0, react.useMemo)(() => {
|
|
4298
4288
|
if (globalDisabled) return true;
|
|
4299
|
-
return !canShift(
|
|
4300
|
-
currentFirstWeek,
|
|
4301
|
-
weekCount,
|
|
4302
|
-
direction: direction === "next" ? 1 : -1,
|
|
4303
|
-
...shiftByProp !== void 0 && { shiftBy: shiftByProp },
|
|
4304
|
-
behavior: outOfRangeBehavior,
|
|
4305
|
-
...minValue !== void 0 && { min: minValue },
|
|
4306
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4307
|
-
weekStartDay,
|
|
4308
|
-
T
|
|
4309
|
-
});
|
|
4289
|
+
return !windowPolicy.canShift(currentFirstWeek, direction === "next" ? 1 : -1, shiftByProp);
|
|
4310
4290
|
}, [
|
|
4311
4291
|
globalDisabled,
|
|
4292
|
+
windowPolicy,
|
|
4312
4293
|
currentFirstWeek,
|
|
4313
|
-
weekCount,
|
|
4314
4294
|
direction,
|
|
4315
|
-
shiftByProp
|
|
4316
|
-
outOfRangeBehavior,
|
|
4317
|
-
minValue,
|
|
4318
|
-
maxValue,
|
|
4319
|
-
weekStartDay,
|
|
4320
|
-
T
|
|
4295
|
+
shiftByProp
|
|
4321
4296
|
]);
|
|
4322
4297
|
const state = (0, react.useMemo)(() => ({
|
|
4323
4298
|
root: rootState,
|