@react-stately/datepicker 3.9.2 → 3.9.4
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.
- package/dist/import.mjs +4 -1514
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/main.js +8 -1518
- package/dist/main.js.map +1 -1
- package/dist/module.js +4 -1514
- package/dist/module.js.map +1 -1
- package/dist/placeholders.main.js +409 -0
- package/dist/placeholders.main.js.map +1 -0
- package/dist/placeholders.mjs +404 -0
- package/dist/placeholders.module.js +404 -0
- package/dist/placeholders.module.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useDateFieldState.main.js +441 -0
- package/dist/useDateFieldState.main.js.map +1 -0
- package/dist/useDateFieldState.mjs +436 -0
- package/dist/useDateFieldState.module.js +436 -0
- package/dist/useDateFieldState.module.js.map +1 -0
- package/dist/useDatePickerState.main.js +130 -0
- package/dist/useDatePickerState.main.js.map +1 -0
- package/dist/useDatePickerState.mjs +125 -0
- package/dist/useDatePickerState.module.js +125 -0
- package/dist/useDatePickerState.module.js.map +1 -0
- package/dist/useDateRangePickerState.main.js +237 -0
- package/dist/useDateRangePickerState.main.js.map +1 -0
- package/dist/useDateRangePickerState.mjs +232 -0
- package/dist/useDateRangePickerState.module.js +232 -0
- package/dist/useDateRangePickerState.module.js.map +1 -0
- package/dist/useTimeFieldState.main.js +86 -0
- package/dist/useTimeFieldState.main.js.map +1 -0
- package/dist/useTimeFieldState.mjs +81 -0
- package/dist/useTimeFieldState.module.js +81 -0
- package/dist/useTimeFieldState.module.js.map +1 -0
- package/dist/utils.main.js +190 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +179 -0
- package/dist/utils.module.js +179 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +9 -9
- package/src/utils.ts +2 -1
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
var $50d5d6a623389320$exports = require("./utils.main.js");
|
|
2
|
+
var $e1e8ada727fae1a1$exports = require("./placeholders.main.js");
|
|
3
|
+
var $iqS8N$internationalizeddate = require("@internationalized/date");
|
|
4
|
+
var $iqS8N$reactstatelyform = require("@react-stately/form");
|
|
5
|
+
var $iqS8N$reactstatelyutils = require("@react-stately/utils");
|
|
6
|
+
var $iqS8N$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, "useDateFieldState", () => $596a1f0f523d6752$export$60e84778edff6d26);
|
|
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
|
+
const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
|
|
31
|
+
year: true,
|
|
32
|
+
month: true,
|
|
33
|
+
day: true,
|
|
34
|
+
hour: true,
|
|
35
|
+
minute: true,
|
|
36
|
+
second: true,
|
|
37
|
+
dayPeriod: true,
|
|
38
|
+
era: true
|
|
39
|
+
};
|
|
40
|
+
const $596a1f0f523d6752$var$PAGE_STEP = {
|
|
41
|
+
year: 5,
|
|
42
|
+
month: 2,
|
|
43
|
+
day: 7,
|
|
44
|
+
hour: 2,
|
|
45
|
+
minute: 15,
|
|
46
|
+
second: 15
|
|
47
|
+
};
|
|
48
|
+
// Node seems to convert everything to lowercase...
|
|
49
|
+
const $596a1f0f523d6752$var$TYPE_MAPPING = {
|
|
50
|
+
dayperiod: 'dayPeriod'
|
|
51
|
+
};
|
|
52
|
+
function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
53
|
+
let { locale: locale, createCalendar: createCalendar, hideTimeZone: hideTimeZone, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
54
|
+
let v = props.value || props.defaultValue || props.placeholderValue;
|
|
55
|
+
let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$exports.useDefaultProps)(v, props.granularity);
|
|
56
|
+
let timeZone = defaultTimeZone || 'UTC';
|
|
57
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
58
|
+
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
59
|
+
let defaultFormatter = (0, $iqS8N$react.useMemo)(()=>new (0, $iqS8N$internationalizeddate.DateFormatter)(locale), [
|
|
60
|
+
locale
|
|
61
|
+
]);
|
|
62
|
+
let calendar = (0, $iqS8N$react.useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
|
|
63
|
+
createCalendar,
|
|
64
|
+
defaultFormatter
|
|
65
|
+
]);
|
|
66
|
+
let [value, setDate] = (0, $iqS8N$reactstatelyutils.useControlledState)(props.value, props.defaultValue, props.onChange);
|
|
67
|
+
let calendarValue = (0, $iqS8N$react.useMemo)(()=>(0, $50d5d6a623389320$exports.convertValue)(value, calendar), [
|
|
68
|
+
value,
|
|
69
|
+
calendar
|
|
70
|
+
]);
|
|
71
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
72
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
73
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
74
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
75
|
+
let [placeholderDate, setPlaceholderDate] = (0, $iqS8N$react.useState)(()=>(0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
76
|
+
let val = calendarValue || placeholderDate;
|
|
77
|
+
let showEra = calendar.identifier === 'gregory' && val.era === 'BC';
|
|
78
|
+
let formatOpts = (0, $iqS8N$react.useMemo)(()=>{
|
|
79
|
+
var _props_maxGranularity;
|
|
80
|
+
return {
|
|
81
|
+
granularity: granularity,
|
|
82
|
+
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : 'year',
|
|
83
|
+
timeZone: defaultTimeZone,
|
|
84
|
+
hideTimeZone: hideTimeZone,
|
|
85
|
+
hourCycle: props.hourCycle,
|
|
86
|
+
showEra: showEra,
|
|
87
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros
|
|
88
|
+
};
|
|
89
|
+
}, [
|
|
90
|
+
props.maxGranularity,
|
|
91
|
+
granularity,
|
|
92
|
+
props.hourCycle,
|
|
93
|
+
props.shouldForceLeadingZeros,
|
|
94
|
+
defaultTimeZone,
|
|
95
|
+
hideTimeZone,
|
|
96
|
+
showEra
|
|
97
|
+
]);
|
|
98
|
+
let opts = (0, $iqS8N$react.useMemo)(()=>(0, $50d5d6a623389320$exports.getFormatOptions)({}, formatOpts), [
|
|
99
|
+
formatOpts
|
|
100
|
+
]);
|
|
101
|
+
let dateFormatter = (0, $iqS8N$react.useMemo)(()=>new (0, $iqS8N$internationalizeddate.DateFormatter)(locale, opts), [
|
|
102
|
+
locale,
|
|
103
|
+
opts
|
|
104
|
+
]);
|
|
105
|
+
let resolvedOptions = (0, $iqS8N$react.useMemo)(()=>dateFormatter.resolvedOptions(), [
|
|
106
|
+
dateFormatter
|
|
107
|
+
]);
|
|
108
|
+
// Determine how many editable segments there are for validation purposes.
|
|
109
|
+
// The result is cached for performance.
|
|
110
|
+
let allSegments = (0, $iqS8N$react.useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$596a1f0f523d6752$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[seg.type] = true, p), {}), [
|
|
111
|
+
dateFormatter
|
|
112
|
+
]);
|
|
113
|
+
let [validSegments, setValidSegments] = (0, $iqS8N$react.useState)(()=>props.value || props.defaultValue ? {
|
|
114
|
+
...allSegments
|
|
115
|
+
} : {});
|
|
116
|
+
let clearedSegment = (0, $iqS8N$react.useRef)();
|
|
117
|
+
// Reset placeholder when calendar changes
|
|
118
|
+
let lastCalendarIdentifier = (0, $iqS8N$react.useRef)(calendar.identifier);
|
|
119
|
+
(0, $iqS8N$react.useEffect)(()=>{
|
|
120
|
+
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
121
|
+
lastCalendarIdentifier.current = calendar.identifier;
|
|
122
|
+
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $iqS8N$internationalizeddate.toCalendar)(placeholder, calendar) : (0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
123
|
+
}
|
|
124
|
+
}, [
|
|
125
|
+
calendar,
|
|
126
|
+
granularity,
|
|
127
|
+
validSegments,
|
|
128
|
+
defaultTimeZone,
|
|
129
|
+
props.placeholderValue
|
|
130
|
+
]);
|
|
131
|
+
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
132
|
+
if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
133
|
+
validSegments = {
|
|
134
|
+
...allSegments
|
|
135
|
+
};
|
|
136
|
+
setValidSegments(validSegments);
|
|
137
|
+
}
|
|
138
|
+
// If the value is set to null and all segments are valid, reset the placeholder.
|
|
139
|
+
if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
|
|
140
|
+
validSegments = {};
|
|
141
|
+
setValidSegments(validSegments);
|
|
142
|
+
setPlaceholderDate((0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
143
|
+
}
|
|
144
|
+
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
145
|
+
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
146
|
+
let setValue = (newValue)=>{
|
|
147
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
148
|
+
let validKeys = Object.keys(validSegments);
|
|
149
|
+
let allKeys = Object.keys(allSegments);
|
|
150
|
+
// if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared
|
|
151
|
+
if (newValue == null) {
|
|
152
|
+
setDate(null);
|
|
153
|
+
setPlaceholderDate((0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
154
|
+
setValidSegments({});
|
|
155
|
+
} else if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== 'dayPeriod') {
|
|
156
|
+
// The display calendar should not have any effect on the emitted value.
|
|
157
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
158
|
+
newValue = (0, $iqS8N$internationalizeddate.toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $iqS8N$internationalizeddate.GregorianCalendar)());
|
|
159
|
+
setDate(newValue);
|
|
160
|
+
} else setPlaceholderDate(newValue);
|
|
161
|
+
clearedSegment.current = null;
|
|
162
|
+
};
|
|
163
|
+
let dateValue = (0, $iqS8N$react.useMemo)(()=>displayValue.toDate(timeZone), [
|
|
164
|
+
displayValue,
|
|
165
|
+
timeZone
|
|
166
|
+
]);
|
|
167
|
+
let segments = (0, $iqS8N$react.useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
168
|
+
let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type];
|
|
169
|
+
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
170
|
+
let isPlaceholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
|
|
171
|
+
let placeholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] ? (0, $e1e8ada727fae1a1$exports.getPlaceholder)(segment.type, segment.value, locale) : null;
|
|
172
|
+
return {
|
|
173
|
+
type: $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
174
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
175
|
+
...$596a1f0f523d6752$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
176
|
+
isPlaceholder: isPlaceholder,
|
|
177
|
+
placeholder: placeholder,
|
|
178
|
+
isEditable: isEditable
|
|
179
|
+
};
|
|
180
|
+
}), [
|
|
181
|
+
dateValue,
|
|
182
|
+
validSegments,
|
|
183
|
+
dateFormatter,
|
|
184
|
+
resolvedOptions,
|
|
185
|
+
displayValue,
|
|
186
|
+
calendar,
|
|
187
|
+
locale
|
|
188
|
+
]);
|
|
189
|
+
// When the era field appears, mark it valid if the year field is already valid.
|
|
190
|
+
// If the era field disappears, remove it from the valid segments.
|
|
191
|
+
if (allSegments.era && validSegments.year && !validSegments.era) {
|
|
192
|
+
validSegments.era = true;
|
|
193
|
+
setValidSegments({
|
|
194
|
+
...validSegments
|
|
195
|
+
});
|
|
196
|
+
} else if (!allSegments.era && validSegments.era) {
|
|
197
|
+
delete validSegments.era;
|
|
198
|
+
setValidSegments({
|
|
199
|
+
...validSegments
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
let markValid = (part)=>{
|
|
203
|
+
validSegments[part] = true;
|
|
204
|
+
if (part === 'year' && allSegments.era) validSegments.era = true;
|
|
205
|
+
setValidSegments({
|
|
206
|
+
...validSegments
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
let adjustSegment = (type, amount)=>{
|
|
210
|
+
if (!validSegments[type]) {
|
|
211
|
+
markValid(type);
|
|
212
|
+
let validKeys = Object.keys(validSegments);
|
|
213
|
+
let allKeys = Object.keys(allSegments);
|
|
214
|
+
if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) setValue(displayValue);
|
|
215
|
+
} else setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
216
|
+
};
|
|
217
|
+
let builtinValidation = (0, $iqS8N$react.useMemo)(()=>(0, $50d5d6a623389320$exports.getValidationResult)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
218
|
+
value,
|
|
219
|
+
minValue,
|
|
220
|
+
maxValue,
|
|
221
|
+
isDateUnavailable,
|
|
222
|
+
formatOpts
|
|
223
|
+
]);
|
|
224
|
+
let validation = (0, $iqS8N$reactstatelyform.useFormValidationState)({
|
|
225
|
+
...props,
|
|
226
|
+
value: value,
|
|
227
|
+
builtinValidation: builtinValidation
|
|
228
|
+
});
|
|
229
|
+
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
230
|
+
let validationState = props.validationState || (isValueInvalid ? 'invalid' : null);
|
|
231
|
+
var _props_maxGranularity;
|
|
232
|
+
return {
|
|
233
|
+
...validation,
|
|
234
|
+
value: calendarValue,
|
|
235
|
+
dateValue: dateValue,
|
|
236
|
+
calendar: calendar,
|
|
237
|
+
setValue: setValue,
|
|
238
|
+
segments: segments,
|
|
239
|
+
dateFormatter: dateFormatter,
|
|
240
|
+
validationState: validationState,
|
|
241
|
+
isInvalid: isValueInvalid,
|
|
242
|
+
granularity: granularity,
|
|
243
|
+
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : 'year',
|
|
244
|
+
isDisabled: isDisabled,
|
|
245
|
+
isReadOnly: isReadOnly,
|
|
246
|
+
isRequired: isRequired,
|
|
247
|
+
increment (part) {
|
|
248
|
+
adjustSegment(part, 1);
|
|
249
|
+
},
|
|
250
|
+
decrement (part) {
|
|
251
|
+
adjustSegment(part, -1);
|
|
252
|
+
},
|
|
253
|
+
incrementPage (part) {
|
|
254
|
+
adjustSegment(part, $596a1f0f523d6752$var$PAGE_STEP[part] || 1);
|
|
255
|
+
},
|
|
256
|
+
decrementPage (part) {
|
|
257
|
+
adjustSegment(part, -($596a1f0f523d6752$var$PAGE_STEP[part] || 1));
|
|
258
|
+
},
|
|
259
|
+
setSegment (part, v) {
|
|
260
|
+
markValid(part);
|
|
261
|
+
setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
262
|
+
},
|
|
263
|
+
confirmPlaceholder () {
|
|
264
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
265
|
+
// Confirm the placeholder if only the day period is not filled in.
|
|
266
|
+
let validKeys = Object.keys(validSegments);
|
|
267
|
+
let allKeys = Object.keys(allSegments);
|
|
268
|
+
if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
|
|
269
|
+
validSegments = {
|
|
270
|
+
...allSegments
|
|
271
|
+
};
|
|
272
|
+
setValidSegments(validSegments);
|
|
273
|
+
setValue(displayValue.copy());
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
clearSegment (part) {
|
|
277
|
+
delete validSegments[part];
|
|
278
|
+
clearedSegment.current = part;
|
|
279
|
+
setValidSegments({
|
|
280
|
+
...validSegments
|
|
281
|
+
});
|
|
282
|
+
let placeholder = (0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
283
|
+
let value = displayValue;
|
|
284
|
+
// Reset day period to default without changing the hour.
|
|
285
|
+
if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {
|
|
286
|
+
let isPM = displayValue.hour >= 12;
|
|
287
|
+
let shouldBePM = placeholder.hour >= 12;
|
|
288
|
+
if (isPM && !shouldBePM) value = displayValue.set({
|
|
289
|
+
hour: displayValue.hour - 12
|
|
290
|
+
});
|
|
291
|
+
else if (!isPM && shouldBePM) value = displayValue.set({
|
|
292
|
+
hour: displayValue.hour + 12
|
|
293
|
+
});
|
|
294
|
+
} else if (part in displayValue) value = displayValue.set({
|
|
295
|
+
[part]: placeholder[part]
|
|
296
|
+
});
|
|
297
|
+
setDate(null);
|
|
298
|
+
setValue(value);
|
|
299
|
+
},
|
|
300
|
+
formatValue (fieldOptions) {
|
|
301
|
+
if (!calendarValue) return '';
|
|
302
|
+
let formatOptions = (0, $50d5d6a623389320$exports.getFormatOptions)(fieldOptions, formatOpts);
|
|
303
|
+
let formatter = new (0, $iqS8N$internationalizeddate.DateFormatter)(locale, formatOptions);
|
|
304
|
+
return formatter.format(dateValue);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function $596a1f0f523d6752$var$getSegmentLimits(date, type, options) {
|
|
309
|
+
switch(type){
|
|
310
|
+
case 'era':
|
|
311
|
+
{
|
|
312
|
+
let eras = date.calendar.getEras();
|
|
313
|
+
return {
|
|
314
|
+
value: eras.indexOf(date.era),
|
|
315
|
+
minValue: 0,
|
|
316
|
+
maxValue: eras.length - 1
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
case 'year':
|
|
320
|
+
return {
|
|
321
|
+
value: date.year,
|
|
322
|
+
minValue: 1,
|
|
323
|
+
maxValue: date.calendar.getYearsInEra(date)
|
|
324
|
+
};
|
|
325
|
+
case 'month':
|
|
326
|
+
return {
|
|
327
|
+
value: date.month,
|
|
328
|
+
minValue: (0, $iqS8N$internationalizeddate.getMinimumMonthInYear)(date),
|
|
329
|
+
maxValue: date.calendar.getMonthsInYear(date)
|
|
330
|
+
};
|
|
331
|
+
case 'day':
|
|
332
|
+
return {
|
|
333
|
+
value: date.day,
|
|
334
|
+
minValue: (0, $iqS8N$internationalizeddate.getMinimumDayInMonth)(date),
|
|
335
|
+
maxValue: date.calendar.getDaysInMonth(date)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if ('hour' in date) switch(type){
|
|
339
|
+
case 'dayPeriod':
|
|
340
|
+
return {
|
|
341
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
342
|
+
minValue: 0,
|
|
343
|
+
maxValue: 12
|
|
344
|
+
};
|
|
345
|
+
case 'hour':
|
|
346
|
+
if (options.hour12) {
|
|
347
|
+
let isPM = date.hour >= 12;
|
|
348
|
+
return {
|
|
349
|
+
value: date.hour,
|
|
350
|
+
minValue: isPM ? 12 : 0,
|
|
351
|
+
maxValue: isPM ? 23 : 11
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
value: date.hour,
|
|
356
|
+
minValue: 0,
|
|
357
|
+
maxValue: 23
|
|
358
|
+
};
|
|
359
|
+
case 'minute':
|
|
360
|
+
return {
|
|
361
|
+
value: date.minute,
|
|
362
|
+
minValue: 0,
|
|
363
|
+
maxValue: 59
|
|
364
|
+
};
|
|
365
|
+
case 'second':
|
|
366
|
+
return {
|
|
367
|
+
value: date.second,
|
|
368
|
+
minValue: 0,
|
|
369
|
+
maxValue: 59
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return {};
|
|
373
|
+
}
|
|
374
|
+
function $596a1f0f523d6752$var$addSegment(value, part, amount, options) {
|
|
375
|
+
switch(part){
|
|
376
|
+
case 'era':
|
|
377
|
+
case 'year':
|
|
378
|
+
case 'month':
|
|
379
|
+
case 'day':
|
|
380
|
+
return value.cycle(part, amount, {
|
|
381
|
+
round: part === 'year'
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if ('hour' in value) switch(part){
|
|
385
|
+
case 'dayPeriod':
|
|
386
|
+
{
|
|
387
|
+
let hours = value.hour;
|
|
388
|
+
let isPM = hours >= 12;
|
|
389
|
+
return value.set({
|
|
390
|
+
hour: isPM ? hours - 12 : hours + 12
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
case 'hour':
|
|
394
|
+
case 'minute':
|
|
395
|
+
case 'second':
|
|
396
|
+
return value.cycle(part, amount, {
|
|
397
|
+
round: part !== 'hour',
|
|
398
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
|
|
403
|
+
switch(part){
|
|
404
|
+
case 'day':
|
|
405
|
+
case 'month':
|
|
406
|
+
case 'year':
|
|
407
|
+
case 'era':
|
|
408
|
+
return value.set({
|
|
409
|
+
[part]: segmentValue
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
if ('hour' in value) switch(part){
|
|
413
|
+
case 'dayPeriod':
|
|
414
|
+
{
|
|
415
|
+
let hours = value.hour;
|
|
416
|
+
let wasPM = hours >= 12;
|
|
417
|
+
let isPM = segmentValue >= 12;
|
|
418
|
+
if (isPM === wasPM) return value;
|
|
419
|
+
return value.set({
|
|
420
|
+
hour: wasPM ? hours - 12 : hours + 12
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
case 'hour':
|
|
424
|
+
// In 12 hour time, ensure that AM/PM does not change
|
|
425
|
+
if (options.hour12) {
|
|
426
|
+
let hours = value.hour;
|
|
427
|
+
let wasPM = hours >= 12;
|
|
428
|
+
if (!wasPM && segmentValue === 12) segmentValue = 0;
|
|
429
|
+
if (wasPM && segmentValue < 12) segmentValue += 12;
|
|
430
|
+
}
|
|
431
|
+
// fallthrough
|
|
432
|
+
case 'minute':
|
|
433
|
+
case 'second':
|
|
434
|
+
return value.set({
|
|
435
|
+
[part]: segmentValue
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
//# sourceMappingURL=useDateFieldState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAwFD,MAAM,0CAAoB;IACxB,MAAM;IACN,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AQ,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.main.js.map"}
|