@fluentui/react-datepicker-compat 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +88 -1
- package/CHANGELOG.md +23 -2
- package/lib/components/Calendar/Calendar.js +9 -7
- package/lib/components/Calendar/Calendar.js.map +1 -1
- package/lib/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib/components/CalendarDay/CalendarDay.js +8 -11
- package/lib/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js +8 -10
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js +8 -5
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridRow.js +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js +1 -1
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeeks.js +4 -3
- package/lib/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib/components/CalendarMonth/CalendarMonth.js +10 -8
- package/lib/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib/components/CalendarYear/CalendarYear.js +38 -39
- package/lib/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/components/DatePicker/renderDatePicker.js +15 -6
- package/lib/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePicker.js +18 -13
- package/lib/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib/utils/dateGrid/findAvailableDate.js +1 -1
- package/lib/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib/utils/dateGrid/getDayGrid.js +3 -2
- package/lib/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib/utils/dateGrid/isAfterMaxDate.js +1 -1
- package/lib/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib/utils/dateGrid/isBeforeMinDate.js +1 -1
- package/lib/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib/utils/dateGrid/isRestrictedDate.js +1 -1
- package/lib/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib/utils/dateMath/dateMath.js.map +1 -1
- package/lib/utils/dom.js.map +1 -1
- package/lib/utils/focus.js.map +1 -1
- package/lib/utils/usePopupPositioning.js +2 -2
- package/lib/utils/usePopupPositioning.js.map +1 -1
- package/lib-commonjs/Calendar.js +2 -2
- package/lib-commonjs/Calendar.js.map +1 -1
- package/lib-commonjs/CalendarDay.js +2 -2
- package/lib-commonjs/CalendarDay.js.map +1 -1
- package/lib-commonjs/CalendarDayGrid.js +2 -2
- package/lib-commonjs/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/CalendarMonth.js +2 -2
- package/lib-commonjs/CalendarMonth.js.map +1 -1
- package/lib-commonjs/CalendarPicker.js +2 -2
- package/lib-commonjs/CalendarPicker.js.map +1 -1
- package/lib-commonjs/CalendarYear.js +2 -2
- package/lib-commonjs/CalendarYear.js.map +1 -1
- package/lib-commonjs/DatePicker.js +2 -2
- package/lib-commonjs/DatePicker.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.js +32 -28
- package/lib-commonjs/components/Calendar/Calendar.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.types.js +5 -3
- package/lib-commonjs/components/Calendar/Calendar.types.js.map +1 -1
- package/lib-commonjs/components/Calendar/defaults.js +3 -1
- package/lib-commonjs/components/Calendar/defaults.js.map +1 -1
- package/lib-commonjs/components/Calendar/index.js +7 -5
- package/lib-commonjs/components/Calendar/index.js.map +1 -1
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js +12 -8
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.js +25 -26
- package/lib-commonjs/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js +2 -2
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/index.js +4 -4
- package/lib-commonjs/components/CalendarDay/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js +13 -9
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js +27 -27
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js +2 -2
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js +29 -24
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js +8 -6
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js +6 -4
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/index.js +10 -6
- package/lib-commonjs/components/CalendarDayGrid/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js +29 -23
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js +9 -5
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js +9 -6
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js +24 -21
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js +2 -2
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/index.js +4 -4
- package/lib-commonjs/components/CalendarMonth/index.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js +5 -3
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/index.js +3 -3
- package/lib-commonjs/components/CalendarPicker/index.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js +20 -16
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.js +60 -59
- package/lib-commonjs/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js +2 -2
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/index.js +4 -4
- package/lib-commonjs/components/CalendarYear/index.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js +5 -3
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DatePicker/DatePicker.js +7 -5
- package/lib-commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/defaults.js +6 -2
- package/lib-commonjs/components/DatePicker/defaults.js.map +1 -1
- package/lib-commonjs/components/DatePicker/index.js +7 -7
- package/lib-commonjs/components/DatePicker/index.js.map +1 -1
- package/lib-commonjs/components/DatePicker/renderDatePicker.js +22 -12
- package/lib-commonjs/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePicker.js +59 -52
- package/lib-commonjs/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js +9 -5
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib-commonjs/index.js +98 -34
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/animations.js +45 -15
- package/lib-commonjs/utils/animations.js.map +1 -1
- package/lib-commonjs/utils/constants.js +18 -6
- package/lib-commonjs/utils/constants.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js +24 -8
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/index.js +3 -3
- package/lib-commonjs/utils/dateFormatting/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js +4 -2
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js +3 -1
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js +3 -1
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDayGrid.js +6 -3
- package/lib-commonjs/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/index.js +6 -6
- package/lib-commonjs/utils/dateGrid/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js +4 -2
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js +4 -2
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isContiguous.js +3 -1
- package/lib-commonjs/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js +4 -2
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib-commonjs/utils/dateMath/dateMath.js +54 -18
- package/lib-commonjs/utils/dateMath/dateMath.js.map +1 -1
- package/lib-commonjs/utils/dateMath/index.js +2 -2
- package/lib-commonjs/utils/dateMath/index.js.map +1 -1
- package/lib-commonjs/utils/dom.js +5 -3
- package/lib-commonjs/utils/dom.js.map +1 -1
- package/lib-commonjs/utils/focus.js +3 -1
- package/lib-commonjs/utils/focus.js.map +1 -1
- package/lib-commonjs/utils/index.js +8 -8
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/usePopupPositioning.js +9 -7
- package/lib-commonjs/utils/usePopupPositioning.js.map +1 -1
- package/package.json +17 -17
|
@@ -17,7 +17,7 @@ function useFocusLogic() {
|
|
|
17
17
|
const inputRef = React.useRef(null);
|
|
18
18
|
const preventFocusOpeningPicker = React.useRef(false);
|
|
19
19
|
const focus = React.useCallback(()=>{
|
|
20
|
-
var
|
|
20
|
+
var _inputRef_current_focus, _inputRef_current;
|
|
21
21
|
(_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : (_inputRef_current_focus = _inputRef_current.focus) === null || _inputRef_current_focus === void 0 ? void 0 : _inputRef_current_focus.call(_inputRef_current);
|
|
22
22
|
}, []);
|
|
23
23
|
const preventNextFocusOpeningPicker = React.useCallback(()=>{
|
|
@@ -40,8 +40,8 @@ function usePopupVisibility(props) {
|
|
|
40
40
|
React.useEffect(()=>{
|
|
41
41
|
if (isMounted.current && !open) {
|
|
42
42
|
var // If DatePicker's menu (Calendar) is closed, run onAfterMenuDismiss
|
|
43
|
-
_props_onOpenChange;
|
|
44
|
-
(_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0 ? void 0 : _props_onOpenChange.call(
|
|
43
|
+
_props_onOpenChange, _props;
|
|
44
|
+
(_props_onOpenChange = (_props = props).onOpenChange) === null || _props_onOpenChange === void 0 ? void 0 : _props_onOpenChange.call(_props, false);
|
|
45
45
|
}
|
|
46
46
|
isMounted.current = true;
|
|
47
47
|
}, // Should only run on allowTextInput or open change
|
|
@@ -55,14 +55,15 @@ function usePopupVisibility(props) {
|
|
|
55
55
|
setOpen
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
|
-
function useSelectedDate({ formatDate
|
|
58
|
+
function useSelectedDate({ formatDate, onSelectDate, value }) {
|
|
59
59
|
const [selectedDate, setSelectedDateState] = useControllableState({
|
|
60
60
|
initialState: null,
|
|
61
61
|
state: value
|
|
62
62
|
});
|
|
63
63
|
const [formattedDate, setFormattedDate] = React.useState(()=>value && formatDate ? formatDate(value) : '');
|
|
64
64
|
const setSelectedDate = (newDate)=>{
|
|
65
|
-
|
|
65
|
+
var _onSelectDate;
|
|
66
|
+
(_onSelectDate = onSelectDate) === null || _onSelectDate === void 0 ? void 0 : _onSelectDate(newDate);
|
|
66
67
|
setSelectedDateState(newDate);
|
|
67
68
|
setFormattedDate(newDate && formatDate ? formatDate(newDate) : '');
|
|
68
69
|
};
|
|
@@ -93,7 +94,8 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
93
94
|
* @param props - props from this instance of DatePicker
|
|
94
95
|
* @param ref - reference to root Input slot
|
|
95
96
|
*/ export const useDatePicker_unstable = (props, ref)=>{
|
|
96
|
-
|
|
97
|
+
var _fieldContext;
|
|
98
|
+
const { allowTextInput = false, allFocusable = false, borderless = false, dateTimeFormatter, defaultOpen = false, disableAutoFocus = true, firstDayOfWeek = DayOfWeek.Sunday, firstWeekOfYear = FirstWeekOfYear.FirstDay, formatDate = defaultFormatDate, highlightCurrentMonth = false, highlightSelectedMonth = false, initialPickerDate = new Date(), inlinePopup = false, isMonthPickerVisible = true, maxDate, minDate, mountNode, onOpenChange, onSelectDate: onUserSelectDate, openOnClick = true, onValidationResult, parseDateFromString = defaultParseDateFromString, showCloseButton = false, showGoToToday = true, showMonthPickerAsOverlay = false, showWeekNumbers = false, strings = defaultDatePickerStrings, today, underlined = false, value, ...restOfProps } = props;
|
|
97
99
|
const calendar = React.useRef(null);
|
|
98
100
|
const [focus, rootRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] = useFocusLogic();
|
|
99
101
|
const [selectedDate, formattedDate, setSelectedDate, setFormattedDate] = useSelectedDate({
|
|
@@ -104,9 +106,10 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
104
106
|
const [open, setOpenState] = usePopupVisibility(props);
|
|
105
107
|
const fieldContext = useFieldContext();
|
|
106
108
|
var _fieldContext_required;
|
|
107
|
-
const required = (_fieldContext_required = fieldContext === null ||
|
|
109
|
+
const required = (_fieldContext_required = (_fieldContext = fieldContext) === null || _fieldContext === void 0 ? void 0 : _fieldContext.required) !== null && _fieldContext_required !== void 0 ? _fieldContext_required : props.required;
|
|
108
110
|
const popupSurfaceId = useId('datePicker-popupSurface');
|
|
109
111
|
const validateTextInput = React.useCallback((date = null)=>{
|
|
112
|
+
var _onValidationResult;
|
|
110
113
|
let error;
|
|
111
114
|
if (allowTextInput) {
|
|
112
115
|
if (formattedDate || date) {
|
|
@@ -130,15 +133,16 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
} else {
|
|
136
|
+
var _onUserSelectDate;
|
|
133
137
|
if (required) {
|
|
134
138
|
error = 'required-input';
|
|
135
139
|
}
|
|
136
|
-
onUserSelectDate === null ||
|
|
140
|
+
(_onUserSelectDate = onUserSelectDate) === null || _onUserSelectDate === void 0 ? void 0 : _onUserSelectDate(date);
|
|
137
141
|
}
|
|
138
142
|
} else if (required && !formattedDate) {
|
|
139
143
|
error = 'required-input';
|
|
140
144
|
}
|
|
141
|
-
onValidationResult === null ||
|
|
145
|
+
(_onValidationResult = onValidationResult) === null || _onValidationResult === void 0 ? void 0 : _onValidationResult({
|
|
142
146
|
error
|
|
143
147
|
});
|
|
144
148
|
}, [
|
|
@@ -155,7 +159,8 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
155
159
|
setSelectedDate
|
|
156
160
|
]);
|
|
157
161
|
const setOpen = React.useCallback((newState)=>{
|
|
158
|
-
|
|
162
|
+
var _onOpenChange;
|
|
163
|
+
(_onOpenChange = onOpenChange) === null || _onOpenChange === void 0 ? void 0 : _onOpenChange(newState);
|
|
159
164
|
setOpenState(newState);
|
|
160
165
|
if (!open && !props.disabled) {
|
|
161
166
|
focus();
|
|
@@ -202,7 +207,7 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
202
207
|
preventNextFocusOpeningPicker
|
|
203
208
|
]);
|
|
204
209
|
const onInputChange = React.useCallback((ev, data)=>{
|
|
205
|
-
const { value: newValue
|
|
210
|
+
const { value: newValue } = data;
|
|
206
211
|
if (allowTextInput) {
|
|
207
212
|
if (open) {
|
|
208
213
|
dismissDatePickerPopup();
|
|
@@ -337,7 +342,7 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
337
342
|
root.onKeyDown = useEventCallback(mergeCallbacks(root.onKeyDown, onInputKeyDown));
|
|
338
343
|
root.onFocus = useEventCallback(mergeCallbacks(root.onFocus, onInputFocus));
|
|
339
344
|
root.onClick = useEventCallback(mergeCallbacks(root.onClick, onInputClick));
|
|
340
|
-
const { modalAttributes
|
|
345
|
+
const { modalAttributes } = useModalAttributes({
|
|
341
346
|
trapFocus: true,
|
|
342
347
|
alwaysFocusable: true,
|
|
343
348
|
legacyTrapFocus: false
|
|
@@ -354,7 +359,7 @@ const defaultParseDateFromString = (dateStr)=>{
|
|
|
354
359
|
},
|
|
355
360
|
elementType: 'div'
|
|
356
361
|
}) : undefined;
|
|
357
|
-
const { targetDocument
|
|
362
|
+
const { targetDocument } = useFluent();
|
|
358
363
|
useOnClickOutside({
|
|
359
364
|
element: targetDocument,
|
|
360
365
|
callback: (ev)=>dismissDatePickerPopup(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ArrowDown, Enter, Escape } from '@fluentui/keyboard-keys';\nimport { Calendar } from '../Calendar/Calendar';\nimport { CalendarMonthRegular } from '@fluentui/react-icons';\nimport { compareDatePart, DayOfWeek, FirstWeekOfYear } from '../../utils';\nimport { defaultDatePickerStrings } from './defaults';\nimport { Input } from '@fluentui/react-input';\nimport {\n mergeCallbacks,\n useControllableState,\n useEventCallback,\n useId,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n slot,\n} from '@fluentui/react-utilities';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopupPositioning } from '../../utils/usePopupPositioning';\nimport type { CalendarProps, ICalendar } from '../Calendar/Calendar.types';\nimport type { DatePickerProps, DatePickerState, DatePickerValidationResultData } from './DatePicker.types';\nimport type { InputProps, InputOnChangeData } from '@fluentui/react-input';\n\nfunction isDateOutOfBounds(date: Date, minDate?: Date, maxDate?: Date): boolean {\n return (!!minDate && compareDatePart(minDate!, date) > 0) || (!!maxDate && compareDatePart(maxDate!, date) < 0);\n}\n\nfunction useFocusLogic() {\n const inputRef = React.useRef<HTMLInputElement>(null);\n const preventFocusOpeningPicker = React.useRef(false);\n\n const focus = React.useCallback(() => {\n inputRef.current?.focus?.();\n }, []);\n\n const preventNextFocusOpeningPicker = React.useCallback(() => {\n preventFocusOpeningPicker.current = true;\n }, []);\n\n return [focus, inputRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] as const;\n}\n\nfunction usePopupVisibility(props: DatePickerProps) {\n const [open, setOpen] = useControllableState({\n initialState: false,\n defaultState: props.defaultOpen,\n state: props.open,\n });\n const isMounted = React.useRef(false);\n\n React.useEffect(\n () => {\n if (isMounted.current && !open) {\n // If DatePicker's menu (Calendar) is closed, run onAfterMenuDismiss\n props.onOpenChange?.(false);\n }\n isMounted.current = true;\n },\n // Should only run on allowTextInput or open change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [props.allowTextInput, open],\n );\n\n return [open, setOpen] as const;\n}\n\nfunction useSelectedDate({ formatDate, onSelectDate, value }: DatePickerProps) {\n const [selectedDate, setSelectedDateState] = useControllableState<Date | null | undefined>({\n initialState: null,\n state: value,\n });\n const [formattedDate, setFormattedDate] = React.useState(() => (value && formatDate ? formatDate(value) : ''));\n\n const setSelectedDate = (newDate: Date | null | undefined) => {\n onSelectDate?.(newDate);\n setSelectedDateState(newDate);\n setFormattedDate(newDate && formatDate ? formatDate(newDate) : '');\n };\n\n React.useEffect(() => {\n setFormattedDate(value && formatDate ? formatDate(value) : '');\n }, [formatDate, value]);\n\n return [selectedDate, formattedDate, setSelectedDate, setFormattedDate] as const;\n}\n\nconst defaultFormatDate = (date?: Date) => (date ? date.toDateString() : '');\nconst defaultParseDateFromString = (dateStr: string) => {\n const date = Date.parse(dateStr);\n return date ? new Date(date) : null;\n};\n\n/**\n * Create the state required to render DatePicker.\n *\n * The returned state can be modified with hooks such as useDatePickerStyles_unstable,\n * before being passed to renderDatePicker_unstable.\n *\n * @param props - props from this instance of DatePicker\n * @param ref - reference to root Input slot\n */\nexport const useDatePicker_unstable = (props: DatePickerProps, ref: React.Ref<HTMLInputElement>): DatePickerState => {\n const {\n allowTextInput = false,\n allFocusable = false,\n borderless = false,\n dateTimeFormatter,\n defaultOpen = false,\n disableAutoFocus = true,\n firstDayOfWeek = DayOfWeek.Sunday,\n firstWeekOfYear = FirstWeekOfYear.FirstDay,\n formatDate = defaultFormatDate,\n highlightCurrentMonth = false,\n highlightSelectedMonth = false,\n initialPickerDate = new Date(),\n inlinePopup = false,\n isMonthPickerVisible = true,\n maxDate,\n minDate,\n mountNode,\n onOpenChange,\n onSelectDate: onUserSelectDate,\n openOnClick = true,\n onValidationResult,\n parseDateFromString = defaultParseDateFromString,\n showCloseButton = false,\n showGoToToday = true,\n showMonthPickerAsOverlay = false,\n showWeekNumbers = false,\n strings = defaultDatePickerStrings,\n today,\n underlined = false,\n value,\n ...restOfProps\n } = props;\n const calendar = React.useRef<ICalendar>(null);\n const [focus, rootRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] = useFocusLogic();\n const [selectedDate, formattedDate, setSelectedDate, setFormattedDate] = useSelectedDate({\n formatDate,\n onSelectDate: onUserSelectDate,\n value,\n });\n const [open, setOpenState] = usePopupVisibility(props);\n const fieldContext = useFieldContext();\n const required = fieldContext?.required ?? props.required;\n const popupSurfaceId = useId('datePicker-popupSurface');\n\n const validateTextInput = React.useCallback(\n (date: Date | null = null): void => {\n let error: DatePickerValidationResultData['error'];\n\n if (allowTextInput) {\n if (formattedDate || date) {\n // Don't parse if the selected date has the same formatted string as what we're about to parse.\n // The formatted string might be ambiguous (ex: \"1/2/3\" or \"New Year Eve\") and the parser might\n // not be able to come up with the exact same date.\n if (selectedDate && formatDate && formatDate(date ?? selectedDate) === formattedDate) {\n return;\n }\n date = date || parseDateFromString!(formattedDate);\n\n // Check if date is null or date is an invalid date\n if (!date || isNaN(date.getTime())) {\n // Reset input if formatting is available\n setSelectedDate(selectedDate);\n error = 'invalid-input';\n } else {\n if (isDateOutOfBounds(date, minDate, maxDate)) {\n error = 'out-of-bounds';\n } else {\n setSelectedDate(date);\n }\n }\n } else {\n if (required) {\n error = 'required-input';\n }\n\n onUserSelectDate?.(date);\n }\n } else if (required && !formattedDate) {\n error = 'required-input';\n }\n\n onValidationResult?.({ error });\n },\n [\n allowTextInput,\n formatDate,\n formattedDate,\n maxDate,\n minDate,\n onUserSelectDate,\n onValidationResult,\n parseDateFromString,\n required,\n selectedDate,\n setSelectedDate,\n ],\n );\n\n const setOpen = React.useCallback(\n (newState: boolean) => {\n onOpenChange?.(newState);\n setOpenState(newState);\n\n if (!open && !props.disabled) {\n focus();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [focus, onOpenChange, props.disabled, setOpenState],\n );\n\n const dismissDatePickerPopup = React.useCallback(\n (newlySelectedDate?: Date | null): void => {\n if (open) {\n setOpen(false);\n\n validateTextInput(newlySelectedDate);\n if (!allowTextInput && newlySelectedDate) {\n setSelectedDate(newlySelectedDate);\n }\n }\n },\n [allowTextInput, open, setOpen, setSelectedDate, validateTextInput],\n );\n\n const showDatePickerPopup = React.useCallback((): void => {\n if (!open) {\n preventNextFocusOpeningPicker();\n setOpen(true);\n }\n }, [open, preventNextFocusOpeningPicker, setOpen]);\n\n /**\n * Callback for closing the calendar callout\n */\n const calendarDismissed = React.useCallback(\n (newlySelectedDate?: Date): void => {\n preventNextFocusOpeningPicker();\n dismissDatePickerPopup(newlySelectedDate);\n },\n [dismissDatePickerPopup, preventNextFocusOpeningPicker],\n );\n\n const onInputChange = React.useCallback(\n (ev: React.ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => {\n const { value: newValue } = data;\n\n if (allowTextInput) {\n if (open) {\n dismissDatePickerPopup();\n }\n\n setFormattedDate(newValue);\n }\n },\n [allowTextInput, dismissDatePickerPopup, open, setFormattedDate],\n );\n\n const onInputBlur: React.FocusEventHandler<HTMLInputElement> = React.useCallback((): void => {\n validateTextInput();\n }, [validateTextInput]);\n\n const onInputKeyDown = React.useCallback(\n (ev: React.KeyboardEvent<HTMLElement>): void => {\n switch (ev.key) {\n case Enter:\n ev.preventDefault();\n ev.stopPropagation();\n if (!open) {\n validateTextInput();\n showDatePickerPopup();\n } else {\n // When DatePicker allows input date string directly,\n // it is expected to hit another enter to close the popup\n if (props.allowTextInput) {\n dismissDatePickerPopup();\n }\n }\n break;\n\n case Escape:\n ev.stopPropagation();\n ev.preventDefault();\n if (open) {\n calendarDismissed();\n }\n break;\n\n case ArrowDown:\n ev.preventDefault();\n if (ev.altKey && !open) {\n showDatePickerPopup();\n }\n break;\n\n default:\n break;\n }\n },\n [calendarDismissed, dismissDatePickerPopup, open, props.allowTextInput, showDatePickerPopup, validateTextInput],\n );\n\n const onInputFocus: React.FocusEventHandler<HTMLInputElement> = React.useCallback((): void => {\n if (disableAutoFocus) {\n return;\n }\n\n if (!allowTextInput) {\n if (!preventFocusOpeningPicker.current) {\n showDatePickerPopup();\n }\n preventFocusOpeningPicker.current = false;\n }\n }, [allowTextInput, disableAutoFocus, preventFocusOpeningPicker, showDatePickerPopup]);\n\n const onInputClick: React.MouseEventHandler<HTMLInputElement> = React.useCallback((): void => {\n // default openOnClick to !props.disableAutoFocus for legacy support of disableAutoFocus behavior\n if ((props.openOnClick || !props.disableAutoFocus) && !open && !props.disabled) {\n showDatePickerPopup();\n return;\n }\n\n if (allowTextInput) {\n dismissDatePickerPopup();\n }\n }, [\n allowTextInput,\n dismissDatePickerPopup,\n open,\n props.disabled,\n props.disableAutoFocus,\n props.openOnClick,\n showDatePickerPopup,\n ]);\n\n const onIconClick = (ev: React.MouseEvent<HTMLElement>): void => {\n ev.stopPropagation();\n if (!open && !props.disabled) {\n showDatePickerPopup();\n } else if (props.allowTextInput) {\n dismissDatePickerPopup();\n }\n };\n\n const inputAppearance: InputProps['appearance'] = underlined\n ? 'underline'\n : borderless\n ? 'filled-lighter'\n : 'outline';\n\n const [triggerWrapperRef, popupRef] = usePopupPositioning(props);\n const root = slot.always(restOfProps, {\n defaultProps: {\n appearance: inputAppearance,\n 'aria-controls': open ? popupSurfaceId : undefined,\n 'aria-expanded': open,\n 'aria-haspopup': 'dialog',\n contentAfter: <CalendarMonthRegular onClick={onIconClick as unknown as React.MouseEventHandler<SVGElement>} />,\n readOnly: !allowTextInput,\n role: 'combobox',\n },\n elementType: Input,\n });\n\n const inputRoot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': open ? popupSurfaceId : undefined,\n ref: triggerWrapperRef,\n },\n elementType: 'span',\n });\n inputRoot.ref = useMergedRefs(inputRoot.ref, triggerWrapperRef);\n root.root = inputRoot;\n const inputShorthand = slot.always(props.input, {\n elementType: 'input',\n });\n inputShorthand.ref = useMergedRefs(inputShorthand.ref, ref, rootRef);\n root.input = inputShorthand;\n root.onChange = useEventCallback(mergeCallbacks(root.onChange, onInputChange));\n root.onBlur = useEventCallback(mergeCallbacks(root.onBlur, onInputBlur));\n root.onKeyDown = useEventCallback(mergeCallbacks(root.onKeyDown, onInputKeyDown));\n root.onFocus = useEventCallback(mergeCallbacks(root.onFocus, onInputFocus));\n root.onClick = useEventCallback(mergeCallbacks(root.onClick, onInputClick));\n const { modalAttributes } = useModalAttributes({ trapFocus: true, alwaysFocusable: true, legacyTrapFocus: false });\n const popupSurface = open\n ? slot.optional(props.popupSurface, {\n renderByDefault: true,\n defaultProps: {\n 'aria-label': 'Calendar',\n 'aria-modal': true,\n id: popupSurfaceId,\n role: 'dialog',\n ref: popupRef,\n ...modalAttributes,\n },\n elementType: 'div',\n })\n : undefined;\n const { targetDocument } = useFluent();\n useOnClickOutside({\n element: targetDocument,\n callback: ev => dismissDatePickerPopup(),\n refs: [triggerWrapperRef, popupRef],\n disabled: !open,\n });\n useOnScrollOutside({\n element: targetDocument,\n callback: ev => dismissDatePickerPopup(),\n refs: [triggerWrapperRef, popupRef],\n disabled: !open,\n }); // When the popup is opened, focus should go to the calendar.\n // In v8 this was done by focusing after the callout was positioned, but in v9 this can be simulated by using a\n // useEffect hook.\n React.useEffect(() => {\n if (open && !props.disabled && calendar.current) {\n calendar.current.focus();\n }\n }, [disableAutoFocus, open, props.disabled]);\n const calendarShorthand = slot.always(props.calendar, {\n defaultProps: {\n allFocusable,\n componentRef: calendar,\n dateTimeFormatter,\n firstDayOfWeek,\n firstWeekOfYear,\n highlightCurrentMonth,\n highlightSelectedMonth,\n isMonthPickerVisible,\n maxDate,\n minDate,\n showCloseButton,\n showGoToToday,\n showMonthPickerAsOverlay,\n showWeekNumbers,\n strings,\n today,\n value: selectedDate || initialPickerDate,\n },\n elementType: Calendar,\n });\n calendarShorthand.onDismiss = useEventCallback(mergeCallbacks(calendarShorthand.onDismiss, calendarDismissed));\n calendarShorthand.onSelectDate = useEventCallback(mergeCallbacks(calendarShorthand.onSelectDate, calendarDismissed));\n const state: DatePickerState = {\n disabled: !!props.disabled,\n inlinePopup,\n components: { root: Input, calendar: Calendar as React.FC<Partial<CalendarProps>>, popupSurface: 'div' },\n calendar: calendarShorthand,\n mountNode,\n root,\n popupSurface,\n };\n\n state.root.value = formattedDate;\n\n return state;\n};\n"],"names":["React","ArrowDown","Enter","Escape","Calendar","CalendarMonthRegular","compareDatePart","DayOfWeek","FirstWeekOfYear","defaultDatePickerStrings","Input","mergeCallbacks","useControllableState","useEventCallback","useId","useMergedRefs","useOnClickOutside","useOnScrollOutside","slot","useFieldContext_unstable","useFieldContext","useFluent_unstable","useFluent","useModalAttributes","usePopupPositioning","isDateOutOfBounds","date","minDate","maxDate","useFocusLogic","inputRef","useRef","preventFocusOpeningPicker","focus","useCallback","current","preventNextFocusOpeningPicker","usePopupVisibility","props","open","setOpen","initialState","defaultState","defaultOpen","state","isMounted","useEffect","onOpenChange","allowTextInput","useSelectedDate","formatDate","onSelectDate","value","selectedDate","setSelectedDateState","formattedDate","setFormattedDate","useState","setSelectedDate","newDate","defaultFormatDate","toDateString","defaultParseDateFromString","dateStr","Date","parse","useDatePicker_unstable","ref","allFocusable","borderless","dateTimeFormatter","disableAutoFocus","firstDayOfWeek","Sunday","firstWeekOfYear","FirstDay","highlightCurrentMonth","highlightSelectedMonth","initialPickerDate","inlinePopup","isMonthPickerVisible","mountNode","onUserSelectDate","openOnClick","onValidationResult","parseDateFromString","showCloseButton","showGoToToday","showMonthPickerAsOverlay","showWeekNumbers","strings","today","underlined","restOfProps","calendar","rootRef","setOpenState","fieldContext","required","popupSurfaceId","validateTextInput","error","isNaN","getTime","newState","disabled","dismissDatePickerPopup","newlySelectedDate","showDatePickerPopup","calendarDismissed","onInputChange","ev","data","newValue","onInputBlur","onInputKeyDown","key","preventDefault","stopPropagation","altKey","onInputFocus","onInputClick","onIconClick","inputAppearance","triggerWrapperRef","popupRef","root","always","defaultProps","appearance","undefined","contentAfter","onClick","readOnly","role","elementType","inputRoot","inputShorthand","input","onChange","onBlur","onKeyDown","onFocus","modalAttributes","trapFocus","alwaysFocusable","legacyTrapFocus","popupSurface","optional","renderByDefault","id","targetDocument","element","callback","refs","calendarShorthand","componentRef","onDismiss","components"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,EAAEC,KAAK,EAAEC,MAAM,QAAQ,0BAA0B;AACnE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,SAAS,EAAEC,eAAe,QAAQ,cAAc;AAC1E,SAASC,wBAAwB,QAAQ,aAAa;AACtD,SAASC,KAAK,QAAQ,wBAAwB;AAC9C,SACEC,cAAc,EACdC,oBAAoB,EACpBC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,IAAI,QACC,4BAA4B;AACnC,SAASC,4BAA4BC,eAAe,QAAQ,wBAAwB;AACpF,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,mBAAmB,QAAQ,kCAAkC;AAKtE,SAASC,kBAAkBC,IAAU,EAAEC,OAAc,EAAEC,OAAc,EAAW;IAC9E,OAAO,AAAC,CAAC,CAACD,WAAWrB,gBAAgBqB,SAAUD,QAAQ,KAAO,CAAC,CAACE,WAAWtB,gBAAgBsB,SAAUF,QAAQ;AAC/G;AAEA,SAASG,gBAAgB;IACvB,MAAMC,W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ACF,KAAK;QACxB,CAAC;IACH,GAAG;QAACsC;QAAkBhC;QAAMD,MAAMmE,QAAQ;KAAC;IAC3C,MAAMkD,oBAAoBzI,KAAK6G,MAAM,CAACzF,MAAMwD,QAAQ,EAAE;QACpDkC,cAAc;YACZ5D;YACAwF,cAAc9D;YACdxB;YACAE;YACAE;YACAE;YACAC;YACAG;YACApD;YACAD;YACA2D;YACAC;YACAC;YACAC;YACAC;YACAC;YACAvC,OAAOC,gBAAgByB;QACzB;QACAyD,aAAanI;IACf;IACAuJ,kBAAkBE,SAAS,GAAGhJ,iBAAiBF,eAAegJ,kBAAkBE,SAAS,EAAEhD;IAC3F8C,kBAAkBxG,YAAY,GAAGtC,iBAAiBF,eAAegJ,kBAAkBxG,YAAY,EAAE0D;IACjG,MAAMjE,QAAyB;QAC7B6D,UAAU,CAAC,CAACnE,MAAMmE,QAAQ;QAC1B1B;QACA+E,YAAY;YAAEhC,MAAMpH;YAAOoF,UAAU1F;YAA8C+I,cAAc;QAAM;QACvGrD,UAAU6D;QACV1E;QACA6C;QACAqB;IACF;IAEAvG,MAAMkF,IAAI,CAAC1E,KAAK,GAAGG;IAEnB,OAAOX;AACT,EAAE"}
|
|
1
|
+
{"version":3,"sources":["useDatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ArrowDown, Enter, Escape } from '@fluentui/keyboard-keys';\nimport { Calendar } from '../Calendar/Calendar';\nimport { CalendarMonthRegular } from '@fluentui/react-icons';\nimport { compareDatePart, DayOfWeek, FirstWeekOfYear } from '../../utils';\nimport { defaultDatePickerStrings } from './defaults';\nimport { Input } from '@fluentui/react-input';\nimport {\n mergeCallbacks,\n useControllableState,\n useEventCallback,\n useId,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n slot,\n} from '@fluentui/react-utilities';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useModalAttributes } from '@fluentui/react-tabster';\nimport { usePopupPositioning } from '../../utils/usePopupPositioning';\nimport type { CalendarProps, ICalendar } from '../Calendar/Calendar.types';\nimport type { DatePickerProps, DatePickerState, DatePickerValidationResultData } from './DatePicker.types';\nimport type { InputProps, InputOnChangeData } from '@fluentui/react-input';\n\nfunction isDateOutOfBounds(date: Date, minDate?: Date, maxDate?: Date): boolean {\n return (!!minDate && compareDatePart(minDate!, date) > 0) || (!!maxDate && compareDatePart(maxDate!, date) < 0);\n}\n\nfunction useFocusLogic() {\n const inputRef = React.useRef<HTMLInputElement>(null);\n const preventFocusOpeningPicker = React.useRef(false);\n\n const focus = React.useCallback(() => {\n inputRef.current?.focus?.();\n }, []);\n\n const preventNextFocusOpeningPicker = React.useCallback(() => {\n preventFocusOpeningPicker.current = true;\n }, []);\n\n return [focus, inputRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] as const;\n}\n\nfunction usePopupVisibility(props: DatePickerProps) {\n const [open, setOpen] = useControllableState({\n initialState: false,\n defaultState: props.defaultOpen,\n state: props.open,\n });\n const isMounted = React.useRef(false);\n\n React.useEffect(\n () => {\n if (isMounted.current && !open) {\n // If DatePicker's menu (Calendar) is closed, run onAfterMenuDismiss\n props.onOpenChange?.(false);\n }\n isMounted.current = true;\n },\n // Should only run on allowTextInput or open change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [props.allowTextInput, open],\n );\n\n return [open, setOpen] as const;\n}\n\nfunction useSelectedDate({ formatDate, onSelectDate, value }: DatePickerProps) {\n const [selectedDate, setSelectedDateState] = useControllableState<Date | null | undefined>({\n initialState: null,\n state: value,\n });\n const [formattedDate, setFormattedDate] = React.useState(() => (value && formatDate ? formatDate(value) : ''));\n\n const setSelectedDate = (newDate: Date | null | undefined) => {\n onSelectDate?.(newDate);\n setSelectedDateState(newDate);\n setFormattedDate(newDate && formatDate ? formatDate(newDate) : '');\n };\n\n React.useEffect(() => {\n setFormattedDate(value && formatDate ? formatDate(value) : '');\n }, [formatDate, value]);\n\n return [selectedDate, formattedDate, setSelectedDate, setFormattedDate] as const;\n}\n\nconst defaultFormatDate = (date?: Date) => (date ? date.toDateString() : '');\nconst defaultParseDateFromString = (dateStr: string) => {\n const date = Date.parse(dateStr);\n return date ? new Date(date) : null;\n};\n\n/**\n * Create the state required to render DatePicker.\n *\n * The returned state can be modified with hooks such as useDatePickerStyles_unstable,\n * before being passed to renderDatePicker_unstable.\n *\n * @param props - props from this instance of DatePicker\n * @param ref - reference to root Input slot\n */\nexport const useDatePicker_unstable = (props: DatePickerProps, ref: React.Ref<HTMLInputElement>): DatePickerState => {\n const {\n allowTextInput = false,\n allFocusable = false,\n borderless = false,\n dateTimeFormatter,\n defaultOpen = false,\n disableAutoFocus = true,\n firstDayOfWeek = DayOfWeek.Sunday,\n firstWeekOfYear = FirstWeekOfYear.FirstDay,\n formatDate = defaultFormatDate,\n highlightCurrentMonth = false,\n highlightSelectedMonth = false,\n initialPickerDate = new Date(),\n inlinePopup = false,\n isMonthPickerVisible = true,\n maxDate,\n minDate,\n mountNode,\n onOpenChange,\n onSelectDate: onUserSelectDate,\n openOnClick = true,\n onValidationResult,\n parseDateFromString = defaultParseDateFromString,\n showCloseButton = false,\n showGoToToday = true,\n showMonthPickerAsOverlay = false,\n showWeekNumbers = false,\n strings = defaultDatePickerStrings,\n today,\n underlined = false,\n value,\n ...restOfProps\n } = props;\n const calendar = React.useRef<ICalendar>(null);\n const [focus, rootRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] = useFocusLogic();\n const [selectedDate, formattedDate, setSelectedDate, setFormattedDate] = useSelectedDate({\n formatDate,\n onSelectDate: onUserSelectDate,\n value,\n });\n const [open, setOpenState] = usePopupVisibility(props);\n const fieldContext = useFieldContext();\n const required = fieldContext?.required ?? props.required;\n const popupSurfaceId = useId('datePicker-popupSurface');\n\n const validateTextInput = React.useCallback(\n (date: Date | null = null): void => {\n let error: DatePickerValidationResultData['error'];\n\n if (allowTextInput) {\n if (formattedDate || date) {\n // Don't parse if the selected date has the same formatted string as what we're about to parse.\n // The formatted string might be ambiguous (ex: \"1/2/3\" or \"New Year Eve\") and the parser might\n // not be able to come up with the exact same date.\n if (selectedDate && formatDate && formatDate(date ?? selectedDate) === formattedDate) {\n return;\n }\n date = date || parseDateFromString!(formattedDate);\n\n // Check if date is null or date is an invalid date\n if (!date || isNaN(date.getTime())) {\n // Reset input if formatting is available\n setSelectedDate(selectedDate);\n error = 'invalid-input';\n } else {\n if (isDateOutOfBounds(date, minDate, maxDate)) {\n error = 'out-of-bounds';\n } else {\n setSelectedDate(date);\n }\n }\n } else {\n if (required) {\n error = 'required-input';\n }\n\n onUserSelectDate?.(date);\n }\n } else if (required && !formattedDate) {\n error = 'required-input';\n }\n\n onValidationResult?.({ error });\n },\n [\n allowTextInput,\n formatDate,\n formattedDate,\n maxDate,\n minDate,\n onUserSelectDate,\n onValidationResult,\n parseDateFromString,\n required,\n selectedDate,\n setSelectedDate,\n ],\n );\n\n const setOpen = React.useCallback(\n (newState: boolean) => {\n onOpenChange?.(newState);\n setOpenState(newState);\n\n if (!open && !props.disabled) {\n focus();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [focus, onOpenChange, props.disabled, setOpenState],\n );\n\n const dismissDatePickerPopup = React.useCallback(\n (newlySelectedDate?: Date | null): void => {\n if (open) {\n setOpen(false);\n\n validateTextInput(newlySelectedDate);\n if (!allowTextInput && newlySelectedDate) {\n setSelectedDate(newlySelectedDate);\n }\n }\n },\n [allowTextInput, open, setOpen, setSelectedDate, validateTextInput],\n );\n\n const showDatePickerPopup = React.useCallback((): void => {\n if (!open) {\n preventNextFocusOpeningPicker();\n setOpen(true);\n }\n }, [open, preventNextFocusOpeningPicker, setOpen]);\n\n /**\n * Callback for closing the calendar callout\n */\n const calendarDismissed = React.useCallback(\n (newlySelectedDate?: Date): void => {\n preventNextFocusOpeningPicker();\n dismissDatePickerPopup(newlySelectedDate);\n },\n [dismissDatePickerPopup, preventNextFocusOpeningPicker],\n );\n\n const onInputChange = React.useCallback(\n (ev: React.ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => {\n const { value: newValue } = data;\n\n if (allowTextInput) {\n if (open) {\n dismissDatePickerPopup();\n }\n\n setFormattedDate(newValue);\n }\n },\n [allowTextInput, dismissDatePickerPopup, open, setFormattedDate],\n );\n\n const onInputBlur: React.FocusEventHandler<HTMLInputElement> = React.useCallback((): void => {\n validateTextInput();\n }, [validateTextInput]);\n\n const onInputKeyDown = React.useCallback(\n (ev: React.KeyboardEvent<HTMLElement>): void => {\n switch (ev.key) {\n case Enter:\n ev.preventDefault();\n ev.stopPropagation();\n if (!open) {\n validateTextInput();\n showDatePickerPopup();\n } else {\n // When DatePicker allows input date string directly,\n // it is expected to hit another enter to close the popup\n if (props.allowTextInput) {\n dismissDatePickerPopup();\n }\n }\n break;\n\n case Escape:\n ev.stopPropagation();\n ev.preventDefault();\n if (open) {\n calendarDismissed();\n }\n break;\n\n case ArrowDown:\n ev.preventDefault();\n if (ev.altKey && !open) {\n showDatePickerPopup();\n }\n break;\n\n default:\n break;\n }\n },\n [calendarDismissed, dismissDatePickerPopup, open, props.allowTextInput, showDatePickerPopup, validateTextInput],\n );\n\n const onInputFocus: React.FocusEventHandler<HTMLInputElement> = React.useCallback((): void => {\n if (disableAutoFocus) {\n return;\n }\n\n if (!allowTextInput) {\n if (!preventFocusOpeningPicker.current) {\n showDatePickerPopup();\n }\n preventFocusOpeningPicker.current = false;\n }\n }, [allowTextInput, disableAutoFocus, preventFocusOpeningPicker, showDatePickerPopup]);\n\n const onInputClick: React.MouseEventHandler<HTMLInputElement> = React.useCallback((): void => {\n // default openOnClick to !props.disableAutoFocus for legacy support of disableAutoFocus behavior\n if ((props.openOnClick || !props.disableAutoFocus) && !open && !props.disabled) {\n showDatePickerPopup();\n return;\n }\n\n if (allowTextInput) {\n dismissDatePickerPopup();\n }\n }, [\n allowTextInput,\n dismissDatePickerPopup,\n open,\n props.disabled,\n props.disableAutoFocus,\n props.openOnClick,\n showDatePickerPopup,\n ]);\n\n const onIconClick = (ev: React.MouseEvent<HTMLElement>): void => {\n ev.stopPropagation();\n if (!open && !props.disabled) {\n showDatePickerPopup();\n } else if (props.allowTextInput) {\n dismissDatePickerPopup();\n }\n };\n\n const inputAppearance: InputProps['appearance'] = underlined\n ? 'underline'\n : borderless\n ? 'filled-lighter'\n : 'outline';\n\n const [triggerWrapperRef, popupRef] = usePopupPositioning(props);\n const root = slot.always(restOfProps, {\n defaultProps: {\n appearance: inputAppearance,\n 'aria-controls': open ? popupSurfaceId : undefined,\n 'aria-expanded': open,\n 'aria-haspopup': 'dialog',\n contentAfter: <CalendarMonthRegular onClick={onIconClick as unknown as React.MouseEventHandler<SVGElement>} />,\n readOnly: !allowTextInput,\n role: 'combobox',\n },\n elementType: Input,\n });\n\n const inputRoot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': open ? popupSurfaceId : undefined,\n ref: triggerWrapperRef,\n },\n elementType: 'span',\n });\n inputRoot.ref = useMergedRefs(inputRoot.ref, triggerWrapperRef);\n root.root = inputRoot;\n const inputShorthand = slot.always(props.input, {\n elementType: 'input',\n });\n inputShorthand.ref = useMergedRefs(inputShorthand.ref, ref, rootRef);\n root.input = inputShorthand;\n root.onChange = useEventCallback(mergeCallbacks(root.onChange, onInputChange));\n root.onBlur = useEventCallback(mergeCallbacks(root.onBlur, onInputBlur));\n root.onKeyDown = useEventCallback(mergeCallbacks(root.onKeyDown, onInputKeyDown));\n root.onFocus = useEventCallback(mergeCallbacks(root.onFocus, onInputFocus));\n root.onClick = useEventCallback(mergeCallbacks(root.onClick, onInputClick));\n const { modalAttributes } = useModalAttributes({ trapFocus: true, alwaysFocusable: true, legacyTrapFocus: false });\n const popupSurface = open\n ? slot.optional(props.popupSurface, {\n renderByDefault: true,\n defaultProps: {\n 'aria-label': 'Calendar',\n 'aria-modal': true,\n id: popupSurfaceId,\n role: 'dialog',\n ref: popupRef,\n ...modalAttributes,\n },\n elementType: 'div',\n })\n : undefined;\n const { targetDocument } = useFluent();\n useOnClickOutside({\n element: targetDocument,\n callback: ev => dismissDatePickerPopup(),\n refs: [triggerWrapperRef, popupRef],\n disabled: !open,\n });\n useOnScrollOutside({\n element: targetDocument,\n callback: ev => dismissDatePickerPopup(),\n refs: [triggerWrapperRef, popupRef],\n disabled: !open,\n }); // When the popup is opened, focus should go to the calendar.\n // In v8 this was done by focusing after the callout was positioned, but in v9 this can be simulated by using a\n // useEffect hook.\n React.useEffect(() => {\n if (open && !props.disabled && calendar.current) {\n calendar.current.focus();\n }\n }, [disableAutoFocus, open, props.disabled]);\n const calendarShorthand = slot.always(props.calendar, {\n defaultProps: {\n allFocusable,\n componentRef: calendar,\n dateTimeFormatter,\n firstDayOfWeek,\n firstWeekOfYear,\n highlightCurrentMonth,\n highlightSelectedMonth,\n isMonthPickerVisible,\n maxDate,\n minDate,\n showCloseButton,\n showGoToToday,\n showMonthPickerAsOverlay,\n showWeekNumbers,\n strings,\n today,\n value: selectedDate || initialPickerDate,\n },\n elementType: Calendar,\n });\n calendarShorthand.onDismiss = useEventCallback(mergeCallbacks(calendarShorthand.onDismiss, calendarDismissed));\n calendarShorthand.onSelectDate = useEventCallback(mergeCallbacks(calendarShorthand.onSelectDate, calendarDismissed));\n const state: DatePickerState = {\n disabled: !!props.disabled,\n inlinePopup,\n components: { root: Input, calendar: Calendar as React.FC<Partial<CalendarProps>>, popupSurface: 'div' },\n calendar: calendarShorthand,\n mountNode,\n root,\n popupSurface,\n };\n\n state.root.value = formattedDate;\n\n return state;\n};\n"],"names":["React","ArrowDown","Enter","Escape","Calendar","CalendarMonthRegular","compareDatePart","DayOfWeek","FirstWeekOfYear","defaultDatePickerStrings","Input","mergeCallbacks","useControllableState","useEventCallback","useId","useMergedRefs","useOnClickOutside","useOnScrollOutside","slot","useFieldContext_unstable","useFieldContext","useFluent_unstable","useFluent","useModalAttributes","usePopupPositioning","isDateOutOfBounds","date","minDate","maxDate","useFocusLogic","inputRef","useRef","preventFocusOpeningPicker","focus","useCallback","current","preventNextFocusOpeningPicker","usePopupVisibility","props","open","setOpen","initialState","defaultState","defaultOpen","state","isMounted","useEffect","onOpenChange","allowTextInput","useSelectedDate","formatDate","onSelectDate","value","selectedDate","setSelectedDateState","formattedDate","setFormattedDate","useState","setSelectedDate","newDate","defaultFormatDate","toDateString","defaultParseDateFromString","dateStr","Date","parse","useDatePicker_unstable","ref","fieldContext","allFocusable","borderless","dateTimeFormatter","disableAutoFocus","firstDayOfWeek","Sunday","firstWeekOfYear","FirstDay","highlightCurrentMonth","highlightSelectedMonth","initialPickerDate","inlinePopup","isMonthPickerVisible","mountNode","onUserSelectDate","openOnClick","onValidationResult","parseDateFromString","showCloseButton","showGoToToday","showMonthPickerAsOverlay","showWeekNumbers","strings","today","underlined","restOfProps","calendar","rootRef","setOpenState","required","popupSurfaceId","validateTextInput","error","isNaN","getTime","newState","disabled","dismissDatePickerPopup","newlySelectedDate","showDatePickerPopup","calendarDismissed","onInputChange","ev","data","newValue","onInputBlur","onInputKeyDown","key","preventDefault","stopPropagation","altKey","onInputFocus","onInputClick","onIconClick","inputAppearance","triggerWrapperRef","popupRef","root","always","defaultProps","appearance","undefined","contentAfter","onClick","readOnly","role","elementType","inputRoot","inputShorthand","input","onChange","onBlur","onKeyDown","onFocus","modalAttributes","trapFocus","alwaysFocusable","legacyTrapFocus","popupSurface","optional","renderByDefault","id","targetDocument","element","callback","refs","calendarShorthand","componentRef","onDismiss","components"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,EAAEC,KAAK,EAAEC,MAAM,QAAQ,0BAA0B;AACnE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,SAAS,EAAEC,eAAe,QAAQ,cAAc;AAC1E,SAASC,wBAAwB,QAAQ,aAAa;AACtD,SAASC,KAAK,QAAQ,wBAAwB;AAC9C,SACEC,cAAc,EACdC,oBAAoB,EACpBC,gBAAgB,EAChBC,KAAK,EAC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YACZ3D;YACAuF,cAAc7D;YACdxB;YACAE;YACAE;YACAE;YACAC;YACAG;YACArD;YACAD;YACA4D;YACAC;YACAC;YACAC;YACAC;YACAC;YACAxC,OAAOC,gBAAgB0B;QACzB;QACAwD,aAAanI;IACf;IACAuJ,kBAAkBE,SAAS,GAAGhJ,iBAAiBF,eAAegJ,kBAAkBE,SAAS,EAAEhD;IAC3F8C,kBAAkBxG,YAAY,GAAGtC,iBAAiBF,eAAegJ,kBAAkBxG,YAAY,EAAE0D;IACjG,MAAMjE,QAAyB;QAC7B6D,UAAU,CAAC,CAACnE,MAAMmE,QAAQ;QAC1BzB;QACA8E,YAAY;YAAEhC,MAAMpH;YAAOqF,UAAU3F;YAA8C+I,cAAc;QAAM;QACvGpD,UAAU4D;QACVzE;QACA4C;QACAqB;IACF;IAEAvG,MAAMkF,IAAI,CAAC1E,KAAK,GAAGG;IAEnB,OAAOX;AACT,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__resetStyles","__styles","mergeClasses","tokens","typographyStyles","datePickerClassNames","root","calendar","popupSurface","useStyles","base","qhf8xq","Bceei9c","xfaavh","disabled","d","usePopupSurfaceClassName","useDatePickerStyles_unstable","state","styles","popupSurfaceClassName","className"],"sources":["useDatePickerStyles.styles.js"],"sourcesContent":["import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\nexport const datePickerClassNames = {\n root: 'fui-DatePicker',\n calendar: 'fui-DatePicker__calendar',\n popupSurface: 'fui-DatePicker__popupSurface'\n};\nconst useStyles = makeStyles({\n base: {\n position: 'relative',\n cursor: 'pointer',\n '& input': {\n cursor: 'pointer'\n }\n },\n disabled: {\n cursor: 'default',\n '& input': {\n cursor: 'default'\n }\n }\n});\nconst usePopupSurfaceClassName = makeResetStyles({\n backgroundColor: tokens.colorNeutralBackground1,\n boxShadow: tokens.shadow16,\n borderRadius: tokens.borderRadiusMedium,\n borderWidth: '1px',\n borderStyle: 'solid',\n borderColor: tokens.colorTransparentStroke,\n display: 'inline-flex',\n color: tokens.colorNeutralForeground1,\n ...typographyStyles.body1\n});\n/**\n * Apply styling to the DatePicker slots based on the state\n */ export const useDatePickerStyles_unstable = (state)=>{\n const styles = useStyles();\n const popupSurfaceClassName = usePopupSurfaceClassName();\n const { disabled
|
|
1
|
+
{"version":3,"names":["__resetStyles","__styles","mergeClasses","tokens","typographyStyles","datePickerClassNames","root","calendar","popupSurface","useStyles","base","qhf8xq","Bceei9c","xfaavh","disabled","d","usePopupSurfaceClassName","useDatePickerStyles_unstable","state","styles","popupSurfaceClassName","className"],"sources":["useDatePickerStyles.styles.js"],"sourcesContent":["import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\nexport const datePickerClassNames = {\n root: 'fui-DatePicker',\n calendar: 'fui-DatePicker__calendar',\n popupSurface: 'fui-DatePicker__popupSurface'\n};\nconst useStyles = makeStyles({\n base: {\n position: 'relative',\n cursor: 'pointer',\n '& input': {\n cursor: 'pointer'\n }\n },\n disabled: {\n cursor: 'default',\n '& input': {\n cursor: 'default'\n }\n }\n});\nconst usePopupSurfaceClassName = makeResetStyles({\n backgroundColor: tokens.colorNeutralBackground1,\n boxShadow: tokens.shadow16,\n borderRadius: tokens.borderRadiusMedium,\n borderWidth: '1px',\n borderStyle: 'solid',\n borderColor: tokens.colorTransparentStroke,\n display: 'inline-flex',\n color: tokens.colorNeutralForeground1,\n ...typographyStyles.body1\n});\n/**\n * Apply styling to the DatePicker slots based on the state\n */ export const useDatePickerStyles_unstable = (state)=>{\n const styles = useStyles();\n const popupSurfaceClassName = usePopupSurfaceClassName();\n const { disabled } = state;\n state.root.className = mergeClasses(datePickerClassNames.root, styles.base, disabled && styles.disabled, state.root.className);\n if (state.popupSurface) {\n state.popupSurface.className = mergeClasses(datePickerClassNames.popupSurface, popupSurfaceClassName, state.popupSurface.className);\n }\n state.calendar.className = mergeClasses(dat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CAAC"}
|
|
@@ -6,7 +6,7 @@ import { compareDatePart, addDays } from '../dateMath/dateMath';
|
|
|
6
6
|
* Returns closest available date given the restriction `options`, or undefined otherwise
|
|
7
7
|
* @param options - list of search options
|
|
8
8
|
*/ export const findAvailableDate = (options)=>{
|
|
9
|
-
const { targetDate
|
|
9
|
+
const { targetDate, initialDate, direction, ...restrictedDateOptions } = options;
|
|
10
10
|
let availableDate = targetDate;
|
|
11
11
|
// if the target date is available, return it immediately
|
|
12
12
|
if (!isRestrictedDate(targetDate, restrictedDateOptions)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["findAvailableDate.ts"],"sourcesContent":["import { AvailableDateOptions } from './dateGrid.types';\n\nimport { isRestrictedDate } from './isRestrictedDate';\n\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { compareDatePart, addDays } from '../dateMath/dateMath';\n\n/**\n * Returns closest available date given the restriction `options`, or undefined otherwise\n * @param options - list of search options\n */\nexport const findAvailableDate = (options: AvailableDateOptions): Date | undefined => {\n const { targetDate, initialDate, direction, ...restrictedDateOptions } = options;\n let availableDate = targetDate;\n // if the target date is available, return it immediately\n if (!isRestrictedDate(targetDate, restrictedDateOptions)) {\n return targetDate;\n }\n\n while (\n compareDatePart(initialDate, availableDate) !== 0 &&\n isRestrictedDate(availableDate, restrictedDateOptions) &&\n !isAfterMaxDate(availableDate, restrictedDateOptions) &&\n !isBeforeMinDate(availableDate, restrictedDateOptions)\n ) {\n availableDate = addDays(availableDate, direction);\n }\n\n if (compareDatePart(initialDate, availableDate) !== 0 && !isRestrictedDate(availableDate, restrictedDateOptions)) {\n return availableDate;\n }\n\n return undefined;\n};\n"],"names":["isRestrictedDate","isAfterMaxDate","isBeforeMinDate","compareDatePart","addDays","findAvailableDate","options","targetDate","initialDate","direction","restrictedDateOptions","availableDate","undefined"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,qBAAqB;AAEtD,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,eAAe,EAAEC,OAAO,QAAQ,uBAAuB;AAEhE;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC
|
|
1
|
+
{"version":3,"sources":["findAvailableDate.ts"],"sourcesContent":["import { AvailableDateOptions } from './dateGrid.types';\n\nimport { isRestrictedDate } from './isRestrictedDate';\n\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { compareDatePart, addDays } from '../dateMath/dateMath';\n\n/**\n * Returns closest available date given the restriction `options`, or undefined otherwise\n * @param options - list of search options\n */\nexport const findAvailableDate = (options: AvailableDateOptions): Date | undefined => {\n const { targetDate, initialDate, direction, ...restrictedDateOptions } = options;\n let availableDate = targetDate;\n // if the target date is available, return it immediately\n if (!isRestrictedDate(targetDate, restrictedDateOptions)) {\n return targetDate;\n }\n\n while (\n compareDatePart(initialDate, availableDate) !== 0 &&\n isRestrictedDate(availableDate, restrictedDateOptions) &&\n !isAfterMaxDate(availableDate, restrictedDateOptions) &&\n !isBeforeMinDate(availableDate, restrictedDateOptions)\n ) {\n availableDate = addDays(availableDate, direction);\n }\n\n if (compareDatePart(initialDate, availableDate) !== 0 && !isRestrictedDate(availableDate, restrictedDateOptions)) {\n return availableDate;\n }\n\n return undefined;\n};\n"],"names":["isRestrictedDate","isAfterMaxDate","isBeforeMinDate","compareDatePart","addDays","findAvailableDate","options","targetDate","initialDate","direction","restrictedDateOptions","availableDate","undefined"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,qBAAqB;AAEtD,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,eAAe,EAAEC,OAAO,QAAQ,uBAAuB;AAEhE;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGC,uBAAuB,GAAGJ;IACzE,IAAIK,gBAAgBJ;IACpB,yDAAyD;IACzD,IAAI,CAACP,iBAAiBO,YAAYG,wBAAwB;QACxD,OAAOH;IACT;IAEA,MACEJ,gBAAgBK,aAAaG,mBAAmB,KAChDX,iBAAiBW,eAAeD,0BAChC,CAACT,eAAeU,eAAeD,0BAC/B,CAACR,gBAAgBS,eAAeD,uBAChC;QACAC,gBAAgBP,QAAQO,eAAeF;IACzC;IAEA,IAAIN,gBAAgBK,aAAaG,mBAAmB,KAAK,CAACX,iBAAiBW,eAAeD,wBAAwB;QAChH,OAAOC;IACT;IAEA,OAAOC;AACT,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getBoundedDateRange.ts"],"sourcesContent":["import { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Generates a list of dates, bounded by min and max dates\n * @param dateRange - input date range\n * @param minDate - min date to limit the range\n * @param maxDate - max date to limit the range\n */\nexport const getBoundedDateRange = (dateRange: Date[], minDate?: Date, maxDate?: Date): Date[] => {\n let boundedDateRange = [...dateRange];\n if (minDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, minDate as Date) >= 0);\n }\n if (maxDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, maxDate as Date) <= 0);\n }\n return boundedDateRange;\n};\n"],"names":["compareDatePart","getBoundedDateRange","dateRange","minDate","maxDate","boundedDateRange","filter","date"],"mappings":"AAAA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,sBAAsB,CAACC,WAAmBC,SAAgBC
|
|
1
|
+
{"version":3,"sources":["getBoundedDateRange.ts"],"sourcesContent":["import { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Generates a list of dates, bounded by min and max dates\n * @param dateRange - input date range\n * @param minDate - min date to limit the range\n * @param maxDate - max date to limit the range\n */\nexport const getBoundedDateRange = (dateRange: Date[], minDate?: Date, maxDate?: Date): Date[] => {\n let boundedDateRange = [...dateRange];\n if (minDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, minDate as Date) >= 0);\n }\n if (maxDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, maxDate as Date) <= 0);\n }\n return boundedDateRange;\n};\n"],"names":["compareDatePart","getBoundedDateRange","dateRange","minDate","maxDate","boundedDateRange","filter","date"],"mappings":"AAAA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,sBAAsB,CAACC,WAAmBC,SAAgBC;IACrE,IAAIC,mBAAmB;WAAIH;KAAU;IACrC,IAAIC,SAAS;QACXE,mBAAmBA,iBAAiBC,MAAM,CAAC,CAACC,OAAeP,gBAAgBO,MAAMJ,YAAoB;IACvG;IACA,IAAIC,SAAS;QACXC,mBAAmBA,iBAAiBC,MAAM,CAAC,CAACC,OAAeP,gBAAgBO,MAAMH,YAAoB;IACvG;IACA,OAAOC;AACT,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getDateRangeTypeToUse.ts"],"sourcesContent":["import { DateRangeType, DayOfWeek } from '../constants';\nimport { isContiguous } from './isContiguous';\n/**\n * Return corrected date range type, given `dateRangeType` and list of working days.\n * For non-contiguous working days and working week range type, returns general week range type.\n * For other cases returns input date range type.\n * @param dateRangeType - input type of range\n * @param workWeekDays - list of working days in a week\n */\nexport const getDateRangeTypeToUse = (\n dateRangeType: DateRangeType,\n workWeekDays: DayOfWeek[] | undefined,\n firstDayOfWeek: DayOfWeek,\n): DateRangeType => {\n if (workWeekDays && dateRangeType === DateRangeType.WorkWeek) {\n if (!isContiguous(workWeekDays, true, firstDayOfWeek) || workWeekDays.length === 0) {\n return DateRangeType.Week;\n }\n }\n\n return dateRangeType;\n};\n"],"names":["DateRangeType","isContiguous","getDateRangeTypeToUse","dateRangeType","workWeekDays","firstDayOfWeek","WorkWeek","length","Week"],"mappings":"AAAA,SAASA,aAAa,QAAmB,eAAe;AACxD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C;;;;;;CAMC,GACD,OAAO,MAAMC,wBAAwB,CACnCC,eACAC,cACAC
|
|
1
|
+
{"version":3,"sources":["getDateRangeTypeToUse.ts"],"sourcesContent":["import { DateRangeType, DayOfWeek } from '../constants';\nimport { isContiguous } from './isContiguous';\n/**\n * Return corrected date range type, given `dateRangeType` and list of working days.\n * For non-contiguous working days and working week range type, returns general week range type.\n * For other cases returns input date range type.\n * @param dateRangeType - input type of range\n * @param workWeekDays - list of working days in a week\n */\nexport const getDateRangeTypeToUse = (\n dateRangeType: DateRangeType,\n workWeekDays: DayOfWeek[] | undefined,\n firstDayOfWeek: DayOfWeek,\n): DateRangeType => {\n if (workWeekDays && dateRangeType === DateRangeType.WorkWeek) {\n if (!isContiguous(workWeekDays, true, firstDayOfWeek) || workWeekDays.length === 0) {\n return DateRangeType.Week;\n }\n }\n\n return dateRangeType;\n};\n"],"names":["DateRangeType","isContiguous","getDateRangeTypeToUse","dateRangeType","workWeekDays","firstDayOfWeek","WorkWeek","length","Week"],"mappings":"AAAA,SAASA,aAAa,QAAmB,eAAe;AACxD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C;;;;;;CAMC,GACD,OAAO,MAAMC,wBAAwB,CACnCC,eACAC,cACAC;IAEA,IAAID,gBAAgBD,kBAAkBH,cAAcM,QAAQ,EAAE;QAC5D,IAAI,CAACL,aAAaG,cAAc,MAAMC,mBAAmBD,aAAaG,MAAM,KAAK,GAAG;YAClF,OAAOP,cAAcQ,IAAI;QAC3B;IACF;IAEA,OAAOL;AACT,EAAE"}
|
|
@@ -9,7 +9,7 @@ import { isRestrictedDate } from './isRestrictedDate';
|
|
|
9
9
|
* and one at the end from the future range
|
|
10
10
|
* @param options - parameters to specify date related restrictions for the resulting grid
|
|
11
11
|
*/ export const getDayGrid = (options)=>{
|
|
12
|
-
const { selectedDate
|
|
12
|
+
const { selectedDate, dateRangeType, firstDayOfWeek, today, minDate, maxDate, weeksToShow, workWeekDays, daysToSelectInDayView, restrictedDates, markedDays } = options;
|
|
13
13
|
const restrictedDateOptions = {
|
|
14
14
|
minDate,
|
|
15
15
|
maxDate,
|
|
@@ -45,6 +45,7 @@ import { isRestrictedDate } from './isRestrictedDate';
|
|
|
45
45
|
const week = [];
|
|
46
46
|
isAllDaysOfWeekOutOfMonth = true;
|
|
47
47
|
for(let dayIndex = 0; dayIndex < DAYS_IN_WEEK; dayIndex++){
|
|
48
|
+
var _markedDays;
|
|
48
49
|
const originalDate = new Date(date.getTime());
|
|
49
50
|
const dayInfo = {
|
|
50
51
|
key: date.toString(),
|
|
@@ -54,7 +55,7 @@ import { isRestrictedDate } from './isRestrictedDate';
|
|
|
54
55
|
isToday: compareDates(todaysDate, date),
|
|
55
56
|
isSelected: isInDateRangeArray(date, selectedDates),
|
|
56
57
|
isInBounds: !isRestrictedDate(date, restrictedDateOptions),
|
|
57
|
-
isMarked: (markedDays === null ||
|
|
58
|
+
isMarked: ((_markedDays = markedDays) === null || _markedDays === void 0 ? void 0 : _markedDays.some((markedDay)=>compareDates(originalDate, markedDay))) || false
|
|
58
59
|
};
|
|
59
60
|
week.push(dayInfo);
|
|
60
61
|
if (dayInfo.isInMonth) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getDayGrid.ts"],"sourcesContent":["import { addDays, compareDates, getDateRangeArray, isInDateRangeArray } from '../dateMath/dateMath';\nimport { DAYS_IN_WEEK } from '../constants';\nimport { Day, DayGridOptions } from './dateGrid.types';\nimport { getDateRangeTypeToUse } from './getDateRangeTypeToUse';\nimport { getBoundedDateRange } from './getBoundedDateRange';\nimport { isRestrictedDate } from './isRestrictedDate';\n\n/**\n * Generates a grid of days, given the `options`.\n * Returns one additional week at the begining from the previous range\n * and one at the end from the future range\n * @param options - parameters to specify date related restrictions for the resulting grid\n */\nexport const getDayGrid = (options: DayGridOptions): Day[][] => {\n const {\n selectedDate,\n dateRangeType,\n firstDayOfWeek,\n today,\n minDate,\n maxDate,\n weeksToShow,\n workWeekDays,\n daysToSelectInDayView,\n restrictedDates,\n markedDays,\n } = options;\n const restrictedDateOptions = { minDate, maxDate, restrictedDates };\n\n const todaysDate = today || new Date();\n\n const navigatedDate = options.navigatedDate ? options.navigatedDate : todaysDate;\n\n let date;\n if (weeksToShow && weeksToShow <= 4) {\n // if showing less than a full month, just use date == navigatedDate\n date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), navigatedDate.getDate());\n } else {\n date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), 1);\n }\n const weeks: Day[][] = [];\n\n // Cycle the date backwards to get to the first day of the week.\n while (date.getDay() !== firstDayOfWeek) {\n date.setDate(date.getDate() - 1);\n }\n\n // add the transition week as last week of previous range\n date = addDays(date, -DAYS_IN_WEEK);\n\n // a flag to indicate whether all days of the week are outside the month\n let isAllDaysOfWeekOutOfMonth = false;\n\n // in work week view if the days aren't contiguous we use week view instead\n const selectedDateRangeType = getDateRangeTypeToUse(dateRangeType, workWeekDays, firstDayOfWeek);\n\n let selectedDates: Date[] = [];\n\n if (selectedDate) {\n selectedDates = getDateRangeArray(\n selectedDate,\n selectedDateRangeType,\n firstDayOfWeek,\n workWeekDays,\n daysToSelectInDayView,\n );\n selectedDates = getBoundedDateRange(selectedDates, minDate, maxDate);\n }\n\n let shouldGetWeeks = true;\n\n for (let weekIndex = 0; shouldGetWeeks; weekIndex++) {\n const week: Day[] = [];\n\n isAllDaysOfWeekOutOfMonth = true;\n\n for (let dayIndex = 0; dayIndex < DAYS_IN_WEEK; dayIndex++) {\n const originalDate = new Date(date.getTime());\n const dayInfo: Day = {\n key: date.toString(),\n date: date.getDate().toString(),\n originalDate,\n isInMonth: date.getMonth() === navigatedDate.getMonth(),\n isToday: compareDates(todaysDate, date),\n isSelected: isInDateRangeArray(date, selectedDates),\n isInBounds: !isRestrictedDate(date, restrictedDateOptions),\n isMarked: markedDays?.some((markedDay: Date) => compareDates(originalDate, markedDay)) || false,\n };\n\n week.push(dayInfo);\n\n if (dayInfo.isInMonth) {\n isAllDaysOfWeekOutOfMonth = false;\n }\n\n date.setDate(date.getDate() + 1);\n }\n\n // We append the condition of the loop depending upon the showSixWeeksByDefault prop.\n shouldGetWeeks = weeksToShow ? weekIndex < weeksToShow + 1 : !isAllDaysOfWeekOutOfMonth || weekIndex === 0;\n\n // we don't check shouldGetWeeks before pushing because we want to add one extra week for transition state\n weeks.push(week);\n }\n\n return weeks;\n};\n"],"names":["addDays","compareDates","getDateRangeArray","isInDateRangeArray","DAYS_IN_WEEK","getDateRangeTypeToUse","getBoundedDateRange","isRestrictedDate","getDayGrid","options","selectedDate","dateRangeType","firstDayOfWeek","today","minDate","maxDate","weeksToShow","workWeekDays","daysToSelectInDayView","restrictedDates","markedDays","restrictedDateOptions","todaysDate","Date","navigatedDate","date","getFullYear","getMonth","getDate","weeks","getDay","setDate","isAllDaysOfWeekOutOfMonth","selectedDateRangeType","selectedDates","shouldGetWeeks","weekIndex","week","dayIndex","originalDate","getTime","dayInfo","key","toString","isInMonth","isToday","isSelected","isInBounds","isMarked","some","markedDay","push"],"mappings":"AAAA,SAASA,OAAO,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,uBAAuB;AACpG,SAASC,YAAY,QAAQ,eAAe;AAE5C,SAASC,qBAAqB,QAAQ,0BAA0B;AAChE,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,gBAAgB,QAAQ,qBAAqB;AAEtD;;;;;CAKC,GACD,OAAO,MAAMC,aAAa,CAACC
|
|
1
|
+
{"version":3,"sources":["getDayGrid.ts"],"sourcesContent":["import { addDays, compareDates, getDateRangeArray, isInDateRangeArray } from '../dateMath/dateMath';\nimport { DAYS_IN_WEEK } from '../constants';\nimport { Day, DayGridOptions } from './dateGrid.types';\nimport { getDateRangeTypeToUse } from './getDateRangeTypeToUse';\nimport { getBoundedDateRange } from './getBoundedDateRange';\nimport { isRestrictedDate } from './isRestrictedDate';\n\n/**\n * Generates a grid of days, given the `options`.\n * Returns one additional week at the begining from the previous range\n * and one at the end from the future range\n * @param options - parameters to specify date related restrictions for the resulting grid\n */\nexport const getDayGrid = (options: DayGridOptions): Day[][] => {\n const {\n selectedDate,\n dateRangeType,\n firstDayOfWeek,\n today,\n minDate,\n maxDate,\n weeksToShow,\n workWeekDays,\n daysToSelectInDayView,\n restrictedDates,\n markedDays,\n } = options;\n const restrictedDateOptions = { minDate, maxDate, restrictedDates };\n\n const todaysDate = today || new Date();\n\n const navigatedDate = options.navigatedDate ? options.navigatedDate : todaysDate;\n\n let date;\n if (weeksToShow && weeksToShow <= 4) {\n // if showing less than a full month, just use date == navigatedDate\n date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), navigatedDate.getDate());\n } else {\n date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), 1);\n }\n const weeks: Day[][] = [];\n\n // Cycle the date backwards to get to the first day of the week.\n while (date.getDay() !== firstDayOfWeek) {\n date.setDate(date.getDate() - 1);\n }\n\n // add the transition week as last week of previous range\n date = addDays(date, -DAYS_IN_WEEK);\n\n // a flag to indicate whether all days of the week are outside the month\n let isAllDaysOfWeekOutOfMonth = false;\n\n // in work week view if the days aren't contiguous we use week view instead\n const selectedDateRangeType = getDateRangeTypeToUse(dateRangeType, workWeekDays, firstDayOfWeek);\n\n let selectedDates: Date[] = [];\n\n if (selectedDate) {\n selectedDates = getDateRangeArray(\n selectedDate,\n selectedDateRangeType,\n firstDayOfWeek,\n workWeekDays,\n daysToSelectInDayView,\n );\n selectedDates = getBoundedDateRange(selectedDates, minDate, maxDate);\n }\n\n let shouldGetWeeks = true;\n\n for (let weekIndex = 0; shouldGetWeeks; weekIndex++) {\n const week: Day[] = [];\n\n isAllDaysOfWeekOutOfMonth = true;\n\n for (let dayIndex = 0; dayIndex < DAYS_IN_WEEK; dayIndex++) {\n const originalDate = new Date(date.getTime());\n const dayInfo: Day = {\n key: date.toString(),\n date: date.getDate().toString(),\n originalDate,\n isInMonth: date.getMonth() === navigatedDate.getMonth(),\n isToday: compareDates(todaysDate, date),\n isSelected: isInDateRangeArray(date, selectedDates),\n isInBounds: !isRestrictedDate(date, restrictedDateOptions),\n isMarked: markedDays?.some((markedDay: Date) => compareDates(originalDate, markedDay)) || false,\n };\n\n week.push(dayInfo);\n\n if (dayInfo.isInMonth) {\n isAllDaysOfWeekOutOfMonth = false;\n }\n\n date.setDate(date.getDate() + 1);\n }\n\n // We append the condition of the loop depending upon the showSixWeeksByDefault prop.\n shouldGetWeeks = weeksToShow ? weekIndex < weeksToShow + 1 : !isAllDaysOfWeekOutOfMonth || weekIndex === 0;\n\n // we don't check shouldGetWeeks before pushing because we want to add one extra week for transition state\n weeks.push(week);\n }\n\n return weeks;\n};\n"],"names":["addDays","compareDates","getDateRangeArray","isInDateRangeArray","DAYS_IN_WEEK","getDateRangeTypeToUse","getBoundedDateRange","isRestrictedDate","getDayGrid","options","selectedDate","dateRangeType","firstDayOfWeek","today","minDate","maxDate","weeksToShow","workWeekDays","daysToSelectInDayView","restrictedDates","markedDays","restrictedDateOptions","todaysDate","Date","navigatedDate","date","getFullYear","getMonth","getDate","weeks","getDay","setDate","isAllDaysOfWeekOutOfMonth","selectedDateRangeType","selectedDates","shouldGetWeeks","weekIndex","week","dayIndex","originalDate","getTime","dayInfo","key","toString","isInMonth","isToday","isSelected","isInBounds","isMarked","some","markedDay","push"],"mappings":"AAAA,SAASA,OAAO,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,uBAAuB;AACpG,SAASC,YAAY,QAAQ,eAAe;AAE5C,SAASC,qBAAqB,QAAQ,0BAA0B;AAChE,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,gBAAgB,QAAQ,qBAAqB;AAEtD;;;;;CAKC,GACD,OAAO,MAAMC,aAAa,CAACC;IACzB,MAAM,EACJC,YAAY,EACZC,aAAa,EACbC,cAAc,EACdC,KAAK,EACLC,OAAO,EACPC,OAA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C7BJ;gBACAK,WAAWnB,KAAKE,QAAQ,OAAOH,cAAcG,QAAQ;gBACrDkB,SAAS5C,aAAaqB,YAAYG;gBAClCqB,YAAY3C,mBAAmBsB,MAAMS;gBACrCa,YAAY,CAACxC,iBAAiBkB,MAAMJ;gBACpC2B,UAAU5B,EAAAA,cAAAA,wBAAAA,kCAAAA,YAAY6B,IAAI,CAAC,CAACC,YAAoBjD,aAAasC,cAAcW,gBAAe;YAC5F;YAEAb,KAAKc,IAAI,CAACV;YAEV,IAAIA,QAAQG,SAAS,EAAE;gBACrBZ,4BAA4B;YAC9B;YAEAP,KAAKM,OAAO,CAACN,KAAKG,OAAO,KAAK;QAChC;QAEA,qFAAqF;QACrFO,iBAAiBnB,cAAcoB,YAAYpB,cAAc,IAAI,CAACgB,6BAA6BI,cAAc;QAEzG,0GAA0G;QAC1GP,MAAMsB,IAAI,CAACd;IACb;IAEA,OAAOR;AACT,EAAE"}
|
|
@@ -4,6 +4,6 @@ import { compareDatePart } from '../dateMath/dateMath';
|
|
|
4
4
|
* @param date - date to check
|
|
5
5
|
* @param options - object with max date to check against
|
|
6
6
|
*/ export const isAfterMaxDate = (date, options)=>{
|
|
7
|
-
const { maxDate
|
|
7
|
+
const { maxDate } = options;
|
|
8
8
|
return maxDate ? compareDatePart(date, maxDate) >= 1 : false;
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["isAfterMaxDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens later than max date\n * @param date - date to check\n * @param options - object with max date to check against\n */\nexport const isAfterMaxDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { maxDate } = options;\n return maxDate ? compareDatePart(date, maxDate) >= 1 : false;\n};\n"],"names":["compareDatePart","isAfterMaxDate","date","options","maxDate"],"mappings":"AACA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;CAIC,GACD,OAAO,MAAMC,iBAAiB,CAACC,MAAYC
|
|
1
|
+
{"version":3,"sources":["isAfterMaxDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens later than max date\n * @param date - date to check\n * @param options - object with max date to check against\n */\nexport const isAfterMaxDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { maxDate } = options;\n return maxDate ? compareDatePart(date, maxDate) >= 1 : false;\n};\n"],"names":["compareDatePart","isAfterMaxDate","date","options","maxDate"],"mappings":"AACA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;CAIC,GACD,OAAO,MAAMC,iBAAiB,CAACC,MAAYC;IACzC,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,OAAOC,UAAUJ,gBAAgBE,MAAME,YAAY,IAAI;AACzD,EAAE"}
|
|
@@ -4,6 +4,6 @@ import { compareDatePart } from '../dateMath/dateMath';
|
|
|
4
4
|
* @param date - date to check
|
|
5
5
|
* @param options - object with min date to check against
|
|
6
6
|
*/ export const isBeforeMinDate = (date, options)=>{
|
|
7
|
-
const { minDate
|
|
7
|
+
const { minDate } = options;
|
|
8
8
|
return minDate ? compareDatePart(minDate, date) >= 1 : false;
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["isBeforeMinDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens earlier than min date\n * @param date - date to check\n * @param options - object with min date to check against\n */\nexport const isBeforeMinDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { minDate } = options;\n return minDate ? compareDatePart(minDate, date) >= 1 : false;\n};\n"],"names":["compareDatePart","isBeforeMinDate","date","options","minDate"],"mappings":"AACA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,CAACC,MAAYC
|
|
1
|
+
{"version":3,"sources":["isBeforeMinDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens earlier than min date\n * @param date - date to check\n * @param options - object with min date to check against\n */\nexport const isBeforeMinDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { minDate } = options;\n return minDate ? compareDatePart(minDate, date) >= 1 : false;\n};\n"],"names":["compareDatePart","isBeforeMinDate","date","options","minDate"],"mappings":"AACA,SAASA,eAAe,QAAQ,uBAAuB;AAEvD;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,CAACC,MAAYC;IAC1C,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,OAAOC,UAAUJ,gBAAgBI,SAASF,SAAS,IAAI;AACzD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["isContiguous.ts"],"sourcesContent":["import { DayOfWeek } from '../constants';\n\n/**\n * Returns whether provided week days are contiguous.\n * @param days - list of days in a week\n * @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not\n * @param firstDayOfWeek - decides which day of week is the first one in the order.\n */\nexport const isContiguous = (days: DayOfWeek[], isSingleWeek: boolean, firstDayOfWeek: DayOfWeek): boolean => {\n const daySet = new Set(days);\n let amountOfNoNeighbors = 0;\n for (const day of days) {\n const nextDay = (day + 1) % 7;\n if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {\n amountOfNoNeighbors++;\n }\n }\n\n // In case the full week is provided, then each day has a neighbor\n //, otherwise the last day does not have a neighbor.\n return amountOfNoNeighbors < 2;\n};\n"],"names":["isContiguous","days","isSingleWeek","firstDayOfWeek","daySet","Set","amountOfNoNeighbors","day","nextDay","has"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,eAAe,CAACC,MAAmBC,cAAuBC
|
|
1
|
+
{"version":3,"sources":["isContiguous.ts"],"sourcesContent":["import { DayOfWeek } from '../constants';\n\n/**\n * Returns whether provided week days are contiguous.\n * @param days - list of days in a week\n * @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not\n * @param firstDayOfWeek - decides which day of week is the first one in the order.\n */\nexport const isContiguous = (days: DayOfWeek[], isSingleWeek: boolean, firstDayOfWeek: DayOfWeek): boolean => {\n const daySet = new Set(days);\n let amountOfNoNeighbors = 0;\n for (const day of days) {\n const nextDay = (day + 1) % 7;\n if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {\n amountOfNoNeighbors++;\n }\n }\n\n // In case the full week is provided, then each day has a neighbor\n //, otherwise the last day does not have a neighbor.\n return amountOfNoNeighbors < 2;\n};\n"],"names":["isContiguous","days","isSingleWeek","firstDayOfWeek","daySet","Set","amountOfNoNeighbors","day","nextDay","has"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,eAAe,CAACC,MAAmBC,cAAuBC;IACrE,MAAMC,SAAS,IAAIC,IAAIJ;IACvB,IAAIK,sBAAsB;IAC1B,KAAK,MAAMC,OAAON,KAAM;QACtB,MAAMO,UAAU,AAACD,CAAAA,MAAM,CAAA,IAAK;QAC5B,IAAI,CAAEH,CAAAA,OAAOK,GAAG,CAACD,YAAa,CAAA,CAACN,gBAAgBC,mBAAmBK,OAAM,CAAC,GAAI;YAC3EF;QACF;IACF;IAEA,kEAAkE;IAClE,oDAAoD;IACpD,OAAOA,sBAAsB;AAC/B,EAAE"}
|
|
@@ -6,7 +6,7 @@ import { isAfterMaxDate } from './isAfterMaxDate';
|
|
|
6
6
|
* @param date - date to check
|
|
7
7
|
* @param options - restriction options (min date, max date and list of restricted dates)
|
|
8
8
|
*/ export const isRestrictedDate = (date, options)=>{
|
|
9
|
-
const { restrictedDates
|
|
9
|
+
const { restrictedDates, minDate, maxDate } = options;
|
|
10
10
|
if (!restrictedDates && !minDate && !maxDate) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["isRestrictedDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDates } from '../dateMath/dateMath';\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\n/**\n * Checks if `date` falls into the restricted `options`\n * @param date - date to check\n * @param options - restriction options (min date, max date and list of restricted dates)\n */\nexport const isRestrictedDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { restrictedDates, minDate, maxDate } = options;\n if (!restrictedDates && !minDate && !maxDate) {\n return false;\n }\n const inRestrictedDates = restrictedDates && restrictedDates.some((rd: Date) => compareDates(rd, date));\n return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);\n};\n"],"names":["compareDates","isBeforeMinDate","isAfterMaxDate","isRestrictedDate","date","options","restrictedDates","minDate","maxDate","inRestrictedDates","some","rd"],"mappings":"AACA,SAASA,YAAY,QAAQ,uBAAuB;AACpD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAElD;;;;CAIC,GACD,OAAO,MAAMC,mBAAmB,CAACC,MAAYC
|
|
1
|
+
{"version":3,"sources":["isRestrictedDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDates } from '../dateMath/dateMath';\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\n/**\n * Checks if `date` falls into the restricted `options`\n * @param date - date to check\n * @param options - restriction options (min date, max date and list of restricted dates)\n */\nexport const isRestrictedDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { restrictedDates, minDate, maxDate } = options;\n if (!restrictedDates && !minDate && !maxDate) {\n return false;\n }\n const inRestrictedDates = restrictedDates && restrictedDates.some((rd: Date) => compareDates(rd, date));\n return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);\n};\n"],"names":["compareDates","isBeforeMinDate","isAfterMaxDate","isRestrictedDate","date","options","restrictedDates","minDate","maxDate","inRestrictedDates","some","rd"],"mappings":"AACA,SAASA,YAAY,QAAQ,uBAAuB;AACpD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAElD;;;;CAIC,GACD,OAAO,MAAMC,mBAAmB,CAACC,MAAYC;IAC3C,MAAM,EAAEC,eAAe,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGH;IAC9C,IAAI,CAACC,mBAAmB,CAACC,WAAW,CAACC,SAAS;QAC5C,OAAO;IACT;IACA,MAAMC,oBAAoBH,mBAAmBA,gBAAgBI,IAAI,CAAC,CAACC,KAAaX,aAAaW,IAAIP;IACjG,OAAOK,qBAAqBR,gBAAgBG,MAAMC,YAAYH,eAAeE,MAAMC;AACrF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["dateMath.ts"],"sourcesContent":["import { DateRangeType, DayOfWeek, FirstWeekOfYear, MonthOfYear, TimeConstants } from '../constants';\n\n/**\n * Returns a date offset from the given date by the specified number of days.\n * @param date - The origin date\n * @param days - The number of days to offset. 'days' can be negative.\n * @returns A new Date object offset from the origin date by the given number of days\n */\nexport function addDays(date: Date, days: number): Date {\n const result = new Date(date.getTime());\n result.setDate(result.getDate() + days);\n return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of weeks.\n * @param date - The origin date\n * @param weeks - The number of weeks to offset. 'weeks' can be negative.\n * @returns A new Date object offset from the origin date by the given number of weeks\n */\nexport function addWeeks(date: Date, weeks: number): Date {\n return addDays(date, weeks * TimeConstants.DaysInOneWeek);\n}\n\n/**\n * Returns a date offset from the given date by the specified number of months.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param months - The number of months to offset. 'months' can be negative.\n * @returns A new Date object offset from the origin date by the given number of months\n */\nexport function addMonths(date: Date, months: number): Date {\n let result = new Date(date.getTime());\n const newMonth = result.getMonth() + months;\n result.setMonth(newMonth);\n\n // We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.\n // Loop until we back up to a day the new month has.\n // (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)\n if (\n result.getMonth() !==\n ((newMonth % TimeConstants.MonthInOneYear) + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear\n ) {\n result = addDays(result, -result.getDate());\n }\n return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of years.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param years - The number of years to offset. 'years' can be negative.\n * @returns A new Date object offset from the origin date by the given number of years\n */\nexport function addYears(date: Date, years: number): Date {\n let result = new Date(date.getTime());\n result.setFullYear(date.getFullYear() + years);\n\n // We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.\n // Loop until we back up to a day the new month has.\n // (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)\n if (\n result.getMonth() !==\n ((date.getMonth() % TimeConstants.MonthInOneYear) + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear\n ) {\n result = addDays(result, -result.getDate());\n }\n return result;\n}\n\n/**\n * Returns a date that is the first day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the month.\n */\nexport function getMonthStart(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the last day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the month.\n */\nexport function getMonthEnd(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth() + 1, 0, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the first day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the year.\n */\nexport function getYearStart(date: Date): Date {\n return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the last day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the year.\n */\nexport function getYearEnd(date: Date): Date {\n return new Date(date.getFullYear() + 1, 0, 0, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is a copy of the given date, aside from the month changing to the given month.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param month - The 0-based index of the month to set on the date.\n * @returns A new Date object with the given month set.\n */\nexport function setMonth(date: Date, month: number): Date {\n return addMonths(date, month - date.getMonth());\n}\n\n/**\n * Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.\n * @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.\n */\nexport function compareDates(date1: Date, date2: Date): boolean {\n if (!date1 && !date2) {\n return true;\n } else if (!date1 || !date2) {\n return false;\n } else {\n return (\n date1.getFullYear() === date2.getFullYear() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getDate() === date2.getDate()\n );\n }\n}\n\n/**\n * Compare the date parts of two dates\n * @param date1 - The first date to compare\n * @param date2 - The second date to compare\n * @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value\n * if date1 is later than date2.\n */\nexport function compareDatePart(date1: Date, date2: Date): Number {\n return getDatePartHashValue(date1) - getDatePartHashValue(date2);\n}\n\n/**\n * Gets the date range array including the specified date. The date range array is calculated as the list\n * of dates accounting for the specified first day of the week and date range type.\n * @param date - The input date\n * @param dateRangeType - The desired date range type, i.e., day, week, month, etc.\n * @param firstDayOfWeek - The first day of the week.\n * @param workWeekDays - The allowed days in work week. If not provided, assumes all days are allowed.\n * @param daysToSelectInDayView - The number of days to include when using dateRangeType === DateRangeType.Day\n * for multiday view. Defaults to 1\n * @returns An array of dates representing the date range containing the specified date.\n */\nexport function getDateRangeArray(\n date: Date,\n dateRangeType: DateRangeType,\n firstDayOfWeek: DayOfWeek,\n workWeekDays?: DayOfWeek[],\n daysToSelectInDayView: number = 1,\n): Date[] {\n const datesArray: Date[] = [];\n let startDate: Date;\n let endDate = null;\n\n if (!workWeekDays) {\n workWeekDays = [DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday];\n }\n\n daysToSelectInDayView = Math.max(daysToSelectInDayView, 1);\n\n switch (dateRangeType) {\n case DateRangeType.Day:\n startDate = getDatePart(date);\n endDate = addDays(startDate, daysToSelectInDayView);\n break;\n\n case DateRangeType.Week:\n case DateRangeType.WorkWeek:\n startDate = getStartDateOfWeek(getDatePart(date), firstDayOfWeek);\n endDate = addDays(startDate, TimeConstants.DaysInOneWeek);\n break;\n\n case DateRangeType.Month:\n startDate = new Date(date.getFullYear(), date.getMonth(), 1);\n endDate = addMonths(startDate, 1);\n break;\n\n default:\n throw new Error('Unexpected object: ' + dateRangeType);\n }\n\n // Populate the dates array with the dates in range\n let nextDate = startDate;\n\n do {\n if (dateRangeType !== DateRangeType.WorkWeek) {\n // push all days not in work week view\n datesArray.push(nextDate);\n } else if (workWeekDays.indexOf(nextDate.getDay()) !== -1) {\n datesArray.push(nextDate);\n }\n nextDate = addDays(nextDate, 1);\n } while (!compareDates(nextDate, endDate));\n\n return datesArray;\n}\n\n/**\n * Checks whether the specified date is in the given date range.\n * @param date - The origin date\n * @param dateRange - An array of dates to do the lookup on\n * @returns True if the date matches one of the dates in the specified array, false otherwise.\n */\nexport function isInDateRangeArray(date: Date, dateRange: Date[]): boolean {\n for (const dateInRange of dateRange) {\n if (compareDates(date, dateInRange)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Returns the week number for a date.\n * Week numbers are 1 - 52 (53) in a year\n * @param navigatedDate - A date to find the week number for.\n * @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)\n * @param firstWeekOfYear - The first week of the year (1-2)\n * @returns The weeks number array for the current month.\n */\nexport function getWeekNumbersInMonth(\n weeksInMonth: number,\n firstDayOfWeek: DayOfWeek,\n firstWeekOfYear: FirstWeekOfYear,\n navigatedDate: Date,\n): number[] {\n const selectedYear = navigatedDate.getFullYear();\n const selectedMonth = navigatedDate.getMonth();\n let dayOfMonth = 1;\n const fistDayOfMonth = new Date(selectedYear, selectedMonth, dayOfMonth);\n const endOfFirstWeek =\n dayOfMonth +\n (firstDayOfWeek + TimeConstants.DaysInOneWeek - 1) -\n adjustWeekDay(firstDayOfWeek, fistDayOfMonth.getDay());\n let endOfWeekRange = new Date(selectedYear, selectedMonth, endOfFirstWeek);\n dayOfMonth = endOfWeekRange.getDate();\n\n const weeksArray = [];\n for (let i = 0; i < weeksInMonth; i++) {\n // Get week number for end of week\n weeksArray.push(getWeekNumber(endOfWeekRange, firstDayOfWeek, firstWeekOfYear));\n dayOfMonth += TimeConstants.DaysInOneWeek;\n endOfWeekRange = new Date(selectedYear, selectedMonth, dayOfMonth);\n }\n return weeksArray;\n}\n\n/**\n * Returns the week number for a date.\n * Week numbers are 1 - 52 (53) in a year\n * @param date - A date to find the week number for.\n * @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)\n * @param firstWeekOfYear - The first week of the year (1-2)\n * @returns The week's number in the year.\n */\nexport function getWeekNumber(date: Date, firstDayOfWeek: DayOfWeek, firstWeekOfYear: FirstWeekOfYear): number {\n // First four-day week of the year - minumum days count\n const fourDayWeek = 4;\n\n switch (firstWeekOfYear) {\n case FirstWeekOfYear.FirstFullWeek:\n return getWeekOfYearFullDays(date, firstDayOfWeek, TimeConstants.DaysInOneWeek);\n\n case FirstWeekOfYear.FirstFourDayWeek:\n return getWeekOfYearFullDays(date, firstDayOfWeek, fourDayWeek);\n\n default:\n return getFirstDayWeekOfYear(date, firstDayOfWeek);\n }\n}\n\n/**\n * Gets the date for the first day of the week based on the given date assuming\n * the specified first day of the week.\n * @param date - The date to find the beginning of the week date for.\n * @returns A new date object representing the first day of the week containing the input date.\n */\nexport function getStartDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date {\n let daysOffset = firstDayOfWeek - date.getDay();\n if (daysOffset > 0) {\n // If first day of week is > date, go 1 week back, to ensure resulting date is in the past.\n daysOffset -= TimeConstants.DaysInOneWeek;\n }\n return addDays(date, daysOffset);\n}\n\n/**\n * Gets the date for the last day of the week based on the given date assuming\n * the specified first day of the week.\n * @param date - The date to find the beginning of the week date for.\n * @returns A new date object representing the first day of the week containing the input date.\n */\nexport function getEndDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date {\n const lastDayOfWeek = firstDayOfWeek - 1 >= 0 ? firstDayOfWeek - 1 : TimeConstants.DaysInOneWeek - 1;\n let daysOffset = lastDayOfWeek - date.getDay();\n if (daysOffset < 0) {\n // If last day of week is < date, go 1 week forward, to ensure resulting date is in the future.\n daysOffset += TimeConstants.DaysInOneWeek;\n }\n return addDays(date, daysOffset);\n}\n\n/**\n * Gets a new date with the time portion zeroed out, i.e., set to midnight\n * @param date - The origin date\n * @returns A new date with the time set to midnight\n */\nfunction getDatePart(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), date.getDate());\n}\n\n/**\n * Helper function to assist in date comparisons\n */\nexport function getDatePartHashValue(date: Date): number {\n // Generate date hash value created as sum of Date (up to 31 = 5 bits), Month (up to 11 = 4 bits) and Year.\n // eslint-disable-next-line no-bitwise\n return date.getDate() + (date.getMonth() << 5) + (date.getFullYear() << 9);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @param numberOfFullDays - week settings.\n * @returns The week's number in the year.\n */\nfunction getWeekOfYearFullDays(date: Date, firstDayOfWeek: DayOfWeek, numberOfFullDays: number): number {\n const dayOfYear = getDayOfYear(date) - 1;\n let num = date.getDay() - (dayOfYear % TimeConstants.DaysInOneWeek);\n\n const lastDayOfPrevYear = new Date(date.getFullYear() - 1, MonthOfYear.December, 31);\n const daysInYear = getDayOfYear(lastDayOfPrevYear) - 1;\n\n let num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n if (num2 !== 0 && num2 >= numberOfFullDays) {\n num2 -= TimeConstants.DaysInOneWeek;\n }\n\n let num3 = dayOfYear - num2;\n if (num3 < 0) {\n num -= daysInYear % TimeConstants.DaysInOneWeek;\n num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n if (num2 !== 0 && num2 + 1 >= numberOfFullDays) {\n num2 -= TimeConstants.DaysInOneWeek;\n }\n\n num3 = daysInYear - num2;\n }\n\n return Math.floor(num3 / TimeConstants.DaysInOneWeek + 1);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @returns The week's number in the year.\n */\nfunction getFirstDayWeekOfYear(date: Date, firstDayOfWeek: number): number {\n const num = getDayOfYear(date) - 1;\n const num2 = date.getDay() - (num % TimeConstants.DaysInOneWeek);\n const num3 = (num2 - firstDayOfWeek + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n\n return Math.floor((num + num3) / TimeConstants.DaysInOneWeek + 1);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns adjusted week day number when `firstDayOfWeek` is other than Sunday.\n * For Week Day Number comparison checks\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @param dateWeekDay - shifts number forward to 1 week in case passed as true\n * @returns The day of week adjusted to `firstDayOfWeek`; e.g. when `firstDayOfWeek` is Monday (1),\n * Sunday becomes 7.\n */\nfunction adjustWeekDay(firstDayOfWeek: DayOfWeek, dateWeekDay: DayOfWeek): number {\n return firstDayOfWeek !== DayOfWeek.Sunday && dateWeekDay < firstDayOfWeek\n ? dateWeekDay + TimeConstants.DaysInOneWeek\n : dateWeekDay;\n}\n\n/**\n * Returns the day number for a date in a year:\n * the number of days since January 1st in the particular year.\n * @param date - A date to find the day number for.\n * @returns The day's number in the year.\n */\nfunction getDayOfYear(date: Date): number {\n const month = date.getMonth();\n const year = date.getFullYear();\n let daysUntilDate = 0;\n\n for (let i = 0; i < month; i++) {\n daysUntilDate += daysInMonth(i + 1, year);\n }\n\n daysUntilDate += date.getDate();\n\n return daysUntilDate;\n}\n\n/**\n * Returns the number of days in the month\n * @param month - The month number to target (months 1-12).\n * @param year - The year to target.\n * @returns The number of days in the month.\n */\nfunction daysInMonth(month: number, year: number): number {\n return new Date(year, month, 0).getDate();\n}\n"],"names":["DateRangeType","DayOfWeek","FirstWeekOfYear","MonthOfYear","TimeConstants","addDays","date","days","result","Date","getTime","setDate","getDate","addWeeks","weeks","DaysInOneWeek","addMonths","months","newMonth","getMonth","setMonth","MonthInOneYear","addYears","years","setFullYear","getFullYear","getMonthStart","getMonthEnd","getYearStart","getYearEnd","month","compareDates","date1","date2","compareDatePart","getDatePartHashValue","getDateRangeArray","dateRangeType","firstDayOfWeek","workWeekDays","daysToSelectInDayView","datesArray","startDate","endDate","Monday","Tuesday","Wednesday","Thursday","Friday","Math","max","Day","getDatePart","Week","WorkWeek","getStartDateOfWeek","Month","Error","nextDate","push","indexOf","getDay","isInDateRangeArray","dateRange","dateInRange","getWeekNumbersInMonth","weeksInMonth","firstWeekOfYear","navigatedDate","selectedYear","selectedMonth","dayOfMonth","fistDayOfMonth","endOfFirstWeek","adjustWeekDay","endOfWeekRange","weeksArray","i","getWeekNumber","fourDayWeek","FirstFullWeek","getWeekOfYearFullDays","FirstFourDayWeek","getFirstDayWeekOfYear","daysOffset","getEndDateOfWeek","lastDayOfWeek","numberOfFullDays","dayOfYear","getDayOfYear","num","lastDayOfPrevYear","December","daysInYear","num2","num3","floor","dateWeekDay","Sunday","year","daysUntilDate","daysInMonth"],"mappings":"AAAA,SAASA,aAAa,EAAEC,SAAS,EAAEC,eAAe,EAAEC,WAAW,EAAEC,aAAa,QAAQ,eAAe;AAErG;;;;;CAKC,GACD,OAAO,SAASC,QAAQC,IAAU,EAAEC,IAAY,EAAQ;IACtD,MAAMC,SAAS,IAAIC,KAAKH,KAAK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M,OAAO;IAE7B,OAAOwF;AACT;AAEA;;;;;CAKC,GACD,SAASC,YAAYvE,KAAa,EAAEqE,IAAY,EAAU;IACxD,OAAO,IAAI1F,KAAK0F,MAAMrE,OAAO,GAAGlB,OAAO;AACzC"}
|
|
1
|
+
{"version":3,"sources":["dateMath.ts"],"sourcesContent":["import { DateRangeType, DayOfWeek, FirstWeekOfYear, MonthOfYear, TimeConstants } from '../constants';\n\n/**\n * Returns a date offset from the given date by the specified number of days.\n * @param date - The origin date\n * @param days - The number of days to offset. 'days' can be negative.\n * @returns A new Date object offset from the origin date by the given number of days\n */\nexport function addDays(date: Date, days: number): Date {\n const result = new Date(date.getTime());\n result.setDate(result.getDate() + days);\n return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of weeks.\n * @param date - The origin date\n * @param weeks - The number of weeks to offset. 'weeks' can be negative.\n * @returns A new Date object offset from the origin date by the given number of weeks\n */\nexport function addWeeks(date: Date, weeks: number): Date {\n return addDays(date, weeks * TimeConstants.DaysInOneWeek);\n}\n\n/**\n * Returns a date offset from the given date by the specified number of months.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param months - The number of months to offset. 'months' can be negative.\n * @returns A new Date object offset from the origin date by the given number of months\n */\nexport function addMonths(date: Date, months: number): Date {\n let result = new Date(date.getTime());\n const newMonth = result.getMonth() + months;\n result.setMonth(newMonth);\n\n // We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.\n // Loop until we back up to a day the new month has.\n // (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)\n if (\n result.getMonth() !==\n ((newMonth % TimeConstants.MonthInOneYear) + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear\n ) {\n result = addDays(result, -result.getDate());\n }\n return result;\n}\n\n/**\n * Returns a date offset from the given date by the specified number of years.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param years - The number of years to offset. 'years' can be negative.\n * @returns A new Date object offset from the origin date by the given number of years\n */\nexport function addYears(date: Date, years: number): Date {\n let result = new Date(date.getTime());\n result.setFullYear(date.getFullYear() + years);\n\n // We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.\n // Loop until we back up to a day the new month has.\n // (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)\n if (\n result.getMonth() !==\n ((date.getMonth() % TimeConstants.MonthInOneYear) + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear\n ) {\n result = addDays(result, -result.getDate());\n }\n return result;\n}\n\n/**\n * Returns a date that is the first day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the month.\n */\nexport function getMonthStart(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the last day of the month of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the month.\n */\nexport function getMonthEnd(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth() + 1, 0, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the first day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the first day of the year.\n */\nexport function getYearStart(date: Date): Date {\n return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is the last day of the year of the provided date.\n * @param date - The origin date\n * @returns A new Date object with the day set to the last day of the year.\n */\nexport function getYearEnd(date: Date): Date {\n return new Date(date.getFullYear() + 1, 0, 0, 0, 0, 0, 0);\n}\n\n/**\n * Returns a date that is a copy of the given date, aside from the month changing to the given month.\n * The method tries to preserve the day-of-month; however, if the new month does not have enough days\n * to contain the original day-of-month, we'll use the last day of the new month.\n * @param date - The origin date\n * @param month - The 0-based index of the month to set on the date.\n * @returns A new Date object with the given month set.\n */\nexport function setMonth(date: Date, month: number): Date {\n return addMonths(date, month - date.getMonth());\n}\n\n/**\n * Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.\n * @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.\n */\nexport function compareDates(date1: Date, date2: Date): boolean {\n if (!date1 && !date2) {\n return true;\n } else if (!date1 || !date2) {\n return false;\n } else {\n return (\n date1.getFullYear() === date2.getFullYear() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getDate() === date2.getDate()\n );\n }\n}\n\n/**\n * Compare the date parts of two dates\n * @param date1 - The first date to compare\n * @param date2 - The second date to compare\n * @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value\n * if date1 is later than date2.\n */\nexport function compareDatePart(date1: Date, date2: Date): Number {\n return getDatePartHashValue(date1) - getDatePartHashValue(date2);\n}\n\n/**\n * Gets the date range array including the specified date. The date range array is calculated as the list\n * of dates accounting for the specified first day of the week and date range type.\n * @param date - The input date\n * @param dateRangeType - The desired date range type, i.e., day, week, month, etc.\n * @param firstDayOfWeek - The first day of the week.\n * @param workWeekDays - The allowed days in work week. If not provided, assumes all days are allowed.\n * @param daysToSelectInDayView - The number of days to include when using dateRangeType === DateRangeType.Day\n * for multiday view. Defaults to 1\n * @returns An array of dates representing the date range containing the specified date.\n */\nexport function getDateRangeArray(\n date: Date,\n dateRangeType: DateRangeType,\n firstDayOfWeek: DayOfWeek,\n workWeekDays?: DayOfWeek[],\n daysToSelectInDayView: number = 1,\n): Date[] {\n const datesArray: Date[] = [];\n let startDate: Date;\n let endDate = null;\n\n if (!workWeekDays) {\n workWeekDays = [DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday];\n }\n\n daysToSelectInDayView = Math.max(daysToSelectInDayView, 1);\n\n switch (dateRangeType) {\n case DateRangeType.Day:\n startDate = getDatePart(date);\n endDate = addDays(startDate, daysToSelectInDayView);\n break;\n\n case DateRangeType.Week:\n case DateRangeType.WorkWeek:\n startDate = getStartDateOfWeek(getDatePart(date), firstDayOfWeek);\n endDate = addDays(startDate, TimeConstants.DaysInOneWeek);\n break;\n\n case DateRangeType.Month:\n startDate = new Date(date.getFullYear(), date.getMonth(), 1);\n endDate = addMonths(startDate, 1);\n break;\n\n default:\n throw new Error('Unexpected object: ' + dateRangeType);\n }\n\n // Populate the dates array with the dates in range\n let nextDate = startDate;\n\n do {\n if (dateRangeType !== DateRangeType.WorkWeek) {\n // push all days not in work week view\n datesArray.push(nextDate);\n } else if (workWeekDays.indexOf(nextDate.getDay()) !== -1) {\n datesArray.push(nextDate);\n }\n nextDate = addDays(nextDate, 1);\n } while (!compareDates(nextDate, endDate));\n\n return datesArray;\n}\n\n/**\n * Checks whether the specified date is in the given date range.\n * @param date - The origin date\n * @param dateRange - An array of dates to do the lookup on\n * @returns True if the date matches one of the dates in the specified array, false otherwise.\n */\nexport function isInDateRangeArray(date: Date, dateRange: Date[]): boolean {\n for (const dateInRange of dateRange) {\n if (compareDates(date, dateInRange)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Returns the week number for a date.\n * Week numbers are 1 - 52 (53) in a year\n * @param navigatedDate - A date to find the week number for.\n * @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)\n * @param firstWeekOfYear - The first week of the year (1-2)\n * @returns The weeks number array for the current month.\n */\nexport function getWeekNumbersInMonth(\n weeksInMonth: number,\n firstDayOfWeek: DayOfWeek,\n firstWeekOfYear: FirstWeekOfYear,\n navigatedDate: Date,\n): number[] {\n const selectedYear = navigatedDate.getFullYear();\n const selectedMonth = navigatedDate.getMonth();\n let dayOfMonth = 1;\n const fistDayOfMonth = new Date(selectedYear, selectedMonth, dayOfMonth);\n const endOfFirstWeek =\n dayOfMonth +\n (firstDayOfWeek + TimeConstants.DaysInOneWeek - 1) -\n adjustWeekDay(firstDayOfWeek, fistDayOfMonth.getDay());\n let endOfWeekRange = new Date(selectedYear, selectedMonth, endOfFirstWeek);\n dayOfMonth = endOfWeekRange.getDate();\n\n const weeksArray = [];\n for (let i = 0; i < weeksInMonth; i++) {\n // Get week number for end of week\n weeksArray.push(getWeekNumber(endOfWeekRange, firstDayOfWeek, firstWeekOfYear));\n dayOfMonth += TimeConstants.DaysInOneWeek;\n endOfWeekRange = new Date(selectedYear, selectedMonth, dayOfMonth);\n }\n return weeksArray;\n}\n\n/**\n * Returns the week number for a date.\n * Week numbers are 1 - 52 (53) in a year\n * @param date - A date to find the week number for.\n * @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)\n * @param firstWeekOfYear - The first week of the year (1-2)\n * @returns The week's number in the year.\n */\nexport function getWeekNumber(date: Date, firstDayOfWeek: DayOfWeek, firstWeekOfYear: FirstWeekOfYear): number {\n // First four-day week of the year - minumum days count\n const fourDayWeek = 4;\n\n switch (firstWeekOfYear) {\n case FirstWeekOfYear.FirstFullWeek:\n return getWeekOfYearFullDays(date, firstDayOfWeek, TimeConstants.DaysInOneWeek);\n\n case FirstWeekOfYear.FirstFourDayWeek:\n return getWeekOfYearFullDays(date, firstDayOfWeek, fourDayWeek);\n\n default:\n return getFirstDayWeekOfYear(date, firstDayOfWeek);\n }\n}\n\n/**\n * Gets the date for the first day of the week based on the given date assuming\n * the specified first day of the week.\n * @param date - The date to find the beginning of the week date for.\n * @returns A new date object representing the first day of the week containing the input date.\n */\nexport function getStartDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date {\n let daysOffset = firstDayOfWeek - date.getDay();\n if (daysOffset > 0) {\n // If first day of week is > date, go 1 week back, to ensure resulting date is in the past.\n daysOffset -= TimeConstants.DaysInOneWeek;\n }\n return addDays(date, daysOffset);\n}\n\n/**\n * Gets the date for the last day of the week based on the given date assuming\n * the specified first day of the week.\n * @param date - The date to find the beginning of the week date for.\n * @returns A new date object representing the first day of the week containing the input date.\n */\nexport function getEndDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date {\n const lastDayOfWeek = firstDayOfWeek - 1 >= 0 ? firstDayOfWeek - 1 : TimeConstants.DaysInOneWeek - 1;\n let daysOffset = lastDayOfWeek - date.getDay();\n if (daysOffset < 0) {\n // If last day of week is < date, go 1 week forward, to ensure resulting date is in the future.\n daysOffset += TimeConstants.DaysInOneWeek;\n }\n return addDays(date, daysOffset);\n}\n\n/**\n * Gets a new date with the time portion zeroed out, i.e., set to midnight\n * @param date - The origin date\n * @returns A new date with the time set to midnight\n */\nfunction getDatePart(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), date.getDate());\n}\n\n/**\n * Helper function to assist in date comparisons\n */\nexport function getDatePartHashValue(date: Date): number {\n // Generate date hash value created as sum of Date (up to 31 = 5 bits), Month (up to 11 = 4 bits) and Year.\n // eslint-disable-next-line no-bitwise\n return date.getDate() + (date.getMonth() << 5) + (date.getFullYear() << 9);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @param numberOfFullDays - week settings.\n * @returns The week's number in the year.\n */\nfunction getWeekOfYearFullDays(date: Date, firstDayOfWeek: DayOfWeek, numberOfFullDays: number): number {\n const dayOfYear = getDayOfYear(date) - 1;\n let num = date.getDay() - (dayOfYear % TimeConstants.DaysInOneWeek);\n\n const lastDayOfPrevYear = new Date(date.getFullYear() - 1, MonthOfYear.December, 31);\n const daysInYear = getDayOfYear(lastDayOfPrevYear) - 1;\n\n let num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n if (num2 !== 0 && num2 >= numberOfFullDays) {\n num2 -= TimeConstants.DaysInOneWeek;\n }\n\n let num3 = dayOfYear - num2;\n if (num3 < 0) {\n num -= daysInYear % TimeConstants.DaysInOneWeek;\n num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n if (num2 !== 0 && num2 + 1 >= numberOfFullDays) {\n num2 -= TimeConstants.DaysInOneWeek;\n }\n\n num3 = daysInYear - num2;\n }\n\n return Math.floor(num3 / TimeConstants.DaysInOneWeek + 1);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns week number for a date.\n * @param date - current selected date.\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @returns The week's number in the year.\n */\nfunction getFirstDayWeekOfYear(date: Date, firstDayOfWeek: number): number {\n const num = getDayOfYear(date) - 1;\n const num2 = date.getDay() - (num % TimeConstants.DaysInOneWeek);\n const num3 = (num2 - firstDayOfWeek + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;\n\n return Math.floor((num + num3) / TimeConstants.DaysInOneWeek + 1);\n}\n\n/**\n * Helper function for `getWeekNumber`.\n * Returns adjusted week day number when `firstDayOfWeek` is other than Sunday.\n * For Week Day Number comparison checks\n * @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)\n * @param dateWeekDay - shifts number forward to 1 week in case passed as true\n * @returns The day of week adjusted to `firstDayOfWeek`; e.g. when `firstDayOfWeek` is Monday (1),\n * Sunday becomes 7.\n */\nfunction adjustWeekDay(firstDayOfWeek: DayOfWeek, dateWeekDay: DayOfWeek): number {\n return firstDayOfWeek !== DayOfWeek.Sunday && dateWeekDay < firstDayOfWeek\n ? dateWeekDay + TimeConstants.DaysInOneWeek\n : dateWeekDay;\n}\n\n/**\n * Returns the day number for a date in a year:\n * the number of days since January 1st in the particular year.\n * @param date - A date to find the day number for.\n * @returns The day's number in the year.\n */\nfunction getDayOfYear(date: Date): number {\n const month = date.getMonth();\n const year = date.getFullYear();\n let daysUntilDate = 0;\n\n for (let i = 0; i < month; i++) {\n daysUntilDate += daysInMonth(i + 1, year);\n }\n\n daysUntilDate += date.getDate();\n\n return daysUntilDate;\n}\n\n/**\n * Returns the number of days in the month\n * @param month - The month number to target (months 1-12).\n * @param year - The year to target.\n * @returns The number of days in the month.\n */\nfunction daysInMonth(month: number, year: number): number {\n return new Date(year, month, 0).getDate();\n}\n"],"names":["DateRangeType","DayOfWeek","FirstWeekOfYear","MonthOfYear","TimeConstants","addDays","date","days","result","Date","getTime","setDate","getDate","addWeeks","weeks","DaysInOneWeek","addMonths","months","newMonth","getMonth","setMonth","MonthInOneYear","addYears","years","setFullYear","getFullYear","getMonthStart","getMonthEnd","getYearStart","getYearEnd","month","compareDates","date1","date2","compareDatePart","getDatePartHashValue","getDateRangeArray","dateRangeType","firstDayOfWeek","workWeekDays","daysToSelectInDayView","datesArray","startDate","endDate","Monday","Tuesday","Wednesday","Thursday","Friday","Math","max","Day","getDatePart","Week","WorkWeek","getStartDateOfWeek","Month","Error","nextDate","push","indexOf","getDay","isInDateRangeArray","dateRange","dateInRange","getWeekNumbersInMonth","weeksInMonth","firstWeekOfYear","navigatedDate","selectedYear","selectedMonth","dayOfMonth","fistDayOfMonth","endOfFirstWeek","adjustWeekDay","endOfWeekRange","weeksArray","i","getWeekNumber","fourDayWeek","FirstFullWeek","getWeekOfYearFullDays","FirstFourDayWeek","getFirstDayWeekOfYear","daysOffset","getEndDateOfWeek","lastDayOfWeek","numberOfFullDays","dayOfYear","getDayOfYear","num","lastDayOfPrevYear","December","daysInYear","num2","num3","floor","dateWeekDay","Sunday","year","daysUntilDate","daysInMonth"],"mappings":"AAAA,SAASA,aAAa,EAAEC,SAAS,EAAEC,eAAe,EAAEC,WAAW,EAAEC,aAAa,QAAQ,eAAe;AAErG;;;;;CAKC,GACD,OAAO,SAASC,QAAQC,IAAU,EAAEC,IAAY;IAC9C,MAAMC,SAAS,IAAIC,KAAKH,KAAKI,OAAO;IACpCF,OAAOG,OAAO,CAACH,OAAOI,OAAO,KAAKL;IAClC,OAAOC;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASK,SAASP,IAAU,EAAEQ,KAAa;IAChD,OAAOT,QAAQC,MAAMQ,QAAQV,cAAcW,aAAa;AAC1D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,UAAUV,IAAU,EAAEW,MAAc;IAClD,IAAIT,SAAS,IAAIC,KAAKH,KAAKI,OAAO;IAClC,MAAMQ,WAAWV,OAAOW,QAAQ,KAAKF;IACrCT,OAAOY,QAAQ,CAACF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AAK,CAAC,AAACN,CAAAA,MAAMK,IAAG,IAAK3F,cAAcW,aAAa,GAAG;AACjE;AAEA;;;;;;;;CAQC,GACD,SAAS2D,cAAcpC,cAAyB,EAAE2D,WAAsB;IACtE,OAAO3D,mBAAmBrC,UAAUiG,MAAM,IAAID,cAAc3D,iBACxD2D,cAAc7F,cAAcW,aAAa,GACzCkF;AACN;AAEA;;;;;CAKC,GACD,SAASR,aAAanF,IAAU;IAC9B,MAAMwB,QAAQxB,KAAKa,QAAQ;IAC3B,MAAMgF,OAAO7F,KAAKmB,WAAW;IAC7B,IAAI2E,gBAAgB;IAEpB,IAAK,IAAIvB,IAAI,GAAGA,IAAI/C,OAAO+C,IAAK;QAC9BuB,iBAAiBC,YAAYxB,IAAI,GAAGsB;IACtC;IAEAC,iBAAiB9F,KAAKM,OAAO;IAE7B,OAAOwF;AACT;AAEA;;;;;CAKC,GACD,SAASC,YAAYvE,KAAa,EAAEqE,IAAY;IAC9C,OAAO,IAAI1F,KAAK0F,MAAMrE,OAAO,GAAGlB,OAAO;AACzC"}
|
package/lib/utils/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["dom.ts"],"sourcesContent":["import { canUseDOM } from '@fluentui/react-utilities';\n\nexport function getWindow(targetElement?: Element | null): Window | undefined {\n if (!canUseDOM() || typeof window === 'undefined') {\n return undefined;\n }\n\n const el = targetElement as Element;\n\n return el && el.ownerDocument && el.ownerDocument.defaultView ? el.ownerDocument.defaultView : window;\n}\n"],"names":["canUseDOM","getWindow","targetElement","window","undefined","el","ownerDocument","defaultView"],"mappings":"AAAA,SAASA,SAAS,QAAQ,4BAA4B;AAEtD,OAAO,SAASC,UAAUC,aAA8B
|
|
1
|
+
{"version":3,"sources":["dom.ts"],"sourcesContent":["import { canUseDOM } from '@fluentui/react-utilities';\n\nexport function getWindow(targetElement?: Element | null): Window | undefined {\n if (!canUseDOM() || typeof window === 'undefined') {\n return undefined;\n }\n\n const el = targetElement as Element;\n\n return el && el.ownerDocument && el.ownerDocument.defaultView ? el.ownerDocument.defaultView : window;\n}\n"],"names":["canUseDOM","getWindow","targetElement","window","undefined","el","ownerDocument","defaultView"],"mappings":"AAAA,SAASA,SAAS,QAAQ,4BAA4B;AAEtD,OAAO,SAASC,UAAUC,aAA8B;IACtD,IAAI,CAACF,eAAe,OAAOG,WAAW,aAAa;QACjD,OAAOC;IACT;IAEA,MAAMC,KAAKH;IAEX,OAAOG,MAAMA,GAAGC,aAAa,IAAID,GAAGC,aAAa,CAACC,WAAW,GAAGF,GAAGC,aAAa,CAACC,WAAW,GAAGJ;AACjG"}
|
package/lib/utils/focus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["focus.ts"],"sourcesContent":["import { getWindow } from './dom';\n\nlet targetToFocusOnNextRepaint: HTMLElement | { focus: () => void } | null | undefined = undefined;\n\n/**\n * Sets focus to an element asynchronously. The focus will be set at the next browser repaint,\n * meaning it won't cause any extra recalculations. If more than one focusAsync is called during one frame,\n * only the latest called focusAsync element will actually be focused\n * @param element - The element to focus\n */\nexport function focusAsync(element: HTMLElement | { focus: () => void } | undefined | null): void {\n if (element) {\n // An element was already queued to be focused, so replace that one with the new element\n if (targetToFocusOnNextRepaint) {\n targetToFocusOnNextRepaint = element;\n return;\n }\n\n targetToFocusOnNextRepaint = element;\n\n const win = getWindow(element as Element);\n\n if (win) {\n // element.focus() is a no-op if the element is no longer in the DOM, meaning this is always safe\n win.requestAnimationFrame(() => {\n targetToFocusOnNextRepaint && targetToFocusOnNextRepaint.focus();\n\n // We are done focusing for this frame, so reset the queued focus element\n targetToFocusOnNextRepaint = undefined;\n });\n }\n }\n}\n"],"names":["getWindow","targetToFocusOnNextRepaint","undefined","focusAsync","element","win","requestAnimationFrame","focus"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAElC,IAAIC,6BAAqFC;AAEzF;;;;;CAKC,GACD,OAAO,SAASC,WAAWC,OAA+D
|
|
1
|
+
{"version":3,"sources":["focus.ts"],"sourcesContent":["import { getWindow } from './dom';\n\nlet targetToFocusOnNextRepaint: HTMLElement | { focus: () => void } | null | undefined = undefined;\n\n/**\n * Sets focus to an element asynchronously. The focus will be set at the next browser repaint,\n * meaning it won't cause any extra recalculations. If more than one focusAsync is called during one frame,\n * only the latest called focusAsync element will actually be focused\n * @param element - The element to focus\n */\nexport function focusAsync(element: HTMLElement | { focus: () => void } | undefined | null): void {\n if (element) {\n // An element was already queued to be focused, so replace that one with the new element\n if (targetToFocusOnNextRepaint) {\n targetToFocusOnNextRepaint = element;\n return;\n }\n\n targetToFocusOnNextRepaint = element;\n\n const win = getWindow(element as Element);\n\n if (win) {\n // element.focus() is a no-op if the element is no longer in the DOM, meaning this is always safe\n win.requestAnimationFrame(() => {\n targetToFocusOnNextRepaint && targetToFocusOnNextRepaint.focus();\n\n // We are done focusing for this frame, so reset the queued focus element\n targetToFocusOnNextRepaint = undefined;\n });\n }\n }\n}\n"],"names":["getWindow","targetToFocusOnNextRepaint","undefined","focusAsync","element","win","requestAnimationFrame","focus"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAElC,IAAIC,6BAAqFC;AAEzF;;;;;CAKC,GACD,OAAO,SAASC,WAAWC,OAA+D;IACxF,IAAIA,SAAS;QACX,wFAAwF;QACxF,IAAIH,4BAA4B;YAC9BA,6BAA6BG;YAC7B;QACF;QAEAH,6BAA6BG;QAE7B,MAAMC,MAAML,UAAUI;QAEtB,IAAIC,KAAK;YACP,iGAAiG;YACjGA,IAAIC,qBAAqB,CAAC;gBACxBL,8BAA8BA,2BAA2BM,KAAK;gBAE9D,yEAAyE;gBACzEN,6BAA6BC;YAC/B;QACF;IACF;AACF"}
|