@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
704 lines (703 loc) • 31.7 kB
JavaScript
import { P as ke, t as g, n as d } from "./element-CgEWt74-.js";
import { r as Ve } from "./state-Bo2bck5_.js";
import { u as Fe } from "./stringutils-DJjRa8dG.js";
import { s as Ce } from "./input-wrapper-8iKEzDRZ.js";
(function() {
(function(M) {
const s = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), L = {
ariaAtomic: "aria-atomic",
ariaAutoComplete: "aria-autocomplete",
ariaBusy: "aria-busy",
ariaChecked: "aria-checked",
ariaColCount: "aria-colcount",
ariaColIndex: "aria-colindex",
ariaColIndexText: "aria-colindextext",
ariaColSpan: "aria-colspan",
ariaCurrent: "aria-current",
ariaDescription: "aria-description",
ariaDisabled: "aria-disabled",
ariaExpanded: "aria-expanded",
ariaHasPopup: "aria-haspopup",
ariaHidden: "aria-hidden",
ariaInvalid: "aria-invalid",
ariaKeyShortcuts: "aria-keyshortcuts",
ariaLabel: "aria-label",
ariaLevel: "aria-level",
ariaLive: "aria-live",
ariaModal: "aria-modal",
ariaMultiLine: "aria-multiline",
ariaMultiSelectable: "aria-multiselectable",
ariaOrientation: "aria-orientation",
ariaPlaceholder: "aria-placeholder",
ariaPosInSet: "aria-posinset",
ariaPressed: "aria-pressed",
ariaReadOnly: "aria-readonly",
ariaRelevant: "aria-relevant",
ariaRequired: "aria-required",
ariaRoleDescription: "aria-roledescription",
ariaRowCount: "aria-rowcount",
ariaRowIndex: "aria-rowindex",
ariaRowIndexText: "aria-rowindextext",
ariaRowSpan: "aria-rowspan",
ariaSelected: "aria-selected",
ariaSetSize: "aria-setsize",
ariaSort: "aria-sort",
ariaValueMax: "aria-valuemax",
ariaValueMin: "aria-valuemin",
ariaValueNow: "aria-valuenow",
ariaValueText: "aria-valuetext",
role: "role"
}, oe = (t, e) => {
for (let i in L) {
e[i] = null;
let a = null;
const r = L[i];
Object.defineProperty(e, i, {
get() {
return a;
},
set(n) {
a = n, t.isConnected ? k(t, r, n) : F.set(t, e);
}
});
}
};
function K(t) {
const e = u.get(t), { form: i } = e;
Y(t, i, e), X(t, e.labels);
}
const j = (t, e = !1) => {
const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
acceptNode(n) {
return u.has(n) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
}
});
let a = i.nextNode();
const r = !e || t.disabled;
for (; a; )
a.formDisabledCallback && r && W(a, t.disabled), a = i.nextNode();
}, G = { attributes: !0, attributeFilter: ["disabled", "name"] }, N = D() ? new MutationObserver((t) => {
for (const e of t) {
const i = e.target;
if (e.attributeName === "disabled" && (i.constructor.formAssociated ? W(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && j(i)), e.attributeName === "name" && i.constructor.formAssociated) {
const a = u.get(i), r = T.get(i);
a.setFormValue(r);
}
}
}) : {};
function P(t) {
t.forEach((e) => {
const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), n = Array.from(a);
r.forEach((o) => {
var m;
if (u.has(o) && o.constructor.formAssociated && K(o), F.has(o)) {
const f = F.get(o);
Object.keys(L).filter((v) => f[v] !== null).forEach((v) => {
k(o, L[v], f[v]);
}), F.delete(o);
}
if (I.has(o)) {
const f = I.get(o);
k(o, "internals-valid", f.validity.valid.toString()), k(o, "internals-invalid", (!f.validity.valid).toString()), k(o, "aria-invalid", (!f.validity.valid).toString()), I.delete(o);
}
if (o.localName === "form") {
const f = b.get(o), E = document.createTreeWalker(o, NodeFilter.SHOW_ELEMENT, {
acceptNode($) {
return u.has($) && $.constructor.formAssociated && !(f && f.has($)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
}
});
let v = E.nextNode();
for (; v; )
K(v), v = E.nextNode();
}
o.localName === "fieldset" && ((m = N.observe) === null || m === void 0 || m.call(N, o, G), j(o, !0));
}), n.forEach((o) => {
const m = u.get(o);
m && p.get(m) && J(m), C.has(o) && C.get(o).disconnect();
});
});
}
function le(t) {
t.forEach((e) => {
const { removedNodes: i } = e;
i.forEach((a) => {
const r = U.get(e.target);
u.has(a) && ee(a), r.disconnect();
});
});
}
const ce = (t) => {
var e, i;
const a = new MutationObserver(le);
!((e = window == null ? void 0 : window.ShadyDOM) === null || e === void 0) && e.inUse && t.mode && t.host && (t = t.host), (i = a.observe) === null || i === void 0 || i.call(a, t, { childList: !0 }), U.set(t, a);
};
D() && new MutationObserver(P);
const H = {
childList: !0,
subtree: !0
}, k = (t, e, i) => {
t.getAttribute(e) !== i && t.setAttribute(e, i);
}, W = (t, e) => {
t.toggleAttribute("internals-disabled", e), e ? k(t, "aria-disabled", "true") : t.removeAttribute("aria-disabled"), t.formDisabledCallback && t.formDisabledCallback.apply(t, [e]);
}, J = (t) => {
p.get(t).forEach((i) => {
i.remove();
}), p.set(t, []);
}, Q = (t, e) => {
const i = document.createElement("input");
return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i), p.get(e).push(i), i;
}, de = (t, e) => {
var i;
p.set(e, []), (i = N.observe) === null || i === void 0 || i.call(N, t, G);
}, X = (t, e) => {
if (e.length) {
Array.from(e).forEach((a) => a.addEventListener("click", t.click.bind(t)));
let i = e[0].id;
e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), k(t, "aria-labelledby", i);
}
}, R = (t) => {
const e = Array.from(t.elements).filter((n) => !n.tagName.includes("-") && n.validity).map((n) => n.validity.valid), i = b.get(t) || [], a = Array.from(i).filter((n) => n.isConnected).map((n) => u.get(n).validity.valid), r = [...e, ...a].includes(!1);
t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
}, he = (t) => {
R(O(t.target));
}, ue = (t) => {
R(O(t.target));
}, fe = (t) => {
const e = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${t.id ? `,${i}[form='${t.id}']` : ""}`).join(",");
t.addEventListener("click", (i) => {
if (i.target.closest(e)) {
const r = b.get(t);
if (t.noValidate)
return;
r.size && Array.from(r).reverse().map((m) => u.get(m).reportValidity()).includes(!1) && i.preventDefault();
}
});
}, pe = (t) => {
const e = b.get(t.target);
e && e.size && e.forEach((i) => {
i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
});
}, Y = (t, e, i) => {
if (e) {
const a = b.get(e);
if (a)
a.add(t);
else {
const r = /* @__PURE__ */ new Set();
r.add(t), b.set(e, r), fe(e), e.addEventListener("reset", pe), e.addEventListener("input", he), e.addEventListener("change", ue);
}
V.set(e, { ref: t, internals: i }), t.constructor.formAssociated && t.formAssociatedCallback && setTimeout(() => {
t.formAssociatedCallback.apply(t, [e]);
}, 0), R(e);
}
}, O = (t) => {
let e = t.parentNode;
return e && e.tagName !== "FORM" && (e = O(e)), e;
}, w = (t, e, i = DOMException) => {
if (!t.constructor.formAssociated)
throw new i(e);
}, Z = (t, e, i) => {
const a = b.get(t);
return a && a.size && a.forEach((r) => {
u.get(r)[i]() || (e = !1);
}), e;
}, ee = (t) => {
if (t.constructor.formAssociated) {
const e = u.get(t), { labels: i, form: a } = e;
X(t, i), Y(t, a, e);
}
};
function D() {
return typeof MutationObserver < "u";
}
class me {
constructor() {
this.badInput = !1, this.customError = !1, this.patternMismatch = !1, this.rangeOverflow = !1, this.rangeUnderflow = !1, this.stepMismatch = !1, this.tooLong = !1, this.tooShort = !1, this.typeMismatch = !1, this.valid = !0, this.valueMissing = !1, Object.seal(this);
}
}
const ye = (t) => (t.badInput = !1, t.customError = !1, t.patternMismatch = !1, t.rangeOverflow = !1, t.rangeUnderflow = !1, t.stepMismatch = !1, t.tooLong = !1, t.tooShort = !1, t.typeMismatch = !1, t.valid = !0, t.valueMissing = !1, t), ge = (t, e, i) => (t.valid = be(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && R(i), t), be = (t) => {
let e = !0;
for (let i in t)
i !== "valid" && t[i] !== !1 && (e = !1);
return e;
}, B = /* @__PURE__ */ new WeakMap();
function te(t, e) {
t.toggleAttribute(e, !0), t.part && t.part.add(e);
}
class _ extends Set {
static get isPolyfilled() {
return !0;
}
constructor(e) {
if (super(), !e || !e.tagName || e.tagName.indexOf("-") === -1)
throw new TypeError("Illegal constructor");
B.set(this, e);
}
add(e) {
if (!/^--/.test(e) || typeof e != "string")
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${e} must start with '--'.`);
const i = super.add(e), a = B.get(this), r = `state${e}`;
return a.isConnected ? te(a, r) : setTimeout(() => {
te(a, r);
}), i;
}
clear() {
for (let [e] of this.entries())
this.delete(e);
super.clear();
}
delete(e) {
const i = super.delete(e), a = B.get(this);
return a.isConnected ? (a.toggleAttribute(`state${e}`, !1), a.part && a.part.remove(`state${e}`)) : setTimeout(() => {
a.toggleAttribute(`state${e}`, !1), a.part && a.part.remove(`state${e}`);
}), i;
}
}
function ie(t, e, i, a) {
if (typeof e == "function" ? t !== e || !0 : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return i === "m" ? a : i === "a" ? a.call(t) : a ? a.value : e.get(t);
}
function ve(t, e, i, a, r) {
if (typeof e == "function" ? t !== e || !0 : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return e.set(t, i), i;
}
var x;
class we {
constructor(e) {
x.set(this, void 0), ve(this, x, e);
for (let i = 0; i < e.length; i++) {
let a = e[i];
this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
}
Object.freeze(this);
}
get length() {
return ie(this, x, "f").length;
}
[(x = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
return ie(this, x, "f")[Symbol.iterator]();
}
item(e) {
return this[e] == null ? null : this[e];
}
namedItem(e) {
return this[e] == null ? null : this[e];
}
}
function Ee() {
const t = HTMLFormElement.prototype.checkValidity;
HTMLFormElement.prototype.checkValidity = i;
const e = HTMLFormElement.prototype.reportValidity;
HTMLFormElement.prototype.reportValidity = a;
function i(...n) {
let o = t.apply(this, n);
return Z(this, o, "checkValidity");
}
function a(...n) {
let o = e.apply(this, n);
return Z(this, o, "reportValidity");
}
const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
Object.defineProperty(HTMLFormElement.prototype, "elements", {
get(...n) {
const o = r.call(this, ...n), m = Array.from(b.get(this) || []);
if (m.length === 0)
return o;
const f = Array.from(o).concat(m).sort((E, v) => E.compareDocumentPosition ? E.compareDocumentPosition(v) & 2 ? 1 : -1 : 0);
return new we(f);
}
});
}
class ae {
static get isPolyfilled() {
return !0;
}
constructor(e) {
if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
throw new TypeError("Illegal constructor");
const i = e.getRootNode(), a = new me();
this.states = new _(e), s.set(this, e), h.set(this, a), u.set(e, this), oe(e, this), de(e, this), Object.seal(this), i instanceof DocumentFragment && ce(i);
}
checkValidity() {
const e = s.get(this);
if (w(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
return !0;
const i = h.get(this);
if (!i.valid) {
const a = new Event("invalid", {
bubbles: !1,
cancelable: !0,
composed: !1
});
e.dispatchEvent(a);
}
return i.valid;
}
get form() {
const e = s.get(this);
w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
let i;
return e.constructor.formAssociated === !0 && (i = O(e)), i;
}
get labels() {
const e = s.get(this);
w(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
const i = e.getAttribute("id"), a = e.getRootNode();
return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
}
reportValidity() {
const e = s.get(this);
if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
return !0;
const i = this.checkValidity(), a = A.get(this);
if (a && !e.constructor.formAssociated)
throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
return !i && a && (e.focus(), a.focus()), i;
}
setFormValue(e) {
const i = s.get(this);
if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), J(this), e != null && !(e instanceof FormData)) {
if (i.getAttribute("name")) {
const a = Q(i, this);
a.value = e;
}
} else e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
if (typeof r == "string") {
const n = Q(i, this);
n.name = a, n.value = r;
}
});
T.set(i, e);
}
setValidity(e, i, a) {
const r = s.get(this);
if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
A.set(this, a);
const n = h.get(this), o = {};
for (const E in e)
o[E] = e[E];
Object.keys(o).length === 0 && ye(n);
const m = Object.assign(Object.assign({}, n), o);
delete m.valid;
const { valid: f } = ge(n, m, this.form);
if (!f && !i)
throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
y.set(this, f ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !f), r.toggleAttribute("internals-valid", f), k(r, "aria-invalid", `${!f}`)) : I.set(r, this);
}
get shadowRoot() {
const e = s.get(this), i = S.get(e);
return i || null;
}
get validationMessage() {
const e = s.get(this);
return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), y.get(this);
}
get validity() {
const e = s.get(this);
return w(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), h.get(this);
}
get willValidate() {
const e = s.get(this);
return w(e, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(e.disabled || e.hasAttribute("disabled") || e.hasAttribute("readonly"));
}
}
function Me() {
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
return !1;
class t extends HTMLElement {
constructor() {
super(), this.internals = this.attachInternals();
}
}
const e = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, "")}`;
customElements.define(e, t);
const i = new t();
return [
"shadowRoot",
"form",
"willValidate",
"validity",
"validationMessage",
"labels",
"setFormValue",
"setValidity",
"checkValidity",
"reportValidity"
].every((a) => a in i.internals);
}
let se = !1, re = !1;
function q(t) {
re || (re = !0, window.CustomStateSet = _, t && (HTMLElement.prototype.attachInternals = function(...e) {
const i = t.call(this, e);
return i.states = new _(this), i;
}));
}
function ne(t = !0) {
if (!se) {
if (se = !0, typeof window < "u" && (window.ElementInternals = ae), typeof CustomElementRegistry < "u") {
const e = CustomElementRegistry.prototype.define;
CustomElementRegistry.prototype.define = function(i, a, r) {
if (a.formAssociated) {
const n = a.prototype.connectedCallback;
a.prototype.connectedCallback = function() {
z.has(this) || (z.set(this, !0), this.hasAttribute("disabled") && W(this, !0)), n != null && n.apply(this), ee(this);
};
}
e.call(this, i, a, r);
};
}
if (typeof HTMLElement < "u" && (HTMLElement.prototype.attachInternals = function() {
if (this.tagName) {
if (this.tagName.indexOf("-") === -1)
throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
} else return {};
if (u.has(this))
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
return new ae(this);
}), typeof Element < "u") {
let e = function(...a) {
const r = i.apply(this, a);
if (S.set(this, r), D()) {
const n = new MutationObserver(P);
window.ShadyDOM ? n.observe(this, H) : n.observe(r, H), C.set(this, n);
}
return r;
};
const i = Element.prototype.attachShadow;
Element.prototype.attachShadow = e;
}
D() && typeof document < "u" && new MutationObserver(P).observe(document.documentElement, H), typeof HTMLFormElement < "u" && Ee(), (t || typeof window < "u" && !window.CustomStateSet) && q();
}
}
return !!customElements.polyfillWrapFlushCallback || (Me() ? typeof window < "u" && !window.CustomStateSet && q(HTMLElement.prototype.attachInternals) : ne(!1)), M.forceCustomStateSetPolyfill = q, M.forceElementInternalsPolyfill = ne, Object.defineProperty(M, "__esModule", { value: !0 }), M;
})({});
})();
var Te = Object.defineProperty, l = (M, s, h, p) => {
for (var u = void 0, y = M.length - 1, V; y >= 0; y--)
(V = M[y]) && (u = V(s, h, u) || u);
return u && Te(s, h, u), u;
};
class c extends ke {
constructor() {
super(), this.defaultValue = null, this.disabled = !1, this.readonly = !1, this.required = !1, this.max = null, this.maxlength = null, this.min = null, this.minlength = null, this.step = null, this.ariaDescribedBy = null, this.ariaLabelledby = null, this.name = "", this.pattern = null, this.placeholder = null, this.id = Fe(), this.counter = !1, this.hasError = !1, this.inline = !1, this.hasFieldset = !1, this.optionalTag = !1, this.requiredTag = !1, this.skipForwardTestid = !1, this.useWrapper = !0, this.fullwidth = !1, this.counterMaxLength = 0, this.errorMessage = "", this.helptext = "", this.helptextDropdown = "", this.helptextDropdownButton = Ce.props.helptextDropdownButton.default, this.label = null, this.optionalText = g.forms.labels.optional, this.requiredText = g.forms.labels.required, this.tagText = null, this.dataTestid = "", this.touched = !1, this.internals = this.attachInternals();
}
static get formAssociated() {
return !0;
}
manageValidity(s) {
var h, p, u, y, V, C, b, T, F, S, A;
s && (this.required && !this.value ? this.internals.setValidity({ valueMissing: !0 }, g.forms.messages.required, s) : (h = s.validity) != null && h.typeMismatch || (p = s.validity) != null && p.badInput ? this.internals.setValidity({ typeMismatch: !0 }, g.forms.messages.invalid, s) : (u = s.validity) != null && u.patternMismatch ? this.internals.setValidity(
{ patternMismatch: !0 },
g.forms.messages.invalidPattern,
s
) : (y = s.validity) != null && y.tooShort || this.minlength && this.minlength > 0 && this.value.length < this.minlength ? this.internals.setValidity({ tooShort: !0 }, g.forms.messages.tooShort, s) : (V = s.validity) != null && V.tooLong || this.maxlength && this.maxlength > 0 && this.value.length > this.maxlength ? this.internals.setValidity({ tooLong: !0 }, g.forms.messages.tooLong, s) : (C = s.validity) != null && C.rangeUnderflow ? this.internals.setValidity(
{ rangeUnderflow: !0 },
this.min ? g.forms.messages.rangeUnderflowMin.replace("{min}", (b = this.min) == null ? void 0 : b.toString()) : g.forms.messages.rangeUnderflow,
s
) : (T = s.validity) != null && T.stepMismatch ? this.internals.setValidity({ stepMismatch: !0 }, g.forms.messages.invalid, s) : (F = s.validity) != null && F.rangeOverflow ? this.internals.setValidity(
{ rangeOverflow: !0 },
this.max ? g.forms.messages.rangeOverflowMax.replace("{max}", (S = this.max) == null ? void 0 : S.toString()) : g.forms.messages.rangeOverflow,
s
) : (A = s.validity) != null && A.customError ? this.internals.setValidity({ customError: !0 }, s.validationMessage, s) : this.internals.setValidity({}));
}
setFormValue(s) {
if (this.internals)
if (Array.isArray(s)) {
const h = new FormData();
s.forEach((p) => {
h.append(this.name, p);
}), this.internals.setFormValue(h);
} else
this.internals.setFormValue(s);
}
// Trigger this when you want to set the value of the *radio or checkbox* input out to the form
// Do not use valueChanged or onChange for radios and checkboxes!
valueChecked(s) {
if (!this.touched) return;
const h = this.internals.form || this.closest("form"), p = h ? new FormData(h) : null;
h && h.querySelectorAll(
`pkt-radiobutton[name="${this.name}"], input[type=radio][name="${this.name}"]`
).forEach((u) => {
const y = u;
y.name === this.name && y.value !== this.value && y.checked && (y.checked = !1);
}), typeof s == "string" ? (this.checked = s === "true", this.internals.ariaChecked = s === "true") : typeof s == "boolean" && (this.checked = s, this.internals.ariaChecked = s), this.checked ? (this.internals.setFormValue(this.value || "on", this.value || "on"), p && p.append(this.name, this.value || "on"), this.internals.states.add("--checked")) : (this.internals.setFormValue(null, null), p && p.delete(this.name), this.internals.states.delete("--checked")), this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), this.dispatchEvent(
new CustomEvent("value-change", {
detail: this.checked,
bubbles: !0,
composed: !0
})
), this.internals.reportValidity();
}
valueChanged(s, h) {
(h !== this.value || h !== this._value) && (typeof s == "string" ? ((this.multiple || this.range) && s.includes(",") && (s = s.split(",")), this.value = s, this._value = Array.isArray(s) ? s : [s]) : Array.isArray(s) ? (this.value = this.multiple || this.range ? s : s[0], this._value = s) : (this.value = "", this._value = []), (!this.value || this.value.length === 0) && h && h.length !== 0 ? this.clearInputValue() : this.value && this.value.toString() !== (h == null ? void 0 : h.toString()) && this.onChange(this.value), this.updateComplete.then(() => this.requestUpdate()));
}
// When input goes from content to no content
clearInputValue() {
const s = this.multiple || this.range ? [] : "";
this.value = s, this.internals.setFormValue(s), this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), this.dispatchEvent(
new CustomEvent("value-change", {
detail: s,
bubbles: !0,
composed: !0
})
);
}
// When user enters the input, we need to push that event out to the form
onFocus() {
this.dispatchEvent(new FocusEvent("focus", { bubbles: !0, composed: !0 }));
}
// And also when the user leaves the input...
onBlur() {
this.dispatchEvent(new FocusEvent("blur", { bubbles: !0, composed: !0 }));
}
// Trigger this when user types in the input
onInput() {
this.dispatchEvent(new InputEvent("input", { bubbles: !0, composed: !0 }));
}
// Trigger this when you want to set the value of the input out to the form
onChange(s) {
if (!this.touched) {
this.touched = !0, s && this.setFormValue(s);
return;
}
typeof s != "string" && !Array.isArray(s) || ((this.range || this.multiple) && !Array.isArray(s) && s.includes(",") && (s = s.split(",")), !this.multiple && !this.range && Array.isArray(s) && (s = s[0]), this.setFormValue(s), this.manageValidity(this.inputRef.value), this.inputRefTo && this.manageValidity(this.inputRefTo.value), this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), this.dispatchEvent(
new CustomEvent("value-change", {
detail: s,
bubbles: !0,
composed: !0
})
));
}
formResetCallback() {
this.touched = !1, this._options && this._options.length && this._options.forEach((s) => {
s.selected = !1;
}), this.checked !== void 0 ? (this.checked = !1, this.internals.ariaChecked = !1, this.internals.setFormValue("", ""), this.inputRef.value.checked = !1, this.valueChecked(this.checked)) : (this.internals.setFormValue(""), this.value = this.defaultValue || (this.multiple || this.range ? [] : ""), this._value = this.value, this.valueChanged(this.value, null)), this.internals.ariaInvalid = !1;
}
updated(s) {
super.updated(s), s.has("dataTestid") && this.dataTestid && this.inputRef.value && (this.skipForwardTestid ? this.hasAttribute("data-testid") || this.setAttribute("data-testid", this.dataTestid) : (this.inputRef.value.dataset.testid = this.dataTestid, this.removeAttribute("data-testid")));
}
firstUpdated(s) {
if (super.firstUpdated(s), !this.form) {
const h = this.internals.form || this.closest("form");
this.form = h;
}
if (this.value && this.defaultValue !== null && (this.defaultValue = this.value), this.defaultValue !== null && !this.value && this.valueChanged(this.defaultValue, null), this.defaultChecked && (this.internals.ariaChecked = !0, this.checked = !0), this.required && (this.internals.ariaRequired = !0), this.disabled && (this.internals.ariaDisabled = !0), this.id && !this.name && (this.name = this.id), this.checked !== void 0) {
const h = this.checked === "" || this.checked === "true" || this.checked === !0;
this.internals.ariaChecked = h, this.internals.setFormValue(
h ? this.value || "on" : "",
h ? this.value || "on" : ""
);
} else
this.internals.setFormValue(this.value);
this.inputRef && this.inputRef.value && (this.inputRef.value.setAttribute("form", ""), this.manageValidity(this.inputRef.value)), this.inputRefTo && this.inputRefTo.value && (this.inputRefTo.value.setAttribute("form", ""), this.manageValidity(this.inputRefTo.value));
}
}
l([
d()
], c.prototype, "defaultValue");
l([
d({ type: Boolean, reflect: !0 })
], c.prototype, "disabled");
l([
d({ type: Boolean, reflect: !0 })
], c.prototype, "readonly");
l([
d({ type: Boolean, reflect: !0 })
], c.prototype, "required");
l([
d({ type: Number, reflect: !0 })
], c.prototype, "max");
l([
d({ type: Number, reflect: !0 })
], c.prototype, "maxlength");
l([
d({ type: Number, reflect: !0 })
], c.prototype, "min");
l([
d({ type: Number, reflect: !0 })
], c.prototype, "minlength");
l([
d({ type: Number, reflect: !0 })
], c.prototype, "step");
l([
d({ type: String })
], c.prototype, "ariaDescribedBy");
l([
d({ type: String })
], c.prototype, "ariaLabelledby");
l([
d({ type: String, reflect: !0 })
], c.prototype, "name");
l([
d({ type: String, reflect: !0 })
], c.prototype, "pattern");
l([
d({ type: String, reflect: !0 })
], c.prototype, "placeholder");
l([
d({ type: String, reflect: !0 })
], c.prototype, "id");
l([
d({ type: Boolean })
], c.prototype, "counter");
l([
d({ type: Boolean })
], c.prototype, "hasError");
l([
d({ type: Boolean })
], c.prototype, "inline");
l([
d({ type: Boolean })
], c.prototype, "hasFieldset");
l([
d({ type: Boolean })
], c.prototype, "optionalTag");
l([
d({ type: Boolean })
], c.prototype, "requiredTag");
l([
d({ type: Boolean })
], c.prototype, "skipForwardTestid");
l([
d({ type: Boolean, reflect: !1 })
], c.prototype, "useWrapper");
l([
d({ type: Boolean, reflect: !0 })
], c.prototype, "fullwidth");
l([
d({ type: Number })
], c.prototype, "counterMaxLength");
l([
d({ type: String })
], c.prototype, "errorMessage");
l([
d({ type: String })
], c.prototype, "helptext");
l([
d({ type: String })
], c.prototype, "helptextDropdown");
l([
d({ type: String, reflect: !1 })
], c.prototype, "helptextDropdownButton");
l([
d({ type: String })
], c.prototype, "label");
l([
d({ type: String, reflect: !1 })
], c.prototype, "optionalText");
l([
d({ type: String, reflect: !1 })
], c.prototype, "requiredText");
l([
d({ type: String, reflect: !1 })
], c.prototype, "tagText");
l([
d({ type: String, attribute: "data-testid" })
], c.prototype, "dataTestid");
l([
Ve()
], c.prototype, "touched");
export {
c as P
};