slim-select 3.4.1 → 3.4.3
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/dist/index.d.ts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +189 -182
- package/dist/react/index.umd.js +2 -2
- package/dist/slimselect.cjs.js +1 -1
- package/dist/slimselect.cjs.js.map +1 -1
- package/dist/slimselect.es.js +30 -23
- package/dist/slimselect.es.js.map +1 -1
- package/dist/slimselect.iife.js +1 -1
- package/dist/slimselect.iife.js.map +1 -1
- package/dist/slimselect.js +1 -1
- package/dist/slimselect.js.map +1 -1
- package/dist/vue/index.d.ts +2 -1
- package/dist/vue/index.js +94 -87
- package/dist/vue/index.umd.js +1 -1
- package/package.json +9 -9
- package/src/slim-select/index.test.ts +32 -0
- package/src/slim-select/render.test.ts +50 -0
- package/src/slim-select/render.ts +7 -1
- package/src/slim-select/store.test.ts +17 -0
- package/src/slim-select/store.ts +20 -6
package/dist/react/index.js
CHANGED
|
@@ -6,16 +6,16 @@ function he() {
|
|
|
6
6
|
ee = 1;
|
|
7
7
|
var p = /* @__PURE__ */ Symbol.for("react.transitional.element"), e = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
8
|
function t(s, i, n) {
|
|
9
|
-
var
|
|
10
|
-
if (n !== void 0 && (
|
|
9
|
+
var l = null;
|
|
10
|
+
if (n !== void 0 && (l = "" + n), i.key !== void 0 && (l = "" + i.key), "key" in i) {
|
|
11
11
|
n = {};
|
|
12
|
-
for (var
|
|
13
|
-
|
|
12
|
+
for (var r in i)
|
|
13
|
+
r !== "key" && (n[r] = i[r]);
|
|
14
14
|
} else n = i;
|
|
15
15
|
return i = n.ref, {
|
|
16
16
|
$$typeof: p,
|
|
17
17
|
type: s,
|
|
18
|
-
key:
|
|
18
|
+
key: l,
|
|
19
19
|
ref: i !== void 0 ? i : null,
|
|
20
20
|
props: n
|
|
21
21
|
};
|
|
@@ -55,7 +55,7 @@ function de() {
|
|
|
55
55
|
return a.displayName || "Context";
|
|
56
56
|
case k:
|
|
57
57
|
return (a._context.displayName || "Context") + ".Consumer";
|
|
58
|
-
case
|
|
58
|
+
case C:
|
|
59
59
|
var u = a.render;
|
|
60
60
|
return a = a.displayName, a || (a = u.displayName || u.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
|
|
61
61
|
case B:
|
|
@@ -81,8 +81,8 @@ function de() {
|
|
|
81
81
|
}
|
|
82
82
|
if (u) {
|
|
83
83
|
u = console;
|
|
84
|
-
var
|
|
85
|
-
return
|
|
84
|
+
var w = u.error, O = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
|
|
85
|
+
return w.call(
|
|
86
86
|
u,
|
|
87
87
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
88
|
O
|
|
@@ -107,22 +107,22 @@ function de() {
|
|
|
107
107
|
function n() {
|
|
108
108
|
return Error("react-stack-top-frame");
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function l(a) {
|
|
111
111
|
if (J.call(a, "key")) {
|
|
112
112
|
var u = Object.getOwnPropertyDescriptor(a, "key").get;
|
|
113
113
|
if (u && u.isReactWarning) return !1;
|
|
114
114
|
}
|
|
115
115
|
return a.key !== void 0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
118
|
-
function
|
|
117
|
+
function r(a, u) {
|
|
118
|
+
function w() {
|
|
119
119
|
G || (G = !0, console.error(
|
|
120
120
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
121
121
|
u
|
|
122
122
|
));
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
get:
|
|
124
|
+
w.isReactWarning = !0, Object.defineProperty(a, "key", {
|
|
125
|
+
get: w,
|
|
126
126
|
configurable: !0
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -132,13 +132,13 @@ function de() {
|
|
|
132
132
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
133
133
|
)), a = this.props.ref, a !== void 0 ? a : null;
|
|
134
134
|
}
|
|
135
|
-
function h(a, u,
|
|
136
|
-
var y =
|
|
135
|
+
function h(a, u, w, O, F, U) {
|
|
136
|
+
var y = w.ref;
|
|
137
137
|
return a = {
|
|
138
138
|
$$typeof: E,
|
|
139
139
|
type: a,
|
|
140
140
|
key: u,
|
|
141
|
-
props:
|
|
141
|
+
props: w,
|
|
142
142
|
_owner: O
|
|
143
143
|
}, (y !== void 0 ? y : null) !== null ? Object.defineProperty(a, "ref", {
|
|
144
144
|
enumerable: !1,
|
|
@@ -165,7 +165,7 @@ function de() {
|
|
|
165
165
|
value: U
|
|
166
166
|
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
|
|
167
167
|
}
|
|
168
|
-
function o(a, u,
|
|
168
|
+
function o(a, u, w, O, F, U) {
|
|
169
169
|
var y = u.children;
|
|
170
170
|
if (y !== void 0)
|
|
171
171
|
if (O)
|
|
@@ -196,18 +196,18 @@ React keys must be passed directly to JSX without using spread:
|
|
|
196
196
|
y
|
|
197
197
|
), Q[y + O] = !0);
|
|
198
198
|
}
|
|
199
|
-
if (y = null,
|
|
200
|
-
|
|
199
|
+
if (y = null, w !== void 0 && (t(w), y = "" + w), l(u) && (t(u.key), y = "" + u.key), "key" in u) {
|
|
200
|
+
w = {};
|
|
201
201
|
for (var W in u)
|
|
202
|
-
W !== "key" && (
|
|
203
|
-
} else
|
|
204
|
-
return y &&
|
|
205
|
-
|
|
202
|
+
W !== "key" && (w[W] = u[W]);
|
|
203
|
+
} else w = u;
|
|
204
|
+
return y && r(
|
|
205
|
+
w,
|
|
206
206
|
typeof a == "function" ? a.displayName || a.name || "Unknown" : a
|
|
207
207
|
), h(
|
|
208
208
|
a,
|
|
209
209
|
y,
|
|
210
|
-
|
|
210
|
+
w,
|
|
211
211
|
i(),
|
|
212
212
|
F,
|
|
213
213
|
U
|
|
@@ -219,7 +219,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
219
219
|
function m(a) {
|
|
220
220
|
return typeof a == "object" && a !== null && a.$$typeof === E;
|
|
221
221
|
}
|
|
222
|
-
var f = re, E = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), S = /* @__PURE__ */ Symbol.for("react.strict_mode"), v = /* @__PURE__ */ Symbol.for("react.profiler"), k = /* @__PURE__ */ Symbol.for("react.consumer"), L = /* @__PURE__ */ Symbol.for("react.context"),
|
|
222
|
+
var f = re, E = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), S = /* @__PURE__ */ Symbol.for("react.strict_mode"), v = /* @__PURE__ */ Symbol.for("react.profiler"), k = /* @__PURE__ */ Symbol.for("react.consumer"), L = /* @__PURE__ */ Symbol.for("react.context"), C = /* @__PURE__ */ Symbol.for("react.forward_ref"), D = /* @__PURE__ */ Symbol.for("react.suspense"), P = /* @__PURE__ */ Symbol.for("react.suspense_list"), B = /* @__PURE__ */ Symbol.for("react.memo"), T = /* @__PURE__ */ Symbol.for("react.lazy"), R = /* @__PURE__ */ Symbol.for("react.activity"), ne = /* @__PURE__ */ Symbol.for("react.client.reference"), j = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, le = Array.isArray, q = console.createTask ? console.createTask : function() {
|
|
223
223
|
return null;
|
|
224
224
|
};
|
|
225
225
|
f = {
|
|
@@ -231,22 +231,22 @@ React keys must be passed directly to JSX without using spread:
|
|
|
231
231
|
f,
|
|
232
232
|
n
|
|
233
233
|
)(), Z = q(s(n)), Q = {};
|
|
234
|
-
_.Fragment = A, _.jsx = function(a, u,
|
|
234
|
+
_.Fragment = A, _.jsx = function(a, u, w) {
|
|
235
235
|
var O = 1e4 > j.recentlyCreatedOwnerStacks++;
|
|
236
236
|
return o(
|
|
237
237
|
a,
|
|
238
238
|
u,
|
|
239
|
-
|
|
239
|
+
w,
|
|
240
240
|
!1,
|
|
241
241
|
O ? Error("react-stack-top-frame") : K,
|
|
242
242
|
O ? q(s(a)) : Z
|
|
243
243
|
);
|
|
244
|
-
}, _.jsxs = function(a, u,
|
|
244
|
+
}, _.jsxs = function(a, u, w) {
|
|
245
245
|
var O = 1e4 > j.recentlyCreatedOwnerStacks++;
|
|
246
246
|
return o(
|
|
247
247
|
a,
|
|
248
248
|
u,
|
|
249
|
-
|
|
249
|
+
w,
|
|
250
250
|
!0,
|
|
251
251
|
O ? Error("react-stack-top-frame") : K,
|
|
252
252
|
O ? q(s(a)) : Z
|
|
@@ -343,10 +343,10 @@ function ie(p, e) {
|
|
|
343
343
|
function H(p, e = 50, t = !1) {
|
|
344
344
|
let s;
|
|
345
345
|
return function(...i) {
|
|
346
|
-
const n = self,
|
|
346
|
+
const n = self, l = () => {
|
|
347
347
|
s = null, t || p.apply(n, i);
|
|
348
|
-
},
|
|
349
|
-
clearTimeout(s), s = setTimeout(
|
|
348
|
+
}, r = t && !s;
|
|
349
|
+
clearTimeout(s), s = setTimeout(l, e), r && p.apply(n, i);
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
352
|
function Y(p, e) {
|
|
@@ -356,7 +356,7 @@ function me(p) {
|
|
|
356
356
|
const e = p.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (t) => "-" + t.toLowerCase());
|
|
357
357
|
return p[0] === p[0].toUpperCase() ? e.substring(1) : e;
|
|
358
358
|
}
|
|
359
|
-
class
|
|
359
|
+
class b {
|
|
360
360
|
id;
|
|
361
361
|
value;
|
|
362
362
|
text;
|
|
@@ -384,7 +384,7 @@ class x {
|
|
|
384
384
|
constructor(e) {
|
|
385
385
|
if (this.id = !e.id || e.id === "" ? z() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
|
|
386
386
|
for (const t of e.options)
|
|
387
|
-
this.options.push(new
|
|
387
|
+
this.options.push(new b(t));
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
class ge {
|
|
@@ -410,7 +410,7 @@ class ge {
|
|
|
410
410
|
if (i)
|
|
411
411
|
return i;
|
|
412
412
|
}
|
|
413
|
-
} else if (t instanceof
|
|
413
|
+
} else if (t instanceof b || "text" in t) {
|
|
414
414
|
const s = this.validateOption(t);
|
|
415
415
|
if (s)
|
|
416
416
|
return s;
|
|
@@ -429,37 +429,42 @@ class ge {
|
|
|
429
429
|
if (s instanceof x || "label" in s) {
|
|
430
430
|
let i = [];
|
|
431
431
|
"options" in s && s.options && s.options.forEach((n) => {
|
|
432
|
-
i.push(new
|
|
432
|
+
i.push(new b(n));
|
|
433
433
|
}), i.length > 0 && t.push(new x(s));
|
|
434
434
|
}
|
|
435
|
-
(s instanceof
|
|
435
|
+
(s instanceof b || "text" in s) && t.push(new b(s));
|
|
436
436
|
}
|
|
437
437
|
}), t;
|
|
438
438
|
}
|
|
439
439
|
setData(e, t = !1) {
|
|
440
440
|
const s = this.partialToFullData(e);
|
|
441
|
+
let i = [];
|
|
441
442
|
if (t) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
443
|
+
i = this.getSelectedOptions();
|
|
444
|
+
const n = [];
|
|
445
|
+
i.forEach((l) => {
|
|
446
|
+
let r = !1;
|
|
445
447
|
for (const c of s) {
|
|
446
|
-
if (c instanceof
|
|
447
|
-
|
|
448
|
+
if (c instanceof b && c.id === l.id) {
|
|
449
|
+
r = !0;
|
|
448
450
|
break;
|
|
449
451
|
}
|
|
450
452
|
if (c instanceof x) {
|
|
451
453
|
for (const h of c.options)
|
|
452
|
-
if (h.id ===
|
|
453
|
-
|
|
454
|
+
if (h.id === l.id) {
|
|
455
|
+
r = !0;
|
|
454
456
|
break;
|
|
455
457
|
}
|
|
456
458
|
}
|
|
457
459
|
}
|
|
458
|
-
|
|
460
|
+
r || n.push(l);
|
|
459
461
|
}), this.data = [...n, ...s];
|
|
460
462
|
} else
|
|
461
463
|
this.data = s;
|
|
462
|
-
this.selectType === "single"
|
|
464
|
+
if (this.selectType === "single") {
|
|
465
|
+
const n = t && i.length === 0;
|
|
466
|
+
this.setSelectedBy("id", this.getSelected(), n);
|
|
467
|
+
}
|
|
463
468
|
}
|
|
464
469
|
// Get data will return all the data
|
|
465
470
|
getData() {
|
|
@@ -472,28 +477,29 @@ class ge {
|
|
|
472
477
|
}
|
|
473
478
|
addOption(e, t = !1) {
|
|
474
479
|
if (t) {
|
|
475
|
-
let s = [new
|
|
480
|
+
let s = [new b(e)];
|
|
476
481
|
this.setData(s.concat(this.getData()));
|
|
477
482
|
} else
|
|
478
|
-
this.setData(this.getData().concat(new
|
|
483
|
+
this.setData(this.getData().concat(new b(e)));
|
|
479
484
|
}
|
|
480
485
|
// Pass in an array of id that will loop through
|
|
481
486
|
// each option and set the selected property to true
|
|
482
487
|
// but also clean selected by determining selectType
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
488
|
+
// When allowEmptySelection is true (e.g. after search with no prior selection), single select will not auto-select the first option
|
|
489
|
+
setSelectedBy(e, t, s = !1) {
|
|
490
|
+
let i = null, n = !1;
|
|
491
|
+
const l = [];
|
|
492
|
+
for (let c of this.data) {
|
|
493
|
+
if (c instanceof x)
|
|
494
|
+
for (let h of c.options) {
|
|
495
|
+
i || (i = h);
|
|
496
|
+
let o = h[e] || "";
|
|
497
|
+
h.selected = n ? !1 : t.includes(o), h.selected && (l.push(h), this.selectType === "single" && (n = !0));
|
|
492
498
|
}
|
|
493
|
-
|
|
499
|
+
c instanceof b && (i || (i = c), c.selected = n ? !1 : t.includes(c[e]), c.selected && (l.push(c), this.selectType === "single" && (n = !0)));
|
|
494
500
|
}
|
|
495
|
-
this.selectType === "single" &&
|
|
496
|
-
const r = t.map((
|
|
501
|
+
this.selectType === "single" && i && !n && !s && (i.selected = !0, l.push(i));
|
|
502
|
+
const r = t.map((c) => l.find((h) => h[e] === c)?.id || "");
|
|
497
503
|
this.selectedOrder = r;
|
|
498
504
|
}
|
|
499
505
|
getSelected() {
|
|
@@ -521,7 +527,7 @@ class ge {
|
|
|
521
527
|
getFirstOption() {
|
|
522
528
|
let e = null;
|
|
523
529
|
for (let t of this.data)
|
|
524
|
-
if (t instanceof x ? e = t.options[0] : t instanceof
|
|
530
|
+
if (t instanceof x ? e = t.options[0] : t instanceof b && (e = t), e)
|
|
525
531
|
break;
|
|
526
532
|
return e;
|
|
527
533
|
}
|
|
@@ -536,14 +542,14 @@ class ge {
|
|
|
536
542
|
return this.data.forEach((i) => {
|
|
537
543
|
if (i instanceof x) {
|
|
538
544
|
let n = [];
|
|
539
|
-
if (i.options.forEach((
|
|
540
|
-
(!e || e(
|
|
545
|
+
if (i.options.forEach((r) => {
|
|
546
|
+
(!e || e(r)) && (t ? n.push(new b(r)) : s.push(new b(r)));
|
|
541
547
|
}), n.length > 0) {
|
|
542
|
-
let
|
|
543
|
-
|
|
548
|
+
let r = new x(i);
|
|
549
|
+
r.options = n, s.push(r);
|
|
544
550
|
}
|
|
545
551
|
}
|
|
546
|
-
i instanceof
|
|
552
|
+
i instanceof b && (!e || e(i)) && s.push(new b(i));
|
|
547
553
|
}), s;
|
|
548
554
|
}
|
|
549
555
|
// Take in an array of options and reoder them based upon the selected order
|
|
@@ -569,6 +575,7 @@ class ve {
|
|
|
569
575
|
callbacks;
|
|
570
576
|
// Used to compute the range selection
|
|
571
577
|
lastSelectedOption;
|
|
578
|
+
lastRenderedOptions;
|
|
572
579
|
// Timeout tracking for cleanup
|
|
573
580
|
closeAnimationTimeout = null;
|
|
574
581
|
// Elements
|
|
@@ -577,7 +584,7 @@ class ve {
|
|
|
577
584
|
// Classes
|
|
578
585
|
classes;
|
|
579
586
|
constructor(e, t, s, i) {
|
|
580
|
-
this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto"), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main);
|
|
587
|
+
this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, this.lastRenderedOptions = [], this.main = this.mainDiv(), this.content = this.contentDiv(), this.updateClassStyles(), this.updateAriaAttributes(), this.settings.contentPosition !== "relative" && (this.content.main.style.top = "-9999px", this.content.main.style.left = "-9999px", this.content.main.style.margin = "0", this.content.main.style.width = "auto"), this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main);
|
|
581
588
|
}
|
|
582
589
|
// Helper method to add classes that may contain spaces
|
|
583
590
|
// Splits by spaces and adds each class individually to avoid DOMException
|
|
@@ -687,21 +694,21 @@ class ve {
|
|
|
687
694
|
};
|
|
688
695
|
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
689
696
|
n.setAttribute("viewBox", "0 0 100 100");
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
this.addClasses(
|
|
697
|
+
const l = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
698
|
+
l.setAttribute("d", this.classes.deselectPath), n.appendChild(l), s.appendChild(n), e.appendChild(s);
|
|
699
|
+
const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
700
|
+
this.addClasses(r, this.classes.arrow), r.setAttribute("viewBox", "0 0 100 100");
|
|
694
701
|
const c = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
695
|
-
return c.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(
|
|
702
|
+
return c.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(r, this.classes.hide), r.appendChild(c), e.appendChild(r), {
|
|
696
703
|
main: e,
|
|
697
704
|
values: t,
|
|
698
705
|
deselect: {
|
|
699
706
|
main: s,
|
|
700
707
|
svg: n,
|
|
701
|
-
path:
|
|
708
|
+
path: l
|
|
702
709
|
},
|
|
703
710
|
arrow: {
|
|
704
|
-
main:
|
|
711
|
+
main: r,
|
|
705
712
|
path: c
|
|
706
713
|
}
|
|
707
714
|
};
|
|
@@ -755,8 +762,8 @@ class ve {
|
|
|
755
762
|
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
756
763
|
let s = [];
|
|
757
764
|
for (let i = 0; i < e.length; i++) {
|
|
758
|
-
const n = e[i],
|
|
759
|
-
|
|
765
|
+
const n = e[i], l = n.getAttribute("data-id");
|
|
766
|
+
l && (t.filter((c) => c.id === l, !1).length || s.push(n));
|
|
760
767
|
}
|
|
761
768
|
for (const i of s)
|
|
762
769
|
this.addClasses(i, this.classes.valueOut), setTimeout(() => {
|
|
@@ -765,8 +772,8 @@ class ve {
|
|
|
765
772
|
e = this.main.values.childNodes;
|
|
766
773
|
for (let i = 0; i < t.length; i++) {
|
|
767
774
|
let n = !0;
|
|
768
|
-
for (let
|
|
769
|
-
t[i].id === String(e[
|
|
775
|
+
for (let l = 0; l < e.length; l++)
|
|
776
|
+
t[i].id === String(e[l].dataset.id) && (n = !1);
|
|
770
777
|
n && (this.settings.keepOrder ? this.main.values.appendChild(this.multipleValue(t[i])) : e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[i])) : i === 0 ? this.main.values.insertBefore(this.multipleValue(t[i]), e[i]) : e[i - 1].insertAdjacentElement("afterend", this.multipleValue(t[i])));
|
|
771
778
|
}
|
|
772
779
|
}
|
|
@@ -776,8 +783,8 @@ class ve {
|
|
|
776
783
|
const s = document.createElement("div");
|
|
777
784
|
if (this.addClasses(s, this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
|
|
778
785
|
const i = document.createElement("div");
|
|
779
|
-
this.addClasses(i, this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (
|
|
780
|
-
if (
|
|
786
|
+
this.addClasses(i, this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (r) => {
|
|
787
|
+
if (r.preventDefault(), r.stopPropagation(), this.settings.disabled)
|
|
781
788
|
return;
|
|
782
789
|
let c = !0;
|
|
783
790
|
const h = this.store.getSelectedOptions(), o = h.filter((d) => d.selected && d.id !== e.id, !0);
|
|
@@ -787,16 +794,16 @@ class ve {
|
|
|
787
794
|
if (m instanceof x)
|
|
788
795
|
for (const f of m.options)
|
|
789
796
|
f.id && d.push(f.id);
|
|
790
|
-
m instanceof
|
|
797
|
+
m instanceof b && d.push(m.id);
|
|
791
798
|
}
|
|
792
799
|
this.callbacks.setSelected(d, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o), this.updateDeselectAll();
|
|
793
800
|
}
|
|
794
801
|
};
|
|
795
802
|
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
796
803
|
n.setAttribute("viewBox", "0 0 100 100");
|
|
797
|
-
const
|
|
798
|
-
|
|
799
|
-
|
|
804
|
+
const l = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
805
|
+
l.setAttribute("d", this.classes.optionDelete), n.appendChild(l), i.appendChild(n), t.appendChild(i), i.onkeydown = (r) => {
|
|
806
|
+
r.key === "Enter" && i.click();
|
|
800
807
|
};
|
|
801
808
|
}
|
|
802
809
|
return t;
|
|
@@ -847,24 +854,24 @@ class ve {
|
|
|
847
854
|
case "Escape":
|
|
848
855
|
return this.callbacks.close(), !1;
|
|
849
856
|
case " ":
|
|
850
|
-
const
|
|
857
|
+
const l = this.content.list.querySelector(
|
|
851
858
|
"." + this.classes.getFirst("highlighted")
|
|
852
859
|
);
|
|
853
|
-
return
|
|
860
|
+
return l ? (l.click(), !1) : !0;
|
|
854
861
|
case "Enter":
|
|
855
|
-
const
|
|
862
|
+
const r = this.content.list.querySelector(
|
|
856
863
|
"." + this.classes.getFirst("highlighted")
|
|
857
864
|
);
|
|
858
|
-
return
|
|
865
|
+
return r ? (r.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
|
|
859
866
|
}
|
|
860
867
|
return !0;
|
|
861
868
|
}, e.appendChild(t), this.callbacks.addable) {
|
|
862
869
|
this.addClasses(s, this.classes.addable);
|
|
863
870
|
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
864
871
|
n.setAttribute("viewBox", "0 0 100 100");
|
|
865
|
-
const
|
|
866
|
-
|
|
867
|
-
if (
|
|
872
|
+
const l = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
873
|
+
l.setAttribute("d", this.classes.addablePath), n.appendChild(l), s.appendChild(n), s.onclick = (r) => {
|
|
874
|
+
if (r.preventDefault(), r.stopPropagation(), !this.callbacks.addable)
|
|
868
875
|
return;
|
|
869
876
|
const c = this.content.search.input.value.trim();
|
|
870
877
|
if (c === "") {
|
|
@@ -872,7 +879,7 @@ class ve {
|
|
|
872
879
|
return;
|
|
873
880
|
}
|
|
874
881
|
const h = (d) => {
|
|
875
|
-
let m = new
|
|
882
|
+
let m = new b(d);
|
|
876
883
|
if (this.callbacks.addOption(m), this.settings.isMultiple) {
|
|
877
884
|
let f = this.store.getSelected();
|
|
878
885
|
f.push(m.id), this.callbacks.setSelected(f, !0);
|
|
@@ -894,7 +901,7 @@ class ve {
|
|
|
894
901
|
}, e.appendChild(s), i.addable = {
|
|
895
902
|
main: s,
|
|
896
903
|
svg: n,
|
|
897
|
-
path:
|
|
904
|
+
path: l
|
|
898
905
|
};
|
|
899
906
|
}
|
|
900
907
|
return i;
|
|
@@ -927,11 +934,11 @@ class ve {
|
|
|
927
934
|
}
|
|
928
935
|
for (let n = 0; n < t.length; n++)
|
|
929
936
|
if (t[n].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
930
|
-
const
|
|
931
|
-
this.removeClasses(
|
|
932
|
-
const
|
|
933
|
-
if (
|
|
934
|
-
const o =
|
|
937
|
+
const l = t[n];
|
|
938
|
+
this.removeClasses(l, this.classes.highlighted);
|
|
939
|
+
const r = l.parentElement;
|
|
940
|
+
if (r && r.classList.contains(this.classes.getFirst("mainOpen"))) {
|
|
941
|
+
const o = r.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
935
942
|
o && o.click();
|
|
936
943
|
}
|
|
937
944
|
let c = t[e === "down" ? n + 1 < t.length ? n + 1 : 0 : n - 1 >= 0 ? n - 1 : t.length - 1];
|
|
@@ -967,13 +974,13 @@ class ve {
|
|
|
967
974
|
}
|
|
968
975
|
// Take in data and add options to
|
|
969
976
|
renderOptions(e) {
|
|
970
|
-
if (this.content.list.innerHTML = "", e.length === 0) {
|
|
977
|
+
if (this.lastRenderedOptions = e.map((s) => s instanceof b ? [s] : s.options.map((i) => new b(i))).flat(), this.content.list.innerHTML = "", e.length === 0) {
|
|
971
978
|
const s = document.createElement("div");
|
|
972
979
|
this.addClasses(s, this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
|
|
973
980
|
return;
|
|
974
981
|
}
|
|
975
982
|
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
|
|
976
|
-
new
|
|
983
|
+
new b({
|
|
977
984
|
text: "",
|
|
978
985
|
value: "",
|
|
979
986
|
selected: !1,
|
|
@@ -988,10 +995,10 @@ class ve {
|
|
|
988
995
|
this.addClasses(i, this.classes.optgroup);
|
|
989
996
|
const n = document.createElement("div");
|
|
990
997
|
this.addClasses(n, this.classes.optgroupLabel), i.appendChild(n);
|
|
991
|
-
const r = document.createElement("div");
|
|
992
|
-
this.addClasses(r, this.classes.optgroupLabelText), r.textContent = s.label, n.appendChild(r);
|
|
993
998
|
const l = document.createElement("div");
|
|
994
|
-
|
|
999
|
+
this.addClasses(l, this.classes.optgroupLabelText), l.textContent = s.label, n.appendChild(l);
|
|
1000
|
+
const r = document.createElement("div");
|
|
1001
|
+
if (this.addClasses(r, this.classes.optgroupActions), n.appendChild(r), this.settings.isMultiple && s.selectAll) {
|
|
995
1002
|
const c = document.createElement("div");
|
|
996
1003
|
this.addClasses(c, this.classes.optgroupSelectAll);
|
|
997
1004
|
let h = !0;
|
|
@@ -1024,11 +1031,11 @@ class ve {
|
|
|
1024
1031
|
let A = s.options.map((v) => v.id).filter((v) => v !== void 0);
|
|
1025
1032
|
const S = g.concat(A);
|
|
1026
1033
|
for (const v of s.options)
|
|
1027
|
-
v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new
|
|
1034
|
+
v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new b(v));
|
|
1028
1035
|
this.callbacks.setSelected(S, !0);
|
|
1029
1036
|
return;
|
|
1030
1037
|
}
|
|
1031
|
-
}),
|
|
1038
|
+
}), r.appendChild(c);
|
|
1032
1039
|
}
|
|
1033
1040
|
if (s.closable !== "off") {
|
|
1034
1041
|
const c = document.createElement("div");
|
|
@@ -1038,13 +1045,13 @@ class ve {
|
|
|
1038
1045
|
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1039
1046
|
h.appendChild(o), s.options.some((d) => d.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(c, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (this.addClasses(i, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (this.addClasses(i, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), n.addEventListener("click", (d) => {
|
|
1040
1047
|
d.preventDefault(), d.stopPropagation(), i.classList.contains(this.classes.getFirst("close")) ? (this.removeClasses(i, this.classes.close), this.addClasses(i, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : (this.removeClasses(i, this.classes.mainOpen), this.addClasses(i, this.classes.close), o.setAttribute("d", this.classes.arrowClose));
|
|
1041
|
-
}),
|
|
1048
|
+
}), r.appendChild(c);
|
|
1042
1049
|
}
|
|
1043
1050
|
i.appendChild(n);
|
|
1044
1051
|
for (const c of s.options)
|
|
1045
|
-
i.appendChild(this.option(new
|
|
1052
|
+
i.appendChild(this.option(new b(c))), t.appendChild(i);
|
|
1046
1053
|
}
|
|
1047
|
-
s instanceof
|
|
1054
|
+
s instanceof b && t.appendChild(this.option(s));
|
|
1048
1055
|
}
|
|
1049
1056
|
this.content.list.appendChild(t);
|
|
1050
1057
|
}
|
|
@@ -1063,25 +1070,25 @@ class ve {
|
|
|
1063
1070
|
this.classes.searchHighlighter
|
|
1064
1071
|
) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display || this.addClasses(t, this.classes.hide), e.disabled && this.addClasses(t, this.classes.disabled), e.selected && this.settings.hideSelected && this.addClasses(t, this.classes.hide), e.selected ? (this.addClasses(t, this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (this.removeClasses(t, this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (s) => {
|
|
1065
1072
|
s.preventDefault(), s.stopPropagation();
|
|
1066
|
-
const i = this.store.getSelected(), n = s.currentTarget,
|
|
1067
|
-
if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !
|
|
1073
|
+
const i = this.store.getSelected(), n = s.currentTarget, l = String(n.dataset.id), r = s.ctrlKey || s.metaKey;
|
|
1074
|
+
if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !r)
|
|
1068
1075
|
return;
|
|
1069
1076
|
let c = !1;
|
|
1070
1077
|
const h = this.store.getSelectedOptions();
|
|
1071
1078
|
let o = [];
|
|
1072
1079
|
if (this.settings.isMultiple) {
|
|
1073
|
-
const d = h.some((f) => f.id ===
|
|
1080
|
+
const d = h.some((f) => f.id === l);
|
|
1074
1081
|
if (s.shiftKey && this.lastSelectedOption) {
|
|
1075
|
-
const f = this.
|
|
1082
|
+
const f = this.lastRenderedOptions, E = f.findIndex((A) => A.id === this.lastSelectedOption.id), g = f.findIndex((A) => A.id === e.id);
|
|
1076
1083
|
if (E >= 0 && g >= 0) {
|
|
1077
|
-
const A = Math.min(E, g), S = Math.max(E, g), k = f.slice(A, S + 1).filter((L) => !h.find((
|
|
1084
|
+
const A = Math.min(E, g), S = Math.max(E, g), k = f.slice(A, S + 1).filter((L) => !h.find((C) => C.id === L.id));
|
|
1078
1085
|
h.length + k.length <= this.settings.maxSelected ? o = h.concat(k) : o = h;
|
|
1079
1086
|
} else
|
|
1080
1087
|
o = h;
|
|
1081
|
-
} else
|
|
1088
|
+
} else r ? (d ? o = h.filter((f) => f.id !== l) : o = h.concat(e), this.lastSelectedOption = e) : (d ? o = h.filter((f) => f.id !== l) : o = h.concat(e), this.lastSelectedOption = e);
|
|
1082
1089
|
}
|
|
1083
1090
|
if (this.settings.isMultiple || (e.selected ? o = [] : o = [e]), this.callbacks.beforeChange || (c = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(o, h) === !1 ? c = !1 : c = !0), c) {
|
|
1084
|
-
this.store.getOptionByID(
|
|
1091
|
+
this.store.getOptionByID(l) || this.callbacks.addOption(e), this.callbacks.setSelected(
|
|
1085
1092
|
o.map((f) => f.id),
|
|
1086
1093
|
!1
|
|
1087
1094
|
);
|
|
@@ -1097,9 +1104,9 @@ class ve {
|
|
|
1097
1104
|
const i = t.trim();
|
|
1098
1105
|
if (i === "")
|
|
1099
1106
|
return e;
|
|
1100
|
-
const n = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
|
1101
|
-
|
|
1102
|
-
const
|
|
1107
|
+
const n = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), l = document.createElement("div");
|
|
1108
|
+
l.innerHTML = e;
|
|
1109
|
+
const r = (c) => {
|
|
1103
1110
|
if (c.nodeType === Node.TEXT_NODE) {
|
|
1104
1111
|
const h = c.textContent || "", o = new RegExp("(" + n + ")", "i");
|
|
1105
1112
|
if (o.test(h)) {
|
|
@@ -1111,15 +1118,15 @@ class ve {
|
|
|
1111
1118
|
} else f && d.appendChild(document.createTextNode(f));
|
|
1112
1119
|
}), c.parentNode?.replaceChild(d, c);
|
|
1113
1120
|
}
|
|
1114
|
-
} else c.nodeType === Node.ELEMENT_NODE && Array.from(c.childNodes).forEach((h) =>
|
|
1121
|
+
} else c.nodeType === Node.ELEMENT_NODE && Array.from(c.childNodes).forEach((h) => r(h));
|
|
1115
1122
|
};
|
|
1116
|
-
return Array.from(
|
|
1123
|
+
return Array.from(l.childNodes).forEach((c) => r(c)), l.innerHTML;
|
|
1117
1124
|
}
|
|
1118
1125
|
setContentDirection(e) {
|
|
1119
1126
|
const t = e === "above", s = t ? this.classes.dirAbove : this.classes.dirBelow, i = t ? this.classes.dirBelow : this.classes.dirAbove;
|
|
1120
1127
|
if (this.removeClasses(this.main.main, i), this.addClasses(this.main.main, s), this.removeClasses(this.content.main, i), this.addClasses(this.content.main, s), t) {
|
|
1121
|
-
const n = this.main.main.offsetHeight,
|
|
1122
|
-
this.content.main.style.margin = "-" + (n +
|
|
1128
|
+
const n = this.main.main.offsetHeight, l = this.content.main.offsetHeight;
|
|
1129
|
+
this.content.main.style.margin = "-" + (n + l - 1) + "px 0px 0px 0px";
|
|
1123
1130
|
} else
|
|
1124
1131
|
this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
1125
1132
|
}
|
|
@@ -1131,10 +1138,10 @@ class ve {
|
|
|
1131
1138
|
this.settings.contentPosition === "fixed" ? (t = e.top + e.height, s = e.left) : (t = e.top + window.scrollY + e.height, s = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = s + "px";
|
|
1132
1139
|
const i = this.settings.contentWidth;
|
|
1133
1140
|
this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", i ? i.startsWith(">") ? this.content.main.style.minWidth = i.slice(1) : i.startsWith("<") ? this.content.main.style.maxWidth = i.slice(1) : this.content.main.style.width = i : this.content.main.style.width = e.width + "px";
|
|
1134
|
-
const n = 20,
|
|
1141
|
+
const n = 20, l = window.innerWidth - n, r = () => {
|
|
1135
1142
|
const h = this.content.main.getBoundingClientRect().right;
|
|
1136
|
-
if (h <=
|
|
1137
|
-
const o = h -
|
|
1143
|
+
if (h <= l) return;
|
|
1144
|
+
const o = h - l, d = parseFloat(this.content.main.style.left) || 0;
|
|
1138
1145
|
if (this.settings.contentPosition === "fixed") {
|
|
1139
1146
|
const m = Math.max(n, d - o);
|
|
1140
1147
|
this.content.main.style.left = m + "px";
|
|
@@ -1144,7 +1151,7 @@ class ve {
|
|
|
1144
1151
|
}
|
|
1145
1152
|
};
|
|
1146
1153
|
requestAnimationFrame(() => {
|
|
1147
|
-
|
|
1154
|
+
r(), requestAnimationFrame(r);
|
|
1148
1155
|
});
|
|
1149
1156
|
}
|
|
1150
1157
|
moveContentAbove() {
|
|
@@ -1154,8 +1161,8 @@ class ve {
|
|
|
1154
1161
|
this.setContentDirection("below"), this.setContentPosition();
|
|
1155
1162
|
}
|
|
1156
1163
|
ensureElementInView(e, t) {
|
|
1157
|
-
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, n = t.offsetTop,
|
|
1158
|
-
n < s ? e.scrollTop -= s - n :
|
|
1164
|
+
const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, n = t.offsetTop, l = n + t.clientHeight;
|
|
1165
|
+
n < s ? e.scrollTop -= s - n : l > i && (e.scrollTop += l - i);
|
|
1159
1166
|
}
|
|
1160
1167
|
putContent() {
|
|
1161
1168
|
const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
|
|
@@ -1165,8 +1172,8 @@ class ve {
|
|
|
1165
1172
|
updateDeselectAll() {
|
|
1166
1173
|
if (!this.store || !this.settings)
|
|
1167
1174
|
return;
|
|
1168
|
-
const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, n = this.main.deselect.main,
|
|
1169
|
-
i && !(s && !t) ? this.removeClasses(n,
|
|
1175
|
+
const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, n = this.main.deselect.main, l = this.classes.hide;
|
|
1176
|
+
i && !(s && !t) ? this.removeClasses(n, l) : this.addClasses(n, l);
|
|
1170
1177
|
}
|
|
1171
1178
|
}
|
|
1172
1179
|
class be {
|
|
@@ -1229,22 +1236,22 @@ class be {
|
|
|
1229
1236
|
if (!this.listen)
|
|
1230
1237
|
return;
|
|
1231
1238
|
let t = !1, s = !1, i = !1, n = !1;
|
|
1232
|
-
for (const
|
|
1233
|
-
if (
|
|
1234
|
-
for (const
|
|
1235
|
-
if (
|
|
1239
|
+
for (const l of e) {
|
|
1240
|
+
if (l.target === this.select && (l.attributeName === "disabled" && (s = !0), l.attributeName === "class" && (t = !0), l.type === "childList")) {
|
|
1241
|
+
for (const r of Array.from(l.addedNodes))
|
|
1242
|
+
if (r.nodeName === "OPTION" && r.value === this.select.value) {
|
|
1236
1243
|
n = !0;
|
|
1237
1244
|
break;
|
|
1238
1245
|
}
|
|
1239
1246
|
i = !0;
|
|
1240
1247
|
}
|
|
1241
|
-
(
|
|
1248
|
+
(l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
|
|
1242
1249
|
}
|
|
1243
1250
|
if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange) {
|
|
1244
1251
|
if (this.isUpdating) {
|
|
1245
1252
|
if (this.select.options.length > 0) {
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1253
|
+
const l = this.getData();
|
|
1254
|
+
l.length > 0 && (this.pendingOptionsChange = l);
|
|
1248
1255
|
}
|
|
1249
1256
|
n && this.select.dispatchEvent(new Event("change"));
|
|
1250
1257
|
return;
|
|
@@ -1301,8 +1308,8 @@ class be {
|
|
|
1301
1308
|
const i = s.childNodes;
|
|
1302
1309
|
for (const n of i)
|
|
1303
1310
|
if (n.nodeName === "OPTION") {
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1311
|
+
const l = n;
|
|
1312
|
+
l.selected && e.push(this.getDataFromOption(l));
|
|
1306
1313
|
}
|
|
1307
1314
|
}
|
|
1308
1315
|
if (s.nodeName === "OPTION") {
|
|
@@ -1321,10 +1328,10 @@ class be {
|
|
|
1321
1328
|
for (const s of t) {
|
|
1322
1329
|
if (s.nodeName === "OPTGROUP") {
|
|
1323
1330
|
const n = s.childNodes;
|
|
1324
|
-
for (const
|
|
1325
|
-
if (
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1331
|
+
for (const l of n)
|
|
1332
|
+
if (l.nodeName === "OPTION") {
|
|
1333
|
+
const r = l;
|
|
1334
|
+
r.selected = e.includes(r.id);
|
|
1328
1335
|
}
|
|
1329
1336
|
}
|
|
1330
1337
|
if (s.nodeName === "OPTION") {
|
|
@@ -1344,10 +1351,10 @@ class be {
|
|
|
1344
1351
|
for (const s of t) {
|
|
1345
1352
|
if (s.nodeName === "OPTGROUP") {
|
|
1346
1353
|
const n = s.childNodes;
|
|
1347
|
-
for (const
|
|
1348
|
-
if (
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1354
|
+
for (const l of n)
|
|
1355
|
+
if (l.nodeName === "OPTION") {
|
|
1356
|
+
const r = l;
|
|
1357
|
+
r.selected = e.includes(r.value);
|
|
1351
1358
|
}
|
|
1352
1359
|
}
|
|
1353
1360
|
if (s.nodeName === "OPTION") {
|
|
@@ -1366,7 +1373,7 @@ class be {
|
|
|
1366
1373
|
if (!(!e || e.length === 0)) {
|
|
1367
1374
|
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
1368
1375
|
for (const t of e)
|
|
1369
|
-
t instanceof x && this.select.appendChild(this.createOptgroup(t)), t instanceof
|
|
1376
|
+
t instanceof x && this.select.appendChild(this.createOptgroup(t)), t instanceof b && this.select.appendChild(this.createOption(t));
|
|
1370
1377
|
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
1371
1378
|
const t = this.pendingOptionsChange;
|
|
1372
1379
|
t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
@@ -1391,7 +1398,7 @@ class be {
|
|
|
1391
1398
|
// Find and handle labels associated with this select
|
|
1392
1399
|
setupLabelHandlers() {
|
|
1393
1400
|
const e = [], t = this.select.id;
|
|
1394
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1401
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((l) => e.push(l));
|
|
1395
1402
|
let s = this.select.parentElement;
|
|
1396
1403
|
for (; s && s !== document.body; ) {
|
|
1397
1404
|
if (s.tagName === "LABEL") {
|
|
@@ -1403,17 +1410,17 @@ class be {
|
|
|
1403
1410
|
Array.from(new Set(e)).forEach((n) => {
|
|
1404
1411
|
if (n.__slimSelectLabelHandler)
|
|
1405
1412
|
return;
|
|
1406
|
-
const
|
|
1407
|
-
const c =
|
|
1408
|
-
|
|
1413
|
+
const l = (r) => {
|
|
1414
|
+
const c = r.target, h = ie(c, this.select.dataset.id);
|
|
1415
|
+
r.preventDefault(), !h && this.onLabelClick && this.onLabelClick();
|
|
1409
1416
|
};
|
|
1410
|
-
n.__slimSelectLabelHandler =
|
|
1417
|
+
n.__slimSelectLabelHandler = l, n.addEventListener("click", l, { capture: !0, passive: !1 });
|
|
1411
1418
|
});
|
|
1412
1419
|
}
|
|
1413
1420
|
// Remove label handlers
|
|
1414
1421
|
removeLabelHandlers() {
|
|
1415
1422
|
const e = [], t = this.select.id;
|
|
1416
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((
|
|
1423
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((l) => e.push(l));
|
|
1417
1424
|
let s = this.select.parentElement;
|
|
1418
1425
|
for (; s && s !== document.body; ) {
|
|
1419
1426
|
if (s.tagName === "LABEL") {
|
|
@@ -1423,8 +1430,8 @@ class be {
|
|
|
1423
1430
|
s = s.parentElement;
|
|
1424
1431
|
}
|
|
1425
1432
|
Array.from(new Set(e)).forEach((n) => {
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1433
|
+
const l = n.__slimSelectLabelHandler;
|
|
1434
|
+
l && (n.removeEventListener("click", l, { capture: !0 }), delete n.__slimSelectLabelHandler);
|
|
1428
1435
|
});
|
|
1429
1436
|
}
|
|
1430
1437
|
destroy() {
|
|
@@ -1508,16 +1515,16 @@ let we = class {
|
|
|
1508
1515
|
}
|
|
1509
1516
|
this.selectEl.dataset.ssid && this.destroy(), this.settings = new Ce(e.settings), this.cssClasses = new pe(e.cssClasses);
|
|
1510
1517
|
const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
|
|
1511
|
-
for (const
|
|
1512
|
-
e.events.hasOwnProperty(
|
|
1513
|
-
this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new be(this.selectEl), this.selectEl.id || (this.selectEl.id = this.settings.id), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (
|
|
1514
|
-
this.setSelected(
|
|
1515
|
-
}, this.select.onClassChange = (
|
|
1516
|
-
this.settings.class =
|
|
1517
|
-
}, this.select.onDisabledChange = (
|
|
1518
|
-
|
|
1519
|
-
}, this.select.onOptionsChange = (
|
|
1520
|
-
this.setData(
|
|
1518
|
+
for (const r in e.events)
|
|
1519
|
+
e.events.hasOwnProperty(r) && (t.indexOf(r) !== -1 ? this.events[r] = H(e.events[r], 100) : this.events[r] = e.events[r]);
|
|
1520
|
+
this.settings.disabled = e.settings?.disabled ? e.settings.disabled : this.selectEl.disabled, this.settings.isMultiple = this.selectEl.multiple, this.settings.style = this.selectEl.style.cssText, this.settings.class = this.selectEl.className.split(" "), this.select = new be(this.selectEl), this.selectEl.id || (this.selectEl.id = this.settings.id), this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class), this.select.hideUI(), this.select.onValueChange = (r) => {
|
|
1521
|
+
this.setSelected(r.map((c) => c.id));
|
|
1522
|
+
}, this.select.onClassChange = (r) => {
|
|
1523
|
+
this.settings.class = r, this.render.updateClassStyles();
|
|
1524
|
+
}, this.select.onDisabledChange = (r) => {
|
|
1525
|
+
r ? this.disable() : this.enable();
|
|
1526
|
+
}, this.select.onOptionsChange = (r) => {
|
|
1527
|
+
this.setData(r || []);
|
|
1521
1528
|
}, this.select.onLabelClick = () => {
|
|
1522
1529
|
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1523
1530
|
};
|
|
@@ -1534,8 +1541,8 @@ let we = class {
|
|
|
1534
1541
|
afterChange: this.events.afterChange
|
|
1535
1542
|
};
|
|
1536
1543
|
this.render = new ve(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
|
|
1537
|
-
const n = this.selectEl.getAttribute("aria-label"),
|
|
1538
|
-
n ? this.render.main.main.setAttribute("aria-label", n) :
|
|
1544
|
+
const n = this.selectEl.getAttribute("aria-label"), l = this.selectEl.getAttribute("aria-labelledby");
|
|
1545
|
+
n ? this.render.main.main.setAttribute("aria-label", n) : l && this.render.main.main.setAttribute("aria-labelledby", l), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), window.addEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.addEventListener("scroll", this.windowScroll, !1), document.addEventListener("visibilitychange", this.windowVisibilityChange), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
|
|
1539
1546
|
}
|
|
1540
1547
|
// Set to enabled and remove disabled classes
|
|
1541
1548
|
enable() {
|
|
@@ -1567,17 +1574,17 @@ let we = class {
|
|
|
1567
1574
|
const s = this.store.getSelected(), i = this.store.getDataOptions();
|
|
1568
1575
|
e = Array.isArray(e) ? e : [e];
|
|
1569
1576
|
const n = [];
|
|
1570
|
-
for (const
|
|
1571
|
-
if (i.find((c) => c.id ==
|
|
1572
|
-
n.push(
|
|
1577
|
+
for (const r of e) {
|
|
1578
|
+
if (i.find((c) => c.id == r)) {
|
|
1579
|
+
n.push(r);
|
|
1573
1580
|
continue;
|
|
1574
1581
|
}
|
|
1575
|
-
for (const c of i.filter((h) => h.value ==
|
|
1582
|
+
for (const c of i.filter((h) => h.value == r))
|
|
1576
1583
|
n.push(c.id);
|
|
1577
1584
|
}
|
|
1578
1585
|
this.store.setSelectedBy("id", n);
|
|
1579
|
-
const
|
|
1580
|
-
this.select.updateOptions(
|
|
1586
|
+
const l = this.store.getData();
|
|
1587
|
+
this.select.updateOptions(l), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(l), t && this.events.afterChange && !Y(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1581
1588
|
}
|
|
1582
1589
|
addOption(e) {
|
|
1583
1590
|
const t = this.store.getSelected();
|
|
@@ -1637,16 +1644,16 @@ let we = class {
|
|
|
1637
1644
|
};
|
|
1638
1645
|
};
|
|
1639
1646
|
const Se = oe(
|
|
1640
|
-
({ data: p, settings: e, events: t, cssClasses: s, value: i, onChange: n, children:
|
|
1647
|
+
({ data: p, settings: e, events: t, cssClasses: s, value: i, onChange: n, children: l, multiple: r }, c) => {
|
|
1641
1648
|
const h = I(null), o = I(null), d = I(!0), m = I(i);
|
|
1642
1649
|
ce(c, () => ({
|
|
1643
1650
|
slimSelect: o.current
|
|
1644
1651
|
}));
|
|
1645
|
-
const f = (g) => typeof g == "string" ?
|
|
1652
|
+
const f = (g) => typeof g == "string" ? r ? [g] : g : Array.isArray(g) ? r ? g : g[0] : r ? [] : "", E = (g, A = !1) => {
|
|
1646
1653
|
if (!o.current || g === void 0)
|
|
1647
1654
|
return;
|
|
1648
|
-
const S = f(g), k = o.current.getData().flatMap((
|
|
1649
|
-
if (!(Array.isArray(S) ? S.length > 0 && S.every((
|
|
1655
|
+
const S = f(g), k = o.current.getData().flatMap((C) => "label" in C ? C.options : [C]);
|
|
1656
|
+
if (!(Array.isArray(S) ? S.length > 0 && S.every((C) => k.some((D) => D.value === C)) : S !== "" && k.some((C) => C.value === S)) && !Array.isArray(S) && !k.some((D) => D.placeholder)) {
|
|
1650
1657
|
const D = o.current.getData(), P = {
|
|
1651
1658
|
value: "",
|
|
1652
1659
|
text: "",
|
|
@@ -1667,9 +1674,9 @@ const Se = oe(
|
|
|
1667
1674
|
...t,
|
|
1668
1675
|
afterChange: (S) => {
|
|
1669
1676
|
if (!o.current) return;
|
|
1670
|
-
const v =
|
|
1677
|
+
const v = r ? S.map((T) => T.value) : S[0]?.value ?? "", L = o.current.getData().flatMap(
|
|
1671
1678
|
(T) => "label" in T ? T.options : [T]
|
|
1672
|
-
),
|
|
1679
|
+
), C = m.current, D = C === void 0 ? !1 : Array.isArray(C) ? C.length > 0 && C.every((T) => L.some((R) => R.value === T)) : C !== "" && L.some((T) => T.value === C), P = Array.isArray(v) ? v.length > 0 && v.every((T) => L.some((R) => R.value === T)) : v !== "" && L.some((T) => T.value === v), B = Array.isArray(v) && Array.isArray(C) ? JSON.stringify(v.sort()) !== JSON.stringify(C.sort()) : C !== v;
|
|
1673
1680
|
n && B && (D || P) && (n(v), m.current = v), A && A(S);
|
|
1674
1681
|
}
|
|
1675
1682
|
}, o.current = new we(g), i !== void 0 && E(i, !1), () => {
|
|
@@ -1683,13 +1690,13 @@ const Se = oe(
|
|
|
1683
1690
|
o.current && i !== void 0 && (m.current = i, E(i, !1));
|
|
1684
1691
|
}, [i]), $(() => {
|
|
1685
1692
|
o.current && p && !d.current && (o.current.setData(p), i !== void 0 && E(i, !1));
|
|
1686
|
-
}, [p]), /* @__PURE__ */ fe.jsx("select", { ref: h, multiple:
|
|
1693
|
+
}, [p]), /* @__PURE__ */ fe.jsx("select", { ref: h, multiple: r, children: l });
|
|
1687
1694
|
}
|
|
1688
1695
|
);
|
|
1689
1696
|
Se.displayName = "SlimSelect";
|
|
1690
1697
|
export {
|
|
1691
1698
|
x as Optgroup,
|
|
1692
|
-
|
|
1699
|
+
b as Option,
|
|
1693
1700
|
Ce as Settings,
|
|
1694
1701
|
Se as default
|
|
1695
1702
|
};
|