@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/module.js CHANGED
@@ -1,410 +1,345 @@
1
- import _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
- import { useEffect, useMemo, useRef, useState } from "react";
3
- import { useDateFormatter } from "@react-aria/i18n";
4
- import { useControlledState } from "@react-stately/utils";
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 $e9245e22e7d2e30e959129f8619bae$export$isInvalid(date, minValue, maxValue) {
9
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
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
- for (let key in duration) {
16
- halfDuration[key] = Math.floor(duration[key] / 2);
12
+ var $071794a38ae0e339$exports = {};
17
13
 
18
- if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
19
- halfDuration[key]--;
20
- }
21
- }
14
+ $parcel$export($071794a38ae0e339$exports, "useCalendarState", () => $071794a38ae0e339$export$6d095e787d2b5e1f);
22
15
 
23
- let aligned = $e9245e22e7d2e30e959129f8619bae$export$alignStart(date, duration, locale).subtract(halfDuration);
24
- return $e9245e22e7d2e30e959129f8619bae$export$constrainStart(date, aligned, duration, locale, minValue, maxValue);
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
- function $e9245e22e7d2e30e959129f8619bae$export$alignStart(date, duration, locale, minValue, maxValue) {
28
- // align to the start of the largest unit
29
- let aligned = date;
30
-
31
- if (duration.years) {
32
- aligned = startOfYear(date);
33
- } else if (duration.months) {
34
- aligned = startOfMonth(date);
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
- function $e9245e22e7d2e30e959129f8619bae$export$alignEnd(date, duration, locale, minValue, maxValue) {
43
- let d = _babelRuntimeHelpersEsmExtends({}, duration); // subtract 1 from the smallest unit
44
-
45
-
46
- if (duration.days) {
47
- d.days--;
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
- function $e9245e22e7d2e30e959129f8619bae$export$constrainStart(date, aligned, duration, locale, minValue, maxValue) {
61
- if (minValue && date.compare(minValue) >= 0) {
62
- aligned = maxDate(aligned, $e9245e22e7d2e30e959129f8619bae$export$alignStart(toCalendarDate(minValue), duration, locale));
63
- }
64
-
65
- if (maxValue && date.compare(maxValue) <= 0) {
66
- aligned = minDate(aligned, $e9245e22e7d2e30e959129f8619bae$export$alignEnd(toCalendarDate(maxValue), duration, locale));
67
- }
68
-
69
- return aligned;
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
- function $e9245e22e7d2e30e959129f8619bae$export$constrainValue(date, minValue, maxValue) {
73
- if (minValue) {
74
- date = maxDate(date, toCalendarDate(minValue));
75
- }
76
-
77
- if (maxValue) {
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
- if (date.compare(startDate) < 0) {
137
- setStartDate($e9245e22e7d2e30e959129f8619bae$export$alignEnd(date, visibleDuration, locale, minValue, maxValue));
138
- } else if (date.compare(next) >= 0) {
139
- setStartDate($e9245e22e7d2e30e959129f8619bae$export$alignStart(date, visibleDuration, locale, minValue, maxValue));
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
- setFocusedDate(date);
143
- }
144
-
145
- function setValue(newValue) {
146
- if (!props.isDisabled && !props.isReadOnly) {
147
- // The display calendar should not have any effect on the emitted value.
148
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
149
- newValue = toCalendar(newValue, (value == null ? void 0 : value.calendar) || new GregorianCalendar()); // Preserve time if the input value had one.
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
- return {
160
- isDisabled: props.isDisabled,
161
- isReadOnly: props.isReadOnly,
162
- value: calendarDateValue,
163
- setValue,
164
- visibleRange: {
165
- start: startDate,
166
- end: endDate
167
- },
168
- focusedDate,
169
- timeZone,
170
-
171
- setFocusedDate(date) {
172
- setFocusedDate(date);
173
- setFocused(true);
174
- },
175
-
176
- focusNextDay() {
177
- focusCell(focusedDate.add({
178
- days: 1
179
- }));
180
- },
181
-
182
- focusPreviousDay() {
183
- focusCell(focusedDate.subtract({
184
- days: 1
185
- }));
186
- },
187
-
188
- focusNextRow() {
189
- if (visibleDuration.days) {
190
- this.focusNextPage();
191
- } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
192
- focusCell(focusedDate.add({
193
- weeks: 1
194
- }));
195
- }
196
- },
197
-
198
- focusPreviousRow() {
199
- if (visibleDuration.days) {
200
- this.focusPreviousPage();
201
- } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
202
- focusCell(focusedDate.subtract({
203
- weeks: 1
204
- }));
205
- }
206
- },
207
-
208
- focusNextPage() {
209
- let start = startDate.add(visibleDuration);
210
- setStartDate($e9245e22e7d2e30e959129f8619bae$export$constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue));
211
- setFocusedDate($e9245e22e7d2e30e959129f8619bae$export$constrainValue(focusedDate.add(visibleDuration), minValue, maxValue));
212
- },
213
-
214
- focusPreviousPage() {
215
- let start = startDate.subtract(visibleDuration);
216
- setStartDate($e9245e22e7d2e30e959129f8619bae$export$constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue));
217
- setFocusedDate($e9245e22e7d2e30e959129f8619bae$export$constrainValue(focusedDate.subtract(visibleDuration), minValue, maxValue));
218
- },
219
-
220
- focusPageStart() {
221
- focusCell(startDate);
222
- },
223
-
224
- focusPageEnd() {
225
- focusCell(endDate);
226
- },
227
-
228
- focusNextSection() {
229
- if (visibleDuration.days) {
230
- this.focusNextPage();
231
- } else if (visibleDuration.weeks) {
232
- focusCell(focusedDate.add({
233
- months: 1
234
- }));
235
- } else if (visibleDuration.months || visibleDuration.years) {
236
- focusCell(focusedDate.add({
237
- years: 1
238
- }));
239
- }
240
- },
241
-
242
- focusPreviousSection() {
243
- if (visibleDuration.days) {
244
- this.focusPreviousPage();
245
- } else if (visibleDuration.weeks) {
246
- focusCell(focusedDate.subtract({
247
- months: 1
248
- }));
249
- } else if (visibleDuration.months || visibleDuration.years) {
250
- focusCell(focusedDate.subtract({
251
- years: 1
252
- }));
253
- }
254
- },
255
-
256
- selectFocusedDate() {
257
- setValue(focusedDate);
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
- isFocused,
265
- setFocused,
254
+ var $b4f14c36da84ed2c$exports = {};
266
255
 
267
- isInvalid(date) {
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
- isNextVisibleRangeInvalid() {
290
- return $e9245e22e7d2e30e959129f8619bae$export$isInvalid(endDate.add({
291
- days: 1
292
- }), minValue, maxValue);
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
- export function useRangeCalendarState(props) {
298
- let {
299
- value: valueProp,
300
- defaultValue,
301
- onChange,
302
- createCalendar,
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
- if (value.end.compare(end) > 0) {
323
- alignment = 'start';
324
- }
325
- }
326
-
327
- let calendar = useCalendarState(_babelRuntimeHelpersEsmExtends({}, calendarProps, {
328
- value: value && value.start,
329
- createCalendar,
330
- locale,
331
- visibleDuration,
332
- minValue,
333
- maxValue,
334
- selectionAlignment: alignment
335
- }));
336
- let highlightedRange = anchorDate ? $b99e30b96646887f54a48af37fe3b03$var$makeRange(anchorDate, calendar.focusedDate) : value && $b99e30b96646887f54a48af37fe3b03$var$makeRange(value.start, value.end);
337
-
338
- let selectDate = date => {
339
- if (props.isReadOnly) {
340
- return;
341
- }
342
-
343
- if (!anchorDate) {
344
- setAnchorDate(date);
345
- } else {
346
- let range = $b99e30b96646887f54a48af37fe3b03$var$makeRange(anchorDate, date);
347
- setValue({
348
- start: $b99e30b96646887f54a48af37fe3b03$var$convertValue(range.start, value == null ? void 0 : value.start),
349
- end: $b99e30b96646887f54a48af37fe3b03$var$convertValue(range.end, value == null ? void 0 : value.end)
350
- });
351
- setAnchorDate(null);
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
- function $b99e30b96646887f54a48af37fe3b03$var$makeRange(start, end) {
385
- if (!start || !end) {
386
- return null;
387
- }
388
-
389
- if (end.compare(start) < 0) {
390
- [start, end] = [end, start];
391
- }
392
-
393
- return {
394
- start: toCalendarDate(start),
395
- end: toCalendarDate(end)
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
- return newValue;
409
- }
343
+
344
+ export {$071794a38ae0e339$export$6d095e787d2b5e1f as useCalendarState, $b4f14c36da84ed2c$export$9a987164d97ecc90 as useRangeCalendarState};
410
345
  //# sourceMappingURL=module.js.map