@react-stately/calendar 3.0.0-alpha.1 → 3.0.0-alpha.4

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