@helsenorge/datepicker 9.4.3 → 10.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import React, { createContext, forwardRef, useContext, useState, useEffect, useLayoutEffect, useRef } from "react";
3
- import { isSameDay, subDays, addDays, differenceInCalendarDays, startOfMonth, endOfMonth, startOfDay, addMonths, differenceInCalendarMonths, isSameMonth, isBefore, isAfter, getUnixTime, getWeeksInMonth, addWeeks, isSameYear, setMonth, setYear, startOfYear, max, min, endOfISOWeek, endOfWeek, startOfISOWeek, startOfWeek, getISOWeek, getWeek, format, isDate, addYears, isValid, parse, isWithinInterval } from "date-fns";
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import React, { createContext, useContext, useState, useEffect, useMemo, useCallback, useRef } from "react";
3
+ import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getWeek, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, isValid, parse, isWithinInterval } from "date-fns";
4
4
  import { enUS, nb } from "date-fns/locale";
5
5
  import Button$1 from "@helsenorge/designsystem-react/components/Button";
6
6
  import Icon from "@helsenorge/designsystem-react/components/Icon";
@@ -14,6 +14,7 @@ import { usePseudoClasses } from "@helsenorge/designsystem-react/hooks/usePseudo
14
14
  import { isMobileUA } from "@helsenorge/designsystem-react/utils/mobile";
15
15
  import { isMutableRefObject, mergeRefs } from "@helsenorge/designsystem-react/utils/refs";
16
16
  import classNames from "classnames";
17
+ import { enUS as enUS$1 } from "date-fns/locale/en-US";
17
18
  import reactdaypickerstyles from "react-day-picker/dist/style.module.css";
18
19
  import { useFocusTrap } from "@helsenorge/designsystem-react/hooks/useFocusTrap";
19
20
  import { useInterval } from "@helsenorge/designsystem-react/hooks/useInterval";
@@ -25,788 +26,1117 @@ import styles from "./styles.module.scss";
25
26
  import ErrorWrapper from "@helsenorge/designsystem-react/components/ErrorWrapper";
26
27
  import { useUuid } from "@helsenorge/designsystem-react/hooks/useUuid";
27
28
  import { isComponent } from "@helsenorge/designsystem-react/utils/component";
28
- var __assign = function() {
29
- __assign = Object.assign || function __assign2(t) {
30
- for (var s, i = 1, n = arguments.length; i < n; i++) {
31
- s = arguments[i];
32
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
29
+ var UI;
30
+ (function(UI2) {
31
+ UI2["Root"] = "root";
32
+ UI2["Chevron"] = "chevron";
33
+ UI2["Day"] = "day";
34
+ UI2["DayButton"] = "day_button";
35
+ UI2["CaptionLabel"] = "caption_label";
36
+ UI2["Dropdowns"] = "dropdowns";
37
+ UI2["Dropdown"] = "dropdown";
38
+ UI2["DropdownRoot"] = "dropdown_root";
39
+ UI2["Footer"] = "footer";
40
+ UI2["MonthGrid"] = "month_grid";
41
+ UI2["MonthCaption"] = "month_caption";
42
+ UI2["MonthsDropdown"] = "months_dropdown";
43
+ UI2["Month"] = "month";
44
+ UI2["Months"] = "months";
45
+ UI2["Nav"] = "nav";
46
+ UI2["NextMonthButton"] = "button_next";
47
+ UI2["PreviousMonthButton"] = "button_previous";
48
+ UI2["Week"] = "week";
49
+ UI2["Weeks"] = "weeks";
50
+ UI2["Weekday"] = "weekday";
51
+ UI2["Weekdays"] = "weekdays";
52
+ UI2["WeekNumber"] = "week_number";
53
+ UI2["WeekNumberHeader"] = "week_number_header";
54
+ UI2["YearsDropdown"] = "years_dropdown";
55
+ })(UI || (UI = {}));
56
+ var DayFlag;
57
+ (function(DayFlag2) {
58
+ DayFlag2["disabled"] = "disabled";
59
+ DayFlag2["hidden"] = "hidden";
60
+ DayFlag2["outside"] = "outside";
61
+ DayFlag2["focused"] = "focused";
62
+ DayFlag2["today"] = "today";
63
+ })(DayFlag || (DayFlag = {}));
64
+ var SelectionState;
65
+ (function(SelectionState2) {
66
+ SelectionState2["range_end"] = "range_end";
67
+ SelectionState2["range_middle"] = "range_middle";
68
+ SelectionState2["range_start"] = "range_start";
69
+ SelectionState2["selected"] = "selected";
70
+ })(SelectionState || (SelectionState = {}));
71
+ const FIVE_WEEKS = 5;
72
+ const FOUR_WEEKS = 4;
73
+ function getBroadcastWeeksInMonth(month, dateLib) {
74
+ const firstDayOfMonth = dateLib.startOfMonth(month);
75
+ const firstDayOfWeek = firstDayOfMonth.getDay() > 0 ? firstDayOfMonth.getDay() : 7;
76
+ const broadcastStartDate = dateLib.addDays(month, -firstDayOfWeek + 1);
77
+ const lastDateOfLastWeek = dateLib.addDays(broadcastStartDate, FIVE_WEEKS * 7 - 1);
78
+ const numberOfWeeks = month.getMonth() === lastDateOfLastWeek.getMonth() ? FIVE_WEEKS : FOUR_WEEKS;
79
+ return numberOfWeeks;
80
+ }
81
+ function startOfBroadcastWeek(date, dateLib) {
82
+ const firstOfMonth = dateLib.startOfMonth(date);
83
+ const dayOfWeek = firstOfMonth.getDay();
84
+ if (dayOfWeek === 1) {
85
+ return firstOfMonth;
86
+ } else if (dayOfWeek === 0) {
87
+ return dateLib.addDays(firstOfMonth, -1 * 6);
88
+ } else {
89
+ return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
90
+ }
91
+ }
92
+ function endOfBroadcastWeek(date, dateLib) {
93
+ const startDate = startOfBroadcastWeek(date, dateLib);
94
+ const numberOfWeeks = getBroadcastWeeksInMonth(date, dateLib);
95
+ const endDate = dateLib.addDays(startDate, numberOfWeeks * 7 - 1);
96
+ return endDate;
97
+ }
98
+ class DateLib {
99
+ /**
100
+ * Creates an instance of DateLib.
101
+ *
102
+ * @param options The options for the date library.
103
+ * @param overrides Overrides for the date library functions.
104
+ */
105
+ constructor(options, overrides) {
106
+ this.Date = Date;
107
+ this.addDays = (date, amount) => {
108
+ var _a;
109
+ return ((_a = this.overrides) == null ? void 0 : _a.addDays) ? this.overrides.addDays(date, amount) : addDays(date, amount);
110
+ };
111
+ this.addMonths = (date, amount) => {
112
+ var _a;
113
+ return ((_a = this.overrides) == null ? void 0 : _a.addMonths) ? this.overrides.addMonths(date, amount) : addMonths(date, amount);
114
+ };
115
+ this.addWeeks = (date, amount) => {
116
+ var _a;
117
+ return ((_a = this.overrides) == null ? void 0 : _a.addWeeks) ? this.overrides.addWeeks(date, amount) : addWeeks(date, amount);
118
+ };
119
+ this.addYears = (date, amount) => {
120
+ var _a;
121
+ return ((_a = this.overrides) == null ? void 0 : _a.addYears) ? this.overrides.addYears(date, amount) : addYears(date, amount);
122
+ };
123
+ this.differenceInCalendarDays = (dateLeft, dateRight) => {
124
+ var _a;
125
+ return ((_a = this.overrides) == null ? void 0 : _a.differenceInCalendarDays) ? this.overrides.differenceInCalendarDays(dateLeft, dateRight) : differenceInCalendarDays(dateLeft, dateRight);
126
+ };
127
+ this.differenceInCalendarMonths = (dateLeft, dateRight) => {
128
+ var _a;
129
+ return ((_a = this.overrides) == null ? void 0 : _a.differenceInCalendarMonths) ? this.overrides.differenceInCalendarMonths(dateLeft, dateRight) : differenceInCalendarMonths(dateLeft, dateRight);
130
+ };
131
+ this.endOfBroadcastWeek = (date) => {
132
+ var _a;
133
+ return ((_a = this.overrides) == null ? void 0 : _a.endOfBroadcastWeek) ? this.overrides.endOfBroadcastWeek(date, this) : endOfBroadcastWeek(date, this);
134
+ };
135
+ this.endOfISOWeek = (date) => {
136
+ var _a;
137
+ return ((_a = this.overrides) == null ? void 0 : _a.endOfISOWeek) ? this.overrides.endOfISOWeek(date) : endOfISOWeek(date);
138
+ };
139
+ this.endOfMonth = (date) => {
140
+ var _a;
141
+ return ((_a = this.overrides) == null ? void 0 : _a.endOfMonth) ? this.overrides.endOfMonth(date) : endOfMonth(date);
142
+ };
143
+ this.endOfWeek = (date) => {
144
+ var _a;
145
+ return ((_a = this.overrides) == null ? void 0 : _a.endOfWeek) ? this.overrides.endOfWeek(date, this.options) : endOfWeek(date, this.options);
146
+ };
147
+ this.endOfYear = (date) => {
148
+ var _a;
149
+ return ((_a = this.overrides) == null ? void 0 : _a.endOfYear) ? this.overrides.endOfYear(date) : endOfYear(date);
150
+ };
151
+ this.format = (date, formatStr) => {
152
+ var _a;
153
+ return ((_a = this.overrides) == null ? void 0 : _a.format) ? this.overrides.format(date, formatStr, this.options) : format(date, formatStr, this.options);
154
+ };
155
+ this.getISOWeek = (date) => {
156
+ var _a;
157
+ return ((_a = this.overrides) == null ? void 0 : _a.getISOWeek) ? this.overrides.getISOWeek(date) : getISOWeek(date);
158
+ };
159
+ this.getWeek = (date) => {
160
+ var _a;
161
+ return ((_a = this.overrides) == null ? void 0 : _a.getWeek) ? this.overrides.getWeek(date, this.options) : getWeek(date, this.options);
162
+ };
163
+ this.isAfter = (date, dateToCompare) => {
164
+ var _a;
165
+ return ((_a = this.overrides) == null ? void 0 : _a.isAfter) ? this.overrides.isAfter(date, dateToCompare) : isAfter(date, dateToCompare);
166
+ };
167
+ this.isBefore = (date, dateToCompare) => {
168
+ var _a;
169
+ return ((_a = this.overrides) == null ? void 0 : _a.isBefore) ? this.overrides.isBefore(date, dateToCompare) : isBefore(date, dateToCompare);
170
+ };
171
+ this.isDate = (value) => {
172
+ var _a;
173
+ return ((_a = this.overrides) == null ? void 0 : _a.isDate) ? this.overrides.isDate(value) : isDate(value);
174
+ };
175
+ this.isSameDay = (dateLeft, dateRight) => {
176
+ var _a;
177
+ return ((_a = this.overrides) == null ? void 0 : _a.isSameDay) ? this.overrides.isSameDay(dateLeft, dateRight) : isSameDay(dateLeft, dateRight);
178
+ };
179
+ this.isSameMonth = (dateLeft, dateRight) => {
180
+ var _a;
181
+ return ((_a = this.overrides) == null ? void 0 : _a.isSameMonth) ? this.overrides.isSameMonth(dateLeft, dateRight) : isSameMonth(dateLeft, dateRight);
182
+ };
183
+ this.isSameYear = (dateLeft, dateRight) => {
184
+ var _a;
185
+ return ((_a = this.overrides) == null ? void 0 : _a.isSameYear) ? this.overrides.isSameYear(dateLeft, dateRight) : isSameYear(dateLeft, dateRight);
186
+ };
187
+ this.max = (dates) => {
188
+ var _a;
189
+ return ((_a = this.overrides) == null ? void 0 : _a.max) ? this.overrides.max(dates) : max(dates);
190
+ };
191
+ this.min = (dates) => {
192
+ var _a;
193
+ return ((_a = this.overrides) == null ? void 0 : _a.min) ? this.overrides.min(dates) : min(dates);
194
+ };
195
+ this.setMonth = (date, month) => {
196
+ var _a;
197
+ return ((_a = this.overrides) == null ? void 0 : _a.setMonth) ? this.overrides.setMonth(date, month) : setMonth(date, month);
198
+ };
199
+ this.setYear = (date, year) => {
200
+ var _a;
201
+ return ((_a = this.overrides) == null ? void 0 : _a.setYear) ? this.overrides.setYear(date, year) : setYear(date, year);
202
+ };
203
+ this.startOfBroadcastWeek = (date) => {
204
+ var _a;
205
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfBroadcastWeek) ? this.overrides.startOfBroadcastWeek(date, this) : startOfBroadcastWeek(date, this);
206
+ };
207
+ this.startOfDay = (date) => {
208
+ var _a;
209
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfDay) ? this.overrides.startOfDay(date) : startOfDay(date);
210
+ };
211
+ this.startOfISOWeek = (date) => {
212
+ var _a;
213
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfISOWeek) ? this.overrides.startOfISOWeek(date) : startOfISOWeek(date);
214
+ };
215
+ this.startOfMonth = (date) => {
216
+ var _a;
217
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfMonth) ? this.overrides.startOfMonth(date) : startOfMonth(date);
218
+ };
219
+ this.startOfWeek = (date) => {
220
+ var _a;
221
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfWeek) ? this.overrides.startOfWeek(date, this.options) : startOfWeek(date, this.options);
222
+ };
223
+ this.startOfYear = (date) => {
224
+ var _a;
225
+ return ((_a = this.overrides) == null ? void 0 : _a.startOfYear) ? this.overrides.startOfYear(date) : startOfYear(date);
226
+ };
227
+ this.options = { locale: enUS, ...options };
228
+ this.overrides = overrides;
229
+ }
230
+ }
231
+ const defaultDateLib = new DateLib();
232
+ function getClassNamesForModifiers(modifiers, classNames2, modifiersClassNames = {}) {
233
+ const modifierClassNames = Object.entries(modifiers).filter(([, active]) => active === true).reduce((previousValue, [key]) => {
234
+ if (modifiersClassNames[key]) {
235
+ previousValue.push(modifiersClassNames[key]);
236
+ } else if (classNames2[DayFlag[key]]) {
237
+ previousValue.push(classNames2[DayFlag[key]]);
238
+ } else if (classNames2[SelectionState[key]]) {
239
+ previousValue.push(classNames2[SelectionState[key]]);
33
240
  }
34
- return t;
241
+ return previousValue;
242
+ }, [classNames2[UI.Day]]);
243
+ return modifierClassNames;
244
+ }
245
+ function Button(props) {
246
+ return React.createElement("button", { ...props });
247
+ }
248
+ function CaptionLabel(props) {
249
+ return React.createElement("span", { ...props });
250
+ }
251
+ function Chevron(props) {
252
+ const { size = 24, orientation = "left", className } = props;
253
+ return React.createElement(
254
+ "svg",
255
+ { className, width: size, height: size, viewBox: "0 0 24 24" },
256
+ orientation === "up" && React.createElement("polygon", { points: "6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" }),
257
+ orientation === "down" && React.createElement("polygon", { points: "6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72" }),
258
+ orientation === "left" && React.createElement("polygon", { points: "16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" }),
259
+ orientation === "right" && React.createElement("polygon", { points: "8 18.612 14.1888889 12.5 8 6.37733333 9.91111111 4.5 18 12.5 9.91111111 20.5" })
260
+ );
261
+ }
262
+ function Day(props) {
263
+ const { day, modifiers, ...tdProps } = props;
264
+ return React.createElement("td", { ...tdProps });
265
+ }
266
+ function DayButton(props) {
267
+ const { day, modifiers, ...buttonProps } = props;
268
+ const ref = React.useRef(null);
269
+ React.useEffect(() => {
270
+ var _a;
271
+ if (modifiers.focused)
272
+ (_a = ref.current) == null ? void 0 : _a.focus();
273
+ }, [modifiers.focused]);
274
+ return React.createElement("button", { ref, ...buttonProps });
275
+ }
276
+ function Dropdown(props) {
277
+ const { options, className, components: components2, classNames: classNames2, ...selectProps } = props;
278
+ const cssClassSelect = [classNames2[UI.Dropdown], className].join(" ");
279
+ const selectedOption = options == null ? void 0 : options.find(({ value }) => value === selectProps.value);
280
+ return React.createElement(
281
+ "span",
282
+ { "data-disabled": selectProps.disabled, className: classNames2[UI.DropdownRoot] },
283
+ React.createElement(components2.Select, { className: cssClassSelect, ...selectProps }, options == null ? void 0 : options.map(({ value, label, disabled }) => React.createElement(components2.Option, { key: value, value, disabled }, label))),
284
+ React.createElement(
285
+ "span",
286
+ { className: classNames2[UI.CaptionLabel], "aria-hidden": true },
287
+ selectedOption == null ? void 0 : selectedOption.label,
288
+ React.createElement(components2.Chevron, { orientation: "down", size: 18, className: classNames2[UI.Chevron] })
289
+ )
290
+ );
291
+ }
292
+ function DropdownNav(props) {
293
+ return React.createElement("div", { ...props });
294
+ }
295
+ function Footer(props) {
296
+ return React.createElement("div", { ...props });
297
+ }
298
+ function Month(props) {
299
+ const { calendarMonth, displayIndex, ...divProps } = props;
300
+ return React.createElement("div", { ...divProps }, props.children);
301
+ }
302
+ function MonthCaption(props) {
303
+ const { calendarMonth, displayIndex, ...divProps } = props;
304
+ return React.createElement("div", { ...divProps });
305
+ }
306
+ function MonthGrid(props) {
307
+ return React.createElement("table", { ...props });
308
+ }
309
+ function Months(props) {
310
+ return React.createElement("div", { ...props });
311
+ }
312
+ const dayPickerContext = createContext(void 0);
313
+ function useDayPicker() {
314
+ const context = useContext(dayPickerContext);
315
+ if (context === void 0) {
316
+ throw new Error("useDayPicker() must be used within a custom component.");
317
+ }
318
+ return context;
319
+ }
320
+ function MonthsDropdown(props) {
321
+ const { components: components2 } = useDayPicker();
322
+ return React.createElement(components2.Dropdown, { ...props });
323
+ }
324
+ function Nav(props) {
325
+ const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props;
326
+ const { components: components2, classNames: classNames2, labels: { labelPrevious: labelPrevious2, labelNext: labelNext2 } } = useDayPicker();
327
+ return React.createElement(
328
+ "nav",
329
+ { ...navProps },
330
+ React.createElement(
331
+ components2.PreviousMonthButton,
332
+ { type: "button", className: classNames2[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, disabled: previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick: props.onPreviousClick },
333
+ React.createElement(components2.Chevron, { disabled: previousMonth ? void 0 : true, className: classNames2[UI.Chevron], orientation: "left" })
334
+ ),
335
+ React.createElement(
336
+ components2.NextMonthButton,
337
+ { type: "button", className: classNames2[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, disabled: nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick: props.onNextClick },
338
+ React.createElement(components2.Chevron, { disabled: nextMonth ? void 0 : true, orientation: "right", className: classNames2[UI.Chevron] })
339
+ )
340
+ );
341
+ }
342
+ function NextMonthButton(props) {
343
+ const { components: components2 } = useDayPicker();
344
+ return React.createElement(components2.Button, { ...props });
345
+ }
346
+ function Option(props) {
347
+ return React.createElement("option", { ...props });
348
+ }
349
+ function PreviousMonthButton(props) {
350
+ const { components: components2 } = useDayPicker();
351
+ return React.createElement(components2.Button, { ...props });
352
+ }
353
+ function Root(props) {
354
+ return React.createElement("div", { ...props });
355
+ }
356
+ function Select(props) {
357
+ return React.createElement("select", { ...props });
358
+ }
359
+ function Week(props) {
360
+ const { week, ...trProps } = props;
361
+ return React.createElement("tr", { ...trProps });
362
+ }
363
+ function Weekday(props) {
364
+ return React.createElement("th", { ...props });
365
+ }
366
+ function Weekdays(props) {
367
+ return React.createElement(
368
+ "thead",
369
+ { "aria-hidden": true },
370
+ React.createElement("tr", { ...props })
371
+ );
372
+ }
373
+ function WeekNumber(props) {
374
+ const { week, ...thProps } = props;
375
+ return React.createElement("th", { ...thProps });
376
+ }
377
+ function WeekNumberHeader(props) {
378
+ return React.createElement("th", { ...props });
379
+ }
380
+ function Weeks(props) {
381
+ return React.createElement("tbody", { ...props });
382
+ }
383
+ function YearsDropdown(props) {
384
+ const { components: components2 } = useDayPicker();
385
+ return React.createElement(components2.Dropdown, { ...props });
386
+ }
387
+ const components = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
388
+ __proto__: null,
389
+ Button,
390
+ CaptionLabel,
391
+ Chevron,
392
+ Day,
393
+ DayButton,
394
+ Dropdown,
395
+ DropdownNav,
396
+ Footer,
397
+ Month,
398
+ MonthCaption,
399
+ MonthGrid,
400
+ Months,
401
+ MonthsDropdown,
402
+ Nav,
403
+ NextMonthButton,
404
+ Option,
405
+ PreviousMonthButton,
406
+ Root,
407
+ Select,
408
+ Week,
409
+ WeekNumber,
410
+ WeekNumberHeader,
411
+ Weekday,
412
+ Weekdays,
413
+ Weeks,
414
+ YearsDropdown
415
+ }, Symbol.toStringTag, { value: "Module" }));
416
+ function getComponents(customComponents) {
417
+ return {
418
+ ...components,
419
+ ...customComponents
35
420
  };
36
- return __assign.apply(this, arguments);
37
- };
38
- function __rest(s, e) {
39
- var t = {};
40
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
- t[p] = s[p];
42
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
- t[p[i]] = s[p[i]];
46
- }
47
- return t;
48
421
  }
49
- function __spreadArray(to, from, pack) {
50
- for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
422
+ function getDataAttributes(props) {
423
+ const dataAttributes = {
424
+ "data-mode": props.mode ?? void 0,
425
+ "data-required": "required" in props ? props.required : void 0,
426
+ "data-multiple-months": props.numberOfMonths && props.numberOfMonths > 1 || void 0,
427
+ "data-week-numbers": props.showWeekNumber || void 0,
428
+ "data-broadcast-calendar": props.broadcastCalendar || void 0
429
+ };
430
+ Object.entries(props).forEach(([key, val]) => {
431
+ if (key.startsWith("data-")) {
432
+ dataAttributes[key] = val;
54
433
  }
434
+ });
435
+ return dataAttributes;
436
+ }
437
+ function getDefaultClassNames() {
438
+ const classNames2 = {};
439
+ for (const key in UI) {
440
+ classNames2[UI[key]] = `rdp-${UI[key]}`;
441
+ }
442
+ for (const key in DayFlag) {
443
+ classNames2[DayFlag[key]] = `rdp-${DayFlag[key]}`;
55
444
  }
56
- return to.concat(ar || Array.prototype.slice.call(from));
445
+ for (const key in SelectionState) {
446
+ classNames2[SelectionState[key]] = `rdp-${SelectionState[key]}`;
447
+ }
448
+ return classNames2;
57
449
  }
58
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
59
- var e = new Error(message);
60
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
61
- };
62
- function isDayPickerMultiple(props) {
63
- return props.mode === "multiple";
64
- }
65
- function isDayPickerRange(props) {
66
- return props.mode === "range";
67
- }
68
- function isDayPickerSingle(props) {
69
- return props.mode === "single";
70
- }
71
- var defaultClassNames = {
72
- root: "rdp",
73
- multiple_months: "rdp-multiple_months",
74
- with_weeknumber: "rdp-with_weeknumber",
75
- vhidden: "rdp-vhidden",
76
- button_reset: "rdp-button_reset",
77
- button: "rdp-button",
78
- caption: "rdp-caption",
79
- caption_start: "rdp-caption_start",
80
- caption_end: "rdp-caption_end",
81
- caption_between: "rdp-caption_between",
82
- caption_label: "rdp-caption_label",
83
- caption_dropdowns: "rdp-caption_dropdowns",
84
- dropdown: "rdp-dropdown",
85
- dropdown_month: "rdp-dropdown_month",
86
- dropdown_year: "rdp-dropdown_year",
87
- dropdown_icon: "rdp-dropdown_icon",
88
- months: "rdp-months",
89
- month: "rdp-month",
90
- table: "rdp-table",
91
- tbody: "rdp-tbody",
92
- tfoot: "rdp-tfoot",
93
- head: "rdp-head",
94
- head_row: "rdp-head_row",
95
- head_cell: "rdp-head_cell",
96
- nav: "rdp-nav",
97
- nav_button: "rdp-nav_button",
98
- nav_button_previous: "rdp-nav_button_previous",
99
- nav_button_next: "rdp-nav_button_next",
100
- nav_icon: "rdp-nav_icon",
101
- row: "rdp-row",
102
- weeknumber: "rdp-weeknumber",
103
- cell: "rdp-cell",
104
- day: "rdp-day",
105
- day_today: "rdp-day_today",
106
- day_outside: "rdp-day_outside",
107
- day_selected: "rdp-day_selected",
108
- day_disabled: "rdp-day_disabled",
109
- day_hidden: "rdp-day_hidden",
110
- day_range_start: "rdp-day_range_start",
111
- day_range_end: "rdp-day_range_end",
112
- day_range_middle: "rdp-day_range_middle"
113
- };
114
- function formatCaption(month, options) {
115
- return format(month, "LLLL y", options);
450
+ function formatCaption(month, options, dateLib) {
451
+ return (dateLib ?? new DateLib(options)).format(month, "LLLL y");
116
452
  }
117
- function formatDay(day, options) {
118
- return format(day, "d", options);
453
+ const formatMonthCaption = formatCaption;
454
+ function formatDay(date, options, dateLib) {
455
+ return (dateLib ?? new DateLib(options)).format(date, "d");
119
456
  }
120
- function formatMonthCaption(month, options) {
121
- return format(month, "LLLL", options);
457
+ function formatMonthDropdown(monthNumber, locale) {
458
+ var _a;
459
+ return (_a = locale.localize) == null ? void 0 : _a.month(monthNumber);
122
460
  }
123
461
  function formatWeekNumber(weekNumber) {
124
- return "".concat(weekNumber);
462
+ if (weekNumber < 10) {
463
+ return `0${weekNumber.toLocaleString()}`;
464
+ }
465
+ return `${weekNumber.toLocaleString()}`;
466
+ }
467
+ function formatWeekNumberHeader() {
468
+ return ``;
125
469
  }
126
- function formatWeekdayName(weekday, options) {
127
- return format(weekday, "cccccc", options);
470
+ function formatWeekdayName(weekday, options, dateLib) {
471
+ return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
128
472
  }
129
- function formatYearCaption(year, options) {
130
- return format(year, "yyyy", options);
473
+ function formatYearDropdown(year) {
474
+ return year.toString();
131
475
  }
132
- var formatters = /* @__PURE__ */ Object.freeze({
476
+ const formatYearCaption = formatYearDropdown;
477
+ const defaultFormatters = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
133
478
  __proto__: null,
134
479
  formatCaption,
135
480
  formatDay,
136
481
  formatMonthCaption,
482
+ formatMonthDropdown,
137
483
  formatWeekNumber,
484
+ formatWeekNumberHeader,
138
485
  formatWeekdayName,
139
- formatYearCaption
140
- });
141
- var labelDay = function(day, activeModifiers, options) {
142
- return format(day, "do MMMM (EEEE)", options);
143
- };
144
- var labelMonthDropdown = function() {
145
- return "Month: ";
146
- };
147
- var labelNext = function() {
148
- return "Go to next month";
149
- };
150
- var labelPrevious = function() {
151
- return "Go to previous month";
152
- };
153
- var labelWeekday = function(day, options) {
154
- return format(day, "cccc", options);
155
- };
156
- var labelWeekNumber = function(n) {
157
- return "Week n. ".concat(n);
158
- };
159
- var labelYearDropdown = function() {
160
- return "Year: ";
161
- };
162
- var labels = /* @__PURE__ */ Object.freeze({
163
- __proto__: null,
164
- labelDay,
165
- labelMonthDropdown,
166
- labelNext,
167
- labelPrevious,
168
- labelWeekNumber,
169
- labelWeekday,
170
- labelYearDropdown
171
- });
172
- function getDefaultContextValues() {
173
- var captionLayout = "buttons";
174
- var classNames2 = defaultClassNames;
175
- var locale = enUS;
176
- var modifiersClassNames = {};
177
- var modifiers = {};
178
- var numberOfMonths = 1;
179
- var styles2 = {};
180
- var today = /* @__PURE__ */ new Date();
486
+ formatYearCaption,
487
+ formatYearDropdown
488
+ }, Symbol.toStringTag, { value: "Module" }));
489
+ function getFormatters(customFormatters) {
490
+ if ((customFormatters == null ? void 0 : customFormatters.formatMonthCaption) && !customFormatters.formatCaption) {
491
+ customFormatters.formatCaption = customFormatters.formatMonthCaption;
492
+ }
493
+ if ((customFormatters == null ? void 0 : customFormatters.formatYearCaption) && !customFormatters.formatYearDropdown) {
494
+ customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
495
+ }
181
496
  return {
182
- captionLayout,
183
- classNames: classNames2,
184
- formatters,
185
- labels,
186
- locale,
187
- modifiersClassNames,
188
- modifiers,
189
- numberOfMonths,
190
- styles: styles2,
191
- today,
192
- mode: "default"
497
+ ...defaultFormatters,
498
+ ...customFormatters
193
499
  };
194
500
  }
195
- function parseFromToProps(props) {
196
- var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
197
- var fromDate = props.fromDate, toDate = props.toDate;
198
- if (fromMonth) {
199
- fromDate = startOfMonth(fromMonth);
200
- } else if (fromYear) {
201
- fromDate = new Date(fromYear, 0, 1);
501
+ function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
502
+ if (!navStart)
503
+ return void 0;
504
+ if (!navEnd)
505
+ return void 0;
506
+ const { addMonths: addMonths2, startOfMonth: startOfMonth2 } = dateLib;
507
+ const year = displayMonth.getFullYear();
508
+ const months = [];
509
+ let month = navStart;
510
+ while (months.length < 12) {
511
+ months.push(month.getMonth());
512
+ month = addMonths2(month, 1);
513
+ }
514
+ const sortedMonths = months.sort((a, b) => {
515
+ return a - b;
516
+ });
517
+ const options = sortedMonths.map((value) => {
518
+ const label = formatters.formatMonthDropdown(value, dateLib.options.locale ?? enUS$1);
519
+ const month2 = dateLib.Date ? new dateLib.Date(year, value) : new Date(year, value);
520
+ const disabled = navStart && month2 < startOfMonth2(navStart) || navEnd && month2 > startOfMonth2(navEnd) || false;
521
+ return { value, label, disabled };
522
+ });
523
+ return options;
524
+ }
525
+ function getStyleForModifiers(dayModifiers, styles2 = {}, modifiersStyles = {}) {
526
+ let style = { ...styles2 == null ? void 0 : styles2[UI.Day] };
527
+ Object.entries(dayModifiers).filter(([, active]) => active === true).forEach(([modifier]) => {
528
+ style = {
529
+ ...style,
530
+ ...modifiersStyles == null ? void 0 : modifiersStyles[modifier]
531
+ };
532
+ });
533
+ return style;
534
+ }
535
+ const offsetFormatCache = {};
536
+ const offsetCache = {};
537
+ function tzOffset(timeZone, date) {
538
+ try {
539
+ const format2 = offsetFormatCache[timeZone] || (offsetFormatCache[timeZone] = new Intl.DateTimeFormat("en-GB", {
540
+ timeZone,
541
+ hour: "numeric",
542
+ timeZoneName: "longOffset"
543
+ }).format);
544
+ const offsetStr = format2(date).split("GMT")[1] || "";
545
+ if (offsetStr in offsetCache) return offsetCache[offsetStr];
546
+ return calcOffset(offsetStr, offsetStr.split(":"));
547
+ } catch {
548
+ if (timeZone in offsetCache) return offsetCache[timeZone];
549
+ const captures = timeZone == null ? void 0 : timeZone.match(offsetRe);
550
+ if (captures) return calcOffset(timeZone, captures.slice(1));
551
+ return NaN;
552
+ }
553
+ }
554
+ const offsetRe = /([+-]\d\d):?(\d\d)?/;
555
+ function calcOffset(cacheStr, values) {
556
+ const hours = +values[0];
557
+ const minutes = +(values[1] || 0);
558
+ return offsetCache[cacheStr] = hours > 0 ? hours * 60 + minutes : hours * 60 - minutes;
559
+ }
560
+ class TZDateMini extends Date {
561
+ //#region static
562
+ constructor(...args) {
563
+ super();
564
+ if (args.length > 1 && typeof args[args.length - 1] === "string") {
565
+ this.timeZone = args.pop();
566
+ }
567
+ this.internal = /* @__PURE__ */ new Date();
568
+ if (isNaN(tzOffset(this.timeZone, this))) {
569
+ this.setTime(NaN);
570
+ } else {
571
+ if (!args.length) {
572
+ this.setTime(Date.now());
573
+ } else if (typeof args[0] === "number" && (args.length === 1 || args.length === 2 && typeof args[1] !== "number")) {
574
+ this.setTime(args[0]);
575
+ } else if (typeof args[0] === "string") {
576
+ this.setTime(+new Date(args[0]));
577
+ } else if (args[0] instanceof Date) {
578
+ this.setTime(+args[0]);
579
+ } else {
580
+ this.setTime(+new Date(...args));
581
+ adjustToSystemTZ(this);
582
+ syncToInternal(this);
583
+ }
584
+ }
202
585
  }
203
- if (toMonth) {
204
- toDate = endOfMonth(toMonth);
205
- } else if (toYear) {
206
- toDate = new Date(toYear, 11, 31);
586
+ static tz(tz, ...args) {
587
+ return args.length ? new TZDateMini(...args, tz) : new TZDateMini(Date.now(), tz);
207
588
  }
208
- return {
209
- fromDate: fromDate ? startOfDay(fromDate) : void 0,
210
- toDate: toDate ? startOfDay(toDate) : void 0
211
- };
589
+ //#endregion
590
+ //#region time zone
591
+ withTimeZone(timeZone) {
592
+ return new TZDateMini(+this, timeZone);
593
+ }
594
+ getTimezoneOffset() {
595
+ return -tzOffset(this.timeZone, this);
596
+ }
597
+ //#endregion
598
+ //#region time
599
+ setTime(time) {
600
+ Date.prototype.setTime.apply(this, arguments);
601
+ syncToInternal(this);
602
+ return +this;
603
+ }
604
+ //#endregion
605
+ //#region date-fns integration
606
+ [Symbol.for("constructDateFrom")](date) {
607
+ return new TZDateMini(+new Date(date), this.timeZone);
608
+ }
609
+ //#endregion
212
610
  }
213
- var DayPickerContext = createContext(void 0);
214
- function DayPickerProvider(props) {
215
- var _a;
216
- var initialProps = props.initialProps;
217
- var defaultContextValues = getDefaultContextValues();
218
- var _b = parseFromToProps(initialProps), fromDate = _b.fromDate, toDate = _b.toDate;
219
- var captionLayout = (_a = initialProps.captionLayout) !== null && _a !== void 0 ? _a : defaultContextValues.captionLayout;
220
- if (captionLayout !== "buttons" && (!fromDate || !toDate)) {
221
- captionLayout = "buttons";
611
+ const re = /^(get|set)(?!UTC)/;
612
+ Object.getOwnPropertyNames(Date.prototype).forEach((method) => {
613
+ if (!re.test(method)) return;
614
+ const utcMethod = method.replace(re, "$1UTC");
615
+ if (!TZDateMini.prototype[utcMethod]) return;
616
+ if (method.startsWith("get")) {
617
+ TZDateMini.prototype[method] = function() {
618
+ return this.internal[utcMethod]();
619
+ };
620
+ } else {
621
+ TZDateMini.prototype[method] = function() {
622
+ Date.prototype[utcMethod].apply(this.internal, arguments);
623
+ syncFromInternal(this);
624
+ return +this;
625
+ };
626
+ TZDateMini.prototype[utcMethod] = function() {
627
+ Date.prototype[utcMethod].apply(this, arguments);
628
+ syncToInternal(this);
629
+ return +this;
630
+ };
631
+ }
632
+ });
633
+ function syncToInternal(date) {
634
+ date.internal.setTime(+date);
635
+ date.internal.setUTCMinutes(date.internal.getUTCMinutes() - date.getTimezoneOffset());
636
+ }
637
+ function syncFromInternal(date) {
638
+ Date.prototype.setFullYear.call(date, date.internal.getUTCFullYear(), date.internal.getUTCMonth(), date.internal.getUTCDate());
639
+ Date.prototype.setHours.call(date, date.internal.getUTCHours(), date.internal.getUTCMinutes(), date.internal.getUTCSeconds(), date.internal.getUTCMilliseconds());
640
+ adjustToSystemTZ(date);
641
+ }
642
+ function adjustToSystemTZ(date) {
643
+ const offset = tzOffset(date.timeZone, date);
644
+ const prevHour = /* @__PURE__ */ new Date(+date);
645
+ prevHour.setUTCHours(prevHour.getUTCHours() - 1);
646
+ const systemOffset = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset();
647
+ const prevHourSystemOffset = -(/* @__PURE__ */ new Date(+prevHour)).getTimezoneOffset();
648
+ const systemDSTChange = systemOffset - prevHourSystemOffset;
649
+ const dstShift = Date.prototype.getHours.apply(date) !== date.internal.getUTCHours();
650
+ if (systemDSTChange && dstShift) date.internal.setUTCMinutes(date.internal.getUTCMinutes() + systemDSTChange);
651
+ const offsetDiff = systemOffset - offset;
652
+ if (offsetDiff) Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetDiff);
653
+ const postOffset = tzOffset(date.timeZone, date);
654
+ const postSystemOffset = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset();
655
+ const postOffsetDiff = postSystemOffset - postOffset;
656
+ const offsetChanged = postOffset !== offset;
657
+ const postDiff = postOffsetDiff - offsetDiff;
658
+ if (offsetChanged && postDiff) {
659
+ Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + postDiff);
660
+ const newOffset = tzOffset(date.timeZone, date);
661
+ const offsetChange = postOffset - newOffset;
662
+ if (offsetChange) {
663
+ date.internal.setUTCMinutes(date.internal.getUTCMinutes() + offsetChange);
664
+ Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetChange);
665
+ }
666
+ }
667
+ }
668
+ class TZDate extends TZDateMini {
669
+ //#region static
670
+ static tz(tz, ...args) {
671
+ return args.length ? new TZDate(...args, tz) : new TZDate(Date.now(), tz);
672
+ }
673
+ //#endregion
674
+ //#region representation
675
+ toISOString() {
676
+ const [sign, hours, minutes] = this.tzComponents();
677
+ const tz = `${sign}${hours}:${minutes}`;
678
+ return this.internal.toISOString().slice(0, -1) + tz;
679
+ }
680
+ toString() {
681
+ return `${this.toDateString()} ${this.toTimeString()}`;
682
+ }
683
+ toDateString() {
684
+ const [day, date, month, year] = this.internal.toUTCString().split(" ");
685
+ return `${day == null ? void 0 : day.slice(0, -1)} ${month} ${date} ${year}`;
686
+ }
687
+ toTimeString() {
688
+ const time = this.internal.toUTCString().split(" ")[4];
689
+ const [sign, hours, minutes] = this.tzComponents();
690
+ return `${time} GMT${sign}${hours}${minutes} (${tzName(this.timeZone, this)})`;
691
+ }
692
+ toLocaleString(locales, options) {
693
+ return Date.prototype.toLocaleString.call(this, locales, {
694
+ ...options,
695
+ timeZone: (options == null ? void 0 : options.timeZone) || this.timeZone
696
+ });
222
697
  }
223
- var onSelect;
224
- if (isDayPickerSingle(initialProps) || isDayPickerMultiple(initialProps) || isDayPickerRange(initialProps)) {
225
- onSelect = initialProps.onSelect;
698
+ toLocaleDateString(locales, options) {
699
+ return Date.prototype.toLocaleDateString.call(this, locales, {
700
+ ...options,
701
+ timeZone: (options == null ? void 0 : options.timeZone) || this.timeZone
702
+ });
226
703
  }
227
- var value = __assign(__assign(__assign({}, defaultContextValues), initialProps), { captionLayout, classNames: __assign(__assign({}, defaultContextValues.classNames), initialProps.classNames), components: __assign({}, initialProps.components), formatters: __assign(__assign({}, defaultContextValues.formatters), initialProps.formatters), fromDate, labels: __assign(__assign({}, defaultContextValues.labels), initialProps.labels), mode: initialProps.mode || defaultContextValues.mode, modifiers: __assign(__assign({}, defaultContextValues.modifiers), initialProps.modifiers), modifiersClassNames: __assign(__assign({}, defaultContextValues.modifiersClassNames), initialProps.modifiersClassNames), onSelect, styles: __assign(__assign({}, defaultContextValues.styles), initialProps.styles), toDate });
228
- return jsx(DayPickerContext.Provider, { value, children: props.children });
704
+ toLocaleTimeString(locales, options) {
705
+ return Date.prototype.toLocaleTimeString.call(this, locales, {
706
+ ...options,
707
+ timeZone: (options == null ? void 0 : options.timeZone) || this.timeZone
708
+ });
709
+ }
710
+ //#endregion
711
+ //#region private
712
+ tzComponents() {
713
+ const offset = this.getTimezoneOffset();
714
+ const sign = offset > 0 ? "-" : "+";
715
+ const hours = String(Math.floor(Math.abs(offset) / 60)).padStart(2, "0");
716
+ const minutes = String(Math.abs(offset) % 60).padStart(2, "0");
717
+ return [sign, hours, minutes];
718
+ }
719
+ //#endregion
720
+ withTimeZone(timeZone) {
721
+ return new TZDate(+this, timeZone);
722
+ }
723
+ //#region date-fns integration
724
+ [Symbol.for("constructDateFrom")](date) {
725
+ return new TZDate(+new Date(date), this.timeZone);
726
+ }
727
+ //#endregion
728
+ }
729
+ function tzName(tz, date) {
730
+ return new Intl.DateTimeFormat("en-GB", {
731
+ timeZone: tz,
732
+ timeZoneName: "long"
733
+ }).format(date).slice(12);
734
+ }
735
+ function getWeekdays(dateLib, ISOWeek, timeZone, broadcastCalendar) {
736
+ const date = timeZone ? TZDate.tz(timeZone) : dateLib.Date ? new dateLib.Date() : /* @__PURE__ */ new Date();
737
+ const start = ISOWeek ? dateLib.startOfISOWeek(date) : dateLib.startOfWeek(date);
738
+ const days = [];
739
+ for (let i = 0; i < 7; i++) {
740
+ const day = dateLib.addDays(start, i);
741
+ days.push(day);
742
+ }
743
+ return days;
229
744
  }
230
- function useDayPicker() {
231
- var context = useContext(DayPickerContext);
232
- if (!context) {
233
- throw new Error("useDayPicker must be used within a DayPickerProvider.");
745
+ function getYearOptions(navStart, navEnd, formatters, dateLib) {
746
+ if (!navStart)
747
+ return void 0;
748
+ if (!navEnd)
749
+ return void 0;
750
+ const { startOfYear: startOfYear2, endOfYear: endOfYear2, addYears: addYears2, isBefore: isBefore2, isSameYear: isSameYear2 } = dateLib;
751
+ const firstNavYear = startOfYear2(navStart);
752
+ const lastNavYear = endOfYear2(navEnd);
753
+ const years = [];
754
+ let year = firstNavYear;
755
+ while (isBefore2(year, lastNavYear) || isSameYear2(year, lastNavYear)) {
756
+ years.push(year.getFullYear());
757
+ year = addYears2(year, 1);
758
+ }
759
+ return years.map((value) => {
760
+ const label = formatters.formatYearDropdown(value);
761
+ return {
762
+ value,
763
+ label,
764
+ disabled: false
765
+ };
766
+ });
767
+ }
768
+ function labelGrid(date, options, dateLib) {
769
+ return (dateLib ?? new DateLib(options)).format(date, "LLLL y");
770
+ }
771
+ const labelCaption = labelGrid;
772
+ function labelGridcell(date, modifiers, options, dateLib) {
773
+ let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
774
+ if (modifiers == null ? void 0 : modifiers.today) {
775
+ label = `Today, ${label}`;
234
776
  }
235
- return context;
777
+ return label;
236
778
  }
237
- function CaptionLabel(props) {
238
- var _a = useDayPicker(), locale = _a.locale, classNames2 = _a.classNames, styles2 = _a.styles, formatCaption2 = _a.formatters.formatCaption;
239
- return jsx("div", { className: classNames2.caption_label, style: styles2.caption_label, "aria-live": "polite", role: "presentation", id: props.id, children: formatCaption2(props.displayMonth, { locale }) });
779
+ function labelDayButton(date, modifiers, options, dateLib) {
780
+ let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
781
+ if (modifiers.today)
782
+ label = `Today, ${label}`;
783
+ if (modifiers.selected)
784
+ label = `${label}, selected`;
785
+ return label;
240
786
  }
241
- function IconDropdown(props) {
242
- return jsx("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props, { children: jsx("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" }) }));
787
+ const labelDay = labelDayButton;
788
+ function labelNav() {
789
+ return "";
243
790
  }
244
- function Dropdown(props) {
245
- var _a, _b;
246
- var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
247
- var dayPicker = useDayPicker();
248
- var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
249
- return jsxs("div", { className, style, children: [jsx("span", { className: dayPicker.classNames.vhidden, children: props["aria-label"] }), jsx("select", { name: props.name, "aria-label": props["aria-label"], className: dayPicker.classNames.dropdown, style: dayPicker.styles.dropdown, value, onChange, children }), jsxs("div", { className: dayPicker.classNames.caption_label, style: dayPicker.styles.caption_label, "aria-hidden": "true", children: [caption, jsx(IconDropdownComponent, { className: dayPicker.classNames.dropdown_icon, style: dayPicker.styles.dropdown_icon })] })] });
791
+ function labelMonthDropdown(options) {
792
+ return "Choose the Month";
250
793
  }
251
- function MonthsDropdown(props) {
252
- var _a;
253
- var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, styles2 = _b.styles, locale = _b.locale, formatMonthCaption2 = _b.formatters.formatMonthCaption, classNames2 = _b.classNames, components = _b.components, labelMonthDropdown2 = _b.labels.labelMonthDropdown;
254
- if (!fromDate)
255
- return jsx(Fragment, {});
256
- if (!toDate)
257
- return jsx(Fragment, {});
258
- var dropdownMonths = [];
259
- if (isSameYear(fromDate, toDate)) {
260
- var date = startOfMonth(fromDate);
261
- for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
262
- dropdownMonths.push(setMonth(date, month));
263
- }
264
- } else {
265
- var date = startOfMonth(/* @__PURE__ */ new Date());
266
- for (var month = 0; month <= 11; month++) {
267
- dropdownMonths.push(setMonth(date, month));
268
- }
269
- }
270
- var handleChange = function(e) {
271
- var selectedMonth = Number(e.target.value);
272
- var newMonth = setMonth(startOfMonth(props.displayMonth), selectedMonth);
273
- props.onChange(newMonth);
274
- };
275
- var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
276
- return jsx(DropdownComponent, { name: "months", "aria-label": labelMonthDropdown2(), className: classNames2.dropdown_month, style: styles2.dropdown_month, onChange: handleChange, value: props.displayMonth.getMonth(), caption: formatMonthCaption2(props.displayMonth, { locale }), children: dropdownMonths.map(function(m) {
277
- return jsx("option", { value: m.getMonth(), children: formatMonthCaption2(m, { locale }) }, m.getMonth());
278
- }) });
794
+ function labelNext(month) {
795
+ return "Go to the Next Month";
279
796
  }
280
- function YearsDropdown(props) {
281
- var _a;
282
- var displayMonth = props.displayMonth;
283
- var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, locale = _b.locale, styles2 = _b.styles, classNames2 = _b.classNames, components = _b.components, formatYearCaption2 = _b.formatters.formatYearCaption, labelYearDropdown2 = _b.labels.labelYearDropdown;
284
- var years = [];
285
- if (!fromDate)
286
- return jsx(Fragment, {});
287
- if (!toDate)
288
- return jsx(Fragment, {});
289
- var fromYear = fromDate.getFullYear();
290
- var toYear = toDate.getFullYear();
291
- for (var year = fromYear; year <= toYear; year++) {
292
- years.push(setYear(startOfYear(/* @__PURE__ */ new Date()), year));
293
- }
294
- var handleChange = function(e) {
295
- var newMonth = setYear(startOfMonth(displayMonth), Number(e.target.value));
296
- props.onChange(newMonth);
297
- };
298
- var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
299
- return jsx(DropdownComponent, { name: "years", "aria-label": labelYearDropdown2(), className: classNames2.dropdown_year, style: styles2.dropdown_year, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption2(displayMonth, { locale }), children: years.map(function(year2) {
300
- return jsx("option", { value: year2.getFullYear(), children: formatYearCaption2(year2, { locale }) }, year2.getFullYear());
301
- }) });
797
+ function labelPrevious(month) {
798
+ return "Go to the Previous Month";
302
799
  }
303
- function useControlledValue(defaultValue, controlledValue) {
304
- var _a = useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
305
- var value = controlledValue === void 0 ? uncontrolledValue : controlledValue;
306
- return [value, setValue];
800
+ function labelWeekday(date, options, dateLib) {
801
+ return (dateLib ?? new DateLib(options)).format(date, "cccc");
307
802
  }
308
- function getInitialMonth(context) {
309
- var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
310
- var initialMonth = month || defaultMonth || today || /* @__PURE__ */ new Date();
311
- var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
312
- if (toDate && differenceInCalendarMonths(toDate, initialMonth) < 0) {
313
- var offset = -1 * (numberOfMonths - 1);
314
- initialMonth = addMonths(toDate, offset);
315
- }
316
- if (fromDate && differenceInCalendarMonths(initialMonth, fromDate) < 0) {
317
- initialMonth = fromDate;
318
- }
319
- return startOfMonth(initialMonth);
320
- }
321
- function useNavigationState() {
322
- var context = useDayPicker();
323
- var initialMonth = getInitialMonth(context);
324
- var _a = useControlledValue(initialMonth, context.month), month = _a[0], setMonth2 = _a[1];
325
- var goToMonth = function(date) {
326
- var _a2;
327
- if (context.disableNavigation)
328
- return;
329
- var month2 = startOfMonth(date);
330
- setMonth2(month2);
331
- (_a2 = context.onMonthChange) === null || _a2 === void 0 ? void 0 : _a2.call(context, month2);
332
- };
333
- return [month, goToMonth];
334
- }
335
- function getDisplayMonths(month, _a) {
336
- var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
337
- var start = startOfMonth(month);
338
- var end = startOfMonth(addMonths(start, numberOfMonths));
339
- var monthsDiff = differenceInCalendarMonths(end, start);
340
- var months = [];
341
- for (var i = 0; i < monthsDiff; i++) {
342
- var nextMonth = addMonths(start, i);
343
- months.push(nextMonth);
344
- }
345
- if (reverseMonths)
346
- months = months.reverse();
803
+ function labelWeekNumber(weekNumber, options) {
804
+ return `Week ${weekNumber}`;
805
+ }
806
+ function labelWeekNumberHeader(options) {
807
+ return "Week Number";
808
+ }
809
+ function labelYearDropdown(options) {
810
+ return "Choose the Year";
811
+ }
812
+ const defaultLabels = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
813
+ __proto__: null,
814
+ labelCaption,
815
+ labelDay,
816
+ labelDayButton,
817
+ labelGrid,
818
+ labelGridcell,
819
+ labelMonthDropdown,
820
+ labelNav,
821
+ labelNext,
822
+ labelPrevious,
823
+ labelWeekNumber,
824
+ labelWeekNumberHeader,
825
+ labelWeekday,
826
+ labelYearDropdown
827
+ }, Symbol.toStringTag, { value: "Module" }));
828
+ function getDates(displayMonths, maxDate, props, dateLib) {
829
+ const firstMonth = displayMonths[0];
830
+ const lastMonth = displayMonths[displayMonths.length - 1];
831
+ const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
832
+ const { addDays: addDays2, differenceInCalendarDays: differenceInCalendarDays2, differenceInCalendarMonths: differenceInCalendarMonths2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, isAfter: isAfter2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
833
+ const startWeekFirstDate = broadcastCalendar ? startOfBroadcastWeek2(firstMonth, dateLib) : ISOWeek ? startOfISOWeek2(firstMonth) : startOfWeek2(firstMonth);
834
+ const endWeekLastDate = broadcastCalendar ? endOfBroadcastWeek2(lastMonth, dateLib) : ISOWeek ? endOfISOWeek2(endOfMonth2(lastMonth)) : endOfWeek2(endOfMonth2(lastMonth));
835
+ const nOfDays = differenceInCalendarDays2(endWeekLastDate, startWeekFirstDate);
836
+ const nOfMonths = differenceInCalendarMonths2(lastMonth, firstMonth) + 1;
837
+ const dates = [];
838
+ for (let i = 0; i <= nOfDays; i++) {
839
+ const date = addDays2(startWeekFirstDate, i);
840
+ if (maxDate && isAfter2(date, maxDate)) {
841
+ break;
842
+ }
843
+ dates.push(date);
844
+ }
845
+ const nrOfDaysWithFixedWeeks = broadcastCalendar ? 35 : 42;
846
+ const extraDates = nrOfDaysWithFixedWeeks * nOfMonths;
847
+ if (fixedWeeks && dates.length < extraDates) {
848
+ const daysToAdd = extraDates - dates.length;
849
+ for (let i = 0; i < daysToAdd; i++) {
850
+ const date = addDays2(dates[dates.length - 1], 1);
851
+ dates.push(date);
852
+ }
853
+ }
854
+ return dates;
855
+ }
856
+ function getDays(calendarMonths) {
857
+ const initialDays = [];
858
+ return calendarMonths.reduce((days, month) => {
859
+ const initialDays2 = [];
860
+ const weekDays = month.weeks.reduce((weekDays2, week) => {
861
+ return [...weekDays2, ...week.days];
862
+ }, initialDays2);
863
+ return [...days, ...weekDays];
864
+ }, initialDays);
865
+ }
866
+ function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib) {
867
+ const { numberOfMonths = 1 } = props;
868
+ const months = [];
869
+ for (let i = 0; i < numberOfMonths; i++) {
870
+ const month = dateLib.addMonths(firstDisplayedMonth, i);
871
+ if (calendarEndMonth && month > calendarEndMonth) {
872
+ break;
873
+ }
874
+ months.push(month);
875
+ }
347
876
  return months;
348
877
  }
349
- function getNextMonth(startingMonth, options) {
878
+ function getInitialMonth(props, dateLib) {
879
+ const { month, defaultMonth, today = props.timeZone ? TZDate.tz(props.timeZone) : dateLib.Date ? new dateLib.Date() : /* @__PURE__ */ new Date(), numberOfMonths = 1, endMonth, startMonth } = props;
880
+ let initialMonth = month || defaultMonth || today;
881
+ const { differenceInCalendarMonths: differenceInCalendarMonths2, addMonths: addMonths2, startOfMonth: startOfMonth2 } = dateLib;
882
+ if (endMonth && differenceInCalendarMonths2(endMonth, initialMonth) < 0) {
883
+ const offset = -1 * (numberOfMonths - 1);
884
+ initialMonth = addMonths2(endMonth, offset);
885
+ }
886
+ if (startMonth && differenceInCalendarMonths2(initialMonth, startMonth) < 0) {
887
+ initialMonth = startMonth;
888
+ }
889
+ return startOfMonth2(initialMonth);
890
+ }
891
+ class CalendarDay {
892
+ constructor(date, displayMonth, dateLib = defaultDateLib) {
893
+ this.date = date;
894
+ this.displayMonth = displayMonth;
895
+ this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
896
+ this.dateLib = dateLib;
897
+ }
898
+ /**
899
+ * Check if the day is the same as the given day: considering if it is in the
900
+ * same display month.
901
+ */
902
+ isEqualTo(day) {
903
+ return this.dateLib.isSameDay(day.date, this.date) && this.dateLib.isSameMonth(day.displayMonth, this.displayMonth);
904
+ }
905
+ }
906
+ class CalendarMonth {
907
+ constructor(month, weeks) {
908
+ this.date = month;
909
+ this.weeks = weeks;
910
+ }
911
+ }
912
+ class CalendarWeek {
913
+ constructor(weekNumber, days) {
914
+ this.days = days;
915
+ this.weekNumber = weekNumber;
916
+ }
917
+ }
918
+ function getMonths(displayMonths, dates, props, dateLib) {
919
+ const { addDays: addDays2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, getISOWeek: getISOWeek2, getWeek: getWeek2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
920
+ const dayPickerMonths = displayMonths.reduce((months, month) => {
921
+ const firstDateOfFirstWeek = props.broadcastCalendar ? startOfBroadcastWeek2(month, dateLib) : props.ISOWeek ? startOfISOWeek2(month) : startOfWeek2(month);
922
+ const lastDateOfLastWeek = props.broadcastCalendar ? endOfBroadcastWeek2(month, dateLib) : props.ISOWeek ? endOfISOWeek2(endOfMonth2(month)) : endOfWeek2(endOfMonth2(month));
923
+ const monthDates = dates.filter((date) => {
924
+ return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
925
+ });
926
+ const nrOfDaysWithFixedWeeks = props.broadcastCalendar ? 35 : 42;
927
+ if (props.fixedWeeks && monthDates.length < nrOfDaysWithFixedWeeks) {
928
+ const extraDates = dates.filter((date) => {
929
+ const daysToAdd = nrOfDaysWithFixedWeeks - monthDates.length;
930
+ return date > lastDateOfLastWeek && date <= addDays2(lastDateOfLastWeek, daysToAdd);
931
+ });
932
+ monthDates.push(...extraDates);
933
+ }
934
+ const weeks = monthDates.reduce((weeks2, date) => {
935
+ const weekNumber = props.ISOWeek ? getISOWeek2(date) : getWeek2(date);
936
+ const week = weeks2.find((week2) => week2.weekNumber === weekNumber);
937
+ const day = new CalendarDay(date, month, dateLib);
938
+ if (!week) {
939
+ weeks2.push(new CalendarWeek(weekNumber, [day]));
940
+ } else {
941
+ week.days.push(day);
942
+ }
943
+ return weeks2;
944
+ }, []);
945
+ const dayPickerMonth = new CalendarMonth(month, weeks);
946
+ months.push(dayPickerMonth);
947
+ return months;
948
+ }, []);
949
+ if (!props.reverseMonths) {
950
+ return dayPickerMonths;
951
+ } else {
952
+ return dayPickerMonths.reverse();
953
+ }
954
+ }
955
+ function getNavMonths(props, dateLib) {
956
+ var _a;
957
+ let { startMonth, endMonth } = props;
958
+ const { startOfYear: startOfYear2, startOfDay: startOfDay2, startOfMonth: startOfMonth2, endOfMonth: endOfMonth2, addYears: addYears2, endOfYear: endOfYear2 } = dateLib;
959
+ const { fromYear, toYear, fromMonth, toMonth } = props;
960
+ if (!startMonth && fromMonth) {
961
+ startMonth = fromMonth;
962
+ }
963
+ if (!startMonth && fromYear) {
964
+ startMonth = new Date(fromYear, 0, 1);
965
+ }
966
+ if (!endMonth && toMonth) {
967
+ endMonth = toMonth;
968
+ }
969
+ if (!endMonth && toYear) {
970
+ endMonth = new Date(toYear, 11, 31);
971
+ }
972
+ const hasDropdowns = (_a = props.captionLayout) == null ? void 0 : _a.startsWith("dropdown");
973
+ if (startMonth) {
974
+ startMonth = startOfMonth2(startMonth);
975
+ } else if (fromYear) {
976
+ startMonth = new Date(fromYear, 0, 1);
977
+ } else if (!startMonth && hasDropdowns) {
978
+ const today = props.today ?? (props.timeZone ? TZDate.tz(props.timeZone) : dateLib.Date ? new dateLib.Date() : /* @__PURE__ */ new Date());
979
+ startMonth = startOfYear2(addYears2(today, -100));
980
+ }
981
+ if (endMonth) {
982
+ endMonth = endOfMonth2(endMonth);
983
+ } else if (toYear) {
984
+ endMonth = new Date(toYear, 11, 31);
985
+ } else if (!endMonth && hasDropdowns) {
986
+ const today = props.today ?? (props.timeZone ? TZDate.tz(props.timeZone) : dateLib.Date ? new dateLib.Date() : /* @__PURE__ */ new Date());
987
+ endMonth = endOfYear2(today);
988
+ }
989
+ return [
990
+ startMonth ? startOfDay2(startMonth) : startMonth,
991
+ endMonth ? startOfDay2(endMonth) : endMonth
992
+ ];
993
+ }
994
+ function getNextMonth(firstDisplayedMonth, calendarEndMonth, options, dateLib) {
350
995
  if (options.disableNavigation) {
351
996
  return void 0;
352
997
  }
353
- var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
354
- var offset = pagedNavigation ? numberOfMonths : 1;
355
- var month = startOfMonth(startingMonth);
356
- if (!toDate) {
357
- return addMonths(month, offset);
998
+ const { pagedNavigation, numberOfMonths = 1 } = options;
999
+ const { startOfMonth: startOfMonth2, addMonths: addMonths2, differenceInCalendarMonths: differenceInCalendarMonths2 } = dateLib;
1000
+ const offset = pagedNavigation ? numberOfMonths : 1;
1001
+ const month = startOfMonth2(firstDisplayedMonth);
1002
+ if (!calendarEndMonth) {
1003
+ return addMonths2(month, offset);
358
1004
  }
359
- var monthsDiff = differenceInCalendarMonths(toDate, startingMonth);
1005
+ const monthsDiff = differenceInCalendarMonths2(calendarEndMonth, firstDisplayedMonth);
360
1006
  if (monthsDiff < numberOfMonths) {
361
1007
  return void 0;
362
1008
  }
363
- return addMonths(month, offset);
1009
+ return addMonths2(month, offset);
364
1010
  }
365
- function getPreviousMonth(startingMonth, options) {
1011
+ function getPreviousMonth(firstDisplayedMonth, calendarStartMonth, options, dateLib) {
366
1012
  if (options.disableNavigation) {
367
1013
  return void 0;
368
1014
  }
369
- var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
370
- var offset = pagedNavigation ? numberOfMonths : 1;
371
- var month = startOfMonth(startingMonth);
372
- if (!fromDate) {
373
- return addMonths(month, -offset);
1015
+ const { pagedNavigation, numberOfMonths } = options;
1016
+ const { startOfMonth: startOfMonth2, addMonths: addMonths2, differenceInCalendarMonths: differenceInCalendarMonths2 } = dateLib;
1017
+ const offset = pagedNavigation ? numberOfMonths ?? 1 : 1;
1018
+ const month = startOfMonth2(firstDisplayedMonth);
1019
+ if (!calendarStartMonth) {
1020
+ return addMonths2(month, -offset);
374
1021
  }
375
- var monthsDiff = differenceInCalendarMonths(month, fromDate);
1022
+ const monthsDiff = differenceInCalendarMonths2(month, calendarStartMonth);
376
1023
  if (monthsDiff <= 0) {
377
1024
  return void 0;
378
1025
  }
379
- return addMonths(month, -offset);
380
- }
381
- var NavigationContext = createContext(void 0);
382
- function NavigationProvider(props) {
383
- var dayPicker = useDayPicker();
384
- var _a = useNavigationState(), currentMonth = _a[0], goToMonth = _a[1];
385
- var displayMonths = getDisplayMonths(currentMonth, dayPicker);
386
- var nextMonth = getNextMonth(currentMonth, dayPicker);
387
- var previousMonth = getPreviousMonth(currentMonth, dayPicker);
388
- var isDateDisplayed = function(date) {
389
- return displayMonths.some(function(displayMonth) {
390
- return isSameMonth(date, displayMonth);
391
- });
392
- };
393
- var goToDate = function(date, refDate) {
394
- if (isDateDisplayed(date)) {
395
- return;
396
- }
397
- if (refDate && isBefore(date, refDate)) {
398
- goToMonth(addMonths(date, 1 + dayPicker.numberOfMonths * -1));
399
- } else {
400
- goToMonth(date);
401
- }
402
- };
403
- var value = {
404
- currentMonth,
405
- displayMonths,
406
- goToMonth,
407
- goToDate,
408
- previousMonth,
409
- nextMonth,
410
- isDateDisplayed
411
- };
412
- return jsx(NavigationContext.Provider, { value, children: props.children });
413
- }
414
- function useNavigation() {
415
- var context = useContext(NavigationContext);
416
- if (!context) {
417
- throw new Error("useNavigation must be used within a NavigationProvider");
418
- }
419
- return context;
420
- }
421
- function CaptionDropdowns(props) {
422
- var _a;
423
- var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
424
- var goToMonth = useNavigation().goToMonth;
425
- var handleMonthChange = function(newMonth) {
426
- goToMonth(addMonths(newMonth, props.displayIndex ? -props.displayIndex : 0));
427
- };
428
- var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
429
- var captionLabel = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
430
- return jsxs("div", { className: classNames2.caption_dropdowns, style: styles2.caption_dropdowns, children: [jsx("div", { className: classNames2.vhidden, children: captionLabel }), jsx(MonthsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth }), jsx(YearsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth })] });
431
- }
432
- function IconLeft(props) {
433
- return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" }) }));
434
- }
435
- function IconRight(props) {
436
- return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" }) }));
437
- }
438
- var Button = forwardRef(function(props, ref) {
439
- var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
440
- var classNamesArr = [classNames2.button_reset, classNames2.button];
441
- if (props.className) {
442
- classNamesArr.push(props.className);
443
- }
444
- var className = classNamesArr.join(" ");
445
- var style = __assign(__assign({}, styles2.button_reset), styles2.button);
446
- if (props.style) {
447
- Object.assign(style, props.style);
448
- }
449
- return jsx("button", __assign({}, props, { ref, type: "button", className, style }));
450
- });
451
- function Navigation(props) {
452
- var _a, _b;
453
- var _c = useDayPicker(), dir = _c.dir, locale = _c.locale, classNames2 = _c.classNames, styles2 = _c.styles, _d = _c.labels, labelPrevious2 = _d.labelPrevious, labelNext2 = _d.labelNext, components = _c.components;
454
- if (!props.nextMonth && !props.previousMonth) {
455
- return jsx(Fragment, {});
456
- }
457
- var previousLabel = labelPrevious2(props.previousMonth, { locale });
458
- var previousClassName = [
459
- classNames2.nav_button,
460
- classNames2.nav_button_previous
461
- ].join(" ");
462
- var nextLabel = labelNext2(props.nextMonth, { locale });
463
- var nextClassName = [
464
- classNames2.nav_button,
465
- classNames2.nav_button_next
466
- ].join(" ");
467
- var IconRightComponent = (_a = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _a !== void 0 ? _a : IconRight;
468
- var IconLeftComponent = (_b = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _b !== void 0 ? _b : IconLeft;
469
- return jsxs("div", { className: classNames2.nav, style: styles2.nav, children: [!props.hidePrevious && jsx(Button, { name: "previous-month", "aria-label": previousLabel, className: previousClassName, style: styles2.nav_button_previous, disabled: !props.previousMonth, onClick: props.onPreviousClick, children: dir === "rtl" ? jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) }), !props.hideNext && jsx(Button, { name: "next-month", "aria-label": nextLabel, className: nextClassName, style: styles2.nav_button_next, disabled: !props.nextMonth, onClick: props.onNextClick, children: dir === "rtl" ? jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) })] });
470
- }
471
- function CaptionNavigation(props) {
472
- var numberOfMonths = useDayPicker().numberOfMonths;
473
- var _a = useNavigation(), previousMonth = _a.previousMonth, nextMonth = _a.nextMonth, goToMonth = _a.goToMonth, displayMonths = _a.displayMonths;
474
- var displayIndex = displayMonths.findIndex(function(month) {
475
- return isSameMonth(props.displayMonth, month);
476
- });
477
- var isFirst = displayIndex === 0;
478
- var isLast = displayIndex === displayMonths.length - 1;
479
- var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
480
- var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
481
- var handlePreviousClick = function() {
482
- if (!previousMonth)
483
- return;
484
- goToMonth(previousMonth);
485
- };
486
- var handleNextClick = function() {
487
- if (!nextMonth)
488
- return;
489
- goToMonth(nextMonth);
490
- };
491
- return jsx(Navigation, { displayMonth: props.displayMonth, hideNext, hidePrevious, nextMonth, previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick });
1026
+ return addMonths2(month, -offset);
492
1027
  }
493
- function Caption(props) {
494
- var _a;
495
- var _b = useDayPicker(), classNames2 = _b.classNames, disableNavigation = _b.disableNavigation, styles2 = _b.styles, captionLayout = _b.captionLayout, components = _b.components;
496
- var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
497
- var caption;
498
- if (disableNavigation) {
499
- caption = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
500
- } else if (captionLayout === "dropdown") {
501
- caption = jsx(CaptionDropdowns, { displayMonth: props.displayMonth, id: props.id });
502
- } else if (captionLayout === "dropdown-buttons") {
503
- caption = jsxs(Fragment, { children: [jsx(CaptionDropdowns, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id })] });
504
- } else {
505
- caption = jsxs(Fragment, { children: [jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id })] });
506
- }
507
- return jsx("div", { className: classNames2.caption, style: styles2.caption, children: caption });
1028
+ function getWeeks(months) {
1029
+ const initialWeeks = [];
1030
+ return months.reduce((weeks, month) => {
1031
+ return [...weeks, ...month.weeks];
1032
+ }, initialWeeks);
508
1033
  }
509
- function Footer(props) {
510
- var _a = useDayPicker(), footer = _a.footer, styles2 = _a.styles, tfoot = _a.classNames.tfoot;
511
- if (!footer)
512
- return jsx(Fragment, {});
513
- return jsx("tfoot", { className: tfoot, style: styles2.tfoot, children: jsx("tr", { children: jsx("td", { colSpan: 8, children: footer }) }) });
514
- }
515
- function getWeekdays(locale, weekStartsOn, ISOWeek) {
516
- var start = ISOWeek ? startOfISOWeek(/* @__PURE__ */ new Date()) : startOfWeek(/* @__PURE__ */ new Date(), { locale, weekStartsOn });
517
- var days = [];
518
- for (var i = 0; i < 7; i++) {
519
- var day = addDays(start, i);
520
- days.push(day);
521
- }
522
- return days;
523
- }
524
- function HeadRow() {
525
- var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, weekStartsOn = _a.weekStartsOn, ISOWeek = _a.ISOWeek, formatWeekdayName2 = _a.formatters.formatWeekdayName, labelWeekday2 = _a.labels.labelWeekday;
526
- var weekdays = getWeekdays(locale, weekStartsOn, ISOWeek);
527
- return jsxs("tr", { style: styles2.head_row, className: classNames2.head_row, children: [showWeekNumber && jsx("td", { style: styles2.head_cell, className: classNames2.head_cell }), weekdays.map(function(weekday, i) {
528
- return jsx("th", { scope: "col", className: classNames2.head_cell, style: styles2.head_cell, "aria-label": labelWeekday2(weekday, { locale }), children: formatWeekdayName2(weekday, { locale }) }, i);
529
- })] });
1034
+ function useControlledValue(defaultValue, controlledValue) {
1035
+ const [uncontrolledValue, setValue] = useState(defaultValue);
1036
+ const value = controlledValue === void 0 ? uncontrolledValue : controlledValue;
1037
+ return [value, setValue];
530
1038
  }
531
- function Head() {
532
- var _a;
533
- var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
534
- var HeadRowComponent = (_a = components === null || components === void 0 ? void 0 : components.HeadRow) !== null && _a !== void 0 ? _a : HeadRow;
535
- return jsx("thead", { style: styles2.head, className: classNames2.head, children: jsx(HeadRowComponent, {}) });
536
- }
537
- function DayContent(props) {
538
- var _a = useDayPicker(), locale = _a.locale, formatDay2 = _a.formatters.formatDay;
539
- return jsx(Fragment, { children: formatDay2(props.date, { locale }) });
540
- }
541
- var SelectMultipleContext = createContext(void 0);
542
- function SelectMultipleProvider(props) {
543
- if (!isDayPickerMultiple(props.initialProps)) {
544
- var emptyContextValue = {
545
- selected: void 0,
546
- modifiers: {
547
- disabled: []
548
- }
549
- };
550
- return jsx(SelectMultipleContext.Provider, { value: emptyContextValue, children: props.children });
551
- }
552
- return jsx(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children });
553
- }
554
- function SelectMultipleProviderInternal(_a) {
555
- var initialProps = _a.initialProps, children = _a.children;
556
- var selected = initialProps.selected, min2 = initialProps.min, max2 = initialProps.max;
557
- var onDayClick = function(day, activeModifiers, e) {
558
- var _a2, _b;
559
- (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
560
- var isMinSelected = Boolean(activeModifiers.selected && min2 && (selected === null || selected === void 0 ? void 0 : selected.length) === min2);
561
- if (isMinSelected) {
1039
+ function useCalendar(props, dateLib) {
1040
+ const [navStart, navEnd] = getNavMonths(props, dateLib);
1041
+ const { startOfMonth: startOfMonth2, endOfMonth: endOfMonth2 } = dateLib;
1042
+ const initialMonth = getInitialMonth(props, dateLib);
1043
+ const [firstMonth, setFirstMonth] = useControlledValue(initialMonth, props.month ? startOfMonth2(props.month) : void 0);
1044
+ useEffect(() => {
1045
+ const newInitialMonth = getInitialMonth(props, dateLib);
1046
+ setFirstMonth(newInitialMonth);
1047
+ }, [props.timeZone]);
1048
+ const displayMonths = getDisplayMonths(firstMonth, navEnd, props, dateLib);
1049
+ const dates = getDates(displayMonths, props.endMonth ? endOfMonth2(props.endMonth) : void 0, props, dateLib);
1050
+ const months = getMonths(displayMonths, dates, props, dateLib);
1051
+ const weeks = getWeeks(months);
1052
+ const days = getDays(months);
1053
+ const previousMonth = getPreviousMonth(firstMonth, navStart, props, dateLib);
1054
+ const nextMonth = getNextMonth(firstMonth, navEnd, props, dateLib);
1055
+ const { disableNavigation, onMonthChange } = props;
1056
+ const isDayInCalendar = (day) => weeks.some((week) => week.days.some((d) => d.isEqualTo(day)));
1057
+ const goToMonth = (date) => {
1058
+ if (disableNavigation) {
562
1059
  return;
563
1060
  }
564
- var isMaxSelected = Boolean(!activeModifiers.selected && max2 && (selected === null || selected === void 0 ? void 0 : selected.length) === max2);
565
- if (isMaxSelected) {
566
- return;
1061
+ let newMonth = startOfMonth2(date);
1062
+ if (navStart && newMonth < startOfMonth2(navStart)) {
1063
+ newMonth = startOfMonth2(navStart);
567
1064
  }
568
- var selectedDays = selected ? __spreadArray([], selected) : [];
569
- if (activeModifiers.selected) {
570
- var index = selectedDays.findIndex(function(selectedDay) {
571
- return isSameDay(day, selectedDay);
572
- });
573
- selectedDays.splice(index, 1);
574
- } else {
575
- selectedDays.push(day);
1065
+ if (navEnd && newMonth > startOfMonth2(navEnd)) {
1066
+ newMonth = startOfMonth2(navEnd);
576
1067
  }
577
- (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, selectedDays, day, activeModifiers, e);
578
- };
579
- var modifiers = {
580
- disabled: []
1068
+ setFirstMonth(newMonth);
1069
+ onMonthChange == null ? void 0 : onMonthChange(newMonth);
581
1070
  };
582
- if (selected) {
583
- modifiers.disabled.push(function(day) {
584
- var isMaxSelected = max2 && selected.length > max2 - 1;
585
- var isSelected = selected.some(function(selectedDay) {
586
- return isSameDay(selectedDay, day);
587
- });
588
- return Boolean(isMaxSelected && !isSelected);
589
- });
590
- }
591
- var contextValue = {
592
- selected,
593
- onDayClick,
594
- modifiers
595
- };
596
- return jsx(SelectMultipleContext.Provider, { value: contextValue, children });
597
- }
598
- function useSelectMultiple() {
599
- var context = useContext(SelectMultipleContext);
600
- if (!context) {
601
- throw new Error("useSelectMultiple must be used within a SelectMultipleProvider");
602
- }
603
- return context;
604
- }
605
- function addToRange(day, range) {
606
- var _a = range || {}, from = _a.from, to = _a.to;
607
- if (from && to) {
608
- if (isSameDay(to, day) && isSameDay(from, day)) {
609
- return void 0;
610
- }
611
- if (isSameDay(to, day)) {
612
- return { from: to, to: void 0 };
613
- }
614
- if (isSameDay(from, day)) {
615
- return void 0;
616
- }
617
- if (isAfter(from, day)) {
618
- return { from: day, to };
619
- }
620
- return { from, to: day };
621
- }
622
- if (to) {
623
- if (isAfter(day, to)) {
624
- return { from: to, to: day };
625
- }
626
- return { from: day, to };
627
- }
628
- if (from) {
629
- if (isBefore(day, from)) {
630
- return { from: day, to: from };
1071
+ const goToDay = (day) => {
1072
+ if (isDayInCalendar(day)) {
1073
+ return;
631
1074
  }
632
- return { from, to: day };
633
- }
634
- return { from: day, to: void 0 };
635
- }
636
- var SelectRangeContext = createContext(void 0);
637
- function SelectRangeProvider(props) {
638
- if (!isDayPickerRange(props.initialProps)) {
639
- var emptyContextValue = {
640
- selected: void 0,
641
- modifiers: {
642
- range_start: [],
643
- range_end: [],
644
- range_middle: [],
645
- disabled: []
646
- }
647
- };
648
- return jsx(SelectRangeContext.Provider, { value: emptyContextValue, children: props.children });
649
- }
650
- return jsx(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children });
651
- }
652
- function SelectRangeProviderInternal(_a) {
653
- var initialProps = _a.initialProps, children = _a.children;
654
- var selected = initialProps.selected;
655
- var _b = selected || {}, selectedFrom = _b.from, selectedTo = _b.to;
656
- var min2 = initialProps.min;
657
- var max2 = initialProps.max;
658
- var onDayClick = function(day, activeModifiers, e) {
659
- var _a2, _b2;
660
- (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
661
- var newRange = addToRange(day, selected);
662
- (_b2 = initialProps.onSelect) === null || _b2 === void 0 ? void 0 : _b2.call(initialProps, newRange, day, activeModifiers, e);
1075
+ goToMonth(day.date);
663
1076
  };
664
- var modifiers = {
665
- range_start: [],
666
- range_end: [],
667
- range_middle: [],
668
- disabled: []
1077
+ const calendar = {
1078
+ months,
1079
+ weeks,
1080
+ days,
1081
+ navStart,
1082
+ navEnd,
1083
+ previousMonth,
1084
+ nextMonth,
1085
+ goToMonth,
1086
+ goToDay
669
1087
  };
670
- if (selectedFrom) {
671
- modifiers.range_start = [selectedFrom];
672
- if (!selectedTo) {
673
- modifiers.range_end = [selectedFrom];
674
- } else {
675
- modifiers.range_end = [selectedTo];
676
- if (!isSameDay(selectedFrom, selectedTo)) {
677
- modifiers.range_middle = [
678
- {
679
- after: selectedFrom,
680
- before: selectedTo
681
- }
682
- ];
1088
+ return calendar;
1089
+ }
1090
+ function calculateFocusTarget(days, getModifiers, isSelected, lastFocused) {
1091
+ let focusTarget;
1092
+ let index = 0;
1093
+ let found = false;
1094
+ while (index < days.length && !found) {
1095
+ const day = days[index];
1096
+ const modifiers = getModifiers(day);
1097
+ if (!modifiers[DayFlag.disabled] && !modifiers[DayFlag.hidden] && !modifiers[DayFlag.outside]) {
1098
+ if (modifiers[DayFlag.focused]) {
1099
+ focusTarget = day;
1100
+ found = true;
1101
+ } else if (lastFocused == null ? void 0 : lastFocused.isEqualTo(day)) {
1102
+ focusTarget = day;
1103
+ found = true;
1104
+ } else if (isSelected(day.date)) {
1105
+ focusTarget = day;
1106
+ found = true;
1107
+ } else if (modifiers[DayFlag.today]) {
1108
+ focusTarget = day;
1109
+ found = true;
683
1110
  }
684
1111
  }
685
- } else if (selectedTo) {
686
- modifiers.range_start = [selectedTo];
687
- modifiers.range_end = [selectedTo];
688
- }
689
- if (min2) {
690
- if (selectedFrom && !selectedTo) {
691
- modifiers.disabled.push({
692
- after: subDays(selectedFrom, min2 - 1),
693
- before: addDays(selectedFrom, min2 - 1)
694
- });
695
- }
696
- if (selectedFrom && selectedTo) {
697
- modifiers.disabled.push({
698
- after: selectedFrom,
699
- before: addDays(selectedFrom, min2 - 1)
700
- });
701
- }
702
- if (!selectedFrom && selectedTo) {
703
- modifiers.disabled.push({
704
- after: subDays(selectedTo, min2 - 1),
705
- before: addDays(selectedTo, min2 - 1)
706
- });
707
- }
1112
+ index++;
708
1113
  }
709
- if (max2) {
710
- if (selectedFrom && !selectedTo) {
711
- modifiers.disabled.push({
712
- before: addDays(selectedFrom, -max2 + 1)
713
- });
714
- modifiers.disabled.push({
715
- after: addDays(selectedFrom, max2 - 1)
716
- });
717
- }
718
- if (selectedFrom && selectedTo) {
719
- var selectedCount = differenceInCalendarDays(selectedTo, selectedFrom) + 1;
720
- var offset = max2 - selectedCount;
721
- modifiers.disabled.push({
722
- before: subDays(selectedFrom, offset)
723
- });
724
- modifiers.disabled.push({
725
- after: addDays(selectedTo, offset)
726
- });
727
- }
728
- if (!selectedFrom && selectedTo) {
729
- modifiers.disabled.push({
730
- before: addDays(selectedTo, -max2 + 1)
731
- });
732
- modifiers.disabled.push({
733
- after: addDays(selectedTo, max2 - 1)
734
- });
735
- }
1114
+ if (!focusTarget) {
1115
+ focusTarget = days.find((day) => {
1116
+ const m = getModifiers(day);
1117
+ return !m[DayFlag.disabled] && !m[DayFlag.hidden] && !m[DayFlag.outside];
1118
+ });
736
1119
  }
737
- return jsx(SelectRangeContext.Provider, { value: { selected, onDayClick, modifiers }, children });
1120
+ return focusTarget;
738
1121
  }
739
- function useSelectRange() {
740
- var context = useContext(SelectRangeContext);
741
- if (!context) {
742
- throw new Error("useSelectRange must be used within a SelectRangeProvider");
1122
+ function rangeIncludesDate(range, date, excludeEnds = false, dateLib = defaultDateLib) {
1123
+ let { from, to } = range;
1124
+ const { differenceInCalendarDays: differenceInCalendarDays2, isSameDay: isSameDay2 } = dateLib;
1125
+ if (from && to) {
1126
+ const isRangeInverted = differenceInCalendarDays2(to, from) < 0;
1127
+ if (isRangeInverted) {
1128
+ [from, to] = [to, from];
1129
+ }
1130
+ const isInRange = differenceInCalendarDays2(date, from) >= (excludeEnds ? 1 : 0) && differenceInCalendarDays2(to, date) >= (excludeEnds ? 1 : 0);
1131
+ return isInRange;
743
1132
  }
744
- return context;
745
- }
746
- function matcherToArray(matcher) {
747
- if (Array.isArray(matcher)) {
748
- return __spreadArray([], matcher);
749
- } else if (matcher !== void 0) {
750
- return [matcher];
751
- } else {
752
- return [];
1133
+ if (!excludeEnds && to) {
1134
+ return isSameDay2(to, date);
753
1135
  }
754
- }
755
- function getCustomModifiers(dayModifiers) {
756
- var customModifiers = {};
757
- Object.entries(dayModifiers).forEach(function(_a) {
758
- var modifier = _a[0], matcher = _a[1];
759
- customModifiers[modifier] = matcherToArray(matcher);
760
- });
761
- return customModifiers;
762
- }
763
- var InternalModifier;
764
- (function(InternalModifier2) {
765
- InternalModifier2["Outside"] = "outside";
766
- InternalModifier2["Disabled"] = "disabled";
767
- InternalModifier2["Selected"] = "selected";
768
- InternalModifier2["Hidden"] = "hidden";
769
- InternalModifier2["Today"] = "today";
770
- InternalModifier2["RangeStart"] = "range_start";
771
- InternalModifier2["RangeEnd"] = "range_end";
772
- InternalModifier2["RangeMiddle"] = "range_middle";
773
- })(InternalModifier || (InternalModifier = {}));
774
- var Selected = InternalModifier.Selected, Disabled = InternalModifier.Disabled, Hidden = InternalModifier.Hidden, Today = InternalModifier.Today, RangeEnd = InternalModifier.RangeEnd, RangeMiddle = InternalModifier.RangeMiddle, RangeStart = InternalModifier.RangeStart, Outside = InternalModifier.Outside;
775
- function getInternalModifiers(dayPicker, selectMultiple, selectRange) {
776
- var _a;
777
- var internalModifiers = (_a = {}, _a[Selected] = matcherToArray(dayPicker.selected), _a[Disabled] = matcherToArray(dayPicker.disabled), _a[Hidden] = matcherToArray(dayPicker.hidden), _a[Today] = [dayPicker.today], _a[RangeEnd] = [], _a[RangeMiddle] = [], _a[RangeStart] = [], _a[Outside] = [], _a);
778
- if (dayPicker.fromDate) {
779
- internalModifiers[Disabled].push({ before: dayPicker.fromDate });
780
- }
781
- if (dayPicker.toDate) {
782
- internalModifiers[Disabled].push({ after: dayPicker.toDate });
783
- }
784
- if (isDayPickerMultiple(dayPicker)) {
785
- internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectMultiple.modifiers[Disabled]);
786
- } else if (isDayPickerRange(dayPicker)) {
787
- internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectRange.modifiers[Disabled]);
788
- internalModifiers[RangeStart] = selectRange.modifiers[RangeStart];
789
- internalModifiers[RangeMiddle] = selectRange.modifiers[RangeMiddle];
790
- internalModifiers[RangeEnd] = selectRange.modifiers[RangeEnd];
791
- }
792
- return internalModifiers;
793
- }
794
- var ModifiersContext = createContext(void 0);
795
- function ModifiersProvider(props) {
796
- var dayPicker = useDayPicker();
797
- var selectMultiple = useSelectMultiple();
798
- var selectRange = useSelectRange();
799
- var internalModifiers = getInternalModifiers(dayPicker, selectMultiple, selectRange);
800
- var customModifiers = getCustomModifiers(dayPicker.modifiers);
801
- var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
802
- return jsx(ModifiersContext.Provider, { value: modifiers, children: props.children });
803
- }
804
- function useModifiers() {
805
- var context = useContext(ModifiersContext);
806
- if (!context) {
807
- throw new Error("useModifiers must be used within a ModifiersProvider");
1136
+ if (!excludeEnds && from) {
1137
+ return isSameDay2(from, date);
808
1138
  }
809
- return context;
1139
+ return false;
810
1140
  }
811
1141
  function isDateInterval(matcher) {
812
1142
  return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
@@ -823,54 +1153,37 @@ function isDateBeforeType(value) {
823
1153
  function isDayOfWeekType(value) {
824
1154
  return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
825
1155
  }
826
- function isDateInRange(date, range) {
827
- var _a;
828
- var from = range.from, to = range.to;
829
- if (from && to) {
830
- var isRangeInverted = differenceInCalendarDays(to, from) < 0;
831
- if (isRangeInverted) {
832
- _a = [to, from], from = _a[0], to = _a[1];
833
- }
834
- var isInRange = differenceInCalendarDays(date, from) >= 0 && differenceInCalendarDays(to, date) >= 0;
835
- return isInRange;
836
- }
837
- if (to) {
838
- return isSameDay(to, date);
839
- }
840
- if (from) {
841
- return isSameDay(from, date);
842
- }
843
- return false;
844
- }
845
- function isDateType(value) {
846
- return isDate(value);
1156
+ function isDatesArray(value, dateLib) {
1157
+ return Array.isArray(value) && value.every(dateLib.isDate);
847
1158
  }
848
- function isArrayOfDates(value) {
849
- return Array.isArray(value) && value.every(isDate);
850
- }
851
- function isMatch(day, matchers) {
852
- return matchers.some(function(matcher) {
1159
+ function dateMatchModifiers(date, matchers, dateLib = defaultDateLib) {
1160
+ const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
1161
+ const { isSameDay: isSameDay2, differenceInCalendarDays: differenceInCalendarDays2, isAfter: isAfter2 } = dateLib;
1162
+ return matchersArr.some((matcher) => {
853
1163
  if (typeof matcher === "boolean") {
854
1164
  return matcher;
855
1165
  }
856
- if (isDateType(matcher)) {
857
- return isSameDay(day, matcher);
1166
+ if (dateLib.isDate(matcher)) {
1167
+ return isSameDay2(date, matcher);
858
1168
  }
859
- if (isArrayOfDates(matcher)) {
860
- return matcher.includes(day);
1169
+ if (isDatesArray(matcher, dateLib)) {
1170
+ return matcher.includes(date);
861
1171
  }
862
1172
  if (isDateRange(matcher)) {
863
- return isDateInRange(day, matcher);
1173
+ return rangeIncludesDate(matcher, date, false, dateLib);
864
1174
  }
865
1175
  if (isDayOfWeekType(matcher)) {
866
- return matcher.dayOfWeek.includes(day.getDay());
1176
+ if (!Array.isArray(matcher.dayOfWeek)) {
1177
+ return matcher.dayOfWeek === date.getDay();
1178
+ }
1179
+ return matcher.dayOfWeek.includes(date.getDay());
867
1180
  }
868
1181
  if (isDateInterval(matcher)) {
869
- var diffBefore = differenceInCalendarDays(matcher.before, day);
870
- var diffAfter = differenceInCalendarDays(matcher.after, day);
871
- var isDayBefore = diffBefore > 0;
872
- var isDayAfter = diffAfter < 0;
873
- var isClosedInterval = isAfter(matcher.before, matcher.after);
1182
+ const diffBefore = differenceInCalendarDays2(matcher.before, date);
1183
+ const diffAfter = differenceInCalendarDays2(matcher.after, date);
1184
+ const isDayBefore = diffBefore > 0;
1185
+ const isDayAfter = diffAfter < 0;
1186
+ const isClosedInterval = isAfter2(matcher.before, matcher.after);
874
1187
  if (isClosedInterval) {
875
1188
  return isDayAfter && isDayBefore;
876
1189
  } else {
@@ -878,633 +1191,568 @@ function isMatch(day, matchers) {
878
1191
  }
879
1192
  }
880
1193
  if (isDateAfterType(matcher)) {
881
- return differenceInCalendarDays(day, matcher.after) > 0;
1194
+ return differenceInCalendarDays2(date, matcher.after) > 0;
882
1195
  }
883
1196
  if (isDateBeforeType(matcher)) {
884
- return differenceInCalendarDays(matcher.before, day) > 0;
1197
+ return differenceInCalendarDays2(matcher.before, date) > 0;
885
1198
  }
886
1199
  if (typeof matcher === "function") {
887
- return matcher(day);
1200
+ return matcher(date);
888
1201
  }
889
1202
  return false;
890
1203
  });
891
1204
  }
892
- function getActiveModifiers(day, modifiers, displayMonth) {
893
- var matchedModifiers = Object.keys(modifiers).reduce(function(result, key) {
894
- var modifier = modifiers[key];
895
- if (isMatch(day, modifier)) {
896
- result.push(key);
897
- }
898
- return result;
899
- }, []);
900
- var activeModifiers = {};
901
- matchedModifiers.forEach(function(modifier) {
902
- return activeModifiers[modifier] = true;
903
- });
904
- if (displayMonth && !isSameMonth(day, displayMonth)) {
905
- activeModifiers.outside = true;
906
- }
907
- return activeModifiers;
908
- }
909
- function getInitialFocusTarget(displayMonths, modifiers) {
910
- var firstDayInMonth = startOfMonth(displayMonths[0]);
911
- var lastDayInMonth = endOfMonth(displayMonths[displayMonths.length - 1]);
912
- var firstFocusableDay;
913
- var today;
914
- var date = firstDayInMonth;
915
- while (date <= lastDayInMonth) {
916
- var activeModifiers = getActiveModifiers(date, modifiers);
917
- var isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
918
- if (!isFocusable) {
919
- date = addDays(date, 1);
920
- continue;
921
- }
922
- if (activeModifiers.selected) {
923
- return date;
924
- }
925
- if (activeModifiers.today && !today) {
926
- today = date;
927
- }
928
- if (!firstFocusableDay) {
929
- firstFocusableDay = date;
930
- }
931
- date = addDays(date, 1);
932
- }
933
- if (today) {
934
- return today;
935
- } else {
936
- return firstFocusableDay;
937
- }
938
- }
939
- var MAX_RETRY = 365;
940
- function getNextFocus(focusedDay, options) {
941
- var moveBy = options.moveBy, direction = options.direction, context = options.context, modifiers = options.modifiers, _a = options.retry, retry = _a === void 0 ? { count: 0, lastFocused: focusedDay } : _a;
942
- var weekStartsOn = context.weekStartsOn, fromDate = context.fromDate, toDate = context.toDate, locale = context.locale;
943
- var moveFns = {
944
- day: addDays,
945
- week: addWeeks,
946
- month: addMonths,
947
- year: addYears,
948
- startOfWeek: function(date) {
949
- return context.ISOWeek ? startOfISOWeek(date) : startOfWeek(date, { locale, weekStartsOn });
950
- },
951
- endOfWeek: function(date) {
952
- return context.ISOWeek ? endOfISOWeek(date) : endOfWeek(date, { locale, weekStartsOn });
953
- }
1205
+ function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dateLib) {
1206
+ const { ISOWeek, broadcastCalendar } = props;
1207
+ const { addDays: addDays2, addMonths: addMonths2, addWeeks: addWeeks2, addYears: addYears2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfWeek: endOfWeek2, max: max2, min: min2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
1208
+ const moveFns = {
1209
+ day: addDays2,
1210
+ week: addWeeks2,
1211
+ month: addMonths2,
1212
+ year: addYears2,
1213
+ startOfWeek: (date) => broadcastCalendar ? startOfBroadcastWeek2(date, dateLib) : ISOWeek ? startOfISOWeek2(date) : startOfWeek2(date),
1214
+ endOfWeek: (date) => broadcastCalendar ? endOfBroadcastWeek2(date, dateLib) : ISOWeek ? endOfISOWeek2(date) : endOfWeek2(date)
954
1215
  };
955
- var newFocusedDay = moveFns[moveBy](focusedDay, direction === "after" ? 1 : -1);
956
- if (direction === "before" && fromDate) {
957
- newFocusedDay = max([fromDate, newFocusedDay]);
958
- } else if (direction === "after" && toDate) {
959
- newFocusedDay = min([toDate, newFocusedDay]);
960
- }
961
- var isFocusable = true;
962
- if (modifiers) {
963
- var activeModifiers = getActiveModifiers(newFocusedDay, modifiers);
964
- isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
965
- }
966
- if (isFocusable) {
967
- return newFocusedDay;
968
- } else {
969
- if (retry.count > MAX_RETRY) {
970
- return retry.lastFocused;
971
- }
972
- return getNextFocus(newFocusedDay, {
973
- moveBy,
974
- direction,
975
- context,
976
- modifiers,
977
- retry: __assign(__assign({}, retry), { count: retry.count + 1 })
978
- });
1216
+ let focusableDate = moveFns[moveBy](refDate, moveDir === "after" ? 1 : -1);
1217
+ if (moveDir === "before" && navStart) {
1218
+ focusableDate = max2([navStart, focusableDate]);
1219
+ } else if (moveDir === "after" && navEnd) {
1220
+ focusableDate = min2([navEnd, focusableDate]);
979
1221
  }
1222
+ return focusableDate;
980
1223
  }
981
- var FocusContext = createContext(void 0);
982
- function FocusProvider(props) {
983
- var navigation = useNavigation();
984
- var modifiers = useModifiers();
985
- var _a = useState(), focusedDay = _a[0], setFocusedDay = _a[1];
986
- var _b = useState(), lastFocused = _b[0], setLastFocused = _b[1];
987
- var initialFocusTarget = getInitialFocusTarget(navigation.displayMonths, modifiers);
988
- var focusTarget = (focusedDay !== null && focusedDay !== void 0 ? focusedDay : lastFocused && navigation.isDateDisplayed(lastFocused)) ? lastFocused : initialFocusTarget;
989
- var blur = function() {
1224
+ function getNextFocus(moveBy, moveDir, refDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt = 0) {
1225
+ if (attempt > 365) {
1226
+ return void 0;
1227
+ }
1228
+ const focusableDate = getFocusableDate(
1229
+ moveBy,
1230
+ moveDir,
1231
+ refDay.date,
1232
+ // should be refDay? or refDay.date?
1233
+ calendarStartMonth,
1234
+ calendarEndMonth,
1235
+ props,
1236
+ dateLib
1237
+ );
1238
+ const isDisabled = Boolean(props.disabled && dateMatchModifiers(focusableDate, props.disabled, dateLib));
1239
+ const isHidden = Boolean(props.hidden && dateMatchModifiers(focusableDate, props.hidden, dateLib));
1240
+ const targetMonth = focusableDate;
1241
+ const focusDay = new CalendarDay(focusableDate, targetMonth, dateLib);
1242
+ if (!isDisabled && !isHidden) {
1243
+ return focusDay;
1244
+ }
1245
+ return getNextFocus(moveBy, moveDir, focusDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt + 1);
1246
+ }
1247
+ function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
1248
+ const { autoFocus } = props;
1249
+ const [lastFocused, setLastFocused] = useState();
1250
+ const focusTarget = calculateFocusTarget(calendar.days, getModifiers, isSelected || (() => false), lastFocused);
1251
+ const [focusedDay, setFocused] = useState(autoFocus ? focusTarget : void 0);
1252
+ const blur = () => {
990
1253
  setLastFocused(focusedDay);
991
- setFocusedDay(void 0);
1254
+ setFocused(void 0);
992
1255
  };
993
- var focus = function(date) {
994
- setFocusedDay(date);
995
- };
996
- var context = useDayPicker();
997
- var moveFocus = function(moveBy, direction) {
1256
+ const moveFocus = (moveBy, moveDir) => {
998
1257
  if (!focusedDay)
999
1258
  return;
1000
- var nextFocused = getNextFocus(focusedDay, {
1001
- moveBy,
1002
- direction,
1003
- context,
1004
- modifiers
1005
- });
1006
- if (isSameDay(focusedDay, nextFocused))
1007
- return void 0;
1008
- navigation.goToDate(nextFocused, focusedDay);
1009
- focus(nextFocused);
1259
+ const nextFocus = getNextFocus(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
1260
+ if (!nextFocus)
1261
+ return;
1262
+ calendar.goToDay(nextFocus);
1263
+ setFocused(nextFocus);
1010
1264
  };
1011
- var value = {
1012
- focusedDay,
1013
- focusTarget,
1265
+ const isFocusTarget = (day) => {
1266
+ return Boolean(focusTarget == null ? void 0 : focusTarget.isEqualTo(day));
1267
+ };
1268
+ const useFocus2 = {
1269
+ isFocusTarget,
1270
+ setFocused,
1271
+ focused: focusedDay,
1014
1272
  blur,
1015
- focus,
1016
- focusDayAfter: function() {
1017
- return moveFocus("day", "after");
1018
- },
1019
- focusDayBefore: function() {
1020
- return moveFocus("day", "before");
1021
- },
1022
- focusWeekAfter: function() {
1023
- return moveFocus("week", "after");
1024
- },
1025
- focusWeekBefore: function() {
1026
- return moveFocus("week", "before");
1027
- },
1028
- focusMonthBefore: function() {
1029
- return moveFocus("month", "before");
1030
- },
1031
- focusMonthAfter: function() {
1032
- return moveFocus("month", "after");
1033
- },
1034
- focusYearBefore: function() {
1035
- return moveFocus("year", "before");
1036
- },
1037
- focusYearAfter: function() {
1038
- return moveFocus("year", "after");
1039
- },
1040
- focusStartOfWeek: function() {
1041
- return moveFocus("startOfWeek", "before");
1042
- },
1043
- focusEndOfWeek: function() {
1044
- return moveFocus("endOfWeek", "after");
1045
- }
1273
+ moveFocus
1046
1274
  };
1047
- return jsx(FocusContext.Provider, { value, children: props.children });
1048
- }
1049
- function useFocusContext() {
1050
- var context = useContext(FocusContext);
1051
- if (!context) {
1052
- throw new Error("useFocusContext must be used within a FocusProvider");
1275
+ return useFocus2;
1276
+ }
1277
+ function useGetModifiers(days, props, dateLib) {
1278
+ const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today } = props;
1279
+ const { isSameDay: isSameDay2, isSameMonth: isSameMonth2, startOfMonth: startOfMonth2, isBefore: isBefore2, endOfMonth: endOfMonth2, isAfter: isAfter2 } = dateLib;
1280
+ const startMonth = props.startMonth && startOfMonth2(props.startMonth);
1281
+ const endMonth = props.endMonth && endOfMonth2(props.endMonth);
1282
+ const internalModifiersMap = {
1283
+ [DayFlag.focused]: [],
1284
+ [DayFlag.outside]: [],
1285
+ [DayFlag.disabled]: [],
1286
+ [DayFlag.hidden]: [],
1287
+ [DayFlag.today]: []
1288
+ };
1289
+ const customModifiersMap = {};
1290
+ for (const day of days) {
1291
+ const { date, displayMonth } = day;
1292
+ const isOutside = Boolean(displayMonth && !isSameMonth2(date, displayMonth));
1293
+ const isBeforeStartMonth = Boolean(startMonth && isBefore2(date, startMonth));
1294
+ const isAfterEndMonth = Boolean(endMonth && isAfter2(date, endMonth));
1295
+ const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
1296
+ const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeStartMonth || isAfterEndMonth || // Broadcast calendar will show outside days as default
1297
+ !broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
1298
+ const isToday = isSameDay2(date, today ?? (props.timeZone ? TZDate.tz(props.timeZone) : dateLib.Date ? new dateLib.Date() : /* @__PURE__ */ new Date()));
1299
+ if (isOutside)
1300
+ internalModifiersMap.outside.push(day);
1301
+ if (isDisabled)
1302
+ internalModifiersMap.disabled.push(day);
1303
+ if (isHidden)
1304
+ internalModifiersMap.hidden.push(day);
1305
+ if (isToday)
1306
+ internalModifiersMap.today.push(day);
1307
+ if (modifiers) {
1308
+ Object.keys(modifiers).forEach((name) => {
1309
+ const modifierValue = modifiers == null ? void 0 : modifiers[name];
1310
+ const isMatch = modifierValue ? dateMatchModifiers(date, modifierValue, dateLib) : false;
1311
+ if (!isMatch)
1312
+ return;
1313
+ if (customModifiersMap[name]) {
1314
+ customModifiersMap[name].push(day);
1315
+ } else {
1316
+ customModifiersMap[name] = [day];
1317
+ }
1318
+ });
1319
+ }
1053
1320
  }
1054
- return context;
1055
- }
1056
- function useActiveModifiers(day, displayMonth) {
1057
- var modifiers = useModifiers();
1058
- var activeModifiers = getActiveModifiers(day, modifiers, displayMonth);
1059
- return activeModifiers;
1060
- }
1061
- var SelectSingleContext = createContext(void 0);
1062
- function SelectSingleProvider(props) {
1063
- if (!isDayPickerSingle(props.initialProps)) {
1064
- var emptyContextValue = {
1065
- selected: void 0
1321
+ return (day) => {
1322
+ const dayFlags = {
1323
+ [DayFlag.focused]: false,
1324
+ [DayFlag.disabled]: false,
1325
+ [DayFlag.hidden]: false,
1326
+ [DayFlag.outside]: false,
1327
+ [DayFlag.today]: false
1066
1328
  };
1067
- return jsx(SelectSingleContext.Provider, { value: emptyContextValue, children: props.children });
1068
- }
1069
- return jsx(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children });
1070
- }
1071
- function SelectSingleProviderInternal(_a) {
1072
- var initialProps = _a.initialProps, children = _a.children;
1073
- var onDayClick = function(day, activeModifiers, e) {
1074
- var _a2, _b, _c;
1075
- (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
1076
- if (activeModifiers.selected && !initialProps.required) {
1077
- (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, void 0, day, activeModifiers, e);
1078
- return;
1329
+ const customModifiers = {};
1330
+ for (const name in internalModifiersMap) {
1331
+ const days2 = internalModifiersMap[name];
1332
+ dayFlags[name] = days2.some((d) => d === day);
1079
1333
  }
1080
- (_c = initialProps.onSelect) === null || _c === void 0 ? void 0 : _c.call(initialProps, day, day, activeModifiers, e);
1081
- };
1082
- var contextValue = {
1083
- selected: initialProps.selected,
1084
- onDayClick
1334
+ for (const name in customModifiersMap) {
1335
+ customModifiers[name] = customModifiersMap[name].some((d) => d === day);
1336
+ }
1337
+ return {
1338
+ ...dayFlags,
1339
+ // custom modifiers should override all the previous ones
1340
+ ...customModifiers
1341
+ };
1085
1342
  };
1086
- return jsx(SelectSingleContext.Provider, { value: contextValue, children });
1087
1343
  }
1088
- function useSelectSingle() {
1089
- var context = useContext(SelectSingleContext);
1090
- if (!context) {
1091
- throw new Error("useSelectSingle must be used within a SelectSingleProvider");
1092
- }
1093
- return context;
1094
- }
1095
- function useDayEventHandlers(date, activeModifiers) {
1096
- var dayPicker = useDayPicker();
1097
- var single = useSelectSingle();
1098
- var multiple = useSelectMultiple();
1099
- var range = useSelectRange();
1100
- var _a = useFocusContext(), focusDayAfter = _a.focusDayAfter, focusDayBefore = _a.focusDayBefore, focusWeekAfter = _a.focusWeekAfter, focusWeekBefore = _a.focusWeekBefore, blur = _a.blur, focus = _a.focus, focusMonthBefore = _a.focusMonthBefore, focusMonthAfter = _a.focusMonthAfter, focusYearBefore = _a.focusYearBefore, focusYearAfter = _a.focusYearAfter, focusStartOfWeek = _a.focusStartOfWeek, focusEndOfWeek = _a.focusEndOfWeek;
1101
- var onClick = function(e) {
1102
- var _a2, _b, _c, _d;
1103
- if (isDayPickerSingle(dayPicker)) {
1104
- (_a2 = single.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(single, date, activeModifiers, e);
1105
- } else if (isDayPickerMultiple(dayPicker)) {
1106
- (_b = multiple.onDayClick) === null || _b === void 0 ? void 0 : _b.call(multiple, date, activeModifiers, e);
1107
- } else if (isDayPickerRange(dayPicker)) {
1108
- (_c = range.onDayClick) === null || _c === void 0 ? void 0 : _c.call(range, date, activeModifiers, e);
1344
+ function useMulti(props, dateLib) {
1345
+ const { selected: initiallySelected, required, onSelect } = props;
1346
+ const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1347
+ const selected = !onSelect ? internallySelected : initiallySelected;
1348
+ const { isSameDay: isSameDay2 } = dateLib;
1349
+ const isSelected = (date) => {
1350
+ return (selected == null ? void 0 : selected.some((d) => isSameDay2(d, date))) ?? false;
1351
+ };
1352
+ const { min: min2, max: max2 } = props;
1353
+ const select = (triggerDate, modifiers, e) => {
1354
+ let newDates = [...selected ?? []];
1355
+ if (isSelected(triggerDate)) {
1356
+ if ((selected == null ? void 0 : selected.length) === min2) {
1357
+ return;
1358
+ }
1359
+ if (required && (selected == null ? void 0 : selected.length) === 1) {
1360
+ return;
1361
+ }
1362
+ newDates = selected == null ? void 0 : selected.filter((d) => !isSameDay2(d, triggerDate));
1109
1363
  } else {
1110
- (_d = dayPicker.onDayClick) === null || _d === void 0 ? void 0 : _d.call(dayPicker, date, activeModifiers, e);
1364
+ if ((selected == null ? void 0 : selected.length) === max2) {
1365
+ newDates = [triggerDate];
1366
+ } else {
1367
+ newDates = [...newDates, triggerDate];
1368
+ }
1111
1369
  }
1370
+ if (!onSelect) {
1371
+ setSelected(newDates);
1372
+ }
1373
+ onSelect == null ? void 0 : onSelect(newDates, triggerDate, modifiers, e);
1374
+ return newDates;
1112
1375
  };
1113
- var onFocus = function(e) {
1114
- var _a2;
1115
- focus(date);
1116
- (_a2 = dayPicker.onDayFocus) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1117
- };
1118
- var onBlur = function(e) {
1119
- var _a2;
1120
- blur();
1121
- (_a2 = dayPicker.onDayBlur) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1122
- };
1123
- var onMouseEnter = function(e) {
1124
- var _a2;
1125
- (_a2 = dayPicker.onDayMouseEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1126
- };
1127
- var onMouseLeave = function(e) {
1128
- var _a2;
1129
- (_a2 = dayPicker.onDayMouseLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1130
- };
1131
- var onPointerEnter = function(e) {
1132
- var _a2;
1133
- (_a2 = dayPicker.onDayPointerEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1134
- };
1135
- var onPointerLeave = function(e) {
1136
- var _a2;
1137
- (_a2 = dayPicker.onDayPointerLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1138
- };
1139
- var onTouchCancel = function(e) {
1140
- var _a2;
1141
- (_a2 = dayPicker.onDayTouchCancel) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1142
- };
1143
- var onTouchEnd = function(e) {
1144
- var _a2;
1145
- (_a2 = dayPicker.onDayTouchEnd) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1146
- };
1147
- var onTouchMove = function(e) {
1148
- var _a2;
1149
- (_a2 = dayPicker.onDayTouchMove) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1150
- };
1151
- var onTouchStart = function(e) {
1152
- var _a2;
1153
- (_a2 = dayPicker.onDayTouchStart) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1154
- };
1155
- var onKeyUp = function(e) {
1156
- var _a2;
1157
- (_a2 = dayPicker.onDayKeyUp) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1158
- };
1159
- var onKeyDown = function(e) {
1160
- var _a2;
1161
- switch (e.key) {
1162
- case "ArrowLeft":
1163
- e.preventDefault();
1164
- e.stopPropagation();
1165
- dayPicker.dir === "rtl" ? focusDayAfter() : focusDayBefore();
1166
- break;
1167
- case "ArrowRight":
1168
- e.preventDefault();
1169
- e.stopPropagation();
1170
- dayPicker.dir === "rtl" ? focusDayBefore() : focusDayAfter();
1171
- break;
1172
- case "ArrowDown":
1173
- e.preventDefault();
1174
- e.stopPropagation();
1175
- focusWeekAfter();
1176
- break;
1177
- case "ArrowUp":
1178
- e.preventDefault();
1179
- e.stopPropagation();
1180
- focusWeekBefore();
1181
- break;
1182
- case "PageUp":
1183
- e.preventDefault();
1184
- e.stopPropagation();
1185
- e.shiftKey ? focusYearBefore() : focusMonthBefore();
1186
- break;
1187
- case "PageDown":
1188
- e.preventDefault();
1189
- e.stopPropagation();
1190
- e.shiftKey ? focusYearAfter() : focusMonthAfter();
1191
- break;
1192
- case "Home":
1193
- e.preventDefault();
1194
- e.stopPropagation();
1195
- focusStartOfWeek();
1196
- break;
1197
- case "End":
1198
- e.preventDefault();
1199
- e.stopPropagation();
1200
- focusEndOfWeek();
1201
- break;
1202
- }
1203
- (_a2 = dayPicker.onDayKeyDown) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1204
- };
1205
- var eventHandlers = {
1206
- onClick,
1207
- onFocus,
1208
- onBlur,
1209
- onKeyDown,
1210
- onKeyUp,
1211
- onMouseEnter,
1212
- onMouseLeave,
1213
- onPointerEnter,
1214
- onPointerLeave,
1215
- onTouchCancel,
1216
- onTouchEnd,
1217
- onTouchMove,
1218
- onTouchStart
1376
+ return {
1377
+ selected,
1378
+ select,
1379
+ isSelected
1219
1380
  };
1220
- return eventHandlers;
1221
- }
1222
- function useSelectedDays() {
1223
- var dayPicker = useDayPicker();
1224
- var single = useSelectSingle();
1225
- var multiple = useSelectMultiple();
1226
- var range = useSelectRange();
1227
- var selectedDays = isDayPickerSingle(dayPicker) ? single.selected : isDayPickerMultiple(dayPicker) ? multiple.selected : isDayPickerRange(dayPicker) ? range.selected : void 0;
1228
- return selectedDays;
1229
- }
1230
- function isInternalModifier(modifier) {
1231
- return Object.values(InternalModifier).includes(modifier);
1232
- }
1233
- function getDayClassNames(dayPicker, activeModifiers) {
1234
- var classNames2 = [dayPicker.classNames.day];
1235
- Object.keys(activeModifiers).forEach(function(modifier) {
1236
- var customClassName = dayPicker.modifiersClassNames[modifier];
1237
- if (customClassName) {
1238
- classNames2.push(customClassName);
1239
- } else if (isInternalModifier(modifier)) {
1240
- var internalClassName = dayPicker.classNames["day_".concat(modifier)];
1241
- if (internalClassName) {
1242
- classNames2.push(internalClassName);
1381
+ }
1382
+ function addToRange(date, initialRange, min2 = 0, max2 = 0, required = false, dateLib = defaultDateLib) {
1383
+ const { from, to } = initialRange || {};
1384
+ const { isSameDay: isSameDay2, isAfter: isAfter2, isBefore: isBefore2 } = dateLib;
1385
+ let range;
1386
+ if (!from && !to) {
1387
+ range = { from: date, to: min2 > 0 ? void 0 : date };
1388
+ } else if (from && !to) {
1389
+ if (isSameDay2(from, date)) {
1390
+ if (required) {
1391
+ range = { from, to: void 0 };
1392
+ } else {
1393
+ range = void 0;
1243
1394
  }
1395
+ } else if (isBefore2(date, from)) {
1396
+ range = { from: date, to: from };
1397
+ } else {
1398
+ range = { from, to: date };
1244
1399
  }
1245
- });
1246
- return classNames2;
1400
+ } else if (from && to) {
1401
+ if (isSameDay2(from, date) && isSameDay2(to, date)) {
1402
+ if (required) {
1403
+ range = { from, to };
1404
+ } else {
1405
+ range = void 0;
1406
+ }
1407
+ } else if (isSameDay2(from, date)) {
1408
+ range = { from, to: min2 > 0 ? void 0 : date };
1409
+ } else if (isSameDay2(to, date)) {
1410
+ range = { from: date, to: min2 > 0 ? void 0 : date };
1411
+ } else if (isBefore2(date, from)) {
1412
+ range = { from: date, to };
1413
+ } else if (isAfter2(date, from)) {
1414
+ range = { from, to: date };
1415
+ } else if (isAfter2(date, to)) {
1416
+ range = { from, to: date };
1417
+ } else {
1418
+ throw new Error("Invalid range");
1419
+ }
1420
+ }
1421
+ if ((range == null ? void 0 : range.from) && (range == null ? void 0 : range.to)) {
1422
+ const diff = dateLib.differenceInCalendarDays(range.to, range.from);
1423
+ if (max2 > 0 && diff > max2) {
1424
+ range = { from: date, to: void 0 };
1425
+ } else if (min2 > 1 && diff < min2) {
1426
+ range = { from: date, to: void 0 };
1427
+ }
1428
+ }
1429
+ return range;
1247
1430
  }
1248
- function getDayStyle(dayPicker, activeModifiers) {
1249
- var style = __assign({}, dayPicker.styles.day);
1250
- Object.keys(activeModifiers).forEach(function(modifier) {
1251
- var _a;
1252
- style = __assign(__assign({}, style), (_a = dayPicker.modifiersStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
1431
+ function rangeContainsDayOfWeek(range, dayOfWeek, dateLib = defaultDateLib) {
1432
+ const dayOfWeekArr = !Array.isArray(dayOfWeek) ? [dayOfWeek] : dayOfWeek;
1433
+ let date = range.from;
1434
+ const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
1435
+ const totalDaysLimit = Math.min(totalDays, 6);
1436
+ for (let i = 0; i <= totalDaysLimit; i++) {
1437
+ if (dayOfWeekArr.includes(date.getDay())) {
1438
+ return true;
1439
+ }
1440
+ date = dateLib.addDays(date, 1);
1441
+ }
1442
+ return false;
1443
+ }
1444
+ function rangeOverlaps(rangeLeft, rangeRight, dateLib = defaultDateLib) {
1445
+ return rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) || rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib);
1446
+ }
1447
+ function rangeContainsModifiers(range, modifiers, dateLib = defaultDateLib) {
1448
+ const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
1449
+ const nonFunctionMatchers = matchers.filter((matcher) => typeof matcher !== "function");
1450
+ const nonFunctionMatchersResult = nonFunctionMatchers.some((matcher) => {
1451
+ if (typeof matcher === "boolean")
1452
+ return matcher;
1453
+ if (dateLib.isDate(matcher)) {
1454
+ return rangeIncludesDate(range, matcher, false, dateLib);
1455
+ }
1456
+ if (isDatesArray(matcher, dateLib)) {
1457
+ return matcher.some((date) => rangeIncludesDate(range, date, false, dateLib));
1458
+ }
1459
+ if (isDateRange(matcher)) {
1460
+ if (matcher.from && matcher.to) {
1461
+ return rangeOverlaps(range, { from: matcher.from, to: matcher.to }, dateLib);
1462
+ }
1463
+ return false;
1464
+ }
1465
+ if (isDayOfWeekType(matcher)) {
1466
+ return rangeContainsDayOfWeek(range, matcher.dayOfWeek, dateLib);
1467
+ }
1468
+ if (isDateInterval(matcher)) {
1469
+ const isClosedInterval = dateLib.isAfter(matcher.before, matcher.after);
1470
+ if (isClosedInterval) {
1471
+ return rangeOverlaps(range, {
1472
+ from: dateLib.addDays(matcher.after, 1),
1473
+ to: dateLib.addDays(matcher.before, -1)
1474
+ }, dateLib);
1475
+ }
1476
+ return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
1477
+ }
1478
+ if (isDateAfterType(matcher) || isDateBeforeType(matcher)) {
1479
+ return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
1480
+ }
1481
+ return false;
1253
1482
  });
1254
- return style;
1483
+ if (nonFunctionMatchersResult) {
1484
+ return true;
1485
+ }
1486
+ const functionMatchers = matchers.filter((matcher) => typeof matcher === "function");
1487
+ if (functionMatchers.length) {
1488
+ let date = range.from;
1489
+ const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
1490
+ for (let i = 0; i <= totalDays; i++) {
1491
+ if (functionMatchers.some((matcher) => matcher(date))) {
1492
+ return true;
1493
+ }
1494
+ date = dateLib.addDays(date, 1);
1495
+ }
1496
+ }
1497
+ return false;
1255
1498
  }
1256
- function useDayRender(day, displayMonth, buttonRef) {
1257
- var _a;
1258
- var _b, _c;
1259
- var dayPicker = useDayPicker();
1260
- var focusContext = useFocusContext();
1261
- var activeModifiers = useActiveModifiers(day, displayMonth);
1262
- var eventHandlers = useDayEventHandlers(day, activeModifiers);
1263
- var selectedDays = useSelectedDays();
1264
- var isButton = Boolean(dayPicker.onDayClick || dayPicker.mode !== "default");
1265
- useEffect(function() {
1266
- var _a2;
1267
- if (activeModifiers.outside)
1268
- return;
1269
- if (!focusContext.focusedDay)
1270
- return;
1271
- if (!isButton)
1272
- return;
1273
- if (isSameDay(focusContext.focusedDay, day)) {
1274
- (_a2 = buttonRef.current) === null || _a2 === void 0 ? void 0 : _a2.focus();
1499
+ function useRange(props, dateLib) {
1500
+ const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect } = props;
1501
+ const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1502
+ const selected = !onSelect ? internallySelected : initiallySelected;
1503
+ const isSelected = (date) => selected && rangeIncludesDate(selected, date, false, dateLib);
1504
+ const select = (triggerDate, modifiers, e) => {
1505
+ const { min: min2, max: max2 } = props;
1506
+ const newRange = triggerDate ? addToRange(triggerDate, selected, min2, max2, required, dateLib) : void 0;
1507
+ if (excludeDisabled && disabled && (newRange == null ? void 0 : newRange.from) && newRange.to) {
1508
+ if (rangeContainsModifiers({ from: newRange.from, to: newRange.to }, disabled, dateLib)) {
1509
+ newRange.from = triggerDate;
1510
+ newRange.to = void 0;
1511
+ }
1275
1512
  }
1276
- }, [
1277
- focusContext.focusedDay,
1278
- day,
1279
- buttonRef,
1280
- isButton,
1281
- activeModifiers.outside
1282
- ]);
1283
- var className = getDayClassNames(dayPicker, activeModifiers).join(" ");
1284
- var style = getDayStyle(dayPicker, activeModifiers);
1285
- var isHidden = Boolean(activeModifiers.outside && !dayPicker.showOutsideDays || activeModifiers.hidden);
1286
- var DayContentComponent = (_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent;
1287
- var children = jsx(DayContentComponent, { date: day, displayMonth, activeModifiers });
1288
- var divProps = {
1289
- style,
1290
- className,
1291
- children,
1292
- role: "gridcell"
1513
+ if (!onSelect) {
1514
+ setSelected(newRange);
1515
+ }
1516
+ onSelect == null ? void 0 : onSelect(newRange, triggerDate, modifiers, e);
1517
+ return newRange;
1293
1518
  };
1294
- var isFocusTarget = focusContext.focusTarget && isSameDay(focusContext.focusTarget, day) && !activeModifiers.outside;
1295
- var isFocused = focusContext.focusedDay && isSameDay(focusContext.focusedDay, day);
1296
- var buttonProps = __assign(__assign(__assign({}, divProps), (_a = { disabled: activeModifiers.disabled, role: "gridcell" }, _a["aria-selected"] = activeModifiers.selected, _a.tabIndex = isFocused || isFocusTarget ? 0 : -1, _a)), eventHandlers);
1297
- var dayRender = {
1298
- isButton,
1299
- isHidden,
1300
- activeModifiers,
1301
- selectedDays,
1302
- buttonProps,
1303
- divProps
1519
+ return {
1520
+ selected,
1521
+ select,
1522
+ isSelected
1304
1523
  };
1305
- return dayRender;
1306
- }
1307
- function Day(props) {
1308
- var buttonRef = useRef(null);
1309
- var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
1310
- if (dayRender.isHidden) {
1311
- return jsx("div", { role: "gridcell" });
1312
- }
1313
- if (!dayRender.isButton) {
1314
- return jsx("div", __assign({}, dayRender.divProps));
1315
- }
1316
- return jsx(Button, __assign({ name: "day", ref: buttonRef }, dayRender.buttonProps));
1317
1524
  }
1318
- function WeekNumber(props) {
1319
- var weekNumber = props.number, dates = props.dates;
1320
- var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles2 = _a.styles, classNames2 = _a.classNames, locale = _a.locale, labelWeekNumber2 = _a.labels.labelWeekNumber, formatWeekNumber2 = _a.formatters.formatWeekNumber;
1321
- var content = formatWeekNumber2(Number(weekNumber), { locale });
1322
- if (!onWeekNumberClick) {
1323
- return jsx("span", { className: classNames2.weeknumber, style: styles2.weeknumber, children: content });
1324
- }
1325
- var label = labelWeekNumber2(Number(weekNumber), { locale });
1326
- var handleClick = function(e) {
1327
- onWeekNumberClick(weekNumber, dates, e);
1525
+ function useSingle(props, dateLib) {
1526
+ const { selected: initiallySelected, required, onSelect } = props;
1527
+ const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1528
+ const selected = !onSelect ? internallySelected : initiallySelected;
1529
+ const { isSameDay: isSameDay2 } = dateLib;
1530
+ const isSelected = (compareDate) => {
1531
+ return selected ? isSameDay2(selected, compareDate) : false;
1328
1532
  };
1329
- return jsx(Button, { name: "week-number", "aria-label": label, className: classNames2.weeknumber, style: styles2.weeknumber, onClick: handleClick, children: content });
1330
- }
1331
- function Row(props) {
1332
- var _a, _b;
1333
- var _c = useDayPicker(), styles2 = _c.styles, classNames2 = _c.classNames, showWeekNumber = _c.showWeekNumber, components = _c.components;
1334
- var DayComponent = (_a = components === null || components === void 0 ? void 0 : components.Day) !== null && _a !== void 0 ? _a : Day;
1335
- var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
1336
- var weekNumberCell;
1337
- if (showWeekNumber) {
1338
- weekNumberCell = jsx("td", { className: classNames2.cell, style: styles2.cell, children: jsx(WeeknumberComponent, { number: props.weekNumber, dates: props.dates }) });
1339
- }
1340
- return jsxs("tr", { className: classNames2.row, style: styles2.row, children: [weekNumberCell, props.dates.map(function(date) {
1341
- return jsx("td", { className: classNames2.cell, style: styles2.cell, role: "presentation", children: jsx(DayComponent, { displayMonth: props.displayMonth, date }) }, getUnixTime(date));
1342
- })] });
1343
- }
1344
- function daysToMonthWeeks(fromDate, toDate, options) {
1345
- var toWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? endOfISOWeek(toDate) : endOfWeek(toDate, options);
1346
- var fromWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? startOfISOWeek(fromDate) : startOfWeek(fromDate, options);
1347
- var nOfDays = differenceInCalendarDays(toWeek, fromWeek);
1348
- var days = [];
1349
- for (var i = 0; i <= nOfDays; i++) {
1350
- days.push(addDays(fromWeek, i));
1351
- }
1352
- var weeksInMonth = days.reduce(function(result, date) {
1353
- var weekNumber = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? getISOWeek(date) : getWeek(date, options);
1354
- var existingWeek = result.find(function(value) {
1355
- return value.weekNumber === weekNumber;
1356
- });
1357
- if (existingWeek) {
1358
- existingWeek.dates.push(date);
1359
- return result;
1533
+ const select = (triggerDate, modifiers, e) => {
1534
+ let newDate = triggerDate;
1535
+ if (!required && selected && selected && isSameDay2(triggerDate, selected)) {
1536
+ newDate = void 0;
1360
1537
  }
1361
- result.push({
1362
- weekNumber,
1363
- dates: [date]
1364
- });
1365
- return result;
1366
- }, []);
1367
- return weeksInMonth;
1368
- }
1369
- function getMonthWeeks(month, options) {
1370
- var weeksInMonth = daysToMonthWeeks(startOfMonth(month), endOfMonth(month), options);
1371
- if (options === null || options === void 0 ? void 0 : options.useFixedWeeks) {
1372
- var nrOfMonthWeeks = getWeeksInMonth(month, options);
1373
- if (nrOfMonthWeeks < 6) {
1374
- var lastWeek = weeksInMonth[weeksInMonth.length - 1];
1375
- var lastDate = lastWeek.dates[lastWeek.dates.length - 1];
1376
- var toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks);
1377
- var extraWeeks = daysToMonthWeeks(addWeeks(lastDate, 1), toDate, options);
1378
- weeksInMonth.push.apply(weeksInMonth, extraWeeks);
1379
- }
1380
- }
1381
- return weeksInMonth;
1382
- }
1383
- function Table(props) {
1384
- var _a, _b, _c;
1385
- var _d = useDayPicker(), locale = _d.locale, classNames2 = _d.classNames, styles2 = _d.styles, hideHead = _d.hideHead, fixedWeeks = _d.fixedWeeks, components = _d.components, weekStartsOn = _d.weekStartsOn, firstWeekContainsDate = _d.firstWeekContainsDate, ISOWeek = _d.ISOWeek;
1386
- var weeks = getMonthWeeks(props.displayMonth, {
1387
- useFixedWeeks: Boolean(fixedWeeks),
1388
- ISOWeek,
1389
- locale,
1390
- weekStartsOn,
1391
- firstWeekContainsDate
1392
- });
1393
- var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
1394
- var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
1395
- var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
1396
- return jsxs("table", { id: props.id, className: classNames2.table, style: styles2.table, role: "grid", "aria-labelledby": props["aria-labelledby"], children: [!hideHead && jsx(HeadComponent, {}), jsx("tbody", { className: classNames2.tbody, style: styles2.tbody, children: weeks.map(function(week) {
1397
- return jsx(RowComponent, { displayMonth: props.displayMonth, dates: week.dates, weekNumber: week.weekNumber }, week.weekNumber);
1398
- }) }), jsx(FooterComponent, { displayMonth: props.displayMonth })] });
1399
- }
1400
- function canUseDOM() {
1401
- return !!(typeof window !== "undefined" && window.document && window.document.createElement);
1402
- }
1403
- var useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
1404
- var serverHandoffComplete = false;
1405
- var id = 0;
1406
- function genId() {
1407
- return "react-day-picker-".concat(++id);
1408
- }
1409
- function useId(providedId) {
1410
- var _a;
1411
- var initialId = providedId !== null && providedId !== void 0 ? providedId : serverHandoffComplete ? genId() : null;
1412
- var _b = useState(initialId), id2 = _b[0], setId = _b[1];
1413
- useIsomorphicLayoutEffect(function() {
1414
- if (id2 === null) {
1415
- setId(genId());
1538
+ if (!onSelect) {
1539
+ setSelected(newDate);
1416
1540
  }
1417
- }, []);
1418
- useEffect(function() {
1419
- if (serverHandoffComplete === false) {
1420
- serverHandoffComplete = true;
1541
+ if (required) {
1542
+ onSelect == null ? void 0 : onSelect(newDate, triggerDate, modifiers, e);
1543
+ } else {
1544
+ onSelect == null ? void 0 : onSelect(newDate, triggerDate, modifiers, e);
1421
1545
  }
1422
- }, []);
1423
- return (_a = providedId !== null && providedId !== void 0 ? providedId : id2) !== null && _a !== void 0 ? _a : void 0;
1546
+ return newDate;
1547
+ };
1548
+ return {
1549
+ selected,
1550
+ select,
1551
+ isSelected
1552
+ };
1424
1553
  }
1425
- function Month(props) {
1426
- var _a;
1427
- var _b;
1428
- var dayPicker = useDayPicker();
1429
- var dir = dayPicker.dir, classNames2 = dayPicker.classNames, styles2 = dayPicker.styles, components = dayPicker.components;
1430
- var displayMonths = useNavigation().displayMonths;
1431
- var captionId = useId(dayPicker.id ? "".concat(dayPicker.id, "-").concat(props.displayIndex) : void 0);
1432
- var tableId = dayPicker.id ? "".concat(dayPicker.id, "-grid-").concat(props.displayIndex) : void 0;
1433
- var className = [classNames2.month];
1434
- var style = styles2.month;
1435
- var isStart = props.displayIndex === 0;
1436
- var isEnd = props.displayIndex === displayMonths.length - 1;
1437
- var isCenter = !isStart && !isEnd;
1438
- if (dir === "rtl") {
1439
- _a = [isStart, isEnd], isEnd = _a[0], isStart = _a[1];
1440
- }
1441
- if (isStart) {
1442
- className.push(classNames2.caption_start);
1443
- style = __assign(__assign({}, style), styles2.caption_start);
1444
- }
1445
- if (isEnd) {
1446
- className.push(classNames2.caption_end);
1447
- style = __assign(__assign({}, style), styles2.caption_end);
1448
- }
1449
- if (isCenter) {
1450
- className.push(classNames2.caption_between);
1451
- style = __assign(__assign({}, style), styles2.caption_between);
1452
- }
1453
- var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
1454
- return jsxs("div", { className: className.join(" "), style, children: [jsx(CaptionComponent, { id: captionId, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(Table, { id: tableId, "aria-labelledby": captionId, displayMonth: props.displayMonth })] }, props.displayIndex);
1554
+ function useSelection(props, dateLib) {
1555
+ const single = useSingle(props, dateLib);
1556
+ const multi = useMulti(props, dateLib);
1557
+ const range = useRange(props, dateLib);
1558
+ switch (props.mode) {
1559
+ case "single":
1560
+ return single;
1561
+ case "multiple":
1562
+ return multi;
1563
+ case "range":
1564
+ return range;
1565
+ default:
1566
+ return void 0;
1567
+ }
1455
1568
  }
1456
- function Months(props) {
1457
- var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
1458
- return jsx("div", { className: classNames2.months, style: styles2.months, children: props.children });
1459
- }
1460
- function Root(_a) {
1461
- var _b, _c;
1462
- var initialProps = _a.initialProps;
1463
- var dayPicker = useDayPicker();
1464
- var focusContext = useFocusContext();
1465
- var navigation = useNavigation();
1466
- var _d = useState(false), hasInitialFocus = _d[0], setHasInitialFocus = _d[1];
1467
- useEffect(function() {
1468
- if (!dayPicker.initialFocus)
1469
- return;
1470
- if (!focusContext.focusTarget)
1471
- return;
1472
- if (hasInitialFocus)
1473
- return;
1474
- focusContext.focus(focusContext.focusTarget);
1475
- setHasInitialFocus(true);
1569
+ function DayPicker(props) {
1570
+ const { components: components2, formatters, labels, dateLib, locale, classNames: classNames2 } = useMemo(() => {
1571
+ const locale2 = { ...enUS$1, ...props.locale };
1572
+ const dateLib2 = new DateLib({
1573
+ locale: locale2,
1574
+ weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn,
1575
+ firstWeekContainsDate: props.firstWeekContainsDate,
1576
+ useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
1577
+ useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens
1578
+ }, props.dateLib);
1579
+ return {
1580
+ dateLib: dateLib2,
1581
+ components: getComponents(props.components),
1582
+ formatters: getFormatters(props.formatters),
1583
+ labels: { ...defaultLabels, ...props.labels },
1584
+ locale: locale2,
1585
+ classNames: { ...getDefaultClassNames(), ...props.classNames }
1586
+ };
1476
1587
  }, [
1477
- dayPicker.initialFocus,
1478
- hasInitialFocus,
1479
- focusContext.focus,
1480
- focusContext.focusTarget,
1481
- focusContext
1588
+ props.classNames,
1589
+ props.components,
1590
+ props.dateLib,
1591
+ props.firstWeekContainsDate,
1592
+ props.formatters,
1593
+ props.labels,
1594
+ props.locale,
1595
+ props.useAdditionalDayOfYearTokens,
1596
+ props.useAdditionalWeekYearTokens,
1597
+ props.weekStartsOn,
1598
+ props.broadcastCalendar
1482
1599
  ]);
1483
- var classNames2 = [dayPicker.classNames.root, dayPicker.className];
1484
- if (dayPicker.numberOfMonths > 1) {
1485
- classNames2.push(dayPicker.classNames.multiple_months);
1486
- }
1487
- if (dayPicker.showWeekNumber) {
1488
- classNames2.push(dayPicker.classNames.with_weeknumber);
1489
- }
1490
- var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
1491
- var dataAttributes = Object.keys(initialProps).filter(function(key) {
1492
- return key.startsWith("data-");
1493
- }).reduce(function(attrs, key) {
1494
- var _a2;
1495
- return __assign(__assign({}, attrs), (_a2 = {}, _a2[key] = initialProps[key], _a2));
1496
- }, {});
1497
- var MonthsComponent = (_c = (_b = initialProps.components) === null || _b === void 0 ? void 0 : _b.Months) !== null && _c !== void 0 ? _c : Months;
1498
- return jsx("div", __assign({ className: classNames2.join(" "), style, dir: dayPicker.dir, id: dayPicker.id, nonce: initialProps.nonce, title: initialProps.title, lang: initialProps.lang }, dataAttributes, { children: jsx(MonthsComponent, { children: navigation.displayMonths.map(function(month, i) {
1499
- return jsx(Month, { displayIndex: i, displayMonth: month }, i);
1500
- }) }) }));
1501
- }
1502
- function RootProvider(props) {
1503
- var children = props.children, initialProps = __rest(props, ["children"]);
1504
- return jsx(DayPickerProvider, { initialProps, children: jsx(NavigationProvider, { children: jsx(SelectSingleProvider, { initialProps, children: jsx(SelectMultipleProvider, { initialProps, children: jsx(SelectRangeProvider, { initialProps, children: jsx(ModifiersProvider, { children: jsx(FocusProvider, { children }) }) }) }) }) }) });
1505
- }
1506
- function DayPicker(props) {
1507
- return jsx(RootProvider, __assign({}, props, { children: jsx(Root, { initialProps: props }) }));
1600
+ const { captionLayout, mode, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles: styles2 } = props;
1601
+ const { formatCaption: formatCaption2, formatDay: formatDay2, formatMonthDropdown: formatMonthDropdown2, formatWeekNumber: formatWeekNumber2, formatWeekNumberHeader: formatWeekNumberHeader2, formatWeekdayName: formatWeekdayName2, formatYearDropdown: formatYearDropdown2 } = formatters;
1602
+ const calendar = useCalendar(props, dateLib);
1603
+ const { days, months, navStart, navEnd, previousMonth, nextMonth, goToMonth } = calendar;
1604
+ const getModifiers = useGetModifiers(days, props, dateLib);
1605
+ const { isSelected, select, selected: selectedValue } = useSelection(props, dateLib) ?? {};
1606
+ const { blur, focused, isFocusTarget, moveFocus, setFocused } = useFocus(props, calendar, getModifiers, isSelected ?? (() => false), dateLib);
1607
+ const { labelDayButton: labelDayButton2, labelGridcell: labelGridcell2, labelGrid: labelGrid2, labelMonthDropdown: labelMonthDropdown2, labelNav: labelNav2, labelWeekday: labelWeekday2, labelWeekNumber: labelWeekNumber2, labelWeekNumberHeader: labelWeekNumberHeader2, labelYearDropdown: labelYearDropdown2 } = labels;
1608
+ const weekdays = useMemo(() => getWeekdays(dateLib, props.ISOWeek, props.timeZone), [dateLib, props.ISOWeek, props.timeZone]);
1609
+ const isInteractive = mode !== void 0 || onDayClick !== void 0;
1610
+ const handlePreviousClick = useCallback(() => {
1611
+ if (!previousMonth)
1612
+ return;
1613
+ goToMonth(previousMonth);
1614
+ onPrevClick == null ? void 0 : onPrevClick(previousMonth);
1615
+ }, [previousMonth, goToMonth, onPrevClick]);
1616
+ const handleNextClick = useCallback(() => {
1617
+ if (!nextMonth)
1618
+ return;
1619
+ goToMonth(nextMonth);
1620
+ onNextClick == null ? void 0 : onNextClick(nextMonth);
1621
+ }, [goToMonth, nextMonth, onNextClick]);
1622
+ const handleDayClick = useCallback((day, m) => (e) => {
1623
+ e.preventDefault();
1624
+ e.stopPropagation();
1625
+ setFocused(day);
1626
+ select == null ? void 0 : select(day.date, m, e);
1627
+ onDayClick == null ? void 0 : onDayClick(day.date, m, e);
1628
+ }, [select, onDayClick, setFocused]);
1629
+ const handleDayFocus = useCallback((day, m) => (e) => {
1630
+ setFocused(day);
1631
+ onDayFocus == null ? void 0 : onDayFocus(day.date, m, e);
1632
+ }, [onDayFocus, setFocused]);
1633
+ const handleDayBlur = useCallback((day, m) => (e) => {
1634
+ blur();
1635
+ onDayBlur == null ? void 0 : onDayBlur(day.date, m, e);
1636
+ }, [blur, onDayBlur]);
1637
+ const handleDayKeyDown = useCallback((day, modifiers) => (e) => {
1638
+ const keyMap = {
1639
+ ArrowLeft: ["day", props.dir === "rtl" ? "after" : "before"],
1640
+ ArrowRight: ["day", props.dir === "rtl" ? "before" : "after"],
1641
+ ArrowDown: ["week", "after"],
1642
+ ArrowUp: ["week", "before"],
1643
+ PageUp: [e.shiftKey ? "year" : "month", "before"],
1644
+ PageDown: [e.shiftKey ? "year" : "month", "after"],
1645
+ Home: ["startOfWeek", "before"],
1646
+ End: ["endOfWeek", "after"]
1647
+ };
1648
+ if (keyMap[e.key]) {
1649
+ e.preventDefault();
1650
+ e.stopPropagation();
1651
+ const [moveBy, moveDir] = keyMap[e.key];
1652
+ moveFocus(moveBy, moveDir);
1653
+ }
1654
+ onDayKeyDown == null ? void 0 : onDayKeyDown(day.date, modifiers, e);
1655
+ }, [moveFocus, onDayKeyDown, props.dir]);
1656
+ const handleDayMouseEnter = useCallback((day, modifiers) => (e) => {
1657
+ onDayMouseEnter == null ? void 0 : onDayMouseEnter(day.date, modifiers, e);
1658
+ }, [onDayMouseEnter]);
1659
+ const handleDayMouseLeave = useCallback((day, modifiers) => (e) => {
1660
+ onDayMouseLeave == null ? void 0 : onDayMouseLeave(day.date, modifiers, e);
1661
+ }, [onDayMouseLeave]);
1662
+ const handleMonthChange = useCallback((date) => (e) => {
1663
+ const selectedMonth = Number(e.target.value);
1664
+ const month = dateLib.setMonth(dateLib.startOfMonth(date), selectedMonth);
1665
+ goToMonth(month);
1666
+ }, [dateLib, goToMonth]);
1667
+ const handleYearChange = useCallback((date) => (e) => {
1668
+ const selectedYear = Number(e.target.value);
1669
+ const month = dateLib.setYear(dateLib.startOfMonth(date), selectedYear);
1670
+ goToMonth(month);
1671
+ }, [dateLib, goToMonth]);
1672
+ const { className, style } = useMemo(() => ({
1673
+ className: [classNames2[UI.Root], props.className].filter(Boolean).join(" "),
1674
+ style: { ...styles2 == null ? void 0 : styles2[UI.Root], ...props.style }
1675
+ }), [classNames2, props.className, props.style, styles2]);
1676
+ const dataAttributes = getDataAttributes(props);
1677
+ const contextValue = {
1678
+ dayPickerProps: props,
1679
+ selected: selectedValue,
1680
+ select,
1681
+ isSelected,
1682
+ months,
1683
+ nextMonth,
1684
+ previousMonth,
1685
+ goToMonth,
1686
+ getModifiers,
1687
+ components: components2,
1688
+ classNames: classNames2,
1689
+ styles: styles2,
1690
+ labels,
1691
+ formatters
1692
+ };
1693
+ return React.createElement(
1694
+ dayPickerContext.Provider,
1695
+ { value: contextValue },
1696
+ React.createElement(
1697
+ components2.Root,
1698
+ { className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], ...dataAttributes },
1699
+ React.createElement(
1700
+ components2.Months,
1701
+ { className: classNames2[UI.Months], style: styles2 == null ? void 0 : styles2[UI.Months] },
1702
+ !props.hideNavigation && React.createElement(components2.Nav, { className: classNames2[UI.Nav], style: styles2 == null ? void 0 : styles2[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
1703
+ months.map((calendarMonth, displayIndex) => {
1704
+ const dropdownMonths = getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib);
1705
+ const dropdownYears = getYearOptions(navStart, navEnd, formatters, dateLib);
1706
+ return React.createElement(
1707
+ components2.Month,
1708
+ { className: classNames2[UI.Month], style: styles2 == null ? void 0 : styles2[UI.Month], key: displayIndex, displayIndex, calendarMonth },
1709
+ React.createElement(components2.MonthCaption, { className: classNames2[UI.MonthCaption], style: styles2 == null ? void 0 : styles2[UI.MonthCaption], calendarMonth, displayIndex }, (captionLayout == null ? void 0 : captionLayout.startsWith("dropdown")) ? React.createElement(
1710
+ components2.DropdownNav,
1711
+ { className: classNames2[UI.Dropdowns], style: styles2 == null ? void 0 : styles2[UI.Dropdowns] },
1712
+ captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { className: classNames2[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options: dropdownMonths, style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: calendarMonth.date.getMonth() }) : React.createElement("span", { role: "status", "aria-live": "polite" }, formatMonthDropdown2(calendarMonth.date.getMonth(), locale)),
1713
+ captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { className: classNames2[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options: dropdownYears, style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: calendarMonth.date.getFullYear() }) : React.createElement("span", { role: "status", "aria-live": "polite" }, formatYearDropdown2(calendarMonth.date.getFullYear()))
1714
+ ) : React.createElement(components2.CaptionLabel, { className: classNames2[UI.CaptionLabel], role: "status", "aria-live": "polite" }, formatCaption2(calendarMonth.date, dateLib.options, dateLib))),
1715
+ React.createElement(
1716
+ components2.MonthGrid,
1717
+ { role: "grid", "aria-multiselectable": mode === "multiple" || mode === "range", "aria-label": labelGrid2(calendarMonth.date, dateLib.options, dateLib) || void 0, className: classNames2[UI.MonthGrid], style: styles2 == null ? void 0 : styles2[UI.MonthGrid] },
1718
+ !props.hideWeekdays && React.createElement(
1719
+ components2.Weekdays,
1720
+ { className: classNames2[UI.Weekdays], style: styles2 == null ? void 0 : styles2[UI.Weekdays] },
1721
+ showWeekNumber && React.createElement(components2.WeekNumberHeader, { "aria-label": labelWeekNumberHeader2(dateLib.options), className: classNames2[UI.WeekNumberHeader], style: styles2 == null ? void 0 : styles2[UI.WeekNumberHeader], scope: "col" }, formatWeekNumberHeader2()),
1722
+ weekdays.map((weekday, i) => React.createElement(components2.Weekday, { "aria-label": labelWeekday2(weekday, dateLib.options, dateLib), className: classNames2[UI.Weekday], key: i, style: styles2 == null ? void 0 : styles2[UI.Weekday], scope: "col" }, formatWeekdayName2(weekday, dateLib.options, dateLib)))
1723
+ ),
1724
+ React.createElement(components2.Weeks, { className: classNames2[UI.Weeks], style: styles2 == null ? void 0 : styles2[UI.Weeks] }, calendarMonth.weeks.map((week, weekIndex) => {
1725
+ return React.createElement(
1726
+ components2.Week,
1727
+ { className: classNames2[UI.Week], key: week.weekNumber, style: styles2 == null ? void 0 : styles2[UI.Week], week },
1728
+ showWeekNumber && React.createElement(components2.WeekNumber, { week, style: styles2 == null ? void 0 : styles2[UI.WeekNumber], "aria-label": labelWeekNumber2(week.weekNumber, {
1729
+ locale
1730
+ }), className: classNames2[UI.WeekNumber], scope: "row", role: "rowheader" }, formatWeekNumber2(week.weekNumber)),
1731
+ week.days.map((day) => {
1732
+ const { date } = day;
1733
+ const modifiers = getModifiers(day);
1734
+ modifiers[DayFlag.focused] = !modifiers.hidden && Boolean(focused == null ? void 0 : focused.isEqualTo(day));
1735
+ modifiers[SelectionState.selected] = !modifiers.disabled && ((isSelected == null ? void 0 : isSelected(date)) || modifiers.selected);
1736
+ if (isDateRange(selectedValue)) {
1737
+ const { from, to } = selectedValue;
1738
+ modifiers[SelectionState.range_start] = Boolean(from && to && dateLib.isSameDay(date, from));
1739
+ modifiers[SelectionState.range_end] = Boolean(from && to && dateLib.isSameDay(date, to));
1740
+ modifiers[SelectionState.range_middle] = rangeIncludesDate(selectedValue, date, true, dateLib);
1741
+ }
1742
+ const style2 = getStyleForModifiers(modifiers, styles2, props.modifiersStyles);
1743
+ const className2 = getClassNamesForModifiers(modifiers, classNames2, props.modifiersClassNames);
1744
+ const ariaLabel = !isInteractive && !modifiers.hidden ? labelGridcell2(date, modifiers, dateLib.options, dateLib) : void 0;
1745
+ return React.createElement(components2.Day, { key: `${dateLib.format(date, "yyyy-MM-dd")}_${dateLib.format(day.displayMonth, "yyyy-MM")}`, day, modifiers, className: className2.join(" "), style: style2, role: "gridcell", "aria-selected": modifiers.selected || void 0, "aria-label": ariaLabel, "data-day": dateLib.format(date, "yyyy-MM-dd"), "data-month": day.outside ? dateLib.format(date, "yyyy-MM") : void 0, "data-selected": modifiers.selected || void 0, "data-disabled": modifiers.disabled || void 0, "data-hidden": modifiers.hidden || void 0, "data-outside": day.outside || void 0, "data-focused": modifiers.focused || void 0, "data-today": modifiers.today || void 0 }, !modifiers.hidden && isInteractive ? React.createElement(components2.DayButton, { className: classNames2[UI.DayButton], style: styles2 == null ? void 0 : styles2[UI.DayButton], type: "button", day, modifiers, disabled: modifiers.disabled || void 0, tabIndex: isFocusTarget(day) ? 0 : -1, "aria-label": labelDayButton2(date, modifiers, dateLib.options, dateLib), onClick: handleDayClick(day, modifiers), onBlur: handleDayBlur(day, modifiers), onFocus: handleDayFocus(day, modifiers), onKeyDown: handleDayKeyDown(day, modifiers), onMouseEnter: handleDayMouseEnter(day, modifiers), onMouseLeave: handleDayMouseLeave(day, modifiers) }, formatDay2(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay2(day.date, dateLib.options, dateLib));
1746
+ })
1747
+ );
1748
+ }))
1749
+ )
1750
+ );
1751
+ })
1752
+ ),
1753
+ props.footer && React.createElement(components2.Footer, { className: classNames2[UI.Footer], style: styles2 == null ? void 0 : styles2[UI.Footer], role: "status", "aria-live": "polite" }, props.footer)
1754
+ )
1755
+ );
1508
1756
  }
1509
1757
  const BUBBLE_WIDTH_PX = 329;
1510
1758
  const WINDOW_MARGIN_PX = 12;
@@ -1631,10 +1879,11 @@ const getArrowStyle = (bubbleStyle, controllerSize, verticalPosition) => {
1631
1879
  };
1632
1880
  const DatePickerPopup = (props) => {
1633
1881
  const { datepickerWrapperRef, footer, inputRef, testId, variant, zIndex, ...rest } = props;
1882
+ const today = /* @__PURE__ */ new Date();
1634
1883
  const arrowRef = useRef(null);
1635
1884
  const [controllerSize, setControllerSize] = useState();
1636
1885
  const bubbleSize = useSize(datepickerWrapperRef);
1637
- const controllerisVisible = useIsVisible(inputRef, 0);
1886
+ const controllerisVisible = useIsVisible(datepickerWrapperRef, 0);
1638
1887
  useFocusTrap(datepickerWrapperRef, true);
1639
1888
  const updateControllerSize = () => {
1640
1889
  var _a;
@@ -1664,14 +1913,20 @@ const DatePickerPopup = (props) => {
1664
1913
  /* @__PURE__ */ jsx("div", { className: datepickerPopupContainerClasses, "data-testid": testId, ref: datepickerWrapperRef, style: { ...bubbleStyle, zIndex }, children: /* @__PURE__ */ jsx(
1665
1914
  DayPicker,
1666
1915
  {
1667
- captionLayout: "dropdown-buttons",
1916
+ captionLayout: "dropdown",
1668
1917
  classNames: datePickerClassNames,
1669
1918
  mode: "single",
1670
1919
  style: { "--rdp-cell-size": getSpacer("l") },
1671
- modifiersClassNames: { today: styles["day--today"], selected: styles["day_selected"], disabled: styles["day--disabled"] },
1920
+ modifiersClassNames: {
1921
+ today: styles["day--today"],
1922
+ selected: styles["day--selected"],
1923
+ disabled: styles["day--disabled"]
1924
+ },
1672
1925
  footer: /* @__PURE__ */ jsx("span", { className: styles["footer-wrapper"], children: footer }),
1673
1926
  fixedWeeks: true,
1674
- ...rest
1927
+ ...rest,
1928
+ startMonth: props.startMonth ?? new Date(today.getFullYear() - 100, today.getMonth(), 1),
1929
+ endMonth: props.endMonth ?? new Date(today.getFullYear() + 100, today.getMonth(), 1)
1675
1930
  }
1676
1931
  ) }),
1677
1932
  /* @__PURE__ */ jsx("div", { ref: arrowRef, className: popupArrowClasses, style: { ...arrowStyle, zIndex } })
@@ -1902,8 +2157,8 @@ const DatePicker = React.forwardRef((props, ref) => {
1902
2157
  disabled: disabledDays,
1903
2158
  datepickerWrapperRef,
1904
2159
  footer: footerContent,
1905
- fromDate: minDate,
1906
- toDate: maxDate,
2160
+ startMonth: minDate,
2161
+ endMonth: maxDate,
1907
2162
  inputRef: refObject,
1908
2163
  locale,
1909
2164
  month,