@mattilsynet/design 2.1.10 → 2.1.12
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/mtds/chart/chart-axis.d.ts +1 -0
- package/mtds/chart/chart-doughnut.d.ts +1 -0
- package/mtds/chart/chart-element.d.ts +19 -0
- package/mtds/external/@u-elements/u-details/dist/u-details.js +23 -23
- package/mtds/external/@u-elements/u-details/dist/u-details.js.map +1 -1
- package/mtds/field/field.d.ts +2 -0
- package/mtds/field/field.js +78 -73
- package/mtds/field/field.js.map +1 -1
- package/mtds/fieldset/fieldset-observer.js +13 -13
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/index.iife.js +7 -7
- package/mtds/package.json.js +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +40 -40
- package/mtds/styles.module.css.js +29 -29
- package/mtds/table/table.js +14 -6
- package/mtds/table/table.js.map +1 -1
- package/mtds/table/table.stories.d.ts +3 -0
- package/mtds/tooltip/tooltip-observer.js +8 -8
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/utils.d.ts +7 -0
- package/mtds/utils.js +24 -23
- package/mtds/utils.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MTDSElement } from '../utils';
|
|
2
|
+
import type * as ReactTypes from "react";
|
|
3
|
+
export type ReactChart = ReactTypes.JSX.IntrinsicElements["div"] & {
|
|
4
|
+
class?: string;
|
|
5
|
+
};
|
|
6
|
+
declare global {
|
|
7
|
+
namespace React.JSX {
|
|
8
|
+
interface IntrinsicElements {
|
|
9
|
+
"mtds-chart": ReactChart;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare class MTDSChart extends MTDSElement {
|
|
14
|
+
_resizeObserver: ResizeObserver | null;
|
|
15
|
+
_svg: SVGSVGElement | null;
|
|
16
|
+
constructor();
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
1
|
+
var h = typeof window < "u" && typeof window.document < "u" && typeof window.navigator < "u", c;
|
|
2
|
+
h && // @ts-expect-error Typescript has not implemented userAgentData yet https://stackoverflow.com/a/71392474
|
|
3
3
|
/^Mac/i.test(((c = navigator.userAgentData) == null ? void 0 : c.platform) || navigator.platform);
|
|
4
|
-
var
|
|
4
|
+
var y = ":host(:not([hidden])) { display: block }", m = typeof HTMLElement > "u" ? class {
|
|
5
5
|
} : HTMLElement;
|
|
6
6
|
function o(t, e, n) {
|
|
7
7
|
return n === void 0 ? t.getAttribute(e) : (n === null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n), null);
|
|
@@ -9,29 +9,29 @@ function o(t, e, n) {
|
|
|
9
9
|
var f = (t, e, n) => {
|
|
10
10
|
for (const i of n[0].split(","))
|
|
11
11
|
n[0] = i, Element.prototype[`${t}EventListener`].apply(e, n);
|
|
12
|
-
},
|
|
12
|
+
}, d = (t, ...e) => f("add", t, e), u = (t, ...e) => f("remove", t, e), b = (t) => {
|
|
13
13
|
const e = "key" in t && (t.key === " " || t.key === "Enter");
|
|
14
14
|
return e && t.preventDefault(), e && t.target instanceof HTMLElement && t.target.click(), e;
|
|
15
|
-
},
|
|
15
|
+
}, g = (t) => {
|
|
16
16
|
var e;
|
|
17
17
|
const n = ((e = t.getRootNode) == null ? void 0 : e.call(t)) || t.ownerDocument;
|
|
18
18
|
return n instanceof Document || n instanceof ShadowRoot ? n : document;
|
|
19
|
-
},
|
|
19
|
+
}, r = (t, e, n) => {
|
|
20
20
|
const i = document.createElement(t);
|
|
21
21
|
if (e && (i.textContent = e), n) for (const [s, a] of Object.entries(n)) o(i, s, a);
|
|
22
22
|
return i;
|
|
23
23
|
}, p = {
|
|
24
|
-
define: (t, e) => !
|
|
25
|
-
},
|
|
24
|
+
define: (t, e) => !h || window.customElements.get(t) || window.customElements.define(t, e)
|
|
25
|
+
}, v = `${y}
|
|
26
26
|
::slotted(u-summary) { cursor: pointer; display: block }
|
|
27
27
|
::slotted(u-summary)::before { content: ''; display: inline-block; vertical-align: middle; margin-inline: .05em .3125em; border-block: .3125em solid transparent; border-inline-start: .5em solid }
|
|
28
28
|
::slotted(u-summary[aria-expanded="true"])::before { rotate: 90deg }
|
|
29
|
-
:host > [part="details-content"]:not([hidden=""]) { display: block }`,
|
|
29
|
+
:host > [part="details-content"]:not([hidden=""]) { display: block }`, k = class extends m {
|
|
30
30
|
constructor() {
|
|
31
31
|
super(), this._content = null, this.shadowRoot || this.attachShadow({ mode: "open" }).append(
|
|
32
32
|
r("slot", null, { name: "summary" }),
|
|
33
33
|
r("slot", null, { part: "details-content" }),
|
|
34
|
-
r("style",
|
|
34
|
+
r("style", v)
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
// Using ES2015 syntax for backwards compatibility
|
|
@@ -40,27 +40,27 @@ var f = (t, e, n) => {
|
|
|
40
40
|
}
|
|
41
41
|
connectedCallback() {
|
|
42
42
|
var t;
|
|
43
|
-
this._content = (t = this.shadowRoot) == null ? void 0 : t.children[1], o(this, "role", "group"),
|
|
43
|
+
this._content = (t = this.shadowRoot) == null ? void 0 : t.children[1], o(this, "role", "group"), d(this._content, "beforematch", this), d(this, "click,keydown", this), this.attributeChangedCallback();
|
|
44
44
|
}
|
|
45
45
|
disconnectedCallback() {
|
|
46
|
-
this._content &&
|
|
46
|
+
this._content && u(this._content, "beforematch", this), u(this, "click,keydown", this), this._content = null;
|
|
47
47
|
}
|
|
48
48
|
attributeChangedCallback(t, e, n) {
|
|
49
49
|
const i = "onbeforematch" in this ? "until-found" : !0, s = this.open;
|
|
50
50
|
for (const a of this.children)
|
|
51
|
-
a.nodeName === "U-SUMMARY" &&
|
|
51
|
+
a.nodeName === "U-SUMMARY" && o(a, "aria-expanded", `${s}`);
|
|
52
52
|
if (this._content && (o(this._content, "aria-hidden", `${!s}`), this._content.hidden = s ? !1 : i), s && this.name) {
|
|
53
|
-
const a =
|
|
53
|
+
const a = g(this).querySelectorAll(
|
|
54
54
|
`${this.nodeName}[name="${this.name}"]`
|
|
55
55
|
);
|
|
56
|
-
for (const
|
|
57
|
-
|
|
56
|
+
for (const l of a)
|
|
57
|
+
l !== this && (l.open = !1);
|
|
58
58
|
}
|
|
59
59
|
t === "open" && e === null != (n === null) && this.dispatchEvent(new Event("toggle"));
|
|
60
60
|
}
|
|
61
61
|
handleEvent(t) {
|
|
62
62
|
const e = this.querySelector(":scope > u-summary"), n = e?.contains(t.target);
|
|
63
|
-
t.defaultPrevented || (t.type === "beforematch" && (this.open = !0), n && t.type === "keydown" &&
|
|
63
|
+
t.defaultPrevented || (t.type === "beforematch" && (this.open = !0), n && t.type === "keydown" && b(t), n && t.type === "click" && (this.open = !this.open));
|
|
64
64
|
}
|
|
65
65
|
get open() {
|
|
66
66
|
return this.hasAttribute("open");
|
|
@@ -74,16 +74,16 @@ var f = (t, e, n) => {
|
|
|
74
74
|
set name(t) {
|
|
75
75
|
o(this, "name", t);
|
|
76
76
|
}
|
|
77
|
-
},
|
|
77
|
+
}, w = class extends m {
|
|
78
78
|
connectedCallback() {
|
|
79
79
|
o(this, "role", "button"), this.slot = "summary", this.tabIndex = 0;
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
p.define("u-details",
|
|
83
|
-
p.define("u-summary",
|
|
82
|
+
p.define("u-details", k);
|
|
83
|
+
p.define("u-summary", w);
|
|
84
84
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
k as UHTMLDetailsElement,
|
|
86
|
+
v as UHTMLDetailsStyle,
|
|
87
|
+
w as UHTMLSummaryElement
|
|
88
88
|
};
|
|
89
89
|
//# sourceMappingURL=u-details.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"u-details.js","sources":["../../../../../node_modules/@u-elements/u-details/dist/u-details.js"],"sourcesContent":["// ../utils.ts\nvar IS_BROWSER = typeof window !== \"undefined\" && typeof window.document !== \"undefined\" && typeof window.navigator !== \"undefined\";\nvar IS_ANDROID = IS_BROWSER && /android/i.test(navigator.userAgent);\nvar _a;\nIS_BROWSER && // @ts-expect-error Typescript has not implemented userAgentData yet https://stackoverflow.com/a/71392474\n/^Mac/i.test(((_a = navigator.userAgentData) == null ? void 0 : _a.platform) || navigator.platform);\nvar SAFE_LABELLEDBY = `${IS_ANDROID ? \"data\" : \"aria\"}-labelledby`;\nvar DISPLAY_BLOCK = \":host(:not([hidden])) { display: block }\";\nvar UHTMLElement = typeof HTMLElement === \"undefined\" ? class {\n} : HTMLElement;\nfunction attr(el, name, value) {\n if (value === void 0) return el.getAttribute(name);\n if (value === null) el.removeAttribute(name);\n else if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n return null;\n}\nvar events = (action, element, rest) => {\n for (const type of rest[0].split(\",\")) {\n rest[0] = type;\n Element.prototype[`${action}EventListener`].apply(element, rest);\n }\n};\nvar on = (element, ...rest) => events(\"add\", element, rest);\nvar off = (element, ...rest) => events(\"remove\", element, rest);\nvar asButton = (event) => {\n const isClick = \"key\" in event && (event.key === \" \" || event.key === \"Enter\");\n if (isClick) event.preventDefault();\n if (isClick && event.target instanceof HTMLElement) event.target.click();\n return isClick;\n};\nvar getRoot = (node) => {\n var _a2;\n const root = ((_a2 = node.getRootNode) == null ? void 0 : _a2.call(node)) || node.ownerDocument;\n return root instanceof Document || root instanceof ShadowRoot ? root : document;\n};\nvar id = 0;\nvar useId = (el) => {\n if (!el) return \"\";\n if (!el.id) el.id = `:${el.nodeName.toLowerCase()}${(++id).toString(32)}`;\n return el.id;\n};\nvar createElement = (tagName, text, attrs) => {\n const el = document.createElement(tagName);\n if (text) el.textContent = text;\n if (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n return el;\n};\nvar customElements = {\n define: (name, instance) => !IS_BROWSER || window.customElements.get(name) || window.customElements.define(name, instance)\n};\nvar declarativeShadowRoot = (style, slot = \"<slot></slot>\") => `<template shadowrootmode=\"open\">${slot}<style>${style}</style></template>`;\n\n// u-details.ts\nvar UHTMLDetailsStyle = `${DISPLAY_BLOCK}\n::slotted(u-summary) { cursor: pointer; display: block }\n::slotted(u-summary)::before { content: ''; display: inline-block; vertical-align: middle; margin-inline: .05em .3125em; border-block: .3125em solid transparent; border-inline-start: .5em solid }\n::slotted(u-summary[aria-expanded=\"true\"])::before { rotate: 90deg }\n:host > [part=\"details-content\"]:not([hidden=\"\"]) { display: block }`;\nvar UHTMLDetailsShadowRoot = declarativeShadowRoot(\n UHTMLDetailsStyle,\n '<slot name=\"summary\"></slot><slot part=\"details-content\" hidden=\"until-found\"></slot>'\n);\nvar UHTMLDetailsElement = class extends UHTMLElement {\n constructor() {\n super();\n // Using underscore instead of private fields for backwards compatibility\n this._content = null;\n if (!this.shadowRoot)\n this.attachShadow({ mode: \"open\" }).append(\n createElement(\"slot\", null, { name: \"summary\" }),\n createElement(\"slot\", null, { part: \"details-content\" }),\n createElement(\"style\", UHTMLDetailsStyle)\n );\n }\n // Using ES2015 syntax for backwards compatibility\n static get observedAttributes() {\n return [\"open\"];\n }\n connectedCallback() {\n var _a2;\n this._content = (_a2 = this.shadowRoot) == null ? void 0 : _a2.children[1];\n attr(this, \"role\", \"group\");\n on(this._content, \"beforematch\", this);\n on(this, \"click,keydown\", this);\n this.attributeChangedCallback();\n }\n disconnectedCallback() {\n if (this._content) off(this._content, \"beforematch\", this);\n off(this, \"click,keydown\", this);\n this._content = null;\n }\n attributeChangedCallback(prop, prev, next) {\n const hide = \"onbeforematch\" in this ? \"until-found\" : true;\n const open = this.open;\n for (const el of this.children)\n if (el.nodeName === \"U-SUMMARY\") {\n attr(this, SAFE_LABELLEDBY, useId(el));\n attr(el, \"aria-expanded\", `${open}`);\n }\n if (this._content) {\n attr(this._content, \"aria-hidden\", `${!open}`);\n this._content.hidden = open ? false : hide;\n }\n if (open && this.name) {\n const uDetailsList = getRoot(this).querySelectorAll(\n `${this.nodeName}[name=\"${this.name}\"]`\n );\n for (const uDetails of uDetailsList)\n if (uDetails !== this) uDetails.open = false;\n }\n if (prop === \"open\" && prev === null !== (next === null))\n this.dispatchEvent(new Event(\"toggle\"));\n }\n handleEvent(event) {\n const summary = this.querySelector(\":scope > u-summary\");\n const isSummary = summary == null ? void 0 : summary.contains(event.target);\n if (event.defaultPrevented) return;\n if (event.type === \"beforematch\") this.open = true;\n if (isSummary && event.type === \"keydown\") asButton(event);\n if (isSummary && event.type === \"click\") this.open = !this.open;\n }\n get open() {\n return this.hasAttribute(\"open\");\n }\n set open(value) {\n attr(this, \"open\", value ? \"\" : null);\n }\n get name() {\n return attr(this, \"name\") || \"\";\n }\n set name(value) {\n attr(this, \"name\", value);\n }\n};\nvar UHTMLSummaryElement = class extends UHTMLElement {\n connectedCallback() {\n attr(this, \"role\", \"button\");\n this.slot = \"summary\";\n this.tabIndex = 0;\n }\n};\ncustomElements.define(\"u-details\", UHTMLDetailsElement);\ncustomElements.define(\"u-summary\", UHTMLSummaryElement);\n\nexport { UHTMLDetailsElement, UHTMLDetailsShadowRoot, UHTMLDetailsStyle, UHTMLSummaryElement };\n"],"names":["IS_BROWSER","IS_ANDROID","_a","SAFE_LABELLEDBY","DISPLAY_BLOCK","UHTMLElement","attr","el","name","value","events","action","element","rest","type","on","off","asButton","event","isClick","getRoot","node","_a2","root","id","useId","createElement","tagName","text","attrs","key","val","customElements","instance","UHTMLDetailsStyle","UHTMLDetailsElement","prop","prev","next","hide","open","uDetailsList","uDetails","summary","isSummary","UHTMLSummaryElement"],"mappings":"AACA,IAAIA,IAAa,OAAO,SAAW,OAAe,OAAO,OAAO,WAAa,OAAe,OAAO,OAAO,YAAc,KACpHC,IAAaD,KAAc,WAAW,KAAK,UAAU,SAAS,GAC9DE;AACJF;AACA,QAAQ,OAAOE,IAAK,UAAU,kBAA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AAsB,cAAcxC,EAAa;AAAA,EACnD,oBAAoB;AAClB,IAAAC,EAAK,MAAM,QAAQ,QAAQ,GAC3B,KAAK,OAAO,WACZ,KAAK,WAAW;AAAA,EAClB;AACF;AACA0B,EAAe,OAAO,aAAaG,CAAmB;AACtDH,EAAe,OAAO,aAAaa,CAAmB;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"u-details.js","sources":["../../../../../node_modules/@u-elements/u-details/dist/u-details.js"],"sourcesContent":["// ../utils.ts\nvar IS_BROWSER = typeof window !== \"undefined\" && typeof window.document !== \"undefined\" && typeof window.navigator !== \"undefined\";\nvar _a;\nIS_BROWSER && // @ts-expect-error Typescript has not implemented userAgentData yet https://stackoverflow.com/a/71392474\n/^Mac/i.test(((_a = navigator.userAgentData) == null ? void 0 : _a.platform) || navigator.platform);\nvar DISPLAY_BLOCK = \":host(:not([hidden])) { display: block }\";\nvar UHTMLElement = typeof HTMLElement === \"undefined\" ? class {\n} : HTMLElement;\nfunction attr(el, name, value) {\n if (value === void 0) return el.getAttribute(name);\n if (value === null) el.removeAttribute(name);\n else if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n return null;\n}\nvar events = (action, element, rest) => {\n for (const type of rest[0].split(\",\")) {\n rest[0] = type;\n Element.prototype[`${action}EventListener`].apply(element, rest);\n }\n};\nvar on = (element, ...rest) => events(\"add\", element, rest);\nvar off = (element, ...rest) => events(\"remove\", element, rest);\nvar asButton = (event) => {\n const isClick = \"key\" in event && (event.key === \" \" || event.key === \"Enter\");\n if (isClick) event.preventDefault();\n if (isClick && event.target instanceof HTMLElement) event.target.click();\n return isClick;\n};\nvar getRoot = (node) => {\n var _a2;\n const root = ((_a2 = node.getRootNode) == null ? void 0 : _a2.call(node)) || node.ownerDocument;\n return root instanceof Document || root instanceof ShadowRoot ? root : document;\n};\nvar createElement = (tagName, text, attrs) => {\n const el = document.createElement(tagName);\n if (text) el.textContent = text;\n if (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n return el;\n};\nvar customElements = {\n define: (name, instance) => !IS_BROWSER || window.customElements.get(name) || window.customElements.define(name, instance)\n};\nvar declarativeShadowRoot = (style, slot = \"<slot></slot>\") => `<template shadowrootmode=\"open\">${slot}<style>${style}</style></template>`;\n\n// u-details.ts\nvar UHTMLDetailsStyle = `${DISPLAY_BLOCK}\n::slotted(u-summary) { cursor: pointer; display: block }\n::slotted(u-summary)::before { content: ''; display: inline-block; vertical-align: middle; margin-inline: .05em .3125em; border-block: .3125em solid transparent; border-inline-start: .5em solid }\n::slotted(u-summary[aria-expanded=\"true\"])::before { rotate: 90deg }\n:host > [part=\"details-content\"]:not([hidden=\"\"]) { display: block }`;\nvar UHTMLDetailsShadowRoot = declarativeShadowRoot(\n UHTMLDetailsStyle,\n '<slot name=\"summary\"></slot><slot part=\"details-content\" hidden=\"until-found\"></slot>'\n);\nvar UHTMLDetailsElement = class extends UHTMLElement {\n constructor() {\n super();\n // Using underscore instead of private fields for backwards compatibility\n this._content = null;\n if (!this.shadowRoot)\n this.attachShadow({ mode: \"open\" }).append(\n createElement(\"slot\", null, { name: \"summary\" }),\n createElement(\"slot\", null, { part: \"details-content\" }),\n createElement(\"style\", UHTMLDetailsStyle)\n );\n }\n // Using ES2015 syntax for backwards compatibility\n static get observedAttributes() {\n return [\"open\"];\n }\n connectedCallback() {\n var _a2;\n this._content = (_a2 = this.shadowRoot) == null ? void 0 : _a2.children[1];\n attr(this, \"role\", \"group\");\n on(this._content, \"beforematch\", this);\n on(this, \"click,keydown\", this);\n this.attributeChangedCallback();\n }\n disconnectedCallback() {\n if (this._content) off(this._content, \"beforematch\", this);\n off(this, \"click,keydown\", this);\n this._content = null;\n }\n attributeChangedCallback(prop, prev, next) {\n const hide = \"onbeforematch\" in this ? \"until-found\" : true;\n const open = this.open;\n for (const el of this.children)\n if (el.nodeName === \"U-SUMMARY\") attr(el, \"aria-expanded\", `${open}`);\n if (this._content) {\n attr(this._content, \"aria-hidden\", `${!open}`);\n this._content.hidden = open ? false : hide;\n }\n if (open && this.name) {\n const uDetailsList = getRoot(this).querySelectorAll(\n `${this.nodeName}[name=\"${this.name}\"]`\n );\n for (const uDetails of uDetailsList)\n if (uDetails !== this) uDetails.open = false;\n }\n if (prop === \"open\" && prev === null !== (next === null))\n this.dispatchEvent(new Event(\"toggle\"));\n }\n handleEvent(event) {\n const summary = this.querySelector(\":scope > u-summary\");\n const isSummary = summary == null ? void 0 : summary.contains(event.target);\n if (event.defaultPrevented) return;\n if (event.type === \"beforematch\") this.open = true;\n if (isSummary && event.type === \"keydown\") asButton(event);\n if (isSummary && event.type === \"click\") this.open = !this.open;\n }\n get open() {\n return this.hasAttribute(\"open\");\n }\n set open(value) {\n attr(this, \"open\", value ? \"\" : null);\n }\n get name() {\n return attr(this, \"name\") || \"\";\n }\n set name(value) {\n attr(this, \"name\", value);\n }\n};\nvar UHTMLSummaryElement = class extends UHTMLElement {\n connectedCallback() {\n attr(this, \"role\", \"button\");\n this.slot = \"summary\";\n this.tabIndex = 0;\n }\n};\ncustomElements.define(\"u-details\", UHTMLDetailsElement);\ncustomElements.define(\"u-summary\", UHTMLSummaryElement);\n\nexport { UHTMLDetailsElement, UHTMLDetailsShadowRoot, UHTMLDetailsStyle, UHTMLSummaryElement };\n"],"names":["IS_BROWSER","_a","DISPLAY_BLOCK","UHTMLElement","attr","el","name","value","events","action","element","rest","type","on","off","asButton","event","isClick","getRoot","node","_a2","root","createElement","tagName","text","attrs","key","val","customElements","instance","UHTMLDetailsStyle","UHTMLDetailsElement","prop","prev","next","hide","open","uDetailsList","uDetails","summary","isSummary","UHTMLSummaryElement"],"mappings":"AACA,IAAIA,IAAa,OAAO,SAAW,OAAe,OAAO,OAAO,WAAa,OAAe,OAAO,OAAO,YAAc,KACpHC;AACJD;AACA,QAAQ,OAAOC,IAAK,UAAU,kBAAkB,OAAO,SAASA,EAAG,aAAa,UAAU,QAAQ;AAClG,IAAIC,IAAgB,4CAChBC,IAAe,OAAO,cAAgB,MAAc,MA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C,IAAenB,EAAQ,IAAI,EAAE;AAAA,QACjC,GAAG,KAAK,QAAQ,UAAU,KAAK,IAAI;AAAA,MAC3C;AACM,iBAAWoB,KAAYD;AACrB,QAAIC,MAAa,SAAMA,EAAS,OAAO;AAAA,IAC3C;AACA,IAAIN,MAAS,UAAUC,MAAS,SAAUC,MAAS,SACjD,KAAK,cAAc,IAAI,MAAM,QAAQ,CAAC;AAAA,EAC1C;AAAA,EACA,YAAYlB,GAAO;AACjB,UAAMuB,IAAU,KAAK,cAAc,oBAAoB,GACjDC,IAAuCD,GAAQ,SAASvB,EAAM,MAAM;AAC1E,IAAIA,EAAM,qBACNA,EAAM,SAAS,kBAAe,KAAK,OAAO,KAC1CwB,KAAaxB,EAAM,SAAS,aAAWD,EAASC,CAAK,GACrDwB,KAAaxB,EAAM,SAAS,YAAS,KAAK,OAAO,CAAC,KAAK;AAAA,EAC7D;AAAA,EACA,IAAI,OAAO;AACT,WAAO,KAAK,aAAa,MAAM;AAAA,EACjC;AAAA,EACA,IAAI,KAAKT,GAAO;AACd,IAAAH,EAAK,MAAM,QAAQG,IAAQ,KAAK,IAAI;AAAA,EACtC;AAAA,EACA,IAAI,OAAO;AACT,WAAOH,EAAK,MAAM,MAAM,KAAK;AAAA,EAC/B;AAAA,EACA,IAAI,KAAKG,GAAO;AACd,IAAAH,EAAK,MAAM,QAAQG,CAAK;AAAA,EAC1B;AACF,GACIkC,IAAsB,cAActC,EAAa;AAAA,EACnD,oBAAoB;AAClB,IAAAC,EAAK,MAAM,QAAQ,QAAQ,GAC3B,KAAK,OAAO,WACZ,KAAK,WAAW;AAAA,EAClB;AACF;AACAwB,EAAe,OAAO,aAAaG,CAAmB;AACtDH,EAAe,OAAO,aAAaa,CAAmB;","x_google_ignoreList":[0]}
|
package/mtds/field/field.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export type FieldComboboxProps = ReactUcombobox & {
|
|
|
45
45
|
selected?: FieldComboboxSelected;
|
|
46
46
|
} & Pick<InputProps, "disabled" | "readOnly" | "placeholder" | "type" | "name"> & // Allow input props to be passed down
|
|
47
47
|
Pick<FieldDatalistProps, "data-position" | "data-nofilter">;
|
|
48
|
+
export type FieldLabelProps = React.ComponentPropsWithoutRef<"label">;
|
|
48
49
|
export declare const Field: FieldComponent & {
|
|
49
50
|
Affixes: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
50
51
|
Combobox: React.ForwardRefExoticComponent<Omit<FieldComboboxProps, "ref"> & React.RefAttributes<UHTMLComboboxElement>>;
|
|
@@ -53,5 +54,6 @@ export declare const Field: FieldComponent & {
|
|
|
53
54
|
"data-position"?: Placement;
|
|
54
55
|
} & React.RefAttributes<HTMLDataListElement>>;
|
|
55
56
|
Option: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.OptionHTMLAttributes<HTMLOptionElement>, HTMLOptionElement>, "ref"> & React.RefAttributes<HTMLOptionElement>>;
|
|
57
|
+
Label: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "ref"> & React.RefAttributes<HTMLLabelElement>>;
|
|
56
58
|
};
|
|
57
59
|
export {};
|
package/mtds/field/field.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as t, Fragment as
|
|
1
|
+
import { jsx as t, Fragment as I, jsxs as j } from "react/jsx-runtime";
|
|
2
2
|
import { clsx as k } from "../external/clsx/dist/clsx.js";
|
|
3
|
-
import { forwardRef as
|
|
3
|
+
import { forwardRef as c, useRef as z, useImperativeHandle as K, useEffect as M } from "react";
|
|
4
4
|
import "../alert/alert.js";
|
|
5
5
|
import "../app/app.js";
|
|
6
6
|
import "../avatar/avatar.js";
|
|
@@ -31,154 +31,159 @@ import "../tag/tag.js";
|
|
|
31
31
|
import "../togglegroup/togglegroup.js";
|
|
32
32
|
import "../typography/typography.js";
|
|
33
33
|
import "../validation/validation.js";
|
|
34
|
-
import
|
|
34
|
+
import g from "../styles.module.css.js";
|
|
35
35
|
import { toCustomElementProps as N } from "../utils.js";
|
|
36
|
-
const P = (i) => typeof i == "string" ? { label: i, value: i } : i, V =
|
|
37
|
-
"data-size":
|
|
38
|
-
as:
|
|
36
|
+
const P = (i) => typeof i == "string" ? { label: i, value: i } : i, V = c(function({
|
|
37
|
+
"data-size": o,
|
|
38
|
+
as: e,
|
|
39
39
|
className: a,
|
|
40
40
|
count: m,
|
|
41
|
-
description:
|
|
41
|
+
description: u,
|
|
42
42
|
error: F,
|
|
43
43
|
helpText: y,
|
|
44
|
-
helpTextLabel:
|
|
44
|
+
helpTextLabel: H,
|
|
45
45
|
label: f,
|
|
46
|
-
prefix:
|
|
46
|
+
prefix: b,
|
|
47
47
|
style: D,
|
|
48
|
-
suffix:
|
|
49
|
-
validation:
|
|
48
|
+
suffix: h,
|
|
49
|
+
validation: C,
|
|
50
50
|
...r
|
|
51
|
-
},
|
|
52
|
-
const
|
|
53
|
-
"data-size":
|
|
54
|
-
className: k(
|
|
51
|
+
}, v) {
|
|
52
|
+
const l = e || "div", E = !!h || !!b, W = C || F, O = {
|
|
53
|
+
"data-size": o,
|
|
54
|
+
className: k(g.field, a),
|
|
55
55
|
style: D
|
|
56
56
|
};
|
|
57
|
-
return
|
|
57
|
+
return e === "select" && !r.children && Object.assign(r, {
|
|
58
58
|
options: void 0,
|
|
59
59
|
// Ensure options is not passed to DOM
|
|
60
|
-
children: /* @__PURE__ */ t(
|
|
61
|
-
}),
|
|
60
|
+
children: /* @__PURE__ */ t(I, { children: r.options?.map(P).map(({ label: x, value: p }) => /* @__PURE__ */ t("option", { value: p, children: x }, p)) })
|
|
61
|
+
}), e ? /* @__PURE__ */ j("div", { ...O, children: [
|
|
62
62
|
!!f && /* @__PURE__ */ t("label", { suppressHydrationWarning: !0, children: f }),
|
|
63
|
-
!!y && /* @__PURE__ */ t(Q, { "aria-label":
|
|
64
|
-
!!
|
|
63
|
+
!!y && /* @__PURE__ */ t(Q, { "aria-label": H, children: y }),
|
|
64
|
+
!!u && /* @__PURE__ */ t("p", { suppressHydrationWarning: !0, children: u }),
|
|
65
65
|
E ? /* @__PURE__ */ j(S, { children: [
|
|
66
|
-
!!
|
|
66
|
+
!!b && /* @__PURE__ */ t("span", { children: b }),
|
|
67
67
|
/* @__PURE__ */ t(
|
|
68
|
-
|
|
68
|
+
l,
|
|
69
69
|
{
|
|
70
|
-
className:
|
|
70
|
+
className: g.input,
|
|
71
71
|
suppressHydrationWarning: !0,
|
|
72
|
-
ref:
|
|
72
|
+
ref: v,
|
|
73
73
|
...r
|
|
74
74
|
}
|
|
75
75
|
),
|
|
76
|
-
!!
|
|
76
|
+
!!h && /* @__PURE__ */ t("span", { children: h })
|
|
77
77
|
] }) : /* @__PURE__ */ t(
|
|
78
|
-
|
|
78
|
+
l,
|
|
79
79
|
{
|
|
80
|
-
className: typeof
|
|
80
|
+
className: typeof e == "string" ? g.input : void 0,
|
|
81
81
|
suppressHydrationWarning: !0,
|
|
82
|
-
ref:
|
|
82
|
+
ref: v,
|
|
83
83
|
...r
|
|
84
84
|
}
|
|
85
85
|
),
|
|
86
|
-
!!W && /* @__PURE__ */ t("div", { suppressHydrationWarning: !0, className:
|
|
86
|
+
!!W && /* @__PURE__ */ t("div", { suppressHydrationWarning: !0, className: g.validation, children: W }),
|
|
87
87
|
!!m && /* @__PURE__ */ t("p", { suppressHydrationWarning: !0, "data-count": m })
|
|
88
|
-
] }) : /* @__PURE__ */ t("div", { ref:
|
|
89
|
-
}), S =
|
|
90
|
-
function({ className:
|
|
91
|
-
return /* @__PURE__ */ t("div", { className: k(
|
|
88
|
+
] }) : /* @__PURE__ */ t("div", { ref: v, ...O, ...r });
|
|
89
|
+
}), S = c(
|
|
90
|
+
function({ className: o, ...e }, a) {
|
|
91
|
+
return /* @__PURE__ */ t("div", { className: k(g.affixes, o), ref: a, ...e });
|
|
92
92
|
}
|
|
93
|
-
), T =
|
|
94
|
-
function({ "data-nofilter":
|
|
93
|
+
), T = c(
|
|
94
|
+
function({ "data-nofilter": o, ...e }, a) {
|
|
95
95
|
return /* @__PURE__ */ t(
|
|
96
96
|
"u-datalist",
|
|
97
97
|
{
|
|
98
|
-
"data-nofilter": !!
|
|
98
|
+
"data-nofilter": !!o || void 0,
|
|
99
99
|
ref: a,
|
|
100
|
-
...N(
|
|
100
|
+
...N(e)
|
|
101
101
|
}
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
|
-
), q =
|
|
105
|
-
function(
|
|
106
|
-
return /* @__PURE__ */ t("u-option", { ref:
|
|
104
|
+
), q = c(
|
|
105
|
+
function(o, e) {
|
|
106
|
+
return /* @__PURE__ */ t("u-option", { ref: e, ...N(o) });
|
|
107
107
|
}
|
|
108
|
-
), X =
|
|
108
|
+
), X = c(
|
|
109
109
|
function({
|
|
110
|
-
"data-multiple":
|
|
111
|
-
"data-nofilter":
|
|
110
|
+
"data-multiple": o,
|
|
111
|
+
"data-nofilter": e,
|
|
112
112
|
"data-position": a,
|
|
113
113
|
onAfterChange: m,
|
|
114
|
-
onAfterSelect:
|
|
114
|
+
onAfterSelect: u,
|
|
115
115
|
onBeforeChange: F,
|
|
116
116
|
onBeforeMatch: y,
|
|
117
|
-
onBeforeSelect:
|
|
117
|
+
onBeforeSelect: H,
|
|
118
118
|
onSelectedChange: f,
|
|
119
|
-
children:
|
|
119
|
+
children: b,
|
|
120
120
|
disabled: D,
|
|
121
|
-
name:
|
|
122
|
-
options:
|
|
121
|
+
name: h,
|
|
122
|
+
options: C,
|
|
123
123
|
placeholder: r,
|
|
124
|
-
readOnly:
|
|
125
|
-
selected:
|
|
124
|
+
readOnly: v,
|
|
125
|
+
selected: l,
|
|
126
126
|
type: E,
|
|
127
127
|
...W
|
|
128
128
|
}, O) {
|
|
129
|
-
const
|
|
130
|
-
return
|
|
129
|
+
const x = z(null), p = z(f);
|
|
130
|
+
return p.current = f, m && (u = m, console.warn(
|
|
131
131
|
"Combobox onAfterChange is deprecated, use onAfterSelect instead."
|
|
132
|
-
)), F && (
|
|
132
|
+
)), F && (H = F, console.warn(
|
|
133
133
|
"Combobox onBeforeChange is deprecated, use onBeforeSelect instead."
|
|
134
|
-
)), K(O, () =>
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
134
|
+
)), K(O, () => x.current), M(() => {
|
|
135
|
+
const d = x.current, s = (n) => {
|
|
136
|
+
const L = p.current;
|
|
137
|
+
if (!p) return;
|
|
138
138
|
n.preventDefault();
|
|
139
|
-
const { isConnected: B, textContent: G, value:
|
|
140
|
-
|
|
139
|
+
const { isConnected: B, textContent: G, value: w } = n.detail, A = G?.trim() || "", R = l || [];
|
|
140
|
+
L?.(B ? R.filter((J) => J.value !== w) : o ? [...R, { value: w, label: A }] : [{ value: w, label: A }]);
|
|
141
141
|
};
|
|
142
|
-
return
|
|
143
|
-
}, [
|
|
142
|
+
return d?.addEventListener("comboboxbeforeselect", s), () => d?.removeEventListener("comboboxbeforeselect", s);
|
|
143
|
+
}, [o, l]), /* @__PURE__ */ j(
|
|
144
144
|
"u-combobox",
|
|
145
145
|
{
|
|
146
|
-
"data-multiple":
|
|
146
|
+
"data-multiple": o || void 0,
|
|
147
147
|
...N({
|
|
148
|
-
oncomboboxbeforeselect:
|
|
148
|
+
oncomboboxbeforeselect: H,
|
|
149
149
|
oncomboboxbeforematch: y,
|
|
150
|
-
oncomboboxafterselect:
|
|
151
|
-
ref:
|
|
150
|
+
oncomboboxafterselect: u,
|
|
151
|
+
ref: x,
|
|
152
152
|
...W
|
|
153
153
|
}),
|
|
154
154
|
children: [
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
l?.map(({ children: d, label: s, value: n }) => /* @__PURE__ */ t("data", { value: n, suppressHydrationWarning: !0, children: d ?? s }, n)),
|
|
156
|
+
b || /* @__PURE__ */ j(I, { children: [
|
|
157
157
|
/* @__PURE__ */ t(
|
|
158
158
|
U,
|
|
159
159
|
{
|
|
160
|
-
name:
|
|
160
|
+
name: h,
|
|
161
161
|
type: E,
|
|
162
162
|
disabled: D,
|
|
163
|
-
readOnly:
|
|
163
|
+
readOnly: v,
|
|
164
164
|
placeholder: r
|
|
165
165
|
}
|
|
166
166
|
),
|
|
167
167
|
/* @__PURE__ */ t("del", { ...N({ "aria-label": "Fjern tekst" }) })
|
|
168
168
|
] }),
|
|
169
|
-
!!
|
|
169
|
+
!!C && /* @__PURE__ */ t(T, { "data-nofilter": e, "data-position": a, children: C.map(P).map(({ children: d, label: s, value: n }) => /* @__PURE__ */ t(q, { value: n, label: s, children: d ?? s }, n)) })
|
|
170
170
|
]
|
|
171
171
|
}
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
|
-
),
|
|
174
|
+
), wt = Object.assign(V, {
|
|
175
175
|
Affixes: S,
|
|
176
176
|
Combobox: X,
|
|
177
177
|
Datalist: T,
|
|
178
|
-
Option: q
|
|
178
|
+
Option: q,
|
|
179
|
+
Label: c(
|
|
180
|
+
function(o, e) {
|
|
181
|
+
return /* @__PURE__ */ t("label", { suppressHydrationWarning: !0, ref: e, ...o });
|
|
182
|
+
}
|
|
183
|
+
)
|
|
179
184
|
});
|
|
180
185
|
export {
|
|
181
|
-
|
|
186
|
+
wt as Field,
|
|
182
187
|
V as FieldComp
|
|
183
188
|
};
|
|
184
189
|
//# sourceMappingURL=field.js.map
|
package/mtds/field/field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText, Input, type InputProps } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\ntype FieldBaseProps = {\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n\tvalue?: React.ComponentPropsWithRef<\"input\">[\"value\"];\n\tonInput?: (\n\t\te: React.ChangeEvent<\n\t\t\tHTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n\t\t>,\n\t) => void;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst valid = validation || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!valid && (\n\t\t\t\t<div suppressHydrationWarning className={styles.validation}>\n\t\t\t\t\t{valid}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = ReactUcombobox & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t\"disabled\" | \"readOnly\" | \"placeholder\" | \"type\" | \"name\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"data-multiple\": multiple,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-position\": position,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n});\n"],"names":["toOption","o","FieldComp","forwardRef","size","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validation","rest","ref","Tag","affixes","valid","shared","clsx","styles","value","jsx","jsxs","HelpText","FieldAffixes","FieldDatalist","filter","toCustomElementProps","FieldOption","props","FieldCombobox","multiple","nofilter","position","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMd,KAAM,OACZe,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAQL,KAAcP,GACtBa,IAAS;AAAA,IACd,aAAalB;AAAA,IACb,WAAWmB,EAAKC,EAAO,OAAOlB,CAAS;AAAA,IACvC,OAAAQ;AAAA,EAAA;AAID,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AAA,GADHa,CAEX,CACA;AAAA,UACAoB,KACA,gBAAAlB,EAAAuC,GAAA,EACC,UAAA;AAAA,YAAA,gBAAAxC;AAAA,cAACyC;AAAA,cAAA;AAAA,gBACA,MAAApB;AAAA,gBACA,MAAAK;AAAA,gBACA,UAAAN;AAAA,gBACA,UAAAI;AAAA,gBACA,aAAAD;AAAA,cAAA;AAAA,YAAA;AAAA,YAED,gBAAAvB,EAAC,SAAK,GAAGM,EAAqB,EAAE,cAAc,cAAA,CAAe,EAAA,CAAG;AAAA,UAAA,GACjE;AAAA,UAEA,CAAC,CAACgB,KACF,gBAAAtB,EAACI,GAAA,EAAc,iBAAeO,GAAU,iBAAeC,GACrD,UAAAU,EAAQ,IAAIhD,CAAQ,EAAE,IAAI,CAAC,EAAE,UAAA6C,GAAU,OAAAjC,GAAO,OAAAa,EAAA,MAC9C,gBAAAC,EAACO,GAAA,EAAwB,OAAAR,GAAc,OAAAb,GACrC,UAAAiC,KAAYjC,EAAA,GADIa,CAElB,CACA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIJ;AACD,GAEa2C,KAAQ,OAAO,OAAOlE,GAAW;AAAA,EAC7C,SAAS2B;AAAA,EACT,UAAUM;AAAA,EACV,UAAUL;AAAA,EACV,QAAQG;AACT,CAAC;"}
|
|
1
|
+
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText, Input, type InputProps } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\ntype FieldBaseProps = {\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n\tvalue?: React.ComponentPropsWithRef<\"input\">[\"value\"];\n\tonInput?: (\n\t\te: React.ChangeEvent<\n\t\t\tHTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n\t\t>,\n\t) => void;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst valid = validation || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!valid && (\n\t\t\t\t<div suppressHydrationWarning className={styles.validation}>\n\t\t\t\t\t{valid}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = ReactUcombobox & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t\"disabled\" | \"readOnly\" | \"placeholder\" | \"type\" | \"name\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"data-multiple\": multiple,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-position\": position,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tLabel: forwardRef<HTMLLabelElement, FieldLabelProps>(\n\t\tfunction FieldLabel(rest, ref) {\n\t\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t\t},\n\t),\n});\n"],"names":["toOption","o","FieldComp","forwardRef","size","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validation","rest","ref","Tag","affixes","valid","shared","clsx","styles","value","jsx","jsxs","HelpText","FieldAffixes","FieldDatalist","filter","toCustomElementProps","FieldOption","props","FieldCombobox","multiple","nofilter","position","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMd,KAAM,OACZe,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAQL,KAAcP,GACtBa,IAAS;AAAA,IACd,aAAalB;AA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A,MAClC,gBAAAC,EAAC,QAAA,EAAiB,OAAAD,GAAc,0BAAwB,IACtD,UAAAoB,KAAYjC,EAAA,GADHa,CAEX,CACA;AAAA,UACAoB,KACA,gBAAAlB,EAAAuC,GAAA,EACC,UAAA;AAAA,YAAA,gBAAAxC;AAAA,cAACyC;AAAA,cAAA;AAAA,gBACA,MAAApB;AAAA,gBACA,MAAAK;AAAA,gBACA,UAAAN;AAAA,gBACA,UAAAI;AAAA,gBACA,aAAAD;AAAA,cAAA;AAAA,YAAA;AAAA,YAED,gBAAAvB,EAAC,SAAK,GAAGM,EAAqB,EAAE,cAAc,cAAA,CAAe,EAAA,CAAG;AAAA,UAAA,GACjE;AAAA,UAEA,CAAC,CAACgB,KACF,gBAAAtB,EAACI,GAAA,EAAc,iBAAeO,GAAU,iBAAeC,GACrD,UAAAU,EAAQ,IAAIhD,CAAQ,EAAE,IAAI,CAAC,EAAE,UAAA6C,GAAU,OAAAjC,GAAO,OAAAa,EAAA,MAC9C,gBAAAC,EAACO,GAAA,EAAwB,OAAAR,GAAc,OAAAb,GACrC,UAAAiC,KAAYjC,EAAA,GADIa,CAElB,CACA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIJ;AACD,GAGa2C,KAAQ,OAAO,OAAOlE,GAAW;AAAA,EAC7C,SAAS2B;AAAA,EACT,UAAUM;AAAA,EACV,UAAUL;AAAA,EACV,QAAQG;AAAA,EACR,OAAO9B;AAAA,IACN,SAAoBc,GAAMC,GAAK;AAC9B,+BAAQ,SAAA,EAAM,0BAAwB,IAAC,KAAAA,GAAW,GAAGD,GAAM;AAAA,IAC5D;AAAA,EAAA;AAEF,CAAC;"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import c from "../styles.module.css.js";
|
|
2
2
|
import { onLoaded as r, onMutation as f, attr as e, useId as u, isInputLike as m } from "../utils.js";
|
|
3
|
-
const I =
|
|
4
|
-
function L(
|
|
5
|
-
|
|
6
|
-
for (const
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
let i = null,
|
|
10
|
-
for (const t of
|
|
11
|
-
t.classList.contains(p) ? (
|
|
12
|
-
for (const t of
|
|
13
|
-
const d = e(t,
|
|
14
|
-
e(t,
|
|
3
|
+
const I = c.fieldset.split(" ")[0], p = c.validation.split(" ")[0], l = "aria-describedby", A = "aria-invalid";
|
|
4
|
+
function L(a) {
|
|
5
|
+
setTimeout(() => {
|
|
6
|
+
for (const o of a)
|
|
7
|
+
if (o.isConnected) {
|
|
8
|
+
const s = [];
|
|
9
|
+
let i = null, n = !0;
|
|
10
|
+
for (const t of o.getElementsByTagName("*"))
|
|
11
|
+
t.classList.contains(p) ? (n = e(t, "data-color") === "success" || !t.clientHeight, i = u(t)) : m(t) && s.push(t);
|
|
12
|
+
for (const t of s) {
|
|
13
|
+
const d = e(t, l)?.replace(i || "#", "");
|
|
14
|
+
e(t, l, `${i || ""} ${d || ""}`.trim()), e(t, A, `${!n}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isInputLike, onLoaded, onMutation, useId } from \"../utils\";\n\nconst CSS_FIELDSET = styles.fieldset.split(\" \")[0];\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\nconst ARIA_DESC = \"aria-describedby\";\nconst ARIA_INVALID = \"aria-invalid\";\n\n// Using
|
|
1
|
+
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isInputLike, onLoaded, onMutation, useId } from \"../utils\";\n\nconst CSS_FIELDSET = styles.fieldset.split(\" \")[0];\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\nconst ARIA_DESC = \"aria-describedby\";\nconst ARIA_INVALID = \"aria-invalid\";\n\n// Using setTimeout to ensure it runs after field-observer\nfunction handleFieldsetMutation(fieldsets: HTMLCollectionOf<Element>) {\n\tsetTimeout(() => {\n\t\tfor (const fieldset of fieldsets)\n\t\t\tif (fieldset.isConnected) {\n\t\t\t\tconst inputs: HTMLInputElement[] = [];\n\t\t\t\tlet validId: string | null = null;\n\t\t\t\tlet valid = true;\n\n\t\t\t\tfor (const el of fieldset.getElementsByTagName(\"*\")) {\n\t\t\t\t\tif (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\t\tvalidId = useId(el);\n\t\t\t\t\t} else if (isInputLike(el)) inputs.push(el);\n\t\t\t\t}\n\n\t\t\t\tfor (const input of inputs) {\n\t\t\t\t\tconst desc = attr(input, ARIA_DESC)?.replace(validId || \"#\", \"\");\n\n\t\t\t\t\tattr(input, ARIA_DESC, `${validId || \"\"} ${desc || \"\"}`.trim());\n\t\t\t\t\tattr(input, ARIA_INVALID, `${!valid}`);\n\t\t\t\t}\n\t\t\t}\n\t});\n}\n\nonLoaded(() =>\n\tonMutation(document.documentElement, CSS_FIELDSET, handleFieldsetMutation),\n);\n"],"names":["CSS_FIELDSET","styles","CSS_VALIDATION","ARIA_DESC","ARIA_INVALID","handleFieldsetMutation","fieldsets","fieldset","inputs","validId","valid","el","attr","useId","isInputLike","input","desc","onLoaded","onMutation"],"mappings":";;AAGA,MAAMA,IAAeC,EAAO,SAAS,MAAM,GAAG,EAAE,CAAC,GAC3CC,IAAiBD,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,GAC/CE,IAAY,oBACZC,IAAe;AAGrB,SAASC,EAAuBC,GAAsC;AACrE,aAAW,MAAM;AAChB,eAAWC,KAAYD;AACtB,UAAIC,EAAS,aAAa;AACzB,cAAMC,IAA6B,CAAA;AACnC,YAAIC,IAAyB,MACzBC,IAAQ;AAEZ,mBAAWC,KAAMJ,EAAS,qBAAqB,GAAG;AACjD,UAAII,EAAG,UAAU,SAAST,CAAc,KACvCQ,IAAQE,EAAKD,GAAI,YAAY,MAAM,aAAa,CAACA,EAAG,cACpDF,IAAUI,EAAMF,CAAE,KACRG,EAAYH,CAAE,KAAGH,EAAO,KAAKG,CAAE;AAG3C,mBAAWI,KAASP,GAAQ;AAC3B,gBAAMQ,IAAOJ,EAAKG,GAAOZ,CAAS,GAAG,QAAQM,KAAW,KAAK,EAAE;AAE/D,UAAAG,EAAKG,GAAOZ,GAAW,GAAGM,KAAW,EAAE,IAAIO,KAAQ,EAAE,GAAG,KAAA,CAAM,GAC9DJ,EAAKG,GAAOX,GAAc,GAAG,CAACM,CAAK,EAAE;AAAA,QACtC;AAAA,MACD;AAAA,EACF,CAAC;AACF;AAEAO;AAAA,EAAS,MACRC,EAAW,SAAS,iBAAiBlB,GAAcK,CAAsB;AAC1E;"}
|