@klinking/colander 3.1.0-alpha.6 → 3.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +1 -1
- package/dist/formats/date.d.cts +1 -1
- package/dist/formats/date.d.mts +1 -1
- package/dist/formats/date.mjs +1 -1
- package/dist/formats/object.cjs +1 -1
- package/dist/formats/object.d.cts +1 -1
- package/dist/formats/object.d.mts +1 -1
- package/dist/formats/object.mjs +1 -1
- package/dist/formats/plain-date-time.cjs +1 -1
- package/dist/formats/plain-date-time.d.cts +1 -1
- package/dist/formats/plain-date-time.d.mts +1 -1
- package/dist/formats/plain-date-time.mjs +1 -1
- package/dist/formats/plain-date.cjs +1 -1
- package/dist/formats/plain-date.d.cts +1 -1
- package/dist/formats/plain-date.d.mts +1 -1
- package/dist/formats/plain-date.mjs +1 -1
- package/dist/formats/plain-month-day.cjs +1 -1
- package/dist/formats/plain-month-day.d.cts +1 -1
- package/dist/formats/plain-month-day.d.mts +1 -1
- package/dist/formats/plain-month-day.mjs +1 -1
- package/dist/formats/plain-year-month.cjs +1 -1
- package/dist/formats/plain-year-month.d.cts +1 -1
- package/dist/formats/plain-year-month.d.mts +1 -1
- package/dist/formats/plain-year-month.mjs +1 -1
- package/dist/formats/zoned-date-time.cjs +1 -1
- package/dist/formats/zoned-date-time.d.cts +1 -1
- package/dist/formats/zoned-date-time.d.mts +1 -1
- package/dist/formats/zoned-date-time.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +1 -1
- package/dist/{weeks-navigation-Dn3UtG76.mjs → weeks-navigation-BSKwFvdP.mjs} +57 -78
- package/dist/{weeks-navigation-SuKJZJCM.cjs → weeks-navigation-CPevz3Xg.cjs} +57 -78
- package/dist/{index-DnFCKyyw.d.cts → weeks-view-context-BTojXkys.d.cts} +23 -16
- package/dist/{index-q3cQKJdA.d.mts → weeks-view-context-CFXV8orh.d.mts} +23 -16
- package/package.json +1 -1
- package/src/grid.tsx +1 -1
- package/src/out-of-range.test.ts +33 -53
- package/src/out-of-range.ts +47 -123
- package/src/weeks-navigation.tsx +15 -6
- package/src/weeks-view-state.ts +21 -12
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-window.test.ts +109 -21
- package/src/weeks-window.ts +57 -19
|
@@ -2708,7 +2708,7 @@ function useWeeksGridKeyboard() {
|
|
|
2708
2708
|
shiftKey: e.shiftKey,
|
|
2709
2709
|
focusedDate,
|
|
2710
2710
|
windowStart: weeksState.windowInfo.windowStart,
|
|
2711
|
-
weekCount:
|
|
2711
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
2712
2712
|
minValue,
|
|
2713
2713
|
maxValue,
|
|
2714
2714
|
disabled,
|
|
@@ -3743,24 +3743,21 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
|
3743
3743
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3744
3744
|
function weekHasValidDay(weekStart, min, max, T) {
|
|
3745
3745
|
const weekEnd = weekStart.add({ days: 6 });
|
|
3746
|
-
return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
|
|
3746
|
+
return (!max || T.PlainDate.compare(weekStart, max) <= 0) && (!min || T.PlainDate.compare(weekEnd, min) >= 0);
|
|
3747
|
+
}
|
|
3748
|
+
/** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
|
|
3749
|
+
function windowHasValidWeek(firstWeek, weekCount, min, max, T) {
|
|
3750
|
+
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
|
|
3751
|
+
return false;
|
|
3747
3752
|
}
|
|
3748
3753
|
/**
|
|
3749
3754
|
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
3750
3755
|
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
3751
3756
|
*/
|
|
3752
|
-
function weekStartContaining(date, weekStartDay
|
|
3757
|
+
function weekStartContaining(date, weekStartDay) {
|
|
3753
3758
|
const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3754
3759
|
return date.subtract({ days: daysFromStart });
|
|
3755
3760
|
}
|
|
3756
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains min. */
|
|
3757
|
-
function findFirstValidWeekStart(min, weekStartDay, T) {
|
|
3758
|
-
return weekStartContaining(min, weekStartDay, T);
|
|
3759
|
-
}
|
|
3760
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains max. */
|
|
3761
|
-
function findLastValidWeekStart(max, weekStartDay, T) {
|
|
3762
|
-
return weekStartContaining(max, weekStartDay, T);
|
|
3763
|
-
}
|
|
3764
3761
|
/**
|
|
3765
3762
|
* Trim leading and trailing fully-disabled weeks from a window.
|
|
3766
3763
|
* Returns new { firstWeek, weekCount }.
|
|
@@ -3790,7 +3787,7 @@ function shrinkWindow(firstWeek, weekCount, min, max, T) {
|
|
|
3790
3787
|
* the adjusted { firstWeek, weekCount }.
|
|
3791
3788
|
*/
|
|
3792
3789
|
function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3793
|
-
if (!min
|
|
3790
|
+
if (!min && !max || behavior === "unbounded") return {
|
|
3794
3791
|
firstWeek: targetFirstWeek,
|
|
3795
3792
|
weekCount
|
|
3796
3793
|
};
|
|
@@ -3799,52 +3796,18 @@ function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekS
|
|
|
3799
3796
|
weekCount
|
|
3800
3797
|
};
|
|
3801
3798
|
if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
|
|
3810
|
-
else resolvedFirst = firstValid;
|
|
3811
|
-
} else resolvedFirst = snappedFirst;
|
|
3812
|
-
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3813
|
-
return {
|
|
3814
|
-
firstWeek: resolvedFirst,
|
|
3815
|
-
weekCount
|
|
3816
|
-
};
|
|
3817
|
-
}
|
|
3799
|
+
const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
|
|
3800
|
+
const lastValid = max && weekStartContaining(max, weekStartDay);
|
|
3801
|
+
const firstValid = min && weekStartContaining(min, weekStartDay);
|
|
3802
|
+
let resolvedFirst = targetFirstWeek;
|
|
3803
|
+
if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
|
|
3804
|
+
else if (firstValid && T.PlainDate.compare(targetFirstWeek, firstValid) < 0) resolvedFirst = firstValid;
|
|
3805
|
+
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3818
3806
|
return {
|
|
3819
|
-
firstWeek:
|
|
3807
|
+
firstWeek: resolvedFirst,
|
|
3820
3808
|
weekCount
|
|
3821
3809
|
};
|
|
3822
3810
|
}
|
|
3823
|
-
/**
|
|
3824
|
-
* Returns whether the navigation button for the given direction should be enabled.
|
|
3825
|
-
*/
|
|
3826
|
-
function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
|
|
3827
|
-
if (behavior === "unbounded" || !min || !max) return true;
|
|
3828
|
-
const shift = shiftBy ?? weekCount;
|
|
3829
|
-
const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
|
|
3830
|
-
if (behavior === "stop" || behavior === "stop-shrink") {
|
|
3831
|
-
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
|
|
3832
|
-
return false;
|
|
3833
|
-
}
|
|
3834
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
3835
|
-
const applied = applyOutOfRange({
|
|
3836
|
-
targetFirstWeek,
|
|
3837
|
-
weekCount,
|
|
3838
|
-
behavior,
|
|
3839
|
-
min,
|
|
3840
|
-
max,
|
|
3841
|
-
weekStartDay,
|
|
3842
|
-
T
|
|
3843
|
-
});
|
|
3844
|
-
return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
|
|
3845
|
-
}
|
|
3846
|
-
return true;
|
|
3847
|
-
}
|
|
3848
3811
|
//#endregion
|
|
3849
3812
|
//#region src/weeks-window.ts
|
|
3850
3813
|
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
@@ -3856,17 +3819,26 @@ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T
|
|
|
3856
3819
|
weekStartDay,
|
|
3857
3820
|
T
|
|
3858
3821
|
};
|
|
3822
|
+
const isStop = behavior === "stop" || behavior === "stop-shrink";
|
|
3823
|
+
const isBounded = min !== void 0 || max !== void 0;
|
|
3824
|
+
const resolve = (requestedFirstWeek) => applyOutOfRange({
|
|
3825
|
+
...bounds,
|
|
3826
|
+
targetFirstWeek: requestedFirstWeek
|
|
3827
|
+
});
|
|
3828
|
+
const moveTo = (requestedFirstWeek) => {
|
|
3829
|
+
if (isStop && isBounded && !windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)) return null;
|
|
3830
|
+
return resolve(requestedFirstWeek);
|
|
3831
|
+
};
|
|
3859
3832
|
return {
|
|
3860
|
-
resolve
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
})
|
|
3833
|
+
resolve,
|
|
3834
|
+
moveTo,
|
|
3835
|
+
shift: (current, direction, shiftBy) => {
|
|
3836
|
+
const by = shiftBy ?? current.weekCount;
|
|
3837
|
+
const next = moveTo(current.firstWeek.add({ weeks: direction * by }));
|
|
3838
|
+
if (next === null) return null;
|
|
3839
|
+
if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
|
|
3840
|
+
return next;
|
|
3841
|
+
}
|
|
3870
3842
|
};
|
|
3871
3843
|
}
|
|
3872
3844
|
//#endregion
|
|
@@ -4090,29 +4062,32 @@ function useWeeksViewRootState(props) {
|
|
|
4090
4062
|
if (!isControlled) setInternalFirstWeek(newFirstWeek);
|
|
4091
4063
|
onFirstWeekChange?.(newFirstWeek);
|
|
4092
4064
|
}, [isControlled, onFirstWeekChange]);
|
|
4065
|
+
const shownWindow = useMemo(() => ({
|
|
4066
|
+
firstWeek: windowInfo.windowStart,
|
|
4067
|
+
weekCount: windowInfo.weekCount
|
|
4068
|
+
}), [windowInfo.windowStart, windowInfo.weekCount]);
|
|
4093
4069
|
const goNext = useCallback((shiftBy) => {
|
|
4094
|
-
const
|
|
4095
|
-
updateFirstWeek(
|
|
4070
|
+
const next = windowPolicy.shift(shownWindow, 1, shiftBy);
|
|
4071
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4096
4072
|
}, [
|
|
4097
|
-
|
|
4098
|
-
weekCount,
|
|
4073
|
+
shownWindow,
|
|
4099
4074
|
windowPolicy,
|
|
4100
4075
|
updateFirstWeek
|
|
4101
4076
|
]);
|
|
4102
4077
|
const goPrev = useCallback((shiftBy) => {
|
|
4103
|
-
const
|
|
4104
|
-
updateFirstWeek(
|
|
4078
|
+
const next = windowPolicy.shift(shownWindow, -1, shiftBy);
|
|
4079
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4105
4080
|
}, [
|
|
4106
|
-
|
|
4107
|
-
weekCount,
|
|
4081
|
+
shownWindow,
|
|
4108
4082
|
windowPolicy,
|
|
4109
4083
|
updateFirstWeek
|
|
4110
4084
|
]);
|
|
4111
4085
|
const scrollToWeek = useCallback((target, options) => {
|
|
4112
|
-
const
|
|
4113
|
-
|
|
4086
|
+
const requested = resolveFirstWeek(shownWindow.firstWeek, weekCount, resolveSpec(target), options);
|
|
4087
|
+
const next = windowPolicy.moveTo(requested);
|
|
4088
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4114
4089
|
}, [
|
|
4115
|
-
|
|
4090
|
+
shownWindow,
|
|
4116
4091
|
weekCount,
|
|
4117
4092
|
resolveSpec,
|
|
4118
4093
|
windowPolicy,
|
|
@@ -4260,14 +4235,18 @@ function useWeeksNavButton(direction, shiftByProp) {
|
|
|
4260
4235
|
const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
|
|
4261
4236
|
const { windowInfo } = useWeeksViewState();
|
|
4262
4237
|
const { rootState } = useViewState();
|
|
4263
|
-
const
|
|
4238
|
+
const { windowStart, weekCount } = windowInfo;
|
|
4264
4239
|
const isDisabled = useMemo(() => {
|
|
4265
4240
|
if (globalDisabled) return true;
|
|
4266
|
-
return
|
|
4241
|
+
return windowPolicy.shift({
|
|
4242
|
+
firstWeek: windowStart,
|
|
4243
|
+
weekCount
|
|
4244
|
+
}, direction === "next" ? 1 : -1, shiftByProp) === null;
|
|
4267
4245
|
}, [
|
|
4268
4246
|
globalDisabled,
|
|
4269
4247
|
windowPolicy,
|
|
4270
|
-
|
|
4248
|
+
windowStart,
|
|
4249
|
+
weekCount,
|
|
4271
4250
|
direction,
|
|
4272
4251
|
shiftByProp
|
|
4273
4252
|
]);
|
|
@@ -2731,7 +2731,7 @@ function useWeeksGridKeyboard() {
|
|
|
2731
2731
|
shiftKey: e.shiftKey,
|
|
2732
2732
|
focusedDate,
|
|
2733
2733
|
windowStart: weeksState.windowInfo.windowStart,
|
|
2734
|
-
weekCount:
|
|
2734
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
2735
2735
|
minValue,
|
|
2736
2736
|
maxValue,
|
|
2737
2737
|
disabled,
|
|
@@ -3766,24 +3766,21 @@ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
|
|
|
3766
3766
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
3767
3767
|
function weekHasValidDay(weekStart, min, max, T) {
|
|
3768
3768
|
const weekEnd = weekStart.add({ days: 6 });
|
|
3769
|
-
return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
|
|
3769
|
+
return (!max || T.PlainDate.compare(weekStart, max) <= 0) && (!min || T.PlainDate.compare(weekEnd, min) >= 0);
|
|
3770
|
+
}
|
|
3771
|
+
/** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
|
|
3772
|
+
function windowHasValidWeek(firstWeek, weekCount, min, max, T) {
|
|
3773
|
+
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
|
|
3774
|
+
return false;
|
|
3770
3775
|
}
|
|
3771
3776
|
/**
|
|
3772
3777
|
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
3773
3778
|
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
3774
3779
|
*/
|
|
3775
|
-
function weekStartContaining(date, weekStartDay
|
|
3780
|
+
function weekStartContaining(date, weekStartDay) {
|
|
3776
3781
|
const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
|
|
3777
3782
|
return date.subtract({ days: daysFromStart });
|
|
3778
3783
|
}
|
|
3779
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains min. */
|
|
3780
|
-
function findFirstValidWeekStart(min, weekStartDay, T) {
|
|
3781
|
-
return weekStartContaining(min, weekStartDay, T);
|
|
3782
|
-
}
|
|
3783
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains max. */
|
|
3784
|
-
function findLastValidWeekStart(max, weekStartDay, T) {
|
|
3785
|
-
return weekStartContaining(max, weekStartDay, T);
|
|
3786
|
-
}
|
|
3787
3784
|
/**
|
|
3788
3785
|
* Trim leading and trailing fully-disabled weeks from a window.
|
|
3789
3786
|
* Returns new { firstWeek, weekCount }.
|
|
@@ -3813,7 +3810,7 @@ function shrinkWindow(firstWeek, weekCount, min, max, T) {
|
|
|
3813
3810
|
* the adjusted { firstWeek, weekCount }.
|
|
3814
3811
|
*/
|
|
3815
3812
|
function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
|
|
3816
|
-
if (!min
|
|
3813
|
+
if (!min && !max || behavior === "unbounded") return {
|
|
3817
3814
|
firstWeek: targetFirstWeek,
|
|
3818
3815
|
weekCount
|
|
3819
3816
|
};
|
|
@@ -3822,52 +3819,18 @@ function applyOutOfRange({ targetFirstWeek, weekCount, behavior, min, max, weekS
|
|
|
3822
3819
|
weekCount
|
|
3823
3820
|
};
|
|
3824
3821
|
if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
|
|
3833
|
-
else resolvedFirst = firstValid;
|
|
3834
|
-
} else resolvedFirst = snappedFirst;
|
|
3835
|
-
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3836
|
-
return {
|
|
3837
|
-
firstWeek: resolvedFirst,
|
|
3838
|
-
weekCount
|
|
3839
|
-
};
|
|
3840
|
-
}
|
|
3822
|
+
const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
|
|
3823
|
+
const lastValid = max && weekStartContaining(max, weekStartDay);
|
|
3824
|
+
const firstValid = min && weekStartContaining(min, weekStartDay);
|
|
3825
|
+
let resolvedFirst = targetFirstWeek;
|
|
3826
|
+
if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
|
|
3827
|
+
else if (firstValid && T.PlainDate.compare(targetFirstWeek, firstValid) < 0) resolvedFirst = firstValid;
|
|
3828
|
+
if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
3841
3829
|
return {
|
|
3842
|
-
firstWeek:
|
|
3830
|
+
firstWeek: resolvedFirst,
|
|
3843
3831
|
weekCount
|
|
3844
3832
|
};
|
|
3845
3833
|
}
|
|
3846
|
-
/**
|
|
3847
|
-
* Returns whether the navigation button for the given direction should be enabled.
|
|
3848
|
-
*/
|
|
3849
|
-
function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
|
|
3850
|
-
if (behavior === "unbounded" || !min || !max) return true;
|
|
3851
|
-
const shift = shiftBy ?? weekCount;
|
|
3852
|
-
const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
|
|
3853
|
-
if (behavior === "stop" || behavior === "stop-shrink") {
|
|
3854
|
-
for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
|
|
3855
|
-
return false;
|
|
3856
|
-
}
|
|
3857
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
3858
|
-
const applied = applyOutOfRange({
|
|
3859
|
-
targetFirstWeek,
|
|
3860
|
-
weekCount,
|
|
3861
|
-
behavior,
|
|
3862
|
-
min,
|
|
3863
|
-
max,
|
|
3864
|
-
weekStartDay,
|
|
3865
|
-
T
|
|
3866
|
-
});
|
|
3867
|
-
return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
|
|
3868
|
-
}
|
|
3869
|
-
return true;
|
|
3870
|
-
}
|
|
3871
3834
|
//#endregion
|
|
3872
3835
|
//#region src/weeks-window.ts
|
|
3873
3836
|
function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T }) {
|
|
@@ -3879,17 +3842,26 @@ function createWeekWindowPolicy({ weekCount, behavior, min, max, weekStartDay, T
|
|
|
3879
3842
|
weekStartDay,
|
|
3880
3843
|
T
|
|
3881
3844
|
};
|
|
3845
|
+
const isStop = behavior === "stop" || behavior === "stop-shrink";
|
|
3846
|
+
const isBounded = min !== void 0 || max !== void 0;
|
|
3847
|
+
const resolve = (requestedFirstWeek) => applyOutOfRange({
|
|
3848
|
+
...bounds,
|
|
3849
|
+
targetFirstWeek: requestedFirstWeek
|
|
3850
|
+
});
|
|
3851
|
+
const moveTo = (requestedFirstWeek) => {
|
|
3852
|
+
if (isStop && isBounded && !windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)) return null;
|
|
3853
|
+
return resolve(requestedFirstWeek);
|
|
3854
|
+
};
|
|
3882
3855
|
return {
|
|
3883
|
-
resolve
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
})
|
|
3856
|
+
resolve,
|
|
3857
|
+
moveTo,
|
|
3858
|
+
shift: (current, direction, shiftBy) => {
|
|
3859
|
+
const by = shiftBy ?? current.weekCount;
|
|
3860
|
+
const next = moveTo(current.firstWeek.add({ weeks: direction * by }));
|
|
3861
|
+
if (next === null) return null;
|
|
3862
|
+
if ((behavior === "snap" || behavior === "snap-shrink") && isBounded && T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0) return null;
|
|
3863
|
+
return next;
|
|
3864
|
+
}
|
|
3893
3865
|
};
|
|
3894
3866
|
}
|
|
3895
3867
|
//#endregion
|
|
@@ -4113,29 +4085,32 @@ function useWeeksViewRootState(props) {
|
|
|
4113
4085
|
if (!isControlled) setInternalFirstWeek(newFirstWeek);
|
|
4114
4086
|
onFirstWeekChange?.(newFirstWeek);
|
|
4115
4087
|
}, [isControlled, onFirstWeekChange]);
|
|
4088
|
+
const shownWindow = (0, react.useMemo)(() => ({
|
|
4089
|
+
firstWeek: windowInfo.windowStart,
|
|
4090
|
+
weekCount: windowInfo.weekCount
|
|
4091
|
+
}), [windowInfo.windowStart, windowInfo.weekCount]);
|
|
4116
4092
|
const goNext = (0, react.useCallback)((shiftBy) => {
|
|
4117
|
-
const
|
|
4118
|
-
updateFirstWeek(
|
|
4093
|
+
const next = windowPolicy.shift(shownWindow, 1, shiftBy);
|
|
4094
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4119
4095
|
}, [
|
|
4120
|
-
|
|
4121
|
-
weekCount,
|
|
4096
|
+
shownWindow,
|
|
4122
4097
|
windowPolicy,
|
|
4123
4098
|
updateFirstWeek
|
|
4124
4099
|
]);
|
|
4125
4100
|
const goPrev = (0, react.useCallback)((shiftBy) => {
|
|
4126
|
-
const
|
|
4127
|
-
updateFirstWeek(
|
|
4101
|
+
const next = windowPolicy.shift(shownWindow, -1, shiftBy);
|
|
4102
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4128
4103
|
}, [
|
|
4129
|
-
|
|
4130
|
-
weekCount,
|
|
4104
|
+
shownWindow,
|
|
4131
4105
|
windowPolicy,
|
|
4132
4106
|
updateFirstWeek
|
|
4133
4107
|
]);
|
|
4134
4108
|
const scrollToWeek = (0, react.useCallback)((target, options) => {
|
|
4135
|
-
const
|
|
4136
|
-
|
|
4109
|
+
const requested = resolveFirstWeek(shownWindow.firstWeek, weekCount, resolveSpec(target), options);
|
|
4110
|
+
const next = windowPolicy.moveTo(requested);
|
|
4111
|
+
if (next) updateFirstWeek(next.firstWeek);
|
|
4137
4112
|
}, [
|
|
4138
|
-
|
|
4113
|
+
shownWindow,
|
|
4139
4114
|
weekCount,
|
|
4140
4115
|
resolveSpec,
|
|
4141
4116
|
windowPolicy,
|
|
@@ -4283,14 +4258,18 @@ function useWeeksNavButton(direction, shiftByProp) {
|
|
|
4283
4258
|
const { windowPolicy, goNext, goPrev } = useWeeksViewStable();
|
|
4284
4259
|
const { windowInfo } = useWeeksViewState();
|
|
4285
4260
|
const { rootState } = useViewState();
|
|
4286
|
-
const
|
|
4261
|
+
const { windowStart, weekCount } = windowInfo;
|
|
4287
4262
|
const isDisabled = (0, react.useMemo)(() => {
|
|
4288
4263
|
if (globalDisabled) return true;
|
|
4289
|
-
return
|
|
4264
|
+
return windowPolicy.shift({
|
|
4265
|
+
firstWeek: windowStart,
|
|
4266
|
+
weekCount
|
|
4267
|
+
}, direction === "next" ? 1 : -1, shiftByProp) === null;
|
|
4290
4268
|
}, [
|
|
4291
4269
|
globalDisabled,
|
|
4292
4270
|
windowPolicy,
|
|
4293
|
-
|
|
4271
|
+
windowStart,
|
|
4272
|
+
weekCount,
|
|
4294
4273
|
direction,
|
|
4295
4274
|
shiftByProp
|
|
4296
4275
|
]);
|
|
@@ -1546,13 +1546,6 @@ interface CalendarStateContextValue {
|
|
|
1546
1546
|
baseRootState: BaseRootState;
|
|
1547
1547
|
}
|
|
1548
1548
|
//#endregion
|
|
1549
|
-
//#region src/calendar-provider.d.ts
|
|
1550
|
-
/**
|
|
1551
|
-
* Provides shared calendar state (selection, config, range preview) to all
|
|
1552
|
-
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
1553
|
-
*/
|
|
1554
|
-
declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: CalendarProviderProps<F>): _$react_jsx_runtime0.JSX.Element;
|
|
1555
|
-
//#endregion
|
|
1556
1549
|
//#region src/out-of-range.d.ts
|
|
1557
1550
|
/**
|
|
1558
1551
|
* Controls how a {@link WeeksView} window behaves when navigation would move it
|
|
@@ -1565,7 +1558,8 @@ declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: Ca
|
|
|
1565
1558
|
* - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
|
|
1566
1559
|
* weeks can be viewed. Out-of-range days simply render disabled. (Default.)
|
|
1567
1560
|
* - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
|
|
1568
|
-
* disabled
|
|
1561
|
+
* disabled, and `goNext`/`goPrev`/`scrollToWeek` and keyboard paging do
|
|
1562
|
+
* nothing, once the next step would show a window containing no in-range day.
|
|
1569
1563
|
* - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
|
|
1570
1564
|
* fewer week rows instead of showing rows that are entirely out of range.
|
|
1571
1565
|
* - `"snap"` — A jump that would overshoot **snaps** the window so its edge
|
|
@@ -1573,6 +1567,8 @@ declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: Ca
|
|
|
1573
1567
|
* - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
|
|
1574
1568
|
* the in-range weeks.
|
|
1575
1569
|
*
|
|
1570
|
+
* A single bound (`min` only or `max` only) is honored; the missing side is unlimited.
|
|
1571
|
+
*
|
|
1576
1572
|
* `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
|
|
1577
1573
|
* fewer weeks than `weekCount`** — i.e. the window is taller than the range.
|
|
1578
1574
|
* Snapping can only pin *one* edge to a bound; if the range is narrower than the
|
|
@@ -1896,18 +1892,29 @@ interface WeekDescriptor {
|
|
|
1896
1892
|
declare function computeWeeksInWindow(firstWeek: Temporal.PlainDate, weekCount: number, weekStartDay: WeekStartDay, _T: TemporalNamespace): WeekDescriptor[];
|
|
1897
1893
|
//#endregion
|
|
1898
1894
|
//#region src/weeks-window.d.ts
|
|
1895
|
+
/** A window as shown: its first week and how many rows it has (≤ the prop). */
|
|
1896
|
+
interface EffectiveWindow {
|
|
1897
|
+
firstWeek: Temporal.PlainDate;
|
|
1898
|
+
weekCount: number;
|
|
1899
|
+
}
|
|
1899
1900
|
/**
|
|
1900
1901
|
* The rules for where a WeeksView window may sit. Built once from the bounds and
|
|
1901
1902
|
* shared by every way of moving the window (buttons, keyboard, `scrollToWeek`).
|
|
1902
1903
|
*/
|
|
1903
1904
|
interface WeekWindowPolicy {
|
|
1904
|
-
/**
|
|
1905
|
-
resolve(requestedFirstWeek: Temporal.PlainDate):
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1905
|
+
/** The window that is shown for a requested first week. Never refuses. */
|
|
1906
|
+
resolve(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow;
|
|
1907
|
+
/**
|
|
1908
|
+
* The window to move to for a requested first week, or `null` when the
|
|
1909
|
+
* behavior forbids the move (`stop`/`stop-shrink` with no in-range day in it).
|
|
1910
|
+
*/
|
|
1911
|
+
moveTo(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow | null;
|
|
1912
|
+
/**
|
|
1913
|
+
* Moves by `shiftBy` weeks (default: the rows currently shown) from the
|
|
1914
|
+
* window as shown. `null` when the move is forbidden or would not change
|
|
1915
|
+
* the window (`snap` already at the edge).
|
|
1916
|
+
*/
|
|
1917
|
+
shift(current: EffectiveWindow, direction: 1 | -1, shiftBy?: number): EffectiveWindow | null;
|
|
1911
1918
|
}
|
|
1912
1919
|
//#endregion
|
|
1913
1920
|
//#region src/weeks-view-types.d.ts
|
|
@@ -2163,4 +2170,4 @@ declare function useWeeksViewStable(): WeeksViewStableContextValue;
|
|
|
2163
2170
|
/** Returns the WeeksView state context (volatile grid data). */
|
|
2164
2171
|
declare function useWeeksViewState(): WeeksViewStateContextValue;
|
|
2165
2172
|
//#endregion
|
|
2166
|
-
export { GridBody as $,
|
|
2173
|
+
export { GridBody as $, TimeStringState as $t, VisibleMonth as A, GridHeaderProps as At, resolveFirstWeekSpec as B, PlainDateObject as Bt, WeekCountState as C, DayCellTemplateState as Ct, WeeksViewProps as D, GridBodyState as Dt, WeeksView as E, GridBodyProps as Et, WeekDescriptor as F, MonthYearStringProps as Ft, RangePreview as G, RangePreviewState as Gt, WeekNumberHeader as H, RangeEndDragHandleProps as Ht, computeWeeksInWindow as I, MonthYearStringState as It, MonthYearString as J, RangeStartDragHandleProps as Jt, RangeSelected as K, RangeSelectedProps as Kt, FirstWeekSpec as L, NavButtonState as Lt, WeeksViewStableContextValue as M, GridProps as Mt, WeeksViewStateContextValue as N, GridState as Nt, WeeksViewRoot as O, GridHeaderCellProps as Ot, WindowInfo as P, MonthData as Pt, Grid as Q, TimeStringProps as Qt, ScrollToWeekSnap as R, NextMonthButtonProps as Rt, WeekCountProps as S, DayCellTemplateProps as St, WeeksNavButtonState as T, DragHandleState as Tt, RangeEndDragHandle as U, RangeMode as Ut, WeekNumberCell as V, PrevMonthButtonProps as Vt, RangeStartDragHandle as W, RangePreviewProps as Wt, PrevMonthButton as X, RootState as Xt, NextMonthButton as Y, RawValueForFormat as Yt, TimeString as Z, TemporalNamespace as Zt, NextWeeksButton as _, DateStringProps as _t, useMonthViewStable as a, WeekNumberHeaderProps as an, MonthView as at, PrevWeeksButtonProps as b, DayButtonProps as bt, useCalendarState as c, WeekTemplateProps as cn, MonthViewRootProps as ct, MonthSeparatorCell as d, GridContext as dn, MonthOutOfRangeBehavior as dt, ValueChangeMeta as en, WeekTemplate as et, MonthSeparatorMonth as f, WeekDataContext as fn, OutOfRangeBehavior as ft, MonthSeparatorYear as g, DateRange as gt, MonthSeparatorWeekCount as h, CalendarStateContextValue as ht, useViewContext as i, WeekNumberCellState as in, GridHeaderCell as it, WeeksViewRootProps as j, GridHeaderState as jt, WeeksViewRootHandle as k, GridHeaderCellState as kt, computePreviewRange as l, WeekTemplateState as ln, MonthViewStableContextValue as lt, MonthSeparatorState as m, CalendarStableContextValue as mt, useWeeksViewState as n, ValueFormat as nn, DayCellTemplate as nt, useMonthViewState as o, WeekNumberHeaderState as on, MonthViewProps as ot, MonthSeparatorRow as p, CalendarProviderProps as pt, DateString as q, RangeSelectedState as qt, ViewContextValue as r, WeekNumberCellProps as rn, GridHeader as rt, useCalendarStable as s, WeekStartDay as sn, MonthViewRoot as st, useWeeksViewStable as t, ValueForFormat as tn, DayButton as tt, MonthSeparator as u, DayCellDataContext as un, MonthViewStateContextValue as ut, NextWeeksButtonProps as v, DateStringState as vt, WeeksNavButtonOwnProps as w, DragHandleOwnProps as wt, WeekCount as x, DayButtonState as xt, PrevWeeksButton as y, DateValueObject as yt, resolveFirstWeek as z, OutsideDays as zt };
|
|
@@ -1546,13 +1546,6 @@ interface CalendarStateContextValue {
|
|
|
1546
1546
|
baseRootState: BaseRootState;
|
|
1547
1547
|
}
|
|
1548
1548
|
//#endregion
|
|
1549
|
-
//#region src/calendar-provider.d.ts
|
|
1550
|
-
/**
|
|
1551
|
-
* Provides shared calendar state (selection, config, range preview) to all
|
|
1552
|
-
* descendant view components. Does NOT manage focus, navigation, or grid data.
|
|
1553
|
-
*/
|
|
1554
|
-
declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: CalendarProviderProps<F>): _$react_jsx_runtime0.JSX.Element;
|
|
1555
|
-
//#endregion
|
|
1556
1549
|
//#region src/out-of-range.d.ts
|
|
1557
1550
|
/**
|
|
1558
1551
|
* Controls how a {@link WeeksView} window behaves when navigation would move it
|
|
@@ -1565,7 +1558,8 @@ declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: Ca
|
|
|
1565
1558
|
* - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
|
|
1566
1559
|
* weeks can be viewed. Out-of-range days simply render disabled. (Default.)
|
|
1567
1560
|
* - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
|
|
1568
|
-
* disabled
|
|
1561
|
+
* disabled, and `goNext`/`goPrev`/`scrollToWeek` and keyboard paging do
|
|
1562
|
+
* nothing, once the next step would show a window containing no in-range day.
|
|
1569
1563
|
* - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
|
|
1570
1564
|
* fewer week rows instead of showing rows that are entirely out of range.
|
|
1571
1565
|
* - `"snap"` — A jump that would overshoot **snaps** the window so its edge
|
|
@@ -1573,6 +1567,8 @@ declare function CalendarProvider<F extends ValueFormat = "PlainDate">(props: Ca
|
|
|
1573
1567
|
* - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
|
|
1574
1568
|
* the in-range weeks.
|
|
1575
1569
|
*
|
|
1570
|
+
* A single bound (`min` only or `max` only) is honored; the missing side is unlimited.
|
|
1571
|
+
*
|
|
1576
1572
|
* `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
|
|
1577
1573
|
* fewer weeks than `weekCount`** — i.e. the window is taller than the range.
|
|
1578
1574
|
* Snapping can only pin *one* edge to a bound; if the range is narrower than the
|
|
@@ -1896,18 +1892,29 @@ interface WeekDescriptor {
|
|
|
1896
1892
|
declare function computeWeeksInWindow(firstWeek: Temporal.PlainDate, weekCount: number, weekStartDay: WeekStartDay, _T: TemporalNamespace): WeekDescriptor[];
|
|
1897
1893
|
//#endregion
|
|
1898
1894
|
//#region src/weeks-window.d.ts
|
|
1895
|
+
/** A window as shown: its first week and how many rows it has (≤ the prop). */
|
|
1896
|
+
interface EffectiveWindow {
|
|
1897
|
+
firstWeek: Temporal.PlainDate;
|
|
1898
|
+
weekCount: number;
|
|
1899
|
+
}
|
|
1899
1900
|
/**
|
|
1900
1901
|
* The rules for where a WeeksView window may sit. Built once from the bounds and
|
|
1901
1902
|
* shared by every way of moving the window (buttons, keyboard, `scrollToWeek`).
|
|
1902
1903
|
*/
|
|
1903
1904
|
interface WeekWindowPolicy {
|
|
1904
|
-
/**
|
|
1905
|
-
resolve(requestedFirstWeek: Temporal.PlainDate):
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1905
|
+
/** The window that is shown for a requested first week. Never refuses. */
|
|
1906
|
+
resolve(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow;
|
|
1907
|
+
/**
|
|
1908
|
+
* The window to move to for a requested first week, or `null` when the
|
|
1909
|
+
* behavior forbids the move (`stop`/`stop-shrink` with no in-range day in it).
|
|
1910
|
+
*/
|
|
1911
|
+
moveTo(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow | null;
|
|
1912
|
+
/**
|
|
1913
|
+
* Moves by `shiftBy` weeks (default: the rows currently shown) from the
|
|
1914
|
+
* window as shown. `null` when the move is forbidden or would not change
|
|
1915
|
+
* the window (`snap` already at the edge).
|
|
1916
|
+
*/
|
|
1917
|
+
shift(current: EffectiveWindow, direction: 1 | -1, shiftBy?: number): EffectiveWindow | null;
|
|
1911
1918
|
}
|
|
1912
1919
|
//#endregion
|
|
1913
1920
|
//#region src/weeks-view-types.d.ts
|
|
@@ -2163,4 +2170,4 @@ declare function useWeeksViewStable(): WeeksViewStableContextValue;
|
|
|
2163
2170
|
/** Returns the WeeksView state context (volatile grid data). */
|
|
2164
2171
|
declare function useWeeksViewState(): WeeksViewStateContextValue;
|
|
2165
2172
|
//#endregion
|
|
2166
|
-
export { GridBody as $,
|
|
2173
|
+
export { GridBody as $, TimeStringState as $t, VisibleMonth as A, GridHeaderProps as At, resolveFirstWeekSpec as B, PlainDateObject as Bt, WeekCountState as C, DayCellTemplateState as Ct, WeeksViewProps as D, GridBodyState as Dt, WeeksView as E, GridBodyProps as Et, WeekDescriptor as F, MonthYearStringProps as Ft, RangePreview as G, RangePreviewState as Gt, WeekNumberHeader as H, RangeEndDragHandleProps as Ht, computeWeeksInWindow as I, MonthYearStringState as It, MonthYearString as J, RangeStartDragHandleProps as Jt, RangeSelected as K, RangeSelectedProps as Kt, FirstWeekSpec as L, NavButtonState as Lt, WeeksViewStableContextValue as M, GridProps as Mt, WeeksViewStateContextValue as N, GridState as Nt, WeeksViewRoot as O, GridHeaderCellProps as Ot, WindowInfo as P, MonthData as Pt, Grid as Q, TimeStringProps as Qt, ScrollToWeekSnap as R, NextMonthButtonProps as Rt, WeekCountProps as S, DayCellTemplateProps as St, WeeksNavButtonState as T, DragHandleState as Tt, RangeEndDragHandle as U, RangeMode as Ut, WeekNumberCell as V, PrevMonthButtonProps as Vt, RangeStartDragHandle as W, RangePreviewProps as Wt, PrevMonthButton as X, RootState as Xt, NextMonthButton as Y, RawValueForFormat as Yt, TimeString as Z, TemporalNamespace as Zt, NextWeeksButton as _, DateStringProps as _t, useMonthViewStable as a, WeekNumberHeaderProps as an, MonthView as at, PrevWeeksButtonProps as b, DayButtonProps as bt, useCalendarState as c, WeekTemplateProps as cn, MonthViewRootProps as ct, MonthSeparatorCell as d, GridContext as dn, MonthOutOfRangeBehavior as dt, ValueChangeMeta as en, WeekTemplate as et, MonthSeparatorMonth as f, WeekDataContext as fn, OutOfRangeBehavior as ft, MonthSeparatorYear as g, DateRange as gt, MonthSeparatorWeekCount as h, CalendarStateContextValue as ht, useViewContext as i, WeekNumberCellState as in, GridHeaderCell as it, WeeksViewRootProps as j, GridHeaderState as jt, WeeksViewRootHandle as k, GridHeaderCellState as kt, computePreviewRange as l, WeekTemplateState as ln, MonthViewStableContextValue as lt, MonthSeparatorState as m, CalendarStableContextValue as mt, useWeeksViewState as n, ValueFormat as nn, DayCellTemplate as nt, useMonthViewState as o, WeekNumberHeaderState as on, MonthViewProps as ot, MonthSeparatorRow as p, CalendarProviderProps as pt, DateString as q, RangeSelectedState as qt, ViewContextValue as r, WeekNumberCellProps as rn, GridHeader as rt, useCalendarStable as s, WeekStartDay as sn, MonthViewRoot as st, useWeeksViewStable as t, ValueForFormat as tn, DayButton as tt, MonthSeparator as u, DayCellDataContext as un, MonthViewStateContextValue as ut, NextWeeksButtonProps as v, DateStringState as vt, WeeksNavButtonOwnProps as w, DragHandleOwnProps as wt, WeekCount as x, DayButtonState as xt, PrevWeeksButton as y, DateValueObject as yt, resolveFirstWeek as z, OutsideDays as zt };
|
package/package.json
CHANGED
package/src/grid.tsx
CHANGED
|
@@ -109,7 +109,7 @@ function useWeeksGridKeyboard() {
|
|
|
109
109
|
shiftKey: e.shiftKey,
|
|
110
110
|
focusedDate,
|
|
111
111
|
windowStart: weeksState.windowInfo.windowStart,
|
|
112
|
-
weekCount:
|
|
112
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
113
113
|
minValue,
|
|
114
114
|
maxValue,
|
|
115
115
|
disabled,
|