calkit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +734 -0
- package/dist/booking.es.js +1845 -0
- package/dist/booking.es.js.map +1 -0
- package/dist/booking.umd.js +888 -0
- package/dist/booking.umd.js.map +1 -0
- package/dist/calkit.es.js +5230 -0
- package/dist/calkit.es.js.map +1 -0
- package/dist/calkit.umd.js +2164 -0
- package/dist/calkit.umd.js.map +1 -0
- package/dist/datepicker.es.js +1619 -0
- package/dist/datepicker.es.js.map +1 -0
- package/dist/datepicker.umd.js +818 -0
- package/dist/datepicker.umd.js.map +1 -0
- package/dist/scheduler.es.js +3235 -0
- package/dist/scheduler.es.js.map +1 -0
- package/dist/scheduler.umd.js +1547 -0
- package/dist/scheduler.umd.js.map +1 -0
- package/dist/timepicker.es.js +962 -0
- package/dist/timepicker.es.js.map +1 -0
- package/dist/timepicker.umd.js +517 -0
- package/dist/timepicker.umd.js.map +1 -0
- package/llms.txt +594 -0
- package/package.json +58 -0
|
@@ -0,0 +1,962 @@
|
|
|
1
|
+
class C extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(), this.attachShadow({ mode: "open" }), this._initialized = !1;
|
|
4
|
+
}
|
|
5
|
+
/** Override in subclass — return array of CSSStyleSheet or CSS strings. */
|
|
6
|
+
static get styles() {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this._initialized || (this._adoptStyles(), this._initialized = !0), this.render();
|
|
11
|
+
}
|
|
12
|
+
_adoptStyles() {
|
|
13
|
+
const e = this.constructor.styles;
|
|
14
|
+
if (e.length)
|
|
15
|
+
if ("adoptedStyleSheets" in this.shadowRoot)
|
|
16
|
+
this.shadowRoot.adoptedStyleSheets = e.map((s) => {
|
|
17
|
+
if (s instanceof CSSStyleSheet) return s;
|
|
18
|
+
const t = new CSSStyleSheet();
|
|
19
|
+
return t.replaceSync(s), t;
|
|
20
|
+
});
|
|
21
|
+
else
|
|
22
|
+
for (const s of e) {
|
|
23
|
+
const t = document.createElement("style");
|
|
24
|
+
t.textContent = s instanceof CSSStyleSheet ? "" : s, this.shadowRoot.prepend(t);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Subclasses override to update Shadow DOM. */
|
|
28
|
+
render() {
|
|
29
|
+
}
|
|
30
|
+
/** Dispatch a composed, bubbling custom event. */
|
|
31
|
+
emit(e, s = {}) {
|
|
32
|
+
this.dispatchEvent(
|
|
33
|
+
new CustomEvent(e, { detail: s, bubbles: !0, composed: !0 })
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
/** Show an inline status banner. */
|
|
37
|
+
showStatus(e, s, t = {}) {
|
|
38
|
+
if (!this._store) return;
|
|
39
|
+
const { autoDismiss: a, dismissible: i = !0 } = t;
|
|
40
|
+
clearTimeout(this._statusTimer), this._store.set({ statusType: e, statusMessage: s, statusDismissible: i }), this.emit("cal:status", { type: e, message: s }), a && a > 0 && (this._statusTimer = setTimeout(() => this.clearStatus(), a));
|
|
41
|
+
}
|
|
42
|
+
/** Clear the status banner. */
|
|
43
|
+
clearStatus() {
|
|
44
|
+
this._store && (clearTimeout(this._statusTimer), this._store.set({ statusType: null, statusMessage: null, statusDismissible: !0 }), this.emit("cal:status", { type: null, message: null }));
|
|
45
|
+
}
|
|
46
|
+
/** Query within shadow root. */
|
|
47
|
+
$(e) {
|
|
48
|
+
return this.shadowRoot.querySelector(e);
|
|
49
|
+
}
|
|
50
|
+
$$(e) {
|
|
51
|
+
return this.shadowRoot.querySelectorAll(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function A(r) {
|
|
55
|
+
let e = { ...r };
|
|
56
|
+
const s = /* @__PURE__ */ new Set();
|
|
57
|
+
return {
|
|
58
|
+
get(t) {
|
|
59
|
+
return e[t];
|
|
60
|
+
},
|
|
61
|
+
set(t) {
|
|
62
|
+
const a = e;
|
|
63
|
+
e = { ...e, ...t };
|
|
64
|
+
let i = !1;
|
|
65
|
+
for (const l of Object.keys(t))
|
|
66
|
+
if (a[l] !== e[l]) {
|
|
67
|
+
i = !0;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (i)
|
|
71
|
+
for (const l of s) l(e, a);
|
|
72
|
+
},
|
|
73
|
+
getState() {
|
|
74
|
+
return e;
|
|
75
|
+
},
|
|
76
|
+
subscribe(t) {
|
|
77
|
+
return s.add(t), () => s.delete(t);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function k(r) {
|
|
82
|
+
if (!r || typeof r != "string") return null;
|
|
83
|
+
const e = r.trim().toUpperCase(), s = e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/);
|
|
84
|
+
if (s) {
|
|
85
|
+
let a = parseInt(s[1], 10);
|
|
86
|
+
const i = parseInt(s[2], 10), l = s[3];
|
|
87
|
+
return l === "AM" && a === 12 && (a = 0), l === "PM" && a !== 12 && (a += 12), { hours: a, minutes: i };
|
|
88
|
+
}
|
|
89
|
+
const t = e.match(/^(\d{1,2}):(\d{2})$/);
|
|
90
|
+
return t ? { hours: parseInt(t[1], 10), minutes: parseInt(t[2], 10) } : null;
|
|
91
|
+
}
|
|
92
|
+
function x(r, e, s = "24h") {
|
|
93
|
+
const t = String(e).padStart(2, "0");
|
|
94
|
+
if (s === "12h") {
|
|
95
|
+
const a = r >= 12 ? "PM" : "AM";
|
|
96
|
+
return `${r % 12 || 12}:${t} ${a}`;
|
|
97
|
+
}
|
|
98
|
+
return `${String(r).padStart(2, "0")}:${t}`;
|
|
99
|
+
}
|
|
100
|
+
function g(r) {
|
|
101
|
+
const e = k(r);
|
|
102
|
+
return e ? e.hours * 60 + e.minutes : 0;
|
|
103
|
+
}
|
|
104
|
+
function _(r) {
|
|
105
|
+
const e = Math.floor(r / 60) % 24, s = r % 60;
|
|
106
|
+
return `${String(e).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
|
|
107
|
+
}
|
|
108
|
+
function E(r, e, s) {
|
|
109
|
+
const t = [], a = g(r), i = g(e);
|
|
110
|
+
for (let l = a; l <= i; l += s)
|
|
111
|
+
t.push(_(l));
|
|
112
|
+
return t;
|
|
113
|
+
}
|
|
114
|
+
function M(r, e, s, t = "24h") {
|
|
115
|
+
const a = [], i = g(r), l = g(e);
|
|
116
|
+
for (let c = i; c <= l; c += s) {
|
|
117
|
+
const u = _(c), h = c + s, m = _(Math.min(h, l + s)), d = k(u), n = k(m), o = d ? x(d.hours, d.minutes, t) : u, p = n ? x(n.hours, n.minutes, t) : m;
|
|
118
|
+
a.push({ time: u, displayText: `${o}–${p}` });
|
|
119
|
+
}
|
|
120
|
+
return a;
|
|
121
|
+
}
|
|
122
|
+
function T(r, e, s) {
|
|
123
|
+
const t = g(r), a = g(e), i = g(s), l = Math.min(a, i), c = Math.max(a, i);
|
|
124
|
+
return t >= l && t <= c;
|
|
125
|
+
}
|
|
126
|
+
const z = `
|
|
127
|
+
:host {
|
|
128
|
+
/* Light theme (default) */
|
|
129
|
+
--cal-bg: 0 0% 100%;
|
|
130
|
+
--cal-bg-muted: 240 5% 96%;
|
|
131
|
+
--cal-fg: 240 6% 10%;
|
|
132
|
+
--cal-fg-muted: 240 4% 46%;
|
|
133
|
+
--cal-border: 240 6% 90%;
|
|
134
|
+
--cal-accent: 240 6% 10%;
|
|
135
|
+
--cal-accent-fg: 0 0% 100%;
|
|
136
|
+
--cal-accent-subtle: 240 5% 96%;
|
|
137
|
+
--cal-hover: 240 5% 93%;
|
|
138
|
+
--cal-ring: 240 6% 10%;
|
|
139
|
+
--cal-radius: 8px;
|
|
140
|
+
--cal-radius-sm: 6px;
|
|
141
|
+
--cal-cell-size: 36px;
|
|
142
|
+
--cal-transition: 150ms ease;
|
|
143
|
+
|
|
144
|
+
/* Booking color palette (softer / less saturated) */
|
|
145
|
+
--cal-booking-blue-bg: 217 55% 94%;
|
|
146
|
+
--cal-booking-blue-fg: 217 60% 35%;
|
|
147
|
+
--cal-booking-green-bg: 152 45% 93%;
|
|
148
|
+
--cal-booking-green-fg: 152 55% 28%;
|
|
149
|
+
--cal-booking-red-bg: 4 50% 94%;
|
|
150
|
+
--cal-booking-red-fg: 4 55% 40%;
|
|
151
|
+
--cal-booking-orange-bg: 30 55% 93%;
|
|
152
|
+
--cal-booking-orange-fg: 30 60% 35%;
|
|
153
|
+
--cal-booking-gray-bg: 240 8% 94%;
|
|
154
|
+
--cal-booking-gray-fg: 240 8% 38%;
|
|
155
|
+
|
|
156
|
+
/* Booking hover tokens */
|
|
157
|
+
--cal-booking-blue-hover: 217 55% 88%;
|
|
158
|
+
--cal-booking-green-hover: 152 45% 87%;
|
|
159
|
+
--cal-booking-red-hover: 4 50% 88%;
|
|
160
|
+
--cal-booking-orange-hover: 30 55% 87%;
|
|
161
|
+
--cal-booking-gray-hover: 240 8% 88%;
|
|
162
|
+
|
|
163
|
+
/* Scheduler tokens */
|
|
164
|
+
--cal-sched-grid-line: 240 6% 94%;
|
|
165
|
+
--cal-sched-now-line: 4 70% 55%;
|
|
166
|
+
--cal-sched-slot-hover: 240 5% 97%;
|
|
167
|
+
--cal-sched-header-bg: 240 5% 98%;
|
|
168
|
+
|
|
169
|
+
/* Status tokens */
|
|
170
|
+
--cal-status-error-bg: 4 50% 95%;
|
|
171
|
+
--cal-status-error-fg: 4 55% 40%;
|
|
172
|
+
--cal-status-error-border: 4 50% 85%;
|
|
173
|
+
--cal-status-warning-bg: 40 55% 95%;
|
|
174
|
+
--cal-status-warning-fg: 40 60% 35%;
|
|
175
|
+
--cal-status-warning-border: 40 50% 85%;
|
|
176
|
+
--cal-status-info-bg: 217 55% 95%;
|
|
177
|
+
--cal-status-info-fg: 217 60% 35%;
|
|
178
|
+
--cal-status-info-border: 217 50% 85%;
|
|
179
|
+
--cal-status-success-bg: 152 45% 95%;
|
|
180
|
+
--cal-status-success-fg: 152 55% 28%;
|
|
181
|
+
--cal-status-success-border: 152 45% 85%;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
:host([theme="dark"]) {
|
|
185
|
+
--cal-bg: 240 6% 10%;
|
|
186
|
+
--cal-bg-muted: 240 4% 16%;
|
|
187
|
+
--cal-fg: 0 0% 98%;
|
|
188
|
+
--cal-fg-muted: 240 4% 54%;
|
|
189
|
+
--cal-border: 240 4% 20%;
|
|
190
|
+
--cal-accent: 0 0% 98%;
|
|
191
|
+
--cal-accent-fg: 240 6% 10%;
|
|
192
|
+
--cal-accent-subtle: 240 4% 16%;
|
|
193
|
+
--cal-hover: 240 4% 20%;
|
|
194
|
+
--cal-ring: 0 0% 98%;
|
|
195
|
+
|
|
196
|
+
--cal-booking-blue-bg: 217 50% 25%;
|
|
197
|
+
--cal-booking-blue-fg: 217 80% 75%;
|
|
198
|
+
--cal-booking-green-bg: 142 40% 22%;
|
|
199
|
+
--cal-booking-green-fg: 142 70% 70%;
|
|
200
|
+
--cal-booking-red-bg: 4 45% 25%;
|
|
201
|
+
--cal-booking-red-fg: 4 70% 75%;
|
|
202
|
+
--cal-booking-orange-bg: 30 45% 25%;
|
|
203
|
+
--cal-booking-orange-fg: 30 80% 75%;
|
|
204
|
+
--cal-booking-gray-bg: 240 5% 22%;
|
|
205
|
+
--cal-booking-gray-fg: 240 5% 65%;
|
|
206
|
+
|
|
207
|
+
--cal-booking-blue-hover: 217 50% 30%;
|
|
208
|
+
--cal-booking-green-hover: 142 40% 27%;
|
|
209
|
+
--cal-booking-red-hover: 4 45% 30%;
|
|
210
|
+
--cal-booking-orange-hover: 30 45% 30%;
|
|
211
|
+
--cal-booking-gray-hover: 240 5% 27%;
|
|
212
|
+
|
|
213
|
+
--cal-sched-grid-line: 240 4% 18%;
|
|
214
|
+
--cal-sched-now-line: 4 55% 55%;
|
|
215
|
+
--cal-sched-slot-hover: 240 4% 14%;
|
|
216
|
+
--cal-sched-header-bg: 240 5% 12%;
|
|
217
|
+
|
|
218
|
+
--cal-status-error-bg: 4 45% 20%;
|
|
219
|
+
--cal-status-error-fg: 4 70% 75%;
|
|
220
|
+
--cal-status-error-border: 4 45% 30%;
|
|
221
|
+
--cal-status-warning-bg: 40 45% 20%;
|
|
222
|
+
--cal-status-warning-fg: 40 80% 75%;
|
|
223
|
+
--cal-status-warning-border: 40 45% 30%;
|
|
224
|
+
--cal-status-info-bg: 217 50% 20%;
|
|
225
|
+
--cal-status-info-fg: 217 80% 75%;
|
|
226
|
+
--cal-status-info-border: 217 50% 30%;
|
|
227
|
+
--cal-status-success-bg: 152 40% 18%;
|
|
228
|
+
--cal-status-success-fg: 152 70% 70%;
|
|
229
|
+
--cal-status-success-border: 152 40% 28%;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
:host([theme="auto"]) {
|
|
233
|
+
--cal-bg: 0 0% 100%;
|
|
234
|
+
--cal-bg-muted: 240 5% 96%;
|
|
235
|
+
--cal-fg: 240 6% 10%;
|
|
236
|
+
--cal-fg-muted: 240 4% 46%;
|
|
237
|
+
--cal-border: 240 6% 90%;
|
|
238
|
+
--cal-accent: 240 6% 10%;
|
|
239
|
+
--cal-accent-fg: 0 0% 100%;
|
|
240
|
+
--cal-accent-subtle: 240 5% 96%;
|
|
241
|
+
--cal-hover: 240 5% 93%;
|
|
242
|
+
--cal-ring: 240 6% 10%;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@media (prefers-color-scheme: dark) {
|
|
246
|
+
:host([theme="auto"]) {
|
|
247
|
+
--cal-bg: 240 6% 10%;
|
|
248
|
+
--cal-bg-muted: 240 4% 16%;
|
|
249
|
+
--cal-fg: 0 0% 98%;
|
|
250
|
+
--cal-fg-muted: 240 4% 54%;
|
|
251
|
+
--cal-border: 240 4% 20%;
|
|
252
|
+
--cal-accent: 0 0% 98%;
|
|
253
|
+
--cal-accent-fg: 240 6% 10%;
|
|
254
|
+
--cal-accent-subtle: 240 4% 16%;
|
|
255
|
+
--cal-hover: 240 4% 20%;
|
|
256
|
+
--cal-ring: 0 0% 98%;
|
|
257
|
+
|
|
258
|
+
--cal-booking-blue-bg: 217 50% 25%;
|
|
259
|
+
--cal-booking-blue-fg: 217 80% 75%;
|
|
260
|
+
--cal-booking-green-bg: 142 40% 22%;
|
|
261
|
+
--cal-booking-green-fg: 142 70% 70%;
|
|
262
|
+
--cal-booking-red-bg: 4 45% 25%;
|
|
263
|
+
--cal-booking-red-fg: 4 70% 75%;
|
|
264
|
+
--cal-booking-orange-bg: 30 45% 25%;
|
|
265
|
+
--cal-booking-orange-fg: 30 80% 75%;
|
|
266
|
+
--cal-booking-gray-bg: 240 5% 22%;
|
|
267
|
+
--cal-booking-gray-fg: 240 5% 65%;
|
|
268
|
+
|
|
269
|
+
--cal-booking-blue-hover: 217 50% 30%;
|
|
270
|
+
--cal-booking-green-hover: 142 40% 27%;
|
|
271
|
+
--cal-booking-red-hover: 4 45% 30%;
|
|
272
|
+
--cal-booking-orange-hover: 30 45% 30%;
|
|
273
|
+
--cal-booking-gray-hover: 240 5% 27%;
|
|
274
|
+
|
|
275
|
+
--cal-sched-grid-line: 240 4% 18%;
|
|
276
|
+
--cal-sched-now-line: 4 55% 55%;
|
|
277
|
+
--cal-sched-slot-hover: 240 4% 14%;
|
|
278
|
+
--cal-sched-header-bg: 240 5% 12%;
|
|
279
|
+
|
|
280
|
+
--cal-status-error-bg: 4 45% 20%;
|
|
281
|
+
--cal-status-error-fg: 4 70% 75%;
|
|
282
|
+
--cal-status-error-border: 4 45% 30%;
|
|
283
|
+
--cal-status-warning-bg: 40 45% 20%;
|
|
284
|
+
--cal-status-warning-fg: 40 80% 75%;
|
|
285
|
+
--cal-status-warning-border: 40 45% 30%;
|
|
286
|
+
--cal-status-info-bg: 217 50% 20%;
|
|
287
|
+
--cal-status-info-fg: 217 80% 75%;
|
|
288
|
+
--cal-status-info-border: 217 50% 30%;
|
|
289
|
+
--cal-status-success-bg: 152 40% 18%;
|
|
290
|
+
--cal-status-success-fg: 152 70% 70%;
|
|
291
|
+
--cal-status-success-border: 152 40% 28%;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
`, $ = `
|
|
295
|
+
:host {
|
|
296
|
+
display: inline-block;
|
|
297
|
+
font-family: inherit;
|
|
298
|
+
font-size: 14px;
|
|
299
|
+
line-height: 1.5;
|
|
300
|
+
color: hsl(var(--cal-fg));
|
|
301
|
+
-webkit-font-smoothing: antialiased;
|
|
302
|
+
-moz-osx-font-smoothing: grayscale;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
:host([display="inline"]) {
|
|
306
|
+
display: inline-block;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
*,
|
|
310
|
+
*::before,
|
|
311
|
+
*::after {
|
|
312
|
+
box-sizing: border-box;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
button {
|
|
316
|
+
font: inherit;
|
|
317
|
+
color: inherit;
|
|
318
|
+
background: none;
|
|
319
|
+
border: none;
|
|
320
|
+
padding: 0;
|
|
321
|
+
margin: 0;
|
|
322
|
+
cursor: pointer;
|
|
323
|
+
-webkit-tap-highlight-color: transparent;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
button:focus-visible {
|
|
327
|
+
outline: 2px solid hsl(var(--cal-ring));
|
|
328
|
+
outline-offset: 2px;
|
|
329
|
+
border-radius: var(--cal-radius-sm);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
[hidden] {
|
|
333
|
+
display: none !important;
|
|
334
|
+
}
|
|
335
|
+
`, B = `
|
|
336
|
+
@keyframes cal-fade-in {
|
|
337
|
+
from { opacity: 0; }
|
|
338
|
+
to { opacity: 1; }
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
@keyframes cal-slide-up {
|
|
342
|
+
from {
|
|
343
|
+
opacity: 0;
|
|
344
|
+
transform: translateY(4px);
|
|
345
|
+
}
|
|
346
|
+
to {
|
|
347
|
+
opacity: 1;
|
|
348
|
+
transform: translateY(0);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@keyframes cal-slide-left {
|
|
353
|
+
from {
|
|
354
|
+
opacity: 0;
|
|
355
|
+
transform: translateX(16px);
|
|
356
|
+
}
|
|
357
|
+
to {
|
|
358
|
+
opacity: 1;
|
|
359
|
+
transform: translateX(0);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
@keyframes cal-slide-right {
|
|
364
|
+
from {
|
|
365
|
+
opacity: 0;
|
|
366
|
+
transform: translateX(-16px);
|
|
367
|
+
}
|
|
368
|
+
to {
|
|
369
|
+
opacity: 1;
|
|
370
|
+
transform: translateX(0);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.cal-animate-fade { animation: cal-fade-in 150ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
375
|
+
.cal-animate-slide-up { animation: cal-slide-up 200ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
376
|
+
.cal-animate-slide-left { animation: cal-slide-left 200ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
377
|
+
.cal-animate-slide-right { animation: cal-slide-right 200ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
378
|
+
|
|
379
|
+
@keyframes cal-shimmer {
|
|
380
|
+
0% { background-position: -200% 0; }
|
|
381
|
+
100% { background-position: 200% 0; }
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.cal-skeleton {
|
|
385
|
+
background: linear-gradient(
|
|
386
|
+
90deg,
|
|
387
|
+
hsl(var(--cal-bg-muted)) 25%,
|
|
388
|
+
hsl(var(--cal-hover)) 50%,
|
|
389
|
+
hsl(var(--cal-bg-muted)) 75%
|
|
390
|
+
);
|
|
391
|
+
background-size: 200% 100%;
|
|
392
|
+
animation: cal-shimmer 1.5s infinite ease-in-out;
|
|
393
|
+
border-radius: 999px;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.cal-skeleton--rect {
|
|
397
|
+
border-radius: var(--cal-radius-sm);
|
|
398
|
+
}
|
|
399
|
+
`;
|
|
400
|
+
function O({ trigger: r, content: e, onClose: s }) {
|
|
401
|
+
const t = document.createElement("div");
|
|
402
|
+
t.classList.add("cal-popover"), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "false"), t.style.display = "none", t.appendChild(e);
|
|
403
|
+
let a = !1;
|
|
404
|
+
function i() {
|
|
405
|
+
t.classList.remove("cal-popover--above");
|
|
406
|
+
const d = r.getBoundingClientRect(), n = t.offsetHeight, o = window.innerHeight - d.bottom, p = d.top;
|
|
407
|
+
o < n + 8 && p > o ? (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");
|
|
408
|
+
}
|
|
409
|
+
function l() {
|
|
410
|
+
a || (a = !0, t.style.display = "", t.classList.add("cal-animate-slide-up"), requestAnimationFrame(() => i()), document.addEventListener("click", u, !0), document.addEventListener("keydown", h, !0));
|
|
411
|
+
}
|
|
412
|
+
function c() {
|
|
413
|
+
a && (a = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up"), document.removeEventListener("click", u, !0), document.removeEventListener("keydown", h, !0), s == null || s());
|
|
414
|
+
}
|
|
415
|
+
function u(d) {
|
|
416
|
+
var o;
|
|
417
|
+
const n = (o = r.getRootNode()) == null ? void 0 : o.host;
|
|
418
|
+
n && !n.contains(d.target) && d.target !== n && c();
|
|
419
|
+
}
|
|
420
|
+
function h(d) {
|
|
421
|
+
d.key === "Escape" && (d.stopPropagation(), c());
|
|
422
|
+
}
|
|
423
|
+
function m() {
|
|
424
|
+
a && (a = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up")), document.removeEventListener("click", u, !0), document.removeEventListener("keydown", h, !0);
|
|
425
|
+
}
|
|
426
|
+
return { panel: t, open: l, close: c, destroy: m, get isOpen() {
|
|
427
|
+
return a;
|
|
428
|
+
} };
|
|
429
|
+
}
|
|
430
|
+
const R = `
|
|
431
|
+
.cal-popover-wrapper {
|
|
432
|
+
position: relative;
|
|
433
|
+
display: inline-block;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.cal-popover {
|
|
437
|
+
position: absolute;
|
|
438
|
+
left: 0;
|
|
439
|
+
z-index: 50;
|
|
440
|
+
background: hsl(var(--cal-bg));
|
|
441
|
+
border: 1px solid hsl(var(--cal-border));
|
|
442
|
+
border-radius: var(--cal-radius);
|
|
443
|
+
box-shadow: 0 4px 16px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -2px rgba(0, 0, 0, 0.04);
|
|
444
|
+
padding: 12px;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.cal-trigger {
|
|
448
|
+
display: inline-flex;
|
|
449
|
+
align-items: center;
|
|
450
|
+
gap: 8px;
|
|
451
|
+
height: 36px;
|
|
452
|
+
padding: 0 12px;
|
|
453
|
+
font-size: 14px;
|
|
454
|
+
border: 1px solid hsl(var(--cal-border));
|
|
455
|
+
border-radius: var(--cal-radius-sm);
|
|
456
|
+
background: hsl(var(--cal-bg));
|
|
457
|
+
color: hsl(var(--cal-fg));
|
|
458
|
+
cursor: pointer;
|
|
459
|
+
transition: border-color var(--cal-transition);
|
|
460
|
+
white-space: nowrap;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.cal-trigger:hover {
|
|
464
|
+
border-color: hsl(var(--cal-fg-muted));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.cal-trigger--placeholder {
|
|
468
|
+
color: hsl(var(--cal-fg-muted));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.cal-trigger__icon {
|
|
472
|
+
display: flex;
|
|
473
|
+
color: hsl(var(--cal-fg-muted));
|
|
474
|
+
}
|
|
475
|
+
`;
|
|
476
|
+
function j(r) {
|
|
477
|
+
const {
|
|
478
|
+
slots: e = [],
|
|
479
|
+
mode: s = "single",
|
|
480
|
+
format: t = "24h",
|
|
481
|
+
selected: a,
|
|
482
|
+
hoverTime: i,
|
|
483
|
+
rangeStart: l,
|
|
484
|
+
unavailableTimes: c = [],
|
|
485
|
+
onSelect: u,
|
|
486
|
+
onHover: h,
|
|
487
|
+
durationLabels: m = !1
|
|
488
|
+
} = r, d = document.createElement("div");
|
|
489
|
+
d.classList.add("cal-time-grid"), m && d.classList.add("cal-time-grid--duration"), d.setAttribute("role", "listbox"), s === "multi" && d.setAttribute("aria-multiselectable", "true");
|
|
490
|
+
for (const n of e) {
|
|
491
|
+
const o = document.createElement("button");
|
|
492
|
+
o.classList.add("cal-time-slot"), o.setAttribute("role", "option"), o.dataset.time = n.time;
|
|
493
|
+
const p = k(n.time), L = n.displayText ? n.displayText : p ? x(p.hours, p.minutes, t) : n.time, y = document.createElement("span");
|
|
494
|
+
if (y.classList.add("cal-time-slot__time"), y.textContent = L, o.appendChild(y), n.label) {
|
|
495
|
+
const b = document.createElement("span");
|
|
496
|
+
b.classList.add("cal-time-slot__label"), b.textContent = n.label, o.appendChild(b);
|
|
497
|
+
}
|
|
498
|
+
const S = n.available === !1 || c.includes(n.time);
|
|
499
|
+
if (S && (o.classList.add("cal-time-slot--unavailable"), o.disabled = !0, o.setAttribute("aria-disabled", "true")), H(n.time, a, s) ? (o.classList.add("cal-time-slot--selected"), o.setAttribute("aria-selected", "true")) : o.setAttribute("aria-selected", "false"), s === "range" && l && !I(a) && i) {
|
|
500
|
+
const b = T(n.time, l, i), f = n.time === l, v = n.time === i;
|
|
501
|
+
b && !f && !v && o.classList.add("cal-time-slot--in-range"), f && o.classList.add("cal-time-slot--range-start"), v && o.classList.add("cal-time-slot--range-end");
|
|
502
|
+
} else if (s === "range" && a && typeof a == "object" && a.start && a.end) {
|
|
503
|
+
const b = T(n.time, a.start, a.end), f = n.time === a.start, v = n.time === a.end;
|
|
504
|
+
f && o.classList.add("cal-time-slot--range-start", "cal-time-slot--selected"), v && o.classList.add("cal-time-slot--range-end", "cal-time-slot--selected"), b && !f && !v && o.classList.add("cal-time-slot--in-range");
|
|
505
|
+
}
|
|
506
|
+
S || (o.addEventListener("click", () => u == null ? void 0 : u(n.time)), o.addEventListener("mouseenter", () => h == null ? void 0 : h(n.time))), d.appendChild(o);
|
|
507
|
+
}
|
|
508
|
+
return d.addEventListener("mouseleave", () => h == null ? void 0 : h(null)), d;
|
|
509
|
+
}
|
|
510
|
+
function H(r, e, s) {
|
|
511
|
+
return e ? s === "single" ? e === r : s === "multi" ? Array.isArray(e) && e.includes(r) : s === "range" && typeof e == "object" && e.start && e.end ? e.start === r || e.end === r : !1 : !1;
|
|
512
|
+
}
|
|
513
|
+
function I(r) {
|
|
514
|
+
return r && typeof r == "object" && r.start && r.end;
|
|
515
|
+
}
|
|
516
|
+
const P = `
|
|
517
|
+
.cal-time-grid {
|
|
518
|
+
display: grid;
|
|
519
|
+
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
520
|
+
gap: 6px;
|
|
521
|
+
max-height: 280px;
|
|
522
|
+
overflow-y: auto;
|
|
523
|
+
padding: 4px;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
.cal-time-grid::-webkit-scrollbar {
|
|
527
|
+
width: 6px;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.cal-time-grid::-webkit-scrollbar-track {
|
|
531
|
+
background: transparent;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.cal-time-grid::-webkit-scrollbar-thumb {
|
|
535
|
+
background: hsl(var(--cal-border));
|
|
536
|
+
border-radius: 3px;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
.cal-time-slot {
|
|
540
|
+
display: flex;
|
|
541
|
+
flex-direction: column;
|
|
542
|
+
align-items: center;
|
|
543
|
+
justify-content: center;
|
|
544
|
+
height: 40px;
|
|
545
|
+
padding: 0 8px;
|
|
546
|
+
border-radius: 999px;
|
|
547
|
+
font-size: 13px;
|
|
548
|
+
background: hsl(var(--cal-bg-muted));
|
|
549
|
+
color: hsl(var(--cal-fg));
|
|
550
|
+
transition: background var(--cal-transition), color var(--cal-transition);
|
|
551
|
+
gap: 1px;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
.cal-time-slot:not(.cal-time-slot--unavailable):not(.cal-time-slot--selected):hover {
|
|
555
|
+
background: hsl(var(--cal-hover));
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.cal-time-slot__time {
|
|
559
|
+
font-weight: 500;
|
|
560
|
+
line-height: 1;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.cal-time-slot__label {
|
|
564
|
+
font-size: 9px;
|
|
565
|
+
opacity: 0.7;
|
|
566
|
+
line-height: 1;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
.cal-time-slot--selected {
|
|
570
|
+
background: hsl(var(--cal-accent));
|
|
571
|
+
color: hsl(var(--cal-accent-fg));
|
|
572
|
+
font-weight: 600;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
.cal-time-slot--in-range {
|
|
576
|
+
background: hsl(var(--cal-accent-subtle));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
.cal-time-slot--range-start,
|
|
580
|
+
.cal-time-slot--range-end {
|
|
581
|
+
background: hsl(var(--cal-accent));
|
|
582
|
+
color: hsl(var(--cal-accent-fg));
|
|
583
|
+
font-weight: 600;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.cal-time-slot--unavailable {
|
|
587
|
+
opacity: 0.3;
|
|
588
|
+
cursor: not-allowed;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
.cal-time-grid--duration {
|
|
592
|
+
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
.cal-time-grid--duration .cal-time-slot {
|
|
596
|
+
font-size: 12px;
|
|
597
|
+
}
|
|
598
|
+
`;
|
|
599
|
+
function D({ columns: r = 3, rows: e = 4, durationLabels: s = !1 } = {}) {
|
|
600
|
+
const t = document.createElement("div");
|
|
601
|
+
t.setAttribute("role", "status"), t.setAttribute("aria-label", "Loading..."), t.classList.add("cal-skeleton-time-grid"), s && t.classList.add("cal-skeleton-time-grid--duration");
|
|
602
|
+
const a = r * e;
|
|
603
|
+
for (let i = 0; i < a; i++) {
|
|
604
|
+
const l = document.createElement("div");
|
|
605
|
+
l.classList.add("cal-skeleton"), t.appendChild(l);
|
|
606
|
+
}
|
|
607
|
+
return t;
|
|
608
|
+
}
|
|
609
|
+
const X = `
|
|
610
|
+
.cal-skeleton-time-grid {
|
|
611
|
+
display: grid;
|
|
612
|
+
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
613
|
+
gap: 6px;
|
|
614
|
+
padding: 4px;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.cal-skeleton-time-grid--duration {
|
|
618
|
+
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
.cal-skeleton-time-grid .cal-skeleton {
|
|
622
|
+
height: 40px;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
.cal-skeleton-calendar-grid {
|
|
626
|
+
display: grid;
|
|
627
|
+
grid-template-columns: repeat(7, 1fr);
|
|
628
|
+
gap: 2px;
|
|
629
|
+
padding: 4px;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.cal-skeleton-calendar-grid__header {
|
|
633
|
+
height: 20px;
|
|
634
|
+
margin-bottom: 4px;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
.cal-skeleton-calendar-grid__day {
|
|
638
|
+
height: var(--cal-cell-size, 36px);
|
|
639
|
+
aspect-ratio: 1;
|
|
640
|
+
border-radius: var(--cal-radius-sm) !important;
|
|
641
|
+
}
|
|
642
|
+
`, w = {
|
|
643
|
+
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>',
|
|
644
|
+
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>',
|
|
645
|
+
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>',
|
|
646
|
+
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>'
|
|
647
|
+
};
|
|
648
|
+
function q({ type: r = "info", message: e, dismissible: s = !0, onDismiss: t }) {
|
|
649
|
+
const a = document.createElement("div");
|
|
650
|
+
a.classList.add("cal-status", `cal-status--${r}`, "cal-animate-slide-up"), a.setAttribute("role", r === "error" ? "alert" : "status"), a.setAttribute("aria-live", r === "error" ? "assertive" : "polite");
|
|
651
|
+
const i = document.createElement("span");
|
|
652
|
+
i.classList.add("cal-status__icon"), i.innerHTML = w[r] || w.info, a.appendChild(i);
|
|
653
|
+
const l = document.createElement("span");
|
|
654
|
+
if (l.classList.add("cal-status__text"), l.textContent = e, a.appendChild(l), s) {
|
|
655
|
+
const c = document.createElement("button");
|
|
656
|
+
c.classList.add("cal-status__close"), c.setAttribute("aria-label", "Dismiss"), c.innerHTML = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 3l6 6M9 3l-6 6"/></svg>', c.addEventListener("click", () => t == null ? void 0 : t()), a.appendChild(c);
|
|
657
|
+
}
|
|
658
|
+
return a;
|
|
659
|
+
}
|
|
660
|
+
const G = `
|
|
661
|
+
.cal-status {
|
|
662
|
+
display: flex;
|
|
663
|
+
align-items: center;
|
|
664
|
+
gap: 8px;
|
|
665
|
+
padding: 8px 12px;
|
|
666
|
+
border-radius: var(--cal-radius-sm);
|
|
667
|
+
font-size: 12px;
|
|
668
|
+
line-height: 1.4;
|
|
669
|
+
margin-bottom: 8px;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.cal-status__icon {
|
|
673
|
+
flex-shrink: 0;
|
|
674
|
+
display: flex;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
.cal-status__text {
|
|
678
|
+
flex: 1;
|
|
679
|
+
min-width: 0;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
.cal-status__close {
|
|
683
|
+
flex-shrink: 0;
|
|
684
|
+
display: flex;
|
|
685
|
+
align-items: center;
|
|
686
|
+
justify-content: center;
|
|
687
|
+
width: 20px;
|
|
688
|
+
height: 20px;
|
|
689
|
+
border-radius: 4px;
|
|
690
|
+
cursor: pointer;
|
|
691
|
+
opacity: 0.7;
|
|
692
|
+
transition: opacity var(--cal-transition);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
.cal-status__close:hover {
|
|
696
|
+
opacity: 1;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
.cal-status--error {
|
|
700
|
+
background: hsl(var(--cal-status-error-bg));
|
|
701
|
+
color: hsl(var(--cal-status-error-fg));
|
|
702
|
+
border: 1px solid hsl(var(--cal-status-error-border));
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
.cal-status--warning {
|
|
706
|
+
background: hsl(var(--cal-status-warning-bg));
|
|
707
|
+
color: hsl(var(--cal-status-warning-fg));
|
|
708
|
+
border: 1px solid hsl(var(--cal-status-warning-border));
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.cal-status--info {
|
|
712
|
+
background: hsl(var(--cal-status-info-bg));
|
|
713
|
+
color: hsl(var(--cal-status-info-fg));
|
|
714
|
+
border: 1px solid hsl(var(--cal-status-info-border));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
.cal-status--success {
|
|
718
|
+
background: hsl(var(--cal-status-success-bg));
|
|
719
|
+
color: hsl(var(--cal-status-success-fg));
|
|
720
|
+
border: 1px solid hsl(var(--cal-status-success-border));
|
|
721
|
+
}
|
|
722
|
+
`, N = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="8" cy="8" r="6"/><path d="M8 4.5V8l2.5 1.5"/></svg>', Y = `
|
|
723
|
+
.cal-timepicker {
|
|
724
|
+
background: hsl(var(--cal-bg));
|
|
725
|
+
border-radius: var(--cal-radius);
|
|
726
|
+
user-select: none;
|
|
727
|
+
min-width: 200px;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
:host([display="inline"]) .cal-timepicker {
|
|
731
|
+
border: 1px solid hsl(var(--cal-border));
|
|
732
|
+
padding: 12px;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.cal-timepicker__header {
|
|
736
|
+
font-size: 14px;
|
|
737
|
+
font-weight: 600;
|
|
738
|
+
color: hsl(var(--cal-fg));
|
|
739
|
+
margin-bottom: 8px;
|
|
740
|
+
padding: 0 4px;
|
|
741
|
+
}
|
|
742
|
+
`;
|
|
743
|
+
class U extends C {
|
|
744
|
+
static get styles() {
|
|
745
|
+
return [z, $, B, P, R, X, G, Y];
|
|
746
|
+
}
|
|
747
|
+
static get observedAttributes() {
|
|
748
|
+
return ["mode", "display", "theme", "start-time", "end-time", "interval", "format", "placeholder", "value", "duration-labels", "loading"];
|
|
749
|
+
}
|
|
750
|
+
constructor() {
|
|
751
|
+
super(), this._store = A({
|
|
752
|
+
selected: null,
|
|
753
|
+
// string | string[] | {start, end}
|
|
754
|
+
rangeStart: null,
|
|
755
|
+
// for range mode in-progress
|
|
756
|
+
hoverTime: null,
|
|
757
|
+
isOpen: !1,
|
|
758
|
+
statusType: null,
|
|
759
|
+
statusMessage: null,
|
|
760
|
+
statusDismissible: !0
|
|
761
|
+
}), this._slots = null, this._unavailableTimes = [], this._popover = null, this._unsubscribe = null, this._rendering = !1;
|
|
762
|
+
}
|
|
763
|
+
// -- Attribute getters --
|
|
764
|
+
get mode() {
|
|
765
|
+
return this.getAttribute("mode") || "single";
|
|
766
|
+
}
|
|
767
|
+
get display() {
|
|
768
|
+
return this.getAttribute("display") || "inline";
|
|
769
|
+
}
|
|
770
|
+
get placeholder() {
|
|
771
|
+
return this.getAttribute("placeholder") || "Select time";
|
|
772
|
+
}
|
|
773
|
+
get startTime() {
|
|
774
|
+
return this.getAttribute("start-time") || "09:00";
|
|
775
|
+
}
|
|
776
|
+
get endTime() {
|
|
777
|
+
return this.getAttribute("end-time") || "17:00";
|
|
778
|
+
}
|
|
779
|
+
get interval() {
|
|
780
|
+
return parseInt(this.getAttribute("interval") || "30", 10);
|
|
781
|
+
}
|
|
782
|
+
get format() {
|
|
783
|
+
return this.getAttribute("format") || "24h";
|
|
784
|
+
}
|
|
785
|
+
get durationLabels() {
|
|
786
|
+
return this.hasAttribute("duration-labels");
|
|
787
|
+
}
|
|
788
|
+
get loading() {
|
|
789
|
+
return this.hasAttribute("loading");
|
|
790
|
+
}
|
|
791
|
+
set loading(e) {
|
|
792
|
+
e ? this.setAttribute("loading", "") : this.removeAttribute("loading");
|
|
793
|
+
}
|
|
794
|
+
// -- Properties --
|
|
795
|
+
get slots() {
|
|
796
|
+
return this._slots;
|
|
797
|
+
}
|
|
798
|
+
set slots(e) {
|
|
799
|
+
this._slots = Array.isArray(e) ? e : null, this._initialized && this.render();
|
|
800
|
+
}
|
|
801
|
+
get unavailableTimes() {
|
|
802
|
+
return this._unavailableTimes;
|
|
803
|
+
}
|
|
804
|
+
set unavailableTimes(e) {
|
|
805
|
+
this._unavailableTimes = Array.isArray(e) ? e : [], this._initialized && this.render();
|
|
806
|
+
}
|
|
807
|
+
get value() {
|
|
808
|
+
return this._store.getState().selected;
|
|
809
|
+
}
|
|
810
|
+
set value(e) {
|
|
811
|
+
this.mode === "single" && typeof e == "string" ? this._store.set({ selected: e, rangeStart: null }) : this.mode === "multi" && Array.isArray(e) ? this._store.set({ selected: [...e].sort((s, t) => g(s) - g(t)), rangeStart: null }) : this.mode === "range" && e && typeof e == "object" ? this._store.set({ selected: { start: e.start, end: e.end }, rangeStart: null }) : this._store.set({ selected: null, rangeStart: null });
|
|
812
|
+
}
|
|
813
|
+
_getEffectiveSlots() {
|
|
814
|
+
return this._slots ? this._slots : this.durationLabels ? M(this.startTime, this.endTime, this.interval, this.format).map((t) => ({
|
|
815
|
+
...t,
|
|
816
|
+
available: !this._unavailableTimes.includes(t.time)
|
|
817
|
+
})) : E(this.startTime, this.endTime, this.interval).map((s) => ({
|
|
818
|
+
time: s,
|
|
819
|
+
available: !this._unavailableTimes.includes(s)
|
|
820
|
+
}));
|
|
821
|
+
}
|
|
822
|
+
connectedCallback() {
|
|
823
|
+
super.connectedCallback(), this._unsubscribe = this._store.subscribe((s, t) => {
|
|
824
|
+
if (this._rendering) return;
|
|
825
|
+
s.hoverTime !== t.hoverTime && s.selected === t.selected && s.rangeStart === t.rangeStart && s.isOpen === t.isOpen ? this._updateSlotHighlight(s) : this.render();
|
|
826
|
+
});
|
|
827
|
+
const e = this.getAttribute("value");
|
|
828
|
+
if (e)
|
|
829
|
+
if (this.mode === "multi" && e.includes(","))
|
|
830
|
+
this.value = e.split(",").map((s) => s.trim());
|
|
831
|
+
else if (this.mode === "range" && e.includes("/")) {
|
|
832
|
+
const [s, t] = e.split("/");
|
|
833
|
+
this.value = { start: s.trim(), end: t.trim() };
|
|
834
|
+
} else
|
|
835
|
+
this.value = e;
|
|
836
|
+
}
|
|
837
|
+
disconnectedCallback() {
|
|
838
|
+
var e, s;
|
|
839
|
+
(e = this._unsubscribe) == null || e.call(this), (s = this._popover) == null || s.destroy(), clearTimeout(this._statusTimer);
|
|
840
|
+
}
|
|
841
|
+
attributeChangedCallback(e, s, t) {
|
|
842
|
+
if (s !== t) {
|
|
843
|
+
if (e === "value" && this._initialized)
|
|
844
|
+
if (this.mode === "multi" && t && t.includes(","))
|
|
845
|
+
this.value = t.split(",").map((a) => a.trim());
|
|
846
|
+
else if (this.mode === "range" && t && t.includes("/")) {
|
|
847
|
+
const [a, i] = t.split("/");
|
|
848
|
+
this.value = { start: a.trim(), end: i.trim() };
|
|
849
|
+
} else
|
|
850
|
+
this.value = t;
|
|
851
|
+
this._initialized && this.render();
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
// -- Selection --
|
|
855
|
+
_handleSelect(e) {
|
|
856
|
+
const s = this._store.getState();
|
|
857
|
+
if (this.mode === "single")
|
|
858
|
+
this._store.set({ selected: e }), this.emit("cal:time-change", { value: e }), this.display === "popover" && this.close();
|
|
859
|
+
else if (this.mode === "multi") {
|
|
860
|
+
const t = Array.isArray(s.selected) ? [...s.selected] : [], a = t.indexOf(e);
|
|
861
|
+
a >= 0 ? t.splice(a, 1) : t.push(e), t.sort((i, l) => g(i) - g(l)), this._store.set({ selected: t }), this.emit("cal:time-change", { value: t });
|
|
862
|
+
} else if (this.mode === "range")
|
|
863
|
+
if (!s.rangeStart || s.selected && typeof s.selected == "object" && s.selected.start && s.selected.end)
|
|
864
|
+
this._store.set({ rangeStart: e, selected: null, hoverTime: null });
|
|
865
|
+
else {
|
|
866
|
+
let t = s.rangeStart, a = e;
|
|
867
|
+
g(t) > g(a) && ([t, a] = [a, t]);
|
|
868
|
+
const i = { start: t, end: a };
|
|
869
|
+
this._store.set({ selected: i, rangeStart: null, hoverTime: null }), this.emit("cal:time-change", { value: i }), this.display === "popover" && this.close();
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
_handleHover(e) {
|
|
873
|
+
this.mode === "range" && this._store.set({ hoverTime: e });
|
|
874
|
+
}
|
|
875
|
+
// -- Lightweight hover highlight --
|
|
876
|
+
_updateSlotHighlight(e) {
|
|
877
|
+
const s = this.$$(".cal-time-slot"), { rangeStart: t, hoverTime: a, selected: i } = e, l = i && typeof i == "object" && i.start && i.end;
|
|
878
|
+
for (const c of s) {
|
|
879
|
+
const u = c.dataset.time;
|
|
880
|
+
if (!(!u || c.disabled))
|
|
881
|
+
if (t && !l && a) {
|
|
882
|
+
const h = g(t) < g(a) ? t : a, m = g(t) < g(a) ? a : t, d = g(u), n = d > g(h) && d < g(m), o = u === t, p = u === a;
|
|
883
|
+
c.classList.toggle("cal-time-slot--range-start", o), c.classList.toggle("cal-time-slot--range-end", p), c.classList.toggle("cal-time-slot--in-range", n);
|
|
884
|
+
} else t || c.classList.remove("cal-time-slot--range-start", "cal-time-slot--range-end", "cal-time-slot--in-range");
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
// -- Public API --
|
|
888
|
+
open() {
|
|
889
|
+
this._popover && (this._popover.open(), this._store.set({ isOpen: !0 }), this.emit("cal:open"));
|
|
890
|
+
}
|
|
891
|
+
close() {
|
|
892
|
+
this._popover && (this._popover.close(), this._store.set({ isOpen: !1 }), this.emit("cal:close"));
|
|
893
|
+
}
|
|
894
|
+
// -- Render --
|
|
895
|
+
_renderTimepickerContent() {
|
|
896
|
+
const e = this._store.getState(), s = document.createElement("div");
|
|
897
|
+
s.classList.add("cal-timepicker"), e.statusType && e.statusMessage && s.appendChild(q({
|
|
898
|
+
type: e.statusType,
|
|
899
|
+
message: e.statusMessage,
|
|
900
|
+
dismissible: e.statusDismissible,
|
|
901
|
+
onDismiss: () => this.clearStatus()
|
|
902
|
+
}));
|
|
903
|
+
const t = document.createElement("div");
|
|
904
|
+
if (t.classList.add("cal-timepicker__header"), t.textContent = "Select Time", s.appendChild(t), this.loading)
|
|
905
|
+
s.appendChild(D({ durationLabels: this.durationLabels }));
|
|
906
|
+
else {
|
|
907
|
+
const a = this._getEffectiveSlots(), i = j({
|
|
908
|
+
slots: a,
|
|
909
|
+
mode: this.mode,
|
|
910
|
+
format: this.format,
|
|
911
|
+
selected: e.selected,
|
|
912
|
+
hoverTime: e.hoverTime,
|
|
913
|
+
rangeStart: e.rangeStart,
|
|
914
|
+
unavailableTimes: this._unavailableTimes,
|
|
915
|
+
onSelect: (l) => this._handleSelect(l),
|
|
916
|
+
onHover: (l) => this._handleHover(l),
|
|
917
|
+
durationLabels: this.durationLabels
|
|
918
|
+
});
|
|
919
|
+
s.appendChild(i);
|
|
920
|
+
}
|
|
921
|
+
return s;
|
|
922
|
+
}
|
|
923
|
+
_formatTriggerText() {
|
|
924
|
+
const e = this._store.getState();
|
|
925
|
+
return e.selected ? this.mode === "single" && typeof e.selected == "string" ? e.selected : this.mode === "multi" && Array.isArray(e.selected) && e.selected.length ? `${e.selected.length} time${e.selected.length > 1 ? "s" : ""} selected` : this.mode === "range" && typeof e.selected == "object" && e.selected.start ? `${e.selected.start} – ${e.selected.end}` : null : null;
|
|
926
|
+
}
|
|
927
|
+
render() {
|
|
928
|
+
var t;
|
|
929
|
+
if (this._rendering) return;
|
|
930
|
+
this._rendering = !0;
|
|
931
|
+
const e = this.shadowRoot, s = [...e.childNodes];
|
|
932
|
+
for (const a of s)
|
|
933
|
+
a.nodeName !== "STYLE" && !(a instanceof CSSStyleSheet) && e.removeChild(a);
|
|
934
|
+
if ((t = this._popover) == null || t.destroy(), this._popover = null, this.display === "popover") {
|
|
935
|
+
const a = document.createElement("div");
|
|
936
|
+
a.classList.add("cal-popover-wrapper");
|
|
937
|
+
const i = document.createElement("button");
|
|
938
|
+
i.classList.add("cal-trigger");
|
|
939
|
+
const l = document.createElement("span");
|
|
940
|
+
l.classList.add("cal-trigger__icon"), l.innerHTML = N, i.appendChild(l);
|
|
941
|
+
const c = this._formatTriggerText(), u = document.createElement("span");
|
|
942
|
+
c ? u.textContent = c : (u.textContent = this.placeholder, u.classList.add("cal-trigger--placeholder")), i.appendChild(u), a.appendChild(i);
|
|
943
|
+
const h = this._renderTimepickerContent(), m = O({
|
|
944
|
+
trigger: i,
|
|
945
|
+
content: h,
|
|
946
|
+
onClose: () => {
|
|
947
|
+
this._store.set({ isOpen: !1 }), this.emit("cal:close");
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
a.appendChild(m.panel), e.appendChild(a), i.addEventListener("click", (d) => {
|
|
951
|
+
d.stopPropagation(), m.isOpen ? this.close() : this.open();
|
|
952
|
+
}), this._popover = m, this._store.get("isOpen") && m.open();
|
|
953
|
+
} else
|
|
954
|
+
e.appendChild(this._renderTimepickerContent());
|
|
955
|
+
this._rendering = !1;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
customElements.get("cal-timepicker") || customElements.define("cal-timepicker", U);
|
|
959
|
+
export {
|
|
960
|
+
U as CalTimepicker
|
|
961
|
+
};
|
|
962
|
+
//# sourceMappingURL=timepicker.es.js.map
|