@danielgindi/selectbox 2.0.57 → 2.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs.js +190 -160
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +190 -160
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +190 -160
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/dist/types/DropList.d.ts +343 -0
- package/dist/types/DropList.d.ts.map +1 -0
- package/dist/types/SelectBox.d.ts +497 -0
- package/dist/types/SelectBox.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +207 -0
- package/dist/types/types.d.ts.map +1 -0
- package/eslint.config.mjs +8 -0
- package/lib/DropList.js +1 -3430
- package/lib/SelectBox.js +1 -3689
- package/lib/index.js +1 -4
- package/package.json +9 -4
- package/tsconfig.json +35 -0
- package/vue/DropList.vue +495 -565
- package/vue/DropList.vue.d.ts +4 -0
- package/vue/SelectBox.vue +855 -981
- package/vue/SelectBox.vue.d.ts +4 -0
- package/vue/component-types.d.ts +210 -0
- package/vue/index.d.ts +4 -0
- package/vue/index.js +3 -4
- package/vue/utils/slots.js +89 -96
- package/lib/utils/escapeRegex.js +0 -1
- package/lib/utils/throttle.js +0 -48
package/dist/lib.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,86 +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} [searchPlaceholder=''] placeholder text for the inline search box
|
|
116
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
117
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
118
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
119
|
-
* @property {boolean} [filterGroups=false] should groups be filtered?
|
|
120
|
-
* @property {boolean} [filterEmptyGroups=false] should empty groups be filtered out?
|
|
121
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
122
|
-
* @property {function(dropList: DropList):DropList.PositionOptions} [positionOptionsProvider]
|
|
123
|
-
* */
|
|
124
|
-
/** */
|
|
125
|
-
/**
|
|
126
|
-
* @typedef {Object} DropList.PositionAnchor
|
|
127
|
-
* @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`)
|
|
128
|
-
* @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`)
|
|
129
|
-
* */
|
|
130
|
-
/** */
|
|
131
|
-
/**
|
|
132
|
-
* @typedef {Object} DropList.PositionOptions
|
|
133
|
-
* @property {Element?} [target] Target element to act as anchor
|
|
134
|
-
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
135
|
-
* @property {number?} [targetHeight] Override height of the target
|
|
136
|
-
* @property {number?} [targetWidth] Override width of the target
|
|
137
|
-
* @property {DropList.PositionAnchor?} [position]
|
|
138
|
-
* @property {DropList.PositionAnchor?} [anchor]
|
|
139
|
-
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
140
|
-
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
141
|
-
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
142
|
-
* */
|
|
143
|
-
/** */
|
|
144
|
-
/**
|
|
145
|
-
* @typedef {Object} DropList.ItemBase
|
|
146
|
-
* @property {string} [value]
|
|
147
|
-
* @property {string} [label]
|
|
148
|
-
* @property {boolean} [_group=false]
|
|
149
|
-
* @property {boolean} [_child=false]
|
|
150
|
-
* @property {boolean} [_nocheck=false]
|
|
151
|
-
* @property {boolean} [_nointeraction=false]
|
|
152
|
-
* @property {DropList.ItemBase[]} [_subitems]
|
|
153
|
-
* */
|
|
154
|
-
/**
|
|
155
|
-
* @typedef {DropList.ItemBase} DropList.Item
|
|
156
|
-
* @property {boolean} [_checked=false]
|
|
157
|
-
* */
|
|
158
|
-
/** */
|
|
159
|
-
/** @type {DropList.Options} */
|
|
160
108
|
var DefaultOptions = {
|
|
161
109
|
baseClassName: "droplist",
|
|
162
110
|
autoItemBlur: true,
|
|
@@ -221,6 +169,7 @@ var DropList = class DropList {
|
|
|
221
169
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
222
170
|
on: o.on || null,
|
|
223
171
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
172
|
+
onError: o.onError,
|
|
224
173
|
searchable: o.searchable,
|
|
225
174
|
searchPlaceholder: o.searchPlaceholder,
|
|
226
175
|
isHeaderVisible: o.isHeaderVisible,
|
|
@@ -238,7 +187,14 @@ var DropList = class DropList {
|
|
|
238
187
|
throttledRefilterItems: null,
|
|
239
188
|
focusItemIndex: -1,
|
|
240
189
|
focusItemEl: null,
|
|
241
|
-
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
|
|
242
198
|
};
|
|
243
199
|
let classes = [p.baseClassName + "_wrapper"];
|
|
244
200
|
if (p.additionalClasses) classes = classes.concat((p.additionalClasses + "").split(" ").filter((x) => x));
|
|
@@ -304,7 +260,11 @@ var DropList = class DropList {
|
|
|
304
260
|
};
|
|
305
261
|
else item = items[index];
|
|
306
262
|
}
|
|
307
|
-
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
|
+
});
|
|
308
268
|
itemEl.className = `${p.baseClassName}__item`;
|
|
309
269
|
const classList = itemEl.classList;
|
|
310
270
|
if (item) {
|
|
@@ -462,6 +422,7 @@ var DropList = class DropList {
|
|
|
462
422
|
}
|
|
463
423
|
/**
|
|
464
424
|
* @private
|
|
425
|
+
* @internal
|
|
465
426
|
*/
|
|
466
427
|
_setupUnrenderFunction() {
|
|
467
428
|
const p = this._p;
|
|
@@ -473,12 +434,20 @@ var DropList = class DropList {
|
|
|
473
434
|
if (item === NoResultsItemSymbol) try {
|
|
474
435
|
fnNoResults(item, el);
|
|
475
436
|
} catch (err) {
|
|
476
|
-
|
|
437
|
+
reportError(p.onError, err, {
|
|
438
|
+
source: "unrenderNoResultsItem",
|
|
439
|
+
item,
|
|
440
|
+
el
|
|
441
|
+
});
|
|
477
442
|
}
|
|
478
443
|
else try {
|
|
479
444
|
fn(item[ItemSymbol], el);
|
|
480
445
|
} catch (err) {
|
|
481
|
-
|
|
446
|
+
reportError(p.onError, err, {
|
|
447
|
+
source: "unrenderItem",
|
|
448
|
+
item: item[ItemSymbol],
|
|
449
|
+
el
|
|
450
|
+
});
|
|
482
451
|
}
|
|
483
452
|
delete el[ItemSymbol];
|
|
484
453
|
if (p.focusItemEl === el) p.focusItemEl = null;
|
|
@@ -498,6 +467,7 @@ var DropList = class DropList {
|
|
|
498
467
|
p.valueProp = prop;
|
|
499
468
|
return this;
|
|
500
469
|
}
|
|
470
|
+
/** @internal */
|
|
501
471
|
_syncBaseClasses() {
|
|
502
472
|
const p = this._p, el = p.el;
|
|
503
473
|
if (!el) return;
|
|
@@ -536,7 +506,7 @@ var DropList = class DropList {
|
|
|
536
506
|
goToLast(event) {
|
|
537
507
|
this._move("last", event);
|
|
538
508
|
}
|
|
539
|
-
toggleFocusedItem() {
|
|
509
|
+
toggleFocusedItem(event) {
|
|
540
510
|
const p = this._p;
|
|
541
511
|
if (this.hasFocusedItem() && p.multi) {
|
|
542
512
|
let item = (p.filteredItems ?? p.items)[p.focusItemIndex];
|
|
@@ -657,7 +627,7 @@ var DropList = class DropList {
|
|
|
657
627
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
658
628
|
if (hasOwnProperty.call(newItem, "_nocheck")) item._nocheck = !!newItem._nocheck;
|
|
659
629
|
if (hasOwnProperty.call(newItem, "_nointeraction")) item._nointeraction = !!newItem._nointeraction;
|
|
660
|
-
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems =
|
|
630
|
+
if (hasOwnProperty.call(newItem, "_subitems")) item._subitems = newItem._subitems;
|
|
661
631
|
if (p.multi) {
|
|
662
632
|
if (hasOwnProperty.call(newItem, "_checked")) item._checked = !!newItem._checked;
|
|
663
633
|
}
|
|
@@ -665,10 +635,10 @@ var DropList = class DropList {
|
|
|
665
635
|
if (!!newItem._group !== item._group) {
|
|
666
636
|
if (item._group) p.groupCount--;
|
|
667
637
|
else p.groupCount++;
|
|
668
|
-
|
|
638
|
+
item._group = !!newItem._group;
|
|
669
639
|
}
|
|
670
640
|
}
|
|
671
|
-
if (hasOwnProperty.call(newItem, "_level"))
|
|
641
|
+
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
672
642
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
673
643
|
let virtualItemIndex = itemIndex;
|
|
674
644
|
if (p.filteredItems) {
|
|
@@ -815,6 +785,23 @@ var DropList = class DropList {
|
|
|
815
785
|
return this._p.positionOptionsProvider;
|
|
816
786
|
}
|
|
817
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
|
+
/**
|
|
818
805
|
* @param {string} term
|
|
819
806
|
* @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
|
|
820
807
|
* @returns {DropList}
|
|
@@ -835,6 +822,7 @@ var DropList = class DropList {
|
|
|
835
822
|
return !!(p.throttledRefilterItems.isScheduled() || !p.filteredItems && (p.filterTerm || p.filterOnEmptyTerm && p.filterFn));
|
|
836
823
|
}
|
|
837
824
|
/** @private */
|
|
825
|
+
/** @internal */
|
|
838
826
|
_refilterItems() {
|
|
839
827
|
const p = this._p;
|
|
840
828
|
const term = p.filterTerm;
|
|
@@ -869,7 +857,7 @@ var DropList = class DropList {
|
|
|
869
857
|
});
|
|
870
858
|
}
|
|
871
859
|
if (!Array.isArray(filteredItems)) if (term) {
|
|
872
|
-
const matcher = new RegExp(
|
|
860
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
873
861
|
filteredItems = p.items.filter((x) => {
|
|
874
862
|
if (!filterGroups && x._group) return true;
|
|
875
863
|
return matcher.test(x.label);
|
|
@@ -946,7 +934,7 @@ var DropList = class DropList {
|
|
|
946
934
|
p.filterThrottleWindow = window;
|
|
947
935
|
let isScheduled = p.throttledRefilterItems ? p.throttledRefilterItems.isScheduled() : false;
|
|
948
936
|
if (p.throttledRefilterItems) p.throttledRefilterItems.cancel();
|
|
949
|
-
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow
|
|
937
|
+
p.throttledRefilterItems = throttle(() => this._refilterItems(), p.filterThrottleWindow);
|
|
950
938
|
if (isScheduled) p.throttledRefilterItems();
|
|
951
939
|
return this;
|
|
952
940
|
}
|
|
@@ -1292,7 +1280,7 @@ var DropList = class DropList {
|
|
|
1292
1280
|
if (this.isVisible()) this._trigger("show");
|
|
1293
1281
|
return this;
|
|
1294
1282
|
}
|
|
1295
|
-
hide() {
|
|
1283
|
+
hide(event) {
|
|
1296
1284
|
const p = this._p, el = p.el;
|
|
1297
1285
|
if (p.onDocumentMouseDown) {
|
|
1298
1286
|
p.sink.remove(document, "mousedown", p.onDocumentMouseDown);
|
|
@@ -1464,6 +1452,7 @@ var DropList = class DropList {
|
|
|
1464
1452
|
}
|
|
1465
1453
|
return this;
|
|
1466
1454
|
}
|
|
1455
|
+
/** @internal */
|
|
1467
1456
|
_showSublist(item, itemElement) {
|
|
1468
1457
|
if (!item._subitems?.length) return;
|
|
1469
1458
|
const p = this._p;
|
|
@@ -1539,6 +1528,7 @@ var DropList = class DropList {
|
|
|
1539
1528
|
droplist.show();
|
|
1540
1529
|
droplist.el.focus();
|
|
1541
1530
|
}
|
|
1531
|
+
/** @internal */
|
|
1542
1532
|
_hideSublist() {
|
|
1543
1533
|
const p = this._p;
|
|
1544
1534
|
if (!p.currentSubDropList) return;
|
|
@@ -1638,6 +1628,7 @@ var DropList = class DropList {
|
|
|
1638
1628
|
}
|
|
1639
1629
|
return this;
|
|
1640
1630
|
}
|
|
1631
|
+
/** @internal */
|
|
1641
1632
|
_scrollItemIndexIntoView(itemIndex) {
|
|
1642
1633
|
const p = this._p;
|
|
1643
1634
|
if (this._hasScroll()) {
|
|
@@ -1701,6 +1692,7 @@ var DropList = class DropList {
|
|
|
1701
1692
|
this._p.mitt.emit(event, value);
|
|
1702
1693
|
return this;
|
|
1703
1694
|
}
|
|
1695
|
+
/** @internal */
|
|
1704
1696
|
_getItemIndex(item) {
|
|
1705
1697
|
const p = this._p;
|
|
1706
1698
|
let itemIndex = -1;
|
|
@@ -1714,6 +1706,7 @@ var DropList = class DropList {
|
|
|
1714
1706
|
}
|
|
1715
1707
|
return itemIndex;
|
|
1716
1708
|
}
|
|
1709
|
+
/** @internal */
|
|
1717
1710
|
_setSingleSelectedItemEl(itemEl, value) {
|
|
1718
1711
|
const p = this._p;
|
|
1719
1712
|
if (p.singleSelectedItemEl) {
|
|
@@ -1731,12 +1724,14 @@ var DropList = class DropList {
|
|
|
1731
1724
|
* @param {string} event
|
|
1732
1725
|
* @param {*} [data]
|
|
1733
1726
|
* @private
|
|
1727
|
+
* @internal
|
|
1734
1728
|
*/
|
|
1735
1729
|
_trigger(event, data) {
|
|
1736
1730
|
const p = this._p;
|
|
1737
1731
|
if (p.on) p.on(event, ...data === void 0 ? [] : [data]);
|
|
1738
1732
|
p.mitt.emit(event, data);
|
|
1739
1733
|
}
|
|
1734
|
+
/** @internal */
|
|
1740
1735
|
_itemUpAction(event, itemEl) {
|
|
1741
1736
|
if ((0, _danielgindi_dom_utils_lib_Dom.closestUntil)(event.target, ".requires-pointer-events,button", itemEl)) return;
|
|
1742
1737
|
let p = this._p;
|
|
@@ -1749,6 +1744,7 @@ var DropList = class DropList {
|
|
|
1749
1744
|
}, 0);
|
|
1750
1745
|
}
|
|
1751
1746
|
}
|
|
1747
|
+
/** @internal */
|
|
1752
1748
|
_hookMouseEvents() {
|
|
1753
1749
|
const p = this._p;
|
|
1754
1750
|
p.sink.add(p.el, "mouseup", (event) => {
|
|
@@ -1762,9 +1758,11 @@ var DropList = class DropList {
|
|
|
1762
1758
|
this._handleMouseOver(event, li);
|
|
1763
1759
|
});
|
|
1764
1760
|
}
|
|
1761
|
+
/** @internal */
|
|
1765
1762
|
_handleMouseOver(event, itemEl) {
|
|
1766
1763
|
this._focus(event, itemEl, null, true);
|
|
1767
1764
|
}
|
|
1765
|
+
/** @internal */
|
|
1768
1766
|
_hookTouchEvents() {
|
|
1769
1767
|
const p = this._p;
|
|
1770
1768
|
let currentTouchId;
|
|
@@ -1804,6 +1802,7 @@ var DropList = class DropList {
|
|
|
1804
1802
|
});
|
|
1805
1803
|
});
|
|
1806
1804
|
}
|
|
1805
|
+
/** @internal */
|
|
1807
1806
|
_hookFocusEvents() {
|
|
1808
1807
|
const p = this._p;
|
|
1809
1808
|
p.sink.add(p.el, "focus", (event) => {
|
|
@@ -1821,10 +1820,12 @@ var DropList = class DropList {
|
|
|
1821
1820
|
});
|
|
1822
1821
|
}, true);
|
|
1823
1822
|
}
|
|
1823
|
+
/** @internal */
|
|
1824
1824
|
_hookKeyEvents() {
|
|
1825
1825
|
const p = this._p;
|
|
1826
1826
|
p.sink.add(p.el, "keydown", (evt) => this._keydown(evt));
|
|
1827
1827
|
}
|
|
1828
|
+
/** @internal */
|
|
1828
1829
|
_hookSearchEvents() {
|
|
1829
1830
|
const p = this._p;
|
|
1830
1831
|
if (!p.searchInput) return;
|
|
@@ -1835,6 +1836,7 @@ var DropList = class DropList {
|
|
|
1835
1836
|
p.throttledRefilterItems();
|
|
1836
1837
|
});
|
|
1837
1838
|
}
|
|
1839
|
+
/** @internal */
|
|
1838
1840
|
_keydown(event) {
|
|
1839
1841
|
const p = this._p;
|
|
1840
1842
|
if (p.keyDownHandler && p.keyDownHandler.call(this, event)) return;
|
|
@@ -1897,6 +1899,7 @@ var DropList = class DropList {
|
|
|
1897
1899
|
if (!p.searchable) this._keydownFreeType(event, !this.isVisible());
|
|
1898
1900
|
}
|
|
1899
1901
|
}
|
|
1902
|
+
/** @internal */
|
|
1900
1903
|
_keydownFreeType(evt, autoSelect) {
|
|
1901
1904
|
const p = this._p;
|
|
1902
1905
|
const character = evt.key || String.fromCharCode(evt.keyCode);
|
|
@@ -1905,7 +1908,7 @@ var DropList = class DropList {
|
|
|
1905
1908
|
if (!isChar) return;
|
|
1906
1909
|
clearTimeout(p.filterTimer);
|
|
1907
1910
|
let keyword = (p.previousFilter || "") + character;
|
|
1908
|
-
let regex = new RegExp(`^${
|
|
1911
|
+
let regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1909
1912
|
let matchIndex = -1;
|
|
1910
1913
|
let item;
|
|
1911
1914
|
let focusItemIndex = p.focusItemIndex;
|
|
@@ -1920,7 +1923,7 @@ var DropList = class DropList {
|
|
|
1920
1923
|
}
|
|
1921
1924
|
if (matchIndex === -1) {
|
|
1922
1925
|
keyword = character;
|
|
1923
|
-
regex = new RegExp(`^${
|
|
1926
|
+
regex = new RegExp(`^${escapeRegex(keyword)}`, "i");
|
|
1924
1927
|
for (let i = 0, count = items.length; i < count; i++) {
|
|
1925
1928
|
if (matchIndex !== -1 && i < focusItemIndex) continue;
|
|
1926
1929
|
item = items[i];
|
|
@@ -1940,6 +1943,7 @@ var DropList = class DropList {
|
|
|
1940
1943
|
}, 1e3);
|
|
1941
1944
|
} else delete p.previousFilter;
|
|
1942
1945
|
}
|
|
1946
|
+
/** @internal */
|
|
1943
1947
|
_focus(event, itemEl, itemIndex, openSubitems) {
|
|
1944
1948
|
const p = this._p;
|
|
1945
1949
|
if (p._isFocusingItem) return;
|
|
@@ -1973,6 +1977,7 @@ var DropList = class DropList {
|
|
|
1973
1977
|
p._isFocusingItem = false;
|
|
1974
1978
|
if (openSubitems) this._showSublist(item, focusItemEl);
|
|
1975
1979
|
}
|
|
1980
|
+
/** @internal */
|
|
1976
1981
|
_delayBlurItemOnBlur() {
|
|
1977
1982
|
if (this[DestroyedSymbol$1]) return;
|
|
1978
1983
|
const p = this._p;
|
|
@@ -1983,6 +1988,7 @@ var DropList = class DropList {
|
|
|
1983
1988
|
this.blurFocusedItem();
|
|
1984
1989
|
}, p.autoItemBlurDelay);
|
|
1985
1990
|
}
|
|
1991
|
+
/** @internal */
|
|
1986
1992
|
_move(direction, event) {
|
|
1987
1993
|
const p = this._p;
|
|
1988
1994
|
let next, nextIndex, directionUp;
|
|
@@ -2052,10 +2058,12 @@ var DropList = class DropList {
|
|
|
2052
2058
|
this._focus(event, next || null, nextIndex, false);
|
|
2053
2059
|
if (!this.isVisible()) this.triggerItemSelection(item, event);
|
|
2054
2060
|
}
|
|
2061
|
+
/** @internal */
|
|
2055
2062
|
_hasScroll() {
|
|
2056
2063
|
const menuEl = this._p.menuEl;
|
|
2057
2064
|
return menuEl.clientHeight < menuEl.scrollHeight;
|
|
2058
2065
|
}
|
|
2066
|
+
/** @internal */
|
|
2059
2067
|
_updateGroupStateForItem(item) {
|
|
2060
2068
|
const p = this._p;
|
|
2061
2069
|
if (!p.multi) return this;
|
|
@@ -2099,6 +2107,7 @@ var DropList = class DropList {
|
|
|
2099
2107
|
}
|
|
2100
2108
|
return this;
|
|
2101
2109
|
}
|
|
2110
|
+
/** @internal */
|
|
2102
2111
|
_updateGroupCheckedState(groupIndex, fireEvents) {
|
|
2103
2112
|
const p = this._p;
|
|
2104
2113
|
if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1)) return this;
|
|
@@ -2132,6 +2141,7 @@ var DropList = class DropList {
|
|
|
2132
2141
|
/**
|
|
2133
2142
|
* @private
|
|
2134
2143
|
* @returns {DropList} self
|
|
2144
|
+
* @internal
|
|
2135
2145
|
*/
|
|
2136
2146
|
_measureItem() {
|
|
2137
2147
|
const p = this._p;
|
|
@@ -2179,6 +2189,7 @@ var DropList = class DropList {
|
|
|
2179
2189
|
* @param {number?} targetItemCount - item count we are expecting. Defaults to current item count
|
|
2180
2190
|
* @returns {DropList}
|
|
2181
2191
|
* @private
|
|
2192
|
+
* @internal
|
|
2182
2193
|
*/
|
|
2183
2194
|
_determineVirtualMode(targetItemCount) {
|
|
2184
2195
|
const p = this._p;
|
|
@@ -2188,6 +2199,7 @@ var DropList = class DropList {
|
|
|
2188
2199
|
if (shouldBeVirtual !== p.virtualListHelper.isVirtual()) p.virtualListHelper.setVirtual(shouldBeVirtual).render();
|
|
2189
2200
|
return this;
|
|
2190
2201
|
}
|
|
2202
|
+
/** @internal */
|
|
2191
2203
|
_renderItemContent(item, itemEl) {
|
|
2192
2204
|
const p = this._p;
|
|
2193
2205
|
const originalItem = item[ItemSymbol];
|
|
@@ -2209,17 +2221,12 @@ var DropList = class DropList {
|
|
|
2209
2221
|
}
|
|
2210
2222
|
}
|
|
2211
2223
|
}
|
|
2212
|
-
/**
|
|
2213
|
-
*
|
|
2214
|
-
* @param {DropList.PositionOptions} [positionOptions=undefined]
|
|
2215
|
-
* @returns {number} new outer width
|
|
2216
|
-
* @private
|
|
2217
|
-
*/
|
|
2224
|
+
/** @internal */
|
|
2218
2225
|
_updateWidth(positionOptions) {
|
|
2219
2226
|
const p = this._p, el = p.el;
|
|
2220
2227
|
let targetWidth = 0;
|
|
2221
2228
|
if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2222
|
-
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.
|
|
2229
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2223
2230
|
else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
|
|
2224
2231
|
let autoWidth = 0;
|
|
2225
2232
|
if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
@@ -2241,7 +2248,7 @@ var DropList = class DropList {
|
|
|
2241
2248
|
}
|
|
2242
2249
|
};
|
|
2243
2250
|
//#endregion
|
|
2244
|
-
//#region lib/SelectBox.
|
|
2251
|
+
//#region src/lib/SelectBox.ts
|
|
2245
2252
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2246
2253
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2247
2254
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2267,57 +2274,6 @@ var inputBackbufferCssProps = [
|
|
|
2267
2274
|
"padding-left",
|
|
2268
2275
|
"padding-right"
|
|
2269
2276
|
];
|
|
2270
|
-
/**
|
|
2271
|
-
* @typedef {Object} SelectBox.Options
|
|
2272
|
-
* @property {DropList.Options} [listOptions] options to pass to the `DropList`
|
|
2273
|
-
* @property {Element} [el] An element to attach to, instead of creating a new one
|
|
2274
|
-
* @property {string} [baseClassName='selectbox'] class name for the menu root element
|
|
2275
|
-
* @property {string|string[]} [additionalClasses]
|
|
2276
|
-
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
2277
|
-
* @property {boolean} [disabled=false] Should start as disabled?
|
|
2278
|
-
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
2279
|
-
* @property {boolean} [clearable=true] Has clear button?
|
|
2280
|
-
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
2281
|
-
* @property {string} [placeholder=''] Placeholder text
|
|
2282
|
-
* @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
|
|
2283
|
-
* @property {boolean} [sortListItems=false] Sort list items
|
|
2284
|
-
* @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
|
|
2285
|
-
* @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
|
|
2286
|
-
* @property {*[]} [stickyValues]
|
|
2287
|
-
* @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
|
|
2288
|
-
* @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortListCheckedFirst` only
|
|
2289
|
-
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
2290
|
-
* @property {boolean} [multi=false] can multiple values be selected?
|
|
2291
|
-
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
2292
|
-
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
2293
|
-
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
2294
|
-
* @property {string} [labelProp='label']
|
|
2295
|
-
* @property {string} [valueProp='value']
|
|
2296
|
-
* @property {string} [multiItemLabelProp='short_label']
|
|
2297
|
-
* @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
|
|
2298
|
-
* @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
|
|
2299
|
-
* @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
|
|
2300
|
-
* @property {DropList.ItemBase[]|null} [items] initial items
|
|
2301
|
-
* @property {*[]|null} [selectedValues] initial selected values
|
|
2302
|
-
* @property {*|*[]|null} [value] initial selected value
|
|
2303
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
|
|
2304
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
|
|
2305
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
|
|
2306
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderMultiItem]
|
|
2307
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
|
|
2308
|
-
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
|
|
2309
|
-
* @property {boolean} [searchable=false] is it searchable?
|
|
2310
|
-
* @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
|
|
2311
|
-
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
2312
|
-
* @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.
|
|
2313
|
-
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
2314
|
-
* @property {boolean} [filterOnEmptyTerm=false] call the filter function on empty search term too
|
|
2315
|
-
* @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
|
|
2316
|
-
* @property {function(name: string, ...args)} [on]
|
|
2317
|
-
* @property {boolean} [isLoadingMode]
|
|
2318
|
-
* @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
|
|
2319
|
-
* @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>
|
|
2320
|
-
* */
|
|
2321
2277
|
var DefaultOptions$1 = {
|
|
2322
2278
|
el: null,
|
|
2323
2279
|
baseClassName: "selectbox",
|
|
@@ -2436,6 +2392,7 @@ var SelectBox = class {
|
|
|
2436
2392
|
on: o.on || null,
|
|
2437
2393
|
silenceEvents: true,
|
|
2438
2394
|
mitt: (0, mitt.default)(),
|
|
2395
|
+
onError: o.onError,
|
|
2439
2396
|
isLoadingMode: !!o.isLoadingMode,
|
|
2440
2397
|
closeListWhenLoading: !!o.closeListWhenLoading,
|
|
2441
2398
|
clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
|
|
@@ -2451,7 +2408,11 @@ var SelectBox = class {
|
|
|
2451
2408
|
filterThrottleWindow: o.filterThrottleWindow,
|
|
2452
2409
|
filterOnEmptyTerm: o.filterOnEmptyTerm,
|
|
2453
2410
|
filterFn: null,
|
|
2454
|
-
filterTerm: ""
|
|
2411
|
+
filterTerm: "",
|
|
2412
|
+
dropListVisible: false,
|
|
2413
|
+
lastActiveElement: null,
|
|
2414
|
+
lastKeyAllowsNonTypeKeys: false,
|
|
2415
|
+
presenceInt: null
|
|
2455
2416
|
};
|
|
2456
2417
|
let el = o.el;
|
|
2457
2418
|
if (el instanceof Element) p.ownsEl = false;
|
|
@@ -3189,7 +3150,7 @@ var SelectBox = class {
|
|
|
3189
3150
|
if (p.filterFn === fn) return this;
|
|
3190
3151
|
p.filterFn = fn;
|
|
3191
3152
|
if (!fn) fn = (items, term) => {
|
|
3192
|
-
const matcher = new RegExp(
|
|
3153
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
3193
3154
|
const labelProp = p.labelProp, multiItemLabelProp = p.multiItemLabelProp;
|
|
3194
3155
|
return p.items.filter((x) => {
|
|
3195
3156
|
if (!p.treatGroupSelectionAsItems && x._group) return true;
|
|
@@ -3207,6 +3168,25 @@ var SelectBox = class {
|
|
|
3207
3168
|
return this._p.filterFn;
|
|
3208
3169
|
}
|
|
3209
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
|
+
/**
|
|
3210
3190
|
* Focus on input element
|
|
3211
3191
|
* @returns {SelectBox}
|
|
3212
3192
|
*/
|
|
@@ -3495,6 +3475,7 @@ var SelectBox = class {
|
|
|
3495
3475
|
* Prepare the mapping between values and items.
|
|
3496
3476
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3497
3477
|
* @private
|
|
3478
|
+
* @internal
|
|
3498
3479
|
*/
|
|
3499
3480
|
_refreshItemByValueMap() {
|
|
3500
3481
|
const p = this._p;
|
|
@@ -3507,6 +3488,7 @@ var SelectBox = class {
|
|
|
3507
3488
|
* @param {*} value
|
|
3508
3489
|
* @returns {DropList.ItemBase|undefined}
|
|
3509
3490
|
* @private
|
|
3491
|
+
* @internal
|
|
3510
3492
|
*/
|
|
3511
3493
|
_getItemByValue(value) {
|
|
3512
3494
|
const p = this._p;
|
|
@@ -3516,6 +3498,7 @@ var SelectBox = class {
|
|
|
3516
3498
|
return p.subitemByValueMap.get(value);
|
|
3517
3499
|
}
|
|
3518
3500
|
/** @private */
|
|
3501
|
+
/** @internal */
|
|
3519
3502
|
_refreshSubitemByValueMap() {
|
|
3520
3503
|
const p = this._p;
|
|
3521
3504
|
const subitemByValueMap = p.subitemByValueMap = /* @__PURE__ */ new Map();
|
|
@@ -3526,6 +3509,7 @@ var SelectBox = class {
|
|
|
3526
3509
|
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
3527
3510
|
* @param {string} valueProp
|
|
3528
3511
|
* @private
|
|
3512
|
+
* @internal
|
|
3529
3513
|
*/
|
|
3530
3514
|
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
3531
3515
|
for (let item of items) {
|
|
@@ -3535,6 +3519,7 @@ var SelectBox = class {
|
|
|
3535
3519
|
}
|
|
3536
3520
|
}
|
|
3537
3521
|
/** @private */
|
|
3522
|
+
/** @internal */
|
|
3538
3523
|
_renderBase() {
|
|
3539
3524
|
const p = this._p;
|
|
3540
3525
|
if (!p.inputBackBuffer) p.inputBackBuffer = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { css: {
|
|
@@ -3623,6 +3608,7 @@ var SelectBox = class {
|
|
|
3623
3608
|
}
|
|
3624
3609
|
/**
|
|
3625
3610
|
* @private
|
|
3611
|
+
* @internal
|
|
3626
3612
|
*/
|
|
3627
3613
|
_syncBaseClasses() {
|
|
3628
3614
|
const p = this._p, el = p.el;
|
|
@@ -3643,6 +3629,7 @@ var SelectBox = class {
|
|
|
3643
3629
|
el.className = classes.join(" ");
|
|
3644
3630
|
}
|
|
3645
3631
|
/** @private */
|
|
3632
|
+
/** @internal */
|
|
3646
3633
|
_setupDropdownMenu() {
|
|
3647
3634
|
const p = this._p;
|
|
3648
3635
|
p.valueProp;
|
|
@@ -3672,6 +3659,7 @@ var SelectBox = class {
|
|
|
3672
3659
|
filterGroups: p.treatGroupSelectionAsItems,
|
|
3673
3660
|
filterEmptyGroups: !p.treatGroupSelectionAsItems,
|
|
3674
3661
|
filterFn: p.actualFilterFn,
|
|
3662
|
+
onError: p.listOptions?.onError ?? p.onError,
|
|
3675
3663
|
positionOptionsProvider: () => this._getDropListPositionOptions(),
|
|
3676
3664
|
on: (name, event) => {
|
|
3677
3665
|
switch (name) {
|
|
@@ -3807,6 +3795,7 @@ var SelectBox = class {
|
|
|
3807
3795
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3808
3796
|
this._registerDropdownEvents();
|
|
3809
3797
|
}
|
|
3798
|
+
/** @internal */
|
|
3810
3799
|
_handleOnBlur() {
|
|
3811
3800
|
const p = this._p;
|
|
3812
3801
|
setTimeout(() => {
|
|
@@ -3818,9 +3807,11 @@ var SelectBox = class {
|
|
|
3818
3807
|
this.closeList();
|
|
3819
3808
|
});
|
|
3820
3809
|
}
|
|
3810
|
+
/** @internal */
|
|
3821
3811
|
_unregisterDropdownEvents() {
|
|
3822
3812
|
this._p.sink.remove(null, ".dropdown");
|
|
3823
3813
|
}
|
|
3814
|
+
/** @internal */
|
|
3824
3815
|
_registerDropdownEvents() {
|
|
3825
3816
|
const p = this._p;
|
|
3826
3817
|
this._unregisterDropdownEvents();
|
|
@@ -3958,6 +3949,7 @@ var SelectBox = class {
|
|
|
3958
3949
|
}).add(p.el, "touchcancel.dropdown_touchextra", onTouchCancel);
|
|
3959
3950
|
});
|
|
3960
3951
|
}
|
|
3952
|
+
/** @internal */
|
|
3961
3953
|
_performSelectWithEvent(item, value) {
|
|
3962
3954
|
let cancellable = {
|
|
3963
3955
|
value,
|
|
@@ -3974,6 +3966,7 @@ var SelectBox = class {
|
|
|
3974
3966
|
});
|
|
3975
3967
|
return true;
|
|
3976
3968
|
}
|
|
3969
|
+
/** @internal */
|
|
3977
3970
|
_performClearWithEvent(clearInput = false) {
|
|
3978
3971
|
let cancellable = { cancel: false };
|
|
3979
3972
|
this._trigger("clear:before", cancellable);
|
|
@@ -3984,6 +3977,7 @@ var SelectBox = class {
|
|
|
3984
3977
|
this._trigger("clear");
|
|
3985
3978
|
return true;
|
|
3986
3979
|
}
|
|
3980
|
+
/** @internal */
|
|
3987
3981
|
_movePrev() {
|
|
3988
3982
|
const p = this._p;
|
|
3989
3983
|
if (this.isMultiEnabled()) return;
|
|
@@ -3997,6 +3991,7 @@ var SelectBox = class {
|
|
|
3997
3991
|
else this._performClearWithEvent();
|
|
3998
3992
|
}
|
|
3999
3993
|
}
|
|
3994
|
+
/** @internal */
|
|
4000
3995
|
_moveNext() {
|
|
4001
3996
|
const p = this._p;
|
|
4002
3997
|
if (this.isMultiEnabled()) return;
|
|
@@ -4011,6 +4006,7 @@ var SelectBox = class {
|
|
|
4011
4006
|
}
|
|
4012
4007
|
}
|
|
4013
4008
|
/** @private */
|
|
4009
|
+
/** @internal */
|
|
4014
4010
|
_updateListItems() {
|
|
4015
4011
|
const p = this._p;
|
|
4016
4012
|
const dropList = p.dropList;
|
|
@@ -4040,6 +4036,7 @@ var SelectBox = class {
|
|
|
4040
4036
|
if (hasRefocusedItem) p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
|
|
4041
4037
|
}
|
|
4042
4038
|
/** @private */
|
|
4039
|
+
/** @internal */
|
|
4043
4040
|
_setSelectedItems(items) {
|
|
4044
4041
|
const p = this._p, valueProp = p.valueProp;
|
|
4045
4042
|
if (p.multi) {
|
|
@@ -4055,6 +4052,7 @@ var SelectBox = class {
|
|
|
4055
4052
|
this._scheduleSync("full");
|
|
4056
4053
|
}
|
|
4057
4054
|
/** @private */
|
|
4055
|
+
/** @internal */
|
|
4058
4056
|
_scheduleSync(mode, data) {
|
|
4059
4057
|
const p = this._p;
|
|
4060
4058
|
if (!p.syncQueue) p.syncQueue = [];
|
|
@@ -4072,6 +4070,7 @@ var SelectBox = class {
|
|
|
4072
4070
|
});
|
|
4073
4071
|
}
|
|
4074
4072
|
/** @private */
|
|
4073
|
+
/** @internal */
|
|
4075
4074
|
_performSync(queue) {
|
|
4076
4075
|
const p = this._p;
|
|
4077
4076
|
if (this[DestroyedSymbol]) return;
|
|
@@ -4125,13 +4124,18 @@ var SelectBox = class {
|
|
|
4125
4124
|
}
|
|
4126
4125
|
}
|
|
4127
4126
|
/** @private */
|
|
4127
|
+
/** @internal */
|
|
4128
4128
|
_cleanupSingleWrapper() {
|
|
4129
4129
|
const p = this._p;
|
|
4130
4130
|
if (!p.singleWrapper) return;
|
|
4131
4131
|
if (p.unrenderSingleItem && p.singleWrapper.childNodes.length > 0) try {
|
|
4132
4132
|
p.unrenderSingleItem(p.singleWrapper[ItemSymbol], p.singleWrapper);
|
|
4133
4133
|
} catch (err) {
|
|
4134
|
-
|
|
4134
|
+
reportError(p.onError, err, {
|
|
4135
|
+
source: "unrenderSingleItem",
|
|
4136
|
+
item: p.singleWrapper[ItemSymbol],
|
|
4137
|
+
el: p.singleWrapper
|
|
4138
|
+
});
|
|
4135
4139
|
}
|
|
4136
4140
|
delete p.singleWrapper[ItemSymbol];
|
|
4137
4141
|
p.singleWrapper.innerHTML = "";
|
|
@@ -4139,6 +4143,7 @@ var SelectBox = class {
|
|
|
4139
4143
|
/**
|
|
4140
4144
|
* @param {number} index
|
|
4141
4145
|
* @private
|
|
4146
|
+
* @internal
|
|
4142
4147
|
*/
|
|
4143
4148
|
_removeMultiItemElementByIndex(index) {
|
|
4144
4149
|
const p = this._p, multiItemEls = p.multiItemEls;
|
|
@@ -4149,7 +4154,11 @@ var SelectBox = class {
|
|
|
4149
4154
|
if (unrender && itemEl.childNodes.length > 0) try {
|
|
4150
4155
|
unrender(item, itemEl);
|
|
4151
4156
|
} catch (err) {
|
|
4152
|
-
|
|
4157
|
+
reportError(p.onError, err, {
|
|
4158
|
+
source: item?.[p.valueProp] === RestMultiItemsSymbol ? "unrenderRestMultiItem" : "unrenderMultiItem",
|
|
4159
|
+
item,
|
|
4160
|
+
el: itemEl
|
|
4161
|
+
});
|
|
4153
4162
|
}
|
|
4154
4163
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(itemEl);
|
|
4155
4164
|
if (index === multiItemEls.length - 1) multiItemEls.pop();
|
|
@@ -4159,6 +4168,7 @@ var SelectBox = class {
|
|
|
4159
4168
|
/**
|
|
4160
4169
|
* @param {DropList.ItemBase} item
|
|
4161
4170
|
* @private
|
|
4171
|
+
* @internal
|
|
4162
4172
|
*/
|
|
4163
4173
|
_renderSingleItemContent(item) {
|
|
4164
4174
|
const p = this._p;
|
|
@@ -4173,6 +4183,7 @@ var SelectBox = class {
|
|
|
4173
4183
|
* @param {DropList.ItemBase} item
|
|
4174
4184
|
* @param {Element} itemEl
|
|
4175
4185
|
* @private
|
|
4186
|
+
* @internal
|
|
4176
4187
|
*/
|
|
4177
4188
|
_renderMultiItemContent(item, itemEl) {
|
|
4178
4189
|
const p = this._p;
|
|
@@ -4187,6 +4198,7 @@ var SelectBox = class {
|
|
|
4187
4198
|
* @param {DropList.ItemBase} item
|
|
4188
4199
|
* @returns {boolean} true if rendered, false if not
|
|
4189
4200
|
* @private
|
|
4201
|
+
* @internal
|
|
4190
4202
|
*/
|
|
4191
4203
|
_addMultiItemElement(item) {
|
|
4192
4204
|
const p = this._p;
|
|
@@ -4197,6 +4209,7 @@ var SelectBox = class {
|
|
|
4197
4209
|
return true;
|
|
4198
4210
|
}
|
|
4199
4211
|
/** @private */
|
|
4212
|
+
/** @internal */
|
|
4200
4213
|
_addMultiItemRestElement() {
|
|
4201
4214
|
const p = this._p;
|
|
4202
4215
|
let items = p.selectedItems.slice(0);
|
|
@@ -4209,6 +4222,7 @@ var SelectBox = class {
|
|
|
4209
4222
|
});
|
|
4210
4223
|
}
|
|
4211
4224
|
/** @private */
|
|
4225
|
+
/** @internal */
|
|
4212
4226
|
_syncClearButton() {
|
|
4213
4227
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4214
4228
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
@@ -4231,6 +4245,7 @@ var SelectBox = class {
|
|
|
4231
4245
|
}
|
|
4232
4246
|
}
|
|
4233
4247
|
/** @private */
|
|
4248
|
+
/** @internal */
|
|
4234
4249
|
_syncPlaceholder() {
|
|
4235
4250
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
4236
4251
|
let placeholder = "";
|
|
@@ -4242,6 +4257,7 @@ var SelectBox = class {
|
|
|
4242
4257
|
else p.input.removeAttribute("title");
|
|
4243
4258
|
}
|
|
4244
4259
|
/** @private */
|
|
4260
|
+
/** @internal */
|
|
4245
4261
|
_syncSingleItem() {
|
|
4246
4262
|
const p = this._p;
|
|
4247
4263
|
if (p.singleWrapper) this._cleanupSingleWrapper();
|
|
@@ -4256,6 +4272,7 @@ var SelectBox = class {
|
|
|
4256
4272
|
* @param {boolean=false} fullItemsRender Should re-render all items?
|
|
4257
4273
|
* @param {boolean=false} updateListItems Should call updateListItems?
|
|
4258
4274
|
* @returns {SelectBox}
|
|
4275
|
+
* @internal
|
|
4259
4276
|
*/
|
|
4260
4277
|
_syncFull(fullItemsRender, updateListItems) {
|
|
4261
4278
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
@@ -4316,6 +4333,7 @@ var SelectBox = class {
|
|
|
4316
4333
|
* @param {string} event
|
|
4317
4334
|
* @param {*} [data]
|
|
4318
4335
|
* @private
|
|
4336
|
+
* @internal
|
|
4319
4337
|
*/
|
|
4320
4338
|
_trigger(event, data) {
|
|
4321
4339
|
const p = this._p;
|
|
@@ -4328,6 +4346,7 @@ var SelectBox = class {
|
|
|
4328
4346
|
* @param {Object} item
|
|
4329
4347
|
* @returns {Element|null}
|
|
4330
4348
|
* @private
|
|
4349
|
+
* @internal
|
|
4331
4350
|
*/
|
|
4332
4351
|
_renderMultiItem(item) {
|
|
4333
4352
|
const p = this._p;
|
|
@@ -4355,6 +4374,7 @@ var SelectBox = class {
|
|
|
4355
4374
|
* @param {Event} originatingEvent
|
|
4356
4375
|
* @returns {SelectBox}
|
|
4357
4376
|
* @private
|
|
4377
|
+
* @internal
|
|
4358
4378
|
*/
|
|
4359
4379
|
_removeMultiItemFromEvent(itemEl, originatingEvent) {
|
|
4360
4380
|
const p = this._p;
|
|
@@ -4370,7 +4390,7 @@ var SelectBox = class {
|
|
|
4370
4390
|
let itemsToRemove = [];
|
|
4371
4391
|
for (let item of items) {
|
|
4372
4392
|
let removeselEvt = {
|
|
4373
|
-
value,
|
|
4393
|
+
value: item[p.valueProp],
|
|
4374
4394
|
item,
|
|
4375
4395
|
cancel: false
|
|
4376
4396
|
};
|
|
@@ -4381,7 +4401,7 @@ var SelectBox = class {
|
|
|
4381
4401
|
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4382
4402
|
for (let item of itemsToRemove) {
|
|
4383
4403
|
let idx = p.selectedItems.indexOf(item);
|
|
4384
|
-
if (idx === -1) idx = p.selectedValues.indexOf(
|
|
4404
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4385
4405
|
if (idx !== -1) {
|
|
4386
4406
|
p.selectedItems.splice(idx, 1);
|
|
4387
4407
|
p.selectedValues.splice(idx, 1);
|
|
@@ -4415,6 +4435,7 @@ var SelectBox = class {
|
|
|
4415
4435
|
* @param {DropList.ItemBase} item
|
|
4416
4436
|
* @param {boolean} [populate]
|
|
4417
4437
|
* @private
|
|
4438
|
+
* @internal
|
|
4418
4439
|
*/
|
|
4419
4440
|
_removeMultiItem(item, populate = false) {
|
|
4420
4441
|
const p = this._p;
|
|
@@ -4441,6 +4462,7 @@ var SelectBox = class {
|
|
|
4441
4462
|
/**
|
|
4442
4463
|
* @param {*} value
|
|
4443
4464
|
* @private
|
|
4465
|
+
* @internal
|
|
4444
4466
|
*/
|
|
4445
4467
|
_setInputText(value) {
|
|
4446
4468
|
const p = this._p;
|
|
@@ -4453,6 +4475,7 @@ var SelectBox = class {
|
|
|
4453
4475
|
* Update input size to current state
|
|
4454
4476
|
* @returns {SelectBox}
|
|
4455
4477
|
* @private
|
|
4478
|
+
* @internal
|
|
4456
4479
|
*/
|
|
4457
4480
|
_resizeInput() {
|
|
4458
4481
|
const p = this._p, el = p.el;
|
|
@@ -4510,6 +4533,7 @@ var SelectBox = class {
|
|
|
4510
4533
|
* Update autocomplete position if needed
|
|
4511
4534
|
* @returns {SelectBox}
|
|
4512
4535
|
* @private
|
|
4536
|
+
* @internal
|
|
4513
4537
|
*/
|
|
4514
4538
|
_repositionDropList() {
|
|
4515
4539
|
const p = this._p, el = p.el;
|
|
@@ -4525,6 +4549,7 @@ var SelectBox = class {
|
|
|
4525
4549
|
/**
|
|
4526
4550
|
* @param {KeyboardEvent} event
|
|
4527
4551
|
* @private
|
|
4552
|
+
* @internal
|
|
4528
4553
|
*/
|
|
4529
4554
|
_handleInputKeydown(event) {
|
|
4530
4555
|
const p = this._p;
|
|
@@ -4555,6 +4580,7 @@ var SelectBox = class {
|
|
|
4555
4580
|
/**
|
|
4556
4581
|
* @param {KeyboardEvent} event
|
|
4557
4582
|
* @private
|
|
4583
|
+
* @internal
|
|
4558
4584
|
*/
|
|
4559
4585
|
_handleMultiKeydown(event) {
|
|
4560
4586
|
const p = this._p;
|
|
@@ -4600,6 +4626,7 @@ var SelectBox = class {
|
|
|
4600
4626
|
/**
|
|
4601
4627
|
* @returns {DropList.PositionOptions}
|
|
4602
4628
|
* @private
|
|
4629
|
+
* @internal
|
|
4603
4630
|
*/
|
|
4604
4631
|
_getDropListPositionOptions() {
|
|
4605
4632
|
return {
|
|
@@ -4620,6 +4647,7 @@ var SelectBox = class {
|
|
|
4620
4647
|
};
|
|
4621
4648
|
}
|
|
4622
4649
|
/** @private */
|
|
4650
|
+
/** @internal */
|
|
4623
4651
|
_startTrackingPresence() {
|
|
4624
4652
|
const p = this._p;
|
|
4625
4653
|
this._stopTrackingPresence();
|
|
@@ -4628,6 +4656,7 @@ var SelectBox = class {
|
|
|
4628
4656
|
}, 200);
|
|
4629
4657
|
}
|
|
4630
4658
|
/** @private */
|
|
4659
|
+
/** @internal */
|
|
4631
4660
|
_stopTrackingPresence() {
|
|
4632
4661
|
const p = this._p;
|
|
4633
4662
|
if (p.presenceInt) {
|
|
@@ -4643,6 +4672,7 @@ var SelectBox = class {
|
|
|
4643
4672
|
* @param {boolean=false} sortCheckedFirst
|
|
4644
4673
|
* @param {boolean=false} splitCheckedGroups
|
|
4645
4674
|
* @returns {DropList.ItemBase[]}
|
|
4675
|
+
* @internal
|
|
4646
4676
|
*/
|
|
4647
4677
|
_sortItems(items, sort, sortCheckedFirst, splitCheckedGroups) {
|
|
4648
4678
|
const p = this._p;
|