@mattilsynet/design 2.2.29 → 2.2.30
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 +8 -9
- package/mtds/alert/alert.js.map +1 -1
- package/mtds/analytics/analytics.js +104 -165
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +27 -73
- package/mtds/app/app-observer.js.map +1 -1
- package/mtds/app/app-toggle.js +24 -2
- package/mtds/app/app-toggle.js.map +1 -1
- package/mtds/app/app-toggle2.js +10 -16
- package/mtds/app/app-toggle2.js.map +1 -1
- package/mtds/app/app.js +32 -36
- package/mtds/app/app.js.map +1 -1
- package/mtds/atlas/atlas-element.d.ts +27 -0
- package/mtds/atlas/atlas-element.js +63 -84
- package/mtds/atlas/atlas-element.js.map +1 -1
- package/mtds/atlas/atlas-marker.js +28 -48
- package/mtds/atlas/atlas-marker.js.map +1 -1
- package/mtds/atlas/atlas-matgeo.d.ts +3 -8
- package/mtds/atlas/atlas-matgeo.js +36 -66
- package/mtds/atlas/atlas-matgeo.js.map +1 -1
- package/mtds/atlas/atlas-wms.js +11 -21
- package/mtds/atlas/atlas-wms.js.map +1 -1
- package/mtds/atlas/atlas.css.js +2 -2
- package/mtds/atlas/atlas.css.js.map +1 -1
- package/mtds/atlas/atlas.js +23 -23
- package/mtds/atlas/atlas.js.map +1 -1
- package/mtds/atlas/atlas.stories.d.ts +1 -0
- package/mtds/atlas/cluster.js +697 -1576
- package/mtds/atlas/cluster.js.map +1 -1
- package/mtds/atlas.iife.js +4 -4
- package/mtds/atlas.js +11 -10
- package/mtds/avatar/avatar.js +8 -8
- package/mtds/avatar/avatar.js.map +1 -1
- package/mtds/badge/badge.js +7 -7
- package/mtds/badge/badge.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs-observer.js +9 -10
- package/mtds/breadcrumbs/breadcrumbs-observer.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs.js +13 -14
- package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
- package/mtds/button/button.js +14 -16
- package/mtds/button/button.js.map +1 -1
- package/mtds/card/card.js +12 -14
- package/mtds/card/card.js.map +1 -1
- package/mtds/chart/chart-axis.js +15 -27
- package/mtds/chart/chart-axis.js.map +1 -1
- package/mtds/chart/chart-bars.js +13 -15
- package/mtds/chart/chart-bars.js.map +1 -1
- package/mtds/chart/chart-element.js +48 -83
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart-lines.js +32 -54
- package/mtds/chart/chart-lines.js.map +1 -1
- package/mtds/chart/chart-pies.js +14 -34
- package/mtds/chart/chart-pies.js.map +1 -1
- package/mtds/chart/chart.css.js +2 -2
- package/mtds/chart/chart.css.js.map +1 -1
- package/mtds/chart/chart.js +12 -12
- package/mtds/chart/chart.js.map +1 -1
- package/mtds/chip/chip.js +8 -8
- package/mtds/chip/chip.js.map +1 -1
- package/mtds/details/details.js +12 -14
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +22 -35
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/dialog/dialog.js +12 -12
- package/mtds/dialog/dialog.js.map +1 -1
- package/mtds/divider/divider.js +10 -10
- package/mtds/divider/divider.js.map +1 -1
- package/mtds/errorsummary/errorsummary-observer.js +8 -11
- package/mtds/errorsummary/errorsummary-observer.js.map +1 -1
- package/mtds/errorsummary/errorsummary.js +11 -11
- package/mtds/errorsummary/errorsummary.js.map +1 -1
- package/mtds/external/@turf/boolean-point-in-polygon/dist/esm/index.js +19 -27
- package/mtds/external/@turf/boolean-point-in-polygon/dist/esm/index.js.map +1 -1
- package/mtds/external/@turf/helpers/dist/esm/index.js +16 -29
- package/mtds/external/@turf/helpers/dist/esm/index.js.map +1 -1
- package/mtds/external/@turf/invariant/dist/esm/index.js +13 -20
- package/mtds/external/@turf/invariant/dist/esm/index.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet-src.js +3096 -6004
- package/mtds/external/leaflet/dist/leaflet-src.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet.css.js +2 -2
- package/mtds/external/leaflet/dist/leaflet.css.js.map +1 -1
- package/mtds/external/point-in-polygon-hao/dist/esm/index.js +16 -46
- package/mtds/external/point-in-polygon-hao/dist/esm/index.js.map +1 -1
- package/mtds/external/robust-predicates/esm/orient2d.js +19 -163
- package/mtds/external/robust-predicates/esm/orient2d.js.map +1 -1
- package/mtds/external/robust-predicates/esm/util.js +25 -85
- package/mtds/external/robust-predicates/esm/util.js.map +1 -1
- package/mtds/field/field-observer.js +53 -101
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.js +145 -177
- package/mtds/field/field.js.map +1 -1
- package/mtds/fieldset/fieldset-observer.js +14 -24
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/fieldset/fieldset.js +20 -23
- package/mtds/fieldset/fieldset.js.map +1 -1
- package/mtds/fileupload/fileupload.js +8 -9
- package/mtds/fileupload/fileupload.js.map +1 -1
- package/mtds/helptext/helptext.js +15 -15
- package/mtds/helptext/helptext.js.map +1 -1
- package/mtds/illustrations/index.json +2 -2
- package/mtds/index.iife.js +15 -15
- package/mtds/index.js +26 -26
- package/mtds/input/input.js +28 -30
- package/mtds/input/input.js.map +1 -1
- package/mtds/law/law-helper.js +77 -143
- package/mtds/law/law-helper.js.map +1 -1
- package/mtds/law/law.js +6 -6
- package/mtds/law/law.js.map +1 -1
- package/mtds/layout/layout.js +10 -13
- package/mtds/layout/layout.js.map +1 -1
- package/mtds/link/link.js +7 -8
- package/mtds/link/link.js.map +1 -1
- package/mtds/logo/logo-observer.js +12 -18
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/logo/logo.js +8 -8
- package/mtds/logo/logo.js.map +1 -1
- package/mtds/package.json.js +2 -2
- package/mtds/pagination/pagination-helper.js +11 -17
- package/mtds/pagination/pagination-helper.js.map +1 -1
- package/mtds/pagination/pagination.js +30 -30
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/popover/popover-observer.js +33 -45
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/popover/popover.js +12 -13
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/progress/progress.js +8 -8
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/react-atlas.js +13 -12
- package/mtds/react.js +80 -80
- package/mtds/skeleton/skeleton.js +8 -8
- package/mtds/skeleton/skeleton.js.map +1 -1
- package/mtds/spinner/spinner.js +8 -8
- package/mtds/spinner/spinner.js.map +1 -1
- package/mtds/steps/steps.js +7 -7
- package/mtds/steps/steps.js.map +1 -1
- package/mtds/styles.css +1 -4605
- package/mtds/styles.json +43 -43
- package/mtds/styles.module.css.js +112 -167
- package/mtds/styles.module.css.js.map +1 -1
- package/mtds/table/table-observer.js +19 -22
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/table/table.d.ts +7 -0
- package/mtds/table/table.js +43 -18
- package/mtds/table/table.js.map +1 -1
- package/mtds/tabs/tabs.js +21 -25
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tag/tag.js +8 -8
- package/mtds/tag/tag.js.map +1 -1
- package/mtds/tailwind.css +6 -25
- package/mtds/toast/toast-helper.js +20 -35
- package/mtds/toast/toast-helper.js.map +1 -1
- package/mtds/toast/toast-observer.js +15 -30
- package/mtds/toast/toast-observer.js.map +1 -1
- package/mtds/toast/toast.js +37 -45
- package/mtds/toast/toast.js.map +1 -1
- package/mtds/togglegroup/togglegroup-observer.js +10 -15
- package/mtds/togglegroup/togglegroup-observer.js.map +1 -1
- package/mtds/togglegroup/togglegroup.js +24 -21
- package/mtds/togglegroup/togglegroup.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +32 -48
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/typography/typography.js +19 -28
- package/mtds/typography/typography.js.map +1 -1
- package/mtds/utils.js +89 -129
- package/mtds/utils.js.map +1 -1
- package/mtds/validation/validation-observer.js +25 -31
- package/mtds/validation/validation-observer.js.map +1 -1
- package/mtds/validation/validation.js +12 -12
- package/mtds/validation/validation.js.map +1 -1
- package/package.json +4 -3
|
@@ -1,119 +1,71 @@
|
|
|
1
|
-
import { UHTMLComboboxElement } from "@u-elements/u-combobox";
|
|
2
|
-
import { UHTMLDataListElement } from "@u-elements/u-datalist";
|
|
3
|
-
import
|
|
4
|
-
import { isBrowser, onLoaded, onMutation, on, QUICK_EVENT, isInputLike, attr, useId, anchorPosition } from "../utils.js";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let valid = true;
|
|
17
|
-
for (const el of field.getElementsByTagName("*")) {
|
|
18
|
-
if (el instanceof HTMLLabelElement) labels.push(el);
|
|
19
|
-
else if (el instanceof UHTMLComboboxElement) combobox = el;
|
|
20
|
-
else if (isInputLike(el) && !el.hidden) input = el;
|
|
21
|
-
else if (el.hasAttribute("data-description")) descriptions.push(el);
|
|
22
|
-
else if (el.classList.contains(CSS_VALIDATION)) {
|
|
23
|
-
valid = attr(el, "data-color") === "success" || !el.clientHeight;
|
|
24
|
-
descriptions.unshift(el);
|
|
25
|
-
} else if (el instanceof HTMLParagraphElement)
|
|
26
|
-
descriptions.some((desc) => desc.contains(el)) || descriptions.push(el);
|
|
27
|
-
}
|
|
28
|
-
if (input) {
|
|
29
|
-
for (const label of labels) label.htmlFor = useId(input);
|
|
30
|
-
renderCombobox(combobox);
|
|
31
|
-
renderCounter(input);
|
|
32
|
-
renderTextareaSize(input);
|
|
33
|
-
attr(input, "aria-describedby", descriptions.map(useId).join(" "));
|
|
34
|
-
attr(input, "aria-invalid", `${!valid}`);
|
|
1
|
+
import { UHTMLComboboxElement as T } from "@u-elements/u-combobox";
|
|
2
|
+
import { UHTMLDataListElement as E } from "@u-elements/u-datalist";
|
|
3
|
+
import p from "../styles.module.css.js";
|
|
4
|
+
import { isBrowser as I, onLoaded as C, onMutation as M, on as c, QUICK_EVENT as m, isInputLike as b, attr as n, useId as f, anchorPosition as u } from "../utils.js";
|
|
5
|
+
const g = p.field.split(" ")[0], h = p.validation.split(" "), $ = h[0], A = I() ? document.getElementsByClassName(g) : [];
|
|
6
|
+
function H() {
|
|
7
|
+
for (const t of A)
|
|
8
|
+
if (t.isConnected) {
|
|
9
|
+
const a = [], i = [];
|
|
10
|
+
let e = null, s = null, l = !0;
|
|
11
|
+
for (const o of t.getElementsByTagName("*"))
|
|
12
|
+
o instanceof HTMLLabelElement ? a.push(o) : o instanceof T ? e = o : b(o) && !o.hidden ? s = o : o.hasAttribute("data-description") ? i.push(o) : o.classList.contains($) ? (l = n(o, "data-color") === "success" || !o.clientHeight, i.unshift(o)) : o instanceof HTMLParagraphElement && (i.some((d) => d.contains(o)) || i.push(o));
|
|
13
|
+
if (s) {
|
|
14
|
+
for (const o of a) o.htmlFor = f(s);
|
|
15
|
+
F(e), x(s), v(s), n(s, "aria-describedby", i.map(f).join(" ")), n(s, "aria-invalid", `${!l}`);
|
|
35
16
|
}
|
|
36
17
|
}
|
|
37
18
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`${textarea.scrollHeight}px`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
19
|
+
function v(t) {
|
|
20
|
+
t instanceof HTMLTextAreaElement && (t.style.setProperty("--mtds-textarea-height", "auto"), t.style.setProperty(
|
|
21
|
+
"--mtds-textarea-height",
|
|
22
|
+
`${t.scrollHeight}px`
|
|
23
|
+
));
|
|
46
24
|
}
|
|
47
|
-
const
|
|
48
|
-
function
|
|
49
|
-
const { control, list } =
|
|
50
|
-
if (
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
attr(el, "data-sr-empty", getText(style, "combobox-empty"));
|
|
54
|
-
attr(el, "data-sr-found", getText(style, "combobox-found"));
|
|
55
|
-
attr(el, "data-sr-invalid", getText(style, "combobox-invalid"));
|
|
56
|
-
attr(el, "data-sr-of", getText(style, "combobox-of"));
|
|
57
|
-
attr(el, "data-sr-remove", getText(style, "combobox-remove"));
|
|
58
|
-
attr(el, "data-sr-removed", getText(style, "combobox-removed"));
|
|
59
|
-
attr(list, "data-sr-plural", getText(style, "datalist-plural"));
|
|
60
|
-
attr(list, "data-sr-singular", getText(style, "datalist-singular"));
|
|
61
|
-
}
|
|
62
|
-
if (list && control && !list.hasAttribute("popover")) {
|
|
63
|
-
attr(list, "popover", "manual");
|
|
64
|
-
attr(control, "popovertarget", useId(list));
|
|
25
|
+
const r = (t, a) => t.getPropertyValue(`--mtds-text-${a}`)?.slice(1, -1) || "";
|
|
26
|
+
function F(t) {
|
|
27
|
+
const { control: a, list: i } = t || {};
|
|
28
|
+
if (t && i && !t.hasAttribute("data-sr-added")) {
|
|
29
|
+
const e = window.getComputedStyle(t);
|
|
30
|
+
n(t, "data-sr-added", r(e, "combobox-added")), n(t, "data-sr-empty", r(e, "combobox-empty")), n(t, "data-sr-found", r(e, "combobox-found")), n(t, "data-sr-invalid", r(e, "combobox-invalid")), n(t, "data-sr-of", r(e, "combobox-of")), n(t, "data-sr-remove", r(e, "combobox-remove")), n(t, "data-sr-removed", r(e, "combobox-removed")), n(i, "data-sr-plural", r(e, "datalist-plural")), n(i, "data-sr-singular", r(e, "datalist-singular"));
|
|
65
31
|
}
|
|
32
|
+
i && a && !i.hasAttribute("popover") && (n(i, "popover", "manual"), n(a, "popovertarget", f(i)));
|
|
66
33
|
}
|
|
67
|
-
function
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const style = window.getComputedStyle(el || input);
|
|
75
|
-
const over = getText(style, "count-over");
|
|
76
|
-
const under = getText(style, "count-under");
|
|
77
|
-
const label = `${(nextInvalid ? over : under).replace("%d", `${Math.abs(remainder)}`)}`;
|
|
78
|
-
if (prevInvalid !== nextInvalid) {
|
|
79
|
-
attr(el, "aria-live", nextInvalid ? "polite" : "off");
|
|
80
|
-
for (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);
|
|
34
|
+
function x(t) {
|
|
35
|
+
const a = t?.nextElementSibling, i = a && n(a, "data-count");
|
|
36
|
+
if (a && i) {
|
|
37
|
+
const e = Number(i) - t.value.length, s = e < 0, l = n(a, "aria-live") === "polite", o = window.getComputedStyle(a || t), d = r(o, "count-over"), y = r(o, "count-under"), L = `${(s ? d : y).replace("%d", `${Math.abs(e)}`)}`;
|
|
38
|
+
if (l !== s) {
|
|
39
|
+
n(a, "aria-live", s ? "polite" : "off");
|
|
40
|
+
for (const S of h) a.classList.toggle(S, s);
|
|
81
41
|
}
|
|
82
|
-
|
|
42
|
+
n(a, "aria-label", L);
|
|
83
43
|
}
|
|
84
44
|
}
|
|
85
|
-
function
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
`[popovertarget="${el.id}"]`
|
|
45
|
+
function N({ target: t, newState: a }) {
|
|
46
|
+
if (t instanceof E) {
|
|
47
|
+
const e = t.getRootNode()?.querySelector(
|
|
48
|
+
`[popovertarget="${t.id}"]`
|
|
90
49
|
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
el.style.maxHeight = `${Math.max(50, availableHeight)}px`;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
50
|
+
a === "closed" ? u(t, !1) : e && u(t, e, {
|
|
51
|
+
contain({ availableHeight: s }) {
|
|
52
|
+
t.style.width = `${e.clientWidth}px`, t.style.maxHeight = `${Math.max(50, s)}px`;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
99
55
|
}
|
|
100
56
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
renderCounter(event.target);
|
|
104
|
-
renderTextareaSize(event.target);
|
|
105
|
-
}
|
|
57
|
+
function w(t) {
|
|
58
|
+
b(t.target) && (x(t.target), v(t.target));
|
|
106
59
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
109
|
-
event.preventDefault();
|
|
60
|
+
function D(t) {
|
|
61
|
+
t.target?.closest?.(`.${g}`) && t.preventDefault();
|
|
110
62
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
63
|
+
C(() => [
|
|
64
|
+
M(() => H(), "class"),
|
|
65
|
+
c(document, "input", w, m),
|
|
66
|
+
c(document, "toggle", N, m),
|
|
115
67
|
// Use capture since toggle does not bubble
|
|
116
|
-
|
|
68
|
+
c(document, "invalid", D, !0)
|
|
117
69
|
// Use capture as invalid and submit does not bubble
|
|
118
70
|
]);
|
|
119
71
|
//# sourceMappingURL=field-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tisBrowser,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst FIELDS = isBrowser() ? document.getElementsByClassName(CSS_FIELD) : [];\n\nfunction handleFieldMutation() {\n\tfor (const field of FIELDS)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descriptions: Element[] = [];\n\t\t\tconst validationMsg: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descriptions.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalidationMsg.push(el);\n\t\t\t\t\tdescriptions.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescriptions.some((desc) => desc.contains(el)) ||\n\t\t\t\t\t\tdescriptions.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descriptions.map(useId).join(\" \"));\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\t\tconst label = `${(nextInvalid ? over : under).replace(\"%d\", `${Math.abs(remainder)}`)}`;\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tattr(el, \"aria-label\", label);\n\t}\n}\n\nfunction handleFieldToggle({ target: el, newState }: Partial<ToggleEvent>) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(el, anchor, {\n\t\t\t\tcontain({ availableHeight }) {\n\t\t\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\t\t\tel.style.maxHeight = `${Math.max(50, availableHeight)}px`;\n\t\t\t\t},\n\t\t\t});\n\t}\n}\n// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tif ((event.target as Element)?.closest?.(`.${CSS_FIELD}`))\n\t\tevent.preventDefault(); // Prevent browsers from showing default validation bubbles\n}\n\nonLoaded(() => [\n\tonMutation(() => handleFieldMutation(), \"class\"),\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT),\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT), // Use capture since toggle does not bubble\n\ton(document, \"invalid\", handleFieldValdiation, true), // Use capture as invalid and submit does not bubble\n]);\n"],"names":[],"mappings":";;;;AAeA,
|
|
1
|
+
{"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tisBrowser,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst FIELDS = isBrowser() ? document.getElementsByClassName(CSS_FIELD) : [];\n\nfunction handleFieldMutation() {\n\tfor (const field of FIELDS)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descriptions: Element[] = [];\n\t\t\tconst validationMsg: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descriptions.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalidationMsg.push(el);\n\t\t\t\t\tdescriptions.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescriptions.some((desc) => desc.contains(el)) ||\n\t\t\t\t\t\tdescriptions.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descriptions.map(useId).join(\" \"));\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\t\tconst label = `${(nextInvalid ? over : under).replace(\"%d\", `${Math.abs(remainder)}`)}`;\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tattr(el, \"aria-label\", label);\n\t}\n}\n\nfunction handleFieldToggle({ target: el, newState }: Partial<ToggleEvent>) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(el, anchor, {\n\t\t\t\tcontain({ availableHeight }) {\n\t\t\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\t\t\tel.style.maxHeight = `${Math.max(50, availableHeight)}px`;\n\t\t\t\t},\n\t\t\t});\n\t}\n}\n// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tif ((event.target as Element)?.closest?.(`.${CSS_FIELD}`))\n\t\tevent.preventDefault(); // Prevent browsers from showing default validation bubbles\n}\n\nonLoaded(() => [\n\tonMutation(() => handleFieldMutation(), \"class\"),\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT),\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT), // Use capture since toggle does not bubble\n\ton(document, \"invalid\", handleFieldValdiation, true), // Use capture as invalid and submit does not bubble\n]);\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","FIELDS","isBrowser","handleFieldMutation","field","labels","descriptions","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","getText","style","key","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleFieldToggle","newState","UHTMLDataListElement","anchor","anchorPosition","availableHeight","handleFieldInput","event","handleFieldValdiation","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAeA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAClCE,IAASC,EAAA,IAAc,SAAS,uBAAuBL,CAAS,IAAI,CAAA;AAE1E,SAASM,IAAsB;AAC9B,aAAWC,KAASH;AACnB,QAAIG,EAAM,aAAa;AACtB,YAAMC,IAA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ragment, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
|
|
5
|
-
import { HelpText } from "../helptext/helptext.js";
|
|
6
|
-
import { Input } from "../input/input.js";
|
|
7
|
-
import
|
|
8
|
-
import { toCustomElementProps } from "../utils.js";
|
|
9
|
-
import { Validation } from "../validation/validation.js";
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
"data-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"data-size": size,
|
|
33
|
-
"data-validation": dataValidation,
|
|
34
|
-
className: clsx(styles.field, className),
|
|
35
|
-
style
|
|
2
|
+
import { jsx as e, Fragment as P, jsxs as W } from "react/jsx-runtime";
|
|
3
|
+
import S from "clsx";
|
|
4
|
+
import { forwardRef as s, useRef as k, useImperativeHandle as Y, useEffect as Z } from "react";
|
|
5
|
+
import { HelpText as _ } from "../helptext/helptext.js";
|
|
6
|
+
import { Input as $ } from "../input/input.js";
|
|
7
|
+
import D from "../styles.module.css.js";
|
|
8
|
+
import { toCustomElementProps as q } from "../utils.js";
|
|
9
|
+
import { Validation as ee } from "../validation/validation.js";
|
|
10
|
+
const T = (i) => typeof i == "string" ? { label: i, value: i } : i, ne = s(function({
|
|
11
|
+
"data-size": n,
|
|
12
|
+
"data-validation": t,
|
|
13
|
+
as: o,
|
|
14
|
+
className: u,
|
|
15
|
+
count: f,
|
|
16
|
+
description: m,
|
|
17
|
+
error: v,
|
|
18
|
+
helpText: x,
|
|
19
|
+
helpTextLabel: g,
|
|
20
|
+
label: b,
|
|
21
|
+
prefix: h,
|
|
22
|
+
style: O,
|
|
23
|
+
suffix: F,
|
|
24
|
+
validation: j,
|
|
25
|
+
...r
|
|
26
|
+
}, l) {
|
|
27
|
+
const C = o || "div", L = !!F || !!h, c = j || v, y = {
|
|
28
|
+
"data-size": n,
|
|
29
|
+
"data-validation": t,
|
|
30
|
+
className: S(D.field, u),
|
|
31
|
+
style: O
|
|
36
32
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
!!
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/* @__PURE__ */ jsx(
|
|
50
|
-
Tag,
|
|
33
|
+
return o === "select" && !r.children && Object.assign(r, {
|
|
34
|
+
options: void 0,
|
|
35
|
+
// Ensure options is not passed to DOM
|
|
36
|
+
children: /* @__PURE__ */ e(P, { children: r.options?.map(T).map(({ label: E, value: H }) => /* @__PURE__ */ e("option", { value: H, children: E }, H)) })
|
|
37
|
+
}), o ? /* @__PURE__ */ W("div", { ...y, children: [
|
|
38
|
+
!!b && /* @__PURE__ */ e(J, { children: b }),
|
|
39
|
+
!!x && /* @__PURE__ */ e(_, { "aria-label": g, children: x }),
|
|
40
|
+
!!m && /* @__PURE__ */ e(K, { children: m }),
|
|
41
|
+
L ? /* @__PURE__ */ W(V, { children: [
|
|
42
|
+
!!h && /* @__PURE__ */ e("span", { children: h }),
|
|
43
|
+
/* @__PURE__ */ e(
|
|
44
|
+
C,
|
|
51
45
|
{
|
|
52
|
-
className:
|
|
53
|
-
suppressHydrationWarning:
|
|
54
|
-
ref,
|
|
55
|
-
...
|
|
46
|
+
className: D.input,
|
|
47
|
+
suppressHydrationWarning: !0,
|
|
48
|
+
ref: l,
|
|
49
|
+
...r
|
|
56
50
|
}
|
|
57
51
|
),
|
|
58
|
-
!!
|
|
59
|
-
] }) : /* @__PURE__ */
|
|
60
|
-
|
|
52
|
+
!!F && /* @__PURE__ */ e("span", { children: F })
|
|
53
|
+
] }) : /* @__PURE__ */ e(
|
|
54
|
+
C,
|
|
61
55
|
{
|
|
62
|
-
className: typeof
|
|
63
|
-
suppressHydrationWarning:
|
|
64
|
-
ref,
|
|
65
|
-
...
|
|
56
|
+
className: typeof o == "string" ? D.input : void 0,
|
|
57
|
+
suppressHydrationWarning: !0,
|
|
58
|
+
ref: l,
|
|
59
|
+
...r
|
|
66
60
|
}
|
|
67
61
|
),
|
|
68
|
-
!!
|
|
69
|
-
!!
|
|
70
|
-
] }) : /* @__PURE__ */
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return /* @__PURE__ */ jsx("div", { className: clsx(styles.affixes, className), ref, ...rest });
|
|
62
|
+
!!c && /* @__PURE__ */ e(ee, { children: c }),
|
|
63
|
+
!!f && /* @__PURE__ */ e(M, { "data-count": f })
|
|
64
|
+
] }) : /* @__PURE__ */ e("div", { ref: l, ...y, ...r });
|
|
65
|
+
}), V = s(
|
|
66
|
+
function({ className: n, ...t }, o) {
|
|
67
|
+
return /* @__PURE__ */ e("div", { className: S(D.affixes, n), ref: o, ...t });
|
|
75
68
|
}
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return /* @__PURE__ */ jsx(
|
|
69
|
+
), B = s(
|
|
70
|
+
function({ "data-nofilter": n, ...t }, o) {
|
|
71
|
+
return /* @__PURE__ */ e(
|
|
80
72
|
"u-datalist",
|
|
81
73
|
{
|
|
82
|
-
"data-nofilter": !!
|
|
83
|
-
ref,
|
|
84
|
-
...
|
|
74
|
+
"data-nofilter": !!n || void 0,
|
|
75
|
+
ref: o,
|
|
76
|
+
...q(t)
|
|
85
77
|
}
|
|
86
78
|
);
|
|
87
79
|
}
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return /* @__PURE__ */ jsx("u-option", { ref, ...toCustomElementProps(props) });
|
|
80
|
+
), G = s(
|
|
81
|
+
function(n, t) {
|
|
82
|
+
return /* @__PURE__ */ e("u-option", { ref: t, ...q(n) });
|
|
92
83
|
}
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
"data-
|
|
98
|
-
"data-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
console.warn(
|
|
130
|
-
`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
useImperativeHandle(ref, () => innerRef.current);
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
const self = innerRef.current;
|
|
136
|
-
const handleChange = (event) => {
|
|
137
|
-
const handleSelected = onSelected.current;
|
|
138
|
-
if (!onSelected) return;
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
const { isConnected: remove, textContent, value } = event.detail;
|
|
141
|
-
const label = textContent?.trim() || "";
|
|
142
|
-
const prev = selected || [];
|
|
143
|
-
if (remove) handleSelected?.(prev.filter((i) => i.value !== value));
|
|
144
|
-
else if (multiple) handleSelected?.([...prev, { value, label }]);
|
|
145
|
-
else handleSelected?.([{ value, label }]);
|
|
84
|
+
), te = s(
|
|
85
|
+
function({
|
|
86
|
+
"aria-required": n,
|
|
87
|
+
"data-position": t,
|
|
88
|
+
"data-nofilter": o,
|
|
89
|
+
"data-multiple": u,
|
|
90
|
+
onAfterChange: f,
|
|
91
|
+
onAfterSelect: m,
|
|
92
|
+
onBeforeChange: v,
|
|
93
|
+
onBeforeMatch: x,
|
|
94
|
+
onBeforeSelect: g,
|
|
95
|
+
onSelectedChange: b,
|
|
96
|
+
onInput: h,
|
|
97
|
+
onChange: O,
|
|
98
|
+
children: F,
|
|
99
|
+
disabled: j,
|
|
100
|
+
name: r,
|
|
101
|
+
options: l,
|
|
102
|
+
placeholder: C,
|
|
103
|
+
readOnly: L,
|
|
104
|
+
selected: c,
|
|
105
|
+
type: y,
|
|
106
|
+
...E
|
|
107
|
+
}, H) {
|
|
108
|
+
const N = k(null), w = k(b);
|
|
109
|
+
return w.current = b, f && (m = f, console.warn(
|
|
110
|
+
"Combobox onAfterChange is deprecated, use onAfterSelect instead."
|
|
111
|
+
)), v && (g = v, console.warn(
|
|
112
|
+
"Combobox onBeforeChange is deprecated, use onBeforeSelect instead."
|
|
113
|
+
)), Y(H, () => N.current), Z(() => {
|
|
114
|
+
const p = N.current, d = (a) => {
|
|
115
|
+
const A = w.current;
|
|
116
|
+
if (!w) return;
|
|
117
|
+
a.preventDefault();
|
|
118
|
+
const { isConnected: Q, textContent: U, value: R } = a.detail, z = U?.trim() || "", I = c || [];
|
|
119
|
+
A?.(Q ? I.filter((X) => X.value !== R) : u ? [...I, { value: R, label: z }] : [{ value: R, label: z }]);
|
|
146
120
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}, [multiple, selected]);
|
|
150
|
-
return /* @__PURE__ */ jsxs(
|
|
121
|
+
return p?.addEventListener("comboboxbeforeselect", d), () => p?.removeEventListener("comboboxbeforeselect", d);
|
|
122
|
+
}, [u, c]), /* @__PURE__ */ W(
|
|
151
123
|
"u-combobox",
|
|
152
124
|
{
|
|
153
|
-
"data-multiple":
|
|
154
|
-
...
|
|
155
|
-
oncomboboxbeforeselect:
|
|
156
|
-
oncomboboxbeforematch:
|
|
157
|
-
oncomboboxafterselect:
|
|
158
|
-
ref:
|
|
159
|
-
...
|
|
125
|
+
"data-multiple": u || void 0,
|
|
126
|
+
...q({
|
|
127
|
+
oncomboboxbeforeselect: g,
|
|
128
|
+
oncomboboxbeforematch: x,
|
|
129
|
+
oncomboboxafterselect: m,
|
|
130
|
+
ref: N,
|
|
131
|
+
...E
|
|
160
132
|
}),
|
|
161
133
|
children: [
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
/* @__PURE__ */
|
|
165
|
-
|
|
134
|
+
c?.map(({ children: p, label: d, value: a }) => /* @__PURE__ */ e("data", { value: a, suppressHydrationWarning: !0, children: p ?? d }, a)),
|
|
135
|
+
F || /* @__PURE__ */ W(P, { children: [
|
|
136
|
+
/* @__PURE__ */ e(
|
|
137
|
+
$,
|
|
166
138
|
{
|
|
167
|
-
"aria-required":
|
|
168
|
-
disabled,
|
|
169
|
-
name,
|
|
170
|
-
onInput,
|
|
171
|
-
onChange,
|
|
172
|
-
placeholder,
|
|
173
|
-
readOnly,
|
|
174
|
-
type
|
|
139
|
+
"aria-required": n,
|
|
140
|
+
disabled: j,
|
|
141
|
+
name: r,
|
|
142
|
+
onInput: h,
|
|
143
|
+
onChange: O,
|
|
144
|
+
placeholder: C,
|
|
145
|
+
readOnly: L,
|
|
146
|
+
type: y
|
|
175
147
|
}
|
|
176
148
|
),
|
|
177
|
-
/* @__PURE__ */
|
|
149
|
+
/* @__PURE__ */ e("del", { "aria-label": "Fjern tekst", suppressHydrationWarning: !0 })
|
|
178
150
|
] }),
|
|
179
|
-
!!
|
|
151
|
+
!!l && /* @__PURE__ */ e(B, { "data-nofilter": o, "data-position": t, children: l.map(T).map(({ children: p, label: d, value: a }) => /* @__PURE__ */ e(G, { value: a, label: d, children: p ?? d }, a)) })
|
|
180
152
|
]
|
|
181
153
|
}
|
|
182
154
|
);
|
|
183
155
|
}
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return /* @__PURE__ */ jsx("label", { suppressHydrationWarning: true, ref, ...rest });
|
|
156
|
+
), J = s(
|
|
157
|
+
function(n, t) {
|
|
158
|
+
return /* @__PURE__ */ e("label", { suppressHydrationWarning: !0, ref: t, ...n });
|
|
188
159
|
}
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
function FieldCount2(rest, ref) {
|
|
195
|
-
return /* @__PURE__ */ jsx("p", { suppressHydrationWarning: true, ref, ...rest });
|
|
160
|
+
), K = s(function(n, t) {
|
|
161
|
+
return /* @__PURE__ */ e("p", { suppressHydrationWarning: !0, ref: t, ...n });
|
|
162
|
+
}), M = s(
|
|
163
|
+
function(n, t) {
|
|
164
|
+
return /* @__PURE__ */ e("p", { suppressHydrationWarning: !0, ref: t, ...n });
|
|
196
165
|
}
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
Count: FieldCount
|
|
166
|
+
), pe = Object.assign(ne, {
|
|
167
|
+
Affixes: V,
|
|
168
|
+
Combobox: te,
|
|
169
|
+
Datalist: B,
|
|
170
|
+
Option: G,
|
|
171
|
+
Description: K,
|
|
172
|
+
Label: J,
|
|
173
|
+
Count: M
|
|
206
174
|
});
|
|
207
175
|
export {
|
|
208
|
-
Field,
|
|
209
|
-
FieldComp
|
|
176
|
+
pe as Field,
|
|
177
|
+
ne as FieldComp
|
|
210
178
|
};
|
|
211
179
|
//# sourceMappingURL=field.js.map
|