1542 lines
59 KiB
JavaScript
1542 lines
59 KiB
JavaScript
var $a16eae39a66f3afd$exports = require("./ar-AE.main.js");
|
|
var $be973442240b2918$exports = require("./bg-BG.main.js");
|
|
var $a1709037331f64d7$exports = require("./cs-CZ.main.js");
|
|
var $1896523498fa2f44$exports = require("./da-DK.main.js");
|
|
var $169837a5a815615d$exports = require("./de-DE.main.js");
|
|
var $cfb55132d6925036$exports = require("./el-GR.main.js");
|
|
var $384a6c8de1da1e62$exports = require("./en-US.main.js");
|
|
var $be8241903709dc6e$exports = require("./es-ES.main.js");
|
|
var $63e1eb192205ecbf$exports = require("./et-EE.main.js");
|
|
var $41dc33071b9981dc$exports = require("./fi-FI.main.js");
|
|
var $c75ba81d7768253e$exports = require("./fr-FR.main.js");
|
|
var $f678f4bf27dcdd12$exports = require("./he-IL.main.js");
|
|
var $d23f6e75dc589b55$exports = require("./hr-HR.main.js");
|
|
var $439e34e0a9a3f4c1$exports = require("./hu-HU.main.js");
|
|
var $449973ba87982f00$exports = require("./it-IT.main.js");
|
|
var $902560907618d6e6$exports = require("./ja-JP.main.js");
|
|
var $8c0f39c970bc2860$exports = require("./ko-KR.main.js");
|
|
var $db03bc54746c5caa$exports = require("./lt-LT.main.js");
|
|
var $3f356a0921f4d37a$exports = require("./lv-LV.main.js");
|
|
var $1265d19da9735bfb$exports = require("./nb-NO.main.js");
|
|
var $7b57f991f3f6edd1$exports = require("./nl-NL.main.js");
|
|
var $04fe5f1360210d7c$exports = require("./pl-PL.main.js");
|
|
var $e64ffd0cafbe4c46$exports = require("./pt-BR.main.js");
|
|
var $f7b4a5fc25c8f238$exports = require("./pt-PT.main.js");
|
|
var $cf72ee454c27a2e7$exports = require("./ro-RO.main.js");
|
|
var $a41511fa599c2cbe$exports = require("./ru-RU.main.js");
|
|
var $2fedc389afac088d$exports = require("./sk-SK.main.js");
|
|
var $b0aebb8d8c040cc9$exports = require("./sl-SI.main.js");
|
|
var $67017d9b82b5d17e$exports = require("./sr-SP.main.js");
|
|
var $833e86f5dac82c23$exports = require("./sv-SE.main.js");
|
|
var $5b72687d362158b0$exports = require("./tr-TR.main.js");
|
|
var $5d2b1be67024bd70$exports = require("./uk-UA.main.js");
|
|
var $644f5cd034787834$exports = require("./zh-CN.main.js");
|
|
var $11c20589c8b82ee8$exports = require("./zh-TW.main.js");
|
|
var $h2qOe$internationalizeddate = require("@internationalized/date");
|
|
var $h2qOe$reactstatelyform = require("@react-stately/form");
|
|
var $h2qOe$reactstatelyoverlays = require("@react-stately/overlays");
|
|
var $h2qOe$reactstatelyutils = require("@react-stately/utils");
|
|
var $h2qOe$react = require("react");
|
|
var $h2qOe$internationalizedstring = require("@internationalized/string");
|
|
|
|
|
|
function $parcel$export(e, n, v, s) {
|
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
}
|
|
|
|
function $parcel$interopDefault(a) {
|
|
return a && a.__esModule ? a.default : a;
|
|
}
|
|
|
|
$parcel$export(module.exports, "useDatePickerState", () => $aaab7a647e17e1fd$export$87194bb378cc3ac2);
|
|
$parcel$export(module.exports, "useDateFieldState", () => $596a1f0f523d6752$export$60e84778edff6d26);
|
|
$parcel$export(module.exports, "useDateRangePickerState", () => $7072d26f58deb33b$export$e50a61c1de9f574);
|
|
$parcel$export(module.exports, "useTimeFieldState", () => $2654e87be0231a69$export$fd53cef0cc796101);
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/ /*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
var $5294278fb5cc815e$exports = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$5294278fb5cc815e$exports = {
|
|
"ar-AE": $a16eae39a66f3afd$exports,
|
|
"bg-BG": $be973442240b2918$exports,
|
|
"cs-CZ": $a1709037331f64d7$exports,
|
|
"da-DK": $1896523498fa2f44$exports,
|
|
"de-DE": $169837a5a815615d$exports,
|
|
"el-GR": $cfb55132d6925036$exports,
|
|
"en-US": $384a6c8de1da1e62$exports,
|
|
"es-ES": $be8241903709dc6e$exports,
|
|
"et-EE": $63e1eb192205ecbf$exports,
|
|
"fi-FI": $41dc33071b9981dc$exports,
|
|
"fr-FR": $c75ba81d7768253e$exports,
|
|
"he-IL": $f678f4bf27dcdd12$exports,
|
|
"hr-HR": $d23f6e75dc589b55$exports,
|
|
"hu-HU": $439e34e0a9a3f4c1$exports,
|
|
"it-IT": $449973ba87982f00$exports,
|
|
"ja-JP": $902560907618d6e6$exports,
|
|
"ko-KR": $8c0f39c970bc2860$exports,
|
|
"lt-LT": $db03bc54746c5caa$exports,
|
|
"lv-LV": $3f356a0921f4d37a$exports,
|
|
"nb-NO": $1265d19da9735bfb$exports,
|
|
"nl-NL": $7b57f991f3f6edd1$exports,
|
|
"pl-PL": $04fe5f1360210d7c$exports,
|
|
"pt-BR": $e64ffd0cafbe4c46$exports,
|
|
"pt-PT": $f7b4a5fc25c8f238$exports,
|
|
"ro-RO": $cf72ee454c27a2e7$exports,
|
|
"ru-RU": $a41511fa599c2cbe$exports,
|
|
"sk-SK": $2fedc389afac088d$exports,
|
|
"sl-SI": $b0aebb8d8c040cc9$exports,
|
|
"sr-SP": $67017d9b82b5d17e$exports,
|
|
"sv-SE": $833e86f5dac82c23$exports,
|
|
"tr-TR": $5b72687d362158b0$exports,
|
|
"uk-UA": $5d2b1be67024bd70$exports,
|
|
"zh-CN": $644f5cd034787834$exports,
|
|
"zh-TW": $11c20589c8b82ee8$exports
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const $50d5d6a623389320$var$dictionary = new (0, $h2qOe$internationalizedstring.LocalizedStringDictionary)((0, (/*@__PURE__*/$parcel$interopDefault($5294278fb5cc815e$exports))));
|
|
function $50d5d6a623389320$var$getLocale() {
|
|
// Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
|
|
// validation messages, which to not respect our provider's language.
|
|
// @ts-ignore
|
|
return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
|
|
}
|
|
function $50d5d6a623389320$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
|
|
let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
|
|
let rangeUnderflow = value != null && minValue != null && value.compare(minValue) < 0;
|
|
let isUnavailable = value != null && (isDateUnavailable === null || isDateUnavailable === void 0 ? void 0 : isDateUnavailable(value)) || false;
|
|
let isInvalid = rangeOverflow || rangeUnderflow || isUnavailable;
|
|
let errors = [];
|
|
if (isInvalid) {
|
|
let locale = $50d5d6a623389320$var$getLocale();
|
|
let strings = (0, $h2qOe$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $50d5d6a623389320$var$dictionary;
|
|
let formatter = new (0, $h2qOe$internationalizedstring.LocalizedStringFormatter)(locale, strings);
|
|
let dateFormatter = new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, $50d5d6a623389320$export$7e319ea407e63bc0({}, options));
|
|
let timeZone = dateFormatter.resolvedOptions().timeZone;
|
|
if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
|
|
minValue: dateFormatter.format(minValue.toDate(timeZone))
|
|
}));
|
|
if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
|
|
maxValue: dateFormatter.format(maxValue.toDate(timeZone))
|
|
}));
|
|
if (isUnavailable) errors.push(formatter.format("unavailableDate"));
|
|
}
|
|
return {
|
|
isInvalid: isInvalid,
|
|
validationErrors: errors,
|
|
validationDetails: {
|
|
badInput: isUnavailable,
|
|
customError: false,
|
|
patternMismatch: false,
|
|
rangeOverflow: rangeOverflow,
|
|
rangeUnderflow: rangeUnderflow,
|
|
stepMismatch: false,
|
|
tooLong: false,
|
|
tooShort: false,
|
|
typeMismatch: false,
|
|
valueMissing: false,
|
|
valid: !isInvalid
|
|
}
|
|
};
|
|
}
|
|
function $50d5d6a623389320$export$80ff8fc0ae339c13(value, minValue, maxValue, isDateUnavailable, options) {
|
|
let startValidation = $50d5d6a623389320$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.start, minValue, maxValue, isDateUnavailable, options);
|
|
let endValidation = $50d5d6a623389320$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
|
|
let result = (0, $h2qOe$reactstatelyform.mergeValidation)(startValidation, endValidation);
|
|
if (value.end != null && value.start != null && value.end.compare(value.start) < 0) result = (0, $h2qOe$reactstatelyform.mergeValidation)(result, {
|
|
isInvalid: true,
|
|
validationErrors: [
|
|
$50d5d6a623389320$var$dictionary.getStringForLocale("rangeReversed", $50d5d6a623389320$var$getLocale())
|
|
],
|
|
validationDetails: {
|
|
...(0, $h2qOe$reactstatelyform.VALID_VALIDITY_STATE),
|
|
rangeUnderflow: true,
|
|
rangeOverflow: true,
|
|
valid: false
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
const $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS = {
|
|
year: "numeric",
|
|
month: "numeric",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
second: "2-digit"
|
|
};
|
|
const $50d5d6a623389320$var$TWO_DIGIT_FIELD_OPTIONS = {
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: "2-digit"
|
|
};
|
|
function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
let defaultFieldOptions = options.shouldForceLeadingZeros ? $50d5d6a623389320$var$TWO_DIGIT_FIELD_OPTIONS : $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS;
|
|
fieldOptions = {
|
|
...defaultFieldOptions,
|
|
...fieldOptions
|
|
};
|
|
let granularity = options.granularity || "minute";
|
|
let keys = Object.keys(fieldOptions);
|
|
var _options_maxGranularity;
|
|
let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
|
|
if (startIdx < 0) startIdx = 0;
|
|
let endIdx = keys.indexOf(granularity);
|
|
if (endIdx < 0) endIdx = 2;
|
|
if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
|
|
let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
|
|
opts[key] = fieldOptions[key];
|
|
return opts;
|
|
}, {});
|
|
if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
|
|
opts.timeZone = options.timeZone || "UTC";
|
|
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
|
|
if (options.showEra && startIdx === 0) opts.era = "short";
|
|
return opts;
|
|
}
|
|
function $50d5d6a623389320$export$c5221a78ef73c5e9(placeholderValue) {
|
|
if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
|
|
return new (0, $h2qOe$internationalizeddate.Time)();
|
|
}
|
|
function $50d5d6a623389320$export$61a490a80c552550(value, calendar) {
|
|
if (value === null) return null;
|
|
if (!value) return undefined;
|
|
return (0, $h2qOe$internationalizeddate.toCalendar)(value, calendar);
|
|
}
|
|
function $50d5d6a623389320$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
|
|
if (placeholderValue) return $50d5d6a623389320$export$61a490a80c552550(placeholderValue, calendar);
|
|
let date = (0, $h2qOe$internationalizeddate.toCalendar)((0, $h2qOe$internationalizeddate.now)(timeZone).set({
|
|
hour: 0,
|
|
minute: 0,
|
|
second: 0,
|
|
millisecond: 0
|
|
}), calendar);
|
|
if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $h2qOe$internationalizeddate.toCalendarDate)(date);
|
|
if (!timeZone) return (0, $h2qOe$internationalizeddate.toCalendarDateTime)(date);
|
|
return date;
|
|
}
|
|
function $50d5d6a623389320$export$2440da353cedad43(v, granularity) {
|
|
// Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
|
|
let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
|
|
let defaultGranularity = v && "minute" in v ? "minute" : "day";
|
|
// props.granularity must actually exist in the value if one is provided.
|
|
if (v && granularity && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
let [lastValue, setLastValue] = (0, $h2qOe$react.useState)([
|
|
defaultGranularity,
|
|
defaultTimeZone
|
|
]);
|
|
// If the granularity or time zone changed, update the last value.
|
|
if (v && (lastValue[0] !== defaultGranularity || lastValue[1] !== defaultTimeZone)) setLastValue([
|
|
defaultGranularity,
|
|
defaultTimeZone
|
|
]);
|
|
if (!granularity) granularity = v ? defaultGranularity : lastValue[0];
|
|
let timeZone = v ? defaultTimeZone : lastValue[1];
|
|
return [
|
|
granularity,
|
|
timeZone
|
|
];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
|
|
let overlayState = (0, $h2qOe$reactstatelyoverlays.useOverlayTriggerState)(props);
|
|
let [value, setValue] = (0, $h2qOe$reactstatelyutils.useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
let v = value || props.placeholderValue;
|
|
let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$export$2440da353cedad43)(v, props.granularity);
|
|
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
|
|
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
var _props_shouldCloseOnSelect;
|
|
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
let [selectedDate, setSelectedDate] = (0, $h2qOe$react.useState)(null);
|
|
let [selectedTime, setSelectedTime] = (0, $h2qOe$react.useState)(null);
|
|
if (value) {
|
|
selectedDate = value;
|
|
if ("hour" in value) selectedTime = value;
|
|
}
|
|
// props.granularity must actually exist in the value if one is provided.
|
|
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
let showEra = (value === null || value === void 0 ? void 0 : value.calendar.identifier) === "gregory" && value.era === "BC";
|
|
let formatOpts = (0, $h2qOe$react.useMemo)(()=>({
|
|
granularity: granularity,
|
|
timeZone: defaultTimeZone,
|
|
hideTimeZone: props.hideTimeZone,
|
|
hourCycle: props.hourCycle,
|
|
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
showEra: showEra
|
|
}), [
|
|
granularity,
|
|
props.hourCycle,
|
|
props.shouldForceLeadingZeros,
|
|
defaultTimeZone,
|
|
props.hideTimeZone,
|
|
showEra
|
|
]);
|
|
let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
let builtinValidation = (0, $h2qOe$react.useMemo)(()=>(0, $50d5d6a623389320$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
value,
|
|
minValue,
|
|
maxValue,
|
|
isDateUnavailable,
|
|
formatOpts
|
|
]);
|
|
let validation = (0, $h2qOe$reactstatelyform.useFormValidationState)({
|
|
...props,
|
|
value: value,
|
|
builtinValidation: builtinValidation
|
|
});
|
|
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
let commitValue = (date, time)=>{
|
|
setValue("timeZone" in time ? time.set((0, $h2qOe$internationalizeddate.toCalendarDate)(date)) : (0, $h2qOe$internationalizeddate.toCalendarDateTime)(date, time));
|
|
setSelectedDate(null);
|
|
setSelectedTime(null);
|
|
validation.commitValidation();
|
|
};
|
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
let selectDate = (newValue)=>{
|
|
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
if (hasTime) {
|
|
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
else setSelectedDate(newValue);
|
|
} else {
|
|
setValue(newValue);
|
|
validation.commitValidation();
|
|
}
|
|
if (shouldClose) overlayState.setOpen(false);
|
|
};
|
|
let selectTime = (newValue)=>{
|
|
if (selectedDate && newValue) commitValue(selectedDate, newValue);
|
|
else setSelectedTime(newValue);
|
|
};
|
|
return {
|
|
...validation,
|
|
value: value,
|
|
setValue: setValue,
|
|
dateValue: selectedDate,
|
|
timeValue: selectedTime,
|
|
setDateValue: selectDate,
|
|
setTimeValue: selectTime,
|
|
granularity: granularity,
|
|
hasTime: hasTime,
|
|
...overlayState,
|
|
setOpen (isOpen) {
|
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
// the user opens the popover again.
|
|
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
overlayState.setOpen(isOpen);
|
|
},
|
|
validationState: validationState,
|
|
isInvalid: isValueInvalid,
|
|
formatValue (locale, fieldOptions) {
|
|
if (!dateValue) return "";
|
|
let formatOptions = (0, $50d5d6a623389320$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
let formatter = new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, formatOptions);
|
|
return formatter.format(dateValue);
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
// These placeholders are based on the strings used by the <input type="date">
|
|
// implementations in Chrome and Firefox. Additional languages are supported
|
|
// here than React Spectrum's typical translations.
|
|
const $e1e8ada727fae1a1$var$placeholders = new (0, $h2qOe$internationalizedstring.LocalizedStringDictionary)({
|
|
ach: {
|
|
year: "mwaka",
|
|
month: "dwe",
|
|
day: "nino"
|
|
},
|
|
af: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
am: {
|
|
year: "\u12D3\u12D3\u12D3\u12D3",
|
|
month: "\u121A\u121C",
|
|
day: "\u1240\u1240"
|
|
},
|
|
an: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
ar: {
|
|
year: "\u0633\u0646\u0629",
|
|
month: "\u0634\u0647\u0631",
|
|
day: "\u064A\u0648\u0645"
|
|
},
|
|
ast: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
az: {
|
|
year: "iiii",
|
|
month: "aa",
|
|
day: "gg"
|
|
},
|
|
be: {
|
|
year: "\u0433\u0433\u0433\u0433",
|
|
month: "\u043C\u043C",
|
|
day: "\u0434\u0434"
|
|
},
|
|
bg: {
|
|
year: "\u0433\u0433\u0433\u0433",
|
|
month: "\u043C\u043C",
|
|
day: "\u0434\u0434"
|
|
},
|
|
bn: {
|
|
year: "yyyy",
|
|
month: "\u09AE\u09BF\u09AE\u09BF",
|
|
day: "dd"
|
|
},
|
|
br: {
|
|
year: "bbbb",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
bs: {
|
|
year: "gggg",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
ca: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
cak: {
|
|
year: "jjjj",
|
|
month: "ii",
|
|
day: "q'q'"
|
|
},
|
|
ckb: {
|
|
year: "\u0633\u0627\u06B5",
|
|
month: "\u0645\u0627\u0646\u06AF",
|
|
day: "\u0695\u06C6\u0698"
|
|
},
|
|
cs: {
|
|
year: "rrrr",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
cy: {
|
|
year: "bbbb",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
da: {
|
|
year: "\xe5\xe5\xe5\xe5",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
de: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "tt"
|
|
},
|
|
dsb: {
|
|
year: "llll",
|
|
month: "mm",
|
|
day: "\u017A\u017A"
|
|
},
|
|
el: {
|
|
year: "\u03B5\u03B5\u03B5\u03B5",
|
|
month: "\u03BC\u03BC",
|
|
day: "\u03B7\u03B7"
|
|
},
|
|
en: {
|
|
year: "yyyy",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
eo: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "tt"
|
|
},
|
|
es: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
et: {
|
|
year: "aaaa",
|
|
month: "kk",
|
|
day: "pp"
|
|
},
|
|
eu: {
|
|
year: "uuuu",
|
|
month: "hh",
|
|
day: "ee"
|
|
},
|
|
fa: {
|
|
year: "\u0633\u0627\u0644",
|
|
month: "\u0645\u0627\u0647",
|
|
day: "\u0631\u0648\u0632"
|
|
},
|
|
ff: {
|
|
year: "hhhh",
|
|
month: "ll",
|
|
day: "\xf1\xf1"
|
|
},
|
|
fi: {
|
|
year: "vvvv",
|
|
month: "kk",
|
|
day: "pp"
|
|
},
|
|
fr: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "jj"
|
|
},
|
|
fy: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
ga: {
|
|
year: "bbbb",
|
|
month: "mm",
|
|
day: "ll"
|
|
},
|
|
gd: {
|
|
year: "bbbb",
|
|
month: "mm",
|
|
day: "ll"
|
|
},
|
|
gl: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
he: {
|
|
year: "\u05E9\u05E0\u05D4",
|
|
month: "\u05D7\u05D5\u05D3\u05E9",
|
|
day: "\u05D9\u05D5\u05DD"
|
|
},
|
|
hr: {
|
|
year: "gggg",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
hsb: {
|
|
year: "llll",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
hu: {
|
|
year: "\xe9\xe9\xe9\xe9",
|
|
month: "hh",
|
|
day: "nn"
|
|
},
|
|
ia: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
id: {
|
|
year: "tttt",
|
|
month: "bb",
|
|
day: "hh"
|
|
},
|
|
it: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "gg"
|
|
},
|
|
ja: {
|
|
year: " \u5E74 ",
|
|
month: "\u6708",
|
|
day: "\u65E5"
|
|
},
|
|
ka: {
|
|
year: "\u10EC\u10EC\u10EC\u10EC",
|
|
month: "\u10D7\u10D7",
|
|
day: "\u10E0\u10E0"
|
|
},
|
|
kk: {
|
|
year: "\u0436\u0436\u0436\u0436",
|
|
month: "\u0430\u0430",
|
|
day: "\u043A\u043A"
|
|
},
|
|
kn: {
|
|
year: "\u0CB5\u0CB5\u0CB5\u0CB5",
|
|
month: "\u0CAE\u0CBF\u0CAE\u0CC0",
|
|
day: "\u0CA6\u0CBF\u0CA6\u0CBF"
|
|
},
|
|
ko: {
|
|
year: "\uC5F0\uB3C4",
|
|
month: "\uC6D4",
|
|
day: "\uC77C"
|
|
},
|
|
lb: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
lo: {
|
|
year: "\u0E9B\u0E9B\u0E9B\u0E9B",
|
|
month: "\u0E94\u0E94",
|
|
day: "\u0EA7\u0EA7"
|
|
},
|
|
lt: {
|
|
year: "mmmm",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
lv: {
|
|
year: "gggg",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
meh: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
ml: {
|
|
year: "\u0D35\u0D7C\u0D37\u0D02",
|
|
month: "\u0D2E\u0D3E\u0D38\u0D02",
|
|
day: "\u0D24\u0D40\u0D2F\u0D24\u0D3F"
|
|
},
|
|
ms: {
|
|
year: "tttt",
|
|
month: "mm",
|
|
day: "hh"
|
|
},
|
|
nl: {
|
|
year: "jjjj",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
nn: {
|
|
year: "\xe5\xe5\xe5\xe5",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
no: {
|
|
year: "\xe5\xe5\xe5\xe5",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
oc: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "jj"
|
|
},
|
|
pl: {
|
|
year: "rrrr",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
pt: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
rm: {
|
|
year: "oooo",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
ro: {
|
|
year: "aaaa",
|
|
month: "ll",
|
|
day: "zz"
|
|
},
|
|
ru: {
|
|
year: "\u0433\u0433\u0433\u0433",
|
|
month: "\u043C\u043C",
|
|
day: "\u0434\u0434"
|
|
},
|
|
sc: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
scn: {
|
|
year: "aaaa",
|
|
month: "mm",
|
|
day: "jj"
|
|
},
|
|
sk: {
|
|
year: "rrrr",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
sl: {
|
|
year: "llll",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
sr: {
|
|
year: "\u0433\u0433\u0433\u0433",
|
|
month: "\u043C\u043C",
|
|
day: "\u0434\u0434"
|
|
},
|
|
sv: {
|
|
year: "\xe5\xe5\xe5\xe5",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
szl: {
|
|
year: "rrrr",
|
|
month: "mm",
|
|
day: "dd"
|
|
},
|
|
tg: {
|
|
year: "\u0441\u0441\u0441\u0441",
|
|
month: "\u043C\u043C",
|
|
day: "\u0440\u0440"
|
|
},
|
|
th: {
|
|
year: "\u0E1B\u0E1B\u0E1B\u0E1B",
|
|
month: "\u0E14\u0E14",
|
|
day: "\u0E27\u0E27"
|
|
},
|
|
tr: {
|
|
year: "yyyy",
|
|
month: "aa",
|
|
day: "gg"
|
|
},
|
|
uk: {
|
|
year: "\u0440\u0440\u0440\u0440",
|
|
month: "\u043C\u043C",
|
|
day: "\u0434\u0434"
|
|
},
|
|
"zh-CN": {
|
|
year: "\u5E74",
|
|
month: "\u6708",
|
|
day: "\u65E5"
|
|
},
|
|
"zh-TW": {
|
|
year: "\u5E74",
|
|
month: "\u6708",
|
|
day: "\u65E5"
|
|
}
|
|
}, "en");
|
|
function $e1e8ada727fae1a1$export$d3f5c5e0a5023fa0(field, value, locale) {
|
|
// Use the actual placeholder value for the era and day period fields.
|
|
if (field === "era" || field === "dayPeriod") return value;
|
|
if (field === "year" || field === "month" || field === "day") return $e1e8ada727fae1a1$var$placeholders.getStringForLocale(field, locale);
|
|
// For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
|
|
return "\u2013\u2013";
|
|
}
|
|
|
|
|
|
|
|
|
|
const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
|
|
year: true,
|
|
month: true,
|
|
day: true,
|
|
hour: true,
|
|
minute: true,
|
|
second: true,
|
|
dayPeriod: true,
|
|
era: true
|
|
};
|
|
const $596a1f0f523d6752$var$PAGE_STEP = {
|
|
year: 5,
|
|
month: 2,
|
|
day: 7,
|
|
hour: 2,
|
|
minute: 15,
|
|
second: 15
|
|
};
|
|
// Node seems to convert everything to lowercase...
|
|
const $596a1f0f523d6752$var$TYPE_MAPPING = {
|
|
dayperiod: "dayPeriod"
|
|
};
|
|
function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
let { locale: locale, createCalendar: createCalendar, hideTimeZone: hideTimeZone, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
let v = props.value || props.defaultValue || props.placeholderValue;
|
|
let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$export$2440da353cedad43)(v, props.granularity);
|
|
let timeZone = defaultTimeZone || "UTC";
|
|
// props.granularity must actually exist in the value if one is provided.
|
|
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
let defaultFormatter = (0, $h2qOe$react.useMemo)(()=>new (0, $h2qOe$internationalizeddate.DateFormatter)(locale), [
|
|
locale
|
|
]);
|
|
let calendar = (0, $h2qOe$react.useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
|
|
createCalendar,
|
|
defaultFormatter
|
|
]);
|
|
let [value, setDate] = (0, $h2qOe$reactstatelyutils.useControlledState)(props.value, props.defaultValue, props.onChange);
|
|
let calendarValue = (0, $h2qOe$react.useMemo)(()=>(0, $50d5d6a623389320$export$61a490a80c552550)(value, calendar), [
|
|
value,
|
|
calendar
|
|
]);
|
|
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
// change from uncontrolled to controlled and emit a warning.
|
|
let [placeholderDate, setPlaceholderDate] = (0, $h2qOe$react.useState)(()=>(0, $50d5d6a623389320$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
let val = calendarValue || placeholderDate;
|
|
let showEra = calendar.identifier === "gregory" && val.era === "BC";
|
|
let formatOpts = (0, $h2qOe$react.useMemo)(()=>{
|
|
var _props_maxGranularity;
|
|
return {
|
|
granularity: granularity,
|
|
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
|
|
timeZone: defaultTimeZone,
|
|
hideTimeZone: hideTimeZone,
|
|
hourCycle: props.hourCycle,
|
|
showEra: showEra,
|
|
shouldForceLeadingZeros: props.shouldForceLeadingZeros
|
|
};
|
|
}, [
|
|
props.maxGranularity,
|
|
granularity,
|
|
props.hourCycle,
|
|
props.shouldForceLeadingZeros,
|
|
defaultTimeZone,
|
|
hideTimeZone,
|
|
showEra
|
|
]);
|
|
let opts = (0, $h2qOe$react.useMemo)(()=>(0, $50d5d6a623389320$export$7e319ea407e63bc0)({}, formatOpts), [
|
|
formatOpts
|
|
]);
|
|
let dateFormatter = (0, $h2qOe$react.useMemo)(()=>new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, opts), [
|
|
locale,
|
|
opts
|
|
]);
|
|
let resolvedOptions = (0, $h2qOe$react.useMemo)(()=>dateFormatter.resolvedOptions(), [
|
|
dateFormatter
|
|
]);
|
|
// Determine how many editable segments there are for validation purposes.
|
|
// The result is cached for performance.
|
|
let allSegments = (0, $h2qOe$react.useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$596a1f0f523d6752$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[seg.type] = true, p), {}), [
|
|
dateFormatter
|
|
]);
|
|
let [validSegments, setValidSegments] = (0, $h2qOe$react.useState)(()=>props.value || props.defaultValue ? {
|
|
...allSegments
|
|
} : {});
|
|
let clearedSegment = (0, $h2qOe$react.useRef)();
|
|
// Reset placeholder when calendar changes
|
|
let lastCalendarIdentifier = (0, $h2qOe$react.useRef)(calendar.identifier);
|
|
(0, $h2qOe$react.useEffect)(()=>{
|
|
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
lastCalendarIdentifier.current = calendar.identifier;
|
|
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $h2qOe$internationalizeddate.toCalendar)(placeholder, calendar) : (0, $50d5d6a623389320$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
}
|
|
}, [
|
|
calendar,
|
|
granularity,
|
|
validSegments,
|
|
defaultTimeZone,
|
|
props.placeholderValue
|
|
]);
|
|
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
validSegments = {
|
|
...allSegments
|
|
};
|
|
setValidSegments(validSegments);
|
|
}
|
|
// If the value is set to null and all segments are valid, reset the placeholder.
|
|
if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
|
|
validSegments = {};
|
|
setValidSegments(validSegments);
|
|
setPlaceholderDate((0, $50d5d6a623389320$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
}
|
|
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
let setValue = (newValue)=>{
|
|
if (props.isDisabled || props.isReadOnly) return;
|
|
let validKeys = Object.keys(validSegments);
|
|
let allKeys = Object.keys(allSegments);
|
|
// if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared
|
|
if (newValue == null) {
|
|
setDate(null);
|
|
setPlaceholderDate((0, $50d5d6a623389320$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
setValidSegments({});
|
|
} else if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== "dayPeriod") {
|
|
// The display calendar should not have any effect on the emitted value.
|
|
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
newValue = (0, $h2qOe$internationalizeddate.toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $h2qOe$internationalizeddate.GregorianCalendar)());
|
|
setDate(newValue);
|
|
} else setPlaceholderDate(newValue);
|
|
clearedSegment.current = null;
|
|
};
|
|
let dateValue = (0, $h2qOe$react.useMemo)(()=>displayValue.toDate(timeZone), [
|
|
displayValue,
|
|
timeZone
|
|
]);
|
|
let segments = (0, $h2qOe$react.useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type];
|
|
if (segment.type === "era" && calendar.getEras().length === 1) isEditable = false;
|
|
let isPlaceholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
|
|
let placeholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] ? (0, $e1e8ada727fae1a1$export$d3f5c5e0a5023fa0)(segment.type, segment.value, locale) : null;
|
|
return {
|
|
type: $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
text: isPlaceholder ? placeholder : segment.value,
|
|
...$596a1f0f523d6752$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
isPlaceholder: isPlaceholder,
|
|
placeholder: placeholder,
|
|
isEditable: isEditable
|
|
};
|
|
}), [
|
|
dateValue,
|
|
validSegments,
|
|
dateFormatter,
|
|
resolvedOptions,
|
|
displayValue,
|
|
calendar,
|
|
locale
|
|
]);
|
|
// When the era field appears, mark it valid if the year field is already valid.
|
|
// If the era field disappears, remove it from the valid segments.
|
|
if (allSegments.era && validSegments.year && !validSegments.era) {
|
|
validSegments.era = true;
|
|
setValidSegments({
|
|
...validSegments
|
|
});
|
|
} else if (!allSegments.era && validSegments.era) {
|
|
delete validSegments.era;
|
|
setValidSegments({
|
|
...validSegments
|
|
});
|
|
}
|
|
let markValid = (part)=>{
|
|
validSegments[part] = true;
|
|
if (part === "year" && allSegments.era) validSegments.era = true;
|
|
setValidSegments({
|
|
...validSegments
|
|
});
|
|
};
|
|
let adjustSegment = (type, amount)=>{
|
|
if (!validSegments[type]) {
|
|
markValid(type);
|
|
let validKeys = Object.keys(validSegments);
|
|
let allKeys = Object.keys(allSegments);
|
|
if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) setValue(displayValue);
|
|
} else setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
};
|
|
let builtinValidation = (0, $h2qOe$react.useMemo)(()=>(0, $50d5d6a623389320$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
value,
|
|
minValue,
|
|
maxValue,
|
|
isDateUnavailable,
|
|
formatOpts
|
|
]);
|
|
let validation = (0, $h2qOe$reactstatelyform.useFormValidationState)({
|
|
...props,
|
|
value: value,
|
|
builtinValidation: builtinValidation
|
|
});
|
|
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
var _props_maxGranularity;
|
|
return {
|
|
...validation,
|
|
value: calendarValue,
|
|
dateValue: dateValue,
|
|
calendar: calendar,
|
|
setValue: setValue,
|
|
segments: segments,
|
|
dateFormatter: dateFormatter,
|
|
validationState: validationState,
|
|
isInvalid: isValueInvalid,
|
|
granularity: granularity,
|
|
maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
|
|
isDisabled: isDisabled,
|
|
isReadOnly: isReadOnly,
|
|
isRequired: isRequired,
|
|
increment (part) {
|
|
adjustSegment(part, 1);
|
|
},
|
|
decrement (part) {
|
|
adjustSegment(part, -1);
|
|
},
|
|
incrementPage (part) {
|
|
adjustSegment(part, $596a1f0f523d6752$var$PAGE_STEP[part] || 1);
|
|
},
|
|
decrementPage (part) {
|
|
adjustSegment(part, -($596a1f0f523d6752$var$PAGE_STEP[part] || 1));
|
|
},
|
|
setSegment (part, v) {
|
|
markValid(part);
|
|
setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
},
|
|
confirmPlaceholder () {
|
|
if (props.isDisabled || props.isReadOnly) return;
|
|
// Confirm the placeholder if only the day period is not filled in.
|
|
let validKeys = Object.keys(validSegments);
|
|
let allKeys = Object.keys(allSegments);
|
|
if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
|
|
validSegments = {
|
|
...allSegments
|
|
};
|
|
setValidSegments(validSegments);
|
|
setValue(displayValue.copy());
|
|
}
|
|
},
|
|
clearSegment (part) {
|
|
delete validSegments[part];
|
|
clearedSegment.current = part;
|
|
setValidSegments({
|
|
...validSegments
|
|
});
|
|
let placeholder = (0, $50d5d6a623389320$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
let value = displayValue;
|
|
// Reset day period to default without changing the hour.
|
|
if (part === "dayPeriod" && "hour" in displayValue && "hour" in placeholder) {
|
|
let isPM = displayValue.hour >= 12;
|
|
let shouldBePM = placeholder.hour >= 12;
|
|
if (isPM && !shouldBePM) value = displayValue.set({
|
|
hour: displayValue.hour - 12
|
|
});
|
|
else if (!isPM && shouldBePM) value = displayValue.set({
|
|
hour: displayValue.hour + 12
|
|
});
|
|
} else if (part in displayValue) value = displayValue.set({
|
|
[part]: placeholder[part]
|
|
});
|
|
setDate(null);
|
|
setValue(value);
|
|
},
|
|
formatValue (fieldOptions) {
|
|
if (!calendarValue) return "";
|
|
let formatOptions = (0, $50d5d6a623389320$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
let formatter = new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, formatOptions);
|
|
return formatter.format(dateValue);
|
|
}
|
|
};
|
|
}
|
|
function $596a1f0f523d6752$var$getSegmentLimits(date, type, options) {
|
|
switch(type){
|
|
case "era":
|
|
{
|
|
let eras = date.calendar.getEras();
|
|
return {
|
|
value: eras.indexOf(date.era),
|
|
minValue: 0,
|
|
maxValue: eras.length - 1
|
|
};
|
|
}
|
|
case "year":
|
|
return {
|
|
value: date.year,
|
|
minValue: 1,
|
|
maxValue: date.calendar.getYearsInEra(date)
|
|
};
|
|
case "month":
|
|
return {
|
|
value: date.month,
|
|
minValue: (0, $h2qOe$internationalizeddate.getMinimumMonthInYear)(date),
|
|
maxValue: date.calendar.getMonthsInYear(date)
|
|
};
|
|
case "day":
|
|
return {
|
|
value: date.day,
|
|
minValue: (0, $h2qOe$internationalizeddate.getMinimumDayInMonth)(date),
|
|
maxValue: date.calendar.getDaysInMonth(date)
|
|
};
|
|
}
|
|
if ("hour" in date) switch(type){
|
|
case "dayPeriod":
|
|
return {
|
|
value: date.hour >= 12 ? 12 : 0,
|
|
minValue: 0,
|
|
maxValue: 12
|
|
};
|
|
case "hour":
|
|
if (options.hour12) {
|
|
let isPM = date.hour >= 12;
|
|
return {
|
|
value: date.hour,
|
|
minValue: isPM ? 12 : 0,
|
|
maxValue: isPM ? 23 : 11
|
|
};
|
|
}
|
|
return {
|
|
value: date.hour,
|
|
minValue: 0,
|
|
maxValue: 23
|
|
};
|
|
case "minute":
|
|
return {
|
|
value: date.minute,
|
|
minValue: 0,
|
|
maxValue: 59
|
|
};
|
|
case "second":
|
|
return {
|
|
value: date.second,
|
|
minValue: 0,
|
|
maxValue: 59
|
|
};
|
|
}
|
|
return {};
|
|
}
|
|
function $596a1f0f523d6752$var$addSegment(value, part, amount, options) {
|
|
switch(part){
|
|
case "era":
|
|
case "year":
|
|
case "month":
|
|
case "day":
|
|
return value.cycle(part, amount, {
|
|
round: part === "year"
|
|
});
|
|
}
|
|
if ("hour" in value) switch(part){
|
|
case "dayPeriod":
|
|
{
|
|
let hours = value.hour;
|
|
let isPM = hours >= 12;
|
|
return value.set({
|
|
hour: isPM ? hours - 12 : hours + 12
|
|
});
|
|
}
|
|
case "hour":
|
|
case "minute":
|
|
case "second":
|
|
return value.cycle(part, amount, {
|
|
round: part !== "hour",
|
|
hourCycle: options.hour12 ? 12 : 24
|
|
});
|
|
}
|
|
}
|
|
function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
|
|
switch(part){
|
|
case "day":
|
|
case "month":
|
|
case "year":
|
|
case "era":
|
|
return value.set({
|
|
[part]: segmentValue
|
|
});
|
|
}
|
|
if ("hour" in value) switch(part){
|
|
case "dayPeriod":
|
|
{
|
|
let hours = value.hour;
|
|
let wasPM = hours >= 12;
|
|
let isPM = segmentValue >= 12;
|
|
if (isPM === wasPM) return value;
|
|
return value.set({
|
|
hour: wasPM ? hours - 12 : hours + 12
|
|
});
|
|
}
|
|
case "hour":
|
|
// In 12 hour time, ensure that AM/PM does not change
|
|
if (options.hour12) {
|
|
let hours = value.hour;
|
|
let wasPM = hours >= 12;
|
|
if (!wasPM && segmentValue === 12) segmentValue = 0;
|
|
if (wasPM && segmentValue < 12) segmentValue += 12;
|
|
}
|
|
// fallthrough
|
|
case "minute":
|
|
case "second":
|
|
return value.set({
|
|
[part]: segmentValue
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
var _value_start, _value_end;
|
|
let overlayState = (0, $h2qOe$reactstatelyoverlays.useOverlayTriggerState)(props);
|
|
let [controlledValue, setControlledValue] = (0, $h2qOe$reactstatelyutils.useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
let [placeholderValue, setPlaceholderValue] = (0, $h2qOe$react.useState)(()=>controlledValue || {
|
|
start: null,
|
|
end: null
|
|
});
|
|
// Reset the placeholder if the value prop is set to null.
|
|
if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
|
|
placeholderValue = {
|
|
start: null,
|
|
end: null
|
|
};
|
|
setPlaceholderValue(placeholderValue);
|
|
}
|
|
let value = controlledValue || placeholderValue;
|
|
let setValue = (value)=>{
|
|
setPlaceholderValue(value || {
|
|
start: null,
|
|
end: null
|
|
});
|
|
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
else setControlledValue(null);
|
|
};
|
|
let v = (value === null || value === void 0 ? void 0 : value.start) || (value === null || value === void 0 ? void 0 : value.end) || props.placeholderValue;
|
|
let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$export$2440da353cedad43)(v, props.granularity);
|
|
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
var _props_shouldCloseOnSelect;
|
|
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
let [dateRange, setSelectedDateRange] = (0, $h2qOe$react.useState)(null);
|
|
let [timeRange, setSelectedTimeRange] = (0, $h2qOe$react.useState)(null);
|
|
if (value && value.start && value.end) {
|
|
dateRange = value;
|
|
if ("hour" in value.start) timeRange = value;
|
|
}
|
|
let commitValue = (dateRange, timeRange)=>{
|
|
setValue({
|
|
start: "timeZone" in timeRange.start ? timeRange.start.set((0, $h2qOe$internationalizeddate.toCalendarDate)(dateRange.start)) : (0, $h2qOe$internationalizeddate.toCalendarDateTime)(dateRange.start, timeRange.start),
|
|
end: "timeZone" in timeRange.end ? timeRange.end.set((0, $h2qOe$internationalizeddate.toCalendarDate)(dateRange.end)) : (0, $h2qOe$internationalizeddate.toCalendarDateTime)(dateRange.end, timeRange.end)
|
|
});
|
|
setSelectedDateRange(null);
|
|
setSelectedTimeRange(null);
|
|
validation.commitValidation();
|
|
};
|
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
let setDateRange = (range)=>{
|
|
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
if (hasTime) {
|
|
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, {
|
|
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue),
|
|
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue)
|
|
});
|
|
else setSelectedDateRange(range);
|
|
} else if (range.start && range.end) {
|
|
setValue(range);
|
|
validation.commitValidation();
|
|
} else setSelectedDateRange(range);
|
|
if (shouldClose) overlayState.setOpen(false);
|
|
};
|
|
let setTimeRange = (range)=>{
|
|
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);
|
|
else setSelectedTimeRange(range);
|
|
};
|
|
let showEra = (value === null || value === void 0 ? void 0 : (_value_start = value.start) === null || _value_start === void 0 ? void 0 : _value_start.calendar.identifier) === "gregory" && value.start.era === "BC" || (value === null || value === void 0 ? void 0 : (_value_end = value.end) === null || _value_end === void 0 ? void 0 : _value_end.calendar.identifier) === "gregory" && value.end.era === "BC";
|
|
let formatOpts = (0, $h2qOe$react.useMemo)(()=>({
|
|
granularity: granularity,
|
|
timeZone: defaultTimeZone,
|
|
hideTimeZone: props.hideTimeZone,
|
|
hourCycle: props.hourCycle,
|
|
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
showEra: showEra
|
|
}), [
|
|
granularity,
|
|
props.hourCycle,
|
|
props.shouldForceLeadingZeros,
|
|
defaultTimeZone,
|
|
props.hideTimeZone,
|
|
showEra
|
|
]);
|
|
let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
let builtinValidation = (0, $h2qOe$react.useMemo)(()=>(0, $50d5d6a623389320$export$80ff8fc0ae339c13)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
value,
|
|
minValue,
|
|
maxValue,
|
|
isDateUnavailable,
|
|
formatOpts
|
|
]);
|
|
let validation = (0, $h2qOe$reactstatelyform.useFormValidationState)({
|
|
...props,
|
|
value: controlledValue,
|
|
name: (0, $h2qOe$react.useMemo)(()=>[
|
|
props.startName,
|
|
props.endName
|
|
], [
|
|
props.startName,
|
|
props.endName
|
|
]),
|
|
builtinValidation: builtinValidation
|
|
});
|
|
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
return {
|
|
...validation,
|
|
value: value,
|
|
setValue: setValue,
|
|
dateRange: dateRange,
|
|
timeRange: timeRange,
|
|
granularity: granularity,
|
|
hasTime: hasTime,
|
|
setDate (part, date) {
|
|
setDateRange({
|
|
...dateRange,
|
|
[part]: date
|
|
});
|
|
},
|
|
setTime (part, time) {
|
|
setTimeRange({
|
|
...timeRange,
|
|
[part]: time
|
|
});
|
|
},
|
|
setDateTime (part, dateTime) {
|
|
setValue({
|
|
...value,
|
|
[part]: dateTime
|
|
});
|
|
},
|
|
setDateRange: setDateRange,
|
|
setTimeRange: setTimeRange,
|
|
...overlayState,
|
|
setOpen (isOpen) {
|
|
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
// the user opens the popover again.
|
|
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, {
|
|
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue),
|
|
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $50d5d6a623389320$export$c5221a78ef73c5e9)(props.placeholderValue)
|
|
});
|
|
overlayState.setOpen(isOpen);
|
|
},
|
|
validationState: validationState,
|
|
isInvalid: isValueInvalid,
|
|
formatValue (locale, fieldOptions) {
|
|
if (!value || !value.start || !value.end) return null;
|
|
let startTimeZone = "timeZone" in value.start ? value.start.timeZone : undefined;
|
|
let startGranularity = props.granularity || (value.start && "minute" in value.start ? "minute" : "day");
|
|
let endTimeZone = "timeZone" in value.end ? value.end.timeZone : undefined;
|
|
let endGranularity = props.granularity || (value.end && "minute" in value.end ? "minute" : "day");
|
|
let startOptions = (0, $50d5d6a623389320$export$7e319ea407e63bc0)(fieldOptions, {
|
|
granularity: startGranularity,
|
|
timeZone: startTimeZone,
|
|
hideTimeZone: props.hideTimeZone,
|
|
hourCycle: props.hourCycle,
|
|
showEra: value.start.calendar.identifier === "gregory" && value.start.era === "BC" || value.end.calendar.identifier === "gregory" && value.end.era === "BC"
|
|
});
|
|
let startDate = value.start.toDate(startTimeZone || "UTC");
|
|
let endDate = value.end.toDate(endTimeZone || "UTC");
|
|
let startFormatter = new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, startOptions);
|
|
let endFormatter;
|
|
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {
|
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
// are shared between the start and end dates (e.g. the same month).
|
|
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
try {
|
|
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
// Find the separator between the start and end date. This is determined
|
|
// by finding the last shared literal before the end range.
|
|
let separatorIndex = -1;
|
|
for(let i = 0; i < parts.length; i++){
|
|
let part = parts[i];
|
|
if (part.source === "shared" && part.type === "literal") separatorIndex = i;
|
|
else if (part.source === "endRange") break;
|
|
}
|
|
// Now we can combine the parts into start and end strings.
|
|
let start = "";
|
|
let end = "";
|
|
for(let i = 0; i < parts.length; i++){
|
|
if (i < separatorIndex) start += parts[i].value;
|
|
else if (i > separatorIndex) end += parts[i].value;
|
|
}
|
|
return {
|
|
start: start,
|
|
end: end
|
|
};
|
|
} catch (e) {
|
|
// ignore
|
|
}
|
|
endFormatter = startFormatter;
|
|
} else {
|
|
let endOptions = (0, $50d5d6a623389320$export$7e319ea407e63bc0)(fieldOptions, {
|
|
granularity: endGranularity,
|
|
timeZone: endTimeZone,
|
|
hideTimeZone: props.hideTimeZone,
|
|
hourCycle: props.hourCycle
|
|
});
|
|
endFormatter = new (0, $h2qOe$internationalizeddate.DateFormatter)(locale, endOptions);
|
|
}
|
|
return {
|
|
start: startFormatter.format(startDate),
|
|
end: endFormatter.format(endDate)
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
|
|
function $2654e87be0231a69$export$fd53cef0cc796101(props) {
|
|
let { placeholderValue: placeholderValue = new (0, $h2qOe$internationalizeddate.Time)(), minValue: minValue, maxValue: maxValue, granularity: granularity, validate: validate } = props;
|
|
let [value, setValue] = (0, $h2qOe$reactstatelyutils.useControlledState)(props.value, props.defaultValue, props.onChange);
|
|
let v = value || placeholderValue;
|
|
let day = v && "day" in v ? v : undefined;
|
|
let defaultValueTimeZone = props.defaultValue && "timeZone" in props.defaultValue ? props.defaultValue.timeZone : undefined;
|
|
let placeholderDate = (0, $h2qOe$react.useMemo)(()=>{
|
|
let valueTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
|
|
return (valueTimeZone || defaultValueTimeZone) && placeholderValue ? (0, $h2qOe$internationalizeddate.toZoned)($2654e87be0231a69$var$convertValue(placeholderValue), valueTimeZone || defaultValueTimeZone) : $2654e87be0231a69$var$convertValue(placeholderValue);
|
|
}, [
|
|
placeholderValue,
|
|
v,
|
|
defaultValueTimeZone
|
|
]);
|
|
let minDate = (0, $h2qOe$react.useMemo)(()=>$2654e87be0231a69$var$convertValue(minValue, day), [
|
|
minValue,
|
|
day
|
|
]);
|
|
let maxDate = (0, $h2qOe$react.useMemo)(()=>$2654e87be0231a69$var$convertValue(maxValue, day), [
|
|
maxValue,
|
|
day
|
|
]);
|
|
let timeValue = (0, $h2qOe$react.useMemo)(()=>value && "day" in value ? (0, $h2qOe$internationalizeddate.toTime)(value) : value, [
|
|
value
|
|
]);
|
|
let dateTime = (0, $h2qOe$react.useMemo)(()=>value == null ? null : $2654e87be0231a69$var$convertValue(value), [
|
|
value
|
|
]);
|
|
let onChange = (newValue)=>{
|
|
setValue(day || defaultValueTimeZone ? newValue : newValue && (0, $h2qOe$internationalizeddate.toTime)(newValue));
|
|
};
|
|
let state = (0, $596a1f0f523d6752$export$60e84778edff6d26)({
|
|
...props,
|
|
value: dateTime,
|
|
defaultValue: undefined,
|
|
minValue: minDate,
|
|
maxValue: maxDate,
|
|
onChange: onChange,
|
|
granularity: granularity || "minute",
|
|
maxGranularity: "hour",
|
|
placeholderValue: placeholderDate,
|
|
// Calendar should not matter for time fields.
|
|
createCalendar: ()=>new (0, $h2qOe$internationalizeddate.GregorianCalendar)(),
|
|
validate: (0, $h2qOe$react.useCallback)(()=>validate === null || validate === void 0 ? void 0 : validate(value), [
|
|
validate,
|
|
value
|
|
])
|
|
});
|
|
return {
|
|
...state,
|
|
timeValue: timeValue
|
|
};
|
|
}
|
|
function $2654e87be0231a69$var$convertValue(value, date = (0, $h2qOe$internationalizeddate.today)((0, $h2qOe$internationalizeddate.getLocalTimeZone)())) {
|
|
if (!value) return null;
|
|
if ("day" in value) return value;
|
|
return (0, $h2qOe$internationalizeddate.toCalendarDateTime)(date, value);
|
|
}
|
|
|
|
|
|
|
|
|
|
//# sourceMappingURL=main.js.map
|