@kupola/kupola 1.6.2 → 1.6.4

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.
@@ -2269,13 +2269,13 @@ class _r {
2269
2269
  const e = t.className;
2270
2270
  if (typeof e == "string") {
2271
2271
  for (const s of this._cssClasses)
2272
- if (e.includes(s)) {
2273
- const n = s.replace("ds-", ""), r = this.initializers.get(n) || this.initializers.get(s);
2274
- if (r) {
2272
+ if (new RegExp(`(^|\\s)${s}(\\s|$)`).test(e)) {
2273
+ const r = s.replace("ds-", ""), a = this.initializers.get(r) || this.initializers.get(s);
2274
+ if (a) {
2275
2275
  try {
2276
- await r(t), this.processedElements.add(t);
2277
- } catch (a) {
2278
- console.error(`[ComponentInitializerRegistry] Error initializing "${n}":`, a);
2276
+ await a(t), this.processedElements.add(t);
2277
+ } catch (o) {
2278
+ console.error(`[ComponentInitializerRegistry] Error initializing "${r}":`, o);
2279
2279
  }
2280
2280
  return;
2281
2281
  }
@@ -2302,13 +2302,13 @@ class _r {
2302
2302
  const e = t.className;
2303
2303
  if (typeof e == "string") {
2304
2304
  for (const s of this._cssClasses)
2305
- if (e.includes(s)) {
2306
- const n = s.replace("ds-", ""), r = this.cleanupFunctions.get(n) || this.cleanupFunctions.get(s);
2307
- if (r) {
2305
+ if (new RegExp(`(^|\\s)${s}(\\s|$)`).test(e)) {
2306
+ const r = s.replace("ds-", ""), a = this.cleanupFunctions.get(r) || this.cleanupFunctions.get(s);
2307
+ if (a) {
2308
2308
  try {
2309
- r(t);
2310
- } catch (a) {
2311
- console.error(`[ComponentInitializerRegistry] Error cleaning up "${n}":`, a);
2309
+ a(t);
2310
+ } catch (o) {
2311
+ console.error(`[ComponentInitializerRegistry] Error cleaning up "${r}":`, o);
2312
2312
  }
2313
2313
  this.processedElements.delete(t);
2314
2314
  return;
@@ -2958,7 +2958,7 @@ class Er {
2958
2958
  !this.trigger || !this.menu || this.element.__kupolaInitialized || (this._itemClickHandler = (t) => {
2959
2959
  t.stopPropagation();
2960
2960
  const e = t.currentTarget;
2961
- e.classList.contains("is-disabled") || e.classList.contains("ds-dropdown__divider") || (this.menu.querySelectorAll(".ds-dropdown__item").forEach((s) => s.classList.remove("is-selected")), e.classList.add("is-selected"), this.triggerText && !e.hasAttribute("data-no-update-trigger") && (this.triggerText.textContent = e.textContent.trim()), this.element.setAttribute("data-value", e.getAttribute("data-value") || ""), this.onSelect && this.onSelect({ item: e, value: e.getAttribute("data-value"), text: e.textContent.trim() }), this.closeOnClick && (this.hideMenu(), this.trigger.focus()));
2961
+ e.classList.contains("is-disabled") || e.classList.contains("ds-dropdown__divider") || (this.menu.querySelectorAll(".ds-dropdown__item").forEach((s) => s.classList.remove("is-selected")), e.classList.add("is-selected"), this.triggerText && !e.hasAttribute("data-no-update-trigger") && (this.triggerText.textContent = e.textContent.trim()), this.element.setAttribute("data-value", e.getAttribute("data-value") || ""), this.onSelect && this.onSelect({ item: e, value: e.getAttribute("data-value"), text: e.textContent.trim() }), this.closeOnClick !== !1 && (this.hideMenu(), this.trigger && this.trigger.focus()));
2962
2962
  }, this._bindMenuItems(), this._triggerClickHandler = (t) => {
2963
2963
  t.stopPropagation(), !this.disabled && this.toggleMenu();
2964
2964
  }, this._triggerMouseenterHandler = () => {
@@ -2998,12 +2998,14 @@ class Er {
2998
2998
  }, this.triggerMode === "hover" ? (this.trigger.addEventListener("mouseenter", this._triggerMouseenterHandler), this.trigger.addEventListener("mouseleave", this._triggerMouseleaveHandler), this.menu.addEventListener("mouseenter", this._mouseenterHandler), this.menu.addEventListener("mouseleave", this._mouseleaveHandler)) : this.trigger.addEventListener("click", this._triggerClickHandler), this._triggerKeydownHandler = (t) => {
2999
2999
  this.disabled || (t.key === "Enter" || t.key === " " || t.key === "ArrowDown") && (t.preventDefault(), this.showMenu());
3000
3000
  }, this.trigger.addEventListener("keydown", this._triggerKeydownHandler), document.addEventListener("keydown", this._keydownHandler), this._documentClickHandler = (t) => {
3001
- !this.element.contains(t.target) && !this.menu.contains(t.target) && this.hideMenu();
3001
+ if (!this.isOpen) return;
3002
+ const e = this.element.contains(t.target), s = this.menu && this.menu.contains(t.target);
3003
+ !e && !s && this.hideMenu();
3002
3004
  }, this._documentClickListener = H.on(document, "click", this._documentClickHandler, { scope: this.scope }), this.menu.style.display = "none", this.element.__kupolaInitialized = !0);
3003
3005
  }
3004
3006
  _bindMenuItems() {
3005
3007
  this.menu.querySelectorAll(".ds-dropdown__item").forEach((t) => {
3006
- t.addEventListener("click", (e) => this._itemClickHandler(e)), t._dropdownItemClickHandler = (e) => this._itemClickHandler(e);
3008
+ t._dropdownItemClickHandler = (e) => this._itemClickHandler(e), t.addEventListener("click", t._dropdownItemClickHandler);
3007
3009
  });
3008
3010
  }
3009
3011
  _getNavigableItems() {
@@ -3015,14 +3017,14 @@ class Er {
3015
3017
  _calculatePosition() {
3016
3018
  if (!this.autoPosition)
3017
3019
  return;
3018
- const t = this.element.getBoundingClientRect(), e = this.menu.getBoundingClientRect(), s = window.innerHeight, n = window.innerWidth;
3020
+ const t = this.element.getBoundingClientRect(), e = window.innerHeight, s = window.innerWidth;
3019
3021
  if (this.menu.classList.remove("ds-dropdown--top", "ds-dropdown--right", "ds-dropdown--dropup"), this.appendToBody) {
3020
- this.menu.style.width = `${Math.max(t.width, e.width)}px`;
3021
- const r = s - t.bottom, a = t.top;
3022
- r < e.height && a > r ? (this.menu.style.top = `${t.top - e.height - 4}px`, this.menu.style.bottom = "auto") : (this.menu.style.top = `${t.bottom + 4}px`, this.menu.style.bottom = "auto"), t.left + e.width > n ? (this.menu.style.left = `${t.right - Math.max(t.width, e.width)}px`, this.menu.style.right = "auto") : (this.menu.style.left = `${t.left}px`, this.menu.style.right = "auto");
3022
+ this.menu.style.width = `${t.width}px`;
3023
+ const n = this.menu.getBoundingClientRect(), r = e - t.bottom, a = t.top;
3024
+ r < n.height && a > r ? (this.menu.style.top = `${t.top - n.height - 4}px`, this.menu.style.bottom = "auto") : (this.menu.style.top = `${t.bottom + 4}px`, this.menu.style.bottom = "auto"), t.left + n.width > s ? (this.menu.style.left = `${t.right - n.width}px`, this.menu.style.right = "auto") : (this.menu.style.left = `${t.left}px`, this.menu.style.right = "auto");
3023
3025
  } else {
3024
- const r = s - t.bottom, a = t.top;
3025
- r < e.height && a > r ? (this.menu.classList.add("ds-dropdown--dropup"), this.menu.style.top = "auto", this.menu.style.bottom = "100%", this.menu.style.marginBottom = "4px") : (this.menu.style.top = "100%", this.menu.style.bottom = "auto", this.menu.style.marginBottom = "0"), t.left + e.width > n ? (this.menu.style.left = "auto", this.menu.style.right = "0") : (this.menu.style.left = "0", this.menu.style.right = "auto");
3026
+ const n = e - t.bottom, r = t.top;
3027
+ n < menuRect.height && r > n ? (this.menu.classList.add("ds-dropdown--dropup"), this.menu.style.top = "auto", this.menu.style.bottom = "100%", this.menu.style.marginBottom = "4px") : (this.menu.style.top = "100%", this.menu.style.bottom = "auto", this.menu.style.marginBottom = "0"), t.left + menuRect.width > s ? (this.menu.style.left = "auto", this.menu.style.right = "0") : (this.menu.style.left = "0", this.menu.style.right = "auto");
3026
3028
  }
3027
3029
  }
3028
3030
  showMenu() {
@@ -3033,12 +3035,12 @@ class Er {
3033
3035
  }
3034
3036
  _appendMenuToBody() {
3035
3037
  if (!this.menu) return;
3036
- this._originalParent = this.menu.parentNode, this._originalPosition = this.menu.style.position, this._originalTop = this.menu.style.top, this._originalLeft = this.menu.style.left, this._originalRight = this.menu.style.right, this._originalBottom = this.menu.style.bottom, this._originalMarginBottom = this.menu.style.marginBottom, this._originalWidth = this.menu.style.width, this._originalTransform = this.menu.style.transform, this._originalZIndex = this.menu.style.zIndex;
3037
- const t = W().dropdown;
3038
- this.menu.style.position = "fixed", this.menu.style.zIndex = t, this.menu.style.transform = "translateZ(0)", document.body.appendChild(this.menu);
3038
+ this._originalParent = this.menu.parentNode, this._originalPosition = this.menu.style.position, this._originalTop = this.menu.style.top, this._originalLeft = this.menu.style.left, this._originalRight = this.menu.style.right, this._originalBottom = this.menu.style.bottom, this._originalMarginBottom = this.menu.style.marginBottom, this._originalWidth = this.menu.style.width, this._originalTransform = this.menu.style.transform, this._originalZIndex = this.menu.style.zIndex, this._originalDisplay = this.menu.style.display;
3039
+ const t = this.element.getBoundingClientRect(), e = W().dropdown;
3040
+ this.menu.style.position = "fixed", this.menu.style.width = `${t.width}px`, this.menu.style.zIndex = e, this.menu.style.transform = "translateZ(0)", document.body.appendChild(this.menu);
3039
3041
  }
3040
3042
  _restoreMenuFromBody() {
3041
- !this.menu || !this._originalParent || (this._originalParent.appendChild(this.menu), this.menu.style.position = this._originalPosition || "", this.menu.style.top = this._originalTop || "", this.menu.style.left = this._originalLeft || "", this.menu.style.right = this._originalRight || "", this.menu.style.bottom = this._originalBottom || "", this.menu.style.marginBottom = this._originalMarginBottom || "", this.menu.style.width = this._originalWidth || "", this.menu.style.zIndex = this._originalZIndex || "", this.menu.style.transform = this._originalTransform || "", this._originalParent = null);
3043
+ !this.menu || !this._originalParent || (this._originalParent.appendChild(this.menu), this.menu.style.position = this._originalPosition || "", this.menu.style.top = this._originalTop || "", this.menu.style.left = this._originalLeft || "", this.menu.style.right = this._originalRight || "", this.menu.style.bottom = this._originalBottom || "", this.menu.style.marginBottom = this._originalMarginBottom || "", this.menu.style.width = this._originalWidth || "", this.menu.style.zIndex = this._originalZIndex || "", this.menu.style.transform = this._originalTransform || "", this.menu.style.display = this._originalDisplay || "", this._originalParent = null, console.log("[Dropdown] Menu restored from body"));
3042
3044
  }
3043
3045
  _addScrollListener() {
3044
3046
  this._scrollHandler = () => {
@@ -3059,17 +3061,21 @@ class Er {
3059
3061
  }
3060
3062
  // Update menu items dynamically
3061
3063
  setItems(t) {
3062
- this.menu.querySelectorAll(".ds-dropdown__item").forEach((e) => {
3064
+ this._itemClickHandler || (this._itemClickHandler = (e) => {
3065
+ e.stopPropagation();
3066
+ const s = e.currentTarget;
3067
+ s.classList.contains("is-disabled") || s.classList.contains("ds-dropdown__divider") || (this.menu.querySelectorAll(".ds-dropdown__item").forEach((n) => n.classList.remove("is-selected")), s.classList.add("is-selected"), this.triggerText && !s.hasAttribute("data-no-update-trigger") && (this.triggerText.textContent = s.textContent.trim()), this.element.setAttribute("data-value", s.getAttribute("data-value") || ""), this.onSelect && this.onSelect({ item: s, value: s.getAttribute("data-value"), text: s.textContent.trim() }), this.closeOnClick !== !1 && (this.hideMenu(), this.trigger && this.trigger.focus()));
3068
+ }), this.menu.querySelectorAll(".ds-dropdown__item").forEach((e) => {
3063
3069
  e._dropdownItemClickHandler && e.removeEventListener("click", e._dropdownItemClickHandler);
3064
- }), this.menu.innerHTML = "", t.forEach((e) => {
3070
+ }), this.menu.innerHTML = "", t.forEach((e, s) => {
3065
3071
  if (e.type === "divider") {
3066
- const s = document.createElement("div");
3067
- s.className = "ds-dropdown__divider", this.menu.appendChild(s);
3072
+ const n = document.createElement("div");
3073
+ n.className = "ds-dropdown__divider", this.menu.appendChild(n);
3068
3074
  } else {
3069
- const s = document.createElement("div");
3070
- s.className = "ds-dropdown__item" + (e.disabled ? " is-disabled" : "") + (e.active ? " is-selected" : ""), s.textContent = e.text || e.label || "", e.value !== void 0 && s.setAttribute("data-value", e.value), e.icon && (s.innerHTML = e.icon + s.innerHTML), e.disabled && s.classList.add("is-disabled"), this.menu.appendChild(s);
3075
+ const n = document.createElement("div");
3076
+ n.className = "ds-dropdown__item" + (e.disabled ? " is-disabled" : "") + (e.active ? " is-selected" : ""), n.textContent = e.text || e.label || "", e.value !== void 0 && n.setAttribute("data-value", e.value), e.icon && (n.innerHTML = e.icon + n.innerHTML), e.disabled && n.classList.add("is-disabled"), n._dropdownItemClickHandler = (r) => this._itemClickHandler(r), n.addEventListener("click", n._dropdownItemClickHandler), this.menu.appendChild(n);
3071
3077
  }
3072
- }), this._bindMenuItems();
3078
+ });
3073
3079
  }
3074
3080
  destroy() {
3075
3081
  this.element.__kupolaInitialized && (clearTimeout(this._hoverTimer), clearTimeout(this._hoverLeaveTimer), this.trigger && (this._triggerClickHandler && this.trigger.removeEventListener("click", this._triggerClickHandler), this._triggerMouseenterHandler && this.trigger.removeEventListener("mouseenter", this._triggerMouseenterHandler), this._triggerMouseleaveHandler && this.trigger.removeEventListener("mouseleave", this._triggerMouseleaveHandler), this._triggerKeydownHandler && this.trigger.removeEventListener("keydown", this._triggerKeydownHandler)), this.menu && (this.menu.querySelectorAll(".ds-dropdown__item").forEach((t) => {
@@ -3078,6 +3084,7 @@ class Er {
3078
3084
  }
3079
3085
  }
3080
3086
  function Jt(i, t) {
3087
+ i._kupolaDropdown && i._kupolaDropdown.destroy();
3081
3088
  const e = new Er(i, t);
3082
3089
  e.init(), i._kupolaDropdown = e;
3083
3090
  }
@@ -3127,7 +3134,9 @@ class wr {
3127
3134
  break;
3128
3135
  }
3129
3136
  }, document.addEventListener("keydown", this._keydownHandler), this._documentClickHandler = (t) => {
3130
- !this.element.contains(t.target) && !this.optionsEl.contains(t.target) && this.hideOptions();
3137
+ if (!this.isOpen) return;
3138
+ const e = this.element.contains(t.target), s = this.optionsEl && this.optionsEl.contains(t.target);
3139
+ !e && !s && this.hideOptions();
3131
3140
  }, this._documentClickListener = H.on(document, "click", this._documentClickHandler, { scope: this.scope }), this._restoreSelectedState(), this.optionsEl.style.display = "none", this.element.__kupolaInitialized = !0);
3132
3141
  }
3133
3142
  _collectOptions() {
@@ -3175,11 +3184,17 @@ class wr {
3175
3184
  }), this.focusIndex = -1;
3176
3185
  }
3177
3186
  _renderRemoteOptions(t) {
3178
- this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach((e) => {
3187
+ this._optionClickHandler || (this._optionClickHandler = (e) => {
3188
+ e.stopPropagation();
3189
+ const s = e.currentTarget;
3190
+ if (s.classList.contains("is-disabled")) return;
3191
+ const n = s.getAttribute("data-value");
3192
+ this.multiple ? this._toggleMultiOption(n, s) : this._selectSingleOption(n, s);
3193
+ }), this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach((e) => {
3179
3194
  e._selectOptionClickHandler && e.removeEventListener("click", e._selectOptionClickHandler), e.remove();
3180
3195
  }), t.forEach((e) => {
3181
3196
  const s = document.createElement("div");
3182
- s.className = "ds-select__option", s.setAttribute("data-value", e.value), s.textContent = e.text || e.label, e.disabled && s.classList.add("is-disabled"), this.selectedValues.has(e.value) && s.classList.add("is-selected"), s.addEventListener("click", (n) => this._optionClickHandler(n)), s._selectOptionClickHandler = (n) => this._optionClickHandler(n), this.optionsEl.appendChild(s);
3197
+ s.className = "ds-select__option", s.setAttribute("data-value", e.value), s.textContent = e.text || e.label, e.disabled && s.classList.add("is-disabled"), this.selectedValues.has(e.value) && s.classList.add("is-selected"), s._selectOptionClickHandler = (n) => this._optionClickHandler(n), s.addEventListener("click", s._selectOptionClickHandler), this.optionsEl.appendChild(s);
3183
3198
  }), this.allOptions = t.map((e) => ({
3184
3199
  el: this.optionsEl.querySelector(`[data-value="${e.value}"]`),
3185
3200
  value: e.value,
@@ -3256,7 +3271,7 @@ class wr {
3256
3271
  }
3257
3272
  _bindOptionClicks() {
3258
3273
  this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach((t) => {
3259
- t.addEventListener("click", (e) => this._optionClickHandler(e)), t._selectOptionClickHandler = (e) => this._optionClickHandler(e);
3274
+ t._selectOptionClickHandler = (e) => this._optionClickHandler(e), t.addEventListener("click", t._selectOptionClickHandler);
3260
3275
  });
3261
3276
  }
3262
3277
  _getVisibleOptions() {
@@ -3285,18 +3300,18 @@ class wr {
3285
3300
  _appendOptionsToBody() {
3286
3301
  if (!this.optionsEl) return;
3287
3302
  this._originalParent = this.optionsEl.parentNode, this._originalPosition = this.optionsEl.style.position, this._originalTop = this.optionsEl.style.top, this._originalLeft = this.optionsEl.style.left, this._originalRight = this.optionsEl.style.right, this._originalWidth = this.optionsEl.style.width, this._originalTransform = this.optionsEl.style.transform, this._originalZIndex = this.optionsEl.style.zIndex;
3288
- const t = W().dropdown;
3289
- this.optionsEl.style.position = "fixed", this.optionsEl.style.zIndex = t, this.optionsEl.style.transform = "translateZ(0)", document.body.appendChild(this.optionsEl);
3303
+ const t = this.element.getBoundingClientRect(), e = W().dropdown;
3304
+ this.optionsEl.style.position = "fixed", this.optionsEl.style.width = `${t.width}px`, this.optionsEl.style.zIndex = e, this.optionsEl.style.transform = "translateZ(0)", document.body.appendChild(this.optionsEl);
3290
3305
  }
3291
3306
  _restoreOptionsFromBody() {
3292
3307
  !this.optionsEl || !this._originalParent || (this._originalParent.appendChild(this.optionsEl), this.optionsEl.style.position = this._originalPosition || "", this.optionsEl.style.top = this._originalTop || "", this.optionsEl.style.left = this._originalLeft || "", this.optionsEl.style.right = this._originalRight || "", this.optionsEl.style.width = this._originalWidth || "", this.optionsEl.style.zIndex = this._originalZIndex || "", this.optionsEl.style.transform = this._originalTransform || "", this._originalParent = null);
3293
3308
  }
3294
3309
  _calculateOptionsPosition() {
3295
3310
  if (!this.appendToBody || !this.optionsEl) return;
3296
- const t = this.element.getBoundingClientRect(), e = this.optionsEl.getBoundingClientRect(), s = window.innerHeight, n = window.innerWidth;
3297
- this.optionsEl.style.width = `${Math.max(t.width, e.width)}px`;
3298
- const r = s - t.bottom, a = t.top;
3299
- r < e.height && a > r ? this.optionsEl.style.top = `${t.top - e.height - 4}px` : this.optionsEl.style.top = `${t.bottom + 4}px`, t.left + e.width > n ? this.optionsEl.style.left = `${t.right - Math.max(t.width, e.width)}px` : this.optionsEl.style.left = `${t.left}px`;
3311
+ const t = this.element.getBoundingClientRect(), e = window.innerHeight, s = window.innerWidth;
3312
+ this.optionsEl.style.width = `${t.width}px`;
3313
+ const n = this.optionsEl.getBoundingClientRect(), r = e - t.bottom, a = t.top;
3314
+ r < n.height && a > r ? this.optionsEl.style.top = `${t.top - n.height - 4}px` : this.optionsEl.style.top = `${t.bottom + 4}px`, t.left + n.width > s ? this.optionsEl.style.left = `${t.right - n.width}px` : this.optionsEl.style.left = `${t.left}px`;
3300
3315
  }
3301
3316
  toggleOptions() {
3302
3317
  this.isOpen ? this.hideOptions() : this.showOptions();