@react-stately/calendar 3.0.0-nightly.2840 → 3.0.0-nightly.2846

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/import.mjs CHANGED
@@ -1,28 +1,7 @@
1
- import {DateFormatter as $keQhS$DateFormatter, toCalendar as $keQhS$toCalendar, toCalendarDate as $keQhS$toCalendarDate, today as $keQhS$today, GregorianCalendar as $keQhS$GregorianCalendar, startOfWeek as $keQhS$startOfWeek, startOfMonth as $keQhS$startOfMonth, endOfWeek as $keQhS$endOfWeek, endOfMonth as $keQhS$endOfMonth, isSameDay as $keQhS$isSameDay, getDayOfWeek as $keQhS$getDayOfWeek, startOfYear as $keQhS$startOfYear, maxDate as $keQhS$maxDate, minDate as $keQhS$minDate, isEqualDay as $keQhS$isEqualDay} from "@internationalized/date";
2
- import {useControlledState as $keQhS$useControlledState} from "@react-stately/utils";
3
- import {useMemo as $keQhS$useMemo, useState as $keQhS$useState, useRef as $keQhS$useRef} from "react";
1
+ import {useCalendarState as $131cf43a05231e1e$export$6d095e787d2b5e1f} from "./useCalendarState.mjs";
2
+ import {useRangeCalendarState as $9a36b6ba2fb1a7c5$export$9a987164d97ecc90} from "./useRangeCalendarState.mjs";
4
3
 
5
4
  /*
6
- * Copyright 2020 Adobe. All rights reserved.
7
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License. You may obtain a copy
9
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software distributed under
12
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
- * OF ANY KIND, either express or implied. See the License for the specific language
14
- * governing permissions and limitations under the License.
15
- */ /*
16
- * Copyright 2020 Adobe. All rights reserved.
17
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18
- * you may not use this file except in compliance with the License. You may obtain a copy
19
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
20
- *
21
- * Unless required by applicable law or agreed to in writing, software distributed under
22
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
23
- * OF ANY KIND, either express or implied. See the License for the specific language
24
- * governing permissions and limitations under the License.
25
- */ /*
26
5
  * Copyright 2020 Adobe. All rights reserved.
27
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
28
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -33,499 +12,6 @@ import {useMemo as $keQhS$useMemo, useState as $keQhS$useState, useRef as $keQhS
33
12
  * OF ANY KIND, either express or implied. See the License for the specific language
34
13
  * governing permissions and limitations under the License.
35
14
  */
36
- function $f62d864046160412$export$eac50920cf2fd59a(date, minValue, maxValue) {
37
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
38
- }
39
- function $f62d864046160412$export$f4a51ff076cc9a09(date, duration, locale, minValue, maxValue) {
40
- let halfDuration = {};
41
- for(let key in duration){
42
- halfDuration[key] = Math.floor(duration[key] / 2);
43
- if (halfDuration[key] > 0 && duration[key] % 2 === 0) halfDuration[key]--;
44
- }
45
- let aligned = $f62d864046160412$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration);
46
- return $f62d864046160412$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
47
- }
48
- function $f62d864046160412$export$144a00ba6044eb9(date, duration, locale, minValue, maxValue) {
49
- // align to the start of the largest unit
50
- let aligned = date;
51
- if (duration.years) aligned = (0, $keQhS$startOfYear)(date);
52
- else if (duration.months) aligned = (0, $keQhS$startOfMonth)(date);
53
- else if (duration.weeks) aligned = (0, $keQhS$startOfWeek)(date, locale);
54
- return $f62d864046160412$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
55
- }
56
- function $f62d864046160412$export$530edbfc915b2b04(date, duration, locale, minValue, maxValue) {
57
- let d = {
58
- ...duration
59
- };
60
- // subtract 1 from the smallest unit
61
- if (duration.days) d.days--;
62
- else if (duration.weeks) d.weeks--;
63
- else if (duration.months) d.months--;
64
- else if (duration.years) d.years--;
65
- let aligned = $f62d864046160412$export$144a00ba6044eb9(date, duration, locale).subtract(d);
66
- return $f62d864046160412$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue);
67
- }
68
- function $f62d864046160412$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) {
69
- if (minValue && date.compare(minValue) >= 0) aligned = (0, $keQhS$maxDate)(aligned, $f62d864046160412$export$144a00ba6044eb9((0, $keQhS$toCalendarDate)(minValue), duration, locale));
70
- if (maxValue && date.compare(maxValue) <= 0) aligned = (0, $keQhS$minDate)(aligned, $f62d864046160412$export$530edbfc915b2b04((0, $keQhS$toCalendarDate)(maxValue), duration, locale));
71
- return aligned;
72
- }
73
- function $f62d864046160412$export$4f5203c0d889109e(date, minValue, maxValue) {
74
- if (minValue) date = (0, $keQhS$maxDate)(date, (0, $keQhS$toCalendarDate)(minValue));
75
- if (maxValue) date = (0, $keQhS$minDate)(date, (0, $keQhS$toCalendarDate)(maxValue));
76
- return date;
77
- }
78
- function $f62d864046160412$export$a1d3911297b952d7(date, minValue, isDateUnavailable) {
79
- if (!isDateUnavailable) return date;
80
- while(date.compare(minValue) >= 0 && isDateUnavailable(date))date = date.subtract({
81
- days: 1
82
- });
83
- if (date.compare(minValue) >= 0) return date;
84
- }
85
-
86
-
87
-
88
-
89
-
90
- function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
91
- let defaultFormatter = (0, $keQhS$useMemo)(()=>new (0, $keQhS$DateFormatter)(props.locale), [
92
- props.locale
93
- ]);
94
- let resolvedOptions = (0, $keQhS$useMemo)(()=>defaultFormatter.resolvedOptions(), [
95
- defaultFormatter
96
- ]);
97
- let { locale: locale, createCalendar: createCalendar, visibleDuration: visibleDuration = {
98
- months: 1
99
- }, minValue: minValue, maxValue: maxValue, selectionAlignment: selectionAlignment, isDateUnavailable: isDateUnavailable, pageBehavior: pageBehavior = "visible" } = props;
100
- let calendar = (0, $keQhS$useMemo)(()=>createCalendar(resolvedOptions.calendar), [
101
- createCalendar,
102
- resolvedOptions.calendar
103
- ]);
104
- let [value, setControlledValue] = (0, $keQhS$useControlledState)(props.value, props.defaultValue, props.onChange);
105
- let calendarDateValue = (0, $keQhS$useMemo)(()=>value ? (0, $keQhS$toCalendar)((0, $keQhS$toCalendarDate)(value), calendar) : null, [
106
- value,
107
- calendar
108
- ]);
109
- let timeZone = (0, $keQhS$useMemo)(()=>value && "timeZone" in value ? value.timeZone : resolvedOptions.timeZone, [
110
- value,
111
- resolvedOptions.timeZone
112
- ]);
113
- let focusedCalendarDate = (0, $keQhS$useMemo)(()=>props.focusedValue ? (0, $f62d864046160412$export$4f5203c0d889109e)((0, $keQhS$toCalendar)((0, $keQhS$toCalendarDate)(props.focusedValue), calendar), minValue, maxValue) : undefined, [
114
- props.focusedValue,
115
- calendar,
116
- minValue,
117
- maxValue
118
- ]);
119
- let defaultFocusedCalendarDate = (0, $keQhS$useMemo)(()=>(0, $f62d864046160412$export$4f5203c0d889109e)(props.defaultFocusedValue ? (0, $keQhS$toCalendar)((0, $keQhS$toCalendarDate)(props.defaultFocusedValue), calendar) : calendarDateValue || (0, $keQhS$toCalendar)((0, $keQhS$today)(timeZone), calendar), minValue, maxValue), [
120
- props.defaultFocusedValue,
121
- calendarDateValue,
122
- timeZone,
123
- calendar,
124
- minValue,
125
- maxValue
126
- ]);
127
- let [focusedDate, setFocusedDate] = (0, $keQhS$useControlledState)(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);
128
- let [startDate, setStartDate] = (0, $keQhS$useState)(()=>{
129
- switch(selectionAlignment){
130
- case "start":
131
- return (0, $f62d864046160412$export$144a00ba6044eb9)(focusedDate, visibleDuration, locale, minValue, maxValue);
132
- case "end":
133
- return (0, $f62d864046160412$export$530edbfc915b2b04)(focusedDate, visibleDuration, locale, minValue, maxValue);
134
- case "center":
135
- default:
136
- return (0, $f62d864046160412$export$f4a51ff076cc9a09)(focusedDate, visibleDuration, locale, minValue, maxValue);
137
- }
138
- });
139
- let [isFocused, setFocused] = (0, $keQhS$useState)(props.autoFocus || false);
140
- let endDate = (0, $keQhS$useMemo)(()=>{
141
- let duration = {
142
- ...visibleDuration
143
- };
144
- if (duration.days) duration.days--;
145
- else duration.days = -1;
146
- return startDate.add(duration);
147
- }, [
148
- startDate,
149
- visibleDuration
150
- ]);
151
- // Reset focused date and visible range when calendar changes.
152
- let [lastCalendarIdentifier, setLastCalendarIdentifier] = (0, $keQhS$useState)(calendar.identifier);
153
- if (calendar.identifier !== lastCalendarIdentifier) {
154
- let newFocusedDate = (0, $keQhS$toCalendar)(focusedDate, calendar);
155
- setStartDate((0, $f62d864046160412$export$f4a51ff076cc9a09)(newFocusedDate, visibleDuration, locale, minValue, maxValue));
156
- setFocusedDate(newFocusedDate);
157
- setLastCalendarIdentifier(calendar.identifier);
158
- }
159
- if ((0, $f62d864046160412$export$eac50920cf2fd59a)(focusedDate, minValue, maxValue)) // If the focused date was moved to an invalid value, it can't be focused, so constrain it.
160
- setFocusedDate((0, $f62d864046160412$export$4f5203c0d889109e)(focusedDate, minValue, maxValue));
161
- else if (focusedDate.compare(startDate) < 0) setStartDate((0, $f62d864046160412$export$530edbfc915b2b04)(focusedDate, visibleDuration, locale, minValue, maxValue));
162
- else if (focusedDate.compare(endDate) > 0) setStartDate((0, $f62d864046160412$export$144a00ba6044eb9)(focusedDate, visibleDuration, locale, minValue, maxValue));
163
- // Sets focus to a specific cell date
164
- function focusCell(date) {
165
- date = (0, $f62d864046160412$export$4f5203c0d889109e)(date, minValue, maxValue);
166
- setFocusedDate(date);
167
- }
168
- function setValue(newValue) {
169
- if (!props.isDisabled && !props.isReadOnly) {
170
- if (newValue === null) {
171
- setControlledValue(null);
172
- return;
173
- }
174
- newValue = (0, $f62d864046160412$export$4f5203c0d889109e)(newValue, minValue, maxValue);
175
- newValue = (0, $f62d864046160412$export$a1d3911297b952d7)(newValue, startDate, isDateUnavailable);
176
- if (!newValue) return;
177
- // The display calendar should not have any effect on the emitted value.
178
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
179
- newValue = (0, $keQhS$toCalendar)(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $keQhS$GregorianCalendar)());
180
- // Preserve time if the input value had one.
181
- if (value && "hour" in value) setControlledValue(value.set(newValue));
182
- else setControlledValue(newValue);
183
- }
184
- }
185
- let isUnavailable = (0, $keQhS$useMemo)(()=>{
186
- if (!calendarDateValue) return false;
187
- if (isDateUnavailable && isDateUnavailable(calendarDateValue)) return true;
188
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(calendarDateValue, minValue, maxValue);
189
- }, [
190
- calendarDateValue,
191
- isDateUnavailable,
192
- minValue,
193
- maxValue
194
- ]);
195
- let isValueInvalid = props.isInvalid || props.validationState === "invalid" || isUnavailable;
196
- let validationState = isValueInvalid ? "invalid" : null;
197
- let pageDuration = (0, $keQhS$useMemo)(()=>{
198
- if (pageBehavior === "visible") return visibleDuration;
199
- return $131cf43a05231e1e$var$unitDuration(visibleDuration);
200
- }, [
201
- pageBehavior,
202
- visibleDuration
203
- ]);
204
- return {
205
- isDisabled: props.isDisabled,
206
- isReadOnly: props.isReadOnly,
207
- value: calendarDateValue,
208
- setValue: setValue,
209
- visibleRange: {
210
- start: startDate,
211
- end: endDate
212
- },
213
- minValue: minValue,
214
- maxValue: maxValue,
215
- focusedDate: focusedDate,
216
- timeZone: timeZone,
217
- validationState: validationState,
218
- isValueInvalid: isValueInvalid,
219
- setFocusedDate (date) {
220
- focusCell(date);
221
- setFocused(true);
222
- },
223
- focusNextDay () {
224
- focusCell(focusedDate.add({
225
- days: 1
226
- }));
227
- },
228
- focusPreviousDay () {
229
- focusCell(focusedDate.subtract({
230
- days: 1
231
- }));
232
- },
233
- focusNextRow () {
234
- if (visibleDuration.days) this.focusNextPage();
235
- else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
236
- weeks: 1
237
- }));
238
- },
239
- focusPreviousRow () {
240
- if (visibleDuration.days) this.focusPreviousPage();
241
- else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
242
- weeks: 1
243
- }));
244
- },
245
- focusNextPage () {
246
- let start = startDate.add(pageDuration);
247
- setFocusedDate((0, $f62d864046160412$export$4f5203c0d889109e)(focusedDate.add(pageDuration), minValue, maxValue));
248
- setStartDate((0, $f62d864046160412$export$144a00ba6044eb9)((0, $f62d864046160412$export$5bb865b12696a77d)(focusedDate, start, pageDuration, locale, minValue, maxValue), pageDuration, locale));
249
- },
250
- focusPreviousPage () {
251
- let start = startDate.subtract(pageDuration);
252
- setFocusedDate((0, $f62d864046160412$export$4f5203c0d889109e)(focusedDate.subtract(pageDuration), minValue, maxValue));
253
- setStartDate((0, $f62d864046160412$export$144a00ba6044eb9)((0, $f62d864046160412$export$5bb865b12696a77d)(focusedDate, start, pageDuration, locale, minValue, maxValue), pageDuration, locale));
254
- },
255
- focusSectionStart () {
256
- if (visibleDuration.days) focusCell(startDate);
257
- else if (visibleDuration.weeks) focusCell((0, $keQhS$startOfWeek)(focusedDate, locale));
258
- else if (visibleDuration.months || visibleDuration.years) focusCell((0, $keQhS$startOfMonth)(focusedDate));
259
- },
260
- focusSectionEnd () {
261
- if (visibleDuration.days) focusCell(endDate);
262
- else if (visibleDuration.weeks) focusCell((0, $keQhS$endOfWeek)(focusedDate, locale));
263
- else if (visibleDuration.months || visibleDuration.years) focusCell((0, $keQhS$endOfMonth)(focusedDate));
264
- },
265
- focusNextSection (larger) {
266
- if (!larger && !visibleDuration.days) {
267
- focusCell(focusedDate.add($131cf43a05231e1e$var$unitDuration(visibleDuration)));
268
- return;
269
- }
270
- if (visibleDuration.days) this.focusNextPage();
271
- else if (visibleDuration.weeks) focusCell(focusedDate.add({
272
- months: 1
273
- }));
274
- else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
275
- years: 1
276
- }));
277
- },
278
- focusPreviousSection (larger) {
279
- if (!larger && !visibleDuration.days) {
280
- focusCell(focusedDate.subtract($131cf43a05231e1e$var$unitDuration(visibleDuration)));
281
- return;
282
- }
283
- if (visibleDuration.days) this.focusPreviousPage();
284
- else if (visibleDuration.weeks) focusCell(focusedDate.subtract({
285
- months: 1
286
- }));
287
- else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
288
- years: 1
289
- }));
290
- },
291
- selectFocusedDate () {
292
- setValue(focusedDate);
293
- },
294
- selectDate (date) {
295
- setValue(date);
296
- },
297
- isFocused: isFocused,
298
- setFocused: setFocused,
299
- isInvalid (date) {
300
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(date, minValue, maxValue);
301
- },
302
- isSelected (date) {
303
- return calendarDateValue != null && (0, $keQhS$isSameDay)(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);
304
- },
305
- isCellFocused (date) {
306
- return isFocused && focusedDate && (0, $keQhS$isSameDay)(date, focusedDate);
307
- },
308
- isCellDisabled (date) {
309
- return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);
310
- },
311
- isCellUnavailable (date) {
312
- return props.isDateUnavailable && props.isDateUnavailable(date);
313
- },
314
- isPreviousVisibleRangeInvalid () {
315
- let prev = startDate.subtract({
316
- days: 1
317
- });
318
- return (0, $keQhS$isSameDay)(prev, startDate) || this.isInvalid(prev, minValue, maxValue);
319
- },
320
- isNextVisibleRangeInvalid () {
321
- // Adding may return the same date if we reached the end of time
322
- // according to the calendar system (e.g. 9999-12-31).
323
- let next = endDate.add({
324
- days: 1
325
- });
326
- return (0, $keQhS$isSameDay)(next, endDate) || this.isInvalid(next, minValue, maxValue);
327
- },
328
- getDatesInWeek (weekIndex, from = startDate) {
329
- // let date = startOfWeek(from, locale);
330
- let date = from.add({
331
- weeks: weekIndex
332
- });
333
- let dates = [];
334
- date = (0, $keQhS$startOfWeek)(date, locale);
335
- // startOfWeek will clamp dates within the calendar system's valid range, which may
336
- // start in the middle of a week. In this case, add null placeholders.
337
- let dayOfWeek = (0, $keQhS$getDayOfWeek)(date, locale);
338
- for(let i = 0; i < dayOfWeek; i++)dates.push(null);
339
- while(dates.length < 7){
340
- dates.push(date);
341
- let nextDate = date.add({
342
- days: 1
343
- });
344
- if ((0, $keQhS$isSameDay)(date, nextDate)) break;
345
- date = nextDate;
346
- }
347
- // Add null placeholders if at the end of the calendar system.
348
- while(dates.length < 7)dates.push(null);
349
- return dates;
350
- }
351
- };
352
- }
353
- function $131cf43a05231e1e$var$unitDuration(duration) {
354
- let unit = {
355
- ...duration
356
- };
357
- for(let key in duration)unit[key] = 1;
358
- return unit;
359
- }
360
-
361
-
362
- /*
363
- * Copyright 2020 Adobe. All rights reserved.
364
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
365
- * you may not use this file except in compliance with the License. You may obtain a copy
366
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
367
- *
368
- * Unless required by applicable law or agreed to in writing, software distributed under
369
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
370
- * OF ANY KIND, either express or implied. See the License for the specific language
371
- * governing permissions and limitations under the License.
372
- */
373
-
374
-
375
-
376
-
377
- function $9a36b6ba2fb1a7c5$export$9a987164d97ecc90(props) {
378
- let { value: valueProp, defaultValue: defaultValue, onChange: onChange, createCalendar: createCalendar, locale: locale, visibleDuration: visibleDuration = {
379
- months: 1
380
- }, minValue: minValue, maxValue: maxValue, ...calendarProps } = props;
381
- let [value, setValue] = (0, $keQhS$useControlledState)(valueProp, defaultValue || null, onChange);
382
- let [anchorDate, setAnchorDateState] = (0, $keQhS$useState)(null);
383
- let alignment = "center";
384
- if (value && value.start && value.end) {
385
- let start = (0, $f62d864046160412$export$f4a51ff076cc9a09)((0, $keQhS$toCalendarDate)(value.start), visibleDuration, locale, minValue, maxValue);
386
- let end = start.add(visibleDuration).subtract({
387
- days: 1
388
- });
389
- if (value.end.compare(end) > 0) alignment = "start";
390
- }
391
- // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.
392
- let availableRangeRef = (0, $keQhS$useRef)(null);
393
- let [availableRange, setAvailableRange] = (0, $keQhS$useState)(null);
394
- let min = (0, $keQhS$useMemo)(()=>(0, $keQhS$maxDate)(minValue, availableRange === null || availableRange === void 0 ? void 0 : availableRange.start), [
395
- minValue,
396
- availableRange
397
- ]);
398
- let max = (0, $keQhS$useMemo)(()=>(0, $keQhS$minDate)(maxValue, availableRange === null || availableRange === void 0 ? void 0 : availableRange.end), [
399
- maxValue,
400
- availableRange
401
- ]);
402
- let calendar = (0, $131cf43a05231e1e$export$6d095e787d2b5e1f)({
403
- ...calendarProps,
404
- value: value && value.start,
405
- createCalendar: createCalendar,
406
- locale: locale,
407
- visibleDuration: visibleDuration,
408
- minValue: min,
409
- maxValue: max,
410
- selectionAlignment: alignment
411
- });
412
- let updateAvailableRange = (date)=>{
413
- if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
414
- availableRangeRef.current = {
415
- start: $9a36b6ba2fb1a7c5$var$nextUnavailableDate(date, calendar, -1),
416
- end: $9a36b6ba2fb1a7c5$var$nextUnavailableDate(date, calendar, 1)
417
- };
418
- setAvailableRange(availableRangeRef.current);
419
- } else {
420
- availableRangeRef.current = null;
421
- setAvailableRange(null);
422
- }
423
- };
424
- // If the visible range changes, we need to update the available range.
425
- let [lastVisibleRange, setLastVisibleRange] = (0, $keQhS$useState)(calendar.visibleRange);
426
- if (!(0, $keQhS$isEqualDay)(calendar.visibleRange.start, lastVisibleRange.start) || !(0, $keQhS$isEqualDay)(calendar.visibleRange.end, lastVisibleRange.end)) {
427
- updateAvailableRange(anchorDate);
428
- setLastVisibleRange(calendar.visibleRange);
429
- }
430
- let setAnchorDate = (date)=>{
431
- if (date) {
432
- setAnchorDateState(date);
433
- updateAvailableRange(date);
434
- } else {
435
- setAnchorDateState(null);
436
- updateAvailableRange(null);
437
- }
438
- };
439
- let highlightedRange = anchorDate ? $9a36b6ba2fb1a7c5$var$makeRange(anchorDate, calendar.focusedDate) : value && $9a36b6ba2fb1a7c5$var$makeRange(value.start, value.end);
440
- let selectDate = (date)=>{
441
- if (props.isReadOnly) return;
442
- date = (0, $f62d864046160412$export$4f5203c0d889109e)(date, min, max);
443
- date = (0, $f62d864046160412$export$a1d3911297b952d7)(date, calendar.visibleRange.start, props.isDateUnavailable);
444
- if (!date) return;
445
- if (!anchorDate) setAnchorDate(date);
446
- else {
447
- let range = $9a36b6ba2fb1a7c5$var$makeRange(anchorDate, date);
448
- setValue({
449
- start: $9a36b6ba2fb1a7c5$var$convertValue(range.start, value === null || value === void 0 ? void 0 : value.start),
450
- end: $9a36b6ba2fb1a7c5$var$convertValue(range.end, value === null || value === void 0 ? void 0 : value.end)
451
- });
452
- setAnchorDate(null);
453
- }
454
- };
455
- let [isDragging, setDragging] = (0, $keQhS$useState)(false);
456
- let { isDateUnavailable: isDateUnavailable } = props;
457
- let isInvalidSelection = (0, $keQhS$useMemo)(()=>{
458
- if (!value || anchorDate) return false;
459
- if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) return true;
460
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(value.start, minValue, maxValue) || (0, $f62d864046160412$export$eac50920cf2fd59a)(value.end, minValue, maxValue);
461
- }, [
462
- isDateUnavailable,
463
- value,
464
- anchorDate,
465
- minValue,
466
- maxValue
467
- ]);
468
- let isValueInvalid = props.isInvalid || props.validationState === "invalid" || isInvalidSelection;
469
- let validationState = isValueInvalid ? "invalid" : null;
470
- return {
471
- ...calendar,
472
- value: value,
473
- setValue: setValue,
474
- anchorDate: anchorDate,
475
- setAnchorDate: setAnchorDate,
476
- highlightedRange: highlightedRange,
477
- validationState: validationState,
478
- isValueInvalid: isValueInvalid,
479
- selectFocusedDate () {
480
- selectDate(calendar.focusedDate);
481
- },
482
- selectDate: selectDate,
483
- highlightDate (date) {
484
- if (anchorDate) calendar.setFocusedDate(date);
485
- },
486
- isSelected (date) {
487
- return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date);
488
- },
489
- isInvalid (date) {
490
- var _availableRangeRef_current, _availableRangeRef_current1;
491
- return calendar.isInvalid(date) || (0, $f62d864046160412$export$eac50920cf2fd59a)(date, (_availableRangeRef_current = availableRangeRef.current) === null || _availableRangeRef_current === void 0 ? void 0 : _availableRangeRef_current.start, (_availableRangeRef_current1 = availableRangeRef.current) === null || _availableRangeRef_current1 === void 0 ? void 0 : _availableRangeRef_current1.end);
492
- },
493
- isDragging: isDragging,
494
- setDragging: setDragging
495
- };
496
- }
497
- function $9a36b6ba2fb1a7c5$var$makeRange(start, end) {
498
- if (!start || !end) return null;
499
- if (end.compare(start) < 0) [start, end] = [
500
- end,
501
- start
502
- ];
503
- return {
504
- start: (0, $keQhS$toCalendarDate)(start),
505
- end: (0, $keQhS$toCalendarDate)(end)
506
- };
507
- }
508
- function $9a36b6ba2fb1a7c5$var$convertValue(newValue, oldValue) {
509
- // The display calendar should not have any effect on the emitted value.
510
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
511
- newValue = (0, $keQhS$toCalendar)(newValue, (oldValue === null || oldValue === void 0 ? void 0 : oldValue.calendar) || new (0, $keQhS$GregorianCalendar)());
512
- // Preserve time if the input value had one.
513
- if (oldValue && "hour" in oldValue) return oldValue.set(newValue);
514
- return newValue;
515
- }
516
- function $9a36b6ba2fb1a7c5$var$nextUnavailableDate(anchorDate, state, dir) {
517
- let nextDate = anchorDate.add({
518
- days: dir
519
- });
520
- while((dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) && !state.isCellUnavailable(nextDate))nextDate = nextDate.add({
521
- days: dir
522
- });
523
- if (state.isCellUnavailable(nextDate)) return nextDate.add({
524
- days: -dir
525
- });
526
- return null;
527
- }
528
-
529
15
 
530
16
 
531
17