@react-stately/calendar 3.4.3 → 3.5.0

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,495 +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
- newValue = (0, $f62d864046160412$export$4f5203c0d889109e)(newValue, minValue, maxValue);
171
- newValue = (0, $f62d864046160412$export$a1d3911297b952d7)(newValue, startDate, isDateUnavailable);
172
- if (!newValue) return;
173
- // The display calendar should not have any effect on the emitted value.
174
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
175
- newValue = (0, $keQhS$toCalendar)(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $keQhS$GregorianCalendar)());
176
- // Preserve time if the input value had one.
177
- if (value && "hour" in value) setControlledValue(value.set(newValue));
178
- else setControlledValue(newValue);
179
- }
180
- }
181
- let isUnavailable = (0, $keQhS$useMemo)(()=>{
182
- if (!calendarDateValue) return false;
183
- if (isDateUnavailable && isDateUnavailable(calendarDateValue)) return true;
184
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(calendarDateValue, minValue, maxValue);
185
- }, [
186
- calendarDateValue,
187
- isDateUnavailable,
188
- minValue,
189
- maxValue
190
- ]);
191
- let isValueInvalid = props.isInvalid || props.validationState === "invalid" || isUnavailable;
192
- let validationState = isValueInvalid ? "invalid" : null;
193
- let pageDuration = (0, $keQhS$useMemo)(()=>{
194
- if (pageBehavior === "visible") return visibleDuration;
195
- return $131cf43a05231e1e$var$unitDuration(visibleDuration);
196
- }, [
197
- pageBehavior,
198
- visibleDuration
199
- ]);
200
- return {
201
- isDisabled: props.isDisabled,
202
- isReadOnly: props.isReadOnly,
203
- value: calendarDateValue,
204
- setValue: setValue,
205
- visibleRange: {
206
- start: startDate,
207
- end: endDate
208
- },
209
- minValue: minValue,
210
- maxValue: maxValue,
211
- focusedDate: focusedDate,
212
- timeZone: timeZone,
213
- validationState: validationState,
214
- isValueInvalid: isValueInvalid,
215
- setFocusedDate (date) {
216
- focusCell(date);
217
- setFocused(true);
218
- },
219
- focusNextDay () {
220
- focusCell(focusedDate.add({
221
- days: 1
222
- }));
223
- },
224
- focusPreviousDay () {
225
- focusCell(focusedDate.subtract({
226
- days: 1
227
- }));
228
- },
229
- focusNextRow () {
230
- if (visibleDuration.days) this.focusNextPage();
231
- else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
232
- weeks: 1
233
- }));
234
- },
235
- focusPreviousRow () {
236
- if (visibleDuration.days) this.focusPreviousPage();
237
- else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
238
- weeks: 1
239
- }));
240
- },
241
- focusNextPage () {
242
- let start = startDate.add(pageDuration);
243
- setFocusedDate((0, $f62d864046160412$export$4f5203c0d889109e)(focusedDate.add(pageDuration), minValue, maxValue));
244
- setStartDate((0, $f62d864046160412$export$144a00ba6044eb9)((0, $f62d864046160412$export$5bb865b12696a77d)(focusedDate, start, pageDuration, locale, minValue, maxValue), pageDuration, locale));
245
- },
246
- focusPreviousPage () {
247
- let start = startDate.subtract(pageDuration);
248
- setFocusedDate((0, $f62d864046160412$export$4f5203c0d889109e)(focusedDate.subtract(pageDuration), minValue, maxValue));
249
- setStartDate((0, $f62d864046160412$export$144a00ba6044eb9)((0, $f62d864046160412$export$5bb865b12696a77d)(focusedDate, start, pageDuration, locale, minValue, maxValue), pageDuration, locale));
250
- },
251
- focusSectionStart () {
252
- if (visibleDuration.days) focusCell(startDate);
253
- else if (visibleDuration.weeks) focusCell((0, $keQhS$startOfWeek)(focusedDate, locale));
254
- else if (visibleDuration.months || visibleDuration.years) focusCell((0, $keQhS$startOfMonth)(focusedDate));
255
- },
256
- focusSectionEnd () {
257
- if (visibleDuration.days) focusCell(endDate);
258
- else if (visibleDuration.weeks) focusCell((0, $keQhS$endOfWeek)(focusedDate, locale));
259
- else if (visibleDuration.months || visibleDuration.years) focusCell((0, $keQhS$endOfMonth)(focusedDate));
260
- },
261
- focusNextSection (larger) {
262
- if (!larger && !visibleDuration.days) {
263
- focusCell(focusedDate.add($131cf43a05231e1e$var$unitDuration(visibleDuration)));
264
- return;
265
- }
266
- if (visibleDuration.days) this.focusNextPage();
267
- else if (visibleDuration.weeks) focusCell(focusedDate.add({
268
- months: 1
269
- }));
270
- else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
271
- years: 1
272
- }));
273
- },
274
- focusPreviousSection (larger) {
275
- if (!larger && !visibleDuration.days) {
276
- focusCell(focusedDate.subtract($131cf43a05231e1e$var$unitDuration(visibleDuration)));
277
- return;
278
- }
279
- if (visibleDuration.days) this.focusPreviousPage();
280
- else if (visibleDuration.weeks) focusCell(focusedDate.subtract({
281
- months: 1
282
- }));
283
- else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
284
- years: 1
285
- }));
286
- },
287
- selectFocusedDate () {
288
- setValue(focusedDate);
289
- },
290
- selectDate (date) {
291
- setValue(date);
292
- },
293
- isFocused: isFocused,
294
- setFocused: setFocused,
295
- isInvalid (date) {
296
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(date, minValue, maxValue);
297
- },
298
- isSelected (date) {
299
- return calendarDateValue != null && (0, $keQhS$isSameDay)(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);
300
- },
301
- isCellFocused (date) {
302
- return isFocused && focusedDate && (0, $keQhS$isSameDay)(date, focusedDate);
303
- },
304
- isCellDisabled (date) {
305
- return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);
306
- },
307
- isCellUnavailable (date) {
308
- return props.isDateUnavailable && props.isDateUnavailable(date);
309
- },
310
- isPreviousVisibleRangeInvalid () {
311
- let prev = startDate.subtract({
312
- days: 1
313
- });
314
- return (0, $keQhS$isSameDay)(prev, startDate) || this.isInvalid(prev, minValue, maxValue);
315
- },
316
- isNextVisibleRangeInvalid () {
317
- // Adding may return the same date if we reached the end of time
318
- // according to the calendar system (e.g. 9999-12-31).
319
- let next = endDate.add({
320
- days: 1
321
- });
322
- return (0, $keQhS$isSameDay)(next, endDate) || this.isInvalid(next, minValue, maxValue);
323
- },
324
- getDatesInWeek (weekIndex, from = startDate) {
325
- // let date = startOfWeek(from, locale);
326
- let date = from.add({
327
- weeks: weekIndex
328
- });
329
- let dates = [];
330
- date = (0, $keQhS$startOfWeek)(date, locale);
331
- // startOfWeek will clamp dates within the calendar system's valid range, which may
332
- // start in the middle of a week. In this case, add null placeholders.
333
- let dayOfWeek = (0, $keQhS$getDayOfWeek)(date, locale);
334
- for(let i = 0; i < dayOfWeek; i++)dates.push(null);
335
- while(dates.length < 7){
336
- dates.push(date);
337
- let nextDate = date.add({
338
- days: 1
339
- });
340
- if ((0, $keQhS$isSameDay)(date, nextDate)) break;
341
- date = nextDate;
342
- }
343
- // Add null placeholders if at the end of the calendar system.
344
- while(dates.length < 7)dates.push(null);
345
- return dates;
346
- }
347
- };
348
- }
349
- function $131cf43a05231e1e$var$unitDuration(duration) {
350
- let unit = {
351
- ...duration
352
- };
353
- for(let key in duration)unit[key] = 1;
354
- return unit;
355
- }
356
-
357
-
358
- /*
359
- * Copyright 2020 Adobe. All rights reserved.
360
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
361
- * you may not use this file except in compliance with the License. You may obtain a copy
362
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
363
- *
364
- * Unless required by applicable law or agreed to in writing, software distributed under
365
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
366
- * OF ANY KIND, either express or implied. See the License for the specific language
367
- * governing permissions and limitations under the License.
368
- */
369
-
370
-
371
-
372
-
373
- function $9a36b6ba2fb1a7c5$export$9a987164d97ecc90(props) {
374
- let { value: valueProp, defaultValue: defaultValue, onChange: onChange, createCalendar: createCalendar, locale: locale, visibleDuration: visibleDuration = {
375
- months: 1
376
- }, minValue: minValue, maxValue: maxValue, ...calendarProps } = props;
377
- let [value, setValue] = (0, $keQhS$useControlledState)(valueProp, defaultValue || null, onChange);
378
- let [anchorDate, setAnchorDateState] = (0, $keQhS$useState)(null);
379
- let alignment = "center";
380
- if (value && value.start && value.end) {
381
- let start = (0, $f62d864046160412$export$f4a51ff076cc9a09)((0, $keQhS$toCalendarDate)(value.start), visibleDuration, locale, minValue, maxValue);
382
- let end = start.add(visibleDuration).subtract({
383
- days: 1
384
- });
385
- if (value.end.compare(end) > 0) alignment = "start";
386
- }
387
- // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.
388
- let availableRangeRef = (0, $keQhS$useRef)(null);
389
- let [availableRange, setAvailableRange] = (0, $keQhS$useState)(null);
390
- let min = (0, $keQhS$useMemo)(()=>(0, $keQhS$maxDate)(minValue, availableRange === null || availableRange === void 0 ? void 0 : availableRange.start), [
391
- minValue,
392
- availableRange
393
- ]);
394
- let max = (0, $keQhS$useMemo)(()=>(0, $keQhS$minDate)(maxValue, availableRange === null || availableRange === void 0 ? void 0 : availableRange.end), [
395
- maxValue,
396
- availableRange
397
- ]);
398
- let calendar = (0, $131cf43a05231e1e$export$6d095e787d2b5e1f)({
399
- ...calendarProps,
400
- value: value && value.start,
401
- createCalendar: createCalendar,
402
- locale: locale,
403
- visibleDuration: visibleDuration,
404
- minValue: min,
405
- maxValue: max,
406
- selectionAlignment: alignment
407
- });
408
- let updateAvailableRange = (date)=>{
409
- if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
410
- availableRangeRef.current = {
411
- start: $9a36b6ba2fb1a7c5$var$nextUnavailableDate(date, calendar, -1),
412
- end: $9a36b6ba2fb1a7c5$var$nextUnavailableDate(date, calendar, 1)
413
- };
414
- setAvailableRange(availableRangeRef.current);
415
- } else {
416
- availableRangeRef.current = null;
417
- setAvailableRange(null);
418
- }
419
- };
420
- // If the visible range changes, we need to update the available range.
421
- let [lastVisibleRange, setLastVisibleRange] = (0, $keQhS$useState)(calendar.visibleRange);
422
- if (!(0, $keQhS$isEqualDay)(calendar.visibleRange.start, lastVisibleRange.start) || !(0, $keQhS$isEqualDay)(calendar.visibleRange.end, lastVisibleRange.end)) {
423
- updateAvailableRange(anchorDate);
424
- setLastVisibleRange(calendar.visibleRange);
425
- }
426
- let setAnchorDate = (date)=>{
427
- if (date) {
428
- setAnchorDateState(date);
429
- updateAvailableRange(date);
430
- } else {
431
- setAnchorDateState(null);
432
- updateAvailableRange(null);
433
- }
434
- };
435
- let highlightedRange = anchorDate ? $9a36b6ba2fb1a7c5$var$makeRange(anchorDate, calendar.focusedDate) : value && $9a36b6ba2fb1a7c5$var$makeRange(value.start, value.end);
436
- let selectDate = (date)=>{
437
- if (props.isReadOnly) return;
438
- date = (0, $f62d864046160412$export$4f5203c0d889109e)(date, min, max);
439
- date = (0, $f62d864046160412$export$a1d3911297b952d7)(date, calendar.visibleRange.start, props.isDateUnavailable);
440
- if (!date) return;
441
- if (!anchorDate) setAnchorDate(date);
442
- else {
443
- let range = $9a36b6ba2fb1a7c5$var$makeRange(anchorDate, date);
444
- setValue({
445
- start: $9a36b6ba2fb1a7c5$var$convertValue(range.start, value === null || value === void 0 ? void 0 : value.start),
446
- end: $9a36b6ba2fb1a7c5$var$convertValue(range.end, value === null || value === void 0 ? void 0 : value.end)
447
- });
448
- setAnchorDate(null);
449
- }
450
- };
451
- let [isDragging, setDragging] = (0, $keQhS$useState)(false);
452
- let { isDateUnavailable: isDateUnavailable } = props;
453
- let isInvalidSelection = (0, $keQhS$useMemo)(()=>{
454
- if (!value || anchorDate) return false;
455
- if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) return true;
456
- return (0, $f62d864046160412$export$eac50920cf2fd59a)(value.start, minValue, maxValue) || (0, $f62d864046160412$export$eac50920cf2fd59a)(value.end, minValue, maxValue);
457
- }, [
458
- isDateUnavailable,
459
- value,
460
- anchorDate,
461
- minValue,
462
- maxValue
463
- ]);
464
- let isValueInvalid = props.isInvalid || props.validationState === "invalid" || isInvalidSelection;
465
- let validationState = isValueInvalid ? "invalid" : null;
466
- return {
467
- ...calendar,
468
- value: value,
469
- setValue: setValue,
470
- anchorDate: anchorDate,
471
- setAnchorDate: setAnchorDate,
472
- highlightedRange: highlightedRange,
473
- validationState: validationState,
474
- isValueInvalid: isValueInvalid,
475
- selectFocusedDate () {
476
- selectDate(calendar.focusedDate);
477
- },
478
- selectDate: selectDate,
479
- highlightDate (date) {
480
- if (anchorDate) calendar.setFocusedDate(date);
481
- },
482
- isSelected (date) {
483
- return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date);
484
- },
485
- isInvalid (date) {
486
- var _availableRangeRef_current, _availableRangeRef_current1;
487
- 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);
488
- },
489
- isDragging: isDragging,
490
- setDragging: setDragging
491
- };
492
- }
493
- function $9a36b6ba2fb1a7c5$var$makeRange(start, end) {
494
- if (!start || !end) return null;
495
- if (end.compare(start) < 0) [start, end] = [
496
- end,
497
- start
498
- ];
499
- return {
500
- start: (0, $keQhS$toCalendarDate)(start),
501
- end: (0, $keQhS$toCalendarDate)(end)
502
- };
503
- }
504
- function $9a36b6ba2fb1a7c5$var$convertValue(newValue, oldValue) {
505
- // The display calendar should not have any effect on the emitted value.
506
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
507
- newValue = (0, $keQhS$toCalendar)(newValue, (oldValue === null || oldValue === void 0 ? void 0 : oldValue.calendar) || new (0, $keQhS$GregorianCalendar)());
508
- // Preserve time if the input value had one.
509
- if (oldValue && "hour" in oldValue) return oldValue.set(newValue);
510
- return newValue;
511
- }
512
- function $9a36b6ba2fb1a7c5$var$nextUnavailableDate(anchorDate, state, dir) {
513
- let nextDate = anchorDate.add({
514
- days: dir
515
- });
516
- while((dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) && !state.isCellUnavailable(nextDate))nextDate = nextDate.add({
517
- days: dir
518
- });
519
- if (state.isCellUnavailable(nextDate)) return nextDate.add({
520
- days: -dir
521
- });
522
- return null;
523
- }
524
-
525
15
 
526
16
 
527
17