calkit 0.1.0 → 0.2.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.
- package/README.md +1 -1
- package/dist/booking.es.js +421 -318
- package/dist/booking.es.js.map +1 -1
- package/dist/booking.umd.js +12 -12
- package/dist/booking.umd.js.map +1 -1
- package/dist/calkit.d.ts +453 -0
- package/dist/calkit.es.js +1101 -898
- package/dist/calkit.es.js.map +1 -1
- package/dist/calkit.umd.js +34 -34
- package/dist/calkit.umd.js.map +1 -1
- package/dist/datepicker.es.js +333 -241
- package/dist/datepicker.es.js.map +1 -1
- package/dist/datepicker.umd.js +12 -12
- package/dist/datepicker.umd.js.map +1 -1
- package/dist/scheduler.es.js +705 -638
- package/dist/scheduler.es.js.map +1 -1
- package/dist/scheduler.umd.js +20 -20
- package/dist/scheduler.umd.js.map +1 -1
- package/dist/timepicker.es.js +146 -116
- package/dist/timepicker.es.js.map +1 -1
- package/dist/timepicker.umd.js +6 -6
- package/dist/timepicker.umd.js.map +1 -1
- package/llms.txt +1 -1
- package/package.json +4 -2
package/dist/datepicker.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ie extends HTMLElement {
|
|
2
2
|
constructor() {
|
|
3
3
|
super(), this.attachShadow({ mode: "open" }), this._initialized = !1;
|
|
4
4
|
}
|
|
@@ -27,6 +27,9 @@ class ne extends HTMLElement {
|
|
|
27
27
|
/** Subclasses override to update Shadow DOM. */
|
|
28
28
|
render() {
|
|
29
29
|
}
|
|
30
|
+
/** Reset selection state. Subclasses should override with specific logic. */
|
|
31
|
+
clear() {
|
|
32
|
+
}
|
|
30
33
|
/** Dispatch a composed, bubbling custom event. */
|
|
31
34
|
emit(e, a = {}) {
|
|
32
35
|
this.dispatchEvent(
|
|
@@ -51,7 +54,7 @@ class ne extends HTMLElement {
|
|
|
51
54
|
return this.shadowRoot.querySelectorAll(e);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
function
|
|
57
|
+
function ce(s) {
|
|
55
58
|
let e = { ...s };
|
|
56
59
|
const a = /* @__PURE__ */ new Set();
|
|
57
60
|
return {
|
|
@@ -78,7 +81,7 @@ function se(s) {
|
|
|
78
81
|
}
|
|
79
82
|
};
|
|
80
83
|
}
|
|
81
|
-
const
|
|
84
|
+
const X = [
|
|
82
85
|
"January",
|
|
83
86
|
"February",
|
|
84
87
|
"March",
|
|
@@ -91,25 +94,86 @@ const I = [
|
|
|
91
94
|
"October",
|
|
92
95
|
"November",
|
|
93
96
|
"December"
|
|
94
|
-
],
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
e.
|
|
99
|
-
|
|
97
|
+
], de = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
98
|
+
function ge(s) {
|
|
99
|
+
if (!s) return X;
|
|
100
|
+
try {
|
|
101
|
+
const e = new Intl.DateTimeFormat(s, { month: "long" });
|
|
102
|
+
return Array.from({ length: 12 }, (a, t) => {
|
|
103
|
+
const n = e.format(new Date(2024, t, 1));
|
|
104
|
+
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
105
|
+
});
|
|
106
|
+
} catch {
|
|
107
|
+
return X;
|
|
108
|
+
}
|
|
100
109
|
}
|
|
101
|
-
function
|
|
110
|
+
function te(s) {
|
|
111
|
+
if (!s)
|
|
112
|
+
return [
|
|
113
|
+
"Jan",
|
|
114
|
+
"Feb",
|
|
115
|
+
"Mar",
|
|
116
|
+
"Apr",
|
|
117
|
+
"May",
|
|
118
|
+
"Jun",
|
|
119
|
+
"Jul",
|
|
120
|
+
"Aug",
|
|
121
|
+
"Sep",
|
|
122
|
+
"Oct",
|
|
123
|
+
"Nov",
|
|
124
|
+
"Dec"
|
|
125
|
+
];
|
|
126
|
+
try {
|
|
127
|
+
const e = new Intl.DateTimeFormat(s, { month: "short" });
|
|
128
|
+
return Array.from({ length: 12 }, (a, t) => {
|
|
129
|
+
const n = e.format(new Date(2024, t, 1));
|
|
130
|
+
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
131
|
+
});
|
|
132
|
+
} catch {
|
|
133
|
+
return [
|
|
134
|
+
"Jan",
|
|
135
|
+
"Feb",
|
|
136
|
+
"Mar",
|
|
137
|
+
"Apr",
|
|
138
|
+
"May",
|
|
139
|
+
"Jun",
|
|
140
|
+
"Jul",
|
|
141
|
+
"Aug",
|
|
142
|
+
"Sep",
|
|
143
|
+
"Oct",
|
|
144
|
+
"Nov",
|
|
145
|
+
"Dec"
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function ue(s = 0, e) {
|
|
150
|
+
if (e)
|
|
151
|
+
try {
|
|
152
|
+
const t = new Intl.DateTimeFormat(e, { weekday: "short" }), n = [];
|
|
153
|
+
for (let r = 0; r < 7; r++) {
|
|
154
|
+
const o = new Date(2024, 0, 7 + (s + r) % 7), l = t.format(o);
|
|
155
|
+
n.push(l.charAt(0).toUpperCase() + l.slice(1));
|
|
156
|
+
}
|
|
157
|
+
return n;
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
const a = [];
|
|
161
|
+
for (let t = 0; t < 7; t++)
|
|
162
|
+
a.push(de[(s + t) % 7]);
|
|
163
|
+
return a;
|
|
164
|
+
}
|
|
165
|
+
function q(s, e) {
|
|
102
166
|
return new Date(s, e + 1, 0).getDate();
|
|
103
167
|
}
|
|
104
|
-
function
|
|
168
|
+
function he(s, e) {
|
|
105
169
|
return new Date(s, e, 1).getDay();
|
|
106
170
|
}
|
|
107
|
-
function
|
|
171
|
+
function k(s) {
|
|
108
172
|
if (typeof s == "string") return s;
|
|
109
173
|
const e = s instanceof Date ? s : new Date(s.year, s.month, s.day), a = e.getFullYear(), t = String(e.getMonth() + 1).padStart(2, "0"), n = String(e.getDate()).padStart(2, "0");
|
|
110
174
|
return `${a}-${t}-${n}`;
|
|
111
175
|
}
|
|
112
|
-
function
|
|
176
|
+
function S(s) {
|
|
113
177
|
if (!s) return null;
|
|
114
178
|
if (s instanceof Date) return s;
|
|
115
179
|
if (typeof s == "string") {
|
|
@@ -118,44 +182,44 @@ function L(s) {
|
|
|
118
182
|
}
|
|
119
183
|
return null;
|
|
120
184
|
}
|
|
121
|
-
function
|
|
185
|
+
function C(s, e) {
|
|
122
186
|
if (!s || !e) return !1;
|
|
123
|
-
const a =
|
|
187
|
+
const a = S(s), t = S(e);
|
|
124
188
|
return !a || !t ? !1 : a.getFullYear() === t.getFullYear() && a.getMonth() === t.getMonth() && a.getDate() === t.getDate();
|
|
125
189
|
}
|
|
126
|
-
function
|
|
190
|
+
function pe(s, e, a) {
|
|
127
191
|
if (!s || !e || !a) return !1;
|
|
128
|
-
const t =
|
|
192
|
+
const t = S(s), n = S(e), r = S(a);
|
|
129
193
|
if (!t || !n || !r) return !1;
|
|
130
194
|
const o = t.getTime(), l = Math.min(n.getTime(), r.getTime()), i = Math.max(n.getTime(), r.getTime());
|
|
131
195
|
return o >= l && o <= i;
|
|
132
196
|
}
|
|
133
|
-
function
|
|
134
|
-
return
|
|
197
|
+
function G() {
|
|
198
|
+
return k(/* @__PURE__ */ new Date());
|
|
135
199
|
}
|
|
136
200
|
function z(s, e, a) {
|
|
137
201
|
const t = new Date(s, e + a, 1);
|
|
138
202
|
return { year: t.getFullYear(), month: t.getMonth() };
|
|
139
203
|
}
|
|
140
|
-
function
|
|
141
|
-
const t =
|
|
142
|
-
for (let
|
|
143
|
-
const
|
|
144
|
-
o.push({ year: i.year, month: i.month, day:
|
|
145
|
-
}
|
|
146
|
-
for (let
|
|
147
|
-
const
|
|
148
|
-
o.push({ year: s, month: e, day:
|
|
149
|
-
}
|
|
150
|
-
const
|
|
151
|
-
let
|
|
204
|
+
function be(s, e, a = 0) {
|
|
205
|
+
const t = q(s, e), r = (he(s, e) - a + 7) % 7, o = [], l = G(), i = z(s, e, -1), h = q(i.year, i.month);
|
|
206
|
+
for (let u = r - 1; u >= 0; u--) {
|
|
207
|
+
const p = h - u, b = k({ year: i.year, month: i.month, day: p });
|
|
208
|
+
o.push({ year: i.year, month: i.month, day: p, dateString: b, isCurrentMonth: !1, isToday: b === l });
|
|
209
|
+
}
|
|
210
|
+
for (let u = 1; u <= t; u++) {
|
|
211
|
+
const p = k({ year: s, month: e, day: u });
|
|
212
|
+
o.push({ year: s, month: e, day: u, dateString: p, isCurrentMonth: !0, isToday: p === l });
|
|
213
|
+
}
|
|
214
|
+
const d = z(s, e, 1);
|
|
215
|
+
let g = 1;
|
|
152
216
|
for (; o.length < 42; ) {
|
|
153
|
-
const
|
|
154
|
-
o.push({ year:
|
|
217
|
+
const u = k({ year: d.year, month: d.month, day: g });
|
|
218
|
+
o.push({ year: d.year, month: d.month, day: g, dateString: u, isCurrentMonth: !1, isToday: u === l }), g++;
|
|
155
219
|
}
|
|
156
220
|
return o;
|
|
157
221
|
}
|
|
158
|
-
const
|
|
222
|
+
const fe = `
|
|
159
223
|
:host {
|
|
160
224
|
/* Light theme (default) */
|
|
161
225
|
--cal-bg: 0 0% 100%;
|
|
@@ -323,7 +387,7 @@ const de = `
|
|
|
323
387
|
--cal-status-success-border: 152 40% 28%;
|
|
324
388
|
}
|
|
325
389
|
}
|
|
326
|
-
`,
|
|
390
|
+
`, ve = `
|
|
327
391
|
:host {
|
|
328
392
|
display: inline-block;
|
|
329
393
|
font-family: inherit;
|
|
@@ -364,7 +428,7 @@ const de = `
|
|
|
364
428
|
[hidden] {
|
|
365
429
|
display: none !important;
|
|
366
430
|
}
|
|
367
|
-
`,
|
|
431
|
+
`, me = `
|
|
368
432
|
@keyframes cal-fade-in {
|
|
369
433
|
from { opacity: 0; }
|
|
370
434
|
to { opacity: 1; }
|
|
@@ -428,30 +492,30 @@ const de = `
|
|
|
428
492
|
.cal-skeleton--rect {
|
|
429
493
|
border-radius: var(--cal-radius-sm);
|
|
430
494
|
}
|
|
431
|
-
`,
|
|
495
|
+
`, Q = {
|
|
432
496
|
blue: { bg: "var(--cal-booking-blue-bg)", fg: "var(--cal-booking-blue-fg)", hover: "var(--cal-booking-blue-hover)" },
|
|
433
497
|
green: { bg: "var(--cal-booking-green-bg)", fg: "var(--cal-booking-green-fg)", hover: "var(--cal-booking-green-hover)" },
|
|
434
498
|
red: { bg: "var(--cal-booking-red-bg)", fg: "var(--cal-booking-red-fg)", hover: "var(--cal-booking-red-hover)" },
|
|
435
499
|
orange: { bg: "var(--cal-booking-orange-bg)", fg: "var(--cal-booking-orange-fg)", hover: "var(--cal-booking-orange-hover)" },
|
|
436
500
|
gray: { bg: "var(--cal-booking-gray-bg)", fg: "var(--cal-booking-gray-fg)", hover: "var(--cal-booking-gray-hover)" }
|
|
437
501
|
}, T = "blue";
|
|
438
|
-
function B(s) {
|
|
439
|
-
return
|
|
502
|
+
function B(s, e) {
|
|
503
|
+
return e && e[s] ? e[s] : Q[s] || Q[T];
|
|
440
504
|
}
|
|
441
|
-
function
|
|
442
|
-
const
|
|
443
|
-
(
|
|
505
|
+
function ye(s, e = [], a = {}, t = null, n = null) {
|
|
506
|
+
const r = e.find((f) => f.end === s), o = e.find((f) => f.start === s), l = e.find(
|
|
507
|
+
(f) => f.start < s && f.end > s
|
|
444
508
|
);
|
|
445
|
-
let
|
|
446
|
-
|
|
509
|
+
let i = "available", h = null, d = !1, g = null, u = null, p = null;
|
|
510
|
+
r && o ? (i = "half-day", d = !0, g = B(r.color || T, n), u = B(o.color || T, n)) : l ? (i = "booked", p = B(l.color || T, n)) : o && !r ? (i = "checkin-only", u = B(o.color || T, n)) : r && !o && (i = "checkout-only", g = B(r.color || T, n));
|
|
447
511
|
const b = a[s];
|
|
448
|
-
if (b && (b.status && (
|
|
449
|
-
const
|
|
450
|
-
|
|
512
|
+
if (b && (b.status && (i = b.status), b.label !== void 0 && (h = b.label)), t) {
|
|
513
|
+
const f = t(s);
|
|
514
|
+
f && (f.status && (i = f.status), f.label !== void 0 && (h = f.label));
|
|
451
515
|
}
|
|
452
|
-
return { status:
|
|
516
|
+
return { status: i, label: h, checkoutBooking: r, checkinBooking: o, halfDay: d, colorOut: g, colorIn: u, colorFull: p };
|
|
453
517
|
}
|
|
454
|
-
function
|
|
518
|
+
function ke(s, e, a = []) {
|
|
455
519
|
if (!s || !e) return !0;
|
|
456
520
|
const t = s < e ? s : e, n = s < e ? e : s;
|
|
457
521
|
for (const r of a)
|
|
@@ -459,10 +523,10 @@ function pe(s, e, a = []) {
|
|
|
459
523
|
return !1;
|
|
460
524
|
return !0;
|
|
461
525
|
}
|
|
462
|
-
function
|
|
463
|
-
return !s || !e ? !1 : !
|
|
526
|
+
function _e(s, e, a = []) {
|
|
527
|
+
return !s || !e ? !1 : !ke(s, e, a);
|
|
464
528
|
}
|
|
465
|
-
function
|
|
529
|
+
function we(s) {
|
|
466
530
|
const {
|
|
467
531
|
year: e,
|
|
468
532
|
month: a,
|
|
@@ -472,80 +536,82 @@ function fe(s) {
|
|
|
472
536
|
rangeEnd: o,
|
|
473
537
|
hoverDate: l,
|
|
474
538
|
minDate: i,
|
|
475
|
-
maxDate:
|
|
476
|
-
disabledDates:
|
|
477
|
-
mode:
|
|
478
|
-
focusedDate:
|
|
479
|
-
onSelect:
|
|
480
|
-
onHover:
|
|
539
|
+
maxDate: h,
|
|
540
|
+
disabledDates: d = [],
|
|
541
|
+
mode: g = "single",
|
|
542
|
+
focusedDate: u,
|
|
543
|
+
onSelect: p,
|
|
544
|
+
onHover: b,
|
|
481
545
|
// Booking-specific params
|
|
482
|
-
bookings:
|
|
483
|
-
dayData:
|
|
484
|
-
labelFormula:
|
|
485
|
-
showLabelsOnHover:
|
|
486
|
-
|
|
546
|
+
bookings: f = null,
|
|
547
|
+
dayData: j = null,
|
|
548
|
+
labelFormula: K = null,
|
|
549
|
+
showLabelsOnHover: _ = !1,
|
|
550
|
+
locale: D,
|
|
551
|
+
customColors: se = null
|
|
552
|
+
} = s, E = f !== null, A = document.createElement("div");
|
|
487
553
|
A.setAttribute("role", "grid"), A.classList.add("cal-grid");
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
for (const
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
A.appendChild(
|
|
495
|
-
const
|
|
554
|
+
const P = document.createElement("div");
|
|
555
|
+
P.setAttribute("role", "row"), P.classList.add("cal-weekdays");
|
|
556
|
+
for (const w of ue(t, D)) {
|
|
557
|
+
const M = document.createElement("div");
|
|
558
|
+
M.setAttribute("role", "columnheader"), M.setAttribute("aria-label", w), M.classList.add("cal-weekday"), M.textContent = w, P.appendChild(M);
|
|
559
|
+
}
|
|
560
|
+
A.appendChild(P);
|
|
561
|
+
const re = be(e, a, t), J = g === "range" && r && !o && l || E && r && !o && l ? l : o, oe = E ? _e(r, l, f) : !1;
|
|
496
562
|
let Y;
|
|
497
|
-
return
|
|
498
|
-
|
|
563
|
+
return re.forEach((w, M) => {
|
|
564
|
+
M % 7 === 0 && (Y = document.createElement("div"), Y.setAttribute("role", "row"), Y.classList.add("cal-row"), A.appendChild(Y));
|
|
499
565
|
const c = document.createElement("button");
|
|
500
566
|
c.setAttribute("role", "gridcell"), c.setAttribute("part", "day"), c.classList.add("cal-day");
|
|
501
|
-
const
|
|
502
|
-
c.dataset.date =
|
|
503
|
-
const
|
|
504
|
-
c.setAttribute("aria-label",
|
|
567
|
+
const v = w.dateString;
|
|
568
|
+
c.dataset.date = v;
|
|
569
|
+
const le = new Date(w.year, w.month, w.day);
|
|
570
|
+
c.setAttribute("aria-label", le.toLocaleDateString("en-US", {
|
|
505
571
|
weekday: "long",
|
|
506
572
|
year: "numeric",
|
|
507
573
|
month: "long",
|
|
508
574
|
day: "numeric"
|
|
509
|
-
})),
|
|
510
|
-
let y = null,
|
|
511
|
-
if (
|
|
512
|
-
y =
|
|
513
|
-
const { status:
|
|
514
|
-
if (
|
|
515
|
-
let
|
|
516
|
-
if (
|
|
517
|
-
|
|
518
|
-
else if (
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
} else
|
|
522
|
-
|
|
575
|
+
})), w.isCurrentMonth || c.classList.add("cal-day--outside"), w.isToday && c.classList.add("cal-day--today");
|
|
576
|
+
let y = null, O = !1;
|
|
577
|
+
if (E) {
|
|
578
|
+
y = ye(v, f, j || {}, K, se);
|
|
579
|
+
const { status: m, label: x, halfDay: $, colorOut: F, colorIn: R, colorFull: N } = y;
|
|
580
|
+
if (m === "booked" && (c.classList.add("cal-day--booked"), N && (c.style.setProperty("--booking-bg", `hsl(${N.bg})`), c.style.setProperty("--booking-fg", `hsl(${N.fg})`), c.style.setProperty("--booking-hover", `hsl(${N.hover})`)), O = !0), m === "blocked" && (c.classList.add("cal-day--blocked"), O = !0), $ && (c.classList.add("cal-day--half-day"), F && c.style.setProperty("--half-day-color-out", `hsl(${F.bg})`), R && c.style.setProperty("--half-day-color-in", `hsl(${R.bg})`), O = !0), m === "checkout-only" && (c.classList.add("cal-day--checkout-only"), F && c.style.setProperty("--half-day-color-out", `hsl(${F.bg})`)), m === "checkin-only" && (c.classList.add("cal-day--checkin-only"), R && c.style.setProperty("--half-day-color-in", `hsl(${R.bg})`)), _) {
|
|
581
|
+
let L = null;
|
|
582
|
+
if ($ && y.checkoutBooking && y.checkinBooking)
|
|
583
|
+
L = `${y.checkoutBooking.label || ""} / ${y.checkinBooking.label || ""}`;
|
|
584
|
+
else if (m === "booked") {
|
|
585
|
+
const I = f.find((W) => W.start <= v && W.end > v);
|
|
586
|
+
I && (L = I.label);
|
|
587
|
+
} else m === "checkout-only" && y.checkoutBooking ? L = y.checkoutBooking.label : m === "checkin-only" && y.checkinBooking && (L = y.checkinBooking.label);
|
|
588
|
+
L && c.setAttribute("data-booking-label", L);
|
|
523
589
|
}
|
|
524
|
-
if (
|
|
525
|
-
const
|
|
526
|
-
|
|
590
|
+
if (oe && r && !o && l) {
|
|
591
|
+
const L = r < l ? r : l, I = r < l ? l : r;
|
|
592
|
+
v >= L && v <= I && c.classList.add("cal-day--invalid-range");
|
|
527
593
|
}
|
|
528
594
|
}
|
|
529
|
-
if (
|
|
530
|
-
const
|
|
531
|
-
|
|
595
|
+
if (E ? r && o && (C(v, r) || C(v, o)) ? (c.classList.add("cal-day--selected"), c.setAttribute("aria-selected", "true")) : c.setAttribute("aria-selected", "false") : n.some((x) => C(x, v)) ? (c.classList.add("cal-day--selected"), c.setAttribute("aria-selected", "true")) : c.setAttribute("aria-selected", "false"), (g === "range" || E) && r && J) {
|
|
596
|
+
const m = C(v, r), x = C(v, J), $ = pe(v, r, J);
|
|
597
|
+
m && c.classList.add("cal-day--range-start"), x && c.classList.add("cal-day--range-end"), $ && !m && !x && c.classList.add("cal-day--in-range");
|
|
532
598
|
}
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
599
|
+
const U = xe(v, i, h, d) || O;
|
|
600
|
+
if (U && (c.classList.add("cal-day--disabled"), c.disabled = !0, c.setAttribute("aria-disabled", "true")), u && C(v, u) ? c.setAttribute("tabindex", "0") : c.setAttribute("tabindex", "-1"), E && y && y.label != null) {
|
|
535
601
|
c.classList.add("cal-day--with-label");
|
|
536
|
-
const
|
|
537
|
-
|
|
602
|
+
const m = document.createElement("span");
|
|
603
|
+
m.classList.add("cal-day__number"), m.textContent = w.day, c.appendChild(m);
|
|
538
604
|
const x = document.createElement("span");
|
|
539
605
|
x.classList.add("cal-day__label"), x.textContent = y.label, c.appendChild(x);
|
|
540
606
|
} else
|
|
541
|
-
c.textContent =
|
|
542
|
-
|
|
543
|
-
}), A.addEventListener("mouseleave", () =>
|
|
607
|
+
c.textContent = w.day;
|
|
608
|
+
U ? E && c.addEventListener("mouseenter", () => b == null ? void 0 : b(v)) : (c.addEventListener("click", () => p == null ? void 0 : p(v)), c.addEventListener("mouseenter", () => b == null ? void 0 : b(v))), Y.appendChild(c);
|
|
609
|
+
}), A.addEventListener("mouseleave", () => b == null ? void 0 : b(null)), A;
|
|
544
610
|
}
|
|
545
|
-
function
|
|
611
|
+
function xe(s, e, a, t) {
|
|
546
612
|
return !!(t.includes(s) || e && s < e || a && s > a);
|
|
547
613
|
}
|
|
548
|
-
const
|
|
614
|
+
const De = `
|
|
549
615
|
.cal-grid {
|
|
550
616
|
display: flex;
|
|
551
617
|
flex-direction: column;
|
|
@@ -803,18 +869,18 @@ const ye = `
|
|
|
803
869
|
pointer-events: none;
|
|
804
870
|
z-index: 10;
|
|
805
871
|
}
|
|
806
|
-
`,
|
|
807
|
-
function
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
const
|
|
813
|
-
|
|
872
|
+
`, ae = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 12L6 8l4-4"/></svg>', ne = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l4 4-4 4"/></svg>';
|
|
873
|
+
function Z({ year: s, month: e, onPrev: a, onNext: t, onTitleClick: n, locale: r }) {
|
|
874
|
+
const o = document.createElement("div");
|
|
875
|
+
o.classList.add("cal-nav");
|
|
876
|
+
const l = document.createElement("button");
|
|
877
|
+
l.classList.add("cal-nav__btn", "cal-nav__btn--prev"), l.innerHTML = ae, l.setAttribute("aria-label", "Previous month"), l.addEventListener("click", a);
|
|
878
|
+
const i = ge(r), h = n ? "button" : "div", d = document.createElement(h);
|
|
879
|
+
d.classList.add("cal-nav__title"), n && (d.classList.add("cal-nav__title--interactive"), d.setAttribute("aria-label", `Select month and year, currently ${i[e]} ${s}`), d.addEventListener("click", n)), d.setAttribute("aria-live", "polite"), d.textContent = `${i[e]} ${s}`;
|
|
814
880
|
const g = document.createElement("button");
|
|
815
|
-
return g.classList.add("cal-nav__btn", "cal-nav__btn--next"), g.innerHTML =
|
|
881
|
+
return g.classList.add("cal-nav__btn", "cal-nav__btn--next"), g.innerHTML = ne, g.setAttribute("aria-label", "Next month"), g.addEventListener("click", t), o.appendChild(l), o.appendChild(d), o.appendChild(g), o;
|
|
816
882
|
}
|
|
817
|
-
const
|
|
883
|
+
const Le = `
|
|
818
884
|
.cal-nav {
|
|
819
885
|
display: flex;
|
|
820
886
|
align-items: center;
|
|
@@ -855,51 +921,39 @@ const me = `
|
|
|
855
921
|
.cal-nav__title--interactive:hover {
|
|
856
922
|
background: hsl(var(--cal-hover));
|
|
857
923
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
"Feb",
|
|
861
|
-
"Mar",
|
|
862
|
-
"Apr",
|
|
863
|
-
"May",
|
|
864
|
-
"Jun",
|
|
865
|
-
"Jul",
|
|
866
|
-
"Aug",
|
|
867
|
-
"Sep",
|
|
868
|
-
"Oct",
|
|
869
|
-
"Nov",
|
|
870
|
-
"Dec"
|
|
871
|
-
];
|
|
872
|
-
function _e({
|
|
924
|
+
`;
|
|
925
|
+
function Se({
|
|
873
926
|
pickerYear: s,
|
|
874
927
|
viewMonth: e,
|
|
875
928
|
viewYear: a,
|
|
876
929
|
onMonthSelect: t,
|
|
877
930
|
onYearPrev: n,
|
|
878
931
|
onYearNext: r,
|
|
879
|
-
onClose: o
|
|
932
|
+
onClose: o,
|
|
933
|
+
locale: l
|
|
880
934
|
}) {
|
|
881
|
-
const l = document.createElement("div");
|
|
882
|
-
l.classList.add("cal-myp", "cal-animate-fade");
|
|
883
935
|
const i = document.createElement("div");
|
|
884
|
-
i.classList.add("cal-
|
|
885
|
-
const g = document.createElement("button");
|
|
886
|
-
g.classList.add("cal-nav__btn"), g.innerHTML = Q, g.setAttribute("aria-label", "Previous year"), g.addEventListener("click", n);
|
|
936
|
+
i.classList.add("cal-myp", "cal-animate-fade");
|
|
887
937
|
const h = document.createElement("div");
|
|
888
|
-
h.classList.add("cal-myp__year-
|
|
938
|
+
h.classList.add("cal-myp__year-nav");
|
|
939
|
+
const d = document.createElement("button");
|
|
940
|
+
d.classList.add("cal-nav__btn"), d.innerHTML = ae, d.setAttribute("aria-label", "Previous year"), d.addEventListener("click", n);
|
|
941
|
+
const g = document.createElement("div");
|
|
942
|
+
g.classList.add("cal-myp__year-label"), g.textContent = s;
|
|
889
943
|
const u = document.createElement("button");
|
|
890
|
-
u.classList.add("cal-nav__btn"), u.innerHTML =
|
|
891
|
-
const
|
|
892
|
-
|
|
893
|
-
const b = /* @__PURE__ */ new Date(),
|
|
894
|
-
for (let
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
return
|
|
899
|
-
|
|
900
|
-
}),
|
|
944
|
+
u.classList.add("cal-nav__btn"), u.innerHTML = ne, u.setAttribute("aria-label", "Next year"), u.addEventListener("click", r), h.appendChild(d), h.appendChild(g), h.appendChild(u), i.appendChild(h);
|
|
945
|
+
const p = document.createElement("div");
|
|
946
|
+
p.classList.add("cal-myp__grid");
|
|
947
|
+
const b = te(l), f = /* @__PURE__ */ new Date(), j = f.getMonth(), K = f.getFullYear();
|
|
948
|
+
for (let _ = 0; _ < 12; _++) {
|
|
949
|
+
const D = document.createElement("button");
|
|
950
|
+
D.classList.add("cal-myp__cell"), D.textContent = b[_], _ === e && s === a && D.classList.add("cal-myp__cell--active"), _ === j && s === K && D.classList.add("cal-myp__cell--today"), D.addEventListener("click", () => t(_, s)), p.appendChild(D);
|
|
951
|
+
}
|
|
952
|
+
return i.appendChild(p), i.addEventListener("keydown", (_) => {
|
|
953
|
+
_.key === "Escape" && (_.stopPropagation(), o());
|
|
954
|
+
}), i;
|
|
901
955
|
}
|
|
902
|
-
const
|
|
956
|
+
const Ee = `
|
|
903
957
|
.cal-myp {
|
|
904
958
|
width: calc(7 * var(--cal-cell-size));
|
|
905
959
|
}
|
|
@@ -957,58 +1011,74 @@ const xe = `
|
|
|
957
1011
|
border: 1px solid hsl(var(--cal-border));
|
|
958
1012
|
font-weight: 600;
|
|
959
1013
|
}
|
|
960
|
-
|
|
961
|
-
|
|
1014
|
+
`, V = {
|
|
1015
|
+
today: "Today",
|
|
1016
|
+
"this-week": "This Week",
|
|
1017
|
+
"next-7": "Next 7 Days",
|
|
1018
|
+
"next-30": "Next 30 Days"
|
|
1019
|
+
};
|
|
1020
|
+
function H(s, e) {
|
|
1021
|
+
if (!e) return V[s] || s;
|
|
1022
|
+
try {
|
|
1023
|
+
if (s === "today") {
|
|
1024
|
+
const n = new Intl.RelativeTimeFormat(e, { numeric: "auto" }).formatToParts(0, "day").map((r) => r.value).join("");
|
|
1025
|
+
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
1026
|
+
}
|
|
1027
|
+
} catch {
|
|
1028
|
+
}
|
|
1029
|
+
return V[s] || s;
|
|
1030
|
+
}
|
|
1031
|
+
function Me(s) {
|
|
962
1032
|
return [
|
|
963
1033
|
{
|
|
964
1034
|
key: "today",
|
|
965
|
-
label: "
|
|
1035
|
+
label: H("today", s),
|
|
966
1036
|
resolve() {
|
|
967
|
-
const
|
|
968
|
-
return { start:
|
|
1037
|
+
const e = G();
|
|
1038
|
+
return { start: e, end: e };
|
|
969
1039
|
}
|
|
970
1040
|
},
|
|
971
1041
|
{
|
|
972
1042
|
key: "this-week",
|
|
973
|
-
label: "
|
|
1043
|
+
label: H("this-week", s),
|
|
974
1044
|
resolve() {
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
const
|
|
978
|
-
return
|
|
1045
|
+
const e = /* @__PURE__ */ new Date(), a = e.getDay(), t = new Date(e);
|
|
1046
|
+
t.setDate(e.getDate() - a);
|
|
1047
|
+
const n = new Date(t);
|
|
1048
|
+
return n.setDate(t.getDate() + 6), { start: k(t), end: k(n) };
|
|
979
1049
|
}
|
|
980
1050
|
},
|
|
981
1051
|
{
|
|
982
1052
|
key: "next-7",
|
|
983
|
-
label: "
|
|
1053
|
+
label: H("next-7", s),
|
|
984
1054
|
resolve() {
|
|
985
|
-
const
|
|
986
|
-
return
|
|
1055
|
+
const e = /* @__PURE__ */ new Date(), a = /* @__PURE__ */ new Date();
|
|
1056
|
+
return a.setDate(e.getDate() + 6), { start: k(e), end: k(a) };
|
|
987
1057
|
}
|
|
988
1058
|
},
|
|
989
1059
|
{
|
|
990
1060
|
key: "next-30",
|
|
991
|
-
label: "
|
|
1061
|
+
label: H("next-30", s),
|
|
992
1062
|
resolve() {
|
|
993
|
-
const
|
|
994
|
-
return
|
|
1063
|
+
const e = /* @__PURE__ */ new Date(), a = /* @__PURE__ */ new Date();
|
|
1064
|
+
return a.setDate(e.getDate() + 29), { start: k(e), end: k(a) };
|
|
995
1065
|
}
|
|
996
1066
|
}
|
|
997
1067
|
];
|
|
998
1068
|
}
|
|
999
|
-
function
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
const
|
|
1003
|
-
for (const
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
e == null || e(
|
|
1007
|
-
}),
|
|
1069
|
+
function Ce({ presetKeys: s, onSelect: e, locale: a }) {
|
|
1070
|
+
const t = document.createElement("div");
|
|
1071
|
+
t.classList.add("cal-presets");
|
|
1072
|
+
const n = Me(a), r = s.map((o) => n.find((l) => l.key === o)).filter(Boolean);
|
|
1073
|
+
for (const o of r) {
|
|
1074
|
+
const l = document.createElement("button");
|
|
1075
|
+
l.classList.add("cal-preset"), l.textContent = o.label, l.addEventListener("click", () => {
|
|
1076
|
+
e == null || e(o.resolve());
|
|
1077
|
+
}), t.appendChild(l);
|
|
1008
1078
|
}
|
|
1009
|
-
return
|
|
1079
|
+
return t;
|
|
1010
1080
|
}
|
|
1011
|
-
const
|
|
1081
|
+
const Ae = `
|
|
1012
1082
|
.cal-presets {
|
|
1013
1083
|
display: flex;
|
|
1014
1084
|
flex-wrap: wrap;
|
|
@@ -1035,37 +1105,37 @@ const Le = `
|
|
|
1035
1105
|
background: hsl(var(--cal-hover));
|
|
1036
1106
|
}
|
|
1037
1107
|
`;
|
|
1038
|
-
function
|
|
1108
|
+
function Te({ trigger: s, content: e, onClose: a }) {
|
|
1039
1109
|
const t = document.createElement("div");
|
|
1040
1110
|
t.classList.add("cal-popover"), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "false"), t.style.display = "none", t.appendChild(e);
|
|
1041
1111
|
let n = !1;
|
|
1042
1112
|
function r() {
|
|
1043
1113
|
t.classList.remove("cal-popover--above");
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1114
|
+
const g = s.getBoundingClientRect(), u = t.offsetHeight, p = window.innerHeight - g.bottom, b = g.top;
|
|
1115
|
+
p < u + 8 && b > p ? (t.classList.add("cal-popover--above"), t.style.top = "auto", t.style.bottom = "100%", t.style.marginBottom = "4px", t.style.marginTop = "0") : (t.style.top = "100%", t.style.bottom = "auto", t.style.marginTop = "4px", t.style.marginBottom = "0");
|
|
1046
1116
|
}
|
|
1047
1117
|
function o() {
|
|
1048
|
-
n || (n = !0, t.style.display = "", t.classList.add("cal-animate-slide-up"), requestAnimationFrame(() => r()), document.addEventListener("click", i, !0), document.addEventListener("keydown",
|
|
1118
|
+
n || (n = !0, t.style.display = "", t.classList.add("cal-animate-slide-up"), requestAnimationFrame(() => r()), document.addEventListener("click", i, !0), document.addEventListener("keydown", h, !0));
|
|
1049
1119
|
}
|
|
1050
1120
|
function l() {
|
|
1051
|
-
n && (n = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up"), document.removeEventListener("click", i, !0), document.removeEventListener("keydown",
|
|
1121
|
+
n && (n = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up"), document.removeEventListener("click", i, !0), document.removeEventListener("keydown", h, !0), a == null || a());
|
|
1052
1122
|
}
|
|
1053
|
-
function i(
|
|
1054
|
-
var
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1123
|
+
function i(g) {
|
|
1124
|
+
var p;
|
|
1125
|
+
const u = (p = s.getRootNode()) == null ? void 0 : p.host;
|
|
1126
|
+
u && !u.contains(g.target) && g.target !== u && l();
|
|
1057
1127
|
}
|
|
1058
|
-
function g
|
|
1059
|
-
|
|
1128
|
+
function h(g) {
|
|
1129
|
+
g.key === "Escape" && (g.stopPropagation(), l());
|
|
1060
1130
|
}
|
|
1061
|
-
function
|
|
1062
|
-
n && (n = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up")), document.removeEventListener("click", i, !0), document.removeEventListener("keydown",
|
|
1131
|
+
function d() {
|
|
1132
|
+
n && (n = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up")), document.removeEventListener("click", i, !0), document.removeEventListener("keydown", h, !0);
|
|
1063
1133
|
}
|
|
1064
|
-
return { panel: t, open: o, close: l, destroy:
|
|
1134
|
+
return { panel: t, open: o, close: l, destroy: d, get isOpen() {
|
|
1065
1135
|
return n;
|
|
1066
1136
|
} };
|
|
1067
1137
|
}
|
|
1068
|
-
const
|
|
1138
|
+
const Ye = `
|
|
1069
1139
|
.cal-popover-wrapper {
|
|
1070
1140
|
position: relative;
|
|
1071
1141
|
display: inline-block;
|
|
@@ -1111,7 +1181,7 @@ const Ee = `
|
|
|
1111
1181
|
color: hsl(var(--cal-fg-muted));
|
|
1112
1182
|
}
|
|
1113
1183
|
`;
|
|
1114
|
-
function
|
|
1184
|
+
function Be({ rows: s = 5 } = {}) {
|
|
1115
1185
|
const e = document.createElement("div");
|
|
1116
1186
|
e.setAttribute("role", "status"), e.setAttribute("aria-label", "Loading..."), e.classList.add("cal-skeleton-calendar-grid");
|
|
1117
1187
|
for (let t = 0; t < 7; t++) {
|
|
@@ -1125,7 +1195,7 @@ function Me({ rows: s = 5 } = {}) {
|
|
|
1125
1195
|
}
|
|
1126
1196
|
return e;
|
|
1127
1197
|
}
|
|
1128
|
-
const
|
|
1198
|
+
const ze = `
|
|
1129
1199
|
.cal-skeleton-time-grid {
|
|
1130
1200
|
display: grid;
|
|
1131
1201
|
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
@@ -1158,17 +1228,17 @@ const Ce = `
|
|
|
1158
1228
|
aspect-ratio: 1;
|
|
1159
1229
|
border-radius: var(--cal-radius-sm) !important;
|
|
1160
1230
|
}
|
|
1161
|
-
`,
|
|
1231
|
+
`, ee = {
|
|
1162
1232
|
error: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 4v3M7 9.5v.01"/></svg>',
|
|
1163
1233
|
warning: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M7 1.5L1 12.5h12L7 1.5zM7 6v2.5M7 10.5v.01"/></svg>',
|
|
1164
1234
|
info: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 6.5V10M7 4.5v.01"/></svg>',
|
|
1165
1235
|
success: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M4.5 7l2 2L9.5 5"/></svg>'
|
|
1166
1236
|
};
|
|
1167
|
-
function
|
|
1237
|
+
function Pe({ type: s = "info", message: e, dismissible: a = !0, onDismiss: t }) {
|
|
1168
1238
|
const n = document.createElement("div");
|
|
1169
1239
|
n.classList.add("cal-status", `cal-status--${s}`, "cal-animate-slide-up"), n.setAttribute("role", s === "error" ? "alert" : "status"), n.setAttribute("aria-live", s === "error" ? "assertive" : "polite");
|
|
1170
1240
|
const r = document.createElement("span");
|
|
1171
|
-
r.classList.add("cal-status__icon"), r.innerHTML =
|
|
1241
|
+
r.classList.add("cal-status__icon"), r.innerHTML = ee[s] || ee.info, n.appendChild(r);
|
|
1172
1242
|
const o = document.createElement("span");
|
|
1173
1243
|
if (o.classList.add("cal-status__text"), o.textContent = e, n.appendChild(o), a) {
|
|
1174
1244
|
const l = document.createElement("button");
|
|
@@ -1176,7 +1246,7 @@ function Ae({ type: s = "info", message: e, dismissible: a = !0, onDismiss: t })
|
|
|
1176
1246
|
}
|
|
1177
1247
|
return n;
|
|
1178
1248
|
}
|
|
1179
|
-
const
|
|
1249
|
+
const Oe = `
|
|
1180
1250
|
.cal-status {
|
|
1181
1251
|
display: flex;
|
|
1182
1252
|
align-items: center;
|
|
@@ -1238,7 +1308,7 @@ const Te = `
|
|
|
1238
1308
|
color: hsl(var(--cal-status-success-fg));
|
|
1239
1309
|
border: 1px solid hsl(var(--cal-status-success-border));
|
|
1240
1310
|
}
|
|
1241
|
-
`,
|
|
1311
|
+
`, $e = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="12" height="11" rx="2"/><path d="M5 1v3M11 1v3M2 7h12"/></svg>', Fe = `
|
|
1242
1312
|
.cal-picker {
|
|
1243
1313
|
background: hsl(var(--cal-bg));
|
|
1244
1314
|
border-radius: var(--cal-radius);
|
|
@@ -1259,9 +1329,9 @@ const Te = `
|
|
|
1259
1329
|
flex: 0 0 auto;
|
|
1260
1330
|
}
|
|
1261
1331
|
`;
|
|
1262
|
-
class
|
|
1332
|
+
class Re extends ie {
|
|
1263
1333
|
static get styles() {
|
|
1264
|
-
return [
|
|
1334
|
+
return [fe, ve, me, De, Le, Ee, Ae, Ye, ze, Oe, Fe];
|
|
1265
1335
|
}
|
|
1266
1336
|
static get observedAttributes() {
|
|
1267
1337
|
return ["mode", "display", "theme", "value", "min-date", "max-date", "disabled-dates", "first-day", "locale", "presets", "placeholder", "loading"];
|
|
@@ -1269,7 +1339,7 @@ class ze extends ne {
|
|
|
1269
1339
|
constructor() {
|
|
1270
1340
|
super();
|
|
1271
1341
|
const e = /* @__PURE__ */ new Date();
|
|
1272
|
-
this._store =
|
|
1342
|
+
this._store = ce({
|
|
1273
1343
|
viewYear: e.getFullYear(),
|
|
1274
1344
|
viewMonth: e.getMonth(),
|
|
1275
1345
|
selectedDates: [],
|
|
@@ -1277,7 +1347,7 @@ class ze extends ne {
|
|
|
1277
1347
|
rangeEnd: null,
|
|
1278
1348
|
hoverDate: null,
|
|
1279
1349
|
isOpen: !1,
|
|
1280
|
-
focusedDate:
|
|
1350
|
+
focusedDate: G(),
|
|
1281
1351
|
navDirection: null,
|
|
1282
1352
|
pickingMonth: !1,
|
|
1283
1353
|
pickerYear: e.getFullYear(),
|
|
@@ -1305,6 +1375,9 @@ class ze extends ne {
|
|
|
1305
1375
|
get maxDate() {
|
|
1306
1376
|
return this.getAttribute("max-date") || null;
|
|
1307
1377
|
}
|
|
1378
|
+
get locale() {
|
|
1379
|
+
return this.getAttribute("locale") || void 0;
|
|
1380
|
+
}
|
|
1308
1381
|
get loading() {
|
|
1309
1382
|
return this.hasAttribute("loading");
|
|
1310
1383
|
}
|
|
@@ -1326,7 +1399,7 @@ class ze extends ne {
|
|
|
1326
1399
|
}
|
|
1327
1400
|
set value(e) {
|
|
1328
1401
|
if (this.mode === "range" && e && typeof e == "object") {
|
|
1329
|
-
const a = typeof e.start == "string" ? e.start :
|
|
1402
|
+
const a = typeof e.start == "string" ? e.start : k(e.start), t = typeof e.end == "string" ? e.end : k(e.end);
|
|
1330
1403
|
this._store.set({
|
|
1331
1404
|
rangeStart: a,
|
|
1332
1405
|
rangeEnd: t,
|
|
@@ -1335,7 +1408,7 @@ class ze extends ne {
|
|
|
1335
1408
|
} else this.mode === "multi" && Array.isArray(e) ? (this._store.set({ selectedDates: e }), e.length && this._navigateToDate(e[0])) : typeof e == "string" ? (this._store.set({ selectedDates: [e], rangeStart: null, rangeEnd: null }), this._navigateToDate(e)) : this._store.set({ selectedDates: [], rangeStart: null, rangeEnd: null });
|
|
1336
1409
|
}
|
|
1337
1410
|
_navigateToDate(e) {
|
|
1338
|
-
const a =
|
|
1411
|
+
const a = S(e);
|
|
1339
1412
|
a && this._store.set({ viewYear: a.getFullYear(), viewMonth: a.getMonth() });
|
|
1340
1413
|
}
|
|
1341
1414
|
connectedCallback() {
|
|
@@ -1391,7 +1464,7 @@ class ze extends ne {
|
|
|
1391
1464
|
}), this.emit("cal:change", { value: { start: t, end: n } }), this.display === "popover" && this.close();
|
|
1392
1465
|
}
|
|
1393
1466
|
else if (this.mode === "multi") {
|
|
1394
|
-
const t = [...a.selectedDates], n = t.findIndex((r) =>
|
|
1467
|
+
const t = [...a.selectedDates], n = t.findIndex((r) => C(r, e));
|
|
1395
1468
|
n >= 0 ? t.splice(n, 1) : t.push(e), t.sort(), this._store.set({ selectedDates: t, focusedDate: e }), this.emit("cal:change", { value: t });
|
|
1396
1469
|
}
|
|
1397
1470
|
}
|
|
@@ -1436,7 +1509,7 @@ class ze extends ne {
|
|
|
1436
1509
|
e.stopPropagation(), this._store.set({ pickingMonth: !1 });
|
|
1437
1510
|
return;
|
|
1438
1511
|
}
|
|
1439
|
-
const a = this._store.getState(), t =
|
|
1512
|
+
const a = this._store.getState(), t = S(a.focusedDate);
|
|
1440
1513
|
if (!t) return;
|
|
1441
1514
|
let n = null;
|
|
1442
1515
|
switch (e.key) {
|
|
@@ -1464,7 +1537,7 @@ class ze extends ne {
|
|
|
1464
1537
|
}
|
|
1465
1538
|
if (n) {
|
|
1466
1539
|
e.preventDefault();
|
|
1467
|
-
const r =
|
|
1540
|
+
const r = k(n);
|
|
1468
1541
|
n.getMonth() !== a.viewMonth || n.getFullYear() !== a.viewYear ? this._store.set({
|
|
1469
1542
|
viewYear: n.getFullYear(),
|
|
1470
1543
|
viewMonth: n.getMonth(),
|
|
@@ -1482,13 +1555,13 @@ class ze extends ne {
|
|
|
1482
1555
|
for (const o of a) {
|
|
1483
1556
|
const l = o.dataset.date;
|
|
1484
1557
|
if (!l || o.classList.contains("cal-day--disabled")) continue;
|
|
1485
|
-
const i = l === t,
|
|
1486
|
-
let
|
|
1558
|
+
const i = l === t, h = l === r;
|
|
1559
|
+
let d = !1;
|
|
1487
1560
|
if (t && r) {
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1561
|
+
const g = t < r ? t : r, u = t < r ? r : t;
|
|
1562
|
+
d = l >= g && l <= u && !i && !h;
|
|
1490
1563
|
}
|
|
1491
|
-
o.classList.toggle("cal-day--range-start", i && !!r), o.classList.toggle("cal-day--range-end",
|
|
1564
|
+
o.classList.toggle("cal-day--range-start", i && !!r), o.classList.toggle("cal-day--range-end", h && !!r), o.classList.toggle("cal-day--in-range", d);
|
|
1492
1565
|
}
|
|
1493
1566
|
}
|
|
1494
1567
|
// -- Public API --
|
|
@@ -1501,10 +1574,18 @@ class ze extends ne {
|
|
|
1501
1574
|
goToMonth(e, a) {
|
|
1502
1575
|
this._store.set({ viewYear: a, viewMonth: e });
|
|
1503
1576
|
}
|
|
1577
|
+
clear() {
|
|
1578
|
+
this._store.set({
|
|
1579
|
+
selectedDates: [],
|
|
1580
|
+
rangeStart: null,
|
|
1581
|
+
rangeEnd: null,
|
|
1582
|
+
hoverDate: null
|
|
1583
|
+
}), this.emit("cal:change", { value: null });
|
|
1584
|
+
}
|
|
1504
1585
|
// -- Render --
|
|
1505
1586
|
_renderCalendarContent() {
|
|
1506
1587
|
const e = this._store.getState(), a = document.createElement("div");
|
|
1507
|
-
if (a.classList.add("cal-picker"), e.statusType && e.statusMessage && a.appendChild(
|
|
1588
|
+
if (a.classList.add("cal-picker"), e.statusType && e.statusMessage && a.appendChild(Pe({
|
|
1508
1589
|
type: e.statusType,
|
|
1509
1590
|
message: e.statusMessage,
|
|
1510
1591
|
dismissible: e.statusDismissible,
|
|
@@ -1513,14 +1594,14 @@ class ze extends ne {
|
|
|
1513
1594
|
const o = document.createElement("div");
|
|
1514
1595
|
o.classList.add("cal-months");
|
|
1515
1596
|
const l = document.createElement("div");
|
|
1516
|
-
return l.classList.add("cal-month"), l.appendChild(
|
|
1597
|
+
return l.classList.add("cal-month"), l.appendChild(Be()), o.appendChild(l), a.appendChild(o), a.addEventListener("keydown", (i) => this._handleKeydown(i)), a;
|
|
1517
1598
|
}
|
|
1518
1599
|
const t = document.createElement("div");
|
|
1519
1600
|
t.classList.add("cal-months");
|
|
1520
1601
|
const n = this.mode === "range" && this.hasAttribute("dual"), r = n ? 2 : 1;
|
|
1521
1602
|
for (let o = 0; o < r; o++) {
|
|
1522
|
-
const { year: l, month: i } = o === 0 ? { year: e.viewYear, month: e.viewMonth } : z(e.viewYear, e.viewMonth, 1),
|
|
1523
|
-
if (
|
|
1603
|
+
const { year: l, month: i } = o === 0 ? { year: e.viewYear, month: e.viewMonth } : z(e.viewYear, e.viewMonth, 1), h = document.createElement("div");
|
|
1604
|
+
if (h.classList.add("cal-month"), o === 0 && h.appendChild(Z({
|
|
1524
1605
|
year: l,
|
|
1525
1606
|
month: i,
|
|
1526
1607
|
onPrev: e.pickingMonth ? () => {
|
|
@@ -1529,26 +1610,29 @@ class ze extends ne {
|
|
|
1529
1610
|
} : () => {
|
|
1530
1611
|
n || this._nextMonth();
|
|
1531
1612
|
},
|
|
1532
|
-
onTitleClick: () => this._toggleMonthPicker()
|
|
1533
|
-
|
|
1613
|
+
onTitleClick: () => this._toggleMonthPicker(),
|
|
1614
|
+
locale: this.locale
|
|
1615
|
+
})), o === 1 && h.appendChild(Z({
|
|
1534
1616
|
year: l,
|
|
1535
1617
|
month: i,
|
|
1536
1618
|
onPrev: () => {
|
|
1537
1619
|
},
|
|
1538
|
-
onNext: () => this._nextMonth()
|
|
1620
|
+
onNext: () => this._nextMonth(),
|
|
1621
|
+
locale: this.locale
|
|
1539
1622
|
})), e.pickingMonth && o === 0) {
|
|
1540
|
-
const
|
|
1623
|
+
const d = Se({
|
|
1541
1624
|
pickerYear: e.pickerYear,
|
|
1542
1625
|
viewMonth: e.viewMonth,
|
|
1543
1626
|
viewYear: e.viewYear,
|
|
1544
|
-
onMonthSelect: (
|
|
1627
|
+
onMonthSelect: (g, u) => this._selectMonthFromPicker(g, u),
|
|
1545
1628
|
onYearPrev: () => this._store.set({ pickerYear: e.pickerYear - 1 }),
|
|
1546
1629
|
onYearNext: () => this._store.set({ pickerYear: e.pickerYear + 1 }),
|
|
1547
|
-
onClose: () => this._store.set({ pickingMonth: !1 })
|
|
1630
|
+
onClose: () => this._store.set({ pickingMonth: !1 }),
|
|
1631
|
+
locale: this.locale
|
|
1548
1632
|
});
|
|
1549
|
-
|
|
1633
|
+
h.appendChild(d);
|
|
1550
1634
|
} else {
|
|
1551
|
-
const
|
|
1635
|
+
const d = e.navDirection === "next" ? "cal-animate-slide-left" : e.navDirection === "prev" ? "cal-animate-slide-right" : "", g = we({
|
|
1552
1636
|
year: l,
|
|
1553
1637
|
month: i,
|
|
1554
1638
|
firstDay: this.firstDay,
|
|
@@ -1561,16 +1645,18 @@ class ze extends ne {
|
|
|
1561
1645
|
disabledDates: this.disabledDates,
|
|
1562
1646
|
mode: this.mode,
|
|
1563
1647
|
focusedDate: e.focusedDate,
|
|
1564
|
-
onSelect: (
|
|
1565
|
-
onHover: (
|
|
1648
|
+
onSelect: (u) => this._handleSelect(u),
|
|
1649
|
+
onHover: (u) => this._handleHover(u),
|
|
1650
|
+
locale: this.locale
|
|
1566
1651
|
});
|
|
1567
|
-
|
|
1652
|
+
d && g.classList.add(d), h.appendChild(g);
|
|
1568
1653
|
}
|
|
1569
|
-
t.appendChild(
|
|
1654
|
+
t.appendChild(h);
|
|
1570
1655
|
}
|
|
1571
|
-
return a.appendChild(t), this.mode === "range" && this.presetKeys.length && a.appendChild(
|
|
1656
|
+
return a.appendChild(t), this.mode === "range" && this.presetKeys.length && a.appendChild(Ce({
|
|
1572
1657
|
presetKeys: this.presetKeys,
|
|
1573
|
-
onSelect: (o) => this._handlePresetSelect(o)
|
|
1658
|
+
onSelect: (o) => this._handlePresetSelect(o),
|
|
1659
|
+
locale: this.locale
|
|
1574
1660
|
})), a.addEventListener("keydown", (o) => this._handleKeydown(o)), a;
|
|
1575
1661
|
}
|
|
1576
1662
|
_formatTriggerText() {
|
|
@@ -1578,8 +1664,14 @@ class ze extends ne {
|
|
|
1578
1664
|
return this.mode === "range" && e.rangeStart && e.rangeEnd ? `${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}` : e.selectedDates.length ? this.mode === "multi" ? `${e.selectedDates.length} dates selected` : this._formatShortDate(e.selectedDates[0]) : null;
|
|
1579
1665
|
}
|
|
1580
1666
|
_formatShortDate(e) {
|
|
1581
|
-
const a =
|
|
1582
|
-
|
|
1667
|
+
const a = S(e);
|
|
1668
|
+
if (!a) return e;
|
|
1669
|
+
if (this.locale)
|
|
1670
|
+
try {
|
|
1671
|
+
return new Intl.DateTimeFormat(this.locale, { month: "short", day: "numeric", year: "numeric" }).format(a);
|
|
1672
|
+
} catch {
|
|
1673
|
+
}
|
|
1674
|
+
return `${te(this.locale)[a.getMonth()]} ${a.getDate()}, ${a.getFullYear()}`;
|
|
1583
1675
|
}
|
|
1584
1676
|
render() {
|
|
1585
1677
|
var t;
|
|
@@ -1594,26 +1686,26 @@ class ze extends ne {
|
|
|
1594
1686
|
const r = document.createElement("button");
|
|
1595
1687
|
r.classList.add("cal-trigger");
|
|
1596
1688
|
const o = document.createElement("span");
|
|
1597
|
-
o.classList.add("cal-trigger__icon"), o.innerHTML =
|
|
1689
|
+
o.classList.add("cal-trigger__icon"), o.innerHTML = $e, r.appendChild(o);
|
|
1598
1690
|
const l = this._formatTriggerText(), i = document.createElement("span");
|
|
1599
1691
|
l ? i.textContent = l : (i.textContent = this.placeholder, i.classList.add("cal-trigger--placeholder")), r.appendChild(i), n.appendChild(r);
|
|
1600
|
-
const
|
|
1692
|
+
const h = this._renderCalendarContent(), d = Te({
|
|
1601
1693
|
trigger: r,
|
|
1602
|
-
content:
|
|
1694
|
+
content: h,
|
|
1603
1695
|
onClose: () => {
|
|
1604
1696
|
this._store.set({ isOpen: !1 }), this.emit("cal:close");
|
|
1605
1697
|
}
|
|
1606
1698
|
});
|
|
1607
|
-
n.appendChild(
|
|
1608
|
-
|
|
1609
|
-
}), this._popover =
|
|
1699
|
+
n.appendChild(d.panel), e.appendChild(n), r.addEventListener("click", (g) => {
|
|
1700
|
+
g.stopPropagation(), d.isOpen ? this.close() : this.open();
|
|
1701
|
+
}), this._popover = d, this._store.get("isOpen") && d.open();
|
|
1610
1702
|
} else
|
|
1611
1703
|
e.appendChild(this._renderCalendarContent());
|
|
1612
1704
|
this._store.set({ navDirection: null }), this._rendering = !1;
|
|
1613
1705
|
}
|
|
1614
1706
|
}
|
|
1615
|
-
customElements.get("cal-datepicker") || customElements.define("cal-datepicker",
|
|
1707
|
+
customElements.get("cal-datepicker") || customElements.define("cal-datepicker", Re);
|
|
1616
1708
|
export {
|
|
1617
|
-
|
|
1709
|
+
Re as CalDatepicker
|
|
1618
1710
|
};
|
|
1619
1711
|
//# sourceMappingURL=datepicker.es.js.map
|