@mattilsynet/design 2.1.1 → 2.1.3
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/alert/alert.js.map +1 -1
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +5 -5
- package/mtds/app/app-observer.js.map +1 -1
- package/mtds/app/app-toggle.js.map +1 -1
- package/mtds/app/app-toggle2.js.map +1 -1
- package/mtds/app/app.js.map +1 -1
- package/mtds/avatar/avatar.js.map +1 -1
- package/mtds/badge/badge.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs-observer.js +8 -4
- package/mtds/breadcrumbs/breadcrumbs-observer.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
- package/mtds/button/button.js.map +1 -1
- package/mtds/card/card.js.map +1 -1
- package/mtds/chip/chip.js.map +1 -1
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +7 -3
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/dialog/dialog.js.map +1 -1
- package/mtds/dialog/dialog.stories.d.ts +1 -0
- package/mtds/divider/divider.js.map +1 -1
- package/mtds/errorsummary/errorsummary-observer.js +6 -4
- package/mtds/errorsummary/errorsummary-observer.js.map +1 -1
- package/mtds/errorsummary/errorsummary.js.map +1 -1
- package/mtds/external/@floating-ui/core/dist/floating-ui.core.js +342 -0
- package/mtds/external/@floating-ui/core/dist/floating-ui.core.js.map +1 -0
- package/mtds/external/@floating-ui/dom/dist/floating-ui.dom.js +397 -0
- package/mtds/external/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -0
- package/mtds/external/@floating-ui/utils/dist/floating-ui.utils.dom.js +137 -0
- package/mtds/external/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -0
- package/mtds/external/@floating-ui/utils/dist/floating-ui.utils.js +130 -0
- package/mtds/external/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -0
- package/mtds/external/@u-elements/u-combobox/dist/u-combobox.js.map +1 -1
- package/mtds/external/@u-elements/u-datalist/dist/u-datalist.js.map +1 -1
- package/mtds/external/@u-elements/u-details/dist/u-details.js +27 -28
- package/mtds/external/@u-elements/u-details/dist/u-details.js.map +1 -1
- package/mtds/external/@u-elements/u-progress/dist/u-progress.js.map +1 -1
- package/mtds/external/@u-elements/u-tabs/dist/u-tabs.js.map +1 -1
- package/mtds/field/field-observer.js +54 -48
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.d.ts +3 -3
- package/mtds/field/field.js.map +1 -1
- package/mtds/fieldset/fieldset-observer.js +4 -4
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/fieldset/fieldset.js.map +1 -1
- package/mtds/helptext/helptext.js.map +1 -1
- package/mtds/index.iife.js +7 -7
- package/mtds/input/input.js.map +1 -1
- package/mtds/layout/layout.js.map +1 -1
- package/mtds/link/link.js.map +1 -1
- package/mtds/logo/logo-observer.js +4 -2
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/logo/logo.js.map +1 -1
- package/mtds/package.json.js +1 -1
- package/mtds/pagination/pagination-helper.js.map +1 -1
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/popover/popover-observer.js +21 -14
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/popover/popover.d.ts +2 -2
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/skeleton/skeleton.js.map +1 -1
- package/mtds/spinner/spinner.js.map +1 -1
- package/mtds/steps/steps.js.map +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +20 -20
- package/mtds/styles.module.css.js +86 -84
- package/mtds/styles.module.css.js.map +1 -1
- package/mtds/table/table-observer.js +10 -8
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/table/table.js.map +1 -1
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tag/tag.js.map +1 -1
- package/mtds/tailwind.css +1 -0
- package/mtds/togglegroup/togglegroup-observer.js +8 -8
- package/mtds/togglegroup/togglegroup-observer.js.map +1 -1
- package/mtds/togglegroup/togglegroup.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +14 -10
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/typography/typography.js.map +1 -1
- package/mtds/utils.d.ts +2 -14
- package/mtds/utils.js +60 -71
- package/mtds/utils.js.map +1 -1
- package/mtds/validation/validation.js.map +1 -1
- package/package.json +13 -12
- package/mtds/toast/toast-observer.d.ts +0 -2
package/mtds/utils.js
CHANGED
|
@@ -1,96 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
function
|
|
1
|
+
import { autoUpdate as m, computePosition as l } from "./external/@floating-ui/dom/dist/floating-ui.dom.js";
|
|
2
|
+
const $ = { capture: !0, passive: !0 }, p = typeof window < "u" && typeof document < "u";
|
|
3
|
+
function h(t, n) {
|
|
4
4
|
let e;
|
|
5
|
-
return (...
|
|
6
|
-
clearTimeout(e), e = setTimeout(() => t(...
|
|
5
|
+
return (...i) => {
|
|
6
|
+
clearTimeout(e), e = setTimeout(() => t(...i), n);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function A(t, n, e) {
|
|
10
10
|
return e === void 0 ? t.getAttribute(n) ?? null : (e === null ? t.removeAttribute(n) : t.getAttribute(n) !== e && t.setAttribute(n, e), null);
|
|
11
11
|
}
|
|
12
|
-
let
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
return t.id || (t.id = `${
|
|
12
|
+
let w = 0;
|
|
13
|
+
const E = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
|
|
14
|
+
function C(t) {
|
|
15
|
+
return t.id || (t.id = `${E}${++w}`), t.id;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
for (const
|
|
19
|
-
e[0] =
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
let
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
17
|
+
const c = (t, n, [...e]) => {
|
|
18
|
+
for (const i of e[0].split(","))
|
|
19
|
+
e[0] = i, n[`${t}EventListener`](...e);
|
|
20
|
+
}, b = (t, ...n) => {
|
|
21
|
+
s && (t === window || t === document) && s.push(() => v(t, ...n)), c("add", t, n);
|
|
22
|
+
}, v = (t, ...n) => c("remove", t, n);
|
|
23
|
+
let s = null;
|
|
24
|
+
const S = (t) => {
|
|
25
|
+
if (!p) return;
|
|
26
26
|
window._mtdsUnbindEvents || (window._mtdsUnbindEvents = /* @__PURE__ */ new Map());
|
|
27
27
|
const n = () => requestAnimationFrame(() => {
|
|
28
28
|
const e = String(t).replace(/(\n|\s)/g, "");
|
|
29
|
-
window._mtdsUnbindEvents?.get(e)?.forEach((
|
|
29
|
+
window._mtdsUnbindEvents?.get(e)?.forEach((i) => {
|
|
30
|
+
i();
|
|
31
|
+
}), s = [], t(), window._mtdsUnbindEvents?.set(e, s?.slice(0)), s = null;
|
|
30
32
|
});
|
|
31
|
-
document.readyState === "complete" ? n() :
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Math.max(10, a - (c - p) / 2),
|
|
44
|
-
g - c - 10
|
|
45
|
-
), C = Math.min(
|
|
46
|
-
Math.max(10, d - (s - u) / 2),
|
|
47
|
-
v - s - 10
|
|
48
|
-
), W = a - c > 0, _ = a + p + c < g, $ = d - s > 0, I = d + u + s < v, T = i === r.top || i === r.bottom, B = i === r.right && (o || _) || !W, S = i === r.bottom && (o || I) || !$, D = Math.round(
|
|
49
|
-
T ? R : B ? a + p : a - c
|
|
50
|
-
), N = Math.round(
|
|
51
|
-
T ? S ? d + u : d - s : C
|
|
52
|
-
);
|
|
53
|
-
t.style.position = "absolute", t.style.left = `${D + M}px`, t.style.top = `${N + O}px`, l?.style.setProperty(
|
|
54
|
-
"translate",
|
|
55
|
-
`0px ${Math.round(S ? M + d + u + s + 30 : 0)}px`
|
|
33
|
+
document.readyState === "complete" ? n() : b(window, "load", n);
|
|
34
|
+
}, u = /* @__PURE__ */ new WeakMap();
|
|
35
|
+
function y(t, n, e) {
|
|
36
|
+
u.get(t)?.(), u.delete(t), n && u.set(
|
|
37
|
+
t,
|
|
38
|
+
m(n, t, () => {
|
|
39
|
+
if (!t.isConnected || !n.isConnected || t.hidden)
|
|
40
|
+
return y(t, !1);
|
|
41
|
+
l(n, t, e).then(({ x: i, y: o }) => {
|
|
42
|
+
t.style.left = `${i}px`, t.style.top = `${o}px`;
|
|
43
|
+
});
|
|
44
|
+
})
|
|
56
45
|
);
|
|
57
46
|
}
|
|
58
|
-
function
|
|
47
|
+
function M(t) {
|
|
59
48
|
let n = 0;
|
|
60
|
-
const e = () => setTimeout(
|
|
61
|
-
t([],
|
|
62
|
-
},
|
|
49
|
+
const e = () => setTimeout(i, 200), i = () => {
|
|
50
|
+
t([], o), o.takeRecords(), n = 0;
|
|
51
|
+
}, o = new MutationObserver(() => {
|
|
63
52
|
n || (n = requestAnimationFrame(e));
|
|
64
53
|
});
|
|
65
|
-
return
|
|
54
|
+
return o;
|
|
66
55
|
}
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
if (t.isConnected &&
|
|
71
|
-
for (const
|
|
56
|
+
const d = /* @__PURE__ */ new WeakMap(), L = (t, n, e) => {
|
|
57
|
+
const i = t.getElementsByClassName(n), o = d.get(t) || [];
|
|
58
|
+
o.length || (d.set(t, o), M((T, f) => {
|
|
59
|
+
if (t.isConnected && o?.length)
|
|
60
|
+
for (const a of o) a();
|
|
72
61
|
else
|
|
73
|
-
|
|
62
|
+
f?.disconnect(), d.delete(t);
|
|
74
63
|
}).observe(t, {
|
|
75
64
|
attributeFilter: ["class", "hidden"],
|
|
76
65
|
attributes: !0,
|
|
77
66
|
childList: !0,
|
|
78
67
|
subtree: !0
|
|
79
|
-
})),
|
|
80
|
-
},
|
|
68
|
+
})), o.push(() => e(i));
|
|
69
|
+
}, _ = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement), r = "aria-selected", I = ({ className: t, hidden: n, open: e, ...i }, o) => (i.suppressHydrationWarning = !0, i[r] !== void 0 && (i[r] = `${(i[r] || "false") !== "false"}`), (t || o) && (i.class = `${o} ${t}`.trim()), n && (i.hidden = !0), e && (i.open = !0), i);
|
|
81
70
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
71
|
+
p as IS_BROWSER,
|
|
72
|
+
$ as QUICK_EVENT,
|
|
73
|
+
y as anchorPosition,
|
|
74
|
+
A as attr,
|
|
75
|
+
M as createOptimizedMutationObserver,
|
|
76
|
+
h as debounce,
|
|
77
|
+
_ as isInputLike,
|
|
78
|
+
v as off,
|
|
79
|
+
b as on,
|
|
80
|
+
S as onLoaded,
|
|
81
|
+
L as onMutation,
|
|
82
|
+
I as toCustomElementProps,
|
|
83
|
+
C as useId
|
|
95
84
|
};
|
|
96
85
|
//# 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\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const IS_BROWSER =\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\";\n\n// TODO: Documentation for prettyNumber\nlet INTL_NUM: Intl.NumberFormat | undefined;\nexport function prettyNumber(number: number | string) {\n\tif (!INTL_NUM)\n\t\tINTL_NUM = new Intl.NumberFormat(\n\t\t\t(IS_BROWSER && attr(document.documentElement, \"lang\")) || \"no\",\n\t\t);\n\treturn INTL_NUM.format(Number(number));\n}\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 (...args: T) => {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback(...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 use as EventTarget\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 function 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 * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId(el: Element) {\n\tif (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\t[...rest]: Parameters<typeof Element.prototype.addEventListener>, // Spreat to make a copy of the array\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\telement[`${action}EventListener`](...rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => {\n\tif (UNBIND && (element === window || element === document))\n\t\tUNBIND.push(() => off(element, ...rest));\n\tevents(\"add\", element, rest);\n};\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsUnbindEvents?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onLoaded\n * @description Runs a callback when window is loaded in browser, and ensures events are unbound if hot reloading\n * @param callback The callback to run when the page is ready\n */\nlet UNBIND: Array<() => void> | null = null;\nexport const onLoaded = (callback: () => void) => {\n\tif (!IS_BROWSER) return;\n\tif (!window._mtdsUnbindEvents) window._mtdsUnbindEvents = new Map();\n\n\tconst run = () =>\n\t\trequestAnimationFrame(() => {\n\t\t\tconst key = String(callback).replace(/(\\n|\\s)/g, \"\");\n\t\t\twindow._mtdsUnbindEvents?.get(key)?.forEach((unbind) => unbind()); // Unbind previous events\n\t\t\tUNBIND = []; // Prepare to listen for newly bound events\n\t\t\tcallback(); // Run binding\n\t\t\twindow._mtdsUnbindEvents?.set(key, UNBIND?.slice(0)); // Store for later unbinding\n\t\t\tUNBIND = null; // Stop listening for newly bound events\n\t\t});\n\n\tif (document.readyState === \"complete\") run();\n\telse on(window, \"load\", run);\n};\n\n/**\n * Scroller targes helping anchorPosition\n */\nconst SCROLLER = IS_BROWSER ? document.createElement(\"div\") : null; // Used to ensure we have scrollability under\nconst TARGETS = new Map<Element, () => void>(); // Store current open poppers and their update functions\nconst TARGETS_UPDATE = () => {\n\tfor (const [_, update] of TARGETS) update();\n};\n\nif (SCROLLER) {\n\tSCROLLER.style.cssText = \"position:absolute;padding:1px;top:0;left:0px\";\n\ton(window, \"load,resize,scroll\", TARGETS_UPDATE, QUICK_EVENT);\n}\n\n/**\n * anchorPosition\n * @param target The Element to position\n * @param anchor The Element to use as anchor\n */\nconst POSITION = { top: 0, right: 1, bottom: 2, left: 3 }; // Speed up by using a const map\n\nexport type AnchorPosition = keyof typeof POSITION;\n\nexport function anchorPosition(\n\ttarget: HTMLElement,\n\tanchor: Element | false,\n\tplace?: string | number,\n\tforce?: boolean,\n) {\n\tconst position =\n\t\tPOSITION[place as keyof typeof POSITION] ??\n\t\tNumber(place) ??\n\t\tPOSITION.bottom;\n\n\tif (anchor === false || !anchor.isConnected || !target.isConnected)\n\t\treturn TARGETS.delete(target); // Stop watching if anchor is removed from DOM\n\tif (!SCROLLER?.isConnected) document.body.append(SCROLLER || \"\"); // Ensure we have the scroller\n\tif (!TARGETS.has(target))\n\t\tTARGETS.set(target, () => anchorPosition(target, anchor, position, force));\n\n\tconst { offsetWidth: targetW, offsetHeight: targetH } = target;\n\tconst { width, height, left, top } = anchor.getBoundingClientRect();\n\tconst isHTMLAnchor = anchor instanceof HTMLElement; // SVG or XML elements does not have offsetWidth or offsetHeight\n\tconst anchorW = isHTMLAnchor ? anchor.offsetWidth : anchor.clientWidth;\n\tconst anchorH = isHTMLAnchor ? anchor.offsetHeight : anchor.clientHeight;\n\n\t// Get visual viewport info\n\tconst viewW = window.visualViewport?.width || window.innerWidth;\n\tconst viewH = window.visualViewport?.height || window.innerHeight;\n\tconst scrollX = window.pageXOffset || document.documentElement.scrollLeft;\n\tconst scrollY = window.pageYOffset || document.documentElement.scrollTop;\n\n\tconst anchorX = Math.round(left - (anchorW - width) / 2); // Correct for CSS transform scale\n\tconst anchorY = Math.round(top - (anchorH - height) / 2); // Correct for CSS transform scale\n\tconst centerX = Math.min(\n\t\tMath.max(10, anchorX - (targetW - anchorW) / 2),\n\t\tviewW - targetW - 10,\n\t);\n\tconst centerY = Math.min(\n\t\tMath.max(10, anchorY - (targetH - anchorH) / 2),\n\t\tviewH - targetH - 10,\n\t);\n\n\t// Use visual viewport dimensions for space calculations\n\tconst hasSpaceLeft = anchorX - targetW > 0;\n\tconst hasSpaceRight = anchorX + anchorW + targetW < viewW;\n\tconst hasSpaceOver = anchorY - targetH > 0;\n\tconst hasSpaceUnder = anchorY + anchorH + targetH < viewH;\n\n\tconst isVertical = position === POSITION.top || position === POSITION.bottom;\n\tconst isRight =\n\t\t(position === POSITION.right && (force || hasSpaceRight)) || !hasSpaceLeft; // Always position right when no hasSpaceLeft, as no OS scrolls further left than 0\n\tconst isUnder =\n\t\t(position === POSITION.bottom && (force || hasSpaceUnder)) || !hasSpaceOver; // Always position under when no hasSpaceOver, as no OS scrolls further up than 0\n\n\t// Calculate positions in viewport coordinates\n\tconst viewX = Math.round(\n\t\tisVertical ? centerX : isRight ? anchorX + anchorW : anchorX - targetW,\n\t);\n\tconst viewY = Math.round(\n\t\tisVertical ? (isUnder ? anchorY + anchorH : anchorY - targetH) : centerY,\n\t);\n\n\t// Use absolute positioning\n\ttarget.style.position = \"absolute\";\n\ttarget.style.left = `${viewX + scrollX}px`;\n\ttarget.style.top = `${viewY + scrollY}px`;\n\n\tSCROLLER?.style.setProperty(\n\t\t\"translate\",\n\t\t`0px ${Math.round(isUnder ? scrollX + anchorY + anchorH + targetH + 30 : 0)}px`,\n\t);\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n\tlet queue = 0;\n\n\tconst onFrame = () => setTimeout(onTimer, 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tcallback([], observer);\n\t\tobserver.takeRecords(); // Clear records to avoid running callback multiple times\n\t\tqueue = 0;\n\t};\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame);\n\t});\n\n\treturn observer;\n}\n\n/**\n * onMutation\n * @description Utility to quickly observe mutations on a specific class name\n * @param el The Element to use as EventTarget\n * @param className The class name to observe\n * @param callback The callback to run when mutations are detected\n */\nconst MUTATORS = new WeakMap<Element, Array<() => void>>();\nexport const onMutation = <T extends Element>(\n\tel: Element,\n\tclassName: string,\n\tcallback: (elems: HTMLCollectionOf<T>) => void,\n) => {\n\tconst elems = el.getElementsByClassName(className);\n\tconst mutator = MUTATORS.get(el) || [];\n\n\tif (!mutator.length) {\n\t\tMUTATORS.set(el, mutator);\n\t\tcreateOptimizedMutationObserver((_, observer) => {\n\t\t\tif (el.isConnected && mutator?.length) {\n\t\t\t\tfor (const callback of mutator) callback();\n\t\t\t} else {\n\t\t\t\tobserver?.disconnect();\n\t\t\t\tMUTATORS.delete(el);\n\t\t\t}\n\t\t}).observe(el, {\n\t\t\tattributeFilter: [\"class\", \"hidden\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t}\n\tmutator.push(() => callback(elems as HTMLCollectionOf<T>));\n};\n\n/**\n * isInputLike\n * @description Check if element is an input like element\n * @param el The element to check\n * @returns True if the element is an input like element\n */\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement &&\n\t\"validity\" in el &&\n\t!(el instanceof HTMLButtonElement);\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 = (\n\t{ className, hidden, open, ...rest }: Record<string, unknown>,\n\tklass?: string,\n) => {\n\trest.suppressHydrationWarning = true; // Make Next.js happy\n\tif (rest[SELECTED] !== undefined)\n\t\trest[SELECTED] = `${(rest[SELECTED] || \"false\") !== \"false\"}`; // Ensure aria-selected boolean is string\n\tif (className || klass) rest.class = clsx(klass, className || \"\"); // Use class instead of className\n\tif (hidden) rest.hidden = true; // Ensure boolean prop behaviour\n\tif (open) rest.open = true; // Ensure boolean prop behaviour\n\treturn rest;\n};\n"],"names":["QUICK_EVENT","IS_BROWSER","debounce","callback","delay","timer","args","attr","el","name","value","id","UUID","useId","events","action","element","type","rest","on","UNBIND","off","onLoaded","run","key","unbind","SCROLLER","TARGETS","TARGETS_UPDATE","_","update","POSITION","anchorPosition","target","anchor","place","force","position","targetW","targetH","width","height","left","top","isHTMLAnchor","anchorW","anchorH","viewW","viewH","scrollX","scrollY","anchorX","anchorY","centerX","centerY","hasSpaceLeft","hasSpaceRight","hasSpaceOver","hasSpaceUnder","isVertical","isRight","isUnder","viewX","viewY","createOptimizedMutationObserver","queue","onFrame","onTimer","observer","MUTATORS","onMutation","className","elems","mutator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OAEA7D,EAAK,2BAA2B,IAC5BA,EAAKyD,CAAQ,MAAM,WACtBzD,EAAKyD,CAAQ,IAAI,IAAIzD,EAAKyD,CAAQ,KAAK,aAAa,OAAO,MACxDJ,KAAaQ,OAAO7D,EAAK,QAAQ8D,EAAKD,GAAOR,KAAa,EAAE,IAC5DM,QAAa,SAAS,KACtBC,QAAW,OAAO,KACf5D;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import { autoUpdate, computePosition } from \"@floating-ui/dom\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const IS_BROWSER =\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\";\n\n// TODO: Documentation for prettyNumber\nlet INTL_NUM: Intl.NumberFormat | undefined;\nexport function prettyNumber(number: number | string) {\n\tif (!INTL_NUM)\n\t\tINTL_NUM = new Intl.NumberFormat(\n\t\t\t(IS_BROWSER && attr(document.documentElement, \"lang\")) || \"no\",\n\t\t);\n\treturn INTL_NUM.format(Number(number));\n}\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 (...args: T) => {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback(...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 use as EventTarget\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 function 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 * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId(el: Element) {\n\tif (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\t[...rest]: Parameters<typeof Element.prototype.addEventListener>, // Spreat to make a copy of the array\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\telement[`${action}EventListener`](...rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => {\n\tif (UNBIND && (element === window || element === document))\n\t\tUNBIND.push(() => off(element, ...rest));\n\tevents(\"add\", element, rest);\n};\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsUnbindEvents?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onLoaded\n * @description Runs a callback when window is loaded in browser, and ensures events are unbound if hot reloading\n * @param callback The callback to run when the page is ready\n */\nlet UNBIND: Array<() => void> | null = null;\nexport const onLoaded = (callback: () => void) => {\n\tif (!IS_BROWSER) return;\n\tif (!window._mtdsUnbindEvents) window._mtdsUnbindEvents = new Map();\n\n\tconst run = () =>\n\t\trequestAnimationFrame(() => {\n\t\t\tconst key = String(callback).replace(/(\\n|\\s)/g, \"\");\n\t\t\twindow._mtdsUnbindEvents?.get(key)?.forEach((unbind) => {\n\t\t\t\tunbind(); // Unbind previous events\n\t\t\t});\n\t\t\tUNBIND = []; // Prepare to listen for newly bound events\n\t\t\tcallback(); // Run binding\n\t\t\twindow._mtdsUnbindEvents?.set(key, UNBIND?.slice(0)); // Store for later unbinding\n\t\t\tUNBIND = null; // Stop listening for newly bound events\n\t\t});\n\n\tif (document.readyState === \"complete\") run();\n\telse on(window, \"load\", run);\n};\n\nconst ANCHORED = new WeakMap<Element, ReturnType<typeof autoUpdate>>();\nexport function anchorPosition(\n\ttarget: HTMLElement,\n\tanchor: false | Element,\n\toptions?: Parameters<typeof computePosition>[2],\n) {\n\tANCHORED.get(target)?.(); // Unbind previous anchor position\n\tANCHORED.delete(target);\n\n\tif (anchor)\n\t\tANCHORED.set(\n\t\t\ttarget,\n\t\t\tautoUpdate(anchor, target, () => {\n\t\t\t\tif (!target.isConnected || !anchor.isConnected || target.hidden)\n\t\t\t\t\treturn anchorPosition(target, false);\n\t\t\t\tcomputePosition(anchor, target, options).then(({ x, y }) => {\n\t\t\t\t\ttarget.style.left = `${x}px`;\n\t\t\t\t\ttarget.style.top = `${y}px`;\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n\tlet queue = 0;\n\n\tconst onFrame = () => setTimeout(onTimer, 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tcallback([], observer);\n\t\tobserver.takeRecords(); // Clear records to avoid running callback multiple times\n\t\tqueue = 0;\n\t};\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame);\n\t});\n\n\treturn observer;\n}\n\n/**\n * onMutation\n * @description Utility to quickly observe mutations on a specific class name\n * @param el The Element to use as EventTarget\n * @param className The class name to observe\n * @param callback The callback to run when mutations are detected\n */\nconst MUTATORS = new WeakMap<Element, Array<() => void>>();\nexport const onMutation = <T extends Element>(\n\tel: Element,\n\tclassName: string,\n\tcallback: (elems: HTMLCollectionOf<T>) => void,\n) => {\n\tconst elems = el.getElementsByClassName(className);\n\tconst mutator = MUTATORS.get(el) || [];\n\n\tif (!mutator.length) {\n\t\tMUTATORS.set(el, mutator);\n\t\tcreateOptimizedMutationObserver((_, observer) => {\n\t\t\tif (el.isConnected && mutator?.length) {\n\t\t\t\tfor (const callback of mutator) callback();\n\t\t\t} else {\n\t\t\t\tobserver?.disconnect();\n\t\t\t\tMUTATORS.delete(el);\n\t\t\t}\n\t\t}).observe(el, {\n\t\t\tattributeFilter: [\"class\", \"hidden\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t}\n\tmutator.push(() => callback(elems as HTMLCollectionOf<T>));\n};\n\n/**\n * isInputLike\n * @description Check if element is an input like element\n * @param el The element to check\n * @returns True if the element is an input like element\n */\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement &&\n\t\"validity\" in el &&\n\t!(el instanceof HTMLButtonElement);\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 = (\n\t{ className, hidden, open, ...rest }: Record<string, unknown>,\n\tklass?: string,\n) => {\n\trest.suppressHydrationWarning = true; // Make Next.js happy\n\tif (rest[SELECTED] !== undefined)\n\t\trest[SELECTED] = `${(rest[SELECTED] || \"false\") !== \"false\"}`; // Ensure aria-selected boolean is string\n\tif (className || klass) rest.class = `${klass} ${className}`.trim(); // Use class instead of className\n\tif (hidden) rest.hidden = true; // Ensure boolean prop behaviour\n\tif (open) rest.open = true; // Ensure boolean prop behaviour\n\treturn rest;\n};\n"],"names":["QUICK_EVENT","IS_BROWSER","debounce","callback","delay","timer","args","attr","el","name","value","id","UUID","useId","events","action","element","type","rest","on","UNBIND","off","onLoaded","run","key","unbind","ANCHORED","anchorPosition","target","anchor","options","autoUpdate","computePosition","x","y","createOptimizedMutationObserver","queue","onFrame","onTimer","observer","MUTATORS","onMutation","className","elems","mutator","_","isInputLike","SELECTED","toCustomElementProps","hidden","open","klass"],"mappings":";AAEO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,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Aa,CACzBjC,GACAkC,GACAvC,MACI;AACJ,QAAMwC,IAAQnC,EAAG,uBAAuBkC,CAAS,GAC3CE,IAAUJ,EAAS,IAAIhC,CAAE,KAAK,CAAA;AAEpC,EAAKoC,EAAQ,WACZJ,EAAS,IAAIhC,GAAIoC,CAAO,GACxBT,EAAgC,CAACU,GAAGN,MAAa;AAChD,QAAI/B,EAAG,eAAeoC,GAAS;AAC9B,iBAAWzC,KAAYyC,EAASzC,CAAAA,EAAAA;AAAAA;AAEhC,MAAAoC,GAAU,WAAA,GACVC,EAAS,OAAOhC,CAAE;AAAA,EAEpB,CAAC,EAAE,QAAQA,GAAI;AAAA,IACd,iBAAiB,CAAC,SAAS,QAAQ;AAAA,IACnC,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EAAA,CACT,IAEFoC,EAAQ,KAAK,MAAMzC,EAASwC,CAA4B,CAAC;AAC1D,GAQaG,IAAc,CAACtC,MAC3BA,aAAc,eACd,cAAcA,KACd,EAAEA,aAAc,oBAQXuC,IAAW,iBACJC,IAAuB,CACnC,EAAE,WAAAN,GAAW,QAAAO,GAAQ,MAAAC,GAAM,GAAGhC,EAAA,GAC9BiC,OAEAjC,EAAK,2BAA2B,IAC5BA,EAAK6B,CAAQ,MAAM,WACtB7B,EAAK6B,CAAQ,IAAI,IAAI7B,EAAK6B,CAAQ,KAAK,aAAa,OAAO,MACxDL,KAAaS,OAAOjC,EAAK,QAAQ,GAAGiC,CAAK,IAAIT,CAAS,GAAG,KAAA,IACzDO,QAAa,SAAS,KACtBC,QAAW,OAAO,KACfhC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sources":["../../designsystem/validation/validation.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type ValidationProps = React.ComponentPropsWithoutRef<\"div\">;\n\nexport const Validation = forwardRef<HTMLDivElement, ValidationProps>(\n\tfunction Validation({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tsuppressHydrationWarning // Prevent hydration mismatch for SSR due to field-observer.ts\n\t\t\t\tclassName={clsx(styles.validation, className)}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["Validation","forwardRef","className","rest","ref","jsx","clsx","styles"],"mappings":";;;;AAMO,MAAMA,IAAaC;AAAA,EACzB,SAAoB,EAAE,WAAAC,GAAW,GAAGC,EAAA,GAAQC,GAAK;
|
|
1
|
+
{"version":3,"file":"validation.js","sources":["../../designsystem/validation/validation.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type ValidationProps = React.ComponentPropsWithoutRef<\"div\">;\n\nexport const Validation = forwardRef<HTMLDivElement, ValidationProps>(\n\tfunction Validation({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tsuppressHydrationWarning // Prevent hydration mismatch for SSR due to field-observer.ts\n\t\t\t\tclassName={clsx(styles.validation, className)}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["Validation","forwardRef","className","rest","ref","jsx","clsx","styles"],"mappings":";;;;AAMO,MAAMA,IAAaC;AAAA,EACzB,SAAoB,EAAE,WAAAC,GAAW,GAAGC,EAAA,GAAQC,GAAK;AAChD,WACC,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,0BAAwB;AAAA,QACxB,WAAWC,EAAKC,EAAO,YAAYL,CAAS;AAAA,QAC5C,KAAAE;AAAA,QACC,GAAGD;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mattilsynet/design",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./mtds/index.js",
|
|
6
6
|
"types": "./mtds/index.d.ts",
|
|
@@ -41,33 +41,34 @@
|
|
|
41
41
|
"storybook:build": "npm run build && storybook build"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@biomejs/biome": "^2.
|
|
44
|
+
"@biomejs/biome": "^2.2.0",
|
|
45
45
|
"@digdir/designsystemet": "^1.1.9",
|
|
46
|
-
"@digdir/designsystemet-css": "^1.1.
|
|
46
|
+
"@digdir/designsystemet-css": "^1.1.10",
|
|
47
47
|
"@phosphor-icons/core": "^2.1.1",
|
|
48
48
|
"@phosphor-icons/react": "^2.1.10",
|
|
49
|
-
"@storybook/addon-docs": "^9.1.
|
|
50
|
-
"@storybook/addon-themes": "^9.1.
|
|
51
|
-
"@storybook/react-vite": "^9.1.
|
|
49
|
+
"@storybook/addon-docs": "^9.1.2",
|
|
50
|
+
"@storybook/addon-themes": "^9.1.2",
|
|
51
|
+
"@storybook/react-vite": "^9.1.2",
|
|
52
52
|
"@tanstack/react-table": "^8.21.3",
|
|
53
|
-
"@types/node": "^24.2.
|
|
54
|
-
"@types/react": "^19.1.
|
|
53
|
+
"@types/node": "^24.2.1",
|
|
54
|
+
"@types/react": "^19.1.10",
|
|
55
55
|
"@types/react-dom": "^19.1.7",
|
|
56
|
-
"@vitejs/plugin-react": "^
|
|
56
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
57
57
|
"fast-glob": "^3.3.3",
|
|
58
58
|
"postcss": "^8.5.6",
|
|
59
59
|
"postcss-nesting": "^13.0.2",
|
|
60
60
|
"react": "^19.1.1",
|
|
61
61
|
"react-dom": "^19.1.1",
|
|
62
|
-
"storybook": "^9.1.
|
|
62
|
+
"storybook": "^9.1.2",
|
|
63
63
|
"typescript": "^5.9.2",
|
|
64
|
-
"vite": "^7.
|
|
64
|
+
"vite": "^7.1.2",
|
|
65
65
|
"vite-plugin-dts": "^4.5.4"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
+
"@floating-ui/dom": "^1.7.3",
|
|
68
69
|
"@u-elements/u-combobox": "^1.0.0",
|
|
69
70
|
"@u-elements/u-datalist": "^1.0.13",
|
|
70
|
-
"@u-elements/u-details": "^0.1.
|
|
71
|
+
"@u-elements/u-details": "^0.1.2",
|
|
71
72
|
"@u-elements/u-progress": "^0.0.5",
|
|
72
73
|
"@u-elements/u-tabs": "^0.0.9",
|
|
73
74
|
"clsx": "^2.1.1"
|