@knitui/dates 0.5.0 → 0.6.1
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/Calendar/pick-calendar-props/pick-calendar-props.d.ts +1 -1
- package/lib/typescript/CalendarHeader/CalendarHeader.d.ts +14 -14
- package/lib/typescript/DatesProvider/DatesProvider.d.ts.map +1 -1
- package/lib/typescript/Day/Day.d.ts +31 -31
- package/lib/typescript/Day/Day.d.ts.map +1 -1
- package/lib/typescript/DecadeLevel/DecadeLevel.d.ts +7 -7
- package/lib/typescript/DecadeLevelGroup/DecadeLevelGroup.d.ts +7 -7
- package/lib/typescript/InlineDateTimePicker/InlineDateTimePicker.d.ts +4 -4
- package/lib/typescript/MiniCalendar/MiniCalendar.d.ts +18 -18
- package/lib/typescript/Month/Month.d.ts +9 -8
- package/lib/typescript/Month/Month.d.ts.map +1 -1
- package/lib/typescript/MonthLevel/MonthLevel.d.ts +10 -10
- package/lib/typescript/MonthLevel/MonthLevel.d.ts.map +1 -1
- package/lib/typescript/MonthLevelGroup/MonthLevelGroup.d.ts +10 -10
- 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/PickerControl/PickerControl.d.ts +10 -10
- 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/TimeGrid/TimeGrid.d.ts +7 -7
- package/lib/typescript/TimePicker/TimePicker.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresetGroup.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts +6 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts.map +1 -1
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts +6 -6
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts.map +1 -1
- package/lib/typescript/YearLevel/YearLevel.d.ts +7 -7
- package/lib/typescript/YearLevelGroup/YearLevelGroup.d.ts +7 -7
- 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/_reference/ExampleControl.d.ts +8 -8
- 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 +6 -6
- 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
|
@@ -20,13 +20,18 @@
|
|
|
20
20
|
// frame/row/cell, not a per-render spread the optimiser could fold onto a whole
|
|
21
21
|
// cell.
|
|
22
22
|
// ───────────────────────────────────────────────────────────────────────────
|
|
23
|
+
import * as React from "react";
|
|
24
|
+
import { useMemo } from "react";
|
|
23
25
|
import dayjs from "dayjs";
|
|
24
26
|
import { Box } from "@knitui/components";
|
|
25
27
|
import { createStyledContext, slotStyles, styled, withStaticProperties } from "@knitui/core";
|
|
28
|
+
import { useCallbackRef } from "@knitui/hooks";
|
|
26
29
|
import { CELL_SPACING } from "../cell-metrics";
|
|
27
30
|
import { useDatesContext } from "../DatesProvider";
|
|
31
|
+
import { areCellPropsEqual } from "../internal/are-cell-props-equal";
|
|
28
32
|
import { focusElement } from "../internal/focus-element";
|
|
29
33
|
import { hasPreventDefault } from "../internal/has-prevent-default";
|
|
34
|
+
import { memoizeByDate } from "../internal/memoize-control-props";
|
|
30
35
|
import { PickerControl } from "../PickerControl";
|
|
31
36
|
import { toDateString } from "../utils";
|
|
32
37
|
import { getYearInTabOrder } from "./get-year-in-tab-order/get-year-in-tab-order";
|
|
@@ -115,6 +120,91 @@ const YearsListCell = styled(Box, {
|
|
|
115
120
|
}
|
|
116
121
|
});
|
|
117
122
|
|
|
123
|
+
/** Props for the memoized year cell — see {@link YearsListControlCell}. */
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* One year cell, memoized — the `YearsList` twin of `Month`'s `MonthDayCell` and
|
|
127
|
+
* `MonthsList`'s `MonthsListControlCell`.
|
|
128
|
+
*
|
|
129
|
+
* A RANGE year picker updates `hoveredDate` on every web hover move, re-rendering
|
|
130
|
+
* the whole picker subtree; without this boundary all 10 `PickerControl` leaves
|
|
131
|
+
* re-rendered (and 10 refs detached/reattached, re-running `__getControlRef`) for a
|
|
132
|
+
* change that moved two cells' background colour.
|
|
133
|
+
*
|
|
134
|
+
* The boundary is deliberately an INTERNAL cell, not the public `PickerControl`.
|
|
135
|
+
* Tamagui's styled-context and theme reads happen inside the leaf and still
|
|
136
|
+
* propagate past a memo, so cells keep responding to theme/size changes.
|
|
137
|
+
*/
|
|
138
|
+
const YearsListControlCell = /*#__PURE__*/React.memo(function YearsListControlCell({
|
|
139
|
+
year,
|
|
140
|
+
label,
|
|
141
|
+
disabled,
|
|
142
|
+
rowIndex,
|
|
143
|
+
cellIndex,
|
|
144
|
+
tabIndex,
|
|
145
|
+
size,
|
|
146
|
+
fullWidth,
|
|
147
|
+
preventFocus,
|
|
148
|
+
cellProps,
|
|
149
|
+
controlProps,
|
|
150
|
+
mergedControlProps,
|
|
151
|
+
onControlMouseEnter,
|
|
152
|
+
onControlClick,
|
|
153
|
+
onControlKeyDown,
|
|
154
|
+
getControlRef
|
|
155
|
+
}) {
|
|
156
|
+
// Tamagui hover handlers are not part of `PickerControl`'s public prop type;
|
|
157
|
+
// attach them via a precisely-typed object spread, the kit's pattern for web-only
|
|
158
|
+
// affordances (see `Month`). Native never fires it.
|
|
159
|
+
const hoverHandlers = {
|
|
160
|
+
onHoverIn: event => onControlMouseEnter(event, year)
|
|
161
|
+
};
|
|
162
|
+
return /*#__PURE__*/_jsx(YearsListCell, {
|
|
163
|
+
role: "cell",
|
|
164
|
+
fullWidth: fullWidth,
|
|
165
|
+
...cellProps,
|
|
166
|
+
children: /*#__PURE__*/_jsx(PickerControl, {
|
|
167
|
+
size: size,
|
|
168
|
+
fullWidth: fullWidth
|
|
169
|
+
// explicit beats sugar: the `control` slot sits UNDER per-year
|
|
170
|
+
// `getYearControlProps`, and the consumer's own handlers are
|
|
171
|
+
// preserved (called before ours).
|
|
172
|
+
,
|
|
173
|
+
...mergedControlProps,
|
|
174
|
+
disabled: disabled,
|
|
175
|
+
ref: node => {
|
|
176
|
+
if (node) {
|
|
177
|
+
getControlRef(rowIndex, cellIndex, {
|
|
178
|
+
focus: () => focusElement(node),
|
|
179
|
+
disabled
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
onKeyDown: event => {
|
|
184
|
+
controlProps?.onKeyDown?.(event);
|
|
185
|
+
onControlKeyDown(event, {
|
|
186
|
+
rowIndex,
|
|
187
|
+
cellIndex,
|
|
188
|
+
date: year
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
onPress: event => {
|
|
192
|
+
controlProps?.onPress?.(event);
|
|
193
|
+
onControlClick(event, year);
|
|
194
|
+
},
|
|
195
|
+
onPressIn: event => {
|
|
196
|
+
controlProps?.onPressIn?.(event);
|
|
197
|
+
if (preventFocus && hasPreventDefault(event)) {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
tabIndex: tabIndex,
|
|
202
|
+
...hoverHandlers,
|
|
203
|
+
children: controlProps?.children ?? label
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
}, areCellPropsEqual);
|
|
207
|
+
|
|
118
208
|
// ── 7. Per-slot `styles` sugar + per-item passthrough ───────────────────────────
|
|
119
209
|
// The kit's ONE styling model is props on the parts. `styles` is thin sugar over
|
|
120
210
|
// that: a map from named slot → that part's props, resolved through
|
|
@@ -178,73 +268,77 @@ const YearsListComponent = YearsListFrame.styleable(function YearsList(props, re
|
|
|
178
268
|
|
|
179
269
|
// 7. Typed per-slot accessor (dev-warns unknown keys against the known set).
|
|
180
270
|
const s = slotStyles(styles, YEARS_LIST_SLOT_KEYS, "YearsList");
|
|
181
|
-
const
|
|
271
|
+
const resolvedLocale = ctx.getLocale(locale);
|
|
272
|
+
|
|
273
|
+
// The 10 cells' grid, bounds and LABELS depend only on the decade, the locale,
|
|
274
|
+
// the format and the min/max bounds — never on the selection — yet they were
|
|
275
|
+
// rebuilt every render, each cell paying a `dayjs(year).locale(…).format(…)`
|
|
276
|
+
// (parse + locale clone + locale-table format) for a label fixed for the decade.
|
|
277
|
+
const yearsInfo = useMemo(() => {
|
|
278
|
+
const grid = getYearsData(decade);
|
|
279
|
+
return {
|
|
280
|
+
grid,
|
|
281
|
+
cells: grid.map(row => row.map(year => ({
|
|
282
|
+
year,
|
|
283
|
+
disabled: isYearDisabled({
|
|
284
|
+
year,
|
|
285
|
+
minDate: minDateString,
|
|
286
|
+
maxDate: maxDateString
|
|
287
|
+
}),
|
|
288
|
+
label: dayjs(year).locale(resolvedLocale).format(yearsListFormat)
|
|
289
|
+
})))
|
|
290
|
+
};
|
|
291
|
+
}, [decade, minDateString, maxDateString, resolvedLocale, yearsListFormat]);
|
|
292
|
+
|
|
293
|
+
// ONE per-render cache shared by `getYearInTabOrder` (which consults the getter
|
|
294
|
+
// twice per year) and the cell loop below (a third time). Not memoized across
|
|
295
|
+
// renders — the getter closes over live selection state.
|
|
296
|
+
const resolveControlProps = memoizeByDate(getYearControlProps);
|
|
182
297
|
const yearInTabOrder = getYearInTabOrder({
|
|
183
|
-
years,
|
|
298
|
+
years: yearsInfo.grid,
|
|
184
299
|
minDate: minDateString,
|
|
185
300
|
maxDate: maxDateString,
|
|
186
|
-
getYearControlProps
|
|
301
|
+
getYearControlProps: resolveControlProps
|
|
187
302
|
});
|
|
188
303
|
const cellGap = withCellSpacing ? CELL_SPACING : 0;
|
|
189
|
-
const rows = years.map((yearsRow, rowIndex) => {
|
|
190
|
-
const cells = yearsRow.map((year, cellIndex) => {
|
|
191
|
-
const controlProps = getYearControlProps?.(year);
|
|
192
|
-
const isYearInTabOrder = dayjs(year).isSame(yearInTabOrder, "year");
|
|
193
|
-
const disabled = isYearDisabled({
|
|
194
|
-
year,
|
|
195
|
-
minDate: minDateString,
|
|
196
|
-
maxDate: maxDateString
|
|
197
|
-
}) || controlProps?.disabled;
|
|
198
304
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
305
|
+
// The cell memo can only bail out if every function prop it receives keeps a
|
|
306
|
+
// stable identity. All four of these arrive freshly built each render (the level
|
|
307
|
+
// group builds them per decade, `YearPicker` per render), so they are wrapped once
|
|
308
|
+
// here rather than being stabilised at each of their many call sites.
|
|
309
|
+
const onControlMouseEnter = useCallbackRef(__onControlMouseEnter);
|
|
310
|
+
const onControlClick = useCallbackRef(__onControlClick);
|
|
311
|
+
const onControlKeyDown = useCallbackRef(__onControlKeyDown);
|
|
312
|
+
const getControlRef = useCallbackRef(__getControlRef);
|
|
313
|
+
const cellSlotProps = s.get("cell");
|
|
314
|
+
const rows = yearsInfo.cells.map((yearsRow, rowIndex) => {
|
|
315
|
+
const cells = yearsRow.map(({
|
|
316
|
+
year,
|
|
317
|
+
disabled: outOfBounds,
|
|
318
|
+
label
|
|
319
|
+
}, cellIndex) => {
|
|
320
|
+
const controlProps = resolveControlProps?.(year);
|
|
321
|
+
// Both sides come from `getYearsData`'s canonical `YYYY-MM-DD`, so the `YYYY`
|
|
322
|
+
// prefix compare is exactly the year-granularity `isSame` it replaces.
|
|
323
|
+
const isYearInTabOrder = yearInTabOrder !== undefined && year.slice(0, 4) === yearInTabOrder.slice(0, 4);
|
|
324
|
+
const disabled = outOfBounds || controlProps?.disabled;
|
|
325
|
+
return /*#__PURE__*/_jsx(YearsListControlCell, {
|
|
326
|
+
year: year,
|
|
327
|
+
label: label,
|
|
328
|
+
disabled: disabled,
|
|
329
|
+
rowIndex: rowIndex,
|
|
330
|
+
cellIndex: cellIndex,
|
|
331
|
+
tabIndex: __preventFocus || !isYearInTabOrder ? -1 : 0,
|
|
332
|
+
size: size,
|
|
207
333
|
fullWidth: fullWidth,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
...s.merge("control", controlProps),
|
|
217
|
-
disabled: disabled,
|
|
218
|
-
ref: node => {
|
|
219
|
-
if (node) {
|
|
220
|
-
__getControlRef?.(rowIndex, cellIndex, {
|
|
221
|
-
focus: () => focusElement(node),
|
|
222
|
-
disabled
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
onKeyDown: event => {
|
|
227
|
-
controlProps?.onKeyDown?.(event);
|
|
228
|
-
__onControlKeyDown?.(event, {
|
|
229
|
-
rowIndex,
|
|
230
|
-
cellIndex,
|
|
231
|
-
date: year
|
|
232
|
-
});
|
|
233
|
-
},
|
|
234
|
-
onPress: event => {
|
|
235
|
-
controlProps?.onPress?.(event);
|
|
236
|
-
__onControlClick?.(event, year);
|
|
237
|
-
},
|
|
238
|
-
onPressIn: event => {
|
|
239
|
-
controlProps?.onPressIn?.(event);
|
|
240
|
-
if (__preventFocus && hasPreventDefault(event)) {
|
|
241
|
-
event.preventDefault();
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
tabIndex: __preventFocus || !isYearInTabOrder ? -1 : 0,
|
|
245
|
-
...hoverHandlers,
|
|
246
|
-
children: controlProps?.children ?? dayjs(year).locale(ctx.getLocale(locale)).format(yearsListFormat)
|
|
247
|
-
})
|
|
334
|
+
preventFocus: __preventFocus,
|
|
335
|
+
cellProps: cellSlotProps,
|
|
336
|
+
controlProps: controlProps,
|
|
337
|
+
mergedControlProps: s.merge("control", controlProps),
|
|
338
|
+
onControlMouseEnter: onControlMouseEnter,
|
|
339
|
+
onControlClick: onControlClick,
|
|
340
|
+
onControlKeyDown: onControlKeyDown,
|
|
341
|
+
getControlRef: getControlRef
|
|
248
342
|
}, year);
|
|
249
343
|
});
|
|
250
344
|
return /*#__PURE__*/_jsx(YearsListRow, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["dayjs","Box","createStyledContext","slotStyles","styled","withStaticProperties","CELL_SPACING","useDatesContext","focusElement","hasPreventDefault","PickerControl","toDateString","getYearInTabOrder","getYearsData","isYearDisabled","jsx","_jsx","YearsListContext","size","YearsListFrame","name","context","flexDirection","variants","fullWidth","true","width","flexGrow","YearsListRow","YearsListCell","alignItems","justifyContent","flexBasis","
|
|
1
|
+
{"version":3,"names":["React","useMemo","dayjs","Box","createStyledContext","slotStyles","styled","withStaticProperties","useCallbackRef","CELL_SPACING","useDatesContext","areCellPropsEqual","focusElement","hasPreventDefault","memoizeByDate","PickerControl","toDateString","getYearInTabOrder","getYearsData","isYearDisabled","jsx","_jsx","YearsListContext","size","YearsListFrame","name","context","flexDirection","variants","fullWidth","true","width","flexGrow","YearsListRow","YearsListCell","alignItems","justifyContent","flexBasis","YearsListControlCell","memo","year","label","disabled","rowIndex","cellIndex","tabIndex","preventFocus","cellProps","controlProps","mergedControlProps","onControlMouseEnter","onControlClick","onControlKeyDown","getControlRef","hoverHandlers","onHoverIn","event","role","children","ref","node","focus","onKeyDown","date","onPress","onPressIn","preventDefault","YEARS_LIST_SLOT_KEYS","YearsListComponent","styleable","YearsList","props","decade","yearsListFormat","locale","minDate","maxDate","getYearControlProps","__getControlRef","__onControlKeyDown","__onControlClick","__onControlMouseEnter","__preventFocus","__stopPropagation","withCellSpacing","styles","rest","ctx","minDateString","undefined","maxDateString","s","resolvedLocale","getLocale","yearsInfo","grid","cells","map","row","format","resolveControlProps","yearInTabOrder","years","cellGap","cellSlotProps","get","rows","yearsRow","outOfBounds","isYearInTabOrder","slice","merge","columnGap","rowGap","displayName","Frame","Row","Cell"],"sourceRoot":"../../../src","sources":["YearsList/YearsList.tsx"],"mapp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AAA,GACjB8D,CAAC,CAACc,GAAG,CAAC,MAAM,CAAC;MAAA,GACbnB,IAAI;MAAA5B,QAAA,EAEPgD;IAAI,CACS;EAAC;AAErB,CAAC,CAAC;AAEFtC,kBAAkB,CAAC8C,WAAW,GAAG,yBAAyB;;AAE1D;AACA;AACA;AACA;AACA,OAAO,MAAM5C,SAAS,GAAG/D,oBAAoB,CAAC6D,kBAAkB,EAAE;EAChE+C,KAAK,EAAE3F,cAAc;EACrB4F,GAAG,EAAEnF,YAAY;EACjBoF,IAAI,EAAEnF;AACR,CAAC,CAAC","ignoreList":[]}
|
|
@@ -21,7 +21,13 @@ export function getYearInTabOrder({
|
|
|
21
21
|
if (selectedYear) {
|
|
22
22
|
return selectedYear;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// One formatted "today" instead of a fresh `dayjs()` (plus its `startOf`/`endOf`
|
|
26
|
+
// clones) per candidate. `years` always comes from `getYearsData`, which emits
|
|
27
|
+
// zero-padded `YYYY-MM-DD`, so comparing the `YYYY` prefix is exactly the
|
|
28
|
+
// year-granularity `isSame` this replaces.
|
|
29
|
+
const currentYearPrefix = dayjs().format("YYYY");
|
|
30
|
+
const currentYear = enabledYears.find(year => year.slice(0, 4) === currentYearPrefix);
|
|
25
31
|
if (currentYear) {
|
|
26
32
|
return currentYear;
|
|
27
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["dayjs","isYearDisabled","getYearInTabOrder","years","minDate","maxDate","getYearControlProps","enabledYears","flat","filter","year","disabled","selectedYear","find","selected","currentYear","
|
|
1
|
+
{"version":3,"names":["dayjs","isYearDisabled","getYearInTabOrder","years","minDate","maxDate","getYearControlProps","enabledYears","flat","filter","year","disabled","selectedYear","find","selected","currentYearPrefix","format","currentYear","slice"],"sourceRoot":"../../../../src","sources":["YearsList/get-year-in-tab-order/get-year-in-tab-order.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAASC,cAAc,QAAQ,sCAAsC;AAerE;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,KAAK;EACLC,OAAO;EACPC,OAAO;EACPC;AACsB,CAAC,EAA+B;EACtD,MAAMC,YAAY,GAAGJ,KAAK,CACvBK,IAAI,CAAC,CAAC,CACNC,MAAM,CACJC,IAAI,IACH,CAACT,cAAc,CAAC;IAAES,IAAI;IAAEN,OAAO;IAAEC;EAAQ,CAAC,CAAC,IAAI,CAACC,mBAAmB,GAAGI,IAAI,CAAC,EAAEC,QACjF,CAAC;EAEH,MAAMC,YAAY,GAAGL,YAAY,CAACM,IAAI,CAAEH,IAAI,IAAKJ,mBAAmB,GAAGI,IAAI,CAAC,EAAEI,QAAQ,CAAC;EAEvF,IAAIF,YAAY,EAAE;IAChB,OAAOA,YAAY;EACrB;;EAEA;EACA;EACA;EACA;EACA,MAAMG,iBAAiB,GAAGf,KAAK,CAAC,CAAC,CAACgB,MAAM,CAAC,MAAM,CAAC;EAChD,MAAMC,WAAW,GAAGV,YAAY,CAACM,IAAI,CAAEH,IAAI,IAAKA,IAAI,CAACQ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAKH,iBAAiB,CAAC;EAEvF,IAAIE,WAAW,EAAE;IACf,OAAOA,WAAW;EACpB;EAEA,OAAOV,YAAY,CAAC,CAAC,CAAC;AACxB","ignoreList":[]}
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
|
+
import { isCanonicalDateString } from "../../../internal/date-string-fast-path";
|
|
4
5
|
/**
|
|
5
6
|
* Whether `date` falls within the inclusive `[start, end]` range, ported 1:1 from
|
|
6
7
|
* Mantine's `is-in-range`. The pair is sorted first (so callers may pass the
|
|
7
8
|
* endpoints in either order), then the bounds are widened by 1ms to the day's
|
|
8
9
|
* edges so the comparison is inclusive of both endpoints. Pure dayjs — no DOM.
|
|
10
|
+
*
|
|
11
|
+
* The Mantine spelling is the most expensive per-cell call in a range picker:
|
|
12
|
+
* `[...range].sort()` allocates an array and builds 2 dayjs instances inside the
|
|
13
|
+
* comparator, then each bound costs an instance plus `startOf`/`endOf` and
|
|
14
|
+
* `subtract`/`add` clones — ~11 instances per call, and `getControlProps` calls
|
|
15
|
+
* it for every cell (up to 3× per cell across the range/first/last checks).
|
|
16
|
+
*
|
|
17
|
+
* The widened bounds exist purely to make the endpoint comparison inclusive at
|
|
18
|
+
* DAY granularity, so for canonical zero-padded `YYYY-MM-DD` strings the whole
|
|
19
|
+
* thing reduces to `min <= date <= max` on the date prefix — exact, and with no
|
|
20
|
+
* sort, no clones and no allocations. Any non-canonical endpoint falls back to
|
|
21
|
+
* the original dayjs path.
|
|
9
22
|
*/
|
|
10
23
|
export function isInRange(date, range) {
|
|
24
|
+
const [start, end] = range;
|
|
25
|
+
if (isCanonicalDateString(date) && isCanonicalDateString(start) && isCanonicalDateString(end)) {
|
|
26
|
+
const value = date.slice(0, 10);
|
|
27
|
+
const from = start.slice(0, 10);
|
|
28
|
+
const to = end.slice(0, 10);
|
|
29
|
+
return from <= to ? value >= from && value <= to : value >= to && value <= from;
|
|
30
|
+
}
|
|
11
31
|
const _range = [...range].sort((a, b) => dayjs(a).isAfter(dayjs(b)) ? 1 : -1);
|
|
12
32
|
return dayjs(_range[0]).startOf("day").subtract(1, "ms").isBefore(date) && dayjs(_range[1]).endOf("day").add(1, "ms").isAfter(date);
|
|
13
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["dayjs","isInRange","date","range","_range","sort","a","b","isAfter","startOf","subtract","isBefore","endOf","add"],"sourceRoot":"../../../../../src","sources":["hooks/use-dates-state/is-in-range/is-in-range.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;
|
|
1
|
+
{"version":3,"names":["dayjs","isCanonicalDateString","isInRange","date","range","start","end","value","slice","from","to","_range","sort","a","b","isAfter","startOf","subtract","isBefore","endOf","add"],"sourceRo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CAAC,CAACQ,KAAK,CAAC,KAAK,CAAC,CAACC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAACL,OAAO,CAACZ,IAAI,CAAC;AAE5D","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import dayjs from "dayjs";
|
|
5
|
+
import { isBeforeByPrefix, isSameByPrefix } from "../../internal/date-string-fast-path";
|
|
5
6
|
import { useUncontrolledDates } from "../use-uncontrolled-dates";
|
|
6
7
|
import { isInRange } from "./is-in-range";
|
|
7
8
|
|
|
@@ -126,23 +127,40 @@ export function useDatesState({
|
|
|
126
127
|
onMouseLeave?.(event);
|
|
127
128
|
setHoveredDate(null);
|
|
128
129
|
} : onMouseLeave;
|
|
130
|
+
|
|
131
|
+
// ── The per-cell comparison helpers ────────────────────────────────────────
|
|
132
|
+
// `getControlProps` below is called for EVERY cell of the grid (42 for a day
|
|
133
|
+
// picker, ×2 for two columns), and it consults these three times per cell — so
|
|
134
|
+
// `dayjs(a).isSame(b, level)`, at ~4 allocations a call (the instance, plus
|
|
135
|
+
// dayjs' internal `startOf`/`endOf` clones), dominated the render. Both sides
|
|
136
|
+
// are canonical `YYYY-MM-DD` in every picker, so a prefix compare at the
|
|
137
|
+
// `level`'s granularity is exact and allocation-free; `isSameByPrefix` /
|
|
138
|
+
// `isBeforeByPrefix` return `null` for anything non-canonical, which falls back
|
|
139
|
+
// to the original dayjs comparison.
|
|
140
|
+
const isSameAtLevel = (a, b) => {
|
|
141
|
+
if (a == null || b == null) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return isSameByPrefix(a, b, level) ?? dayjs(a).isSame(b, level);
|
|
145
|
+
};
|
|
146
|
+
const isStrictlyBefore = (a, b) => isBeforeByPrefix(a, b) ?? dayjs(a).isBefore(b);
|
|
129
147
|
const isFirstInRange = date => {
|
|
130
148
|
if (!rangeView[0]) {
|
|
131
149
|
return false;
|
|
132
150
|
}
|
|
133
|
-
if (
|
|
134
|
-
return !(hoveredDate &&
|
|
151
|
+
if (isSameAtLevel(date, rangeView[0])) {
|
|
152
|
+
return !(hoveredDate && isStrictlyBefore(hoveredDate, rangeView[0]));
|
|
135
153
|
}
|
|
136
154
|
return false;
|
|
137
155
|
};
|
|
138
156
|
const isLastInRange = date => {
|
|
139
157
|
if (rangeView[1]) {
|
|
140
|
-
return
|
|
158
|
+
return isSameAtLevel(date, rangeView[1]);
|
|
141
159
|
}
|
|
142
160
|
if (!rangeView[0] || !hoveredDate) {
|
|
143
161
|
return false;
|
|
144
162
|
}
|
|
145
|
-
return
|
|
163
|
+
return isStrictlyBefore(hoveredDate, rangeView[0]) && isSameAtLevel(date, rangeView[0]);
|
|
146
164
|
};
|
|
147
165
|
|
|
148
166
|
// NOTE: Mantine also returns a `data-autofocus` web-DOM attribute here; it is
|
|
@@ -150,7 +168,7 @@ export function useDatesState({
|
|
|
150
168
|
const getControlProps = date => {
|
|
151
169
|
if (type === "range") {
|
|
152
170
|
return {
|
|
153
|
-
selected: rangeView.some(selection =>
|
|
171
|
+
selected: rangeView.some(selection => isSameAtLevel(selection, date)),
|
|
154
172
|
inRange: isDateInRange(date),
|
|
155
173
|
firstInRange: isFirstInRange(date),
|
|
156
174
|
lastInRange: isLastInRange(date)
|
|
@@ -158,12 +176,12 @@ export function useDatesState({
|
|
|
158
176
|
}
|
|
159
177
|
if (type === "multiple") {
|
|
160
178
|
return {
|
|
161
|
-
selected: storedArray.some(selection =>
|
|
179
|
+
selected: storedArray.some(selection => isSameAtLevel(selection, date))
|
|
162
180
|
};
|
|
163
181
|
}
|
|
164
182
|
const single = Array.isArray(stored) ? null : stored;
|
|
165
183
|
return {
|
|
166
|
-
selected:
|
|
184
|
+
selected: isSameAtLevel(single, date)
|
|
167
185
|
};
|
|
168
186
|
};
|
|
169
187
|
const onHoveredDateChange = date => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useState","dayjs","useUncontrolledDates","isInRange","useDatesState","type","level","value","defaultValue","onChange","allowSingleDateInRange","allowDeselect","onMouseLeave","_value","setValue","stored","commit","next","rangeView","Array","isArray","storedArray","pickedDate","setPickedDate","hoveredDate","setHoveredDate","onDateChange","date","isSame","result","sort","a","b","isAfter","values","filter","item","some","selected","single","isDateInRange","onRootMouseLeave","event","
|
|
1
|
+
{"version":3,"names":["useEffect","useState","dayjs","isBeforeByPrefix","isSameByPrefix","useUncontrolledDates","isInRange","useDatesState","type","level","value","defaultValue","onChange","allowSingleDateInRange","allowDeselect","onMouseLeave","_value","setValue","stored","commit","next","rangeView","Array","isArray","storedArray","pickedDate","setPickedDate","hoveredDate","setHoveredDate","onDateChange","date","isSame","result","sort","a","b","isAfter","values","filter","item","some","selected","single","isDateInRange","onRootMouseLeave","event","isSameAtLevel","isStrictlyBefore","isBefore","isFirstInRange","isLastInRange","getControlProps","selection","inRange","firstInRange","lastInRange","onHoveredDateChange","isNeitherSelected","isBothSelected"],"sourceRoot":"../../../../src","sources":["hooks/use-dates-state/use-dates-state.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3C,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,sCAAsC;AAQvF,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,SAAS,QAAQ,eAAe;;AAEzC;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAIA;;AAQA;;AAKA;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAA0C;EACrEC,IAAI;EACJC,KAAK;EACLC,KAAK;EACLC,YAAY;EACZC,QAAQ;EACRC,sBAAsB;EACtBC,aAAa;EACbC;AACwB,CAAC,EAAE;EAC3B,MAAM,CAACC,MAAM,EAAEC,QAAQ,CAAC,GAAGZ,oBAAoB,CAAO;IAC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
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Internal cross-platform helper — NOT exported from the public `src/index.ts`
|
|
4
|
+
// barrel.
|
|
5
|
+
//
|
|
6
|
+
// The shared `React.memo` comparator for the grid CELL components of `Month`,
|
|
7
|
+
// `MonthsList` and `YearsList`. All three grids have the same shape of problem, so
|
|
8
|
+
// they share one implementation rather than each carrying a copy.
|
|
9
|
+
|
|
10
|
+
/** A plain (non-array, non-null) object — the shape {@link areCellPropsEqual} looks one level into. */
|
|
11
|
+
function isPlainObject(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* One-level-deep `React.memo` comparator for a memoized grid cell.
|
|
17
|
+
*
|
|
18
|
+
* A plain shallow compare is not enough for these grids: a cell's per-item inputs
|
|
19
|
+
* arrive as FRESHLY BUILT objects on every render — the per-item prop getter
|
|
20
|
+
* (`getDayProps` / `getMonthControlProps` / `getYearControlProps`, which is
|
|
21
|
+
* `useDatesState`'s `getControlProps`) returns a new object by design, and
|
|
22
|
+
* `slotStyles().get()/merge()` likewise. Their CONTENTS, though, are stable
|
|
23
|
+
* booleans for all but the two or three cells whose state actually moved.
|
|
24
|
+
*
|
|
25
|
+
* So: compare props shallowly, and where both sides are plain objects, compare one
|
|
26
|
+
* level deeper. That is exactly deep enough to see "same selection state, new
|
|
27
|
+
* object" and shallow enough to stay O(props) — and it degrades safely, since any
|
|
28
|
+
* value it cannot prove equal (a nested object, a fresh function) reads as changed
|
|
29
|
+
* and simply re-renders the cell.
|
|
30
|
+
*
|
|
31
|
+
* Generic over the cell's props so each grid keeps its own precise props type; the
|
|
32
|
+
* comparator itself only ever reads keys and compares values.
|
|
33
|
+
*/
|
|
34
|
+
export function areCellPropsEqual(prev, next) {
|
|
35
|
+
const keys = Object.keys(prev);
|
|
36
|
+
if (keys.length !== Object.keys(next).length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
const a = prev[key];
|
|
41
|
+
const b = next[key];
|
|
42
|
+
if (a === b) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!isPlainObject(a) || !isPlainObject(b)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const innerKeys = Object.keys(a);
|
|
49
|
+
if (innerKeys.length !== Object.keys(b).length) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
for (const innerKey of innerKeys) {
|
|
53
|
+
if (a[innerKey] !== b[innerKey]) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=are-cell-props-equal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isPlainObject","value","Array","isArray","areCellPropsEqual","prev","next","keys","Object","length","key","a","b","innerKeys","innerKey"],"sourceRoot":"../../../src","sources":["internal/are-cell-props-equal.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,SAASA,aAAaA,CAACC,KAAc,EAAoC;EACvE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC;AAC7E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,iBAAiBA,CAAmBC,IAAO,EAAEC,IAAO,EAAW;EAC7E,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,IAAI,CAAgB;EAE7C,IAAIE,IAAI,CAACE,MAAM,KAAKD,MAAM,CAACD,IAAI,CAACD,IAAI,CAAC,CAACG,MAAM,EAAE;IAC5C,OAAO,KAAK;EACd;EAEA,KAAK,MAAMC,GAAG,IAAIH,I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