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