@danielgindi/selectbox 2.0.57 → 2.0.59
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/lib.cjs.js +227 -681
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +230 -681
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +227 -681
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/dist/types/DropList.d.ts +205 -0
- package/dist/types/DropList.d.ts.map +1 -0
- package/dist/types/SelectBox.d.ts +209 -0
- package/dist/types/SelectBox.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +222 -0
- package/dist/types/types.d.ts.map +1 -0
- package/eslint.config.mjs +8 -0
- package/lib/DropList.js +1 -3430
- package/lib/SelectBox.js +1 -3689
- package/lib/index.js +1 -4
- package/package.json +17 -12
- package/tsconfig.json +35 -0
- package/vue/DropList.vue +508 -565
- package/vue/DropList.vue.d.ts +4 -0
- package/vue/SelectBox.vue +780 -981
- package/vue/SelectBox.vue.d.ts +4 -0
- package/vue/component-types.d.ts +210 -0
- package/vue/index.d.ts +4 -0
- package/vue/index.js +3 -4
- package/vue/utils/slots.js +71 -96
- package/lib/utils/escapeRegex.js +0 -1
- package/lib/utils/throttle.js +0 -48
package/dist/lib.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 2.0.
|
|
2
|
+
* @danielgindi/selectbox 2.0.59
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
(function(global, factory) {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
return to;
|
|
34
34
|
};
|
|
35
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
36
36
|
value: mod,
|
|
37
37
|
enumerable: true
|
|
38
38
|
}) : target, mod));
|
|
@@ -40,14 +40,18 @@
|
|
|
40
40
|
_danielgindi_dom_utils_lib_DomEventsSink = __toESM(_danielgindi_dom_utils_lib_DomEventsSink);
|
|
41
41
|
_danielgindi_virtual_list_helper = __toESM(_danielgindi_virtual_list_helper);
|
|
42
42
|
mitt = __toESM(mitt);
|
|
43
|
-
//#region lib/utils/escapeRegex.
|
|
44
|
-
|
|
43
|
+
//#region src/lib/utils/escapeRegex.ts
|
|
44
|
+
/** @internal */
|
|
45
|
+
var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
45
46
|
//#endregion
|
|
46
|
-
//#region lib/utils/throttle.
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
//#region src/lib/utils/throttle.ts
|
|
48
|
+
/** @internal */
|
|
49
|
+
var throttle = (func, wait, options = {}) => {
|
|
50
|
+
let timeout;
|
|
51
|
+
let context;
|
|
52
|
+
let args;
|
|
53
|
+
let result;
|
|
49
54
|
let previous = 0;
|
|
50
|
-
if (!options) options = {};
|
|
51
55
|
const later = () => {
|
|
52
56
|
previous = options.leading === false ? 0 : Date.now();
|
|
53
57
|
timeout = null;
|
|
@@ -82,86 +86,30 @@
|
|
|
82
86
|
return throttled;
|
|
83
87
|
};
|
|
84
88
|
//#endregion
|
|
85
|
-
//#region lib/
|
|
89
|
+
//#region src/lib/utils/reportError.ts
|
|
90
|
+
/**
|
|
91
|
+
* Routes an error/warning to `handler` if supplied, falling back to the
|
|
92
|
+
* console (matching the previous hardcoded behaviour) if there is no
|
|
93
|
+
* handler, or if the handler itself throws.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
var reportError = (handler, error, context) => {
|
|
97
|
+
if (handler) try {
|
|
98
|
+
handler(error, context);
|
|
99
|
+
return;
|
|
100
|
+
} catch (handlerError) {
|
|
101
|
+
console.error(handlerError);
|
|
102
|
+
}
|
|
103
|
+
if (context.level === "warn") console.warn(error);
|
|
104
|
+
else console.error(error);
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/lib/DropList.ts
|
|
86
108
|
var ItemSymbol = Symbol("item");
|
|
87
109
|
var DestroyedSymbol$1 = Symbol("destroyed");
|
|
88
110
|
var GhostSymbol = Symbol("ghost");
|
|
89
111
|
var NoResultsItemSymbol = Symbol("no_results_items");
|
|
90
112
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
91
|
-
/**
|
|
92
|
-
* @typedef {Object} DropList.Options
|
|
93
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
94
|
-
* @property {string} [baseClassName='droplist'] class name for the menu root element
|
|
95
|
-
* @property {string|string[]} [additionalClasses]
|
|
96
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
97
|
-
* @property {boolean} [autoItemBlur=true] Should we automatically blur the focused item when the droplist loses focus?
|
|
98
|
-
* @property {number} [autoItemBlurDelay=300] How long to wait before deciding to blur the focused item (when the droplist loses focus)?
|
|
99
|
-
* @property {boolean} [capturesFocus=true] Should this DropList be added to the TAB-key stack?
|
|
100
|
-
* @property {boolean} [multi=false] Does this DropList show checkboxes for multiple item selection?
|
|
101
|
-
* @property {*} [singleSelectedValue] Current selected value when using single selection.
|
|
102
|
-
* @property {function} [keyDownHandler=null] An alternative "keydown" event handler. Return true to prevent default behaviour.
|
|
103
|
-
* @property {boolean} [autoCheckGroupChildren=true] When a group is checked/unchecked - all items beneath it will update accordingly
|
|
104
|
-
* @property {boolean} [useExactTargetWidth=false] Use the exact target's width, do not allow growing
|
|
105
|
-
* @property {boolean} [constrainToWindow=true] Should the position be constrained to the window, attaching to window's borders if needed?
|
|
106
|
-
* @property {Boolean} [autoFlipDirection=true] Should the position/anchor be flipped automatically when there's no space in the required direction?
|
|
107
|
-
* @property {number} [estimatedItemHeight=20] An estimated row height, for approximating scroll height.
|
|
108
|
-
* @property {boolean} [estimateWidth=false] Use an estimation for the width instead of measuring. May be faster - needs testing and may depend on the CSS.
|
|
109
|
-
* @property {number} [virtualMinItems=100] Turns into a virtual list - with items being created and showing up on viewport only. The value specified the minimum item count where a virtual list will be created.
|
|
110
|
-
* @property {string} [labelProp='label']
|
|
111
|
-
* @property {string} [valueProp='value']
|
|
112
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderItem] Function to call when rendering an item element
|
|
113
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderItem] Function to call when rendering an item element
|
|
114
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
115
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
116
|
-
* @property {function(name: string, data: *)} [on]
|
|
117
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
118
|
-
* @property {boolean} [isFooterVisible=false] show footer element
|
|
119
|
-
* @property {boolean} [searchable=false] include inline search box
|
|
120
|
-
* @property {string} [searchPlaceholder=''] placeholder text for the inline search box
|
|
121
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
122
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
123
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
124
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
125
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
126
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
127
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
128
|
-
* */
|
|
129
|
-
/** */
|
|
130
|
-
/**
|
|
131
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
132
|
-
* @property {'left'|'center'|'right'|'start'|'end'|string|number} x - horizontal anchor specification (could be either `'left'|'center'|'right'|'start'|'end'` or a percentage `'50%'` or a fixed decimal `Number`)
|
|
133
|
-
* @property {'top'|'center'|'bottom'|string|number} y - vertical anchor specification (could be either `'top'|'center'|'bottom'` or a percentage `'50%'` or a fixed decimal `Number`)
|
|
134
|
-
* */
|
|
135
|
-
/** */
|
|
136
|
-
/**
|
|
137
|
-
* @typedef {Object} DropList.PositionOptions
|
|
138
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
139
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
140
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
141
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
142
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
143
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
144
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
145
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
146
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
147
|
-
* */
|
|
148
|
-
/** */
|
|
149
|
-
/**
|
|
150
|
-
* @typedef {Object} DropList.ItemBase
|
|
151
|
-
* @property {string} [value]
|
|
152
|
-
* @property {string} [label]
|
|
153
|
-
* @property {boolean} [_group=false]
|
|
154
|
-
* @property {boolean} [_child=false]
|
|
155
|
-
* @property {boolean} [_nocheck=false]
|
|
156
|
-
* @property {boolean} [_nointeraction=false]
|
|
157
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
158
|
-
* */
|
|
159
|
-
/**
|
|
160
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
161
|
-
* @property {boolean} [_checked=false]
|
|
162
|
-
* */
|
|
163
|
-
/** */
|
|
164
|
-
/** @type {DropList.Options} */
|
|
165
113
|
var DefaultOptions = {
|
|
166
114
|
baseClassName: "droplist",
|
|
167
115
|
autoItemBlur: true,
|
|
@@ -190,9 +138,6 @@
|
|
|
190
138
|
filterEmptyGroups: false
|
|
191
139
|
};
|
|
192
140
|
var DropList = class DropList {
|
|
193
|
-
/**
|
|
194
|
-
* @param {DropList.Options} options
|
|
195
|
-
*/
|
|
196
141
|
constructor(options) {
|
|
197
142
|
const o = { ...DefaultOptions };
|
|
198
143
|
for (let [key, value] of Object.entries(
|
|
@@ -226,6 +171,7 @@
|
|
|
226
171
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
227
172
|
on: o.on || null,
|
|
228
173
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
174
|
+
onError: o.onError,
|
|
229
175
|
searchable: o.searchable,
|
|
230
176
|
searchPlaceholder: o.searchPlaceholder,
|
|
231
177
|
isHeaderVisible: o.isHeaderVisible,
|
|
@@ -243,7 +189,14 @@
|
|
|
243
189
|
throttledRefilterItems: null,
|
|
244
190
|
focusItemIndex: -1,
|
|
245
191
|
focusItemEl: null,
|
|
246
|
-
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default()
|
|
192
|
+
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default(),
|
|
193
|
+
visible: false,
|
|
194
|
+
hiding: false,
|
|
195
|
+
singleSelectedItemEl: null,
|
|
196
|
+
onDocumentMouseDown: null,
|
|
197
|
+
lastKeyWasChar: false,
|
|
198
|
+
currentSubDropList: null,
|
|
199
|
+
_isFocusingItem: false
|
|
247
200
|
};
|
|
248
201
|
let classes = [p.baseClassName + "_wrapper"];
|
|
249
202
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -309,7 +262,11 @@
|
|
|
309
262
|
};
|
|
310
263
|
else item = items[index];
|
|
311
264
|
}
|
|
312
|
-
if (!item)
|
|
265
|
+
if (!item) reportError(p.onError, `onItemRender called for (${index}) which has no item`, {
|
|
266
|
+
source: "renderItem",
|
|
267
|
+
level: "warn",
|
|
268
|
+
index
|
|
269
|
+
});
|
|
313
270
|
itemEl.className = `${p.baseClassName}__item`;
|
|
314
271
|
const classList = itemEl.classList;
|
|
315
272
|
if (item) {
|
|
@@ -386,19 +343,13 @@
|
|
|
386
343
|
}
|
|
387
344
|
/**
|
|
388
345
|
* Returns true if other is an inclusive descendant of node, and false otherwise.
|
|
389
|
-
*
|
|
390
|
-
* @param {boolean} [considerSubmenus=true]
|
|
391
|
-
* @returns {boolean}
|
|
346
|
+
* Accepts `EventTarget` (not just `Node`) since callers pass `event.target`/`event.relatedTarget` directly.
|
|
392
347
|
*/
|
|
393
348
|
elContains(other, considerSubmenus = true) {
|
|
394
349
|
if (this.el.contains(other)) return true;
|
|
395
350
|
if (considerSubmenus && this._p.currentSubDropList?.droplist?.elContains(other)) return true;
|
|
396
351
|
return false;
|
|
397
352
|
}
|
|
398
|
-
/**
|
|
399
|
-
* @param {string|string[]} classes
|
|
400
|
-
* @returns {DropList}
|
|
401
|
-
*/
|
|
402
353
|
setAdditionalClasses(classes) {
|
|
403
354
|
const p = this._p;
|
|
404
355
|
p.additionalClasses = classes;
|
|
@@ -407,8 +358,6 @@
|
|
|
407
358
|
}
|
|
408
359
|
/**
|
|
409
360
|
* Sets the appropriate direction for the droplist
|
|
410
|
-
* @param {'ltr'|'rtl'|'auto'} direction
|
|
411
|
-
* @return {DropList}
|
|
412
361
|
*/
|
|
413
362
|
setDirection(direction) {
|
|
414
363
|
const p = this._p;
|
|
@@ -418,46 +367,26 @@
|
|
|
418
367
|
}
|
|
419
368
|
/**
|
|
420
369
|
* Gets the supplied direction for the droplist
|
|
421
|
-
* @return {'ltr'|'rtl'|'auto'}
|
|
422
370
|
*/
|
|
423
371
|
getDirection() {
|
|
424
372
|
return this._p.direction;
|
|
425
373
|
}
|
|
426
|
-
/**
|
|
427
|
-
* @param {string} prop
|
|
428
|
-
* @returns {DropList}
|
|
429
|
-
*/
|
|
430
374
|
setLabelProp(prop) {
|
|
431
375
|
const p = this._p;
|
|
432
376
|
p.labelProp = prop;
|
|
433
377
|
return this;
|
|
434
378
|
}
|
|
435
|
-
/**
|
|
436
|
-
*
|
|
437
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [fn] Function to call when rendering an item element
|
|
438
|
-
* @returns {DropList}
|
|
439
|
-
*/
|
|
440
379
|
setRenderItem(fn) {
|
|
441
380
|
const p = this._p;
|
|
442
381
|
p.renderItem = fn;
|
|
443
382
|
return this;
|
|
444
383
|
}
|
|
445
|
-
/**
|
|
446
|
-
*
|
|
447
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [fn] Function to call when rendering an item element
|
|
448
|
-
* @returns {DropList}
|
|
449
|
-
*/
|
|
450
384
|
setUnrenderItem(fn) {
|
|
451
385
|
const p = this._p;
|
|
452
386
|
p.unrenderItem = fn;
|
|
453
387
|
this._setupUnrenderFunction();
|
|
454
388
|
return this;
|
|
455
389
|
}
|
|
456
|
-
/**
|
|
457
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element):(*|false))|null} render
|
|
458
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element))|null} unrender
|
|
459
|
-
* @returns {DropList}
|
|
460
|
-
*/
|
|
461
390
|
setRenderNoResultsItem(render, unrender) {
|
|
462
391
|
const p = this._p;
|
|
463
392
|
p.renderNoResultsItem = render;
|
|
@@ -467,6 +396,7 @@
|
|
|
467
396
|
}
|
|
468
397
|
/**
|
|
469
398
|
* @private
|
|
399
|
+
* @internal
|
|
470
400
|
*/
|
|
471
401
|
_setupUnrenderFunction() {
|
|
472
402
|
const p = this._p;
|
|
@@ -478,12 +408,20 @@
|
|
|
478
408
|
if (item === NoResultsItemSymbol) try {
|
|
479
409
|
fnNoResults(item, el);
|
|
480
410
|
} catch (err) {
|
|
481
|
-
|
|
411
|
+
reportError(p.onError, err, {
|
|
412
|
+
source: "unrenderNoResultsItem",
|
|
413
|
+
item,
|
|
414
|
+
el
|
|
415
|
+
});
|
|
482
416
|
}
|
|
483
417
|
else try {
|
|
484
418
|
fn(item[ItemSymbol], el);
|
|
485
419
|
} catch (err) {
|
|
486
|
-
|
|
420
|
+
reportError(p.onError, err, {
|
|
421
|
+
source: "unrenderItem",
|
|
422
|
+
item: item[ItemSymbol],
|
|
423
|
+
el
|
|
424
|
+
});
|
|
487
425
|
}
|
|
488
426
|
delete el[ItemSymbol];
|
|
489
427
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -494,15 +432,12 @@
|
|
|
494
432
|
});
|
|
495
433
|
return this;
|
|
496
434
|
}
|
|
497
|
-
/**
|
|
498
|
-
* @param {string} prop
|
|
499
|
-
* @returns {DropList}
|
|
500
|
-
*/
|
|
501
435
|
setValueProp(prop) {
|
|
502
436
|
const p = this._p;
|
|
503
437
|
p.valueProp = prop;
|
|
504
438
|
return this;
|
|
505
439
|
}
|
|
440
|
+
/** @internal */
|
|
506
441
|
_syncBaseClasses() {
|
|
507
442
|
const p = this._p, el = p.el;
|
|
508
443
|
if (!el) return;
|
|
@@ -541,7 +476,7 @@
|
|
|
541
476
|
goToLast(event) {
|
|
542
477
|
this._move("last", event);
|
|
543
478
|
}
|
|
544
|
-
toggleFocusedItem() {
|
|
479
|
+
toggleFocusedItem(event) {
|
|
545
480
|
const p = this._p;
|
|
546
481
|
if (this.hasFocusedItem() && p.multi) {
|
|
547
482
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -584,19 +519,16 @@
|
|
|
584
519
|
return true;
|
|
585
520
|
}
|
|
586
521
|
/**
|
|
587
|
-
*
|
|
588
|
-
* @param
|
|
589
|
-
* @param {number} [atIndex=-1] The index to insert at (or -1)
|
|
590
|
-
* @returns {DropList}
|
|
522
|
+
* @param item The item to add. It is copied.
|
|
523
|
+
* @param atIndex The index to insert at (or -1)
|
|
591
524
|
*/
|
|
592
525
|
addItem(item, atIndex = -1) {
|
|
593
526
|
return this.addItems([item], atIndex);
|
|
594
527
|
}
|
|
595
528
|
/**
|
|
596
529
|
* Adds items to the menu and renders
|
|
597
|
-
* @param
|
|
598
|
-
* @param
|
|
599
|
-
* @returns {DropList}
|
|
530
|
+
* @param itemsToAdd The items to add. These are copied.
|
|
531
|
+
* @param atIndex The index to insert at (or -1)
|
|
600
532
|
*/
|
|
601
533
|
addItems(itemsToAdd, atIndex = -1) {
|
|
602
534
|
const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
|
|
@@ -638,8 +570,7 @@
|
|
|
638
570
|
}
|
|
639
571
|
/**
|
|
640
572
|
* Replaces all current items with the supplied items
|
|
641
|
-
* @param
|
|
642
|
-
* @returns {DropList}
|
|
573
|
+
* @param items The items to set. These are copied.
|
|
643
574
|
*/
|
|
644
575
|
setItems(items) {
|
|
645
576
|
const p = this._p;
|
|
@@ -662,7 +593,7 @@
|
|
|
662
593
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
663
594
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
664
595
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
665
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
596
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
666
597
|
if (p.multi) {
|
|
667
598
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
668
599
|
}
|
|
@@ -670,10 +601,10 @@
|
|
|
670
601
|
if (!!newItem._group !== item._group) {
|
|
671
602
|
if (item._group) p.groupCount--;
|
|
672
603
|
else p.groupCount++;
|
|
673
|
-
|
|
604
|
+
item._group = !!newItem._group;
|
|
674
605
|
}
|
|
675
606
|
}
|
|
676
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
607
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
677
608
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
678
609
|
let virtualItemIndex = itemIndex;
|
|
679
610
|
if (p.filteredItems) {
|
|
@@ -784,8 +715,6 @@
|
|
|
784
715
|
/**
|
|
785
716
|
* Return the item element at the given original index, if it exists.
|
|
786
717
|
* The item may not be currently rendered, and null will be returned
|
|
787
|
-
* @param index
|
|
788
|
-
* @returns {HTMLElement|null}
|
|
789
718
|
*/
|
|
790
719
|
itemElementAtIndex(index) {
|
|
791
720
|
const p = this._p;
|
|
@@ -796,16 +725,10 @@
|
|
|
796
725
|
/**
|
|
797
726
|
* Return the item element at the given index, if it exists.
|
|
798
727
|
* The item may not be currently rendered, and null will be returned
|
|
799
|
-
* @param index
|
|
800
|
-
* @returns {HTMLElement|null}
|
|
801
728
|
*/
|
|
802
729
|
filteredElementItemAtIndex(index) {
|
|
803
730
|
return this._p.virtualListHelper.getItemElementAt(index) ?? null;
|
|
804
731
|
}
|
|
805
|
-
/**
|
|
806
|
-
* @param {function(dropList: DropList):DropList.PositionOptions} fn
|
|
807
|
-
* @returns {DropList}
|
|
808
|
-
*/
|
|
809
732
|
setPositionOptionsProvider(fn) {
|
|
810
733
|
const p = this._p;
|
|
811
734
|
if (p.positionOptionsProvider === fn) return this;
|
|
@@ -813,16 +736,27 @@
|
|
|
813
736
|
this.relayout();
|
|
814
737
|
return this;
|
|
815
738
|
}
|
|
816
|
-
/**
|
|
817
|
-
* @returns {function(dropList: DropList):DropList.PositionOptions|null}
|
|
818
|
-
*/
|
|
819
739
|
getPositionOptionsProvider() {
|
|
820
740
|
return this._p.positionOptionsProvider;
|
|
821
741
|
}
|
|
822
742
|
/**
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
|
|
743
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
744
|
+
* instead of the default `console.error`/`console.warn`.
|
|
745
|
+
*/
|
|
746
|
+
setOnError(fn) {
|
|
747
|
+
const p = this._p;
|
|
748
|
+
p.onError = fn ?? void 0;
|
|
749
|
+
return this;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Gets the current `onError` handler, if any.
|
|
753
|
+
*/
|
|
754
|
+
getOnError() {
|
|
755
|
+
return this._p.onError;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* @param term the search term to set
|
|
759
|
+
* @param performSearch should actually perform the search, or just set the input's text?
|
|
826
760
|
*/
|
|
827
761
|
setSearchTerm(term, performSearch = false) {
|
|
828
762
|
const p = this._p;
|
|
@@ -840,6 +774,7 @@
|
|
|
840
774
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
841
775
|
}
|
|
842
776
|
/** @private */
|
|
777
|
+
/** @internal */
|
|
843
778
|
_refilterItems() {
|
|
844
779
|
const p = this._p;
|
|
845
780
|
const term = p.filterTerm;
|
|
@@ -874,7 +809,7 @@
|
|
|
874
809
|
});
|
|
875
810
|
}
|
|
876
811
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
877
|
-
const matcher = new RegExp(
|
|
812
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
878
813
|
filteredItems = p.items.filter((x) => {
|
|
879
814
|
if (!filterGroups && x._group) return true;
|
|
880
815
|
return matcher.test(x.label);
|
|
@@ -926,45 +861,27 @@
|
|
|
926
861
|
if (p.items) return p.items.length;
|
|
927
862
|
return 0;
|
|
928
863
|
}
|
|
929
|
-
/**
|
|
930
|
-
* @param {string} noResultsText
|
|
931
|
-
* @returns {DropList}
|
|
932
|
-
*/
|
|
933
864
|
setNoResultsText(noResultsText) {
|
|
934
865
|
const p = this._p;
|
|
935
866
|
p.noResultsText = noResultsText;
|
|
936
867
|
if (p.hasNoResultsItem) p.virtualListHelper.refreshItemAt(0).render();
|
|
937
868
|
return this;
|
|
938
869
|
}
|
|
939
|
-
/**
|
|
940
|
-
* @returns {string}
|
|
941
|
-
*/
|
|
942
870
|
getNoResultsText() {
|
|
943
871
|
return this._p.noResultsText;
|
|
944
872
|
}
|
|
945
|
-
/**
|
|
946
|
-
* @param {number} window
|
|
947
|
-
* @returns {DropList}
|
|
948
|
-
*/
|
|
949
873
|
setFilterThrottleWindow(window) {
|
|
950
874
|
const p = this._p;
|
|
951
875
|
p.filterThrottleWindow = window;
|
|
952
876
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
953
877
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
954
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
878
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
955
879
|
if (isScheduled) p.throttledRefilterItems();
|
|
956
880
|
return this;
|
|
957
881
|
}
|
|
958
|
-
/**
|
|
959
|
-
* @returns {number}
|
|
960
|
-
*/
|
|
961
882
|
getFilterThrottleWindow() {
|
|
962
883
|
return this._p.filterThrottleWindow;
|
|
963
884
|
}
|
|
964
|
-
/**
|
|
965
|
-
* @param {boolean} value
|
|
966
|
-
* @returns {DropList}
|
|
967
|
-
*/
|
|
968
885
|
setFilterOnEmptyTerm(value) {
|
|
969
886
|
const p = this._p;
|
|
970
887
|
if (p.filterOnEmptyTerm === value) return this;
|
|
@@ -972,16 +889,9 @@
|
|
|
972
889
|
p.throttledRefilterItems();
|
|
973
890
|
return this;
|
|
974
891
|
}
|
|
975
|
-
/**
|
|
976
|
-
* @returns {boolean}
|
|
977
|
-
*/
|
|
978
892
|
getFilterOnEmptyTerm() {
|
|
979
893
|
return this._p.filterOnEmptyTerm;
|
|
980
894
|
}
|
|
981
|
-
/**
|
|
982
|
-
* @param {boolean} value
|
|
983
|
-
* @returns {DropList}
|
|
984
|
-
*/
|
|
985
895
|
setFilterGroups(value) {
|
|
986
896
|
const p = this._p;
|
|
987
897
|
if (p.filterGroups === value) return this;
|
|
@@ -989,52 +899,30 @@
|
|
|
989
899
|
p.throttledRefilterItems();
|
|
990
900
|
return this;
|
|
991
901
|
}
|
|
992
|
-
/**
|
|
993
|
-
* @returns {boolean}
|
|
994
|
-
*/
|
|
995
902
|
getFilterGroups() {
|
|
996
903
|
return this._p.filterGroups;
|
|
997
904
|
}
|
|
998
|
-
|
|
999
|
-
* @param {boolean} value
|
|
1000
|
-
* @returns {DropList}
|
|
1001
|
-
*/
|
|
1002
|
-
setFilterEmptyGroups(value) {
|
|
905
|
+
setFilterEmptyGroups(value = true) {
|
|
1003
906
|
const p = this._p;
|
|
1004
907
|
if (p.filterEmptyGroups === value) return this;
|
|
1005
908
|
p.filterEmptyGroups = value;
|
|
1006
909
|
p.throttledRefilterItems();
|
|
1007
910
|
return this;
|
|
1008
911
|
}
|
|
1009
|
-
/**
|
|
1010
|
-
* @returns {boolean}
|
|
1011
|
-
*/
|
|
1012
912
|
getFilterEmptyGroups() {
|
|
1013
913
|
return this._p.filterEmptyGroups;
|
|
1014
914
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
* @param {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} fn
|
|
1017
|
-
* @returns {DropList}
|
|
1018
|
-
*/
|
|
1019
915
|
setFilterFn(fn) {
|
|
1020
916
|
const p = this._p;
|
|
917
|
+
fn ??= null;
|
|
1021
918
|
if (p.filterFn === fn) return this;
|
|
1022
919
|
p.filterFn = fn;
|
|
1023
920
|
p.throttledRefilterItems();
|
|
1024
921
|
return this;
|
|
1025
922
|
}
|
|
1026
|
-
/**
|
|
1027
|
-
* @returns {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)}
|
|
1028
|
-
*/
|
|
1029
923
|
getFilterFn() {
|
|
1030
924
|
return this._p.filterFn;
|
|
1031
925
|
}
|
|
1032
|
-
/**
|
|
1033
|
-
*
|
|
1034
|
-
* @param {DropList.PositionOptions} [positionOptions]
|
|
1035
|
-
* @returns {DropList}
|
|
1036
|
-
* @public
|
|
1037
|
-
*/
|
|
1038
926
|
relayout(positionOptions) {
|
|
1039
927
|
const p = this._p, el = p.el, menuEl = p.menuEl;
|
|
1040
928
|
if (!this.isVisible()) return this;
|
|
@@ -1176,10 +1064,6 @@
|
|
|
1176
1064
|
}
|
|
1177
1065
|
/**
|
|
1178
1066
|
* Set the checked mode of a specific value.
|
|
1179
|
-
* @public
|
|
1180
|
-
* @param {*} value - array of values to check
|
|
1181
|
-
* @param {boolean} checked - will the value be checked?
|
|
1182
|
-
* @returns {DropList} self
|
|
1183
1067
|
*/
|
|
1184
1068
|
setItemChecked(value, checked) {
|
|
1185
1069
|
const p = this._p;
|
|
@@ -1199,9 +1083,6 @@
|
|
|
1199
1083
|
}
|
|
1200
1084
|
/**
|
|
1201
1085
|
* Set the checked values. All the other values will be unchecked,
|
|
1202
|
-
* @public
|
|
1203
|
-
* @param {Array<*>} values - array of values to check
|
|
1204
|
-
* @returns {DropList} self
|
|
1205
1086
|
*/
|
|
1206
1087
|
setCheckedValues(values) {
|
|
1207
1088
|
const p = this._p;
|
|
@@ -1224,11 +1105,9 @@
|
|
|
1224
1105
|
}
|
|
1225
1106
|
/**
|
|
1226
1107
|
* Get all checked values. Returns array of item values.
|
|
1227
|
-
* @
|
|
1228
|
-
* @param {boolean} excludeGroups=false Exclude group items
|
|
1229
|
-
* @returns {Array<*>} self
|
|
1108
|
+
* @param excludeGroups Exclude group items
|
|
1230
1109
|
*/
|
|
1231
|
-
getCheckedValues(excludeGroups) {
|
|
1110
|
+
getCheckedValues(excludeGroups = false) {
|
|
1232
1111
|
const p = this._p;
|
|
1233
1112
|
excludeGroups = excludeGroups && p.groupCount > 0;
|
|
1234
1113
|
let values = [];
|
|
@@ -1242,11 +1121,9 @@
|
|
|
1242
1121
|
}
|
|
1243
1122
|
/**
|
|
1244
1123
|
* Get all checked items. Returns array of actual item data object.
|
|
1245
|
-
* @
|
|
1246
|
-
* @param {boolean} excludeGroups=false Exclude group items
|
|
1247
|
-
* @returns {DropList.Item[]}
|
|
1124
|
+
* @param excludeGroups Exclude group items
|
|
1248
1125
|
*/
|
|
1249
|
-
getCheckedItems(excludeGroups) {
|
|
1126
|
+
getCheckedItems(excludeGroups = false) {
|
|
1250
1127
|
const p = this._p;
|
|
1251
1128
|
excludeGroups = excludeGroups && p.groupCount > 0;
|
|
1252
1129
|
const items = [];
|
|
@@ -1258,12 +1135,6 @@
|
|
|
1258
1135
|
}
|
|
1259
1136
|
return items;
|
|
1260
1137
|
}
|
|
1261
|
-
/**
|
|
1262
|
-
*
|
|
1263
|
-
* @param {DropList.PositionOptions?} [positionOptions]
|
|
1264
|
-
* @returns {DropList}
|
|
1265
|
-
* @public
|
|
1266
|
-
*/
|
|
1267
1138
|
show(positionOptions) {
|
|
1268
1139
|
const p = this._p;
|
|
1269
1140
|
p.hiding = false;
|
|
@@ -1297,7 +1168,7 @@
|
|
|
1297
1168
|
if (this.isVisible()) this._trigger("show");
|
|
1298
1169
|
return this;
|
|
1299
1170
|
}
|
|
1300
|
-
hide() {
|
|
1171
|
+
hide(event) {
|
|
1301
1172
|
const p = this._p, el = p.el;
|
|
1302
1173
|
if (p.onDocumentMouseDown) {
|
|
1303
1174
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1347,7 +1218,6 @@
|
|
|
1347
1218
|
/**
|
|
1348
1219
|
* Change visibility of the header element
|
|
1349
1220
|
* You should probably call `relayout()` after this.
|
|
1350
|
-
* @param {boolean} visible
|
|
1351
1221
|
*/
|
|
1352
1222
|
setHeaderVisible(visible) {
|
|
1353
1223
|
if (this.isHeaderVisible() === !!visible) return;
|
|
@@ -1356,14 +1226,12 @@
|
|
|
1356
1226
|
}
|
|
1357
1227
|
/**
|
|
1358
1228
|
* Is the header element visible?
|
|
1359
|
-
* @returns {boolean}
|
|
1360
1229
|
*/
|
|
1361
1230
|
isHeaderVisible() {
|
|
1362
1231
|
return !!this._p.headerEl.parentNode;
|
|
1363
1232
|
}
|
|
1364
1233
|
/**
|
|
1365
1234
|
* Get a reference to the header element in order to add custom content.
|
|
1366
|
-
* @returns {Element}
|
|
1367
1235
|
*/
|
|
1368
1236
|
getHeaderElement() {
|
|
1369
1237
|
return this._p.headerEl;
|
|
@@ -1371,7 +1239,6 @@
|
|
|
1371
1239
|
/**
|
|
1372
1240
|
* Change visibility of the footer element
|
|
1373
1241
|
* You should probably call `relayout()` after this.
|
|
1374
|
-
* @param {boolean} visible
|
|
1375
1242
|
*/
|
|
1376
1243
|
setFooterVisible(visible) {
|
|
1377
1244
|
if (this.isFooterVisible() === !!visible) return;
|
|
@@ -1380,14 +1247,12 @@
|
|
|
1380
1247
|
}
|
|
1381
1248
|
/**
|
|
1382
1249
|
* Is the footer element visible?
|
|
1383
|
-
* @returns {boolean}
|
|
1384
1250
|
*/
|
|
1385
1251
|
isFooterVisible() {
|
|
1386
1252
|
return !!this._p.footerEl.parentNode;
|
|
1387
1253
|
}
|
|
1388
1254
|
/**
|
|
1389
1255
|
* Get a reference to the footer element in order to add custom content.
|
|
1390
|
-
* @returns {Element}
|
|
1391
1256
|
*/
|
|
1392
1257
|
getFooterElement() {
|
|
1393
1258
|
return this._p.footerEl;
|
|
@@ -1395,7 +1260,6 @@
|
|
|
1395
1260
|
/**
|
|
1396
1261
|
* Set inline search visibility
|
|
1397
1262
|
* You should probably call `relayout()` after this.
|
|
1398
|
-
* @param {boolean} searchable
|
|
1399
1263
|
*/
|
|
1400
1264
|
setSearchable(searchable) {
|
|
1401
1265
|
const p = this._p;
|
|
@@ -1421,7 +1285,6 @@
|
|
|
1421
1285
|
}
|
|
1422
1286
|
/**
|
|
1423
1287
|
* Set the placeholder text of the inline search box
|
|
1424
|
-
* @param {string} placeholder
|
|
1425
1288
|
*/
|
|
1426
1289
|
setSearchPlaceholder(placeholder) {
|
|
1427
1290
|
const p = this._p;
|
|
@@ -1469,6 +1332,7 @@
|
|
|
1469
1332
|
}
|
|
1470
1333
|
return this;
|
|
1471
1334
|
}
|
|
1335
|
+
/** @internal */
|
|
1472
1336
|
_showSublist(item, itemElement) {
|
|
1473
1337
|
if (!item._subitems?.length) return;
|
|
1474
1338
|
const p = this._p;
|
|
@@ -1544,6 +1408,7 @@
|
|
|
1544
1408
|
droplist.show();
|
|
1545
1409
|
droplist.el.focus();
|
|
1546
1410
|
}
|
|
1411
|
+
/** @internal */
|
|
1547
1412
|
_hideSublist() {
|
|
1548
1413
|
const p = this._p;
|
|
1549
1414
|
if (!p.currentSubDropList) return;
|
|
@@ -1643,6 +1508,7 @@
|
|
|
1643
1508
|
}
|
|
1644
1509
|
return this;
|
|
1645
1510
|
}
|
|
1511
|
+
/** @internal */
|
|
1646
1512
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1647
1513
|
const p = this._p;
|
|
1648
1514
|
if (this._hasScroll()) {
|
|
@@ -1663,9 +1529,6 @@
|
|
|
1663
1529
|
}
|
|
1664
1530
|
/**
|
|
1665
1531
|
* Register an event handler
|
|
1666
|
-
* @param {(string|'*')?} event
|
|
1667
|
-
* @param {function(any)} handler
|
|
1668
|
-
* @returns {DropList}
|
|
1669
1532
|
*/
|
|
1670
1533
|
on(event, handler) {
|
|
1671
1534
|
this._p.mitt.on(event, handler);
|
|
@@ -1673,9 +1536,6 @@
|
|
|
1673
1536
|
}
|
|
1674
1537
|
/**
|
|
1675
1538
|
* Register a one time event handler
|
|
1676
|
-
* @param {(string|'*')?} event
|
|
1677
|
-
* @param {function(any)} handler
|
|
1678
|
-
* @returns {DropList}
|
|
1679
1539
|
*/
|
|
1680
1540
|
once(event, handler) {
|
|
1681
1541
|
let wrapped = (value) => {
|
|
@@ -1687,9 +1547,6 @@
|
|
|
1687
1547
|
}
|
|
1688
1548
|
/**
|
|
1689
1549
|
* Remove an `handler` for `event`, all events for `event`, or all events completely.
|
|
1690
|
-
* @param {(string|'*')?} event
|
|
1691
|
-
* @param {function(any)} handler
|
|
1692
|
-
* @returns {DropList}
|
|
1693
1550
|
*/
|
|
1694
1551
|
off(event, handler) {
|
|
1695
1552
|
if (!event && !event) this._p.mitt.all.clear();
|
|
@@ -1698,14 +1555,12 @@
|
|
|
1698
1555
|
}
|
|
1699
1556
|
/**
|
|
1700
1557
|
* Emit an event
|
|
1701
|
-
* @param {string} event
|
|
1702
|
-
* @param {any} value
|
|
1703
|
-
* @returns {DropList}
|
|
1704
1558
|
*/
|
|
1705
1559
|
emit(event, value) {
|
|
1706
1560
|
this._p.mitt.emit(event, value);
|
|
1707
1561
|
return this;
|
|
1708
1562
|
}
|
|
1563
|
+
/** @internal */
|
|
1709
1564
|
_getItemIndex(item) {
|
|
1710
1565
|
const p = this._p;
|
|
1711
1566
|
let itemIndex = -1;
|
|
@@ -1719,6 +1574,7 @@
|
|
|
1719
1574
|
}
|
|
1720
1575
|
return itemIndex;
|
|
1721
1576
|
}
|
|
1577
|
+
/** @internal */
|
|
1722
1578
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1723
1579
|
const p = this._p;
|
|
1724
1580
|
if (p.singleSelectedItemEl) {
|
|
@@ -1733,15 +1589,15 @@
|
|
|
1733
1589
|
return this;
|
|
1734
1590
|
}
|
|
1735
1591
|
/**
|
|
1736
|
-
* @param {string} event
|
|
1737
|
-
* @param {*} [data]
|
|
1738
1592
|
* @private
|
|
1593
|
+
* @internal
|
|
1739
1594
|
*/
|
|
1740
1595
|
_trigger(event, data) {
|
|
1741
1596
|
const p = this._p;
|
|
1742
1597
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1743
1598
|
p.mitt.emit(event, data);
|
|
1744
1599
|
}
|
|
1600
|
+
/** @internal */
|
|
1745
1601
|
_itemUpAction(event, itemEl) {
|
|
1746
1602
|
if ((0, _danielgindi_dom_utils_lib_Dom.closestUntil)(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1747
1603
|
let p = this._p;
|
|
@@ -1754,6 +1610,7 @@
|
|
|
1754
1610
|
}, 0);
|
|
1755
1611
|
}
|
|
1756
1612
|
}
|
|
1613
|
+
/** @internal */
|
|
1757
1614
|
_hookMouseEvents() {
|
|
1758
1615
|
const p = this._p;
|
|
1759
1616
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1767,9 +1624,11 @@
|
|
|
1767
1624
|
this._handleMouseOver(event, li);
|
|
1768
1625
|
});
|
|
1769
1626
|
}
|
|
1627
|
+
/** @internal */
|
|
1770
1628
|
_handleMouseOver(event, itemEl) {
|
|
1771
1629
|
this._focus(event, itemEl, null, true);
|
|
1772
1630
|
}
|
|
1631
|
+
/** @internal */
|
|
1773
1632
|
_hookTouchEvents() {
|
|
1774
1633
|
const p = this._p;
|
|
1775
1634
|
let currentTouchId;
|
|
@@ -1809,6 +1668,7 @@
|
|
|
1809
1668
|
});
|
|
1810
1669
|
});
|
|
1811
1670
|
}
|
|
1671
|
+
/** @internal */
|
|
1812
1672
|
_hookFocusEvents() {
|
|
1813
1673
|
const p = this._p;
|
|
1814
1674
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1826,10 +1686,12 @@
|
|
|
1826
1686
|
});
|
|
1827
1687
|
}, true);
|
|
1828
1688
|
}
|
|
1689
|
+
/** @internal */
|
|
1829
1690
|
_hookKeyEvents() {
|
|
1830
1691
|
const p = this._p;
|
|
1831
1692
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1832
1693
|
}
|
|
1694
|
+
/** @internal */
|
|
1833
1695
|
_hookSearchEvents() {
|
|
1834
1696
|
const p = this._p;
|
|
1835
1697
|
if (!p.searchInput) return;
|
|
@@ -1840,6 +1702,7 @@
|
|
|
1840
1702
|
p.throttledRefilterItems();
|
|
1841
1703
|
});
|
|
1842
1704
|
}
|
|
1705
|
+
/** @internal */
|
|
1843
1706
|
_keydown(event) {
|
|
1844
1707
|
const p = this._p;
|
|
1845
1708
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1868,9 +1731,7 @@
|
|
|
1868
1731
|
case keycode_js.VALUE_UP:
|
|
1869
1732
|
this.previous(event);
|
|
1870
1733
|
break;
|
|
1871
|
-
case keycode_js.VALUE_DOWN:
|
|
1872
|
-
this.next(event);
|
|
1873
|
-
break;
|
|
1734
|
+
case keycode_js.VALUE_DOWN: this.next(event);
|
|
1874
1735
|
}
|
|
1875
1736
|
break;
|
|
1876
1737
|
case keycode_js.VALUE_LEFT:
|
|
@@ -1902,6 +1763,7 @@
|
|
|
1902
1763
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1903
1764
|
}
|
|
1904
1765
|
}
|
|
1766
|
+
/** @internal */
|
|
1905
1767
|
_keydownFreeType(evt, autoSelect) {
|
|
1906
1768
|
const p = this._p;
|
|
1907
1769
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1910,7 +1772,7 @@
|
|
|
1910
1772
|
if (!isChar) return;
|
|
1911
1773
|
clearTimeout(p.filterTimer);
|
|
1912
1774
|
let keyword = (p.previousFilter || "") + character;
|
|
1913
|
-
let regex = new RegExp(`^${
|
|
1775
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1914
1776
|
let matchIndex = -1;
|
|
1915
1777
|
let item;
|
|
1916
1778
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1925,7 +1787,7 @@
|
|
|
1925
1787
|
}
|
|
1926
1788
|
if (matchIndex === -1) {
|
|
1927
1789
|
keyword = character;
|
|
1928
|
-
regex = new RegExp(`^${
|
|
1790
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1929
1791
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1930
1792
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1931
1793
|
item = items[i];
|
|
@@ -1945,6 +1807,7 @@
|
|
|
1945
1807
|
}, 1e3);
|
|
1946
1808
|
} else delete p.previousFilter;
|
|
1947
1809
|
}
|
|
1810
|
+
/** @internal */
|
|
1948
1811
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1949
1812
|
const p = this._p;
|
|
1950
1813
|
if (p._isFocusingItem) return;
|
|
@@ -1978,6 +1841,7 @@
|
|
|
1978
1841
|
p._isFocusingItem = false;
|
|
1979
1842
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1980
1843
|
}
|
|
1844
|
+
/** @internal */
|
|
1981
1845
|
_delayBlurItemOnBlur() {
|
|
1982
1846
|
if (this[DestroyedSymbol$1]) return;
|
|
1983
1847
|
const p = this._p;
|
|
@@ -1988,6 +1852,7 @@
|
|
|
1988
1852
|
this.blurFocusedItem();
|
|
1989
1853
|
}, p.autoItemBlurDelay);
|
|
1990
1854
|
}
|
|
1855
|
+
/** @internal */
|
|
1991
1856
|
_move(direction, event) {
|
|
1992
1857
|
const p = this._p;
|
|
1993
1858
|
let next, nextIndex, directionUp;
|
|
@@ -2057,10 +1922,12 @@
|
|
|
2057
1922
|
this._focus(event, next || null, nextIndex, false);
|
|
2058
1923
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2059
1924
|
}
|
|
1925
|
+
/** @internal */
|
|
2060
1926
|
_hasScroll() {
|
|
2061
1927
|
const menuEl = this._p.menuEl;
|
|
2062
1928
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2063
1929
|
}
|
|
1930
|
+
/** @internal */
|
|
2064
1931
|
_updateGroupStateForItem(item) {
|
|
2065
1932
|
const p = this._p;
|
|
2066
1933
|
if (!p.multi) return this;
|
|
@@ -2104,6 +1971,7 @@
|
|
|
2104
1971
|
}
|
|
2105
1972
|
return this;
|
|
2106
1973
|
}
|
|
1974
|
+
/** @internal */
|
|
2107
1975
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2108
1976
|
const p = this._p;
|
|
2109
1977
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2136,7 +2004,7 @@
|
|
|
2136
2004
|
}
|
|
2137
2005
|
/**
|
|
2138
2006
|
* @private
|
|
2139
|
-
* @
|
|
2007
|
+
* @internal
|
|
2140
2008
|
*/
|
|
2141
2009
|
_measureItem() {
|
|
2142
2010
|
const p = this._p;
|
|
@@ -2181,9 +2049,9 @@
|
|
|
2181
2049
|
}
|
|
2182
2050
|
/**
|
|
2183
2051
|
* Determines whether the list should be in virtual mode, depending on the item count.
|
|
2184
|
-
* @param
|
|
2185
|
-
* @returns {DropList}
|
|
2052
|
+
* @param targetItemCount item count we are expecting. Defaults to current item count
|
|
2186
2053
|
* @private
|
|
2054
|
+
* @internal
|
|
2187
2055
|
*/
|
|
2188
2056
|
_determineVirtualMode(targetItemCount) {
|
|
2189
2057
|
const p = this._p;
|
|
@@ -2193,6 +2061,7 @@
|
|
|
2193
2061
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2194
2062
|
return this;
|
|
2195
2063
|
}
|
|
2064
|
+
/** @internal */
|
|
2196
2065
|
_renderItemContent(item, itemEl) {
|
|
2197
2066
|
const p = this._p;
|
|
2198
2067
|
const originalItem = item[ItemSymbol];
|
|
@@ -2214,17 +2083,12 @@
|
|
|
2214
2083
|
}
|
|
2215
2084
|
}
|
|
2216
2085
|
}
|
|
2217
|
-
/**
|
|
2218
|
-
*
|
|
2219
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2220
|
-
* @returns {number} new outer width
|
|
2221
|
-
* @private
|
|
2222
|
-
*/
|
|
2086
|
+
/** @internal */
|
|
2223
2087
|
_updateWidth(positionOptions) {
|
|
2224
2088
|
const p = this._p, el = p.el;
|
|
2225
2089
|
let targetWidth = 0;
|
|
2226
2090
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2227
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2091
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2228
2092
|
else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
|
|
2229
2093
|
let autoWidth = 0;
|
|
2230
2094
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2246,15 +2110,10 @@
|
|
|
2246
2110
|
}
|
|
2247
2111
|
};
|
|
2248
2112
|
//#endregion
|
|
2249
|
-
//#region lib/SelectBox.
|
|
2113
|
+
//#region src/lib/SelectBox.ts
|
|
2250
2114
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2251
2115
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2252
2116
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
2253
|
-
/**
|
|
2254
|
-
* @param {Element|EventTarget} el
|
|
2255
|
-
* @param {string} className
|
|
2256
|
-
* @returns {boolean}
|
|
2257
|
-
*/
|
|
2258
2117
|
var hasClass = function(el, className) {
|
|
2259
2118
|
if (el instanceof Element) return el.classList.contains(className);
|
|
2260
2119
|
return false;
|
|
@@ -2272,57 +2131,6 @@
|
|
|
2272
2131
|
"padding-left",
|
|
2273
2132
|
"padding-right"
|
|
2274
2133
|
];
|
|
2275
|
-
/**
|
|
2276
|
-
* @typedef {Object} SelectBox.Options
|
|
2277
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2278
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2279
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2280
|
-
* @property {string|string[]} [additionalClasses]
|
|
2281
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2282
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2283
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2284
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2285
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2286
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2287
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2288
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2289
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2290
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2291
|
-
* @property {*[]} [stickyValues]
|
|
2292
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2293
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2294
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2295
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2296
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2297
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2298
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2299
|
-
* @property {string} [labelProp='label']
|
|
2300
|
-
* @property {string} [valueProp='value']
|
|
2301
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2302
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2303
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2304
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2305
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2306
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2307
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2308
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2309
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2310
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2311
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2312
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2313
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2314
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2315
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2316
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2317
|
-
* @property {boolean} [autoSelectTextOnCheck=true] automatically select text in input when an item is checked (multi mode). Used to allow the user to quickly type multiple items.
|
|
2318
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2319
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2320
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2321
|
-
* @property {function(name: string, ...args)} [on]
|
|
2322
|
-
* @property {boolean} [isLoadingMode]
|
|
2323
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2324
|
-
* @property {string[]} [clearInputWhen=['single_close','multi_select_single']] clear input box when closing the droplist or selecting <code>['single_close', 'multi_close', 'multi_select_single']</code>
|
|
2325
|
-
* */
|
|
2326
2134
|
var DefaultOptions$1 = {
|
|
2327
2135
|
el: null,
|
|
2328
2136
|
baseClassName: "selectbox",
|
|
@@ -2361,12 +2169,6 @@
|
|
|
2361
2169
|
closeListWhenLoading: true,
|
|
2362
2170
|
clearInputWhen: ["single_close", "multi_select_single"]
|
|
2363
2171
|
};
|
|
2364
|
-
/**
|
|
2365
|
-
*
|
|
2366
|
-
* @param {DropList.ItemBase[]} items
|
|
2367
|
-
* @param {string} labelProp
|
|
2368
|
-
* @returns {string}
|
|
2369
|
-
*/
|
|
2370
2172
|
var defaultMultiPlaceholderFormatter = (items, labelProp) => {
|
|
2371
2173
|
if (items.length === 0) return "";
|
|
2372
2174
|
let title = items[0][labelProp] + "";
|
|
@@ -2390,9 +2192,6 @@
|
|
|
2390
2192
|
return true;
|
|
2391
2193
|
}
|
|
2392
2194
|
var SelectBox = class {
|
|
2393
|
-
/**
|
|
2394
|
-
* @param {SelectBox.Options} options
|
|
2395
|
-
*/
|
|
2396
2195
|
constructor(options) {
|
|
2397
2196
|
const o = { ...DefaultOptions$1 };
|
|
2398
2197
|
for (let [key, value] of Object.entries(
|
|
@@ -2441,6 +2240,7 @@
|
|
|
2441
2240
|
on: o.on || null,
|
|
2442
2241
|
silenceEvents: true,
|
|
2443
2242
|
mitt: (0, mitt.default)(),
|
|
2243
|
+
onError: o.onError,
|
|
2444
2244
|
isLoadingMode: !!o.isLoadingMode,
|
|
2445
2245
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2446
2246
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2456,7 +2256,11 @@
|
|
|
2456
2256
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2457
2257
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2458
2258
|
filterFn: null,
|
|
2459
|
-
filterTerm: ""
|
|
2259
|
+
filterTerm: "",
|
|
2260
|
+
dropListVisible: false,
|
|
2261
|
+
lastActiveElement: null,
|
|
2262
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2263
|
+
presenceInt: null
|
|
2460
2264
|
};
|
|
2461
2265
|
let el = o.el;
|
|
2462
2266
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -2575,21 +2379,15 @@
|
|
|
2575
2379
|
}
|
|
2576
2380
|
/**
|
|
2577
2381
|
* Returns true if other is an inclusive descendant of droplist node, false otherwise, and undefined if the droplist is not initiated.
|
|
2578
|
-
* @param {Node} other
|
|
2579
|
-
* @param {boolean} [considerSubmenus=true]
|
|
2580
|
-
* @returns {boolean|undefined}
|
|
2581
2382
|
*/
|
|
2582
2383
|
droplistElContains(other, considerSubmenus = true) {
|
|
2583
2384
|
return this._p.dropList?.elContains(other, considerSubmenus);
|
|
2584
2385
|
}
|
|
2585
2386
|
/**
|
|
2586
2387
|
* Enables the control
|
|
2587
|
-
* @param {boolean=true} enabled Should the control be enabled?
|
|
2588
|
-
* @returns {SelectBox}
|
|
2589
2388
|
*/
|
|
2590
|
-
enable(enabled) {
|
|
2389
|
+
enable(enabled = true) {
|
|
2591
2390
|
const p = this._p;
|
|
2592
|
-
if (enabled === void 0) enabled = true;
|
|
2593
2391
|
p.disabled = !enabled;
|
|
2594
2392
|
p.el.setAttribute("aria-disabled", p.disabled.toString());
|
|
2595
2393
|
p.input.disabled = !!p.disabled;
|
|
@@ -2600,50 +2398,38 @@
|
|
|
2600
2398
|
}
|
|
2601
2399
|
/**
|
|
2602
2400
|
* Is the control enabled?
|
|
2603
|
-
* @returns {boolean}
|
|
2604
2401
|
*/
|
|
2605
2402
|
isEnabled() {
|
|
2606
2403
|
return !this._p.disabled;
|
|
2607
2404
|
}
|
|
2608
2405
|
/**
|
|
2609
2406
|
* Disables the control
|
|
2610
|
-
* @param {boolean=true} disabled Should the control be disabled?
|
|
2611
|
-
* @returns {SelectBox}
|
|
2612
2407
|
*/
|
|
2613
|
-
disable(disabled) {
|
|
2614
|
-
return this.enable(
|
|
2408
|
+
disable(disabled = true) {
|
|
2409
|
+
return this.enable(!disabled);
|
|
2615
2410
|
}
|
|
2616
2411
|
/**
|
|
2617
2412
|
* Is the control disabled?
|
|
2618
|
-
* @returns {boolean}
|
|
2619
2413
|
*/
|
|
2620
2414
|
isDisabled() {
|
|
2621
2415
|
return this._p.disabled;
|
|
2622
2416
|
}
|
|
2623
2417
|
/**
|
|
2624
2418
|
* Sets read only mode
|
|
2625
|
-
* @param {boolean=true} readOnly Should the control be read only?
|
|
2626
|
-
* @returns {SelectBox}
|
|
2627
2419
|
*/
|
|
2628
|
-
setReadOnly(readOnly) {
|
|
2420
|
+
setReadOnly(readOnly = true) {
|
|
2629
2421
|
const p = this._p;
|
|
2630
|
-
if (readOnly === void 0) readOnly = true;
|
|
2631
2422
|
p.readOnly = readOnly;
|
|
2632
2423
|
p.el.setAttribute("aria-readOnly", p.readOnly.toString());
|
|
2633
2424
|
p.input.readOnly = !(p.searchable || p.multi) || !!p.readOnly;
|
|
2634
2425
|
return this;
|
|
2635
2426
|
}
|
|
2636
2427
|
/**
|
|
2637
|
-
* Is the control
|
|
2638
|
-
* @returns {boolean}
|
|
2428
|
+
* Is the control read only?
|
|
2639
2429
|
*/
|
|
2640
2430
|
isReadOnly() {
|
|
2641
2431
|
return this._p.readOnly;
|
|
2642
2432
|
}
|
|
2643
|
-
/**
|
|
2644
|
-
* @param {string|string[]} classes
|
|
2645
|
-
* @returns {SelectBox}
|
|
2646
|
-
*/
|
|
2647
2433
|
setAdditionalClasses(classes) {
|
|
2648
2434
|
const p = this._p;
|
|
2649
2435
|
p.additionalClasses = classes;
|
|
@@ -2651,10 +2437,8 @@
|
|
|
2651
2437
|
return this;
|
|
2652
2438
|
}
|
|
2653
2439
|
/**
|
|
2654
|
-
*
|
|
2655
|
-
* @param
|
|
2656
|
-
* @param {boolean} [resetValues=true] should reset values to current values (essentially refresh the data based on items & values). If set to false, use setValue to set a fresh value
|
|
2657
|
-
* @returns {SelectBox}
|
|
2440
|
+
* @param items the items to set (not values)
|
|
2441
|
+
* @param resetValues should reset values to current values (essentially refresh the data based on items & values). If set to false, use setValue to set a fresh value
|
|
2658
2442
|
*/
|
|
2659
2443
|
setItems(items, resetValues = true) {
|
|
2660
2444
|
const p = this._p;
|
|
@@ -2690,16 +2474,9 @@
|
|
|
2690
2474
|
}
|
|
2691
2475
|
if (p.dropList) p.dropList.updateItemByValue(value, newItem);
|
|
2692
2476
|
}
|
|
2693
|
-
/**
|
|
2694
|
-
* @returns {DropList.ItemBase[]|*}
|
|
2695
|
-
*/
|
|
2696
2477
|
getItems() {
|
|
2697
2478
|
return this._p.items;
|
|
2698
2479
|
}
|
|
2699
|
-
/**
|
|
2700
|
-
* @param {boolean} clearable
|
|
2701
|
-
* @returns {SelectBox}
|
|
2702
|
-
*/
|
|
2703
2480
|
setClearable(clearable) {
|
|
2704
2481
|
clearable = !!clearable;
|
|
2705
2482
|
if (this._p.clearable === clearable) return this;
|
|
@@ -2707,16 +2484,9 @@
|
|
|
2707
2484
|
this._scheduleSync("render_clear");
|
|
2708
2485
|
return this;
|
|
2709
2486
|
}
|
|
2710
|
-
/**
|
|
2711
|
-
* @returns {boolean}
|
|
2712
|
-
*/
|
|
2713
2487
|
getClearable() {
|
|
2714
2488
|
return this._p.clearable;
|
|
2715
2489
|
}
|
|
2716
|
-
/**
|
|
2717
|
-
* @param {boolean} enabled
|
|
2718
|
-
* @returns {SelectBox}
|
|
2719
|
-
*/
|
|
2720
2490
|
setHasOpenIndicator(enabled) {
|
|
2721
2491
|
enabled = !!enabled;
|
|
2722
2492
|
if (this._p.hasOpenIndicator === enabled) return this;
|
|
@@ -2724,31 +2494,20 @@
|
|
|
2724
2494
|
this._scheduleSync("render_base");
|
|
2725
2495
|
return this;
|
|
2726
2496
|
}
|
|
2727
|
-
/**
|
|
2728
|
-
* @returns {boolean}
|
|
2729
|
-
*/
|
|
2730
2497
|
getHasOpenIndicator() {
|
|
2731
2498
|
return this._p.hasOpenIndicator;
|
|
2732
2499
|
}
|
|
2733
|
-
/**
|
|
2734
|
-
* @param {string} placeholder
|
|
2735
|
-
* @returns {SelectBox}
|
|
2736
|
-
*/
|
|
2737
2500
|
setPlaceholder(placeholder) {
|
|
2738
2501
|
this._p.placeholder = placeholder == null ? "" : String(placeholder);
|
|
2739
2502
|
this._scheduleSync("render_base");
|
|
2740
2503
|
return this;
|
|
2741
2504
|
}
|
|
2742
|
-
/**
|
|
2743
|
-
* @returns {string}
|
|
2744
|
-
*/
|
|
2745
2505
|
getPlaceHolder() {
|
|
2746
2506
|
return this._p.placeholder;
|
|
2747
2507
|
}
|
|
2748
2508
|
/**
|
|
2749
|
-
* @param
|
|
2750
|
-
* @param
|
|
2751
|
-
* @returns {SelectBox}
|
|
2509
|
+
* @param term the search term to set
|
|
2510
|
+
* @param performSearch should actually perform the search, or just set the input's text?
|
|
2752
2511
|
*/
|
|
2753
2512
|
setSearchTerm(term, performSearch = false) {
|
|
2754
2513
|
const p = this._p;
|
|
@@ -2762,9 +2521,6 @@
|
|
|
2762
2521
|
}
|
|
2763
2522
|
return this;
|
|
2764
2523
|
}
|
|
2765
|
-
/**
|
|
2766
|
-
* @returns {string}
|
|
2767
|
-
*/
|
|
2768
2524
|
getSearchTerm() {
|
|
2769
2525
|
const p = this._p;
|
|
2770
2526
|
if (p.input) return p.input.value;
|
|
@@ -2774,10 +2530,6 @@
|
|
|
2774
2530
|
this._p.dropList?.invokeRefilter();
|
|
2775
2531
|
return this;
|
|
2776
2532
|
}
|
|
2777
|
-
/**
|
|
2778
|
-
* @param {boolean} sortSelectedItems
|
|
2779
|
-
* @returns {SelectBox}
|
|
2780
|
-
*/
|
|
2781
2533
|
setSortSelectedItems(sortSelectedItems) {
|
|
2782
2534
|
const p = this._p;
|
|
2783
2535
|
sortSelectedItems = !!sortSelectedItems;
|
|
@@ -2786,16 +2538,9 @@
|
|
|
2786
2538
|
this._scheduleSync("render_items");
|
|
2787
2539
|
return this;
|
|
2788
2540
|
}
|
|
2789
|
-
/**
|
|
2790
|
-
* @returns {boolean}
|
|
2791
|
-
*/
|
|
2792
2541
|
isSortSelectedItemsEnabled() {
|
|
2793
2542
|
return this._p.sortSelectedItems;
|
|
2794
2543
|
}
|
|
2795
|
-
/**
|
|
2796
|
-
* @param {boolean} sortListItems
|
|
2797
|
-
* @returns {SelectBox}
|
|
2798
|
-
*/
|
|
2799
2544
|
setSortListItems(sortListItems) {
|
|
2800
2545
|
const p = this._p;
|
|
2801
2546
|
sortListItems = !!sortListItems;
|
|
@@ -2805,16 +2550,9 @@
|
|
|
2805
2550
|
this._scheduleSync("render_list");
|
|
2806
2551
|
return this;
|
|
2807
2552
|
}
|
|
2808
|
-
/**
|
|
2809
|
-
* @returns {boolean}
|
|
2810
|
-
*/
|
|
2811
2553
|
isSortListItemsEnabled() {
|
|
2812
2554
|
return this._p.sortListItems;
|
|
2813
2555
|
}
|
|
2814
|
-
/**
|
|
2815
|
-
* @param {boolean} sortListCheckedFirst
|
|
2816
|
-
* @returns {SelectBox}
|
|
2817
|
-
*/
|
|
2818
2556
|
setSortListCheckedFirst(sortListCheckedFirst) {
|
|
2819
2557
|
const p = this._p;
|
|
2820
2558
|
sortListCheckedFirst = !!sortListCheckedFirst;
|
|
@@ -2824,16 +2562,9 @@
|
|
|
2824
2562
|
this._scheduleSync("render_list");
|
|
2825
2563
|
return this;
|
|
2826
2564
|
}
|
|
2827
|
-
/**
|
|
2828
|
-
* @returns {boolean}
|
|
2829
|
-
*/
|
|
2830
2565
|
isSortListCheckedFirstEnabled() {
|
|
2831
2566
|
return this._p.sortListCheckedFirst;
|
|
2832
2567
|
}
|
|
2833
|
-
/**
|
|
2834
|
-
* @param {*[]} values
|
|
2835
|
-
* @returns {SelectBox}
|
|
2836
|
-
*/
|
|
2837
2568
|
setStickyValues(values) {
|
|
2838
2569
|
const p = this._p;
|
|
2839
2570
|
p.stickyValues = Array.isArray(values) ? new Set(values) : null;
|
|
@@ -2841,16 +2572,9 @@
|
|
|
2841
2572
|
this._scheduleSync("render_list");
|
|
2842
2573
|
return this;
|
|
2843
2574
|
}
|
|
2844
|
-
/**
|
|
2845
|
-
* @returns {*[]}
|
|
2846
|
-
*/
|
|
2847
2575
|
getStickyValues() {
|
|
2848
2576
|
return this._p.stickyValues ? Array.from(this._p.stickyValues) : null;
|
|
2849
2577
|
}
|
|
2850
|
-
/**
|
|
2851
|
-
* @param {function(a: DropList.ItemBase, b: DropList.ItemBase):number} comparator
|
|
2852
|
-
* @returns {SelectBox}
|
|
2853
|
-
*/
|
|
2854
2578
|
setSortItemComparator(comparator) {
|
|
2855
2579
|
const p = this._p;
|
|
2856
2580
|
if (p.sortItemComparator === comparator) return this;
|
|
@@ -2859,16 +2583,9 @@
|
|
|
2859
2583
|
this._scheduleSync("render_list");
|
|
2860
2584
|
return this;
|
|
2861
2585
|
}
|
|
2862
|
-
/**
|
|
2863
|
-
* @returns {function(a: DropList.ItemBase, b: DropList.ItemBase):number}
|
|
2864
|
-
*/
|
|
2865
2586
|
getSortItemComparator() {
|
|
2866
2587
|
return this._p.sortItemComparator;
|
|
2867
2588
|
}
|
|
2868
|
-
/**
|
|
2869
|
-
* @param {boolean} treatGroupSelectionAsItems
|
|
2870
|
-
* @returns {SelectBox}
|
|
2871
|
-
*/
|
|
2872
2589
|
setTreatGroupSelectionAsItems(treatGroupSelectionAsItems) {
|
|
2873
2590
|
const p = this._p;
|
|
2874
2591
|
treatGroupSelectionAsItems = !!treatGroupSelectionAsItems;
|
|
@@ -2880,16 +2597,9 @@
|
|
|
2880
2597
|
this._scheduleSync("render_list");
|
|
2881
2598
|
return this;
|
|
2882
2599
|
}
|
|
2883
|
-
/**
|
|
2884
|
-
* @returns {boolean}
|
|
2885
|
-
*/
|
|
2886
2600
|
isTreatGroupSelectionAsItemsEnabled() {
|
|
2887
2601
|
return !this._p.treatGroupSelectionAsItems;
|
|
2888
2602
|
}
|
|
2889
|
-
/**
|
|
2890
|
-
* @param {boolean} splitListCheckedGroups
|
|
2891
|
-
* @returns {SelectBox}
|
|
2892
|
-
*/
|
|
2893
2603
|
setSplitListCheckedGroups(splitListCheckedGroups) {
|
|
2894
2604
|
const p = this._p;
|
|
2895
2605
|
splitListCheckedGroups = !!splitListCheckedGroups;
|
|
@@ -2899,16 +2609,9 @@
|
|
|
2899
2609
|
this._scheduleSync("render_list");
|
|
2900
2610
|
return this;
|
|
2901
2611
|
}
|
|
2902
|
-
/**
|
|
2903
|
-
* @returns {boolean}
|
|
2904
|
-
*/
|
|
2905
2612
|
isSplitListCheckedGroupsEnabled() {
|
|
2906
2613
|
return this._p.splitListCheckedGroups;
|
|
2907
2614
|
}
|
|
2908
|
-
/**
|
|
2909
|
-
* @param {boolean} showSelection
|
|
2910
|
-
* @returns {SelectBox}
|
|
2911
|
-
*/
|
|
2912
2615
|
setShowSelection(showSelection) {
|
|
2913
2616
|
const p = this._p;
|
|
2914
2617
|
showSelection = !!showSelection;
|
|
@@ -2917,16 +2620,9 @@
|
|
|
2917
2620
|
this._scheduleSync("render_items");
|
|
2918
2621
|
return this;
|
|
2919
2622
|
}
|
|
2920
|
-
/**
|
|
2921
|
-
* @returns {boolean}
|
|
2922
|
-
*/
|
|
2923
2623
|
isShowSelectionEnabled() {
|
|
2924
2624
|
return this._p.showSelection;
|
|
2925
2625
|
}
|
|
2926
|
-
/**
|
|
2927
|
-
* @param {boolean} showPlaceholderInTooltip
|
|
2928
|
-
* @returns {SelectBox}
|
|
2929
|
-
*/
|
|
2930
2626
|
setShowPlaceholderInTooltip(showPlaceholderInTooltip) {
|
|
2931
2627
|
const p = this._p;
|
|
2932
2628
|
showPlaceholderInTooltip = !!showPlaceholderInTooltip;
|
|
@@ -2935,16 +2631,9 @@
|
|
|
2935
2631
|
this._scheduleSync("render_base");
|
|
2936
2632
|
return this;
|
|
2937
2633
|
}
|
|
2938
|
-
/**
|
|
2939
|
-
* @returns {boolean}
|
|
2940
|
-
*/
|
|
2941
2634
|
isShowPlaceholderInTooltipEnabled() {
|
|
2942
2635
|
return this._p.showPlaceholderInTooltip;
|
|
2943
2636
|
}
|
|
2944
|
-
/**
|
|
2945
|
-
* @param {function(items: DropList.ItemBase[]):string} formatter
|
|
2946
|
-
* @returns {SelectBox}
|
|
2947
|
-
*/
|
|
2948
2637
|
setMultiPlaceholderFormatter(formatter) {
|
|
2949
2638
|
const p = this._p;
|
|
2950
2639
|
if (p.multiPlaceholderFormatter === formatter) return this;
|
|
@@ -2952,26 +2641,15 @@
|
|
|
2952
2641
|
this._scheduleSync("render_base");
|
|
2953
2642
|
return this;
|
|
2954
2643
|
}
|
|
2955
|
-
/**
|
|
2956
|
-
* @param {boolean|'touch'} value
|
|
2957
|
-
* @returns {SelectBox}
|
|
2958
|
-
*/
|
|
2959
2644
|
setBlurOnSingleSelection(value) {
|
|
2960
2645
|
const p = this._p;
|
|
2961
2646
|
if (p.blurOnSingleSelection === value) return this;
|
|
2962
2647
|
p.blurOnSingleSelection = value;
|
|
2963
2648
|
return this;
|
|
2964
2649
|
}
|
|
2965
|
-
/**
|
|
2966
|
-
* @returns {boolean|'touch'}
|
|
2967
|
-
*/
|
|
2968
2650
|
getBlurOnSingleSelection() {
|
|
2969
2651
|
return this._p.blurOnSingleSelection;
|
|
2970
2652
|
}
|
|
2971
|
-
/**
|
|
2972
|
-
* @param {boolean} multi
|
|
2973
|
-
* @returns {SelectBox}
|
|
2974
|
-
*/
|
|
2975
2653
|
setMulti(multi) {
|
|
2976
2654
|
const p = this._p;
|
|
2977
2655
|
multi = !!multi;
|
|
@@ -2987,16 +2665,9 @@
|
|
|
2987
2665
|
this._scheduleSync("full");
|
|
2988
2666
|
return this;
|
|
2989
2667
|
}
|
|
2990
|
-
/**
|
|
2991
|
-
* @returns {boolean}
|
|
2992
|
-
*/
|
|
2993
2668
|
isMultiEnabled() {
|
|
2994
2669
|
return this._p.multi;
|
|
2995
2670
|
}
|
|
2996
|
-
/**
|
|
2997
|
-
* @param {boolean} searchable
|
|
2998
|
-
* @returns {SelectBox}
|
|
2999
|
-
*/
|
|
3000
2671
|
setSearchable(searchable) {
|
|
3001
2672
|
const p = this._p;
|
|
3002
2673
|
searchable = !!searchable;
|
|
@@ -3005,10 +2676,6 @@
|
|
|
3005
2676
|
this._scheduleSync("full");
|
|
3006
2677
|
return this;
|
|
3007
2678
|
}
|
|
3008
|
-
/**
|
|
3009
|
-
* @param {boolean} allowTypeToSelect
|
|
3010
|
-
* @returns {SelectBox}
|
|
3011
|
-
*/
|
|
3012
2679
|
setAllowTypeToSelect(allowTypeToSelect) {
|
|
3013
2680
|
const p = this._p;
|
|
3014
2681
|
allowTypeToSelect = !!allowTypeToSelect;
|
|
@@ -3016,129 +2683,71 @@
|
|
|
3016
2683
|
p.allowTypeToSelect = allowTypeToSelect;
|
|
3017
2684
|
return this;
|
|
3018
2685
|
}
|
|
3019
|
-
/**
|
|
3020
|
-
* @returns {boolean}
|
|
3021
|
-
*/
|
|
3022
2686
|
isSearchableEnabled() {
|
|
3023
2687
|
return this._p.searchable;
|
|
3024
2688
|
}
|
|
3025
|
-
/**
|
|
3026
|
-
* @param {string} noResultsText
|
|
3027
|
-
* @returns {SelectBox}
|
|
3028
|
-
*/
|
|
3029
2689
|
setNoResultsText(noResultsText) {
|
|
3030
2690
|
this._p.dropList?.setNoResultsText(noResultsText);
|
|
3031
2691
|
return this;
|
|
3032
2692
|
}
|
|
3033
|
-
/**
|
|
3034
|
-
* @returns {string}
|
|
3035
|
-
*/
|
|
3036
2693
|
getNoResultsText() {
|
|
3037
2694
|
return this._p.noResultsText;
|
|
3038
2695
|
}
|
|
3039
|
-
/**
|
|
3040
|
-
* @param {boolean} autoSelectTextOnCheck
|
|
3041
|
-
* @returns {SelectBox}
|
|
3042
|
-
*/
|
|
3043
2696
|
setAutoSelectTextOnCheck(autoSelectTextOnCheck) {
|
|
3044
2697
|
this._p.autoSelectTextOnCheck = autoSelectTextOnCheck;
|
|
3045
2698
|
return this;
|
|
3046
2699
|
}
|
|
3047
|
-
/**
|
|
3048
|
-
* @returns {boolean}
|
|
3049
|
-
*/
|
|
3050
2700
|
getAutoSelectTextOnCheck() {
|
|
3051
2701
|
return this._p.autoSelectTextOnCheck;
|
|
3052
2702
|
}
|
|
3053
|
-
/**
|
|
3054
|
-
* @param {number} window
|
|
3055
|
-
* @returns {SelectBox}
|
|
3056
|
-
*/
|
|
3057
2703
|
setFilterThrottleWindow(window) {
|
|
3058
2704
|
const p = this._p;
|
|
3059
2705
|
p.filterThrottleWindow = window;
|
|
3060
2706
|
p.dropList?.setFilterThrottleWindow(window);
|
|
3061
2707
|
return this;
|
|
3062
2708
|
}
|
|
3063
|
-
/**
|
|
3064
|
-
* @returns {number}
|
|
3065
|
-
*/
|
|
3066
2709
|
getFilterThrottleWindow() {
|
|
3067
2710
|
return this._p.filterThrottleWindow;
|
|
3068
2711
|
}
|
|
3069
|
-
/**
|
|
3070
|
-
* @param {boolean} value
|
|
3071
|
-
* @returns {SelectBox}
|
|
3072
|
-
*/
|
|
3073
2712
|
setFilterOnEmptyTerm(value) {
|
|
3074
2713
|
const p = this._p;
|
|
3075
2714
|
if (p.filterOnEmptyTerm === value) return this;
|
|
3076
2715
|
p.dropList?.setFilterOnEmptyTerm(value);
|
|
3077
2716
|
return this;
|
|
3078
2717
|
}
|
|
3079
|
-
/**
|
|
3080
|
-
* @returns {boolean}
|
|
3081
|
-
*/
|
|
3082
2718
|
getFilterOnEmptyTerm() {
|
|
3083
2719
|
return this._p.filterOnEmptyTerm;
|
|
3084
2720
|
}
|
|
3085
|
-
/**
|
|
3086
|
-
* @param {DropList.Options} listOptions
|
|
3087
|
-
* @returns {SelectBox}
|
|
3088
|
-
*/
|
|
3089
2721
|
setListOptions(listOptions) {
|
|
3090
2722
|
const p = this._p;
|
|
3091
2723
|
p.listOptions = listOptions;
|
|
3092
2724
|
this._setupDropdownMenu();
|
|
3093
2725
|
return this;
|
|
3094
2726
|
}
|
|
3095
|
-
/**
|
|
3096
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element):(*|false))|null} render
|
|
3097
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element))|null} unrender
|
|
3098
|
-
* @returns {SelectBox})|null
|
|
3099
|
-
*/
|
|
3100
2727
|
setRenderSingleItem(render, unrender) {
|
|
3101
2728
|
const p = this._p;
|
|
3102
2729
|
p.renderSingleItem = render;
|
|
3103
2730
|
p.unrenderSingleItem = unrender;
|
|
3104
2731
|
return this;
|
|
3105
2732
|
}
|
|
3106
|
-
/**
|
|
3107
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element):(*|false))|null} render
|
|
3108
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element))|null} unrender
|
|
3109
|
-
* @returns {SelectBox}
|
|
3110
|
-
*/
|
|
3111
2733
|
setRenderMultiItem(render, unrender) {
|
|
3112
2734
|
const p = this._p;
|
|
3113
2735
|
p.renderMultiItem = render;
|
|
3114
2736
|
p.unrenderMultiItem = unrender;
|
|
3115
2737
|
return this;
|
|
3116
2738
|
}
|
|
3117
|
-
/**
|
|
3118
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element):(*|false))|null} render
|
|
3119
|
-
* @param {(function(item: DropList.ItemBase, itemEl: Element))|null} unrender
|
|
3120
|
-
* @returns {SelectBox}
|
|
3121
|
-
*/
|
|
3122
2739
|
setRenderRestMultiItem(render, unrender) {
|
|
3123
2740
|
const p = this._p;
|
|
3124
2741
|
p.renderRestMultiItem = render;
|
|
3125
2742
|
p.unrenderRestMultiItem = unrender;
|
|
3126
2743
|
return this;
|
|
3127
2744
|
}
|
|
3128
|
-
/**
|
|
3129
|
-
* @param {string} prop
|
|
3130
|
-
* @returns {SelectBox}
|
|
3131
|
-
*/
|
|
3132
2745
|
setLabelProp(prop) {
|
|
3133
2746
|
const p = this._p;
|
|
3134
2747
|
p.labelProp = prop;
|
|
3135
2748
|
if (p.dropList) p.dropList.setLabelProp(prop);
|
|
3136
2749
|
return this;
|
|
3137
2750
|
}
|
|
3138
|
-
/**
|
|
3139
|
-
* @param {string} prop
|
|
3140
|
-
* @returns {SelectBox}
|
|
3141
|
-
*/
|
|
3142
2751
|
setValueProp(prop) {
|
|
3143
2752
|
const p = this._p;
|
|
3144
2753
|
if (p.valueProp === prop) return this;
|
|
@@ -3147,54 +2756,35 @@
|
|
|
3147
2756
|
this._refreshItemByValueMap();
|
|
3148
2757
|
return this;
|
|
3149
2758
|
}
|
|
3150
|
-
/**
|
|
3151
|
-
* @param {string} prop
|
|
3152
|
-
* @returns {SelectBox}
|
|
3153
|
-
*/
|
|
3154
2759
|
setMultiItemLabelProp(prop) {
|
|
3155
2760
|
const p = this._p;
|
|
3156
2761
|
p.multiItemLabelProp = prop;
|
|
3157
2762
|
this._scheduleSync("render_items");
|
|
3158
2763
|
return this;
|
|
3159
2764
|
}
|
|
3160
|
-
/**
|
|
3161
|
-
* @param {'before'|'after'|'none'} position
|
|
3162
|
-
* @returns {SelectBox}
|
|
3163
|
-
*/
|
|
3164
2765
|
setMultiItemRemovePosition(position) {
|
|
3165
2766
|
const p = this._p;
|
|
3166
2767
|
p.multiItemRemovePosition = position;
|
|
3167
2768
|
this._scheduleSync("render_items");
|
|
3168
2769
|
return this;
|
|
3169
2770
|
}
|
|
3170
|
-
/**
|
|
3171
|
-
* @param {number|null|undefined} value
|
|
3172
|
-
* @returns {SelectBox}
|
|
3173
|
-
*/
|
|
3174
2771
|
setMaxMultiItems(value) {
|
|
3175
2772
|
const p = this._p;
|
|
3176
2773
|
p.maxMultiItems = value;
|
|
3177
2774
|
return this;
|
|
3178
2775
|
}
|
|
3179
|
-
/**
|
|
3180
|
-
* @param {function(count: number, items: DropList.ItemBase[]):string|null|undefined} value
|
|
3181
|
-
* @returns {SelectBox}
|
|
3182
|
-
*/
|
|
3183
2776
|
setMultiItemsRestLabelProvider(value) {
|
|
3184
2777
|
const p = this._p;
|
|
3185
2778
|
p.multiItemsRestLabelProvider = value;
|
|
3186
2779
|
return this;
|
|
3187
2780
|
}
|
|
3188
|
-
/**
|
|
3189
|
-
* @param {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} fn
|
|
3190
|
-
* @returns {SelectBox}
|
|
3191
|
-
*/
|
|
3192
2781
|
setFilterFn(fn) {
|
|
3193
2782
|
const p = this._p;
|
|
2783
|
+
fn ??= null;
|
|
3194
2784
|
if (p.filterFn === fn) return this;
|
|
3195
2785
|
p.filterFn = fn;
|
|
3196
2786
|
if (!fn) fn = (items, term) => {
|
|
3197
|
-
const matcher = new RegExp(
|
|
2787
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3198
2788
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3199
2789
|
return p.items.filter((x) => {
|
|
3200
2790
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3205,15 +2795,28 @@
|
|
|
3205
2795
|
p.dropList?.setFilterFn(fn);
|
|
3206
2796
|
return this;
|
|
3207
2797
|
}
|
|
3208
|
-
/**
|
|
3209
|
-
* @returns {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)}
|
|
3210
|
-
*/
|
|
3211
2798
|
getFilterFn() {
|
|
3212
2799
|
return this._p.filterFn;
|
|
3213
2800
|
}
|
|
3214
2801
|
/**
|
|
2802
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderMultiItem`/`unrenderSingleItem`)
|
|
2803
|
+
* instead of the default `console.error`/`console.warn`. Also used as the default `onError` for the internal
|
|
2804
|
+
* `DropList`, unless `listOptions.onError` is set explicitly.
|
|
2805
|
+
*/
|
|
2806
|
+
setOnError(fn) {
|
|
2807
|
+
const p = this._p;
|
|
2808
|
+
p.onError = fn ?? void 0;
|
|
2809
|
+
p.dropList?.setOnError(p.listOptions?.onError ?? p.onError);
|
|
2810
|
+
return this;
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Gets the current `onError` handler, if any.
|
|
2814
|
+
*/
|
|
2815
|
+
getOnError() {
|
|
2816
|
+
return this._p.onError;
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
3215
2819
|
* Focus on input element
|
|
3216
|
-
* @returns {SelectBox}
|
|
3217
2820
|
*/
|
|
3218
2821
|
focusInput() {
|
|
3219
2822
|
const p = this._p;
|
|
@@ -3222,7 +2825,6 @@
|
|
|
3222
2825
|
}
|
|
3223
2826
|
/**
|
|
3224
2827
|
* Remvoe focus from the input element
|
|
3225
|
-
* @returns {SelectBox}
|
|
3226
2828
|
*/
|
|
3227
2829
|
blurInput() {
|
|
3228
2830
|
const p = this._p;
|
|
@@ -3231,7 +2833,6 @@
|
|
|
3231
2833
|
}
|
|
3232
2834
|
/**
|
|
3233
2835
|
* Removes all selected items
|
|
3234
|
-
* @returns {SelectBox}
|
|
3235
2836
|
*/
|
|
3236
2837
|
clear() {
|
|
3237
2838
|
if (!this._performClearWithEvent(true)) return this;
|
|
@@ -3240,8 +2841,6 @@
|
|
|
3240
2841
|
}
|
|
3241
2842
|
/**
|
|
3242
2843
|
* Returns a single value or an array of selected values - depending on `multi` prop
|
|
3243
|
-
* @public
|
|
3244
|
-
* @returns {*[]}
|
|
3245
2844
|
*/
|
|
3246
2845
|
getValue() {
|
|
3247
2846
|
const p = this._p;
|
|
@@ -3250,9 +2849,7 @@
|
|
|
3250
2849
|
}
|
|
3251
2850
|
/**
|
|
3252
2851
|
* Selects the specified value or multiple values - depending on `multi` prop
|
|
3253
|
-
* @
|
|
3254
|
-
* @param {*|*[]} value - if `multi`, then an array of values to select, otherwise - a single value to select
|
|
3255
|
-
* @returns {SelectBox}
|
|
2852
|
+
* @param value - if `multi`, then an array of values to select, otherwise - a single value to select
|
|
3256
2853
|
*/
|
|
3257
2854
|
setValue(value) {
|
|
3258
2855
|
if (this._p.multi) return this.setSelectedValues(Array.isArray(value) ? value : value !== void 0 ? [value] : []);
|
|
@@ -3260,17 +2857,12 @@
|
|
|
3260
2857
|
}
|
|
3261
2858
|
/**
|
|
3262
2859
|
* Returns an array of selected values
|
|
3263
|
-
* @public
|
|
3264
|
-
* @returns {*[]}
|
|
3265
2860
|
*/
|
|
3266
2861
|
getSelectedValues() {
|
|
3267
2862
|
return this._p.selectedValues.slice(0);
|
|
3268
2863
|
}
|
|
3269
2864
|
/**
|
|
3270
2865
|
* Selects the specified values
|
|
3271
|
-
* @public
|
|
3272
|
-
* @param {*[]} values - an array of *values* to select
|
|
3273
|
-
* @returns {SelectBox}
|
|
3274
2866
|
*/
|
|
3275
2867
|
setSelectedValues(values) {
|
|
3276
2868
|
const p = this._p, valueProp = p.valueProp;
|
|
@@ -3295,16 +2887,12 @@
|
|
|
3295
2887
|
}
|
|
3296
2888
|
/**
|
|
3297
2889
|
* Returns the count of selected values
|
|
3298
|
-
* @public
|
|
3299
|
-
* @returns {number}
|
|
3300
2890
|
*/
|
|
3301
2891
|
getSelectedValueCount() {
|
|
3302
2892
|
return this._p.selectedValues.length;
|
|
3303
2893
|
}
|
|
3304
2894
|
/**
|
|
3305
2895
|
* Returns an array of selected items
|
|
3306
|
-
* @public
|
|
3307
|
-
* @returns {Array.<Object>}
|
|
3308
2896
|
*/
|
|
3309
2897
|
getSelectedItems() {
|
|
3310
2898
|
return this._p.selectedItems.slice(0);
|
|
@@ -3313,17 +2901,11 @@
|
|
|
3313
2901
|
* Sets the specified items to "checked" mode.
|
|
3314
2902
|
* An array of items is passed, not values, because we need to keep track if items,
|
|
3315
2903
|
* and if we already have the array of items then this spares the process of searching for the items by values.
|
|
3316
|
-
* @public
|
|
3317
|
-
* @param {DropList.ItemBase[]} items - an array of *items* to select (not values)
|
|
3318
|
-
* @returns {SelectBox}
|
|
3319
2904
|
*/
|
|
3320
2905
|
setSelectedItems(items) {
|
|
3321
2906
|
this._setSelectedItems(items);
|
|
3322
2907
|
return this;
|
|
3323
2908
|
}
|
|
3324
|
-
/**
|
|
3325
|
-
* @returns {SelectBox}
|
|
3326
|
-
*/
|
|
3327
2909
|
openList() {
|
|
3328
2910
|
const p = this._p;
|
|
3329
2911
|
if (p.dropList.isVisible()) return this;
|
|
@@ -3338,9 +2920,6 @@
|
|
|
3338
2920
|
else if (!p.multi && this.getValue() !== void 0) p.dropList.setFocusedItemByValue(this.getValue());
|
|
3339
2921
|
return this;
|
|
3340
2922
|
}
|
|
3341
|
-
/**
|
|
3342
|
-
* @returns {SelectBox}
|
|
3343
|
-
*/
|
|
3344
2923
|
closeList() {
|
|
3345
2924
|
const p = this._p;
|
|
3346
2925
|
if (this[DestroyedSymbol]) return this;
|
|
@@ -3352,32 +2931,17 @@
|
|
|
3352
2931
|
}
|
|
3353
2932
|
return this;
|
|
3354
2933
|
}
|
|
3355
|
-
/**
|
|
3356
|
-
* @param {boolean} [open]
|
|
3357
|
-
* @returns {SelectBox}
|
|
3358
|
-
*/
|
|
3359
2934
|
toggleList(open) {
|
|
3360
2935
|
const p = this._p;
|
|
3361
2936
|
if (open === void 0 ? !p.dropList.isVisible() : !!open) return this.openList();
|
|
3362
2937
|
else return this.closeList();
|
|
3363
2938
|
}
|
|
3364
|
-
/**
|
|
3365
|
-
* @returns {boolean}
|
|
3366
|
-
*/
|
|
3367
2939
|
isListOpen() {
|
|
3368
2940
|
return !!this._p.dropListVisible;
|
|
3369
2941
|
}
|
|
3370
|
-
/**
|
|
3371
|
-
* @param {boolean} [on]
|
|
3372
|
-
* @returns {SelectBox}
|
|
3373
|
-
*/
|
|
3374
2942
|
toggleLoading(on) {
|
|
3375
2943
|
return this.setIsLoadingMode(on === void 0 ? !this.getIsLoadingMode() : !!on);
|
|
3376
2944
|
}
|
|
3377
|
-
/**
|
|
3378
|
-
* @param {boolean} isLoadingMode
|
|
3379
|
-
* @returns {SelectBox}
|
|
3380
|
-
*/
|
|
3381
2945
|
setIsLoadingMode(isLoadingMode) {
|
|
3382
2946
|
const p = this._p;
|
|
3383
2947
|
isLoadingMode = isLoadingMode === void 0 ? true : !!isLoadingMode;
|
|
@@ -3388,31 +2952,21 @@
|
|
|
3388
2952
|
this._scheduleSync("render_base");
|
|
3389
2953
|
return this;
|
|
3390
2954
|
}
|
|
3391
|
-
/**
|
|
3392
|
-
* @returns {boolean}
|
|
3393
|
-
*/
|
|
3394
2955
|
getIsLoadingMode() {
|
|
3395
2956
|
return this._p.isLoadingMode;
|
|
3396
2957
|
}
|
|
3397
2958
|
/**
|
|
3398
2959
|
* Sets whether to close the list when loading mode is enabled
|
|
3399
|
-
* @param {boolean} closeListWhenLoading
|
|
3400
|
-
* @returns {SelectBox}
|
|
3401
2960
|
*/
|
|
3402
2961
|
setCloseListWhenLoading(closeListWhenLoading) {
|
|
3403
2962
|
this._p.closeListWhenLoading = closeListWhenLoading;
|
|
3404
2963
|
return this;
|
|
3405
2964
|
}
|
|
3406
|
-
/**
|
|
3407
|
-
* @returns {boolean}
|
|
3408
|
-
*/
|
|
3409
2965
|
getCloseListWhenLoading() {
|
|
3410
2966
|
return this._p.closeListWhenLoading;
|
|
3411
2967
|
}
|
|
3412
2968
|
/**
|
|
3413
2969
|
* Sets when to clear the input field
|
|
3414
|
-
* @param {string[]} clearInputWhen
|
|
3415
|
-
* @returns {SelectBox}
|
|
3416
2970
|
*/
|
|
3417
2971
|
setClearInputWhen(clearInputWhen) {
|
|
3418
2972
|
this._p.clearInputWhen = Array.isArray(clearInputWhen) ? clearInputWhen.slice(0) : [];
|
|
@@ -3420,15 +2974,12 @@
|
|
|
3420
2974
|
}
|
|
3421
2975
|
/**
|
|
3422
2976
|
* Retrieves the settings for when to clear the input field
|
|
3423
|
-
* @returns {string[]}
|
|
3424
2977
|
*/
|
|
3425
2978
|
getClearInputWhen() {
|
|
3426
2979
|
return this._p.clearInputWhen;
|
|
3427
2980
|
}
|
|
3428
2981
|
/**
|
|
3429
2982
|
* Sets the appropriate direction for the selectbox
|
|
3430
|
-
* @param {'ltr'|'rtl'|'auto'} direction
|
|
3431
|
-
* @return {SelectBox}
|
|
3432
2983
|
*/
|
|
3433
2984
|
setDirection(direction) {
|
|
3434
2985
|
const p = this._p;
|
|
@@ -3438,14 +2989,12 @@
|
|
|
3438
2989
|
}
|
|
3439
2990
|
/**
|
|
3440
2991
|
* Gets the supplied direction for the selectbox
|
|
3441
|
-
* @return {'ltr'|'rtl'|'auto'}
|
|
3442
2992
|
*/
|
|
3443
2993
|
getDirection() {
|
|
3444
2994
|
return this._p.direction;
|
|
3445
2995
|
}
|
|
3446
2996
|
/**
|
|
3447
2997
|
* Can be called in case that the selectbox was attached to the dom late and has a weird size.
|
|
3448
|
-
* @returns {SelectBox}
|
|
3449
2998
|
*/
|
|
3450
2999
|
refreshSize() {
|
|
3451
3000
|
this._resizeInput();
|
|
@@ -3453,9 +3002,6 @@
|
|
|
3453
3002
|
}
|
|
3454
3003
|
/**
|
|
3455
3004
|
* Register an event handler
|
|
3456
|
-
* @param {(string|'*')?} event
|
|
3457
|
-
* @param {function(any)} handler
|
|
3458
|
-
* @returns {SelectBox}
|
|
3459
3005
|
*/
|
|
3460
3006
|
on(event, handler) {
|
|
3461
3007
|
this._p.mitt.on(event, handler);
|
|
@@ -3463,9 +3009,6 @@
|
|
|
3463
3009
|
}
|
|
3464
3010
|
/**
|
|
3465
3011
|
* Register a one time event handler
|
|
3466
|
-
* @param {(string|'*')?} event
|
|
3467
|
-
* @param {function(any)} handler
|
|
3468
|
-
* @returns {SelectBox}
|
|
3469
3012
|
*/
|
|
3470
3013
|
once(event, handler) {
|
|
3471
3014
|
let wrapped = (value) => {
|
|
@@ -3477,9 +3020,6 @@
|
|
|
3477
3020
|
}
|
|
3478
3021
|
/**
|
|
3479
3022
|
* Remove an `handler` for `event`, all events for `event`, or all events completely.
|
|
3480
|
-
* @param {(string|'*')?} event
|
|
3481
|
-
* @param {function(any)} handler
|
|
3482
|
-
* @returns {SelectBox}
|
|
3483
3023
|
*/
|
|
3484
3024
|
off(event, handler) {
|
|
3485
3025
|
if (!event && !event) this._p.mitt.all.clear();
|
|
@@ -3488,9 +3028,6 @@
|
|
|
3488
3028
|
}
|
|
3489
3029
|
/**
|
|
3490
3030
|
* Emit an event
|
|
3491
|
-
* @param {string} event
|
|
3492
|
-
* @param {any} value
|
|
3493
|
-
* @returns {SelectBox}
|
|
3494
3031
|
*/
|
|
3495
3032
|
emit(event, value) {
|
|
3496
3033
|
this._p.mitt.emit(event, value);
|
|
@@ -3500,6 +3037,7 @@
|
|
|
3500
3037
|
* Prepare the mapping between values and items.
|
|
3501
3038
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3502
3039
|
* @private
|
|
3040
|
+
* @internal
|
|
3503
3041
|
*/
|
|
3504
3042
|
_refreshItemByValueMap() {
|
|
3505
3043
|
const p = this._p;
|
|
@@ -3509,9 +3047,8 @@
|
|
|
3509
3047
|
p.subitemByValueMap = null;
|
|
3510
3048
|
}
|
|
3511
3049
|
/**
|
|
3512
|
-
* @param {*} value
|
|
3513
|
-
* @returns {DropList.ItemBase|undefined}
|
|
3514
3050
|
* @private
|
|
3051
|
+
* @internal
|
|
3515
3052
|
*/
|
|
3516
3053
|
_getItemByValue(value) {
|
|
3517
3054
|
const p = this._p;
|
|
@@ -3521,16 +3058,15 @@
|
|
|
3521
3058
|
return p.subitemByValueMap.get(value);
|
|
3522
3059
|
}
|
|
3523
3060
|
/** @private */
|
|
3061
|
+
/** @internal */
|
|
3524
3062
|
_refreshSubitemByValueMap() {
|
|
3525
3063
|
const p = this._p;
|
|
3526
3064
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
3527
3065
|
this._addSubitemsToValueMap(p.items, subitemByValueMap, p.valueProp);
|
|
3528
3066
|
}
|
|
3529
3067
|
/**
|
|
3530
|
-
* @param {DropList.ItemBase[]} items
|
|
3531
|
-
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3532
|
-
* @param {string} valueProp
|
|
3533
3068
|
* @private
|
|
3069
|
+
* @internal
|
|
3534
3070
|
*/
|
|
3535
3071
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3536
3072
|
for (let item of items) {
|
|
@@ -3540,6 +3076,7 @@
|
|
|
3540
3076
|
}
|
|
3541
3077
|
}
|
|
3542
3078
|
/** @private */
|
|
3079
|
+
/** @internal */
|
|
3543
3080
|
_renderBase() {
|
|
3544
3081
|
const p = this._p;
|
|
3545
3082
|
if (!p.inputBackBuffer) p.inputBackBuffer = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { css: {
|
|
@@ -3628,6 +3165,7 @@
|
|
|
3628
3165
|
}
|
|
3629
3166
|
/**
|
|
3630
3167
|
* @private
|
|
3168
|
+
* @internal
|
|
3631
3169
|
*/
|
|
3632
3170
|
_syncBaseClasses() {
|
|
3633
3171
|
const p = this._p, el = p.el;
|
|
@@ -3648,6 +3186,7 @@
|
|
|
3648
3186
|
el.className = classes.join(" ");
|
|
3649
3187
|
}
|
|
3650
3188
|
/** @private */
|
|
3189
|
+
/** @internal */
|
|
3651
3190
|
_setupDropdownMenu() {
|
|
3652
3191
|
const p = this._p;
|
|
3653
3192
|
p.valueProp;
|
|
@@ -3677,6 +3216,7 @@
|
|
|
3677
3216
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3678
3217
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3679
3218
|
filterFn: p.actualFilterFn,
|
|
3219
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3680
3220
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3681
3221
|
on: (name, event) => {
|
|
3682
3222
|
switch (name) {
|
|
@@ -3803,15 +3343,14 @@
|
|
|
3803
3343
|
case "search":
|
|
3804
3344
|
this._trigger("search", event);
|
|
3805
3345
|
break;
|
|
3806
|
-
case "itemschanged":
|
|
3807
|
-
this._trigger("itemschanged", event);
|
|
3808
|
-
break;
|
|
3346
|
+
case "itemschanged": this._trigger("itemschanged", event);
|
|
3809
3347
|
}
|
|
3810
3348
|
}
|
|
3811
3349
|
});
|
|
3812
3350
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3813
3351
|
this._registerDropdownEvents();
|
|
3814
3352
|
}
|
|
3353
|
+
/** @internal */
|
|
3815
3354
|
_handleOnBlur() {
|
|
3816
3355
|
const p = this._p;
|
|
3817
3356
|
setTimeout(() => {
|
|
@@ -3823,9 +3362,11 @@
|
|
|
3823
3362
|
this.closeList();
|
|
3824
3363
|
});
|
|
3825
3364
|
}
|
|
3365
|
+
/** @internal */
|
|
3826
3366
|
_unregisterDropdownEvents() {
|
|
3827
3367
|
this._p.sink.remove(null, ".dropdown");
|
|
3828
3368
|
}
|
|
3369
|
+
/** @internal */
|
|
3829
3370
|
_registerDropdownEvents() {
|
|
3830
3371
|
const p = this._p;
|
|
3831
3372
|
this._unregisterDropdownEvents();
|
|
@@ -3870,9 +3411,7 @@
|
|
|
3870
3411
|
case keycode_js.VALUE_HOME:
|
|
3871
3412
|
dropList.goToFirst(evt);
|
|
3872
3413
|
break;
|
|
3873
|
-
case keycode_js.VALUE_END:
|
|
3874
|
-
dropList.goToLast(evt);
|
|
3875
|
-
break;
|
|
3414
|
+
case keycode_js.VALUE_END: dropList.goToLast(evt);
|
|
3876
3415
|
}
|
|
3877
3416
|
break;
|
|
3878
3417
|
case keycode_js.VALUE_SPACE:
|
|
@@ -3902,17 +3441,15 @@
|
|
|
3902
3441
|
evt.preventDefault();
|
|
3903
3442
|
}
|
|
3904
3443
|
break;
|
|
3905
|
-
default:
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
}
|
|
3915
|
-
break;
|
|
3444
|
+
default: if (dropList.isVisible()) dropList._keydownFreeType(evt, false);
|
|
3445
|
+
else if (p.allowTypeToSelect) dropList._keydownFreeType(evt, true);
|
|
3446
|
+
else {
|
|
3447
|
+
this.openList();
|
|
3448
|
+
setTimeout(() => {
|
|
3449
|
+
if (this[DestroyedSymbol]) return;
|
|
3450
|
+
dropList._keydownFreeType(evt, false);
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3916
3453
|
}
|
|
3917
3454
|
if (!suppressEnterSpaceToggle) {
|
|
3918
3455
|
if (evt.key === keycode_js.VALUE_ENTER || evt.key === keycode_js.VALUE_SPACE && p.lastKeyAllowsNonTypeKeys && !p.multi && !dropList.hasFocusedItem() && !p.disabled && !p.readOnly) {
|
|
@@ -3963,6 +3500,7 @@
|
|
|
3963
3500
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3964
3501
|
});
|
|
3965
3502
|
}
|
|
3503
|
+
/** @internal */
|
|
3966
3504
|
_performSelectWithEvent(item, value) {
|
|
3967
3505
|
let cancellable = {
|
|
3968
3506
|
value,
|
|
@@ -3979,6 +3517,7 @@
|
|
|
3979
3517
|
});
|
|
3980
3518
|
return true;
|
|
3981
3519
|
}
|
|
3520
|
+
/** @internal */
|
|
3982
3521
|
_performClearWithEvent(clearInput = false) {
|
|
3983
3522
|
let cancellable = { cancel: false };
|
|
3984
3523
|
this._trigger("clear:before", cancellable);
|
|
@@ -3989,6 +3528,7 @@
|
|
|
3989
3528
|
this._trigger("clear");
|
|
3990
3529
|
return true;
|
|
3991
3530
|
}
|
|
3531
|
+
/** @internal */
|
|
3992
3532
|
_movePrev() {
|
|
3993
3533
|
const p = this._p;
|
|
3994
3534
|
if (this.isMultiEnabled()) return;
|
|
@@ -4002,6 +3542,7 @@
|
|
|
4002
3542
|
else this._performClearWithEvent();
|
|
4003
3543
|
}
|
|
4004
3544
|
}
|
|
3545
|
+
/** @internal */
|
|
4005
3546
|
_moveNext() {
|
|
4006
3547
|
const p = this._p;
|
|
4007
3548
|
if (this.isMultiEnabled()) return;
|
|
@@ -4016,6 +3557,7 @@
|
|
|
4016
3557
|
}
|
|
4017
3558
|
}
|
|
4018
3559
|
/** @private */
|
|
3560
|
+
/** @internal */
|
|
4019
3561
|
_updateListItems() {
|
|
4020
3562
|
const p = this._p;
|
|
4021
3563
|
const dropList = p.dropList;
|
|
@@ -4045,6 +3587,7 @@
|
|
|
4045
3587
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
4046
3588
|
}
|
|
4047
3589
|
/** @private */
|
|
3590
|
+
/** @internal */
|
|
4048
3591
|
_setSelectedItems(items) {
|
|
4049
3592
|
const p = this._p, valueProp = p.valueProp;
|
|
4050
3593
|
if (p.multi) {
|
|
@@ -4060,6 +3603,7 @@
|
|
|
4060
3603
|
this._scheduleSync("full");
|
|
4061
3604
|
}
|
|
4062
3605
|
/** @private */
|
|
3606
|
+
/** @internal */
|
|
4063
3607
|
_scheduleSync(mode, data) {
|
|
4064
3608
|
const p = this._p;
|
|
4065
3609
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4077,6 +3621,7 @@
|
|
|
4077
3621
|
});
|
|
4078
3622
|
}
|
|
4079
3623
|
/** @private */
|
|
3624
|
+
/** @internal */
|
|
4080
3625
|
_performSync(queue) {
|
|
4081
3626
|
const p = this._p;
|
|
4082
3627
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4124,26 +3669,29 @@
|
|
|
4124
3669
|
if (!p.showSelection) this._syncPlaceholder();
|
|
4125
3670
|
else if (p.multiItemEls[p.multiItemEls.length - 1]?.[ItemSymbol]?.[p.valueProp] === RestMultiItemsSymbol) this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4126
3671
|
break;
|
|
4127
|
-
case "resize_input":
|
|
4128
|
-
this._resizeInput();
|
|
4129
|
-
break;
|
|
3672
|
+
case "resize_input": this._resizeInput();
|
|
4130
3673
|
}
|
|
4131
3674
|
}
|
|
4132
3675
|
/** @private */
|
|
3676
|
+
/** @internal */
|
|
4133
3677
|
_cleanupSingleWrapper() {
|
|
4134
3678
|
const p = this._p;
|
|
4135
3679
|
if (!p.singleWrapper) return;
|
|
4136
3680
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4137
3681
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4138
3682
|
} catch (err) {
|
|
4139
|
-
|
|
3683
|
+
reportError(p.onError, err, {
|
|
3684
|
+
source: "unrenderSingleItem",
|
|
3685
|
+
item: p.singleWrapper[ItemSymbol],
|
|
3686
|
+
el: p.singleWrapper
|
|
3687
|
+
});
|
|
4140
3688
|
}
|
|
4141
3689
|
delete p.singleWrapper[ItemSymbol];
|
|
4142
3690
|
p.singleWrapper.innerHTML = "";
|
|
4143
3691
|
}
|
|
4144
3692
|
/**
|
|
4145
|
-
* @param {number} index
|
|
4146
3693
|
* @private
|
|
3694
|
+
* @internal
|
|
4147
3695
|
*/
|
|
4148
3696
|
_removeMultiItemElementByIndex(index) {
|
|
4149
3697
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4154,7 +3702,11 @@
|
|
|
4154
3702
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4155
3703
|
unrender(item, itemEl);
|
|
4156
3704
|
} catch (err) {
|
|
4157
|
-
|
|
3705
|
+
reportError(p.onError, err, {
|
|
3706
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
3707
|
+
item,
|
|
3708
|
+
el: itemEl
|
|
3709
|
+
});
|
|
4158
3710
|
}
|
|
4159
3711
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(itemEl);
|
|
4160
3712
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4162,8 +3714,8 @@
|
|
|
4162
3714
|
}
|
|
4163
3715
|
}
|
|
4164
3716
|
/**
|
|
4165
|
-
* @param {DropList.ItemBase} item
|
|
4166
3717
|
* @private
|
|
3718
|
+
* @internal
|
|
4167
3719
|
*/
|
|
4168
3720
|
_renderSingleItemContent(item) {
|
|
4169
3721
|
const p = this._p;
|
|
@@ -4175,9 +3727,8 @@
|
|
|
4175
3727
|
}
|
|
4176
3728
|
}
|
|
4177
3729
|
/**
|
|
4178
|
-
* @param {DropList.ItemBase} item
|
|
4179
|
-
* @param {Element} itemEl
|
|
4180
3730
|
* @private
|
|
3731
|
+
* @internal
|
|
4181
3732
|
*/
|
|
4182
3733
|
_renderMultiItemContent(item, itemEl) {
|
|
4183
3734
|
const p = this._p;
|
|
@@ -4189,9 +3740,9 @@
|
|
|
4189
3740
|
}
|
|
4190
3741
|
}
|
|
4191
3742
|
/**
|
|
4192
|
-
* @param {DropList.ItemBase} item
|
|
4193
3743
|
* @returns {boolean} true if rendered, false if not
|
|
4194
3744
|
* @private
|
|
3745
|
+
* @internal
|
|
4195
3746
|
*/
|
|
4196
3747
|
_addMultiItemElement(item) {
|
|
4197
3748
|
const p = this._p;
|
|
@@ -4202,6 +3753,7 @@
|
|
|
4202
3753
|
return true;
|
|
4203
3754
|
}
|
|
4204
3755
|
/** @private */
|
|
3756
|
+
/** @internal */
|
|
4205
3757
|
_addMultiItemRestElement() {
|
|
4206
3758
|
const p = this._p;
|
|
4207
3759
|
let items = p.selectedItems.slice(0);
|
|
@@ -4214,6 +3766,7 @@
|
|
|
4214
3766
|
});
|
|
4215
3767
|
}
|
|
4216
3768
|
/** @private */
|
|
3769
|
+
/** @internal */
|
|
4217
3770
|
_syncClearButton() {
|
|
4218
3771
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4219
3772
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4236,6 +3789,7 @@
|
|
|
4236
3789
|
}
|
|
4237
3790
|
}
|
|
4238
3791
|
/** @private */
|
|
3792
|
+
/** @internal */
|
|
4239
3793
|
_syncPlaceholder() {
|
|
4240
3794
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4241
3795
|
let placeholder = "";
|
|
@@ -4247,6 +3801,7 @@
|
|
|
4247
3801
|
else p.input.removeAttribute("title");
|
|
4248
3802
|
}
|
|
4249
3803
|
/** @private */
|
|
3804
|
+
/** @internal */
|
|
4250
3805
|
_syncSingleItem() {
|
|
4251
3806
|
const p = this._p;
|
|
4252
3807
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4258,9 +3813,7 @@
|
|
|
4258
3813
|
}
|
|
4259
3814
|
/**
|
|
4260
3815
|
* Syncs render state, selected items, and position
|
|
4261
|
-
* @
|
|
4262
|
-
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4263
|
-
* @returns {SelectBox}
|
|
3816
|
+
* @internal
|
|
4264
3817
|
*/
|
|
4265
3818
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4266
3819
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4318,9 +3871,8 @@
|
|
|
4318
3871
|
return this;
|
|
4319
3872
|
}
|
|
4320
3873
|
/**
|
|
4321
|
-
* @param {string} event
|
|
4322
|
-
* @param {*} [data]
|
|
4323
3874
|
* @private
|
|
3875
|
+
* @internal
|
|
4324
3876
|
*/
|
|
4325
3877
|
_trigger(event, data) {
|
|
4326
3878
|
const p = this._p;
|
|
@@ -4330,9 +3882,8 @@
|
|
|
4330
3882
|
}
|
|
4331
3883
|
/**
|
|
4332
3884
|
* Render a multi item
|
|
4333
|
-
* @param {Object} item
|
|
4334
|
-
* @returns {Element|null}
|
|
4335
3885
|
* @private
|
|
3886
|
+
* @internal
|
|
4336
3887
|
*/
|
|
4337
3888
|
_renderMultiItem(item) {
|
|
4338
3889
|
const p = this._p;
|
|
@@ -4356,10 +3907,8 @@
|
|
|
4356
3907
|
}
|
|
4357
3908
|
/**
|
|
4358
3909
|
* Removes a specific multi item by user event
|
|
4359
|
-
* @param {Element} itemEl
|
|
4360
|
-
* @param {Event} originatingEvent
|
|
4361
|
-
* @returns {SelectBox}
|
|
4362
3910
|
* @private
|
|
3911
|
+
* @internal
|
|
4363
3912
|
*/
|
|
4364
3913
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4365
3914
|
const p = this._p;
|
|
@@ -4375,7 +3924,7 @@
|
|
|
4375
3924
|
let itemsToRemove = [];
|
|
4376
3925
|
for (let item of items) {
|
|
4377
3926
|
let removeselEvt = {
|
|
4378
|
-
value,
|
|
3927
|
+
value: item[p.valueProp],
|
|
4379
3928
|
item,
|
|
4380
3929
|
cancel: false
|
|
4381
3930
|
};
|
|
@@ -4386,7 +3935,7 @@
|
|
|
4386
3935
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4387
3936
|
for (let item of itemsToRemove) {
|
|
4388
3937
|
let idx = p.selectedItems.indexOf(item);
|
|
4389
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
3938
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4390
3939
|
if (idx !== -1) {
|
|
4391
3940
|
p.selectedItems.splice(idx, 1);
|
|
4392
3941
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4417,9 +3966,8 @@
|
|
|
4417
3966
|
return this;
|
|
4418
3967
|
}
|
|
4419
3968
|
/**
|
|
4420
|
-
* @param {DropList.ItemBase} item
|
|
4421
|
-
* @param {boolean} [populate]
|
|
4422
3969
|
* @private
|
|
3970
|
+
* @internal
|
|
4423
3971
|
*/
|
|
4424
3972
|
_removeMultiItem(item, populate = false) {
|
|
4425
3973
|
const p = this._p;
|
|
@@ -4444,8 +3992,8 @@
|
|
|
4444
3992
|
this._scheduleSync("render_list");
|
|
4445
3993
|
}
|
|
4446
3994
|
/**
|
|
4447
|
-
* @param {*} value
|
|
4448
3995
|
* @private
|
|
3996
|
+
* @internal
|
|
4449
3997
|
*/
|
|
4450
3998
|
_setInputText(value) {
|
|
4451
3999
|
const p = this._p;
|
|
@@ -4456,8 +4004,8 @@
|
|
|
4456
4004
|
}
|
|
4457
4005
|
/**
|
|
4458
4006
|
* Update input size to current state
|
|
4459
|
-
* @returns {SelectBox}
|
|
4460
4007
|
* @private
|
|
4008
|
+
* @internal
|
|
4461
4009
|
*/
|
|
4462
4010
|
_resizeInput() {
|
|
4463
4011
|
const p = this._p, el = p.el;
|
|
@@ -4513,8 +4061,8 @@
|
|
|
4513
4061
|
}
|
|
4514
4062
|
/**
|
|
4515
4063
|
* Update autocomplete position if needed
|
|
4516
|
-
* @returns {SelectBox}
|
|
4517
4064
|
* @private
|
|
4065
|
+
* @internal
|
|
4518
4066
|
*/
|
|
4519
4067
|
_repositionDropList() {
|
|
4520
4068
|
const p = this._p, el = p.el;
|
|
@@ -4528,8 +4076,8 @@
|
|
|
4528
4076
|
return this;
|
|
4529
4077
|
}
|
|
4530
4078
|
/**
|
|
4531
|
-
* @param {KeyboardEvent} event
|
|
4532
4079
|
* @private
|
|
4080
|
+
* @internal
|
|
4533
4081
|
*/
|
|
4534
4082
|
_handleInputKeydown(event) {
|
|
4535
4083
|
const p = this._p;
|
|
@@ -4558,8 +4106,8 @@
|
|
|
4558
4106
|
}
|
|
4559
4107
|
}
|
|
4560
4108
|
/**
|
|
4561
|
-
* @param {KeyboardEvent} event
|
|
4562
4109
|
* @private
|
|
4110
|
+
* @internal
|
|
4563
4111
|
*/
|
|
4564
4112
|
_handleMultiKeydown(event) {
|
|
4565
4113
|
const p = this._p;
|
|
@@ -4603,12 +4151,12 @@
|
|
|
4603
4151
|
}
|
|
4604
4152
|
}
|
|
4605
4153
|
/**
|
|
4606
|
-
* @returns {DropList.PositionOptions}
|
|
4607
4154
|
* @private
|
|
4155
|
+
* @internal
|
|
4608
4156
|
*/
|
|
4609
4157
|
_getDropListPositionOptions() {
|
|
4610
4158
|
return {
|
|
4611
|
-
target: this._p.el,
|
|
4159
|
+
target: /**@type Element*/ this._p.el,
|
|
4612
4160
|
offset: {
|
|
4613
4161
|
x: 0,
|
|
4614
4162
|
y: 0
|
|
@@ -4625,6 +4173,7 @@
|
|
|
4625
4173
|
};
|
|
4626
4174
|
}
|
|
4627
4175
|
/** @private */
|
|
4176
|
+
/** @internal */
|
|
4628
4177
|
_startTrackingPresence() {
|
|
4629
4178
|
const p = this._p;
|
|
4630
4179
|
this._stopTrackingPresence();
|
|
@@ -4633,6 +4182,7 @@
|
|
|
4633
4182
|
}, 200);
|
|
4634
4183
|
}
|
|
4635
4184
|
/** @private */
|
|
4185
|
+
/** @internal */
|
|
4636
4186
|
_stopTrackingPresence() {
|
|
4637
4187
|
const p = this._p;
|
|
4638
4188
|
if (p.presenceInt) {
|
|
@@ -4643,11 +4193,7 @@
|
|
|
4643
4193
|
/**
|
|
4644
4194
|
* Handles sorting, and putting checked items first (according to selectedValues, not item.checked)
|
|
4645
4195
|
* @private
|
|
4646
|
-
* @
|
|
4647
|
-
* @param {boolean=false} sort
|
|
4648
|
-
* @param {boolean=false} sortCheckedFirst
|
|
4649
|
-
* @param {boolean=false} splitCheckedGroups
|
|
4650
|
-
* @returns {DropList.ItemBase[]}
|
|
4196
|
+
* @internal
|
|
4651
4197
|
*/
|
|
4652
4198
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4653
4199
|
const p = this._p;
|