@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.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,85 +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} [noResultsText='No matching results'] text for no results (empty for none)
|
|
90
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
91
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
92
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
93
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
94
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
95
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
96
|
-
* */
|
|
97
|
-
/** */
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
100
|
-
* @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`)
|
|
101
|
-
* @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`)
|
|
102
|
-
* */
|
|
103
|
-
/** */
|
|
104
|
-
/**
|
|
105
|
-
* @typedef {Object} DropList.PositionOptions
|
|
106
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
107
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
108
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
109
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
110
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
111
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
112
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
113
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
114
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
115
|
-
* */
|
|
116
|
-
/** */
|
|
117
|
-
/**
|
|
118
|
-
* @typedef {Object} DropList.ItemBase
|
|
119
|
-
* @property {string} [value]
|
|
120
|
-
* @property {string} [label]
|
|
121
|
-
* @property {boolean} [_group=false]
|
|
122
|
-
* @property {boolean} [_child=false]
|
|
123
|
-
* @property {boolean} [_nocheck=false]
|
|
124
|
-
* @property {boolean} [_nointeraction=false]
|
|
125
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
126
|
-
* */
|
|
127
|
-
/**
|
|
128
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
129
|
-
* @property {boolean} [_checked=false]
|
|
130
|
-
* */
|
|
131
|
-
/** */
|
|
132
|
-
/** @type {DropList.Options} */
|
|
133
82
|
var DefaultOptions = {
|
|
134
83
|
baseClassName: "droplist",
|
|
135
84
|
autoItemBlur: true,
|
|
@@ -150,6 +99,7 @@ var DefaultOptions = {
|
|
|
150
99
|
isHeaderVisible: false,
|
|
151
100
|
isFooterVisible: false,
|
|
152
101
|
searchable: false,
|
|
102
|
+
searchPlaceholder: "",
|
|
153
103
|
noResultsText: "No matching results",
|
|
154
104
|
filterThrottleWindow: 300,
|
|
155
105
|
filterOnEmptyTerm: false,
|
|
@@ -193,7 +143,9 @@ var DropList = class DropList {
|
|
|
193
143
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
194
144
|
on: o.on || null,
|
|
195
145
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
146
|
+
onError: o.onError,
|
|
196
147
|
searchable: o.searchable,
|
|
148
|
+
searchPlaceholder: o.searchPlaceholder,
|
|
197
149
|
isHeaderVisible: o.isHeaderVisible,
|
|
198
150
|
isFooterVisible: o.isFooterVisible,
|
|
199
151
|
silenceEvents: true,
|
|
@@ -209,7 +161,14 @@ var DropList = class DropList {
|
|
|
209
161
|
throttledRefilterItems: null,
|
|
210
162
|
focusItemIndex: -1,
|
|
211
163
|
focusItemEl: null,
|
|
212
|
-
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
|
|
213
172
|
};
|
|
214
173
|
let classes = [p.baseClassName + "_wrapper"];
|
|
215
174
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -275,7 +234,11 @@ var DropList = class DropList {
|
|
|
275
234
|
};
|
|
276
235
|
else item = items[index];
|
|
277
236
|
}
|
|
278
|
-
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
|
+
});
|
|
279
242
|
itemEl.className = `${p.baseClassName}__item`;
|
|
280
243
|
const classList = itemEl.classList;
|
|
281
244
|
if (item) {
|
|
@@ -433,6 +396,7 @@ var DropList = class DropList {
|
|
|
433
396
|
}
|
|
434
397
|
/**
|
|
435
398
|
* @private
|
|
399
|
+
* @internal
|
|
436
400
|
*/
|
|
437
401
|
_setupUnrenderFunction() {
|
|
438
402
|
const p = this._p;
|
|
@@ -444,12 +408,20 @@ var DropList = class DropList {
|
|
|
444
408
|
if (item === NoResultsItemSymbol) try {
|
|
445
409
|
fnNoResults(item, el);
|
|
446
410
|
} catch (err) {
|
|
447
|
-
|
|
411
|
+
reportError(p.onError, err, {
|
|
412
|
+
source: "unrenderNoResultsItem",
|
|
413
|
+
item,
|
|
414
|
+
el
|
|
415
|
+
});
|
|
448
416
|
}
|
|
449
417
|
else try {
|
|
450
418
|
fn(item[ItemSymbol], el);
|
|
451
419
|
} catch (err) {
|
|
452
|
-
|
|
420
|
+
reportError(p.onError, err, {
|
|
421
|
+
source: "unrenderItem",
|
|
422
|
+
item: item[ItemSymbol],
|
|
423
|
+
el
|
|
424
|
+
});
|
|
453
425
|
}
|
|
454
426
|
delete el[ItemSymbol];
|
|
455
427
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -469,6 +441,7 @@ var DropList = class DropList {
|
|
|
469
441
|
p.valueProp = prop;
|
|
470
442
|
return this;
|
|
471
443
|
}
|
|
444
|
+
/** @internal */
|
|
472
445
|
_syncBaseClasses() {
|
|
473
446
|
const p = this._p, el = p.el;
|
|
474
447
|
if (!el) return;
|
|
@@ -507,7 +480,7 @@ var DropList = class DropList {
|
|
|
507
480
|
goToLast(event) {
|
|
508
481
|
this._move("last", event);
|
|
509
482
|
}
|
|
510
|
-
toggleFocusedItem() {
|
|
483
|
+
toggleFocusedItem(event) {
|
|
511
484
|
const p = this._p;
|
|
512
485
|
if (this.hasFocusedItem() && p.multi) {
|
|
513
486
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -628,7 +601,7 @@ var DropList = class DropList {
|
|
|
628
601
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
629
602
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
630
603
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
631
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
604
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
632
605
|
if (p.multi) {
|
|
633
606
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
634
607
|
}
|
|
@@ -636,10 +609,10 @@ var DropList = class DropList {
|
|
|
636
609
|
if (!!newItem._group !== item._group) {
|
|
637
610
|
if (item._group) p.groupCount--;
|
|
638
611
|
else p.groupCount++;
|
|
639
|
-
|
|
612
|
+
item._group = !!newItem._group;
|
|
640
613
|
}
|
|
641
614
|
}
|
|
642
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
615
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
643
616
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
644
617
|
let virtualItemIndex = itemIndex;
|
|
645
618
|
if (p.filteredItems) {
|
|
@@ -786,6 +759,23 @@ var DropList = class DropList {
|
|
|
786
759
|
return this._p.positionOptionsProvider;
|
|
787
760
|
}
|
|
788
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
|
+
/**
|
|
789
779
|
* @param {string} term
|
|
790
780
|
* @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
|
|
791
781
|
* @returns {DropList}
|
|
@@ -806,6 +796,7 @@ var DropList = class DropList {
|
|
|
806
796
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
807
797
|
}
|
|
808
798
|
/** @private */
|
|
799
|
+
/** @internal */
|
|
809
800
|
_refilterItems() {
|
|
810
801
|
const p = this._p;
|
|
811
802
|
const term = p.filterTerm;
|
|
@@ -840,7 +831,7 @@ var DropList = class DropList {
|
|
|
840
831
|
});
|
|
841
832
|
}
|
|
842
833
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
843
|
-
const matcher = new RegExp(
|
|
834
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
844
835
|
filteredItems = p.items.filter((x) => {
|
|
845
836
|
if (!filterGroups && x._group) return true;
|
|
846
837
|
return matcher.test(x.label);
|
|
@@ -917,7 +908,7 @@ var DropList = class DropList {
|
|
|
917
908
|
p.filterThrottleWindow = window;
|
|
918
909
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
919
910
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
920
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
911
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
921
912
|
if (isScheduled) p.throttledRefilterItems();
|
|
922
913
|
return this;
|
|
923
914
|
}
|
|
@@ -1260,7 +1251,7 @@ var DropList = class DropList {
|
|
|
1260
1251
|
if (this.isVisible()) this._trigger("show");
|
|
1261
1252
|
return this;
|
|
1262
1253
|
}
|
|
1263
|
-
hide() {
|
|
1254
|
+
hide(event) {
|
|
1264
1255
|
const p = this._p, el = p.el;
|
|
1265
1256
|
if (p.onDocumentMouseDown) {
|
|
1266
1257
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1372,7 +1363,8 @@ var DropList = class DropList {
|
|
|
1372
1363
|
autocomplete: "off",
|
|
1373
1364
|
autocapitalize: "off",
|
|
1374
1365
|
spellcheck: "false",
|
|
1375
|
-
"aria-autocomplete": "list"
|
|
1366
|
+
"aria-autocomplete": "list",
|
|
1367
|
+
placeholder: p.searchPlaceholder || ""
|
|
1376
1368
|
});
|
|
1377
1369
|
p.headerEl.appendChild(p.searchInput);
|
|
1378
1370
|
} else {
|
|
@@ -1381,6 +1373,15 @@ var DropList = class DropList {
|
|
|
1381
1373
|
}
|
|
1382
1374
|
this.setHeaderVisible(searchable);
|
|
1383
1375
|
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Set the placeholder text of the inline search box
|
|
1378
|
+
* @param {string} placeholder
|
|
1379
|
+
*/
|
|
1380
|
+
setSearchPlaceholder(placeholder) {
|
|
1381
|
+
const p = this._p;
|
|
1382
|
+
p.searchPlaceholder = placeholder || "";
|
|
1383
|
+
if (p.searchInput) p.searchInput.placeholder = p.searchPlaceholder;
|
|
1384
|
+
}
|
|
1384
1385
|
hasFocusedItem() {
|
|
1385
1386
|
return this._p.focusItemIndex > -1 && this._p.focusItemIndex < this._p.items.length;
|
|
1386
1387
|
}
|
|
@@ -1422,6 +1423,7 @@ var DropList = class DropList {
|
|
|
1422
1423
|
}
|
|
1423
1424
|
return this;
|
|
1424
1425
|
}
|
|
1426
|
+
/** @internal */
|
|
1425
1427
|
_showSublist(item, itemElement) {
|
|
1426
1428
|
if (!item._subitems?.length) return;
|
|
1427
1429
|
const p = this._p;
|
|
@@ -1497,6 +1499,7 @@ var DropList = class DropList {
|
|
|
1497
1499
|
droplist.show();
|
|
1498
1500
|
droplist.el.focus();
|
|
1499
1501
|
}
|
|
1502
|
+
/** @internal */
|
|
1500
1503
|
_hideSublist() {
|
|
1501
1504
|
const p = this._p;
|
|
1502
1505
|
if (!p.currentSubDropList) return;
|
|
@@ -1596,6 +1599,7 @@ var DropList = class DropList {
|
|
|
1596
1599
|
}
|
|
1597
1600
|
return this;
|
|
1598
1601
|
}
|
|
1602
|
+
/** @internal */
|
|
1599
1603
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1600
1604
|
const p = this._p;
|
|
1601
1605
|
if (this._hasScroll()) {
|
|
@@ -1659,6 +1663,7 @@ var DropList = class DropList {
|
|
|
1659
1663
|
this._p.mitt.emit(event, value);
|
|
1660
1664
|
return this;
|
|
1661
1665
|
}
|
|
1666
|
+
/** @internal */
|
|
1662
1667
|
_getItemIndex(item) {
|
|
1663
1668
|
const p = this._p;
|
|
1664
1669
|
let itemIndex = -1;
|
|
@@ -1672,6 +1677,7 @@ var DropList = class DropList {
|
|
|
1672
1677
|
}
|
|
1673
1678
|
return itemIndex;
|
|
1674
1679
|
}
|
|
1680
|
+
/** @internal */
|
|
1675
1681
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1676
1682
|
const p = this._p;
|
|
1677
1683
|
if (p.singleSelectedItemEl) {
|
|
@@ -1689,12 +1695,14 @@ var DropList = class DropList {
|
|
|
1689
1695
|
* @param {string} event
|
|
1690
1696
|
* @param {*} [data]
|
|
1691
1697
|
* @private
|
|
1698
|
+
* @internal
|
|
1692
1699
|
*/
|
|
1693
1700
|
_trigger(event, data) {
|
|
1694
1701
|
const p = this._p;
|
|
1695
1702
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1696
1703
|
p.mitt.emit(event, data);
|
|
1697
1704
|
}
|
|
1705
|
+
/** @internal */
|
|
1698
1706
|
_itemUpAction(event, itemEl) {
|
|
1699
1707
|
if (closestUntil(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1700
1708
|
let p = this._p;
|
|
@@ -1707,6 +1715,7 @@ var DropList = class DropList {
|
|
|
1707
1715
|
}, 0);
|
|
1708
1716
|
}
|
|
1709
1717
|
}
|
|
1718
|
+
/** @internal */
|
|
1710
1719
|
_hookMouseEvents() {
|
|
1711
1720
|
const p = this._p;
|
|
1712
1721
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1720,9 +1729,11 @@ var DropList = class DropList {
|
|
|
1720
1729
|
this._handleMouseOver(event, li);
|
|
1721
1730
|
});
|
|
1722
1731
|
}
|
|
1732
|
+
/** @internal */
|
|
1723
1733
|
_handleMouseOver(event, itemEl) {
|
|
1724
1734
|
this._focus(event, itemEl, null, true);
|
|
1725
1735
|
}
|
|
1736
|
+
/** @internal */
|
|
1726
1737
|
_hookTouchEvents() {
|
|
1727
1738
|
const p = this._p;
|
|
1728
1739
|
let currentTouchId;
|
|
@@ -1762,6 +1773,7 @@ var DropList = class DropList {
|
|
|
1762
1773
|
});
|
|
1763
1774
|
});
|
|
1764
1775
|
}
|
|
1776
|
+
/** @internal */
|
|
1765
1777
|
_hookFocusEvents() {
|
|
1766
1778
|
const p = this._p;
|
|
1767
1779
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1779,10 +1791,12 @@ var DropList = class DropList {
|
|
|
1779
1791
|
});
|
|
1780
1792
|
}, true);
|
|
1781
1793
|
}
|
|
1794
|
+
/** @internal */
|
|
1782
1795
|
_hookKeyEvents() {
|
|
1783
1796
|
const p = this._p;
|
|
1784
1797
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1785
1798
|
}
|
|
1799
|
+
/** @internal */
|
|
1786
1800
|
_hookSearchEvents() {
|
|
1787
1801
|
const p = this._p;
|
|
1788
1802
|
if (!p.searchInput) return;
|
|
@@ -1793,6 +1807,7 @@ var DropList = class DropList {
|
|
|
1793
1807
|
p.throttledRefilterItems();
|
|
1794
1808
|
});
|
|
1795
1809
|
}
|
|
1810
|
+
/** @internal */
|
|
1796
1811
|
_keydown(event) {
|
|
1797
1812
|
const p = this._p;
|
|
1798
1813
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1855,6 +1870,7 @@ var DropList = class DropList {
|
|
|
1855
1870
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1856
1871
|
}
|
|
1857
1872
|
}
|
|
1873
|
+
/** @internal */
|
|
1858
1874
|
_keydownFreeType(evt, autoSelect) {
|
|
1859
1875
|
const p = this._p;
|
|
1860
1876
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1863,7 +1879,7 @@ var DropList = class DropList {
|
|
|
1863
1879
|
if (!isChar) return;
|
|
1864
1880
|
clearTimeout(p.filterTimer);
|
|
1865
1881
|
let keyword = (p.previousFilter || "") + character;
|
|
1866
|
-
let regex = new RegExp(`^${
|
|
1882
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1867
1883
|
let matchIndex = -1;
|
|
1868
1884
|
let item;
|
|
1869
1885
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1878,7 +1894,7 @@ var DropList = class DropList {
|
|
|
1878
1894
|
}
|
|
1879
1895
|
if (matchIndex === -1) {
|
|
1880
1896
|
keyword = character;
|
|
1881
|
-
regex = new RegExp(`^${
|
|
1897
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1882
1898
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1883
1899
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1884
1900
|
item = items[i];
|
|
@@ -1898,6 +1914,7 @@ var DropList = class DropList {
|
|
|
1898
1914
|
}, 1e3);
|
|
1899
1915
|
} else delete p.previousFilter;
|
|
1900
1916
|
}
|
|
1917
|
+
/** @internal */
|
|
1901
1918
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1902
1919
|
const p = this._p;
|
|
1903
1920
|
if (p._isFocusingItem) return;
|
|
@@ -1931,6 +1948,7 @@ var DropList = class DropList {
|
|
|
1931
1948
|
p._isFocusingItem = false;
|
|
1932
1949
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1933
1950
|
}
|
|
1951
|
+
/** @internal */
|
|
1934
1952
|
_delayBlurItemOnBlur() {
|
|
1935
1953
|
if (this[DestroyedSymbol$1]) return;
|
|
1936
1954
|
const p = this._p;
|
|
@@ -1941,6 +1959,7 @@ var DropList = class DropList {
|
|
|
1941
1959
|
this.blurFocusedItem();
|
|
1942
1960
|
}, p.autoItemBlurDelay);
|
|
1943
1961
|
}
|
|
1962
|
+
/** @internal */
|
|
1944
1963
|
_move(direction, event) {
|
|
1945
1964
|
const p = this._p;
|
|
1946
1965
|
let next, nextIndex, directionUp;
|
|
@@ -2010,10 +2029,12 @@ var DropList = class DropList {
|
|
|
2010
2029
|
this._focus(event, next || null, nextIndex, false);
|
|
2011
2030
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2012
2031
|
}
|
|
2032
|
+
/** @internal */
|
|
2013
2033
|
_hasScroll() {
|
|
2014
2034
|
const menuEl = this._p.menuEl;
|
|
2015
2035
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2016
2036
|
}
|
|
2037
|
+
/** @internal */
|
|
2017
2038
|
_updateGroupStateForItem(item) {
|
|
2018
2039
|
const p = this._p;
|
|
2019
2040
|
if (!p.multi) return this;
|
|
@@ -2057,6 +2078,7 @@ var DropList = class DropList {
|
|
|
2057
2078
|
}
|
|
2058
2079
|
return this;
|
|
2059
2080
|
}
|
|
2081
|
+
/** @internal */
|
|
2060
2082
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2061
2083
|
const p = this._p;
|
|
2062
2084
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2090,6 +2112,7 @@ var DropList = class DropList {
|
|
|
2090
2112
|
/**
|
|
2091
2113
|
* @private
|
|
2092
2114
|
* @returns {DropList} self
|
|
2115
|
+
* @internal
|
|
2093
2116
|
*/
|
|
2094
2117
|
_measureItem() {
|
|
2095
2118
|
const p = this._p;
|
|
@@ -2137,6 +2160,7 @@ var DropList = class DropList {
|
|
|
2137
2160
|
* @param {number?} targetItemCount - item count we are expecting. Defaults to current item count
|
|
2138
2161
|
* @returns {DropList}
|
|
2139
2162
|
* @private
|
|
2163
|
+
* @internal
|
|
2140
2164
|
*/
|
|
2141
2165
|
_determineVirtualMode(targetItemCount) {
|
|
2142
2166
|
const p = this._p;
|
|
@@ -2146,6 +2170,7 @@ var DropList = class DropList {
|
|
|
2146
2170
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2147
2171
|
return this;
|
|
2148
2172
|
}
|
|
2173
|
+
/** @internal */
|
|
2149
2174
|
_renderItemContent(item, itemEl) {
|
|
2150
2175
|
const p = this._p;
|
|
2151
2176
|
const originalItem = item[ItemSymbol];
|
|
@@ -2167,17 +2192,12 @@ var DropList = class DropList {
|
|
|
2167
2192
|
}
|
|
2168
2193
|
}
|
|
2169
2194
|
}
|
|
2170
|
-
/**
|
|
2171
|
-
*
|
|
2172
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2173
|
-
* @returns {number} new outer width
|
|
2174
|
-
* @private
|
|
2175
|
-
*/
|
|
2195
|
+
/** @internal */
|
|
2176
2196
|
_updateWidth(positionOptions) {
|
|
2177
2197
|
const p = this._p, el = p.el;
|
|
2178
2198
|
let targetWidth = 0;
|
|
2179
2199
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2180
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2200
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2181
2201
|
else targetWidth = getElementWidth(positionOptions.target, true, true);
|
|
2182
2202
|
let autoWidth = 0;
|
|
2183
2203
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2199,7 +2219,7 @@ var DropList = class DropList {
|
|
|
2199
2219
|
}
|
|
2200
2220
|
};
|
|
2201
2221
|
//#endregion
|
|
2202
|
-
//#region lib/SelectBox.
|
|
2222
|
+
//#region src/lib/SelectBox.ts
|
|
2203
2223
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2204
2224
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2205
2225
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2225,57 +2245,6 @@ var inputBackbufferCssProps = [
|
|
|
2225
2245
|
"padding-left",
|
|
2226
2246
|
"padding-right"
|
|
2227
2247
|
];
|
|
2228
|
-
/**
|
|
2229
|
-
* @typedef {Object} SelectBox.Options
|
|
2230
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2231
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2232
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2233
|
-
* @property {string|string[]} [additionalClasses]
|
|
2234
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2235
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2236
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2237
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2238
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2239
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2240
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2241
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2242
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2243
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2244
|
-
* @property {*[]} [stickyValues]
|
|
2245
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2246
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2247
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2248
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2249
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2250
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2251
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2252
|
-
* @property {string} [labelProp='label']
|
|
2253
|
-
* @property {string} [valueProp='value']
|
|
2254
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2255
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2256
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2257
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2258
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2259
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2260
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2261
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2262
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2263
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2264
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2265
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2266
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2267
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2268
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2269
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2270
|
-
* @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.
|
|
2271
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2272
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2273
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2274
|
-
* @property {function(name: string, ...args)} [on]
|
|
2275
|
-
* @property {boolean} [isLoadingMode]
|
|
2276
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2277
|
-
* @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>
|
|
2278
|
-
* */
|
|
2279
2248
|
var DefaultOptions$1 = {
|
|
2280
2249
|
el: null,
|
|
2281
2250
|
baseClassName: "selectbox",
|
|
@@ -2394,6 +2363,7 @@ var SelectBox = class {
|
|
|
2394
2363
|
on: o.on || null,
|
|
2395
2364
|
silenceEvents: true,
|
|
2396
2365
|
mitt: mitt(),
|
|
2366
|
+
onError: o.onError,
|
|
2397
2367
|
isLoadingMode: !!o.isLoadingMode,
|
|
2398
2368
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2399
2369
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2409,7 +2379,11 @@ var SelectBox = class {
|
|
|
2409
2379
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2410
2380
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2411
2381
|
filterFn: null,
|
|
2412
|
-
filterTerm: ""
|
|
2382
|
+
filterTerm: "",
|
|
2383
|
+
dropListVisible: false,
|
|
2384
|
+
lastActiveElement: null,
|
|
2385
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2386
|
+
presenceInt: null
|
|
2413
2387
|
};
|
|
2414
2388
|
let el = o.el;
|
|
2415
2389
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -3147,7 +3121,7 @@ var SelectBox = class {
|
|
|
3147
3121
|
if (p.filterFn === fn) return this;
|
|
3148
3122
|
p.filterFn = fn;
|
|
3149
3123
|
if (!fn) fn = (items, term) => {
|
|
3150
|
-
const matcher = new RegExp(
|
|
3124
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3151
3125
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3152
3126
|
return p.items.filter((x) => {
|
|
3153
3127
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3165,6 +3139,25 @@ var SelectBox = class {
|
|
|
3165
3139
|
return this._p.filterFn;
|
|
3166
3140
|
}
|
|
3167
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
|
+
/**
|
|
3168
3161
|
* Focus on input element
|
|
3169
3162
|
* @returns {SelectBox}
|
|
3170
3163
|
*/
|
|
@@ -3453,6 +3446,7 @@ var SelectBox = class {
|
|
|
3453
3446
|
* Prepare the mapping between values and items.
|
|
3454
3447
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3455
3448
|
* @private
|
|
3449
|
+
* @internal
|
|
3456
3450
|
*/
|
|
3457
3451
|
_refreshItemByValueMap() {
|
|
3458
3452
|
const p = this._p;
|
|
@@ -3465,6 +3459,7 @@ var SelectBox = class {
|
|
|
3465
3459
|
* @param {*} value
|
|
3466
3460
|
* @returns {DropList.ItemBase|undefined}
|
|
3467
3461
|
* @private
|
|
3462
|
+
* @internal
|
|
3468
3463
|
*/
|
|
3469
3464
|
_getItemByValue(value) {
|
|
3470
3465
|
const p = this._p;
|
|
@@ -3474,6 +3469,7 @@ var SelectBox = class {
|
|
|
3474
3469
|
return p.subitemByValueMap.get(value);
|
|
3475
3470
|
}
|
|
3476
3471
|
/** @private */
|
|
3472
|
+
/** @internal */
|
|
3477
3473
|
_refreshSubitemByValueMap() {
|
|
3478
3474
|
const p = this._p;
|
|
3479
3475
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
@@ -3484,6 +3480,7 @@ var SelectBox = class {
|
|
|
3484
3480
|
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3485
3481
|
* @param {string} valueProp
|
|
3486
3482
|
* @private
|
|
3483
|
+
* @internal
|
|
3487
3484
|
*/
|
|
3488
3485
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3489
3486
|
for (let item of items) {
|
|
@@ -3493,6 +3490,7 @@ var SelectBox = class {
|
|
|
3493
3490
|
}
|
|
3494
3491
|
}
|
|
3495
3492
|
/** @private */
|
|
3493
|
+
/** @internal */
|
|
3496
3494
|
_renderBase() {
|
|
3497
3495
|
const p = this._p;
|
|
3498
3496
|
if (!p.inputBackBuffer) p.inputBackBuffer = createElement("span", { css: {
|
|
@@ -3581,6 +3579,7 @@ var SelectBox = class {
|
|
|
3581
3579
|
}
|
|
3582
3580
|
/**
|
|
3583
3581
|
* @private
|
|
3582
|
+
* @internal
|
|
3584
3583
|
*/
|
|
3585
3584
|
_syncBaseClasses() {
|
|
3586
3585
|
const p = this._p, el = p.el;
|
|
@@ -3601,6 +3600,7 @@ var SelectBox = class {
|
|
|
3601
3600
|
el.className = classes.join(" ");
|
|
3602
3601
|
}
|
|
3603
3602
|
/** @private */
|
|
3603
|
+
/** @internal */
|
|
3604
3604
|
_setupDropdownMenu() {
|
|
3605
3605
|
const p = this._p;
|
|
3606
3606
|
p.valueProp;
|
|
@@ -3630,6 +3630,7 @@ var SelectBox = class {
|
|
|
3630
3630
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3631
3631
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3632
3632
|
filterFn: p.actualFilterFn,
|
|
3633
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3633
3634
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3634
3635
|
on: (name, event) => {
|
|
3635
3636
|
switch (name) {
|
|
@@ -3765,6 +3766,7 @@ var SelectBox = class {
|
|
|
3765
3766
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3766
3767
|
this._registerDropdownEvents();
|
|
3767
3768
|
}
|
|
3769
|
+
/** @internal */
|
|
3768
3770
|
_handleOnBlur() {
|
|
3769
3771
|
const p = this._p;
|
|
3770
3772
|
setTimeout(() => {
|
|
@@ -3776,9 +3778,11 @@ var SelectBox = class {
|
|
|
3776
3778
|
this.closeList();
|
|
3777
3779
|
});
|
|
3778
3780
|
}
|
|
3781
|
+
/** @internal */
|
|
3779
3782
|
_unregisterDropdownEvents() {
|
|
3780
3783
|
this._p.sink.remove(null, ".dropdown");
|
|
3781
3784
|
}
|
|
3785
|
+
/** @internal */
|
|
3782
3786
|
_registerDropdownEvents() {
|
|
3783
3787
|
const p = this._p;
|
|
3784
3788
|
this._unregisterDropdownEvents();
|
|
@@ -3916,6 +3920,7 @@ var SelectBox = class {
|
|
|
3916
3920
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3917
3921
|
});
|
|
3918
3922
|
}
|
|
3923
|
+
/** @internal */
|
|
3919
3924
|
_performSelectWithEvent(item, value) {
|
|
3920
3925
|
let cancellable = {
|
|
3921
3926
|
value,
|
|
@@ -3932,6 +3937,7 @@ var SelectBox = class {
|
|
|
3932
3937
|
});
|
|
3933
3938
|
return true;
|
|
3934
3939
|
}
|
|
3940
|
+
/** @internal */
|
|
3935
3941
|
_performClearWithEvent(clearInput = false) {
|
|
3936
3942
|
let cancellable = { cancel: false };
|
|
3937
3943
|
this._trigger("clear:before", cancellable);
|
|
@@ -3942,6 +3948,7 @@ var SelectBox = class {
|
|
|
3942
3948
|
this._trigger("clear");
|
|
3943
3949
|
return true;
|
|
3944
3950
|
}
|
|
3951
|
+
/** @internal */
|
|
3945
3952
|
_movePrev() {
|
|
3946
3953
|
const p = this._p;
|
|
3947
3954
|
if (this.isMultiEnabled()) return;
|
|
@@ -3955,6 +3962,7 @@ var SelectBox = class {
|
|
|
3955
3962
|
else this._performClearWithEvent();
|
|
3956
3963
|
}
|
|
3957
3964
|
}
|
|
3965
|
+
/** @internal */
|
|
3958
3966
|
_moveNext() {
|
|
3959
3967
|
const p = this._p;
|
|
3960
3968
|
if (this.isMultiEnabled()) return;
|
|
@@ -3969,6 +3977,7 @@ var SelectBox = class {
|
|
|
3969
3977
|
}
|
|
3970
3978
|
}
|
|
3971
3979
|
/** @private */
|
|
3980
|
+
/** @internal */
|
|
3972
3981
|
_updateListItems() {
|
|
3973
3982
|
const p = this._p;
|
|
3974
3983
|
const dropList = p.dropList;
|
|
@@ -3998,6 +4007,7 @@ var SelectBox = class {
|
|
|
3998
4007
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
3999
4008
|
}
|
|
4000
4009
|
/** @private */
|
|
4010
|
+
/** @internal */
|
|
4001
4011
|
_setSelectedItems(items) {
|
|
4002
4012
|
const p = this._p, valueProp = p.valueProp;
|
|
4003
4013
|
if (p.multi) {
|
|
@@ -4013,6 +4023,7 @@ var SelectBox = class {
|
|
|
4013
4023
|
this._scheduleSync("full");
|
|
4014
4024
|
}
|
|
4015
4025
|
/** @private */
|
|
4026
|
+
/** @internal */
|
|
4016
4027
|
_scheduleSync(mode, data) {
|
|
4017
4028
|
const p = this._p;
|
|
4018
4029
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4030,6 +4041,7 @@ var SelectBox = class {
|
|
|
4030
4041
|
});
|
|
4031
4042
|
}
|
|
4032
4043
|
/** @private */
|
|
4044
|
+
/** @internal */
|
|
4033
4045
|
_performSync(queue) {
|
|
4034
4046
|
const p = this._p;
|
|
4035
4047
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4083,13 +4095,18 @@ var SelectBox = class {
|
|
|
4083
4095
|
}
|
|
4084
4096
|
}
|
|
4085
4097
|
/** @private */
|
|
4098
|
+
/** @internal */
|
|
4086
4099
|
_cleanupSingleWrapper() {
|
|
4087
4100
|
const p = this._p;
|
|
4088
4101
|
if (!p.singleWrapper) return;
|
|
4089
4102
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4090
4103
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4091
4104
|
} catch (err) {
|
|
4092
|
-
|
|
4105
|
+
reportError(p.onError, err, {
|
|
4106
|
+
source: "unrenderSingleItem",
|
|
4107
|
+
item: p.singleWrapper[ItemSymbol],
|
|
4108
|
+
el: p.singleWrapper
|
|
4109
|
+
});
|
|
4093
4110
|
}
|
|
4094
4111
|
delete p.singleWrapper[ItemSymbol];
|
|
4095
4112
|
p.singleWrapper.innerHTML = "";
|
|
@@ -4097,6 +4114,7 @@ var SelectBox = class {
|
|
|
4097
4114
|
/**
|
|
4098
4115
|
* @param {number} index
|
|
4099
4116
|
* @private
|
|
4117
|
+
* @internal
|
|
4100
4118
|
*/
|
|
4101
4119
|
_removeMultiItemElementByIndex(index) {
|
|
4102
4120
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4107,7 +4125,11 @@ var SelectBox = class {
|
|
|
4107
4125
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4108
4126
|
unrender(item, itemEl);
|
|
4109
4127
|
} catch (err) {
|
|
4110
|
-
|
|
4128
|
+
reportError(p.onError, err, {
|
|
4129
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
4130
|
+
item,
|
|
4131
|
+
el: itemEl
|
|
4132
|
+
});
|
|
4111
4133
|
}
|
|
4112
4134
|
remove(itemEl);
|
|
4113
4135
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4117,6 +4139,7 @@ var SelectBox = class {
|
|
|
4117
4139
|
/**
|
|
4118
4140
|
* @param {DropList.ItemBase} item
|
|
4119
4141
|
* @private
|
|
4142
|
+
* @internal
|
|
4120
4143
|
*/
|
|
4121
4144
|
_renderSingleItemContent(item) {
|
|
4122
4145
|
const p = this._p;
|
|
@@ -4131,6 +4154,7 @@ var SelectBox = class {
|
|
|
4131
4154
|
* @param {DropList.ItemBase} item
|
|
4132
4155
|
* @param {Element} itemEl
|
|
4133
4156
|
* @private
|
|
4157
|
+
* @internal
|
|
4134
4158
|
*/
|
|
4135
4159
|
_renderMultiItemContent(item, itemEl) {
|
|
4136
4160
|
const p = this._p;
|
|
@@ -4145,6 +4169,7 @@ var SelectBox = class {
|
|
|
4145
4169
|
* @param {DropList.ItemBase} item
|
|
4146
4170
|
* @returns {boolean} true if rendered, false if not
|
|
4147
4171
|
* @private
|
|
4172
|
+
* @internal
|
|
4148
4173
|
*/
|
|
4149
4174
|
_addMultiItemElement(item) {
|
|
4150
4175
|
const p = this._p;
|
|
@@ -4155,6 +4180,7 @@ var SelectBox = class {
|
|
|
4155
4180
|
return true;
|
|
4156
4181
|
}
|
|
4157
4182
|
/** @private */
|
|
4183
|
+
/** @internal */
|
|
4158
4184
|
_addMultiItemRestElement() {
|
|
4159
4185
|
const p = this._p;
|
|
4160
4186
|
let items = p.selectedItems.slice(0);
|
|
@@ -4167,6 +4193,7 @@ var SelectBox = class {
|
|
|
4167
4193
|
});
|
|
4168
4194
|
}
|
|
4169
4195
|
/** @private */
|
|
4196
|
+
/** @internal */
|
|
4170
4197
|
_syncClearButton() {
|
|
4171
4198
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4172
4199
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4189,6 +4216,7 @@ var SelectBox = class {
|
|
|
4189
4216
|
}
|
|
4190
4217
|
}
|
|
4191
4218
|
/** @private */
|
|
4219
|
+
/** @internal */
|
|
4192
4220
|
_syncPlaceholder() {
|
|
4193
4221
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4194
4222
|
let placeholder = "";
|
|
@@ -4200,6 +4228,7 @@ var SelectBox = class {
|
|
|
4200
4228
|
else p.input.removeAttribute("title");
|
|
4201
4229
|
}
|
|
4202
4230
|
/** @private */
|
|
4231
|
+
/** @internal */
|
|
4203
4232
|
_syncSingleItem() {
|
|
4204
4233
|
const p = this._p;
|
|
4205
4234
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4214,6 +4243,7 @@ var SelectBox = class {
|
|
|
4214
4243
|
* @param {boolean=false} fullItemsRender Should re-render all items?
|
|
4215
4244
|
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4216
4245
|
* @returns {SelectBox}
|
|
4246
|
+
* @internal
|
|
4217
4247
|
*/
|
|
4218
4248
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4219
4249
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4274,6 +4304,7 @@ var SelectBox = class {
|
|
|
4274
4304
|
* @param {string} event
|
|
4275
4305
|
* @param {*} [data]
|
|
4276
4306
|
* @private
|
|
4307
|
+
* @internal
|
|
4277
4308
|
*/
|
|
4278
4309
|
_trigger(event, data) {
|
|
4279
4310
|
const p = this._p;
|
|
@@ -4286,6 +4317,7 @@ var SelectBox = class {
|
|
|
4286
4317
|
* @param {Object} item
|
|
4287
4318
|
* @returns {Element|null}
|
|
4288
4319
|
* @private
|
|
4320
|
+
* @internal
|
|
4289
4321
|
*/
|
|
4290
4322
|
_renderMultiItem(item) {
|
|
4291
4323
|
const p = this._p;
|
|
@@ -4313,6 +4345,7 @@ var SelectBox = class {
|
|
|
4313
4345
|
* @param {Event} originatingEvent
|
|
4314
4346
|
* @returns {SelectBox}
|
|
4315
4347
|
* @private
|
|
4348
|
+
* @internal
|
|
4316
4349
|
*/
|
|
4317
4350
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4318
4351
|
const p = this._p;
|
|
@@ -4328,7 +4361,7 @@ var SelectBox = class {
|
|
|
4328
4361
|
let itemsToRemove = [];
|
|
4329
4362
|
for (let item of items) {
|
|
4330
4363
|
let removeselEvt = {
|
|
4331
|
-
value,
|
|
4364
|
+
value: item[p.valueProp],
|
|
4332
4365
|
item,
|
|
4333
4366
|
cancel: false
|
|
4334
4367
|
};
|
|
@@ -4339,7 +4372,7 @@ var SelectBox = class {
|
|
|
4339
4372
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4340
4373
|
for (let item of itemsToRemove) {
|
|
4341
4374
|
let idx = p.selectedItems.indexOf(item);
|
|
4342
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
4375
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4343
4376
|
if (idx !== -1) {
|
|
4344
4377
|
p.selectedItems.splice(idx, 1);
|
|
4345
4378
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4373,6 +4406,7 @@ var SelectBox = class {
|
|
|
4373
4406
|
* @param {DropList.ItemBase} item
|
|
4374
4407
|
* @param {boolean} [populate]
|
|
4375
4408
|
* @private
|
|
4409
|
+
* @internal
|
|
4376
4410
|
*/
|
|
4377
4411
|
_removeMultiItem(item, populate = false) {
|
|
4378
4412
|
const p = this._p;
|
|
@@ -4399,6 +4433,7 @@ var SelectBox = class {
|
|
|
4399
4433
|
/**
|
|
4400
4434
|
* @param {*} value
|
|
4401
4435
|
* @private
|
|
4436
|
+
* @internal
|
|
4402
4437
|
*/
|
|
4403
4438
|
_setInputText(value) {
|
|
4404
4439
|
const p = this._p;
|
|
@@ -4411,6 +4446,7 @@ var SelectBox = class {
|
|
|
4411
4446
|
* Update input size to current state
|
|
4412
4447
|
* @returns {SelectBox}
|
|
4413
4448
|
* @private
|
|
4449
|
+
* @internal
|
|
4414
4450
|
*/
|
|
4415
4451
|
_resizeInput() {
|
|
4416
4452
|
const p = this._p, el = p.el;
|
|
@@ -4468,6 +4504,7 @@ var SelectBox = class {
|
|
|
4468
4504
|
* Update autocomplete position if needed
|
|
4469
4505
|
* @returns {SelectBox}
|
|
4470
4506
|
* @private
|
|
4507
|
+
* @internal
|
|
4471
4508
|
*/
|
|
4472
4509
|
_repositionDropList() {
|
|
4473
4510
|
const p = this._p, el = p.el;
|
|
@@ -4483,6 +4520,7 @@ var SelectBox = class {
|
|
|
4483
4520
|
/**
|
|
4484
4521
|
* @param {KeyboardEvent} event
|
|
4485
4522
|
* @private
|
|
4523
|
+
* @internal
|
|
4486
4524
|
*/
|
|
4487
4525
|
_handleInputKeydown(event) {
|
|
4488
4526
|
const p = this._p;
|
|
@@ -4513,6 +4551,7 @@ var SelectBox = class {
|
|
|
4513
4551
|
/**
|
|
4514
4552
|
* @param {KeyboardEvent} event
|
|
4515
4553
|
* @private
|
|
4554
|
+
* @internal
|
|
4516
4555
|
*/
|
|
4517
4556
|
_handleMultiKeydown(event) {
|
|
4518
4557
|
const p = this._p;
|
|
@@ -4558,6 +4597,7 @@ var SelectBox = class {
|
|
|
4558
4597
|
/**
|
|
4559
4598
|
* @returns {DropList.PositionOptions}
|
|
4560
4599
|
* @private
|
|
4600
|
+
* @internal
|
|
4561
4601
|
*/
|
|
4562
4602
|
_getDropListPositionOptions() {
|
|
4563
4603
|
return {
|
|
@@ -4578,6 +4618,7 @@ var SelectBox = class {
|
|
|
4578
4618
|
};
|
|
4579
4619
|
}
|
|
4580
4620
|
/** @private */
|
|
4621
|
+
/** @internal */
|
|
4581
4622
|
_startTrackingPresence() {
|
|
4582
4623
|
const p = this._p;
|
|
4583
4624
|
this._stopTrackingPresence();
|
|
@@ -4586,6 +4627,7 @@ var SelectBox = class {
|
|
|
4586
4627
|
}, 200);
|
|
4587
4628
|
}
|
|
4588
4629
|
/** @private */
|
|
4630
|
+
/** @internal */
|
|
4589
4631
|
_stopTrackingPresence() {
|
|
4590
4632
|
const p = this._p;
|
|
4591
4633
|
if (p.presenceInt) {
|
|
@@ -4601,6 +4643,7 @@ var SelectBox = class {
|
|
|
4601
4643
|
* @param {boolean=false} sortCheckedFirst
|
|
4602
4644
|
* @param {boolean=false} splitCheckedGroups
|
|
4603
4645
|
* @returns {DropList.ItemBase[]}
|
|
4646
|
+
* @internal
|
|
4604
4647
|
*/
|
|
4605
4648
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4606
4649
|
const p = this._p;
|