@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,107 @@
1
+ import {hookData as $a074e1e2d0f0a665$export$653eddfc964b0f8a, useSelectedDateDescription as $a074e1e2d0f0a665$export$b6df97c887c38e1a, useVisibleRangeDescription as $a074e1e2d0f0a665$export$31afe65d91ef6e8} from "./utils.module.js";
2
+ import $g2t6q$intlStringsmodulejs from "./intlStrings.module.js";
3
+ import {announce as $g2t6q$announce} from "@react-aria/live-announcer";
4
+ import {filterDOMProps as $g2t6q$filterDOMProps, useUpdateEffect as $g2t6q$useUpdateEffect, useSlotId as $g2t6q$useSlotId, useLabels as $g2t6q$useLabels, mergeProps as $g2t6q$mergeProps} from "@react-aria/utils";
5
+ import {useLocalizedStringFormatter as $g2t6q$useLocalizedStringFormatter} from "@react-aria/i18n";
6
+ import {useState as $g2t6q$useState} from "react";
7
+
8
+
9
+ function $parcel$interopDefault(a) {
10
+ return a && a.__esModule ? a.default : a;
11
+ }
12
+ /*
13
+ * Copyright 2020 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+
27
+
28
+ function $c4acc1de3ab169cf$export$d652b3ea2d672d5b(props, state) {
29
+ let stringFormatter = (0, $g2t6q$useLocalizedStringFormatter)((0, ($parcel$interopDefault($g2t6q$intlStringsmodulejs))), "@react-aria/calendar");
30
+ let domProps = (0, $g2t6q$filterDOMProps)(props);
31
+ let title = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);
32
+ let visibleRangeDescription = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, true);
33
+ // Announce when the visible date range changes
34
+ (0, $g2t6q$useUpdateEffect)(()=>{
35
+ // only when pressing the Previous or Next button
36
+ if (!state.isFocused) (0, $g2t6q$announce)(visibleRangeDescription);
37
+ }, [
38
+ visibleRangeDescription
39
+ ]);
40
+ // Announce when the selected value changes
41
+ let selectedDateDescription = (0, $a074e1e2d0f0a665$export$b6df97c887c38e1a)(state);
42
+ (0, $g2t6q$useUpdateEffect)(()=>{
43
+ if (selectedDateDescription) (0, $g2t6q$announce)(selectedDateDescription, "polite", 4000);
44
+ // handle an update to the caption that describes the currently selected range, to announce the new value
45
+ }, [
46
+ selectedDateDescription
47
+ ]);
48
+ let errorMessageId = (0, $g2t6q$useSlotId)([
49
+ Boolean(props.errorMessage),
50
+ props.isInvalid,
51
+ props.validationState
52
+ ]);
53
+ // Pass the label to the child grid elements.
54
+ (0, $a074e1e2d0f0a665$export$653eddfc964b0f8a).set(state, {
55
+ ariaLabel: props["aria-label"],
56
+ ariaLabelledBy: props["aria-labelledby"],
57
+ errorMessageId: errorMessageId,
58
+ selectedDateDescription: selectedDateDescription
59
+ });
60
+ // If the next or previous buttons become disabled while they are focused, move focus to the calendar body.
61
+ let [nextFocused, setNextFocused] = (0, $g2t6q$useState)(false);
62
+ let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();
63
+ if (nextDisabled && nextFocused) {
64
+ setNextFocused(false);
65
+ state.setFocused(true);
66
+ }
67
+ let [previousFocused, setPreviousFocused] = (0, $g2t6q$useState)(false);
68
+ let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();
69
+ if (previousDisabled && previousFocused) {
70
+ setPreviousFocused(false);
71
+ state.setFocused(true);
72
+ }
73
+ let labelProps = (0, $g2t6q$useLabels)({
74
+ id: props["id"],
75
+ "aria-label": [
76
+ props["aria-label"],
77
+ visibleRangeDescription
78
+ ].filter(Boolean).join(", "),
79
+ "aria-labelledby": props["aria-labelledby"]
80
+ });
81
+ return {
82
+ calendarProps: (0, $g2t6q$mergeProps)(domProps, labelProps, {
83
+ role: "application",
84
+ "aria-describedby": props["aria-describedby"] || undefined
85
+ }),
86
+ nextButtonProps: {
87
+ onPress: ()=>state.focusNextPage(),
88
+ "aria-label": stringFormatter.format("next"),
89
+ isDisabled: nextDisabled,
90
+ onFocusChange: setNextFocused
91
+ },
92
+ prevButtonProps: {
93
+ onPress: ()=>state.focusPreviousPage(),
94
+ "aria-label": stringFormatter.format("previous"),
95
+ isDisabled: previousDisabled,
96
+ onFocusChange: setPreviousFocused
97
+ },
98
+ errorMessageProps: {
99
+ id: errorMessageId
100
+ },
101
+ title: title
102
+ };
103
+ }
104
+
105
+
106
+ export {$c4acc1de3ab169cf$export$d652b3ea2d672d5b as useCalendarBase};
107
+ //# sourceMappingURL=useCalendarBase.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA2BM,SAAS,0CAAgB,KAAuD,EAAE,KAAyC;IAChI,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE;IAE9B,IAAI,QAAQ,CAAA,GAAA,wCAAyB,EAAE,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,YAAY,CAAC,GAAG,EAAE,MAAM,QAAQ,EAAE;IACzG,IAAI,0BAA0B,CAAA,GAAA,wCAAyB,EAAE,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,YAAY,CAAC,GAAG,EAAE,MAAM,QAAQ,EAAE;IAE3H,+CAA+C;IAC/C,CAAA,GAAA,sBAAc,EAAE;QACd,iDAAiD;QACjD,IAAI,CAAC,MAAM,SAAS,EAClB,CAAA,GAAA,eAAO,EAAE;IAEb,GAAG;QAAC;KAAwB;IAE5B,2CAA2C;IAC3C,IAAI,0BAA0B,CAAA,GAAA,yCAAyB,EAAE;IACzD,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,yBACF,CAAA,GAAA,eAAO,EAAE,yBAAyB,UAAU;IAE9C,yGAAyG;IAC3G,GAAG;QAAC;KAAwB;IAE5B,IAAI,iBAAiB,CAAA,GAAA,gBAAQ,EAAE;QAAC,QAAQ,MAAM,YAAY;QAAG,MAAM,SAAS;QAAE,MAAM,eAAe;KAAC;IAEpG,6CAA6C;IAC7C,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC,OAAO;QAClB,WAAW,KAAK,CAAC,aAAa;QAC9B,gBAAgB,KAAK,CAAC,kBAAkB;wBACxC;iCACA;IACF;IAEA,2GAA2G;IAC3G,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7C,IAAI,eAAe,MAAM,UAAU,IAAI,MAAM,yBAAyB;IACtE,IAAI,gBAAgB,aAAa;QAC/B,eAAe;QACf,MAAM,UAAU,CAAC;IACnB;IAEA,IAAI,CAAC,iBAAiB,mBAAmB,GAAG,CAAA,GAAA,eAAO,EAAE;IACrD,IAAI,mBAAmB,MAAM,UAAU,IAAI,MAAM,6BAA6B;IAC9E,IAAI,oBAAoB,iBAAiB;QACvC,mBAAmB;QACnB,MAAM,UAAU,CAAC;IACnB;IAEA,IAAI,aAAa,CAAA,GAAA,gBAAQ,EAAE;QACzB,IAAI,KAAK,CAAC,KAAK;QACf,cAAc;YAAC,KAAK,CAAC,aAAa;YAAE;SAAwB,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;QAClF,mBAAmB,KAAK,CAAC,kBAAkB;IAC7C;IAEA,OAAO;QACL,eAAe,CAAA,GAAA,iBAAS,EAAE,UAAU,YAAY;YAC9C,MAAM;YACN,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;QACnD;QACA,iBAAiB;YACf,SAAS,IAAM,MAAM,aAAa;YAClC,cAAc,gBAAgB,MAAM,CAAC;YACrC,YAAY;YACZ,eAAe;QACjB;QACA,iBAAiB;YACf,SAAS,IAAM,MAAM,iBAAiB;YACtC,cAAc,gBAAgB,MAAM,CAAC;YACrC,YAAY;YACZ,eAAe;QACjB;QACA,mBAAmB;YACjB,IAAI;QACN;eACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarBase.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 {announce} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, DOMProps} from '@react-types/shared';\nimport {CalendarPropsBase} from '@react-types/calendar';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {filterDOMProps, mergeProps, useLabels, useSlotId, useUpdateEffect} from '@react-aria/utils';\nimport {hookData, useSelectedDateDescription, useVisibleRangeDescription} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useState} from 'react';\n\nexport interface CalendarAria {\n /** Props for the calendar grouping element. */\n calendarProps: DOMAttributes,\n /** Props for the next button. */\n nextButtonProps: AriaButtonProps,\n /** Props for the previous button. */\n prevButtonProps: AriaButtonProps,\n /** Props for the error message element, if any. */\n errorMessageProps: DOMAttributes,\n /** A description of the visible date range, for use in the calendar title. */\n title: string\n}\n\nexport function useCalendarBase(props: CalendarPropsBase & DOMProps & AriaLabelingProps, state: CalendarState | RangeCalendarState): CalendarAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let domProps = filterDOMProps(props);\n\n let title = useVisibleRangeDescription(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);\n let visibleRangeDescription = useVisibleRangeDescription(state.visibleRange.start, state.visibleRange.end, state.timeZone, true);\n\n // Announce when the visible date range changes\n useUpdateEffect(() => {\n // only when pressing the Previous or Next button\n if (!state.isFocused) {\n announce(visibleRangeDescription);\n }\n }, [visibleRangeDescription]);\n\n // Announce when the selected value changes\n let selectedDateDescription = useSelectedDateDescription(state);\n useUpdateEffect(() => {\n if (selectedDateDescription) {\n announce(selectedDateDescription, 'polite', 4000);\n }\n // handle an update to the caption that describes the currently selected range, to announce the new value\n }, [selectedDateDescription]);\n\n let errorMessageId = useSlotId([Boolean(props.errorMessage), props.isInvalid, props.validationState]);\n\n // Pass the label to the child grid elements.\n hookData.set(state, {\n ariaLabel: props['aria-label'],\n ariaLabelledBy: props['aria-labelledby'],\n errorMessageId,\n selectedDateDescription\n });\n\n // If the next or previous buttons become disabled while they are focused, move focus to the calendar body.\n let [nextFocused, setNextFocused] = useState(false);\n let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();\n if (nextDisabled && nextFocused) {\n setNextFocused(false);\n state.setFocused(true);\n }\n\n let [previousFocused, setPreviousFocused] = useState(false);\n let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();\n if (previousDisabled && previousFocused) {\n setPreviousFocused(false);\n state.setFocused(true);\n }\n\n let labelProps = useLabels({\n id: props['id'],\n 'aria-label': [props['aria-label'], visibleRangeDescription].filter(Boolean).join(', '),\n 'aria-labelledby': props['aria-labelledby']\n });\n\n return {\n calendarProps: mergeProps(domProps, labelProps, {\n role: 'application',\n 'aria-describedby': props['aria-describedby'] || undefined\n }),\n nextButtonProps: {\n onPress: () => state.focusNextPage(),\n 'aria-label': stringFormatter.format('next'),\n isDisabled: nextDisabled,\n onFocusChange: setNextFocused\n },\n prevButtonProps: {\n onPress: () => state.focusPreviousPage(),\n 'aria-label': stringFormatter.format('previous'),\n isDisabled: previousDisabled,\n onFocusChange: setPreviousFocused\n },\n errorMessageProps: {\n id: errorMessageId\n },\n title\n };\n}\n"],"names":[],"version":3,"file":"useCalendarBase.module.js.map"}
@@ -0,0 +1,276 @@
1
+ var $df1d8e967e73ec8e$exports = require("./utils.main.js");
2
+ var $bd6dc95a3c5ee5cd$exports = require("./intlStrings.main.js");
3
+ var $cuS6T$internationalizeddate = require("@internationalized/date");
4
+ var $cuS6T$reactariautils = require("@react-aria/utils");
5
+ var $cuS6T$reactariainteractions = require("@react-aria/interactions");
6
+ var $cuS6T$react = require("react");
7
+ var $cuS6T$reactariai18n = require("@react-aria/i18n");
8
+
9
+
10
+ function $parcel$interopDefault(a) {
11
+ return a && a.__esModule ? a.default : a;
12
+ }
13
+
14
+ function $parcel$export(e, n, v, s) {
15
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
16
+ }
17
+
18
+ $parcel$export(module.exports, "useCalendarCell", () => $4d833327a32c9193$export$136073280381448e);
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
+
34
+
35
+
36
+ function $4d833327a32c9193$export$136073280381448e(props, state, ref) {
37
+ let { date: date, isDisabled: isDisabled } = props;
38
+ let { errorMessageId: errorMessageId, selectedDateDescription: selectedDateDescription } = (0, $df1d8e967e73ec8e$exports.hookData).get(state);
39
+ let stringFormatter = (0, $cuS6T$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
40
+ let dateFormatter = (0, $cuS6T$reactariai18n.useDateFormatter)({
41
+ weekday: "long",
42
+ day: "numeric",
43
+ month: "long",
44
+ year: "numeric",
45
+ era: (0, $df1d8e967e73ec8e$exports.getEraFormat)(date),
46
+ timeZone: state.timeZone
47
+ });
48
+ let isSelected = state.isSelected(date);
49
+ let isFocused = state.isCellFocused(date);
50
+ isDisabled = isDisabled || state.isCellDisabled(date);
51
+ let isUnavailable = state.isCellUnavailable(date);
52
+ let isSelectable = !isDisabled && !isUnavailable;
53
+ let isInvalid = state.isValueInvalid && ("highlightedRange" in state ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0 : state.value && (0, $cuS6T$internationalizeddate.isSameDay)(state.value, date));
54
+ if (isInvalid) isSelected = true;
55
+ // For performance, reuse the same date object as before if the new date prop is the same.
56
+ // This allows subsequent useMemo results to be reused.
57
+ date = (0, $cuS6T$reactariautils.useDeepMemo)(date, (0, $cuS6T$internationalizeddate.isEqualDay));
58
+ let nativeDate = (0, $cuS6T$react.useMemo)(()=>date.toDate(state.timeZone), [
59
+ date,
60
+ state.timeZone
61
+ ]);
62
+ // aria-label should be localize Day of week, Month, Day and Year without Time.
63
+ let isDateToday = (0, $cuS6T$internationalizeddate.isToday)(date, state.timeZone);
64
+ let label = (0, $cuS6T$react.useMemo)(()=>{
65
+ let label = "";
66
+ // If this is a range calendar, add a description of the full selected range
67
+ // to the first and last selected date.
68
+ if ("highlightedRange" in state && state.value && !state.anchorDate && ((0, $cuS6T$internationalizeddate.isSameDay)(date, state.value.start) || (0, $cuS6T$internationalizeddate.isSameDay)(date, state.value.end))) label = selectedDateDescription + ", ";
69
+ label += dateFormatter.format(nativeDate);
70
+ if (isDateToday) // If date is today, set appropriate string depending on selected state:
71
+ label = stringFormatter.format(isSelected ? "todayDateSelected" : "todayDate", {
72
+ date: label
73
+ });
74
+ else if (isSelected) // If date is selected but not today:
75
+ label = stringFormatter.format("dateSelected", {
76
+ date: label
77
+ });
78
+ if (state.minValue && (0, $cuS6T$internationalizeddate.isSameDay)(date, state.minValue)) label += ", " + stringFormatter.format("minimumDate");
79
+ else if (state.maxValue && (0, $cuS6T$internationalizeddate.isSameDay)(date, state.maxValue)) label += ", " + stringFormatter.format("maximumDate");
80
+ return label;
81
+ }, [
82
+ dateFormatter,
83
+ nativeDate,
84
+ stringFormatter,
85
+ isSelected,
86
+ isDateToday,
87
+ date,
88
+ state,
89
+ selectedDateDescription
90
+ ]);
91
+ // When a cell is focused and this is a range calendar, add a prompt to help
92
+ // screenreader users know that they are in a range selection mode.
93
+ let rangeSelectionPrompt = "";
94
+ if ("anchorDate" in state && isFocused && !state.isReadOnly && isSelectable) {
95
+ // If selection has started add "click to finish selecting range"
96
+ if (state.anchorDate) rangeSelectionPrompt = stringFormatter.format("finishRangeSelectionPrompt");
97
+ else rangeSelectionPrompt = stringFormatter.format("startRangeSelectionPrompt");
98
+ }
99
+ let descriptionProps = (0, $cuS6T$reactariautils.useDescription)(rangeSelectionPrompt);
100
+ let isAnchorPressed = (0, $cuS6T$react.useRef)(false);
101
+ let isRangeBoundaryPressed = (0, $cuS6T$react.useRef)(false);
102
+ let touchDragTimerRef = (0, $cuS6T$react.useRef)(null);
103
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $cuS6T$reactariainteractions.usePress)({
104
+ // When dragging to select a range, we don't want dragging over the original anchor
105
+ // again to trigger onPressStart. Cancel presses immediately when the pointer exits.
106
+ shouldCancelOnPointerExit: "anchorDate" in state && !!state.anchorDate,
107
+ preventFocusOnPress: true,
108
+ isDisabled: !isSelectable || state.isReadOnly,
109
+ onPressStart (e) {
110
+ if (state.isReadOnly) {
111
+ state.setFocusedDate(date);
112
+ return;
113
+ }
114
+ if ("highlightedRange" in state && !state.anchorDate && (e.pointerType === "mouse" || e.pointerType === "touch")) {
115
+ // Allow dragging the start or end date of a range to modify it
116
+ // rather than starting a new selection.
117
+ // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges
118
+ // are constrained to available dates. The user will need to select a new range in this case.
119
+ if (state.highlightedRange && !isInvalid) {
120
+ if ((0, $cuS6T$internationalizeddate.isSameDay)(date, state.highlightedRange.start)) {
121
+ state.setAnchorDate(state.highlightedRange.end);
122
+ state.setFocusedDate(date);
123
+ state.setDragging(true);
124
+ isRangeBoundaryPressed.current = true;
125
+ return;
126
+ } else if ((0, $cuS6T$internationalizeddate.isSameDay)(date, state.highlightedRange.end)) {
127
+ state.setAnchorDate(state.highlightedRange.start);
128
+ state.setFocusedDate(date);
129
+ state.setDragging(true);
130
+ isRangeBoundaryPressed.current = true;
131
+ return;
132
+ }
133
+ }
134
+ let startDragging = ()=>{
135
+ state.setDragging(true);
136
+ touchDragTimerRef.current = null;
137
+ state.selectDate(date);
138
+ state.setFocusedDate(date);
139
+ isAnchorPressed.current = true;
140
+ };
141
+ // Start selection on mouse/touch down so users can drag to select a range.
142
+ // On touch, delay dragging to determine if the user really meant to scroll.
143
+ if (e.pointerType === "touch") touchDragTimerRef.current = setTimeout(startDragging, 200);
144
+ else startDragging();
145
+ }
146
+ },
147
+ onPressEnd () {
148
+ isRangeBoundaryPressed.current = false;
149
+ isAnchorPressed.current = false;
150
+ clearTimeout(touchDragTimerRef.current);
151
+ touchDragTimerRef.current = null;
152
+ },
153
+ onPress () {
154
+ // For non-range selection, always select on press up.
155
+ if (!("anchorDate" in state) && !state.isReadOnly) {
156
+ state.selectDate(date);
157
+ state.setFocusedDate(date);
158
+ }
159
+ },
160
+ onPressUp (e) {
161
+ if (state.isReadOnly) return;
162
+ // If the user tapped quickly, the date won't be selected yet and the
163
+ // timer will still be in progress. In this case, select the date on touch up.
164
+ // Timer is cleared in onPressEnd.
165
+ if ("anchorDate" in state && touchDragTimerRef.current) {
166
+ state.selectDate(date);
167
+ state.setFocusedDate(date);
168
+ }
169
+ if ("anchorDate" in state) {
170
+ if (isRangeBoundaryPressed.current) // When clicking on the start or end date of an already selected range,
171
+ // start a new selection on press up to also allow dragging the date to
172
+ // change the existing range.
173
+ state.setAnchorDate(date);
174
+ else if (state.anchorDate && !isAnchorPressed.current) {
175
+ // When releasing a drag or pressing the end date of a range, select it.
176
+ state.selectDate(date);
177
+ state.setFocusedDate(date);
178
+ } else if (e.pointerType === "keyboard" && !state.anchorDate) {
179
+ // For range selection, auto-advance the focused date by one if using keyboard.
180
+ // This gives an indication that you're selecting a range rather than a single date.
181
+ // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,
182
+ // there will be an announcement to "click to finish selecting range" (above).
183
+ state.selectDate(date);
184
+ let nextDay = date.add({
185
+ days: 1
186
+ });
187
+ if (state.isInvalid(nextDay)) nextDay = date.subtract({
188
+ days: 1
189
+ });
190
+ if (!state.isInvalid(nextDay)) state.setFocusedDate(nextDay);
191
+ } else if (e.pointerType === "virtual") {
192
+ // For screen readers, just select the date on click.
193
+ state.selectDate(date);
194
+ state.setFocusedDate(date);
195
+ }
196
+ }
197
+ }
198
+ });
199
+ let tabIndex = null;
200
+ if (!isDisabled) tabIndex = (0, $cuS6T$internationalizeddate.isSameDay)(date, state.focusedDate) ? 0 : -1;
201
+ // Focus the button in the DOM when the state updates.
202
+ (0, $cuS6T$react.useEffect)(()=>{
203
+ if (isFocused && ref.current) {
204
+ (0, $cuS6T$reactariautils.focusWithoutScrolling)(ref.current);
205
+ // Scroll into view if navigating with a keyboard, otherwise
206
+ // try not to shift the view under the user's mouse/finger.
207
+ // If in a overlay, scrollIntoViewport will only cause scrolling
208
+ // up to the overlay scroll body to prevent overlay shifting.
209
+ // Also only scroll into view if the cell actually got focused.
210
+ // There are some cases where the cell might be disabled or inside,
211
+ // an inert container and we don't want to scroll then.
212
+ if ((0, $cuS6T$reactariainteractions.getInteractionModality)() !== "pointer" && document.activeElement === ref.current) (0, $cuS6T$reactariautils.scrollIntoViewport)(ref.current, {
213
+ containingElement: (0, $cuS6T$reactariautils.getScrollParent)(ref.current)
214
+ });
215
+ }
216
+ }, [
217
+ isFocused,
218
+ ref
219
+ ]);
220
+ let cellDateFormatter = (0, $cuS6T$reactariai18n.useDateFormatter)({
221
+ day: "numeric",
222
+ timeZone: state.timeZone,
223
+ calendar: date.calendar.identifier
224
+ });
225
+ let formattedDate = (0, $cuS6T$react.useMemo)(()=>cellDateFormatter.formatToParts(nativeDate).find((part)=>part.type === "day").value, [
226
+ cellDateFormatter,
227
+ nativeDate
228
+ ]);
229
+ return {
230
+ cellProps: {
231
+ role: "gridcell",
232
+ "aria-disabled": !isSelectable || null,
233
+ "aria-selected": isSelected || null,
234
+ "aria-invalid": isInvalid || null
235
+ },
236
+ buttonProps: (0, $cuS6T$reactariautils.mergeProps)(pressProps, {
237
+ onFocus () {
238
+ if (!isDisabled) state.setFocusedDate(date);
239
+ },
240
+ tabIndex: tabIndex,
241
+ role: "button",
242
+ "aria-disabled": !isSelectable || null,
243
+ "aria-label": label,
244
+ "aria-invalid": isInvalid || null,
245
+ "aria-describedby": [
246
+ isInvalid ? errorMessageId : null,
247
+ descriptionProps["aria-describedby"]
248
+ ].filter(Boolean).join(" ") || undefined,
249
+ onPointerEnter (e) {
250
+ // Highlight the date on hover or drag over a date when selecting a range.
251
+ if ("highlightDate" in state && (e.pointerType !== "touch" || state.isDragging) && isSelectable) state.highlightDate(date);
252
+ },
253
+ onPointerDown (e) {
254
+ // This is necessary on touch devices to allow dragging
255
+ // outside the original pressed element.
256
+ // (JSDOM does not support this)
257
+ if ("releasePointerCapture" in e.target) e.target.releasePointerCapture(e.pointerId);
258
+ },
259
+ onContextMenu (e) {
260
+ // Prevent context menu on long press.
261
+ e.preventDefault();
262
+ }
263
+ }),
264
+ isPressed: isPressed,
265
+ isFocused: isFocused,
266
+ isSelected: isSelected,
267
+ isDisabled: isDisabled,
268
+ isUnavailable: isUnavailable,
269
+ isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,
270
+ isInvalid: isInvalid,
271
+ formattedDate: formattedDate
272
+ };
273
+ }
274
+
275
+
276
+ //# sourceMappingURL=useCalendarCell.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAgEM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC,EAAE,GAA2B;IAClI,IAAI,QAAC,IAAI,cAAE,UAAU,EAAC,GAAG;IACzB,IAAI,kBAAC,cAAc,2BAAE,uBAAuB,EAAC,GAAG,CAAA,GAAA,kCAAO,E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AuD;gBACvD,wCAAwC;gBACxC,gCAAgC;gBAChC,IAAI,2BAA2B,EAAE,MAAM,EACrC,EAAE,MAAM,CAAC,qBAAqB,CAAC,EAAE,SAAS;YAE9C;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} 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 {RefObject, useEffect, useMemo, useRef} from 'react';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\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\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>): 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);\n isDisabled = isDisabled || state.isCellDisabled(date);\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isInvalid = state.isValueInvalid && (\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(null);\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 = null;\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 = null;\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 = null;\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 || null,\n 'aria-selected': isSelected || null,\n 'aria-invalid': isInvalid || null\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 || null,\n 'aria-label': label,\n 'aria-invalid': isInvalid || null,\n 'aria-describedby': [\n isInvalid ? errorMessageId : null,\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"}