@react-stately/calendar
Advanced tools
Comparing version 3.0.0-nightly.1452 to 3.0.0-nightly.1460
@@ -106,4 +106,12 @@ var $hEzMm$internationalizeddate = require("@internationalized/date"); | ||
]); | ||
let defaultDate = $hEzMm$react.useMemo(()=>calendarDateValue || $4301262d71f567b9$export$4f5203c0d889109e($hEzMm$internationalizeddate.toCalendar($hEzMm$internationalizeddate.today(timeZone), calendar), minValue, maxValue) | ||
let focusedCalendarDate = $hEzMm$react.useMemo(()=>props.focusedValue ? $4301262d71f567b9$export$4f5203c0d889109e($hEzMm$internationalizeddate.toCalendar($hEzMm$internationalizeddate.toCalendarDate(props.focusedValue), calendar), minValue, maxValue) : undefined | ||
, [ | ||
props.focusedValue, | ||
calendar, | ||
minValue, | ||
maxValue | ||
]); | ||
let defaultFocusedCalendarDate = $hEzMm$react.useMemo(()=>$4301262d71f567b9$export$4f5203c0d889109e(props.defaultFocusedValue ? $hEzMm$internationalizeddate.toCalendar($hEzMm$internationalizeddate.toCalendarDate(props.defaultFocusedValue), calendar) : calendarDateValue || $hEzMm$internationalizeddate.toCalendar($hEzMm$internationalizeddate.today(timeZone), calendar), minValue, maxValue) | ||
, [ | ||
props.defaultFocusedValue, | ||
calendarDateValue, | ||
@@ -115,14 +123,14 @@ timeZone, | ||
]); | ||
let [focusedDate, setFocusedDate] = $hEzMm$reactstatelyutils.useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange); | ||
let [startDate, setStartDate] = $hEzMm$react.useState(()=>{ | ||
switch(selectionAlignment){ | ||
case 'start': | ||
return $4301262d71f567b9$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $4301262d71f567b9$export$144a00ba6044eb9(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'end': | ||
return $4301262d71f567b9$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $4301262d71f567b9$export$530edbfc915b2b04(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'center': | ||
default: | ||
return $4301262d71f567b9$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $4301262d71f567b9$export$f4a51ff076cc9a09(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
} | ||
}); | ||
let [focusedDate, setFocusedDate] = $hEzMm$react.useState(defaultDate); | ||
let [isFocused, setFocused] = $hEzMm$react.useState(props.autoFocus || false); | ||
@@ -138,24 +146,13 @@ let endDate = $hEzMm$react.useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
let lastCalendarIdentifier = $hEzMm$react.useRef(calendar.identifier); | ||
$hEzMm$react.useEffect(()=>{ | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $hEzMm$internationalizeddate.toCalendar(focusedDate, calendar); | ||
setStartDate($4301262d71f567b9$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
}, [ | ||
calendar, | ||
focusedDate, | ||
visibleDuration, | ||
locale, | ||
minValue, | ||
maxValue | ||
]); | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $hEzMm$internationalizeddate.toCalendar(focusedDate, calendar); | ||
setStartDate($4301262d71f567b9$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
if (focusedDate.compare(startDate) < 0) setStartDate($4301262d71f567b9$export$530edbfc915b2b04(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
else if (focusedDate.compare(startDate.add(visibleDuration)) >= 0) setStartDate($4301262d71f567b9$export$144a00ba6044eb9(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
// Sets focus to a specific cell date | ||
function focusCell(date) { | ||
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue); | ||
date = $4301262d71f567b9$export$4f5203c0d889109e(date, minValue, maxValue); | ||
let next = startDate.add(visibleDuration); | ||
if (date.compare(startDate) < 0) setStartDate($4301262d71f567b9$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($4301262d71f567b9$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(date); | ||
@@ -185,3 +182,3 @@ } | ||
setFocusedDate (date) { | ||
setFocusedDate(date); | ||
focusCell(date); | ||
setFocused(true); | ||
@@ -188,0 +185,0 @@ }, |
import {toCalendar as $keQhS$toCalendar, toCalendarDate as $keQhS$toCalendarDate, today as $keQhS$today, GregorianCalendar as $keQhS$GregorianCalendar, isSameDay as $keQhS$isSameDay, startOfYear as $keQhS$startOfYear, startOfMonth as $keQhS$startOfMonth, startOfWeek as $keQhS$startOfWeek, maxDate as $keQhS$maxDate, minDate as $keQhS$minDate} from "@internationalized/date"; | ||
import {useControlledState as $keQhS$useControlledState} from "@react-stately/utils"; | ||
import {useDateFormatter as $keQhS$useDateFormatter} from "@react-aria/i18n"; | ||
import {useMemo as $keQhS$useMemo, useState as $keQhS$useState, useRef as $keQhS$useRef, useEffect as $keQhS$useEffect} from "react"; | ||
import {useMemo as $keQhS$useMemo, useState as $keQhS$useState, useRef as $keQhS$useRef} from "react"; | ||
@@ -90,4 +90,12 @@ function $parcel$export(e, n, v, s) { | ||
]); | ||
let defaultDate = $keQhS$useMemo(()=>calendarDateValue || $f62d864046160412$export$4f5203c0d889109e($keQhS$toCalendar($keQhS$today(timeZone), calendar), minValue, maxValue) | ||
let focusedCalendarDate = $keQhS$useMemo(()=>props.focusedValue ? $f62d864046160412$export$4f5203c0d889109e($keQhS$toCalendar($keQhS$toCalendarDate(props.focusedValue), calendar), minValue, maxValue) : undefined | ||
, [ | ||
props.focusedValue, | ||
calendar, | ||
minValue, | ||
maxValue | ||
]); | ||
let defaultFocusedCalendarDate = $keQhS$useMemo(()=>$f62d864046160412$export$4f5203c0d889109e(props.defaultFocusedValue ? $keQhS$toCalendar($keQhS$toCalendarDate(props.defaultFocusedValue), calendar) : calendarDateValue || $keQhS$toCalendar($keQhS$today(timeZone), calendar), minValue, maxValue) | ||
, [ | ||
props.defaultFocusedValue, | ||
calendarDateValue, | ||
@@ -99,14 +107,14 @@ timeZone, | ||
]); | ||
let [focusedDate, setFocusedDate] = $keQhS$useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange); | ||
let [startDate, setStartDate] = $keQhS$useState(()=>{ | ||
switch(selectionAlignment){ | ||
case 'start': | ||
return $f62d864046160412$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f62d864046160412$export$144a00ba6044eb9(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'end': | ||
return $f62d864046160412$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f62d864046160412$export$530edbfc915b2b04(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'center': | ||
default: | ||
return $f62d864046160412$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return $f62d864046160412$export$f4a51ff076cc9a09(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
} | ||
}); | ||
let [focusedDate, setFocusedDate] = $keQhS$useState(defaultDate); | ||
let [isFocused, setFocused] = $keQhS$useState(props.autoFocus || false); | ||
@@ -122,24 +130,13 @@ let endDate = $keQhS$useMemo(()=>startDate.add(visibleDuration).subtract({ | ||
let lastCalendarIdentifier = $keQhS$useRef(calendar.identifier); | ||
$keQhS$useEffect(()=>{ | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $keQhS$toCalendar(focusedDate, calendar); | ||
setStartDate($f62d864046160412$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
}, [ | ||
calendar, | ||
focusedDate, | ||
visibleDuration, | ||
locale, | ||
minValue, | ||
maxValue | ||
]); | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = $keQhS$toCalendar(focusedDate, calendar); | ||
setStartDate($f62d864046160412$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
if (focusedDate.compare(startDate) < 0) setStartDate($f62d864046160412$export$530edbfc915b2b04(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
else if (focusedDate.compare(startDate.add(visibleDuration)) >= 0) setStartDate($f62d864046160412$export$144a00ba6044eb9(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
// Sets focus to a specific cell date | ||
function focusCell(date) { | ||
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue); | ||
date = $f62d864046160412$export$4f5203c0d889109e(date, minValue, maxValue); | ||
let next = startDate.add(visibleDuration); | ||
if (date.compare(startDate) < 0) setStartDate($f62d864046160412$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue)); | ||
else if (date.compare(next) >= 0) setStartDate($f62d864046160412$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(date); | ||
@@ -169,3 +166,3 @@ } | ||
setFocusedDate (date) { | ||
setFocusedDate(date); | ||
focusCell(date); | ||
setFocused(true); | ||
@@ -172,0 +169,0 @@ }, |
{ | ||
"name": "@react-stately/calendar", | ||
"version": "3.0.0-nightly.1452+320c69908", | ||
"version": "3.0.0-nightly.1460+2c25922e2", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,8 +21,8 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@internationalized/date": "3.0.0-nightly.3148+320c69908", | ||
"@react-aria/i18n": "3.0.0-nightly.1452+320c69908", | ||
"@react-stately/utils": "3.0.0-nightly.1452+320c69908", | ||
"@react-types/calendar": "3.0.0-nightly.3148+320c69908", | ||
"@react-types/datepicker": "3.0.0-nightly.3148+320c69908", | ||
"@react-types/shared": "3.0.0-nightly.1452+320c69908", | ||
"@internationalized/date": "3.0.0-nightly.3156+2c25922e2", | ||
"@react-aria/i18n": "3.0.0-nightly.1460+2c25922e2", | ||
"@react-stately/utils": "3.0.0-nightly.1460+2c25922e2", | ||
"@react-types/calendar": "3.0.0-nightly.3156+2c25922e2", | ||
"@react-types/datepicker": "3.0.0-nightly.3156+2c25922e2", | ||
"@react-types/shared": "3.0.0-nightly.1460+2c25922e2", | ||
"date-fns": "^1.30.1" | ||
@@ -36,3 +36,3 @@ }, | ||
}, | ||
"gitHead": "320c69908b41be47a3abb2878d04f90384e54321" | ||
"gitHead": "2c25922e23ec51bd487b7838adb48a60c558dc36" | ||
} |
@@ -28,3 +28,3 @@ /* | ||
import {useDateFormatter} from '@react-aria/i18n'; | ||
import {useEffect, useMemo, useRef, useState} from 'react'; | ||
import {useMemo, useRef, useState} from 'react'; | ||
@@ -55,15 +55,28 @@ interface CalendarStateOptions<T extends DateValue> extends CalendarProps<T> { | ||
let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]); | ||
let defaultDate = useMemo(() => calendarDateValue || constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue), [calendarDateValue, timeZone, calendar, minValue, maxValue]); | ||
let focusedCalendarDate = useMemo(() => ( | ||
props.focusedValue | ||
? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue) | ||
: undefined | ||
), [props.focusedValue, calendar, minValue, maxValue]); | ||
let defaultFocusedCalendarDate = useMemo(() => ( | ||
constrainValue( | ||
props.defaultFocusedValue | ||
? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar) | ||
: calendarDateValue || toCalendar(today(timeZone), calendar), | ||
minValue, | ||
maxValue | ||
) | ||
), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]); | ||
let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange); | ||
let [startDate, setStartDate] = useState(() => { | ||
switch (selectionAlignment) { | ||
case 'start': | ||
return alignStart(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'end': | ||
return alignEnd(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
case 'center': | ||
default: | ||
return alignCenter(defaultDate, visibleDuration, locale, minValue, maxValue); | ||
return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue); | ||
} | ||
}); | ||
let [focusedDate, setFocusedDate] = useState(defaultDate); | ||
let [isFocused, setFocused] = useState(props.autoFocus || false); | ||
@@ -75,23 +88,18 @@ | ||
let lastCalendarIdentifier = useRef(calendar.identifier); | ||
useEffect(() => { | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = toCalendar(focusedDate, calendar); | ||
setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
}, [calendar, focusedDate, visibleDuration, locale, minValue, maxValue]); | ||
if (calendar.identifier !== lastCalendarIdentifier.current) { | ||
let newFocusedDate = toCalendar(focusedDate, calendar); | ||
setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue)); | ||
setFocusedDate(newFocusedDate); | ||
lastCalendarIdentifier.current = calendar.identifier; | ||
} | ||
if (focusedDate.compare(startDate) < 0) { | ||
setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
} else if (focusedDate.compare(startDate.add(visibleDuration)) >= 0) { | ||
setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue)); | ||
} | ||
// Sets focus to a specific cell date | ||
function focusCell(date: CalendarDate) { | ||
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue); | ||
date = constrainValue(date, minValue, maxValue); | ||
let next = startDate.add(visibleDuration); | ||
if (date.compare(startDate) < 0) { | ||
setStartDate(alignEnd(date, visibleDuration, locale, minValue, maxValue)); | ||
} else if (date.compare(next) >= 0) { | ||
setStartDate(alignStart(date, visibleDuration, locale, minValue, maxValue)); | ||
} | ||
setFocusedDate(date); | ||
@@ -127,3 +135,3 @@ } | ||
setFocusedDate(date) { | ||
setFocusedDate(date); | ||
focusCell(date); | ||
setFocused(true); | ||
@@ -130,0 +138,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
143669
1292