@altinn/altinn-components 0.68.10 → 0.68.15

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.
@@ -1,147 +1,145 @@
1
1
  import { jsx as F } from "react/jsx-runtime";
2
- import { useRef as R, useMemo as h } from "react";
2
+ import { useRef as O, useMemo as v } from "react";
3
3
  import "../index-p1eeF8LQ.js";
4
4
  import "../tooltip-Caqi75cv.js";
5
5
  import "../ToolbarSearch-BWqWKrm-.js";
6
6
  import "../components/Typography/Link.js";
7
- import { Button as q } from "../components/Button/Button.js";
7
+ import { Button as Q } from "../components/Button/Button.js";
8
8
  import "react-dom";
9
- import { useIsDesktop as J } from "./useIsDesktop.js";
9
+ import { useIsDesktop as X } from "./useIsDesktop.js";
10
10
  import "../components/GlobalMenu/GlobalMenuBase.js";
11
11
  import "../components/Snackbar/useSnackbar.js";
12
- import { formatDisplayName as j } from "../functions/name/name.js";
13
- import { formatDate as K } from "../functions/date/date.js";
14
- import { formatOrgNo as w } from "../functions/orgno/orgno.js";
15
- import { a as Q, S as X } from "../HeartFill-CbQmSZr5.js";
16
- const H = (e) => e === "Organization" ? "company" : "person", pt = ({
12
+ import { formatDisplayName as R } from "../functions/name/name.js";
13
+ import { formatDate as Z } from "../functions/date/date.js";
14
+ import { formatOrgNo as H } from "../functions/orgno/orgno.js";
15
+ import { a as C, S as T } from "../HeartFill-CbQmSZr5.js";
16
+ const V = (e) => e === "Organization" ? "company" : "person", W = /* @__PURE__ */ new Map(), E = (e) => {
17
+ const o = e || "nb";
18
+ let i = W.get(o);
19
+ return i || (i = new Intl.Collator(o, { sensitivity: "base", ignorePunctuation: !0 }), W.set(o, i)), i;
20
+ }, _t = ({
17
21
  partyListDTO: e = [],
18
22
  favoriteAccountUuids: o,
19
- currentAccountUuid: f,
20
- selfAccountUuid: d,
21
- isLoading: m = !1,
23
+ currentAccountUuid: i,
24
+ selfAccountUuid: l,
25
+ isLoading: d = !1,
22
26
  onSelectAccount: N,
23
- virtualized: p = !1,
24
- onToggleFavorite: I,
25
- languageCode: s,
26
- showDeletedUnits: c,
27
+ virtualized: m = !1,
28
+ onToggleFavorite: h,
29
+ languageCode: n,
30
+ showDeletedUnits: a,
27
31
  onShowDeletedUnitsChange: g
28
32
  }) => {
29
- const v = J(), u = R(I);
30
- u.current = I;
31
- const _ = R(f);
32
- _.current = f;
33
- const y = h(() => {
33
+ const p = X(), u = O(h);
34
+ u.current = h;
35
+ const _ = O(i);
36
+ _.current = i;
37
+ const I = v(() => {
34
38
  if (!e || e.length === 0) return [];
35
- const i = s || "nb", r = (n, l) => n.name.localeCompare(l.name, i, {
36
- sensitivity: "base",
37
- ignorePunctuation: !0
38
- });
39
- return [...e].sort(r);
40
- }, [e, s]), $ = h(
41
- () => e.some((i) => i.isDeleted || i.subunits?.some((r) => r.isDeleted)),
39
+ const r = E(n);
40
+ return [...e].sort((s, c) => r.compare(s.name, c.name));
41
+ }, [e, n]), D = v(
42
+ () => e.some((r) => r.isDeleted || r.subunits?.some((s) => s.isDeleted)),
42
43
  [e]
43
- ), V = h(
44
- () => e.reduce((i, r) => i + 1 + (r.subunits?.length ?? 0), 0),
44
+ ), K = v(
45
+ () => e.reduce((r, s) => r + 1 + (s.subunits?.length ?? 0), 0),
45
46
  [e]
46
- ), [D, W] = h(() => {
47
- if (m || !y.length || !d)
47
+ ), P = o?.join(",") ?? "", B = v(() => new Set(P ? P.split(",") : []), [P]), [w, Y] = v(() => {
48
+ if (d || !I.length || !l)
48
49
  return [
49
50
  { selfAccountItem: void 0, peopleAccountItems: [], organizationAccountItems: [], favoriteAccountItems: [] },
50
51
  {}
51
52
  ];
52
- const i = new Set(o), r = (t) => i.has(t), n = (t) => !t.isDeleted || c !== !1 || t.partyUuid === _.current, l = M(s), A = s || "nb", G = (t, a) => t.name.localeCompare(a.name, A, {
53
- sensitivity: "base",
54
- ignorePunctuation: !0
55
- });
56
- let x;
57
- const k = [], U = [], S = [];
58
- for (const t of y)
59
- if (T(t.type)) {
60
- if (t.partyUuid === d)
61
- x = z(
62
- s,
53
+ const r = (t) => B.has(t), s = (t) => !t.isDeleted || a !== !1 || t.partyUuid === _.current, c = G(n), y = E(n), A = (t, f) => y.compare(t.name, f.name);
54
+ let j;
55
+ const $ = [], U = [], S = [];
56
+ for (const t of I)
57
+ if (et(t.type)) {
58
+ if (t.partyUuid === l)
59
+ j = z(
60
+ n,
63
61
  t,
64
62
  "favorites",
65
63
  !1,
66
64
  u,
67
- v,
65
+ p,
68
66
  void 0,
69
67
  !0
70
68
  );
71
- else if (n(t) || r(t.partyUuid)) {
72
- const a = z(
73
- s,
69
+ else if (s(t) || r(t.partyUuid)) {
70
+ const f = z(
71
+ n,
74
72
  t,
75
73
  t.partyUuid,
76
74
  r(t.partyUuid),
77
75
  u,
78
- v
76
+ p
79
77
  );
80
- k.push(a), r(t.partyUuid) && S.push({ ...a, groupId: "favorites" });
78
+ $.push(f), r(t.partyUuid) && S.push({ ...f, groupId: "favorites" });
81
79
  }
82
- } else if (C(t.type)) {
83
- if (n(t) || r(t.partyUuid)) {
84
- const a = z(
85
- s,
80
+ } else if (tt(t.type)) {
81
+ if (s(t) || r(t.partyUuid)) {
82
+ const f = z(
83
+ n,
86
84
  t,
87
85
  t.partyUuid,
88
86
  r(t.partyUuid),
89
87
  u,
90
- v
88
+ p
91
89
  );
92
- n(t) && U.push(a), r(t.partyUuid) && S.push({ ...a, groupId: "favorites" });
90
+ s(t) && U.push(f), r(t.partyUuid) && S.push({ ...f, groupId: "favorites" });
93
91
  }
94
92
  if (t.subunits && t.subunits.length > 0) {
95
- const a = [...t.subunits].sort(G);
96
- for (const b of a)
97
- if (n(b) || r(b.partyUuid)) {
98
- const O = z(
99
- s,
93
+ const f = [...t.subunits].sort(A);
94
+ for (const b of f)
95
+ if (s(b) || r(b.partyUuid)) {
96
+ const M = z(
97
+ n,
100
98
  b,
101
99
  t.partyUuid,
102
100
  r(b.partyUuid),
103
101
  u,
104
- v,
102
+ p,
105
103
  t
106
104
  );
107
- n(b) && U.push(O), r(b.partyUuid) && S.push({
108
- ...O,
105
+ s(b) && U.push(M), r(b.partyUuid) && S.push({
106
+ ...M,
109
107
  groupId: "favorites"
110
108
  });
111
109
  }
112
110
  }
113
111
  }
114
- const Y = {
112
+ const J = {
115
113
  [U[0]?.groupId || "company"]: {
116
- title: l.account_orgs,
114
+ title: c.account_orgs,
117
115
  divider: !0
118
116
  },
119
- [k[0]?.groupId || "person"]: {
120
- title: l.account_persons,
117
+ [$[0]?.groupId || "person"]: {
118
+ title: c.account_persons,
121
119
  divider: !0
122
120
  },
123
121
  favorites: {
124
- title: l.account_favorites,
122
+ title: c.account_favorites,
125
123
  divider: !0
126
124
  }
127
125
  };
128
- return [{ selfAccountItem: x, peopleAccountItems: k, organizationAccountItems: U, favoriteAccountItems: S }, Y];
129
- }, [y, d, o, m, s, v, c]), P = h(() => {
130
- const { selfAccountItem: i, peopleAccountItems: r, organizationAccountItems: n, favoriteAccountItems: l } = D;
131
- return i ? [i, ...l, ...r, ...n] : [];
132
- }, [D]), [E, B] = h(() => {
133
- if (P.length === 0)
126
+ return [{ selfAccountItem: j, peopleAccountItems: $, organizationAccountItems: U, favoriteAccountItems: S }, J];
127
+ }, [I, l, B, d, n, p, a]), k = v(() => {
128
+ const { selfAccountItem: r, peopleAccountItems: s, organizationAccountItems: c, favoriteAccountItems: y } = w;
129
+ return r ? [r, ...y, ...s, ...c] : [];
130
+ }, [w]), [q, x] = v(() => {
131
+ if (k.length === 0)
134
132
  return [[], void 0];
135
- let i;
136
- return [P.map((n) => {
137
- if (f === n.id) {
138
- const A = { ...n, selected: !0 };
139
- return i = A, A;
133
+ let r;
134
+ return [k.map((c) => {
135
+ if (i === c.id) {
136
+ const A = { ...c, selected: !0 };
137
+ return r = A, A;
140
138
  }
141
- return n.selected ? { ...n, selected: !1 } : n;
142
- }), i];
143
- }, [P, f]);
144
- return m || !e || !B ? {
139
+ return c.selected ? { ...c, selected: !1 } : c;
140
+ }), r];
141
+ }, [k, i]);
142
+ return d || !e || !x ? {
145
143
  accountMenu: {
146
144
  items: [],
147
145
  groups: {},
@@ -150,89 +148,89 @@ const H = (e) => e === "Organization" ? "company" : "person", pt = ({
150
148
  },
151
149
  currentAccount: void 0
152
150
  },
153
- loading: m
151
+ loading: d
154
152
  } : {
155
153
  accountMenu: {
156
- items: E,
157
- groups: W,
158
- virtualized: p,
154
+ items: q,
155
+ groups: Y,
156
+ virtualized: m,
159
157
  onSelectAccount: N,
160
- currentAccount: B
158
+ currentAccount: x
161
159
  },
162
160
  loading: !1,
163
- showDeletedUnits: $ ? c : void 0,
164
- onShowDeletedUnitsChange: $ ? g : void 0,
165
- accountCount: V
161
+ showDeletedUnits: D ? a : void 0,
162
+ onShowDeletedUnitsChange: D ? g : void 0,
163
+ accountCount: K
166
164
  };
167
- }, Z = ({
165
+ }, L = ({
168
166
  partyUuid: e,
169
167
  isFavorite: o,
170
- toggleFavoriteRef: f,
171
- texts: d
168
+ toggleFavoriteRef: i,
169
+ texts: l
172
170
  }) => /* @__PURE__ */ F(
173
- q,
171
+ Q,
174
172
  {
175
173
  rounded: !0,
176
174
  variant: "ghost",
177
- "aria-label": o ? d.remove_from_favorites : d.add_to_favorites,
178
- onClick: (m) => {
179
- m.stopPropagation(), f?.current?.(e);
175
+ "aria-label": o ? l.remove_from_favorites : l.add_to_favorites,
176
+ onClick: (d) => {
177
+ d.stopPropagation(), i?.current?.(e);
180
178
  },
181
179
  size: "xs",
182
- children: o ? /* @__PURE__ */ F(Q, {}) : /* @__PURE__ */ F(X, {})
180
+ children: o ? /* @__PURE__ */ F(C, {}) : /* @__PURE__ */ F(T, {})
183
181
  }
184
- ), z = (e, o, f, d, m, N, p, I) => {
185
- const s = H(o?.type ?? ""), c = M(e), g = j({
182
+ ), z = (e, o, i, l, d, N, m, h) => {
183
+ const n = V(o?.type ?? ""), a = G(e), g = R({
186
184
  fullName: o?.name,
187
- type: s
188
- }), v = p ? j({
189
- fullName: p?.name,
190
- type: H(p?.type ?? ""),
185
+ type: n
186
+ }), p = m ? R({
187
+ fullName: m?.name,
188
+ type: V(m?.type ?? ""),
191
189
  reverseNameOrder: !1
192
190
  }) : void 0;
193
191
  let u = "";
194
- const _ = s === "company" && p ? "subunit" : s;
192
+ const _ = n === "company" && m ? "subunit" : n;
195
193
  switch (_) {
196
194
  case "company":
197
- u = `${c.org_no}. ${w(o.organizationNumber)}`;
195
+ u = `${a.org_no}. ${H(o.organizationNumber)}`;
198
196
  break;
199
197
  case "person":
200
- u = o?.dateOfBirth ? `${c.birthdate}: ${K(o?.dateOfBirth)}` : "";
198
+ u = o?.dateOfBirth ? `${a.birthdate}: ${Z(o?.dateOfBirth)}` : "";
201
199
  break;
202
200
  case "subunit":
203
- u = `↳ ${c.org_no}. ${w(o?.organizationNumber)}, ${c.subunit_of} ${v}`;
201
+ u = `↳ ${a.org_no}. ${H(o?.organizationNumber)}, ${a.subunit_of} ${p}`;
204
202
  break;
205
203
  default:
206
204
  u = "";
207
205
  }
208
- const y = I ? void 0 : /* @__PURE__ */ F(
209
- Z,
206
+ const I = h ? void 0 : /* @__PURE__ */ F(
207
+ L,
210
208
  {
211
209
  partyUuid: o?.partyUuid,
212
- isFavorite: d,
213
- toggleFavoriteRef: m,
214
- texts: c
210
+ isFavorite: l,
211
+ toggleFavoriteRef: d,
212
+ texts: a
215
213
  }
216
214
  );
217
215
  return {
218
216
  id: o?.partyUuid,
219
217
  icon: {
220
218
  name: g,
221
- type: s,
222
- isParent: !p,
219
+ type: n,
220
+ isParent: !m,
223
221
  isDeleted: o?.isDeleted
224
222
  },
225
223
  name: g,
226
224
  description: u,
227
225
  searchWords: _ === "person" ? [g, o?.dateOfBirth ?? ""] : [g, o?.organizationNumber ?? ""],
228
- groupId: f,
226
+ groupId: i,
229
227
  type: _,
230
228
  selected: !1,
231
229
  disabled: !!o?.onlyHierarchyElementWithNoAccess,
232
- badge: I ? { label: c.you, color: "person" } : o.isDeleted && N ? { label: c.deleted, color: "neutral" } : void 0,
233
- controls: y
230
+ badge: h ? { label: a.you, color: "person" } : o.isDeleted && N ? { label: a.deleted, color: "neutral" } : void 0,
231
+ controls: I
234
232
  };
235
- }, C = (e) => e === "Organization", T = (e) => e === "Person" || e === "SelfIdentified", M = (e) => {
233
+ }, tt = (e) => e === "Organization", et = (e) => e === "Person" || e === "SelfIdentified", G = (e) => {
236
234
  switch (e) {
237
235
  case "nn":
238
236
  return {
@@ -276,5 +274,5 @@ const H = (e) => e === "Organization" ? "company" : "person", pt = ({
276
274
  }
277
275
  };
278
276
  export {
279
- pt as useAccountSelector
277
+ _t as useAccountSelector
280
278
  };
@@ -32,7 +32,11 @@ export interface AuthorizedParty {
32
32
  export interface useAccountSelectorProps {
33
33
  /** UUID of the user's own personal account */
34
34
  selfAccountUuid?: string;
35
- /** Array of authorized parties that the user can act on behalf of */
35
+ /**
36
+ * Array of authorized parties that the user can act on behalf of.
37
+ * Pass a referentially stable array: a fresh reference on every render
38
+ * forces the full list to be re-sorted and rebuilt.
39
+ */
36
40
  partyListDTO?: AuthorizedParty[];
37
41
  /** Array of parties (defined by their partyUUIDs) marked as favorites by the user */
38
42
  favoriteAccountUuids?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.68.10",
3
+ "version": "0.68.15",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",
@@ -45,7 +45,7 @@
45
45
  "@types/react": "^19.1.5",
46
46
  "@types/react-dom": "^19.2.3",
47
47
  "@vitejs/plugin-react-swc": "^3.11.0",
48
- "@vitest/browser": "4.0.16",
48
+ "@vitest/browser": "4.1.8",
49
49
  "@vitest/browser-playwright": "4.0.16",
50
50
  "@vitest/coverage-v8": "^4.1.3",
51
51
  "axe-core": "^4.10.3",
@@ -61,7 +61,7 @@
61
61
  "storybook-addon-theme-provider": "^0.2.10",
62
62
  "tsx": "^4.21.0",
63
63
  "typescript": "^5.8.3",
64
- "vite": "7.3.2",
64
+ "vite": "7.3.5",
65
65
  "vite-plugin-dts": "^4.5.4",
66
66
  "vite-plugin-lib-inject-css": "^2.2.2",
67
67
  "vite-plugin-static-copy": "^2.3.2",