@ministryofjustice/frontend 3.4.0 → 3.5.0

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 (33) hide show
  1. package/moj/all.jquery.min.js +7 -70
  2. package/moj/all.js +2856 -2865
  3. package/moj/components/add-another/add-another.js +135 -104
  4. package/moj/components/alert/alert.js +482 -247
  5. package/moj/components/alert/alert.spec.helper.js +30 -5
  6. package/moj/components/button-menu/button-menu.js +346 -319
  7. package/moj/components/date-picker/date-picker.js +925 -900
  8. package/moj/components/filter-toggle-button/filter-toggle-button.js +122 -91
  9. package/moj/components/form-validator/form-validator.js +399 -164
  10. package/moj/components/multi-file-upload/multi-file-upload.js +445 -210
  11. package/moj/components/multi-select/multi-select.js +106 -75
  12. package/moj/components/password-reveal/password-reveal.js +64 -33
  13. package/moj/components/rich-text-editor/rich-text-editor.js +186 -153
  14. package/moj/components/search-toggle/search-toggle.js +77 -46
  15. package/moj/components/sortable-table/sortable-table.js +167 -146
  16. package/moj/helpers/_links.scss +1 -1
  17. package/moj/helpers.js +218 -180
  18. package/moj/moj-frontend.min.js +7 -70
  19. package/moj/version.js +28 -1
  20. package/package.json +1 -1
  21. package/moj/all.spec.js +0 -24
  22. package/moj/components/add-another/add-another.spec.js +0 -165
  23. package/moj/components/alert/alert.spec.js +0 -229
  24. package/moj/components/button-menu/button-menu.spec.js +0 -360
  25. package/moj/components/date-picker/date-picker.spec.js +0 -1178
  26. package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -302
  27. package/moj/components/multi-file-upload/multi-file-upload.spec.js +0 -510
  28. package/moj/components/multi-select/multi-select.spec.js +0 -128
  29. package/moj/components/password-reveal/password-reveal.spec.js +0 -57
  30. package/moj/components/search-toggle/search-toggle.spec.js +0 -129
  31. package/moj/components/sortable-table/sortable-table.spec.js +0 -362
  32. package/moj/helpers.spec.js +0 -235
  33. package/moj/namespace.js +0 -2
@@ -1,247 +1,482 @@
1
- /**
2
- * @typedef {object} AlertConfig
3
- * @property {boolean} [dismissible=false] - Can the alert be dismissed by the user
4
- * @property {string} [dismissText=Dismiss] - the label text for the dismiss button
5
- * @property {boolean} [disableAutoFocus=false] - whether the alert will be autofocused
6
- * @property {string} [focusOnDismissSelector] - CSS Selector for element to be focused on dismiss
7
- */
8
-
9
- /**
10
- * @param {HTMLElement} $module - the Alert element
11
- * @param {AlertConfig} config - configuration options
12
- * @class
13
- */
14
- MOJFrontend.Alert = function ($module, config = {}) {
15
- if (!$module) {
16
- return this
17
- }
18
-
19
- const schema = Object.freeze({
20
- properties: {
21
- dismissible: { type: 'boolean' },
22
- dismissText: { type: 'string' },
23
- disableAutoFocus: { type: 'boolean' },
24
- focusOnDismissSelector: { type: 'string' }
25
- }
26
- })
27
-
28
- const defaults = {
29
- dismissible: false,
30
- dismissText: 'Dismiss',
31
- disableAutoFocus: false
32
- }
33
-
34
- // data attributes override JS config, which overrides defaults
35
- this.config = this.mergeConfigs(
36
- defaults,
37
- config,
38
- this.parseDataset(schema, $module.dataset)
39
- )
40
-
41
- this.$module = $module
42
- }
43
-
44
- MOJFrontend.Alert.prototype.init = function () {
45
- /**
46
- * Focus the alert
47
- *
48
- * If `role="alert"` is set, focus the element to help some assistive
49
- * technologies prioritise announcing it.
50
- *
51
- * You can turn off the auto-focus functionality by setting
52
- * `data-disable-auto-focus="true"` in the component HTML. You might wish to
53
- * do this based on user research findings, or to avoid a clash with another
54
- * element which should be focused when the page loads.
55
- */
56
- if (
57
- this.$module.getAttribute('role') === 'alert' &&
58
- !this.config.disableAutoFocus
59
- ) {
60
- MOJFrontend.setFocus(this.$module)
61
- }
62
-
63
- this.$dismissButton = this.$module.querySelector('.moj-alert__dismiss')
64
-
65
- if (this.config.dismissible && this.$dismissButton) {
66
- this.$dismissButton.innerHTML = this.config.dismissText
67
- this.$dismissButton.removeAttribute('hidden')
68
-
69
- this.$module.addEventListener('click', (event) => {
70
- if (this.$dismissButton.contains(event.target)) {
71
- this.dimiss()
72
- }
73
- })
74
- }
75
- }
76
-
77
- /**
78
- * Handle dismissing the alert
79
- */
80
- MOJFrontend.Alert.prototype.dimiss = function () {
81
- let $elementToRecieveFocus
82
-
83
- // If a selector has been provided, attempt to find that element
84
- if (this.config.focusOnDismissSelector) {
85
- $elementToRecieveFocus = document.querySelector(
86
- this.config.focusOnDismissSelector
87
- )
88
- }
89
-
90
- // Is the next sibling another alert
91
- if (!$elementToRecieveFocus) {
92
- const $nextSibling = this.$module.nextElementSibling
93
- if ($nextSibling && $nextSibling.matches('.moj-alert')) {
94
- $elementToRecieveFocus = $nextSibling
95
- }
96
- }
97
-
98
- // Else try to find any preceding sibling alert or heading
99
- if (!$elementToRecieveFocus) {
100
- $elementToRecieveFocus = MOJFrontend.getPreviousSibling(
101
- this.$module,
102
- '.moj-alert, h1, h2, h3, h4, h5, h6'
103
- )
104
- }
105
-
106
- // Else find the closest ancestor heading, or fallback to main, or last resort
107
- // use the body element
108
- if (!$elementToRecieveFocus) {
109
- $elementToRecieveFocus = MOJFrontend.findNearestMatchingElement(
110
- this.$module,
111
- 'h1, h2, h3, h4, h5, h6, main, body'
112
- )
113
- }
114
-
115
- // If we have an element, place focus on it
116
- if ($elementToRecieveFocus) {
117
- MOJFrontend.setFocus($elementToRecieveFocus)
118
- }
119
-
120
- // Remove the alert
121
- this.$module.remove()
122
- }
123
-
124
- /**
125
- * Normalise string
126
- *
127
- * 'If it looks like a duck, and it quacks like a duck…' 🦆
128
- *
129
- * If the passed value looks like a boolean or a number, convert it to a boolean
130
- * or number.
131
- *
132
- * Designed to be used to convert config passed via data attributes (which are
133
- * always strings) into something sensible.
134
- *
135
- * @internal
136
- * @param {DOMStringMap[string]} value - The value to normalise
137
- * @param {SchemaProperty} [property] - Component schema property
138
- * @returns {string | boolean | number | undefined} Normalised data
139
- */
140
- MOJFrontend.Alert.prototype.normaliseString = function (value, property) {
141
- const trimmedValue = value ? value.trim() : ''
142
-
143
- let output
144
- let outputType
145
- if (property && property.type) {
146
- outputType = property.type
147
- }
148
-
149
- // No schema type set? Determine automatically
150
- if (!outputType) {
151
- if (['true', 'false'].includes(trimmedValue)) {
152
- outputType = 'boolean'
153
- }
154
-
155
- // Empty / whitespace-only strings are considered finite so we need to check
156
- // the length of the trimmed string as well
157
- if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
158
- outputType = 'number'
159
- }
160
- }
161
-
162
- switch (outputType) {
163
- case 'boolean':
164
- output = trimmedValue === 'true'
165
- break
166
-
167
- case 'number':
168
- output = Number(trimmedValue)
169
- break
170
-
171
- default:
172
- output = value
173
- }
174
-
175
- return output
176
- }
177
-
178
- /**
179
- * Parse dataset
180
- *
181
- * Loop over an object and normalise each value using {@link normaliseString},
182
- * optionally expanding nested `i18n.field`
183
- *
184
- * @param {Schema} schema - component schema
185
- * @param {DOMStringMap} dataset - HTML element dataset
186
- * @returns {object} Normalised dataset
187
- */
188
- MOJFrontend.Alert.prototype.parseDataset = function (schema, dataset) {
189
- const parsed = {}
190
-
191
- for (const [field, property] of Object.entries(schema.properties)) {
192
- if (field in dataset) {
193
- if (dataset[field]) {
194
- parsed[field] = this.normaliseString(dataset[field], property)
195
- }
196
- }
197
- }
198
-
199
- return parsed
200
- }
201
-
202
- /**
203
- * Config merging function
204
- *
205
- * Takes any number of objects and combines them together, with
206
- * greatest priority on the LAST item passed in.
207
- *
208
- * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
209
- * @returns {{ [key: string]: unknown }} A merged config object
210
- */
211
- MOJFrontend.Alert.prototype.mergeConfigs = function (...configObjects) {
212
- const formattedConfigObject = {}
213
-
214
- // Loop through each of the passed objects
215
- for (const configObject of configObjects) {
216
- for (const key of Object.keys(configObject)) {
217
- const option = formattedConfigObject[key]
218
- const override = configObject[key]
219
-
220
- // Push their keys one-by-one into formattedConfigObject. Any duplicate
221
- // keys with object values will be merged, otherwise the new value will
222
- // override the existing value.
223
- if (typeof option === 'object' && typeof override === 'object') {
224
- // @ts-expect-error Index signature for type 'string' is missing
225
- formattedConfigObject[key] = this.mergeConfigs(option, override)
226
- } else {
227
- formattedConfigObject[key] = override
228
- }
229
- }
230
- }
231
-
232
- return formattedConfigObject
233
- }
234
-
235
- /**
236
- * Schema for component config
237
- *
238
- * @typedef {object} Schema
239
- * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
240
- */
241
-
242
- /**
243
- * Schema property for component config
244
- *
245
- * @typedef {object} SchemaProperty
246
- * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
247
- */
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MOJFrontend = factory());
5
+ })(this, (function () { 'use strict';
6
+
7
+ function getDefaultExportFromCjs (x) {
8
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
+ }
10
+
11
+ var helpers;
12
+ var hasRequiredHelpers;
13
+
14
+ function requireHelpers () {
15
+ if (hasRequiredHelpers) return helpers;
16
+ hasRequiredHelpers = 1;
17
+ function removeAttributeValue(el, attr, value) {
18
+ let re, m;
19
+ if (el.getAttribute(attr)) {
20
+ if (el.getAttribute(attr) === value) {
21
+ el.removeAttribute(attr);
22
+ } else {
23
+ re = new RegExp(`(^|\\s)${value}(\\s|$)`);
24
+ m = el.getAttribute(attr).match(re);
25
+ if (m && m.length === 3) {
26
+ el.setAttribute(
27
+ attr,
28
+ el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')
29
+ );
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ function addAttributeValue(el, attr, value) {
36
+ let re;
37
+ if (!el.getAttribute(attr)) {
38
+ el.setAttribute(attr, value);
39
+ } else {
40
+ re = new RegExp(`(^|\\s)${value}(\\s|$)`);
41
+ if (!re.test(el.getAttribute(attr))) {
42
+ el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`);
43
+ }
44
+ }
45
+ }
46
+
47
+ function dragAndDropSupported() {
48
+ const div = document.createElement('div');
49
+ return typeof div.ondrop !== 'undefined'
50
+ }
51
+
52
+ function formDataSupported() {
53
+ return typeof FormData === 'function'
54
+ }
55
+
56
+ function fileApiSupported() {
57
+ const input = document.createElement('input');
58
+ input.type = 'file';
59
+ return typeof input.files !== 'undefined'
60
+ }
61
+
62
+ function nodeListForEach(nodes, callback) {
63
+ if (window.NodeList.prototype.forEach) {
64
+ return nodes.forEach(callback)
65
+ }
66
+ for (let i = 0; i < nodes.length; i++) {
67
+ callback.call(window, nodes[i], i, nodes);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Find an elements next sibling
73
+ *
74
+ * Utility function to find an elements next sibling matching the provided
75
+ * selector.
76
+ *
77
+ * @param {HTMLElement} $element - Element to find siblings for
78
+ * @param {string} selector - selector for required sibling
79
+ */
80
+ function getNextSibling($element, selector) {
81
+ if (!$element) return
82
+ // Get the next sibling element
83
+ let $sibling = $element.nextElementSibling;
84
+
85
+ // If there's no selector, return the first sibling
86
+ if (!selector) return $sibling
87
+
88
+ // If the sibling matches our selector, use it
89
+ // If not, jump to the next sibling and continue the loop
90
+ while ($sibling) {
91
+ if ($sibling.matches(selector)) return $sibling
92
+ $sibling = $sibling.nextElementSibling;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Find an elements preceding sibling
98
+ *
99
+ * Utility function to find an elements previous sibling matching the provided
100
+ * selector.
101
+ *
102
+ * @param {HTMLElement} $element - Element to find siblings for
103
+ * @param {string} selector - selector for required sibling
104
+ */
105
+ function getPreviousSibling($element, selector) {
106
+ if (!$element) return
107
+ // Get the previous sibling element
108
+ let $sibling = $element.previousElementSibling;
109
+
110
+ // If there's no selector, return the first sibling
111
+ if (!selector) return $sibling
112
+
113
+ // If the sibling matches our selector, use it
114
+ // If not, jump to the next sibling and continue the loop
115
+ while ($sibling) {
116
+ if ($sibling.matches(selector)) return $sibling
117
+ $sibling = $sibling.previousElementSibling;
118
+ }
119
+ }
120
+
121
+ function findNearestMatchingElement($element, selector) {
122
+ // If no element or selector is provided, return null
123
+ if (!$element) return
124
+ if (!selector) return
125
+
126
+ // Start with the current element
127
+ let $currentElement = $element;
128
+
129
+ while ($currentElement) {
130
+ // First check the current element
131
+ if ($currentElement.matches(selector)) {
132
+ return $currentElement
133
+ }
134
+
135
+ // Check all previous siblings
136
+ let $sibling = $currentElement.previousElementSibling;
137
+ while ($sibling) {
138
+ // Check if the sibling itself is a heading
139
+ if ($sibling.matches(selector)) {
140
+ return $sibling
141
+ }
142
+ $sibling = $sibling.previousElementSibling;
143
+ }
144
+
145
+ // If no match found in siblings, move up to parent
146
+ $currentElement = $currentElement.parentElement;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Move focus to element
152
+ *
153
+ * Sets tabindex to -1 to make the element programmatically focusable,
154
+ * but removes it on blur as the element doesn't need to be focused again.
155
+ *
156
+ * @param {HTMLElement} $element - HTML element
157
+ * @param {object} [options] - Handler options
158
+ * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
159
+ * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
160
+ */
161
+ function setFocus($element, options = {}) {
162
+ const isFocusable = $element.getAttribute('tabindex');
163
+
164
+ if (!isFocusable) {
165
+ $element.setAttribute('tabindex', '-1');
166
+ }
167
+
168
+ /**
169
+ * Handle element focus
170
+ */
171
+ function onFocus() {
172
+ $element.addEventListener('blur', onBlur, { once: true });
173
+ }
174
+
175
+ /**
176
+ * Handle element blur
177
+ */
178
+ function onBlur() {
179
+ if (options.onBlur) {
180
+ options.onBlur.call($element);
181
+ }
182
+
183
+ if (!isFocusable) {
184
+ $element.removeAttribute('tabindex');
185
+ }
186
+ }
187
+
188
+ // Add listener to reset element on blur, after focus
189
+ $element.addEventListener('focus', onFocus, { once: true });
190
+
191
+ // Focus element
192
+ if (options.onBeforeFocus) {
193
+ options.onBeforeFocus.call($element);
194
+ }
195
+ $element.focus();
196
+ }
197
+
198
+ helpers = {
199
+ removeAttributeValue,
200
+ addAttributeValue,
201
+ dragAndDropSupported,
202
+ formDataSupported,
203
+ fileApiSupported,
204
+ nodeListForEach,
205
+ getNextSibling,
206
+ getPreviousSibling,
207
+ findNearestMatchingElement,
208
+ setFocus
209
+ };
210
+ return helpers;
211
+ }
212
+
213
+ var alert$1;
214
+ var hasRequiredAlert;
215
+
216
+ function requireAlert () {
217
+ if (hasRequiredAlert) return alert$1;
218
+ hasRequiredAlert = 1;
219
+ const {
220
+ findNearestMatchingElement,
221
+ getPreviousSibling,
222
+ setFocus
223
+ } = requireHelpers();
224
+
225
+ /**
226
+ * @typedef {object} AlertConfig
227
+ * @property {boolean} [dismissible=false] - Can the alert be dismissed by the user
228
+ * @property {string} [dismissText=Dismiss] - the label text for the dismiss button
229
+ * @property {boolean} [disableAutoFocus=false] - whether the alert will be autofocused
230
+ * @property {string} [focusOnDismissSelector] - CSS Selector for element to be focused on dismiss
231
+ */
232
+
233
+ /**
234
+ * @param {HTMLElement} $module - the Alert element
235
+ * @param {AlertConfig} config - configuration options
236
+ * @class
237
+ */
238
+ function Alert($module, config = {}) {
239
+ if (!$module) {
240
+ return this
241
+ }
242
+
243
+ const schema = Object.freeze({
244
+ properties: {
245
+ dismissible: { type: 'boolean' },
246
+ dismissText: { type: 'string' },
247
+ disableAutoFocus: { type: 'boolean' },
248
+ focusOnDismissSelector: { type: 'string' }
249
+ }
250
+ });
251
+
252
+ const defaults = {
253
+ dismissible: false,
254
+ dismissText: 'Dismiss',
255
+ disableAutoFocus: false
256
+ };
257
+
258
+ // data attributes override JS config, which overrides defaults
259
+ this.config = this.mergeConfigs(
260
+ defaults,
261
+ config,
262
+ this.parseDataset(schema, $module.dataset)
263
+ );
264
+
265
+ this.$module = $module;
266
+ }
267
+
268
+ Alert.prototype.init = function () {
269
+ /**
270
+ * Focus the alert
271
+ *
272
+ * If `role="alert"` is set, focus the element to help some assistive
273
+ * technologies prioritise announcing it.
274
+ *
275
+ * You can turn off the auto-focus functionality by setting
276
+ * `data-disable-auto-focus="true"` in the component HTML. You might wish to
277
+ * do this based on user research findings, or to avoid a clash with another
278
+ * element which should be focused when the page loads.
279
+ */
280
+ if (
281
+ this.$module.getAttribute('role') === 'alert' &&
282
+ !this.config.disableAutoFocus
283
+ ) {
284
+ setFocus(this.$module);
285
+ }
286
+
287
+ this.$dismissButton = this.$module.querySelector('.moj-alert__dismiss');
288
+
289
+ if (this.config.dismissible && this.$dismissButton) {
290
+ this.$dismissButton.innerHTML = this.config.dismissText;
291
+ this.$dismissButton.removeAttribute('hidden');
292
+
293
+ this.$module.addEventListener('click', (event) => {
294
+ if (this.$dismissButton.contains(event.target)) {
295
+ this.dimiss();
296
+ }
297
+ });
298
+ }
299
+ };
300
+
301
+ /**
302
+ * Handle dismissing the alert
303
+ */
304
+ Alert.prototype.dimiss = function () {
305
+ let $elementToRecieveFocus;
306
+
307
+ // If a selector has been provided, attempt to find that element
308
+ if (this.config.focusOnDismissSelector) {
309
+ $elementToRecieveFocus = document.querySelector(
310
+ this.config.focusOnDismissSelector
311
+ );
312
+ }
313
+
314
+ // Is the next sibling another alert
315
+ if (!$elementToRecieveFocus) {
316
+ const $nextSibling = this.$module.nextElementSibling;
317
+ if ($nextSibling && $nextSibling.matches('.moj-alert')) {
318
+ $elementToRecieveFocus = $nextSibling;
319
+ }
320
+ }
321
+
322
+ // Else try to find any preceding sibling alert or heading
323
+ if (!$elementToRecieveFocus) {
324
+ $elementToRecieveFocus = getPreviousSibling(
325
+ this.$module,
326
+ '.moj-alert, h1, h2, h3, h4, h5, h6'
327
+ );
328
+ }
329
+
330
+ // Else find the closest ancestor heading, or fallback to main, or last resort
331
+ // use the body element
332
+ if (!$elementToRecieveFocus) {
333
+ $elementToRecieveFocus = findNearestMatchingElement(
334
+ this.$module,
335
+ 'h1, h2, h3, h4, h5, h6, main, body'
336
+ );
337
+ }
338
+
339
+ // If we have an element, place focus on it
340
+ if ($elementToRecieveFocus) {
341
+ setFocus($elementToRecieveFocus);
342
+ }
343
+
344
+ // Remove the alert
345
+ this.$module.remove();
346
+ };
347
+
348
+ /**
349
+ * Normalise string
350
+ *
351
+ * 'If it looks like a duck, and it quacks like a duck…' 🦆
352
+ *
353
+ * If the passed value looks like a boolean or a number, convert it to a boolean
354
+ * or number.
355
+ *
356
+ * Designed to be used to convert config passed via data attributes (which are
357
+ * always strings) into something sensible.
358
+ *
359
+ * @internal
360
+ * @param {DOMStringMap[string]} value - The value to normalise
361
+ * @param {SchemaProperty} [property] - Component schema property
362
+ * @returns {string | boolean | number | undefined} Normalised data
363
+ */
364
+ Alert.prototype.normaliseString = function (value, property) {
365
+ const trimmedValue = value ? value.trim() : '';
366
+
367
+ let output;
368
+ let outputType;
369
+ if (property && property.type) {
370
+ outputType = property.type;
371
+ }
372
+
373
+ // No schema type set? Determine automatically
374
+ if (!outputType) {
375
+ if (['true', 'false'].includes(trimmedValue)) {
376
+ outputType = 'boolean';
377
+ }
378
+
379
+ // Empty / whitespace-only strings are considered finite so we need to check
380
+ // the length of the trimmed string as well
381
+ if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
382
+ outputType = 'number';
383
+ }
384
+ }
385
+
386
+ switch (outputType) {
387
+ case 'boolean':
388
+ output = trimmedValue === 'true';
389
+ break
390
+
391
+ case 'number':
392
+ output = Number(trimmedValue);
393
+ break
394
+
395
+ default:
396
+ output = value;
397
+ }
398
+
399
+ return output
400
+ };
401
+
402
+ /**
403
+ * Parse dataset
404
+ *
405
+ * Loop over an object and normalise each value using {@link normaliseString},
406
+ * optionally expanding nested `i18n.field`
407
+ *
408
+ * @param {Schema} schema - component schema
409
+ * @param {DOMStringMap} dataset - HTML element dataset
410
+ * @returns {object} Normalised dataset
411
+ */
412
+ Alert.prototype.parseDataset = function (schema, dataset) {
413
+ const parsed = {};
414
+
415
+ for (const [field, property] of Object.entries(schema.properties)) {
416
+ if (field in dataset) {
417
+ if (dataset[field]) {
418
+ parsed[field] = this.normaliseString(dataset[field], property);
419
+ }
420
+ }
421
+ }
422
+
423
+ return parsed
424
+ };
425
+
426
+ /**
427
+ * Config merging function
428
+ *
429
+ * Takes any number of objects and combines them together, with
430
+ * greatest priority on the LAST item passed in.
431
+ *
432
+ * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
433
+ * @returns {{ [key: string]: unknown }} A merged config object
434
+ */
435
+ Alert.prototype.mergeConfigs = function (...configObjects) {
436
+ const formattedConfigObject = {};
437
+
438
+ // Loop through each of the passed objects
439
+ for (const configObject of configObjects) {
440
+ for (const key of Object.keys(configObject)) {
441
+ const option = formattedConfigObject[key];
442
+ const override = configObject[key];
443
+
444
+ // Push their keys one-by-one into formattedConfigObject. Any duplicate
445
+ // keys with object values will be merged, otherwise the new value will
446
+ // override the existing value.
447
+ if (typeof option === 'object' && typeof override === 'object') {
448
+ // @ts-expect-error Index signature for type 'string' is missing
449
+ formattedConfigObject[key] = this.mergeConfigs(option, override);
450
+ } else {
451
+ formattedConfigObject[key] = override;
452
+ }
453
+ }
454
+ }
455
+
456
+ return formattedConfigObject
457
+ };
458
+
459
+ alert$1 = { Alert };
460
+
461
+ /**
462
+ * Schema for component config
463
+ *
464
+ * @typedef {object} Schema
465
+ * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
466
+ */
467
+
468
+ /**
469
+ * Schema property for component config
470
+ *
471
+ * @typedef {object} SchemaProperty
472
+ * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
473
+ */
474
+ return alert$1;
475
+ }
476
+
477
+ var alertExports = requireAlert();
478
+ var alert = /*@__PURE__*/getDefaultExportFromCjs(alertExports);
479
+
480
+ return alert;
481
+
482
+ }));