@react-stately/datepicker 3.9.1 → 3.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +4 -1514
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +8 -1518
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +4 -1514
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/placeholders.main.js +409 -0
  34. package/dist/placeholders.main.js.map +1 -0
  35. package/dist/placeholders.mjs +404 -0
  36. package/dist/placeholders.module.js +404 -0
  37. package/dist/placeholders.module.js.map +1 -0
  38. package/dist/pt-BR.mjs +1 -1
  39. package/dist/pt-PT.mjs +1 -1
  40. package/dist/ro-RO.mjs +1 -1
  41. package/dist/ru-RU.mjs +1 -1
  42. package/dist/sk-SK.mjs +1 -1
  43. package/dist/sl-SI.mjs +1 -1
  44. package/dist/sr-SP.mjs +1 -1
  45. package/dist/sv-SE.mjs +1 -1
  46. package/dist/tr-TR.mjs +1 -1
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/uk-UA.mjs +1 -1
  49. package/dist/useDateFieldState.main.js +441 -0
  50. package/dist/useDateFieldState.main.js.map +1 -0
  51. package/dist/useDateFieldState.mjs +436 -0
  52. package/dist/useDateFieldState.module.js +436 -0
  53. package/dist/useDateFieldState.module.js.map +1 -0
  54. package/dist/useDatePickerState.main.js +130 -0
  55. package/dist/useDatePickerState.main.js.map +1 -0
  56. package/dist/useDatePickerState.mjs +125 -0
  57. package/dist/useDatePickerState.module.js +125 -0
  58. package/dist/useDatePickerState.module.js.map +1 -0
  59. package/dist/useDateRangePickerState.main.js +237 -0
  60. package/dist/useDateRangePickerState.main.js.map +1 -0
  61. package/dist/useDateRangePickerState.mjs +232 -0
  62. package/dist/useDateRangePickerState.module.js +232 -0
  63. package/dist/useDateRangePickerState.module.js.map +1 -0
  64. package/dist/useTimeFieldState.main.js +86 -0
  65. package/dist/useTimeFieldState.main.js.map +1 -0
  66. package/dist/useTimeFieldState.mjs +81 -0
  67. package/dist/useTimeFieldState.module.js +81 -0
  68. package/dist/useTimeFieldState.module.js.map +1 -0
  69. package/dist/utils.main.js +190 -0
  70. package/dist/utils.main.js.map +1 -0
  71. package/dist/utils.mjs +179 -0
  72. package/dist/utils.module.js +179 -0
  73. package/dist/utils.module.js.map +1 -0
  74. package/dist/zh-CN.mjs +1 -1
  75. package/dist/zh-TW.mjs +1 -1
  76. package/package.json +9 -9
  77. package/src/utils.ts +2 -1
@@ -0,0 +1,436 @@
1
+ import {convertValue as $35a22f14a1f04b11$export$61a490a80c552550, createPlaceholderDate as $35a22f14a1f04b11$export$66aa2b09de4b1ea5, getFormatOptions as $35a22f14a1f04b11$export$7e319ea407e63bc0, getValidationResult as $35a22f14a1f04b11$export$f18627323ab57ac0, useDefaultProps as $35a22f14a1f04b11$export$2440da353cedad43} from "./utils.module.js";
2
+ import {getPlaceholder as $3e3ed55ab2966714$export$d3f5c5e0a5023fa0} from "./placeholders.module.js";
3
+ import {DateFormatter as $g03ag$DateFormatter, toCalendar as $g03ag$toCalendar, GregorianCalendar as $g03ag$GregorianCalendar, getMinimumMonthInYear as $g03ag$getMinimumMonthInYear, getMinimumDayInMonth as $g03ag$getMinimumDayInMonth} from "@internationalized/date";
4
+ import {useFormValidationState as $g03ag$useFormValidationState} from "@react-stately/form";
5
+ import {useControlledState as $g03ag$useControlledState} from "@react-stately/utils";
6
+ import {useMemo as $g03ag$useMemo, useState as $g03ag$useState, useRef as $g03ag$useRef, useEffect as $g03ag$useEffect} from "react";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
25
+ year: true,
26
+ month: true,
27
+ day: true,
28
+ hour: true,
29
+ minute: true,
30
+ second: true,
31
+ dayPeriod: true,
32
+ era: true
33
+ };
34
+ const $3c0fc76039f1c516$var$PAGE_STEP = {
35
+ year: 5,
36
+ month: 2,
37
+ day: 7,
38
+ hour: 2,
39
+ minute: 15,
40
+ second: 15
41
+ };
42
+ // Node seems to convert everything to lowercase...
43
+ const $3c0fc76039f1c516$var$TYPE_MAPPING = {
44
+ dayperiod: "dayPeriod"
45
+ };
46
+ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
47
+ let { locale: locale, createCalendar: createCalendar, hideTimeZone: hideTimeZone, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
48
+ let v = props.value || props.defaultValue || props.placeholderValue;
49
+ let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
50
+ let timeZone = defaultTimeZone || "UTC";
51
+ // props.granularity must actually exist in the value if one is provided.
52
+ if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
53
+ let defaultFormatter = (0, $g03ag$useMemo)(()=>new (0, $g03ag$DateFormatter)(locale), [
54
+ locale
55
+ ]);
56
+ let calendar = (0, $g03ag$useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
57
+ createCalendar,
58
+ defaultFormatter
59
+ ]);
60
+ let [value, setDate] = (0, $g03ag$useControlledState)(props.value, props.defaultValue, props.onChange);
61
+ let calendarValue = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$61a490a80c552550)(value, calendar), [
62
+ value,
63
+ calendar
64
+ ]);
65
+ // We keep track of the placeholder date separately in state so that onChange is not called
66
+ // until all segments are set. If the value === null (not undefined), then assume the component
67
+ // is controlled, so use the placeholder as the value until all segments are entered so it doesn't
68
+ // change from uncontrolled to controlled and emit a warning.
69
+ let [placeholderDate, setPlaceholderDate] = (0, $g03ag$useState)(()=>(0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
70
+ let val = calendarValue || placeholderDate;
71
+ let showEra = calendar.identifier === "gregory" && val.era === "BC";
72
+ let formatOpts = (0, $g03ag$useMemo)(()=>{
73
+ var _props_maxGranularity;
74
+ return {
75
+ granularity: granularity,
76
+ maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
77
+ timeZone: defaultTimeZone,
78
+ hideTimeZone: hideTimeZone,
79
+ hourCycle: props.hourCycle,
80
+ showEra: showEra,
81
+ shouldForceLeadingZeros: props.shouldForceLeadingZeros
82
+ };
83
+ }, [
84
+ props.maxGranularity,
85
+ granularity,
86
+ props.hourCycle,
87
+ props.shouldForceLeadingZeros,
88
+ defaultTimeZone,
89
+ hideTimeZone,
90
+ showEra
91
+ ]);
92
+ let opts = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, formatOpts), [
93
+ formatOpts
94
+ ]);
95
+ let dateFormatter = (0, $g03ag$useMemo)(()=>new (0, $g03ag$DateFormatter)(locale, opts), [
96
+ locale,
97
+ opts
98
+ ]);
99
+ let resolvedOptions = (0, $g03ag$useMemo)(()=>dateFormatter.resolvedOptions(), [
100
+ dateFormatter
101
+ ]);
102
+ // Determine how many editable segments there are for validation purposes.
103
+ // The result is cached for performance.
104
+ let allSegments = (0, $g03ag$useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[seg.type] = true, p), {}), [
105
+ dateFormatter
106
+ ]);
107
+ let [validSegments, setValidSegments] = (0, $g03ag$useState)(()=>props.value || props.defaultValue ? {
108
+ ...allSegments
109
+ } : {});
110
+ let clearedSegment = (0, $g03ag$useRef)();
111
+ // Reset placeholder when calendar changes
112
+ let lastCalendarIdentifier = (0, $g03ag$useRef)(calendar.identifier);
113
+ (0, $g03ag$useEffect)(()=>{
114
+ if (calendar.identifier !== lastCalendarIdentifier.current) {
115
+ lastCalendarIdentifier.current = calendar.identifier;
116
+ setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $g03ag$toCalendar)(placeholder, calendar) : (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
117
+ }
118
+ }, [
119
+ calendar,
120
+ granularity,
121
+ validSegments,
122
+ defaultTimeZone,
123
+ props.placeholderValue
124
+ ]);
125
+ // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
126
+ if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
127
+ validSegments = {
128
+ ...allSegments
129
+ };
130
+ setValidSegments(validSegments);
131
+ }
132
+ // If the value is set to null and all segments are valid, reset the placeholder.
133
+ if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
134
+ validSegments = {};
135
+ setValidSegments(validSegments);
136
+ setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
137
+ }
138
+ // If all segments are valid, use the date from state, otherwise use the placeholder date.
139
+ let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
140
+ let setValue = (newValue)=>{
141
+ if (props.isDisabled || props.isReadOnly) return;
142
+ let validKeys = Object.keys(validSegments);
143
+ let allKeys = Object.keys(allSegments);
144
+ // if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared
145
+ if (newValue == null) {
146
+ setDate(null);
147
+ setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
148
+ setValidSegments({});
149
+ } else if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== "dayPeriod") {
150
+ // The display calendar should not have any effect on the emitted value.
151
+ // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
152
+ newValue = (0, $g03ag$toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $g03ag$GregorianCalendar)());
153
+ setDate(newValue);
154
+ } else setPlaceholderDate(newValue);
155
+ clearedSegment.current = null;
156
+ };
157
+ let dateValue = (0, $g03ag$useMemo)(()=>displayValue.toDate(timeZone), [
158
+ displayValue,
159
+ timeZone
160
+ ]);
161
+ let segments = (0, $g03ag$useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
162
+ let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
163
+ if (segment.type === "era" && calendar.getEras().length === 1) isEditable = false;
164
+ let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
165
+ let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? (0, $3e3ed55ab2966714$export$d3f5c5e0a5023fa0)(segment.type, segment.value, locale) : null;
166
+ return {
167
+ type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
168
+ text: isPlaceholder ? placeholder : segment.value,
169
+ ...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
170
+ isPlaceholder: isPlaceholder,
171
+ placeholder: placeholder,
172
+ isEditable: isEditable
173
+ };
174
+ }), [
175
+ dateValue,
176
+ validSegments,
177
+ dateFormatter,
178
+ resolvedOptions,
179
+ displayValue,
180
+ calendar,
181
+ locale
182
+ ]);
183
+ // When the era field appears, mark it valid if the year field is already valid.
184
+ // If the era field disappears, remove it from the valid segments.
185
+ if (allSegments.era && validSegments.year && !validSegments.era) {
186
+ validSegments.era = true;
187
+ setValidSegments({
188
+ ...validSegments
189
+ });
190
+ } else if (!allSegments.era && validSegments.era) {
191
+ delete validSegments.era;
192
+ setValidSegments({
193
+ ...validSegments
194
+ });
195
+ }
196
+ let markValid = (part)=>{
197
+ validSegments[part] = true;
198
+ if (part === "year" && allSegments.era) validSegments.era = true;
199
+ setValidSegments({
200
+ ...validSegments
201
+ });
202
+ };
203
+ let adjustSegment = (type, amount)=>{
204
+ if (!validSegments[type]) {
205
+ markValid(type);
206
+ let validKeys = Object.keys(validSegments);
207
+ let allKeys = Object.keys(allSegments);
208
+ if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) setValue(displayValue);
209
+ } else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
210
+ };
211
+ let builtinValidation = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
212
+ value,
213
+ minValue,
214
+ maxValue,
215
+ isDateUnavailable,
216
+ formatOpts
217
+ ]);
218
+ let validation = (0, $g03ag$useFormValidationState)({
219
+ ...props,
220
+ value: value,
221
+ builtinValidation: builtinValidation
222
+ });
223
+ let isValueInvalid = validation.displayValidation.isInvalid;
224
+ let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
225
+ var _props_maxGranularity;
226
+ return {
227
+ ...validation,
228
+ value: calendarValue,
229
+ dateValue: dateValue,
230
+ calendar: calendar,
231
+ setValue: setValue,
232
+ segments: segments,
233
+ dateFormatter: dateFormatter,
234
+ validationState: validationState,
235
+ isInvalid: isValueInvalid,
236
+ granularity: granularity,
237
+ maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
238
+ isDisabled: isDisabled,
239
+ isReadOnly: isReadOnly,
240
+ isRequired: isRequired,
241
+ increment (part) {
242
+ adjustSegment(part, 1);
243
+ },
244
+ decrement (part) {
245
+ adjustSegment(part, -1);
246
+ },
247
+ incrementPage (part) {
248
+ adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
249
+ },
250
+ decrementPage (part) {
251
+ adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
252
+ },
253
+ setSegment (part, v) {
254
+ markValid(part);
255
+ setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
256
+ },
257
+ confirmPlaceholder () {
258
+ if (props.isDisabled || props.isReadOnly) return;
259
+ // Confirm the placeholder if only the day period is not filled in.
260
+ let validKeys = Object.keys(validSegments);
261
+ let allKeys = Object.keys(allSegments);
262
+ if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
263
+ validSegments = {
264
+ ...allSegments
265
+ };
266
+ setValidSegments(validSegments);
267
+ setValue(displayValue.copy());
268
+ }
269
+ },
270
+ clearSegment (part) {
271
+ delete validSegments[part];
272
+ clearedSegment.current = part;
273
+ setValidSegments({
274
+ ...validSegments
275
+ });
276
+ let placeholder = (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone);
277
+ let value = displayValue;
278
+ // Reset day period to default without changing the hour.
279
+ if (part === "dayPeriod" && "hour" in displayValue && "hour" in placeholder) {
280
+ let isPM = displayValue.hour >= 12;
281
+ let shouldBePM = placeholder.hour >= 12;
282
+ if (isPM && !shouldBePM) value = displayValue.set({
283
+ hour: displayValue.hour - 12
284
+ });
285
+ else if (!isPM && shouldBePM) value = displayValue.set({
286
+ hour: displayValue.hour + 12
287
+ });
288
+ } else if (part in displayValue) value = displayValue.set({
289
+ [part]: placeholder[part]
290
+ });
291
+ setDate(null);
292
+ setValue(value);
293
+ },
294
+ formatValue (fieldOptions) {
295
+ if (!calendarValue) return "";
296
+ let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
297
+ let formatter = new (0, $g03ag$DateFormatter)(locale, formatOptions);
298
+ return formatter.format(dateValue);
299
+ }
300
+ };
301
+ }
302
+ function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
303
+ switch(type){
304
+ case "era":
305
+ {
306
+ let eras = date.calendar.getEras();
307
+ return {
308
+ value: eras.indexOf(date.era),
309
+ minValue: 0,
310
+ maxValue: eras.length - 1
311
+ };
312
+ }
313
+ case "year":
314
+ return {
315
+ value: date.year,
316
+ minValue: 1,
317
+ maxValue: date.calendar.getYearsInEra(date)
318
+ };
319
+ case "month":
320
+ return {
321
+ value: date.month,
322
+ minValue: (0, $g03ag$getMinimumMonthInYear)(date),
323
+ maxValue: date.calendar.getMonthsInYear(date)
324
+ };
325
+ case "day":
326
+ return {
327
+ value: date.day,
328
+ minValue: (0, $g03ag$getMinimumDayInMonth)(date),
329
+ maxValue: date.calendar.getDaysInMonth(date)
330
+ };
331
+ }
332
+ if ("hour" in date) switch(type){
333
+ case "dayPeriod":
334
+ return {
335
+ value: date.hour >= 12 ? 12 : 0,
336
+ minValue: 0,
337
+ maxValue: 12
338
+ };
339
+ case "hour":
340
+ if (options.hour12) {
341
+ let isPM = date.hour >= 12;
342
+ return {
343
+ value: date.hour,
344
+ minValue: isPM ? 12 : 0,
345
+ maxValue: isPM ? 23 : 11
346
+ };
347
+ }
348
+ return {
349
+ value: date.hour,
350
+ minValue: 0,
351
+ maxValue: 23
352
+ };
353
+ case "minute":
354
+ return {
355
+ value: date.minute,
356
+ minValue: 0,
357
+ maxValue: 59
358
+ };
359
+ case "second":
360
+ return {
361
+ value: date.second,
362
+ minValue: 0,
363
+ maxValue: 59
364
+ };
365
+ }
366
+ return {};
367
+ }
368
+ function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
369
+ switch(part){
370
+ case "era":
371
+ case "year":
372
+ case "month":
373
+ case "day":
374
+ return value.cycle(part, amount, {
375
+ round: part === "year"
376
+ });
377
+ }
378
+ if ("hour" in value) switch(part){
379
+ case "dayPeriod":
380
+ {
381
+ let hours = value.hour;
382
+ let isPM = hours >= 12;
383
+ return value.set({
384
+ hour: isPM ? hours - 12 : hours + 12
385
+ });
386
+ }
387
+ case "hour":
388
+ case "minute":
389
+ case "second":
390
+ return value.cycle(part, amount, {
391
+ round: part !== "hour",
392
+ hourCycle: options.hour12 ? 12 : 24
393
+ });
394
+ }
395
+ }
396
+ function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
397
+ switch(part){
398
+ case "day":
399
+ case "month":
400
+ case "year":
401
+ case "era":
402
+ return value.set({
403
+ [part]: segmentValue
404
+ });
405
+ }
406
+ if ("hour" in value) switch(part){
407
+ case "dayPeriod":
408
+ {
409
+ let hours = value.hour;
410
+ let wasPM = hours >= 12;
411
+ let isPM = segmentValue >= 12;
412
+ if (isPM === wasPM) return value;
413
+ return value.set({
414
+ hour: wasPM ? hours - 12 : hours + 12
415
+ });
416
+ }
417
+ case "hour":
418
+ // In 12 hour time, ensure that AM/PM does not change
419
+ if (options.hour12) {
420
+ let hours = value.hour;
421
+ let wasPM = hours >= 12;
422
+ if (!wasPM && segmentValue === 12) segmentValue = 0;
423
+ if (wasPM && segmentValue < 12) segmentValue += 12;
424
+ }
425
+ // fallthrough
426
+ case "minute":
427
+ case "second":
428
+ return value.set({
429
+ [part]: segmentValue
430
+ });
431
+ }
432
+ }
433
+
434
+
435
+ export {$3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState};
436
+ //# sourceMappingURL=useDateFieldState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAwFD,MAAM,0CAAoB;IACxB,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,KAAK;AACP;AAEA,MAAM,kCAAY;IAChB,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;AACV;AAEA,mDAAmD;AACnD,MAAM,qCAAe;IACnB,WAAW;AACb;AAwBO,SAAS,0CAAmD,KAA+B;IAChG,IAAI,UACF,MAAM,kBACN,cAAc,gBACd,YAAY,cACZ,UAAU,cACV,UAAU,cACV,UAAU,YACV,QAAQ,YACR,QAAQ,qBACR,iBAAiB,EAClB,GAAG;IAEJ,IAAI,IAAgB,MAAM,KAAK,IAAI,MAAM,YAAY,IAAI,MAAM,gBAAgB;IAC/E,IAAI,CAAC,aAAa,gBAAgB,GAAG,CAAA,GAAA,yCAAc,EAAE,GAAG,MAAM,WAAW;IACzE,IAAI,WAAW,mBAAmB;IAElC,yEAAyE;IACzE,IAAI,KAAK,CAAE,CAAA,eAAe,CAAA,GACxB,MAAM,IAAI,MAAM,yBAAyB,cAAc,gBAAgB,EAAE,QAAQ;IAGnF,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE,IAA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QAAQ;gBAC/B,OAAO,SAAS;gBAChB,WAAW,QAAQ,MAAM,GAAG,KAAK;YACnC;IACJ;AAEJ;AAEA,SAAS,iCAAW,KAAgB,EAAE,IAAY,EAAE,YAAoB,EAAE,OAA2C;IACnH,OAAQ;QACN,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAO,MAAM,GAAG,CAAC;gBAAC,CAAC,KAAK,EAAE;YAAY;IAC1C;IAEA,IAAI,UAAU,OACZ,OAAQ;QACN,KAAK;YAAa;gBAChB,IAAI,QAAQ,MAAM,IAAI;gBACtB,IAAI,QAAQ,SAAS;gBACrB,IAAI,OAAO,gBAAgB;gBAC3B,IAAI,SAAS,OACX,OAAO;gBAET,OAAO,MAAM,GAAG,CAAC;oBAAC,MAAM,QAAQ,QAAQ,KAAK,QAAQ;gBAAE;YACzD;QACA,KAAK;YACH,qDAAqD;YACrD,IAAI,QAAQ,MAAM,EAAE;gBAClB,IAAI,QAAQ,MAAM,IAAI;gBACtB,IAAI,QAAQ,SAAS;gBACrB,IAAI,CAAC,SAAS,iBAAiB,IAC7B,eAAe;gBAEjB,IAAI,SAAS,eAAe,IAC1B,gBAAgB;YAEpB;QACA,cAAc;QAChB,KAAK;QACL,KAAK;YACH,OAAO,MAAM,GAAG,CAAC;gBAAC,CAAC,KAAK,EAAE;YAAY;IAC1C;AAEJ","sources":["packages/@react-stately/datepicker/src/useDateFieldState.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 {Calendar, DateFormatter, getMinimumDayInMonth, getMinimumMonthInYear, GregorianCalendar, toCalendar} from '@internationalized/date';\nimport {convertValue, createPlaceholderDate, FieldOptions, getFormatOptions, getValidationResult, useDefaultProps} from './utils';\nimport {DatePickerProps, DateValue, Granularity} from '@react-types/datepicker';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {getPlaceholder} from './placeholders';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport type SegmentType = 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'dayPeriod' | 'literal' | 'timeZoneName';\nexport interface DateSegment {\n /** The type of segment. */\n type: SegmentType,\n /** The formatted text for the segment. */\n text: string,\n /** The numeric value for the segment, if applicable. */\n value?: number,\n /** The minimum numeric value for the segment, if applicable. */\n minValue?: number,\n /** The maximum numeric value for the segment, if applicable. */\n maxValue?: number,\n /** Whether the value is a placeholder. */\n isPlaceholder: boolean,\n /** A placeholder string for the segment. */\n placeholder: string,\n /** Whether the segment is editable. */\n isEditable: boolean\n}\n\nexport interface DateFieldState extends FormValidationState {\n /** The current field value. */\n value: DateValue,\n /** The current value, converted to a native JavaScript `Date` object. */\n dateValue: Date,\n /** The calendar system currently in use. */\n calendar: Calendar,\n /** Sets the field's value. */\n setValue(value: DateValue): void,\n /** A list of segments for the current value. */\n segments: DateSegment[],\n /** A date formatter configured for the current locale and format. */\n dateFormatter: DateFormatter,\n /**\n * The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props.\n * @deprecated Use `isInvalid` instead.\n */\n validationState: ValidationState,\n /** Whether the date field is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */\n isInvalid: boolean,\n /** The granularity for the field, based on the `granularity` prop and current value. */\n granularity: Granularity,\n /** The maximum date or time unit that is displayed in the field. */\n maxGranularity: 'year' | 'month' | Granularity,\n /** Whether the field is disabled. */\n isDisabled: boolean,\n /** Whether the field is read only. */\n isReadOnly: boolean,\n /** Whether the field is required. */\n isRequired: boolean,\n /** Increments the given segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment(type: SegmentType): void,\n /** Decrements the given segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement(type: SegmentType): void,\n /**\n * Increments the given segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage(type: SegmentType): void,\n /**\n * Decrements the given segment by a larger amount, rounding it to the nearest increment.\n * The amount to decrement by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage(type: SegmentType): void,\n /** Sets the value of the given segment. */\n setSegment(type: 'era', value: string): void,\n setSegment(type: SegmentType, value: number): void,\n /** Updates the remaining unfilled segments with the placeholder value. */\n confirmPlaceholder(): void,\n /** Clears the value of the given segment, reverting it to the placeholder. */\n clearSegment(type: SegmentType): void,\n /** Formats the current date value using the given options. */\n formatValue(fieldOptions: FieldOptions): string\n}\n\nconst EDITABLE_SEGMENTS = {\n year: true,\n month: true,\n day: true,\n hour: true,\n minute: true,\n second: true,\n dayPeriod: true,\n era: true\n};\n\nconst PAGE_STEP = {\n year: 5,\n month: 2,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15\n};\n\n// Node seems to convert everything to lowercase...\nconst TYPE_MAPPING = {\n dayperiod: 'dayPeriod'\n};\n\nexport interface DateFieldStateOptions<T extends DateValue = DateValue> extends DatePickerProps<T> {\n /**\n * The maximum unit to display in the date field.\n * @default 'year'\n */\n maxGranularity?: 'year' | 'month' | Granularity,\n /** The locale to display and edit the value according to. */\n locale: string,\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: string) => Calendar\n}\n\n/**\n * Provides state management for a date field component.\n * A date field allows users to enter and edit date and time values using a keyboard.\n * Each part of a date value is displayed in an individually editable segment.\n */\nexport function useDateFieldState<T extends DateValue = DateValue>(props: DateFieldStateOptions<T>): DateFieldState {\n let {\n locale,\n createCalendar,\n hideTimeZone,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n isDateUnavailable\n } = props;\n\n let v: DateValue = (props.value || props.defaultValue || props.placeholderValue);\n let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);\n let timeZone = defaultTimeZone || 'UTC';\n\n // props.granularity must actually exist in the value if one is provided.\n if (v && !(granularity in v)) {\n throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());\n }\n\n let defaultFormatter = useMemo(() => new DateFormatter(locale), [locale]);\n let calendar = useMemo(() => createCalendar(defaultFormatter.resolvedOptions().calendar), [createCalendar, defaultFormatter]);\n\n let [value, setDate] = useControlledState<DateValue>(\n props.value,\n props.defaultValue,\n props.onChange\n );\n\n let calendarValue = useMemo(() => convertValue(value, calendar), [value, calendar]);\n\n // We keep track of the placeholder date separately in state so that onChange is not called\n // until all segments are set. If the value === null (not undefined), then assume the component\n // is controlled, so use the placeholder as the value until all segments are entered so it doesn't\n // change from uncontrolled to controlled and emit a warning.\n let [placeholderDate, setPlaceholderDate] = useState(\n () => createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone)\n );\n\n let val = calendarValue || placeholderDate;\n let showEra = calendar.identifier === 'gregory' && val.era === 'BC';\n let formatOpts = useMemo(() => ({\n granularity,\n maxGranularity: props.maxGranularity ?? 'year',\n timeZone: defaultTimeZone,\n hideTimeZone,\n hourCycle: props.hourCycle,\n showEra,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros\n }), [props.maxGranularity, granularity, props.hourCycle, props.shouldForceLeadingZeros, defaultTimeZone, hideTimeZone, showEra]);\n let opts = useMemo(() => getFormatOptions({}, formatOpts), [formatOpts]);\n\n let dateFormatter = useMemo(() => new DateFormatter(locale, opts), [locale, opts]);\n let resolvedOptions = useMemo(() => dateFormatter.resolvedOptions(), [dateFormatter]);\n\n // Determine how many editable segments there are for validation purposes.\n // The result is cached for performance.\n let allSegments: Partial<typeof EDITABLE_SEGMENTS> = useMemo(() =>\n dateFormatter.formatToParts(new Date())\n .filter(seg => EDITABLE_SEGMENTS[seg.type])\n .reduce((p, seg) => (p[seg.type] = true, p), {})\n , [dateFormatter]);\n\n let [validSegments, setValidSegments] = useState<Partial<typeof EDITABLE_SEGMENTS>>(\n () => props.value || props.defaultValue ? {...allSegments} : {}\n );\n\n let clearedSegment = useRef<string>();\n\n // Reset placeholder when calendar changes\n let lastCalendarIdentifier = useRef(calendar.identifier);\n useEffect(() => {\n if (calendar.identifier !== lastCalendarIdentifier.current) {\n lastCalendarIdentifier.current = calendar.identifier;\n setPlaceholderDate(placeholder =>\n Object.keys(validSegments).length > 0\n ? toCalendar(placeholder, calendar)\n : createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone)\n );\n }\n }, [calendar, granularity, validSegments, defaultTimeZone, props.placeholderValue]);\n\n // If there is a value prop, and some segments were previously placeholders, mark them all as valid.\n if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {\n validSegments = {...allSegments};\n setValidSegments(validSegments);\n }\n\n // If the value is set to null and all segments are valid, reset the placeholder.\n if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {\n validSegments = {};\n setValidSegments(validSegments);\n setPlaceholderDate(createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone));\n }\n\n // If all segments are valid, use the date from state, otherwise use the placeholder date.\n let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;\n let setValue = (newValue: DateValue) => {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n let validKeys = Object.keys(validSegments);\n let allKeys = Object.keys(allSegments);\n\n // if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared\n if (newValue == null) {\n setDate(null);\n setPlaceholderDate(createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone));\n setValidSegments({});\n } else if (validKeys.length >= allKeys.length || (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== 'dayPeriod')) {\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n newValue = toCalendar(newValue, v?.calendar || new GregorianCalendar());\n setDate(newValue);\n } else {\n setPlaceholderDate(newValue);\n }\n clearedSegment.current = null;\n };\n\n let dateValue = useMemo(() => displayValue.toDate(timeZone), [displayValue, timeZone]);\n let segments = useMemo(() =>\n dateFormatter.formatToParts(dateValue)\n .map(segment => {\n let isEditable = EDITABLE_SEGMENTS[segment.type];\n if (segment.type === 'era' && calendar.getEras().length === 1) {\n isEditable = false;\n }\n\n let isPlaceholder = EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];\n let placeholder = EDITABLE_SEGMENTS[segment.type] ? getPlaceholder(segment.type, segment.value, locale) : null;\n return {\n type: TYPE_MAPPING[segment.type] || segment.type,\n text: isPlaceholder ? placeholder : segment.value,\n ...getSegmentLimits(displayValue, segment.type, resolvedOptions),\n isPlaceholder,\n placeholder,\n isEditable\n } as DateSegment;\n })\n , [dateValue, validSegments, dateFormatter, resolvedOptions, displayValue, calendar, locale]);\n\n // When the era field appears, mark it valid if the year field is already valid.\n // If the era field disappears, remove it from the valid segments.\n if (allSegments.era && validSegments.year && !validSegments.era) {\n validSegments.era = true;\n setValidSegments({...validSegments});\n } else if (!allSegments.era && validSegments.era) {\n delete validSegments.era;\n setValidSegments({...validSegments});\n }\n\n let markValid = (part: Intl.DateTimeFormatPartTypes) => {\n validSegments[part] = true;\n if (part === 'year' && allSegments.era) {\n validSegments.era = true;\n }\n setValidSegments({...validSegments});\n };\n\n let adjustSegment = (type: Intl.DateTimeFormatPartTypes, amount: number) => {\n if (!validSegments[type]) {\n markValid(type);\n let validKeys = Object.keys(validSegments);\n let allKeys = Object.keys(allSegments);\n if (validKeys.length >= allKeys.length || (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod)) {\n setValue(displayValue);\n }\n } else {\n setValue(addSegment(displayValue, type, amount, resolvedOptions));\n }\n };\n\n let builtinValidation = useMemo(() => getValidationResult(\n value,\n minValue,\n maxValue,\n isDateUnavailable,\n formatOpts\n ), [value, minValue, maxValue, isDateUnavailable, formatOpts]);\n\n let validation = useFormValidationState({\n ...props,\n value,\n builtinValidation\n });\n\n let isValueInvalid = validation.displayValidation.isInvalid;\n let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);\n\n return {\n ...validation,\n value: calendarValue,\n dateValue,\n calendar,\n setValue,\n segments,\n dateFormatter,\n validationState,\n isInvalid: isValueInvalid,\n granularity,\n maxGranularity: props.maxGranularity ?? 'year',\n isDisabled,\n isReadOnly,\n isRequired,\n increment(part) {\n adjustSegment(part, 1);\n },\n decrement(part) {\n adjustSegment(part, -1);\n },\n incrementPage(part) {\n adjustSegment(part, PAGE_STEP[part] || 1);\n },\n decrementPage(part) {\n adjustSegment(part, -(PAGE_STEP[part] || 1));\n },\n setSegment(part, v) {\n markValid(part);\n setValue(setSegment(displayValue, part, v, resolvedOptions));\n },\n confirmPlaceholder() {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n // Confirm the placeholder if only the day period is not filled in.\n let validKeys = Object.keys(validSegments);\n let allKeys = Object.keys(allSegments);\n if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {\n validSegments = {...allSegments};\n setValidSegments(validSegments);\n setValue(displayValue.copy());\n }\n },\n clearSegment(part) {\n delete validSegments[part];\n clearedSegment.current = part;\n setValidSegments({...validSegments});\n\n let placeholder = createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone);\n let value = displayValue;\n\n // Reset day period to default without changing the hour.\n if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {\n let isPM = displayValue.hour >= 12;\n let shouldBePM = placeholder.hour >= 12;\n if (isPM && !shouldBePM) {\n value = displayValue.set({hour: displayValue.hour - 12});\n } else if (!isPM && shouldBePM) {\n value = displayValue.set({hour: displayValue.hour + 12});\n }\n } else if (part in displayValue) {\n value = displayValue.set({[part]: placeholder[part]});\n }\n\n setDate(null);\n setValue(value);\n },\n formatValue(fieldOptions: FieldOptions) {\n if (!calendarValue) {\n return '';\n }\n\n let formatOptions = getFormatOptions(fieldOptions, formatOpts);\n let formatter = new DateFormatter(locale, formatOptions);\n return formatter.format(dateValue);\n }\n };\n}\n\nfunction getSegmentLimits(date: DateValue, type: string, options: Intl.ResolvedDateTimeFormatOptions) {\n switch (type) {\n case 'era': {\n let eras = date.calendar.getEras();\n return {\n value: eras.indexOf(date.era),\n minValue: 0,\n maxValue: eras.length - 1\n };\n }\n case 'year':\n return {\n value: date.year,\n minValue: 1,\n maxValue: date.calendar.getYearsInEra(date)\n };\n case 'month':\n return {\n value: date.month,\n minValue: getMinimumMonthInYear(date),\n maxValue: date.calendar.getMonthsInYear(date)\n };\n case 'day':\n return {\n value: date.day,\n minValue: getMinimumDayInMonth(date),\n maxValue: date.calendar.getDaysInMonth(date)\n };\n }\n\n if ('hour' in date) {\n switch (type) {\n case 'dayPeriod':\n return {\n value: date.hour >= 12 ? 12 : 0,\n minValue: 0,\n maxValue: 12\n };\n case 'hour':\n if (options.hour12) {\n let isPM = date.hour >= 12;\n return {\n value: date.hour,\n minValue: isPM ? 12 : 0,\n maxValue: isPM ? 23 : 11\n };\n }\n\n return {\n value: date.hour,\n minValue: 0,\n maxValue: 23\n };\n case 'minute':\n return {\n value: date.minute,\n minValue: 0,\n maxValue: 59\n };\n case 'second':\n return {\n value: date.second,\n minValue: 0,\n maxValue: 59\n };\n }\n }\n\n return {};\n}\n\nfunction addSegment(value: DateValue, part: string, amount: number, options: Intl.ResolvedDateTimeFormatOptions) {\n switch (part) {\n case 'era':\n case 'year':\n case 'month':\n case 'day':\n return value.cycle(part, amount, {round: part === 'year'});\n }\n\n if ('hour' in value) {\n switch (part) {\n case 'dayPeriod': {\n let hours = value.hour;\n let isPM = hours >= 12;\n return value.set({hour: isPM ? hours - 12 : hours + 12});\n }\n case 'hour':\n case 'minute':\n case 'second':\n return value.cycle(part, amount, {\n round: part !== 'hour',\n hourCycle: options.hour12 ? 12 : 24\n });\n }\n }\n}\n\nfunction setSegment(value: DateValue, part: string, segmentValue: number, options: Intl.ResolvedDateTimeFormatOptions) {\n switch (part) {\n case 'day':\n case 'month':\n case 'year':\n case 'era':\n return value.set({[part]: segmentValue});\n }\n\n if ('hour' in value) {\n switch (part) {\n case 'dayPeriod': {\n let hours = value.hour;\n let wasPM = hours >= 12;\n let isPM = segmentValue >= 12;\n if (isPM === wasPM) {\n return value;\n }\n return value.set({hour: wasPM ? hours - 12 : hours + 12});\n }\n case 'hour':\n // In 12 hour time, ensure that AM/PM does not change\n if (options.hour12) {\n let hours = value.hour;\n let wasPM = hours >= 12;\n if (!wasPM && segmentValue === 12) {\n segmentValue = 0;\n }\n if (wasPM && segmentValue < 12) {\n segmentValue += 12;\n }\n }\n // fallthrough\n case 'minute':\n case 'second':\n return value.set({[part]: segmentValue});\n }\n }\n}\n"],"names":[],"version":3,"file":"useDateFieldState.module.js.map"}
@@ -0,0 +1,130 @@
1
+ var $50d5d6a623389320$exports = require("./utils.main.js");
2
+ var $g6L8e$internationalizeddate = require("@internationalized/date");
3
+ var $g6L8e$reactstatelyform = require("@react-stately/form");
4
+ var $g6L8e$reactstatelyoverlays = require("@react-stately/overlays");
5
+ var $g6L8e$reactstatelyutils = require("@react-stately/utils");
6
+ var $g6L8e$react = require("react");
7
+
8
+
9
+ function $parcel$export(e, n, v, s) {
10
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
+ }
12
+
13
+ $parcel$export(module.exports, "useDatePickerState", () => $aaab7a647e17e1fd$export$87194bb378cc3ac2);
14
+ /*
15
+ * Copyright 2020 Adobe. All rights reserved.
16
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License. You may obtain a copy
18
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software distributed under
21
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
+ * OF ANY KIND, either express or implied. See the License for the specific language
23
+ * governing permissions and limitations under the License.
24
+ */
25
+
26
+
27
+
28
+
29
+
30
+ function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
31
+ let overlayState = (0, $g6L8e$reactstatelyoverlays.useOverlayTriggerState)(props);
32
+ let [value, setValue] = (0, $g6L8e$reactstatelyutils.useControlledState)(props.value, props.defaultValue || null, props.onChange);
33
+ let v = value || props.placeholderValue;
34
+ let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$exports.useDefaultProps)(v, props.granularity);
35
+ let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
36
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
37
+ var _props_shouldCloseOnSelect;
38
+ let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
39
+ let [selectedDate, setSelectedDate] = (0, $g6L8e$react.useState)(null);
40
+ let [selectedTime, setSelectedTime] = (0, $g6L8e$react.useState)(null);
41
+ if (value) {
42
+ selectedDate = value;
43
+ if ("hour" in value) selectedTime = value;
44
+ }
45
+ // props.granularity must actually exist in the value if one is provided.
46
+ if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
47
+ let showEra = (value === null || value === void 0 ? void 0 : value.calendar.identifier) === "gregory" && value.era === "BC";
48
+ let formatOpts = (0, $g6L8e$react.useMemo)(()=>({
49
+ granularity: granularity,
50
+ timeZone: defaultTimeZone,
51
+ hideTimeZone: props.hideTimeZone,
52
+ hourCycle: props.hourCycle,
53
+ shouldForceLeadingZeros: props.shouldForceLeadingZeros,
54
+ showEra: showEra
55
+ }), [
56
+ granularity,
57
+ props.hourCycle,
58
+ props.shouldForceLeadingZeros,
59
+ defaultTimeZone,
60
+ props.hideTimeZone,
61
+ showEra
62
+ ]);
63
+ let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
64
+ let builtinValidation = (0, $g6L8e$react.useMemo)(()=>(0, $50d5d6a623389320$exports.getValidationResult)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
65
+ value,
66
+ minValue,
67
+ maxValue,
68
+ isDateUnavailable,
69
+ formatOpts
70
+ ]);
71
+ let validation = (0, $g6L8e$reactstatelyform.useFormValidationState)({
72
+ ...props,
73
+ value: value,
74
+ builtinValidation: builtinValidation
75
+ });
76
+ let isValueInvalid = validation.displayValidation.isInvalid;
77
+ let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
78
+ let commitValue = (date, time)=>{
79
+ setValue("timeZone" in time ? time.set((0, $g6L8e$internationalizeddate.toCalendarDate)(date)) : (0, $g6L8e$internationalizeddate.toCalendarDateTime)(date, time));
80
+ setSelectedDate(null);
81
+ setSelectedTime(null);
82
+ validation.commitValidation();
83
+ };
84
+ // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
85
+ let selectDate = (newValue)=>{
86
+ let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
87
+ if (hasTime) {
88
+ if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue));
89
+ else setSelectedDate(newValue);
90
+ } else {
91
+ setValue(newValue);
92
+ validation.commitValidation();
93
+ }
94
+ if (shouldClose) overlayState.setOpen(false);
95
+ };
96
+ let selectTime = (newValue)=>{
97
+ if (selectedDate && newValue) commitValue(selectedDate, newValue);
98
+ else setSelectedTime(newValue);
99
+ };
100
+ return {
101
+ ...validation,
102
+ value: value,
103
+ setValue: setValue,
104
+ dateValue: selectedDate,
105
+ timeValue: selectedTime,
106
+ setDateValue: selectDate,
107
+ setTimeValue: selectTime,
108
+ granularity: granularity,
109
+ hasTime: hasTime,
110
+ ...overlayState,
111
+ setOpen (isOpen) {
112
+ // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
113
+ // If only the time was set and not the date, don't commit. The state will be preserved until
114
+ // the user opens the popover again.
115
+ if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue));
116
+ overlayState.setOpen(isOpen);
117
+ },
118
+ validationState: validationState,
119
+ isInvalid: isValueInvalid,
120
+ formatValue (locale, fieldOptions) {
121
+ if (!dateValue) return "";
122
+ let formatOptions = (0, $50d5d6a623389320$exports.getFormatOptions)(fieldOptions, formatOpts);
123
+ let formatter = new (0, $g6L8e$internationalizeddate.DateFormatter)(locale, formatOptions);
124
+ return formatter.format(dateValue);
125
+ }
126
+ };
127
+ }
128
+
129
+
130
+ //# sourceMappingURL=useDatePickerState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6DM,SAAS,0CAAoD,KAAgC;IAClG,IAAI,eAAe,CAAA,GAAA,kDAAqB,EAAE;IAC1C,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAa,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,MAAM,MAAM,QAAQ;IAE7G,IAAI,IAAK,SAAS,MAAM,gBAAgB;IACxC,IAAI,CAAC,aAAa,gBAAgB,GAAG,CAAA,GAAA,yCAAc,EAAE,GAAG,MAAM,WAAW;IACzE,IAAI,YAAY,SAAS,OAAO,MAAM,MAAM,CAAC,4BAAA,6BAAA,kBAAmB,SAAS;IACzE,IAAI,UAAU,gBAAgB,UAAU,gBAAgB,YAAY,gBAAgB;QAC1D;IAA1B,IAAI,sBAAsB,CAAA,6BAAA,MAAM,mBAAmB,cAAzB,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AgB;QAChB,gBAAgB;QAChB,WAAW,gBAAgB;IAC7B;IAEA,gGAAgG;IAChG,IAAI,aAAa,CAAC;QAChB,IAAI,cAAc,OAAO,wBAAwB,aAAa,wBAAwB;QACtF,IAAI;YACF,IAAI,gBAAgB,aAClB,YAAY,UAAU,gBAAgB,CAAA,GAAA,4CAAiB,EAAE,MAAM,gBAAgB;iBAE/E,gBAAgB;eAEb;YACL,SAAS;YACT,WAAW,gBAAgB;QAC7B;QAEA,IAAI,aACF,aAAa,OAAO,CAAC;IAEzB;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,gBAAgB,UAClB,YAAY,cAAc;aAE1B,gBAAgB;IAEpB;IAEA,OAAO;QACL,GAAG,UAAU;eACb;kBACA;QACA,WAAW;QACX,WAAW;QACX,cAAc;QACd,cAAc;qBACd;iBACA;QACA,GAAG,YAAY;QACf,SAAQ,MAAM;YACZ,kGAAkG;YAClG,6FAA6F;YAC7F,oCAAoC;YACpC,IAAI,CAAC,UAAU,CAAC,SAAS,gBAAgB,SACvC,YAAY,cAAc,gBAAgB,CAAA,GAAA,4CAAiB,EAAE,MAAM,gBAAgB;YAGrF,aAAa,OAAO,CAAC;QACvB;yBACA;QACA,WAAW;QACX,aAAY,MAAM,EAAE,YAAY;YAC9B,IAAI,CAAC,WACH,OAAO;YAGT,IAAI,gBAAgB,CAAA,GAAA,0CAAe,EAAE,cAAc;YACnD,IAAI,YAAY,IAAI,CAAA,GAAA,0CAAY,EAAE,QAAQ;YAC1C,OAAO,UAAU,MAAM,CAAC;QAC1B;IACF;AACF","sources":["packages/@react-stately/datepicker/src/useDatePickerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';\nimport {DatePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';\nimport {FieldOptions, getFormatOptions, getPlaceholderTime, getValidationResult, useDefaultProps} from './utils';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface DatePickerStateOptions<T extends DateValue> extends DatePickerProps<T> {\n /**\n * Determines whether the date picker popover should close automatically when a date is selected.\n * @default true\n */\n shouldCloseOnSelect?: boolean | (() => boolean)\n}\n\nexport interface DatePickerState extends OverlayTriggerState, FormValidationState {\n /** The currently selected date. */\n value: DateValue | null,\n /** Sets the selected date. */\n setValue(value: DateValue | null): void,\n /**\n * The date portion of the value. This may be set prior to `value` if the user has\n * selected a date but has not yet selected a time.\n */\n dateValue: DateValue,\n /** Sets the date portion of the value. */\n setDateValue(value: CalendarDate): void,\n /**\n * The time portion of the value. This may be set prior to `value` if the user has\n * selected a time but has not yet selected a date.\n */\n timeValue: TimeValue,\n /** Sets the time portion of the value. */\n setTimeValue(value: TimeValue): void,\n /** The granularity for the field, based on the `granularity` prop and current value. */\n granularity: Granularity,\n /** Whether the date picker supports selecting a time, according to the `granularity` prop and current value. */\n hasTime: boolean,\n /** Whether the calendar popover is currently open. */\n isOpen: boolean,\n /** Sets whether the calendar popover is open. */\n setOpen(isOpen: boolean): void,\n /**\n * The current validation state of the date picker, based on the `validationState`, `minValue`, and `maxValue` props.\n * @deprecated Use `isInvalid` instead.\n */\n validationState: ValidationState,\n /** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */\n isInvalid: boolean,\n /** Formats the selected value using the given options. */\n formatValue(locale: string, fieldOptions: FieldOptions): string\n}\n\n/**\n * Provides state management for a date picker component.\n * A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.\n */\nexport function useDatePickerState<T extends DateValue = DateValue>(props: DatePickerStateOptions<T>): DatePickerState {\n let overlayState = useOverlayTriggerState(props);\n let [value, setValue] = useControlledState<DateValue>(props.value, props.defaultValue || null, props.onChange);\n\n let v = (value || props.placeholderValue);\n let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);\n let dateValue = value != null ? value.toDate(defaultTimeZone ?? 'UTC') : null;\n let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';\n let shouldCloseOnSelect = props.shouldCloseOnSelect ?? true;\n\n let [selectedDate, setSelectedDate] = useState<DateValue>(null);\n let [selectedTime, setSelectedTime] = useState<TimeValue>(null);\n\n if (value) {\n selectedDate = value;\n if ('hour' in value) {\n selectedTime = value;\n }\n }\n\n // props.granularity must actually exist in the value if one is provided.\n if (v && !(granularity in v)) {\n throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());\n }\n\n let showEra = value?.calendar.identifier === 'gregory' && value.era === 'BC';\n let formatOpts = useMemo(() => ({\n granularity,\n timeZone: defaultTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros,\n showEra\n }), [granularity, props.hourCycle, props.shouldForceLeadingZeros, defaultTimeZone, props.hideTimeZone, showEra]);\n\n let {minValue, maxValue, isDateUnavailable} = props;\n let builtinValidation = useMemo(() => getValidationResult(\n value,\n minValue,\n maxValue,\n isDateUnavailable,\n formatOpts\n ), [value, minValue, maxValue, isDateUnavailable, formatOpts]);\n\n let validation = useFormValidationState({\n ...props,\n value,\n builtinValidation\n });\n\n let isValueInvalid = validation.displayValidation.isInvalid;\n let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);\n\n let commitValue = (date: DateValue, time: TimeValue) => {\n setValue('timeZone' in time ? time.set(toCalendarDate(date)) : toCalendarDateTime(date, time));\n setSelectedDate(null);\n setSelectedTime(null);\n validation.commitValidation();\n };\n\n // Intercept setValue to make sure the Time section is not changed by date selection in Calendar\n let selectDate = (newValue: CalendarDate) => {\n let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;\n if (hasTime) {\n if (selectedTime || shouldClose) {\n commitValue(newValue, selectedTime || getPlaceholderTime(props.placeholderValue));\n } else {\n setSelectedDate(newValue);\n }\n } else {\n setValue(newValue);\n validation.commitValidation();\n }\n\n if (shouldClose) {\n overlayState.setOpen(false);\n }\n };\n\n let selectTime = (newValue: TimeValue) => {\n if (selectedDate && newValue) {\n commitValue(selectedDate, newValue);\n } else {\n setSelectedTime(newValue);\n }\n };\n\n return {\n ...validation,\n value,\n setValue,\n dateValue: selectedDate,\n timeValue: selectedTime,\n setDateValue: selectDate,\n setTimeValue: selectTime,\n granularity,\n hasTime,\n ...overlayState,\n setOpen(isOpen) {\n // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.\n // If only the time was set and not the date, don't commit. The state will be preserved until\n // the user opens the popover again.\n if (!isOpen && !value && selectedDate && hasTime) {\n commitValue(selectedDate, selectedTime || getPlaceholderTime(props.placeholderValue));\n }\n\n overlayState.setOpen(isOpen);\n },\n validationState,\n isInvalid: isValueInvalid,\n formatValue(locale, fieldOptions) {\n if (!dateValue) {\n return '';\n }\n\n let formatOptions = getFormatOptions(fieldOptions, formatOpts);\n let formatter = new DateFormatter(locale, formatOptions);\n return formatter.format(dateValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDatePickerState.main.js.map"}