courthive-components 6.10.2 → 6.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,430 +0,0 @@
1
- //#region node_modules/.pnpm/timepicker-ui@4.4.0/node_modules/timepicker-ui/dist/plugins/range.js
2
- var e = /^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i, t = /^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/;
3
- function n(t) {
4
- let n = t.match(e);
5
- return n ? {
6
- hour: n[1],
7
- minutes: n[2],
8
- type: n[3].toUpperCase()
9
- } : null;
10
- }
11
- function r(e) {
12
- let n = e.match(t);
13
- return n ? {
14
- hour: n[1],
15
- minutes: n[2]
16
- } : null;
17
- }
18
- function i(e, t) {
19
- let n = parseInt(e.hour, 10), r = parseInt(e.minutes, 10);
20
- if (Number.isNaN(n) || Number.isNaN(r)) return 0;
21
- if (t === "12h" && e.type) {
22
- let t = e.type.toUpperCase();
23
- t === "PM" && n !== 12 && (n += 12), t === "AM" && n === 12 && (n = 0);
24
- }
25
- return n * 60 + r;
26
- }
27
- function a(e) {
28
- if (!e || e === "--:--") return null;
29
- let t = n(e);
30
- if (t) return {
31
- hour: t.hour,
32
- minutes: t.minutes,
33
- type: t.type
34
- };
35
- let i = e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);
36
- if (i) return {
37
- hour: i[1],
38
- minutes: i[2],
39
- type: i[3].toUpperCase()
40
- };
41
- let a = r(e);
42
- if (a) return {
43
- hour: a.hour,
44
- minutes: a.minutes
45
- };
46
- let o = e.match(/^(\d{1,2}):(\d{2})$/);
47
- return o ? {
48
- hour: o[1],
49
- minutes: o[2]
50
- } : null;
51
- }
52
- function o(e) {
53
- let t = e.minutes === "--" ? "--" : e.minutes.padStart(2, "0"), n = `${e.hour}:${t}`;
54
- return e.type ? `${n} ${e.type}` : n;
55
- }
56
- function s(e, t) {
57
- return e ? i(e, t) : 0;
58
- }
59
- function c(e, t, n) {
60
- if (!e || !t) return 0;
61
- let r = s(e, n);
62
- return s(t, n) - r;
63
- }
64
- function l(e, t) {
65
- return e ? t === "12h" ? !!(e.hour && e.minutes && e.type) : !!(e.hour && e.minutes) : !1;
66
- }
67
- function u(e) {
68
- if (!e || !e.includes(" - ")) return {
69
- from: null,
70
- to: null
71
- };
72
- let t = e.split(" - ").map((e) => e.trim());
73
- return t.length !== 2 || t[0] === "--:--" || t[1] === "--:--" ? {
74
- from: null,
75
- to: null
76
- } : {
77
- from: a(t[0]),
78
- to: a(t[1])
79
- };
80
- }
81
- var d = class {
82
- activePart = "from";
83
- fromValue = null;
84
- toValue = null;
85
- previewValue = null;
86
- clockType;
87
- minDuration;
88
- maxDuration;
89
- emitter;
90
- constructor(e, t, n, r) {
91
- this.clockType = e, this.minDuration = t, this.maxDuration = n, this.emitter = r;
92
- }
93
- getActivePart() {
94
- return this.activePart;
95
- }
96
- getFromValue() {
97
- return this.fromValue;
98
- }
99
- getToValue() {
100
- return this.toValue;
101
- }
102
- getPreviewValue() {
103
- return this.previewValue;
104
- }
105
- setFromValue(e) {
106
- this.fromValue = e;
107
- }
108
- setToValue(e) {
109
- this.toValue = e;
110
- }
111
- setPreviewValue(e) {
112
- this.previewValue = e;
113
- }
114
- isFromComplete() {
115
- return l(this.fromValue, this.clockType);
116
- }
117
- isToComplete() {
118
- return l(this.toValue, this.clockType);
119
- }
120
- canSwitchToEnd() {
121
- return this.isFromComplete();
122
- }
123
- canConfirm() {
124
- return !this.isFromComplete() || !this.isToComplete() ? !1 : this.getDuration() > 0;
125
- }
126
- setActivePart(e) {
127
- if (e === "to" && !this.canSwitchToEnd()) return !1;
128
- let t = this.activePart !== e;
129
- return this.activePart = e, t && (this.previewValue = null), t;
130
- }
131
- resetActivePart() {
132
- this.activePart = "from", this.previewValue = null;
133
- }
134
- getCurrentValue() {
135
- return this.previewValue ? this.previewValue : this.activePart === "from" ? this.fromValue : this.toValue;
136
- }
137
- getSavedValue() {
138
- return this.activePart === "from" ? this.fromValue : this.toValue;
139
- }
140
- commitPreview() {
141
- this.previewValue &&= (this.activePart === "from" ? this.fromValue = this.previewValue : this.toValue = this.previewValue, null);
142
- }
143
- getDuration() {
144
- return c(this.fromValue, this.toValue, this.clockType);
145
- }
146
- validate() {
147
- if (!this.fromValue || !this.toValue) return {
148
- valid: !0,
149
- duration: 0
150
- };
151
- let e = this.getDuration(), t = !0;
152
- return this.minDuration !== void 0 && e < this.minDuration && (t = !1), this.maxDuration !== void 0 && e > this.maxDuration && (t = !1), this.emitter.emit("range:validation", {
153
- valid: t,
154
- duration: e,
155
- minDuration: this.minDuration,
156
- maxDuration: this.maxDuration
157
- }), {
158
- valid: t,
159
- duration: e
160
- };
161
- }
162
- getDisabledTimeForEndPart() {
163
- if (this.activePart === "from" || !this.fromValue || !this.isFromComplete()) return null;
164
- let e = [], t = [], n = parseInt(this.fromValue.hour, 10), r = parseInt(this.fromValue.minutes, 10), i = this.fromValue.type;
165
- if (this.clockType === "24h") {
166
- for (let t = 0; t < n; t++) e.push(t.toString().padStart(2, "0"));
167
- for (let e = 0; e < r; e++) t.push(e.toString().padStart(2, "0"));
168
- return {
169
- hours: e,
170
- minutes: t,
171
- fromHour: n
172
- };
173
- }
174
- for (let e = 0; e < r; e++) t.push(e.toString().padStart(2, "0"));
175
- return {
176
- hours: e,
177
- minutes: t,
178
- fromType: i,
179
- fromHour: n
180
- };
181
- }
182
- reset() {
183
- this.activePart = "from", this.fromValue = null, this.toValue = null, this.previewValue = null;
184
- }
185
- }, f = class {
186
- core;
187
- state;
188
- constructor(e, t) {
189
- this.core = e, this.state = t;
190
- }
191
- updateTabs() {
192
- let e = this.core.getModalElement();
193
- if (!e) return;
194
- let t = e.querySelector(".tp-ui-range-tab.tp-ui-range-from"), n = e.querySelector(".tp-ui-range-tab.tp-ui-range-to"), r = this.state.getActivePart() === "from", i = this.state.isFromComplete();
195
- t?.classList.toggle("active", r), n?.classList.toggle("active", !r), n?.classList.toggle("disabled", !i), t?.setAttribute("aria-selected", String(r)), n?.setAttribute("aria-selected", String(!r)), n?.setAttribute("aria-disabled", String(!i)), t?.setAttribute("tabindex", r ? "0" : "-1"), n?.setAttribute("tabindex", r || !i ? "-1" : "0");
196
- }
197
- updateTimeDisplay() {
198
- let e = this.core.getModalElement();
199
- if (!e) return;
200
- let t = e.querySelector(".tp-ui-range-from-time"), n = e.querySelector(".tp-ui-range-to-time"), r = this.state.getActivePart(), i = this.state.getPreviewValue(), a = this.state.getFromValue(), s = this.state.getToValue(), c = "--:--";
201
- r === "from" && i ? c = o(i) : a && (c = o(a));
202
- let l = "--:--";
203
- r === "to" && i ? l = o(i) : s && (l = o(s)), t && (t.textContent = c), n && (n.textContent = l);
204
- }
205
- updateOkButton() {
206
- let e = this.core.getOkButton();
207
- if (!e) return;
208
- let t = this.state.canConfirm();
209
- e.classList.toggle("disabled", !t), e.setAttribute("aria-disabled", String(!t));
210
- }
211
- updateInputValue() {
212
- let e = this.core.getInput();
213
- if (!e) return;
214
- let t = this.state.getFromValue(), n = this.state.getToValue();
215
- e.value = `${t ? o(t) : "--:--"} - ${n ? o(n) : "--:--"}`;
216
- }
217
- syncClockToActivePart() {
218
- let e = this.state.getSavedValue(), t = this.core.getHour(), n = this.core.getMinutes();
219
- if (t && (t.value = e?.hour ?? "12"), n && (n.value = e?.minutes ?? "00"), this.core.options.clock.type === "12h") {
220
- let t = this.core.getAM(), n = this.core.getPM();
221
- e?.type === "AM" ? (t?.classList.add("active"), n?.classList.remove("active")) : e?.type === "PM" ? (n?.classList.add("active"), t?.classList.remove("active")) : (t?.classList.remove("active"), n?.classList.remove("active"));
222
- }
223
- n && (n.blur(), n.classList.remove("active")), t && t.click();
224
- }
225
- updateAll() {
226
- this.updateTabs(), this.updateTimeDisplay(), this.updateOkButton();
227
- }
228
- };
229
- function p(e, t, n, r) {
230
- e.on(n, r), t.push(() => e.off(n, r));
231
- }
232
- var m = class {
233
- core;
234
- emitter;
235
- state;
236
- ui;
237
- cleanupHandlers = [];
238
- isSyncingAmPm = !1;
239
- constructor(e, t) {
240
- this.core = e, this.emitter = t;
241
- let { range: n, clock: r } = e.options;
242
- this.state = new d(r.type, n?.minDuration, n?.maxDuration, t), this.ui = new f(e, this.state);
243
- }
244
- get isEnabled() {
245
- return this.core.options.range?.enabled === !0;
246
- }
247
- init() {
248
- if (!this.isEnabled) return;
249
- let { from: e, to: t } = u(this.core.getInput()?.value || "");
250
- this.state.setFromValue(e), this.state.setToValue(t), this.state.setActivePart("from"), this.state.setPreviewValue(null), this.bindEvents(), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent(), this.ui.updateAll();
251
- }
252
- getActivePart() {
253
- return this.state.getActivePart();
254
- }
255
- setActivePart(e) {
256
- this.isEnabled && (this.state.setActivePart(e) && this.emitter.emit("range:switch", {
257
- active: e,
258
- disabledTime: this.state.getDisabledTimeForEndPart()
259
- }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent(), this.ui.updateAll());
260
- }
261
- getFromValue() {
262
- return this.state.getFromValue();
263
- }
264
- getToValue() {
265
- return this.state.getToValue();
266
- }
267
- getDisabledTimeForEndPart() {
268
- return this.isEnabled ? this.state.getDisabledTimeForEndPart() : null;
269
- }
270
- getDuration() {
271
- return this.state.getDuration();
272
- }
273
- validateRange() {
274
- return this.isEnabled ? this.state.validate() : {
275
- valid: !0,
276
- duration: 0
277
- };
278
- }
279
- canConfirm() {
280
- return !this.isEnabled || this.state.canConfirm();
281
- }
282
- getFormattedRange() {
283
- let e = this.state.getFromValue(), t = this.state.getToValue();
284
- return !e || !t ? null : {
285
- from: o(e),
286
- to: o(t)
287
- };
288
- }
289
- bindEvents() {
290
- let e = this.core.getModalElement();
291
- if (!e) return;
292
- let t = e.querySelector(".tp-ui-range-tab.tp-ui-range-from"), n = e.querySelector(".tp-ui-range-tab.tp-ui-range-to");
293
- if (t) {
294
- let e = () => this.activatePart("from", t);
295
- t.addEventListener("click", e), this.cleanupHandlers.push(() => t.removeEventListener("click", e));
296
- }
297
- if (n) {
298
- let e = () => this.activatePart("to", n);
299
- n.addEventListener("click", e), this.cleanupHandlers.push(() => n.removeEventListener("click", e));
300
- }
301
- this.bindTabKeyboard(t, n), p(this.emitter, this.cleanupHandlers, "update", () => this.handleUpdate()), p(this.emitter, this.cleanupHandlers, "range:minute:commit", (e) => this.handleMinuteCommit(e)), p(this.emitter, this.cleanupHandlers, "confirm", () => this.handleConfirm()), p(this.emitter, this.cleanupHandlers, "select:am", () => this.handleAmPm()), p(this.emitter, this.cleanupHandlers, "select:pm", () => this.handleAmPm()), p(this.emitter, this.cleanupHandlers, "clear", () => this.handleClear());
302
- }
303
- isTabDisabled(e) {
304
- return !e || e.getAttribute("aria-disabled") === "true" || e.classList.contains("disabled");
305
- }
306
- activatePart(e, t) {
307
- this.isTabDisabled(t) || this.setActivePart(e);
308
- }
309
- bindTabKeyboard(e, t) {
310
- let n = [e, t].filter((e) => e !== null);
311
- n.length !== 0 && n.forEach((e, t) => {
312
- let r = t === 0 ? "from" : "to", i = (i) => {
313
- switch (i.key) {
314
- case "ArrowRight":
315
- case "ArrowLeft": {
316
- i.preventDefault();
317
- let e = ((i.key === "ArrowRight" ? t + 1 : t - 1) + n.length) % n.length, r = n[e];
318
- this.isTabDisabled(r) || r.focus();
319
- break;
320
- }
321
- case "Home":
322
- i.preventDefault(), n[0].focus();
323
- break;
324
- case "End":
325
- i.preventDefault(), n[n.length - 1].focus();
326
- break;
327
- case "Enter":
328
- case " ":
329
- case "Spacebar": i.preventDefault(), this.activatePart(r, e);
330
- }
331
- };
332
- e.addEventListener("keydown", i), this.cleanupHandlers.push(() => e.removeEventListener("keydown", i));
333
- });
334
- }
335
- handleClear() {
336
- this.isEnabled && (this.state.setFromValue(null), this.state.setToValue(null), this.state.setPreviewValue(null), this.state.resetActivePart());
337
- }
338
- handleUpdate() {
339
- if (!this.isEnabled) return;
340
- let e = this.core.getHour(), t = this.core.getMinutes(), n = this.core.getActiveTypeMode(), r = e?.value ?? "12", i = this.state.getSavedValue(), a = i?.minutes && i.minutes !== "--" ? t?.value ?? "--" : "--", o = this.core.options.clock.type === "12h" ? n?.textContent ?? void 0 : void 0;
341
- this.state.setPreviewValue({
342
- hour: r,
343
- minutes: a,
344
- type: o
345
- }), this.ui.updateAll();
346
- }
347
- handleMinuteCommit(e) {
348
- if (!this.isEnabled) return;
349
- let t = {
350
- hour: e.hour,
351
- minutes: e.minutes,
352
- type: e.type ?? void 0
353
- };
354
- this.state.getActivePart() === "from" ? (this.state.setFromValue(t), this.state.setPreviewValue(null), this.state.isFromComplete() && (this.state.setActivePart("to"), this.emitter.emit("range:switch", {
355
- active: "to",
356
- disabledTime: this.state.getDisabledTimeForEndPart()
357
- }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent())) : (this.state.setToValue(t), this.state.setPreviewValue(null)), this.state.validate(), this.ui.updateAll();
358
- }
359
- handleAmPm() {
360
- if (!this.isEnabled || this.isSyncingAmPm || this.core.options.clock.type !== "12h") return;
361
- let e = this.core.getActiveTypeMode()?.textContent;
362
- if (e) {
363
- if (this.state.getActivePart() === "from") {
364
- let t = this.state.getFromValue();
365
- t && (this.state.setFromValue({
366
- ...t,
367
- type: e
368
- }), this.state.isFromComplete() && (this.state.setActivePart("to"), this.state.setPreviewValue(null), this.emitter.emit("range:switch", {
369
- active: "to",
370
- disabledTime: this.state.getDisabledTimeForEndPart()
371
- }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent()));
372
- } else {
373
- let t = this.state.getToValue();
374
- t && this.state.setToValue({
375
- ...t,
376
- type: e
377
- }), this.emitter.emit("range:switch", {
378
- active: "to",
379
- disabledTime: this.state.getDisabledTimeForEndPart()
380
- });
381
- }
382
- this.state.validate(), this.ui.updateAll();
383
- }
384
- }
385
- emitAmPmSyncEvent() {
386
- if (this.core.options.clock.type !== "12h") return;
387
- let e = this.state.getSavedValue();
388
- if (e?.type) {
389
- this.isSyncingAmPm = !0;
390
- try {
391
- e.type === "AM" ? this.emitter.emit("select:am", {}) : e.type === "PM" && this.emitter.emit("select:pm", {});
392
- } finally {
393
- this.isSyncingAmPm = !1;
394
- }
395
- }
396
- }
397
- handleConfirm() {
398
- if (!this.isEnabled) return;
399
- this.state.commitPreview();
400
- let e = this.state.getFromValue(), t = this.state.getToValue(), n = e ? o(e) : "--:--", r = t ? o(t) : "--:--", i = this.state.getDuration();
401
- this.ui.updateInputValue(), this.emitter.emit("range:confirm", {
402
- from: n,
403
- to: r,
404
- duration: i
405
- });
406
- }
407
- reset() {
408
- this.state.reset();
409
- }
410
- destroy() {
411
- this.cleanupHandlers.forEach((e) => e()), this.cleanupHandlers = [], this.reset();
412
- }
413
- }, h = {
414
- name: "range",
415
- factory: (e, t) => new m(e, t),
416
- clearHandler: (e, t) => {
417
- if (!e.options.range?.enabled) return;
418
- let n = e.getModalElement();
419
- if (!n) return;
420
- let r = n.querySelector(".tp-ui-range-from"), i = n.querySelector(".tp-ui-range-to"), a = n.querySelector(".tp-ui-range-from-time"), o = n.querySelector(".tp-ui-range-to-time");
421
- a && (a.textContent = "--:--"), o && (o.textContent = "--:--"), r?.classList.add("active"), i?.classList.remove("active"), r?.setAttribute("aria-selected", "true"), i?.setAttribute("aria-selected", "false"), r?.setAttribute("tabindex", "0"), i?.setAttribute("tabindex", "-1"), i?.classList.add("disabled"), i?.setAttribute("aria-disabled", "true");
422
- let s = e.getHour();
423
- s && s.focus(), t.emit("range:switch", {
424
- active: "from",
425
- disabledTime: null
426
- });
427
- }
428
- };
429
- //#endregion
430
- export { h as RangePlugin };