@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.cjs.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
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -35,14 +35,18 @@ _danielgindi_virtual_list_helper = __toESM(_danielgindi_virtual_list_helper);
|
|
|
35
35
|
let keycode_js = require("keycode-js");
|
|
36
36
|
let mitt = require("mitt");
|
|
37
37
|
mitt = __toESM(mitt);
|
|
38
|
-
//#region lib/utils/escapeRegex.
|
|
39
|
-
|
|
38
|
+
//#region src/lib/utils/escapeRegex.ts
|
|
39
|
+
/** @internal */
|
|
40
|
+
var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
40
41
|
//#endregion
|
|
41
|
-
//#region lib/utils/throttle.
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
//#region src/lib/utils/throttle.ts
|
|
43
|
+
/** @internal */
|
|
44
|
+
var throttle = (func, wait, options = {}) => {
|
|
45
|
+
let timeout;
|
|
46
|
+
let context;
|
|
47
|
+
let args;
|
|
48
|
+
let result;
|
|
44
49
|
let previous = 0;
|
|
45
|
-
if (!options) options = {};
|
|
46
50
|
const later = () => {
|
|
47
51
|
previous = options.leading === false ? 0 : Date.now();
|
|
48
52
|
timeout = null;
|
|
@@ -77,85 +81,30 @@ var throttle = (func, wait, options) => {
|
|
|
77
81
|
return throttled;
|
|
78
82
|
};
|
|
79
83
|
//#endregion
|
|
80
|
-
//#region lib/
|
|
84
|
+
//#region src/lib/utils/reportError.ts
|
|
85
|
+
/**
|
|
86
|
+
* Routes an error/warning to `handler` if supplied, falling back to the
|
|
87
|
+
* console (matching the previous hardcoded behaviour) if there is no
|
|
88
|
+
* handler, or if the handler itself throws.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
var reportError = (handler, error, context) => {
|
|
92
|
+
if (handler) try {
|
|
93
|
+
handler(error, context);
|
|
94
|
+
return;
|
|
95
|
+
} catch (handlerError) {
|
|
96
|
+
console.error(handlerError);
|
|
97
|
+
}
|
|
98
|
+
if (context.level === "warn") console.warn(error);
|
|
99
|
+
else console.error(error);
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/lib/DropList.ts
|
|
81
103
|
var ItemSymbol = Symbol("item");
|
|
82
104
|
var DestroyedSymbol$1 = Symbol("destroyed");
|
|
83
105
|
var GhostSymbol = Symbol("ghost");
|
|
84
106
|
var NoResultsItemSymbol = Symbol("no_results_items");
|
|
85
107
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
86
|
-
/**
|
|
87
|
-
* @typedef {Object} DropList.Options
|
|
88
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
89
|
-
* @property {string} [baseClassName='droplist'] class name for the menu root element
|
|
90
|
-
* @property {string|string[]} [additionalClasses]
|
|
91
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
92
|
-
* @property {boolean} [autoItemBlur=true] Should we automatically blur the focused item when the droplist loses focus?
|
|
93
|
-
* @property {number} [autoItemBlurDelay=300] How long to wait before deciding to blur the focused item (when the droplist loses focus)?
|
|
94
|
-
* @property {boolean} [capturesFocus=true] Should this DropList be added to the TAB-key stack?
|
|
95
|
-
* @property {boolean} [multi=false] Does this DropList show checkboxes for multiple item selection?
|
|
96
|
-
* @property {*} [singleSelectedValue] Current selected value when using single selection.
|
|
97
|
-
* @property {function} [keyDownHandler=null] An alternative "keydown" event handler. Return true to prevent default behaviour.
|
|
98
|
-
* @property {boolean} [autoCheckGroupChildren=true] When a group is checked/unchecked - all items beneath it will update accordingly
|
|
99
|
-
* @property {boolean} [useExactTargetWidth=false] Use the exact target's width, do not allow growing
|
|
100
|
-
* @property {boolean} [constrainToWindow=true] Should the position be constrained to the window, attaching to window's borders if needed?
|
|
101
|
-
* @property {Boolean} [autoFlipDirection=true] Should the position/anchor be flipped automatically when there's no space in the required direction?
|
|
102
|
-
* @property {number} [estimatedItemHeight=20] An estimated row height, for approximating scroll height.
|
|
103
|
-
* @property {boolean} [estimateWidth=false] Use an estimation for the width instead of measuring. May be faster - needs testing and may depend on the CSS.
|
|
104
|
-
* @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.
|
|
105
|
-
* @property {string} [labelProp='label']
|
|
106
|
-
* @property {string} [valueProp='value']
|
|
107
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderItem] Function to call when rendering an item element
|
|
108
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderItem] Function to call when rendering an item element
|
|
109
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
110
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
111
|
-
* @property {function(name: string, data: *)} [on]
|
|
112
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
113
|
-
* @property {boolean} [isFooterVisible=false] show footer element
|
|
114
|
-
* @property {boolean} [searchable=false] include inline search box
|
|
115
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
116
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
117
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
118
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
119
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
120
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
121
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
122
|
-
* */
|
|
123
|
-
/** */
|
|
124
|
-
/**
|
|
125
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
126
|
-
* @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`)
|
|
127
|
-
* @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`)
|
|
128
|
-
* */
|
|
129
|
-
/** */
|
|
130
|
-
/**
|
|
131
|
-
* @typedef {Object} DropList.PositionOptions
|
|
132
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
133
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
134
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
135
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
136
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
137
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
138
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
139
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
140
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
141
|
-
* */
|
|
142
|
-
/** */
|
|
143
|
-
/**
|
|
144
|
-
* @typedef {Object} DropList.ItemBase
|
|
145
|
-
* @property {string} [value]
|
|
146
|
-
* @property {string} [label]
|
|
147
|
-
* @property {boolean} [_group=false]
|
|
148
|
-
* @property {boolean} [_child=false]
|
|
149
|
-
* @property {boolean} [_nocheck=false]
|
|
150
|
-
* @property {boolean} [_nointeraction=false]
|
|
151
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
152
|
-
* */
|
|
153
|
-
/**
|
|
154
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
155
|
-
* @property {boolean} [_checked=false]
|
|
156
|
-
* */
|
|
157
|
-
/** */
|
|
158
|
-
/** @type {DropList.Options} */
|
|
159
108
|
var DefaultOptions = {
|
|
160
109
|
baseClassName: "droplist",
|
|
161
110
|
autoItemBlur: true,
|
|
@@ -176,6 +125,7 @@ var DefaultOptions = {
|
|
|
176
125
|
isHeaderVisible: false,
|
|
177
126
|
isFooterVisible: false,
|
|
178
127
|
searchable: false,
|
|
128
|
+
searchPlaceholder: "",
|
|
179
129
|
noResultsText: "No matching results",
|
|
180
130
|
filterThrottleWindow: 300,
|
|
181
131
|
filterOnEmptyTerm: false,
|
|
@@ -219,7 +169,9 @@ var DropList = class DropList {
|
|
|
219
169
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
220
170
|
on: o.on || null,
|
|
221
171
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
172
|
+
onError: o.onError,
|
|
222
173
|
searchable: o.searchable,
|
|
174
|
+
searchPlaceholder: o.searchPlaceholder,
|
|
223
175
|
isHeaderVisible: o.isHeaderVisible,
|
|
224
176
|
isFooterVisible: o.isFooterVisible,
|
|
225
177
|
silenceEvents: true,
|
|
@@ -235,7 +187,14 @@ var DropList = class DropList {
|
|
|
235
187
|
throttledRefilterItems: null,
|
|
236
188
|
focusItemIndex: -1,
|
|
237
189
|
focusItemEl: null,
|
|
238
|
-
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default()
|
|
190
|
+
sink: new _danielgindi_dom_utils_lib_DomEventsSink.default(),
|
|
191
|
+
visible: false,
|
|
192
|
+
hiding: false,
|
|
193
|
+
singleSelectedItemEl: null,
|
|
194
|
+
onDocumentMouseDown: null,
|
|
195
|
+
lastKeyWasChar: false,
|
|
196
|
+
currentSubDropList: null,
|
|
197
|
+
_isFocusingItem: false
|
|
239
198
|
};
|
|
240
199
|
let classes = [p.baseClassName + "_wrapper"];
|
|
241
200
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -301,7 +260,11 @@ var DropList = class DropList {
|
|
|
301
260
|
};
|
|
302
261
|
else item = items[index];
|
|
303
262
|
}
|
|
304
|
-
if (!item)
|
|
263
|
+
if (!item) reportError(p.onError, `onItemRender called for (${index}) which has no item`, {
|
|
264
|
+
source: "renderItem",
|
|
265
|
+
level: "warn",
|
|
266
|
+
index
|
|
267
|
+
});
|
|
305
268
|
itemEl.className = `${p.baseClassName}__item`;
|
|
306
269
|
const classList = itemEl.classList;
|
|
307
270
|
if (item) {
|
|
@@ -459,6 +422,7 @@ var DropList = class DropList {
|
|
|
459
422
|
}
|
|
460
423
|
/**
|
|
461
424
|
* @private
|
|
425
|
+
* @internal
|
|
462
426
|
*/
|
|
463
427
|
_setupUnrenderFunction() {
|
|
464
428
|
const p = this._p;
|
|
@@ -470,12 +434,20 @@ var DropList = class DropList {
|
|
|
470
434
|
if (item === NoResultsItemSymbol) try {
|
|
471
435
|
fnNoResults(item, el);
|
|
472
436
|
} catch (err) {
|
|
473
|
-
|
|
437
|
+
reportError(p.onError, err, {
|
|
438
|
+
source: "unrenderNoResultsItem",
|
|
439
|
+
item,
|
|
440
|
+
el
|
|
441
|
+
});
|
|
474
442
|
}
|
|
475
443
|
else try {
|
|
476
444
|
fn(item[ItemSymbol], el);
|
|
477
445
|
} catch (err) {
|
|
478
|
-
|
|
446
|
+
reportError(p.onError, err, {
|
|
447
|
+
source: "unrenderItem",
|
|
448
|
+
item: item[ItemSymbol],
|
|
449
|
+
el
|
|
450
|
+
});
|
|
479
451
|
}
|
|
480
452
|
delete el[ItemSymbol];
|
|
481
453
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -495,6 +467,7 @@ var DropList = class DropList {
|
|
|
495
467
|
p.valueProp = prop;
|
|
496
468
|
return this;
|
|
497
469
|
}
|
|
470
|
+
/** @internal */
|
|
498
471
|
_syncBaseClasses() {
|
|
499
472
|
const p = this._p, el = p.el;
|
|
500
473
|
if (!el) return;
|
|
@@ -533,7 +506,7 @@ var DropList = class DropList {
|
|
|
533
506
|
goToLast(event) {
|
|
534
507
|
this._move("last", event);
|
|
535
508
|
}
|
|
536
|
-
toggleFocusedItem() {
|
|
509
|
+
toggleFocusedItem(event) {
|
|
537
510
|
const p = this._p;
|
|
538
511
|
if (this.hasFocusedItem() && p.multi) {
|
|
539
512
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -654,7 +627,7 @@ var DropList = class DropList {
|
|
|
654
627
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
655
628
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
656
629
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
657
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
630
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
658
631
|
if (p.multi) {
|
|
659
632
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
660
633
|
}
|
|
@@ -662,10 +635,10 @@ var DropList = class DropList {
|
|
|
662
635
|
if (!!newItem._group !== item._group) {
|
|
663
636
|
if (item._group) p.groupCount--;
|
|
664
637
|
else p.groupCount++;
|
|
665
|
-
|
|
638
|
+
item._group = !!newItem._group;
|
|
666
639
|
}
|
|
667
640
|
}
|
|
668
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
641
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
669
642
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
670
643
|
let virtualItemIndex = itemIndex;
|
|
671
644
|
if (p.filteredItems) {
|
|
@@ -812,6 +785,23 @@ var DropList = class DropList {
|
|
|
812
785
|
return this._p.positionOptionsProvider;
|
|
813
786
|
}
|
|
814
787
|
/**
|
|
788
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
789
|
+
* instead of the default `console.error`/`console.warn`.
|
|
790
|
+
* @param {DropList.LibraryErrorHandler|null} [fn]
|
|
791
|
+
* @returns {DropList}
|
|
792
|
+
*/
|
|
793
|
+
setOnError(fn) {
|
|
794
|
+
const p = this._p;
|
|
795
|
+
p.onError = fn ?? void 0;
|
|
796
|
+
return this;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* @returns {DropList.LibraryErrorHandler|undefined}
|
|
800
|
+
*/
|
|
801
|
+
getOnError() {
|
|
802
|
+
return this._p.onError;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
815
805
|
* @param {string} term
|
|
816
806
|
* @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
|
|
817
807
|
* @returns {DropList}
|
|
@@ -832,6 +822,7 @@ var DropList = class DropList {
|
|
|
832
822
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
833
823
|
}
|
|
834
824
|
/** @private */
|
|
825
|
+
/** @internal */
|
|
835
826
|
_refilterItems() {
|
|
836
827
|
const p = this._p;
|
|
837
828
|
const term = p.filterTerm;
|
|
@@ -866,7 +857,7 @@ var DropList = class DropList {
|
|
|
866
857
|
});
|
|
867
858
|
}
|
|
868
859
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
869
|
-
const matcher = new RegExp(
|
|
860
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
870
861
|
filteredItems = p.items.filter((x) => {
|
|
871
862
|
if (!filterGroups && x._group) return true;
|
|
872
863
|
return matcher.test(x.label);
|
|
@@ -943,7 +934,7 @@ var DropList = class DropList {
|
|
|
943
934
|
p.filterThrottleWindow = window;
|
|
944
935
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
945
936
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
946
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
937
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
947
938
|
if (isScheduled) p.throttledRefilterItems();
|
|
948
939
|
return this;
|
|
949
940
|
}
|
|
@@ -1289,7 +1280,7 @@ var DropList = class DropList {
|
|
|
1289
1280
|
if (this.isVisible()) this._trigger("show");
|
|
1290
1281
|
return this;
|
|
1291
1282
|
}
|
|
1292
|
-
hide() {
|
|
1283
|
+
hide(event) {
|
|
1293
1284
|
const p = this._p, el = p.el;
|
|
1294
1285
|
if (p.onDocumentMouseDown) {
|
|
1295
1286
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1401,7 +1392,8 @@ var DropList = class DropList {
|
|
|
1401
1392
|
autocomplete: "off",
|
|
1402
1393
|
autocapitalize: "off",
|
|
1403
1394
|
spellcheck: "false",
|
|
1404
|
-
"aria-autocomplete": "list"
|
|
1395
|
+
"aria-autocomplete": "list",
|
|
1396
|
+
placeholder: p.searchPlaceholder || ""
|
|
1405
1397
|
});
|
|
1406
1398
|
p.headerEl.appendChild(p.searchInput);
|
|
1407
1399
|
} else {
|
|
@@ -1410,6 +1402,15 @@ var DropList = class DropList {
|
|
|
1410
1402
|
}
|
|
1411
1403
|
this.setHeaderVisible(searchable);
|
|
1412
1404
|
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Set the placeholder text of the inline search box
|
|
1407
|
+
* @param {string} placeholder
|
|
1408
|
+
*/
|
|
1409
|
+
setSearchPlaceholder(placeholder) {
|
|
1410
|
+
const p = this._p;
|
|
1411
|
+
p.searchPlaceholder = placeholder || "";
|
|
1412
|
+
if (p.searchInput) p.searchInput.placeholder = p.searchPlaceholder;
|
|
1413
|
+
}
|
|
1413
1414
|
hasFocusedItem() {
|
|
1414
1415
|
return this._p.focusItemIndex > -1 && this._p.focusItemIndex < this._p.items.length;
|
|
1415
1416
|
}
|
|
@@ -1451,6 +1452,7 @@ var DropList = class DropList {
|
|
|
1451
1452
|
}
|
|
1452
1453
|
return this;
|
|
1453
1454
|
}
|
|
1455
|
+
/** @internal */
|
|
1454
1456
|
_showSublist(item, itemElement) {
|
|
1455
1457
|
if (!item._subitems?.length) return;
|
|
1456
1458
|
const p = this._p;
|
|
@@ -1526,6 +1528,7 @@ var DropList = class DropList {
|
|
|
1526
1528
|
droplist.show();
|
|
1527
1529
|
droplist.el.focus();
|
|
1528
1530
|
}
|
|
1531
|
+
/** @internal */
|
|
1529
1532
|
_hideSublist() {
|
|
1530
1533
|
const p = this._p;
|
|
1531
1534
|
if (!p.currentSubDropList) return;
|
|
@@ -1625,6 +1628,7 @@ var DropList = class DropList {
|
|
|
1625
1628
|
}
|
|
1626
1629
|
return this;
|
|
1627
1630
|
}
|
|
1631
|
+
/** @internal */
|
|
1628
1632
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1629
1633
|
const p = this._p;
|
|
1630
1634
|
if (this._hasScroll()) {
|
|
@@ -1688,6 +1692,7 @@ var DropList = class DropList {
|
|
|
1688
1692
|
this._p.mitt.emit(event, value);
|
|
1689
1693
|
return this;
|
|
1690
1694
|
}
|
|
1695
|
+
/** @internal */
|
|
1691
1696
|
_getItemIndex(item) {
|
|
1692
1697
|
const p = this._p;
|
|
1693
1698
|
let itemIndex = -1;
|
|
@@ -1701,6 +1706,7 @@ var DropList = class DropList {
|
|
|
1701
1706
|
}
|
|
1702
1707
|
return itemIndex;
|
|
1703
1708
|
}
|
|
1709
|
+
/** @internal */
|
|
1704
1710
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1705
1711
|
const p = this._p;
|
|
1706
1712
|
if (p.singleSelectedItemEl) {
|
|
@@ -1718,12 +1724,14 @@ var DropList = class DropList {
|
|
|
1718
1724
|
* @param {string} event
|
|
1719
1725
|
* @param {*} [data]
|
|
1720
1726
|
* @private
|
|
1727
|
+
* @internal
|
|
1721
1728
|
*/
|
|
1722
1729
|
_trigger(event, data) {
|
|
1723
1730
|
const p = this._p;
|
|
1724
1731
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1725
1732
|
p.mitt.emit(event, data);
|
|
1726
1733
|
}
|
|
1734
|
+
/** @internal */
|
|
1727
1735
|
_itemUpAction(event, itemEl) {
|
|
1728
1736
|
if ((0, _danielgindi_dom_utils_lib_Dom.closestUntil)(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1729
1737
|
let p = this._p;
|
|
@@ -1736,6 +1744,7 @@ var DropList = class DropList {
|
|
|
1736
1744
|
}, 0);
|
|
1737
1745
|
}
|
|
1738
1746
|
}
|
|
1747
|
+
/** @internal */
|
|
1739
1748
|
_hookMouseEvents() {
|
|
1740
1749
|
const p = this._p;
|
|
1741
1750
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1749,9 +1758,11 @@ var DropList = class DropList {
|
|
|
1749
1758
|
this._handleMouseOver(event, li);
|
|
1750
1759
|
});
|
|
1751
1760
|
}
|
|
1761
|
+
/** @internal */
|
|
1752
1762
|
_handleMouseOver(event, itemEl) {
|
|
1753
1763
|
this._focus(event, itemEl, null, true);
|
|
1754
1764
|
}
|
|
1765
|
+
/** @internal */
|
|
1755
1766
|
_hookTouchEvents() {
|
|
1756
1767
|
const p = this._p;
|
|
1757
1768
|
let currentTouchId;
|
|
@@ -1791,6 +1802,7 @@ var DropList = class DropList {
|
|
|
1791
1802
|
});
|
|
1792
1803
|
});
|
|
1793
1804
|
}
|
|
1805
|
+
/** @internal */
|
|
1794
1806
|
_hookFocusEvents() {
|
|
1795
1807
|
const p = this._p;
|
|
1796
1808
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1808,10 +1820,12 @@ var DropList = class DropList {
|
|
|
1808
1820
|
});
|
|
1809
1821
|
}, true);
|
|
1810
1822
|
}
|
|
1823
|
+
/** @internal */
|
|
1811
1824
|
_hookKeyEvents() {
|
|
1812
1825
|
const p = this._p;
|
|
1813
1826
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1814
1827
|
}
|
|
1828
|
+
/** @internal */
|
|
1815
1829
|
_hookSearchEvents() {
|
|
1816
1830
|
const p = this._p;
|
|
1817
1831
|
if (!p.searchInput) return;
|
|
@@ -1822,6 +1836,7 @@ var DropList = class DropList {
|
|
|
1822
1836
|
p.throttledRefilterItems();
|
|
1823
1837
|
});
|
|
1824
1838
|
}
|
|
1839
|
+
/** @internal */
|
|
1825
1840
|
_keydown(event) {
|
|
1826
1841
|
const p = this._p;
|
|
1827
1842
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1884,6 +1899,7 @@ var DropList = class DropList {
|
|
|
1884
1899
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1885
1900
|
}
|
|
1886
1901
|
}
|
|
1902
|
+
/** @internal */
|
|
1887
1903
|
_keydownFreeType(evt, autoSelect) {
|
|
1888
1904
|
const p = this._p;
|
|
1889
1905
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1892,7 +1908,7 @@ var DropList = class DropList {
|
|
|
1892
1908
|
if (!isChar) return;
|
|
1893
1909
|
clearTimeout(p.filterTimer);
|
|
1894
1910
|
let keyword = (p.previousFilter || "") + character;
|
|
1895
|
-
let regex = new RegExp(`^${
|
|
1911
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1896
1912
|
let matchIndex = -1;
|
|
1897
1913
|
let item;
|
|
1898
1914
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1907,7 +1923,7 @@ var DropList = class DropList {
|
|
|
1907
1923
|
}
|
|
1908
1924
|
if (matchIndex === -1) {
|
|
1909
1925
|
keyword = character;
|
|
1910
|
-
regex = new RegExp(`^${
|
|
1926
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1911
1927
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1912
1928
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1913
1929
|
item = items[i];
|
|
@@ -1927,6 +1943,7 @@ var DropList = class DropList {
|
|
|
1927
1943
|
}, 1e3);
|
|
1928
1944
|
} else delete p.previousFilter;
|
|
1929
1945
|
}
|
|
1946
|
+
/** @internal */
|
|
1930
1947
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1931
1948
|
const p = this._p;
|
|
1932
1949
|
if (p._isFocusingItem) return;
|
|
@@ -1960,6 +1977,7 @@ var DropList = class DropList {
|
|
|
1960
1977
|
p._isFocusingItem = false;
|
|
1961
1978
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1962
1979
|
}
|
|
1980
|
+
/** @internal */
|
|
1963
1981
|
_delayBlurItemOnBlur() {
|
|
1964
1982
|
if (this[DestroyedSymbol$1]) return;
|
|
1965
1983
|
const p = this._p;
|
|
@@ -1970,6 +1988,7 @@ var DropList = class DropList {
|
|
|
1970
1988
|
this.blurFocusedItem();
|
|
1971
1989
|
}, p.autoItemBlurDelay);
|
|
1972
1990
|
}
|
|
1991
|
+
/** @internal */
|
|
1973
1992
|
_move(direction, event) {
|
|
1974
1993
|
const p = this._p;
|
|
1975
1994
|
let next, nextIndex, directionUp;
|
|
@@ -2039,10 +2058,12 @@ var DropList = class DropList {
|
|
|
2039
2058
|
this._focus(event, next || null, nextIndex, false);
|
|
2040
2059
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2041
2060
|
}
|
|
2061
|
+
/** @internal */
|
|
2042
2062
|
_hasScroll() {
|
|
2043
2063
|
const menuEl = this._p.menuEl;
|
|
2044
2064
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2045
2065
|
}
|
|
2066
|
+
/** @internal */
|
|
2046
2067
|
_updateGroupStateForItem(item) {
|
|
2047
2068
|
const p = this._p;
|
|
2048
2069
|
if (!p.multi) return this;
|
|
@@ -2086,6 +2107,7 @@ var DropList = class DropList {
|
|
|
2086
2107
|
}
|
|
2087
2108
|
return this;
|
|
2088
2109
|
}
|
|
2110
|
+
/** @internal */
|
|
2089
2111
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2090
2112
|
const p = this._p;
|
|
2091
2113
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2119,6 +2141,7 @@ var DropList = class DropList {
|
|
|
2119
2141
|
/**
|
|
2120
2142
|
* @private
|
|
2121
2143
|
* @returns {DropList} self
|
|
2144
|
+
* @internal
|
|
2122
2145
|
*/
|
|
2123
2146
|
_measureItem() {
|
|
2124
2147
|
const p = this._p;
|
|
@@ -2166,6 +2189,7 @@ var DropList = class DropList {
|
|
|
2166
2189
|
* @param {number?} targetItemCount - item count we are expecting. Defaults to current item count
|
|
2167
2190
|
* @returns {DropList}
|
|
2168
2191
|
* @private
|
|
2192
|
+
* @internal
|
|
2169
2193
|
*/
|
|
2170
2194
|
_determineVirtualMode(targetItemCount) {
|
|
2171
2195
|
const p = this._p;
|
|
@@ -2175,6 +2199,7 @@ var DropList = class DropList {
|
|
|
2175
2199
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2176
2200
|
return this;
|
|
2177
2201
|
}
|
|
2202
|
+
/** @internal */
|
|
2178
2203
|
_renderItemContent(item, itemEl) {
|
|
2179
2204
|
const p = this._p;
|
|
2180
2205
|
const originalItem = item[ItemSymbol];
|
|
@@ -2196,17 +2221,12 @@ var DropList = class DropList {
|
|
|
2196
2221
|
}
|
|
2197
2222
|
}
|
|
2198
2223
|
}
|
|
2199
|
-
/**
|
|
2200
|
-
*
|
|
2201
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2202
|
-
* @returns {number} new outer width
|
|
2203
|
-
* @private
|
|
2204
|
-
*/
|
|
2224
|
+
/** @internal */
|
|
2205
2225
|
_updateWidth(positionOptions) {
|
|
2206
2226
|
const p = this._p, el = p.el;
|
|
2207
2227
|
let targetWidth = 0;
|
|
2208
2228
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2209
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2229
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2210
2230
|
else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
|
|
2211
2231
|
let autoWidth = 0;
|
|
2212
2232
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2228,7 +2248,7 @@ var DropList = class DropList {
|
|
|
2228
2248
|
}
|
|
2229
2249
|
};
|
|
2230
2250
|
//#endregion
|
|
2231
|
-
//#region lib/SelectBox.
|
|
2251
|
+
//#region src/lib/SelectBox.ts
|
|
2232
2252
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2233
2253
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2234
2254
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2254,57 +2274,6 @@ var inputBackbufferCssProps = [
|
|
|
2254
2274
|
"padding-left",
|
|
2255
2275
|
"padding-right"
|
|
2256
2276
|
];
|
|
2257
|
-
/**
|
|
2258
|
-
* @typedef {Object} SelectBox.Options
|
|
2259
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2260
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2261
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2262
|
-
* @property {string|string[]} [additionalClasses]
|
|
2263
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2264
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2265
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2266
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2267
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2268
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2269
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2270
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2271
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2272
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2273
|
-
* @property {*[]} [stickyValues]
|
|
2274
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2275
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2276
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2277
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2278
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2279
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2280
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2281
|
-
* @property {string} [labelProp='label']
|
|
2282
|
-
* @property {string} [valueProp='value']
|
|
2283
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2284
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2285
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2286
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2287
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2288
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2289
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2290
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2291
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2292
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2293
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2294
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2295
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2296
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2297
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2298
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2299
|
-
* @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.
|
|
2300
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2301
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2302
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2303
|
-
* @property {function(name: string, ...args)} [on]
|
|
2304
|
-
* @property {boolean} [isLoadingMode]
|
|
2305
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2306
|
-
* @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>
|
|
2307
|
-
* */
|
|
2308
2277
|
var DefaultOptions$1 = {
|
|
2309
2278
|
el: null,
|
|
2310
2279
|
baseClassName: "selectbox",
|
|
@@ -2423,6 +2392,7 @@ var SelectBox = class {
|
|
|
2423
2392
|
on: o.on || null,
|
|
2424
2393
|
silenceEvents: true,
|
|
2425
2394
|
mitt: (0, mitt.default)(),
|
|
2395
|
+
onError: o.onError,
|
|
2426
2396
|
isLoadingMode: !!o.isLoadingMode,
|
|
2427
2397
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2428
2398
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2438,7 +2408,11 @@ var SelectBox = class {
|
|
|
2438
2408
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2439
2409
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2440
2410
|
filterFn: null,
|
|
2441
|
-
filterTerm: ""
|
|
2411
|
+
filterTerm: "",
|
|
2412
|
+
dropListVisible: false,
|
|
2413
|
+
lastActiveElement: null,
|
|
2414
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2415
|
+
presenceInt: null
|
|
2442
2416
|
};
|
|
2443
2417
|
let el = o.el;
|
|
2444
2418
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -3176,7 +3150,7 @@ var SelectBox = class {
|
|
|
3176
3150
|
if (p.filterFn === fn) return this;
|
|
3177
3151
|
p.filterFn = fn;
|
|
3178
3152
|
if (!fn) fn = (items, term) => {
|
|
3179
|
-
const matcher = new RegExp(
|
|
3153
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3180
3154
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3181
3155
|
return p.items.filter((x) => {
|
|
3182
3156
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3194,6 +3168,25 @@ var SelectBox = class {
|
|
|
3194
3168
|
return this._p.filterFn;
|
|
3195
3169
|
}
|
|
3196
3170
|
/**
|
|
3171
|
+
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderMultiItem`/`unrenderSingleItem`)
|
|
3172
|
+
* instead of the default `console.error`/`console.warn`. Also used as the default `onError` for the internal
|
|
3173
|
+
* `DropList`, unless `listOptions.onError` is set explicitly.
|
|
3174
|
+
* @param {SelectBox.LibraryErrorHandler|null} [fn]
|
|
3175
|
+
* @returns {SelectBox}
|
|
3176
|
+
*/
|
|
3177
|
+
setOnError(fn) {
|
|
3178
|
+
const p = this._p;
|
|
3179
|
+
p.onError = fn ?? void 0;
|
|
3180
|
+
p.dropList?.setOnError(p.listOptions?.onError ?? p.onError);
|
|
3181
|
+
return this;
|
|
3182
|
+
}
|
|
3183
|
+
/**
|
|
3184
|
+
* @returns {SelectBox.LibraryErrorHandler|undefined}
|
|
3185
|
+
*/
|
|
3186
|
+
getOnError() {
|
|
3187
|
+
return this._p.onError;
|
|
3188
|
+
}
|
|
3189
|
+
/**
|
|
3197
3190
|
* Focus on input element
|
|
3198
3191
|
* @returns {SelectBox}
|
|
3199
3192
|
*/
|
|
@@ -3482,6 +3475,7 @@ var SelectBox = class {
|
|
|
3482
3475
|
* Prepare the mapping between values and items.
|
|
3483
3476
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3484
3477
|
* @private
|
|
3478
|
+
* @internal
|
|
3485
3479
|
*/
|
|
3486
3480
|
_refreshItemByValueMap() {
|
|
3487
3481
|
const p = this._p;
|
|
@@ -3494,6 +3488,7 @@ var SelectBox = class {
|
|
|
3494
3488
|
* @param {*} value
|
|
3495
3489
|
* @returns {DropList.ItemBase|undefined}
|
|
3496
3490
|
* @private
|
|
3491
|
+
* @internal
|
|
3497
3492
|
*/
|
|
3498
3493
|
_getItemByValue(value) {
|
|
3499
3494
|
const p = this._p;
|
|
@@ -3503,6 +3498,7 @@ var SelectBox = class {
|
|
|
3503
3498
|
return p.subitemByValueMap.get(value);
|
|
3504
3499
|
}
|
|
3505
3500
|
/** @private */
|
|
3501
|
+
/** @internal */
|
|
3506
3502
|
_refreshSubitemByValueMap() {
|
|
3507
3503
|
const p = this._p;
|
|
3508
3504
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
@@ -3513,6 +3509,7 @@ var SelectBox = class {
|
|
|
3513
3509
|
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3514
3510
|
* @param {string} valueProp
|
|
3515
3511
|
* @private
|
|
3512
|
+
* @internal
|
|
3516
3513
|
*/
|
|
3517
3514
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3518
3515
|
for (let item of items) {
|
|
@@ -3522,6 +3519,7 @@ var SelectBox = class {
|
|
|
3522
3519
|
}
|
|
3523
3520
|
}
|
|
3524
3521
|
/** @private */
|
|
3522
|
+
/** @internal */
|
|
3525
3523
|
_renderBase() {
|
|
3526
3524
|
const p = this._p;
|
|
3527
3525
|
if (!p.inputBackBuffer) p.inputBackBuffer = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { css: {
|
|
@@ -3610,6 +3608,7 @@ var SelectBox = class {
|
|
|
3610
3608
|
}
|
|
3611
3609
|
/**
|
|
3612
3610
|
* @private
|
|
3611
|
+
* @internal
|
|
3613
3612
|
*/
|
|
3614
3613
|
_syncBaseClasses() {
|
|
3615
3614
|
const p = this._p, el = p.el;
|
|
@@ -3630,6 +3629,7 @@ var SelectBox = class {
|
|
|
3630
3629
|
el.className = classes.join(" ");
|
|
3631
3630
|
}
|
|
3632
3631
|
/** @private */
|
|
3632
|
+
/** @internal */
|
|
3633
3633
|
_setupDropdownMenu() {
|
|
3634
3634
|
const p = this._p;
|
|
3635
3635
|
p.valueProp;
|
|
@@ -3659,6 +3659,7 @@ var SelectBox = class {
|
|
|
3659
3659
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3660
3660
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3661
3661
|
filterFn: p.actualFilterFn,
|
|
3662
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3662
3663
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3663
3664
|
on: (name, event) => {
|
|
3664
3665
|
switch (name) {
|
|
@@ -3794,6 +3795,7 @@ var SelectBox = class {
|
|
|
3794
3795
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3795
3796
|
this._registerDropdownEvents();
|
|
3796
3797
|
}
|
|
3798
|
+
/** @internal */
|
|
3797
3799
|
_handleOnBlur() {
|
|
3798
3800
|
const p = this._p;
|
|
3799
3801
|
setTimeout(() => {
|
|
@@ -3805,9 +3807,11 @@ var SelectBox = class {
|
|
|
3805
3807
|
this.closeList();
|
|
3806
3808
|
});
|
|
3807
3809
|
}
|
|
3810
|
+
/** @internal */
|
|
3808
3811
|
_unregisterDropdownEvents() {
|
|
3809
3812
|
this._p.sink.remove(null, ".dropdown");
|
|
3810
3813
|
}
|
|
3814
|
+
/** @internal */
|
|
3811
3815
|
_registerDropdownEvents() {
|
|
3812
3816
|
const p = this._p;
|
|
3813
3817
|
this._unregisterDropdownEvents();
|
|
@@ -3945,6 +3949,7 @@ var SelectBox = class {
|
|
|
3945
3949
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3946
3950
|
});
|
|
3947
3951
|
}
|
|
3952
|
+
/** @internal */
|
|
3948
3953
|
_performSelectWithEvent(item, value) {
|
|
3949
3954
|
let cancellable = {
|
|
3950
3955
|
value,
|
|
@@ -3961,6 +3966,7 @@ var SelectBox = class {
|
|
|
3961
3966
|
});
|
|
3962
3967
|
return true;
|
|
3963
3968
|
}
|
|
3969
|
+
/** @internal */
|
|
3964
3970
|
_performClearWithEvent(clearInput = false) {
|
|
3965
3971
|
let cancellable = { cancel: false };
|
|
3966
3972
|
this._trigger("clear:before", cancellable);
|
|
@@ -3971,6 +3977,7 @@ var SelectBox = class {
|
|
|
3971
3977
|
this._trigger("clear");
|
|
3972
3978
|
return true;
|
|
3973
3979
|
}
|
|
3980
|
+
/** @internal */
|
|
3974
3981
|
_movePrev() {
|
|
3975
3982
|
const p = this._p;
|
|
3976
3983
|
if (this.isMultiEnabled()) return;
|
|
@@ -3984,6 +3991,7 @@ var SelectBox = class {
|
|
|
3984
3991
|
else this._performClearWithEvent();
|
|
3985
3992
|
}
|
|
3986
3993
|
}
|
|
3994
|
+
/** @internal */
|
|
3987
3995
|
_moveNext() {
|
|
3988
3996
|
const p = this._p;
|
|
3989
3997
|
if (this.isMultiEnabled()) return;
|
|
@@ -3998,6 +4006,7 @@ var SelectBox = class {
|
|
|
3998
4006
|
}
|
|
3999
4007
|
}
|
|
4000
4008
|
/** @private */
|
|
4009
|
+
/** @internal */
|
|
4001
4010
|
_updateListItems() {
|
|
4002
4011
|
const p = this._p;
|
|
4003
4012
|
const dropList = p.dropList;
|
|
@@ -4027,6 +4036,7 @@ var SelectBox = class {
|
|
|
4027
4036
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
4028
4037
|
}
|
|
4029
4038
|
/** @private */
|
|
4039
|
+
/** @internal */
|
|
4030
4040
|
_setSelectedItems(items) {
|
|
4031
4041
|
const p = this._p, valueProp = p.valueProp;
|
|
4032
4042
|
if (p.multi) {
|
|
@@ -4042,6 +4052,7 @@ var SelectBox = class {
|
|
|
4042
4052
|
this._scheduleSync("full");
|
|
4043
4053
|
}
|
|
4044
4054
|
/** @private */
|
|
4055
|
+
/** @internal */
|
|
4045
4056
|
_scheduleSync(mode, data) {
|
|
4046
4057
|
const p = this._p;
|
|
4047
4058
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4059,6 +4070,7 @@ var SelectBox = class {
|
|
|
4059
4070
|
});
|
|
4060
4071
|
}
|
|
4061
4072
|
/** @private */
|
|
4073
|
+
/** @internal */
|
|
4062
4074
|
_performSync(queue) {
|
|
4063
4075
|
const p = this._p;
|
|
4064
4076
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4112,13 +4124,18 @@ var SelectBox = class {
|
|
|
4112
4124
|
}
|
|
4113
4125
|
}
|
|
4114
4126
|
/** @private */
|
|
4127
|
+
/** @internal */
|
|
4115
4128
|
_cleanupSingleWrapper() {
|
|
4116
4129
|
const p = this._p;
|
|
4117
4130
|
if (!p.singleWrapper) return;
|
|
4118
4131
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4119
4132
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4120
4133
|
} catch (err) {
|
|
4121
|
-
|
|
4134
|
+
reportError(p.onError, err, {
|
|
4135
|
+
source: "unrenderSingleItem",
|
|
4136
|
+
item: p.singleWrapper[ItemSymbol],
|
|
4137
|
+
el: p.singleWrapper
|
|
4138
|
+
});
|
|
4122
4139
|
}
|
|
4123
4140
|
delete p.singleWrapper[ItemSymbol];
|
|
4124
4141
|
p.singleWrapper.innerHTML = "";
|
|
@@ -4126,6 +4143,7 @@ var SelectBox = class {
|
|
|
4126
4143
|
/**
|
|
4127
4144
|
* @param {number} index
|
|
4128
4145
|
* @private
|
|
4146
|
+
* @internal
|
|
4129
4147
|
*/
|
|
4130
4148
|
_removeMultiItemElementByIndex(index) {
|
|
4131
4149
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4136,7 +4154,11 @@ var SelectBox = class {
|
|
|
4136
4154
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4137
4155
|
unrender(item, itemEl);
|
|
4138
4156
|
} catch (err) {
|
|
4139
|
-
|
|
4157
|
+
reportError(p.onError, err, {
|
|
4158
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
4159
|
+
item,
|
|
4160
|
+
el: itemEl
|
|
4161
|
+
});
|
|
4140
4162
|
}
|
|
4141
4163
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(itemEl);
|
|
4142
4164
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4146,6 +4168,7 @@ var SelectBox = class {
|
|
|
4146
4168
|
/**
|
|
4147
4169
|
* @param {DropList.ItemBase} item
|
|
4148
4170
|
* @private
|
|
4171
|
+
* @internal
|
|
4149
4172
|
*/
|
|
4150
4173
|
_renderSingleItemContent(item) {
|
|
4151
4174
|
const p = this._p;
|
|
@@ -4160,6 +4183,7 @@ var SelectBox = class {
|
|
|
4160
4183
|
* @param {DropList.ItemBase} item
|
|
4161
4184
|
* @param {Element} itemEl
|
|
4162
4185
|
* @private
|
|
4186
|
+
* @internal
|
|
4163
4187
|
*/
|
|
4164
4188
|
_renderMultiItemContent(item, itemEl) {
|
|
4165
4189
|
const p = this._p;
|
|
@@ -4174,6 +4198,7 @@ var SelectBox = class {
|
|
|
4174
4198
|
* @param {DropList.ItemBase} item
|
|
4175
4199
|
* @returns {boolean} true if rendered, false if not
|
|
4176
4200
|
* @private
|
|
4201
|
+
* @internal
|
|
4177
4202
|
*/
|
|
4178
4203
|
_addMultiItemElement(item) {
|
|
4179
4204
|
const p = this._p;
|
|
@@ -4184,6 +4209,7 @@ var SelectBox = class {
|
|
|
4184
4209
|
return true;
|
|
4185
4210
|
}
|
|
4186
4211
|
/** @private */
|
|
4212
|
+
/** @internal */
|
|
4187
4213
|
_addMultiItemRestElement() {
|
|
4188
4214
|
const p = this._p;
|
|
4189
4215
|
let items = p.selectedItems.slice(0);
|
|
@@ -4196,6 +4222,7 @@ var SelectBox = class {
|
|
|
4196
4222
|
});
|
|
4197
4223
|
}
|
|
4198
4224
|
/** @private */
|
|
4225
|
+
/** @internal */
|
|
4199
4226
|
_syncClearButton() {
|
|
4200
4227
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4201
4228
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4218,6 +4245,7 @@ var SelectBox = class {
|
|
|
4218
4245
|
}
|
|
4219
4246
|
}
|
|
4220
4247
|
/** @private */
|
|
4248
|
+
/** @internal */
|
|
4221
4249
|
_syncPlaceholder() {
|
|
4222
4250
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4223
4251
|
let placeholder = "";
|
|
@@ -4229,6 +4257,7 @@ var SelectBox = class {
|
|
|
4229
4257
|
else p.input.removeAttribute("title");
|
|
4230
4258
|
}
|
|
4231
4259
|
/** @private */
|
|
4260
|
+
/** @internal */
|
|
4232
4261
|
_syncSingleItem() {
|
|
4233
4262
|
const p = this._p;
|
|
4234
4263
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4243,6 +4272,7 @@ var SelectBox = class {
|
|
|
4243
4272
|
* @param {boolean=false} fullItemsRender Should re-render all items?
|
|
4244
4273
|
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4245
4274
|
* @returns {SelectBox}
|
|
4275
|
+
* @internal
|
|
4246
4276
|
*/
|
|
4247
4277
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4248
4278
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4303,6 +4333,7 @@ var SelectBox = class {
|
|
|
4303
4333
|
* @param {string} event
|
|
4304
4334
|
* @param {*} [data]
|
|
4305
4335
|
* @private
|
|
4336
|
+
* @internal
|
|
4306
4337
|
*/
|
|
4307
4338
|
_trigger(event, data) {
|
|
4308
4339
|
const p = this._p;
|
|
@@ -4315,6 +4346,7 @@ var SelectBox = class {
|
|
|
4315
4346
|
* @param {Object} item
|
|
4316
4347
|
* @returns {Element|null}
|
|
4317
4348
|
* @private
|
|
4349
|
+
* @internal
|
|
4318
4350
|
*/
|
|
4319
4351
|
_renderMultiItem(item) {
|
|
4320
4352
|
const p = this._p;
|
|
@@ -4342,6 +4374,7 @@ var SelectBox = class {
|
|
|
4342
4374
|
* @param {Event} originatingEvent
|
|
4343
4375
|
* @returns {SelectBox}
|
|
4344
4376
|
* @private
|
|
4377
|
+
* @internal
|
|
4345
4378
|
*/
|
|
4346
4379
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4347
4380
|
const p = this._p;
|
|
@@ -4357,7 +4390,7 @@ var SelectBox = class {
|
|
|
4357
4390
|
let itemsToRemove = [];
|
|
4358
4391
|
for (let item of items) {
|
|
4359
4392
|
let removeselEvt = {
|
|
4360
|
-
value,
|
|
4393
|
+
value: item[p.valueProp],
|
|
4361
4394
|
item,
|
|
4362
4395
|
cancel: false
|
|
4363
4396
|
};
|
|
@@ -4368,7 +4401,7 @@ var SelectBox = class {
|
|
|
4368
4401
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4369
4402
|
for (let item of itemsToRemove) {
|
|
4370
4403
|
let idx = p.selectedItems.indexOf(item);
|
|
4371
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
4404
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4372
4405
|
if (idx !== -1) {
|
|
4373
4406
|
p.selectedItems.splice(idx, 1);
|
|
4374
4407
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4402,6 +4435,7 @@ var SelectBox = class {
|
|
|
4402
4435
|
* @param {DropList.ItemBase} item
|
|
4403
4436
|
* @param {boolean} [populate]
|
|
4404
4437
|
* @private
|
|
4438
|
+
* @internal
|
|
4405
4439
|
*/
|
|
4406
4440
|
_removeMultiItem(item, populate = false) {
|
|
4407
4441
|
const p = this._p;
|
|
@@ -4428,6 +4462,7 @@ var SelectBox = class {
|
|
|
4428
4462
|
/**
|
|
4429
4463
|
* @param {*} value
|
|
4430
4464
|
* @private
|
|
4465
|
+
* @internal
|
|
4431
4466
|
*/
|
|
4432
4467
|
_setInputText(value) {
|
|
4433
4468
|
const p = this._p;
|
|
@@ -4440,6 +4475,7 @@ var SelectBox = class {
|
|
|
4440
4475
|
* Update input size to current state
|
|
4441
4476
|
* @returns {SelectBox}
|
|
4442
4477
|
* @private
|
|
4478
|
+
* @internal
|
|
4443
4479
|
*/
|
|
4444
4480
|
_resizeInput() {
|
|
4445
4481
|
const p = this._p, el = p.el;
|
|
@@ -4497,6 +4533,7 @@ var SelectBox = class {
|
|
|
4497
4533
|
* Update autocomplete position if needed
|
|
4498
4534
|
* @returns {SelectBox}
|
|
4499
4535
|
* @private
|
|
4536
|
+
* @internal
|
|
4500
4537
|
*/
|
|
4501
4538
|
_repositionDropList() {
|
|
4502
4539
|
const p = this._p, el = p.el;
|
|
@@ -4512,6 +4549,7 @@ var SelectBox = class {
|
|
|
4512
4549
|
/**
|
|
4513
4550
|
* @param {KeyboardEvent} event
|
|
4514
4551
|
* @private
|
|
4552
|
+
* @internal
|
|
4515
4553
|
*/
|
|
4516
4554
|
_handleInputKeydown(event) {
|
|
4517
4555
|
const p = this._p;
|
|
@@ -4542,6 +4580,7 @@ var SelectBox = class {
|
|
|
4542
4580
|
/**
|
|
4543
4581
|
* @param {KeyboardEvent} event
|
|
4544
4582
|
* @private
|
|
4583
|
+
* @internal
|
|
4545
4584
|
*/
|
|
4546
4585
|
_handleMultiKeydown(event) {
|
|
4547
4586
|
const p = this._p;
|
|
@@ -4587,6 +4626,7 @@ var SelectBox = class {
|
|
|
4587
4626
|
/**
|
|
4588
4627
|
* @returns {DropList.PositionOptions}
|
|
4589
4628
|
* @private
|
|
4629
|
+
* @internal
|
|
4590
4630
|
*/
|
|
4591
4631
|
_getDropListPositionOptions() {
|
|
4592
4632
|
return {
|
|
@@ -4607,6 +4647,7 @@ var SelectBox = class {
|
|
|
4607
4647
|
};
|
|
4608
4648
|
}
|
|
4609
4649
|
/** @private */
|
|
4650
|
+
/** @internal */
|
|
4610
4651
|
_startTrackingPresence() {
|
|
4611
4652
|
const p = this._p;
|
|
4612
4653
|
this._stopTrackingPresence();
|
|
@@ -4615,6 +4656,7 @@ var SelectBox = class {
|
|
|
4615
4656
|
}, 200);
|
|
4616
4657
|
}
|
|
4617
4658
|
/** @private */
|
|
4659
|
+
/** @internal */
|
|
4618
4660
|
_stopTrackingPresence() {
|
|
4619
4661
|
const p = this._p;
|
|
4620
4662
|
if (p.presenceInt) {
|
|
@@ -4630,6 +4672,7 @@ var SelectBox = class {
|
|
|
4630
4672
|
* @param {boolean=false} sortCheckedFirst
|
|
4631
4673
|
* @param {boolean=false} splitCheckedGroups
|
|
4632
4674
|
* @returns {DropList.ItemBase[]}
|
|
4675
|
+
* @internal
|
|
4633
4676
|
*/
|
|
4634
4677
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4635
4678
|
const p = this._p;
|