@react-aria/calendar 3.9.3 → 3.9.5
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/dist/types.d.ts.map +1 -1
- package/dist/useCalendarCell.main.js +23 -4
- package/dist/useCalendarCell.main.js.map +1 -1
- package/dist/useCalendarCell.mjs +24 -5
- package/dist/useCalendarCell.module.js +24 -5
- package/dist/useCalendarCell.module.js.map +1 -1
- package/dist/useRangeCalendar.main.js +2 -2
- package/dist/useRangeCalendar.main.js.map +1 -1
- package/dist/useRangeCalendar.mjs +3 -3
- package/dist/useRangeCalendar.module.js +3 -3
- package/dist/useRangeCalendar.module.js.map +1 -1
- package/package.json +10 -10
- package/src/useCalendarCell.ts +22 -5
- package/src/useRangeCalendar.ts +4 -4
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;ACwBA;IACE,+CAA+C;IAC/C,aAAa,EAAE,aAAa,CAAC;IAC7B,iCAAiC;IACjC,eAAe,EAAE,eAAe,CAAC;IACjC,qCAAqC;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,mDAAmD;IACnD,iBAAiB,EAAE,aAAa,CAAC;IACjC,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAA;CACd;ACnBD;;;GAGG;AACH,4BAA4B,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAEhH;ACHD;;;GAGG;AACH,iCAAiC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,YAAY,CA0DxK;AC7DD;IACE;;;;OAIG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;OA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D;IACE,0CAA0C;IAC1C,IAAI,EAAE,YAAY,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;IACE,qDAAqD;IACrD,SAAS,EAAE,aAAa,CAAC;IACzB,oDAAoD;IACpD,WAAW,EAAE,aAAa,CAAC;IAC3B,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,mCAAmC;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;;;;OAOG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,qBAAqB,EAAE,OAAO,CAAC;IAC/B,wDAAwD;IACxD,SAAS,EAAE,OAAO,CAAC;IACnB,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,gCAAgC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAuS7J;ACrWD,YAAY,EAAC,iBAAiB,EAAE,sBAAsB,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/utils.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarBase.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendar.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useRangeCalendar.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarGrid.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarCell.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/index.ts","packages/@react-aria/calendar/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useCalendar} from './useCalendar';\nexport {useRangeCalendar} from './useRangeCalendar';\nexport {useCalendarGrid} from './useCalendarGrid';\nexport {useCalendarCell} from './useCalendarCell';\n\nexport type {AriaCalendarProps, AriaRangeCalendarProps, CalendarProps, DateValue, RangeCalendarProps} from '@react-types/calendar';\nexport type {CalendarAria} from './useCalendarBase';\nexport type {AriaCalendarGridProps, CalendarGridAria} from './useCalendarGrid';\nexport type {AriaCalendarCellProps, CalendarCellAria} from './useCalendarCell';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -109,6 +109,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
109
109
|
onPressStart (e) {
|
|
110
110
|
if (state.isReadOnly) {
|
|
111
111
|
state.setFocusedDate(date);
|
|
112
|
+
state.setFocused(true);
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
115
|
if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {
|
|
@@ -120,12 +121,14 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
120
121
|
if ((0, $cuS6T$internationalizeddate.isSameDay)(date, state.highlightedRange.start)) {
|
|
121
122
|
state.setAnchorDate(state.highlightedRange.end);
|
|
122
123
|
state.setFocusedDate(date);
|
|
124
|
+
state.setFocused(true);
|
|
123
125
|
state.setDragging(true);
|
|
124
126
|
isRangeBoundaryPressed.current = true;
|
|
125
127
|
return;
|
|
126
128
|
} else if ((0, $cuS6T$internationalizeddate.isSameDay)(date, state.highlightedRange.end)) {
|
|
127
129
|
state.setAnchorDate(state.highlightedRange.start);
|
|
128
130
|
state.setFocusedDate(date);
|
|
131
|
+
state.setFocused(true);
|
|
129
132
|
state.setDragging(true);
|
|
130
133
|
isRangeBoundaryPressed.current = true;
|
|
131
134
|
return;
|
|
@@ -136,6 +139,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
136
139
|
touchDragTimerRef.current = undefined;
|
|
137
140
|
state.selectDate(date);
|
|
138
141
|
state.setFocusedDate(date);
|
|
142
|
+
state.setFocused(true);
|
|
139
143
|
isAnchorPressed.current = true;
|
|
140
144
|
};
|
|
141
145
|
// Start selection on mouse/touch down so users can drag to select a range.
|
|
@@ -155,6 +159,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
155
159
|
if (!('anchorDate' in state) && !state.isReadOnly) {
|
|
156
160
|
state.selectDate(date);
|
|
157
161
|
state.setFocusedDate(date);
|
|
162
|
+
state.setFocused(true);
|
|
158
163
|
}
|
|
159
164
|
},
|
|
160
165
|
onPressUp (e) {
|
|
@@ -165,6 +170,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
165
170
|
if ('anchorDate' in state && touchDragTimerRef.current) {
|
|
166
171
|
state.selectDate(date);
|
|
167
172
|
state.setFocusedDate(date);
|
|
173
|
+
state.setFocused(true);
|
|
168
174
|
}
|
|
169
175
|
if ('anchorDate' in state) {
|
|
170
176
|
if (isRangeBoundaryPressed.current) // When clicking on the start or end date of an already selected range,
|
|
@@ -175,6 +181,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
175
181
|
// When releasing a drag or pressing the end date of a range, select it.
|
|
176
182
|
state.selectDate(date);
|
|
177
183
|
state.setFocusedDate(date);
|
|
184
|
+
state.setFocused(true);
|
|
178
185
|
} else if (e.pointerType === 'keyboard' && !state.anchorDate) {
|
|
179
186
|
// For range selection, auto-advance the focused date by one if using keyboard.
|
|
180
187
|
// This gives an indication that you're selecting a range rather than a single date.
|
|
@@ -187,11 +194,15 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
187
194
|
if (state.isInvalid(nextDay)) nextDay = date.subtract({
|
|
188
195
|
days: 1
|
|
189
196
|
});
|
|
190
|
-
if (!state.isInvalid(nextDay))
|
|
197
|
+
if (!state.isInvalid(nextDay)) {
|
|
198
|
+
state.setFocusedDate(nextDay);
|
|
199
|
+
state.setFocused(true);
|
|
200
|
+
}
|
|
191
201
|
} else if (e.pointerType === 'virtual') {
|
|
192
202
|
// For screen readers, just select the date on click.
|
|
193
203
|
state.selectDate(date);
|
|
194
204
|
state.setFocusedDate(date);
|
|
205
|
+
state.setFocused(true);
|
|
195
206
|
}
|
|
196
207
|
}
|
|
197
208
|
}
|
|
@@ -209,7 +220,7 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
209
220
|
// Also only scroll into view if the cell actually got focused.
|
|
210
221
|
// There are some cases where the cell might be disabled or inside,
|
|
211
222
|
// an inert container and we don't want to scroll then.
|
|
212
|
-
if ((0, $cuS6T$reactariainteractions.getInteractionModality)() !== 'pointer' &&
|
|
223
|
+
if ((0, $cuS6T$reactariainteractions.getInteractionModality)() !== 'pointer' && (0, $cuS6T$reactariautils.getActiveElement)() === ref.current) (0, $cuS6T$reactariautils.scrollIntoViewport)(ref.current, {
|
|
213
224
|
containingElement: (0, $cuS6T$reactariautils.getScrollParent)(ref.current)
|
|
214
225
|
});
|
|
215
226
|
}
|
|
@@ -235,7 +246,10 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
235
246
|
},
|
|
236
247
|
buttonProps: (0, $cuS6T$reactariautils.mergeProps)(pressProps, {
|
|
237
248
|
onFocus () {
|
|
238
|
-
if (!isDisabled)
|
|
249
|
+
if (!isDisabled) {
|
|
250
|
+
state.setFocusedDate(date);
|
|
251
|
+
state.setFocused(true);
|
|
252
|
+
}
|
|
239
253
|
},
|
|
240
254
|
tabIndex: tabIndex,
|
|
241
255
|
role: 'button',
|
|
@@ -254,7 +268,12 @@ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
|
|
|
254
268
|
// This is necessary on touch devices to allow dragging
|
|
255
269
|
// outside the original pressed element.
|
|
256
270
|
// (JSDOM does not support this)
|
|
257
|
-
|
|
271
|
+
let target = (0, $cuS6T$reactariautils.getEventTarget)(e);
|
|
272
|
+
if (target instanceof HTMLElement && 'releasePointerCapture' in target) {
|
|
273
|
+
if ('hasPointerCapture' in target) {
|
|
274
|
+
if (target.hasPointerCapture(e.pointerId)) target.releasePointerCapture(e.pointerId);
|
|
275
|
+
} else target.releasePointerCapture(e.pointerId);
|
|
276
|
+
}
|
|
258
277
|
},
|
|
259
278
|
onContextMenu (e) {
|
|
260
279
|
// Prevent context menu on long press.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAqEM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC,EAAE,GAAkC;IACzI,IAAI,QAAC,IAAI,cAAE,UAAU,EAAC,GAAG;IACzB,IAAI,kBAAC,cAAc,2BAAE,uBAAuB,EAAC,GAAG,CAAA,GAAA,kCAAO,EAAE,GAAG,CAAC;IAC7D,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,gBAAgB,CAAA,GAAA,qCAAe,EAAE;QACnC,SAAS;QACT,KAAK;QACL,OAAO;QACP,MAAM;QACN,KAAK,CAAA,GAAA,sCAAW,EAAE;QAClB,UAAU,MAAM,QAAQ;IAC1B;IACA,IAAI,aAAa,MAAM,UAAU,CAAC;IAClC,IAAI,YAAY,MAAM,aAAa,CAAC,SAAS,CAAC,MAAM,cAAc;IAClE,aAAa,cAAc,MAAM,cAAc,CAAC;IAChD,IAAI,gBAAgB,MAAM,iBAAiB,CAAC;I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cesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';\nimport {getEraFormat, hookData} from './utils';\nimport {getInteractionModality, usePress} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface AriaCalendarCellProps {\n /** The date that this cell represents. */\n date: CalendarDate,\n /**\n * Whether the cell is disabled. By default, this is determined by the\n * Calendar's `minValue`, `maxValue`, and `isDisabled` props.\n */\n isDisabled?: boolean,\n\n /**\n * Whether the cell is outside of the current month.\n */\n isOutsideMonth?: boolean\n}\n\nexport interface CalendarCellAria {\n /** Props for the grid cell element (e.g. `<td>`). */\n cellProps: DOMAttributes,\n /** Props for the button element within the cell. */\n buttonProps: DOMAttributes,\n /** Whether the cell is currently being pressed. */\n isPressed: boolean,\n /** Whether the cell is selected. */\n isSelected: boolean,\n /** Whether the cell is focused. */\n isFocused: boolean,\n /**\n * Whether the cell is disabled, according to the calendar's `minValue`, `maxValue`, and `isDisabled` props.\n * Disabled dates are not focusable, and cannot be selected by the user. They are typically\n * displayed with a dimmed appearance.\n */\n isDisabled: boolean,\n /**\n * Whether the cell is unavailable, according to the calendar's `isDateUnavailable` prop. Unavailable dates remain\n * focusable, but cannot be selected by the user. They should be displayed with a visual affordance to indicate they\n * are unavailable, such as a different color or a strikethrough.\n *\n * Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio,\n * [as defined by WCAG](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).\n */\n isUnavailable: boolean,\n /**\n * Whether the cell is outside the visible range of the calendar.\n * For example, dates before the first day of a month in the same week.\n */\n isOutsideVisibleRange: boolean,\n /** Whether the cell is part of an invalid selection. */\n isInvalid: boolean,\n /** The day number formatted according to the current locale. */\n formattedDate: string\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar cell component.\n * A calendar cell displays a date cell within a calendar grid which can be selected by the user.\n */\nexport function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement | null>): CalendarCellAria {\n let {date, isDisabled} = props;\n let {errorMessageId, selectedDateDescription} = hookData.get(state)!;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n era: getEraFormat(date),\n timeZone: state.timeZone\n });\n let isSelected = state.isSelected(date);\n let isFocused = state.isCellFocused(date) && !props.isOutsideMonth;\n isDisabled = isDisabled || state.isCellDisabled(date);\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isInvalid = state.isValueInvalid && Boolean(\n 'highlightedRange' in state\n ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0\n : state.value && isSameDay(state.value, date)\n );\n\n if (isInvalid) {\n isSelected = true;\n }\n\n // For performance, reuse the same date object as before if the new date prop is the same.\n // This allows subsequent useMemo results to be reused.\n date = useDeepMemo<CalendarDate>(date, isEqualDay);\n let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);\n\n // aria-label should be localize Day of week, Month, Day and Year without Time.\n let isDateToday = isToday(date, state.timeZone);\n let label = useMemo(() => {\n let label = '';\n\n // If this is a range calendar, add a description of the full selected range\n // to the first and last selected date.\n if (\n 'highlightedRange' in state &&\n state.value &&\n !state.anchorDate &&\n (isSameDay(date, state.value.start) || isSameDay(date, state.value.end))\n ) {\n label = selectedDateDescription + ', ';\n }\n\n label += dateFormatter.format(nativeDate);\n if (isDateToday) {\n // If date is today, set appropriate string depending on selected state:\n label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {\n date: label\n });\n } else if (isSelected) {\n // If date is selected but not today:\n label = stringFormatter.format('dateSelected', {\n date: label\n });\n }\n\n if (state.minValue && isSameDay(date, state.minValue)) {\n label += ', ' + stringFormatter.format('minimumDate');\n } else if (state.maxValue && isSameDay(date, state.maxValue)) {\n label += ', ' + stringFormatter.format('maximumDate');\n }\n\n return label;\n }, [dateFormatter, nativeDate, stringFormatter, isSelected, isDateToday, date, state, selectedDateDescription]);\n\n // When a cell is focused and this is a range calendar, add a prompt to help\n // screenreader users know that they are in a range selection mode.\n let rangeSelectionPrompt = '';\n if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {\n // If selection has started add \"click to finish selecting range\"\n if (state.anchorDate) {\n rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');\n // Otherwise, add \"click to start selecting range\" prompt\n } else {\n rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');\n }\n }\n\n let descriptionProps = useDescription(rangeSelectionPrompt);\n\n let isAnchorPressed = useRef(false);\n let isRangeBoundaryPressed = useRef(false);\n let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let {pressProps, isPressed} = usePress({\n // When dragging to select a range, we don't want dragging over the original anchor\n // again to trigger onPressStart. Cancel presses immediately when the pointer exits.\n shouldCancelOnPointerExit: 'anchorDate' in state && !!state.anchorDate,\n preventFocusOnPress: true,\n isDisabled: !isSelectable || state.isReadOnly,\n onPressStart(e) {\n if (state.isReadOnly) {\n state.setFocusedDate(date);\n return;\n }\n\n if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {\n // Allow dragging the start or end date of a range to modify it\n // rather than starting a new selection.\n // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges\n // are constrained to available dates. The user will need to select a new range in this case.\n if (state.highlightedRange && !isInvalid) {\n if (isSameDay(date, state.highlightedRange.start)) {\n state.setAnchorDate(state.highlightedRange.end);\n state.setFocusedDate(date);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n } else if (isSameDay(date, state.highlightedRange.end)) {\n state.setAnchorDate(state.highlightedRange.start);\n state.setFocusedDate(date);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n }\n }\n\n let startDragging = () => {\n state.setDragging(true);\n touchDragTimerRef.current = undefined;\n\n state.selectDate(date);\n state.setFocusedDate(date);\n isAnchorPressed.current = true;\n };\n\n // Start selection on mouse/touch down so users can drag to select a range.\n // On touch, delay dragging to determine if the user really meant to scroll.\n if (e.pointerType === 'touch') {\n touchDragTimerRef.current = setTimeout(startDragging, 200);\n } else {\n startDragging();\n }\n }\n },\n onPressEnd() {\n isRangeBoundaryPressed.current = false;\n isAnchorPressed.current = false;\n clearTimeout(touchDragTimerRef.current);\n touchDragTimerRef.current = undefined;\n },\n onPress() {\n // For non-range selection, always select on press up.\n if (!('anchorDate' in state) && !state.isReadOnly) {\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n },\n onPressUp(e) {\n if (state.isReadOnly) {\n return;\n }\n\n // If the user tapped quickly, the date won't be selected yet and the\n // timer will still be in progress. In this case, select the date on touch up.\n // Timer is cleared in onPressEnd.\n if ('anchorDate' in state && touchDragTimerRef.current) {\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n\n if ('anchorDate' in state) {\n if (isRangeBoundaryPressed.current) {\n // When clicking on the start or end date of an already selected range,\n // start a new selection on press up to also allow dragging the date to\n // change the existing range.\n state.setAnchorDate(date);\n } else if (state.anchorDate && !isAnchorPressed.current) {\n // When releasing a drag or pressing the end date of a range, select it.\n state.selectDate(date);\n state.setFocusedDate(date);\n } else if (e.pointerType === 'keyboard' && !state.anchorDate) {\n // For range selection, auto-advance the focused date by one if using keyboard.\n // This gives an indication that you're selecting a range rather than a single date.\n // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,\n // there will be an announcement to \"click to finish selecting range\" (above).\n state.selectDate(date);\n let nextDay = date.add({days: 1});\n if (state.isInvalid(nextDay)) {\n nextDay = date.subtract({days: 1});\n }\n if (!state.isInvalid(nextDay)) {\n state.setFocusedDate(nextDay);\n }\n } else if (e.pointerType === 'virtual') {\n // For screen readers, just select the date on click.\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n }\n }\n });\n\n let tabIndex: number | undefined = undefined;\n if (!isDisabled) {\n tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;\n }\n\n // Focus the button in the DOM when the state updates.\n useEffect(() => {\n if (isFocused && ref.current) {\n focusWithoutScrolling(ref.current);\n\n // Scroll into view if navigating with a keyboard, otherwise\n // try not to shift the view under the user's mouse/finger.\n // If in a overlay, scrollIntoViewport will only cause scrolling\n // up to the overlay scroll body to prevent overlay shifting.\n // Also only scroll into view if the cell actually got focused.\n // There are some cases where the cell might be disabled or inside,\n // an inert container and we don't want to scroll then.\n if (getInteractionModality() !== 'pointer' && document.activeElement === ref.current) {\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n }\n }\n }, [isFocused, ref]);\n\n let cellDateFormatter = useDateFormatter({\n day: 'numeric',\n timeZone: state.timeZone,\n calendar: date.calendar.identifier\n });\n\n let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value, [cellDateFormatter, nativeDate]);\n\n return {\n cellProps: {\n role: 'gridcell',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-selected': isSelected || undefined,\n 'aria-invalid': isInvalid || undefined\n },\n buttonProps: mergeProps(pressProps, {\n onFocus() {\n if (!isDisabled) {\n state.setFocusedDate(date);\n }\n },\n tabIndex,\n role: 'button',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-label': label,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': [\n isInvalid ? errorMessageId : undefined,\n descriptionProps['aria-describedby']\n ].filter(Boolean).join(' ') || undefined,\n onPointerEnter(e) {\n // Highlight the date on hover or drag over a date when selecting a range.\n if ('highlightDate' in state && (e.pointerType !== 'touch' || state.isDragging) && isSelectable) {\n state.highlightDate(date);\n }\n },\n onPointerDown(e) {\n // This is necessary on touch devices to allow dragging\n // outside the original pressed element.\n // (JSDOM does not support this)\n if ('releasePointerCapture' in e.target) {\n e.target.releasePointerCapture(e.pointerId);\n }\n },\n onContextMenu(e) {\n // Prevent context menu on long press.\n e.preventDefault();\n }\n }),\n isPressed,\n isFocused,\n isSelected,\n isDisabled,\n isUnavailable,\n isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,\n isInvalid,\n formattedDate\n };\n}\n"],"names":[],"version":3,"file":"useCalendarCell.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAqEM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC,EAAE,GAAkC;IACzI,IAAI,QAAC,IAAI,cAAE,UAAU,EAAC,GAAG;IACzB,IAAI,kBAAC,cAAc,2BAAE,uBAAuB,EAAC,GAAG,CAAA,GAAA,kCAAO,EAAE,GAAG,CAAC;IAC7D,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,gBAAgB,CAAA,GAAA,qCAAe,EAAE;QACnC,SAAS;QACT,KAAK;QACL,OAAO;QACP,MAAM;QACN,KAAK,CAAA,GAAA,sCAAW,EAAE;QAClB,UAAU,MAAM,QAAQ;IAC1B;IACA,IAAI,aAAa,MAAM,UAAU,CAAC;IAClC,IAAI,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AAe;gBAC3B,uDAAuD;gBACvD,wCAAwC;gBACxC,gCAAgC;gBAChC,IAAI,SAAS,CAAA,GAAA,oCAAa,EAAE;gBAC5B,IAAI,kBAAkB,eAAe,2BAA2B,QAAQ;oBACtE,IAAI,uBAAuB,QACzB;wBAAA,IAAI,OAAO,iBAAiB,CAAC,EAAE,SAAS,GACtC,OAAO,qBAAqB,CAAC,EAAE,SAAS;oBAC1C,OAEA,AAAC,OAAuB,qBAAqB,CAAC,EAAE,SAAS;gBAE7D;YACF;YACA,eAAc,CAAC;gBACb,sCAAsC;gBACtC,EAAE,cAAc;YAClB;QACF;mBACA;mBACA;oBACA;oBACA;uBACA;QACA,uBAAuB,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,IAAI;mBAC5G;uBACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarCell.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getActiveElement, getEventTarget, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';\nimport {getEraFormat, hookData} from './utils';\nimport {getInteractionModality, usePress} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface AriaCalendarCellProps {\n /** The date that this cell represents. */\n date: CalendarDate,\n /**\n * Whether the cell is disabled. By default, this is determined by the\n * Calendar's `minValue`, `maxValue`, and `isDisabled` props.\n */\n isDisabled?: boolean,\n\n /**\n * Whether the cell is outside of the current month.\n */\n isOutsideMonth?: boolean\n}\n\nexport interface CalendarCellAria {\n /** Props for the grid cell element (e.g. `<td>`). */\n cellProps: DOMAttributes,\n /** Props for the button element within the cell. */\n buttonProps: DOMAttributes,\n /** Whether the cell is currently being pressed. */\n isPressed: boolean,\n /** Whether the cell is selected. */\n isSelected: boolean,\n /** Whether the cell is focused. */\n isFocused: boolean,\n /**\n * Whether the cell is disabled, according to the calendar's `minValue`, `maxValue`, and `isDisabled` props.\n * Disabled dates are not focusable, and cannot be selected by the user. They are typically\n * displayed with a dimmed appearance.\n */\n isDisabled: boolean,\n /**\n * Whether the cell is unavailable, according to the calendar's `isDateUnavailable` prop. Unavailable dates remain\n * focusable, but cannot be selected by the user. They should be displayed with a visual affordance to indicate they\n * are unavailable, such as a different color or a strikethrough.\n *\n * Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio,\n * [as defined by WCAG](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).\n */\n isUnavailable: boolean,\n /**\n * Whether the cell is outside the visible range of the calendar.\n * For example, dates before the first day of a month in the same week.\n */\n isOutsideVisibleRange: boolean,\n /** Whether the cell is part of an invalid selection. */\n isInvalid: boolean,\n /** The day number formatted according to the current locale. */\n formattedDate: string\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar cell component.\n * A calendar cell displays a date cell within a calendar grid which can be selected by the user.\n */\nexport function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement | null>): CalendarCellAria {\n let {date, isDisabled} = props;\n let {errorMessageId, selectedDateDescription} = hookData.get(state)!;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n era: getEraFormat(date),\n timeZone: state.timeZone\n });\n let isSelected = state.isSelected(date);\n let isFocused = state.isCellFocused(date) && !props.isOutsideMonth;\n isDisabled = isDisabled || state.isCellDisabled(date);\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isInvalid = state.isValueInvalid && Boolean(\n 'highlightedRange' in state\n ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0\n : state.value && isSameDay(state.value, date)\n );\n\n if (isInvalid) {\n isSelected = true;\n }\n\n // For performance, reuse the same date object as before if the new date prop is the same.\n // This allows subsequent useMemo results to be reused.\n date = useDeepMemo<CalendarDate>(date, isEqualDay);\n let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);\n\n // aria-label should be localize Day of week, Month, Day and Year without Time.\n let isDateToday = isToday(date, state.timeZone);\n let label = useMemo(() => {\n let label = '';\n\n // If this is a range calendar, add a description of the full selected range\n // to the first and last selected date.\n if (\n 'highlightedRange' in state &&\n state.value &&\n !state.anchorDate &&\n (isSameDay(date, state.value.start) || isSameDay(date, state.value.end))\n ) {\n label = selectedDateDescription + ', ';\n }\n\n label += dateFormatter.format(nativeDate);\n if (isDateToday) {\n // If date is today, set appropriate string depending on selected state:\n label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {\n date: label\n });\n } else if (isSelected) {\n // If date is selected but not today:\n label = stringFormatter.format('dateSelected', {\n date: label\n });\n }\n\n if (state.minValue && isSameDay(date, state.minValue)) {\n label += ', ' + stringFormatter.format('minimumDate');\n } else if (state.maxValue && isSameDay(date, state.maxValue)) {\n label += ', ' + stringFormatter.format('maximumDate');\n }\n\n return label;\n }, [dateFormatter, nativeDate, stringFormatter, isSelected, isDateToday, date, state, selectedDateDescription]);\n\n // When a cell is focused and this is a range calendar, add a prompt to help\n // screenreader users know that they are in a range selection mode.\n let rangeSelectionPrompt = '';\n if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {\n // If selection has started add \"click to finish selecting range\"\n if (state.anchorDate) {\n rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');\n // Otherwise, add \"click to start selecting range\" prompt\n } else {\n rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');\n }\n }\n\n let descriptionProps = useDescription(rangeSelectionPrompt);\n\n let isAnchorPressed = useRef(false);\n let isRangeBoundaryPressed = useRef(false);\n let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let {pressProps, isPressed} = usePress({\n // When dragging to select a range, we don't want dragging over the original anchor\n // again to trigger onPressStart. Cancel presses immediately when the pointer exits.\n shouldCancelOnPointerExit: 'anchorDate' in state && !!state.anchorDate,\n preventFocusOnPress: true,\n isDisabled: !isSelectable || state.isReadOnly,\n onPressStart(e) {\n if (state.isReadOnly) {\n state.setFocusedDate(date);\n state.setFocused(true);\n return;\n }\n\n if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {\n // Allow dragging the start or end date of a range to modify it\n // rather than starting a new selection.\n // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges\n // are constrained to available dates. The user will need to select a new range in this case.\n if (state.highlightedRange && !isInvalid) {\n if (isSameDay(date, state.highlightedRange.start)) {\n state.setAnchorDate(state.highlightedRange.end);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n } else if (isSameDay(date, state.highlightedRange.end)) {\n state.setAnchorDate(state.highlightedRange.start);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n }\n }\n\n let startDragging = () => {\n state.setDragging(true);\n touchDragTimerRef.current = undefined;\n\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n isAnchorPressed.current = true;\n };\n\n // Start selection on mouse/touch down so users can drag to select a range.\n // On touch, delay dragging to determine if the user really meant to scroll.\n if (e.pointerType === 'touch') {\n touchDragTimerRef.current = setTimeout(startDragging, 200);\n } else {\n startDragging();\n }\n }\n },\n onPressEnd() {\n isRangeBoundaryPressed.current = false;\n isAnchorPressed.current = false;\n clearTimeout(touchDragTimerRef.current);\n touchDragTimerRef.current = undefined;\n },\n onPress() {\n // For non-range selection, always select on press up.\n if (!('anchorDate' in state) && !state.isReadOnly) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n onPressUp(e) {\n if (state.isReadOnly) {\n return;\n }\n\n // If the user tapped quickly, the date won't be selected yet and the\n // timer will still be in progress. In this case, select the date on touch up.\n // Timer is cleared in onPressEnd.\n if ('anchorDate' in state && touchDragTimerRef.current) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n\n if ('anchorDate' in state) {\n if (isRangeBoundaryPressed.current) {\n // When clicking on the start or end date of an already selected range,\n // start a new selection on press up to also allow dragging the date to\n // change the existing range.\n state.setAnchorDate(date);\n } else if (state.anchorDate && !isAnchorPressed.current) {\n // When releasing a drag or pressing the end date of a range, select it.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n } else if (e.pointerType === 'keyboard' && !state.anchorDate) {\n // For range selection, auto-advance the focused date by one if using keyboard.\n // This gives an indication that you're selecting a range rather than a single date.\n // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,\n // there will be an announcement to \"click to finish selecting range\" (above).\n state.selectDate(date);\n let nextDay = date.add({days: 1});\n if (state.isInvalid(nextDay)) {\n nextDay = date.subtract({days: 1});\n }\n if (!state.isInvalid(nextDay)) {\n state.setFocusedDate(nextDay);\n state.setFocused(true);\n }\n } else if (e.pointerType === 'virtual') {\n // For screen readers, just select the date on click.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n }\n }\n });\n\n let tabIndex: number | undefined = undefined;\n if (!isDisabled) {\n tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;\n }\n\n // Focus the button in the DOM when the state updates.\n useEffect(() => {\n if (isFocused && ref.current) {\n focusWithoutScrolling(ref.current);\n\n // Scroll into view if navigating with a keyboard, otherwise\n // try not to shift the view under the user's mouse/finger.\n // If in a overlay, scrollIntoViewport will only cause scrolling\n // up to the overlay scroll body to prevent overlay shifting.\n // Also only scroll into view if the cell actually got focused.\n // There are some cases where the cell might be disabled or inside,\n // an inert container and we don't want to scroll then.\n if (getInteractionModality() !== 'pointer' && getActiveElement() === ref.current) {\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n }\n }\n }, [isFocused, ref]);\n\n let cellDateFormatter = useDateFormatter({\n day: 'numeric',\n timeZone: state.timeZone,\n calendar: date.calendar.identifier\n });\n\n let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value, [cellDateFormatter, nativeDate]);\n\n return {\n cellProps: {\n role: 'gridcell',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-selected': isSelected || undefined,\n 'aria-invalid': isInvalid || undefined\n },\n buttonProps: mergeProps(pressProps, {\n onFocus() {\n if (!isDisabled) {\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n tabIndex,\n role: 'button',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-label': label,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': [\n isInvalid ? errorMessageId : undefined,\n descriptionProps['aria-describedby']\n ].filter(Boolean).join(' ') || undefined,\n onPointerEnter(e) {\n // Highlight the date on hover or drag over a date when selecting a range.\n if ('highlightDate' in state && (e.pointerType !== 'touch' || state.isDragging) && isSelectable) {\n state.highlightDate(date);\n }\n },\n onPointerDown(e: PointerEvent) {\n // This is necessary on touch devices to allow dragging\n // outside the original pressed element.\n // (JSDOM does not support this)\n let target = getEventTarget(e);\n if (target instanceof HTMLElement && 'releasePointerCapture' in target) {\n if ('hasPointerCapture' in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n (target as HTMLElement).releasePointerCapture(e.pointerId);\n }\n }\n },\n onContextMenu(e) {\n // Prevent context menu on long press.\n e.preventDefault();\n }\n }),\n isPressed,\n isFocused,\n isSelected,\n isDisabled,\n isUnavailable,\n isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,\n isInvalid,\n formattedDate\n };\n}\n"],"names":[],"version":3,"file":"useCalendarCell.main.js.map"}
|
package/dist/useCalendarCell.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {getEraFormat as $a074e1e2d0f0a665$export$134cbb7fb09a9522, hookData as $a074e1e2d0f0a665$export$653eddfc964b0f8a} from "./utils.mjs";
|
|
2
2
|
import $dm6hl$intlStringsmodulejs from "./intlStrings.mjs";
|
|
3
3
|
import {isSameDay as $dm6hl$isSameDay, isEqualDay as $dm6hl$isEqualDay, isToday as $dm6hl$isToday} from "@internationalized/date";
|
|
4
|
-
import {useDeepMemo as $dm6hl$useDeepMemo, useDescription as $dm6hl$useDescription, focusWithoutScrolling as $dm6hl$focusWithoutScrolling, scrollIntoViewport as $dm6hl$scrollIntoViewport, getScrollParent as $dm6hl$getScrollParent, mergeProps as $dm6hl$mergeProps} from "@react-aria/utils";
|
|
4
|
+
import {useDeepMemo as $dm6hl$useDeepMemo, useDescription as $dm6hl$useDescription, focusWithoutScrolling as $dm6hl$focusWithoutScrolling, getActiveElement as $dm6hl$getActiveElement, scrollIntoViewport as $dm6hl$scrollIntoViewport, getScrollParent as $dm6hl$getScrollParent, mergeProps as $dm6hl$mergeProps, getEventTarget as $dm6hl$getEventTarget} from "@react-aria/utils";
|
|
5
5
|
import {usePress as $dm6hl$usePress, getInteractionModality as $dm6hl$getInteractionModality} from "@react-aria/interactions";
|
|
6
6
|
import {useLocalizedStringFormatter as $dm6hl$useLocalizedStringFormatter, useDateFormatter as $dm6hl$useDateFormatter} from "@react-aria/i18n";
|
|
7
7
|
import {useMemo as $dm6hl$useMemo, useRef as $dm6hl$useRef, useEffect as $dm6hl$useEffect} from "react";
|
|
@@ -103,6 +103,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
103
103
|
onPressStart (e) {
|
|
104
104
|
if (state.isReadOnly) {
|
|
105
105
|
state.setFocusedDate(date);
|
|
106
|
+
state.setFocused(true);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {
|
|
@@ -114,12 +115,14 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
114
115
|
if ((0, $dm6hl$isSameDay)(date, state.highlightedRange.start)) {
|
|
115
116
|
state.setAnchorDate(state.highlightedRange.end);
|
|
116
117
|
state.setFocusedDate(date);
|
|
118
|
+
state.setFocused(true);
|
|
117
119
|
state.setDragging(true);
|
|
118
120
|
isRangeBoundaryPressed.current = true;
|
|
119
121
|
return;
|
|
120
122
|
} else if ((0, $dm6hl$isSameDay)(date, state.highlightedRange.end)) {
|
|
121
123
|
state.setAnchorDate(state.highlightedRange.start);
|
|
122
124
|
state.setFocusedDate(date);
|
|
125
|
+
state.setFocused(true);
|
|
123
126
|
state.setDragging(true);
|
|
124
127
|
isRangeBoundaryPressed.current = true;
|
|
125
128
|
return;
|
|
@@ -130,6 +133,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
130
133
|
touchDragTimerRef.current = undefined;
|
|
131
134
|
state.selectDate(date);
|
|
132
135
|
state.setFocusedDate(date);
|
|
136
|
+
state.setFocused(true);
|
|
133
137
|
isAnchorPressed.current = true;
|
|
134
138
|
};
|
|
135
139
|
// Start selection on mouse/touch down so users can drag to select a range.
|
|
@@ -149,6 +153,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
149
153
|
if (!('anchorDate' in state) && !state.isReadOnly) {
|
|
150
154
|
state.selectDate(date);
|
|
151
155
|
state.setFocusedDate(date);
|
|
156
|
+
state.setFocused(true);
|
|
152
157
|
}
|
|
153
158
|
},
|
|
154
159
|
onPressUp (e) {
|
|
@@ -159,6 +164,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
159
164
|
if ('anchorDate' in state && touchDragTimerRef.current) {
|
|
160
165
|
state.selectDate(date);
|
|
161
166
|
state.setFocusedDate(date);
|
|
167
|
+
state.setFocused(true);
|
|
162
168
|
}
|
|
163
169
|
if ('anchorDate' in state) {
|
|
164
170
|
if (isRangeBoundaryPressed.current) // When clicking on the start or end date of an already selected range,
|
|
@@ -169,6 +175,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
169
175
|
// When releasing a drag or pressing the end date of a range, select it.
|
|
170
176
|
state.selectDate(date);
|
|
171
177
|
state.setFocusedDate(date);
|
|
178
|
+
state.setFocused(true);
|
|
172
179
|
} else if (e.pointerType === 'keyboard' && !state.anchorDate) {
|
|
173
180
|
// For range selection, auto-advance the focused date by one if using keyboard.
|
|
174
181
|
// This gives an indication that you're selecting a range rather than a single date.
|
|
@@ -181,11 +188,15 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
181
188
|
if (state.isInvalid(nextDay)) nextDay = date.subtract({
|
|
182
189
|
days: 1
|
|
183
190
|
});
|
|
184
|
-
if (!state.isInvalid(nextDay))
|
|
191
|
+
if (!state.isInvalid(nextDay)) {
|
|
192
|
+
state.setFocusedDate(nextDay);
|
|
193
|
+
state.setFocused(true);
|
|
194
|
+
}
|
|
185
195
|
} else if (e.pointerType === 'virtual') {
|
|
186
196
|
// For screen readers, just select the date on click.
|
|
187
197
|
state.selectDate(date);
|
|
188
198
|
state.setFocusedDate(date);
|
|
199
|
+
state.setFocused(true);
|
|
189
200
|
}
|
|
190
201
|
}
|
|
191
202
|
}
|
|
@@ -203,7 +214,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
203
214
|
// Also only scroll into view if the cell actually got focused.
|
|
204
215
|
// There are some cases where the cell might be disabled or inside,
|
|
205
216
|
// an inert container and we don't want to scroll then.
|
|
206
|
-
if ((0, $dm6hl$getInteractionModality)() !== 'pointer' &&
|
|
217
|
+
if ((0, $dm6hl$getInteractionModality)() !== 'pointer' && (0, $dm6hl$getActiveElement)() === ref.current) (0, $dm6hl$scrollIntoViewport)(ref.current, {
|
|
207
218
|
containingElement: (0, $dm6hl$getScrollParent)(ref.current)
|
|
208
219
|
});
|
|
209
220
|
}
|
|
@@ -229,7 +240,10 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
229
240
|
},
|
|
230
241
|
buttonProps: (0, $dm6hl$mergeProps)(pressProps, {
|
|
231
242
|
onFocus () {
|
|
232
|
-
if (!isDisabled)
|
|
243
|
+
if (!isDisabled) {
|
|
244
|
+
state.setFocusedDate(date);
|
|
245
|
+
state.setFocused(true);
|
|
246
|
+
}
|
|
233
247
|
},
|
|
234
248
|
tabIndex: tabIndex,
|
|
235
249
|
role: 'button',
|
|
@@ -248,7 +262,12 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
248
262
|
// This is necessary on touch devices to allow dragging
|
|
249
263
|
// outside the original pressed element.
|
|
250
264
|
// (JSDOM does not support this)
|
|
251
|
-
|
|
265
|
+
let target = (0, $dm6hl$getEventTarget)(e);
|
|
266
|
+
if (target instanceof HTMLElement && 'releasePointerCapture' in target) {
|
|
267
|
+
if ('hasPointerCapture' in target) {
|
|
268
|
+
if (target.hasPointerCapture(e.pointerId)) target.releasePointerCapture(e.pointerId);
|
|
269
|
+
} else target.releasePointerCapture(e.pointerId);
|
|
270
|
+
}
|
|
252
271
|
},
|
|
253
272
|
onContextMenu (e) {
|
|
254
273
|
// Prevent context menu on long press.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {getEraFormat as $a074e1e2d0f0a665$export$134cbb7fb09a9522, hookData as $a074e1e2d0f0a665$export$653eddfc964b0f8a} from "./utils.module.js";
|
|
2
2
|
import $dm6hl$intlStringsmodulejs from "./intlStrings.module.js";
|
|
3
3
|
import {isSameDay as $dm6hl$isSameDay, isEqualDay as $dm6hl$isEqualDay, isToday as $dm6hl$isToday} from "@internationalized/date";
|
|
4
|
-
import {useDeepMemo as $dm6hl$useDeepMemo, useDescription as $dm6hl$useDescription, focusWithoutScrolling as $dm6hl$focusWithoutScrolling, scrollIntoViewport as $dm6hl$scrollIntoViewport, getScrollParent as $dm6hl$getScrollParent, mergeProps as $dm6hl$mergeProps} from "@react-aria/utils";
|
|
4
|
+
import {useDeepMemo as $dm6hl$useDeepMemo, useDescription as $dm6hl$useDescription, focusWithoutScrolling as $dm6hl$focusWithoutScrolling, getActiveElement as $dm6hl$getActiveElement, scrollIntoViewport as $dm6hl$scrollIntoViewport, getScrollParent as $dm6hl$getScrollParent, mergeProps as $dm6hl$mergeProps, getEventTarget as $dm6hl$getEventTarget} from "@react-aria/utils";
|
|
5
5
|
import {usePress as $dm6hl$usePress, getInteractionModality as $dm6hl$getInteractionModality} from "@react-aria/interactions";
|
|
6
6
|
import {useLocalizedStringFormatter as $dm6hl$useLocalizedStringFormatter, useDateFormatter as $dm6hl$useDateFormatter} from "@react-aria/i18n";
|
|
7
7
|
import {useMemo as $dm6hl$useMemo, useRef as $dm6hl$useRef, useEffect as $dm6hl$useEffect} from "react";
|
|
@@ -103,6 +103,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
103
103
|
onPressStart (e) {
|
|
104
104
|
if (state.isReadOnly) {
|
|
105
105
|
state.setFocusedDate(date);
|
|
106
|
+
state.setFocused(true);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {
|
|
@@ -114,12 +115,14 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
114
115
|
if ((0, $dm6hl$isSameDay)(date, state.highlightedRange.start)) {
|
|
115
116
|
state.setAnchorDate(state.highlightedRange.end);
|
|
116
117
|
state.setFocusedDate(date);
|
|
118
|
+
state.setFocused(true);
|
|
117
119
|
state.setDragging(true);
|
|
118
120
|
isRangeBoundaryPressed.current = true;
|
|
119
121
|
return;
|
|
120
122
|
} else if ((0, $dm6hl$isSameDay)(date, state.highlightedRange.end)) {
|
|
121
123
|
state.setAnchorDate(state.highlightedRange.start);
|
|
122
124
|
state.setFocusedDate(date);
|
|
125
|
+
state.setFocused(true);
|
|
123
126
|
state.setDragging(true);
|
|
124
127
|
isRangeBoundaryPressed.current = true;
|
|
125
128
|
return;
|
|
@@ -130,6 +133,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
130
133
|
touchDragTimerRef.current = undefined;
|
|
131
134
|
state.selectDate(date);
|
|
132
135
|
state.setFocusedDate(date);
|
|
136
|
+
state.setFocused(true);
|
|
133
137
|
isAnchorPressed.current = true;
|
|
134
138
|
};
|
|
135
139
|
// Start selection on mouse/touch down so users can drag to select a range.
|
|
@@ -149,6 +153,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
149
153
|
if (!('anchorDate' in state) && !state.isReadOnly) {
|
|
150
154
|
state.selectDate(date);
|
|
151
155
|
state.setFocusedDate(date);
|
|
156
|
+
state.setFocused(true);
|
|
152
157
|
}
|
|
153
158
|
},
|
|
154
159
|
onPressUp (e) {
|
|
@@ -159,6 +164,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
159
164
|
if ('anchorDate' in state && touchDragTimerRef.current) {
|
|
160
165
|
state.selectDate(date);
|
|
161
166
|
state.setFocusedDate(date);
|
|
167
|
+
state.setFocused(true);
|
|
162
168
|
}
|
|
163
169
|
if ('anchorDate' in state) {
|
|
164
170
|
if (isRangeBoundaryPressed.current) // When clicking on the start or end date of an already selected range,
|
|
@@ -169,6 +175,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
169
175
|
// When releasing a drag or pressing the end date of a range, select it.
|
|
170
176
|
state.selectDate(date);
|
|
171
177
|
state.setFocusedDate(date);
|
|
178
|
+
state.setFocused(true);
|
|
172
179
|
} else if (e.pointerType === 'keyboard' && !state.anchorDate) {
|
|
173
180
|
// For range selection, auto-advance the focused date by one if using keyboard.
|
|
174
181
|
// This gives an indication that you're selecting a range rather than a single date.
|
|
@@ -181,11 +188,15 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
181
188
|
if (state.isInvalid(nextDay)) nextDay = date.subtract({
|
|
182
189
|
days: 1
|
|
183
190
|
});
|
|
184
|
-
if (!state.isInvalid(nextDay))
|
|
191
|
+
if (!state.isInvalid(nextDay)) {
|
|
192
|
+
state.setFocusedDate(nextDay);
|
|
193
|
+
state.setFocused(true);
|
|
194
|
+
}
|
|
185
195
|
} else if (e.pointerType === 'virtual') {
|
|
186
196
|
// For screen readers, just select the date on click.
|
|
187
197
|
state.selectDate(date);
|
|
188
198
|
state.setFocusedDate(date);
|
|
199
|
+
state.setFocused(true);
|
|
189
200
|
}
|
|
190
201
|
}
|
|
191
202
|
}
|
|
@@ -203,7 +214,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
203
214
|
// Also only scroll into view if the cell actually got focused.
|
|
204
215
|
// There are some cases where the cell might be disabled or inside,
|
|
205
216
|
// an inert container and we don't want to scroll then.
|
|
206
|
-
if ((0, $dm6hl$getInteractionModality)() !== 'pointer' &&
|
|
217
|
+
if ((0, $dm6hl$getInteractionModality)() !== 'pointer' && (0, $dm6hl$getActiveElement)() === ref.current) (0, $dm6hl$scrollIntoViewport)(ref.current, {
|
|
207
218
|
containingElement: (0, $dm6hl$getScrollParent)(ref.current)
|
|
208
219
|
});
|
|
209
220
|
}
|
|
@@ -229,7 +240,10 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
229
240
|
},
|
|
230
241
|
buttonProps: (0, $dm6hl$mergeProps)(pressProps, {
|
|
231
242
|
onFocus () {
|
|
232
|
-
if (!isDisabled)
|
|
243
|
+
if (!isDisabled) {
|
|
244
|
+
state.setFocusedDate(date);
|
|
245
|
+
state.setFocused(true);
|
|
246
|
+
}
|
|
233
247
|
},
|
|
234
248
|
tabIndex: tabIndex,
|
|
235
249
|
role: 'button',
|
|
@@ -248,7 +262,12 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
|
|
|
248
262
|
// This is necessary on touch devices to allow dragging
|
|
249
263
|
// outside the original pressed element.
|
|
250
264
|
// (JSDOM does not support this)
|
|
251
|
-
|
|
265
|
+
let target = (0, $dm6hl$getEventTarget)(e);
|
|
266
|
+
if (target instanceof HTMLElement && 'releasePointerCapture' in target) {
|
|
267
|
+
if ('hasPointerCapture' in target) {
|
|
268
|
+
if (target.hasPointerCapture(e.pointerId)) target.releasePointerCapture(e.pointerId);
|
|
269
|
+
} else target.releasePointerCapture(e.pointerId);
|
|
270
|
+
}
|
|
252
271
|
},
|
|
253
272
|
onContextMenu (e) {
|
|
254
273
|
// Prevent context menu on long press.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAqEM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC,EAAE,GAAkC;IACzI,IAAI,QAAC,IAAI,cAAE,UAAU,EAAC,GAAG;IACzB,IAAI,kBAAC,cAAc,2BAAE,uBAAuB,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC;IAC7D,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,gBAAgB,CAAA,GAAA,uBAAe,EAAE;QACnC,SAAS;QACT,KAAK;QACL,OAAO;QACP,MAAM;QACN,KAAK,CAAA,GAAA,yCAAW,EAAE;QAClB,UAAU,MAAM,QAAQ;IAC1B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AK,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,IAAI;mBAC5G;uBACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarCell.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';\nimport {getEraFormat, hookData} from './utils';\nimport {getInteractionModality, usePress} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface AriaCalendarCellProps {\n /** The date that this cell represents. */\n date: CalendarDate,\n /**\n * Whether the cell is disabled. By default, this is determined by the\n * Calendar's `minValue`, `maxValue`, and `isDisabled` props.\n */\n isDisabled?: boolean,\n\n /**\n * Whether the cell is outside of the current month.\n */\n isOutsideMonth?: boolean\n}\n\nexport interface CalendarCellAria {\n /** Props for the grid cell element (e.g. `<td>`). */\n cellProps: DOMAttributes,\n /** Props for the button element within the cell. */\n buttonProps: DOMAttributes,\n /** Whether the cell is currently being pressed. */\n isPressed: boolean,\n /** Whether the cell is selected. */\n isSelected: boolean,\n /** Whether the cell is focused. */\n isFocused: boolean,\n /**\n * Whether the cell is disabled, according to the calendar's `minValue`, `maxValue`, and `isDisabled` props.\n * Disabled dates are not focusable, and cannot be selected by the user. They are typically\n * displayed with a dimmed appearance.\n */\n isDisabled: boolean,\n /**\n * Whether the cell is unavailable, according to the calendar's `isDateUnavailable` prop. Unavailable dates remain\n * focusable, but cannot be selected by the user. They should be displayed with a visual affordance to indicate they\n * are unavailable, such as a different color or a strikethrough.\n *\n * Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio,\n * [as defined by WCAG](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).\n */\n isUnavailable: boolean,\n /**\n * Whether the cell is outside the visible range of the calendar.\n * For example, dates before the first day of a month in the same week.\n */\n isOutsideVisibleRange: boolean,\n /** Whether the cell is part of an invalid selection. */\n isInvalid: boolean,\n /** The day number formatted according to the current locale. */\n formattedDate: string\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar cell component.\n * A calendar cell displays a date cell within a calendar grid which can be selected by the user.\n */\nexport function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement | null>): CalendarCellAria {\n let {date, isDisabled} = props;\n let {errorMessageId, selectedDateDescription} = hookData.get(state)!;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n era: getEraFormat(date),\n timeZone: state.timeZone\n });\n let isSelected = state.isSelected(date);\n let isFocused = state.isCellFocused(date) && !props.isOutsideMonth;\n isDisabled = isDisabled || state.isCellDisabled(date);\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isInvalid = state.isValueInvalid && Boolean(\n 'highlightedRange' in state\n ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0\n : state.value && isSameDay(state.value, date)\n );\n\n if (isInvalid) {\n isSelected = true;\n }\n\n // For performance, reuse the same date object as before if the new date prop is the same.\n // This allows subsequent useMemo results to be reused.\n date = useDeepMemo<CalendarDate>(date, isEqualDay);\n let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);\n\n // aria-label should be localize Day of week, Month, Day and Year without Time.\n let isDateToday = isToday(date, state.timeZone);\n let label = useMemo(() => {\n let label = '';\n\n // If this is a range calendar, add a description of the full selected range\n // to the first and last selected date.\n if (\n 'highlightedRange' in state &&\n state.value &&\n !state.anchorDate &&\n (isSameDay(date, state.value.start) || isSameDay(date, state.value.end))\n ) {\n label = selectedDateDescription + ', ';\n }\n\n label += dateFormatter.format(nativeDate);\n if (isDateToday) {\n // If date is today, set appropriate string depending on selected state:\n label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {\n date: label\n });\n } else if (isSelected) {\n // If date is selected but not today:\n label = stringFormatter.format('dateSelected', {\n date: label\n });\n }\n\n if (state.minValue && isSameDay(date, state.minValue)) {\n label += ', ' + stringFormatter.format('minimumDate');\n } else if (state.maxValue && isSameDay(date, state.maxValue)) {\n label += ', ' + stringFormatter.format('maximumDate');\n }\n\n return label;\n }, [dateFormatter, nativeDate, stringFormatter, isSelected, isDateToday, date, state, selectedDateDescription]);\n\n // When a cell is focused and this is a range calendar, add a prompt to help\n // screenreader users know that they are in a range selection mode.\n let rangeSelectionPrompt = '';\n if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {\n // If selection has started add \"click to finish selecting range\"\n if (state.anchorDate) {\n rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');\n // Otherwise, add \"click to start selecting range\" prompt\n } else {\n rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');\n }\n }\n\n let descriptionProps = useDescription(rangeSelectionPrompt);\n\n let isAnchorPressed = useRef(false);\n let isRangeBoundaryPressed = useRef(false);\n let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let {pressProps, isPressed} = usePress({\n // When dragging to select a range, we don't want dragging over the original anchor\n // again to trigger onPressStart. Cancel presses immediately when the pointer exits.\n shouldCancelOnPointerExit: 'anchorDate' in state && !!state.anchorDate,\n preventFocusOnPress: true,\n isDisabled: !isSelectable || state.isReadOnly,\n onPressStart(e) {\n if (state.isReadOnly) {\n state.setFocusedDate(date);\n return;\n }\n\n if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {\n // Allow dragging the start or end date of a range to modify it\n // rather than starting a new selection.\n // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges\n // are constrained to available dates. The user will need to select a new range in this case.\n if (state.highlightedRange && !isInvalid) {\n if (isSameDay(date, state.highlightedRange.start)) {\n state.setAnchorDate(state.highlightedRange.end);\n state.setFocusedDate(date);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n } else if (isSameDay(date, state.highlightedRange.end)) {\n state.setAnchorDate(state.highlightedRange.start);\n state.setFocusedDate(date);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n }\n }\n\n let startDragging = () => {\n state.setDragging(true);\n touchDragTimerRef.current = undefined;\n\n state.selectDate(date);\n state.setFocusedDate(date);\n isAnchorPressed.current = true;\n };\n\n // Start selection on mouse/touch down so users can drag to select a range.\n // On touch, delay dragging to determine if the user really meant to scroll.\n if (e.pointerType === 'touch') {\n touchDragTimerRef.current = setTimeout(startDragging, 200);\n } else {\n startDragging();\n }\n }\n },\n onPressEnd() {\n isRangeBoundaryPressed.current = false;\n isAnchorPressed.current = false;\n clearTimeout(touchDragTimerRef.current);\n touchDragTimerRef.current = undefined;\n },\n onPress() {\n // For non-range selection, always select on press up.\n if (!('anchorDate' in state) && !state.isReadOnly) {\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n },\n onPressUp(e) {\n if (state.isReadOnly) {\n return;\n }\n\n // If the user tapped quickly, the date won't be selected yet and the\n // timer will still be in progress. In this case, select the date on touch up.\n // Timer is cleared in onPressEnd.\n if ('anchorDate' in state && touchDragTimerRef.current) {\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n\n if ('anchorDate' in state) {\n if (isRangeBoundaryPressed.current) {\n // When clicking on the start or end date of an already selected range,\n // start a new selection on press up to also allow dragging the date to\n // change the existing range.\n state.setAnchorDate(date);\n } else if (state.anchorDate && !isAnchorPressed.current) {\n // When releasing a drag or pressing the end date of a range, select it.\n state.selectDate(date);\n state.setFocusedDate(date);\n } else if (e.pointerType === 'keyboard' && !state.anchorDate) {\n // For range selection, auto-advance the focused date by one if using keyboard.\n // This gives an indication that you're selecting a range rather than a single date.\n // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,\n // there will be an announcement to \"click to finish selecting range\" (above).\n state.selectDate(date);\n let nextDay = date.add({days: 1});\n if (state.isInvalid(nextDay)) {\n nextDay = date.subtract({days: 1});\n }\n if (!state.isInvalid(nextDay)) {\n state.setFocusedDate(nextDay);\n }\n } else if (e.pointerType === 'virtual') {\n // For screen readers, just select the date on click.\n state.selectDate(date);\n state.setFocusedDate(date);\n }\n }\n }\n });\n\n let tabIndex: number | undefined = undefined;\n if (!isDisabled) {\n tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;\n }\n\n // Focus the button in the DOM when the state updates.\n useEffect(() => {\n if (isFocused && ref.current) {\n focusWithoutScrolling(ref.current);\n\n // Scroll into view if navigating with a keyboard, otherwise\n // try not to shift the view under the user's mouse/finger.\n // If in a overlay, scrollIntoViewport will only cause scrolling\n // up to the overlay scroll body to prevent overlay shifting.\n // Also only scroll into view if the cell actually got focused.\n // There are some cases where the cell might be disabled or inside,\n // an inert container and we don't want to scroll then.\n if (getInteractionModality() !== 'pointer' && document.activeElement === ref.current) {\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n }\n }\n }, [isFocused, ref]);\n\n let cellDateFormatter = useDateFormatter({\n day: 'numeric',\n timeZone: state.timeZone,\n calendar: date.calendar.identifier\n });\n\n let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value, [cellDateFormatter, nativeDate]);\n\n return {\n cellProps: {\n role: 'gridcell',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-selected': isSelected || undefined,\n 'aria-invalid': isInvalid || undefined\n },\n buttonProps: mergeProps(pressProps, {\n onFocus() {\n if (!isDisabled) {\n state.setFocusedDate(date);\n }\n },\n tabIndex,\n role: 'button',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-label': label,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': [\n isInvalid ? errorMessageId : undefined,\n descriptionProps['aria-describedby']\n ].filter(Boolean).join(' ') || undefined,\n onPointerEnter(e) {\n // Highlight the date on hover or drag over a date when selecting a range.\n if ('highlightDate' in state && (e.pointerType !== 'touch' || state.isDragging) && isSelectable) {\n state.highlightDate(date);\n }\n },\n onPointerDown(e) {\n // This is necessary on touch devices to allow dragging\n // outside the original pressed element.\n // (JSDOM does not support this)\n if ('releasePointerCapture' in e.target) {\n e.target.releasePointerCapture(e.pointerId);\n }\n },\n onContextMenu(e) {\n // Prevent context menu on long press.\n e.preventDefault();\n }\n }),\n isPressed,\n isFocused,\n isSelected,\n isDisabled,\n isUnavailable,\n isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,\n isInvalid,\n formattedDate\n };\n}\n"],"names":[],"version":3,"file":"useCalendarCell.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAqEM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC,EAAE,GAAkC;IACzI,IAAI,QAAC,IAAI,cAAE,UAAU,EAAC,GAAG;IACzB,IAAI,kBAAC,cAAc,2BAAE,uBAAuB,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC;IAC7D,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,gBAAgB,CAAA,GAAA,uBAAe,EAAE;QAC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e,CAAC;gBACd,0EAA0E;gBAC1E,IAAI,mBAAmB,SAAU,CAAA,EAAE,WAAW,KAAK,WAAW,MAAM,UAAU,AAAD,KAAM,cACjF,MAAM,aAAa,CAAC;YAExB;YACA,eAAc,CAAe;gBAC3B,uDAAuD;gBACvD,wCAAwC;gBACxC,gCAAgC;gBAChC,IAAI,SAAS,CAAA,GAAA,qBAAa,EAAE;gBAC5B,IAAI,kBAAkB,eAAe,2BAA2B,QAAQ;oBACtE,IAAI,uBAAuB,QACzB;wBAAA,IAAI,OAAO,iBAAiB,CAAC,EAAE,SAAS,GACtC,OAAO,qBAAqB,CAAC,EAAE,SAAS;oBAC1C,OAEA,AAAC,OAAuB,qBAAqB,CAAC,EAAE,SAAS;gBAE7D;YACF;YACA,eAAc,CAAC;gBACb,sCAAsC;gBACtC,EAAE,cAAc;YAClB;QACF;mBACA;mBACA;oBACA;oBACA;uBACA;QACA,uBAAuB,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,IAAI;mBAC5G;uBACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarCell.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getActiveElement, getEventTarget, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';\nimport {getEraFormat, hookData} from './utils';\nimport {getInteractionModality, usePress} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface AriaCalendarCellProps {\n /** The date that this cell represents. */\n date: CalendarDate,\n /**\n * Whether the cell is disabled. By default, this is determined by the\n * Calendar's `minValue`, `maxValue`, and `isDisabled` props.\n */\n isDisabled?: boolean,\n\n /**\n * Whether the cell is outside of the current month.\n */\n isOutsideMonth?: boolean\n}\n\nexport interface CalendarCellAria {\n /** Props for the grid cell element (e.g. `<td>`). */\n cellProps: DOMAttributes,\n /** Props for the button element within the cell. */\n buttonProps: DOMAttributes,\n /** Whether the cell is currently being pressed. */\n isPressed: boolean,\n /** Whether the cell is selected. */\n isSelected: boolean,\n /** Whether the cell is focused. */\n isFocused: boolean,\n /**\n * Whether the cell is disabled, according to the calendar's `minValue`, `maxValue`, and `isDisabled` props.\n * Disabled dates are not focusable, and cannot be selected by the user. They are typically\n * displayed with a dimmed appearance.\n */\n isDisabled: boolean,\n /**\n * Whether the cell is unavailable, according to the calendar's `isDateUnavailable` prop. Unavailable dates remain\n * focusable, but cannot be selected by the user. They should be displayed with a visual affordance to indicate they\n * are unavailable, such as a different color or a strikethrough.\n *\n * Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio,\n * [as defined by WCAG](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).\n */\n isUnavailable: boolean,\n /**\n * Whether the cell is outside the visible range of the calendar.\n * For example, dates before the first day of a month in the same week.\n */\n isOutsideVisibleRange: boolean,\n /** Whether the cell is part of an invalid selection. */\n isInvalid: boolean,\n /** The day number formatted according to the current locale. */\n formattedDate: string\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar cell component.\n * A calendar cell displays a date cell within a calendar grid which can be selected by the user.\n */\nexport function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement | null>): CalendarCellAria {\n let {date, isDisabled} = props;\n let {errorMessageId, selectedDateDescription} = hookData.get(state)!;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n era: getEraFormat(date),\n timeZone: state.timeZone\n });\n let isSelected = state.isSelected(date);\n let isFocused = state.isCellFocused(date) && !props.isOutsideMonth;\n isDisabled = isDisabled || state.isCellDisabled(date);\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isInvalid = state.isValueInvalid && Boolean(\n 'highlightedRange' in state\n ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0\n : state.value && isSameDay(state.value, date)\n );\n\n if (isInvalid) {\n isSelected = true;\n }\n\n // For performance, reuse the same date object as before if the new date prop is the same.\n // This allows subsequent useMemo results to be reused.\n date = useDeepMemo<CalendarDate>(date, isEqualDay);\n let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);\n\n // aria-label should be localize Day of week, Month, Day and Year without Time.\n let isDateToday = isToday(date, state.timeZone);\n let label = useMemo(() => {\n let label = '';\n\n // If this is a range calendar, add a description of the full selected range\n // to the first and last selected date.\n if (\n 'highlightedRange' in state &&\n state.value &&\n !state.anchorDate &&\n (isSameDay(date, state.value.start) || isSameDay(date, state.value.end))\n ) {\n label = selectedDateDescription + ', ';\n }\n\n label += dateFormatter.format(nativeDate);\n if (isDateToday) {\n // If date is today, set appropriate string depending on selected state:\n label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {\n date: label\n });\n } else if (isSelected) {\n // If date is selected but not today:\n label = stringFormatter.format('dateSelected', {\n date: label\n });\n }\n\n if (state.minValue && isSameDay(date, state.minValue)) {\n label += ', ' + stringFormatter.format('minimumDate');\n } else if (state.maxValue && isSameDay(date, state.maxValue)) {\n label += ', ' + stringFormatter.format('maximumDate');\n }\n\n return label;\n }, [dateFormatter, nativeDate, stringFormatter, isSelected, isDateToday, date, state, selectedDateDescription]);\n\n // When a cell is focused and this is a range calendar, add a prompt to help\n // screenreader users know that they are in a range selection mode.\n let rangeSelectionPrompt = '';\n if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {\n // If selection has started add \"click to finish selecting range\"\n if (state.anchorDate) {\n rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');\n // Otherwise, add \"click to start selecting range\" prompt\n } else {\n rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');\n }\n }\n\n let descriptionProps = useDescription(rangeSelectionPrompt);\n\n let isAnchorPressed = useRef(false);\n let isRangeBoundaryPressed = useRef(false);\n let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let {pressProps, isPressed} = usePress({\n // When dragging to select a range, we don't want dragging over the original anchor\n // again to trigger onPressStart. Cancel presses immediately when the pointer exits.\n shouldCancelOnPointerExit: 'anchorDate' in state && !!state.anchorDate,\n preventFocusOnPress: true,\n isDisabled: !isSelectable || state.isReadOnly,\n onPressStart(e) {\n if (state.isReadOnly) {\n state.setFocusedDate(date);\n state.setFocused(true);\n return;\n }\n\n if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {\n // Allow dragging the start or end date of a range to modify it\n // rather than starting a new selection.\n // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges\n // are constrained to available dates. The user will need to select a new range in this case.\n if (state.highlightedRange && !isInvalid) {\n if (isSameDay(date, state.highlightedRange.start)) {\n state.setAnchorDate(state.highlightedRange.end);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n } else if (isSameDay(date, state.highlightedRange.end)) {\n state.setAnchorDate(state.highlightedRange.start);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n }\n }\n\n let startDragging = () => {\n state.setDragging(true);\n touchDragTimerRef.current = undefined;\n\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n isAnchorPressed.current = true;\n };\n\n // Start selection on mouse/touch down so users can drag to select a range.\n // On touch, delay dragging to determine if the user really meant to scroll.\n if (e.pointerType === 'touch') {\n touchDragTimerRef.current = setTimeout(startDragging, 200);\n } else {\n startDragging();\n }\n }\n },\n onPressEnd() {\n isRangeBoundaryPressed.current = false;\n isAnchorPressed.current = false;\n clearTimeout(touchDragTimerRef.current);\n touchDragTimerRef.current = undefined;\n },\n onPress() {\n // For non-range selection, always select on press up.\n if (!('anchorDate' in state) && !state.isReadOnly) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n onPressUp(e) {\n if (state.isReadOnly) {\n return;\n }\n\n // If the user tapped quickly, the date won't be selected yet and the\n // timer will still be in progress. In this case, select the date on touch up.\n // Timer is cleared in onPressEnd.\n if ('anchorDate' in state && touchDragTimerRef.current) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n\n if ('anchorDate' in state) {\n if (isRangeBoundaryPressed.current) {\n // When clicking on the start or end date of an already selected range,\n // start a new selection on press up to also allow dragging the date to\n // change the existing range.\n state.setAnchorDate(date);\n } else if (state.anchorDate && !isAnchorPressed.current) {\n // When releasing a drag or pressing the end date of a range, select it.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n } else if (e.pointerType === 'keyboard' && !state.anchorDate) {\n // For range selection, auto-advance the focused date by one if using keyboard.\n // This gives an indication that you're selecting a range rather than a single date.\n // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,\n // there will be an announcement to \"click to finish selecting range\" (above).\n state.selectDate(date);\n let nextDay = date.add({days: 1});\n if (state.isInvalid(nextDay)) {\n nextDay = date.subtract({days: 1});\n }\n if (!state.isInvalid(nextDay)) {\n state.setFocusedDate(nextDay);\n state.setFocused(true);\n }\n } else if (e.pointerType === 'virtual') {\n // For screen readers, just select the date on click.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n }\n }\n });\n\n let tabIndex: number | undefined = undefined;\n if (!isDisabled) {\n tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;\n }\n\n // Focus the button in the DOM when the state updates.\n useEffect(() => {\n if (isFocused && ref.current) {\n focusWithoutScrolling(ref.current);\n\n // Scroll into view if navigating with a keyboard, otherwise\n // try not to shift the view under the user's mouse/finger.\n // If in a overlay, scrollIntoViewport will only cause scrolling\n // up to the overlay scroll body to prevent overlay shifting.\n // Also only scroll into view if the cell actually got focused.\n // There are some cases where the cell might be disabled or inside,\n // an inert container and we don't want to scroll then.\n if (getInteractionModality() !== 'pointer' && getActiveElement() === ref.current) {\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n }\n }\n }, [isFocused, ref]);\n\n let cellDateFormatter = useDateFormatter({\n day: 'numeric',\n timeZone: state.timeZone,\n calendar: date.calendar.identifier\n });\n\n let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value, [cellDateFormatter, nativeDate]);\n\n return {\n cellProps: {\n role: 'gridcell',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-selected': isSelected || undefined,\n 'aria-invalid': isInvalid || undefined\n },\n buttonProps: mergeProps(pressProps, {\n onFocus() {\n if (!isDisabled) {\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n tabIndex,\n role: 'button',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-label': label,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': [\n isInvalid ? errorMessageId : undefined,\n descriptionProps['aria-describedby']\n ].filter(Boolean).join(' ') || undefined,\n onPointerEnter(e) {\n // Highlight the date on hover or drag over a date when selecting a range.\n if ('highlightDate' in state && (e.pointerType !== 'touch' || state.isDragging) && isSelectable) {\n state.highlightDate(date);\n }\n },\n onPointerDown(e: PointerEvent) {\n // This is necessary on touch devices to allow dragging\n // outside the original pressed element.\n // (JSDOM does not support this)\n let target = getEventTarget(e);\n if (target instanceof HTMLElement && 'releasePointerCapture' in target) {\n if ('hasPointerCapture' in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n (target as HTMLElement).releasePointerCapture(e.pointerId);\n }\n }\n },\n onContextMenu(e) {\n // Prevent context menu on long press.\n e.preventDefault();\n }\n }),\n isPressed,\n isFocused,\n isSelected,\n isDisabled,\n isUnavailable,\n isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,\n isInvalid,\n formattedDate\n };\n}\n"],"names":[],"version":3,"file":"useCalendarCell.module.js.map"}
|
|
@@ -44,13 +44,13 @@ function $c49ada48cbc48220$export$87e0539f600c24e5(props, state, ref) {
|
|
|
44
44
|
state.setDragging(false);
|
|
45
45
|
if (!state.anchorDate) return;
|
|
46
46
|
let target = e.target;
|
|
47
|
-
if (ref.current && ref.current
|
|
47
|
+
if (ref.current && (0, $3kfPe$reactariautils.isFocusWithin)(ref.current) && (!(0, $3kfPe$reactariautils.nodeContains)(ref.current, target) || !target.closest('button, [role="button"]'))) state.selectFocusedDate();
|
|
48
48
|
};
|
|
49
49
|
(0, $3kfPe$reactariautils.useEvent)(windowRef, 'pointerup', endDragging);
|
|
50
50
|
// Also stop range selection on blur, e.g. tabbing away from the calendar.
|
|
51
51
|
res.calendarProps.onBlur = (e)=>{
|
|
52
52
|
if (!ref.current) return;
|
|
53
|
-
if ((!e.relatedTarget || !ref.current
|
|
53
|
+
if ((!e.relatedTarget || !(0, $3kfPe$reactariautils.nodeContains)(ref.current, e.relatedTarget)) && state.anchorDate) state.selectFocusedDate();
|
|
54
54
|
};
|
|
55
55
|
// Prevent touch scrolling while dragging
|
|
56
56
|
(0, $3kfPe$reactariautils.useEvent)(ref, 'touchmove', (e)=>{
|
|
@@ -1 +1 @@
|
|
|
1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ACvF,sEAAsE;IACtE,IAAI,cAAc,CAAC;QACjB,IAAI,eAAe,OAAO,EAAE;YAC1B,eAAe,OAAO,GAAG;YACzB;QACF;QAEA,MAAM,WAAW,CAAC;QAClB,IAAI,CAAC,MAAM,UAAU,EACnB;QAGF,IAAI,SAAS,EAAE,MAAM;QACrB,IACE,IAAI,OAAO,IACX,CAAA,GAAA,mCAAY,EAAE,IAAI,OAAO,KACxB,CAAA,CAAC,CAAA,GAAA,kCAAW,EAAE,IAAI,OAAO,EAAE,WAAW,CAAC,OAAO,OAAO,CAAC,0BAAyB,GAEhF,MAAM,iBAAiB;IAE3B;IAEA,CAAA,GAAA,8BAAO,EAAE,WAAW,aAAa;IAEjC,0EAA0E;IAC1E,IAAI,aAAa,CAAC,MAAM,GAAG,CAAA;QACzB,IAAI,CAAC,IAAI,OAAO,EACd;QAEF,IAAI,AAAC,CAAA,CAAC,EAAE,aAAa,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,IAAI,OAAO,EAAE,EAAE,aAAa,CAAA,KAAM,MAAM,UAAU,EACvF,MAAM,iBAAiB;IAE3B;IAEA,yCAAyC;IACzC,CAAA,GAAA,8BAAO,EAAE,KAAK,aAAa,CAAA;QACzB,IAAI,MAAM,UAAU,EAClB,EAAE,cAAc;IAEpB,GAAG;QAAC,SAAS;QAAO,SAAS;IAAI;IAEjC,OAAO;AACT","sources":["packages/@react-aria/calendar/src/useRangeCalendar.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaRangeCalendarProps, DateValue} from '@react-types/calendar';\nimport {CalendarAria, useCalendarBase} from './useCalendarBase';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {isFocusWithin, nodeContains, useEvent} from '@react-aria/utils';\nimport {RangeCalendarState} from '@react-stately/calendar';\nimport {useRef} from 'react';\n\n/**\n * Provides the behavior and accessibility implementation for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<FocusableElement | null>): CalendarAria {\n let res = useCalendarBase(props, state);\n\n // We need to ignore virtual pointer events from VoiceOver due to these bugs.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n // usePress also does this and waits for the following click event before firing.\n // We need to match that here otherwise this will fire before the press event in\n // useCalendarCell, causing range selection to not work properly.\n let isVirtualClick = useRef(false);\n let windowRef = useRef(typeof window !== 'undefined' ? window : null);\n useEvent(windowRef, 'pointerdown', e => {\n isVirtualClick.current = e.width === 0 && e.height === 0;\n });\n\n // Stop range selection when pressing or releasing a pointer outside the calendar body,\n // except when pressing the next or previous buttons to switch months.\n let endDragging = (e: PointerEvent) => {\n if (isVirtualClick.current) {\n isVirtualClick.current = false;\n return;\n }\n\n state.setDragging(false);\n if (!state.anchorDate) {\n return;\n }\n\n let target = e.target as Element;\n if (\n ref.current &&\n isFocusWithin(ref.current) &&\n (!nodeContains(ref.current, target) || !target.closest('button, [role=\"button\"]'))\n ) {\n state.selectFocusedDate();\n }\n };\n\n useEvent(windowRef, 'pointerup', endDragging);\n\n // Also stop range selection on blur, e.g. tabbing away from the calendar.\n res.calendarProps.onBlur = e => {\n if (!ref.current) {\n return;\n }\n if ((!e.relatedTarget || !nodeContains(ref.current, e.relatedTarget)) && state.anchorDate) {\n state.selectFocusedDate();\n }\n };\n\n // Prevent touch scrolling while dragging\n useEvent(ref, 'touchmove', e => {\n if (state.isDragging) {\n e.preventDefault();\n }\n }, {passive: false, capture: true});\n\n return res;\n}\n"],"names":[],"version":3,"file":"useRangeCalendar.main.js.map"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useCalendarBase as $c4acc1de3ab169cf$export$d652b3ea2d672d5b} from "./useCalendarBase.mjs";
|
|
2
|
-
import {useEvent as $juhpn$useEvent} from "@react-aria/utils";
|
|
2
|
+
import {useEvent as $juhpn$useEvent, isFocusWithin as $juhpn$isFocusWithin, nodeContains as $juhpn$nodeContains} from "@react-aria/utils";
|
|
3
3
|
import {useRef as $juhpn$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
/*
|
|
@@ -38,13 +38,13 @@ function $46a4342aab3d8076$export$87e0539f600c24e5(props, state, ref) {
|
|
|
38
38
|
state.setDragging(false);
|
|
39
39
|
if (!state.anchorDate) return;
|
|
40
40
|
let target = e.target;
|
|
41
|
-
if (ref.current && ref.current
|
|
41
|
+
if (ref.current && (0, $juhpn$isFocusWithin)(ref.current) && (!(0, $juhpn$nodeContains)(ref.current, target) || !target.closest('button, [role="button"]'))) state.selectFocusedDate();
|
|
42
42
|
};
|
|
43
43
|
(0, $juhpn$useEvent)(windowRef, 'pointerup', endDragging);
|
|
44
44
|
// Also stop range selection on blur, e.g. tabbing away from the calendar.
|
|
45
45
|
res.calendarProps.onBlur = (e)=>{
|
|
46
46
|
if (!ref.current) return;
|
|
47
|
-
if ((!e.relatedTarget || !ref.current
|
|
47
|
+
if ((!e.relatedTarget || !(0, $juhpn$nodeContains)(ref.current, e.relatedTarget)) && state.anchorDate) state.selectFocusedDate();
|
|
48
48
|
};
|
|
49
49
|
// Prevent touch scrolling while dragging
|
|
50
50
|
(0, $juhpn$useEvent)(ref, 'touchmove', (e)=>{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useCalendarBase as $c4acc1de3ab169cf$export$d652b3ea2d672d5b} from "./useCalendarBase.module.js";
|
|
2
|
-
import {useEvent as $juhpn$useEvent} from "@react-aria/utils";
|
|
2
|
+
import {useEvent as $juhpn$useEvent, isFocusWithin as $juhpn$isFocusWithin, nodeContains as $juhpn$nodeContains} from "@react-aria/utils";
|
|
3
3
|
import {useRef as $juhpn$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
/*
|
|
@@ -38,13 +38,13 @@ function $46a4342aab3d8076$export$87e0539f600c24e5(props, state, ref) {
|
|
|
38
38
|
state.setDragging(false);
|
|
39
39
|
if (!state.anchorDate) return;
|
|
40
40
|
let target = e.target;
|
|
41
|
-
if (ref.current && ref.current
|
|
41
|
+
if (ref.current && (0, $juhpn$isFocusWithin)(ref.current) && (!(0, $juhpn$nodeContains)(ref.current, target) || !target.closest('button, [role="button"]'))) state.selectFocusedDate();
|
|
42
42
|
};
|
|
43
43
|
(0, $juhpn$useEvent)(windowRef, 'pointerup', endDragging);
|
|
44
44
|
// Also stop range selection on blur, e.g. tabbing away from the calendar.
|
|
45
45
|
res.calendarProps.onBlur = (e)=>{
|
|
46
46
|
if (!ref.current) return;
|
|
47
|
-
if ((!e.relatedTarget || !ref.current
|
|
47
|
+
if ((!e.relatedTarget || !(0, $juhpn$nodeContains)(ref.current, e.relatedTarget)) && state.anchorDate) state.selectFocusedDate();
|
|
48
48
|
};
|
|
49
49
|
// Prevent touch scrolling while dragging
|
|
50
50
|
(0, $juhpn$useEvent)(ref, 'touchmove', (e)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAaM,SAAS,0CAAsC,KAAgC,EAAE,KAAyB,EAAE,GAAuC;IACxJ,IAAI,MAAM,CAAA,GAAA,yCAAc,EAAE,OAAO;IAEjC,6EAA6E;IAC7E,iDAAiD;IACjD,iDAAiD;IACjD,iFAAiF;IACjF,gFAAgF;IAChF,iEAAiE;IACjE,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC5B,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE,OAAO,WAAW,cAAc,SAAS;IAChE,CAAA,GAAA,eAAO,EAAE,WAAW,eAA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,EAAE,WAAW,aAAa;IAEjC,0EAA0E;IAC1E,IAAI,aAAa,CAAC,MAAM,GAAG,CAAA;QACzB,IAAI,CAAC,IAAI,OAAO,EACd;QAEF,IAAI,AAAC,CAAA,CAAC,EAAE,aAAa,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,IAAI,OAAO,EAAE,EAAE,aAAa,CAAA,KAAM,MAAM,UAAU,EACvF,MAAM,iBAAiB;IAE3B;IAEA,yCAAyC;IACzC,CAAA,GAAA,eAAO,EAAE,KAAK,aAAa,CAAA;QACzB,IAAI,MAAM,UAAU,EAClB,EAAE,cAAc;IAEpB,GAAG;QAAC,SAAS;QAAO,SAAS;IAAI;IAEjC,OAAO;AACT","sources":["packages/@react-aria/calendar/src/useRangeCalendar.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaRangeCalendarProps, DateValue} from '@react-types/calendar';\nimport {CalendarAria, useCalendarBase} from './useCalendarBase';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {isFocusWithin, nodeContains, useEvent} from '@react-aria/utils';\nimport {RangeCalendarState} from '@react-stately/calendar';\nimport {useRef} from 'react';\n\n/**\n * Provides the behavior and accessibility implementation for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<FocusableElement | null>): CalendarAria {\n let res = useCalendarBase(props, state);\n\n // We need to ignore virtual pointer events from VoiceOver due to these bugs.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n // usePress also does this and waits for the following click event before firing.\n // We need to match that here otherwise this will fire before the press event in\n // useCalendarCell, causing range selection to not work properly.\n let isVirtualClick = useRef(false);\n let windowRef = useRef(typeof window !== 'undefined' ? window : null);\n useEvent(windowRef, 'pointerdown', e => {\n isVirtualClick.current = e.width === 0 && e.height === 0;\n });\n\n // Stop range selection when pressing or releasing a pointer outside the calendar body,\n // except when pressing the next or previous buttons to switch months.\n let endDragging = (e: PointerEvent) => {\n if (isVirtualClick.current) {\n isVirtualClick.current = false;\n return;\n }\n\n state.setDragging(false);\n if (!state.anchorDate) {\n return;\n }\n\n let target = e.target as Element;\n if (\n ref.current &&\n isFocusWithin(ref.current) &&\n (!nodeContains(ref.current, target) || !target.closest('button, [role=\"button\"]'))\n ) {\n state.selectFocusedDate();\n }\n };\n\n useEvent(windowRef, 'pointerup', endDragging);\n\n // Also stop range selection on blur, e.g. tabbing away from the calendar.\n res.calendarProps.onBlur = e => {\n if (!ref.current) {\n return;\n }\n if ((!e.relatedTarget || !nodeContains(ref.current, e.relatedTarget)) && state.anchorDate) {\n state.selectFocusedDate();\n }\n };\n\n // Prevent touch scrolling while dragging\n useEvent(ref, 'touchmove', e => {\n if (state.isDragging) {\n e.preventDefault();\n }\n }, {passive: false, capture: true});\n\n return res;\n}\n"],"names":[],"version":3,"file":"useRangeCalendar.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/calendar",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.5",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@internationalized/date": "^3.
|
|
30
|
-
"@react-aria/i18n": "^3.12.
|
|
31
|
-
"@react-aria/interactions": "^3.
|
|
29
|
+
"@internationalized/date": "^3.12.0",
|
|
30
|
+
"@react-aria/i18n": "^3.12.16",
|
|
31
|
+
"@react-aria/interactions": "^3.27.1",
|
|
32
32
|
"@react-aria/live-announcer": "^3.4.4",
|
|
33
|
-
"@react-aria/utils": "^3.
|
|
34
|
-
"@react-stately/calendar": "^3.9.
|
|
35
|
-
"@react-types/button": "^3.
|
|
36
|
-
"@react-types/calendar": "^3.8.
|
|
37
|
-
"@react-types/shared": "^3.
|
|
33
|
+
"@react-aria/utils": "^3.33.1",
|
|
34
|
+
"@react-stately/calendar": "^3.9.3",
|
|
35
|
+
"@react-types/button": "^3.15.1",
|
|
36
|
+
"@react-types/calendar": "^3.8.3",
|
|
37
|
+
"@react-types/shared": "^3.33.1",
|
|
38
38
|
"@swc/helpers": "^0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
|
|
48
48
|
}
|
package/src/useCalendarCell.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
15
|
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
16
|
-
import {focusWithoutScrolling, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';
|
|
16
|
+
import {focusWithoutScrolling, getActiveElement, getEventTarget, getScrollParent, mergeProps, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';
|
|
17
17
|
import {getEraFormat, hookData} from './utils';
|
|
18
18
|
import {getInteractionModality, usePress} from '@react-aria/interactions';
|
|
19
19
|
// @ts-ignore
|
|
@@ -174,6 +174,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
174
174
|
onPressStart(e) {
|
|
175
175
|
if (state.isReadOnly) {
|
|
176
176
|
state.setFocusedDate(date);
|
|
177
|
+
state.setFocused(true);
|
|
177
178
|
return;
|
|
178
179
|
}
|
|
179
180
|
|
|
@@ -186,12 +187,14 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
186
187
|
if (isSameDay(date, state.highlightedRange.start)) {
|
|
187
188
|
state.setAnchorDate(state.highlightedRange.end);
|
|
188
189
|
state.setFocusedDate(date);
|
|
190
|
+
state.setFocused(true);
|
|
189
191
|
state.setDragging(true);
|
|
190
192
|
isRangeBoundaryPressed.current = true;
|
|
191
193
|
return;
|
|
192
194
|
} else if (isSameDay(date, state.highlightedRange.end)) {
|
|
193
195
|
state.setAnchorDate(state.highlightedRange.start);
|
|
194
196
|
state.setFocusedDate(date);
|
|
197
|
+
state.setFocused(true);
|
|
195
198
|
state.setDragging(true);
|
|
196
199
|
isRangeBoundaryPressed.current = true;
|
|
197
200
|
return;
|
|
@@ -204,6 +207,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
204
207
|
|
|
205
208
|
state.selectDate(date);
|
|
206
209
|
state.setFocusedDate(date);
|
|
210
|
+
state.setFocused(true);
|
|
207
211
|
isAnchorPressed.current = true;
|
|
208
212
|
};
|
|
209
213
|
|
|
@@ -227,6 +231,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
227
231
|
if (!('anchorDate' in state) && !state.isReadOnly) {
|
|
228
232
|
state.selectDate(date);
|
|
229
233
|
state.setFocusedDate(date);
|
|
234
|
+
state.setFocused(true);
|
|
230
235
|
}
|
|
231
236
|
},
|
|
232
237
|
onPressUp(e) {
|
|
@@ -240,6 +245,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
240
245
|
if ('anchorDate' in state && touchDragTimerRef.current) {
|
|
241
246
|
state.selectDate(date);
|
|
242
247
|
state.setFocusedDate(date);
|
|
248
|
+
state.setFocused(true);
|
|
243
249
|
}
|
|
244
250
|
|
|
245
251
|
if ('anchorDate' in state) {
|
|
@@ -252,6 +258,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
252
258
|
// When releasing a drag or pressing the end date of a range, select it.
|
|
253
259
|
state.selectDate(date);
|
|
254
260
|
state.setFocusedDate(date);
|
|
261
|
+
state.setFocused(true);
|
|
255
262
|
} else if (e.pointerType === 'keyboard' && !state.anchorDate) {
|
|
256
263
|
// For range selection, auto-advance the focused date by one if using keyboard.
|
|
257
264
|
// This gives an indication that you're selecting a range rather than a single date.
|
|
@@ -264,11 +271,13 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
264
271
|
}
|
|
265
272
|
if (!state.isInvalid(nextDay)) {
|
|
266
273
|
state.setFocusedDate(nextDay);
|
|
274
|
+
state.setFocused(true);
|
|
267
275
|
}
|
|
268
276
|
} else if (e.pointerType === 'virtual') {
|
|
269
277
|
// For screen readers, just select the date on click.
|
|
270
278
|
state.selectDate(date);
|
|
271
279
|
state.setFocusedDate(date);
|
|
280
|
+
state.setFocused(true);
|
|
272
281
|
}
|
|
273
282
|
}
|
|
274
283
|
}
|
|
@@ -291,7 +300,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
291
300
|
// Also only scroll into view if the cell actually got focused.
|
|
292
301
|
// There are some cases where the cell might be disabled or inside,
|
|
293
302
|
// an inert container and we don't want to scroll then.
|
|
294
|
-
if (getInteractionModality() !== 'pointer' &&
|
|
303
|
+
if (getInteractionModality() !== 'pointer' && getActiveElement() === ref.current) {
|
|
295
304
|
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
296
305
|
}
|
|
297
306
|
}
|
|
@@ -316,6 +325,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
316
325
|
onFocus() {
|
|
317
326
|
if (!isDisabled) {
|
|
318
327
|
state.setFocusedDate(date);
|
|
328
|
+
state.setFocused(true);
|
|
319
329
|
}
|
|
320
330
|
},
|
|
321
331
|
tabIndex,
|
|
@@ -333,12 +343,19 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
333
343
|
state.highlightDate(date);
|
|
334
344
|
}
|
|
335
345
|
},
|
|
336
|
-
onPointerDown(e) {
|
|
346
|
+
onPointerDown(e: PointerEvent) {
|
|
337
347
|
// This is necessary on touch devices to allow dragging
|
|
338
348
|
// outside the original pressed element.
|
|
339
349
|
// (JSDOM does not support this)
|
|
340
|
-
|
|
341
|
-
|
|
350
|
+
let target = getEventTarget(e);
|
|
351
|
+
if (target instanceof HTMLElement && 'releasePointerCapture' in target) {
|
|
352
|
+
if ('hasPointerCapture' in target) {
|
|
353
|
+
if (target.hasPointerCapture(e.pointerId)) {
|
|
354
|
+
target.releasePointerCapture(e.pointerId);
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
(target as HTMLElement).releasePointerCapture(e.pointerId);
|
|
358
|
+
}
|
|
342
359
|
}
|
|
343
360
|
},
|
|
344
361
|
onContextMenu(e) {
|
package/src/useRangeCalendar.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
import {AriaRangeCalendarProps, DateValue} from '@react-types/calendar';
|
|
14
14
|
import {CalendarAria, useCalendarBase} from './useCalendarBase';
|
|
15
15
|
import {FocusableElement, RefObject} from '@react-types/shared';
|
|
16
|
+
import {isFocusWithin, nodeContains, useEvent} from '@react-aria/utils';
|
|
16
17
|
import {RangeCalendarState} from '@react-stately/calendar';
|
|
17
|
-
import {useEvent} from '@react-aria/utils';
|
|
18
18
|
import {useRef} from 'react';
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -52,8 +52,8 @@ export function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarPr
|
|
|
52
52
|
let target = e.target as Element;
|
|
53
53
|
if (
|
|
54
54
|
ref.current &&
|
|
55
|
-
ref.current
|
|
56
|
-
(!ref.current
|
|
55
|
+
isFocusWithin(ref.current) &&
|
|
56
|
+
(!nodeContains(ref.current, target) || !target.closest('button, [role="button"]'))
|
|
57
57
|
) {
|
|
58
58
|
state.selectFocusedDate();
|
|
59
59
|
}
|
|
@@ -66,7 +66,7 @@ export function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarPr
|
|
|
66
66
|
if (!ref.current) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
if ((!e.relatedTarget || !ref.current
|
|
69
|
+
if ((!e.relatedTarget || !nodeContains(ref.current, e.relatedTarget)) && state.anchorDate) {
|
|
70
70
|
state.selectFocusedDate();
|
|
71
71
|
}
|
|
72
72
|
};
|