monobill-mintui 0.6.708 → 0.6.709

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.
Files changed (69) hide show
  1. package/bin/component-dependencies.json +4 -3
  2. package/dist/components/chunks/{date-picker-Bqre6M4g.js → date-picker-D3l2uFzg.js} +23 -5
  3. package/dist/components/chunks/date-picker-DY0mlT4u.js +1 -0
  4. package/dist/components/chunks/{input-j6FCwb-x.js → input-BTRS6ggP.js} +89 -11
  5. package/dist/components/chunks/input-D9FDLgwb.js +1 -0
  6. package/dist/components/chunks/select-Bs4-xwX6.js +1 -0
  7. package/dist/components/chunks/select-ByoX89vD.js +615 -0
  8. package/dist/components/chunks/{time-picker-DY5emLWw.js → time-picker-BczVLEX_.js} +21 -6
  9. package/dist/components/chunks/time-picker-CEEByAUI.js +1 -0
  10. package/dist/components/date-picker/DatePicker.d.ts +6 -0
  11. package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
  12. package/dist/components/date-picker/browser.js +1 -1
  13. package/dist/components/date-picker/index.cjs +1 -1
  14. package/dist/components/date-picker/index.js +1 -1
  15. package/dist/components/datetime-picker/DateTimePicker.d.ts +4 -0
  16. package/dist/components/datetime-picker/DateTimePicker.d.ts.map +1 -1
  17. package/dist/components/datetime-picker/browser.js +21 -6
  18. package/dist/components/datetime-picker/index.cjs +1 -1
  19. package/dist/components/datetime-picker/index.js +21 -6
  20. package/dist/components/input/Input.d.ts +3 -0
  21. package/dist/components/input/Input.d.ts.map +1 -1
  22. package/dist/components/input/browser.js +1 -1
  23. package/dist/components/input/index.cjs +1 -1
  24. package/dist/components/input/index.js +1 -1
  25. package/dist/components/off-canvas/OffCanvas.d.ts +2 -0
  26. package/dist/components/off-canvas/OffCanvas.d.ts.map +1 -1
  27. package/dist/components/off-canvas/browser.js +17 -12
  28. package/dist/components/off-canvas/index.cjs +1 -1
  29. package/dist/components/off-canvas/index.js +17 -12
  30. package/dist/components/resource-table/ResourceTable.d.ts +7 -0
  31. package/dist/components/resource-table/ResourceTable.d.ts.map +1 -1
  32. package/dist/components/resource-table/browser.js +36 -10
  33. package/dist/components/resource-table/index.cjs +2 -2
  34. package/dist/components/resource-table/index.js +36 -10
  35. package/dist/components/search/browser.js +1 -1
  36. package/dist/components/search/index.cjs +1 -1
  37. package/dist/components/search/index.js +1 -1
  38. package/dist/components/select/NativeSelect.d.ts +4 -0
  39. package/dist/components/select/NativeSelect.d.ts.map +1 -1
  40. package/dist/components/select/Select.d.ts +4 -0
  41. package/dist/components/select/Select.d.ts.map +1 -1
  42. package/dist/components/select/browser.js +2 -578
  43. package/dist/components/select/index.cjs +1 -1
  44. package/dist/components/select/index.js +2 -578
  45. package/dist/components/sortable/browser.js +1 -1
  46. package/dist/components/sortable/index.cjs +1 -1
  47. package/dist/components/sortable/index.js +1 -1
  48. package/dist/components/time-picker/TimePicker.d.ts +4 -0
  49. package/dist/components/time-picker/TimePicker.d.ts.map +1 -1
  50. package/dist/components/time-picker/browser.js +1 -1
  51. package/dist/components/time-picker/index.cjs +1 -1
  52. package/dist/components/time-picker/index.js +1 -1
  53. package/dist/components/tree/browser.js +1 -1
  54. package/dist/components/tree/index.cjs +1 -1
  55. package/dist/components/tree/index.js +1 -1
  56. package/dist/date-picker.css +1 -1
  57. package/dist/index.cjs +3 -3
  58. package/dist/index.css +5 -5
  59. package/dist/index.js +2465 -2273
  60. package/dist/input.css +1 -1
  61. package/dist/off-canvas.css +1 -1
  62. package/dist/resource-table.css +1 -1
  63. package/dist/select.css +1 -1
  64. package/package.json +1 -1
  65. package/dist/components/chunks/date-picker-CBucQNne.js +0 -1
  66. package/dist/components/chunks/input-Br2qLesW.js +0 -1
  67. package/dist/components/chunks/time-picker-CxdBZbER.js +0 -1
  68. /package/dist/components/chunks/{sortable-Dgk6LvmB.js → sortable-BSw58wy_.js} +0 -0
  69. /package/dist/components/chunks/{sortable-BAL3k9Se.js → sortable-D3et5wXB.js} +0 -0
@@ -0,0 +1,615 @@
1
+ import "./icon-hyFz3uhh.js";
2
+ import { t as e } from "./register-element-BFYmIynH.js";
3
+ import "./icon-l34kRIZg.js";
4
+ import "./popover-C1qiTAvR.js";
5
+ //#region src/components/select/NativeSelect.ts
6
+ var t = "data-mint-native-select-part", n = class extends HTMLElement {
7
+ static get observedAttributes() {
8
+ return [
9
+ "name",
10
+ "value",
11
+ "disabled",
12
+ "id",
13
+ "required",
14
+ "label",
15
+ "info",
16
+ "error",
17
+ "error-message",
18
+ "multiple",
19
+ "loading",
20
+ "aria-label",
21
+ "aria-labelledby",
22
+ "aria-describedby"
23
+ ];
24
+ }
25
+ constructor() {
26
+ super(), this._select = null, this._wrapper = null, this._prependNodes = [], this._appendNodes = [], this._caretUpIcon = null, this._caretDownIcon = null, this._changeHandler = null, this._optionObserver = null, this._childrenObserver = null, this._hostOptionsObserverRaf = null, this._generatedControlId = `mint-native-select-${Math.random().toString(36).slice(2, 10)}`;
27
+ }
28
+ connectedCallback() {
29
+ this.classList.add("mint-native-select-host"), this.getLabel() || console.error("mint-native-select: The \"label\" attribute is required. Please provide a label for the select."), this.render(), this._childrenObserver && this._childrenObserver.disconnect(), this._childrenObserver = new MutationObserver((e) => {
30
+ if (e.some((e) => {
31
+ let t = e.target;
32
+ if (this._select && (t === this._select || this._select.contains(t))) return !1;
33
+ let n = Array.from(e.addedNodes).some((e) => e.nodeType === Node.ELEMENT_NODE && (e.tagName === "OPTION" || e.tagName === "OPTGROUP")) || Array.from(e.removedNodes).some((e) => e.nodeType === Node.ELEMENT_NODE && (e.tagName === "OPTION" || e.tagName === "OPTGROUP")), r = e.type === "attributes" && e.target.nodeType === Node.ELEMENT_NODE && (e.target.tagName === "OPTION" || e.target.tagName === "OPTGROUP");
34
+ return n || r;
35
+ })) {
36
+ if (this._hostOptionsObserverRaf !== null) return;
37
+ this._hostOptionsObserverRaf = requestAnimationFrame(() => {
38
+ this._hostOptionsObserverRaf = null, this.isConnected && this.render();
39
+ });
40
+ }
41
+ }), this._childrenObserver.observe(this, {
42
+ childList: !0,
43
+ subtree: !0,
44
+ attributes: !0,
45
+ attributeFilter: [
46
+ "value",
47
+ "selected",
48
+ "disabled"
49
+ ]
50
+ });
51
+ }
52
+ disconnectedCallback() {
53
+ this._select && this._changeHandler && (this._select.removeEventListener("change", this._changeHandler), this._changeHandler = null), this._optionObserver &&= (this._optionObserver.disconnect(), null), this._childrenObserver &&= (this._childrenObserver.disconnect(), null), this._hostOptionsObserverRaf !== null && (cancelAnimationFrame(this._hostOptionsObserverRaf), this._hostOptionsObserverRaf = null);
54
+ }
55
+ isLoading() {
56
+ let e = this.getAttribute("loading");
57
+ return e !== null && e !== "false";
58
+ }
59
+ attributeChangedCallback(e, t, n) {
60
+ if (t !== n) {
61
+ if (e === "error" || e === "error-message") {
62
+ this._renderErrorState(), this._select && (this._select.className = this.getSelectClasses(), this._select.setAttribute("aria-invalid", this.hasError() ? "true" : "false"), this._syncSelectAccessibility());
63
+ return;
64
+ }
65
+ if (e === "loading") {
66
+ this.render();
67
+ return;
68
+ }
69
+ if (e === "value") {
70
+ if (this._select) if (this.isMultiple()) {
71
+ let e = [];
72
+ try {
73
+ let t = n ? JSON.parse(n) : [];
74
+ e = Array.isArray(t) ? t.map((e) => String(e)) : [];
75
+ } catch {
76
+ e = n ? [String(n)] : [];
77
+ }
78
+ Array.from(this._select.options).forEach((t) => {
79
+ t.selected = e.includes(t.value);
80
+ });
81
+ } else this._select.value = n || "";
82
+ return;
83
+ }
84
+ this.render();
85
+ }
86
+ }
87
+ getName() {
88
+ return this.getAttribute("name") || "";
89
+ }
90
+ getValue() {
91
+ if (this.isMultiple() && this._select) {
92
+ let e = Array.from(this._select.selectedOptions).map((e) => e.value);
93
+ return JSON.stringify(e);
94
+ }
95
+ return this.hasAttribute("value") ? this.getAttribute("value") || "" : this._select ? this._select.value : "";
96
+ }
97
+ setValue(e) {
98
+ if (this.isMultiple()) {
99
+ let t = Array.isArray(e) ? e.map((e) => String(e)) : e == null || e === "" ? [] : [String(e)];
100
+ this.setAttribute("value", JSON.stringify(t)), this._select && Array.from(this._select.options).forEach((e) => {
101
+ e.selected = t.includes(e.value);
102
+ });
103
+ return;
104
+ }
105
+ let t = e == null ? "" : String(e);
106
+ this.setAttribute("value", t), this._select && (this._select.value = t);
107
+ }
108
+ get value() {
109
+ try {
110
+ return this.getValue() || "";
111
+ } catch {
112
+ return "";
113
+ }
114
+ }
115
+ set value(e) {
116
+ try {
117
+ if (this.isMultiple()) {
118
+ this.setValue(e);
119
+ return;
120
+ }
121
+ let t = e || "";
122
+ (this.getAttribute("value") || "") !== t && this.setAttribute("value", t), this._select && requestAnimationFrame(() => {
123
+ this._select && (t === "" || Array.from(this._select.options).some((e) => e.value === t)) && this._select.value !== t && (this._select.value = t);
124
+ });
125
+ } catch {}
126
+ }
127
+ isDisabled() {
128
+ let e = this.getAttribute("disabled");
129
+ return e !== null && e !== "false";
130
+ }
131
+ isMultiple() {
132
+ let e = this.getAttribute("multiple");
133
+ return e !== null && e !== "false";
134
+ }
135
+ isRequired() {
136
+ let e = this.getAttribute("required");
137
+ return e !== null && e !== "false";
138
+ }
139
+ hasError() {
140
+ return this.getAttribute("error") === "true";
141
+ }
142
+ getErrorMessage() {
143
+ return this.getAttribute("error-message") || "";
144
+ }
145
+ getId() {
146
+ return this.getAttribute("id") || "";
147
+ }
148
+ getLabel() {
149
+ return this.getAttribute("label") || "";
150
+ }
151
+ getInfo() {
152
+ return this.getAttribute("info") || "";
153
+ }
154
+ getSelectClasses() {
155
+ return [
156
+ "mint-native-select-control",
157
+ this.isMultiple() ? "is-multiple" : "",
158
+ this.hasError() ? "has-error" : ""
159
+ ].filter(Boolean).join(" ");
160
+ }
161
+ render() {
162
+ this._hostOptionsObserverRaf !== null && (cancelAnimationFrame(this._hostOptionsObserverRaf), this._hostOptionsObserverRaf = null);
163
+ let e = this.isLoading(), n = this.isMultiple(), r = this.getValue();
164
+ this._collectAdornments();
165
+ let i = [];
166
+ this._select && Array.from(this._select.children).forEach((e) => {
167
+ (e.tagName === "OPTION" || e.tagName === "OPTGROUP") && i.push(e.cloneNode(!0));
168
+ }), Array.from(this.children).forEach((e) => {
169
+ e instanceof HTMLElement && e.hasAttribute(t) && e.remove();
170
+ }), this._wrapper = null, this._select = null;
171
+ let a = Array.from(this.children).filter((e) => e.tagName === "OPTION" || e.tagName === "OPTGROUP").map((e) => e.cloneNode(!0)), o = this.getLabel(), s = this.getInfo(), c = this.getId() || this._generatedControlId, l = this.getName(), u = this.isDisabled(), d = this.hasError();
172
+ if (o) {
173
+ let e = document.createElement("label");
174
+ e.setAttribute(t, "label"), e.className = "mint-native-select-label", c && e.setAttribute("for", c);
175
+ let n = document.createTextNode(o);
176
+ e.appendChild(n), this.appendChild(e);
177
+ }
178
+ this._wrapper = document.createElement("div"), this._wrapper.setAttribute(t, "wrapper"), this._wrapper.className = "mint-native-select-control-wrap", this.appendChild(this._wrapper);
179
+ let f = this._makeAdornment("prepend", this._prependNodes);
180
+ f && this._wrapper.appendChild(f), this._select = document.createElement("select"), this._select.className = this.getSelectClasses(), c && (this._select.id = c), l && (this._select.name = l), u && (this._select.disabled = !0), this._select.required = this.isRequired(), n && (this._select.multiple = !0), this._select.setAttribute("aria-invalid", d ? "true" : "false");
181
+ let p = this.getAttribute("aria-label")?.trim(), m = this.getAttribute("aria-labelledby")?.trim();
182
+ m ? this._select.setAttribute("aria-labelledby", m) : o ? this._select.removeAttribute("aria-label") : this._select.setAttribute("aria-label", p || "Select an option");
183
+ let h = a.length > 0 ? a : i;
184
+ if (h.length > 0 && h.forEach((e) => {
185
+ this._select.appendChild(e);
186
+ }), this._select.options.length === 0) {
187
+ let e = document.createElement("option");
188
+ e.value = "", e.textContent = "Select an option", e.disabled = !0, e.selected = !0, this._select.appendChild(e);
189
+ }
190
+ if (n) {
191
+ let e = [];
192
+ try {
193
+ let t = r ? JSON.parse(r) : [];
194
+ e = Array.isArray(t) ? t.map((e) => String(e)) : [];
195
+ } catch {
196
+ e = r ? [String(r)] : [];
197
+ }
198
+ Array.from(this._select.options).forEach((t) => {
199
+ t.selected = e.includes(t.value);
200
+ });
201
+ } else this._select.value = r || "";
202
+ this._changeHandler && this._select && this._select.removeEventListener("change", this._changeHandler), this._changeHandler = (e) => {
203
+ let t = e.target, r = n ? Array.from(t.selectedOptions).map((e) => e.value) : t.value, i = n ? JSON.stringify(r) : String(r || "");
204
+ (this.getAttribute("value") || "") !== i && (i ? this.setAttribute("value", i) : this.removeAttribute("value"));
205
+ let a = new Event("input", {
206
+ bubbles: !0,
207
+ cancelable: !0,
208
+ composed: !0
209
+ });
210
+ this.dispatchEvent(a), this.dispatchEvent(new CustomEvent("input", {
211
+ detail: { value: r },
212
+ bubbles: !0,
213
+ cancelable: !0,
214
+ composed: !0
215
+ })), this.dispatchEvent(new CustomEvent("change", {
216
+ detail: { value: r },
217
+ bubbles: !0,
218
+ cancelable: !0,
219
+ composed: !0
220
+ }));
221
+ }, this._select.addEventListener("change", this._changeHandler), this._optionObserver && this._optionObserver.disconnect(), this._optionObserver = new MutationObserver(() => {
222
+ let e = this.getAttribute("value") || this.value || "";
223
+ this._select && e && requestAnimationFrame(() => {
224
+ if (this._select) if (n) {
225
+ let t = [];
226
+ try {
227
+ let n = JSON.parse(e);
228
+ t = Array.isArray(n) ? n.map((e) => String(e)) : [];
229
+ } catch {
230
+ t = [String(e)];
231
+ }
232
+ Array.from(this._select.options).forEach((e) => {
233
+ e.selected = t.includes(e.value);
234
+ });
235
+ } else Array.from(this._select.options).some((t) => t.value === e) && this._select.value !== e && (this._select.value = e);
236
+ });
237
+ }), this._optionObserver.observe(this._select, {
238
+ childList: !0,
239
+ subtree: !0
240
+ });
241
+ let g = document.createElement("div");
242
+ if (g.className = "mint-native-select-control-main", g.appendChild(this._select), this._wrapper.appendChild(g), n) this._caretUpIcon = null, this._caretDownIcon = null;
243
+ else {
244
+ let e = document.createElement("div");
245
+ e.className = "mint-native-select-caret", this._caretUpIcon = document.createElement("mint-icon"), this._caretUpIcon.setAttribute("name", "caret-up"), this._caretUpIcon.className = "mint-native-select-caret-up", this._caretUpIcon.setAttribute("aria-hidden", "true"), e.appendChild(this._caretUpIcon), this._caretDownIcon = document.createElement("mint-icon"), this._caretDownIcon.setAttribute("name", "caret-down"), this._caretDownIcon.className = "mint-native-select-caret-down", this._caretDownIcon.setAttribute("aria-hidden", "true"), e.appendChild(this._caretDownIcon), g.appendChild(e);
246
+ }
247
+ let _ = this._makeAdornment("append", this._appendNodes);
248
+ if (_ && this._wrapper.appendChild(_), s) {
249
+ let e = document.createElement("div");
250
+ e.setAttribute(t, "info"), e.className = "mint-native-select-info", e.textContent = s, this.appendChild(e);
251
+ }
252
+ this._renderErrorState(), this._syncSelectAccessibility(), this._renderSkeleton(e);
253
+ }
254
+ _collectAdornments() {
255
+ let e = [
256
+ ...this._prependNodes,
257
+ ...this._appendNodes,
258
+ ...Array.from(this.querySelectorAll(":scope > [slot=\"prepend\"], :scope > [slot=\"append\"]"))
259
+ ];
260
+ this._prependNodes = e.filter((e) => e.getAttribute("slot") === "prepend"), this._appendNodes = e.filter((e) => e.getAttribute("slot") === "append"), this._prependNodes.forEach((e) => this.appendChild(e)), this._appendNodes.forEach((e) => this.appendChild(e));
261
+ }
262
+ _makeAdornment(e, t) {
263
+ if (!t.length) return null;
264
+ let n = document.createElement("span");
265
+ return n.className = `mint-native-select-adornment mint-native-select-${e}-slot`, t.forEach((e) => n.appendChild(e)), n;
266
+ }
267
+ _renderSkeleton(e) {
268
+ let t = this.querySelector(".mint-native-select-skeleton-container"), n = this._wrapper;
269
+ if (e) {
270
+ t || (t = document.createElement("div"), t.className = "mint-native-select-skeleton-container", t.setAttribute("aria-hidden", "true"), n ? n.appendChild(t) : this.appendChild(t));
271
+ let e = t.querySelector(".mint-native-select-skeleton");
272
+ e || (e = document.createElement("div"), t.appendChild(e));
273
+ let r = this.isMultiple();
274
+ e.classList.toggle("is-multiple", r), e.style.height = r ? "5rem" : "2rem", t.style.display = "block", this._select && (this._select.style.opacity = "0", this._select.style.pointerEvents = "none", this._select.setAttribute("aria-busy", "true"));
275
+ } else t && (t.style.display = "none"), this._select && (this._select.style.opacity = "1", this._select.style.pointerEvents = "auto", this._select.removeAttribute("aria-busy"));
276
+ }
277
+ _renderErrorState() {
278
+ let e = this.hasError(), n = this.getErrorMessage(), r = this.querySelector(".mint-native-select-error");
279
+ e && n ? (r ? r.hasAttribute(t) || r.setAttribute(t, "error") : (r = document.createElement("div"), r.setAttribute(t, "error"), r.className = "mint-native-select-error", this.appendChild(r)), r.textContent = n) : r && r.remove();
280
+ }
281
+ _syncSelectAccessibility() {
282
+ if (!this._select) return;
283
+ let e = this._select.id || this._generatedControlId, n = (this.getAttribute("aria-describedby") || "").split(/\s+/).filter(Boolean), r = this.querySelector(`[${t}="info"]`), i = this.querySelector(".mint-native-select-error");
284
+ r && (r.id = `${e}-info`, n.push(r.id)), i && (i.id = `${e}-error`, n.push(i.id)), n.length ? this._select.setAttribute("aria-describedby", Array.from(new Set(n)).join(" ")) : this._select.removeAttribute("aria-describedby");
285
+ }
286
+ };
287
+ customElements.get("mint-native-select") || e("mint-native-select", n);
288
+ //#endregion
289
+ //#region src/components/select/Select.ts
290
+ var r = "data-mint-select-part", i = class extends HTMLElement {
291
+ constructor(...e) {
292
+ super(...e), this._native = null, this._trigger = null, this._popover = null, this._list = null, this._prependNodes = [], this._appendNodes = [], this._observer = null, this._syncing = !1, this._typeahead = "", this._typeaheadTimer = null, this._pointerSelectedOption = null, this._id = `mint-select-${Math.random().toString(36).slice(2, 10)}`;
293
+ }
294
+ static get observedAttributes() {
295
+ return [
296
+ "name",
297
+ "value",
298
+ "values",
299
+ "multiple",
300
+ "disabled",
301
+ "id",
302
+ "required",
303
+ "label",
304
+ "info",
305
+ "error",
306
+ "error-message",
307
+ "loading",
308
+ "placeholder",
309
+ "aria-label",
310
+ "aria-labelledby",
311
+ "aria-describedby",
312
+ "form"
313
+ ];
314
+ }
315
+ connectedCallback() {
316
+ this.classList.add("mint-select-host"), this.render(), this._observer?.disconnect(), this._observer = new MutationObserver((e) => {
317
+ this._syncing || e.some((e) => {
318
+ let t = e.target instanceof Element ? e.target : e.target.parentElement;
319
+ return t === this || t?.closest(`[${r}]`) ? !1 : e.type === "attributes" ? [
320
+ "value",
321
+ "label",
322
+ "disabled",
323
+ "selected"
324
+ ].includes(e.attributeName) : t instanceof HTMLOptionElement || t instanceof HTMLOptGroupElement || [...e.addedNodes, ...e.removedNodes].some((e) => e instanceof HTMLOptionElement || e instanceof HTMLOptGroupElement);
325
+ }) && this.render();
326
+ }), this._observer.observe(this, {
327
+ childList: !0,
328
+ subtree: !0,
329
+ attributes: !0,
330
+ attributeFilter: [
331
+ "value",
332
+ "label",
333
+ "disabled",
334
+ "selected"
335
+ ]
336
+ });
337
+ }
338
+ disconnectedCallback() {
339
+ this._observer?.disconnect(), this._observer = null, this._typeaheadTimer !== null && window.clearTimeout(this._typeaheadTimer);
340
+ }
341
+ attributeChangedCallback(e, t, n) {
342
+ if (!(t === n || !this.isConnected)) {
343
+ if (e === "values" && this._native && this.isMultiple()) {
344
+ this._applyValues(this.parseValues(n)), this.updateDisplay();
345
+ return;
346
+ }
347
+ if (e === "multiple" && this._native) {
348
+ this.render();
349
+ return;
350
+ }
351
+ if (e === "value" && this._native) {
352
+ this.isMultiple() ? this._applyValues(n ? [n] : []) : this._native.value = n || "", this.updateDisplay();
353
+ return;
354
+ }
355
+ this.render();
356
+ }
357
+ }
358
+ get value() {
359
+ return this.isMultiple() ? this.values : this._native?.value || this.getAttribute("value") || "";
360
+ }
361
+ set value(e) {
362
+ this.setValue(e);
363
+ }
364
+ get values() {
365
+ return this._native && this.isMultiple() ? Array.from(this._native.selectedOptions, (e) => e.value) : this.parseValues(this.getAttribute("values"));
366
+ }
367
+ set values(e) {
368
+ this.setValue(e);
369
+ }
370
+ getValue() {
371
+ return this.value;
372
+ }
373
+ setValue(e) {
374
+ if (this.isMultiple()) {
375
+ let t = Array.isArray(e) ? e.map(String) : e == null || e === "" ? [] : [String(e)];
376
+ this.setAttribute("values", JSON.stringify(t)), this._applyValues(t);
377
+ } else {
378
+ let t = e == null ? "" : String(e);
379
+ this.setAttribute("value", t), this._native && (this._native.value = t);
380
+ }
381
+ this.updateDisplay();
382
+ }
383
+ isDisabled() {
384
+ return this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false";
385
+ }
386
+ isLoading() {
387
+ let e = this.getAttribute("loading");
388
+ return e !== null && e !== "false";
389
+ }
390
+ isRequired() {
391
+ return this.hasAttribute("required") && this.getAttribute("required") !== "false";
392
+ }
393
+ isMultiple() {
394
+ return this.hasAttribute("multiple") && this.getAttribute("multiple") !== "false";
395
+ }
396
+ hasError() {
397
+ return this.getAttribute("error") === "true";
398
+ }
399
+ parseValues(e) {
400
+ if (!e) return [];
401
+ try {
402
+ let t = JSON.parse(e);
403
+ if (Array.isArray(t)) {
404
+ if (t.length === 1 && typeof t[0] == "string" && t[0].trim().startsWith("[")) try {
405
+ let e = JSON.parse(t[0]);
406
+ if (Array.isArray(e)) return e.map(String);
407
+ } catch {}
408
+ return t.map(String);
409
+ }
410
+ } catch {}
411
+ return [e];
412
+ }
413
+ _applyValues(e) {
414
+ if (!this._native) return;
415
+ let t = new Set(e);
416
+ Array.from(this._native.options).forEach((e) => {
417
+ e.selected = t.has(e.value);
418
+ });
419
+ }
420
+ options() {
421
+ return Array.from(this.querySelectorAll(":scope > option, :scope > optgroup > option"));
422
+ }
423
+ selectedOption() {
424
+ return this._native?.selectedOptions[0] || this.options().find((e) => e.value === this.value);
425
+ }
426
+ render() {
427
+ let e = this._native?.value || this.getAttribute("value") || "", t = this._native?.multiple ? Array.from(this._native.selectedOptions, (e) => e.value) : [], n = t.length ? t : this.parseValues(this.getAttribute("values"));
428
+ this._syncing = !0, this._collectAdornments(), Array.from(this.children).forEach((e) => {
429
+ e.hasAttribute(r) && e.remove();
430
+ });
431
+ let i = this.getAttribute("label")?.trim() || "", a = this.getAttribute("id") || this._id;
432
+ if (i) {
433
+ let e = document.createElement("label");
434
+ e.setAttribute(r, "label"), e.className = "mint-select-label", e.htmlFor = `${a}-trigger`, e.textContent = i, this.append(e);
435
+ }
436
+ let o = document.createElement("div");
437
+ o.setAttribute(r, "wrap"), o.className = "mint-select-control-wrap", o.style.position = "relative", this.append(o);
438
+ let s = this._makeAdornment("prepend", this._prependNodes);
439
+ s && o.append(s);
440
+ let c = document.createElement("button");
441
+ c.type = "button", c.id = `${a}-trigger`, c.className = "mint-select-trigger", c.disabled = this.isDisabled() || this.isLoading(), c.setAttribute("role", "combobox"), c.setAttribute("aria-busy", String(this.isLoading())), c.setAttribute("aria-haspopup", "listbox"), c.setAttribute("aria-expanded", "false"), c.setAttribute("aria-required", String(this.isRequired())), c.setAttribute("aria-invalid", String(this.hasError()));
442
+ let l = this.getAttribute("aria-labelledby"), u = this.getAttribute("aria-label")?.trim();
443
+ if (l ? c.setAttribute("aria-labelledby", l) : !i && u ? c.setAttribute("aria-label", u) : i && c.setAttribute("aria-labelledby", `${a}-label`), i) {
444
+ let e = this.querySelector(`[${r}="label"]`);
445
+ e && (e.id = `${a}-label`);
446
+ }
447
+ let d = document.createElement("span");
448
+ d.className = "mint-select-value", c.append(d);
449
+ let f = document.createElement("span");
450
+ f.className = "mint-select-caret", f.setAttribute("aria-hidden", "true"), f.innerHTML = "<mint-icon name=\"caret-up\"></mint-icon><mint-icon name=\"caret-down\"></mint-icon>", c.append(f), o.append(c);
451
+ let p = this._makeAdornment("append", this._appendNodes);
452
+ p && o.append(p);
453
+ let m = null;
454
+ this.isLoading() ? (m = document.createElement("div"), m.className = "mint-select-skeleton", m.setAttribute("aria-hidden", "true"), m.style.cssText = "position:absolute;inset:0;z-index:1;border:1px solid var(--mint-color-border,#dfe6e0);border-radius:.5rem;background:var(--mint-color-surface-muted,#e8eee9);animation:mint-select-pulse 1.4s ease-in-out infinite;", o.append(m), c.style.visibility = "hidden", this.setAttribute("aria-busy", "true")) : this.removeAttribute("aria-busy");
455
+ let h = document.createElement("select");
456
+ h.setAttribute(r, "native"), h.className = "mint-select-native-control", h.id = `${a}-native`, h.name = this.getAttribute("name") || "", h.multiple = this.isMultiple(), this.hasAttribute("form") && h.setAttribute("form", this.getAttribute("form") || ""), h.required = this.isRequired(), h.disabled = this.isDisabled(), h.tabIndex = -1, h.setAttribute("aria-hidden", "true"), h.setAttribute("aria-invalid", String(this.hasError()));
457
+ let g = [
458
+ this.getAttribute("aria-describedby"),
459
+ i ? `${a}-label` : "",
460
+ this.getAttribute("info") ? `${a}-info` : "",
461
+ this.getAttribute("error-message") ? `${a}-error` : ""
462
+ ].filter(Boolean).join(" ");
463
+ if (g && h.setAttribute("aria-describedby", g), this.options().forEach((e) => h.append(e.cloneNode(!0))), !h.options.length) {
464
+ let e = document.createElement("option");
465
+ e.value = "", e.textContent = this.getAttribute("placeholder") || "Select an option", e.disabled = !0, h.append(e);
466
+ }
467
+ if (h.multiple) {
468
+ let t = n.length ? n : this.parseValues(this.getAttribute("values")).length ? this.parseValues(this.getAttribute("values")) : e ? [e] : [];
469
+ t.length && Array.from(h.options).forEach((e) => {
470
+ e.selected = t.includes(e.value);
471
+ });
472
+ } else h.value = e;
473
+ o.append(h), this._native = h, this._trigger = c;
474
+ let _ = document.createElement("mint-popover");
475
+ _.className = "mint-select-popover", _.setAttribute(r, "popover"), _.setAttribute("trigger-id", c.id), _.setAttribute("trigger-toggle", "false"), _.setAttribute("direction", "down"), _.setAttribute("trigger-align", "start"), _.setAttribute("align-selected", "true"), _.setAttribute("distance", "4"), _.setAttribute("padding", "0"), _.setAttribute("aria-label", i ? `${i} options` : "Select options");
476
+ let v = document.createElement("div");
477
+ v.className = "mint-select-options", v.id = `${a}-listbox`, v.setAttribute("role", "listbox"), v.setAttribute("aria-multiselectable", String(this.isMultiple())), c.setAttribute("aria-controls", v.id), _.append(v), this.append(_), this._popover = _, this._list = v, this.renderOptions(), this.updateDisplay(), this.bindEvents();
478
+ let y = this.getAttribute("info");
479
+ if (y) {
480
+ let e = document.createElement("div");
481
+ e.setAttribute(r, "info"), e.className = "mint-select-info", e.id = `${a}-info`, e.textContent = y, this.append(e);
482
+ }
483
+ let b = this.getAttribute("error-message");
484
+ if (this.hasError() && b) {
485
+ let e = document.createElement("div");
486
+ e.setAttribute(r, "error"), e.className = "mint-select-error", e.id = `${a}-error`, e.textContent = b, this.append(e);
487
+ }
488
+ this._syncing = !1;
489
+ }
490
+ renderOptions() {
491
+ this._list && (this._list.replaceChildren(), Array.from(this.children).filter((e) => e.tagName === "OPTION" || e.tagName === "OPTGROUP").forEach((e) => {
492
+ if (e instanceof HTMLOptGroupElement) {
493
+ let t = document.createElement("div");
494
+ t.className = "mint-select-group-label", t.setAttribute("role", "presentation"), t.textContent = e.label, this._list.append(t), Array.from(e.children).forEach((t) => this.addOption(t, e.disabled));
495
+ } else this.addOption(e, !1);
496
+ }));
497
+ }
498
+ _collectAdornments() {
499
+ let e = [
500
+ ...this._prependNodes,
501
+ ...this._appendNodes,
502
+ ...Array.from(this.querySelectorAll(":scope > [slot=\"prepend\"], :scope > [slot=\"append\"]"))
503
+ ];
504
+ this._prependNodes = e.filter((e) => e.getAttribute("slot") === "prepend"), this._appendNodes = e.filter((e) => e.getAttribute("slot") === "append"), this._prependNodes.forEach((e) => this.append(e)), this._appendNodes.forEach((e) => this.append(e));
505
+ }
506
+ _makeAdornment(e, t) {
507
+ if (!t.length) return null;
508
+ let n = document.createElement("span");
509
+ return n.className = `mint-select-adornment mint-select-${e}-slot`, t.forEach((e) => n.append(e)), n;
510
+ }
511
+ addOption(e, t) {
512
+ if (!this._list) return;
513
+ let n = document.createElement("button");
514
+ n.type = "button", n.className = "mint-select-option", n.dataset.value = e.value, n.setAttribute("role", "option"), n.setAttribute("aria-selected", String(this.isMultiple() ? this.values.includes(e.value) : e.value === this.value)), n.disabled = e.disabled || t || this.isDisabled(), n.tabIndex = -1;
515
+ let r = document.createElement("span");
516
+ r.textContent = e.label || e.textContent || "", n.append(r);
517
+ let i = document.createElement("mint-icon");
518
+ i.setAttribute("name", "check"), i.setAttribute("aria-hidden", "true"), i.className = "mint-select-option-check", n.append(i), this._list.append(n);
519
+ }
520
+ updateDisplay() {
521
+ if (!this._native || !this._trigger) return;
522
+ let e = this.selectedOption(), t = this.values, n = this.isMultiple() ? t.map((e) => this.options().find((t) => t.value === e)?.label || e) : [], r = this._trigger.querySelector(".mint-select-value");
523
+ r && (r.textContent = this.isMultiple() ? n.join(", ") || this.getAttribute("placeholder") || "Select an option" : e?.getAttribute("data-display-label") || e?.label || e?.textContent?.trim() || this.getAttribute("placeholder") || "Select an option", r.classList.toggle("is-placeholder", this.isMultiple() ? t.length === 0 : !e || e.value === "")), this._trigger.setAttribute("aria-invalid", String(this.hasError())), this._trigger.setAttribute("aria-haspopup", "listbox"), this._list?.setAttribute("aria-multiselectable", String(this.isMultiple())), this._list?.querySelectorAll("[role=\"option\"]").forEach((e) => e.setAttribute("aria-selected", String(this.isMultiple() ? t.includes(e.dataset.value || "") : e.dataset.value === this._native.value)));
524
+ }
525
+ bindEvents() {
526
+ !this._trigger || !this._popover || !this._native || !this._list || (this._trigger.onclick = () => {
527
+ this._popover.style.setProperty("--mint-select-popover-width", `${this._trigger.getBoundingClientRect().width}px`), this._popover.hasAttribute("open") ? this._popover.close() : this.openPopover();
528
+ }, this._trigger.onkeydown = (e) => {
529
+ let t = Array.from(this._list.querySelectorAll("[role=\"option\"]:not(:disabled)"));
530
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
531
+ e.preventDefault(), this._popover.hasAttribute("open") || this.openPopover();
532
+ let n = t.findIndex((e) => e.dataset.value === (this.isMultiple() ? this.values[0] : this._native.value));
533
+ t[e.key === "ArrowDown" ? Math.min(t.length - 1, n + 1) : Math.max(0, n <= 0 ? 0 : n - 1)]?.focus();
534
+ } else if (e.key === "Enter" || e.key === " ") if (this._popover.hasAttribute("open")) {
535
+ e.preventDefault();
536
+ let t = this._list.querySelector("[role=\"option\"]:focus");
537
+ t ? this.selectOption(t.dataset.value || "") : this.openPopover();
538
+ } else e.key === " " && (e.preventDefault(), this.openPopover());
539
+ else e.key === "Escape" && this._popover.hasAttribute("open") ? (e.preventDefault(), this._popover.close(), this._trigger.focus()) : e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && this.typeahead(e.key);
540
+ }, this._list.onpointerdown = (e) => {
541
+ let t = e.target.closest("[role=\"option\"]");
542
+ if (!t || t.disabled) return;
543
+ e.preventDefault();
544
+ let n = t.dataset.value || "";
545
+ this._pointerSelectedOption = {
546
+ value: n,
547
+ time: Date.now()
548
+ }, this.selectOption(n);
549
+ }, this._list.onclick = (e) => {
550
+ let t = e.target.closest("[role=\"option\"]");
551
+ if (!t || t.disabled) return;
552
+ let n = t.dataset.value || "", r = this._pointerSelectedOption?.value === n && Date.now() - this._pointerSelectedOption.time < 1e3;
553
+ this._pointerSelectedOption = null, r || this.selectOption(n);
554
+ }, this._list.onkeydown = (e) => {
555
+ let t = Array.from(this._list.querySelectorAll("[role=\"option\"]:not(:disabled)")), n = t.indexOf(e.target), r = n;
556
+ if (e.key === "ArrowDown") r = Math.min(t.length - 1, n + 1);
557
+ else if (e.key === "ArrowUp") r = Math.max(0, n - 1);
558
+ else if (e.key === "Home") r = 0;
559
+ else if (e.key === "End") r = t.length - 1;
560
+ else if (e.key === "Escape") {
561
+ e.preventDefault(), this._popover.close(), this._trigger.focus();
562
+ return;
563
+ } else if (e.key === "Enter" || e.key === " ") {
564
+ e.preventDefault(), this.selectOption(e.target.dataset.value || "");
565
+ return;
566
+ } else if (e.key.length === 1) {
567
+ this.typeahead(e.key);
568
+ return;
569
+ } else return;
570
+ e.preventDefault(), t[r]?.focus();
571
+ }, this._native.onchange = () => {
572
+ this.isMultiple() ? this.setAttribute("values", JSON.stringify(this.values)) : this.setAttribute("value", this._native.value), this.updateDisplay(), this.dispatchSelectionEvents();
573
+ });
574
+ }
575
+ openPopover() {
576
+ this._popover && this._popover.open();
577
+ }
578
+ selectOption(e) {
579
+ if (this._native) {
580
+ if (this.isMultiple()) {
581
+ let t = new Set(this.values);
582
+ t.has(e) ? t.delete(e) : t.add(e);
583
+ let n = [...t];
584
+ this._applyValues(n), this.setAttribute("values", JSON.stringify(n)), this.updateDisplay(), this.dispatchSelectionEvents();
585
+ return;
586
+ }
587
+ this._native.value = e, this.setAttribute("value", e), this.updateDisplay(), this._popover?.close(), this._trigger?.focus(), this.dispatchSelectionEvents();
588
+ }
589
+ }
590
+ dispatchSelectionEvents() {
591
+ let e = this.isMultiple() ? this.values : this._native?.value || "", t = this.isMultiple() ? {
592
+ value: e,
593
+ values: e
594
+ } : { value: e };
595
+ this.dispatchEvent(new CustomEvent("input", {
596
+ bubbles: !0,
597
+ composed: !0,
598
+ detail: t
599
+ })), this.dispatchEvent(new CustomEvent("change", {
600
+ bubbles: !0,
601
+ composed: !0,
602
+ detail: t
603
+ }));
604
+ }
605
+ typeahead(e) {
606
+ this._typeahead += e.toLocaleLowerCase(), this._typeaheadTimer !== null && window.clearTimeout(this._typeaheadTimer), this._typeaheadTimer = window.setTimeout(() => {
607
+ this._typeahead = "";
608
+ }, 700);
609
+ let t = Array.from(this._list?.querySelectorAll("[role=\"option\"]:not(:disabled)") || []).find((e) => e.textContent?.trim().toLocaleLowerCase().startsWith(this._typeahead));
610
+ t && (this._popover?.hasAttribute("open") || this.openPopover(), t.focus());
611
+ }
612
+ };
613
+ customElements.get("mint-select") || e("mint-select", i);
614
+ //#endregion
615
+ export { n, i as t };