monobill-mintui 0.6.650 → 0.6.652
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/bin/component-dependencies.json +13 -1
- package/dist/components/chunks/ScrollFade-D1FPF6ZS.js +82 -0
- package/dist/components/chunks/ScrollFade-DT2Br2g7.js +1 -0
- package/dist/components/chunks/date-picker-BQsCoKaK.js +1282 -0
- package/dist/components/chunks/date-picker-tm5Oc92c.js +1 -0
- package/dist/components/chunks/{input-CYv5hraJ.js → input-DcglGwsR.js} +13 -6
- package/dist/components/chunks/input-awdYlp-G.js +1 -0
- package/dist/components/chunks/{popover-DB1OaYVe.js → popover-FdMS4yAD.js} +54 -14
- package/dist/components/chunks/popover-wGdggZ-a.js +1 -0
- package/dist/components/chunks/{table-DRdsVUJL.js → table-B9e-cnAC.js} +7 -6
- package/dist/components/chunks/table-vjF3q3J5.js +1 -0
- package/dist/components/chunks/time-picker-Cq3qzkDb.js +1 -0
- package/dist/components/chunks/time-picker-S0bc0BPU.js +360 -0
- package/dist/components/date-picker/DatePicker.d.ts +5 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
- package/dist/components/date-picker/browser.js +2 -1270
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +2 -1270
- package/dist/components/datetime-picker/DateTimePicker.d.ts +44 -0
- package/dist/components/datetime-picker/DateTimePicker.d.ts.map +1 -0
- package/dist/components/datetime-picker/browser.js +255 -0
- package/dist/components/datetime-picker/index.cjs +1 -0
- package/dist/components/datetime-picker/index.d.ts +4 -0
- package/dist/components/datetime-picker/index.d.ts.map +1 -0
- package/dist/components/datetime-picker/index.js +243 -0
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/form/browser.js +9 -8
- package/dist/components/form/index.cjs +1 -1
- package/dist/components/form/index.js +9 -8
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/link/browser.js +1 -1
- package/dist/components/link/index.cjs +1 -1
- package/dist/components/link/index.js +1 -1
- package/dist/components/navigation/browser.js +2 -2
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/popover/Popover.d.ts.map +1 -1
- package/dist/components/popover/browser.js +1 -1
- package/dist/components/popover/index.cjs +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/resource-table/ResourceTable.d.ts +1 -0
- package/dist/components/resource-table/ResourceTable.d.ts.map +1 -1
- package/dist/components/resource-table/browser.js +22 -22
- package/dist/components/resource-table/index.cjs +2 -2
- package/dist/components/resource-table/index.js +22 -22
- package/dist/components/scroll-fade/ScrollFade.d.ts +15 -0
- package/dist/components/scroll-fade/ScrollFade.d.ts.map +1 -0
- package/dist/components/scroll-fade/browser.js +16 -0
- package/dist/components/scroll-fade/index.cjs +1 -0
- package/dist/components/scroll-fade/index.d.ts +6 -0
- package/dist/components/scroll-fade/index.d.ts.map +1 -0
- package/dist/components/scroll-fade/index.js +4 -0
- package/dist/components/search/Search.d.ts.map +1 -1
- package/dist/components/search/browser.js +3 -3
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +3 -3
- package/dist/components/select/NativeSelect.d.ts +38 -0
- package/dist/components/select/NativeSelect.d.ts.map +1 -0
- package/dist/components/select/Select.d.ts +36 -29
- package/dist/components/select/Select.d.ts.map +1 -1
- package/dist/components/select/browser.js +313 -19
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.d.ts +3 -2
- package/dist/components/select/index.d.ts.map +1 -1
- package/dist/components/select/index.js +313 -19
- package/dist/components/side-navigation/SideNavigation.d.ts +1 -0
- package/dist/components/side-navigation/SideNavigation.d.ts.map +1 -1
- package/dist/components/side-navigation/browser.js +24 -23
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +24 -23
- package/dist/components/sortable/browser.js +1 -1
- package/dist/components/sortable/index.cjs +1 -1
- package/dist/components/sortable/index.js +1 -1
- package/dist/components/table/Table.d.ts +1 -0
- package/dist/components/table/Table.d.ts.map +1 -1
- package/dist/components/table/browser.js +1 -1
- package/dist/components/table/index.cjs +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/tags/browser.js +1 -1
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +1 -1
- package/dist/components/time-picker/TimePicker.d.ts +1 -0
- package/dist/components/time-picker/TimePicker.d.ts.map +1 -1
- package/dist/components/time-picker/browser.js +2 -347
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +2 -347
- package/dist/components/tree/Tree.d.ts +2 -0
- package/dist/components/tree/Tree.d.ts.map +1 -1
- package/dist/components/tree/browser.js +15 -7
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +15 -7
- package/dist/datetime-picker.css +3 -0
- package/dist/index.cjs +4 -4
- package/dist/index.css +22 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1413 -739
- package/dist/modal.css +1 -1
- package/dist/navigation-search.json +15 -1
- package/dist/navigation.css +1 -1
- package/dist/off-canvas.css +1 -1
- package/dist/popover.css +1 -1
- package/dist/scroll-fade.css +3 -0
- package/dist/select.css +1 -1
- package/dist/side-navigation.css +1 -1
- package/dist/theme.css +7 -2
- package/dist/time-picker.css +1 -1
- package/package.json +19 -1
- package/dist/components/chunks/caret-up-DzrY-bTy.js +0 -1
- package/dist/components/chunks/caret-up-ZK3v_oWQ.js +0 -9
- package/dist/components/chunks/input-Du8C2LW8.js +0 -1
- package/dist/components/chunks/popover-CNZ5u-MA.js +0 -1
- package/dist/components/chunks/table-2-0iNQJy.js +0 -1
- /package/dist/components/chunks/{caret-right-BzeJ0Fw3.js → caret-right-BcZ9bOhS.js} +0 -0
- /package/dist/components/chunks/{caret-right-Bh7uMg-Y.js → caret-right-CgIVfus7.js} +0 -0
- /package/dist/components/chunks/{link-BsC3zT_I.js → link-BjbBJpI6.js} +0 -0
- /package/dist/components/chunks/{link-dTjSvr4E.js → link-CU-gTgir.js} +0 -0
- /package/dist/components/chunks/{search-v06eZL4m.js → search--bcFMYMP.js} +0 -0
- /package/dist/components/chunks/{search-CTAGy5ab.js → search-Cixhf7hA.js} +0 -0
- /package/dist/components/chunks/{sortable-B1nMJBah.js → sortable-CNlF0_gv.js} +0 -0
- /package/dist/components/chunks/{sortable-CXM-7eyL.js → sortable-CVK48xj1.js} +0 -0
|
@@ -12,14 +12,15 @@ const __mintLoadStyle = (key, url) => {
|
|
|
12
12
|
}
|
|
13
13
|
__mintLoadStyle('theme', '../../theme.css')
|
|
14
14
|
__mintLoadStyle('icon', '../../icon.css')
|
|
15
|
+
__mintLoadStyle('popover', '../../popover.css')
|
|
16
|
+
__mintLoadStyle('stack', '../../stack.css')
|
|
15
17
|
__mintLoadStyle('select', '../../select.css')
|
|
16
18
|
import "../chunks/icon-Cxv9k3CY.js";
|
|
17
19
|
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
18
20
|
import "../chunks/icon-DMa6Oo80.js";
|
|
19
|
-
import "../chunks/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var t = "data-mint-select-part", n = class extends HTMLElement {
|
|
21
|
+
import "../chunks/popover-FdMS4yAD.js";
|
|
22
|
+
//#region src/components/select/NativeSelect.ts
|
|
23
|
+
var t = "data-mint-native-select-part", n = class extends HTMLElement {
|
|
23
24
|
static get observedAttributes() {
|
|
24
25
|
return [
|
|
25
26
|
"name",
|
|
@@ -39,10 +40,10 @@ var t = "data-mint-select-part", n = class extends HTMLElement {
|
|
|
39
40
|
];
|
|
40
41
|
}
|
|
41
42
|
constructor() {
|
|
42
|
-
super(), this._select = null, this._wrapper = null, this._caretUpIcon = null, this._caretDownIcon = null, this._changeHandler = null, this._optionObserver = null, this._childrenObserver = null, this._hostOptionsObserverRaf = null, this._generatedControlId = `mint-select-${Math.random().toString(36).slice(2, 10)}`;
|
|
43
|
+
super(), this._select = null, this._wrapper = null, 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)}`;
|
|
43
44
|
}
|
|
44
45
|
connectedCallback() {
|
|
45
|
-
this.classList.add("mint-select-host"), this.getLabel() || console.error("mint-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) => {
|
|
46
|
+
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) => {
|
|
46
47
|
if (e.some((e) => {
|
|
47
48
|
let t = e.target;
|
|
48
49
|
if (this._select && (t === this._select || this._select.contains(t))) return !1;
|
|
@@ -169,7 +170,7 @@ var t = "data-mint-select-part", n = class extends HTMLElement {
|
|
|
169
170
|
}
|
|
170
171
|
getSelectClasses() {
|
|
171
172
|
return [
|
|
172
|
-
"mint-select-control",
|
|
173
|
+
"mint-native-select-control",
|
|
173
174
|
this.isMultiple() ? "is-multiple" : "",
|
|
174
175
|
this.hasError() ? "has-error" : ""
|
|
175
176
|
].filter(Boolean).join(" ");
|
|
@@ -185,11 +186,11 @@ var t = "data-mint-select-part", n = class extends HTMLElement {
|
|
|
185
186
|
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();
|
|
186
187
|
if (o) {
|
|
187
188
|
let e = document.createElement("label");
|
|
188
|
-
e.setAttribute(t, "label"), e.className = "mint-select-label", c && e.setAttribute("for", c);
|
|
189
|
+
e.setAttribute(t, "label"), e.className = "mint-native-select-label", c && e.setAttribute("for", c);
|
|
189
190
|
let n = document.createTextNode(o);
|
|
190
191
|
e.appendChild(n), this.appendChild(e);
|
|
191
192
|
}
|
|
192
|
-
this._wrapper = document.createElement("div"), this._wrapper.setAttribute(t, "wrapper"), this._wrapper.className = "mint-select-control-wrap", this.appendChild(this._wrapper), 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");
|
|
193
|
+
this._wrapper = document.createElement("div"), this._wrapper.setAttribute(t, "wrapper"), this._wrapper.className = "mint-native-select-control-wrap", this.appendChild(this._wrapper), 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");
|
|
193
194
|
let f = this.getAttribute("aria-label")?.trim(), p = this.getAttribute("aria-labelledby")?.trim();
|
|
194
195
|
p ? this._select.setAttribute("aria-labelledby", p) : o ? this._select.removeAttribute("aria-label") : this._select.setAttribute("aria-label", f || "Select an option");
|
|
195
196
|
let m = a.length > 0 ? a : i;
|
|
@@ -252,34 +253,327 @@ var t = "data-mint-select-part", n = class extends HTMLElement {
|
|
|
252
253
|
}), this._wrapper.appendChild(this._select), n) this._caretUpIcon = null, this._caretDownIcon = null;
|
|
253
254
|
else {
|
|
254
255
|
let e = document.createElement("div");
|
|
255
|
-
e.className = "mint-select-caret", this._caretUpIcon = document.createElement("mint-icon"), this._caretUpIcon.setAttribute("name", "caret-up"), this._caretUpIcon.className = "mint-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-select-caret-down", this._caretDownIcon.setAttribute("aria-hidden", "true"), e.appendChild(this._caretDownIcon), this._wrapper.appendChild(e);
|
|
256
|
+
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), this._wrapper.appendChild(e);
|
|
256
257
|
}
|
|
257
258
|
if (s) {
|
|
258
259
|
let e = document.createElement("div");
|
|
259
|
-
e.setAttribute(t, "info"), e.className = "mint-select-info", e.textContent = s, this.appendChild(e);
|
|
260
|
+
e.setAttribute(t, "info"), e.className = "mint-native-select-info", e.textContent = s, this.appendChild(e);
|
|
260
261
|
}
|
|
261
262
|
this._renderErrorState(), this._syncSelectAccessibility(), this._renderSkeleton(e);
|
|
262
263
|
}
|
|
263
264
|
_renderSkeleton(e) {
|
|
264
|
-
let t = this.querySelector(".mint-select-skeleton-container"), n = this._wrapper;
|
|
265
|
+
let t = this.querySelector(".mint-native-select-skeleton-container"), n = this._wrapper;
|
|
265
266
|
if (e) {
|
|
266
|
-
t || (t = document.createElement("div"), t.className = "mint-select-skeleton-container", t.setAttribute("aria-hidden", "true"), n ? n.appendChild(t) : this.appendChild(t));
|
|
267
|
-
let e = t.querySelector(".mint-select-skeleton");
|
|
267
|
+
t || (t = document.createElement("div"), t.className = "mint-native-select-skeleton-container", t.setAttribute("aria-hidden", "true"), n ? n.appendChild(t) : this.appendChild(t));
|
|
268
|
+
let e = t.querySelector(".mint-native-select-skeleton");
|
|
268
269
|
e || (e = document.createElement("div"), t.appendChild(e));
|
|
269
270
|
let r = this.isMultiple();
|
|
270
271
|
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"));
|
|
271
272
|
} else t && (t.style.display = "none"), this._select && (this._select.style.opacity = "1", this._select.style.pointerEvents = "auto", this._select.removeAttribute("aria-busy"));
|
|
272
273
|
}
|
|
273
274
|
_renderErrorState() {
|
|
274
|
-
let e = this.hasError(), n = this.getErrorMessage(), r = this.querySelector(".mint-select-error");
|
|
275
|
-
e && n ? (r ? r.hasAttribute(t) || r.setAttribute(t, "error") : (r = document.createElement("div"), r.setAttribute(t, "error"), r.className = "mint-select-error", this.appendChild(r)), r.textContent = n) : r && r.remove();
|
|
275
|
+
let e = this.hasError(), n = this.getErrorMessage(), r = this.querySelector(".mint-native-select-error");
|
|
276
|
+
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();
|
|
276
277
|
}
|
|
277
278
|
_syncSelectAccessibility() {
|
|
278
279
|
if (!this._select) return;
|
|
279
|
-
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-select-error");
|
|
280
|
+
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");
|
|
280
281
|
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");
|
|
281
282
|
}
|
|
282
283
|
};
|
|
283
|
-
customElements.get("mint-select") || e("mint-select", n);
|
|
284
|
+
customElements.get("mint-native-select") || e("mint-native-select", n);
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/components/select/Select.ts
|
|
287
|
+
var r = "data-mint-select-part", i = class extends HTMLElement {
|
|
288
|
+
constructor(...e) {
|
|
289
|
+
super(...e), this._native = null, this._trigger = null, this._popover = null, this._list = null, this._observer = null, this._syncing = !1, this._typeahead = "", this._typeaheadTimer = null, this._id = `mint-select-${Math.random().toString(36).slice(2, 10)}`;
|
|
290
|
+
}
|
|
291
|
+
static get observedAttributes() {
|
|
292
|
+
return [
|
|
293
|
+
"name",
|
|
294
|
+
"value",
|
|
295
|
+
"values",
|
|
296
|
+
"multiple",
|
|
297
|
+
"disabled",
|
|
298
|
+
"id",
|
|
299
|
+
"required",
|
|
300
|
+
"label",
|
|
301
|
+
"info",
|
|
302
|
+
"error",
|
|
303
|
+
"error-message",
|
|
304
|
+
"loading",
|
|
305
|
+
"placeholder",
|
|
306
|
+
"aria-label",
|
|
307
|
+
"aria-labelledby",
|
|
308
|
+
"aria-describedby",
|
|
309
|
+
"form"
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
connectedCallback() {
|
|
313
|
+
this.classList.add("mint-select-host"), this.render(), this._observer?.disconnect(), this._observer = new MutationObserver((e) => {
|
|
314
|
+
this._syncing || e.some((e) => {
|
|
315
|
+
let t = e.target instanceof Element ? e.target : e.target.parentElement;
|
|
316
|
+
return t === this || t?.closest(`[${r}]`) ? !1 : e.type === "attributes" ? [
|
|
317
|
+
"value",
|
|
318
|
+
"label",
|
|
319
|
+
"disabled",
|
|
320
|
+
"selected"
|
|
321
|
+
].includes(e.attributeName) : t instanceof HTMLOptionElement || t instanceof HTMLOptGroupElement || [...e.addedNodes, ...e.removedNodes].some((e) => e instanceof HTMLOptionElement || e instanceof HTMLOptGroupElement);
|
|
322
|
+
}) && this.render();
|
|
323
|
+
}), this._observer.observe(this, {
|
|
324
|
+
childList: !0,
|
|
325
|
+
subtree: !0,
|
|
326
|
+
attributes: !0,
|
|
327
|
+
attributeFilter: [
|
|
328
|
+
"value",
|
|
329
|
+
"label",
|
|
330
|
+
"disabled",
|
|
331
|
+
"selected"
|
|
332
|
+
]
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
disconnectedCallback() {
|
|
336
|
+
this._observer?.disconnect(), this._observer = null, this._typeaheadTimer !== null && window.clearTimeout(this._typeaheadTimer);
|
|
337
|
+
}
|
|
338
|
+
attributeChangedCallback(e, t, n) {
|
|
339
|
+
if (!(t === n || !this.isConnected)) {
|
|
340
|
+
if (e === "values" && this._native && this.isMultiple()) {
|
|
341
|
+
this._applyValues(this.parseValues(n)), this.updateDisplay();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (e === "multiple" && this._native) {
|
|
345
|
+
this.render();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (e === "value" && this._native) {
|
|
349
|
+
this.isMultiple() ? this._applyValues(n ? [n] : []) : this._native.value = n || "", this.updateDisplay();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this.render();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
get value() {
|
|
356
|
+
return this.isMultiple() ? this.values : this._native?.value || this.getAttribute("value") || "";
|
|
357
|
+
}
|
|
358
|
+
set value(e) {
|
|
359
|
+
this.setValue(e);
|
|
360
|
+
}
|
|
361
|
+
get values() {
|
|
362
|
+
return this._native && this.isMultiple() ? Array.from(this._native.selectedOptions, (e) => e.value) : this.parseValues(this.getAttribute("values"));
|
|
363
|
+
}
|
|
364
|
+
set values(e) {
|
|
365
|
+
this.setValue(e);
|
|
366
|
+
}
|
|
367
|
+
getValue() {
|
|
368
|
+
return this.value;
|
|
369
|
+
}
|
|
370
|
+
setValue(e) {
|
|
371
|
+
if (this.isMultiple()) {
|
|
372
|
+
let t = Array.isArray(e) ? e.map(String) : e == null || e === "" ? [] : [String(e)];
|
|
373
|
+
this.setAttribute("values", JSON.stringify(t)), this._applyValues(t);
|
|
374
|
+
} else {
|
|
375
|
+
let t = e == null ? "" : String(e);
|
|
376
|
+
this.setAttribute("value", t), this._native && (this._native.value = t);
|
|
377
|
+
}
|
|
378
|
+
this.updateDisplay();
|
|
379
|
+
}
|
|
380
|
+
isDisabled() {
|
|
381
|
+
return this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false";
|
|
382
|
+
}
|
|
383
|
+
isLoading() {
|
|
384
|
+
let e = this.getAttribute("loading");
|
|
385
|
+
return e !== null && e !== "false";
|
|
386
|
+
}
|
|
387
|
+
isRequired() {
|
|
388
|
+
return this.hasAttribute("required") && this.getAttribute("required") !== "false";
|
|
389
|
+
}
|
|
390
|
+
isMultiple() {
|
|
391
|
+
return this.hasAttribute("multiple") && this.getAttribute("multiple") !== "false";
|
|
392
|
+
}
|
|
393
|
+
hasError() {
|
|
394
|
+
return this.getAttribute("error") === "true";
|
|
395
|
+
}
|
|
396
|
+
parseValues(e) {
|
|
397
|
+
if (!e) return [];
|
|
398
|
+
try {
|
|
399
|
+
let t = JSON.parse(e);
|
|
400
|
+
if (Array.isArray(t)) {
|
|
401
|
+
if (t.length === 1 && typeof t[0] == "string" && t[0].trim().startsWith("[")) try {
|
|
402
|
+
let e = JSON.parse(t[0]);
|
|
403
|
+
if (Array.isArray(e)) return e.map(String);
|
|
404
|
+
} catch {}
|
|
405
|
+
return t.map(String);
|
|
406
|
+
}
|
|
407
|
+
} catch {}
|
|
408
|
+
return [e];
|
|
409
|
+
}
|
|
410
|
+
_applyValues(e) {
|
|
411
|
+
if (!this._native) return;
|
|
412
|
+
let t = new Set(e);
|
|
413
|
+
Array.from(this._native.options).forEach((e) => {
|
|
414
|
+
e.selected = t.has(e.value);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
options() {
|
|
418
|
+
return Array.from(this.querySelectorAll(":scope > option, :scope > optgroup > option"));
|
|
419
|
+
}
|
|
420
|
+
selectedOption() {
|
|
421
|
+
return this._native?.selectedOptions[0] || this.options().find((e) => e.value === this.value);
|
|
422
|
+
}
|
|
423
|
+
render() {
|
|
424
|
+
let e = this._native?.value ?? this.getAttribute("value") ?? "", t = this._native && this._native.multiple ? Array.from(this._native.selectedOptions, (e) => e.value) : this.parseValues(this.getAttribute("values"));
|
|
425
|
+
this._syncing = !0, Array.from(this.children).forEach((e) => {
|
|
426
|
+
e.hasAttribute(r) && e.remove();
|
|
427
|
+
});
|
|
428
|
+
let n = this.getAttribute("label")?.trim() || "", i = this.getAttribute("id") || this._id;
|
|
429
|
+
if (n) {
|
|
430
|
+
let e = document.createElement("label");
|
|
431
|
+
e.setAttribute(r, "label"), e.className = "mint-select-label", e.htmlFor = `${i}-trigger`, e.textContent = n, this.append(e);
|
|
432
|
+
}
|
|
433
|
+
let a = document.createElement("div");
|
|
434
|
+
a.setAttribute(r, "wrap"), a.className = "mint-select-control-wrap", this.append(a);
|
|
435
|
+
let o = document.createElement("button");
|
|
436
|
+
o.type = "button", o.id = `${i}-trigger`, o.className = "mint-select-trigger", o.disabled = this.isDisabled() || this.isLoading(), o.setAttribute("role", "combobox"), o.setAttribute("aria-busy", String(this.isLoading())), o.setAttribute("aria-haspopup", "listbox"), o.setAttribute("aria-expanded", "false"), o.setAttribute("aria-required", String(this.isRequired())), o.setAttribute("aria-invalid", String(this.hasError()));
|
|
437
|
+
let s = this.getAttribute("aria-labelledby"), c = this.getAttribute("aria-label")?.trim();
|
|
438
|
+
if (s ? o.setAttribute("aria-labelledby", s) : !n && c ? o.setAttribute("aria-label", c) : n && o.setAttribute("aria-labelledby", `${i}-label`), n) {
|
|
439
|
+
let e = this.querySelector(`[${r}="label"]`);
|
|
440
|
+
e && (e.id = `${i}-label`);
|
|
441
|
+
}
|
|
442
|
+
let l = document.createElement("span");
|
|
443
|
+
l.className = "mint-select-value", o.append(l);
|
|
444
|
+
let u = document.createElement("span");
|
|
445
|
+
u.className = "mint-select-caret", u.setAttribute("aria-hidden", "true"), u.innerHTML = "<mint-icon name=\"caret-up\"></mint-icon><mint-icon name=\"caret-down\"></mint-icon>", o.append(u), a.append(o);
|
|
446
|
+
let d = document.createElement("select");
|
|
447
|
+
d.setAttribute(r, "native"), d.className = "mint-select-native-control", d.id = `${i}-native`, d.name = this.getAttribute("name") || "", d.multiple = this.isMultiple(), this.hasAttribute("form") && d.setAttribute("form", this.getAttribute("form") || ""), d.required = this.isRequired(), d.disabled = this.isDisabled(), d.tabIndex = -1, d.setAttribute("aria-hidden", "true"), d.setAttribute("aria-invalid", String(this.hasError()));
|
|
448
|
+
let f = [
|
|
449
|
+
this.getAttribute("aria-describedby"),
|
|
450
|
+
n ? `${i}-label` : "",
|
|
451
|
+
this.getAttribute("info") ? `${i}-info` : "",
|
|
452
|
+
this.getAttribute("error-message") ? `${i}-error` : ""
|
|
453
|
+
].filter(Boolean).join(" ");
|
|
454
|
+
if (f && d.setAttribute("aria-describedby", f), this.options().forEach((e) => d.append(e.cloneNode(!0))), !d.options.length) {
|
|
455
|
+
let e = document.createElement("option");
|
|
456
|
+
e.value = "", e.textContent = this.getAttribute("placeholder") || "Select an option", e.disabled = !0, d.append(e);
|
|
457
|
+
}
|
|
458
|
+
if (d.multiple) {
|
|
459
|
+
let n = t.length ? t : this.parseValues(this.getAttribute("values")).length ? this.parseValues(this.getAttribute("values")) : e ? [e] : [];
|
|
460
|
+
n.length && Array.from(d.options).forEach((e) => {
|
|
461
|
+
e.selected = n.includes(e.value);
|
|
462
|
+
});
|
|
463
|
+
} else d.value = e;
|
|
464
|
+
a.append(d), this._native = d, this._trigger = o;
|
|
465
|
+
let p = document.createElement("mint-popover");
|
|
466
|
+
p.className = "mint-select-popover", p.setAttribute(r, "popover"), p.setAttribute("trigger-id", o.id), p.setAttribute("trigger-toggle", "false"), p.setAttribute("direction", "down"), p.setAttribute("trigger-align", "start"), p.setAttribute("align-selected", "true"), p.setAttribute("distance", "4"), p.setAttribute("padding", "0"), p.setAttribute("aria-label", n ? `${n} options` : "Select options");
|
|
467
|
+
let m = document.createElement("div");
|
|
468
|
+
m.className = "mint-select-options", m.id = `${i}-listbox`, m.setAttribute("role", "listbox"), m.setAttribute("aria-multiselectable", String(this.isMultiple())), o.setAttribute("aria-controls", m.id), p.append(m), this.append(p), this._popover = p, this._list = m, this.renderOptions(), this.updateDisplay(), this.bindEvents();
|
|
469
|
+
let h = this.getAttribute("info");
|
|
470
|
+
if (h) {
|
|
471
|
+
let e = document.createElement("div");
|
|
472
|
+
e.setAttribute(r, "info"), e.className = "mint-select-info", e.id = `${i}-info`, e.textContent = h, this.append(e);
|
|
473
|
+
}
|
|
474
|
+
let g = this.getAttribute("error-message");
|
|
475
|
+
if (this.hasError() && g) {
|
|
476
|
+
let e = document.createElement("div");
|
|
477
|
+
e.setAttribute(r, "error"), e.className = "mint-select-error", e.id = `${i}-error`, e.textContent = g, this.append(e);
|
|
478
|
+
}
|
|
479
|
+
this._syncing = !1;
|
|
480
|
+
}
|
|
481
|
+
renderOptions() {
|
|
482
|
+
this._list && (this._list.replaceChildren(), Array.from(this.children).filter((e) => e.tagName === "OPTION" || e.tagName === "OPTGROUP").forEach((e) => {
|
|
483
|
+
if (e instanceof HTMLOptGroupElement) {
|
|
484
|
+
let t = document.createElement("div");
|
|
485
|
+
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));
|
|
486
|
+
} else this.addOption(e, !1);
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
addOption(e, t) {
|
|
490
|
+
if (!this._list) return;
|
|
491
|
+
let n = document.createElement("button");
|
|
492
|
+
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;
|
|
493
|
+
let r = document.createElement("span");
|
|
494
|
+
r.textContent = e.label || e.textContent || "", n.append(r);
|
|
495
|
+
let i = document.createElement("mint-icon");
|
|
496
|
+
i.setAttribute("name", "check"), i.setAttribute("aria-hidden", "true"), i.className = "mint-select-option-check", n.append(i), this._list.append(n);
|
|
497
|
+
}
|
|
498
|
+
updateDisplay() {
|
|
499
|
+
if (!this._native || !this._trigger) return;
|
|
500
|
+
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");
|
|
501
|
+
r && (r.textContent = this.isMultiple() ? n.join(", ") || this.getAttribute("placeholder") || "Select an option" : 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)));
|
|
502
|
+
}
|
|
503
|
+
bindEvents() {
|
|
504
|
+
!this._trigger || !this._popover || !this._native || !this._list || (this._trigger.onclick = () => {
|
|
505
|
+
this._popover.style.setProperty("--mint-select-popover-width", `${this._trigger.getBoundingClientRect().width}px`), this._popover.hasAttribute("open") ? this._popover.close() : this._popover.open();
|
|
506
|
+
}, this._trigger.onkeydown = (e) => {
|
|
507
|
+
let t = Array.from(this._list.querySelectorAll("[role=\"option\"]:not(:disabled)"));
|
|
508
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
509
|
+
e.preventDefault(), this._popover.hasAttribute("open") || this._popover.open();
|
|
510
|
+
let n = t.findIndex((e) => e.dataset.value === (this.isMultiple() ? this.values[0] : this._native.value));
|
|
511
|
+
t[e.key === "ArrowDown" ? Math.min(t.length - 1, n + 1) : Math.max(0, n <= 0 ? 0 : n - 1)]?.focus();
|
|
512
|
+
} else if (e.key === "Enter" || e.key === " ") if (this._popover.hasAttribute("open")) {
|
|
513
|
+
e.preventDefault();
|
|
514
|
+
let t = this._list.querySelector("[role=\"option\"]:focus");
|
|
515
|
+
t ? this.selectOption(t.dataset.value || "") : this._popover.open();
|
|
516
|
+
} else e.key === " " && (e.preventDefault(), this._popover.open());
|
|
517
|
+
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);
|
|
518
|
+
}, this._list.onclick = (e) => {
|
|
519
|
+
let t = e.target.closest("[role=\"option\"]");
|
|
520
|
+
t && !t.disabled && this.selectOption(t.dataset.value || "");
|
|
521
|
+
}, this._list.onkeydown = (e) => {
|
|
522
|
+
let t = Array.from(this._list.querySelectorAll("[role=\"option\"]:not(:disabled)")), n = t.indexOf(e.target), r = n;
|
|
523
|
+
if (e.key === "ArrowDown") r = Math.min(t.length - 1, n + 1);
|
|
524
|
+
else if (e.key === "ArrowUp") r = Math.max(0, n - 1);
|
|
525
|
+
else if (e.key === "Home") r = 0;
|
|
526
|
+
else if (e.key === "End") r = t.length - 1;
|
|
527
|
+
else if (e.key === "Escape") {
|
|
528
|
+
e.preventDefault(), this._popover.close(), this._trigger.focus();
|
|
529
|
+
return;
|
|
530
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
531
|
+
e.preventDefault(), this.selectOption(e.target.dataset.value || "");
|
|
532
|
+
return;
|
|
533
|
+
} else if (e.key.length === 1) {
|
|
534
|
+
this.typeahead(e.key);
|
|
535
|
+
return;
|
|
536
|
+
} else return;
|
|
537
|
+
e.preventDefault(), t[r]?.focus();
|
|
538
|
+
}, this._native.onchange = () => {
|
|
539
|
+
this.isMultiple() ? this.setAttribute("values", JSON.stringify(this.values)) : this.setAttribute("value", this._native.value), this.updateDisplay(), this.dispatchSelectionEvents();
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
selectOption(e) {
|
|
543
|
+
if (this._native) {
|
|
544
|
+
if (this.isMultiple()) {
|
|
545
|
+
let t = new Set(this.values);
|
|
546
|
+
t.has(e) ? t.delete(e) : t.add(e);
|
|
547
|
+
let n = [...t];
|
|
548
|
+
this._applyValues(n), this.setAttribute("values", JSON.stringify(n)), this.updateDisplay(), this.dispatchSelectionEvents();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
this._native.value = e, this.setAttribute("value", e), this.updateDisplay(), this._popover?.close(), this._trigger?.focus(), this.dispatchSelectionEvents();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
dispatchSelectionEvents() {
|
|
555
|
+
let e = this.isMultiple() ? this.values : this._native?.value || "", t = this.isMultiple() ? {
|
|
556
|
+
value: e,
|
|
557
|
+
values: e
|
|
558
|
+
} : { value: e };
|
|
559
|
+
this.dispatchEvent(new CustomEvent("input", {
|
|
560
|
+
bubbles: !0,
|
|
561
|
+
composed: !0,
|
|
562
|
+
detail: t
|
|
563
|
+
})), this.dispatchEvent(new CustomEvent("change", {
|
|
564
|
+
bubbles: !0,
|
|
565
|
+
composed: !0,
|
|
566
|
+
detail: t
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
typeahead(e) {
|
|
570
|
+
this._typeahead += e.toLocaleLowerCase(), this._typeaheadTimer !== null && window.clearTimeout(this._typeaheadTimer), this._typeaheadTimer = window.setTimeout(() => {
|
|
571
|
+
this._typeahead = "";
|
|
572
|
+
}, 700);
|
|
573
|
+
let t = Array.from(this._list?.querySelectorAll("[role=\"option\"]:not(:disabled)") || []).find((e) => e.textContent?.trim().toLocaleLowerCase().startsWith(this._typeahead));
|
|
574
|
+
t && (this._popover?.hasAttribute("open") || this._popover?.open(), t.focus());
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
customElements.get("mint-select") || e("mint-select", i);
|
|
284
578
|
//#endregion
|
|
285
|
-
export { n as default };
|
|
579
|
+
export { n as NativeSelect, i as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../chunks/icon-rvYvpQ_h.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-CG0Dhtew.js`),require(`../chunks/caret-up-DzrY-bTy.js`),require(`../chunks/caret-down-DGeJj0xv.js`);var t=`data-mint-select-part`,n=class extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null,this._hostOptionsObserverRaf=null,this._generatedControlId=`mint-select-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-select-host`),this.getLabel()||console.error(`mint-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=>{if(e.some(e=>{let t=e.target;if(this._select&&(t===this._select||this._select.contains(t)))return!1;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`);return n||r})){if(this._hostOptionsObserverRaf!==null)return;this._hostOptionsObserverRaf=requestAnimationFrame(()=>{this._hostOptionsObserverRaf=null,this.isConnected&&this.render()})}}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){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)}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._syncSelectAccessibility());return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){let e=this.getAttribute(`disabled`);return e!==null&&e!==`false`}isMultiple(){let e=this.getAttribute(`multiple`);return e!==null&&e!==`false`}isRequired(){let e=this.getAttribute(`required`);return e!==null&&e!==`false`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){return[`mint-select-control`,this.isMultiple()?`is-multiple`:``,this.hasError()?`has-error`:``].filter(Boolean).join(` `)}render(){this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null);let e=this.isLoading(),n=this.isMultiple(),r=this.getValue(),i=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&i.push(e.cloneNode(!0))}),Array.from(this.children).forEach(e=>{e instanceof HTMLElement&&e.hasAttribute(t)&&e.remove()}),this._wrapper=null,this._select=null;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();if(o){let e=document.createElement(`label`);e.setAttribute(t,`label`),e.className=`mint-select-label`,c&&e.setAttribute(`for`,c);let n=document.createTextNode(o);e.appendChild(n),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t,`wrapper`),this._wrapper.className=`mint-select-control-wrap`,this.appendChild(this._wrapper),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`);let f=this.getAttribute(`aria-label`)?.trim(),p=this.getAttribute(`aria-labelledby`)?.trim();p?this._select.setAttribute(`aria-labelledby`,p):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,f||`Select an option`);let m=a.length>0?a:i;if(m.length>0&&m.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(n){let e=[];try{let t=r?JSON.parse(r):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=r?[String(r)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=r||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let t=e.target,r=n?Array.from(t.selectedOptions).map(e=>e.value):t.value,i=n?JSON.stringify(r):String(r||``);(this.getAttribute(`value`)||``)!==i&&(i?this.setAttribute(`value`,i):this.removeAttribute(`value`));let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(n){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),n)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);e.className=`mint-select-caret`,this._caretUpIcon=document.createElement(`mint-icon`),this._caretUpIcon.setAttribute(`name`,`caret-up`),this._caretUpIcon.className=`mint-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-select-caret-down`,this._caretDownIcon.setAttribute(`aria-hidden`,`true`),e.appendChild(this._caretDownIcon),this._wrapper.appendChild(e)}if(s){let e=document.createElement(`div`);e.setAttribute(t,`info`),e.className=`mint-select-info`,e.textContent=s,this.appendChild(e)}this._renderErrorState(),this._syncSelectAccessibility(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-select-skeleton-container`,t.setAttribute(`aria-hidden`,`true`),n?n.appendChild(t):this.appendChild(t));let e=t.querySelector(`.mint-select-skeleton`);e||(e=document.createElement(`div`),t.appendChild(e));let r=this.isMultiple();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`))}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`,this._select.removeAttribute(`aria-busy`))}_renderErrorState(){let e=this.hasError(),n=this.getErrorMessage(),r=this.querySelector(`.mint-select-error`);e&&n?(r?r.hasAttribute(t)||r.setAttribute(t,`error`):(r=document.createElement(`div`),r.setAttribute(t,`error`),r.className=`mint-select-error`,this.appendChild(r)),r.textContent=n):r&&r.remove()}_syncSelectAccessibility(){if(!this._select)return;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-select-error`);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`)}};customElements.get(`mint-select`)||e.t(`mint-select`,n),module.exports=n;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-rvYvpQ_h.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-CG0Dhtew.js`),require(`../chunks/popover-wGdggZ-a.js`);var t=`data-mint-native-select-part`,n=class extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._select=null,this._wrapper=null,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)}`}connectedCallback(){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=>{if(e.some(e=>{let t=e.target;if(this._select&&(t===this._select||this._select.contains(t)))return!1;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`);return n||r})){if(this._hostOptionsObserverRaf!==null)return;this._hostOptionsObserverRaf=requestAnimationFrame(()=>{this._hostOptionsObserverRaf=null,this.isConnected&&this.render()})}}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){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)}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._syncSelectAccessibility());return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){let e=this.getAttribute(`disabled`);return e!==null&&e!==`false`}isMultiple(){let e=this.getAttribute(`multiple`);return e!==null&&e!==`false`}isRequired(){let e=this.getAttribute(`required`);return e!==null&&e!==`false`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){return[`mint-native-select-control`,this.isMultiple()?`is-multiple`:``,this.hasError()?`has-error`:``].filter(Boolean).join(` `)}render(){this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null);let e=this.isLoading(),n=this.isMultiple(),r=this.getValue(),i=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&i.push(e.cloneNode(!0))}),Array.from(this.children).forEach(e=>{e instanceof HTMLElement&&e.hasAttribute(t)&&e.remove()}),this._wrapper=null,this._select=null;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();if(o){let e=document.createElement(`label`);e.setAttribute(t,`label`),e.className=`mint-native-select-label`,c&&e.setAttribute(`for`,c);let n=document.createTextNode(o);e.appendChild(n),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t,`wrapper`),this._wrapper.className=`mint-native-select-control-wrap`,this.appendChild(this._wrapper),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`);let f=this.getAttribute(`aria-label`)?.trim(),p=this.getAttribute(`aria-labelledby`)?.trim();p?this._select.setAttribute(`aria-labelledby`,p):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,f||`Select an option`);let m=a.length>0?a:i;if(m.length>0&&m.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(n){let e=[];try{let t=r?JSON.parse(r):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=r?[String(r)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=r||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let t=e.target,r=n?Array.from(t.selectedOptions).map(e=>e.value):t.value,i=n?JSON.stringify(r):String(r||``);(this.getAttribute(`value`)||``)!==i&&(i?this.setAttribute(`value`,i):this.removeAttribute(`value`));let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(n){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),n)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);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),this._wrapper.appendChild(e)}if(s){let e=document.createElement(`div`);e.setAttribute(t,`info`),e.className=`mint-native-select-info`,e.textContent=s,this.appendChild(e)}this._renderErrorState(),this._syncSelectAccessibility(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-native-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-native-select-skeleton-container`,t.setAttribute(`aria-hidden`,`true`),n?n.appendChild(t):this.appendChild(t));let e=t.querySelector(`.mint-native-select-skeleton`);e||(e=document.createElement(`div`),t.appendChild(e));let r=this.isMultiple();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`))}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`,this._select.removeAttribute(`aria-busy`))}_renderErrorState(){let e=this.hasError(),n=this.getErrorMessage(),r=this.querySelector(`.mint-native-select-error`);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()}_syncSelectAccessibility(){if(!this._select)return;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`);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`)}};customElements.get(`mint-native-select`)||e.t(`mint-native-select`,n);var r=`data-mint-select-part`,i=class extends HTMLElement{constructor(...e){super(...e),this._native=null,this._trigger=null,this._popover=null,this._list=null,this._observer=null,this._syncing=!1,this._typeahead=``,this._typeaheadTimer=null,this._id=`mint-select-${Math.random().toString(36).slice(2,10)}`}static get observedAttributes(){return[`name`,`value`,`values`,`multiple`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`loading`,`placeholder`,`aria-label`,`aria-labelledby`,`aria-describedby`,`form`]}connectedCallback(){this.classList.add(`mint-select-host`),this.render(),this._observer?.disconnect(),this._observer=new MutationObserver(e=>{this._syncing||e.some(e=>{let t=e.target instanceof Element?e.target:e.target.parentElement;return t===this||t?.closest(`[${r}]`)?!1:e.type===`attributes`?[`value`,`label`,`disabled`,`selected`].includes(e.attributeName):t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement||[...e.addedNodes,...e.removedNodes].some(e=>e instanceof HTMLOptionElement||e instanceof HTMLOptGroupElement)})&&this.render()}),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`label`,`disabled`,`selected`]})}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer)}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`values`&&this._native&&this.isMultiple()){this._applyValues(this.parseValues(n)),this.updateDisplay();return}if(e===`multiple`&&this._native){this.render();return}if(e===`value`&&this._native){this.isMultiple()?this._applyValues(n?[n]:[]):this._native.value=n||``,this.updateDisplay();return}this.render()}}get value(){return this.isMultiple()?this.values:this._native?.value||this.getAttribute(`value`)||``}set value(e){this.setValue(e)}get values(){return this._native&&this.isMultiple()?Array.from(this._native.selectedOptions,e=>e.value):this.parseValues(this.getAttribute(`values`))}set values(e){this.setValue(e)}getValue(){return this.value}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(String):e==null||e===``?[]:[String(e)];this.setAttribute(`values`,JSON.stringify(t)),this._applyValues(t)}else{let t=e==null?``:String(e);this.setAttribute(`value`,t),this._native&&(this._native.value=t)}this.updateDisplay()}isDisabled(){return this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}isRequired(){return this.hasAttribute(`required`)&&this.getAttribute(`required`)!==`false`}isMultiple(){return this.hasAttribute(`multiple`)&&this.getAttribute(`multiple`)!==`false`}hasError(){return this.getAttribute(`error`)===`true`}parseValues(e){if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t)){if(t.length===1&&typeof t[0]==`string`&&t[0].trim().startsWith(`[`))try{let e=JSON.parse(t[0]);if(Array.isArray(e))return e.map(String)}catch{}return t.map(String)}}catch{}return[e]}_applyValues(e){if(!this._native)return;let t=new Set(e);Array.from(this._native.options).forEach(e=>{e.selected=t.has(e.value)})}options(){return Array.from(this.querySelectorAll(`:scope > option, :scope > optgroup > option`))}selectedOption(){return this._native?.selectedOptions[0]||this.options().find(e=>e.value===this.value)}render(){let e=this._native?.value??this.getAttribute(`value`)??``,t=this._native&&this._native.multiple?Array.from(this._native.selectedOptions,e=>e.value):this.parseValues(this.getAttribute(`values`));this._syncing=!0,Array.from(this.children).forEach(e=>{e.hasAttribute(r)&&e.remove()});let n=this.getAttribute(`label`)?.trim()||``,i=this.getAttribute(`id`)||this._id;if(n){let e=document.createElement(`label`);e.setAttribute(r,`label`),e.className=`mint-select-label`,e.htmlFor=`${i}-trigger`,e.textContent=n,this.append(e)}let a=document.createElement(`div`);a.setAttribute(r,`wrap`),a.className=`mint-select-control-wrap`,this.append(a);let o=document.createElement(`button`);o.type=`button`,o.id=`${i}-trigger`,o.className=`mint-select-trigger`,o.disabled=this.isDisabled()||this.isLoading(),o.setAttribute(`role`,`combobox`),o.setAttribute(`aria-busy`,String(this.isLoading())),o.setAttribute(`aria-haspopup`,`listbox`),o.setAttribute(`aria-expanded`,`false`),o.setAttribute(`aria-required`,String(this.isRequired())),o.setAttribute(`aria-invalid`,String(this.hasError()));let s=this.getAttribute(`aria-labelledby`),c=this.getAttribute(`aria-label`)?.trim();if(s?o.setAttribute(`aria-labelledby`,s):!n&&c?o.setAttribute(`aria-label`,c):n&&o.setAttribute(`aria-labelledby`,`${i}-label`),n){let e=this.querySelector(`[${r}="label"]`);e&&(e.id=`${i}-label`)}let l=document.createElement(`span`);l.className=`mint-select-value`,o.append(l);let u=document.createElement(`span`);u.className=`mint-select-caret`,u.setAttribute(`aria-hidden`,`true`),u.innerHTML=`<mint-icon name="caret-up"></mint-icon><mint-icon name="caret-down"></mint-icon>`,o.append(u),a.append(o);let d=document.createElement(`select`);d.setAttribute(r,`native`),d.className=`mint-select-native-control`,d.id=`${i}-native`,d.name=this.getAttribute(`name`)||``,d.multiple=this.isMultiple(),this.hasAttribute(`form`)&&d.setAttribute(`form`,this.getAttribute(`form`)||``),d.required=this.isRequired(),d.disabled=this.isDisabled(),d.tabIndex=-1,d.setAttribute(`aria-hidden`,`true`),d.setAttribute(`aria-invalid`,String(this.hasError()));let f=[this.getAttribute(`aria-describedby`),n?`${i}-label`:``,this.getAttribute(`info`)?`${i}-info`:``,this.getAttribute(`error-message`)?`${i}-error`:``].filter(Boolean).join(` `);if(f&&d.setAttribute(`aria-describedby`,f),this.options().forEach(e=>d.append(e.cloneNode(!0))),!d.options.length){let e=document.createElement(`option`);e.value=``,e.textContent=this.getAttribute(`placeholder`)||`Select an option`,e.disabled=!0,d.append(e)}if(d.multiple){let n=t.length?t:this.parseValues(this.getAttribute(`values`)).length?this.parseValues(this.getAttribute(`values`)):e?[e]:[];n.length&&Array.from(d.options).forEach(e=>{e.selected=n.includes(e.value)})}else d.value=e;a.append(d),this._native=d,this._trigger=o;let p=document.createElement(`mint-popover`);p.className=`mint-select-popover`,p.setAttribute(r,`popover`),p.setAttribute(`trigger-id`,o.id),p.setAttribute(`trigger-toggle`,`false`),p.setAttribute(`direction`,`down`),p.setAttribute(`trigger-align`,`start`),p.setAttribute(`align-selected`,`true`),p.setAttribute(`distance`,`4`),p.setAttribute(`padding`,`0`),p.setAttribute(`aria-label`,n?`${n} options`:`Select options`);let m=document.createElement(`div`);m.className=`mint-select-options`,m.id=`${i}-listbox`,m.setAttribute(`role`,`listbox`),m.setAttribute(`aria-multiselectable`,String(this.isMultiple())),o.setAttribute(`aria-controls`,m.id),p.append(m),this.append(p),this._popover=p,this._list=m,this.renderOptions(),this.updateDisplay(),this.bindEvents();let h=this.getAttribute(`info`);if(h){let e=document.createElement(`div`);e.setAttribute(r,`info`),e.className=`mint-select-info`,e.id=`${i}-info`,e.textContent=h,this.append(e)}let g=this.getAttribute(`error-message`);if(this.hasError()&&g){let e=document.createElement(`div`);e.setAttribute(r,`error`),e.className=`mint-select-error`,e.id=`${i}-error`,e.textContent=g,this.append(e)}this._syncing=!1}renderOptions(){this._list&&(this._list.replaceChildren(),Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).forEach(e=>{if(e instanceof HTMLOptGroupElement){let t=document.createElement(`div`);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))}else this.addOption(e,!1)}))}addOption(e,t){if(!this._list)return;let n=document.createElement(`button`);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;let r=document.createElement(`span`);r.textContent=e.label||e.textContent||``,n.append(r);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`check`),i.setAttribute(`aria-hidden`,`true`),i.className=`mint-select-option-check`,n.append(i),this._list.append(n)}updateDisplay(){if(!this._native||!this._trigger)return;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`);r&&(r.textContent=this.isMultiple()?n.join(`, `)||this.getAttribute(`placeholder`)||`Select an option`: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)))}bindEvents(){!this._trigger||!this._popover||!this._native||!this._list||(this._trigger.onclick=()=>{this._popover.style.setProperty(`--mint-select-popover-width`,`${this._trigger.getBoundingClientRect().width}px`),this._popover.hasAttribute(`open`)?this._popover.close():this._popover.open()},this._trigger.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),this._popover.hasAttribute(`open`)||this._popover.open();let n=t.findIndex(e=>e.dataset.value===(this.isMultiple()?this.values[0]:this._native.value));t[e.key===`ArrowDown`?Math.min(t.length-1,n+1):Math.max(0,n<=0?0:n-1)]?.focus()}else if(e.key===`Enter`||e.key===` `)if(this._popover.hasAttribute(`open`)){e.preventDefault();let t=this._list.querySelector(`[role="option"]:focus`);t?this.selectOption(t.dataset.value||``):this._popover.open()}else e.key===` `&&(e.preventDefault(),this._popover.open());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)},this._list.onclick=e=>{let t=e.target.closest(`[role="option"]`);t&&!t.disabled&&this.selectOption(t.dataset.value||``)},this._list.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`)),n=t.indexOf(e.target),r=n;if(e.key===`ArrowDown`)r=Math.min(t.length-1,n+1);else if(e.key===`ArrowUp`)r=Math.max(0,n-1);else if(e.key===`Home`)r=0;else if(e.key===`End`)r=t.length-1;else if(e.key===`Escape`){e.preventDefault(),this._popover.close(),this._trigger.focus();return}else if(e.key===`Enter`||e.key===` `){e.preventDefault(),this.selectOption(e.target.dataset.value||``);return}else if(e.key.length===1){this.typeahead(e.key);return}else return;e.preventDefault(),t[r]?.focus()},this._native.onchange=()=>{this.isMultiple()?this.setAttribute(`values`,JSON.stringify(this.values)):this.setAttribute(`value`,this._native.value),this.updateDisplay(),this.dispatchSelectionEvents()})}selectOption(e){if(this._native){if(this.isMultiple()){let t=new Set(this.values);t.has(e)?t.delete(e):t.add(e);let n=[...t];this._applyValues(n),this.setAttribute(`values`,JSON.stringify(n)),this.updateDisplay(),this.dispatchSelectionEvents();return}this._native.value=e,this.setAttribute(`value`,e),this.updateDisplay(),this._popover?.close(),this._trigger?.focus(),this.dispatchSelectionEvents()}}dispatchSelectionEvents(){let e=this.isMultiple()?this.values:this._native?.value||``,t=this.isMultiple()?{value:e,values:e}:{value:e};this.dispatchEvent(new CustomEvent(`input`,{bubbles:!0,composed:!0,detail:t})),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:t}))}typeahead(e){this._typeahead+=e.toLocaleLowerCase(),this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=window.setTimeout(()=>{this._typeahead=``},700);let t=Array.from(this._list?.querySelectorAll(`[role="option"]:not(:disabled)`)||[]).find(e=>e.textContent?.trim().toLocaleLowerCase().startsWith(this._typeahead));t&&(this._popover?.hasAttribute(`open`)||this._popover?.open(),t.focus())}};customElements.get(`mint-select`)||e.t(`mint-select`,i),exports.NativeSelect=n,exports.default=i;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import './styles.css';
|
|
2
2
|
import '../icon/index.ts';
|
|
3
|
-
import '../
|
|
4
|
-
import '
|
|
3
|
+
import '../popover/index.ts';
|
|
4
|
+
import './NativeSelect';
|
|
5
5
|
import './Select';
|
|
6
6
|
export { default } from './Select';
|
|
7
|
+
export { default as NativeSelect } from './NativeSelect';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/select/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AACrB,OAAO,kBAAkB,CAAA;AACzB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/select/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AACrB,OAAO,kBAAkB,CAAA;AACzB,OAAO,qBAAqB,CAAA;AAC5B,OAAO,gBAAgB,CAAA;AACvB,OAAO,UAAU,CAAA;AAEjB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
|