@mattilsynet/design 2.2.21 → 2.2.22
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/atlas/atlas-element.d.ts +3 -1
- package/mtds/atlas/atlas-element.js +54 -41
- package/mtds/atlas/atlas-element.js.map +1 -1
- package/mtds/atlas/atlas.css.js +91 -39
- package/mtds/atlas/atlas.css.js.map +1 -1
- package/mtds/atlas/atlas.stories.d.ts +1 -0
- package/mtds/atlas/cluster.js +1 -1
- package/mtds/atlas/cluster.js.map +1 -1
- package/mtds/atlas.iife.js +99 -47
- package/mtds/chart/chart-element.d.ts +1 -2
- package/mtds/chart/chart-element.js +41 -47
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart.css.js +2 -1
- package/mtds/chart/chart.css.js.map +1 -1
- package/mtds/field/field-observer.js +41 -39
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/index.iife.js +23 -22
- package/mtds/package.json.js +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +20 -20
- package/mtds/styles.module.css.js +29 -29
- package/mtds/utils.d.ts +7 -3
- package/mtds/utils.js +47 -42
- package/mtds/utils.js.map +1 -1
- package/package.json +11 -11
package/mtds/styles.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
"alert": "_alert_1cl7y_1 _ds-
|
|
2
|
+
"alert": "_alert_1cl7y_1 _ds-alert_5rpuv_3",
|
|
3
3
|
"app": "_app_1cl7y_1",
|
|
4
4
|
"sticky": "_sticky_1cl7y_1",
|
|
5
|
-
"avatar": "_avatar_1cl7y_1 _ds-
|
|
5
|
+
"avatar": "_avatar_1cl7y_1 _ds-avatar_5rpuv_1",
|
|
6
6
|
"badge": "_badge_1cl7y_1",
|
|
7
|
-
"breadcrumbs": "_breadcrumbs_1cl7y_1 _ds-
|
|
8
|
-
"button": "_button_1cl7y_1 _ds-
|
|
7
|
+
"breadcrumbs": "_breadcrumbs_1cl7y_1 _ds-breadcrumbs_5rpuv_5",
|
|
8
|
+
"button": "_button_1cl7y_1 _ds-button_5rpuv_1",
|
|
9
9
|
"card": "_card_1cl7y_1",
|
|
10
10
|
"group": "_group_1cl7y_1",
|
|
11
|
-
"chip": "_chip_1cl7y_1 _ds-
|
|
12
|
-
"details": "_details_1cl7y_1 _ds-
|
|
13
|
-
"dialog": "_dialog_1cl7y_1 _ds-
|
|
11
|
+
"chip": "_chip_1cl7y_1 _ds-chip_5rpuv_5",
|
|
12
|
+
"details": "_details_1cl7y_1 _ds-details_5rpuv_3",
|
|
13
|
+
"dialog": "_dialog_1cl7y_1 _ds-dialog_5rpuv_5",
|
|
14
14
|
"divider": "_divider_1cl7y_1",
|
|
15
|
-
"errorsummary": "_errorsummary_1cl7y_1 _ds-error-
|
|
16
|
-
"field": "_field_1cl7y_1 _ds-
|
|
17
|
-
"affixes": "_affixes_1cl7y_1 _ds-field-
|
|
18
|
-
"fieldset": "_fieldset_1cl7y_1 _ds-
|
|
15
|
+
"errorsummary": "_errorsummary_1cl7y_1 _ds-error-summary_5rpuv_5",
|
|
16
|
+
"field": "_field_1cl7y_1 _ds-field_5rpuv_1",
|
|
17
|
+
"affixes": "_affixes_1cl7y_1 _ds-field-affixes_5rpuv_3",
|
|
18
|
+
"fieldset": "_fieldset_1cl7y_1 _ds-fieldset_5rpuv_3",
|
|
19
19
|
"fileupload": "_fileupload_1cl7y_1",
|
|
20
|
-
"helptext": "_helptext_1cl7y_1 _ds-
|
|
21
|
-
"input": "_input_1cl7y_1 _ds-
|
|
20
|
+
"helptext": "_helptext_1cl7y_1 _ds-focus_5rpuv_1",
|
|
21
|
+
"input": "_input_1cl7y_1 _ds-input_5rpuv_1",
|
|
22
22
|
"law": "_law_1cl7y_1",
|
|
23
23
|
"grid": "_grid_1cl7y_1",
|
|
24
24
|
"flex": "_flex_1cl7y_1",
|
|
25
25
|
"link": "_link_1cl7y_1",
|
|
26
26
|
"logo": "_logo_1cl7y_1",
|
|
27
|
-
"pagination": "_pagination_1cl7y_1 _ds-
|
|
27
|
+
"pagination": "_pagination_1cl7y_1 _ds-pagination_5rpuv_5",
|
|
28
28
|
"popover": "_popover_1cl7y_1",
|
|
29
29
|
"progress": "_progress_1cl7y_1",
|
|
30
|
-
"skeleton": "_skeleton_1cl7y_1 _ds-
|
|
30
|
+
"skeleton": "_skeleton_1cl7y_1 _ds-skeleton_5rpuv_5",
|
|
31
31
|
"spinner": "_spinner_1cl7y_1",
|
|
32
32
|
"steps": "_steps_1cl7y_1",
|
|
33
|
-
"table": "_table_1cl7y_1 _ds-
|
|
34
|
-
"tabs": "_tabs_1cl7y_1 _ds-
|
|
35
|
-
"tag": "_tag_1cl7y_1 _ds-
|
|
33
|
+
"table": "_table_1cl7y_1 _ds-table_5rpuv_5",
|
|
34
|
+
"tabs": "_tabs_1cl7y_1 _ds-tabs_5rpuv_5",
|
|
35
|
+
"tag": "_tag_1cl7y_1 _ds-tag_5rpuv_5",
|
|
36
36
|
"toast": "_toast_1cl7y_1",
|
|
37
37
|
"togglegroup": "_togglegroup_1cl7y_1",
|
|
38
|
-
"heading": "_heading_1cl7y_1 _ds-
|
|
38
|
+
"heading": "_heading_1cl7y_1 _ds-heading_5rpuv_1",
|
|
39
39
|
"ingress": "_ingress_1cl7y_1",
|
|
40
40
|
"muted": "_muted_1cl7y_1",
|
|
41
41
|
"info": "_info_1cl7y_1",
|
|
42
42
|
"prose": "_prose_1cl7y_1",
|
|
43
|
-
"validation": "_validation_1cl7y_1 _ds-validation-
|
|
43
|
+
"validation": "_validation_1cl7y_1 _ds-validation-message_5rpuv_1",
|
|
44
44
|
"body": "_body_1cl7y_173"
|
|
45
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _ = "_alert_1cl7y_1 _ds-
|
|
1
|
+
const _ = "_alert_1cl7y_1 _ds-alert_5rpuv_3", t = "_app_1cl7y_1", s = "_sticky_1cl7y_1", o = "_avatar_1cl7y_1 _ds-avatar_5rpuv_1", c = "_badge_1cl7y_1", l = "_breadcrumbs_1cl7y_1 _ds-breadcrumbs_5rpuv_5", e = "_button_1cl7y_1 _ds-button_5rpuv_1", a = "_card_1cl7y_1", r = "_group_1cl7y_1", n = "_chip_1cl7y_1 _ds-chip_5rpuv_5", i = "_details_1cl7y_1 _ds-details_5rpuv_3", d = "_dialog_1cl7y_1 _ds-dialog_5rpuv_5", p = "__drawer_1cl7y_1", y = "_divider_1cl7y_1", u = "_errorsummary_1cl7y_1 _ds-error-summary_5rpuv_5", g = "__errorsummary_1cl7y_1", v = "_field_1cl7y_1 _ds-field_5rpuv_1", f = "__datalist_1cl7y_1", m = "_affixes_1cl7y_1 _ds-field-affixes_5rpuv_3", b = "_fieldset_1cl7y_1 _ds-fieldset_5rpuv_3", k = "_fileupload_1cl7y_1", h = "_helptext_1cl7y_1 _ds-focus_5rpuv_1", x = "_input_1cl7y_1 _ds-input_5rpuv_1", w = "_law_1cl7y_1", C = "_grid_1cl7y_1", M = "_flex_1cl7y_1", O = "_link_1cl7y_1", S = "_logo_1cl7y_1", T = "_pagination_1cl7y_1 _ds-pagination_5rpuv_5", j = "_popover_1cl7y_1", q = "_progress_1cl7y_1", z = "__indeterminate_1cl7y_1", A = "_skeleton_1cl7y_1 _ds-skeleton_5rpuv_5", B = "__skeleton_1cl7y_1", D = "_spinner_1cl7y_1", E = "_steps_1cl7y_1", F = "_table_1cl7y_1 _ds-table_5rpuv_5", G = "__scrollShadow_1cl7y_1", H = "_tabs_1cl7y_1 _ds-tabs_5rpuv_5", I = "__scrollMask_1cl7y_1", J = "_tag_1cl7y_1 _ds-tag_5rpuv_5", K = "_toast_1cl7y_1", L = "__toastClose_1cl7y_1", N = "__toastOpen_1cl7y_1", P = "__toastTimeout_1cl7y_1", Q = "_togglegroup_1cl7y_1", R = "__tooltip_1cl7y_1", U = "_heading_1cl7y_1 _ds-heading_5rpuv_1", V = "_ingress_1cl7y_1", W = "_muted_1cl7y_1", X = "_info_1cl7y_1", Y = "_prose_1cl7y_1", Z = "_validation_1cl7y_1 _ds-validation-message_5rpuv_1", $ = "_body_1cl7y_173", __ = "__checked_1cl7y_1", t_ = {
|
|
2
2
|
alert: _,
|
|
3
3
|
app: t,
|
|
4
4
|
sticky: s,
|
|
@@ -6,21 +6,21 @@ const _ = "_alert_1cl7y_1 _ds-alert_dbymd_3", t = "_app_1cl7y_1", s = "_sticky_1
|
|
|
6
6
|
badge: c,
|
|
7
7
|
breadcrumbs: l,
|
|
8
8
|
button: e,
|
|
9
|
-
card:
|
|
10
|
-
group:
|
|
9
|
+
card: a,
|
|
10
|
+
group: r,
|
|
11
11
|
chip: n,
|
|
12
|
-
details:
|
|
13
|
-
dialog:
|
|
14
|
-
_drawer:
|
|
15
|
-
divider:
|
|
16
|
-
errorsummary:
|
|
17
|
-
_errorsummary:
|
|
18
|
-
field:
|
|
19
|
-
_datalist:
|
|
20
|
-
affixes:
|
|
21
|
-
fieldset:
|
|
22
|
-
fileupload:
|
|
23
|
-
helptext:
|
|
12
|
+
details: i,
|
|
13
|
+
dialog: d,
|
|
14
|
+
_drawer: p,
|
|
15
|
+
divider: y,
|
|
16
|
+
errorsummary: u,
|
|
17
|
+
_errorsummary: g,
|
|
18
|
+
field: v,
|
|
19
|
+
_datalist: f,
|
|
20
|
+
affixes: m,
|
|
21
|
+
fieldset: b,
|
|
22
|
+
fileupload: k,
|
|
23
|
+
helptext: h,
|
|
24
24
|
input: x,
|
|
25
25
|
law: w,
|
|
26
26
|
grid: C,
|
|
@@ -57,9 +57,9 @@ const _ = "_alert_1cl7y_1 _ds-alert_dbymd_3", t = "_app_1cl7y_1", s = "_sticky_1
|
|
|
57
57
|
};
|
|
58
58
|
export {
|
|
59
59
|
__ as _checked,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
f as _datalist,
|
|
61
|
+
p as _drawer,
|
|
62
|
+
g as _errorsummary,
|
|
63
63
|
z as _indeterminate,
|
|
64
64
|
I as _scrollMask,
|
|
65
65
|
G as _scrollShadow,
|
|
@@ -68,7 +68,7 @@ export {
|
|
|
68
68
|
N as _toastOpen,
|
|
69
69
|
P as _toastTimeout,
|
|
70
70
|
R as _tooltip,
|
|
71
|
-
|
|
71
|
+
m as affixes,
|
|
72
72
|
_ as alert,
|
|
73
73
|
t as app,
|
|
74
74
|
o as avatar,
|
|
@@ -76,21 +76,21 @@ export {
|
|
|
76
76
|
$ as body,
|
|
77
77
|
l as breadcrumbs,
|
|
78
78
|
e as button,
|
|
79
|
-
|
|
79
|
+
a as card,
|
|
80
80
|
n as chip,
|
|
81
81
|
t_ as default,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
i as details,
|
|
83
|
+
d as dialog,
|
|
84
|
+
y as divider,
|
|
85
|
+
u as errorsummary,
|
|
86
|
+
v as field,
|
|
87
|
+
b as fieldset,
|
|
88
|
+
k as fileupload,
|
|
89
89
|
M as flex,
|
|
90
90
|
C as grid,
|
|
91
|
-
|
|
91
|
+
r as group,
|
|
92
92
|
U as heading,
|
|
93
|
-
|
|
93
|
+
h as helptext,
|
|
94
94
|
X as info,
|
|
95
95
|
V as ingress,
|
|
96
96
|
x as input,
|
package/mtds/utils.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export declare const QUICK_EVENT: {
|
|
|
4
4
|
passive: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare const IS_BROWSER: boolean;
|
|
7
|
-
export declare function prettyNumber(number: number | string): string;
|
|
8
7
|
export declare function debounce<T extends unknown[]>(callback: (...args: T) => void, delay: number): (this: unknown, ...args: T) => void;
|
|
9
8
|
/**
|
|
10
9
|
* attr
|
|
@@ -48,7 +47,12 @@ export declare function anchorPosition(target: HTMLElement, anchor: false | Elem
|
|
|
48
47
|
* Speed up MutationObserver by debouncing and only running when page is visible
|
|
49
48
|
* @return new MutaionObserver
|
|
50
49
|
*/
|
|
51
|
-
export declare function onMutation(callback:
|
|
50
|
+
export declare function onMutation(callback: (observer: MutationObserver) => void, attr: string | {
|
|
51
|
+
attr: string;
|
|
52
|
+
root?: HTMLElement;
|
|
53
|
+
delay?: number;
|
|
54
|
+
}): () => void;
|
|
55
|
+
export declare function onResize(callback: ResizeObserverCallback, element: Element): () => void;
|
|
52
56
|
/**
|
|
53
57
|
* isInputLike
|
|
54
58
|
* @description Check if element is an input like element
|
|
@@ -67,7 +71,7 @@ export declare const toCustomElementProps: ({ className, hidden, open, ...rest }
|
|
|
67
71
|
* @param text Optional text content to add to the element
|
|
68
72
|
* @return HTMLElement with props
|
|
69
73
|
*/
|
|
70
|
-
export declare const tag: <TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, attrs?: Record<string, string | null
|
|
74
|
+
export declare const tag: <TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, attrs?: Record<string, string | null> | null, text?: string | null) => HTMLElementTagNameMap[TagName];
|
|
71
75
|
export declare const MTDSElement: {
|
|
72
76
|
new (): HTMLElement;
|
|
73
77
|
prototype: HTMLElement;
|
package/mtds/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { autoUpdate as
|
|
1
|
+
import { autoUpdate as E, computePosition as v, flip as C, shift as T, size as L } from "@floating-ui/dom";
|
|
2
2
|
import M from "clsx";
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
function
|
|
3
|
+
import A from "./styles.module.css.js";
|
|
4
|
+
const q = { capture: !0, passive: !0 }, m = typeof window < "u" && typeof document < "u";
|
|
5
|
+
function F(t, e) {
|
|
6
6
|
let n;
|
|
7
7
|
return function(...o) {
|
|
8
8
|
clearTimeout(n), n = setTimeout(() => t.apply(this, o), e);
|
|
@@ -11,87 +11,92 @@ function k(t, e) {
|
|
|
11
11
|
function f(t, e, n) {
|
|
12
12
|
return n === void 0 ? t.getAttribute(e) ?? null : (n === null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n), null);
|
|
13
13
|
}
|
|
14
|
-
let
|
|
15
|
-
const
|
|
16
|
-
function
|
|
17
|
-
return t.id || (t.id = `${
|
|
14
|
+
let S = 0;
|
|
15
|
+
const $ = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
|
|
16
|
+
function g(t) {
|
|
17
|
+
return t.id || (t.id = `${$}${++S}`), t.id;
|
|
18
18
|
}
|
|
19
19
|
const p = (t, e, [...n]) => {
|
|
20
20
|
for (const o of n[0].split(","))
|
|
21
21
|
n[0] = o, e[`${t}EventListener`](...n);
|
|
22
|
-
},
|
|
22
|
+
}, h = (t, ...e) => (p("add", t, e), () => H(t, ...e)), H = (t, ...e) => p("remove", t, e), x = (t) => {
|
|
23
23
|
if (!m || !window.requestAnimationFrame) return;
|
|
24
24
|
window._mtdsCleanups || (window._mtdsCleanups = /* @__PURE__ */ new Map());
|
|
25
25
|
const e = () => requestAnimationFrame(() => {
|
|
26
26
|
const n = String(t).replace(/(\n|\s)/g, "");
|
|
27
27
|
window._mtdsCleanups?.get(n)?.map((o) => o()), window._mtdsCleanups?.set(n, t());
|
|
28
28
|
});
|
|
29
|
-
document.readyState === "complete" ? e() :
|
|
30
|
-
},
|
|
31
|
-
function
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
|
|
29
|
+
document.readyState === "complete" ? e() : h(window, "load", e);
|
|
30
|
+
}, u = /* @__PURE__ */ new WeakMap(), _ = `.${A.dialog.split(" ")[0]}`;
|
|
31
|
+
function D(t, e, { contain: n, middleware: o, placement: i, ...c } = {}) {
|
|
32
|
+
if (u.get(t)?.(), u.delete(t), e) {
|
|
33
|
+
const s = t.closest(_)?.querySelector(":scope > footer"), r = Number(f(t, "data-inset")) || 20, l = { bottom: (s?.clientHeight || 0) + r, left: r, right: r, top: r }, w = f(t, "data-position") ?? "bottom";
|
|
34
|
+
u.set(
|
|
35
35
|
t,
|
|
36
|
-
|
|
36
|
+
E(e, t, () => {
|
|
37
37
|
if (!t.isConnected || !e.isConnected || t.hidden)
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
...
|
|
41
|
-
placement: i ||
|
|
38
|
+
return D(t, !1);
|
|
39
|
+
v(e, t, {
|
|
40
|
+
...c,
|
|
41
|
+
placement: i || w,
|
|
42
42
|
middleware: [
|
|
43
43
|
C({ padding: l }),
|
|
44
44
|
T(),
|
|
45
45
|
...n ? [L({ padding: l, apply: n })] : [],
|
|
46
46
|
...o || []
|
|
47
47
|
]
|
|
48
|
-
}).then(({ x:
|
|
49
|
-
t.style.left = `${
|
|
48
|
+
}).then(({ x: y, y: b }) => {
|
|
49
|
+
t.style.left = `${y}px`, t.style.top = `${b}px`;
|
|
50
50
|
});
|
|
51
51
|
})
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function z(t, e) {
|
|
56
56
|
let n = 0;
|
|
57
|
-
const o = () => setTimeout(
|
|
57
|
+
const o = typeof e == "string" ? { attr: e } : e, i = () => setTimeout(c, o?.delay ?? 200), c = () => {
|
|
58
58
|
if (!m) return r();
|
|
59
|
-
t(
|
|
59
|
+
t(s), s.takeRecords(), n = 0;
|
|
60
60
|
}, s = new MutationObserver(() => {
|
|
61
|
-
n || (n = requestAnimationFrame(
|
|
61
|
+
n || (n = requestAnimationFrame(i));
|
|
62
62
|
}), r = () => {
|
|
63
63
|
try {
|
|
64
64
|
s.disconnect();
|
|
65
65
|
} catch {
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
return s.observe(document.documentElement, {
|
|
69
|
-
attributeFilter:
|
|
68
|
+
return s.observe(o?.root || document.documentElement, {
|
|
69
|
+
attributeFilter: [o.attr],
|
|
70
70
|
attributes: !0,
|
|
71
71
|
childList: !0,
|
|
72
72
|
subtree: !0
|
|
73
|
-
}), r;
|
|
73
|
+
}), t(s), r;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
function U(t, e) {
|
|
76
|
+
const n = new ResizeObserver(t);
|
|
77
|
+
return n.observe(e), () => n.disconnect();
|
|
78
|
+
}
|
|
79
|
+
const k = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement), d = "aria-selected", P = ({ className: t, hidden: e, open: n, ...o }, i) => (o.suppressHydrationWarning = !0, o[d] !== void 0 && (o[d] = `${(o[d] || "false") !== "false"}`), (t || i) && (o.class = M(i, t)), e && (o.hidden = !0), n && (o.open = !0), o), W = (t, e, n) => {
|
|
76
80
|
const o = document.createElement(t);
|
|
77
|
-
if (n && (o.textContent = n), e) for (const [i,
|
|
81
|
+
if (n && (o.textContent = n), e) for (const [i, c] of Object.entries(e)) f(o, i, c);
|
|
78
82
|
return o;
|
|
79
83
|
}, B = typeof HTMLElement > "u" ? class {
|
|
80
84
|
} : HTMLElement;
|
|
81
85
|
export {
|
|
82
86
|
m as IS_BROWSER,
|
|
83
87
|
B as MTDSElement,
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
q as QUICK_EVENT,
|
|
89
|
+
D as anchorPosition,
|
|
86
90
|
f as attr,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
W as
|
|
95
|
-
|
|
91
|
+
F as debounce,
|
|
92
|
+
k as isInputLike,
|
|
93
|
+
H as off,
|
|
94
|
+
h as on,
|
|
95
|
+
x as onLoaded,
|
|
96
|
+
z as onMutation,
|
|
97
|
+
U as onResize,
|
|
98
|
+
W as tag,
|
|
99
|
+
P as toCustomElementProps,
|
|
100
|
+
g as useId
|
|
96
101
|
};
|
|
97
102
|
//# sourceMappingURL=utils.js.map
|
package/mtds/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import type { Placement, SizeOptions } from \"@floating-ui/dom\";\nimport {\n\tautoUpdate,\n\tcomputePosition,\n\tflip,\n\tshift,\n\tsize,\n} from \"@floating-ui/dom\";\nimport clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\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 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 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\tevents(\"add\", element, rest);\n\treturn () => off(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_mtdsCleanups?: 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 */\nexport const onLoaded = (setup: () => Array<() => void>) => {\n\tif (!IS_BROWSER || !window.requestAnimationFrame) return; // Skip if not in browser environment\n\tif (!window._mtdsCleanups) window._mtdsCleanups = new Map();\n\n\tconst run = () =>\n\t\trequestAnimationFrame(() => {\n\t\t\tconst key = String(setup).replace(/(\\n|\\s)/g, \"\"); // Create a key based on setup function body\n\t\t\twindow._mtdsCleanups?.get(key)?.map((cleanup) => cleanup()); // Run cleanups\n\t\t\twindow._mtdsCleanups?.set(key, setup()); // Rum setup and store cleanups\n\t\t});\n\n\tif (document.readyState === \"complete\") run();\n\telse on(window, \"load\", run);\n};\n\ntype AnchorOptions = Parameters<typeof computePosition>[2] & {\n\tcontain?: SizeOptions[\"apply\"] | false;\n};\nconst ANCHORED = new WeakMap<Element, ReturnType<typeof autoUpdate>>();\nconst DIALOG = `.${styles.dialog.split(\" \")[0]}`;\nexport function anchorPosition(\n\ttarget: HTMLElement,\n\tanchor: false | Element,\n\t{ contain, middleware, placement, ...options }: AnchorOptions = {},\n) {\n\tANCHORED.get(target)?.(); // Unbind previous anchor position\n\tANCHORED.delete(target);\n\n\t// TODO aria-label på app\n\tif (anchor) {\n\t\tconst footer = target.closest(DIALOG)?.querySelector(\":scope > footer\");\n\t\tconst inset = Number(attr(target, \"data-inset\")) || 20;\n\t\tconst bottom = (footer?.clientHeight || 0) + inset;\n\t\tconst padding = { bottom, left: inset, right: inset, top: inset };\n\t\tconst position = (attr(target, \"data-position\") ?? \"bottom\") as Placement;\n\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, {\n\t\t\t\t\t...options,\n\t\t\t\t\tplacement: placement || position,\n\t\t\t\t\tmiddleware: [\n\t\t\t\t\t\tflip({ padding }),\n\t\t\t\t\t\tshift(),\n\t\t\t\t\t\t...(contain ? [size({ padding, apply: contain })] : []),\n\t\t\t\t\t\t...(middleware || []),\n\t\t\t\t\t],\n\t\t\t\t}).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\t}\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function onMutation(callback: MutationCallback, ...attrs: string[]) {\n\tlet queue = 0;\n\tconst onFrame = () => setTimeout(onTimer, 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tif (!IS_BROWSER) return cleanup(); // If using JSDOM, the document might have been removed\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\tconst cleanup = () => {\n\t\ttry {\n\t\t\tobserver.disconnect();\n\t\t} catch (_) {\n\t\t\t// No more observer\n\t\t}\n\t};\n\n\tobserver.observe(document.documentElement, {\n\t\tattributeFilter: attrs,\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t});\n\n\treturn cleanup;\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 as string); // 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\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>,\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"],"names":["QUICK_EVENT","IS_BROWSER","debounce","callback","delay","timer","args","attr","el","name","value","id","UUID","useId","events","action","element","type","rest","on","off","onLoaded","setup","run","key","cleanup","ANCHORED","DIALOG","styles","anchorPosition","target","anchor","contain","middleware","placement","options","footer","inset","padding","position","autoUpdate","computePosition","flip","shift","size","x","y","onMutation","attrs","queue","onFrame","onTimer","observer","isInputLike","SELECTED","toCustomElementProps","className","hidden","open","klass","clsx","tag","tagName","text","val","MTDSElement"],"mappings":";;;AAWO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,IACZ,OAAO,SAAW,OAAe,OAAO,WAAa;AAY/C,SAASC,EACfC,GACAC,GACC;AACD,MAAIC;AAEJ,SAAO,YAA4BC,GAAS;AAC3C,iBAAaD,CAAK,GAClBA,IAAQ,WAAW,MAAMF,EAAS,MAAM,MAAMG,CAAI,GAAGF,CAAK;AAAA,EAC3D;AACD;AASO,SAASG,EACfC,GACAC,GACAC,GACgB;AAChB,SAAIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAAMF,EAAG,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAOF,EAAG,aAAaC,GAAMC,CAAK,GAC9D;AACR;AAMA,IAAIC,IAAK;AACT,MAAMC,IAAO,GAAG,KAAK,MAAM,SAAS,EAAE,CAAC,GAAG,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AACzE,SAASC,EAAML,GAAa;AAClC,SAAKA,EAAG,OAAIA,EAAG,KAAK,GAAGI,CAAI,GAAG,EAAED,CAAE,KAC3BH,EAAG;AACX;AAGA,MAAMM,IAAS,CACdC,GACAC,GACA,KAAQ,MACE;AACV,aAAWC,KAAQC,EAAK,CAAC,EAAE,MAAM,GAAG;AACnC,IAAAA,EAAK,CAAC,IAAID,GACVD,EAAQ,GAAGD,CAAM,eAAe,EAAE,GAAGG,CAAI;AAE3C,GAQaC,IAAK,CACjBH,MACGE,OAEHJ,EAAO,OAAOE,GAASE,CAAI,GACpB,MAAME,EAAIJ,GAAS,GAAGE,CAAI,IASrBE,IAAM,CAClBJ,MACGE,MACOJ,EAAO,UAAUE,GAASE,CAAI,GAa5BG,IAAW,CAACC,MAAmC;AAC3D,MAAI,C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AAO,MACxDE,KAAaG,OAAOzC,EAAK,QAAQ0C,EAAKD,GAAOH,CAAmB,IAChEC,QAAa,SAAS,KACtBC,QAAW,OAAO,KACfxC,IAWK2C,IAAM,CAClBC,GACAd,GACAe,MACoC;AACpC,QAAMvD,IAAK,SAAS,cAAcsD,CAAO;AAEzC,MADIC,QAAS,cAAcA,IACvBf,EAAO,YAAW,CAACxB,GAAKwC,CAAG,KAAK,OAAO,QAAQhB,CAAK,EAAG,CAAAzC,EAAKC,GAAIgB,GAAKwC,CAAG;AAC5E,SAAOxD;AACR,GAGayD,IACZ,OAAO,cAAgB,MACnB,MAAM;AAAC,IACR;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import type { Placement, SizeOptions } from \"@floating-ui/dom\";\nimport {\n\tautoUpdate,\n\tcomputePosition,\n\tflip,\n\tshift,\n\tsize,\n} from \"@floating-ui/dom\";\nimport clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const IS_BROWSER =\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\";\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 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\tevents(\"add\", element, rest);\n\treturn () => off(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_mtdsCleanups?: 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 */\nexport const onLoaded = (setup: () => Array<() => void>) => {\n\tif (!IS_BROWSER || !window.requestAnimationFrame) return; // Skip if not in browser environment\n\tif (!window._mtdsCleanups) window._mtdsCleanups = new Map();\n\n\tconst run = () =>\n\t\trequestAnimationFrame(() => {\n\t\t\tconst key = String(setup).replace(/(\\n|\\s)/g, \"\"); // Create a key based on setup function body\n\t\t\twindow._mtdsCleanups?.get(key)?.map((cleanup) => cleanup()); // Run cleanups\n\t\t\twindow._mtdsCleanups?.set(key, setup()); // Rum setup and store cleanups\n\t\t});\n\n\tif (document.readyState === \"complete\") run();\n\telse on(window, \"load\", run);\n};\n\ntype AnchorOptions = Parameters<typeof computePosition>[2] & {\n\tcontain?: SizeOptions[\"apply\"] | false;\n};\nconst ANCHORED = new WeakMap<Element, ReturnType<typeof autoUpdate>>();\nconst DIALOG = `.${styles.dialog.split(\" \")[0]}`;\nexport function anchorPosition(\n\ttarget: HTMLElement,\n\tanchor: false | Element,\n\t{ contain, middleware, placement, ...options }: AnchorOptions = {},\n) {\n\tANCHORED.get(target)?.(); // Unbind previous anchor position\n\tANCHORED.delete(target);\n\n\t// TODO aria-label på app\n\tif (anchor) {\n\t\tconst footer = target.closest(DIALOG)?.querySelector(\":scope > footer\");\n\t\tconst inset = Number(attr(target, \"data-inset\")) || 20;\n\t\tconst bottom = (footer?.clientHeight || 0) + inset;\n\t\tconst padding = { bottom, left: inset, right: inset, top: inset };\n\t\tconst position = (attr(target, \"data-position\") ?? \"bottom\") as Placement;\n\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, {\n\t\t\t\t\t...options,\n\t\t\t\t\tplacement: placement || position,\n\t\t\t\t\tmiddleware: [\n\t\t\t\t\t\tflip({ padding }),\n\t\t\t\t\t\tshift(),\n\t\t\t\t\t\t...(contain ? [size({ padding, apply: contain })] : []),\n\t\t\t\t\t\t...(middleware || []),\n\t\t\t\t\t],\n\t\t\t\t}).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\t}\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function onMutation(\n\tcallback: (observer: MutationObserver) => void,\n\tattr: string | { attr: string; root?: HTMLElement; delay?: number },\n) {\n\tlet queue = 0;\n\tconst config = typeof attr === \"string\" ? { attr } : attr;\n\tconst onFrame = () => setTimeout(onTimer, config?.delay ?? 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tif (!IS_BROWSER) return cleanup(); // If using JSDOM, the document might have been removed\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\tconst cleanup = () => {\n\t\ttry {\n\t\t\tobserver.disconnect();\n\t\t} catch (_) {\n\t\t\t// No more observer\n\t\t}\n\t};\n\n\tobserver.observe(config?.root || document.documentElement, {\n\t\tattributeFilter: [config.attr],\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t});\n\n\tcallback(observer); // Initial run\n\treturn cleanup;\n}\n\nexport function onResize(callback: ResizeObserverCallback, element: Element) {\n\tconst resize = new ResizeObserver(callback);\n\tresize.observe(element);\n\treturn () => resize.disconnect();\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 as string); // 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\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"],"names":["QUICK_EVENT","IS_BROWSER","debounce","callback","delay","timer","args","attr","el","name","value","id","UUID","useId","events","action","element","type","rest","on","off","onLoaded","setup","run","key","cleanup","ANCHORED","DIALOG","styles","anchorPosition","target","anchor","contain","middleware","placement","options","footer","inset","padding","position","autoUpdate","computePosition","flip","shift","size","x","y","onMutation","queue","config","onFrame","onTimer","observer","onResize","resize","isInputLike","SELECTED","toCustomElementProps","className","hidden","open","klass","clsx","tag","tagName","attrs","text","val","MTDSElement"],"mappings":";;;AAWO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,IACZ,OAAO,SAAW,OAAe,OAAO,WAAa;AAE/C,SAASC,EACfC,GACAC,GACC;AACD,MAAIC;AAEJ,SAAO,YAA4BC,GAAS;AAC3C,iBAAaD,CAAK,GAClBA,IAAQ,WAAW,MAAMF,EAAS,MAAM,MAAMG,CAAI,GAAGF,CAAK;AAAA,EAC3D;AACD;AASO,SAASG,EACfC,GACAC,GACAC,GACgB;AAChB,SAAIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAAMF,EAAG,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAOF,EAAG,aAAaC,GAAMC,CAAK,GAC9D;AACR;AAMA,IAAIC,IAAK;AAC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AO,cAAgB,MACnB,MAAM;AAAC,IACR;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mattilsynet/design",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,21 +50,21 @@
|
|
|
50
50
|
"storybook:build": "npm run build && storybook build"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@biomejs/biome": "
|
|
54
|
-
"@digdir/designsystemet-css": "^1.
|
|
53
|
+
"@biomejs/biome": "2.3.5",
|
|
54
|
+
"@digdir/designsystemet-css": "^1.7.2",
|
|
55
55
|
"@handsontable/react-wrapper": "^16.1.1",
|
|
56
56
|
"@phosphor-icons/core": "^2.1.1",
|
|
57
57
|
"@phosphor-icons/react": "^2.1.10",
|
|
58
|
-
"@storybook/addon-docs": "^10.0.
|
|
59
|
-
"@storybook/addon-themes": "^10.0.
|
|
60
|
-
"@storybook/react-vite": "^10.0.
|
|
58
|
+
"@storybook/addon-docs": "^10.0.7",
|
|
59
|
+
"@storybook/addon-themes": "^10.0.7",
|
|
60
|
+
"@storybook/react-vite": "^10.0.7",
|
|
61
61
|
"@tanstack/react-table": "^8.21.3",
|
|
62
62
|
"@types/leaflet": "^1.9.21",
|
|
63
63
|
"@types/leaflet.markercluster": "^1.5.6",
|
|
64
|
-
"@types/node": "^24.10.
|
|
65
|
-
"@types/react": "^19.2.
|
|
66
|
-
"@types/react-dom": "^19.2.
|
|
67
|
-
"@vitejs/plugin-react": "^5.1.
|
|
64
|
+
"@types/node": "^24.10.1",
|
|
65
|
+
"@types/react": "^19.2.4",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
68
68
|
"fast-glob": "^3.3.3",
|
|
69
69
|
"handsontable": "^16.1.1",
|
|
70
70
|
"leaflet": "^2.0.0-alpha.1",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"postcss-nesting": "^13.0.2",
|
|
73
73
|
"react": "^19.2.0",
|
|
74
74
|
"react-dom": "^19.2.0",
|
|
75
|
-
"storybook": "^10.0.
|
|
75
|
+
"storybook": "^10.0.7",
|
|
76
76
|
"typescript": "^5.9.3",
|
|
77
77
|
"vite": "^7.2.2",
|
|
78
78
|
"vite-plugin-dts": "^4.5.4"
|