@ministryofjustice/frontend 3.5.0 → 3.6.1

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 (37) hide show
  1. package/moj/all.jquery.min.js +1 -81
  2. package/moj/all.js +2577 -2853
  3. package/moj/all.mjs +126 -0
  4. package/moj/all.scss +1 -1
  5. package/moj/components/add-another/add-another.js +111 -132
  6. package/moj/components/add-another/add-another.mjs +106 -0
  7. package/moj/components/alert/alert.js +352 -479
  8. package/moj/components/alert/alert.mjs +251 -0
  9. package/moj/components/alert/alert.spec.helper.js +6 -24
  10. package/moj/components/alert/alert.spec.helper.mjs +66 -0
  11. package/moj/components/button-menu/button-menu.js +326 -343
  12. package/moj/components/button-menu/button-menu.mjs +329 -0
  13. package/moj/components/cookie-banner/_cookie-banner.scss +1 -1
  14. package/moj/components/date-picker/date-picker.js +905 -922
  15. package/moj/components/date-picker/date-picker.mjs +961 -0
  16. package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -119
  17. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
  18. package/moj/components/form-validator/form-validator.js +201 -396
  19. package/moj/components/form-validator/form-validator.mjs +168 -0
  20. package/moj/components/multi-file-upload/multi-file-upload.js +227 -441
  21. package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
  22. package/moj/components/multi-select/multi-select.js +82 -103
  23. package/moj/components/multi-select/multi-select.mjs +77 -0
  24. package/moj/components/password-reveal/password-reveal.js +40 -61
  25. package/moj/components/password-reveal/password-reveal.mjs +35 -0
  26. package/moj/components/rich-text-editor/rich-text-editor.js +162 -183
  27. package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
  28. package/moj/components/search-toggle/search-toggle.js +52 -73
  29. package/moj/components/search-toggle/search-toggle.mjs +54 -0
  30. package/moj/components/sortable-table/sortable-table.js +143 -164
  31. package/moj/components/sortable-table/sortable-table.mjs +138 -0
  32. package/moj/helpers.js +196 -215
  33. package/moj/helpers.mjs +123 -0
  34. package/moj/moj-frontend.min.js +1 -81
  35. package/moj/version.js +6 -23
  36. package/moj/version.mjs +3 -0
  37. package/package.json +24 -6
package/moj/helpers.js CHANGED
@@ -1,218 +1,199 @@
1
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$1;
12
- var hasRequiredHelpers;
13
-
14
- function requireHelpers () {
15
- if (hasRequiredHelpers) return helpers$1;
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$1 = {
199
- removeAttributeValue,
200
- addAttributeValue,
201
- dragAndDropSupported,
202
- formDataSupported,
203
- fileApiSupported,
204
- nodeListForEach,
205
- getNextSibling,
206
- getPreviousSibling,
207
- findNearestMatchingElement,
208
- setFocus
209
- };
210
- return helpers$1;
211
- }
212
-
213
- var helpersExports = requireHelpers();
214
- var helpers = /*@__PURE__*/getDefaultExportFromCjs(helpersExports);
215
-
216
- return helpers;
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ function removeAttributeValue(el, attr, value) {
8
+ let re, m;
9
+ if (el.getAttribute(attr)) {
10
+ if (el.getAttribute(attr) === value) {
11
+ el.removeAttribute(attr);
12
+ } else {
13
+ re = new RegExp(`(^|\\s)${value}(\\s|$)`);
14
+ m = el.getAttribute(attr).match(re);
15
+ if (m && m.length === 3) {
16
+ el.setAttribute(
17
+ attr,
18
+ el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')
19
+ );
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ function addAttributeValue(el, attr, value) {
26
+ let re;
27
+ if (!el.getAttribute(attr)) {
28
+ el.setAttribute(attr, value);
29
+ } else {
30
+ re = new RegExp(`(^|\\s)${value}(\\s|$)`);
31
+ if (!re.test(el.getAttribute(attr))) {
32
+ el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`);
33
+ }
34
+ }
35
+ }
36
+
37
+ function dragAndDropSupported() {
38
+ const div = document.createElement('div');
39
+ return typeof div.ondrop !== 'undefined'
40
+ }
41
+
42
+ function formDataSupported() {
43
+ return typeof FormData === 'function'
44
+ }
45
+
46
+ function fileApiSupported() {
47
+ const input = document.createElement('input');
48
+ input.type = 'file';
49
+ return typeof input.files !== 'undefined'
50
+ }
51
+
52
+ function nodeListForEach(nodes, callback) {
53
+ if (window.NodeList.prototype.forEach) {
54
+ return nodes.forEach(callback)
55
+ }
56
+ for (let i = 0; i < nodes.length; i++) {
57
+ callback.call(window, nodes[i], i, nodes);
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Find an elements next sibling
63
+ *
64
+ * Utility function to find an elements next sibling matching the provided
65
+ * selector.
66
+ *
67
+ * @param {HTMLElement} $element - Element to find siblings for
68
+ * @param {string} selector - selector for required sibling
69
+ */
70
+ function getNextSibling($element, selector) {
71
+ if (!$element) return
72
+ // Get the next sibling element
73
+ let $sibling = $element.nextElementSibling;
74
+
75
+ // If there's no selector, return the first sibling
76
+ if (!selector) return $sibling
77
+
78
+ // If the sibling matches our selector, use it
79
+ // If not, jump to the next sibling and continue the loop
80
+ while ($sibling) {
81
+ if ($sibling.matches(selector)) return $sibling
82
+ $sibling = $sibling.nextElementSibling;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Find an elements preceding sibling
88
+ *
89
+ * Utility function to find an elements previous sibling matching the provided
90
+ * selector.
91
+ *
92
+ * @param {HTMLElement} $element - Element to find siblings for
93
+ * @param {string} selector - selector for required sibling
94
+ */
95
+ function getPreviousSibling($element, selector) {
96
+ if (!$element) return
97
+ // Get the previous sibling element
98
+ let $sibling = $element.previousElementSibling;
99
+
100
+ // If there's no selector, return the first sibling
101
+ if (!selector) return $sibling
102
+
103
+ // If the sibling matches our selector, use it
104
+ // If not, jump to the next sibling and continue the loop
105
+ while ($sibling) {
106
+ if ($sibling.matches(selector)) return $sibling
107
+ $sibling = $sibling.previousElementSibling;
108
+ }
109
+ }
110
+
111
+ function findNearestMatchingElement($element, selector) {
112
+ // If no element or selector is provided, return null
113
+ if (!$element) return
114
+ if (!selector) return
115
+
116
+ // Start with the current element
117
+ let $currentElement = $element;
118
+
119
+ while ($currentElement) {
120
+ // First check the current element
121
+ if ($currentElement.matches(selector)) {
122
+ return $currentElement
123
+ }
124
+
125
+ // Check all previous siblings
126
+ let $sibling = $currentElement.previousElementSibling;
127
+ while ($sibling) {
128
+ // Check if the sibling itself is a heading
129
+ if ($sibling.matches(selector)) {
130
+ return $sibling
131
+ }
132
+ $sibling = $sibling.previousElementSibling;
133
+ }
134
+
135
+ // If no match found in siblings, move up to parent
136
+ $currentElement = $currentElement.parentElement;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Move focus to element
142
+ *
143
+ * Sets tabindex to -1 to make the element programmatically focusable,
144
+ * but removes it on blur as the element doesn't need to be focused again.
145
+ *
146
+ * @param {HTMLElement} $element - HTML element
147
+ * @param {object} [options] - Handler options
148
+ * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
149
+ * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
150
+ */
151
+ function setFocus($element, options = {}) {
152
+ const isFocusable = $element.getAttribute('tabindex');
153
+
154
+ if (!isFocusable) {
155
+ $element.setAttribute('tabindex', '-1');
156
+ }
157
+
158
+ /**
159
+ * Handle element focus
160
+ */
161
+ function onFocus() {
162
+ $element.addEventListener('blur', onBlur, { once: true });
163
+ }
164
+
165
+ /**
166
+ * Handle element blur
167
+ */
168
+ function onBlur() {
169
+ if (options.onBlur) {
170
+ options.onBlur.call($element);
171
+ }
172
+
173
+ if (!isFocusable) {
174
+ $element.removeAttribute('tabindex');
175
+ }
176
+ }
177
+
178
+ // Add listener to reset element on blur, after focus
179
+ $element.addEventListener('focus', onFocus, { once: true });
180
+
181
+ // Focus element
182
+ if (options.onBeforeFocus) {
183
+ options.onBeforeFocus.call($element);
184
+ }
185
+ $element.focus();
186
+ }
187
+
188
+ exports.addAttributeValue = addAttributeValue;
189
+ exports.dragAndDropSupported = dragAndDropSupported;
190
+ exports.fileApiSupported = fileApiSupported;
191
+ exports.findNearestMatchingElement = findNearestMatchingElement;
192
+ exports.formDataSupported = formDataSupported;
193
+ exports.getNextSibling = getNextSibling;
194
+ exports.getPreviousSibling = getPreviousSibling;
195
+ exports.nodeListForEach = nodeListForEach;
196
+ exports.removeAttributeValue = removeAttributeValue;
197
+ exports.setFocus = setFocus;
217
198
 
218
199
  }));
@@ -0,0 +1,123 @@
1
+ function dragAndDropSupported() {
2
+ const div = document.createElement('div');
3
+ return typeof div.ondrop !== 'undefined'
4
+ }
5
+
6
+ function formDataSupported() {
7
+ return typeof FormData === 'function'
8
+ }
9
+
10
+ function fileApiSupported() {
11
+ const input = document.createElement('input');
12
+ input.type = 'file';
13
+ return typeof input.files !== 'undefined'
14
+ }
15
+
16
+ function nodeListForEach(nodes, callback) {
17
+ if (window.NodeList.prototype.forEach) {
18
+ return nodes.forEach(callback)
19
+ }
20
+ for (let i = 0; i < nodes.length; i++) {
21
+ callback.call(window, nodes[i], i, nodes);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Find an elements preceding sibling
27
+ *
28
+ * Utility function to find an elements previous sibling matching the provided
29
+ * selector.
30
+ *
31
+ * @param {HTMLElement} $element - Element to find siblings for
32
+ * @param {string} selector - selector for required sibling
33
+ */
34
+ function getPreviousSibling($element, selector) {
35
+ if (!$element) return
36
+ // Get the previous sibling element
37
+ let $sibling = $element.previousElementSibling;
38
+
39
+ // If the sibling matches our selector, use it
40
+ // If not, jump to the next sibling and continue the loop
41
+ while ($sibling) {
42
+ if ($sibling.matches(selector)) return $sibling
43
+ $sibling = $sibling.previousElementSibling;
44
+ }
45
+ }
46
+
47
+ function findNearestMatchingElement($element, selector) {
48
+ // If no element or selector is provided, return null
49
+ if (!$element) return
50
+
51
+ // Start with the current element
52
+ let $currentElement = $element;
53
+
54
+ while ($currentElement) {
55
+ // First check the current element
56
+ if ($currentElement.matches(selector)) {
57
+ return $currentElement
58
+ }
59
+
60
+ // Check all previous siblings
61
+ let $sibling = $currentElement.previousElementSibling;
62
+ while ($sibling) {
63
+ // Check if the sibling itself is a heading
64
+ if ($sibling.matches(selector)) {
65
+ return $sibling
66
+ }
67
+ $sibling = $sibling.previousElementSibling;
68
+ }
69
+
70
+ // If no match found in siblings, move up to parent
71
+ $currentElement = $currentElement.parentElement;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Move focus to element
77
+ *
78
+ * Sets tabindex to -1 to make the element programmatically focusable,
79
+ * but removes it on blur as the element doesn't need to be focused again.
80
+ *
81
+ * @param {HTMLElement} $element - HTML element
82
+ * @param {object} [options] - Handler options
83
+ * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
84
+ * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
85
+ */
86
+ function setFocus($element, options = {}) {
87
+ const isFocusable = $element.getAttribute('tabindex');
88
+
89
+ if (!isFocusable) {
90
+ $element.setAttribute('tabindex', '-1');
91
+ }
92
+
93
+ /**
94
+ * Handle element focus
95
+ */
96
+ function onFocus() {
97
+ $element.addEventListener('blur', onBlur, { once: true });
98
+ }
99
+
100
+ /**
101
+ * Handle element blur
102
+ */
103
+ function onBlur() {
104
+ if (options.onBlur) {
105
+ options.onBlur.call($element);
106
+ }
107
+
108
+ if (!isFocusable) {
109
+ $element.removeAttribute('tabindex');
110
+ }
111
+ }
112
+
113
+ // Add listener to reset element on blur, after focus
114
+ $element.addEventListener('focus', onFocus, { once: true });
115
+
116
+ // Focus element
117
+ if (options.onBeforeFocus) {
118
+ options.onBeforeFocus.call($element);
119
+ }
120
+ $element.focus();
121
+ }
122
+
123
+ export { dragAndDropSupported, fileApiSupported, findNearestMatchingElement, formDataSupported, getPreviousSibling, nodeListForEach, setFocus };