@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/dist/lib.cjs.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.65
2
+ * @danielgindi/selectbox 3.0.0
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
- //#region \0rolldown/runtime.js
6
+ // \0rolldown/runtime.js
7
7
  var __create = Object.create;
8
8
  var __defProp = Object.defineProperty;
9
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  value: mod,
25
25
  enumerable: true
26
26
  }) : target, mod));
27
- //#endregion
28
27
  let _danielgindi_dom_utils_lib_Dom = require("@danielgindi/dom-utils/lib/Dom");
29
28
  let _danielgindi_dom_utils_lib_DomCompat = require("@danielgindi/dom-utils/lib/DomCompat");
30
29
  let _danielgindi_dom_utils_lib_Css = require("@danielgindi/dom-utils/lib/Css");
@@ -35,11 +34,10 @@ _danielgindi_virtual_list_helper = __toESM(_danielgindi_virtual_list_helper);
35
34
  let keycode_js = require("keycode-js");
36
35
  let mitt = require("mitt");
37
36
  mitt = __toESM(mitt);
38
- //#region src/lib/utils/escapeRegex.ts
37
+ // src/lib/utils/escapeRegex.ts
39
38
  /** @internal */
40
39
  var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
41
- //#endregion
42
- //#region src/lib/utils/throttle.ts
40
+ // src/lib/utils/throttle.ts
43
41
  /** @internal */
44
42
  var throttle = (func, wait, options = {}) => {
45
43
  let timeout;
@@ -80,8 +78,7 @@ var throttle = (func, wait, options = {}) => {
80
78
  };
81
79
  return throttled;
82
80
  };
83
- //#endregion
84
- //#region src/lib/utils/reportError.ts
81
+ // src/lib/utils/reportError.ts
85
82
  /**
86
83
  * Routes an error/warning to `handler` if supplied, falling back to the
87
84
  * console (matching the previous hardcoded behaviour) if there is no
@@ -98,8 +95,7 @@ var reportError = (handler, error, context) => {
98
95
  if (context.level === "warn") console.warn(error);
99
96
  else console.error(error);
100
97
  };
101
- //#endregion
102
- //#region src/lib/DropList.ts
98
+ // src/lib/DropList.ts
103
99
  var ItemSymbol = Symbol("item");
104
100
  var DestroyedSymbol$1 = Symbol("destroyed");
105
101
  var GhostSymbol = Symbol("ghost");
@@ -122,6 +118,7 @@ var DefaultOptions = {
122
118
  labelProp: "label",
123
119
  valueProp: "value",
124
120
  on: null,
121
+ zIndex: null,
125
122
  isHeaderVisible: false,
126
123
  isFooterVisible: false,
127
124
  searchable: false,
@@ -166,6 +163,9 @@ var DropList = class DropList {
166
163
  unrenderNoResultsItem: o.unrenderNoResultsItem,
167
164
  on: o.on || null,
168
165
  positionOptionsProvider: o.positionOptionsProvider ?? null,
166
+ zIndex: o.zIndex ?? null,
167
+ appliedZIndex: null,
168
+ ownerSelectBox: null,
169
169
  onError: o.onError,
170
170
  searchable: o.searchable,
171
171
  searchPlaceholder: o.searchPlaceholder,
@@ -266,12 +266,13 @@ var DropList = class DropList {
266
266
  itemEl.className = `${p.baseClassName}__item`;
267
267
  const classList = itemEl.classList;
268
268
  if (item) {
269
- if (p.multi) if (item._nocheck) classList.add(`${p.baseClassName}__item_multi_nocheck`);
270
- else {
271
- classList.add(`${p.baseClassName}__item_multi`);
272
- if (item._checked) classList.add(`${p.baseClassName}__item_checked`);
273
- }
274
- else {
269
+ if (p.multi) {
270
+ if (item._nocheck) classList.add(`${p.baseClassName}__item_multi_nocheck`);
271
+ else {
272
+ classList.add(`${p.baseClassName}__item_multi`);
273
+ if (item._checked) classList.add(`${p.baseClassName}__item_checked`);
274
+ }
275
+ } else {
275
276
  classList.add(`${p.baseClassName}__item_single`);
276
277
  if (p.singleSelectedValue !== void 0 && item.value === p.singleSelectedValue) {
277
278
  classList.add(`${p.baseClassName}__item_selected`);
@@ -583,7 +584,7 @@ var DropList = class DropList {
583
584
  const p = this._p;
584
585
  let itemIndex = this.itemIndexByValue(value);
585
586
  if (itemIndex === -1) return this;
586
- let item = this.itemAtIndex(itemIndex);
587
+ let item = p.items[itemIndex];
587
588
  item[ItemSymbol] = newItem;
588
589
  if (hasOwnProperty.call(newItem, p.labelProp)) item.label = newItem[p.labelProp];
589
590
  if (hasOwnProperty.call(newItem, p.valueProp)) item.value = newItem[p.valueProp];
@@ -603,10 +604,7 @@ var DropList = class DropList {
603
604
  if (hasOwnProperty.call(newItem, "_level")) item._level = newItem._level;
604
605
  if (hasOwnProperty.call(newItem, "_child")) item._child = !!newItem._child;
605
606
  let virtualItemIndex = itemIndex;
606
- if (p.filteredItems) {
607
- virtualItemIndex = p.filteredItems.indexOf(item);
608
- if (virtualItemIndex !== -1) p.filteredItems.splice(virtualItemIndex, 1);
609
- }
607
+ if (p.filteredItems) virtualItemIndex = p.filteredItems.indexOf(item);
610
608
  if (virtualItemIndex !== -1 && p.virtualListHelper.isItemRendered(virtualItemIndex)) p.virtualListHelper.refreshItemAt(virtualItemIndex).render();
611
609
  return this;
612
610
  }
@@ -624,7 +622,7 @@ var DropList = class DropList {
624
622
  if (virtualItemIndex !== -1) {
625
623
  p.hasNoResultsItem = (p.filteredItems ?? p.items).length === 0 && !!p.noResultsText;
626
624
  if (p.hasNoResultsItem) p.virtualListHelper.setCount(1).render();
627
- else p.virtualListHelper.removeItemsAt(virtualItemIndex, 1).render();
625
+ else p.virtualListHelper.removeItemsAt(1, virtualItemIndex).render();
628
626
  }
629
627
  return this;
630
628
  }
@@ -736,6 +734,70 @@ var DropList = class DropList {
736
734
  return this._p.positionOptionsProvider;
737
735
  }
738
736
  /**
737
+ * Sets the z-index: a fixed value, a resolver function, or `null` to use the CSS z-index.
738
+ * Applied immediately if the DropList is visible.
739
+ */
740
+ setZIndex(zIndex) {
741
+ const p = this._p;
742
+ zIndex = zIndex ?? null;
743
+ if (p.zIndex === zIndex) return this;
744
+ p.zIndex = zIndex;
745
+ this.updateZIndex();
746
+ return this;
747
+ }
748
+ getZIndex() {
749
+ return this._p.zIndex;
750
+ }
751
+ /**
752
+ * Re-resolves the z-index (re-invoking a resolver function) and applies it.
753
+ * The z-index is resolved automatically on `show()`, so call this only when the stacking
754
+ * order around the owner changes while the DropList is open. Does nothing while hidden.
755
+ */
756
+ updateZIndex() {
757
+ const p = this._p;
758
+ if (!this.isVisible()) return this;
759
+ this._applyZIndex(p.positionOptionsProvider?.() ?? p.lastPositionOptions ?? null);
760
+ return this;
761
+ }
762
+ /**
763
+ * Marks this DropList as owned by a SelectBox, for `DropListZIndexContext`.
764
+ * @internal
765
+ */
766
+ _setOwnerSelectBox(selectBox) {
767
+ this._p.ownerSelectBox = selectBox;
768
+ }
769
+ /** @internal */
770
+ _resolveZIndex(positionOptions) {
771
+ const p = this._p;
772
+ const option = p.zIndex;
773
+ let zIndex;
774
+ if (typeof option === "function") {
775
+ const context = {
776
+ dropList: this,
777
+ owner: p.ownerSelectBox?.el ?? positionOptions?.target ?? null,
778
+ selectBox: p.ownerSelectBox,
779
+ positionOptions
780
+ };
781
+ try {
782
+ zIndex = option(context);
783
+ } catch (err) {
784
+ reportError(p.onError, err, { source: "zIndex" });
785
+ zIndex = null;
786
+ }
787
+ } else zIndex = option;
788
+ if (zIndex == null || zIndex === "") return null;
789
+ return String(zIndex);
790
+ }
791
+ /** @internal */
792
+ _applyZIndex(positionOptions) {
793
+ const p = this._p;
794
+ const zIndex = this._resolveZIndex(positionOptions);
795
+ if (zIndex !== null) p.el.style.zIndex = zIndex;
796
+ else if (p.appliedZIndex !== null) p.el.style.zIndex = "";
797
+ p.appliedZIndex = zIndex;
798
+ p.currentSubDropList?.droplist?.updateZIndex();
799
+ }
800
+ /**
739
801
  * Sets a handler to intercept internal errors/warnings (e.g. from a throwing `renderItem`/`unrenderItem`)
740
802
  * instead of the default `console.error`/`console.warn`.
741
803
  */
@@ -804,13 +866,15 @@ var DropList = class DropList {
804
866
  return our;
805
867
  });
806
868
  }
807
- if (!Array.isArray(filteredItems)) if (term) {
808
- const matcher = new RegExp(escapeRegex(term), "i");
809
- filteredItems = p.items.filter((x) => {
810
- if (!filterGroups && x._group) return true;
811
- return matcher.test(x.label);
812
- });
813
- } else filteredItems = null;
869
+ if (!Array.isArray(filteredItems)) {
870
+ if (term) {
871
+ const matcher = new RegExp(escapeRegex(term), "i");
872
+ filteredItems = p.items.filter((x) => {
873
+ if (!filterGroups && x._group) return true;
874
+ return matcher.test(x.label);
875
+ });
876
+ } else filteredItems = null;
877
+ }
814
878
  p.filteredItems = filteredItems;
815
879
  if (filteredItems && filterEmptyGroups) {
816
880
  let lastGroup = -1;
@@ -1021,8 +1085,10 @@ var DropList = class DropList {
1021
1085
  };
1022
1086
  viewCss.left += anchor.left - position.left;
1023
1087
  if (positionOptions.offset) {
1024
- if (positionOptions.offset.y) if (invertYPos) viewCss.top -= positionOptions.offset.y;
1025
- else viewCss.top += positionOptions.offset.y;
1088
+ if (positionOptions.offset.y) {
1089
+ if (invertYPos) viewCss.top -= positionOptions.offset.y;
1090
+ else viewCss.top += positionOptions.offset.y;
1091
+ }
1026
1092
  if (positionOptions.offset.x) {
1027
1093
  let rtl = elComputedStyle.direction === "rtl";
1028
1094
  viewCss.left += rtl ? -positionOptions.offset.x : positionOptions.offset.x;
@@ -1152,6 +1218,7 @@ var DropList = class DropList {
1152
1218
  p.lastPositionOptions = null;
1153
1219
  if (positionOptions === void 0) positionOptions = p.positionOptionsProvider?.() ?? p.lastPositionOptions;
1154
1220
  else p.lastPositionOptions = positionOptions;
1221
+ this._applyZIndex(positionOptions ?? null);
1155
1222
  if (positionOptions) {
1156
1223
  const elComputedStyle = getComputedStyle(el);
1157
1224
  const originalMaxHeight = el.style.maxHeight;
@@ -1353,7 +1420,8 @@ var DropList = class DropList {
1353
1420
  valueProp: p.valueProp,
1354
1421
  renderItem: p.renderItem,
1355
1422
  unrenderItem: p.unrenderItem,
1356
- positionOptionsProvider: () => p.currentSubDropList.showOptions
1423
+ positionOptionsProvider: () => p.currentSubDropList.showOptions,
1424
+ zIndex: () => this._p?.appliedZIndex ?? null
1357
1425
  });
1358
1426
  let onBlur = (event) => {
1359
1427
  if (this[DestroyedSymbol$1]) return;
@@ -1976,14 +2044,16 @@ var DropList = class DropList {
1976
2044
  } else if (p.focusItemEl) {
1977
2045
  let base = (0, _danielgindi_dom_utils_lib_Css.getElementOffset)(p.focusItemEl).top;
1978
2046
  let height = (0, _danielgindi_dom_utils_lib_Css.getElementHeight)(p.el, true);
1979
- while (true) {
1980
- next = p.focusItemEl.nextElementSibling;
1981
- if (!next) return;
1982
- if (next.tagName !== "LI") continue;
2047
+ let candidate = p.focusItemEl;
2048
+ next = null;
2049
+ while (candidate = direction === "prev_page" ? candidate.previousElementSibling : candidate.nextElementSibling) {
2050
+ if (candidate.tagName !== "LI") continue;
2051
+ next = candidate;
1983
2052
  if (direction === "prev_page") {
1984
2053
  if ((0, _danielgindi_dom_utils_lib_Css.getElementOffset)(next).top - base + height <= 0) break;
1985
2054
  } else if ((0, _danielgindi_dom_utils_lib_Css.getElementOffset)(next).top - base - height >= 0) break;
1986
2055
  }
2056
+ if (!next) return;
1987
2057
  if (next) {
1988
2058
  nextIndex = p.virtualListHelper.getItemIndexFromElement(next);
1989
2059
  if (nextIndex === void 0) nextIndex = -1;
@@ -2176,14 +2246,18 @@ var DropList = class DropList {
2176
2246
  _updateWidth(positionOptions) {
2177
2247
  const p = this._p, el = p.el;
2178
2248
  let targetWidth = 0;
2179
- if (positionOptions) if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
2180
- else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
2181
- else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
2249
+ if (positionOptions) {
2250
+ if (typeof positionOptions.updateWidth === "number") targetWidth = positionOptions.updateWidth;
2251
+ else if (positionOptions.targetWidth != null) targetWidth = positionOptions.targetWidth;
2252
+ else targetWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(positionOptions.target, true, true);
2253
+ }
2182
2254
  let autoWidth = 0;
2183
- if (!p.useExactTargetWidth || !targetWidth) if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
2184
- else {
2185
- el.style.width = "";
2186
- autoWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(el, true, true);
2255
+ if (!p.useExactTargetWidth || !targetWidth) {
2256
+ if (p.estimateWidth || p.virtualListHelper.isVirtual()) autoWidth = p.lastMeasureItemWidth;
2257
+ else {
2258
+ el.style.width = "";
2259
+ autoWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(el, true, true);
2260
+ }
2187
2261
  }
2188
2262
  let newOuterWidth = Math.max(autoWidth, targetWidth);
2189
2263
  (0, _danielgindi_dom_utils_lib_Css.setElementWidth)(el, newOuterWidth, true, true);
@@ -2198,8 +2272,7 @@ var DropList = class DropList {
2198
2272
  return newOuterWidth;
2199
2273
  }
2200
2274
  };
2201
- //#endregion
2202
- //#region src/lib/SelectBox.ts
2275
+ // src/lib/SelectBox.ts
2203
2276
  var DestroyedSymbol = Symbol("destroyed");
2204
2277
  var RestMultiItemsSymbol = Symbol("rest_multi_items");
2205
2278
  var hasTouchCapability = !!("ontouchstart" in window || window.DocumentTouch && window.document instanceof window.DocumentTouch || window.navigator.maxTouchPoints);
@@ -2447,9 +2520,12 @@ var SelectBox = class {
2447
2520
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.list);
2448
2521
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.singleWrapper);
2449
2522
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.input);
2523
+ (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.inputWrapper);
2450
2524
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.inputBackBuffer);
2451
2525
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.clearButtonWrapper);
2452
2526
  (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.openIndicator);
2527
+ (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.spinner);
2528
+ (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.controls);
2453
2529
  if (!p.ownsEl) {
2454
2530
  for (let name of Array.from(p.el.classList)) if (name.startsWith(p.baseClassName)) p.el.classList.remove(name);
2455
2531
  p.el.removeAttribute("role");
@@ -2535,6 +2611,7 @@ var SelectBox = class {
2535
2611
  p.itemsChanged = true;
2536
2612
  this._refreshItemByValueMap();
2537
2613
  if (resetValues) this.setSelectedValues(this.getSelectedValues());
2614
+ else this._scheduleSync("render_list");
2538
2615
  this._trigger("itemschanged", {
2539
2616
  term: null,
2540
2617
  mutated: true,
@@ -2812,6 +2889,22 @@ var SelectBox = class {
2812
2889
  this._setupDropdownMenu();
2813
2890
  return this;
2814
2891
  }
2892
+ /**
2893
+ * Sets `listOptions.zIndex` without recreating the DropList.
2894
+ * `undefined` falls back to `DropListDefaultOptions.zIndex`.
2895
+ */
2896
+ setListZIndex(zIndex) {
2897
+ const p = this._p;
2898
+ p.listOptions = {
2899
+ ...p.listOptions,
2900
+ zIndex
2901
+ };
2902
+ p.dropList?.setZIndex(zIndex === void 0 ? DefaultOptions.zIndex : zIndex);
2903
+ return this;
2904
+ }
2905
+ getListZIndex() {
2906
+ return this._p.listOptions?.zIndex;
2907
+ }
2815
2908
  setRenderSingleItem(render, unrender) {
2816
2909
  const p = this._p;
2817
2910
  p.renderSingleItem = render;
@@ -3174,6 +3267,10 @@ var SelectBox = class {
3174
3267
  top: "-9999px",
3175
3268
  whiteSpace: "pre"
3176
3269
  } });
3270
+ if (!p.controls) {
3271
+ p.controls = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__controls` });
3272
+ p.el.appendChild(p.controls);
3273
+ }
3177
3274
  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", {
3178
3275
  class: `${p.baseClassName}__search_field`,
3179
3276
  type: "search",
@@ -3195,7 +3292,7 @@ var SelectBox = class {
3195
3292
  this._unregisterDropdownEvents();
3196
3293
  const lastActiveElement = document.activeElement;
3197
3294
  p.list = (0, _danielgindi_dom_utils_lib_Dom.createElement)("ul", { class: `${p.baseClassName}__list` });
3198
- p.el.appendChild(p.list);
3295
+ p.el.insertBefore(p.list, p.controls);
3199
3296
  p.list.appendChild(p.inputWrapper);
3200
3297
  p.el.classList.remove(`${p.baseClassName}__single`);
3201
3298
  p.el.classList.add(`${p.baseClassName}__multi`);
@@ -3224,34 +3321,53 @@ var SelectBox = class {
3224
3321
  this._unregisterDropdownEvents();
3225
3322
  const lastActiveElement = document.activeElement;
3226
3323
  p.singleWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)("div", { class: `${p.baseClassName}__single_wrapper` });
3227
- p.el.appendChild(p.singleWrapper);
3228
- p.el.appendChild(p.inputWrapper);
3324
+ p.el.insertBefore(p.singleWrapper, p.controls);
3325
+ p.el.insertBefore(p.inputWrapper, p.controls);
3229
3326
  p.el.classList.remove(`${p.baseClassName}__multi`);
3230
3327
  p.el.classList.add(`${p.baseClassName}__single`);
3231
3328
  if (lastActiveElement === p.input) p.input.focus();
3232
3329
  this._registerDropdownEvents();
3233
3330
  }
3234
3331
  }
3235
- if (p.hasOpenIndicator !== !!p.openIndicator) if (p.hasOpenIndicator) {
3236
- p.openIndicator = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__open_indicator` });
3237
- p.el.appendChild(p.openIndicator);
3238
- p.el.classList.add(`${p.baseClassName}__has_open_indicator`);
3239
- } else {
3240
- (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.openIndicator);
3241
- delete p.openIndicator;
3242
- p.el.classList.remove(`${p.baseClassName}__has_open_indicator`);
3332
+ if (p.hasOpenIndicator !== !!p.openIndicator) {
3333
+ if (p.hasOpenIndicator) {
3334
+ p.openIndicator = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__open_indicator` });
3335
+ this._insertControl(p.openIndicator);
3336
+ p.el.classList.add(`${p.baseClassName}__has_open_indicator`);
3337
+ } else {
3338
+ (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.openIndicator);
3339
+ delete p.openIndicator;
3340
+ p.el.classList.remove(`${p.baseClassName}__has_open_indicator`);
3341
+ }
3243
3342
  }
3244
- if (p.isLoadingMode !== !!p.spinner) if (p.isLoadingMode) {
3245
- p.spinner = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__spinner` });
3246
- p.el.appendChild(p.spinner);
3247
- p.el.classList.add(`${p.baseClassName}__has_spinner`);
3248
- } else {
3249
- (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.spinner);
3250
- delete p.spinner;
3251
- p.el.classList.remove(`${p.baseClassName}__has_spinner`);
3343
+ if (p.isLoadingMode !== !!p.spinner) {
3344
+ if (p.isLoadingMode) {
3345
+ p.spinner = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__spinner` });
3346
+ this._insertControl(p.spinner);
3347
+ p.el.classList.add(`${p.baseClassName}__has_spinner`);
3348
+ } else {
3349
+ (0, _danielgindi_dom_utils_lib_DomCompat.remove)(p.spinner);
3350
+ delete p.spinner;
3351
+ p.el.classList.remove(`${p.baseClassName}__has_spinner`);
3352
+ }
3252
3353
  }
3253
3354
  }
3254
3355
  /**
3356
+ * Inserts a control into the controls group, keeping the order: spinner, clear button, open indicator
3357
+ * @private
3358
+ * @internal
3359
+ */
3360
+ _insertControl(control) {
3361
+ const p = this._p;
3362
+ const order = [
3363
+ p.spinner,
3364
+ p.clearButtonWrapper,
3365
+ p.openIndicator
3366
+ ];
3367
+ const next = order.slice(order.indexOf(control) + 1).find((x) => x && x.parentNode === p.controls);
3368
+ p.controls.insertBefore(control, next ?? null);
3369
+ }
3370
+ /**
3255
3371
  * @private
3256
3372
  * @internal
3257
3373
  */
@@ -3271,7 +3387,10 @@ var SelectBox = class {
3271
3387
  if (p.searchable || p.multi) classes.push(`${p.baseClassName}__searchable`);
3272
3388
  if (p.direction === "ltr" || p.direction === "rtl") classes.push(`${p.baseClassName}__` + p.direction);
3273
3389
  if (p.additionalClasses) classes = classes.concat(p.additionalClasses);
3274
- el.className = classes.join(" ");
3390
+ classes = classes.join(" ").split(/\s+/).filter(Boolean);
3391
+ const previousClasses = p.appliedClasses ?? [];
3392
+ el.className = Array.from(el.classList).filter((name) => !name.startsWith(p.baseClassName) && !previousClasses.includes(name)).concat(classes).join(" ");
3393
+ p.appliedClasses = classes;
3275
3394
  }
3276
3395
  /** @private */
3277
3396
  /** @internal */
@@ -3375,21 +3494,22 @@ var SelectBox = class {
3375
3494
  p.selectionChanged = true;
3376
3495
  p.resortBySelectionNeeded = true;
3377
3496
  const hasGroupSync = !!event.isCheckingGroup;
3378
- if (p.showSelection) if (checked) {
3379
- if (dropList.itemCount() === 1 && p.clearInputWhen.includes("multi_select_single")) this._setInputText("");
3380
- if (p.sortSelectedItems) {
3381
- if (!hasGroupSync) this._scheduleSync("full");
3497
+ if (p.showSelection) {
3498
+ if (checked) {
3499
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes("multi_select_single")) this._setInputText("");
3500
+ if (p.sortSelectedItems) {
3501
+ if (!hasGroupSync) this._scheduleSync("full");
3502
+ } else {
3503
+ if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length > p.maxMultiItems) this._scheduleSync("addOrUpdateMultiItemRestElement");
3504
+ else this._scheduleSync("addMultiItemElement", item);
3505
+ if (!hasGroupSync) this._scheduleSync("render_base");
3506
+ }
3382
3507
  } else {
3383
- if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length > p.maxMultiItems) this._scheduleSync("addOrUpdateMultiItemRestElement");
3384
- else this._scheduleSync("addMultiItemElement", item);
3508
+ if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
3509
+ else this._scheduleSync("removeMultiItemElement", item);
3385
3510
  if (!hasGroupSync) this._scheduleSync("render_base");
3386
3511
  }
3387
- } else {
3388
- if (p.maxMultiItems != null && (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).length === p.maxMultiItems) this._scheduleSync("removeMultiItemRestElement");
3389
- else this._scheduleSync("removeMultiItemElement", item);
3390
- if (!hasGroupSync) this._scheduleSync("render_base");
3391
- }
3392
- else if (p.multi) this._scheduleSync("syncPlaceholder");
3512
+ } else if (p.multi) this._scheduleSync("syncPlaceholder");
3393
3513
  this._trigger(checked ? "addsel" : "removesel", {
3394
3514
  value,
3395
3515
  item,
@@ -3435,6 +3555,7 @@ var SelectBox = class {
3435
3555
  }
3436
3556
  }
3437
3557
  });
3558
+ dropList._setOwnerSelectBox(this);
3438
3559
  p.sink.add(dropList.el, "mousedown", preventDropListMouseDownBlur);
3439
3560
  this._registerDropdownEvents();
3440
3561
  }
@@ -3786,9 +3907,8 @@ var SelectBox = class {
3786
3907
  const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
3787
3908
  if (p.selectedItems.length > 0 && p.selectedItems.some((x) => x[multiItemLabelProp] !== false) && p.clearable && p.showSelection) {
3788
3909
  if (!p.clearButtonWrapper) {
3789
- p.clearButtonWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)(p.multi ? "li" : "span", { class: `${p.baseClassName}__clear` }, p.clearButton = (0, _danielgindi_dom_utils_lib_Dom.createElement)("button"));
3790
- if (p.multi) (0, _danielgindi_dom_utils_lib_DomCompat.append)(p.list, p.clearButtonWrapper);
3791
- else (0, _danielgindi_dom_utils_lib_DomCompat.append)(p.el, p.clearButtonWrapper);
3910
+ p.clearButtonWrapper = (0, _danielgindi_dom_utils_lib_Dom.createElement)("span", { class: `${p.baseClassName}__clear` }, p.clearButton = (0, _danielgindi_dom_utils_lib_Dom.createElement)("button"));
3911
+ this._insertControl(p.clearButtonWrapper);
3792
3912
  p.el.classList.add(`${p.baseClassName}__has_clear`);
3793
3913
  p.sink.add(p.clearButton, "click", () => {
3794
3914
  if (this.isDisabled() || this.isReadOnly()) return;
@@ -3808,9 +3928,10 @@ var SelectBox = class {
3808
3928
  _syncPlaceholder() {
3809
3929
  const p = this._p, multiItemLabelProp = p.multiItemLabelProp;
3810
3930
  let placeholder = "";
3811
- if (p.multi && !p.showSelection) if (typeof p.multiPlaceholderFormatter === "function") placeholder = p.multiPlaceholderFormatter(p.selectedItems);
3812
- else placeholder = p.selectedItems.length === 0 ? p.placeholder || "" : defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
3813
- else if (p.selectedItems.length === 0 || !p.showSelection || p.selectedItems.every((x) => x[multiItemLabelProp] === false)) placeholder = p.placeholder == null ? "" : p.placeholder + "";
3931
+ if (p.multi && !p.showSelection) {
3932
+ if (typeof p.multiPlaceholderFormatter === "function") placeholder = p.multiPlaceholderFormatter(p.selectedItems);
3933
+ else placeholder = p.selectedItems.length === 0 ? p.placeholder || "" : defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
3934
+ } else if (p.selectedItems.length === 0 || !p.showSelection || p.selectedItems.every((x) => x[multiItemLabelProp] === false)) placeholder = p.placeholder == null ? "" : p.placeholder + "";
3814
3935
  p.input.setAttribute("placeholder", placeholder);
3815
3936
  if (p.showPlaceholderInTooltip) p.input.setAttribute("title", placeholder);
3816
3937
  else p.input.removeAttribute("title");
@@ -3934,46 +4055,48 @@ var SelectBox = class {
3934
4055
  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`);
3935
4056
  } else if (/click|mouse|touch/.test(originatingEvent.type)) nextFocus = (0, _danielgindi_dom_utils_lib_Dom.next)(itemEl, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
3936
4057
  const item = itemEl[ItemSymbol], value = item[p.valueProp];
3937
- if (item !== void 0) if (value === RestMultiItemsSymbol) {
3938
- let items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).slice(p.maxMultiItems);
3939
- let itemsToRemove = [];
3940
- for (let item of items) {
4058
+ if (item !== void 0) {
4059
+ if (value === RestMultiItemsSymbol) {
4060
+ let items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter((x) => !x._group)).slice(p.maxMultiItems);
4061
+ let itemsToRemove = [];
4062
+ for (let item of items) {
4063
+ let removeselEvt = {
4064
+ value: item[p.valueProp],
4065
+ item,
4066
+ cancel: false
4067
+ };
4068
+ this._trigger("removesel:before", removeselEvt);
4069
+ if (!removeselEvt.cancel) itemsToRemove.push(item);
4070
+ }
4071
+ if (itemsToRemove.length > 0) {
4072
+ this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
4073
+ for (let item of itemsToRemove) {
4074
+ let idx = p.selectedItems.indexOf(item);
4075
+ if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
4076
+ if (idx !== -1) {
4077
+ p.selectedItems.splice(idx, 1);
4078
+ p.selectedValues.splice(idx, 1);
4079
+ p.selectionChanged = true;
4080
+ p.resortBySelectionNeeded = true;
4081
+ }
4082
+ }
4083
+ }
4084
+ if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
4085
+ if (itemsToRemove.length > 0) this._scheduleSync("render_list");
4086
+ } else {
3941
4087
  let removeselEvt = {
3942
- value: item[p.valueProp],
4088
+ value,
3943
4089
  item,
3944
4090
  cancel: false
3945
4091
  };
3946
4092
  this._trigger("removesel:before", removeselEvt);
3947
- if (!removeselEvt.cancel) itemsToRemove.push(item);
3948
- }
3949
- if (itemsToRemove.length > 0) {
3950
- this._removeMultiItemElementByIndex(p.multiItemEls.length - 1);
3951
- for (let item of itemsToRemove) {
3952
- let idx = p.selectedItems.indexOf(item);
3953
- if (idx === -1) idx = p.selectedValues.indexOf(item[p.valueProp]);
3954
- if (idx !== -1) {
3955
- p.selectedItems.splice(idx, 1);
3956
- p.selectedValues.splice(idx, 1);
3957
- p.selectionChanged = true;
3958
- p.resortBySelectionNeeded = true;
3959
- }
3960
- }
4093
+ if (removeselEvt.cancel) return this;
4094
+ this._removeMultiItem(item);
4095
+ this._trigger("removesel", {
4096
+ value,
4097
+ item
4098
+ });
3961
4099
  }
3962
- if (items.length > itemsToRemove.length) this._addMultiItemRestElement();
3963
- if (itemsToRemove.length > 0) this._scheduleSync("render_list");
3964
- } else {
3965
- let removeselEvt = {
3966
- value,
3967
- item,
3968
- cancel: false
3969
- };
3970
- this._trigger("removesel:before", removeselEvt);
3971
- if (removeselEvt.cancel) return this;
3972
- this._removeMultiItem(item);
3973
- this._trigger("removesel", {
3974
- value,
3975
- item
3976
- });
3977
4100
  }
3978
4101
  if (!nextFocus) nextFocus = p.el.querySelector(`.${p.baseClassName}__item, .${p.baseClassName}__search_field`);
3979
4102
  if (hasClass(nextFocus, `${p.baseClassName}__search_wrapper`)) nextFocus = nextFocus.querySelector("input");
@@ -4032,14 +4155,6 @@ var SelectBox = class {
4032
4155
  let hasResize = false;
4033
4156
  if (p.multi && p.multiItemEls.length === 0 && p.showSelection) {
4034
4157
  input.style.width = "";
4035
- let beforeWidth = 0, afterWidth = 0;
4036
- let beforeStyle = getComputedStyle(p.list || el, "::before");
4037
- 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);
4038
- let afterStyle = getComputedStyle(p.list || el, "::after");
4039
- 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);
4040
- let contentWidth = (0, _danielgindi_dom_utils_lib_Css.getElementWidth)(p.list || el);
4041
- contentWidth -= beforeWidth + afterWidth;
4042
- input.style.width = `${contentWidth}px`;
4043
4158
  hasResize = true;
4044
4159
  } else {
4045
4160
  (0, _danielgindi_dom_utils_lib_Css.setCssProps)(backBufferEl, (0, _danielgindi_dom_utils_lib_Css.getCssProps)(input, inputBackbufferCssProps));
@@ -4324,7 +4439,6 @@ var SelectBox = class {
4324
4439
  return joined;
4325
4440
  }
4326
4441
  };
4327
- //#endregion
4328
4442
  exports.DropList = DropList;
4329
4443
  exports.DropListDefaultOptions = DefaultOptions;
4330
4444
  exports.ItemSymbol = ItemSymbol;