@react-aria/calendar 3.5.6 → 3.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/import.mjs +4 -778
  2. package/dist/intlStrings.main.js +108 -0
  3. package/dist/intlStrings.main.js.map +1 -0
  4. package/dist/intlStrings.mjs +110 -0
  5. package/dist/intlStrings.module.js +110 -0
  6. package/dist/intlStrings.module.js.map +1 -0
  7. package/dist/main.js +8 -782
  8. package/dist/main.js.map +1 -1
  9. package/dist/module.js +4 -778
  10. package/dist/module.js.map +1 -1
  11. package/dist/types.d.ts.map +1 -1
  12. package/dist/useCalendar.main.js +25 -0
  13. package/dist/useCalendar.main.js.map +1 -0
  14. package/dist/useCalendar.mjs +20 -0
  15. package/dist/useCalendar.module.js +20 -0
  16. package/dist/useCalendar.module.js.map +1 -0
  17. package/dist/useCalendarBase.main.js +112 -0
  18. package/dist/useCalendarBase.main.js.map +1 -0
  19. package/dist/useCalendarBase.mjs +107 -0
  20. package/dist/useCalendarBase.module.js +107 -0
  21. package/dist/useCalendarBase.module.js.map +1 -0
  22. package/dist/useCalendarCell.main.js +276 -0
  23. package/dist/useCalendarCell.main.js.map +1 -0
  24. package/dist/useCalendarCell.mjs +271 -0
  25. package/dist/useCalendarCell.module.js +271 -0
  26. package/dist/useCalendarCell.module.js.map +1 -0
  27. package/dist/useCalendarGrid.main.js +139 -0
  28. package/dist/useCalendarGrid.main.js.map +1 -0
  29. package/dist/useCalendarGrid.mjs +134 -0
  30. package/dist/useCalendarGrid.module.js +134 -0
  31. package/dist/useCalendarGrid.module.js.map +1 -0
  32. package/dist/useRangeCalendar.main.js +66 -0
  33. package/dist/useRangeCalendar.main.js.map +1 -0
  34. package/dist/useRangeCalendar.mjs +61 -0
  35. package/dist/useRangeCalendar.module.js +61 -0
  36. package/dist/useRangeCalendar.module.js.map +1 -0
  37. package/dist/utils.main.js +138 -0
  38. package/dist/utils.main.js.map +1 -0
  39. package/dist/utils.mjs +130 -0
  40. package/dist/utils.module.js +130 -0
  41. package/dist/utils.module.js.map +1 -0
  42. package/package.json +11 -11
  43. package/src/useRangeCalendar.ts +6 -5
package/dist/utils.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import $3HATx$intlStringsmodulejs from "./intlStrings.mjs";
2
+ import {isSameDay as $3HATx$isSameDay, startOfMonth as $3HATx$startOfMonth, endOfMonth as $3HATx$endOfMonth} from "@internationalized/date";
3
+ import {useLocalizedStringFormatter as $3HATx$useLocalizedStringFormatter, useDateFormatter as $3HATx$useDateFormatter} from "@react-aria/i18n";
4
+ import {useMemo as $3HATx$useMemo} from "react";
5
+
6
+
7
+ function $parcel$interopDefault(a) {
8
+ return a && a.__esModule ? a.default : a;
9
+ }
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+
23
+
24
+ const $a074e1e2d0f0a665$export$653eddfc964b0f8a = new WeakMap();
25
+ function $a074e1e2d0f0a665$export$134cbb7fb09a9522(date) {
26
+ return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === 'gregory' && date.era === 'BC' ? 'short' : undefined;
27
+ }
28
+ function $a074e1e2d0f0a665$export$b6df97c887c38e1a(state) {
29
+ let stringFormatter = (0, $3HATx$useLocalizedStringFormatter)((0, ($parcel$interopDefault($3HATx$intlStringsmodulejs))), '@react-aria/calendar');
30
+ let start, end;
31
+ if ('highlightedRange' in state) ({ start: start, end: end } = state.highlightedRange || {});
32
+ else start = end = state.value;
33
+ let dateFormatter = (0, $3HATx$useDateFormatter)({
34
+ weekday: 'long',
35
+ month: 'long',
36
+ year: 'numeric',
37
+ day: 'numeric',
38
+ era: $a074e1e2d0f0a665$export$134cbb7fb09a9522(start) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(end),
39
+ timeZone: state.timeZone
40
+ });
41
+ let anchorDate = 'anchorDate' in state ? state.anchorDate : null;
42
+ return (0, $3HATx$useMemo)(()=>{
43
+ // No message if currently selecting a range, or there is nothing highlighted.
44
+ if (!anchorDate && start && end) {
45
+ // Use a single date message if the start and end dates are the same day,
46
+ // otherwise include both dates.
47
+ if ((0, $3HATx$isSameDay)(start, end)) {
48
+ let date = dateFormatter.format(start.toDate(state.timeZone));
49
+ return stringFormatter.format('selectedDateDescription', {
50
+ date: date
51
+ });
52
+ } else {
53
+ let dateRange = $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
54
+ return stringFormatter.format('selectedRangeDescription', {
55
+ dateRange: dateRange
56
+ });
57
+ }
58
+ }
59
+ return '';
60
+ }, [
61
+ start,
62
+ end,
63
+ anchorDate,
64
+ state.timeZone,
65
+ stringFormatter,
66
+ dateFormatter
67
+ ]);
68
+ }
69
+ function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
70
+ let stringFormatter = (0, $3HATx$useLocalizedStringFormatter)((0, ($parcel$interopDefault($3HATx$intlStringsmodulejs))), '@react-aria/calendar');
71
+ let era = $a074e1e2d0f0a665$export$134cbb7fb09a9522(startDate) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(endDate);
72
+ let monthFormatter = (0, $3HATx$useDateFormatter)({
73
+ month: 'long',
74
+ year: 'numeric',
75
+ era: era,
76
+ calendar: startDate.calendar.identifier,
77
+ timeZone: timeZone
78
+ });
79
+ let dateFormatter = (0, $3HATx$useDateFormatter)({
80
+ month: 'long',
81
+ year: 'numeric',
82
+ day: 'numeric',
83
+ era: era,
84
+ calendar: startDate.calendar.identifier,
85
+ timeZone: timeZone
86
+ });
87
+ return (0, $3HATx$useMemo)(()=>{
88
+ // Special case for month granularity. Format as a single month if only a
89
+ // single month is visible, otherwise format as a range of months.
90
+ if ((0, $3HATx$isSameDay)(startDate, (0, $3HATx$startOfMonth)(startDate))) {
91
+ if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(startDate))) return monthFormatter.format(startDate.toDate(timeZone));
92
+ else if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(endDate))) return isAria ? $a074e1e2d0f0a665$var$formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone) : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
93
+ }
94
+ return isAria ? $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
95
+ }, [
96
+ startDate,
97
+ endDate,
98
+ monthFormatter,
99
+ dateFormatter,
100
+ stringFormatter,
101
+ timeZone,
102
+ isAria
103
+ ]);
104
+ }
105
+ function $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start, end, timeZone) {
106
+ let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));
107
+ // Find the separator between the start and end date. This is determined
108
+ // by finding the last shared literal before the end range.
109
+ let separatorIndex = -1;
110
+ for(let i = 0; i < parts.length; i++){
111
+ let part = parts[i];
112
+ if (part.source === 'shared' && part.type === 'literal') separatorIndex = i;
113
+ else if (part.source === 'endRange') break;
114
+ }
115
+ // Now we can combine the parts into start and end strings.
116
+ let startValue = '';
117
+ let endValue = '';
118
+ for(let i = 0; i < parts.length; i++){
119
+ if (i < separatorIndex) startValue += parts[i].value;
120
+ else if (i > separatorIndex) endValue += parts[i].value;
121
+ }
122
+ return stringFormatter.format('dateRange', {
123
+ startDate: startValue,
124
+ endDate: endValue
125
+ });
126
+ }
127
+
128
+
129
+ export {$a074e1e2d0f0a665$export$653eddfc964b0f8a as hookData, $a074e1e2d0f0a665$export$134cbb7fb09a9522 as getEraFormat, $a074e1e2d0f0a665$export$b6df97c887c38e1a as useSelectedDateDescription, $a074e1e2d0f0a665$export$31afe65d91ef6e8 as useVisibleRangeDescription};
130
+ //# sourceMappingURL=utils.module.js.map
@@ -0,0 +1,130 @@
1
+ import $3HATx$intlStringsmodulejs from "./intlStrings.module.js";
2
+ import {isSameDay as $3HATx$isSameDay, startOfMonth as $3HATx$startOfMonth, endOfMonth as $3HATx$endOfMonth} from "@internationalized/date";
3
+ import {useLocalizedStringFormatter as $3HATx$useLocalizedStringFormatter, useDateFormatter as $3HATx$useDateFormatter} from "@react-aria/i18n";
4
+ import {useMemo as $3HATx$useMemo} from "react";
5
+
6
+
7
+ function $parcel$interopDefault(a) {
8
+ return a && a.__esModule ? a.default : a;
9
+ }
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+
23
+
24
+ const $a074e1e2d0f0a665$export$653eddfc964b0f8a = new WeakMap();
25
+ function $a074e1e2d0f0a665$export$134cbb7fb09a9522(date) {
26
+ return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === 'gregory' && date.era === 'BC' ? 'short' : undefined;
27
+ }
28
+ function $a074e1e2d0f0a665$export$b6df97c887c38e1a(state) {
29
+ let stringFormatter = (0, $3HATx$useLocalizedStringFormatter)((0, ($parcel$interopDefault($3HATx$intlStringsmodulejs))), '@react-aria/calendar');
30
+ let start, end;
31
+ if ('highlightedRange' in state) ({ start: start, end: end } = state.highlightedRange || {});
32
+ else start = end = state.value;
33
+ let dateFormatter = (0, $3HATx$useDateFormatter)({
34
+ weekday: 'long',
35
+ month: 'long',
36
+ year: 'numeric',
37
+ day: 'numeric',
38
+ era: $a074e1e2d0f0a665$export$134cbb7fb09a9522(start) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(end),
39
+ timeZone: state.timeZone
40
+ });
41
+ let anchorDate = 'anchorDate' in state ? state.anchorDate : null;
42
+ return (0, $3HATx$useMemo)(()=>{
43
+ // No message if currently selecting a range, or there is nothing highlighted.
44
+ if (!anchorDate && start && end) {
45
+ // Use a single date message if the start and end dates are the same day,
46
+ // otherwise include both dates.
47
+ if ((0, $3HATx$isSameDay)(start, end)) {
48
+ let date = dateFormatter.format(start.toDate(state.timeZone));
49
+ return stringFormatter.format('selectedDateDescription', {
50
+ date: date
51
+ });
52
+ } else {
53
+ let dateRange = $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
54
+ return stringFormatter.format('selectedRangeDescription', {
55
+ dateRange: dateRange
56
+ });
57
+ }
58
+ }
59
+ return '';
60
+ }, [
61
+ start,
62
+ end,
63
+ anchorDate,
64
+ state.timeZone,
65
+ stringFormatter,
66
+ dateFormatter
67
+ ]);
68
+ }
69
+ function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
70
+ let stringFormatter = (0, $3HATx$useLocalizedStringFormatter)((0, ($parcel$interopDefault($3HATx$intlStringsmodulejs))), '@react-aria/calendar');
71
+ let era = $a074e1e2d0f0a665$export$134cbb7fb09a9522(startDate) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(endDate);
72
+ let monthFormatter = (0, $3HATx$useDateFormatter)({
73
+ month: 'long',
74
+ year: 'numeric',
75
+ era: era,
76
+ calendar: startDate.calendar.identifier,
77
+ timeZone: timeZone
78
+ });
79
+ let dateFormatter = (0, $3HATx$useDateFormatter)({
80
+ month: 'long',
81
+ year: 'numeric',
82
+ day: 'numeric',
83
+ era: era,
84
+ calendar: startDate.calendar.identifier,
85
+ timeZone: timeZone
86
+ });
87
+ return (0, $3HATx$useMemo)(()=>{
88
+ // Special case for month granularity. Format as a single month if only a
89
+ // single month is visible, otherwise format as a range of months.
90
+ if ((0, $3HATx$isSameDay)(startDate, (0, $3HATx$startOfMonth)(startDate))) {
91
+ if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(startDate))) return monthFormatter.format(startDate.toDate(timeZone));
92
+ else if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(endDate))) return isAria ? $a074e1e2d0f0a665$var$formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone) : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
93
+ }
94
+ return isAria ? $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
95
+ }, [
96
+ startDate,
97
+ endDate,
98
+ monthFormatter,
99
+ dateFormatter,
100
+ stringFormatter,
101
+ timeZone,
102
+ isAria
103
+ ]);
104
+ }
105
+ function $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start, end, timeZone) {
106
+ let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));
107
+ // Find the separator between the start and end date. This is determined
108
+ // by finding the last shared literal before the end range.
109
+ let separatorIndex = -1;
110
+ for(let i = 0; i < parts.length; i++){
111
+ let part = parts[i];
112
+ if (part.source === 'shared' && part.type === 'literal') separatorIndex = i;
113
+ else if (part.source === 'endRange') break;
114
+ }
115
+ // Now we can combine the parts into start and end strings.
116
+ let startValue = '';
117
+ let endValue = '';
118
+ for(let i = 0; i < parts.length; i++){
119
+ if (i < separatorIndex) startValue += parts[i].value;
120
+ else if (i > separatorIndex) endValue += parts[i].value;
121
+ }
122
+ return stringFormatter.format('dateRange', {
123
+ startDate: startValue,
124
+ endDate: endValue
125
+ });
126
+ }
127
+
128
+
129
+ export {$a074e1e2d0f0a665$export$653eddfc964b0f8a as hookData, $a074e1e2d0f0a665$export$134cbb7fb09a9522 as getEraFormat, $a074e1e2d0f0a665$export$b6df97c887c38e1a as useSelectedDateDescription, $a074e1e2d0f0a665$export$31afe65d91ef6e8 as useVisibleRangeDescription};
130
+ //# sourceMappingURL=utils.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/calendar/src/utils.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, DateFormatter, endOfMonth, isSameDay, startOfMonth} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport type {LocalizedStringFormatter} from '@internationalized/string';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMemo} from 'react';\n\ninterface HookData {\n ariaLabel: string,\n ariaLabelledBy: string,\n errorMessageId: string,\n selectedDateDescription: string\n}\n\nexport const hookData = new WeakMap<CalendarState | RangeCalendarState, HookData>();\n\nexport function getEraFormat(date: CalendarDate): 'short' | undefined {\n return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;\n}\n\nexport function useSelectedDateDescription(state: CalendarState | RangeCalendarState) {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n\n let start: CalendarDate, end: CalendarDate;\n if ('highlightedRange' in state) {\n ({start, end} = state.highlightedRange || {});\n } else {\n start = end = state.value;\n }\n\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era: getEraFormat(start) || getEraFormat(end),\n timeZone: state.timeZone\n });\n\n let anchorDate = 'anchorDate' in state ? state.anchorDate : null;\n return useMemo(() => {\n // No message if currently selecting a range, or there is nothing highlighted.\n if (!anchorDate && start && end) {\n // Use a single date message if the start and end dates are the same day,\n // otherwise include both dates.\n if (isSameDay(start, end)) {\n let date = dateFormatter.format(start.toDate(state.timeZone));\n return stringFormatter.format('selectedDateDescription', {date});\n } else {\n let dateRange = formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);\n\n return stringFormatter.format('selectedRangeDescription', {dateRange});\n }\n }\n return '';\n }, [start, end, anchorDate, state.timeZone, stringFormatter, dateFormatter]);\n}\n\nexport function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean) {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let era: any = getEraFormat(startDate) || getEraFormat(endDate);\n let monthFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n let dateFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n return useMemo(() => {\n // Special case for month granularity. Format as a single month if only a\n // single month is visible, otherwise format as a range of months.\n if (isSameDay(startDate, startOfMonth(startDate))) {\n if (isSameDay(endDate, endOfMonth(startDate))) {\n return monthFormatter.format(startDate.toDate(timeZone));\n } else if (isSameDay(endDate, endOfMonth(endDate))) {\n return isAria\n ? formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone)\n : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));\n }\n }\n\n return isAria\n ? formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone)\n : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));\n }, [startDate, endDate, monthFormatter, dateFormatter, stringFormatter, timeZone, isAria]);\n}\n\nfunction formatRange(dateFormatter: DateFormatter, stringFormatter: LocalizedStringFormatter, start: CalendarDate, end: CalendarDate, timeZone: string) {\n let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));\n\n // Find the separator between the start and end date. This is determined\n // by finding the last shared literal before the end range.\n let separatorIndex = -1;\n for (let i = 0; i < parts.length; i++) {\n let part = parts[i];\n if (part.source === 'shared' && part.type === 'literal') {\n separatorIndex = i;\n } else if (part.source === 'endRange') {\n break;\n }\n }\n\n // Now we can combine the parts into start and end strings.\n let startValue = '';\n let endValue = '';\n for (let i = 0; i < parts.length; i++) {\n if (i < separatorIndex) {\n startValue += parts[i].value;\n } else if (i > separatorIndex) {\n endValue += parts[i].value;\n }\n }\n\n return stringFormatter.format('dateRange', {startDate: startValue, endDate: endValue});\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/calendar",
3
- "version": "3.5.6",
3
+ "version": "3.5.8",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,15 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@internationalized/date": "^3.5.2",
26
- "@react-aria/i18n": "^3.10.2",
27
- "@react-aria/interactions": "^3.21.1",
28
- "@react-aria/live-announcer": "^3.3.2",
29
- "@react-aria/utils": "^3.23.2",
30
- "@react-stately/calendar": "^3.4.4",
31
- "@react-types/button": "^3.9.2",
32
- "@react-types/calendar": "^3.4.4",
33
- "@react-types/shared": "^3.22.1",
25
+ "@internationalized/date": "^3.5.4",
26
+ "@react-aria/i18n": "^3.11.1",
27
+ "@react-aria/interactions": "^3.21.3",
28
+ "@react-aria/live-announcer": "^3.3.4",
29
+ "@react-aria/utils": "^3.24.1",
30
+ "@react-stately/calendar": "^3.5.1",
31
+ "@react-types/button": "^3.9.4",
32
+ "@react-types/calendar": "^3.4.6",
33
+ "@react-types/shared": "^3.23.1",
34
34
  "@swc/helpers": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
43
+ "gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
44
44
  }
@@ -50,21 +50,22 @@ export function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarPr
50
50
  }
51
51
 
52
52
  let target = e.target as Element;
53
- let body = document.getElementById(res.calendarProps.id);
54
53
  if (
55
- body &&
56
- body.contains(document.activeElement) &&
57
- (!body.contains(target) || !target.closest('button, [role="button"]'))
54
+ ref.current &&
55
+ ref.current.contains(document.activeElement) &&
56
+ (!ref.current.contains(target) || !target.closest('button, [role="button"]'))
58
57
  ) {
59
58
  state.selectFocusedDate();
60
59
  }
61
60
  };
62
61
 
63
62
  useEvent(windowRef, 'pointerup', endDragging);
64
- useEvent(windowRef, 'pointercancel', endDragging);
65
63
 
66
64
  // Also stop range selection on blur, e.g. tabbing away from the calendar.
67
65
  res.calendarProps.onBlur = e => {
66
+ if (!ref.current) {
67
+ return;
68
+ }
68
69
  if ((!e.relatedTarget || !ref.current.contains(e.relatedTarget)) && state.anchorDate) {
69
70
  state.selectFocusedDate();
70
71
  }