@aarhus-university/au-lib-react-components 12.6.1 → 12.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.eslintrc.js +35 -35
  2. package/.storybook/main.js +34 -34
  3. package/.storybook/preview.js +17 -17
  4. package/README.md +19 -19
  5. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  6. package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -386
  7. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  8. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  9. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  10. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  11. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  12. package/__tests__/jest/context.test.ts +25 -25
  13. package/__tests__/jest/helpers.test.ts +15 -15
  14. package/__tests__/jest/setupTests.ts +2 -2
  15. package/babel.config.js +8 -8
  16. package/build/umd/all.css +2 -2
  17. package/build/umd/all.js +1 -1
  18. package/build/umd/alphabox.js +1 -1
  19. package/build/umd/databox.js +1 -1
  20. package/build/umd/diagramme.js +1 -1
  21. package/build/umd/flowbox.js +1 -1
  22. package/build/umd/flowbox.js.map +1 -1
  23. package/build/umd/universe.js +1 -1
  24. package/build-storybook.log +386 -386
  25. package/esbuild.mjs +22 -22
  26. package/package.json +107 -107
  27. package/src/components/AUAlertComponent.tsx +128 -128
  28. package/src/components/AUAutoSuggestComponent.js +148 -148
  29. package/src/components/AUButtonComponent.tsx +99 -99
  30. package/src/components/AUCalendarComponent.tsx +497 -497
  31. package/src/components/AUCharacterCountComponent.tsx +56 -56
  32. package/src/components/AUComboBoxComponent.tsx +195 -195
  33. package/src/components/AUContentToggleComponent.tsx +50 -50
  34. package/src/components/AUDatepickerComponent.tsx +124 -124
  35. package/src/components/AUDialogModalComponent.tsx +124 -124
  36. package/src/components/AUDynamicContentComponent.tsx +137 -137
  37. package/src/components/AUEditorComponent.tsx +126 -126
  38. package/src/components/AUErrorComponent.tsx +73 -73
  39. package/src/components/AUMobilePrefixComponent.tsx +20 -20
  40. package/src/components/AUModalComponent.tsx +72 -72
  41. package/src/components/AUNotificationComponent.tsx +44 -44
  42. package/src/components/AUReceiptComponent.tsx +34 -34
  43. package/src/components/AUSpinnerComponent.tsx +40 -40
  44. package/src/components/AUStepComponent.tsx +75 -75
  45. package/src/components/AUSubNavComponent.tsx +57 -57
  46. package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
  47. package/src/components/AUTabbedContentComponent.tsx +154 -154
  48. package/src/components/AUTableComponent.tsx +29 -29
  49. package/src/components/AUToastComponent.tsx +104 -104
  50. package/src/components/AUToolbarComponent.tsx +108 -108
  51. package/src/components/AUTruncatorComponent.tsx +141 -141
  52. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  53. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -142
  54. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  55. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  56. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  57. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  58. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  59. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  60. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  61. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  62. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  63. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  64. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  65. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  66. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  67. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  68. package/src/layout-2016/lib/all.js +3 -3
  69. package/src/layout-2016/lib/au-alphabox.js +99 -99
  70. package/src/layout-2016/lib/au-databox.js +399 -399
  71. package/src/layout-2016/lib/au-diagramme.js +85 -85
  72. package/src/layout-2016/lib/au-flowbox.js +116 -119
  73. package/src/lib/context.tsx +59 -59
  74. package/src/lib/dates.ts +52 -52
  75. package/src/lib/helpers.ts +208 -208
  76. package/src/lib/hooks.ts +157 -157
  77. package/src/lib/i18n.ts +600 -600
  78. package/src/lib/portals.tsx +150 -150
  79. package/src/lib/tinymce.ts +84 -84
  80. package/src/lib/wrapping.ts +21 -21
  81. package/src/styles/_settings.scss +10 -10
  82. package/src/styles/alphabox.scss +222 -222
  83. package/src/styles/app.scss +7 -7
  84. package/src/styles/autosuggest.scss +57 -57
  85. package/src/styles/databox.scss +563 -563
  86. package/src/styles/diagramme.scss +119 -119
  87. package/src/styles/flowbox.scss +72 -72
  88. package/src/styles/maps.scss +395 -395
  89. package/stories/AUAlertComponent.stories.tsx +133 -133
  90. package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
  91. package/stories/AUButtonComponent.stories.tsx +139 -139
  92. package/stories/AUCharacterCountComponent.stories.tsx +121 -121
  93. package/stories/AUComboBoxComponent.stories.tsx +101 -101
  94. package/stories/AUContentToggleComponent.stories.tsx +87 -87
  95. package/stories/AUDialogModalComponent.stories.tsx +75 -75
  96. package/stories/AUDynamicContentComponent.stories.tsx +119 -119
  97. package/stories/AUEditorComponent.stories.tsx +66 -66
  98. package/stories/AUErrorComponent.stories.tsx +132 -132
  99. package/stories/AUModalComponent.stories.tsx +160 -160
  100. package/stories/AUNotificationComponent.stories.tsx +151 -151
  101. package/stories/AUSpinnerComponent.stories.tsx +44 -44
  102. package/stories/AUStepComponent.stories.tsx +91 -91
  103. package/stories/AUToolbarComponent.stories.tsx +389 -389
  104. package/stories/AUTruncatorComponent.stories.tsx +123 -123
  105. package/stories/lib/helpers.tsx +146 -146
  106. package/tsconfig.json +46 -46
  107. package/webpack.config.js +88 -88
  108. package/.claude/settings.local.json +0 -12
  109. package/.vscode/settings.json +0 -22
@@ -1,399 +1,399 @@
1
- /* eslint func-names: ["error", "never"] */
2
- /* eslint no-prototype-builtins: 0 */
3
- /* eslint no-restricted-syntax: 0 */
4
- /* eslint max-classes-per-file: 0 */
5
- /* eslint no-unused-vars: 0 */
6
- /* eslint-env browser */
7
- import React from 'react';
8
- import ReactDOM from 'react-dom';
9
- import DataBoxComponent from '../components/databox/DataBoxComponent';
10
-
11
- const defaultOptions = {
12
- config: {
13
- container: '.au_databox', // DOM-element
14
- firstline: true, // skal søgefeltet stå på en række for sig selv?
15
- alphabet: 2, // hvilken knap er alfabetet?
16
- initLetter: 'a', // Startbogstavet for alfabetet
17
- trigger: 0,
18
- buttons: [ // Teksten på knapperne - nyt!
19
- { text: 'Dummy knap 1', link: '' },
20
- { text: 'Dummy knap 2', link: '' },
21
- ],
22
- stacked: false,
23
- rememberState: false,
24
- expand: false,
25
- },
26
- background: {
27
- color: '#003d73',
28
- linkColor: '#003d73',
29
- src: '',
30
- height: 0,
31
- text: '',
32
- overlay: true,
33
- },
34
- search: {
35
- autocomplete: true,
36
- index: 1,
37
- minLength: 1,
38
- placeHolder: '',
39
- },
40
- data: {
41
- mode: 'json',
42
- source: '',
43
- callback: null,
44
- },
45
- };
46
-
47
- class AUDataboxParser {
48
- static json(source, callback) {
49
- if (source) {
50
- let sourceArr = [];
51
- if (!Array.isArray(source)) {
52
- sourceArr.push(source);
53
- } else {
54
- sourceArr = source;
55
- }
56
- const promises = [];
57
- sourceArr.forEach((s) => {
58
- promises.push(new Promise((resolve) => {
59
- fetch(s).then((promise) => promise.json()).then((data) => {
60
- resolve(data);
61
- });
62
- }));
63
- });
64
-
65
- Promise.all(promises).then((values) => {
66
- callback({
67
- items: values.map((x) => x.items)[0],
68
- groupings: values.map((x) => x.groupings)[0] || [],
69
- });
70
- });
71
- }
72
- }
73
-
74
- static xml(source, callback) {
75
- const xmlFunc = (data) => {
76
- const items = [];
77
- const children = [];
78
- const associations = [];
79
-
80
- let assocXML = [];
81
- let count = 1;
82
-
83
- do {
84
- assocXML = $(data).find(`associations${count} > item`);
85
-
86
- const assoc = [];
87
- for (let i = 0; i < assocXML.length; i += 1) {
88
- assoc.push({
89
- id: $(assocXML[i]).attr('id'),
90
- name: $(assocXML[i]).attr('name'),
91
- items: [],
92
- });
93
- }
94
-
95
- if (assoc.length > 0) {
96
- associations.push(assoc);
97
- }
98
-
99
- count += 1;
100
- } while (assocXML.length > 0);
101
-
102
- const itemsXML = $(data).find('items > item');
103
- $.each(itemsXML, function () {
104
- const extraXML = $(this).find('extra');
105
- const extra = [];
106
- $.each(extraXML.find('param'), () => {
107
- extra.push({
108
- param: $(this).text(),
109
- });
110
- });
111
- const obj = {
112
- id: $(this).attr('id'),
113
- name: $(this).attr('name'),
114
- url: $(this).attr('url'),
115
- parent: $(this).attr('parent'),
116
- extra,
117
- children: [],
118
- associations: [],
119
- };
120
-
121
- for (let i = 0; i < associations.length; i += 1) {
122
- const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
123
-
124
- obj.associations.push([]);
125
-
126
- for (let j = 0; j < objAssoc.length; j += 1) {
127
- const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
128
- obj.associations[i].push({
129
- id: associations[i][id].id,
130
- name: associations[i][id].name,
131
- });
132
- associations[i][id].items.push(obj);
133
- }
134
- }
135
-
136
- items.push(obj);
137
- if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
138
- children.push(obj);
139
- }
140
- });
141
-
142
- for (let c = 0; c < children.length; c += 1) {
143
- const pid = children[c].parent;
144
- for (let p = 0; p < items.length; p += 1) {
145
- if (items[p].id === pid) {
146
- items[p].children.push(children[c]);
147
- break;
148
- }
149
- }
150
- }
151
-
152
- const groupings = [];
153
- for (let i = 0; i < associations.length; i += 1) {
154
- groupings.push({
155
- id: i,
156
- associations: associations[i],
157
- });
158
- }
159
-
160
- callback({
161
- rawData: data,
162
- items,
163
- groupings,
164
- });
165
- };
166
-
167
- AU.helpers.getXML(source, (data) => {
168
- xmlFunc(data);
169
- });
170
- }
171
-
172
- static table(source, callback) {
173
- const table = $(`${source} > table`);
174
- const list = $(`${source} > ul`);
175
-
176
- const items = [];
177
- const children = [];
178
- const associations = [];
179
-
180
- $('li', list).each(function () {
181
- const assoc = [];
182
- $('> ul > li', this).each(function (i) {
183
- assoc.push({
184
- id: i,
185
- name: $(this).text(),
186
- items: [],
187
- });
188
- });
189
-
190
- if (assoc.length > 0) {
191
- associations.push(assoc);
192
- }
193
- });
194
-
195
- $('tr', table).each(function (i) {
196
- if (i > 0) {
197
- const cells = $('td', this);
198
-
199
- const id = parseInt(cells.eq(0).text(), 10);
200
- const parent = parseInt(cells.eq(1).text(), 10);
201
- let name = cells.eq(2).text();
202
- name = name.trim();
203
- const url = $('a', cells.eq(2)).attr('href');
204
- const skip = 3; // Antallet af celler, som ikke angiver associations!
205
-
206
- const obj = {
207
- id,
208
- name,
209
- url,
210
- parent,
211
- extra: [],
212
- children: [],
213
- associations: [],
214
- };
215
-
216
- for (let j = 0; j < associations.length; j += 1) {
217
- const assocCell = cells.eq(j + skip).text();
218
- const assocCellSplit = assocCell.split(',');
219
-
220
- obj.associations.push([]);
221
-
222
- for (let k = 0; k < assocCellSplit.length; k += 1) {
223
- const aid = parseInt(assocCellSplit[k], 10) - 1;
224
-
225
- if (typeof associations[j][aid] !== 'undefined') {
226
- obj.associations[j].push({
227
- id: associations[j][aid].id,
228
- name: associations[j][aid].name,
229
- });
230
-
231
- associations[j][aid].items.push(obj);
232
- }
233
- }
234
- }
235
-
236
- if (obj.parent === 0 || obj.parent === '') {
237
- items.push(obj);
238
- } else {
239
- children.push(obj);
240
- }
241
- }
242
- });
243
-
244
- for (let c = 0; c < children.length; c += 1) {
245
- const pid = children[c].parent;
246
- for (let p = 0; p < items.length; p += 1) {
247
- if (items[p].id === pid) {
248
- items[p].children.push(children[c]);
249
- break;
250
- }
251
- }
252
- }
253
-
254
- const groupings = [];
255
- for (let i = 0; i < associations.length; i += 1) {
256
- groupings.push({
257
- id: i,
258
- associations: associations[i],
259
- });
260
- }
261
-
262
- callback({
263
- items,
264
- groupings,
265
- });
266
- }
267
-
268
- static list(source, callback) {
269
- const list = $(source);
270
- const items = [];
271
- $('li', list).each(function (i) {
272
- items.push({
273
- id: i,
274
- label: $(this).text(),
275
- value: $(this).text(),
276
- name: $(this).text(),
277
- url: $('a', this).attr('href'),
278
- children: [],
279
- associations: [],
280
- });
281
- });
282
-
283
- callback({
284
- items,
285
- groupings: [],
286
- });
287
- }
288
- }
289
- class AUDatabox {
290
- constructor(boxes) {
291
- this.boxes = boxes;
292
- }
293
-
294
- static mergeOptions(_box) {
295
- const box = _box;
296
- if (!box.hasOwnProperty('config')) {
297
- box.config = {};
298
- }
299
-
300
- for (const conf in defaultOptions.config) {
301
- if (!box.config.hasOwnProperty(conf)) {
302
- box.config[conf] = defaultOptions.config[conf];
303
- }
304
- }
305
-
306
- if (!box.hasOwnProperty('background')) {
307
- box.background = {};
308
- }
309
-
310
- for (const bg in defaultOptions.background) {
311
- if (!box.background.hasOwnProperty(bg)) {
312
- box.background[bg] = defaultOptions.background[bg];
313
- }
314
- }
315
-
316
- if (!box.hasOwnProperty('search')) {
317
- box.search = {};
318
- }
319
-
320
- for (const sch in defaultOptions.search) {
321
- if (!box.search.hasOwnProperty(sch)) {
322
- box.search[sch] = defaultOptions.search[sch];
323
- }
324
- }
325
-
326
- if (!box.hasOwnProperty('data')) {
327
- box.data = {};
328
- }
329
-
330
- for (const data in defaultOptions.data) {
331
- if (!box.data.hasOwnProperty(data)) {
332
- box.data[data] = defaultOptions.data[data];
333
- }
334
- }
335
-
336
- return box;
337
- }
338
-
339
- static legacyCleanUp(_box) {
340
- const box = _box;
341
- const container = $(box.config.container);
342
- if (container !== null) {
343
- const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
344
- if (containerChildren.length > 0) {
345
- box.config.buttons = [];
346
- containerChildren.each(function () {
347
- box.config.buttons.push({
348
- text: $(this).text(),
349
- link: '',
350
- });
351
- });
352
- }
353
- }
354
- }
355
-
356
- init() {
357
- const parser = {
358
- json: AUDataboxParser.json,
359
- xml: AUDataboxParser.xml,
360
- table: AUDataboxParser.table,
361
- list: AUDataboxParser.list,
362
- };
363
-
364
- for (let i = 0; i < this.boxes.length; i += 1) {
365
- let box = this.boxes[i];
366
- if (!box.loaded) {
367
- box = AUDatabox.mergeOptions(box);
368
- box.id = i;
369
- AUDatabox.legacyCleanUp(box);
370
- // I stedet for at skulle rette alle gamle søgebokse,
371
- // hvor knappernes tekst er sat direkte i HTML'en,
372
- // finder vi knapperne her og indsætter dem som 'buttons' i config'en
373
- const mountNode = document.querySelector(box.config.container);
374
- const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
375
- if (!box.config.stacked
376
- && AU.responsive.state
377
- && AU.responsive.state.NAME === 'PHONE') {
378
- box.config.stacked = true;
379
- }
380
- if (visible) {
381
- ReactDOM.render(<DataBoxComponent
382
- box={box}
383
- parse={parser[box.data.mode]}
384
- />, mountNode);
385
- box.loaded = true;
386
- }
387
-
388
- if (box.data.mode === 'table' || box.data.mode === 'list') {
389
- const dataElement = document.querySelector(box.data.source);
390
- if (dataElement) {
391
- dataElement.parentNode.removeChild(dataElement);
392
- }
393
- }
394
- }
395
- }
396
- }
397
- }
398
-
399
- window.AUDatabox = AUDatabox;
1
+ /* eslint func-names: ["error", "never"] */
2
+ /* eslint no-prototype-builtins: 0 */
3
+ /* eslint no-restricted-syntax: 0 */
4
+ /* eslint max-classes-per-file: 0 */
5
+ /* eslint no-unused-vars: 0 */
6
+ /* eslint-env browser */
7
+ import React from 'react';
8
+ import ReactDOM from 'react-dom';
9
+ import DataBoxComponent from '../components/databox/DataBoxComponent';
10
+
11
+ const defaultOptions = {
12
+ config: {
13
+ container: '.au_databox', // DOM-element
14
+ firstline: true, // skal søgefeltet stå på en række for sig selv?
15
+ alphabet: 2, // hvilken knap er alfabetet?
16
+ initLetter: 'a', // Startbogstavet for alfabetet
17
+ trigger: 0,
18
+ buttons: [ // Teksten på knapperne - nyt!
19
+ { text: 'Dummy knap 1', link: '' },
20
+ { text: 'Dummy knap 2', link: '' },
21
+ ],
22
+ stacked: false,
23
+ rememberState: false,
24
+ expand: false,
25
+ },
26
+ background: {
27
+ color: '#003d73',
28
+ linkColor: '#003d73',
29
+ src: '',
30
+ height: 0,
31
+ text: '',
32
+ overlay: true,
33
+ },
34
+ search: {
35
+ autocomplete: true,
36
+ index: 1,
37
+ minLength: 1,
38
+ placeHolder: '',
39
+ },
40
+ data: {
41
+ mode: 'json',
42
+ source: '',
43
+ callback: null,
44
+ },
45
+ };
46
+
47
+ class AUDataboxParser {
48
+ static json(source, callback) {
49
+ if (source) {
50
+ let sourceArr = [];
51
+ if (!Array.isArray(source)) {
52
+ sourceArr.push(source);
53
+ } else {
54
+ sourceArr = source;
55
+ }
56
+ const promises = [];
57
+ sourceArr.forEach((s) => {
58
+ promises.push(new Promise((resolve) => {
59
+ fetch(s).then((promise) => promise.json()).then((data) => {
60
+ resolve(data);
61
+ });
62
+ }));
63
+ });
64
+
65
+ Promise.all(promises).then((values) => {
66
+ callback({
67
+ items: values.map((x) => x.items)[0],
68
+ groupings: values.map((x) => x.groupings)[0] || [],
69
+ });
70
+ });
71
+ }
72
+ }
73
+
74
+ static xml(source, callback) {
75
+ const xmlFunc = (data) => {
76
+ const items = [];
77
+ const children = [];
78
+ const associations = [];
79
+
80
+ let assocXML = [];
81
+ let count = 1;
82
+
83
+ do {
84
+ assocXML = $(data).find(`associations${count} > item`);
85
+
86
+ const assoc = [];
87
+ for (let i = 0; i < assocXML.length; i += 1) {
88
+ assoc.push({
89
+ id: $(assocXML[i]).attr('id'),
90
+ name: $(assocXML[i]).attr('name'),
91
+ items: [],
92
+ });
93
+ }
94
+
95
+ if (assoc.length > 0) {
96
+ associations.push(assoc);
97
+ }
98
+
99
+ count += 1;
100
+ } while (assocXML.length > 0);
101
+
102
+ const itemsXML = $(data).find('items > item');
103
+ $.each(itemsXML, function () {
104
+ const extraXML = $(this).find('extra');
105
+ const extra = [];
106
+ $.each(extraXML.find('param'), () => {
107
+ extra.push({
108
+ param: $(this).text(),
109
+ });
110
+ });
111
+ const obj = {
112
+ id: $(this).attr('id'),
113
+ name: $(this).attr('name'),
114
+ url: $(this).attr('url'),
115
+ parent: $(this).attr('parent'),
116
+ extra,
117
+ children: [],
118
+ associations: [],
119
+ };
120
+
121
+ for (let i = 0; i < associations.length; i += 1) {
122
+ const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
123
+
124
+ obj.associations.push([]);
125
+
126
+ for (let j = 0; j < objAssoc.length; j += 1) {
127
+ const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
128
+ obj.associations[i].push({
129
+ id: associations[i][id].id,
130
+ name: associations[i][id].name,
131
+ });
132
+ associations[i][id].items.push(obj);
133
+ }
134
+ }
135
+
136
+ items.push(obj);
137
+ if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
138
+ children.push(obj);
139
+ }
140
+ });
141
+
142
+ for (let c = 0; c < children.length; c += 1) {
143
+ const pid = children[c].parent;
144
+ for (let p = 0; p < items.length; p += 1) {
145
+ if (items[p].id === pid) {
146
+ items[p].children.push(children[c]);
147
+ break;
148
+ }
149
+ }
150
+ }
151
+
152
+ const groupings = [];
153
+ for (let i = 0; i < associations.length; i += 1) {
154
+ groupings.push({
155
+ id: i,
156
+ associations: associations[i],
157
+ });
158
+ }
159
+
160
+ callback({
161
+ rawData: data,
162
+ items,
163
+ groupings,
164
+ });
165
+ };
166
+
167
+ AU.helpers.getXML(source, (data) => {
168
+ xmlFunc(data);
169
+ });
170
+ }
171
+
172
+ static table(source, callback) {
173
+ const table = $(`${source} > table`);
174
+ const list = $(`${source} > ul`);
175
+
176
+ const items = [];
177
+ const children = [];
178
+ const associations = [];
179
+
180
+ $('li', list).each(function () {
181
+ const assoc = [];
182
+ $('> ul > li', this).each(function (i) {
183
+ assoc.push({
184
+ id: i,
185
+ name: $(this).text(),
186
+ items: [],
187
+ });
188
+ });
189
+
190
+ if (assoc.length > 0) {
191
+ associations.push(assoc);
192
+ }
193
+ });
194
+
195
+ $('tr', table).each(function (i) {
196
+ if (i > 0) {
197
+ const cells = $('td', this);
198
+
199
+ const id = parseInt(cells.eq(0).text(), 10);
200
+ const parent = parseInt(cells.eq(1).text(), 10);
201
+ let name = cells.eq(2).text();
202
+ name = name.trim();
203
+ const url = $('a', cells.eq(2)).attr('href');
204
+ const skip = 3; // Antallet af celler, som ikke angiver associations!
205
+
206
+ const obj = {
207
+ id,
208
+ name,
209
+ url,
210
+ parent,
211
+ extra: [],
212
+ children: [],
213
+ associations: [],
214
+ };
215
+
216
+ for (let j = 0; j < associations.length; j += 1) {
217
+ const assocCell = cells.eq(j + skip).text();
218
+ const assocCellSplit = assocCell.split(',');
219
+
220
+ obj.associations.push([]);
221
+
222
+ for (let k = 0; k < assocCellSplit.length; k += 1) {
223
+ const aid = parseInt(assocCellSplit[k], 10) - 1;
224
+
225
+ if (typeof associations[j][aid] !== 'undefined') {
226
+ obj.associations[j].push({
227
+ id: associations[j][aid].id,
228
+ name: associations[j][aid].name,
229
+ });
230
+
231
+ associations[j][aid].items.push(obj);
232
+ }
233
+ }
234
+ }
235
+
236
+ if (obj.parent === 0 || obj.parent === '') {
237
+ items.push(obj);
238
+ } else {
239
+ children.push(obj);
240
+ }
241
+ }
242
+ });
243
+
244
+ for (let c = 0; c < children.length; c += 1) {
245
+ const pid = children[c].parent;
246
+ for (let p = 0; p < items.length; p += 1) {
247
+ if (items[p].id === pid) {
248
+ items[p].children.push(children[c]);
249
+ break;
250
+ }
251
+ }
252
+ }
253
+
254
+ const groupings = [];
255
+ for (let i = 0; i < associations.length; i += 1) {
256
+ groupings.push({
257
+ id: i,
258
+ associations: associations[i],
259
+ });
260
+ }
261
+
262
+ callback({
263
+ items,
264
+ groupings,
265
+ });
266
+ }
267
+
268
+ static list(source, callback) {
269
+ const list = $(source);
270
+ const items = [];
271
+ $('li', list).each(function (i) {
272
+ items.push({
273
+ id: i,
274
+ label: $(this).text(),
275
+ value: $(this).text(),
276
+ name: $(this).text(),
277
+ url: $('a', this).attr('href'),
278
+ children: [],
279
+ associations: [],
280
+ });
281
+ });
282
+
283
+ callback({
284
+ items,
285
+ groupings: [],
286
+ });
287
+ }
288
+ }
289
+ class AUDatabox {
290
+ constructor(boxes) {
291
+ this.boxes = boxes;
292
+ }
293
+
294
+ static mergeOptions(_box) {
295
+ const box = _box;
296
+ if (!box.hasOwnProperty('config')) {
297
+ box.config = {};
298
+ }
299
+
300
+ for (const conf in defaultOptions.config) {
301
+ if (!box.config.hasOwnProperty(conf)) {
302
+ box.config[conf] = defaultOptions.config[conf];
303
+ }
304
+ }
305
+
306
+ if (!box.hasOwnProperty('background')) {
307
+ box.background = {};
308
+ }
309
+
310
+ for (const bg in defaultOptions.background) {
311
+ if (!box.background.hasOwnProperty(bg)) {
312
+ box.background[bg] = defaultOptions.background[bg];
313
+ }
314
+ }
315
+
316
+ if (!box.hasOwnProperty('search')) {
317
+ box.search = {};
318
+ }
319
+
320
+ for (const sch in defaultOptions.search) {
321
+ if (!box.search.hasOwnProperty(sch)) {
322
+ box.search[sch] = defaultOptions.search[sch];
323
+ }
324
+ }
325
+
326
+ if (!box.hasOwnProperty('data')) {
327
+ box.data = {};
328
+ }
329
+
330
+ for (const data in defaultOptions.data) {
331
+ if (!box.data.hasOwnProperty(data)) {
332
+ box.data[data] = defaultOptions.data[data];
333
+ }
334
+ }
335
+
336
+ return box;
337
+ }
338
+
339
+ static legacyCleanUp(_box) {
340
+ const box = _box;
341
+ const container = $(box.config.container);
342
+ if (container !== null) {
343
+ const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
344
+ if (containerChildren.length > 0) {
345
+ box.config.buttons = [];
346
+ containerChildren.each(function () {
347
+ box.config.buttons.push({
348
+ text: $(this).text(),
349
+ link: '',
350
+ });
351
+ });
352
+ }
353
+ }
354
+ }
355
+
356
+ init() {
357
+ const parser = {
358
+ json: AUDataboxParser.json,
359
+ xml: AUDataboxParser.xml,
360
+ table: AUDataboxParser.table,
361
+ list: AUDataboxParser.list,
362
+ };
363
+
364
+ for (let i = 0; i < this.boxes.length; i += 1) {
365
+ let box = this.boxes[i];
366
+ if (!box.loaded) {
367
+ box = AUDatabox.mergeOptions(box);
368
+ box.id = i;
369
+ AUDatabox.legacyCleanUp(box);
370
+ // I stedet for at skulle rette alle gamle søgebokse,
371
+ // hvor knappernes tekst er sat direkte i HTML'en,
372
+ // finder vi knapperne her og indsætter dem som 'buttons' i config'en
373
+ const mountNode = document.querySelector(box.config.container);
374
+ const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
375
+ if (!box.config.stacked
376
+ && AU.responsive.state
377
+ && AU.responsive.state.NAME === 'PHONE') {
378
+ box.config.stacked = true;
379
+ }
380
+ if (visible) {
381
+ ReactDOM.render(<DataBoxComponent
382
+ box={box}
383
+ parse={parser[box.data.mode]}
384
+ />, mountNode);
385
+ box.loaded = true;
386
+ }
387
+
388
+ if (box.data.mode === 'table' || box.data.mode === 'list') {
389
+ const dataElement = document.querySelector(box.data.source);
390
+ if (dataElement) {
391
+ dataElement.parentNode.removeChild(dataElement);
392
+ }
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+
399
+ window.AUDatabox = AUDatabox;