slim-select 3.4.3 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes.d.ts +47 -0
- package/dist/helpers.d.ts +5 -0
- package/dist/index.d.ts +53 -319
- package/dist/index.umd.d.ts +2 -0
- package/dist/react/index.d.ts +4 -319
- package/dist/react/index.js +1471 -1697
- package/dist/react/index.umd.js +2 -2
- package/dist/react/react.d.ts +17 -0
- package/dist/react/react.test.d.ts +1 -0
- package/dist/react/slim-select/react/index.d.ts +4 -0
- package/dist/render.d.ts +90 -0
- package/dist/select.d.ts +38 -0
- package/dist/settings.d.ts +40 -0
- package/dist/slimselect.cjs.js +2 -2
- package/dist/slimselect.cjs.js.map +1 -1
- package/dist/slimselect.css +1 -1
- package/dist/slimselect.css.map +1 -1
- package/dist/slimselect.es.js +1245 -1385
- package/dist/slimselect.es.js.map +1 -1
- package/dist/slimselect.iife.js +2 -2
- package/dist/slimselect.iife.js.map +1 -1
- package/dist/slimselect.js +2 -2
- package/dist/slimselect.js.map +1 -1
- package/dist/src/docs/main.d.ts +0 -0
- package/dist/src/docs/router.d.ts +2 -0
- package/dist/src/docs/store.d.ts +12 -0
- package/dist/store.d.ts +53 -0
- package/dist/vue/index.d.ts +4 -319
- package/dist/vue/index.js +1347 -1504
- package/dist/vue/index.umd.js +1 -1
- package/dist/vue/slim-select/vue/index.d.ts +4 -0
- package/package.json +30 -36
- package/src/slim-select/slimselect.scss +47 -5
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -7
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -1
- package/cdn.html +0 -21
- package/docs.go +0 -12
- package/example.html +0 -25
- package/index.html +0 -76
- package/release.js +0 -191
- package/sitemap.js +0 -108
- package/src/slim-select/accessibility.test.ts +0 -782
- package/src/slim-select/classes.test.ts +0 -73
- package/src/slim-select/classes.ts +0 -117
- package/src/slim-select/helpers.test.ts +0 -162
- package/src/slim-select/helpers.ts +0 -61
- package/src/slim-select/index.test.ts +0 -1356
- package/src/slim-select/index.ts +0 -594
- package/src/slim-select/index.umd.ts +0 -8
- package/src/slim-select/react/index.tsx +0 -9
- package/src/slim-select/react/react.test.tsx +0 -498
- package/src/slim-select/react/react.tsx +0 -209
- package/src/slim-select/render.test.ts +0 -1927
- package/src/slim-select/render.ts +0 -1771
- package/src/slim-select/select.test.ts +0 -683
- package/src/slim-select/select.ts +0 -659
- package/src/slim-select/settings.test.ts +0 -285
- package/src/slim-select/settings.ts +0 -78
- package/src/slim-select/store.test.ts +0 -1007
- package/src/slim-select/store.ts +0 -433
- package/src/slim-select/vue/index.ts +0 -9
- package/src/slim-select/vue/vue.test.ts +0 -1091
- package/src/slim-select/vue/vue.vue +0 -224
- package/tsconfig.json +0 -26
- package/vite.config.docs.mts +0 -29
- package/vite.config.lib.es-cjs.ts +0 -40
- package/vite.config.lib.umd-iife.ts +0 -34
- package/vite.config.react.mts +0 -41
- package/vite.config.vue.mts +0 -40
- package/vitest.config.ts +0 -30
package/dist/react/index.js
CHANGED
|
@@ -1,1702 +1,1476 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
var
|
|
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
|
-
case T:
|
|
64
|
-
u = a._payload, a = a._init;
|
|
65
|
-
try {
|
|
66
|
-
return p(a(u));
|
|
67
|
-
} catch {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
function e(a) {
|
|
73
|
-
return "" + a;
|
|
74
|
-
}
|
|
75
|
-
function t(a) {
|
|
76
|
-
try {
|
|
77
|
-
e(a);
|
|
78
|
-
var u = !1;
|
|
79
|
-
} catch {
|
|
80
|
-
u = !0;
|
|
81
|
-
}
|
|
82
|
-
if (u) {
|
|
83
|
-
u = console;
|
|
84
|
-
var w = u.error, O = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
|
|
85
|
-
return w.call(
|
|
86
|
-
u,
|
|
87
|
-
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
-
O
|
|
89
|
-
), e(a);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function s(a) {
|
|
93
|
-
if (a === A) return "<>";
|
|
94
|
-
if (typeof a == "object" && a !== null && a.$$typeof === T)
|
|
95
|
-
return "<...>";
|
|
96
|
-
try {
|
|
97
|
-
var u = p(a);
|
|
98
|
-
return u ? "<" + u + ">" : "<...>";
|
|
99
|
-
} catch {
|
|
100
|
-
return "<...>";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function i() {
|
|
104
|
-
var a = j.A;
|
|
105
|
-
return a === null ? null : a.getOwner();
|
|
106
|
-
}
|
|
107
|
-
function n() {
|
|
108
|
-
return Error("react-stack-top-frame");
|
|
109
|
-
}
|
|
110
|
-
function l(a) {
|
|
111
|
-
if (J.call(a, "key")) {
|
|
112
|
-
var u = Object.getOwnPropertyDescriptor(a, "key").get;
|
|
113
|
-
if (u && u.isReactWarning) return !1;
|
|
114
|
-
}
|
|
115
|
-
return a.key !== void 0;
|
|
116
|
-
}
|
|
117
|
-
function r(a, u) {
|
|
118
|
-
function w() {
|
|
119
|
-
G || (G = !0, console.error(
|
|
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
|
-
u
|
|
122
|
-
));
|
|
123
|
-
}
|
|
124
|
-
w.isReactWarning = !0, Object.defineProperty(a, "key", {
|
|
125
|
-
get: w,
|
|
126
|
-
configurable: !0
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function c() {
|
|
130
|
-
var a = p(this.type);
|
|
131
|
-
return X[a] || (X[a] = !0, console.error(
|
|
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
|
-
)), a = this.props.ref, a !== void 0 ? a : null;
|
|
134
|
-
}
|
|
135
|
-
function h(a, u, w, O, F, U) {
|
|
136
|
-
var y = w.ref;
|
|
137
|
-
return a = {
|
|
138
|
-
$$typeof: E,
|
|
139
|
-
type: a,
|
|
140
|
-
key: u,
|
|
141
|
-
props: w,
|
|
142
|
-
_owner: O
|
|
143
|
-
}, (y !== void 0 ? y : null) !== null ? Object.defineProperty(a, "ref", {
|
|
144
|
-
enumerable: !1,
|
|
145
|
-
get: c
|
|
146
|
-
}) : Object.defineProperty(a, "ref", { enumerable: !1, value: null }), a._store = {}, Object.defineProperty(a._store, "validated", {
|
|
147
|
-
configurable: !1,
|
|
148
|
-
enumerable: !1,
|
|
149
|
-
writable: !0,
|
|
150
|
-
value: 0
|
|
151
|
-
}), Object.defineProperty(a, "_debugInfo", {
|
|
152
|
-
configurable: !1,
|
|
153
|
-
enumerable: !1,
|
|
154
|
-
writable: !0,
|
|
155
|
-
value: null
|
|
156
|
-
}), Object.defineProperty(a, "_debugStack", {
|
|
157
|
-
configurable: !1,
|
|
158
|
-
enumerable: !1,
|
|
159
|
-
writable: !0,
|
|
160
|
-
value: F
|
|
161
|
-
}), Object.defineProperty(a, "_debugTask", {
|
|
162
|
-
configurable: !1,
|
|
163
|
-
enumerable: !1,
|
|
164
|
-
writable: !0,
|
|
165
|
-
value: U
|
|
166
|
-
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
|
|
167
|
-
}
|
|
168
|
-
function o(a, u, w, O, F, U) {
|
|
169
|
-
var y = u.children;
|
|
170
|
-
if (y !== void 0)
|
|
171
|
-
if (O)
|
|
172
|
-
if (le(y)) {
|
|
173
|
-
for (O = 0; O < y.length; O++)
|
|
174
|
-
d(y[O]);
|
|
175
|
-
Object.freeze && Object.freeze(y);
|
|
176
|
-
} else
|
|
177
|
-
console.error(
|
|
178
|
-
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
-
);
|
|
180
|
-
else d(y);
|
|
181
|
-
if (J.call(u, "key")) {
|
|
182
|
-
y = p(a);
|
|
183
|
-
var N = Object.keys(u).filter(function(ae) {
|
|
184
|
-
return ae !== "key";
|
|
185
|
-
});
|
|
186
|
-
O = 0 < N.length ? "{key: someKey, " + N.join(": ..., ") + ": ...}" : "{key: someKey}", Q[y + O] || (N = 0 < N.length ? "{" + N.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
-
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
-
let props = %s;
|
|
189
|
-
<%s {...props} />
|
|
190
|
-
React keys must be passed directly to JSX without using spread:
|
|
191
|
-
let props = %s;
|
|
192
|
-
<%s key={someKey} {...props} />`,
|
|
193
|
-
O,
|
|
194
|
-
y,
|
|
195
|
-
N,
|
|
196
|
-
y
|
|
197
|
-
), Q[y + O] = !0);
|
|
198
|
-
}
|
|
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
|
-
for (var W in u)
|
|
202
|
-
W !== "key" && (w[W] = u[W]);
|
|
203
|
-
} else w = u;
|
|
204
|
-
return y && r(
|
|
205
|
-
w,
|
|
206
|
-
typeof a == "function" ? a.displayName || a.name || "Unknown" : a
|
|
207
|
-
), h(
|
|
208
|
-
a,
|
|
209
|
-
y,
|
|
210
|
-
w,
|
|
211
|
-
i(),
|
|
212
|
-
F,
|
|
213
|
-
U
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
function d(a) {
|
|
217
|
-
m(a) ? a._store && (a._store.validated = 1) : typeof a == "object" && a !== null && a.$$typeof === T && (a._payload.status === "fulfilled" ? m(a._payload.value) && a._payload.value._store && (a._payload.value._store.validated = 1) : a._store && (a._store.validated = 1));
|
|
218
|
-
}
|
|
219
|
-
function m(a) {
|
|
220
|
-
return typeof a == "object" && a !== null && a.$$typeof === E;
|
|
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"), 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
|
-
return null;
|
|
224
|
-
};
|
|
225
|
-
f = {
|
|
226
|
-
react_stack_bottom_frame: function(a) {
|
|
227
|
-
return a();
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
var G, X = {}, K = f.react_stack_bottom_frame.bind(
|
|
231
|
-
f,
|
|
232
|
-
n
|
|
233
|
-
)(), Z = q(s(n)), Q = {};
|
|
234
|
-
_.Fragment = A, _.jsx = function(a, u, w) {
|
|
235
|
-
var O = 1e4 > j.recentlyCreatedOwnerStacks++;
|
|
236
|
-
return o(
|
|
237
|
-
a,
|
|
238
|
-
u,
|
|
239
|
-
w,
|
|
240
|
-
!1,
|
|
241
|
-
O ? Error("react-stack-top-frame") : K,
|
|
242
|
-
O ? q(s(a)) : Z
|
|
243
|
-
);
|
|
244
|
-
}, _.jsxs = function(a, u, w) {
|
|
245
|
-
var O = 1e4 > j.recentlyCreatedOwnerStacks++;
|
|
246
|
-
return o(
|
|
247
|
-
a,
|
|
248
|
-
u,
|
|
249
|
-
w,
|
|
250
|
-
!0,
|
|
251
|
-
O ? Error("react-stack-top-frame") : K,
|
|
252
|
-
O ? q(s(a)) : Z
|
|
253
|
-
);
|
|
254
|
-
};
|
|
255
|
-
})()), _;
|
|
256
|
-
}
|
|
257
|
-
var se;
|
|
258
|
-
function ue() {
|
|
259
|
-
return se || (se = 1, process.env.NODE_ENV === "production" ? V.exports = he() : V.exports = de()), V.exports;
|
|
260
|
-
}
|
|
261
|
-
var fe = ue();
|
|
262
|
-
class pe {
|
|
263
|
-
main;
|
|
264
|
-
// Placeholder
|
|
265
|
-
placeholder;
|
|
266
|
-
// Values
|
|
267
|
-
values;
|
|
268
|
-
single;
|
|
269
|
-
max;
|
|
270
|
-
value;
|
|
271
|
-
valueText;
|
|
272
|
-
valueDelete;
|
|
273
|
-
valueOut;
|
|
274
|
-
// Deselect
|
|
275
|
-
deselect;
|
|
276
|
-
deselectPath;
|
|
277
|
-
// Not a class but whatever
|
|
278
|
-
// Arrow
|
|
279
|
-
arrow;
|
|
280
|
-
arrowClose;
|
|
281
|
-
// Not a class but whatever
|
|
282
|
-
arrowOpen;
|
|
283
|
-
// Not a class but whatever
|
|
284
|
-
// Content
|
|
285
|
-
content;
|
|
286
|
-
contentOpen;
|
|
287
|
-
dirAbove;
|
|
288
|
-
dirBelow;
|
|
289
|
-
// Search
|
|
290
|
-
search;
|
|
291
|
-
searchHighlighter;
|
|
292
|
-
searching;
|
|
293
|
-
addable;
|
|
294
|
-
addablePath;
|
|
295
|
-
// Not a class but whatever
|
|
296
|
-
// List optgroups/options
|
|
297
|
-
list;
|
|
298
|
-
// Optgroup
|
|
299
|
-
optgroup;
|
|
300
|
-
optgroupLabel;
|
|
301
|
-
optgroupLabelText;
|
|
302
|
-
optgroupActions;
|
|
303
|
-
optgroupSelectAll;
|
|
304
|
-
// optgroup select all
|
|
305
|
-
optgroupSelectAllBox;
|
|
306
|
-
// Not a class but whatever
|
|
307
|
-
optgroupSelectAllCheck;
|
|
308
|
-
// Not a class but whatever
|
|
309
|
-
optgroupClosable;
|
|
310
|
-
// Option
|
|
311
|
-
option;
|
|
312
|
-
optionDelete;
|
|
313
|
-
// Not a class but whatever
|
|
314
|
-
highlighted;
|
|
315
|
-
// Misc
|
|
316
|
-
mainOpen;
|
|
317
|
-
close;
|
|
318
|
-
selected;
|
|
319
|
-
error;
|
|
320
|
-
disabled;
|
|
321
|
-
hide;
|
|
322
|
-
constructor(e) {
|
|
323
|
-
e || (e = {});
|
|
324
|
-
let t = (s = "", i = "") => `${s} ${i}`.trim();
|
|
325
|
-
this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
|
|
326
|
-
}
|
|
327
|
-
getFirst(e) {
|
|
328
|
-
return this[e].split(" ")[0];
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function z() {
|
|
332
|
-
return Math.random().toString(36).substring(2, 10);
|
|
333
|
-
}
|
|
334
|
-
function ie(p, e) {
|
|
335
|
-
function t(i, n) {
|
|
336
|
-
return n && i && i.classList && i.classList.contains(n) || n && i && i.dataset && i.dataset.id && i.dataset.id === e ? i : null;
|
|
337
|
-
}
|
|
338
|
-
function s(i, n) {
|
|
339
|
-
return !i || i === document ? null : t(i, n) ? i : s(i.parentNode, n);
|
|
340
|
-
}
|
|
341
|
-
return t(p, e) || s(p, e);
|
|
342
|
-
}
|
|
343
|
-
function H(p, e = 50, t = !1) {
|
|
344
|
-
let s;
|
|
345
|
-
return function(...i) {
|
|
346
|
-
const n = self, l = () => {
|
|
347
|
-
s = null, t || p.apply(n, i);
|
|
348
|
-
}, r = t && !s;
|
|
349
|
-
clearTimeout(s), s = setTimeout(l, e), r && p.apply(n, i);
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function Y(p, e) {
|
|
353
|
-
return JSON.stringify(p) === JSON.stringify(e);
|
|
354
|
-
}
|
|
355
|
-
function me(p) {
|
|
356
|
-
const e = p.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (t) => "-" + t.toLowerCase());
|
|
357
|
-
return p[0] === p[0].toUpperCase() ? e.substring(1) : e;
|
|
358
|
-
}
|
|
359
|
-
class b {
|
|
360
|
-
id;
|
|
361
|
-
value;
|
|
362
|
-
text;
|
|
363
|
-
html;
|
|
364
|
-
defaultSelected;
|
|
365
|
-
selected;
|
|
366
|
-
display;
|
|
367
|
-
disabled;
|
|
368
|
-
placeholder;
|
|
369
|
-
class;
|
|
370
|
-
style;
|
|
371
|
-
data;
|
|
372
|
-
mandatory;
|
|
373
|
-
constructor(e) {
|
|
374
|
-
this.id = !e.id || e.id === "" ? z() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected !== void 0 ? e.defaultSelected : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
class x {
|
|
378
|
-
id;
|
|
379
|
-
label;
|
|
380
|
-
selectAll;
|
|
381
|
-
selectAllText;
|
|
382
|
-
closable;
|
|
383
|
-
options;
|
|
384
|
-
constructor(e) {
|
|
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
|
-
for (const t of e.options)
|
|
387
|
-
this.options.push(new b(t));
|
|
388
|
-
}
|
|
1
|
+
import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r } from "react";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var i = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
4
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
5
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
+
}), o = class {
|
|
7
|
+
main;
|
|
8
|
+
placeholder;
|
|
9
|
+
values;
|
|
10
|
+
single;
|
|
11
|
+
multiString;
|
|
12
|
+
max;
|
|
13
|
+
value;
|
|
14
|
+
valueText;
|
|
15
|
+
valueDelete;
|
|
16
|
+
valueOut;
|
|
17
|
+
deselect;
|
|
18
|
+
deselectPath;
|
|
19
|
+
arrow;
|
|
20
|
+
arrowClose;
|
|
21
|
+
arrowOpen;
|
|
22
|
+
content;
|
|
23
|
+
contentOpen;
|
|
24
|
+
dirAbove;
|
|
25
|
+
dirBelow;
|
|
26
|
+
search;
|
|
27
|
+
searchHighlighter;
|
|
28
|
+
searching;
|
|
29
|
+
status;
|
|
30
|
+
addable;
|
|
31
|
+
addablePath;
|
|
32
|
+
list;
|
|
33
|
+
optgroup;
|
|
34
|
+
optgroupLabel;
|
|
35
|
+
optgroupLabelText;
|
|
36
|
+
optgroupActions;
|
|
37
|
+
optgroupSelectAll;
|
|
38
|
+
optgroupSelectAllBox;
|
|
39
|
+
optgroupSelectAllCheck;
|
|
40
|
+
optgroupClosable;
|
|
41
|
+
option;
|
|
42
|
+
optionDelete;
|
|
43
|
+
highlighted;
|
|
44
|
+
mainOpen;
|
|
45
|
+
close;
|
|
46
|
+
selected;
|
|
47
|
+
error;
|
|
48
|
+
disabled;
|
|
49
|
+
hide;
|
|
50
|
+
constructor(e) {
|
|
51
|
+
e ||= {};
|
|
52
|
+
let t = (e = "", t = "") => `${e} ${t}`.trim();
|
|
53
|
+
this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
|
|
54
|
+
}
|
|
55
|
+
getFirst(e) {
|
|
56
|
+
return this[e].split(" ")[0];
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/slim-select/helpers.ts
|
|
61
|
+
function s() {
|
|
62
|
+
return Math.random().toString(36).substring(2, 10);
|
|
389
63
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
// Validate DataArrayPartial
|
|
399
|
-
validateDataArray(e) {
|
|
400
|
-
if (!Array.isArray(e))
|
|
401
|
-
return new Error("Data must be an array");
|
|
402
|
-
for (let t of e)
|
|
403
|
-
if (t)
|
|
404
|
-
if (t instanceof x || "label" in t) {
|
|
405
|
-
if (!("label" in t))
|
|
406
|
-
return new Error("Optgroup must have a label");
|
|
407
|
-
if ("options" in t && t.options)
|
|
408
|
-
for (let s of t.options) {
|
|
409
|
-
const i = this.validateOption(s);
|
|
410
|
-
if (i)
|
|
411
|
-
return i;
|
|
412
|
-
}
|
|
413
|
-
} else if (t instanceof b || "text" in t) {
|
|
414
|
-
const s = this.validateOption(t);
|
|
415
|
-
if (s)
|
|
416
|
-
return s;
|
|
417
|
-
} else
|
|
418
|
-
return new Error("Data object must be a valid optgroup or option");
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
// Validate Option
|
|
422
|
-
validateOption(e) {
|
|
423
|
-
return "text" in e ? null : new Error("Option must have a text");
|
|
424
|
-
}
|
|
425
|
-
partialToFullData(e) {
|
|
426
|
-
let t = [];
|
|
427
|
-
return e.forEach((s) => {
|
|
428
|
-
if (s) {
|
|
429
|
-
if (s instanceof x || "label" in s) {
|
|
430
|
-
let i = [];
|
|
431
|
-
"options" in s && s.options && s.options.forEach((n) => {
|
|
432
|
-
i.push(new b(n));
|
|
433
|
-
}), i.length > 0 && t.push(new x(s));
|
|
434
|
-
}
|
|
435
|
-
(s instanceof b || "text" in s) && t.push(new b(s));
|
|
436
|
-
}
|
|
437
|
-
}), t;
|
|
438
|
-
}
|
|
439
|
-
setData(e, t = !1) {
|
|
440
|
-
const s = this.partialToFullData(e);
|
|
441
|
-
let i = [];
|
|
442
|
-
if (t) {
|
|
443
|
-
i = this.getSelectedOptions();
|
|
444
|
-
const n = [];
|
|
445
|
-
i.forEach((l) => {
|
|
446
|
-
let r = !1;
|
|
447
|
-
for (const c of s) {
|
|
448
|
-
if (c instanceof b && c.id === l.id) {
|
|
449
|
-
r = !0;
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
if (c instanceof x) {
|
|
453
|
-
for (const h of c.options)
|
|
454
|
-
if (h.id === l.id) {
|
|
455
|
-
r = !0;
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
r || n.push(l);
|
|
461
|
-
}), this.data = [...n, ...s];
|
|
462
|
-
} else
|
|
463
|
-
this.data = s;
|
|
464
|
-
if (this.selectType === "single") {
|
|
465
|
-
const n = t && i.length === 0;
|
|
466
|
-
this.setSelectedBy("id", this.getSelected(), n);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
// Get data will return all the data
|
|
470
|
-
getData() {
|
|
471
|
-
return this.filter(null, !0);
|
|
472
|
-
}
|
|
473
|
-
// Get data options will return the data as a
|
|
474
|
-
// flat array of just options
|
|
475
|
-
getDataOptions() {
|
|
476
|
-
return this.filter(null, !1);
|
|
477
|
-
}
|
|
478
|
-
addOption(e, t = !1) {
|
|
479
|
-
if (t) {
|
|
480
|
-
let s = [new b(e)];
|
|
481
|
-
this.setData(s.concat(this.getData()));
|
|
482
|
-
} else
|
|
483
|
-
this.setData(this.getData().concat(new b(e)));
|
|
484
|
-
}
|
|
485
|
-
// Pass in an array of id that will loop through
|
|
486
|
-
// each option and set the selected property to true
|
|
487
|
-
// but also clean selected by determining selectType
|
|
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));
|
|
498
|
-
}
|
|
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)));
|
|
500
|
-
}
|
|
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 || "");
|
|
503
|
-
this.selectedOrder = r;
|
|
504
|
-
}
|
|
505
|
-
getSelected() {
|
|
506
|
-
return this.getSelectedOptions().map((e) => e.id);
|
|
507
|
-
}
|
|
508
|
-
getSelectedValues() {
|
|
509
|
-
return this.getSelectedOptions().map((e) => e.value);
|
|
510
|
-
}
|
|
511
|
-
getSelectedOptions() {
|
|
512
|
-
return this.filter((e) => e.selected, !1);
|
|
513
|
-
}
|
|
514
|
-
getOptgroupByID(e) {
|
|
515
|
-
for (let t of this.data)
|
|
516
|
-
if (t instanceof x && t.id === e)
|
|
517
|
-
return t;
|
|
518
|
-
return null;
|
|
519
|
-
}
|
|
520
|
-
getOptionByID(e) {
|
|
521
|
-
let t = this.filter((s) => s.id === e, !1);
|
|
522
|
-
return t.length ? t[0] : null;
|
|
523
|
-
}
|
|
524
|
-
getSelectType() {
|
|
525
|
-
return this.selectType;
|
|
526
|
-
}
|
|
527
|
-
getFirstOption() {
|
|
528
|
-
let e = null;
|
|
529
|
-
for (let t of this.data)
|
|
530
|
-
if (t instanceof x ? e = t.options[0] : t instanceof b && (e = t), e)
|
|
531
|
-
break;
|
|
532
|
-
return e;
|
|
533
|
-
}
|
|
534
|
-
// Take in search string and return filtered list of values
|
|
535
|
-
search(e, t) {
|
|
536
|
-
return e = e.trim(), e === "" ? this.getData() : this.filter((s) => t(s, e), !0);
|
|
537
|
-
}
|
|
538
|
-
// Filter takes in a function that will be used to filter the data
|
|
539
|
-
// This will also keep optgroups of sub options meet the filter requirements
|
|
540
|
-
filter(e, t) {
|
|
541
|
-
const s = [];
|
|
542
|
-
return this.data.forEach((i) => {
|
|
543
|
-
if (i instanceof x) {
|
|
544
|
-
let n = [];
|
|
545
|
-
if (i.options.forEach((r) => {
|
|
546
|
-
(!e || e(r)) && (t ? n.push(new b(r)) : s.push(new b(r)));
|
|
547
|
-
}), n.length > 0) {
|
|
548
|
-
let r = new x(i);
|
|
549
|
-
r.options = n, s.push(r);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
i instanceof b && (!e || e(i)) && s.push(new b(i));
|
|
553
|
-
}), s;
|
|
554
|
-
}
|
|
555
|
-
// Take in an array of options and reoder them based upon the selected order
|
|
556
|
-
selectedOrderOptions(e) {
|
|
557
|
-
const t = [];
|
|
558
|
-
return this.selectedOrder.forEach((s) => {
|
|
559
|
-
const i = e.find((n) => n.id === s);
|
|
560
|
-
i && t.push(i);
|
|
561
|
-
}), e.forEach((s) => {
|
|
562
|
-
let i = !1;
|
|
563
|
-
t.forEach((n) => {
|
|
564
|
-
if (s.id === n.id) {
|
|
565
|
-
i = !0;
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
}), i || t.push(s);
|
|
569
|
-
}), t;
|
|
570
|
-
}
|
|
64
|
+
function c(e, t) {
|
|
65
|
+
function n(e, n) {
|
|
66
|
+
return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
|
|
67
|
+
}
|
|
68
|
+
function r(e, t) {
|
|
69
|
+
return !e || e === document ? null : n(e, t) ? e : r(e.parentNode, t);
|
|
70
|
+
}
|
|
71
|
+
return n(e, t) || r(e, t);
|
|
571
72
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
closeAnimationTimeout = null;
|
|
581
|
-
// Elements
|
|
582
|
-
main;
|
|
583
|
-
content;
|
|
584
|
-
// Classes
|
|
585
|
-
classes;
|
|
586
|
-
constructor(e, t, s, i) {
|
|
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);
|
|
588
|
-
}
|
|
589
|
-
// Helper method to add classes that may contain spaces
|
|
590
|
-
// Splits by spaces and adds each class individually to avoid DOMException
|
|
591
|
-
addClasses(e, t) {
|
|
592
|
-
if (!t || t.trim() === "")
|
|
593
|
-
return;
|
|
594
|
-
const s = t.split(" ").filter((i) => i.trim() !== "");
|
|
595
|
-
for (const i of s)
|
|
596
|
-
e.classList.add(i.trim());
|
|
597
|
-
}
|
|
598
|
-
// Helper method to remove classes that may contain spaces
|
|
599
|
-
removeClasses(e, t) {
|
|
600
|
-
if (!t || t.trim() === "")
|
|
601
|
-
return;
|
|
602
|
-
const s = t.split(" ").filter((i) => i.trim() !== "");
|
|
603
|
-
for (const i of s)
|
|
604
|
-
e.classList.remove(i.trim());
|
|
605
|
-
}
|
|
606
|
-
// Remove disabled classes
|
|
607
|
-
enable() {
|
|
608
|
-
this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
|
|
609
|
-
}
|
|
610
|
-
// Set disabled classes
|
|
611
|
-
disable() {
|
|
612
|
-
this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
|
|
613
|
-
}
|
|
614
|
-
open() {
|
|
615
|
-
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true"), this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null);
|
|
616
|
-
const t = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
|
|
617
|
-
this.addClasses(this.main.main, t), this.addClasses(this.content.main, t), this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
|
|
618
|
-
const s = this.store.getSelectedOptions();
|
|
619
|
-
if (s.length) {
|
|
620
|
-
const i = s[s.length - 1].id, n = this.content.list.querySelector('[data-id="' + i + '"]');
|
|
621
|
-
n && this.ensureElementInView(this.content.list, n);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
close() {
|
|
625
|
-
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.removeClasses(this.content.main, this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
626
|
-
const e = this.getAnimationTiming();
|
|
627
|
-
this.closeAnimationTimeout = setTimeout(() => {
|
|
628
|
-
this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow), this.closeAnimationTimeout = null;
|
|
629
|
-
}, e);
|
|
630
|
-
}
|
|
631
|
-
getAnimationTiming() {
|
|
632
|
-
const t = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
633
|
-
if (t) {
|
|
634
|
-
if (t.endsWith("ms"))
|
|
635
|
-
return parseFloat(t);
|
|
636
|
-
if (t.endsWith("s"))
|
|
637
|
-
return parseFloat(t) * 1e3;
|
|
638
|
-
}
|
|
639
|
-
return 200;
|
|
640
|
-
}
|
|
641
|
-
updateClassStyles() {
|
|
642
|
-
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length)
|
|
643
|
-
for (const e of this.settings.class)
|
|
644
|
-
e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
|
|
645
|
-
(this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
|
|
646
|
-
}
|
|
647
|
-
updateAriaAttributes() {
|
|
648
|
-
const e = this.content.list.id;
|
|
649
|
-
this.main.main.role = "combobox", this.main.main.setAttribute("aria-haspopup", "listbox"), this.main.main.setAttribute("aria-controls", e), this.main.main.setAttribute("aria-expanded", "false"), this.content.list.setAttribute("role", "listbox"), this.content.list.setAttribute("aria-label", this.settings.ariaLabel + " listbox"), this.settings.isMultiple && this.content.list.setAttribute("aria-multiselectable", "true"), this.content.search.input.setAttribute("aria-controls", e);
|
|
650
|
-
}
|
|
651
|
-
mainDiv() {
|
|
652
|
-
const e = document.createElement("div");
|
|
653
|
-
e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (h) => {
|
|
654
|
-
switch (h.key) {
|
|
655
|
-
case "ArrowUp":
|
|
656
|
-
case "ArrowDown":
|
|
657
|
-
return this.callbacks.open(), h.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
658
|
-
case "Tab":
|
|
659
|
-
return this.callbacks.close(), !0;
|
|
660
|
-
// Continue doing normal tabbing
|
|
661
|
-
case "Enter":
|
|
662
|
-
case " ":
|
|
663
|
-
this.callbacks.open();
|
|
664
|
-
const o = this.content.list.querySelector(
|
|
665
|
-
"." + this.classes.getFirst("highlighted")
|
|
666
|
-
);
|
|
667
|
-
return o && o.click(), !1;
|
|
668
|
-
case "Escape":
|
|
669
|
-
return this.callbacks.close(), !1;
|
|
670
|
-
}
|
|
671
|
-
return h.key.length === 1 && this.callbacks.open(), !0;
|
|
672
|
-
}, e.onclick = (h) => {
|
|
673
|
-
this.settings.disabled || (this.settings.isOpen ? this.callbacks.close() : this.callbacks.open());
|
|
674
|
-
};
|
|
675
|
-
const t = document.createElement("div");
|
|
676
|
-
this.addClasses(t, this.classes.values), e.appendChild(t);
|
|
677
|
-
const s = document.createElement("div");
|
|
678
|
-
this.addClasses(s, this.classes.deselect);
|
|
679
|
-
const i = this.store?.getSelectedOptions();
|
|
680
|
-
!this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ? this.addClasses(s, this.classes.hide) : this.removeClasses(s, this.classes.hide), s.onclick = (h) => {
|
|
681
|
-
if (h.stopPropagation(), this.settings.disabled)
|
|
682
|
-
return;
|
|
683
|
-
let o = !0;
|
|
684
|
-
const d = this.store.getSelectedOptions(), m = [];
|
|
685
|
-
if (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(m, d) === !0), o) {
|
|
686
|
-
if (this.settings.isMultiple)
|
|
687
|
-
this.callbacks.setSelected([], !1), this.updateDeselectAll();
|
|
688
|
-
else {
|
|
689
|
-
const f = this.store.getFirstOption(), E = f ? f.id : "";
|
|
690
|
-
this.callbacks.setSelected(E, !1);
|
|
691
|
-
}
|
|
692
|
-
this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
696
|
-
n.setAttribute("viewBox", "0 0 100 100");
|
|
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");
|
|
701
|
-
const c = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
702
|
-
return c.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(r, this.classes.hide), r.appendChild(c), e.appendChild(r), {
|
|
703
|
-
main: e,
|
|
704
|
-
values: t,
|
|
705
|
-
deselect: {
|
|
706
|
-
main: s,
|
|
707
|
-
svg: n,
|
|
708
|
-
path: l
|
|
709
|
-
},
|
|
710
|
-
arrow: {
|
|
711
|
-
main: r,
|
|
712
|
-
path: c
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
mainFocus(e) {
|
|
717
|
-
e !== "click" && this.main.main.focus({ preventScroll: !0 });
|
|
718
|
-
}
|
|
719
|
-
placeholder() {
|
|
720
|
-
const e = this.store.filter((i) => i.placeholder, !1);
|
|
721
|
-
let t = this.settings.placeholderText;
|
|
722
|
-
e.length && (e[0].html !== "" ? t = e[0].html : e[0].text !== "" && (t = e[0].text));
|
|
723
|
-
const s = document.createElement("div");
|
|
724
|
-
return this.addClasses(s, this.classes.placeholder), s.innerHTML = t, s;
|
|
725
|
-
}
|
|
726
|
-
// Get selected values and append to multiSelected values container
|
|
727
|
-
// and remove those who shouldnt exist
|
|
728
|
-
renderValues() {
|
|
729
|
-
if (!this.settings.isMultiple) {
|
|
730
|
-
this.renderSingleValue();
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
this.renderMultipleValues(), this.updateDeselectAll();
|
|
734
|
-
}
|
|
735
|
-
renderSingleValue() {
|
|
736
|
-
const e = this.store.filter((s) => s.selected && !s.placeholder, !1), t = e.length > 0 ? e[0] : null;
|
|
737
|
-
if (!t)
|
|
738
|
-
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
739
|
-
else {
|
|
740
|
-
const s = document.createElement("div");
|
|
741
|
-
this.addClasses(s, this.classes.single), t.html ? s.innerHTML = t.html : s.innerText = t.text, this.main.values.innerHTML = s.outerHTML;
|
|
742
|
-
}
|
|
743
|
-
!this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
|
|
744
|
-
}
|
|
745
|
-
renderMultipleValues() {
|
|
746
|
-
let e = this.main.values.childNodes, t = this.store.filter((i) => i.selected && i.display, !1);
|
|
747
|
-
if (t.length === 0) {
|
|
748
|
-
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
749
|
-
return;
|
|
750
|
-
} else {
|
|
751
|
-
const i = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
|
|
752
|
-
i && i.remove();
|
|
753
|
-
}
|
|
754
|
-
if (t.length > this.settings.maxValuesShown) {
|
|
755
|
-
const i = document.createElement("div");
|
|
756
|
-
this.addClasses(i, this.classes.max), i.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = i.outerHTML;
|
|
757
|
-
return;
|
|
758
|
-
} else {
|
|
759
|
-
const i = this.main.values.querySelector("." + this.classes.getFirst("max"));
|
|
760
|
-
i && i.remove();
|
|
761
|
-
}
|
|
762
|
-
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
763
|
-
let s = [];
|
|
764
|
-
for (let i = 0; i < e.length; i++) {
|
|
765
|
-
const n = e[i], l = n.getAttribute("data-id");
|
|
766
|
-
l && (t.filter((c) => c.id === l, !1).length || s.push(n));
|
|
767
|
-
}
|
|
768
|
-
for (const i of s)
|
|
769
|
-
this.addClasses(i, this.classes.valueOut), setTimeout(() => {
|
|
770
|
-
this.main.values.hasChildNodes() && this.main.values.contains(i) && this.main.values.removeChild(i);
|
|
771
|
-
}, 100);
|
|
772
|
-
e = this.main.values.childNodes;
|
|
773
|
-
for (let i = 0; i < t.length; i++) {
|
|
774
|
-
let n = !0;
|
|
775
|
-
for (let l = 0; l < e.length; l++)
|
|
776
|
-
t[i].id === String(e[l].dataset.id) && (n = !1);
|
|
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])));
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
multipleValue(e) {
|
|
781
|
-
const t = document.createElement("div");
|
|
782
|
-
this.addClasses(t, this.classes.value), t.dataset.id = e.id;
|
|
783
|
-
const s = document.createElement("div");
|
|
784
|
-
if (this.addClasses(s, this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
|
|
785
|
-
const i = document.createElement("div");
|
|
786
|
-
this.addClasses(i, this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (r) => {
|
|
787
|
-
if (r.preventDefault(), r.stopPropagation(), this.settings.disabled)
|
|
788
|
-
return;
|
|
789
|
-
let c = !0;
|
|
790
|
-
const h = this.store.getSelectedOptions(), o = h.filter((d) => d.selected && d.id !== e.id, !0);
|
|
791
|
-
if (!(this.settings.minSelected && o.length < this.settings.minSelected) && (this.callbacks.beforeChange && (c = this.callbacks.beforeChange(o, h) === !0), c)) {
|
|
792
|
-
let d = [];
|
|
793
|
-
for (const m of o) {
|
|
794
|
-
if (m instanceof x)
|
|
795
|
-
for (const f of m.options)
|
|
796
|
-
f.id && d.push(f.id);
|
|
797
|
-
m instanceof b && d.push(m.id);
|
|
798
|
-
}
|
|
799
|
-
this.callbacks.setSelected(d, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o), this.updateDeselectAll();
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
803
|
-
n.setAttribute("viewBox", "0 0 100 100");
|
|
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();
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
return t;
|
|
810
|
-
}
|
|
811
|
-
contentDiv() {
|
|
812
|
-
const e = document.createElement("div");
|
|
813
|
-
e.dataset.id = this.settings.id;
|
|
814
|
-
const t = this.searchDiv();
|
|
815
|
-
e.appendChild(t.main);
|
|
816
|
-
const s = this.listDiv();
|
|
817
|
-
return e.appendChild(s), {
|
|
818
|
-
main: e,
|
|
819
|
-
search: t,
|
|
820
|
-
list: s
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
moveContent() {
|
|
824
|
-
if (this.settings.contentPosition === "relative") {
|
|
825
|
-
this.moveContentBelow();
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
if (this.settings.openPosition === "down") {
|
|
829
|
-
this.moveContentBelow();
|
|
830
|
-
return;
|
|
831
|
-
} else if (this.settings.openPosition === "up") {
|
|
832
|
-
this.moveContentAbove();
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
|
|
836
|
-
}
|
|
837
|
-
searchDiv() {
|
|
838
|
-
const e = document.createElement("div"), t = document.createElement("input"), s = document.createElement("div");
|
|
839
|
-
this.addClasses(e, this.classes.search);
|
|
840
|
-
const i = {
|
|
841
|
-
main: e,
|
|
842
|
-
input: t
|
|
843
|
-
};
|
|
844
|
-
if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput = H((n) => {
|
|
845
|
-
this.callbacks.search(n.target.value);
|
|
846
|
-
}, 100), t.onkeydown = (n) => {
|
|
847
|
-
switch (n.key) {
|
|
848
|
-
case "ArrowUp":
|
|
849
|
-
case "ArrowDown":
|
|
850
|
-
return n.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
851
|
-
case "Tab":
|
|
852
|
-
return this.callbacks.close(), !0;
|
|
853
|
-
// Continue doing normal tabbing
|
|
854
|
-
case "Escape":
|
|
855
|
-
return this.callbacks.close(), !1;
|
|
856
|
-
case " ":
|
|
857
|
-
const l = this.content.list.querySelector(
|
|
858
|
-
"." + this.classes.getFirst("highlighted")
|
|
859
|
-
);
|
|
860
|
-
return l ? (l.click(), !1) : !0;
|
|
861
|
-
case "Enter":
|
|
862
|
-
const r = this.content.list.querySelector(
|
|
863
|
-
"." + this.classes.getFirst("highlighted")
|
|
864
|
-
);
|
|
865
|
-
return r ? (r.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
|
|
866
|
-
}
|
|
867
|
-
return !0;
|
|
868
|
-
}, e.appendChild(t), this.callbacks.addable) {
|
|
869
|
-
this.addClasses(s, this.classes.addable);
|
|
870
|
-
const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
871
|
-
n.setAttribute("viewBox", "0 0 100 100");
|
|
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)
|
|
875
|
-
return;
|
|
876
|
-
const c = this.content.search.input.value.trim();
|
|
877
|
-
if (c === "") {
|
|
878
|
-
this.content.search.input.focus();
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
const h = (d) => {
|
|
882
|
-
let m = new b(d);
|
|
883
|
-
if (this.callbacks.addOption(m), this.settings.isMultiple) {
|
|
884
|
-
let f = this.store.getSelected();
|
|
885
|
-
f.push(m.id), this.callbacks.setSelected(f, !0);
|
|
886
|
-
} else
|
|
887
|
-
this.callbacks.setSelected([m.id], !0);
|
|
888
|
-
this.callbacks.search(""), this.settings.closeOnSelect && setTimeout(() => {
|
|
889
|
-
this.callbacks.close();
|
|
890
|
-
}, 100);
|
|
891
|
-
}, o = this.callbacks.addable(c);
|
|
892
|
-
o === !1 || o === void 0 || o === null || (o instanceof Promise ? o.then((d) => {
|
|
893
|
-
typeof d == "string" ? h({
|
|
894
|
-
text: d,
|
|
895
|
-
value: d
|
|
896
|
-
}) : o instanceof Error ? this.renderError(o.message) : h(d);
|
|
897
|
-
}) : typeof o == "string" ? h({
|
|
898
|
-
text: o,
|
|
899
|
-
value: o
|
|
900
|
-
}) : o instanceof Error ? this.renderError(o.message) : h(o));
|
|
901
|
-
}, e.appendChild(s), i.addable = {
|
|
902
|
-
main: s,
|
|
903
|
-
svg: n,
|
|
904
|
-
path: l
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
return i;
|
|
908
|
-
}
|
|
909
|
-
searchFocus() {
|
|
910
|
-
this.content.search.input.focus({ preventScroll: !0 });
|
|
911
|
-
}
|
|
912
|
-
getOptions(e = !1, t = !1, s = !1) {
|
|
913
|
-
let i = "." + this.classes.getFirst("option");
|
|
914
|
-
return e && (i += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (i += ":not(." + this.classes.getFirst("disabled") + ")"), s && (i += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(i));
|
|
915
|
-
}
|
|
916
|
-
// highlightUp is used to highlight the previous option in the list
|
|
917
|
-
highlight(e) {
|
|
918
|
-
const t = this.getOptions(!0, !0, !0);
|
|
919
|
-
if (t.length === 0)
|
|
920
|
-
return;
|
|
921
|
-
if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
922
|
-
this.addClasses(t[0], this.classes.highlighted);
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
let s = !1;
|
|
926
|
-
for (const n of t)
|
|
927
|
-
n.classList.contains(this.classes.getFirst("highlighted")) && (s = !0);
|
|
928
|
-
if (!s) {
|
|
929
|
-
for (const n of t)
|
|
930
|
-
if (n.classList.contains(this.classes.getFirst("selected"))) {
|
|
931
|
-
this.addClasses(n, this.classes.highlighted);
|
|
932
|
-
break;
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
for (let n = 0; n < t.length; n++)
|
|
936
|
-
if (t[n].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
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"));
|
|
942
|
-
o && o.click();
|
|
943
|
-
}
|
|
944
|
-
let c = t[e === "down" ? n + 1 < t.length ? n + 1 : 0 : n - 1 >= 0 ? n - 1 : t.length - 1];
|
|
945
|
-
this.addClasses(c, this.classes.highlighted), this.ensureElementInView(this.content.list, c), c.id && this.main.main.setAttribute("aria-activedescendant", c.id);
|
|
946
|
-
const h = c.parentElement;
|
|
947
|
-
if (h && h.classList.contains(this.classes.getFirst("close"))) {
|
|
948
|
-
const o = h.querySelector(
|
|
949
|
-
"." + this.classes.getFirst("optgroupLabel")
|
|
950
|
-
);
|
|
951
|
-
o && o.click();
|
|
952
|
-
}
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
const i = t[e === "down" ? 0 : t.length - 1];
|
|
956
|
-
this.addClasses(i, this.classes.highlighted), i.id && this.main.main.setAttribute("aria-activedescendant", i.id), this.ensureElementInView(this.content.list, i);
|
|
957
|
-
}
|
|
958
|
-
// Create main container that options will reside
|
|
959
|
-
listDiv() {
|
|
960
|
-
const e = document.createElement("div");
|
|
961
|
-
this.addClasses(e, this.classes.list);
|
|
962
|
-
const t = this.settings.id + "-list";
|
|
963
|
-
return e.id = t, e.dataset.id = t, e;
|
|
964
|
-
}
|
|
965
|
-
renderError(e) {
|
|
966
|
-
this.content.list.innerHTML = "";
|
|
967
|
-
const t = document.createElement("div");
|
|
968
|
-
this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
|
|
969
|
-
}
|
|
970
|
-
renderSearching() {
|
|
971
|
-
this.content.list.innerHTML = "";
|
|
972
|
-
const e = document.createElement("div");
|
|
973
|
-
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e);
|
|
974
|
-
}
|
|
975
|
-
// Take in data and add options to
|
|
976
|
-
renderOptions(e) {
|
|
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) {
|
|
978
|
-
const s = document.createElement("div");
|
|
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);
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
|
|
983
|
-
new b({
|
|
984
|
-
text: "",
|
|
985
|
-
value: "",
|
|
986
|
-
selected: !1,
|
|
987
|
-
placeholder: !0
|
|
988
|
-
}),
|
|
989
|
-
!0
|
|
990
|
-
));
|
|
991
|
-
const t = document.createDocumentFragment();
|
|
992
|
-
for (const s of e) {
|
|
993
|
-
if (s instanceof x) {
|
|
994
|
-
const i = document.createElement("div");
|
|
995
|
-
this.addClasses(i, this.classes.optgroup);
|
|
996
|
-
const n = document.createElement("div");
|
|
997
|
-
this.addClasses(n, this.classes.optgroupLabel), i.appendChild(n);
|
|
998
|
-
const l = document.createElement("div");
|
|
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) {
|
|
1002
|
-
const c = document.createElement("div");
|
|
1003
|
-
this.addClasses(c, this.classes.optgroupSelectAll);
|
|
1004
|
-
let h = !0;
|
|
1005
|
-
for (const E of s.options)
|
|
1006
|
-
if (!E.selected) {
|
|
1007
|
-
h = !1;
|
|
1008
|
-
break;
|
|
1009
|
-
}
|
|
1010
|
-
h && this.addClasses(c, this.classes.selected);
|
|
1011
|
-
const o = document.createElement("span");
|
|
1012
|
-
o.textContent = s.selectAllText, c.appendChild(o);
|
|
1013
|
-
const d = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1014
|
-
d.setAttribute("viewBox", "0 0 100 100"), c.appendChild(d);
|
|
1015
|
-
const m = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1016
|
-
m.setAttribute("d", this.classes.optgroupSelectAllBox), d.appendChild(m);
|
|
1017
|
-
const f = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1018
|
-
f.setAttribute("d", this.classes.optgroupSelectAllCheck), d.appendChild(f), c.addEventListener("click", (E) => {
|
|
1019
|
-
E.preventDefault(), E.stopPropagation();
|
|
1020
|
-
const g = this.store.getSelected();
|
|
1021
|
-
if (h) {
|
|
1022
|
-
const A = g.filter((S) => {
|
|
1023
|
-
for (const v of s.options)
|
|
1024
|
-
if (S === v.id)
|
|
1025
|
-
return !1;
|
|
1026
|
-
return !0;
|
|
1027
|
-
});
|
|
1028
|
-
this.callbacks.setSelected(A, !0);
|
|
1029
|
-
return;
|
|
1030
|
-
} else {
|
|
1031
|
-
let A = s.options.map((v) => v.id).filter((v) => v !== void 0);
|
|
1032
|
-
const S = g.concat(A);
|
|
1033
|
-
for (const v of s.options)
|
|
1034
|
-
v.id && !this.store.getOptionByID(v.id) && this.callbacks.addOption(new b(v));
|
|
1035
|
-
this.callbacks.setSelected(S, !0);
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
}), r.appendChild(c);
|
|
1039
|
-
}
|
|
1040
|
-
if (s.closable !== "off") {
|
|
1041
|
-
const c = document.createElement("div");
|
|
1042
|
-
this.addClasses(c, this.classes.optgroupClosable);
|
|
1043
|
-
const h = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1044
|
-
h.setAttribute("viewBox", "0 0 100 100"), this.addClasses(h, this.classes.arrow), c.appendChild(h);
|
|
1045
|
-
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
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) => {
|
|
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));
|
|
1048
|
-
}), r.appendChild(c);
|
|
1049
|
-
}
|
|
1050
|
-
i.appendChild(n);
|
|
1051
|
-
for (const c of s.options)
|
|
1052
|
-
i.appendChild(this.option(new b(c))), t.appendChild(i);
|
|
1053
|
-
}
|
|
1054
|
-
s instanceof b && t.appendChild(this.option(s));
|
|
1055
|
-
}
|
|
1056
|
-
this.content.list.appendChild(t);
|
|
1057
|
-
}
|
|
1058
|
-
// Create option div element
|
|
1059
|
-
option(e) {
|
|
1060
|
-
if (e.placeholder) {
|
|
1061
|
-
const s = document.createElement("div");
|
|
1062
|
-
return this.addClasses(s, this.classes.option), this.addClasses(s, this.classes.hide), s;
|
|
1063
|
-
}
|
|
1064
|
-
const t = document.createElement("div");
|
|
1065
|
-
return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, this.addClasses(t, this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((s) => {
|
|
1066
|
-
t.classList.add(s);
|
|
1067
|
-
}), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(
|
|
1068
|
-
e.html !== "" ? e.html : e.text,
|
|
1069
|
-
this.content.search.input.value,
|
|
1070
|
-
this.classes.searchHighlighter
|
|
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) => {
|
|
1072
|
-
s.preventDefault(), s.stopPropagation();
|
|
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)
|
|
1075
|
-
return;
|
|
1076
|
-
let c = !1;
|
|
1077
|
-
const h = this.store.getSelectedOptions();
|
|
1078
|
-
let o = [];
|
|
1079
|
-
if (this.settings.isMultiple) {
|
|
1080
|
-
const d = h.some((f) => f.id === l);
|
|
1081
|
-
if (s.shiftKey && this.lastSelectedOption) {
|
|
1082
|
-
const f = this.lastRenderedOptions, E = f.findIndex((A) => A.id === this.lastSelectedOption.id), g = f.findIndex((A) => A.id === e.id);
|
|
1083
|
-
if (E >= 0 && g >= 0) {
|
|
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));
|
|
1085
|
-
h.length + k.length <= this.settings.maxSelected ? o = h.concat(k) : o = h;
|
|
1086
|
-
} else
|
|
1087
|
-
o = h;
|
|
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);
|
|
1089
|
-
}
|
|
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) {
|
|
1091
|
-
this.store.getOptionByID(l) || this.callbacks.addOption(e), this.callbacks.setSelected(
|
|
1092
|
-
o.map((f) => f.id),
|
|
1093
|
-
!1
|
|
1094
|
-
);
|
|
1095
|
-
const d = s.ctrlKey || s.metaKey || s.shiftKey;
|
|
1096
|
-
this.settings.closeOnSelect && !(this.settings.isMultiple && d) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(o);
|
|
1097
|
-
}
|
|
1098
|
-
}), t;
|
|
1099
|
-
}
|
|
1100
|
-
destroy() {
|
|
1101
|
-
this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null), this.main.main.remove(), this.content.main.remove();
|
|
1102
|
-
}
|
|
1103
|
-
highlightText(e, t, s) {
|
|
1104
|
-
const i = t.trim();
|
|
1105
|
-
if (i === "")
|
|
1106
|
-
return e;
|
|
1107
|
-
const n = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), l = document.createElement("div");
|
|
1108
|
-
l.innerHTML = e;
|
|
1109
|
-
const r = (c) => {
|
|
1110
|
-
if (c.nodeType === Node.TEXT_NODE) {
|
|
1111
|
-
const h = c.textContent || "", o = new RegExp("(" + n + ")", "i");
|
|
1112
|
-
if (o.test(h)) {
|
|
1113
|
-
const d = document.createElement("span");
|
|
1114
|
-
h.split(o).forEach((f, E) => {
|
|
1115
|
-
if (f && o.test(f)) {
|
|
1116
|
-
const g = document.createElement("mark");
|
|
1117
|
-
g.className = s, g.textContent = f, d.appendChild(g);
|
|
1118
|
-
} else f && d.appendChild(document.createTextNode(f));
|
|
1119
|
-
}), c.parentNode?.replaceChild(d, c);
|
|
1120
|
-
}
|
|
1121
|
-
} else c.nodeType === Node.ELEMENT_NODE && Array.from(c.childNodes).forEach((h) => r(h));
|
|
1122
|
-
};
|
|
1123
|
-
return Array.from(l.childNodes).forEach((c) => r(c)), l.innerHTML;
|
|
1124
|
-
}
|
|
1125
|
-
setContentDirection(e) {
|
|
1126
|
-
const t = e === "above", s = t ? this.classes.dirAbove : this.classes.dirBelow, i = t ? this.classes.dirBelow : this.classes.dirAbove;
|
|
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) {
|
|
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";
|
|
1130
|
-
} else
|
|
1131
|
-
this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
1132
|
-
}
|
|
1133
|
-
setContentPosition() {
|
|
1134
|
-
if (this.settings.contentPosition === "relative")
|
|
1135
|
-
return;
|
|
1136
|
-
const e = this.main.main.getBoundingClientRect();
|
|
1137
|
-
let t, s;
|
|
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";
|
|
1139
|
-
const i = this.settings.contentWidth;
|
|
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";
|
|
1141
|
-
const n = 20, l = window.innerWidth - n, r = () => {
|
|
1142
|
-
const h = this.content.main.getBoundingClientRect().right;
|
|
1143
|
-
if (h <= l) return;
|
|
1144
|
-
const o = h - l, d = parseFloat(this.content.main.style.left) || 0;
|
|
1145
|
-
if (this.settings.contentPosition === "fixed") {
|
|
1146
|
-
const m = Math.max(n, d - o);
|
|
1147
|
-
this.content.main.style.left = m + "px";
|
|
1148
|
-
} else {
|
|
1149
|
-
const m = Math.max(window.scrollX + n, d - o);
|
|
1150
|
-
this.content.main.style.left = m + "px";
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
requestAnimationFrame(() => {
|
|
1154
|
-
r(), requestAnimationFrame(r);
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
moveContentAbove() {
|
|
1158
|
-
this.setContentDirection("above"), this.setContentPosition();
|
|
1159
|
-
}
|
|
1160
|
-
moveContentBelow() {
|
|
1161
|
-
this.setContentDirection("below"), this.setContentPosition();
|
|
1162
|
-
}
|
|
1163
|
-
ensureElementInView(e, t) {
|
|
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);
|
|
1166
|
-
}
|
|
1167
|
-
putContent() {
|
|
1168
|
-
const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
|
|
1169
|
-
return window.innerHeight - (t.top + e) <= s && t.top > s ? "up" : "down";
|
|
1170
|
-
}
|
|
1171
|
-
// Updates deselect based on item count and allowDeselect setting
|
|
1172
|
-
updateDeselectAll() {
|
|
1173
|
-
if (!this.store || !this.settings)
|
|
1174
|
-
return;
|
|
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);
|
|
1177
|
-
}
|
|
73
|
+
function l(e, t = 50, n = !1) {
|
|
74
|
+
let r;
|
|
75
|
+
return function(...i) {
|
|
76
|
+
let a = self, o = () => {
|
|
77
|
+
r = null, n || e.apply(a, i);
|
|
78
|
+
}, s = n && !r;
|
|
79
|
+
clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
|
|
80
|
+
};
|
|
1178
81
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
// Mutation observer fields
|
|
1182
|
-
onValueChange;
|
|
1183
|
-
onClassChange;
|
|
1184
|
-
onDisabledChange;
|
|
1185
|
-
onOptionsChange;
|
|
1186
|
-
onLabelClick;
|
|
1187
|
-
// Change observers
|
|
1188
|
-
listen = !1;
|
|
1189
|
-
observer = null;
|
|
1190
|
-
isUpdating = !1;
|
|
1191
|
-
pendingOptionsChange = null;
|
|
1192
|
-
// Event handlers for preventing native select behavior (especially on iOS Safari)
|
|
1193
|
-
preventNativeSelect = null;
|
|
1194
|
-
preventNativeSelectMousedown = null;
|
|
1195
|
-
preventNativeSelectFocus = null;
|
|
1196
|
-
constructor(e) {
|
|
1197
|
-
this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, {
|
|
1198
|
-
// allow bubbling of event
|
|
1199
|
-
passive: !0
|
|
1200
|
-
}), this.observer = new MutationObserver(this.observeCall.bind(this)), this.changeListen(!0);
|
|
1201
|
-
}
|
|
1202
|
-
enable() {
|
|
1203
|
-
this.select.disabled = !1;
|
|
1204
|
-
}
|
|
1205
|
-
disable() {
|
|
1206
|
-
this.select.disabled = !0;
|
|
1207
|
-
}
|
|
1208
|
-
hideUI() {
|
|
1209
|
-
this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clip = "rect(0 0 0 0)", this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
|
|
1210
|
-
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1211
|
-
}, this.preventNativeSelectMousedown = (e) => {
|
|
1212
|
-
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1213
|
-
}, this.preventNativeSelectFocus = (e) => {
|
|
1214
|
-
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1215
|
-
}, this.select.addEventListener("click", this.preventNativeSelect, { capture: !0, passive: !1 }), this.select.addEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0, passive: !1 }), this.select.addEventListener("focus", this.preventNativeSelectFocus, { capture: !0, passive: !1 }));
|
|
1216
|
-
}
|
|
1217
|
-
showUI() {
|
|
1218
|
-
this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clip = "", this.select.removeAttribute("aria-hidden"), this.preventNativeSelect && (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), this.preventNativeSelect = null), this.preventNativeSelectMousedown && (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), this.preventNativeSelectMousedown = null), this.preventNativeSelectFocus && (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), this.preventNativeSelectFocus = null);
|
|
1219
|
-
}
|
|
1220
|
-
changeListen(e) {
|
|
1221
|
-
this.listen = e, e && this.observer && this.observer.observe(this.select, {
|
|
1222
|
-
subtree: !0,
|
|
1223
|
-
// subtree for optgroups options
|
|
1224
|
-
childList: !0,
|
|
1225
|
-
// children changes
|
|
1226
|
-
attributes: !0
|
|
1227
|
-
// attributes changes
|
|
1228
|
-
}), e || this.observer && this.observer.disconnect();
|
|
1229
|
-
}
|
|
1230
|
-
// This function get triggers when the select value changes
|
|
1231
|
-
// and will call the onValueChange function if it exists
|
|
1232
|
-
valueChange(e) {
|
|
1233
|
-
return this.listen && this.onValueChange && this.onValueChange(this.getSelectedOptions()), !0;
|
|
1234
|
-
}
|
|
1235
|
-
observeCall(e) {
|
|
1236
|
-
if (!this.listen)
|
|
1237
|
-
return;
|
|
1238
|
-
let t = !1, s = !1, i = !1, n = !1;
|
|
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) {
|
|
1243
|
-
n = !0;
|
|
1244
|
-
break;
|
|
1245
|
-
}
|
|
1246
|
-
i = !0;
|
|
1247
|
-
}
|
|
1248
|
-
(l.target.nodeName === "OPTGROUP" || l.target.nodeName === "OPTION") && (i = !0);
|
|
1249
|
-
}
|
|
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) {
|
|
1251
|
-
if (this.isUpdating) {
|
|
1252
|
-
if (this.select.options.length > 0) {
|
|
1253
|
-
const l = this.getData();
|
|
1254
|
-
l.length > 0 && (this.pendingOptionsChange = l);
|
|
1255
|
-
}
|
|
1256
|
-
n && this.select.dispatchEvent(new Event("change"));
|
|
1257
|
-
return;
|
|
1258
|
-
}
|
|
1259
|
-
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
1260
|
-
}
|
|
1261
|
-
n && this.select.dispatchEvent(new Event("change"));
|
|
1262
|
-
}
|
|
1263
|
-
// From the select element pull optgroup and options into data
|
|
1264
|
-
getData() {
|
|
1265
|
-
let e = [];
|
|
1266
|
-
const t = this.select.childNodes;
|
|
1267
|
-
for (const s of t)
|
|
1268
|
-
s.nodeName === "OPTGROUP" && e.push(this.getDataFromOptgroup(s)), s.nodeName === "OPTION" && e.push(this.getDataFromOption(s));
|
|
1269
|
-
return e;
|
|
1270
|
-
}
|
|
1271
|
-
getDataFromOptgroup(e) {
|
|
1272
|
-
let t = {
|
|
1273
|
-
id: e.id,
|
|
1274
|
-
label: e.label,
|
|
1275
|
-
selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
|
|
1276
|
-
selectAllText: e.dataset ? e.dataset.selectalltext : "Select all",
|
|
1277
|
-
closable: e.dataset ? e.dataset.closable : "off",
|
|
1278
|
-
options: []
|
|
1279
|
-
};
|
|
1280
|
-
const s = e.childNodes;
|
|
1281
|
-
for (const i of s)
|
|
1282
|
-
i.nodeName === "OPTION" && t.options.push(this.getDataFromOption(i));
|
|
1283
|
-
return t;
|
|
1284
|
-
}
|
|
1285
|
-
// From passed in option pull pieces of usable information
|
|
1286
|
-
getDataFromOption(e) {
|
|
1287
|
-
return {
|
|
1288
|
-
id: e.id,
|
|
1289
|
-
value: e.value,
|
|
1290
|
-
text: e.text,
|
|
1291
|
-
html: e.dataset && e.dataset.html ? e.dataset.html : "",
|
|
1292
|
-
defaultSelected: e.defaultSelected,
|
|
1293
|
-
selected: e.selected,
|
|
1294
|
-
display: e.style.display !== "none",
|
|
1295
|
-
disabled: e.disabled,
|
|
1296
|
-
mandatory: e.dataset ? e.dataset.mandatory === "true" : !1,
|
|
1297
|
-
placeholder: e.dataset.placeholder === "true",
|
|
1298
|
-
class: e.className,
|
|
1299
|
-
style: e.style.cssText,
|
|
1300
|
-
data: e.dataset
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
getSelectedOptions() {
|
|
1304
|
-
let e = [];
|
|
1305
|
-
const t = this.select.childNodes;
|
|
1306
|
-
for (const s of t) {
|
|
1307
|
-
if (s.nodeName === "OPTGROUP") {
|
|
1308
|
-
const i = s.childNodes;
|
|
1309
|
-
for (const n of i)
|
|
1310
|
-
if (n.nodeName === "OPTION") {
|
|
1311
|
-
const l = n;
|
|
1312
|
-
l.selected && e.push(this.getDataFromOption(l));
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
if (s.nodeName === "OPTION") {
|
|
1316
|
-
const i = s;
|
|
1317
|
-
i.selected && e.push(this.getDataFromOption(i));
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
return e;
|
|
1321
|
-
}
|
|
1322
|
-
getSelectedValues() {
|
|
1323
|
-
return this.getSelectedOptions().map((e) => e.value);
|
|
1324
|
-
}
|
|
1325
|
-
setSelected(e) {
|
|
1326
|
-
this.changeListen(!1);
|
|
1327
|
-
const t = this.select.childNodes;
|
|
1328
|
-
for (const s of t) {
|
|
1329
|
-
if (s.nodeName === "OPTGROUP") {
|
|
1330
|
-
const n = s.childNodes;
|
|
1331
|
-
for (const l of n)
|
|
1332
|
-
if (l.nodeName === "OPTION") {
|
|
1333
|
-
const r = l;
|
|
1334
|
-
r.selected = e.includes(r.id);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
if (s.nodeName === "OPTION") {
|
|
1338
|
-
const i = s;
|
|
1339
|
-
i.selected = e.includes(i.id);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
this.changeListen(!0);
|
|
1343
|
-
}
|
|
1344
|
-
// Set selected options by value instead of id
|
|
1345
|
-
// This is useful when the id is not known
|
|
1346
|
-
// and only the value is known
|
|
1347
|
-
// but the value is not unique and can be duplicated
|
|
1348
|
-
setSelectedByValue(e) {
|
|
1349
|
-
this.changeListen(!1);
|
|
1350
|
-
const t = this.select.childNodes;
|
|
1351
|
-
for (const s of t) {
|
|
1352
|
-
if (s.nodeName === "OPTGROUP") {
|
|
1353
|
-
const n = s.childNodes;
|
|
1354
|
-
for (const l of n)
|
|
1355
|
-
if (l.nodeName === "OPTION") {
|
|
1356
|
-
const r = l;
|
|
1357
|
-
r.selected = e.includes(r.value);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
if (s.nodeName === "OPTION") {
|
|
1361
|
-
const i = s;
|
|
1362
|
-
i.selected = e.includes(i.value);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
this.changeListen(!0);
|
|
1366
|
-
}
|
|
1367
|
-
updateSelect(e, t, s) {
|
|
1368
|
-
this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), s && (this.select.className = "", s.forEach((i) => {
|
|
1369
|
-
i.trim() !== "" && this.select.classList.add(i.trim());
|
|
1370
|
-
})), this.changeListen(!0);
|
|
1371
|
-
}
|
|
1372
|
-
updateOptions(e) {
|
|
1373
|
-
if (!(!e || e.length === 0)) {
|
|
1374
|
-
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
1375
|
-
for (const t of e)
|
|
1376
|
-
t instanceof x && this.select.appendChild(this.createOptgroup(t)), t instanceof b && this.select.appendChild(this.createOption(t));
|
|
1377
|
-
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
1378
|
-
const t = this.pendingOptionsChange;
|
|
1379
|
-
t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
createOptgroup(e) {
|
|
1384
|
-
const t = document.createElement("optgroup");
|
|
1385
|
-
if (t.id = e.id, t.label = e.label, e.selectAll && (t.dataset.selectAll = "true"), e.closable !== "off" && (t.dataset.closable = e.closable), e.options)
|
|
1386
|
-
for (const s of e.options)
|
|
1387
|
-
t.appendChild(this.createOption(s));
|
|
1388
|
-
return t;
|
|
1389
|
-
}
|
|
1390
|
-
createOption(e) {
|
|
1391
|
-
const t = document.createElement("option");
|
|
1392
|
-
return t.id = e.id, t.value = e.value, t.textContent = e.text, e.html !== "" && t.setAttribute("data-html", e.html), t.defaultSelected = e.defaultSelected, t.selected = e.selected, e.disabled && (t.disabled = !0), e.display || (t.style.display = "none"), e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((s) => {
|
|
1393
|
-
t.classList.add(s);
|
|
1394
|
-
}), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((s) => {
|
|
1395
|
-
t.setAttribute("data-" + me(s), e.data[s]);
|
|
1396
|
-
}), t;
|
|
1397
|
-
}
|
|
1398
|
-
// Find and handle labels associated with this select
|
|
1399
|
-
setupLabelHandlers() {
|
|
1400
|
-
const e = [], t = this.select.id;
|
|
1401
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((l) => e.push(l));
|
|
1402
|
-
let s = this.select.parentElement;
|
|
1403
|
-
for (; s && s !== document.body; ) {
|
|
1404
|
-
if (s.tagName === "LABEL") {
|
|
1405
|
-
e.push(s);
|
|
1406
|
-
break;
|
|
1407
|
-
}
|
|
1408
|
-
s = s.parentElement;
|
|
1409
|
-
}
|
|
1410
|
-
Array.from(new Set(e)).forEach((n) => {
|
|
1411
|
-
if (n.__slimSelectLabelHandler)
|
|
1412
|
-
return;
|
|
1413
|
-
const l = (r) => {
|
|
1414
|
-
const c = r.target, h = ie(c, this.select.dataset.id);
|
|
1415
|
-
r.preventDefault(), !h && this.onLabelClick && this.onLabelClick();
|
|
1416
|
-
};
|
|
1417
|
-
n.__slimSelectLabelHandler = l, n.addEventListener("click", l, { capture: !0, passive: !1 });
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
// Remove label handlers
|
|
1421
|
-
removeLabelHandlers() {
|
|
1422
|
-
const e = [], t = this.select.id;
|
|
1423
|
-
t && document.querySelectorAll(`label[for="${t}"]`).forEach((l) => e.push(l));
|
|
1424
|
-
let s = this.select.parentElement;
|
|
1425
|
-
for (; s && s !== document.body; ) {
|
|
1426
|
-
if (s.tagName === "LABEL") {
|
|
1427
|
-
e.push(s);
|
|
1428
|
-
break;
|
|
1429
|
-
}
|
|
1430
|
-
s = s.parentElement;
|
|
1431
|
-
}
|
|
1432
|
-
Array.from(new Set(e)).forEach((n) => {
|
|
1433
|
-
const l = n.__slimSelectLabelHandler;
|
|
1434
|
-
l && (n.removeEventListener("click", l, { capture: !0 }), delete n.__slimSelectLabelHandler);
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
destroy() {
|
|
1438
|
-
this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.preventNativeSelect && (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), this.preventNativeSelect = null), this.preventNativeSelectMousedown && (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), this.preventNativeSelectMousedown = null), this.preventNativeSelectFocus && (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), this.preventNativeSelectFocus = null), this.observer && (this.observer.disconnect(), this.observer = null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
|
|
1439
|
-
}
|
|
82
|
+
function u(e, t) {
|
|
83
|
+
return JSON.stringify(e) === JSON.stringify(t);
|
|
1440
84
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
style = "";
|
|
1445
|
-
// Style attribute from the select element
|
|
1446
|
-
class = [];
|
|
1447
|
-
// Class attribute from the select element
|
|
1448
|
-
// Dynamic settings
|
|
1449
|
-
isMultiple = !1;
|
|
1450
|
-
isOpen = !1;
|
|
1451
|
-
isFullOpen = !1;
|
|
1452
|
-
intervalMove = null;
|
|
1453
|
-
// Fields set from constructor
|
|
1454
|
-
disabled;
|
|
1455
|
-
alwaysOpen;
|
|
1456
|
-
showSearch;
|
|
1457
|
-
focusSearch;
|
|
1458
|
-
keepSearch;
|
|
1459
|
-
ariaLabel;
|
|
1460
|
-
searchPlaceholder;
|
|
1461
|
-
searchText;
|
|
1462
|
-
searchingText;
|
|
1463
|
-
searchHighlight;
|
|
1464
|
-
closeOnSelect;
|
|
1465
|
-
contentLocation;
|
|
1466
|
-
contentPosition;
|
|
1467
|
-
contentWidth;
|
|
1468
|
-
openPosition;
|
|
1469
|
-
placeholderText;
|
|
1470
|
-
allowDeselect;
|
|
1471
|
-
hideSelected;
|
|
1472
|
-
keepOrder;
|
|
1473
|
-
showOptionTooltips;
|
|
1474
|
-
minSelected;
|
|
1475
|
-
maxSelected;
|
|
1476
|
-
timeoutDelay;
|
|
1477
|
-
maxValuesShown;
|
|
1478
|
-
maxValuesMessage;
|
|
1479
|
-
addableText;
|
|
1480
|
-
constructor(e) {
|
|
1481
|
-
e || (e = {}), this.id = "ss-" + z(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.keepSearch = e.keepSearch !== void 0 ? e.keepSearch : !1, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || 'Press "Enter" to add {value}';
|
|
1482
|
-
}
|
|
85
|
+
function d(e) {
|
|
86
|
+
let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
|
|
87
|
+
return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
|
|
1483
88
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
};
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
);
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/slim-select/store.ts
|
|
91
|
+
var f = class {
|
|
92
|
+
id;
|
|
93
|
+
value;
|
|
94
|
+
text;
|
|
95
|
+
html;
|
|
96
|
+
defaultSelected;
|
|
97
|
+
selected;
|
|
98
|
+
display;
|
|
99
|
+
disabled;
|
|
100
|
+
placeholder;
|
|
101
|
+
class;
|
|
102
|
+
style;
|
|
103
|
+
data;
|
|
104
|
+
mandatory;
|
|
105
|
+
constructor(e) {
|
|
106
|
+
this.id = !e.id || e.id === "" ? s() : e.id, this.value = e.value === void 0 ? e.text || "" : e.value || "", this.text = e.text || "", this.html = e.html || "", this.defaultSelected = e.defaultSelected === void 0 ? !1 : e.defaultSelected, this.selected = e.selected === void 0 ? !1 : e.selected, this.display = e.display === void 0 ? !0 : e.display, this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.mandatory = e.mandatory === void 0 ? !1 : e.mandatory, this.placeholder = e.placeholder === void 0 ? !1 : e.placeholder, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
|
|
107
|
+
}
|
|
108
|
+
}, p = class {
|
|
109
|
+
id;
|
|
110
|
+
label;
|
|
111
|
+
selectAll;
|
|
112
|
+
selectAllText;
|
|
113
|
+
closable;
|
|
114
|
+
options;
|
|
115
|
+
constructor(e) {
|
|
116
|
+
if (this.id = !e.id || e.id === "" ? s() : 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) for (let t of e.options) this.options.push(new f(t));
|
|
117
|
+
}
|
|
118
|
+
}, m = class {
|
|
119
|
+
selectType = "single";
|
|
120
|
+
data = [];
|
|
121
|
+
selectedOrder = [];
|
|
122
|
+
constructor(e, t) {
|
|
123
|
+
this.selectType = e, this.setData(t);
|
|
124
|
+
}
|
|
125
|
+
validateDataArray(e) {
|
|
126
|
+
if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
|
|
127
|
+
for (let t of e) if (t) if (t instanceof p || "label" in t) {
|
|
128
|
+
if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
|
|
129
|
+
if ("options" in t && t.options) for (let e of t.options) {
|
|
130
|
+
let t = this.validateOption(e);
|
|
131
|
+
if (t) return t;
|
|
132
|
+
}
|
|
133
|
+
} else if (t instanceof f || "text" in t) {
|
|
134
|
+
let e = this.validateOption(t);
|
|
135
|
+
if (e) return e;
|
|
136
|
+
} else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
validateOption(e) {
|
|
140
|
+
return "text" in e ? null : /* @__PURE__ */ Error("Option must have a text");
|
|
141
|
+
}
|
|
142
|
+
partialToFullData(e) {
|
|
143
|
+
let t = [];
|
|
144
|
+
return e.forEach((e) => {
|
|
145
|
+
if (e) {
|
|
146
|
+
if (e instanceof p || "label" in e) {
|
|
147
|
+
let n = [];
|
|
148
|
+
"options" in e && e.options && e.options.forEach((e) => {
|
|
149
|
+
n.push(new f(e));
|
|
150
|
+
}), n.length > 0 && t.push(new p(e));
|
|
151
|
+
}
|
|
152
|
+
(e instanceof f || "text" in e) && t.push(new f(e));
|
|
153
|
+
}
|
|
154
|
+
}), t;
|
|
155
|
+
}
|
|
156
|
+
setData(e, t = !1) {
|
|
157
|
+
let n = this.partialToFullData(e), r = [];
|
|
158
|
+
if (t) {
|
|
159
|
+
r = this.getSelectedOptions();
|
|
160
|
+
let e = [];
|
|
161
|
+
r.forEach((t) => {
|
|
162
|
+
let r = !1;
|
|
163
|
+
for (let e of n) {
|
|
164
|
+
if (e instanceof f && e.id === t.id) {
|
|
165
|
+
r = !0;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
if (e instanceof p) {
|
|
169
|
+
for (let n of e.options) if (n.id === t.id) {
|
|
170
|
+
r = !0;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
r || e.push(t);
|
|
176
|
+
}), this.data = [...e, ...n];
|
|
177
|
+
} else this.data = n;
|
|
178
|
+
if (this.selectType === "single") {
|
|
179
|
+
let e = t && r.length === 0;
|
|
180
|
+
this.setSelectedBy("id", this.getSelected(), e);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
getData() {
|
|
184
|
+
return this.filter(null, !0);
|
|
185
|
+
}
|
|
186
|
+
getDataOptions() {
|
|
187
|
+
return this.filter(null, !1);
|
|
188
|
+
}
|
|
189
|
+
addOption(e, t = !1) {
|
|
190
|
+
if (t) {
|
|
191
|
+
let t = [new f(e)];
|
|
192
|
+
this.setData(t.concat(this.getData()));
|
|
193
|
+
} else this.setData(this.getData().concat(new f(e)));
|
|
194
|
+
}
|
|
195
|
+
setSelectedBy(e, t, n = !1) {
|
|
196
|
+
let r = null, i = !1, a = [];
|
|
197
|
+
for (let n of this.data) {
|
|
198
|
+
if (n instanceof p) for (let o of n.options) {
|
|
199
|
+
r ||= o;
|
|
200
|
+
let n = o[e] || "";
|
|
201
|
+
o.selected = i ? !1 : t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
|
|
202
|
+
}
|
|
203
|
+
n instanceof f && (r ||= n, n.selected = i ? !1 : t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
|
|
204
|
+
}
|
|
205
|
+
this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
|
|
206
|
+
let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
|
|
207
|
+
this.selectedOrder = o;
|
|
208
|
+
}
|
|
209
|
+
getSelected() {
|
|
210
|
+
return this.getSelectedOptions().map((e) => e.id);
|
|
211
|
+
}
|
|
212
|
+
getSelectedValues() {
|
|
213
|
+
return this.getSelectedOptions().map((e) => e.value);
|
|
214
|
+
}
|
|
215
|
+
getSelectedOptions() {
|
|
216
|
+
return this.filter((e) => e.selected, !1);
|
|
217
|
+
}
|
|
218
|
+
getOptgroupByID(e) {
|
|
219
|
+
for (let t of this.data) if (t instanceof p && t.id === e) return t;
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
getOptionByID(e) {
|
|
223
|
+
let t = this.filter((t) => t.id === e, !1);
|
|
224
|
+
return t.length ? t[0] : null;
|
|
225
|
+
}
|
|
226
|
+
getSelectType() {
|
|
227
|
+
return this.selectType;
|
|
228
|
+
}
|
|
229
|
+
getFirstOption() {
|
|
230
|
+
let e = null;
|
|
231
|
+
for (let t of this.data) if (t instanceof p ? e = t.options[0] : t instanceof f && (e = t), e) break;
|
|
232
|
+
return e;
|
|
233
|
+
}
|
|
234
|
+
search(e, t) {
|
|
235
|
+
return e = e.trim(), e === "" ? this.getData() : this.filter((n) => t(n, e), !0);
|
|
236
|
+
}
|
|
237
|
+
filter(e, t) {
|
|
238
|
+
let n = [];
|
|
239
|
+
return this.data.forEach((r) => {
|
|
240
|
+
if (r instanceof p) {
|
|
241
|
+
let i = [];
|
|
242
|
+
if (r.options.forEach((r) => {
|
|
243
|
+
(!e || e(r)) && (t ? i.push(new f(r)) : n.push(new f(r)));
|
|
244
|
+
}), i.length > 0) {
|
|
245
|
+
let e = new p(r);
|
|
246
|
+
e.options = i, n.push(e);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
r instanceof f && (!e || e(r)) && n.push(new f(r));
|
|
250
|
+
}), n;
|
|
251
|
+
}
|
|
252
|
+
selectedOrderOptions(e) {
|
|
253
|
+
let t = [];
|
|
254
|
+
return this.selectedOrder.forEach((n) => {
|
|
255
|
+
let r = e.find((e) => e.id === n);
|
|
256
|
+
r && t.push(r);
|
|
257
|
+
}), e.forEach((e) => {
|
|
258
|
+
let n = !1;
|
|
259
|
+
t.forEach((t) => {
|
|
260
|
+
if (e.id === t.id) {
|
|
261
|
+
n = !0;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}), n || t.push(e);
|
|
265
|
+
}), t;
|
|
266
|
+
}
|
|
267
|
+
}, h = class {
|
|
268
|
+
settings;
|
|
269
|
+
store;
|
|
270
|
+
callbacks;
|
|
271
|
+
lastSelectedOption;
|
|
272
|
+
lastRenderedOptions;
|
|
273
|
+
closeAnimationTimeout = null;
|
|
274
|
+
main;
|
|
275
|
+
content;
|
|
276
|
+
classes;
|
|
277
|
+
constructor(e, t, n, r) {
|
|
278
|
+
this.store = n, this.settings = e, this.classes = t, this.callbacks = r, 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);
|
|
279
|
+
}
|
|
280
|
+
addClasses(e, t) {
|
|
281
|
+
if (!t || t.trim() === "") return;
|
|
282
|
+
let n = t.split(" ").filter((e) => e.trim() !== "");
|
|
283
|
+
for (let t of n) e.classList.add(t.trim());
|
|
284
|
+
}
|
|
285
|
+
removeClasses(e, t) {
|
|
286
|
+
if (!t || t.trim() === "") return;
|
|
287
|
+
let n = t.split(" ").filter((e) => e.trim() !== "");
|
|
288
|
+
for (let t of n) e.classList.remove(t.trim());
|
|
289
|
+
}
|
|
290
|
+
enable() {
|
|
291
|
+
this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
|
|
292
|
+
}
|
|
293
|
+
disable() {
|
|
294
|
+
this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
|
|
295
|
+
}
|
|
296
|
+
open() {
|
|
297
|
+
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true"), this.closeAnimationTimeout &&= (clearTimeout(this.closeAnimationTimeout), null);
|
|
298
|
+
let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
|
|
299
|
+
this.addClasses(this.main.main, e), this.addClasses(this.content.main, e), this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
|
|
300
|
+
let t = this.store.getSelectedOptions();
|
|
301
|
+
if (t.length) {
|
|
302
|
+
let e = t[t.length - 1].id, n = this.content.list.querySelector("[data-id=\"" + e + "\"]");
|
|
303
|
+
n && this.ensureElementInView(this.content.list, n);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
close() {
|
|
307
|
+
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.removeClasses(this.content.main, this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
308
|
+
let e = this.getAnimationTiming();
|
|
309
|
+
this.closeAnimationTimeout = setTimeout(() => {
|
|
310
|
+
this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow), this.closeAnimationTimeout = null;
|
|
311
|
+
}, e);
|
|
312
|
+
}
|
|
313
|
+
getAnimationTiming() {
|
|
314
|
+
let e = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
315
|
+
if (e) {
|
|
316
|
+
if (e.endsWith("ms")) return parseFloat(e);
|
|
317
|
+
if (e.endsWith("s")) return parseFloat(e) * 1e3;
|
|
318
|
+
}
|
|
319
|
+
return 200;
|
|
320
|
+
}
|
|
321
|
+
updateClassStyles() {
|
|
322
|
+
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length) for (let e of this.settings.class) e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
|
|
323
|
+
(this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
|
|
324
|
+
}
|
|
325
|
+
updateAriaAttributes() {
|
|
326
|
+
let e = this.content.list.id;
|
|
327
|
+
this.main.main.role = "combobox", this.main.main.setAttribute("aria-haspopup", "listbox"), this.main.main.setAttribute("aria-controls", e), this.main.main.setAttribute("aria-expanded", "false"), this.content.list.setAttribute("role", "listbox"), this.content.list.setAttribute("aria-label", this.settings.ariaLabel + " listbox"), this.settings.isMultiple && this.content.list.setAttribute("aria-multiselectable", "true"), this.content.search.input.setAttribute("aria-controls", e);
|
|
328
|
+
}
|
|
329
|
+
mainDiv() {
|
|
330
|
+
let e = document.createElement("div");
|
|
331
|
+
e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (e) => {
|
|
332
|
+
switch (e.key) {
|
|
333
|
+
case "ArrowUp":
|
|
334
|
+
case "ArrowDown": return this.callbacks.open(), e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
335
|
+
case "Tab": return this.callbacks.close(), !0;
|
|
336
|
+
case "Enter":
|
|
337
|
+
case " ":
|
|
338
|
+
this.callbacks.open();
|
|
339
|
+
let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
340
|
+
return t && t.click(), !1;
|
|
341
|
+
case "Escape": return this.callbacks.close(), !1;
|
|
342
|
+
}
|
|
343
|
+
return e.key.length === 1 && this.callbacks.open(), !0;
|
|
344
|
+
}, e.onclick = (e) => {
|
|
345
|
+
this.settings.disabled || (this.settings.isOpen ? this.callbacks.close() : this.callbacks.open());
|
|
346
|
+
};
|
|
347
|
+
let t = document.createElement("div");
|
|
348
|
+
this.addClasses(t, this.classes.values), e.appendChild(t);
|
|
349
|
+
let n = document.createElement("div");
|
|
350
|
+
this.addClasses(n, this.classes.deselect), n.setAttribute("role", "button"), n.setAttribute("aria-label", this.settings.deselectText), n.setAttribute("tabindex", "0");
|
|
351
|
+
let r = this.store?.getSelectedOptions();
|
|
352
|
+
!this.settings.allowDeselect || this.settings.isMultiple && r && r.length <= 0 ? this.addClasses(n, this.classes.hide) : this.removeClasses(n, this.classes.hide), n.onclick = (e) => {
|
|
353
|
+
if (e.stopPropagation(), this.settings.disabled) return;
|
|
354
|
+
let t = !0, n = this.store.getSelectedOptions();
|
|
355
|
+
if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange([], n) === !0), t) {
|
|
356
|
+
if (this.settings.isMultiple) this.callbacks.setSelected([], !1), this.updateDeselectAll();
|
|
357
|
+
else {
|
|
358
|
+
let e = this.store.getFirstOption(), t = e ? e.id : "";
|
|
359
|
+
this.callbacks.setSelected(t, !1);
|
|
360
|
+
}
|
|
361
|
+
this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
|
|
362
|
+
}
|
|
363
|
+
}, n.onkeydown = (e) => {
|
|
364
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), n.click());
|
|
365
|
+
};
|
|
366
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
367
|
+
i.setAttribute("viewBox", "0 0 100 100");
|
|
368
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
369
|
+
a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), n.appendChild(i), e.appendChild(n);
|
|
370
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
371
|
+
this.addClasses(o, this.classes.arrow), o.setAttribute("viewBox", "0 0 100 100");
|
|
372
|
+
let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
373
|
+
return s.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(o, this.classes.hide), o.appendChild(s), e.appendChild(o), {
|
|
374
|
+
main: e,
|
|
375
|
+
values: t,
|
|
376
|
+
deselect: {
|
|
377
|
+
main: n,
|
|
378
|
+
svg: i,
|
|
379
|
+
path: a
|
|
380
|
+
},
|
|
381
|
+
arrow: {
|
|
382
|
+
main: o,
|
|
383
|
+
path: s
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
mainFocus(e) {
|
|
388
|
+
e !== "click" && this.main.main.focus({ preventScroll: !0 });
|
|
389
|
+
}
|
|
390
|
+
placeholder() {
|
|
391
|
+
let e = this.store.filter((e) => e.placeholder, !1), t = this.settings.placeholderText;
|
|
392
|
+
e.length && (e[0].html === "" ? e[0].text !== "" && (t = e[0].text) : t = e[0].html);
|
|
393
|
+
let n = document.createElement("div");
|
|
394
|
+
return this.addClasses(n, this.classes.placeholder), n.innerHTML = t, n;
|
|
395
|
+
}
|
|
396
|
+
renderValues() {
|
|
397
|
+
if (!this.settings.isMultiple) {
|
|
398
|
+
this.renderSingleValue();
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
this.renderMultipleValues(), this.updateDeselectAll();
|
|
402
|
+
}
|
|
403
|
+
renderSingleValue() {
|
|
404
|
+
let e = this.store.filter((e) => e.selected && !e.placeholder, !1), t = e.length > 0 ? e[0] : null;
|
|
405
|
+
if (!t) this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
406
|
+
else {
|
|
407
|
+
let e = document.createElement("div");
|
|
408
|
+
this.addClasses(e, this.classes.single), t.html ? e.innerHTML = t.html : e.innerText = t.text, this.main.values.innerHTML = e.outerHTML;
|
|
409
|
+
}
|
|
410
|
+
!this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
|
|
411
|
+
}
|
|
412
|
+
renderMultipleValues() {
|
|
413
|
+
let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1);
|
|
414
|
+
if (t.length === 0) {
|
|
415
|
+
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
416
|
+
return;
|
|
417
|
+
} else {
|
|
418
|
+
let e = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
|
|
419
|
+
e && e.remove();
|
|
420
|
+
}
|
|
421
|
+
if (this.settings.multiString) {
|
|
422
|
+
let e = t;
|
|
423
|
+
this.settings.keepOrder && (e = this.store.selectedOrderOptions(e));
|
|
424
|
+
let n = document.createElement("div");
|
|
425
|
+
this.addClasses(n, this.classes.multiString), n.textContent = e.map((e) => e.text).join(", "), this.settings.showOptionTooltips && n.setAttribute("title", n.textContent), this.main.values.innerHTML = n.outerHTML;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (t.length > this.settings.maxValuesShown) {
|
|
429
|
+
let e = document.createElement("div");
|
|
430
|
+
this.addClasses(e, this.classes.max), e.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = e.outerHTML;
|
|
431
|
+
return;
|
|
432
|
+
} else {
|
|
433
|
+
let e = this.main.values.querySelector("." + this.classes.getFirst("max"));
|
|
434
|
+
e && e.remove();
|
|
435
|
+
}
|
|
436
|
+
this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
|
|
437
|
+
let n = [];
|
|
438
|
+
for (let r = 0; r < e.length; r++) {
|
|
439
|
+
let i = e[r], a = i.getAttribute("data-id");
|
|
440
|
+
a && (t.filter((e) => e.id === a, !1).length || n.push(i));
|
|
441
|
+
}
|
|
442
|
+
for (let e of n) this.addClasses(e, this.classes.valueOut), setTimeout(() => {
|
|
443
|
+
this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
|
|
444
|
+
}, 100);
|
|
445
|
+
e = this.main.values.childNodes;
|
|
446
|
+
for (let n = 0; n < t.length; n++) {
|
|
447
|
+
let r = !0;
|
|
448
|
+
for (let i = 0; i < e.length; i++) t[n].id === String(e[i].dataset.id) && (r = !1);
|
|
449
|
+
r && (this.settings.keepOrder || e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[n])) : n === 0 ? this.main.values.insertBefore(this.multipleValue(t[n]), e[n]) : e[n - 1].insertAdjacentElement("afterend", this.multipleValue(t[n])));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
multipleValue(e) {
|
|
453
|
+
let t = document.createElement("div");
|
|
454
|
+
this.addClasses(t, this.classes.value), t.dataset.id = e.id;
|
|
455
|
+
let n = document.createElement("div");
|
|
456
|
+
if (this.addClasses(n, this.classes.valueText), n.textContent = e.text, t.appendChild(n), !e.mandatory) {
|
|
457
|
+
let n = document.createElement("div");
|
|
458
|
+
this.addClasses(n, this.classes.valueDelete), n.setAttribute("tabindex", "0"), n.setAttribute("role", "button"), n.setAttribute("aria-label", `${this.settings.removeText} ${e.text}`), n.onclick = (t) => {
|
|
459
|
+
if (t.preventDefault(), t.stopPropagation(), this.settings.disabled) return;
|
|
460
|
+
let n = !0, r = this.store.getSelectedOptions(), i = r.filter((t) => t.selected && t.id !== e.id, !0);
|
|
461
|
+
if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
|
|
462
|
+
let e = [];
|
|
463
|
+
for (let t of i) {
|
|
464
|
+
if (t instanceof p) for (let n of t.options) n.id && e.push(n.id);
|
|
465
|
+
t instanceof f && e.push(t.id);
|
|
466
|
+
}
|
|
467
|
+
this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll();
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
let r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
471
|
+
r.setAttribute("viewBox", "0 0 100 100");
|
|
472
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
473
|
+
i.setAttribute("d", this.classes.optionDelete), r.appendChild(i), n.appendChild(r), t.appendChild(n), n.onkeydown = (e) => {
|
|
474
|
+
e.key === "Enter" && n.click();
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
return t;
|
|
478
|
+
}
|
|
479
|
+
contentDiv() {
|
|
480
|
+
let e = document.createElement("div");
|
|
481
|
+
e.dataset.id = this.settings.id;
|
|
482
|
+
let t = this.searchDiv();
|
|
483
|
+
e.appendChild(t.main);
|
|
484
|
+
let n = document.createElement("div");
|
|
485
|
+
this.addClasses(n, this.classes.status), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true"), n.setAttribute("role", "status"), e.appendChild(n);
|
|
486
|
+
let r = this.listDiv();
|
|
487
|
+
return e.appendChild(r), {
|
|
488
|
+
main: e,
|
|
489
|
+
search: t,
|
|
490
|
+
status: n,
|
|
491
|
+
list: r
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
announce(e) {
|
|
495
|
+
this.settings.showSearch && (this.content.status.textContent = e);
|
|
496
|
+
}
|
|
497
|
+
moveContent() {
|
|
498
|
+
if (this.settings.contentPosition === "relative") {
|
|
499
|
+
this.moveContentBelow();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (this.settings.openPosition === "down") {
|
|
503
|
+
this.moveContentBelow();
|
|
504
|
+
return;
|
|
505
|
+
} else if (this.settings.openPosition === "up") {
|
|
506
|
+
this.moveContentAbove();
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
|
|
510
|
+
}
|
|
511
|
+
searchDiv() {
|
|
512
|
+
let e = document.createElement("div"), t = document.createElement("input"), n = document.createElement("div");
|
|
513
|
+
this.addClasses(e, this.classes.search);
|
|
514
|
+
let r = {
|
|
515
|
+
main: e,
|
|
516
|
+
input: t
|
|
517
|
+
};
|
|
518
|
+
if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true"), t.oninput = l((e) => {
|
|
519
|
+
this.callbacks.search(e.target.value);
|
|
520
|
+
}, 100), t.onkeydown = (e) => {
|
|
521
|
+
switch (e.key) {
|
|
522
|
+
case "ArrowUp":
|
|
523
|
+
case "ArrowDown": return e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
524
|
+
case "Tab": return this.callbacks.close(), !0;
|
|
525
|
+
case "Escape": return this.callbacks.close(), !1;
|
|
526
|
+
case " ":
|
|
527
|
+
let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
528
|
+
return t ? (t.click(), !1) : !0;
|
|
529
|
+
case "Enter":
|
|
530
|
+
let r = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
531
|
+
return r ? (r.click(), !1) : this.callbacks.addable ? (n.click(), !1) : !0;
|
|
532
|
+
}
|
|
533
|
+
return !0;
|
|
534
|
+
}, e.appendChild(t), this.callbacks.addable) {
|
|
535
|
+
this.addClasses(n, this.classes.addable);
|
|
536
|
+
let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
537
|
+
t.setAttribute("viewBox", "0 0 100 100");
|
|
538
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
539
|
+
i.setAttribute("d", this.classes.addablePath), t.appendChild(i), n.appendChild(t), n.onclick = (e) => {
|
|
540
|
+
if (e.preventDefault(), e.stopPropagation(), !this.callbacks.addable) return;
|
|
541
|
+
let t = this.content.search.input.value.trim();
|
|
542
|
+
if (t === "") {
|
|
543
|
+
this.content.search.input.focus();
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
let n = (e) => {
|
|
547
|
+
let t = new f(e);
|
|
548
|
+
if (this.callbacks.addOption(t), this.settings.isMultiple) {
|
|
549
|
+
let e = this.store.getSelected();
|
|
550
|
+
e.push(t.id), this.callbacks.setSelected(e, !0);
|
|
551
|
+
} else this.callbacks.setSelected([t.id], !0);
|
|
552
|
+
this.callbacks.search(""), this.settings.closeOnSelect && setTimeout(() => {
|
|
553
|
+
this.callbacks.close();
|
|
554
|
+
}, 100);
|
|
555
|
+
}, r = this.callbacks.addable(t);
|
|
556
|
+
r === !1 || r == null || (r instanceof Promise ? r.then((e) => {
|
|
557
|
+
typeof e == "string" ? n({
|
|
558
|
+
text: e,
|
|
559
|
+
value: e
|
|
560
|
+
}) : r instanceof Error ? this.renderError(r.message) : n(e);
|
|
561
|
+
}) : typeof r == "string" ? n({
|
|
562
|
+
text: r,
|
|
563
|
+
value: r
|
|
564
|
+
}) : r instanceof Error ? this.renderError(r.message) : n(r));
|
|
565
|
+
}, e.appendChild(n), r.addable = {
|
|
566
|
+
main: n,
|
|
567
|
+
svg: t,
|
|
568
|
+
path: i
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
return r;
|
|
572
|
+
}
|
|
573
|
+
searchFocus() {
|
|
574
|
+
this.content.search.input.focus({ preventScroll: !0 });
|
|
575
|
+
}
|
|
576
|
+
getOptions(e = !1, t = !1, n = !1) {
|
|
577
|
+
let r = "." + this.classes.getFirst("option");
|
|
578
|
+
return e && (r += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (r += ":not(." + this.classes.getFirst("disabled") + ")"), n && (r += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(r));
|
|
579
|
+
}
|
|
580
|
+
highlight(e) {
|
|
581
|
+
let t = this.getOptions(!0, !0, !0);
|
|
582
|
+
if (t.length === 0) return;
|
|
583
|
+
if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
584
|
+
this.addClasses(t[0], this.classes.highlighted);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
let n = !1;
|
|
588
|
+
for (let e of t) e.classList.contains(this.classes.getFirst("highlighted")) && (n = !0);
|
|
589
|
+
if (!n) {
|
|
590
|
+
for (let e of t) if (e.classList.contains(this.classes.getFirst("selected"))) {
|
|
591
|
+
this.addClasses(e, this.classes.highlighted);
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
for (let n = 0; n < t.length; n++) if (t[n].classList.contains(this.classes.getFirst("highlighted"))) {
|
|
596
|
+
let r = t[n];
|
|
597
|
+
this.removeClasses(r, this.classes.highlighted);
|
|
598
|
+
let i = r.parentElement;
|
|
599
|
+
if (i && i.classList.contains(this.classes.getFirst("mainOpen"))) {
|
|
600
|
+
let e = i.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
601
|
+
e && e.click();
|
|
602
|
+
}
|
|
603
|
+
let a = t[e === "down" ? n + 1 < t.length ? n + 1 : 0 : n - 1 >= 0 ? n - 1 : t.length - 1];
|
|
604
|
+
this.addClasses(a, this.classes.highlighted), this.ensureElementInView(this.content.list, a), a.id && this.main.main.setAttribute("aria-activedescendant", a.id);
|
|
605
|
+
let o = a.parentElement;
|
|
606
|
+
if (o && o.classList.contains(this.classes.getFirst("close"))) {
|
|
607
|
+
let e = o.querySelector("." + this.classes.getFirst("optgroupLabel"));
|
|
608
|
+
e && e.click();
|
|
609
|
+
}
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
let r = t[e === "down" ? 0 : t.length - 1];
|
|
613
|
+
this.addClasses(r, this.classes.highlighted), r.id && this.main.main.setAttribute("aria-activedescendant", r.id), this.ensureElementInView(this.content.list, r);
|
|
614
|
+
}
|
|
615
|
+
listDiv() {
|
|
616
|
+
let e = document.createElement("div");
|
|
617
|
+
this.addClasses(e, this.classes.list);
|
|
618
|
+
let t = this.settings.id + "-list";
|
|
619
|
+
return e.id = t, e.dataset.id = t, e;
|
|
620
|
+
}
|
|
621
|
+
renderError(e) {
|
|
622
|
+
this.content.list.innerHTML = "";
|
|
623
|
+
let t = document.createElement("div");
|
|
624
|
+
this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
|
|
625
|
+
}
|
|
626
|
+
renderSearching() {
|
|
627
|
+
this.content.list.innerHTML = "";
|
|
628
|
+
let e = document.createElement("div");
|
|
629
|
+
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
|
|
630
|
+
}
|
|
631
|
+
renderOptions(e) {
|
|
632
|
+
if (this.lastRenderedOptions = e.map((e) => e instanceof f ? [e] : e.options.map((e) => new f(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
|
|
633
|
+
let e = document.createElement("div");
|
|
634
|
+
if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
|
|
635
|
+
let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
|
|
636
|
+
e.innerHTML = t, this.announce(t);
|
|
637
|
+
} else e.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
|
|
638
|
+
this.content.list.appendChild(e);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1).length || this.store.addOption(new f({
|
|
642
|
+
text: "",
|
|
643
|
+
value: "",
|
|
644
|
+
selected: !1,
|
|
645
|
+
placeholder: !0
|
|
646
|
+
}), !0));
|
|
647
|
+
let t = document.createDocumentFragment();
|
|
648
|
+
for (let n of e) {
|
|
649
|
+
if (n instanceof p) {
|
|
650
|
+
let e = document.createElement("div");
|
|
651
|
+
this.addClasses(e, this.classes.optgroup);
|
|
652
|
+
let r = document.createElement("div");
|
|
653
|
+
this.addClasses(r, this.classes.optgroupLabel), e.appendChild(r);
|
|
654
|
+
let i = document.createElement("div");
|
|
655
|
+
this.addClasses(i, this.classes.optgroupLabelText), i.textContent = n.label, r.appendChild(i);
|
|
656
|
+
let a = document.createElement("div");
|
|
657
|
+
if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && n.selectAll) {
|
|
658
|
+
let e = document.createElement("div");
|
|
659
|
+
this.addClasses(e, this.classes.optgroupSelectAll);
|
|
660
|
+
let t = !0;
|
|
661
|
+
for (let e of n.options) if (!e.selected) {
|
|
662
|
+
t = !1;
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
t && this.addClasses(e, this.classes.selected);
|
|
666
|
+
let r = document.createElement("span");
|
|
667
|
+
r.textContent = n.selectAllText, e.appendChild(r);
|
|
668
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
669
|
+
i.setAttribute("viewBox", "0 0 100 100"), e.appendChild(i);
|
|
670
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
671
|
+
o.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(o);
|
|
672
|
+
let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
673
|
+
s.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(s), e.addEventListener("click", (e) => {
|
|
674
|
+
e.preventDefault(), e.stopPropagation();
|
|
675
|
+
let r = this.store.getSelected();
|
|
676
|
+
if (t) {
|
|
677
|
+
let e = r.filter((e) => {
|
|
678
|
+
for (let t of n.options) if (e === t.id) return !1;
|
|
679
|
+
return !0;
|
|
680
|
+
});
|
|
681
|
+
this.callbacks.setSelected(e, !0);
|
|
682
|
+
return;
|
|
683
|
+
} else {
|
|
684
|
+
let e = n.options.map((e) => e.id).filter((e) => e !== void 0), t = r.concat(e);
|
|
685
|
+
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new f(e));
|
|
686
|
+
this.callbacks.setSelected(t, !0);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
}), a.appendChild(e);
|
|
690
|
+
}
|
|
691
|
+
if (n.closable !== "off") {
|
|
692
|
+
let t = document.createElement("div");
|
|
693
|
+
this.addClasses(t, this.classes.optgroupClosable);
|
|
694
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
695
|
+
i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), t.appendChild(i);
|
|
696
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
697
|
+
i.appendChild(o), n.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(t, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (t) => {
|
|
698
|
+
t.preventDefault(), t.stopPropagation(), e.classList.contains(this.classes.getFirst("close")) ? (this.removeClasses(e, this.classes.close), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : (this.removeClasses(e, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose));
|
|
699
|
+
}), a.appendChild(t);
|
|
700
|
+
}
|
|
701
|
+
e.appendChild(r);
|
|
702
|
+
for (let r of n.options) e.appendChild(this.option(new f(r))), t.appendChild(e);
|
|
703
|
+
}
|
|
704
|
+
n instanceof f && t.appendChild(this.option(n));
|
|
705
|
+
}
|
|
706
|
+
this.content.list.appendChild(t), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
|
|
707
|
+
}
|
|
708
|
+
option(e) {
|
|
709
|
+
if (e.placeholder) {
|
|
710
|
+
let e = document.createElement("div");
|
|
711
|
+
return this.addClasses(e, this.classes.option), this.addClasses(e, this.classes.hide), e;
|
|
712
|
+
}
|
|
713
|
+
let t = document.createElement("div");
|
|
714
|
+
return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, this.addClasses(t, this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((e) => {
|
|
715
|
+
t.classList.add(e);
|
|
716
|
+
}), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(e.html === "" ? e.text : e.html, this.content.search.input.value, this.classes.searchHighlighter) : e.html === "" ? t.textContent = e.text : t.innerHTML = e.html, 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", (t) => {
|
|
717
|
+
t.preventDefault(), t.stopPropagation();
|
|
718
|
+
let n = this.store.getSelected(), r = t.currentTarget, i = String(r.dataset.id), a = t.ctrlKey || t.metaKey;
|
|
719
|
+
if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= n.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= n.length && e.selected && !a) return;
|
|
720
|
+
let o = !1, s = this.store.getSelectedOptions(), c = [];
|
|
721
|
+
if (this.settings.isMultiple) {
|
|
722
|
+
let n = s.some((e) => e.id === i);
|
|
723
|
+
if (t.shiftKey && this.lastSelectedOption) {
|
|
724
|
+
let t = this.lastRenderedOptions, n = t.findIndex((e) => e.id === this.lastSelectedOption.id), r = t.findIndex((t) => t.id === e.id);
|
|
725
|
+
if (n >= 0 && r >= 0) {
|
|
726
|
+
let e = Math.min(n, r), i = Math.max(n, r), a = t.slice(e, i + 1).filter((e) => !s.find((t) => t.id === e.id));
|
|
727
|
+
c = s.length + a.length <= this.settings.maxSelected ? s.concat(a) : s;
|
|
728
|
+
} else c = s;
|
|
729
|
+
} else c = n ? s.filter((e) => e.id !== i) : s.concat(e), this.lastSelectedOption = e;
|
|
730
|
+
}
|
|
731
|
+
if (this.settings.isMultiple || (c = e.selected ? [] : [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (o = this.callbacks.beforeChange(c, s) !== !1), o) {
|
|
732
|
+
this.store.getOptionByID(i) || this.callbacks.addOption(e), this.callbacks.setSelected(c.map((e) => e.id), !1);
|
|
733
|
+
let n = t.ctrlKey || t.metaKey || t.shiftKey;
|
|
734
|
+
this.settings.closeOnSelect && !(this.settings.isMultiple && n) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(c);
|
|
735
|
+
}
|
|
736
|
+
}), t;
|
|
737
|
+
}
|
|
738
|
+
destroy() {
|
|
739
|
+
this.closeAnimationTimeout &&= (clearTimeout(this.closeAnimationTimeout), null), this.main.main.remove(), this.content.main.remove();
|
|
740
|
+
}
|
|
741
|
+
highlightText(e, t, n) {
|
|
742
|
+
let r = t.trim();
|
|
743
|
+
if (r === "") return e;
|
|
744
|
+
let i = r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = document.createElement("div");
|
|
745
|
+
a.innerHTML = e;
|
|
746
|
+
let o = (e) => {
|
|
747
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
748
|
+
let t = e.textContent || "", r = RegExp("(" + i + ")", "i");
|
|
749
|
+
if (r.test(t)) {
|
|
750
|
+
let i = document.createElement("span");
|
|
751
|
+
t.split(r).forEach((e, t) => {
|
|
752
|
+
if (e && r.test(e)) {
|
|
753
|
+
let t = document.createElement("mark");
|
|
754
|
+
t.className = n, t.textContent = e, i.appendChild(t);
|
|
755
|
+
} else e && i.appendChild(document.createTextNode(e));
|
|
756
|
+
}), e.parentNode?.replaceChild(i, e);
|
|
757
|
+
}
|
|
758
|
+
} else e.nodeType === Node.ELEMENT_NODE && Array.from(e.childNodes).forEach((e) => o(e));
|
|
759
|
+
};
|
|
760
|
+
return Array.from(a.childNodes).forEach((e) => o(e)), a.innerHTML;
|
|
761
|
+
}
|
|
762
|
+
setContentDirection(e) {
|
|
763
|
+
let t = e === "above", n = t ? this.classes.dirAbove : this.classes.dirBelow, r = t ? this.classes.dirBelow : this.classes.dirAbove;
|
|
764
|
+
if (this.removeClasses(this.main.main, r), this.addClasses(this.main.main, n), this.removeClasses(this.content.main, r), this.addClasses(this.content.main, n), t) {
|
|
765
|
+
let e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
|
|
766
|
+
this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px";
|
|
767
|
+
} else this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
768
|
+
}
|
|
769
|
+
setContentPosition() {
|
|
770
|
+
if (this.settings.contentPosition === "relative") return;
|
|
771
|
+
let e = this.main.main.getBoundingClientRect(), t, n;
|
|
772
|
+
this.settings.contentPosition === "fixed" ? (t = e.top + e.height, n = e.left) : (t = e.top + window.scrollY + e.height, n = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = n + "px";
|
|
773
|
+
let r = this.settings.contentWidth;
|
|
774
|
+
this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", r ? r.startsWith(">") ? this.content.main.style.minWidth = r.slice(1) : r.startsWith("<") ? this.content.main.style.maxWidth = r.slice(1) : this.content.main.style.width = r : this.content.main.style.width = e.width + "px";
|
|
775
|
+
let i = window.innerWidth - 20, a = () => {
|
|
776
|
+
let e = this.content.main.getBoundingClientRect().right;
|
|
777
|
+
if (e <= i) return;
|
|
778
|
+
let t = e - i, n = parseFloat(this.content.main.style.left) || 0;
|
|
779
|
+
if (this.settings.contentPosition === "fixed") {
|
|
780
|
+
let e = Math.max(20, n - t);
|
|
781
|
+
this.content.main.style.left = e + "px";
|
|
782
|
+
} else {
|
|
783
|
+
let e = Math.max(window.scrollX + 20, n - t);
|
|
784
|
+
this.content.main.style.left = e + "px";
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
requestAnimationFrame(() => {
|
|
788
|
+
a(), requestAnimationFrame(a);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
moveContentAbove() {
|
|
792
|
+
this.setContentDirection("above"), this.setContentPosition();
|
|
793
|
+
}
|
|
794
|
+
moveContentBelow() {
|
|
795
|
+
this.setContentDirection("below"), this.setContentPosition();
|
|
796
|
+
}
|
|
797
|
+
ensureElementInView(e, t) {
|
|
798
|
+
let n = e.scrollTop + e.offsetTop, r = n + e.clientHeight, i = t.offsetTop, a = i + t.clientHeight;
|
|
799
|
+
i < n ? e.scrollTop -= n - i : a > r && (e.scrollTop += a - r);
|
|
800
|
+
}
|
|
801
|
+
putContent() {
|
|
802
|
+
let e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), n = this.content.main.offsetHeight;
|
|
803
|
+
return window.innerHeight - (t.top + e) <= n && t.top > n ? "up" : "down";
|
|
804
|
+
}
|
|
805
|
+
updateDeselectAll() {
|
|
806
|
+
if (!this.store || !this.settings) return;
|
|
807
|
+
let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.main.deselect.main, a = this.classes.hide;
|
|
808
|
+
r && !(n && !t) ? this.removeClasses(i, a) : this.addClasses(i, a);
|
|
809
|
+
}
|
|
810
|
+
}, g = class {
|
|
811
|
+
select;
|
|
812
|
+
onValueChange;
|
|
813
|
+
onClassChange;
|
|
814
|
+
onDisabledChange;
|
|
815
|
+
onOptionsChange;
|
|
816
|
+
onLabelClick;
|
|
817
|
+
listen = !1;
|
|
818
|
+
observer = null;
|
|
819
|
+
isUpdating = !1;
|
|
820
|
+
pendingOptionsChange = null;
|
|
821
|
+
preventNativeSelect = null;
|
|
822
|
+
preventNativeSelectMousedown = null;
|
|
823
|
+
preventNativeSelectFocus = null;
|
|
824
|
+
constructor(e) {
|
|
825
|
+
this.select = e, this.valueChange = this.valueChange.bind(this), this.select.addEventListener("change", this.valueChange, { passive: !0 }), this.observer = new MutationObserver(this.observeCall.bind(this)), this.changeListen(!0);
|
|
826
|
+
}
|
|
827
|
+
enable() {
|
|
828
|
+
this.select.disabled = !1;
|
|
829
|
+
}
|
|
830
|
+
disable() {
|
|
831
|
+
this.select.disabled = !0;
|
|
832
|
+
}
|
|
833
|
+
hideUI() {
|
|
834
|
+
this.select.tabIndex = -1, this.select.style.position = "absolute", this.select.style.width = "1px", this.select.style.height = "1px", this.select.style.opacity = "0", this.select.style.overflow = "hidden", this.select.style.pointerEvents = "none", this.select.style.margin = "0", this.select.style.padding = "0", this.select.style.borderWidth = "0", this.select.style.clip = "rect(0 0 0 0)", this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
|
|
835
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
836
|
+
}, this.preventNativeSelectMousedown = (e) => {
|
|
837
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
838
|
+
}, this.preventNativeSelectFocus = (e) => {
|
|
839
|
+
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
840
|
+
}, this.select.addEventListener("click", this.preventNativeSelect, {
|
|
841
|
+
capture: !0,
|
|
842
|
+
passive: !1
|
|
843
|
+
}), this.select.addEventListener("mousedown", this.preventNativeSelectMousedown, {
|
|
844
|
+
capture: !0,
|
|
845
|
+
passive: !1
|
|
846
|
+
}), this.select.addEventListener("focus", this.preventNativeSelectFocus, {
|
|
847
|
+
capture: !0,
|
|
848
|
+
passive: !1
|
|
849
|
+
}));
|
|
850
|
+
}
|
|
851
|
+
showUI() {
|
|
852
|
+
this.select.removeAttribute("tabindex"), this.select.style.position = "", this.select.style.width = "", this.select.style.height = "", this.select.style.opacity = "", this.select.style.overflow = "", this.select.style.pointerEvents = "", this.select.style.margin = "", this.select.style.padding = "", this.select.style.borderWidth = "", this.select.style.clip = "", this.select.removeAttribute("aria-hidden"), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null);
|
|
853
|
+
}
|
|
854
|
+
changeListen(e) {
|
|
855
|
+
this.listen = e, e && this.observer && this.observer.observe(this.select, {
|
|
856
|
+
subtree: !0,
|
|
857
|
+
childList: !0,
|
|
858
|
+
attributes: !0
|
|
859
|
+
}), e || this.observer && this.observer.disconnect();
|
|
860
|
+
}
|
|
861
|
+
valueChange(e) {
|
|
862
|
+
return this.listen && this.onValueChange && this.onValueChange(this.getSelectedOptions()), !0;
|
|
863
|
+
}
|
|
864
|
+
observeCall(e) {
|
|
865
|
+
if (!this.listen) return;
|
|
866
|
+
let t = !1, n = !1, r = !1, i = !1;
|
|
867
|
+
for (let a of e) {
|
|
868
|
+
if (a.target === this.select && (a.attributeName === "disabled" && (n = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
|
|
869
|
+
for (let e of Array.from(a.addedNodes)) if (e.nodeName === "OPTION" && e.value === this.select.value) {
|
|
870
|
+
i = !0;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
r = !0;
|
|
874
|
+
}
|
|
875
|
+
(a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (r = !0);
|
|
876
|
+
}
|
|
877
|
+
if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), n && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), r && this.onOptionsChange) {
|
|
878
|
+
if (this.isUpdating) {
|
|
879
|
+
if (this.select.options.length > 0) {
|
|
880
|
+
let e = this.getData();
|
|
881
|
+
e.length > 0 && (this.pendingOptionsChange = e);
|
|
882
|
+
}
|
|
883
|
+
i && this.select.dispatchEvent(new Event("change"));
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
887
|
+
}
|
|
888
|
+
i && this.select.dispatchEvent(new Event("change"));
|
|
889
|
+
}
|
|
890
|
+
getData() {
|
|
891
|
+
let e = [], t = this.select.childNodes;
|
|
892
|
+
for (let n of t) n.nodeName === "OPTGROUP" && e.push(this.getDataFromOptgroup(n)), n.nodeName === "OPTION" && e.push(this.getDataFromOption(n));
|
|
893
|
+
return e;
|
|
894
|
+
}
|
|
895
|
+
getDataFromOptgroup(e) {
|
|
896
|
+
let t = {
|
|
897
|
+
id: e.id,
|
|
898
|
+
label: e.label,
|
|
899
|
+
selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
|
|
900
|
+
selectAllText: e.dataset ? e.dataset.selectalltext : "Select all",
|
|
901
|
+
closable: e.dataset ? e.dataset.closable : "off",
|
|
902
|
+
options: []
|
|
903
|
+
}, n = e.childNodes;
|
|
904
|
+
for (let e of n) e.nodeName === "OPTION" && t.options.push(this.getDataFromOption(e));
|
|
905
|
+
return t;
|
|
906
|
+
}
|
|
907
|
+
getDataFromOption(e) {
|
|
908
|
+
return {
|
|
909
|
+
id: e.id,
|
|
910
|
+
value: e.value,
|
|
911
|
+
text: e.text,
|
|
912
|
+
html: e.dataset && e.dataset.html ? e.dataset.html : "",
|
|
913
|
+
defaultSelected: e.defaultSelected,
|
|
914
|
+
selected: e.selected,
|
|
915
|
+
display: e.style.display !== "none",
|
|
916
|
+
disabled: e.disabled,
|
|
917
|
+
mandatory: e.dataset ? e.dataset.mandatory === "true" : !1,
|
|
918
|
+
placeholder: e.dataset.placeholder === "true",
|
|
919
|
+
class: e.className,
|
|
920
|
+
style: e.style.cssText,
|
|
921
|
+
data: e.dataset
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
getSelectedOptions() {
|
|
925
|
+
let e = [], t = this.select.childNodes;
|
|
926
|
+
for (let n of t) {
|
|
927
|
+
if (n.nodeName === "OPTGROUP") {
|
|
928
|
+
let t = n.childNodes;
|
|
929
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
930
|
+
let t = n;
|
|
931
|
+
t.selected && e.push(this.getDataFromOption(t));
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (n.nodeName === "OPTION") {
|
|
935
|
+
let t = n;
|
|
936
|
+
t.selected && e.push(this.getDataFromOption(t));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return e;
|
|
940
|
+
}
|
|
941
|
+
getSelectedValues() {
|
|
942
|
+
return this.getSelectedOptions().map((e) => e.value);
|
|
943
|
+
}
|
|
944
|
+
setSelected(e) {
|
|
945
|
+
this.changeListen(!1);
|
|
946
|
+
let t = this.select.childNodes;
|
|
947
|
+
for (let n of t) {
|
|
948
|
+
if (n.nodeName === "OPTGROUP") {
|
|
949
|
+
let t = n.childNodes;
|
|
950
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
951
|
+
let t = n;
|
|
952
|
+
t.selected = e.includes(t.id);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
if (n.nodeName === "OPTION") {
|
|
956
|
+
let t = n;
|
|
957
|
+
t.selected = e.includes(t.id);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
this.changeListen(!0);
|
|
961
|
+
}
|
|
962
|
+
setSelectedByValue(e) {
|
|
963
|
+
this.changeListen(!1);
|
|
964
|
+
let t = this.select.childNodes;
|
|
965
|
+
for (let n of t) {
|
|
966
|
+
if (n.nodeName === "OPTGROUP") {
|
|
967
|
+
let t = n.childNodes;
|
|
968
|
+
for (let n of t) if (n.nodeName === "OPTION") {
|
|
969
|
+
let t = n;
|
|
970
|
+
t.selected = e.includes(t.value);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (n.nodeName === "OPTION") {
|
|
974
|
+
let t = n;
|
|
975
|
+
t.selected = e.includes(t.value);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
this.changeListen(!0);
|
|
979
|
+
}
|
|
980
|
+
updateSelect(e, t, n) {
|
|
981
|
+
this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
|
|
982
|
+
e.trim() !== "" && this.select.classList.add(e.trim());
|
|
983
|
+
})), this.changeListen(!0);
|
|
984
|
+
}
|
|
985
|
+
updateOptions(e) {
|
|
986
|
+
if (!(!e || e.length === 0)) {
|
|
987
|
+
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
988
|
+
for (let t of e) t instanceof p && this.select.appendChild(this.createOptgroup(t)), t instanceof f && this.select.appendChild(this.createOption(t));
|
|
989
|
+
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
990
|
+
let e = this.pendingOptionsChange;
|
|
991
|
+
e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
createOptgroup(e) {
|
|
996
|
+
let t = document.createElement("optgroup");
|
|
997
|
+
if (t.id = e.id, t.label = e.label, e.selectAll && (t.dataset.selectAll = "true"), e.closable !== "off" && (t.dataset.closable = e.closable), e.options) for (let n of e.options) t.appendChild(this.createOption(n));
|
|
998
|
+
return t;
|
|
999
|
+
}
|
|
1000
|
+
createOption(e) {
|
|
1001
|
+
let t = document.createElement("option");
|
|
1002
|
+
return t.id = e.id, t.value = e.value, t.textContent = e.text, e.html !== "" && t.setAttribute("data-html", e.html), t.defaultSelected = e.defaultSelected, t.selected = e.selected, e.disabled && (t.disabled = !0), e.display || (t.style.display = "none"), e.placeholder && t.setAttribute("data-placeholder", "true"), e.mandatory && t.setAttribute("data-mandatory", "true"), e.class && e.class.split(" ").forEach((e) => {
|
|
1003
|
+
t.classList.add(e);
|
|
1004
|
+
}), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
|
|
1005
|
+
t.setAttribute("data-" + d(n), e.data[n]);
|
|
1006
|
+
}), t;
|
|
1007
|
+
}
|
|
1008
|
+
setupLabelHandlers() {
|
|
1009
|
+
let e = [], t = this.select.id;
|
|
1010
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
|
|
1011
|
+
let n = this.select.parentElement;
|
|
1012
|
+
for (; n && n !== document.body;) {
|
|
1013
|
+
if (n.tagName === "LABEL") {
|
|
1014
|
+
e.push(n);
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
n = n.parentElement;
|
|
1018
|
+
}
|
|
1019
|
+
Array.from(new Set(e)).forEach((e) => {
|
|
1020
|
+
if (e.__slimSelectLabelHandler) return;
|
|
1021
|
+
let t = (e) => {
|
|
1022
|
+
let t = e.target, n = c(t, this.select.dataset.id);
|
|
1023
|
+
e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
|
|
1024
|
+
};
|
|
1025
|
+
e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
|
|
1026
|
+
capture: !0,
|
|
1027
|
+
passive: !1
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
removeLabelHandlers() {
|
|
1032
|
+
let e = [], t = this.select.id;
|
|
1033
|
+
t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
|
|
1034
|
+
let n = this.select.parentElement;
|
|
1035
|
+
for (; n && n !== document.body;) {
|
|
1036
|
+
if (n.tagName === "LABEL") {
|
|
1037
|
+
e.push(n);
|
|
1038
|
+
break;
|
|
1039
|
+
}
|
|
1040
|
+
n = n.parentElement;
|
|
1041
|
+
}
|
|
1042
|
+
Array.from(new Set(e)).forEach((e) => {
|
|
1043
|
+
let t = e.__slimSelectLabelHandler;
|
|
1044
|
+
t && (e.removeEventListener("click", t, { capture: !0 }), delete e.__slimSelectLabelHandler);
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
destroy() {
|
|
1048
|
+
this.changeListen(!1), this.select.removeEventListener("change", this.valueChange), this.preventNativeSelect &&= (this.select.removeEventListener("click", this.preventNativeSelect, { capture: !0 }), null), this.preventNativeSelectMousedown &&= (this.select.removeEventListener("mousedown", this.preventNativeSelectMousedown, { capture: !0 }), null), this.preventNativeSelectFocus &&= (this.select.removeEventListener("focus", this.preventNativeSelectFocus, { capture: !0 }), null), this.observer &&= (this.observer.disconnect(), null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
|
|
1049
|
+
}
|
|
1050
|
+
}, _ = class {
|
|
1051
|
+
id = "";
|
|
1052
|
+
style = "";
|
|
1053
|
+
class = [];
|
|
1054
|
+
isMultiple = !1;
|
|
1055
|
+
isOpen = !1;
|
|
1056
|
+
isFullOpen = !1;
|
|
1057
|
+
intervalMove = null;
|
|
1058
|
+
disabled;
|
|
1059
|
+
alwaysOpen;
|
|
1060
|
+
showSearch;
|
|
1061
|
+
focusSearch;
|
|
1062
|
+
keepSearch;
|
|
1063
|
+
ariaLabel;
|
|
1064
|
+
searchPlaceholder;
|
|
1065
|
+
searchText;
|
|
1066
|
+
searchingText;
|
|
1067
|
+
resultsText;
|
|
1068
|
+
deselectText;
|
|
1069
|
+
removeText;
|
|
1070
|
+
searchHighlight;
|
|
1071
|
+
closeOnSelect;
|
|
1072
|
+
contentLocation;
|
|
1073
|
+
contentPosition;
|
|
1074
|
+
contentWidth;
|
|
1075
|
+
openPosition;
|
|
1076
|
+
placeholderText;
|
|
1077
|
+
allowDeselect;
|
|
1078
|
+
hideSelected;
|
|
1079
|
+
multiString;
|
|
1080
|
+
keepOrder;
|
|
1081
|
+
showOptionTooltips;
|
|
1082
|
+
minSelected;
|
|
1083
|
+
maxSelected;
|
|
1084
|
+
timeoutDelay;
|
|
1085
|
+
maxValuesShown;
|
|
1086
|
+
maxValuesMessage;
|
|
1087
|
+
addableText;
|
|
1088
|
+
constructor(e) {
|
|
1089
|
+
e ||= {}, this.id = "ss-" + s(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled === void 0 ? !1 : e.disabled, this.alwaysOpen = e.alwaysOpen === void 0 ? !1 : e.alwaysOpen, this.showSearch = e.showSearch === void 0 ? !0 : e.showSearch, this.focusSearch = e.focusSearch === void 0 ? !0 : e.focusSearch, this.keepSearch = e.keepSearch === void 0 ? !1 : e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight === void 0 ? !1 : e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 ? !0 : e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect === void 0 ? !1 : e.allowDeselect, this.hideSelected = e.hideSelected === void 0 ? !1 : e.hideSelected, this.multiString = e.multiString === void 0 ? !1 : e.multiString, this.keepOrder = e.keepOrder === void 0 ? !1 : e.keepOrder, this.showOptionTooltips = e.showOptionTooltips === void 0 ? !1 : e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}";
|
|
1090
|
+
}
|
|
1091
|
+
}, v = class {
|
|
1092
|
+
selectEl;
|
|
1093
|
+
settings;
|
|
1094
|
+
cssClasses;
|
|
1095
|
+
select;
|
|
1096
|
+
store;
|
|
1097
|
+
render;
|
|
1098
|
+
openTimeout = null;
|
|
1099
|
+
closeTimeout = null;
|
|
1100
|
+
events = {
|
|
1101
|
+
search: void 0,
|
|
1102
|
+
searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
|
|
1103
|
+
addable: void 0,
|
|
1104
|
+
beforeChange: void 0,
|
|
1105
|
+
afterChange: void 0,
|
|
1106
|
+
beforeOpen: void 0,
|
|
1107
|
+
afterOpen: void 0,
|
|
1108
|
+
beforeClose: void 0,
|
|
1109
|
+
afterClose: void 0
|
|
1110
|
+
};
|
|
1111
|
+
constructor(e) {
|
|
1112
|
+
if (this.selectEl = typeof e.select == "string" ? document.querySelector(e.select) : e.select, !this.selectEl) {
|
|
1113
|
+
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Could not find select element"));
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (this.selectEl.tagName !== "SELECT") {
|
|
1117
|
+
e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
this.selectEl.dataset.ssid && this.destroy(), this.settings = new _(e.settings), this.cssClasses = new o(e.cssClasses);
|
|
1121
|
+
let t = [
|
|
1122
|
+
"beforeOpen",
|
|
1123
|
+
"afterOpen",
|
|
1124
|
+
"beforeClose",
|
|
1125
|
+
"afterClose"
|
|
1126
|
+
];
|
|
1127
|
+
for (let n in e.events) e.events.hasOwnProperty(n) && (t.indexOf(n) === -1 ? this.events[n] = e.events[n] : this.events[n] = l(e.events[n], 100));
|
|
1128
|
+
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 g(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 = (e) => {
|
|
1129
|
+
this.setSelected(e.map((e) => e.id));
|
|
1130
|
+
}, this.select.onClassChange = (e) => {
|
|
1131
|
+
this.settings.class = e, this.render.updateClassStyles();
|
|
1132
|
+
}, this.select.onDisabledChange = (e) => {
|
|
1133
|
+
e ? this.disable() : this.enable();
|
|
1134
|
+
}, this.select.onOptionsChange = (e) => {
|
|
1135
|
+
this.setData(e || []);
|
|
1136
|
+
}, this.select.onLabelClick = () => {
|
|
1137
|
+
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1138
|
+
};
|
|
1139
|
+
let n = e.data ? e.data : this.select.getData();
|
|
1140
|
+
this.store = new m(this.settings.isMultiple ? "multiple" : "single", n), e.data && this.select.updateOptions(this.store.getData());
|
|
1141
|
+
let r = {
|
|
1142
|
+
open: this.open.bind(this),
|
|
1143
|
+
close: this.close.bind(this),
|
|
1144
|
+
addable: this.events.addable ? this.events.addable : void 0,
|
|
1145
|
+
setSelected: this.setSelected.bind(this),
|
|
1146
|
+
addOption: this.addOption.bind(this),
|
|
1147
|
+
search: this.search.bind(this),
|
|
1148
|
+
beforeChange: this.events.beforeChange,
|
|
1149
|
+
afterChange: this.events.afterChange
|
|
1150
|
+
};
|
|
1151
|
+
this.render = new h(this.settings, this.cssClasses, this.store, r), this.render.renderValues(), this.render.renderOptions(this.store.getData());
|
|
1152
|
+
let i = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
|
|
1153
|
+
if (i) this.render.main.main.setAttribute("aria-label", i);
|
|
1154
|
+
else if (a) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", a);
|
|
1155
|
+
else if (this.selectEl.labels && this.selectEl.labels.length > 0) {
|
|
1156
|
+
let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
|
|
1157
|
+
this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
|
|
1158
|
+
}
|
|
1159
|
+
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;
|
|
1160
|
+
}
|
|
1161
|
+
enable() {
|
|
1162
|
+
this.settings.disabled = !1, this.select.enable(), this.render.enable();
|
|
1163
|
+
}
|
|
1164
|
+
disable() {
|
|
1165
|
+
this.settings.disabled = !0, this.select.disable(), this.render.disable();
|
|
1166
|
+
}
|
|
1167
|
+
getData() {
|
|
1168
|
+
return this.store.getData();
|
|
1169
|
+
}
|
|
1170
|
+
setData(e) {
|
|
1171
|
+
let t = this.store.getSelected(), n = this.store.validateDataArray(e);
|
|
1172
|
+
if (n) {
|
|
1173
|
+
this.events.error && this.events.error(n);
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
this.store.setData(e);
|
|
1177
|
+
let r = this.store.getData();
|
|
1178
|
+
this.select.updateOptions(r), this.render.renderValues(), this.render.renderOptions(r), this.events.afterChange && !u(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1179
|
+
}
|
|
1180
|
+
getSelected() {
|
|
1181
|
+
let e = this.store.getSelectedOptions();
|
|
1182
|
+
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((e) => e.value);
|
|
1183
|
+
}
|
|
1184
|
+
setSelected(e, t = !0) {
|
|
1185
|
+
let n = this.store.getSelected(), r = this.store.getDataOptions();
|
|
1186
|
+
e = Array.isArray(e) ? e : [e];
|
|
1187
|
+
let i = [];
|
|
1188
|
+
for (let t of e) {
|
|
1189
|
+
if (r.find((e) => e.id == t)) {
|
|
1190
|
+
i.push(t);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
for (let e of r.filter((e) => e.value == t)) i.push(e.id);
|
|
1194
|
+
}
|
|
1195
|
+
this.store.setSelectedBy("id", i);
|
|
1196
|
+
let a = this.store.getData();
|
|
1197
|
+
this.select.updateOptions(a), this.render.renderValues(), this.render.content.search.input.value === "" ? this.render.renderOptions(a) : this.search(this.render.content.search.input.value), t && this.events.afterChange && !u(n, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1198
|
+
}
|
|
1199
|
+
addOption(e) {
|
|
1200
|
+
let t = this.store.getSelected();
|
|
1201
|
+
this.store.getDataOptions().some((t) => t.value === (e.value ?? e.text)) || this.store.addOption(e);
|
|
1202
|
+
let n = this.store.getData();
|
|
1203
|
+
this.select.updateOptions(n), this.render.renderValues(), this.render.renderOptions(n), this.events.afterChange && !u(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1204
|
+
}
|
|
1205
|
+
open() {
|
|
1206
|
+
this.settings.disabled || this.settings.isOpen || (this.closeTimeout &&= (clearTimeout(this.closeTimeout), null), this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
|
|
1207
|
+
this.events.afterOpen && this.events.afterOpen(), this.settings.isOpen && (this.settings.isFullOpen = !0), document.addEventListener("click", this.documentClick);
|
|
1208
|
+
}, this.settings.timeoutDelay), this.settings.contentPosition === "absolute" && (this.settings.intervalMove && clearInterval(this.settings.intervalMove), this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500)));
|
|
1209
|
+
}
|
|
1210
|
+
close(e = null) {
|
|
1211
|
+
!this.settings.isOpen || this.settings.alwaysOpen || (this.openTimeout &&= (clearTimeout(this.openTimeout), null), this.events.beforeClose && this.events.beforeClose(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
|
|
1212
|
+
this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
|
|
1213
|
+
}, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
|
|
1214
|
+
}
|
|
1215
|
+
search(e) {
|
|
1216
|
+
if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), e === "") {
|
|
1217
|
+
this.render.renderOptions(this.store.getData());
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
if (!this.events.search) {
|
|
1221
|
+
let t = e === "" ? this.store.getData() : this.store.search(e, this.events.searchFilter);
|
|
1222
|
+
this.render.renderOptions(t);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
this.render.renderSearching();
|
|
1226
|
+
let t = this.events.search(e, this.store.getSelectedOptions());
|
|
1227
|
+
if (t instanceof Promise) {
|
|
1228
|
+
t.then((e) => {
|
|
1229
|
+
this.store.setData(e, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData());
|
|
1230
|
+
}).catch((e) => {
|
|
1231
|
+
this.render.renderError(typeof e == "string" ? e : e.message);
|
|
1232
|
+
});
|
|
1233
|
+
return;
|
|
1234
|
+
} else Array.isArray(t) ? (this.store.setData(t, !0), this.select.updateOptions(this.store.getData()), this.render.renderOptions(this.store.getData())) : this.render.renderError("Search event must return a promise or an array of data");
|
|
1235
|
+
}
|
|
1236
|
+
destroy() {
|
|
1237
|
+
this.openTimeout &&= (clearTimeout(this.openTimeout), null), this.closeTimeout &&= (clearTimeout(this.closeTimeout), null), this.settings.intervalMove && (clearInterval(this.settings.intervalMove), this.settings.intervalMove = null), document.removeEventListener("click", this.documentClick), window.removeEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.removeEventListener("scroll", this.windowScroll, !1), document.removeEventListener("visibilitychange", this.windowVisibilityChange), this.store.setData([]), this.render.destroy(), this.select.destroy();
|
|
1238
|
+
}
|
|
1239
|
+
windowResize = l(() => {
|
|
1240
|
+
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1241
|
+
});
|
|
1242
|
+
windowScroll = l(() => {
|
|
1243
|
+
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1244
|
+
});
|
|
1245
|
+
documentClick = (e) => {
|
|
1246
|
+
this.settings.isOpen && e.target && !c(e.target, this.settings.id) && this.close(e.type);
|
|
1247
|
+
};
|
|
1248
|
+
windowVisibilityChange = () => {
|
|
1249
|
+
document.hidden && this.close();
|
|
1250
|
+
};
|
|
1251
|
+
}, y = /* @__PURE__ */ i(((e) => {
|
|
1252
|
+
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
1253
|
+
function r(e, n, r) {
|
|
1254
|
+
var i = null;
|
|
1255
|
+
if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
|
|
1256
|
+
else r = n;
|
|
1257
|
+
return n = r.ref, {
|
|
1258
|
+
$$typeof: t,
|
|
1259
|
+
type: e,
|
|
1260
|
+
key: i,
|
|
1261
|
+
ref: n === void 0 ? null : n,
|
|
1262
|
+
props: r
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
e.Fragment = n, e.jsx = r, e.jsxs = r;
|
|
1266
|
+
})), b = /* @__PURE__ */ i(((e) => {
|
|
1267
|
+
process.env.NODE_ENV !== "production" && (function() {
|
|
1268
|
+
function t(e) {
|
|
1269
|
+
if (e == null) return null;
|
|
1270
|
+
if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
|
|
1271
|
+
if (typeof e == "string") return e;
|
|
1272
|
+
switch (e) {
|
|
1273
|
+
case v: return "Fragment";
|
|
1274
|
+
case b: return "Profiler";
|
|
1275
|
+
case y: return "StrictMode";
|
|
1276
|
+
case w: return "Suspense";
|
|
1277
|
+
case T: return "SuspenseList";
|
|
1278
|
+
case O: return "Activity";
|
|
1279
|
+
}
|
|
1280
|
+
if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
|
|
1281
|
+
case _: return "Portal";
|
|
1282
|
+
case S: return e.displayName || "Context";
|
|
1283
|
+
case x: return (e._context.displayName || "Context") + ".Consumer";
|
|
1284
|
+
case C:
|
|
1285
|
+
var n = e.render;
|
|
1286
|
+
return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
|
|
1287
|
+
case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
|
|
1288
|
+
case D:
|
|
1289
|
+
n = e._payload, e = e._init;
|
|
1290
|
+
try {
|
|
1291
|
+
return t(e(n));
|
|
1292
|
+
} catch {}
|
|
1293
|
+
}
|
|
1294
|
+
return null;
|
|
1295
|
+
}
|
|
1296
|
+
function n(e) {
|
|
1297
|
+
return "" + e;
|
|
1298
|
+
}
|
|
1299
|
+
function r(e) {
|
|
1300
|
+
try {
|
|
1301
|
+
n(e);
|
|
1302
|
+
var t = !1;
|
|
1303
|
+
} catch {
|
|
1304
|
+
t = !0;
|
|
1305
|
+
}
|
|
1306
|
+
if (t) {
|
|
1307
|
+
t = console;
|
|
1308
|
+
var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
1309
|
+
return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function i(e) {
|
|
1313
|
+
if (e === v) return "<>";
|
|
1314
|
+
if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
|
|
1315
|
+
try {
|
|
1316
|
+
var n = t(e);
|
|
1317
|
+
return n ? "<" + n + ">" : "<...>";
|
|
1318
|
+
} catch {
|
|
1319
|
+
return "<...>";
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
function o() {
|
|
1323
|
+
var e = A.A;
|
|
1324
|
+
return e === null ? null : e.getOwner();
|
|
1325
|
+
}
|
|
1326
|
+
function s() {
|
|
1327
|
+
return Error("react-stack-top-frame");
|
|
1328
|
+
}
|
|
1329
|
+
function c(e) {
|
|
1330
|
+
if (j.call(e, "key")) {
|
|
1331
|
+
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
1332
|
+
if (t && t.isReactWarning) return !1;
|
|
1333
|
+
}
|
|
1334
|
+
return e.key !== void 0;
|
|
1335
|
+
}
|
|
1336
|
+
function l(e, t) {
|
|
1337
|
+
function n() {
|
|
1338
|
+
P || (P = !0, console.error("%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)", t));
|
|
1339
|
+
}
|
|
1340
|
+
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
1341
|
+
get: n,
|
|
1342
|
+
configurable: !0
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
function u() {
|
|
1346
|
+
var e = t(this.type);
|
|
1347
|
+
return F[e] || (F[e] = !0, console.error("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.")), e = this.props.ref, e === void 0 ? null : e;
|
|
1348
|
+
}
|
|
1349
|
+
function d(e, t, n, r, i, a) {
|
|
1350
|
+
var o = n.ref;
|
|
1351
|
+
return e = {
|
|
1352
|
+
$$typeof: g,
|
|
1353
|
+
type: e,
|
|
1354
|
+
key: t,
|
|
1355
|
+
props: n,
|
|
1356
|
+
_owner: r
|
|
1357
|
+
}, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
|
|
1358
|
+
enumerable: !1,
|
|
1359
|
+
value: null
|
|
1360
|
+
}) : Object.defineProperty(e, "ref", {
|
|
1361
|
+
enumerable: !1,
|
|
1362
|
+
get: u
|
|
1363
|
+
}), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
1364
|
+
configurable: !1,
|
|
1365
|
+
enumerable: !1,
|
|
1366
|
+
writable: !0,
|
|
1367
|
+
value: 0
|
|
1368
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
1369
|
+
configurable: !1,
|
|
1370
|
+
enumerable: !1,
|
|
1371
|
+
writable: !0,
|
|
1372
|
+
value: null
|
|
1373
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
1374
|
+
configurable: !1,
|
|
1375
|
+
enumerable: !1,
|
|
1376
|
+
writable: !0,
|
|
1377
|
+
value: i
|
|
1378
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
1379
|
+
configurable: !1,
|
|
1380
|
+
enumerable: !1,
|
|
1381
|
+
writable: !0,
|
|
1382
|
+
value: a
|
|
1383
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
1384
|
+
}
|
|
1385
|
+
function f(e, n, i, a, s, u) {
|
|
1386
|
+
var f = n.children;
|
|
1387
|
+
if (f !== void 0) if (a) if (M(f)) {
|
|
1388
|
+
for (a = 0; a < f.length; a++) p(f[a]);
|
|
1389
|
+
Object.freeze && Object.freeze(f);
|
|
1390
|
+
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
1391
|
+
else p(f);
|
|
1392
|
+
if (j.call(n, "key")) {
|
|
1393
|
+
f = t(e);
|
|
1394
|
+
var m = Object.keys(n).filter(function(e) {
|
|
1395
|
+
return e !== "key";
|
|
1396
|
+
});
|
|
1397
|
+
a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
|
|
1398
|
+
}
|
|
1399
|
+
if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
|
|
1400
|
+
else i = n;
|
|
1401
|
+
return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, o(), s, u);
|
|
1402
|
+
}
|
|
1403
|
+
function p(e) {
|
|
1404
|
+
m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
1405
|
+
}
|
|
1406
|
+
function m(e) {
|
|
1407
|
+
return typeof e == "object" && !!e && e.$$typeof === g;
|
|
1408
|
+
}
|
|
1409
|
+
var h = a("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
|
|
1410
|
+
return null;
|
|
1411
|
+
};
|
|
1412
|
+
h = { react_stack_bottom_frame: function(e) {
|
|
1413
|
+
return e();
|
|
1414
|
+
} };
|
|
1415
|
+
var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
|
|
1416
|
+
e.Fragment = v, e.jsx = function(e, t, n) {
|
|
1417
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
1418
|
+
return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
1419
|
+
}, e.jsxs = function(e, t, n) {
|
|
1420
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
1421
|
+
return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
1422
|
+
};
|
|
1423
|
+
})();
|
|
1424
|
+
})), x = (/* @__PURE__ */ i(((e, t) => {
|
|
1425
|
+
process.env.NODE_ENV === "production" ? t.exports = y() : t.exports = b();
|
|
1426
|
+
})))(), S = e(({ data: e, settings: i, events: a, cssClasses: o, value: s, onChange: c, children: l, multiple: u }, d) => {
|
|
1427
|
+
let f = r(null), p = r(null), m = r(!0), h = r(s);
|
|
1428
|
+
n(d, () => ({ slimSelect: p.current }));
|
|
1429
|
+
let g = (e) => typeof e == "string" ? u ? [e] : e : Array.isArray(e) ? u ? e : e[0] : u ? [] : "", _ = (e, t = !1) => {
|
|
1430
|
+
if (!p.current || e === void 0) return;
|
|
1431
|
+
let n = g(e), r = p.current.getData().flatMap((e) => "label" in e ? e.options : [e]);
|
|
1432
|
+
if (!(Array.isArray(n) ? n.length > 0 && n.every((e) => r.some((t) => t.value === e)) : n !== "" && r.some((e) => e.value === n)) && !Array.isArray(n) && !r.some((e) => e.placeholder)) {
|
|
1433
|
+
let e = p.current.getData();
|
|
1434
|
+
p.current.setData([{
|
|
1435
|
+
value: "",
|
|
1436
|
+
text: "",
|
|
1437
|
+
placeholder: !0
|
|
1438
|
+
}].concat(e));
|
|
1439
|
+
}
|
|
1440
|
+
p.current.setSelected(n, t);
|
|
1441
|
+
};
|
|
1442
|
+
return t(() => {
|
|
1443
|
+
if (!f.current) return;
|
|
1444
|
+
let t = { select: f.current };
|
|
1445
|
+
e && (t.data = e), i && (t.settings = i), o && (t.cssClasses = o);
|
|
1446
|
+
let n = a?.afterChange;
|
|
1447
|
+
return t.events = {
|
|
1448
|
+
...a,
|
|
1449
|
+
afterChange: (e) => {
|
|
1450
|
+
if (!p.current) return;
|
|
1451
|
+
let t = u ? e.map((e) => e.value) : e[0]?.value ?? "", r = p.current.getData().flatMap((e) => "label" in e ? e.options : [e]), i = h.current, a = i === void 0 ? !1 : Array.isArray(i) ? i.length > 0 && i.every((e) => r.some((t) => t.value === e)) : i !== "" && r.some((e) => e.value === i), o = Array.isArray(t) ? t.length > 0 && t.every((e) => r.some((t) => t.value === e)) : t !== "" && r.some((e) => e.value === t), s = Array.isArray(t) && Array.isArray(i) ? JSON.stringify(t.sort()) !== JSON.stringify(i.sort()) : i !== t;
|
|
1452
|
+
c && s && (a || o) && (c(t), h.current = t), n && n(e);
|
|
1453
|
+
}
|
|
1454
|
+
}, p.current = new v(t), s !== void 0 && _(s, !1), () => {
|
|
1455
|
+
p.current &&= (p.current.destroy(), null);
|
|
1456
|
+
};
|
|
1457
|
+
}, []), t(() => {
|
|
1458
|
+
if (m.current) {
|
|
1459
|
+
m.current = !1, h.current = s;
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
p.current && s !== void 0 && (h.current = s, _(s, !1));
|
|
1463
|
+
}, [s]), t(() => {
|
|
1464
|
+
p.current && e && !m.current && (p.current.setData(e), s !== void 0 && _(s, !1));
|
|
1465
|
+
}, [e]), /* @__PURE__ */ (0, x.jsx)("select", {
|
|
1466
|
+
ref: f,
|
|
1467
|
+
multiple: u,
|
|
1468
|
+
children: l
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
1471
|
+
S.displayName = "SlimSelect";
|
|
1472
|
+
//#endregion
|
|
1473
|
+
//#region src/slim-select/react/index.tsx
|
|
1474
|
+
var C = S;
|
|
1475
|
+
//#endregion
|
|
1476
|
+
export { p as Optgroup, f as Option, _ as Settings, C as default };
|