slim-select 3.6.0 → 4.0.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/README.md +167 -147
- package/dist/animations.d.ts +37 -0
- package/dist/classes.d.ts +5 -0
- package/dist/events.d.ts +26 -0
- package/dist/helpers.d.ts +19 -0
- package/dist/index.d.ts +14 -8
- package/dist/lifecycle.d.ts +53 -0
- package/dist/mutations.d.ts +31 -0
- package/dist/react/index.js +1008 -491
- package/dist/react/index.umd.js +1 -6
- package/dist/react/react.d.ts +1 -2
- package/dist/render.d.ts +58 -4
- package/dist/select.d.ts +1 -0
- package/dist/settings.d.ts +4 -1
- package/dist/slimselect.cjs.js +1 -1
- 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 +979 -296
- package/dist/slimselect.es.js.map +1 -1
- package/dist/slimselect.iife.js +1 -1
- package/dist/slimselect.iife.js.map +1 -1
- package/dist/slimselect.js +1 -1
- package/dist/slimselect.js.map +1 -1
- package/dist/src/docs/nav.d.ts +20 -0
- package/dist/store.d.ts +13 -4
- package/dist/sync.d.ts +78 -0
- package/dist/vue/index.js +984 -299
- package/dist/vue/index.umd.js +1 -1
- package/package.json +16 -13
- package/src/slim-select/slimselect.scss +223 -67
package/dist/slimselect.es.js
CHANGED
|
@@ -37,6 +37,11 @@ var e = class {
|
|
|
37
37
|
option;
|
|
38
38
|
optionDelete;
|
|
39
39
|
highlighted;
|
|
40
|
+
modalOverlay;
|
|
41
|
+
modalDialog;
|
|
42
|
+
modalTitle;
|
|
43
|
+
modalClose;
|
|
44
|
+
modalContent;
|
|
40
45
|
mainOpen;
|
|
41
46
|
close;
|
|
42
47
|
selected;
|
|
@@ -46,18 +51,132 @@ var e = class {
|
|
|
46
51
|
constructor(e) {
|
|
47
52
|
e ||= {};
|
|
48
53
|
let t = (e = "", t = "") => `${e} ${t}`.trim();
|
|
49
|
-
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
|
+
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.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), 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);
|
|
50
55
|
}
|
|
51
56
|
getFirst(e) {
|
|
52
57
|
return this[e].split(" ")[0];
|
|
53
58
|
}
|
|
59
|
+
}, t = 200, n = ["transform", "opacity"];
|
|
60
|
+
function r(e, n = t) {
|
|
61
|
+
let r = e.trim();
|
|
62
|
+
if (!r) return n;
|
|
63
|
+
if (r.endsWith("ms")) {
|
|
64
|
+
let e = parseFloat(r);
|
|
65
|
+
return Number.isNaN(e) ? n : e;
|
|
66
|
+
}
|
|
67
|
+
if (r.endsWith("s")) {
|
|
68
|
+
let e = parseFloat(r);
|
|
69
|
+
return Number.isNaN(e) ? n : e * 1e3;
|
|
70
|
+
}
|
|
71
|
+
let i = parseFloat(r);
|
|
72
|
+
return Number.isNaN(i) ? n : i;
|
|
73
|
+
}
|
|
74
|
+
function i(e, n = t) {
|
|
75
|
+
return r(getComputedStyle(e).getPropertyValue("--ss-animation-timing").trim(), n);
|
|
76
|
+
}
|
|
77
|
+
function a(e, n, r = t) {
|
|
78
|
+
let a = i(e, r) + 50;
|
|
79
|
+
return n === void 0 ? a : Math.max(a, n);
|
|
80
|
+
}
|
|
81
|
+
function o() {
|
|
82
|
+
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
83
|
+
}
|
|
84
|
+
function s(e) {
|
|
85
|
+
return e === void 0 ? null : new Set(Array.isArray(e) ? e : [e]);
|
|
86
|
+
}
|
|
87
|
+
function c(e, n, r = t, i) {
|
|
88
|
+
if (o() || i?.aborted) return Promise.resolve();
|
|
89
|
+
let a = s(n);
|
|
90
|
+
return new Promise((t) => {
|
|
91
|
+
let n = null, o = !1, s = () => {
|
|
92
|
+
o || (o = !0, e.removeEventListener("transitionend", l), i?.removeEventListener("abort", c), n && clearTimeout(n), t());
|
|
93
|
+
}, c = () => s(), l = (t) => {
|
|
94
|
+
t.target === e && (a && (!a.has(t.propertyName) || (a.delete(t.propertyName), a.size > 0)) || s());
|
|
95
|
+
};
|
|
96
|
+
i?.addEventListener("abort", c, { once: !0 }), e.addEventListener("transitionend", l), n = setTimeout(s, r);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function l(e, n, r = t, i) {
|
|
100
|
+
return o() || i?.aborted ? Promise.resolve() : new Promise((t) => {
|
|
101
|
+
let a = null, o = !1, s = () => {
|
|
102
|
+
o || (o = !0, e.removeEventListener("animationend", l), i?.removeEventListener("abort", c), a && clearTimeout(a), t());
|
|
103
|
+
}, c = () => s(), l = (t) => {
|
|
104
|
+
t.target === e && (n && t.animationName !== n || s());
|
|
105
|
+
};
|
|
106
|
+
i?.addEventListener("abort", c, { once: !0 }), e.addEventListener("animationend", l), a = setTimeout(s, r);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/slim-select/settings.ts
|
|
111
|
+
var u = 768, d = class {
|
|
112
|
+
id = "";
|
|
113
|
+
style = "";
|
|
114
|
+
class = [];
|
|
115
|
+
isMultiple = !1;
|
|
116
|
+
isOpen = !1;
|
|
117
|
+
isFullOpen = !1;
|
|
118
|
+
disabled;
|
|
119
|
+
alwaysOpen;
|
|
120
|
+
showSearch;
|
|
121
|
+
focusSearch;
|
|
122
|
+
keepSearch;
|
|
123
|
+
ariaLabel;
|
|
124
|
+
searchPlaceholder;
|
|
125
|
+
searchText;
|
|
126
|
+
searchingText;
|
|
127
|
+
resultsText;
|
|
128
|
+
deselectText;
|
|
129
|
+
removeText;
|
|
130
|
+
searchHighlight;
|
|
131
|
+
closeOnSelect;
|
|
132
|
+
contentLocation;
|
|
133
|
+
contentPosition;
|
|
134
|
+
contentWidth;
|
|
135
|
+
openPosition;
|
|
136
|
+
placeholderText;
|
|
137
|
+
allowDeselect;
|
|
138
|
+
hideSelected;
|
|
139
|
+
multiString;
|
|
140
|
+
keepOrder;
|
|
141
|
+
showOptionTooltips;
|
|
142
|
+
minSelected;
|
|
143
|
+
maxSelected;
|
|
144
|
+
timeoutDelay;
|
|
145
|
+
maxValuesShown;
|
|
146
|
+
maxValuesMessage;
|
|
147
|
+
addableText;
|
|
148
|
+
modal;
|
|
149
|
+
modalTitle;
|
|
150
|
+
constructor(e) {
|
|
151
|
+
e ||= {}, this.id = "ss-" + h(), 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}", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
|
|
152
|
+
}
|
|
54
153
|
};
|
|
55
154
|
//#endregion
|
|
56
155
|
//#region src/slim-select/helpers.ts
|
|
57
|
-
function
|
|
156
|
+
function f(e) {
|
|
157
|
+
if (!e) return {};
|
|
158
|
+
let t = {};
|
|
159
|
+
for (let n of Object.keys(e)) {
|
|
160
|
+
let r = e[n];
|
|
161
|
+
r !== void 0 && (t[n] = r);
|
|
162
|
+
}
|
|
163
|
+
return t;
|
|
164
|
+
}
|
|
165
|
+
function p(e) {
|
|
166
|
+
let t = e.cloneNode(!0);
|
|
167
|
+
return t.querySelectorAll("select, option, optgroup, textarea, input, button").forEach((e) => e.remove()), t.textContent?.replace(/\s+/g, " ").trim() || "";
|
|
168
|
+
}
|
|
169
|
+
function m(e) {
|
|
170
|
+
if (e.labels && e.labels.length > 0) {
|
|
171
|
+
let t = Array.from(e.labels).map(p).filter(Boolean);
|
|
172
|
+
if (t.length > 0) return [...new Set(t)].join(" ");
|
|
173
|
+
}
|
|
174
|
+
return e.getAttribute("aria-label")?.trim() || "";
|
|
175
|
+
}
|
|
176
|
+
function h() {
|
|
58
177
|
return Math.random().toString(36).substring(2, 10);
|
|
59
178
|
}
|
|
60
|
-
function
|
|
179
|
+
function g(e, t) {
|
|
61
180
|
function n(e, n) {
|
|
62
181
|
return n && e && e.classList && e.classList.contains(n) || n && e && e.dataset && e.dataset.id && e.dataset.id === t ? e : null;
|
|
63
182
|
}
|
|
@@ -66,7 +185,7 @@ function n(e, t) {
|
|
|
66
185
|
}
|
|
67
186
|
return n(e, t) || r(e, t);
|
|
68
187
|
}
|
|
69
|
-
function
|
|
188
|
+
function _(e, t = 50, n = !1) {
|
|
70
189
|
let r;
|
|
71
190
|
return function(...i) {
|
|
72
191
|
let a = self, o = () => {
|
|
@@ -75,16 +194,180 @@ function r(e, t = 50, n = !1) {
|
|
|
75
194
|
clearTimeout(r), r = setTimeout(o, t), s && e.apply(a, i);
|
|
76
195
|
};
|
|
77
196
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
197
|
+
function v(e, t) {
|
|
198
|
+
if (e.length !== t.length) return !1;
|
|
199
|
+
let n = [...e].sort(), r = [...t].sort();
|
|
200
|
+
return n.every((e, t) => e === r[t]);
|
|
201
|
+
}
|
|
202
|
+
var y = [
|
|
203
|
+
"id",
|
|
204
|
+
"value",
|
|
205
|
+
"text",
|
|
206
|
+
"html",
|
|
207
|
+
"defaultSelected",
|
|
208
|
+
"selected",
|
|
209
|
+
"display",
|
|
210
|
+
"disabled",
|
|
211
|
+
"placeholder",
|
|
212
|
+
"class",
|
|
213
|
+
"style",
|
|
214
|
+
"mandatory"
|
|
215
|
+
];
|
|
216
|
+
function b(e, t) {
|
|
217
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
218
|
+
if (n.length !== r.length) return !1;
|
|
219
|
+
for (let r of n) if (e[r] !== t[r]) return !1;
|
|
220
|
+
return !0;
|
|
80
221
|
}
|
|
81
|
-
function
|
|
222
|
+
function x(e, t) {
|
|
223
|
+
switch (t) {
|
|
224
|
+
case "id": return e.id || "";
|
|
225
|
+
case "value": return e.value === void 0 ? e.text || "" : e.value || "";
|
|
226
|
+
case "text": return e.text || "";
|
|
227
|
+
case "html": return e.html || "";
|
|
228
|
+
case "defaultSelected": return e.defaultSelected ?? !1;
|
|
229
|
+
case "selected": return e.selected ?? !1;
|
|
230
|
+
case "display": return e.display ?? !0;
|
|
231
|
+
case "disabled": return e.disabled ?? !1;
|
|
232
|
+
case "placeholder": return e.placeholder ?? !1;
|
|
233
|
+
case "class": return e.class || "";
|
|
234
|
+
case "style": return e.style || "";
|
|
235
|
+
case "mandatory": return e.mandatory ?? !1;
|
|
236
|
+
default: return e.data || {};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function S(e) {
|
|
240
|
+
return !!e && typeof e == "object" && "label" in e && "options" in e;
|
|
241
|
+
}
|
|
242
|
+
function C(e, t) {
|
|
243
|
+
for (let n of y) if (x(e, n) !== x(t, n)) return !1;
|
|
244
|
+
return b(e.data || {}, t.data || {});
|
|
245
|
+
}
|
|
246
|
+
function w(e, t) {
|
|
247
|
+
let n = (e) => ({
|
|
248
|
+
id: e.id || "",
|
|
249
|
+
label: e.label || "",
|
|
250
|
+
selectAll: e.selectAll ?? !1,
|
|
251
|
+
closable: e.closable || "off"
|
|
252
|
+
}), r = n(e), i = n(t);
|
|
253
|
+
if (r.id !== i.id || r.label !== i.label || r.selectAll !== i.selectAll || r.closable !== i.closable) return !1;
|
|
254
|
+
let a = e.options || [], o = t.options || [];
|
|
255
|
+
if (a.length !== o.length) return !1;
|
|
256
|
+
for (let e = 0; e < a.length; e++) if (!C(a[e], o[e])) return !1;
|
|
257
|
+
return !0;
|
|
258
|
+
}
|
|
259
|
+
function T(e, t) {
|
|
260
|
+
if (e === t) return !0;
|
|
261
|
+
if (e.length !== t.length) return !1;
|
|
262
|
+
for (let n = 0; n < e.length; n++) {
|
|
263
|
+
let r = e[n], i = t[n], a = S(r);
|
|
264
|
+
if (a !== S(i)) return !1;
|
|
265
|
+
if (a) {
|
|
266
|
+
if (!w(r, i)) return !1;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (!C(r, i)) return !1;
|
|
270
|
+
}
|
|
271
|
+
return !0;
|
|
272
|
+
}
|
|
273
|
+
function E(e) {
|
|
82
274
|
let t = e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (e) => "-" + e.toLowerCase());
|
|
83
275
|
return e[0] === e[0].toUpperCase() ? t.substring(1) : t;
|
|
84
276
|
}
|
|
277
|
+
function D(e, t = typeof window < "u" ? window.innerWidth : 768) {
|
|
278
|
+
return e === "on" ? !0 : e === "mobile" ? t < 768 : !1;
|
|
279
|
+
}
|
|
85
280
|
//#endregion
|
|
86
|
-
//#region src/slim-select/
|
|
87
|
-
var
|
|
281
|
+
//#region src/slim-select/events.ts
|
|
282
|
+
var O = class {
|
|
283
|
+
handlers;
|
|
284
|
+
attached = !1;
|
|
285
|
+
constructor(e) {
|
|
286
|
+
this.handlers = e;
|
|
287
|
+
}
|
|
288
|
+
attach(e) {
|
|
289
|
+
this.attached || (this.attached = !0, window.addEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.addEventListener("scroll", this.scrollHandler, !1), document.addEventListener("visibilitychange", this.visibilityHandler));
|
|
290
|
+
}
|
|
291
|
+
attachDocumentClick() {
|
|
292
|
+
document.addEventListener("click", this.handlers.onDocumentClick);
|
|
293
|
+
}
|
|
294
|
+
detachDocumentClick() {
|
|
295
|
+
document.removeEventListener("click", this.handlers.onDocumentClick);
|
|
296
|
+
}
|
|
297
|
+
detach(e) {
|
|
298
|
+
this.attached && (this.attached = !1, this.detachDocumentClick(), window.removeEventListener("resize", this.resizeHandler, !1), e.listenScroll && window.removeEventListener("scroll", this.scrollHandler, !1), document.removeEventListener("visibilitychange", this.visibilityHandler));
|
|
299
|
+
}
|
|
300
|
+
resizeHandler = _(() => {
|
|
301
|
+
this.handlers.onWindowResize();
|
|
302
|
+
});
|
|
303
|
+
scrollHandler = _(() => {
|
|
304
|
+
this.handlers.onWindowScroll();
|
|
305
|
+
});
|
|
306
|
+
visibilityHandler = () => {
|
|
307
|
+
this.handlers.onVisibilityChange();
|
|
308
|
+
};
|
|
309
|
+
}, k = class {
|
|
310
|
+
handlers;
|
|
311
|
+
options;
|
|
312
|
+
state = "closed";
|
|
313
|
+
pendingTimer = null;
|
|
314
|
+
waitResolvers = [];
|
|
315
|
+
generation = 0;
|
|
316
|
+
animationAbort = null;
|
|
317
|
+
constructor(e, t) {
|
|
318
|
+
this.handlers = e, this.options = t;
|
|
319
|
+
}
|
|
320
|
+
get isOpen() {
|
|
321
|
+
return this.state === "opening" || this.state === "open";
|
|
322
|
+
}
|
|
323
|
+
get isFullOpen() {
|
|
324
|
+
return this.state === "open";
|
|
325
|
+
}
|
|
326
|
+
async requestOpen() {
|
|
327
|
+
if (this.state === "opening" || this.state === "open") return;
|
|
328
|
+
this.cancelPending();
|
|
329
|
+
let e = ++this.generation;
|
|
330
|
+
if (this.handlers.beforeOpen && this.handlers.beforeOpen(), this.state = "opening", await this.waitForPhase("open", e), e !== this.generation) {
|
|
331
|
+
this.state === "opening" && (this.state = "closed");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
this.state = "open", this.handlers.afterOpen && this.handlers.afterOpen(), this.handlers.onOpenReady && this.handlers.onOpenReady();
|
|
335
|
+
}
|
|
336
|
+
async requestClose() {
|
|
337
|
+
if (this.state === "closed" || this.state === "closing") return;
|
|
338
|
+
this.cancelPending();
|
|
339
|
+
let e = ++this.generation;
|
|
340
|
+
this.handlers.beforeClose && this.handlers.beforeClose(), this.state = "closing", await this.waitForPhase("close", e), e === this.generation && (this.state = "closed", this.handlers.afterClose && this.handlers.afterClose(), this.handlers.onCloseReady && this.handlers.onCloseReady());
|
|
341
|
+
}
|
|
342
|
+
cancelPending() {
|
|
343
|
+
this.generation++, this.animationAbort?.abort(), this.animationAbort = null, this.pendingTimer &&= (clearTimeout(this.pendingTimer), null);
|
|
344
|
+
let e = this.waitResolvers.splice(0);
|
|
345
|
+
for (let t of e) t();
|
|
346
|
+
}
|
|
347
|
+
destroy() {
|
|
348
|
+
this.cancelPending(), this.state = "closed";
|
|
349
|
+
}
|
|
350
|
+
waitForPhase(e, t) {
|
|
351
|
+
return new Promise((t) => {
|
|
352
|
+
let n = !1, r = () => {
|
|
353
|
+
if (n) return;
|
|
354
|
+
n = !0;
|
|
355
|
+
let e = this.waitResolvers.indexOf(r);
|
|
356
|
+
e !== -1 && this.waitResolvers.splice(e, 1), t();
|
|
357
|
+
};
|
|
358
|
+
if (this.waitResolvers.push(r), this.options.waitForAnimation) {
|
|
359
|
+
let t = new AbortController();
|
|
360
|
+
this.animationAbort = t, this.options.waitForAnimation(e, t.signal).catch(() => void 0).finally(() => {
|
|
361
|
+
this.animationAbort === t && (this.animationAbort = null), r();
|
|
362
|
+
});
|
|
363
|
+
} else this.pendingTimer = setTimeout(() => {
|
|
364
|
+
this.pendingTimer = null, r();
|
|
365
|
+
}, this.options.timeoutDelay);
|
|
366
|
+
}).then(() => {
|
|
367
|
+
this.generation;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}, A = class {
|
|
88
371
|
id;
|
|
89
372
|
value;
|
|
90
373
|
text;
|
|
@@ -99,34 +382,34 @@ var o = class {
|
|
|
99
382
|
data;
|
|
100
383
|
mandatory;
|
|
101
384
|
constructor(e) {
|
|
102
|
-
this.id = !e.id || e.id === "" ?
|
|
385
|
+
this.id = !e.id || e.id === "" ? h() : 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 = f(e.data);
|
|
103
386
|
}
|
|
104
|
-
},
|
|
387
|
+
}, j = class {
|
|
105
388
|
id;
|
|
106
389
|
label;
|
|
107
390
|
selectAll;
|
|
108
|
-
selectAllText;
|
|
109
391
|
closable;
|
|
110
392
|
options;
|
|
111
393
|
constructor(e) {
|
|
112
|
-
if (this.id = !e.id || e.id === "" ?
|
|
394
|
+
if (this.id = !e.id || e.id === "" ? h() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.closable = e.closable || "off", this.options = [], e.options) for (let t of e.options) this.options.push(new A(t));
|
|
113
395
|
}
|
|
114
|
-
},
|
|
396
|
+
}, M = class {
|
|
115
397
|
selectType = "single";
|
|
116
398
|
data = [];
|
|
117
399
|
selectedOrder = [];
|
|
400
|
+
catalog = null;
|
|
118
401
|
constructor(e, t) {
|
|
119
|
-
this.selectType = e, this.setData(t);
|
|
402
|
+
this.selectType = e, this.setData(t), this.snapshotCatalog();
|
|
120
403
|
}
|
|
121
404
|
validateDataArray(e) {
|
|
122
405
|
if (!Array.isArray(e)) return /* @__PURE__ */ Error("Data must be an array");
|
|
123
|
-
for (let t of e) if (t) if (t instanceof
|
|
406
|
+
for (let t of e) if (t) if (t instanceof j || "label" in t) {
|
|
124
407
|
if (!("label" in t)) return /* @__PURE__ */ Error("Optgroup must have a label");
|
|
125
408
|
if ("options" in t && t.options) for (let e of t.options) {
|
|
126
409
|
let t = this.validateOption(e);
|
|
127
410
|
if (t) return t;
|
|
128
411
|
}
|
|
129
|
-
} else if (t instanceof
|
|
412
|
+
} else if (t instanceof A || "text" in t) {
|
|
130
413
|
let e = this.validateOption(t);
|
|
131
414
|
if (e) return e;
|
|
132
415
|
} else return /* @__PURE__ */ Error("Data object must be a valid optgroup or option");
|
|
@@ -139,68 +422,85 @@ var o = class {
|
|
|
139
422
|
let t = [];
|
|
140
423
|
return e.forEach((e) => {
|
|
141
424
|
if (e) {
|
|
142
|
-
if (e instanceof
|
|
425
|
+
if (e instanceof j || "label" in e) {
|
|
143
426
|
let n = [];
|
|
144
427
|
"options" in e && e.options && e.options.forEach((e) => {
|
|
145
|
-
n.push(new
|
|
146
|
-
}), n.length > 0 && t.push(new
|
|
428
|
+
n.push(new A(e));
|
|
429
|
+
}), n.length > 0 && t.push(new j(e));
|
|
147
430
|
}
|
|
148
|
-
(e instanceof
|
|
431
|
+
(e instanceof A || "text" in e) && t.push(new A(e));
|
|
149
432
|
}
|
|
150
433
|
}), t;
|
|
151
434
|
}
|
|
435
|
+
snapshotCatalog() {
|
|
436
|
+
this.catalog = this.cloneData(this.data);
|
|
437
|
+
}
|
|
438
|
+
getCatalogData() {
|
|
439
|
+
return this.cloneData(this.catalog ?? this.data);
|
|
440
|
+
}
|
|
441
|
+
cloneData(e) {
|
|
442
|
+
return e.map((e) => e instanceof j ? new j({
|
|
443
|
+
id: e.id,
|
|
444
|
+
label: e.label,
|
|
445
|
+
selectAll: e.selectAll,
|
|
446
|
+
closable: e.closable,
|
|
447
|
+
options: e.options.map((e) => new A(e instanceof A ? { ...e } : e))
|
|
448
|
+
}) : new A({ ...e }));
|
|
449
|
+
}
|
|
450
|
+
optionMatchesSelected(e, t) {
|
|
451
|
+
return e.id === t.id ? !0 : t.value !== "" && e.value !== "" && e.value === t.value;
|
|
452
|
+
}
|
|
453
|
+
findOptionInData(e, t) {
|
|
454
|
+
for (let n of e) {
|
|
455
|
+
if (n instanceof A) {
|
|
456
|
+
if (this.optionMatchesSelected(n, t)) return n;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
for (let e of n.options) if (this.optionMatchesSelected(e, t)) return e;
|
|
460
|
+
}
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
152
463
|
setData(e, t = !1) {
|
|
153
464
|
let n = this.partialToFullData(e), r = [];
|
|
154
465
|
if (t) {
|
|
155
466
|
r = this.getSelectedOptions();
|
|
156
467
|
let e = [];
|
|
157
468
|
r.forEach((t) => {
|
|
158
|
-
|
|
159
|
-
for (let e of n) {
|
|
160
|
-
if (e instanceof o && e.id === t.id) {
|
|
161
|
-
r = !0;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
if (e instanceof s) {
|
|
165
|
-
for (let n of e.options) if (n.id === t.id) {
|
|
166
|
-
r = !0;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
r || e.push(t);
|
|
469
|
+
this.findOptionInData(n, t) || e.push(t);
|
|
172
470
|
}), this.data = [...e, ...n];
|
|
471
|
+
let t = this.selectType === "single" && r.length === 0, i = r.map((e) => {
|
|
472
|
+
let t = this.findOptionInData(this.data, e);
|
|
473
|
+
return t ? t.id : e.id;
|
|
474
|
+
});
|
|
475
|
+
this.setSelectedBy("id", i, t);
|
|
173
476
|
} else this.data = n;
|
|
174
|
-
|
|
175
|
-
let e = t && r.length === 0;
|
|
176
|
-
this.setSelectedBy("id", this.getSelected(), e);
|
|
177
|
-
}
|
|
477
|
+
!t && this.selectType === "single" && this.setSelectedBy("id", this.getSelected(), !1);
|
|
178
478
|
}
|
|
179
|
-
getData() {
|
|
180
|
-
return this.filter(null, !0);
|
|
479
|
+
getData(e = !0) {
|
|
480
|
+
return this.filter(null, !0, e);
|
|
181
481
|
}
|
|
182
|
-
getDataOptions() {
|
|
183
|
-
return this.filter(null, !1);
|
|
482
|
+
getDataOptions(e = !0) {
|
|
483
|
+
return this.filter(null, !1, e);
|
|
184
484
|
}
|
|
185
485
|
addOption(e, t = !1) {
|
|
186
486
|
if (t) {
|
|
187
|
-
let t = [new
|
|
487
|
+
let t = [new A(e)];
|
|
188
488
|
this.setData(t.concat(this.getData()));
|
|
189
|
-
} else this.setData(this.getData().concat(new
|
|
489
|
+
} else this.setData(this.getData().concat(new A(e)));
|
|
190
490
|
}
|
|
191
491
|
setSelectedBy(e, t, n = !1) {
|
|
192
492
|
let r = null, i = !1, a = [];
|
|
193
493
|
for (let n of this.data) {
|
|
194
|
-
if (n instanceof
|
|
494
|
+
if (n instanceof j) for (let o of n.options) {
|
|
195
495
|
r ||= o;
|
|
196
496
|
let n = o[e] || "";
|
|
197
497
|
o.selected = i ? !1 : t.includes(n), o.selected && (a.push(o), this.selectType === "single" && (i = !0));
|
|
198
498
|
}
|
|
199
|
-
n instanceof
|
|
499
|
+
n instanceof A && (r ||= n, n.selected = i ? !1 : t.includes(n[e]), n.selected && (a.push(n), this.selectType === "single" && (i = !0)));
|
|
200
500
|
}
|
|
201
501
|
this.selectType === "single" && r && !i && !n && (r.selected = !0, a.push(r));
|
|
202
|
-
let
|
|
203
|
-
this.selectedOrder =
|
|
502
|
+
let o = t.map((t) => a.find((n) => n[e] === t)?.id || "");
|
|
503
|
+
this.selectedOrder = o;
|
|
204
504
|
}
|
|
205
505
|
getSelected() {
|
|
206
506
|
return this.getSelectedOptions().map((e) => e.id);
|
|
@@ -209,41 +509,56 @@ var o = class {
|
|
|
209
509
|
return this.getSelectedOptions().map((e) => e.value);
|
|
210
510
|
}
|
|
211
511
|
getSelectedOptions() {
|
|
212
|
-
|
|
512
|
+
let e = [];
|
|
513
|
+
for (let t of this.data) if (t instanceof j) for (let n of t.options) n.selected && e.push(n);
|
|
514
|
+
else t.selected && e.push(t);
|
|
515
|
+
return e;
|
|
213
516
|
}
|
|
214
517
|
getOptgroupByID(e) {
|
|
215
|
-
for (let t of this.data) if (t instanceof
|
|
518
|
+
for (let t of this.data) if (t instanceof j && t.id === e) return t;
|
|
216
519
|
return null;
|
|
217
520
|
}
|
|
218
521
|
getOptionByID(e) {
|
|
219
|
-
let t
|
|
220
|
-
|
|
522
|
+
for (let t of this.data) if (t instanceof j) {
|
|
523
|
+
for (let n of t.options) if (n.id === e) return n;
|
|
524
|
+
} else if (t.id === e) return t;
|
|
525
|
+
return null;
|
|
221
526
|
}
|
|
222
527
|
getSelectType() {
|
|
223
528
|
return this.selectType;
|
|
224
529
|
}
|
|
225
530
|
getFirstOption() {
|
|
226
531
|
let e = null;
|
|
227
|
-
for (let t of this.data) if (t instanceof
|
|
532
|
+
for (let t of this.data) if (t instanceof j ? e = t.options[0] : t instanceof A && (e = t), e) break;
|
|
228
533
|
return e;
|
|
229
534
|
}
|
|
230
535
|
search(e, t) {
|
|
231
|
-
return e = e.trim(), e === "" ? this.getData() : this.filter((n) => t(n, e), !0);
|
|
536
|
+
return e = e.trim(), e === "" ? this.getData(!1) : this.filter((n) => t(n, e), !0, !1);
|
|
232
537
|
}
|
|
233
|
-
|
|
234
|
-
let n =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
538
|
+
createOptgroupView(e, t) {
|
|
539
|
+
let n = new j({
|
|
540
|
+
id: e.id,
|
|
541
|
+
label: e.label,
|
|
542
|
+
selectAll: e.selectAll,
|
|
543
|
+
closable: e.closable,
|
|
544
|
+
options: []
|
|
545
|
+
});
|
|
546
|
+
return n.options = t, n;
|
|
547
|
+
}
|
|
548
|
+
filter(e, t, n = !0) {
|
|
549
|
+
let r = [];
|
|
550
|
+
return this.data.forEach((i) => {
|
|
551
|
+
if (i instanceof j) {
|
|
552
|
+
let a = [];
|
|
553
|
+
if (i.options.forEach((i) => {
|
|
554
|
+
(!e || e(i)) && (t ? a.push(n ? new A(i) : i) : r.push(n ? new A(i) : i));
|
|
555
|
+
}), a.length > 0) if (n) {
|
|
556
|
+
let e = new j(i);
|
|
557
|
+
e.options = a, r.push(e);
|
|
558
|
+
} else r.push(this.createOptgroupView(i, a));
|
|
244
559
|
}
|
|
245
|
-
|
|
246
|
-
}),
|
|
560
|
+
i instanceof A && (!e || e(i)) && r.push(n ? new A(i) : i);
|
|
561
|
+
}), r;
|
|
247
562
|
}
|
|
248
563
|
selectedOrderOptions(e) {
|
|
249
564
|
let t = [];
|
|
@@ -260,18 +575,25 @@ var o = class {
|
|
|
260
575
|
}), n || t.push(e);
|
|
261
576
|
}), t;
|
|
262
577
|
}
|
|
263
|
-
},
|
|
578
|
+
}, N = class {
|
|
264
579
|
settings;
|
|
265
580
|
store;
|
|
266
581
|
callbacks;
|
|
267
582
|
lastSelectedOption;
|
|
268
583
|
lastRenderedOptions;
|
|
269
|
-
|
|
584
|
+
optionsListIsFullData = !1;
|
|
585
|
+
lastSearchFilterTerm = "";
|
|
270
586
|
main;
|
|
271
587
|
content;
|
|
272
588
|
classes;
|
|
589
|
+
positionObserver = null;
|
|
590
|
+
positionObserverRaf = 0;
|
|
591
|
+
modalElements = null;
|
|
592
|
+
modalSessionActive = null;
|
|
593
|
+
bodyScrollLocked = !1;
|
|
594
|
+
savedBodyOverflow = "";
|
|
273
595
|
constructor(e, t, n, r) {
|
|
274
|
-
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);
|
|
596
|
+
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), this.settings.modal !== "off" && !this.settings.alwaysOpen && (this.modalElements = this.createModalElements(), document.body.appendChild(this.modalElements.overlay));
|
|
275
597
|
}
|
|
276
598
|
addClasses(e, t) {
|
|
277
599
|
if (!t || t.trim() === "") return;
|
|
@@ -290,29 +612,76 @@ var o = class {
|
|
|
290
612
|
this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
|
|
291
613
|
}
|
|
292
614
|
open() {
|
|
293
|
-
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true")
|
|
294
|
-
let e = this.
|
|
295
|
-
|
|
615
|
+
this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
|
|
616
|
+
let e = this.resolveModalView();
|
|
617
|
+
if (!e) {
|
|
618
|
+
let e = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
|
|
619
|
+
this.addClasses(this.main.main, e), this.addClasses(this.content.main, e);
|
|
620
|
+
}
|
|
621
|
+
this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), e ? this.showModal() : this.moveContent();
|
|
296
622
|
let t = this.store.getSelectedOptions();
|
|
297
623
|
if (t.length) {
|
|
298
624
|
let e = t[t.length - 1].id, n = this.content.list.querySelector("[data-id=\"" + e + "\"]");
|
|
299
625
|
n && this.ensureElementInView(this.content.list, n);
|
|
300
626
|
}
|
|
301
627
|
}
|
|
628
|
+
isModalViewActive() {
|
|
629
|
+
return this.modalSessionActive === !0;
|
|
630
|
+
}
|
|
631
|
+
resolveModalView() {
|
|
632
|
+
return this.settings.alwaysOpen || this.settings.modal === "off" || !this.modalElements ? !1 : (this.modalSessionActive === null && (this.modalSessionActive = D(this.settings.modal)), this.modalSessionActive);
|
|
633
|
+
}
|
|
634
|
+
createModalElements() {
|
|
635
|
+
let e = document.createElement("div");
|
|
636
|
+
this.addClasses(e, this.classes.modalOverlay), this.addClasses(e, this.classes.hide), e.dataset.id = this.settings.id;
|
|
637
|
+
let t = document.createElement("div");
|
|
638
|
+
this.addClasses(t, this.classes.modalDialog), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "true");
|
|
639
|
+
let n = null;
|
|
640
|
+
this.settings.modalTitle ? (n = document.createElement("div"), this.addClasses(n, this.classes.modalTitle), n.id = `${this.settings.id}-modal-title`, n.textContent = this.settings.modalTitle, t.setAttribute("aria-labelledby", n.id)) : t.setAttribute("aria-label", this.settings.ariaLabel);
|
|
641
|
+
let r = document.createElement("button");
|
|
642
|
+
r.type = "button", this.addClasses(r, this.classes.modalClose), r.setAttribute("aria-label", "Close"), r.onclick = (e) => {
|
|
643
|
+
e.stopPropagation(), this.callbacks.close();
|
|
644
|
+
};
|
|
645
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
646
|
+
i.setAttribute("viewBox", "0 0 100 100");
|
|
647
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
648
|
+
return a.setAttribute("d", this.classes.deselectPath), i.appendChild(a), r.appendChild(i), e.onclick = (t) => {
|
|
649
|
+
t.target === e && this.callbacks.close();
|
|
650
|
+
}, n && t.appendChild(n), e.appendChild(t), {
|
|
651
|
+
overlay: e,
|
|
652
|
+
dialog: t,
|
|
653
|
+
closeButton: r,
|
|
654
|
+
title: n
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
showModal() {
|
|
658
|
+
this.modalElements && (this.modalElements.dialog.appendChild(this.content.main), this.addClasses(this.content.main, this.classes.modalContent), this.content.main.appendChild(this.modalElements.closeButton), this.content.main.style.top = "", this.content.main.style.left = "", this.content.main.style.margin = "", this.content.main.style.width = "", this.removeClasses(this.modalElements.overlay, this.classes.hide), requestAnimationFrame(() => {
|
|
659
|
+
this.modalElements && this.addClasses(this.modalElements.overlay, this.classes.contentOpen);
|
|
660
|
+
}), this.lockBodyScroll());
|
|
661
|
+
}
|
|
662
|
+
lockBodyScroll() {
|
|
663
|
+
this.bodyScrollLocked ||= (this.savedBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
|
|
664
|
+
}
|
|
665
|
+
unlockBodyScroll() {
|
|
666
|
+
this.bodyScrollLocked && (document.body.style.overflow = this.savedBodyOverflow, this.bodyScrollLocked = !1, this.savedBodyOverflow = "");
|
|
667
|
+
}
|
|
668
|
+
restoreContentOffscreen() {
|
|
669
|
+
this.settings.contentLocation && this.settings.contentLocation.appendChild(this.content.main), 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");
|
|
670
|
+
}
|
|
671
|
+
finalizeModalClose() {
|
|
672
|
+
this.modalElements && this.content.main.parentElement === this.modalElements.dialog && (this.addClasses(this.modalElements.overlay, this.classes.hide), this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.removeClasses(this.content.main, this.classes.modalContent), this.restoreContentOffscreen(), this.unlockBodyScroll());
|
|
673
|
+
}
|
|
674
|
+
waitForAnimation(e, t) {
|
|
675
|
+
let r = a(this.content.main, this.settings.timeoutDelay);
|
|
676
|
+
return c(this.content.main, n, r, t);
|
|
677
|
+
}
|
|
302
678
|
close() {
|
|
303
|
-
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose)
|
|
304
|
-
let e = this.
|
|
305
|
-
this.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
getAnimationTiming() {
|
|
310
|
-
let e = getComputedStyle(this.content.main).getPropertyValue("--ss-animation-timing").trim();
|
|
311
|
-
if (e) {
|
|
312
|
-
if (e.endsWith("ms")) return parseFloat(e);
|
|
313
|
-
if (e.endsWith("s")) return parseFloat(e) * 1e3;
|
|
314
|
-
}
|
|
315
|
-
return 200;
|
|
679
|
+
this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose);
|
|
680
|
+
let e = this.modalSessionActive === !0;
|
|
681
|
+
this.removeClasses(this.content.main, this.classes.contentOpen), e || (this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow)), e && this.modalElements && this.removeClasses(this.modalElements.overlay, this.classes.contentOpen), this.modalSessionActive = null, this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
|
|
682
|
+
}
|
|
683
|
+
clearDirectionClasses() {
|
|
684
|
+
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);
|
|
316
685
|
}
|
|
317
686
|
updateClassStyles() {
|
|
318
687
|
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()));
|
|
@@ -345,11 +714,17 @@ var o = class {
|
|
|
345
714
|
let n = document.createElement("div");
|
|
346
715
|
this.addClasses(n, this.classes.deselect), n.setAttribute("role", "button"), n.setAttribute("aria-label", this.settings.deselectText), n.setAttribute("tabindex", "0");
|
|
347
716
|
let r = this.store?.getSelectedOptions();
|
|
348
|
-
!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) => {
|
|
349
|
-
if (e.stopPropagation(), this.settings.disabled) return;
|
|
350
|
-
let t = !0, n = this.store.getSelectedOptions();
|
|
351
|
-
if (this.
|
|
352
|
-
|
|
717
|
+
!this.settings.allowDeselect || this.settings.isMultiple && r && r.length <= 0 || this.isAtMinSelected() ? this.addClasses(n, this.classes.hide) : this.removeClasses(n, this.classes.hide), n.onclick = (e) => {
|
|
718
|
+
if (e.stopPropagation(), this.settings.disabled || this.settings.isMultiple && this.isAtMinSelected()) return;
|
|
719
|
+
let t = !0, n = this.store.getSelectedOptions(), r = [], i = "";
|
|
720
|
+
if (this.settings.isMultiple) {
|
|
721
|
+
let e = this.settings.minSelected, t = this.store.getSelected();
|
|
722
|
+
if (e > 0 && t.length > e) i = this.getMinimumSelectionIds(), r = n.filter((e) => i.includes(e.id));
|
|
723
|
+
else if (e <= 0) i = [];
|
|
724
|
+
else return;
|
|
725
|
+
}
|
|
726
|
+
if (this.callbacks.beforeChange && (t = this.callbacks.beforeChange(r, n) === !0), t) {
|
|
727
|
+
if (this.settings.isMultiple) this.callbacks.setSelected(i, !1), this.updateDeselectAll();
|
|
353
728
|
else {
|
|
354
729
|
let e = this.store.getFirstOption(), t = e ? e.id : "";
|
|
355
730
|
this.callbacks.setSelected(t, !1);
|
|
@@ -384,7 +759,7 @@ var o = class {
|
|
|
384
759
|
e !== "click" && this.main.main.focus({ preventScroll: !0 });
|
|
385
760
|
}
|
|
386
761
|
placeholder() {
|
|
387
|
-
let e = this.store.filter((e) => e.placeholder, !1), t = this.settings.placeholderText;
|
|
762
|
+
let e = this.store.filter((e) => e.placeholder, !1, !1), t = this.settings.placeholderText;
|
|
388
763
|
e.length && (e[0].html === "" ? e[0].text !== "" && (t = e[0].text) : t = e[0].html);
|
|
389
764
|
let n = document.createElement("div");
|
|
390
765
|
return this.addClasses(n, this.classes.placeholder), n.innerHTML = t, n;
|
|
@@ -397,7 +772,7 @@ var o = class {
|
|
|
397
772
|
this.renderMultipleValues(), this.updateDeselectAll();
|
|
398
773
|
}
|
|
399
774
|
renderSingleValue() {
|
|
400
|
-
let e = this.store.filter((e) => e.selected && !e.placeholder, !1), t = e.length > 0 ? e[0] : null;
|
|
775
|
+
let e = this.store.filter((e) => e.selected && !e.placeholder, !1, !1), t = e.length > 0 ? e[0] : null;
|
|
401
776
|
if (!t) this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
402
777
|
else {
|
|
403
778
|
let e = document.createElement("div");
|
|
@@ -406,7 +781,7 @@ var o = class {
|
|
|
406
781
|
!this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
|
|
407
782
|
}
|
|
408
783
|
renderMultipleValues() {
|
|
409
|
-
let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1);
|
|
784
|
+
let e = this.main.values.childNodes, t = this.store.filter((e) => e.selected && e.display, !1, !1);
|
|
410
785
|
if (t.length === 0) {
|
|
411
786
|
this.main.values.innerHTML = this.placeholder().outerHTML;
|
|
412
787
|
return;
|
|
@@ -435,15 +810,29 @@ var o = class {
|
|
|
435
810
|
let i = e[r], a = i.getAttribute("data-id");
|
|
436
811
|
a && (t.filter((e) => e.id === a, !1).length || n.push(i));
|
|
437
812
|
}
|
|
438
|
-
|
|
813
|
+
let r = a(this.content.main, this.settings.timeoutDelay);
|
|
814
|
+
for (let e of n) this.addClasses(e, this.classes.valueOut), l(e, "ss-valueOut", r).then(() => {
|
|
439
815
|
this.main.values.hasChildNodes() && this.main.values.contains(e) && this.main.values.removeChild(e);
|
|
440
|
-
}
|
|
816
|
+
});
|
|
441
817
|
e = this.main.values.childNodes;
|
|
442
818
|
for (let n = 0; n < t.length; n++) {
|
|
443
819
|
let r = !0;
|
|
444
820
|
for (let i = 0; i < e.length; i++) t[n].id === String(e[i].dataset.id) && (r = !1);
|
|
445
821
|
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])));
|
|
446
822
|
}
|
|
823
|
+
this.updateMultipleValueDeleteVisibility();
|
|
824
|
+
}
|
|
825
|
+
isAtMinSelected() {
|
|
826
|
+
return this.settings.isMultiple && this.settings.minSelected > 0 && this.store.getSelectedOptions().length <= this.settings.minSelected;
|
|
827
|
+
}
|
|
828
|
+
getMinimumSelectionIds() {
|
|
829
|
+
let e = this.store.getSelectedOptions();
|
|
830
|
+
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.slice(0, this.settings.minSelected).map((e) => e.id);
|
|
831
|
+
}
|
|
832
|
+
updateMultipleValueDeleteVisibility() {
|
|
833
|
+
if (!this.settings.isMultiple || this.settings.multiString) return;
|
|
834
|
+
let e = !this.isAtMinSelected(), t = this.main.values.querySelectorAll("." + this.classes.getFirst("valueDelete"));
|
|
835
|
+
for (let n of t) e ? this.removeClasses(n, this.classes.hide) : this.addClasses(n, this.classes.hide);
|
|
447
836
|
}
|
|
448
837
|
multipleValue(e) {
|
|
449
838
|
let t = document.createElement("div");
|
|
@@ -451,16 +840,16 @@ var o = class {
|
|
|
451
840
|
let n = document.createElement("div");
|
|
452
841
|
if (this.addClasses(n, this.classes.valueText), n.textContent = e.text, t.appendChild(n), !e.mandatory) {
|
|
453
842
|
let n = document.createElement("div");
|
|
454
|
-
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) => {
|
|
843
|
+
this.addClasses(n, this.classes.valueDelete), n.setAttribute("tabindex", "0"), n.setAttribute("role", "button"), n.setAttribute("aria-label", `${this.settings.removeText} ${e.text}`), this.isAtMinSelected() && this.addClasses(n, this.classes.hide), n.onclick = (t) => {
|
|
455
844
|
if (t.preventDefault(), t.stopPropagation(), this.settings.disabled) return;
|
|
456
845
|
let n = !0, r = this.store.getSelectedOptions(), i = r.filter((t) => t.selected && t.id !== e.id, !0);
|
|
457
846
|
if (!(this.settings.minSelected && i.length < this.settings.minSelected) && (this.callbacks.beforeChange && (n = this.callbacks.beforeChange(i, r) === !0), n)) {
|
|
458
847
|
let e = [];
|
|
459
848
|
for (let t of i) {
|
|
460
|
-
if (t instanceof
|
|
461
|
-
t instanceof
|
|
849
|
+
if (t instanceof j) for (let n of t.options) n.id && e.push(n.id);
|
|
850
|
+
t instanceof A && e.push(t.id);
|
|
462
851
|
}
|
|
463
|
-
this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll();
|
|
852
|
+
this.callbacks.setSelected(e, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(i), this.updateDeselectAll(), this.updateMultipleValueDeleteVisibility();
|
|
464
853
|
}
|
|
465
854
|
};
|
|
466
855
|
let r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
@@ -491,27 +880,48 @@ var o = class {
|
|
|
491
880
|
this.settings.showSearch && (this.content.status.textContent = e);
|
|
492
881
|
}
|
|
493
882
|
moveContent() {
|
|
494
|
-
if (this.
|
|
495
|
-
this.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
this.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
this.
|
|
503
|
-
|
|
883
|
+
if (!this.isModalViewActive()) {
|
|
884
|
+
if (this.settings.contentPosition === "relative") {
|
|
885
|
+
this.moveContentBelow();
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
if (this.settings.openPosition === "down") {
|
|
889
|
+
this.moveContentBelow();
|
|
890
|
+
return;
|
|
891
|
+
} else if (this.settings.openPosition === "up") {
|
|
892
|
+
this.moveContentAbove();
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.putContent() === "up" ? this.moveContentAbove() : this.moveContentBelow();
|
|
504
896
|
}
|
|
505
|
-
|
|
897
|
+
}
|
|
898
|
+
startPositionTracking() {
|
|
899
|
+
this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), !(typeof ResizeObserver > "u") && (this.positionObserver = new ResizeObserver(() => {
|
|
900
|
+
this.settings.isOpen && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
|
|
901
|
+
this.moveContent();
|
|
902
|
+
}));
|
|
903
|
+
}), this.observePositionTargets()));
|
|
904
|
+
}
|
|
905
|
+
stopPositionTracking() {
|
|
906
|
+
cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null;
|
|
907
|
+
}
|
|
908
|
+
observePositionTargets() {
|
|
909
|
+
if (!this.positionObserver) return;
|
|
910
|
+
let e = /* @__PURE__ */ new Set(), t = (t) => {
|
|
911
|
+
!t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
|
|
912
|
+
};
|
|
913
|
+
t(this.main.main), t(this.content.main);
|
|
914
|
+
let n = this.main.main.parentElement, r = this.settings.contentLocation;
|
|
915
|
+
for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
|
|
506
916
|
}
|
|
507
917
|
searchDiv() {
|
|
508
918
|
let e = document.createElement("div"), t = document.createElement("input"), n = document.createElement("div");
|
|
509
919
|
this.addClasses(e, this.classes.search);
|
|
510
|
-
let
|
|
920
|
+
let r = {
|
|
511
921
|
main: e,
|
|
512
922
|
input: t
|
|
513
923
|
};
|
|
514
|
-
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 =
|
|
924
|
+
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 = _((e) => {
|
|
515
925
|
this.callbacks.search(e.target.value);
|
|
516
926
|
}, 100), t.onkeydown = (e) => {
|
|
517
927
|
switch (e.key) {
|
|
@@ -531,8 +941,8 @@ var o = class {
|
|
|
531
941
|
this.addClasses(n, this.classes.addable);
|
|
532
942
|
let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
533
943
|
t.setAttribute("viewBox", "0 0 100 100");
|
|
534
|
-
let
|
|
535
|
-
|
|
944
|
+
let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
945
|
+
a.setAttribute("d", this.classes.addablePath), t.appendChild(a), n.appendChild(t), n.onclick = (e) => {
|
|
536
946
|
if (e.preventDefault(), e.stopPropagation(), !this.callbacks.addable) return;
|
|
537
947
|
let t = this.content.search.input.value.trim();
|
|
538
948
|
if (t === "") {
|
|
@@ -540,14 +950,17 @@ var o = class {
|
|
|
540
950
|
return;
|
|
541
951
|
}
|
|
542
952
|
let n = (e) => {
|
|
543
|
-
let t = new
|
|
953
|
+
let t = new A(e);
|
|
544
954
|
if (this.callbacks.addOption(t), this.settings.isMultiple) {
|
|
545
955
|
let e = this.store.getSelected();
|
|
546
956
|
e.push(t.id), this.callbacks.setSelected(e, !0);
|
|
547
957
|
} else this.callbacks.setSelected([t.id], !0);
|
|
548
|
-
this.callbacks.search(""), this.settings.closeOnSelect
|
|
549
|
-
this.
|
|
550
|
-
|
|
958
|
+
if (this.callbacks.search(""), this.settings.closeOnSelect) {
|
|
959
|
+
let e = i(this.content.main);
|
|
960
|
+
setTimeout(() => {
|
|
961
|
+
this.callbacks.close();
|
|
962
|
+
}, e);
|
|
963
|
+
}
|
|
551
964
|
}, r = this.callbacks.addable(t);
|
|
552
965
|
r === !1 || r == null || (r instanceof Promise ? r.then((e) => {
|
|
553
966
|
typeof e == "string" ? n({
|
|
@@ -558,13 +971,13 @@ var o = class {
|
|
|
558
971
|
text: r,
|
|
559
972
|
value: r
|
|
560
973
|
}) : r instanceof Error ? this.renderError(r.message) : n(r));
|
|
561
|
-
}, e.appendChild(n),
|
|
974
|
+
}, e.appendChild(n), r.addable = {
|
|
562
975
|
main: n,
|
|
563
976
|
svg: t,
|
|
564
|
-
path:
|
|
977
|
+
path: a
|
|
565
978
|
};
|
|
566
979
|
}
|
|
567
|
-
return
|
|
980
|
+
return r;
|
|
568
981
|
}
|
|
569
982
|
searchFocus() {
|
|
570
983
|
this.content.search.input.focus({ preventScroll: !0 });
|
|
@@ -615,17 +1028,18 @@ var o = class {
|
|
|
615
1028
|
return e.id = t, e.dataset.id = t, e;
|
|
616
1029
|
}
|
|
617
1030
|
renderError(e) {
|
|
618
|
-
this.content.list.innerHTML = "";
|
|
1031
|
+
this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
|
|
619
1032
|
let t = document.createElement("div");
|
|
620
1033
|
this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
|
|
621
1034
|
}
|
|
622
1035
|
renderSearching() {
|
|
623
|
-
this.content.list.innerHTML = "";
|
|
1036
|
+
this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
|
|
624
1037
|
let e = document.createElement("div");
|
|
625
1038
|
this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
|
|
626
1039
|
}
|
|
627
1040
|
renderOptions(e) {
|
|
628
|
-
if (this.lastRenderedOptions = e.map((e) => e instanceof
|
|
1041
|
+
if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
|
|
1042
|
+
this.optionsListIsFullData = !1;
|
|
629
1043
|
let e = document.createElement("div");
|
|
630
1044
|
if (this.addClasses(e, this.classes.search), this.callbacks.addable) {
|
|
631
1045
|
let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
|
|
@@ -634,7 +1048,7 @@ var o = class {
|
|
|
634
1048
|
this.content.list.appendChild(e);
|
|
635
1049
|
return;
|
|
636
1050
|
}
|
|
637
|
-
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1).length || this.store.addOption(new
|
|
1051
|
+
this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new A({
|
|
638
1052
|
text: "",
|
|
639
1053
|
value: "",
|
|
640
1054
|
selected: !1,
|
|
@@ -642,7 +1056,7 @@ var o = class {
|
|
|
642
1056
|
}), !0));
|
|
643
1057
|
let t = document.createDocumentFragment();
|
|
644
1058
|
for (let n of e) {
|
|
645
|
-
if (n instanceof
|
|
1059
|
+
if (n instanceof j) {
|
|
646
1060
|
let e = document.createElement("div");
|
|
647
1061
|
this.addClasses(e, this.classes.optgroup);
|
|
648
1062
|
let r = document.createElement("div");
|
|
@@ -653,33 +1067,29 @@ var o = class {
|
|
|
653
1067
|
if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && n.selectAll) {
|
|
654
1068
|
let e = document.createElement("div");
|
|
655
1069
|
this.addClasses(e, this.classes.optgroupSelectAll);
|
|
656
|
-
let t =
|
|
657
|
-
for (let e of n.options) if (!e.selected) {
|
|
658
|
-
t = !1;
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
1070
|
+
let t = this.isOptgroupAllSelected(n.options);
|
|
661
1071
|
t && this.addClasses(e, this.classes.selected);
|
|
662
1072
|
let r = document.createElement("span");
|
|
663
|
-
r.textContent =
|
|
1073
|
+
r.textContent = this.optgroupSelectAllLabel(t), e.appendChild(r);
|
|
664
1074
|
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
665
1075
|
i.setAttribute("viewBox", "0 0 100 100"), e.appendChild(i);
|
|
1076
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1077
|
+
o.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(o);
|
|
666
1078
|
let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
667
|
-
s.setAttribute("d", this.classes.
|
|
668
|
-
let c = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
669
|
-
c.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(c), e.addEventListener("click", (e) => {
|
|
1079
|
+
s.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(s), e.addEventListener("click", (e) => {
|
|
670
1080
|
e.preventDefault(), e.stopPropagation();
|
|
671
|
-
let
|
|
672
|
-
if (t) {
|
|
673
|
-
let e =
|
|
1081
|
+
let t = this.store.getSelected();
|
|
1082
|
+
if (this.isOptgroupAllSelected(n.options, new Set(t))) {
|
|
1083
|
+
let e = t.filter((e) => {
|
|
674
1084
|
for (let t of n.options) if (e === t.id) return !1;
|
|
675
1085
|
return !0;
|
|
676
1086
|
});
|
|
677
1087
|
this.callbacks.setSelected(e, !0);
|
|
678
1088
|
return;
|
|
679
1089
|
} else {
|
|
680
|
-
let e = n.options.map((e) => e.id).filter((e) => e !== void 0),
|
|
681
|
-
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new
|
|
682
|
-
this.callbacks.setSelected(
|
|
1090
|
+
let e = n.options.map((e) => e.id).filter((e) => e !== void 0), r = t.concat(e);
|
|
1091
|
+
for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new A(e));
|
|
1092
|
+
this.callbacks.setSelected(r, !0);
|
|
683
1093
|
return;
|
|
684
1094
|
}
|
|
685
1095
|
}), a.appendChild(e);
|
|
@@ -690,16 +1100,136 @@ var o = class {
|
|
|
690
1100
|
let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
691
1101
|
i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), t.appendChild(i);
|
|
692
1102
|
let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
693
|
-
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", (
|
|
694
|
-
|
|
1103
|
+
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", (n) => {
|
|
1104
|
+
n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen));
|
|
695
1105
|
}), a.appendChild(t);
|
|
696
1106
|
}
|
|
697
1107
|
e.appendChild(r);
|
|
698
|
-
for (let r of n.options) e.appendChild(this.option(new
|
|
1108
|
+
for (let r of n.options) e.appendChild(this.option(new A(r))), t.appendChild(e);
|
|
1109
|
+
}
|
|
1110
|
+
n instanceof A && t.appendChild(this.option(n));
|
|
1111
|
+
}
|
|
1112
|
+
this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
|
|
1113
|
+
}
|
|
1114
|
+
canFilterOptionsInPlace() {
|
|
1115
|
+
return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
|
|
1116
|
+
}
|
|
1117
|
+
resetSearchFilterState() {
|
|
1118
|
+
this.lastSearchFilterTerm = "";
|
|
1119
|
+
}
|
|
1120
|
+
filterOptionsInPlace(e, t) {
|
|
1121
|
+
let n = e.trim();
|
|
1122
|
+
if (n === this.lastSearchFilterTerm) return;
|
|
1123
|
+
this.lastSearchFilterTerm = n;
|
|
1124
|
+
let r = [], i = this.content.list.querySelectorAll("." + this.classes.getFirst("option"));
|
|
1125
|
+
for (let e of i) {
|
|
1126
|
+
let i = e.dataset.id;
|
|
1127
|
+
if (!i) continue;
|
|
1128
|
+
let a = this.store.getOptionByID(i);
|
|
1129
|
+
if (!a) continue;
|
|
1130
|
+
let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
|
|
1131
|
+
o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
|
|
1132
|
+
}
|
|
1133
|
+
this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates();
|
|
1134
|
+
}
|
|
1135
|
+
setOptionsListFullData(e) {
|
|
1136
|
+
let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat();
|
|
1137
|
+
if (n.length !== t.length) {
|
|
1138
|
+
this.optionsListIsFullData = !1;
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
let r = new Set(t.map((e) => e.id));
|
|
1142
|
+
this.optionsListIsFullData = n.every((e) => r.has(e.id));
|
|
1143
|
+
}
|
|
1144
|
+
isClosableOptgroupOpen(e, t) {
|
|
1145
|
+
return e.classList.contains(this.classes.getFirst("close")) ? !1 : e.classList.contains(this.classes.getFirst("mainOpen")) || t.classList.contains(this.classes.getFirst("mainOpen"));
|
|
1146
|
+
}
|
|
1147
|
+
closeClosableOptgroup(e) {
|
|
1148
|
+
let t = e.querySelector("." + this.classes.getFirst("optgroupClosable"));
|
|
1149
|
+
if (!t || e.classList.contains(this.classes.getFirst("close"))) return;
|
|
1150
|
+
this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close);
|
|
1151
|
+
let n = t.querySelector("path");
|
|
1152
|
+
n && n.setAttribute("d", this.classes.arrowClose);
|
|
1153
|
+
}
|
|
1154
|
+
closeOtherClosableOptgroups(e) {
|
|
1155
|
+
let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1156
|
+
for (let n of t) n !== e && this.closeClosableOptgroup(n);
|
|
1157
|
+
}
|
|
1158
|
+
updateOptgroupVisibilityAfterSearch(e) {
|
|
1159
|
+
let t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1160
|
+
for (let n of t) {
|
|
1161
|
+
let t = n.querySelectorAll("." + this.classes.getFirst("option")), r = !1;
|
|
1162
|
+
for (let e of t) if (!e.classList.contains(this.classes.getFirst("hide"))) {
|
|
1163
|
+
r = !0;
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
if (!r) {
|
|
1167
|
+
this.addClasses(n, this.classes.hide);
|
|
1168
|
+
continue;
|
|
699
1169
|
}
|
|
700
|
-
n
|
|
1170
|
+
this.removeClasses(n, this.classes.hide), e !== "" && (this.removeClasses(n, this.classes.close), this.addClasses(n, this.classes.mainOpen));
|
|
701
1171
|
}
|
|
702
|
-
|
|
1172
|
+
}
|
|
1173
|
+
updateSearchResultsMessage(e, t) {
|
|
1174
|
+
if (this.removeListSearchMessage(), e > 0) return;
|
|
1175
|
+
let n = document.createElement("div");
|
|
1176
|
+
if (this.addClasses(n, this.classes.search), this.callbacks.addable) {
|
|
1177
|
+
let e = this.settings.addableText.replace("{value}", t);
|
|
1178
|
+
n.innerHTML = e, this.announce(e);
|
|
1179
|
+
} else n.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
|
|
1180
|
+
this.content.list.appendChild(n);
|
|
1181
|
+
}
|
|
1182
|
+
removeListSearchMessage() {
|
|
1183
|
+
this.content.list.querySelectorAll("." + this.classes.getFirst("search")).forEach((e) => e.remove());
|
|
1184
|
+
}
|
|
1185
|
+
setOptionElementContent(e, t, n) {
|
|
1186
|
+
let r = n.trim();
|
|
1187
|
+
this.settings.searchHighlight && r !== "" ? e.innerHTML = this.highlightText(t.html === "" ? t.text : t.html, r, this.classes.searchHighlighter) : t.html === "" ? e.textContent = t.text : e.innerHTML = t.html, this.settings.showOptionTooltips && e.textContent ? e.setAttribute("title", e.textContent) : e.removeAttribute("title");
|
|
1188
|
+
}
|
|
1189
|
+
hasRenderedOptions() {
|
|
1190
|
+
return this.content.list.querySelector("." + this.classes.getFirst("option")) !== null;
|
|
1191
|
+
}
|
|
1192
|
+
canUpdateOptionSelectionInPlace() {
|
|
1193
|
+
return this.content.search.input.value.trim() === "" ? this.hasRenderedOptions() : !1;
|
|
1194
|
+
}
|
|
1195
|
+
updateOptionSelection() {
|
|
1196
|
+
let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("option")), n = null;
|
|
1197
|
+
for (let r of t) {
|
|
1198
|
+
let t = r.dataset.id;
|
|
1199
|
+
if (!t) continue;
|
|
1200
|
+
let i = this.store.getOptionByID(t);
|
|
1201
|
+
if (!i) continue;
|
|
1202
|
+
let a = e.has(t);
|
|
1203
|
+
a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
|
|
1204
|
+
}
|
|
1205
|
+
!this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates();
|
|
1206
|
+
}
|
|
1207
|
+
updateOptgroupSelectAllStates() {
|
|
1208
|
+
if (!this.settings.isMultiple) return;
|
|
1209
|
+
let e = new Set(this.store.getSelected()), t = this.content.list.querySelectorAll("." + this.classes.getFirst("optgroup"));
|
|
1210
|
+
for (let n of t) {
|
|
1211
|
+
let t = n.querySelector("." + this.classes.getFirst("optgroupSelectAll"));
|
|
1212
|
+
if (!t) continue;
|
|
1213
|
+
let r = n.querySelectorAll("." + this.classes.getFirst("option")), i = r.length > 0;
|
|
1214
|
+
for (let t of r) {
|
|
1215
|
+
let n = t.dataset.id;
|
|
1216
|
+
if (!n || !e.has(n)) {
|
|
1217
|
+
i = !1;
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected);
|
|
1222
|
+
let a = t.querySelector("span");
|
|
1223
|
+
a && (a.textContent = this.optgroupSelectAllLabel(i));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
optgroupSelectAllLabel(e) {
|
|
1227
|
+
return e ? "Unselect All" : "Select All";
|
|
1228
|
+
}
|
|
1229
|
+
isOptgroupAllSelected(e, t) {
|
|
1230
|
+
if (e.length === 0) return !1;
|
|
1231
|
+
for (let n of e) if (!(t ? n.id && t.has(n.id) : n.selected)) return !1;
|
|
1232
|
+
return !0;
|
|
703
1233
|
}
|
|
704
1234
|
option(e) {
|
|
705
1235
|
if (e.placeholder) {
|
|
@@ -709,7 +1239,7 @@ var o = class {
|
|
|
709
1239
|
let t = document.createElement("div");
|
|
710
1240
|
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) => {
|
|
711
1241
|
t.classList.add(e);
|
|
712
|
-
}), e.style && (t.style.cssText = e.style), this.
|
|
1242
|
+
}), e.style && (t.style.cssText = e.style), this.setOptionElementContent(t, e, this.content.search.input.value), 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) => {
|
|
713
1243
|
t.preventDefault(), t.stopPropagation();
|
|
714
1244
|
let n = this.store.getSelected(), r = t.currentTarget, i = String(r.dataset.id), a = t.ctrlKey || t.metaKey;
|
|
715
1245
|
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;
|
|
@@ -732,7 +1262,7 @@ var o = class {
|
|
|
732
1262
|
}), t;
|
|
733
1263
|
}
|
|
734
1264
|
destroy() {
|
|
735
|
-
this.
|
|
1265
|
+
this.stopPositionTracking(), this.modalElements &&= (this.unlockBodyScroll(), this.content.main.parentElement === this.modalElements.dialog && this.restoreContentOffscreen(), this.modalElements.overlay.remove(), null), this.main.main.remove(), this.content.main.remove();
|
|
736
1266
|
}
|
|
737
1267
|
highlightText(e, t, n) {
|
|
738
1268
|
let r = t.trim();
|
|
@@ -800,10 +1330,34 @@ var o = class {
|
|
|
800
1330
|
}
|
|
801
1331
|
updateDeselectAll() {
|
|
802
1332
|
if (!this.store || !this.settings) return;
|
|
803
|
-
let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.main.deselect.main,
|
|
804
|
-
r && !(n && !t) ? this.removeClasses(
|
|
1333
|
+
let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.isAtMinSelected(), a = this.main.deselect.main, o = this.classes.hide;
|
|
1334
|
+
r && !(n && !t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region src/slim-select/mutations.ts
|
|
1339
|
+
function P(e, t) {
|
|
1340
|
+
let n = {
|
|
1341
|
+
classChanged: !1,
|
|
1342
|
+
disabledChanged: !1,
|
|
1343
|
+
optgroupOptionChanged: !1,
|
|
1344
|
+
selectionChanged: !1
|
|
1345
|
+
};
|
|
1346
|
+
for (let r of e) {
|
|
1347
|
+
if (r.target === t && (r.attributeName === "disabled" && (n.disabledChanged = !0), r.attributeName === "class" && (n.classChanged = !0), r.type === "childList")) {
|
|
1348
|
+
for (let e of Array.from(r.addedNodes)) if (e.nodeName === "OPTION" && e.value === t.value) {
|
|
1349
|
+
n.selectionChanged = !0;
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1352
|
+
n.optgroupOptionChanged = !0;
|
|
1353
|
+
}
|
|
1354
|
+
(r.target.nodeName === "OPTGROUP" || r.target.nodeName === "OPTION") && (n.optgroupOptionChanged = !0);
|
|
805
1355
|
}
|
|
806
|
-
|
|
1356
|
+
return n;
|
|
1357
|
+
}
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region src/slim-select/select.ts
|
|
1360
|
+
var F = class {
|
|
807
1361
|
select;
|
|
808
1362
|
onValueChange;
|
|
809
1363
|
onClassChange;
|
|
@@ -817,6 +1371,7 @@ var o = class {
|
|
|
817
1371
|
preventNativeSelect = null;
|
|
818
1372
|
preventNativeSelectMousedown = null;
|
|
819
1373
|
preventNativeSelectFocus = null;
|
|
1374
|
+
restoreAriaHiddenOnBlur = null;
|
|
820
1375
|
constructor(e) {
|
|
821
1376
|
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);
|
|
822
1377
|
}
|
|
@@ -827,12 +1382,14 @@ var o = class {
|
|
|
827
1382
|
this.select.disabled = !0;
|
|
828
1383
|
}
|
|
829
1384
|
hideUI() {
|
|
830
|
-
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.
|
|
1385
|
+
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.clipPath = "inset(50%)", document.activeElement !== this.select && this.select.setAttribute("aria-hidden", "true"), this.preventNativeSelect || (this.preventNativeSelect = (e) => {
|
|
831
1386
|
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
832
1387
|
}, this.preventNativeSelectMousedown = (e) => {
|
|
833
1388
|
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
834
1389
|
}, this.preventNativeSelectFocus = (e) => {
|
|
835
|
-
e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1390
|
+
this.select.removeAttribute("aria-hidden"), e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
|
|
1391
|
+
}, this.restoreAriaHiddenOnBlur = () => {
|
|
1392
|
+
this.select.setAttribute("aria-hidden", "true");
|
|
836
1393
|
}, this.select.addEventListener("click", this.preventNativeSelect, {
|
|
837
1394
|
capture: !0,
|
|
838
1395
|
passive: !1
|
|
@@ -842,10 +1399,13 @@ var o = class {
|
|
|
842
1399
|
}), this.select.addEventListener("focus", this.preventNativeSelectFocus, {
|
|
843
1400
|
capture: !0,
|
|
844
1401
|
passive: !1
|
|
1402
|
+
}), this.select.addEventListener("blur", this.restoreAriaHiddenOnBlur, {
|
|
1403
|
+
capture: !0,
|
|
1404
|
+
passive: !0
|
|
845
1405
|
}));
|
|
846
1406
|
}
|
|
847
1407
|
showUI() {
|
|
848
|
-
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.
|
|
1408
|
+
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.clipPath = "", 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), this.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null);
|
|
849
1409
|
}
|
|
850
1410
|
changeListen(e) {
|
|
851
1411
|
this.listen = e, e && this.observer && this.observer.observe(this.select, {
|
|
@@ -859,29 +1419,19 @@ var o = class {
|
|
|
859
1419
|
}
|
|
860
1420
|
observeCall(e) {
|
|
861
1421
|
if (!this.listen) return;
|
|
862
|
-
let
|
|
863
|
-
for (let a of e) {
|
|
864
|
-
if (a.target === this.select && (a.attributeName === "disabled" && (n = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
|
|
865
|
-
for (let e of Array.from(a.addedNodes)) if (e.nodeName === "OPTION" && e.value === this.select.value) {
|
|
866
|
-
i = !0;
|
|
867
|
-
break;
|
|
868
|
-
}
|
|
869
|
-
r = !0;
|
|
870
|
-
}
|
|
871
|
-
(a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (r = !0);
|
|
872
|
-
}
|
|
1422
|
+
let { classChanged: t, disabledChanged: n, optgroupOptionChanged: r, selectionChanged: i } = P(e, this.select), a = i;
|
|
873
1423
|
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) {
|
|
874
1424
|
if (this.isUpdating) {
|
|
875
1425
|
if (this.select.options.length > 0) {
|
|
876
1426
|
let e = this.getData();
|
|
877
1427
|
e.length > 0 && (this.pendingOptionsChange = e);
|
|
878
1428
|
}
|
|
879
|
-
|
|
1429
|
+
a && this.select.dispatchEvent(new Event("change"));
|
|
880
1430
|
return;
|
|
881
1431
|
}
|
|
882
|
-
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0);
|
|
1432
|
+
this.changeListen(!1), this.onOptionsChange(this.getData()), this.changeListen(!0), a = !1;
|
|
883
1433
|
}
|
|
884
|
-
|
|
1434
|
+
a && this.select.dispatchEvent(new Event("change"));
|
|
885
1435
|
}
|
|
886
1436
|
getData() {
|
|
887
1437
|
let e = [], t = this.select.childNodes;
|
|
@@ -893,7 +1443,6 @@ var o = class {
|
|
|
893
1443
|
id: e.id,
|
|
894
1444
|
label: e.label,
|
|
895
1445
|
selectAll: e.dataset ? e.dataset.selectall === "true" : !1,
|
|
896
|
-
selectAllText: e.dataset ? e.dataset.selectalltext : "Select all",
|
|
897
1446
|
closable: e.dataset ? e.dataset.closable : "off",
|
|
898
1447
|
options: []
|
|
899
1448
|
}, n = e.childNodes;
|
|
@@ -914,7 +1463,7 @@ var o = class {
|
|
|
914
1463
|
placeholder: e.dataset.placeholder === "true",
|
|
915
1464
|
class: e.className,
|
|
916
1465
|
style: e.style.cssText,
|
|
917
|
-
data: e.dataset
|
|
1466
|
+
data: f(e.dataset)
|
|
918
1467
|
};
|
|
919
1468
|
}
|
|
920
1469
|
getSelectedOptions() {
|
|
@@ -953,7 +1502,8 @@ var o = class {
|
|
|
953
1502
|
t.selected = e.includes(t.id);
|
|
954
1503
|
}
|
|
955
1504
|
}
|
|
956
|
-
this.
|
|
1505
|
+
let n = this.getSelectedOptions();
|
|
1506
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
|
|
957
1507
|
}
|
|
958
1508
|
setSelectedByValue(e) {
|
|
959
1509
|
this.changeListen(!1);
|
|
@@ -971,7 +1521,8 @@ var o = class {
|
|
|
971
1521
|
t.selected = e.includes(t.value);
|
|
972
1522
|
}
|
|
973
1523
|
}
|
|
974
|
-
this.
|
|
1524
|
+
let n = this.getSelectedOptions();
|
|
1525
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
|
|
975
1526
|
}
|
|
976
1527
|
updateSelect(e, t, n) {
|
|
977
1528
|
this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
|
|
@@ -981,7 +1532,7 @@ var o = class {
|
|
|
981
1532
|
updateOptions(e) {
|
|
982
1533
|
if (!(!e || e.length === 0)) {
|
|
983
1534
|
this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
|
|
984
|
-
for (let t of e) t instanceof
|
|
1535
|
+
for (let t of e) t instanceof j && this.select.appendChild(this.createOptgroup(t)), t instanceof A && this.select.appendChild(this.createOption(t));
|
|
985
1536
|
if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
|
|
986
1537
|
let e = this.pendingOptionsChange;
|
|
987
1538
|
e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
|
|
@@ -998,25 +1549,25 @@ var o = class {
|
|
|
998
1549
|
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) => {
|
|
999
1550
|
t.classList.add(e);
|
|
1000
1551
|
}), e.data && typeof e.data == "object" && Object.keys(e.data).forEach((n) => {
|
|
1001
|
-
t.setAttribute("data-" +
|
|
1552
|
+
t.setAttribute("data-" + E(n), e.data[n]);
|
|
1002
1553
|
}), t;
|
|
1003
1554
|
}
|
|
1004
1555
|
setupLabelHandlers() {
|
|
1005
1556
|
let e = [], t = this.select.id;
|
|
1006
1557
|
t && document.querySelectorAll(`label[for="${t}"]`).forEach((t) => e.push(t));
|
|
1007
|
-
let
|
|
1008
|
-
for (;
|
|
1009
|
-
if (
|
|
1010
|
-
e.push(
|
|
1558
|
+
let n = this.select.parentElement;
|
|
1559
|
+
for (; n && n !== document.body;) {
|
|
1560
|
+
if (n.tagName === "LABEL") {
|
|
1561
|
+
e.push(n);
|
|
1011
1562
|
break;
|
|
1012
1563
|
}
|
|
1013
|
-
|
|
1564
|
+
n = n.parentElement;
|
|
1014
1565
|
}
|
|
1015
1566
|
Array.from(new Set(e)).forEach((e) => {
|
|
1016
1567
|
if (e.__slimSelectLabelHandler) return;
|
|
1017
1568
|
let t = (e) => {
|
|
1018
|
-
let t = e.target,
|
|
1019
|
-
e.preventDefault(), !
|
|
1569
|
+
let t = e.target, n = g(t, this.select.dataset.id);
|
|
1570
|
+
e.preventDefault(), !n && this.onLabelClick && this.onLabelClick();
|
|
1020
1571
|
};
|
|
1021
1572
|
e.__slimSelectLabelHandler = t, e.addEventListener("click", t, {
|
|
1022
1573
|
capture: !0,
|
|
@@ -1041,58 +1592,120 @@ var o = class {
|
|
|
1041
1592
|
});
|
|
1042
1593
|
}
|
|
1043
1594
|
destroy() {
|
|
1044
|
-
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();
|
|
1595
|
+
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.restoreAriaHiddenOnBlur &&= (this.select.removeEventListener("blur", this.restoreAriaHiddenOnBlur, { capture: !0 }), null), this.observer &&= (this.observer.disconnect(), null), this.removeLabelHandlers(), delete this.select.dataset.id, this.showUI();
|
|
1045
1596
|
}
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
contentLocation;
|
|
1069
|
-
contentPosition;
|
|
1070
|
-
contentWidth;
|
|
1071
|
-
openPosition;
|
|
1072
|
-
placeholderText;
|
|
1073
|
-
allowDeselect;
|
|
1074
|
-
hideSelected;
|
|
1075
|
-
multiString;
|
|
1076
|
-
keepOrder;
|
|
1077
|
-
showOptionTooltips;
|
|
1078
|
-
minSelected;
|
|
1079
|
-
maxSelected;
|
|
1080
|
-
timeoutDelay;
|
|
1081
|
-
maxValuesShown;
|
|
1082
|
-
maxValuesMessage;
|
|
1083
|
-
addableText;
|
|
1597
|
+
};
|
|
1598
|
+
//#endregion
|
|
1599
|
+
//#region src/slim-select/sync.ts
|
|
1600
|
+
function I(e, t) {
|
|
1601
|
+
return T(e.getData(!1), t);
|
|
1602
|
+
}
|
|
1603
|
+
function L(e, t) {
|
|
1604
|
+
let n = Array.isArray(t) ? t : [t], r = e.getDataOptions(!1), i = [];
|
|
1605
|
+
for (let e of n) {
|
|
1606
|
+
if (r.find((t) => t.id == e)) {
|
|
1607
|
+
i.push(e);
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
for (let t of r.filter((t) => t.value == e)) i.push(t.id);
|
|
1611
|
+
}
|
|
1612
|
+
return i;
|
|
1613
|
+
}
|
|
1614
|
+
var R = class {
|
|
1615
|
+
deps;
|
|
1616
|
+
queue = [];
|
|
1617
|
+
flushScheduled = !1;
|
|
1618
|
+
isSyncing = !1;
|
|
1084
1619
|
constructor(e) {
|
|
1085
|
-
|
|
1620
|
+
this.deps = e;
|
|
1621
|
+
}
|
|
1622
|
+
enqueue(e) {
|
|
1623
|
+
if (this.queue.push(e), e.source === "native") {
|
|
1624
|
+
this.flushScheduled || (this.flushScheduled = !0, queueMicrotask(() => this.flush()));
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
this.isSyncing || this.flush();
|
|
1628
|
+
}
|
|
1629
|
+
flush() {
|
|
1630
|
+
if (this.flushScheduled = !1, this.queue.length === 0) return;
|
|
1631
|
+
let e = this.coalesceBatch(this.queue);
|
|
1632
|
+
this.queue = [], this.isSyncing = !0;
|
|
1633
|
+
try {
|
|
1634
|
+
for (let t of e) this.applyChange(t);
|
|
1635
|
+
} finally {
|
|
1636
|
+
this.isSyncing = !1, this.queue.length > 0 && this.flush();
|
|
1637
|
+
}
|
|
1086
1638
|
}
|
|
1087
|
-
|
|
1639
|
+
coalesceBatch(e) {
|
|
1640
|
+
let t = e.some((e) => e.type === "structure"), n = e.some((e) => e.type === "addOption");
|
|
1641
|
+
if (t || n) {
|
|
1642
|
+
let t = e.filter((e) => e.type === "structure" || e.type === "addOption"), n = t[t.length - 1];
|
|
1643
|
+
return n?.type === "structure" ? [n] : t;
|
|
1644
|
+
}
|
|
1645
|
+
let r = e.filter((e) => e.type === "selection");
|
|
1646
|
+
return r.length > 0 ? [r[r.length - 1]] : e;
|
|
1647
|
+
}
|
|
1648
|
+
applyChange(e) {
|
|
1649
|
+
switch (e.type) {
|
|
1650
|
+
case "structure":
|
|
1651
|
+
this.applyStructure(e.data, e.source, e.preserveSelection, e.isSearchResult);
|
|
1652
|
+
break;
|
|
1653
|
+
case "selection":
|
|
1654
|
+
this.applySelection(e.values, e.source, e.runAfterChange !== !1);
|
|
1655
|
+
break;
|
|
1656
|
+
case "addOption":
|
|
1657
|
+
this.applyAddOption(e.option);
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
applyStructure(e, t, n = !1, r = !1) {
|
|
1662
|
+
let { store: i, select: a, render: o, events: s } = this.deps;
|
|
1663
|
+
if (I(i, e)) return;
|
|
1664
|
+
let c = i.getSelected(), l = i.validateDataArray(e);
|
|
1665
|
+
if (l) {
|
|
1666
|
+
s.error ? s.error(l) : this.deps.onError && this.deps.onError(l);
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
i.setData(e, n);
|
|
1670
|
+
let u = i.getData(!1);
|
|
1671
|
+
r || i.snapshotCatalog(), a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !v(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
|
|
1672
|
+
}
|
|
1673
|
+
applySelection(e, t, n) {
|
|
1674
|
+
let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = L(r, e);
|
|
1675
|
+
if (v(s, c)) return;
|
|
1676
|
+
r.setSelectedBy("id", c), i.setSelectedByValue(r.getSelectedValues()), a.renderValues();
|
|
1677
|
+
let l = a.content.search.input.value.trim();
|
|
1678
|
+
l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !v(s, r.getSelected()) && o.afterChange(r.getSelectedOptions());
|
|
1679
|
+
}
|
|
1680
|
+
applyAddOption(e) {
|
|
1681
|
+
let { store: t, select: n, render: r, events: i } = this.deps, a = t.getSelected(), o = r.content.search.input.value.trim() !== "" && !!this.deps.search, s = e.value ?? e.text ?? "", c = (e) => {
|
|
1682
|
+
for (let t of e) {
|
|
1683
|
+
if (t instanceof j) {
|
|
1684
|
+
if (t.options.some((e) => (e.value ?? e.text) === s)) return !0;
|
|
1685
|
+
continue;
|
|
1686
|
+
}
|
|
1687
|
+
if ((t.value ?? t.text) === s) return !0;
|
|
1688
|
+
}
|
|
1689
|
+
return !1;
|
|
1690
|
+
};
|
|
1691
|
+
if (!c(t.getData(!1))) if (o) {
|
|
1692
|
+
let n = t.getCatalogData();
|
|
1693
|
+
c(n) || t.setData([...n, new A(e)], !0), t.snapshotCatalog();
|
|
1694
|
+
} else t.addOption(e), t.snapshotCatalog();
|
|
1695
|
+
let l = t.getData(!1);
|
|
1696
|
+
n.updateOptions(l), r.renderValues(), r.renderOptions(l), i.afterChange && !v(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
|
|
1697
|
+
}
|
|
1698
|
+
}, z = class {
|
|
1088
1699
|
selectEl;
|
|
1089
1700
|
settings;
|
|
1090
1701
|
cssClasses;
|
|
1091
1702
|
select;
|
|
1092
1703
|
store;
|
|
1093
1704
|
render;
|
|
1094
|
-
|
|
1095
|
-
|
|
1705
|
+
sync;
|
|
1706
|
+
lifecycle;
|
|
1707
|
+
globalEvents;
|
|
1708
|
+
searchGeneration = 0;
|
|
1096
1709
|
events = {
|
|
1097
1710
|
search: void 0,
|
|
1098
1711
|
searchFilter: (e, t) => e.text.toLowerCase().indexOf(t.toLowerCase()) !== -1,
|
|
@@ -1120,31 +1733,81 @@ var o = class {
|
|
|
1120
1733
|
"beforeClose",
|
|
1121
1734
|
"afterClose"
|
|
1122
1735
|
];
|
|
1123
|
-
for (let e in t.events) t.events.hasOwnProperty(e) && (n.indexOf(e) === -1 ? this.events[e] = t.events[e] : this.events[e] =
|
|
1124
|
-
this.settings.disabled = t.settings?.disabled ? t.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
|
|
1125
|
-
this.setSelected(e.map((e) => e.id));
|
|
1126
|
-
}, this.select.onClassChange = (e) => {
|
|
1736
|
+
for (let e in t.events) t.events.hasOwnProperty(e) && (n.indexOf(e) === -1 ? this.events[e] = t.events[e] : this.events[e] = _(t.events[e], 100));
|
|
1737
|
+
this.settings.disabled = t.settings?.disabled ? t.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 F(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.onClassChange = (e) => {
|
|
1127
1738
|
this.settings.class = e, this.render.updateClassStyles();
|
|
1128
1739
|
}, this.select.onDisabledChange = (e) => {
|
|
1129
1740
|
e ? this.disable() : this.enable();
|
|
1130
|
-
}, this.select.onOptionsChange = (e) => {
|
|
1131
|
-
this.setData(e || []);
|
|
1132
1741
|
}, this.select.onLabelClick = () => {
|
|
1133
1742
|
this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
|
|
1134
1743
|
};
|
|
1135
|
-
let
|
|
1136
|
-
this.store = new
|
|
1137
|
-
let
|
|
1744
|
+
let r = t.data ? t.data : this.select.getData();
|
|
1745
|
+
this.store = new M(this.settings.isMultiple ? "multiple" : "single", r), t.data && this.select.updateOptions(this.store.getData());
|
|
1746
|
+
let i = {
|
|
1138
1747
|
open: this.open.bind(this),
|
|
1139
1748
|
close: this.close.bind(this),
|
|
1140
1749
|
addable: this.events.addable ? this.events.addable : void 0,
|
|
1141
|
-
setSelected:
|
|
1142
|
-
|
|
1750
|
+
setSelected: (e, t) => {
|
|
1751
|
+
this.sync.enqueue({
|
|
1752
|
+
type: "selection",
|
|
1753
|
+
values: e,
|
|
1754
|
+
source: "ui",
|
|
1755
|
+
runAfterChange: t
|
|
1756
|
+
});
|
|
1757
|
+
},
|
|
1758
|
+
addOption: (e) => {
|
|
1759
|
+
this.sync.enqueue({
|
|
1760
|
+
type: "addOption",
|
|
1761
|
+
option: e,
|
|
1762
|
+
source: "ui"
|
|
1763
|
+
});
|
|
1764
|
+
},
|
|
1143
1765
|
search: this.search.bind(this),
|
|
1144
1766
|
beforeChange: this.events.beforeChange,
|
|
1145
1767
|
afterChange: this.events.afterChange
|
|
1146
1768
|
};
|
|
1147
|
-
this.render = new
|
|
1769
|
+
this.settings.modalTitle = t.settings?.modalTitle ?? m(this.selectEl), this.render = new N(this.settings, this.cssClasses, this.store, i), this.settings.timeoutDelay = a(this.render.content.main, t.settings?.timeoutDelay), this.sync = new R({
|
|
1770
|
+
select: this.select,
|
|
1771
|
+
store: this.store,
|
|
1772
|
+
render: this.render,
|
|
1773
|
+
events: this.events,
|
|
1774
|
+
search: this.search.bind(this)
|
|
1775
|
+
}), this.select.onValueChange = (e) => {
|
|
1776
|
+
this.sync.enqueue({
|
|
1777
|
+
type: "selection",
|
|
1778
|
+
values: e.map((e) => e.id),
|
|
1779
|
+
source: "native"
|
|
1780
|
+
});
|
|
1781
|
+
}, this.select.onOptionsChange = (e) => {
|
|
1782
|
+
this.sync.enqueue({
|
|
1783
|
+
type: "structure",
|
|
1784
|
+
data: e || [],
|
|
1785
|
+
source: "native"
|
|
1786
|
+
});
|
|
1787
|
+
}, this.lifecycle = new k({
|
|
1788
|
+
beforeOpen: this.events.beforeOpen,
|
|
1789
|
+
afterOpen: this.events.afterOpen,
|
|
1790
|
+
beforeClose: this.events.beforeClose,
|
|
1791
|
+
afterClose: () => {
|
|
1792
|
+
this.render.clearDirectionClasses(), this.render.finalizeModalClose(), this.events.afterClose && this.events.afterClose();
|
|
1793
|
+
},
|
|
1794
|
+
onOpenReady: () => this.globalEvents.attachDocumentClick(),
|
|
1795
|
+
onCloseReady: () => this.globalEvents.detachDocumentClick()
|
|
1796
|
+
}, {
|
|
1797
|
+
timeoutDelay: this.settings.timeoutDelay,
|
|
1798
|
+
waitForAnimation: (e, t) => this.render.waitForAnimation(e, t)
|
|
1799
|
+
}), this.globalEvents = new O({
|
|
1800
|
+
onDocumentClick: this.documentClick.bind(this),
|
|
1801
|
+
onWindowResize: () => {
|
|
1802
|
+
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1803
|
+
},
|
|
1804
|
+
onWindowScroll: () => {
|
|
1805
|
+
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1806
|
+
},
|
|
1807
|
+
onVisibilityChange: () => {
|
|
1808
|
+
document.hidden && this.close();
|
|
1809
|
+
}
|
|
1810
|
+
}), this.render.renderValues(), this.render.renderOptions(this.store.getData(!1));
|
|
1148
1811
|
let o = this.selectEl.getAttribute("aria-label"), s = this.selectEl.getAttribute("aria-labelledby");
|
|
1149
1812
|
if (o) this.render.main.main.setAttribute("aria-label", o);
|
|
1150
1813
|
else if (s) this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", s);
|
|
@@ -1152,7 +1815,7 @@ var o = class {
|
|
|
1152
1815
|
let e = Array.from(this.selectEl.labels).map((e, t) => (e.id ||= `${this.settings.id}-label-${t}`, e.id));
|
|
1153
1816
|
this.render.main.main.removeAttribute("aria-label"), this.render.main.main.setAttribute("aria-labelledby", e.join(" "));
|
|
1154
1817
|
}
|
|
1155
|
-
this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling),
|
|
1818
|
+
this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), this.globalEvents.attach({ listenScroll: this.settings.openPosition === "auto" }), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
|
|
1156
1819
|
}
|
|
1157
1820
|
enable() {
|
|
1158
1821
|
this.settings.disabled = !1, this.select.enable(), this.render.enable();
|
|
@@ -1164,88 +1827,108 @@ var o = class {
|
|
|
1164
1827
|
return this.store.getData();
|
|
1165
1828
|
}
|
|
1166
1829
|
setData(e) {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1172
|
-
this.store.setData(e);
|
|
1173
|
-
let r = this.store.getData();
|
|
1174
|
-
this.select.updateOptions(r), this.render.renderValues(), this.render.renderOptions(r), this.events.afterChange && !i(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1830
|
+
this.sync.enqueue({
|
|
1831
|
+
type: "structure",
|
|
1832
|
+
data: e,
|
|
1833
|
+
source: "api"
|
|
1834
|
+
});
|
|
1175
1835
|
}
|
|
1176
1836
|
getSelected() {
|
|
1177
1837
|
let e = this.store.getSelectedOptions();
|
|
1178
1838
|
return this.settings.keepOrder && (e = this.store.selectedOrderOptions(e)), e.map((e) => e.value);
|
|
1179
1839
|
}
|
|
1180
1840
|
setSelected(e, t = !0) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
continue;
|
|
1188
|
-
}
|
|
1189
|
-
for (let e of r.filter((e) => e.value == t)) a.push(e.id);
|
|
1190
|
-
}
|
|
1191
|
-
this.store.setSelectedBy("id", a);
|
|
1192
|
-
let o = this.store.getData();
|
|
1193
|
-
this.select.updateOptions(o), this.render.renderValues(), this.render.content.search.input.value === "" ? this.render.renderOptions(o) : this.search(this.render.content.search.input.value), t && this.events.afterChange && !i(n, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
|
|
1841
|
+
this.sync.enqueue({
|
|
1842
|
+
type: "selection",
|
|
1843
|
+
values: e,
|
|
1844
|
+
source: "api",
|
|
1845
|
+
runAfterChange: t
|
|
1846
|
+
});
|
|
1194
1847
|
}
|
|
1195
1848
|
addOption(e) {
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1849
|
+
this.sync.enqueue({
|
|
1850
|
+
type: "addOption",
|
|
1851
|
+
option: e,
|
|
1852
|
+
source: "api"
|
|
1853
|
+
});
|
|
1200
1854
|
}
|
|
1201
1855
|
open() {
|
|
1202
|
-
this.settings.disabled || this.settings.isOpen
|
|
1203
|
-
|
|
1204
|
-
|
|
1856
|
+
if (this.settings.disabled || this.settings.isOpen) return;
|
|
1857
|
+
this.lifecycle.cancelPending(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.lifecycle.requestOpen().then(() => {
|
|
1858
|
+
this.settings.isOpen && (this.settings.isFullOpen = this.lifecycle.isFullOpen, this.settings.isOpen = this.lifecycle.isOpen);
|
|
1859
|
+
}), this.settings.contentPosition === "absolute" && !this.render.isModalViewActive() && this.render.startPositionTracking();
|
|
1860
|
+
let e = this.render.content.search.input.value.trim();
|
|
1861
|
+
e !== "" && this.search(e);
|
|
1205
1862
|
}
|
|
1206
1863
|
close(e = null) {
|
|
1207
|
-
!this.settings.isOpen || this.settings.alwaysOpen || (this.
|
|
1208
|
-
this.
|
|
1209
|
-
}
|
|
1864
|
+
!this.settings.isOpen || this.settings.alwaysOpen || (this.lifecycle.cancelPending(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && (this.sync.flush(), this.search("")), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.lifecycle.requestClose().then(() => {
|
|
1865
|
+
this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen);
|
|
1866
|
+
}), this.render.stopPositionTracking());
|
|
1210
1867
|
}
|
|
1211
1868
|
search(e) {
|
|
1212
|
-
|
|
1213
|
-
|
|
1869
|
+
let t = e.trim();
|
|
1870
|
+
if (this.render.content.search.input.value !== t && (this.render.content.search.input.value = t), t === "") {
|
|
1871
|
+
this.clearSearch();
|
|
1214
1872
|
return;
|
|
1215
1873
|
}
|
|
1216
|
-
if (
|
|
1217
|
-
|
|
1218
|
-
this.render.renderOptions(t);
|
|
1874
|
+
if (this.events.search) {
|
|
1875
|
+
this.runApiSearch(t);
|
|
1219
1876
|
return;
|
|
1220
1877
|
}
|
|
1878
|
+
this.runLocalSearch(t);
|
|
1879
|
+
}
|
|
1880
|
+
clearSearch() {
|
|
1881
|
+
if (this.searchGeneration++, !this.events.search && this.render.canFilterOptionsInPlace()) {
|
|
1882
|
+
this.render.filterOptionsInPlace("", this.events.searchFilter), this.render.resetSearchFilterState();
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
this.render.resetSearchFilterState(), this.sync.enqueue({
|
|
1886
|
+
type: "structure",
|
|
1887
|
+
data: this.store.getCatalogData(),
|
|
1888
|
+
source: "api",
|
|
1889
|
+
preserveSelection: !0
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
runLocalSearch(e) {
|
|
1893
|
+
if (this.render.canFilterOptionsInPlace()) {
|
|
1894
|
+
this.render.filterOptionsInPlace(e, this.events.searchFilter);
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
let t = this.store.search(e, this.events.searchFilter);
|
|
1898
|
+
this.render.renderOptions(t);
|
|
1899
|
+
}
|
|
1900
|
+
runApiSearch(e) {
|
|
1901
|
+
let t = ++this.searchGeneration;
|
|
1221
1902
|
this.render.renderSearching();
|
|
1222
|
-
let
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1903
|
+
let n = this.events.search(e, this.store.getSelectedOptions(), this.store.getCatalogData()), r = (n) => {
|
|
1904
|
+
t === this.searchGeneration && this.render.content.search.input.value.trim() === e && this.sync.enqueue({
|
|
1905
|
+
type: "structure",
|
|
1906
|
+
data: n,
|
|
1907
|
+
source: "api",
|
|
1908
|
+
preserveSelection: !0,
|
|
1909
|
+
isSearchResult: !0
|
|
1910
|
+
});
|
|
1911
|
+
};
|
|
1912
|
+
if (n instanceof Promise) {
|
|
1913
|
+
n.then(r).catch((e) => {
|
|
1914
|
+
t === this.searchGeneration && this.render.renderError(typeof e == "string" ? e : e.message);
|
|
1228
1915
|
});
|
|
1229
1916
|
return;
|
|
1230
|
-
}
|
|
1917
|
+
}
|
|
1918
|
+
if (Array.isArray(n)) {
|
|
1919
|
+
r(n);
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
this.render.renderError("Search event must return a promise or an array of data");
|
|
1231
1923
|
}
|
|
1232
1924
|
destroy() {
|
|
1233
|
-
this.
|
|
1925
|
+
this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy();
|
|
1926
|
+
}
|
|
1927
|
+
documentClick(e) {
|
|
1928
|
+
this.settings.isOpen && e.target && !g(e.target, this.settings.id) && this.close(e.type);
|
|
1234
1929
|
}
|
|
1235
|
-
windowResize = r(() => {
|
|
1236
|
-
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1237
|
-
});
|
|
1238
|
-
windowScroll = r(() => {
|
|
1239
|
-
!this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
|
|
1240
|
-
});
|
|
1241
|
-
documentClick = (e) => {
|
|
1242
|
-
this.settings.isOpen && e.target && !n(e.target, this.settings.id) && this.close(e.type);
|
|
1243
|
-
};
|
|
1244
|
-
windowVisibilityChange = () => {
|
|
1245
|
-
document.hidden && this.close();
|
|
1246
|
-
};
|
|
1247
1930
|
};
|
|
1248
1931
|
//#endregion
|
|
1249
|
-
export {
|
|
1932
|
+
export { u as MODAL_MOBILE_BREAKPOINT, j as Optgroup, A as Option, d as Settings, z as default };
|
|
1250
1933
|
|
|
1251
1934
|
//# sourceMappingURL=slimselect.es.js.map
|