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

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