@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.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox
|
|
2
|
+
* @danielgindi/selectbox 3.0.0
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
(function(global, factory) {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.SelectBox = {}, global.domUtilsDom, global.domUtilsDomCompat, global.domUtilsCss, global.domUtilsDomEventsSink, global.VirtualListHelper, global.keyCode, global.mitt));
|
|
16
16
|
})(this, function(exports, _danielgindi_dom_utils_lib_Dom, _danielgindi_dom_utils_lib_DomCompat, _danielgindi_dom_utils_lib_Css, _danielgindi_dom_utils_lib_DomEventsSink, _danielgindi_virtual_list_helper, keycode_js, mitt) {
|
|
17
17
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
18
|
-
|
|
18
|
+
// \0rolldown/runtime.js
|
|
19
19
|
var __create = Object.create;
|
|
20
20
|
var __defProp = Object.defineProperty;
|
|
21
21
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -36,15 +36,13 @@
|
|
|
36
36
|
value: mod,
|
|
37
37
|
enumerable: true
|
|
38
38
|
}) : target, mod));
|
|
39
|
-
//#endregion
|
|
40
39
|
_danielgindi_dom_utils_lib_DomEventsSink = __toESM(_danielgindi_dom_utils_lib_DomEventsSink);
|
|
41
40
|
_danielgindi_virtual_list_helper = __toESM(_danielgindi_virtual_list_helper);
|
|
42
41
|
mitt = __toESM(mitt);
|
|
43
|
-
|
|
42
|
+
// src/lib/utils/escapeRegex.ts
|
|
44
43
|
/** @internal */
|
|
45
44
|
var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
46
|
-
|
|
47
|
-
//#region src/lib/utils/throttle.ts
|
|
45
|
+
// src/lib/utils/throttle.ts
|
|
48
46
|
/** @internal */
|
|
49
47
|
var throttle = (func, wait, options = {}) => {
|
|
50
48
|
let timeout;
|
|
@@ -85,8 +83,7 @@
|
|
|
85
83
|
};
|
|
86
84
|
return throttled;
|
|
87
85
|
};
|
|
88
|
-
|
|
89
|
-
//#region src/lib/utils/reportError.ts
|
|
86
|
+
// src/lib/utils/reportError.ts
|
|
90
87
|
/**
|
|
91
88
|
* Routes an error/warning to `handler` if supplied, falling back to the
|
|
92
89
|
* console (matching the previous hardcoded behaviour) if there is no
|
|
@@ -103,8 +100,7 @@
|
|
|
103
100
|
if (context.level === "warn") console.warn(error);
|
|
104
101
|
else console.error(error);
|
|
105
102
|
};
|
|
106
|
-
|
|
107
|
-
//#region src/lib/DropList.ts
|
|
103
|
+
// src/lib/DropList.ts
|
|
108
104
|
var ItemSymbol = Symbol("item");
|
|
109
105
|
var DestroyedSymbol$1 = Symbol("destroyed");
|
|
110
106
|
var GhostSymbol = Symbol("ghost");
|
|
@@ -127,6 +123,7 @@
|
|
|
127
123
|
labelProp: "label",
|
|
128
124
|
valueProp: "value",
|
|
129
125
|
on: null,
|
|
126
|
+
zIndex: null,
|
|
130
127
|
isHeaderVisible: false,
|
|
131
128
|
isFooterVisible: false,
|
|
132
129
|
searchable: false,
|
|
@@ -171,6 +168,9 @@
|
|
|
171
168
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
172
169
|
on: o.on || null,
|
|
173
170
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
171
|
+
zIndex: o.zIndex ?? null,
|
|
172
|
+
appliedZIndex: null,
|
|
173
|
+
ownerSelectBox: null,
|
|
174
174
|
onError: o.onError,
|
|
175
175
|
searchable: o.searchable,
|
|
176
176
|
searchPlaceholder: o.searchPlaceholder,
|
|
@@ -271,12 +271,13 @@
|
|
|
271
271
|
itemEl.className = `${p.baseClassName}__item`;
|
|
272
272
|
const classList = itemEl.classList;
|
|
273
273
|
if (item) {
|
|
274
|
-
if (p.multi)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
if (p.multi) {
|
|
275
|
+
if (item._nocheck) classList.add(`${p.baseClassName}__item_multi_nocheck`);
|
|
276
|
+
else {
|
|
277
|
+
classList.add(`${p.baseClassName}__item_multi`);
|
|
278
|
+
if (item._checked) classList.add(`${p.baseClassName}__item_checked`);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
280
281
|
classList.add(`${p.baseClassName}__item_single`);
|
|
281
282
|
if (p.singleSelectedValue !== void 0 && item.value === p.singleSelectedValue) {
|
|
282
283
|
classList.add(`${p.baseClassName}__item_selected`);
|
|
@@ -588,7 +589,7 @@
|
|
|
588
589
|
const p = this._p;
|
|
589
590
|
let itemIndex = this.itemIndexByValue(value);
|
|
590
591
|
if (itemIndex === -1) return this;
|
|
591
|
-
let item =
|
|
592
|
+
let item = p.items[itemIndex];
|
|
592
593
|
item[ItemSymbol] = newItem;
|
|
593
594
|
if (hasOwnProperty.call(newItem, p.labelProp)) item.label = newItem[p.labelProp];
|
|
594
595
|
if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
|
|
@@ -608,10 +609,7 @@
|
|
|
608
609
|
if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
|
|
609
610
|
if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
|
|
610
611
|
let virtualItemIndex = itemIndex;
|
|
611
|
-
if (p.filteredItems)
|
|
612
|
-
virtualItemIndex = p.filteredItems.indexOf(item);
|
|
613
|
-
if (virtualItemIndex !== -1) p.filteredItems.splice(virtualItemIndex, 1);
|
|
614
|
-
}
|
|
612
|
+
if (p.filteredItems) virtualItemIndex = p.filteredItems.indexOf(item);
|
|
615
613
|
if (virtualItemIndex !== -1 && p.virtualListHelper.isItemRendered(virtualItemIndex)) p.virtualListHelper.refreshItemAt(virtualItemIndex).render();
|
|
616
614
|
return this;
|
|
617
615
|
}
|
|
@@ -629,7 +627,7 @@
|
|
|
629
627
|
if (virtualItemIndex !== -1) {
|
|
630
628
|
p.hasNoResultsItem = (p.filteredItems ?? p.items).length === 0 && !!p.noResultsText;
|
|
631
629
|
if (p.hasNoResultsItem) p.virtualListHelper.setCount(1).render();
|
|
632
|
-
else p.virtualListHelper.removeItemsAt(
|
|
630
|
+
else p.virtualListHelper.removeItemsAt(1, virtualItemIndex).render();
|
|
633
631
|
}
|
|
634
632
|
return this;
|
|
635
633
|
}
|
|
@@ -741,6 +739,70 @@
|
|
|
741
739
|
return this._p.positionOptionsProvider;
|
|
742
740
|
}
|
|
743
741
|
/**
|
|
742
|
+
* Sets the z-index: a fixed value, a resolver function, or `null` to use the CSS z-index.
|
|
743
|
+
* Applied immediately if the DropList is visible.
|
|
744
|
+
*/
|
|
745
|
+
setZIndex(zIndex) {
|
|
746
|
+
const p = this._p;
|
|
747
|
+
zIndex = zIndex ?? null;
|
|
748
|
+
if (p.zIndex === zIndex) return this;
|
|
749
|
+
p.zIndex = zIndex;
|
|
750
|
+
this.updateZIndex();
|
|
751
|
+
return this;
|
|
752
|
+
}
|
|
753
|
+
getZIndex() {
|
|
754
|
+
return this._p.zIndex;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Re-resolves the z-index (re-invoking a resolver function) and applies it.
|
|
758
|
+
* The z-index is resolved automatically on `show()`, so call this only when the stacking
|
|
759
|
+
* order around the owner changes while the DropList is open. Does nothing while hidden.
|
|
760
|
+
*/
|
|
761
|
+
updateZIndex() {
|
|
762
|
+
const p = this._p;
|
|
763
|
+
if (!this.isVisible()) return this;
|
|
764
|
+
this._applyZIndex(p.positionOptionsProvider?.() ?? p.lastPositionOptions ?? null);
|
|
765
|
+
return this;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Marks this DropList as owned by a SelectBox, for `DropListZIndexContext`.
|
|
769
|
+
* @internal
|
|
770
|
+
*/
|
|
771
|
+
_setOwnerSelectBox(selectBox) {
|
|
772
|
+
this._p.ownerSelectBox = selectBox;
|
|
773
|
+
}
|
|
774
|
+
/** @internal */
|
|
775
|
+
_resolveZIndex(positionOptions) {
|
|
776
|
+
const p = this._p;
|
|
777
|
+
const option = p.zIndex;
|
|
778
|
+
let zIndex;
|
|
779
|
+
if (typeof option === "function") {
|
|
780
|
+
const context = {
|
|
781
|
+
dropList: this,
|
|
782
|
+
owner: p.ownerSelectBox?.el ?? positionOptions?.target ?? null,
|
|
783
|
+
selectBox: p.ownerSelectBox,
|
|
784
|
+
positionOptions
|
|
785
|
+
};
|
|
786
|
+
try {
|
|
787
|
+
zIndex = option(context);
|
|
788
|
+
} catch (err) {
|
|
789
|
+
reportError(p.onError, err, { source: "zIndex" });
|
|
790
|
+
zIndex = null;
|
|
791
|
+
}
|
|
792
|
+
} else zIndex = option;
|
|
793
|
+
if (zIndex == null || zIndex === "") return null;
|
|
794
|
+
return String(zIndex);
|
|
795
|
+
}
|
|
796
|
+
/** @internal */
|
|
797
|
+
_applyZIndex(positionOptions) {
|
|
798
|
+
const p = this._p;
|
|
799
|
+
const zIndex = this._resolveZIndex(positionOptions);
|
|
800
|
+
if (zIndex !== null) p.el.style.zIndex = zIndex;
|
|
801
|
+
else if (p.appliedZIndex !== null) p.el.style.zIndex = "";
|
|
802
|
+
p.appliedZIndex = zIndex;
|
|
803
|
+
p.currentSubDropList?.droplist?.updateZIndex();
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
744
806
|
* Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
|
|
745
807
|
* instead of the default `console.error`/`console.warn`.
|
|
746
808
|
*/
|
|
@@ -809,13 +871,15 @@
|
|
|
809
871
|
return our;
|
|
810
872
|
});
|
|
811
873
|
}
|
|
812
|
-
if (!Array.isArray(filteredItems))
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
874
|
+
if (!Array.isArray(filteredItems)) {
|
|
875
|
+
if (term) {
|
|
876
|
+
const matcher = new RegExp(escapeRegex(term), "i");
|
|
877
|
+
filteredItems = p.items.filter((x) => {
|
|
878
|
+
if (!filterGroups && x._group) return true;
|
|
879
|
+
return matcher.test(x.label);
|
|
880
|
+
});
|
|
881
|
+
} else filteredItems = null;
|
|
882
|
+
}
|
|
819
883
|
p.filteredItems = filteredItems;
|
|
820
884
|
if (filteredItems && filterEmptyGroups) {
|
|
821
885
|
let lastGroup = -1;
|
|
@@ -1026,8 +1090,10 @@
|
|
|
1026
1090
|
};
|
|
1027
1091
|
viewCss.left += anchor.left - position.left;
|
|
1028
1092
|
if (positionOptions.offset) {
|
|
1029
|
-
if (positionOptions.offset.y)
|
|
1030
|
-
|
|
1093
|
+
if (positionOptions.offset.y) {
|
|
1094
|
+
if (invertYPos) viewCss.top -= positionOptions.offset.y;
|
|
1095
|
+
else viewCss.top += positionOptions.offset.y;
|
|
1096
|
+
}
|
|
1031
1097
|
if (positionOptions.offset.x) {
|
|
1032
1098
|
let rtl = elComputedStyle.direction === "rtl";
|
|
1033
1099
|
viewCss.left += rtl ? -positionOptions.offset.x : positionOptions.offset.x;
|
|
@@ -1157,6 +1223,7 @@
|
|
|
1157
1223
|
p.lastPositionOptions = null;
|
|
1158
1224
|
if (positionOptions === void 0) positionOptions = p.positionOptionsProvider?.() ?? p.lastPositionOptions;
|
|
1159
1225
|
else p.lastPositionOptions = positionOptions;
|
|
1226
|
+
this._applyZIndex(positionOptions ?? null);
|
|
1160
1227
|
if (positionOptions) {
|
|
1161
1228
|
const elComputedStyle = getComputedStyle(el);
|
|
1162
1229
|
const originalMaxHeight = el.style.maxHeight;
|
|
@@ -1358,7 +1425,8 @@
|
|
|
1358
1425
|
valueProp: p.valueProp,
|
|
1359
1426
|
renderItem: p.renderItem,
|
|
1360
1427
|
unrenderItem: p.unrenderItem,
|
|
1361
|
-
positionOptionsProvider: () => p.currentSubDropList.showOptions
|
|
1428
|
+
positionOptionsProvider: () => p.currentSubDropList.showOptions,
|
|
1429
|
+
zIndex: () => this._p?.appliedZIndex ?? null
|
|
1362
1430
|
});
|
|
1363
1431
|
let onBlur = (event) => {
|
|
1364
1432
|
if (this[DestroyedSymbol$1]) return;
|
|
@@ -1981,14 +2049,16 @@
|
|
|
1981
2049
|
} else if (p.focusItemEl) {
|
|
1982
2050
|
let base = (0, _danielgindi_dom_utils_lib_Css.getElementOffset)(p.focusItemEl).top;
|
|
1983
2051
|
let height = (0, _danielgindi_dom_utils_lib_Css.getElementHeight)(p.el, true);
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
if (
|
|
2052
|
+
let candidate = p.focusItemEl;
|
|
2053
|
+
next = null;
|
|
2054
|
+
while (candidate = direction === "prev_page" ? candidate.previousElementSibling : candidate.nextElementSibling) {
|
|
2055
|
+
if (candidate.tagName !== "LI") continue;
|
|
2056
|
+
next = candidate;
|
|
1988
2057
|
if (direction === "prev_page") {
|
|
1989
2058
|
if ((0, _danielgindi_dom_utils_lib_Css.getElementOffset)(next).top - base + height <= 0) break;
|
|
1990
2059
|
} else if ((0, _danielgindi_dom_utils_lib_Css.getElementOffset)(next).top - base - height >= 0) break;
|
|
1991
2060
|
}
|
|
2061
|
+
if (!next) return;
|
|
1992
2062
|
if (next) {
|
|
1993
2063
|
nextIndex = p.virtualListHelper.getItemIndexFromElement(next);
|
|
1994
2064
|
if (nextIndex === void 0) nextIndex = -1;
|
|
@@ -2181,14 +2251,18 @@
|
|
|
2181
2251
|
_updateWidth(positionOptions) {
|
|
2182
2252
|
const p = this._p, el = p.el;
|
|
2183
2253
|
let targetWidth = 0;
|
|
2184
|
-
if (positionOptions)
|
|
2185
|
-
|
|
2186
|
-
|
|
2254
|
+
if (positionOptions) {
|
|
2255
|
+
if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
|
|
2256
|
+
else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
|
|
2257
|
+
else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
|
|
2258
|
+
}
|
|
2187
2259
|
let autoWidth = 0;
|
|
2188
|
-
if (!p.useExactTargetWidth || !targetWidth)
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2260
|
+
if (!p.useExactTargetWidth || !targetWidth) {
|
|
2261
|
+
if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
|
|
2262
|
+
else {
|
|
2263
|
+
el.style.width = "";
|
|
2264
|
+
autoWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(el, true, true);
|
|
2265
|
+
}
|
|
2192
2266
|
}
|
|
2193
2267
|
let newOuterWidth = Math.max(autoWidth, targetWidth);
|
|
2194
2268
|
(0, _danielgindi_dom_utils_lib_Css.setElementWidth)(el, newOuterWidth, true, true);
|
|
@@ -2203,8 +2277,7 @@
|
|
|
2203
2277
|
return newOuterWidth;
|
|
2204
2278
|
}
|
|
2205
2279
|
};
|
|
2206
|
-
|
|
2207
|
-
//#region src/lib/SelectBox.ts
|
|
2280
|
+
// src/lib/SelectBox.ts
|
|
2208
2281
|
var DestroyedSymbol = Symbol("destroyed");
|
|
2209
2282
|
var RestMultiItemsSymbol = Symbol("rest_multi_items");
|
|
2210
2283
|
var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
|
|
@@ -2452,9 +2525,12 @@
|
|
|
2452
2525
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.list);
|
|
2453
2526
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.singleWrapper);
|
|
2454
2527
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.input);
|
|
2528
|
+
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.inputWrapper);
|
|
2455
2529
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.inputBackBuffer);
|
|
2456
2530
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.clearButtonWrapper);
|
|
2457
2531
|
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.openIndicator);
|
|
2532
|
+
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.spinner);
|
|
2533
|
+
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.controls);
|
|
2458
2534
|
if (!p.ownsEl) {
|
|
2459
2535
|
for (let name of Array.from(p.el.classList)) if (name.startsWith(p.baseClassName)) p.el.classList.remove(name);
|
|
2460
2536
|
p.el.removeAttribute("role");
|
|
@@ -2540,6 +2616,7 @@
|
|
|
2540
2616
|
p.itemsChanged = true;
|
|
2541
2617
|
this._refreshItemByValueMap();
|
|
2542
2618
|
if (resetValues) this.setSelectedValues(this.getSelectedValues());
|
|
2619
|
+
else this._scheduleSync("render_list");
|
|
2543
2620
|
this._trigger("itemschanged", {
|
|
2544
2621
|
term: null,
|
|
2545
2622
|
mutated: true,
|
|
@@ -2817,6 +2894,22 @@
|
|
|
2817
2894
|
this._setupDropdownMenu();
|
|
2818
2895
|
return this;
|
|
2819
2896
|
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Sets `listOptions.zIndex` without recreating the DropList.
|
|
2899
|
+
* `undefined` falls back to `DropListDefaultOptions.zIndex`.
|
|
2900
|
+
*/
|
|
2901
|
+
setListZIndex(zIndex) {
|
|
2902
|
+
const p = this._p;
|
|
2903
|
+
p.listOptions = {
|
|
2904
|
+
...p.listOptions,
|
|
2905
|
+
zIndex
|
|
2906
|
+
};
|
|
2907
|
+
p.dropList?.setZIndex(zIndex === void 0 ? DefaultOptions.zIndex : zIndex);
|
|
2908
|
+
return this;
|
|
2909
|
+
}
|
|
2910
|
+
getListZIndex() {
|
|
2911
|
+
return this._p.listOptions?.zIndex;
|
|
2912
|
+
}
|
|
2820
2913
|
setRenderSingleItem(render, unrender) {
|
|
2821
2914
|
const p = this._p;
|
|
2822
2915
|
p.renderSingleItem = render;
|
|
@@ -3179,6 +3272,10 @@
|
|
|
3179
3272
|
top: "-9999px",
|
|
3180
3273
|
whiteSpace: "pre"
|
|
3181
3274
|
} });
|
|
3275
|
+
if (!p.controls) {
|
|
3276
|
+
p.controls = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__controls` });
|
|
3277
|
+
p.el.appendChild(p.controls);
|
|
3278
|
+
}
|
|
3182
3279
|
if (!p.input) p.inputWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__search_wrapper` }, p.input = (0, _danielgindi_dom_utils_lib_Dom.createElement)("input", {
|
|
3183
3280
|
class: `${p.baseClassName}__search_field`,
|
|
3184
3281
|
type: "search",
|
|
@@ -3200,7 +3297,7 @@
|
|
|
3200
3297
|
this._unregisterDropdownEvents();
|
|
3201
3298
|
const lastActiveElement = document.activeElement;
|
|
3202
3299
|
p.list = (0, _danielgindi_dom_utils_lib_Dom.createElement)("ul", { class: `${p.baseClassName}__list` });
|
|
3203
|
-
p.el.
|
|
3300
|
+
p.el.insertBefore(p.list, p.controls);
|
|
3204
3301
|
p.list.appendChild(p.inputWrapper);
|
|
3205
3302
|
p.el.classList.remove(`${p.baseClassName}__single`);
|
|
3206
3303
|
p.el.classList.add(`${p.baseClassName}__multi`);
|
|
@@ -3229,34 +3326,53 @@
|
|
|
3229
3326
|
this._unregisterDropdownEvents();
|
|
3230
3327
|
const lastActiveElement = document.activeElement;
|
|
3231
3328
|
p.singleWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)("div", { class: `${p.baseClassName}__single_wrapper` });
|
|
3232
|
-
p.el.
|
|
3233
|
-
p.el.
|
|
3329
|
+
p.el.insertBefore(p.singleWrapper, p.controls);
|
|
3330
|
+
p.el.insertBefore(p.inputWrapper, p.controls);
|
|
3234
3331
|
p.el.classList.remove(`${p.baseClassName}__multi`);
|
|
3235
3332
|
p.el.classList.add(`${p.baseClassName}__single`);
|
|
3236
3333
|
if (lastActiveElement === p.input) p.input.focus();
|
|
3237
3334
|
this._registerDropdownEvents();
|
|
3238
3335
|
}
|
|
3239
3336
|
}
|
|
3240
|
-
if (p.hasOpenIndicator !== !!p.openIndicator)
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3337
|
+
if (p.hasOpenIndicator !== !!p.openIndicator) {
|
|
3338
|
+
if (p.hasOpenIndicator) {
|
|
3339
|
+
p.openIndicator = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__open_indicator` });
|
|
3340
|
+
this._insertControl(p.openIndicator);
|
|
3341
|
+
p.el.classList.add(`${p.baseClassName}__has_open_indicator`);
|
|
3342
|
+
} else {
|
|
3343
|
+
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.openIndicator);
|
|
3344
|
+
delete p.openIndicator;
|
|
3345
|
+
p.el.classList.remove(`${p.baseClassName}__has_open_indicator`);
|
|
3346
|
+
}
|
|
3248
3347
|
}
|
|
3249
|
-
if (p.isLoadingMode !== !!p.spinner)
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3348
|
+
if (p.isLoadingMode !== !!p.spinner) {
|
|
3349
|
+
if (p.isLoadingMode) {
|
|
3350
|
+
p.spinner = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__spinner` });
|
|
3351
|
+
this._insertControl(p.spinner);
|
|
3352
|
+
p.el.classList.add(`${p.baseClassName}__has_spinner`);
|
|
3353
|
+
} else {
|
|
3354
|
+
(0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.spinner);
|
|
3355
|
+
delete p.spinner;
|
|
3356
|
+
p.el.classList.remove(`${p.baseClassName}__has_spinner`);
|
|
3357
|
+
}
|
|
3257
3358
|
}
|
|
3258
3359
|
}
|
|
3259
3360
|
/**
|
|
3361
|
+
* Inserts a control into the controls group, keeping the order: spinner, clear button, open indicator
|
|
3362
|
+
* @private
|
|
3363
|
+
* @internal
|
|
3364
|
+
*/
|
|
3365
|
+
_insertControl(control) {
|
|
3366
|
+
const p = this._p;
|
|
3367
|
+
const order = [
|
|
3368
|
+
p.spinner,
|
|
3369
|
+
p.clearButtonWrapper,
|
|
3370
|
+
p.openIndicator
|
|
3371
|
+
];
|
|
3372
|
+
const next = order.slice(order.indexOf(control) + 1).find((x) => x && x.parentNode === p.controls);
|
|
3373
|
+
p.controls.insertBefore(control, next ?? null);
|
|
3374
|
+
}
|
|
3375
|
+
/**
|
|
3260
3376
|
* @private
|
|
3261
3377
|
* @internal
|
|
3262
3378
|
*/
|
|
@@ -3276,7 +3392,10 @@
|
|
|
3276
3392
|
if (p.searchable || p.multi) classes.push(`${p.baseClassName}__searchable`);
|
|
3277
3393
|
if (p.direction === "ltr" || p.direction === "rtl") classes.push(`${p.baseClassName}__` + p.direction);
|
|
3278
3394
|
if (p.additionalClasses) classes = classes.concat(p.additionalClasses);
|
|
3279
|
-
|
|
3395
|
+
classes = classes.join(" ").split(/\s+/).filter(Boolean);
|
|
3396
|
+
const previousClasses = p.appliedClasses ?? [];
|
|
3397
|
+
el.className = Array.from(el.classList).filter((name) => !name.startsWith(p.baseClassName) && !previousClasses.includes(name)).concat(classes).join(" ");
|
|
3398
|
+
p.appliedClasses = classes;
|
|
3280
3399
|
}
|
|
3281
3400
|
/** @private */
|
|
3282
3401
|
/** @internal */
|
|
@@ -3380,21 +3499,22 @@
|
|
|
3380
3499
|
p.selectionChanged = true;
|
|
3381
3500
|
p.resortBySelectionNeeded = true;
|
|
3382
3501
|
const hasGroupSync = !!event.isCheckingGroup;
|
|
3383
|
-
if (p.showSelection)
|
|
3384
|
-
if (
|
|
3385
|
-
|
|
3386
|
-
if (
|
|
3502
|
+
if (p.showSelection) {
|
|
3503
|
+
if (checked) {
|
|
3504
|
+
if (dropList.itemCount() === 1 && p.clearInputWhen.includes("multi_select_single")) this._setInputText("");
|
|
3505
|
+
if (p.sortSelectedItems) {
|
|
3506
|
+
if (!hasGroupSync) this._scheduleSync("full");
|
|
3507
|
+
} else {
|
|
3508
|
+
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length > p.maxMultiItems) this._scheduleSync("addOrUpdateMultiItemRestElement");
|
|
3509
|
+
else this._scheduleSync("addMultiItemElement", item);
|
|
3510
|
+
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3511
|
+
}
|
|
3387
3512
|
} else {
|
|
3388
|
-
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length
|
|
3389
|
-
else this._scheduleSync("
|
|
3513
|
+
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
|
|
3514
|
+
else this._scheduleSync("removeMultiItemElement", item);
|
|
3390
3515
|
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3391
3516
|
}
|
|
3392
|
-
} else
|
|
3393
|
-
if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
|
|
3394
|
-
else this._scheduleSync("removeMultiItemElement", item);
|
|
3395
|
-
if (!hasGroupSync) this._scheduleSync("render_base");
|
|
3396
|
-
}
|
|
3397
|
-
else if (p.multi) this._scheduleSync("syncPlaceholder");
|
|
3517
|
+
} else if (p.multi) this._scheduleSync("syncPlaceholder");
|
|
3398
3518
|
this._trigger(checked ? "addsel" : "removesel", {
|
|
3399
3519
|
value,
|
|
3400
3520
|
item,
|
|
@@ -3440,6 +3560,7 @@
|
|
|
3440
3560
|
}
|
|
3441
3561
|
}
|
|
3442
3562
|
});
|
|
3563
|
+
dropList._setOwnerSelectBox(this);
|
|
3443
3564
|
p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
|
|
3444
3565
|
this._registerDropdownEvents();
|
|
3445
3566
|
}
|
|
@@ -3791,9 +3912,8 @@
|
|
|
3791
3912
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
3792
3913
|
if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
|
|
3793
3914
|
if (!p.clearButtonWrapper) {
|
|
3794
|
-
p.clearButtonWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)(
|
|
3795
|
-
|
|
3796
|
-
else (0, _danielgindi_dom_utils_lib_DomCompat.append)(p.el, p.clearButtonWrapper);
|
|
3915
|
+
p.clearButtonWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__clear` }, p.clearButton = (0, _danielgindi_dom_utils_lib_Dom.createElement)("button"));
|
|
3916
|
+
this._insertControl(p.clearButtonWrapper);
|
|
3797
3917
|
p.el.classList.add(`${p.baseClassName}__has_clear`);
|
|
3798
3918
|
p.sink.add(p.clearButton, "click", () => {
|
|
3799
3919
|
if (this.isDisabled() || this.isReadOnly()) return;
|
|
@@ -3813,9 +3933,10 @@
|
|
|
3813
3933
|
_syncPlaceholder() {
|
|
3814
3934
|
const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
|
|
3815
3935
|
let placeholder = "";
|
|
3816
|
-
if (p.multi && !p.showSelection)
|
|
3817
|
-
|
|
3818
|
-
|
|
3936
|
+
if (p.multi && !p.showSelection) {
|
|
3937
|
+
if (typeof p.multiPlaceholderFormatter === "function") placeholder = p.multiPlaceholderFormatter(p.selectedItems);
|
|
3938
|
+
else placeholder = p.selectedItems.length === 0 ? p.placeholder || "" : defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
|
|
3939
|
+
} else if (p.selectedItems.length === 0 || !p.showSelection || p.selectedItems.every((x) => x[multiItemLabelProp] === false)) placeholder = p.placeholder == null ? "" : p.placeholder + "";
|
|
3819
3940
|
p.input.setAttribute("placeholder", placeholder);
|
|
3820
3941
|
if (p.showPlaceholderInTooltip) p.input.setAttribute("title", placeholder);
|
|
3821
3942
|
else p.input.removeAttribute("title");
|
|
@@ -3939,46 +4060,48 @@
|
|
|
3939
4060
|
else if (kEvent.key === keycode_js.VALUE_BACK_SPACE) nextFocus = (0, _danielgindi_dom_utils_lib_Dom.prev)(itemEl, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
|
|
3940
4061
|
} else if (/click|mouse|touch/.test(originatingEvent.type)) nextFocus = (0, _danielgindi_dom_utils_lib_Dom.next)(itemEl, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
|
|
3941
4062
|
const item = itemEl[ItemSymbol], value = item[p.valueProp];
|
|
3942
|
-
if (item !== void 0)
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
4063
|
+
if (item !== void 0) {
|
|
4064
|
+
if (value === RestMultiItemsSymbol) {
|
|
4065
|
+
let items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).slice(p.maxMultiItems);
|
|
4066
|
+
let itemsToRemove = [];
|
|
4067
|
+
for (let item of items) {
|
|
4068
|
+
let removeselEvt = {
|
|
4069
|
+
value: item[p.valueProp],
|
|
4070
|
+
item,
|
|
4071
|
+
cancel: false
|
|
4072
|
+
};
|
|
4073
|
+
this._trigger("removesel:before", removeselEvt);
|
|
4074
|
+
if (!removeselEvt.cancel) itemsToRemove.push(item);
|
|
4075
|
+
}
|
|
4076
|
+
if (itemsToRemove.length > 0) {
|
|
4077
|
+
this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
|
|
4078
|
+
for (let item of itemsToRemove) {
|
|
4079
|
+
let idx = p.selectedItems.indexOf(item);
|
|
4080
|
+
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
4081
|
+
if (idx !== -1) {
|
|
4082
|
+
p.selectedItems.splice(idx, 1);
|
|
4083
|
+
p.selectedValues.splice(idx, 1);
|
|
4084
|
+
p.selectionChanged = true;
|
|
4085
|
+
p.resortBySelectionNeeded = true;
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
|
|
4090
|
+
if (itemsToRemove.length > 0) this._scheduleSync("render_list");
|
|
4091
|
+
} else {
|
|
3946
4092
|
let removeselEvt = {
|
|
3947
|
-
value
|
|
4093
|
+
value,
|
|
3948
4094
|
item,
|
|
3949
4095
|
cancel: false
|
|
3950
4096
|
};
|
|
3951
4097
|
this._trigger("removesel:before", removeselEvt);
|
|
3952
|
-
if (
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
|
|
3959
|
-
if (idx !== -1) {
|
|
3960
|
-
p.selectedItems.splice(idx, 1);
|
|
3961
|
-
p.selectedValues.splice(idx, 1);
|
|
3962
|
-
p.selectionChanged = true;
|
|
3963
|
-
p.resortBySelectionNeeded = true;
|
|
3964
|
-
}
|
|
3965
|
-
}
|
|
4098
|
+
if (removeselEvt.cancel) return this;
|
|
4099
|
+
this._removeMultiItem(item);
|
|
4100
|
+
this._trigger("removesel", {
|
|
4101
|
+
value,
|
|
4102
|
+
item
|
|
4103
|
+
});
|
|
3966
4104
|
}
|
|
3967
|
-
if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
|
|
3968
|
-
if (itemsToRemove.length > 0) this._scheduleSync("render_list");
|
|
3969
|
-
} else {
|
|
3970
|
-
let removeselEvt = {
|
|
3971
|
-
value,
|
|
3972
|
-
item,
|
|
3973
|
-
cancel: false
|
|
3974
|
-
};
|
|
3975
|
-
this._trigger("removesel:before", removeselEvt);
|
|
3976
|
-
if (removeselEvt.cancel) return this;
|
|
3977
|
-
this._removeMultiItem(item);
|
|
3978
|
-
this._trigger("removesel", {
|
|
3979
|
-
value,
|
|
3980
|
-
item
|
|
3981
|
-
});
|
|
3982
4105
|
}
|
|
3983
4106
|
if (!nextFocus) nextFocus = p.el.querySelector(`.${p.baseClassName}__item, .${p.baseClassName}__search_field`);
|
|
3984
4107
|
if (hasClass(nextFocus, `${p.baseClassName}__search_wrapper`)) nextFocus = nextFocus.querySelector("input");
|
|
@@ -4037,14 +4160,6 @@
|
|
|
4037
4160
|
let hasResize = false;
|
|
4038
4161
|
if (p.multi && p.multiItemEls.length === 0 && p.showSelection) {
|
|
4039
4162
|
input.style.width = "";
|
|
4040
|
-
let beforeWidth = 0, afterWidth = 0;
|
|
4041
|
-
let beforeStyle = getComputedStyle(p.list || el, "::before");
|
|
4042
|
-
if (beforeStyle.content && beforeStyle.content !== "none" && beforeStyle.position !== "absolute" && beforeStyle.float !== "none") beforeWidth = (0, _danielgindi_dom_utils_lib_Css.getPseudoElementWidth)(p.list || el, "::before", true, true, true);
|
|
4043
|
-
let afterStyle = getComputedStyle(p.list || el, "::after");
|
|
4044
|
-
if (afterStyle.content && afterStyle.content !== "none" && afterStyle.position !== "absolute" && afterStyle.float !== "none") afterWidth = (0, _danielgindi_dom_utils_lib_Css.getPseudoElementWidth)(p.list || el, "::after", true, true, true);
|
|
4045
|
-
let contentWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(p.list || el);
|
|
4046
|
-
contentWidth -= beforeWidth + afterWidth;
|
|
4047
|
-
input.style.width = `${contentWidth}px`;
|
|
4048
4163
|
hasResize = true;
|
|
4049
4164
|
} else {
|
|
4050
4165
|
(0, _danielgindi_dom_utils_lib_Css.setCssProps)(backBufferEl, (0, _danielgindi_dom_utils_lib_Css.getCssProps)(input, inputBackbufferCssProps));
|
|
@@ -4329,7 +4444,6 @@
|
|
|
4329
4444
|
return joined;
|
|
4330
4445
|
}
|
|
4331
4446
|
};
|
|
4332
|
-
//#endregion
|
|
4333
4447
|
exports.DropList = DropList;
|
|
4334
4448
|
exports.DropListDefaultOptions = DefaultOptions;
|
|
4335
4449
|
exports.ItemSymbol = ItemSymbol;
|