@react-aria/calendar 3.5.6 → 3.5.7

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 (77) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +4 -778
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +8 -782
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +4 -778
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/pt-BR.mjs +1 -1
  34. package/dist/pt-PT.mjs +1 -1
  35. package/dist/ro-RO.mjs +1 -1
  36. package/dist/ru-RU.mjs +1 -1
  37. package/dist/sk-SK.mjs +1 -1
  38. package/dist/sl-SI.mjs +1 -1
  39. package/dist/sr-SP.mjs +1 -1
  40. package/dist/sv-SE.mjs +1 -1
  41. package/dist/tr-TR.mjs +1 -1
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/uk-UA.mjs +1 -1
  44. package/dist/useCalendar.main.js +25 -0
  45. package/dist/useCalendar.main.js.map +1 -0
  46. package/dist/useCalendar.mjs +20 -0
  47. package/dist/useCalendar.module.js +20 -0
  48. package/dist/useCalendar.module.js.map +1 -0
  49. package/dist/useCalendarBase.main.js +112 -0
  50. package/dist/useCalendarBase.main.js.map +1 -0
  51. package/dist/useCalendarBase.mjs +107 -0
  52. package/dist/useCalendarBase.module.js +107 -0
  53. package/dist/useCalendarBase.module.js.map +1 -0
  54. package/dist/useCalendarCell.main.js +276 -0
  55. package/dist/useCalendarCell.main.js.map +1 -0
  56. package/dist/useCalendarCell.mjs +271 -0
  57. package/dist/useCalendarCell.module.js +271 -0
  58. package/dist/useCalendarCell.module.js.map +1 -0
  59. package/dist/useCalendarGrid.main.js +139 -0
  60. package/dist/useCalendarGrid.main.js.map +1 -0
  61. package/dist/useCalendarGrid.mjs +134 -0
  62. package/dist/useCalendarGrid.module.js +134 -0
  63. package/dist/useCalendarGrid.module.js.map +1 -0
  64. package/dist/useRangeCalendar.main.js +66 -0
  65. package/dist/useRangeCalendar.main.js.map +1 -0
  66. package/dist/useRangeCalendar.mjs +61 -0
  67. package/dist/useRangeCalendar.module.js +61 -0
  68. package/dist/useRangeCalendar.module.js.map +1 -0
  69. package/dist/utils.main.js +138 -0
  70. package/dist/utils.main.js.map +1 -0
  71. package/dist/utils.mjs +130 -0
  72. package/dist/utils.module.js +130 -0
  73. package/dist/utils.module.js.map +1 -0
  74. package/dist/zh-CN.mjs +1 -1
  75. package/dist/zh-TW.mjs +1 -1
  76. package/package.json +11 -11
  77. package/src/useRangeCalendar.ts +6 -5
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAaM,SAAS,0CAAsC,KAAgC,EAAE,KAAyB,EAAE,GAAgC;IACjJ,IAAI,MAAM,CAAA,GAAA,yCAAc,EAAE,OAAO;IAEjC,6EAA6E;IA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\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} from '@react-types/shared';\nimport {RangeCalendarState} from '@react-stately/calendar';\nimport {RefObject, useRef} from 'react';\nimport {useEvent} from '@react-aria/utils';\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>): 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 ref.current.contains(document.activeElement) &&\n (!ref.current.contains(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 || !ref.current.contains(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"}
@@ -0,0 +1,138 @@
1
+ var $bd6dc95a3c5ee5cd$exports = require("./intlStrings.main.js");
2
+ var $idq92$internationalizeddate = require("@internationalized/date");
3
+ var $idq92$reactariai18n = require("@react-aria/i18n");
4
+ var $idq92$react = require("react");
5
+
6
+
7
+ function $parcel$interopDefault(a) {
8
+ return a && a.__esModule ? a.default : a;
9
+ }
10
+
11
+ function $parcel$export(e, n, v, s) {
12
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
13
+ }
14
+
15
+ $parcel$export(module.exports, "hookData", () => $df1d8e967e73ec8e$export$653eddfc964b0f8a);
16
+ $parcel$export(module.exports, "getEraFormat", () => $df1d8e967e73ec8e$export$134cbb7fb09a9522);
17
+ $parcel$export(module.exports, "useSelectedDateDescription", () => $df1d8e967e73ec8e$export$b6df97c887c38e1a);
18
+ $parcel$export(module.exports, "useVisibleRangeDescription", () => $df1d8e967e73ec8e$export$31afe65d91ef6e8);
19
+ /*
20
+ * Copyright 2020 Adobe. All rights reserved.
21
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License. You may obtain a copy
23
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software distributed under
26
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
27
+ * OF ANY KIND, either express or implied. See the License for the specific language
28
+ * governing permissions and limitations under the License.
29
+ */
30
+
31
+
32
+
33
+ const $df1d8e967e73ec8e$export$653eddfc964b0f8a = new WeakMap();
34
+ function $df1d8e967e73ec8e$export$134cbb7fb09a9522(date) {
35
+ return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : undefined;
36
+ }
37
+ function $df1d8e967e73ec8e$export$b6df97c887c38e1a(state) {
38
+ let stringFormatter = (0, $idq92$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
39
+ let start, end;
40
+ if ("highlightedRange" in state) ({ start: start, end: end } = state.highlightedRange || {});
41
+ else start = end = state.value;
42
+ let dateFormatter = (0, $idq92$reactariai18n.useDateFormatter)({
43
+ weekday: "long",
44
+ month: "long",
45
+ year: "numeric",
46
+ day: "numeric",
47
+ era: $df1d8e967e73ec8e$export$134cbb7fb09a9522(start) || $df1d8e967e73ec8e$export$134cbb7fb09a9522(end),
48
+ timeZone: state.timeZone
49
+ });
50
+ let anchorDate = "anchorDate" in state ? state.anchorDate : null;
51
+ return (0, $idq92$react.useMemo)(()=>{
52
+ // No message if currently selecting a range, or there is nothing highlighted.
53
+ if (!anchorDate && start && end) {
54
+ // Use a single date message if the start and end dates are the same day,
55
+ // otherwise include both dates.
56
+ if ((0, $idq92$internationalizeddate.isSameDay)(start, end)) {
57
+ let date = dateFormatter.format(start.toDate(state.timeZone));
58
+ return stringFormatter.format("selectedDateDescription", {
59
+ date: date
60
+ });
61
+ } else {
62
+ let dateRange = $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
63
+ return stringFormatter.format("selectedRangeDescription", {
64
+ dateRange: dateRange
65
+ });
66
+ }
67
+ }
68
+ return "";
69
+ }, [
70
+ start,
71
+ end,
72
+ anchorDate,
73
+ state.timeZone,
74
+ stringFormatter,
75
+ dateFormatter
76
+ ]);
77
+ }
78
+ function $df1d8e967e73ec8e$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
79
+ let stringFormatter = (0, $idq92$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
80
+ let era = $df1d8e967e73ec8e$export$134cbb7fb09a9522(startDate) || $df1d8e967e73ec8e$export$134cbb7fb09a9522(endDate);
81
+ let monthFormatter = (0, $idq92$reactariai18n.useDateFormatter)({
82
+ month: "long",
83
+ year: "numeric",
84
+ era: era,
85
+ calendar: startDate.calendar.identifier,
86
+ timeZone: timeZone
87
+ });
88
+ let dateFormatter = (0, $idq92$reactariai18n.useDateFormatter)({
89
+ month: "long",
90
+ year: "numeric",
91
+ day: "numeric",
92
+ era: era,
93
+ calendar: startDate.calendar.identifier,
94
+ timeZone: timeZone
95
+ });
96
+ return (0, $idq92$react.useMemo)(()=>{
97
+ // Special case for month granularity. Format as a single month if only a
98
+ // single month is visible, otherwise format as a range of months.
99
+ if ((0, $idq92$internationalizeddate.isSameDay)(startDate, (0, $idq92$internationalizeddate.startOfMonth)(startDate))) {
100
+ if ((0, $idq92$internationalizeddate.isSameDay)(endDate, (0, $idq92$internationalizeddate.endOfMonth)(startDate))) return monthFormatter.format(startDate.toDate(timeZone));
101
+ else if ((0, $idq92$internationalizeddate.isSameDay)(endDate, (0, $idq92$internationalizeddate.endOfMonth)(endDate))) return isAria ? $df1d8e967e73ec8e$var$formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone) : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
102
+ }
103
+ return isAria ? $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
104
+ }, [
105
+ startDate,
106
+ endDate,
107
+ monthFormatter,
108
+ dateFormatter,
109
+ stringFormatter,
110
+ timeZone,
111
+ isAria
112
+ ]);
113
+ }
114
+ function $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, start, end, timeZone) {
115
+ let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));
116
+ // Find the separator between the start and end date. This is determined
117
+ // by finding the last shared literal before the end range.
118
+ let separatorIndex = -1;
119
+ for(let i = 0; i < parts.length; i++){
120
+ let part = parts[i];
121
+ if (part.source === "shared" && part.type === "literal") separatorIndex = i;
122
+ else if (part.source === "endRange") break;
123
+ }
124
+ // Now we can combine the parts into start and end strings.
125
+ let startValue = "";
126
+ let endValue = "";
127
+ for(let i = 0; i < parts.length; i++){
128
+ if (i < separatorIndex) startValue += parts[i].value;
129
+ else if (i > separatorIndex) endValue += parts[i].value;
130
+ }
131
+ return stringFormatter.format("dateRange", {
132
+ startDate: startValue,
133
+ endDate: endValue
134
+ });
135
+ }
136
+
137
+
138
+ //# sourceMappingURL=utils.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiBM,MAAM,4CAAW,IAAI;AAErB,SAAS,0CAAa,IAAkB;IAC7C,OAAO,CAAA,iBAAA,2BAAA,KAAM,QAAQ,CAAC,UAAU,MAAK,aAAa,KAAK,GAAG,KAAK,OAAO,UAAU;AAClF;AAEO,SAAS,0CAA2B,KAAyC;IAClF,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAEhE,IAAI,OAAqB;IACzB,IAAI,sBAAsB,OACvB,CAAA,SAAC,KAAK,OAAE,GAAG,EAAC,GAAG,MAAM,gBAAgB,IAAI,CAAC,CAAA;SAE3C,QAAQ,MAAM,MAAM,KAAK;IAG3B,IAAI,gBAAgB,CAAA,GAAA,qCAAe,EAAE;QACnC,SAAS;QACT,OAAO;QACP,MAAM;QACN,KAAK;QACL,KAAK,0CAAa,UAAU,0CAAa;QACzC,UAAU,MAAM,QAAQ;IAC1B;IAEA,IAAI,aAAa,gBAAgB,QAAQ,MAAM,UAAU,GAAG;IAC5D,OAAO,CAA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SAAS,CAAA,GAAA,uCAAS,EAAE,WACvC,OAAO,SACH,kCAAY,gBAAgB,iBAAiB,WAAW,SAAS,YACjE,eAAe,WAAW,CAAC,UAAU,MAAM,CAAC,WAAW,QAAQ,MAAM,CAAC;QAE9E;QAEA,OAAO,SACH,kCAAY,eAAe,iBAAiB,WAAW,SAAS,YAChE,cAAc,WAAW,CAAC,UAAU,MAAM,CAAC,WAAW,QAAQ,MAAM,CAAC;IAC3E,GAAG;QAAC;QAAW;QAAS;QAAgB;QAAe;QAAiB;QAAU;KAAO;AAC3F;AAEA,SAAS,kCAAY,aAA4B,EAAE,eAAyC,EAAE,KAAmB,EAAE,GAAiB,EAAE,QAAgB;IACpJ,IAAI,QAAQ,cAAc,kBAAkB,CAAC,MAAM,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC;IAEhF,wEAAwE;IACxE,2DAA2D;IAC3D,IAAI,iBAAiB;IACrB,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,OAAO,KAAK,CAAC,EAAE;QACnB,IAAI,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI,KAAK,WAC5C,iBAAiB;aACZ,IAAI,KAAK,MAAM,KAAK,YACzB;IAEJ;IAEA,2DAA2D;IAC3D,IAAI,aAAa;IACjB,IAAI,WAAW;IACf,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,IAAI,gBACN,cAAc,KAAK,CAAC,EAAE,CAAC,KAAK;aACvB,IAAI,IAAI,gBACb,YAAY,KAAK,CAAC,EAAE,CAAC,KAAK;IAE9B;IAEA,OAAO,gBAAgB,MAAM,CAAC,aAAa;QAAC,WAAW;QAAY,SAAS;IAAQ;AACtF","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.main.js.map"}
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.mjs.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":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiBM,MAAM,4CAAW,IAAI;AAErB,SAAS,0CAAa,IAAkB;IAC7C,OAAO,CAAA,iBAAA,2BAAA,KAAM,QAAQ,CAAC,UAAU,MAAK,aAAa,KAAK,GAAG,KAAK,OAAO,UAAU;AAClF;AAEO,SAAS,0CAA2B,KAAyC;IAClF,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAEhE,IAAI,OAAqB;IACzB,IAAI,sBAAsB,OACvB,CAAA,SAAC,KAAK,OAAE,GAAG,EAAC,GAAG,MAAM,gBAAgB,IAAI,CAAC,CAAA;SAE3C,QAAQ,MAAM,MAAM,KAAK;IAG3B,IAAI,gBAAgB,CAAA,GAAA,uBAAe,EAAE;QACnC,SAAS;QACT,OAAO;QACP,MAAM;QACN,KAAK;QACL,KAAK,0CAAa,UAAU,0CAAa;QACzC,UAAU,MAAM,QAAQ;IAC1B;IAEA,IAAI,aAAa,gBAAgB,QAAQ,MAAM,UAAU,GAAG;IAC5D,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,8EAA8E;QAC9E,IAAI,CAAC,cAAc,SAAS;YAC1B,yEAAyE;YACzE,gCAAgC;YAChC,IAAI,CAAA,GAAA,gBAAQ,EAAE,OAAO,MAAM;gBACzB,IAAI,OAAO,cAAc,MAAM,CAAC,MAAM,MAAM,CAAC,MAAM,QAAQ;gBAC3D,OAAO,gBAAgB,MAAM,CAAC,2BAA2B;0BAAC;gBAAI;YAChE,OAAO;gBACL,IAAI,YAAY,kCAAY,eAAe,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Ae;QAAiB;QAAU;KAAO;AAC3F;AAEA,SAAS,kCAAY,aAA4B,EAAE,eAAyC,EAAE,KAAmB,EAAE,GAAiB,EAAE,QAAgB;IACpJ,IAAI,QAAQ,cAAc,kBAAkB,CAAC,MAAM,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC;IAEhF,wEAAwE;IACxE,2DAA2D;IAC3D,IAAI,iBAAiB;IACrB,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,OAAO,KAAK,CAAC,EAAE;QACnB,IAAI,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI,KAAK,WAC5C,iBAAiB;aACZ,IAAI,KAAK,MAAM,KAAK,YACzB;IAEJ;IAEA,2DAA2D;IAC3D,IAAI,aAAa;IACjB,IAAI,WAAW;IACf,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,IAAI,gBACN,cAAc,KAAK,CAAC,EAAE,CAAC,KAAK;aACvB,IAAI,IAAI,gBACb,YAAY,KAAK,CAAC,EAAE,CAAC,KAAK;IAE9B;IAEA,OAAO,gBAAgB,MAAM,CAAC,aAAa;QAAC,WAAW;QAAY,SAAS;IAAQ;AACtF","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/dist/zh-CN.mjs CHANGED
@@ -16,4 +16,4 @@ $628e140a43dfb330$exports = {
16
16
 
17
17
 
18
18
  export {$628e140a43dfb330$exports as default};
19
- //# sourceMappingURL=zh-CN.module.js.map
19
+ //# sourceMappingURL=zh-CN.mjs.map
package/dist/zh-TW.mjs CHANGED
@@ -16,4 +16,4 @@ $745937250cd4679c$exports = {
16
16
 
17
17
 
18
18
  export {$745937250cd4679c$exports as default};
19
- //# sourceMappingURL=zh-TW.module.js.map
19
+ //# sourceMappingURL=zh-TW.mjs.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.7",
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.3",
26
+ "@react-aria/i18n": "^3.11.0",
27
+ "@react-aria/interactions": "^3.21.2",
28
+ "@react-aria/live-announcer": "^3.3.3",
29
+ "@react-aria/utils": "^3.24.0",
30
+ "@react-stately/calendar": "^3.5.0",
31
+ "@react-types/button": "^3.9.3",
32
+ "@react-types/calendar": "^3.4.5",
33
+ "@react-types/shared": "^3.23.0",
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": "f645f29edc1322153fd60af4640cbcab1d992dbd"
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
  }