@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
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import {
|
|
3
|
+
render,
|
|
4
|
+
screen,
|
|
5
|
+
act,
|
|
6
|
+
cleanup,
|
|
7
|
+
fireEvent,
|
|
8
|
+
} from "@testing-library/react";
|
|
9
|
+
import { createRef } from "react";
|
|
10
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
11
|
+
import {
|
|
12
|
+
Grid,
|
|
13
|
+
GridBody,
|
|
14
|
+
WeekTemplate,
|
|
15
|
+
DayCellTemplate,
|
|
16
|
+
DayButton,
|
|
17
|
+
} from "./grid";
|
|
18
|
+
import type { OutOfRangeBehavior } from "./out-of-range";
|
|
19
|
+
import { useViewContext } from "./view-context";
|
|
20
|
+
import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation";
|
|
21
|
+
import { WeeksView, type WeeksViewRootHandle } from "./weeks-view";
|
|
22
|
+
import { useWeeksViewState } from "./weeks-view-context";
|
|
23
|
+
|
|
24
|
+
const T = Temporal;
|
|
25
|
+
const pd = (s: string) => T.PlainDate.from(s);
|
|
26
|
+
|
|
27
|
+
function WindowDisplay() {
|
|
28
|
+
const { windowInfo } = useWeeksViewState();
|
|
29
|
+
return (
|
|
30
|
+
<div>
|
|
31
|
+
<span data-testid="start">{windowInfo.windowStart.toString()}</span>
|
|
32
|
+
<span data-testid="count">{windowInfo.weekCount}</span>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function FocusDisplay() {
|
|
38
|
+
return (
|
|
39
|
+
<span data-testid="focus">{useViewContext().focusedDate.toString()}</span>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface Setup {
|
|
44
|
+
behavior: OutOfRangeBehavior;
|
|
45
|
+
weekCount: number;
|
|
46
|
+
firstWeek: string;
|
|
47
|
+
min?: string;
|
|
48
|
+
max?: string;
|
|
49
|
+
value?: string;
|
|
50
|
+
handle?: React.RefObject<WeeksViewRootHandle | null>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function renderWindow({
|
|
54
|
+
behavior,
|
|
55
|
+
weekCount,
|
|
56
|
+
firstWeek,
|
|
57
|
+
min,
|
|
58
|
+
max,
|
|
59
|
+
value,
|
|
60
|
+
handle,
|
|
61
|
+
}: Setup) {
|
|
62
|
+
return render(
|
|
63
|
+
<WeeksView
|
|
64
|
+
ref={handle}
|
|
65
|
+
temporal={T}
|
|
66
|
+
weekCount={weekCount}
|
|
67
|
+
defaultFirstWeek={pd(firstWeek)}
|
|
68
|
+
outOfRangeBehavior={behavior}
|
|
69
|
+
{...(min && { min: pd(min) })}
|
|
70
|
+
{...(max && { max: pd(max) })}
|
|
71
|
+
{...(value && { defaultValue: pd(value) })}
|
|
72
|
+
>
|
|
73
|
+
<FocusDisplay />
|
|
74
|
+
<WindowDisplay />
|
|
75
|
+
<PrevWeeksButton data-testid="prev" />
|
|
76
|
+
<NextWeeksButton data-testid="next" />
|
|
77
|
+
<Grid>
|
|
78
|
+
<GridBody>
|
|
79
|
+
<WeekTemplate>
|
|
80
|
+
<DayCellTemplate>
|
|
81
|
+
<DayButton />
|
|
82
|
+
</DayCellTemplate>
|
|
83
|
+
</WeekTemplate>
|
|
84
|
+
</GridBody>
|
|
85
|
+
</Grid>
|
|
86
|
+
</WeeksView>,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const start = () => screen.getByTestId("start").textContent;
|
|
91
|
+
const click = (id: string) =>
|
|
92
|
+
act(() => {
|
|
93
|
+
screen.getByTestId(id).click();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
afterEach(cleanup);
|
|
97
|
+
|
|
98
|
+
describe("WeeksView window bounds: stop holds for every way of moving", () => {
|
|
99
|
+
it.each([
|
|
100
|
+
{
|
|
101
|
+
description: "scrollToWeek refuses to leave the bound under stop",
|
|
102
|
+
behavior: "stop" as const,
|
|
103
|
+
expected: { start: "2026-03-01" },
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
description: "scrollToWeek refuses to leave the bound under stop-shrink",
|
|
107
|
+
behavior: "stop-shrink" as const,
|
|
108
|
+
expected: { start: "2026-03-01" },
|
|
109
|
+
},
|
|
110
|
+
])("$description", ({ behavior, expected }) => {
|
|
111
|
+
const handle = createRef<WeeksViewRootHandle>();
|
|
112
|
+
renderWindow({
|
|
113
|
+
behavior,
|
|
114
|
+
weekCount: 2,
|
|
115
|
+
firstWeek: "2026-03-01",
|
|
116
|
+
min: "2026-03-01",
|
|
117
|
+
max: "2026-03-14",
|
|
118
|
+
handle,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
act(() => handle.current?.scrollToWeek(pd("2026-06-07")));
|
|
122
|
+
|
|
123
|
+
expect(start()).toBe(expected.start);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("scrollToWeek still moves when the target window keeps an in-range day", () => {
|
|
127
|
+
const handle = createRef<WeeksViewRootHandle>();
|
|
128
|
+
renderWindow({
|
|
129
|
+
behavior: "stop",
|
|
130
|
+
weekCount: 2,
|
|
131
|
+
firstWeek: "2026-03-01",
|
|
132
|
+
min: "2026-03-01",
|
|
133
|
+
max: "2026-03-21",
|
|
134
|
+
handle,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
act(() => handle.current?.scrollToWeek(pd("2026-03-08")));
|
|
138
|
+
|
|
139
|
+
expect(start()).toBe("2026-03-08");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("WeeksView window bounds: a single bound is honored", () => {
|
|
144
|
+
it.each([
|
|
145
|
+
{
|
|
146
|
+
description: "min only, stop: Prev cannot page before min",
|
|
147
|
+
behavior: "stop" as const,
|
|
148
|
+
bounds: { min: "2026-03-01" },
|
|
149
|
+
button: "prev",
|
|
150
|
+
expected: { start: "2026-03-01", disabled: true },
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
description: "max only, stop: Next cannot page past max",
|
|
154
|
+
behavior: "stop" as const,
|
|
155
|
+
bounds: { max: "2026-03-14" },
|
|
156
|
+
button: "next",
|
|
157
|
+
expected: { start: "2026-03-01", disabled: true },
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
description: "max only, snap: Next snaps back instead of overshooting",
|
|
161
|
+
behavior: "snap" as const,
|
|
162
|
+
bounds: { max: "2026-03-14" },
|
|
163
|
+
button: "next",
|
|
164
|
+
expected: { start: "2026-03-01", disabled: true },
|
|
165
|
+
},
|
|
166
|
+
])("$description", ({ behavior, bounds, button, expected }) => {
|
|
167
|
+
renderWindow({
|
|
168
|
+
behavior,
|
|
169
|
+
weekCount: 2,
|
|
170
|
+
firstWeek: "2026-03-01",
|
|
171
|
+
...bounds,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect((screen.getByTestId(button) as HTMLButtonElement).disabled).toBe(
|
|
175
|
+
expected.disabled,
|
|
176
|
+
);
|
|
177
|
+
click(button);
|
|
178
|
+
expect(start()).toBe(expected.start);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("WeeksView window bounds: a shrunk window pages by the rows it shows", () => {
|
|
183
|
+
// 4-row prop, but max 03-14 trims the window to the 2 rows 03-01..03-14.
|
|
184
|
+
const shrunk = {
|
|
185
|
+
behavior: "stop-shrink" as const,
|
|
186
|
+
weekCount: 4,
|
|
187
|
+
firstWeek: "2026-03-01",
|
|
188
|
+
min: "2026-01-01",
|
|
189
|
+
max: "2026-03-14",
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
it("Prev shifts by the shown row count", () => {
|
|
193
|
+
renderWindow(shrunk);
|
|
194
|
+
expect(screen.getByTestId("count").textContent).toBe("2");
|
|
195
|
+
|
|
196
|
+
click("prev");
|
|
197
|
+
|
|
198
|
+
expect(start()).toBe("2026-02-15");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("PageUp moves focus by the shown row count", () => {
|
|
202
|
+
renderWindow({ ...shrunk, value: "2026-03-08" });
|
|
203
|
+
|
|
204
|
+
fireEvent.keyDown(screen.getByRole("grid"), { key: "PageUp" });
|
|
205
|
+
|
|
206
|
+
expect(screen.getByTestId("focus").textContent).toBe("2026-02-22");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe("WeeksView window bounds: End stays inside a trimmed window", () => {
|
|
211
|
+
it("End focuses the last shown day after leading rows are trimmed", () => {
|
|
212
|
+
// min trims 02-15 and 02-22, leaving the 2 rows 03-01..03-14.
|
|
213
|
+
renderWindow({
|
|
214
|
+
behavior: "stop-shrink",
|
|
215
|
+
weekCount: 4,
|
|
216
|
+
firstWeek: "2026-02-15",
|
|
217
|
+
min: "2026-03-01",
|
|
218
|
+
value: "2026-03-01",
|
|
219
|
+
});
|
|
220
|
+
expect(screen.getByTestId("count").textContent).toBe("2");
|
|
221
|
+
|
|
222
|
+
fireEvent.keyDown(screen.getByRole("grid"), { key: "End" });
|
|
223
|
+
|
|
224
|
+
expect(screen.getByTestId("focus").textContent).toBe("2026-03-14");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("WeeksView window bounds: buttons act on the window that is shown", () => {
|
|
229
|
+
it("Prev from an over-shoot initial window moves from the snapped window", () => {
|
|
230
|
+
// 03-22 overshoots max, so the shown window is the snapped 03-01 one.
|
|
231
|
+
renderWindow({
|
|
232
|
+
behavior: "snap",
|
|
233
|
+
weekCount: 2,
|
|
234
|
+
firstWeek: "2026-03-22",
|
|
235
|
+
max: "2026-03-14",
|
|
236
|
+
});
|
|
237
|
+
expect(start()).toBe("2026-03-01");
|
|
238
|
+
expect((screen.getByTestId("prev") as HTMLButtonElement).disabled).toBe(
|
|
239
|
+
false,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
click("prev");
|
|
243
|
+
|
|
244
|
+
expect(start()).toBe("2026-02-15");
|
|
245
|
+
});
|
|
246
|
+
});
|
package/src/weeks-window.test.ts
CHANGED
|
@@ -1,43 +1,131 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { describe, it, expect } from "vitest";
|
|
3
|
+
import type { OutOfRangeBehavior } from "./out-of-range";
|
|
3
4
|
import { createWeekWindowPolicy } from "./weeks-window";
|
|
4
5
|
|
|
5
6
|
const T = Temporal;
|
|
6
7
|
const pd = (s: string) => T.PlainDate.from(s);
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
function policyFor(
|
|
10
|
+
behavior: OutOfRangeBehavior,
|
|
11
|
+
bounds: { min?: string; max?: string } = {
|
|
12
|
+
min: "2025-12-01",
|
|
13
|
+
max: "2026-01-10",
|
|
14
|
+
},
|
|
15
|
+
) {
|
|
16
|
+
return createWeekWindowPolicy({
|
|
17
|
+
weekCount: 8,
|
|
18
|
+
behavior,
|
|
19
|
+
min: bounds.min ? pd(bounds.min) : undefined,
|
|
20
|
+
max: bounds.max ? pd(bounds.max) : undefined,
|
|
14
21
|
weekStartDay: 0,
|
|
15
22
|
T,
|
|
16
23
|
});
|
|
24
|
+
}
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
weekCount: 4,
|
|
23
|
-
});
|
|
24
|
-
});
|
|
26
|
+
const shown = (firstWeek: string, weekCount = 8) => ({
|
|
27
|
+
firstWeek: pd(firstWeek),
|
|
28
|
+
weekCount,
|
|
29
|
+
});
|
|
25
30
|
|
|
31
|
+
describe("WeekWindowPolicy.shift", () => {
|
|
26
32
|
it.each([
|
|
33
|
+
{
|
|
34
|
+
description: "unbounded — always allowed",
|
|
35
|
+
behavior: "unbounded" as const,
|
|
36
|
+
from: shown("2026-06-01"),
|
|
37
|
+
direction: 1 as const,
|
|
38
|
+
expected: { allowed: true },
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
description: "stop — refused when the target window has no in-range week",
|
|
42
|
+
behavior: "stop" as const,
|
|
43
|
+
from: shown("2025-12-28"),
|
|
44
|
+
direction: 1 as const,
|
|
45
|
+
expected: { allowed: false },
|
|
46
|
+
},
|
|
27
47
|
{
|
|
28
48
|
description:
|
|
29
|
-
"
|
|
30
|
-
|
|
49
|
+
"stop-shrink — refused when the target window has no in-range week",
|
|
50
|
+
behavior: "stop-shrink" as const,
|
|
51
|
+
from: shown("2025-12-28"),
|
|
31
52
|
direction: 1 as const,
|
|
32
|
-
expected: false,
|
|
53
|
+
expected: { allowed: false },
|
|
33
54
|
},
|
|
34
55
|
{
|
|
35
|
-
description: "
|
|
36
|
-
|
|
56
|
+
description: "snap — refused when already at the clamp position",
|
|
57
|
+
behavior: "snap" as const,
|
|
58
|
+
from: shown("2025-11-16"),
|
|
59
|
+
direction: 1 as const,
|
|
60
|
+
expected: { allowed: false },
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
description: "snap — allowed away from the clamp position",
|
|
64
|
+
behavior: "snap" as const,
|
|
65
|
+
from: shown("2025-11-16"),
|
|
66
|
+
direction: -1 as const,
|
|
67
|
+
expected: { allowed: true },
|
|
68
|
+
},
|
|
69
|
+
])("$description", ({ behavior, from, direction, expected }) => {
|
|
70
|
+
expect(policyFor(behavior).shift(from, direction) !== null).toBe(
|
|
71
|
+
expected.allowed,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("shifts by the rows currently shown, not the weekCount prop", () => {
|
|
76
|
+
const next = policyFor("stop-shrink", {
|
|
77
|
+
min: "2025-01-01",
|
|
78
|
+
max: "2026-03-14",
|
|
79
|
+
}).shift(shown("2026-03-01", 2), -1);
|
|
80
|
+
expect(next?.firstWeek.toString()).toBe("2026-02-15");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it.each([
|
|
84
|
+
{
|
|
85
|
+
description: "min only, stop — Prev refused below the bound",
|
|
86
|
+
behavior: "stop" as const,
|
|
87
|
+
bounds: { min: "2026-03-01" },
|
|
37
88
|
direction: -1 as const,
|
|
38
|
-
expected:
|
|
89
|
+
expected: { allowed: false },
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
description: "max only, stop — Next refused past the bound",
|
|
93
|
+
behavior: "stop" as const,
|
|
94
|
+
bounds: { max: "2026-03-14" },
|
|
95
|
+
direction: 1 as const,
|
|
96
|
+
expected: { allowed: false },
|
|
97
|
+
},
|
|
98
|
+
])("$description", ({ behavior, bounds, direction, expected }) => {
|
|
99
|
+
expect(
|
|
100
|
+
policyFor(behavior, bounds).shift(shown("2026-03-01"), direction) !==
|
|
101
|
+
null,
|
|
102
|
+
).toBe(expected.allowed);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("WeekWindowPolicy.moveTo", () => {
|
|
107
|
+
it.each([
|
|
108
|
+
{
|
|
109
|
+
description: "stop — refused when no row is in range",
|
|
110
|
+
behavior: "stop" as const,
|
|
111
|
+
target: "2026-06-07",
|
|
112
|
+
expected: null,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
description: "stop — allowed when part of the window is in range",
|
|
116
|
+
behavior: "stop" as const,
|
|
117
|
+
target: "2026-01-04",
|
|
118
|
+
expected: "2026-01-04",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
description: "snap — pulls back instead of refusing",
|
|
122
|
+
behavior: "snap" as const,
|
|
123
|
+
target: "2026-06-07",
|
|
124
|
+
expected: "2025-11-16",
|
|
39
125
|
},
|
|
40
|
-
])("
|
|
41
|
-
expect(
|
|
126
|
+
])("$description", ({ behavior, target, expected }) => {
|
|
127
|
+
expect(
|
|
128
|
+
policyFor(behavior).moveTo(pd(target))?.firstWeek.toString() ?? null,
|
|
129
|
+
).toBe(expected);
|
|
42
130
|
});
|
|
43
131
|
});
|
package/src/weeks-window.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import {
|
|
3
3
|
applyOutOfRange,
|
|
4
|
-
|
|
4
|
+
windowHasValidWeek,
|
|
5
5
|
type OutOfRangeBehavior,
|
|
6
6
|
} from "./out-of-range";
|
|
7
7
|
import type { TemporalNamespace, WeekStartDay } from "./types";
|
|
8
8
|
|
|
9
9
|
/** Inputs that determine how a weeks window may move relative to `min`/`max`. */
|
|
10
10
|
export interface WeekWindowPolicyInput {
|
|
11
|
+
/** The `weekCount` prop: the most rows a window will ever show. */
|
|
11
12
|
weekCount: number;
|
|
12
13
|
behavior: OutOfRangeBehavior;
|
|
13
14
|
min: Temporal.PlainDate | undefined;
|
|
@@ -16,22 +17,34 @@ export interface WeekWindowPolicyInput {
|
|
|
16
17
|
T: TemporalNamespace;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/** A window as shown: its first week and how many rows it has (≤ the prop). */
|
|
21
|
+
export interface EffectiveWindow {
|
|
22
|
+
firstWeek: Temporal.PlainDate;
|
|
23
|
+
weekCount: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* The rules for where a WeeksView window may sit. Built once from the bounds and
|
|
21
28
|
* shared by every way of moving the window (buttons, keyboard, `scrollToWeek`).
|
|
22
29
|
*/
|
|
23
30
|
export interface WeekWindowPolicy {
|
|
24
|
-
/**
|
|
25
|
-
resolve(requestedFirstWeek: Temporal.PlainDate):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/** The window that is shown for a requested first week. Never refuses. */
|
|
32
|
+
resolve(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow;
|
|
33
|
+
/**
|
|
34
|
+
* The window to move to for a requested first week, or `null` when the
|
|
35
|
+
* behavior forbids the move (`stop`/`stop-shrink` with no in-range day in it).
|
|
36
|
+
*/
|
|
37
|
+
moveTo(requestedFirstWeek: Temporal.PlainDate): EffectiveWindow | null;
|
|
38
|
+
/**
|
|
39
|
+
* Moves by `shiftBy` weeks (default: the rows currently shown) from the
|
|
40
|
+
* window as shown. `null` when the move is forbidden or would not change
|
|
41
|
+
* the window (`snap` already at the edge).
|
|
42
|
+
*/
|
|
43
|
+
shift(
|
|
44
|
+
current: EffectiveWindow,
|
|
32
45
|
direction: 1 | -1,
|
|
33
46
|
shiftBy?: number,
|
|
34
|
-
):
|
|
47
|
+
): EffectiveWindow | null;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
export function createWeekWindowPolicy({
|
|
@@ -50,15 +63,40 @@ export function createWeekWindowPolicy({
|
|
|
50
63
|
weekStartDay,
|
|
51
64
|
T,
|
|
52
65
|
};
|
|
66
|
+
const isStop = behavior === "stop" || behavior === "stop-shrink";
|
|
67
|
+
const isBounded = min !== undefined || max !== undefined;
|
|
68
|
+
|
|
69
|
+
const resolve: WeekWindowPolicy["resolve"] = (requestedFirstWeek) =>
|
|
70
|
+
applyOutOfRange({ ...bounds, targetFirstWeek: requestedFirstWeek });
|
|
71
|
+
|
|
72
|
+
const moveTo: WeekWindowPolicy["moveTo"] = (requestedFirstWeek) => {
|
|
73
|
+
if (
|
|
74
|
+
isStop &&
|
|
75
|
+
isBounded &&
|
|
76
|
+
!windowHasValidWeek(requestedFirstWeek, weekCount, min, max, T)
|
|
77
|
+
) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return resolve(requestedFirstWeek);
|
|
81
|
+
};
|
|
82
|
+
|
|
53
83
|
return {
|
|
54
|
-
resolve
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
84
|
+
resolve,
|
|
85
|
+
moveTo,
|
|
86
|
+
shift: (current, direction, shiftBy) => {
|
|
87
|
+
const by = shiftBy ?? current.weekCount;
|
|
88
|
+
const target = current.firstWeek.add({ weeks: direction * by });
|
|
89
|
+
const next = moveTo(target);
|
|
90
|
+
if (next === null) return null;
|
|
91
|
+
const isSnap = behavior === "snap" || behavior === "snap-shrink";
|
|
92
|
+
if (
|
|
93
|
+
isSnap &&
|
|
94
|
+
isBounded &&
|
|
95
|
+
T.PlainDate.compare(next.firstWeek, current.firstWeek) === 0
|
|
96
|
+
) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return next;
|
|
100
|
+
},
|
|
63
101
|
};
|
|
64
102
|
}
|