@uxf/datepicker 13.0.3 → 14.1.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,100 +1,249 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDatePickerNavigation = useDatePickerNavigation;
4
- const react_1 = require("react");
4
+ const compiler_runtime_1 = require("react/compiler-runtime");
5
5
  const create_date_string_1 = require("../utils/create-date-string");
6
6
  const date_string_1 = require("../utils/date-string");
7
7
  const get_initial_months_1 = require("../utils/get-initial-months");
8
8
  const get_next_active_month_1 = require("../utils/get-next-active-month");
9
- function useDatePickerNavigation({ activeMonths, setActiveMonths, setFocusedDate, minBookingDate, maxBookingDate, numberOfMonths, }) {
9
+ function useDatePickerNavigation(t0) {
10
10
  var _a, _b;
11
- const goToPrevMonths = (0, react_1.useCallback)(() => {
12
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1);
13
- setActiveMonths(newActiveMonths);
14
- setFocusedDate(null);
15
- return newActiveMonths;
16
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
17
- const goToPrevMonthsByOneMonth = (0, react_1.useCallback)(() => {
18
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1, 1);
19
- setActiveMonths(newActiveMonths);
20
- setFocusedDate(null);
21
- return newActiveMonths;
22
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
23
- const goToNextMonths = (0, react_1.useCallback)(() => {
24
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1);
25
- setActiveMonths(newActiveMonths);
26
- setFocusedDate(null);
27
- return newActiveMonths;
28
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
29
- const goToNextMonthsByOneMonth = (0, react_1.useCallback)(() => {
30
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1, 1);
31
- setActiveMonths(newActiveMonths);
32
- setFocusedDate(null);
33
- return newActiveMonths;
34
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
35
- const goToDate = (0, react_1.useCallback)((date) => {
36
- const newActiveMonths = (0, get_initial_months_1.getInitialMonths)(numberOfMonths, date);
37
- setActiveMonths(newActiveMonths);
38
- setFocusedDate(null);
39
- return newActiveMonths;
40
- }, [numberOfMonths, setActiveMonths, setFocusedDate]);
41
- const goToPrevYear = (0, react_1.useCallback)((numYears = 1) => {
42
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -(numYears * 12 - numberOfMonths + 1));
43
- setActiveMonths(newActiveMonths);
44
- setFocusedDate(null);
45
- return newActiveMonths;
46
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
47
- const goToNextYear = (0, react_1.useCallback)((numYears = 1) => {
48
- const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, numYears * 12 - numberOfMonths + 1);
49
- setActiveMonths(newActiveMonths);
50
- setFocusedDate(null);
51
- return newActiveMonths;
52
- }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
53
- const firstMonthStr = (0, date_string_1.toDateString)((_b = (_a = activeMonths.at(0)) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : new Date());
54
- const lastMonthStr = (0, date_string_1.toDateString)(activeMonths[activeMonths.length - 1].date);
55
- const firstYear = parseInt(firstMonthStr.slice(0, 4), 10);
56
- const lastYear = parseInt(lastMonthStr.slice(0, 4), 10);
57
- // Can navigate back if the first active month is not before minBookingDate.
58
- const canGoToPrevMonth = !minBookingDate || minBookingDate <= firstMonthStr;
59
- // Can navigate forward if the month after the last active month is still within maxBookingDate.
60
- const canGoToNextMonth = !maxBookingDate || (0, date_string_1.addMonths)(lastMonthStr, 1) <= maxBookingDate;
61
- // Can navigate back a year if Dec 31 of (firstYear - 1) is still on or after minBookingDate.
11
+ const $ = (0, compiler_runtime_1.c)(62);
12
+ const { activeMonths, setActiveMonths, setFocusedDate, minBookingDate, maxBookingDate, numberOfMonths } = t0;
13
+ let t1;
14
+ if ($[0] !== activeMonths || $[1] !== numberOfMonths || $[2] !== setActiveMonths || $[3] !== setFocusedDate) {
15
+ t1 = () => {
16
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1);
17
+ setActiveMonths(newActiveMonths);
18
+ setFocusedDate(null);
19
+ return newActiveMonths;
20
+ };
21
+ $[0] = activeMonths;
22
+ $[1] = numberOfMonths;
23
+ $[2] = setActiveMonths;
24
+ $[3] = setFocusedDate;
25
+ $[4] = t1;
26
+ }
27
+ else {
28
+ t1 = $[4];
29
+ }
30
+ const goToPrevMonths = t1;
31
+ let t2;
32
+ if ($[5] !== activeMonths || $[6] !== numberOfMonths || $[7] !== setActiveMonths || $[8] !== setFocusedDate) {
33
+ t2 = () => {
34
+ const newActiveMonths_0 = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1, 1);
35
+ setActiveMonths(newActiveMonths_0);
36
+ setFocusedDate(null);
37
+ return newActiveMonths_0;
38
+ };
39
+ $[5] = activeMonths;
40
+ $[6] = numberOfMonths;
41
+ $[7] = setActiveMonths;
42
+ $[8] = setFocusedDate;
43
+ $[9] = t2;
44
+ }
45
+ else {
46
+ t2 = $[9];
47
+ }
48
+ const goToPrevMonthsByOneMonth = t2;
49
+ let t3;
50
+ if ($[10] !== activeMonths || $[11] !== numberOfMonths || $[12] !== setActiveMonths || $[13] !== setFocusedDate) {
51
+ t3 = () => {
52
+ const newActiveMonths_1 = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1);
53
+ setActiveMonths(newActiveMonths_1);
54
+ setFocusedDate(null);
55
+ return newActiveMonths_1;
56
+ };
57
+ $[10] = activeMonths;
58
+ $[11] = numberOfMonths;
59
+ $[12] = setActiveMonths;
60
+ $[13] = setFocusedDate;
61
+ $[14] = t3;
62
+ }
63
+ else {
64
+ t3 = $[14];
65
+ }
66
+ const goToNextMonths = t3;
67
+ let t4;
68
+ if ($[15] !== activeMonths || $[16] !== numberOfMonths || $[17] !== setActiveMonths || $[18] !== setFocusedDate) {
69
+ t4 = () => {
70
+ const newActiveMonths_2 = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1, 1);
71
+ setActiveMonths(newActiveMonths_2);
72
+ setFocusedDate(null);
73
+ return newActiveMonths_2;
74
+ };
75
+ $[15] = activeMonths;
76
+ $[16] = numberOfMonths;
77
+ $[17] = setActiveMonths;
78
+ $[18] = setFocusedDate;
79
+ $[19] = t4;
80
+ }
81
+ else {
82
+ t4 = $[19];
83
+ }
84
+ const goToNextMonthsByOneMonth = t4;
85
+ let t5;
86
+ if ($[20] !== numberOfMonths || $[21] !== setActiveMonths || $[22] !== setFocusedDate) {
87
+ t5 = date => {
88
+ const newActiveMonths_3 = (0, get_initial_months_1.getInitialMonths)(numberOfMonths, date);
89
+ setActiveMonths(newActiveMonths_3);
90
+ setFocusedDate(null);
91
+ return newActiveMonths_3;
92
+ };
93
+ $[20] = numberOfMonths;
94
+ $[21] = setActiveMonths;
95
+ $[22] = setFocusedDate;
96
+ $[23] = t5;
97
+ }
98
+ else {
99
+ t5 = $[23];
100
+ }
101
+ const goToDate = t5;
102
+ let t6;
103
+ if ($[24] !== activeMonths || $[25] !== numberOfMonths || $[26] !== setActiveMonths || $[27] !== setFocusedDate) {
104
+ t6 = t7 => {
105
+ const numYears = t7 === undefined ? 1 : t7;
106
+ const newActiveMonths_4 = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -(numYears * 12 - numberOfMonths + 1));
107
+ setActiveMonths(newActiveMonths_4);
108
+ setFocusedDate(null);
109
+ return newActiveMonths_4;
110
+ };
111
+ $[24] = activeMonths;
112
+ $[25] = numberOfMonths;
113
+ $[26] = setActiveMonths;
114
+ $[27] = setFocusedDate;
115
+ $[28] = t6;
116
+ }
117
+ else {
118
+ t6 = $[28];
119
+ }
120
+ const goToPrevYear = t6;
121
+ let t7;
122
+ if ($[29] !== activeMonths || $[30] !== numberOfMonths || $[31] !== setActiveMonths || $[32] !== setFocusedDate) {
123
+ t7 = t8 => {
124
+ const numYears_0 = t8 === undefined ? 1 : t8;
125
+ const newActiveMonths_5 = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, numYears_0 * 12 - numberOfMonths + 1);
126
+ setActiveMonths(newActiveMonths_5);
127
+ setFocusedDate(null);
128
+ return newActiveMonths_5;
129
+ };
130
+ $[29] = activeMonths;
131
+ $[30] = numberOfMonths;
132
+ $[31] = setActiveMonths;
133
+ $[32] = setFocusedDate;
134
+ $[33] = t7;
135
+ }
136
+ else {
137
+ t7 = $[33];
138
+ }
139
+ const goToNextYear = t7;
140
+ let canGoToPrevMonth;
141
+ let firstYear;
142
+ let lastYear;
143
+ let t8;
144
+ if ($[34] !== activeMonths || $[35] !== maxBookingDate || $[36] !== minBookingDate) {
145
+ const firstMonthStr = (0, date_string_1.toDateString)((_b = (_a = activeMonths.at(0)) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : new Date());
146
+ const lastMonthStr = (0, date_string_1.toDateString)(activeMonths[activeMonths.length - 1].date);
147
+ firstYear = parseInt(firstMonthStr.slice(0, 4), 10);
148
+ lastYear = parseInt(lastMonthStr.slice(0, 4), 10);
149
+ canGoToPrevMonth = !minBookingDate || minBookingDate <= firstMonthStr;
150
+ t8 = !maxBookingDate || (0, date_string_1.addMonths)(lastMonthStr, 1) <= maxBookingDate;
151
+ $[34] = activeMonths;
152
+ $[35] = maxBookingDate;
153
+ $[36] = minBookingDate;
154
+ $[37] = canGoToPrevMonth;
155
+ $[38] = firstYear;
156
+ $[39] = lastYear;
157
+ $[40] = t8;
158
+ }
159
+ else {
160
+ canGoToPrevMonth = $[37];
161
+ firstYear = $[38];
162
+ lastYear = $[39];
163
+ t8 = $[40];
164
+ }
165
+ const canGoToNextMonth = t8;
62
166
  const canGoToPrevYear = !minBookingDate || (0, create_date_string_1.createDateString)(firstYear - 1, 11, 31) >= minBookingDate;
63
- // Can navigate forward a year if Jan 1 of (lastYear + 1) is still within maxBookingDate.
64
167
  const canGoToNextYear = !maxBookingDate || (0, create_date_string_1.createDateString)(lastYear + 1, 0) <= maxBookingDate;
65
- const canGoTo = (0, react_1.useCallback)((month, type) => {
66
- if (!minBookingDate && !maxBookingDate) {
67
- return true;
68
- }
69
- const ds = (0, date_string_1.toDateString)(month);
70
- const year = parseInt(ds.slice(0, 4), 10);
71
- if (type === "month") {
72
- // Month is reachable if its range overlaps [minBookingDate, maxBookingDate].
73
- // "end of this month + 1 day > min" AND "start of this month - 1 day < max"
74
- const afterMin = !minBookingDate || (0, date_string_1.addMonths)(ds, 1) > minBookingDate;
75
- const beforeMax = !maxBookingDate || (0, date_string_1.addDays)(ds, -1) < maxBookingDate;
76
- return afterMin && beforeMax;
77
- }
78
- // type === "year"
79
- const afterMin = !minBookingDate || (0, create_date_string_1.createDateString)(year + 1, 0) > minBookingDate;
80
- const beforeMax = !maxBookingDate || (0, create_date_string_1.createDateString)(year - 1, 11, 31) < maxBookingDate;
81
- return afterMin && beforeMax;
82
- }, [maxBookingDate, minBookingDate]);
83
- const canGoToMonth = (0, react_1.useCallback)((date) => canGoTo(date, "month"), [canGoTo]);
84
- const canGoToYear = (0, react_1.useCallback)((date) => canGoTo(date, "year"), [canGoTo]);
85
- return {
86
- canGoToMonth,
87
- canGoToNextMonth,
88
- canGoToNextYear,
89
- canGoToPrevMonth,
90
- canGoToPrevYear,
91
- canGoToYear,
92
- goToDate,
93
- goToNextMonths,
94
- goToNextMonthsByOneMonth,
95
- goToNextYear,
96
- goToPrevMonths,
97
- goToPrevMonthsByOneMonth,
98
- goToPrevYear,
99
- };
168
+ let t9;
169
+ if ($[41] !== maxBookingDate || $[42] !== minBookingDate) {
170
+ t9 = (month, type) => {
171
+ if (!minBookingDate && !maxBookingDate) {
172
+ return true;
173
+ }
174
+ const ds = (0, date_string_1.toDateString)(month);
175
+ const year = parseInt(ds.slice(0, 4), 10);
176
+ if (type === "month") {
177
+ const afterMin = !minBookingDate || (0, date_string_1.addMonths)(ds, 1) > minBookingDate;
178
+ const beforeMax = !maxBookingDate || (0, date_string_1.addDays)(ds, -1) < maxBookingDate;
179
+ return afterMin && beforeMax;
180
+ }
181
+ const afterMin_0 = !minBookingDate || (0, create_date_string_1.createDateString)(year + 1, 0) > minBookingDate;
182
+ const beforeMax_0 = !maxBookingDate || (0, create_date_string_1.createDateString)(year - 1, 11, 31) < maxBookingDate;
183
+ return afterMin_0 && beforeMax_0;
184
+ };
185
+ $[41] = maxBookingDate;
186
+ $[42] = minBookingDate;
187
+ $[43] = t9;
188
+ }
189
+ else {
190
+ t9 = $[43];
191
+ }
192
+ const canGoTo = t9;
193
+ let t10;
194
+ if ($[44] !== canGoTo) {
195
+ t10 = date_0 => canGoTo(date_0, "month");
196
+ $[44] = canGoTo;
197
+ $[45] = t10;
198
+ }
199
+ else {
200
+ t10 = $[45];
201
+ }
202
+ const canGoToMonth = t10;
203
+ let t11;
204
+ if ($[46] !== canGoTo) {
205
+ t11 = date_1 => canGoTo(date_1, "year");
206
+ $[46] = canGoTo;
207
+ $[47] = t11;
208
+ }
209
+ else {
210
+ t11 = $[47];
211
+ }
212
+ const canGoToYear = t11;
213
+ let t12;
214
+ if ($[48] !== canGoToMonth || $[49] !== canGoToNextMonth || $[50] !== canGoToNextYear || $[51] !== canGoToPrevMonth || $[52] !== canGoToPrevYear || $[53] !== canGoToYear || $[54] !== goToDate || $[55] !== goToNextMonths || $[56] !== goToNextMonthsByOneMonth || $[57] !== goToNextYear || $[58] !== goToPrevMonths || $[59] !== goToPrevMonthsByOneMonth || $[60] !== goToPrevYear) {
215
+ t12 = {
216
+ canGoToMonth,
217
+ canGoToNextMonth,
218
+ canGoToNextYear,
219
+ canGoToPrevMonth,
220
+ canGoToPrevYear,
221
+ canGoToYear,
222
+ goToDate,
223
+ goToNextMonths,
224
+ goToNextMonthsByOneMonth,
225
+ goToNextYear,
226
+ goToPrevMonths,
227
+ goToPrevMonthsByOneMonth,
228
+ goToPrevYear
229
+ };
230
+ $[48] = canGoToMonth;
231
+ $[49] = canGoToNextMonth;
232
+ $[50] = canGoToNextYear;
233
+ $[51] = canGoToPrevMonth;
234
+ $[52] = canGoToPrevYear;
235
+ $[53] = canGoToYear;
236
+ $[54] = goToDate;
237
+ $[55] = goToNextMonths;
238
+ $[56] = goToNextMonthsByOneMonth;
239
+ $[57] = goToNextYear;
240
+ $[58] = goToPrevMonths;
241
+ $[59] = goToPrevMonthsByOneMonth;
242
+ $[60] = goToPrevYear;
243
+ $[61] = t12;
244
+ }
245
+ else {
246
+ t12 = $[61];
247
+ }
248
+ return t12;
100
249
  }