@react-stately/calendar
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.3
156
dist/main.js
@@ -1,5 +0,5 @@ | ||
var $8fZ0X$internationalizeddate = require("@internationalized/date"); | ||
var $8fZ0X$reactstatelyutils = require("@react-stately/utils"); | ||
var $8fZ0X$reactariai18n = require("@react-aria/i18n"); | ||
var $8fZ0X$react = require("react"); | ||
var $9X5tg$internationalizeddate = require("@internationalized/date"); | ||
var $9X5tg$reactstatelyutils = require("@react-stately/utils"); | ||
var $9X5tg$reactariai18n = require("@react-aria/i18n"); | ||
var $9X5tg$react = require("react"); | ||
@@ -25,13 +25,13 @@ function $parcel$exportWildcard(dest, source) { | ||
} | ||
var $b6932658840cac06$exports = {}; | ||
var $2685e11fe2f22aa6$exports = {}; | ||
var $f61c34523ac023ce$exports = {}; | ||
var $5270e0b8e8740a4c$exports = {}; | ||
$parcel$export($f61c34523ac023ce$exports, "useCalendarState", () => $f61c34523ac023ce$export$6d095e787d2b5e1f); | ||
$parcel$export($5270e0b8e8740a4c$exports, "useCalendarState", () => $5270e0b8e8740a4c$export$6d095e787d2b5e1f); | ||
function $7e122b6ea38c4913$export$eac50920cf2fd59a(date, minValue, maxValue) { | ||
function $be5afcab32b8119f$export$eac50920cf2fd59a(date, minValue, maxValue) { | ||
return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0; | ||
} | ||
function $7e122b6ea38c4913$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) { | ||
function $be5afcab32b8119f$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) { | ||
let halfDuration = { | ||
@@ -43,14 +43,14 @@ }; | ||
} | ||
let aligned = $7e122b6ea38c4913$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration); | ||
return $7e122b6ea38c4913$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
let aligned = $be5afcab32b8119f$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration); | ||
return $be5afcab32b8119f$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $7e122b6ea38c4913$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) { | ||
function $be5afcab32b8119f$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) { | ||
// align to the start of the largest unit | ||
let aligned = date; | ||
if (duration.years) aligned = $8fZ0X$internationalizeddate.startOfYear(date); | ||
else if (duration.months) aligned = $8fZ0X$internationalizeddate.startOfMonth(date); | ||
else if (duration.weeks) aligned = $8fZ0X$internationalizeddate.startOfWeek(date, locale); | ||
return $7e122b6ea38c4913$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
if (duration.years) aligned = $9X5tg$internationalizeddate.startOfYear(date); | ||
else if (duration.months) aligned = $9X5tg$internationalizeddate.startOfMonth(date); | ||
else if (duration.weeks) aligned = $9X5tg$internationalizeddate.startOfWeek(date, locale); | ||
return $be5afcab32b8119f$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $7e122b6ea38c4913$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) { | ||
function $be5afcab32b8119f$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) { | ||
let d = { | ||
@@ -64,13 +64,13 @@ ...duration | ||
else if (duration.years) d.years--; | ||
let aligned = $7e122b6ea38c4913$export$144a00ba6044eb9(date, duration, locale).subtract(d); | ||
return $7e122b6ea38c4913$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
let aligned = $be5afcab32b8119f$export$144a00ba6044eb9(date, duration, locale).subtract(d); | ||
return $be5afcab32b8119f$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $7e122b6ea38c4913$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) { | ||
if (minValue && date.compare(minValue) >= 0) aligned = $8fZ0X$internationalizeddate.maxDate(aligned, $7e122b6ea38c4913$export$144a00ba6044eb9($8fZ0X$internationalizeddate.toCalendarDate(minValue), duration, locale)); | ||
if (maxValue && date.compare(maxValue) <= 0) aligned = $8fZ0X$internationalizeddate.minDate(aligned, $7e122b6ea38c4913$export$530edbfc915b2b04($8fZ0X$internationalizeddate.toCalendarDate(maxValue), duration, locale)); | ||
function $be5afcab32b8119f$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) { | ||
if (minValue && date.compare(minValue) >= 0) aligned = $9X5tg$internationalizeddate.maxDate(aligned, $be5afcab32b8119f$export$144a00ba6044eb9($9X5tg$internationalizeddate.toCalendarDate(minValue), duration, locale)); | ||
if (maxValue && date.compare(maxValue) <= 0) aligned = $9X5tg$internationalizeddate.minDate(aligned, $be5afcab32b8119f$export$530edbfc915b2b04($9X5tg$internationalizeddate.toCalendarDate(maxValue), duration, locale)); | ||
return aligned; | ||
} | ||
function $7e122b6ea38c4913$export$4f5203c0d889109e(date, minValue, maxValue) { | ||
if (minValue) date = $8fZ0X$internationalizeddate.maxDate(date, $8fZ0X$internationalizeddate.toCalendarDate(minValue)); | ||
if (maxValue) date = $8fZ0X$internationalizeddate.minDate(date, $8fZ0X$internationalizeddate.toCalendarDate(maxValue)); | ||
function $be5afcab32b8119f$export$4f5203c0d889109e(date, minValue, maxValue) { | ||
if (minValue) date = $9X5tg$internationalizeddate.maxDate(date, $9X5tg$internationalizeddate.toCalendarDate(minValue)); | ||
if (maxValue) date = $9X5tg$internationalizeddate.minDate(date, $9X5tg$internationalizeddate.toCalendarDate(maxValue)); | ||
return date; | ||
@@ -84,5 +84,5 @@ } | ||
function $f61c34523ac023ce$export$6d095e787d2b5e1f(props) { | ||
let defaultFormatter = $8fZ0X$reactariai18n.useDateFormatter(); | ||
let resolvedOptions = $8fZ0X$react.useMemo(()=>defaultFormatter.resolvedOptions() | ||
function $5270e0b8e8740a4c$export$6d095e787d2b5e1f(props) { | ||
let defaultFormatter = $9X5tg$reactariai18n.useDateFormatter(); | ||
let resolvedOptions = $9X5tg$react.useMemo(()=>defaultFormatter.resolvedOptions() | ||
, [ | ||
@@ -94,3 +94,3 @@ defaultFormatter | ||
} , minValue: minValue , maxValue: maxValue , selectionAlignment: selectionAlignment } = props; | ||
let calendar = $8fZ0X$react.useMemo(()=>createCalendar(resolvedOptions.calendar) | ||
let calendar = $9X5tg$react.useMemo(()=>createCalendar(resolvedOptions.calendar) | ||
, [ | ||
@@ -100,4 +100,4 @@ createCalendar, | ||
]); | ||
let [value, setControlledValue] = $8fZ0X$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange); | ||
let calendarDateValue = $8fZ0X$react.useMemo(()=>value ? $8fZ0X$internationalizeddate.toCalendar($8fZ0X$internationalizeddate.toCalendarDate(value), calendar) : null | ||
let [value, setControlledValue] = $9X5tg$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange); | ||
let calendarDateValue = $9X5tg$react.useMemo(()=>value ? $9X5tg$internationalizeddate.toCalendar($9X5tg$internationalizeddate.toCalendarDate(value), calendar) : null | ||
, [ | ||
@@ -107,3 +107,3 @@ value, | ||
]); | ||
let timeZone = $8fZ0X$react.useMemo(()=>value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone | ||
let timeZone = $9X5tg$react.useMemo(()=>value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone | ||
, [ | ||
@@ -113,3 +113,3 @@ value, | ||
]); | ||
let defaultDate = $8fZ0X$react.useMemo(()=>calendarDateValue || $7e122b6ea38c4913$export$4f5203c0d889109e($8fZ0X$internationalizeddate.toCalendar($8fZ0X$internationalizeddate.today(timeZone), calendar), minValue, maxValue) | ||
let defaultDate = $9X5tg$react.useMemo(()=>calendarDateValue || $be5afcab32b8119f$export$4f5203c0d889109e($9X5tg$internationalizeddate.toCalendar($9X5tg$internationalizeddate.today(timeZone), calendar), minValue, maxValue) | ||
, [ | ||
@@ -122,16 +122,16 @@ calendarDateValue, | ||
]); | ||
let [startDate, setStartDate] = $8fZ0X$react.useState(()=>{ | ||
let [startDate, setStartDate] = $9X5tg$react.useState(()=>{ | ||
switch(selectionAlignment){ | ||
case 'start': | ||
return $7e122b6ea38c4913$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $be5afcab32b8119f$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
case 'end': | ||
return $7e122b6ea38c4913$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $be5afcab32b8119f$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
case 'center': | ||
default: | ||
return $7e122b6ea38c4913$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $be5afcab32b8119f$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
} | ||
}); | ||
let [focusedDate, setFocusedDate] = $8fZ0X$react.useState(defaultDate); | ||
let [isFocused, setFocused] = $8fZ0X$react.useState(props.autoFocus || false); | ||
let endDate = $8fZ0X$react.useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
let [focusedDate, setFocusedDate] = $9X5tg$react.useState(defaultDate); | ||
let [isFocused, setFocused] = $9X5tg$react.useState(props.autoFocus || false); | ||
let endDate = $9X5tg$react.useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
days: 1 | ||
@@ -144,7 +144,7 @@ }) | ||
// Reset focused date and visible range when calendar changes. | ||
let lastCalendarIdentifier = $8fZ0X$react.useRef(calendar.identifier); | ||
$8fZ0X$react.useEffect(()=>{ | ||
let lastCalendarIdentifier = $9X5tg$react.useRef(calendar.identifier); | ||
$9X5tg$react.useEffect(()=>{ | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $8fZ0X$internationalizeddate.toCalendar(focusedDate, calendar); | ||
setStartDate($7e122b6ea38c4913$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
let newFocusedDate = $9X5tg$internationalizeddate.toCalendar(focusedDate, calendar); | ||
setStartDate($be5afcab32b8119f$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
@@ -164,6 +164,6 @@ lastCalendarIdentifier.current = calendar.identifier; | ||
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue); | ||
date = $7e122b6ea38c4913$export$4f5203c0d889109e(date, minValue, maxValue); | ||
date = $be5afcab32b8119f$export$4f5203c0d889109e(date, minValue, maxValue); | ||
let next = startDate.add(visibleDuration); | ||
if (date.compare(startDate) < 0) setStartDate($7e122b6ea38c4913$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($7e122b6ea38c4913$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
if (date.compare(startDate) < 0) setStartDate($be5afcab32b8119f$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($be5afcab32b8119f$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(date); | ||
@@ -175,3 +175,3 @@ } | ||
// Emit dates in the same calendar as the original value, if any, otherwise gregorian. | ||
newValue = $8fZ0X$internationalizeddate.toCalendar(newValue, value?.calendar || new $8fZ0X$internationalizeddate.GregorianCalendar()); | ||
newValue = $9X5tg$internationalizeddate.toCalendar(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new $9X5tg$internationalizeddate.GregorianCalendar()); | ||
// Preserve time if the input value had one. | ||
@@ -221,9 +221,9 @@ if (value && 'hour' in value) setControlledValue(value.set(newValue)); | ||
let start = startDate.add(visibleDuration); | ||
setStartDate($7e122b6ea38c4913$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($7e122b6ea38c4913$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue)); | ||
setStartDate($be5afcab32b8119f$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($be5afcab32b8119f$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue)); | ||
}, | ||
focusPreviousPage () { | ||
let start = startDate.subtract(visibleDuration); | ||
setStartDate($7e122b6ea38c4913$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($7e122b6ea38c4913$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue)); | ||
setStartDate($be5afcab32b8119f$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($be5afcab32b8119f$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue)); | ||
}, | ||
@@ -263,15 +263,15 @@ focusPageStart () { | ||
isInvalid (date) { | ||
return $7e122b6ea38c4913$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
return $be5afcab32b8119f$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
}, | ||
isSelected (date) { | ||
return calendarDateValue != null && $8fZ0X$internationalizeddate.isSameDay(date, calendarDateValue); | ||
return calendarDateValue != null && $9X5tg$internationalizeddate.isSameDay(date, calendarDateValue); | ||
}, | ||
isCellFocused (date) { | ||
return isFocused && focusedDate && $8fZ0X$internationalizeddate.isSameDay(date, focusedDate); | ||
return isFocused && focusedDate && $9X5tg$internationalizeddate.isSameDay(date, focusedDate); | ||
}, | ||
isCellDisabled (date) { | ||
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $7e122b6ea38c4913$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $be5afcab32b8119f$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
}, | ||
isPreviousVisibleRangeInvalid () { | ||
return $7e122b6ea38c4913$export$eac50920cf2fd59a(startDate.subtract({ | ||
return $be5afcab32b8119f$export$eac50920cf2fd59a(startDate.subtract({ | ||
days: 1 | ||
@@ -281,3 +281,3 @@ }), minValue, maxValue); | ||
isNextVisibleRangeInvalid () { | ||
return $7e122b6ea38c4913$export$eac50920cf2fd59a(endDate.add({ | ||
return $be5afcab32b8119f$export$eac50920cf2fd59a(endDate.add({ | ||
days: 1 | ||
@@ -290,5 +290,5 @@ }), minValue, maxValue); | ||
var $794e8b1784854410$exports = {}; | ||
var $db599f16579e1659$exports = {}; | ||
$parcel$export($794e8b1784854410$exports, "useRangeCalendarState", () => $794e8b1784854410$export$9a987164d97ecc90); | ||
$parcel$export($db599f16579e1659$exports, "useRangeCalendarState", () => $db599f16579e1659$export$9a987164d97ecc90); | ||
@@ -299,11 +299,11 @@ | ||
function $794e8b1784854410$export$9a987164d97ecc90(props) { | ||
function $db599f16579e1659$export$9a987164d97ecc90(props) { | ||
let { value: valueProp , defaultValue: defaultValue , onChange: onChange , createCalendar: createCalendar , locale: locale , visibleDuration: visibleDuration = { | ||
months: 1 | ||
} , minValue: minValue , maxValue: maxValue , ...calendarProps } = props; | ||
let [value, setValue] = $8fZ0X$reactstatelyutils.useControlledState(valueProp, defaultValue, onChange); | ||
let [anchorDate, setAnchorDate] = $8fZ0X$react.useState(null); | ||
let [value, setValue] = $9X5tg$reactstatelyutils.useControlledState(valueProp, defaultValue, onChange); | ||
let [anchorDate, setAnchorDate] = $9X5tg$react.useState(null); | ||
let alignment = 'center'; | ||
if (value && value.start && value.end) { | ||
let start = $7e122b6ea38c4913$export$f4a51ff076cc9a09($8fZ0X$internationalizeddate.toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue); | ||
let start = $be5afcab32b8119f$export$f4a51ff076cc9a09($9X5tg$internationalizeddate.toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue); | ||
let end = start.add(visibleDuration).subtract({ | ||
@@ -314,3 +314,3 @@ days: 1 | ||
} | ||
let calendar = $f61c34523ac023ce$export$6d095e787d2b5e1f({ | ||
let calendar = $5270e0b8e8740a4c$export$6d095e787d2b5e1f({ | ||
...calendarProps, | ||
@@ -325,3 +325,3 @@ value: value && value.start, | ||
}); | ||
let highlightedRange = anchorDate ? $794e8b1784854410$var$makeRange(anchorDate, calendar.focusedDate) : value && $794e8b1784854410$var$makeRange(value.start, value.end); | ||
let highlightedRange = anchorDate ? $db599f16579e1659$var$makeRange(anchorDate, calendar.focusedDate) : value && $db599f16579e1659$var$makeRange(value.start, value.end); | ||
let selectDate = (date)=>{ | ||
@@ -331,6 +331,6 @@ if (props.isReadOnly) return; | ||
else { | ||
let range = $794e8b1784854410$var$makeRange(anchorDate, date); | ||
let range = $db599f16579e1659$var$makeRange(anchorDate, date); | ||
setValue({ | ||
start: $794e8b1784854410$var$convertValue(range.start, value?.start), | ||
end: $794e8b1784854410$var$convertValue(range.end, value?.end) | ||
start: $db599f16579e1659$var$convertValue(range.start, value === null || value === void 0 ? void 0 : value.start), | ||
end: $db599f16579e1659$var$convertValue(range.end, value === null || value === void 0 ? void 0 : value.end) | ||
}); | ||
@@ -340,3 +340,3 @@ setAnchorDate(null); | ||
}; | ||
let [isDragging, setDragging] = $8fZ0X$react.useState(false); | ||
let [isDragging, setDragging] = $9X5tg$react.useState(false); | ||
return { | ||
@@ -363,3 +363,3 @@ ...calendar, | ||
} | ||
function $794e8b1784854410$var$makeRange(start, end) { | ||
function $db599f16579e1659$var$makeRange(start, end) { | ||
if (!start || !end) return null; | ||
@@ -371,10 +371,10 @@ if (end.compare(start) < 0) [start, end] = [ | ||
return { | ||
start: $8fZ0X$internationalizeddate.toCalendarDate(start), | ||
end: $8fZ0X$internationalizeddate.toCalendarDate(end) | ||
start: $9X5tg$internationalizeddate.toCalendarDate(start), | ||
end: $9X5tg$internationalizeddate.toCalendarDate(end) | ||
}; | ||
} | ||
function $794e8b1784854410$var$convertValue(newValue, oldValue) { | ||
function $db599f16579e1659$var$convertValue(newValue, oldValue) { | ||
// 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 = $8fZ0X$internationalizeddate.toCalendar(newValue, oldValue?.calendar || new $8fZ0X$internationalizeddate.GregorianCalendar()); | ||
newValue = $9X5tg$internationalizeddate.toCalendar(newValue, (oldValue === null || oldValue === void 0 ? void 0 : oldValue.calendar) || new $9X5tg$internationalizeddate.GregorianCalendar()); | ||
// Preserve time if the input value had one. | ||
@@ -386,7 +386,7 @@ if (oldValue && 'hour' in oldValue) return oldValue.set(newValue); | ||
$parcel$exportWildcard(module.exports, $b6932658840cac06$exports); | ||
$parcel$exportWildcard(module.exports, $f61c34523ac023ce$exports); | ||
$parcel$exportWildcard(module.exports, $794e8b1784854410$exports); | ||
$parcel$exportWildcard(module.exports, $2685e11fe2f22aa6$exports); | ||
$parcel$exportWildcard(module.exports, $5270e0b8e8740a4c$exports); | ||
$parcel$exportWildcard(module.exports, $db599f16579e1659$exports); | ||
//# sourceMappingURL=main.js.map |
@@ -1,5 +0,5 @@ | ||
import {toCalendar as $gtpA2$toCalendar, toCalendarDate as $gtpA2$toCalendarDate, today as $gtpA2$today, GregorianCalendar as $gtpA2$GregorianCalendar, isSameDay as $gtpA2$isSameDay, startOfYear as $gtpA2$startOfYear, startOfMonth as $gtpA2$startOfMonth, startOfWeek as $gtpA2$startOfWeek, maxDate as $gtpA2$maxDate, minDate as $gtpA2$minDate} from "@internationalized/date"; | ||
import {useControlledState as $gtpA2$useControlledState} from "@react-stately/utils"; | ||
import {useDateFormatter as $gtpA2$useDateFormatter} from "@react-aria/i18n"; | ||
import {useMemo as $gtpA2$useMemo, useState as $gtpA2$useState, useRef as $gtpA2$useRef, useEffect as $gtpA2$useEffect} from "react"; | ||
import {toCalendar as $c4QNE$toCalendar, toCalendarDate as $c4QNE$toCalendarDate, today as $c4QNE$today, GregorianCalendar as $c4QNE$GregorianCalendar, isSameDay as $c4QNE$isSameDay, startOfYear as $c4QNE$startOfYear, startOfMonth as $c4QNE$startOfMonth, startOfWeek as $c4QNE$startOfWeek, maxDate as $c4QNE$maxDate, minDate as $c4QNE$minDate} from "@internationalized/date"; | ||
import {useControlledState as $c4QNE$useControlledState} from "@react-stately/utils"; | ||
import {useDateFormatter as $c4QNE$useDateFormatter} from "@react-aria/i18n"; | ||
import {useMemo as $c4QNE$useMemo, useState as $c4QNE$useState, useRef as $c4QNE$useRef, useEffect as $c4QNE$useEffect} from "react"; | ||
@@ -9,13 +9,13 @@ function $parcel$export(e, n, v, s) { | ||
} | ||
var $509a3e380a190741$exports = {}; | ||
var $39e15dd59c7693c3$exports = {}; | ||
var $773eaea6455709cc$exports = {}; | ||
var $278d1f147362ecd3$exports = {}; | ||
$parcel$export($773eaea6455709cc$exports, "useCalendarState", () => $773eaea6455709cc$export$6d095e787d2b5e1f); | ||
$parcel$export($278d1f147362ecd3$exports, "useCalendarState", () => $278d1f147362ecd3$export$6d095e787d2b5e1f); | ||
function $e8a61e762628fc7e$export$eac50920cf2fd59a(date, minValue, maxValue) { | ||
function $f4621bbd7c5fce3b$export$eac50920cf2fd59a(date, minValue, maxValue) { | ||
return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0; | ||
} | ||
function $e8a61e762628fc7e$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) { | ||
function $f4621bbd7c5fce3b$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) { | ||
let halfDuration = { | ||
@@ -27,14 +27,14 @@ }; | ||
} | ||
let aligned = $e8a61e762628fc7e$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration); | ||
return $e8a61e762628fc7e$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
let aligned = $f4621bbd7c5fce3b$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration); | ||
return $f4621bbd7c5fce3b$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $e8a61e762628fc7e$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) { | ||
function $f4621bbd7c5fce3b$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) { | ||
// align to the start of the largest unit | ||
let aligned = date; | ||
if (duration.years) aligned = $gtpA2$startOfYear(date); | ||
else if (duration.months) aligned = $gtpA2$startOfMonth(date); | ||
else if (duration.weeks) aligned = $gtpA2$startOfWeek(date, locale); | ||
return $e8a61e762628fc7e$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
if (duration.years) aligned = $c4QNE$startOfYear(date); | ||
else if (duration.months) aligned = $c4QNE$startOfMonth(date); | ||
else if (duration.weeks) aligned = $c4QNE$startOfWeek(date, locale); | ||
return $f4621bbd7c5fce3b$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $e8a61e762628fc7e$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) { | ||
function $f4621bbd7c5fce3b$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) { | ||
let d = { | ||
@@ -48,13 +48,13 @@ ...duration | ||
else if (duration.years) d.years--; | ||
let aligned = $e8a61e762628fc7e$export$144a00ba6044eb9(date, duration, locale).subtract(d); | ||
return $e8a61e762628fc7e$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
let aligned = $f4621bbd7c5fce3b$export$144a00ba6044eb9(date, duration, locale).subtract(d); | ||
return $f4621bbd7c5fce3b$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue); | ||
} | ||
function $e8a61e762628fc7e$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) { | ||
if (minValue && date.compare(minValue) >= 0) aligned = $gtpA2$maxDate(aligned, $e8a61e762628fc7e$export$144a00ba6044eb9($gtpA2$toCalendarDate(minValue), duration, locale)); | ||
if (maxValue && date.compare(maxValue) <= 0) aligned = $gtpA2$minDate(aligned, $e8a61e762628fc7e$export$530edbfc915b2b04($gtpA2$toCalendarDate(maxValue), duration, locale)); | ||
function $f4621bbd7c5fce3b$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) { | ||
if (minValue && date.compare(minValue) >= 0) aligned = $c4QNE$maxDate(aligned, $f4621bbd7c5fce3b$export$144a00ba6044eb9($c4QNE$toCalendarDate(minValue), duration, locale)); | ||
if (maxValue && date.compare(maxValue) <= 0) aligned = $c4QNE$minDate(aligned, $f4621bbd7c5fce3b$export$530edbfc915b2b04($c4QNE$toCalendarDate(maxValue), duration, locale)); | ||
return aligned; | ||
} | ||
function $e8a61e762628fc7e$export$4f5203c0d889109e(date, minValue, maxValue) { | ||
if (minValue) date = $gtpA2$maxDate(date, $gtpA2$toCalendarDate(minValue)); | ||
if (maxValue) date = $gtpA2$minDate(date, $gtpA2$toCalendarDate(maxValue)); | ||
function $f4621bbd7c5fce3b$export$4f5203c0d889109e(date, minValue, maxValue) { | ||
if (minValue) date = $c4QNE$maxDate(date, $c4QNE$toCalendarDate(minValue)); | ||
if (maxValue) date = $c4QNE$minDate(date, $c4QNE$toCalendarDate(maxValue)); | ||
return date; | ||
@@ -68,5 +68,5 @@ } | ||
function $773eaea6455709cc$export$6d095e787d2b5e1f(props) { | ||
let defaultFormatter = $gtpA2$useDateFormatter(); | ||
let resolvedOptions = $gtpA2$useMemo(()=>defaultFormatter.resolvedOptions() | ||
function $278d1f147362ecd3$export$6d095e787d2b5e1f(props) { | ||
let defaultFormatter = $c4QNE$useDateFormatter(); | ||
let resolvedOptions = $c4QNE$useMemo(()=>defaultFormatter.resolvedOptions() | ||
, [ | ||
@@ -78,3 +78,3 @@ defaultFormatter | ||
} , minValue: minValue , maxValue: maxValue , selectionAlignment: selectionAlignment } = props; | ||
let calendar = $gtpA2$useMemo(()=>createCalendar(resolvedOptions.calendar) | ||
let calendar = $c4QNE$useMemo(()=>createCalendar(resolvedOptions.calendar) | ||
, [ | ||
@@ -84,4 +84,4 @@ createCalendar, | ||
]); | ||
let [value, setControlledValue] = $gtpA2$useControlledState(props.value, props.defaultValue, props.onChange); | ||
let calendarDateValue = $gtpA2$useMemo(()=>value ? $gtpA2$toCalendar($gtpA2$toCalendarDate(value), calendar) : null | ||
let [value, setControlledValue] = $c4QNE$useControlledState(props.value, props.defaultValue, props.onChange); | ||
let calendarDateValue = $c4QNE$useMemo(()=>value ? $c4QNE$toCalendar($c4QNE$toCalendarDate(value), calendar) : null | ||
, [ | ||
@@ -91,3 +91,3 @@ value, | ||
]); | ||
let timeZone = $gtpA2$useMemo(()=>value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone | ||
let timeZone = $c4QNE$useMemo(()=>value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone | ||
, [ | ||
@@ -97,3 +97,3 @@ value, | ||
]); | ||
let defaultDate = $gtpA2$useMemo(()=>calendarDateValue || $e8a61e762628fc7e$export$4f5203c0d889109e($gtpA2$toCalendar($gtpA2$today(timeZone), calendar), minValue, maxValue) | ||
let defaultDate = $c4QNE$useMemo(()=>calendarDateValue || $f4621bbd7c5fce3b$export$4f5203c0d889109e($c4QNE$toCalendar($c4QNE$today(timeZone), calendar), minValue, maxValue) | ||
, [ | ||
@@ -106,16 +106,16 @@ calendarDateValue, | ||
]); | ||
let [startDate, setStartDate] = $gtpA2$useState(()=>{ | ||
let [startDate, setStartDate] = $c4QNE$useState(()=>{ | ||
switch(selectionAlignment){ | ||
case 'start': | ||
return $e8a61e762628fc7e$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f4621bbd7c5fce3b$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
case 'end': | ||
return $e8a61e762628fc7e$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f4621bbd7c5fce3b$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
case 'center': | ||
default: | ||
return $e8a61e762628fc7e$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f4621bbd7c5fce3b$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
} | ||
}); | ||
let [focusedDate, setFocusedDate] = $gtpA2$useState(defaultDate); | ||
let [isFocused, setFocused] = $gtpA2$useState(props.autoFocus || false); | ||
let endDate = $gtpA2$useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
let [focusedDate, setFocusedDate] = $c4QNE$useState(defaultDate); | ||
let [isFocused, setFocused] = $c4QNE$useState(props.autoFocus || false); | ||
let endDate = $c4QNE$useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
days: 1 | ||
@@ -128,7 +128,7 @@ }) | ||
// Reset focused date and visible range when calendar changes. | ||
let lastCalendarIdentifier = $gtpA2$useRef(calendar.identifier); | ||
$gtpA2$useEffect(()=>{ | ||
let lastCalendarIdentifier = $c4QNE$useRef(calendar.identifier); | ||
$c4QNE$useEffect(()=>{ | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $gtpA2$toCalendar(focusedDate, calendar); | ||
setStartDate($e8a61e762628fc7e$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
let newFocusedDate = $c4QNE$toCalendar(focusedDate, calendar); | ||
setStartDate($f4621bbd7c5fce3b$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
@@ -148,6 +148,6 @@ lastCalendarIdentifier.current = calendar.identifier; | ||
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue); | ||
date = $e8a61e762628fc7e$export$4f5203c0d889109e(date, minValue, maxValue); | ||
date = $f4621bbd7c5fce3b$export$4f5203c0d889109e(date, minValue, maxValue); | ||
let next = startDate.add(visibleDuration); | ||
if (date.compare(startDate) < 0) setStartDate($e8a61e762628fc7e$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($e8a61e762628fc7e$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
if (date.compare(startDate) < 0) setStartDate($f4621bbd7c5fce3b$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($f4621bbd7c5fce3b$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(date); | ||
@@ -159,3 +159,3 @@ } | ||
// Emit dates in the same calendar as the original value, if any, otherwise gregorian. | ||
newValue = $gtpA2$toCalendar(newValue, value?.calendar || new $gtpA2$GregorianCalendar()); | ||
newValue = $c4QNE$toCalendar(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new $c4QNE$GregorianCalendar()); | ||
// Preserve time if the input value had one. | ||
@@ -205,9 +205,9 @@ if (value && 'hour' in value) setControlledValue(value.set(newValue)); | ||
let start = startDate.add(visibleDuration); | ||
setStartDate($e8a61e762628fc7e$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($e8a61e762628fc7e$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue)); | ||
setStartDate($f4621bbd7c5fce3b$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($f4621bbd7c5fce3b$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue)); | ||
}, | ||
focusPreviousPage () { | ||
let start = startDate.subtract(visibleDuration); | ||
setStartDate($e8a61e762628fc7e$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($e8a61e762628fc7e$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue)); | ||
setStartDate($f4621bbd7c5fce3b$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate($f4621bbd7c5fce3b$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue)); | ||
}, | ||
@@ -247,15 +247,15 @@ focusPageStart () { | ||
isInvalid (date) { | ||
return $e8a61e762628fc7e$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
return $f4621bbd7c5fce3b$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
}, | ||
isSelected (date) { | ||
return calendarDateValue != null && $gtpA2$isSameDay(date, calendarDateValue); | ||
return calendarDateValue != null && $c4QNE$isSameDay(date, calendarDateValue); | ||
}, | ||
isCellFocused (date) { | ||
return isFocused && focusedDate && $gtpA2$isSameDay(date, focusedDate); | ||
return isFocused && focusedDate && $c4QNE$isSameDay(date, focusedDate); | ||
}, | ||
isCellDisabled (date) { | ||
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $e8a61e762628fc7e$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $f4621bbd7c5fce3b$export$eac50920cf2fd59a(date, minValue, maxValue); | ||
}, | ||
isPreviousVisibleRangeInvalid () { | ||
return $e8a61e762628fc7e$export$eac50920cf2fd59a(startDate.subtract({ | ||
return $f4621bbd7c5fce3b$export$eac50920cf2fd59a(startDate.subtract({ | ||
days: 1 | ||
@@ -265,3 +265,3 @@ }), minValue, maxValue); | ||
isNextVisibleRangeInvalid () { | ||
return $e8a61e762628fc7e$export$eac50920cf2fd59a(endDate.add({ | ||
return $f4621bbd7c5fce3b$export$eac50920cf2fd59a(endDate.add({ | ||
days: 1 | ||
@@ -274,5 +274,5 @@ }), minValue, maxValue); | ||
var $47d19290c26a12d7$exports = {}; | ||
var $303e70b3e1864f0a$exports = {}; | ||
$parcel$export($47d19290c26a12d7$exports, "useRangeCalendarState", () => $47d19290c26a12d7$export$9a987164d97ecc90); | ||
$parcel$export($303e70b3e1864f0a$exports, "useRangeCalendarState", () => $303e70b3e1864f0a$export$9a987164d97ecc90); | ||
@@ -283,11 +283,11 @@ | ||
function $47d19290c26a12d7$export$9a987164d97ecc90(props) { | ||
function $303e70b3e1864f0a$export$9a987164d97ecc90(props) { | ||
let { value: valueProp , defaultValue: defaultValue , onChange: onChange , createCalendar: createCalendar , locale: locale , visibleDuration: visibleDuration = { | ||
months: 1 | ||
} , minValue: minValue , maxValue: maxValue , ...calendarProps } = props; | ||
let [value, setValue] = $gtpA2$useControlledState(valueProp, defaultValue, onChange); | ||
let [anchorDate, setAnchorDate] = $gtpA2$useState(null); | ||
let [value, setValue] = $c4QNE$useControlledState(valueProp, defaultValue, onChange); | ||
let [anchorDate, setAnchorDate] = $c4QNE$useState(null); | ||
let alignment = 'center'; | ||
if (value && value.start && value.end) { | ||
let start = $e8a61e762628fc7e$export$f4a51ff076cc9a09($gtpA2$toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue); | ||
let start = $f4621bbd7c5fce3b$export$f4a51ff076cc9a09($c4QNE$toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue); | ||
let end = start.add(visibleDuration).subtract({ | ||
@@ -298,3 +298,3 @@ days: 1 | ||
} | ||
let calendar = $773eaea6455709cc$export$6d095e787d2b5e1f({ | ||
let calendar = $278d1f147362ecd3$export$6d095e787d2b5e1f({ | ||
...calendarProps, | ||
@@ -309,3 +309,3 @@ value: value && value.start, | ||
}); | ||
let highlightedRange = anchorDate ? $47d19290c26a12d7$var$makeRange(anchorDate, calendar.focusedDate) : value && $47d19290c26a12d7$var$makeRange(value.start, value.end); | ||
let highlightedRange = anchorDate ? $303e70b3e1864f0a$var$makeRange(anchorDate, calendar.focusedDate) : value && $303e70b3e1864f0a$var$makeRange(value.start, value.end); | ||
let selectDate = (date)=>{ | ||
@@ -315,6 +315,6 @@ if (props.isReadOnly) return; | ||
else { | ||
let range = $47d19290c26a12d7$var$makeRange(anchorDate, date); | ||
let range = $303e70b3e1864f0a$var$makeRange(anchorDate, date); | ||
setValue({ | ||
start: $47d19290c26a12d7$var$convertValue(range.start, value?.start), | ||
end: $47d19290c26a12d7$var$convertValue(range.end, value?.end) | ||
start: $303e70b3e1864f0a$var$convertValue(range.start, value === null || value === void 0 ? void 0 : value.start), | ||
end: $303e70b3e1864f0a$var$convertValue(range.end, value === null || value === void 0 ? void 0 : value.end) | ||
}); | ||
@@ -324,3 +324,3 @@ setAnchorDate(null); | ||
}; | ||
let [isDragging, setDragging] = $gtpA2$useState(false); | ||
let [isDragging, setDragging] = $c4QNE$useState(false); | ||
return { | ||
@@ -347,3 +347,3 @@ ...calendar, | ||
} | ||
function $47d19290c26a12d7$var$makeRange(start, end) { | ||
function $303e70b3e1864f0a$var$makeRange(start, end) { | ||
if (!start || !end) return null; | ||
@@ -355,10 +355,10 @@ if (end.compare(start) < 0) [start, end] = [ | ||
return { | ||
start: $gtpA2$toCalendarDate(start), | ||
end: $gtpA2$toCalendarDate(end) | ||
start: $c4QNE$toCalendarDate(start), | ||
end: $c4QNE$toCalendarDate(end) | ||
}; | ||
} | ||
function $47d19290c26a12d7$var$convertValue(newValue, oldValue) { | ||
function $303e70b3e1864f0a$var$convertValue(newValue, oldValue) { | ||
// 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 = $gtpA2$toCalendar(newValue, oldValue?.calendar || new $gtpA2$GregorianCalendar()); | ||
newValue = $c4QNE$toCalendar(newValue, (oldValue === null || oldValue === void 0 ? void 0 : oldValue.calendar) || new $c4QNE$GregorianCalendar()); | ||
// Preserve time if the input value had one. | ||
@@ -372,3 +372,3 @@ if (oldValue && 'hour' in oldValue) return oldValue.set(newValue); | ||
export {$773eaea6455709cc$export$6d095e787d2b5e1f as useCalendarState, $47d19290c26a12d7$export$9a987164d97ecc90 as useRangeCalendarState}; | ||
export {$278d1f147362ecd3$export$6d095e787d2b5e1f as useCalendarState, $303e70b3e1864f0a$export$9a987164d97ecc90 as useRangeCalendarState}; | ||
//# sourceMappingURL=module.js.map |
{ | ||
"name": "@react-stately/calendar", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.3", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,8 +21,8 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@internationalized/date": "3.0.0-alpha.2", | ||
"@react-aria/i18n": "^3.3.5", | ||
"@react-stately/utils": "^3.4.0", | ||
"@react-types/calendar": "3.0.0-alpha.2", | ||
"@react-types/datepicker": "3.0.0-alpha.2", | ||
"@react-types/shared": "^3.11.0", | ||
"@internationalized/date": "3.0.0-alpha.3", | ||
"@react-aria/i18n": "^3.3.6", | ||
"@react-stately/utils": "^3.4.1", | ||
"@react-types/calendar": "3.0.0-alpha.3", | ||
"@react-types/datepicker": "3.0.0-alpha.3", | ||
"@react-types/shared": "^3.11.1", | ||
"date-fns": "^1.30.1" | ||
@@ -36,3 +36,3 @@ }, | ||
}, | ||
"gitHead": "54c2366c4f31bd4bf619126131cd583c12972acc" | ||
"gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128327
+ Added@internationalized/date@3.0.0-alpha.3(transitive)
+ Added@react-types/calendar@3.0.0-alpha.3(transitive)
+ Added@react-types/datepicker@3.0.0-alpha.3(transitive)
- Removed@internationalized/date@3.0.0-alpha.2(transitive)
- Removed@react-types/calendar@3.0.0-alpha.2(transitive)
- Removed@react-types/datepicker@3.0.0-alpha.2(transitive)
Updated@react-aria/i18n@^3.3.6
Updated@react-stately/utils@^3.4.1
Updated@react-types/shared@^3.11.1