2024-06-15 00:55:43 +03:00

806 lines
36 KiB
JavaScript

var $1fedb39dedbf7c51$exports = require("./ar-AE.main.js");
var $524ada6153e36bf5$exports = require("./bg-BG.main.js");
var $181053d31fc585a6$exports = require("./cs-CZ.main.js");
var $87f1f2ee75c25d27$exports = require("./da-DK.main.js");
var $3018d278e45fefcf$exports = require("./de-DE.main.js");
var $880b624ba6c377b6$exports = require("./el-GR.main.js");
var $6a7e3934431e9523$exports = require("./en-US.main.js");
var $4c458303ff44205c$exports = require("./es-ES.main.js");
var $4b6ec4ab19a96fff$exports = require("./et-EE.main.js");
var $a5184a366ed55e98$exports = require("./fi-FI.main.js");
var $094c11f0389b0f6c$exports = require("./fr-FR.main.js");
var $5b28c6b8eb99673e$exports = require("./he-IL.main.js");
var $519824243c1aad60$exports = require("./hr-HR.main.js");
var $2fde332abe847288$exports = require("./hu-HU.main.js");
var $b266f7fa452e8e83$exports = require("./it-IT.main.js");
var $3528fd03237947e3$exports = require("./ja-JP.main.js");
var $398f3b7902d2708f$exports = require("./ko-KR.main.js");
var $ebaae1c76687311e$exports = require("./lt-LT.main.js");
var $3ecb31d6694563f6$exports = require("./lv-LV.main.js");
var $26dc2e2c103f178c$exports = require("./nb-NO.main.js");
var $6bfd45b83a7d37dd$exports = require("./nl-NL.main.js");
var $6f70d036cac4bd46$exports = require("./pl-PL.main.js");
var $a227ce57c671783d$exports = require("./pt-BR.main.js");
var $97acad4758696d87$exports = require("./pt-PT.main.js");
var $010069c7d7fbbea3$exports = require("./ro-RO.main.js");
var $0ba9c30c48c8d602$exports = require("./ru-RU.main.js");
var $6873e95bd7af7559$exports = require("./sk-SK.main.js");
var $ce3c7852583668e3$exports = require("./sl-SI.main.js");
var $36cbdcce92af5213$exports = require("./sr-SP.main.js");
var $ce53fa032c8abdc9$exports = require("./sv-SE.main.js");
var $358703e281d51beb$exports = require("./tr-TR.main.js");
var $16bef71241a84fd2$exports = require("./uk-UA.main.js");
var $c80940728ad8dc0d$exports = require("./zh-CN.main.js");
var $ec192a5a83cfafeb$exports = require("./zh-TW.main.js");
var $jzHdg$reactarialiveannouncer = require("@react-aria/live-announcer");
var $jzHdg$reactariautils = require("@react-aria/utils");
var $jzHdg$reactariai18n = require("@react-aria/i18n");
var $jzHdg$react = require("react");
var $jzHdg$internationalizeddate = require("@internationalized/date");
var $jzHdg$reactariainteractions = require("@react-aria/interactions");
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, "useCalendar", () => $20e845123e697a89$export$3ee915f8151bd4f1);
$parcel$export(module.exports, "useRangeCalendar", () => $c49ada48cbc48220$export$87e0539f600c24e5);
$parcel$export(module.exports, "useCalendarGrid", () => $a07388a797d86b95$export$cb95147730a423f5);
$parcel$export(module.exports, "useCalendarCell", () => $4d833327a32c9193$export$136073280381448e);
/*
* 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.
*/
/*
* 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 $bd6dc95a3c5ee5cd$exports = {};
$bd6dc95a3c5ee5cd$exports = {
"ar-AE": $1fedb39dedbf7c51$exports,
"bg-BG": $524ada6153e36bf5$exports,
"cs-CZ": $181053d31fc585a6$exports,
"da-DK": $87f1f2ee75c25d27$exports,
"de-DE": $3018d278e45fefcf$exports,
"el-GR": $880b624ba6c377b6$exports,
"en-US": $6a7e3934431e9523$exports,
"es-ES": $4c458303ff44205c$exports,
"et-EE": $4b6ec4ab19a96fff$exports,
"fi-FI": $a5184a366ed55e98$exports,
"fr-FR": $094c11f0389b0f6c$exports,
"he-IL": $5b28c6b8eb99673e$exports,
"hr-HR": $519824243c1aad60$exports,
"hu-HU": $2fde332abe847288$exports,
"it-IT": $b266f7fa452e8e83$exports,
"ja-JP": $3528fd03237947e3$exports,
"ko-KR": $398f3b7902d2708f$exports,
"lt-LT": $ebaae1c76687311e$exports,
"lv-LV": $3ecb31d6694563f6$exports,
"nb-NO": $26dc2e2c103f178c$exports,
"nl-NL": $6bfd45b83a7d37dd$exports,
"pl-PL": $6f70d036cac4bd46$exports,
"pt-BR": $a227ce57c671783d$exports,
"pt-PT": $97acad4758696d87$exports,
"ro-RO": $010069c7d7fbbea3$exports,
"ru-RU": $0ba9c30c48c8d602$exports,
"sk-SK": $6873e95bd7af7559$exports,
"sl-SI": $ce3c7852583668e3$exports,
"sr-SP": $36cbdcce92af5213$exports,
"sv-SE": $ce53fa032c8abdc9$exports,
"tr-TR": $358703e281d51beb$exports,
"uk-UA": $16bef71241a84fd2$exports,
"zh-CN": $c80940728ad8dc0d$exports,
"zh-TW": $ec192a5a83cfafeb$exports
};
const $df1d8e967e73ec8e$export$653eddfc964b0f8a = new WeakMap();
function $df1d8e967e73ec8e$export$134cbb7fb09a9522(date) {
return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : undefined;
}
function $df1d8e967e73ec8e$export$b6df97c887c38e1a(state) {
let stringFormatter = (0, $jzHdg$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
let start, end;
if ("highlightedRange" in state) ({ start: start, end: end } = state.highlightedRange || {});
else start = end = state.value;
let dateFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
weekday: "long",
month: "long",
year: "numeric",
day: "numeric",
era: $df1d8e967e73ec8e$export$134cbb7fb09a9522(start) || $df1d8e967e73ec8e$export$134cbb7fb09a9522(end),
timeZone: state.timeZone
});
let anchorDate = "anchorDate" in state ? state.anchorDate : null;
return (0, $jzHdg$react.useMemo)(()=>{
// No message if currently selecting a range, or there is nothing highlighted.
if (!anchorDate && start && end) {
// Use a single date message if the start and end dates are the same day,
// otherwise include both dates.
if ((0, $jzHdg$internationalizeddate.isSameDay)(start, end)) {
let date = dateFormatter.format(start.toDate(state.timeZone));
return stringFormatter.format("selectedDateDescription", {
date: date
});
} else {
let dateRange = $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
return stringFormatter.format("selectedRangeDescription", {
dateRange: dateRange
});
}
}
return "";
}, [
start,
end,
anchorDate,
state.timeZone,
stringFormatter,
dateFormatter
]);
}
function $df1d8e967e73ec8e$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
let stringFormatter = (0, $jzHdg$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
let era = $df1d8e967e73ec8e$export$134cbb7fb09a9522(startDate) || $df1d8e967e73ec8e$export$134cbb7fb09a9522(endDate);
let monthFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
month: "long",
year: "numeric",
era: era,
calendar: startDate.calendar.identifier,
timeZone: timeZone
});
let dateFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
month: "long",
year: "numeric",
day: "numeric",
era: era,
calendar: startDate.calendar.identifier,
timeZone: timeZone
});
return (0, $jzHdg$react.useMemo)(()=>{
// Special case for month granularity. Format as a single month if only a
// single month is visible, otherwise format as a range of months.
if ((0, $jzHdg$internationalizeddate.isSameDay)(startDate, (0, $jzHdg$internationalizeddate.startOfMonth)(startDate))) {
if ((0, $jzHdg$internationalizeddate.isSameDay)(endDate, (0, $jzHdg$internationalizeddate.endOfMonth)(startDate))) return monthFormatter.format(startDate.toDate(timeZone));
else if ((0, $jzHdg$internationalizeddate.isSameDay)(endDate, (0, $jzHdg$internationalizeddate.endOfMonth)(endDate))) return isAria ? $df1d8e967e73ec8e$var$formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone) : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
}
return isAria ? $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
}, [
startDate,
endDate,
monthFormatter,
dateFormatter,
stringFormatter,
timeZone,
isAria
]);
}
function $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, start, end, timeZone) {
let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));
// 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 startValue = "";
let endValue = "";
for(let i = 0; i < parts.length; i++){
if (i < separatorIndex) startValue += parts[i].value;
else if (i > separatorIndex) endValue += parts[i].value;
}
return stringFormatter.format("dateRange", {
startDate: startValue,
endDate: endValue
});
}
function $02ef492a56b91cb2$export$d652b3ea2d672d5b(props, state) {
let stringFormatter = (0, $jzHdg$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
let domProps = (0, $jzHdg$reactariautils.filterDOMProps)(props);
let title = (0, $df1d8e967e73ec8e$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);
let visibleRangeDescription = (0, $df1d8e967e73ec8e$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, true);
// Announce when the visible date range changes
(0, $jzHdg$reactariautils.useUpdateEffect)(()=>{
// only when pressing the Previous or Next button
if (!state.isFocused) (0, $jzHdg$reactarialiveannouncer.announce)(visibleRangeDescription);
}, [
visibleRangeDescription
]);
// Announce when the selected value changes
let selectedDateDescription = (0, $df1d8e967e73ec8e$export$b6df97c887c38e1a)(state);
(0, $jzHdg$reactariautils.useUpdateEffect)(()=>{
if (selectedDateDescription) (0, $jzHdg$reactarialiveannouncer.announce)(selectedDateDescription, "polite", 4000);
// handle an update to the caption that describes the currently selected range, to announce the new value
}, [
selectedDateDescription
]);
let errorMessageId = (0, $jzHdg$reactariautils.useSlotId)([
Boolean(props.errorMessage),
props.isInvalid,
props.validationState
]);
// Pass the label to the child grid elements.
(0, $df1d8e967e73ec8e$export$653eddfc964b0f8a).set(state, {
ariaLabel: props["aria-label"],
ariaLabelledBy: props["aria-labelledby"],
errorMessageId: errorMessageId,
selectedDateDescription: selectedDateDescription
});
// If the next or previous buttons become disabled while they are focused, move focus to the calendar body.
let [nextFocused, setNextFocused] = (0, $jzHdg$react.useState)(false);
let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();
if (nextDisabled && nextFocused) {
setNextFocused(false);
state.setFocused(true);
}
let [previousFocused, setPreviousFocused] = (0, $jzHdg$react.useState)(false);
let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();
if (previousDisabled && previousFocused) {
setPreviousFocused(false);
state.setFocused(true);
}
let labelProps = (0, $jzHdg$reactariautils.useLabels)({
id: props["id"],
"aria-label": [
props["aria-label"],
visibleRangeDescription
].filter(Boolean).join(", "),
"aria-labelledby": props["aria-labelledby"]
});
return {
calendarProps: (0, $jzHdg$reactariautils.mergeProps)(domProps, labelProps, {
role: "application",
"aria-describedby": props["aria-describedby"] || undefined
}),
nextButtonProps: {
onPress: ()=>state.focusNextPage(),
"aria-label": stringFormatter.format("next"),
isDisabled: nextDisabled,
onFocusChange: setNextFocused
},
prevButtonProps: {
onPress: ()=>state.focusPreviousPage(),
"aria-label": stringFormatter.format("previous"),
isDisabled: previousDisabled,
onFocusChange: setPreviousFocused
},
errorMessageProps: {
id: errorMessageId
},
title: title
};
}
function $20e845123e697a89$export$3ee915f8151bd4f1(props, state) {
return (0, $02ef492a56b91cb2$export$d652b3ea2d672d5b)(props, state);
}
/*
* 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 $c49ada48cbc48220$export$87e0539f600c24e5(props, state, ref) {
let res = (0, $02ef492a56b91cb2$export$d652b3ea2d672d5b)(props, state);
// We need to ignore virtual pointer events from VoiceOver due to these bugs.
// https://bugs.webkit.org/show_bug.cgi?id=222627
// https://bugs.webkit.org/show_bug.cgi?id=223202
// usePress also does this and waits for the following click event before firing.
// We need to match that here otherwise this will fire before the press event in
// useCalendarCell, causing range selection to not work properly.
let isVirtualClick = (0, $jzHdg$react.useRef)(false);
let windowRef = (0, $jzHdg$react.useRef)(typeof window !== "undefined" ? window : null);
(0, $jzHdg$reactariautils.useEvent)(windowRef, "pointerdown", (e)=>{
isVirtualClick.current = e.width === 0 && e.height === 0;
});
// Stop range selection when pressing or releasing a pointer outside the calendar body,
// except when pressing the next or previous buttons to switch months.
let endDragging = (e)=>{
if (isVirtualClick.current) {
isVirtualClick.current = false;
return;
}
state.setDragging(false);
if (!state.anchorDate) return;
let target = e.target;
let body = document.getElementById(res.calendarProps.id);
if (body && body.contains(document.activeElement) && (!body.contains(target) || !target.closest('button, [role="button"]'))) state.selectFocusedDate();
};
(0, $jzHdg$reactariautils.useEvent)(windowRef, "pointerup", endDragging);
(0, $jzHdg$reactariautils.useEvent)(windowRef, "pointercancel", endDragging);
// Also stop range selection on blur, e.g. tabbing away from the calendar.
res.calendarProps.onBlur = (e)=>{
if ((!e.relatedTarget || !ref.current.contains(e.relatedTarget)) && state.anchorDate) state.selectFocusedDate();
};
// Prevent touch scrolling while dragging
(0, $jzHdg$reactariautils.useEvent)(ref, "touchmove", (e)=>{
if (state.isDragging) e.preventDefault();
}, {
passive: false,
capture: true
});
return res;
}
/*
* 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 $a07388a797d86b95$export$cb95147730a423f5(props, state) {
let { startDate: startDate = state.visibleRange.start, endDate: endDate = state.visibleRange.end } = props;
let { direction: direction } = (0, $jzHdg$reactariai18n.useLocale)();
let onKeyDown = (e)=>{
switch(e.key){
case "Enter":
case " ":
e.preventDefault();
state.selectFocusedDate();
break;
case "PageUp":
e.preventDefault();
e.stopPropagation();
state.focusPreviousSection(e.shiftKey);
break;
case "PageDown":
e.preventDefault();
e.stopPropagation();
state.focusNextSection(e.shiftKey);
break;
case "End":
e.preventDefault();
e.stopPropagation();
state.focusSectionEnd();
break;
case "Home":
e.preventDefault();
e.stopPropagation();
state.focusSectionStart();
break;
case "ArrowLeft":
e.preventDefault();
e.stopPropagation();
if (direction === "rtl") state.focusNextDay();
else state.focusPreviousDay();
break;
case "ArrowUp":
e.preventDefault();
e.stopPropagation();
state.focusPreviousRow();
break;
case "ArrowRight":
e.preventDefault();
e.stopPropagation();
if (direction === "rtl") state.focusPreviousDay();
else state.focusNextDay();
break;
case "ArrowDown":
e.preventDefault();
e.stopPropagation();
state.focusNextRow();
break;
case "Escape":
// Cancel the selection.
if ("setAnchorDate" in state) {
e.preventDefault();
state.setAnchorDate(null);
}
break;
}
};
let visibleRangeDescription = (0, $df1d8e967e73ec8e$export$31afe65d91ef6e8)(startDate, endDate, state.timeZone, true);
let { ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy } = (0, $df1d8e967e73ec8e$export$653eddfc964b0f8a).get(state);
let labelProps = (0, $jzHdg$reactariautils.useLabels)({
"aria-label": [
ariaLabel,
visibleRangeDescription
].filter(Boolean).join(", "),
"aria-labelledby": ariaLabelledBy
});
let dayFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
weekday: props.weekdayStyle || "narrow",
timeZone: state.timeZone
});
let { locale: locale } = (0, $jzHdg$reactariai18n.useLocale)();
let weekDays = (0, $jzHdg$react.useMemo)(()=>{
let weekStart = (0, $jzHdg$internationalizeddate.startOfWeek)((0, $jzHdg$internationalizeddate.today)(state.timeZone), locale);
return [
...new Array(7).keys()
].map((index)=>{
let date = weekStart.add({
days: index
});
let dateDay = date.toDate(state.timeZone);
return dayFormatter.format(dateDay);
});
}, [
locale,
state.timeZone,
dayFormatter
]);
return {
gridProps: (0, $jzHdg$reactariautils.mergeProps)(labelProps, {
role: "grid",
"aria-readonly": state.isReadOnly || null,
"aria-disabled": state.isDisabled || null,
"aria-multiselectable": "highlightedRange" in state || undefined,
onKeyDown: onKeyDown,
onFocus: ()=>state.setFocused(true),
onBlur: ()=>state.setFocused(false)
}),
headerProps: {
// Column headers are hidden to screen readers to make navigating with a touch screen reader easier.
// The day names are already included in the label of each cell, so there's no need to announce them twice.
"aria-hidden": true
},
weekDays: weekDays
};
}
/*
* 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 $4d833327a32c9193$export$136073280381448e(props, state, ref) {
let { date: date, isDisabled: isDisabled } = props;
let { errorMessageId: errorMessageId, selectedDateDescription: selectedDateDescription } = (0, $df1d8e967e73ec8e$export$653eddfc964b0f8a).get(state);
let stringFormatter = (0, $jzHdg$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($bd6dc95a3c5ee5cd$exports))), "@react-aria/calendar");
let dateFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
weekday: "long",
day: "numeric",
month: "long",
year: "numeric",
era: (0, $df1d8e967e73ec8e$export$134cbb7fb09a9522)(date),
timeZone: state.timeZone
});
let isSelected = state.isSelected(date);
let isFocused = state.isCellFocused(date);
isDisabled = isDisabled || state.isCellDisabled(date);
let isUnavailable = state.isCellUnavailable(date);
let isSelectable = !isDisabled && !isUnavailable;
let isInvalid = state.isValueInvalid && ("highlightedRange" in state ? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0 : state.value && (0, $jzHdg$internationalizeddate.isSameDay)(state.value, date));
if (isInvalid) isSelected = true;
// For performance, reuse the same date object as before if the new date prop is the same.
// This allows subsequent useMemo results to be reused.
date = (0, $jzHdg$reactariautils.useDeepMemo)(date, (0, $jzHdg$internationalizeddate.isEqualDay));
let nativeDate = (0, $jzHdg$react.useMemo)(()=>date.toDate(state.timeZone), [
date,
state.timeZone
]);
// aria-label should be localize Day of week, Month, Day and Year without Time.
let isDateToday = (0, $jzHdg$internationalizeddate.isToday)(date, state.timeZone);
let label = (0, $jzHdg$react.useMemo)(()=>{
let label = "";
// If this is a range calendar, add a description of the full selected range
// to the first and last selected date.
if ("highlightedRange" in state && state.value && !state.anchorDate && ((0, $jzHdg$internationalizeddate.isSameDay)(date, state.value.start) || (0, $jzHdg$internationalizeddate.isSameDay)(date, state.value.end))) label = selectedDateDescription + ", ";
label += dateFormatter.format(nativeDate);
if (isDateToday) // If date is today, set appropriate string depending on selected state:
label = stringFormatter.format(isSelected ? "todayDateSelected" : "todayDate", {
date: label
});
else if (isSelected) // If date is selected but not today:
label = stringFormatter.format("dateSelected", {
date: label
});
if (state.minValue && (0, $jzHdg$internationalizeddate.isSameDay)(date, state.minValue)) label += ", " + stringFormatter.format("minimumDate");
else if (state.maxValue && (0, $jzHdg$internationalizeddate.isSameDay)(date, state.maxValue)) label += ", " + stringFormatter.format("maximumDate");
return label;
}, [
dateFormatter,
nativeDate,
stringFormatter,
isSelected,
isDateToday,
date,
state,
selectedDateDescription
]);
// When a cell is focused and this is a range calendar, add a prompt to help
// screenreader users know that they are in a range selection mode.
let rangeSelectionPrompt = "";
if ("anchorDate" in state && isFocused && !state.isReadOnly && isSelectable) {
// If selection has started add "click to finish selecting range"
if (state.anchorDate) rangeSelectionPrompt = stringFormatter.format("finishRangeSelectionPrompt");
else rangeSelectionPrompt = stringFormatter.format("startRangeSelectionPrompt");
}
let descriptionProps = (0, $jzHdg$reactariautils.useDescription)(rangeSelectionPrompt);
let isAnchorPressed = (0, $jzHdg$react.useRef)(false);
let isRangeBoundaryPressed = (0, $jzHdg$react.useRef)(false);
let touchDragTimerRef = (0, $jzHdg$react.useRef)(null);
let { pressProps: pressProps, isPressed: isPressed } = (0, $jzHdg$reactariainteractions.usePress)({
// When dragging to select a range, we don't want dragging over the original anchor
// again to trigger onPressStart. Cancel presses immediately when the pointer exits.
shouldCancelOnPointerExit: "anchorDate" in state && !!state.anchorDate,
preventFocusOnPress: true,
isDisabled: !isSelectable || state.isReadOnly,
onPressStart (e) {
if (state.isReadOnly) {
state.setFocusedDate(date);
return;
}
if ("highlightedRange" in state && !state.anchorDate && (e.pointerType === "mouse" || e.pointerType === "touch")) {
// Allow dragging the start or end date of a range to modify it
// rather than starting a new selection.
// Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges
// are constrained to available dates. The user will need to select a new range in this case.
if (state.highlightedRange && !isInvalid) {
if ((0, $jzHdg$internationalizeddate.isSameDay)(date, state.highlightedRange.start)) {
state.setAnchorDate(state.highlightedRange.end);
state.setFocusedDate(date);
state.setDragging(true);
isRangeBoundaryPressed.current = true;
return;
} else if ((0, $jzHdg$internationalizeddate.isSameDay)(date, state.highlightedRange.end)) {
state.setAnchorDate(state.highlightedRange.start);
state.setFocusedDate(date);
state.setDragging(true);
isRangeBoundaryPressed.current = true;
return;
}
}
let startDragging = ()=>{
state.setDragging(true);
touchDragTimerRef.current = null;
state.selectDate(date);
state.setFocusedDate(date);
isAnchorPressed.current = true;
};
// Start selection on mouse/touch down so users can drag to select a range.
// On touch, delay dragging to determine if the user really meant to scroll.
if (e.pointerType === "touch") touchDragTimerRef.current = setTimeout(startDragging, 200);
else startDragging();
}
},
onPressEnd () {
isRangeBoundaryPressed.current = false;
isAnchorPressed.current = false;
clearTimeout(touchDragTimerRef.current);
touchDragTimerRef.current = null;
},
onPress () {
// For non-range selection, always select on press up.
if (!("anchorDate" in state) && !state.isReadOnly) {
state.selectDate(date);
state.setFocusedDate(date);
}
},
onPressUp (e) {
if (state.isReadOnly) return;
// If the user tapped quickly, the date won't be selected yet and the
// timer will still be in progress. In this case, select the date on touch up.
// Timer is cleared in onPressEnd.
if ("anchorDate" in state && touchDragTimerRef.current) {
state.selectDate(date);
state.setFocusedDate(date);
}
if ("anchorDate" in state) {
if (isRangeBoundaryPressed.current) // When clicking on the start or end date of an already selected range,
// start a new selection on press up to also allow dragging the date to
// change the existing range.
state.setAnchorDate(date);
else if (state.anchorDate && !isAnchorPressed.current) {
// When releasing a drag or pressing the end date of a range, select it.
state.selectDate(date);
state.setFocusedDate(date);
} else if (e.pointerType === "keyboard" && !state.anchorDate) {
// For range selection, auto-advance the focused date by one if using keyboard.
// This gives an indication that you're selecting a range rather than a single date.
// For mouse, this is unnecessary because users will see the indication on hover. For screen readers,
// there will be an announcement to "click to finish selecting range" (above).
state.selectDate(date);
let nextDay = date.add({
days: 1
});
if (state.isInvalid(nextDay)) nextDay = date.subtract({
days: 1
});
if (!state.isInvalid(nextDay)) state.setFocusedDate(nextDay);
} else if (e.pointerType === "virtual") {
// For screen readers, just select the date on click.
state.selectDate(date);
state.setFocusedDate(date);
}
}
}
});
let tabIndex = null;
if (!isDisabled) tabIndex = (0, $jzHdg$internationalizeddate.isSameDay)(date, state.focusedDate) ? 0 : -1;
// Focus the button in the DOM when the state updates.
(0, $jzHdg$react.useEffect)(()=>{
if (isFocused && ref.current) {
(0, $jzHdg$reactariautils.focusWithoutScrolling)(ref.current);
// Scroll into view if navigating with a keyboard, otherwise
// try not to shift the view under the user's mouse/finger.
// If in a overlay, scrollIntoViewport will only cause scrolling
// up to the overlay scroll body to prevent overlay shifting.
// Also only scroll into view if the cell actually got focused.
// There are some cases where the cell might be disabled or inside,
// an inert container and we don't want to scroll then.
if ((0, $jzHdg$reactariainteractions.getInteractionModality)() !== "pointer" && document.activeElement === ref.current) (0, $jzHdg$reactariautils.scrollIntoViewport)(ref.current, {
containingElement: (0, $jzHdg$reactariautils.getScrollParent)(ref.current)
});
}
}, [
isFocused,
ref
]);
let cellDateFormatter = (0, $jzHdg$reactariai18n.useDateFormatter)({
day: "numeric",
timeZone: state.timeZone,
calendar: date.calendar.identifier
});
let formattedDate = (0, $jzHdg$react.useMemo)(()=>cellDateFormatter.formatToParts(nativeDate).find((part)=>part.type === "day").value, [
cellDateFormatter,
nativeDate
]);
return {
cellProps: {
role: "gridcell",
"aria-disabled": !isSelectable || null,
"aria-selected": isSelected || null,
"aria-invalid": isInvalid || null
},
buttonProps: (0, $jzHdg$reactariautils.mergeProps)(pressProps, {
onFocus () {
if (!isDisabled) state.setFocusedDate(date);
},
tabIndex: tabIndex,
role: "button",
"aria-disabled": !isSelectable || null,
"aria-label": label,
"aria-invalid": isInvalid || null,
"aria-describedby": [
isInvalid ? errorMessageId : null,
descriptionProps["aria-describedby"]
].filter(Boolean).join(" ") || undefined,
onPointerEnter (e) {
// Highlight the date on hover or drag over a date when selecting a range.
if ("highlightDate" in state && (e.pointerType !== "touch" || state.isDragging) && isSelectable) state.highlightDate(date);
},
onPointerDown (e) {
// This is necessary on touch devices to allow dragging
// outside the original pressed element.
// (JSDOM does not support this)
if ("releasePointerCapture" in e.target) e.target.releasePointerCapture(e.pointerId);
},
onContextMenu (e) {
// Prevent context menu on long press.
e.preventDefault();
}
}),
isPressed: isPressed,
isFocused: isFocused,
isSelected: isSelected,
isDisabled: isDisabled,
isUnavailable: isUnavailable,
isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,
isInvalid: isInvalid,
formattedDate: formattedDate
};
}
//# sourceMappingURL=main.js.map