@danielgindi/selectbox 2.0.57 → 2.0.58
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 +190 -160
- 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 +190 -160
- 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 +190 -160
- 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 +343 -0
- package/dist/types/DropList.d.ts.map +1 -0
- package/dist/types/SelectBox.d.ts +497 -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 +207 -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 +9 -4
- package/tsconfig.json +35 -0
- package/vue/DropList.vue +495 -565
- package/vue/DropList.vue.d.ts +4 -0
- package/vue/SelectBox.vue +855 -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 +89 -96
- package/lib/utils/escapeRegex.js +0 -1
- package/lib/utils/throttle.js +0 -48
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 2.0.
|
|
2
|
+
* @danielgindi/selectbox 2.0.58
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { closestUntil, createElement, next, prev, setElementAttrs } from "@danielgindi/dom-utils/lib/Dom";
|
|
@@ -9,14 +9,18 @@ import DomEventsSink from "@danielgindi/dom-utils/lib/DomEventsSink";
|
|
|
9
9
|
import VirtualListHelper from "@danielgindi/virtual-list-helper";
|
|
10
10
|
import { VALUE_BACK_SPACE, VALUE_DELETE, VALUE_DOWN, VALUE_END, VALUE_ENTER, VALUE_ESCAPE, VALUE_HOME, VALUE_LEFT, VALUE_PAGE_DOWN, VALUE_PAGE_UP, VALUE_RIGHT, VALUE_SPACE, VALUE_TAB, VALUE_UP } from "keycode-js";
|
|
11
11
|
import mitt from "mitt";
|
|
12
|
-
//#region lib/utils/escapeRegex.
|
|
13
|
-
|
|
12
|
+
//#region src/lib/utils/escapeRegex.ts
|
|
13
|
+
/** @internal */
|
|
14
|
+
var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
14
15
|
//#endregion
|
|
15
|
-
//#region lib/utils/throttle.
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
//#region src/lib/utils/throttle.ts
|
|
17
|
+
/** @internal */
|
|
18
|
+
var throttle = (func, wait, options = {}) => {
|
|
19
|
+
let timeout;
|
|
20
|
+
let context;
|
|
21
|
+
let args;
|
|
22
|
+
let result;
|
|
18
23
|
let previous = 0;
|
|
19
|
-
if (!options) options = {};
|
|
20
24
|
const later = () => {
|
|
21
25
|
previous = options.leading === false ? 0 : Date.now();
|
|
22
26
|
timeout = null;
|
|
@@ -51,86 +55,30 @@ var throttle = (func, wait, options) => {
|
|
|
51
55
|
return throttled;
|
|
52
56
|
};
|
|
53
57
|
//#endregion
|
|
54
|
-
//#region lib/
|
|
58
|
+
//#region src/lib/utils/reportError.ts
|
|
59
|
+
/**
|
|
60
|
+
* Routes an error/warning to `handler` if supplied, falling back to the
|
|
61
|
+
* console (matching the previous hardcoded behaviour) if there is no
|
|
62
|
+
* handler, or if the handler itself throws.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
var reportError = (handler, error, context) => {
|
|
66
|
+
if (handler) try {
|
|
67
|
+
handler(error, context);
|
|
68
|
+
return;
|
|
69
|
+
} catch (handlerError) {
|
|
70
|
+
console.error(handlerError);
|
|
71
|
+
}
|
|
72
|
+
if (context.level === "warn") console.warn(error);
|
|
73
|
+
else console.error(error);
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/lib/DropList.ts
|
|
55
77
|
var ItemSymbol = Symbol("item");
|
|
56
78
|
var DestroyedSymbol$1 = Symbol("destroyed");
|
|
57
79
|
var GhostSymbol = Symbol("ghost");
|
|
58
80
|
var NoResultsItemSymbol = Symbol("no_results_items");
|
|
59
81
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
60
|
-
/**
|
|
61
|
-
* @typedef {Object} DropList.Options
|
|
62
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
63
|
-
* @property {string} [baseClassName='droplist'] class name for the menu root element
|
|
64
|
-
* @property {string|string[]} [additionalClasses]
|
|
65
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
66
|
-
* @property {boolean} [autoItemBlur=true] Should we automatically blur the focused item when the droplist loses focus?
|
|
67
|
-
* @property {number} [autoItemBlurDelay=300] How long to wait before deciding to blur the focused item (when the droplist loses focus)?
|
|
68
|
-
* @property {boolean} [capturesFocus=true] Should this DropList be added to the TAB-key stack?
|
|
69
|
-
* @property {boolean} [multi=false] Does this DropList show checkboxes for multiple item selection?
|
|
70
|
-
* @property {*} [singleSelectedValue] Current selected value when using single selection.
|
|
71
|
-
* @property {function} [keyDownHandler=null] An alternative "keydown" event handler. Return true to prevent default behaviour.
|
|
72
|
-
* @property {boolean} [autoCheckGroupChildren=true] When a group is checked/unchecked - all items beneath it will update accordingly
|
|
73
|
-
* @property {boolean} [useExactTargetWidth=false] Use the exact target's width, do not allow growing
|
|
74
|
-
* @property {boolean} [constrainToWindow=true] Should the position be constrained to the window, attaching to window's borders if needed?
|
|
75
|
-
* @property {Boolean} [autoFlipDirection=true] Should the position/anchor be flipped automatically when there's no space in the required direction?
|
|
76
|
-
* @property {number} [estimatedItemHeight=20] An estimated row height, for approximating scroll height.
|
|
77
|
-
* @property {boolean} [estimateWidth=false] Use an estimation for the width instead of measuring. May be faster - needs testing and may depend on the CSS.
|
|
78
|
-
* @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.
|
|
79
|
-
* @property {string} [labelProp='label']
|
|
80
|
-
* @property {string} [valueProp='value']
|
|
81
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderItem] Function to call when rendering an item element
|
|
82
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderItem] Function to call when rendering an item element
|
|
83
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
84
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
85
|
-
* @property {function(name: string, data: *)} [on]
|
|
86
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
87
|
-
* @property {boolean} [isFooterVisible=false] show footer element
|
|
88
|
-
* @property {boolean} [searchable=false] include inline search box
|
|
89
|
-
* @property {string} [searchPlaceholder=''] placeholder text for the inline search box
|
|
90
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
91
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
92
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
93
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
94
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
95
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
96
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
97
|
-
* */
|
|
98
|
-
/** */
|
|
99
|
-
/**
|
|
100
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
101
|
-
* @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`)
|
|
102
|
-
* @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`)
|
|
103
|
-
* */
|
|
104
|
-
/** */
|
|
105
|
-
/**
|
|
106
|
-
* @typedef {Object} DropList.PositionOptions
|
|
107
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
108
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
109
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
110
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
111
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
112
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
113
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
114
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
115
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
116
|
-
* */
|
|
117
|
-
/** */
|
|
118
|
-
/**
|
|
119
|
-
* @typedef {Object} DropList.ItemBase
|
|
120
|
-
* @property {string} [value]
|
|
121
|
-
* @property {string} [label]
|
|
122
|
-
* @property {boolean} [_group=false]
|
|
123
|
-
* @property {boolean} [_child=false]
|
|
124
|
-
* @property {boolean} [_nocheck=false]
|
|
125
|
-
* @property {boolean} [_nointeraction=false]
|
|
126
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
127
|
-
* */
|
|
128
|
-
/**
|
|
129
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
130
|
-
* @property {boolean} [_checked=false]
|
|
131
|
-
* */
|
|
132
|
-
/** */
|
|
133
|
-
/** @type {DropList.Options} */
|
|
134
82
|
var DefaultOptions = {
|
|
135
83
|
baseClassName: "droplist",
|
|
136
84
|
autoItemBlur: true,
|
|
@@ -195,6 +143,7 @@ var DropList = class DropList {
|
|
|
195
143
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
196
144
|
on: o.on || null,
|
|
197
145
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
146
|
+
onError: o.onError,
|
|
198
147
|
searchable: o.searchable,
|
|
199
148
|
searchPlaceholder: o.searchPlaceholder,
|
|
200
149
|
isHeaderVisible: o.isHeaderVisible,
|
|
@@ -212,7 +161,14 @@ var DropList = class DropList {
|
|
|
212
161
|
throttledRefilterItems: null,
|
|
213
162
|
focusItemIndex: -1,
|
|
214
163
|
focusItemEl: null,
|
|
215
|
-
sink: new DomEventsSink()
|
|
164
|
+
sink: new DomEventsSink(),
|
|
165
|
+
visible: false,
|
|
166
|
+
hiding: false,
|
|
167
|
+
singleSelectedItemEl: null,
|
|
168
|
+
onDocumentMouseDown: null,
|
|
169
|
+
lastKeyWasChar: false,
|
|
170
|
+
currentSubDropList: null,
|
|
171
|
+
_isFocusingItem: false
|
|
216
172
|
};
|
|
217
173
|
let classes = [p.baseClassName + "_wrapper"];
|
|
218
174
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -278,7 +234,11 @@ var DropList = class DropList {
|
|
|
278
234
|
};
|
|
279
235
|
else item = items[index];
|
|
280
236
|
}
|
|
281
|
-
if (!item)
|
|
237
|
+
if (!item) reportError(p.onError, `onItemRender called for (${index}) which has no item`, {
|
|
238
|
+
source: "renderItem",
|
|
239
|
+
level: "warn",
|
|
240
|
+
index
|
|
241
|
+
});
|
|
282
242
|
itemEl.className = `${p.baseClassName}__item`;
|
|
283
243
|
const classList = itemEl.classList;
|
|
284
244
|
if (item) {
|
|
@@ -436,6 +396,7 @@ var DropList = class DropList {
|
|
|
436
396
|
}
|
|
437
397
|
/**
|
|
438
398
|
* @private
|
|
399
|
+
* @internal
|
|
439
400
|
*/
|
|
440
401
|
_setupUnrenderFunction() {
|
|
441
402
|
const p = this._p;
|
|
@@ -447,12 +408,20 @@ var DropList = class DropList {
|
|
|
447
408
|
if (item === NoResultsItemSymbol) try {
|
|
448
409
|
fnNoResults(item, el);
|
|
449
410
|
} catch (err) {
|
|
450
|
-
|
|
411
|
+
reportError(p.onError, err, {
|
|
412
|
+
source: "unrenderNoResultsItem",
|
|
413
|
+
item,
|
|
414
|
+
el
|
|
415
|
+
});
|
|
451
416
|
}
|
|
452
417
|
else try {
|
|
453
418
|
fn(item[ItemSymbol], el);
|
|
454
419
|
} catch (err) {
|
|
455
|
-
|
|
420
|
+
reportError(p.onError, err, {
|
|
421
|
+
source: "unrenderItem",
|
|
422
|
+
item: item[ItemSymbol],
|
|
423
|
+
el
|
|
424
|
+
});
|
|
456
425
|
}
|
|
457
426
|
delete el[ItemSymbol];
|
|
458
427
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -472,6 +441,7 @@ var DropList = class DropList {
|
|
|
472
441
|
p.valueProp = prop;
|
|
473
442
|
return this;
|
|
474
443
|
}
|
|
444
|
+
/** @internal */
|
|
475
445
|
_syncBaseClasses() {
|
|
476
446
|
const p = this._p, el = p.el;
|
|
477
447
|
if (!el) return;
|
|
@@ -510,7 +480,7 @@ var DropList = class DropList {
|
|
|
510
480
|
goToLast(event) {
|
|
511
481
|
this._move("last", event);
|
|
512
482
|
}
|
|
513
|
-
toggleFocusedItem() {
|
|
483
|
+
toggleFocusedItem(event) {
|
|
514
484
|
const p = this._p;
|
|
515
485
|
if (this.hasFocusedItem() && p.multi) {
|
|
516
486
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -631,7 +601,7 @@ var DropList = class DropList {
|
|
|
631
601
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
632
602
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
633
603
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
634
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
604
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
635
605
|
if (p.multi) {
|
|
636
606
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
637
607
|
}
|
|
@@ -639,10 +609,10 @@ var DropList = class DropList {
|
|
|
639
609
|
if (!!newItem._group !== item._group) {
|
|
640
610
|
if (item._group) p.groupCount--;
|
|
641
611
|
else p.groupCount++;
|
|
642
|
-
|
|
612
|
+
item._group = !!newItem._group;
|
|
643
613
|
}
|
|
644
614
|
}
|
|
645
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
615
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
646
616
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
647
617
|
let virtualItemIndex = itemIndex;
|
|
648
618
|
if (p.filteredItems) {
|
|
@@ -789,6 +759,23 @@ var DropList = class DropList {
|
|
|
789
759
|
return this._p.positionOptionsProvider;
|
|
790
760
|
}
|
|
791
761
|
/**
|
|
762
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
763
|
+
* instead of the default `console.error`/`console.warn`.
|
|
764
|
+
* @param {DropList.LibraryErrorHandler|null} [fn]
|
|
765
|
+
* @returns {DropList}
|
|
766
|
+
*/
|
|
767
|
+
setOnError(fn) {
|
|
768
|
+
const p = this._p;
|
|
769
|
+
p.onError = fn ?? void 0;
|
|
770
|
+
return this;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* @returns {DropList.LibraryErrorHandler|undefined}
|
|
774
|
+
*/
|
|
775
|
+
getOnError() {
|
|
776
|
+
return this._p.onError;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
792
779
|
* @param {string} term
|
|
793
780
|
* @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
|
|
794
781
|
* @returns {DropList}
|
|
@@ -809,6 +796,7 @@ var DropList = class DropList {
|
|
|
809
796
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
810
797
|
}
|
|
811
798
|
/** @private */
|
|
799
|
+
/** @internal */
|
|
812
800
|
_refilterItems() {
|
|
813
801
|
const p = this._p;
|
|
814
802
|
const term = p.filterTerm;
|
|
@@ -843,7 +831,7 @@ var DropList = class DropList {
|
|
|
843
831
|
});
|
|
844
832
|
}
|
|
845
833
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
846
|
-
const matcher = new RegExp(
|
|
834
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
847
835
|
filteredItems = p.items.filter((x) => {
|
|
848
836
|
if (!filterGroups && x._group) return true;
|
|
849
837
|
return matcher.test(x.label);
|
|
@@ -920,7 +908,7 @@ var DropList = class DropList {
|
|
|
920
908
|
p.filterThrottleWindow = window;
|
|
921
909
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
922
910
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
923
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
911
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
924
912
|
if (isScheduled) p.throttledRefilterItems();
|
|
925
913
|
return this;
|
|
926
914
|
}
|
|
@@ -1263,7 +1251,7 @@ var DropList = class DropList {
|
|
|
1263
1251
|
if (this.isVisible()) this._trigger("show");
|
|
1264
1252
|
return this;
|
|
1265
1253
|
}
|
|
1266
|
-
hide() {
|
|
1254
|
+
hide(event) {
|
|
1267
1255
|
const p = this._p, el = p.el;
|
|
1268
1256
|
if (p.onDocumentMouseDown) {
|
|
1269
1257
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1435,6 +1423,7 @@ var DropList = class DropList {
|
|
|
1435
1423
|
}
|
|
1436
1424
|
return this;
|
|
1437
1425
|
}
|
|
1426
|
+
/** @internal */
|
|
1438
1427
|
_showSublist(item, itemElement) {
|
|
1439
1428
|
if (!item._subitems?.length) return;
|
|
1440
1429
|
const p = this._p;
|
|
@@ -1510,6 +1499,7 @@ var DropList = class DropList {
|
|
|
1510
1499
|
droplist.show();
|
|
1511
1500
|
droplist.el.focus();
|
|
1512
1501
|
}
|
|
1502
|
+
/** @internal */
|
|
1513
1503
|
_hideSublist() {
|
|
1514
1504
|
const p = this._p;
|
|
1515
1505
|
if (!p.currentSubDropList) return;
|
|
@@ -1609,6 +1599,7 @@ var DropList = class DropList {
|
|
|
1609
1599
|
}
|
|
1610
1600
|
return this;
|
|
1611
1601
|
}
|
|
1602
|
+
/** @internal */
|
|
1612
1603
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1613
1604
|
const p = this._p;
|
|
1614
1605
|
if (this._hasScroll()) {
|
|
@@ -1672,6 +1663,7 @@ var DropList = class DropList {
|
|
|
1672
1663
|
this._p.mitt.emit(event, value);
|
|
1673
1664
|
return this;
|
|
1674
1665
|
}
|
|
1666
|
+
/** @internal */
|
|
1675
1667
|
_getItemIndex(item) {
|
|
1676
1668
|
const p = this._p;
|
|
1677
1669
|
let itemIndex = -1;
|
|
@@ -1685,6 +1677,7 @@ var DropList = class DropList {
|
|
|
1685
1677
|
}
|
|
1686
1678
|
return itemIndex;
|
|
1687
1679
|
}
|
|
1680
|
+
/** @internal */
|
|
1688
1681
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1689
1682
|
const p = this._p;
|
|
1690
1683
|
if (p.singleSelectedItemEl) {
|
|
@@ -1702,12 +1695,14 @@ var DropList = class DropList {
|
|
|
1702
1695
|
* @param {string} event
|
|
1703
1696
|
* @param {*} [data]
|
|
1704
1697
|
* @private
|
|
1698
|
+
* @internal
|
|
1705
1699
|
*/
|
|
1706
1700
|
_trigger(event, data) {
|
|
1707
1701
|
const p = this._p;
|
|
1708
1702
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1709
1703
|
p.mitt.emit(event, data);
|
|
1710
1704
|
}
|
|
1705
|
+
/** @internal */
|
|
1711
1706
|
_itemUpAction(event, itemEl) {
|
|
1712
1707
|
if (closestUntil(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1713
1708
|
let p = this._p;
|
|
@@ -1720,6 +1715,7 @@ var DropList = class DropList {
|
|
|
1720
1715
|
}, 0);
|
|
1721
1716
|
}
|
|
1722
1717
|
}
|
|
1718
|
+
/** @internal */
|
|
1723
1719
|
_hookMouseEvents() {
|
|
1724
1720
|
const p = this._p;
|
|
1725
1721
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1733,9 +1729,11 @@ var DropList = class DropList {
|
|
|
1733
1729
|
this._handleMouseOver(event, li);
|
|
1734
1730
|
});
|
|
1735
1731
|
}
|
|
1732
|
+
/** @internal */
|
|
1736
1733
|
_handleMouseOver(event, itemEl) {
|
|
1737
1734
|
this._focus(event, itemEl, null, true);
|
|
1738
1735
|
}
|
|
1736
|
+
/** @internal */
|
|
1739
1737
|
_hookTouchEvents() {
|
|
1740
1738
|
const p = this._p;
|
|
1741
1739
|
let currentTouchId;
|
|
@@ -1775,6 +1773,7 @@ var DropList = class DropList {
|
|
|
1775
1773
|
});
|
|
1776
1774
|
});
|
|
1777
1775
|
}
|
|
1776
|
+
/** @internal */
|
|
1778
1777
|
_hookFocusEvents() {
|
|
1779
1778
|
const p = this._p;
|
|
1780
1779
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1792,10 +1791,12 @@ var DropList = class DropList {
|
|
|
1792
1791
|
});
|
|
1793
1792
|
}, true);
|
|
1794
1793
|
}
|
|
1794
|
+
/** @internal */
|
|
1795
1795
|
_hookKeyEvents() {
|
|
1796
1796
|
const p = this._p;
|
|
1797
1797
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1798
1798
|
}
|
|
1799
|
+
/** @internal */
|
|
1799
1800
|
_hookSearchEvents() {
|
|
1800
1801
|
const p = this._p;
|
|
1801
1802
|
if (!p.searchInput) return;
|
|
@@ -1806,6 +1807,7 @@ var DropList = class DropList {
|
|
|
1806
1807
|
p.throttledRefilterItems();
|
|
1807
1808
|
});
|
|
1808
1809
|
}
|
|
1810
|
+
/** @internal */
|
|
1809
1811
|
_keydown(event) {
|
|
1810
1812
|
const p = this._p;
|
|
1811
1813
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1868,6 +1870,7 @@ var DropList = class DropList {
|
|
|
1868
1870
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1869
1871
|
}
|
|
1870
1872
|
}
|
|
1873
|
+
/** @internal */
|
|
1871
1874
|
_keydownFreeType(evt, autoSelect) {
|
|
1872
1875
|
const p = this._p;
|
|
1873
1876
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1876,7 +1879,7 @@ var DropList = class DropList {
|
|
|
1876
1879
|
if (!isChar) return;
|
|
1877
1880
|
clearTimeout(p.filterTimer);
|
|
1878
1881
|
let keyword = (p.previousFilter || "") + character;
|
|
1879
|
-
let regex = new RegExp(`^${
|
|
1882
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1880
1883
|
let matchIndex = -1;
|
|
1881
1884
|
let item;
|
|
1882
1885
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1891,7 +1894,7 @@ var DropList = class DropList {
|
|
|
1891
1894
|
}
|
|
1892
1895
|
if (matchIndex === -1) {
|
|
1893
1896
|
keyword = character;
|
|
1894
|
-
regex = new RegExp(`^${
|
|
1897
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1895
1898
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1896
1899
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1897
1900
|
item = items[i];
|
|
@@ -1911,6 +1914,7 @@ var DropList = class DropList {
|
|
|
1911
1914
|
}, 1e3);
|
|
1912
1915
|
} else delete p.previousFilter;
|
|
1913
1916
|
}
|
|
1917
|
+
/** @internal */
|
|
1914
1918
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1915
1919
|
const p = this._p;
|
|
1916
1920
|
if (p._isFocusingItem) return;
|
|
@@ -1944,6 +1948,7 @@ var DropList = class DropList {
|
|
|
1944
1948
|
p._isFocusingItem = false;
|
|
1945
1949
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1946
1950
|
}
|
|
1951
|
+
/** @internal */
|
|
1947
1952
|
_delayBlurItemOnBlur() {
|
|
1948
1953
|
if (this[DestroyedSymbol$1]) return;
|
|
1949
1954
|
const p = this._p;
|
|
@@ -1954,6 +1959,7 @@ var DropList = class DropList {
|
|
|
1954
1959
|
this.blurFocusedItem();
|
|
1955
1960
|
}, p.autoItemBlurDelay);
|
|
1956
1961
|
}
|
|
1962
|
+
/** @internal */
|
|
1957
1963
|
_move(direction, event) {
|
|
1958
1964
|
const p = this._p;
|
|
1959
1965
|
let next, nextIndex, directionUp;
|
|
@@ -2023,10 +2029,12 @@ var DropList = class DropList {
|
|
|
2023
2029
|
this._focus(event, next || null, nextIndex, false);
|
|
2024
2030
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2025
2031
|
}
|
|
2032
|
+
/** @internal */
|
|
2026
2033
|
_hasScroll() {
|
|
2027
2034
|
const menuEl = this._p.menuEl;
|
|
2028
2035
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2029
2036
|
}
|
|
2037
|
+
/** @internal */
|
|
2030
2038
|
_updateGroupStateForItem(item) {
|
|
2031
2039
|
const p = this._p;
|
|
2032
2040
|
if (!p.multi) return this;
|
|
@@ -2070,6 +2078,7 @@ var DropList = class DropList {
|
|
|
2070
2078
|
}
|
|
2071
2079
|
return this;
|
|
2072
2080
|
}
|
|
2081
|
+
/** @internal */
|
|
2073
2082
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2074
2083
|
const p = this._p;
|
|
2075
2084
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2103,6 +2112,7 @@ var DropList = class DropList {
|
|
|
2103
2112
|
/**
|
|
2104
2113
|
* @private
|
|
2105
2114
|
* @returns {DropList} self
|
|
2115
|
+
* @internal
|
|
2106
2116
|
*/
|
|
2107
2117
|
_measureItem() {
|
|
2108
2118
|
const p = this._p;
|
|
@@ -2150,6 +2160,7 @@ var DropList = class DropList {
|
|
|
2150
2160
|
* @param {number?} targetItemCount - item count we are expecting. Defaults to current item count
|
|
2151
2161
|
* @returns {DropList}
|
|
2152
2162
|
* @private
|
|
2163
|
+
* @internal
|
|
2153
2164
|
*/
|
|
2154
2165
|
_determineVirtualMode(targetItemCount) {
|
|
2155
2166
|
const p = this._p;
|
|
@@ -2159,6 +2170,7 @@ var DropList = class DropList {
|
|
|
2159
2170
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2160
2171
|
return this;
|
|
2161
2172
|
}
|
|
2173
|
+
/** @internal */
|
|
2162
2174
|
_renderItemContent(item, itemEl) {
|
|
2163
2175
|
const p = this._p;
|
|
2164
2176
|
const originalItem = item[ItemSymbol];
|
|
@@ -2180,17 +2192,12 @@ var DropList = class DropList {
|
|
|
2180
2192
|
}
|
|
2181
2193
|
}
|
|
2182
2194
|
}
|
|
2183
|
-
/**
|
|
2184
|
-
*
|
|
2185
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2186
|
-
* @returns {number} new outer width
|
|
2187
|
-
* @private
|
|
2188
|
-
*/
|
|
2195
|
+
/** @internal */
|
|
2189
2196
|
_updateWidth(positionOptions) {
|
|
2190
2197
|
const p = this._p, el = p.el;
|
|
2191
2198
|
let targetWidth = 0;
|
|
2192
2199
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2193
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2200
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2194
2201
|
else targetWidth = getElementWidth(positionOptions.target, true, true);
|
|
2195
2202
|
let autoWidth = 0;
|
|
2196
2203
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2212,7 +2219,7 @@ var DropList = class DropList {
|
|
|
2212
2219
|
}
|
|
2213
2220
|
};
|
|
2214
2221
|
//#endregion
|
|
2215
|
-
//#region lib/SelectBox.
|
|
2222
|
+
//#region src/lib/SelectBox.ts
|
|
2216
2223
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2217
2224
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2218
2225
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2238,57 +2245,6 @@ var inputBackbufferCssProps = [
|
|
|
2238
2245
|
"padding-left",
|
|
2239
2246
|
"padding-right"
|
|
2240
2247
|
];
|
|
2241
|
-
/**
|
|
2242
|
-
* @typedef {Object} SelectBox.Options
|
|
2243
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2244
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2245
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2246
|
-
* @property {string|string[]} [additionalClasses]
|
|
2247
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2248
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2249
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2250
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2251
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2252
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2253
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2254
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2255
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2256
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2257
|
-
* @property {*[]} [stickyValues]
|
|
2258
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2259
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2260
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2261
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2262
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2263
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2264
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2265
|
-
* @property {string} [labelProp='label']
|
|
2266
|
-
* @property {string} [valueProp='value']
|
|
2267
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2268
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2269
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2270
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2271
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2272
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2273
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2274
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2275
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2276
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2277
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2278
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2279
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2280
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2281
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2282
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2283
|
-
* @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.
|
|
2284
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2285
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2286
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2287
|
-
* @property {function(name: string, ...args)} [on]
|
|
2288
|
-
* @property {boolean} [isLoadingMode]
|
|
2289
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2290
|
-
* @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>
|
|
2291
|
-
* */
|
|
2292
2248
|
var DefaultOptions$1 = {
|
|
2293
2249
|
el: null,
|
|
2294
2250
|
baseClassName: "selectbox",
|
|
@@ -2407,6 +2363,7 @@ var SelectBox = class {
|
|
|
2407
2363
|
on: o.on || null,
|
|
2408
2364
|
silenceEvents: true,
|
|
2409
2365
|
mitt: mitt(),
|
|
2366
|
+
onError: o.onError,
|
|
2410
2367
|
isLoadingMode: !!o.isLoadingMode,
|
|
2411
2368
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2412
2369
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2422,7 +2379,11 @@ var SelectBox = class {
|
|
|
2422
2379
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2423
2380
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2424
2381
|
filterFn: null,
|
|
2425
|
-
filterTerm: ""
|
|
2382
|
+
filterTerm: "",
|
|
2383
|
+
dropListVisible: false,
|
|
2384
|
+
lastActiveElement: null,
|
|
2385
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2386
|
+
presenceInt: null
|
|
2426
2387
|
};
|
|
2427
2388
|
let el = o.el;
|
|
2428
2389
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -3160,7 +3121,7 @@ var SelectBox = class {
|
|
|
3160
3121
|
if (p.filterFn === fn) return this;
|
|
3161
3122
|
p.filterFn = fn;
|
|
3162
3123
|
if (!fn) fn = (items, term) => {
|
|
3163
|
-
const matcher = new RegExp(
|
|
3124
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3164
3125
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3165
3126
|
return p.items.filter((x) => {
|
|
3166
3127
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3178,6 +3139,25 @@ var SelectBox = class {
|
|
|
3178
3139
|
return this._p.filterFn;
|
|
3179
3140
|
}
|
|
3180
3141
|
/**
|
|
3142
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderMultiItem`/`unrenderSingleItem`)
|
|
3143
|
+
* instead of the default `console.error`/`console.warn`. Also used as the default `onError` for the internal
|
|
3144
|
+
* `DropList`, unless `listOptions.onError` is set explicitly.
|
|
3145
|
+
* @param {SelectBox.LibraryErrorHandler|null} [fn]
|
|
3146
|
+
* @returns {SelectBox}
|
|
3147
|
+
*/
|
|
3148
|
+
setOnError(fn) {
|
|
3149
|
+
const p = this._p;
|
|
3150
|
+
p.onError = fn ?? void 0;
|
|
3151
|
+
p.dropList?.setOnError(p.listOptions?.onError ?? p.onError);
|
|
3152
|
+
return this;
|
|
3153
|
+
}
|
|
3154
|
+
/**
|
|
3155
|
+
* @returns {SelectBox.LibraryErrorHandler|undefined}
|
|
3156
|
+
*/
|
|
3157
|
+
getOnError() {
|
|
3158
|
+
return this._p.onError;
|
|
3159
|
+
}
|
|
3160
|
+
/**
|
|
3181
3161
|
* Focus on input element
|
|
3182
3162
|
* @returns {SelectBox}
|
|
3183
3163
|
*/
|
|
@@ -3466,6 +3446,7 @@ var SelectBox = class {
|
|
|
3466
3446
|
* Prepare the mapping between values and items.
|
|
3467
3447
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3468
3448
|
* @private
|
|
3449
|
+
* @internal
|
|
3469
3450
|
*/
|
|
3470
3451
|
_refreshItemByValueMap() {
|
|
3471
3452
|
const p = this._p;
|
|
@@ -3478,6 +3459,7 @@ var SelectBox = class {
|
|
|
3478
3459
|
* @param {*} value
|
|
3479
3460
|
* @returns {DropList.ItemBase|undefined}
|
|
3480
3461
|
* @private
|
|
3462
|
+
* @internal
|
|
3481
3463
|
*/
|
|
3482
3464
|
_getItemByValue(value) {
|
|
3483
3465
|
const p = this._p;
|
|
@@ -3487,6 +3469,7 @@ var SelectBox = class {
|
|
|
3487
3469
|
return p.subitemByValueMap.get(value);
|
|
3488
3470
|
}
|
|
3489
3471
|
/** @private */
|
|
3472
|
+
/** @internal */
|
|
3490
3473
|
_refreshSubitemByValueMap() {
|
|
3491
3474
|
const p = this._p;
|
|
3492
3475
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
@@ -3497,6 +3480,7 @@ var SelectBox = class {
|
|
|
3497
3480
|
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3498
3481
|
* @param {string} valueProp
|
|
3499
3482
|
* @private
|
|
3483
|
+
* @internal
|
|
3500
3484
|
*/
|
|
3501
3485
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3502
3486
|
for (let item of items) {
|
|
@@ -3506,6 +3490,7 @@ var SelectBox = class {
|
|
|
3506
3490
|
}
|
|
3507
3491
|
}
|
|
3508
3492
|
/** @private */
|
|
3493
|
+
/** @internal */
|
|
3509
3494
|
_renderBase() {
|
|
3510
3495
|
const p = this._p;
|
|
3511
3496
|
if (!p.inputBackBuffer) p.inputBackBuffer = createElement("span", { css: {
|
|
@@ -3594,6 +3579,7 @@ var SelectBox = class {
|
|
|
3594
3579
|
}
|
|
3595
3580
|
/**
|
|
3596
3581
|
* @private
|
|
3582
|
+
* @internal
|
|
3597
3583
|
*/
|
|
3598
3584
|
_syncBaseClasses() {
|
|
3599
3585
|
const p = this._p, el = p.el;
|
|
@@ -3614,6 +3600,7 @@ var SelectBox = class {
|
|
|
3614
3600
|
el.className = classes.join(" ");
|
|
3615
3601
|
}
|
|
3616
3602
|
/** @private */
|
|
3603
|
+
/** @internal */
|
|
3617
3604
|
_setupDropdownMenu() {
|
|
3618
3605
|
const p = this._p;
|
|
3619
3606
|
p.valueProp;
|
|
@@ -3643,6 +3630,7 @@ var SelectBox = class {
|
|
|
3643
3630
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3644
3631
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3645
3632
|
filterFn: p.actualFilterFn,
|
|
3633
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3646
3634
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3647
3635
|
on: (name, event) => {
|
|
3648
3636
|
switch (name) {
|
|
@@ -3778,6 +3766,7 @@ var SelectBox = class {
|
|
|
3778
3766
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3779
3767
|
this._registerDropdownEvents();
|
|
3780
3768
|
}
|
|
3769
|
+
/** @internal */
|
|
3781
3770
|
_handleOnBlur() {
|
|
3782
3771
|
const p = this._p;
|
|
3783
3772
|
setTimeout(() => {
|
|
@@ -3789,9 +3778,11 @@ var SelectBox = class {
|
|
|
3789
3778
|
this.closeList();
|
|
3790
3779
|
});
|
|
3791
3780
|
}
|
|
3781
|
+
/** @internal */
|
|
3792
3782
|
_unregisterDropdownEvents() {
|
|
3793
3783
|
this._p.sink.remove(null, ".dropdown");
|
|
3794
3784
|
}
|
|
3785
|
+
/** @internal */
|
|
3795
3786
|
_registerDropdownEvents() {
|
|
3796
3787
|
const p = this._p;
|
|
3797
3788
|
this._unregisterDropdownEvents();
|
|
@@ -3929,6 +3920,7 @@ var SelectBox = class {
|
|
|
3929
3920
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3930
3921
|
});
|
|
3931
3922
|
}
|
|
3923
|
+
/** @internal */
|
|
3932
3924
|
_performSelectWithEvent(item, value) {
|
|
3933
3925
|
let cancellable = {
|
|
3934
3926
|
value,
|
|
@@ -3945,6 +3937,7 @@ var SelectBox = class {
|
|
|
3945
3937
|
});
|
|
3946
3938
|
return true;
|
|
3947
3939
|
}
|
|
3940
|
+
/** @internal */
|
|
3948
3941
|
_performClearWithEvent(clearInput = false) {
|
|
3949
3942
|
let cancellable = { cancel: false };
|
|
3950
3943
|
this._trigger("clear:before", cancellable);
|
|
@@ -3955,6 +3948,7 @@ var SelectBox = class {
|
|
|
3955
3948
|
this._trigger("clear");
|
|
3956
3949
|
return true;
|
|
3957
3950
|
}
|
|
3951
|
+
/** @internal */
|
|
3958
3952
|
_movePrev() {
|
|
3959
3953
|
const p = this._p;
|
|
3960
3954
|
if (this.isMultiEnabled()) return;
|
|
@@ -3968,6 +3962,7 @@ var SelectBox = class {
|
|
|
3968
3962
|
else this._performClearWithEvent();
|
|
3969
3963
|
}
|
|
3970
3964
|
}
|
|
3965
|
+
/** @internal */
|
|
3971
3966
|
_moveNext() {
|
|
3972
3967
|
const p = this._p;
|
|
3973
3968
|
if (this.isMultiEnabled()) return;
|
|
@@ -3982,6 +3977,7 @@ var SelectBox = class {
|
|
|
3982
3977
|
}
|
|
3983
3978
|
}
|
|
3984
3979
|
/** @private */
|
|
3980
|
+
/** @internal */
|
|
3985
3981
|
_updateListItems() {
|
|
3986
3982
|
const p = this._p;
|
|
3987
3983
|
const dropList = p.dropList;
|
|
@@ -4011,6 +4007,7 @@ var SelectBox = class {
|
|
|
4011
4007
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
4012
4008
|
}
|
|
4013
4009
|
/** @private */
|
|
4010
|
+
/** @internal */
|
|
4014
4011
|
_setSelectedItems(items) {
|
|
4015
4012
|
const p = this._p, valueProp = p.valueProp;
|
|
4016
4013
|
if (p.multi) {
|
|
@@ -4026,6 +4023,7 @@ var SelectBox = class {
|
|
|
4026
4023
|
this._scheduleSync("full");
|
|
4027
4024
|
}
|
|
4028
4025
|
/** @private */
|
|
4026
|
+
/** @internal */
|
|
4029
4027
|
_scheduleSync(mode, data) {
|
|
4030
4028
|
const p = this._p;
|
|
4031
4029
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4043,6 +4041,7 @@ var SelectBox = class {
|
|
|
4043
4041
|
});
|
|
4044
4042
|
}
|
|
4045
4043
|
/** @private */
|
|
4044
|
+
/** @internal */
|
|
4046
4045
|
_performSync(queue) {
|
|
4047
4046
|
const p = this._p;
|
|
4048
4047
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4096,13 +4095,18 @@ var SelectBox = class {
|
|
|
4096
4095
|
}
|
|
4097
4096
|
}
|
|
4098
4097
|
/** @private */
|
|
4098
|
+
/** @internal */
|
|
4099
4099
|
_cleanupSingleWrapper() {
|
|
4100
4100
|
const p = this._p;
|
|
4101
4101
|
if (!p.singleWrapper) return;
|
|
4102
4102
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4103
4103
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4104
4104
|
} catch (err) {
|
|
4105
|
-
|
|
4105
|
+
reportError(p.onError, err, {
|
|
4106
|
+
source: "unrenderSingleItem",
|
|
4107
|
+
item: p.singleWrapper[ItemSymbol],
|
|
4108
|
+
el: p.singleWrapper
|
|
4109
|
+
});
|
|
4106
4110
|
}
|
|
4107
4111
|
delete p.singleWrapper[ItemSymbol];
|
|
4108
4112
|
p.singleWrapper.innerHTML = "";
|
|
@@ -4110,6 +4114,7 @@ var SelectBox = class {
|
|
|
4110
4114
|
/**
|
|
4111
4115
|
* @param {number} index
|
|
4112
4116
|
* @private
|
|
4117
|
+
* @internal
|
|
4113
4118
|
*/
|
|
4114
4119
|
_removeMultiItemElementByIndex(index) {
|
|
4115
4120
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4120,7 +4125,11 @@ var SelectBox = class {
|
|
|
4120
4125
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4121
4126
|
unrender(item, itemEl);
|
|
4122
4127
|
} catch (err) {
|
|
4123
|
-
|
|
4128
|
+
reportError(p.onError, err, {
|
|
4129
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
4130
|
+
item,
|
|
4131
|
+
el: itemEl
|
|
4132
|
+
});
|
|
4124
4133
|
}
|
|
4125
4134
|
remove(itemEl);
|
|
4126
4135
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4130,6 +4139,7 @@ var SelectBox = class {
|
|
|
4130
4139
|
/**
|
|
4131
4140
|
* @param {DropList.ItemBase} item
|
|
4132
4141
|
* @private
|
|
4142
|
+
* @internal
|
|
4133
4143
|
*/
|
|
4134
4144
|
_renderSingleItemContent(item) {
|
|
4135
4145
|
const p = this._p;
|
|
@@ -4144,6 +4154,7 @@ var SelectBox = class {
|
|
|
4144
4154
|
* @param {DropList.ItemBase} item
|
|
4145
4155
|
* @param {Element} itemEl
|
|
4146
4156
|
* @private
|
|
4157
|
+
* @internal
|
|
4147
4158
|
*/
|
|
4148
4159
|
_renderMultiItemContent(item, itemEl) {
|
|
4149
4160
|
const p = this._p;
|
|
@@ -4158,6 +4169,7 @@ var SelectBox = class {
|
|
|
4158
4169
|
* @param {DropList.ItemBase} item
|
|
4159
4170
|
* @returns {boolean} true if rendered, false if not
|
|
4160
4171
|
* @private
|
|
4172
|
+
* @internal
|
|
4161
4173
|
*/
|
|
4162
4174
|
_addMultiItemElement(item) {
|
|
4163
4175
|
const p = this._p;
|
|
@@ -4168,6 +4180,7 @@ var SelectBox = class {
|
|
|
4168
4180
|
return true;
|
|
4169
4181
|
}
|
|
4170
4182
|
/** @private */
|
|
4183
|
+
/** @internal */
|
|
4171
4184
|
_addMultiItemRestElement() {
|
|
4172
4185
|
const p = this._p;
|
|
4173
4186
|
let items = p.selectedItems.slice(0);
|
|
@@ -4180,6 +4193,7 @@ var SelectBox = class {
|
|
|
4180
4193
|
});
|
|
4181
4194
|
}
|
|
4182
4195
|
/** @private */
|
|
4196
|
+
/** @internal */
|
|
4183
4197
|
_syncClearButton() {
|
|
4184
4198
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4185
4199
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4202,6 +4216,7 @@ var SelectBox = class {
|
|
|
4202
4216
|
}
|
|
4203
4217
|
}
|
|
4204
4218
|
/** @private */
|
|
4219
|
+
/** @internal */
|
|
4205
4220
|
_syncPlaceholder() {
|
|
4206
4221
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4207
4222
|
let placeholder = "";
|
|
@@ -4213,6 +4228,7 @@ var SelectBox = class {
|
|
|
4213
4228
|
else p.input.removeAttribute("title");
|
|
4214
4229
|
}
|
|
4215
4230
|
/** @private */
|
|
4231
|
+
/** @internal */
|
|
4216
4232
|
_syncSingleItem() {
|
|
4217
4233
|
const p = this._p;
|
|
4218
4234
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4227,6 +4243,7 @@ var SelectBox = class {
|
|
|
4227
4243
|
* @param {boolean=false} fullItemsRender Should re-render all items?
|
|
4228
4244
|
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4229
4245
|
* @returns {SelectBox}
|
|
4246
|
+
* @internal
|
|
4230
4247
|
*/
|
|
4231
4248
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4232
4249
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4287,6 +4304,7 @@ var SelectBox = class {
|
|
|
4287
4304
|
* @param {string} event
|
|
4288
4305
|
* @param {*} [data]
|
|
4289
4306
|
* @private
|
|
4307
|
+
* @internal
|
|
4290
4308
|
*/
|
|
4291
4309
|
_trigger(event, data) {
|
|
4292
4310
|
const p = this._p;
|
|
@@ -4299,6 +4317,7 @@ var SelectBox = class {
|
|
|
4299
4317
|
* @param {Object} item
|
|
4300
4318
|
* @returns {Element|null}
|
|
4301
4319
|
* @private
|
|
4320
|
+
* @internal
|
|
4302
4321
|
*/
|
|
4303
4322
|
_renderMultiItem(item) {
|
|
4304
4323
|
const p = this._p;
|
|
@@ -4326,6 +4345,7 @@ var SelectBox = class {
|
|
|
4326
4345
|
* @param {Event} originatingEvent
|
|
4327
4346
|
* @returns {SelectBox}
|
|
4328
4347
|
* @private
|
|
4348
|
+
* @internal
|
|
4329
4349
|
*/
|
|
4330
4350
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4331
4351
|
const p = this._p;
|
|
@@ -4341,7 +4361,7 @@ var SelectBox = class {
|
|
|
4341
4361
|
let itemsToRemove = [];
|
|
4342
4362
|
for (let item of items) {
|
|
4343
4363
|
let removeselEvt = {
|
|
4344
|
-
value,
|
|
4364
|
+
value: item[p.valueProp],
|
|
4345
4365
|
item,
|
|
4346
4366
|
cancel: false
|
|
4347
4367
|
};
|
|
@@ -4352,7 +4372,7 @@ var SelectBox = class {
|
|
|
4352
4372
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4353
4373
|
for (let item of itemsToRemove) {
|
|
4354
4374
|
let idx = p.selectedItems.indexOf(item);
|
|
4355
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
4375
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4356
4376
|
if (idx !== -1) {
|
|
4357
4377
|
p.selectedItems.splice(idx, 1);
|
|
4358
4378
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4386,6 +4406,7 @@ var SelectBox = class {
|
|
|
4386
4406
|
* @param {DropList.ItemBase} item
|
|
4387
4407
|
* @param {boolean} [populate]
|
|
4388
4408
|
* @private
|
|
4409
|
+
* @internal
|
|
4389
4410
|
*/
|
|
4390
4411
|
_removeMultiItem(item, populate = false) {
|
|
4391
4412
|
const p = this._p;
|
|
@@ -4412,6 +4433,7 @@ var SelectBox = class {
|
|
|
4412
4433
|
/**
|
|
4413
4434
|
* @param {*} value
|
|
4414
4435
|
* @private
|
|
4436
|
+
* @internal
|
|
4415
4437
|
*/
|
|
4416
4438
|
_setInputText(value) {
|
|
4417
4439
|
const p = this._p;
|
|
@@ -4424,6 +4446,7 @@ var SelectBox = class {
|
|
|
4424
4446
|
* Update input size to current state
|
|
4425
4447
|
* @returns {SelectBox}
|
|
4426
4448
|
* @private
|
|
4449
|
+
* @internal
|
|
4427
4450
|
*/
|
|
4428
4451
|
_resizeInput() {
|
|
4429
4452
|
const p = this._p, el = p.el;
|
|
@@ -4481,6 +4504,7 @@ var SelectBox = class {
|
|
|
4481
4504
|
* Update autocomplete position if needed
|
|
4482
4505
|
* @returns {SelectBox}
|
|
4483
4506
|
* @private
|
|
4507
|
+
* @internal
|
|
4484
4508
|
*/
|
|
4485
4509
|
_repositionDropList() {
|
|
4486
4510
|
const p = this._p, el = p.el;
|
|
@@ -4496,6 +4520,7 @@ var SelectBox = class {
|
|
|
4496
4520
|
/**
|
|
4497
4521
|
* @param {KeyboardEvent} event
|
|
4498
4522
|
* @private
|
|
4523
|
+
* @internal
|
|
4499
4524
|
*/
|
|
4500
4525
|
_handleInputKeydown(event) {
|
|
4501
4526
|
const p = this._p;
|
|
@@ -4526,6 +4551,7 @@ var SelectBox = class {
|
|
|
4526
4551
|
/**
|
|
4527
4552
|
* @param {KeyboardEvent} event
|
|
4528
4553
|
* @private
|
|
4554
|
+
* @internal
|
|
4529
4555
|
*/
|
|
4530
4556
|
_handleMultiKeydown(event) {
|
|
4531
4557
|
const p = this._p;
|
|
@@ -4571,6 +4597,7 @@ var SelectBox = class {
|
|
|
4571
4597
|
/**
|
|
4572
4598
|
* @returns {DropList.PositionOptions}
|
|
4573
4599
|
* @private
|
|
4600
|
+
* @internal
|
|
4574
4601
|
*/
|
|
4575
4602
|
_getDropListPositionOptions() {
|
|
4576
4603
|
return {
|
|
@@ -4591,6 +4618,7 @@ var SelectBox = class {
|
|
|
4591
4618
|
};
|
|
4592
4619
|
}
|
|
4593
4620
|
/** @private */
|
|
4621
|
+
/** @internal */
|
|
4594
4622
|
_startTrackingPresence() {
|
|
4595
4623
|
const p = this._p;
|
|
4596
4624
|
this._stopTrackingPresence();
|
|
@@ -4599,6 +4627,7 @@ var SelectBox = class {
|
|
|
4599
4627
|
}, 200);
|
|
4600
4628
|
}
|
|
4601
4629
|
/** @private */
|
|
4630
|
+
/** @internal */
|
|
4602
4631
|
_stopTrackingPresence() {
|
|
4603
4632
|
const p = this._p;
|
|
4604
4633
|
if (p.presenceInt) {
|
|
@@ -4614,6 +4643,7 @@ var SelectBox = class {
|
|
|
4614
4643
|
* @param {boolean=false} sortCheckedFirst
|
|
4615
4644
|
* @param {boolean=false} splitCheckedGroups
|
|
4616
4645
|
* @returns {DropList.ItemBase[]}
|
|
4646
|
+
* @internal
|
|
4617
4647
|
*/
|
|
4618
4648
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4619
4649
|
const p = this._p;
|