@prometa/sleek 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/sleek-select.d.ts +2 -0
- package/dist/components/sleek-select.d.ts.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/sleek-select.cjs +1 -0
- package/dist/sleek-select.js +2555 -0
- package/dist/tom-select.bootstrap5.css +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,2555 @@
|
|
|
1
|
+
var Je = Object.defineProperty;
|
|
2
|
+
var Oe = (s) => {
|
|
3
|
+
throw TypeError(s);
|
|
4
|
+
};
|
|
5
|
+
var We = (s, e, t) => e in s ? Je(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
6
|
+
var N = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t), ae = (s, e, t) => e.has(s) || Oe("Cannot " + t);
|
|
7
|
+
var x = (s, e, t) => (ae(s, e, "read from private field"), t ? t.call(s) : e.get(s)), K = (s, e, t) => e.has(s) ? Oe("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), H = (s, e, t, i) => (ae(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t), we = (s, e, t) => (ae(s, e, "access private method"), t);
|
|
8
|
+
import { snakeToCamel as Xe } from "./chartjs-chart.js";
|
|
9
|
+
import { t as Ze } from "./utils.js";
|
|
10
|
+
function ce(s, e) {
|
|
11
|
+
s.split(/\s+/).forEach((t) => {
|
|
12
|
+
e(t);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
class et {
|
|
16
|
+
constructor() {
|
|
17
|
+
this._events = {};
|
|
18
|
+
}
|
|
19
|
+
on(e, t) {
|
|
20
|
+
ce(e, (i) => {
|
|
21
|
+
const n = this._events[i] || [];
|
|
22
|
+
n.push(t), this._events[i] = n;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
off(e, t) {
|
|
26
|
+
var i = arguments.length;
|
|
27
|
+
if (i === 0) {
|
|
28
|
+
this._events = {};
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
ce(e, (n) => {
|
|
32
|
+
if (i === 1) {
|
|
33
|
+
delete this._events[n];
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const o = this._events[n];
|
|
37
|
+
o !== void 0 && (o.splice(o.indexOf(t), 1), this._events[n] = o);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
trigger(e, ...t) {
|
|
41
|
+
var i = this;
|
|
42
|
+
ce(e, (n) => {
|
|
43
|
+
const o = i._events[n];
|
|
44
|
+
o !== void 0 && o.forEach((r) => {
|
|
45
|
+
r.apply(i, t);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function tt(s) {
|
|
51
|
+
return s.plugins = {}, class extends s {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments), this.plugins = {
|
|
54
|
+
names: [],
|
|
55
|
+
settings: {},
|
|
56
|
+
requested: {},
|
|
57
|
+
loaded: {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Registers a plugin.
|
|
62
|
+
*
|
|
63
|
+
* @param {function} fn
|
|
64
|
+
*/
|
|
65
|
+
static define(e, t) {
|
|
66
|
+
s.plugins[e] = {
|
|
67
|
+
name: e,
|
|
68
|
+
fn: t
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Initializes the listed plugins (with options).
|
|
73
|
+
* Acceptable formats:
|
|
74
|
+
*
|
|
75
|
+
* List (without options):
|
|
76
|
+
* ['a', 'b', 'c']
|
|
77
|
+
*
|
|
78
|
+
* List (with options):
|
|
79
|
+
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
|
|
80
|
+
*
|
|
81
|
+
* Hash (with options):
|
|
82
|
+
* {'a': { ... }, 'b': { ... }, 'c': { ... }}
|
|
83
|
+
*
|
|
84
|
+
* @param {array|object} plugins
|
|
85
|
+
*/
|
|
86
|
+
initializePlugins(e) {
|
|
87
|
+
var t, i;
|
|
88
|
+
const n = this, o = [];
|
|
89
|
+
if (Array.isArray(e))
|
|
90
|
+
e.forEach((r) => {
|
|
91
|
+
typeof r == "string" ? o.push(r) : (n.plugins.settings[r.name] = r.options, o.push(r.name));
|
|
92
|
+
});
|
|
93
|
+
else if (e)
|
|
94
|
+
for (t in e)
|
|
95
|
+
e.hasOwnProperty(t) && (n.plugins.settings[t] = e[t], o.push(t));
|
|
96
|
+
for (; i = o.shift(); )
|
|
97
|
+
n.require(i);
|
|
98
|
+
}
|
|
99
|
+
loadPlugin(e) {
|
|
100
|
+
var t = this, i = t.plugins, n = s.plugins[e];
|
|
101
|
+
if (!s.plugins.hasOwnProperty(e))
|
|
102
|
+
throw new Error('Unable to find "' + e + '" plugin');
|
|
103
|
+
i.requested[e] = !0, i.loaded[e] = n.fn.apply(t, [t.plugins.settings[e] || {}]), i.names.push(e);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Initializes a plugin.
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
require(e) {
|
|
110
|
+
var t = this, i = t.plugins;
|
|
111
|
+
if (!t.plugins.loaded.hasOwnProperty(e)) {
|
|
112
|
+
if (i.requested[e])
|
|
113
|
+
throw new Error('Plugin has circular dependency ("' + e + '")');
|
|
114
|
+
t.loadPlugin(e);
|
|
115
|
+
}
|
|
116
|
+
return i.loaded[e];
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const le = (s) => (s = s.filter(Boolean), s.length < 2 ? s[0] || "" : it(s) == 1 ? "[" + s.join("") + "]" : "(?:" + s.join("|") + ")"), Ke = (s) => {
|
|
121
|
+
if (!st(s))
|
|
122
|
+
return s.join("");
|
|
123
|
+
let e = "", t = 0;
|
|
124
|
+
const i = () => {
|
|
125
|
+
t > 1 && (e += "{" + t + "}");
|
|
126
|
+
};
|
|
127
|
+
return s.forEach((n, o) => {
|
|
128
|
+
if (n === s[o - 1]) {
|
|
129
|
+
t++;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
i(), e += n, t = 1;
|
|
133
|
+
}), i(), e;
|
|
134
|
+
}, Re = (s) => {
|
|
135
|
+
let e = Array.from(s);
|
|
136
|
+
return le(e);
|
|
137
|
+
}, st = (s) => new Set(s).size !== s.length, G = (s) => (s + "").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu, "\\$1"), it = (s) => s.reduce((e, t) => Math.max(e, nt(t)), 0), nt = (s) => Array.from(s).length, Be = (s) => {
|
|
138
|
+
if (s.length === 1)
|
|
139
|
+
return [[s]];
|
|
140
|
+
let e = [];
|
|
141
|
+
const t = s.substring(1);
|
|
142
|
+
return Be(t).forEach(function(n) {
|
|
143
|
+
let o = n.slice(0);
|
|
144
|
+
o[0] = s.charAt(0) + o[0], e.push(o), o = n.slice(0), o.unshift(s.charAt(0)), e.push(o);
|
|
145
|
+
}), e;
|
|
146
|
+
}, rt = [[0, 65535]], ot = "[̀-ͯ·ʾʼ]";
|
|
147
|
+
let ie, ze;
|
|
148
|
+
const lt = 3, _e = {}, be = {
|
|
149
|
+
"/": "⁄∕",
|
|
150
|
+
0: "߀",
|
|
151
|
+
a: "ⱥɐɑ",
|
|
152
|
+
aa: "ꜳ",
|
|
153
|
+
ae: "æǽǣ",
|
|
154
|
+
ao: "ꜵ",
|
|
155
|
+
au: "ꜷ",
|
|
156
|
+
av: "ꜹꜻ",
|
|
157
|
+
ay: "ꜽ",
|
|
158
|
+
b: "ƀɓƃ",
|
|
159
|
+
c: "ꜿƈȼↄ",
|
|
160
|
+
d: "đɗɖᴅƌꮷԁɦ",
|
|
161
|
+
e: "ɛǝᴇɇ",
|
|
162
|
+
f: "ꝼƒ",
|
|
163
|
+
g: "ǥɠꞡᵹꝿɢ",
|
|
164
|
+
h: "ħⱨⱶɥ",
|
|
165
|
+
i: "ɨı",
|
|
166
|
+
j: "ɉȷ",
|
|
167
|
+
k: "ƙⱪꝁꝃꝅꞣ",
|
|
168
|
+
l: "łƚɫⱡꝉꝇꞁɭ",
|
|
169
|
+
m: "ɱɯϻ",
|
|
170
|
+
n: "ꞥƞɲꞑᴎлԉ",
|
|
171
|
+
o: "øǿɔɵꝋꝍᴑ",
|
|
172
|
+
oe: "œ",
|
|
173
|
+
oi: "ƣ",
|
|
174
|
+
oo: "ꝏ",
|
|
175
|
+
ou: "ȣ",
|
|
176
|
+
p: "ƥᵽꝑꝓꝕρ",
|
|
177
|
+
q: "ꝗꝙɋ",
|
|
178
|
+
r: "ɍɽꝛꞧꞃ",
|
|
179
|
+
s: "ßȿꞩꞅʂ",
|
|
180
|
+
t: "ŧƭʈⱦꞇ",
|
|
181
|
+
th: "þ",
|
|
182
|
+
tz: "ꜩ",
|
|
183
|
+
u: "ʉ",
|
|
184
|
+
v: "ʋꝟʌ",
|
|
185
|
+
vy: "ꝡ",
|
|
186
|
+
w: "ⱳ",
|
|
187
|
+
y: "ƴɏỿ",
|
|
188
|
+
z: "ƶȥɀⱬꝣ",
|
|
189
|
+
hv: "ƕ"
|
|
190
|
+
};
|
|
191
|
+
for (let s in be) {
|
|
192
|
+
let e = be[s] || "";
|
|
193
|
+
for (let t = 0; t < e.length; t++) {
|
|
194
|
+
let i = e.substring(t, t + 1);
|
|
195
|
+
_e[i] = s;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const at = new RegExp(Object.keys(_e).join("|") + "|" + ot, "gu"), ct = (s) => {
|
|
199
|
+
ie === void 0 && (ie = pt(rt));
|
|
200
|
+
}, Ae = (s, e = "NFKD") => s.normalize(e), ne = (s) => Array.from(s).reduce(
|
|
201
|
+
/**
|
|
202
|
+
* @param {string} result
|
|
203
|
+
* @param {string} char
|
|
204
|
+
*/
|
|
205
|
+
(e, t) => e + ut(t),
|
|
206
|
+
""
|
|
207
|
+
), ut = (s) => (s = Ae(s).toLowerCase().replace(at, (e) => _e[e] || ""), Ae(s, "NFC"));
|
|
208
|
+
function* dt(s) {
|
|
209
|
+
for (const [e, t] of s)
|
|
210
|
+
for (let i = e; i <= t; i++) {
|
|
211
|
+
let n = String.fromCharCode(i), o = ne(n);
|
|
212
|
+
o != n.toLowerCase() && (o.length > lt || o.length != 0 && (yield { folded: o, composed: n, code_point: i }));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const ft = (s) => {
|
|
216
|
+
const e = {}, t = (i, n) => {
|
|
217
|
+
const o = e[i] || /* @__PURE__ */ new Set(), r = new RegExp("^" + Re(o) + "$", "iu");
|
|
218
|
+
n.match(r) || (o.add(G(n)), e[i] = o);
|
|
219
|
+
};
|
|
220
|
+
for (let i of dt(s))
|
|
221
|
+
t(i.folded, i.folded), t(i.folded, i.composed);
|
|
222
|
+
return e;
|
|
223
|
+
}, pt = (s) => {
|
|
224
|
+
const e = ft(s), t = {};
|
|
225
|
+
let i = [];
|
|
226
|
+
for (let o in e) {
|
|
227
|
+
let r = e[o];
|
|
228
|
+
r && (t[o] = Re(r)), o.length > 1 && i.push(G(o));
|
|
229
|
+
}
|
|
230
|
+
i.sort((o, r) => r.length - o.length);
|
|
231
|
+
const n = le(i);
|
|
232
|
+
return ze = new RegExp("^" + n, "u"), t;
|
|
233
|
+
}, ht = (s, e = 1) => {
|
|
234
|
+
let t = 0;
|
|
235
|
+
return s = s.map((i) => (ie[i] && (t += i.length), ie[i] || i)), t >= e ? Ke(s) : "";
|
|
236
|
+
}, gt = (s, e = 1) => (e = Math.max(e, s.length - 1), le(Be(s).map((t) => ht(t, e)))), Se = (s, e = !0) => {
|
|
237
|
+
let t = s.length > 1 ? 1 : 0;
|
|
238
|
+
return le(s.map((i) => {
|
|
239
|
+
let n = [];
|
|
240
|
+
const o = e ? i.length() : i.length() - 1;
|
|
241
|
+
for (let r = 0; r < o; r++)
|
|
242
|
+
n.push(gt(i.substrs[r] || "", t));
|
|
243
|
+
return Ke(n);
|
|
244
|
+
}));
|
|
245
|
+
}, mt = (s, e) => {
|
|
246
|
+
for (const t of e) {
|
|
247
|
+
if (t.start != s.start || t.end != s.end || t.substrs.join("") !== s.substrs.join(""))
|
|
248
|
+
continue;
|
|
249
|
+
let i = s.parts;
|
|
250
|
+
const n = (r) => {
|
|
251
|
+
for (const l of i) {
|
|
252
|
+
if (l.start === r.start && l.substr === r.substr)
|
|
253
|
+
return !1;
|
|
254
|
+
if (!(r.length == 1 || l.length == 1) && (r.start < l.start && r.end > l.start || l.start < r.start && l.end > r.start))
|
|
255
|
+
return !0;
|
|
256
|
+
}
|
|
257
|
+
return !1;
|
|
258
|
+
};
|
|
259
|
+
if (!(t.parts.filter(n).length > 0))
|
|
260
|
+
return !0;
|
|
261
|
+
}
|
|
262
|
+
return !1;
|
|
263
|
+
};
|
|
264
|
+
class re {
|
|
265
|
+
constructor() {
|
|
266
|
+
N(this, "parts");
|
|
267
|
+
N(this, "substrs");
|
|
268
|
+
N(this, "start");
|
|
269
|
+
N(this, "end");
|
|
270
|
+
this.parts = [], this.substrs = [], this.start = 0, this.end = 0;
|
|
271
|
+
}
|
|
272
|
+
add(e) {
|
|
273
|
+
e && (this.parts.push(e), this.substrs.push(e.substr), this.start = Math.min(e.start, this.start), this.end = Math.max(e.end, this.end));
|
|
274
|
+
}
|
|
275
|
+
last() {
|
|
276
|
+
return this.parts[this.parts.length - 1];
|
|
277
|
+
}
|
|
278
|
+
length() {
|
|
279
|
+
return this.parts.length;
|
|
280
|
+
}
|
|
281
|
+
clone(e, t) {
|
|
282
|
+
let i = new re(), n = JSON.parse(JSON.stringify(this.parts)), o = n.pop();
|
|
283
|
+
for (const c of n)
|
|
284
|
+
i.add(c);
|
|
285
|
+
let r = t.substr.substring(0, e - o.start), l = r.length;
|
|
286
|
+
return i.add({ start: o.start, end: o.start + l, length: l, substr: r }), i;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const vt = (s) => {
|
|
290
|
+
ct(), s = ne(s);
|
|
291
|
+
let e = "", t = [new re()];
|
|
292
|
+
for (let i = 0; i < s.length; i++) {
|
|
293
|
+
let o = s.substring(i).match(ze);
|
|
294
|
+
const r = s.substring(i, i + 1), l = o ? o[0] : null;
|
|
295
|
+
let c = [], a = /* @__PURE__ */ new Set();
|
|
296
|
+
for (const u of t) {
|
|
297
|
+
const d = u.last();
|
|
298
|
+
if (!d || d.length == 1 || d.end <= i)
|
|
299
|
+
if (l) {
|
|
300
|
+
const p = l.length;
|
|
301
|
+
u.add({ start: i, end: i + p, length: p, substr: l }), a.add("1");
|
|
302
|
+
} else
|
|
303
|
+
u.add({ start: i, end: i + 1, length: 1, substr: r }), a.add("2");
|
|
304
|
+
else if (l) {
|
|
305
|
+
let p = u.clone(i, d);
|
|
306
|
+
const w = l.length;
|
|
307
|
+
p.add({ start: i, end: i + w, length: w, substr: l }), c.push(p);
|
|
308
|
+
} else
|
|
309
|
+
a.add("3");
|
|
310
|
+
}
|
|
311
|
+
if (c.length > 0) {
|
|
312
|
+
c = c.sort((u, d) => u.length() - d.length());
|
|
313
|
+
for (let u of c)
|
|
314
|
+
mt(u, t) || t.push(u);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (i > 0 && a.size == 1 && !a.has("3")) {
|
|
318
|
+
e += Se(t, !1);
|
|
319
|
+
let u = new re();
|
|
320
|
+
const d = t[0];
|
|
321
|
+
d && u.add(d.last()), t = [u];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return e += Se(t, !0), e;
|
|
325
|
+
}, _t = (s, e) => {
|
|
326
|
+
if (s)
|
|
327
|
+
return s[e];
|
|
328
|
+
}, yt = (s, e) => {
|
|
329
|
+
if (s) {
|
|
330
|
+
for (var t, i = e.split("."); (t = i.shift()) && (s = s[t]); )
|
|
331
|
+
;
|
|
332
|
+
return s;
|
|
333
|
+
}
|
|
334
|
+
}, ue = (s, e, t) => {
|
|
335
|
+
var i, n;
|
|
336
|
+
return !s || (s = s + "", e.regex == null) || (n = s.search(e.regex), n === -1) ? 0 : (i = e.string.length / s.length, n === 0 && (i += 0.5), i * t);
|
|
337
|
+
}, de = (s, e) => {
|
|
338
|
+
var t = s[e];
|
|
339
|
+
if (typeof t == "function")
|
|
340
|
+
return t;
|
|
341
|
+
t && !Array.isArray(t) && (s[e] = [t]);
|
|
342
|
+
}, X = (s, e) => {
|
|
343
|
+
if (Array.isArray(s))
|
|
344
|
+
s.forEach(e);
|
|
345
|
+
else
|
|
346
|
+
for (var t in s)
|
|
347
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
348
|
+
}, Ot = (s, e) => typeof s == "number" && typeof e == "number" ? s > e ? 1 : s < e ? -1 : 0 : (s = ne(s + "").toLowerCase(), e = ne(e + "").toLowerCase(), s > e ? 1 : e > s ? -1 : 0);
|
|
349
|
+
class wt {
|
|
350
|
+
/**
|
|
351
|
+
* Textually searches arrays and hashes of objects
|
|
352
|
+
* by property (or multiple properties). Designed
|
|
353
|
+
* specifically for autocomplete.
|
|
354
|
+
*
|
|
355
|
+
*/
|
|
356
|
+
constructor(e, t) {
|
|
357
|
+
N(this, "items");
|
|
358
|
+
// []|{};
|
|
359
|
+
N(this, "settings");
|
|
360
|
+
this.items = e, this.settings = t || { diacritics: !0 };
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Splits a search string into an array of individual
|
|
364
|
+
* regexps to be used to match results.
|
|
365
|
+
*
|
|
366
|
+
*/
|
|
367
|
+
tokenize(e, t, i) {
|
|
368
|
+
if (!e || !e.length)
|
|
369
|
+
return [];
|
|
370
|
+
const n = [], o = e.split(/\s+/);
|
|
371
|
+
var r;
|
|
372
|
+
return i && (r = new RegExp("^(" + Object.keys(i).map(G).join("|") + "):(.*)$")), o.forEach((l) => {
|
|
373
|
+
let c, a = null, u = null;
|
|
374
|
+
r && (c = l.match(r)) && (a = c[1], l = c[2]), l.length > 0 && (this.settings.diacritics ? u = vt(l) || null : u = G(l), u && t && (u = "\\b" + u)), n.push({
|
|
375
|
+
string: l,
|
|
376
|
+
regex: u ? new RegExp(u, "iu") : null,
|
|
377
|
+
field: a
|
|
378
|
+
});
|
|
379
|
+
}), n;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Returns a function to be used to score individual results.
|
|
383
|
+
*
|
|
384
|
+
* Good matches will have a higher score than poor matches.
|
|
385
|
+
* If an item is not a match, 0 will be returned by the function.
|
|
386
|
+
*
|
|
387
|
+
* @returns {T.ScoreFn}
|
|
388
|
+
*/
|
|
389
|
+
getScoreFunction(e, t) {
|
|
390
|
+
var i = this.prepareSearch(e, t);
|
|
391
|
+
return this._getScoreFunction(i);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* @returns {T.ScoreFn}
|
|
395
|
+
*
|
|
396
|
+
*/
|
|
397
|
+
_getScoreFunction(e) {
|
|
398
|
+
const t = e.tokens, i = t.length;
|
|
399
|
+
if (!i)
|
|
400
|
+
return function() {
|
|
401
|
+
return 0;
|
|
402
|
+
};
|
|
403
|
+
const n = e.options.fields, o = e.weights, r = n.length, l = e.getAttrFn;
|
|
404
|
+
if (!r)
|
|
405
|
+
return function() {
|
|
406
|
+
return 1;
|
|
407
|
+
};
|
|
408
|
+
const c = /* @__PURE__ */ function() {
|
|
409
|
+
return r === 1 ? function(a, u) {
|
|
410
|
+
const d = n[0].field;
|
|
411
|
+
return ue(l(u, d), a, o[d] || 1);
|
|
412
|
+
} : function(a, u) {
|
|
413
|
+
var d = 0;
|
|
414
|
+
if (a.field) {
|
|
415
|
+
const p = l(u, a.field);
|
|
416
|
+
!a.regex && p ? d += 1 / r : d += ue(p, a, 1);
|
|
417
|
+
} else
|
|
418
|
+
X(o, (p, w) => {
|
|
419
|
+
d += ue(l(u, w), a, p);
|
|
420
|
+
});
|
|
421
|
+
return d / r;
|
|
422
|
+
};
|
|
423
|
+
}();
|
|
424
|
+
return i === 1 ? function(a) {
|
|
425
|
+
return c(t[0], a);
|
|
426
|
+
} : e.options.conjunction === "and" ? function(a) {
|
|
427
|
+
var u, d = 0;
|
|
428
|
+
for (let p of t) {
|
|
429
|
+
if (u = c(p, a), u <= 0)
|
|
430
|
+
return 0;
|
|
431
|
+
d += u;
|
|
432
|
+
}
|
|
433
|
+
return d / i;
|
|
434
|
+
} : function(a) {
|
|
435
|
+
var u = 0;
|
|
436
|
+
return X(t, (d) => {
|
|
437
|
+
u += c(d, a);
|
|
438
|
+
}), u / i;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Returns a function that can be used to compare two
|
|
443
|
+
* results, for sorting purposes. If no sorting should
|
|
444
|
+
* be performed, `null` will be returned.
|
|
445
|
+
*
|
|
446
|
+
* @return function(a,b)
|
|
447
|
+
*/
|
|
448
|
+
getSortFunction(e, t) {
|
|
449
|
+
var i = this.prepareSearch(e, t);
|
|
450
|
+
return this._getSortFunction(i);
|
|
451
|
+
}
|
|
452
|
+
_getSortFunction(e) {
|
|
453
|
+
var t, i = [];
|
|
454
|
+
const n = this, o = e.options, r = !e.query && o.sort_empty ? o.sort_empty : o.sort;
|
|
455
|
+
if (typeof r == "function")
|
|
456
|
+
return r.bind(this);
|
|
457
|
+
const l = function(a, u) {
|
|
458
|
+
return a === "$score" ? u.score : e.getAttrFn(n.items[u.id], a);
|
|
459
|
+
};
|
|
460
|
+
if (r)
|
|
461
|
+
for (let a of r)
|
|
462
|
+
(e.query || a.field !== "$score") && i.push(a);
|
|
463
|
+
if (e.query) {
|
|
464
|
+
t = !0;
|
|
465
|
+
for (let a of i)
|
|
466
|
+
if (a.field === "$score") {
|
|
467
|
+
t = !1;
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
t && i.unshift({ field: "$score", direction: "desc" });
|
|
471
|
+
} else
|
|
472
|
+
i = i.filter((a) => a.field !== "$score");
|
|
473
|
+
return i.length ? function(a, u) {
|
|
474
|
+
var d, p;
|
|
475
|
+
for (let w of i)
|
|
476
|
+
if (p = w.field, d = (w.direction === "desc" ? -1 : 1) * Ot(l(p, a), l(p, u)), d)
|
|
477
|
+
return d;
|
|
478
|
+
return 0;
|
|
479
|
+
} : null;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Parses a search query and returns an object
|
|
483
|
+
* with tokens and fields ready to be populated
|
|
484
|
+
* with results.
|
|
485
|
+
*
|
|
486
|
+
*/
|
|
487
|
+
prepareSearch(e, t) {
|
|
488
|
+
const i = {};
|
|
489
|
+
var n = Object.assign({}, t);
|
|
490
|
+
if (de(n, "sort"), de(n, "sort_empty"), n.fields) {
|
|
491
|
+
de(n, "fields");
|
|
492
|
+
const o = [];
|
|
493
|
+
n.fields.forEach((r) => {
|
|
494
|
+
typeof r == "string" && (r = { field: r, weight: 1 }), o.push(r), i[r.field] = "weight" in r ? r.weight : 1;
|
|
495
|
+
}), n.fields = o;
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
options: n,
|
|
499
|
+
query: e.toLowerCase().trim(),
|
|
500
|
+
tokens: this.tokenize(e, n.respect_word_boundaries, i),
|
|
501
|
+
total: 0,
|
|
502
|
+
items: [],
|
|
503
|
+
weights: i,
|
|
504
|
+
getAttrFn: n.nesting ? yt : _t
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Searches through all items and returns a sorted array of matches.
|
|
509
|
+
*
|
|
510
|
+
*/
|
|
511
|
+
search(e, t) {
|
|
512
|
+
var i = this, n, o;
|
|
513
|
+
o = this.prepareSearch(e, t), t = o.options, e = o.query;
|
|
514
|
+
const r = t.score || i._getScoreFunction(o);
|
|
515
|
+
e.length ? X(i.items, (c, a) => {
|
|
516
|
+
n = r(c), (t.filter === !1 || n > 0) && o.items.push({ score: n, id: a });
|
|
517
|
+
}) : X(i.items, (c, a) => {
|
|
518
|
+
o.items.push({ score: 1, id: a });
|
|
519
|
+
});
|
|
520
|
+
const l = i._getSortFunction(o);
|
|
521
|
+
return l && o.items.sort(l), o.total = o.items.length, typeof t.limit == "number" && (o.items = o.items.slice(0, t.limit)), o;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const T = (s) => typeof s > "u" || s === null ? null : se(s), se = (s) => typeof s == "boolean" ? s ? "1" : "0" : s + "", fe = (s) => (s + "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), bt = (s, e) => e > 0 ? window.setTimeout(s, e) : (s.call(null), null), At = (s, e) => {
|
|
525
|
+
var t;
|
|
526
|
+
return function(i, n) {
|
|
527
|
+
var o = this;
|
|
528
|
+
t && (o.loading = Math.max(o.loading - 1, 0), clearTimeout(t)), t = setTimeout(function() {
|
|
529
|
+
t = null, o.loadedSearches[i] = !0, s.call(o, i, n);
|
|
530
|
+
}, e);
|
|
531
|
+
};
|
|
532
|
+
}, Ce = (s, e, t) => {
|
|
533
|
+
var i, n = s.trigger, o = {};
|
|
534
|
+
s.trigger = function() {
|
|
535
|
+
var r = arguments[0];
|
|
536
|
+
if (e.indexOf(r) !== -1)
|
|
537
|
+
o[r] = arguments;
|
|
538
|
+
else
|
|
539
|
+
return n.apply(s, arguments);
|
|
540
|
+
}, t.apply(s, []), s.trigger = n;
|
|
541
|
+
for (i of e)
|
|
542
|
+
i in o && n.apply(s, o[i]);
|
|
543
|
+
}, St = (s) => ({
|
|
544
|
+
start: s.selectionStart || 0,
|
|
545
|
+
length: (s.selectionEnd || 0) - (s.selectionStart || 0)
|
|
546
|
+
}), C = (s, e = !1) => {
|
|
547
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
548
|
+
}, L = (s, e, t, i) => {
|
|
549
|
+
s.addEventListener(e, t, i);
|
|
550
|
+
}, R = (s, e) => {
|
|
551
|
+
if (!e || !e[s])
|
|
552
|
+
return !1;
|
|
553
|
+
var t = (e.altKey ? 1 : 0) + (e.ctrlKey ? 1 : 0) + (e.shiftKey ? 1 : 0) + (e.metaKey ? 1 : 0);
|
|
554
|
+
return t === 1;
|
|
555
|
+
}, pe = (s, e) => {
|
|
556
|
+
const t = s.getAttribute("id");
|
|
557
|
+
return t || (s.setAttribute("id", e), e);
|
|
558
|
+
}, xe = (s) => s.replace(/[\\"']/g, "\\$&"), B = (s, e) => {
|
|
559
|
+
e && s.append(e);
|
|
560
|
+
}, I = (s, e) => {
|
|
561
|
+
if (Array.isArray(s))
|
|
562
|
+
s.forEach(e);
|
|
563
|
+
else
|
|
564
|
+
for (var t in s)
|
|
565
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
566
|
+
}, D = (s) => {
|
|
567
|
+
if (s.jquery)
|
|
568
|
+
return s[0];
|
|
569
|
+
if (s instanceof HTMLElement)
|
|
570
|
+
return s;
|
|
571
|
+
if (je(s)) {
|
|
572
|
+
var e = document.createElement("template");
|
|
573
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
574
|
+
}
|
|
575
|
+
return document.querySelector(s);
|
|
576
|
+
}, je = (s) => typeof s == "string" && s.indexOf("<") > -1, Ct = (s) => s.replace(/['"\\]/g, "\\$&"), he = (s, e) => {
|
|
577
|
+
var t = document.createEvent("HTMLEvents");
|
|
578
|
+
t.initEvent(e, !0, !1), s.dispatchEvent(t);
|
|
579
|
+
}, Z = (s, e) => {
|
|
580
|
+
Object.assign(s.style, e);
|
|
581
|
+
}, k = (s, ...e) => {
|
|
582
|
+
var t = Ye(e);
|
|
583
|
+
s = Qe(s), s.map((i) => {
|
|
584
|
+
t.map((n) => {
|
|
585
|
+
i.classList.add(n);
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
}, M = (s, ...e) => {
|
|
589
|
+
var t = Ye(e);
|
|
590
|
+
s = Qe(s), s.map((i) => {
|
|
591
|
+
t.map((n) => {
|
|
592
|
+
i.classList.remove(n);
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
}, Ye = (s) => {
|
|
596
|
+
var e = [];
|
|
597
|
+
return I(s, (t) => {
|
|
598
|
+
typeof t == "string" && (t = t.trim().split(/[\t\n\f\r\s]/)), Array.isArray(t) && (e = e.concat(t));
|
|
599
|
+
}), e.filter(Boolean);
|
|
600
|
+
}, Qe = (s) => (Array.isArray(s) || (s = [s]), s), ge = (s, e, t) => {
|
|
601
|
+
if (!(t && !t.contains(s)))
|
|
602
|
+
for (; s && s.matches; ) {
|
|
603
|
+
if (s.matches(e))
|
|
604
|
+
return s;
|
|
605
|
+
s = s.parentNode;
|
|
606
|
+
}
|
|
607
|
+
}, Ie = (s, e = 0) => e > 0 ? s[s.length - 1] : s[0], xt = (s) => Object.keys(s).length === 0, Ee = (s, e) => {
|
|
608
|
+
if (!s)
|
|
609
|
+
return -1;
|
|
610
|
+
e = e || s.nodeName;
|
|
611
|
+
for (var t = 0; s = s.previousElementSibling; )
|
|
612
|
+
s.matches(e) && t++;
|
|
613
|
+
return t;
|
|
614
|
+
}, A = (s, e) => {
|
|
615
|
+
I(e, (t, i) => {
|
|
616
|
+
t == null ? s.removeAttribute(i) : s.setAttribute(i, "" + t);
|
|
617
|
+
});
|
|
618
|
+
}, me = (s, e) => {
|
|
619
|
+
s.parentNode && s.parentNode.replaceChild(e, s);
|
|
620
|
+
}, It = (s, e) => {
|
|
621
|
+
if (e === null)
|
|
622
|
+
return;
|
|
623
|
+
if (typeof e == "string") {
|
|
624
|
+
if (!e.length)
|
|
625
|
+
return;
|
|
626
|
+
e = new RegExp(e, "i");
|
|
627
|
+
}
|
|
628
|
+
const t = (o) => {
|
|
629
|
+
var r = o.data.match(e);
|
|
630
|
+
if (r && o.data.length > 0) {
|
|
631
|
+
var l = document.createElement("span");
|
|
632
|
+
l.className = "highlight";
|
|
633
|
+
var c = o.splitText(r.index);
|
|
634
|
+
c.splitText(r[0].length);
|
|
635
|
+
var a = c.cloneNode(!0);
|
|
636
|
+
return l.appendChild(a), me(c, l), 1;
|
|
637
|
+
}
|
|
638
|
+
return 0;
|
|
639
|
+
}, i = (o) => {
|
|
640
|
+
o.nodeType === 1 && o.childNodes && !/(script|style)/i.test(o.tagName) && (o.className !== "highlight" || o.tagName !== "SPAN") && Array.from(o.childNodes).forEach((r) => {
|
|
641
|
+
n(r);
|
|
642
|
+
});
|
|
643
|
+
}, n = (o) => o.nodeType === 3 ? t(o) : (i(o), 0);
|
|
644
|
+
n(s);
|
|
645
|
+
}, Et = (s) => {
|
|
646
|
+
var e = s.querySelectorAll("span.highlight");
|
|
647
|
+
Array.prototype.forEach.call(e, function(t) {
|
|
648
|
+
var i = t.parentNode;
|
|
649
|
+
i.replaceChild(t.firstChild, t), i.normalize();
|
|
650
|
+
});
|
|
651
|
+
}, Lt = 65, Ft = 13, kt = 27, $t = 37, Tt = 38, Pt = 39, Dt = 40, Le = 8, Ht = 46, Fe = 9, Mt = typeof navigator > "u" ? !1 : /Mac/.test(navigator.userAgent), ee = Mt ? "metaKey" : "ctrlKey", ke = {
|
|
652
|
+
options: [],
|
|
653
|
+
optgroups: [],
|
|
654
|
+
plugins: [],
|
|
655
|
+
delimiter: ",",
|
|
656
|
+
splitOn: null,
|
|
657
|
+
// regexp or string for splitting up values from a paste command
|
|
658
|
+
persist: !0,
|
|
659
|
+
diacritics: !0,
|
|
660
|
+
create: null,
|
|
661
|
+
createOnBlur: !1,
|
|
662
|
+
createFilter: null,
|
|
663
|
+
highlight: !0,
|
|
664
|
+
openOnFocus: !0,
|
|
665
|
+
shouldOpen: null,
|
|
666
|
+
maxOptions: 50,
|
|
667
|
+
maxItems: null,
|
|
668
|
+
hideSelected: null,
|
|
669
|
+
duplicates: !1,
|
|
670
|
+
addPrecedence: !1,
|
|
671
|
+
selectOnTab: !1,
|
|
672
|
+
preload: null,
|
|
673
|
+
allowEmptyOption: !1,
|
|
674
|
+
//closeAfterSelect: false,
|
|
675
|
+
refreshThrottle: 300,
|
|
676
|
+
loadThrottle: 300,
|
|
677
|
+
loadingClass: "loading",
|
|
678
|
+
dataAttr: null,
|
|
679
|
+
//'data-data',
|
|
680
|
+
optgroupField: "optgroup",
|
|
681
|
+
valueField: "value",
|
|
682
|
+
labelField: "text",
|
|
683
|
+
disabledField: "disabled",
|
|
684
|
+
optgroupLabelField: "label",
|
|
685
|
+
optgroupValueField: "value",
|
|
686
|
+
lockOptgroupOrder: !1,
|
|
687
|
+
sortField: "$order",
|
|
688
|
+
searchField: ["text"],
|
|
689
|
+
searchConjunction: "and",
|
|
690
|
+
mode: null,
|
|
691
|
+
wrapperClass: "ts-wrapper",
|
|
692
|
+
controlClass: "ts-control",
|
|
693
|
+
dropdownClass: "ts-dropdown",
|
|
694
|
+
dropdownContentClass: "ts-dropdown-content",
|
|
695
|
+
itemClass: "item",
|
|
696
|
+
optionClass: "option",
|
|
697
|
+
dropdownParent: null,
|
|
698
|
+
controlInput: '<input type="text" autocomplete="off" size="1" />',
|
|
699
|
+
copyClassesToDropdown: !1,
|
|
700
|
+
placeholder: null,
|
|
701
|
+
hidePlaceholder: null,
|
|
702
|
+
shouldLoad: function(s) {
|
|
703
|
+
return s.length > 0;
|
|
704
|
+
},
|
|
705
|
+
/*
|
|
706
|
+
load : null, // function(query, callback) { ... }
|
|
707
|
+
score : null, // function(search) { ... }
|
|
708
|
+
onInitialize : null, // function() { ... }
|
|
709
|
+
onChange : null, // function(value) { ... }
|
|
710
|
+
onItemAdd : null, // function(value, $item) { ... }
|
|
711
|
+
onItemRemove : null, // function(value) { ... }
|
|
712
|
+
onClear : null, // function() { ... }
|
|
713
|
+
onOptionAdd : null, // function(value, data) { ... }
|
|
714
|
+
onOptionRemove : null, // function(value) { ... }
|
|
715
|
+
onOptionClear : null, // function() { ... }
|
|
716
|
+
onOptionGroupAdd : null, // function(id, data) { ... }
|
|
717
|
+
onOptionGroupRemove : null, // function(id) { ... }
|
|
718
|
+
onOptionGroupClear : null, // function() { ... }
|
|
719
|
+
onDropdownOpen : null, // function(dropdown) { ... }
|
|
720
|
+
onDropdownClose : null, // function(dropdown) { ... }
|
|
721
|
+
onType : null, // function(str) { ... }
|
|
722
|
+
onDelete : null, // function(values) { ... }
|
|
723
|
+
*/
|
|
724
|
+
render: {
|
|
725
|
+
/*
|
|
726
|
+
item: null,
|
|
727
|
+
optgroup: null,
|
|
728
|
+
optgroup_header: null,
|
|
729
|
+
option: null,
|
|
730
|
+
option_create: null
|
|
731
|
+
*/
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
function $e(s, e) {
|
|
735
|
+
var t = Object.assign({}, ke, e), i = t.dataAttr, n = t.labelField, o = t.valueField, r = t.disabledField, l = t.optgroupField, c = t.optgroupLabelField, a = t.optgroupValueField, u = s.tagName.toLowerCase(), d = s.getAttribute("placeholder") || s.getAttribute("data-placeholder");
|
|
736
|
+
if (!d && !t.allowEmptyOption) {
|
|
737
|
+
let v = s.querySelector('option[value=""]');
|
|
738
|
+
v && (d = v.textContent);
|
|
739
|
+
}
|
|
740
|
+
var p = {
|
|
741
|
+
placeholder: d,
|
|
742
|
+
options: [],
|
|
743
|
+
optgroups: [],
|
|
744
|
+
items: [],
|
|
745
|
+
maxItems: null
|
|
746
|
+
}, w = () => {
|
|
747
|
+
var v, b = p.options, y = {}, h = 1;
|
|
748
|
+
let S = 0;
|
|
749
|
+
var P = (m) => {
|
|
750
|
+
var _ = Object.assign({}, m.dataset), g = i && _[i];
|
|
751
|
+
return typeof g == "string" && g.length && (_ = Object.assign(_, JSON.parse(g))), _;
|
|
752
|
+
}, q = (m, _) => {
|
|
753
|
+
var g = T(m.value);
|
|
754
|
+
if (g != null && !(!g && !t.allowEmptyOption)) {
|
|
755
|
+
if (y.hasOwnProperty(g)) {
|
|
756
|
+
if (_) {
|
|
757
|
+
var E = y[g][l];
|
|
758
|
+
E ? Array.isArray(E) ? E.push(_) : y[g][l] = [E, _] : y[g][l] = _;
|
|
759
|
+
}
|
|
760
|
+
} else {
|
|
761
|
+
var O = P(m);
|
|
762
|
+
O[n] = O[n] || m.textContent, O[o] = O[o] || g, O[r] = O[r] || m.disabled, O[l] = O[l] || _, O.$option = m, O.$order = O.$order || ++S, y[g] = O, b.push(O);
|
|
763
|
+
}
|
|
764
|
+
m.selected && p.items.push(g);
|
|
765
|
+
}
|
|
766
|
+
}, j = (m) => {
|
|
767
|
+
var _, g;
|
|
768
|
+
g = P(m), g[c] = g[c] || m.getAttribute("label") || "", g[a] = g[a] || h++, g[r] = g[r] || m.disabled, g.$order = g.$order || ++S, p.optgroups.push(g), _ = g[a], I(m.children, (E) => {
|
|
769
|
+
q(E, _);
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
p.maxItems = s.hasAttribute("multiple") ? null : 1, I(s.children, (m) => {
|
|
773
|
+
v = m.tagName.toLowerCase(), v === "optgroup" ? j(m) : v === "option" && q(m);
|
|
774
|
+
});
|
|
775
|
+
}, f = () => {
|
|
776
|
+
const v = s.getAttribute(i);
|
|
777
|
+
if (v)
|
|
778
|
+
p.options = JSON.parse(v), I(p.options, (y) => {
|
|
779
|
+
p.items.push(y[o]);
|
|
780
|
+
});
|
|
781
|
+
else {
|
|
782
|
+
var b = s.value.trim() || "";
|
|
783
|
+
if (!t.allowEmptyOption && !b.length)
|
|
784
|
+
return;
|
|
785
|
+
const y = b.split(t.delimiter);
|
|
786
|
+
I(y, (h) => {
|
|
787
|
+
const S = {};
|
|
788
|
+
S[n] = h, S[o] = h, p.options.push(S);
|
|
789
|
+
}), p.items = y;
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
return u === "select" ? w() : f(), Object.assign({}, ke, p, e);
|
|
793
|
+
}
|
|
794
|
+
var Te = 0;
|
|
795
|
+
class F extends tt(et) {
|
|
796
|
+
constructor(e, t) {
|
|
797
|
+
super(), this.order = 0, this.isOpen = !1, this.isDisabled = !1, this.isReadOnly = !1, this.isInvalid = !1, this.isValid = !0, this.isLocked = !1, this.isFocused = !1, this.isInputHidden = !1, this.isSetup = !1, this.ignoreFocus = !1, this.ignoreHover = !1, this.hasOptions = !1, this.lastValue = "", this.caretPos = 0, this.loading = 0, this.loadedSearches = {}, this.activeOption = null, this.activeItems = [], this.optgroups = {}, this.options = {}, this.userOptions = {}, this.items = [], this.refreshTimeout = null, Te++;
|
|
798
|
+
var i, n = D(e);
|
|
799
|
+
if (n.tomselect)
|
|
800
|
+
throw new Error("Tom Select already initialized on this element");
|
|
801
|
+
n.tomselect = this;
|
|
802
|
+
var o = window.getComputedStyle && window.getComputedStyle(n, null);
|
|
803
|
+
i = o.getPropertyValue("direction");
|
|
804
|
+
const r = $e(n, t);
|
|
805
|
+
this.settings = r, this.input = n, this.tabIndex = n.tabIndex || 0, this.is_select_tag = n.tagName.toLowerCase() === "select", this.rtl = /rtl/i.test(i), this.inputId = pe(n, "tomselect-" + Te), this.isRequired = n.required, this.sifter = new wt(this.options, { diacritics: r.diacritics }), r.mode = r.mode || (r.maxItems === 1 ? "single" : "multi"), typeof r.hideSelected != "boolean" && (r.hideSelected = r.mode === "multi"), typeof r.hidePlaceholder != "boolean" && (r.hidePlaceholder = r.mode !== "multi");
|
|
806
|
+
var l = r.createFilter;
|
|
807
|
+
typeof l != "function" && (typeof l == "string" && (l = new RegExp(l)), l instanceof RegExp ? r.createFilter = (b) => l.test(b) : r.createFilter = (b) => this.settings.duplicates || !this.options[b]), this.initializePlugins(r.plugins), this.setupCallbacks(), this.setupTemplates();
|
|
808
|
+
const c = D("<div>"), a = D("<div>"), u = this._render("dropdown"), d = D('<div role="listbox" tabindex="-1">'), p = this.input.getAttribute("class") || "", w = r.mode;
|
|
809
|
+
var f;
|
|
810
|
+
if (k(c, r.wrapperClass, p, w), k(a, r.controlClass), B(c, a), k(u, r.dropdownClass, w), r.copyClassesToDropdown && k(u, p), k(d, r.dropdownContentClass), B(u, d), D(r.dropdownParent || c).appendChild(u), je(r.controlInput)) {
|
|
811
|
+
f = D(r.controlInput);
|
|
812
|
+
var v = ["autocorrect", "autocapitalize", "autocomplete", "spellcheck"];
|
|
813
|
+
I(v, (b) => {
|
|
814
|
+
n.getAttribute(b) && A(f, { [b]: n.getAttribute(b) });
|
|
815
|
+
}), f.tabIndex = -1, a.appendChild(f), this.focus_node = f;
|
|
816
|
+
} else r.controlInput ? (f = D(r.controlInput), this.focus_node = f) : (f = D("<input/>"), this.focus_node = a);
|
|
817
|
+
this.wrapper = c, this.dropdown = u, this.dropdown_content = d, this.control = a, this.control_input = f, this.setup();
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* set up event bindings.
|
|
821
|
+
*
|
|
822
|
+
*/
|
|
823
|
+
setup() {
|
|
824
|
+
const e = this, t = e.settings, i = e.control_input, n = e.dropdown, o = e.dropdown_content, r = e.wrapper, l = e.control, c = e.input, a = e.focus_node, u = { passive: !0 }, d = e.inputId + "-ts-dropdown";
|
|
825
|
+
A(o, {
|
|
826
|
+
id: d
|
|
827
|
+
}), A(a, {
|
|
828
|
+
role: "combobox",
|
|
829
|
+
"aria-haspopup": "listbox",
|
|
830
|
+
"aria-expanded": "false",
|
|
831
|
+
"aria-controls": d
|
|
832
|
+
});
|
|
833
|
+
const p = pe(a, e.inputId + "-ts-control"), w = "label[for='" + Ct(e.inputId) + "']", f = document.querySelector(w), v = e.focus.bind(e);
|
|
834
|
+
if (f) {
|
|
835
|
+
L(f, "click", v), A(f, { for: p });
|
|
836
|
+
const h = pe(f, e.inputId + "-ts-label");
|
|
837
|
+
A(a, { "aria-labelledby": h }), A(o, { "aria-labelledby": h });
|
|
838
|
+
}
|
|
839
|
+
if (r.style.width = c.style.width, e.plugins.names.length) {
|
|
840
|
+
const h = "plugin-" + e.plugins.names.join(" plugin-");
|
|
841
|
+
k([r, n], h);
|
|
842
|
+
}
|
|
843
|
+
(t.maxItems === null || t.maxItems > 1) && e.is_select_tag && A(c, { multiple: "multiple" }), t.placeholder && A(i, { placeholder: t.placeholder }), !t.splitOn && t.delimiter && (t.splitOn = new RegExp("\\s*" + G(t.delimiter) + "+\\s*")), t.load && t.loadThrottle && (t.load = At(t.load, t.loadThrottle)), L(n, "mousemove", () => {
|
|
844
|
+
e.ignoreHover = !1;
|
|
845
|
+
}), L(n, "mouseenter", (h) => {
|
|
846
|
+
var S = ge(h.target, "[data-selectable]", n);
|
|
847
|
+
S && e.onOptionHover(h, S);
|
|
848
|
+
}, { capture: !0 }), L(n, "click", (h) => {
|
|
849
|
+
const S = ge(h.target, "[data-selectable]");
|
|
850
|
+
S && (e.onOptionSelect(h, S), C(h, !0));
|
|
851
|
+
}), L(l, "click", (h) => {
|
|
852
|
+
var S = ge(h.target, "[data-ts-item]", l);
|
|
853
|
+
if (S && e.onItemSelect(h, S)) {
|
|
854
|
+
C(h, !0);
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
i.value == "" && (e.onClick(), C(h, !0));
|
|
858
|
+
}), L(a, "keydown", (h) => e.onKeyDown(h)), L(i, "keypress", (h) => e.onKeyPress(h)), L(i, "input", (h) => e.onInput(h)), L(a, "blur", (h) => e.onBlur(h)), L(a, "focus", (h) => e.onFocus(h)), L(i, "paste", (h) => e.onPaste(h));
|
|
859
|
+
const b = (h) => {
|
|
860
|
+
const S = h.composedPath()[0];
|
|
861
|
+
if (!r.contains(S) && !n.contains(S)) {
|
|
862
|
+
e.isFocused && e.blur(), e.inputState();
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
S == i && e.isOpen ? h.stopPropagation() : C(h, !0);
|
|
866
|
+
}, y = () => {
|
|
867
|
+
e.isOpen && e.positionDropdown();
|
|
868
|
+
};
|
|
869
|
+
L(document, "mousedown", b), L(window, "scroll", y, u), L(window, "resize", y, u), this._destroy = () => {
|
|
870
|
+
document.removeEventListener("mousedown", b), window.removeEventListener("scroll", y), window.removeEventListener("resize", y), f && f.removeEventListener("click", v);
|
|
871
|
+
}, this.revertSettings = {
|
|
872
|
+
innerHTML: c.innerHTML,
|
|
873
|
+
tabIndex: c.tabIndex
|
|
874
|
+
}, c.tabIndex = -1, c.insertAdjacentElement("afterend", e.wrapper), e.sync(!1), t.items = [], delete t.optgroups, delete t.options, L(c, "invalid", () => {
|
|
875
|
+
e.isValid && (e.isValid = !1, e.isInvalid = !0, e.refreshState());
|
|
876
|
+
}), e.updateOriginalInput(), e.refreshItems(), e.close(!1), e.inputState(), e.isSetup = !0, c.disabled ? e.disable() : c.readOnly ? e.setReadOnly(!0) : e.enable(), e.on("change", this.onChange), k(c, "tomselected", "ts-hidden-accessible"), e.trigger("initialize"), t.preload === !0 && e.preload();
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Register options and optgroups
|
|
880
|
+
*
|
|
881
|
+
*/
|
|
882
|
+
setupOptions(e = [], t = []) {
|
|
883
|
+
this.addOptions(e), I(t, (i) => {
|
|
884
|
+
this.registerOptionGroup(i);
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Sets up default rendering functions.
|
|
889
|
+
*/
|
|
890
|
+
setupTemplates() {
|
|
891
|
+
var e = this, t = e.settings.labelField, i = e.settings.optgroupLabelField, n = {
|
|
892
|
+
optgroup: (o) => {
|
|
893
|
+
let r = document.createElement("div");
|
|
894
|
+
return r.className = "optgroup", r.appendChild(o.options), r;
|
|
895
|
+
},
|
|
896
|
+
optgroup_header: (o, r) => '<div class="optgroup-header">' + r(o[i]) + "</div>",
|
|
897
|
+
option: (o, r) => "<div>" + r(o[t]) + "</div>",
|
|
898
|
+
item: (o, r) => "<div>" + r(o[t]) + "</div>",
|
|
899
|
+
option_create: (o, r) => '<div class="create">Add <strong>' + r(o.input) + "</strong>…</div>",
|
|
900
|
+
no_results: () => '<div class="no-results">No results found</div>',
|
|
901
|
+
loading: () => '<div class="spinner"></div>',
|
|
902
|
+
not_loading: () => {
|
|
903
|
+
},
|
|
904
|
+
dropdown: () => "<div></div>"
|
|
905
|
+
};
|
|
906
|
+
e.settings.render = Object.assign({}, n, e.settings.render);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Maps fired events to callbacks provided
|
|
910
|
+
* in the settings used when creating the control.
|
|
911
|
+
*/
|
|
912
|
+
setupCallbacks() {
|
|
913
|
+
var e, t, i = {
|
|
914
|
+
initialize: "onInitialize",
|
|
915
|
+
change: "onChange",
|
|
916
|
+
item_add: "onItemAdd",
|
|
917
|
+
item_remove: "onItemRemove",
|
|
918
|
+
item_select: "onItemSelect",
|
|
919
|
+
clear: "onClear",
|
|
920
|
+
option_add: "onOptionAdd",
|
|
921
|
+
option_remove: "onOptionRemove",
|
|
922
|
+
option_clear: "onOptionClear",
|
|
923
|
+
optgroup_add: "onOptionGroupAdd",
|
|
924
|
+
optgroup_remove: "onOptionGroupRemove",
|
|
925
|
+
optgroup_clear: "onOptionGroupClear",
|
|
926
|
+
dropdown_open: "onDropdownOpen",
|
|
927
|
+
dropdown_close: "onDropdownClose",
|
|
928
|
+
type: "onType",
|
|
929
|
+
load: "onLoad",
|
|
930
|
+
focus: "onFocus",
|
|
931
|
+
blur: "onBlur"
|
|
932
|
+
};
|
|
933
|
+
for (e in i)
|
|
934
|
+
t = this.settings[i[e]], t && this.on(e, t);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Sync the Tom Select instance with the original input or select
|
|
938
|
+
*
|
|
939
|
+
*/
|
|
940
|
+
sync(e = !0) {
|
|
941
|
+
const t = this, i = e ? $e(t.input, { delimiter: t.settings.delimiter }) : t.settings;
|
|
942
|
+
t.setupOptions(i.options, i.optgroups), t.setValue(i.items || [], !0), t.lastQuery = null;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Triggered when the main control element
|
|
946
|
+
* has a click event.
|
|
947
|
+
*
|
|
948
|
+
*/
|
|
949
|
+
onClick() {
|
|
950
|
+
var e = this;
|
|
951
|
+
if (e.activeItems.length > 0) {
|
|
952
|
+
e.clearActiveItems(), e.focus();
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
e.isFocused && e.isOpen ? e.blur() : e.focus();
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* @deprecated v1.7
|
|
959
|
+
*
|
|
960
|
+
*/
|
|
961
|
+
onMouseDown() {
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Triggered when the value of the control has been changed.
|
|
965
|
+
* This should propagate the event to the original DOM
|
|
966
|
+
* input / select element.
|
|
967
|
+
*/
|
|
968
|
+
onChange() {
|
|
969
|
+
he(this.input, "input"), he(this.input, "change");
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Triggered on <input> paste.
|
|
973
|
+
*
|
|
974
|
+
*/
|
|
975
|
+
onPaste(e) {
|
|
976
|
+
var t = this;
|
|
977
|
+
if (t.isInputHidden || t.isLocked) {
|
|
978
|
+
C(e);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
t.settings.splitOn && setTimeout(() => {
|
|
982
|
+
var i = t.inputValue();
|
|
983
|
+
if (i.match(t.settings.splitOn)) {
|
|
984
|
+
var n = i.trim().split(t.settings.splitOn);
|
|
985
|
+
I(n, (o) => {
|
|
986
|
+
T(o) && (this.options[o] ? t.addItem(o) : t.createItem(o));
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
}, 0);
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Triggered on <input> keypress.
|
|
993
|
+
*
|
|
994
|
+
*/
|
|
995
|
+
onKeyPress(e) {
|
|
996
|
+
var t = this;
|
|
997
|
+
if (t.isLocked) {
|
|
998
|
+
C(e);
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
var i = String.fromCharCode(e.keyCode || e.which);
|
|
1002
|
+
if (t.settings.create && t.settings.mode === "multi" && i === t.settings.delimiter) {
|
|
1003
|
+
t.createItem(), C(e);
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Triggered on <input> keydown.
|
|
1009
|
+
*
|
|
1010
|
+
*/
|
|
1011
|
+
onKeyDown(e) {
|
|
1012
|
+
var t = this;
|
|
1013
|
+
if (t.ignoreHover = !0, t.isLocked) {
|
|
1014
|
+
e.keyCode !== Fe && C(e);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
switch (e.keyCode) {
|
|
1018
|
+
// ctrl+A: select all
|
|
1019
|
+
case Lt:
|
|
1020
|
+
if (R(ee, e) && t.control_input.value == "") {
|
|
1021
|
+
C(e), t.selectAll();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
break;
|
|
1025
|
+
// esc: close dropdown
|
|
1026
|
+
case kt:
|
|
1027
|
+
t.isOpen && (C(e, !0), t.close()), t.clearActiveItems();
|
|
1028
|
+
return;
|
|
1029
|
+
// down: open dropdown or move selection down
|
|
1030
|
+
case Dt:
|
|
1031
|
+
if (!t.isOpen && t.hasOptions)
|
|
1032
|
+
t.open();
|
|
1033
|
+
else if (t.activeOption) {
|
|
1034
|
+
let i = t.getAdjacent(t.activeOption, 1);
|
|
1035
|
+
i && t.setActiveOption(i);
|
|
1036
|
+
}
|
|
1037
|
+
C(e);
|
|
1038
|
+
return;
|
|
1039
|
+
// up: move selection up
|
|
1040
|
+
case Tt:
|
|
1041
|
+
if (t.activeOption) {
|
|
1042
|
+
let i = t.getAdjacent(t.activeOption, -1);
|
|
1043
|
+
i && t.setActiveOption(i);
|
|
1044
|
+
}
|
|
1045
|
+
C(e);
|
|
1046
|
+
return;
|
|
1047
|
+
// return: select active option
|
|
1048
|
+
case Ft:
|
|
1049
|
+
t.canSelect(t.activeOption) ? (t.onOptionSelect(e, t.activeOption), C(e)) : (t.settings.create && t.createItem() || document.activeElement == t.control_input && t.isOpen) && C(e);
|
|
1050
|
+
return;
|
|
1051
|
+
// left: modifiy item selection to the left
|
|
1052
|
+
case $t:
|
|
1053
|
+
t.advanceSelection(-1, e);
|
|
1054
|
+
return;
|
|
1055
|
+
// right: modifiy item selection to the right
|
|
1056
|
+
case Pt:
|
|
1057
|
+
t.advanceSelection(1, e);
|
|
1058
|
+
return;
|
|
1059
|
+
// tab: select active option and/or create item
|
|
1060
|
+
case Fe:
|
|
1061
|
+
t.settings.selectOnTab && (t.canSelect(t.activeOption) && (t.onOptionSelect(e, t.activeOption), C(e)), t.settings.create && t.createItem() && C(e));
|
|
1062
|
+
return;
|
|
1063
|
+
// delete|backspace: delete items
|
|
1064
|
+
case Le:
|
|
1065
|
+
case Ht:
|
|
1066
|
+
t.deleteSelection(e);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
t.isInputHidden && !R(ee, e) && C(e);
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Triggered on <input> keyup.
|
|
1073
|
+
*
|
|
1074
|
+
*/
|
|
1075
|
+
onInput(e) {
|
|
1076
|
+
if (this.isLocked)
|
|
1077
|
+
return;
|
|
1078
|
+
const t = this.inputValue();
|
|
1079
|
+
if (this.lastValue !== t) {
|
|
1080
|
+
if (this.lastValue = t, t == "") {
|
|
1081
|
+
this._onInput();
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
this.refreshTimeout && window.clearTimeout(this.refreshTimeout), this.refreshTimeout = bt(() => {
|
|
1085
|
+
this.refreshTimeout = null, this._onInput();
|
|
1086
|
+
}, this.settings.refreshThrottle);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
_onInput() {
|
|
1090
|
+
const e = this.lastValue;
|
|
1091
|
+
this.settings.shouldLoad.call(this, e) && this.load(e), this.refreshOptions(), this.trigger("type", e);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Triggered when the user rolls over
|
|
1095
|
+
* an option in the autocomplete dropdown menu.
|
|
1096
|
+
*
|
|
1097
|
+
*/
|
|
1098
|
+
onOptionHover(e, t) {
|
|
1099
|
+
this.ignoreHover || this.setActiveOption(t, !1);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Triggered on <input> focus.
|
|
1103
|
+
*
|
|
1104
|
+
*/
|
|
1105
|
+
onFocus(e) {
|
|
1106
|
+
var t = this, i = t.isFocused;
|
|
1107
|
+
if (t.isDisabled || t.isReadOnly) {
|
|
1108
|
+
t.blur(), C(e);
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
t.ignoreFocus || (t.isFocused = !0, t.settings.preload === "focus" && t.preload(), i || t.trigger("focus"), t.activeItems.length || (t.inputState(), t.refreshOptions(!!t.settings.openOnFocus)), t.refreshState());
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Triggered on <input> blur.
|
|
1115
|
+
*
|
|
1116
|
+
*/
|
|
1117
|
+
onBlur(e) {
|
|
1118
|
+
if (document.hasFocus() !== !1) {
|
|
1119
|
+
var t = this;
|
|
1120
|
+
if (t.isFocused) {
|
|
1121
|
+
t.isFocused = !1, t.ignoreFocus = !1;
|
|
1122
|
+
var i = () => {
|
|
1123
|
+
t.close(), t.setActiveItem(), t.setCaret(t.items.length), t.trigger("blur");
|
|
1124
|
+
};
|
|
1125
|
+
t.settings.create && t.settings.createOnBlur ? t.createItem(null, i) : i();
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Triggered when the user clicks on an option
|
|
1131
|
+
* in the autocomplete dropdown menu.
|
|
1132
|
+
*
|
|
1133
|
+
*/
|
|
1134
|
+
onOptionSelect(e, t) {
|
|
1135
|
+
var i, n = this;
|
|
1136
|
+
t.parentElement && t.parentElement.matches("[data-disabled]") || (t.classList.contains("create") ? n.createItem(null, () => {
|
|
1137
|
+
n.settings.closeAfterSelect && n.close();
|
|
1138
|
+
}) : (i = t.dataset.value, typeof i < "u" && (n.lastQuery = null, n.addItem(i), n.settings.closeAfterSelect && n.close(), !n.settings.hideSelected && e.type && /click/.test(e.type) && n.setActiveOption(t))));
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Return true if the given option can be selected
|
|
1142
|
+
*
|
|
1143
|
+
*/
|
|
1144
|
+
canSelect(e) {
|
|
1145
|
+
return !!(this.isOpen && e && this.dropdown_content.contains(e));
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Triggered when the user clicks on an item
|
|
1149
|
+
* that has been selected.
|
|
1150
|
+
*
|
|
1151
|
+
*/
|
|
1152
|
+
onItemSelect(e, t) {
|
|
1153
|
+
var i = this;
|
|
1154
|
+
return !i.isLocked && i.settings.mode === "multi" ? (C(e), i.setActiveItem(t, e), !0) : !1;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Determines whether or not to invoke
|
|
1158
|
+
* the user-provided option provider / loader
|
|
1159
|
+
*
|
|
1160
|
+
* Note, there is a subtle difference between
|
|
1161
|
+
* this.canLoad() and this.settings.shouldLoad();
|
|
1162
|
+
*
|
|
1163
|
+
* - settings.shouldLoad() is a user-input validator.
|
|
1164
|
+
* When false is returned, the not_loading template
|
|
1165
|
+
* will be added to the dropdown
|
|
1166
|
+
*
|
|
1167
|
+
* - canLoad() is lower level validator that checks
|
|
1168
|
+
* the Tom Select instance. There is no inherent user
|
|
1169
|
+
* feedback when canLoad returns false
|
|
1170
|
+
*
|
|
1171
|
+
*/
|
|
1172
|
+
canLoad(e) {
|
|
1173
|
+
return !(!this.settings.load || this.loadedSearches.hasOwnProperty(e));
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Invokes the user-provided option provider / loader.
|
|
1177
|
+
*
|
|
1178
|
+
*/
|
|
1179
|
+
load(e) {
|
|
1180
|
+
const t = this;
|
|
1181
|
+
if (!t.canLoad(e))
|
|
1182
|
+
return;
|
|
1183
|
+
k(t.wrapper, t.settings.loadingClass), t.loading++;
|
|
1184
|
+
const i = t.loadCallback.bind(t);
|
|
1185
|
+
t.settings.load.call(t, e, i);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Invoked by the user-provided option provider
|
|
1189
|
+
*
|
|
1190
|
+
*/
|
|
1191
|
+
loadCallback(e, t) {
|
|
1192
|
+
const i = this;
|
|
1193
|
+
i.loading = Math.max(i.loading - 1, 0), i.lastQuery = null, i.clearActiveOption(), i.setupOptions(e, t), i.refreshOptions(i.isFocused && !i.isInputHidden), i.loading || M(i.wrapper, i.settings.loadingClass), i.trigger("load", e, t);
|
|
1194
|
+
}
|
|
1195
|
+
preload() {
|
|
1196
|
+
var e = this.wrapper.classList;
|
|
1197
|
+
e.contains("preloaded") || (e.add("preloaded"), this.load(""));
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Sets the input field of the control to the specified value.
|
|
1201
|
+
*
|
|
1202
|
+
*/
|
|
1203
|
+
setTextboxValue(e = "") {
|
|
1204
|
+
var t = this.control_input, i = t.value !== e;
|
|
1205
|
+
i && (t.value = e, he(t, "update"), this.lastValue = e);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Returns the value of the control. If multiple items
|
|
1209
|
+
* can be selected (e.g. <select multiple>), this returns
|
|
1210
|
+
* an array. If only one item can be selected, this
|
|
1211
|
+
* returns a string.
|
|
1212
|
+
*
|
|
1213
|
+
*/
|
|
1214
|
+
getValue() {
|
|
1215
|
+
return this.is_select_tag && this.input.hasAttribute("multiple") ? this.items : this.items.join(this.settings.delimiter);
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Resets the selected items to the given value.
|
|
1219
|
+
*
|
|
1220
|
+
*/
|
|
1221
|
+
setValue(e, t) {
|
|
1222
|
+
var i = t ? [] : ["change"];
|
|
1223
|
+
Ce(this, i, () => {
|
|
1224
|
+
this.clear(t), this.addItems(e, t);
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Resets the number of max items to the given value
|
|
1229
|
+
*
|
|
1230
|
+
*/
|
|
1231
|
+
setMaxItems(e) {
|
|
1232
|
+
e === 0 && (e = null), this.settings.maxItems = e, this.refreshState();
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Sets the selected item.
|
|
1236
|
+
*
|
|
1237
|
+
*/
|
|
1238
|
+
setActiveItem(e, t) {
|
|
1239
|
+
var i = this, n, o, r, l, c, a;
|
|
1240
|
+
if (i.settings.mode !== "single") {
|
|
1241
|
+
if (!e) {
|
|
1242
|
+
i.clearActiveItems(), i.isFocused && i.inputState();
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
if (n = t && t.type.toLowerCase(), n === "click" && R("shiftKey", t) && i.activeItems.length) {
|
|
1246
|
+
for (a = i.getLastActive(), r = Array.prototype.indexOf.call(i.control.children, a), l = Array.prototype.indexOf.call(i.control.children, e), r > l && (c = r, r = l, l = c), o = r; o <= l; o++)
|
|
1247
|
+
e = i.control.children[o], i.activeItems.indexOf(e) === -1 && i.setActiveItemClass(e);
|
|
1248
|
+
C(t);
|
|
1249
|
+
} else n === "click" && R(ee, t) || n === "keydown" && R("shiftKey", t) ? e.classList.contains("active") ? i.removeActiveItem(e) : i.setActiveItemClass(e) : (i.clearActiveItems(), i.setActiveItemClass(e));
|
|
1250
|
+
i.inputState(), i.isFocused || i.focus();
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Set the active and last-active classes
|
|
1255
|
+
*
|
|
1256
|
+
*/
|
|
1257
|
+
setActiveItemClass(e) {
|
|
1258
|
+
const t = this, i = t.control.querySelector(".last-active");
|
|
1259
|
+
i && M(i, "last-active"), k(e, "active last-active"), t.trigger("item_select", e), t.activeItems.indexOf(e) == -1 && t.activeItems.push(e);
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Remove active item
|
|
1263
|
+
*
|
|
1264
|
+
*/
|
|
1265
|
+
removeActiveItem(e) {
|
|
1266
|
+
var t = this.activeItems.indexOf(e);
|
|
1267
|
+
this.activeItems.splice(t, 1), M(e, "active");
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Clears all the active items
|
|
1271
|
+
*
|
|
1272
|
+
*/
|
|
1273
|
+
clearActiveItems() {
|
|
1274
|
+
M(this.activeItems, "active"), this.activeItems = [];
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Sets the selected item in the dropdown menu
|
|
1278
|
+
* of available options.
|
|
1279
|
+
*
|
|
1280
|
+
*/
|
|
1281
|
+
setActiveOption(e, t = !0) {
|
|
1282
|
+
e !== this.activeOption && (this.clearActiveOption(), e && (this.activeOption = e, A(this.focus_node, { "aria-activedescendant": e.getAttribute("id") }), A(e, { "aria-selected": "true" }), k(e, "active"), t && this.scrollToOption(e)));
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Sets the dropdown_content scrollTop to display the option
|
|
1286
|
+
*
|
|
1287
|
+
*/
|
|
1288
|
+
scrollToOption(e, t) {
|
|
1289
|
+
if (!e)
|
|
1290
|
+
return;
|
|
1291
|
+
const i = this.dropdown_content, n = i.clientHeight, o = i.scrollTop || 0, r = e.offsetHeight, l = e.getBoundingClientRect().top - i.getBoundingClientRect().top + o;
|
|
1292
|
+
l + r > n + o ? this.scroll(l - n + r, t) : l < o && this.scroll(l, t);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Scroll the dropdown to the given position
|
|
1296
|
+
*
|
|
1297
|
+
*/
|
|
1298
|
+
scroll(e, t) {
|
|
1299
|
+
const i = this.dropdown_content;
|
|
1300
|
+
t && (i.style.scrollBehavior = t), i.scrollTop = e, i.style.scrollBehavior = "";
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Clears the active option
|
|
1304
|
+
*
|
|
1305
|
+
*/
|
|
1306
|
+
clearActiveOption() {
|
|
1307
|
+
this.activeOption && (M(this.activeOption, "active"), A(this.activeOption, { "aria-selected": null })), this.activeOption = null, A(this.focus_node, { "aria-activedescendant": null });
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Selects all items (CTRL + A).
|
|
1311
|
+
*/
|
|
1312
|
+
selectAll() {
|
|
1313
|
+
const e = this;
|
|
1314
|
+
if (e.settings.mode === "single")
|
|
1315
|
+
return;
|
|
1316
|
+
const t = e.controlChildren();
|
|
1317
|
+
t.length && (e.inputState(), e.close(), e.activeItems = t, I(t, (i) => {
|
|
1318
|
+
e.setActiveItemClass(i);
|
|
1319
|
+
}));
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Determines if the control_input should be in a hidden or visible state
|
|
1323
|
+
*
|
|
1324
|
+
*/
|
|
1325
|
+
inputState() {
|
|
1326
|
+
var e = this;
|
|
1327
|
+
e.control.contains(e.control_input) && (A(e.control_input, { placeholder: e.settings.placeholder }), e.activeItems.length > 0 || !e.isFocused && e.settings.hidePlaceholder && e.items.length > 0 ? (e.setTextboxValue(), e.isInputHidden = !0) : (e.settings.hidePlaceholder && e.items.length > 0 && A(e.control_input, { placeholder: "" }), e.isInputHidden = !1), e.wrapper.classList.toggle("input-hidden", e.isInputHidden));
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Get the input value
|
|
1331
|
+
*/
|
|
1332
|
+
inputValue() {
|
|
1333
|
+
return this.control_input.value.trim();
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Gives the control focus.
|
|
1337
|
+
*/
|
|
1338
|
+
focus() {
|
|
1339
|
+
var e = this;
|
|
1340
|
+
e.isDisabled || e.isReadOnly || (e.ignoreFocus = !0, e.control_input.offsetWidth ? e.control_input.focus() : e.focus_node.focus(), setTimeout(() => {
|
|
1341
|
+
e.ignoreFocus = !1, e.onFocus();
|
|
1342
|
+
}, 0));
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Forces the control out of focus.
|
|
1346
|
+
*
|
|
1347
|
+
*/
|
|
1348
|
+
blur() {
|
|
1349
|
+
this.focus_node.blur(), this.onBlur();
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Returns a function that scores an object
|
|
1353
|
+
* to show how good of a match it is to the
|
|
1354
|
+
* provided query.
|
|
1355
|
+
*
|
|
1356
|
+
* @return {function}
|
|
1357
|
+
*/
|
|
1358
|
+
getScoreFunction(e) {
|
|
1359
|
+
return this.sifter.getScoreFunction(e, this.getSearchOptions());
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Returns search options for sifter (the system
|
|
1363
|
+
* for scoring and sorting results).
|
|
1364
|
+
*
|
|
1365
|
+
* @see https://github.com/orchidjs/sifter.js
|
|
1366
|
+
* @return {object}
|
|
1367
|
+
*/
|
|
1368
|
+
getSearchOptions() {
|
|
1369
|
+
var e = this.settings, t = e.sortField;
|
|
1370
|
+
return typeof e.sortField == "string" && (t = [{ field: e.sortField }]), {
|
|
1371
|
+
fields: e.searchField,
|
|
1372
|
+
conjunction: e.searchConjunction,
|
|
1373
|
+
sort: t,
|
|
1374
|
+
nesting: e.nesting
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Searches through available options and returns
|
|
1379
|
+
* a sorted array of matches.
|
|
1380
|
+
*
|
|
1381
|
+
*/
|
|
1382
|
+
search(e) {
|
|
1383
|
+
var t, i, n = this, o = this.getSearchOptions();
|
|
1384
|
+
if (n.settings.score && (i = n.settings.score.call(n, e), typeof i != "function"))
|
|
1385
|
+
throw new Error('Tom Select "score" setting must be a function that returns a function');
|
|
1386
|
+
return e !== n.lastQuery ? (n.lastQuery = e, t = n.sifter.search(e, Object.assign(o, { score: i })), n.currentResults = t) : t = Object.assign({}, n.currentResults), n.settings.hideSelected && (t.items = t.items.filter((r) => {
|
|
1387
|
+
let l = T(r.id);
|
|
1388
|
+
return !(l && n.items.indexOf(l) !== -1);
|
|
1389
|
+
})), t;
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Refreshes the list of available options shown
|
|
1393
|
+
* in the autocomplete dropdown menu.
|
|
1394
|
+
*
|
|
1395
|
+
*/
|
|
1396
|
+
refreshOptions(e = !0) {
|
|
1397
|
+
var t, i, n, o, r, l, c, a, u, d;
|
|
1398
|
+
const p = {}, w = [];
|
|
1399
|
+
var f = this, v = f.inputValue();
|
|
1400
|
+
const b = v === f.lastQuery || v == "" && f.lastQuery == null;
|
|
1401
|
+
var y = f.search(v), h = null, S = f.settings.shouldOpen || !1, P = f.dropdown_content;
|
|
1402
|
+
b && (h = f.activeOption, h && (u = h.closest("[data-group]"))), o = y.items.length, typeof f.settings.maxOptions == "number" && (o = Math.min(o, f.settings.maxOptions)), o > 0 && (S = !0);
|
|
1403
|
+
const q = (m, _) => {
|
|
1404
|
+
let g = p[m];
|
|
1405
|
+
if (g !== void 0) {
|
|
1406
|
+
let O = w[g];
|
|
1407
|
+
if (O !== void 0)
|
|
1408
|
+
return [g, O.fragment];
|
|
1409
|
+
}
|
|
1410
|
+
let E = document.createDocumentFragment();
|
|
1411
|
+
return g = w.length, w.push({ fragment: E, order: _, optgroup: m }), [g, E];
|
|
1412
|
+
};
|
|
1413
|
+
for (t = 0; t < o; t++) {
|
|
1414
|
+
let m = y.items[t];
|
|
1415
|
+
if (!m)
|
|
1416
|
+
continue;
|
|
1417
|
+
let _ = m.id, g = f.options[_];
|
|
1418
|
+
if (g === void 0)
|
|
1419
|
+
continue;
|
|
1420
|
+
let E = se(_), O = f.getOption(E, !0);
|
|
1421
|
+
for (f.settings.hideSelected || O.classList.toggle("selected", f.items.includes(E)), r = g[f.settings.optgroupField] || "", l = Array.isArray(r) ? r : [r], i = 0, n = l && l.length; i < n; i++) {
|
|
1422
|
+
r = l[i];
|
|
1423
|
+
let J = g.$order, W = f.optgroups[r];
|
|
1424
|
+
W === void 0 ? r = "" : J = W.$order;
|
|
1425
|
+
const [Ge, qe] = q(r, J);
|
|
1426
|
+
i > 0 && (O = O.cloneNode(!0), A(O, { id: g.$id + "-clone-" + i, "aria-selected": null }), O.classList.add("ts-cloned"), M(O, "active"), f.activeOption && f.activeOption.dataset.value == _ && u && u.dataset.group === r.toString() && (h = O)), qe.appendChild(O), r != "" && (p[r] = Ge);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
f.settings.lockOptgroupOrder && w.sort((m, _) => m.order - _.order), c = document.createDocumentFragment(), I(w, (m) => {
|
|
1430
|
+
let _ = m.fragment, g = m.optgroup;
|
|
1431
|
+
if (!_ || !_.children.length)
|
|
1432
|
+
return;
|
|
1433
|
+
let E = f.optgroups[g];
|
|
1434
|
+
if (E !== void 0) {
|
|
1435
|
+
let O = document.createDocumentFragment(), J = f.render("optgroup_header", E);
|
|
1436
|
+
B(O, J), B(O, _);
|
|
1437
|
+
let W = f.render("optgroup", { group: E, options: O });
|
|
1438
|
+
B(c, W);
|
|
1439
|
+
} else
|
|
1440
|
+
B(c, _);
|
|
1441
|
+
}), P.innerHTML = "", B(P, c), f.settings.highlight && (Et(P), y.query.length && y.tokens.length && I(y.tokens, (m) => {
|
|
1442
|
+
It(P, m.regex);
|
|
1443
|
+
}));
|
|
1444
|
+
var j = (m) => {
|
|
1445
|
+
let _ = f.render(m, { input: v });
|
|
1446
|
+
return _ && (S = !0, P.insertBefore(_, P.firstChild)), _;
|
|
1447
|
+
};
|
|
1448
|
+
if (f.loading ? j("loading") : f.settings.shouldLoad.call(f, v) ? y.items.length === 0 && j("no_results") : j("not_loading"), a = f.canCreate(v), a && (d = j("option_create")), f.hasOptions = y.items.length > 0 || a, S) {
|
|
1449
|
+
if (y.items.length > 0) {
|
|
1450
|
+
if (!h && f.settings.mode === "single" && f.items[0] != null && (h = f.getOption(f.items[0])), !P.contains(h)) {
|
|
1451
|
+
let m = 0;
|
|
1452
|
+
d && !f.settings.addPrecedence && (m = 1), h = f.selectable()[m];
|
|
1453
|
+
}
|
|
1454
|
+
} else d && (h = d);
|
|
1455
|
+
e && !f.isOpen && (f.open(), f.scrollToOption(h, "auto")), f.setActiveOption(h);
|
|
1456
|
+
} else
|
|
1457
|
+
f.clearActiveOption(), e && f.isOpen && f.close(!1);
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Return list of selectable options
|
|
1461
|
+
*
|
|
1462
|
+
*/
|
|
1463
|
+
selectable() {
|
|
1464
|
+
return this.dropdown_content.querySelectorAll("[data-selectable]");
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Adds an available option. If it already exists,
|
|
1468
|
+
* nothing will happen. Note: this does not refresh
|
|
1469
|
+
* the options list dropdown (use `refreshOptions`
|
|
1470
|
+
* for that).
|
|
1471
|
+
*
|
|
1472
|
+
* Usage:
|
|
1473
|
+
*
|
|
1474
|
+
* this.addOption(data)
|
|
1475
|
+
*
|
|
1476
|
+
*/
|
|
1477
|
+
addOption(e, t = !1) {
|
|
1478
|
+
const i = this;
|
|
1479
|
+
if (Array.isArray(e))
|
|
1480
|
+
return i.addOptions(e, t), !1;
|
|
1481
|
+
const n = T(e[i.settings.valueField]);
|
|
1482
|
+
return n === null || i.options.hasOwnProperty(n) ? !1 : (e.$order = e.$order || ++i.order, e.$id = i.inputId + "-opt-" + e.$order, i.options[n] = e, i.lastQuery = null, t && (i.userOptions[n] = t, i.trigger("option_add", n, e)), n);
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Add multiple options
|
|
1486
|
+
*
|
|
1487
|
+
*/
|
|
1488
|
+
addOptions(e, t = !1) {
|
|
1489
|
+
I(e, (i) => {
|
|
1490
|
+
this.addOption(i, t);
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* @deprecated 1.7.7
|
|
1495
|
+
*/
|
|
1496
|
+
registerOption(e) {
|
|
1497
|
+
return this.addOption(e);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Registers an option group to the pool of option groups.
|
|
1501
|
+
*
|
|
1502
|
+
* @return {boolean|string}
|
|
1503
|
+
*/
|
|
1504
|
+
registerOptionGroup(e) {
|
|
1505
|
+
var t = T(e[this.settings.optgroupValueField]);
|
|
1506
|
+
return t === null ? !1 : (e.$order = e.$order || ++this.order, this.optgroups[t] = e, t);
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Registers a new optgroup for options
|
|
1510
|
+
* to be bucketed into.
|
|
1511
|
+
*
|
|
1512
|
+
*/
|
|
1513
|
+
addOptionGroup(e, t) {
|
|
1514
|
+
var i;
|
|
1515
|
+
t[this.settings.optgroupValueField] = e, (i = this.registerOptionGroup(t)) && this.trigger("optgroup_add", i, t);
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Removes an existing option group.
|
|
1519
|
+
*
|
|
1520
|
+
*/
|
|
1521
|
+
removeOptionGroup(e) {
|
|
1522
|
+
this.optgroups.hasOwnProperty(e) && (delete this.optgroups[e], this.clearCache(), this.trigger("optgroup_remove", e));
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Clears all existing option groups.
|
|
1526
|
+
*/
|
|
1527
|
+
clearOptionGroups() {
|
|
1528
|
+
this.optgroups = {}, this.clearCache(), this.trigger("optgroup_clear");
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Updates an option available for selection. If
|
|
1532
|
+
* it is visible in the selected items or options
|
|
1533
|
+
* dropdown, it will be re-rendered automatically.
|
|
1534
|
+
*
|
|
1535
|
+
*/
|
|
1536
|
+
updateOption(e, t) {
|
|
1537
|
+
const i = this;
|
|
1538
|
+
var n, o;
|
|
1539
|
+
const r = T(e), l = T(t[i.settings.valueField]);
|
|
1540
|
+
if (r === null)
|
|
1541
|
+
return;
|
|
1542
|
+
const c = i.options[r];
|
|
1543
|
+
if (c == null)
|
|
1544
|
+
return;
|
|
1545
|
+
if (typeof l != "string")
|
|
1546
|
+
throw new Error("Value must be set in option data");
|
|
1547
|
+
const a = i.getOption(r), u = i.getItem(r);
|
|
1548
|
+
if (t.$order = t.$order || c.$order, delete i.options[r], i.uncacheValue(l), i.options[l] = t, a) {
|
|
1549
|
+
if (i.dropdown_content.contains(a)) {
|
|
1550
|
+
const d = i._render("option", t);
|
|
1551
|
+
me(a, d), i.activeOption === a && i.setActiveOption(d);
|
|
1552
|
+
}
|
|
1553
|
+
a.remove();
|
|
1554
|
+
}
|
|
1555
|
+
u && (o = i.items.indexOf(r), o !== -1 && i.items.splice(o, 1, l), n = i._render("item", t), u.classList.contains("active") && k(n, "active"), me(u, n)), i.lastQuery = null;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Removes a single option.
|
|
1559
|
+
*
|
|
1560
|
+
*/
|
|
1561
|
+
removeOption(e, t) {
|
|
1562
|
+
const i = this;
|
|
1563
|
+
e = se(e), i.uncacheValue(e), delete i.userOptions[e], delete i.options[e], i.lastQuery = null, i.trigger("option_remove", e), i.removeItem(e, t);
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Clears all options.
|
|
1567
|
+
*/
|
|
1568
|
+
clearOptions(e) {
|
|
1569
|
+
const t = (e || this.clearFilter).bind(this);
|
|
1570
|
+
this.loadedSearches = {}, this.userOptions = {}, this.clearCache();
|
|
1571
|
+
const i = {};
|
|
1572
|
+
I(this.options, (n, o) => {
|
|
1573
|
+
t(n, o) && (i[o] = n);
|
|
1574
|
+
}), this.options = this.sifter.items = i, this.lastQuery = null, this.trigger("option_clear");
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Used by clearOptions() to decide whether or not an option should be removed
|
|
1578
|
+
* Return true to keep an option, false to remove
|
|
1579
|
+
*
|
|
1580
|
+
*/
|
|
1581
|
+
clearFilter(e, t) {
|
|
1582
|
+
return this.items.indexOf(t) >= 0;
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Returns the dom element of the option
|
|
1586
|
+
* matching the given value.
|
|
1587
|
+
*
|
|
1588
|
+
*/
|
|
1589
|
+
getOption(e, t = !1) {
|
|
1590
|
+
const i = T(e);
|
|
1591
|
+
if (i === null)
|
|
1592
|
+
return null;
|
|
1593
|
+
const n = this.options[i];
|
|
1594
|
+
if (n != null) {
|
|
1595
|
+
if (n.$div)
|
|
1596
|
+
return n.$div;
|
|
1597
|
+
if (t)
|
|
1598
|
+
return this._render("option", n);
|
|
1599
|
+
}
|
|
1600
|
+
return null;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Returns the dom element of the next or previous dom element of the same type
|
|
1604
|
+
* Note: adjacent options may not be adjacent DOM elements (optgroups)
|
|
1605
|
+
*
|
|
1606
|
+
*/
|
|
1607
|
+
getAdjacent(e, t, i = "option") {
|
|
1608
|
+
var n = this, o;
|
|
1609
|
+
if (!e)
|
|
1610
|
+
return null;
|
|
1611
|
+
i == "item" ? o = n.controlChildren() : o = n.dropdown_content.querySelectorAll("[data-selectable]");
|
|
1612
|
+
for (let r = 0; r < o.length; r++)
|
|
1613
|
+
if (o[r] == e)
|
|
1614
|
+
return t > 0 ? o[r + 1] : o[r - 1];
|
|
1615
|
+
return null;
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Returns the dom element of the item
|
|
1619
|
+
* matching the given value.
|
|
1620
|
+
*
|
|
1621
|
+
*/
|
|
1622
|
+
getItem(e) {
|
|
1623
|
+
if (typeof e == "object")
|
|
1624
|
+
return e;
|
|
1625
|
+
var t = T(e);
|
|
1626
|
+
return t !== null ? this.control.querySelector(`[data-value="${xe(t)}"]`) : null;
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* "Selects" multiple items at once. Adds them to the list
|
|
1630
|
+
* at the current caret position.
|
|
1631
|
+
*
|
|
1632
|
+
*/
|
|
1633
|
+
addItems(e, t) {
|
|
1634
|
+
var i = this, n = Array.isArray(e) ? e : [e];
|
|
1635
|
+
n = n.filter((r) => i.items.indexOf(r) === -1);
|
|
1636
|
+
const o = n[n.length - 1];
|
|
1637
|
+
n.forEach((r) => {
|
|
1638
|
+
i.isPending = r !== o, i.addItem(r, t);
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* "Selects" an item. Adds it to the list
|
|
1643
|
+
* at the current caret position.
|
|
1644
|
+
*
|
|
1645
|
+
*/
|
|
1646
|
+
addItem(e, t) {
|
|
1647
|
+
var i = t ? [] : ["change", "dropdown_close"];
|
|
1648
|
+
Ce(this, i, () => {
|
|
1649
|
+
var n, o;
|
|
1650
|
+
const r = this, l = r.settings.mode, c = T(e);
|
|
1651
|
+
if (!(c && r.items.indexOf(c) !== -1 && (l === "single" && r.close(), l === "single" || !r.settings.duplicates)) && !(c === null || !r.options.hasOwnProperty(c)) && (l === "single" && r.clear(t), !(l === "multi" && r.isFull()))) {
|
|
1652
|
+
if (n = r._render("item", r.options[c]), r.control.contains(n) && (n = n.cloneNode(!0)), o = r.isFull(), r.items.splice(r.caretPos, 0, c), r.insertAtCaret(n), r.isSetup) {
|
|
1653
|
+
if (!r.isPending && r.settings.hideSelected) {
|
|
1654
|
+
let a = r.getOption(c), u = r.getAdjacent(a, 1);
|
|
1655
|
+
u && r.setActiveOption(u);
|
|
1656
|
+
}
|
|
1657
|
+
!r.isPending && !r.settings.closeAfterSelect && r.refreshOptions(r.isFocused && l !== "single"), r.settings.closeAfterSelect != !1 && r.isFull() ? r.close() : r.isPending || r.positionDropdown(), r.trigger("item_add", c, n), r.isPending || r.updateOriginalInput({ silent: t });
|
|
1658
|
+
}
|
|
1659
|
+
(!r.isPending || !o && r.isFull()) && (r.inputState(), r.refreshState());
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Removes the selected item matching
|
|
1665
|
+
* the provided value.
|
|
1666
|
+
*
|
|
1667
|
+
*/
|
|
1668
|
+
removeItem(e = null, t) {
|
|
1669
|
+
const i = this;
|
|
1670
|
+
if (e = i.getItem(e), !e)
|
|
1671
|
+
return;
|
|
1672
|
+
var n, o;
|
|
1673
|
+
const r = e.dataset.value;
|
|
1674
|
+
n = Ee(e), e.remove(), e.classList.contains("active") && (o = i.activeItems.indexOf(e), i.activeItems.splice(o, 1), M(e, "active")), i.items.splice(n, 1), i.lastQuery = null, !i.settings.persist && i.userOptions.hasOwnProperty(r) && i.removeOption(r, t), n < i.caretPos && i.setCaret(i.caretPos - 1), i.updateOriginalInput({ silent: t }), i.refreshState(), i.positionDropdown(), i.trigger("item_remove", r, e);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Invokes the `create` method provided in the
|
|
1678
|
+
* TomSelect options that should provide the data
|
|
1679
|
+
* for the new item, given the user input.
|
|
1680
|
+
*
|
|
1681
|
+
* Once this completes, it will be added
|
|
1682
|
+
* to the item list.
|
|
1683
|
+
*
|
|
1684
|
+
*/
|
|
1685
|
+
createItem(e = null, t = () => {
|
|
1686
|
+
}) {
|
|
1687
|
+
arguments.length === 3 && (t = arguments[2]), typeof t != "function" && (t = () => {
|
|
1688
|
+
});
|
|
1689
|
+
var i = this, n = i.caretPos, o;
|
|
1690
|
+
if (e = e || i.inputValue(), !i.canCreate(e))
|
|
1691
|
+
return t(), !1;
|
|
1692
|
+
i.lock();
|
|
1693
|
+
var r = !1, l = (c) => {
|
|
1694
|
+
if (i.unlock(), !c || typeof c != "object")
|
|
1695
|
+
return t();
|
|
1696
|
+
var a = T(c[i.settings.valueField]);
|
|
1697
|
+
if (typeof a != "string")
|
|
1698
|
+
return t();
|
|
1699
|
+
i.setTextboxValue(), i.addOption(c, !0), i.setCaret(n), i.addItem(a), t(c), r = !0;
|
|
1700
|
+
};
|
|
1701
|
+
return typeof i.settings.create == "function" ? o = i.settings.create.call(this, e, l) : o = {
|
|
1702
|
+
[i.settings.labelField]: e,
|
|
1703
|
+
[i.settings.valueField]: e
|
|
1704
|
+
}, r || l(o), !0;
|
|
1705
|
+
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Re-renders the selected item lists.
|
|
1708
|
+
*/
|
|
1709
|
+
refreshItems() {
|
|
1710
|
+
var e = this;
|
|
1711
|
+
e.lastQuery = null, e.isSetup && e.addItems(e.items), e.updateOriginalInput(), e.refreshState();
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Updates all state-dependent attributes
|
|
1715
|
+
* and CSS classes.
|
|
1716
|
+
*/
|
|
1717
|
+
refreshState() {
|
|
1718
|
+
const e = this;
|
|
1719
|
+
e.refreshValidityState();
|
|
1720
|
+
const t = e.isFull(), i = e.isLocked;
|
|
1721
|
+
e.wrapper.classList.toggle("rtl", e.rtl);
|
|
1722
|
+
const n = e.wrapper.classList;
|
|
1723
|
+
n.toggle("focus", e.isFocused), n.toggle("disabled", e.isDisabled), n.toggle("readonly", e.isReadOnly), n.toggle("required", e.isRequired), n.toggle("invalid", !e.isValid), n.toggle("locked", i), n.toggle("full", t), n.toggle("input-active", e.isFocused && !e.isInputHidden), n.toggle("dropdown-active", e.isOpen), n.toggle("has-options", xt(e.options)), n.toggle("has-items", e.items.length > 0);
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Update the `required` attribute of both input and control input.
|
|
1727
|
+
*
|
|
1728
|
+
* The `required` property needs to be activated on the control input
|
|
1729
|
+
* for the error to be displayed at the right place. `required` also
|
|
1730
|
+
* needs to be temporarily deactivated on the input since the input is
|
|
1731
|
+
* hidden and can't show errors.
|
|
1732
|
+
*/
|
|
1733
|
+
refreshValidityState() {
|
|
1734
|
+
var e = this;
|
|
1735
|
+
e.input.validity && (e.isValid = e.input.validity.valid, e.isInvalid = !e.isValid);
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Determines whether or not more items can be added
|
|
1739
|
+
* to the control without exceeding the user-defined maximum.
|
|
1740
|
+
*
|
|
1741
|
+
* @returns {boolean}
|
|
1742
|
+
*/
|
|
1743
|
+
isFull() {
|
|
1744
|
+
return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems;
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Refreshes the original <select> or <input>
|
|
1748
|
+
* element to reflect the current state.
|
|
1749
|
+
*
|
|
1750
|
+
*/
|
|
1751
|
+
updateOriginalInput(e = {}) {
|
|
1752
|
+
const t = this;
|
|
1753
|
+
var i, n;
|
|
1754
|
+
const o = t.input.querySelector('option[value=""]');
|
|
1755
|
+
if (t.is_select_tag) {
|
|
1756
|
+
let c = function(a, u, d) {
|
|
1757
|
+
return a || (a = D('<option value="' + fe(u) + '">' + fe(d) + "</option>")), a != o && t.input.append(a), r.push(a), (a != o || l > 0) && (a.selected = !0), a;
|
|
1758
|
+
};
|
|
1759
|
+
const r = [], l = t.input.querySelectorAll("option:checked").length;
|
|
1760
|
+
t.input.querySelectorAll("option:checked").forEach((a) => {
|
|
1761
|
+
a.selected = !1;
|
|
1762
|
+
}), t.items.length == 0 && t.settings.mode == "single" ? c(o, "", "") : t.items.forEach((a) => {
|
|
1763
|
+
if (i = t.options[a], n = i[t.settings.labelField] || "", r.includes(i.$option)) {
|
|
1764
|
+
const u = t.input.querySelector(`option[value="${xe(a)}"]:not(:checked)`);
|
|
1765
|
+
c(u, a, n);
|
|
1766
|
+
} else
|
|
1767
|
+
i.$option = c(i.$option, a, n);
|
|
1768
|
+
});
|
|
1769
|
+
} else
|
|
1770
|
+
t.input.value = t.getValue();
|
|
1771
|
+
t.isSetup && (e.silent || t.trigger("change", t.getValue()));
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Shows the autocomplete dropdown containing
|
|
1775
|
+
* the available options.
|
|
1776
|
+
*/
|
|
1777
|
+
open() {
|
|
1778
|
+
var e = this;
|
|
1779
|
+
e.isLocked || e.isOpen || e.settings.mode === "multi" && e.isFull() || (e.isOpen = !0, A(e.focus_node, { "aria-expanded": "true" }), e.refreshState(), Z(e.dropdown, { visibility: "hidden", display: "block" }), e.positionDropdown(), Z(e.dropdown, { visibility: "visible", display: "block" }), e.focus(), e.trigger("dropdown_open", e.dropdown));
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Closes the autocomplete dropdown menu.
|
|
1783
|
+
*/
|
|
1784
|
+
close(e = !0) {
|
|
1785
|
+
var t = this, i = t.isOpen;
|
|
1786
|
+
e && (t.setTextboxValue(), t.settings.mode === "single" && t.items.length && t.inputState()), t.isOpen = !1, A(t.focus_node, { "aria-expanded": "false" }), Z(t.dropdown, { display: "none" }), t.settings.hideSelected && t.clearActiveOption(), t.refreshState(), i && t.trigger("dropdown_close", t.dropdown);
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Calculates and applies the appropriate
|
|
1790
|
+
* position of the dropdown if dropdownParent = 'body'.
|
|
1791
|
+
* Otherwise, position is determined by css
|
|
1792
|
+
*/
|
|
1793
|
+
positionDropdown() {
|
|
1794
|
+
if (this.settings.dropdownParent === "body") {
|
|
1795
|
+
var e = this.control, t = e.getBoundingClientRect(), i = e.offsetHeight + t.top + window.scrollY, n = t.left + window.scrollX;
|
|
1796
|
+
Z(this.dropdown, {
|
|
1797
|
+
width: t.width + "px",
|
|
1798
|
+
top: i + "px",
|
|
1799
|
+
left: n + "px"
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Resets / clears all selected items
|
|
1805
|
+
* from the control.
|
|
1806
|
+
*
|
|
1807
|
+
*/
|
|
1808
|
+
clear(e) {
|
|
1809
|
+
var t = this;
|
|
1810
|
+
if (t.items.length) {
|
|
1811
|
+
var i = t.controlChildren();
|
|
1812
|
+
I(i, (n) => {
|
|
1813
|
+
t.removeItem(n, !0);
|
|
1814
|
+
}), t.inputState(), e || t.updateOriginalInput(), t.trigger("clear");
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* A helper method for inserting an element
|
|
1819
|
+
* at the current caret position.
|
|
1820
|
+
*
|
|
1821
|
+
*/
|
|
1822
|
+
insertAtCaret(e) {
|
|
1823
|
+
const t = this, i = t.caretPos, n = t.control;
|
|
1824
|
+
n.insertBefore(e, n.children[i] || null), t.setCaret(i + 1);
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Removes the current selected item(s).
|
|
1828
|
+
*
|
|
1829
|
+
*/
|
|
1830
|
+
deleteSelection(e) {
|
|
1831
|
+
var t, i, n, o, r = this;
|
|
1832
|
+
t = e && e.keyCode === Le ? -1 : 1, i = St(r.control_input);
|
|
1833
|
+
const l = [];
|
|
1834
|
+
if (r.activeItems.length)
|
|
1835
|
+
o = Ie(r.activeItems, t), n = Ee(o), t > 0 && n++, I(r.activeItems, (c) => l.push(c));
|
|
1836
|
+
else if ((r.isFocused || r.settings.mode === "single") && r.items.length) {
|
|
1837
|
+
const c = r.controlChildren();
|
|
1838
|
+
let a;
|
|
1839
|
+
t < 0 && i.start === 0 && i.length === 0 ? a = c[r.caretPos - 1] : t > 0 && i.start === r.inputValue().length && (a = c[r.caretPos]), a !== void 0 && l.push(a);
|
|
1840
|
+
}
|
|
1841
|
+
if (!r.shouldDelete(l, e))
|
|
1842
|
+
return !1;
|
|
1843
|
+
for (C(e, !0), typeof n < "u" && r.setCaret(n); l.length; )
|
|
1844
|
+
r.removeItem(l.pop());
|
|
1845
|
+
return r.inputState(), r.positionDropdown(), r.refreshOptions(!1), !0;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Return true if the items should be deleted
|
|
1849
|
+
*/
|
|
1850
|
+
shouldDelete(e, t) {
|
|
1851
|
+
const i = e.map((n) => n.dataset.value);
|
|
1852
|
+
return !(!i.length || typeof this.settings.onDelete == "function" && this.settings.onDelete(i, t) === !1);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Selects the previous / next item (depending on the `direction` argument).
|
|
1856
|
+
*
|
|
1857
|
+
* > 0 - right
|
|
1858
|
+
* < 0 - left
|
|
1859
|
+
*
|
|
1860
|
+
*/
|
|
1861
|
+
advanceSelection(e, t) {
|
|
1862
|
+
var i, n, o = this;
|
|
1863
|
+
o.rtl && (e *= -1), !o.inputValue().length && (R(ee, t) || R("shiftKey", t) ? (i = o.getLastActive(e), i ? i.classList.contains("active") ? n = o.getAdjacent(i, e, "item") : n = i : e > 0 ? n = o.control_input.nextElementSibling : n = o.control_input.previousElementSibling, n && (n.classList.contains("active") && o.removeActiveItem(i), o.setActiveItemClass(n))) : o.moveCaret(e));
|
|
1864
|
+
}
|
|
1865
|
+
moveCaret(e) {
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Get the last active item
|
|
1869
|
+
*
|
|
1870
|
+
*/
|
|
1871
|
+
getLastActive(e) {
|
|
1872
|
+
let t = this.control.querySelector(".last-active");
|
|
1873
|
+
if (t)
|
|
1874
|
+
return t;
|
|
1875
|
+
var i = this.control.querySelectorAll(".active");
|
|
1876
|
+
if (i)
|
|
1877
|
+
return Ie(i, e);
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Moves the caret to the specified index.
|
|
1881
|
+
*
|
|
1882
|
+
* The input must be moved by leaving it in place and moving the
|
|
1883
|
+
* siblings, due to the fact that focus cannot be restored once lost
|
|
1884
|
+
* on mobile webkit devices
|
|
1885
|
+
*
|
|
1886
|
+
*/
|
|
1887
|
+
setCaret(e) {
|
|
1888
|
+
this.caretPos = this.items.length;
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Return list of item dom elements
|
|
1892
|
+
*
|
|
1893
|
+
*/
|
|
1894
|
+
controlChildren() {
|
|
1895
|
+
return Array.from(this.control.querySelectorAll("[data-ts-item]"));
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Disables user input on the control. Used while
|
|
1899
|
+
* items are being asynchronously created.
|
|
1900
|
+
*/
|
|
1901
|
+
lock() {
|
|
1902
|
+
this.setLocked(!0);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Re-enables user input on the control.
|
|
1906
|
+
*/
|
|
1907
|
+
unlock() {
|
|
1908
|
+
this.setLocked(!1);
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Disable or enable user input on the control
|
|
1912
|
+
*/
|
|
1913
|
+
setLocked(e = this.isReadOnly || this.isDisabled) {
|
|
1914
|
+
this.isLocked = e, this.refreshState();
|
|
1915
|
+
}
|
|
1916
|
+
/**
|
|
1917
|
+
* Disables user input on the control completely.
|
|
1918
|
+
* While disabled, it cannot receive focus.
|
|
1919
|
+
*/
|
|
1920
|
+
disable() {
|
|
1921
|
+
this.setDisabled(!0), this.close();
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Enables the control so that it can respond
|
|
1925
|
+
* to focus and user input.
|
|
1926
|
+
*/
|
|
1927
|
+
enable() {
|
|
1928
|
+
this.setDisabled(!1);
|
|
1929
|
+
}
|
|
1930
|
+
setDisabled(e) {
|
|
1931
|
+
this.focus_node.tabIndex = e ? -1 : this.tabIndex, this.isDisabled = e, this.input.disabled = e, this.control_input.disabled = e, this.setLocked();
|
|
1932
|
+
}
|
|
1933
|
+
setReadOnly(e) {
|
|
1934
|
+
this.isReadOnly = e, this.input.readOnly = e, this.control_input.readOnly = e, this.setLocked();
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Completely destroys the control and
|
|
1938
|
+
* unbinds all event listeners so that it can
|
|
1939
|
+
* be garbage collected.
|
|
1940
|
+
*/
|
|
1941
|
+
destroy() {
|
|
1942
|
+
var e = this, t = e.revertSettings;
|
|
1943
|
+
e.trigger("destroy"), e.off(), e.wrapper.remove(), e.dropdown.remove(), e.input.innerHTML = t.innerHTML, e.input.tabIndex = t.tabIndex, M(e.input, "tomselected", "ts-hidden-accessible"), e._destroy(), delete e.input.tomselect;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* A helper method for rendering "item" and
|
|
1947
|
+
* "option" templates, given the data.
|
|
1948
|
+
*
|
|
1949
|
+
*/
|
|
1950
|
+
render(e, t) {
|
|
1951
|
+
var i, n;
|
|
1952
|
+
const o = this;
|
|
1953
|
+
if (typeof this.settings.render[e] != "function" || (n = o.settings.render[e].call(this, t, fe), !n))
|
|
1954
|
+
return null;
|
|
1955
|
+
if (n = D(n), e === "option" || e === "option_create" ? t[o.settings.disabledField] ? A(n, { "aria-disabled": "true" }) : A(n, { "data-selectable": "" }) : e === "optgroup" && (i = t.group[o.settings.optgroupValueField], A(n, { "data-group": i }), t.group[o.settings.disabledField] && A(n, { "data-disabled": "" })), e === "option" || e === "item") {
|
|
1956
|
+
const r = se(t[o.settings.valueField]);
|
|
1957
|
+
A(n, { "data-value": r }), e === "item" ? (k(n, o.settings.itemClass), A(n, { "data-ts-item": "" })) : (k(n, o.settings.optionClass), A(n, {
|
|
1958
|
+
role: "option",
|
|
1959
|
+
id: t.$id
|
|
1960
|
+
}), t.$div = n, o.options[r] = t);
|
|
1961
|
+
}
|
|
1962
|
+
return n;
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* Type guarded rendering
|
|
1966
|
+
*
|
|
1967
|
+
*/
|
|
1968
|
+
_render(e, t) {
|
|
1969
|
+
const i = this.render(e, t);
|
|
1970
|
+
if (i == null)
|
|
1971
|
+
throw "HTMLElement expected";
|
|
1972
|
+
return i;
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Clears the render cache for a template. If
|
|
1976
|
+
* no template is given, clears all render
|
|
1977
|
+
* caches.
|
|
1978
|
+
*
|
|
1979
|
+
*/
|
|
1980
|
+
clearCache() {
|
|
1981
|
+
I(this.options, (e) => {
|
|
1982
|
+
e.$div && (e.$div.remove(), delete e.$div);
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Removes a value from item and option caches
|
|
1987
|
+
*
|
|
1988
|
+
*/
|
|
1989
|
+
uncacheValue(e) {
|
|
1990
|
+
const t = this.getOption(e);
|
|
1991
|
+
t && t.remove();
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Determines whether or not to display the
|
|
1995
|
+
* create item prompt, given a user input.
|
|
1996
|
+
*
|
|
1997
|
+
*/
|
|
1998
|
+
canCreate(e) {
|
|
1999
|
+
return this.settings.create && e.length > 0 && this.settings.createFilter.call(this, e);
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Wraps this.`method` so that `new_fn` can be invoked 'before', 'after', or 'instead' of the original method
|
|
2003
|
+
*
|
|
2004
|
+
* this.hook('instead','onKeyDown',function( arg1, arg2 ...){
|
|
2005
|
+
*
|
|
2006
|
+
* });
|
|
2007
|
+
*/
|
|
2008
|
+
hook(e, t, i) {
|
|
2009
|
+
var n = this, o = n[t];
|
|
2010
|
+
n[t] = function() {
|
|
2011
|
+
var r, l;
|
|
2012
|
+
return e === "after" && (r = o.apply(n, arguments)), l = i.apply(n, arguments), e === "instead" ? l : (e === "before" && (r = o.apply(n, arguments)), r);
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
const Vt = (s, e, t, i) => {
|
|
2017
|
+
s.addEventListener(e, t, i);
|
|
2018
|
+
};
|
|
2019
|
+
function Nt() {
|
|
2020
|
+
Vt(this.input, "change", () => {
|
|
2021
|
+
this.sync();
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
const Kt = (s) => typeof s > "u" || s === null ? null : Rt(s), Rt = (s) => typeof s == "boolean" ? s ? "1" : "0" : s + "", Pe = (s, e = !1) => {
|
|
2025
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
2026
|
+
}, Bt = (s) => {
|
|
2027
|
+
if (s.jquery)
|
|
2028
|
+
return s[0];
|
|
2029
|
+
if (s instanceof HTMLElement)
|
|
2030
|
+
return s;
|
|
2031
|
+
if (zt(s)) {
|
|
2032
|
+
var e = document.createElement("template");
|
|
2033
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2034
|
+
}
|
|
2035
|
+
return document.querySelector(s);
|
|
2036
|
+
}, zt = (s) => typeof s == "string" && s.indexOf("<") > -1;
|
|
2037
|
+
function jt(s) {
|
|
2038
|
+
var e = this, t = e.onOptionSelect;
|
|
2039
|
+
e.settings.hideSelected = !1;
|
|
2040
|
+
const i = Object.assign({
|
|
2041
|
+
// so that the user may add different ones as well
|
|
2042
|
+
className: "tomselect-checkbox",
|
|
2043
|
+
// the following default to the historic plugin's values
|
|
2044
|
+
checkedClassNames: void 0,
|
|
2045
|
+
uncheckedClassNames: void 0
|
|
2046
|
+
}, s);
|
|
2047
|
+
var n = function(l, c) {
|
|
2048
|
+
c ? (l.checked = !0, i.uncheckedClassNames && l.classList.remove(...i.uncheckedClassNames), i.checkedClassNames && l.classList.add(...i.checkedClassNames)) : (l.checked = !1, i.checkedClassNames && l.classList.remove(...i.checkedClassNames), i.uncheckedClassNames && l.classList.add(...i.uncheckedClassNames));
|
|
2049
|
+
}, o = function(l) {
|
|
2050
|
+
setTimeout(() => {
|
|
2051
|
+
var c = l.querySelector("input." + i.className);
|
|
2052
|
+
c instanceof HTMLInputElement && n(c, l.classList.contains("selected"));
|
|
2053
|
+
}, 1);
|
|
2054
|
+
};
|
|
2055
|
+
e.hook("after", "setupTemplates", () => {
|
|
2056
|
+
var r = e.settings.render.option;
|
|
2057
|
+
e.settings.render.option = (l, c) => {
|
|
2058
|
+
var a = Bt(r.call(e, l, c)), u = document.createElement("input");
|
|
2059
|
+
i.className && u.classList.add(i.className), u.addEventListener("click", function(p) {
|
|
2060
|
+
Pe(p);
|
|
2061
|
+
}), u.type = "checkbox";
|
|
2062
|
+
const d = Kt(l[e.settings.valueField]);
|
|
2063
|
+
return n(u, !!(d && e.items.indexOf(d) > -1)), a.prepend(u), a;
|
|
2064
|
+
};
|
|
2065
|
+
}), e.on("item_remove", (r) => {
|
|
2066
|
+
var l = e.getOption(r);
|
|
2067
|
+
l && (l.classList.remove("selected"), o(l));
|
|
2068
|
+
}), e.on("item_add", (r) => {
|
|
2069
|
+
var l = e.getOption(r);
|
|
2070
|
+
l && o(l);
|
|
2071
|
+
}), e.hook("instead", "onOptionSelect", (r, l) => {
|
|
2072
|
+
if (l.classList.contains("selected")) {
|
|
2073
|
+
l.classList.remove("selected"), e.removeItem(l.dataset.value), e.refreshOptions(), Pe(r, !0);
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
t.call(e, r, l), o(l);
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
const Yt = (s) => {
|
|
2080
|
+
if (s.jquery)
|
|
2081
|
+
return s[0];
|
|
2082
|
+
if (s instanceof HTMLElement)
|
|
2083
|
+
return s;
|
|
2084
|
+
if (Qt(s)) {
|
|
2085
|
+
var e = document.createElement("template");
|
|
2086
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2087
|
+
}
|
|
2088
|
+
return document.querySelector(s);
|
|
2089
|
+
}, Qt = (s) => typeof s == "string" && s.indexOf("<") > -1;
|
|
2090
|
+
function Ut(s) {
|
|
2091
|
+
const e = this, t = Object.assign({
|
|
2092
|
+
className: "clear-button",
|
|
2093
|
+
title: "Clear All",
|
|
2094
|
+
html: (i) => `<div class="${i.className}" title="${i.title}">⨯</div>`
|
|
2095
|
+
}, s);
|
|
2096
|
+
e.on("initialize", () => {
|
|
2097
|
+
var i = Yt(t.html(t));
|
|
2098
|
+
i.addEventListener("click", (n) => {
|
|
2099
|
+
e.isLocked || (e.clear(), e.settings.mode === "single" && e.settings.allowEmptyOption && e.addItem(""), n.preventDefault(), n.stopPropagation());
|
|
2100
|
+
}), e.control.appendChild(i);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
const Gt = (s, e = !1) => {
|
|
2104
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
2105
|
+
}, Y = (s, e, t, i) => {
|
|
2106
|
+
s.addEventListener(e, t, i);
|
|
2107
|
+
}, qt = (s, e) => {
|
|
2108
|
+
if (Array.isArray(s))
|
|
2109
|
+
s.forEach(e);
|
|
2110
|
+
else
|
|
2111
|
+
for (var t in s)
|
|
2112
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
2113
|
+
}, Jt = (s) => {
|
|
2114
|
+
if (s.jquery)
|
|
2115
|
+
return s[0];
|
|
2116
|
+
if (s instanceof HTMLElement)
|
|
2117
|
+
return s;
|
|
2118
|
+
if (Wt(s)) {
|
|
2119
|
+
var e = document.createElement("template");
|
|
2120
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2121
|
+
}
|
|
2122
|
+
return document.querySelector(s);
|
|
2123
|
+
}, Wt = (s) => typeof s == "string" && s.indexOf("<") > -1, Xt = (s, e) => {
|
|
2124
|
+
qt(e, (t, i) => {
|
|
2125
|
+
t == null ? s.removeAttribute(i) : s.setAttribute(i, "" + t);
|
|
2126
|
+
});
|
|
2127
|
+
}, Zt = (s, e) => {
|
|
2128
|
+
var t;
|
|
2129
|
+
(t = s.parentNode) == null || t.insertBefore(e, s.nextSibling);
|
|
2130
|
+
}, es = (s, e) => {
|
|
2131
|
+
var t;
|
|
2132
|
+
(t = s.parentNode) == null || t.insertBefore(e, s);
|
|
2133
|
+
}, ts = (s, e) => {
|
|
2134
|
+
do {
|
|
2135
|
+
var t;
|
|
2136
|
+
if (e = (t = e) == null ? void 0 : t.previousElementSibling, s == e)
|
|
2137
|
+
return !0;
|
|
2138
|
+
} while (e && e.previousElementSibling);
|
|
2139
|
+
return !1;
|
|
2140
|
+
};
|
|
2141
|
+
function ss() {
|
|
2142
|
+
var s = this;
|
|
2143
|
+
if (s.settings.mode !== "multi") return;
|
|
2144
|
+
var e = s.lock, t = s.unlock;
|
|
2145
|
+
let i = !0, n;
|
|
2146
|
+
s.hook("after", "setupTemplates", () => {
|
|
2147
|
+
var o = s.settings.render.item;
|
|
2148
|
+
s.settings.render.item = (r, l) => {
|
|
2149
|
+
const c = Jt(o.call(s, r, l));
|
|
2150
|
+
Xt(c, {
|
|
2151
|
+
draggable: "true"
|
|
2152
|
+
});
|
|
2153
|
+
const a = (v) => {
|
|
2154
|
+
i || Gt(v), v.stopPropagation();
|
|
2155
|
+
}, u = (v) => {
|
|
2156
|
+
n = c, setTimeout(() => {
|
|
2157
|
+
c.classList.add("ts-dragging");
|
|
2158
|
+
}, 0);
|
|
2159
|
+
}, d = (v) => {
|
|
2160
|
+
v.preventDefault(), c.classList.add("ts-drag-over"), w(c, n);
|
|
2161
|
+
}, p = () => {
|
|
2162
|
+
c.classList.remove("ts-drag-over");
|
|
2163
|
+
}, w = (v, b) => {
|
|
2164
|
+
b !== void 0 && (ts(b, c) ? Zt(v, b) : es(v, b));
|
|
2165
|
+
}, f = () => {
|
|
2166
|
+
var v;
|
|
2167
|
+
document.querySelectorAll(".ts-drag-over").forEach((y) => y.classList.remove("ts-drag-over")), (v = n) == null || v.classList.remove("ts-dragging"), n = void 0;
|
|
2168
|
+
var b = [];
|
|
2169
|
+
s.control.querySelectorAll("[data-value]").forEach((y) => {
|
|
2170
|
+
if (y.dataset.value) {
|
|
2171
|
+
let h = y.dataset.value;
|
|
2172
|
+
h && b.push(h);
|
|
2173
|
+
}
|
|
2174
|
+
}), s.setValue(b);
|
|
2175
|
+
};
|
|
2176
|
+
return Y(c, "mousedown", a), Y(c, "dragstart", u), Y(c, "dragenter", d), Y(c, "dragover", d), Y(c, "dragleave", p), Y(c, "dragend", f), c;
|
|
2177
|
+
};
|
|
2178
|
+
}), s.hook("instead", "lock", () => (i = !1, e.call(s))), s.hook("instead", "unlock", () => (i = !0, t.call(s)));
|
|
2179
|
+
}
|
|
2180
|
+
const is = (s, e = !1) => {
|
|
2181
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
2182
|
+
}, ns = (s) => {
|
|
2183
|
+
if (s.jquery)
|
|
2184
|
+
return s[0];
|
|
2185
|
+
if (s instanceof HTMLElement)
|
|
2186
|
+
return s;
|
|
2187
|
+
if (rs(s)) {
|
|
2188
|
+
var e = document.createElement("template");
|
|
2189
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2190
|
+
}
|
|
2191
|
+
return document.querySelector(s);
|
|
2192
|
+
}, rs = (s) => typeof s == "string" && s.indexOf("<") > -1;
|
|
2193
|
+
function os(s) {
|
|
2194
|
+
const e = this, t = Object.assign({
|
|
2195
|
+
title: "Untitled",
|
|
2196
|
+
headerClass: "dropdown-header",
|
|
2197
|
+
titleRowClass: "dropdown-header-title",
|
|
2198
|
+
labelClass: "dropdown-header-label",
|
|
2199
|
+
closeClass: "dropdown-header-close",
|
|
2200
|
+
html: (i) => '<div class="' + i.headerClass + '"><div class="' + i.titleRowClass + '"><span class="' + i.labelClass + '">' + i.title + '</span><a class="' + i.closeClass + '">×</a></div></div>'
|
|
2201
|
+
}, s);
|
|
2202
|
+
e.on("initialize", () => {
|
|
2203
|
+
var i = ns(t.html(t)), n = i.querySelector("." + t.closeClass);
|
|
2204
|
+
n && n.addEventListener("click", (o) => {
|
|
2205
|
+
is(o, !0), e.close();
|
|
2206
|
+
}), e.dropdown.insertBefore(i, e.dropdown.firstChild);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
const ls = (s, e) => {
|
|
2210
|
+
if (Array.isArray(s))
|
|
2211
|
+
s.forEach(e);
|
|
2212
|
+
else
|
|
2213
|
+
for (var t in s)
|
|
2214
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
2215
|
+
}, as = (s, ...e) => {
|
|
2216
|
+
var t = cs(e);
|
|
2217
|
+
s = us(s), s.map((i) => {
|
|
2218
|
+
t.map((n) => {
|
|
2219
|
+
i.classList.remove(n);
|
|
2220
|
+
});
|
|
2221
|
+
});
|
|
2222
|
+
}, cs = (s) => {
|
|
2223
|
+
var e = [];
|
|
2224
|
+
return ls(s, (t) => {
|
|
2225
|
+
typeof t == "string" && (t = t.trim().split(/[\t\n\f\r\s]/)), Array.isArray(t) && (e = e.concat(t));
|
|
2226
|
+
}), e.filter(Boolean);
|
|
2227
|
+
}, us = (s) => (Array.isArray(s) || (s = [s]), s), ds = (s, e) => {
|
|
2228
|
+
if (!s) return -1;
|
|
2229
|
+
e = e || s.nodeName;
|
|
2230
|
+
for (var t = 0; s = s.previousElementSibling; )
|
|
2231
|
+
s.matches(e) && t++;
|
|
2232
|
+
return t;
|
|
2233
|
+
};
|
|
2234
|
+
function fs() {
|
|
2235
|
+
var s = this;
|
|
2236
|
+
s.hook("instead", "setCaret", (e) => {
|
|
2237
|
+
s.settings.mode === "single" || !s.control.contains(s.control_input) ? e = s.items.length : (e = Math.max(0, Math.min(s.items.length, e)), e != s.caretPos && !s.isPending && s.controlChildren().forEach((t, i) => {
|
|
2238
|
+
i < e ? s.control_input.insertAdjacentElement("beforebegin", t) : s.control.appendChild(t);
|
|
2239
|
+
})), s.caretPos = e;
|
|
2240
|
+
}), s.hook("instead", "moveCaret", (e) => {
|
|
2241
|
+
if (!s.isFocused) return;
|
|
2242
|
+
const t = s.getLastActive(e);
|
|
2243
|
+
if (t) {
|
|
2244
|
+
const i = ds(t);
|
|
2245
|
+
s.setCaret(e > 0 ? i + 1 : i), s.setActiveItem(), as(t, "last-active");
|
|
2246
|
+
} else
|
|
2247
|
+
s.setCaret(s.caretPos + e);
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
const ps = 27, hs = 9, gs = (s, e = !1) => {
|
|
2251
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
2252
|
+
}, ms = (s, e, t, i) => {
|
|
2253
|
+
s.addEventListener(e, t, i);
|
|
2254
|
+
}, vs = (s, e) => {
|
|
2255
|
+
if (Array.isArray(s))
|
|
2256
|
+
s.forEach(e);
|
|
2257
|
+
else
|
|
2258
|
+
for (var t in s)
|
|
2259
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
2260
|
+
}, De = (s) => {
|
|
2261
|
+
if (s.jquery)
|
|
2262
|
+
return s[0];
|
|
2263
|
+
if (s instanceof HTMLElement)
|
|
2264
|
+
return s;
|
|
2265
|
+
if (_s(s)) {
|
|
2266
|
+
var e = document.createElement("template");
|
|
2267
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2268
|
+
}
|
|
2269
|
+
return document.querySelector(s);
|
|
2270
|
+
}, _s = (s) => typeof s == "string" && s.indexOf("<") > -1, ys = (s, ...e) => {
|
|
2271
|
+
var t = Os(e);
|
|
2272
|
+
s = ws(s), s.map((i) => {
|
|
2273
|
+
t.map((n) => {
|
|
2274
|
+
i.classList.add(n);
|
|
2275
|
+
});
|
|
2276
|
+
});
|
|
2277
|
+
}, Os = (s) => {
|
|
2278
|
+
var e = [];
|
|
2279
|
+
return vs(s, (t) => {
|
|
2280
|
+
typeof t == "string" && (t = t.trim().split(/[\t\n\f\r\s]/)), Array.isArray(t) && (e = e.concat(t));
|
|
2281
|
+
}), e.filter(Boolean);
|
|
2282
|
+
}, ws = (s) => (Array.isArray(s) || (s = [s]), s);
|
|
2283
|
+
function bs() {
|
|
2284
|
+
const s = this;
|
|
2285
|
+
s.settings.shouldOpen = !0, s.hook("before", "setup", () => {
|
|
2286
|
+
s.focus_node = s.control, ys(s.control_input, "dropdown-input");
|
|
2287
|
+
const e = De('<div class="dropdown-input-wrap">');
|
|
2288
|
+
e.append(s.control_input), s.dropdown.insertBefore(e, s.dropdown.firstChild);
|
|
2289
|
+
const t = De('<input class="items-placeholder" tabindex="-1" />');
|
|
2290
|
+
t.placeholder = s.settings.placeholder || "", s.control.append(t);
|
|
2291
|
+
}), s.on("initialize", () => {
|
|
2292
|
+
s.control_input.addEventListener("keydown", (t) => {
|
|
2293
|
+
switch (t.keyCode) {
|
|
2294
|
+
case ps:
|
|
2295
|
+
s.isOpen && (gs(t, !0), s.close()), s.clearActiveItems();
|
|
2296
|
+
return;
|
|
2297
|
+
case hs:
|
|
2298
|
+
s.focus_node.tabIndex = -1;
|
|
2299
|
+
break;
|
|
2300
|
+
}
|
|
2301
|
+
return s.onKeyDown.call(s, t);
|
|
2302
|
+
}), s.on("blur", () => {
|
|
2303
|
+
s.focus_node.tabIndex = s.isDisabled ? -1 : s.tabIndex;
|
|
2304
|
+
}), s.on("dropdown_open", () => {
|
|
2305
|
+
s.control_input.focus();
|
|
2306
|
+
});
|
|
2307
|
+
const e = s.onBlur;
|
|
2308
|
+
s.hook("instead", "onBlur", (t) => {
|
|
2309
|
+
if (!(t && t.relatedTarget == s.control_input))
|
|
2310
|
+
return e.call(s);
|
|
2311
|
+
}), ms(s.control_input, "blur", () => s.onBlur()), s.hook("before", "close", () => {
|
|
2312
|
+
s.isOpen && s.focus_node.focus({
|
|
2313
|
+
preventScroll: !0
|
|
2314
|
+
});
|
|
2315
|
+
});
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
const te = (s, e, t, i) => {
|
|
2319
|
+
s.addEventListener(e, t, i);
|
|
2320
|
+
};
|
|
2321
|
+
function As() {
|
|
2322
|
+
var s = this;
|
|
2323
|
+
s.on("initialize", () => {
|
|
2324
|
+
var e = document.createElement("span"), t = s.control_input;
|
|
2325
|
+
e.style.cssText = "position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ", s.wrapper.appendChild(e);
|
|
2326
|
+
var i = ["letterSpacing", "fontSize", "fontFamily", "fontWeight", "textTransform"];
|
|
2327
|
+
for (const o of i)
|
|
2328
|
+
e.style[o] = t.style[o];
|
|
2329
|
+
var n = () => {
|
|
2330
|
+
e.textContent = t.value, t.style.width = e.clientWidth + "px";
|
|
2331
|
+
};
|
|
2332
|
+
n(), s.on("update item_add item_remove", n), te(t, "input", n), te(t, "keyup", n), te(t, "blur", n), te(t, "update", n);
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
function Ss() {
|
|
2336
|
+
var s = this, e = s.deleteSelection;
|
|
2337
|
+
this.hook("instead", "deleteSelection", (t) => s.activeItems.length ? e.call(s, t) : !1);
|
|
2338
|
+
}
|
|
2339
|
+
function Cs() {
|
|
2340
|
+
this.hook("instead", "setActiveItem", () => {
|
|
2341
|
+
}), this.hook("instead", "selectAll", () => {
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
const He = 37, xs = 39, Is = (s, e, t) => {
|
|
2345
|
+
for (; s && s.matches; ) {
|
|
2346
|
+
if (s.matches(e))
|
|
2347
|
+
return s;
|
|
2348
|
+
s = s.parentNode;
|
|
2349
|
+
}
|
|
2350
|
+
}, Es = (s, e) => {
|
|
2351
|
+
if (!s) return -1;
|
|
2352
|
+
e = e || s.nodeName;
|
|
2353
|
+
for (var t = 0; s = s.previousElementSibling; )
|
|
2354
|
+
s.matches(e) && t++;
|
|
2355
|
+
return t;
|
|
2356
|
+
};
|
|
2357
|
+
function Ls() {
|
|
2358
|
+
var s = this, e = s.onKeyDown;
|
|
2359
|
+
s.hook("instead", "onKeyDown", (t) => {
|
|
2360
|
+
var i, n, o, r;
|
|
2361
|
+
if (!s.isOpen || !(t.keyCode === He || t.keyCode === xs))
|
|
2362
|
+
return e.call(s, t);
|
|
2363
|
+
s.ignoreHover = !0, r = Is(s.activeOption, "[data-group]"), i = Es(s.activeOption, "[data-selectable]"), r && (t.keyCode === He ? r = r.previousSibling : r = r.nextSibling, r && (o = r.querySelectorAll("[data-selectable]"), n = o[Math.min(o.length - 1, i)], n && s.setActiveOption(n)));
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
const Fs = (s) => (s + "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), Me = (s, e = !1) => {
|
|
2367
|
+
s && (s.preventDefault(), e && s.stopPropagation());
|
|
2368
|
+
}, Ve = (s, e, t, i) => {
|
|
2369
|
+
s.addEventListener(e, t, i);
|
|
2370
|
+
}, Ne = (s) => {
|
|
2371
|
+
if (s.jquery)
|
|
2372
|
+
return s[0];
|
|
2373
|
+
if (s instanceof HTMLElement)
|
|
2374
|
+
return s;
|
|
2375
|
+
if (ks(s)) {
|
|
2376
|
+
var e = document.createElement("template");
|
|
2377
|
+
return e.innerHTML = s.trim(), e.content.firstChild;
|
|
2378
|
+
}
|
|
2379
|
+
return document.querySelector(s);
|
|
2380
|
+
}, ks = (s) => typeof s == "string" && s.indexOf("<") > -1;
|
|
2381
|
+
function $s(s) {
|
|
2382
|
+
const e = Object.assign({
|
|
2383
|
+
label: "×",
|
|
2384
|
+
title: "Remove",
|
|
2385
|
+
className: "remove",
|
|
2386
|
+
append: !0
|
|
2387
|
+
}, s);
|
|
2388
|
+
var t = this;
|
|
2389
|
+
if (e.append) {
|
|
2390
|
+
var i = '<a href="javascript:void(0)" class="' + e.className + '" tabindex="-1" title="' + Fs(e.title) + '">' + e.label + "</a>";
|
|
2391
|
+
t.hook("after", "setupTemplates", () => {
|
|
2392
|
+
var n = t.settings.render.item;
|
|
2393
|
+
t.settings.render.item = (o, r) => {
|
|
2394
|
+
var l = Ne(n.call(t, o, r)), c = Ne(i);
|
|
2395
|
+
return l.appendChild(c), Ve(c, "mousedown", (a) => {
|
|
2396
|
+
Me(a, !0);
|
|
2397
|
+
}), Ve(c, "click", (a) => {
|
|
2398
|
+
t.isLocked || (Me(a, !0), !t.isLocked && t.shouldDelete([l], a) && (t.removeItem(l), t.refreshOptions(!1), t.inputState()));
|
|
2399
|
+
}), l;
|
|
2400
|
+
};
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
function Ts(s) {
|
|
2405
|
+
const e = this, t = Object.assign({
|
|
2406
|
+
text: (i) => i[e.settings.labelField]
|
|
2407
|
+
}, s);
|
|
2408
|
+
e.on("item_remove", function(i) {
|
|
2409
|
+
if (e.isFocused && e.control_input.value.trim() === "") {
|
|
2410
|
+
var n = e.options[i];
|
|
2411
|
+
n && e.setTextboxValue(t.text.call(e, n));
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
const Ps = (s, e) => {
|
|
2416
|
+
if (Array.isArray(s))
|
|
2417
|
+
s.forEach(e);
|
|
2418
|
+
else
|
|
2419
|
+
for (var t in s)
|
|
2420
|
+
s.hasOwnProperty(t) && e(s[t], t);
|
|
2421
|
+
}, Ds = (s, ...e) => {
|
|
2422
|
+
var t = Hs(e);
|
|
2423
|
+
s = Ms(s), s.map((i) => {
|
|
2424
|
+
t.map((n) => {
|
|
2425
|
+
i.classList.add(n);
|
|
2426
|
+
});
|
|
2427
|
+
});
|
|
2428
|
+
}, Hs = (s) => {
|
|
2429
|
+
var e = [];
|
|
2430
|
+
return Ps(s, (t) => {
|
|
2431
|
+
typeof t == "string" && (t = t.trim().split(/[\t\n\f\r\s]/)), Array.isArray(t) && (e = e.concat(t));
|
|
2432
|
+
}), e.filter(Boolean);
|
|
2433
|
+
}, Ms = (s) => (Array.isArray(s) || (s = [s]), s);
|
|
2434
|
+
function Vs() {
|
|
2435
|
+
const s = this, e = s.canLoad, t = s.clearActiveOption, i = s.loadCallback;
|
|
2436
|
+
var n = {}, o, r = !1, l, c = [];
|
|
2437
|
+
if (s.settings.shouldLoadMore || (s.settings.shouldLoadMore = () => {
|
|
2438
|
+
if (o.clientHeight / (o.scrollHeight - o.scrollTop) > 0.9)
|
|
2439
|
+
return !0;
|
|
2440
|
+
if (s.activeOption) {
|
|
2441
|
+
var p = s.selectable(), w = Array.from(p).indexOf(s.activeOption);
|
|
2442
|
+
if (w >= p.length - 2)
|
|
2443
|
+
return !0;
|
|
2444
|
+
}
|
|
2445
|
+
return !1;
|
|
2446
|
+
}), !s.settings.firstUrl)
|
|
2447
|
+
throw "virtual_scroll plugin requires a firstUrl() method";
|
|
2448
|
+
s.settings.sortField = [{
|
|
2449
|
+
field: "$order"
|
|
2450
|
+
}, {
|
|
2451
|
+
field: "$score"
|
|
2452
|
+
}];
|
|
2453
|
+
const a = (d) => typeof s.settings.maxOptions == "number" && o.children.length >= s.settings.maxOptions ? !1 : !!(d in n && n[d]), u = (d, p) => s.items.indexOf(p) >= 0 || c.indexOf(p) >= 0;
|
|
2454
|
+
s.setNextUrl = (d, p) => {
|
|
2455
|
+
n[d] = p;
|
|
2456
|
+
}, s.getUrl = (d) => {
|
|
2457
|
+
if (d in n) {
|
|
2458
|
+
const p = n[d];
|
|
2459
|
+
return n[d] = !1, p;
|
|
2460
|
+
}
|
|
2461
|
+
return s.clearPagination(), s.settings.firstUrl.call(s, d);
|
|
2462
|
+
}, s.clearPagination = () => {
|
|
2463
|
+
n = {};
|
|
2464
|
+
}, s.hook("instead", "clearActiveOption", () => {
|
|
2465
|
+
if (!r)
|
|
2466
|
+
return t.call(s);
|
|
2467
|
+
}), s.hook("instead", "canLoad", (d) => d in n ? a(d) : e.call(s, d)), s.hook("instead", "loadCallback", (d, p) => {
|
|
2468
|
+
if (!r)
|
|
2469
|
+
s.clearOptions(u);
|
|
2470
|
+
else if (l) {
|
|
2471
|
+
const w = d[0];
|
|
2472
|
+
w !== void 0 && (l.dataset.value = w[s.settings.valueField]);
|
|
2473
|
+
}
|
|
2474
|
+
i.call(s, d, p), r = !1;
|
|
2475
|
+
}), s.hook("after", "refreshOptions", () => {
|
|
2476
|
+
const d = s.lastValue;
|
|
2477
|
+
var p;
|
|
2478
|
+
a(d) ? (p = s.render("loading_more", {
|
|
2479
|
+
query: d
|
|
2480
|
+
}), p && (p.setAttribute("data-selectable", ""), l = p)) : d in n && !o.querySelector(".no-results") && (p = s.render("no_more_results", {
|
|
2481
|
+
query: d
|
|
2482
|
+
})), p && (Ds(p, s.settings.optionClass), o.append(p));
|
|
2483
|
+
}), s.on("initialize", () => {
|
|
2484
|
+
c = Object.keys(s.options), o = s.dropdown_content, s.settings.render = Object.assign({}, {
|
|
2485
|
+
loading_more: () => '<div class="loading-more-results">Loading more results ... </div>',
|
|
2486
|
+
no_more_results: () => '<div class="no-more-results">No more results</div>'
|
|
2487
|
+
}, s.settings.render), o.addEventListener("scroll", () => {
|
|
2488
|
+
s.settings.shouldLoadMore.call(s) && a(s.lastValue) && (r || (r = !0, s.load.call(s, s.lastValue)));
|
|
2489
|
+
});
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
F.define("change_listener", Nt);
|
|
2493
|
+
F.define("checkbox_options", jt);
|
|
2494
|
+
F.define("clear_button", Ut);
|
|
2495
|
+
F.define("drag_drop", ss);
|
|
2496
|
+
F.define("dropdown_header", os);
|
|
2497
|
+
F.define("caret_position", fs);
|
|
2498
|
+
F.define("dropdown_input", bs);
|
|
2499
|
+
F.define("input_autogrow", As);
|
|
2500
|
+
F.define("no_backspace_delete", Ss);
|
|
2501
|
+
F.define("no_active_items", Cs);
|
|
2502
|
+
F.define("optgroup_columns", Ls);
|
|
2503
|
+
F.define("remove_button", $s);
|
|
2504
|
+
F.define("restore_on_backspace", Ts);
|
|
2505
|
+
F.define("virtual_scroll", Vs);
|
|
2506
|
+
const Ns = "/tom-select.bootstrap5.css";
|
|
2507
|
+
var $, Q, z, V, U, oe, Ue;
|
|
2508
|
+
const ye = class ye extends HTMLElement {
|
|
2509
|
+
constructor() {
|
|
2510
|
+
super();
|
|
2511
|
+
K(this, oe);
|
|
2512
|
+
K(this, $);
|
|
2513
|
+
K(this, Q);
|
|
2514
|
+
K(this, z);
|
|
2515
|
+
K(this, V);
|
|
2516
|
+
K(this, U, {});
|
|
2517
|
+
H(this, $, document.createElement("select")), H(this, Q, this.attachShadow({ mode: "open" })), H(this, z, this.attachInternals());
|
|
2518
|
+
}
|
|
2519
|
+
connectedCallback() {
|
|
2520
|
+
this.hasAttribute("name") && (x(this, $).name = this.getAttribute("name")), this.hasAttribute("multiple") && x(this, $).setAttribute("multiple", "");
|
|
2521
|
+
const t = document.createElement("link");
|
|
2522
|
+
t.setAttribute("rel", "stylesheet"), t.setAttribute("href", Ns), x(this, Q).appendChild(x(this, $)), x(this, Q).appendChild(t);
|
|
2523
|
+
try {
|
|
2524
|
+
H(this, U, this.getAttributeNames().filter(
|
|
2525
|
+
(i) => i === "options" || i === "value-field" || i === "label-field" || i === "search-field" || i === "items" || i === "optgroup-field" || i === "optgroups"
|
|
2526
|
+
).reduce((i, n) => {
|
|
2527
|
+
const o = n.split("."), r = o.pop(), l = this.getAttribute(n), c = o.reduce((a, u) => (u in a || (a[u] = {}), a[u]), i);
|
|
2528
|
+
return c[Xe(r)] = Ze(l), i;
|
|
2529
|
+
}, {}));
|
|
2530
|
+
} catch (i) {
|
|
2531
|
+
console.error("Invalid options JSON:", i), H(this, U, {});
|
|
2532
|
+
}
|
|
2533
|
+
this.tomSelect = new F(x(this, $), {
|
|
2534
|
+
...x(this, U),
|
|
2535
|
+
plugins: ["remove_button", "clear_button"],
|
|
2536
|
+
highlight: !0
|
|
2537
|
+
}), H(this, V, x(this, $).value), x(this, z).setFormValue(x(this, V)), x(this, $).addEventListener("change", (i) => we(this, oe, Ue).call(this, i));
|
|
2538
|
+
}
|
|
2539
|
+
get value() {
|
|
2540
|
+
return x(this, V);
|
|
2541
|
+
}
|
|
2542
|
+
set value(t) {
|
|
2543
|
+
H(this, V, t), x(this, $).value = t, x(this, z).setFormValue(t);
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
$ = new WeakMap(), Q = new WeakMap(), z = new WeakMap(), V = new WeakMap(), U = new WeakMap(), oe = new WeakSet(), Ue = function(t) {
|
|
2547
|
+
const i = Array.from(x(this, $).selectedOptions).map((o) => o.value);
|
|
2548
|
+
H(this, V, i);
|
|
2549
|
+
const n = new FormData();
|
|
2550
|
+
for (const o of i)
|
|
2551
|
+
n.append(x(this, $).name, o);
|
|
2552
|
+
x(this, z).setFormValue(n);
|
|
2553
|
+
}, ye.formAssociated = !0;
|
|
2554
|
+
let ve = ye;
|
|
2555
|
+
customElements.define("sleek-select", ve);
|