@mattilsynet/design 1.3.5 → 1.3.6
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/analytics/analytics.d.ts +1 -0
- package/mtds/analytics/analytics.js +10 -10
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +1 -1
- package/mtds/app/app-toggle.js +26 -14
- package/mtds/app/app-toggle.js.map +1 -1
- package/mtds/app/app-toggle2.js +14 -26
- package/mtds/app/app-toggle2.js.map +1 -1
- package/mtds/app/app.js +1 -1
- package/mtds/field/field-observer.js +39 -34
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.stories.d.ts +1 -0
- package/mtds/index.iife.js +6 -6
- package/mtds/layout/layout.d.ts +1 -1
- package/mtds/layout/layout.js.map +1 -1
- package/mtds/package.json.js +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/utils.d.ts +1 -1
- package/mtds/utils.js +59 -65
- package/mtds/utils.js.map +1 -1
- package/package.json +2 -3
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { IS_BROWSER as
|
|
2
|
-
const
|
|
3
|
-
let
|
|
1
|
+
import { IS_BROWSER as l } from "../utils.js";
|
|
2
|
+
const s = "mattilsynet.matomo.cloud";
|
|
3
|
+
let a = !0;
|
|
4
4
|
function d(o, n = {}) {
|
|
5
|
-
if (
|
|
6
|
-
if (window._paq || (window._paq = [], window._paq.push(["HeatmapSessionRecording::disable"]), window._paq.push(["enableLinkTracking"]), window._paq.push(["setTrackerUrl", `https://${
|
|
5
|
+
if (l) {
|
|
6
|
+
if (window._paq || (window._paq = [], window._paq.push(["HeatmapSessionRecording::disable"]), window._paq.push(["enableLinkTracking"]), window._paq.push(["setTrackerUrl", `https://${s}/matomo.php`]), document.querySelector('script[src*="matomo.js"]') || document.head.append(
|
|
7
7
|
Object.assign(document.createElement("script"), {
|
|
8
8
|
async: !0,
|
|
9
|
-
src: `https://cdn.matomo.cloud/${
|
|
9
|
+
src: `https://cdn.matomo.cloud/${s}/matomo.js`
|
|
10
10
|
})
|
|
11
11
|
)), o === "init") {
|
|
12
12
|
const { matomoId: e, enabled: t = !0 } = n;
|
|
13
|
-
|
|
13
|
+
a = t, window._paq.push(["setSiteId", e]);
|
|
14
14
|
}
|
|
15
|
-
if (
|
|
16
|
-
if (!(
|
|
15
|
+
if (a === "debug") return console.info(`Analytics: "${o}"`, n);
|
|
16
|
+
if (!(a === !1 || window.location.hostname === "localhost"))
|
|
17
17
|
if (o === "pageview") {
|
|
18
18
|
const { url: e, title: t } = n;
|
|
19
19
|
window._paq.push(["setCustomUrl", e || location.href]), window._paq.push(["setDocumentTitle", t || document.title]), window._paq.push(["trackPageView"]);
|
|
20
20
|
} else if (o === "event") {
|
|
21
21
|
const { category: e, action: t, name: i, value: c } = n, p = ["trackEvent", e, t, i, c];
|
|
22
|
-
window._paq.push(p.filter((
|
|
22
|
+
window._paq.push(p.filter((r) => r !== void 0));
|
|
23
23
|
} else if (o === "search") {
|
|
24
24
|
const {
|
|
25
25
|
query: e,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sources":["../../designsystem/analytics/analytics.ts"],"sourcesContent":["import { IS_BROWSER } from \"../utils\";\n\nconst MATOMO = \"mattilsynet.matomo.cloud\";\nlet ENABLED: AnalyticsActions[\"init\"][\"enabled\"] = true;\n\ntype Matomo = (string | number | boolean)[];\ndeclare global {\n\tinterface Window {\n\t\t_paq?: Matomo[];\n\t}\n}\n\nexport type AnalyticsActions = {\n\tinit: {\n\t\tmatomoId: number | string;\n\t\tenabled?: boolean | \"debug\";\n\t};\n\tpageview: {\n\t\turl?: string;\n\t\ttitle?: string;\n\t};\n\tevent: {\n\t\tcategory: string;\n\t\taction: string;\n\t\tname?: string;\n\t\tvalue?: number;\n\t};\n\tsearch: {\n\t\tquery: string;\n\t\tcategory?: string;\n\t\tresults?: number;\n\t};\n\tmatomo: Matomo;\n};\n\nexport function analytics<Action extends keyof AnalyticsActions>(\n\taction: Action,\n\targs = {} as AnalyticsActions[Action],\n) {\n\tif (!IS_BROWSER) return;\n\tif (!window._paq) {\n\t\twindow._paq = [];\n\t\twindow._paq.push([\"HeatmapSessionRecording::disable\"]); // Disable heatmaps by default as this require cookies\n\t\twindow._paq.push([\"enableLinkTracking\"]);\n\t\twindow._paq.push([\"setTrackerUrl\", `https://${MATOMO}/matomo.php`]);\n\t\tdocument.querySelector('script[src*=\"matomo.js\"]') ||\n\t\t\tdocument.
|
|
1
|
+
{"version":3,"file":"analytics.js","sources":["../../designsystem/analytics/analytics.ts"],"sourcesContent":["import { IS_BROWSER } from \"../utils\";\n\nconst MATOMO = \"mattilsynet.matomo.cloud\";\nlet ENABLED: AnalyticsActions[\"init\"][\"enabled\"] = true;\n\ntype Matomo = (string | number | boolean)[];\ndeclare global {\n\tinterface Window {\n\t\t_paq?: Matomo[];\n\t\t_mtm?: Record<string, string | number>[];\n\t}\n}\n\n// window._paq = window._paq || [];\n// window._mtm = window._mtm || [];\n\n// window._paq.push([\"setCustomUrl\", `${document.location.href}&eirik`]);\n// window._paq.push([\"setDocumentTitle\", \"Eirik 3\"]);\n// window._mtm.push({\n// \tevent: \"mtm.Start\",\n// \t\"mtm.startTime\": new Date().getTime(),\n// \tcustomTitle: \"Eirik 1\",\n// \tcustomUrl: `${document.location.href}&eirik`,\n// });\n\n// window._mtm.push({\n// \tevent: \"mtm.PageView\",\n// \tcustomTitle: \"Eirik 2\",\n// \tcustomUrl: `${document.location.href}&eirik`,\n// });\n\n// const containerId = \"A9utKk3O\";\n\n// document.head.append(\n// \tObject.assign(document.createElement(\"script\"), {\n// \t\tsrc: `https://cdn.matomo.cloud/mattilsynet.matomo.cloud/container_${containerId}.js`,\n// \t\tasync: true,\n// \t\tonload: () => console.log(window._paq),\n// \t}),\n// );\n\nexport type AnalyticsActions = {\n\tinit: {\n\t\tmatomoId: number | string;\n\t\tenabled?: boolean | \"debug\";\n\t};\n\tpageview: {\n\t\turl?: string;\n\t\ttitle?: string;\n\t};\n\tevent: {\n\t\tcategory: string;\n\t\taction: string;\n\t\tname?: string;\n\t\tvalue?: number;\n\t};\n\tsearch: {\n\t\tquery: string;\n\t\tcategory?: string;\n\t\tresults?: number;\n\t};\n\tmatomo: Matomo;\n};\n\nexport function analytics<Action extends keyof AnalyticsActions>(\n\taction: Action,\n\targs = {} as AnalyticsActions[Action],\n) {\n\tif (!IS_BROWSER) return;\n\tif (!window._paq) {\n\t\twindow._paq = [];\n\t\twindow._paq.push([\"HeatmapSessionRecording::disable\"]); // Disable heatmaps by default as this require cookies\n\t\twindow._paq.push([\"enableLinkTracking\"]);\n\t\twindow._paq.push([\"setTrackerUrl\", `https://${MATOMO}/matomo.php`]);\n\t\tdocument.querySelector('script[src*=\"matomo.js\"]') ||\n\t\t\tdocument.head.append(\n\t\t\t\tObject.assign(document.createElement(\"script\"), {\n\t\t\t\t\tasync: true,\n\t\t\t\t\tsrc: `https://cdn.matomo.cloud/${MATOMO}/matomo.js`,\n\t\t\t\t}),\n\t\t\t);\n\t}\n\tif (action === \"init\") {\n\t\tconst { matomoId, enabled = true } = args as AnalyticsActions[\"init\"];\n\t\tENABLED = enabled;\n\t\twindow._paq.push([\"setSiteId\", matomoId]);\n\t}\n\n\tif (ENABLED === \"debug\") return console.info(`Analytics: \"${action}\"`, args);\n\tif (ENABLED === false || window.location.hostname === \"localhost\") return;\n\n\tif (action === \"pageview\") {\n\t\tconst { url, title } = args as AnalyticsActions[\"pageview\"];\n\t\twindow._paq.push([\"setCustomUrl\", url || location.href]);\n\t\twindow._paq.push([\"setDocumentTitle\", title || document.title]);\n\t\twindow._paq.push([\"trackPageView\"]);\n\t} else if (action === \"event\") {\n\t\tconst { category, action, name, value } = args as AnalyticsActions[\"event\"];\n\t\tconst event = [\"trackEvent\", category, action, name, value];\n\t\twindow._paq.push(event.filter((v) => v !== undefined));\n\t} else if (action === \"search\") {\n\t\tconst {\n\t\t\tquery,\n\t\t\tcategory = false,\n\t\t\tresults = false,\n\t\t} = args as AnalyticsActions[\"search\"];\n\t\twindow._paq.push([\"trackSiteSearch\", query, category, results]);\n\t} else if (action === \"matomo\") {\n\t\twindow._paq.push(args as AnalyticsActions[\"matomo\"]);\n\t}\n}\n"],"names":["MATOMO","ENABLED","analytics","action","args","IS_BROWSER","matomoId","enabled","url","title","category","name","value","event","v","query","results"],"mappings":";AAEA,MAAMA,IAAS;AACf,IAAIC,IAA+C;AA6D5C,SAASC,EACfC,GACAC,IAAO,IACN;AACD,MAAKC,GAcL;AAAA,QAbK,OAAO,SACX,OAAO,OAAO,CAAC,GACf,OAAO,KAAK,KAAK,CAAC,kCAAkC,CAAC,GACrD,OAAO,KAAK,KAAK,CAAC,oBAAoB,CAAC,GACvC,OAAO,KAAK,KAAK,CAAC,iBAAiB,WAAWL,CAAM,aAAa,CAAC,GAClE,SAAS,cAAc,0BAA0B,KAChD,SAAS,KAAK;AAAA,MACb,OAAO,OAAO,SAAS,cAAc,QAAQ,GAAG;AAAA,QAC/C,OAAO;AAAA,QACP,KAAK,4BAA4BA,CAAM;AAAA,MACvC,CAAA;AAAA,IACF,IAEEG,MAAW,QAAQ;AACtB,YAAM,EAAE,UAAAG,GAAU,SAAAC,IAAU,GAAS,IAAAH;AAC3B,MAAAH,IAAAM,GACV,OAAO,KAAK,KAAK,CAAC,aAAaD,CAAQ,CAAC;AAAA,IAAA;AAGrC,QAAAL,MAAY,QAAgB,QAAA,QAAQ,KAAK,eAAeE,CAAM,KAAKC,CAAI;AAC3E,QAAI,EAAAH,MAAY,MAAS,OAAO,SAAS,aAAa;AAEtD,UAAIE,MAAW,YAAY;AACpB,cAAA,EAAE,KAAAK,GAAK,OAAAC,EAAA,IAAUL;AACvB,eAAO,KAAK,KAAK,CAAC,gBAAgBI,KAAO,SAAS,IAAI,CAAC,GACvD,OAAO,KAAK,KAAK,CAAC,oBAAoBC,KAAS,SAAS,KAAK,CAAC,GAC9D,OAAO,KAAK,KAAK,CAAC,eAAe,CAAC;AAAA,MAAA,WACxBN,MAAW,SAAS;AAC9B,cAAM,EAAE,UAAAO,GAAU,QAAAP,GAAQ,MAAAQ,GAAM,OAAAC,MAAUR,GACpCS,IAAQ,CAAC,cAAcH,GAAUP,GAAQQ,GAAMC,CAAK;AACnD,eAAA,KAAK,KAAKC,EAAM,OAAO,CAACC,MAAMA,MAAM,MAAS,CAAC;AAAA,MAAA,WAC3CX,MAAW,UAAU;AACzB,cAAA;AAAA,UACL,OAAAY;AAAA,UACA,UAAAL,IAAW;AAAA,UACX,SAAAM,IAAU;AAAA,QAAA,IACPZ;AACJ,eAAO,KAAK,KAAK,CAAC,mBAAmBW,GAAOL,GAAUM,CAAO,CAAC;AAAA,MAAA,MAC/D,CAAWb,MAAW,YACd,OAAA,KAAK,KAAKC,CAAkC;AAAA;AAErD;"}
|
package/mtds/app/app-observer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import m from "../styles.module.css.js";
|
|
2
2
|
import { onLoaded as C, onMutation as T, on as p, QUICK_EVENT as c, debounce as P } from "../utils.js";
|
|
3
|
-
import "./app-
|
|
3
|
+
import "./app-toggle2.js";
|
|
4
4
|
const f = m.app.split(" ")[0], _ = m.sticky.split(" ")[0], h = '[data-command="toggle-app-expanded"]', g = `.${f} > dialog,.${f} dialog ~ main`, S = (t) => {
|
|
5
5
|
document.startViewTransition ? document.startViewTransition(t) : t();
|
|
6
6
|
}, E = (t) => (
|
package/mtds/app/app-toggle.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
const t = `if (
|
|
2
|
+
typeof window !== "undefined" &&
|
|
3
|
+
window.CSSStyleSheet &&
|
|
4
|
+
document.adoptedStyleSheets
|
|
5
|
+
)
|
|
6
|
+
(() => {
|
|
7
|
+
const key = "--mtds-app-expanded";
|
|
8
|
+
const sheet = new CSSStyleSheet();
|
|
9
|
+
const prev = () => !window.localStorage.getItem(key)?.includes("false");
|
|
10
|
+
|
|
11
|
+
document.adoptedStyleSheets.push(sheet);
|
|
12
|
+
window.mtdsToggleAppExpanded = (force) => {
|
|
13
|
+
try {
|
|
14
|
+
const next = force ?? !prev();
|
|
15
|
+
sheet.replaceSync?.(\`:root { \${key}: var(\${key}--\${next})}\`);
|
|
16
|
+
window.localStorage.setItem(key, next);
|
|
17
|
+
} catch (err) {} // localStorage is full or replaceSync is not supported
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Set and store initial state
|
|
21
|
+
window.mtdsToggleAppExpanded(prev());
|
|
22
|
+
})();
|
|
23
|
+
`;
|
|
24
|
+
export {
|
|
25
|
+
t as default
|
|
26
|
+
};
|
|
15
27
|
//# sourceMappingURL=app-toggle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-toggle.js","sources":["../../designsystem/app/app-toggle.js"],"sourcesContent":["if (
|
|
1
|
+
{"version":3,"file":"app-toggle.js","sources":["../../designsystem/app/app-toggle.js?raw"],"sourcesContent":["export default \"if (\\n\\ttypeof window !== \\\"undefined\\\" &&\\n\\twindow.CSSStyleSheet &&\\n\\tdocument.adoptedStyleSheets\\n)\\n\\t(() => {\\n\\t\\tconst key = \\\"--mtds-app-expanded\\\";\\n\\t\\tconst sheet = new CSSStyleSheet();\\n\\t\\tconst prev = () => !window.localStorage.getItem(key)?.includes(\\\"false\\\");\\n\\n\\t\\tdocument.adoptedStyleSheets.push(sheet);\\n\\t\\twindow.mtdsToggleAppExpanded = (force) => {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tconst next = force ?? !prev();\\n\\t\\t\\t\\tsheet.replaceSync?.(`:root { ${key}: var(${key}--${next})}`);\\n\\t\\t\\t\\twindow.localStorage.setItem(key, next);\\n\\t\\t\\t} catch (err) {} // localStorage is full or replaceSync is not supported\\n\\t\\t};\\n\\n\\t\\t// Set and store initial state\\n\\t\\twindow.mtdsToggleAppExpanded(prev());\\n\\t})();\\n\""],"names":["script"],"mappings":"AAAA,MAAeA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
|
package/mtds/app/app-toggle2.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
sheet.replaceSync?.(\`:root { \${key}: var(\${key}--\${next})}\`);
|
|
16
|
-
window.localStorage.setItem(key, next);
|
|
17
|
-
} catch (err) {} // localStorage is full or replaceSync is not supported
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Set and store initial state
|
|
21
|
-
window.mtdsToggleAppExpanded(prev());
|
|
22
|
-
})();
|
|
23
|
-
`;
|
|
24
|
-
export {
|
|
25
|
-
t as default
|
|
26
|
-
};
|
|
1
|
+
typeof window < "u" && window.CSSStyleSheet && document.adoptedStyleSheets && (() => {
|
|
2
|
+
const e = "--mtds-app-expanded", t = new CSSStyleSheet(), n = () => {
|
|
3
|
+
var d;
|
|
4
|
+
return !((d = window.localStorage.getItem(e)) != null && d.includes("false"));
|
|
5
|
+
};
|
|
6
|
+
document.adoptedStyleSheets.push(t), window.mtdsToggleAppExpanded = (d) => {
|
|
7
|
+
var p;
|
|
8
|
+
try {
|
|
9
|
+
const o = d ?? !n();
|
|
10
|
+
(p = t.replaceSync) == null || p.call(t, `:root { ${e}: var(${e}--${o})}`), window.localStorage.setItem(e, o);
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
13
|
+
}, window.mtdsToggleAppExpanded(n());
|
|
14
|
+
})();
|
|
27
15
|
//# sourceMappingURL=app-toggle2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-toggle2.js","sources":["../../designsystem/app/app-toggle.js
|
|
1
|
+
{"version":3,"file":"app-toggle2.js","sources":["../../designsystem/app/app-toggle.js"],"sourcesContent":["if (\n\ttypeof window !== \"undefined\" &&\n\twindow.CSSStyleSheet &&\n\tdocument.adoptedStyleSheets\n)\n\t(() => {\n\t\tconst key = \"--mtds-app-expanded\";\n\t\tconst sheet = new CSSStyleSheet();\n\t\tconst prev = () => !window.localStorage.getItem(key)?.includes(\"false\");\n\n\t\tdocument.adoptedStyleSheets.push(sheet);\n\t\twindow.mtdsToggleAppExpanded = (force) => {\n\t\t\ttry {\n\t\t\t\tconst next = force ?? !prev();\n\t\t\t\tsheet.replaceSync?.(`:root { ${key}: var(${key}--${next})}`);\n\t\t\t\twindow.localStorage.setItem(key, next);\n\t\t\t} catch (err) {} // localStorage is full or replaceSync is not supported\n\t\t};\n\n\t\t// Set and store initial state\n\t\twindow.mtdsToggleAppExpanded(prev());\n\t})();\n"],"names":["key","sheet","prev","_a","force","next"],"mappings":"AACC,OAAO,SAAW,OAClB,OAAO,iBACP,SAAS,uBAER,MAAM;AACN,QAAMA,IAAM,uBACNC,IAAQ,IAAI,cAAe,GAC3BC,IAAO,MAAM;AARrB,QAAAC;AAQqB,cAACA,IAAA,OAAO,aAAa,QAAQH,CAAG,MAA/B,QAAAG,EAAkC,SAAS;AAAA;AAE/D,WAAS,mBAAmB,KAAKF,CAAK,GACtC,OAAO,wBAAwB,CAACG,MAAU;AAX5C,QAAAD;AAYG,QAAI;AACH,YAAME,IAAOD,KAAS,CAACF,EAAM;AAC7B,OAAAC,IAAAF,EAAM,gBAAN,QAAAE,EAAA,KAAAF,GAAoB,WAAWD,CAAG,SAASA,CAAG,KAAKK,CAAI,OACvD,OAAO,aAAa,QAAQL,GAAKK,CAAI;AAAA,IACzC,QAAiB;AAAA,IAAE;AAAA,EAChB,GAGD,OAAO,sBAAsBH,GAAM;AACrC,GAAK;"}
|
package/mtds/app/app.js
CHANGED
|
@@ -32,7 +32,7 @@ import "../togglegroup/togglegroup.js";
|
|
|
32
32
|
import "../typography/typography.js";
|
|
33
33
|
import "../validation/validation.js";
|
|
34
34
|
import a from "../styles.module.css.js";
|
|
35
|
-
import d from "./app-
|
|
35
|
+
import d from "./app-toggle.js";
|
|
36
36
|
const f = p(function({ as: t, className: r, ...m }, n) {
|
|
37
37
|
return /* @__PURE__ */ o(t || "div", { className: e(a.app, r), ref: n, ...m });
|
|
38
38
|
}), u = p(function({ as: t, className: r, ...m }, n) {
|
|
@@ -1,70 +1,75 @@
|
|
|
1
|
-
import { UHTMLComboboxElement as
|
|
2
|
-
import { UHTMLDataListElement as
|
|
3
|
-
import
|
|
4
|
-
import { onLoaded as I, onMutation as
|
|
5
|
-
const
|
|
1
|
+
import { UHTMLComboboxElement as g } from "../external/@u-elements/u-combobox/dist/u-combobox.js";
|
|
2
|
+
import { UHTMLDataListElement as S } from "../external/@u-elements/u-datalist/dist/u-datalist.js";
|
|
3
|
+
import v from "../styles.module.css.js";
|
|
4
|
+
import { onLoaded as I, onMutation as M, on as m, QUICK_EVENT as u, isInputLike as x, attr as i, useId as h, anchorPosition as p } from "../utils.js";
|
|
5
|
+
const b = v.field.split(" ")[0], y = v.validation.split(" "), A = y[0], a = (t, o) => {
|
|
6
6
|
var n;
|
|
7
7
|
return ((n = t.getPropertyValue(`--mtds-text-${o}`)) == null ? void 0 : n.slice(1, -1)) || "";
|
|
8
8
|
};
|
|
9
|
-
function
|
|
10
|
-
for (const
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
let c = null,
|
|
14
|
-
for (const e of
|
|
15
|
-
e instanceof HTMLLabelElement ?
|
|
16
|
-
if (
|
|
17
|
-
for (const e of
|
|
18
|
-
|
|
9
|
+
function L(t, o) {
|
|
10
|
+
for (const n of t)
|
|
11
|
+
if (n.isConnected) {
|
|
12
|
+
const s = [], r = [], f = [];
|
|
13
|
+
let c = null, d = null, l = !0;
|
|
14
|
+
for (const e of n.getElementsByTagName("*"))
|
|
15
|
+
e instanceof HTMLLabelElement ? s.push(e) : e instanceof g ? c = e : x(e) ? d = e : e.hasAttribute("data-description") ? r.push(e) : e.classList.contains(A) ? (l = i(e, "data-color") === "success" || !e.clientHeight, f.push(e), r.unshift(e)) : e instanceof HTMLParagraphElement && (r.some((E) => E.contains(e)) || r.push(e));
|
|
16
|
+
if (d) {
|
|
17
|
+
for (const e of s) e.htmlFor = h(d);
|
|
18
|
+
if (o && i(n, "data-validation") === "form") {
|
|
19
|
+
l = d.matches(":valid");
|
|
20
|
+
for (const e of f) i(e, "hidden", l ? "" : null);
|
|
21
|
+
}
|
|
22
|
+
H(c), C(d), T(d), i(d, "aria-describedby", r.map(h).join(" ") || null), i(d, "aria-invalid", `${!l}`);
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
|
-
function
|
|
26
|
+
function T(t) {
|
|
23
27
|
t instanceof HTMLTextAreaElement && (t.style.setProperty("--mtds-textarea-height", "auto"), t.style.setProperty(
|
|
24
28
|
"--mtds-textarea-height",
|
|
25
29
|
`${t.scrollHeight}px`
|
|
26
30
|
));
|
|
27
31
|
}
|
|
28
|
-
function
|
|
32
|
+
function H(t) {
|
|
29
33
|
var n;
|
|
30
34
|
if (!(t != null && t.list) || (n = t.list) != null && n.hasAttribute("popover")) return;
|
|
31
35
|
const o = window.getComputedStyle(t);
|
|
32
36
|
i(t, "data-sr-added", a(o, "combobox-added")), i(t, "data-sr-empty", a(o, "combobox-empty")), i(t, "data-sr-found", a(o, "combobox-found")), i(t, "data-sr-invalid", a(o, "combobox-invalid")), i(t, "data-sr-of", a(o, "combobox-of")), i(t, "data-sr-remove", a(o, "combobox-remove")), i(t, "data-sr-removed", a(o, "combobox-removed")), i(t.list, "data-sr-plural", a(o, "datalist-plural")), i(t.list, "data-sr-singular", a(o, "datalist-singular")), i(t.list, "popover", "manual");
|
|
33
37
|
}
|
|
34
|
-
function
|
|
38
|
+
function C(t) {
|
|
35
39
|
const o = t == null ? void 0 : t.nextElementSibling, n = o && i(o, "data-count");
|
|
36
40
|
if (o && n) {
|
|
37
|
-
const s = Number(n) - t.value.length,
|
|
38
|
-
if (
|
|
39
|
-
i(o, "aria-live",
|
|
40
|
-
for (const
|
|
41
|
+
const s = Number(n) - t.value.length, r = s < 0, f = i(o, "aria-live") === "polite", c = window.getComputedStyle(o || t), d = a(c, "count-over"), l = a(c, "count-under");
|
|
42
|
+
if (f !== r) {
|
|
43
|
+
i(o, "aria-live", r ? "polite" : "off");
|
|
44
|
+
for (const e of y) o.classList.toggle(e, r);
|
|
41
45
|
}
|
|
42
|
-
o.textContent = (
|
|
46
|
+
o.textContent = (r ? d : l).replace(
|
|
43
47
|
"%d",
|
|
44
48
|
`${Math.abs(s)}`
|
|
45
49
|
);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
function
|
|
49
|
-
if (t instanceof
|
|
52
|
+
function N({ target: t, newState: o }) {
|
|
53
|
+
if (t instanceof S) {
|
|
50
54
|
const n = t.getRootNode(), s = n == null ? void 0 : n.querySelector(
|
|
51
55
|
`[popovertarget="${t.id}"]`
|
|
52
56
|
);
|
|
53
|
-
o === "closed" ?
|
|
57
|
+
o === "closed" ? p(t, !1) : s && (t.style.width = `${s.clientWidth}px`, p(t, s, "bottom", !0));
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
function $({ target: t }) {
|
|
57
|
-
|
|
61
|
+
x(t) && (C(t), T(t));
|
|
58
62
|
}
|
|
59
|
-
function
|
|
60
|
-
var
|
|
61
|
-
(
|
|
63
|
+
function w(t) {
|
|
64
|
+
var n, s;
|
|
65
|
+
const o = (s = (n = t.target) == null ? void 0 : n.closest) == null ? void 0 : s.call(n, `.${b}`);
|
|
66
|
+
t.type === "invalid" && o && t.preventDefault(), L(document.getElementsByClassName(b), !0);
|
|
62
67
|
}
|
|
63
|
-
function
|
|
64
|
-
const o = t instanceof
|
|
65
|
-
o && !(o != null && o.hidden) && setTimeout(() =>
|
|
68
|
+
function D({ target: t }) {
|
|
69
|
+
const o = t instanceof g && t.list;
|
|
70
|
+
o && !(o != null && o.hidden) && setTimeout(() => p(o, t, 2, !0), 10);
|
|
66
71
|
}
|
|
67
72
|
I(() => {
|
|
68
|
-
|
|
73
|
+
M(document.documentElement, b, L), m(document, "beforechange", D, u), m(document, "input", $, u), m(document, "invalid,submit", w, !0), m(document, "toggle", N, u);
|
|
69
74
|
});
|
|
70
75
|
//# sourceMappingURL=field-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tQUICK_EVENT,\n\tanchorPosition,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el)) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descs.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid =\n\t\t\t\t\t\tattr(el, \"data-color\") === \"success\" ||\n\t\t\t\t\t\t!el.clientWidth ||\n\t\t\t\t\t\t!el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tif (!el?.list || el.list?.hasAttribute(\"popover\")) return;\n\tconst style = window.getComputedStyle(el);\n\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\tattr(el.list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\tattr(el.list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\tattr(el.list, \"popover\", \"manual\");\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleToggle({ target: el, newState }: Event & { newState?: string }) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor) {\n\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\tanchorPosition(el, anchor, \"bottom\", true);\n\t\t}\n\t}\n}\n// Update when typing\nfunction handleInput({ target }: Event) {\n\tif (isInputLike(target)) {\n\t\trenderCounter(target);\n\t\trenderTextareaSize(target);\n\t}\n}\n\n// Prevent browsers from showing default validation bubbles\nfunction handleInvalid(event: Event) {\n\tif ((event.target as Element)?.closest?.(`.${CSS_FIELD}`))\n\t\tevent.preventDefault();\n}\n\n// Position combobox when changing content\nfunction handleBeforeChange({ target: el }: Event) {\n\tconst list = el instanceof UHTMLComboboxElement && el.list;\n\tif (list && !list?.hidden)\n\t\tsetTimeout(() => anchorPosition(list, el, 2, true), 10); // Reposition list if not hidden\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"beforechange\", handleBeforeChange, QUICK_EVENT);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid\", handleInvalid, true); // Use capture as invalid does noe bubble\n\ton(document, \"toggle\", handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","_a","handleMutation","fields","field","labels","descs","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleToggle","newState","UHTMLDataListElement","root","anchor","anchorPosition","handleInput","target","handleInvalid","event","_b","handleBeforeChange","list","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAcA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAElCE,IAAU,CAACC,GAA4BC,MAAA;;AAC5C,WAAAC,IAAAF,EAAM,iBAAiB,eAAeC,CAAG,EAAE,MAA3C,gBAAAC,EAA8C,MAAM,GAAG,QAAO;AAAA;AAE/D,SAASC,EAAeC,GAAmC;AAC1D,aAAWC,KAASD;AACnB,QAAIC,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAC,GAC9BC,IAAmB,CAAC;AAC1B,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMN,EAAM,qBAAqB,GAAG;AAC9C,QAAIM,aAAc,mBAAyBL,EAAA,KAAKK,CAAE,I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GzB,IAAImB,MAAa,WAAyBI,EAAAvB,GAAI,EAAK,IAC1CsB,MACRtB,EAAG,MAAM,QAAQ,GAAGsB,EAAO,WAAW,MACvBC,EAAAvB,GAAIsB,GAAQ,UAAU,EAAI;AAAA,EAC1C;AAEF;AAEA,SAASE,EAAY,EAAE,QAAAC,KAAiB;AACnC,EAAAvB,EAAYuB,CAAM,MACrBjB,EAAciB,CAAM,GACpBhB,EAAmBgB,CAAM;AAE3B;AAGA,SAASC,EAAcC,GAAc;;AACpC,GAAKC,KAAArC,IAAAoC,EAAM,WAAN,gBAAApC,EAA0B,YAA1B,QAAAqC,EAAA,KAAArC,GAAoC,IAAIP,CAAS,OACrD2C,EAAM,eAAe;AACvB;AAGA,SAASE,EAAmB,EAAE,QAAQ7B,KAAa;AAC5C,QAAA8B,IAAO9B,aAAcC,KAAwBD,EAAG;AAClD,EAAA8B,KAAQ,EAACA,KAAA,QAAAA,EAAM,WAClB,WAAW,MAAMP,EAAeO,GAAM9B,GAAI,GAAG,EAAI,GAAG,EAAE;AACxD;AAEA+B,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiBhD,GAAWQ,CAAc,GAC3DyC,EAAA,UAAU,gBAAgBJ,GAAoBK,CAAW,GACzDD,EAAA,UAAU,SAAST,GAAaU,CAAW,GAC3CD,EAAA,UAAU,WAAWP,GAAe,EAAI,GACxCO,EAAA,UAAU,UAAUf,GAAcgB,CAAW;AACjD,CAAC;"}
|
|
1
|
+
{"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tQUICK_EVENT,\n\tanchorPosition,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>, validate?: boolean) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tconst valids: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el)) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descs.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalids.push(el);\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\tif (validate && attr(field, \"data-validation\") === \"form\") {\n\t\t\t\t\tvalid = input.matches(\":valid\");\n\t\t\t\t\tfor (const el of valids) attr(el, \"hidden\", valid ? \"\" : null);\n\t\t\t\t}\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tif (!el?.list || el.list?.hasAttribute(\"popover\")) return;\n\tconst style = window.getComputedStyle(el);\n\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\tattr(el.list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\tattr(el.list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\tattr(el.list, \"popover\", \"manual\");\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleToggle({ target: el, newState }: Event & { newState?: string }) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor) {\n\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\tanchorPosition(el, anchor, \"bottom\", true);\n\t\t}\n\t}\n}\n// Update when typing\nfunction handleInput({ target }: Event) {\n\tif (isInputLike(target)) {\n\t\trenderCounter(target);\n\t\trenderTextareaSize(target);\n\t}\n}\n\nfunction handleValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleMutation(document.getElementsByClassName(CSS_FIELD), true); // Update state\n}\n\n// Position combobox when changing content\nfunction handleBeforeChange({ target: el }: Event) {\n\tconst list = el instanceof UHTMLComboboxElement && el.list;\n\tif (list && !list?.hidden)\n\t\tsetTimeout(() => anchorPosition(list, el, 2, true), 10); // Reposition list if not hidden\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"beforechange\", handleBeforeChange, QUICK_EVENT);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid,submit\", handleValdiation, true); // Use capture as invalid and submit does not bubble\n\ton(document, \"toggle\", handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","_a","handleMutation","fields","validate","field","labels","descs","valids","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleToggle","newState","UHTMLDataListElement","root","anchor","anchorPosition","handleInput","target","handleValdiation","event","_b","handleBeforeChange","list","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAcA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAElCE,IAAU,CAACC,GAA4BC,MAAA;;AAC5C,WAAAC,IAAAF,EAAM,iBAAiB,eAAeC,CAAG,EAAE,MAA3C,gBAAAC,EAA8C,MAAM,GAAG,QAAO;AAAA;AAE/D,SAASC,EAAeC,GAAmCC,GAAoB;AAC9E,aAAWC,KAASF;AACnB,QAAIE,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAC,GAC9BC,IAAmB,CAAC,GACpBC,IAAoB,CAAC;AAC3B,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMP,EAAM,qBAAqB,GAAG;AAC9C,QAAIO,aAAc,mBAAyBN,EAAA,KAAKM,CAAE,IACzCA,aAAcC,IAAiCJ,IAAAG,IAC/CE,EAAYF,CAAE,IAAWF,IAAAE,IACzBA,EAAG,aAAa,kBAAkB,IAAGL,EAAM,KAAKK,CAAE,IAClDA,EAAG,UAAU,SAASf,CAAc,KAC5Cc,IAAQI,EAAKH,GAAI,YAAY,MAAM,aAAa,CAACA,EAAG,cACpDJ,EAAO,KAAKI,CAAE,GACdL,EAAM,QAAQK,CAAE,KACNA,aAAc,yBAClBL,EAAA,KAAK,CAACS,MAASA,EAAK,SAASJ,CAAE,CAAC,KAAKL,EAAM,KAAKK,CAAE;AAG1D,UAAIF,GAAO;AACV,mBAAWO,KAASX,EAAc,CAAAW,EAAA,UAAUC,EAAMR,CAAK;AACvD,YAAIN,KAAYW,EAAKV,GAAO,iBAAiB,MAAM,QAAQ;AAClD,UAAAM,IA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lC,KAASmC,KAAAvC,IAAAsC,EAAM,WAAN,gBAAAtC,EAA0B,YAA1B,gBAAAuC,EAAA,KAAAvC,GAAoC,IAAIP,CAAS;AAEhE,EAAI6C,EAAM,SAAS,aAAalC,OAAa,eAAe,GAC5DH,EAAe,SAAS,uBAAuBR,CAAS,GAAG,EAAI;AAChE;AAGA,SAAS+C,EAAmB,EAAE,QAAQ7B,KAAa;AAC5C,QAAA8B,IAAO9B,aAAcC,KAAwBD,EAAG;AAClD,EAAA8B,KAAQ,EAACA,KAAA,QAAAA,EAAM,WAClB,WAAW,MAAMP,EAAeO,GAAM9B,GAAI,GAAG,EAAI,GAAG,EAAE;AACxD;AAEA+B,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiBlD,GAAWQ,CAAc,GAC3D2C,EAAA,UAAU,gBAAgBJ,GAAoBK,CAAW,GACzDD,EAAA,UAAU,SAAST,GAAaU,CAAW,GAC3CD,EAAA,UAAU,kBAAkBP,GAAkB,EAAI,GAClDO,EAAA,UAAU,UAAUf,GAAcgB,CAAW;AACjD,CAAC;"}
|
|
@@ -158,6 +158,7 @@ export declare const Required: Story;
|
|
|
158
158
|
export declare const Indeterminate: Story;
|
|
159
159
|
export declare const Toggles: Story;
|
|
160
160
|
export declare const WithValidation: Story;
|
|
161
|
+
export declare const WithValidationForm: Story;
|
|
161
162
|
export declare const WithAffixes: Story;
|
|
162
163
|
export declare const WithCharacterCount: Story;
|
|
163
164
|
export declare const WithCustomDescriptionTag: Story;
|