@react-stately/datepicker 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +1214 -0
- package/dist/main.js +503 -459
- package/dist/main.js.map +1 -1
- package/dist/module.js +503 -459
- package/dist/module.js.map +1 -1
- package/package.json +14 -9
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,1214 @@
|
|
|
1
|
+
import {toCalendarDate as $7UzoM$toCalendarDate, toCalendarDateTime as $7UzoM$toCalendarDateTime, DateFormatter as $7UzoM$DateFormatter, Time as $7UzoM$Time, toCalendar as $7UzoM$toCalendar, now as $7UzoM$now, GregorianCalendar as $7UzoM$GregorianCalendar, getMinimumMonthInYear as $7UzoM$getMinimumMonthInYear, getMinimumDayInMonth as $7UzoM$getMinimumDayInMonth, toTime as $7UzoM$toTime, today as $7UzoM$today, getLocalTimeZone as $7UzoM$getLocalTimeZone} from "@internationalized/date";
|
|
2
|
+
import {useOverlayTriggerState as $7UzoM$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
|
+
import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
|
|
4
|
+
import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
|
|
5
|
+
import {LocalizedStringDictionary as $7UzoM$LocalizedStringDictionary} from "@internationalized/string";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/ /*
|
|
18
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
/*
|
|
29
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
30
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
32
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
35
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
36
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
37
|
+
* governing permissions and limitations under the License.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
function $35a22f14a1f04b11$export$eac50920cf2fd59a(value, minValue, maxValue) {
|
|
41
|
+
return value != null && (minValue != null && value.compare(minValue) < 0 || maxValue != null && value.compare(maxValue) > 0);
|
|
42
|
+
}
|
|
43
|
+
const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
|
|
44
|
+
year: "numeric",
|
|
45
|
+
month: "numeric",
|
|
46
|
+
day: "numeric",
|
|
47
|
+
hour: "numeric",
|
|
48
|
+
minute: "2-digit",
|
|
49
|
+
second: "2-digit"
|
|
50
|
+
};
|
|
51
|
+
function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
52
|
+
fieldOptions = {
|
|
53
|
+
...$35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS,
|
|
54
|
+
...fieldOptions
|
|
55
|
+
};
|
|
56
|
+
let granularity = options.granularity || "minute";
|
|
57
|
+
let keys = Object.keys(fieldOptions);
|
|
58
|
+
var _options_maxGranularity;
|
|
59
|
+
let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
|
|
60
|
+
if (startIdx < 0) startIdx = 0;
|
|
61
|
+
let endIdx = keys.indexOf(granularity);
|
|
62
|
+
if (endIdx < 0) endIdx = 2;
|
|
63
|
+
if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
|
|
64
|
+
let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
|
|
65
|
+
opts[key] = fieldOptions[key];
|
|
66
|
+
return opts;
|
|
67
|
+
}, {});
|
|
68
|
+
if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
|
|
69
|
+
opts.timeZone = options.timeZone || "UTC";
|
|
70
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
71
|
+
if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
|
|
72
|
+
if (options.showEra && startIdx === 0) opts.era = "short";
|
|
73
|
+
return opts;
|
|
74
|
+
}
|
|
75
|
+
function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
|
|
76
|
+
if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
|
|
77
|
+
return new (0, $7UzoM$Time)();
|
|
78
|
+
}
|
|
79
|
+
function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
|
|
80
|
+
if (value === null) return null;
|
|
81
|
+
if (!value) return undefined;
|
|
82
|
+
return (0, $7UzoM$toCalendar)(value, calendar);
|
|
83
|
+
}
|
|
84
|
+
function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
|
|
85
|
+
if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
|
|
86
|
+
let date = (0, $7UzoM$toCalendar)((0, $7UzoM$now)(timeZone).set({
|
|
87
|
+
hour: 0,
|
|
88
|
+
minute: 0,
|
|
89
|
+
second: 0,
|
|
90
|
+
millisecond: 0
|
|
91
|
+
}), calendar);
|
|
92
|
+
if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $7UzoM$toCalendarDate)(date);
|
|
93
|
+
if (!timeZone) return (0, $7UzoM$toCalendarDateTime)(date);
|
|
94
|
+
return date;
|
|
95
|
+
}
|
|
96
|
+
function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
97
|
+
// Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
|
|
98
|
+
let lastValue = (0, $7UzoM$useRef)(v);
|
|
99
|
+
if (v) lastValue.current = v;
|
|
100
|
+
v = lastValue.current;
|
|
101
|
+
let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
|
|
102
|
+
granularity = granularity || (v && "minute" in v ? "minute" : "day");
|
|
103
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
104
|
+
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
105
|
+
return [
|
|
106
|
+
granularity,
|
|
107
|
+
defaultTimeZone
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
117
|
+
var _props_isDateUnavailable;
|
|
118
|
+
let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
|
|
119
|
+
let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
120
|
+
let v = value || props.placeholderValue;
|
|
121
|
+
let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
122
|
+
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
|
|
123
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
124
|
+
var _props_shouldCloseOnSelect;
|
|
125
|
+
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
126
|
+
let [selectedDate, setSelectedDate] = (0, $7UzoM$useState)(null);
|
|
127
|
+
let [selectedTime, setSelectedTime] = (0, $7UzoM$useState)(null);
|
|
128
|
+
if (value) {
|
|
129
|
+
selectedDate = value;
|
|
130
|
+
if ("hour" in value) selectedTime = value;
|
|
131
|
+
}
|
|
132
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
133
|
+
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
134
|
+
let commitValue = (date, time)=>{
|
|
135
|
+
setValue("timeZone" in time ? time.set((0, $7UzoM$toCalendarDate)(date)) : (0, $7UzoM$toCalendarDateTime)(date, time));
|
|
136
|
+
};
|
|
137
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
138
|
+
let selectDate = (newValue)=>{
|
|
139
|
+
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
140
|
+
if (hasTime) {
|
|
141
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
142
|
+
else setSelectedDate(newValue);
|
|
143
|
+
} else setValue(newValue);
|
|
144
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
145
|
+
};
|
|
146
|
+
let selectTime = (newValue)=>{
|
|
147
|
+
if (selectedDate) commitValue(selectedDate, newValue);
|
|
148
|
+
else setSelectedTime(newValue);
|
|
149
|
+
};
|
|
150
|
+
let validationState = props.validationState || ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value, props.minValue, props.maxValue) ? "invalid" : null) || (value && ((_props_isDateUnavailable = props.isDateUnavailable) === null || _props_isDateUnavailable === void 0 ? void 0 : _props_isDateUnavailable.call(props, value)) ? "invalid" : null);
|
|
151
|
+
return {
|
|
152
|
+
value: value,
|
|
153
|
+
setValue: setValue,
|
|
154
|
+
dateValue: selectedDate,
|
|
155
|
+
timeValue: selectedTime,
|
|
156
|
+
setDateValue: selectDate,
|
|
157
|
+
setTimeValue: selectTime,
|
|
158
|
+
granularity: granularity,
|
|
159
|
+
hasTime: hasTime,
|
|
160
|
+
...overlayState,
|
|
161
|
+
setOpen (isOpen) {
|
|
162
|
+
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
163
|
+
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
164
|
+
// the user opens the popover again.
|
|
165
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
166
|
+
overlayState.setOpen(isOpen);
|
|
167
|
+
},
|
|
168
|
+
validationState: validationState,
|
|
169
|
+
formatValue (locale, fieldOptions) {
|
|
170
|
+
if (!dateValue) return "";
|
|
171
|
+
let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
|
|
172
|
+
granularity: granularity,
|
|
173
|
+
timeZone: defaultTimeZone,
|
|
174
|
+
hideTimeZone: props.hideTimeZone,
|
|
175
|
+
hourCycle: props.hourCycle,
|
|
176
|
+
showEra: value.calendar.identifier === "gregory" && value.era === "BC"
|
|
177
|
+
});
|
|
178
|
+
let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
|
|
179
|
+
return formatter.format(dateValue);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
/*
|
|
186
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
187
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
188
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
189
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
190
|
+
*
|
|
191
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
192
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
193
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
194
|
+
* governing permissions and limitations under the License.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
199
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
200
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
201
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
202
|
+
*
|
|
203
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
204
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
205
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
206
|
+
* governing permissions and limitations under the License.
|
|
207
|
+
*/
|
|
208
|
+
// These placeholders are based on the strings used by the <input type="date">
|
|
209
|
+
// implementations in Chrome and Firefox. Additional languages are supported
|
|
210
|
+
// here than React Spectrum's typical translations.
|
|
211
|
+
const $3e3ed55ab2966714$var$placeholders = new (0, $7UzoM$LocalizedStringDictionary)({
|
|
212
|
+
ach: {
|
|
213
|
+
year: "mwaka",
|
|
214
|
+
month: "dwe",
|
|
215
|
+
day: "nino"
|
|
216
|
+
},
|
|
217
|
+
af: {
|
|
218
|
+
year: "jjjj",
|
|
219
|
+
month: "mm",
|
|
220
|
+
day: "dd"
|
|
221
|
+
},
|
|
222
|
+
am: {
|
|
223
|
+
year: "ዓዓዓዓ",
|
|
224
|
+
month: "ሚሜ",
|
|
225
|
+
day: "ቀቀ"
|
|
226
|
+
},
|
|
227
|
+
an: {
|
|
228
|
+
year: "aaaa",
|
|
229
|
+
month: "mm",
|
|
230
|
+
day: "dd"
|
|
231
|
+
},
|
|
232
|
+
ar: {
|
|
233
|
+
year: "سنة",
|
|
234
|
+
month: "شهر",
|
|
235
|
+
day: "يوم"
|
|
236
|
+
},
|
|
237
|
+
ast: {
|
|
238
|
+
year: "aaaa",
|
|
239
|
+
month: "mm",
|
|
240
|
+
day: "dd"
|
|
241
|
+
},
|
|
242
|
+
az: {
|
|
243
|
+
year: "iiii",
|
|
244
|
+
month: "aa",
|
|
245
|
+
day: "gg"
|
|
246
|
+
},
|
|
247
|
+
be: {
|
|
248
|
+
year: "гггг",
|
|
249
|
+
month: "мм",
|
|
250
|
+
day: "дд"
|
|
251
|
+
},
|
|
252
|
+
bg: {
|
|
253
|
+
year: "гггг",
|
|
254
|
+
month: "мм",
|
|
255
|
+
day: "дд"
|
|
256
|
+
},
|
|
257
|
+
bn: {
|
|
258
|
+
year: "yyyy",
|
|
259
|
+
month: "মিমি",
|
|
260
|
+
day: "dd"
|
|
261
|
+
},
|
|
262
|
+
br: {
|
|
263
|
+
year: "bbbb",
|
|
264
|
+
month: "mm",
|
|
265
|
+
day: "dd"
|
|
266
|
+
},
|
|
267
|
+
bs: {
|
|
268
|
+
year: "gggg",
|
|
269
|
+
month: "mm",
|
|
270
|
+
day: "dd"
|
|
271
|
+
},
|
|
272
|
+
ca: {
|
|
273
|
+
year: "aaaa",
|
|
274
|
+
month: "mm",
|
|
275
|
+
day: "dd"
|
|
276
|
+
},
|
|
277
|
+
cak: {
|
|
278
|
+
year: "jjjj",
|
|
279
|
+
month: "ii",
|
|
280
|
+
day: "q'q'"
|
|
281
|
+
},
|
|
282
|
+
ckb: {
|
|
283
|
+
year: "ساڵ",
|
|
284
|
+
month: "مانگ",
|
|
285
|
+
day: "ڕۆژ"
|
|
286
|
+
},
|
|
287
|
+
cs: {
|
|
288
|
+
year: "rrrr",
|
|
289
|
+
month: "mm",
|
|
290
|
+
day: "dd"
|
|
291
|
+
},
|
|
292
|
+
cy: {
|
|
293
|
+
year: "bbbb",
|
|
294
|
+
month: "mm",
|
|
295
|
+
day: "dd"
|
|
296
|
+
},
|
|
297
|
+
da: {
|
|
298
|
+
year: "\xe5\xe5\xe5\xe5",
|
|
299
|
+
month: "mm",
|
|
300
|
+
day: "dd"
|
|
301
|
+
},
|
|
302
|
+
de: {
|
|
303
|
+
year: "jjjj",
|
|
304
|
+
month: "mm",
|
|
305
|
+
day: "tt"
|
|
306
|
+
},
|
|
307
|
+
dsb: {
|
|
308
|
+
year: "llll",
|
|
309
|
+
month: "mm",
|
|
310
|
+
day: "źź"
|
|
311
|
+
},
|
|
312
|
+
el: {
|
|
313
|
+
year: "εεεε",
|
|
314
|
+
month: "μμ",
|
|
315
|
+
day: "ηη"
|
|
316
|
+
},
|
|
317
|
+
en: {
|
|
318
|
+
year: "yyyy",
|
|
319
|
+
month: "mm",
|
|
320
|
+
day: "dd"
|
|
321
|
+
},
|
|
322
|
+
eo: {
|
|
323
|
+
year: "jjjj",
|
|
324
|
+
month: "mm",
|
|
325
|
+
day: "tt"
|
|
326
|
+
},
|
|
327
|
+
es: {
|
|
328
|
+
year: "aaaa",
|
|
329
|
+
month: "mm",
|
|
330
|
+
day: "dd"
|
|
331
|
+
},
|
|
332
|
+
et: {
|
|
333
|
+
year: "aaaa",
|
|
334
|
+
month: "kk",
|
|
335
|
+
day: "pp"
|
|
336
|
+
},
|
|
337
|
+
eu: {
|
|
338
|
+
year: "uuuu",
|
|
339
|
+
month: "hh",
|
|
340
|
+
day: "ee"
|
|
341
|
+
},
|
|
342
|
+
fa: {
|
|
343
|
+
year: "سال",
|
|
344
|
+
month: "ماه",
|
|
345
|
+
day: "روز"
|
|
346
|
+
},
|
|
347
|
+
ff: {
|
|
348
|
+
year: "hhhh",
|
|
349
|
+
month: "ll",
|
|
350
|
+
day: "\xf1\xf1"
|
|
351
|
+
},
|
|
352
|
+
fi: {
|
|
353
|
+
year: "vvvv",
|
|
354
|
+
month: "kk",
|
|
355
|
+
day: "pp"
|
|
356
|
+
},
|
|
357
|
+
fr: {
|
|
358
|
+
year: "aaaa",
|
|
359
|
+
month: "mm",
|
|
360
|
+
day: "jj"
|
|
361
|
+
},
|
|
362
|
+
fy: {
|
|
363
|
+
year: "jjjj",
|
|
364
|
+
month: "mm",
|
|
365
|
+
day: "dd"
|
|
366
|
+
},
|
|
367
|
+
ga: {
|
|
368
|
+
year: "bbbb",
|
|
369
|
+
month: "mm",
|
|
370
|
+
day: "ll"
|
|
371
|
+
},
|
|
372
|
+
gd: {
|
|
373
|
+
year: "bbbb",
|
|
374
|
+
month: "mm",
|
|
375
|
+
day: "ll"
|
|
376
|
+
},
|
|
377
|
+
gl: {
|
|
378
|
+
year: "aaaa",
|
|
379
|
+
month: "mm",
|
|
380
|
+
day: "dd"
|
|
381
|
+
},
|
|
382
|
+
he: {
|
|
383
|
+
year: "שנה",
|
|
384
|
+
month: "חודש",
|
|
385
|
+
day: "יום"
|
|
386
|
+
},
|
|
387
|
+
hr: {
|
|
388
|
+
year: "gggg",
|
|
389
|
+
month: "mm",
|
|
390
|
+
day: "dd"
|
|
391
|
+
},
|
|
392
|
+
hsb: {
|
|
393
|
+
year: "llll",
|
|
394
|
+
month: "mm",
|
|
395
|
+
day: "dd"
|
|
396
|
+
},
|
|
397
|
+
hu: {
|
|
398
|
+
year: "\xe9\xe9\xe9\xe9",
|
|
399
|
+
month: "hh",
|
|
400
|
+
day: "nn"
|
|
401
|
+
},
|
|
402
|
+
ia: {
|
|
403
|
+
year: "aaaa",
|
|
404
|
+
month: "mm",
|
|
405
|
+
day: "dd"
|
|
406
|
+
},
|
|
407
|
+
id: {
|
|
408
|
+
year: "tttt",
|
|
409
|
+
month: "bb",
|
|
410
|
+
day: "hh"
|
|
411
|
+
},
|
|
412
|
+
it: {
|
|
413
|
+
year: "aaaa",
|
|
414
|
+
month: "mm",
|
|
415
|
+
day: "gg"
|
|
416
|
+
},
|
|
417
|
+
ja: {
|
|
418
|
+
year: " 年 ",
|
|
419
|
+
month: "月",
|
|
420
|
+
day: "日"
|
|
421
|
+
},
|
|
422
|
+
ka: {
|
|
423
|
+
year: "წწწწ",
|
|
424
|
+
month: "თთ",
|
|
425
|
+
day: "რრ"
|
|
426
|
+
},
|
|
427
|
+
kk: {
|
|
428
|
+
year: "жжжж",
|
|
429
|
+
month: "аа",
|
|
430
|
+
day: "кк"
|
|
431
|
+
},
|
|
432
|
+
kn: {
|
|
433
|
+
year: "ವವವವ",
|
|
434
|
+
month: "ಮಿಮೀ",
|
|
435
|
+
day: "ದಿದಿ"
|
|
436
|
+
},
|
|
437
|
+
ko: {
|
|
438
|
+
year: "연도",
|
|
439
|
+
month: "월",
|
|
440
|
+
day: "일"
|
|
441
|
+
},
|
|
442
|
+
lb: {
|
|
443
|
+
year: "jjjj",
|
|
444
|
+
month: "mm",
|
|
445
|
+
day: "dd"
|
|
446
|
+
},
|
|
447
|
+
lo: {
|
|
448
|
+
year: "ປປປປ",
|
|
449
|
+
month: "ດດ",
|
|
450
|
+
day: "ວວ"
|
|
451
|
+
},
|
|
452
|
+
lt: {
|
|
453
|
+
year: "mmmm",
|
|
454
|
+
month: "mm",
|
|
455
|
+
day: "dd"
|
|
456
|
+
},
|
|
457
|
+
lv: {
|
|
458
|
+
year: "gggg",
|
|
459
|
+
month: "mm",
|
|
460
|
+
day: "dd"
|
|
461
|
+
},
|
|
462
|
+
meh: {
|
|
463
|
+
year: "aaaa",
|
|
464
|
+
month: "mm",
|
|
465
|
+
day: "dd"
|
|
466
|
+
},
|
|
467
|
+
ml: {
|
|
468
|
+
year: "വർഷം",
|
|
469
|
+
month: "മാസം",
|
|
470
|
+
day: "തീയതി"
|
|
471
|
+
},
|
|
472
|
+
ms: {
|
|
473
|
+
year: "tttt",
|
|
474
|
+
month: "mm",
|
|
475
|
+
day: "hh"
|
|
476
|
+
},
|
|
477
|
+
nl: {
|
|
478
|
+
year: "jjjj",
|
|
479
|
+
month: "mm",
|
|
480
|
+
day: "dd"
|
|
481
|
+
},
|
|
482
|
+
nn: {
|
|
483
|
+
year: "\xe5\xe5\xe5\xe5",
|
|
484
|
+
month: "mm",
|
|
485
|
+
day: "dd"
|
|
486
|
+
},
|
|
487
|
+
no: {
|
|
488
|
+
year: "\xe5\xe5\xe5\xe5",
|
|
489
|
+
month: "mm",
|
|
490
|
+
day: "dd"
|
|
491
|
+
},
|
|
492
|
+
oc: {
|
|
493
|
+
year: "aaaa",
|
|
494
|
+
month: "mm",
|
|
495
|
+
day: "jj"
|
|
496
|
+
},
|
|
497
|
+
pl: {
|
|
498
|
+
year: "rrrr",
|
|
499
|
+
month: "mm",
|
|
500
|
+
day: "dd"
|
|
501
|
+
},
|
|
502
|
+
pt: {
|
|
503
|
+
year: "aaaa",
|
|
504
|
+
month: "mm",
|
|
505
|
+
day: "dd"
|
|
506
|
+
},
|
|
507
|
+
rm: {
|
|
508
|
+
year: "oooo",
|
|
509
|
+
month: "mm",
|
|
510
|
+
day: "dd"
|
|
511
|
+
},
|
|
512
|
+
ro: {
|
|
513
|
+
year: "aaaa",
|
|
514
|
+
month: "ll",
|
|
515
|
+
day: "zz"
|
|
516
|
+
},
|
|
517
|
+
ru: {
|
|
518
|
+
year: "гггг",
|
|
519
|
+
month: "мм",
|
|
520
|
+
day: "дд"
|
|
521
|
+
},
|
|
522
|
+
sc: {
|
|
523
|
+
year: "aaaa",
|
|
524
|
+
month: "mm",
|
|
525
|
+
day: "dd"
|
|
526
|
+
},
|
|
527
|
+
scn: {
|
|
528
|
+
year: "aaaa",
|
|
529
|
+
month: "mm",
|
|
530
|
+
day: "jj"
|
|
531
|
+
},
|
|
532
|
+
sk: {
|
|
533
|
+
year: "rrrr",
|
|
534
|
+
month: "mm",
|
|
535
|
+
day: "dd"
|
|
536
|
+
},
|
|
537
|
+
sl: {
|
|
538
|
+
year: "llll",
|
|
539
|
+
month: "mm",
|
|
540
|
+
day: "dd"
|
|
541
|
+
},
|
|
542
|
+
sr: {
|
|
543
|
+
year: "гггг",
|
|
544
|
+
month: "мм",
|
|
545
|
+
day: "дд"
|
|
546
|
+
},
|
|
547
|
+
sv: {
|
|
548
|
+
year: "\xe5\xe5\xe5\xe5",
|
|
549
|
+
month: "mm",
|
|
550
|
+
day: "dd"
|
|
551
|
+
},
|
|
552
|
+
szl: {
|
|
553
|
+
year: "rrrr",
|
|
554
|
+
month: "mm",
|
|
555
|
+
day: "dd"
|
|
556
|
+
},
|
|
557
|
+
tg: {
|
|
558
|
+
year: "сссс",
|
|
559
|
+
month: "мм",
|
|
560
|
+
day: "рр"
|
|
561
|
+
},
|
|
562
|
+
th: {
|
|
563
|
+
year: "ปปปป",
|
|
564
|
+
month: "ดด",
|
|
565
|
+
day: "วว"
|
|
566
|
+
},
|
|
567
|
+
tr: {
|
|
568
|
+
year: "yyyy",
|
|
569
|
+
month: "aa",
|
|
570
|
+
day: "gg"
|
|
571
|
+
},
|
|
572
|
+
uk: {
|
|
573
|
+
year: "рррр",
|
|
574
|
+
month: "мм",
|
|
575
|
+
day: "дд"
|
|
576
|
+
},
|
|
577
|
+
"zh-CN": {
|
|
578
|
+
year: "年",
|
|
579
|
+
month: "月",
|
|
580
|
+
day: "日"
|
|
581
|
+
},
|
|
582
|
+
"zh-TW": {
|
|
583
|
+
year: "年",
|
|
584
|
+
month: "月",
|
|
585
|
+
day: "日"
|
|
586
|
+
}
|
|
587
|
+
}, "en");
|
|
588
|
+
function $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(field, value, locale) {
|
|
589
|
+
// Use the actual placeholder value for the era and day period fields.
|
|
590
|
+
if (field === "era" || field === "dayPeriod") return value;
|
|
591
|
+
if (field === "year" || field === "month" || field === "day") return $3e3ed55ab2966714$var$placeholders.getStringForLocale(field, locale);
|
|
592
|
+
// For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
|
|
593
|
+
return "––";
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
600
|
+
year: true,
|
|
601
|
+
month: true,
|
|
602
|
+
day: true,
|
|
603
|
+
hour: true,
|
|
604
|
+
minute: true,
|
|
605
|
+
second: true,
|
|
606
|
+
dayPeriod: true,
|
|
607
|
+
era: true
|
|
608
|
+
};
|
|
609
|
+
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
610
|
+
year: 5,
|
|
611
|
+
month: 2,
|
|
612
|
+
day: 7,
|
|
613
|
+
hour: 2,
|
|
614
|
+
minute: 15,
|
|
615
|
+
second: 15
|
|
616
|
+
};
|
|
617
|
+
// Node seems to convert everything to lowercase...
|
|
618
|
+
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
619
|
+
dayperiod: "dayPeriod"
|
|
620
|
+
};
|
|
621
|
+
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
622
|
+
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
623
|
+
let v = props.value || props.defaultValue || props.placeholderValue;
|
|
624
|
+
let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
625
|
+
let timeZone = defaultTimeZone || "UTC";
|
|
626
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
627
|
+
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
628
|
+
let defaultFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale), [
|
|
629
|
+
locale
|
|
630
|
+
]);
|
|
631
|
+
let calendar = (0, $7UzoM$useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
|
|
632
|
+
createCalendar,
|
|
633
|
+
defaultFormatter
|
|
634
|
+
]);
|
|
635
|
+
let [value, setDate] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
|
|
636
|
+
let calendarValue = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$61a490a80c552550)(value, calendar), [
|
|
637
|
+
value,
|
|
638
|
+
calendar
|
|
639
|
+
]);
|
|
640
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
641
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
642
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
643
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
644
|
+
let [placeholderDate, setPlaceholderDate] = (0, $7UzoM$useState)(()=>(0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
645
|
+
let val = calendarValue || placeholderDate;
|
|
646
|
+
let showEra = calendar.identifier === "gregory" && val.era === "BC";
|
|
647
|
+
var _props_maxGranularity;
|
|
648
|
+
let formatOpts = (0, $7UzoM$useMemo)(()=>({
|
|
649
|
+
granularity: granularity,
|
|
650
|
+
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
|
|
651
|
+
timeZone: defaultTimeZone,
|
|
652
|
+
hideTimeZone: hideTimeZone,
|
|
653
|
+
hourCycle: props.hourCycle,
|
|
654
|
+
showEra: showEra
|
|
655
|
+
}), [
|
|
656
|
+
props.maxGranularity,
|
|
657
|
+
granularity,
|
|
658
|
+
props.hourCycle,
|
|
659
|
+
defaultTimeZone,
|
|
660
|
+
hideTimeZone,
|
|
661
|
+
showEra
|
|
662
|
+
]);
|
|
663
|
+
let opts = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, formatOpts), [
|
|
664
|
+
formatOpts
|
|
665
|
+
]);
|
|
666
|
+
let dateFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale, opts), [
|
|
667
|
+
locale,
|
|
668
|
+
opts
|
|
669
|
+
]);
|
|
670
|
+
let resolvedOptions = (0, $7UzoM$useMemo)(()=>dateFormatter.resolvedOptions(), [
|
|
671
|
+
dateFormatter
|
|
672
|
+
]);
|
|
673
|
+
// Determine how many editable segments there are for validation purposes.
|
|
674
|
+
// The result is cached for performance.
|
|
675
|
+
let allSegments = (0, $7UzoM$useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[seg.type] = true, p), {}), [
|
|
676
|
+
dateFormatter
|
|
677
|
+
]);
|
|
678
|
+
let [validSegments, setValidSegments] = (0, $7UzoM$useState)(()=>props.value || props.defaultValue ? {
|
|
679
|
+
...allSegments
|
|
680
|
+
} : {});
|
|
681
|
+
// Reset placeholder when calendar changes
|
|
682
|
+
let lastCalendarIdentifier = (0, $7UzoM$useRef)(calendar.identifier);
|
|
683
|
+
(0, $7UzoM$useEffect)(()=>{
|
|
684
|
+
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
685
|
+
lastCalendarIdentifier.current = calendar.identifier;
|
|
686
|
+
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $7UzoM$toCalendar)(placeholder, calendar) : (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
687
|
+
}
|
|
688
|
+
}, [
|
|
689
|
+
calendar,
|
|
690
|
+
granularity,
|
|
691
|
+
validSegments,
|
|
692
|
+
defaultTimeZone,
|
|
693
|
+
props.placeholderValue
|
|
694
|
+
]);
|
|
695
|
+
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
696
|
+
if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
697
|
+
validSegments = {
|
|
698
|
+
...allSegments
|
|
699
|
+
};
|
|
700
|
+
setValidSegments(validSegments);
|
|
701
|
+
}
|
|
702
|
+
// If the value is set to null and all segments are valid, reset the placeholder.
|
|
703
|
+
if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
|
|
704
|
+
validSegments = {};
|
|
705
|
+
setValidSegments(validSegments);
|
|
706
|
+
setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
707
|
+
}
|
|
708
|
+
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
709
|
+
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
710
|
+
let setValue = (newValue)=>{
|
|
711
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
712
|
+
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
713
|
+
// The display calendar should not have any effect on the emitted value.
|
|
714
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
715
|
+
newValue = (0, $7UzoM$toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $7UzoM$GregorianCalendar)());
|
|
716
|
+
setDate(newValue);
|
|
717
|
+
} else setPlaceholderDate(newValue);
|
|
718
|
+
};
|
|
719
|
+
let dateValue = (0, $7UzoM$useMemo)(()=>displayValue.toDate(timeZone), [
|
|
720
|
+
displayValue,
|
|
721
|
+
timeZone
|
|
722
|
+
]);
|
|
723
|
+
let segments = (0, $7UzoM$useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
724
|
+
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
725
|
+
if (segment.type === "era" && calendar.getEras().length === 1) isEditable = false;
|
|
726
|
+
let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
|
|
727
|
+
let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? (0, $3e3ed55ab2966714$export$d3f5c5e0a5023fa0)(segment.type, segment.value, locale) : null;
|
|
728
|
+
return {
|
|
729
|
+
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
730
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
731
|
+
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
732
|
+
isPlaceholder: isPlaceholder,
|
|
733
|
+
placeholder: placeholder,
|
|
734
|
+
isEditable: isEditable
|
|
735
|
+
};
|
|
736
|
+
}), [
|
|
737
|
+
dateValue,
|
|
738
|
+
validSegments,
|
|
739
|
+
dateFormatter,
|
|
740
|
+
resolvedOptions,
|
|
741
|
+
displayValue,
|
|
742
|
+
calendar,
|
|
743
|
+
locale
|
|
744
|
+
]);
|
|
745
|
+
// When the era field appears, mark it valid if the year field is already valid.
|
|
746
|
+
// If the era field disappears, remove it from the valid segments.
|
|
747
|
+
if (allSegments.era && validSegments.year && !validSegments.era) {
|
|
748
|
+
validSegments.era = true;
|
|
749
|
+
setValidSegments({
|
|
750
|
+
...validSegments
|
|
751
|
+
});
|
|
752
|
+
} else if (!allSegments.era && validSegments.era) {
|
|
753
|
+
delete validSegments.era;
|
|
754
|
+
setValidSegments({
|
|
755
|
+
...validSegments
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
let markValid = (part)=>{
|
|
759
|
+
validSegments[part] = true;
|
|
760
|
+
if (part === "year" && allSegments.era) validSegments.era = true;
|
|
761
|
+
setValidSegments({
|
|
762
|
+
...validSegments
|
|
763
|
+
});
|
|
764
|
+
};
|
|
765
|
+
let adjustSegment = (type, amount)=>{
|
|
766
|
+
if (!validSegments[type]) {
|
|
767
|
+
markValid(type);
|
|
768
|
+
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) setValue(displayValue);
|
|
769
|
+
} else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
770
|
+
};
|
|
771
|
+
let validationState = props.validationState || ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(calendarValue, props.minValue, props.maxValue) ? "invalid" : null);
|
|
772
|
+
var _props_maxGranularity1;
|
|
773
|
+
return {
|
|
774
|
+
value: calendarValue,
|
|
775
|
+
dateValue: dateValue,
|
|
776
|
+
calendar: calendar,
|
|
777
|
+
setValue: setValue,
|
|
778
|
+
segments: segments,
|
|
779
|
+
dateFormatter: dateFormatter,
|
|
780
|
+
validationState: validationState,
|
|
781
|
+
granularity: granularity,
|
|
782
|
+
maxGranularity: (_props_maxGranularity1 = props.maxGranularity) !== null && _props_maxGranularity1 !== void 0 ? _props_maxGranularity1 : "year",
|
|
783
|
+
isDisabled: isDisabled,
|
|
784
|
+
isReadOnly: isReadOnly,
|
|
785
|
+
isRequired: isRequired,
|
|
786
|
+
increment (part) {
|
|
787
|
+
adjustSegment(part, 1);
|
|
788
|
+
},
|
|
789
|
+
decrement (part) {
|
|
790
|
+
adjustSegment(part, -1);
|
|
791
|
+
},
|
|
792
|
+
incrementPage (part) {
|
|
793
|
+
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
794
|
+
},
|
|
795
|
+
decrementPage (part) {
|
|
796
|
+
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
797
|
+
},
|
|
798
|
+
setSegment (part, v) {
|
|
799
|
+
markValid(part);
|
|
800
|
+
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
801
|
+
},
|
|
802
|
+
confirmPlaceholder () {
|
|
803
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
804
|
+
// Confirm the placeholder if only the day period is not filled in.
|
|
805
|
+
let validKeys = Object.keys(validSegments);
|
|
806
|
+
let allKeys = Object.keys(allSegments);
|
|
807
|
+
if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
|
|
808
|
+
validSegments = {
|
|
809
|
+
...allSegments
|
|
810
|
+
};
|
|
811
|
+
setValidSegments(validSegments);
|
|
812
|
+
setValue(displayValue.copy());
|
|
813
|
+
}
|
|
814
|
+
},
|
|
815
|
+
clearSegment (part) {
|
|
816
|
+
delete validSegments[part];
|
|
817
|
+
setValidSegments({
|
|
818
|
+
...validSegments
|
|
819
|
+
});
|
|
820
|
+
let placeholder = (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
821
|
+
let value = displayValue;
|
|
822
|
+
// Reset day period to default without changing the hour.
|
|
823
|
+
if (part === "dayPeriod" && "hour" in displayValue && "hour" in placeholder) {
|
|
824
|
+
let isPM = displayValue.hour >= 12;
|
|
825
|
+
let shouldBePM = placeholder.hour >= 12;
|
|
826
|
+
if (isPM && !shouldBePM) value = displayValue.set({
|
|
827
|
+
hour: displayValue.hour - 12
|
|
828
|
+
});
|
|
829
|
+
else if (!isPM && shouldBePM) value = displayValue.set({
|
|
830
|
+
hour: displayValue.hour + 12
|
|
831
|
+
});
|
|
832
|
+
} else if (part in displayValue) value = displayValue.set({
|
|
833
|
+
[part]: placeholder[part]
|
|
834
|
+
});
|
|
835
|
+
setDate(null);
|
|
836
|
+
setValue(value);
|
|
837
|
+
},
|
|
838
|
+
formatValue (fieldOptions) {
|
|
839
|
+
if (!calendarValue) return "";
|
|
840
|
+
let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
841
|
+
let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
|
|
842
|
+
return formatter.format(dateValue);
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
|
|
847
|
+
switch(type){
|
|
848
|
+
case "era":
|
|
849
|
+
{
|
|
850
|
+
let eras = date.calendar.getEras();
|
|
851
|
+
return {
|
|
852
|
+
value: eras.indexOf(date.era),
|
|
853
|
+
minValue: 0,
|
|
854
|
+
maxValue: eras.length - 1
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
case "year":
|
|
858
|
+
return {
|
|
859
|
+
value: date.year,
|
|
860
|
+
minValue: 1,
|
|
861
|
+
maxValue: date.calendar.getYearsInEra(date)
|
|
862
|
+
};
|
|
863
|
+
case "month":
|
|
864
|
+
return {
|
|
865
|
+
value: date.month,
|
|
866
|
+
minValue: (0, $7UzoM$getMinimumMonthInYear)(date),
|
|
867
|
+
maxValue: date.calendar.getMonthsInYear(date)
|
|
868
|
+
};
|
|
869
|
+
case "day":
|
|
870
|
+
return {
|
|
871
|
+
value: date.day,
|
|
872
|
+
minValue: (0, $7UzoM$getMinimumDayInMonth)(date),
|
|
873
|
+
maxValue: date.calendar.getDaysInMonth(date)
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
if ("hour" in date) switch(type){
|
|
877
|
+
case "dayPeriod":
|
|
878
|
+
return {
|
|
879
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
880
|
+
minValue: 0,
|
|
881
|
+
maxValue: 12
|
|
882
|
+
};
|
|
883
|
+
case "hour":
|
|
884
|
+
if (options.hour12) {
|
|
885
|
+
let isPM = date.hour >= 12;
|
|
886
|
+
return {
|
|
887
|
+
value: date.hour,
|
|
888
|
+
minValue: isPM ? 12 : 0,
|
|
889
|
+
maxValue: isPM ? 23 : 11
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
return {
|
|
893
|
+
value: date.hour,
|
|
894
|
+
minValue: 0,
|
|
895
|
+
maxValue: 23
|
|
896
|
+
};
|
|
897
|
+
case "minute":
|
|
898
|
+
return {
|
|
899
|
+
value: date.minute,
|
|
900
|
+
minValue: 0,
|
|
901
|
+
maxValue: 59
|
|
902
|
+
};
|
|
903
|
+
case "second":
|
|
904
|
+
return {
|
|
905
|
+
value: date.second,
|
|
906
|
+
minValue: 0,
|
|
907
|
+
maxValue: 59
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
return {};
|
|
911
|
+
}
|
|
912
|
+
function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
|
|
913
|
+
switch(part){
|
|
914
|
+
case "era":
|
|
915
|
+
case "year":
|
|
916
|
+
case "month":
|
|
917
|
+
case "day":
|
|
918
|
+
return value.cycle(part, amount, {
|
|
919
|
+
round: part === "year"
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
if ("hour" in value) switch(part){
|
|
923
|
+
case "dayPeriod":
|
|
924
|
+
{
|
|
925
|
+
let hours = value.hour;
|
|
926
|
+
let isPM = hours >= 12;
|
|
927
|
+
return value.set({
|
|
928
|
+
hour: isPM ? hours - 12 : hours + 12
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
case "hour":
|
|
932
|
+
case "minute":
|
|
933
|
+
case "second":
|
|
934
|
+
return value.cycle(part, amount, {
|
|
935
|
+
round: part !== "hour",
|
|
936
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
941
|
+
switch(part){
|
|
942
|
+
case "day":
|
|
943
|
+
case "month":
|
|
944
|
+
case "year":
|
|
945
|
+
case "era":
|
|
946
|
+
return value.set({
|
|
947
|
+
[part]: segmentValue
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if ("hour" in value) switch(part){
|
|
951
|
+
case "dayPeriod":
|
|
952
|
+
{
|
|
953
|
+
let hours = value.hour;
|
|
954
|
+
let wasPM = hours >= 12;
|
|
955
|
+
let isPM = segmentValue >= 12;
|
|
956
|
+
if (isPM === wasPM) return value;
|
|
957
|
+
return value.set({
|
|
958
|
+
hour: wasPM ? hours - 12 : hours + 12
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
case "hour":
|
|
962
|
+
// In 12 hour time, ensure that AM/PM does not change
|
|
963
|
+
if (options.hour12) {
|
|
964
|
+
let hours1 = value.hour;
|
|
965
|
+
let wasPM1 = hours1 >= 12;
|
|
966
|
+
if (!wasPM1 && segmentValue === 12) segmentValue = 0;
|
|
967
|
+
if (wasPM1 && segmentValue < 12) segmentValue += 12;
|
|
968
|
+
}
|
|
969
|
+
// fallthrough
|
|
970
|
+
case "minute":
|
|
971
|
+
case "second":
|
|
972
|
+
return value.set({
|
|
973
|
+
[part]: segmentValue
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
/*
|
|
980
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
981
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
982
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
983
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
984
|
+
*
|
|
985
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
986
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
987
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
988
|
+
* governing permissions and limitations under the License.
|
|
989
|
+
*/
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
995
|
+
var _props_isDateUnavailable, _props_isDateUnavailable1;
|
|
996
|
+
let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
|
|
997
|
+
let [controlledValue, setControlledValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
998
|
+
let [placeholderValue, setPlaceholderValue] = (0, $7UzoM$useState)(()=>controlledValue || {
|
|
999
|
+
start: null,
|
|
1000
|
+
end: null
|
|
1001
|
+
});
|
|
1002
|
+
// Reset the placeholder if the value prop is set to null.
|
|
1003
|
+
if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
|
|
1004
|
+
placeholderValue = {
|
|
1005
|
+
start: null,
|
|
1006
|
+
end: null
|
|
1007
|
+
};
|
|
1008
|
+
setPlaceholderValue(placeholderValue);
|
|
1009
|
+
}
|
|
1010
|
+
let value = controlledValue || placeholderValue;
|
|
1011
|
+
let setValue = (value)=>{
|
|
1012
|
+
setPlaceholderValue(value);
|
|
1013
|
+
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
1014
|
+
else setControlledValue(null);
|
|
1015
|
+
};
|
|
1016
|
+
let v = (value === null || value === void 0 ? void 0 : value.start) || (value === null || value === void 0 ? void 0 : value.end) || props.placeholderValue;
|
|
1017
|
+
let [granularity] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
1018
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
1019
|
+
var _props_shouldCloseOnSelect;
|
|
1020
|
+
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
1021
|
+
let [dateRange, setSelectedDateRange] = (0, $7UzoM$useState)(null);
|
|
1022
|
+
let [timeRange, setSelectedTimeRange] = (0, $7UzoM$useState)(null);
|
|
1023
|
+
if (value && value.start && value.end) {
|
|
1024
|
+
dateRange = value;
|
|
1025
|
+
if ("hour" in value.start) timeRange = value;
|
|
1026
|
+
}
|
|
1027
|
+
let commitValue = (dateRange, timeRange)=>{
|
|
1028
|
+
setValue({
|
|
1029
|
+
start: "timeZone" in timeRange.start ? timeRange.start.set((0, $7UzoM$toCalendarDate)(dateRange.start)) : (0, $7UzoM$toCalendarDateTime)(dateRange.start, timeRange.start),
|
|
1030
|
+
end: "timeZone" in timeRange.end ? timeRange.end.set((0, $7UzoM$toCalendarDate)(dateRange.end)) : (0, $7UzoM$toCalendarDateTime)(dateRange.end, timeRange.end)
|
|
1031
|
+
});
|
|
1032
|
+
};
|
|
1033
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
1034
|
+
let setDateRange = (range)=>{
|
|
1035
|
+
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
1036
|
+
if (hasTime) {
|
|
1037
|
+
if (shouldClose || range.start && range.end && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end)) commitValue(range, {
|
|
1038
|
+
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
|
|
1039
|
+
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
|
|
1040
|
+
});
|
|
1041
|
+
else setSelectedDateRange(range);
|
|
1042
|
+
} else if (range.start && range.end) setValue(range);
|
|
1043
|
+
else setSelectedDateRange(range);
|
|
1044
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
1045
|
+
};
|
|
1046
|
+
let setTimeRange = (range)=>{
|
|
1047
|
+
if ((dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && range.start && range.end) commitValue(dateRange, range);
|
|
1048
|
+
else setSelectedTimeRange(range);
|
|
1049
|
+
};
|
|
1050
|
+
let validationState = props.validationState || (value != null && ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value.start, props.minValue, props.maxValue) || (0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value.end, props.minValue, props.maxValue) || value.end != null && value.start != null && value.end.compare(value.start) < 0 || (value === null || value === void 0 ? void 0 : value.start) && ((_props_isDateUnavailable = props.isDateUnavailable) === null || _props_isDateUnavailable === void 0 ? void 0 : _props_isDateUnavailable.call(props, value.start)) || (value === null || value === void 0 ? void 0 : value.end) && ((_props_isDateUnavailable1 = props.isDateUnavailable) === null || _props_isDateUnavailable1 === void 0 ? void 0 : _props_isDateUnavailable1.call(props, value.end))) ? "invalid" : null);
|
|
1051
|
+
return {
|
|
1052
|
+
value: value,
|
|
1053
|
+
setValue: setValue,
|
|
1054
|
+
dateRange: dateRange,
|
|
1055
|
+
timeRange: timeRange,
|
|
1056
|
+
granularity: granularity,
|
|
1057
|
+
hasTime: hasTime,
|
|
1058
|
+
setDate (part, date) {
|
|
1059
|
+
setDateRange({
|
|
1060
|
+
...dateRange,
|
|
1061
|
+
[part]: date
|
|
1062
|
+
});
|
|
1063
|
+
},
|
|
1064
|
+
setTime (part, time) {
|
|
1065
|
+
setTimeRange({
|
|
1066
|
+
...timeRange,
|
|
1067
|
+
[part]: time
|
|
1068
|
+
});
|
|
1069
|
+
},
|
|
1070
|
+
setDateTime (part, dateTime) {
|
|
1071
|
+
setValue({
|
|
1072
|
+
...value,
|
|
1073
|
+
[part]: dateTime
|
|
1074
|
+
});
|
|
1075
|
+
},
|
|
1076
|
+
setDateRange: setDateRange,
|
|
1077
|
+
setTimeRange: setTimeRange,
|
|
1078
|
+
...overlayState,
|
|
1079
|
+
setOpen (isOpen) {
|
|
1080
|
+
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
1081
|
+
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
1082
|
+
// the user opens the popover again.
|
|
1083
|
+
if (!isOpen && !((value === null || value === void 0 ? void 0 : value.start) && (value === null || value === void 0 ? void 0 : value.end)) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && hasTime) commitValue(dateRange, {
|
|
1084
|
+
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
|
|
1085
|
+
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
|
|
1086
|
+
});
|
|
1087
|
+
overlayState.setOpen(isOpen);
|
|
1088
|
+
},
|
|
1089
|
+
validationState: validationState,
|
|
1090
|
+
formatValue (locale, fieldOptions) {
|
|
1091
|
+
if (!value || !value.start || !value.end) return null;
|
|
1092
|
+
let startTimeZone = "timeZone" in value.start ? value.start.timeZone : undefined;
|
|
1093
|
+
let startGranularity = props.granularity || (value.start && "minute" in value.start ? "minute" : "day");
|
|
1094
|
+
let endTimeZone = "timeZone" in value.end ? value.end.timeZone : undefined;
|
|
1095
|
+
let endGranularity = props.granularity || (value.end && "minute" in value.end ? "minute" : "day");
|
|
1096
|
+
let startOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
|
|
1097
|
+
granularity: startGranularity,
|
|
1098
|
+
timeZone: startTimeZone,
|
|
1099
|
+
hideTimeZone: props.hideTimeZone,
|
|
1100
|
+
hourCycle: props.hourCycle,
|
|
1101
|
+
showEra: value.start.calendar.identifier === "gregory" && value.start.era === "BC" || value.end.calendar.identifier === "gregory" && value.end.era === "BC"
|
|
1102
|
+
});
|
|
1103
|
+
let startDate = value.start.toDate(startTimeZone || "UTC");
|
|
1104
|
+
let endDate = value.end.toDate(endTimeZone || "UTC");
|
|
1105
|
+
let startFormatter = new (0, $7UzoM$DateFormatter)(locale, startOptions);
|
|
1106
|
+
let endFormatter;
|
|
1107
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {
|
|
1108
|
+
// Use formatRange, as it results in shorter output when some of the fields
|
|
1109
|
+
// are shared between the start and end dates (e.g. the same month).
|
|
1110
|
+
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
1111
|
+
try {
|
|
1112
|
+
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
1113
|
+
// Find the separator between the start and end date. This is determined
|
|
1114
|
+
// by finding the last shared literal before the end range.
|
|
1115
|
+
let separatorIndex = -1;
|
|
1116
|
+
for(let i = 0; i < parts.length; i++){
|
|
1117
|
+
let part = parts[i];
|
|
1118
|
+
if (part.source === "shared" && part.type === "literal") separatorIndex = i;
|
|
1119
|
+
else if (part.source === "endRange") break;
|
|
1120
|
+
}
|
|
1121
|
+
// Now we can combine the parts into start and end strings.
|
|
1122
|
+
let start = "";
|
|
1123
|
+
let end = "";
|
|
1124
|
+
for(let i1 = 0; i1 < parts.length; i1++){
|
|
1125
|
+
if (i1 < separatorIndex) start += parts[i1].value;
|
|
1126
|
+
else if (i1 > separatorIndex) end += parts[i1].value;
|
|
1127
|
+
}
|
|
1128
|
+
return {
|
|
1129
|
+
start: start,
|
|
1130
|
+
end: end
|
|
1131
|
+
};
|
|
1132
|
+
} catch (e) {
|
|
1133
|
+
// ignore
|
|
1134
|
+
}
|
|
1135
|
+
endFormatter = startFormatter;
|
|
1136
|
+
} else {
|
|
1137
|
+
let endOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
|
|
1138
|
+
granularity: endGranularity,
|
|
1139
|
+
timeZone: endTimeZone,
|
|
1140
|
+
hideTimeZone: props.hideTimeZone,
|
|
1141
|
+
hourCycle: props.hourCycle
|
|
1142
|
+
});
|
|
1143
|
+
endFormatter = new (0, $7UzoM$DateFormatter)(locale, endOptions);
|
|
1144
|
+
}
|
|
1145
|
+
return {
|
|
1146
|
+
start: startFormatter.format(startDate),
|
|
1147
|
+
end: endFormatter.format(endDate)
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
/*
|
|
1155
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1156
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
1157
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1158
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1159
|
+
*
|
|
1160
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1161
|
+
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1162
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1163
|
+
* governing permissions and limitations under the License.
|
|
1164
|
+
*/
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
|
|
1169
|
+
let { placeholderValue: placeholderValue = new (0, $7UzoM$Time)() , minValue: minValue , maxValue: maxValue , granularity: granularity } = props;
|
|
1170
|
+
let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
|
|
1171
|
+
let v = value || placeholderValue;
|
|
1172
|
+
let day = v && "day" in v ? v : undefined;
|
|
1173
|
+
let placeholderDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(placeholderValue), [
|
|
1174
|
+
placeholderValue
|
|
1175
|
+
]);
|
|
1176
|
+
let minDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day), [
|
|
1177
|
+
minValue,
|
|
1178
|
+
day
|
|
1179
|
+
]);
|
|
1180
|
+
let maxDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day), [
|
|
1181
|
+
maxValue,
|
|
1182
|
+
day
|
|
1183
|
+
]);
|
|
1184
|
+
let dateTime = (0, $7UzoM$useMemo)(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value), [
|
|
1185
|
+
value
|
|
1186
|
+
]);
|
|
1187
|
+
let onChange = (newValue)=>{
|
|
1188
|
+
setValue(v && "day" in v ? newValue : newValue && (0, $7UzoM$toTime)(newValue));
|
|
1189
|
+
};
|
|
1190
|
+
return (0, $3c0fc76039f1c516$export$60e84778edff6d26)({
|
|
1191
|
+
...props,
|
|
1192
|
+
value: dateTime,
|
|
1193
|
+
defaultValue: undefined,
|
|
1194
|
+
minValue: minDate,
|
|
1195
|
+
maxValue: maxDate,
|
|
1196
|
+
onChange: onChange,
|
|
1197
|
+
granularity: granularity || "minute",
|
|
1198
|
+
maxGranularity: "hour",
|
|
1199
|
+
placeholderValue: placeholderDate,
|
|
1200
|
+
// Calendar should not matter for time fields.
|
|
1201
|
+
createCalendar: ()=>new (0, $7UzoM$GregorianCalendar)()
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
function $eff5d8ee529ac4bb$var$convertValue(value, date = (0, $7UzoM$today)((0, $7UzoM$getLocalTimeZone)())) {
|
|
1205
|
+
if (!value) return null;
|
|
1206
|
+
if ("day" in value) return value;
|
|
1207
|
+
return (0, $7UzoM$toCalendarDateTime)(date, value);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
|
|
1214
|
+
//# sourceMappingURL=module.js.map
|