@knitui/dates 0.5.0 → 0.6.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.
- package/lib/commonjs/DatesProvider/DatesProvider.js +33 -4
- package/lib/commonjs/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/commonjs/Day/Day.js +45 -7
- package/lib/commonjs/Day/Day.js.map +1 -1
- package/lib/commonjs/Month/Month.js +266 -80
- package/lib/commonjs/Month/Month.js.map +1 -1
- package/lib/commonjs/MonthLevel/MonthLevel.js +19 -3
- package/lib/commonjs/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/commonjs/MonthsList/MonthsList.js +160 -60
- package/lib/commonjs/MonthsList/MonthsList.js.map +1 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js +15 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/commonjs/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/commonjs/YearsList/YearsList.js +155 -60
- package/lib/commonjs/YearsList/YearsList.js.map +1 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/commonjs/internal/are-cell-props-equal.js +64 -0
- package/lib/commonjs/internal/are-cell-props-equal.js.map +1 -0
- package/lib/commonjs/internal/date-string-fast-path.js +98 -0
- package/lib/commonjs/internal/date-string-fast-path.js.map +1 -0
- package/lib/commonjs/internal/memoize-control-props.js +54 -0
- package/lib/commonjs/internal/memoize-control-props.js.map +1 -0
- package/lib/commonjs/internal/month-days-cache.js +71 -0
- package/lib/commonjs/internal/month-days-cache.js.map +1 -0
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js +17 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/module/DatesProvider/DatesProvider.js +34 -5
- package/lib/module/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/module/Day/Day.js +46 -8
- package/lib/module/Day/Day.js.map +1 -1
- package/lib/module/Month/Month.js +267 -82
- package/lib/module/Month/Month.js.map +1 -1
- package/lib/module/MonthLevel/MonthLevel.js +19 -3
- package/lib/module/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/module/MonthsList/MonthsList.js +159 -60
- package/lib/module/MonthsList/MonthsList.js.map +1 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControl.js +15 -1
- package/lib/module/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/module/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/module/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/module/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/module/YearsList/YearsList.js +154 -60
- package/lib/module/YearsList/YearsList.js.map +1 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/module/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/module/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/module/internal/are-cell-props-equal.js +60 -0
- package/lib/module/internal/are-cell-props-equal.js.map +1 -0
- package/lib/module/internal/date-string-fast-path.js +91 -0
- package/lib/module/internal/date-string-fast-path.js.map +1 -0
- package/lib/module/internal/memoize-control-props.js +50 -0
- package/lib/module/internal/memoize-control-props.js.map +1 -0
- package/lib/module/internal/month-days-cache.js +68 -0
- package/lib/module/internal/month-days-cache.js.map +1 -0
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/module/utils/is-same-month/is-same-month.js +17 -1
- package/lib/module/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/typescript/DatesProvider/DatesProvider.d.ts.map +1 -1
- package/lib/typescript/Day/Day.d.ts +7 -7
- package/lib/typescript/Day/Day.d.ts.map +1 -1
- package/lib/typescript/Month/Month.d.ts +3 -2
- package/lib/typescript/Month/Month.d.ts.map +1 -1
- package/lib/typescript/MonthLevel/MonthLevel.d.ts.map +1 -1
- package/lib/typescript/MonthsList/MonthsList.d.ts +3 -2
- package/lib/typescript/MonthsList/MonthsList.d.ts.map +1 -1
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts +6 -0
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControl.d.ts +13 -0
- package/lib/typescript/TimeControlsList/TimeControl.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControlsList.d.ts.map +1 -1
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts.map +1 -1
- package/lib/typescript/YearsList/YearsList.d.ts +3 -2
- package/lib/typescript/YearsList/YearsList.d.ts.map +1 -1
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts +6 -0
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts +12 -0
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts.map +1 -1
- package/lib/typescript/hooks/use-dates-state/use-dates-state.d.ts.map +1 -1
- package/lib/typescript/internal/are-cell-props-equal.d.ts +21 -0
- package/lib/typescript/internal/are-cell-props-equal.d.ts.map +1 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts +35 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts.map +1 -0
- package/lib/typescript/internal/memoize-control-props.d.ts +12 -0
- package/lib/typescript/internal/memoize-control-props.d.ts.map +1 -0
- package/lib/typescript/internal/month-days-cache.d.ts +19 -0
- package/lib/typescript/internal/month-days-cache.d.ts.map +1 -0
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts +9 -1
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts +6 -0
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts +6 -0
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts +13 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/DatesProvider/DatesProvider.tsx +27 -5
- package/src/Day/Day.tsx +51 -10
- package/src/Month/Month.tsx +357 -80
- package/src/MonthLevel/MonthLevel.tsx +35 -16
- package/src/MonthsList/MonthsList.tsx +201 -55
- package/src/MonthsList/get-month-in-tab-order/get-month-in-tab-order.ts +12 -1
- package/src/TimeControlsList/TimeControl.tsx +16 -1
- package/src/TimeControlsList/TimeControlsList.tsx +15 -3
- package/src/WeekdaysRow/WeekdaysRow.tsx +29 -5
- package/src/YearsList/YearsList.tsx +196 -55
- package/src/YearsList/get-year-in-tab-order/get-year-in-tab-order.ts +12 -1
- package/src/hooks/use-dates-state/is-in-range/is-in-range.ts +22 -0
- package/src/hooks/use-dates-state/use-dates-state.ts +27 -11
- package/src/internal/are-cell-props-equal.ts +63 -0
- package/src/internal/date-string-fast-path.ts +94 -0
- package/src/internal/memoize-control-props.ts +54 -0
- package/src/internal/month-days-cache.ts +77 -0
- package/src/utils/get-date-in-tab-order/get-date-in-tab-order.ts +17 -2
- package/src/utils/is-after-min-date/is-after-min-date.ts +16 -1
- package/src/utils/is-before-max-date/is-before-max-date.ts +16 -1
- package/src/utils/is-same-month/is-same-month.ts +18 -1
|
@@ -56,11 +56,40 @@ function DatesProvider({
|
|
|
56
56
|
settings,
|
|
57
57
|
children
|
|
58
58
|
}) {
|
|
59
|
+
// The context value MUST keep a stable identity across renders. A context change
|
|
60
|
+
// propagates past every `React.memo` boundary below it, so an inline
|
|
61
|
+
// `value={{ ...defaults, ...settings }}` — a fresh object each render — defeats
|
|
62
|
+
// the memoized day cell (`Month`'s `MonthDayCell`) for all 42 cells of every
|
|
63
|
+
// month grid, which is exactly the boundary that keeps a web hover from
|
|
64
|
+
// re-rendering the whole calendar.
|
|
65
|
+
//
|
|
66
|
+
// `settings` itself is documented (and used throughout the stories/tests) as an
|
|
67
|
+
// INLINE literal, so memoizing on its identity would never hit. We therefore
|
|
68
|
+
// depend on the individual fields: the four primitives by value, and
|
|
69
|
+
// `weekendDays` by its joined value rather than its identity so an inlined
|
|
70
|
+
// `weekendDays={[0, 6]}` does not invalidate on every render either.
|
|
71
|
+
const {
|
|
72
|
+
locale,
|
|
73
|
+
firstDayOfWeek,
|
|
74
|
+
weekendDays,
|
|
75
|
+
labelSeparator,
|
|
76
|
+
consistentWeeks
|
|
77
|
+
} = settings;
|
|
78
|
+
const weekendDaysKey = weekendDays?.join(",");
|
|
79
|
+
const value = (0, _react.useMemo)(
|
|
80
|
+
// The merge is kept verbatim (rather than rebuilt from the destructured
|
|
81
|
+
// locals) so the exact spread semantics are preserved — including a key that
|
|
82
|
+
// is present with an explicit `undefined`, which overrides its default.
|
|
83
|
+
() => ({
|
|
84
|
+
...DATES_PROVIDER_DEFAULT_SETTINGS,
|
|
85
|
+
...settings
|
|
86
|
+
}),
|
|
87
|
+
// `settings` is read inside but deliberately NOT a dependency — that is the
|
|
88
|
+
// whole point (see above); `weekendDays` is depended on via `weekendDaysKey`.
|
|
89
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
|
+
[locale, firstDayOfWeek, weekendDaysKey, labelSeparator, consistentWeeks]);
|
|
59
91
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DatesProviderContext.Provider, {
|
|
60
|
-
value:
|
|
61
|
-
...DATES_PROVIDER_DEFAULT_SETTINGS,
|
|
62
|
-
...settings
|
|
63
|
-
},
|
|
92
|
+
value: value,
|
|
64
93
|
children: children
|
|
65
94
|
});
|
|
66
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_jsxRuntime","DATES_PROVIDER_DEFAULT_SETTINGS","exports","locale","firstDayOfWeek","weekendDays","labelSeparator","consistentWeeks","DatesProviderContext","createContext","DatesProvider","settings","children","
|
|
1
|
+
{"version":3,"names":["_react","require","_jsxRuntime","DATES_PROVIDER_DEFAULT_SETTINGS","exports","locale","firstDayOfWeek","weekendDays","labelSeparator","consistentWeeks","DatesProviderContext","createContext","DatesProvider","settings","children","weekendDaysKey","join","value","useMemo","jsx","Provider","displayName"],"sourceRoot":"../../../src","sources":["DatesProvider/DatesProvider.tsx"],"mappings":";;;;;;;;AAoBA,IAAAA,MAAA,GAAAC,OAAA;AAA+D,IAAAC,WAAA,GAAAD,OAAA;AApB/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;;AAcA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,+BAAmD,GAAAC,OAAA,CAAAD,+BAAA,GAAG;EACjEE,MAAM,EAAE,IAAI;EACZC,cAAc,EAAE,CAAC;EACjBC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;EACnBC,cAAc,EAAE,GAAG;EACnBC,eAAe,EAAE;AACnB,CAAC;AAEM,MAAMC,oBAAoB,GAAAN,OAAA,CAAAM,oBAAA,gBAAG,IAAAC,oBAAa,EAC/CR,+BACF,CAAC;AASD;AACA;AACA;AACA;AACA;AACO,SAASS,aAAaA,CAAC;EAAEC,QAAQ;EAAEC;AAA6B,CAAC,EAAE;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM;IAAET,MAAM;IAAEC,cAAc;IAAEC,WAAW;IAAEC,cAAc;IAAEC;EAAgB,CAAC,GAAGI,QAAQ;EACzF,MAAME,cAAc,GAAGR,WAAW,EAAES,IAAI,CAAC,GAAG,CAAC;EAE7C,MAAMC,KAAK,GAAG,IAAAC,cAAO;EACnB;EACA;EACA;EACA,OAAO;IAAE,GAAGf,+BAA+B;IAAE,GAAGU;EAAS,CAAC,CAAC;EAC3D;EACA;EACA;EACA,CAACR,MAAM,EAAEC,cAAc,EAAES,cAAc,EAAEP,cAAc,EAAEC,eAAe,CAC1E,CAAC;EAED,oBAAO,IAAAP,WAAA,CAAAiB,GAAA,EAACT,oBAAoB,CAACU,QAAQ;IAACH,KAAK,EAAEA,KAAM;IAAAH,QAAA,EAAEA;EAAQ,CAAgC,CAAC;AAChG;AAEAF,aAAa,CAACS,WAAW,GAAG,6BAA6B","ignoreList":[]}
|
package/lib/commonjs/Day/Day.js
CHANGED
|
@@ -95,6 +95,22 @@ const DayContext = (0, _core.createStyledContext)({
|
|
|
95
95
|
size: "md"
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Whether `day` falls on today's LOCAL calendar date, compared without
|
|
100
|
+
* allocating a single extra dayjs instance.
|
|
101
|
+
*
|
|
102
|
+
* `day.isSame(new Date(), "day")` — the obvious spelling — costs a `Date`, a
|
|
103
|
+
* dayjs instance wrapping it, and two more clones for dayjs' internal
|
|
104
|
+
* `startOf`/`endOf` bracket, i.e. ~4 allocations PER CELL (×42 cells, every
|
|
105
|
+
* render). Reading the three calendar fields off the instance we already have
|
|
106
|
+
* is exact (`year`/`month`/`date` are plain field reads, no clone) and costs
|
|
107
|
+
* only the one `Date` for "now".
|
|
108
|
+
*/
|
|
109
|
+
function isSameDayAsToday(day) {
|
|
110
|
+
const now = new Date();
|
|
111
|
+
return day.date() === now.getDate() && day.month() === now.getMonth() && day.year() === now.getFullYear();
|
|
112
|
+
}
|
|
113
|
+
|
|
98
114
|
/**
|
|
99
115
|
* The atomic calendar cell — an `UnstyledButton`-based control composed via
|
|
100
116
|
* `styled`. Accent comes from the active theme's palette ramp via the `theme`
|
|
@@ -283,14 +299,36 @@ const DayComponent = DayFrame.styleable(function Day(props, ref) {
|
|
|
283
299
|
locale,
|
|
284
300
|
...rest
|
|
285
301
|
} = props;
|
|
286
|
-
|
|
302
|
+
|
|
303
|
+
// The RAW context, not `useDatesContext()`. The hook's four `useCallback` getter
|
|
304
|
+
// helpers are convenience for components that resolve several settings; `Day`
|
|
305
|
+
// needs exactly one value — the locale for its fallback label — and it is the
|
|
306
|
+
// grid's hottest leaf (42 instances per month × `numberOfColumns`, all
|
|
307
|
+
// re-rendering on a hover frame). Going through the hook there cost 42 extra
|
|
308
|
+
// hook subscriptions and ~168 freshly allocated closures per grid render for a
|
|
309
|
+
// single string read. `locale || ctx.locale` below is the getter's body verbatim
|
|
310
|
+
// (`getLocale = (input) => input || ctx.locale`), so a standalone `<Day>`
|
|
311
|
+
// resolves its locale exactly as before.
|
|
312
|
+
const ctx = React.useContext(_DatesProvider.DatesProviderContext);
|
|
287
313
|
const day = (0, _dayjs.default)(date);
|
|
288
|
-
|
|
314
|
+
|
|
315
|
+
// Only the `highlightToday` border consults "is this today", so the comparison
|
|
316
|
+
// is skipped entirely when the border is off (the default).
|
|
317
|
+
const isToday = highlightToday && isSameDayAsToday(day);
|
|
289
318
|
|
|
290
319
|
// Locale-aware default label, read from `DatesProvider`. A static (display-only)
|
|
291
|
-
// day announces nothing — it is not an interactive date.
|
|
292
|
-
//
|
|
293
|
-
|
|
320
|
+
// day announces nothing — it is not an interactive date.
|
|
321
|
+
//
|
|
322
|
+
// An explicit `aria-label` WINS, so it is read up-front and the fallback is
|
|
323
|
+
// only built when there is none: `Month` always passes its own `aria-label`
|
|
324
|
+
// through `...rest` (spread last), which means computing the fallback there
|
|
325
|
+
// was pure waste — a locale clone plus `format("D MMMM YYYY")`, the most
|
|
326
|
+
// expensive token set in the file, for a string that was always discarded,
|
|
327
|
+
// ×42 cells every render. Reading the explicit label here also means NATIVE
|
|
328
|
+
// (`accessibilityLabel` below) now announces the same custom label web does,
|
|
329
|
+
// instead of the generic date it used to fall back to.
|
|
330
|
+
const explicitAriaLabel = props["aria-label"];
|
|
331
|
+
const ariaLabel = isStatic ? undefined : explicitAriaLabel ?? day.locale(locale || ctx.locale).format("D MMMM YYYY");
|
|
294
332
|
|
|
295
333
|
// Mirror Mantine's data-attribute gating: a disabled day shows none of the
|
|
296
334
|
// selection/range/weekend/outside styling, and today's border is suppressed
|
|
@@ -326,7 +364,7 @@ const DayComponent = DayFrame.styleable(function Day(props, ref) {
|
|
|
326
364
|
fullWidth: fullWidth,
|
|
327
365
|
disabled: disabled,
|
|
328
366
|
role: isStatic ? "presentation" : "button",
|
|
329
|
-
"aria-label":
|
|
367
|
+
"aria-label": ariaLabel,
|
|
330
368
|
"aria-selected": isSelected || undefined,
|
|
331
369
|
"aria-disabled": disabled || undefined,
|
|
332
370
|
"aria-hidden": hidden || undefined
|
|
@@ -335,7 +373,7 @@ const DayComponent = DayFrame.styleable(function Day(props, ref) {
|
|
|
335
373
|
,
|
|
336
374
|
...(0, _a11y.controlA11yProps)({
|
|
337
375
|
role: isStatic ? "none" : "button",
|
|
338
|
-
label:
|
|
376
|
+
label: ariaLabel,
|
|
339
377
|
selected: isSelected,
|
|
340
378
|
disabled
|
|
341
379
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_dayjs","_interopRequireDefault","_components","_core","_cellMetrics","_DatesProvider","_a11y","_webCursor","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","daySizeVariant","xxs","width","CELL_WIDTH","height","minHeight","xs","sm","md","lg","xl","xxl","dayFontVariant","fontSize","CELL_FONT","DayContext","createStyledContext","size","DayFrame","styled","UnstyledButton","Frame","name","context","alignItems","justifyContent","borderWidth","borderColor","borderRadius","backgroundColor","webCursor","hoverStyle","pressStyle","variants","fullWidth","true","outside","opacity","weekend","inRange","firstInRange","borderTopLeftRadius","borderBottomLeftRadius","lastInRange","borderTopRightRadius","borderBottomRightRadius","today","selected","hidden","display","disabled","pointerEvents","static","userSelect","defaultVariants","DayLabel","Text","color","DayComponent","styleable","Day","props","ref","
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_dayjs","_interopRequireDefault","_components","_core","_cellMetrics","_DatesProvider","_a11y","_webCursor","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","daySizeVariant","xxs","width","CELL_WIDTH","height","minHeight","xs","sm","md","lg","xl","xxl","dayFontVariant","fontSize","CELL_FONT","DayContext","createStyledContext","size","isSameDayAsToday","day","now","Date","date","getDate","month","getMonth","year","getFullYear","DayFrame","styled","UnstyledButton","Frame","name","context","alignItems","justifyContent","borderWidth","borderColor","borderRadius","backgroundColor","webCursor","hoverStyle","pressStyle","variants","fullWidth","true","outside","opacity","weekend","inRange","firstInRange","borderTopLeftRadius","borderBottomLeftRadius","lastInRange","borderTopRightRadius","borderBottomRightRadius","today","selected","hidden","display","disabled","pointerEvents","static","userSelect","defaultVariants","DayLabel","Text","color","DayComponent","styleable","Day","props","ref","isStatic","renderDay","highlightToday","locale","rest","ctx","useContext","DatesProviderContext","dayjs","isToday","explicitAriaLabel","ariaLabel","undefined","format","isWeekend","isOutside","isSelected","isInRange","isFirstInRange","isLastInRange","showToday","content","isTextContent","elementProps","type","jsx","role","controlA11yProps","label","render","children","displayName","exports","withStaticProperties","Label"],"sourceRoot":"../../../src","sources":["Day/Day.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAAmD,IAAAS,WAAA,GAAAT,OAAA;AAAA,SAAAE,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAA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,EAAEH,QAAQ;EACf+E,KAAK,EAAE1C;AACT,CAAC,CAAC","ignoreList":[]}
|
|
@@ -4,18 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Month = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var React = _react;
|
|
7
9
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
8
10
|
var _components = require("@knitui/components");
|
|
9
11
|
var _core = require("@knitui/core");
|
|
12
|
+
var _hooks = require("@knitui/hooks");
|
|
10
13
|
var _cellMetrics = require("../cell-metrics");
|
|
11
14
|
var _DatesProvider = require("../DatesProvider");
|
|
12
15
|
var _Day = require("../Day");
|
|
16
|
+
var _areCellPropsEqual = require("../internal/are-cell-props-equal");
|
|
13
17
|
var _focusElement = require("../internal/focus-element");
|
|
14
18
|
var _hasPreventDefault = require("../internal/has-prevent-default");
|
|
19
|
+
var _memoizeControlProps = require("../internal/memoize-control-props");
|
|
20
|
+
var _monthDaysCache = require("../internal/month-days-cache");
|
|
15
21
|
var _utils = require("../utils");
|
|
16
22
|
var _WeekdaysRow = require("../WeekdaysRow");
|
|
17
23
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
26
|
// ───────────────────────────────────────────────────────────────────────────
|
|
20
27
|
// Month — the calendar month day grid.
|
|
21
28
|
//
|
|
@@ -35,6 +42,137 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
35
42
|
// `fullWidth` is a boolean VARIANT on the cell/frame, not a per-render spread.
|
|
36
43
|
// ───────────────────────────────────────────────────────────────────────────
|
|
37
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The facts about one day cell that depend ONLY on the grid shape + provider
|
|
47
|
+
* settings — no consumer callback, no selection. Derived once per grid shape and
|
|
48
|
+
* cached for as long as that shape holds; this is where all the per-cell dayjs
|
|
49
|
+
* work lives, so it is the layer that must never be invalidated by a consumer
|
|
50
|
+
* handing us a fresh closure. See the two `useMemo`s in `Month` below.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** One week row's base cells plus its (optional) ISO week number. */
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The SELECTION-INDEPENDENT facts about one day cell — {@link MonthBaseCellInfo}
|
|
57
|
+
* with the two consumer callbacks (`excludeDate`/`getDayAriaLabel`) applied over
|
|
58
|
+
* it. Derived once per grid shape + callback identity rather than once per
|
|
59
|
+
* render — see the two `useMemo`s in `Month` below.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/** One week row's cells plus its (optional) ISO week number. */
|
|
63
|
+
|
|
64
|
+
/** Props for the memoized day cell — see {@link MonthDayCell}. */
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* One day cell, memoized.
|
|
68
|
+
*
|
|
69
|
+
* The grid re-renders for reasons that concern only one or two cells — most
|
|
70
|
+
* sharply a web hover move, which updates `hoveredDate` and re-renders the whole
|
|
71
|
+
* `DatePicker` subtree per cell crossed. Without a memo boundary that meant 42
|
|
72
|
+
* `Day` leaves re-rendering (and 42 refs detaching/reattaching, re-running
|
|
73
|
+
* `__getDayRef` and rebuilding the `daysRefs` matrix) for a change that moved two
|
|
74
|
+
* cells' background colour.
|
|
75
|
+
*
|
|
76
|
+
* The boundary is deliberately here — an internal cell, the same pattern the kit
|
|
77
|
+
* uses for `Combobox`'s `OptionRow` and `TagsInput`'s chips — and NOT on the public
|
|
78
|
+
* `Day`, whose props contract stays exactly as it was. Tamagui's styled-context
|
|
79
|
+
* and theme reads happen inside `Day` and still propagate past a memo, so cells
|
|
80
|
+
* keep responding to theme/size changes.
|
|
81
|
+
*/
|
|
82
|
+
const MonthDayCell = /*#__PURE__*/React.memo(function MonthDayCell({
|
|
83
|
+
date,
|
|
84
|
+
outside,
|
|
85
|
+
hidden,
|
|
86
|
+
weekend,
|
|
87
|
+
disabled,
|
|
88
|
+
ariaLabel,
|
|
89
|
+
rowIndex,
|
|
90
|
+
cellIndex,
|
|
91
|
+
tabIndex,
|
|
92
|
+
size,
|
|
93
|
+
isStatic,
|
|
94
|
+
fullWidth,
|
|
95
|
+
highlightToday,
|
|
96
|
+
renderDay,
|
|
97
|
+
stopPropagation,
|
|
98
|
+
preventFocus,
|
|
99
|
+
cellProps,
|
|
100
|
+
dayProps,
|
|
101
|
+
mergedDayProps,
|
|
102
|
+
onDayMouseEnter,
|
|
103
|
+
onDayClick,
|
|
104
|
+
onDayKeyDown,
|
|
105
|
+
getDayRef
|
|
106
|
+
}) {
|
|
107
|
+
// Tamagui hover handlers are not part `Day`'s public prop type; attach them via
|
|
108
|
+
// a precisely-typed object spread, the kit's pattern for web-only affordances
|
|
109
|
+
// (see `@knitui/components` `hoverProps`). Native ignores it.
|
|
110
|
+
const hoverHandlers = {
|
|
111
|
+
onHoverIn: event => onDayMouseEnter(event, date)
|
|
112
|
+
};
|
|
113
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MonthCell, {
|
|
114
|
+
role: "cell",
|
|
115
|
+
fullWidth: fullWidth,
|
|
116
|
+
...cellProps,
|
|
117
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Day.Day, {
|
|
118
|
+
highlightToday: highlightToday,
|
|
119
|
+
renderDay: renderDay,
|
|
120
|
+
date: date,
|
|
121
|
+
size: size,
|
|
122
|
+
weekend: weekend,
|
|
123
|
+
outside: outside,
|
|
124
|
+
hidden: hidden,
|
|
125
|
+
"aria-label": ariaLabel,
|
|
126
|
+
static: isStatic,
|
|
127
|
+
fullWidth: fullWidth,
|
|
128
|
+
disabled: disabled,
|
|
129
|
+
ref: node => {
|
|
130
|
+
if (node) {
|
|
131
|
+
getDayRef(rowIndex, cellIndex, {
|
|
132
|
+
focus: () => (0, _focusElement.focusElement)(node),
|
|
133
|
+
disabled,
|
|
134
|
+
isHidden: hidden,
|
|
135
|
+
isOutside: outside
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// explicit beats sugar: the `day` slot sits UNDER per-item
|
|
140
|
+
// `getDayProps`, and the consumer's own handlers are preserved
|
|
141
|
+
// (called before ours).
|
|
142
|
+
,
|
|
143
|
+
...mergedDayProps,
|
|
144
|
+
...hoverHandlers,
|
|
145
|
+
onKeyDown: event => {
|
|
146
|
+
dayProps?.onKeyDown?.(event);
|
|
147
|
+
onDayKeyDown(event, {
|
|
148
|
+
rowIndex,
|
|
149
|
+
cellIndex,
|
|
150
|
+
date
|
|
151
|
+
});
|
|
152
|
+
// When nested inside an input-trigger dropdown (`__stopPropagation`,
|
|
153
|
+
// driven by `DateTimePicker`), keep the calendar's Escape from
|
|
154
|
+
// bubbling out and closing an outer picker — the cross-platform
|
|
155
|
+
// replacement for Mantine's `data-mantine-stop-propagation`. No-op
|
|
156
|
+
// on native (no DOM `stopPropagation`).
|
|
157
|
+
if (stopPropagation && (0, _hasPreventDefault.isEscapeKey)(event) && (0, _hasPreventDefault.hasStopPropagation)(event)) {
|
|
158
|
+
event.stopPropagation();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
onPress: event => {
|
|
162
|
+
dayProps?.onPress?.(event);
|
|
163
|
+
onDayClick(event, date);
|
|
164
|
+
},
|
|
165
|
+
onPressIn: event => {
|
|
166
|
+
dayProps?.onPressIn?.(event);
|
|
167
|
+
if (preventFocus && (0, _hasPreventDefault.hasPreventDefault)(event)) {
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
tabIndex: tabIndex
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}, _areCellPropsEqual.areCellPropsEqual);
|
|
175
|
+
|
|
38
176
|
/** Month grid size — the kit's shared control size scale (mirrors `Day`). */
|
|
39
177
|
|
|
40
178
|
// ── 2. Shared context ───────────────────────────────────────────────────────
|
|
@@ -264,103 +402,151 @@ const MonthComponent = MonthFrame.styleable(function Month(props, ref) {
|
|
|
264
402
|
const minDateString = minDate == null ? undefined : (0, _utils.toDateString)(minDate);
|
|
265
403
|
const maxDateString = maxDate == null ? undefined : (0, _utils.toDateString)(maxDate);
|
|
266
404
|
const weekendDaysList = ctx.getWeekendDays(weekendDays);
|
|
405
|
+
const resolvedLocale = locale || ctx.locale;
|
|
406
|
+
// The weekend set is depended on by VALUE below, not by identity: a consumer
|
|
407
|
+
// inlining `weekendDays={[0, 6]}` hands us a fresh array every render, which
|
|
408
|
+
// would defeat the grid memo while never changing the answer.
|
|
409
|
+
const weekendDaysKey = weekendDaysList.join(",");
|
|
267
410
|
|
|
268
411
|
// 7. Typed per-slot accessor (dev-warns unknown keys against the known set).
|
|
269
412
|
const s = (0, _core.slotStyles)(styles, MONTH_SLOT_KEYS, "Month");
|
|
270
|
-
|
|
413
|
+
|
|
414
|
+
// Memoized on the three primitives the grid shape depends on, so navigating
|
|
415
|
+
// back to an already-visited month replays the cached weeks instead of walking
|
|
416
|
+
// the calendar day by day again (~70 dayjs instances + 35 `format` calls). Also
|
|
417
|
+
// gives `dates` a STABLE identity per month, which is what lets it be used as a
|
|
418
|
+
// `useMemo` dependency below.
|
|
419
|
+
const dates = (0, _monthDaysCache.getCachedMonthDays)({
|
|
271
420
|
month,
|
|
272
421
|
firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),
|
|
273
422
|
consistentWeeks: ctx.consistentWeeks
|
|
274
423
|
});
|
|
424
|
+
|
|
425
|
+
// ── The per-cell derivation, hoisted out of the render loop ────────────────
|
|
426
|
+
// Everything here is SELECTION-INDEPENDENT: which days are outside the month,
|
|
427
|
+
// hidden, weekend, out of bounds, and what each announces. None of it can change
|
|
428
|
+
// when the selection or the hovered day changes — yet it was all re-derived for
|
|
429
|
+
// 42 cells on every render, including the renders caused by nothing but a hover
|
|
430
|
+
// moving one cell over. `dayjs(date)` + `format("D MMMM YYYY")` per cell was the
|
|
431
|
+
// bulk of it.
|
|
432
|
+
//
|
|
433
|
+
// The selection-DEPENDENT parts (`getDayProps`, the roving `tabIndex`) are
|
|
434
|
+
// deliberately left in the loop below: they read live state, so memoizing them
|
|
435
|
+
// would need a selection signature that is easy to get subtly wrong. Splitting
|
|
436
|
+
// at the selection boundary gets the same win with none of that risk.
|
|
437
|
+
//
|
|
438
|
+
// The derivation is split across TWO memos, at the consumer-callback boundary.
|
|
439
|
+
// `excludeDate`/`getDayAriaLabel` arrive straight from consumer props, and an app
|
|
440
|
+
// that writes `excludeDate={(d) => …}` inline hands us a new function on every
|
|
441
|
+
// render — which invalidated the single combined memo on every hover frame, so
|
|
442
|
+
// the 42 dayjs instances + 42 `format("D MMMM YYYY")` calls were paid anyway.
|
|
443
|
+
// Stabilising those identities (`useCallbackRef`) is NOT an option: a predicate
|
|
444
|
+
// legitimately closes over live state, and a memo that cannot see it change would
|
|
445
|
+
// silently show stale disabled days. So instead the EXPENSIVE half — everything
|
|
446
|
+
// that touches dayjs — is memoized WITHOUT them, and only the cheap half (calling
|
|
447
|
+
// the consumer's two functions and assembling the result) recomputes when their
|
|
448
|
+
// identity moves. Both memos still bail out entirely in the common case, so the
|
|
449
|
+
// stable-callback path is unchanged.
|
|
450
|
+
const baseRows = (0, _react.useMemo)(() => dates.map(week => ({
|
|
451
|
+
weekNumber: withWeekNumbers ? (0, _utils.getWeekNumber)(week) : undefined,
|
|
452
|
+
cells: week.map(date => {
|
|
453
|
+
const outside = !(0, _utils.isSameMonth)(date, month);
|
|
454
|
+
// ONE dayjs per cell, shared by the weekend test and the fallback label.
|
|
455
|
+
// `weekendDaysList.some((wd) => wd === dayjs(date).day())` built an
|
|
456
|
+
// instance PER WEEKEND DAY TESTED — 2 with the default `[0, 6]`, i.e. 84
|
|
457
|
+
// per grid — and the label built a third. `.day()` is a plain field read
|
|
458
|
+
// and `.locale()` returns a clone, so sharing the instance is safe.
|
|
459
|
+
const day = (0, _dayjs.default)(date);
|
|
460
|
+
const dayOfWeek = day.day();
|
|
461
|
+
return {
|
|
462
|
+
date,
|
|
463
|
+
outside,
|
|
464
|
+
hidden: hideOutsideDates ? outside : false,
|
|
465
|
+
weekend: weekendDaysList.some(wd => wd === dayOfWeek),
|
|
466
|
+
// Computed up front rather than lazily behind `getDayAriaLabel`'s `||`:
|
|
467
|
+
// being independent of the consumer's getter is exactly what makes this
|
|
468
|
+
// layer cacheable, and the resolved label is identical either way.
|
|
469
|
+
defaultAriaLabel: isStatic ? undefined : day.locale(resolvedLocale).format("D MMMM YYYY")
|
|
470
|
+
};
|
|
471
|
+
})
|
|
472
|
+
})),
|
|
473
|
+
// `weekendDaysList` is depended on via `weekendDaysKey` (its value) rather than
|
|
474
|
+
// its identity — see the note where that key is built.
|
|
475
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
476
|
+
[dates, month, hideOutsideDates, weekendDaysKey, isStatic, resolvedLocale, withWeekNumbers]);
|
|
477
|
+
const rowsInfo = (0, _react.useMemo)(() => baseRows.map(row => ({
|
|
478
|
+
weekNumber: row.weekNumber,
|
|
479
|
+
cells: row.cells.map(cell => ({
|
|
480
|
+
date: cell.date,
|
|
481
|
+
outside: cell.outside,
|
|
482
|
+
hidden: cell.hidden,
|
|
483
|
+
weekend: cell.weekend,
|
|
484
|
+
disabled: excludeDate?.(cell.date) || !(0, _utils.isBeforeMaxDate)(cell.date, maxDateString) || !(0, _utils.isAfterMinDate)(cell.date, minDateString),
|
|
485
|
+
ariaLabel: getDayAriaLabel?.(cell.date) || cell.defaultAriaLabel
|
|
486
|
+
}))
|
|
487
|
+
})), [baseRows, excludeDate, minDateString, maxDateString, getDayAriaLabel]);
|
|
488
|
+
|
|
489
|
+
// ONE per-render cache shared by `getDateInTabOrder` (which consults the getter
|
|
490
|
+
// twice per date) and the cell loop below (a third time) — so each date's props
|
|
491
|
+
// are derived exactly once instead of three times. `getDayProps` is typically
|
|
492
|
+
// `useDatesState`'s `getControlProps`, ~20 dayjs instances per call for a range
|
|
493
|
+
// picker, which made those redundant calls the single largest cost in the grid.
|
|
494
|
+
// Deliberately NOT memoized across renders: the getter closes over live
|
|
495
|
+
// selection/hover state (see `memoizeByDate`).
|
|
496
|
+
const resolveDayProps = (0, _memoizeControlProps.memoizeByDate)(getDayProps);
|
|
275
497
|
const dateInTabOrder = (0, _utils.getDateInTabOrder)({
|
|
276
498
|
dates,
|
|
277
499
|
minDate: minDateString,
|
|
278
500
|
maxDate: maxDateString,
|
|
279
|
-
getDayProps,
|
|
501
|
+
getDayProps: resolveDayProps,
|
|
280
502
|
excludeDate,
|
|
281
503
|
hideOutsideDates,
|
|
282
504
|
month
|
|
283
505
|
});
|
|
284
506
|
const cellGap = withCellSpacing ? _cellMetrics.CELL_SPACING : 0;
|
|
285
|
-
const rows = dates.map((week, rowIndex) => {
|
|
286
|
-
const cells = week.map((date, cellIndex) => {
|
|
287
|
-
const day = (0, _dayjs.default)(date);
|
|
288
|
-
const outside = !(0, _utils.isSameMonth)(date, month);
|
|
289
|
-
const hidden = hideOutsideDates ? outside : false;
|
|
290
|
-
const weekend = weekendDaysList.some(wd => wd === day.day());
|
|
291
|
-
const disabled = excludeDate?.(date) || !(0, _utils.isBeforeMaxDate)(date, maxDateString) || !(0, _utils.isAfterMinDate)(date, minDateString);
|
|
292
|
-
const ariaLabel = getDayAriaLabel?.(date) || (isStatic ? undefined : day.locale(locale || ctx.locale).format("D MMMM YYYY"));
|
|
293
|
-
const dayProps = getDayProps?.(date);
|
|
294
|
-
const isDateInTabOrder = day.isSame(dateInTabOrder, "date");
|
|
295
|
-
const tabIndex = __preventFocus || !isDateInTabOrder ? -1 : 0;
|
|
296
507
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
508
|
+
// The cell memo can only bail out if every function prop it receives keeps a
|
|
509
|
+
// stable identity. All four of these arrive freshly built each render (the level
|
|
510
|
+
// group builds them per month, `DatePicker` per render), so they are wrapped
|
|
511
|
+
// once here rather than being stabilised at each of their many call sites.
|
|
512
|
+
const onDayMouseEnter = (0, _hooks.useCallbackRef)(__onDayMouseEnter);
|
|
513
|
+
const onDayClick = (0, _hooks.useCallbackRef)(__onDayClick);
|
|
514
|
+
const onDayKeyDown = (0, _hooks.useCallbackRef)(__onDayKeyDown);
|
|
515
|
+
const getDayRef = (0, _hooks.useCallbackRef)(__getDayRef);
|
|
516
|
+
const cellSlotProps = s.get("cell");
|
|
517
|
+
const rows = rowsInfo.map((row, rowIndex) => {
|
|
518
|
+
const cells = row.cells.map((info, cellIndex) => {
|
|
519
|
+
const dayProps = resolveDayProps?.(info.date);
|
|
520
|
+
// `dateInTabOrder` comes from the same `getMonthDays` output as `date`, so
|
|
521
|
+
// both are canonical `YYYY-MM-DD` — string equality is exactly the
|
|
522
|
+
// day-granularity `isSame` this used to spend a dayjs instance (plus its
|
|
523
|
+
// `startOf`/`endOf` clones) on, per cell, per render.
|
|
524
|
+
const isDateInTabOrder = dateInTabOrder !== undefined && info.date === dateInTabOrder;
|
|
525
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MonthDayCell, {
|
|
526
|
+
date: info.date,
|
|
527
|
+
outside: info.outside,
|
|
528
|
+
hidden: info.hidden,
|
|
529
|
+
weekend: info.weekend,
|
|
530
|
+
disabled: info.disabled,
|
|
531
|
+
ariaLabel: info.ariaLabel,
|
|
532
|
+
rowIndex: rowIndex,
|
|
533
|
+
cellIndex: cellIndex,
|
|
534
|
+
tabIndex: __preventFocus || !isDateInTabOrder ? -1 : 0,
|
|
535
|
+
size: size,
|
|
536
|
+
isStatic: isStatic,
|
|
305
537
|
fullWidth: fullWidth,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
disabled: disabled,
|
|
319
|
-
ref: node => {
|
|
320
|
-
if (node) {
|
|
321
|
-
__getDayRef?.(rowIndex, cellIndex, {
|
|
322
|
-
focus: () => (0, _focusElement.focusElement)(node),
|
|
323
|
-
disabled,
|
|
324
|
-
isHidden: hidden,
|
|
325
|
-
isOutside: outside
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
// explicit beats sugar: the `day` slot sits UNDER per-item
|
|
330
|
-
// `getDayProps`, and the consumer's own handlers are preserved
|
|
331
|
-
// (called before ours).
|
|
332
|
-
,
|
|
333
|
-
...s.merge("day", dayProps),
|
|
334
|
-
...hoverHandlers,
|
|
335
|
-
onKeyDown: event => {
|
|
336
|
-
dayProps?.onKeyDown?.(event);
|
|
337
|
-
__onDayKeyDown?.(event, {
|
|
338
|
-
rowIndex,
|
|
339
|
-
cellIndex,
|
|
340
|
-
date
|
|
341
|
-
});
|
|
342
|
-
// When nested inside an input-trigger dropdown (`__stopPropagation`,
|
|
343
|
-
// driven by `DateTimePicker`), keep the calendar's Escape from
|
|
344
|
-
// bubbling out and closing an outer picker — the cross-platform
|
|
345
|
-
// replacement for Mantine's `data-mantine-stop-propagation`. No-op
|
|
346
|
-
// on native (no DOM `stopPropagation`).
|
|
347
|
-
if (__stopPropagation && (0, _hasPreventDefault.isEscapeKey)(event) && (0, _hasPreventDefault.hasStopPropagation)(event)) {
|
|
348
|
-
event.stopPropagation();
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
onPress: event => {
|
|
352
|
-
dayProps?.onPress?.(event);
|
|
353
|
-
__onDayClick?.(event, date);
|
|
354
|
-
},
|
|
355
|
-
onPressIn: event => {
|
|
356
|
-
dayProps?.onPressIn?.(event);
|
|
357
|
-
if (__preventFocus && (0, _hasPreventDefault.hasPreventDefault)(event)) {
|
|
358
|
-
event.preventDefault();
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
tabIndex: tabIndex
|
|
362
|
-
})
|
|
363
|
-
}, date);
|
|
538
|
+
highlightToday: highlightToday,
|
|
539
|
+
renderDay: renderDay,
|
|
540
|
+
stopPropagation: __stopPropagation,
|
|
541
|
+
preventFocus: __preventFocus,
|
|
542
|
+
cellProps: cellSlotProps,
|
|
543
|
+
dayProps: dayProps,
|
|
544
|
+
mergedDayProps: s.merge("day", dayProps),
|
|
545
|
+
onDayMouseEnter: onDayMouseEnter,
|
|
546
|
+
onDayClick: onDayClick,
|
|
547
|
+
onDayKeyDown: onDayKeyDown,
|
|
548
|
+
getDayRef: getDayRef
|
|
549
|
+
}, info.date);
|
|
364
550
|
});
|
|
365
551
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(MonthRow, {
|
|
366
552
|
role: "row",
|
|
@@ -374,7 +560,7 @@ const MonthComponent = MonthFrame.styleable(function Month(props, ref) {
|
|
|
374
560
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(MonthWeekNumberLabel, {
|
|
375
561
|
size: size,
|
|
376
562
|
...s.get("weekNumberLabel"),
|
|
377
|
-
children:
|
|
563
|
+
children: row.weekNumber
|
|
378
564
|
})
|
|
379
565
|
}), cells]
|
|
380
566
|
}, rowIndex);
|