@react-stately/calendar 3.4.4 → 3.5.1

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,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.module.js";
2
+ import {useRangeCalendarState as $9a36b6ba2fb1a7c5$export$9a987164d97ecc90} from "./useRangeCalendarState.module.js";
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
 
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAaM,SAAS,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;AACF;AAEA,SAAS,gCAAU,KAAgB,EAAE,GAAc;IACjD,IAAI,CAAC,SAAS,CAAC,KACb,OAAO;IAGT,IAAI,IAAI,OAAO,CAAC,SAAS,GACvB,CAAC,OAAO,IAAI,GAAG;QAAC;QAAK;KAAM;IAG7B,OAAO;QAAC,OAAO,CAAA,GAAA,qBAAa,EAAE;QAAQ,KAAK,CAAA,GAAA,qBAAa,EAAE;IAAI;AAChE;AAEA,SAAS,mCAAa,QAAsB,EAAE,QAAmB;IAC/D,wEAAwE;IACxE,sFAAsF;IACtF,WAAW,CAAA,GAAA,iBAAS,EAAE,UAAU,CAAA,qBAAA,+BAAA,SAAU,QAAQ,KAAI,IAAI,CAAA,GAAA,wBAAgB;IAE1E,4CAA4C;IAC5C,IAAI,YAAY,UAAU,UACxB,OAAO,SAAS,GAAG,CAAC;IAGtB,OAAO;AACT;AAEA,SAAS,0CAAoB,UAAwB,EAAE,KAAoB,EAAE,GAAW;IACtF,IAAI,WAAW,WAAW,GAAG,CAAC;QAAC,MAAM;IAAG;IACxC,MACE,AAAC,CAAA,MAAM,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,KAAK,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,KAAK,CAAA,KACzG,CAAC,MAAM,iBAAiB,CAAC,UAEzB,WAAW,SAAS,GAAG,CAAC;QAAC,MAAM;IAAG;IAGpC,IAAI,MAAM,iBAAiB,CAAC,WAC1B,OAAO,SAAS,GAAG,CAAC;QAAC,MAAM,CAAC;IAAG;IAGjC,OAAO;AACT;","sources":["packages/@react-stately/calendar/src/index.ts","packages/@react-stately/calendar/src/useCalendarState.ts","packages/@react-stately/calendar/src/utils.ts","packages/@react-stately/calendar/src/useRangeCalendarState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useCalendarState} from './useCalendarState';\nexport {useRangeCalendarState} from './useRangeCalendarState';\n\nexport type {CalendarStateOptions} from './useCalendarState';\nexport type {RangeCalendarStateOptions} from './useRangeCalendarState';\nexport type {CalendarState, RangeCalendarState} from './types'; \n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {alignCenter, alignEnd, alignStart, constrainStart, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {\n Calendar,\n CalendarDate,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue} from '@react-types/calendar';\nimport {CalendarState} from './types';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface CalendarStateOptions<T extends DateValue = DateValue> extends CalendarProps<T> {\n /** The locale to display and edit the value according to. */\n locale: string,\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: string) => Calendar,\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** Determines how to align the initial selection relative to the visible date range. */\n selectionAlignment?: 'start' | 'center' | 'end'\n}\n\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<T extends DateValue = DateValue>(props: CalendarStateOptions<T>): CalendarState {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible'\n } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue>(props.value, props.defaultValue, props.onChange);\n let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);\n let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(() => (\n props.focusedValue\n ? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue)\n : undefined\n ), [props.focusedValue, calendar, minValue, maxValue]);\n let defaultFocusedCalendarDate = useMemo(() => (\n constrainValue(\n props.defaultFocusedValue\n ? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar)\n : calendarDateValue || toCalendar(today(timeZone), calendar),\n minValue,\n maxValue\n )\n ), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);\n let [startDate, setStartDate] = useState(() => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n });\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendarIdentifier, setLastCalendarIdentifier] = useState(calendar.identifier);\n if (calendar.identifier !== lastCalendarIdentifier) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendarIdentifier(calendar.identifier);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function setValue(newValue: CalendarDate) {\n if (!props.isDisabled && !props.isReadOnly) {\n newValue = constrainValue(newValue, minValue, maxValue);\n newValue = previousAvailableDate(newValue, startDate, isDateUnavailable);\n if (!newValue) {\n return;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n newValue = toCalendar(newValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(newValue));\n } else {\n setControlledValue(newValue);\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (isDateUnavailable && isDateUnavailable(calendarDateValue)) {\n return true;\n }\n\n return isInvalid(calendarDateValue, minValue, maxValue);\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled,\n isReadOnly: props.isReadOnly,\n value: calendarDateValue,\n setValue,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n setFocused(true);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n setValue(focusedDate);\n },\n selectDate(date) {\n setValue(date);\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n return calendarDateValue != null && isSameDay(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable && props.isDateUnavailable(date);\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev, minValue, maxValue);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next, minValue, maxValue);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n // let date = startOfWeek(from, locale);\n let date = from.add({weeks: weekIndex});\n let dates = [];\n\n date = startOfWeek(date, locale);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n\n while (dates.length < 7) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < 7) {\n dates.push(null);\n }\n\n return dates;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport {\n CalendarDate,\n DateDuration,\n maxDate,\n minDate,\n startOfMonth,\n startOfWeek,\n startOfYear,\n toCalendarDate\n} from '@internationalized/date';\nimport {DateValue} from '@react-types/calendar';\n\nexport function isInvalid(date: DateValue, minValue: DateValue, maxValue: DateValue) {\n return (minValue != null && date.compare(minValue) < 0) ||\n (maxValue != null && date.compare(maxValue) > 0);\n}\n\nexport function alignCenter(date: CalendarDate, duration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue) {\n let halfDuration: DateDuration = {};\n for (let key in duration) {\n halfDuration[key] = Math.floor(duration[key] / 2);\n if (halfDuration[key] > 0 && duration[key] % 2 === 0) {\n halfDuration[key]--;\n }\n }\n\n let aligned = alignStart(date, duration, locale).subtract(halfDuration);\n return constrainStart(date, aligned, duration, locale, minValue, maxValue);\n}\n\nexport function alignStart(date: CalendarDate, duration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue) {\n // align to the start of the largest unit\n let aligned = date;\n if (duration.years) {\n aligned = startOfYear(date);\n } else if (duration.months) {\n aligned = startOfMonth(date);\n } else if (duration.weeks) {\n aligned = startOfWeek(date, locale);\n }\n\n return constrainStart(date, aligned, duration, locale, minValue, maxValue);\n}\n\nexport function alignEnd(date: CalendarDate, duration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue) {\n let d = {...duration};\n // subtract 1 from the smallest unit\n if (duration.days) {\n d.days--;\n } else if (duration.weeks) {\n d.weeks--;\n } else if (duration.months) {\n d.months--;\n } else if (duration.years) {\n d.years--;\n }\n\n let aligned = alignStart(date, duration, locale).subtract(d);\n return constrainStart(date, aligned, duration, locale, minValue, maxValue);\n}\n\nexport function constrainStart(\n date: CalendarDate,\n aligned: CalendarDate,\n duration: DateDuration,\n locale: string,\n minValue: DateValue,\n maxValue: DateValue) {\n if (minValue && date.compare(minValue) >= 0) {\n aligned = maxDate(\n aligned,\n alignStart(toCalendarDate(minValue), duration, locale)\n );\n }\n\n if (maxValue && date.compare(maxValue) <= 0) {\n aligned = minDate(\n aligned,\n alignEnd(toCalendarDate(maxValue), duration, locale)\n );\n }\n\n return aligned;\n}\n\nexport function constrainValue(date: CalendarDate, minValue: DateValue, maxValue: DateValue) {\n if (minValue) {\n date = maxDate(date, toCalendarDate(minValue));\n }\n\n if (maxValue) {\n date = minDate(date, toCalendarDate(maxValue));\n }\n\n return date;\n}\n\nexport function previousAvailableDate(date: CalendarDate, minValue: DateValue, isDateUnavailable: (date: CalendarDate) => boolean) {\n if (!isDateUnavailable) {\n return date;\n }\n\n while (date.compare(minValue) >= 0 && isDateUnavailable(date)) {\n date = date.subtract({days: 1});\n }\n\n if (date.compare(minValue) >= 0) {\n return date;\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {alignCenter, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {Calendar, CalendarDate, DateDuration, GregorianCalendar, isEqualDay, maxDate, minDate, toCalendar, toCalendarDate} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from './types';\nimport {DateRange, DateValue, RangeCalendarProps} from '@react-types/calendar';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useCalendarState} from './useCalendarState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface RangeCalendarStateOptions<T extends DateValue = DateValue> extends RangeCalendarProps<T> {\n /** The locale to display and edit the value according to. */\n locale: string,\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: string) => Calendar,\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n * @default {months: 1}\n */\n visibleDuration?: DateDuration\n}\n\n/**\n * Provides state management for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {\n let {value: valueProp, defaultValue, onChange, createCalendar, locale, visibleDuration = {months: 1}, minValue, maxValue, ...calendarProps} = props;\n let [value, setValue] = useControlledState<DateRange>(\n valueProp,\n defaultValue || null,\n onChange\n );\n\n let [anchorDate, setAnchorDateState] = useState(null);\n let alignment: 'center' | 'start' = 'center';\n if (value && value.start && value.end) {\n let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);\n let end = start.add(visibleDuration).subtract({days: 1});\n\n if (value.end.compare(end) > 0) {\n alignment = 'start';\n }\n }\n\n // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.\n let availableRangeRef = useRef<RangeValue<DateValue>>(null);\n let [availableRange, setAvailableRange] = useState<RangeValue<DateValue>>(null);\n let min = useMemo(() => maxDate(minValue, availableRange?.start), [minValue, availableRange]);\n let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]);\n\n let calendar = useCalendarState({\n ...calendarProps,\n value: value && value.start,\n createCalendar,\n locale,\n visibleDuration,\n minValue: min,\n maxValue: max,\n selectionAlignment: alignment\n });\n\n let updateAvailableRange = (date) => {\n if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {\n availableRangeRef.current = {\n start: nextUnavailableDate(date, calendar, -1),\n end: nextUnavailableDate(date, calendar, 1)\n };\n setAvailableRange(availableRangeRef.current);\n } else {\n availableRangeRef.current = null;\n setAvailableRange(null);\n }\n };\n\n // If the visible range changes, we need to update the available range.\n let [lastVisibleRange, setLastVisibleRange] = useState(calendar.visibleRange);\n if (!isEqualDay(calendar.visibleRange.start, lastVisibleRange.start) || !isEqualDay(calendar.visibleRange.end, lastVisibleRange.end)) {\n updateAvailableRange(anchorDate);\n setLastVisibleRange(calendar.visibleRange);\n }\n\n let setAnchorDate = (date: CalendarDate) => {\n if (date) {\n setAnchorDateState(date);\n updateAvailableRange(date);\n } else {\n setAnchorDateState(null);\n updateAvailableRange(null);\n }\n };\n\n let highlightedRange = anchorDate ? makeRange(anchorDate, calendar.focusedDate) : value && makeRange(value.start, value.end);\n let selectDate = (date: CalendarDate) => {\n if (props.isReadOnly) {\n return;\n }\n\n date = constrainValue(date, min, max);\n date = previousAvailableDate(date, calendar.visibleRange.start, props.isDateUnavailable);\n if (!date) {\n return;\n }\n\n if (!anchorDate) {\n setAnchorDate(date);\n } else {\n let range = makeRange(anchorDate, date);\n setValue({\n start: convertValue(range.start, value?.start),\n end: convertValue(range.end, value?.end)\n });\n setAnchorDate(null);\n }\n };\n\n let [isDragging, setDragging] = useState(false);\n\n let {isDateUnavailable} = props;\n let isInvalidSelection = useMemo(() => {\n if (!value || anchorDate) {\n return false;\n }\n\n if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) {\n return true;\n }\n\n return isInvalid(value.start, minValue, maxValue) || isInvalid(value.end, minValue, maxValue);\n }, [isDateUnavailable, value, anchorDate, minValue, maxValue]);\n\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isInvalidSelection;\n let validationState: ValidationState = isValueInvalid ? 'invalid' : null;\n\n return {\n ...calendar,\n value,\n setValue,\n anchorDate,\n setAnchorDate,\n highlightedRange,\n validationState,\n isValueInvalid,\n selectFocusedDate() {\n selectDate(calendar.focusedDate);\n },\n selectDate,\n highlightDate(date) {\n if (anchorDate) {\n calendar.setFocusedDate(date);\n }\n },\n isSelected(date) {\n return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date);\n },\n isInvalid(date) {\n return calendar.isInvalid(date) || isInvalid(date, availableRangeRef.current?.start, availableRangeRef.current?.end);\n },\n isDragging,\n setDragging\n };\n}\n\nfunction makeRange(start: DateValue, end: DateValue): RangeValue<CalendarDate> {\n if (!start || !end) {\n return null;\n }\n\n if (end.compare(start) < 0) {\n [start, end] = [end, start];\n }\n\n return {start: toCalendarDate(start), end: toCalendarDate(end)};\n}\n\nfunction convertValue(newValue: CalendarDate, oldValue: DateValue) {\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n newValue = toCalendar(newValue, oldValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (oldValue && 'hour' in oldValue) {\n return oldValue.set(newValue);\n }\n\n return newValue;\n}\n\nfunction nextUnavailableDate(anchorDate: CalendarDate, state: CalendarState, dir: number) {\n let nextDate = anchorDate.add({days: dir});\n while (\n (dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) &&\n !state.isCellUnavailable(nextDate)\n ) {\n nextDate = nextDate.add({days: dir});\n }\n\n if (state.isCellUnavailable(nextDate)) {\n return nextDate.add({days: -dir});\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/calendar/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useCalendarState} from './useCalendarState';\nexport {useRangeCalendarState} from './useRangeCalendarState';\n\nexport type {CalendarStateOptions} from './useCalendarState';\nexport type {RangeCalendarStateOptions} from './useRangeCalendarState';\nexport type {CalendarState, RangeCalendarState} from './types'; \n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -87,9 +87,9 @@ interface CalendarStateBase {
87
87
  }
88
88
  export interface CalendarState extends CalendarStateBase {
89
89
  /** The currently selected date. */
90
- readonly value: CalendarDate;
90
+ readonly value: CalendarDate | null;
91
91
  /** Sets the currently selected date. */
92
- setValue(value: CalendarDate): void;
92
+ setValue(value: CalendarDate | null): void;
93
93
  }
94
94
  export interface RangeCalendarState extends CalendarStateBase {
95
95
  /** The currently selected date range. */