@klinking/colander 2.0.2 → 3.0.0

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.
Files changed (56) hide show
  1. package/dist/formats/date.cjs +1 -1
  2. package/dist/formats/date.d.cts +2 -2
  3. package/dist/formats/date.d.mts +2 -2
  4. package/dist/formats/date.mjs +1 -1
  5. package/dist/formats/object.cjs +1 -1
  6. package/dist/formats/object.d.cts +2 -2
  7. package/dist/formats/object.d.mts +2 -2
  8. package/dist/formats/object.mjs +1 -1
  9. package/dist/formats/plain-date-time.cjs +1 -1
  10. package/dist/formats/plain-date-time.d.cts +2 -2
  11. package/dist/formats/plain-date-time.d.mts +2 -2
  12. package/dist/formats/plain-date-time.mjs +1 -1
  13. package/dist/formats/plain-date.cjs +1 -1
  14. package/dist/formats/plain-date.d.cts +2 -2
  15. package/dist/formats/plain-date.d.mts +2 -2
  16. package/dist/formats/plain-date.mjs +1 -1
  17. package/dist/formats/plain-month-day.cjs +1 -1
  18. package/dist/formats/plain-month-day.d.cts +2 -2
  19. package/dist/formats/plain-month-day.d.mts +2 -2
  20. package/dist/formats/plain-month-day.mjs +1 -1
  21. package/dist/formats/plain-year-month.cjs +1 -1
  22. package/dist/formats/plain-year-month.d.cts +2 -2
  23. package/dist/formats/plain-year-month.d.mts +2 -2
  24. package/dist/formats/plain-year-month.mjs +1 -1
  25. package/dist/formats/zoned-date-time.cjs +1 -1
  26. package/dist/formats/zoned-date-time.d.cts +2 -2
  27. package/dist/formats/zoned-date-time.d.mts +2 -2
  28. package/dist/formats/zoned-date-time.mjs +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.cts +2 -2
  31. package/dist/index.d.mts +2 -2
  32. package/dist/index.mjs +1 -1
  33. package/dist/{weeks-navigation-Xve4O55H.mjs → weeks-navigation-Bg0nZLgh.mjs} +43 -41
  34. package/dist/{weeks-navigation-epiyL4IP.cjs → weeks-navigation-CJzhxbgj.cjs} +43 -41
  35. package/dist/{weeks-view-context-BZeWx9N8.d.cts → weeks-view-context-CNAq2Hiu.d.cts} +77 -15
  36. package/dist/{weeks-view-context-MVe1b-BS.d.mts → weeks-view-context-CsP3PBiu.d.mts} +77 -15
  37. package/package.json +92 -26
  38. package/src/formats/date.ts +4 -1
  39. package/src/formats/object.ts +4 -1
  40. package/src/formats/plain-date-time.ts +4 -1
  41. package/src/formats/plain-date.ts +4 -1
  42. package/src/formats/plain-month-day.ts +4 -1
  43. package/src/formats/plain-year-month.ts +4 -1
  44. package/src/formats/zoned-date-time.ts +4 -1
  45. package/src/grid.tsx +1 -1
  46. package/src/index.ts +4 -1
  47. package/src/month-view-types.ts +11 -6
  48. package/src/month-view.test.tsx +44 -2
  49. package/src/month-view.tsx +6 -6
  50. package/src/navigation.tsx +13 -1
  51. package/src/{overflow.test.ts → out-of-range.test.ts} +16 -12
  52. package/src/{overflow.ts → out-of-range.ts} +56 -10
  53. package/src/weeks-navigation.tsx +8 -7
  54. package/src/weeks-view-state.ts +33 -26
  55. package/src/weeks-view-types.ts +15 -4
  56. package/src/weeks-view.tsx +3 -3
@@ -1,14 +1,60 @@
1
1
  import type { Temporal } from "@js-temporal/polyfill";
2
2
  import type { TemporalNamespace, WeekStartDay } from "./types";
3
3
 
4
- export type OverflowBehavior =
4
+ /**
5
+ * Controls how a {@link WeeksView} window behaves when navigation would move it
6
+ * past the `min`/`max` bounds.
7
+ *
8
+ * `min`/`max` always restrict which **days are selectable**. `outOfRangeBehavior`
9
+ * is a separate concern: it decides whether the **visible window** may scroll
10
+ * beyond those bounds, and how the edge is handled.
11
+ *
12
+ * - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
13
+ * weeks can be viewed. Out-of-range days simply render disabled. (Default.)
14
+ * - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
15
+ * disabled once the next step would show a window containing no in-range day.
16
+ * - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
17
+ * fewer week rows instead of showing rows that are entirely out of range.
18
+ * - `"snap"` — A jump that would overshoot **snaps** the window so its edge
19
+ * aligns to the last/first in-range week, rather than stopping or overshooting.
20
+ * - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
21
+ * the in-range weeks.
22
+ *
23
+ * `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
24
+ * fewer weeks than `weekCount`** — i.e. the window is taller than the range.
25
+ * Snapping can only pin *one* edge to a bound; if the range is narrower than the
26
+ * window, the opposite edge still overhangs into out-of-range weeks. `"snap"`
27
+ * keeps the full `weekCount` (padding the overhang with all-disabled week rows),
28
+ * while `"snap-shrink"` trims those rows so only the in-range weeks show.
29
+ *
30
+ * Example with `weekCount: 6` and a `min`/`max` that span just 2 weeks: `"snap"`
31
+ * shows 6 rows (4 of them fully disabled), `"snap-shrink"` shows 2 rows. When
32
+ * the range is ≥ `weekCount` weeks wide, the snapped window already fits, so the
33
+ * two behave the same.
34
+ */
35
+ export type OutOfRangeBehavior =
5
36
  | "unbounded"
6
37
  | "stop"
7
38
  | "stop-shrink"
8
39
  | "snap"
9
40
  | "snap-shrink";
10
41
 
11
- export type MonthOverflowBehavior = "unbounded" | "stop";
42
+ /**
43
+ * Controls how {@link MonthView} navigation behaves when it would move the
44
+ * visible month(s) past the `min`/`max` bounds.
45
+ *
46
+ * `min`/`max` always restrict which **days are selectable**. This decides
47
+ * whether you can still **view** months outside them.
48
+ *
49
+ * - `"unbounded"` — Prev/Next are never disabled by `min`/`max`; you can page to
50
+ * any month. Out-of-range days render disabled. (Default.)
51
+ * - `"stop"` — Prev/Next become disabled once the destination month crosses the
52
+ * boundary.
53
+ *
54
+ * MonthView renders fixed month grids, so the `"…-shrink"`/`"snap…"` modes that
55
+ * {@link OutOfRangeBehavior} offers for WeeksView's flexible window don't apply.
56
+ */
57
+ export type MonthOutOfRangeBehavior = "unbounded" | "stop";
12
58
 
13
59
  // ---------------------------------------------------------------------------
14
60
  // Internal helpers
@@ -105,10 +151,10 @@ function shrinkWindow(
105
151
  // Public API
106
152
  // ---------------------------------------------------------------------------
107
153
 
108
- export interface ApplyOverflowInput {
154
+ export interface ApplyOutOfRangeInput {
109
155
  targetFirstWeek: Temporal.PlainDate;
110
156
  weekCount: number;
111
- behavior: OverflowBehavior;
157
+ behavior: OutOfRangeBehavior;
112
158
  min?: Temporal.PlainDate;
113
159
  max?: Temporal.PlainDate;
114
160
  weekStartDay: WeekStartDay;
@@ -116,10 +162,10 @@ export interface ApplyOverflowInput {
116
162
  }
117
163
 
118
164
  /**
119
- * Given a target firstWeek and weekCount, apply overflow behavior and return
165
+ * Given a target firstWeek and weekCount, apply the out-of-range behavior and return
120
166
  * the adjusted { firstWeek, weekCount }.
121
167
  */
122
- export function applyOverflow({
168
+ export function applyOutOfRange({
123
169
  targetFirstWeek,
124
170
  weekCount,
125
171
  behavior,
@@ -127,7 +173,7 @@ export function applyOverflow({
127
173
  max,
128
174
  weekStartDay,
129
175
  T,
130
- }: ApplyOverflowInput): { firstWeek: Temporal.PlainDate; weekCount: number } {
176
+ }: ApplyOutOfRangeInput): { firstWeek: Temporal.PlainDate; weekCount: number } {
131
177
  // Without bounds, all modes behave as unbounded
132
178
  if (!min || !max || behavior === "unbounded") {
133
179
  return { firstWeek: targetFirstWeek, weekCount };
@@ -185,7 +231,7 @@ export interface CanShiftInput {
185
231
  weekCount: number;
186
232
  direction: 1 | -1;
187
233
  shiftBy?: number;
188
- behavior: OverflowBehavior;
234
+ behavior: OutOfRangeBehavior;
189
235
  min?: Temporal.PlainDate;
190
236
  max?: Temporal.PlainDate;
191
237
  weekStartDay: WeekStartDay;
@@ -224,8 +270,8 @@ export function canShift({
224
270
 
225
271
  if (behavior === "snap" || behavior === "snap-shrink") {
226
272
  // Disabled when the current position is already the snapped position
227
- // (i.e. applying overflow to the target produces the same firstWeek)
228
- const applied = applyOverflow({
273
+ // (i.e. applying the out-of-range behavior to the target produces the same firstWeek)
274
+ const applied = applyOutOfRange({
229
275
  targetFirstWeek,
230
276
  weekCount,
231
277
  behavior,
@@ -3,7 +3,7 @@ import { useRender } from "@base-ui/react/use-render";
3
3
  import React, { forwardRef, useMemo } from "react";
4
4
  import { useCalendarStable } from "./calendar-context";
5
5
  import { useMonthViewState } from "./month-view-context";
6
- import { canShift } from "./overflow";
6
+ import { canShift } from "./out-of-range";
7
7
  import type { RootState, StateAttributesMapping } from "./types";
8
8
  import { useWeeksViewStable, useWeeksViewState } from "./weeks-view-context";
9
9
 
@@ -77,7 +77,8 @@ function useWeeksNavButton(
77
77
  temporal: T,
78
78
  weekStartDay,
79
79
  } = useCalendarStable();
80
- const { weekCount, overflowBehavior, goNext, goPrev } = useWeeksViewStable();
80
+ const { weekCount, outOfRangeBehavior, goNext, goPrev } =
81
+ useWeeksViewStable();
81
82
  const { windowInfo } = useWeeksViewState();
82
83
  const { rootState } = useMonthViewState();
83
84
 
@@ -90,7 +91,7 @@ function useWeeksNavButton(
90
91
  weekCount,
91
92
  direction: direction === "next" ? 1 : -1,
92
93
  ...(shiftByProp !== undefined && { shiftBy: shiftByProp }),
93
- behavior: overflowBehavior,
94
+ behavior: outOfRangeBehavior,
94
95
  ...(minValue !== undefined && { min: minValue }),
95
96
  ...(maxValue !== undefined && { max: maxValue }),
96
97
  weekStartDay,
@@ -102,7 +103,7 @@ function useWeeksNavButton(
102
103
  weekCount,
103
104
  direction,
104
105
  shiftByProp,
105
- overflowBehavior,
106
+ outOfRangeBehavior,
106
107
  minValue,
107
108
  maxValue,
108
109
  weekStartDay,
@@ -149,7 +150,7 @@ function PrevWeeksButtonFn(
149
150
 
150
151
  /**
151
152
  * Button that navigates to the previous week(s). Automatically disabled when
152
- * no more weeks are available based on `overflowBehavior` and `min`.
153
+ * no more weeks are available based on `outOfRangeBehavior` and `min`.
153
154
  * Exposes `data-direction="prev"`.
154
155
  */
155
156
  export const PrevWeeksButton = forwardRef(PrevWeeksButtonFn);
@@ -177,7 +178,7 @@ function NextWeeksButtonFn(
177
178
 
178
179
  /**
179
180
  * Button that navigates to the next week(s). Automatically disabled when
180
- * no more weeks are available based on `overflowBehavior` and `max`.
181
+ * no more weeks are available based on `outOfRangeBehavior` and `max`.
181
182
  * Exposes `data-direction="next"`.
182
183
  */
183
184
  export const NextWeeksButton = forwardRef(NextWeeksButtonFn);
@@ -216,6 +217,6 @@ function WeekCountFn(
216
217
 
217
218
  /**
218
219
  * Renders the current visible week count as a number. Useful with shrink
219
- * overflow modes where the actual count may be less than the `weekCount` prop.
220
+ * out-of-range modes where the actual count may be less than the `weekCount` prop.
220
221
  */
221
222
  export const WeekCount = forwardRef(WeekCountFn);
@@ -2,7 +2,7 @@ import type { Temporal } from "@js-temporal/polyfill";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { useCalendarStable, useCalendarState } from "./calendar-context";
4
4
  import { computeWeeksInWindow } from "./compute-weeks-in-window";
5
- import { applyOverflow, type OverflowBehavior } from "./overflow";
5
+ import { applyOutOfRange, type OutOfRangeBehavior } from "./out-of-range";
6
6
  import {
7
7
  resolveFirstWeekSpec,
8
8
  resolveFirstWeek,
@@ -29,13 +29,13 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
29
29
  defaultFirstWeek: defaultFirstWeekProp,
30
30
  onFirstWeekChange,
31
31
  scrollBy: scrollByProp,
32
- overflowBehavior: overflowBehaviorProp,
32
+ outOfRangeBehavior: outOfRangeBehaviorProp,
33
33
  onWindowChange,
34
34
  } = props;
35
35
 
36
36
  const scrollBy = scrollByProp ?? "row";
37
- const overflowBehavior: OverflowBehavior =
38
- overflowBehaviorProp ?? "unbounded";
37
+ const outOfRangeBehavior: OutOfRangeBehavior =
38
+ outOfRangeBehaviorProp ?? "unbounded";
39
39
 
40
40
  // Read calendar-level context
41
41
  const calStable = useCalendarStable();
@@ -81,13 +81,13 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
81
81
  [resolvedFirstWeek, weekCount, weekStartDay, T],
82
82
  );
83
83
 
84
- // --- Apply overflow ---
85
- const overflowResult = useMemo(
84
+ // --- Apply out-of-range behavior ---
85
+ const outOfRangeResult = useMemo(
86
86
  () =>
87
- applyOverflow({
87
+ applyOutOfRange({
88
88
  targetFirstWeek: resolvedFirstWeek,
89
89
  weekCount,
90
- behavior: overflowBehavior,
90
+ behavior: outOfRangeBehavior,
91
91
  ...(minValue !== undefined && { min: minValue }),
92
92
  ...(maxValue !== undefined && { max: maxValue }),
93
93
  weekStartDay,
@@ -96,7 +96,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
96
96
  [
97
97
  resolvedFirstWeek,
98
98
  weekCount,
99
- overflowBehavior,
99
+ outOfRangeBehavior,
100
100
  minValue,
101
101
  maxValue,
102
102
  weekStartDay,
@@ -104,19 +104,26 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
104
104
  ],
105
105
  );
106
106
 
107
- // Recompute weeks if overflow adjusted the window
107
+ // Recompute weeks if the out-of-range behavior adjusted the window
108
108
  const adjustedWeeks = useMemo(() => {
109
109
  const sameFirst =
110
- T.PlainDate.compare(overflowResult.firstWeek, resolvedFirstWeek) === 0;
111
- const sameCount = overflowResult.weekCount === weekCount;
110
+ T.PlainDate.compare(outOfRangeResult.firstWeek, resolvedFirstWeek) === 0;
111
+ const sameCount = outOfRangeResult.weekCount === weekCount;
112
112
  if (sameFirst && sameCount) return rawWeeks;
113
113
  return computeWeeksInWindow(
114
- overflowResult.firstWeek,
115
- overflowResult.weekCount,
114
+ outOfRangeResult.firstWeek,
115
+ outOfRangeResult.weekCount,
116
116
  weekStartDay,
117
117
  T,
118
118
  );
119
- }, [overflowResult, resolvedFirstWeek, weekCount, rawWeeks, weekStartDay, T]);
119
+ }, [
120
+ outOfRangeResult,
121
+ resolvedFirstWeek,
122
+ weekCount,
123
+ rawWeeks,
124
+ weekStartDay,
125
+ T,
126
+ ]);
120
127
 
121
128
  // --- Compute WindowInfo ---
122
129
  const isDateEnabled = useCallback(
@@ -310,10 +317,10 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
310
317
  (shiftBy?: number) => {
311
318
  const shift = shiftBy ?? weekCount;
312
319
  const target = resolvedFirstWeek.add({ weeks: shift });
313
- const adjusted = applyOverflow({
320
+ const adjusted = applyOutOfRange({
314
321
  targetFirstWeek: target,
315
322
  weekCount,
316
- behavior: overflowBehavior,
323
+ behavior: outOfRangeBehavior,
317
324
  ...(minValue !== undefined && { min: minValue }),
318
325
  ...(maxValue !== undefined && { max: maxValue }),
319
326
  weekStartDay,
@@ -324,7 +331,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
324
331
  [
325
332
  resolvedFirstWeek,
326
333
  weekCount,
327
- overflowBehavior,
334
+ outOfRangeBehavior,
328
335
  minValue,
329
336
  maxValue,
330
337
  weekStartDay,
@@ -337,10 +344,10 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
337
344
  (shiftBy?: number) => {
338
345
  const shift = shiftBy ?? weekCount;
339
346
  const target = resolvedFirstWeek.subtract({ weeks: shift });
340
- const adjusted = applyOverflow({
347
+ const adjusted = applyOutOfRange({
341
348
  targetFirstWeek: target,
342
349
  weekCount,
343
- behavior: overflowBehavior,
350
+ behavior: outOfRangeBehavior,
344
351
  ...(minValue !== undefined && { min: minValue }),
345
352
  ...(maxValue !== undefined && { max: maxValue }),
346
353
  weekStartDay,
@@ -351,7 +358,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
351
358
  [
352
359
  resolvedFirstWeek,
353
360
  weekCount,
354
- overflowBehavior,
361
+ outOfRangeBehavior,
355
362
  minValue,
356
363
  maxValue,
357
364
  weekStartDay,
@@ -373,10 +380,10 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
373
380
  resolvedTarget,
374
381
  options,
375
382
  );
376
- const adjusted = applyOverflow({
383
+ const adjusted = applyOutOfRange({
377
384
  targetFirstWeek: newFirstWeek,
378
385
  weekCount,
379
- behavior: overflowBehavior,
386
+ behavior: outOfRangeBehavior,
380
387
  ...(minValue !== undefined && { min: minValue }),
381
388
  ...(maxValue !== undefined && { max: maxValue }),
382
389
  weekStartDay,
@@ -388,7 +395,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
388
395
  resolvedFirstWeek,
389
396
  weekCount,
390
397
  resolveSpec,
391
- overflowBehavior,
398
+ outOfRangeBehavior,
392
399
  minValue,
393
400
  maxValue,
394
401
  weekStartDay,
@@ -420,7 +427,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
420
427
  () => ({
421
428
  weekCount,
422
429
  scrollBy,
423
- overflowBehavior,
430
+ outOfRangeBehavior,
424
431
  goNext,
425
432
  goPrev,
426
433
  scrollToWeek,
@@ -430,7 +437,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
430
437
  [
431
438
  weekCount,
432
439
  scrollBy,
433
- overflowBehavior,
440
+ outOfRangeBehavior,
434
441
  goNext,
435
442
  goPrev,
436
443
  scrollToWeek,
@@ -1,6 +1,6 @@
1
1
  import type { Temporal } from "@js-temporal/polyfill";
2
2
  import type { WeekDescriptor } from "./compute-weeks-in-window";
3
- import type { OverflowBehavior } from "./overflow";
3
+ import type { OutOfRangeBehavior } from "./out-of-range";
4
4
  import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
5
5
  import type { RootState } from "./types";
6
6
 
@@ -26,10 +26,21 @@ export interface WeeksViewRootProps {
26
26
  */
27
27
  scrollBy?: "row" | "page" | undefined;
28
28
  /**
29
- * How navigation behaves at `min`/`max` bounds.
29
+ * How the visible window behaves at the `min`/`max` bounds. `min`/`max`
30
+ * always restrict which **days are selectable**; this controls whether the
31
+ * window may scroll beyond them, and how the edge is handled. See
32
+ * {@link OutOfRangeBehavior}.
33
+ *
34
+ * - `"unbounded"` — navigation is never restricted by `min`/`max`.
35
+ * - `"stop"` — navigation halts once the next step has no in-range day.
36
+ * - `"stop-shrink"` — like `"stop"`, but the window shrinks at the edge.
37
+ * - `"snap"` — overshooting jumps snap the window edge to the last/first
38
+ * in-range week.
39
+ * - `"snap-shrink"` — snap to the boundary, shrinking if still out of range.
40
+ *
30
41
  * @default "unbounded"
31
42
  */
32
- overflowBehavior?: OverflowBehavior | undefined;
43
+ outOfRangeBehavior?: OutOfRangeBehavior | undefined;
33
44
  /** Called when the visible window changes. */
34
45
  onWindowChange?: ((info: WindowInfo) => void) | undefined;
35
46
  /** React children. */
@@ -75,7 +86,7 @@ export interface WeeksViewStableContextValue {
75
86
  /** How much to scroll per navigation step. */
76
87
  scrollBy: "row" | "page";
77
88
  /** How navigation behaves at bounds. */
78
- overflowBehavior: OverflowBehavior;
89
+ outOfRangeBehavior: OutOfRangeBehavior;
79
90
  /** Navigate to the next week(s). Optionally override the shift amount (in weeks). */
80
91
  goNext: (shiftBy?: number) => void;
81
92
  /** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
@@ -48,7 +48,7 @@ function WeeksViewRootFn(
48
48
  numberOfMonths: 1,
49
49
  fixedWeeks: false,
50
50
  outsideDays: "enabled" as const,
51
- overflowBehavior: "unbounded" as const,
51
+ outOfRangeBehavior: "unbounded" as const,
52
52
  goNextMonth: () => {},
53
53
  goPrevMonth: () => {},
54
54
  setGridLabelId: () => {},
@@ -106,7 +106,7 @@ function WeeksViewFn(
106
106
  defaultFirstWeek,
107
107
  onFirstWeekChange,
108
108
  scrollBy,
109
- overflowBehavior,
109
+ outOfRangeBehavior,
110
110
  onWindowChange,
111
111
  children,
112
112
  ...calendarProps
@@ -121,7 +121,7 @@ function WeeksViewFn(
121
121
  defaultFirstWeek={defaultFirstWeek}
122
122
  onFirstWeekChange={onFirstWeekChange}
123
123
  scrollBy={scrollBy}
124
- overflowBehavior={overflowBehavior}
124
+ outOfRangeBehavior={outOfRangeBehavior}
125
125
  onWindowChange={onWindowChange}
126
126
  >
127
127
  {children}