@klinking/colander 3.1.0-alpha.1 → 3.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +2 -3
- package/dist/formats/date.d.cts +10 -14
- package/dist/formats/date.d.mts +10 -14
- package/dist/formats/date.mjs +2 -3
- package/dist/formats/object.cjs +2 -3
- package/dist/formats/object.d.cts +10 -14
- package/dist/formats/object.d.mts +10 -14
- package/dist/formats/object.mjs +2 -3
- package/dist/formats/plain-date-time.cjs +2 -3
- package/dist/formats/plain-date-time.d.cts +10 -14
- package/dist/formats/plain-date-time.d.mts +10 -14
- package/dist/formats/plain-date-time.mjs +2 -3
- package/dist/formats/plain-date.cjs +2 -3
- package/dist/formats/plain-date.d.cts +10 -14
- package/dist/formats/plain-date.d.mts +10 -14
- package/dist/formats/plain-date.mjs +2 -3
- package/dist/formats/plain-month-day.cjs +2 -3
- package/dist/formats/plain-month-day.d.cts +10 -14
- package/dist/formats/plain-month-day.d.mts +10 -14
- package/dist/formats/plain-month-day.mjs +2 -3
- package/dist/formats/plain-year-month.cjs +2 -3
- package/dist/formats/plain-year-month.d.cts +10 -14
- package/dist/formats/plain-year-month.d.mts +10 -14
- package/dist/formats/plain-year-month.mjs +2 -3
- package/dist/formats/zoned-date-time.cjs +2 -3
- package/dist/formats/zoned-date-time.d.cts +10 -14
- package/dist/formats/zoned-date-time.d.mts +10 -14
- package/dist/formats/zoned-date-time.mjs +2 -3
- package/dist/{weeks-view-context-CNAq2Hiu.d.cts → index-K1_zOIpa.d.mts} +198 -114
- package/dist/{weeks-view-context-CsP3PBiu.d.mts → index-bRoYX03d.d.cts} +198 -114
- 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 -2
- package/dist/{weeks-navigation-CJzhxbgj.cjs → weeks-navigation-3UTRiTUP.cjs} +1102 -952
- package/dist/{weeks-navigation-Bg0nZLgh.mjs → weeks-navigation-BoHqK5fq.mjs} +1102 -951
- package/package.json +21 -18
- package/src/calendar-provider.test.tsx +88 -1
- package/src/calendar-provider.tsx +89 -73
- package/src/calendar-types.ts +2 -0
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +214 -0
- package/src/day-cell-state.ts +244 -0
- package/src/day-cell-store.test.tsx +273 -0
- package/src/day-cell-store.tsx +204 -0
- package/src/day-cell.test.tsx +73 -90
- package/src/day-cell.tsx +106 -444
- package/src/drag-handle.tsx +2 -2
- package/src/formats/date.ts +2 -0
- package/src/formats/formats.test.ts +1 -1
- package/src/formats/object.ts +2 -0
- package/src/formats/plain-date-time.ts +2 -0
- package/src/formats/plain-date.ts +2 -0
- package/src/formats/plain-month-day.ts +2 -0
- package/src/formats/plain-year-month.ts +2 -0
- package/src/formats/zoned-date-time.ts +2 -0
- package/src/grid-header.tsx +3 -3
- package/src/grid.event-perf.test.tsx +7 -1
- package/src/grid.perf.test.tsx +7 -1
- package/src/grid.tsx +38 -77
- package/src/index.ts +2 -0
- package/src/keyboard.test.ts +1 -1
- package/src/month-separator.test.tsx +1 -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.test.tsx +89 -1
- package/src/month-view.tsx +74 -217
- package/src/month-window.test.ts +207 -0
- package/src/month-window.ts +93 -0
- package/src/navigation.tsx +18 -76
- package/src/out-of-range.test.ts +34 -54
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +120 -0
- package/src/range-preview.tsx +3 -5
- package/src/resolve-first-week.test.ts +1 -1
- package/src/root-selection.ts +99 -97
- package/src/selected-range.tsx +3 -5
- package/src/store.ts +72 -0
- package/src/today.test.tsx +105 -0
- package/src/types.ts +24 -1
- package/src/utils.bench.ts +158 -106
- package/src/utils.test.ts +26 -1
- package/src/utils.ts +40 -9
- package/src/view-context.test.tsx +126 -0
- package/src/view-context.ts +45 -0
- package/src/week-number.test.tsx +76 -0
- package/src/week-number.tsx +48 -19
- package/src/weeks-grid.tsx +20 -10
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-navigation.tsx +15 -31
- package/src/weeks-view-state.ts +67 -101
- package/src/weeks-view-types.ts +4 -1
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-view.test.tsx +116 -14
- package/src/weeks-view.tsx +24 -52
- package/src/weeks-window.test.ts +131 -0
- package/src/weeks-window.ts +102 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15,17 +15,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
22
|
let react = require("react");
|
|
24
23
|
react = __toESM(react, 1);
|
|
24
|
+
let use_sync_external_store_shim_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
25
25
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
let _base_ui_react_merge_props = require("@base-ui/react/merge-props");
|
|
27
27
|
let _base_ui_react_use_render = require("@base-ui/react/use-render");
|
|
28
|
-
|
|
28
|
+
// src/calendar-context.ts
|
|
29
29
|
/** @internal React context carrying stable CalendarProvider values (callbacks, config). */
|
|
30
30
|
const CalendarStableContext = (0, react.createContext)(null);
|
|
31
31
|
/** @internal React context carrying volatile CalendarProvider state. */
|
|
@@ -42,8 +42,7 @@ function useCalendarState() {
|
|
|
42
42
|
if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
|
|
43
43
|
return ctx;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
//#region src/utils.ts
|
|
45
|
+
// src/utils.ts
|
|
47
46
|
/**
|
|
48
47
|
* Resolves a {@link TemporalNamespace} instance.
|
|
49
48
|
*
|
|
@@ -70,6 +69,17 @@ function getSystemTimeZone(T) {
|
|
|
70
69
|
return T.Now.timeZoneId();
|
|
71
70
|
}
|
|
72
71
|
/**
|
|
72
|
+
* The date a view opens on: the selected date, else today in the provider's time zone.
|
|
73
|
+
*
|
|
74
|
+
* @param selected - The currently selected value, or `undefined`.
|
|
75
|
+
* @param today - Reads today's date in the provider's time zone.
|
|
76
|
+
* @param timeZone - IANA time zone.
|
|
77
|
+
* @param T - Temporal namespace.
|
|
78
|
+
*/
|
|
79
|
+
function resolveInitialAnchor(selected, today, timeZone, T) {
|
|
80
|
+
return selectedToZdt(selected, timeZone, T)?.toPlainDate() ?? today();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
73
83
|
* Converts any {@link DateValueObject} into a `Temporal.ZonedDateTime`.
|
|
74
84
|
*
|
|
75
85
|
* Handles all supported value formats (`PlainDate`, `PlainDateTime`,
|
|
@@ -462,24 +472,32 @@ function getWeekdayNames(locale, T, weekStartDay = 0) {
|
|
|
462
472
|
/**
|
|
463
473
|
* Computes the ISO 8601 week number for a given date.
|
|
464
474
|
*
|
|
465
|
-
* The ISO week number is determined by the Thursday of the date's ISO week
|
|
475
|
+
* The ISO week number is determined by the Thursday of the date's ISO week:
|
|
476
|
+
* a week belongs to the year that contains the majority of its days, i.e.
|
|
477
|
+
* the year containing its midpoint day. For 7-day weeks this is exactly
|
|
478
|
+
* ISO 8601 (Thursday rule, Jan 4 always in week 1).
|
|
479
|
+
*
|
|
480
|
+
* For calendars whose weeks have N ≠ 7 days, the same construction is
|
|
481
|
+
* generalized: the midpoint is day ⌈N/2⌉ of the week, and the anchor date
|
|
482
|
+
* that is always in week 1 is January (N − ⌈N/2⌉ + 1).
|
|
466
483
|
*
|
|
467
484
|
* @param date - The date to compute the week number for.
|
|
468
485
|
* @param T - Temporal namespace.
|
|
469
486
|
*/
|
|
470
487
|
function getISOWeekNumber(date, T) {
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
488
|
+
const daysInWeek = date.daysInWeek;
|
|
489
|
+
const midpoint = Math.ceil(daysInWeek / 2);
|
|
490
|
+
const midDay = date.add({ days: midpoint - date.dayOfWeek });
|
|
491
|
+
const anchor = T.PlainDate.from({
|
|
492
|
+
year: midDay.year,
|
|
474
493
|
month: 1,
|
|
475
|
-
day:
|
|
494
|
+
day: daysInWeek - midpoint + 1
|
|
476
495
|
});
|
|
477
|
-
const
|
|
478
|
-
const daysDiff =
|
|
479
|
-
return Math.round(daysDiff /
|
|
496
|
+
const anchorMidDay = anchor.add({ days: midpoint - anchor.dayOfWeek });
|
|
497
|
+
const daysDiff = midDay.since(anchorMidDay, { largestUnit: "days" }).days;
|
|
498
|
+
return Math.round(daysDiff / daysInWeek) + 1;
|
|
480
499
|
}
|
|
481
|
-
|
|
482
|
-
//#region src/root-selection.ts
|
|
500
|
+
// src/root-selection.ts
|
|
483
501
|
/** Construct a DateRange (workaround for TS generic conditional type widening). */
|
|
484
502
|
function mkRange(start, end) {
|
|
485
503
|
return {
|
|
@@ -497,6 +515,18 @@ function tagRaw(raw, format) {
|
|
|
497
515
|
value: raw
|
|
498
516
|
};
|
|
499
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* Decodes a range value into committed dates. An empty range is `[]`; a range
|
|
520
|
+
* with only an end is `[end, null]` (pending start, so the end is still the
|
|
521
|
+
* anchor of the next click).
|
|
522
|
+
*/
|
|
523
|
+
function decodeRange(range, toPlain) {
|
|
524
|
+
const start = range.start != null ? toPlain(range.start) : null;
|
|
525
|
+
const end = range.end != null ? toPlain(range.end) : null;
|
|
526
|
+
if (start === null && end === null) return [];
|
|
527
|
+
if (start === null && end !== null) return [end, null];
|
|
528
|
+
return [start, end];
|
|
529
|
+
}
|
|
500
530
|
/** Resolve a `RangeMode` to a concrete "start" | "end" | "reset" action for inside-range clicks. */
|
|
501
531
|
function resolveInsideAction(mode, date, start, end) {
|
|
502
532
|
if (mode === "adjust-start") return "start";
|
|
@@ -775,23 +805,19 @@ function truncateDatesForMode(opts) {
|
|
|
775
805
|
return clamped;
|
|
776
806
|
}
|
|
777
807
|
/**
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
808
|
+
* The range a click on `hoveredDate` would produce, or `null` when the click
|
|
809
|
+
* would do nothing (read-only, disabled date). One path for both the
|
|
810
|
+
* provider's own preview and the public {@link computePreviewRange}.
|
|
781
811
|
*/
|
|
782
|
-
function
|
|
783
|
-
const
|
|
784
|
-
if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
|
|
785
|
-
const rawStart = currentRange?.start != null ? Temporal.PlainDate.from(currentRange.start) : null;
|
|
786
|
-
const rawEnd = currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end) : null;
|
|
787
|
-
const committedDates = currentRange ? rawStart === null && rawEnd !== null ? [rawEnd, null] : [rawStart, rawEnd] : [];
|
|
812
|
+
function computeRangePreview(input) {
|
|
813
|
+
const { hoveredDate, committedDates, rangeMode, allowRangeReversal, readOnly, isDateDisabled, T } = input;
|
|
788
814
|
const committedStart = committedDates[0] ?? void 0;
|
|
789
|
-
const committedEnd = committedDates[1] ?? void 0;
|
|
790
|
-
const
|
|
815
|
+
const committedEnd = committedDates.length > 1 ? committedDates[committedDates.length - 1] ?? void 0 : committedStart;
|
|
816
|
+
const unused = () => [];
|
|
791
817
|
const result = computeSelectionUpdate({
|
|
792
818
|
date: hoveredDate,
|
|
793
|
-
readOnly
|
|
794
|
-
isDateDisabled
|
|
819
|
+
readOnly,
|
|
820
|
+
isDateDisabled,
|
|
795
821
|
isMultiple: false,
|
|
796
822
|
isRange: true,
|
|
797
823
|
committedDates,
|
|
@@ -799,23 +825,83 @@ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeR
|
|
|
799
825
|
committedEnd,
|
|
800
826
|
selectedZdt: void 0,
|
|
801
827
|
rangeMode,
|
|
802
|
-
allowRangeReversal
|
|
803
|
-
sortDates: (d) => [...d].sort((a, b) =>
|
|
804
|
-
currentSingleFormatted:
|
|
805
|
-
currentRangeFormatted:
|
|
806
|
-
currentMultipleFormatted:
|
|
828
|
+
allowRangeReversal,
|
|
829
|
+
sortDates: (d) => [...d].sort((a, b) => T.PlainDate.compare(a, b)),
|
|
830
|
+
currentSingleFormatted: unused,
|
|
831
|
+
currentRangeFormatted: unused,
|
|
832
|
+
currentMultipleFormatted: unused,
|
|
807
833
|
resolvedFormat: "PlainDate",
|
|
808
834
|
timeZone: "UTC",
|
|
809
|
-
T
|
|
835
|
+
T
|
|
810
836
|
});
|
|
811
837
|
if (result.skip || result.newDates.length === 0) return null;
|
|
812
838
|
const start = result.newDates[0];
|
|
813
839
|
const end = result.newDates.length > 1 ? result.newDates[1] : start;
|
|
814
840
|
if (start == null || end == null) return null;
|
|
815
|
-
return
|
|
841
|
+
return [start, end];
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Pure utility that computes the preview range for a hovered date, using the
|
|
845
|
+
* same logic as the built-in hover preview. Useful for deriving the preview in
|
|
846
|
+
* an `onHoveredDateChange` handler without needing a controlled `previewRange`.
|
|
847
|
+
*
|
|
848
|
+
* Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
|
|
849
|
+
* disables dates or is read-only; by default every date is selectable.
|
|
850
|
+
*/
|
|
851
|
+
function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T, options = {}) {
|
|
852
|
+
const Temporal = T ?? globalThis.Temporal;
|
|
853
|
+
if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
|
|
854
|
+
const preview = computeRangePreview({
|
|
855
|
+
hoveredDate,
|
|
856
|
+
committedDates: currentRange ? decodeRange(currentRange, (raw) => Temporal.PlainDate.from(raw)) : [],
|
|
857
|
+
rangeMode,
|
|
858
|
+
allowRangeReversal: !preventRangeReversal,
|
|
859
|
+
readOnly: options.readOnly ?? false,
|
|
860
|
+
isDateDisabled: options.isDateDisabled ?? (() => false),
|
|
861
|
+
T: Temporal
|
|
862
|
+
});
|
|
863
|
+
return preview ? mkRange(preview[0], preview[1]) : null;
|
|
864
|
+
}
|
|
865
|
+
// src/store.ts
|
|
866
|
+
function createStore(initial) {
|
|
867
|
+
let state = initial;
|
|
868
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
869
|
+
return {
|
|
870
|
+
get: () => state,
|
|
871
|
+
set: (next) => {
|
|
872
|
+
if (Object.is(state, next)) return;
|
|
873
|
+
state = next;
|
|
874
|
+
for (const listener of listeners) listener();
|
|
875
|
+
},
|
|
876
|
+
subscribe: (listener) => {
|
|
877
|
+
listeners.add(listener);
|
|
878
|
+
return () => listeners.delete(listener);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
/** `useLayoutEffect` in the browser, `useEffect` on the server (no warning). */
|
|
883
|
+
const useIsoLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
884
|
+
/**
|
|
885
|
+
* Subscribes to the slice of `store` that `select` picks. The component
|
|
886
|
+
* re-renders only when `isEqual` says the slice changed; otherwise the
|
|
887
|
+
* previously returned slice is handed back, keeping its identity.
|
|
888
|
+
*/
|
|
889
|
+
function useStoreSelector(store, select, isEqual) {
|
|
890
|
+
return (0, use_sync_external_store_shim_with_selector.useSyncExternalStoreWithSelector)(store.subscribe, store.get, store.get, select, isEqual);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Returns a function with a stable identity that always calls the latest
|
|
894
|
+
* `fn`, so contexts holding it don't change when its closure does. Call it
|
|
895
|
+
* from event handlers and effects, not during render.
|
|
896
|
+
*/
|
|
897
|
+
function useStableCallback(fn) {
|
|
898
|
+
const latest = (0, react.useRef)(fn);
|
|
899
|
+
(0, react.useInsertionEffect)(() => {
|
|
900
|
+
latest.current = fn;
|
|
901
|
+
});
|
|
902
|
+
return (0, react.useCallback)((...args) => latest.current(...args), []);
|
|
816
903
|
}
|
|
817
|
-
|
|
818
|
-
//#region src/calendar-provider.tsx
|
|
904
|
+
// src/calendar-provider.tsx
|
|
819
905
|
/**
|
|
820
906
|
* Provides shared calendar state (selection, config, range preview) to all
|
|
821
907
|
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
@@ -826,6 +912,7 @@ function CalendarProvider(props) {
|
|
|
826
912
|
const locale = localeProp ?? "en-US";
|
|
827
913
|
const timeZone = timeZoneProp ?? getSystemTimeZone(T);
|
|
828
914
|
const weekStartDay = weekStartDayProp ?? 0;
|
|
915
|
+
const today = (0, react.useCallback)(() => T.Now.zonedDateTimeISO(timeZone).toPlainDate(), [T, timeZone]);
|
|
829
916
|
const resolvedFormat = formatProp ?? "PlainDate";
|
|
830
917
|
const selectionMode = selectionModeProp ?? "single";
|
|
831
918
|
const disabled = disabledProp ?? false;
|
|
@@ -903,13 +990,7 @@ function CalendarProvider(props) {
|
|
|
903
990
|
}
|
|
904
991
|
if (isRange) {
|
|
905
992
|
if (rangeValue === null) return [];
|
|
906
|
-
if (rangeValue)
|
|
907
|
-
const start = rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
|
|
908
|
-
const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
|
|
909
|
-
if (start === null && end === null) return [];
|
|
910
|
-
if (start === null && end !== null) return [end, null];
|
|
911
|
-
return [start, end];
|
|
912
|
-
}
|
|
993
|
+
if (rangeValue) return decodeRange(rangeValue, rawToPlain);
|
|
913
994
|
return;
|
|
914
995
|
}
|
|
915
996
|
if (singleValue === null) return [];
|
|
@@ -923,18 +1004,27 @@ function CalendarProvider(props) {
|
|
|
923
1004
|
rawToPlain,
|
|
924
1005
|
sortDates
|
|
925
1006
|
]);
|
|
926
|
-
const
|
|
1007
|
+
const warnedMalformedRef = (0, react.useRef)(false);
|
|
1008
|
+
(0, react.useEffect)(() => {
|
|
1009
|
+
if (!(valueProp != null && (isRange && !isDateRange(valueProp) || isMultiple && !Array.isArray(valueProp)))) {
|
|
1010
|
+
warnedMalformedRef.current = false;
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (warnedMalformedRef.current) return;
|
|
1014
|
+
warnedMalformedRef.current = true;
|
|
1015
|
+
if (isRange) console.warn(`[DatePicker] selectionMode="range" expects \`value\` to be a { start, end } DateRange or null, but received ${Array.isArray(valueProp) ? "an array" : typeof valueProp}. Ignoring it and falling back to uncontrolled.`);
|
|
1016
|
+
else console.warn(`[DatePicker] selectionMode="multiple" expects \`value\` to be an array or null, but received ${typeof valueProp}. Ignoring it and falling back to uncontrolled.`);
|
|
1017
|
+
}, [
|
|
1018
|
+
valueProp,
|
|
1019
|
+
isRange,
|
|
1020
|
+
isMultiple
|
|
1021
|
+
]);
|
|
1022
|
+
const defaultDates = (0, react.useMemo)(() => {
|
|
927
1023
|
if (isMultiple) {
|
|
928
1024
|
if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
|
|
929
1025
|
return [];
|
|
930
1026
|
}
|
|
931
|
-
if (rangeDefault)
|
|
932
|
-
const start = rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
|
|
933
|
-
const end = rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
|
|
934
|
-
if (start === null && end === null) return [];
|
|
935
|
-
if (start === null && end !== null) return [end, null];
|
|
936
|
-
return [start, end];
|
|
937
|
-
}
|
|
1027
|
+
if (rangeDefault) return decodeRange(rangeDefault, rawToPlain);
|
|
938
1028
|
if (singleDefault != null) return [rawToPlain(singleDefault)];
|
|
939
1029
|
return [];
|
|
940
1030
|
}, [
|
|
@@ -944,7 +1034,8 @@ function CalendarProvider(props) {
|
|
|
944
1034
|
singleDefault,
|
|
945
1035
|
rawToPlain,
|
|
946
1036
|
sortDates
|
|
947
|
-
])
|
|
1037
|
+
]);
|
|
1038
|
+
const [internalDates, setInternalDates] = (0, react.useState)(defaultDates);
|
|
948
1039
|
const isControlled = controlledDates !== void 0;
|
|
949
1040
|
const committedDates = isControlled ? controlledDates : internalDates;
|
|
950
1041
|
const rangeStart = !isMultiple && committedDates.length > 0 ? committedDates[0] ?? void 0 : void 0;
|
|
@@ -1020,40 +1111,18 @@ function CalendarProvider(props) {
|
|
|
1020
1111
|
const [previewStart, previewEnd] = (0, react.useMemo)(() => {
|
|
1021
1112
|
if (previewRangeProp !== void 0) {
|
|
1022
1113
|
if (!previewRangeProp) return [void 0, void 0];
|
|
1023
|
-
|
|
1024
|
-
return toZonedDateTime({
|
|
1025
|
-
format: resolvedFormat,
|
|
1026
|
-
value: raw
|
|
1027
|
-
}, timeZone, T).toPlainDate();
|
|
1028
|
-
};
|
|
1029
|
-
return [previewRangeProp.start != null ? rawToPlainLocal(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlainLocal(previewRangeProp.end) : void 0];
|
|
1114
|
+
return [previewRangeProp.start != null ? rawToPlain(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlain(previewRangeProp.end) : void 0];
|
|
1030
1115
|
}
|
|
1031
1116
|
if (!hoveredDate || !isRange) return [void 0, void 0];
|
|
1032
|
-
|
|
1033
|
-
|
|
1117
|
+
return computeRangePreview({
|
|
1118
|
+
hoveredDate,
|
|
1034
1119
|
readOnly,
|
|
1035
1120
|
isDateDisabled,
|
|
1036
|
-
isMultiple: false,
|
|
1037
|
-
isRange: true,
|
|
1038
1121
|
committedDates,
|
|
1039
|
-
committedStart,
|
|
1040
|
-
committedEnd,
|
|
1041
|
-
selectedZdt: void 0,
|
|
1042
1122
|
rangeMode,
|
|
1043
1123
|
allowRangeReversal,
|
|
1044
|
-
sortDates,
|
|
1045
|
-
currentSingleFormatted,
|
|
1046
|
-
currentRangeFormatted,
|
|
1047
|
-
currentMultipleFormatted,
|
|
1048
|
-
resolvedFormat,
|
|
1049
|
-
timeZone,
|
|
1050
1124
|
T
|
|
1051
|
-
});
|
|
1052
|
-
if (result.skip || result.newDates.length === 0) return [void 0, void 0];
|
|
1053
|
-
const ps = result.newDates[0];
|
|
1054
|
-
const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
|
|
1055
|
-
if (ps == null || pe == null) return [void 0, void 0];
|
|
1056
|
-
return [ps, pe];
|
|
1125
|
+
}) ?? [void 0, void 0];
|
|
1057
1126
|
}, [
|
|
1058
1127
|
previewRangeProp,
|
|
1059
1128
|
hoveredDate,
|
|
@@ -1061,16 +1130,9 @@ function CalendarProvider(props) {
|
|
|
1061
1130
|
readOnly,
|
|
1062
1131
|
isDateDisabled,
|
|
1063
1132
|
committedDates,
|
|
1064
|
-
committedStart,
|
|
1065
|
-
committedEnd,
|
|
1066
1133
|
rangeMode,
|
|
1067
1134
|
allowRangeReversal,
|
|
1068
|
-
|
|
1069
|
-
currentSingleFormatted,
|
|
1070
|
-
currentRangeFormatted,
|
|
1071
|
-
currentMultipleFormatted,
|
|
1072
|
-
resolvedFormat,
|
|
1073
|
-
timeZone,
|
|
1135
|
+
rawToPlain,
|
|
1074
1136
|
T
|
|
1075
1137
|
]);
|
|
1076
1138
|
const prevModeRef = (0, react.useRef)(selectionMode);
|
|
@@ -1092,22 +1154,35 @@ function CalendarProvider(props) {
|
|
|
1092
1154
|
plainToFormatValue,
|
|
1093
1155
|
isControlled
|
|
1094
1156
|
]);
|
|
1157
|
+
const warnedOutOfBoundsRef = (0, react.useRef)(false);
|
|
1095
1158
|
(0, react.useEffect)(() => {
|
|
1096
1159
|
if (isRange || isMultiple) return;
|
|
1097
1160
|
const start = committedStart;
|
|
1098
|
-
if (!start)
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
date: void 0,
|
|
1106
|
-
previous: prev
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1161
|
+
if (!start) {
|
|
1162
|
+
warnedOutOfBoundsRef.current = false;
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
if (!(minValue && T.PlainDate.compare(start, minValue) < 0 || maxValue && T.PlainDate.compare(start, maxValue) > 0)) {
|
|
1166
|
+
warnedOutOfBoundsRef.current = false;
|
|
1167
|
+
return;
|
|
1110
1168
|
}
|
|
1169
|
+
if (isControlled) {
|
|
1170
|
+
if (!warnedOutOfBoundsRef.current) {
|
|
1171
|
+
warnedOutOfBoundsRef.current = true;
|
|
1172
|
+
console.warn(`[DatePicker] The controlled \`value\` is outside the min/max range. It stays selected (rendered disabled) until you update \`value\`; the component will not clear it for you.`);
|
|
1173
|
+
}
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const prev = currentSingleFormatted();
|
|
1177
|
+
commitSelection({
|
|
1178
|
+
newDates: [],
|
|
1179
|
+
fireCallback: (onValueChange) => {
|
|
1180
|
+
onValueChange?.(null, {
|
|
1181
|
+
date: void 0,
|
|
1182
|
+
previous: prev
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1111
1186
|
}, [
|
|
1112
1187
|
minValue,
|
|
1113
1188
|
maxValue,
|
|
@@ -1116,9 +1191,10 @@ function CalendarProvider(props) {
|
|
|
1116
1191
|
currentSingleFormatted,
|
|
1117
1192
|
T,
|
|
1118
1193
|
isRange,
|
|
1119
|
-
isMultiple
|
|
1194
|
+
isMultiple,
|
|
1195
|
+
isControlled
|
|
1120
1196
|
]);
|
|
1121
|
-
const
|
|
1197
|
+
const onSelectLatest = (0, react.useCallback)((date) => {
|
|
1122
1198
|
const result = computeSelectionUpdate({
|
|
1123
1199
|
date,
|
|
1124
1200
|
readOnly,
|
|
@@ -1162,7 +1238,7 @@ function CalendarProvider(props) {
|
|
|
1162
1238
|
currentRangeFormatted,
|
|
1163
1239
|
currentMultipleFormatted
|
|
1164
1240
|
]);
|
|
1165
|
-
const
|
|
1241
|
+
const setRangeLatest = (0, react.useCallback)((start, end) => {
|
|
1166
1242
|
const result = computeSetRangeUpdate({
|
|
1167
1243
|
start,
|
|
1168
1244
|
end,
|
|
@@ -1188,6 +1264,8 @@ function CalendarProvider(props) {
|
|
|
1188
1264
|
resolvedFormat,
|
|
1189
1265
|
T
|
|
1190
1266
|
]);
|
|
1267
|
+
const onSelect = useStableCallback(onSelectLatest);
|
|
1268
|
+
const setRange = useStableCallback(setRangeLatest);
|
|
1191
1269
|
const nonNullDates = (0, react.useMemo)(() => committedDates.filter((d) => d != null), [committedDates]);
|
|
1192
1270
|
const stableCtx = (0, react.useMemo)(() => ({
|
|
1193
1271
|
onSelect,
|
|
@@ -1199,6 +1277,7 @@ function CalendarProvider(props) {
|
|
|
1199
1277
|
...minValue !== void 0 && { minValue },
|
|
1200
1278
|
...maxValue !== void 0 && { maxValue },
|
|
1201
1279
|
timeZone,
|
|
1280
|
+
today,
|
|
1202
1281
|
locale,
|
|
1203
1282
|
temporal: T,
|
|
1204
1283
|
weekStartDay,
|
|
@@ -1216,6 +1295,7 @@ function CalendarProvider(props) {
|
|
|
1216
1295
|
minValue,
|
|
1217
1296
|
maxValue,
|
|
1218
1297
|
timeZone,
|
|
1298
|
+
today,
|
|
1219
1299
|
locale,
|
|
1220
1300
|
T,
|
|
1221
1301
|
weekStartDay,
|
|
@@ -1268,8 +1348,293 @@ function CalendarProvider(props) {
|
|
|
1268
1348
|
})
|
|
1269
1349
|
});
|
|
1270
1350
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1351
|
+
// src/context.ts
|
|
1352
|
+
/** @internal Provides the days and index of the current week row to child components. */
|
|
1353
|
+
const WeekDataContext = (0, react.createContext)(null);
|
|
1354
|
+
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
1355
|
+
const GridContext = (0, react.createContext)({ orientation: "horizontal" });
|
|
1356
|
+
/** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
|
|
1357
|
+
const DayCellDataContext = (0, react.createContext)(null);
|
|
1358
|
+
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1359
|
+
const GridMonthContext = (0, react.createContext)(null);
|
|
1360
|
+
// src/day-cell-state.ts
|
|
1361
|
+
const NO_RANGE = {
|
|
1362
|
+
rangeStart: false,
|
|
1363
|
+
rangeEnd: false,
|
|
1364
|
+
rangeBoundary: false,
|
|
1365
|
+
inRange: false,
|
|
1366
|
+
rangeIndex: false,
|
|
1367
|
+
rangeLength: false,
|
|
1368
|
+
rangeHasStart: false,
|
|
1369
|
+
rangeHasEnd: false,
|
|
1370
|
+
rangePreviewStart: false,
|
|
1371
|
+
rangePreviewEnd: false,
|
|
1372
|
+
rangePreviewBoundary: false,
|
|
1373
|
+
rangePreviewInRange: false,
|
|
1374
|
+
rangePreviewIndex: false,
|
|
1375
|
+
rangePreviewLength: false,
|
|
1376
|
+
rangePreviewHasStart: false,
|
|
1377
|
+
rangePreviewHasEnd: false
|
|
1378
|
+
};
|
|
1379
|
+
function computeRangeState(date, inputs) {
|
|
1380
|
+
const { T, selectionMode, rangeStart, rangeEnd, previewStart, previewEnd } = inputs;
|
|
1381
|
+
if (selectionMode !== "range") return NO_RANGE;
|
|
1382
|
+
const isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
1383
|
+
const isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
1384
|
+
const inRange = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
1385
|
+
const effectiveStart = rangeStart ?? rangeEnd;
|
|
1386
|
+
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
1387
|
+
const isPreviewStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
1388
|
+
const isPreviewEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
1389
|
+
const inPreview = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
1390
|
+
return {
|
|
1391
|
+
rangeStart: isRangeStart,
|
|
1392
|
+
rangeEnd: isRangeEnd,
|
|
1393
|
+
rangeBoundary: isRangeStart || isRangeEnd,
|
|
1394
|
+
inRange,
|
|
1395
|
+
rangeIndex: inRange && effectiveStart ? date.since(effectiveStart).days : false,
|
|
1396
|
+
rangeLength: inRange && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false,
|
|
1397
|
+
rangeHasStart: inRange && rangeStart !== void 0,
|
|
1398
|
+
rangeHasEnd: inRange && rangeEnd !== void 0,
|
|
1399
|
+
rangePreviewStart: isPreviewStart,
|
|
1400
|
+
rangePreviewEnd: isPreviewEnd,
|
|
1401
|
+
rangePreviewBoundary: isPreviewStart || isPreviewEnd,
|
|
1402
|
+
rangePreviewInRange: inPreview,
|
|
1403
|
+
rangePreviewIndex: inPreview && previewStart ? date.since(previewStart).days : false,
|
|
1404
|
+
rangePreviewLength: inPreview && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false,
|
|
1405
|
+
rangePreviewHasStart: inPreview && previewStart !== void 0,
|
|
1406
|
+
rangePreviewHasEnd: inPreview && previewEnd !== void 0
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
/** Derives the state of one day cell. Pure function, no hooks. */
|
|
1410
|
+
function computeDayCellState(date, position, inputs) {
|
|
1411
|
+
const { T, outsideDays } = inputs;
|
|
1412
|
+
const { columnIndex, month } = position;
|
|
1413
|
+
const isCurrentMonth = date.year === month.year && date.month === month.month;
|
|
1414
|
+
const base = {
|
|
1415
|
+
root: inputs.rootState,
|
|
1416
|
+
date,
|
|
1417
|
+
columnIndex,
|
|
1418
|
+
orientation: inputs.orientation
|
|
1419
|
+
};
|
|
1420
|
+
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
1421
|
+
...base,
|
|
1422
|
+
...NO_RANGE,
|
|
1423
|
+
outsideMonth: true,
|
|
1424
|
+
hidden: true,
|
|
1425
|
+
selected: false,
|
|
1426
|
+
today: false,
|
|
1427
|
+
disabled: true,
|
|
1428
|
+
focused: false,
|
|
1429
|
+
isTabTarget: false
|
|
1430
|
+
};
|
|
1431
|
+
const isToday = T.PlainDate.compare(date, inputs.today) === 0;
|
|
1432
|
+
if (!isCurrentMonth && outsideDays !== "enabled") {
|
|
1433
|
+
const suppressRange = outsideDays === "disabled";
|
|
1434
|
+
return {
|
|
1435
|
+
...base,
|
|
1436
|
+
...suppressRange ? NO_RANGE : computeRangeState(date, inputs),
|
|
1437
|
+
outsideMonth: true,
|
|
1438
|
+
hidden: false,
|
|
1439
|
+
selected: false,
|
|
1440
|
+
today: isToday,
|
|
1441
|
+
disabled: true,
|
|
1442
|
+
focused: false,
|
|
1443
|
+
isTabTarget: false
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return {
|
|
1447
|
+
...base,
|
|
1448
|
+
...computeRangeState(date, inputs),
|
|
1449
|
+
outsideMonth: !isCurrentMonth,
|
|
1450
|
+
hidden: false,
|
|
1451
|
+
selected: inputs.selectionMode !== "range" ? inputs.selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false,
|
|
1452
|
+
today: isToday,
|
|
1453
|
+
disabled: inputs.disabled || (inputs.isDateDisabled?.(date) ?? false),
|
|
1454
|
+
focused: T.PlainDate.compare(date, inputs.focusedDate) === 0,
|
|
1455
|
+
isTabTarget: T.PlainDate.compare(date, inputs.tabTargetDate) === 0
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
const COMPARED_KEYS = Object.keys({
|
|
1459
|
+
outsideMonth: true,
|
|
1460
|
+
hidden: true,
|
|
1461
|
+
selected: true,
|
|
1462
|
+
today: true,
|
|
1463
|
+
disabled: true,
|
|
1464
|
+
focused: true,
|
|
1465
|
+
rangeStart: true,
|
|
1466
|
+
rangeEnd: true,
|
|
1467
|
+
rangeBoundary: true,
|
|
1468
|
+
inRange: true,
|
|
1469
|
+
rangeIndex: true,
|
|
1470
|
+
rangeLength: true,
|
|
1471
|
+
rangeHasStart: true,
|
|
1472
|
+
rangeHasEnd: true,
|
|
1473
|
+
rangePreviewStart: true,
|
|
1474
|
+
rangePreviewEnd: true,
|
|
1475
|
+
rangePreviewBoundary: true,
|
|
1476
|
+
rangePreviewInRange: true,
|
|
1477
|
+
rangePreviewIndex: true,
|
|
1478
|
+
rangePreviewLength: true,
|
|
1479
|
+
rangePreviewHasStart: true,
|
|
1480
|
+
rangePreviewHasEnd: true,
|
|
1481
|
+
isTabTarget: true
|
|
1482
|
+
});
|
|
1483
|
+
/** Whether two cell states render the same cell. */
|
|
1484
|
+
function dayCellStateEqual(a, b) {
|
|
1485
|
+
for (const key of COMPARED_KEYS) if (a[key] !== b[key]) return false;
|
|
1486
|
+
return true;
|
|
1487
|
+
}
|
|
1488
|
+
// src/view-context.ts
|
|
1489
|
+
/** @internal React context for the active view (MonthView or WeeksView). */
|
|
1490
|
+
const ViewContext = (0, react.createContext)(null);
|
|
1491
|
+
/** Returns the nearest view context (MonthView or WeeksView). */
|
|
1492
|
+
function useViewContext() {
|
|
1493
|
+
const ctx = (0, react.useContext)(ViewContext);
|
|
1494
|
+
if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
|
|
1495
|
+
return ctx;
|
|
1496
|
+
}
|
|
1497
|
+
/** @internal Context for {@link ViewStableContextValue}. */
|
|
1498
|
+
const ViewStableContext = (0, react.createContext)(null);
|
|
1499
|
+
/** @internal Context for {@link ViewStateContextValue}. */
|
|
1500
|
+
const ViewStateContext = (0, react.createContext)(null);
|
|
1501
|
+
/** Returns the nearest view's stable values. */
|
|
1502
|
+
function useViewStable() {
|
|
1503
|
+
const ctx = (0, react.useContext)(ViewStableContext);
|
|
1504
|
+
if (!ctx) throw new Error("useViewStable must be used within MonthView or WeeksView");
|
|
1505
|
+
return ctx;
|
|
1506
|
+
}
|
|
1507
|
+
/** Returns the nearest view's volatile state. */
|
|
1508
|
+
function useViewState() {
|
|
1509
|
+
const ctx = (0, react.useContext)(ViewStateContext);
|
|
1510
|
+
if (!ctx) throw new Error("useViewState must be used within MonthView or WeeksView");
|
|
1511
|
+
return ctx;
|
|
1512
|
+
}
|
|
1513
|
+
// src/day-cell-store.tsx
|
|
1514
|
+
/** @internal The view's day-cell store. Its identity never changes. */
|
|
1515
|
+
const DayCellStoreContext = (0, react.createContext)(null);
|
|
1516
|
+
/**
|
|
1517
|
+
* Publishes the calendar and view state that day cells derive from. Cells
|
|
1518
|
+
* subscribe per date, so a change re-renders only the cells it affects instead
|
|
1519
|
+
* of every cell under a context.
|
|
1520
|
+
*
|
|
1521
|
+
* The store is seeded on the first render and updated only after a change
|
|
1522
|
+
* commits, never during render: a render React discards (a suspended
|
|
1523
|
+
* transition) must not leak into cells that re-render meanwhile. Cells that
|
|
1524
|
+
* render in the same pass as a change read the previous state first, then
|
|
1525
|
+
* re-render from the layout effect before the browser paints.
|
|
1526
|
+
*/
|
|
1527
|
+
function DayCellStoreProvider(props) {
|
|
1528
|
+
const { disabled, isDateDisabled, selectionMode, temporal: T, today, weekStartDay } = useCalendarStable();
|
|
1529
|
+
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
1530
|
+
const { viewType, focusedDate, tabTargetDate } = useViewContext();
|
|
1531
|
+
const { rootState, currentDateTime } = useViewState();
|
|
1532
|
+
const { outsideDays } = useViewStable();
|
|
1533
|
+
const todayKey = today().toString();
|
|
1534
|
+
const { year, month } = currentDateTime;
|
|
1535
|
+
const snapshot = (0, react.useMemo)(() => ({
|
|
1536
|
+
inputs: {
|
|
1537
|
+
T,
|
|
1538
|
+
today: T.PlainDate.from(todayKey),
|
|
1539
|
+
rootState,
|
|
1540
|
+
selectionMode,
|
|
1541
|
+
selectedDates,
|
|
1542
|
+
rangeStart,
|
|
1543
|
+
rangeEnd,
|
|
1544
|
+
previewStart,
|
|
1545
|
+
previewEnd,
|
|
1546
|
+
disabled,
|
|
1547
|
+
isDateDisabled,
|
|
1548
|
+
focusedDate,
|
|
1549
|
+
tabTargetDate,
|
|
1550
|
+
outsideDays
|
|
1551
|
+
},
|
|
1552
|
+
viewType,
|
|
1553
|
+
viewMonth: {
|
|
1554
|
+
year,
|
|
1555
|
+
month
|
|
1556
|
+
},
|
|
1557
|
+
weekStartDay
|
|
1558
|
+
}), [
|
|
1559
|
+
T,
|
|
1560
|
+
todayKey,
|
|
1561
|
+
rootState,
|
|
1562
|
+
selectionMode,
|
|
1563
|
+
selectedDates,
|
|
1564
|
+
rangeStart,
|
|
1565
|
+
rangeEnd,
|
|
1566
|
+
previewStart,
|
|
1567
|
+
previewEnd,
|
|
1568
|
+
disabled,
|
|
1569
|
+
isDateDisabled,
|
|
1570
|
+
focusedDate,
|
|
1571
|
+
tabTargetDate,
|
|
1572
|
+
outsideDays,
|
|
1573
|
+
viewType,
|
|
1574
|
+
year,
|
|
1575
|
+
month,
|
|
1576
|
+
weekStartDay
|
|
1577
|
+
]);
|
|
1578
|
+
const [store] = (0, react.useState)(() => createStore(snapshot));
|
|
1579
|
+
useIsoLayoutEffect(() => store.set(snapshot), [store, snapshot]);
|
|
1580
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellStoreContext.Provider, {
|
|
1581
|
+
value: store,
|
|
1582
|
+
children: props.children
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Hands `state` to render functions with `root` as a non-enumerable getter
|
|
1587
|
+
* that calls `onReadRoot`. Base UI's data-attribute pass only walks
|
|
1588
|
+
* enumerable keys, so `root` counts as read only when user code reads it.
|
|
1589
|
+
*/
|
|
1590
|
+
function withLazyRoot(state, onReadRoot) {
|
|
1591
|
+
const { root, ...rest } = state;
|
|
1592
|
+
return Object.defineProperty(rest, "root", {
|
|
1593
|
+
get() {
|
|
1594
|
+
onReadRoot();
|
|
1595
|
+
return root;
|
|
1596
|
+
},
|
|
1597
|
+
enumerable: false
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Subscribes to one day cell's state. The cell re-renders only when a field
|
|
1602
|
+
* it renders changes; `root` joins that comparison once a render function has
|
|
1603
|
+
* read `state.root`, so cells that never read it ignore focus and selection
|
|
1604
|
+
* changes elsewhere in the grid.
|
|
1605
|
+
*/
|
|
1606
|
+
function useDayCellState(date, columnIndex, gridMonth) {
|
|
1607
|
+
const store = (0, react.useContext)(DayCellStoreContext);
|
|
1608
|
+
if (!store) throw new Error("Day cells must be used inside MonthView or WeeksView.");
|
|
1609
|
+
const { orientation } = (0, react.useContext)(GridContext);
|
|
1610
|
+
const readsRoot = (0, react.useRef)(false);
|
|
1611
|
+
const state = useStoreSelector(store, (0, react.useCallback)((s) => {
|
|
1612
|
+
const daysInWeek = date.daysInWeek;
|
|
1613
|
+
return computeDayCellState(date, {
|
|
1614
|
+
columnIndex: columnIndex ?? (date.dayOfWeek % daysInWeek - s.weekStartDay + daysInWeek) % daysInWeek,
|
|
1615
|
+
month: s.viewType === "weeks" ? {
|
|
1616
|
+
year: date.year,
|
|
1617
|
+
month: date.month
|
|
1618
|
+
} : gridMonth ?? s.viewMonth
|
|
1619
|
+
}, {
|
|
1620
|
+
...s.inputs,
|
|
1621
|
+
orientation
|
|
1622
|
+
});
|
|
1623
|
+
}, [
|
|
1624
|
+
date,
|
|
1625
|
+
columnIndex,
|
|
1626
|
+
gridMonth,
|
|
1627
|
+
orientation
|
|
1628
|
+
]), (0, react.useCallback)((a, b) => a.date === b.date && a.columnIndex === b.columnIndex && a.orientation === b.orientation && dayCellStateEqual(a, b) && (!readsRoot.current || a.root === b.root), []));
|
|
1629
|
+
return (0, react.useMemo)(() => withLazyRoot(state, () => {
|
|
1630
|
+
readsRoot.current = true;
|
|
1631
|
+
}), [state]);
|
|
1632
|
+
}
|
|
1633
|
+
/** Like {@link useDayCellState}, taking the grid month from the enclosing week. */
|
|
1634
|
+
function useStandaloneDayCellState(date) {
|
|
1635
|
+
return useDayCellState(date, void 0, (0, react.useContext)(WeekDataContext)?.gridMonth);
|
|
1636
|
+
}
|
|
1637
|
+
// src/month-view-context.ts
|
|
1273
1638
|
/** @internal React context for MonthView stable values (config + callbacks). */
|
|
1274
1639
|
const MonthViewStableContext = (0, react.createContext)(null);
|
|
1275
1640
|
/** @internal React context for MonthView volatile state. */
|
|
@@ -1286,211 +1651,243 @@ function useMonthViewState() {
|
|
|
1286
1651
|
if (!ctx) throw new Error("useMonthViewState must be used within MonthView.Root");
|
|
1287
1652
|
return ctx;
|
|
1288
1653
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
//#region src/month-view.tsx
|
|
1301
|
-
function MonthViewRoot(props) {
|
|
1302
|
-
const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
|
|
1303
|
-
const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
|
|
1304
|
-
const fixedWeeks = fixedWeeksProp ?? false;
|
|
1305
|
-
const outsideDays = outsideDaysProp ?? "enabled";
|
|
1306
|
-
const outOfRangeBehavior = outOfRangeBehaviorProp ?? "unbounded";
|
|
1307
|
-
const calStable = useCalendarStable();
|
|
1308
|
-
const calState = useCalendarState();
|
|
1309
|
-
const T = calStable.temporal;
|
|
1310
|
-
const { timeZone, weekStartDay, isDateDisabled } = calStable;
|
|
1311
|
-
const isMonthControlled = monthProp !== void 0;
|
|
1654
|
+
// src/month-view-navigation.ts
|
|
1655
|
+
/**
|
|
1656
|
+
* Owns which month the view shows, in both controlled and uncontrolled mode:
|
|
1657
|
+
* the month state, the Prev/Next steps, and syncing the window with focus.
|
|
1658
|
+
*
|
|
1659
|
+
* `onMonthChange` fires exactly once per move: from the effect below when
|
|
1660
|
+
* uncontrolled, and from the step or the focus-sync effect when controlled.
|
|
1661
|
+
*/
|
|
1662
|
+
function useMonthNavigation(input) {
|
|
1663
|
+
const { month, defaultMonth, initialAnchor, onMonthChange, policy, focusedDate, setFocusedDate, T } = input;
|
|
1664
|
+
const isControlled = month !== void 0;
|
|
1312
1665
|
const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
|
|
1313
|
-
if (
|
|
1314
|
-
year:
|
|
1315
|
-
month:
|
|
1666
|
+
if (month) return {
|
|
1667
|
+
year: month.year,
|
|
1668
|
+
month: month.month
|
|
1316
1669
|
};
|
|
1317
|
-
if (
|
|
1318
|
-
year:
|
|
1319
|
-
month:
|
|
1670
|
+
if (defaultMonth) return {
|
|
1671
|
+
year: defaultMonth.year,
|
|
1672
|
+
month: defaultMonth.month
|
|
1320
1673
|
};
|
|
1321
|
-
|
|
1322
|
-
const zdt = toZonedDateTime(calState.selected, timeZone, T);
|
|
1323
|
-
return {
|
|
1324
|
-
year: zdt.year,
|
|
1325
|
-
month: zdt.month
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
const now = T.Now.zonedDateTimeISO(timeZone);
|
|
1674
|
+
const anchor = initialAnchor();
|
|
1329
1675
|
return {
|
|
1330
|
-
year:
|
|
1331
|
-
month:
|
|
1676
|
+
year: anchor.year,
|
|
1677
|
+
month: anchor.month
|
|
1332
1678
|
};
|
|
1333
1679
|
});
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
if (!(monthIndex in prev)) return prev;
|
|
1349
|
-
const next = { ...prev };
|
|
1350
|
-
delete next[monthIndex];
|
|
1351
|
-
return next;
|
|
1352
|
-
}
|
|
1353
|
-
if (prev[monthIndex] === id) return prev;
|
|
1354
|
-
return {
|
|
1355
|
-
...prev,
|
|
1356
|
-
[monthIndex]: id
|
|
1357
|
-
};
|
|
1358
|
-
});
|
|
1359
|
-
}, []);
|
|
1680
|
+
const year = isControlled ? month.year : internalMonth.year;
|
|
1681
|
+
const monthNumber = isControlled ? month.month : internalMonth.month;
|
|
1682
|
+
const currentMonth = (0, react.useMemo)(() => ({
|
|
1683
|
+
year,
|
|
1684
|
+
month: monthNumber
|
|
1685
|
+
}), [year, monthNumber]);
|
|
1686
|
+
const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
|
|
1687
|
+
year,
|
|
1688
|
+
month: monthNumber
|
|
1689
|
+
}), [
|
|
1690
|
+
year,
|
|
1691
|
+
monthNumber,
|
|
1692
|
+
T
|
|
1693
|
+
]);
|
|
1360
1694
|
const onMonthChangeRef = (0, react.useRef)(onMonthChange);
|
|
1361
1695
|
onMonthChangeRef.current = onMonthChange;
|
|
1362
|
-
const notifyMonth = (0, react.useCallback)((
|
|
1363
|
-
onMonthChangeRef.current?.(T.PlainYearMonth.from(
|
|
1364
|
-
year,
|
|
1365
|
-
month
|
|
1366
|
-
}));
|
|
1696
|
+
const notifyMonth = (0, react.useCallback)((target) => {
|
|
1697
|
+
onMonthChangeRef.current?.(T.PlainYearMonth.from(target));
|
|
1367
1698
|
}, [T]);
|
|
1368
|
-
const isMonthVisible = (0, react.useCallback)((targetYear, targetMonth) => {
|
|
1369
|
-
for (let i = 0; i < numberOfMonths; i++) {
|
|
1370
|
-
const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
|
|
1371
|
-
const y = Math.floor(totalMonths / 12);
|
|
1372
|
-
const m = totalMonths % 12 + 1;
|
|
1373
|
-
if (targetYear === y && targetMonth === m) return true;
|
|
1374
|
-
}
|
|
1375
|
-
return false;
|
|
1376
|
-
}, [
|
|
1377
|
-
currentMonth.year,
|
|
1378
|
-
currentMonth.month,
|
|
1379
|
-
numberOfMonths
|
|
1380
|
-
]);
|
|
1381
|
-
const navigateToMonth = (0, react.useCallback)((targetYear, targetMonth) => {
|
|
1382
|
-
if (isMonthControlled) return;
|
|
1383
|
-
setInternalMonth((prev) => {
|
|
1384
|
-
const next = shiftWindowToMonth(prev, {
|
|
1385
|
-
year: targetYear,
|
|
1386
|
-
month: targetMonth
|
|
1387
|
-
}, numberOfMonths);
|
|
1388
|
-
if (next.year === prev.year && next.month === prev.month) return prev;
|
|
1389
|
-
return next;
|
|
1390
|
-
});
|
|
1391
|
-
}, [isMonthControlled, numberOfMonths]);
|
|
1392
1699
|
const skipFocusSyncForRef = (0, react.useRef)(null);
|
|
1393
1700
|
const prevFocusedRef = (0, react.useRef)(focusedDate);
|
|
1394
1701
|
(0, react.useEffect)(() => {
|
|
1395
1702
|
skipFocusSyncForRef.current = null;
|
|
1396
|
-
}, [
|
|
1703
|
+
}, [month?.year, month?.month]);
|
|
1397
1704
|
(0, react.useEffect)(() => {
|
|
1398
1705
|
const prevFocused = prevFocusedRef.current;
|
|
1399
1706
|
prevFocusedRef.current = focusedDate;
|
|
1400
|
-
|
|
1707
|
+
const target = {
|
|
1708
|
+
year: focusedDate.year,
|
|
1709
|
+
month: focusedDate.month
|
|
1710
|
+
};
|
|
1711
|
+
if (isControlled) {
|
|
1401
1712
|
if (skipFocusSyncForRef.current === focusedDate) {
|
|
1402
1713
|
skipFocusSyncForRef.current = null;
|
|
1403
1714
|
return;
|
|
1404
1715
|
}
|
|
1405
1716
|
if (prevFocused === focusedDate) return;
|
|
1406
|
-
if (
|
|
1407
|
-
|
|
1408
|
-
year: currentMonth.year,
|
|
1409
|
-
month: currentMonth.month
|
|
1410
|
-
}, {
|
|
1411
|
-
year: focusedDate.year,
|
|
1412
|
-
month: focusedDate.month
|
|
1413
|
-
}, numberOfMonths);
|
|
1414
|
-
notifyMonth(next.year, next.month);
|
|
1717
|
+
if (policy.isVisible(currentMonth, target)) return;
|
|
1718
|
+
notifyMonth(policy.reveal(currentMonth, target));
|
|
1415
1719
|
return;
|
|
1416
1720
|
}
|
|
1417
|
-
|
|
1721
|
+
setInternalMonth((prev) => {
|
|
1722
|
+
const next = policy.reveal(prev, target);
|
|
1723
|
+
if (next.year === prev.year && next.month === prev.month) return prev;
|
|
1724
|
+
return next;
|
|
1725
|
+
});
|
|
1418
1726
|
}, [
|
|
1419
1727
|
focusedDate,
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
notifyMonth
|
|
1424
|
-
currentMonth.year,
|
|
1425
|
-
currentMonth.month,
|
|
1426
|
-
numberOfMonths
|
|
1728
|
+
isControlled,
|
|
1729
|
+
policy,
|
|
1730
|
+
currentMonth,
|
|
1731
|
+
notifyMonth
|
|
1427
1732
|
]);
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1733
|
+
const mountedRef = (0, react.useRef)(false);
|
|
1734
|
+
(0, react.useEffect)(() => {
|
|
1735
|
+
if (!mountedRef.current) {
|
|
1736
|
+
mountedRef.current = true;
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
if (isControlled) return;
|
|
1740
|
+
onMonthChangeRef.current?.(viewingYearMonth);
|
|
1741
|
+
}, [viewingYearMonth, isControlled]);
|
|
1742
|
+
const go = (0, react.useCallback)((direction) => {
|
|
1743
|
+
if (isControlled) {
|
|
1744
|
+
const step = policy.step(month, direction);
|
|
1745
|
+
if (step.blocked) return;
|
|
1746
|
+
const nextFocus = focusedDateForMonth(focusedDate, step.start, step.firstDay);
|
|
1438
1747
|
skipFocusSyncForRef.current = nextFocus;
|
|
1439
|
-
notifyMonth(
|
|
1748
|
+
notifyMonth(step.start);
|
|
1440
1749
|
setFocusedDate(nextFocus);
|
|
1441
1750
|
return;
|
|
1442
1751
|
}
|
|
1443
1752
|
setInternalMonth((m) => {
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
}, firstDay));
|
|
1449
|
-
return {
|
|
1450
|
-
year,
|
|
1451
|
-
month
|
|
1452
|
-
};
|
|
1753
|
+
const step = policy.step(m, direction);
|
|
1754
|
+
if (step.blocked) return m;
|
|
1755
|
+
setFocusedDate((prev) => focusedDateForMonth(prev, step.start, step.firstDay));
|
|
1756
|
+
return step.start;
|
|
1453
1757
|
});
|
|
1454
1758
|
}, [
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1759
|
+
isControlled,
|
|
1760
|
+
month,
|
|
1761
|
+
policy,
|
|
1458
1762
|
notifyMonth,
|
|
1459
|
-
focusedDate
|
|
1763
|
+
focusedDate,
|
|
1764
|
+
setFocusedDate
|
|
1460
1765
|
]);
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1766
|
+
return {
|
|
1767
|
+
currentMonth,
|
|
1768
|
+
viewingYearMonth,
|
|
1769
|
+
goNextMonth: (0, react.useCallback)(() => go("next"), [go]),
|
|
1770
|
+
goPrevMonth: (0, react.useCallback)(() => go("prev"), [go])
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
// src/month-window.ts
|
|
1774
|
+
const monthIndex = (m) => m.year * 12 + (m.month - 1);
|
|
1775
|
+
/**
|
|
1776
|
+
* Builds the policy for a MonthView window of `numberOfMonths` months.
|
|
1777
|
+
*
|
|
1778
|
+
* `unbounded` never blocks a step: `min`/`max` only gate which days are
|
|
1779
|
+
* selectable, not which months can be viewed. Any other behavior is `stop`,
|
|
1780
|
+
* which blocks a step whose entering month lies beyond the bound's month.
|
|
1781
|
+
*/
|
|
1782
|
+
function createMonthWindowPolicy(input) {
|
|
1783
|
+
const { numberOfMonths, behavior, min, max, T } = input;
|
|
1784
|
+
return {
|
|
1785
|
+
step(start, direction) {
|
|
1786
|
+
const adjacent = computeAdjacentMonth(start, direction, T);
|
|
1787
|
+
const newStart = {
|
|
1788
|
+
year: adjacent.year,
|
|
1789
|
+
month: adjacent.month
|
|
1790
|
+
};
|
|
1791
|
+
const entering = direction === "prev" ? newStart : monthAt(newStart, numberOfMonths - 1);
|
|
1792
|
+
let blocked = false;
|
|
1793
|
+
if (behavior !== "unbounded") {
|
|
1794
|
+
const bound = direction === "prev" ? min : max;
|
|
1795
|
+
if (bound) {
|
|
1796
|
+
const diff = monthIndex(entering) - monthIndex(bound);
|
|
1797
|
+
blocked = direction === "prev" ? diff < 0 : diff > 0;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
return {
|
|
1801
|
+
start: newStart,
|
|
1802
|
+
entering,
|
|
1803
|
+
firstDay: adjacent.firstDay,
|
|
1804
|
+
blocked
|
|
1805
|
+
};
|
|
1806
|
+
},
|
|
1807
|
+
isVisible(start, target) {
|
|
1808
|
+
const offset = monthIndex(target) - monthIndex(start);
|
|
1809
|
+
return offset >= 0 && offset < numberOfMonths;
|
|
1810
|
+
},
|
|
1811
|
+
reveal(start, target) {
|
|
1812
|
+
return shiftWindowToMonth(start, target, numberOfMonths);
|
|
1475
1813
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
function monthAt(start, offset) {
|
|
1817
|
+
const index = monthIndex(start) + offset;
|
|
1818
|
+
return {
|
|
1819
|
+
year: Math.floor(index / 12),
|
|
1820
|
+
month: index % 12 + 1
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
// src/month-view.tsx
|
|
1824
|
+
function MonthViewRoot(props) {
|
|
1825
|
+
const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, outOfRangeBehavior: outOfRangeBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
|
|
1826
|
+
const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
|
|
1827
|
+
const fixedWeeks = fixedWeeksProp ?? false;
|
|
1828
|
+
const outsideDays = outsideDaysProp ?? "enabled";
|
|
1829
|
+
const outOfRangeBehavior = outOfRangeBehaviorProp ?? "unbounded";
|
|
1830
|
+
const calStable = useCalendarStable();
|
|
1831
|
+
const calState = useCalendarState();
|
|
1832
|
+
const T = calStable.temporal;
|
|
1833
|
+
const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
|
|
1834
|
+
const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
|
|
1835
|
+
const gridFocusedRef = (0, react.useRef)(false);
|
|
1836
|
+
const { minValue, maxValue } = calStable;
|
|
1837
|
+
const windowPolicy = (0, react.useMemo)(() => createMonthWindowPolicy({
|
|
1838
|
+
numberOfMonths,
|
|
1839
|
+
behavior: outOfRangeBehavior,
|
|
1840
|
+
min: minValue,
|
|
1841
|
+
max: maxValue,
|
|
1842
|
+
T
|
|
1843
|
+
}), [
|
|
1844
|
+
numberOfMonths,
|
|
1845
|
+
outOfRangeBehavior,
|
|
1846
|
+
minValue,
|
|
1847
|
+
maxValue,
|
|
1848
|
+
T
|
|
1849
|
+
]);
|
|
1850
|
+
const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
|
|
1851
|
+
const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
|
|
1852
|
+
const opening = monthProp ?? defaultMonthProp;
|
|
1853
|
+
if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
|
|
1854
|
+
return T.PlainDate.from({
|
|
1855
|
+
year: opening.year,
|
|
1856
|
+
month: opening.month,
|
|
1857
|
+
day: 1
|
|
1858
|
+
});
|
|
1859
|
+
});
|
|
1860
|
+
const { currentMonth, viewingYearMonth, goNextMonth, goPrevMonth } = useMonthNavigation({
|
|
1861
|
+
month: monthProp,
|
|
1862
|
+
defaultMonth: defaultMonthProp,
|
|
1863
|
+
initialAnchor: (0, react.useCallback)(() => resolveInitialAnchor(calState.selected, today, timeZone, T), [
|
|
1864
|
+
calState.selected,
|
|
1865
|
+
today,
|
|
1866
|
+
timeZone,
|
|
1867
|
+
T
|
|
1868
|
+
]),
|
|
1869
|
+
onMonthChange,
|
|
1870
|
+
policy: windowPolicy,
|
|
1871
|
+
focusedDate,
|
|
1872
|
+
setFocusedDate,
|
|
1873
|
+
T
|
|
1874
|
+
});
|
|
1875
|
+
const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
|
|
1876
|
+
const setGridLabelId = (0, react.useCallback)((monthIndex, id) => {
|
|
1877
|
+
setGridLabelIds((prev) => {
|
|
1878
|
+
if (id === void 0) {
|
|
1879
|
+
if (!(monthIndex in prev)) return prev;
|
|
1880
|
+
const next = { ...prev };
|
|
1881
|
+
delete next[monthIndex];
|
|
1882
|
+
return next;
|
|
1883
|
+
}
|
|
1884
|
+
if (prev[monthIndex] === id) return prev;
|
|
1482
1885
|
return {
|
|
1483
|
-
|
|
1484
|
-
|
|
1886
|
+
...prev,
|
|
1887
|
+
[monthIndex]: id
|
|
1485
1888
|
};
|
|
1486
1889
|
});
|
|
1487
|
-
}, [
|
|
1488
|
-
T,
|
|
1489
|
-
isMonthControlled,
|
|
1490
|
-
monthProp,
|
|
1491
|
-
notifyMonth,
|
|
1492
|
-
focusedDate
|
|
1493
|
-
]);
|
|
1890
|
+
}, []);
|
|
1494
1891
|
const allMonths = (0, react.useMemo)(() => {
|
|
1495
1892
|
const opts = {
|
|
1496
1893
|
weekStartDay,
|
|
@@ -1550,19 +1947,6 @@ function MonthViewRoot(props) {
|
|
|
1550
1947
|
T,
|
|
1551
1948
|
gridHasFocus
|
|
1552
1949
|
]);
|
|
1553
|
-
const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
|
|
1554
|
-
year: currentMonth.year,
|
|
1555
|
-
month: currentMonth.month
|
|
1556
|
-
}), [currentMonth, T]);
|
|
1557
|
-
const mountedRef = (0, react.useRef)(false);
|
|
1558
|
-
(0, react.useEffect)(() => {
|
|
1559
|
-
if (!mountedRef.current) {
|
|
1560
|
-
mountedRef.current = true;
|
|
1561
|
-
return;
|
|
1562
|
-
}
|
|
1563
|
-
if (isMonthControlled) return;
|
|
1564
|
-
onMonthChangeRef.current?.(viewingYearMonth);
|
|
1565
|
-
}, [viewingYearMonth, isMonthControlled]);
|
|
1566
1950
|
const rootState = (0, react.useMemo)(() => ({
|
|
1567
1951
|
...calState.baseRootState,
|
|
1568
1952
|
focused: focusedDate,
|
|
@@ -1577,6 +1961,7 @@ function MonthViewRoot(props) {
|
|
|
1577
1961
|
fixedWeeks,
|
|
1578
1962
|
outsideDays,
|
|
1579
1963
|
outOfRangeBehavior,
|
|
1964
|
+
windowPolicy,
|
|
1580
1965
|
goNextMonth,
|
|
1581
1966
|
goPrevMonth,
|
|
1582
1967
|
setGridLabelId,
|
|
@@ -1586,6 +1971,7 @@ function MonthViewRoot(props) {
|
|
|
1586
1971
|
fixedWeeks,
|
|
1587
1972
|
outsideDays,
|
|
1588
1973
|
outOfRangeBehavior,
|
|
1974
|
+
windowPolicy,
|
|
1589
1975
|
goNextMonth,
|
|
1590
1976
|
goPrevMonth,
|
|
1591
1977
|
setGridLabelId
|
|
@@ -1617,13 +2003,28 @@ function MonthViewRoot(props) {
|
|
|
1617
2003
|
tabTargetDate,
|
|
1618
2004
|
gridHasFocus
|
|
1619
2005
|
]);
|
|
2006
|
+
const viewStableCtx = (0, react.useMemo)(() => ({
|
|
2007
|
+
gridFocusedRef,
|
|
2008
|
+
outsideDays,
|
|
2009
|
+
setFocusedDate
|
|
2010
|
+
}), [outsideDays]);
|
|
2011
|
+
const viewStateCtx = (0, react.useMemo)(() => ({
|
|
2012
|
+
currentDateTime,
|
|
2013
|
+
rootState
|
|
2014
|
+
}), [currentDateTime, rootState]);
|
|
1620
2015
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
1621
2016
|
value: stableCtx,
|
|
1622
2017
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
1623
2018
|
value: stateCtx,
|
|
1624
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1625
|
-
value:
|
|
1626
|
-
children
|
|
2019
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
|
|
2020
|
+
value: viewStableCtx,
|
|
2021
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
|
|
2022
|
+
value: viewStateCtx,
|
|
2023
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
|
|
2024
|
+
value: viewCtx,
|
|
2025
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellStoreProvider, { children })
|
|
2026
|
+
})
|
|
2027
|
+
})
|
|
1627
2028
|
})
|
|
1628
2029
|
})
|
|
1629
2030
|
});
|
|
@@ -1645,21 +2046,10 @@ function MonthView(props) {
|
|
|
1645
2046
|
});
|
|
1646
2047
|
}
|
|
1647
2048
|
MonthView.Root = MonthViewRoot;
|
|
1648
|
-
|
|
1649
|
-
//#region src/context.ts
|
|
1650
|
-
/** @internal Provides the days and index of the current week row to child components. */
|
|
1651
|
-
const WeekDataContext = (0, react.createContext)(null);
|
|
1652
|
-
/** @internal Provides the resolved grid orientation to descendant cells. */
|
|
1653
|
-
const GridContext = (0, react.createContext)({ orientation: "horizontal" });
|
|
1654
|
-
/** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
|
|
1655
|
-
const DayCellDataContext = (0, react.createContext)(null);
|
|
1656
|
-
/** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
|
|
1657
|
-
const GridMonthContext = (0, react.createContext)(null);
|
|
1658
|
-
//#endregion
|
|
1659
|
-
//#region src/grid-header.tsx
|
|
2049
|
+
// src/grid-header.tsx
|
|
1660
2050
|
function useGridHeaderCellState(index) {
|
|
1661
2051
|
const { locale, temporal: T, weekStartDay } = useCalendarStable();
|
|
1662
|
-
const { rootState } =
|
|
2052
|
+
const { rootState } = useViewState();
|
|
1663
2053
|
const weekdayNames = (0, react.useMemo)(() => getWeekdayNames(locale, T, weekStartDay), [
|
|
1664
2054
|
locale,
|
|
1665
2055
|
T,
|
|
@@ -1735,7 +2125,7 @@ function GridHeaderCellFn(props, ref) {
|
|
|
1735
2125
|
const GridHeaderCell = (0, react.forwardRef)(GridHeaderCellFn);
|
|
1736
2126
|
function GridHeaderFn(props, ref) {
|
|
1737
2127
|
const { render, children, ...otherProps } = props;
|
|
1738
|
-
const { rootState } =
|
|
2128
|
+
const { rootState } = useViewState();
|
|
1739
2129
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
1740
2130
|
return (0, _base_ui_react_use_render.useRender)({
|
|
1741
2131
|
defaultTagName: "thead",
|
|
@@ -1748,8 +2138,7 @@ function GridHeaderFn(props, ref) {
|
|
|
1748
2138
|
}
|
|
1749
2139
|
/** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
|
|
1750
2140
|
const GridHeader = (0, react.forwardRef)(GridHeaderFn);
|
|
1751
|
-
|
|
1752
|
-
//#region src/keyboard.ts
|
|
2141
|
+
// src/keyboard.ts
|
|
1753
2142
|
/**
|
|
1754
2143
|
* Computes the target date when jumping by `months` from `focusedDate`.
|
|
1755
2144
|
*
|
|
@@ -1822,8 +2211,7 @@ function computeNextFocusDate(input) {
|
|
|
1822
2211
|
if (nextDate) return clampToBounds(nextDate, focusedDate, minValue, maxValue, T);
|
|
1823
2212
|
return { action: "none" };
|
|
1824
2213
|
}
|
|
1825
|
-
|
|
1826
|
-
//#region src/month-separator.tsx
|
|
2214
|
+
// src/month-separator.tsx
|
|
1827
2215
|
/** Context providing MonthSeparator data to child components. */
|
|
1828
2216
|
const MonthSeparatorDataContext = (0, react.createContext)(null);
|
|
1829
2217
|
function useMonthSeparatorData() {
|
|
@@ -1953,8 +2341,7 @@ function MonthSeparatorFn(props, ref) {
|
|
|
1953
2341
|
* Default children: `<Month /> <Year />`.
|
|
1954
2342
|
*/
|
|
1955
2343
|
const MonthSeparator = (0, react.forwardRef)(MonthSeparatorFn);
|
|
1956
|
-
|
|
1957
|
-
//#region src/weeks-view-context.ts
|
|
2344
|
+
// src/weeks-view-context.ts
|
|
1958
2345
|
/** @internal React context for WeeksView stable values (config + callbacks). */
|
|
1959
2346
|
const WeeksViewStableContext = (0, react.createContext)(null);
|
|
1960
2347
|
/** @internal React context for WeeksView volatile state. */
|
|
@@ -1971,8 +2358,7 @@ function useWeeksViewState() {
|
|
|
1971
2358
|
if (!ctx) throw new Error("useWeeksViewState must be used within WeeksView.Root");
|
|
1972
2359
|
return ctx;
|
|
1973
2360
|
}
|
|
1974
|
-
|
|
1975
|
-
//#region src/weeks-grid.tsx
|
|
2361
|
+
// src/weeks-grid.tsx
|
|
1976
2362
|
/**
|
|
1977
2363
|
* @internal WeeksGrid — renders continuous week rows for WeeksView.
|
|
1978
2364
|
* Not exported from the public API.
|
|
@@ -2106,28 +2492,35 @@ function WeeksGrid(props) {
|
|
|
2106
2492
|
}
|
|
2107
2493
|
return map;
|
|
2108
2494
|
}, [monthBoundaries]);
|
|
2495
|
+
const rowValues = (0, react.useMemo)(() => weeks.map((week, i) => {
|
|
2496
|
+
const days = weekDaysArrays[i] ?? [];
|
|
2497
|
+
return {
|
|
2498
|
+
weekData: {
|
|
2499
|
+
days,
|
|
2500
|
+
weekIndex: week.weekIndex,
|
|
2501
|
+
gridRowIndex: i + 2
|
|
2502
|
+
},
|
|
2503
|
+
gridMonth: {
|
|
2504
|
+
weeks: [days],
|
|
2505
|
+
year: week.year,
|
|
2506
|
+
month: week.month
|
|
2507
|
+
}
|
|
2508
|
+
};
|
|
2509
|
+
}), [weeks, weekDaysArrays]);
|
|
2109
2510
|
const rows = [];
|
|
2110
2511
|
for (const [i, week] of weeks.entries()) {
|
|
2111
|
-
|
|
2112
|
-
if (days === void 0) continue;
|
|
2512
|
+
if (weekDaysArrays[i] === void 0) continue;
|
|
2113
2513
|
const separators = boundariesAtIndex.get(i);
|
|
2114
2514
|
if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorDataContext.Provider, {
|
|
2115
2515
|
value: separatorData,
|
|
2116
2516
|
children: separatorTemplate
|
|
2117
2517
|
}, `sep-${separatorData.year}-${separatorData.month}`));
|
|
2118
|
-
const
|
|
2518
|
+
const rowValue = rowValues[i];
|
|
2519
|
+
if (rowValue === void 0) continue;
|
|
2119
2520
|
rows.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
|
|
2120
|
-
value:
|
|
2121
|
-
days,
|
|
2122
|
-
weekIndex: week.weekIndex,
|
|
2123
|
-
gridRowIndex: weekGridRow
|
|
2124
|
-
},
|
|
2521
|
+
value: rowValue.weekData,
|
|
2125
2522
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridMonthContext.Provider, {
|
|
2126
|
-
value:
|
|
2127
|
-
weeks: [days],
|
|
2128
|
-
year: week.year,
|
|
2129
|
-
month: week.month
|
|
2130
|
-
},
|
|
2523
|
+
value: rowValue.gridMonth,
|
|
2131
2524
|
children: weekRowChildren
|
|
2132
2525
|
})
|
|
2133
2526
|
}, week.startDate.toString()));
|
|
@@ -2138,8 +2531,7 @@ function WeeksGrid(props) {
|
|
|
2138
2531
|
children: rows
|
|
2139
2532
|
});
|
|
2140
2533
|
}
|
|
2141
|
-
|
|
2142
|
-
//#region src/weeks-keyboard.ts
|
|
2534
|
+
// src/weeks-keyboard.ts
|
|
2143
2535
|
const NONE = {
|
|
2144
2536
|
action: "none",
|
|
2145
2537
|
windowShift: 0,
|
|
@@ -2213,132 +2605,7 @@ function computeWeeksKeyNav(input) {
|
|
|
2213
2605
|
default: return NONE;
|
|
2214
2606
|
}
|
|
2215
2607
|
}
|
|
2216
|
-
|
|
2217
|
-
//#region src/day-cell.tsx
|
|
2218
|
-
/** Computes derived day cell state from context values. Pure function, no hooks. */
|
|
2219
|
-
function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd) {
|
|
2220
|
-
const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
|
|
2221
|
-
if (!isCurrentMonth && outsideDays === "hidden") return {
|
|
2222
|
-
root: rootState,
|
|
2223
|
-
date,
|
|
2224
|
-
columnIndex,
|
|
2225
|
-
orientation,
|
|
2226
|
-
outsideMonth: true,
|
|
2227
|
-
hidden: true,
|
|
2228
|
-
selected: false,
|
|
2229
|
-
today: false,
|
|
2230
|
-
disabled: true,
|
|
2231
|
-
focused: false,
|
|
2232
|
-
rangeStart: false,
|
|
2233
|
-
rangeEnd: false,
|
|
2234
|
-
rangeBoundary: false,
|
|
2235
|
-
inRange: false,
|
|
2236
|
-
rangeIndex: false,
|
|
2237
|
-
rangeLength: false,
|
|
2238
|
-
rangeHasStart: false,
|
|
2239
|
-
rangeHasEnd: false,
|
|
2240
|
-
rangePreviewStart: false,
|
|
2241
|
-
rangePreviewEnd: false,
|
|
2242
|
-
rangePreviewBoundary: false,
|
|
2243
|
-
rangePreviewInRange: false,
|
|
2244
|
-
rangePreviewIndex: false,
|
|
2245
|
-
rangePreviewLength: false,
|
|
2246
|
-
rangePreviewHasStart: false,
|
|
2247
|
-
rangePreviewHasEnd: false,
|
|
2248
|
-
isTabTarget: false
|
|
2249
|
-
};
|
|
2250
|
-
const today = T.Now.plainDateISO();
|
|
2251
|
-
const isToday = T.PlainDate.compare(date, today) === 0;
|
|
2252
|
-
const isRange = selectionMode === "range";
|
|
2253
|
-
let isRangeStart = false;
|
|
2254
|
-
let isRangeEnd = false;
|
|
2255
|
-
let isInRangeDay = false;
|
|
2256
|
-
let rangeIdx = false;
|
|
2257
|
-
let rangeLen = false;
|
|
2258
|
-
let isPreviewRangeStart = false;
|
|
2259
|
-
let isPreviewRangeEnd = false;
|
|
2260
|
-
let isInPreviewRange = false;
|
|
2261
|
-
let previewIdx = false;
|
|
2262
|
-
let previewLen = false;
|
|
2263
|
-
if (isRange) {
|
|
2264
|
-
isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
|
|
2265
|
-
isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
|
|
2266
|
-
isInRangeDay = isInRange(date, rangeStart, rangeEnd, T) !== false;
|
|
2267
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
2268
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
2269
|
-
rangeIdx = isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
|
|
2270
|
-
rangeLen = isInRangeDay && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false;
|
|
2271
|
-
isPreviewRangeStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
|
|
2272
|
-
isPreviewRangeEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
|
|
2273
|
-
isInPreviewRange = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
|
|
2274
|
-
previewIdx = isInPreviewRange && previewStart ? date.since(previewStart).days : false;
|
|
2275
|
-
previewLen = isInPreviewRange && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false;
|
|
2276
|
-
}
|
|
2277
|
-
const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
|
|
2278
|
-
const suppressRange = !isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
|
|
2279
|
-
if (outsideNonInteractive) return {
|
|
2280
|
-
root: rootState,
|
|
2281
|
-
date,
|
|
2282
|
-
columnIndex,
|
|
2283
|
-
orientation,
|
|
2284
|
-
outsideMonth: true,
|
|
2285
|
-
hidden: false,
|
|
2286
|
-
selected: false,
|
|
2287
|
-
today: isToday,
|
|
2288
|
-
disabled: true,
|
|
2289
|
-
focused: false,
|
|
2290
|
-
rangeStart: suppressRange ? false : isRangeStart,
|
|
2291
|
-
rangeEnd: suppressRange ? false : isRangeEnd,
|
|
2292
|
-
rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
|
|
2293
|
-
inRange: suppressRange ? false : isInRangeDay,
|
|
2294
|
-
rangeIndex: suppressRange ? false : rangeIdx,
|
|
2295
|
-
rangeLength: suppressRange ? false : rangeLen,
|
|
2296
|
-
rangeHasStart: suppressRange ? false : isInRangeDay && rangeStart !== void 0,
|
|
2297
|
-
rangeHasEnd: suppressRange ? false : isInRangeDay && rangeEnd !== void 0,
|
|
2298
|
-
rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
|
|
2299
|
-
rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
|
|
2300
|
-
rangePreviewBoundary: suppressRange ? false : isPreviewRangeStart || isPreviewRangeEnd,
|
|
2301
|
-
rangePreviewInRange: suppressRange ? false : isInPreviewRange,
|
|
2302
|
-
rangePreviewIndex: suppressRange ? false : previewIdx,
|
|
2303
|
-
rangePreviewLength: suppressRange ? false : previewLen,
|
|
2304
|
-
rangePreviewHasStart: suppressRange ? false : isInPreviewRange && previewStart !== void 0,
|
|
2305
|
-
rangePreviewHasEnd: suppressRange ? false : isInPreviewRange && previewEnd !== void 0,
|
|
2306
|
-
isTabTarget: false
|
|
2307
|
-
};
|
|
2308
|
-
const isSelected = selectionMode !== "range" ? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false;
|
|
2309
|
-
const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
|
|
2310
|
-
const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
|
|
2311
|
-
const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
|
|
2312
|
-
return {
|
|
2313
|
-
root: rootState,
|
|
2314
|
-
date,
|
|
2315
|
-
columnIndex,
|
|
2316
|
-
orientation,
|
|
2317
|
-
selected: isSelected,
|
|
2318
|
-
today: isToday,
|
|
2319
|
-
disabled: isDisabled,
|
|
2320
|
-
outsideMonth: !isCurrentMonth,
|
|
2321
|
-
hidden: false,
|
|
2322
|
-
focused: isFocused,
|
|
2323
|
-
rangeStart: isRangeStart,
|
|
2324
|
-
rangeEnd: isRangeEnd,
|
|
2325
|
-
rangeBoundary: isRangeStart || isRangeEnd,
|
|
2326
|
-
inRange: isInRangeDay,
|
|
2327
|
-
rangeIndex: rangeIdx,
|
|
2328
|
-
rangeLength: rangeLen,
|
|
2329
|
-
rangeHasStart: isInRangeDay && rangeStart !== void 0,
|
|
2330
|
-
rangeHasEnd: isInRangeDay && rangeEnd !== void 0,
|
|
2331
|
-
rangePreviewStart: isPreviewRangeStart,
|
|
2332
|
-
rangePreviewEnd: isPreviewRangeEnd,
|
|
2333
|
-
rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
|
|
2334
|
-
rangePreviewInRange: isInPreviewRange,
|
|
2335
|
-
rangePreviewIndex: previewIdx,
|
|
2336
|
-
rangePreviewLength: previewLen,
|
|
2337
|
-
rangePreviewHasStart: isInPreviewRange && previewStart !== void 0,
|
|
2338
|
-
rangePreviewHasEnd: isInPreviewRange && previewEnd !== void 0,
|
|
2339
|
-
isTabTarget
|
|
2340
|
-
};
|
|
2341
|
-
}
|
|
2608
|
+
// src/day-cell.tsx
|
|
2342
2609
|
const dayStateAttributesMapping = {
|
|
2343
2610
|
root: () => null,
|
|
2344
2611
|
date: (v) => v ? { "data-date": v.toString() } : null,
|
|
@@ -2367,34 +2634,46 @@ const dayStateAttributesMapping = {
|
|
|
2367
2634
|
rangePreviewHasStart: (v) => v ? { "data-range-preview-has-start": "" } : null,
|
|
2368
2635
|
rangePreviewHasEnd: (v) => v ? { "data-range-preview-has-end": "" } : null
|
|
2369
2636
|
};
|
|
2637
|
+
/** @internal The enclosing day cell's state, read by its `DayButton`. */
|
|
2638
|
+
const DayCellStateContext = (0, react.createContext)(null);
|
|
2370
2639
|
function DayCellInstanceFn(props) {
|
|
2371
|
-
const { render, date, columnIndex,
|
|
2372
|
-
const
|
|
2640
|
+
const { render, date, columnIndex, gridMonth, children, ...otherProps } = props;
|
|
2641
|
+
const derived = useDayCellState(date, columnIndex, gridMonth);
|
|
2642
|
+
const state = derived;
|
|
2643
|
+
const defaultProps = state.hidden ? {
|
|
2644
|
+
role: "gridcell",
|
|
2645
|
+
"aria-hidden": true,
|
|
2646
|
+
children: null
|
|
2647
|
+
} : {
|
|
2648
|
+
role: "gridcell",
|
|
2649
|
+
"aria-selected": state.selected || void 0,
|
|
2650
|
+
"aria-disabled": state.disabled || void 0,
|
|
2651
|
+
children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {})
|
|
2652
|
+
};
|
|
2373
2653
|
const cell = (0, _base_ui_react_use_render.useRender)({
|
|
2374
2654
|
defaultTagName: "td",
|
|
2375
2655
|
render,
|
|
2376
2656
|
ref: [],
|
|
2377
2657
|
state,
|
|
2378
2658
|
stateAttributesMapping: dayStateAttributesMapping,
|
|
2379
|
-
props: (0, _base_ui_react_merge_props.mergeProps)(
|
|
2380
|
-
role: "gridcell",
|
|
2381
|
-
"aria-hidden": true,
|
|
2382
|
-
children: null
|
|
2383
|
-
} : {
|
|
2384
|
-
role: "gridcell",
|
|
2385
|
-
"aria-selected": state.selected || void 0,
|
|
2386
|
-
"aria-disabled": state.disabled || void 0,
|
|
2387
|
-
children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, { _derivedState })
|
|
2388
|
-
}, otherProps)
|
|
2659
|
+
props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
|
|
2389
2660
|
});
|
|
2390
2661
|
const outsideDisabled = state.hidden || state.outsideMonth && state.disabled;
|
|
2662
|
+
const cellData = (0, react.useMemo)(() => ({
|
|
2663
|
+
date,
|
|
2664
|
+
columnIndex,
|
|
2665
|
+
outsideDisabled
|
|
2666
|
+
}), [
|
|
2667
|
+
date,
|
|
2668
|
+
columnIndex,
|
|
2669
|
+
outsideDisabled
|
|
2670
|
+
]);
|
|
2391
2671
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellDataContext.Provider, {
|
|
2392
|
-
value:
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
}
|
|
2397
|
-
children: cell
|
|
2672
|
+
value: cellData,
|
|
2673
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellStateContext.Provider, {
|
|
2674
|
+
value: derived,
|
|
2675
|
+
children: cell
|
|
2676
|
+
})
|
|
2398
2677
|
});
|
|
2399
2678
|
}
|
|
2400
2679
|
/**
|
|
@@ -2410,26 +2689,35 @@ function passThroughPropsEqual(prev, next, handledKeys) {
|
|
|
2410
2689
|
for (const key of prevKeys) if (prev[key] !== next[key]) return false;
|
|
2411
2690
|
return true;
|
|
2412
2691
|
}
|
|
2413
|
-
const DAY_CELL_HANDLED_KEYS = new Set([
|
|
2692
|
+
const DAY_CELL_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2414
2693
|
"render",
|
|
2415
2694
|
"date",
|
|
2416
2695
|
"columnIndex",
|
|
2417
|
-
"
|
|
2418
|
-
"
|
|
2696
|
+
"gridMonth",
|
|
2697
|
+
"children"
|
|
2419
2698
|
]);
|
|
2420
|
-
const DAY_BUTTON_HANDLED_KEYS = new Set([
|
|
2699
|
+
const DAY_BUTTON_HANDLED_KEYS = /* @__PURE__ */ new Set([
|
|
2421
2700
|
"render",
|
|
2422
2701
|
"date",
|
|
2423
2702
|
"children",
|
|
2424
|
-
"
|
|
2703
|
+
"_state"
|
|
2425
2704
|
]);
|
|
2705
|
+
/**
|
|
2706
|
+
* Whether a day cell can skip a parent re-render. Its own state comes from
|
|
2707
|
+
* the store, so only props are compared here.
|
|
2708
|
+
*/
|
|
2426
2709
|
function dayCellInstancePropsAreEqual(prev, next) {
|
|
2427
|
-
|
|
2428
|
-
const a = prev._derivedState;
|
|
2429
|
-
const b = next._derivedState;
|
|
2430
|
-
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);
|
|
2710
|
+
return prev.date === next.date && prev.render === next.render && prev.columnIndex === next.columnIndex && prev.gridMonth === next.gridMonth && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2431
2711
|
}
|
|
2432
2712
|
const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
2713
|
+
/** The cells of a whole month, for a `DayCellTemplate` outside any week row. */
|
|
2714
|
+
function MonthDayCells(props) {
|
|
2715
|
+
const days = (0, react.useContext)(MonthViewStateContext)?.weeks.flat() ?? [];
|
|
2716
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2717
|
+
...props,
|
|
2718
|
+
date: day
|
|
2719
|
+
}, day.toString())) });
|
|
2720
|
+
}
|
|
2433
2721
|
/**
|
|
2434
2722
|
* Renders one `<td role="gridcell">` per day. Exposes data-attributes for
|
|
2435
2723
|
* `selected`, `today`, `disabled`, `outside-month`, `focused`,
|
|
@@ -2441,58 +2729,32 @@ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsA
|
|
|
2441
2729
|
function DayCellTemplate(props) {
|
|
2442
2730
|
const { date: dateProp, ...restProps } = props;
|
|
2443
2731
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
|
|
2457
|
-
year: dateProp.year,
|
|
2458
|
-
month: dateProp.month
|
|
2459
|
-
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2460
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2461
|
-
...restProps,
|
|
2462
|
-
date: dateProp,
|
|
2463
|
-
_derivedState: derived
|
|
2464
|
-
});
|
|
2465
|
-
}
|
|
2466
|
-
const days = weekData ? weekData.days : weeks.flat();
|
|
2467
|
-
const perWeek = weekData != null;
|
|
2468
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
|
|
2469
|
-
const daysInWeek = day.daysInWeek;
|
|
2470
|
-
const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
|
|
2471
|
-
year: day.year,
|
|
2472
|
-
month: day.month
|
|
2473
|
-
} : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
|
|
2474
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2475
|
-
...restProps,
|
|
2476
|
-
date: day,
|
|
2477
|
-
columnIndex: perWeek ? i : void 0,
|
|
2478
|
-
_derivedState: derived
|
|
2479
|
-
}, day.toString());
|
|
2480
|
-
}) });
|
|
2732
|
+
if (dateProp) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2733
|
+
...restProps,
|
|
2734
|
+
date: dateProp,
|
|
2735
|
+
gridMonth: weekData?.gridMonth
|
|
2736
|
+
});
|
|
2737
|
+
if (!weekData) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthDayCells, { ...restProps });
|
|
2738
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: weekData.days.map((day, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
|
|
2739
|
+
...restProps,
|
|
2740
|
+
date: day,
|
|
2741
|
+
columnIndex: i,
|
|
2742
|
+
gridMonth: weekData.gridMonth
|
|
2743
|
+
}, day.toString())) });
|
|
2481
2744
|
}
|
|
2482
2745
|
function DayButtonInnerFn(props, ref) {
|
|
2483
|
-
const { render, date,
|
|
2746
|
+
const { render, date, _state, ...otherProps } = props;
|
|
2484
2747
|
const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
|
|
2485
|
-
const { setFocusedDate } =
|
|
2486
|
-
const gridFocusedRef = (0, react.useContext)(MonthViewStableContext).gridFocusedRef;
|
|
2748
|
+
const { gridFocusedRef, setFocusedDate } = useViewStable();
|
|
2487
2749
|
const internalRef = (0, react.useRef)(null);
|
|
2488
|
-
const isHidden =
|
|
2489
|
-
const isFocused =
|
|
2490
|
-
const isTabTarget =
|
|
2491
|
-
const isDisabled =
|
|
2750
|
+
const isHidden = _state.hidden;
|
|
2751
|
+
const isFocused = _state.focused;
|
|
2752
|
+
const isTabTarget = _state.isTabTarget;
|
|
2753
|
+
const isDisabled = _state.disabled;
|
|
2492
2754
|
(0, react.useEffect)(() => {
|
|
2493
2755
|
if (shouldMoveDomFocus(isFocused, gridFocusedRef.current) && internalRef.current) internalRef.current.focus();
|
|
2494
2756
|
}, [isFocused, gridFocusedRef]);
|
|
2495
|
-
const state =
|
|
2757
|
+
const state = _state;
|
|
2496
2758
|
const defaultProps = isHidden ? {} : {
|
|
2497
2759
|
type: "button",
|
|
2498
2760
|
tabIndex: isTabTarget ? 0 : -1,
|
|
@@ -2524,12 +2786,7 @@ function DayButtonInnerFn(props, ref) {
|
|
|
2524
2786
|
});
|
|
2525
2787
|
}
|
|
2526
2788
|
function dayButtonInnerPropsAreEqual(prev, next) {
|
|
2527
|
-
|
|
2528
|
-
if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
|
|
2529
|
-
const a = prev._derivedState;
|
|
2530
|
-
const b = next._derivedState;
|
|
2531
|
-
if (!a || !b) return a === b;
|
|
2532
|
-
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;
|
|
2789
|
+
return prev.date === next.date && prev.render === next.render && prev._state === next._state && passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS);
|
|
2533
2790
|
}
|
|
2534
2791
|
const DayButtonInner = (0, react.memo)((0, react.forwardRef)(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
|
|
2535
2792
|
/**
|
|
@@ -2539,53 +2796,37 @@ const DayButtonInner = (0, react.memo)((0, react.forwardRef)(DayButtonInnerFn),
|
|
|
2539
2796
|
* Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
|
|
2540
2797
|
*/
|
|
2541
2798
|
function DayButtonFn(props, ref) {
|
|
2542
|
-
const { date: dateProp,
|
|
2799
|
+
const { date: dateProp, ...restProps } = props;
|
|
2800
|
+
const cellState = (0, react.useContext)(DayCellStateContext);
|
|
2543
2801
|
const cellData = (0, react.useContext)(DayCellDataContext);
|
|
2802
|
+
if (cellState && (!dateProp || dateProp.equals(cellState.date))) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
|
|
2803
|
+
...restProps,
|
|
2804
|
+
ref,
|
|
2805
|
+
date: cellState.date,
|
|
2806
|
+
_state: cellState
|
|
2807
|
+
});
|
|
2544
2808
|
const resolvedDate = dateProp ?? cellData?.date;
|
|
2545
|
-
if (resolvedDate) {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
_derivedState
|
|
2551
|
-
});
|
|
2552
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonFallback, {
|
|
2553
|
-
ref,
|
|
2554
|
-
...restProps,
|
|
2555
|
-
date: resolvedDate
|
|
2556
|
-
});
|
|
2557
|
-
}
|
|
2809
|
+
if (resolvedDate) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StandaloneDayButton, {
|
|
2810
|
+
...restProps,
|
|
2811
|
+
ref,
|
|
2812
|
+
date: resolvedDate
|
|
2813
|
+
});
|
|
2558
2814
|
throw new Error("DayButton must be used inside DayCellTemplate or receive an explicit date prop.");
|
|
2559
2815
|
}
|
|
2560
2816
|
const DayButton = (0, react.forwardRef)(DayButtonFn);
|
|
2561
|
-
/**
|
|
2562
|
-
function
|
|
2817
|
+
/** A `DayButton` outside any day cell: subscribes to its own date's state. */
|
|
2818
|
+
function StandaloneDayButtonFn(props, ref) {
|
|
2563
2819
|
const { date, ...restProps } = props;
|
|
2564
|
-
const
|
|
2565
|
-
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2566
|
-
const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
|
|
2567
|
-
const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
|
|
2568
|
-
const viewCtx = useViewContext();
|
|
2569
|
-
const { focusedDate, tabTargetDate } = viewCtx;
|
|
2570
|
-
const monthStable = (0, react.useContext)(MonthViewStableContext);
|
|
2571
|
-
const { rootState, currentMonth: currentDateTime } = useMonthViewState();
|
|
2572
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
2573
|
-
const cellMonth = viewCtx.viewType === "weeks" ? {
|
|
2574
|
-
year: date.year,
|
|
2575
|
-
month: date.month
|
|
2576
|
-
} : weekData?.gridMonth ?? currentDateTime;
|
|
2577
|
-
const daysInWeek = date.daysInWeek;
|
|
2578
|
-
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);
|
|
2820
|
+
const state = useStandaloneDayCellState(date);
|
|
2579
2821
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
|
|
2580
2822
|
...restProps,
|
|
2581
2823
|
ref,
|
|
2582
2824
|
date,
|
|
2583
|
-
|
|
2825
|
+
_state: state
|
|
2584
2826
|
});
|
|
2585
2827
|
}
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2588
|
-
//#region src/grid.tsx
|
|
2828
|
+
const StandaloneDayButton = (0, react.forwardRef)(StandaloneDayButtonFn);
|
|
2829
|
+
// src/grid.tsx
|
|
2589
2830
|
function useGridKeyboard() {
|
|
2590
2831
|
const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
|
|
2591
2832
|
const { focusedDate, setFocusedDate } = useViewContext();
|
|
@@ -2633,7 +2874,7 @@ function useWeeksGridKeyboard() {
|
|
|
2633
2874
|
shiftKey: e.shiftKey,
|
|
2634
2875
|
focusedDate,
|
|
2635
2876
|
windowStart: weeksState.windowInfo.windowStart,
|
|
2636
|
-
weekCount:
|
|
2877
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
2637
2878
|
minValue,
|
|
2638
2879
|
maxValue,
|
|
2639
2880
|
disabled,
|
|
@@ -2685,17 +2926,15 @@ const gridStateAttributesMapping = {
|
|
|
2685
2926
|
* delegates to the appropriate internal renderer.
|
|
2686
2927
|
*/
|
|
2687
2928
|
function GridFn(props, ref) {
|
|
2688
|
-
const
|
|
2689
|
-
|
|
2690
|
-
|
|
2929
|
+
const view = (0, react.useContext)(ViewContext);
|
|
2930
|
+
if (!view) throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
|
|
2931
|
+
return view.viewType === "weeks" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
|
|
2691
2932
|
ref,
|
|
2692
2933
|
...props
|
|
2693
|
-
})
|
|
2694
|
-
if (weeksState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
|
|
2934
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGrid, {
|
|
2695
2935
|
ref,
|
|
2696
2936
|
...props
|
|
2697
2937
|
});
|
|
2698
|
-
throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
|
|
2699
2938
|
}
|
|
2700
2939
|
const Grid = (0, react.forwardRef)(GridFn);
|
|
2701
2940
|
function MonthGridFn(props, ref) {
|
|
@@ -2802,7 +3041,7 @@ function WeeksViewGridFn(props, ref) {
|
|
|
2802
3041
|
const weeksStable = useWeeksViewStable();
|
|
2803
3042
|
const weeksState = useWeeksViewState();
|
|
2804
3043
|
const { gridFocusedRef } = weeksStable;
|
|
2805
|
-
const { gridLabelIds, weeks
|
|
3044
|
+
const { gridLabelIds, weeks } = weeksState;
|
|
2806
3045
|
const handleKeyDown = useWeeksGridKeyboard();
|
|
2807
3046
|
const gridRef = (0, react.useRef)(null);
|
|
2808
3047
|
(0, react.useEffect)(() => {
|
|
@@ -2873,47 +3112,16 @@ function WeeksViewGridFn(props, ref) {
|
|
|
2873
3112
|
props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
|
|
2874
3113
|
});
|
|
2875
3114
|
const orientationCtx = (0, react.useMemo)(() => ({ orientation: resolvedOrientation }), [resolvedOrientation]);
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
outsideDays: "enabled",
|
|
2880
|
-
outOfRangeBehavior: "unbounded",
|
|
2881
|
-
goNextMonth: () => {},
|
|
2882
|
-
goPrevMonth: () => {},
|
|
2883
|
-
setGridLabelId: () => {},
|
|
2884
|
-
gridFocusedRef
|
|
2885
|
-
}), [gridFocusedRef]);
|
|
2886
|
-
const monthViewStateShim = (0, react.useMemo)(() => ({
|
|
2887
|
-
currentMonth: {
|
|
2888
|
-
year: currentDateTime.year,
|
|
2889
|
-
month: currentDateTime.month
|
|
2890
|
-
},
|
|
2891
|
-
weeks: [],
|
|
2892
|
-
allMonths: [],
|
|
2893
|
-
currentDateTime,
|
|
2894
|
-
gridLabelIds,
|
|
2895
|
-
rootState: weeksState.rootState
|
|
2896
|
-
}), [
|
|
2897
|
-
currentDateTime,
|
|
2898
|
-
gridLabelIds,
|
|
2899
|
-
weeksState.rootState
|
|
2900
|
-
]);
|
|
2901
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
2902
|
-
value: monthViewStableShim,
|
|
2903
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
2904
|
-
value: monthViewStateShim,
|
|
2905
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
|
|
2906
|
-
value: orientationCtx,
|
|
2907
|
-
children: el
|
|
2908
|
-
})
|
|
2909
|
-
})
|
|
3115
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
|
|
3116
|
+
value: orientationCtx,
|
|
3117
|
+
children: el
|
|
2910
3118
|
});
|
|
2911
3119
|
}
|
|
2912
3120
|
const WeeksViewGrid = (0, react.forwardRef)(WeeksViewGridFn);
|
|
2913
3121
|
const gridBodyStateAttributesMapping = { root: () => null };
|
|
2914
3122
|
/** Table body wrapping the week rows. Renders a `<tbody>` by default. */
|
|
2915
3123
|
function GridBodyFn(props, ref) {
|
|
2916
|
-
if ((0, react.useContext)(
|
|
3124
|
+
if ((0, react.useContext)(ViewContext)?.viewType === "weeks") {
|
|
2917
3125
|
const { children, className, style } = props;
|
|
2918
3126
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksGrid, {
|
|
2919
3127
|
className,
|
|
@@ -2929,7 +3137,7 @@ function GridBodyFn(props, ref) {
|
|
|
2929
3137
|
const GridBody = (0, react.forwardRef)(GridBodyFn);
|
|
2930
3138
|
function MonthGridBodyFn(props, ref) {
|
|
2931
3139
|
const { render, ...otherProps } = props;
|
|
2932
|
-
const { rootState } =
|
|
3140
|
+
const { rootState } = useViewState();
|
|
2933
3141
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
2934
3142
|
const defaultProps = { children: props.children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) };
|
|
2935
3143
|
const { children: _children, ...restOtherProps } = otherProps;
|
|
@@ -2951,20 +3159,21 @@ const weekInstanceStateAttributesMapping = {
|
|
|
2951
3159
|
function WeekInstance(props) {
|
|
2952
3160
|
const { render, ...otherProps } = props;
|
|
2953
3161
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
2954
|
-
const { rootState } =
|
|
3162
|
+
const { rootState } = useViewState();
|
|
3163
|
+
const state = (0, react.useMemo)(() => ({
|
|
3164
|
+
root: rootState,
|
|
3165
|
+
weekIndex: weekData.weekIndex,
|
|
3166
|
+
gridRowIndex: weekData.gridRowIndex
|
|
3167
|
+
}), [
|
|
3168
|
+
rootState,
|
|
3169
|
+
weekData.weekIndex,
|
|
3170
|
+
weekData.gridRowIndex
|
|
3171
|
+
]);
|
|
2955
3172
|
return (0, _base_ui_react_use_render.useRender)({
|
|
2956
3173
|
defaultTagName: "tr",
|
|
2957
3174
|
render,
|
|
2958
3175
|
ref: [],
|
|
2959
|
-
state
|
|
2960
|
-
root: rootState,
|
|
2961
|
-
weekIndex: weekData.weekIndex,
|
|
2962
|
-
gridRowIndex: weekData.gridRowIndex
|
|
2963
|
-
}), [
|
|
2964
|
-
rootState,
|
|
2965
|
-
weekData.weekIndex,
|
|
2966
|
-
weekData.gridRowIndex
|
|
2967
|
-
]),
|
|
3176
|
+
state,
|
|
2968
3177
|
stateAttributesMapping: weekInstanceStateAttributesMapping,
|
|
2969
3178
|
props: (0, _base_ui_react_merge_props.mergeProps)({}, otherProps)
|
|
2970
3179
|
});
|
|
@@ -2976,29 +3185,33 @@ function WeekInstance(props) {
|
|
|
2976
3185
|
function WeekTemplate(props) {
|
|
2977
3186
|
const outerWeekData = (0, react.useContext)(WeekDataContext);
|
|
2978
3187
|
const gridMonthCtx = (0, react.useContext)(GridMonthContext);
|
|
2979
|
-
const
|
|
2980
|
-
const weeks = gridMonthCtx?.weeks ??
|
|
3188
|
+
const monthState = (0, react.useContext)(MonthViewStateContext);
|
|
3189
|
+
const weeks = gridMonthCtx?.weeks ?? monthState?.weeks ?? [];
|
|
2981
3190
|
const gridMonth = (0, react.useMemo)(() => gridMonthCtx ? {
|
|
2982
3191
|
year: gridMonthCtx.year,
|
|
2983
3192
|
month: gridMonthCtx.month
|
|
2984
3193
|
} : void 0, [gridMonthCtx]);
|
|
2985
|
-
const
|
|
2986
|
-
|
|
2987
|
-
|
|
3194
|
+
const gridRowIndex = outerWeekData?.gridRowIndex;
|
|
3195
|
+
const weekValues = (0, react.useMemo)(() => weeks.map((weekDays, i) => ({
|
|
3196
|
+
days: weekDays,
|
|
3197
|
+
weekIndex: i,
|
|
3198
|
+
...gridMonth !== void 0 && { gridMonth },
|
|
3199
|
+
...gridRowIndex !== void 0 && { gridRowIndex }
|
|
3200
|
+
})), [
|
|
3201
|
+
weeks,
|
|
3202
|
+
gridMonth,
|
|
3203
|
+
gridRowIndex
|
|
3204
|
+
]);
|
|
3205
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: weekValues.map((value) => {
|
|
3206
|
+
const firstDay = value.days[0];
|
|
2988
3207
|
if (firstDay === void 0) return null;
|
|
2989
3208
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
|
|
2990
|
-
value
|
|
2991
|
-
|
|
2992
|
-
weekIndex: i,
|
|
2993
|
-
...gridMonth !== void 0 && { gridMonth },
|
|
2994
|
-
...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
|
|
2995
|
-
},
|
|
2996
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, { ...props })
|
|
3209
|
+
value,
|
|
3210
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekInstance, { ...props })
|
|
2997
3211
|
}, firstDay.toString());
|
|
2998
3212
|
}) });
|
|
2999
3213
|
}
|
|
3000
|
-
|
|
3001
|
-
//#region src/navigation.tsx
|
|
3214
|
+
// src/navigation.tsx
|
|
3002
3215
|
const dateStringStateAttributesMapping = {
|
|
3003
3216
|
root: () => null,
|
|
3004
3217
|
month: () => null,
|
|
@@ -3020,7 +3233,7 @@ function DateStringFn(props, ref) {
|
|
|
3020
3233
|
const { render, locales, options, ...otherProps } = props;
|
|
3021
3234
|
const { locale, temporal: T, timeZone } = useCalendarStable();
|
|
3022
3235
|
const { selected } = useCalendarState();
|
|
3023
|
-
const { currentDateTime, rootState } =
|
|
3236
|
+
const { currentDateTime, rootState } = useViewState();
|
|
3024
3237
|
const selectedZdt = selectedToZdt(selected, timeZone, T);
|
|
3025
3238
|
const displayDate = selectedZdt ? zdtToNativeDate(selectedZdt) : new Date(currentDateTime.year, currentDateTime.month - 1, 1);
|
|
3026
3239
|
const formatted = displayDate.toLocaleDateString(locales ?? locale, options);
|
|
@@ -3059,7 +3272,7 @@ function TimeStringFn(props, ref) {
|
|
|
3059
3272
|
const { render, locales, options, ...otherProps } = props;
|
|
3060
3273
|
const { locale, temporal: T, timeZone } = useCalendarStable();
|
|
3061
3274
|
const { selected } = useCalendarState();
|
|
3062
|
-
const { rootState } =
|
|
3275
|
+
const { rootState } = useViewState();
|
|
3063
3276
|
const selZdt = selectedToZdt(selected, timeZone, T);
|
|
3064
3277
|
const displayDate = selZdt ? zdtToNativeDate(selZdt) : zdtToNativeDate(T.Now.zonedDateTimeISO(timeZone));
|
|
3065
3278
|
const mergedOptions = {
|
|
@@ -3164,37 +3377,16 @@ function MonthYearStringFn(props, ref) {
|
|
|
3164
3377
|
*/
|
|
3165
3378
|
const MonthYearString = (0, react.forwardRef)(MonthYearStringFn);
|
|
3166
3379
|
function useNavButton(direction) {
|
|
3167
|
-
const { disabled: globalDisabled,
|
|
3168
|
-
const
|
|
3169
|
-
const
|
|
3170
|
-
const
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
|
|
3174
|
-
const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
|
|
3175
|
-
const boundValue = direction === "prev" ? minValue : maxValue;
|
|
3176
|
-
const isDisabled = (0, react.useMemo)(() => {
|
|
3177
|
-
if (globalDisabled) return true;
|
|
3178
|
-
if (outOfRangeBehavior === "unbounded") return false;
|
|
3179
|
-
if (!boundValue) return false;
|
|
3180
|
-
if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
|
|
3181
|
-
return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
|
|
3182
|
-
}, [
|
|
3183
|
-
globalDisabled,
|
|
3184
|
-
outOfRangeBehavior,
|
|
3185
|
-
destYear,
|
|
3186
|
-
destMonth,
|
|
3187
|
-
boundValue,
|
|
3380
|
+
const { disabled: globalDisabled, temporal: T } = useCalendarStable();
|
|
3381
|
+
const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, windowPolicy } = useMonthViewStable();
|
|
3382
|
+
const { currentMonth, rootState } = useMonthViewState();
|
|
3383
|
+
const step = (0, react.useMemo)(() => windowPolicy.step(currentMonth, direction), [
|
|
3384
|
+
windowPolicy,
|
|
3385
|
+
currentMonth,
|
|
3188
3386
|
direction
|
|
3189
3387
|
]);
|
|
3190
|
-
const
|
|
3191
|
-
|
|
3192
|
-
month: destMonth
|
|
3193
|
-
}), [
|
|
3194
|
-
destYear,
|
|
3195
|
-
destMonth,
|
|
3196
|
-
T
|
|
3197
|
-
]);
|
|
3388
|
+
const isDisabled = globalDisabled || step.blocked;
|
|
3389
|
+
const target = (0, react.useMemo)(() => T.PlainYearMonth.from(step.entering), [step.entering, T]);
|
|
3198
3390
|
return {
|
|
3199
3391
|
state: (0, react.useMemo)(() => ({
|
|
3200
3392
|
root: rootState,
|
|
@@ -3255,8 +3447,7 @@ function NextMonthButtonFn(props, ref) {
|
|
|
3255
3447
|
* when the next month falls after `max`. Exposes `data-direction="next"`.
|
|
3256
3448
|
*/
|
|
3257
3449
|
const NextMonthButton = (0, react.forwardRef)(NextMonthButtonFn);
|
|
3258
|
-
|
|
3259
|
-
//#region src/selected-range.tsx
|
|
3450
|
+
// src/selected-range.tsx
|
|
3260
3451
|
const rangeOverlayStateAttributesMapping = {
|
|
3261
3452
|
root: () => null,
|
|
3262
3453
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3325,9 +3516,8 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3325
3516
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3326
3517
|
const { temporal: T } = useCalendarStable();
|
|
3327
3518
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
3328
|
-
const
|
|
3329
|
-
const {
|
|
3330
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
3519
|
+
const { rootState } = useViewState();
|
|
3520
|
+
const { outsideDays } = useViewStable();
|
|
3331
3521
|
const days = weekData?.days ?? [];
|
|
3332
3522
|
const gridMonth = weekData?.gridMonth;
|
|
3333
3523
|
const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gridMonth), [
|
|
@@ -3377,8 +3567,7 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3377
3567
|
});
|
|
3378
3568
|
}
|
|
3379
3569
|
const RangeSelectedInner = (0, react.forwardRef)(RangeSelectedInnerFn);
|
|
3380
|
-
|
|
3381
|
-
//#region src/range-preview.tsx
|
|
3570
|
+
// src/range-preview.tsx
|
|
3382
3571
|
function RangePreviewFn(props, ref) {
|
|
3383
3572
|
const { selectionMode } = useCalendarStable();
|
|
3384
3573
|
if (selectionMode !== "range") return null;
|
|
@@ -3400,9 +3589,8 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3400
3589
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3401
3590
|
const { temporal: T } = useCalendarStable();
|
|
3402
3591
|
const { previewStart, previewEnd } = useCalendarState();
|
|
3403
|
-
const
|
|
3404
|
-
const {
|
|
3405
|
-
const outsideDays = monthStable?.outsideDays ?? "enabled";
|
|
3592
|
+
const { rootState } = useViewState();
|
|
3593
|
+
const { outsideDays } = useViewStable();
|
|
3406
3594
|
const days = weekData?.days ?? [];
|
|
3407
3595
|
const gridMonth = weekData?.gridMonth;
|
|
3408
3596
|
const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, previewStart, previewEnd, T, outsideDays, gridMonth), [
|
|
@@ -3452,8 +3640,7 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3452
3640
|
});
|
|
3453
3641
|
}
|
|
3454
3642
|
const RangePreviewInner = (0, react.forwardRef)(RangePreviewInnerFn);
|
|
3455
|
-
|
|
3456
|
-
//#region src/drag-handle.tsx
|
|
3643
|
+
// src/drag-handle.tsx
|
|
3457
3644
|
const dragHandleStateAttributesMapping = {
|
|
3458
3645
|
root: () => null,
|
|
3459
3646
|
active: (v) => v ? { "data-active": "" } : null,
|
|
@@ -3464,7 +3651,7 @@ const dragHandleStateAttributesMapping = {
|
|
|
3464
3651
|
function useDragHandle(edge, { dragging: draggingProp }) {
|
|
3465
3652
|
const { temporal: T, setHoveredDate, readOnly, disabled } = useCalendarStable();
|
|
3466
3653
|
const { rangeStart, rangeEnd } = useCalendarState();
|
|
3467
|
-
const { rootState } =
|
|
3654
|
+
const { rootState } = useViewState();
|
|
3468
3655
|
const cellData = (0, react.useContext)(DayCellDataContext);
|
|
3469
3656
|
const { orientation } = (0, react.useContext)(GridContext);
|
|
3470
3657
|
const date = cellData?.date;
|
|
@@ -3472,32 +3659,34 @@ function useDragHandle(edge, { dragging: draggingProp }) {
|
|
|
3472
3659
|
const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
|
|
3473
3660
|
const isDragging = !!draggingProp && isActive;
|
|
3474
3661
|
const handleRef = (0, react.useRef)(null);
|
|
3662
|
+
const state = (0, react.useMemo)(() => ({
|
|
3663
|
+
root: rootState,
|
|
3664
|
+
active: isActive,
|
|
3665
|
+
dragging: isDragging,
|
|
3666
|
+
edge,
|
|
3667
|
+
orientation
|
|
3668
|
+
}), [
|
|
3669
|
+
rootState,
|
|
3670
|
+
isActive,
|
|
3671
|
+
isDragging,
|
|
3672
|
+
edge,
|
|
3673
|
+
orientation
|
|
3674
|
+
]);
|
|
3675
|
+
const defaultProps = {
|
|
3676
|
+
role: "slider",
|
|
3677
|
+
"aria-roledescription": "drag handle",
|
|
3678
|
+
"aria-label": edge === "start" ? "Range start date" : "Range end date",
|
|
3679
|
+
"aria-valuetext": date?.toString(),
|
|
3680
|
+
"aria-grabbed": isActive ? isDragging : void 0,
|
|
3681
|
+
"aria-hidden": isActive ? void 0 : true,
|
|
3682
|
+
onPointerEnter: () => {
|
|
3683
|
+
if (date && !outsideDisabled) setHoveredDate(date);
|
|
3684
|
+
}
|
|
3685
|
+
};
|
|
3475
3686
|
return {
|
|
3476
|
-
state
|
|
3477
|
-
root: rootState,
|
|
3478
|
-
active: isActive,
|
|
3479
|
-
dragging: isDragging,
|
|
3480
|
-
edge,
|
|
3481
|
-
orientation
|
|
3482
|
-
}), [
|
|
3483
|
-
rootState,
|
|
3484
|
-
isActive,
|
|
3485
|
-
isDragging,
|
|
3486
|
-
edge,
|
|
3487
|
-
orientation
|
|
3488
|
-
]),
|
|
3687
|
+
state,
|
|
3489
3688
|
stateAttributesMapping: dragHandleStateAttributesMapping,
|
|
3490
|
-
defaultProps
|
|
3491
|
-
role: "slider",
|
|
3492
|
-
"aria-roledescription": "drag handle",
|
|
3493
|
-
"aria-label": edge === "start" ? "Range start date" : "Range end date",
|
|
3494
|
-
"aria-valuetext": date?.toString(),
|
|
3495
|
-
"aria-grabbed": isActive ? isDragging : void 0,
|
|
3496
|
-
"aria-hidden": isActive ? void 0 : true,
|
|
3497
|
-
onPointerEnter: () => {
|
|
3498
|
-
if (date && !outsideDisabled) setHoveredDate(date);
|
|
3499
|
-
}
|
|
3500
|
-
},
|
|
3689
|
+
defaultProps,
|
|
3501
3690
|
handleRef
|
|
3502
3691
|
};
|
|
3503
3692
|
}
|
|
@@ -3538,27 +3727,41 @@ function RangeEndDragHandleFn(props, ref) {
|
|
|
3538
3727
|
}
|
|
3539
3728
|
/** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
|
|
3540
3729
|
const RangeEndDragHandle = (0, react.forwardRef)(RangeEndDragHandleFn);
|
|
3541
|
-
|
|
3542
|
-
//#region src/week-number.tsx
|
|
3730
|
+
// src/week-number.tsx
|
|
3543
3731
|
const weekNumberCellStateAttributesMapping = {
|
|
3544
3732
|
root: () => null,
|
|
3545
3733
|
weekNumber: (v) => ({ "data-week-number": String(v) })
|
|
3546
3734
|
};
|
|
3735
|
+
/**
|
|
3736
|
+
* Default strategy: ISO 8601, generalized to the week's midpoint day.
|
|
3737
|
+
*
|
|
3738
|
+
* A week belongs to the year containing the majority of its days, i.e. the
|
|
3739
|
+
* year containing its midpoint day (day ⌈N/2⌉ of an N-day week — Thursday
|
|
3740
|
+
* for 7-day ISO weeks). The midpoint day of the row is located and its week
|
|
3741
|
+
* number computed via {@link getISOWeekNumber}.
|
|
3742
|
+
*/
|
|
3743
|
+
const defaultWeekNumberStrategy = (weekDays, T) => {
|
|
3744
|
+
let midDay = weekDays[0];
|
|
3745
|
+
if (midDay === void 0) return 0;
|
|
3746
|
+
const midpoint = Math.ceil(midDay.daysInWeek / 2);
|
|
3747
|
+
for (const d of weekDays) if (d.dayOfWeek === midpoint) {
|
|
3748
|
+
midDay = d;
|
|
3749
|
+
break;
|
|
3750
|
+
}
|
|
3751
|
+
return getISOWeekNumber(midDay, T);
|
|
3752
|
+
};
|
|
3547
3753
|
function WeekNumberCellFn(props, ref) {
|
|
3548
|
-
const { render, ...otherProps } = props;
|
|
3754
|
+
const { render, getWeekNumber, ...otherProps } = props;
|
|
3549
3755
|
const weekData = (0, react.useContext)(WeekDataContext);
|
|
3550
|
-
const { rootState } =
|
|
3756
|
+
const { rootState } = useViewState();
|
|
3551
3757
|
const { temporal: T } = useCalendarStable();
|
|
3552
3758
|
const days = weekData?.days ?? [];
|
|
3553
|
-
const
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
}
|
|
3560
|
-
return getISOWeekNumber(thursday, T);
|
|
3561
|
-
}, [days, T]);
|
|
3759
|
+
const strategy = getWeekNumber ?? defaultWeekNumberStrategy;
|
|
3760
|
+
const weekNumber = (0, react.useMemo)(() => strategy(days, T), [
|
|
3761
|
+
strategy,
|
|
3762
|
+
days,
|
|
3763
|
+
T
|
|
3764
|
+
]);
|
|
3562
3765
|
const state = (0, react.useMemo)(() => ({
|
|
3563
3766
|
root: rootState,
|
|
3564
3767
|
weekNumber
|
|
@@ -3578,14 +3781,32 @@ function WeekNumberCellFn(props, ref) {
|
|
|
3578
3781
|
});
|
|
3579
3782
|
}
|
|
3580
3783
|
/**
|
|
3581
|
-
* Renders the
|
|
3582
|
-
*
|
|
3784
|
+
* Renders the week number for a week row. Must be used inside a
|
|
3785
|
+
* {@link WeekTemplate}. Renders a `<td>` with `role="rowheader"`.
|
|
3786
|
+
*
|
|
3787
|
+
* ## Week numbering
|
|
3788
|
+
*
|
|
3789
|
+
* By default, week numbers follow ISO 8601: a week belongs to the year that
|
|
3790
|
+
* contains the majority of its days, which is the year containing the week's
|
|
3791
|
+
* midpoint day (Thursday for a Monday–Sunday 7-day week), and week 1 is the
|
|
3792
|
+
* week containing the year's first midpoint day (equivalently, January 4).
|
|
3793
|
+
* This holds regardless of which day the displayed week row starts on.
|
|
3794
|
+
*
|
|
3795
|
+
* For calendars whose weeks are not 7 days, the default generalizes the same
|
|
3796
|
+
* rule: the midpoint is day ⌈N/2⌉ of an N-day week and the week-1 anchor is
|
|
3797
|
+
* January (N − ⌈N/2⌉ + 1). Note that no standard defines week numbering for
|
|
3798
|
+
* such calendars, so the default is a best-effort extrapolation.
|
|
3799
|
+
*
|
|
3800
|
+
* Pass `getWeekNumber` to override the numbering entirely (e.g. US-style
|
|
3801
|
+
* numbering where week 1 contains January 1, or fiscal-year weeks). It
|
|
3802
|
+
* receives the week row's dates in display order plus the calendar's
|
|
3803
|
+
* Temporal namespace, and must return the number to display.
|
|
3583
3804
|
*/
|
|
3584
3805
|
const WeekNumberCell = (0, react.forwardRef)(WeekNumberCellFn);
|
|
3585
3806
|
const weekNumberHeaderStateAttributesMapping = { root: () => null };
|
|
3586
3807
|
function WeekNumberHeaderFn(props, ref) {
|
|
3587
3808
|
const { render, ...otherProps } = props;
|
|
3588
|
-
const { rootState } =
|
|
3809
|
+
const { rootState } = useViewState();
|
|
3589
3810
|
const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
|
|
3590
3811
|
return (0, _base_ui_react_use_render.useRender)({
|
|
3591
3812
|
defaultTagName: "th",
|
|
@@ -3604,8 +3825,7 @@ function WeekNumberHeaderFn(props, ref) {
|
|
|
3604
3825
|
* Column header for the week number column. Renders a `<th scope="col">`.
|
|
3605
3826
|
*/
|
|
3606
3827
|
const WeekNumberHeader = (0, react.forwardRef)(WeekNumberHeaderFn);
|
|
3607
|
-
|
|
3608
|
-
//#region src/compute-weeks-in-window.ts
|
|
3828
|
+
// src/compute-weeks-in-window.ts
|
|
3609
3829
|
/**
|
|
3610
3830
|
* Computes an array of week descriptors for a continuous window.
|
|
3611
3831
|
* `firstWeek` is snapped back to the nearest `weekStartDay`.
|
|
@@ -3627,115 +3847,7 @@ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
|
|
|
3627
3847
|
}
|
|
3628
3848
|
return weeks;
|
|
3629
3849
|
}
|
|
3630
|
-
|
|
3631
|
-
//#region src/out-of-range.ts
|
|
3632
|
-
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3633
|
-
function weekHasValidDay(weekStart, min, max, T) {
|
|
3634
|
-
const weekEnd = weekStart.add({ days: 6 });
|
|
3635
|
-
return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
|
|
3636
|
-
}
|
|
3637
|
-
/**
|
|
3638
|
-
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
3639
|
-
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
3640
|
-
*/
|
|
3641
|
-
function weekStartContaining(date, weekStartDay, _T) {
|
|
3642
|
-
const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3643
|
-
return date.subtract({ days: daysFromStart });
|
|
3644
|
-
}
|
|
3645
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains min. */
|
|
3646
|
-
function findFirstValidWeekStart(min, weekStartDay, T) {
|
|
3647
|
-
return weekStartContaining(min, weekStartDay, T);
|
|
3648
|
-
}
|
|
3649
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains max. */
|
|
3650
|
-
function findLastValidWeekStart(max, weekStartDay, T) {
|
|
3651
|
-
return weekStartContaining(max, weekStartDay, T);
|
|
3652
|
-
}
|
|
3653
|
-
/**
|
|
3654
|
-
* Trim leading and trailing fully-disabled weeks from a window.
|
|
3655
|
-
* Returns new { firstWeek, weekCount }.
|
|
3656
|
-
*/
|
|
3657
|
-
function shrinkWindow(firstWeek, weekCount, min, max, T) {
|
|
3658
|
-
let start = 0;
|
|
3659
|
-
let end = weekCount - 1;
|
|
3660
|
-
while (start <= end) {
|
|
3661
|
-
if (weekHasValidDay(firstWeek.add({ days: start * 7 }), min, max, T)) break;
|
|
3662
|
-
start++;
|
|
3663
|
-
}
|
|
3664
|
-
while (end >= start) {
|
|
3665
|
-
if (weekHasValidDay(firstWeek.add({ days: end * 7 }), min, max, T)) break;
|
|
3666
|
-
end--;
|
|
3667
|
-
}
|
|
3668
|
-
if (start > end) return {
|
|
3669
|
-
firstWeek,
|
|
3670
|
-
weekCount
|
|
3671
|
-
};
|
|
3672
|
-
return {
|
|
3673
|
-
firstWeek: firstWeek.add({ days: start * 7 }),
|
|
3674
|
-
weekCount: end - start + 1
|
|
3675
|
-
};
|
|
3676
|
-
}
|
|
3677
|
-
/**
|
|
3678
|
-
* Given a target firstWeek and weekCount, apply the out-of-range behavior and return
|
|
3679
|
-
* the adjusted { firstWeek, weekCount }.
|
|
3680
|
-
*/
|
|
3681
|
-
function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3682
|
-
if (!min || !max || behavior === "unbounded") return {
|
|
3683
|
-
firstWeek: targetFirstWeek,
|
|
3684
|
-
weekCount
|
|
3685
|
-
};
|
|
3686
|
-
if (behavior === "stop") return {
|
|
3687
|
-
firstWeek: targetFirstWeek,
|
|
3688
|
-
weekCount
|
|
3689
|
-
};
|
|
3690
|
-
if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
3691
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
3692
|
-
const lastValid = findLastValidWeekStart(max, weekStartDay, T);
|
|
3693
|
-
const snappedFirst = lastValid.subtract({ days: (weekCount - 1) * 7 });
|
|
3694
|
-
const targetLastWeek = targetFirstWeek.add({ days: (weekCount - 1) * 7 });
|
|
3695
|
-
let resolvedFirst;
|
|
3696
|
-
if (T.PlainDate.compare(targetLastWeek, lastValid) <= 0) {
|
|
3697
|
-
const firstValid = findFirstValidWeekStart(min, weekStartDay, T);
|
|
3698
|
-
if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
|
|
3699
|
-
else resolvedFirst = firstValid;
|
|
3700
|
-
} else resolvedFirst = snappedFirst;
|
|
3701
|
-
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3702
|
-
return {
|
|
3703
|
-
firstWeek: resolvedFirst,
|
|
3704
|
-
weekCount
|
|
3705
|
-
};
|
|
3706
|
-
}
|
|
3707
|
-
return {
|
|
3708
|
-
firstWeek: targetFirstWeek,
|
|
3709
|
-
weekCount
|
|
3710
|
-
};
|
|
3711
|
-
}
|
|
3712
|
-
/**
|
|
3713
|
-
* Returns whether the navigation button for the given direction should be enabled.
|
|
3714
|
-
*/
|
|
3715
|
-
function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
|
|
3716
|
-
if (behavior === "unbounded" || !min || !max) return true;
|
|
3717
|
-
const shift = shiftBy ?? weekCount;
|
|
3718
|
-
const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
|
|
3719
|
-
if (behavior === "stop" || behavior === "stop-shrink") {
|
|
3720
|
-
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
|
|
3721
|
-
return false;
|
|
3722
|
-
}
|
|
3723
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
3724
|
-
const applied = applyOutOfRange({
|
|
3725
|
-
targetFirstWeek,
|
|
3726
|
-
weekCount,
|
|
3727
|
-
behavior,
|
|
3728
|
-
min,
|
|
3729
|
-
max,
|
|
3730
|
-
weekStartDay,
|
|
3731
|
-
T
|
|
3732
|
-
});
|
|
3733
|
-
return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
|
|
3734
|
-
}
|
|
3735
|
-
return true;
|
|
3736
|
-
}
|
|
3737
|
-
//#endregion
|
|
3738
|
-
//#region src/resolve-first-week.ts
|
|
3850
|
+
// src/resolve-first-week.ts
|
|
3739
3851
|
/** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
|
|
3740
3852
|
function snapToWeekStart(date, weekStartDay) {
|
|
3741
3853
|
const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
@@ -3826,8 +3938,109 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
|
3826
3938
|
}
|
|
3827
3939
|
}
|
|
3828
3940
|
}
|
|
3829
|
-
|
|
3830
|
-
|
|
3941
|
+
// src/out-of-range.ts
|
|
3942
|
+
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3943
|
+
function weekHasValidDay(weekStart, min, max, T) {
|
|
3944
|
+
const weekEnd = weekStart.add({ days: 6 });
|
|
3945
|
+
return (!max || T.PlainDate.compare(weekStart, max) <= 0) && (!min || T.PlainDate.compare(weekEnd, min) >= 0);
|
|
3946
|
+
}
|
|
3947
|
+
/** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
|
|
3948
|
+
function windowHasValidWeek(firstWeek, weekCount, min, max, T) {
|
|
3949
|
+
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
|
|
3950
|
+
return false;
|
|
3951
|
+
}
|
|
3952
|
+
/**
|
|
3953
|
+
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
3954
|
+
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
3955
|
+
*/
|
|
3956
|
+
function weekStartContaining(date, weekStartDay) {
|
|
3957
|
+
const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3958
|
+
return date.subtract({ days: daysFromStart });
|
|
3959
|
+
}
|
|
3960
|
+
/**
|
|
3961
|
+
* Trim leading and trailing fully-disabled weeks from a window.
|
|
3962
|
+
* Returns new { firstWeek, weekCount }.
|
|
3963
|
+
*/
|
|
3964
|
+
function shrinkWindow(firstWeek, weekCount, min, max, T) {
|
|
3965
|
+
let start = 0;
|
|
3966
|
+
let end = weekCount - 1;
|
|
3967
|
+
while (start <= end) {
|
|
3968
|
+
if (weekHasValidDay(firstWeek.add({ days: start * 7 }), min, max, T)) break;
|
|
3969
|
+
start++;
|
|
3970
|
+
}
|
|
3971
|
+
while (end >= start) {
|
|
3972
|
+
if (weekHasValidDay(firstWeek.add({ days: end * 7 }), min, max, T)) break;
|
|
3973
|
+
end--;
|
|
3974
|
+
}
|
|
3975
|
+
if (start > end) return {
|
|
3976
|
+
firstWeek,
|
|
3977
|
+
weekCount
|
|
3978
|
+
};
|
|
3979
|
+
return {
|
|
3980
|
+
firstWeek: firstWeek.add({ days: start * 7 }),
|
|
3981
|
+
weekCount: end - start + 1
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
/**
|
|
3985
|
+
* Given a target firstWeek and weekCount, apply the out-of-range behavior and return
|
|
3986
|
+
* the adjusted { firstWeek, weekCount }.
|
|
3987
|
+
*/
|
|
3988
|
+
function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3989
|
+
if (!min && !max || behavior === "unbounded") return {
|
|
3990
|
+
firstWeek: targetFirstWeek,
|
|
3991
|
+
weekCount
|
|
3992
|
+
};
|
|
3993
|
+
if (behavior === "stop") return {
|
|
3994
|
+
firstWeek: targetFirstWeek,
|
|
3995
|
+
weekCount
|
|
3996
|
+
};
|
|
3997
|
+
if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
3998
|
+
const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
|
|
3999
|
+
const lastValid = max && weekStartContaining(max, weekStartDay);
|
|
4000
|
+
const firstValid = min && weekStartContaining(min, weekStartDay);
|
|
4001
|
+
let resolvedFirst = targetFirstWeek;
|
|
4002
|
+
if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
|
|
4003
|
+
else if (firstValid && T.PlainDate.compare(targetFirstWeek, firstValid) < 0) resolvedFirst = firstValid;
|
|
4004
|
+
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
4005
|
+
return {
|
|
4006
|
+
firstWeek: resolvedFirst,
|
|
4007
|
+
weekCount
|
|
4008
|
+
};
|
|
4009
|
+
}
|
|
4010
|
+
// src/weeks-window.ts
|
|
4011
|
+
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
4012
|
+
const bounds = {
|
|
4013
|
+
weekCount,
|
|
4014
|
+
behavior,
|
|
4015
|
+
...min !== void 0 && { min },
|
|
4016
|
+
...max !== void 0 && { max },
|
|
4017
|
+
weekStartDay,
|
|
4018
|
+
T
|
|
4019
|
+
};
|
|
4020
|
+
const isStop = behavior === "stop" || behavior === "stop-shrink";
|
|
4021
|
+
const isBounded = min !== void 0 || max !== void 0;
|
|
4022
|
+
const resolve = (requestedFirstWeek) => applyOutOfRange({
|
|
4023
|
+
...bounds,
|
|
4024
|
+
targetFirstWeek: requestedFirstWeek
|
|
4025
|
+
});
|
|
4026
|
+
const moveTo = (requestedFirstWeek) => {
|
|
4027
|
+
if (isStop && isBounded && !windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)) return null;
|
|
4028
|
+
return resolve(requestedFirstWeek);
|
|
4029
|
+
};
|
|
4030
|
+
return {
|
|
4031
|
+
resolve,
|
|
4032
|
+
moveTo,
|
|
4033
|
+
shift: (current, direction, shiftBy) => {
|
|
4034
|
+
const by = shiftBy ?? current.weekCount;
|
|
4035
|
+
const target = current.firstWeek.add({ weeks: direction * by });
|
|
4036
|
+
const next = moveTo(target);
|
|
4037
|
+
if (next === null) return null;
|
|
4038
|
+
if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
|
|
4039
|
+
return next;
|
|
4040
|
+
}
|
|
4041
|
+
};
|
|
4042
|
+
}
|
|
4043
|
+
// src/weeks-view-state.ts
|
|
3831
4044
|
/**
|
|
3832
4045
|
* Core state management hook for WeeksView.Root.
|
|
3833
4046
|
* Reads calendar-level context and manages weeks-specific state.
|
|
@@ -3839,14 +4052,13 @@ function useWeeksViewRootState(props) {
|
|
|
3839
4052
|
const calStable = useCalendarStable();
|
|
3840
4053
|
const calState = useCalendarState();
|
|
3841
4054
|
const T = calStable.temporal;
|
|
3842
|
-
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } = calStable;
|
|
4055
|
+
const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone, today } = calStable;
|
|
3843
4056
|
const isControlled = firstWeekProp !== void 0;
|
|
3844
4057
|
const resolveSpec = (0, react.useCallback)((spec) => resolveFirstWeekSpec(spec, weekStartDay, T), [weekStartDay, T]);
|
|
3845
4058
|
const [internalFirstWeek, setInternalFirstWeek] = (0, react.useState)(() => {
|
|
3846
4059
|
if (firstWeekProp !== void 0) return resolveSpec(firstWeekProp);
|
|
3847
4060
|
if (defaultFirstWeekProp !== void 0) return resolveSpec(defaultFirstWeekProp);
|
|
3848
|
-
|
|
3849
|
-
return resolveSpec(T.Now.plainDateISO());
|
|
4061
|
+
return resolveSpec(resolveInitialAnchor(calState.selected, today, timeZone, T));
|
|
3850
4062
|
});
|
|
3851
4063
|
const resolvedFirstWeek = isControlled ? resolveSpec(firstWeekProp) : internalFirstWeek;
|
|
3852
4064
|
const rawWeeks = (0, react.useMemo)(() => computeWeeksInWindow(resolvedFirstWeek, weekCount, weekStartDay, T), [
|
|
@@ -3855,16 +4067,14 @@ function useWeeksViewRootState(props) {
|
|
|
3855
4067
|
weekStartDay,
|
|
3856
4068
|
T
|
|
3857
4069
|
]);
|
|
3858
|
-
const
|
|
3859
|
-
targetFirstWeek: resolvedFirstWeek,
|
|
4070
|
+
const windowPolicy = (0, react.useMemo)(() => createWeekWindowPolicy({
|
|
3860
4071
|
weekCount,
|
|
3861
4072
|
behavior: outOfRangeBehavior,
|
|
3862
|
-
|
|
3863
|
-
|
|
4073
|
+
min: minValue,
|
|
4074
|
+
max: maxValue,
|
|
3864
4075
|
weekStartDay,
|
|
3865
4076
|
T
|
|
3866
4077
|
}), [
|
|
3867
|
-
resolvedFirstWeek,
|
|
3868
4078
|
weekCount,
|
|
3869
4079
|
outOfRangeBehavior,
|
|
3870
4080
|
minValue,
|
|
@@ -3872,6 +4082,7 @@ function useWeeksViewRootState(props) {
|
|
|
3872
4082
|
weekStartDay,
|
|
3873
4083
|
T
|
|
3874
4084
|
]);
|
|
4085
|
+
const outOfRangeResult = (0, react.useMemo)(() => windowPolicy.resolve(resolvedFirstWeek), [windowPolicy, resolvedFirstWeek]);
|
|
3875
4086
|
const adjustedWeeks = (0, react.useMemo)(() => {
|
|
3876
4087
|
const sameFirst = T.PlainDate.compare(outOfRangeResult.firstWeek, resolvedFirstWeek) === 0;
|
|
3877
4088
|
const sameCount = outOfRangeResult.weekCount === weekCount;
|
|
@@ -3901,10 +4112,10 @@ function useWeeksViewRootState(props) {
|
|
|
3901
4112
|
const firstWeek = weeks[0];
|
|
3902
4113
|
const lastWeek = weeks[weeks.length - 1];
|
|
3903
4114
|
if (firstWeek === void 0 || lastWeek === void 0) {
|
|
3904
|
-
const
|
|
4115
|
+
const now = today();
|
|
3905
4116
|
return {
|
|
3906
|
-
windowStart:
|
|
3907
|
-
windowEnd:
|
|
4117
|
+
windowStart: now,
|
|
4118
|
+
windowEnd: now,
|
|
3908
4119
|
weekCount: 0,
|
|
3909
4120
|
dayCount: 0,
|
|
3910
4121
|
enabledWeekCount: 0,
|
|
@@ -4049,67 +4260,35 @@ function useWeeksViewRootState(props) {
|
|
|
4049
4260
|
if (!isControlled) setInternalFirstWeek(newFirstWeek);
|
|
4050
4261
|
onFirstWeekChange?.(newFirstWeek);
|
|
4051
4262
|
}, [isControlled, onFirstWeekChange]);
|
|
4263
|
+
const shownWindow = (0, react.useMemo)(() => ({
|
|
4264
|
+
firstWeek: windowInfo.windowStart,
|
|
4265
|
+
weekCount: windowInfo.weekCount
|
|
4266
|
+
}), [windowInfo.windowStart, windowInfo.weekCount]);
|
|
4052
4267
|
const goNext = (0, react.useCallback)((shiftBy) => {
|
|
4053
|
-
const
|
|
4054
|
-
updateFirstWeek(
|
|
4055
|
-
targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
|
|
4056
|
-
weekCount,
|
|
4057
|
-
behavior: outOfRangeBehavior,
|
|
4058
|
-
...minValue !== void 0 && { min: minValue },
|
|
4059
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4060
|
-
weekStartDay,
|
|
4061
|
-
T
|
|
4062
|
-
}).firstWeek);
|
|
4268
|
+
const next = windowPolicy.shift(shownWindow, 1, shiftBy);
|
|
4269
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4063
4270
|
}, [
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
outOfRangeBehavior,
|
|
4067
|
-
minValue,
|
|
4068
|
-
maxValue,
|
|
4069
|
-
weekStartDay,
|
|
4070
|
-
T,
|
|
4271
|
+
shownWindow,
|
|
4272
|
+
windowPolicy,
|
|
4071
4273
|
updateFirstWeek
|
|
4072
4274
|
]);
|
|
4073
4275
|
const goPrev = (0, react.useCallback)((shiftBy) => {
|
|
4074
|
-
const
|
|
4075
|
-
updateFirstWeek(
|
|
4076
|
-
targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
|
|
4077
|
-
weekCount,
|
|
4078
|
-
behavior: outOfRangeBehavior,
|
|
4079
|
-
...minValue !== void 0 && { min: minValue },
|
|
4080
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4081
|
-
weekStartDay,
|
|
4082
|
-
T
|
|
4083
|
-
}).firstWeek);
|
|
4276
|
+
const next = windowPolicy.shift(shownWindow, -1, shiftBy);
|
|
4277
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4084
4278
|
}, [
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
outOfRangeBehavior,
|
|
4088
|
-
minValue,
|
|
4089
|
-
maxValue,
|
|
4090
|
-
weekStartDay,
|
|
4091
|
-
T,
|
|
4279
|
+
shownWindow,
|
|
4280
|
+
windowPolicy,
|
|
4092
4281
|
updateFirstWeek
|
|
4093
4282
|
]);
|
|
4094
4283
|
const scrollToWeek = (0, react.useCallback)((target, options) => {
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
behavior: outOfRangeBehavior,
|
|
4099
|
-
...minValue !== void 0 && { min: minValue },
|
|
4100
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4101
|
-
weekStartDay,
|
|
4102
|
-
T
|
|
4103
|
-
}).firstWeek);
|
|
4284
|
+
const requested = resolveFirstWeek(shownWindow.firstWeek, weekCount, resolveSpec(target), options);
|
|
4285
|
+
const next = windowPolicy.moveTo(requested);
|
|
4286
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4104
4287
|
}, [
|
|
4105
|
-
|
|
4288
|
+
shownWindow,
|
|
4106
4289
|
weekCount,
|
|
4107
4290
|
resolveSpec,
|
|
4108
|
-
|
|
4109
|
-
minValue,
|
|
4110
|
-
maxValue,
|
|
4111
|
-
weekStartDay,
|
|
4112
|
-
T,
|
|
4291
|
+
windowPolicy,
|
|
4113
4292
|
updateFirstWeek
|
|
4114
4293
|
]);
|
|
4115
4294
|
const onWindowChangeRef = (0, react.useRef)(onWindowChange);
|
|
@@ -4126,6 +4305,7 @@ function useWeeksViewRootState(props) {
|
|
|
4126
4305
|
weekCount,
|
|
4127
4306
|
scrollBy,
|
|
4128
4307
|
outOfRangeBehavior,
|
|
4308
|
+
windowPolicy,
|
|
4129
4309
|
goNext,
|
|
4130
4310
|
goPrev,
|
|
4131
4311
|
scrollToWeek,
|
|
@@ -4135,6 +4315,7 @@ function useWeeksViewRootState(props) {
|
|
|
4135
4315
|
weekCount,
|
|
4136
4316
|
scrollBy,
|
|
4137
4317
|
outOfRangeBehavior,
|
|
4318
|
+
windowPolicy,
|
|
4138
4319
|
goNext,
|
|
4139
4320
|
goPrev,
|
|
4140
4321
|
scrollToWeek,
|
|
@@ -4182,52 +4363,34 @@ function useWeeksViewRootState(props) {
|
|
|
4182
4363
|
tabTargetDate,
|
|
4183
4364
|
gridHasFocus
|
|
4184
4365
|
]),
|
|
4366
|
+
viewStableCtx: (0, react.useMemo)(() => ({
|
|
4367
|
+
gridFocusedRef,
|
|
4368
|
+
outsideDays: "enabled",
|
|
4369
|
+
setFocusedDate
|
|
4370
|
+
}), []),
|
|
4371
|
+
viewStateCtx: (0, react.useMemo)(() => ({
|
|
4372
|
+
currentDateTime,
|
|
4373
|
+
rootState
|
|
4374
|
+
}), [currentDateTime, rootState]),
|
|
4185
4375
|
scrollToWeek
|
|
4186
4376
|
};
|
|
4187
4377
|
}
|
|
4188
|
-
|
|
4189
|
-
//#region src/weeks-view.tsx
|
|
4378
|
+
// src/weeks-view.tsx
|
|
4190
4379
|
function WeeksViewRootFn(props, ref) {
|
|
4191
4380
|
const { children } = props;
|
|
4192
|
-
const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
4381
|
+
const { stableCtx, stateCtx, viewCtx, viewStableCtx, viewStateCtx, scrollToWeek } = useWeeksViewRootState(props);
|
|
4193
4382
|
(0, react.useImperativeHandle)(ref, () => ({ scrollToWeek }), [scrollToWeek]);
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
setGridLabelId: () => {},
|
|
4203
|
-
gridFocusedRef
|
|
4204
|
-
}), []);
|
|
4205
|
-
const monthViewStateShim = (0, react.useMemo)(() => ({
|
|
4206
|
-
currentMonth: {
|
|
4207
|
-
year: stateCtx.currentDateTime.year,
|
|
4208
|
-
month: stateCtx.currentDateTime.month
|
|
4209
|
-
},
|
|
4210
|
-
weeks: [],
|
|
4211
|
-
allMonths: [],
|
|
4212
|
-
currentDateTime: stateCtx.currentDateTime,
|
|
4213
|
-
gridLabelIds: stateCtx.gridLabelIds,
|
|
4214
|
-
rootState: stateCtx.rootState
|
|
4215
|
-
}), [
|
|
4216
|
-
stateCtx.currentDateTime,
|
|
4217
|
-
stateCtx.gridLabelIds,
|
|
4218
|
-
stateCtx.rootState
|
|
4219
|
-
]);
|
|
4220
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
|
|
4221
|
-
value: monthViewStableShim,
|
|
4222
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
|
|
4223
|
-
value: monthViewStateShim,
|
|
4224
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
|
|
4225
|
-
value: stableCtx,
|
|
4226
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
|
|
4227
|
-
value: stateCtx,
|
|
4383
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
|
|
4384
|
+
value: stableCtx,
|
|
4385
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
|
|
4386
|
+
value: stateCtx,
|
|
4387
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStableContext.Provider, {
|
|
4388
|
+
value: viewStableCtx,
|
|
4389
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewStateContext.Provider, {
|
|
4390
|
+
value: viewStateCtx,
|
|
4228
4391
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
|
|
4229
4392
|
value: viewCtx,
|
|
4230
|
-
children
|
|
4393
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellStoreProvider, { children })
|
|
4231
4394
|
})
|
|
4232
4395
|
})
|
|
4233
4396
|
})
|
|
@@ -4254,8 +4417,7 @@ function WeeksViewFn(props, ref) {
|
|
|
4254
4417
|
}
|
|
4255
4418
|
const WeeksView = (0, react.forwardRef)(WeeksViewFn);
|
|
4256
4419
|
WeeksView.Root = WeeksViewRoot;
|
|
4257
|
-
|
|
4258
|
-
//#region src/weeks-navigation.tsx
|
|
4420
|
+
// src/weeks-navigation.tsx
|
|
4259
4421
|
const weeksNavButtonStateAttributesMapping = {
|
|
4260
4422
|
root: () => null,
|
|
4261
4423
|
direction: (v) => ({ "data-direction": v }),
|
|
@@ -4266,35 +4428,24 @@ const weekCountStateAttributesMapping = {
|
|
|
4266
4428
|
weekCount: () => null
|
|
4267
4429
|
};
|
|
4268
4430
|
function useWeeksNavButton(direction, shiftByProp) {
|
|
4269
|
-
const { disabled: globalDisabled
|
|
4270
|
-
const {
|
|
4431
|
+
const { disabled: globalDisabled } = useCalendarStable();
|
|
4432
|
+
const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
|
|
4271
4433
|
const { windowInfo } = useWeeksViewState();
|
|
4272
|
-
const { rootState } =
|
|
4273
|
-
const
|
|
4434
|
+
const { rootState } = useViewState();
|
|
4435
|
+
const { windowStart, weekCount } = windowInfo;
|
|
4274
4436
|
const isDisabled = (0, react.useMemo)(() => {
|
|
4275
4437
|
if (globalDisabled) return true;
|
|
4276
|
-
return
|
|
4277
|
-
|
|
4278
|
-
weekCount
|
|
4279
|
-
|
|
4280
|
-
...shiftByProp !== void 0 && { shiftBy: shiftByProp },
|
|
4281
|
-
behavior: outOfRangeBehavior,
|
|
4282
|
-
...minValue !== void 0 && { min: minValue },
|
|
4283
|
-
...maxValue !== void 0 && { max: maxValue },
|
|
4284
|
-
weekStartDay,
|
|
4285
|
-
T
|
|
4286
|
-
});
|
|
4438
|
+
return windowPolicy.shift({
|
|
4439
|
+
firstWeek: windowStart,
|
|
4440
|
+
weekCount
|
|
4441
|
+
}, direction === "next" ? 1 : -1, shiftByProp) === null;
|
|
4287
4442
|
}, [
|
|
4288
4443
|
globalDisabled,
|
|
4289
|
-
|
|
4444
|
+
windowPolicy,
|
|
4445
|
+
windowStart,
|
|
4290
4446
|
weekCount,
|
|
4291
4447
|
direction,
|
|
4292
|
-
shiftByProp
|
|
4293
|
-
outOfRangeBehavior,
|
|
4294
|
-
minValue,
|
|
4295
|
-
maxValue,
|
|
4296
|
-
weekStartDay,
|
|
4297
|
-
T
|
|
4448
|
+
shiftByProp
|
|
4298
4449
|
]);
|
|
4299
4450
|
const state = (0, react.useMemo)(() => ({
|
|
4300
4451
|
root: rootState,
|
|
@@ -4355,7 +4506,7 @@ const NextWeeksButton = (0, react.forwardRef)(NextWeeksButtonFn);
|
|
|
4355
4506
|
function WeekCountFn(props, ref) {
|
|
4356
4507
|
const { render, ...otherProps } = props;
|
|
4357
4508
|
const { windowInfo } = useWeeksViewState();
|
|
4358
|
-
const { rootState } =
|
|
4509
|
+
const { rootState } = useViewState();
|
|
4359
4510
|
const count = windowInfo.weekCount;
|
|
4360
4511
|
const state = (0, react.useMemo)(() => ({
|
|
4361
4512
|
root: rootState,
|
|
@@ -4375,7 +4526,6 @@ function WeekCountFn(props, ref) {
|
|
|
4375
4526
|
* out-of-range modes where the actual count may be less than the `weekCount` prop.
|
|
4376
4527
|
*/
|
|
4377
4528
|
const WeekCount = (0, react.forwardRef)(WeekCountFn);
|
|
4378
|
-
//#endregion
|
|
4379
4529
|
Object.defineProperty(exports, "CalendarProvider", {
|
|
4380
4530
|
enumerable: true,
|
|
4381
4531
|
get: function() {
|