@react-aria/datepicker 3.10.0 → 3.11.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 (71) 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/intlStrings.mjs +1 -1
  16. package/dist/it-IT.mjs +1 -1
  17. package/dist/ja-JP.mjs +1 -1
  18. package/dist/ko-KR.mjs +1 -1
  19. package/dist/lt-LT.mjs +1 -1
  20. package/dist/lv-LV.mjs +1 -1
  21. package/dist/nb-NO.mjs +1 -1
  22. package/dist/nl-NL.mjs +1 -1
  23. package/dist/pl-PL.mjs +1 -1
  24. package/dist/pt-BR.mjs +1 -1
  25. package/dist/pt-PT.mjs +1 -1
  26. package/dist/ro-RO.mjs +1 -1
  27. package/dist/ru-RU.mjs +1 -1
  28. package/dist/sk-SK.mjs +1 -1
  29. package/dist/sl-SI.mjs +1 -1
  30. package/dist/sr-SP.mjs +1 -1
  31. package/dist/sv-SE.mjs +1 -1
  32. package/dist/tr-TR.mjs +1 -1
  33. package/dist/types.d.ts +10 -10
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/uk-UA.mjs +1 -1
  36. package/dist/useDateField.main.js +27 -26
  37. package/dist/useDateField.main.js.map +1 -1
  38. package/dist/useDateField.mjs +28 -27
  39. package/dist/useDateField.module.js +27 -26
  40. package/dist/useDateField.module.js.map +1 -1
  41. package/dist/useDatePicker.main.js +23 -23
  42. package/dist/useDatePicker.main.js.map +1 -1
  43. package/dist/useDatePicker.mjs +24 -24
  44. package/dist/useDatePicker.module.js +23 -23
  45. package/dist/useDatePicker.module.js.map +1 -1
  46. package/dist/useDatePickerGroup.main.js +10 -10
  47. package/dist/useDatePickerGroup.main.js.map +1 -1
  48. package/dist/useDatePickerGroup.mjs +11 -11
  49. package/dist/useDatePickerGroup.module.js +10 -10
  50. package/dist/useDatePickerGroup.module.js.map +1 -1
  51. package/dist/useDateRangePicker.main.js +28 -28
  52. package/dist/useDateRangePicker.main.js.map +1 -1
  53. package/dist/useDateRangePicker.mjs +29 -29
  54. package/dist/useDateRangePicker.module.js +28 -28
  55. package/dist/useDateRangePicker.module.js.map +1 -1
  56. package/dist/useDateSegment.main.js +79 -72
  57. package/dist/useDateSegment.main.js.map +1 -1
  58. package/dist/useDateSegment.mjs +80 -73
  59. package/dist/useDateSegment.module.js +79 -72
  60. package/dist/useDateSegment.module.js.map +1 -1
  61. package/dist/useDisplayNames.main.js +2 -2
  62. package/dist/useDisplayNames.mjs +3 -3
  63. package/dist/useDisplayNames.module.js +2 -2
  64. package/dist/zh-CN.mjs +1 -1
  65. package/dist/zh-TW.mjs +1 -1
  66. package/package.json +21 -21
  67. package/src/useDateField.ts +8 -7
  68. package/src/useDatePicker.ts +3 -3
  69. package/src/useDatePickerGroup.ts +4 -4
  70. package/src/useDateRangePicker.ts +3 -3
  71. package/src/useDateSegment.ts +15 -5
@@ -26,27 +26,27 @@ import {useSpinButton as $4d1jn$useSpinButton} from "@react-aria/spinbutton";
26
26
 
27
27
 
28
28
  function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
29
- let enteredKeys = (0, $4d1jn$useRef)("");
29
+ let enteredKeys = (0, $4d1jn$useRef)('');
30
30
  let { locale: locale } = (0, $4d1jn$useLocale)();
31
31
  let displayNames = (0, $3aeceb3a64eb8358$export$d42c60378c8168f8)();
32
32
  let { ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy, ariaDescribedBy: ariaDescribedBy, focusManager: focusManager } = (0, $16f0b7bb276bc17e$export$653eddfc964b0f8a).get(state);
33
- let textValue = segment.isPlaceholder ? "" : segment.text;
33
+ let textValue = segment.isPlaceholder ? '' : segment.text;
34
34
  let options = (0, $4d1jn$useMemo)(()=>state.dateFormatter.resolvedOptions(), [
35
35
  state.dateFormatter
36
36
  ]);
37
37
  let monthDateFormatter = (0, $4d1jn$useDateFormatter)({
38
- month: "long",
38
+ month: 'long',
39
39
  timeZone: options.timeZone
40
40
  });
41
41
  let hourDateFormatter = (0, $4d1jn$useDateFormatter)({
42
- hour: "numeric",
42
+ hour: 'numeric',
43
43
  hour12: options.hour12,
44
44
  timeZone: options.timeZone
45
45
  });
46
- if (segment.type === "month" && !segment.isPlaceholder) {
46
+ if (segment.type === 'month' && !segment.isPlaceholder) {
47
47
  let monthTextValue = monthDateFormatter.format(state.dateValue);
48
48
  textValue = monthTextValue !== textValue ? `${textValue} \u{2013} ${monthTextValue}` : monthTextValue;
49
- } else if (segment.type === "hour" && !segment.isPlaceholder) textValue = hourDateFormatter.format(state.dateValue);
49
+ } else if (segment.type === 'hour' && !segment.isPlaceholder) textValue = hourDateFormatter.format(state.dateValue);
50
50
  let { spinButtonProps: spinButtonProps } = (0, $4d1jn$useSpinButton)({
51
51
  // The ARIA spec says aria-valuenow is optional if there's no value, but aXe seems to require it.
52
52
  // This doesn't seem to have any negative effects with real AT since we also use aria-valuetext.
@@ -59,27 +59,27 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
59
59
  isReadOnly: state.isReadOnly || !segment.isEditable,
60
60
  isRequired: state.isRequired,
61
61
  onIncrement: ()=>{
62
- enteredKeys.current = "";
62
+ enteredKeys.current = '';
63
63
  state.increment(segment.type);
64
64
  },
65
65
  onDecrement: ()=>{
66
- enteredKeys.current = "";
66
+ enteredKeys.current = '';
67
67
  state.decrement(segment.type);
68
68
  },
69
69
  onIncrementPage: ()=>{
70
- enteredKeys.current = "";
70
+ enteredKeys.current = '';
71
71
  state.incrementPage(segment.type);
72
72
  },
73
73
  onDecrementPage: ()=>{
74
- enteredKeys.current = "";
74
+ enteredKeys.current = '';
75
75
  state.decrementPage(segment.type);
76
76
  },
77
77
  onIncrementToMax: ()=>{
78
- enteredKeys.current = "";
78
+ enteredKeys.current = '';
79
79
  state.setSegment(segment.type, segment.maxValue);
80
80
  },
81
81
  onDecrementToMin: ()=>{
82
- enteredKeys.current = "";
82
+ enteredKeys.current = '';
83
83
  state.setSegment(segment.type, segment.minValue);
84
84
  }
85
85
  });
@@ -93,20 +93,20 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
93
93
  if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly && !segment.isPlaceholder) {
94
94
  let newValue = segment.text.slice(0, -1);
95
95
  let parsed = parser.parse(newValue);
96
- newValue = parsed === 0 ? "" : newValue;
96
+ newValue = parsed === 0 ? '' : newValue;
97
97
  if (newValue.length === 0 || parsed === 0) state.clearSegment(segment.type);
98
98
  else state.setSegment(segment.type, parsed);
99
99
  enteredKeys.current = newValue;
100
- } else if (segment.type === "dayPeriod") state.clearSegment(segment.type);
100
+ } else if (segment.type === 'dayPeriod') state.clearSegment(segment.type);
101
101
  };
102
102
  let onKeyDown = (e)=>{
103
103
  // Firefox does not fire selectstart for Ctrl/Cmd + A
104
104
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1742153
105
- if (e.key === "a" && ((0, $4d1jn$isMac)() ? e.metaKey : e.ctrlKey)) e.preventDefault();
105
+ if (e.key === 'a' && ((0, $4d1jn$isMac)() ? e.metaKey : e.ctrlKey)) e.preventDefault();
106
106
  if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
107
107
  switch(e.key){
108
- case "Backspace":
109
- case "Delete":
108
+ case 'Backspace':
109
+ case 'Delete':
110
110
  // Safari on iOS does not fire beforeinput for the backspace key because the cursor is at the start.
111
111
  e.preventDefault();
112
112
  e.stopPropagation();
@@ -116,34 +116,34 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
116
116
  };
117
117
  // Safari dayPeriod option doesn't work...
118
118
  let { startsWith: startsWith } = (0, $4d1jn$useFilter)({
119
- sensitivity: "base"
119
+ sensitivity: 'base'
120
120
  });
121
121
  let amPmFormatter = (0, $4d1jn$useDateFormatter)({
122
- hour: "numeric",
122
+ hour: 'numeric',
123
123
  hour12: true
124
124
  });
125
125
  let am = (0, $4d1jn$useMemo)(()=>{
126
126
  let date = new Date();
127
127
  date.setHours(0);
128
- return amPmFormatter.formatToParts(date).find((part)=>part.type === "dayPeriod").value;
128
+ return amPmFormatter.formatToParts(date).find((part)=>part.type === 'dayPeriod').value;
129
129
  }, [
130
130
  amPmFormatter
131
131
  ]);
132
132
  let pm = (0, $4d1jn$useMemo)(()=>{
133
133
  let date = new Date();
134
134
  date.setHours(12);
135
- return amPmFormatter.formatToParts(date).find((part)=>part.type === "dayPeriod").value;
135
+ return amPmFormatter.formatToParts(date).find((part)=>part.type === 'dayPeriod').value;
136
136
  }, [
137
137
  amPmFormatter
138
138
  ]);
139
139
  // Get a list of formatted era names so users can type the first character to choose one.
140
140
  let eraFormatter = (0, $4d1jn$useDateFormatter)({
141
- year: "numeric",
142
- era: "narrow",
143
- timeZone: "UTC"
141
+ year: 'numeric',
142
+ era: 'narrow',
143
+ timeZone: 'UTC'
144
144
  });
145
145
  let eras = (0, $4d1jn$useMemo)(()=>{
146
- if (segment.type !== "era") return [];
146
+ if (segment.type !== 'era') return [];
147
147
  let date = (0, $4d1jn$toCalendar)(new (0, $4d1jn$CalendarDate)(1, 1, 1), state.calendar);
148
148
  let eras = state.calendar.getEras().map((era)=>{
149
149
  let eraDate = date.set({
@@ -151,9 +151,9 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
151
151
  month: 1,
152
152
  day: 1,
153
153
  era: era
154
- }).toDate("UTC");
154
+ }).toDate('UTC');
155
155
  let parts = eraFormatter.formatToParts(eraDate);
156
- let formatted = parts.find((p)=>p.type === "era").value;
156
+ let formatted = parts.find((p)=>p.type === 'era').value;
157
157
  return {
158
158
  era: era,
159
159
  formatted: formatted
@@ -174,38 +174,38 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
174
174
  if (state.isDisabled || state.isReadOnly) return;
175
175
  let newValue = enteredKeys.current + key;
176
176
  switch(segment.type){
177
- case "dayPeriod":
178
- if (startsWith(am, key)) state.setSegment("dayPeriod", 0);
179
- else if (startsWith(pm, key)) state.setSegment("dayPeriod", 12);
177
+ case 'dayPeriod':
178
+ if (startsWith(am, key)) state.setSegment('dayPeriod', 0);
179
+ else if (startsWith(pm, key)) state.setSegment('dayPeriod', 12);
180
180
  else break;
181
181
  focusManager.focusNext();
182
182
  break;
183
- case "era":
183
+ case 'era':
184
184
  {
185
185
  let matched = eras.find((e)=>startsWith(e.formatted, key));
186
186
  if (matched) {
187
- state.setSegment("era", matched.era);
187
+ state.setSegment('era', matched.era);
188
188
  focusManager.focusNext();
189
189
  }
190
190
  break;
191
191
  }
192
- case "day":
193
- case "hour":
194
- case "minute":
195
- case "second":
196
- case "month":
197
- case "year":
192
+ case 'day':
193
+ case 'hour':
194
+ case 'minute':
195
+ case 'second':
196
+ case 'month':
197
+ case 'year':
198
198
  {
199
199
  if (!parser.isValidPartialNumber(newValue)) return;
200
200
  let numberValue = parser.parse(newValue);
201
201
  let segmentValue = numberValue;
202
202
  let allowsZero = segment.minValue === 0;
203
- if (segment.type === "hour" && state.dateFormatter.resolvedOptions().hour12) {
203
+ if (segment.type === 'hour' && state.dateFormatter.resolvedOptions().hour12) {
204
204
  switch(state.dateFormatter.resolvedOptions().hourCycle){
205
- case "h11":
205
+ case 'h11':
206
206
  if (numberValue > 11) segmentValue = parser.parse(key);
207
207
  break;
208
- case "h12":
208
+ case 'h12':
209
209
  allowsZero = false;
210
210
  if (numberValue > 12) segmentValue = parser.parse(key);
211
211
  break;
@@ -215,8 +215,8 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
215
215
  if (isNaN(numberValue)) return;
216
216
  let shouldSetValue = segmentValue !== 0 || allowsZero;
217
217
  if (shouldSetValue) state.setSegment(segment.type, segmentValue);
218
- if (Number(numberValue + "0") > segment.maxValue || newValue.length >= String(segment.maxValue).length) {
219
- enteredKeys.current = "";
218
+ if (Number(numberValue + '0') > segment.maxValue || newValue.length >= String(segment.maxValue).length) {
219
+ enteredKeys.current = '';
220
220
  if (shouldSetValue) focusManager.focusNext();
221
221
  } else enteredKeys.current = newValue;
222
222
  break;
@@ -224,7 +224,7 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
224
224
  }
225
225
  };
226
226
  let onFocus = ()=>{
227
- enteredKeys.current = "";
227
+ enteredKeys.current = '';
228
228
  (0, $4d1jn$scrollIntoViewport)(ref.current, {
229
229
  containingElement: (0, $4d1jn$getScrollParent)(ref.current)
230
230
  });
@@ -232,16 +232,24 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
232
232
  let selection = window.getSelection();
233
233
  selection.collapse(ref.current);
234
234
  };
235
- let compositionRef = (0, $4d1jn$useRef)("");
235
+ let documentRef = (0, $4d1jn$useRef)(typeof document !== 'undefined' ? document : null);
236
+ (0, $4d1jn$useEvent)(documentRef, 'selectionchange', ()=>{
237
+ // Enforce that the selection is collapsed when inside a date segment.
238
+ // Otherwise, when tapping on a segment in Android Chrome and then entering text,
239
+ // composition events will be fired that break the DOM structure and crash the page.
240
+ let selection = window.getSelection();
241
+ if (ref.current.contains(selection.anchorNode)) selection.collapse(ref.current);
242
+ });
243
+ let compositionRef = (0, $4d1jn$useRef)('');
236
244
  // @ts-ignore - TODO: possibly old TS version? doesn't fail in my editor...
237
- (0, $4d1jn$useEvent)(ref, "beforeinput", (e)=>{
245
+ (0, $4d1jn$useEvent)(ref, 'beforeinput', (e)=>{
238
246
  e.preventDefault();
239
247
  switch(e.inputType){
240
- case "deleteContentBackward":
241
- case "deleteContentForward":
248
+ case 'deleteContentBackward':
249
+ case 'deleteContentForward':
242
250
  if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly) backspace();
243
251
  break;
244
- case "insertCompositionText":
252
+ case 'insertCompositionText':
245
253
  // insertCompositionText cannot be canceled.
246
254
  // Record the current state of the element so we can restore it in the `input` event below.
247
255
  compositionRef.current = ref.current.textContent;
@@ -254,10 +262,10 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
254
262
  break;
255
263
  }
256
264
  });
257
- (0, $4d1jn$useEvent)(ref, "input", (e)=>{
265
+ (0, $4d1jn$useEvent)(ref, 'input', (e)=>{
258
266
  let { inputType: inputType, data: data } = e;
259
267
  switch(inputType){
260
- case "insertCompositionText":
268
+ case 'insertCompositionText':
261
269
  // Reset the DOM to how it was in the beforeinput event.
262
270
  ref.current.textContent = compositionRef.current;
263
271
  // Android sometimes fires key presses of letters as composition events. Need to handle am/pm keys here too.
@@ -280,12 +288,12 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
280
288
  focusManager
281
289
  ]);
282
290
  // spinbuttons cannot be focused with VoiceOver on iOS.
283
- let touchPropOverrides = (0, $4d1jn$isIOS)() || segment.type === "timeZoneName" ? {
284
- role: "textbox",
285
- "aria-valuemax": null,
286
- "aria-valuemin": null,
287
- "aria-valuetext": null,
288
- "aria-valuenow": null
291
+ let touchPropOverrides = (0, $4d1jn$isIOS)() || segment.type === 'timeZoneName' ? {
292
+ role: 'textbox',
293
+ 'aria-valuemax': null,
294
+ 'aria-valuemin': null,
295
+ 'aria-valuetext': null,
296
+ 'aria-valuenow': null
289
297
  } : {};
290
298
  // Only apply aria-describedby to the first segment, unless the field is invalid. This avoids it being
291
299
  // read every time the user navigates to a new segment.
@@ -297,39 +305,38 @@ function $32489daedd52963e$export$1315d136e6f7581(segment, state, ref) {
297
305
  let isEditable = !state.isDisabled && !state.isReadOnly && segment.isEditable;
298
306
  // Prepend the label passed from the field to each segment name.
299
307
  // This is needed because VoiceOver on iOS does not announce groups.
300
- let name = segment.type === "literal" ? "" : displayNames.of(segment.type);
308
+ let name = segment.type === 'literal' ? '' : displayNames.of(segment.type);
301
309
  let labelProps = (0, $4d1jn$useLabels)({
302
- "aria-label": `${name}${ariaLabel ? `, ${ariaLabel}` : ""}${ariaLabelledBy ? ", " : ""}`,
303
- "aria-labelledby": ariaLabelledBy
310
+ 'aria-label': `${name}${ariaLabel ? `, ${ariaLabel}` : ''}${ariaLabelledBy ? ', ' : ''}`,
311
+ 'aria-labelledby': ariaLabelledBy
304
312
  });
305
313
  // Literal segments should not be visible to screen readers. We don't really need any of the above,
306
314
  // but the rules of hooks mean hooks cannot be conditional so we have to put this condition here.
307
- if (segment.type === "literal") return {
315
+ if (segment.type === 'literal') return {
308
316
  segmentProps: {
309
- "aria-hidden": true
317
+ 'aria-hidden': true
310
318
  }
311
319
  };
312
320
  return {
313
321
  segmentProps: (0, $4d1jn$mergeProps)(spinButtonProps, labelProps, {
314
322
  id: id,
315
323
  ...touchPropOverrides,
316
- "aria-invalid": state.isInvalid ? "true" : undefined,
317
- "aria-describedby": ariaDescribedBy,
318
- "aria-readonly": state.isReadOnly || !segment.isEditable ? "true" : undefined,
319
- "data-placeholder": segment.isPlaceholder || undefined,
324
+ 'aria-invalid': state.isInvalid ? 'true' : undefined,
325
+ 'aria-describedby': ariaDescribedBy,
326
+ 'aria-readonly': state.isReadOnly || !segment.isEditable ? 'true' : undefined,
327
+ 'data-placeholder': segment.isPlaceholder || undefined,
320
328
  contentEditable: isEditable,
321
329
  suppressContentEditableWarning: isEditable,
322
- spellCheck: isEditable ? "false" : undefined,
323
- autoCapitalize: isEditable ? "off" : undefined,
324
- autoCorrect: isEditable ? "off" : undefined,
330
+ spellCheck: isEditable ? 'false' : undefined,
331
+ autoCorrect: isEditable ? 'off' : undefined,
325
332
  // Capitalization was changed in React 17...
326
- [parseInt((0, $4d1jn$react).version, 10) >= 17 ? "enterKeyHint" : "enterkeyhint"]: isEditable ? "next" : undefined,
327
- inputMode: state.isDisabled || segment.type === "dayPeriod" || segment.type === "era" || !isEditable ? undefined : "numeric",
333
+ [parseInt((0, $4d1jn$react).version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: isEditable ? 'next' : undefined,
334
+ inputMode: state.isDisabled || segment.type === 'dayPeriod' || segment.type === 'era' || !isEditable ? undefined : 'numeric',
328
335
  tabIndex: state.isDisabled ? undefined : 0,
329
336
  onKeyDown: onKeyDown,
330
337
  onFocus: onFocus,
331
338
  style: {
332
- caretColor: "transparent"
339
+ caretColor: 'transparent'
333
340
  },
334
341
  // Prevent pointer events from reaching useDatePickerGroup, and allow native browser behavior to focus the segment.
335
342
  onPointerDown (e) {
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAuBM,SAAS,yCAAe,OAAoB,EAAE,KAAqB,EAAE,GAA2B;IACrG,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE;IACzB,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,gBAAQ;IACvB,IAAI,eAAe,CAAA,GAAA,yCAAc;IACjC,IAAI,aAAC,SAAS,kBAAE,cAAc,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC;IAE9E,IAAI,YAAY,QAAQ,aAAa,GAAG,KAAK,QAAQ,IAAI;IACzD,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,aAAa,CAAC,eAAe,IAAI;QAAC,MAAM,aAAa;KAAC;IACxF,IAAI,qBAAqB,CAAA,GAAA,uBAAe,EAAE;QAAC,OAAO;QAAQ,UAAU,QAAQ,QAAQ;IAAA;IACpF,IAAI,oBAAoB,CAAA,GAAA,uBAAe,EAAE;QACvC,MAAM;QACN,QAAQ,QAAQ,MAAM;QACtB,UAAU,QAAQ,QAAQ;IAC5B;IAEA,IAAI,QAAQ,IAAI,KAAK,WAAW,CAAC,QAAQ,aAAa,EAAE;QACtD,IAAI,iBAAiB,m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MAAM,UAAU,IAAI,CAAC,QAAQ,UAAU,GAAG,SAAS;YACpE,oBAAoB,QAAQ,aAAa,IAAI;YAC7C,iBAAiB;YACjB,gCAAgC;YAChC,YAAY,aAAa,UAAU;YACnC,gBAAgB,aAAa,QAAQ;YACrC,aAAa,aAAa,QAAQ;YAClC,4CAA4C;YAC5C,CAAC,SAAS,CAAA,GAAA,YAAI,EAAE,OAAO,EAAE,OAAO,KAAK,iBAAiB,eAAe,EAAE,aAAa,SAAS;YAC7F,WAAW,MAAM,UAAU,IAAI,QAAQ,IAAI,KAAK,eAAe,QAAQ,IAAI,KAAK,SAAS,CAAC,aAAa,YAAY;YACnH,UAAU,MAAM,UAAU,GAAG,YAAY;uBACzC;qBACA;YACA,OAAO;gBACL,YAAY;YACd;YACA,mHAAmH;YACnH,eAAc,CAAC;gBACb,EAAE,eAAe;YACnB;YACA,aAAY,CAAC;gBACX,EAAE,eAAe;YACnB;QACF;IACF;AACF;AAEA,SAAS,yCAAmB,OAAiB;IAC3C,gGAAgG;IAChG,QAAQ,IAAI;IACZ,IAAI,QAAQ,OAAO,CAAC,EAAE;IACtB,IAAI,OAAO,OAAO,CAAC,QAAQ,MAAM,GAAG,EAAE;IACtC,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EACtB,OAAO;IAEX;IACA,OAAO;AACT","sources":["packages/@react-aria/datepicker/src/useDateSegment.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, toCalendar} from '@internationalized/date';\nimport {DateFieldState, DateSegment} from '@react-stately/datepicker';\nimport {DOMAttributes} from '@react-types/shared';\nimport {getScrollParent, isIOS, isMac, mergeProps, scrollIntoViewport, useEvent, useId, useLabels, useLayoutEffect} from '@react-aria/utils';\nimport {hookData} from './useDateField';\nimport {NumberParser} from '@internationalized/number';\nimport React, {RefObject, useMemo, useRef} from 'react';\nimport {useDateFormatter, useFilter, useLocale} from '@react-aria/i18n';\nimport {useDisplayNames} from './useDisplayNames';\nimport {useSpinButton} from '@react-aria/spinbutton';\n\nexport interface DateSegmentAria {\n /** Props for the segment element. */\n segmentProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a segment in a date field.\n * A date segment displays an individual unit of a date and time, and allows users to edit\n * the value by typing or using the arrow keys to increment and decrement.\n */\nexport function useDateSegment(segment: DateSegment, state: DateFieldState, ref: RefObject<HTMLElement>): DateSegmentAria {\n let enteredKeys = useRef('');\n let {locale} = useLocale();\n let displayNames = useDisplayNames();\n let {ariaLabel, ariaLabelledBy, ariaDescribedBy, focusManager} = hookData.get(state);\n\n let textValue = segment.isPlaceholder ? '' : segment.text;\n let options = useMemo(() => state.dateFormatter.resolvedOptions(), [state.dateFormatter]);\n let monthDateFormatter = useDateFormatter({month: 'long', timeZone: options.timeZone});\n let hourDateFormatter = useDateFormatter({\n hour: 'numeric',\n hour12: options.hour12,\n timeZone: options.timeZone\n });\n\n if (segment.type === 'month' && !segment.isPlaceholder) {\n let monthTextValue = monthDateFormatter.format(state.dateValue);\n textValue = monthTextValue !== textValue ? `${textValue} – ${monthTextValue}` : monthTextValue;\n } else if (segment.type === 'hour' && !segment.isPlaceholder) {\n textValue = hourDateFormatter.format(state.dateValue);\n }\n\n let {spinButtonProps} = useSpinButton({\n // The ARIA spec says aria-valuenow is optional if there's no value, but aXe seems to require it.\n // This doesn't seem to have any negative effects with real AT since we also use aria-valuetext.\n // https://github.com/dequelabs/axe-core/issues/3505\n value: segment.value,\n textValue,\n minValue: segment.minValue,\n maxValue: segment.maxValue,\n isDisabled: state.isDisabled,\n isReadOnly: state.isReadOnly || !segment.isEditable,\n isRequired: state.isRequired,\n onIncrement: () => {\n enteredKeys.current = '';\n state.increment(segment.type);\n },\n onDecrement: () => {\n enteredKeys.current = '';\n state.decrement(segment.type);\n },\n onIncrementPage: () => {\n enteredKeys.current = '';\n state.incrementPage(segment.type);\n },\n onDecrementPage: () => {\n enteredKeys.current = '';\n state.decrementPage(segment.type);\n },\n onIncrementToMax: () => {\n enteredKeys.current = '';\n state.setSegment(segment.type, segment.maxValue);\n },\n onDecrementToMin: () => {\n enteredKeys.current = '';\n state.setSegment(segment.type, segment.minValue);\n }\n });\n\n let parser = useMemo(() => new NumberParser(locale, {maximumFractionDigits: 0}), [locale]);\n\n let backspace = () => {\n if (segment.text === segment.placeholder) {\n focusManager.focusPrevious();\n }\n if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly && !segment.isPlaceholder) {\n let newValue = segment.text.slice(0, -1);\n let parsed = parser.parse(newValue);\n newValue = parsed === 0 ? '' : newValue;\n if (newValue.length === 0 || parsed === 0) {\n state.clearSegment(segment.type);\n } else {\n state.setSegment(segment.type, parsed);\n }\n enteredKeys.current = newValue;\n } else if (segment.type === 'dayPeriod') {\n state.clearSegment(segment.type);\n }\n };\n\n let onKeyDown = (e) => {\n // Firefox does not fire selectstart for Ctrl/Cmd + A\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1742153\n if (e.key === 'a' && (isMac() ? e.metaKey : e.ctrlKey)) {\n e.preventDefault();\n }\n\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) {\n return;\n }\n\n switch (e.key) {\n case 'Backspace':\n case 'Delete': {\n // Safari on iOS does not fire beforeinput for the backspace key because the cursor is at the start.\n e.preventDefault();\n e.stopPropagation();\n backspace();\n break;\n }\n }\n };\n\n // Safari dayPeriod option doesn't work...\n let {startsWith} = useFilter({sensitivity: 'base'});\n let amPmFormatter = useDateFormatter({hour: 'numeric', hour12: true});\n let am = useMemo(() => {\n let date = new Date();\n date.setHours(0);\n return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod').value;\n }, [amPmFormatter]);\n\n let pm = useMemo(() => {\n let date = new Date();\n date.setHours(12);\n return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod').value;\n }, [amPmFormatter]);\n\n // Get a list of formatted era names so users can type the first character to choose one.\n let eraFormatter = useDateFormatter({year: 'numeric', era: 'narrow', timeZone: 'UTC'});\n let eras = useMemo(() => {\n if (segment.type !== 'era') {\n return [];\n }\n\n let date = toCalendar(new CalendarDate(1, 1, 1), state.calendar);\n let eras = state.calendar.getEras().map(era => {\n let eraDate = date.set({year: 1, month: 1, day: 1, era}).toDate('UTC');\n let parts = eraFormatter.formatToParts(eraDate);\n let formatted = parts.find(p => p.type === 'era').value;\n return {era, formatted};\n });\n\n // Remove the common prefix from formatted values. This is so that in calendars with eras like\n // ERA0 and ERA1 (e.g. Ethiopic), users can press \"0\" and \"1\" to select an era. In other cases,\n // the first letter is used.\n let prefixLength = commonPrefixLength(eras.map(era => era.formatted));\n if (prefixLength) {\n for (let era of eras) {\n era.formatted = era.formatted.slice(prefixLength);\n }\n }\n\n return eras;\n }, [eraFormatter, state.calendar, segment.type]);\n\n let onInput = (key: string) => {\n if (state.isDisabled || state.isReadOnly) {\n return;\n }\n\n let newValue = enteredKeys.current + key;\n\n switch (segment.type) {\n case 'dayPeriod':\n if (startsWith(am, key)) {\n state.setSegment('dayPeriod', 0);\n } else if (startsWith(pm, key)) {\n state.setSegment('dayPeriod', 12);\n } else {\n break;\n }\n focusManager.focusNext();\n break;\n case 'era': {\n let matched = eras.find(e => startsWith(e.formatted, key));\n if (matched) {\n state.setSegment('era', matched.era);\n focusManager.focusNext();\n }\n break;\n }\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'month':\n case 'year': {\n if (!parser.isValidPartialNumber(newValue)) {\n return;\n }\n\n let numberValue = parser.parse(newValue);\n let segmentValue = numberValue;\n let allowsZero = segment.minValue === 0;\n if (segment.type === 'hour' && state.dateFormatter.resolvedOptions().hour12) {\n switch (state.dateFormatter.resolvedOptions().hourCycle) {\n case 'h11':\n if (numberValue > 11) {\n segmentValue = parser.parse(key);\n }\n break;\n case 'h12':\n allowsZero = false;\n if (numberValue > 12) {\n segmentValue = parser.parse(key);\n }\n break;\n }\n\n if (segment.value >= 12 && numberValue > 1) {\n numberValue += 12;\n }\n } else if (numberValue > segment.maxValue) {\n segmentValue = parser.parse(key);\n }\n\n if (isNaN(numberValue)) {\n return;\n }\n\n let shouldSetValue = segmentValue !== 0 || allowsZero;\n if (shouldSetValue) {\n state.setSegment(segment.type, segmentValue);\n }\n\n if (Number(numberValue + '0') > segment.maxValue || newValue.length >= String(segment.maxValue).length) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n focusManager.focusNext();\n }\n } else {\n enteredKeys.current = newValue;\n }\n break;\n }\n }\n };\n\n let onFocus = () => {\n enteredKeys.current = '';\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n\n // Collapse selection to start or Chrome won't fire input events.\n let selection = window.getSelection();\n selection.collapse(ref.current);\n };\n\n let compositionRef = useRef('');\n // @ts-ignore - TODO: possibly old TS version? doesn't fail in my editor...\n useEvent(ref, 'beforeinput', e => {\n e.preventDefault();\n\n switch (e.inputType) {\n case 'deleteContentBackward':\n case 'deleteContentForward':\n if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly) {\n backspace();\n }\n break;\n case 'insertCompositionText':\n // insertCompositionText cannot be canceled.\n // Record the current state of the element so we can restore it in the `input` event below.\n compositionRef.current = ref.current.textContent;\n\n // Safari gets stuck in a composition state unless we also assign to the value here.\n // eslint-disable-next-line no-self-assign\n ref.current.textContent = ref.current.textContent;\n break;\n default:\n if (e.data != null) {\n onInput(e.data);\n }\n break;\n }\n });\n\n useEvent(ref, 'input', (e: InputEvent) => {\n let {inputType, data} = e;\n switch (inputType) {\n case 'insertCompositionText':\n // Reset the DOM to how it was in the beforeinput event.\n ref.current.textContent = compositionRef.current;\n\n // Android sometimes fires key presses of letters as composition events. Need to handle am/pm keys here too.\n // Can also happen e.g. with Pinyin keyboard on iOS.\n if (startsWith(am, data) || startsWith(pm, data)) {\n onInput(data);\n }\n break;\n }\n });\n\n useLayoutEffect(() => {\n let element = ref.current;\n return () => {\n // If the focused segment is removed, focus the previous one, or the next one if there was no previous one.\n if (document.activeElement === element) {\n let prev = focusManager.focusPrevious();\n if (!prev) {\n focusManager.focusNext();\n }\n }\n };\n }, [ref, focusManager]);\n\n // spinbuttons cannot be focused with VoiceOver on iOS.\n let touchPropOverrides = isIOS() || segment.type === 'timeZoneName' ? {\n role: 'textbox',\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuetext': null,\n 'aria-valuenow': null\n } : {};\n\n // Only apply aria-describedby to the first segment, unless the field is invalid. This avoids it being\n // read every time the user navigates to a new segment.\n let firstSegment = useMemo(() => state.segments.find(s => s.isEditable), [state.segments]);\n if (segment !== firstSegment && !state.isInvalid) {\n ariaDescribedBy = undefined;\n }\n\n let id = useId();\n let isEditable = !state.isDisabled && !state.isReadOnly && segment.isEditable;\n\n // Prepend the label passed from the field to each segment name.\n // This is needed because VoiceOver on iOS does not announce groups.\n let name = segment.type === 'literal' ? '' : displayNames.of(segment.type);\n let labelProps = useLabels({\n 'aria-label': `${name}${ariaLabel ? `, ${ariaLabel}` : ''}${ariaLabelledBy ? ', ' : ''}`,\n 'aria-labelledby': ariaLabelledBy\n });\n\n // Literal segments should not be visible to screen readers. We don't really need any of the above,\n // but the rules of hooks mean hooks cannot be conditional so we have to put this condition here.\n if (segment.type === 'literal') {\n return {\n segmentProps: {\n 'aria-hidden': true\n }\n };\n }\n\n return {\n segmentProps: mergeProps(spinButtonProps, labelProps, {\n id,\n ...touchPropOverrides,\n 'aria-invalid': state.isInvalid ? 'true' : undefined,\n 'aria-describedby': ariaDescribedBy,\n 'aria-readonly': state.isReadOnly || !segment.isEditable ? 'true' : undefined,\n 'data-placeholder': segment.isPlaceholder || undefined,\n contentEditable: isEditable,\n suppressContentEditableWarning: isEditable,\n spellCheck: isEditable ? 'false' : undefined,\n autoCapitalize: isEditable ? 'off' : undefined,\n autoCorrect: isEditable ? 'off' : undefined,\n // Capitalization was changed in React 17...\n [parseInt(React.version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: isEditable ? 'next' : undefined,\n inputMode: state.isDisabled || segment.type === 'dayPeriod' || segment.type === 'era' || !isEditable ? undefined : 'numeric',\n tabIndex: state.isDisabled ? undefined : 0,\n onKeyDown,\n onFocus,\n style: {\n caretColor: 'transparent'\n },\n // Prevent pointer events from reaching useDatePickerGroup, and allow native browser behavior to focus the segment.\n onPointerDown(e) {\n e.stopPropagation();\n },\n onMouseDown(e) {\n e.stopPropagation();\n }\n })\n };\n}\n\nfunction commonPrefixLength(strings: string[]): number {\n // Sort the strings, and compare the characters in the first and last to find the common prefix.\n strings.sort();\n let first = strings[0];\n let last = strings[strings.length - 1];\n for (let i = 0; i < first.length; i++) {\n if (first[i] !== last[i]) {\n return i;\n }\n }\n return 0;\n}\n"],"names":[],"version":3,"file":"useDateSegment.module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAuBM,SAAS,yCAAe,OAAoB,EAAE,KAAqB,EAAE,GAAkC;IAC5G,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE;IACzB,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,gBAAQ;IACvB,IAAI,eAAe,CAAA,GAAA,yCAAc;IACjC,IAAI,aAAC,SAAS,kBAAE,cAAc,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC;IAE9E,IAAI,YAAY,QAAQ,aAAa,GAAG,KAAK,QAAQ,IAAI;IACzD,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,aAAa,CAAC,eAAe,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;IACZ,IAAI,QAAQ,OAAO,CAAC,EAAE;IACtB,IAAI,OAAO,OAAO,CAAC,QAAQ,MAAM,GAAG,EAAE;IACtC,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EACtB,OAAO;IAEX;IACA,OAAO;AACT","sources":["packages/@react-aria/datepicker/src/useDateSegment.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, toCalendar} from '@internationalized/date';\nimport {DateFieldState, DateSegment} from '@react-stately/datepicker';\nimport {getScrollParent, isIOS, isMac, mergeProps, scrollIntoViewport, useEvent, useId, useLabels, useLayoutEffect} from '@react-aria/utils';\nimport {hookData} from './useDateField';\nimport {NumberParser} from '@internationalized/number';\nimport React, {useMemo, useRef} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {useDateFormatter, useFilter, useLocale} from '@react-aria/i18n';\nimport {useDisplayNames} from './useDisplayNames';\nimport {useSpinButton} from '@react-aria/spinbutton';\n\nexport interface DateSegmentAria {\n /** Props for the segment element. */\n segmentProps: React.HTMLAttributes<HTMLDivElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a segment in a date field.\n * A date segment displays an individual unit of a date and time, and allows users to edit\n * the value by typing or using the arrow keys to increment and decrement.\n */\nexport function useDateSegment(segment: DateSegment, state: DateFieldState, ref: RefObject<HTMLElement | null>): DateSegmentAria {\n let enteredKeys = useRef('');\n let {locale} = useLocale();\n let displayNames = useDisplayNames();\n let {ariaLabel, ariaLabelledBy, ariaDescribedBy, focusManager} = hookData.get(state);\n\n let textValue = segment.isPlaceholder ? '' : segment.text;\n let options = useMemo(() => state.dateFormatter.resolvedOptions(), [state.dateFormatter]);\n let monthDateFormatter = useDateFormatter({month: 'long', timeZone: options.timeZone});\n let hourDateFormatter = useDateFormatter({\n hour: 'numeric',\n hour12: options.hour12,\n timeZone: options.timeZone\n });\n\n if (segment.type === 'month' && !segment.isPlaceholder) {\n let monthTextValue = monthDateFormatter.format(state.dateValue);\n textValue = monthTextValue !== textValue ? `${textValue} – ${monthTextValue}` : monthTextValue;\n } else if (segment.type === 'hour' && !segment.isPlaceholder) {\n textValue = hourDateFormatter.format(state.dateValue);\n }\n\n let {spinButtonProps} = useSpinButton({\n // The ARIA spec says aria-valuenow is optional if there's no value, but aXe seems to require it.\n // This doesn't seem to have any negative effects with real AT since we also use aria-valuetext.\n // https://github.com/dequelabs/axe-core/issues/3505\n value: segment.value,\n textValue,\n minValue: segment.minValue,\n maxValue: segment.maxValue,\n isDisabled: state.isDisabled,\n isReadOnly: state.isReadOnly || !segment.isEditable,\n isRequired: state.isRequired,\n onIncrement: () => {\n enteredKeys.current = '';\n state.increment(segment.type);\n },\n onDecrement: () => {\n enteredKeys.current = '';\n state.decrement(segment.type);\n },\n onIncrementPage: () => {\n enteredKeys.current = '';\n state.incrementPage(segment.type);\n },\n onDecrementPage: () => {\n enteredKeys.current = '';\n state.decrementPage(segment.type);\n },\n onIncrementToMax: () => {\n enteredKeys.current = '';\n state.setSegment(segment.type, segment.maxValue);\n },\n onDecrementToMin: () => {\n enteredKeys.current = '';\n state.setSegment(segment.type, segment.minValue);\n }\n });\n\n let parser = useMemo(() => new NumberParser(locale, {maximumFractionDigits: 0}), [locale]);\n\n let backspace = () => {\n if (segment.text === segment.placeholder) {\n focusManager.focusPrevious();\n }\n if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly && !segment.isPlaceholder) {\n let newValue = segment.text.slice(0, -1);\n let parsed = parser.parse(newValue);\n newValue = parsed === 0 ? '' : newValue;\n if (newValue.length === 0 || parsed === 0) {\n state.clearSegment(segment.type);\n } else {\n state.setSegment(segment.type, parsed);\n }\n enteredKeys.current = newValue;\n } else if (segment.type === 'dayPeriod') {\n state.clearSegment(segment.type);\n }\n };\n\n let onKeyDown = (e) => {\n // Firefox does not fire selectstart for Ctrl/Cmd + A\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1742153\n if (e.key === 'a' && (isMac() ? e.metaKey : e.ctrlKey)) {\n e.preventDefault();\n }\n\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) {\n return;\n }\n\n switch (e.key) {\n case 'Backspace':\n case 'Delete': {\n // Safari on iOS does not fire beforeinput for the backspace key because the cursor is at the start.\n e.preventDefault();\n e.stopPropagation();\n backspace();\n break;\n }\n }\n };\n\n // Safari dayPeriod option doesn't work...\n let {startsWith} = useFilter({sensitivity: 'base'});\n let amPmFormatter = useDateFormatter({hour: 'numeric', hour12: true});\n let am = useMemo(() => {\n let date = new Date();\n date.setHours(0);\n return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod').value;\n }, [amPmFormatter]);\n\n let pm = useMemo(() => {\n let date = new Date();\n date.setHours(12);\n return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod').value;\n }, [amPmFormatter]);\n\n // Get a list of formatted era names so users can type the first character to choose one.\n let eraFormatter = useDateFormatter({year: 'numeric', era: 'narrow', timeZone: 'UTC'});\n let eras = useMemo(() => {\n if (segment.type !== 'era') {\n return [];\n }\n\n let date = toCalendar(new CalendarDate(1, 1, 1), state.calendar);\n let eras = state.calendar.getEras().map(era => {\n let eraDate = date.set({year: 1, month: 1, day: 1, era}).toDate('UTC');\n let parts = eraFormatter.formatToParts(eraDate);\n let formatted = parts.find(p => p.type === 'era').value;\n return {era, formatted};\n });\n\n // Remove the common prefix from formatted values. This is so that in calendars with eras like\n // ERA0 and ERA1 (e.g. Ethiopic), users can press \"0\" and \"1\" to select an era. In other cases,\n // the first letter is used.\n let prefixLength = commonPrefixLength(eras.map(era => era.formatted));\n if (prefixLength) {\n for (let era of eras) {\n era.formatted = era.formatted.slice(prefixLength);\n }\n }\n\n return eras;\n }, [eraFormatter, state.calendar, segment.type]);\n\n let onInput = (key: string) => {\n if (state.isDisabled || state.isReadOnly) {\n return;\n }\n\n let newValue = enteredKeys.current + key;\n\n switch (segment.type) {\n case 'dayPeriod':\n if (startsWith(am, key)) {\n state.setSegment('dayPeriod', 0);\n } else if (startsWith(pm, key)) {\n state.setSegment('dayPeriod', 12);\n } else {\n break;\n }\n focusManager.focusNext();\n break;\n case 'era': {\n let matched = eras.find(e => startsWith(e.formatted, key));\n if (matched) {\n state.setSegment('era', matched.era);\n focusManager.focusNext();\n }\n break;\n }\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'month':\n case 'year': {\n if (!parser.isValidPartialNumber(newValue)) {\n return;\n }\n\n let numberValue = parser.parse(newValue);\n let segmentValue = numberValue;\n let allowsZero = segment.minValue === 0;\n if (segment.type === 'hour' && state.dateFormatter.resolvedOptions().hour12) {\n switch (state.dateFormatter.resolvedOptions().hourCycle) {\n case 'h11':\n if (numberValue > 11) {\n segmentValue = parser.parse(key);\n }\n break;\n case 'h12':\n allowsZero = false;\n if (numberValue > 12) {\n segmentValue = parser.parse(key);\n }\n break;\n }\n\n if (segment.value >= 12 && numberValue > 1) {\n numberValue += 12;\n }\n } else if (numberValue > segment.maxValue) {\n segmentValue = parser.parse(key);\n }\n\n if (isNaN(numberValue)) {\n return;\n }\n\n let shouldSetValue = segmentValue !== 0 || allowsZero;\n if (shouldSetValue) {\n state.setSegment(segment.type, segmentValue);\n }\n\n if (Number(numberValue + '0') > segment.maxValue || newValue.length >= String(segment.maxValue).length) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n focusManager.focusNext();\n }\n } else {\n enteredKeys.current = newValue;\n }\n break;\n }\n }\n };\n\n let onFocus = () => {\n enteredKeys.current = '';\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n\n // Collapse selection to start or Chrome won't fire input events.\n let selection = window.getSelection();\n selection.collapse(ref.current);\n };\n\n let documentRef = useRef(typeof document !== 'undefined' ? document : null);\n useEvent(documentRef, 'selectionchange', () => {\n // Enforce that the selection is collapsed when inside a date segment.\n // Otherwise, when tapping on a segment in Android Chrome and then entering text,\n // composition events will be fired that break the DOM structure and crash the page.\n let selection = window.getSelection();\n if (ref.current.contains(selection.anchorNode)) {\n selection.collapse(ref.current);\n }\n });\n\n let compositionRef = useRef('');\n // @ts-ignore - TODO: possibly old TS version? doesn't fail in my editor...\n useEvent(ref, 'beforeinput', e => {\n e.preventDefault();\n\n switch (e.inputType) {\n case 'deleteContentBackward':\n case 'deleteContentForward':\n if (parser.isValidPartialNumber(segment.text) && !state.isReadOnly) {\n backspace();\n }\n break;\n case 'insertCompositionText':\n // insertCompositionText cannot be canceled.\n // Record the current state of the element so we can restore it in the `input` event below.\n compositionRef.current = ref.current.textContent;\n\n // Safari gets stuck in a composition state unless we also assign to the value here.\n // eslint-disable-next-line no-self-assign\n ref.current.textContent = ref.current.textContent;\n break;\n default:\n if (e.data != null) {\n onInput(e.data);\n }\n break;\n }\n });\n\n useEvent(ref, 'input', (e: InputEvent) => {\n let {inputType, data} = e;\n switch (inputType) {\n case 'insertCompositionText':\n // Reset the DOM to how it was in the beforeinput event.\n ref.current.textContent = compositionRef.current;\n\n // Android sometimes fires key presses of letters as composition events. Need to handle am/pm keys here too.\n // Can also happen e.g. with Pinyin keyboard on iOS.\n if (startsWith(am, data) || startsWith(pm, data)) {\n onInput(data);\n }\n break;\n }\n });\n\n useLayoutEffect(() => {\n let element = ref.current;\n return () => {\n // If the focused segment is removed, focus the previous one, or the next one if there was no previous one.\n if (document.activeElement === element) {\n let prev = focusManager.focusPrevious();\n if (!prev) {\n focusManager.focusNext();\n }\n }\n };\n }, [ref, focusManager]);\n\n // spinbuttons cannot be focused with VoiceOver on iOS.\n let touchPropOverrides = isIOS() || segment.type === 'timeZoneName' ? {\n role: 'textbox',\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuetext': null,\n 'aria-valuenow': null\n } : {};\n\n // Only apply aria-describedby to the first segment, unless the field is invalid. This avoids it being\n // read every time the user navigates to a new segment.\n let firstSegment = useMemo(() => state.segments.find(s => s.isEditable), [state.segments]);\n if (segment !== firstSegment && !state.isInvalid) {\n ariaDescribedBy = undefined;\n }\n\n let id = useId();\n let isEditable = !state.isDisabled && !state.isReadOnly && segment.isEditable;\n\n // Prepend the label passed from the field to each segment name.\n // This is needed because VoiceOver on iOS does not announce groups.\n let name = segment.type === 'literal' ? '' : displayNames.of(segment.type);\n let labelProps = useLabels({\n 'aria-label': `${name}${ariaLabel ? `, ${ariaLabel}` : ''}${ariaLabelledBy ? ', ' : ''}`,\n 'aria-labelledby': ariaLabelledBy\n });\n\n // Literal segments should not be visible to screen readers. We don't really need any of the above,\n // but the rules of hooks mean hooks cannot be conditional so we have to put this condition here.\n if (segment.type === 'literal') {\n return {\n segmentProps: {\n 'aria-hidden': true\n }\n };\n }\n\n return {\n segmentProps: mergeProps(spinButtonProps, labelProps, {\n id,\n ...touchPropOverrides,\n 'aria-invalid': state.isInvalid ? 'true' : undefined,\n 'aria-describedby': ariaDescribedBy,\n 'aria-readonly': state.isReadOnly || !segment.isEditable ? 'true' : undefined,\n 'data-placeholder': segment.isPlaceholder || undefined,\n contentEditable: isEditable,\n suppressContentEditableWarning: isEditable,\n spellCheck: isEditable ? 'false' : undefined,\n autoCorrect: isEditable ? 'off' : undefined,\n // Capitalization was changed in React 17...\n [parseInt(React.version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: isEditable ? 'next' : undefined,\n inputMode: state.isDisabled || segment.type === 'dayPeriod' || segment.type === 'era' || !isEditable ? undefined : 'numeric',\n tabIndex: state.isDisabled ? undefined : 0,\n onKeyDown,\n onFocus,\n style: {\n caretColor: 'transparent'\n },\n // Prevent pointer events from reaching useDatePickerGroup, and allow native browser behavior to focus the segment.\n onPointerDown(e) {\n e.stopPropagation();\n },\n onMouseDown(e) {\n e.stopPropagation();\n }\n })\n };\n}\n\nfunction commonPrefixLength(strings: string[]): number {\n // Sort the strings, and compare the characters in the first and last to find the common prefix.\n strings.sort();\n let first = strings[0];\n let last = strings[strings.length - 1];\n for (let i = 0; i < first.length; i++) {\n if (first[i] !== last[i]) {\n return i;\n }\n }\n return 0;\n}\n"],"names":[],"version":3,"file":"useDateSegment.module.js.map"}
@@ -28,14 +28,14 @@ $parcel$export(module.exports, "useDisplayNames", () => $934ac650a0aceb4b$export
28
28
 
29
29
  function $934ac650a0aceb4b$export$d42c60378c8168f8() {
30
30
  let { locale: locale } = (0, $2nNUW$reactariai18n.useLocale)();
31
- let dictionary = (0, $2nNUW$reactariai18n.useLocalizedStringDictionary)((0, ($parcel$interopDefault($c1905b78f6d2f5bf$exports))), "@react-aria/datepicker");
31
+ let dictionary = (0, $2nNUW$reactariai18n.useLocalizedStringDictionary)((0, ($parcel$interopDefault($c1905b78f6d2f5bf$exports))), '@react-aria/datepicker');
32
32
  return (0, $2nNUW$react.useMemo)(()=>{
33
33
  // Try to use Intl.DisplayNames if possible. It may be supported in browsers, but not support the dateTimeField
34
34
  // type as that was only added in v2. https://github.com/tc39/intl-displaynames-v2
35
35
  try {
36
36
  // @ts-ignore
37
37
  return new Intl.DisplayNames(locale, {
38
- type: "dateTimeField"
38
+ type: 'dateTimeField'
39
39
  });
40
40
  } catch (err) {
41
41
  return new $934ac650a0aceb4b$var$DisplayNamesPolyfill(locale, dictionary);
@@ -22,14 +22,14 @@ function $parcel$interopDefault(a) {
22
22
 
23
23
  function $3aeceb3a64eb8358$export$d42c60378c8168f8() {
24
24
  let { locale: locale } = (0, $jR5iF$useLocale)();
25
- let dictionary = (0, $jR5iF$useLocalizedStringDictionary)((0, ($parcel$interopDefault($jR5iF$intlStringsmodulejs))), "@react-aria/datepicker");
25
+ let dictionary = (0, $jR5iF$useLocalizedStringDictionary)((0, ($parcel$interopDefault($jR5iF$intlStringsmodulejs))), '@react-aria/datepicker');
26
26
  return (0, $jR5iF$useMemo)(()=>{
27
27
  // Try to use Intl.DisplayNames if possible. It may be supported in browsers, but not support the dateTimeField
28
28
  // type as that was only added in v2. https://github.com/tc39/intl-displaynames-v2
29
29
  try {
30
30
  // @ts-ignore
31
31
  return new Intl.DisplayNames(locale, {
32
- type: "dateTimeField"
32
+ type: 'dateTimeField'
33
33
  });
34
34
  } catch (err) {
35
35
  return new $3aeceb3a64eb8358$var$DisplayNamesPolyfill(locale, dictionary);
@@ -51,4 +51,4 @@ class $3aeceb3a64eb8358$var$DisplayNamesPolyfill {
51
51
 
52
52
 
53
53
  export {$3aeceb3a64eb8358$export$d42c60378c8168f8 as useDisplayNames};
54
- //# sourceMappingURL=useDisplayNames.mjs.map
54
+ //# sourceMappingURL=useDisplayNames.module.js.map
@@ -22,14 +22,14 @@ function $parcel$interopDefault(a) {
22
22
 
23
23
  function $3aeceb3a64eb8358$export$d42c60378c8168f8() {
24
24
  let { locale: locale } = (0, $jR5iF$useLocale)();
25
- let dictionary = (0, $jR5iF$useLocalizedStringDictionary)((0, ($parcel$interopDefault($jR5iF$intlStringsmodulejs))), "@react-aria/datepicker");
25
+ let dictionary = (0, $jR5iF$useLocalizedStringDictionary)((0, ($parcel$interopDefault($jR5iF$intlStringsmodulejs))), '@react-aria/datepicker');
26
26
  return (0, $jR5iF$useMemo)(()=>{
27
27
  // Try to use Intl.DisplayNames if possible. It may be supported in browsers, but not support the dateTimeField
28
28
  // type as that was only added in v2. https://github.com/tc39/intl-displaynames-v2
29
29
  try {
30
30
  // @ts-ignore
31
31
  return new Intl.DisplayNames(locale, {
32
- type: "dateTimeField"
32
+ type: 'dateTimeField'
33
33
  });
34
34
  } catch (err) {
35
35
  return new $3aeceb3a64eb8358$var$DisplayNamesPolyfill(locale, dictionary);
package/dist/zh-CN.mjs CHANGED
@@ -20,4 +20,4 @@ $51078838e1b16cd7$exports = {
20
20
 
21
21
 
22
22
  export {$51078838e1b16cd7$exports as default};
23
- //# sourceMappingURL=zh-CN.mjs.map
23
+ //# sourceMappingURL=zh-CN.module.js.map
package/dist/zh-TW.mjs CHANGED
@@ -20,4 +20,4 @@ $33fab8219207655a$exports = {
20
20
 
21
21
 
22
22
  export {$33fab8219207655a$exports as default};
23
- //# sourceMappingURL=zh-TW.mjs.map
23
+ //# sourceMappingURL=zh-TW.module.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/datepicker",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,31 +22,31 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@internationalized/date": "^3.5.3",
26
- "@internationalized/number": "^3.5.2",
27
- "@internationalized/string": "^3.2.2",
28
- "@react-aria/focus": "^3.17.0",
29
- "@react-aria/form": "^3.0.4",
30
- "@react-aria/i18n": "^3.11.0",
31
- "@react-aria/interactions": "^3.21.2",
32
- "@react-aria/label": "^3.7.7",
33
- "@react-aria/spinbutton": "^3.6.4",
34
- "@react-aria/utils": "^3.24.0",
35
- "@react-stately/datepicker": "^3.9.3",
36
- "@react-stately/form": "^3.0.2",
37
- "@react-types/button": "^3.9.3",
38
- "@react-types/calendar": "^3.4.5",
39
- "@react-types/datepicker": "^3.7.3",
40
- "@react-types/dialog": "^3.5.9",
41
- "@react-types/shared": "^3.23.0",
25
+ "@internationalized/date": "^3.5.5",
26
+ "@internationalized/number": "^3.5.3",
27
+ "@internationalized/string": "^3.2.3",
28
+ "@react-aria/focus": "^3.18.0",
29
+ "@react-aria/form": "^3.0.6",
30
+ "@react-aria/i18n": "^3.12.0",
31
+ "@react-aria/interactions": "^3.22.0",
32
+ "@react-aria/label": "^3.7.9",
33
+ "@react-aria/spinbutton": "^3.6.6",
34
+ "@react-aria/utils": "^3.25.0",
35
+ "@react-stately/datepicker": "^3.10.0",
36
+ "@react-stately/form": "^3.0.4",
37
+ "@react-types/button": "^3.9.5",
38
+ "@react-types/calendar": "^3.4.7",
39
+ "@react-types/datepicker": "^3.8.0",
40
+ "@react-types/dialog": "^3.5.11",
41
+ "@react-types/shared": "^3.24.0",
42
42
  "@swc/helpers": "^0.5.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
46
- "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
45
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
46
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
51
+ "gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
52
52
  }