@mattilsynet/design 2.2.29 → 2.2.31

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.
Files changed (175) hide show
  1. package/mtds/alert/alert.js +8 -9
  2. package/mtds/alert/alert.js.map +1 -1
  3. package/mtds/analytics/analytics.js +104 -165
  4. package/mtds/analytics/analytics.js.map +1 -1
  5. package/mtds/app/app-observer.js +28 -74
  6. package/mtds/app/app-observer.js.map +1 -1
  7. package/mtds/app/app-toggle.js +10 -4
  8. package/mtds/app/app-toggle.js.map +1 -1
  9. package/mtds/app/app-toggle2.js +26 -16
  10. package/mtds/app/app-toggle2.js.map +1 -1
  11. package/mtds/app/app.js +32 -36
  12. package/mtds/app/app.js.map +1 -1
  13. package/mtds/atlas/atlas-element.d.ts +27 -0
  14. package/mtds/atlas/atlas-element.js +63 -84
  15. package/mtds/atlas/atlas-element.js.map +1 -1
  16. package/mtds/atlas/atlas-marker.js +28 -48
  17. package/mtds/atlas/atlas-marker.js.map +1 -1
  18. package/mtds/atlas/atlas-matgeo.d.ts +3 -8
  19. package/mtds/atlas/atlas-matgeo.js +36 -66
  20. package/mtds/atlas/atlas-matgeo.js.map +1 -1
  21. package/mtds/atlas/atlas-wms.js +11 -21
  22. package/mtds/atlas/atlas-wms.js.map +1 -1
  23. package/mtds/atlas/atlas.css.js +5 -4
  24. package/mtds/atlas/atlas.css.js.map +1 -1
  25. package/mtds/atlas/atlas.js +23 -23
  26. package/mtds/atlas/atlas.js.map +1 -1
  27. package/mtds/atlas/atlas.stories.d.ts +1 -0
  28. package/mtds/atlas/cluster.js +697 -1576
  29. package/mtds/atlas/cluster.js.map +1 -1
  30. package/mtds/atlas.iife.js +7 -6
  31. package/mtds/atlas.js +11 -10
  32. package/mtds/avatar/avatar.js +8 -8
  33. package/mtds/avatar/avatar.js.map +1 -1
  34. package/mtds/badge/badge.js +7 -7
  35. package/mtds/badge/badge.js.map +1 -1
  36. package/mtds/breadcrumbs/breadcrumbs-observer.js +9 -10
  37. package/mtds/breadcrumbs/breadcrumbs-observer.js.map +1 -1
  38. package/mtds/breadcrumbs/breadcrumbs.js +13 -14
  39. package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
  40. package/mtds/button/button.js +14 -16
  41. package/mtds/button/button.js.map +1 -1
  42. package/mtds/card/card.js +12 -14
  43. package/mtds/card/card.js.map +1 -1
  44. package/mtds/chart/chart-axis.js +15 -27
  45. package/mtds/chart/chart-axis.js.map +1 -1
  46. package/mtds/chart/chart-bars.js +13 -15
  47. package/mtds/chart/chart-bars.js.map +1 -1
  48. package/mtds/chart/chart-element.js +48 -83
  49. package/mtds/chart/chart-element.js.map +1 -1
  50. package/mtds/chart/chart-lines.js +32 -54
  51. package/mtds/chart/chart-lines.js.map +1 -1
  52. package/mtds/chart/chart-pies.js +14 -34
  53. package/mtds/chart/chart-pies.js.map +1 -1
  54. package/mtds/chart/chart.css.js +2 -2
  55. package/mtds/chart/chart.css.js.map +1 -1
  56. package/mtds/chart/chart.js +12 -12
  57. package/mtds/chart/chart.js.map +1 -1
  58. package/mtds/chip/chip.js +8 -8
  59. package/mtds/chip/chip.js.map +1 -1
  60. package/mtds/details/details.js +12 -14
  61. package/mtds/details/details.js.map +1 -1
  62. package/mtds/dialog/dialog-observer.js +22 -35
  63. package/mtds/dialog/dialog-observer.js.map +1 -1
  64. package/mtds/dialog/dialog.js +12 -12
  65. package/mtds/dialog/dialog.js.map +1 -1
  66. package/mtds/divider/divider.js +10 -10
  67. package/mtds/divider/divider.js.map +1 -1
  68. package/mtds/errorsummary/errorsummary-observer.js +8 -11
  69. package/mtds/errorsummary/errorsummary-observer.js.map +1 -1
  70. package/mtds/errorsummary/errorsummary.js +11 -11
  71. package/mtds/errorsummary/errorsummary.js.map +1 -1
  72. package/mtds/external/@turf/boolean-point-in-polygon/dist/esm/index.js +19 -27
  73. package/mtds/external/@turf/boolean-point-in-polygon/dist/esm/index.js.map +1 -1
  74. package/mtds/external/@turf/helpers/dist/esm/index.js +16 -29
  75. package/mtds/external/@turf/helpers/dist/esm/index.js.map +1 -1
  76. package/mtds/external/@turf/invariant/dist/esm/index.js +13 -20
  77. package/mtds/external/@turf/invariant/dist/esm/index.js.map +1 -1
  78. package/mtds/external/leaflet/dist/leaflet-src.js +3099 -6007
  79. package/mtds/external/leaflet/dist/leaflet-src.js.map +1 -1
  80. package/mtds/external/leaflet/dist/leaflet.css.js +2 -2
  81. package/mtds/external/leaflet/dist/leaflet.css.js.map +1 -1
  82. package/mtds/external/point-in-polygon-hao/dist/esm/index.js +16 -46
  83. package/mtds/external/point-in-polygon-hao/dist/esm/index.js.map +1 -1
  84. package/mtds/external/robust-predicates/esm/orient2d.js +19 -163
  85. package/mtds/external/robust-predicates/esm/orient2d.js.map +1 -1
  86. package/mtds/external/robust-predicates/esm/util.js +25 -85
  87. package/mtds/external/robust-predicates/esm/util.js.map +1 -1
  88. package/mtds/field/field-observer.js +53 -101
  89. package/mtds/field/field-observer.js.map +1 -1
  90. package/mtds/field/field.js +145 -177
  91. package/mtds/field/field.js.map +1 -1
  92. package/mtds/fieldset/fieldset-observer.js +14 -24
  93. package/mtds/fieldset/fieldset-observer.js.map +1 -1
  94. package/mtds/fieldset/fieldset.js +20 -23
  95. package/mtds/fieldset/fieldset.js.map +1 -1
  96. package/mtds/fileupload/fileupload.js +8 -9
  97. package/mtds/fileupload/fileupload.js.map +1 -1
  98. package/mtds/helptext/helptext.js +15 -15
  99. package/mtds/helptext/helptext.js.map +1 -1
  100. package/mtds/illustrations/index.json +2 -2
  101. package/mtds/index.d.ts +1 -0
  102. package/mtds/index.iife.js +165 -15
  103. package/mtds/index.js +29 -26
  104. package/mtds/index.js.map +1 -1
  105. package/mtds/input/input.js +28 -30
  106. package/mtds/input/input.js.map +1 -1
  107. package/mtds/law/law-helper.js +77 -143
  108. package/mtds/law/law-helper.js.map +1 -1
  109. package/mtds/law/law.js +6 -6
  110. package/mtds/law/law.js.map +1 -1
  111. package/mtds/layout/layout.js +10 -13
  112. package/mtds/layout/layout.js.map +1 -1
  113. package/mtds/link/link.js +7 -8
  114. package/mtds/link/link.js.map +1 -1
  115. package/mtds/logo/logo-observer.js +12 -18
  116. package/mtds/logo/logo-observer.js.map +1 -1
  117. package/mtds/logo/logo.js +8 -8
  118. package/mtds/logo/logo.js.map +1 -1
  119. package/mtds/package.json.js +2 -2
  120. package/mtds/pagination/pagination-helper.js +11 -17
  121. package/mtds/pagination/pagination-helper.js.map +1 -1
  122. package/mtds/pagination/pagination.js +30 -30
  123. package/mtds/pagination/pagination.js.map +1 -1
  124. package/mtds/popover/popover-observer.js +33 -45
  125. package/mtds/popover/popover-observer.js.map +1 -1
  126. package/mtds/popover/popover.js +12 -13
  127. package/mtds/popover/popover.js.map +1 -1
  128. package/mtds/print/print.css.js +155 -0
  129. package/mtds/print/print.css.js.map +1 -0
  130. package/mtds/print/print.stories.d.ts +15 -0
  131. package/mtds/progress/progress.js +8 -8
  132. package/mtds/progress/progress.js.map +1 -1
  133. package/mtds/react-atlas.js +13 -12
  134. package/mtds/react.js +80 -80
  135. package/mtds/skeleton/skeleton.js +8 -8
  136. package/mtds/skeleton/skeleton.js.map +1 -1
  137. package/mtds/spinner/spinner.js +8 -8
  138. package/mtds/spinner/spinner.js.map +1 -1
  139. package/mtds/steps/steps.js +7 -7
  140. package/mtds/steps/steps.js.map +1 -1
  141. package/mtds/styles.css +1 -4605
  142. package/mtds/styles.json +43 -43
  143. package/mtds/styles.module.css.js +112 -167
  144. package/mtds/styles.module.css.js.map +1 -1
  145. package/mtds/table/table-observer.js +19 -22
  146. package/mtds/table/table-observer.js.map +1 -1
  147. package/mtds/table/table.d.ts +7 -0
  148. package/mtds/table/table.js +43 -18
  149. package/mtds/table/table.js.map +1 -1
  150. package/mtds/tabs/tabs.js +21 -25
  151. package/mtds/tabs/tabs.js.map +1 -1
  152. package/mtds/tag/tag.js +8 -8
  153. package/mtds/tag/tag.js.map +1 -1
  154. package/mtds/tailwind.css +4 -24
  155. package/mtds/toast/toast-helper.js +20 -35
  156. package/mtds/toast/toast-helper.js.map +1 -1
  157. package/mtds/toast/toast-observer.js +15 -30
  158. package/mtds/toast/toast-observer.js.map +1 -1
  159. package/mtds/toast/toast.js +37 -45
  160. package/mtds/toast/toast.js.map +1 -1
  161. package/mtds/togglegroup/togglegroup-observer.js +10 -15
  162. package/mtds/togglegroup/togglegroup-observer.js.map +1 -1
  163. package/mtds/togglegroup/togglegroup.js +24 -21
  164. package/mtds/togglegroup/togglegroup.js.map +1 -1
  165. package/mtds/tooltip/tooltip-observer.js +32 -48
  166. package/mtds/tooltip/tooltip-observer.js.map +1 -1
  167. package/mtds/typography/typography.js +19 -28
  168. package/mtds/typography/typography.js.map +1 -1
  169. package/mtds/utils.js +89 -129
  170. package/mtds/utils.js.map +1 -1
  171. package/mtds/validation/validation-observer.js +25 -31
  172. package/mtds/validation/validation-observer.js.map +1 -1
  173. package/mtds/validation/validation.js +12 -12
  174. package/mtds/validation/validation.js.map +1 -1
  175. package/package.json +13 -12
@@ -1,119 +1,71 @@
1
- import { UHTMLComboboxElement } from "@u-elements/u-combobox";
2
- import { UHTMLDataListElement } from "@u-elements/u-datalist";
3
- import styles from "../styles.module.css.js";
4
- import { isBrowser, onLoaded, onMutation, on, QUICK_EVENT, isInputLike, attr, useId, anchorPosition } from "../utils.js";
5
- const CSS_FIELD = styles.field.split(" ")[0];
6
- const CSS_VALIDATIONS = styles.validation.split(" ");
7
- const CSS_VALIDATION = CSS_VALIDATIONS[0];
8
- const FIELDS = isBrowser() ? document.getElementsByClassName(CSS_FIELD) : [];
9
- function handleFieldMutation() {
10
- for (const field of FIELDS)
11
- if (field.isConnected) {
12
- const labels = [];
13
- const descriptions = [];
14
- let combobox = null;
15
- let input = null;
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 renderTextareaSize(textarea) {
39
- if (textarea instanceof HTMLTextAreaElement) {
40
- textarea.style.setProperty("--mtds-textarea-height", "auto");
41
- textarea.style.setProperty(
42
- "--mtds-textarea-height",
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 getText = (style, key) => style.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || "";
48
- function renderCombobox(el) {
49
- const { control, list } = el || {};
50
- if (el && list && !el.hasAttribute("data-sr-added")) {
51
- const style = window.getComputedStyle(el);
52
- attr(el, "data-sr-added", getText(style, "combobox-added"));
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 renderCounter(input) {
68
- const el = input?.nextElementSibling;
69
- const limit = el && attr(el, "data-count");
70
- if (el && limit) {
71
- const remainder = Number(limit) - input.value.length;
72
- const nextInvalid = remainder < 0;
73
- const prevInvalid = attr(el, "aria-live") === "polite";
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
- attr(el, "aria-label", label);
42
+ n(a, "aria-label", L);
83
43
  }
84
44
  }
85
- function handleFieldToggle({ target: el, newState }) {
86
- if (el instanceof UHTMLDataListElement) {
87
- const root = el.getRootNode();
88
- const anchor = root?.querySelector(
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
- if (newState === "closed") anchorPosition(el, false);
92
- else if (anchor)
93
- anchorPosition(el, anchor, {
94
- contain({ availableHeight }) {
95
- el.style.width = `${anchor.clientWidth}px`;
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 handleFieldInput(event) {
102
- if (isInputLike(event.target)) {
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 handleFieldValdiation(event) {
108
- if (event.target?.closest?.(`.${CSS_FIELD}`))
109
- event.preventDefault();
60
+ function D(t) {
61
+ t.target?.closest?.(`.${g}`) && t.preventDefault();
110
62
  }
111
- onLoaded(() => [
112
- onMutation(() => handleFieldMutation(), "class"),
113
- on(document, "input", handleFieldInput, QUICK_EVENT),
114
- on(document, "toggle", handleFieldToggle, QUICK_EVENT),
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
- on(document, "invalid", handleFieldValdiation, true)
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,MAAM,YAAY,OAAO,MAAM,MAAM,GAAG,EAAE,CAAC;AAC3C,MAAM,kBAAkB,OAAO,WAAW,MAAM,GAAG;AACnD,MAAM,iBAAiB,gBAAgB,CAAC;AACxC,MAAM,SAAS,UAAA,IAAc,SAAS,uBAAuB,SAAS,IAAI,CAAA;AAE1E,SAAS,sBAAsB;AAC9B,aAAW,SAAS;AACnB,QAAI,MAAM,aAAa;AACtB,YAAM,SAA6B,CAAA;AACnC,YAAM,eAA0B,CAAA;AAEhC,UAAI,WAAwC;AAC5C,UAAI,QAAiC;AACrC,UAAI,QAAQ;AAEZ,iBAAW,MAAM,MAAM,qBAAqB,GAAG,GAAG;AACjD,YAAI,cAAc,iBAAkB,QAAO,KAAK,EAAE;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AAkC;AAC1E,MAAI,cAAc,sBAAsB;AACvC,UAAM,OAAO,GAAG,YAAA;AAChB,UAAM,SAAS,MAAM;AAAA,MACpB,mBAAmB,GAAG,EAAE;AAAA,IAAA;AAGzB,QAAI,aAAa,SAAU,gBAAe,IAAI,KAAK;AAAA,aAC1C;AACR,qBAAe,IAAI,QAAQ;AAAA,QAC1B,QAAQ,EAAE,mBAAmB;AAC5B,aAAG,MAAM,QAAQ,GAAG,OAAO,WAAW;AACtC,aAAG,MAAM,YAAY,GAAG,KAAK,IAAI,IAAI,eAAe,CAAC;AAAA,QACtD;AAAA,MAAA,CACA;AAAA,EACH;AACD;AAEA,SAAS,iBAAiB,OAAc;AACvC,MAAI,YAAY,MAAM,MAAM,GAAG;AAC9B,kBAAc,MAAM,MAAM;AAC1B,uBAAmB,MAAM,MAAM;AAAA,EAChC;AACD;AAEA,SAAS,sBAAsB,OAAc;AAC5C,MAAK,MAAM,QAAoB,UAAU,IAAI,SAAS,EAAE;AACvD,UAAM,eAAA;AACR;AAEA,SAAS,MAAM;AAAA,EACd,WAAW,MAAM,oBAAA,GAAuB,OAAO;AAAA,EAC/C,GAAG,UAAU,SAAS,kBAAkB,WAAW;AAAA,EACnD,GAAG,UAAU,UAAU,mBAAmB,WAAW;AAAA;AAAA,EACrD,GAAG,UAAU,WAAW,uBAAuB,IAAI;AAAA;AACpD,CAAC;"}
1
+ {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\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_EV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MAAMxC,EAAA,GAAuB,OAAO;AAAA,EAC/CyC,EAAG,UAAU,SAASL,GAAkBM,CAAW;AAAA,EACnDD,EAAG,UAAU,UAAUX,GAAmBY,CAAW;AAAA;AAAA,EACrDD,EAAG,UAAU,WAAWH,GAAuB,EAAI;AAAA;AACpD,CAAC;"}
@@ -1,211 +1,179 @@
1
1
  'use client';
2
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import clsx from "clsx";
4
- import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
5
- import { HelpText } from "../helptext/helptext.js";
6
- import { Input } from "../input/input.js";
7
- import styles from "../styles.module.css.js";
8
- import { toCustomElementProps } from "../utils.js";
9
- import { Validation } from "../validation/validation.js";
10
- const toOption = (o) => typeof o === "string" ? { label: o, value: o } : o;
11
- const FieldComp = forwardRef(function Field2({
12
- "data-size": size,
13
- "data-validation": dataValidation,
14
- as,
15
- className,
16
- count,
17
- description,
18
- error,
19
- helpText,
20
- helpTextLabel,
21
- label,
22
- prefix,
23
- style,
24
- suffix,
25
- validation: validationContent,
26
- ...rest
27
- }, ref) {
28
- const Tag = as || "div";
29
- const affixes = !!suffix || !!prefix;
30
- const validation = validationContent || error;
31
- const shared = {
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
- if (as === "select" && !rest.children)
38
- Object.assign(rest, {
39
- options: void 0,
40
- // Ensure options is not passed to DOM
41
- children: /* @__PURE__ */ jsx(Fragment, { children: rest.options?.map(toOption).map(({ label: label2, value }) => /* @__PURE__ */ jsx("option", { value, children: label2 }, value)) })
42
- });
43
- return as ? /* @__PURE__ */ jsxs("div", { ...shared, children: [
44
- !!label && /* @__PURE__ */ jsx(FieldLabel, { children: label }),
45
- !!helpText && /* @__PURE__ */ jsx(HelpText, { "aria-label": helpTextLabel, children: helpText }),
46
- !!description && /* @__PURE__ */ jsx(FieldDescription, { children: description }),
47
- affixes ? /* @__PURE__ */ jsxs(FieldAffixes, { children: [
48
- !!prefix && /* @__PURE__ */ jsx("span", { children: prefix }),
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: styles.input,
53
- suppressHydrationWarning: true,
54
- ref,
55
- ...rest
46
+ className: D.input,
47
+ suppressHydrationWarning: !0,
48
+ ref: l,
49
+ ...r
56
50
  }
57
51
  ),
58
- !!suffix && /* @__PURE__ */ jsx("span", { children: suffix })
59
- ] }) : /* @__PURE__ */ jsx(
60
- Tag,
52
+ !!F && /* @__PURE__ */ e("span", { children: F })
53
+ ] }) : /* @__PURE__ */ e(
54
+ C,
61
55
  {
62
- className: typeof as === "string" ? styles.input : void 0,
63
- suppressHydrationWarning: true,
64
- ref,
65
- ...rest
56
+ className: typeof o == "string" ? D.input : void 0,
57
+ suppressHydrationWarning: !0,
58
+ ref: l,
59
+ ...r
66
60
  }
67
61
  ),
68
- !!validation && /* @__PURE__ */ jsx(Validation, { children: validation }),
69
- !!count && /* @__PURE__ */ jsx(FieldCount, { "data-count": count })
70
- ] }) : /* @__PURE__ */ jsx("div", { ref, ...shared, ...rest });
71
- });
72
- const FieldAffixes = forwardRef(
73
- function FieldAffixes2({ className, ...rest }, ref) {
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
- const FieldDatalist = forwardRef(
78
- function FieldDatalist2({ "data-nofilter": filter, ...rest }, ref) {
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": !!filter || void 0,
83
- ref,
84
- ...toCustomElementProps(rest)
74
+ "data-nofilter": !!n || void 0,
75
+ ref: o,
76
+ ...q(t)
85
77
  }
86
78
  );
87
79
  }
88
- );
89
- const FieldOption = forwardRef(
90
- function FieldOption2(props, ref) {
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
- const FieldCombobox = forwardRef(
95
- function FieldCombobox2({
96
- "aria-required": required,
97
- "data-position": position,
98
- "data-nofilter": nofilter,
99
- "data-multiple": multiple,
100
- onAfterChange,
101
- onAfterSelect,
102
- onBeforeChange,
103
- onBeforeMatch,
104
- onBeforeSelect,
105
- onSelectedChange,
106
- onInput,
107
- onChange,
108
- children,
109
- disabled,
110
- name,
111
- options,
112
- placeholder,
113
- readOnly,
114
- selected,
115
- type,
116
- ...props
117
- }, ref) {
118
- const innerRef = useRef(null);
119
- const onSelected = useRef(onSelectedChange);
120
- onSelected.current = onSelectedChange;
121
- if (onAfterChange) {
122
- onAfterSelect = onAfterChange;
123
- console.warn(
124
- `Combobox onAfterChange is deprecated, use onAfterSelect instead.`
125
- );
126
- }
127
- if (onBeforeChange) {
128
- onBeforeSelect = onBeforeChange;
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
- self?.addEventListener("comboboxbeforeselect", handleChange);
148
- return () => self?.removeEventListener("comboboxbeforeselect", handleChange);
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": multiple || void 0,
154
- ...toCustomElementProps({
155
- oncomboboxbeforeselect: onBeforeSelect,
156
- oncomboboxbeforematch: onBeforeMatch,
157
- oncomboboxafterselect: onAfterSelect,
158
- ref: innerRef,
159
- ...props
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
- selected?.map(({ children: children2, label, value }) => /* @__PURE__ */ jsx("data", { value, suppressHydrationWarning: true, children: children2 ?? label }, value)),
163
- children || /* @__PURE__ */ jsxs(Fragment, { children: [
164
- /* @__PURE__ */ jsx(
165
- Input,
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": 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__ */ jsx("del", { "aria-label": "Fjern tekst", suppressHydrationWarning: true })
149
+ /* @__PURE__ */ e("del", { "aria-label": "Fjern tekst", suppressHydrationWarning: !0 })
178
150
  ] }),
179
- !!options && /* @__PURE__ */ jsx(FieldDatalist, { "data-nofilter": nofilter, "data-position": position, children: options.map(toOption).map(({ children: children2, label, value }) => /* @__PURE__ */ jsx(FieldOption, { value, label, children: children2 ?? label }, value)) })
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
- const FieldLabel = forwardRef(
186
- function FieldLabel2(rest, ref) {
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
- const FieldDescription = forwardRef(function FieldDescription2(rest, ref) {
191
- return /* @__PURE__ */ jsx("p", { suppressHydrationWarning: true, ref, ...rest });
192
- });
193
- const FieldCount = forwardRef(
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
- const Field = Object.assign(FieldComp, {
199
- Affixes: FieldAffixes,
200
- Combobox: FieldCombobox,
201
- Datalist: FieldDatalist,
202
- Option: FieldOption,
203
- Description: FieldDescription,
204
- Label: FieldLabel,
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