@react-stately/calendar 3.0.0-nightly.1349 → 3.0.0-nightly.1356
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/dist/main.js +326 -407
- package/dist/main.js.map +1 -1
- package/dist/module.js +310 -375
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/module.js
CHANGED
|
@@ -1,410 +1,345 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { useDateFormatter
|
|
4
|
-
import {
|
|
5
|
-
import { maxDate, minDate, startOfMonth, startOfWeek, startOfYear, toCalendarDate, GregorianCalendar, isSameDay, toCalendar, today } from "@internationalized/date";
|
|
6
|
-
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
|
|
1
|
+
import {toCalendar as $7F3MR$toCalendar, toCalendarDate as $7F3MR$toCalendarDate, today as $7F3MR$today, GregorianCalendar as $7F3MR$GregorianCalendar, isSameDay as $7F3MR$isSameDay, startOfYear as $7F3MR$startOfYear, startOfMonth as $7F3MR$startOfMonth, startOfWeek as $7F3MR$startOfWeek, maxDate as $7F3MR$maxDate, minDate as $7F3MR$minDate} from "@internationalized/date";
|
|
2
|
+
import {useControlledState as $7F3MR$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useDateFormatter as $7F3MR$useDateFormatter} from "@react-aria/i18n";
|
|
4
|
+
import {useMemo as $7F3MR$useMemo, useState as $7F3MR$useState, useRef as $7F3MR$useRef, useEffect as $7F3MR$useEffect} from "react";
|
|
7
5
|
|
|
8
|
-
function $
|
|
9
|
-
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
10
8
|
}
|
|
9
|
+
var $103da5e0f4a8c171$exports = {};
|
|
11
10
|
|
|
12
|
-
function $e9245e22e7d2e30e959129f8619bae$export$alignCenter(date, duration, locale, minValue, maxValue) {
|
|
13
|
-
let halfDuration = {};
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
12
|
+
var $071794a38ae0e339$exports = {};
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
halfDuration[key]--;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
14
|
+
$parcel$export($071794a38ae0e339$exports, "useCalendarState", () => $071794a38ae0e339$export$6d095e787d2b5e1f);
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
function $5415b3b7a99138bd$export$eac50920cf2fd59a(date, minValue, maxValue) {
|
|
17
|
+
return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
aligned
|
|
35
|
-
} else if (duration.weeks) {
|
|
36
|
-
aligned = startOfWeek(date, locale);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return $e9245e22e7d2e30e959129f8619bae$export$constrainStart(date, aligned, duration, locale, minValue, maxValue);
|
|
19
|
+
function $5415b3b7a99138bd$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) {
|
|
20
|
+
let halfDuration = {
|
|
21
|
+
};
|
|
22
|
+
for(let key in duration){
|
|
23
|
+
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
24
|
+
if (halfDuration[key] > 0 && duration[key] % 2 === 0) halfDuration[key]--;
|
|
25
|
+
}
|
|
26
|
+
let aligned = $5415b3b7a99138bd$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration);
|
|
27
|
+
return $5415b3b7a99138bd$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else if (duration.weeks) {
|
|
49
|
-
d.weeks--;
|
|
50
|
-
} else if (duration.months) {
|
|
51
|
-
d.months--;
|
|
52
|
-
} else if (duration.years) {
|
|
53
|
-
d.years--;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let aligned = $e9245e22e7d2e30e959129f8619bae$export$alignStart(date, duration, locale).subtract(d);
|
|
57
|
-
return $e9245e22e7d2e30e959129f8619bae$export$constrainStart(date, aligned, duration, locale, minValue, maxValue);
|
|
29
|
+
function $5415b3b7a99138bd$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) {
|
|
30
|
+
// align to the start of the largest unit
|
|
31
|
+
let aligned = date;
|
|
32
|
+
if (duration.years) aligned = $7F3MR$startOfYear(date);
|
|
33
|
+
else if (duration.months) aligned = $7F3MR$startOfMonth(date);
|
|
34
|
+
else if (duration.weeks) aligned = $7F3MR$startOfWeek(date, locale);
|
|
35
|
+
return $5415b3b7a99138bd$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
function $5415b3b7a99138bd$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) {
|
|
38
|
+
let d = {
|
|
39
|
+
...duration
|
|
40
|
+
};
|
|
41
|
+
// subtract 1 from the smallest unit
|
|
42
|
+
if (duration.days) d.days--;
|
|
43
|
+
else if (duration.weeks) d.weeks--;
|
|
44
|
+
else if (duration.months) d.months--;
|
|
45
|
+
else if (duration.years) d.years--;
|
|
46
|
+
let aligned = $5415b3b7a99138bd$export$144a00ba6044eb9(date, duration, locale).subtract(d);
|
|
47
|
+
return $5415b3b7a99138bd$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
|
|
70
48
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
date = minDate(date, toCalendarDate(maxValue));
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return date;
|
|
49
|
+
function $5415b3b7a99138bd$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) {
|
|
50
|
+
if (minValue && date.compare(minValue) >= 0) aligned = $7F3MR$maxDate(aligned, $5415b3b7a99138bd$export$144a00ba6044eb9($7F3MR$toCalendarDate(minValue), duration, locale));
|
|
51
|
+
if (maxValue && date.compare(maxValue) <= 0) aligned = $7F3MR$minDate(aligned, $5415b3b7a99138bd$export$530edbfc915b2b04($7F3MR$toCalendarDate(maxValue), duration, locale));
|
|
52
|
+
return aligned;
|
|
53
|
+
}
|
|
54
|
+
function $5415b3b7a99138bd$export$4f5203c0d889109e(date, minValue, maxValue) {
|
|
55
|
+
if (minValue) date = $7F3MR$maxDate(date, $7F3MR$toCalendarDate(minValue));
|
|
56
|
+
if (maxValue) date = $7F3MR$minDate(date, $7F3MR$toCalendarDate(maxValue));
|
|
57
|
+
return date;
|
|
82
58
|
}
|
|
83
59
|
|
|
84
|
-
export function useCalendarState(props) {
|
|
85
|
-
let defaultFormatter = useDateFormatter();
|
|
86
|
-
let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);
|
|
87
|
-
let {
|
|
88
|
-
locale,
|
|
89
|
-
createCalendar,
|
|
90
|
-
timeZone = resolvedOptions.timeZone,
|
|
91
|
-
visibleDuration = {
|
|
92
|
-
months: 1
|
|
93
|
-
},
|
|
94
|
-
minValue,
|
|
95
|
-
maxValue,
|
|
96
|
-
selectionAlignment
|
|
97
|
-
} = props;
|
|
98
|
-
let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]);
|
|
99
|
-
let [value, setControlledValue] = useControlledState(props.value, props.defaultValue, props.onChange);
|
|
100
|
-
let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);
|
|
101
|
-
let defaultDate = useMemo(() => calendarDateValue || $e9245e22e7d2e30e959129f8619bae$export$constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue), [calendarDateValue, timeZone, calendar, minValue, maxValue]);
|
|
102
|
-
let [startDate, setStartDate] = useState(() => {
|
|
103
|
-
switch (selectionAlignment) {
|
|
104
|
-
case 'start':
|
|
105
|
-
return $e9245e22e7d2e30e959129f8619bae$export$alignStart(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
106
60
|
|
|
107
|
-
case 'end':
|
|
108
|
-
return $e9245e22e7d2e30e959129f8619bae$export$alignEnd(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
109
61
|
|
|
110
|
-
case 'center':
|
|
111
|
-
default:
|
|
112
|
-
return $e9245e22e7d2e30e959129f8619bae$export$alignCenter(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
let [focusedDate, setFocusedDate] = useState(defaultDate);
|
|
116
|
-
let [isFocused, setFocused] = useState(props.autoFocus || false);
|
|
117
|
-
let endDate = useMemo(() => startDate.add(visibleDuration).subtract({
|
|
118
|
-
days: 1
|
|
119
|
-
}), [startDate, visibleDuration]); // Reset focused date and visible range when calendar changes.
|
|
120
62
|
|
|
121
|
-
let lastCalendarIdentifier = useRef(calendar.identifier);
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
124
|
-
let newFocusedDate = toCalendar(focusedDate, calendar);
|
|
125
|
-
setStartDate($e9245e22e7d2e30e959129f8619bae$export$alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));
|
|
126
|
-
setFocusedDate(newFocusedDate);
|
|
127
|
-
lastCalendarIdentifier.current = calendar.identifier;
|
|
128
|
-
}
|
|
129
|
-
}, [calendar, focusedDate, visibleDuration, locale, minValue, maxValue]); // Sets focus to a specific cell date
|
|
130
63
|
|
|
131
|
-
function focusCell(date) {
|
|
132
|
-
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue);
|
|
133
|
-
date = $e9245e22e7d2e30e959129f8619bae$export$constrainValue(date, minValue, maxValue);
|
|
134
|
-
let next = startDate.add(visibleDuration);
|
|
135
64
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
65
|
+
function $071794a38ae0e339$export$6d095e787d2b5e1f(props) {
|
|
66
|
+
let defaultFormatter = $7F3MR$useDateFormatter();
|
|
67
|
+
let resolvedOptions = $7F3MR$useMemo(()=>defaultFormatter.resolvedOptions()
|
|
68
|
+
, [
|
|
69
|
+
defaultFormatter
|
|
70
|
+
]);
|
|
71
|
+
let { locale: locale , createCalendar: createCalendar , timeZone: timeZone = resolvedOptions.timeZone , visibleDuration: visibleDuration = {
|
|
72
|
+
months: 1
|
|
73
|
+
} , minValue: minValue , maxValue: maxValue , selectionAlignment: selectionAlignment } = props;
|
|
74
|
+
let calendar = $7F3MR$useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
75
|
+
, [
|
|
76
|
+
createCalendar,
|
|
77
|
+
resolvedOptions.calendar
|
|
78
|
+
]);
|
|
79
|
+
let [value, setControlledValue] = $7F3MR$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
80
|
+
let calendarDateValue = $7F3MR$useMemo(()=>value ? $7F3MR$toCalendar($7F3MR$toCalendarDate(value), calendar) : null
|
|
81
|
+
, [
|
|
82
|
+
value,
|
|
83
|
+
calendar
|
|
84
|
+
]);
|
|
85
|
+
let defaultDate = $7F3MR$useMemo(()=>calendarDateValue || $5415b3b7a99138bd$export$4f5203c0d889109e($7F3MR$toCalendar($7F3MR$today(timeZone), calendar), minValue, maxValue)
|
|
86
|
+
, [
|
|
87
|
+
calendarDateValue,
|
|
88
|
+
timeZone,
|
|
89
|
+
calendar,
|
|
90
|
+
minValue,
|
|
91
|
+
maxValue
|
|
92
|
+
]);
|
|
93
|
+
let [startDate, setStartDate] = $7F3MR$useState(()=>{
|
|
94
|
+
switch(selectionAlignment){
|
|
95
|
+
case 'start':
|
|
96
|
+
return $5415b3b7a99138bd$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
97
|
+
case 'end':
|
|
98
|
+
return $5415b3b7a99138bd$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
99
|
+
case 'center':
|
|
100
|
+
default:
|
|
101
|
+
return $5415b3b7a99138bd$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
let [focusedDate, setFocusedDate] = $7F3MR$useState(defaultDate);
|
|
105
|
+
let [isFocused, setFocused] = $7F3MR$useState(props.autoFocus || false);
|
|
106
|
+
let endDate = $7F3MR$useMemo(()=>startDate.add(visibleDuration).subtract({
|
|
107
|
+
days: 1
|
|
108
|
+
})
|
|
109
|
+
, [
|
|
110
|
+
startDate,
|
|
111
|
+
visibleDuration
|
|
112
|
+
]);
|
|
113
|
+
// Reset focused date and visible range when calendar changes.
|
|
114
|
+
let lastCalendarIdentifier = $7F3MR$useRef(calendar.identifier);
|
|
115
|
+
$7F3MR$useEffect(()=>{
|
|
116
|
+
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
117
|
+
let newFocusedDate = $7F3MR$toCalendar(focusedDate, calendar);
|
|
118
|
+
setStartDate($5415b3b7a99138bd$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue));
|
|
119
|
+
setFocusedDate(newFocusedDate);
|
|
120
|
+
lastCalendarIdentifier.current = calendar.identifier;
|
|
121
|
+
}
|
|
122
|
+
}, [
|
|
123
|
+
calendar,
|
|
124
|
+
focusedDate,
|
|
125
|
+
visibleDuration,
|
|
126
|
+
locale,
|
|
127
|
+
minValue,
|
|
128
|
+
maxValue
|
|
129
|
+
]);
|
|
130
|
+
// Sets focus to a specific cell date
|
|
131
|
+
function focusCell(date) {
|
|
132
|
+
// date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue);
|
|
133
|
+
date = $5415b3b7a99138bd$export$4f5203c0d889109e(date, minValue, maxValue);
|
|
134
|
+
let next = startDate.add(visibleDuration);
|
|
135
|
+
if (date.compare(startDate) < 0) setStartDate($5415b3b7a99138bd$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue));
|
|
136
|
+
else if (date.compare(next) >= 0) setStartDate($5415b3b7a99138bd$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue));
|
|
137
|
+
setFocusedDate(date);
|
|
140
138
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (value && 'hour' in value) {
|
|
152
|
-
setControlledValue(value.set(newValue));
|
|
153
|
-
} else {
|
|
154
|
-
setControlledValue(newValue);
|
|
155
|
-
}
|
|
139
|
+
function setValue(newValue) {
|
|
140
|
+
if (!props.isDisabled && !props.isReadOnly) {
|
|
141
|
+
// The display calendar should not have any effect on the emitted value.
|
|
142
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
143
|
+
newValue = $7F3MR$toCalendar(newValue, value?.calendar || new $7F3MR$GregorianCalendar());
|
|
144
|
+
// Preserve time if the input value had one.
|
|
145
|
+
if (value && 'hour' in value) setControlledValue(value.set(newValue));
|
|
146
|
+
else setControlledValue(newValue);
|
|
147
|
+
}
|
|
156
148
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
149
|
+
return {
|
|
150
|
+
isDisabled: props.isDisabled,
|
|
151
|
+
isReadOnly: props.isReadOnly,
|
|
152
|
+
value: calendarDateValue,
|
|
153
|
+
setValue: setValue,
|
|
154
|
+
visibleRange: {
|
|
155
|
+
start: startDate,
|
|
156
|
+
end: endDate
|
|
157
|
+
},
|
|
158
|
+
focusedDate: focusedDate,
|
|
159
|
+
timeZone: timeZone,
|
|
160
|
+
setFocusedDate (date) {
|
|
161
|
+
setFocusedDate(date);
|
|
162
|
+
setFocused(true);
|
|
163
|
+
},
|
|
164
|
+
focusNextDay () {
|
|
165
|
+
focusCell(focusedDate.add({
|
|
166
|
+
days: 1
|
|
167
|
+
}));
|
|
168
|
+
},
|
|
169
|
+
focusPreviousDay () {
|
|
170
|
+
focusCell(focusedDate.subtract({
|
|
171
|
+
days: 1
|
|
172
|
+
}));
|
|
173
|
+
},
|
|
174
|
+
focusNextRow () {
|
|
175
|
+
if (visibleDuration.days) this.focusNextPage();
|
|
176
|
+
else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
|
|
177
|
+
weeks: 1
|
|
178
|
+
}));
|
|
179
|
+
},
|
|
180
|
+
focusPreviousRow () {
|
|
181
|
+
if (visibleDuration.days) this.focusPreviousPage();
|
|
182
|
+
else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
|
|
183
|
+
weeks: 1
|
|
184
|
+
}));
|
|
185
|
+
},
|
|
186
|
+
focusNextPage () {
|
|
187
|
+
let start = startDate.add(visibleDuration);
|
|
188
|
+
setStartDate($5415b3b7a99138bd$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue));
|
|
189
|
+
setFocusedDate($5415b3b7a99138bd$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue));
|
|
190
|
+
},
|
|
191
|
+
focusPreviousPage () {
|
|
192
|
+
let start = startDate.subtract(visibleDuration);
|
|
193
|
+
setStartDate($5415b3b7a99138bd$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue));
|
|
194
|
+
setFocusedDate($5415b3b7a99138bd$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue));
|
|
195
|
+
},
|
|
196
|
+
focusPageStart () {
|
|
197
|
+
focusCell(startDate);
|
|
198
|
+
},
|
|
199
|
+
focusPageEnd () {
|
|
200
|
+
focusCell(endDate);
|
|
201
|
+
},
|
|
202
|
+
focusNextSection () {
|
|
203
|
+
if (visibleDuration.days) this.focusNextPage();
|
|
204
|
+
else if (visibleDuration.weeks) focusCell(focusedDate.add({
|
|
205
|
+
months: 1
|
|
206
|
+
}));
|
|
207
|
+
else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
|
|
208
|
+
years: 1
|
|
209
|
+
}));
|
|
210
|
+
},
|
|
211
|
+
focusPreviousSection () {
|
|
212
|
+
if (visibleDuration.days) this.focusPreviousPage();
|
|
213
|
+
else if (visibleDuration.weeks) focusCell(focusedDate.subtract({
|
|
214
|
+
months: 1
|
|
215
|
+
}));
|
|
216
|
+
else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
|
|
217
|
+
years: 1
|
|
218
|
+
}));
|
|
219
|
+
},
|
|
220
|
+
selectFocusedDate () {
|
|
221
|
+
setValue(focusedDate);
|
|
222
|
+
},
|
|
223
|
+
selectDate (date) {
|
|
224
|
+
setValue(date);
|
|
225
|
+
},
|
|
226
|
+
isFocused: isFocused,
|
|
227
|
+
setFocused: setFocused,
|
|
228
|
+
isInvalid (date) {
|
|
229
|
+
return $5415b3b7a99138bd$export$eac50920cf2fd59a(date, minValue, maxValue);
|
|
230
|
+
},
|
|
231
|
+
isSelected (date) {
|
|
232
|
+
return calendarDateValue != null && $7F3MR$isSameDay(date, calendarDateValue);
|
|
233
|
+
},
|
|
234
|
+
isCellFocused (date) {
|
|
235
|
+
return isFocused && focusedDate && $7F3MR$isSameDay(date, focusedDate);
|
|
236
|
+
},
|
|
237
|
+
isCellDisabled (date) {
|
|
238
|
+
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $5415b3b7a99138bd$export$eac50920cf2fd59a(date, minValue, maxValue);
|
|
239
|
+
},
|
|
240
|
+
isPreviousVisibleRangeInvalid () {
|
|
241
|
+
return $5415b3b7a99138bd$export$eac50920cf2fd59a(startDate.subtract({
|
|
242
|
+
days: 1
|
|
243
|
+
}), minValue, maxValue);
|
|
244
|
+
},
|
|
245
|
+
isNextVisibleRangeInvalid () {
|
|
246
|
+
return $5415b3b7a99138bd$export$eac50920cf2fd59a(endDate.add({
|
|
247
|
+
days: 1
|
|
248
|
+
}), minValue, maxValue);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
259
252
|
|
|
260
|
-
selectDate(date) {
|
|
261
|
-
setValue(date);
|
|
262
|
-
},
|
|
263
253
|
|
|
264
|
-
|
|
265
|
-
setFocused,
|
|
254
|
+
var $b4f14c36da84ed2c$exports = {};
|
|
266
255
|
|
|
267
|
-
|
|
268
|
-
return $e9245e22e7d2e30e959129f8619bae$export$isInvalid(date, minValue, maxValue);
|
|
269
|
-
},
|
|
256
|
+
$parcel$export($b4f14c36da84ed2c$exports, "useRangeCalendarState", () => $b4f14c36da84ed2c$export$9a987164d97ecc90);
|
|
270
257
|
|
|
271
|
-
isSelected(date) {
|
|
272
|
-
return calendarDateValue != null && isSameDay(date, calendarDateValue);
|
|
273
|
-
},
|
|
274
258
|
|
|
275
|
-
isCellFocused(date) {
|
|
276
|
-
return isFocused && focusedDate && isSameDay(date, focusedDate);
|
|
277
|
-
},
|
|
278
259
|
|
|
279
|
-
isCellDisabled(date) {
|
|
280
|
-
return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $e9245e22e7d2e30e959129f8619bae$export$isInvalid(date, minValue, maxValue);
|
|
281
|
-
},
|
|
282
260
|
|
|
283
|
-
isPreviousVisibleRangeInvalid() {
|
|
284
|
-
return $e9245e22e7d2e30e959129f8619bae$export$isInvalid(startDate.subtract({
|
|
285
|
-
days: 1
|
|
286
|
-
}), minValue, maxValue);
|
|
287
|
-
},
|
|
288
261
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
262
|
+
function $b4f14c36da84ed2c$export$9a987164d97ecc90(props) {
|
|
263
|
+
let { value: valueProp , defaultValue: defaultValue , onChange: onChange , createCalendar: createCalendar , locale: locale , visibleDuration: visibleDuration = {
|
|
264
|
+
months: 1
|
|
265
|
+
} , minValue: minValue , maxValue: maxValue , ...calendarProps } = props;
|
|
266
|
+
let [value, setValue] = $7F3MR$useControlledState(valueProp, defaultValue, onChange);
|
|
267
|
+
let [anchorDate, setAnchorDate] = $7F3MR$useState(null);
|
|
268
|
+
let alignment = 'center';
|
|
269
|
+
if (value && value.start && value.end) {
|
|
270
|
+
let start = $5415b3b7a99138bd$export$f4a51ff076cc9a09($7F3MR$toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);
|
|
271
|
+
let end = start.add(visibleDuration).subtract({
|
|
272
|
+
days: 1
|
|
273
|
+
});
|
|
274
|
+
if (value.end.compare(end) > 0) alignment = 'start';
|
|
293
275
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
locale,
|
|
304
|
-
visibleDuration = {
|
|
305
|
-
months: 1
|
|
306
|
-
},
|
|
307
|
-
minValue,
|
|
308
|
-
maxValue
|
|
309
|
-
} = props,
|
|
310
|
-
calendarProps = _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose(props, ["value", "defaultValue", "onChange", "createCalendar", "locale", "visibleDuration", "minValue", "maxValue"]);
|
|
311
|
-
|
|
312
|
-
let [value, setValue] = useControlledState(valueProp, defaultValue, onChange);
|
|
313
|
-
let [anchorDate, setAnchorDate] = useState(null);
|
|
314
|
-
let alignment = 'center';
|
|
315
|
-
|
|
316
|
-
if (value && value.start && value.end) {
|
|
317
|
-
let start = $e9245e22e7d2e30e959129f8619bae$export$alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);
|
|
318
|
-
let end = start.add(visibleDuration).subtract({
|
|
319
|
-
days: 1
|
|
276
|
+
let calendar = $071794a38ae0e339$export$6d095e787d2b5e1f({
|
|
277
|
+
...calendarProps,
|
|
278
|
+
value: value && value.start,
|
|
279
|
+
createCalendar: createCalendar,
|
|
280
|
+
locale: locale,
|
|
281
|
+
visibleDuration: visibleDuration,
|
|
282
|
+
minValue: minValue,
|
|
283
|
+
maxValue: maxValue,
|
|
284
|
+
selectionAlignment: alignment
|
|
320
285
|
});
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
let [isDragging, setDragging] = useState(false);
|
|
356
|
-
return _babelRuntimeHelpersEsmExtends({}, calendar, {
|
|
357
|
-
value,
|
|
358
|
-
setValue,
|
|
359
|
-
anchorDate,
|
|
360
|
-
setAnchorDate,
|
|
361
|
-
highlightedRange,
|
|
362
|
-
|
|
363
|
-
selectFocusedDate() {
|
|
364
|
-
selectDate(calendar.focusedDate);
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
selectDate,
|
|
368
|
-
|
|
369
|
-
highlightDate(date) {
|
|
370
|
-
if (anchorDate) {
|
|
371
|
-
calendar.setFocusedDate(date);
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
|
|
375
|
-
isSelected(date) {
|
|
376
|
-
return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0;
|
|
377
|
-
},
|
|
378
|
-
|
|
379
|
-
isDragging,
|
|
380
|
-
setDragging
|
|
381
|
-
});
|
|
286
|
+
let highlightedRange = anchorDate ? $b4f14c36da84ed2c$var$makeRange(anchorDate, calendar.focusedDate) : value && $b4f14c36da84ed2c$var$makeRange(value.start, value.end);
|
|
287
|
+
let selectDate = (date)=>{
|
|
288
|
+
if (props.isReadOnly) return;
|
|
289
|
+
if (!anchorDate) setAnchorDate(date);
|
|
290
|
+
else {
|
|
291
|
+
let range = $b4f14c36da84ed2c$var$makeRange(anchorDate, date);
|
|
292
|
+
setValue({
|
|
293
|
+
start: $b4f14c36da84ed2c$var$convertValue(range.start, value?.start),
|
|
294
|
+
end: $b4f14c36da84ed2c$var$convertValue(range.end, value?.end)
|
|
295
|
+
});
|
|
296
|
+
setAnchorDate(null);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
let [isDragging, setDragging] = $7F3MR$useState(false);
|
|
300
|
+
return {
|
|
301
|
+
...calendar,
|
|
302
|
+
value: value,
|
|
303
|
+
setValue: setValue,
|
|
304
|
+
anchorDate: anchorDate,
|
|
305
|
+
setAnchorDate: setAnchorDate,
|
|
306
|
+
highlightedRange: highlightedRange,
|
|
307
|
+
selectFocusedDate () {
|
|
308
|
+
selectDate(calendar.focusedDate);
|
|
309
|
+
},
|
|
310
|
+
selectDate: selectDate,
|
|
311
|
+
highlightDate (date) {
|
|
312
|
+
if (anchorDate) calendar.setFocusedDate(date);
|
|
313
|
+
},
|
|
314
|
+
isSelected (date) {
|
|
315
|
+
return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0;
|
|
316
|
+
},
|
|
317
|
+
isDragging: isDragging,
|
|
318
|
+
setDragging: setDragging
|
|
319
|
+
};
|
|
382
320
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
321
|
+
function $b4f14c36da84ed2c$var$makeRange(start, end) {
|
|
322
|
+
if (!start || !end) return null;
|
|
323
|
+
if (end.compare(start) < 0) [start, end] = [
|
|
324
|
+
end,
|
|
325
|
+
start
|
|
326
|
+
];
|
|
327
|
+
return {
|
|
328
|
+
start: $7F3MR$toCalendarDate(start),
|
|
329
|
+
end: $7F3MR$toCalendarDate(end)
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function $b4f14c36da84ed2c$var$convertValue(newValue, oldValue) {
|
|
333
|
+
// The display calendar should not have any effect on the emitted value.
|
|
334
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
335
|
+
newValue = $7F3MR$toCalendar(newValue, oldValue?.calendar || new $7F3MR$GregorianCalendar());
|
|
336
|
+
// Preserve time if the input value had one.
|
|
337
|
+
if (oldValue && 'hour' in oldValue) return oldValue.set(newValue);
|
|
338
|
+
return newValue;
|
|
397
339
|
}
|
|
398
340
|
|
|
399
|
-
function $b99e30b96646887f54a48af37fe3b03$var$convertValue(newValue, oldValue) {
|
|
400
|
-
// The display calendar should not have any effect on the emitted value.
|
|
401
|
-
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
402
|
-
newValue = toCalendar(newValue, (oldValue == null ? void 0 : oldValue.calendar) || new GregorianCalendar()); // Preserve time if the input value had one.
|
|
403
341
|
|
|
404
|
-
if (oldValue && 'hour' in oldValue) {
|
|
405
|
-
return oldValue.set(newValue);
|
|
406
|
-
}
|
|
407
342
|
|
|
408
|
-
|
|
409
|
-
}
|
|
343
|
+
|
|
344
|
+
export {$071794a38ae0e339$export$6d095e787d2b5e1f as useCalendarState, $b4f14c36da84ed2c$export$9a987164d97ecc90 as useRangeCalendarState};
|
|
410
345
|
//# sourceMappingURL=module.js.map
|