@react-stately/datepicker 3.16.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +5 -5
- package/dist/main.js +8 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -5
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +9 -0
- package/package.json +17 -20
- package/src/index.ts +9 -9
- package/dist/IncompleteDate.main.js +0 -335
- package/dist/IncompleteDate.main.js.map +0 -1
- package/dist/IncompleteDate.mjs +0 -330
- package/dist/IncompleteDate.module.js +0 -330
- package/dist/IncompleteDate.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -9
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -11
- package/dist/ar-AE.module.js +0 -11
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -9
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -11
- package/dist/bg-BG.module.js +0 -11
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -9
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -11
- package/dist/cs-CZ.module.js +0 -11
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -9
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -11
- package/dist/da-DK.module.js +0 -11
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -9
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -11
- package/dist/de-DE.module.js +0 -11
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -9
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -11
- package/dist/el-GR.module.js +0 -11
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -9
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -11
- package/dist/en-US.module.js +0 -11
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -9
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -11
- package/dist/es-ES.module.js +0 -11
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -9
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -11
- package/dist/et-EE.module.js +0 -11
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -9
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -11
- package/dist/fi-FI.module.js +0 -11
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -9
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -11
- package/dist/fr-FR.module.js +0 -11
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -9
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -11
- package/dist/he-IL.module.js +0 -11
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -9
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -11
- package/dist/hr-HR.module.js +0 -11
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -9
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -11
- package/dist/hu-HU.module.js +0 -11
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -9
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -11
- package/dist/it-IT.module.js +0 -11
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -9
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -11
- package/dist/ja-JP.module.js +0 -11
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -9
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -11
- package/dist/ko-KR.module.js +0 -11
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -9
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -11
- package/dist/lt-LT.module.js +0 -11
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -9
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -11
- package/dist/lv-LV.module.js +0 -11
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -9
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -11
- package/dist/nb-NO.module.js +0 -11
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -9
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -11
- package/dist/nl-NL.module.js +0 -11
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -9
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -11
- package/dist/pl-PL.module.js +0 -11
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/placeholders.main.js +0 -414
- package/dist/placeholders.main.js.map +0 -1
- package/dist/placeholders.mjs +0 -409
- package/dist/placeholders.module.js +0 -409
- package/dist/placeholders.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -9
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -11
- package/dist/pt-BR.module.js +0 -11
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -9
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -11
- package/dist/pt-PT.module.js +0 -11
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -9
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -11
- package/dist/ro-RO.module.js +0 -11
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -9
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -11
- package/dist/ru-RU.module.js +0 -11
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -9
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -11
- package/dist/sk-SK.module.js +0 -11
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -9
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -11
- package/dist/sl-SI.module.js +0 -11
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -9
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -11
- package/dist/sr-SP.module.js +0 -11
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -9
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -11
- package/dist/sv-SE.module.js +0 -11
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -9
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -11
- package/dist/tr-TR.module.js +0 -11
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -253
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -9
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -11
- package/dist/uk-UA.module.js +0 -11
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useDateFieldState.main.js +0 -377
- package/dist/useDateFieldState.main.js.map +0 -1
- package/dist/useDateFieldState.mjs +0 -372
- package/dist/useDateFieldState.module.js +0 -372
- package/dist/useDateFieldState.module.js.map +0 -1
- package/dist/useDatePickerState.main.js +0 -141
- package/dist/useDatePickerState.main.js.map +0 -1
- package/dist/useDatePickerState.mjs +0 -136
- package/dist/useDatePickerState.module.js +0 -136
- package/dist/useDatePickerState.module.js.map +0 -1
- package/dist/useDateRangePickerState.main.js +0 -268
- package/dist/useDateRangePickerState.main.js.map +0 -1
- package/dist/useDateRangePickerState.mjs +0 -263
- package/dist/useDateRangePickerState.module.js +0 -263
- package/dist/useDateRangePickerState.module.js.map +0 -1
- package/dist/useTimeFieldState.main.js +0 -89
- package/dist/useTimeFieldState.main.js.map +0 -1
- package/dist/useTimeFieldState.mjs +0 -84
- package/dist/useTimeFieldState.module.js +0 -84
- package/dist/useTimeFieldState.module.js.map +0 -1
- package/dist/utils.main.js +0 -200
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -189
- package/dist/utils.module.js +0 -189
- package/dist/utils.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -9
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -11
- package/dist/zh-CN.module.js +0 -11
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -9
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -11
- package/dist/zh-TW.module.js +0 -11
- package/dist/zh-TW.module.js.map +0 -1
- package/src/IncompleteDate.ts +0 -392
- package/src/placeholders.ts +0 -109
- package/src/useDateFieldState.ts +0 -478
- package/src/useDatePickerState.ts +0 -203
- package/src/useDateRangePickerState.ts +0 -330
- package/src/useTimeFieldState.ts +0 -99
- package/src/utils.ts +0 -272
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import {convertValue as $35a22f14a1f04b11$export$61a490a80c552550, createPlaceholderDate as $35a22f14a1f04b11$export$66aa2b09de4b1ea5, getFormatOptions as $35a22f14a1f04b11$export$7e319ea407e63bc0, getValidationResult as $35a22f14a1f04b11$export$f18627323ab57ac0, useDefaultProps as $35a22f14a1f04b11$export$2440da353cedad43} from "./utils.mjs";
|
|
2
|
-
import {getPlaceholder as $3e3ed55ab2966714$export$d3f5c5e0a5023fa0} from "./placeholders.mjs";
|
|
3
|
-
import {IncompleteDate as $f863c03ccd9aead0$export$ae165b50d181e1ef} from "./IncompleteDate.mjs";
|
|
4
|
-
import {DateFormatter as $g03ag$DateFormatter, isEqualCalendar as $g03ag$isEqualCalendar, toCalendar as $g03ag$toCalendar, GregorianCalendar as $g03ag$GregorianCalendar} from "@internationalized/date";
|
|
5
|
-
import {useFormValidationState as $g03ag$useFormValidationState} from "@react-stately/form";
|
|
6
|
-
import {NumberFormatter as $g03ag$NumberFormatter} from "@internationalized/number";
|
|
7
|
-
import {useControlledState as $g03ag$useControlledState} from "@react-stately/utils";
|
|
8
|
-
import {useMemo as $g03ag$useMemo, useState as $g03ag$useState} from "react";
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
-
* governing permissions and limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
29
|
-
year: true,
|
|
30
|
-
month: true,
|
|
31
|
-
day: true,
|
|
32
|
-
hour: true,
|
|
33
|
-
minute: true,
|
|
34
|
-
second: true,
|
|
35
|
-
dayPeriod: true,
|
|
36
|
-
era: true
|
|
37
|
-
};
|
|
38
|
-
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
39
|
-
year: 5,
|
|
40
|
-
month: 2,
|
|
41
|
-
day: 7,
|
|
42
|
-
hour: 2,
|
|
43
|
-
minute: 15,
|
|
44
|
-
second: 15
|
|
45
|
-
};
|
|
46
|
-
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
47
|
-
// Node seems to convert everything to lowercase...
|
|
48
|
-
dayperiod: 'dayPeriod',
|
|
49
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts#named_years
|
|
50
|
-
relatedYear: 'year',
|
|
51
|
-
yearName: 'literal',
|
|
52
|
-
unknown: 'literal'
|
|
53
|
-
};
|
|
54
|
-
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
55
|
-
let { locale: locale, createCalendar: createCalendar, hideTimeZone: hideTimeZone, isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, isRequired: isRequired = false, minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
56
|
-
let v = props.value || props.defaultValue || props.placeholderValue || null;
|
|
57
|
-
let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
58
|
-
let timeZone = defaultTimeZone || 'UTC';
|
|
59
|
-
// props.granularity must actually exist in the value if one is provided.
|
|
60
|
-
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
61
|
-
// Resolve default hour cycle and calendar system.
|
|
62
|
-
let [calendar, hourCycle] = (0, $g03ag$useMemo)(()=>{
|
|
63
|
-
let formatter = new (0, $g03ag$DateFormatter)(locale, {
|
|
64
|
-
dateStyle: 'short',
|
|
65
|
-
timeStyle: 'short',
|
|
66
|
-
hour12: props.hourCycle != null ? props.hourCycle === 12 : undefined
|
|
67
|
-
});
|
|
68
|
-
let opts = formatter.resolvedOptions();
|
|
69
|
-
let calendar = createCalendar(opts.calendar);
|
|
70
|
-
return [
|
|
71
|
-
calendar,
|
|
72
|
-
opts.hourCycle
|
|
73
|
-
];
|
|
74
|
-
}, [
|
|
75
|
-
locale,
|
|
76
|
-
props.hourCycle,
|
|
77
|
-
createCalendar
|
|
78
|
-
]);
|
|
79
|
-
var _props_defaultValue;
|
|
80
|
-
let [value, setDate] = (0, $g03ag$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
|
|
81
|
-
let [initialValue] = (0, $g03ag$useState)(value);
|
|
82
|
-
let calendarValue = (0, $g03ag$useMemo)(()=>{
|
|
83
|
-
var _convertValue;
|
|
84
|
-
return (_convertValue = (0, $35a22f14a1f04b11$export$61a490a80c552550)(value, calendar)) !== null && _convertValue !== void 0 ? _convertValue : null;
|
|
85
|
-
}, [
|
|
86
|
-
value,
|
|
87
|
-
calendar
|
|
88
|
-
]);
|
|
89
|
-
let [displayValue, setDisplayValue] = (0, $g03ag$useState)(()=>new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue));
|
|
90
|
-
let showEra = calendar.identifier === 'gregory' && displayValue.era === 'BC';
|
|
91
|
-
let formatOpts = (0, $g03ag$useMemo)(()=>{
|
|
92
|
-
var _props_maxGranularity;
|
|
93
|
-
return {
|
|
94
|
-
granularity: granularity,
|
|
95
|
-
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : 'year',
|
|
96
|
-
timeZone: defaultTimeZone,
|
|
97
|
-
hideTimeZone: hideTimeZone,
|
|
98
|
-
hourCycle: props.hourCycle,
|
|
99
|
-
showEra: showEra,
|
|
100
|
-
shouldForceLeadingZeros: props.shouldForceLeadingZeros
|
|
101
|
-
};
|
|
102
|
-
}, [
|
|
103
|
-
props.maxGranularity,
|
|
104
|
-
granularity,
|
|
105
|
-
props.hourCycle,
|
|
106
|
-
props.shouldForceLeadingZeros,
|
|
107
|
-
defaultTimeZone,
|
|
108
|
-
hideTimeZone,
|
|
109
|
-
showEra
|
|
110
|
-
]);
|
|
111
|
-
let opts = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, formatOpts), [
|
|
112
|
-
formatOpts
|
|
113
|
-
]);
|
|
114
|
-
let dateFormatter = (0, $g03ag$useMemo)(()=>new (0, $g03ag$DateFormatter)(locale, opts), [
|
|
115
|
-
locale,
|
|
116
|
-
opts
|
|
117
|
-
]);
|
|
118
|
-
let resolvedOptions = (0, $g03ag$useMemo)(()=>dateFormatter.resolvedOptions(), [
|
|
119
|
-
dateFormatter
|
|
120
|
-
]);
|
|
121
|
-
let placeholder = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone), [
|
|
122
|
-
props.placeholderValue,
|
|
123
|
-
granularity,
|
|
124
|
-
calendar,
|
|
125
|
-
defaultTimeZone
|
|
126
|
-
]);
|
|
127
|
-
let displaySegments = (0, $g03ag$useMemo)(()=>{
|
|
128
|
-
let is12HourClock = hourCycle === 'h11' || hourCycle === 'h12';
|
|
129
|
-
let segments = [
|
|
130
|
-
'era',
|
|
131
|
-
'year',
|
|
132
|
-
'month',
|
|
133
|
-
'day',
|
|
134
|
-
'hour',
|
|
135
|
-
...is12HourClock ? [
|
|
136
|
-
'dayPeriod'
|
|
137
|
-
] : [],
|
|
138
|
-
'minute',
|
|
139
|
-
'second'
|
|
140
|
-
];
|
|
141
|
-
let minIndex = segments.indexOf(props.maxGranularity || 'era');
|
|
142
|
-
let maxIndex = segments.indexOf(granularity === 'hour' && is12HourClock ? 'dayPeriod' : granularity);
|
|
143
|
-
return segments.slice(minIndex, maxIndex + 1);
|
|
144
|
-
}, [
|
|
145
|
-
props.maxGranularity,
|
|
146
|
-
granularity,
|
|
147
|
-
hourCycle
|
|
148
|
-
]);
|
|
149
|
-
let [lastValue, setLastValue] = (0, $g03ag$useState)(calendarValue);
|
|
150
|
-
let [lastCalendar, setLastCalendar] = (0, $g03ag$useState)(calendar);
|
|
151
|
-
let [lastHourCycle, setLastHourCycle] = (0, $g03ag$useState)(hourCycle);
|
|
152
|
-
if (calendarValue !== lastValue || hourCycle !== lastHourCycle || !(0, $g03ag$isEqualCalendar)(calendar, lastCalendar)) {
|
|
153
|
-
displayValue = new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue);
|
|
154
|
-
setLastValue(calendarValue);
|
|
155
|
-
setLastCalendar(calendar);
|
|
156
|
-
setLastHourCycle(hourCycle);
|
|
157
|
-
setDisplayValue(displayValue);
|
|
158
|
-
}
|
|
159
|
-
let setValue = (newValue)=>{
|
|
160
|
-
if (props.isDisabled || props.isReadOnly) return;
|
|
161
|
-
if (newValue == null || newValue instanceof (0, $f863c03ccd9aead0$export$ae165b50d181e1ef) && newValue.isCleared(displaySegments)) {
|
|
162
|
-
setDisplayValue(new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue));
|
|
163
|
-
setDate(null);
|
|
164
|
-
} else if (!(newValue instanceof (0, $f863c03ccd9aead0$export$ae165b50d181e1ef))) {
|
|
165
|
-
// The display calendar should not have any effect on the emitted value.
|
|
166
|
-
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
167
|
-
newValue = (0, $g03ag$toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $g03ag$GregorianCalendar)());
|
|
168
|
-
setDisplayValue(new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue));
|
|
169
|
-
setDate(newValue);
|
|
170
|
-
} else {
|
|
171
|
-
// If the new value is complete and valid, trigger onChange eagerly.
|
|
172
|
-
// If it represents an incomplete or invalid value (e.g. February 30th),
|
|
173
|
-
// wait until the field is blurred to trigger onChange.
|
|
174
|
-
if (newValue.isComplete(displaySegments)) {
|
|
175
|
-
let dateValue = newValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
|
|
176
|
-
if (newValue.validate(dateValue, displaySegments)) {
|
|
177
|
-
let newDateValue = (0, $g03ag$toCalendar)(dateValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $g03ag$GregorianCalendar)());
|
|
178
|
-
if (!value || newDateValue.compare(value) !== 0) {
|
|
179
|
-
setDisplayValue(new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue)); // reset in case prop isn't updated
|
|
180
|
-
setDate(newDateValue);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// Incomplete/invalid value. Set temporary display override.
|
|
186
|
-
setDisplayValue(newValue);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
let dateValue = (0, $g03ag$useMemo)(()=>{
|
|
190
|
-
let v = displayValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
|
|
191
|
-
return v.toDate(timeZone);
|
|
192
|
-
}, [
|
|
193
|
-
displayValue,
|
|
194
|
-
timeZone,
|
|
195
|
-
calendarValue,
|
|
196
|
-
placeholder
|
|
197
|
-
]);
|
|
198
|
-
let segments = (0, $g03ag$useMemo)(()=>$3c0fc76039f1c516$var$processSegments(dateValue, displayValue, dateFormatter, resolvedOptions, calendar, locale, granularity), [
|
|
199
|
-
dateValue,
|
|
200
|
-
dateFormatter,
|
|
201
|
-
resolvedOptions,
|
|
202
|
-
displayValue,
|
|
203
|
-
calendar,
|
|
204
|
-
locale,
|
|
205
|
-
granularity
|
|
206
|
-
]);
|
|
207
|
-
let adjustSegment = (type, amount)=>{
|
|
208
|
-
setValue(displayValue.cycle(type, amount, placeholder, displaySegments));
|
|
209
|
-
};
|
|
210
|
-
let builtinValidation = (0, $g03ag$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
211
|
-
value,
|
|
212
|
-
minValue,
|
|
213
|
-
maxValue,
|
|
214
|
-
isDateUnavailable,
|
|
215
|
-
formatOpts
|
|
216
|
-
]);
|
|
217
|
-
let validation = (0, $g03ag$useFormValidationState)({
|
|
218
|
-
...props,
|
|
219
|
-
value: value,
|
|
220
|
-
builtinValidation: builtinValidation
|
|
221
|
-
});
|
|
222
|
-
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
223
|
-
let validationState = props.validationState || (isValueInvalid ? 'invalid' : null);
|
|
224
|
-
var _props_defaultValue1, _props_maxGranularity;
|
|
225
|
-
return {
|
|
226
|
-
...validation,
|
|
227
|
-
value: calendarValue,
|
|
228
|
-
defaultValue: (_props_defaultValue1 = props.defaultValue) !== null && _props_defaultValue1 !== void 0 ? _props_defaultValue1 : initialValue,
|
|
229
|
-
dateValue: dateValue,
|
|
230
|
-
calendar: calendar,
|
|
231
|
-
setValue: setValue,
|
|
232
|
-
segments: segments,
|
|
233
|
-
dateFormatter: dateFormatter,
|
|
234
|
-
validationState: validationState,
|
|
235
|
-
isInvalid: isValueInvalid,
|
|
236
|
-
granularity: granularity,
|
|
237
|
-
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : 'year',
|
|
238
|
-
isDisabled: isDisabled,
|
|
239
|
-
isReadOnly: isReadOnly,
|
|
240
|
-
isRequired: isRequired,
|
|
241
|
-
increment (part) {
|
|
242
|
-
adjustSegment(part, 1);
|
|
243
|
-
},
|
|
244
|
-
decrement (part) {
|
|
245
|
-
adjustSegment(part, -1);
|
|
246
|
-
},
|
|
247
|
-
incrementPage (part) {
|
|
248
|
-
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
249
|
-
},
|
|
250
|
-
decrementPage (part) {
|
|
251
|
-
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
252
|
-
},
|
|
253
|
-
incrementToMax (part) {
|
|
254
|
-
let maxValue = part === 'hour' && hourCycle === 'h12' ? 11 : displayValue.getSegmentLimits(part).maxValue;
|
|
255
|
-
setValue(displayValue.set(part, maxValue, placeholder));
|
|
256
|
-
},
|
|
257
|
-
decrementToMin (part) {
|
|
258
|
-
let minValue = part === 'hour' && hourCycle === 'h12' ? 12 : displayValue.getSegmentLimits(part).minValue;
|
|
259
|
-
setValue(displayValue.set(part, minValue, placeholder));
|
|
260
|
-
},
|
|
261
|
-
setSegment (part, v) {
|
|
262
|
-
setValue(displayValue.set(part, v, placeholder));
|
|
263
|
-
},
|
|
264
|
-
confirmPlaceholder () {
|
|
265
|
-
if (props.isDisabled || props.isReadOnly) return;
|
|
266
|
-
// If the display value is complete but invalid, we need to constrain it and emit onChange on blur.
|
|
267
|
-
if (displayValue.isComplete(displaySegments)) {
|
|
268
|
-
let dateValue = displayValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
|
|
269
|
-
let newDateValue = (0, $g03ag$toCalendar)(dateValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $g03ag$GregorianCalendar)());
|
|
270
|
-
if (!value || newDateValue.compare(value) !== 0) setDate(newDateValue);
|
|
271
|
-
setDisplayValue(new (0, $f863c03ccd9aead0$export$ae165b50d181e1ef)(calendar, hourCycle, calendarValue));
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
clearSegment (part) {
|
|
275
|
-
let value = displayValue;
|
|
276
|
-
if (part !== 'timeZoneName' && part !== 'literal') value = displayValue.clear(part);
|
|
277
|
-
setValue(value);
|
|
278
|
-
},
|
|
279
|
-
formatValue (fieldOptions) {
|
|
280
|
-
if (!calendarValue) return '';
|
|
281
|
-
let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
282
|
-
let formatter = new (0, $g03ag$DateFormatter)(locale, formatOptions);
|
|
283
|
-
return formatter.format(dateValue);
|
|
284
|
-
},
|
|
285
|
-
getDateFormatter (locale, formatOptions) {
|
|
286
|
-
let newOptions = {
|
|
287
|
-
...formatOpts,
|
|
288
|
-
...formatOptions
|
|
289
|
-
};
|
|
290
|
-
let newFormatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, newOptions);
|
|
291
|
-
return new (0, $g03ag$DateFormatter)(locale, newFormatOptions);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
function $3c0fc76039f1c516$var$processSegments(dateValue, displayValue, dateFormatter, resolvedOptions, calendar, locale, granularity) {
|
|
296
|
-
let timeValue = [
|
|
297
|
-
'hour',
|
|
298
|
-
'minute',
|
|
299
|
-
'second'
|
|
300
|
-
];
|
|
301
|
-
let segments = dateFormatter.formatToParts(dateValue);
|
|
302
|
-
// In order to allow formatting temporarily invalid dates during editing (e.g. February 30th),
|
|
303
|
-
// use a NumberFormatter to manually format segments directly from raw numbers.
|
|
304
|
-
// When the user blurs the date field, the invalid segments will be constrained.
|
|
305
|
-
let numberFormatter = new (0, $g03ag$NumberFormatter)(locale, {
|
|
306
|
-
useGrouping: false
|
|
307
|
-
});
|
|
308
|
-
let twoDigitFormatter = new (0, $g03ag$NumberFormatter)(locale, {
|
|
309
|
-
useGrouping: false,
|
|
310
|
-
minimumIntegerDigits: 2
|
|
311
|
-
});
|
|
312
|
-
for (let segment of segments)if (segment.type === 'year' || segment.type === 'month' || segment.type === 'day' || segment.type === 'hour') {
|
|
313
|
-
var _displayValue_segment_type;
|
|
314
|
-
let value = (_displayValue_segment_type = displayValue[segment.type]) !== null && _displayValue_segment_type !== void 0 ? _displayValue_segment_type : 0;
|
|
315
|
-
if (resolvedOptions[segment.type] === '2-digit') segment.value = twoDigitFormatter.format(value);
|
|
316
|
-
else segment.value = numberFormatter.format(value);
|
|
317
|
-
}
|
|
318
|
-
let processedSegments = [];
|
|
319
|
-
for (let segment of segments){
|
|
320
|
-
let type = $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type;
|
|
321
|
-
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[type];
|
|
322
|
-
if (type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
323
|
-
let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[type] && displayValue[segment.type] == null;
|
|
324
|
-
let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[type] ? (0, $3e3ed55ab2966714$export$d3f5c5e0a5023fa0)(type, segment.value, locale) : null;
|
|
325
|
-
let dateSegment = {
|
|
326
|
-
type: type,
|
|
327
|
-
text: isPlaceholder ? placeholder : segment.value,
|
|
328
|
-
...displayValue.getSegmentLimits(type),
|
|
329
|
-
isPlaceholder: isPlaceholder,
|
|
330
|
-
placeholder: placeholder,
|
|
331
|
-
isEditable: isEditable
|
|
332
|
-
};
|
|
333
|
-
// There is an issue in RTL languages where time fields render (minute:hour) instead of (hour:minute).
|
|
334
|
-
// To force an LTR direction on the time field since, we wrap the time segments in LRI (left-to-right) isolate unicode. See https://www.w3.org/International/questions/qa-bidi-unicode-controls.
|
|
335
|
-
// These unicode characters will be added to the array of processed segments as literals and will mark the start and end of the embedded direction change.
|
|
336
|
-
if (type === 'hour') {
|
|
337
|
-
// This marks the start of the embedded direction change.
|
|
338
|
-
processedSegments.push({
|
|
339
|
-
type: 'literal',
|
|
340
|
-
text: '\u2066',
|
|
341
|
-
isPlaceholder: false,
|
|
342
|
-
placeholder: '',
|
|
343
|
-
isEditable: false
|
|
344
|
-
});
|
|
345
|
-
processedSegments.push(dateSegment);
|
|
346
|
-
// This marks the end of the embedded direction change in the case that the granularity it set to "hour".
|
|
347
|
-
if (type === granularity) processedSegments.push({
|
|
348
|
-
type: 'literal',
|
|
349
|
-
text: '\u2069',
|
|
350
|
-
isPlaceholder: false,
|
|
351
|
-
placeholder: '',
|
|
352
|
-
isEditable: false
|
|
353
|
-
});
|
|
354
|
-
} else if (timeValue.includes(type) && type === granularity) {
|
|
355
|
-
processedSegments.push(dateSegment);
|
|
356
|
-
// This marks the end of the embedded direction change.
|
|
357
|
-
processedSegments.push({
|
|
358
|
-
type: 'literal',
|
|
359
|
-
text: '\u2069',
|
|
360
|
-
isPlaceholder: false,
|
|
361
|
-
placeholder: '',
|
|
362
|
-
isEditable: false
|
|
363
|
-
});
|
|
364
|
-
} else // We only want to "wrap" the unicode around segments that are hour, minute, or second. If they aren't, just process as normal.
|
|
365
|
-
processedSegments.push(dateSegment);
|
|
366
|
-
}
|
|
367
|
-
return processedSegments;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
export {$3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState};
|
|
372
|
-
//# sourceMappingURL=useDateFieldState.module.js.map
|