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

798 lines
36 KiB
JavaScript

import $39324ace0d945f59$exports from "./ar-AE.module.js";
import $1830a539e98c7baf$exports from "./bg-BG.module.js";
import $f4b92528965aab97$exports from "./cs-CZ.module.js";
import $1cd578ef0547c8f1$exports from "./da-DK.module.js";
import $db55a8973925d619$exports from "./de-DE.module.js";
import $ec6937d58566d443$exports from "./el-GR.module.js";
import $1f5cea0742dc284a$exports from "./en-US.module.js";
import $2ca7ea366384817b$exports from "./es-ES.module.js";
import $97874a7fe9cd091f$exports from "./et-EE.module.js";
import $5d376b7fce1a45b2$exports from "./fi-FI.module.js";
import $3bf722b362aaf54d$exports from "./fr-FR.module.js";
import $38c43f8322316031$exports from "./he-IL.module.js";
import $c90e0f32b44630bf$exports from "./hr-HR.module.js";
import $715875e6e7a338f4$exports from "./hu-HU.module.js";
import $37d77c66e34daccf$exports from "./it-IT.module.js";
import $542f39aee29303c3$exports from "./ja-JP.module.js";
import $22a5f0623ea73e4f$exports from "./ko-KR.module.js";
import $522380d13d62cba0$exports from "./lt-LT.module.js";
import $8a7bc830b2fe6485$exports from "./lv-LV.module.js";
import $9fac9c044470683b$exports from "./nb-NO.module.js";
import $b127d3569efb1449$exports from "./nl-NL.module.js";
import $51404a4090633490$exports from "./pl-PL.module.js";
import $e5e6a3fe3b4527df$exports from "./pt-BR.module.js";
import $c519dcadcbb1ee47$exports from "./pt-PT.module.js";
import $e5aa0186ca7889c6$exports from "./ro-RO.module.js";
import $5b907f5fa3eee652$exports from "./ru-RU.module.js";
import $1b4c51359c99cf79$exports from "./sk-SK.module.js";
import $02e4e6a4608cc6f3$exports from "./sl-SI.module.js";
import $6dd2fbaad93b6878$exports from "./sr-SP.module.js";
import $33ea59bfe6e804e0$exports from "./sv-SE.module.js";
import $4603b0d0246969b2$exports from "./tr-TR.module.js";
import $82649816f530bb1b$exports from "./uk-UA.module.js";
import $628e140a43dfb330$exports from "./zh-CN.module.js";
import $745937250cd4679c$exports from "./zh-TW.module.js";
import {announce as $amWdn$announce} from "@react-aria/live-announcer";
import {filterDOMProps as $amWdn$filterDOMProps, useUpdateEffect as $amWdn$useUpdateEffect, useSlotId as $amWdn$useSlotId, useLabels as $amWdn$useLabels, mergeProps as $amWdn$mergeProps, useEvent as $amWdn$useEvent, useDeepMemo as $amWdn$useDeepMemo, useDescription as $amWdn$useDescription, focusWithoutScrolling as $amWdn$focusWithoutScrolling, scrollIntoViewport as $amWdn$scrollIntoViewport, getScrollParent as $amWdn$getScrollParent} from "@react-aria/utils";
import {useLocalizedStringFormatter as $amWdn$useLocalizedStringFormatter, useDateFormatter as $amWdn$useDateFormatter, useLocale as $amWdn$useLocale} from "@react-aria/i18n";
import {useState as $amWdn$useState, useMemo as $amWdn$useMemo, useRef as $amWdn$useRef, useEffect as $amWdn$useEffect} from "react";
import {isSameDay as $amWdn$isSameDay, startOfMonth as $amWdn$startOfMonth, endOfMonth as $amWdn$endOfMonth, startOfWeek as $amWdn$startOfWeek, today as $amWdn$today, isEqualDay as $amWdn$isEqualDay, isToday as $amWdn$isToday} from "@internationalized/date";
import {usePress as $amWdn$usePress, getInteractionModality as $amWdn$getInteractionModality} from "@react-aria/interactions";
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
/*
* 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 $3904726b442bd9b2$exports = {};
$3904726b442bd9b2$exports = {
"ar-AE": $39324ace0d945f59$exports,
"bg-BG": $1830a539e98c7baf$exports,
"cs-CZ": $f4b92528965aab97$exports,
"da-DK": $1cd578ef0547c8f1$exports,
"de-DE": $db55a8973925d619$exports,
"el-GR": $ec6937d58566d443$exports,
"en-US": $1f5cea0742dc284a$exports,
"es-ES": $2ca7ea366384817b$exports,
"et-EE": $97874a7fe9cd091f$exports,
"fi-FI": $5d376b7fce1a45b2$exports,
"fr-FR": $3bf722b362aaf54d$exports,
"he-IL": $38c43f8322316031$exports,
"hr-HR": $c90e0f32b44630bf$exports,
"hu-HU": $715875e6e7a338f4$exports,
"it-IT": $37d77c66e34daccf$exports,
"ja-JP": $542f39aee29303c3$exports,
"ko-KR": $22a5f0623ea73e4f$exports,
"lt-LT": $522380d13d62cba0$exports,
"lv-LV": $8a7bc830b2fe6485$exports,
"nb-NO": $9fac9c044470683b$exports,
"nl-NL": $b127d3569efb1449$exports,
"pl-PL": $51404a4090633490$exports,
"pt-BR": $e5e6a3fe3b4527df$exports,
"pt-PT": $c519dcadcbb1ee47$exports,
"ro-RO": $e5aa0186ca7889c6$exports,
"ru-RU": $5b907f5fa3eee652$exports,
"sk-SK": $1b4c51359c99cf79$exports,
"sl-SI": $02e4e6a4608cc6f3$exports,
"sr-SP": $6dd2fbaad93b6878$exports,
"sv-SE": $33ea59bfe6e804e0$exports,
"tr-TR": $4603b0d0246969b2$exports,
"uk-UA": $82649816f530bb1b$exports,
"zh-CN": $628e140a43dfb330$exports,
"zh-TW": $745937250cd4679c$exports
};
const $a074e1e2d0f0a665$export$653eddfc964b0f8a = new WeakMap();
function $a074e1e2d0f0a665$export$134cbb7fb09a9522(date) {
return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : undefined;
}
function $a074e1e2d0f0a665$export$b6df97c887c38e1a(state) {
let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$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, $amWdn$useDateFormatter)({
weekday: "long",
month: "long",
year: "numeric",
day: "numeric",
era: $a074e1e2d0f0a665$export$134cbb7fb09a9522(start) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(end),
timeZone: state.timeZone
});
let anchorDate = "anchorDate" in state ? state.anchorDate : null;
return (0, $amWdn$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, $amWdn$isSameDay)(start, end)) {
let date = dateFormatter.format(start.toDate(state.timeZone));
return stringFormatter.format("selectedDateDescription", {
date: date
});
} else {
let dateRange = $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
return stringFormatter.format("selectedRangeDescription", {
dateRange: dateRange
});
}
}
return "";
}, [
start,
end,
anchorDate,
state.timeZone,
stringFormatter,
dateFormatter
]);
}
function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))), "@react-aria/calendar");
let era = $a074e1e2d0f0a665$export$134cbb7fb09a9522(startDate) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(endDate);
let monthFormatter = (0, $amWdn$useDateFormatter)({
month: "long",
year: "numeric",
era: era,
calendar: startDate.calendar.identifier,
timeZone: timeZone
});
let dateFormatter = (0, $amWdn$useDateFormatter)({
month: "long",
year: "numeric",
day: "numeric",
era: era,
calendar: startDate.calendar.identifier,
timeZone: timeZone
});
return (0, $amWdn$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, $amWdn$isSameDay)(startDate, (0, $amWdn$startOfMonth)(startDate))) {
if ((0, $amWdn$isSameDay)(endDate, (0, $amWdn$endOfMonth)(startDate))) return monthFormatter.format(startDate.toDate(timeZone));
else if ((0, $amWdn$isSameDay)(endDate, (0, $amWdn$endOfMonth)(endDate))) return isAria ? $a074e1e2d0f0a665$var$formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone) : monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
}
return isAria ? $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
}, [
startDate,
endDate,
monthFormatter,
dateFormatter,
stringFormatter,
timeZone,
isAria
]);
}
function $a074e1e2d0f0a665$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 $c4acc1de3ab169cf$export$d652b3ea2d672d5b(props, state) {
let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))), "@react-aria/calendar");
let domProps = (0, $amWdn$filterDOMProps)(props);
let title = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);
let visibleRangeDescription = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, true);
// Announce when the visible date range changes
(0, $amWdn$useUpdateEffect)(()=>{
// only when pressing the Previous or Next button
if (!state.isFocused) (0, $amWdn$announce)(visibleRangeDescription);
}, [
visibleRangeDescription
]);
// Announce when the selected value changes
let selectedDateDescription = (0, $a074e1e2d0f0a665$export$b6df97c887c38e1a)(state);
(0, $amWdn$useUpdateEffect)(()=>{
if (selectedDateDescription) (0, $amWdn$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, $amWdn$useSlotId)([
Boolean(props.errorMessage),
props.isInvalid,
props.validationState
]);
// Pass the label to the child grid elements.
(0, $a074e1e2d0f0a665$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, $amWdn$useState)(false);
let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();
if (nextDisabled && nextFocused) {
setNextFocused(false);
state.setFocused(true);
}
let [previousFocused, setPreviousFocused] = (0, $amWdn$useState)(false);
let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();
if (previousDisabled && previousFocused) {
setPreviousFocused(false);
state.setFocused(true);
}
let labelProps = (0, $amWdn$useLabels)({
id: props["id"],
"aria-label": [
props["aria-label"],
visibleRangeDescription
].filter(Boolean).join(", "),
"aria-labelledby": props["aria-labelledby"]
});
return {
calendarProps: (0, $amWdn$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 $9942cad8a072a530$export$3ee915f8151bd4f1(props, state) {
return (0, $c4acc1de3ab169cf$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 $46a4342aab3d8076$export$87e0539f600c24e5(props, state, ref) {
let res = (0, $c4acc1de3ab169cf$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, $amWdn$useRef)(false);
let windowRef = (0, $amWdn$useRef)(typeof window !== "undefined" ? window : null);
(0, $amWdn$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, $amWdn$useEvent)(windowRef, "pointerup", endDragging);
(0, $amWdn$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, $amWdn$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 $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
let { startDate: startDate = state.visibleRange.start, endDate: endDate = state.visibleRange.end } = props;
let { direction: direction } = (0, $amWdn$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, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(startDate, endDate, state.timeZone, true);
let { ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy } = (0, $a074e1e2d0f0a665$export$653eddfc964b0f8a).get(state);
let labelProps = (0, $amWdn$useLabels)({
"aria-label": [
ariaLabel,
visibleRangeDescription
].filter(Boolean).join(", "),
"aria-labelledby": ariaLabelledBy
});
let dayFormatter = (0, $amWdn$useDateFormatter)({
weekday: props.weekdayStyle || "narrow",
timeZone: state.timeZone
});
let { locale: locale } = (0, $amWdn$useLocale)();
let weekDays = (0, $amWdn$useMemo)(()=>{
let weekStart = (0, $amWdn$startOfWeek)((0, $amWdn$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, $amWdn$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 $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
let { date: date, isDisabled: isDisabled } = props;
let { errorMessageId: errorMessageId, selectedDateDescription: selectedDateDescription } = (0, $a074e1e2d0f0a665$export$653eddfc964b0f8a).get(state);
let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))), "@react-aria/calendar");
let dateFormatter = (0, $amWdn$useDateFormatter)({
weekday: "long",
day: "numeric",
month: "long",
year: "numeric",
era: (0, $a074e1e2d0f0a665$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, $amWdn$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, $amWdn$useDeepMemo)(date, (0, $amWdn$isEqualDay));
let nativeDate = (0, $amWdn$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, $amWdn$isToday)(date, state.timeZone);
let label = (0, $amWdn$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, $amWdn$isSameDay)(date, state.value.start) || (0, $amWdn$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, $amWdn$isSameDay)(date, state.minValue)) label += ", " + stringFormatter.format("minimumDate");
else if (state.maxValue && (0, $amWdn$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, $amWdn$useDescription)(rangeSelectionPrompt);
let isAnchorPressed = (0, $amWdn$useRef)(false);
let isRangeBoundaryPressed = (0, $amWdn$useRef)(false);
let touchDragTimerRef = (0, $amWdn$useRef)(null);
let { pressProps: pressProps, isPressed: isPressed } = (0, $amWdn$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, $amWdn$isSameDay)(date, state.highlightedRange.start)) {
state.setAnchorDate(state.highlightedRange.end);
state.setFocusedDate(date);
state.setDragging(true);
isRangeBoundaryPressed.current = true;
return;
} else if ((0, $amWdn$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, $amWdn$isSameDay)(date, state.focusedDate) ? 0 : -1;
// Focus the button in the DOM when the state updates.
(0, $amWdn$useEffect)(()=>{
if (isFocused && ref.current) {
(0, $amWdn$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, $amWdn$getInteractionModality)() !== "pointer" && document.activeElement === ref.current) (0, $amWdn$scrollIntoViewport)(ref.current, {
containingElement: (0, $amWdn$getScrollParent)(ref.current)
});
}
}, [
isFocused,
ref
]);
let cellDateFormatter = (0, $amWdn$useDateFormatter)({
day: "numeric",
timeZone: state.timeZone,
calendar: date.calendar.identifier
});
let formattedDate = (0, $amWdn$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, $amWdn$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
};
}
export {$9942cad8a072a530$export$3ee915f8151bd4f1 as useCalendar, $46a4342aab3d8076$export$87e0539f600c24e5 as useRangeCalendar, $e3031d1f8c9d64eb$export$cb95147730a423f5 as useCalendarGrid, $36a0ac60f04457c5$export$136073280381448e as useCalendarCell};
//# sourceMappingURL=module.js.map