monobill-mintui 0.6.522 → 0.6.540

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/index.js CHANGED
@@ -1965,13 +1965,18 @@ var g = class extends HTMLElement {
1965
1965
  customElements.get("mint-modal") || customElements.define("mint-modal", g);
1966
1966
  //#endregion
1967
1967
  //#region src/components/popover/Popover.ts
1968
- var _ = class extends HTMLElement {
1968
+ var _ = class e extends HTMLElement {
1969
+ static {
1970
+ this.VIEWPORT_EDGE_MARGIN = 12;
1971
+ }
1969
1972
  static get observedAttributes() {
1970
1973
  return [
1971
1974
  "id",
1972
1975
  "direction",
1973
1976
  "open",
1974
1977
  "trigger-id",
1978
+ "trigger-toggle",
1979
+ "trigger-align",
1975
1980
  "padding",
1976
1981
  "hover",
1977
1982
  "distance"
@@ -2008,7 +2013,7 @@ var _ = class extends HTMLElement {
2008
2013
  let e = this._isInsideModal() ? "z-[80]" : "z-[60]";
2009
2014
  this.classList.remove("z-50", "z-[60]", "z-[80]"), this.classList.add(e);
2010
2015
  }
2011
- this.render(), (e === "trigger-id" || e === "hover") && this._setupTrigger(), e === "open" && this.isOpen() && this._closeOtherPopovers();
2016
+ this.render(), (e === "trigger-id" || e === "hover" || e === "trigger-toggle") && this._setupTrigger(), e === "open" && this.isOpen() && this._closeOtherPopovers();
2012
2017
  }
2013
2018
  }
2014
2019
  getId() {
@@ -2060,6 +2065,13 @@ var _ = class extends HTMLElement {
2060
2065
  isHoverEnabled() {
2061
2066
  return this.getAttribute("hover") === "true";
2062
2067
  }
2068
+ getTriggerAlign() {
2069
+ let e = (this.getAttribute("trigger-align") || "center").toLowerCase();
2070
+ return e === "start" || e === "end" ? e : "center";
2071
+ }
2072
+ isTriggerToggleEnabled() {
2073
+ return this.getAttribute("trigger-toggle") !== "false";
2074
+ }
2063
2075
  isOpen() {
2064
2076
  return this.getAttribute("open") === "true";
2065
2077
  }
@@ -2076,7 +2088,7 @@ var _ = class extends HTMLElement {
2076
2088
  }, 10));
2077
2089
  }
2078
2090
  _attachTriggerListener() {
2079
- if (this._triggerElement && !this._triggerClickHandler) {
2091
+ if (this.isTriggerToggleEnabled() && this._triggerElement && !this._triggerClickHandler) {
2080
2092
  let e = this;
2081
2093
  this._triggerClickHandler = function(t) {
2082
2094
  t.stopImmediatePropagation(), t.preventDefault(), e.getAttribute("open") === "true" ? e.removeAttribute("open") : e.setAttribute("open", "true");
@@ -2120,53 +2132,59 @@ var _ = class extends HTMLElement {
2120
2132
  left: 0,
2121
2133
  direction: "down"
2122
2134
  };
2123
- let e = this._triggerElement.getBoundingClientRect(), t = this._popover.querySelector(".popover-content");
2124
- if (!t) return {
2135
+ let t = this._triggerElement.getBoundingClientRect(), n = this._popover.querySelector(".popover-content");
2136
+ if (!n) return {
2125
2137
  top: 0,
2126
2138
  left: 0,
2127
2139
  direction: "down"
2128
2140
  };
2129
- this.classList.contains("hidden") && (this.classList.remove("hidden"), this._popover.style.visibility = "hidden");
2130
- let n = t.getBoundingClientRect(), r = window.innerWidth, i = window.innerHeight, a = this._getDistancePx(), o = this.getDirection(), s = 0, c = 0;
2131
- switch (o) {
2141
+ n.style.removeProperty("max-height"), n.style.removeProperty("overflow-y"), this.classList.contains("hidden") && (this.classList.remove("hidden"), this._popover.style.visibility = "hidden");
2142
+ let r = n.getBoundingClientRect(), i = window.innerWidth, a = window.innerHeight, o = e.VIEWPORT_EDGE_MARGIN, s = this._getDistancePx(), c = this.getDirection(), l = 0, u = 0, d = this.getTriggerAlign();
2143
+ switch (c) {
2132
2144
  case "down":
2133
- if (s = e.bottom + a, c = e.left + e.width / 2 - n.width / 2, s + n.height > i) {
2134
- let t = e.top - n.height - a;
2135
- t >= 0 ? (o = "up", s = t) : (s = Math.max(0, i - n.height - a), s + n.height > i && (s = 0));
2145
+ if (l = t.bottom + s, u = d === "start" ? t.left : d === "end" ? t.right - r.width : t.left + t.width / 2 - r.width / 2, l + r.height > a - o) {
2146
+ let e = t.top - r.height - s;
2147
+ e >= o ? (c = "up", l = e) : (l = Math.max(o, a - r.height - s - o), l + r.height > a - o && (l = o));
2136
2148
  }
2137
- c < 0 && (c = a), c + n.width > r && (c = Math.max(a, r - n.width - a), c + n.width > r && (c = r - n.width));
2149
+ u < 0 && (u = s), u + r.width > i && (u = Math.max(s, i - r.width - s), u + r.width > i && (u = i - r.width));
2138
2150
  break;
2139
2151
  case "up":
2140
- if (s = e.top - n.height - a, c = e.left + e.width / 2 - n.width / 2, s < 0) {
2141
- let t = e.bottom + a;
2142
- t + n.height <= i ? (o = "down", s = t) : (s = Math.min(i - n.height - a, i - n.height), s < 0 && (s = i - n.height));
2152
+ if (l = t.top - r.height - s, u = d === "start" ? t.left : d === "end" ? t.right - r.width : t.left + t.width / 2 - r.width / 2, l < o) {
2153
+ let e = t.bottom + s;
2154
+ e + r.height <= a - o ? (c = "down", l = e) : (l = Math.min(a - r.height - s - o, a - r.height - o), l < o && (l = Math.max(o, a - r.height - o)));
2143
2155
  }
2144
- c < 0 && (c = a), c + n.width > r && (c = Math.max(a, r - n.width - a), c + n.width > r && (c = r - n.width));
2156
+ u < 0 && (u = s), u + r.width > i && (u = Math.max(s, i - r.width - s), u + r.width > i && (u = i - r.width));
2145
2157
  break;
2146
2158
  case "right":
2147
- if (s = e.top + e.height / 2 - n.height / 2, c = e.right + a, c + n.width > r) {
2148
- let t = e.left - n.width - a;
2149
- t >= 0 ? (o = "left", c = t) : (c = Math.max(0, r - n.width - a), c + n.width > r && (c = r - n.width));
2159
+ if (l = d === "start" ? t.top : d === "end" ? t.bottom - r.height : t.top + t.height / 2 - r.height / 2, u = t.right + s, u + r.width > i) {
2160
+ let e = t.left - r.width - s;
2161
+ e >= 0 ? (c = "left", u = e) : (u = Math.max(0, i - r.width - s), u + r.width > i && (u = i - r.width));
2150
2162
  }
2151
- s < 0 && (s = a), s + n.height > i && (s = Math.max(a, i - n.height - a), s + n.height > i && (s = i - n.height));
2163
+ l < o && (l = o), l + r.height > a - o && (l = Math.max(o, a - r.height - s - o), l + r.height > a - o && (l = o));
2152
2164
  break;
2153
2165
  case "left":
2154
- if (s = e.top + e.height / 2 - n.height / 2, c = e.left - n.width - a, c < 0) {
2155
- let t = e.right + a;
2156
- t + n.width <= r ? (o = "right", c = t) : (c = Math.min(r - n.width - a, r - n.width), c < 0 && (c = 0));
2166
+ if (l = d === "start" ? t.top : d === "end" ? t.bottom - r.height : t.top + t.height / 2 - r.height / 2, u = t.left - r.width - s, u < 0) {
2167
+ let e = t.right + s;
2168
+ e + r.width <= i ? (c = "right", u = e) : (u = Math.min(i - r.width - s, i - r.width), u < 0 && (u = 0));
2157
2169
  }
2158
- s < 0 && (s = a), s + n.height > i && (s = Math.max(a, i - n.height - a), s + n.height > i && (s = i - n.height));
2170
+ l < o && (l = o), l + r.height > a - o && (l = Math.max(o, a - r.height - s - o), l + r.height > a - o && (l = o));
2159
2171
  break;
2160
2172
  }
2161
2173
  return {
2162
- top: s,
2163
- left: c,
2164
- direction: o
2174
+ top: l,
2175
+ left: u,
2176
+ direction: c
2165
2177
  };
2166
2178
  }
2179
+ _applyViewportHeightConstraint(t, n) {
2180
+ let r = window.innerHeight, i = e.VIEWPORT_EDGE_MARGIN, a = n;
2181
+ a < i && (a = i);
2182
+ let o = r - 2 * i, s = r - i - a, c = Math.max(48, Math.min(o, s));
2183
+ return t.style.maxHeight = `${Math.floor(c)}px`, t.style.overflowY = "auto", t.style.overflowX = "hidden", t.style.overscrollBehavior = "contain", a;
2184
+ }
2167
2185
  render() {
2168
- let e = this.getId(), t = this.isOpen(), n = this.getPadding();
2169
- if (e && (this.id = e), t) {
2186
+ let t = this.getId(), n = this.isOpen(), r = this.getPadding();
2187
+ if (t && (this.id = t), n) {
2170
2188
  if (this.classList.remove("hidden"), this.style.pointerEvents = "auto", this._triggerElement && this._triggerElement.tagName === "MINT-BUTTON" && requestAnimationFrame(() => {
2171
2189
  this._triggerElement.setAttribute("active", "true");
2172
2190
  let e = this._triggerElement;
@@ -2209,10 +2227,10 @@ var _ = class extends HTMLElement {
2209
2227
  this._popover.className = `fixed ${e} pointer-events-auto`, this.appendChild(this._popover);
2210
2228
  }
2211
2229
  this.isHoverEnabled() && this._attachHoverListeners();
2212
- let r = this._popover.querySelector(".popover-content");
2213
- if (!r) r = document.createElement("div"), r.className = `popover-content bg-white dark:bg-mint-elevated border border-gray-200 dark:border-mint-divider rounded-lg shadow-xl ${n} transform`, this._popover.appendChild(r);
2230
+ let i = this._popover.querySelector(".popover-content");
2231
+ if (!i) i = document.createElement("div"), i.className = `popover-content min-h-0 bg-white dark:bg-mint-elevated border border-gray-200 dark:border-mint-divider rounded-lg shadow-xl ${r} transform`, this._popover.appendChild(i);
2214
2232
  else {
2215
- let e = r.className.split(/\s+/).filter(Boolean), t = [
2233
+ let e = i.className.split(/\s+/).filter(Boolean), t = [
2216
2234
  "p-0",
2217
2235
  "p-0.5",
2218
2236
  "p-1",
@@ -2230,23 +2248,30 @@ var _ = class extends HTMLElement {
2230
2248
  "p-16",
2231
2249
  "p-20",
2232
2250
  "p-24"
2233
- ], i = e.filter((e) => !t.includes(e)), a = [
2251
+ ], n = e.filter((e) => !t.includes(e)), a = [
2234
2252
  "border",
2235
2253
  "border-gray-200",
2236
2254
  "dark:border-mint-divider"
2237
- ], o = [...i];
2255
+ ], o = [...n];
2238
2256
  for (let e of a) o.includes(e) || o.push(e);
2239
- r.className = [...o, n].join(" ");
2257
+ o.includes("min-h-0") || o.push("min-h-0"), i.className = [...o, r].join(" ");
2240
2258
  }
2241
- Array.from(this.children).forEach((e) => {
2242
- e !== this._overlay && e !== this._popover && e.parentElement === this && r.appendChild(e);
2243
- }), t ? (this._triggerElement || this._setupTrigger(), this._setupPositionListeners(), this.offsetHeight, this._triggerElement ? this._updatePosition(r) : (this._popover.style.top = "50%", this._popover.style.left = "50%", this._popover.style.transform = "translate(-50%, -50%)", this._popover.style.visibility = "visible", this._popover.style.display = "block", r.style.transform = "scale(0.97) translateY(10px)", r.style.opacity = "0", r.style.transition = "opacity 200ms ease-out, transform 200ms ease-out", requestAnimationFrame(() => {
2244
- requestAnimationFrame(() => {
2245
- r.style.transform = "scale(1) translateY(0)", r.style.opacity = "1";
2259
+ if (Array.from(this.children).forEach((e) => {
2260
+ e !== this._overlay && e !== this._popover && e.parentElement === this && i.appendChild(e);
2261
+ }), n) if (this._triggerElement || this._setupTrigger(), this._setupPositionListeners(), this.offsetHeight, this._triggerElement) this._updatePosition(i);
2262
+ else {
2263
+ this._popover.style.top = "50%", this._popover.style.left = "50%", this._popover.style.transform = "translate(-50%, -50%)", this._popover.style.visibility = "visible", this._popover.style.display = "block";
2264
+ let t = e.VIEWPORT_EDGE_MARGIN, n = Math.max(48, window.innerHeight - 2 * t);
2265
+ i.style.maxHeight = `${Math.floor(n)}px`, i.style.overflowY = "auto", i.style.overflowX = "hidden", i.style.overscrollBehavior = "contain", i.style.transform = "scale(0.97) translateY(10px)", i.style.opacity = "0", i.style.transition = "opacity 200ms ease-out, transform 200ms ease-out", requestAnimationFrame(() => {
2266
+ requestAnimationFrame(() => {
2267
+ i.style.transform = "scale(1) translateY(0)", i.style.opacity = "1";
2268
+ });
2246
2269
  });
2247
- }))) : !t && r && (this._removePositionListeners(), r.style.opacity !== "0" && r.style.opacity !== "" && (r.style.transition = "opacity 200ms ease-in, transform 200ms ease-in", r.style.transform = "scale(0.97) translateY(10px)", r.style.opacity = "0", setTimeout(() => {
2248
- r.style.transform = "", r.style.opacity = "", r.style.transition = "", this._popover.style.visibility = "", this._popover.style.display = "";
2249
- }, 200))), this._updateBackgroundColor();
2270
+ }
2271
+ else !n && i && (this._removePositionListeners(), i.style.opacity !== "0" && i.style.opacity !== "" && (i.style.transition = "opacity 200ms ease-in, transform 200ms ease-in", i.style.transform = "scale(0.97) translateY(10px)", i.style.opacity = "0", setTimeout(() => {
2272
+ i.style.transform = "", i.style.opacity = "", i.style.transition = "", this._popover.style.visibility = "", this._popover.style.display = "";
2273
+ }, 200)));
2274
+ this._updateBackgroundColor();
2250
2275
  }
2251
2276
  _updateBackgroundColor() {
2252
2277
  if (!this._popover) return;
@@ -2265,8 +2290,8 @@ var _ = class extends HTMLElement {
2265
2290
  if (!this._triggerElement || !this._popover) return;
2266
2291
  let t = this._popover.style.visibility !== "hidden";
2267
2292
  t || (this._popover.style.visibility = "hidden", this._popover.style.display = "block", this._popover.style.top = "0", this._popover.style.left = "0"), this._popover.offsetHeight;
2268
- let n = this._calculatePosition();
2269
- this._popover.style.top = `${n.top}px`, this._popover.style.left = `${n.left}px`, t || (this._popover.style.visibility = "visible", e && (!e.style.opacity || e.style.opacity === "") && (e.style.transform = "scale(0.97) translateY(10px)", e.style.opacity = "0", e.style.transition = "opacity 200ms ease-out, transform 200ms ease-out", requestAnimationFrame(() => {
2293
+ let n = this._calculatePosition(), r = this._applyViewportHeightConstraint(e, n.top);
2294
+ this._popover.style.top = `${r}px`, this._popover.style.left = `${n.left}px`, t || (this._popover.style.visibility = "visible", e && (!e.style.opacity || e.style.opacity === "") && (e.style.transform = "scale(0.97) translateY(10px)", e.style.opacity = "0", e.style.transition = "opacity 200ms ease-out, transform 200ms ease-out", requestAnimationFrame(() => {
2270
2295
  requestAnimationFrame(() => {
2271
2296
  e.style.transform = "scale(1) translateY(0)", e.style.opacity = "1";
2272
2297
  });
@@ -6013,8 +6038,12 @@ var E = class extends HTMLElement {
6013
6038
  let n = this._getFieldElements(e);
6014
6039
  if (n.length === 0) {
6015
6040
  setTimeout(() => {
6016
- let n = this._getFieldElements(e);
6017
- n.length > 0 && this._applyValueToField(n, e, t);
6041
+ let t = this._getFieldElements(e);
6042
+ if (t.length === 0) return;
6043
+ let n = this._formData ? this._getReactiveValue(this._formData) : null;
6044
+ if (!n || typeof n != "object" || Array.isArray(n)) return;
6045
+ let r = n[e];
6046
+ this._applyValueToField(t, e, r);
6018
6047
  }, 300);
6019
6048
  return;
6020
6049
  }
@@ -6573,12 +6602,14 @@ customElements.get("mint-chip") || customElements.define("mint-chip", O);
6573
6602
  //#region src/components/tags/Tags.ts
6574
6603
  var k = class extends HTMLElement {
6575
6604
  constructor(...e) {
6576
- super(...e), this._container = null, this._chipsWrap = null, this._input = null, this._tags = [], this._placeholder = "Add tag", this._dragIndex = null, this._dragChip = null, this._isPointerDragging = !1, this._pointerMoveHandler = null, this._pointerUpHandler = null;
6605
+ super(...e), this._container = null, this._chipsWrap = null, this._input = null, this._tags = [], this._predefinedTags = [], this._placeholder = "Add tag", this._predefinedPopoverOpenListenersAttached = !1, this._predefinedBlurCloseTimer = null, this._suppressNextPredefinedBlurClose = !1, this._dragIndex = null, this._dragChip = null, this._isPointerDragging = !1, this._pointerMoveHandler = null, this._pointerUpHandler = null, this._containerFocusRingListeners = !1;
6577
6606
  }
6578
6607
  static get observedAttributes() {
6579
6608
  return [
6580
6609
  "tags",
6581
6610
  "placeholder",
6611
+ "predefined-tags",
6612
+ "predefined-only",
6582
6613
  "sortable",
6583
6614
  "label",
6584
6615
  "info",
@@ -6611,9 +6642,7 @@ var k = class extends HTMLElement {
6611
6642
  e ? "border-red-300 dark:border-red-300" : "border-gray-200 dark:border-mint-divider",
6612
6643
  "bg-white",
6613
6644
  "dark:bg-mint-elevated",
6614
- "focus-within:ring-2",
6615
- "focus-within:ring-offset-1",
6616
- e ? "focus-within:ring-red-400 dark:focus-within:ring-red-500" : "focus-within:ring-gray-400 dark:focus-within:ring-gray-500"
6645
+ ...this._containerRingClasses(e)
6617
6646
  ];
6618
6647
  this._container.className = t.join(" ");
6619
6648
  }
@@ -6634,15 +6663,36 @@ var k = class extends HTMLElement {
6634
6663
  }
6635
6664
  _parseAttrs() {
6636
6665
  let e = this.getAttribute("tags");
6637
- if (!e) return;
6666
+ e && (this._tags = this._parseTagItems(e, "tags"));
6667
+ let t = this.getAttribute("placeholder");
6668
+ t !== null && (this._placeholder = t);
6669
+ let n = this.getAttribute("predefined-tags");
6670
+ this._predefinedTags = this._parseTagItems(n, "predefined-tags");
6671
+ }
6672
+ _parseTagItems(e, t) {
6673
+ if (!e) return [];
6638
6674
  try {
6639
6675
  let t = JSON.parse(e);
6640
- Array.isArray(t) && (this._tags = t);
6676
+ return Array.isArray(t) ? t.map((e) => {
6677
+ if (typeof e == "string") {
6678
+ let t = e.trim();
6679
+ return t ? {
6680
+ value: t,
6681
+ label: t,
6682
+ dismissable: !0
6683
+ } : null;
6684
+ }
6685
+ if (!e || typeof e != "object") return null;
6686
+ let t = e, n = String(t.value ?? "").trim();
6687
+ return n ? {
6688
+ value: n,
6689
+ label: String(t.label ?? n),
6690
+ dismissable: t.dismissable !== !1
6691
+ } : null;
6692
+ }).filter((e) => e !== null) : [];
6641
6693
  } catch (e) {
6642
- console.warn("mint-tags: failed to parse tags attribute", e);
6694
+ return console.warn(`mint-tags: failed to parse ${t} attribute`, e), [];
6643
6695
  }
6644
- let t = this.getAttribute("placeholder");
6645
- t !== null && (this._placeholder = t);
6646
6696
  }
6647
6697
  _syncAttr() {
6648
6698
  this.setAttribute("tags", JSON.stringify(this._tags));
@@ -6656,6 +6706,36 @@ var k = class extends HTMLElement {
6656
6706
  hasError() {
6657
6707
  return this.getAttribute("error") === "true";
6658
6708
  }
6709
+ _containerRingClasses(e) {
6710
+ return e ? [
6711
+ "focus-within:ring-2",
6712
+ "focus-within:ring-offset-1",
6713
+ "focus-within:ring-red-400",
6714
+ "dark:focus-within:ring-red-500",
6715
+ "data-[mint-tags-active=true]:ring-2",
6716
+ "data-[mint-tags-active=true]:ring-offset-1",
6717
+ "data-[mint-tags-active=true]:ring-red-400",
6718
+ "dark:data-[mint-tags-active=true]:ring-red-500"
6719
+ ] : [
6720
+ "focus-within:ring-2",
6721
+ "focus-within:ring-offset-1",
6722
+ "focus-within:ring-gray-400",
6723
+ "dark:focus-within:ring-gray-500",
6724
+ "data-[mint-tags-active=true]:ring-2",
6725
+ "data-[mint-tags-active=true]:ring-offset-1",
6726
+ "data-[mint-tags-active=true]:ring-gray-400",
6727
+ "dark:data-[mint-tags-active=true]:ring-gray-500"
6728
+ ];
6729
+ }
6730
+ _attachContainerFocusRingListeners() {
6731
+ !this._container || this._containerFocusRingListeners || (this._containerFocusRingListeners = !0, this._container.addEventListener("focusin", () => {
6732
+ this._container?.setAttribute("data-mint-tags-active", "true");
6733
+ }), this._container.addEventListener("focusout", () => {
6734
+ requestAnimationFrame(() => {
6735
+ this._container && (this._container.contains(document.activeElement) || this._container.removeAttribute("data-mint-tags-active"));
6736
+ });
6737
+ }));
6738
+ }
6659
6739
  getErrorMessage() {
6660
6740
  return this.getAttribute("error-message") || "";
6661
6741
  }
@@ -6671,6 +6751,9 @@ var k = class extends HTMLElement {
6671
6751
  isLoading() {
6672
6752
  return this.hasAttribute("loading");
6673
6753
  }
6754
+ isPredefinedOnly() {
6755
+ return this.getAttribute("predefined-only") === "true";
6756
+ }
6674
6757
  _render() {
6675
6758
  this.classList.add("box-border", "m-0", "p-0", "border-0", "align-baseline", "block", "w-full");
6676
6759
  let e = this.isLoading(), t = this.getLabel(), n = this.getInfo(), r = this.hasError(), i = this.getId() || `mint-tags-${Math.random().toString(36).substr(2, 9)}`;
@@ -6691,11 +6774,9 @@ var k = class extends HTMLElement {
6691
6774
  r ? "border-red-300 dark:border-red-300" : "border-gray-200 dark:border-mint-divider",
6692
6775
  "bg-white",
6693
6776
  "dark:bg-mint-elevated",
6694
- "focus-within:ring-2",
6695
- "focus-within:ring-offset-1",
6696
- r ? "focus-within:ring-red-400 dark:focus-within:ring-red-500" : "focus-within:ring-gray-400 dark:focus-within:ring-gray-500"
6777
+ ...this._containerRingClasses(r)
6697
6778
  ];
6698
- this._container.className = e.join(" "), this._chipsWrap = document.createElement("div"), this._chipsWrap.className = "flex flex-wrap items-center gap-2", this._chipsWrap.addEventListener("dragover", (e) => {
6779
+ this._container.className = e.join(" "), this._container.addEventListener("pointerdown", (e) => this._onContainerPointerDown(e)), this._attachContainerFocusRingListeners(), this._chipsWrap = document.createElement("div"), this._chipsWrap.className = "flex flex-wrap items-center gap-2", this._chipsWrap.addEventListener("dragover", (e) => {
6699
6780
  this.hasAttribute("sortable") && e.preventDefault();
6700
6781
  }), this._chipsWrap.addEventListener("drop", (e) => {
6701
6782
  this.hasAttribute("sortable") && e.preventDefault();
@@ -6715,7 +6796,7 @@ var k = class extends HTMLElement {
6715
6796
  e.key === "Enter" && (e.preventDefault(), this._addFromInput());
6716
6797
  }), this._container.appendChild(this._chipsWrap), this.appendChild(this._container);
6717
6798
  }
6718
- if (this._container) {
6799
+ if (this._input && (this.isPredefinedOnly() && this._predefinedTags.length > 0 ? this._input.setAttribute("readonly", "true") : this._input.removeAttribute("readonly")), this._container) {
6719
6800
  let e = [
6720
6801
  "flex",
6721
6802
  "flex-wrap",
@@ -6730,9 +6811,7 @@ var k = class extends HTMLElement {
6730
6811
  r ? "border-red-300 dark:border-red-300" : "border-gray-200 dark:border-mint-divider",
6731
6812
  "bg-white",
6732
6813
  "dark:bg-mint-elevated",
6733
- "focus-within:ring-2",
6734
- "focus-within:ring-offset-1",
6735
- r ? "focus-within:ring-red-400 dark:focus-within:ring-red-500" : "focus-within:ring-gray-400 dark:focus-within:ring-gray-500"
6814
+ ...this._containerRingClasses(r)
6736
6815
  ];
6737
6816
  this._container.className = e.join(" ");
6738
6817
  }
@@ -6745,7 +6824,56 @@ var k = class extends HTMLElement {
6745
6824
  let o = this.querySelector(".mint-tags-info");
6746
6825
  n ? (o || (o = document.createElement("span"), o.className = "mint-tags-info text-xs text-gray-500 dark:text-gray-400 select-none mt-1 block", this._container && this._container.parentElement === this ? this.insertBefore(o, this._container.nextSibling) : this.appendChild(o)), o.textContent = n) : o && o.remove();
6747
6826
  let s = this.getName();
6748
- s ? (this.setAttribute("name", s), this._input && (this._input.name = s, this._input.id = i)) : (this.removeAttribute("name"), this._input && (this._input.removeAttribute("name"), this._input.id = i)), this._wireInputBackspace(), this._renderChips(), this._renderErrorState(), this._renderSkeleton(e);
6827
+ s ? (this.setAttribute("name", s), this._input && (this._input.name = s, this._input.id = i)) : (this.removeAttribute("name"), this._input && (this._input.removeAttribute("name"), this._input.id = i)), this._wireInputBackspace(), this._renderChips(), this._renderPredefinedPopover(), this._renderErrorState(), this._renderSkeleton(e);
6828
+ }
6829
+ _getAvailablePredefinedTags() {
6830
+ let e = new Set(this._tags.map((e) => e.value.toLowerCase()));
6831
+ return this._predefinedTags.filter((t) => !e.has(t.value.toLowerCase()));
6832
+ }
6833
+ _renderPredefinedPopover() {
6834
+ if (!this._container || !this._chipsWrap || (this.querySelectorAll("[data-mint-tags-predefined=\"true\"]").forEach((e) => e.remove()), !this._predefinedTags.length) || !this._input || !this._input.id) return;
6835
+ let e = `${this.getAttribute("id") || this._input.id}-tags-field`;
6836
+ this._container.id = e;
6837
+ let t = document.createElement("mint-popover");
6838
+ t.setAttribute("trigger-id", e), t.setAttribute("trigger-toggle", "false"), t.setAttribute("trigger-align", "start"), t.setAttribute("direction", "down"), t.setAttribute("padding", "0"), t.setAttribute("distance", "6px"), t.dataset.mintTagsPredefined = "true";
6839
+ let n = document.createElement("div"), r = this._container.offsetWidth;
6840
+ n.className = "box-border flex w-full min-w-0 flex-col gap-0.5 bg-white p-1 dark:bg-mint-elevated", r > 0 ? n.style.minWidth = `${Math.max(r, 200)}px` : n.style.minWidth = "12rem", n.addEventListener("mousedown", (e) => {
6841
+ e.preventDefault();
6842
+ });
6843
+ let i = this._getAvailablePredefinedTags();
6844
+ if (i.length) i.forEach((e) => {
6845
+ let r = document.createElement("mint-button");
6846
+ r.setAttribute("type", "button"), r.setAttribute("variant", "ghost"), r.setAttribute("full-width", "true"), r.setAttribute("align", "left"), r.className = "w-full justify-start", r.textContent = e.label || e.value, r.addEventListener("mousedown", (e) => {
6847
+ e.preventDefault();
6848
+ }, !0), r.addEventListener("click", () => {
6849
+ this._addTag(e), t.removeAttribute("open"), requestAnimationFrame(() => {
6850
+ this._input?.focus({ preventScroll: !0 }), this._container?.setAttribute("data-mint-tags-active", "true");
6851
+ });
6852
+ }), n.appendChild(r);
6853
+ });
6854
+ else {
6855
+ let e = document.createElement("div");
6856
+ e.className = "px-2 py-1 text-xs text-gray-500 dark:text-gray-400", e.textContent = "No tags available", n.appendChild(e);
6857
+ }
6858
+ t.appendChild(n), this._container.appendChild(t), this._attachPredefinedPopoverOpenOnInputFocus();
6859
+ }
6860
+ _getPredefinedPopoverEl() {
6861
+ return this.querySelector("mint-popover[data-mint-tags-predefined=\"true\"]");
6862
+ }
6863
+ _attachPredefinedPopoverOpenOnInputFocus() {
6864
+ !this._input || !this._predefinedTags.length || this._predefinedPopoverOpenListenersAttached || (this._predefinedPopoverOpenListenersAttached = !0, this._input.addEventListener("focus", () => {
6865
+ if (this._predefinedBlurCloseTimer !== null && (window.clearTimeout(this._predefinedBlurCloseTimer), this._predefinedBlurCloseTimer = null), this.isLoading()) return;
6866
+ let e = this._getPredefinedPopoverEl();
6867
+ e && e.setAttribute("open", "true");
6868
+ }), this._input.addEventListener("blur", () => {
6869
+ this._predefinedBlurCloseTimer !== null && window.clearTimeout(this._predefinedBlurCloseTimer), this._predefinedBlurCloseTimer = window.setTimeout(() => {
6870
+ if (this._predefinedBlurCloseTimer = null, this._suppressNextPredefinedBlurClose) {
6871
+ this._suppressNextPredefinedBlurClose = !1;
6872
+ return;
6873
+ }
6874
+ this._getPredefinedPopoverEl()?.removeAttribute("open");
6875
+ }, 150);
6876
+ }));
6749
6877
  }
6750
6878
  _renderSkeleton(e) {
6751
6879
  let t = this._container;
@@ -6772,22 +6900,36 @@ var k = class extends HTMLElement {
6772
6900
  _addFromInput() {
6773
6901
  if (!this._input) return;
6774
6902
  let e = this._input.value.trim();
6775
- if (e) {
6776
- if (this._tags.some((t) => t.value.toLowerCase() === e.toLowerCase())) {
6903
+ if (!e) return;
6904
+ if (this._tags.some((t) => t.value.toLowerCase() === e.toLowerCase())) {
6905
+ this._input.value = "";
6906
+ return;
6907
+ }
6908
+ let t = this._predefinedTags.find((t) => t.value.toLowerCase() === e.toLowerCase());
6909
+ if (this.isPredefinedOnly()) {
6910
+ if (!t) {
6777
6911
  this._input.value = "";
6778
6912
  return;
6779
6913
  }
6780
- this._tags.push({
6781
- value: e,
6782
- label: e,
6783
- dismissable: !0
6784
- }), this._syncAttr(), this._renderChips(), this._emitChange(), this._input.value = "", setTimeout(() => {
6785
- this._input?.focus();
6786
- }, 10);
6787
- }
6914
+ this._addTag(t);
6915
+ } else this._addTag(t || {
6916
+ value: e,
6917
+ label: e,
6918
+ dismissable: !0
6919
+ });
6920
+ this._input.value = "", setTimeout(() => {
6921
+ this._input?.focus();
6922
+ }, 10);
6923
+ }
6924
+ _addTag(e) {
6925
+ this._tags.some((t) => t.value.toLowerCase() === e.value.toLowerCase()) || (this._tags.push({
6926
+ value: e.value,
6927
+ label: e.label || e.value,
6928
+ dismissable: e.dismissable !== !1
6929
+ }), this._syncAttr(), this._renderChips(), this._renderPredefinedPopover(), this._emitChange());
6788
6930
  }
6789
6931
  _removeTag(e) {
6790
- this._tags = this._tags.filter((t) => t.value !== e), this._syncAttr(), this._renderChips(), this._emitChange();
6932
+ this._tags = this._tags.filter((t) => t.value !== e), this._syncAttr(), this._renderChips(), this._renderPredefinedPopover(), this._emitChange();
6791
6933
  }
6792
6934
  _emitChange() {
6793
6935
  this.dispatchEvent(new CustomEvent("tags-change", {
@@ -6815,6 +6957,15 @@ var k = class extends HTMLElement {
6815
6957
  (e.key === "Backspace" || e.key === "Delete") && t.dismissable && (e.preventDefault(), this._removeTag(t.value), this._focusInput());
6816
6958
  });
6817
6959
  }
6960
+ _onContainerPointerDown(e) {
6961
+ if (this._input && e.button === 0 && !e.defaultPrevented && !e.composedPath().some((e) => e === this._input)) {
6962
+ this._predefinedBlurCloseTimer !== null && (window.clearTimeout(this._predefinedBlurCloseTimer), this._predefinedBlurCloseTimer = null), this._suppressNextPredefinedBlurClose = !0, e.preventDefault();
6963
+ try {
6964
+ this._input.focus({ preventScroll: !0 });
6965
+ } catch {}
6966
+ this._predefinedTags.length > 0 && this._getPredefinedPopoverEl()?.setAttribute("open", "true");
6967
+ }
6968
+ }
6818
6969
  _onDragStart(e, t) {
6819
6970
  this.hasAttribute("sortable") && (this._dragChip = t, this._dragIndex = Number(t.dataset.index), e.dataTransfer?.setData("text/plain", t.dataset.index || ""), e.dataTransfer && (e.dataTransfer.effectAllowed = "move", e.dataTransfer.dropEffect = "move"), t.classList.add("opacity-60"));
6820
6971
  }