@mattilsynet/design 3.1.10 → 3.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/utils.d.ts CHANGED
@@ -69,3 +69,10 @@ export declare const MTDSElement: {
69
69
  * @description Defines a customElement if running in browser and if not already registered
70
70
  */
71
71
  export declare const defineElement: (name: string, instance: CustomElementConstructor) => true | void | CustomElementConstructor;
72
+ /**
73
+ * attachStyle
74
+ * @param el The Element to scope styles for
75
+ * @param css The css to inject
76
+ */
77
+ export declare const SUPPORTS_CONSTRUCTED_CSS: false | CSSStyleSheet[];
78
+ export declare const attachStyle: (el: Element, css: string) => void;
package/mtds/utils.js CHANGED
@@ -1,36 +1,36 @@
1
1
  import u from "clsx";
2
- import l from "./styles.module.css.js";
3
- const E = { capture: !0, passive: !0 }, d = () => typeof window < "u" && typeof document < "u", y = (e) => d() ? document.getElementsByClassName(l[e].split(" ")[0]) : [];
4
- function C(e, t) {
5
- let n;
6
- return function(...o) {
7
- clearTimeout(n), n = setTimeout(() => e.apply(this, o), t);
2
+ import a from "./styles.module.css.js";
3
+ const E = { capture: !0, passive: !0 }, r = () => typeof window < "u" && typeof document < "u", C = (e) => r() ? document.getElementsByClassName(a[e].split(" ")[0]) : [];
4
+ function h(e, t) {
5
+ let o;
6
+ return function(...n) {
7
+ clearTimeout(o), o = setTimeout(() => e.apply(this, n), t);
8
8
  };
9
9
  }
10
- const a = (e, t, n) => n === void 0 ? e.getAttribute(t) ?? null : (n === null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n), null), m = (e, ...t) => {
11
- const [n, ...o] = t;
12
- for (const s of n.split(" ")) e.addEventListener(s, ...o);
10
+ const l = (e, t, o) => o === void 0 ? e.getAttribute(t) ?? null : (o === null ? e.removeAttribute(t) : e.getAttribute(t) !== o && e.setAttribute(t, o), null), p = (e, ...t) => {
11
+ const [o, ...n] = t;
12
+ for (const s of o.split(" ")) e.addEventListener(s, ...n);
13
13
  return () => f(e, ...t);
14
14
  }, f = (e, ...t) => {
15
- const [n, ...o] = t;
16
- for (const s of n.split(" ")) e.removeEventListener(s, ...o);
17
- }, b = (e, t) => {
18
- if (!d()) return;
15
+ const [o, ...n] = t;
16
+ for (const s of o.split(" ")) e.removeEventListener(s, ...n);
17
+ }, T = (e, t) => {
18
+ if (!r()) return;
19
19
  window._mtdsHotReloadCleanup || (window._mtdsHotReloadCleanup = /* @__PURE__ */ new Map());
20
- const n = () => {
21
- window._mtdsHotReloadCleanup?.get(e)?.map((o) => o()), window._mtdsHotReloadCleanup?.set(e, t());
20
+ const o = () => {
21
+ window._mtdsHotReloadCleanup?.get(e)?.map((n) => n()), window._mtdsHotReloadCleanup?.set(e, t());
22
22
  };
23
- document.readyState !== "complete" ? m(window, "load", n) : document.fonts?.ready?.then(n) || setTimeout(n, 0);
24
- }, g = (e, t, n) => {
25
- let o = 0;
23
+ document.readyState !== "complete" ? p(window, "load", o) : document.fonts?.ready?.then(o) || setTimeout(o, 0);
24
+ }, b = (e, t, o) => {
25
+ let n = 0;
26
26
  const s = () => {
27
27
  if (!e.isConnected) return i();
28
- t(r), r.takeRecords(), o = 0;
29
- }, i = () => r?.disconnect?.(), r = new MutationObserver(() => {
30
- o || (o = requestAnimationFrame(s));
28
+ t(d), d.takeRecords(), n = 0;
29
+ }, i = () => d?.disconnect?.(), d = new MutationObserver(() => {
30
+ n || (n = requestAnimationFrame(s));
31
31
  });
32
- return r.observe(e, n), s(), i;
33
- }, c = "aria-selected", v = (e, t) => Object.assign({}, e, {
32
+ return d.observe(e, o), s(), i;
33
+ }, c = "aria-selected", R = (e, t) => Object.assign({}, e, {
34
34
  suppressHydrationWarning: !0,
35
35
  // Make Next.js happy
36
36
  [c]: e[c] === void 0 ? void 0 : `${(e[c] || "false") !== "false"}`,
@@ -41,25 +41,32 @@ const a = (e, t, n) => n === void 0 ? e.getAttribute(t) ?? null : (n === null ?
41
41
  // Ensure boolean prop behaviour
42
42
  open: !!e.open
43
43
  // Ensure boolean prop behaviour
44
- }), H = (e, t, n) => {
45
- const o = document.createElement(e);
46
- if (n && (o.textContent = n), t) for (const [s, i] of Object.entries(t)) a(o, s, i);
47
- return o;
48
- }, T = typeof HTMLElement > "u" ? class {
49
- } : HTMLElement, M = (e, t) => !d() || window.customElements.get(e) || window.customElements.define(e, t);
44
+ }), m = (e, t, o) => {
45
+ const n = document.createElement(e);
46
+ if (o && (n.textContent = o), t) for (const [s, i] of Object.entries(t)) l(n, s, i);
47
+ return n;
48
+ }, g = typeof HTMLElement > "u" ? class {
49
+ } : HTMLElement, v = (e, t) => !r() || window.customElements.get(e) || window.customElements.define(e, t), w = typeof window < "u" && window.CSSStyleSheet && document.adoptedStyleSheets, H = (e, t) => {
50
+ if (!w) return;
51
+ e.shadowRoot || e.attachShadow({ mode: "open" }).append(m("slot"));
52
+ const o = new CSSStyleSheet();
53
+ o.replaceSync(t), e.shadowRoot.adoptedStyleSheets = [o];
54
+ };
50
55
  export {
51
- T as MTDSElement,
56
+ g as MTDSElement,
52
57
  E as QUICK_EVENT,
53
- a as attr,
54
- C as debounce,
55
- M as defineElement,
56
- y as getByCSSModule,
57
- d as isBrowser,
58
+ w as SUPPORTS_CONSTRUCTED_CSS,
59
+ H as attachStyle,
60
+ l as attr,
61
+ h as debounce,
62
+ v as defineElement,
63
+ C as getByCSSModule,
64
+ r as isBrowser,
58
65
  f as off,
59
- m as on,
60
- b as onHotReload,
61
- g as onMutation,
62
- H as tag,
63
- v as toCustomElementProps
66
+ p as on,
67
+ T as onHotReload,
68
+ b as onMutation,
69
+ m as tag,
70
+ R as toCustomElementProps
64
71
  };
65
72
  //# sourceMappingURL=utils.js.map
package/mtds/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const isBrowser = () =>\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\"; // Using function to play nice with Vitest where DOM can come and go\n\nexport const getByCSSModule = (key: string) =>\n\tisBrowser() ? document.getElementsByClassName(styles[key].split(\" \")[0]) : [];\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn function (this: unknown, ...args: T) {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback.apply(this, args), delay);\n\t};\n}\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to read/write attributes from\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport const attr = (\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null => {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n};\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.addEventListener(type, ...options);\n\treturn () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.removeEventListener(type, ...options);\n};\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsHotReloadCleanup?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n\tif (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n\tif (!window._mtdsHotReloadCleanup) window._mtdsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n\tconst run = () => {\n\t\twindow._mtdsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n\t\twindow._mtdsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n\t};\n\n\tif (document.readyState !== \"complete\") on(window, \"load\", run);\n\telse document.fonts?.ready?.then(run) || setTimeout(run, 0); // Prefer fonts ready promise if available, but fallback to setTimeout\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport const onMutation = (\n\tel: Node,\n\tcallback: (observer: MutationObserver) => void,\n\toptions: MutationObserverInit,\n) => {\n\tlet queue = 0;\n\tconst onFrame = () => {\n\t\tif (!el.isConnected) return cleanup(); // Disconnect if element is removed from DOM\n\t\tcallback(observer);\n\t\tobserver.takeRecords(); // Clear records to avoid multiple triggers\n\t\tqueue = 0;\n\t};\n\tconst cleanup = () => observer?.disconnect?.();\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame); // requestAnimationFrame only runs when page is visible\n\t});\n\n\tobserver.observe(el, options);\n\tonFrame(); // Initial run\n\treturn cleanup;\n};\n\n/**\n * toCustomElementProps\n * @description Utility to quickly convert props to custom element attributes\n * @param props The props to convert\n * @returns The converted props\n */\nconst SELECTED = \"aria-selected\";\nexport const toCustomElementProps = <T extends Record<string, unknown>>(\n\trest: T,\n\tklass?: string,\n) =>\n\tObject.assign({}, rest, {\n\t\tsuppressHydrationWarning: true, // Make Next.js happy\n\t\t[SELECTED]:\n\t\t\trest[SELECTED] === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (`${(rest[SELECTED] || \"false\") !== \"false\"}` as unknown as boolean), // Ensure aria-selected boolean is string\n\t\tclass: clsx(klass, rest.className as string), // Use class instead of className\n\t\thidden: !!rest.hidden, // Ensure boolean prop behaviour\n\t\topen: !!rest.open, // Ensure boolean prop behaviour\n\t});\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n\ttagName: TagName,\n\tattrs?: Record<string, string | null> | null,\n\ttext?: string | null,\n): HTMLElementTagNameMap[TagName] => {\n\tconst el = document.createElement(tagName);\n\tif (text) el.textContent = text;\n\tif (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n\treturn el;\n};\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const MTDSElement =\n\ttypeof HTMLElement === \"undefined\"\n\t\t? (class {} as typeof HTMLElement)\n\t\t: HTMLElement;\n\n/**\n * defineElement\n * @description Defines a customElement if running in browser and if not already registered\n */\nexport const defineElement = (\n\tname: string,\n\tinstance: CustomElementConstructor,\n) =>\n\t!isBrowser() ||\n\twindow.customElements.get(name) ||\n\twindow.customElements.define(name, instance);\n"],"names":["QUICK_EVENT","isBrowser","getByCSSModule","key","styles","debounce","callback","delay","timer","args","attr","el","name","value","on","rest","types","options","type","off","onHotReload","setup","run","cleanup","onMutation","queue","onFrame","observer","SELECTED","toCustomElementProps","klass","clsx","tag","tagName","attrs","text","val","MTDSElement","defineElement","instance"],"mappings":";;AAGO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,IAAY,MACxB,OAAO,SAAW,OAAe,OAAO,WAAa,KAEzCC,IAAiB,CAACC,MAC9BF,EAAA,IAAc,SAAS,uBAAuBG,EAAOD,CAAG,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;AAErE,SAASE,EACfC,GACAC,GACC;AACD,MAAIC;AAEJ,SAAO,YAA4BC,GAAS;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B,CAAQ,GACjBA,EAAS,YAAA,GACTF,IAAQ;AAAA,EACT,GACMF,IAAU,MAAMI,GAAU,aAAA,GAC1BA,IAAW,IAAI,iBAAiB,MAAM;AAC3C,IAAKF,MAAOA,IAAQ,sBAAsBC,CAAO;AAAA,EAClD,CAAC;AAED,SAAAC,EAAS,QAAQhB,GAAIM,CAAO,GAC5BS,EAAA,GACOH;AACR,GAQMK,IAAW,iBACJC,IAAuB,CACnCd,GACAe,MAEA,OAAO,OAAO,CAAA,GAAIf,GAAM;AAAA,EACvB,0BAA0B;AAAA;AAAA,EAC1B,CAACa,CAAQ,GACRb,EAAKa,CAAQ,MAAM,SAChB,SACC,IAAIb,EAAKa,CAAQ,KAAK,aAAa,OAAO;AAAA;AAAA,EAC/C,OAAOG,EAAKD,GAAOf,EAAK,SAAmB;AAAA;AAAA,EAC3C,QAAQ,CAAC,CAACA,EAAK;AAAA;AAAA,EACf,MAAM,CAAC,CAACA,EAAK;AAAA;AACd,CAAC,GAUWiB,IAAM,CAClBC,GACAC,GACAC,MACoC;AACpC,QAAMxB,IAAK,SAAS,cAAcsB,CAAO;AAEzC,MADIE,QAAS,cAAcA,IACvBD,EAAO,YAAW,CAAC/B,GAAKiC,CAAG,KAAK,OAAO,QAAQF,CAAK,EAAG,CAAAxB,EAAKC,GAAIR,GAAKiC,CAAG;AAC5E,SAAOzB;AACR,GAGa0B,IACZ,OAAO,cAAgB,MACnB,MAAM;AAAC,IACR,aAMSC,IAAgB,CAC5B1B,GACA2B,MAEA,CAACtC,OACD,OAAO,eAAe,IAAIW,CAAI,KAC9B,OAAO,eAAe,OAAOA,GAAM2B,CAAQ;"}
1
+ {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const isBrowser = () =>\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\"; // Using function to play nice with Vitest where DOM can come and go\n\nexport const getByCSSModule = (key: string) =>\n\tisBrowser() ? document.getElementsByClassName(styles[key].split(\" \")[0]) : [];\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn function (this: unknown, ...args: T) {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback.apply(this, args), delay);\n\t};\n}\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to read/write attributes from\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport const attr = (\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null => {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n};\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.addEventListener(type, ...options);\n\treturn () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.removeEventListener(type, ...options);\n};\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsHotReloadCleanup?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n\tif (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n\tif (!window._mtdsHotReloadCleanup) window._mtdsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n\tconst run = () => {\n\t\twindow._mtdsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n\t\twindow._mtdsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n\t};\n\n\tif (document.readyState !== \"complete\") on(window, \"load\", run);\n\telse document.fonts?.ready?.then(run) || setTimeout(run, 0); // Prefer fonts ready promise if available, but fallback to setTimeout\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport const onMutation = (\n\tel: Node,\n\tcallback: (observer: MutationObserver) => void,\n\toptions: MutationObserverInit,\n) => {\n\tlet queue = 0;\n\tconst onFrame = () => {\n\t\tif (!el.isConnected) return cleanup(); // Disconnect if element is removed from DOM\n\t\tcallback(observer);\n\t\tobserver.takeRecords(); // Clear records to avoid multiple triggers\n\t\tqueue = 0;\n\t};\n\tconst cleanup = () => observer?.disconnect?.();\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame); // requestAnimationFrame only runs when page is visible\n\t});\n\n\tobserver.observe(el, options);\n\tonFrame(); // Initial run\n\treturn cleanup;\n};\n\n/**\n * toCustomElementProps\n * @description Utility to quickly convert props to custom element attributes\n * @param props The props to convert\n * @returns The converted props\n */\nconst SELECTED = \"aria-selected\";\nexport const toCustomElementProps = <T extends Record<string, unknown>>(\n\trest: T,\n\tklass?: string,\n) =>\n\tObject.assign({}, rest, {\n\t\tsuppressHydrationWarning: true, // Make Next.js happy\n\t\t[SELECTED]:\n\t\t\trest[SELECTED] === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (`${(rest[SELECTED] || \"false\") !== \"false\"}` as unknown as boolean), // Ensure aria-selected boolean is string\n\t\tclass: clsx(klass, rest.className as string), // Use class instead of className\n\t\thidden: !!rest.hidden, // Ensure boolean prop behaviour\n\t\topen: !!rest.open, // Ensure boolean prop behaviour\n\t});\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n\ttagName: TagName,\n\tattrs?: Record<string, string | null> | null,\n\ttext?: string | null,\n): HTMLElementTagNameMap[TagName] => {\n\tconst el = document.createElement(tagName);\n\tif (text) el.textContent = text;\n\tif (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n\treturn el;\n};\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const MTDSElement =\n\ttypeof HTMLElement === \"undefined\"\n\t\t? (class {} as typeof HTMLElement)\n\t\t: HTMLElement;\n\n/**\n * defineElement\n * @description Defines a customElement if running in browser and if not already registered\n */\nexport const defineElement = (\n\tname: string,\n\tinstance: CustomElementConstructor,\n) =>\n\t!isBrowser() ||\n\twindow.customElements.get(name) ||\n\twindow.customElements.define(name, instance);\n\n/**\n * attachStyle\n * @param el The Element to scope styles for\n * @param css The css to inject\n */\nexport const SUPPORTS_CONSTRUCTED_CSS =\n\ttypeof window !== \"undefined\" &&\n\twindow.CSSStyleSheet &&\n\tdocument.adoptedStyleSheets;\n\nexport const attachStyle = (el: Element, css: string) => {\n\tif (!SUPPORTS_CONSTRUCTED_CSS) return;\n\tif (!el.shadowRoot) el.attachShadow({ mode: \"open\" }).append(tag(\"slot\"));\n\n\tconst sheet = new CSSStyleSheet();\n\tsheet.replaceSync(css);\n\t(el.shadowRoot as ShadowRoot).adoptedStyleSheets = [sheet];\n};\n"],"names":["QUICK_EVENT","isBrowser","getByCSSModule","key","styles","debounce","callback","delay","timer","args","attr","el","name","value","on","rest","types","options","type","off","onHotReload","setup","run","cleanup","onMutation","queue","onFrame","observer","SELECTED","toCustomElementProps","klass","clsx","tag","tagName","attrs","text","val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,MACnB,MAAM;AAAC,IACR,aAMSC,IAAgB,CAC5B1B,GACA2B,MAEA,CAACtC,OACD,OAAO,eAAe,IAAIW,CAAI,KAC9B,OAAO,eAAe,OAAOA,GAAM2B,CAAQ,GAO/BC,IACZ,OAAO,SAAW,OAClB,OAAO,iBACP,SAAS,oBAEGC,IAAc,CAAC9B,GAAa+B,MAAgB;AACxD,MAAI,CAACF,EAA0B;AAC/B,EAAK7B,EAAG,cAAYA,EAAG,aAAa,EAAE,MAAM,OAAA,CAAQ,EAAE,OAAOqB,EAAI,MAAM,CAAC;AAExE,QAAMW,IAAQ,IAAI,cAAA;AAClB,EAAAA,EAAM,YAAYD,CAAG,GACpB/B,EAAG,WAA0B,qBAAqB,CAACgC,CAAK;AAC1D;"}
@@ -1,40 +1,51 @@
1
- import p from "../styles.module.css.js";
2
- import { onHotReload as E, on as s, onMutation as h, QUICK_EVENT as V, debounce as m, attr as e } from "../utils.js";
3
- const b = `.${p.field.split(" ")[0]}`, N = "input,textarea,select", y = "ds-suggestion,u-combobox", C = p.validation.split(" ")[0], c = (t) => t instanceof HTMLFormElement && e(t, "data-validation") === "form", T = (t) => c(t.form), S = (t) => t.closest("fieldset") || t.closest(b) || t.form, v = (t) => t?.getElementsByClassName(C) || [], d = (t) => {
4
- const n = t?.type === "submit" || t?.type === "invalid";
5
- let i;
6
- for (const r of document.forms)
7
- if (c(r))
8
- for (const o of r.querySelectorAll(N)) {
9
- if (!o.clientHeight) continue;
10
- const a = S(o), u = o.closest(y), I = e(o, "data-validation"), l = u ? e(o, "aria-required") === "true" && !!u?.items.length : o.validity.valid;
11
- if (e(o, "data-validation", `${l}`), !i && !l && (i = o), t || !I)
12
- for (const f of v(a)) {
13
- const g = a?.nodeName === "FIELDSET" && f.parentElement !== a;
14
- e(f, "hidden", g || !n || l ? "" : null);
15
- }
16
- }
17
- i && n && (t.preventDefault(), i.focus());
18
- }, D = ({ target: t }) => {
19
- if (T(t))
20
- for (const n of v(S(t))) e(n, "hidden", "");
21
- }, L = (t) => c(t.target.form) && t?.preventDefault();
22
- E("validations", () => [
23
- s(document, "input", D, !0),
1
+ import g from "../styles.module.css.js";
2
+ import { isBrowser as I, onHotReload as p, on as l, QUICK_EVENT as v, debounce as V, onMutation as A, attr as i } from "../utils.js";
3
+ const h = `.${g.field.split(" ")[0]}`, D = `${h} :is(input,textarea,select)`, E = "ds-suggestion,u-combobox", N = g.validation.split(" ")[0], d = (t) => t instanceof HTMLFormElement && i(t, "data-validation") === "form", a = (t) => t.closest(h), u = (t) => t?.querySelectorAll(D) || [], c = (t) => t?.getElementsByClassName(N) || [], f = (t) => {
4
+ if (!t.clientHeight) return !0;
5
+ const e = t.closest(E)?.items;
6
+ return e ? i(t, "aria-required") === "true" && !!e.length : t.matches(":user-valid");
7
+ }, m = (t) => {
8
+ const e = t.target?.form || t.target;
9
+ let o;
10
+ if (d(e)) {
11
+ for (const n of u(e)) {
12
+ const s = f(n);
13
+ !o && !s && (o = n);
14
+ for (const r of c(a(n)))
15
+ i(r, "hidden", s ? "" : null);
16
+ }
17
+ for (const n of e.querySelectorAll("fieldset")) {
18
+ const s = [...u(n)].every(f);
19
+ for (const r of c(n))
20
+ a(r) || i(r, "hidden", s ? "" : null);
21
+ }
22
+ o && (t.preventDefault(), o.focus());
23
+ }
24
+ }, T = ({ target: t }) => {
25
+ const e = t;
26
+ if (!d(e.form))
27
+ for (const o of c(e.closest("fieldset") || a(e)))
28
+ i(o, "hidden", "");
29
+ }, y = (t) => d(t.target.form) && t?.preventDefault(), S = /* @__PURE__ */ new WeakSet(), C = I() ? c(document) : [], L = () => {
30
+ for (const t of C) {
31
+ if (S.has(t)) continue;
32
+ S.add(t);
33
+ const e = u(a(t))[0];
34
+ d(e?.form) && i(t, "hidden", "");
35
+ }
36
+ };
37
+ p("validations", () => [
38
+ l(document, "input", T, !0),
24
39
  // Hide validation when typing
25
- s(document, "invalid", L, !0),
40
+ l(document, "invalid", y, !0),
26
41
  // Prevent default browser invalid popup
27
- s(document, "invalid", m(d, 10), V),
42
+ l(document, "invalid", V(m, 10), v),
28
43
  // Debounced to group invalid events
29
- s(document, "submit", d, !0),
44
+ l(document, "submit", m, !0),
30
45
  // Use capture as submit does not bubble
31
- h(
32
- document,
33
- m(() => d(), 0),
34
- {
35
- childList: !0,
36
- subtree: !0
37
- }
38
- )
46
+ A(document, L, {
47
+ childList: !0,
48
+ subtree: !0
49
+ })
39
50
  ]);
40
51
  //# sourceMappingURL=validation-observer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation-observer.js","sources":["../../designsystem/validation/validation-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\tdebounce,\n\ton,\n\tonHotReload,\n\tonMutation,\n\tQUICK_EVENT,\n} from \"../utils\";\n\nconst CSS_FIELD = `.${styles.field.split(\" \")[0]}`;\nconst CSS_INPUTS = \"input,textarea,select\" as \"input\";\nconst CSS_SUGGESTION = \"ds-suggestion,u-combobox\" as \"ds-suggestion\"; // u-combobox kept for backward compatibility\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\n\nconst isValidationForm = (form: unknown): form is HTMLFormElement =>\n\tform instanceof HTMLFormElement && attr(form, \"data-validation\") === \"form\";\n\nconst isValidationInput = (input: unknown): input is HTMLInputElement =>\n\tisValidationForm((input as HTMLInputElement).form);\n\nconst getScope = (input: HTMLInputElement) =>\n\tinput.closest(\"fieldset\") || input.closest(CSS_FIELD) || input.form;\n\nconst getValidations = (el?: HTMLElement | null) =>\n\tel?.getElementsByClassName(CSS_VALIDATION) || [];\n\nconst handleValidations = (event?: Event) => {\n\tconst isSubmit = event?.type === \"submit\" || event?.type === \"invalid\";\n\tlet firstInvalid: HTMLInputElement | undefined;\n\n\tfor (const form of document.forms)\n\t\tif (isValidationForm(form))\n\t\t\tfor (const input of form.querySelectorAll(CSS_INPUTS)) {\n\t\t\t\tif (!input.clientHeight) continue; // Skip hidden inputs\n\t\t\t\tconst scope = getScope(input);\n\t\t\t\tconst suggestion = input.closest(CSS_SUGGESTION);\n\t\t\t\tconst prevValid = attr(input, \"data-validation\");\n\t\t\t\tconst nextValid = suggestion\n\t\t\t\t\t? attr(input, \"aria-required\") === \"true\" &&\n\t\t\t\t\t\t!!suggestion?.items.length\n\t\t\t\t\t: input.validity.valid;\n\n\t\t\t\tattr(input, \"data-validation\", `${nextValid}`);\n\t\t\t\tif (!firstInvalid && !nextValid) firstInvalid = input;\n\t\t\t\t// Update if not registered or validation does not match\n\t\t\t\tif (event || !prevValid)\n\t\t\t\t\tfor (const el of getValidations(scope)) {\n\t\t\t\t\t\tconst isNested =\n\t\t\t\t\t\t\tscope?.nodeName === \"FIELDSET\" && el.parentElement !== scope;\n\t\t\t\t\t\tattr(el, \"hidden\", isNested || !isSubmit || nextValid ? \"\" : null);\n\t\t\t\t\t}\n\t\t\t}\n\n\tif (firstInvalid && isSubmit) {\n\t\tevent.preventDefault(); // Prevent submit if focusable invalid element found\n\t\tfirstInvalid.focus(); // Only move focus to first invalid field if validate was true\n\t}\n};\n\nconst handleInput = ({ target }: Event) => {\n\tif (isValidationInput(target))\n\t\tfor (const el of getValidations(getScope(target))) attr(el, \"hidden\", \"\");\n};\n\nconst handleInvalid = (e: Event) =>\n\tisValidationForm((e.target as HTMLInputElement).form) && e?.preventDefault(); // Prevent default browser invalid popup\n\nonHotReload(\"validations\", () => [\n\ton(document, \"input\", handleInput, true), // Hide validation when typing\n\ton(document, \"invalid\", handleInvalid, true), // Prevent default browser invalid popup\n\ton(document, \"invalid\", debounce(handleValidations, 10), QUICK_EVENT), // Debounced to group invalid events\n\ton(document, \"submit\", handleValidations, true), // Use capture as submit does not bubble\n\tonMutation(\n\t\tdocument,\n\t\tdebounce(() => handleValidations(), 0),\n\t\t{\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t},\n\t),\n]);\n"],"names":["CSS_FIELD","styles","CSS_INPUTS","CSS_SUGGESTION","CSS_VALIDATION","isValidationForm","form","attr","isValidationInput","input","getScope","getValidations","el","handleValidations","event","isSubmit","firstInvalid","scope","suggestion","prevValid","nextValid","isNested","handleInput","target","handleInvalid","e","onHotReload","on","debounce","QUICK_EVENT","onMutation"],"mappings":";;AAUA,MAAMA,IAAY,IAAIC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,IAC1CC,IAAa,yBACbC,IAAiB,4BACjBC,IAAiBH,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,GAE/CI,IAAmB,CAACC,MACzBA,aAAgB,mBAAmBC,EAAKD,GAAM,iBAAiB,MAAM,QAEhEE,IAAoB,CAACC,MAC1BJ,EAAkBI,EAA2B,IAAI,GAE5CC,IAAW,CAACD,MACjBA,EAAM,QAAQ,UAAU,KAAKA,EAAM,QAAQT,CAAS,KAAKS,EAAM,MAE1DE,IAAiB,CAACC,MACvBA,GAAI,uBAAuBR,CAAc,KAAK,CAAA,GAEzCS,IAAoB,CAACC,MAAkB;AAC5C,QAAMC,IAAWD,GAAO,SAAS,YAAYA,GAAO,SAAS;AAC7D,MAAIE;AAEJ,aAAWV,KAAQ,SAAS;AAC3B,QAAID,EAAiBC,CAAI;AACxB,iBAAWG,KAASH,EAAK,iBAAiBJ,CAAU,GAAG;AACtD,YAAI,CAACO,EAAM,aAAc;AACzB,cAAMQ,IAAQP,EAASD,CAAK,GACtBS,IAAaT,EAAM,QAAQN,CAAc,GACzCgB,IAAYZ,EAAKE,GAAO,iBAAiB,GACzCW,IAAYF,IACfX,EAAKE,GAAO,eAAe,MAAM,UAClC,CAAC,CAACS,GAAY,MAAM,SACnBT,EAAM,SAAS;AAKlB,YAHAF,EAAKE,GAAO,mBAAmB,GAAGW,CAAS,EAAE,GACzC,CAACJ,KAAgB,CAACI,MAAWJ,IAAeP,IAE5CK,KAAS,CAACK;AACb,qBAAWP,KAAMD,EAAeM,CAAK,GAAG;AACvC,kBAAMI,IACLJ,GAAO,aAAa,cAAcL,EAAG,kBAAkBK;AACxD,YAAAV,EAAKK,GAAI,UAAUS,KAAY,CAACN,KAAYK,IAAY,KAAK,IAAI;AAAA,UAClE;AAAA,MACF;AAEF,EAAIJ,KAAgBD,MACnBD,EAAM,eAAA,GACNE,EAAa,MAAA;AAEf,GAEMM,IAAc,CAAC,EAAE,QAAAC,QAAoB;AAC1C,MAAIf,EAAkBe,CAAM;AAC3B,eAAWX,KAAMD,EAAeD,EAASa,CAAM,CAAC,EAAG,CAAAhB,EAAKK,GAAI,UAAU,EAAE;AAC1E,GAEMY,IAAgB,CAACC,MACtBpB,EAAkBoB,EAAE,OAA4B,IAAI,KAAKA,GAAG,eAAA;AAE7DC,EAAY,eAAe,MAAM;AAAA,EAChCC,EAAG,UAAU,SAASL,GAAa,EAAI;AAAA;AAAA,EACvCK,EAAG,UAAU,WAAWH,GAAe,EAAI;AAAA;AAAA,EAC3CG,EAAG,UAAU,WAAWC,EAASf,GAAmB,EAAE,GAAGgB,CAAW;AAAA;AAAA,EACpEF,EAAG,UAAU,UAAUd,GAAmB,EAAI;AAAA;AAAA,EAC9CiB;AAAA,IACC;AAAA,IACAF,EAAS,MAAMf,EAAA,GAAqB,CAAC;AAAA,IACrC;AAAA,MACC,WAAW;AAAA,MACX,SAAS;AAAA,IAAA;AAAA,EACV;AAEF,CAAC;"}
1
+ {"version":3,"file":"validation-observer.js","sources":["../../designsystem/validation/validation-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\tdebounce,\n\tisBrowser,\n\ton,\n\tonHotReload,\n\tonMutation,\n\tQUICK_EVENT,\n} from \"../utils\";\n\nconst CSS_FIELD = `.${styles.field.split(\" \")[0]}`;\nconst CSS_INPUTS = `${CSS_FIELD} :is(input,textarea,select)` as \"input\";\nconst CSS_SUGGESTION = \"ds-suggestion,u-combobox\" as \"ds-suggestion\"; // u-combobox kept for backward compatibility\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\n\nconst isValidationForm = (form: unknown): form is HTMLFormElement =>\n\tform instanceof HTMLFormElement && attr(form, \"data-validation\") === \"form\";\n\nconst getField = (el: Element) => el.closest(CSS_FIELD);\nconst getInputs = (el?: Element | Document | null) =>\n\tel?.querySelectorAll(CSS_INPUTS) || [];\n\nconst getValidations = (el?: Element | Document | null) =>\n\tel?.getElementsByClassName(CSS_VALIDATION) || [];\n\nconst getValidity = (input: Element) => {\n\tif (!input.clientHeight) return true; // Skip hidden inputs\n\tconst suggestion = input.closest(CSS_SUGGESTION)?.items;\n\tif (!suggestion) return input.matches(\":user-valid\");\n\treturn attr(input, \"aria-required\") === \"true\" && !!suggestion.length;\n};\n\n// Hide or show validations on submit or invalid event\nconst handleValidations = (event: Event) => {\n\tconst form = (event.target as HTMLInputElement)?.form || event.target;\n\tlet invalid: HTMLInputElement | undefined;\n\tif (!isValidationForm(form)) return;\n\n\t// Toggle validitiy of fields\n\tfor (const input of getInputs(form)) {\n\t\tconst isValid = getValidity(input);\n\t\tif (!invalid && !isValid) invalid = input;\n\t\tfor (const el of getValidations(getField(input)))\n\t\t\tattr(el, \"hidden\", isValid ? \"\" : null);\n\t}\n\n\t// Toggle validitiy of fieldset\n\tfor (const fieldset of form.querySelectorAll(\"fieldset\")) {\n\t\tconst isValid = [...getInputs(fieldset)].every(getValidity);\n\t\tfor (const el of getValidations(fieldset))\n\t\t\tif (!getField(el)) attr(el, \"hidden\", isValid ? \"\" : null); // Only toggle fieldset validations if they are not also in a field\n\t}\n\n\tif (!invalid) return;\n\tevent.preventDefault(); // Prevent submit if focusable invalid element found\n\tinvalid.focus(); // Only move focus to first invalid field if validate was true\n};\n\n// Hide related validations adain when typing\nconst handleInput = ({ target }: Event) => {\n\tconst input = target as HTMLInputElement;\n\tif (isValidationForm(input.form)) return;\n\tfor (const el of getValidations(input.closest(\"fieldset\") || getField(input)))\n\t\tattr(el, \"hidden\", \"\");\n};\n\n// Hide native browser validation popup\nconst handleInvalid = (e: Event) =>\n\tisValidationForm((e.target as HTMLInputElement).form) && e?.preventDefault();\n\n// Hide validations when added to the DOM\nconst VALIDATIONS_ADDED = new WeakSet<Element>();\nconst VALIDATIONS = isBrowser() ? getValidations(document) : [];\nconst handleMutation = () => {\n\tfor (const valid of VALIDATIONS) {\n\t\tif (VALIDATIONS_ADDED.has(valid)) continue;\n\t\tVALIDATIONS_ADDED.add(valid);\n\t\tconst input = getInputs(getField(valid))[0];\n\t\tif (isValidationForm(input?.form)) attr(valid, \"hidden\", \"\");\n\t}\n};\n\nonHotReload(\"validations\", () => [\n\ton(document, \"input\", handleInput, true), // Hide validation when typing\n\ton(document, \"invalid\", handleInvalid, true), // Prevent default browser invalid popup\n\ton(document, \"invalid\", debounce(handleValidations, 10), QUICK_EVENT), // Debounced to group invalid events\n\ton(document, \"submit\", handleValidations, true), // Use capture as submit does not bubble\n\tonMutation(document, handleMutation, {\n\t\tchildList: true,\n\t\tsubtree: true,\n\t}),\n]);\n"],"names":["CSS_FIELD","styles","CSS_INPUTS","CSS_SUGGESTION","CSS_VALIDATION","isValidationForm","form","attr","getField","el","getInputs","getValidations","getValidity","input","suggestion","handleValidations","event","invalid","isValid","fieldset","handleInput","target","handleInvalid","e","VALIDATIONS_ADDED","VALIDATIONS","isBrowser","handleMutation","valid","onHotReload","on","debounce","QUICK_EVENT","onMutation"],"mappings":";;AAWA,MAAMA,IAAY,IAAIC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,IAC1CC,IAAa,GAAGF,CAAS,+BACzBG,IAAiB,4BACjBC,IAAiBH,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,GAE/CI,IAAmB,CAACC,MACzBA,aAAgB,mBAAmBC,EAAKD,GAAM,iBAAiB,MAAM,QAEhEE,IAAW,CAACC,MAAgBA,EAAG,QAAQT,CAAS,GAChDU,IAAY,CAACD,MAClBA,GAAI,iBAAiBP,CAAU,KAAK,CAAA,GAE/BS,IAAiB,CAACF,MACvBA,GAAI,uBAAuBL,CAAc,KAAK,CAAA,GAEzCQ,IAAc,CAACC,MAAmB;AACvC,MAAI,CAACA,EAAM,aAAc,QAAO;AAChC,QAAMC,IAAa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K,EAAG;AAClC,IAAAJ,EAAkB,IAAII,CAAK;AAC3B,UAAMf,IAAQH,EAAUF,EAASoB,CAAK,CAAC,EAAE,CAAC;AAC1C,IAAIvB,EAAiBQ,GAAO,IAAI,KAAGN,EAAKqB,GAAO,UAAU,EAAE;AAAA,EAC5D;AACD;AAEAC,EAAY,eAAe,MAAM;AAAA,EAChCC,EAAG,UAAU,SAASV,GAAa,EAAI;AAAA;AAAA,EACvCU,EAAG,UAAU,WAAWR,GAAe,EAAI;AAAA;AAAA,EAC3CQ,EAAG,UAAU,WAAWC,EAAShB,GAAmB,EAAE,GAAGiB,CAAW;AAAA;AAAA,EACpEF,EAAG,UAAU,UAAUf,GAAmB,EAAI;AAAA;AAAA,EAC9CkB,EAAW,UAAUN,GAAgB;AAAA,IACpC,WAAW;AAAA,IACX,SAAS;AAAA,EAAA,CACT;AACF,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattilsynet/design",
3
- "version": "3.1.10",
3
+ "version": "3.1.12",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,15 +60,15 @@
60
60
  "@handsontable/react-wrapper": "^16.2.0",
61
61
  "@phosphor-icons/core": "^2.1.1",
62
62
  "@phosphor-icons/react": "^2.1.10",
63
- "@storybook/addon-docs": "^10.2.12",
64
- "@storybook/addon-themes": "^10.2.12",
65
- "@storybook/react-vite": "^10.2.12",
63
+ "@storybook/addon-docs": "^10.2.13",
64
+ "@storybook/addon-themes": "^10.2.13",
65
+ "@storybook/react-vite": "^10.2.13",
66
66
  "@tanstack/react-table": "^8.21.3",
67
67
  "@turf/boolean-point-in-polygon": "^7.3.4",
68
68
  "@turf/helpers": "^7.3.4",
69
69
  "@types/leaflet": "^1.9.21",
70
70
  "@types/leaflet.markercluster": "^1.5.6",
71
- "@types/node": "^25.3.0",
71
+ "@types/node": "^25.3.3",
72
72
  "@types/react": "^19.2.14",
73
73
  "@types/react-dom": "^19.2.3",
74
74
  "@vitejs/plugin-react": "^5.1.4",
@@ -80,7 +80,7 @@
80
80
  "react": "^19.2.4",
81
81
  "react-dom": "^19.2.4",
82
82
  "react-moveable": "^0.56.0",
83
- "storybook": "^10.2.12",
83
+ "storybook": "^10.2.13",
84
84
  "typescript": "^5.9.3",
85
85
  "vite": "^7.3.1",
86
86
  "vite-plugin-dts": "^4.5.4"