@ministryofjustice/frontend 5.0.0 → 5.1.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.bundle.js +1598 -1062
- package/moj/all.bundle.js.map +1 -1
- package/moj/all.bundle.mjs +1894 -1054
- package/moj/all.bundle.mjs.map +1 -1
- package/moj/all.mjs +7 -90
- package/moj/all.mjs.map +1 -1
- package/moj/all.scss +1 -0
- package/moj/all.scss.map +1 -1
- package/moj/common/index.mjs +57 -0
- package/moj/common/index.mjs.map +1 -0
- package/moj/common/moj-frontend-version.mjs +14 -0
- package/moj/common/moj-frontend-version.mjs.map +1 -0
- package/moj/components/add-another/add-another.bundle.js +105 -76
- package/moj/components/add-another/add-another.bundle.js.map +1 -1
- package/moj/components/add-another/add-another.bundle.mjs +222 -71
- package/moj/components/add-another/add-another.bundle.mjs.map +1 -1
- package/moj/components/add-another/add-another.mjs +103 -72
- package/moj/components/add-another/add-another.mjs.map +1 -1
- package/moj/components/alert/alert.bundle.js +115 -191
- package/moj/components/alert/alert.bundle.js.map +1 -1
- package/moj/components/alert/alert.bundle.mjs +354 -186
- package/moj/components/alert/alert.bundle.mjs.map +1 -1
- package/moj/components/alert/alert.mjs +55 -140
- package/moj/components/alert/alert.mjs.map +1 -1
- package/moj/components/button-menu/README.md +3 -1
- package/moj/components/button-menu/button-menu.bundle.js +91 -120
- package/moj/components/button-menu/button-menu.bundle.js.map +1 -1
- package/moj/components/button-menu/button-menu.bundle.mjs +329 -114
- package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -1
- package/moj/components/button-menu/button-menu.mjs +89 -116
- package/moj/components/button-menu/button-menu.mjs.map +1 -1
- package/moj/components/date-picker/date-picker.bundle.js +174 -154
- package/moj/components/date-picker/date-picker.bundle.js.map +1 -1
- package/moj/components/date-picker/date-picker.bundle.mjs +411 -147
- package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -1
- package/moj/components/date-picker/date-picker.mjs +172 -150
- package/moj/components/date-picker/date-picker.mjs.map +1 -1
- package/moj/components/filter/template.njk +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +133 -44
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +374 -41
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +131 -40
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.js +159 -69
- package/moj/components/form-validator/form-validator.bundle.js.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.mjs +399 -65
- package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.mjs +134 -54
- package/moj/components/form-validator/form-validator.mjs.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js +291 -117
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +527 -109
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.mjs +288 -101
- package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
- package/moj/components/multi-file-upload/template.njk +1 -1
- package/moj/components/multi-select/multi-select.bundle.js +106 -41
- package/moj/components/multi-select/multi-select.bundle.js.map +1 -1
- package/moj/components/multi-select/multi-select.bundle.mjs +346 -37
- package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -1
- package/moj/components/multi-select/multi-select.mjs +104 -37
- package/moj/components/multi-select/multi-select.mjs.map +1 -1
- package/moj/components/password-reveal/_password-reveal.scss +3 -1
- package/moj/components/password-reveal/_password-reveal.scss.map +1 -1
- package/moj/components/password-reveal/password-reveal.bundle.js +32 -29
- package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -1
- package/moj/components/password-reveal/password-reveal.bundle.mjs +149 -24
- package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -1
- package/moj/components/password-reveal/password-reveal.mjs +30 -25
- package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
- package/moj/components/rich-text-editor/README.md +4 -3
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js +127 -62
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -1
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +367 -58
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -1
- package/moj/components/rich-text-editor/rich-text-editor.mjs +125 -58
- package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
- package/moj/components/search-toggle/search-toggle.bundle.js +94 -26
- package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -1
- package/moj/components/search-toggle/search-toggle.bundle.mjs +334 -22
- package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -1
- package/moj/components/search-toggle/search-toggle.mjs +92 -22
- package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
- package/moj/components/sortable-table/_sortable-table.scss +3 -42
- package/moj/components/sortable-table/_sortable-table.scss.map +1 -1
- package/moj/components/sortable-table/sortable-table.bundle.js +200 -83
- package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -1
- package/moj/components/sortable-table/sortable-table.bundle.mjs +439 -78
- package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -1
- package/moj/components/sortable-table/sortable-table.mjs +198 -79
- package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
- package/moj/core/_all.scss +3 -0
- package/moj/core/_all.scss.map +1 -0
- package/moj/core/_moj-frontend-properties.scss +7 -0
- package/moj/core/_moj-frontend-properties.scss.map +1 -0
- package/moj/filters/prototype-kit-13-filters.js +4 -3
- package/moj/helpers.bundle.js +22 -77
- package/moj/helpers.bundle.js.map +1 -1
- package/moj/helpers.bundle.mjs +23 -74
- package/moj/helpers.bundle.mjs.map +1 -1
- package/moj/helpers.mjs +23 -74
- package/moj/helpers.mjs.map +1 -1
- package/moj/moj-frontend.min.css +1 -1
- package/moj/moj-frontend.min.css.map +1 -1
- package/moj/moj-frontend.min.js +1 -1
- package/moj/moj-frontend.min.js.map +1 -1
- package/package.json +1 -1
- package/moj/version.bundle.js +0 -12
- package/moj/version.bundle.js.map +0 -1
- package/moj/version.bundle.mjs +0 -4
- package/moj/version.bundle.mjs.map +0 -1
- package/moj/version.mjs +0 -4
- package/moj/version.mjs.map +0 -1
package/moj/helpers.bundle.js
CHANGED
|
@@ -4,43 +4,42 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @param {Element} $element - Element to remove attribute value from
|
|
9
|
+
* @param {string} attr - Attribute name
|
|
10
|
+
* @param {string} value - Attribute value
|
|
11
|
+
*/
|
|
12
|
+
function removeAttributeValue($element, attr, value) {
|
|
8
13
|
let re, m;
|
|
9
|
-
if (
|
|
10
|
-
if (
|
|
11
|
-
|
|
14
|
+
if ($element.getAttribute(attr)) {
|
|
15
|
+
if ($element.getAttribute(attr) === value) {
|
|
16
|
+
$element.removeAttribute(attr);
|
|
12
17
|
} else {
|
|
13
18
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
14
|
-
m =
|
|
19
|
+
m = $element.getAttribute(attr).match(re);
|
|
15
20
|
if (m && m.length === 3) {
|
|
16
|
-
|
|
21
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Element} $element - Element to add attribute value to
|
|
29
|
+
* @param {string} attr - Attribute name
|
|
30
|
+
* @param {string} value - Attribute value
|
|
31
|
+
*/
|
|
32
|
+
function addAttributeValue($element, attr, value) {
|
|
22
33
|
let re;
|
|
23
|
-
if (
|
|
24
|
-
|
|
34
|
+
if (!$element.getAttribute(attr)) {
|
|
35
|
+
$element.setAttribute(attr, value);
|
|
25
36
|
} else {
|
|
26
37
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
27
|
-
if (!re.test(
|
|
28
|
-
|
|
38
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
39
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
|
-
function dragAndDropSupported() {
|
|
33
|
-
const div = document.createElement('div');
|
|
34
|
-
return typeof div.ondrop !== 'undefined';
|
|
35
|
-
}
|
|
36
|
-
function formDataSupported() {
|
|
37
|
-
return typeof FormData === 'function';
|
|
38
|
-
}
|
|
39
|
-
function fileApiSupported() {
|
|
40
|
-
const input = document.createElement('input');
|
|
41
|
-
input.type = 'file';
|
|
42
|
-
return typeof input.files !== 'undefined';
|
|
43
|
-
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* Find an elements next sibling
|
|
@@ -131,65 +130,11 @@
|
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
/**
|
|
135
|
-
* Move focus to element
|
|
136
|
-
*
|
|
137
|
-
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
138
|
-
* but removes it on blur as the element doesn't need to be focused again.
|
|
139
|
-
*
|
|
140
|
-
* @param {HTMLElement} $element - HTML element
|
|
141
|
-
* @param {object} [options] - Handler options
|
|
142
|
-
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
143
|
-
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
144
|
-
*/
|
|
145
|
-
function setFocus($element, options = {}) {
|
|
146
|
-
const isFocusable = $element.getAttribute('tabindex');
|
|
147
|
-
if (!isFocusable) {
|
|
148
|
-
$element.setAttribute('tabindex', '-1');
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Handle element focus
|
|
153
|
-
*/
|
|
154
|
-
function onFocus() {
|
|
155
|
-
$element.addEventListener('blur', onBlur, {
|
|
156
|
-
once: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Handle element blur
|
|
162
|
-
*/
|
|
163
|
-
function onBlur() {
|
|
164
|
-
if (options.onBlur) {
|
|
165
|
-
options.onBlur.call($element);
|
|
166
|
-
}
|
|
167
|
-
if (!isFocusable) {
|
|
168
|
-
$element.removeAttribute('tabindex');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Add listener to reset element on blur, after focus
|
|
173
|
-
$element.addEventListener('focus', onFocus, {
|
|
174
|
-
once: true
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Focus element
|
|
178
|
-
if (options.onBeforeFocus) {
|
|
179
|
-
options.onBeforeFocus.call($element);
|
|
180
|
-
}
|
|
181
|
-
$element.focus();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
133
|
exports.addAttributeValue = addAttributeValue;
|
|
185
|
-
exports.dragAndDropSupported = dragAndDropSupported;
|
|
186
|
-
exports.fileApiSupported = fileApiSupported;
|
|
187
134
|
exports.findNearestMatchingElement = findNearestMatchingElement;
|
|
188
|
-
exports.formDataSupported = formDataSupported;
|
|
189
135
|
exports.getNextSibling = getNextSibling;
|
|
190
136
|
exports.getPreviousSibling = getPreviousSibling;
|
|
191
137
|
exports.removeAttributeValue = removeAttributeValue;
|
|
192
|
-
exports.setFocus = setFocus;
|
|
193
138
|
|
|
194
139
|
}));
|
|
195
140
|
//# sourceMappingURL=helpers.bundle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.bundle.js","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.bundle.js","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getNextSibling","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement"],"mappings":";;;;;;EAAA;EACA;EACA;EACA;EACA;EACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAC1D,IAAIC,EAAE,EAAEC,CAAC;EACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;MAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;EACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;EAChC,KAAC,MAAM;EACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;QACzCE,CAAC,GAAGJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;EAC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,QAAQ,CAACI,sBAAsB;EAC5C;;EAEA;MACAE,eAAe,GAAGA,eAAe,CAACC,aAAa;EACjD;EACF;;;;;;;;;;;;"}
|
package/moj/helpers.bundle.mjs
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Element} $element - Element to remove attribute value from
|
|
3
|
+
* @param {string} attr - Attribute name
|
|
4
|
+
* @param {string} value - Attribute value
|
|
5
|
+
*/
|
|
6
|
+
function removeAttributeValue($element, attr, value) {
|
|
2
7
|
let re, m;
|
|
3
|
-
if (
|
|
4
|
-
if (
|
|
5
|
-
|
|
8
|
+
if ($element.getAttribute(attr)) {
|
|
9
|
+
if ($element.getAttribute(attr) === value) {
|
|
10
|
+
$element.removeAttribute(attr);
|
|
6
11
|
} else {
|
|
7
12
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
8
|
-
m =
|
|
13
|
+
m = $element.getAttribute(attr).match(re);
|
|
9
14
|
if (m && m.length === 3) {
|
|
10
|
-
|
|
15
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Element} $element - Element to add attribute value to
|
|
23
|
+
* @param {string} attr - Attribute name
|
|
24
|
+
* @param {string} value - Attribute value
|
|
25
|
+
*/
|
|
26
|
+
function addAttributeValue($element, attr, value) {
|
|
16
27
|
let re;
|
|
17
|
-
if (
|
|
18
|
-
|
|
28
|
+
if (!$element.getAttribute(attr)) {
|
|
29
|
+
$element.setAttribute(attr, value);
|
|
19
30
|
} else {
|
|
20
31
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
21
|
-
if (!re.test(
|
|
22
|
-
|
|
32
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
33
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
|
-
function dragAndDropSupported() {
|
|
27
|
-
const div = document.createElement('div');
|
|
28
|
-
return typeof div.ondrop !== 'undefined';
|
|
29
|
-
}
|
|
30
|
-
function formDataSupported() {
|
|
31
|
-
return typeof FormData === 'function';
|
|
32
|
-
}
|
|
33
|
-
function fileApiSupported() {
|
|
34
|
-
const input = document.createElement('input');
|
|
35
|
-
input.type = 'file';
|
|
36
|
-
return typeof input.files !== 'undefined';
|
|
37
|
-
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* Find an elements next sibling
|
|
@@ -125,55 +124,5 @@ function findNearestMatchingElement($element, selector) {
|
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
* Move focus to element
|
|
130
|
-
*
|
|
131
|
-
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
132
|
-
* but removes it on blur as the element doesn't need to be focused again.
|
|
133
|
-
*
|
|
134
|
-
* @param {HTMLElement} $element - HTML element
|
|
135
|
-
* @param {object} [options] - Handler options
|
|
136
|
-
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
137
|
-
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
138
|
-
*/
|
|
139
|
-
function setFocus($element, options = {}) {
|
|
140
|
-
const isFocusable = $element.getAttribute('tabindex');
|
|
141
|
-
if (!isFocusable) {
|
|
142
|
-
$element.setAttribute('tabindex', '-1');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Handle element focus
|
|
147
|
-
*/
|
|
148
|
-
function onFocus() {
|
|
149
|
-
$element.addEventListener('blur', onBlur, {
|
|
150
|
-
once: true
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Handle element blur
|
|
156
|
-
*/
|
|
157
|
-
function onBlur() {
|
|
158
|
-
if (options.onBlur) {
|
|
159
|
-
options.onBlur.call($element);
|
|
160
|
-
}
|
|
161
|
-
if (!isFocusable) {
|
|
162
|
-
$element.removeAttribute('tabindex');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Add listener to reset element on blur, after focus
|
|
167
|
-
$element.addEventListener('focus', onFocus, {
|
|
168
|
-
once: true
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// Focus element
|
|
172
|
-
if (options.onBeforeFocus) {
|
|
173
|
-
options.onBeforeFocus.call($element);
|
|
174
|
-
}
|
|
175
|
-
$element.focus();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export { addAttributeValue, dragAndDropSupported, fileApiSupported, findNearestMatchingElement, formDataSupported, getNextSibling, getPreviousSibling, removeAttributeValue, setFocus };
|
|
127
|
+
export { addAttributeValue, findNearestMatchingElement, getNextSibling, getPreviousSibling, removeAttributeValue };
|
|
179
128
|
//# sourceMappingURL=helpers.bundle.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.bundle.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.bundle.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getNextSibling","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;EAC1D,IAAIC,EAAE,EAAEC,CAAC;AACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;IAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;AACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;AAChC,KAAC,MAAM;AACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;MACzCE,CAAC,GAAGJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;AACzC,MAAA,IAAIC,CAAC,IAAIA,CAAC,CAACK,MAAM,KAAK,CAAC,EAAE;AACvBT,QAAAA,QAAQ,CAACU,YAAY,CACnBT,IAAI,EACJD,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACU,OAAO,CAACR,EAAE,EAAEC,CAAC,CAAC,CAAC,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,CACjE,CAAC;AACH;AACF;AACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASQ,iBAAiBA,CAACZ,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;AACvD,EAAA,IAAIC,EAAE;AACN,EAAA,IAAI,CAACH,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,E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AACA;AACA,EAAA,OAAOA,QAAQ,EAAE;IACf,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE,OAAOE,QAAQ;IAC/CA,QAAQ,GAAGA,QAAQ,CAACI,sBAAsB;AAC5C;AACF;;AAEA;AACA;AACA;AACA;AACO,SAASC,0BAA0BA,CAACtB,QAAQ,EAAEe,QAAQ,EAAE;AAC7D;EACA,IAAI,CAACf,QAAQ,IAAI,EAAEA,QAAQ,YAAYgB,WAAW,CAAC,IAAI,CAACD,QAAQ,EAAE;AAChE,IAAA;AACF;;AAEA;EACA,IAAIQ,eAAe,GAAGvB,QAAQ;AAE9B,EAAA,OAAOuB,eAAe,EAAE;AACtB;AACA,IAAA,IAAIA,eAAe,CAACJ,OAAO,CAACJ,QAAQ,CAAC,EAAE;AACrC,MAAA,OAAOQ,eAAe;AACxB;;AAEA;AACA,IAAA,IAAIN,QAAQ,GAAGM,eAAe,CAACF,sBAAsB;AACrD,IAAA,OAAOJ,QAAQ,EAAE;AACf;AACA,MAAA,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE;AAC9B,QAAA,OAAOE,QAAQ;AACjB;MACAA,QAAQ,GAAGA,QAAQ,CAACI,sBAAsB;AAC5C;;AAEA;IACAE,eAAe,GAAGA,eAAe,CAACC,aAAa;AACjD;AACF;;;;"}
|
package/moj/helpers.mjs
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Element} $element - Element to remove attribute value from
|
|
3
|
+
* @param {string} attr - Attribute name
|
|
4
|
+
* @param {string} value - Attribute value
|
|
5
|
+
*/
|
|
6
|
+
function removeAttributeValue($element, attr, value) {
|
|
2
7
|
let re, m;
|
|
3
|
-
if (
|
|
4
|
-
if (
|
|
5
|
-
|
|
8
|
+
if ($element.getAttribute(attr)) {
|
|
9
|
+
if ($element.getAttribute(attr) === value) {
|
|
10
|
+
$element.removeAttribute(attr);
|
|
6
11
|
} else {
|
|
7
12
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
8
|
-
m =
|
|
13
|
+
m = $element.getAttribute(attr).match(re);
|
|
9
14
|
if (m && m.length === 3) {
|
|
10
|
-
|
|
15
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Element} $element - Element to add attribute value to
|
|
23
|
+
* @param {string} attr - Attribute name
|
|
24
|
+
* @param {string} value - Attribute value
|
|
25
|
+
*/
|
|
26
|
+
function addAttributeValue($element, attr, value) {
|
|
16
27
|
let re;
|
|
17
|
-
if (
|
|
18
|
-
|
|
28
|
+
if (!$element.getAttribute(attr)) {
|
|
29
|
+
$element.setAttribute(attr, value);
|
|
19
30
|
} else {
|
|
20
31
|
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
21
|
-
if (!re.test(
|
|
22
|
-
|
|
32
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
33
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
|
-
function dragAndDropSupported() {
|
|
27
|
-
const div = document.createElement('div');
|
|
28
|
-
return typeof div.ondrop !== 'undefined';
|
|
29
|
-
}
|
|
30
|
-
function formDataSupported() {
|
|
31
|
-
return typeof FormData === 'function';
|
|
32
|
-
}
|
|
33
|
-
function fileApiSupported() {
|
|
34
|
-
const input = document.createElement('input');
|
|
35
|
-
input.type = 'file';
|
|
36
|
-
return typeof input.files !== 'undefined';
|
|
37
|
-
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* Find an elements preceding sibling
|
|
@@ -94,55 +93,5 @@ function findNearestMatchingElement($element, selector) {
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
* Move focus to element
|
|
99
|
-
*
|
|
100
|
-
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
101
|
-
* but removes it on blur as the element doesn't need to be focused again.
|
|
102
|
-
*
|
|
103
|
-
* @param {HTMLElement} $element - HTML element
|
|
104
|
-
* @param {object} [options] - Handler options
|
|
105
|
-
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
106
|
-
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
107
|
-
*/
|
|
108
|
-
function setFocus($element, options = {}) {
|
|
109
|
-
const isFocusable = $element.getAttribute('tabindex');
|
|
110
|
-
if (!isFocusable) {
|
|
111
|
-
$element.setAttribute('tabindex', '-1');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Handle element focus
|
|
116
|
-
*/
|
|
117
|
-
function onFocus() {
|
|
118
|
-
$element.addEventListener('blur', onBlur, {
|
|
119
|
-
once: true
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Handle element blur
|
|
125
|
-
*/
|
|
126
|
-
function onBlur() {
|
|
127
|
-
if (options.onBlur) {
|
|
128
|
-
options.onBlur.call($element);
|
|
129
|
-
}
|
|
130
|
-
if (!isFocusable) {
|
|
131
|
-
$element.removeAttribute('tabindex');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Add listener to reset element on blur, after focus
|
|
136
|
-
$element.addEventListener('focus', onFocus, {
|
|
137
|
-
once: true
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Focus element
|
|
141
|
-
if (options.onBeforeFocus) {
|
|
142
|
-
options.onBeforeFocus.call($element);
|
|
143
|
-
}
|
|
144
|
-
$element.focus();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export { addAttributeValue, dragAndDropSupported, fileApiSupported, findNearestMatchingElement, formDataSupported, getPreviousSibling, removeAttributeValue, setFocus };
|
|
96
|
+
export { addAttributeValue, findNearestMatchingElement, getPreviousSibling, removeAttributeValue };
|
|
148
97
|
//# sourceMappingURL=helpers.mjs.map
|
package/moj/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getPreviousSibling","selector","HTMLElement","$sibling","previousElementSibling","matches","findNearestMatchingElement","$currentElement","parentElement"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;EAC1D,IAAIC,EAAE,EAAEC,CAAC;AACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;IAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;AACzCF,MAAAA,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