@klinking/colander 0.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 (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. package/src/weeks-view.tsx +127 -0
@@ -0,0 +1,127 @@
1
+ import type { Temporal } from "@js-temporal/polyfill";
2
+ import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
3
+ import { CalendarProvider } from "./calendar-provider";
4
+ import type { CalendarProviderProps } from "./calendar-types";
5
+ import { MonthViewStableContext, MonthViewStateContext } from "./month-view-context";
6
+ import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
7
+ import type { RootState, ValueFormat } from "./types";
8
+ import { ViewContext } from "./view-context";
9
+ import { WeeksViewStableContext, WeeksViewStateContext } from "./weeks-view-context";
10
+ import { useWeeksViewRootState } from "./weeks-view-state";
11
+ import type { WeeksViewRootProps } from "./weeks-view-types";
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // WeeksView.Root — placed inside CalendarProvider
15
+ // ---------------------------------------------------------------------------
16
+
17
+ /** Imperative handle exposed by WeeksView.Root via ref. */
18
+ export interface WeeksViewRootHandle {
19
+ scrollToWeek: (target: FirstWeekSpec, options?: { snap?: ScrollToWeekSnap }) => void;
20
+ }
21
+
22
+ function WeeksViewRootFn(props: WeeksViewRootProps, ref: React.ForwardedRef<WeeksViewRootHandle>) {
23
+ const { children } = props;
24
+ const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
25
+
26
+ useImperativeHandle(ref, () => ({ scrollToWeek }), [scrollToWeek]);
27
+
28
+ const gridFocusedRef = useRef(false);
29
+
30
+ // Provide MonthViewStableContext/MonthViewStateContext shims so shared
31
+ // components (WeeksNavButton, WeekCount, etc.) that read rootState via
32
+ // useMonthViewState() can function outside the Grid in WeeksView.
33
+ const monthViewStableShim = useMemo(
34
+ () => ({
35
+ numberOfMonths: 1,
36
+ fixedWeeks: false,
37
+ outsideDays: "enabled" as const,
38
+ overflowBehavior: "unbounded" as const,
39
+ goNextMonth: () => {},
40
+ goPrevMonth: () => {},
41
+ setGridLabelId: () => {},
42
+ gridFocusedRef,
43
+ }),
44
+ [],
45
+ );
46
+
47
+ const monthViewStateShim = useMemo(
48
+ () => ({
49
+ currentMonth: {
50
+ year: stateCtx.currentDateTime.year,
51
+ month: stateCtx.currentDateTime.month,
52
+ },
53
+ weeks: [] as Temporal.PlainDate[][],
54
+ allMonths: [],
55
+ currentDateTime: stateCtx.currentDateTime,
56
+ gridLabelIds: stateCtx.gridLabelIds,
57
+ rootState: {} as RootState,
58
+ }),
59
+ [stateCtx.currentDateTime, stateCtx.gridLabelIds],
60
+ );
61
+
62
+ return (
63
+ <MonthViewStableContext.Provider value={monthViewStableShim}>
64
+ <MonthViewStateContext.Provider value={monthViewStateShim}>
65
+ <WeeksViewStableContext.Provider value={stableCtx}>
66
+ <WeeksViewStateContext.Provider value={stateCtx}>
67
+ <ViewContext.Provider value={viewCtx}>{children}</ViewContext.Provider>
68
+ </WeeksViewStateContext.Provider>
69
+ </WeeksViewStableContext.Provider>
70
+ </MonthViewStateContext.Provider>
71
+ </MonthViewStableContext.Provider>
72
+ );
73
+ }
74
+
75
+ const WeeksViewRoot = forwardRef(WeeksViewRootFn);
76
+
77
+ // ---------------------------------------------------------------------------
78
+ // WeeksView convenience wrapper — composes CalendarProvider + WeeksView.Root
79
+ // ---------------------------------------------------------------------------
80
+
81
+ type WeeksViewProps<F extends ValueFormat = "PlainDate"> = CalendarProviderProps<F> &
82
+ WeeksViewRootProps;
83
+
84
+ function WeeksViewFn(props: WeeksViewProps, ref: React.ForwardedRef<WeeksViewRootHandle>) {
85
+ const {
86
+ weekCount,
87
+ firstWeek,
88
+ defaultFirstWeek,
89
+ onFirstWeekChange,
90
+ scrollBy,
91
+ overflowBehavior,
92
+ onWindowChange,
93
+ children,
94
+ ...calendarProps
95
+ } = props as WeeksViewProps & { children?: React.ReactNode };
96
+
97
+ return (
98
+ <CalendarProvider {...(calendarProps as CalendarProviderProps)}>
99
+ <WeeksViewRoot
100
+ ref={ref}
101
+ weekCount={weekCount}
102
+ firstWeek={firstWeek}
103
+ defaultFirstWeek={defaultFirstWeek}
104
+ onFirstWeekChange={onFirstWeekChange}
105
+ scrollBy={scrollBy}
106
+ overflowBehavior={overflowBehavior}
107
+ onWindowChange={onWindowChange}
108
+ >
109
+ {children}
110
+ </WeeksViewRoot>
111
+ </CalendarProvider>
112
+ );
113
+ }
114
+
115
+ const WeeksView = forwardRef(WeeksViewFn) as WeeksViewComponent;
116
+
117
+ // Attach Root as a static property
118
+ interface WeeksViewComponent extends React.ForwardRefExoticComponent<
119
+ WeeksViewProps & React.RefAttributes<WeeksViewRootHandle>
120
+ > {
121
+ Root: typeof WeeksViewRoot;
122
+ }
123
+
124
+ (WeeksView as WeeksViewComponent).Root = WeeksViewRoot;
125
+
126
+ export { WeeksView, WeeksViewRoot };
127
+ export type { WeeksViewProps };