@popovandrii/ui-elements 0.0.28 → 0.0.31
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 +10 -39
- package/dist/Button.d.ts +1 -1
- package/dist/Select.d.ts +10 -1
- package/dist/Switch.d.ts +7 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +455 -536
- package/dist/index.umd.js +1 -1
- package/dist/style.css +1 -1
- package/dist/theme-dark-neon.css +1 -0
- package/dist/theme-dark.css +1 -0
- package/dist/theme-light-neon.css +1 -0
- package/dist/theme-light.css +1 -0
- package/package.json +11 -11
package/dist/index.es.js
CHANGED
|
@@ -1,537 +1,456 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
`.${this.selectors.input}`
|
|
455
|
-
);
|
|
456
|
-
s.forEach((n, a) => {
|
|
457
|
-
this.dbug && (n.id || console.error(`Input #${a} in group has no ID!`), (!n.value || n.value === "on") && console.warn(
|
|
458
|
-
`Input #${n.id} does not have a value specified (currently "${n.value}")`
|
|
459
|
-
));
|
|
460
|
-
const l = o[a];
|
|
461
|
-
l && (n.tabIndex = -1, l.setAttribute("role", "radio"), l.setAttribute("aria-checked", String(n.checked)), l.setAttribute("tabindex", n.checked ? "0" : "-1"), n.disabled ? l.setAttribute("aria-disabled", "true") : l.removeAttribute("aria-disabled"), n.addEventListener(
|
|
462
|
-
"click",
|
|
463
|
-
() => {
|
|
464
|
-
s.forEach((h) => {
|
|
465
|
-
h.checked = !1, h.removeAttribute("checked");
|
|
466
|
-
}), s[a].checked = !0, s[a].setAttribute("checked", ""), this.costomEvent(n);
|
|
467
|
-
},
|
|
468
|
-
{ signal: e }
|
|
469
|
-
));
|
|
470
|
-
});
|
|
471
|
-
const i = Array.from(s).find((n) => n.checked && !n.disabled) || Array.from(s).find((n) => !n.disabled);
|
|
472
|
-
if (i) {
|
|
473
|
-
const n = t.querySelector(
|
|
474
|
-
`label[for="${i.id}"]`
|
|
475
|
-
);
|
|
476
|
-
n && n.setAttribute("tabindex", "0");
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
costomEvent(e) {
|
|
481
|
-
const t = {
|
|
482
|
-
detail: { id: e.id, value: e.value },
|
|
483
|
-
bubbles: !0
|
|
484
|
-
};
|
|
485
|
-
this.dbug && console.log("CostomEvent:", t.detail), e.dispatchEvent(new CustomEvent("ui-button-group-change", t));
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
class I {
|
|
489
|
-
selectors;
|
|
490
|
-
buttons = null;
|
|
491
|
-
abortController = new AbortController();
|
|
492
|
-
dbug;
|
|
493
|
-
constructor(e = {}, t = !1) {
|
|
494
|
-
this.dbug = t;
|
|
495
|
-
const r = {
|
|
496
|
-
main: "UIb"
|
|
497
|
-
};
|
|
498
|
-
this.selectors = { ...r, ...e }, this.buttons = document.querySelectorAll(
|
|
499
|
-
`.${this.selectors.main}`
|
|
500
|
-
), this.#t();
|
|
501
|
-
}
|
|
502
|
-
destroy() {
|
|
503
|
-
this.abortController && this.abortController.abort(), this.buttons = null;
|
|
504
|
-
}
|
|
505
|
-
#t() {
|
|
506
|
-
this.abortController = new AbortController();
|
|
507
|
-
const e = this.abortController.signal;
|
|
508
|
-
this.buttons?.forEach((t) => {
|
|
509
|
-
t.addEventListener(
|
|
510
|
-
"click",
|
|
511
|
-
() => {
|
|
512
|
-
this.costomEvent(t, String(t.dataset.value));
|
|
513
|
-
},
|
|
514
|
-
{ signal: e }
|
|
515
|
-
);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
costomEvent(e, t) {
|
|
519
|
-
if (!t || t === "undefined" || t.trim() === "") {
|
|
520
|
-
console.log('Button data-value="" Not set!');
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
this.dbug && console.log(`CostomEvent: { detail: ${t}, bubbles: true }`), e.dispatchEvent(
|
|
524
|
-
new CustomEvent("ui-button-change", {
|
|
525
|
-
detail: { val: t },
|
|
526
|
-
bubbles: !0
|
|
527
|
-
})
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
export {
|
|
532
|
-
I as Button,
|
|
533
|
-
L as ButtonGroup,
|
|
534
|
-
A as Select,
|
|
535
|
-
S as SpinBox,
|
|
536
|
-
$ as Switch
|
|
1
|
+
//#region src/SpinBox.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
selectors;
|
|
4
|
+
spinBoxes;
|
|
5
|
+
abortController = new AbortController();
|
|
6
|
+
dbug;
|
|
7
|
+
constructor(e = {}, t = !1) {
|
|
8
|
+
this.dbug = t;
|
|
9
|
+
let n = {
|
|
10
|
+
main: "UIsp",
|
|
11
|
+
btn: "UIsp__btn",
|
|
12
|
+
input: "UIsp__input",
|
|
13
|
+
disabledBtn: "disabled"
|
|
14
|
+
};
|
|
15
|
+
this.selectors = {
|
|
16
|
+
...n,
|
|
17
|
+
...e
|
|
18
|
+
}, this.spinBoxes = document.querySelectorAll(`.${this.selectors.main}`), this.event();
|
|
19
|
+
}
|
|
20
|
+
state = (e, t, n, r = 0, i = 0) => {
|
|
21
|
+
e == r || e < r ? (t.classList.add(this.selectors.disabledBtn), t.disabled = !0) : (t.classList.remove(this.selectors.disabledBtn), t.disabled = !1), i !== 0 && (e == i || e > i ? (n.classList.add(this.selectors.disabledBtn), n.disabled = !0) : (n.classList.remove(this.selectors.disabledBtn), n.disabled = !1));
|
|
22
|
+
};
|
|
23
|
+
destroy() {
|
|
24
|
+
this.abortController && this.abortController.abort(), this.spinBoxes = null;
|
|
25
|
+
}
|
|
26
|
+
getValidDataNumber = (e, t) => {
|
|
27
|
+
let n = e.getAttribute(`data-${t}`);
|
|
28
|
+
return n === null || n.trim() === "" || isNaN(Number(n)) ? 0 : Number(n);
|
|
29
|
+
};
|
|
30
|
+
event() {
|
|
31
|
+
this.abortController = new AbortController();
|
|
32
|
+
let e = this.abortController.signal;
|
|
33
|
+
this.spinBoxes?.forEach((t) => {
|
|
34
|
+
let n, r = t.querySelectorAll(`.${this.selectors.btn}`), i = t.querySelector(`.${this.selectors.input}`);
|
|
35
|
+
this.dbug && (r || console.log(`Buttons (${this.selectors.btn}) not found in container`), i || console.log(`Input (${this.selectors.input}) not found in container`));
|
|
36
|
+
let a = r[0], o = r[1], s = this.getValidDataNumber(t, "step"), c = this.getValidDataNumber(t, "min"), l = this.getValidDataNumber(t, "max"), u = (e) => {
|
|
37
|
+
t.setAttribute("aria-valuenow", String(e)), t.setAttribute("aria-valuetext", `${e} items`);
|
|
38
|
+
};
|
|
39
|
+
Number(i.value) <= c && (i.value = c.toFixed(s)), l === 0 ? i.value = Number(i.value).toFixed(s) : (Number(i.value) >= l && (i.value = l.toFixed(s)), l && t.setAttribute("aria-valuemax", l.toFixed(s))), c && t.setAttribute("aria-valuemin", c.toFixed(s)), this.state(Number(i.value), a, o, c, l), u(i.value);
|
|
40
|
+
let d = null, f = (e = 1) => {
|
|
41
|
+
i.value = String(Math.abs(Number(i.value)));
|
|
42
|
+
let t = parseFloat(i.value) || 0;
|
|
43
|
+
return t += 1 * e / 10 ** s, t > l && l !== 0 && (t = l), i.value = t.toFixed(s), this.state(Number(i.value), a, o, c, l), u(i.value), i.value;
|
|
44
|
+
}, p = (e = 1) => {
|
|
45
|
+
i.value = String(Math.abs(Number(i.value)));
|
|
46
|
+
let t = parseFloat(i.value) || 0;
|
|
47
|
+
return t -= 1 * e / 10 ** s, t < c && (t = c), i.value = t.toFixed(s), this.state(Number(i.value), a, o, c, l), u(i.value), i.value;
|
|
48
|
+
}, m = (e, t = 150) => {
|
|
49
|
+
d === null && (d = window.setInterval(e, t));
|
|
50
|
+
}, h = () => {
|
|
51
|
+
d !== null && (clearInterval(d), d = null);
|
|
52
|
+
};
|
|
53
|
+
o.addEventListener("mousedown", (e) => {
|
|
54
|
+
let t = e.shiftKey ? 3 : 1;
|
|
55
|
+
m(() => f(t));
|
|
56
|
+
}, { signal: e }), o.addEventListener("touchstart", () => m(f), { signal: e }), [
|
|
57
|
+
"mouseup",
|
|
58
|
+
"mouseleave",
|
|
59
|
+
"mouseout",
|
|
60
|
+
"touchend",
|
|
61
|
+
"touchcancel"
|
|
62
|
+
].forEach((t) => {
|
|
63
|
+
o.addEventListener(t, h, { signal: e });
|
|
64
|
+
}), o.addEventListener("click", (e) => {
|
|
65
|
+
let t = e.shiftKey ? 3 : 1;
|
|
66
|
+
d === null && (n = f(t), this.costomEvent(i, n));
|
|
67
|
+
}, { signal: e }), a.addEventListener("click", (e) => {
|
|
68
|
+
let t = e.shiftKey ? 3 : 1;
|
|
69
|
+
d === null && (n = p(t), this.costomEvent(i, n));
|
|
70
|
+
}, { signal: e }), a.addEventListener("mousedown", (e) => {
|
|
71
|
+
let t = e.shiftKey ? 3 : 1;
|
|
72
|
+
m(() => p(t), 100);
|
|
73
|
+
}, { signal: e }), a.addEventListener("touchstart", () => m(p, 100), { signal: e }), [
|
|
74
|
+
"mouseup",
|
|
75
|
+
"mouseleave",
|
|
76
|
+
"mouseout",
|
|
77
|
+
"touchend",
|
|
78
|
+
"touchcancel"
|
|
79
|
+
].forEach((t) => {
|
|
80
|
+
a.addEventListener(t, h, { signal: e });
|
|
81
|
+
}), i.addEventListener("keydown", (e) => {
|
|
82
|
+
let t = e.key, n = e.shiftKey ? 5 : 1;
|
|
83
|
+
if ([
|
|
84
|
+
"Backspace",
|
|
85
|
+
"Delete",
|
|
86
|
+
"ArrowLeft",
|
|
87
|
+
"ArrowRight",
|
|
88
|
+
"Tab",
|
|
89
|
+
"Enter",
|
|
90
|
+
"Home",
|
|
91
|
+
"End"
|
|
92
|
+
].includes(t) || (e.ctrlKey || e.metaKey) && [
|
|
93
|
+
"a",
|
|
94
|
+
"c",
|
|
95
|
+
"v",
|
|
96
|
+
"x"
|
|
97
|
+
].includes(t.toLowerCase())) return;
|
|
98
|
+
if ([
|
|
99
|
+
"e",
|
|
100
|
+
"+",
|
|
101
|
+
"-"
|
|
102
|
+
].includes(t)) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (t === "ArrowUp" || t === "ArrowDown") {
|
|
107
|
+
e.preventDefault(), t === "ArrowUp" ? f(n) : p(n);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let r = t === "," ? "." : t, a = /^[0-9]$/.test(r), o = r === ".", c = i.value.includes(".");
|
|
111
|
+
(s === 0 && !a || s > 0 && !(a || o) || o && c) && e.preventDefault();
|
|
112
|
+
}, { signal: e }), i.addEventListener("keyup", (e) => {
|
|
113
|
+
(e.key === "ArrowUp" || e.key === "ArrowDown") && this.costomEvent(i, i.value);
|
|
114
|
+
}, { signal: e }), i.addEventListener("change", () => {
|
|
115
|
+
Number(i.value) < c && (i.value = c.toFixed(s)), Number(i.value) > l && l !== 0 ? i.value = l.toFixed(s) : i.value = Number(i.value).toFixed(s), this.state(Number(i.value), a, o, c, l), this.costomEvent(i, i.value);
|
|
116
|
+
}, { signal: e });
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
costomEvent(e, t) {
|
|
120
|
+
let n = {
|
|
121
|
+
detail: {
|
|
122
|
+
id: e.id,
|
|
123
|
+
value: t
|
|
124
|
+
},
|
|
125
|
+
bubbles: !0
|
|
126
|
+
};
|
|
127
|
+
this.dbug && console.log("CostomEvent: data.detail ", n.detail), e.dispatchEvent(new CustomEvent("ui-spinbox-change", n));
|
|
128
|
+
}
|
|
129
|
+
}, t = class {
|
|
130
|
+
selectors;
|
|
131
|
+
main = null;
|
|
132
|
+
abortController = new AbortController();
|
|
133
|
+
dbug;
|
|
134
|
+
constructor(e = {}, t = !1) {
|
|
135
|
+
this.dbug = t;
|
|
136
|
+
let n = {
|
|
137
|
+
main: "UIsw",
|
|
138
|
+
label: "UIsw-label"
|
|
139
|
+
};
|
|
140
|
+
this.selectors = {
|
|
141
|
+
...n,
|
|
142
|
+
...e
|
|
143
|
+
}, this.main = document.querySelectorAll(`.${this.selectors.main}`), this.event();
|
|
144
|
+
}
|
|
145
|
+
destroy() {
|
|
146
|
+
this.abortController && this.abortController.abort(), this.main = null;
|
|
147
|
+
}
|
|
148
|
+
event() {
|
|
149
|
+
this.abortController = new AbortController();
|
|
150
|
+
let e = this.abortController.signal;
|
|
151
|
+
this.main?.forEach((t) => {
|
|
152
|
+
let n = t.querySelector(`.${this.selectors.label}`), r = t.querySelector("input");
|
|
153
|
+
n && n.id && t.setAttribute("aria-labelledby", n.id), r?.disabled && (t.setAttribute("tabindex", "-1"), t.setAttribute("aria-disabled", "true"), t.addEventListener("click", (e) => {
|
|
154
|
+
e.preventDefault(), e.stopImmediatePropagation();
|
|
155
|
+
}, {
|
|
156
|
+
capture: !0,
|
|
157
|
+
signal: e
|
|
158
|
+
})), r && (r.checked ? t.setAttribute("aria-checked", "true") : t.setAttribute("aria-checked", "false"), r.addEventListener("change", () => {
|
|
159
|
+
t.setAttribute("aria-checked", String(r.checked)), this.customEvent(r, String(r.checked));
|
|
160
|
+
}, { signal: e }), t.addEventListener("click", (e) => {
|
|
161
|
+
if (e.target.tagName === "INPUT") return;
|
|
162
|
+
let t = e.target.closest("label");
|
|
163
|
+
t || (r.checked = !r.checked), t || r.dispatchEvent(new Event("change"));
|
|
164
|
+
}, { signal: e }), t.addEventListener("keydown", (e) => {
|
|
165
|
+
let n = t.querySelector("input");
|
|
166
|
+
e.key === "ArrowRight" ? (r.checked = !0, t.setAttribute("aria-checked", String(r.checked)), e.preventDefault(), this.customEvent(n, "true")) : e.key === "ArrowLeft" && (r.checked = !1, t.setAttribute("aria-checked", String(r.checked)), e.preventDefault(), this.customEvent(n, "false"));
|
|
167
|
+
}, { signal: e }));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
setValue(e, t) {
|
|
171
|
+
this.main?.forEach((n) => {
|
|
172
|
+
let r = n.querySelector(`input#${e}`);
|
|
173
|
+
r && (r.checked = t, this.dbug && console.log("SetValue:", r.checked), n.setAttribute("aria-checked", String(t)), this.customEvent(r, String(t)));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
customEvent(e, t) {
|
|
177
|
+
let n = {
|
|
178
|
+
detail: {
|
|
179
|
+
id: e.id,
|
|
180
|
+
value: t
|
|
181
|
+
},
|
|
182
|
+
bubbles: !0
|
|
183
|
+
};
|
|
184
|
+
this.dbug && console.log("CustomEvent:", n.detail), e.dispatchEvent(new CustomEvent("ui-switch-change", n));
|
|
185
|
+
}
|
|
186
|
+
}, n = class e {
|
|
187
|
+
selectors;
|
|
188
|
+
main = null;
|
|
189
|
+
itemArrowInitialized = /* @__PURE__ */ new WeakSet();
|
|
190
|
+
abortController = new AbortController();
|
|
191
|
+
dbug;
|
|
192
|
+
selectMap = /* @__PURE__ */ new Map();
|
|
193
|
+
constructor(e = {}, t = !1) {
|
|
194
|
+
this.dbug = t;
|
|
195
|
+
let n = {
|
|
196
|
+
idPrefix: "UI-option-",
|
|
197
|
+
main: "UIselect",
|
|
198
|
+
selected: "UIselect-selected",
|
|
199
|
+
arrow: "UIselect-arrow",
|
|
200
|
+
optionsList: "UIselect-options",
|
|
201
|
+
search: "UIselect-options__search",
|
|
202
|
+
items: "UIselect-options__items",
|
|
203
|
+
flash: "UIFlash",
|
|
204
|
+
excludedItems: ["divider", "test"]
|
|
205
|
+
};
|
|
206
|
+
this.selectors = {
|
|
207
|
+
...n,
|
|
208
|
+
...e
|
|
209
|
+
}, this.main = document.querySelectorAll(`.${this.selectors.main}`), this.event(), this.initGlobalListener(this.selectors);
|
|
210
|
+
}
|
|
211
|
+
filterExcluded(e, t) {
|
|
212
|
+
return Array.from(e).filter((e) => !t.some((t) => typeof t == "string" ? e.classList.contains(t) || e.id === t : e === t));
|
|
213
|
+
}
|
|
214
|
+
filterSearch(e, t) {
|
|
215
|
+
let n = t.trim().toLowerCase();
|
|
216
|
+
return e.filter((e) => {
|
|
217
|
+
let t = e.dataset.value?.toLowerCase() || "", r = e.textContent?.toLowerCase() || "";
|
|
218
|
+
return t.includes(n) || r.includes(n);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
destroy() {
|
|
222
|
+
e.closeAll(this.selectors), this.abortController && (this.abortController.abort(), this.selectMap.clear()), this.main = null;
|
|
223
|
+
}
|
|
224
|
+
setValue(e, t) {
|
|
225
|
+
let n = this.selectMap.get(e);
|
|
226
|
+
if (!n) {
|
|
227
|
+
this.dbug && console.warn("UISelect: element not registered");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
let { input: r, selected: i } = n, a = e.querySelector(`.${this.selectors.optionsList}`);
|
|
231
|
+
if (!a) return;
|
|
232
|
+
let o = Array.from(a.querySelectorAll(`.${this.selectors.items} ul li`)), s = this.filterExcluded(o, this.selectors.excludedItems), c = s.find((e) => String(e.dataset.value) === String(t));
|
|
233
|
+
if (!c) {
|
|
234
|
+
this.dbug && console.warn(`UISelect: value "${t}" not found`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
s.forEach((e) => e.removeAttribute("aria-selected")), c.setAttribute("aria-selected", "true"), i.textContent = c.textContent ?? "", r.value = String(t), r.setAttribute("value", String(t)), e.setAttribute("aria-activedescendant", c.id || `${this.selectors.idPrefix}${s.indexOf(c)}`), this.customEvent(e, String(t)), e.classList.remove(this.selectors.flash), e.offsetWidth, e.classList.add(this.selectors.flash), e.addEventListener("animationend", () => e.classList.remove(this.selectors.flash), { once: !0 });
|
|
238
|
+
}
|
|
239
|
+
event() {
|
|
240
|
+
this.abortController = new AbortController();
|
|
241
|
+
let e = this.abortController.signal;
|
|
242
|
+
this.main?.forEach((t) => {
|
|
243
|
+
let n = t.querySelector(`.${this.selectors.main} input[type='hidden']`);
|
|
244
|
+
try {
|
|
245
|
+
if (!n) throw Error("<input type=\"hidden\" name=\"YouUniqueId\">");
|
|
246
|
+
} catch (e) {
|
|
247
|
+
return console.warn("Not found:", e.message);
|
|
248
|
+
}
|
|
249
|
+
let r = t.querySelector(`.${this.selectors.selected}`), i = t.querySelector(`.${this.selectors.arrow}`), a = t.querySelector(`.${this.selectors.optionsList}`), o = t.querySelector(`.${this.selectors.search} input`);
|
|
250
|
+
this.selectMap.set(t, {
|
|
251
|
+
input: n,
|
|
252
|
+
selected: r
|
|
253
|
+
}), i && i.addEventListener("click", () => {
|
|
254
|
+
this.toggle(t, a);
|
|
255
|
+
}, { signal: e }), r.addEventListener("click", () => {
|
|
256
|
+
this.toggle(t, a);
|
|
257
|
+
}, { signal: e }), t.addEventListener("click", () => {
|
|
258
|
+
this.itemsPosition(a);
|
|
259
|
+
}, { signal: e });
|
|
260
|
+
let s = a.querySelectorAll(`.${this.selectors.items} ul li`), c = this.filterExcluded(s, this.selectors.excludedItems), l = t.querySelector("[aria-selected='true']");
|
|
261
|
+
l && this.defaultSelect(t, l, r, n);
|
|
262
|
+
var u = [];
|
|
263
|
+
o && o.addEventListener("input", (i) => {
|
|
264
|
+
let o = i.target.value.trim();
|
|
265
|
+
r && (u = this.filterSearch(c, o), o ? (s.forEach((e) => e.remove()), u.forEach((e) => {
|
|
266
|
+
a.querySelector(`.${this.selectors.optionsList} ul`)?.appendChild(e);
|
|
267
|
+
})) : s.forEach((e) => {
|
|
268
|
+
a.querySelector(`.${this.selectors.optionsList} ul`)?.appendChild(e);
|
|
269
|
+
}), this.itemArrow(t, a, r, n, e));
|
|
270
|
+
}, { signal: e }), this.itemArrow(t, a, r, n, e), this.items(t, a, c, r, n, e);
|
|
271
|
+
}, { signal: e });
|
|
272
|
+
}
|
|
273
|
+
itemArrow(e, t, n, r, i) {
|
|
274
|
+
if (this.itemArrowInitialized.has(e)) return;
|
|
275
|
+
this.itemArrowInitialized.add(e);
|
|
276
|
+
let a = -1, o = n.textContent ? n.textContent : "", s = e.querySelector(`.${this.selectors.search} input`);
|
|
277
|
+
e.addEventListener("keydown", (i) => {
|
|
278
|
+
s && s.focus();
|
|
279
|
+
let c = Array.from(t.querySelectorAll(`.${this.selectors.optionsList} ul li`)), l = this.filterExcluded(c, this.selectors.excludedItems), u = l.length;
|
|
280
|
+
if (u !== 0) if (i.key === "ArrowDown") {
|
|
281
|
+
i.preventDefault(), e.getAttribute("aria-expanded") === "false" && this.toggle(e, t), a = (a + 1) % u, n.textContent = l[a].textContent, l.forEach((e) => e.removeAttribute("aria-selected")), l[a].setAttribute("aria-selected", "true");
|
|
282
|
+
let r = l[a].id || `${this.selectors.idPrefix}${a}`;
|
|
283
|
+
e.setAttribute("aria-activedescendant", r), l[a].scrollIntoView({ block: "nearest" });
|
|
284
|
+
} else if (i.key === "ArrowUp") {
|
|
285
|
+
i.preventDefault(), a = (a - 1 + u) % u, n.textContent = l[a].textContent, l.forEach((e) => e.removeAttribute("aria-selected")), l[a].setAttribute("aria-selected", "true");
|
|
286
|
+
let t = l[a].id || `${this.selectors.idPrefix}${a}`;
|
|
287
|
+
e.setAttribute("aria-activedescendant", t), l[a].scrollIntoView({ block: "nearest" });
|
|
288
|
+
} else if (i.key === "Enter") if (i.preventDefault(), a >= 0) {
|
|
289
|
+
n.textContent = l[a].textContent, l.forEach((e) => e.removeAttribute("aria-selected")), l[a].setAttribute("aria-selected", "true");
|
|
290
|
+
let i = l[a].id || `${this.selectors.idPrefix}${a}`;
|
|
291
|
+
e.setAttribute("aria-activedescendant", i), r.value = String(l[a].dataset.value), this.customEvent(e, r.value), this.close(e, t);
|
|
292
|
+
} else this.toggle(e, t);
|
|
293
|
+
else i.key === "Escape" && (e.getAttribute("aria-activedescendant") || (n.textContent = o), this.close(e, t));
|
|
294
|
+
}, { signal: i });
|
|
295
|
+
}
|
|
296
|
+
itemsPosition(e) {
|
|
297
|
+
let t = e.querySelector("[aria-selected=\"true\"]");
|
|
298
|
+
t && t.scrollIntoView({ block: "nearest" });
|
|
299
|
+
}
|
|
300
|
+
items(e, t, n, r, i, a) {
|
|
301
|
+
n.forEach((o, s) => {
|
|
302
|
+
o.addEventListener("click", () => {
|
|
303
|
+
let a = n[s];
|
|
304
|
+
if (a) {
|
|
305
|
+
r.textContent = a.textContent, n.forEach((e) => e.removeAttribute("aria-selected")), a.setAttribute("aria-selected", "true");
|
|
306
|
+
let o = a.id || `${this.selectors.idPrefix}${s}`;
|
|
307
|
+
e.setAttribute("aria-expanded", "false"), e.setAttribute("aria-activedescendant", o), i.value = String(n[s].dataset.value), this.customEvent(e, i.value), this.close(e, t);
|
|
308
|
+
}
|
|
309
|
+
}, { signal: a });
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
defaultSelect(e, t, n, r) {
|
|
313
|
+
t && (r.setAttribute("value", t.dataset.value ?? ""), n.textContent = t.textContent ?? "", e.setAttribute("aria-activedescendant", t.id || ""));
|
|
314
|
+
}
|
|
315
|
+
customEvent(e, t) {
|
|
316
|
+
let n = {
|
|
317
|
+
detail: {
|
|
318
|
+
id: e.id,
|
|
319
|
+
value: t
|
|
320
|
+
},
|
|
321
|
+
bubbles: !0
|
|
322
|
+
};
|
|
323
|
+
this.dbug && console.log("CustomEvent:", n.detail), e.dispatchEvent(new CustomEvent("ui-select-change", n));
|
|
324
|
+
}
|
|
325
|
+
toggle(t, n) {
|
|
326
|
+
e.closeAll(this.selectors), n.hidden ? (n.hidden = !1, t.setAttribute("aria-expanded", "true")) : this.close(t, n);
|
|
327
|
+
}
|
|
328
|
+
close(e, t) {
|
|
329
|
+
t.hidden = !0, e.setAttribute("aria-expanded", "false");
|
|
330
|
+
}
|
|
331
|
+
static closeAll(e) {
|
|
332
|
+
document.querySelectorAll(`.${e.main}`).forEach((t) => {
|
|
333
|
+
let n = t.querySelector(`.${e.optionsList}`);
|
|
334
|
+
n.hidden = !0, t.setAttribute("aria-expanded", "false");
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
initGlobalListener(t) {
|
|
338
|
+
document.addEventListener("click", (n) => {
|
|
339
|
+
let r = n.target;
|
|
340
|
+
[...document.querySelectorAll(`.${t.main}`)].some((e) => e.contains(r)) || e.closeAll(t);
|
|
341
|
+
}, { signal: this.abortController.signal });
|
|
342
|
+
}
|
|
343
|
+
}, r = class {
|
|
344
|
+
selectors;
|
|
345
|
+
main = null;
|
|
346
|
+
abortController = new AbortController();
|
|
347
|
+
dbug;
|
|
348
|
+
constructor(e = {}, t = !1) {
|
|
349
|
+
this.dbug = t;
|
|
350
|
+
let n = {
|
|
351
|
+
main: "UIbg",
|
|
352
|
+
btn: "UIbg-btn",
|
|
353
|
+
input: "UIbg-input"
|
|
354
|
+
};
|
|
355
|
+
this.selectors = {
|
|
356
|
+
...n,
|
|
357
|
+
...e
|
|
358
|
+
}, this.main = document.querySelectorAll(`.${this.selectors.main}`), this.#e();
|
|
359
|
+
}
|
|
360
|
+
destroy() {
|
|
361
|
+
this.abortController && this.abortController.abort(), this.main = null;
|
|
362
|
+
}
|
|
363
|
+
#e() {
|
|
364
|
+
this.abortController = new AbortController();
|
|
365
|
+
let e = this.abortController.signal;
|
|
366
|
+
this.main?.forEach((t) => {
|
|
367
|
+
let n = t.querySelector(`.${this.selectors.input}:checked`);
|
|
368
|
+
n && this.costomEvent(n);
|
|
369
|
+
let r = t.querySelectorAll(`.${this.selectors.btn}`);
|
|
370
|
+
r.forEach((t) => {
|
|
371
|
+
t.addEventListener("click", () => {
|
|
372
|
+
r.forEach((e) => {
|
|
373
|
+
e.setAttribute("aria-checked", "false"), e.setAttribute("tabindex", "-1");
|
|
374
|
+
}), t.setAttribute("aria-checked", "true"), t.setAttribute("tabindex", "0"), t.focus();
|
|
375
|
+
}, { signal: e }), t.addEventListener("keydown", (e) => {
|
|
376
|
+
let n = Array.from(r).indexOf(t);
|
|
377
|
+
if (e.key === "ArrowRight" && n++, e.key === "ArrowLeft" && n--, n < 0 && (n = r.length - 1), n >= r.length && (n = 0), e.key === "Enter") {
|
|
378
|
+
let t = i[n];
|
|
379
|
+
t && !t.disabled && (i.forEach((e) => {
|
|
380
|
+
e.checked = !1, e.removeAttribute("checked");
|
|
381
|
+
}), t.checked = !0, t.setAttribute("checked", ""), this.costomEvent(t)), e.preventDefault();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
let a = r[n];
|
|
385
|
+
a && (r.forEach((e) => e.setAttribute("tabindex", "-1")), a.setAttribute("tabindex", "0"), a.focus());
|
|
386
|
+
}, { signal: e });
|
|
387
|
+
});
|
|
388
|
+
let i = t.querySelectorAll(`.${this.selectors.input}`);
|
|
389
|
+
i.forEach((t, n) => {
|
|
390
|
+
this.dbug && (t.id || console.error(`Input #${n} in group has no ID!`), (!t.value || t.value === "on") && console.warn(`Input #${t.id} does not have a value specified (currently "${t.value}")`));
|
|
391
|
+
let a = r[n];
|
|
392
|
+
a && (t.tabIndex = -1, a.setAttribute("role", "radio"), a.setAttribute("aria-checked", String(t.checked)), a.setAttribute("tabindex", t.checked ? "0" : "-1"), t.disabled ? a.setAttribute("aria-disabled", "true") : a.removeAttribute("aria-disabled"), t.addEventListener("click", () => {
|
|
393
|
+
i.forEach((e) => {
|
|
394
|
+
e.checked = !1, e.removeAttribute("checked");
|
|
395
|
+
}), i[n].checked = !0, i[n].setAttribute("checked", ""), this.costomEvent(t);
|
|
396
|
+
}, { signal: e }));
|
|
397
|
+
});
|
|
398
|
+
let a = Array.from(i).find((e) => e.checked && !e.disabled) || Array.from(i).find((e) => !e.disabled);
|
|
399
|
+
if (a) {
|
|
400
|
+
let e = t.querySelector(`label[for="${a.id}"]`);
|
|
401
|
+
e && e.setAttribute("tabindex", "0");
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
costomEvent(e) {
|
|
406
|
+
let t = {
|
|
407
|
+
detail: {
|
|
408
|
+
id: e.id,
|
|
409
|
+
value: e.value
|
|
410
|
+
},
|
|
411
|
+
bubbles: !0
|
|
412
|
+
};
|
|
413
|
+
this.dbug && console.log("CostomEvent:", t.detail), e.dispatchEvent(new CustomEvent("ui-button-group-change", t));
|
|
414
|
+
}
|
|
415
|
+
}, i = class {
|
|
416
|
+
selectors;
|
|
417
|
+
buttons = null;
|
|
418
|
+
abortController = new AbortController();
|
|
419
|
+
dbug;
|
|
420
|
+
constructor(e = {}, t = !0) {
|
|
421
|
+
this.dbug = t;
|
|
422
|
+
let n = { main: "UIb" };
|
|
423
|
+
this.selectors = {
|
|
424
|
+
...n,
|
|
425
|
+
...e
|
|
426
|
+
}, this.buttons = document.querySelectorAll(`.${this.selectors.main}`), this.#e();
|
|
427
|
+
}
|
|
428
|
+
destroy() {
|
|
429
|
+
this.abortController && this.abortController.abort(), this.buttons = null;
|
|
430
|
+
}
|
|
431
|
+
#e() {
|
|
432
|
+
this.abortController = new AbortController();
|
|
433
|
+
let e = this.abortController.signal;
|
|
434
|
+
this.buttons?.forEach((t) => {
|
|
435
|
+
t.addEventListener("click", () => {
|
|
436
|
+
this.customEvent(t, String(t.dataset.value));
|
|
437
|
+
}, { signal: e });
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
customEvent(e, t) {
|
|
441
|
+
if (!t || t === "undefined" || t.trim() === "") {
|
|
442
|
+
console.warn("Button data-value=\"\" Not set!");
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
let n = {
|
|
446
|
+
detail: {
|
|
447
|
+
id: e.id,
|
|
448
|
+
value: t
|
|
449
|
+
},
|
|
450
|
+
bubbles: !0
|
|
451
|
+
};
|
|
452
|
+
this.dbug && console.info("Button CustomEvent:", n.detail), e.dispatchEvent(new CustomEvent("ui-button-change", n));
|
|
453
|
+
}
|
|
537
454
|
};
|
|
455
|
+
//#endregion
|
|
456
|
+
export { i as Button, r as ButtonGroup, n as Select, e as SpinBox, t as Switch };
|