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.
@@ -0,0 +1,452 @@
1
+ //#region node_modules/.pnpm/timepicker-ui@4.5.0/node_modules/timepicker-ui/dist/plugins/range.js
2
+ var e = /^(0?[1-9]|1[0-2]):([0-5]?\d)(?::([0-5]?\d))?\s*(AM|PM)$/i, t = /^([01]?\d|2[0-3]):([0-5]?\d)(?::([0-5]?\d))?$/, n = (e) => String(e).padStart(2, "0");
3
+ function r(r, i) {
4
+ let a = r.trim().match(i.clockType === "12h" ? e : t);
5
+ if (!a) return null;
6
+ let o = {
7
+ hour: n(a[1]),
8
+ minutes: n(a[2])
9
+ };
10
+ return i.showSeconds && (o.seconds = n(a[3] ?? "0")), i.clockType === "12h" && (o.type = a[4].toUpperCase()), o;
11
+ }
12
+ var i = (e, t, n) => {
13
+ if (n !== "12h" || !t) return e;
14
+ let r = t.toUpperCase();
15
+ return r === "PM" && e !== 12 ? e + 12 : r === "AM" && e === 12 ? 0 : e;
16
+ };
17
+ function a(e, t) {
18
+ let n = parseInt(e.hour, 10), r = parseInt(e.minutes, 10), a = parseInt(e.seconds ?? "0", 10);
19
+ return Number.isNaN(n) || Number.isNaN(r) || Number.isNaN(a) ? 0 : i(n, e.type, t) * 3600 + r * 60 + a;
20
+ }
21
+ var o = "--", s = (e) => e.startsWith(o);
22
+ function c(e = !1) {
23
+ return e ? "--:--:--" : "--:--";
24
+ }
25
+ function l(e, t = !1) {
26
+ if (!e || s(e)) return null;
27
+ let n = (n) => r(e, {
28
+ clockType: n,
29
+ showSeconds: t
30
+ });
31
+ return n("12h") ?? n("24h");
32
+ }
33
+ function u(e, t = !1) {
34
+ let r = `${e.hour}:${n(e.minutes)}`, i = t ? `${r}:${n(e.seconds ?? "0")}` : r;
35
+ return e.type ? `${i} ${e.type}` : i;
36
+ }
37
+ function d(e, t = !1) {
38
+ return e ? u(e, t) : c(t);
39
+ }
40
+ function f(e, t, n) {
41
+ return !e || !t ? 0 : a(t, n) - a(e, n);
42
+ }
43
+ function p(e, t, n) {
44
+ return Math.floor(f(e, t, n) / 60);
45
+ }
46
+ function m(e, t) {
47
+ return e ? t === "12h" ? !!(e.hour && e.minutes && e.type) : !!(e.hour && e.minutes) : !1;
48
+ }
49
+ function h(e, t = !1) {
50
+ if (!e || !e.includes(" - ")) return {
51
+ from: null,
52
+ to: null
53
+ };
54
+ let n = e.split(" - ").map((e) => e.trim());
55
+ return n.length !== 2 || n.some(s) ? {
56
+ from: null,
57
+ to: null
58
+ } : {
59
+ from: l(n[0], t),
60
+ to: l(n[1], t)
61
+ };
62
+ }
63
+ var g = (e) => Array.from({ length: e }, (e, t) => n(t)), _ = class {
64
+ activePart = "from";
65
+ fromValue = null;
66
+ toValue = null;
67
+ previewValue = null;
68
+ clockType;
69
+ minDuration;
70
+ maxDuration;
71
+ emitter;
72
+ showSeconds;
73
+ chosenFields = /* @__PURE__ */ new Set();
74
+ constructor(e, t, n, r, i = !1) {
75
+ this.clockType = e, this.minDuration = t, this.maxDuration = n, this.emitter = r, this.showSeconds = i;
76
+ }
77
+ getActivePart() {
78
+ return this.activePart;
79
+ }
80
+ getFromValue() {
81
+ return this.fromValue;
82
+ }
83
+ getToValue() {
84
+ return this.toValue;
85
+ }
86
+ getPreviewValue() {
87
+ return this.previewValue;
88
+ }
89
+ setFromValue(e) {
90
+ this.fromValue = e;
91
+ }
92
+ setToValue(e) {
93
+ this.toValue = e;
94
+ }
95
+ setPreviewValue(e) {
96
+ this.previewValue = e;
97
+ }
98
+ isFromComplete() {
99
+ return m(this.fromValue, this.clockType);
100
+ }
101
+ isToComplete() {
102
+ return m(this.toValue, this.clockType);
103
+ }
104
+ canSwitchToEnd() {
105
+ return this.isFromComplete();
106
+ }
107
+ getCompletePreview(e) {
108
+ let t = this.previewValue;
109
+ if (!t || this.activePart !== e) return null;
110
+ let n = [t.minutes, t.seconds ?? ""].some(s);
111
+ return m(t, this.clockType) && !n ? t : null;
112
+ }
113
+ getPendingFrom() {
114
+ return this.isFromComplete() ? null : this.getCompletePreview("from");
115
+ }
116
+ canConfirm() {
117
+ let e = this.chosenFields.size > 0 ? this.getCompletePreview("to") : null, t = this.isFromComplete() && this.isToComplete() ? this.toValue : null, n = f(this.fromValue, e ?? t, this.clockType);
118
+ return n > 0 && this.isWithinLimits(n);
119
+ }
120
+ isWithinLimits(e) {
121
+ let t = this.minDuration !== void 0 && e < this.minDuration * 60, n = this.maxDuration !== void 0 && e > this.maxDuration * 60;
122
+ return !t && !n;
123
+ }
124
+ setActivePart(e) {
125
+ if (this.chosenFields.clear(), e === "to" && !this.canSwitchToEnd()) return !1;
126
+ let t = this.activePart !== e;
127
+ return this.activePart = e, t && (this.previewValue = null), t;
128
+ }
129
+ getSavedValue() {
130
+ return this.activePart === "from" ? this.fromValue : this.toValue;
131
+ }
132
+ commitPreview() {
133
+ this.previewValue &&= (this.activePart === "from" ? this.fromValue = this.previewValue : this.toValue = this.previewValue, null);
134
+ }
135
+ getDurationSeconds() {
136
+ return f(this.fromValue, this.toValue, this.clockType);
137
+ }
138
+ getDuration() {
139
+ return p(this.fromValue, this.toValue, this.clockType);
140
+ }
141
+ validate() {
142
+ if (!this.fromValue || !this.toValue) return {
143
+ valid: !0,
144
+ duration: 0
145
+ };
146
+ let e = this.getDuration(), t = this.getDurationSeconds(), n = this.isWithinLimits(t), r = this.showSeconds ? {
147
+ valid: n,
148
+ duration: e,
149
+ durationSeconds: t
150
+ } : {
151
+ valid: n,
152
+ duration: e
153
+ };
154
+ return this.emitter.emit("range:validation", {
155
+ ...r,
156
+ minDuration: this.minDuration,
157
+ maxDuration: this.maxDuration
158
+ }), r;
159
+ }
160
+ getDisabledTimeForEndPart() {
161
+ if (this.activePart === "from" || !this.fromValue || !this.isFromComplete()) return null;
162
+ let e = parseInt(this.fromValue.hour, 10), t = parseInt(this.fromValue.minutes, 10), n = {
163
+ hours: [],
164
+ minutes: g(t),
165
+ fromHour: e
166
+ };
167
+ return this.clockType === "24h" ? n.hours = g(e) : n.fromType = this.fromValue.type, this.showSeconds && (n.seconds = g(parseInt(this.fromValue.seconds ?? "0", 10)), n.fromMinute = t), n;
168
+ }
169
+ reset() {
170
+ this.activePart = "from", this.fromValue = null, this.toValue = null, this.previewValue = null, this.chosenFields.clear();
171
+ }
172
+ }, v = (e, t, n) => {
173
+ e?.classList.toggle(t, n);
174
+ }, y = (e, t, n) => {
175
+ n ? e.getAttribute(t) !== n && e.setAttribute(t, n) : e.removeAttribute(t);
176
+ }, b = (e, t) => {
177
+ e && y(e, "aria-pressed", String(t));
178
+ }, x = (e, t) => {
179
+ v(e, "active", t), b(e, t);
180
+ }, S = (e, t, n) => {
181
+ x(e, n === "AM"), x(t, n === "PM");
182
+ }, C = [
183
+ "aria-label",
184
+ "aria-valuemin",
185
+ "aria-valuemax",
186
+ "aria-valuenow",
187
+ "aria-valuetext"
188
+ ], w = (e) => {
189
+ if (!e) return;
190
+ let t = e.querySelector(".tp-ui-clock-face");
191
+ if (!t) return;
192
+ let n = e.querySelector("input.active") ?? e.querySelector(".tp-ui-hour");
193
+ C.forEach((e) => y(t, e, n?.getAttribute(e)));
194
+ }, T = (e, t) => {
195
+ if (!e) return;
196
+ e.value = t;
197
+ let n = parseInt(t, 10), r = !Number.isNaN(n);
198
+ y(e, "aria-valuenow", r && String(n)), y(e, "aria-valuetext", r && t), w(e.closest(".tp-ui-modal"));
199
+ }, E = class {
200
+ core;
201
+ state;
202
+ constructor(e, t) {
203
+ this.core = e, this.state = t;
204
+ }
205
+ updateTabs() {
206
+ let e = this.core.getModalElement();
207
+ if (!e) return;
208
+ 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() || this.state.getPendingFrom() !== null;
209
+ 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");
210
+ }
211
+ updateTimeDisplay() {
212
+ let e = this.core.getModalElement();
213
+ if (!e) return;
214
+ 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 = (e, t) => r === e && i ? i : t;
215
+ this.renderTime(t, a("from", this.state.getFromValue())), this.renderTime(n, a("to", this.state.getToValue()));
216
+ }
217
+ renderTime(e, t) {
218
+ if (!e) return;
219
+ let { showSeconds: n } = this.state;
220
+ t ? (e.textContent = u(t, n), e.removeAttribute("aria-hidden")) : (e.textContent = c(n), e.setAttribute("aria-hidden", "true"));
221
+ }
222
+ updateOkButton() {
223
+ let e = this.core.getOkButton();
224
+ if (!e) return;
225
+ let t = this.state.canConfirm();
226
+ e.classList.toggle("disabled", !t), e.setAttribute("aria-disabled", String(!t));
227
+ }
228
+ updateInputValue() {
229
+ let e = this.core.getInput();
230
+ if (!e) return;
231
+ let { showSeconds: t } = this.state;
232
+ e.value = `${d(this.state.getFromValue(), t)} - ${d(this.state.getToValue(), t)}`;
233
+ }
234
+ syncClockToActivePart() {
235
+ let e = this.state.getSavedValue(), t = this.core.getHour(), n = this.core.getMinutes(), r = this.state.showSeconds ? this.core.getSeconds() : null;
236
+ T(t, e?.hour ?? "12"), T(n, e?.minutes ?? "00"), T(r, e?.seconds ?? "00"), this.core.options.clock.type === "12h" && S(this.core.getAM(), this.core.getPM(), e?.type), [n, r].forEach((e) => {
237
+ e?.blur(), e?.classList.remove("active");
238
+ }), t && t.click();
239
+ }
240
+ updateAll() {
241
+ this.updateTabs(), this.updateTimeDisplay(), this.updateOkButton();
242
+ }
243
+ };
244
+ function D(e, t, n, r) {
245
+ e.on(n, r), t.push(() => e.off(n, r));
246
+ }
247
+ var O = class {
248
+ core;
249
+ emitter;
250
+ state;
251
+ ui;
252
+ cleanupHandlers = [];
253
+ isSyncingAmPm = !1;
254
+ constructor(e, t) {
255
+ this.core = e, this.emitter = t, this.createState();
256
+ }
257
+ get isEnabled() {
258
+ return this.core.options.range?.enabled === !0;
259
+ }
260
+ createState() {
261
+ let { range: e, clock: t } = this.core.options;
262
+ this.state = new _(t.type, e?.minDuration, e?.maxDuration, this.emitter, t.showSeconds === !0), this.ui = new E(this.core, this.state);
263
+ }
264
+ init() {
265
+ if (this.releaseHandlers(), !this.isEnabled) return;
266
+ this.createState();
267
+ let { from: e, to: t } = h(this.core.getInput()?.value || "", this.state.showSeconds);
268
+ this.state.setFromValue(e), this.state.setToValue(t), this.bindEvents(), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent(), this.ui.updateAll();
269
+ }
270
+ getActivePart() {
271
+ return this.state.getActivePart();
272
+ }
273
+ setActivePart(e) {
274
+ this.isEnabled && (this.state.setActivePart(e) && this.emitter.emit("range:switch", {
275
+ active: e,
276
+ disabledTime: this.state.getDisabledTimeForEndPart()
277
+ }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent(), this.ui.updateAll());
278
+ }
279
+ getFromValue() {
280
+ return this.state.getFromValue();
281
+ }
282
+ getToValue() {
283
+ return this.state.getToValue();
284
+ }
285
+ getDisabledTimeForEndPart() {
286
+ return this.isEnabled ? this.state.getDisabledTimeForEndPart() : null;
287
+ }
288
+ getDuration() {
289
+ return this.state.getDuration();
290
+ }
291
+ validateRange() {
292
+ return this.isEnabled ? this.state.validate() : {
293
+ valid: !0,
294
+ duration: 0
295
+ };
296
+ }
297
+ canConfirm() {
298
+ return !this.isEnabled || this.state.canConfirm();
299
+ }
300
+ getFormattedRange() {
301
+ let e = this.state.getFromValue(), t = this.state.getToValue();
302
+ if (!e || !t) return null;
303
+ let { showSeconds: n } = this.state;
304
+ return {
305
+ from: u(e, n),
306
+ to: u(t, n)
307
+ };
308
+ }
309
+ bindEvents() {
310
+ let e = this.core.getModalElement();
311
+ if (!e) return;
312
+ let t = e.querySelector(".tp-ui-range-tab.tp-ui-range-from"), n = e.querySelector(".tp-ui-range-tab.tp-ui-range-to");
313
+ this.listen(t, "click", () => this.activatePart("from", t)), this.listen(n, "click", () => this.activatePart("to", n)), this.bindTabKeyboard(t, n), this.bindFieldChoice("hour", this.core.getHour()), this.bindFieldChoice("minutes", this.core.getMinutes()), this.bindFieldChoice("seconds", this.state.showSeconds ? this.core.getSeconds() : null), D(this.emitter, this.cleanupHandlers, "update", (e) => this.handleUpdate(e?.hour)), D(this.emitter, this.cleanupHandlers, "range:minute:commit", (e) => this.handleMinuteCommit(e)), D(this.emitter, this.cleanupHandlers, "confirm", () => this.handleConfirm()), D(this.emitter, this.cleanupHandlers, "select:am", () => this.handleAmPm()), D(this.emitter, this.cleanupHandlers, "select:pm", () => this.handleAmPm()), D(this.emitter, this.cleanupHandlers, "clear", () => this.handleClear());
314
+ }
315
+ listen(e, t, n) {
316
+ e && (e.addEventListener(t, n), this.cleanupHandlers.push(() => e.removeEventListener(t, n)));
317
+ }
318
+ bindFieldChoice(e, t) {
319
+ this.listen(t, "keydown", () => this.state.chosenFields.add(e)), this.listen(t, "blur", () => {
320
+ this.state.chosenFields.has(e) && this.handleUpdate(this.state.getPreviewValue()?.hour);
321
+ });
322
+ }
323
+ isTabDisabled(e) {
324
+ return !e || e.getAttribute("aria-disabled") === "true" || e.classList.contains("disabled");
325
+ }
326
+ activatePart(e, t) {
327
+ if (!this.core.isOpen || this.isTabDisabled(t)) return;
328
+ let n = e === "to" ? this.state.getPendingFrom() : null;
329
+ n ? this.handleMinuteCommit(n) : this.setActivePart(e);
330
+ }
331
+ bindTabKeyboard(e, t) {
332
+ let n = [e, t].filter((e) => e !== null);
333
+ n.length !== 0 && n.forEach((e, t) => {
334
+ let r = t === 0 ? "from" : "to";
335
+ this.listen(e, "keydown", (i) => {
336
+ switch (i.key) {
337
+ case "ArrowRight":
338
+ case "ArrowLeft": {
339
+ i.preventDefault();
340
+ let e = ((i.key === "ArrowRight" ? t + 1 : t - 1) + n.length) % n.length, r = n[e];
341
+ this.isTabDisabled(r) || r.focus();
342
+ break;
343
+ }
344
+ case "Home":
345
+ i.preventDefault(), n[0].focus();
346
+ break;
347
+ case "End":
348
+ i.preventDefault(), n[n.length - 1].focus();
349
+ break;
350
+ case "Enter":
351
+ case " ": i.preventDefault(), this.activatePart(r, e);
352
+ }
353
+ });
354
+ });
355
+ }
356
+ handleClear() {
357
+ this.isEnabled && (this.reset(), this.emitter.emit("range:switch", {
358
+ active: "from",
359
+ disabledTime: null
360
+ }), this.ui.updateAll(), this.focusHour());
361
+ }
362
+ focusHour() {
363
+ this.core.getHour()?.focus();
364
+ }
365
+ handleUpdate(e) {
366
+ this.isEnabled && (this.state.setPreviewValue(e === void 0 ? null : this.buildPreview(e)), this.ui.updateAll());
367
+ }
368
+ buildPreview(e) {
369
+ let t = this.state.getSavedValue()?.minutes, n = !!t && !s(t), r = (e, t) => (n || this.state.chosenFields.has(e)) && t?.value || o;
370
+ return {
371
+ hour: e,
372
+ minutes: r("minutes", this.core.getMinutes()),
373
+ seconds: this.state.showSeconds ? r("seconds", this.core.getSeconds()) : void 0,
374
+ type: this.core.options.clock.type === "12h" ? this.core.getActiveType() : void 0
375
+ };
376
+ }
377
+ handleMinuteCommit(e) {
378
+ if (!this.isEnabled) return;
379
+ let t = {
380
+ hour: e.hour,
381
+ minutes: e.minutes,
382
+ seconds: e.seconds,
383
+ type: e.type ?? void 0
384
+ };
385
+ this.state.getActivePart() === "from" ? (this.state.setFromValue(t), this.state.setPreviewValue(null), this.state.isFromComplete() && (this.state.setActivePart("to"), this.emitter.emit("range:switch", {
386
+ active: "to",
387
+ disabledTime: this.state.getDisabledTimeForEndPart()
388
+ }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent(), this.focusHour())) : (this.state.setToValue(t), this.state.setPreviewValue(null)), this.state.validate(), this.ui.updateAll();
389
+ }
390
+ handleAmPm() {
391
+ if (!this.isEnabled || this.isSyncingAmPm || this.core.options.clock.type !== "12h") return;
392
+ let e = this.core.getActiveType();
393
+ if (e) {
394
+ if (this.state.getActivePart() === "from") {
395
+ let t = this.state.getFromValue();
396
+ t && (this.state.setFromValue({
397
+ ...t,
398
+ type: e
399
+ }), this.state.isFromComplete() && (this.state.setActivePart("to"), this.state.setPreviewValue(null), this.emitter.emit("range:switch", {
400
+ active: "to",
401
+ disabledTime: this.state.getDisabledTimeForEndPart()
402
+ }), this.ui.syncClockToActivePart(), this.emitAmPmSyncEvent()));
403
+ } else {
404
+ let t = this.state.getToValue();
405
+ t && this.state.setToValue({
406
+ ...t,
407
+ type: e
408
+ }), this.emitter.emit("range:switch", {
409
+ active: "to",
410
+ disabledTime: this.state.getDisabledTimeForEndPart()
411
+ });
412
+ }
413
+ this.state.validate(), this.ui.updateAll();
414
+ }
415
+ }
416
+ emitAmPmSyncEvent() {
417
+ if (this.core.options.clock.type !== "12h") return;
418
+ let e = this.state.getSavedValue();
419
+ if (e?.type) {
420
+ this.isSyncingAmPm = !0;
421
+ try {
422
+ e.type === "AM" ? this.emitter.emit("select:am", {}) : e.type === "PM" && this.emitter.emit("select:pm", {});
423
+ } finally {
424
+ this.isSyncingAmPm = !1;
425
+ }
426
+ }
427
+ }
428
+ handleConfirm() {
429
+ if (!this.isEnabled) return;
430
+ this.state.commitPreview();
431
+ let { showSeconds: e } = this.state, t = {
432
+ from: d(this.state.getFromValue(), e),
433
+ to: d(this.state.getToValue(), e),
434
+ duration: this.state.getDuration()
435
+ };
436
+ e && (t.durationSeconds = this.state.getDurationSeconds()), this.ui.updateInputValue(), this.emitter.emit("range:confirm", t);
437
+ }
438
+ reset() {
439
+ this.state.reset();
440
+ }
441
+ destroy() {
442
+ this.releaseHandlers(), this.reset();
443
+ }
444
+ releaseHandlers() {
445
+ this.cleanupHandlers.forEach((e) => e()), this.cleanupHandlers = [];
446
+ }
447
+ }, k = {
448
+ name: "range",
449
+ factory: (e, t) => new O(e, t)
450
+ };
451
+ //#endregion
452
+ export { k as RangePlugin };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "courthive-components",
3
- "packageManager": "pnpm@12.10.1",
4
- "version": "6.10.2",
3
+ "packageManager": "pnpm@12.14.0",
4
+ "version": "6.11.0",
5
5
  "engines": {
6
- "node": ">=22"
6
+ "node": ">=24"
7
7
  },
8
8
  "description": "Components for competitions projects",
9
9
  "files": [
@@ -90,13 +90,13 @@
90
90
  "@types/d3": "^7.4.3",
91
91
  "@types/leaflet": "^1.9.12",
92
92
  "@types/vanillajs-datepicker": "^1.3.5",
93
- "@typescript-eslint/eslint-plugin": "8.71.1",
94
- "@typescript-eslint/parser": "8.71.1",
93
+ "@typescript-eslint/eslint-plugin": "8.71.2",
94
+ "@typescript-eslint/parser": "8.71.2",
95
95
  "@vitest/browser": "^5.0.3",
96
96
  "@vitest/browser-playwright": "^5.0.3",
97
97
  "@vitest/coverage-v8": "^5.0.0",
98
98
  "@vitest/ui": "^5.0.0",
99
- "eslint": "10.12.0",
99
+ "eslint": "10.13.0",
100
100
  "eslint-plugin-sonarjs": "4.2.2",
101
101
  "eslint-plugin-storybook": "^10.2.17",
102
102
  "gh-pages": "6.3.0",
@@ -110,7 +110,7 @@
110
110
  "semver": "7.8.5",
111
111
  "storybook": "^10.2.17",
112
112
  "tabulator-tables": "6.6.1",
113
- "tods-competition-factory": "7.16.0",
113
+ "tods-competition-factory": "7.19.0",
114
114
  "typescript": "^6.0.2",
115
115
  "vite": "8.3.4",
116
116
  "vite-plugin-dts": "^5.0.0",