@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.
- package/moj/all.jquery.min.js +1 -81
- package/moj/all.js +2577 -2853
- package/moj/all.mjs +126 -0
- package/moj/all.scss +1 -1
- package/moj/components/add-another/add-another.js +111 -132
- package/moj/components/add-another/add-another.mjs +106 -0
- package/moj/components/alert/alert.js +352 -479
- package/moj/components/alert/alert.mjs +251 -0
- package/moj/components/alert/alert.spec.helper.js +6 -24
- package/moj/components/alert/alert.spec.helper.mjs +66 -0
- package/moj/components/button-menu/button-menu.js +326 -343
- package/moj/components/button-menu/button-menu.mjs +329 -0
- package/moj/components/cookie-banner/_cookie-banner.scss +1 -1
- package/moj/components/date-picker/date-picker.js +905 -922
- package/moj/components/date-picker/date-picker.mjs +961 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -119
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
- package/moj/components/form-validator/form-validator.js +201 -396
- package/moj/components/form-validator/form-validator.mjs +168 -0
- package/moj/components/multi-file-upload/multi-file-upload.js +227 -441
- package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
- package/moj/components/multi-select/multi-select.js +82 -103
- package/moj/components/multi-select/multi-select.mjs +77 -0
- package/moj/components/password-reveal/password-reveal.js +40 -61
- package/moj/components/password-reveal/password-reveal.mjs +35 -0
- package/moj/components/rich-text-editor/rich-text-editor.js +162 -183
- package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
- package/moj/components/search-toggle/search-toggle.js +52 -73
- package/moj/components/search-toggle/search-toggle.mjs +54 -0
- package/moj/components/sortable-table/sortable-table.js +143 -164
- package/moj/components/sortable-table/sortable-table.mjs +138 -0
- package/moj/helpers.js +196 -215
- package/moj/helpers.mjs +123 -0
- package/moj/moj-frontend.min.js +1 -81
- package/moj/version.js +6 -23
- package/moj/version.mjs +3 -0
- package/package.json +24 -6
package/moj/helpers.js
CHANGED
|
@@ -1,218 +1,199 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
}));
|
package/moj/helpers.mjs
ADDED
|
@@ -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 };
|