datex-ui 1.0.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/constants/locales.d.ts +4 -7
- package/dist/constants/themes.d.ts +5 -6
- package/dist/datex.d.ts +77 -115
- package/dist/index.d.ts +9 -4
- package/dist/index.esm.js +1034 -700
- package/dist/services/calendar-service.d.ts +21 -0
- package/dist/services/event-service.d.ts +17 -0
- package/dist/services/keyboard-service.d.ts +51 -0
- package/dist/services/position-service.d.ts +18 -0
- package/dist/services/theme-service.d.ts +18 -0
- package/dist/services/validation-service.d.ts +32 -0
- package/dist/types/{index.d.ts → datex-types.d.ts} +21 -7
- package/dist/utils/date-utils.d.ts +16 -0
- package/package.json +68 -68
- package/dist/style.css +0 -1
- package/dist/tests/setup.d.ts +0 -1
- package/dist/utils/dateHelpers.d.ts +0 -24
- package/dist/utils/domHelpers.d.ts +0 -30
package/dist/index.esm.js
CHANGED
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
function
|
|
2
|
-
const e =
|
|
3
|
-
return t.replace(/YYYY/g, String(e)).replace(/MM/g,
|
|
1
|
+
function g(r, t) {
|
|
2
|
+
const e = r.getFullYear(), a = String(r.getMonth() + 1).padStart(2, "0"), i = String(r.getDate()).padStart(2, "0"), s = String(r.getHours()).padStart(2, "0"), n = String(r.getMinutes()).padStart(2, "0"), o = String(r.getSeconds()).padStart(2, "0");
|
|
3
|
+
return t.replace(/YYYY/g, String(e)).replace(/MM/g, a).replace(/DD/g, i).replace(/HH/g, s).replace(/mm/g, n).replace(/ss/g, o);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
const e = new Date(
|
|
7
|
-
return e.setDate(e.getDate() + t), e;
|
|
8
|
-
}
|
|
9
|
-
function y(c, t) {
|
|
10
|
-
const e = new Date(c);
|
|
5
|
+
function h(r, t) {
|
|
6
|
+
const e = new Date(r);
|
|
11
7
|
return e.setMonth(e.getMonth() + t), e;
|
|
12
8
|
}
|
|
13
|
-
function
|
|
14
|
-
const t = new Date(
|
|
9
|
+
function v(r) {
|
|
10
|
+
const t = new Date(r);
|
|
15
11
|
return t.setHours(0, 0, 0, 0), t;
|
|
16
12
|
}
|
|
17
|
-
function
|
|
18
|
-
const t = new Date(
|
|
13
|
+
function y(r) {
|
|
14
|
+
const t = new Date(r);
|
|
19
15
|
return t.setHours(23, 59, 59, 999), t;
|
|
20
16
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
17
|
+
function D(r, t) {
|
|
18
|
+
return r.getTime() > t.getTime();
|
|
19
|
+
}
|
|
20
|
+
function p(r, t) {
|
|
21
|
+
return r.getTime() < t.getTime();
|
|
22
|
+
}
|
|
23
|
+
function d(r, t, e = "day") {
|
|
24
|
+
if (!r || !t) return !1;
|
|
25
|
+
switch (e) {
|
|
26
|
+
case "day":
|
|
27
|
+
return r.getFullYear() === t.getFullYear() && r.getMonth() === t.getMonth() && r.getDate() === t.getDate();
|
|
28
|
+
case "month":
|
|
29
|
+
return r.getFullYear() === t.getFullYear() && r.getMonth() === t.getMonth();
|
|
30
|
+
case "year":
|
|
31
|
+
return r.getFullYear() === t.getFullYear();
|
|
32
|
+
default:
|
|
33
|
+
return !1;
|
|
34
|
+
}
|
|
23
35
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
36
|
+
function f(r) {
|
|
37
|
+
return r instanceof Date && !isNaN(r.getTime());
|
|
26
38
|
}
|
|
27
|
-
function
|
|
39
|
+
function m(r, t) {
|
|
28
40
|
if (t === "YYYY-MM-DD")
|
|
29
|
-
return new Date(
|
|
41
|
+
return new Date(r);
|
|
30
42
|
if (t === "DD/MM/YYYY") {
|
|
31
|
-
const e =
|
|
43
|
+
const e = r.split("/");
|
|
32
44
|
if (e.length === 3) {
|
|
33
|
-
const
|
|
34
|
-
return new Date(
|
|
45
|
+
const a = parseInt(e[0], 10), i = parseInt(e[1], 10) - 1, s = parseInt(e[2], 10);
|
|
46
|
+
return new Date(s, i, a);
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
if (t === "DD/MM/YYYY HH:mm") {
|
|
38
|
-
const [e,
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
return new Date(
|
|
50
|
+
const [e, a] = r.split(" "), i = e.split("/"), s = a ? a.split(":") : ["0", "0"];
|
|
51
|
+
if (i.length === 3) {
|
|
52
|
+
const n = parseInt(i[0], 10), o = parseInt(i[1], 10) - 1, l = parseInt(i[2], 10), c = parseInt(s[0], 10) || 0, u = parseInt(s[1], 10) || 0;
|
|
53
|
+
return new Date(l, o, n, c, u);
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
|
-
return new Date(
|
|
56
|
+
return new Date(r);
|
|
45
57
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
case "month":
|
|
52
|
-
return c.getFullYear() === t.getFullYear() && c.getMonth() === t.getMonth();
|
|
53
|
-
case "year":
|
|
54
|
-
return c.getFullYear() === t.getFullYear();
|
|
55
|
-
default:
|
|
56
|
-
return !1;
|
|
57
|
-
}
|
|
58
|
+
function b(r) {
|
|
59
|
+
return new Date(r.getFullYear(), r.getMonth(), 1);
|
|
60
|
+
}
|
|
61
|
+
function k(r) {
|
|
62
|
+
return new Date(r.getFullYear(), r.getMonth() + 1, 0);
|
|
58
63
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
64
|
+
function x(r, t = 1) {
|
|
65
|
+
const a = (r.getDay() - t + 7) % 7, i = new Date(r);
|
|
66
|
+
return i.setDate(r.getDate() - a), i;
|
|
61
67
|
}
|
|
62
|
-
const
|
|
68
|
+
const C = {
|
|
63
69
|
primaryColor: "#357ebd",
|
|
64
70
|
secondaryColor: "#ccc",
|
|
65
71
|
backgroundColor: "#ffffff",
|
|
@@ -75,7 +81,7 @@ const L = {
|
|
|
75
81
|
borderRadius: "4px",
|
|
76
82
|
fontSize: "15px",
|
|
77
83
|
fontFamily: "arial"
|
|
78
|
-
},
|
|
84
|
+
}, A = {
|
|
79
85
|
primaryColor: "#0d6efd",
|
|
80
86
|
secondaryColor: "#6c757d",
|
|
81
87
|
backgroundColor: "#ffffff",
|
|
@@ -91,7 +97,7 @@ const L = {
|
|
|
91
97
|
borderRadius: "6px",
|
|
92
98
|
fontSize: "14px",
|
|
93
99
|
fontFamily: 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'
|
|
94
|
-
},
|
|
100
|
+
}, H = {
|
|
95
101
|
primaryColor: "#1976d2",
|
|
96
102
|
secondaryColor: "#757575",
|
|
97
103
|
backgroundColor: "#ffffff",
|
|
@@ -107,82 +113,36 @@ const L = {
|
|
|
107
113
|
borderRadius: "4px",
|
|
108
114
|
fontSize: "14px",
|
|
109
115
|
fontFamily: 'Roboto, "Helvetica Neue", Arial, sans-serif'
|
|
110
|
-
}, Y = {
|
|
111
|
-
format: "DD/MM/YYYY",
|
|
112
|
-
separator: " - ",
|
|
113
|
-
applyLabel: "Aplicar",
|
|
114
|
-
cancelLabel: "Cancelar",
|
|
115
|
-
customRangeLabel: "Rango Personalizado",
|
|
116
|
-
daysOfWeek: ["Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
|
|
117
|
-
monthNames: [
|
|
118
|
-
"Enero",
|
|
119
|
-
"Febrero",
|
|
120
|
-
"Marzo",
|
|
121
|
-
"Abril",
|
|
122
|
-
"Mayo",
|
|
123
|
-
"Junio",
|
|
124
|
-
"Julio",
|
|
125
|
-
"Agosto",
|
|
126
|
-
"Septiembre",
|
|
127
|
-
"Octubre",
|
|
128
|
-
"Noviembre",
|
|
129
|
-
"Diciembre"
|
|
130
|
-
],
|
|
131
|
-
firstDay: 1
|
|
132
|
-
// Monday
|
|
133
|
-
}, A = {
|
|
134
|
-
format: "DD/MM/YYYY HH:mm",
|
|
135
|
-
separator: " - ",
|
|
136
|
-
applyLabel: "Aplicar",
|
|
137
|
-
cancelLabel: "Cancelar",
|
|
138
|
-
customRangeLabel: "Rango Personalizado",
|
|
139
|
-
daysOfWeek: ["Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
|
|
140
|
-
monthNames: [
|
|
141
|
-
"Enero",
|
|
142
|
-
"Febrero",
|
|
143
|
-
"Marzo",
|
|
144
|
-
"Abril",
|
|
145
|
-
"Mayo",
|
|
146
|
-
"Junio",
|
|
147
|
-
"Julio",
|
|
148
|
-
"Agosto",
|
|
149
|
-
"Septiembre",
|
|
150
|
-
"Octubre",
|
|
151
|
-
"Noviembre",
|
|
152
|
-
"Diciembre"
|
|
153
|
-
],
|
|
154
|
-
firstDay: 1
|
|
155
|
-
// Monday
|
|
156
116
|
};
|
|
157
|
-
class
|
|
158
|
-
constructor(t, e =
|
|
159
|
-
|
|
160
|
-
throw new Error("Datex: Element not found");
|
|
161
|
-
this.options = this.mergeOptions(e), this.locale = this.options.locale, this.theme = { ...this.options.theme }, this.callback = i || (() => {
|
|
162
|
-
});
|
|
163
|
-
const a = /* @__PURE__ */ new Date();
|
|
164
|
-
this.state = {
|
|
165
|
-
startDate: this.options.timePicker ? this.options.startDate : M(this.options.startDate),
|
|
166
|
-
endDate: this.options.timePicker ? this.options.endDate : E(this.options.endDate),
|
|
167
|
-
oldStartDate: this.options.timePicker ? this.options.startDate : M(this.options.startDate),
|
|
168
|
-
oldEndDate: this.options.timePicker ? this.options.endDate : E(this.options.endDate),
|
|
169
|
-
isShowing: !1,
|
|
170
|
-
leftCalendar: { month: a, calendar: [] },
|
|
171
|
-
rightCalendar: { month: y(a, 1), calendar: [] },
|
|
172
|
-
chosenLabel: null,
|
|
173
|
-
hoverDate: null
|
|
174
|
-
}, this.createContainer(), this.setupEventListeners(), this.updateElement(), this.calculateChosenLabel(), this.applyTheme();
|
|
117
|
+
class w {
|
|
118
|
+
constructor(t, e = C) {
|
|
119
|
+
this.container = t, this.theme = { ...C, ...e };
|
|
175
120
|
}
|
|
176
121
|
applyTheme() {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
122
|
+
this.removeExistingStyles(), this.createAndApplyStyles(), this.forceReflow();
|
|
123
|
+
}
|
|
124
|
+
setTheme(t) {
|
|
125
|
+
this.theme = { ...C, ...t }, this.applyTheme();
|
|
126
|
+
}
|
|
127
|
+
cleanup() {
|
|
128
|
+
this.removeExistingStyles();
|
|
129
|
+
}
|
|
130
|
+
removeExistingStyles() {
|
|
131
|
+
if (this.styleId) {
|
|
132
|
+
const t = document.getElementById(this.styleId);
|
|
133
|
+
t == null || t.remove();
|
|
183
134
|
}
|
|
184
|
-
|
|
185
|
-
|
|
135
|
+
}
|
|
136
|
+
createAndApplyStyles() {
|
|
137
|
+
this.styleId = this.generateStyleId();
|
|
138
|
+
const t = document.createElement("style");
|
|
139
|
+
t.id = this.styleId, t.textContent = this.generateThemeCSS(), document.head.appendChild(t), this.container.dataset.themeStyleId = this.styleId;
|
|
140
|
+
}
|
|
141
|
+
generateStyleId() {
|
|
142
|
+
return "daterangepicker-theme-" + Math.random().toString(36).slice(2, 9);
|
|
143
|
+
}
|
|
144
|
+
forceReflow() {
|
|
145
|
+
this.container.offsetHeight;
|
|
186
146
|
}
|
|
187
147
|
generateThemeCSS() {
|
|
188
148
|
const t = this.theme;
|
|
@@ -199,7 +159,6 @@ class q {
|
|
|
199
159
|
z-index: 3001 !important;
|
|
200
160
|
}
|
|
201
161
|
|
|
202
|
-
/* IMPORTANTE: Permitir interacción con selectores */
|
|
203
162
|
.datex-picker select,
|
|
204
163
|
.datex-picker select * {
|
|
205
164
|
user-select: auto !important;
|
|
@@ -253,6 +212,7 @@ class q {
|
|
|
253
212
|
.datex-picker .calendar-table th.month {
|
|
254
213
|
color: ${t.textColor} !important;
|
|
255
214
|
width: auto !important;
|
|
215
|
+
pointer-events: auto !important;
|
|
256
216
|
}
|
|
257
217
|
|
|
258
218
|
.datex-picker .calendar-table .next span,
|
|
@@ -311,7 +271,7 @@ class q {
|
|
|
311
271
|
}
|
|
312
272
|
|
|
313
273
|
.datex-picker td.in-range {
|
|
314
|
-
background-color:
|
|
274
|
+
background-color: ${t.rangeColor} !important;
|
|
315
275
|
border-color: transparent !important;
|
|
316
276
|
color: #000 !important;
|
|
317
277
|
border-radius: 0 !important;
|
|
@@ -319,13 +279,13 @@ class q {
|
|
|
319
279
|
|
|
320
280
|
.datex-picker td.start-date {
|
|
321
281
|
border-radius: 3px 0 0 3px !important;
|
|
322
|
-
background-color:
|
|
282
|
+
background-color: ${t.selectedColor} !important;
|
|
323
283
|
color: #fff !important;
|
|
324
284
|
}
|
|
325
285
|
|
|
326
286
|
.datex-picker td.end-date {
|
|
327
287
|
border-radius: 0 3px 3px 0 !important;
|
|
328
|
-
background-color:
|
|
288
|
+
background-color: ${t.selectedColor} !important;
|
|
329
289
|
color: #fff !important;
|
|
330
290
|
}
|
|
331
291
|
|
|
@@ -335,7 +295,7 @@ class q {
|
|
|
335
295
|
|
|
336
296
|
.datex-picker td.active,
|
|
337
297
|
.datex-picker td.active:hover {
|
|
338
|
-
background-color:
|
|
298
|
+
background-color: ${t.selectedColor} !important;
|
|
339
299
|
border-color: transparent !important;
|
|
340
300
|
color: #fff !important;
|
|
341
301
|
}
|
|
@@ -454,15 +414,6 @@ class q {
|
|
|
454
414
|
opacity: 0.8 !important;
|
|
455
415
|
}
|
|
456
416
|
|
|
457
|
-
/* Asegurar que el contenedor no bloquee eventos */
|
|
458
|
-
.datex-picker .calendar-table th.month {
|
|
459
|
-
pointer-events: auto !important;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
.datex-picker .calendar-table th.month * {
|
|
463
|
-
pointer-events: auto !important;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
417
|
.datex-picker select.monthselect,
|
|
467
418
|
.datex-picker select.yearselect {
|
|
468
419
|
font-size: 12px !important;
|
|
@@ -474,24 +425,18 @@ class q {
|
|
|
474
425
|
border: 1px solid ${t.borderColor} !important;
|
|
475
426
|
color: ${t.textColor} !important;
|
|
476
427
|
outline: none !important;
|
|
477
|
-
/* Asegurar que los dropdowns funcionen nativamente */
|
|
478
428
|
appearance: auto !important;
|
|
479
429
|
-webkit-appearance: menulist !important;
|
|
480
430
|
-moz-appearance: menulist !important;
|
|
481
|
-
/* Permitir interacción */
|
|
482
431
|
pointer-events: auto !important;
|
|
483
432
|
user-select: auto !important;
|
|
484
433
|
-webkit-user-select: auto !important;
|
|
485
434
|
-moz-user-select: auto !important;
|
|
486
|
-
/* Tamaño mínimo para ser clickeable */
|
|
487
435
|
min-height: 20px !important;
|
|
488
436
|
min-width: 50px !important;
|
|
489
|
-
/* Asegurar que estén por encima de otros elementos */
|
|
490
437
|
position: relative !important;
|
|
491
438
|
z-index: 1000000 !important;
|
|
492
|
-
/* Remover cualquier transformación que pueda interferir */
|
|
493
439
|
transform: none !important;
|
|
494
|
-
/* Asegurar que no estén bloqueados por overlay */
|
|
495
440
|
isolation: auto !important;
|
|
496
441
|
}
|
|
497
442
|
|
|
@@ -560,7 +505,6 @@ class q {
|
|
|
560
505
|
color: #fff !important;
|
|
561
506
|
}
|
|
562
507
|
|
|
563
|
-
/* Media queries para responsive - exactamente como el CSS original */
|
|
564
508
|
@media (min-width: 564px) {
|
|
565
509
|
.datex-picker {
|
|
566
510
|
width: auto !important;
|
|
@@ -614,27 +558,516 @@ class q {
|
|
|
614
558
|
}
|
|
615
559
|
`;
|
|
616
560
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
561
|
+
}
|
|
562
|
+
class S {
|
|
563
|
+
constructor() {
|
|
564
|
+
this.boundHandlers = /* @__PURE__ */ new Map();
|
|
565
|
+
}
|
|
566
|
+
addEventHandler(t, e, a) {
|
|
567
|
+
const i = `${e}_${Math.random()}`;
|
|
568
|
+
this.boundHandlers.set(i, a), t.addEventListener(e, a);
|
|
569
|
+
}
|
|
570
|
+
setDocumentListeners(t, e) {
|
|
571
|
+
this.documentClickHandler = t, this.documentFocusHandler = e, document.addEventListener("mousedown", this.documentClickHandler, !0), document.addEventListener("focusin", this.documentFocusHandler, !0);
|
|
572
|
+
}
|
|
573
|
+
setWindowListeners(t, e) {
|
|
574
|
+
this.resizeHandler = t, this.scrollHandler = e, window.addEventListener("resize", this.resizeHandler), window.addEventListener("scroll", this.scrollHandler, !0);
|
|
575
|
+
}
|
|
576
|
+
removeDocumentListeners() {
|
|
577
|
+
this.documentClickHandler && (document.removeEventListener(
|
|
578
|
+
"mousedown",
|
|
579
|
+
this.documentClickHandler,
|
|
580
|
+
!0
|
|
581
|
+
), this.documentClickHandler = void 0), this.documentFocusHandler && (document.removeEventListener("focusin", this.documentFocusHandler, !0), this.documentFocusHandler = void 0);
|
|
582
|
+
}
|
|
583
|
+
removeWindowListeners() {
|
|
584
|
+
this.resizeHandler && (window.removeEventListener("resize", this.resizeHandler), this.resizeHandler = void 0), this.scrollHandler && (window.removeEventListener("scroll", this.scrollHandler, !0), this.scrollHandler = void 0);
|
|
585
|
+
}
|
|
586
|
+
cleanup() {
|
|
587
|
+
this.removeDocumentListeners(), this.removeWindowListeners(), this.boundHandlers.clear();
|
|
588
|
+
}
|
|
589
|
+
dispatchEvent(t, e, a) {
|
|
590
|
+
const i = new CustomEvent(e, {
|
|
591
|
+
bubbles: !0,
|
|
592
|
+
detail: a
|
|
593
|
+
});
|
|
594
|
+
t.dispatchEvent(i);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
class E {
|
|
598
|
+
constructor(t, e, a) {
|
|
599
|
+
this.element = t, this.container = e, this.options = a;
|
|
600
|
+
}
|
|
601
|
+
calculatePosition() {
|
|
602
|
+
if (!this.container) return;
|
|
603
|
+
(window.innerWidth <= 768 || "ontouchstart" in window) && this.container.classList.contains("touch-enabled") ? this.positionForMobile() : this.positionForDesktop();
|
|
604
|
+
}
|
|
605
|
+
positionForMobile() {
|
|
606
|
+
this.container.style.position = "fixed", this.container.style.bottom = "0", this.container.style.left = "0", this.container.style.right = "0", this.container.style.top = "auto", this.container.style.width = "100%", this.container.style.maxWidth = "100vw", this.container.style.borderRadius = "16px 16px 0 0", this.container.style.zIndex = "99999", this.container.classList.add("drop-up");
|
|
607
|
+
}
|
|
608
|
+
positionForDesktop() {
|
|
609
|
+
const t = this.element.getBoundingClientRect();
|
|
610
|
+
this.resetContainerPosition();
|
|
611
|
+
const e = this.container.offsetWidth, a = this.container.offsetHeight, { top: i, drops: s } = this.calculateVerticalPosition(
|
|
612
|
+
t,
|
|
613
|
+
a
|
|
614
|
+
), n = this.calculateHorizontalPosition(
|
|
615
|
+
t,
|
|
616
|
+
e
|
|
617
|
+
);
|
|
618
|
+
this.applyDropUpClass(s), this.applyFinalPosition(i, n);
|
|
619
|
+
}
|
|
620
|
+
resetContainerPosition() {
|
|
621
|
+
this.container.style.top = "0", this.container.style.left = "0", this.container.style.right = "auto", this.container.style.position = "fixed";
|
|
622
|
+
}
|
|
623
|
+
calculateVerticalPosition(t, e) {
|
|
624
|
+
let a, i = this.options.drops;
|
|
625
|
+
switch (i) {
|
|
626
|
+
case "auto":
|
|
627
|
+
a = t.bottom + 5, a + e >= window.innerHeight && (a = t.top - e - 5, i = "up");
|
|
628
|
+
break;
|
|
629
|
+
case "up":
|
|
630
|
+
a = t.top - e - 5;
|
|
631
|
+
break;
|
|
632
|
+
default:
|
|
633
|
+
a = t.bottom + 5;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
return { top: Math.max(9, a), drops: i };
|
|
637
|
+
}
|
|
638
|
+
calculateHorizontalPosition(t, e) {
|
|
639
|
+
let a;
|
|
640
|
+
switch (this.options.opens) {
|
|
641
|
+
case "left":
|
|
642
|
+
a = t.right - e;
|
|
643
|
+
break;
|
|
644
|
+
case "center":
|
|
645
|
+
a = t.left + t.width / 2 - e / 2;
|
|
646
|
+
break;
|
|
647
|
+
default:
|
|
648
|
+
a = t.left;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
return a < 9 ? a = 9 : a + e > window.innerWidth - 9 && (a = window.innerWidth - e - 9), a;
|
|
652
|
+
}
|
|
653
|
+
applyDropUpClass(t) {
|
|
654
|
+
t === "up" ? this.container.classList.add("drop-up") : this.container.classList.remove("drop-up");
|
|
655
|
+
}
|
|
656
|
+
applyFinalPosition(t, e) {
|
|
657
|
+
this.container.style.top = `${t}px`, this.container.style.left = `${e}px`, this.container.style.right = "auto", this.container.style.zIndex = "99999";
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
class L {
|
|
661
|
+
constructor(t, e) {
|
|
662
|
+
this.options = t, this.locale = e;
|
|
663
|
+
}
|
|
664
|
+
buildCalendarMatrix(t) {
|
|
665
|
+
const e = b(t), a = x(e, this.locale.firstDay), i = [];
|
|
666
|
+
let s = [];
|
|
667
|
+
const n = new Date(a);
|
|
668
|
+
for (let o = 0; o < 42; o++) {
|
|
669
|
+
o > 0 && o % 7 === 0 && (i.push(s), s = []);
|
|
670
|
+
const l = new Date(n);
|
|
671
|
+
l.setDate(n.getDate() + o), s.push(l);
|
|
672
|
+
}
|
|
673
|
+
return s.length > 0 && i.push(s), i;
|
|
674
|
+
}
|
|
675
|
+
renderCalendarHTML(t, e, a, i, s, n) {
|
|
676
|
+
const o = t.month, l = o.getFullYear(), c = o.getMonth();
|
|
677
|
+
let u = '<table class="table-condensed">';
|
|
678
|
+
return u += this.renderHeader(e, c, l, s, n), u += this.renderDayHeaders(), u += this.renderCalendarBody(
|
|
679
|
+
t.calendar,
|
|
680
|
+
o,
|
|
681
|
+
a,
|
|
682
|
+
i
|
|
683
|
+
), u += "</table>", u;
|
|
684
|
+
}
|
|
685
|
+
renderHeader(t, e, a, i, s) {
|
|
686
|
+
let n = "<thead><tr>";
|
|
687
|
+
i && (!this.options.linkedCalendars || t === "left") ? n += '<th class="prev available"><span></span></th>' : n += "<th></th>";
|
|
688
|
+
let o = this.locale.monthNames[e] + " " + a;
|
|
689
|
+
return this.options.showDropdowns && (o = this.renderDropdowns(e, a)), n += `<th colspan="5" class="month">${o}</th>`, s && (!this.options.linkedCalendars || t === "right" || this.options.singleDatePicker) ? n += '<th class="next available"><span></span></th>' : n += "<th></th>", n += "</tr>", n;
|
|
690
|
+
}
|
|
691
|
+
renderDayHeaders() {
|
|
692
|
+
let t = "<tr>";
|
|
693
|
+
for (const e of this.locale.daysOfWeek)
|
|
694
|
+
t += `<th>${e}</th>`;
|
|
695
|
+
return t += "</tr></thead>", t;
|
|
696
|
+
}
|
|
697
|
+
renderCalendarBody(t, e, a, i) {
|
|
698
|
+
let s = "<tbody>";
|
|
699
|
+
for (const n of t) {
|
|
700
|
+
s += "<tr>";
|
|
701
|
+
for (const o of n) {
|
|
702
|
+
const l = this.getDayClasses(
|
|
703
|
+
o,
|
|
704
|
+
e,
|
|
705
|
+
a,
|
|
706
|
+
i
|
|
707
|
+
), c = l.includes("disabled"), u = l.join(" ") + (c ? "" : " available");
|
|
708
|
+
s += `<td class="${u}" data-date="${g(
|
|
709
|
+
o,
|
|
710
|
+
"YYYY-MM-DD"
|
|
711
|
+
)}">${o.getDate()}</td>`;
|
|
712
|
+
}
|
|
713
|
+
s += "</tr>";
|
|
714
|
+
}
|
|
715
|
+
return s += "</tbody>", s;
|
|
716
|
+
}
|
|
717
|
+
renderDropdowns(t, e) {
|
|
718
|
+
const { minYear: a, maxYear: i } = this.calculateYearRange(e), s = this.renderMonthDropdown(
|
|
719
|
+
t,
|
|
720
|
+
e,
|
|
721
|
+
a,
|
|
722
|
+
i
|
|
723
|
+
), n = this.renderYearDropdown(e, a, i);
|
|
724
|
+
return s + " " + n;
|
|
725
|
+
}
|
|
726
|
+
calculateYearRange(t) {
|
|
727
|
+
let e = this.options.minYear, a = this.options.maxYear;
|
|
728
|
+
return this.options.minDate && (e = Math.max(e, this.options.minDate.getFullYear())), this.options.maxDate && (a = Math.min(a, this.options.maxDate.getFullYear())), { minYear: e, maxYear: a };
|
|
729
|
+
}
|
|
730
|
+
renderMonthDropdown(t, e, a, i) {
|
|
731
|
+
const s = e === a, n = e === i;
|
|
732
|
+
let o = '<select class="monthselect">';
|
|
733
|
+
for (let l = 0; l < 12; l++) {
|
|
734
|
+
let c = !1;
|
|
735
|
+
s && this.options.minDate && l < this.options.minDate.getMonth() && (c = !0), n && this.options.maxDate && l > this.options.maxDate.getMonth() && (c = !0), o += `<option value="${l}"${l === t ? ' selected="selected"' : ""}${c ? ' disabled="disabled"' : ""}>${this.locale.monthNames[l]}</option>`;
|
|
736
|
+
}
|
|
737
|
+
return o += "</select>", o;
|
|
738
|
+
}
|
|
739
|
+
renderYearDropdown(t, e, a) {
|
|
740
|
+
let i = '<select class="yearselect">';
|
|
741
|
+
for (let s = e; s <= a; s++)
|
|
742
|
+
i += `<option value="${s}"${s === t ? ' selected="selected"' : ""}>${s}</option>`;
|
|
743
|
+
return i += "</select>", i;
|
|
744
|
+
}
|
|
745
|
+
getDayClasses(t, e, a, i) {
|
|
746
|
+
const s = [];
|
|
747
|
+
return d(t, /* @__PURE__ */ new Date(), "day") && s.push("today"), (t.getDay() === 0 || t.getDay() === 6) && s.push("weekend"), t.getMonth() !== e.getMonth() && s.push("off", "ends"), this.options.minDate && p(t, v(this.options.minDate)) && s.push("off", "disabled"), this.options.maxDate && D(t, y(this.options.maxDate)) && s.push("off", "disabled"), d(t, a, "day") && s.push("active", "start-date"), i && d(t, i, "day") && s.push("active", "end-date"), i && D(t, a) && p(t, i) && s.push("in-range"), s;
|
|
748
|
+
}
|
|
749
|
+
canNavigatePrevious(t) {
|
|
750
|
+
return !this.options.minDate || D(b(t), this.options.minDate);
|
|
751
|
+
}
|
|
752
|
+
canNavigateNext(t) {
|
|
753
|
+
return !this.options.maxDate || p(k(t), this.options.maxDate);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
class M {
|
|
757
|
+
constructor(t = {}) {
|
|
758
|
+
this.validation = t;
|
|
759
|
+
}
|
|
760
|
+
updateValidation(t) {
|
|
761
|
+
this.validation = { ...this.validation, ...t };
|
|
762
|
+
}
|
|
763
|
+
validateDate(t) {
|
|
764
|
+
var e, a, i;
|
|
765
|
+
return (e = this.validation.disabledDates) != null && e.some((s) => this.isSameDate(s, t)) ? {
|
|
766
|
+
isValid: !1,
|
|
767
|
+
error: "Esta fecha está deshabilitada",
|
|
768
|
+
errorCode: "DISABLED_DATE"
|
|
769
|
+
} : (a = this.validation.disabledDaysOfWeek) != null && a.includes(t.getDay()) ? {
|
|
770
|
+
isValid: !1,
|
|
771
|
+
error: `Los ${[
|
|
772
|
+
"Domingo",
|
|
773
|
+
"Lunes",
|
|
774
|
+
"Martes",
|
|
775
|
+
"Miércoles",
|
|
776
|
+
"Jueves",
|
|
777
|
+
"Viernes",
|
|
778
|
+
"Sábado"
|
|
779
|
+
][t.getDay()]}s están deshabilitados`,
|
|
780
|
+
errorCode: "DISABLED_DAY_OF_WEEK"
|
|
781
|
+
} : this.validation.businessDaysOnly && this.isWeekend(t) ? {
|
|
782
|
+
isValid: !1,
|
|
783
|
+
error: "Solo se permiten días laborables",
|
|
784
|
+
errorCode: "BUSINESS_DAYS_ONLY"
|
|
785
|
+
} : (i = this.validation.holidays) != null && i.some((s) => this.isSameDate(s, t)) ? {
|
|
786
|
+
isValid: !1,
|
|
787
|
+
error: "Los días festivos están deshabilitados",
|
|
788
|
+
errorCode: "HOLIDAY_DISABLED"
|
|
789
|
+
} : this.validation.enabledDateRanges && !this.isDateInEnabledRanges(t) ? {
|
|
790
|
+
isValid: !1,
|
|
791
|
+
error: "Esta fecha está fuera de los rangos permitidos",
|
|
792
|
+
errorCode: "OUTSIDE_ENABLED_RANGE"
|
|
793
|
+
} : this.validation.customValidator && !this.validation.customValidator(t) ? {
|
|
794
|
+
isValid: !1,
|
|
795
|
+
error: "Esta fecha no cumple con los criterios personalizados",
|
|
796
|
+
errorCode: "CUSTOM_VALIDATION_FAILED"
|
|
797
|
+
} : { isValid: !0 };
|
|
798
|
+
}
|
|
799
|
+
validateDateRange(t, e) {
|
|
800
|
+
const a = this.validateDate(t);
|
|
801
|
+
if (!a.isValid)
|
|
802
|
+
return a;
|
|
803
|
+
const i = this.validateDate(e);
|
|
804
|
+
return i.isValid ? this.validation.minDaysBetween && this.getDaysBetween(t, e) < this.validation.minDaysBetween ? {
|
|
805
|
+
isValid: !1,
|
|
806
|
+
error: `Debe haber al menos ${this.validation.minDaysBetween} días entre las fechas`,
|
|
807
|
+
errorCode: "MIN_DAYS_BETWEEN"
|
|
808
|
+
} : this.validation.maxDaysBetween && this.getDaysBetween(t, e) > this.validation.maxDaysBetween ? {
|
|
809
|
+
isValid: !1,
|
|
810
|
+
error: `No puede haber más de ${this.validation.maxDaysBetween} días entre las fechas`,
|
|
811
|
+
errorCode: "MAX_DAYS_BETWEEN"
|
|
812
|
+
} : { isValid: !0 } : i;
|
|
813
|
+
}
|
|
814
|
+
// Utility methods
|
|
815
|
+
isSameDate(t, e) {
|
|
816
|
+
return t.getFullYear() === e.getFullYear() && t.getMonth() === e.getMonth() && t.getDate() === e.getDate();
|
|
817
|
+
}
|
|
818
|
+
isWeekend(t) {
|
|
819
|
+
const e = t.getDay();
|
|
820
|
+
return e === 0 || e === 6;
|
|
821
|
+
}
|
|
822
|
+
getDaysBetween(t, e) {
|
|
823
|
+
const a = e.getTime() - t.getTime();
|
|
824
|
+
return Math.ceil(a / (1e3 * 3600 * 24));
|
|
825
|
+
}
|
|
826
|
+
isDateInEnabledRanges(t) {
|
|
827
|
+
return this.validation.enabledDateRanges ? this.validation.enabledDateRanges.some(([e, a]) => t >= e && t <= a) : !0;
|
|
828
|
+
}
|
|
829
|
+
// Public utility methods
|
|
830
|
+
getBusinessDays(t, e) {
|
|
831
|
+
let a = 0;
|
|
832
|
+
const i = new Date(t);
|
|
833
|
+
for (; i <= e; )
|
|
834
|
+
this.isWeekend(i) || a++, i.setDate(i.getDate() + 1);
|
|
835
|
+
return a;
|
|
836
|
+
}
|
|
837
|
+
addBusinessDays(t, e) {
|
|
838
|
+
const a = new Date(t);
|
|
839
|
+
let i = 0;
|
|
840
|
+
for (; i < e; )
|
|
841
|
+
a.setDate(a.getDate() + 1), this.isWeekend(a) || i++;
|
|
842
|
+
return a;
|
|
843
|
+
}
|
|
844
|
+
isHoliday(t) {
|
|
845
|
+
var e;
|
|
846
|
+
return ((e = this.validation.holidays) == null ? void 0 : e.some((a) => this.isSameDate(a, t))) || !1;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
class $ {
|
|
850
|
+
constructor(t, e = {}) {
|
|
851
|
+
this.currentFocusedDate = null, this.isActive = !1, this.container = t, this.options = {
|
|
852
|
+
enabled: !0,
|
|
853
|
+
shortcuts: {
|
|
854
|
+
today: "t",
|
|
855
|
+
clear: "c",
|
|
856
|
+
close: "Escape",
|
|
857
|
+
apply: "Enter",
|
|
858
|
+
cancel: "Escape",
|
|
859
|
+
...e.shortcuts
|
|
860
|
+
},
|
|
861
|
+
...e
|
|
862
|
+
}, this.options.enabled && this.setupKeyboardEvents();
|
|
863
|
+
}
|
|
864
|
+
setHandlers(t) {
|
|
865
|
+
this.onDateSelect = t.onDateSelect, this.onClose = t.onClose, this.onApply = t.onApply, this.onCancel = t.onCancel, this.onToday = t.onToday, this.onClear = t.onClear;
|
|
866
|
+
}
|
|
867
|
+
activate(t) {
|
|
868
|
+
this.isActive = !0, this.currentFocusedDate = t || /* @__PURE__ */ new Date(), this.updateFocusedDate(), this.container.focus();
|
|
869
|
+
}
|
|
870
|
+
deactivate() {
|
|
871
|
+
this.isActive = !1, this.currentFocusedDate = null, this.removeFocusStyles();
|
|
872
|
+
}
|
|
873
|
+
setupKeyboardEvents() {
|
|
874
|
+
this.container.setAttribute("tabindex", "0"), this.container.addEventListener("keydown", this.handleKeyDown.bind(this)), this.container.addEventListener("focus", this.handleFocus.bind(this)), this.container.addEventListener("blur", this.handleBlur.bind(this));
|
|
875
|
+
}
|
|
876
|
+
handleKeyDown(t) {
|
|
877
|
+
var n, o, l, c;
|
|
878
|
+
if (!this.isActive || !this.currentFocusedDate) return;
|
|
879
|
+
const { key: e, ctrlKey: a, shiftKey: i, altKey: s } = t;
|
|
880
|
+
switch (e) {
|
|
881
|
+
case "ArrowLeft":
|
|
882
|
+
t.preventDefault(), this.navigateDate(-1);
|
|
883
|
+
break;
|
|
884
|
+
case "ArrowRight":
|
|
885
|
+
t.preventDefault(), this.navigateDate(1);
|
|
886
|
+
break;
|
|
887
|
+
case "ArrowUp":
|
|
888
|
+
t.preventDefault(), this.navigateDate(-7);
|
|
889
|
+
break;
|
|
890
|
+
case "ArrowDown":
|
|
891
|
+
t.preventDefault(), this.navigateDate(7);
|
|
892
|
+
break;
|
|
893
|
+
case "Home":
|
|
894
|
+
t.preventDefault(), this.navigateToStartOfWeek();
|
|
895
|
+
break;
|
|
896
|
+
case "End":
|
|
897
|
+
t.preventDefault(), this.navigateToEndOfWeek();
|
|
898
|
+
break;
|
|
899
|
+
case "PageUp":
|
|
900
|
+
t.preventDefault(), this.navigateMonth(i ? -12 : -1);
|
|
901
|
+
break;
|
|
902
|
+
case "PageDown":
|
|
903
|
+
t.preventDefault(), this.navigateMonth(i ? 12 : 1);
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
switch (e) {
|
|
907
|
+
case "Enter":
|
|
908
|
+
case " ":
|
|
909
|
+
t.preventDefault(), this.currentFocusedDate && this.onDateSelect && this.onDateSelect(this.currentFocusedDate);
|
|
910
|
+
break;
|
|
911
|
+
case "Escape":
|
|
912
|
+
t.preventDefault(), this.onClose && this.onClose();
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
if (!a && !s)
|
|
916
|
+
switch (e.toLowerCase()) {
|
|
917
|
+
case ((o = (n = this.options.shortcuts) == null ? void 0 : n.today) == null ? void 0 : o.toLowerCase()):
|
|
918
|
+
t.preventDefault(), this.onToday && this.onToday();
|
|
919
|
+
break;
|
|
920
|
+
case ((c = (l = this.options.shortcuts) == null ? void 0 : l.clear) == null ? void 0 : c.toLowerCase()):
|
|
921
|
+
t.preventDefault(), this.onClear && this.onClear();
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
if (a && !s && !i)
|
|
925
|
+
switch (e.toLowerCase()) {
|
|
926
|
+
case "enter":
|
|
927
|
+
t.preventDefault(), this.onApply && this.onApply();
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
handleFocus() {
|
|
932
|
+
this.isActive || this.activate();
|
|
933
|
+
}
|
|
934
|
+
handleBlur() {
|
|
935
|
+
setTimeout(() => {
|
|
936
|
+
this.container.contains(document.activeElement) || this.deactivate();
|
|
937
|
+
}, 100);
|
|
938
|
+
}
|
|
939
|
+
navigateDate(t) {
|
|
940
|
+
if (!this.currentFocusedDate) return;
|
|
941
|
+
const e = new Date(this.currentFocusedDate);
|
|
942
|
+
e.setDate(e.getDate() + t), this.currentFocusedDate = e, this.updateFocusedDate();
|
|
943
|
+
}
|
|
944
|
+
navigateMonth(t) {
|
|
945
|
+
if (!this.currentFocusedDate) return;
|
|
946
|
+
const e = new Date(this.currentFocusedDate);
|
|
947
|
+
e.setMonth(e.getMonth() + t), this.currentFocusedDate = e, this.updateFocusedDate();
|
|
620
948
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
this.
|
|
949
|
+
navigateToStartOfWeek() {
|
|
950
|
+
if (!this.currentFocusedDate) return;
|
|
951
|
+
const t = new Date(this.currentFocusedDate), e = t.getDay();
|
|
952
|
+
t.setDate(t.getDate() - e), this.currentFocusedDate = t, this.updateFocusedDate();
|
|
624
953
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
954
|
+
navigateToEndOfWeek() {
|
|
955
|
+
if (!this.currentFocusedDate) return;
|
|
956
|
+
const t = new Date(this.currentFocusedDate), e = t.getDay();
|
|
957
|
+
t.setDate(t.getDate() + (6 - e)), this.currentFocusedDate = t, this.updateFocusedDate();
|
|
628
958
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
this.
|
|
632
|
-
|
|
633
|
-
}
|
|
959
|
+
updateFocusedDate() {
|
|
960
|
+
if (!this.currentFocusedDate) return;
|
|
961
|
+
this.removeFocusStyles();
|
|
962
|
+
const t = this.formatDateForSelector(this.currentFocusedDate), e = this.container.querySelector(
|
|
963
|
+
`[data-date="${t}"]`
|
|
964
|
+
);
|
|
965
|
+
e && (e.classList.add("keyboard-focused"), e.setAttribute("aria-selected", "true"), e.scrollIntoView({ block: "nearest", inline: "nearest" })), this.addFocusStyles();
|
|
966
|
+
}
|
|
967
|
+
removeFocusStyles() {
|
|
968
|
+
this.container.querySelectorAll(".keyboard-focused").forEach((e) => {
|
|
969
|
+
e.classList.remove("keyboard-focused"), e.removeAttribute("aria-selected");
|
|
634
970
|
});
|
|
635
971
|
}
|
|
636
|
-
|
|
637
|
-
|
|
972
|
+
addFocusStyles() {
|
|
973
|
+
if (this.container.querySelector(".keyboard-focus-styles")) return;
|
|
974
|
+
const t = document.createElement("style");
|
|
975
|
+
t.className = "keyboard-focus-styles", t.textContent = `
|
|
976
|
+
.datex-picker .calendar-table td.keyboard-focused {
|
|
977
|
+
outline: 2px solid #10b981 !important;
|
|
978
|
+
outline-offset: -2px !important;
|
|
979
|
+
z-index: 10 !important;
|
|
980
|
+
position: relative !important;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
.datex-picker .calendar-table td.keyboard-focused > * {
|
|
984
|
+
background: #10b981 !important;
|
|
985
|
+
color: white !important;
|
|
986
|
+
font-weight: 600 !important;
|
|
987
|
+
}
|
|
988
|
+
`, document.head.appendChild(t);
|
|
989
|
+
}
|
|
990
|
+
formatDateForSelector(t) {
|
|
991
|
+
const e = t.getFullYear(), a = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getDate()).padStart(2, "0");
|
|
992
|
+
return `${e}-${a}-${i}`;
|
|
993
|
+
}
|
|
994
|
+
// Public methods
|
|
995
|
+
getCurrentFocusedDate() {
|
|
996
|
+
return this.currentFocusedDate;
|
|
997
|
+
}
|
|
998
|
+
setFocusedDate(t) {
|
|
999
|
+
this.currentFocusedDate = t, this.updateFocusedDate();
|
|
1000
|
+
}
|
|
1001
|
+
cleanup() {
|
|
1002
|
+
this.container.removeEventListener(
|
|
1003
|
+
"keydown",
|
|
1004
|
+
this.handleKeyDown.bind(this)
|
|
1005
|
+
), this.container.removeEventListener("focus", this.handleFocus.bind(this)), this.container.removeEventListener("blur", this.handleBlur.bind(this)), this.removeFocusStyles();
|
|
1006
|
+
const t = document.querySelector(".keyboard-focus-styles");
|
|
1007
|
+
t && t.remove();
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const F = {
|
|
1011
|
+
format: "DD/MM/YYYY",
|
|
1012
|
+
separator: " - ",
|
|
1013
|
+
applyLabel: "Aplicar",
|
|
1014
|
+
cancelLabel: "Cancelar",
|
|
1015
|
+
customRangeLabel: "Rango Personalizado",
|
|
1016
|
+
daysOfWeek: ["Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
|
|
1017
|
+
monthNames: [
|
|
1018
|
+
"Enero",
|
|
1019
|
+
"Febrero",
|
|
1020
|
+
"Marzo",
|
|
1021
|
+
"Abril",
|
|
1022
|
+
"Mayo",
|
|
1023
|
+
"Junio",
|
|
1024
|
+
"Julio",
|
|
1025
|
+
"Agosto",
|
|
1026
|
+
"Septiembre",
|
|
1027
|
+
"Octubre",
|
|
1028
|
+
"Noviembre",
|
|
1029
|
+
"Diciembre"
|
|
1030
|
+
],
|
|
1031
|
+
firstDay: 1
|
|
1032
|
+
}, I = {
|
|
1033
|
+
format: "DD/MM/YYYY HH:mm",
|
|
1034
|
+
separator: " - ",
|
|
1035
|
+
applyLabel: "Aplicar",
|
|
1036
|
+
cancelLabel: "Cancelar",
|
|
1037
|
+
customRangeLabel: "Rango Personalizado",
|
|
1038
|
+
daysOfWeek: ["Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
|
|
1039
|
+
monthNames: [
|
|
1040
|
+
"Enero",
|
|
1041
|
+
"Febrero",
|
|
1042
|
+
"Marzo",
|
|
1043
|
+
"Abril",
|
|
1044
|
+
"Mayo",
|
|
1045
|
+
"Junio",
|
|
1046
|
+
"Julio",
|
|
1047
|
+
"Agosto",
|
|
1048
|
+
"Septiembre",
|
|
1049
|
+
"Octubre",
|
|
1050
|
+
"Noviembre",
|
|
1051
|
+
"Diciembre"
|
|
1052
|
+
],
|
|
1053
|
+
firstDay: 1
|
|
1054
|
+
};
|
|
1055
|
+
class P {
|
|
1056
|
+
constructor(t, e = {}, a) {
|
|
1057
|
+
this.element = this.resolveElement(t), this.options = this.mergeWithDefaults(e), this.locale = this.options.locale, this.callback = a || (() => {
|
|
1058
|
+
}), this.eventService = new S(), this.initializeState(), this.initializeServices(), this.createContainer(), this.setupEventListeners(), this.updateElement(), this.calculateChosenLabel();
|
|
1059
|
+
}
|
|
1060
|
+
resolveElement(t) {
|
|
1061
|
+
if (typeof t == "string") {
|
|
1062
|
+
const e = t.startsWith("#") ? document.getElementById(t.slice(1)) : document.querySelector(t) || document.getElementById(t);
|
|
1063
|
+
if (!e || !(e instanceof HTMLElement))
|
|
1064
|
+
throw new Error("Datex: Element not found");
|
|
1065
|
+
return e;
|
|
1066
|
+
}
|
|
1067
|
+
return t;
|
|
1068
|
+
}
|
|
1069
|
+
mergeWithDefaults(t) {
|
|
1070
|
+
const e = /* @__PURE__ */ new Date(), a = {
|
|
638
1071
|
startDate: t.startDate || e,
|
|
639
1072
|
endDate: t.endDate || e,
|
|
640
1073
|
minDate: t.minDate ?? null,
|
|
@@ -656,16 +1089,39 @@ class q {
|
|
|
656
1089
|
ranges: t.ranges || {},
|
|
657
1090
|
opens: t.opens || "center",
|
|
658
1091
|
drops: t.drops || "auto",
|
|
659
|
-
locale: t.locale ||
|
|
1092
|
+
locale: t.locale || F,
|
|
660
1093
|
buttonClasses: t.buttonClasses || "btn btn-sm",
|
|
661
1094
|
applyButtonClasses: t.applyButtonClasses || "btn-success",
|
|
662
1095
|
cancelButtonClasses: t.cancelButtonClasses || "btn-danger",
|
|
663
|
-
theme: t.theme ||
|
|
1096
|
+
theme: t.theme || C,
|
|
1097
|
+
validation: t.validation || {},
|
|
1098
|
+
events: t.events || {}
|
|
1099
|
+
};
|
|
1100
|
+
return a.timePicker && a.autoApply && (a.autoApply = !1), a;
|
|
1101
|
+
}
|
|
1102
|
+
initializeState() {
|
|
1103
|
+
const t = /* @__PURE__ */ new Date();
|
|
1104
|
+
this.state = {
|
|
1105
|
+
startDate: this.options.timePicker ? this.options.startDate : v(this.options.startDate),
|
|
1106
|
+
endDate: this.options.timePicker ? this.options.endDate : y(this.options.endDate),
|
|
1107
|
+
oldStartDate: this.options.timePicker ? this.options.startDate : v(this.options.startDate),
|
|
1108
|
+
oldEndDate: this.options.timePicker ? this.options.endDate : y(this.options.endDate),
|
|
1109
|
+
isShowing: !1,
|
|
1110
|
+
leftCalendar: { month: t, calendar: [] },
|
|
1111
|
+
rightCalendar: { month: h(t, 1), calendar: [] },
|
|
1112
|
+
chosenLabel: null,
|
|
1113
|
+
hoverDate: null
|
|
664
1114
|
};
|
|
665
|
-
|
|
1115
|
+
}
|
|
1116
|
+
initializeServices() {
|
|
1117
|
+
this.calendarService = new L(this.options, this.locale);
|
|
666
1118
|
}
|
|
667
1119
|
createContainer() {
|
|
668
|
-
const t =
|
|
1120
|
+
const t = this.buildContainerTemplate(), e = document.createElement("div");
|
|
1121
|
+
e.innerHTML = t.trim(), this.container = e.firstElementChild, document.body.appendChild(this.container), this.initializeContainerServices(), this.setupContainerClasses(), this.setupInitialVisibility();
|
|
1122
|
+
}
|
|
1123
|
+
buildContainerTemplate() {
|
|
1124
|
+
return `
|
|
669
1125
|
<div class="datex-picker">
|
|
670
1126
|
<div class="ranges"></div>
|
|
671
1127
|
<div class="drp-calendar left">
|
|
@@ -686,631 +1142,509 @@ class q {
|
|
|
686
1142
|
</button>
|
|
687
1143
|
</div>
|
|
688
1144
|
</div>
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1145
|
+
`;
|
|
1146
|
+
}
|
|
1147
|
+
initializeContainerServices() {
|
|
1148
|
+
this.themeService = new w(this.container, this.options.theme), this.positionService = new E(
|
|
1149
|
+
this.element,
|
|
1150
|
+
this.container,
|
|
1151
|
+
this.options
|
|
1152
|
+
), this.validationService = new M(this.options.validation), this.keyboardService = new $(this.container, {
|
|
1153
|
+
enabled: !0
|
|
1154
|
+
}), this.keyboardService.setHandlers({
|
|
1155
|
+
onDateSelect: (t) => {
|
|
1156
|
+
this.handleKeyboardDateSelect(t);
|
|
1157
|
+
},
|
|
1158
|
+
onClose: () => {
|
|
1159
|
+
this.hide();
|
|
1160
|
+
},
|
|
1161
|
+
onToday: () => {
|
|
1162
|
+
const t = /* @__PURE__ */ new Date();
|
|
1163
|
+
this.setStartDate(t), this.setEndDate(t), this.updateView();
|
|
1164
|
+
},
|
|
1165
|
+
onClear: () => {
|
|
1166
|
+
this.clearSelection();
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
setupContainerClasses() {
|
|
1171
|
+
this.container.classList.add(`opens${this.options.opens}`), this.options.singleDatePicker && this.container.classList.add("single"), this.options.autoApply && this.container.classList.add("auto-apply"), Object.keys(this.options.ranges).length > 0 && (this.container.classList.add("show-ranges"), this.renderRanges()), (this.options.alwaysShowCalendars || Object.keys(this.options.ranges).length === 0) && this.container.classList.add("show-calendar"), this.options.autoApply || this.container.classList.add("show-calendar");
|
|
1172
|
+
}
|
|
1173
|
+
setupInitialVisibility() {
|
|
1174
|
+
this.options.timePicker || this.container.querySelectorAll(".calendar-time").forEach((e) => {
|
|
1175
|
+
e.style.display = "none";
|
|
692
1176
|
}), this.container.style.display = "none";
|
|
693
1177
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
this.
|
|
1178
|
+
// Public API methods
|
|
1179
|
+
show() {
|
|
1180
|
+
this.state.isShowing || (this.storeOldValues(), this.themeService.applyTheme(), this.setupDocumentListeners(), this.updateView(), this.displayContainer(), this.positionContainer(), this.keyboardService.activate(this.state.startDate), this.dispatchShowEvent());
|
|
1181
|
+
}
|
|
1182
|
+
hide() {
|
|
1183
|
+
this.state.isShowing && (this.revertIfIncomplete(), this.triggerCallbackIfChanged(), this.updateElement(), this.removeDocumentListeners(), this.keyboardService.deactivate(), this.hideContainer(), this.dispatchHideEvent());
|
|
1184
|
+
}
|
|
1185
|
+
toggle() {
|
|
1186
|
+
this.state.isShowing ? this.hide() : this.show();
|
|
1187
|
+
}
|
|
1188
|
+
setStartDate(t) {
|
|
1189
|
+
this.state.startDate = this.options.timePicker ? new Date(t) : v(t), this.options.timePickerIncrement && this.options.timePicker && this.roundToIncrement(this.state.startDate), this.updateView();
|
|
1190
|
+
}
|
|
1191
|
+
setEndDate(t) {
|
|
1192
|
+
this.state.endDate = this.options.timePicker ? new Date(t) : y(t), this.options.timePickerIncrement && this.options.timePicker && this.roundToIncrement(this.state.endDate), this.updateView();
|
|
1193
|
+
}
|
|
1194
|
+
getStartDate() {
|
|
1195
|
+
return new Date(this.state.startDate);
|
|
1196
|
+
}
|
|
1197
|
+
getEndDate() {
|
|
1198
|
+
return this.state.endDate ? new Date(this.state.endDate) : null;
|
|
1199
|
+
}
|
|
1200
|
+
setTheme(t) {
|
|
1201
|
+
this.themeService.setTheme(t);
|
|
1202
|
+
}
|
|
1203
|
+
// Validation methods
|
|
1204
|
+
updateValidation(t) {
|
|
1205
|
+
this.validationService.updateValidation(t);
|
|
1206
|
+
}
|
|
1207
|
+
validateDate(t) {
|
|
1208
|
+
return this.validationService.validateDate(t);
|
|
1209
|
+
}
|
|
1210
|
+
validateDateRange(t, e) {
|
|
1211
|
+
return this.validationService.validateDateRange(t, e);
|
|
1212
|
+
}
|
|
1213
|
+
// Keyboard navigation methods
|
|
1214
|
+
enableKeyboardNavigation() {
|
|
1215
|
+
this.state.isShowing && this.keyboardService.activate(this.state.startDate);
|
|
1216
|
+
}
|
|
1217
|
+
disableKeyboardNavigation() {
|
|
1218
|
+
this.keyboardService.deactivate();
|
|
1219
|
+
}
|
|
1220
|
+
setKeyboardFocusedDate(t) {
|
|
1221
|
+
this.keyboardService.setFocusedDate(t);
|
|
1222
|
+
}
|
|
1223
|
+
remove() {
|
|
1224
|
+
this.cleanup();
|
|
1225
|
+
}
|
|
1226
|
+
// Private helper methods
|
|
1227
|
+
storeOldValues() {
|
|
1228
|
+
this.state.oldStartDate = new Date(this.state.startDate), this.state.oldEndDate = this.state.endDate ? new Date(this.state.endDate) : null;
|
|
1229
|
+
}
|
|
1230
|
+
setupDocumentListeners() {
|
|
1231
|
+
this.eventService.setDocumentListeners(
|
|
1232
|
+
this.handleOutsideClick.bind(this),
|
|
1233
|
+
this.handleOutsideFocus.bind(this)
|
|
1234
|
+
), this.eventService.setWindowListeners(
|
|
1235
|
+
this.positionContainer.bind(this),
|
|
1236
|
+
this.positionContainer.bind(this)
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
removeDocumentListeners() {
|
|
1240
|
+
this.eventService.removeDocumentListeners(), this.eventService.removeWindowListeners();
|
|
1241
|
+
}
|
|
1242
|
+
displayContainer() {
|
|
1243
|
+
this.container.style.display = "block", this.state.isShowing = !0;
|
|
1244
|
+
}
|
|
1245
|
+
hideContainer() {
|
|
1246
|
+
this.container.style.display = "none", this.state.isShowing = !1;
|
|
1247
|
+
}
|
|
1248
|
+
positionContainer() {
|
|
1249
|
+
setTimeout(() => this.positionService.calculatePosition(), 0);
|
|
1250
|
+
}
|
|
1251
|
+
revertIfIncomplete() {
|
|
1252
|
+
this.state.endDate || (this.state.startDate = new Date(this.state.oldStartDate), this.state.endDate = this.state.oldEndDate ? new Date(this.state.oldEndDate) : null);
|
|
1253
|
+
}
|
|
1254
|
+
triggerCallbackIfChanged() {
|
|
1255
|
+
const t = !d(
|
|
1256
|
+
this.state.startDate,
|
|
1257
|
+
this.state.oldStartDate,
|
|
1258
|
+
"day"
|
|
1259
|
+
), e = this.state.endDate && this.state.oldEndDate && !d(this.state.endDate, this.state.oldEndDate, "day");
|
|
1260
|
+
(t || e) && this.callback(
|
|
1261
|
+
new Date(this.state.startDate),
|
|
1262
|
+
this.state.endDate ? new Date(this.state.endDate) : new Date(this.state.startDate),
|
|
1263
|
+
this.state.chosenLabel || void 0
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
roundToIncrement(t) {
|
|
1267
|
+
if (!this.options.timePickerIncrement) return;
|
|
1268
|
+
const e = Math.round(t.getMinutes() / this.options.timePickerIncrement) * this.options.timePickerIncrement;
|
|
1269
|
+
t.setMinutes(e);
|
|
1270
|
+
}
|
|
1271
|
+
dispatchShowEvent() {
|
|
1272
|
+
this.eventService.dispatchEvent(this.element, "show.daterangepicker", this);
|
|
1273
|
+
}
|
|
1274
|
+
dispatchHideEvent() {
|
|
1275
|
+
this.eventService.dispatchEvent(this.element, "hide.daterangepicker", this);
|
|
1276
|
+
}
|
|
1277
|
+
cleanup() {
|
|
1278
|
+
var t;
|
|
1279
|
+
this.removeDocumentListeners(), this.themeService.cleanup(), this.eventService.cleanup(), this.keyboardService.cleanup(), (t = this.container) != null && t.parentNode && this.container.parentNode.removeChild(this.container);
|
|
1280
|
+
}
|
|
1281
|
+
handleKeyboardDateSelect(t) {
|
|
1282
|
+
const e = this.validationService.validateDate(t);
|
|
1283
|
+
if (!e.isValid) {
|
|
1284
|
+
this.showValidationError(e.error, e.errorCode);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
this.state.hoverDate = null, this.state.endDate || p(t, this.state.startDate) ? (this.state.endDate = null, this.setStartDate(t)) : (this.setEndDate(t), this.options.autoApply && (this.calculateChosenLabel(), this.handleApplyClick())), this.options.singleDatePicker && (this.setEndDate(this.state.startDate), this.options.autoApply && this.handleApplyClick()), this.updateDateClasses();
|
|
1288
|
+
}
|
|
1289
|
+
clearSelection() {
|
|
1290
|
+
const t = /* @__PURE__ */ new Date();
|
|
1291
|
+
this.state.startDate = t, this.state.endDate = null, this.state.chosenLabel = null, this.updateView();
|
|
1292
|
+
}
|
|
1293
|
+
showValidationError(t, e) {
|
|
1294
|
+
var a;
|
|
1295
|
+
(a = this.options.events) != null && a.onValidationError && this.options.events.onValidationError(t, e), console.warn(`DateX Validation Error: ${t} (${e})`);
|
|
700
1296
|
}
|
|
701
1297
|
setupEventListeners() {
|
|
702
|
-
this.
|
|
1298
|
+
this.setupElementEvents(), this.setupContainerEvents();
|
|
1299
|
+
}
|
|
1300
|
+
setupElementEvents() {
|
|
1301
|
+
this.isInputOrButton() ? (this.eventService.addEventHandler(
|
|
1302
|
+
this.element,
|
|
1303
|
+
"click",
|
|
1304
|
+
this.show.bind(this)
|
|
1305
|
+
), this.eventService.addEventHandler(
|
|
1306
|
+
this.element,
|
|
1307
|
+
"focus",
|
|
1308
|
+
this.show.bind(this)
|
|
1309
|
+
), this.eventService.addEventHandler(
|
|
703
1310
|
this.element,
|
|
704
1311
|
"keyup",
|
|
705
|
-
this.
|
|
706
|
-
), this.addEventHandler(
|
|
1312
|
+
this.handleElementChange.bind(this)
|
|
1313
|
+
), this.eventService.addEventHandler(
|
|
707
1314
|
this.element,
|
|
708
1315
|
"keydown",
|
|
709
|
-
this.
|
|
710
|
-
)) : this.
|
|
1316
|
+
this.handleKeydown.bind(this)
|
|
1317
|
+
)) : this.eventService.addEventHandler(
|
|
1318
|
+
this.element,
|
|
1319
|
+
"click",
|
|
1320
|
+
this.toggle.bind(this)
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
setupContainerEvents() {
|
|
1324
|
+
this.eventService.addEventHandler(
|
|
711
1325
|
this.container,
|
|
712
1326
|
"click",
|
|
713
|
-
this.
|
|
714
|
-
), this.addEventHandler(
|
|
1327
|
+
this.handleContainerClick.bind(this)
|
|
1328
|
+
), this.eventService.addEventHandler(
|
|
715
1329
|
this.container,
|
|
716
1330
|
"mouseover",
|
|
717
|
-
this.
|
|
718
|
-
), this.addEventHandler(
|
|
1331
|
+
this.handleContainerMouseOver.bind(this)
|
|
1332
|
+
), this.eventService.addEventHandler(
|
|
719
1333
|
this.container,
|
|
720
1334
|
"mouseleave",
|
|
721
|
-
this.
|
|
722
|
-
), this.addEventHandler(
|
|
1335
|
+
this.handleContainerMouseLeave.bind(this)
|
|
1336
|
+
), this.eventService.addEventHandler(
|
|
723
1337
|
this.container,
|
|
724
1338
|
"change",
|
|
725
|
-
this.
|
|
726
|
-
)
|
|
727
|
-
this.container.querySelectorAll(
|
|
728
|
-
"select.monthselect, select.yearselect"
|
|
729
|
-
).forEach((e) => {
|
|
730
|
-
this.addEventHandler(
|
|
731
|
-
e,
|
|
732
|
-
"change",
|
|
733
|
-
this.monthOrYearChanged.bind(this)
|
|
734
|
-
);
|
|
735
|
-
});
|
|
736
|
-
}, 100);
|
|
737
|
-
}
|
|
738
|
-
addEventHandler(t, e, i) {
|
|
739
|
-
const a = `${e}_${Math.random()}`;
|
|
740
|
-
this.boundHandlers.set(a, i), t.addEventListener(e, i);
|
|
741
|
-
}
|
|
742
|
-
containerChange(t) {
|
|
743
|
-
if (t.target.matches("select.monthselect, select.yearselect")) {
|
|
744
|
-
this.monthOrYearChanged(t);
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
containerMouseOver(t) {
|
|
749
|
-
if (t.target.matches("td.available")) {
|
|
750
|
-
this.hoverDate(t);
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
containerMouseLeave() {
|
|
755
|
-
this.state.hoverDate && (this.state.hoverDate = null, this.updateDateClasses());
|
|
1339
|
+
this.handleContainerChange.bind(this)
|
|
1340
|
+
);
|
|
756
1341
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (!(e.tagName === "SELECT" || e.closest("select"))) {
|
|
760
|
-
if (e.matches(".ranges li")) {
|
|
761
|
-
this.clickRange(t);
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
if (e.matches(".applyBtn")) {
|
|
765
|
-
this.clickApply(t);
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
if (e.matches(".cancelBtn")) {
|
|
769
|
-
this.clickCancel(t);
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
if (e.matches(".prev")) {
|
|
773
|
-
this.clickPrev(t);
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
if (e.matches(".next")) {
|
|
777
|
-
this.clickNext(t);
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
if (e.matches("td.available")) {
|
|
781
|
-
this.clickDate(t);
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
1342
|
+
isInputOrButton() {
|
|
1343
|
+
return this.element.tagName === "INPUT" || this.element.tagName === "BUTTON";
|
|
785
1344
|
}
|
|
786
|
-
|
|
1345
|
+
handleContainerClick(t) {
|
|
787
1346
|
const e = t.target;
|
|
788
|
-
e.tagName === "SELECT" || e.closest("select") || t.
|
|
1347
|
+
e.tagName === "SELECT" || e.closest("select") || (e.matches(".ranges li") ? this.handleRangeClick(t) : e.matches(".applyBtn") ? this.handleApplyClick() : e.matches(".cancelBtn") ? this.handleCancelClick() : e.matches(".prev") ? this.handlePrevClick(t) : e.matches(".next") ? this.handleNextClick(t) : e.matches("td.available") && this.handleDateClick(t));
|
|
789
1348
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
this.move();
|
|
793
|
-
}, 0), this.dispatchEvent("show.daterangepicker"), this.state.isShowing = !0);
|
|
1349
|
+
handleContainerMouseOver(t) {
|
|
1350
|
+
t.target.matches("td.available") && this.handleDateHover(t);
|
|
794
1351
|
}
|
|
795
|
-
|
|
796
|
-
this.state.
|
|
797
|
-
new Date(this.state.startDate),
|
|
798
|
-
this.state.endDate ? new Date(this.state.endDate) : new Date(this.state.startDate),
|
|
799
|
-
this.state.chosenLabel || void 0
|
|
800
|
-
), this.updateElement(), this.removeDocumentListeners(), this.container.style.display = "none", this.dispatchEvent("hide.daterangepicker"), this.state.isShowing = !1);
|
|
1352
|
+
handleContainerMouseLeave() {
|
|
1353
|
+
this.state.hoverDate && (this.state.hoverDate = null, this.updateDateClasses());
|
|
801
1354
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
"mousedown",
|
|
805
|
-
this.documentClickHandler,
|
|
806
|
-
!0
|
|
807
|
-
), this.documentClickHandler = void 0), this.documentFocusHandler && (document.removeEventListener("focusin", this.documentFocusHandler, !0), this.documentFocusHandler = void 0), this.resizeHandler && (window.removeEventListener("resize", this.resizeHandler), this.resizeHandler = void 0), this.scrollHandler && (window.removeEventListener("scroll", this.scrollHandler, !0), this.scrollHandler = void 0);
|
|
1355
|
+
handleContainerChange(t) {
|
|
1356
|
+
t.target.matches("select.monthselect, select.yearselect") && this.handleMonthYearChange(t);
|
|
808
1357
|
}
|
|
809
|
-
|
|
1358
|
+
handleOutsideClick(t) {
|
|
810
1359
|
const e = t.target;
|
|
811
|
-
this.element.contains(e) || this.container.contains(e) || e.closest(".datex-picker") || e.tagName === "SELECT" || e.closest("select") || (this.hide(), this.dispatchEvent(
|
|
1360
|
+
this.element.contains(e) || this.container.contains(e) || e.closest(".datex-picker") || e.tagName === "SELECT" || e.closest("select") || (this.hide(), this.eventService.dispatchEvent(
|
|
1361
|
+
this.element,
|
|
1362
|
+
"outsideClick.daterangepicker"
|
|
1363
|
+
));
|
|
812
1364
|
}
|
|
813
|
-
|
|
1365
|
+
handleOutsideFocus(t) {
|
|
814
1366
|
const e = t.target;
|
|
815
1367
|
this.element.contains(e) || this.container.contains(e) || e.closest(".datex-picker") || setTimeout(() => {
|
|
816
|
-
const
|
|
817
|
-
|
|
1368
|
+
const a = document.activeElement;
|
|
1369
|
+
a && !this.element.contains(a) && !this.container.contains(a) && !a.closest(".datex-picker") && this.hide();
|
|
818
1370
|
}, 50);
|
|
819
1371
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
if (
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
".right .calendar-time select"
|
|
828
|
-
);
|
|
829
|
-
this.state.endDate ? t.forEach((e) => {
|
|
830
|
-
e.disabled = !1, e.classList.remove("disabled");
|
|
831
|
-
}) : t.forEach((e) => {
|
|
832
|
-
e.disabled = !0, e.classList.add("disabled");
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
this.updateMonthsInView(), this.updateCalendars(), this.updateFormInputs(), this.updateSelectedDisplay(), this.calculateChosenLabel();
|
|
836
|
-
}
|
|
837
|
-
updateMonthsInView() {
|
|
838
|
-
this.state.endDate ? (this.state.leftCalendar.month = this.getStartOfMonth(
|
|
839
|
-
this.state.startDate
|
|
840
|
-
), !this.options.linkedCalendars && (this.state.endDate.getMonth() !== this.state.startDate.getMonth() || this.state.endDate.getFullYear() !== this.state.startDate.getFullYear()) ? this.state.rightCalendar.month = this.getStartOfMonth(
|
|
841
|
-
this.state.endDate
|
|
842
|
-
) : this.state.rightCalendar.month = y(
|
|
843
|
-
this.state.leftCalendar.month,
|
|
844
|
-
1
|
|
845
|
-
)) : (this.state.leftCalendar.month = this.getStartOfMonth(
|
|
846
|
-
this.state.startDate
|
|
847
|
-
), this.state.rightCalendar.month = y(
|
|
848
|
-
this.state.leftCalendar.month,
|
|
849
|
-
1
|
|
850
|
-
));
|
|
851
|
-
}
|
|
852
|
-
getStartOfMonth(t) {
|
|
853
|
-
return new Date(t.getFullYear(), t.getMonth(), 1);
|
|
854
|
-
}
|
|
855
|
-
getEndOfMonth(t) {
|
|
856
|
-
return new Date(t.getFullYear(), t.getMonth() + 1, 0);
|
|
857
|
-
}
|
|
858
|
-
getStartOfWeek(t, e = 1) {
|
|
859
|
-
const a = (t.getDay() - e + 7) % 7, n = new Date(t);
|
|
860
|
-
return n.setDate(t.getDate() - a), n;
|
|
861
|
-
}
|
|
862
|
-
updateCalendars() {
|
|
863
|
-
this.renderCalendar("left"), this.options.singleDatePicker || this.renderCalendar("right"), setTimeout(() => {
|
|
864
|
-
this.container.querySelectorAll(
|
|
865
|
-
"select.monthselect, select.yearselect"
|
|
866
|
-
).forEach((e) => {
|
|
867
|
-
e.removeEventListener(
|
|
868
|
-
"change",
|
|
869
|
-
this.monthOrYearChanged.bind(this)
|
|
870
|
-
), e.addEventListener("change", this.monthOrYearChanged.bind(this));
|
|
871
|
-
});
|
|
872
|
-
}, 10);
|
|
873
|
-
}
|
|
874
|
-
renderCalendar(t) {
|
|
875
|
-
const e = t === "left" ? this.state.leftCalendar : this.state.rightCalendar, i = this.container.querySelector(
|
|
876
|
-
`.drp-calendar.${t} .calendar-table`
|
|
877
|
-
), a = e.month, n = a.getFullYear(), o = a.getMonth(), r = this.getStartOfMonth(a), f = this.getStartOfWeek(r, this.locale.firstDay), h = [];
|
|
878
|
-
let d = [];
|
|
879
|
-
const p = new Date(f);
|
|
880
|
-
for (let D = 0; D < 42; D++) {
|
|
881
|
-
D > 0 && D % 7 === 0 && (h.push(d), d = []);
|
|
882
|
-
const k = new Date(p);
|
|
883
|
-
k.setDate(p.getDate() + D), d.push(k);
|
|
884
|
-
}
|
|
885
|
-
d.length > 0 && h.push(d), e.calendar = h;
|
|
886
|
-
let s = '<table class="table-condensed">';
|
|
887
|
-
s += "<thead>", s += "<tr>";
|
|
888
|
-
const l = !this.options.minDate || b(this.getStartOfMonth(a), this.options.minDate), m = !this.options.maxDate || g(this.getEndOfMonth(a), this.options.maxDate);
|
|
889
|
-
l && (!this.options.linkedCalendars || t === "left") ? s += '<th class="prev available"><span></span></th>' : s += "<th></th>";
|
|
890
|
-
let u = this.locale.monthNames[o] + " " + n;
|
|
891
|
-
this.options.showDropdowns && (u = this.renderDropdowns(o, n, t)), s += `<th colspan="5" class="month">${u}</th>`, m && (!this.options.linkedCalendars || t === "right" || this.options.singleDatePicker) ? s += '<th class="next available"><span></span></th>' : s += "<th></th>", s += "</tr>", s += "<tr>";
|
|
892
|
-
for (const D of this.locale.daysOfWeek)
|
|
893
|
-
s += `<th>${D}</th>`;
|
|
894
|
-
s += "</tr>", s += "</thead>", s += "<tbody>";
|
|
895
|
-
for (const D of h) {
|
|
896
|
-
s += "<tr>";
|
|
897
|
-
for (const k of D) {
|
|
898
|
-
const w = this.getDayClasses(k, a), H = w.includes("disabled"), P = w.join(" ") + (H ? "" : " available");
|
|
899
|
-
s += `<td class="${P}" data-date="${v(
|
|
900
|
-
k,
|
|
901
|
-
"YYYY-MM-DD"
|
|
902
|
-
)}">${k.getDate()}</td>`;
|
|
903
|
-
}
|
|
904
|
-
s += "</tr>";
|
|
905
|
-
}
|
|
906
|
-
s += "</tbody>", s += "</table>", i.innerHTML = s, this.options.timePicker && this.renderTimePicker(t);
|
|
907
|
-
}
|
|
908
|
-
renderDropdowns(t, e, i) {
|
|
909
|
-
let a = this.options.minYear, n = this.options.maxYear;
|
|
910
|
-
this.options.minDate && (a = Math.max(a, this.options.minDate.getFullYear())), this.options.maxDate && (n = Math.min(n, this.options.maxDate.getFullYear()));
|
|
911
|
-
const o = e, r = o === a, f = o === n;
|
|
912
|
-
let h = '<select class="monthselect">';
|
|
913
|
-
for (let p = 0; p < 12; p++) {
|
|
914
|
-
let s = !1;
|
|
915
|
-
r && this.options.minDate && p < this.options.minDate.getMonth() && (s = !0), f && this.options.maxDate && p > this.options.maxDate.getMonth() && (s = !0), h += `<option value="${p}"${p === t ? ' selected="selected"' : ""}${s ? ' disabled="disabled"' : ""}>${this.locale.monthNames[p]}</option>`;
|
|
916
|
-
}
|
|
917
|
-
h += "</select>";
|
|
918
|
-
let d = '<select class="yearselect">';
|
|
919
|
-
for (let p = a; p <= n; p++)
|
|
920
|
-
d += `<option value="${p}"${p === e ? ' selected="selected"' : ""}>${p}</option>`;
|
|
921
|
-
return d += "</select>", h + " " + d;
|
|
922
|
-
}
|
|
923
|
-
getDayClasses(t, e) {
|
|
924
|
-
const i = [];
|
|
925
|
-
return x(t, /* @__PURE__ */ new Date(), "day") && i.push("today"), (t.getDay() === 0 || t.getDay() === 6) && i.push("weekend"), t.getMonth() !== e.getMonth() && i.push("off", "ends"), this.options.minDate && g(t, M(this.options.minDate)) && i.push("off", "disabled"), this.options.maxDate && b(t, E(this.options.maxDate)) && i.push("off", "disabled"), x(t, this.state.startDate, "day") && i.push("active", "start-date"), this.state.endDate && x(t, this.state.endDate, "day") && i.push("active", "end-date"), this.state.endDate && b(t, this.state.startDate) && g(t, this.state.endDate) && i.push("in-range"), i;
|
|
1372
|
+
handleElementChange() {
|
|
1373
|
+
var s;
|
|
1374
|
+
if (!this.isInputOrButton()) return;
|
|
1375
|
+
const t = this.element;
|
|
1376
|
+
if (!((s = t.value) != null && s.length)) return;
|
|
1377
|
+
const e = t.value.split(this.locale.separator), { startDate: a, endDate: i } = this.parseDateParts(e);
|
|
1378
|
+
a && f(a) && i && f(i) && (this.setStartDate(a), this.setEndDate(i), this.updateView());
|
|
926
1379
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
), e = this.options.singleDatePicker || this.state.endDate && (g(this.state.startDate, this.state.endDate) || x(this.state.startDate, this.state.endDate, "day"));
|
|
931
|
-
t.disabled = !e;
|
|
1380
|
+
parseDateParts(t) {
|
|
1381
|
+
let e = null, a = null;
|
|
1382
|
+
return t.length === 2 ? (e = m(t[0].trim(), this.locale.format), a = m(t[1].trim(), this.locale.format)) : (this.options.singleDatePicker || t.length === 1) && (e = m(t[0].trim(), this.locale.format), a = e), { startDate: e, endDate: a };
|
|
932
1383
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
let e = v(this.state.startDate, this.locale.format);
|
|
936
|
-
!this.options.singleDatePicker && this.state.endDate && (e += this.locale.separator + v(this.state.endDate, this.locale.format)), t.textContent = e;
|
|
1384
|
+
handleKeydown(t) {
|
|
1385
|
+
t.key === "Tab" || t.key === "Enter" ? this.hide() : t.key === "Escape" && (t.preventDefault(), t.stopPropagation(), this.hide());
|
|
937
1386
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
const
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
$(this.state.startDate, this.options.maxSpan.days || 0),
|
|
950
|
-
this.options.maxDate
|
|
951
|
-
)) && (o = $(this.state.startDate, this.options.maxSpan.days || 0)), t === "left")
|
|
952
|
-
a = new Date(this.state.startDate), n = this.options.minDate;
|
|
953
|
-
else {
|
|
954
|
-
a = this.state.endDate ? new Date(this.state.endDate) : new Date(this.state.startDate), n = this.state.startDate;
|
|
955
|
-
const s = this.container.querySelector(
|
|
956
|
-
".drp-calendar.right .calendar-time"
|
|
957
|
-
);
|
|
958
|
-
if (s && s.innerHTML !== "") {
|
|
959
|
-
const l = s.querySelector(
|
|
960
|
-
".hourselect"
|
|
961
|
-
), m = s.querySelector(
|
|
962
|
-
".minuteselect"
|
|
963
|
-
), u = s.querySelector(
|
|
964
|
-
".secondselect"
|
|
965
|
-
), D = s.querySelector(
|
|
966
|
-
".ampmselect"
|
|
967
|
-
);
|
|
968
|
-
if (l && l.value) {
|
|
969
|
-
let k = parseInt(l.value, 10);
|
|
970
|
-
if (!this.options.timePicker24Hour && D) {
|
|
971
|
-
const w = D.value;
|
|
972
|
-
w === "PM" && k < 12 && (k += 12), w === "AM" && k === 12 && (k = 0);
|
|
973
|
-
}
|
|
974
|
-
a.setHours(k);
|
|
1387
|
+
// Event handler implementations
|
|
1388
|
+
handleRangeClick(t) {
|
|
1389
|
+
const a = t.target.dataset.rangeKey;
|
|
1390
|
+
if (a)
|
|
1391
|
+
if (this.state.chosenLabel = a, this.updateActiveRange(a), a === this.locale.customRangeLabel)
|
|
1392
|
+
this.showCalendars();
|
|
1393
|
+
else {
|
|
1394
|
+
const i = this.options.ranges[a];
|
|
1395
|
+
if (i) {
|
|
1396
|
+
const [s, n] = i;
|
|
1397
|
+
this.state.startDate = new Date(s), this.state.endDate = new Date(n), this.showCalendars(), this.updateView(), this.options.autoApply && this.handleApplyClick();
|
|
975
1398
|
}
|
|
976
|
-
m && m.value && a.setMinutes(parseInt(m.value, 10)), u && u.value && a.setSeconds(parseInt(u.value, 10));
|
|
977
|
-
}
|
|
978
|
-
g(a, this.state.startDate) && (a = new Date(this.state.startDate)), o && b(a, o) && (a = new Date(o));
|
|
979
|
-
}
|
|
980
|
-
let r = '<select class="hourselect">';
|
|
981
|
-
const f = this.options.timePicker24Hour ? 0 : 1, h = this.options.timePicker24Hour ? 23 : 12;
|
|
982
|
-
for (let s = f; s <= h; s++) {
|
|
983
|
-
let l = s;
|
|
984
|
-
this.options.timePicker24Hour || (l = a.getHours() >= 12 ? s === 12 ? 12 : s + 12 : s === 12 ? 0 : s);
|
|
985
|
-
const m = new Date(a);
|
|
986
|
-
m.setHours(l), m.setMinutes(59);
|
|
987
|
-
let u = !1;
|
|
988
|
-
n && g(m, n) && (u = !0), m.setMinutes(0), o && b(m, o) && (u = !0), l === a.getHours() && !u ? r += `<option value="${s}" selected="selected">${s}</option>` : u ? r += `<option value="${s}" disabled="disabled" class="disabled">${s}</option>` : r += `<option value="${s}">${s}</option>`;
|
|
989
|
-
}
|
|
990
|
-
r += "</select> ", r += ': <select class="minuteselect">';
|
|
991
|
-
for (let s = 0; s < 60; s += this.options.timePickerIncrement) {
|
|
992
|
-
const l = s < 10 ? "0" + s : s.toString(), m = new Date(a);
|
|
993
|
-
m.setMinutes(s), m.setSeconds(59);
|
|
994
|
-
let u = !1;
|
|
995
|
-
n && g(m, n) && (u = !0), m.setSeconds(0), o && b(m, o) && (u = !0), a.getMinutes() === s && !u ? r += `<option value="${s}" selected="selected">${l}</option>` : u ? r += `<option value="${s}" disabled="disabled" class="disabled">${l}</option>` : r += `<option value="${s}">${l}</option>`;
|
|
996
|
-
}
|
|
997
|
-
if (r += "</select> ", this.options.timePickerSeconds) {
|
|
998
|
-
r += ': <select class="secondselect">';
|
|
999
|
-
for (let s = 0; s < 60; s++) {
|
|
1000
|
-
const l = s < 10 ? "0" + s : s.toString(), m = new Date(a);
|
|
1001
|
-
m.setSeconds(s);
|
|
1002
|
-
let u = !1;
|
|
1003
|
-
n && g(m, n) && (u = !0), o && b(m, o) && (u = !0), a.getSeconds() === s && !u ? r += `<option value="${s}" selected="selected">${l}</option>` : u ? r += `<option value="${s}" disabled="disabled" class="disabled">${l}</option>` : r += `<option value="${s}">${l}</option>`;
|
|
1004
1399
|
}
|
|
1005
|
-
r += "</select> ";
|
|
1006
|
-
}
|
|
1007
|
-
if (!this.options.timePicker24Hour) {
|
|
1008
|
-
r += '<select class="ampmselect">';
|
|
1009
|
-
const s = new Date(a);
|
|
1010
|
-
s.setHours(12, 0, 0);
|
|
1011
|
-
const l = new Date(a);
|
|
1012
|
-
l.setHours(0, 0, 0);
|
|
1013
|
-
let m = "", u = "";
|
|
1014
|
-
n && g(s, n) && (m = ' disabled="disabled" class="disabled"'), o && b(l, o) && (u = ' disabled="disabled" class="disabled"'), a.getHours() >= 12 ? r += `<option value="AM"${m}>AM</option><option value="PM" selected="selected"${u}>PM</option>` : r += `<option value="AM" selected="selected"${m}>AM</option><option value="PM"${u}>PM</option>`, r += "</select>";
|
|
1015
|
-
}
|
|
1016
|
-
const d = e.querySelector(".calendar-time");
|
|
1017
|
-
d.innerHTML = r, d.querySelectorAll("select").forEach((s) => {
|
|
1018
|
-
s.addEventListener("change", this.timeChanged.bind(this));
|
|
1019
|
-
});
|
|
1020
1400
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (!i) return;
|
|
1024
|
-
const a = i.classList.contains("left"), n = i, o = n.querySelector(".hourselect"), r = n.querySelector(
|
|
1025
|
-
".minuteselect"
|
|
1026
|
-
), f = n.querySelector(
|
|
1027
|
-
".secondselect"
|
|
1028
|
-
), h = n.querySelector(".ampmselect");
|
|
1029
|
-
let d = parseInt(o.value, 10), p = parseInt(r.value, 10);
|
|
1030
|
-
if (isNaN(p)) {
|
|
1031
|
-
const l = r.options[r.options.length - 1];
|
|
1032
|
-
p = parseInt(l.value, 10);
|
|
1033
|
-
}
|
|
1034
|
-
const s = this.options.timePickerSeconds && f ? parseInt(f.value, 10) : 0;
|
|
1035
|
-
if (!this.options.timePicker24Hour && h) {
|
|
1036
|
-
const l = h.value;
|
|
1037
|
-
l === "PM" && d < 12 && (d += 12), l === "AM" && d === 12 && (d = 0);
|
|
1038
|
-
}
|
|
1039
|
-
if (a) {
|
|
1040
|
-
const l = new Date(this.state.startDate);
|
|
1041
|
-
l.setHours(d, p, s), this.setStartDate(l), this.options.singleDatePicker ? this.state.endDate = new Date(l) : this.state.endDate && v(this.state.endDate, "YYYY-MM-DD") === v(l, "YYYY-MM-DD") && g(this.state.endDate, l) && this.setEndDate(new Date(l));
|
|
1042
|
-
} else if (this.state.endDate) {
|
|
1043
|
-
const l = new Date(this.state.endDate);
|
|
1044
|
-
l.setHours(d, p, s), this.setEndDate(l);
|
|
1045
|
-
}
|
|
1046
|
-
this.updateCalendars(), this.updateFormInputs(), this.renderTimePicker("left"), this.renderTimePicker("right");
|
|
1401
|
+
handleApplyClick() {
|
|
1402
|
+
this.hide(), this.eventService.dispatchEvent(this.element, "apply.daterangepicker");
|
|
1047
1403
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
const t = this.element;
|
|
1051
|
-
let e = v(this.state.startDate, this.locale.format);
|
|
1052
|
-
!this.options.singleDatePicker && this.state.endDate && (e += this.locale.separator + v(this.state.endDate, this.locale.format)), e !== t.value && (t.value = e, this.dispatchEvent("change"));
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
move() {
|
|
1056
|
-
if (!this.state.isShowing || !this.container) return;
|
|
1057
|
-
const t = this.element.getBoundingClientRect();
|
|
1058
|
-
let e, i = this.options.drops;
|
|
1059
|
-
this.container.style.top = "0", this.container.style.left = "0", this.container.style.right = "auto", this.container.style.position = "fixed";
|
|
1060
|
-
const a = this.container.offsetWidth, n = this.container.offsetHeight;
|
|
1061
|
-
switch (i) {
|
|
1062
|
-
case "auto":
|
|
1063
|
-
e = t.bottom + 5, e + n >= window.innerHeight && (e = t.top - n - 5, i = "up");
|
|
1064
|
-
break;
|
|
1065
|
-
case "up":
|
|
1066
|
-
e = t.top - n - 5;
|
|
1067
|
-
break;
|
|
1068
|
-
default:
|
|
1069
|
-
e = t.bottom + 5;
|
|
1070
|
-
break;
|
|
1071
|
-
}
|
|
1072
|
-
i === "up" ? this.container.classList.add("drop-up") : this.container.classList.remove("drop-up");
|
|
1073
|
-
let o;
|
|
1074
|
-
this.options.opens === "left" ? (o = t.right - a, o < 9 && (o = 9)) : this.options.opens === "center" ? (o = t.left + t.width / 2 - a / 2, o < 9 ? o = 9 : o + a > window.innerWidth - 9 && (o = window.innerWidth - a - 9)) : (o = t.left, o + a > window.innerWidth - 9 && (o = window.innerWidth - a - 9)), o < 9 && (o = 9), e < 9 && (e = 9), this.container.style.top = `${e}px`, this.container.style.left = `${o}px`, this.container.style.right = "auto", this.container.style.zIndex = "99999";
|
|
1075
|
-
}
|
|
1076
|
-
// Event handlers
|
|
1077
|
-
clickRange(t) {
|
|
1078
|
-
const e = t.target, i = e.dataset.rangeKey;
|
|
1079
|
-
if (!i) return;
|
|
1080
|
-
if (this.container.querySelectorAll(".ranges li").forEach((n) => n.classList.remove("active")), e.classList.add("active"), this.state.chosenLabel = i, i === this.locale.customRangeLabel)
|
|
1081
|
-
this.showCalendars();
|
|
1082
|
-
else {
|
|
1083
|
-
const n = this.options.ranges[i];
|
|
1084
|
-
if (n) {
|
|
1085
|
-
const [o, r] = n;
|
|
1086
|
-
this.state.startDate = new Date(o), this.state.endDate = new Date(r), !this.options.alwaysShowCalendars && Object.keys(this.options.ranges).length === 0 ? this.hideCalendars() : this.showCalendars(), this.updateView(), this.options.autoApply && this.clickApply(t);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1404
|
+
handleCancelClick() {
|
|
1405
|
+
this.state.startDate = new Date(this.state.oldStartDate), this.state.endDate = this.state.oldEndDate ? new Date(this.state.oldEndDate) : null, this.hide(), this.eventService.dispatchEvent(this.element, "cancel.daterangepicker");
|
|
1089
1406
|
}
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1407
|
+
handlePrevClick(t) {
|
|
1408
|
+
const a = t.target.closest(".drp-calendar");
|
|
1409
|
+
a && (a.classList.contains("left") ? (this.state.leftCalendar.month = h(
|
|
1093
1410
|
this.state.leftCalendar.month,
|
|
1094
1411
|
-1
|
|
1095
|
-
), this.options.linkedCalendars && (this.state.rightCalendar.month =
|
|
1412
|
+
), this.options.linkedCalendars && (this.state.rightCalendar.month = h(
|
|
1096
1413
|
this.state.rightCalendar.month,
|
|
1097
1414
|
-1
|
|
1098
|
-
))) : this.state.rightCalendar.month =
|
|
1415
|
+
))) : this.state.rightCalendar.month = h(
|
|
1099
1416
|
this.state.rightCalendar.month,
|
|
1100
1417
|
-1
|
|
1101
1418
|
), this.updateCalendars());
|
|
1102
1419
|
}
|
|
1103
|
-
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1420
|
+
handleNextClick(t) {
|
|
1421
|
+
const a = t.target.closest(".drp-calendar");
|
|
1422
|
+
a && (a.classList.contains("left") ? this.state.leftCalendar.month = h(
|
|
1106
1423
|
this.state.leftCalendar.month,
|
|
1107
1424
|
1
|
|
1108
|
-
) : (this.state.rightCalendar.month =
|
|
1425
|
+
) : (this.state.rightCalendar.month = h(
|
|
1109
1426
|
this.state.rightCalendar.month,
|
|
1110
1427
|
1
|
|
1111
|
-
), this.options.linkedCalendars && (this.state.leftCalendar.month =
|
|
1428
|
+
), this.options.linkedCalendars && (this.state.leftCalendar.month = h(
|
|
1112
1429
|
this.state.leftCalendar.month,
|
|
1113
1430
|
1
|
|
1114
1431
|
))), this.updateCalendars());
|
|
1115
1432
|
}
|
|
1116
|
-
|
|
1433
|
+
handleDateClick(t) {
|
|
1434
|
+
var n, o;
|
|
1117
1435
|
const e = t.target;
|
|
1118
1436
|
if (!e.classList.contains("available")) return;
|
|
1119
|
-
const
|
|
1120
|
-
if (!
|
|
1121
|
-
const
|
|
1122
|
-
if (
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1437
|
+
const a = e.dataset.date;
|
|
1438
|
+
if (!a) return;
|
|
1439
|
+
const i = m(a, "YYYY-MM-DD");
|
|
1440
|
+
if (!f(i)) return;
|
|
1441
|
+
const s = this.validationService.validateDate(i);
|
|
1442
|
+
if (!s.isValid) {
|
|
1443
|
+
this.showValidationError(s.error, s.errorCode);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
if (!((n = this.options.events) != null && n.beforeDateSelect && !this.options.events.beforeDateSelect(i))) {
|
|
1447
|
+
if (this.applyTimeToDate(i, e), this.state.hoverDate = null, this.state.endDate || p(i, this.state.startDate))
|
|
1448
|
+
this.state.endDate = null, this.setStartDate(i);
|
|
1449
|
+
else {
|
|
1450
|
+
if (this.setEndDate(i), this.state.startDate && this.state.endDate) {
|
|
1451
|
+
const l = this.validationService.validateDateRange(
|
|
1452
|
+
this.state.startDate,
|
|
1453
|
+
this.state.endDate
|
|
1134
1454
|
);
|
|
1135
|
-
if (
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
a.setHours(d);
|
|
1455
|
+
if (!l.isValid) {
|
|
1456
|
+
this.showValidationError(
|
|
1457
|
+
l.error,
|
|
1458
|
+
l.errorCode
|
|
1459
|
+
), this.state.endDate = null, this.updateDateClasses();
|
|
1460
|
+
return;
|
|
1142
1461
|
}
|
|
1143
|
-
if (r) {
|
|
1144
|
-
let d = parseInt(r.value, 10);
|
|
1145
|
-
if (isNaN(d)) {
|
|
1146
|
-
const p = r.options[r.options.length - 1];
|
|
1147
|
-
d = parseInt(p.value, 10);
|
|
1148
|
-
}
|
|
1149
|
-
a.setMinutes(d);
|
|
1150
|
-
}
|
|
1151
|
-
this.options.timePickerSeconds && f && a.setSeconds(parseInt(f.value, 10));
|
|
1152
1462
|
}
|
|
1463
|
+
this.options.autoApply && (this.calculateChosenLabel(), this.handleApplyClick());
|
|
1153
1464
|
}
|
|
1154
|
-
this.
|
|
1465
|
+
this.options.singleDatePicker && (this.setEndDate(this.state.startDate), this.options.autoApply && this.handleApplyClick()), (o = this.options.events) != null && o.onDateSelect && this.options.events.onDateSelect(i), this.updateDateClasses();
|
|
1155
1466
|
}
|
|
1156
1467
|
}
|
|
1157
|
-
|
|
1468
|
+
handleDateHover(t) {
|
|
1158
1469
|
const e = t.target;
|
|
1159
1470
|
if (!e.classList.contains("available")) return;
|
|
1160
|
-
const
|
|
1161
|
-
if (!
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1471
|
+
const a = e.dataset.date;
|
|
1472
|
+
if (!a) return;
|
|
1473
|
+
const i = m(a, "YYYY-MM-DD");
|
|
1474
|
+
f(i) && !this.state.endDate && !p(i, this.state.startDate) && (this.state.hoverDate = i, this.updateDateClasses());
|
|
1164
1475
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
}
|
|
1177
|
-
});
|
|
1476
|
+
handleMonthYearChange(t) {
|
|
1477
|
+
const a = t.target.closest(".drp-calendar");
|
|
1478
|
+
if (!a) return;
|
|
1479
|
+
const i = a.classList.contains("left"), s = a.querySelector(
|
|
1480
|
+
".monthselect"
|
|
1481
|
+
), n = a.querySelector(
|
|
1482
|
+
".yearselect"
|
|
1483
|
+
);
|
|
1484
|
+
if (!s || !n) return;
|
|
1485
|
+
const o = parseInt(s.value, 10), l = parseInt(n.value, 10), c = new Date(l, o, 1);
|
|
1486
|
+
i ? (this.state.leftCalendar.month = c, this.options.linkedCalendars && (this.state.rightCalendar.month = h(c, 1))) : (this.state.rightCalendar.month = c, this.options.linkedCalendars && (this.state.leftCalendar.month = h(c, -1))), this.updateCalendars();
|
|
1178
1487
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1488
|
+
// View update methods
|
|
1489
|
+
updateView() {
|
|
1490
|
+
this.updateMonthsInView(), this.updateCalendars(), this.updateFormInputs(), this.updateSelectedDisplay(), this.calculateChosenLabel();
|
|
1491
|
+
}
|
|
1492
|
+
updateMonthsInView() {
|
|
1493
|
+
this.state.endDate ? (this.state.leftCalendar.month = b(this.state.startDate), !this.options.linkedCalendars && (this.state.endDate.getMonth() !== this.state.startDate.getMonth() || this.state.endDate.getFullYear() !== this.state.startDate.getFullYear()) ? this.state.rightCalendar.month = b(this.state.endDate) : this.state.rightCalendar.month = h(
|
|
1494
|
+
this.state.leftCalendar.month,
|
|
1495
|
+
1
|
|
1496
|
+
)) : (this.state.leftCalendar.month = b(this.state.startDate), this.state.rightCalendar.month = h(
|
|
1497
|
+
this.state.leftCalendar.month,
|
|
1498
|
+
1
|
|
1499
|
+
));
|
|
1181
1500
|
}
|
|
1182
|
-
|
|
1183
|
-
this.
|
|
1501
|
+
updateCalendars() {
|
|
1502
|
+
this.renderCalendar("left"), this.options.singleDatePicker || this.renderCalendar("right");
|
|
1184
1503
|
}
|
|
1185
|
-
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
return;
|
|
1189
|
-
const a = i.classList.contains("left"), n = i.querySelector(
|
|
1190
|
-
".monthselect"
|
|
1191
|
-
), o = i.querySelector(
|
|
1192
|
-
".yearselect"
|
|
1504
|
+
renderCalendar(t) {
|
|
1505
|
+
const e = t === "left" ? this.state.leftCalendar : this.state.rightCalendar, a = this.container.querySelector(
|
|
1506
|
+
`.drp-calendar.${t} .calendar-table`
|
|
1193
1507
|
);
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1508
|
+
e.calendar = this.calendarService.buildCalendarMatrix(
|
|
1509
|
+
e.month
|
|
1510
|
+
);
|
|
1511
|
+
const i = this.calendarService.canNavigatePrevious(e.month), s = this.calendarService.canNavigateNext(e.month), n = this.calendarService.renderCalendarHTML(
|
|
1512
|
+
e,
|
|
1513
|
+
t,
|
|
1514
|
+
this.state.startDate,
|
|
1515
|
+
this.state.endDate,
|
|
1516
|
+
i,
|
|
1517
|
+
s
|
|
1518
|
+
);
|
|
1519
|
+
a.innerHTML = n;
|
|
1198
1520
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
let i = null, a = null;
|
|
1205
|
-
e.length === 2 ? (i = C(e[0].trim(), this.locale.format), a = C(e[1].trim(), this.locale.format)) : (this.options.singleDatePicker || e.length === 1) && (i = C(e[0].trim(), this.locale.format), a = i), i && S(i) && a && S(a) && (this.setStartDate(i), this.setEndDate(a), this.updateView());
|
|
1521
|
+
updateFormInputs() {
|
|
1522
|
+
const t = this.container.querySelector(
|
|
1523
|
+
".applyBtn"
|
|
1524
|
+
), e = this.options.singleDatePicker || this.state.endDate && (p(this.state.startDate, this.state.endDate) || d(this.state.startDate, this.state.endDate, "day"));
|
|
1525
|
+
t.disabled = !e;
|
|
1206
1526
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1527
|
+
updateSelectedDisplay() {
|
|
1528
|
+
const t = this.container.querySelector(".drp-selected");
|
|
1529
|
+
let e = g(this.state.startDate, this.locale.format);
|
|
1530
|
+
!this.options.singleDatePicker && this.state.endDate && (e += this.locale.separator + g(this.state.endDate, this.locale.format)), t.textContent = e;
|
|
1209
1531
|
}
|
|
1210
|
-
|
|
1211
|
-
this.
|
|
1532
|
+
updateElement() {
|
|
1533
|
+
if (this.element.tagName === "INPUT" && this.options.autoUpdateInput) {
|
|
1534
|
+
const t = this.element;
|
|
1535
|
+
let e = g(this.state.startDate, this.locale.format);
|
|
1536
|
+
!this.options.singleDatePicker && this.state.endDate && (e += this.locale.separator + g(this.state.endDate, this.locale.format)), e !== t.value && (t.value = e, this.eventService.dispatchEvent(this.element, "change"));
|
|
1537
|
+
}
|
|
1212
1538
|
}
|
|
1213
|
-
|
|
1214
|
-
this.container.
|
|
1539
|
+
renderRanges() {
|
|
1540
|
+
const t = this.container.querySelector(".ranges");
|
|
1541
|
+
t.innerHTML = this.createRangeService().renderRanges();
|
|
1215
1542
|
}
|
|
1216
1543
|
calculateChosenLabel() {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
this.
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
let f = !1;
|
|
1223
|
-
if (this.state.endDate ? f = x(this.state.endDate, o, "day") : f = x(this.state.startDate, o, "day"), r && f) {
|
|
1224
|
-
const h = Math.abs(o.getTime() - n.getTime()) / 864e5 + 1;
|
|
1225
|
-
(!e || h > e.days) && (e = { label: a, days: h });
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
if (this.container.querySelectorAll(".ranges li").forEach((a) => a.classList.remove("active")), e) {
|
|
1229
|
-
t = !1, this.state.chosenLabel = e.label;
|
|
1230
|
-
const a = this.container.querySelector(
|
|
1231
|
-
`[data-range-key="${e.label}"]`
|
|
1232
|
-
);
|
|
1233
|
-
a && a.classList.add("active");
|
|
1234
|
-
}
|
|
1235
|
-
if (t)
|
|
1236
|
-
if (this.options.showCustomRangeLabel) {
|
|
1237
|
-
this.state.chosenLabel = this.locale.customRangeLabel;
|
|
1238
|
-
const a = this.container.querySelector(
|
|
1239
|
-
`[data-range-key="${this.locale.customRangeLabel}"]`
|
|
1240
|
-
);
|
|
1241
|
-
a && a.classList.add("active");
|
|
1242
|
-
} else
|
|
1243
|
-
this.state.chosenLabel = null;
|
|
1244
|
-
Object.keys(this.options.ranges).length > 0 && this.showCalendars();
|
|
1245
|
-
}
|
|
1246
|
-
// Public API
|
|
1247
|
-
setStartDate(t) {
|
|
1248
|
-
if (!this.options.timePicker)
|
|
1249
|
-
this.state.startDate = M(t);
|
|
1250
|
-
else if (this.state.startDate = new Date(t), this.options.timePickerIncrement) {
|
|
1251
|
-
const e = Math.round(
|
|
1252
|
-
this.state.startDate.getMinutes() / this.options.timePickerIncrement
|
|
1253
|
-
) * this.options.timePickerIncrement;
|
|
1254
|
-
this.state.startDate.setMinutes(e);
|
|
1255
|
-
}
|
|
1256
|
-
this.updateView();
|
|
1544
|
+
const t = this.createRangeService();
|
|
1545
|
+
this.state.chosenLabel = t.calculateChosenLabel(
|
|
1546
|
+
this.state.startDate,
|
|
1547
|
+
this.state.endDate
|
|
1548
|
+
), t.updateActiveRange(this.container, this.state.chosenLabel), Object.keys(this.options.ranges).length > 0 && this.showCalendars();
|
|
1257
1549
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
this.state.endDate = E(t);
|
|
1261
|
-
else if (this.state.endDate = new Date(t), this.options.timePickerIncrement) {
|
|
1262
|
-
const e = Math.round(
|
|
1263
|
-
this.state.endDate.getMinutes() / this.options.timePickerIncrement
|
|
1264
|
-
) * this.options.timePickerIncrement;
|
|
1265
|
-
this.state.endDate.setMinutes(e);
|
|
1266
|
-
}
|
|
1267
|
-
this.updateView();
|
|
1550
|
+
updateActiveRange(t) {
|
|
1551
|
+
this.createRangeService().updateActiveRange(this.container, t);
|
|
1268
1552
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1553
|
+
showCalendars() {
|
|
1554
|
+
this.container.classList.add("show-calendar"), this.positionContainer(), this.eventService.dispatchEvent(
|
|
1555
|
+
this.element,
|
|
1556
|
+
"showCalendar.daterangepicker"
|
|
1557
|
+
);
|
|
1271
1558
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1559
|
+
updateDateClasses() {
|
|
1560
|
+
this.container.querySelectorAll("td[data-date]").forEach((e) => {
|
|
1561
|
+
const a = e.dataset.date;
|
|
1562
|
+
if (!a) return;
|
|
1563
|
+
const i = m(a, "YYYY-MM-DD");
|
|
1564
|
+
if (!f(i)) return;
|
|
1565
|
+
e.classList.remove("in-range", "end-date", "start-date", "active");
|
|
1566
|
+
const s = this.state.startDate, n = this.state.endDate, o = this.state.hoverDate;
|
|
1567
|
+
if (s && d(i, s, "day") && e.classList.add("active", "start-date"), n && d(i, n, "day") && e.classList.add("active", "end-date"), s && n && D(i, s) && p(i, n) && e.classList.add("in-range"), s && o && !n) {
|
|
1568
|
+
const l = p(o, s) ? o : s, c = p(o, s) ? s : o;
|
|
1569
|
+
d(i, o, "day") ? e.classList.add("end-date") : D(i, l) && p(i, c) && e.classList.add("in-range");
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1274
1572
|
}
|
|
1275
|
-
|
|
1276
|
-
if (this.
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
const r = $(a, this.options.maxSpan.days || 0);
|
|
1294
|
-
b(r, o) && (o = r);
|
|
1295
|
-
}
|
|
1296
|
-
o && b(n, o) && (n = new Date(o)), !(this.options.minDate && g(n, this.options.minDate) || o && b(a, o)) && (this.options.ranges[e] = [a, n]);
|
|
1573
|
+
applyTimeToDate(t, e) {
|
|
1574
|
+
if (!this.options.timePicker) return;
|
|
1575
|
+
const a = e.closest(".drp-calendar");
|
|
1576
|
+
if (!a) return;
|
|
1577
|
+
const i = a.querySelector(
|
|
1578
|
+
".hourselect"
|
|
1579
|
+
), s = a.querySelector(
|
|
1580
|
+
".minuteselect"
|
|
1581
|
+
), n = a.querySelector(
|
|
1582
|
+
".secondselect"
|
|
1583
|
+
), o = a.querySelector(
|
|
1584
|
+
".ampmselect"
|
|
1585
|
+
);
|
|
1586
|
+
if (i) {
|
|
1587
|
+
let l = parseInt(i.value, 10);
|
|
1588
|
+
if (!this.options.timePicker24Hour && o) {
|
|
1589
|
+
const c = o.value;
|
|
1590
|
+
c === "PM" && l < 12 && (l += 12), c === "AM" && l === 12 && (l = 0);
|
|
1297
1591
|
}
|
|
1298
|
-
|
|
1592
|
+
t.setHours(l);
|
|
1299
1593
|
}
|
|
1594
|
+
if (s) {
|
|
1595
|
+
const l = parseInt(s.value, 10) || 0;
|
|
1596
|
+
t.setMinutes(l);
|
|
1597
|
+
}
|
|
1598
|
+
this.options.timePickerSeconds && n && t.setSeconds(parseInt(n.value, 10));
|
|
1300
1599
|
}
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1600
|
+
createRangeService() {
|
|
1601
|
+
return {
|
|
1602
|
+
renderRanges: () => {
|
|
1603
|
+
let t = "<ul>";
|
|
1604
|
+
for (const [e] of Object.entries(this.options.ranges))
|
|
1605
|
+
t += `<li data-range-key="${e}">${e}</li>`;
|
|
1606
|
+
return this.options.showCustomRangeLabel && (t += `<li data-range-key="${this.locale.customRangeLabel}">${this.locale.customRangeLabel}</li>`), t += "</ul>", t;
|
|
1607
|
+
},
|
|
1608
|
+
calculateChosenLabel: (t, e) => {
|
|
1609
|
+
let a = null;
|
|
1610
|
+
for (const [i, [s, n]] of Object.entries(
|
|
1611
|
+
this.options.ranges
|
|
1612
|
+
)) {
|
|
1613
|
+
const o = d(t, s, "day");
|
|
1614
|
+
let l = !1;
|
|
1615
|
+
if (e ? l = d(e, n, "day") : l = d(t, n, "day"), o && l) {
|
|
1616
|
+
const c = Math.abs(n.getTime() - s.getTime()) / 864e5 + 1;
|
|
1617
|
+
(!a || c > a.days) && (a = { label: i, days: c });
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
return a ? a.label : this.options.showCustomRangeLabel ? this.locale.customRangeLabel : null;
|
|
1621
|
+
},
|
|
1622
|
+
updateActiveRange: (t, e) => {
|
|
1623
|
+
if (t.querySelectorAll(".ranges li").forEach((i) => i.classList.remove("active")), e) {
|
|
1624
|
+
const i = t.querySelector(
|
|
1625
|
+
`[data-range-key="${e}"]`
|
|
1626
|
+
);
|
|
1627
|
+
i == null || i.classList.add("active");
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1307
1631
|
}
|
|
1308
1632
|
}
|
|
1309
1633
|
export {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1634
|
+
A as BOOTSTRAP_THEME,
|
|
1635
|
+
C as DEFAULT_THEME,
|
|
1636
|
+
P as Datex,
|
|
1637
|
+
H as MATERIAL_THEME,
|
|
1638
|
+
F as SPANISH_LOCALE,
|
|
1639
|
+
I as SPANISH_LOCALE_WITH_TIME,
|
|
1640
|
+
h as addMonths,
|
|
1641
|
+
y as endOfDay,
|
|
1642
|
+
g as formatDate,
|
|
1643
|
+
b as getStartOfMonth,
|
|
1644
|
+
D as isAfterDate,
|
|
1645
|
+
p as isBeforeDate,
|
|
1646
|
+
d as isSameDate,
|
|
1647
|
+
f as isValidDate,
|
|
1648
|
+
m as parseDate,
|
|
1649
|
+
v as startOfDay
|
|
1316
1650
|
};
|