@danielgindi/selectbox 2.0.56 → 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 +203 -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 +203 -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 +203 -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 -3412
- 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 +450 -509
- 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.umd.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
|
(function(global, factory) {
|
|
@@ -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,85 +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} [noResultsText='No matching results'] text for no results (empty for none)
|
|
121
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
122
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
123
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
124
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
125
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
126
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
127
|
-
* */
|
|
128
|
-
/** */
|
|
129
|
-
/**
|
|
130
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
131
|
-
* @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`)
|
|
132
|
-
* @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`)
|
|
133
|
-
* */
|
|
134
|
-
/** */
|
|
135
|
-
/**
|
|
136
|
-
* @typedef {Object} DropList.PositionOptions
|
|
137
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
138
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
139
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
140
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
141
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
142
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
143
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
144
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
145
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
146
|
-
* */
|
|
147
|
-
/** */
|
|
148
|
-
/**
|
|
149
|
-
* @typedef {Object} DropList.ItemBase
|
|
150
|
-
* @property {string} [value]
|
|
151
|
-
* @property {string} [label]
|
|
152
|
-
* @property {boolean} [_group=false]
|
|
153
|
-
* @property {boolean} [_child=false]
|
|
154
|
-
* @property {boolean} [_nocheck=false]
|
|
155
|
-
* @property {boolean} [_nointeraction=false]
|
|
156
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
157
|
-
* */
|
|
158
|
-
/**
|
|
159
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
160
|
-
* @property {boolean} [_checked=false]
|
|
161
|
-
* */
|
|
162
|
-
/** */
|
|
163
|
-
/** @type {DropList.Options} */
|
|
164
113
|
var DefaultOptions = {
|
|
165
114
|
baseClassName: "droplist",
|
|
166
115
|
autoItemBlur: true,
|
|
@@ -181,6 +130,7 @@
|
|
|
181
130
|
isHeaderVisible: false,
|
|
182
131
|
isFooterVisible: false,
|
|
183
132
|
searchable: false,
|
|
133
|
+
searchPlaceholder: "",
|
|
184
134
|
noResultsText: "No matching results",
|
|
185
135
|
filterThrottleWindow: 300,
|
|
186
136
|
filterOnEmptyTerm: false,
|
|
@@ -224,7 +174,9 @@
|
|
|
224
174
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
225
175
|
on: o.on || null,
|
|
226
176
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
177
|
+
onError: o.onError,
|
|
227
178
|
searchable: o.searchable,
|
|
179
|
+
searchPlaceholder: o.searchPlaceholder,
|
|
228
180
|
isHeaderVisible: o.isHeaderVisible,
|
|
229
181
|
isFooterVisible: o.isFooterVisible,
|
|
230
182
|
silenceEvents: true,
|
|
@@ -240,7 +192,14 @@
|
|
|
240
192
|
throttledRefilterItems: null,
|
|
241
193
|
focusItemIndex: -1,
|
|
242
194
|
focusItemEl: null,
|
|
243
|
-
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default()
|
|
195
|
+
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default(),
|
|
196
|
+
visible: false,
|
|
197
|
+
hiding: false,
|
|
198
|
+
singleSelectedItemEl: null,
|
|
199
|
+
onDocumentMouseDown: null,
|
|
200
|
+
lastKeyWasChar: false,
|
|
201
|
+
currentSubDropList: null,
|
|
202
|
+
_isFocusingItem: false
|
|
244
203
|
};
|
|
245
204
|
let classes = [p.baseClassName + "_wrapper"];
|
|
246
205
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -306,7 +265,11 @@
|
|
|
306
265
|
};
|
|
307
266
|
else item = items[index];
|
|
308
267
|
}
|
|
309
|
-
if (!item)
|
|
268
|
+
if (!item) reportError(p.onError, `onItemRender called for (${index}) which has no item`, {
|
|
269
|
+
source: "renderItem",
|
|
270
|
+
level: "warn",
|
|
271
|
+
index
|
|
272
|
+
});
|
|
310
273
|
itemEl.className = `${p.baseClassName}__item`;
|
|
311
274
|
const classList = itemEl.classList;
|
|
312
275
|
if (item) {
|
|
@@ -464,6 +427,7 @@
|
|
|
464
427
|
}
|
|
465
428
|
/**
|
|
466
429
|
* @private
|
|
430
|
+
* @internal
|
|
467
431
|
*/
|
|
468
432
|
_setupUnrenderFunction() {
|
|
469
433
|
const p = this._p;
|
|
@@ -475,12 +439,20 @@
|
|
|
475
439
|
if (item === NoResultsItemSymbol) try {
|
|
476
440
|
fnNoResults(item, el);
|
|
477
441
|
} catch (err) {
|
|
478
|
-
|
|
442
|
+
reportError(p.onError, err, {
|
|
443
|
+
source: "unrenderNoResultsItem",
|
|
444
|
+
item,
|
|
445
|
+
el
|
|
446
|
+
});
|
|
479
447
|
}
|
|
480
448
|
else try {
|
|
481
449
|
fn(item[ItemSymbol], el);
|
|
482
450
|
} catch (err) {
|
|
483
|
-
|
|
451
|
+
reportError(p.onError, err, {
|
|
452
|
+
source: "unrenderItem",
|
|
453
|
+
item: item[ItemSymbol],
|
|
454
|
+
el
|
|
455
|
+
});
|
|
484
456
|
}
|
|
485
457
|
delete el[ItemSymbol];
|
|
486
458
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -500,6 +472,7 @@
|
|
|
500
472
|
p.valueProp = prop;
|
|
501
473
|
return this;
|
|
502
474
|
}
|
|
475
|
+
/** @internal */
|
|
503
476
|
_syncBaseClasses() {
|
|
504
477
|
const p = this._p, el = p.el;
|
|
505
478
|
if (!el) return;
|
|
@@ -538,7 +511,7 @@
|
|
|
538
511
|
goToLast(event) {
|
|
539
512
|
this._move("last", event);
|
|
540
513
|
}
|
|
541
|
-
toggleFocusedItem() {
|
|
514
|
+
toggleFocusedItem(event) {
|
|
542
515
|
const p = this._p;
|
|
543
516
|
if (this.hasFocusedItem() && p.multi) {
|
|
544
517
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -659,7 +632,7 @@
|
|
|
659
632
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
660
633
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
661
634
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
662
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
635
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
663
636
|
if (p.multi) {
|
|
664
637
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
665
638
|
}
|
|
@@ -667,10 +640,10 @@
|
|
|
667
640
|
if (!!newItem._group !== item._group) {
|
|
668
641
|
if (item._group) p.groupCount--;
|
|
669
642
|
else p.groupCount++;
|
|
670
|
-
|
|
643
|
+
item._group = !!newItem._group;
|
|
671
644
|
}
|
|
672
645
|
}
|
|
673
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
646
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
674
647
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
675
648
|
let virtualItemIndex = itemIndex;
|
|
676
649
|
if (p.filteredItems) {
|
|
@@ -817,6 +790,23 @@
|
|
|
817
790
|
return this._p.positionOptionsProvider;
|
|
818
791
|
}
|
|
819
792
|
/**
|
|
793
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
794
|
+
* instead of the default `console.error`/`console.warn`.
|
|
795
|
+
* @param {DropList.LibraryErrorHandler|null} [fn]
|
|
796
|
+
* @returns {DropList}
|
|
797
|
+
*/
|
|
798
|
+
setOnError(fn) {
|
|
799
|
+
const p = this._p;
|
|
800
|
+
p.onError = fn ?? void 0;
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* @returns {DropList.LibraryErrorHandler|undefined}
|
|
805
|
+
*/
|
|
806
|
+
getOnError() {
|
|
807
|
+
return this._p.onError;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
820
810
|
* @param {string} term
|
|
821
811
|
* @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
|
|
822
812
|
* @returns {DropList}
|
|
@@ -837,6 +827,7 @@
|
|
|
837
827
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
838
828
|
}
|
|
839
829
|
/** @private */
|
|
830
|
+
/** @internal */
|
|
840
831
|
_refilterItems() {
|
|
841
832
|
const p = this._p;
|
|
842
833
|
const term = p.filterTerm;
|
|
@@ -871,7 +862,7 @@
|
|
|
871
862
|
});
|
|
872
863
|
}
|
|
873
864
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
874
|
-
const matcher = new RegExp(
|
|
865
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
875
866
|
filteredItems = p.items.filter((x) => {
|
|
876
867
|
if (!filterGroups && x._group) return true;
|
|
877
868
|
return matcher.test(x.label);
|
|
@@ -948,7 +939,7 @@
|
|
|
948
939
|
p.filterThrottleWindow = window;
|
|
949
940
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
950
941
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
951
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
942
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
952
943
|
if (isScheduled) p.throttledRefilterItems();
|
|
953
944
|
return this;
|
|
954
945
|
}
|
|
@@ -1294,7 +1285,7 @@
|
|
|
1294
1285
|
if (this.isVisible()) this._trigger("show");
|
|
1295
1286
|
return this;
|
|
1296
1287
|
}
|
|
1297
|
-
hide() {
|
|
1288
|
+
hide(event) {
|
|
1298
1289
|
const p = this._p, el = p.el;
|
|
1299
1290
|
if (p.onDocumentMouseDown) {
|
|
1300
1291
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1406,7 +1397,8 @@
|
|
|
1406
1397
|
autocomplete: "off",
|
|
1407
1398
|
autocapitalize: "off",
|
|
1408
1399
|
spellcheck: "false",
|
|
1409
|
-
"aria-autocomplete": "list"
|
|
1400
|
+
"aria-autocomplete": "list",
|
|
1401
|
+
placeholder: p.searchPlaceholder || ""
|
|
1410
1402
|
});
|
|
1411
1403
|
p.headerEl.appendChild(p.searchInput);
|
|
1412
1404
|
} else {
|
|
@@ -1415,6 +1407,15 @@
|
|
|
1415
1407
|
}
|
|
1416
1408
|
this.setHeaderVisible(searchable);
|
|
1417
1409
|
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Set the placeholder text of the inline search box
|
|
1412
|
+
* @param {string} placeholder
|
|
1413
|
+
*/
|
|
1414
|
+
setSearchPlaceholder(placeholder) {
|
|
1415
|
+
const p = this._p;
|
|
1416
|
+
p.searchPlaceholder = placeholder || "";
|
|
1417
|
+
if (p.searchInput) p.searchInput.placeholder = p.searchPlaceholder;
|
|
1418
|
+
}
|
|
1418
1419
|
hasFocusedItem() {
|
|
1419
1420
|
return this._p.focusItemIndex > -1 && this._p.focusItemIndex < this._p.items.length;
|
|
1420
1421
|
}
|
|
@@ -1456,6 +1457,7 @@
|
|
|
1456
1457
|
}
|
|
1457
1458
|
return this;
|
|
1458
1459
|
}
|
|
1460
|
+
/** @internal */
|
|
1459
1461
|
_showSublist(item, itemElement) {
|
|
1460
1462
|
if (!item._subitems?.length) return;
|
|
1461
1463
|
const p = this._p;
|
|
@@ -1531,6 +1533,7 @@
|
|
|
1531
1533
|
droplist.show();
|
|
1532
1534
|
droplist.el.focus();
|
|
1533
1535
|
}
|
|
1536
|
+
/** @internal */
|
|
1534
1537
|
_hideSublist() {
|
|
1535
1538
|
const p = this._p;
|
|
1536
1539
|
if (!p.currentSubDropList) return;
|
|
@@ -1630,6 +1633,7 @@
|
|
|
1630
1633
|
}
|
|
1631
1634
|
return this;
|
|
1632
1635
|
}
|
|
1636
|
+
/** @internal */
|
|
1633
1637
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1634
1638
|
const p = this._p;
|
|
1635
1639
|
if (this._hasScroll()) {
|
|
@@ -1693,6 +1697,7 @@
|
|
|
1693
1697
|
this._p.mitt.emit(event, value);
|
|
1694
1698
|
return this;
|
|
1695
1699
|
}
|
|
1700
|
+
/** @internal */
|
|
1696
1701
|
_getItemIndex(item) {
|
|
1697
1702
|
const p = this._p;
|
|
1698
1703
|
let itemIndex = -1;
|
|
@@ -1706,6 +1711,7 @@
|
|
|
1706
1711
|
}
|
|
1707
1712
|
return itemIndex;
|
|
1708
1713
|
}
|
|
1714
|
+
/** @internal */
|
|
1709
1715
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1710
1716
|
const p = this._p;
|
|
1711
1717
|
if (p.singleSelectedItemEl) {
|
|
@@ -1723,12 +1729,14 @@
|
|
|
1723
1729
|
* @param {string} event
|
|
1724
1730
|
* @param {*} [data]
|
|
1725
1731
|
* @private
|
|
1732
|
+
* @internal
|
|
1726
1733
|
*/
|
|
1727
1734
|
_trigger(event, data) {
|
|
1728
1735
|
const p = this._p;
|
|
1729
1736
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1730
1737
|
p.mitt.emit(event, data);
|
|
1731
1738
|
}
|
|
1739
|
+
/** @internal */
|
|
1732
1740
|
_itemUpAction(event, itemEl) {
|
|
1733
1741
|
if ((0, _danielgindi_dom_utils_lib_Dom.closestUntil)(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1734
1742
|
let p = this._p;
|
|
@@ -1741,6 +1749,7 @@
|
|
|
1741
1749
|
}, 0);
|
|
1742
1750
|
}
|
|
1743
1751
|
}
|
|
1752
|
+
/** @internal */
|
|
1744
1753
|
_hookMouseEvents() {
|
|
1745
1754
|
const p = this._p;
|
|
1746
1755
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1754,9 +1763,11 @@
|
|
|
1754
1763
|
this._handleMouseOver(event, li);
|
|
1755
1764
|
});
|
|
1756
1765
|
}
|
|
1766
|
+
/** @internal */
|
|
1757
1767
|
_handleMouseOver(event, itemEl) {
|
|
1758
1768
|
this._focus(event, itemEl, null, true);
|
|
1759
1769
|
}
|
|
1770
|
+
/** @internal */
|
|
1760
1771
|
_hookTouchEvents() {
|
|
1761
1772
|
const p = this._p;
|
|
1762
1773
|
let currentTouchId;
|
|
@@ -1796,6 +1807,7 @@
|
|
|
1796
1807
|
});
|
|
1797
1808
|
});
|
|
1798
1809
|
}
|
|
1810
|
+
/** @internal */
|
|
1799
1811
|
_hookFocusEvents() {
|
|
1800
1812
|
const p = this._p;
|
|
1801
1813
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1813,10 +1825,12 @@
|
|
|
1813
1825
|
});
|
|
1814
1826
|
}, true);
|
|
1815
1827
|
}
|
|
1828
|
+
/** @internal */
|
|
1816
1829
|
_hookKeyEvents() {
|
|
1817
1830
|
const p = this._p;
|
|
1818
1831
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1819
1832
|
}
|
|
1833
|
+
/** @internal */
|
|
1820
1834
|
_hookSearchEvents() {
|
|
1821
1835
|
const p = this._p;
|
|
1822
1836
|
if (!p.searchInput) return;
|
|
@@ -1827,6 +1841,7 @@
|
|
|
1827
1841
|
p.throttledRefilterItems();
|
|
1828
1842
|
});
|
|
1829
1843
|
}
|
|
1844
|
+
/** @internal */
|
|
1830
1845
|
_keydown(event) {
|
|
1831
1846
|
const p = this._p;
|
|
1832
1847
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1889,6 +1904,7 @@
|
|
|
1889
1904
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1890
1905
|
}
|
|
1891
1906
|
}
|
|
1907
|
+
/** @internal */
|
|
1892
1908
|
_keydownFreeType(evt, autoSelect) {
|
|
1893
1909
|
const p = this._p;
|
|
1894
1910
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1897,7 +1913,7 @@
|
|
|
1897
1913
|
if (!isChar) return;
|
|
1898
1914
|
clearTimeout(p.filterTimer);
|
|
1899
1915
|
let keyword = (p.previousFilter || "") + character;
|
|
1900
|
-
let regex = new RegExp(`^${
|
|
1916
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1901
1917
|
let matchIndex = -1;
|
|
1902
1918
|
let item;
|
|
1903
1919
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1912,7 +1928,7 @@
|
|
|
1912
1928
|
}
|
|
1913
1929
|
if (matchIndex === -1) {
|
|
1914
1930
|
keyword = character;
|
|
1915
|
-
regex = new RegExp(`^${
|
|
1931
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1916
1932
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1917
1933
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1918
1934
|
item = items[i];
|
|
@@ -1932,6 +1948,7 @@
|
|
|
1932
1948
|
}, 1e3);
|
|
1933
1949
|
} else delete p.previousFilter;
|
|
1934
1950
|
}
|
|
1951
|
+
/** @internal */
|
|
1935
1952
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1936
1953
|
const p = this._p;
|
|
1937
1954
|
if (p._isFocusingItem) return;
|
|
@@ -1965,6 +1982,7 @@
|
|
|
1965
1982
|
p._isFocusingItem = false;
|
|
1966
1983
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1967
1984
|
}
|
|
1985
|
+
/** @internal */
|
|
1968
1986
|
_delayBlurItemOnBlur() {
|
|
1969
1987
|
if (this[DestroyedSymbol$1]) return;
|
|
1970
1988
|
const p = this._p;
|
|
@@ -1975,6 +1993,7 @@
|
|
|
1975
1993
|
this.blurFocusedItem();
|
|
1976
1994
|
}, p.autoItemBlurDelay);
|
|
1977
1995
|
}
|
|
1996
|
+
/** @internal */
|
|
1978
1997
|
_move(direction, event) {
|
|
1979
1998
|
const p = this._p;
|
|
1980
1999
|
let next, nextIndex, directionUp;
|
|
@@ -2044,10 +2063,12 @@
|
|
|
2044
2063
|
this._focus(event, next || null, nextIndex, false);
|
|
2045
2064
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2046
2065
|
}
|
|
2066
|
+
/** @internal */
|
|
2047
2067
|
_hasScroll() {
|
|
2048
2068
|
const menuEl = this._p.menuEl;
|
|
2049
2069
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2050
2070
|
}
|
|
2071
|
+
/** @internal */
|
|
2051
2072
|
_updateGroupStateForItem(item) {
|
|
2052
2073
|
const p = this._p;
|
|
2053
2074
|
if (!p.multi) return this;
|
|
@@ -2091,6 +2112,7 @@
|
|
|
2091
2112
|
}
|
|
2092
2113
|
return this;
|
|
2093
2114
|
}
|
|
2115
|
+
/** @internal */
|
|
2094
2116
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2095
2117
|
const p = this._p;
|
|
2096
2118
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2124,6 +2146,7 @@
|
|
|
2124
2146
|
/**
|
|
2125
2147
|
* @private
|
|
2126
2148
|
* @returns {DropList} self
|
|
2149
|
+
* @internal
|
|
2127
2150
|
*/
|
|
2128
2151
|
_measureItem() {
|
|
2129
2152
|
const p = this._p;
|
|
@@ -2171,6 +2194,7 @@
|
|
|
2171
2194
|
* @param {number?} targetItemCount - item count we are expecting. Defaults to current item count
|
|
2172
2195
|
* @returns {DropList}
|
|
2173
2196
|
* @private
|
|
2197
|
+
* @internal
|
|
2174
2198
|
*/
|
|
2175
2199
|
_determineVirtualMode(targetItemCount) {
|
|
2176
2200
|
const p = this._p;
|
|
@@ -2180,6 +2204,7 @@
|
|
|
2180
2204
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2181
2205
|
return this;
|
|
2182
2206
|
}
|
|
2207
|
+
/** @internal */
|
|
2183
2208
|
_renderItemContent(item, itemEl) {
|
|
2184
2209
|
const p = this._p;
|
|
2185
2210
|
const originalItem = item[ItemSymbol];
|
|
@@ -2201,17 +2226,12 @@
|
|
|
2201
2226
|
}
|
|
2202
2227
|
}
|
|
2203
2228
|
}
|
|
2204
|
-
/**
|
|
2205
|
-
*
|
|
2206
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2207
|
-
* @returns {number} new outer width
|
|
2208
|
-
* @private
|
|
2209
|
-
*/
|
|
2229
|
+
/** @internal */
|
|
2210
2230
|
_updateWidth(positionOptions) {
|
|
2211
2231
|
const p = this._p, el = p.el;
|
|
2212
2232
|
let targetWidth = 0;
|
|
2213
2233
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2214
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2234
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2215
2235
|
else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
|
|
2216
2236
|
let autoWidth = 0;
|
|
2217
2237
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2233,7 +2253,7 @@
|
|
|
2233
2253
|
}
|
|
2234
2254
|
};
|
|
2235
2255
|
//#endregion
|
|
2236
|
-
//#region lib/SelectBox.
|
|
2256
|
+
//#region src/lib/SelectBox.ts
|
|
2237
2257
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2238
2258
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2239
2259
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2259,57 +2279,6 @@
|
|
|
2259
2279
|
"padding-left",
|
|
2260
2280
|
"padding-right"
|
|
2261
2281
|
];
|
|
2262
|
-
/**
|
|
2263
|
-
* @typedef {Object} SelectBox.Options
|
|
2264
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2265
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2266
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2267
|
-
* @property {string|string[]} [additionalClasses]
|
|
2268
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2269
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2270
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2271
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2272
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2273
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2274
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2275
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2276
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2277
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2278
|
-
* @property {*[]} [stickyValues]
|
|
2279
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2280
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2281
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2282
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2283
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2284
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2285
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2286
|
-
* @property {string} [labelProp='label']
|
|
2287
|
-
* @property {string} [valueProp='value']
|
|
2288
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2289
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2290
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2291
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2292
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2293
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2294
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2295
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2296
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2297
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2298
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2299
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2300
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2301
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2302
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2303
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2304
|
-
* @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.
|
|
2305
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2306
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2307
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2308
|
-
* @property {function(name: string, ...args)} [on]
|
|
2309
|
-
* @property {boolean} [isLoadingMode]
|
|
2310
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2311
|
-
* @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>
|
|
2312
|
-
* */
|
|
2313
2282
|
var DefaultOptions$1 = {
|
|
2314
2283
|
el: null,
|
|
2315
2284
|
baseClassName: "selectbox",
|
|
@@ -2428,6 +2397,7 @@
|
|
|
2428
2397
|
on: o.on || null,
|
|
2429
2398
|
silenceEvents: true,
|
|
2430
2399
|
mitt: (0, mitt.default)(),
|
|
2400
|
+
onError: o.onError,
|
|
2431
2401
|
isLoadingMode: !!o.isLoadingMode,
|
|
2432
2402
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2433
2403
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2443,7 +2413,11 @@
|
|
|
2443
2413
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2444
2414
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2445
2415
|
filterFn: null,
|
|
2446
|
-
filterTerm: ""
|
|
2416
|
+
filterTerm: "",
|
|
2417
|
+
dropListVisible: false,
|
|
2418
|
+
lastActiveElement: null,
|
|
2419
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2420
|
+
presenceInt: null
|
|
2447
2421
|
};
|
|
2448
2422
|
let el = o.el;
|
|
2449
2423
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -3181,7 +3155,7 @@
|
|
|
3181
3155
|
if (p.filterFn === fn) return this;
|
|
3182
3156
|
p.filterFn = fn;
|
|
3183
3157
|
if (!fn) fn = (items, term) => {
|
|
3184
|
-
const matcher = new RegExp(
|
|
3158
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3185
3159
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3186
3160
|
return p.items.filter((x) => {
|
|
3187
3161
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3199,6 +3173,25 @@
|
|
|
3199
3173
|
return this._p.filterFn;
|
|
3200
3174
|
}
|
|
3201
3175
|
/**
|
|
3176
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderMultiItem`/`unrenderSingleItem`)
|
|
3177
|
+
* instead of the default `console.error`/`console.warn`. Also used as the default `onError` for the internal
|
|
3178
|
+
* `DropList`, unless `listOptions.onError` is set explicitly.
|
|
3179
|
+
* @param {SelectBox.LibraryErrorHandler|null} [fn]
|
|
3180
|
+
* @returns {SelectBox}
|
|
3181
|
+
*/
|
|
3182
|
+
setOnError(fn) {
|
|
3183
|
+
const p = this._p;
|
|
3184
|
+
p.onError = fn ?? void 0;
|
|
3185
|
+
p.dropList?.setOnError(p.listOptions?.onError ?? p.onError);
|
|
3186
|
+
return this;
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* @returns {SelectBox.LibraryErrorHandler|undefined}
|
|
3190
|
+
*/
|
|
3191
|
+
getOnError() {
|
|
3192
|
+
return this._p.onError;
|
|
3193
|
+
}
|
|
3194
|
+
/**
|
|
3202
3195
|
* Focus on input element
|
|
3203
3196
|
* @returns {SelectBox}
|
|
3204
3197
|
*/
|
|
@@ -3487,6 +3480,7 @@
|
|
|
3487
3480
|
* Prepare the mapping between values and items.
|
|
3488
3481
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3489
3482
|
* @private
|
|
3483
|
+
* @internal
|
|
3490
3484
|
*/
|
|
3491
3485
|
_refreshItemByValueMap() {
|
|
3492
3486
|
const p = this._p;
|
|
@@ -3499,6 +3493,7 @@
|
|
|
3499
3493
|
* @param {*} value
|
|
3500
3494
|
* @returns {DropList.ItemBase|undefined}
|
|
3501
3495
|
* @private
|
|
3496
|
+
* @internal
|
|
3502
3497
|
*/
|
|
3503
3498
|
_getItemByValue(value) {
|
|
3504
3499
|
const p = this._p;
|
|
@@ -3508,6 +3503,7 @@
|
|
|
3508
3503
|
return p.subitemByValueMap.get(value);
|
|
3509
3504
|
}
|
|
3510
3505
|
/** @private */
|
|
3506
|
+
/** @internal */
|
|
3511
3507
|
_refreshSubitemByValueMap() {
|
|
3512
3508
|
const p = this._p;
|
|
3513
3509
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
@@ -3518,6 +3514,7 @@
|
|
|
3518
3514
|
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3519
3515
|
* @param {string} valueProp
|
|
3520
3516
|
* @private
|
|
3517
|
+
* @internal
|
|
3521
3518
|
*/
|
|
3522
3519
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3523
3520
|
for (let item of items) {
|
|
@@ -3527,6 +3524,7 @@
|
|
|
3527
3524
|
}
|
|
3528
3525
|
}
|
|
3529
3526
|
/** @private */
|
|
3527
|
+
/** @internal */
|
|
3530
3528
|
_renderBase() {
|
|
3531
3529
|
const p = this._p;
|
|
3532
3530
|
if (!p.inputBackBuffer) p.inputBackBuffer = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { css: {
|
|
@@ -3615,6 +3613,7 @@
|
|
|
3615
3613
|
}
|
|
3616
3614
|
/**
|
|
3617
3615
|
* @private
|
|
3616
|
+
* @internal
|
|
3618
3617
|
*/
|
|
3619
3618
|
_syncBaseClasses() {
|
|
3620
3619
|
const p = this._p, el = p.el;
|
|
@@ -3635,6 +3634,7 @@
|
|
|
3635
3634
|
el.className = classes.join(" ");
|
|
3636
3635
|
}
|
|
3637
3636
|
/** @private */
|
|
3637
|
+
/** @internal */
|
|
3638
3638
|
_setupDropdownMenu() {
|
|
3639
3639
|
const p = this._p;
|
|
3640
3640
|
p.valueProp;
|
|
@@ -3664,6 +3664,7 @@
|
|
|
3664
3664
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3665
3665
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3666
3666
|
filterFn: p.actualFilterFn,
|
|
3667
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3667
3668
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3668
3669
|
on: (name, event) => {
|
|
3669
3670
|
switch (name) {
|
|
@@ -3799,6 +3800,7 @@
|
|
|
3799
3800
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3800
3801
|
this._registerDropdownEvents();
|
|
3801
3802
|
}
|
|
3803
|
+
/** @internal */
|
|
3802
3804
|
_handleOnBlur() {
|
|
3803
3805
|
const p = this._p;
|
|
3804
3806
|
setTimeout(() => {
|
|
@@ -3810,9 +3812,11 @@
|
|
|
3810
3812
|
this.closeList();
|
|
3811
3813
|
});
|
|
3812
3814
|
}
|
|
3815
|
+
/** @internal */
|
|
3813
3816
|
_unregisterDropdownEvents() {
|
|
3814
3817
|
this._p.sink.remove(null, ".dropdown");
|
|
3815
3818
|
}
|
|
3819
|
+
/** @internal */
|
|
3816
3820
|
_registerDropdownEvents() {
|
|
3817
3821
|
const p = this._p;
|
|
3818
3822
|
this._unregisterDropdownEvents();
|
|
@@ -3950,6 +3954,7 @@
|
|
|
3950
3954
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3951
3955
|
});
|
|
3952
3956
|
}
|
|
3957
|
+
/** @internal */
|
|
3953
3958
|
_performSelectWithEvent(item, value) {
|
|
3954
3959
|
let cancellable = {
|
|
3955
3960
|
value,
|
|
@@ -3966,6 +3971,7 @@
|
|
|
3966
3971
|
});
|
|
3967
3972
|
return true;
|
|
3968
3973
|
}
|
|
3974
|
+
/** @internal */
|
|
3969
3975
|
_performClearWithEvent(clearInput = false) {
|
|
3970
3976
|
let cancellable = { cancel: false };
|
|
3971
3977
|
this._trigger("clear:before", cancellable);
|
|
@@ -3976,6 +3982,7 @@
|
|
|
3976
3982
|
this._trigger("clear");
|
|
3977
3983
|
return true;
|
|
3978
3984
|
}
|
|
3985
|
+
/** @internal */
|
|
3979
3986
|
_movePrev() {
|
|
3980
3987
|
const p = this._p;
|
|
3981
3988
|
if (this.isMultiEnabled()) return;
|
|
@@ -3989,6 +3996,7 @@
|
|
|
3989
3996
|
else this._performClearWithEvent();
|
|
3990
3997
|
}
|
|
3991
3998
|
}
|
|
3999
|
+
/** @internal */
|
|
3992
4000
|
_moveNext() {
|
|
3993
4001
|
const p = this._p;
|
|
3994
4002
|
if (this.isMultiEnabled()) return;
|
|
@@ -4003,6 +4011,7 @@
|
|
|
4003
4011
|
}
|
|
4004
4012
|
}
|
|
4005
4013
|
/** @private */
|
|
4014
|
+
/** @internal */
|
|
4006
4015
|
_updateListItems() {
|
|
4007
4016
|
const p = this._p;
|
|
4008
4017
|
const dropList = p.dropList;
|
|
@@ -4032,6 +4041,7 @@
|
|
|
4032
4041
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
4033
4042
|
}
|
|
4034
4043
|
/** @private */
|
|
4044
|
+
/** @internal */
|
|
4035
4045
|
_setSelectedItems(items) {
|
|
4036
4046
|
const p = this._p, valueProp = p.valueProp;
|
|
4037
4047
|
if (p.multi) {
|
|
@@ -4047,6 +4057,7 @@
|
|
|
4047
4057
|
this._scheduleSync("full");
|
|
4048
4058
|
}
|
|
4049
4059
|
/** @private */
|
|
4060
|
+
/** @internal */
|
|
4050
4061
|
_scheduleSync(mode, data) {
|
|
4051
4062
|
const p = this._p;
|
|
4052
4063
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4064,6 +4075,7 @@
|
|
|
4064
4075
|
});
|
|
4065
4076
|
}
|
|
4066
4077
|
/** @private */
|
|
4078
|
+
/** @internal */
|
|
4067
4079
|
_performSync(queue) {
|
|
4068
4080
|
const p = this._p;
|
|
4069
4081
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4117,13 +4129,18 @@
|
|
|
4117
4129
|
}
|
|
4118
4130
|
}
|
|
4119
4131
|
/** @private */
|
|
4132
|
+
/** @internal */
|
|
4120
4133
|
_cleanupSingleWrapper() {
|
|
4121
4134
|
const p = this._p;
|
|
4122
4135
|
if (!p.singleWrapper) return;
|
|
4123
4136
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4124
4137
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4125
4138
|
} catch (err) {
|
|
4126
|
-
|
|
4139
|
+
reportError(p.onError, err, {
|
|
4140
|
+
source: "unrenderSingleItem",
|
|
4141
|
+
item: p.singleWrapper[ItemSymbol],
|
|
4142
|
+
el: p.singleWrapper
|
|
4143
|
+
});
|
|
4127
4144
|
}
|
|
4128
4145
|
delete p.singleWrapper[ItemSymbol];
|
|
4129
4146
|
p.singleWrapper.innerHTML = "";
|
|
@@ -4131,6 +4148,7 @@
|
|
|
4131
4148
|
/**
|
|
4132
4149
|
* @param {number} index
|
|
4133
4150
|
* @private
|
|
4151
|
+
* @internal
|
|
4134
4152
|
*/
|
|
4135
4153
|
_removeMultiItemElementByIndex(index) {
|
|
4136
4154
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4141,7 +4159,11 @@
|
|
|
4141
4159
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4142
4160
|
unrender(item, itemEl);
|
|
4143
4161
|
} catch (err) {
|
|
4144
|
-
|
|
4162
|
+
reportError(p.onError, err, {
|
|
4163
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
4164
|
+
item,
|
|
4165
|
+
el: itemEl
|
|
4166
|
+
});
|
|
4145
4167
|
}
|
|
4146
4168
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(itemEl);
|
|
4147
4169
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4151,6 +4173,7 @@
|
|
|
4151
4173
|
/**
|
|
4152
4174
|
* @param {DropList.ItemBase} item
|
|
4153
4175
|
* @private
|
|
4176
|
+
* @internal
|
|
4154
4177
|
*/
|
|
4155
4178
|
_renderSingleItemContent(item) {
|
|
4156
4179
|
const p = this._p;
|
|
@@ -4165,6 +4188,7 @@
|
|
|
4165
4188
|
* @param {DropList.ItemBase} item
|
|
4166
4189
|
* @param {Element} itemEl
|
|
4167
4190
|
* @private
|
|
4191
|
+
* @internal
|
|
4168
4192
|
*/
|
|
4169
4193
|
_renderMultiItemContent(item, itemEl) {
|
|
4170
4194
|
const p = this._p;
|
|
@@ -4179,6 +4203,7 @@
|
|
|
4179
4203
|
* @param {DropList.ItemBase} item
|
|
4180
4204
|
* @returns {boolean} true if rendered, false if not
|
|
4181
4205
|
* @private
|
|
4206
|
+
* @internal
|
|
4182
4207
|
*/
|
|
4183
4208
|
_addMultiItemElement(item) {
|
|
4184
4209
|
const p = this._p;
|
|
@@ -4189,6 +4214,7 @@
|
|
|
4189
4214
|
return true;
|
|
4190
4215
|
}
|
|
4191
4216
|
/** @private */
|
|
4217
|
+
/** @internal */
|
|
4192
4218
|
_addMultiItemRestElement() {
|
|
4193
4219
|
const p = this._p;
|
|
4194
4220
|
let items = p.selectedItems.slice(0);
|
|
@@ -4201,6 +4227,7 @@
|
|
|
4201
4227
|
});
|
|
4202
4228
|
}
|
|
4203
4229
|
/** @private */
|
|
4230
|
+
/** @internal */
|
|
4204
4231
|
_syncClearButton() {
|
|
4205
4232
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4206
4233
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4223,6 +4250,7 @@
|
|
|
4223
4250
|
}
|
|
4224
4251
|
}
|
|
4225
4252
|
/** @private */
|
|
4253
|
+
/** @internal */
|
|
4226
4254
|
_syncPlaceholder() {
|
|
4227
4255
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4228
4256
|
let placeholder = "";
|
|
@@ -4234,6 +4262,7 @@
|
|
|
4234
4262
|
else p.input.removeAttribute("title");
|
|
4235
4263
|
}
|
|
4236
4264
|
/** @private */
|
|
4265
|
+
/** @internal */
|
|
4237
4266
|
_syncSingleItem() {
|
|
4238
4267
|
const p = this._p;
|
|
4239
4268
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4248,6 +4277,7 @@
|
|
|
4248
4277
|
* @param {boolean=false} fullItemsRender Should re-render all items?
|
|
4249
4278
|
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4250
4279
|
* @returns {SelectBox}
|
|
4280
|
+
* @internal
|
|
4251
4281
|
*/
|
|
4252
4282
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4253
4283
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4308,6 +4338,7 @@
|
|
|
4308
4338
|
* @param {string} event
|
|
4309
4339
|
* @param {*} [data]
|
|
4310
4340
|
* @private
|
|
4341
|
+
* @internal
|
|
4311
4342
|
*/
|
|
4312
4343
|
_trigger(event, data) {
|
|
4313
4344
|
const p = this._p;
|
|
@@ -4320,6 +4351,7 @@
|
|
|
4320
4351
|
* @param {Object} item
|
|
4321
4352
|
* @returns {Element|null}
|
|
4322
4353
|
* @private
|
|
4354
|
+
* @internal
|
|
4323
4355
|
*/
|
|
4324
4356
|
_renderMultiItem(item) {
|
|
4325
4357
|
const p = this._p;
|
|
@@ -4347,6 +4379,7 @@
|
|
|
4347
4379
|
* @param {Event} originatingEvent
|
|
4348
4380
|
* @returns {SelectBox}
|
|
4349
4381
|
* @private
|
|
4382
|
+
* @internal
|
|
4350
4383
|
*/
|
|
4351
4384
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4352
4385
|
const p = this._p;
|
|
@@ -4362,7 +4395,7 @@
|
|
|
4362
4395
|
let itemsToRemove = [];
|
|
4363
4396
|
for (let item of items) {
|
|
4364
4397
|
let removeselEvt = {
|
|
4365
|
-
value,
|
|
4398
|
+
value: item[p.valueProp],
|
|
4366
4399
|
item,
|
|
4367
4400
|
cancel: false
|
|
4368
4401
|
};
|
|
@@ -4373,7 +4406,7 @@
|
|
|
4373
4406
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4374
4407
|
for (let item of itemsToRemove) {
|
|
4375
4408
|
let idx = p.selectedItems.indexOf(item);
|
|
4376
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
4409
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4377
4410
|
if (idx !== -1) {
|
|
4378
4411
|
p.selectedItems.splice(idx, 1);
|
|
4379
4412
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4407,6 +4440,7 @@
|
|
|
4407
4440
|
* @param {DropList.ItemBase} item
|
|
4408
4441
|
* @param {boolean} [populate]
|
|
4409
4442
|
* @private
|
|
4443
|
+
* @internal
|
|
4410
4444
|
*/
|
|
4411
4445
|
_removeMultiItem(item, populate = false) {
|
|
4412
4446
|
const p = this._p;
|
|
@@ -4433,6 +4467,7 @@
|
|
|
4433
4467
|
/**
|
|
4434
4468
|
* @param {*} value
|
|
4435
4469
|
* @private
|
|
4470
|
+
* @internal
|
|
4436
4471
|
*/
|
|
4437
4472
|
_setInputText(value) {
|
|
4438
4473
|
const p = this._p;
|
|
@@ -4445,6 +4480,7 @@
|
|
|
4445
4480
|
* Update input size to current state
|
|
4446
4481
|
* @returns {SelectBox}
|
|
4447
4482
|
* @private
|
|
4483
|
+
* @internal
|
|
4448
4484
|
*/
|
|
4449
4485
|
_resizeInput() {
|
|
4450
4486
|
const p = this._p, el = p.el;
|
|
@@ -4502,6 +4538,7 @@
|
|
|
4502
4538
|
* Update autocomplete position if needed
|
|
4503
4539
|
* @returns {SelectBox}
|
|
4504
4540
|
* @private
|
|
4541
|
+
* @internal
|
|
4505
4542
|
*/
|
|
4506
4543
|
_repositionDropList() {
|
|
4507
4544
|
const p = this._p, el = p.el;
|
|
@@ -4517,6 +4554,7 @@
|
|
|
4517
4554
|
/**
|
|
4518
4555
|
* @param {KeyboardEvent} event
|
|
4519
4556
|
* @private
|
|
4557
|
+
* @internal
|
|
4520
4558
|
*/
|
|
4521
4559
|
_handleInputKeydown(event) {
|
|
4522
4560
|
const p = this._p;
|
|
@@ -4547,6 +4585,7 @@
|
|
|
4547
4585
|
/**
|
|
4548
4586
|
* @param {KeyboardEvent} event
|
|
4549
4587
|
* @private
|
|
4588
|
+
* @internal
|
|
4550
4589
|
*/
|
|
4551
4590
|
_handleMultiKeydown(event) {
|
|
4552
4591
|
const p = this._p;
|
|
@@ -4592,6 +4631,7 @@
|
|
|
4592
4631
|
/**
|
|
4593
4632
|
* @returns {DropList.PositionOptions}
|
|
4594
4633
|
* @private
|
|
4634
|
+
* @internal
|
|
4595
4635
|
*/
|
|
4596
4636
|
_getDropListPositionOptions() {
|
|
4597
4637
|
return {
|
|
@@ -4612,6 +4652,7 @@
|
|
|
4612
4652
|
};
|
|
4613
4653
|
}
|
|
4614
4654
|
/** @private */
|
|
4655
|
+
/** @internal */
|
|
4615
4656
|
_startTrackingPresence() {
|
|
4616
4657
|
const p = this._p;
|
|
4617
4658
|
this._stopTrackingPresence();
|
|
@@ -4620,6 +4661,7 @@
|
|
|
4620
4661
|
}, 200);
|
|
4621
4662
|
}
|
|
4622
4663
|
/** @private */
|
|
4664
|
+
/** @internal */
|
|
4623
4665
|
_stopTrackingPresence() {
|
|
4624
4666
|
const p = this._p;
|
|
4625
4667
|
if (p.presenceInt) {
|
|
@@ -4635,6 +4677,7 @@
|
|
|
4635
4677
|
* @param {boolean=false} sortCheckedFirst
|
|
4636
4678
|
* @param {boolean=false} splitCheckedGroups
|
|
4637
4679
|
* @returns {DropList.ItemBase[]}
|
|
4680
|
+
* @internal
|
|
4638
4681
|
*/
|
|
4639
4682
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4640
4683
|
const p = this._p;
|