@react-stately/calendar 3.0.0-nightly.1347 → 3.0.0-nightly.1371

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,363 @@
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 $iUi8f$internationalizeddate = require("@internationalized/date");
2
+ var $iUi8f$reactstatelyutils = require("@react-stately/utils");
3
+ var $iUi8f$reactariai18n = require("@react-aria/i18n");
4
+ var $iUi8f$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 $bdfceb7c4b57da39$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 $6c0a8c647037ad43$exports = {};
46
29
 
47
- if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
48
- halfDuration[key]--;
49
- }
50
- }
30
+ $parcel$export($6c0a8c647037ad43$exports, "useCalendarState", () => $6c0a8c647037ad43$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 $da856c074c1b8d5f$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 $da856c074c1b8d5f$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 = $da856c074c1b8d5f$export$144a00ba6044eb9(date, duration, locale).subtract(halfDuration);
43
+ return $da856c074c1b8d5f$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 $da856c074c1b8d5f$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 = $iUi8f$internationalizeddate.startOfYear(date);
49
+ else if (duration.months) aligned = $iUi8f$internationalizeddate.startOfMonth(date);
50
+ else if (duration.weeks) aligned = $iUi8f$internationalizeddate.startOfWeek(date, locale);
51
+ return $da856c074c1b8d5f$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 $da856c074c1b8d5f$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 = $da856c074c1b8d5f$export$144a00ba6044eb9(date, duration, locale).subtract(d);
63
+ return $da856c074c1b8d5f$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 $da856c074c1b8d5f$export$5bb865b12696a77d(date, aligned, duration, locale, minValue, maxValue) {
66
+ if (minValue && date.compare(minValue) >= 0) aligned = $iUi8f$internationalizeddate.maxDate(aligned, $da856c074c1b8d5f$export$144a00ba6044eb9($iUi8f$internationalizeddate.toCalendarDate(minValue), duration, locale));
67
+ if (maxValue && date.compare(maxValue) <= 0) aligned = $iUi8f$internationalizeddate.minDate(aligned, $da856c074c1b8d5f$export$530edbfc915b2b04($iUi8f$internationalizeddate.toCalendarDate(maxValue), duration, locale));
68
+ return aligned;
69
+ }
70
+ function $da856c074c1b8d5f$export$4f5203c0d889109e(date, minValue, maxValue) {
71
+ if (minValue) date = $iUi8f$internationalizeddate.maxDate(date, $iUi8f$internationalizeddate.toCalendarDate(minValue));
72
+ if (maxValue) date = $iUi8f$internationalizeddate.minDate(date, $iUi8f$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 $6c0a8c647037ad43$export$6d095e787d2b5e1f(props) {
82
+ let defaultFormatter = $iUi8f$reactariai18n.useDateFormatter();
83
+ let resolvedOptions = $iUi8f$react.useMemo(()=>defaultFormatter.resolvedOptions()
84
+ , [
85
+ defaultFormatter
86
+ ]);
87
+ let { locale: locale , createCalendar: createCalendar , timeZone: timeZone = resolvedOptions.timeZone , visibleDuration: visibleDuration = {
88
+ months: 1
89
+ } , minValue: minValue , maxValue: maxValue , selectionAlignment: selectionAlignment } = props;
90
+ let calendar = $iUi8f$react.useMemo(()=>createCalendar(resolvedOptions.calendar)
91
+ , [
92
+ createCalendar,
93
+ resolvedOptions.calendar
94
+ ]);
95
+ let [value, setControlledValue] = $iUi8f$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange);
96
+ let calendarDateValue = $iUi8f$react.useMemo(()=>value ? $iUi8f$internationalizeddate.toCalendar($iUi8f$internationalizeddate.toCalendarDate(value), calendar) : null
97
+ , [
98
+ value,
99
+ calendar
100
+ ]);
101
+ let defaultDate = $iUi8f$react.useMemo(()=>calendarDateValue || $da856c074c1b8d5f$export$4f5203c0d889109e($iUi8f$internationalizeddate.toCalendar($iUi8f$internationalizeddate.today(timeZone), calendar), minValue, maxValue)
102
+ , [
103
+ calendarDateValue,
104
+ timeZone,
105
+ calendar,
106
+ minValue,
107
+ maxValue
108
+ ]);
109
+ let [startDate, setStartDate] = $iUi8f$react.useState(()=>{
110
+ switch(selectionAlignment){
111
+ case 'start':
112
+ return $da856c074c1b8d5f$export$144a00ba6044eb9(defaultDate, visibleDuration, locale, minValue, maxValue);
113
+ case 'end':
114
+ return $da856c074c1b8d5f$export$530edbfc915b2b04(defaultDate, visibleDuration, locale, minValue, maxValue);
115
+ case 'center':
116
+ default:
117
+ return $da856c074c1b8d5f$export$f4a51ff076cc9a09(defaultDate, visibleDuration, locale, minValue, maxValue);
118
+ }
119
+ });
120
+ let [focusedDate, setFocusedDate] = $iUi8f$react.useState(defaultDate);
121
+ let [isFocused, setFocused] = $iUi8f$react.useState(props.autoFocus || false);
122
+ let endDate = $iUi8f$react.useMemo(()=>startDate.add(visibleDuration).subtract({
123
+ days: 1
124
+ })
125
+ , [
126
+ startDate,
127
+ visibleDuration
128
+ ]);
129
+ // Reset focused date and visible range when calendar changes.
130
+ let lastCalendarIdentifier = $iUi8f$react.useRef(calendar.identifier);
131
+ $iUi8f$react.useEffect(()=>{
132
+ if (calendar.identifier !== lastCalendarIdentifier.current) {
133
+ let newFocusedDate = $iUi8f$internationalizeddate.toCalendar(focusedDate, calendar);
134
+ setStartDate($da856c074c1b8d5f$export$f4a51ff076cc9a09(newFocusedDate, visibleDuration, locale, minValue, maxValue));
135
+ setFocusedDate(newFocusedDate);
136
+ lastCalendarIdentifier.current = calendar.identifier;
137
+ }
138
+ }, [
139
+ calendar,
140
+ focusedDate,
141
+ visibleDuration,
142
+ locale,
143
+ minValue,
144
+ maxValue
145
+ ]);
146
+ // Sets focus to a specific cell date
147
+ function focusCell(date) {
148
+ // date = constrain(focusedDate, date, visibleDuration, locale, minValue, maxValue);
149
+ date = $da856c074c1b8d5f$export$4f5203c0d889109e(date, minValue, maxValue);
150
+ let next = startDate.add(visibleDuration);
151
+ if (date.compare(startDate) < 0) setStartDate($da856c074c1b8d5f$export$530edbfc915b2b04(date, visibleDuration, locale, minValue, maxValue));
152
+ else if (date.compare(next) >= 0) setStartDate($da856c074c1b8d5f$export$144a00ba6044eb9(date, visibleDuration, locale, minValue, maxValue));
153
+ setFocusedDate(date);
169
154
  }
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
- }
155
+ function setValue(newValue) {
156
+ if (!props.isDisabled && !props.isReadOnly) {
157
+ // The display calendar should not have any effect on the emitted value.
158
+ // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
159
+ newValue = $iUi8f$internationalizeddate.toCalendar(newValue, value?.calendar || new $iUi8f$internationalizeddate.GregorianCalendar());
160
+ // Preserve time if the input value had one.
161
+ if (value && 'hour' in value) setControlledValue(value.set(newValue));
162
+ else setControlledValue(newValue);
163
+ }
185
164
  }
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
- };
165
+ return {
166
+ isDisabled: props.isDisabled,
167
+ isReadOnly: props.isReadOnly,
168
+ value: calendarDateValue,
169
+ setValue: setValue,
170
+ visibleRange: {
171
+ start: startDate,
172
+ end: endDate
173
+ },
174
+ focusedDate: focusedDate,
175
+ timeZone: timeZone,
176
+ setFocusedDate (date) {
177
+ setFocusedDate(date);
178
+ setFocused(true);
179
+ },
180
+ focusNextDay () {
181
+ focusCell(focusedDate.add({
182
+ days: 1
183
+ }));
184
+ },
185
+ focusPreviousDay () {
186
+ focusCell(focusedDate.subtract({
187
+ days: 1
188
+ }));
189
+ },
190
+ focusNextRow () {
191
+ if (visibleDuration.days) this.focusNextPage();
192
+ else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
193
+ weeks: 1
194
+ }));
195
+ },
196
+ focusPreviousRow () {
197
+ if (visibleDuration.days) this.focusPreviousPage();
198
+ else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
199
+ weeks: 1
200
+ }));
201
+ },
202
+ focusNextPage () {
203
+ let start = startDate.add(visibleDuration);
204
+ setStartDate($da856c074c1b8d5f$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue));
205
+ setFocusedDate($da856c074c1b8d5f$export$4f5203c0d889109e(focusedDate.add(visibleDuration), minValue, maxValue));
206
+ },
207
+ focusPreviousPage () {
208
+ let start = startDate.subtract(visibleDuration);
209
+ setStartDate($da856c074c1b8d5f$export$5bb865b12696a77d(focusedDate, start, visibleDuration, locale, minValue, maxValue));
210
+ setFocusedDate($da856c074c1b8d5f$export$4f5203c0d889109e(focusedDate.subtract(visibleDuration), minValue, maxValue));
211
+ },
212
+ focusPageStart () {
213
+ focusCell(startDate);
214
+ },
215
+ focusPageEnd () {
216
+ focusCell(endDate);
217
+ },
218
+ focusNextSection () {
219
+ if (visibleDuration.days) this.focusNextPage();
220
+ else if (visibleDuration.weeks) focusCell(focusedDate.add({
221
+ months: 1
222
+ }));
223
+ else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.add({
224
+ years: 1
225
+ }));
226
+ },
227
+ focusPreviousSection () {
228
+ if (visibleDuration.days) this.focusPreviousPage();
229
+ else if (visibleDuration.weeks) focusCell(focusedDate.subtract({
230
+ months: 1
231
+ }));
232
+ else if (visibleDuration.months || visibleDuration.years) focusCell(focusedDate.subtract({
233
+ years: 1
234
+ }));
235
+ },
236
+ selectFocusedDate () {
237
+ setValue(focusedDate);
238
+ },
239
+ selectDate (date) {
240
+ setValue(date);
241
+ },
242
+ isFocused: isFocused,
243
+ setFocused: setFocused,
244
+ isInvalid (date) {
245
+ return $da856c074c1b8d5f$export$eac50920cf2fd59a(date, minValue, maxValue);
246
+ },
247
+ isSelected (date) {
248
+ return calendarDateValue != null && $iUi8f$internationalizeddate.isSameDay(date, calendarDateValue);
249
+ },
250
+ isCellFocused (date) {
251
+ return isFocused && focusedDate && $iUi8f$internationalizeddate.isSameDay(date, focusedDate);
252
+ },
253
+ isCellDisabled (date) {
254
+ return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || $da856c074c1b8d5f$export$eac50920cf2fd59a(date, minValue, maxValue);
255
+ },
256
+ isPreviousVisibleRangeInvalid () {
257
+ return $da856c074c1b8d5f$export$eac50920cf2fd59a(startDate.subtract({
258
+ days: 1
259
+ }), minValue, maxValue);
260
+ },
261
+ isNextVisibleRangeInvalid () {
262
+ return $da856c074c1b8d5f$export$eac50920cf2fd59a(endDate.add({
263
+ days: 1
264
+ }), minValue, maxValue);
265
+ }
266
+ };
325
267
  }
326
268
 
327
- exports.useCalendarState = useCalendarState;
328
269
 
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"]);
270
+ var $65911ba90eda5d23$exports = {};
343
271
 
344
- let [value, setValue] = useControlledState(valueProp, defaultValue, onChange);
345
- let [anchorDate, setAnchorDate] = useState(null);
346
- let alignment = 'center';
272
+ $parcel$export($65911ba90eda5d23$exports, "useRangeCalendarState", () => $65911ba90eda5d23$export$9a987164d97ecc90);
347
273
 
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
274
 
354
- if (value.end.compare(end) > 0) {
355
- alignment = 'start';
356
- }
357
- }
358
275
 
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
276
 
370
- let selectDate = date => {
371
- if (props.isReadOnly) {
372
- return;
373
- }
374
277
 
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);
278
+ function $65911ba90eda5d23$export$9a987164d97ecc90(props) {
279
+ let { value: valueProp , defaultValue: defaultValue , onChange: onChange , createCalendar: createCalendar , locale: locale , visibleDuration: visibleDuration = {
280
+ months: 1
281
+ } , minValue: minValue , maxValue: maxValue , ...calendarProps } = props;
282
+ let [value, setValue] = $iUi8f$reactstatelyutils.useControlledState(valueProp, defaultValue, onChange);
283
+ let [anchorDate, setAnchorDate] = $iUi8f$react.useState(null);
284
+ let alignment = 'center';
285
+ if (value && value.start && value.end) {
286
+ let start = $da856c074c1b8d5f$export$f4a51ff076cc9a09($iUi8f$internationalizeddate.toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);
287
+ let end = start.add(visibleDuration).subtract({
288
+ days: 1
289
+ });
290
+ if (value.end.compare(end) > 0) alignment = 'start';
384
291
  }
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
- });
292
+ let calendar = $6c0a8c647037ad43$export$6d095e787d2b5e1f({
293
+ ...calendarProps,
294
+ value: value && value.start,
295
+ createCalendar: createCalendar,
296
+ locale: locale,
297
+ visibleDuration: visibleDuration,
298
+ minValue: minValue,
299
+ maxValue: maxValue,
300
+ selectionAlignment: alignment
301
+ });
302
+ let highlightedRange = anchorDate ? $65911ba90eda5d23$var$makeRange(anchorDate, calendar.focusedDate) : value && $65911ba90eda5d23$var$makeRange(value.start, value.end);
303
+ let selectDate = (date)=>{
304
+ if (props.isReadOnly) return;
305
+ if (!anchorDate) setAnchorDate(date);
306
+ else {
307
+ let range = $65911ba90eda5d23$var$makeRange(anchorDate, date);
308
+ setValue({
309
+ start: $65911ba90eda5d23$var$convertValue(range.start, value?.start),
310
+ end: $65911ba90eda5d23$var$convertValue(range.end, value?.end)
311
+ });
312
+ setAnchorDate(null);
313
+ }
314
+ };
315
+ let [isDragging, setDragging] = $iUi8f$react.useState(false);
316
+ return {
317
+ ...calendar,
318
+ value: value,
319
+ setValue: setValue,
320
+ anchorDate: anchorDate,
321
+ setAnchorDate: setAnchorDate,
322
+ highlightedRange: highlightedRange,
323
+ selectFocusedDate () {
324
+ selectDate(calendar.focusedDate);
325
+ },
326
+ selectDate: selectDate,
327
+ highlightDate (date) {
328
+ if (anchorDate) calendar.setFocusedDate(date);
329
+ },
330
+ isSelected (date) {
331
+ return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0;
332
+ },
333
+ isDragging: isDragging,
334
+ setDragging: setDragging
335
+ };
414
336
  }
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
- };
337
+ function $65911ba90eda5d23$var$makeRange(start, end) {
338
+ if (!start || !end) return null;
339
+ if (end.compare(start) < 0) [start, end] = [
340
+ end,
341
+ start
342
+ ];
343
+ return {
344
+ start: $iUi8f$internationalizeddate.toCalendarDate(start),
345
+ end: $iUi8f$internationalizeddate.toCalendarDate(end)
346
+ };
347
+ }
348
+ function $65911ba90eda5d23$var$convertValue(newValue, oldValue) {
349
+ // The display calendar should not have any effect on the emitted value.
350
+ // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
351
+ newValue = $iUi8f$internationalizeddate.toCalendar(newValue, oldValue?.calendar || new $iUi8f$internationalizeddate.GregorianCalendar());
352
+ // Preserve time if the input value had one.
353
+ if (oldValue && 'hour' in oldValue) return oldValue.set(newValue);
354
+ return newValue;
431
355
  }
432
356
 
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
357
 
438
- if (oldValue && 'hour' in oldValue) {
439
- return oldValue.set(newValue);
440
- }
358
+ $parcel$exportWildcard(module.exports, $bdfceb7c4b57da39$exports);
359
+ $parcel$exportWildcard(module.exports, $6c0a8c647037ad43$exports);
360
+ $parcel$exportWildcard(module.exports, $65911ba90eda5d23$exports);
361
+
441
362
 
442
- return newValue;
443
- }
444
363
  //# sourceMappingURL=main.js.map