tom-select-rails 0.2.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tom-select-rails/version.rb +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js +9 -5
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js +13 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js +12 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js +9 -4
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js +16 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/utils.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/utils.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js +164 -160
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js +94 -89
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js +121 -116
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js +234 -230
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js +112 -107
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js +149 -144
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js +277 -269
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js +329 -272
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js +268 -209
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js +348 -291
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/types/tom-select.d.ts +6 -6
- data/vendor/assets/javascripts/tom-select-rails/types/types/settings.d.ts +19 -22
- data/vendor/assets/javascripts/tom-select-rails/types/utils.d.ts +5 -5
- data/vendor/assets/javascripts/tom-select-rails/types/vanilla.d.ts +2 -2
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css +41 -19
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css +61 -34
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css +39 -17
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css +41 -19
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/clear_button.scss +12 -5
- data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/remove_button.scss +34 -8
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap4.scss +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap5.scss +20 -10
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.default.scss +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.scss +11 -2
- metadata +3 -3
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Tom Select v2.
|
2
|
+
* Tom Select v2.2.0
|
3
3
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
*/
|
5
5
|
|
@@ -37,9 +37,9 @@
|
|
37
37
|
|
38
38
|
on(events, fct) {
|
39
39
|
forEvents(events, event => {
|
40
|
-
|
41
|
-
|
42
|
-
this._events[event]
|
40
|
+
const event_array = this._events[event] || [];
|
41
|
+
event_array.push(fct);
|
42
|
+
this._events[event] = event_array;
|
43
43
|
});
|
44
44
|
}
|
45
45
|
|
@@ -52,21 +52,26 @@
|
|
52
52
|
}
|
53
53
|
|
54
54
|
forEvents(events, event => {
|
55
|
-
if (n === 1)
|
56
|
-
|
55
|
+
if (n === 1) {
|
56
|
+
delete this._events[event];
|
57
|
+
return;
|
58
|
+
}
|
57
59
|
|
58
|
-
this._events[event]
|
60
|
+
const event_array = this._events[event];
|
61
|
+
if (event_array === undefined) return;
|
62
|
+
event_array.splice(event_array.indexOf(fct), 1);
|
63
|
+
this._events[event] = event_array;
|
59
64
|
});
|
60
65
|
}
|
61
66
|
|
62
67
|
trigger(events, ...args) {
|
63
68
|
var self = this;
|
64
69
|
forEvents(events, event => {
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
const event_array = self._events[event];
|
71
|
+
if (event_array === undefined) return;
|
72
|
+
event_array.forEach(fct => {
|
68
73
|
fct.apply(self, args);
|
69
|
-
}
|
74
|
+
});
|
70
75
|
});
|
71
76
|
}
|
72
77
|
|
@@ -193,69 +198,124 @@
|
|
193
198
|
};
|
194
199
|
}
|
195
200
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
201
|
+
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
202
|
+
/**
|
203
|
+
* Convert array of strings to a regular expression
|
204
|
+
* ex ['ab','a'] => (?:ab|a)
|
205
|
+
* ex ['a','b'] => [ab]
|
206
|
+
* @param {string[]} chars
|
207
|
+
* @return {string}
|
208
|
+
*/
|
209
|
+
const arrayToPattern = chars => {
|
210
|
+
chars = chars.filter(Boolean);
|
200
211
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
'
|
206
|
-
'ø': 'o'
|
212
|
+
if (chars.length < 2) {
|
213
|
+
return chars[0] || '';
|
214
|
+
}
|
215
|
+
|
216
|
+
return maxValueLength(chars) == 1 ? '[' + chars.join('') + ']' : '(?:' + chars.join('|') + ')';
|
207
217
|
};
|
208
|
-
const convert_pat = new RegExp(Object.keys(latin_convert).join('|'), 'gu');
|
209
|
-
const code_points = [[0, 65535]];
|
210
218
|
/**
|
211
|
-
*
|
212
|
-
*
|
213
|
-
*
|
219
|
+
* @param {string[]} array
|
220
|
+
* @return {string}
|
214
221
|
*/
|
215
222
|
|
216
|
-
const
|
217
|
-
|
218
|
-
return
|
223
|
+
const sequencePattern = array => {
|
224
|
+
if (!hasDuplicates(array)) {
|
225
|
+
return array.join('');
|
226
|
+
}
|
227
|
+
|
228
|
+
let pattern = '';
|
229
|
+
let prev_char_count = 0;
|
230
|
+
|
231
|
+
const prev_pattern = () => {
|
232
|
+
if (prev_char_count > 1) {
|
233
|
+
pattern += '{' + prev_char_count + '}';
|
234
|
+
}
|
235
|
+
};
|
236
|
+
|
237
|
+
array.forEach((char, i) => {
|
238
|
+
if (char === array[i - 1]) {
|
239
|
+
prev_char_count++;
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
|
243
|
+
prev_pattern();
|
244
|
+
pattern += char;
|
245
|
+
prev_char_count = 1;
|
219
246
|
});
|
247
|
+
prev_pattern();
|
248
|
+
return pattern;
|
220
249
|
};
|
221
250
|
/**
|
222
251
|
* Convert array of strings to a regular expression
|
223
252
|
* ex ['ab','a'] => (?:ab|a)
|
224
253
|
* ex ['a','b'] => [ab]
|
225
|
-
*
|
254
|
+
* @param {Set<string>} chars
|
255
|
+
* @return {string}
|
226
256
|
*/
|
227
257
|
|
228
|
-
const
|
229
|
-
|
230
|
-
|
231
|
-
|
258
|
+
const setToPattern = chars => {
|
259
|
+
let array = toArray(chars);
|
260
|
+
return arrayToPattern(array);
|
261
|
+
};
|
262
|
+
/**
|
263
|
+
*
|
264
|
+
* https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values
|
265
|
+
* @param {any[]} array
|
266
|
+
*/
|
232
267
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
268
|
+
const hasDuplicates = array => {
|
269
|
+
return new Set(array).size !== array.length;
|
270
|
+
};
|
271
|
+
/**
|
272
|
+
* https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error
|
273
|
+
* @param {string} str
|
274
|
+
* @return {string}
|
275
|
+
*/
|
237
276
|
|
238
|
-
|
239
|
-
|
240
|
-
|
277
|
+
const escape_regex = str => {
|
278
|
+
return (str + '').replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu, '\\$1');
|
279
|
+
};
|
280
|
+
/**
|
281
|
+
* Return the max length of array values
|
282
|
+
* @param {string[]} array
|
283
|
+
*
|
284
|
+
*/
|
241
285
|
|
242
|
-
|
286
|
+
const maxValueLength = array => {
|
287
|
+
return array.reduce((longest, value) => Math.max(longest, unicodeLength(value)), 0);
|
243
288
|
};
|
244
|
-
|
245
|
-
|
246
|
-
|
289
|
+
/**
|
290
|
+
* @param {string} str
|
291
|
+
*/
|
292
|
+
|
293
|
+
const unicodeLength = str => {
|
294
|
+
return toArray(str).length;
|
247
295
|
};
|
296
|
+
/**
|
297
|
+
* @param {any} p
|
298
|
+
* @return {any[]}
|
299
|
+
*/
|
300
|
+
|
301
|
+
const toArray = p => Array.from(p);
|
302
|
+
|
303
|
+
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
248
304
|
/**
|
249
305
|
* Get all possible combinations of substrings that add up to the given string
|
250
306
|
* https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string
|
251
|
-
*
|
307
|
+
* @param {string} input
|
308
|
+
* @return {string[][]}
|
252
309
|
*/
|
253
|
-
|
254
310
|
const allSubstrings = input => {
|
255
311
|
if (input.length === 1) return [[input]];
|
256
|
-
|
257
|
-
|
258
|
-
|
312
|
+
/** @type {string[][]} */
|
313
|
+
|
314
|
+
let result = [];
|
315
|
+
const start = input.substring(1);
|
316
|
+
const suba = allSubstrings(start);
|
317
|
+
suba.forEach(function (subresult) {
|
318
|
+
let tmp = subresult.slice(0);
|
259
319
|
tmp[0] = input.charAt(0) + tmp[0];
|
260
320
|
result.push(tmp);
|
261
321
|
tmp = subresult.slice(0);
|
@@ -264,108 +324,500 @@
|
|
264
324
|
});
|
265
325
|
return result;
|
266
326
|
};
|
327
|
+
|
328
|
+
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
329
|
+
|
330
|
+
/**
|
331
|
+
* @typedef {{[key:string]:string}} TUnicodeMap
|
332
|
+
* @typedef {{[key:string]:Set<string>}} TUnicodeSets
|
333
|
+
* @typedef {[[number,number]]} TCodePoints
|
334
|
+
* @typedef {{folded:string,composed:string,code_point:number}} TCodePointObj
|
335
|
+
* @typedef {{start:number,end:number,length:number,substr:string}} TSequencePart
|
336
|
+
*/
|
337
|
+
/** @type {TCodePoints} */
|
338
|
+
|
339
|
+
const code_points = [[0, 65535]];
|
340
|
+
const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}]'; // \u{2bc}
|
341
|
+
|
342
|
+
/** @type {TUnicodeMap} */
|
343
|
+
|
344
|
+
let unicode_map;
|
345
|
+
/** @type {RegExp} */
|
346
|
+
|
347
|
+
let multi_char_reg;
|
348
|
+
const max_char_length = 3;
|
349
|
+
/** @type {TUnicodeMap} */
|
350
|
+
|
351
|
+
const latin_convert = {
|
352
|
+
'æ': 'ae',
|
353
|
+
'ⱥ': 'a',
|
354
|
+
'ø': 'o',
|
355
|
+
'⁄': '/',
|
356
|
+
'∕': '/'
|
357
|
+
};
|
358
|
+
const convert_pat = new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
|
267
359
|
/**
|
268
|
-
*
|
360
|
+
* Initialize the unicode_map from the give code point ranges
|
269
361
|
*
|
362
|
+
* @param {TCodePoints=} _code_points
|
363
|
+
*/
|
364
|
+
|
365
|
+
const initialize = _code_points => {
|
366
|
+
if (unicode_map !== undefined) return;
|
367
|
+
unicode_map = generateMap(_code_points || code_points);
|
368
|
+
};
|
369
|
+
/**
|
370
|
+
* Helper method for normalize a string
|
371
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
|
372
|
+
* @param {string} str
|
373
|
+
* @param {string} form
|
374
|
+
*/
|
375
|
+
|
376
|
+
const normalize = (str, form = 'NFKD') => str.normalize(form);
|
377
|
+
/**
|
378
|
+
* Compatibility Decomposition without reordering string
|
379
|
+
* calling str.normalize('NFKD') on \u{594}\u{595}\u{596} becomes \u{596}\u{594}\u{595}
|
380
|
+
* @param {string} str
|
381
|
+
*/
|
382
|
+
|
383
|
+
const decompose = str => {
|
384
|
+
if (str.match(/[\u0f71-\u0f81]/)) {
|
385
|
+
return toArray(str).reduce(
|
386
|
+
/**
|
387
|
+
* @param {string} result
|
388
|
+
* @param {string} char
|
389
|
+
*/
|
390
|
+
(result, char) => {
|
391
|
+
return result + normalize(char);
|
392
|
+
}, '');
|
393
|
+
}
|
394
|
+
|
395
|
+
return normalize(str);
|
396
|
+
};
|
397
|
+
/**
|
398
|
+
* Remove accents
|
399
|
+
* via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
|
400
|
+
* @param {string} str
|
401
|
+
* @return {string}
|
270
402
|
*/
|
271
403
|
|
272
|
-
const
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
404
|
+
const asciifold = str => {
|
405
|
+
return decompose(str).toLowerCase().replace(convert_pat, (
|
406
|
+
/** @type {string} */
|
407
|
+
char) => {
|
408
|
+
return latin_convert[char] || '';
|
409
|
+
});
|
410
|
+
};
|
411
|
+
/**
|
412
|
+
* Generate a list of unicode variants from the list of code points
|
413
|
+
* @param {TCodePoints} code_points
|
414
|
+
* @yield {TCodePointObj}
|
415
|
+
*/
|
278
416
|
|
279
|
-
|
417
|
+
function* generator(code_points) {
|
418
|
+
for (const [code_point_min, code_point_max] of code_points) {
|
419
|
+
for (let i = code_point_min; i <= code_point_max; i++) {
|
420
|
+
let composed = String.fromCharCode(i);
|
421
|
+
let folded = asciifold(composed);
|
422
|
+
|
423
|
+
if (folded == composed.toLowerCase()) {
|
280
424
|
continue;
|
281
|
-
} // skip when
|
425
|
+
} // skip when folded is a string longer than 3 characters long
|
282
426
|
// bc the resulting regex patterns will be long
|
283
427
|
// eg:
|
284
|
-
//
|
285
|
-
//
|
428
|
+
// folded صلى الله عليه وسلم length 18 code point 65018
|
429
|
+
// folded جل جلاله length 8 code point 65019
|
286
430
|
|
287
431
|
|
288
|
-
if (
|
432
|
+
if (folded.length > max_char_length) {
|
289
433
|
continue;
|
290
434
|
}
|
291
435
|
|
292
|
-
if (
|
293
|
-
|
436
|
+
if (folded.length == 0) {
|
437
|
+
continue;
|
294
438
|
}
|
295
439
|
|
296
|
-
|
440
|
+
let decomposed = normalize(composed);
|
441
|
+
let recomposed = normalize(decomposed, 'NFC');
|
297
442
|
|
298
|
-
if (
|
443
|
+
if (recomposed === composed && folded === decomposed) {
|
299
444
|
continue;
|
300
445
|
}
|
301
446
|
|
302
|
-
|
447
|
+
yield {
|
448
|
+
folded: folded,
|
449
|
+
composed: composed,
|
450
|
+
code_point: i
|
451
|
+
};
|
452
|
+
}
|
453
|
+
}
|
454
|
+
}
|
455
|
+
/**
|
456
|
+
* Generate a unicode map from the list of code points
|
457
|
+
* @param {TCodePoints} code_points
|
458
|
+
* @return {TUnicodeSets}
|
459
|
+
*/
|
460
|
+
|
461
|
+
const generateSets = code_points => {
|
462
|
+
/** @type {{[key:string]:Set<string>}} */
|
463
|
+
const unicode_sets = {};
|
464
|
+
/**
|
465
|
+
* @param {string} folded
|
466
|
+
* @param {string} to_add
|
467
|
+
*/
|
468
|
+
|
469
|
+
const addMatching = (folded, to_add) => {
|
470
|
+
/** @type {Set<string>} */
|
471
|
+
const folded_set = unicode_sets[folded] || new Set();
|
472
|
+
const patt = new RegExp('^' + setToPattern(folded_set) + '$', 'iu');
|
473
|
+
|
474
|
+
if (to_add.match(patt)) {
|
475
|
+
return;
|
303
476
|
}
|
304
|
-
}); // filter out if there's only one character in the list
|
305
477
|
|
306
|
-
|
478
|
+
folded_set.add(escape_regex(to_add));
|
479
|
+
unicode_sets[folded] = folded_set;
|
480
|
+
};
|
307
481
|
|
308
|
-
for (let
|
309
|
-
|
482
|
+
for (let value of generator(code_points)) {
|
483
|
+
addMatching(value.folded, value.folded);
|
484
|
+
addMatching(value.folded, value.composed);
|
485
|
+
}
|
486
|
+
|
487
|
+
return unicode_sets;
|
488
|
+
};
|
489
|
+
/**
|
490
|
+
* Generate a unicode map from the list of code points
|
491
|
+
* ae => (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))
|
492
|
+
*
|
493
|
+
* @param {TCodePoints} code_points
|
494
|
+
* @return {TUnicodeMap}
|
495
|
+
*/
|
310
496
|
|
311
|
-
|
312
|
-
|
497
|
+
const generateMap = code_points => {
|
498
|
+
/** @type {TUnicodeSets} */
|
499
|
+
const unicode_sets = generateSets(code_points);
|
500
|
+
/** @type {TUnicodeMap} */
|
501
|
+
|
502
|
+
const unicode_map = {};
|
503
|
+
/** @type {string[]} */
|
504
|
+
|
505
|
+
let multi_char = [];
|
506
|
+
|
507
|
+
for (let folded in unicode_sets) {
|
508
|
+
let set = unicode_sets[folded];
|
509
|
+
|
510
|
+
if (set) {
|
511
|
+
unicode_map[folded] = setToPattern(set);
|
313
512
|
}
|
314
|
-
} // latin character pattern
|
315
|
-
// match longer substrings first
|
316
|
-
|
317
|
-
|
318
|
-
latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length);
|
319
|
-
latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns
|
320
|
-
// ae needs:
|
321
|
-
// (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))
|
322
|
-
|
323
|
-
var diacritic_patterns = {};
|
324
|
-
latin_chars.sort((a, b) => a.length - b.length).forEach(latin => {
|
325
|
-
var substrings = allSubstrings(latin);
|
326
|
-
var pattern = substrings.map(sub_pat => {
|
327
|
-
sub_pat = sub_pat.map(l => {
|
328
|
-
if (diacritics.hasOwnProperty(l)) {
|
329
|
-
return escapeToPattern(diacritics[l]);
|
330
|
-
}
|
331
513
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
514
|
+
if (folded.length > 1) {
|
515
|
+
multi_char.push(escape_regex(folded));
|
516
|
+
}
|
517
|
+
}
|
518
|
+
|
519
|
+
multi_char.sort((a, b) => b.length - a.length);
|
520
|
+
const multi_char_patt = arrayToPattern(multi_char);
|
521
|
+
multi_char_reg = new RegExp('^' + multi_char_patt, 'u');
|
522
|
+
return unicode_map;
|
523
|
+
};
|
524
|
+
/**
|
525
|
+
* Map each element of an array from it's folded value to all possible unicode matches
|
526
|
+
* @param {string[]} strings
|
527
|
+
* @param {number} min_replacement
|
528
|
+
* @return {string}
|
529
|
+
*/
|
530
|
+
|
531
|
+
const mapSequence = (strings, min_replacement = 1) => {
|
532
|
+
let chars_replaced = 0;
|
533
|
+
strings = strings.map(str => {
|
534
|
+
if (unicode_map[str]) {
|
535
|
+
chars_replaced += str.length;
|
536
|
+
}
|
537
|
+
|
538
|
+
return unicode_map[str] || str;
|
337
539
|
});
|
338
|
-
|
540
|
+
|
541
|
+
if (chars_replaced >= min_replacement) {
|
542
|
+
return sequencePattern(strings);
|
543
|
+
}
|
544
|
+
|
545
|
+
return '';
|
339
546
|
};
|
340
547
|
/**
|
341
|
-
*
|
342
|
-
*
|
548
|
+
* Convert a short string and split it into all possible patterns
|
549
|
+
* Keep a pattern only if min_replacement is met
|
550
|
+
*
|
551
|
+
* 'abc'
|
552
|
+
* => [['abc'],['ab','c'],['a','bc'],['a','b','c']]
|
553
|
+
* => ['abc-pattern','ab-c-pattern'...]
|
343
554
|
*
|
555
|
+
*
|
556
|
+
* @param {string} str
|
557
|
+
* @param {number} min_replacement
|
558
|
+
* @return {string}
|
559
|
+
*/
|
560
|
+
|
561
|
+
const substringsToPattern = (str, min_replacement = 1) => {
|
562
|
+
min_replacement = Math.max(min_replacement, str.length - 1);
|
563
|
+
return arrayToPattern(allSubstrings(str).map(sub_pat => {
|
564
|
+
return mapSequence(sub_pat, min_replacement);
|
565
|
+
}));
|
566
|
+
};
|
567
|
+
/**
|
568
|
+
* Convert an array of sequences into a pattern
|
569
|
+
* [{start:0,end:3,length:3,substr:'iii'}...] => (?:iii...)
|
570
|
+
*
|
571
|
+
* @param {Sequence[]} sequences
|
572
|
+
* @param {boolean} all
|
573
|
+
*/
|
574
|
+
|
575
|
+
const sequencesToPattern = (sequences, all = true) => {
|
576
|
+
let min_replacement = sequences.length > 1 ? 1 : 0;
|
577
|
+
return arrayToPattern(sequences.map(sequence => {
|
578
|
+
let seq = [];
|
579
|
+
const len = all ? sequence.length() : sequence.length() - 1;
|
580
|
+
|
581
|
+
for (let j = 0; j < len; j++) {
|
582
|
+
seq.push(substringsToPattern(sequence.substrs[j] || '', min_replacement));
|
583
|
+
}
|
584
|
+
|
585
|
+
return sequencePattern(seq);
|
586
|
+
}));
|
587
|
+
};
|
588
|
+
/**
|
589
|
+
* Return true if the sequence is already in the sequences
|
590
|
+
* @param {Sequence} needle_seq
|
591
|
+
* @param {Sequence[]} sequences
|
344
592
|
*/
|
345
593
|
|
346
|
-
|
347
|
-
|
348
|
-
|
594
|
+
|
595
|
+
const inSequences = (needle_seq, sequences) => {
|
596
|
+
for (const seq of sequences) {
|
597
|
+
if (seq.start != needle_seq.start || seq.end != needle_seq.end) {
|
598
|
+
continue;
|
599
|
+
}
|
600
|
+
|
601
|
+
if (seq.substrs.join('') !== needle_seq.substrs.join('')) {
|
602
|
+
continue;
|
603
|
+
}
|
604
|
+
|
605
|
+
let needle_parts = needle_seq.parts;
|
606
|
+
/**
|
607
|
+
* @param {TSequencePart} part
|
608
|
+
*/
|
609
|
+
|
610
|
+
const filter = part => {
|
611
|
+
for (const needle_part of needle_parts) {
|
612
|
+
if (needle_part.start === part.start && needle_part.substr === part.substr) {
|
613
|
+
return false;
|
614
|
+
}
|
615
|
+
|
616
|
+
if (part.length == 1 || needle_part.length == 1) {
|
617
|
+
continue;
|
618
|
+
} // check for overlapping parts
|
619
|
+
// a = ['::=','==']
|
620
|
+
// b = ['::','===']
|
621
|
+
// a = ['r','sm']
|
622
|
+
// b = ['rs','m']
|
623
|
+
|
624
|
+
|
625
|
+
if (part.start < needle_part.start && part.end > needle_part.start) {
|
626
|
+
return true;
|
627
|
+
}
|
628
|
+
|
629
|
+
if (needle_part.start < part.start && needle_part.end > part.start) {
|
630
|
+
return true;
|
631
|
+
}
|
632
|
+
}
|
633
|
+
|
634
|
+
return false;
|
635
|
+
};
|
636
|
+
|
637
|
+
let filtered = seq.parts.filter(filter);
|
638
|
+
|
639
|
+
if (filtered.length > 0) {
|
640
|
+
continue;
|
641
|
+
}
|
642
|
+
|
643
|
+
return true;
|
644
|
+
}
|
645
|
+
|
646
|
+
return false;
|
647
|
+
};
|
648
|
+
|
649
|
+
class Sequence {
|
650
|
+
constructor() {
|
651
|
+
/** @type {TSequencePart[]} */
|
652
|
+
this.parts = [];
|
653
|
+
/** @type {string[]} */
|
654
|
+
|
655
|
+
this.substrs = [];
|
656
|
+
this.start = 0;
|
657
|
+
this.end = 0;
|
658
|
+
}
|
659
|
+
/**
|
660
|
+
* @param {TSequencePart|undefined} part
|
661
|
+
*/
|
662
|
+
|
663
|
+
|
664
|
+
add(part) {
|
665
|
+
if (part) {
|
666
|
+
this.parts.push(part);
|
667
|
+
this.substrs.push(part.substr);
|
668
|
+
this.start = Math.min(part.start, this.start);
|
669
|
+
this.end = Math.max(part.end, this.end);
|
670
|
+
}
|
671
|
+
}
|
672
|
+
|
673
|
+
last() {
|
674
|
+
return this.parts[this.parts.length - 1];
|
349
675
|
}
|
350
676
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
677
|
+
length() {
|
678
|
+
return this.parts.length;
|
679
|
+
}
|
680
|
+
/**
|
681
|
+
* @param {number} position
|
682
|
+
* @param {TSequencePart} last_piece
|
683
|
+
*/
|
355
684
|
|
356
|
-
|
357
|
-
|
685
|
+
|
686
|
+
clone(position, last_piece) {
|
687
|
+
let clone = new Sequence();
|
688
|
+
let parts = JSON.parse(JSON.stringify(this.parts));
|
689
|
+
let last_part = parts.pop();
|
690
|
+
|
691
|
+
for (const part of parts) {
|
692
|
+
clone.add(part);
|
358
693
|
}
|
359
694
|
|
360
|
-
|
361
|
-
|
695
|
+
let last_substr = last_piece.substr.substring(0, position - last_part.start);
|
696
|
+
let clone_last_len = last_substr.length;
|
697
|
+
clone.add({
|
698
|
+
start: last_part.start,
|
699
|
+
end: last_part.start + clone_last_len,
|
700
|
+
length: clone_last_len,
|
701
|
+
substr: last_substr
|
702
|
+
});
|
703
|
+
return clone;
|
704
|
+
}
|
705
|
+
|
706
|
+
}
|
707
|
+
/**
|
708
|
+
* Expand a regular expression pattern to include unicode variants
|
709
|
+
* eg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/
|
710
|
+
*
|
711
|
+
* Issue:
|
712
|
+
* ﺊﺋ [ 'ﺊ = \\u{fe8a}', 'ﺋ = \\u{fe8b}' ]
|
713
|
+
* becomes: ئئ [ 'ي = \\u{64a}', 'ٔ = \\u{654}', 'ي = \\u{64a}', 'ٔ = \\u{654}' ]
|
714
|
+
*
|
715
|
+
* İIJ = IIJ = ⅡJ
|
716
|
+
*
|
717
|
+
* 1/2/4
|
718
|
+
*
|
719
|
+
* @param {string} str
|
720
|
+
* @return {string|undefined}
|
721
|
+
*/
|
722
|
+
|
723
|
+
|
724
|
+
const getPattern = str => {
|
725
|
+
initialize();
|
726
|
+
str = asciifold(str);
|
727
|
+
let pattern = '';
|
728
|
+
let sequences = [new Sequence()];
|
729
|
+
|
730
|
+
for (let i = 0; i < str.length; i++) {
|
731
|
+
let substr = str.substring(i);
|
732
|
+
let match = substr.match(multi_char_reg);
|
733
|
+
const char = str.substring(i, i + 1);
|
734
|
+
const match_str = match ? match[0] : null; // loop through sequences
|
735
|
+
// add either the char or multi_match
|
736
|
+
|
737
|
+
let overlapping = [];
|
738
|
+
let added_types = new Set();
|
739
|
+
|
740
|
+
for (const sequence of sequences) {
|
741
|
+
const last_piece = sequence.last();
|
742
|
+
|
743
|
+
if (!last_piece || last_piece.length == 1 || last_piece.end <= i) {
|
744
|
+
// if we have a multi match
|
745
|
+
if (match_str) {
|
746
|
+
const len = match_str.length;
|
747
|
+
sequence.add({
|
748
|
+
start: i,
|
749
|
+
end: i + len,
|
750
|
+
length: len,
|
751
|
+
substr: match_str
|
752
|
+
});
|
753
|
+
added_types.add('1');
|
754
|
+
} else {
|
755
|
+
sequence.add({
|
756
|
+
start: i,
|
757
|
+
end: i + 1,
|
758
|
+
length: 1,
|
759
|
+
substr: char
|
760
|
+
});
|
761
|
+
added_types.add('2');
|
762
|
+
}
|
763
|
+
} else if (match_str) {
|
764
|
+
let clone = sequence.clone(i, last_piece);
|
765
|
+
const len = match_str.length;
|
766
|
+
clone.add({
|
767
|
+
start: i,
|
768
|
+
end: i + len,
|
769
|
+
length: len,
|
770
|
+
substr: match_str
|
771
|
+
});
|
772
|
+
overlapping.push(clone);
|
773
|
+
} else {
|
774
|
+
// don't add char
|
775
|
+
// adding would create invalid patterns: 234 => [2,34,4]
|
776
|
+
added_types.add('3');
|
777
|
+
}
|
778
|
+
} // if we have overlapping
|
779
|
+
|
780
|
+
|
781
|
+
if (overlapping.length > 0) {
|
782
|
+
// ['ii','iii'] before ['i','i','iii']
|
783
|
+
overlapping = overlapping.sort((a, b) => {
|
784
|
+
return a.length() - b.length();
|
785
|
+
});
|
786
|
+
|
787
|
+
for (let clone of overlapping) {
|
788
|
+
// don't add if we already have an equivalent sequence
|
789
|
+
if (inSequences(clone, sequences)) {
|
790
|
+
continue;
|
791
|
+
}
|
792
|
+
|
793
|
+
sequences.push(clone);
|
794
|
+
}
|
795
|
+
|
796
|
+
continue;
|
797
|
+
} // if we haven't done anything unique
|
798
|
+
// clean up the patterns
|
799
|
+
// helps keep patterns smaller
|
800
|
+
// if str = 'r₨㎧aarss', pattern will be 446 instead of 655
|
801
|
+
|
802
|
+
|
803
|
+
if (i > 0 && added_types.size == 1 && !added_types.has('3')) {
|
804
|
+
pattern += sequencesToPattern(sequences, false);
|
805
|
+
let new_seq = new Sequence();
|
806
|
+
const old_seq = sequences[0];
|
807
|
+
|
808
|
+
if (old_seq) {
|
809
|
+
new_seq.add(old_seq.last());
|
810
|
+
}
|
811
|
+
|
812
|
+
sequences = [new_seq];
|
362
813
|
}
|
814
|
+
}
|
363
815
|
|
364
|
-
|
365
|
-
|
816
|
+
pattern += sequencesToPattern(sequences, true);
|
817
|
+
return pattern;
|
366
818
|
};
|
367
819
|
|
368
|
-
|
820
|
+
/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */
|
369
821
|
|
370
822
|
/**
|
371
823
|
* A property getter resolving dot-notation
|
@@ -403,20 +855,13 @@
|
|
403
855
|
var score, pos;
|
404
856
|
if (!value) return 0;
|
405
857
|
value = value + '';
|
858
|
+
if (token.regex == null) return 0;
|
406
859
|
pos = value.search(token.regex);
|
407
860
|
if (pos === -1) return 0;
|
408
861
|
score = token.string.length / value.length;
|
409
862
|
if (pos === 0) score += 0.5;
|
410
863
|
return score * weight;
|
411
864
|
};
|
412
|
-
/**
|
413
|
-
*
|
414
|
-
* https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error
|
415
|
-
*/
|
416
|
-
|
417
|
-
const escape_regex = str => {
|
418
|
-
return (str + '').replace(/([\$\(-\+\.\?\[-\^\{-\}])/g, '\\$1');
|
419
|
-
};
|
420
865
|
/**
|
421
866
|
* Cast object property to an array if it exists and has a value
|
422
867
|
*
|
@@ -441,7 +886,7 @@
|
|
441
886
|
*
|
442
887
|
*/
|
443
888
|
|
444
|
-
const iterate = (object, callback) => {
|
889
|
+
const iterate$1 = (object, callback) => {
|
445
890
|
if (Array.isArray(object)) {
|
446
891
|
object.forEach(callback);
|
447
892
|
} else {
|
@@ -464,6 +909,8 @@
|
|
464
909
|
return 0;
|
465
910
|
};
|
466
911
|
|
912
|
+
/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */
|
913
|
+
|
467
914
|
/**
|
468
915
|
* sifter.js
|
469
916
|
* Copyright (c) 2013–2020 Brian Reavis & contributors
|
@@ -525,12 +972,12 @@
|
|
525
972
|
|
526
973
|
if (word.length > 0) {
|
527
974
|
if (this.settings.diacritics) {
|
528
|
-
regex =
|
975
|
+
regex = getPattern(word) || null;
|
529
976
|
} else {
|
530
977
|
regex = escape_regex(word);
|
531
978
|
}
|
532
979
|
|
533
|
-
if (respect_word_boundaries) regex = "\\b" + regex;
|
980
|
+
if (regex && respect_word_boundaries) regex = "\\b" + regex;
|
534
981
|
}
|
535
982
|
|
536
983
|
tokens.push({
|
@@ -548,12 +995,17 @@
|
|
548
995
|
* Good matches will have a higher score than poor matches.
|
549
996
|
* If an item is not a match, 0 will be returned by the function.
|
550
997
|
*
|
551
|
-
* @returns {
|
998
|
+
* @returns {T.ScoreFn}
|
552
999
|
*/
|
553
1000
|
getScoreFunction(query, options) {
|
554
1001
|
var search = this.prepareSearch(query, options);
|
555
1002
|
return this._getScoreFunction(search);
|
556
1003
|
}
|
1004
|
+
/**
|
1005
|
+
* @returns {T.ScoreFn}
|
1006
|
+
*
|
1007
|
+
*/
|
1008
|
+
|
557
1009
|
|
558
1010
|
_getScoreFunction(search) {
|
559
1011
|
const tokens = search.tokens,
|
@@ -586,7 +1038,7 @@
|
|
586
1038
|
if (field_count === 1) {
|
587
1039
|
return function (token, data) {
|
588
1040
|
const field = fields[0].field;
|
589
|
-
return scoreValue(getAttrFn(data, field), token, weights[field]);
|
1041
|
+
return scoreValue(getAttrFn(data, field), token, weights[field] || 1);
|
590
1042
|
};
|
591
1043
|
}
|
592
1044
|
|
@@ -602,7 +1054,7 @@
|
|
602
1054
|
sum += scoreValue(value, token, 1);
|
603
1055
|
}
|
604
1056
|
} else {
|
605
|
-
iterate(weights, (weight, field) => {
|
1057
|
+
iterate$1(weights, (weight, field) => {
|
606
1058
|
sum += scoreValue(getAttrFn(data, field), token, weight);
|
607
1059
|
});
|
608
1060
|
}
|
@@ -619,12 +1071,11 @@
|
|
619
1071
|
|
620
1072
|
if (search.options.conjunction === 'and') {
|
621
1073
|
return function (data) {
|
622
|
-
var
|
623
|
-
score,
|
1074
|
+
var score,
|
624
1075
|
sum = 0;
|
625
1076
|
|
626
|
-
for (
|
627
|
-
score = scoreObject(
|
1077
|
+
for (let token of tokens) {
|
1078
|
+
score = scoreObject(token, data);
|
628
1079
|
if (score <= 0) return 0;
|
629
1080
|
sum += score;
|
630
1081
|
}
|
@@ -634,7 +1085,7 @@
|
|
634
1085
|
} else {
|
635
1086
|
return function (data) {
|
636
1087
|
var sum = 0;
|
637
|
-
iterate(tokens, token => {
|
1088
|
+
iterate$1(tokens, token => {
|
638
1089
|
sum += scoreObject(token, data);
|
639
1090
|
});
|
640
1091
|
return sum / token_count;
|
@@ -655,12 +1106,11 @@
|
|
655
1106
|
}
|
656
1107
|
|
657
1108
|
_getSortFunction(search) {
|
658
|
-
var
|
1109
|
+
var implicit_score,
|
1110
|
+
sort_flds = [];
|
659
1111
|
const self = this,
|
660
1112
|
options = search.options,
|
661
|
-
sort = !search.query && options.sort_empty ? options.sort_empty : options.sort
|
662
|
-
sort_flds = [],
|
663
|
-
multipliers = [];
|
1113
|
+
sort = !search.query && options.sort_empty ? options.sort_empty : options.sort;
|
664
1114
|
|
665
1115
|
if (typeof sort == 'function') {
|
666
1116
|
return sort.bind(this);
|
@@ -679,9 +1129,9 @@
|
|
679
1129
|
|
680
1130
|
|
681
1131
|
if (sort) {
|
682
|
-
for (
|
683
|
-
if (search.query ||
|
684
|
-
sort_flds.push(
|
1132
|
+
for (let s of sort) {
|
1133
|
+
if (search.query || s.field !== '$score') {
|
1134
|
+
sort_flds.push(s);
|
685
1135
|
}
|
686
1136
|
}
|
687
1137
|
} // the "$score" field is implied to be the primary
|
@@ -691,8 +1141,8 @@
|
|
691
1141
|
if (search.query) {
|
692
1142
|
implicit_score = true;
|
693
1143
|
|
694
|
-
for (
|
695
|
-
if (
|
1144
|
+
for (let fld of sort_flds) {
|
1145
|
+
if (fld.field === '$score') {
|
696
1146
|
implicit_score = false;
|
697
1147
|
break;
|
698
1148
|
}
|
@@ -703,18 +1153,10 @@
|
|
703
1153
|
field: '$score',
|
704
1154
|
direction: 'desc'
|
705
1155
|
});
|
706
|
-
}
|
707
|
-
} else {
|
708
|
-
for (i = 0, n = sort_flds.length; i < n; i++) {
|
709
|
-
if (sort_flds[i].field === '$score') {
|
710
|
-
sort_flds.splice(i, 1);
|
711
|
-
break;
|
712
|
-
}
|
713
|
-
}
|
714
|
-
}
|
1156
|
+
} // without a search.query, all items will have the same score
|
715
1157
|
|
716
|
-
|
717
|
-
|
1158
|
+
} else {
|
1159
|
+
sort_flds = sort_flds.filter(fld => fld.field !== '$score');
|
718
1160
|
} // build function
|
719
1161
|
|
720
1162
|
|
@@ -722,25 +1164,20 @@
|
|
722
1164
|
|
723
1165
|
if (!sort_flds_count) {
|
724
1166
|
return null;
|
725
|
-
}
|
726
|
-
const sort_fld = sort_flds[0].field;
|
727
|
-
const multiplier = multipliers[0];
|
728
|
-
return function (a, b) {
|
729
|
-
return multiplier * cmp(get_field(sort_fld, a), get_field(sort_fld, b));
|
730
|
-
};
|
731
|
-
} else {
|
732
|
-
return function (a, b) {
|
733
|
-
var i, result, field;
|
1167
|
+
}
|
734
1168
|
|
735
|
-
|
736
|
-
|
737
|
-
result = multipliers[i] * cmp(get_field(field, a), get_field(field, b));
|
738
|
-
if (result) return result;
|
739
|
-
}
|
1169
|
+
return function (a, b) {
|
1170
|
+
var result, field;
|
740
1171
|
|
741
|
-
|
742
|
-
|
743
|
-
|
1172
|
+
for (let sort_fld of sort_flds) {
|
1173
|
+
field = sort_fld.field;
|
1174
|
+
let multiplier = sort_fld.direction === 'desc' ? -1 : 1;
|
1175
|
+
result = multiplier * cmp(get_field(field, a), get_field(field, b));
|
1176
|
+
if (result) return result;
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
return 0;
|
1180
|
+
};
|
744
1181
|
}
|
745
1182
|
|
746
1183
|
/**
|
@@ -799,7 +1236,7 @@
|
|
799
1236
|
|
800
1237
|
|
801
1238
|
if (query.length) {
|
802
|
-
iterate(self.items, (item, id) => {
|
1239
|
+
iterate$1(self.items, (item, id) => {
|
803
1240
|
score = fn_score(item);
|
804
1241
|
|
805
1242
|
if (options.filter === false || score > 0) {
|
@@ -810,7 +1247,7 @@
|
|
810
1247
|
}
|
811
1248
|
});
|
812
1249
|
} else {
|
813
|
-
iterate(self.items, (_, id) => {
|
1250
|
+
iterate$1(self.items, (_, id) => {
|
814
1251
|
search.items.push({
|
815
1252
|
'score': 1,
|
816
1253
|
'id': id
|
@@ -833,6 +1270,29 @@
|
|
833
1270
|
|
834
1271
|
}
|
835
1272
|
|
1273
|
+
/**
|
1274
|
+
* Iterates over arrays and hashes.
|
1275
|
+
*
|
1276
|
+
* ```
|
1277
|
+
* iterate(this.items, function(item, id) {
|
1278
|
+
* // invoked for each item
|
1279
|
+
* });
|
1280
|
+
* ```
|
1281
|
+
*
|
1282
|
+
*/
|
1283
|
+
|
1284
|
+
const iterate = (object, callback) => {
|
1285
|
+
if (Array.isArray(object)) {
|
1286
|
+
object.forEach(callback);
|
1287
|
+
} else {
|
1288
|
+
for (var key in object) {
|
1289
|
+
if (object.hasOwnProperty(key)) {
|
1290
|
+
callback(object[key], key);
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
}
|
1294
|
+
};
|
1295
|
+
|
836
1296
|
/**
|
837
1297
|
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
|
838
1298
|
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
|
@@ -850,10 +1310,10 @@
|
|
850
1310
|
}
|
851
1311
|
|
852
1312
|
if (isHtmlString(query)) {
|
853
|
-
|
854
|
-
|
1313
|
+
var tpl = document.createElement('template');
|
1314
|
+
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
|
855
1315
|
|
856
|
-
return
|
1316
|
+
return tpl.content.firstChild;
|
857
1317
|
}
|
858
1318
|
|
859
1319
|
return document.querySelector(query);
|
@@ -1064,9 +1524,9 @@
|
|
1064
1524
|
|
1065
1525
|
const highlightChildren = node => {
|
1066
1526
|
if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName) && (node.className !== 'highlight' || node.tagName !== 'SPAN')) {
|
1067
|
-
|
1068
|
-
|
1069
|
-
}
|
1527
|
+
Array.from(node.childNodes).forEach(element => {
|
1528
|
+
highlightRecursive(element);
|
1529
|
+
});
|
1070
1530
|
}
|
1071
1531
|
};
|
1072
1532
|
|
@@ -1639,7 +2099,7 @@
|
|
1639
2099
|
control_input = getDom(settings.controlInput); // set attributes
|
1640
2100
|
|
1641
2101
|
var attrs = ['autocorrect', 'autocapitalize', 'autocomplete'];
|
1642
|
-
iterate(attrs, attr => {
|
2102
|
+
iterate$1(attrs, attr => {
|
1643
2103
|
if (input.getAttribute(attr)) {
|
1644
2104
|
setAttr(control_input, {
|
1645
2105
|
[attr]: input.getAttribute(attr)
|
@@ -1743,6 +2203,9 @@
|
|
1743
2203
|
}
|
1744
2204
|
|
1745
2205
|
self.control_input.type = input.type;
|
2206
|
+
addEvent(dropdown, 'mousemove', () => {
|
2207
|
+
self.ignoreHover = false;
|
2208
|
+
});
|
1746
2209
|
addEvent(dropdown, 'mouseenter', e => {
|
1747
2210
|
var target_match = parentMatch(e.target, '[data-selectable]', dropdown);
|
1748
2211
|
if (target_match) self.onOptionHover(e, target_match);
|
@@ -1815,18 +2278,12 @@
|
|
1815
2278
|
}
|
1816
2279
|
};
|
1817
2280
|
|
1818
|
-
const win_hover = () => {
|
1819
|
-
self.ignoreHover = false;
|
1820
|
-
};
|
1821
|
-
|
1822
2281
|
addEvent(document, 'mousedown', doc_mousedown);
|
1823
2282
|
addEvent(window, 'scroll', win_scroll, passive_event);
|
1824
2283
|
addEvent(window, 'resize', win_scroll, passive_event);
|
1825
|
-
addEvent(window, 'mousemove', win_hover, passive_event);
|
1826
2284
|
|
1827
2285
|
this._destroy = () => {
|
1828
2286
|
document.removeEventListener('mousedown', doc_mousedown);
|
1829
|
-
window.removeEventListener('mousemove', win_hover);
|
1830
2287
|
window.removeEventListener('scroll', win_scroll);
|
1831
2288
|
window.removeEventListener('resize', win_scroll);
|
1832
2289
|
if (label) label.removeEventListener('click', label_click);
|
@@ -1844,7 +2301,7 @@
|
|
1844
2301
|
settings.items = [];
|
1845
2302
|
delete settings.optgroups;
|
1846
2303
|
delete settings.options;
|
1847
|
-
addEvent(input, 'invalid',
|
2304
|
+
addEvent(input, 'invalid', () => {
|
1848
2305
|
if (self.isValid) {
|
1849
2306
|
self.isValid = false;
|
1850
2307
|
self.isInvalid = true;
|
@@ -1881,7 +2338,7 @@
|
|
1881
2338
|
// build options table
|
1882
2339
|
this.addOptions(options); // build optgroup table
|
1883
2340
|
|
1884
|
-
iterate(optgroups, optgroup => {
|
2341
|
+
iterate$1(optgroups, optgroup => {
|
1885
2342
|
this.registerOptionGroup(optgroup);
|
1886
2343
|
});
|
1887
2344
|
}
|
@@ -2045,13 +2502,15 @@
|
|
2045
2502
|
}
|
2046
2503
|
|
2047
2504
|
var splitInput = pastedText.trim().split(self.settings.splitOn);
|
2048
|
-
iterate(splitInput, piece => {
|
2049
|
-
|
2505
|
+
iterate$1(splitInput, piece => {
|
2506
|
+
const hash = hash_key(piece);
|
2050
2507
|
|
2051
|
-
if (
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2508
|
+
if (hash) {
|
2509
|
+
if (this.options[piece]) {
|
2510
|
+
self.addItem(piece);
|
2511
|
+
} else {
|
2512
|
+
self.createItem(piece);
|
2513
|
+
}
|
2055
2514
|
}
|
2056
2515
|
});
|
2057
2516
|
}, 0);
|
@@ -2279,7 +2738,7 @@
|
|
2279
2738
|
};
|
2280
2739
|
|
2281
2740
|
if (self.settings.create && self.settings.createOnBlur) {
|
2282
|
-
self.createItem(null,
|
2741
|
+
self.createItem(null, deactivate);
|
2283
2742
|
} else {
|
2284
2743
|
deactivate();
|
2285
2744
|
}
|
@@ -2300,7 +2759,7 @@
|
|
2300
2759
|
}
|
2301
2760
|
|
2302
2761
|
if (option.classList.contains('create')) {
|
2303
|
-
self.createItem(null,
|
2762
|
+
self.createItem(null, () => {
|
2304
2763
|
if (self.settings.closeAfterSelect) {
|
2305
2764
|
self.close();
|
2306
2765
|
}
|
@@ -2669,7 +3128,7 @@
|
|
2669
3128
|
self.hideInput();
|
2670
3129
|
self.close();
|
2671
3130
|
self.activeItems = activeItems;
|
2672
|
-
iterate(activeItems, item => {
|
3131
|
+
iterate$1(activeItems, item => {
|
2673
3132
|
self.setActiveItemClass(item);
|
2674
3133
|
});
|
2675
3134
|
}
|
@@ -2805,7 +3264,7 @@
|
|
2805
3264
|
|
2806
3265
|
|
2807
3266
|
search(query) {
|
2808
|
-
var
|
3267
|
+
var result, calculateScore;
|
2809
3268
|
var self = this;
|
2810
3269
|
var options = this.getSearchOptions(); // validate user-provided result scoring function
|
2811
3270
|
|
@@ -2830,13 +3289,10 @@
|
|
2830
3289
|
|
2831
3290
|
|
2832
3291
|
if (self.settings.hideSelected) {
|
2833
|
-
|
2834
|
-
let hashed = hash_key(
|
2835
|
-
|
2836
|
-
|
2837
|
-
result.items.splice(i, 1);
|
2838
|
-
}
|
2839
|
-
}
|
3292
|
+
result.items = result.items.filter(item => {
|
3293
|
+
let hashed = hash_key(item.id);
|
3294
|
+
return !(hashed && self.items.indexOf(hashed) !== -1);
|
3295
|
+
});
|
2840
3296
|
}
|
2841
3297
|
|
2842
3298
|
return result;
|
@@ -2849,21 +3305,24 @@
|
|
2849
3305
|
|
2850
3306
|
|
2851
3307
|
refreshOptions(triggerDropdown = true) {
|
2852
|
-
var i, j, k, n, optgroup, optgroups, html, has_create_option,
|
3308
|
+
var i, j, k, n, optgroup, optgroups, html, has_create_option, active_group;
|
2853
3309
|
var create;
|
2854
3310
|
const groups = {};
|
2855
3311
|
const groups_order = [];
|
2856
3312
|
var self = this;
|
2857
3313
|
var query = self.inputValue();
|
3314
|
+
const same_query = query === self.lastQuery || query == '' && self.lastQuery == null;
|
2858
3315
|
var results = self.search(query);
|
2859
|
-
var active_option = null;
|
2860
|
-
|
3316
|
+
var active_option = null;
|
2861
3317
|
var show_dropdown = self.settings.shouldOpen || false;
|
2862
3318
|
var dropdown_content = self.dropdown_content;
|
2863
3319
|
|
2864
|
-
if (
|
2865
|
-
|
2866
|
-
|
3320
|
+
if (same_query) {
|
3321
|
+
active_option = self.activeOption;
|
3322
|
+
|
3323
|
+
if (active_option) {
|
3324
|
+
active_group = active_option.closest('[data-group]');
|
3325
|
+
}
|
2867
3326
|
} // build markup
|
2868
3327
|
|
2869
3328
|
|
@@ -2880,12 +3339,16 @@
|
|
2880
3339
|
|
2881
3340
|
for (i = 0; i < n; i++) {
|
2882
3341
|
// get option dom element
|
2883
|
-
let
|
3342
|
+
let item = results.items[i];
|
3343
|
+
if (!item) continue;
|
3344
|
+
let opt_value = item.id;
|
2884
3345
|
let option = self.options[opt_value];
|
2885
|
-
|
3346
|
+
if (option === undefined) continue;
|
3347
|
+
let opt_hash = get_hash(opt_value);
|
3348
|
+
let option_el = self.getOption(opt_hash, true); // toggle 'selected' class
|
2886
3349
|
|
2887
3350
|
if (!self.settings.hideSelected) {
|
2888
|
-
option_el.classList.toggle('selected', self.items.includes(
|
3351
|
+
option_el.classList.toggle('selected', self.items.includes(opt_hash));
|
2889
3352
|
}
|
2890
3353
|
|
2891
3354
|
optgroup = option[self.settings.optgroupField] || '';
|
@@ -2898,8 +3361,10 @@
|
|
2898
3361
|
optgroup = '';
|
2899
3362
|
}
|
2900
3363
|
|
2901
|
-
|
2902
|
-
|
3364
|
+
let group_fragment = groups[optgroup];
|
3365
|
+
|
3366
|
+
if (group_fragment === undefined) {
|
3367
|
+
group_fragment = document.createDocumentFragment();
|
2903
3368
|
groups_order.push(optgroup);
|
2904
3369
|
} // nodes can only have one parent, so if the option is in mutple groups, we need a clone
|
2905
3370
|
|
@@ -2911,48 +3376,50 @@
|
|
2911
3376
|
'aria-selected': null
|
2912
3377
|
});
|
2913
3378
|
option_el.classList.add('ts-cloned');
|
2914
|
-
removeClasses(option_el, 'active');
|
2915
|
-
} // make sure we keep the activeOption in the same group
|
2916
|
-
|
3379
|
+
removeClasses(option_el, 'active'); // make sure we keep the activeOption in the same group
|
2917
3380
|
|
2918
|
-
|
2919
|
-
|
2920
|
-
if (active_group.dataset.group === optgroup) {
|
3381
|
+
if (self.activeOption && self.activeOption.dataset.value == opt_value) {
|
3382
|
+
if (active_group && active_group.dataset.group === optgroup.toString()) {
|
2921
3383
|
active_option = option_el;
|
2922
3384
|
}
|
2923
|
-
} else {
|
2924
|
-
active_option = option_el;
|
2925
3385
|
}
|
2926
3386
|
}
|
2927
3387
|
|
2928
|
-
|
3388
|
+
group_fragment.appendChild(option_el);
|
3389
|
+
groups[optgroup] = group_fragment;
|
2929
3390
|
}
|
2930
3391
|
} // sort optgroups
|
2931
3392
|
|
2932
3393
|
|
2933
|
-
if (
|
3394
|
+
if (self.settings.lockOptgroupOrder) {
|
2934
3395
|
groups_order.sort((a, b) => {
|
2935
|
-
|
2936
|
-
|
3396
|
+
const grp_a = self.optgroups[a];
|
3397
|
+
const grp_b = self.optgroups[b];
|
3398
|
+
const a_order = grp_a && grp_a.$order || 0;
|
3399
|
+
const b_order = grp_b && grp_b.$order || 0;
|
2937
3400
|
return a_order - b_order;
|
2938
3401
|
});
|
2939
3402
|
} // render optgroup headers & join groups
|
2940
3403
|
|
2941
3404
|
|
2942
3405
|
html = document.createDocumentFragment();
|
2943
|
-
iterate(groups_order, optgroup => {
|
2944
|
-
|
3406
|
+
iterate$1(groups_order, optgroup => {
|
3407
|
+
let group_fragment = groups[optgroup];
|
3408
|
+
if (!group_fragment || !group_fragment.children.length) return;
|
3409
|
+
let group_heading = self.optgroups[optgroup];
|
3410
|
+
|
3411
|
+
if (group_heading !== undefined) {
|
2945
3412
|
let group_options = document.createDocumentFragment();
|
2946
|
-
let header = self.render('optgroup_header',
|
3413
|
+
let header = self.render('optgroup_header', group_heading);
|
2947
3414
|
append(group_options, header);
|
2948
|
-
append(group_options,
|
3415
|
+
append(group_options, group_fragment);
|
2949
3416
|
let group_html = self.render('optgroup', {
|
2950
|
-
group:
|
3417
|
+
group: group_heading,
|
2951
3418
|
options: group_options
|
2952
3419
|
});
|
2953
3420
|
append(html, group_html);
|
2954
3421
|
} else {
|
2955
|
-
append(html,
|
3422
|
+
append(html, group_fragment);
|
2956
3423
|
}
|
2957
3424
|
});
|
2958
3425
|
dropdown_content.innerHTML = '';
|
@@ -2962,7 +3429,7 @@
|
|
2962
3429
|
removeHighlight(dropdown_content);
|
2963
3430
|
|
2964
3431
|
if (results.query.length && results.tokens.length) {
|
2965
|
-
iterate(results.tokens, tok => {
|
3432
|
+
iterate$1(results.tokens, tok => {
|
2966
3433
|
highlight(dropdown_content, tok.regex);
|
2967
3434
|
});
|
2968
3435
|
}
|
@@ -3003,7 +3470,7 @@
|
|
3003
3470
|
|
3004
3471
|
if (show_dropdown) {
|
3005
3472
|
if (results.items.length > 0) {
|
3006
|
-
if (!active_option && self.settings.mode === 'single' && self.items
|
3473
|
+
if (!active_option && self.settings.mode === 'single' && self.items[0] != undefined) {
|
3007
3474
|
active_option = self.getOption(self.items[0]);
|
3008
3475
|
}
|
3009
3476
|
|
@@ -3090,7 +3557,7 @@
|
|
3090
3557
|
|
3091
3558
|
|
3092
3559
|
addOptions(data, user_created = false) {
|
3093
|
-
iterate(data, dat => {
|
3560
|
+
iterate$1(data, dat => {
|
3094
3561
|
this.addOption(dat, user_created);
|
3095
3562
|
});
|
3096
3563
|
}
|
@@ -3170,11 +3637,12 @@
|
|
3170
3637
|
const value_new = hash_key(data[self.settings.valueField]); // sanity checks
|
3171
3638
|
|
3172
3639
|
if (value_old === null) return;
|
3173
|
-
|
3640
|
+
const data_old = self.options[value_old];
|
3641
|
+
if (data_old == undefined) return;
|
3174
3642
|
if (typeof value_new !== 'string') throw new Error('Value must be set in option data');
|
3175
3643
|
const option = self.getOption(value_old);
|
3176
3644
|
const item = self.getItem(value_old);
|
3177
|
-
data.$order = data.$order ||
|
3645
|
+
data.$order = data.$order || data_old.$order;
|
3178
3646
|
delete self.options[value_old]; // invalidate render cache
|
3179
3647
|
// don't remove existing node yet, we'll remove it after replacing it
|
3180
3648
|
|
@@ -3238,9 +3706,9 @@
|
|
3238
3706
|
this.userOptions = {};
|
3239
3707
|
this.clearCache();
|
3240
3708
|
const selected = {};
|
3241
|
-
iterate(this.options, (option, key) => {
|
3709
|
+
iterate$1(this.options, (option, key) => {
|
3242
3710
|
if (boundFilter(option, key)) {
|
3243
|
-
selected[key] =
|
3711
|
+
selected[key] = option;
|
3244
3712
|
}
|
3245
3713
|
});
|
3246
3714
|
this.options = this.sifter.items = selected;
|
@@ -3270,10 +3738,10 @@
|
|
3270
3738
|
|
3271
3739
|
getOption(value, create = false) {
|
3272
3740
|
const hashed = hash_key(value);
|
3741
|
+
if (hashed === null) return null;
|
3742
|
+
const option = this.options[hashed];
|
3273
3743
|
|
3274
|
-
if (
|
3275
|
-
const option = this.options[hashed];
|
3276
|
-
|
3744
|
+
if (option != undefined) {
|
3277
3745
|
if (option.$div) {
|
3278
3746
|
return option.$div;
|
3279
3747
|
}
|
@@ -3346,11 +3814,11 @@
|
|
3346
3814
|
var self = this;
|
3347
3815
|
var items = Array.isArray(values) ? values : [values];
|
3348
3816
|
items = items.filter(x => self.items.indexOf(x) === -1);
|
3349
|
-
|
3350
|
-
|
3351
|
-
self.isPending =
|
3352
|
-
self.addItem(
|
3353
|
-
}
|
3817
|
+
const last_item = items[items.length - 1];
|
3818
|
+
items.forEach(item => {
|
3819
|
+
self.isPending = item !== last_item;
|
3820
|
+
self.addItem(item, silent);
|
3821
|
+
});
|
3354
3822
|
}
|
3355
3823
|
/**
|
3356
3824
|
* "Selects" an item. Adds it to the list
|
@@ -3481,7 +3949,16 @@
|
|
3481
3949
|
*/
|
3482
3950
|
|
3483
3951
|
|
3484
|
-
createItem(input = null,
|
3952
|
+
createItem(input = null, callback = () => {}) {
|
3953
|
+
// triggerDropdown parameter @deprecated 2.1.1
|
3954
|
+
if (arguments.length === 3) {
|
3955
|
+
callback = arguments[2];
|
3956
|
+
}
|
3957
|
+
|
3958
|
+
if (typeof callback != 'function') {
|
3959
|
+
callback = () => {};
|
3960
|
+
}
|
3961
|
+
|
3485
3962
|
var self = this;
|
3486
3963
|
var caret = self.caretPos;
|
3487
3964
|
var output;
|
@@ -3757,7 +4234,7 @@
|
|
3757
4234
|
var self = this;
|
3758
4235
|
if (!self.items.length) return;
|
3759
4236
|
var items = self.controlChildren();
|
3760
|
-
iterate(items, item => {
|
4237
|
+
iterate$1(items, item => {
|
3761
4238
|
self.removeItem(item, true);
|
3762
4239
|
});
|
3763
4240
|
self.showInput();
|
@@ -3775,7 +4252,7 @@
|
|
3775
4252
|
const self = this;
|
3776
4253
|
const caret = self.caretPos;
|
3777
4254
|
const target = self.control;
|
3778
|
-
target.insertBefore(el, target.children[caret]);
|
4255
|
+
target.insertBefore(el, target.children[caret] || null);
|
3779
4256
|
self.setCaret(caret + 1);
|
3780
4257
|
}
|
3781
4258
|
/**
|
@@ -3800,14 +4277,19 @@
|
|
3800
4277
|
caret++;
|
3801
4278
|
}
|
3802
4279
|
|
3803
|
-
iterate(self.activeItems, item => rm_items.push(item));
|
4280
|
+
iterate$1(self.activeItems, item => rm_items.push(item));
|
3804
4281
|
} else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) {
|
3805
4282
|
const items = self.controlChildren();
|
4283
|
+
let rm_item;
|
3806
4284
|
|
3807
4285
|
if (direction < 0 && selection.start === 0 && selection.length === 0) {
|
3808
|
-
|
4286
|
+
rm_item = items[self.caretPos - 1];
|
3809
4287
|
} else if (direction > 0 && selection.start === self.inputValue().length) {
|
3810
|
-
|
4288
|
+
rm_item = items[self.caretPos];
|
4289
|
+
}
|
4290
|
+
|
4291
|
+
if (rm_item !== undefined) {
|
4292
|
+
rm_items.push(rm_item);
|
3811
4293
|
}
|
3812
4294
|
}
|
3813
4295
|
|
@@ -4009,26 +4491,11 @@
|
|
4009
4491
|
|
4010
4492
|
|
4011
4493
|
render(templateName, data) {
|
4012
|
-
|
4013
|
-
return null;
|
4014
|
-
}
|
4015
|
-
|
4016
|
-
return this._render(templateName, data);
|
4017
|
-
}
|
4018
|
-
/**
|
4019
|
-
* _render() can be called directly when we know we don't want to hit the cache
|
4020
|
-
* return type could be null for some templates, we need https://github.com/microsoft/TypeScript/issues/33014
|
4021
|
-
*/
|
4022
|
-
|
4023
|
-
|
4024
|
-
_render(templateName, data) {
|
4025
|
-
var value = '',
|
4026
|
-
id,
|
4027
|
-
html;
|
4494
|
+
var id, html;
|
4028
4495
|
const self = this;
|
4029
4496
|
|
4030
|
-
if (
|
4031
|
-
|
4497
|
+
if (typeof this.settings.render[templateName] !== 'function') {
|
4498
|
+
return null;
|
4032
4499
|
} // render markup
|
4033
4500
|
|
4034
4501
|
|
@@ -4064,6 +4531,7 @@
|
|
4064
4531
|
}
|
4065
4532
|
|
4066
4533
|
if (templateName === 'option' || templateName === 'item') {
|
4534
|
+
const value = get_hash(data[self.settings.valueField]);
|
4067
4535
|
setAttr(html, {
|
4068
4536
|
'data-value': value
|
4069
4537
|
}); // make sure we have some classes if a template is overwritten
|
@@ -4080,12 +4548,28 @@
|
|
4080
4548
|
id: data.$id
|
4081
4549
|
}); // update cache
|
4082
4550
|
|
4083
|
-
|
4551
|
+
data.$div = html;
|
4552
|
+
self.options[value] = data;
|
4084
4553
|
}
|
4085
4554
|
}
|
4086
4555
|
|
4087
4556
|
return html;
|
4088
4557
|
}
|
4558
|
+
/**
|
4559
|
+
* Type guarded rendering
|
4560
|
+
*
|
4561
|
+
*/
|
4562
|
+
|
4563
|
+
|
4564
|
+
_render(templateName, data) {
|
4565
|
+
const html = this.render(templateName, data);
|
4566
|
+
|
4567
|
+
if (html == null) {
|
4568
|
+
throw 'HTMLElement expected';
|
4569
|
+
}
|
4570
|
+
|
4571
|
+
return html;
|
4572
|
+
}
|
4089
4573
|
/**
|
4090
4574
|
* Clears the render cache for a template. If
|
4091
4575
|
* no template is given, clears all render
|
@@ -4095,7 +4579,7 @@
|
|
4095
4579
|
|
4096
4580
|
|
4097
4581
|
clearCache() {
|
4098
|
-
iterate(this.options,
|
4582
|
+
iterate$1(this.options, option => {
|
4099
4583
|
if (option.$div) {
|
4100
4584
|
option.$div.remove();
|
4101
4585
|
delete option.$div;
|