@danielgindi/selectbox 2.0.65 → 3.0.0
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/README.md +50 -3
- package/css/droplist.css +1 -1
- package/css/droplist.css.map +1 -1
- package/css/selectbox.css +1 -1
- package/css/selectbox.css.map +1 -1
- package/dist/lib.cjs.js +240 -126
- 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 +241 -126
- 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 +240 -126
- 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 +13 -1
- package/dist/types/DropList.d.ts.map +1 -1
- package/dist/types/SelectBox.d.ts +7 -1
- package/dist/types/SelectBox.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +35 -0
- package/dist/types/types.d.ts.map +1 -1
- package/eslint.config.mjs +153 -151
- package/package.json +26 -16
- package/scss/droplist.scss +62 -71
- package/scss/selectbox.scss +126 -210
- package/vite.config.mjs +29 -0
- package/vue/DropList.vue +29 -15
- package/vue/SelectBox.vue +24 -15
- package/vue/component-types.d.ts +223 -217
- package/vue/utils/slots.js +17 -64
- package/vite.config.js +0 -9
package/dist/lib.es6.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox
|
|
2
|
+
* @danielgindi/selectbox 3.0.0
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { closestUntil, createElement, next, prev, setElementAttrs } from "@danielgindi/dom-utils/lib/Dom";
|
|
6
|
-
import {
|
|
7
|
-
import { anchoredPosition, getCssProps, getElementHeight, getElementOffset, getElementWidth,
|
|
6
|
+
import { before, getRootNode, remove, toggleClass } from "@danielgindi/dom-utils/lib/DomCompat";
|
|
7
|
+
import { anchoredPosition, getCssProps, getElementHeight, getElementOffset, getElementWidth, parseTransition, setCssProps, setElementHeight, setElementWidth } from "@danielgindi/dom-utils/lib/Css";
|
|
8
8
|
import DomEventsSink from "@danielgindi/dom-utils/lib/DomEventsSink";
|
|
9
9
|
import VirtualListHelper from "@danielgindi/virtual-list-helper";
|
|
10
10
|
import { VALUE_BACK_SPACE, VALUE_DELETE, VALUE_DOWN, VALUE_END, VALUE_ENTER, VALUE_ESCAPE, VALUE_HOME, VALUE_LEFT, VALUE_PAGE_DOWN, VALUE_PAGE_UP, VALUE_RIGHT, VALUE_SPACE, VALUE_TAB, VALUE_UP } from "keycode-js";
|
|
11
11
|
import mitt from "mitt";
|
|
12
|
-
|
|
12
|
+
// src/lib/utils/escapeRegex.ts
|
|
13
13
|
/** @internal */
|
|
14
14
|
var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
15
|
-
|
|
16
|
-
//#region src/lib/utils/throttle.ts
|
|
15
|
+
// src/lib/utils/throttle.ts
|
|
17
16
|
/** @internal */
|
|
18
17
|
var throttle = (func, wait, options = {}) => {
|
|
19
18
|
let timeout;
|
|
@@ -54,8 +53,7 @@ var throttle = (func, wait, options = {}) => {
|
|
|
54
53
|
};
|
|
55
54
|
return throttled;
|
|
56
55
|
};
|
|
57
|
-
|
|
58
|
-
//#region src/lib/utils/reportError.ts
|
|
56
|
+
// src/lib/utils/reportError.ts
|
|
59
57
|
/**
|
|
60
58
|
* Routes an error/warning to `handler` if supplied, falling back to the
|
|
61
59
|
* console (matching the previous hardcoded behaviour) if there is no
|
|
@@ -72,8 +70,7 @@ var reportError = (handler, error, context) => {
|
|
|
72
70
|
if (context.level === "warn") console.warn(error);
|
|
73
71
|
else console.error(error);
|
|
74
72
|
};
|
|
75
|
-
|
|
76
|
-
//#region src/lib/DropList.ts
|
|
73
|
+
// src/lib/DropList.ts
|
|
77
74
|
var ItemSymbol = Symbol("item");
|
|
78
75
|
var DestroyedSymbol$1 = Symbol("destroyed");
|
|
79
76
|
var GhostSymbol = Symbol("ghost");
|
|
@@ -96,6 +93,7 @@ var DefaultOptions = {
|
|
|
96
93
|
labelProp: "label",
|
|
97
94
|
valueProp: "value",
|
|
98
95
|
on: null,
|
|
96
|
+
zIndex: null,
|
|
99
97
|
isHeaderVisible: false,
|
|
100
98
|
isFooterVisible: false,
|
|
101
99
|
searchable: false,
|
|
@@ -140,6 +138,9 @@ var DropList = class DropList {
|
|
|
140
138
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
141
139
|
on: o.on || null,
|
|
142
140
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
141
|
+
zIndex: o.zIndex ?? null,
|
|
142
|
+
appliedZIndex: null,
|
|
143
|
+
ownerSelectBox: null,
|
|
143
144
|
onError: o.onError,
|
|
144
145
|
searchable: o.searchable,
|
|
145
146
|
searchPlaceholder: o.searchPlaceholder,
|
|
@@ -240,12 +241,13 @@ var DropList = class DropList {
|
|
|
240
241
|
itemEl.className = `${p.baseClassName}__item`;
|
|
241
242
|
const classList = itemEl.classList;
|
|
242
243
|
if (item) {
|
|
243
|
-
if (p.multi)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
if (p.multi) {
|
|
245
|
+
if (item._nocheck) classList.add(`${p.baseClassName}__item_multi_nocheck`);
|
|
246
|
+
else {
|
|
247
|
+
classList.add(`${p.baseClassName}__item_multi`);
|
|
248
|
+
if (item._checked) classList.add(`${p.baseClassName}__item_checked`);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
249
251
|
classList.add(`${p.baseClassName}__item_single`);
|
|
250
252
|
if (p.singleSelectedValue !== void 0 && item.value === p.singleSelectedValue) {
|
|
251
253
|
classList.add(`${p.baseClassName}__item_selected`);
|
|
@@ -557,7 +559,7 @@ var DropList = class DropList {
|
|
|
557
559
|
const p = this._p;
|
|
558
560
|
let itemIndex = this.itemIndexByValue(value);
|
|
559
561
|
if (itemIndex === -1) return this;
|
|
560
|
-
let item =
|
|
562
|
+
let item = p.items[itemIndex];
|
|
561
563
|
item[ItemSymbol] = newItem;
|
|
562
564
|
if (hasOwnProperty.call(newItem, p.labelProp)) item.label = newItem[p.labelProp];
|
|
563
565
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
@@ -577,10 +579,7 @@ var DropList = class DropList {
|
|
|
577
579
|
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
578
580
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
579
581
|
let virtualItemIndex = itemIndex;
|
|
580
|
-
if (p.filteredItems)
|
|
581
|
-
virtualItemIndex = p.filteredItems.indexOf(item);
|
|
582
|
-
if (virtualItemIndex !== -1) p.filteredItems.splice(virtualItemIndex, 1);
|
|
583
|
-
}
|
|
582
|
+
if (p.filteredItems) virtualItemIndex = p.filteredItems.indexOf(item);
|
|
584
583
|
if (virtualItemIndex !== -1 && p.virtualListHelper.isItemRendered(virtualItemIndex)) p.virtualListHelper.refreshItemAt(virtualItemIndex).render();
|
|
585
584
|
return this;
|
|
586
585
|
}
|
|
@@ -598,7 +597,7 @@ var DropList = class DropList {
|
|
|
598
597
|
if (virtualItemIndex !== -1) {
|
|
599
598
|
p.hasNoResultsItem = (p.filteredItems ?? p.items).length === 0 && !!p.noResultsText;
|
|
600
599
|
if (p.hasNoResultsItem) p.virtualListHelper.setCount(1).render();
|
|
601
|
-
else p.virtualListHelper.removeItemsAt(
|
|
600
|
+
else p.virtualListHelper.removeItemsAt(1, virtualItemIndex).render();
|
|
602
601
|
}
|
|
603
602
|
return this;
|
|
604
603
|
}
|
|
@@ -710,6 +709,70 @@ var DropList = class DropList {
|
|
|
710
709
|
return this._p.positionOptionsProvider;
|
|
711
710
|
}
|
|
712
711
|
/**
|
|
712
|
+
* Sets the z-index: a fixed value, a resolver function, or `null` to use the CSS z-index.
|
|
713
|
+
* Applied immediately if the DropList is visible.
|
|
714
|
+
*/
|
|
715
|
+
setZIndex(zIndex) {
|
|
716
|
+
const p = this._p;
|
|
717
|
+
zIndex = zIndex ?? null;
|
|
718
|
+
if (p.zIndex === zIndex) return this;
|
|
719
|
+
p.zIndex = zIndex;
|
|
720
|
+
this.updateZIndex();
|
|
721
|
+
return this;
|
|
722
|
+
}
|
|
723
|
+
getZIndex() {
|
|
724
|
+
return this._p.zIndex;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Re-resolves the z-index (re-invoking a resolver function) and applies it.
|
|
728
|
+
* The z-index is resolved automatically on `show()`, so call this only when the stacking
|
|
729
|
+
* order around the owner changes while the DropList is open. Does nothing while hidden.
|
|
730
|
+
*/
|
|
731
|
+
updateZIndex() {
|
|
732
|
+
const p = this._p;
|
|
733
|
+
if (!this.isVisible()) return this;
|
|
734
|
+
this._applyZIndex(p.positionOptionsProvider?.() ?? p.lastPositionOptions ?? null);
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Marks this DropList as owned by a SelectBox, for `DropListZIndexContext`.
|
|
739
|
+
* @internal
|
|
740
|
+
*/
|
|
741
|
+
_setOwnerSelectBox(selectBox) {
|
|
742
|
+
this._p.ownerSelectBox = selectBox;
|
|
743
|
+
}
|
|
744
|
+
/** @internal */
|
|
745
|
+
_resolveZIndex(positionOptions) {
|
|
746
|
+
const p = this._p;
|
|
747
|
+
const option = p.zIndex;
|
|
748
|
+
let zIndex;
|
|
749
|
+
if (typeof option === "function") {
|
|
750
|
+
const context = {
|
|
751
|
+
dropList: this,
|
|
752
|
+
owner: p.ownerSelectBox?.el ?? positionOptions?.target ?? null,
|
|
753
|
+
selectBox: p.ownerSelectBox,
|
|
754
|
+
positionOptions
|
|
755
|
+
};
|
|
756
|
+
try {
|
|
757
|
+
zIndex = option(context);
|
|
758
|
+
} catch (err) {
|
|
759
|
+
reportError(p.onError, err, { source: "zIndex" });
|
|
760
|
+
zIndex = null;
|
|
761
|
+
}
|
|
762
|
+
} else zIndex = option;
|
|
763
|
+
if (zIndex == null || zIndex === "") return null;
|
|
764
|
+
return String(zIndex);
|
|
765
|
+
}
|
|
766
|
+
/** @internal */
|
|
767
|
+
_applyZIndex(positionOptions) {
|
|
768
|
+
const p = this._p;
|
|
769
|
+
const zIndex = this._resolveZIndex(positionOptions);
|
|
770
|
+
if (zIndex !== null) p.el.style.zIndex = zIndex;
|
|
771
|
+
else if (p.appliedZIndex !== null) p.el.style.zIndex = "";
|
|
772
|
+
p.appliedZIndex = zIndex;
|
|
773
|
+
p.currentSubDropList?.droplist?.updateZIndex();
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
713
776
|
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
714
777
|
* instead of the default `console.error`/`console.warn`.
|
|
715
778
|
*/
|
|
@@ -778,13 +841,15 @@ var DropList = class DropList {
|
|
|
778
841
|
return our;
|
|
779
842
|
});
|
|
780
843
|
}
|
|
781
|
-
if (!Array.isArray(filteredItems))
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
844
|
+
if (!Array.isArray(filteredItems)) {
|
|
845
|
+
if (term) {
|
|
846
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
847
|
+
filteredItems = p.items.filter((x) => {
|
|
848
|
+
if (!filterGroups && x._group) return true;
|
|
849
|
+
return matcher.test(x.label);
|
|
850
|
+
});
|
|
851
|
+
} else filteredItems = null;
|
|
852
|
+
}
|
|
788
853
|
p.filteredItems = filteredItems;
|
|
789
854
|
if (filteredItems && filterEmptyGroups) {
|
|
790
855
|
let lastGroup = -1;
|
|
@@ -995,8 +1060,10 @@ var DropList = class DropList {
|
|
|
995
1060
|
};
|
|
996
1061
|
viewCss.left += anchor.left - position.left;
|
|
997
1062
|
if (positionOptions.offset) {
|
|
998
|
-
if (positionOptions.offset.y)
|
|
999
|
-
|
|
1063
|
+
if (positionOptions.offset.y) {
|
|
1064
|
+
if (invertYPos) viewCss.top -= positionOptions.offset.y;
|
|
1065
|
+
else viewCss.top += positionOptions.offset.y;
|
|
1066
|
+
}
|
|
1000
1067
|
if (positionOptions.offset.x) {
|
|
1001
1068
|
let rtl = elComputedStyle.direction === "rtl";
|
|
1002
1069
|
viewCss.left += rtl ? -positionOptions.offset.x : positionOptions.offset.x;
|
|
@@ -1126,6 +1193,7 @@ var DropList = class DropList {
|
|
|
1126
1193
|
p.lastPositionOptions = null;
|
|
1127
1194
|
if (positionOptions === void 0) positionOptions = p.positionOptionsProvider?.() ?? p.lastPositionOptions;
|
|
1128
1195
|
else p.lastPositionOptions = positionOptions;
|
|
1196
|
+
this._applyZIndex(positionOptions ?? null);
|
|
1129
1197
|
if (positionOptions) {
|
|
1130
1198
|
const elComputedStyle = getComputedStyle(el);
|
|
1131
1199
|
const originalMaxHeight = el.style.maxHeight;
|
|
@@ -1327,7 +1395,8 @@ var DropList = class DropList {
|
|
|
1327
1395
|
valueProp: p.valueProp,
|
|
1328
1396
|
renderItem: p.renderItem,
|
|
1329
1397
|
unrenderItem: p.unrenderItem,
|
|
1330
|
-
positionOptionsProvider: () => p.currentSubDropList.showOptions
|
|
1398
|
+
positionOptionsProvider: () => p.currentSubDropList.showOptions,
|
|
1399
|
+
zIndex: () => this._p?.appliedZIndex ?? null
|
|
1331
1400
|
});
|
|
1332
1401
|
let onBlur = (event) => {
|
|
1333
1402
|
if (this[DestroyedSymbol$1]) return;
|
|
@@ -1950,14 +2019,16 @@ var DropList = class DropList {
|
|
|
1950
2019
|
} else if (p.focusItemEl) {
|
|
1951
2020
|
let base = getElementOffset(p.focusItemEl).top;
|
|
1952
2021
|
let height = getElementHeight(p.el, true);
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
if (
|
|
2022
|
+
let candidate = p.focusItemEl;
|
|
2023
|
+
next = null;
|
|
2024
|
+
while (candidate = direction === "prev_page" ? candidate.previousElementSibling : candidate.nextElementSibling) {
|
|
2025
|
+
if (candidate.tagName !== "LI") continue;
|
|
2026
|
+
next = candidate;
|
|
1957
2027
|
if (direction === "prev_page") {
|
|
1958
2028
|
if (getElementOffset(next).top - base + height <= 0) break;
|
|
1959
2029
|
} else if (getElementOffset(next).top - base - height >= 0) break;
|
|
1960
2030
|
}
|
|
2031
|
+
if (!next) return;
|
|
1961
2032
|
if (next) {
|
|
1962
2033
|
nextIndex = p.virtualListHelper.getItemIndexFromElement(next);
|
|
1963
2034
|
if (nextIndex === void 0) nextIndex = -1;
|
|
@@ -2150,14 +2221,18 @@ var DropList = class DropList {
|
|
|
2150
2221
|
_updateWidth(positionOptions) {
|
|
2151
2222
|
const p = this._p, el = p.el;
|
|
2152
2223
|
let targetWidth = 0;
|
|
2153
|
-
if (positionOptions)
|
|
2154
|
-
|
|
2155
|
-
|
|
2224
|
+
if (positionOptions) {
|
|
2225
|
+
if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2226
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2227
|
+
else targetWidth = getElementWidth(positionOptions.target, true, true);
|
|
2228
|
+
}
|
|
2156
2229
|
let autoWidth = 0;
|
|
2157
|
-
if (!p.useExactTargetWidth || !targetWidth)
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2230
|
+
if (!p.useExactTargetWidth || !targetWidth) {
|
|
2231
|
+
if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
2232
|
+
else {
|
|
2233
|
+
el.style.width = "";
|
|
2234
|
+
autoWidth = getElementWidth(el, true, true);
|
|
2235
|
+
}
|
|
2161
2236
|
}
|
|
2162
2237
|
let newOuterWidth = Math.max(autoWidth, targetWidth);
|
|
2163
2238
|
setElementWidth(el, newOuterWidth, true, true);
|
|
@@ -2172,8 +2247,7 @@ var DropList = class DropList {
|
|
|
2172
2247
|
return newOuterWidth;
|
|
2173
2248
|
}
|
|
2174
2249
|
};
|
|
2175
|
-
|
|
2176
|
-
//#region src/lib/SelectBox.ts
|
|
2250
|
+
// src/lib/SelectBox.ts
|
|
2177
2251
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2178
2252
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2179
2253
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2421,9 +2495,12 @@ var SelectBox = class {
|
|
|
2421
2495
|
remove(p.list);
|
|
2422
2496
|
remove(p.singleWrapper);
|
|
2423
2497
|
remove(p.input);
|
|
2498
|
+
remove(p.inputWrapper);
|
|
2424
2499
|
remove(p.inputBackBuffer);
|
|
2425
2500
|
remove(p.clearButtonWrapper);
|
|
2426
2501
|
remove(p.openIndicator);
|
|
2502
|
+
remove(p.spinner);
|
|
2503
|
+
remove(p.controls);
|
|
2427
2504
|
if (!p.ownsEl) {
|
|
2428
2505
|
for (let name of Array.from(p.el.classList)) if (name.startsWith(p.baseClassName)) p.el.classList.remove(name);
|
|
2429
2506
|
p.el.removeAttribute("role");
|
|
@@ -2509,6 +2586,7 @@ var SelectBox = class {
|
|
|
2509
2586
|
p.itemsChanged = true;
|
|
2510
2587
|
this._refreshItemByValueMap();
|
|
2511
2588
|
if (resetValues) this.setSelectedValues(this.getSelectedValues());
|
|
2589
|
+
else this._scheduleSync("render_list");
|
|
2512
2590
|
this._trigger("itemschanged", {
|
|
2513
2591
|
term: null,
|
|
2514
2592
|
mutated: true,
|
|
@@ -2786,6 +2864,22 @@ var SelectBox = class {
|
|
|
2786
2864
|
this._setupDropdownMenu();
|
|
2787
2865
|
return this;
|
|
2788
2866
|
}
|
|
2867
|
+
/**
|
|
2868
|
+
* Sets `listOptions.zIndex` without recreating the DropList.
|
|
2869
|
+
* `undefined` falls back to `DropListDefaultOptions.zIndex`.
|
|
2870
|
+
*/
|
|
2871
|
+
setListZIndex(zIndex) {
|
|
2872
|
+
const p = this._p;
|
|
2873
|
+
p.listOptions = {
|
|
2874
|
+
...p.listOptions,
|
|
2875
|
+
zIndex
|
|
2876
|
+
};
|
|
2877
|
+
p.dropList?.setZIndex(zIndex === void 0 ? DefaultOptions.zIndex : zIndex);
|
|
2878
|
+
return this;
|
|
2879
|
+
}
|
|
2880
|
+
getListZIndex() {
|
|
2881
|
+
return this._p.listOptions?.zIndex;
|
|
2882
|
+
}
|
|
2789
2883
|
setRenderSingleItem(render, unrender) {
|
|
2790
2884
|
const p = this._p;
|
|
2791
2885
|
p.renderSingleItem = render;
|
|
@@ -3148,6 +3242,10 @@ var SelectBox = class {
|
|
|
3148
3242
|
top: "-9999px",
|
|
3149
3243
|
whiteSpace: "pre"
|
|
3150
3244
|
} });
|
|
3245
|
+
if (!p.controls) {
|
|
3246
|
+
p.controls = createElement("span", { class: `${p.baseClassName}__controls` });
|
|
3247
|
+
p.el.appendChild(p.controls);
|
|
3248
|
+
}
|
|
3151
3249
|
if (!p.input) p.inputWrapper = createElement("span", { class: `${p.baseClassName}__search_wrapper` }, p.input = createElement("input", {
|
|
3152
3250
|
class: `${p.baseClassName}__search_field`,
|
|
3153
3251
|
type: "search",
|
|
@@ -3169,7 +3267,7 @@ var SelectBox = class {
|
|
|
3169
3267
|
this._unregisterDropdownEvents();
|
|
3170
3268
|
const lastActiveElement = document.activeElement;
|
|
3171
3269
|
p.list = createElement("ul", { class: `${p.baseClassName}__list` });
|
|
3172
|
-
p.el.
|
|
3270
|
+
p.el.insertBefore(p.list, p.controls);
|
|
3173
3271
|
p.list.appendChild(p.inputWrapper);
|
|
3174
3272
|
p.el.classList.remove(`${p.baseClassName}__single`);
|
|
3175
3273
|
p.el.classList.add(`${p.baseClassName}__multi`);
|
|
@@ -3198,34 +3296,53 @@ var SelectBox = class {
|
|
|
3198
3296
|
this._unregisterDropdownEvents();
|
|
3199
3297
|
const lastActiveElement = document.activeElement;
|
|
3200
3298
|
p.singleWrapper = createElement("div", { class: `${p.baseClassName}__single_wrapper` });
|
|
3201
|
-
p.el.
|
|
3202
|
-
p.el.
|
|
3299
|
+
p.el.insertBefore(p.singleWrapper, p.controls);
|
|
3300
|
+
p.el.insertBefore(p.inputWrapper, p.controls);
|
|
3203
3301
|
p.el.classList.remove(`${p.baseClassName}__multi`);
|
|
3204
3302
|
p.el.classList.add(`${p.baseClassName}__single`);
|
|
3205
3303
|
if (lastActiveElement === p.input) p.input.focus();
|
|
3206
3304
|
this._registerDropdownEvents();
|
|
3207
3305
|
}
|
|
3208
3306
|
}
|
|
3209
|
-
if (p.hasOpenIndicator !== !!p.openIndicator)
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3307
|
+
if (p.hasOpenIndicator !== !!p.openIndicator) {
|
|
3308
|
+
if (p.hasOpenIndicator) {
|
|
3309
|
+
p.openIndicator = createElement("span", { class: `${p.baseClassName}__open_indicator` });
|
|
3310
|
+
this._insertControl(p.openIndicator);
|
|
3311
|
+
p.el.classList.add(`${p.baseClassName}__has_open_indicator`);
|
|
3312
|
+
} else {
|
|
3313
|
+
remove(p.openIndicator);
|
|
3314
|
+
delete p.openIndicator;
|
|
3315
|
+
p.el.classList.remove(`${p.baseClassName}__has_open_indicator`);
|
|
3316
|
+
}
|
|
3217
3317
|
}
|
|
3218
|
-
if (p.isLoadingMode !== !!p.spinner)
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3318
|
+
if (p.isLoadingMode !== !!p.spinner) {
|
|
3319
|
+
if (p.isLoadingMode) {
|
|
3320
|
+
p.spinner = createElement("span", { class: `${p.baseClassName}__spinner` });
|
|
3321
|
+
this._insertControl(p.spinner);
|
|
3322
|
+
p.el.classList.add(`${p.baseClassName}__has_spinner`);
|
|
3323
|
+
} else {
|
|
3324
|
+
remove(p.spinner);
|
|
3325
|
+
delete p.spinner;
|
|
3326
|
+
p.el.classList.remove(`${p.baseClassName}__has_spinner`);
|
|
3327
|
+
}
|
|
3226
3328
|
}
|
|
3227
3329
|
}
|
|
3228
3330
|
/**
|
|
3331
|
+
* Inserts a control into the controls group, keeping the order: spinner, clear button, open indicator
|
|
3332
|
+
* @private
|
|
3333
|
+
* @internal
|
|
3334
|
+
*/
|
|
3335
|
+
_insertControl(control) {
|
|
3336
|
+
const p = this._p;
|
|
3337
|
+
const order = [
|
|
3338
|
+
p.spinner,
|
|
3339
|
+
p.clearButtonWrapper,
|
|
3340
|
+
p.openIndicator
|
|
3341
|
+
];
|
|
3342
|
+
const next = order.slice(order.indexOf(control) + 1).find((x) => x && x.parentNode === p.controls);
|
|
3343
|
+
p.controls.insertBefore(control, next ?? null);
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3229
3346
|
* @private
|
|
3230
3347
|
* @internal
|
|
3231
3348
|
*/
|
|
@@ -3245,7 +3362,10 @@ var SelectBox = class {
|
|
|
3245
3362
|
if (p.searchable || p.multi) classes.push(`${p.baseClassName}__searchable`);
|
|
3246
3363
|
if (p.direction === "ltr" || p.direction === "rtl") classes.push(`${p.baseClassName}__` + p.direction);
|
|
3247
3364
|
if (p.additionalClasses) classes = classes.concat(p.additionalClasses);
|
|
3248
|
-
|
|
3365
|
+
classes = classes.join(" ").split(/\s+/).filter(Boolean);
|
|
3366
|
+
const previousClasses = p.appliedClasses ?? [];
|
|
3367
|
+
el.className = Array.from(el.classList).filter((name) => !name.startsWith(p.baseClassName) && !previousClasses.includes(name)).concat(classes).join(" ");
|
|
3368
|
+
p.appliedClasses = classes;
|
|
3249
3369
|
}
|
|
3250
3370
|
/** @private */
|
|
3251
3371
|
/** @internal */
|
|
@@ -3349,21 +3469,22 @@ var SelectBox = class {
|
|
|
3349
3469
|
p.selectionChanged = true;
|
|
3350
3470
|
p.resortBySelectionNeeded = true;
|
|
3351
3471
|
const hasGroupSync = !!event.isCheckingGroup;
|
|
3352
|
-
if (p.showSelection)
|
|
3353
|
-
if (
|
|
3354
|
-
|
|
3355
|
-
if (
|
|
3472
|
+
if (p.showSelection) {
|
|
3473
|
+
if (checked) {
|
|
3474
|
+
if (dropList.itemCount() === 1 && p.clearInputWhen.includes("multi_select_single")) this._setInputText("");
|
|
3475
|
+
if (p.sortSelectedItems) {
|
|
3476
|
+
if (!hasGroupSync) this._scheduleSync("full");
|
|
3477
|
+
} else {
|
|
3478
|
+
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length > p.maxMultiItems) this._scheduleSync("addOrUpdateMultiItemRestElement");
|
|
3479
|
+
else this._scheduleSync("addMultiItemElement", item);
|
|
3480
|
+
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3481
|
+
}
|
|
3356
3482
|
} else {
|
|
3357
|
-
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length
|
|
3358
|
-
else this._scheduleSync("
|
|
3483
|
+
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
|
|
3484
|
+
else this._scheduleSync("removeMultiItemElement", item);
|
|
3359
3485
|
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3360
3486
|
}
|
|
3361
|
-
} else
|
|
3362
|
-
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
|
|
3363
|
-
else this._scheduleSync("removeMultiItemElement", item);
|
|
3364
|
-
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3365
|
-
}
|
|
3366
|
-
else if (p.multi) this._scheduleSync("syncPlaceholder");
|
|
3487
|
+
} else if (p.multi) this._scheduleSync("syncPlaceholder");
|
|
3367
3488
|
this._trigger(checked ? "addsel" : "removesel", {
|
|
3368
3489
|
value,
|
|
3369
3490
|
item,
|
|
@@ -3409,6 +3530,7 @@ var SelectBox = class {
|
|
|
3409
3530
|
}
|
|
3410
3531
|
}
|
|
3411
3532
|
});
|
|
3533
|
+
dropList._setOwnerSelectBox(this);
|
|
3412
3534
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3413
3535
|
this._registerDropdownEvents();
|
|
3414
3536
|
}
|
|
@@ -3760,9 +3882,8 @@ var SelectBox = class {
|
|
|
3760
3882
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
3761
3883
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
3762
3884
|
if (!p.clearButtonWrapper) {
|
|
3763
|
-
p.clearButtonWrapper = createElement(
|
|
3764
|
-
|
|
3765
|
-
else append(p.el, p.clearButtonWrapper);
|
|
3885
|
+
p.clearButtonWrapper = createElement("span", { class: `${p.baseClassName}__clear` }, p.clearButton = createElement("button"));
|
|
3886
|
+
this._insertControl(p.clearButtonWrapper);
|
|
3766
3887
|
p.el.classList.add(`${p.baseClassName}__has_clear`);
|
|
3767
3888
|
p.sink.add(p.clearButton, "click", () => {
|
|
3768
3889
|
if (this.isDisabled() || this.isReadOnly()) return;
|
|
@@ -3782,9 +3903,10 @@ var SelectBox = class {
|
|
|
3782
3903
|
_syncPlaceholder() {
|
|
3783
3904
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
3784
3905
|
let placeholder = "";
|
|
3785
|
-
if (p.multi && !p.showSelection)
|
|
3786
|
-
|
|
3787
|
-
|
|
3906
|
+
if (p.multi && !p.showSelection) {
|
|
3907
|
+
if (typeof p.multiPlaceholderFormatter === "function") placeholder = p.multiPlaceholderFormatter(p.selectedItems);
|
|
3908
|
+
else placeholder = p.selectedItems.length === 0 ? p.placeholder || "" : defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
|
|
3909
|
+
} else if (p.selectedItems.length === 0 || !p.showSelection || p.selectedItems.every((x) => x[multiItemLabelProp] === false)) placeholder = p.placeholder == null ? "" : p.placeholder + "";
|
|
3788
3910
|
p.input.setAttribute("placeholder", placeholder);
|
|
3789
3911
|
if (p.showPlaceholderInTooltip) p.input.setAttribute("title", placeholder);
|
|
3790
3912
|
else p.input.removeAttribute("title");
|
|
@@ -3908,46 +4030,48 @@ var SelectBox = class {
|
|
|
3908
4030
|
else if (kEvent.key === VALUE_BACK_SPACE) nextFocus = prev(itemEl, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
|
|
3909
4031
|
} else if (/click|mouse|touch/.test(originatingEvent.type)) nextFocus = next(itemEl, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
|
|
3910
4032
|
const item = itemEl[ItemSymbol], value = item[p.valueProp];
|
|
3911
|
-
if (item !== void 0)
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
4033
|
+
if (item !== void 0) {
|
|
4034
|
+
if (value === RestMultiItemsSymbol) {
|
|
4035
|
+
let items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).slice(p.maxMultiItems);
|
|
4036
|
+
let itemsToRemove = [];
|
|
4037
|
+
for (let item of items) {
|
|
4038
|
+
let removeselEvt = {
|
|
4039
|
+
value: item[p.valueProp],
|
|
4040
|
+
item,
|
|
4041
|
+
cancel: false
|
|
4042
|
+
};
|
|
4043
|
+
this._trigger("removesel:before", removeselEvt);
|
|
4044
|
+
if (!removeselEvt.cancel) itemsToRemove.push(item);
|
|
4045
|
+
}
|
|
4046
|
+
if (itemsToRemove.length > 0) {
|
|
4047
|
+
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4048
|
+
for (let item of itemsToRemove) {
|
|
4049
|
+
let idx = p.selectedItems.indexOf(item);
|
|
4050
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4051
|
+
if (idx !== -1) {
|
|
4052
|
+
p.selectedItems.splice(idx, 1);
|
|
4053
|
+
p.selectedValues.splice(idx, 1);
|
|
4054
|
+
p.selectionChanged = true;
|
|
4055
|
+
p.resortBySelectionNeeded = true;
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
}
|
|
4059
|
+
if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
|
|
4060
|
+
if (itemsToRemove.length > 0) this._scheduleSync("render_list");
|
|
4061
|
+
} else {
|
|
3915
4062
|
let removeselEvt = {
|
|
3916
|
-
value
|
|
4063
|
+
value,
|
|
3917
4064
|
item,
|
|
3918
4065
|
cancel: false
|
|
3919
4066
|
};
|
|
3920
4067
|
this._trigger("removesel:before", removeselEvt);
|
|
3921
|
-
if (
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
3928
|
-
if (idx !== -1) {
|
|
3929
|
-
p.selectedItems.splice(idx, 1);
|
|
3930
|
-
p.selectedValues.splice(idx, 1);
|
|
3931
|
-
p.selectionChanged = true;
|
|
3932
|
-
p.resortBySelectionNeeded = true;
|
|
3933
|
-
}
|
|
3934
|
-
}
|
|
4068
|
+
if (removeselEvt.cancel) return this;
|
|
4069
|
+
this._removeMultiItem(item);
|
|
4070
|
+
this._trigger("removesel", {
|
|
4071
|
+
value,
|
|
4072
|
+
item
|
|
4073
|
+
});
|
|
3935
4074
|
}
|
|
3936
|
-
if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
|
|
3937
|
-
if (itemsToRemove.length > 0) this._scheduleSync("render_list");
|
|
3938
|
-
} else {
|
|
3939
|
-
let removeselEvt = {
|
|
3940
|
-
value,
|
|
3941
|
-
item,
|
|
3942
|
-
cancel: false
|
|
3943
|
-
};
|
|
3944
|
-
this._trigger("removesel:before", removeselEvt);
|
|
3945
|
-
if (removeselEvt.cancel) return this;
|
|
3946
|
-
this._removeMultiItem(item);
|
|
3947
|
-
this._trigger("removesel", {
|
|
3948
|
-
value,
|
|
3949
|
-
item
|
|
3950
|
-
});
|
|
3951
4075
|
}
|
|
3952
4076
|
if (!nextFocus) nextFocus = p.el.querySelector(`.${p.baseClassName}__item, .${p.baseClassName}__search_field`);
|
|
3953
4077
|
if (hasClass(nextFocus, `${p.baseClassName}__search_wrapper`)) nextFocus = nextFocus.querySelector("input");
|
|
@@ -4006,14 +4130,6 @@ var SelectBox = class {
|
|
|
4006
4130
|
let hasResize = false;
|
|
4007
4131
|
if (p.multi && p.multiItemEls.length === 0 && p.showSelection) {
|
|
4008
4132
|
input.style.width = "";
|
|
4009
|
-
let beforeWidth = 0, afterWidth = 0;
|
|
4010
|
-
let beforeStyle = getComputedStyle(p.list || el, "::before");
|
|
4011
|
-
if (beforeStyle.content && beforeStyle.content !== "none" && beforeStyle.position !== "absolute" && beforeStyle.float !== "none") beforeWidth = getPseudoElementWidth(p.list || el, "::before", true, true, true);
|
|
4012
|
-
let afterStyle = getComputedStyle(p.list || el, "::after");
|
|
4013
|
-
if (afterStyle.content && afterStyle.content !== "none" && afterStyle.position !== "absolute" && afterStyle.float !== "none") afterWidth = getPseudoElementWidth(p.list || el, "::after", true, true, true);
|
|
4014
|
-
let contentWidth = getElementWidth(p.list || el);
|
|
4015
|
-
contentWidth -= beforeWidth + afterWidth;
|
|
4016
|
-
input.style.width = `${contentWidth}px`;
|
|
4017
4133
|
hasResize = true;
|
|
4018
4134
|
} else {
|
|
4019
4135
|
setCssProps(backBufferEl, getCssProps(input, inputBackbufferCssProps));
|
|
@@ -4298,7 +4414,6 @@ var SelectBox = class {
|
|
|
4298
4414
|
return joined;
|
|
4299
4415
|
}
|
|
4300
4416
|
};
|
|
4301
|
-
//#endregion
|
|
4302
4417
|
export { DropList, DefaultOptions as DropListDefaultOptions, ItemSymbol, SelectBox, DefaultOptions$1 as SelectBoxDefaultOptions };
|
|
4303
4418
|
|
|
4304
4419
|
//# sourceMappingURL=lib.es6.js.map
|