@react-aria/datepicker 3.16.1 → 3.17.0

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 (221) hide show
  1. package/dist/import.mjs +6 -6
  2. package/dist/main.js +11 -11
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -6
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +12 -0
  7. package/package.json +16 -28
  8. package/src/index.ts +13 -11
  9. package/dist/ar-AE.main.js +0 -21
  10. package/dist/ar-AE.main.js.map +0 -1
  11. package/dist/ar-AE.mjs +0 -23
  12. package/dist/ar-AE.module.js +0 -23
  13. package/dist/ar-AE.module.js.map +0 -1
  14. package/dist/bg-BG.main.js +0 -21
  15. package/dist/bg-BG.main.js.map +0 -1
  16. package/dist/bg-BG.mjs +0 -23
  17. package/dist/bg-BG.module.js +0 -23
  18. package/dist/bg-BG.module.js.map +0 -1
  19. package/dist/cs-CZ.main.js +0 -21
  20. package/dist/cs-CZ.main.js.map +0 -1
  21. package/dist/cs-CZ.mjs +0 -23
  22. package/dist/cs-CZ.module.js +0 -23
  23. package/dist/cs-CZ.module.js.map +0 -1
  24. package/dist/da-DK.main.js +0 -21
  25. package/dist/da-DK.main.js.map +0 -1
  26. package/dist/da-DK.mjs +0 -23
  27. package/dist/da-DK.module.js +0 -23
  28. package/dist/da-DK.module.js.map +0 -1
  29. package/dist/de-DE.main.js +0 -21
  30. package/dist/de-DE.main.js.map +0 -1
  31. package/dist/de-DE.mjs +0 -23
  32. package/dist/de-DE.module.js +0 -23
  33. package/dist/de-DE.module.js.map +0 -1
  34. package/dist/el-GR.main.js +0 -21
  35. package/dist/el-GR.main.js.map +0 -1
  36. package/dist/el-GR.mjs +0 -23
  37. package/dist/el-GR.module.js +0 -23
  38. package/dist/el-GR.module.js.map +0 -1
  39. package/dist/en-US.main.js +0 -21
  40. package/dist/en-US.main.js.map +0 -1
  41. package/dist/en-US.mjs +0 -23
  42. package/dist/en-US.module.js +0 -23
  43. package/dist/en-US.module.js.map +0 -1
  44. package/dist/es-ES.main.js +0 -21
  45. package/dist/es-ES.main.js.map +0 -1
  46. package/dist/es-ES.mjs +0 -23
  47. package/dist/es-ES.module.js +0 -23
  48. package/dist/es-ES.module.js.map +0 -1
  49. package/dist/et-EE.main.js +0 -21
  50. package/dist/et-EE.main.js.map +0 -1
  51. package/dist/et-EE.mjs +0 -23
  52. package/dist/et-EE.module.js +0 -23
  53. package/dist/et-EE.module.js.map +0 -1
  54. package/dist/fi-FI.main.js +0 -21
  55. package/dist/fi-FI.main.js.map +0 -1
  56. package/dist/fi-FI.mjs +0 -23
  57. package/dist/fi-FI.module.js +0 -23
  58. package/dist/fi-FI.module.js.map +0 -1
  59. package/dist/fr-FR.main.js +0 -21
  60. package/dist/fr-FR.main.js.map +0 -1
  61. package/dist/fr-FR.mjs +0 -23
  62. package/dist/fr-FR.module.js +0 -23
  63. package/dist/fr-FR.module.js.map +0 -1
  64. package/dist/he-IL.main.js +0 -21
  65. package/dist/he-IL.main.js.map +0 -1
  66. package/dist/he-IL.mjs +0 -23
  67. package/dist/he-IL.module.js +0 -23
  68. package/dist/he-IL.module.js.map +0 -1
  69. package/dist/hr-HR.main.js +0 -21
  70. package/dist/hr-HR.main.js.map +0 -1
  71. package/dist/hr-HR.mjs +0 -23
  72. package/dist/hr-HR.module.js +0 -23
  73. package/dist/hr-HR.module.js.map +0 -1
  74. package/dist/hu-HU.main.js +0 -21
  75. package/dist/hu-HU.main.js.map +0 -1
  76. package/dist/hu-HU.mjs +0 -23
  77. package/dist/hu-HU.module.js +0 -23
  78. package/dist/hu-HU.module.js.map +0 -1
  79. package/dist/intlStrings.main.js +0 -108
  80. package/dist/intlStrings.main.js.map +0 -1
  81. package/dist/intlStrings.mjs +0 -110
  82. package/dist/intlStrings.module.js +0 -110
  83. package/dist/intlStrings.module.js.map +0 -1
  84. package/dist/it-IT.main.js +0 -21
  85. package/dist/it-IT.main.js.map +0 -1
  86. package/dist/it-IT.mjs +0 -23
  87. package/dist/it-IT.module.js +0 -23
  88. package/dist/it-IT.module.js.map +0 -1
  89. package/dist/ja-JP.main.js +0 -21
  90. package/dist/ja-JP.main.js.map +0 -1
  91. package/dist/ja-JP.mjs +0 -23
  92. package/dist/ja-JP.module.js +0 -23
  93. package/dist/ja-JP.module.js.map +0 -1
  94. package/dist/ko-KR.main.js +0 -21
  95. package/dist/ko-KR.main.js.map +0 -1
  96. package/dist/ko-KR.mjs +0 -23
  97. package/dist/ko-KR.module.js +0 -23
  98. package/dist/ko-KR.module.js.map +0 -1
  99. package/dist/lt-LT.main.js +0 -21
  100. package/dist/lt-LT.main.js.map +0 -1
  101. package/dist/lt-LT.mjs +0 -23
  102. package/dist/lt-LT.module.js +0 -23
  103. package/dist/lt-LT.module.js.map +0 -1
  104. package/dist/lv-LV.main.js +0 -21
  105. package/dist/lv-LV.main.js.map +0 -1
  106. package/dist/lv-LV.mjs +0 -23
  107. package/dist/lv-LV.module.js +0 -23
  108. package/dist/lv-LV.module.js.map +0 -1
  109. package/dist/nb-NO.main.js +0 -21
  110. package/dist/nb-NO.main.js.map +0 -1
  111. package/dist/nb-NO.mjs +0 -23
  112. package/dist/nb-NO.module.js +0 -23
  113. package/dist/nb-NO.module.js.map +0 -1
  114. package/dist/nl-NL.main.js +0 -21
  115. package/dist/nl-NL.main.js.map +0 -1
  116. package/dist/nl-NL.mjs +0 -23
  117. package/dist/nl-NL.module.js +0 -23
  118. package/dist/nl-NL.module.js.map +0 -1
  119. package/dist/pl-PL.main.js +0 -21
  120. package/dist/pl-PL.main.js.map +0 -1
  121. package/dist/pl-PL.mjs +0 -23
  122. package/dist/pl-PL.module.js +0 -23
  123. package/dist/pl-PL.module.js.map +0 -1
  124. package/dist/pt-BR.main.js +0 -21
  125. package/dist/pt-BR.main.js.map +0 -1
  126. package/dist/pt-BR.mjs +0 -23
  127. package/dist/pt-BR.module.js +0 -23
  128. package/dist/pt-BR.module.js.map +0 -1
  129. package/dist/pt-PT.main.js +0 -21
  130. package/dist/pt-PT.main.js.map +0 -1
  131. package/dist/pt-PT.mjs +0 -23
  132. package/dist/pt-PT.module.js +0 -23
  133. package/dist/pt-PT.module.js.map +0 -1
  134. package/dist/ro-RO.main.js +0 -21
  135. package/dist/ro-RO.main.js.map +0 -1
  136. package/dist/ro-RO.mjs +0 -23
  137. package/dist/ro-RO.module.js +0 -23
  138. package/dist/ro-RO.module.js.map +0 -1
  139. package/dist/ru-RU.main.js +0 -21
  140. package/dist/ru-RU.main.js.map +0 -1
  141. package/dist/ru-RU.mjs +0 -23
  142. package/dist/ru-RU.module.js +0 -23
  143. package/dist/ru-RU.module.js.map +0 -1
  144. package/dist/sk-SK.main.js +0 -21
  145. package/dist/sk-SK.main.js.map +0 -1
  146. package/dist/sk-SK.mjs +0 -23
  147. package/dist/sk-SK.module.js +0 -23
  148. package/dist/sk-SK.module.js.map +0 -1
  149. package/dist/sl-SI.main.js +0 -21
  150. package/dist/sl-SI.main.js.map +0 -1
  151. package/dist/sl-SI.mjs +0 -23
  152. package/dist/sl-SI.module.js +0 -23
  153. package/dist/sl-SI.module.js.map +0 -1
  154. package/dist/sr-SP.main.js +0 -21
  155. package/dist/sr-SP.main.js.map +0 -1
  156. package/dist/sr-SP.mjs +0 -23
  157. package/dist/sr-SP.module.js +0 -23
  158. package/dist/sr-SP.module.js.map +0 -1
  159. package/dist/sv-SE.main.js +0 -21
  160. package/dist/sv-SE.main.js.map +0 -1
  161. package/dist/sv-SE.mjs +0 -23
  162. package/dist/sv-SE.module.js +0 -23
  163. package/dist/sv-SE.module.js.map +0 -1
  164. package/dist/tr-TR.main.js +0 -21
  165. package/dist/tr-TR.main.js.map +0 -1
  166. package/dist/tr-TR.mjs +0 -23
  167. package/dist/tr-TR.module.js +0 -23
  168. package/dist/tr-TR.module.js.map +0 -1
  169. package/dist/types.d.ts +0 -108
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/uk-UA.main.js +0 -21
  172. package/dist/uk-UA.main.js.map +0 -1
  173. package/dist/uk-UA.mjs +0 -23
  174. package/dist/uk-UA.module.js +0 -23
  175. package/dist/uk-UA.module.js.map +0 -1
  176. package/dist/useDateField.main.js +0 -181
  177. package/dist/useDateField.main.js.map +0 -1
  178. package/dist/useDateField.mjs +0 -172
  179. package/dist/useDateField.module.js +0 -172
  180. package/dist/useDateField.module.js.map +0 -1
  181. package/dist/useDatePicker.main.js +0 -178
  182. package/dist/useDatePicker.main.js.map +0 -1
  183. package/dist/useDatePicker.mjs +0 -173
  184. package/dist/useDatePicker.module.js +0 -173
  185. package/dist/useDatePicker.module.js.map +0 -1
  186. package/dist/useDatePickerGroup.main.js +0 -120
  187. package/dist/useDatePickerGroup.main.js.map +0 -1
  188. package/dist/useDatePickerGroup.mjs +0 -115
  189. package/dist/useDatePickerGroup.module.js +0 -115
  190. package/dist/useDatePickerGroup.module.js.map +0 -1
  191. package/dist/useDateRangePicker.main.js +0 -224
  192. package/dist/useDateRangePicker.main.js.map +0 -1
  193. package/dist/useDateRangePicker.mjs +0 -219
  194. package/dist/useDateRangePicker.module.js +0 -219
  195. package/dist/useDateRangePicker.module.js.map +0 -1
  196. package/dist/useDateSegment.main.js +0 -370
  197. package/dist/useDateSegment.main.js.map +0 -1
  198. package/dist/useDateSegment.mjs +0 -361
  199. package/dist/useDateSegment.module.js +0 -361
  200. package/dist/useDateSegment.module.js.map +0 -1
  201. package/dist/useDisplayNames.main.js +0 -58
  202. package/dist/useDisplayNames.main.js.map +0 -1
  203. package/dist/useDisplayNames.mjs +0 -53
  204. package/dist/useDisplayNames.module.js +0 -53
  205. package/dist/useDisplayNames.module.js.map +0 -1
  206. package/dist/zh-CN.main.js +0 -21
  207. package/dist/zh-CN.main.js.map +0 -1
  208. package/dist/zh-CN.mjs +0 -23
  209. package/dist/zh-CN.module.js +0 -23
  210. package/dist/zh-CN.module.js.map +0 -1
  211. package/dist/zh-TW.main.js +0 -21
  212. package/dist/zh-TW.main.js.map +0 -1
  213. package/dist/zh-TW.mjs +0 -23
  214. package/dist/zh-TW.module.js +0 -23
  215. package/dist/zh-TW.module.js.map +0 -1
  216. package/src/useDateField.ts +0 -213
  217. package/src/useDatePicker.ts +0 -192
  218. package/src/useDatePickerGroup.ts +0 -138
  219. package/src/useDateRangePicker.ts +0 -243
  220. package/src/useDateSegment.ts +0 -413
  221. package/src/useDisplayNames.ts +0 -51
@@ -1,219 +0,0 @@
1
- import {focusManagerSymbol as $16f0b7bb276bc17e$export$7b3062cd49e80452, roleSymbol as $16f0b7bb276bc17e$export$300019f83c56d282} from "./useDateField.module.js";
2
- import $eIQ1H$intlStringsmodulejs from "./intlStrings.module.js";
3
- import {useDatePickerGroup as $3dfb0f96be0d6a08$export$4a931266a3838b86} from "./useDatePickerGroup.module.js";
4
- import {createFocusManager as $eIQ1H$createFocusManager} from "@react-aria/focus";
5
- import {DEFAULT_VALIDATION_RESULT as $eIQ1H$DEFAULT_VALIDATION_RESULT, privateValidationStateProp as $eIQ1H$privateValidationStateProp, mergeValidation as $eIQ1H$mergeValidation} from "@react-stately/form";
6
- import {useDescription as $eIQ1H$useDescription, useId as $eIQ1H$useId, filterDOMProps as $eIQ1H$filterDOMProps, nodeContains as $eIQ1H$nodeContains, mergeProps as $eIQ1H$mergeProps} from "@react-aria/utils";
7
- import {useField as $eIQ1H$useField} from "@react-aria/label";
8
- import {useFocusWithin as $eIQ1H$useFocusWithin} from "@react-aria/interactions";
9
- import {useLocalizedStringFormatter as $eIQ1H$useLocalizedStringFormatter, useLocale as $eIQ1H$useLocale} from "@react-aria/i18n";
10
- import {useMemo as $eIQ1H$useMemo, useRef as $eIQ1H$useRef} from "react";
11
-
12
-
13
- function $parcel$interopDefault(a) {
14
- return a && a.__esModule ? a.default : a;
15
- }
16
- /*
17
- * Copyright 2020 Adobe. All rights reserved.
18
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
- * you may not use this file except in compliance with the License. You may obtain a copy
20
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
21
- *
22
- * Unless required by applicable law or agreed to in writing, software distributed under
23
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24
- * OF ANY KIND, either express or implied. See the License for the specific language
25
- * governing permissions and limitations under the License.
26
- */
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
- function $887cac91b7cc8801$export$12fd5f0e9f4bb192(props, state, ref) {
37
- var _state_value, _state_defaultValue, _state_value1, _state_defaultValue1, _state_dateRange;
38
- let stringFormatter = (0, $eIQ1H$useLocalizedStringFormatter)((0, ($parcel$interopDefault($eIQ1H$intlStringsmodulejs))), '@react-aria/datepicker');
39
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
40
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $eIQ1H$useField)({
41
- ...props,
42
- labelElementType: 'span',
43
- isInvalid: isInvalid,
44
- errorMessage: props.errorMessage || validationErrors
45
- });
46
- let labelledBy = fieldProps['aria-labelledby'] || fieldProps.id;
47
- let { locale: locale } = (0, $eIQ1H$useLocale)();
48
- let range = state.formatValue(locale, {
49
- month: 'long'
50
- });
51
- let description = range ? stringFormatter.format('selectedRangeDescription', {
52
- startDate: range.start,
53
- endDate: range.end
54
- }) : '';
55
- let descProps = (0, $eIQ1H$useDescription)(description);
56
- let startFieldProps = {
57
- 'aria-label': stringFormatter.format('startDate'),
58
- 'aria-labelledby': labelledBy
59
- };
60
- let endFieldProps = {
61
- 'aria-label': stringFormatter.format('endDate'),
62
- 'aria-labelledby': labelledBy
63
- };
64
- let buttonId = (0, $eIQ1H$useId)();
65
- let dialogId = (0, $eIQ1H$useId)();
66
- let groupProps = (0, $3dfb0f96be0d6a08$export$4a931266a3838b86)(state, ref);
67
- let ariaDescribedBy = [
68
- descProps['aria-describedby'],
69
- fieldProps['aria-describedby']
70
- ].filter(Boolean).join(' ') || undefined;
71
- let focusManager = (0, $eIQ1H$useMemo)(()=>(0, $eIQ1H$createFocusManager)(ref, {
72
- // Exclude the button from the focus manager.
73
- accept: (element)=>element.id !== buttonId
74
- }), [
75
- ref,
76
- buttonId
77
- ]);
78
- let commonFieldProps = {
79
- [(0, $16f0b7bb276bc17e$export$7b3062cd49e80452)]: focusManager,
80
- [(0, $16f0b7bb276bc17e$export$300019f83c56d282)]: 'presentation',
81
- 'aria-describedby': ariaDescribedBy,
82
- placeholderValue: props.placeholderValue,
83
- hideTimeZone: props.hideTimeZone,
84
- hourCycle: props.hourCycle,
85
- granularity: props.granularity,
86
- shouldForceLeadingZeros: props.shouldForceLeadingZeros,
87
- isDisabled: props.isDisabled,
88
- isReadOnly: props.isReadOnly,
89
- isRequired: props.isRequired,
90
- validationBehavior: props.validationBehavior
91
- };
92
- let domProps = (0, $eIQ1H$filterDOMProps)(props);
93
- let isFocused = (0, $eIQ1H$useRef)(false);
94
- let { focusWithinProps: focusWithinProps } = (0, $eIQ1H$useFocusWithin)({
95
- ...props,
96
- isDisabled: state.isOpen,
97
- onBlurWithin: (e)=>{
98
- // Ignore when focus moves into the popover.
99
- let dialog = document.getElementById(dialogId);
100
- if (!(0, $eIQ1H$nodeContains)(dialog, e.relatedTarget)) {
101
- var _props_onBlur, _props_onFocusChange;
102
- isFocused.current = false;
103
- (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
104
- (_props_onFocusChange = props.onFocusChange) === null || _props_onFocusChange === void 0 ? void 0 : _props_onFocusChange.call(props, false);
105
- }
106
- },
107
- onFocusWithin: (e)=>{
108
- if (!isFocused.current) {
109
- var _props_onFocus, _props_onFocusChange;
110
- isFocused.current = true;
111
- (_props_onFocus = props.onFocus) === null || _props_onFocus === void 0 ? void 0 : _props_onFocus.call(props, e);
112
- (_props_onFocusChange = props.onFocusChange) === null || _props_onFocusChange === void 0 ? void 0 : _props_onFocusChange.call(props, true);
113
- }
114
- }
115
- });
116
- let startFieldValidation = (0, $eIQ1H$useRef)((0, $eIQ1H$DEFAULT_VALIDATION_RESULT));
117
- let endFieldValidation = (0, $eIQ1H$useRef)((0, $eIQ1H$DEFAULT_VALIDATION_RESULT));
118
- var _state_value_start, _state_value_end;
119
- return {
120
- groupProps: (0, $eIQ1H$mergeProps)(domProps, groupProps, fieldProps, descProps, focusWithinProps, {
121
- role: 'group',
122
- 'aria-disabled': props.isDisabled || null,
123
- 'aria-describedby': ariaDescribedBy,
124
- onKeyDown (e) {
125
- if (state.isOpen) return;
126
- if (props.onKeyDown) props.onKeyDown(e);
127
- },
128
- onKeyUp (e) {
129
- if (state.isOpen) return;
130
- if (props.onKeyUp) props.onKeyUp(e);
131
- }
132
- }),
133
- labelProps: {
134
- ...labelProps,
135
- onClick: ()=>{
136
- focusManager.focusFirst();
137
- }
138
- },
139
- buttonProps: {
140
- ...descProps,
141
- id: buttonId,
142
- 'aria-haspopup': 'dialog',
143
- 'aria-label': stringFormatter.format('calendar'),
144
- 'aria-labelledby': `${buttonId} ${labelledBy}`,
145
- 'aria-describedby': ariaDescribedBy,
146
- 'aria-expanded': state.isOpen,
147
- isDisabled: props.isDisabled || props.isReadOnly,
148
- onPress: ()=>state.setOpen(true)
149
- },
150
- dialogProps: {
151
- id: dialogId,
152
- 'aria-labelledby': `${buttonId} ${labelledBy}`
153
- },
154
- startFieldProps: {
155
- ...startFieldProps,
156
- ...commonFieldProps,
157
- value: (_state_value_start = (_state_value = state.value) === null || _state_value === void 0 ? void 0 : _state_value.start) !== null && _state_value_start !== void 0 ? _state_value_start : null,
158
- defaultValue: (_state_defaultValue = state.defaultValue) === null || _state_defaultValue === void 0 ? void 0 : _state_defaultValue.start,
159
- onChange: (start)=>state.setDateTime('start', start),
160
- autoFocus: props.autoFocus,
161
- name: props.startName,
162
- form: props.form,
163
- [(0, $eIQ1H$privateValidationStateProp)]: {
164
- realtimeValidation: state.realtimeValidation,
165
- displayValidation: state.displayValidation,
166
- updateValidation (e) {
167
- startFieldValidation.current = e;
168
- state.updateValidation((0, $eIQ1H$mergeValidation)(e, endFieldValidation.current));
169
- },
170
- resetValidation: state.resetValidation,
171
- commitValidation: state.commitValidation
172
- }
173
- },
174
- endFieldProps: {
175
- ...endFieldProps,
176
- ...commonFieldProps,
177
- value: (_state_value_end = (_state_value1 = state.value) === null || _state_value1 === void 0 ? void 0 : _state_value1.end) !== null && _state_value_end !== void 0 ? _state_value_end : null,
178
- defaultValue: (_state_defaultValue1 = state.defaultValue) === null || _state_defaultValue1 === void 0 ? void 0 : _state_defaultValue1.end,
179
- onChange: (end)=>state.setDateTime('end', end),
180
- name: props.endName,
181
- form: props.form,
182
- [(0, $eIQ1H$privateValidationStateProp)]: {
183
- realtimeValidation: state.realtimeValidation,
184
- displayValidation: state.displayValidation,
185
- updateValidation (e) {
186
- endFieldValidation.current = e;
187
- state.updateValidation((0, $eIQ1H$mergeValidation)(startFieldValidation.current, e));
188
- },
189
- resetValidation: state.resetValidation,
190
- commitValidation: state.commitValidation
191
- }
192
- },
193
- descriptionProps: descriptionProps,
194
- errorMessageProps: errorMessageProps,
195
- calendarProps: {
196
- autoFocus: true,
197
- value: ((_state_dateRange = state.dateRange) === null || _state_dateRange === void 0 ? void 0 : _state_dateRange.start) && state.dateRange.end ? state.dateRange : null,
198
- onChange: state.setDateRange,
199
- minValue: props.minValue,
200
- maxValue: props.maxValue,
201
- isDisabled: props.isDisabled,
202
- isReadOnly: props.isReadOnly,
203
- isDateUnavailable: props.isDateUnavailable,
204
- allowsNonContiguousRanges: props.allowsNonContiguousRanges,
205
- defaultFocusedValue: state.dateRange ? undefined : props.placeholderValue,
206
- isInvalid: state.isInvalid,
207
- errorMessage: typeof props.errorMessage === 'function' ? props.errorMessage(state.displayValidation) : props.errorMessage || state.displayValidation.validationErrors.join(' '),
208
- firstDayOfWeek: props.firstDayOfWeek,
209
- pageBehavior: props.pageBehavior
210
- },
211
- isInvalid: isInvalid,
212
- validationErrors: validationErrors,
213
- validationDetails: validationDetails
214
- };
215
- }
216
-
217
-
218
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AAU,MAAM,QAAQ;YACxB,YAAY,MAAM,UAAU;YAC5B,YAAY,MAAM,UAAU;YAC5B,mBAAmB,MAAM,iBAAiB;YAC1C,2BAA2B,MAAM,yBAAyB;YAC1D,qBAAqB,MAAM,SAAS,GAAG,YAAY,MAAM,gBAAgB;YACzE,WAAW,MAAM,SAAS;YAC1B,cAAc,OAAO,MAAM,YAAY,KAAK,aAAa,MAAM,YAAY,CAAC,MAAM,iBAAiB,IAAK,MAAM,YAAY,IAAI,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC;YAC5K,gBAAgB,MAAM,cAAc;YACpC,cAAc,MAAM,YAAY;QAClC;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/datepicker/src/useDateRangePicker.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaDatePickerProps, AriaDateRangePickerProps, DateValue} from '@react-types/datepicker';\nimport {AriaDialogProps} from '@react-types/dialog';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DateRange, RangeCalendarProps} from '@react-types/calendar';\nimport {DateRangePickerState} from '@react-stately/datepicker';\nimport {DEFAULT_VALIDATION_RESULT, mergeValidation, privateValidationStateProp} from '@react-stately/form';\nimport {DOMAttributes, GroupDOMAttributes, KeyboardEvent, RefObject, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, nodeContains, useDescription, useId} from '@react-aria/utils';\nimport {focusManagerSymbol, roleSymbol} from './useDateField';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useDatePickerGroup} from './useDatePickerGroup';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMemo, useRef} from 'react';\n\nexport interface DateRangePickerAria extends ValidationResult {\n /** Props for the date range picker's visible label element, if any. */\n labelProps: DOMAttributes,\n /** Props for the grouping element containing the date fields and button. */\n groupProps: GroupDOMAttributes,\n /** Props for the start date field. */\n startFieldProps: AriaDatePickerProps<DateValue>,\n /** Props for the end date field. */\n endFieldProps: AriaDatePickerProps<DateValue>,\n /** Props for the popover trigger button. */\n buttonProps: AriaButtonProps,\n /** Props for the description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the error message element, if any. */\n errorMessageProps: DOMAttributes,\n /** Props for the popover dialog. */\n dialogProps: AriaDialogProps,\n /** Props for the range calendar within the popover dialog. */\n calendarProps: RangeCalendarProps<DateValue>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a date picker component.\n * A date range picker combines two DateFields and a RangeCalendar popover to allow\n * users to enter or select a date and time range.\n */\nexport function useDateRangePicker<T extends DateValue>(props: AriaDateRangePickerProps<T>, state: DateRangePickerState, ref: RefObject<Element | null>): DateRangePickerAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/datepicker');\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let labelledBy = fieldProps['aria-labelledby'] || fieldProps.id;\n\n let {locale} = useLocale();\n let range = state.formatValue(locale, {month: 'long'});\n let description = range ? stringFormatter.format('selectedRangeDescription', {startDate: range.start, endDate: range.end}) : '';\n let descProps = useDescription(description);\n\n let startFieldProps = {\n 'aria-label': stringFormatter.format('startDate'),\n 'aria-labelledby': labelledBy\n };\n\n let endFieldProps = {\n 'aria-label': stringFormatter.format('endDate'),\n 'aria-labelledby': labelledBy\n };\n\n let buttonId = useId();\n let dialogId = useId();\n\n let groupProps = useDatePickerGroup(state, ref);\n\n let ariaDescribedBy = [descProps['aria-describedby'], fieldProps['aria-describedby']].filter(Boolean).join(' ') || undefined;\n let focusManager = useMemo(() => createFocusManager(ref, {\n // Exclude the button from the focus manager.\n accept: element => element.id !== buttonId\n }), [ref, buttonId]);\n\n let commonFieldProps = {\n [focusManagerSymbol]: focusManager,\n [roleSymbol]: 'presentation',\n 'aria-describedby': ariaDescribedBy,\n placeholderValue: props.placeholderValue,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n granularity: props.granularity,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros,\n isDisabled: props.isDisabled,\n isReadOnly: props.isReadOnly,\n isRequired: props.isRequired,\n validationBehavior: props.validationBehavior\n };\n\n let domProps = filterDOMProps(props);\n\n let isFocused = useRef(false);\n let {focusWithinProps} = useFocusWithin({\n ...props,\n isDisabled: state.isOpen,\n onBlurWithin: e => {\n // Ignore when focus moves into the popover.\n let dialog = document.getElementById(dialogId);\n if (!nodeContains(dialog, e.relatedTarget)) {\n isFocused.current = false;\n props.onBlur?.(e);\n props.onFocusChange?.(false);\n }\n },\n onFocusWithin: e => {\n if (!isFocused.current) {\n isFocused.current = true;\n props.onFocus?.(e);\n props.onFocusChange?.(true);\n }\n }\n });\n\n let startFieldValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let endFieldValidation = useRef(DEFAULT_VALIDATION_RESULT);\n\n return {\n groupProps: mergeProps(domProps, groupProps, fieldProps, descProps, focusWithinProps, {\n role: 'group' as const,\n 'aria-disabled': props.isDisabled || null,\n 'aria-describedby': ariaDescribedBy,\n onKeyDown(e: KeyboardEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onKeyDown) {\n props.onKeyDown(e);\n }\n },\n onKeyUp(e: KeyboardEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onKeyUp) {\n props.onKeyUp(e);\n }\n }\n }),\n labelProps: {\n ...labelProps,\n onClick: () => {\n focusManager.focusFirst();\n }\n },\n buttonProps: {\n ...descProps,\n id: buttonId,\n 'aria-haspopup': 'dialog',\n 'aria-label': stringFormatter.format('calendar'),\n 'aria-labelledby': `${buttonId} ${labelledBy}`,\n 'aria-describedby': ariaDescribedBy,\n 'aria-expanded': state.isOpen,\n isDisabled: props.isDisabled || props.isReadOnly,\n onPress: () => state.setOpen(true)\n },\n dialogProps: {\n id: dialogId,\n 'aria-labelledby': `${buttonId} ${labelledBy}`\n },\n startFieldProps: {\n ...startFieldProps,\n ...commonFieldProps,\n value: state.value?.start ?? null,\n defaultValue: state.defaultValue?.start,\n onChange: start => state.setDateTime('start', start),\n autoFocus: props.autoFocus,\n name: props.startName,\n form: props.form,\n [privateValidationStateProp]: {\n realtimeValidation: state.realtimeValidation,\n displayValidation: state.displayValidation,\n updateValidation(e) {\n startFieldValidation.current = e;\n state.updateValidation(mergeValidation(e, endFieldValidation.current));\n },\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation\n }\n },\n endFieldProps: {\n ...endFieldProps,\n ...commonFieldProps,\n value: state.value?.end ?? null,\n defaultValue: state.defaultValue?.end,\n onChange: end => state.setDateTime('end', end),\n name: props.endName,\n form: props.form,\n [privateValidationStateProp]: {\n realtimeValidation: state.realtimeValidation,\n displayValidation: state.displayValidation,\n updateValidation(e) {\n endFieldValidation.current = e;\n state.updateValidation(mergeValidation(startFieldValidation.current, e));\n },\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation\n }\n },\n descriptionProps,\n errorMessageProps,\n calendarProps: {\n autoFocus: true,\n value: state.dateRange?.start && state.dateRange.end ? state.dateRange as DateRange : null,\n onChange: state.setDateRange,\n minValue: props.minValue,\n maxValue: props.maxValue,\n isDisabled: props.isDisabled,\n isReadOnly: props.isReadOnly,\n isDateUnavailable: props.isDateUnavailable,\n allowsNonContiguousRanges: props.allowsNonContiguousRanges,\n defaultFocusedValue: state.dateRange ? undefined : props.placeholderValue,\n isInvalid: state.isInvalid,\n errorMessage: typeof props.errorMessage === 'function' ? props.errorMessage(state.displayValidation) : (props.errorMessage || state.displayValidation.validationErrors.join(' ')),\n firstDayOfWeek: props.firstDayOfWeek,\n pageBehavior: props.pageBehavior\n },\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useDateRangePicker.module.js.map"}
@@ -1,370 +0,0 @@
1
- var $4acc2f407c169e55$exports = require("./useDateField.main.js");
2
- var $934ac650a0aceb4b$exports = require("./useDisplayNames.main.js");
3
- var $5Tgzj$internationalizeddate = require("@internationalized/date");
4
- var $5Tgzj$reactariautils = require("@react-aria/utils");
5
- var $5Tgzj$internationalizednumber = require("@internationalized/number");
6
- var $5Tgzj$react = require("react");
7
- var $5Tgzj$reactariai18n = require("@react-aria/i18n");
8
- var $5Tgzj$reactariaspinbutton = require("@react-aria/spinbutton");
9
-
10
-
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
13
- }
14
-
15
- function $parcel$export(e, n, v, s) {
16
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
17
- }
18
-
19
- $parcel$export(module.exports, "useDateSegment", () => $5c015c6316d1904d$export$1315d136e6f7581);
20
- /*
21
- * Copyright 2020 Adobe. All rights reserved.
22
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
- * you may not use this file except in compliance with the License. You may obtain a copy
24
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software distributed under
27
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
28
- * OF ANY KIND, either express or implied. See the License for the specific language
29
- * governing permissions and limitations under the License.
30
- */
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
- function $5c015c6316d1904d$export$1315d136e6f7581(segment, state, ref) {
39
- let enteredKeys = (0, $5Tgzj$react.useRef)('');
40
- let { locale: locale, direction: direction } = (0, $5Tgzj$reactariai18n.useLocale)();
41
- let displayNames = (0, $934ac650a0aceb4b$exports.useDisplayNames)();
42
- let { ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy, ariaDescribedBy: ariaDescribedBy, focusManager: focusManager } = (0, $4acc2f407c169e55$exports.hookData).get(state);
43
- let textValue = segment.isPlaceholder ? '' : segment.text;
44
- let options = (0, $5Tgzj$react.useMemo)(()=>state.dateFormatter.resolvedOptions(), [
45
- state.dateFormatter
46
- ]);
47
- let monthDateFormatter = (0, $5Tgzj$reactariai18n.useDateFormatter)({
48
- month: 'long',
49
- timeZone: options.timeZone
50
- });
51
- let hourDateFormatter = (0, $5Tgzj$reactariai18n.useDateFormatter)({
52
- hour: 'numeric',
53
- hour12: options.hour12,
54
- timeZone: options.timeZone
55
- });
56
- if (segment.type === 'month' && !segment.isPlaceholder) {
57
- let monthTextValue = monthDateFormatter.format(state.dateValue);
58
- textValue = monthTextValue !== textValue ? `${textValue} \u{2013} ${monthTextValue}` : monthTextValue;
59
- } else if (segment.type === 'hour' && !segment.isPlaceholder) textValue = hourDateFormatter.format(state.dateValue);
60
- var _segment_value;
61
- let { spinButtonProps: spinButtonProps } = (0, $5Tgzj$reactariaspinbutton.useSpinButton)({
62
- // The ARIA spec says aria-valuenow is optional if there's no value, but aXe seems to require it.
63
- // This doesn't seem to have any negative effects with real AT since we also use aria-valuetext.
64
- // https://github.com/dequelabs/axe-core/issues/3505
65
- value: (_segment_value = segment.value) !== null && _segment_value !== void 0 ? _segment_value : undefined,
66
- textValue: textValue,
67
- minValue: segment.minValue,
68
- maxValue: segment.maxValue,
69
- isDisabled: state.isDisabled,
70
- isReadOnly: state.isReadOnly || !segment.isEditable,
71
- isRequired: state.isRequired,
72
- onIncrement: ()=>{
73
- enteredKeys.current = '';
74
- state.increment(segment.type);
75
- },
76
- onDecrement: ()=>{
77
- enteredKeys.current = '';
78
- state.decrement(segment.type);
79
- },
80
- onIncrementPage: ()=>{
81
- enteredKeys.current = '';
82
- state.incrementPage(segment.type);
83
- },
84
- onDecrementPage: ()=>{
85
- enteredKeys.current = '';
86
- state.decrementPage(segment.type);
87
- },
88
- onIncrementToMax: ()=>{
89
- enteredKeys.current = '';
90
- state.incrementToMax(segment.type);
91
- },
92
- onDecrementToMin: ()=>{
93
- enteredKeys.current = '';
94
- state.decrementToMin(segment.type);
95
- }
96
- });
97
- let parser = (0, $5Tgzj$react.useMemo)(()=>new (0, $5Tgzj$internationalizednumber.NumberParser)(locale, {
98
- maximumFractionDigits: 0
99
- }), [
100
- locale
101
- ]);
102
- let backspace = ()=>{
103
- if (segment.text === segment.placeholder) focusManager.focusPrevious();
104
- if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly && !segment.isPlaceholder) {
105
- let newValue = segment.text.slice(0, -1);
106
- let parsed = parser.parse(newValue);
107
- newValue = parsed === 0 ? '' : newValue;
108
- if (newValue.length === 0 || parsed === 0) state.clearSegment(segment.type);
109
- else state.setSegment(segment.type, parsed);
110
- enteredKeys.current = newValue;
111
- } else if (segment.type === 'dayPeriod' || segment.type === 'era') state.clearSegment(segment.type);
112
- };
113
- let onKeyDown = (e)=>{
114
- // Firefox does not fire selectstart for Ctrl/Cmd + A
115
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1742153
116
- if (e.key === 'a' && ((0, $5Tgzj$reactariautils.isMac)() ? e.metaKey : e.ctrlKey)) e.preventDefault();
117
- if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
118
- switch(e.key){
119
- case 'Backspace':
120
- case 'Delete':
121
- // Safari on iOS does not fire beforeinput for the backspace key because the cursor is at the start.
122
- e.preventDefault();
123
- e.stopPropagation();
124
- backspace();
125
- break;
126
- }
127
- };
128
- // Safari dayPeriod option doesn't work...
129
- let { startsWith: startsWith } = (0, $5Tgzj$reactariai18n.useFilter)({
130
- sensitivity: 'base'
131
- });
132
- let amPmFormatter = (0, $5Tgzj$reactariai18n.useDateFormatter)({
133
- hour: 'numeric',
134
- hour12: true
135
- });
136
- let am = (0, $5Tgzj$react.useMemo)(()=>{
137
- let date = new Date();
138
- date.setHours(0);
139
- return amPmFormatter.formatToParts(date).find((part)=>part.type === 'dayPeriod').value;
140
- }, [
141
- amPmFormatter
142
- ]);
143
- let pm = (0, $5Tgzj$react.useMemo)(()=>{
144
- let date = new Date();
145
- date.setHours(12);
146
- return amPmFormatter.formatToParts(date).find((part)=>part.type === 'dayPeriod').value;
147
- }, [
148
- amPmFormatter
149
- ]);
150
- // Get a list of formatted era names so users can type the first character to choose one.
151
- let eraFormatter = (0, $5Tgzj$reactariai18n.useDateFormatter)({
152
- year: 'numeric',
153
- era: 'narrow',
154
- timeZone: 'UTC'
155
- });
156
- let eras = (0, $5Tgzj$react.useMemo)(()=>{
157
- if (segment.type !== 'era') return [];
158
- let date = (0, $5Tgzj$internationalizeddate.toCalendar)(new (0, $5Tgzj$internationalizeddate.CalendarDate)(1, 1, 1), state.calendar);
159
- let eras = state.calendar.getEras().map((era)=>{
160
- let eraDate = date.set({
161
- year: 1,
162
- month: 1,
163
- day: 1,
164
- era: era
165
- }).toDate('UTC');
166
- let parts = eraFormatter.formatToParts(eraDate);
167
- let formatted = parts.find((p)=>p.type === 'era').value;
168
- return {
169
- era: era,
170
- formatted: formatted
171
- };
172
- });
173
- // Remove the common prefix from formatted values. This is so that in calendars with eras like
174
- // ERA0 and ERA1 (e.g. Ethiopic), users can press "0" and "1" to select an era. In other cases,
175
- // the first letter is used.
176
- let prefixLength = $5c015c6316d1904d$var$commonPrefixLength(eras.map((era)=>era.formatted));
177
- if (prefixLength) for (let era of eras)era.formatted = era.formatted.slice(prefixLength);
178
- return eras;
179
- }, [
180
- eraFormatter,
181
- state.calendar,
182
- segment.type
183
- ]);
184
- let onInput = (key)=>{
185
- if (state.isDisabled || state.isReadOnly) return;
186
- let newValue = enteredKeys.current + key;
187
- switch(segment.type){
188
- case 'dayPeriod':
189
- if (startsWith(am, key)) state.setSegment('dayPeriod', 0);
190
- else if (startsWith(pm, key)) state.setSegment('dayPeriod', 1);
191
- else break;
192
- focusManager.focusNext();
193
- break;
194
- case 'era':
195
- {
196
- let matched = eras.find((e)=>startsWith(e.formatted, key));
197
- if (matched) {
198
- state.setSegment('era', matched.era);
199
- focusManager.focusNext();
200
- }
201
- break;
202
- }
203
- case 'day':
204
- case 'hour':
205
- case 'minute':
206
- case 'second':
207
- case 'month':
208
- case 'year':
209
- {
210
- if (!parser.isValidPartialNumber(newValue)) return;
211
- let numberValue = parser.parse(newValue);
212
- let segmentValue = numberValue;
213
- if (segment.maxValue !== undefined && numberValue > segment.maxValue) segmentValue = parser.parse(key);
214
- if (isNaN(numberValue)) return;
215
- state.setSegment(segment.type, segmentValue);
216
- if (segment.maxValue !== undefined && (Number(numberValue + '0') > segment.maxValue || newValue.length >= String(segment.maxValue).length)) {
217
- enteredKeys.current = '';
218
- focusManager.focusNext();
219
- } else enteredKeys.current = newValue;
220
- break;
221
- }
222
- }
223
- };
224
- let onFocus = ()=>{
225
- enteredKeys.current = '';
226
- if (ref.current) (0, $5Tgzj$reactariautils.scrollIntoViewport)(ref.current, {
227
- containingElement: (0, $5Tgzj$reactariautils.getScrollParent)(ref.current)
228
- });
229
- // Collapse selection to start or Chrome won't fire input events.
230
- let selection = window.getSelection();
231
- selection === null || selection === void 0 ? void 0 : selection.collapse(ref.current);
232
- };
233
- let documentRef = (0, $5Tgzj$react.useRef)(typeof document !== 'undefined' ? document : null);
234
- (0, $5Tgzj$reactariautils.useEvent)(documentRef, 'selectionchange', ()=>{
235
- // Enforce that the selection is collapsed when inside a date segment.
236
- // Otherwise, when tapping on a segment in Android Chrome and then entering text,
237
- // composition events will be fired that break the DOM structure and crash the page.
238
- let selection = window.getSelection();
239
- if ((selection === null || selection === void 0 ? void 0 : selection.anchorNode) && (0, $5Tgzj$reactariautils.nodeContains)(ref.current, selection === null || selection === void 0 ? void 0 : selection.anchorNode)) selection.collapse(ref.current);
240
- });
241
- let compositionRef = (0, $5Tgzj$react.useRef)('');
242
- (0, $5Tgzj$reactariautils.useEvent)(ref, 'beforeinput', (e)=>{
243
- if (!ref.current) return;
244
- e.preventDefault();
245
- switch(e.inputType){
246
- case 'deleteContentBackward':
247
- case 'deleteContentForward':
248
- if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly) backspace();
249
- break;
250
- case 'insertCompositionText':
251
- // insertCompositionText cannot be canceled.
252
- // Record the current state of the element so we can restore it in the `input` event below.
253
- compositionRef.current = ref.current.textContent;
254
- // Safari gets stuck in a composition state unless we also assign to the value here.
255
- // eslint-disable-next-line no-self-assign
256
- ref.current.textContent = ref.current.textContent;
257
- break;
258
- default:
259
- if (e.data != null) onInput(e.data);
260
- break;
261
- }
262
- });
263
- (0, $5Tgzj$reactariautils.useEvent)(ref, 'input', (e)=>{
264
- let { inputType: inputType, data: data } = e;
265
- switch(inputType){
266
- case 'insertCompositionText':
267
- // Reset the DOM to how it was in the beforeinput event.
268
- if (ref.current) ref.current.textContent = compositionRef.current;
269
- // Android sometimes fires key presses of letters as composition events. Need to handle am/pm keys here too.
270
- // Can also happen e.g. with Pinyin keyboard on iOS.
271
- if (data != null && (startsWith(am, data) || startsWith(pm, data))) onInput(data);
272
- break;
273
- }
274
- });
275
- (0, $5Tgzj$reactariautils.useLayoutEffect)(()=>{
276
- let element = ref.current;
277
- return ()=>{
278
- // If the focused segment is removed, focus the previous one, or the next one if there was no previous one.
279
- if ((0, $5Tgzj$reactariautils.getActiveElement)() === element) {
280
- let prev = focusManager.focusPrevious();
281
- if (!prev) focusManager.focusNext();
282
- }
283
- };
284
- }, [
285
- ref,
286
- focusManager
287
- ]);
288
- // spinbuttons cannot be focused with VoiceOver on iOS.
289
- let touchPropOverrides = (0, $5Tgzj$reactariautils.isIOS)() || segment.type === 'timeZoneName' ? {
290
- role: 'textbox',
291
- 'aria-valuemax': null,
292
- 'aria-valuemin': null,
293
- 'aria-valuetext': null,
294
- 'aria-valuenow': null
295
- } : {};
296
- // Only apply aria-describedby to the first segment, unless the field is invalid. This avoids it being
297
- // read every time the user navigates to a new segment.
298
- let firstSegment = (0, $5Tgzj$react.useMemo)(()=>state.segments.find((s)=>s.isEditable), [
299
- state.segments
300
- ]);
301
- if (segment !== firstSegment && !state.isInvalid) ariaDescribedBy = undefined;
302
- let id = (0, $5Tgzj$reactariautils.useId)();
303
- let isEditable = !state.isDisabled && !state.isReadOnly && segment.isEditable;
304
- // Prepend the label passed from the field to each segment name.
305
- // This is needed because VoiceOver on iOS does not announce groups.
306
- let name = segment.type === 'literal' ? '' : displayNames.of(segment.type);
307
- let labelProps = (0, $5Tgzj$reactariautils.useLabels)({
308
- 'aria-label': `${name}${ariaLabel ? `, ${ariaLabel}` : ''}${ariaLabelledBy ? ', ' : ''}`,
309
- 'aria-labelledby': ariaLabelledBy
310
- });
311
- // Literal segments should not be visible to screen readers. We don't really need any of the above,
312
- // but the rules of hooks mean hooks cannot be conditional so we have to put this condition here.
313
- if (segment.type === 'literal') return {
314
- segmentProps: {
315
- 'aria-hidden': true
316
- }
317
- };
318
- let segmentStyle = {
319
- caretColor: 'transparent'
320
- };
321
- if (direction === 'rtl') {
322
- // While the bidirectional algorithm seems to work properly on inline elements with actual values, it returns different results for placeholder strings.
323
- // To ensure placeholder render in correct format, we apply the CSS equivalent of LRE (left-to-right embedding). See https://www.unicode.org/reports/tr9/#Explicit_Directional_Embeddings.
324
- // However, we apply this to both placeholders and date segments with an actual value because the date segments will shift around when deleting otherwise.
325
- segmentStyle.unicodeBidi = 'embed';
326
- let format = options[segment.type];
327
- if (format === 'numeric' || format === '2-digit') segmentStyle.direction = 'ltr';
328
- }
329
- return {
330
- segmentProps: (0, $5Tgzj$reactariautils.mergeProps)(spinButtonProps, labelProps, {
331
- id: id,
332
- ...touchPropOverrides,
333
- 'aria-invalid': state.isInvalid ? 'true' : undefined,
334
- 'aria-describedby': ariaDescribedBy,
335
- 'aria-readonly': state.isReadOnly || !segment.isEditable ? 'true' : undefined,
336
- 'data-placeholder': segment.isPlaceholder || undefined,
337
- contentEditable: isEditable,
338
- suppressContentEditableWarning: isEditable,
339
- spellCheck: isEditable ? 'false' : undefined,
340
- autoCorrect: isEditable ? 'off' : undefined,
341
- // Capitalization was changed in React 17...
342
- [parseInt((0, ($parcel$interopDefault($5Tgzj$react))).version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: isEditable ? 'next' : undefined,
343
- inputMode: state.isDisabled || segment.type === 'dayPeriod' || segment.type === 'era' || !isEditable ? undefined : 'numeric',
344
- tabIndex: state.isDisabled ? undefined : 0,
345
- onKeyDown: onKeyDown,
346
- onFocus: onFocus,
347
- style: segmentStyle,
348
- // Prevent pointer events from reaching useDatePickerGroup, and allow native browser behavior to focus the segment.
349
- onPointerDown (e) {
350
- e.stopPropagation();
351
- },
352
- onMouseDown (e) {
353
- e.stopPropagation();
354
- }
355
- })
356
- };
357
- }
358
- function $5c015c6316d1904d$var$commonPrefixLength(strings) {
359
- // Sort the strings, and compare the characters in the first and last to find the common prefix.
360
- strings.sort();
361
- let first = strings[0];
362
- let last = strings[strings.length - 1];
363
- for(let i = 0; i < first.length; i++){
364
- if (first[i] !== last[i]) return i;
365
- }
366
- return 0;
367
- }
368
-
369
-
370
- //# sourceMappingURL=useDateSegment.main.js.map