@klinking/colander 3.1.0-alpha.5 → 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.
Files changed (52) hide show
  1. package/dist/formats/date.cjs +1 -1
  2. package/dist/formats/date.d.cts +1 -1
  3. package/dist/formats/date.d.mts +1 -1
  4. package/dist/formats/date.mjs +1 -1
  5. package/dist/formats/object.cjs +1 -1
  6. package/dist/formats/object.d.cts +1 -1
  7. package/dist/formats/object.d.mts +1 -1
  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 +1 -1
  11. package/dist/formats/plain-date-time.d.mts +1 -1
  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 +1 -1
  15. package/dist/formats/plain-date.d.mts +1 -1
  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 +1 -1
  19. package/dist/formats/plain-month-day.d.mts +1 -1
  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 +1 -1
  23. package/dist/formats/plain-year-month.d.mts +1 -1
  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 +1 -1
  27. package/dist/formats/zoned-date-time.d.mts +1 -1
  28. package/dist/formats/zoned-date-time.mjs +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.cts +1 -1
  31. package/dist/index.d.mts +1 -1
  32. package/dist/index.mjs +1 -1
  33. package/dist/{weeks-navigation-CEV8w_69.mjs → weeks-navigation-BSKwFvdP.mjs} +367 -413
  34. package/dist/{weeks-navigation-q3beZn2n.cjs → weeks-navigation-CPevz3Xg.cjs} +367 -413
  35. package/dist/{weeks-view-context-BLZZm1fq.d.mts → weeks-view-context-BTojXkys.d.cts} +51 -10
  36. package/dist/{weeks-view-context-CkTcdZpj.d.cts → weeks-view-context-CFXV8orh.d.mts} +51 -10
  37. package/package.json +1 -1
  38. package/src/calendar-provider.tsx +10 -55
  39. package/src/day-cell-state.test.ts +214 -0
  40. package/src/day-cell-state.ts +314 -0
  41. package/src/day-cell.tsx +29 -383
  42. package/src/grid.tsx +1 -1
  43. package/src/out-of-range.test.ts +33 -53
  44. package/src/out-of-range.ts +47 -123
  45. package/src/range-preview.test.ts +120 -0
  46. package/src/root-selection.ts +99 -97
  47. package/src/weeks-navigation.tsx +12 -28
  48. package/src/weeks-view-state.ts +36 -84
  49. package/src/weeks-view-types.ts +4 -1
  50. package/src/weeks-view.bounds.test.tsx +246 -0
  51. package/src/weeks-window.test.ts +131 -0
  52. package/src/weeks-window.ts +102 -0
@@ -1,7 +1,7 @@
1
- import * as _$react from "react";
2
- import React$1 from "react";
3
1
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
4
2
  import { useRender } from "@base-ui/react/use-render";
3
+ import * as _$react from "react";
4
+ import React$1 from "react";
5
5
 
6
6
  //#region ../node_modules/.pnpm/@js-temporal+polyfill@0.5.1/node_modules/@js-temporal/polyfill/index.d.ts
7
7
  declare namespace Temporal {
@@ -1558,7 +1558,8 @@ interface CalendarStateContextValue {
1558
1558
  * - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
1559
1559
  * weeks can be viewed. Out-of-range days simply render disabled. (Default.)
1560
1560
  * - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
1561
- * disabled once the next step would show a window containing no in-range day.
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.
1562
1563
  * - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
1563
1564
  * fewer week rows instead of showing rows that are entirely out of range.
1564
1565
  * - `"snap"` — A jump that would overshoot **snaps** the window so its edge
@@ -1566,6 +1567,8 @@ interface CalendarStateContextValue {
1566
1567
  * - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
1567
1568
  * the in-range weeks.
1568
1569
  *
1570
+ * A single bound (`min` only or `max` only) is honored; the missing side is unlimited.
1571
+ *
1569
1572
  * `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
1570
1573
  * fewer weeks than `weekCount`** — i.e. the window is taller than the range.
1571
1574
  * Snapping can only pin *one* edge to a bound; if the range is narrower than the
@@ -1732,6 +1735,12 @@ declare const GridHeaderCell: (props: GridHeaderCellProps & React.RefAttributes<
1732
1735
  /** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
1733
1736
  declare const GridHeader: (props: GridHeaderProps & React.RefAttributes<HTMLTableSectionElement>) => React.ReactElement | null;
1734
1737
  //#endregion
1738
+ //#region src/day-cell-state.d.ts
1739
+ /** A day cell's state: the public {@link DayCellTemplateState} plus the roving-tabindex flag. */
1740
+ type DayCellState = DayCellTemplateState & {
1741
+ isTabTarget: boolean;
1742
+ };
1743
+ //#endregion
1735
1744
  //#region src/day-cell.d.ts
1736
1745
  /**
1737
1746
  * Renders one `<td role="gridcell">` per day. Exposes data-attributes for
@@ -1743,9 +1752,7 @@ declare const GridHeader: (props: GridHeaderProps & React.RefAttributes<HTMLTabl
1743
1752
  */
1744
1753
  declare function DayCellTemplate(props: DayCellTemplateProps): _$react_jsx_runtime0.JSX.Element;
1745
1754
  declare const DayButton: (props: DayButtonProps & {
1746
- _derivedState?: DayCellTemplateState & {
1747
- isTabTarget: boolean;
1748
- };
1755
+ _derivedState?: DayCellState;
1749
1756
  } & React.RefAttributes<HTMLButtonElement>) => React.ReactElement | null;
1750
1757
  //#endregion
1751
1758
  //#region src/grid.d.ts
@@ -1884,6 +1891,32 @@ interface WeekDescriptor {
1884
1891
  */
1885
1892
  declare function computeWeeksInWindow(firstWeek: Temporal.PlainDate, weekCount: number, weekStartDay: WeekStartDay, _T: TemporalNamespace): WeekDescriptor[];
1886
1893
  //#endregion
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
+ }
1900
+ /**
1901
+ * The rules for where a WeeksView window may sit. Built once from the bounds and
1902
+ * shared by every way of moving the window (buttons, keyboard, `scrollToWeek`).
1903
+ */
1904
+ interface WeekWindowPolicy {
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;
1918
+ }
1919
+ //#endregion
1887
1920
  //#region src/weeks-view-types.d.ts
1888
1921
  /** Props accepted by `WeeksView.Root`. */
1889
1922
  interface WeeksViewRootProps {
@@ -1934,7 +1967,7 @@ interface WindowInfo {
1934
1967
  windowStart: Temporal.PlainDate;
1935
1968
  /** The last date of the visible window. */
1936
1969
  windowEnd: Temporal.PlainDate;
1937
- /** Number of week rows in the window (the prop value, not actual when shrunk). */
1970
+ /** Number of week rows actually shown (fewer than the `weekCount` prop when shrunk). */
1938
1971
  weekCount: number;
1939
1972
  /** Total number of calendar days in the window. */
1940
1973
  dayCount: number;
@@ -1953,6 +1986,8 @@ interface WeeksViewStableContextValue {
1953
1986
  scrollBy: "row" | "page";
1954
1987
  /** How navigation behaves at bounds. */
1955
1988
  outOfRangeBehavior: OutOfRangeBehavior;
1989
+ /** Where the window may sit given `min`/`max` and `outOfRangeBehavior`. */
1990
+ windowPolicy: WeekWindowPolicy;
1956
1991
  /** Navigate to the next week(s). Optionally override the shift amount (in weeks). */
1957
1992
  goNext: (shiftBy?: number) => void;
1958
1993
  /** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
@@ -2087,10 +2122,16 @@ declare const MonthSeparator: React$1.ForwardRefExoticComponent<Omit<MonthSepara
2087
2122
  //#region src/root-selection.d.ts
2088
2123
  /**
2089
2124
  * Pure utility that computes the preview range for a hovered date, using the
2090
- * same logic as the internal hook. Useful for deriving the preview in an
2091
- * `onHoveredDateChange` handler without needing a controlled `previewRange`.
2125
+ * same logic as the built-in hover preview. Useful for deriving the preview in
2126
+ * an `onHoveredDateChange` handler without needing a controlled `previewRange`.
2127
+ *
2128
+ * Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
2129
+ * disables dates or is read-only; by default every date is selectable.
2092
2130
  */
2093
- declare function computePreviewRange(hoveredDate: Temporal.PlainDate, currentRange: DateRange | null, rangeMode: RangeMode, preventRangeReversal?: boolean, T?: TemporalNamespace): DateRange<"PlainDate"> | null;
2131
+ declare function computePreviewRange(hoveredDate: Temporal.PlainDate, currentRange: DateRange | null, rangeMode: RangeMode, preventRangeReversal?: boolean, T?: TemporalNamespace, options?: {
2132
+ isDateDisabled?: (date: Temporal.PlainDate) => boolean;
2133
+ readOnly?: boolean;
2134
+ }): DateRange<"PlainDate"> | null;
2094
2135
  //#endregion
2095
2136
  //#region src/calendar-context.d.ts
2096
2137
  /** Returns the stable (callbacks/config) part of CalendarProvider context. */
@@ -1,7 +1,7 @@
1
- import * as _$react_jsx_runtime0 from "react/jsx-runtime";
2
- import { useRender } from "@base-ui/react/use-render";
3
1
  import * as _$react from "react";
4
2
  import React$1 from "react";
3
+ import * as _$react_jsx_runtime0 from "react/jsx-runtime";
4
+ import { useRender } from "@base-ui/react/use-render";
5
5
 
6
6
  //#region ../node_modules/.pnpm/@js-temporal+polyfill@0.5.1/node_modules/@js-temporal/polyfill/index.d.ts
7
7
  declare namespace Temporal {
@@ -1558,7 +1558,8 @@ interface CalendarStateContextValue {
1558
1558
  * - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
1559
1559
  * weeks can be viewed. Out-of-range days simply render disabled. (Default.)
1560
1560
  * - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
1561
- * disabled once the next step would show a window containing no in-range day.
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.
1562
1563
  * - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
1563
1564
  * fewer week rows instead of showing rows that are entirely out of range.
1564
1565
  * - `"snap"` — A jump that would overshoot **snaps** the window so its edge
@@ -1566,6 +1567,8 @@ interface CalendarStateContextValue {
1566
1567
  * - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
1567
1568
  * the in-range weeks.
1568
1569
  *
1570
+ * A single bound (`min` only or `max` only) is honored; the missing side is unlimited.
1571
+ *
1569
1572
  * `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
1570
1573
  * fewer weeks than `weekCount`** — i.e. the window is taller than the range.
1571
1574
  * Snapping can only pin *one* edge to a bound; if the range is narrower than the
@@ -1732,6 +1735,12 @@ declare const GridHeaderCell: (props: GridHeaderCellProps & React.RefAttributes<
1732
1735
  /** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
1733
1736
  declare const GridHeader: (props: GridHeaderProps & React.RefAttributes<HTMLTableSectionElement>) => React.ReactElement | null;
1734
1737
  //#endregion
1738
+ //#region src/day-cell-state.d.ts
1739
+ /** A day cell's state: the public {@link DayCellTemplateState} plus the roving-tabindex flag. */
1740
+ type DayCellState = DayCellTemplateState & {
1741
+ isTabTarget: boolean;
1742
+ };
1743
+ //#endregion
1735
1744
  //#region src/day-cell.d.ts
1736
1745
  /**
1737
1746
  * Renders one `<td role="gridcell">` per day. Exposes data-attributes for
@@ -1743,9 +1752,7 @@ declare const GridHeader: (props: GridHeaderProps & React.RefAttributes<HTMLTabl
1743
1752
  */
1744
1753
  declare function DayCellTemplate(props: DayCellTemplateProps): _$react_jsx_runtime0.JSX.Element;
1745
1754
  declare const DayButton: (props: DayButtonProps & {
1746
- _derivedState?: DayCellTemplateState & {
1747
- isTabTarget: boolean;
1748
- };
1755
+ _derivedState?: DayCellState;
1749
1756
  } & React.RefAttributes<HTMLButtonElement>) => React.ReactElement | null;
1750
1757
  //#endregion
1751
1758
  //#region src/grid.d.ts
@@ -1884,6 +1891,32 @@ interface WeekDescriptor {
1884
1891
  */
1885
1892
  declare function computeWeeksInWindow(firstWeek: Temporal.PlainDate, weekCount: number, weekStartDay: WeekStartDay, _T: TemporalNamespace): WeekDescriptor[];
1886
1893
  //#endregion
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
+ }
1900
+ /**
1901
+ * The rules for where a WeeksView window may sit. Built once from the bounds and
1902
+ * shared by every way of moving the window (buttons, keyboard, `scrollToWeek`).
1903
+ */
1904
+ interface WeekWindowPolicy {
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;
1918
+ }
1919
+ //#endregion
1887
1920
  //#region src/weeks-view-types.d.ts
1888
1921
  /** Props accepted by `WeeksView.Root`. */
1889
1922
  interface WeeksViewRootProps {
@@ -1934,7 +1967,7 @@ interface WindowInfo {
1934
1967
  windowStart: Temporal.PlainDate;
1935
1968
  /** The last date of the visible window. */
1936
1969
  windowEnd: Temporal.PlainDate;
1937
- /** Number of week rows in the window (the prop value, not actual when shrunk). */
1970
+ /** Number of week rows actually shown (fewer than the `weekCount` prop when shrunk). */
1938
1971
  weekCount: number;
1939
1972
  /** Total number of calendar days in the window. */
1940
1973
  dayCount: number;
@@ -1953,6 +1986,8 @@ interface WeeksViewStableContextValue {
1953
1986
  scrollBy: "row" | "page";
1954
1987
  /** How navigation behaves at bounds. */
1955
1988
  outOfRangeBehavior: OutOfRangeBehavior;
1989
+ /** Where the window may sit given `min`/`max` and `outOfRangeBehavior`. */
1990
+ windowPolicy: WeekWindowPolicy;
1956
1991
  /** Navigate to the next week(s). Optionally override the shift amount (in weeks). */
1957
1992
  goNext: (shiftBy?: number) => void;
1958
1993
  /** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
@@ -2087,10 +2122,16 @@ declare const MonthSeparator: React$1.ForwardRefExoticComponent<Omit<MonthSepara
2087
2122
  //#region src/root-selection.d.ts
2088
2123
  /**
2089
2124
  * Pure utility that computes the preview range for a hovered date, using the
2090
- * same logic as the internal hook. Useful for deriving the preview in an
2091
- * `onHoveredDateChange` handler without needing a controlled `previewRange`.
2125
+ * same logic as the built-in hover preview. Useful for deriving the preview in
2126
+ * an `onHoveredDateChange` handler without needing a controlled `previewRange`.
2127
+ *
2128
+ * Pass `options.isDateDisabled` and `options.readOnly` to match a calendar that
2129
+ * disables dates or is read-only; by default every date is selectable.
2092
2130
  */
2093
- declare function computePreviewRange(hoveredDate: Temporal.PlainDate, currentRange: DateRange | null, rangeMode: RangeMode, preventRangeReversal?: boolean, T?: TemporalNamespace): DateRange<"PlainDate"> | null;
2131
+ declare function computePreviewRange(hoveredDate: Temporal.PlainDate, currentRange: DateRange | null, rangeMode: RangeMode, preventRangeReversal?: boolean, T?: TemporalNamespace, options?: {
2132
+ isDateDisabled?: (date: Temporal.PlainDate) => boolean;
2133
+ readOnly?: boolean;
2134
+ }): DateRange<"PlainDate"> | null;
2094
2135
  //#endregion
2095
2136
  //#region src/calendar-context.d.ts
2096
2137
  /** Returns the stable (callbacks/config) part of CalendarProvider context. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klinking/colander",
3
- "version": "3.1.0-alpha.5",
3
+ "version": "3.1.0-alpha.7",
4
4
  "homepage": "https://github.com/klink-ing/colander#readme",
5
5
  "bugs": "https://github.com/klink-ing/colander/issues",
6
6
  "license": "MIT",
@@ -12,8 +12,10 @@ import type {
12
12
  import {
13
13
  isDateRange,
14
14
  tagRaw,
15
+ computeRangePreview,
15
16
  computeSelectionUpdate,
16
17
  computeSetRangeUpdate,
18
+ decodeRange,
17
19
  truncateDatesForMode,
18
20
  type SelectionResult,
19
21
  } from "./root-selection";
@@ -180,14 +182,7 @@ function CalendarProvider<F extends ValueFormat = "PlainDate">(
180
182
  }
181
183
  if (isRange) {
182
184
  if (rangeValue === null) return [];
183
- if (rangeValue) {
184
- const start =
185
- rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
186
- const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
187
- if (start === null && end === null) return [];
188
- if (start === null && end !== null) return [end, null];
189
- return [start, end];
190
- }
185
+ if (rangeValue) return decodeRange(rangeValue, rawToPlain);
191
186
  return undefined;
192
187
  }
193
188
  if (singleValue === null) return [];
@@ -237,15 +232,7 @@ function CalendarProvider<F extends ValueFormat = "PlainDate">(
237
232
  if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
238
233
  return [];
239
234
  }
240
- if (rangeDefault) {
241
- const start =
242
- rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
243
- const end =
244
- rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
245
- if (start === null && end === null) return [];
246
- if (start === null && end !== null) return [end, null];
247
- return [start, end];
248
- }
235
+ if (rangeDefault) return decodeRange(rangeDefault, rawToPlain);
249
236
  if (singleDefault != null) return [rawToPlain(singleDefault)];
250
237
  return [];
251
238
  }, [
@@ -366,52 +353,27 @@ function CalendarProvider<F extends ValueFormat = "PlainDate">(
366
353
  >(() => {
367
354
  if (previewRangeProp !== undefined) {
368
355
  if (!previewRangeProp) return [undefined, undefined];
369
- const rawToPlainLocal = (
370
- raw: RawValueForFormat<F>,
371
- ): Temporal.PlainDate => {
372
- const tagged = {
373
- format: resolvedFormat,
374
- value: raw,
375
- } as DateValueObject;
376
- return toZonedDateTime(tagged, timeZone, T).toPlainDate();
377
- };
378
356
  const s =
379
357
  previewRangeProp.start != null
380
- ? rawToPlainLocal(previewRangeProp.start)
358
+ ? rawToPlain(previewRangeProp.start)
381
359
  : undefined;
382
360
  const e =
383
361
  previewRangeProp.end != null
384
- ? rawToPlainLocal(previewRangeProp.end)
362
+ ? rawToPlain(previewRangeProp.end)
385
363
  : undefined;
386
364
  return [s, e];
387
365
  }
388
366
  if (!hoveredDate || !isRange) return [undefined, undefined];
389
- const result = computeSelectionUpdate<F>({
390
- date: hoveredDate,
367
+ const preview = computeRangePreview({
368
+ hoveredDate,
391
369
  readOnly,
392
370
  isDateDisabled,
393
- isMultiple: false,
394
- isRange: true,
395
371
  committedDates,
396
- committedStart,
397
- committedEnd,
398
- selectedZdt: undefined,
399
372
  rangeMode,
400
373
  allowRangeReversal,
401
- sortDates,
402
- currentSingleFormatted,
403
- currentRangeFormatted,
404
- currentMultipleFormatted,
405
- resolvedFormat,
406
- timeZone,
407
374
  T,
408
375
  });
409
- if (result.skip || result.newDates.length === 0)
410
- return [undefined, undefined];
411
- const ps = result.newDates[0];
412
- const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
413
- if (ps == null || pe == null) return [undefined, undefined];
414
- return [ps, pe];
376
+ return preview ?? [undefined, undefined];
415
377
  }, [
416
378
  previewRangeProp,
417
379
  hoveredDate,
@@ -419,16 +381,9 @@ function CalendarProvider<F extends ValueFormat = "PlainDate">(
419
381
  readOnly,
420
382
  isDateDisabled,
421
383
  committedDates,
422
- committedStart,
423
- committedEnd,
424
384
  rangeMode,
425
385
  allowRangeReversal,
426
- sortDates,
427
- currentSingleFormatted,
428
- currentRangeFormatted,
429
- currentMultipleFormatted,
430
- resolvedFormat,
431
- timeZone,
386
+ rawToPlain,
432
387
  T,
433
388
  ]);
434
389
 
@@ -0,0 +1,214 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { describe, expect, it } from "vitest";
3
+ import { computeDayCellState, dayCellStateEqual } from "./day-cell-state";
4
+ import type { DayCellInputs } from "./day-cell-state";
5
+ import type { OutsideDays } from "./types";
6
+
7
+ const T = Temporal;
8
+ const d = (iso: string) => T.PlainDate.from(iso);
9
+
10
+ const inputs = (overrides: Partial<DayCellInputs> = {}): DayCellInputs => ({
11
+ T,
12
+ today: d("2026-03-10"),
13
+ orientation: "horizontal",
14
+ rootState: {} as DayCellInputs["rootState"],
15
+ selectionMode: "single",
16
+ selectedDates: [],
17
+ rangeStart: undefined,
18
+ rangeEnd: undefined,
19
+ previewStart: undefined,
20
+ previewEnd: undefined,
21
+ disabled: false,
22
+ isDateDisabled: undefined,
23
+ focusedDate: d("2026-03-15"),
24
+ tabTargetDate: d("2026-03-15"),
25
+ outsideDays: "enabled",
26
+ ...overrides,
27
+ });
28
+
29
+ const march = { columnIndex: 0, month: { year: 2026, month: 3 } };
30
+
31
+ describe("computeDayCellState", () => {
32
+ it.each([
33
+ {
34
+ description:
35
+ "today, selected, focused and tab target in the viewed month",
36
+ date: "2026-03-10",
37
+ overrides: {
38
+ selectedDates: [d("2026-03-10")],
39
+ focusedDate: d("2026-03-10"),
40
+ tabTargetDate: d("2026-03-10"),
41
+ },
42
+ expected: {
43
+ today: true,
44
+ selected: true,
45
+ focused: true,
46
+ isTabTarget: true,
47
+ outsideMonth: false,
48
+ disabled: false,
49
+ },
50
+ },
51
+ {
52
+ description: "isDateDisabled disables the cell",
53
+ date: "2026-03-12",
54
+ overrides: { isDateDisabled: (x: Temporal.PlainDate) => x.day === 12 },
55
+ expected: { disabled: true, selected: false },
56
+ },
57
+ {
58
+ description: "range mode never reports selected, only range state",
59
+ date: "2026-03-12",
60
+ overrides: {
61
+ selectionMode: "range" as const,
62
+ selectedDates: [d("2026-03-12")],
63
+ rangeStart: d("2026-03-11"),
64
+ rangeEnd: d("2026-03-13"),
65
+ },
66
+ expected: {
67
+ selected: false,
68
+ inRange: true,
69
+ rangeBoundary: false,
70
+ rangeIndex: 1,
71
+ rangeLength: 3,
72
+ rangeHasStart: true,
73
+ rangeHasEnd: true,
74
+ },
75
+ },
76
+ {
77
+ description: "half-open range: only the start is set",
78
+ date: "2026-03-11",
79
+ overrides: {
80
+ selectionMode: "range" as const,
81
+ rangeStart: d("2026-03-11"),
82
+ },
83
+ expected: {
84
+ rangeStart: true,
85
+ rangeEnd: false,
86
+ inRange: true,
87
+ rangeIndex: 0,
88
+ rangeLength: 1,
89
+ rangeHasStart: true,
90
+ rangeHasEnd: false,
91
+ },
92
+ },
93
+ {
94
+ description: "preview range marks its boundary",
95
+ date: "2026-03-14",
96
+ overrides: {
97
+ selectionMode: "range" as const,
98
+ previewStart: d("2026-03-12"),
99
+ previewEnd: d("2026-03-14"),
100
+ },
101
+ expected: {
102
+ rangePreviewEnd: true,
103
+ rangePreviewBoundary: true,
104
+ rangePreviewInRange: true,
105
+ rangePreviewIndex: 2,
106
+ rangePreviewLength: 3,
107
+ },
108
+ },
109
+ ])("$description", ({ date, overrides, expected }) => {
110
+ const state = computeDayCellState(d(date), march, inputs(overrides));
111
+ expect(state).toMatchObject(expected);
112
+ });
113
+
114
+ it.each([
115
+ {
116
+ description: "enabled: outside day is a normal cell",
117
+ outsideDays: "enabled" as OutsideDays,
118
+ expected: {
119
+ outsideMonth: true,
120
+ hidden: false,
121
+ disabled: false,
122
+ inRange: true,
123
+ },
124
+ },
125
+ {
126
+ description: "readOnly: outside day is disabled but keeps range state",
127
+ outsideDays: "readOnly" as OutsideDays,
128
+ expected: {
129
+ outsideMonth: true,
130
+ hidden: false,
131
+ disabled: true,
132
+ inRange: true,
133
+ },
134
+ },
135
+ {
136
+ description: "disabled: outside day is disabled and drops range state",
137
+ outsideDays: "disabled" as OutsideDays,
138
+ expected: {
139
+ outsideMonth: true,
140
+ hidden: false,
141
+ disabled: true,
142
+ inRange: false,
143
+ },
144
+ },
145
+ {
146
+ description: "hidden: outside day is hidden, not today, no range state",
147
+ outsideDays: "hidden" as OutsideDays,
148
+ expected: {
149
+ outsideMonth: true,
150
+ hidden: true,
151
+ disabled: true,
152
+ today: false,
153
+ inRange: false,
154
+ },
155
+ },
156
+ ])("outside day, $description", ({ outsideDays, expected }) => {
157
+ const state = computeDayCellState(
158
+ d("2026-04-02"),
159
+ march,
160
+ inputs({
161
+ outsideDays,
162
+ selectionMode: "range",
163
+ rangeStart: d("2026-04-01"),
164
+ rangeEnd: d("2026-04-03"),
165
+ selectedDates: [d("2026-04-02")],
166
+ focusedDate: d("2026-04-02"),
167
+ tabTargetDate: d("2026-04-02"),
168
+ }),
169
+ );
170
+ expect(state).toMatchObject({
171
+ ...expected,
172
+ selected: false,
173
+ focused: outsideDays === "enabled",
174
+ isTabTarget: outsideDays === "enabled",
175
+ });
176
+ });
177
+ });
178
+
179
+ describe("dayCellStateEqual", () => {
180
+ const state = () => computeDayCellState(d("2026-03-12"), march, inputs());
181
+
182
+ it.each([
183
+ { description: "identical states", change: {}, expected: true },
184
+ {
185
+ description: "root/orientation differ",
186
+ change: { orientation: "vertical" as const },
187
+ expected: true,
188
+ },
189
+ {
190
+ description: "selected differs",
191
+ change: { selected: true },
192
+ expected: false,
193
+ },
194
+ {
195
+ description: "tab target differs",
196
+ change: { isTabTarget: true },
197
+ expected: false,
198
+ },
199
+ {
200
+ description: "range index differs",
201
+ change: { rangeIndex: 2 },
202
+ expected: false,
203
+ },
204
+ {
205
+ description: "preview length differs",
206
+ change: { rangePreviewLength: 4 },
207
+ expected: false,
208
+ },
209
+ ])("$description", ({ change, expected }) => {
210
+ expect(dayCellStateEqual(state(), { ...state(), ...change })).toBe(
211
+ expected,
212
+ );
213
+ });
214
+ });