@ministryofjustice/frontend 4.0.1 → 5.1.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 (256) hide show
  1. package/govuk-prototype-kit.config.json +19 -4
  2. package/moj/_base.scss +2 -0
  3. package/moj/_base.scss.map +1 -0
  4. package/moj/all.bundle.js +3010 -0
  5. package/moj/all.bundle.js.map +1 -0
  6. package/moj/all.bundle.mjs +3293 -0
  7. package/moj/all.bundle.mjs.map +1 -0
  8. package/moj/all.mjs +17 -110
  9. package/moj/all.mjs.map +1 -1
  10. package/moj/all.scss +3 -0
  11. package/moj/all.scss.map +1 -0
  12. package/moj/common/index.mjs +57 -0
  13. package/moj/common/index.mjs.map +1 -0
  14. package/moj/common/moj-frontend-version.mjs +14 -0
  15. package/moj/common/moj-frontend-version.mjs.map +1 -0
  16. package/moj/components/_all.scss +2 -0
  17. package/moj/components/_all.scss.map +1 -0
  18. package/moj/components/action-bar/_action-bar.scss +2 -0
  19. package/moj/components/action-bar/_action-bar.scss.map +1 -0
  20. package/moj/components/add-another/_add-another.scss +2 -0
  21. package/moj/components/add-another/_add-another.scss.map +1 -0
  22. package/moj/components/add-another/add-another.bundle.js +157 -0
  23. package/moj/components/add-another/add-another.bundle.js.map +1 -0
  24. package/moj/components/add-another/add-another.bundle.mjs +271 -0
  25. package/moj/components/add-another/add-another.bundle.mjs.map +1 -0
  26. package/moj/components/add-another/add-another.mjs +135 -91
  27. package/moj/components/add-another/add-another.mjs.map +1 -1
  28. package/moj/components/alert/_alert.scss +4 -0
  29. package/moj/components/alert/_alert.scss.map +1 -0
  30. package/moj/components/alert/alert.bundle.js +254 -0
  31. package/moj/components/alert/alert.bundle.js.map +1 -0
  32. package/moj/components/alert/alert.bundle.mjs +490 -0
  33. package/moj/components/alert/alert.bundle.mjs.map +1 -0
  34. package/moj/components/alert/alert.mjs +97 -218
  35. package/moj/components/alert/alert.mjs.map +1 -1
  36. package/moj/components/alert/{alert.spec.helper.js → alert.spec.helper.bundle.js} +1 -1
  37. package/moj/components/alert/alert.spec.helper.bundle.js.map +1 -0
  38. package/moj/components/alert/alert.spec.helper.bundle.mjs +67 -0
  39. package/moj/components/alert/alert.spec.helper.bundle.mjs.map +1 -0
  40. package/moj/components/alert/alert.spec.helper.mjs.map +1 -1
  41. package/moj/components/badge/_badge.scss +2 -0
  42. package/moj/components/badge/_badge.scss.map +1 -0
  43. package/moj/components/banner/_banner.scss +2 -0
  44. package/moj/components/banner/_banner.scss.map +1 -0
  45. package/moj/components/button-menu/README.md +12 -6
  46. package/moj/components/button-menu/_button-menu.scss +4 -1
  47. package/moj/components/button-menu/_button-menu.scss.map +1 -0
  48. package/moj/components/button-menu/button-menu.bundle.js +270 -0
  49. package/moj/components/button-menu/button-menu.bundle.js.map +1 -0
  50. package/moj/components/button-menu/button-menu.bundle.mjs +506 -0
  51. package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -0
  52. package/moj/components/button-menu/button-menu.mjs +214 -280
  53. package/moj/components/button-menu/button-menu.mjs.map +1 -1
  54. package/moj/components/cookie-banner/_cookie-banner.scss +2 -0
  55. package/moj/components/cookie-banner/_cookie-banner.scss.map +1 -0
  56. package/moj/components/currency-input/_currency-input.scss +2 -0
  57. package/moj/components/currency-input/_currency-input.scss.map +1 -0
  58. package/moj/components/date-picker/_date-picker.scss +2 -0
  59. package/moj/components/date-picker/_date-picker.scss.map +1 -0
  60. package/moj/components/date-picker/date-picker.bundle.js +804 -0
  61. package/moj/components/date-picker/date-picker.bundle.js.map +1 -0
  62. package/moj/components/date-picker/date-picker.bundle.mjs +1040 -0
  63. package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -0
  64. package/moj/components/date-picker/date-picker.mjs +663 -827
  65. package/moj/components/date-picker/date-picker.mjs.map +1 -1
  66. package/moj/components/filter/_filter.scss +2 -0
  67. package/moj/components/filter/_filter.scss.map +1 -0
  68. package/moj/components/filter/template.njk +1 -1
  69. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +185 -0
  70. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -0
  71. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +421 -0
  72. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -0
  73. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +166 -81
  74. package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
  75. package/moj/components/form-validator/form-validator.bundle.js +288 -0
  76. package/moj/components/form-validator/form-validator.bundle.js.map +1 -0
  77. package/moj/components/form-validator/form-validator.bundle.mjs +524 -0
  78. package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -0
  79. package/moj/components/form-validator/form-validator.mjs +226 -149
  80. package/moj/components/form-validator/form-validator.mjs.map +1 -1
  81. package/moj/components/header/_header.scss +2 -0
  82. package/moj/components/header/_header.scss.map +1 -0
  83. package/moj/components/identity-bar/_identity-bar.scss +2 -0
  84. package/moj/components/identity-bar/_identity-bar.scss.map +1 -0
  85. package/moj/components/interruption-card/_interruption-card.scss +2 -0
  86. package/moj/components/interruption-card/_interruption-card.scss.map +1 -0
  87. package/moj/components/messages/_messages.scss +2 -0
  88. package/moj/components/messages/_messages.scss.map +1 -0
  89. package/moj/components/multi-file-upload/_multi-file-upload.scss +2 -0
  90. package/moj/components/multi-file-upload/_multi-file-upload.scss.map +1 -0
  91. package/moj/components/multi-file-upload/multi-file-upload.bundle.js +397 -0
  92. package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -0
  93. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +633 -0
  94. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -0
  95. package/moj/components/multi-file-upload/multi-file-upload.mjs +384 -213
  96. package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
  97. package/moj/components/multi-file-upload/template.njk +1 -1
  98. package/moj/components/multi-select/_multi-select.scss +2 -0
  99. package/moj/components/multi-select/_multi-select.scss.map +1 -0
  100. package/moj/components/multi-select/multi-select.bundle.js +143 -0
  101. package/moj/components/multi-select/multi-select.bundle.js.map +1 -0
  102. package/moj/components/multi-select/multi-select.bundle.mjs +379 -0
  103. package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -0
  104. package/moj/components/multi-select/multi-select.mjs +123 -64
  105. package/moj/components/multi-select/multi-select.mjs.map +1 -1
  106. package/moj/components/notification-badge/_notification-badge.scss +2 -0
  107. package/moj/components/notification-badge/_notification-badge.scss.map +1 -0
  108. package/moj/components/organisation-switcher/_organisation-switcher.scss +2 -0
  109. package/moj/components/organisation-switcher/_organisation-switcher.scss.map +1 -0
  110. package/moj/components/page-header-actions/_page-header-actions.scss +2 -0
  111. package/moj/components/page-header-actions/_page-header-actions.scss.map +1 -0
  112. package/moj/components/pagination/_pagination.scss +2 -2
  113. package/moj/components/pagination/_pagination.scss.map +1 -0
  114. package/moj/components/password-reveal/_password-reveal.scss +5 -1
  115. package/moj/components/password-reveal/_password-reveal.scss.map +1 -0
  116. package/moj/components/password-reveal/password-reveal.bundle.js +52 -0
  117. package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -0
  118. package/moj/components/password-reveal/password-reveal.bundle.mjs +166 -0
  119. package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -0
  120. package/moj/components/password-reveal/password-reveal.mjs +39 -29
  121. package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
  122. package/moj/components/primary-navigation/_primary-navigation.scss +2 -0
  123. package/moj/components/primary-navigation/_primary-navigation.scss.map +1 -0
  124. package/moj/components/progress-bar/_progress-bar.scss +2 -0
  125. package/moj/components/progress-bar/_progress-bar.scss.map +1 -0
  126. package/moj/components/rich-text-editor/README.md +16 -9
  127. package/moj/components/rich-text-editor/_rich-text-editor.scss +2 -0
  128. package/moj/components/rich-text-editor/_rich-text-editor.scss.map +1 -0
  129. package/moj/components/rich-text-editor/rich-text-editor.bundle.js +210 -0
  130. package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -0
  131. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +446 -0
  132. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -0
  133. package/moj/components/rich-text-editor/rich-text-editor.mjs +186 -140
  134. package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
  135. package/moj/components/search/_search.scss +2 -0
  136. package/moj/components/search/_search.scss.map +1 -0
  137. package/moj/components/search-toggle/{search-toggle.scss → _search-toggle.scss} +2 -0
  138. package/moj/components/search-toggle/_search-toggle.scss.map +1 -0
  139. package/moj/components/search-toggle/search-toggle.bundle.js +122 -0
  140. package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -0
  141. package/moj/components/search-toggle/search-toggle.bundle.mjs +358 -0
  142. package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -0
  143. package/moj/components/search-toggle/search-toggle.mjs +104 -43
  144. package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
  145. package/moj/components/side-navigation/_side-navigation.scss +2 -0
  146. package/moj/components/side-navigation/_side-navigation.scss.map +1 -0
  147. package/moj/components/sortable-table/_sortable-table.scss +2 -2
  148. package/moj/components/sortable-table/_sortable-table.scss.map +1 -0
  149. package/moj/components/sortable-table/sortable-table.bundle.js +202 -0
  150. package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -0
  151. package/moj/components/sortable-table/sortable-table.bundle.mjs +438 -0
  152. package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -0
  153. package/moj/components/sortable-table/sortable-table.mjs +179 -122
  154. package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
  155. package/moj/components/sub-navigation/_sub-navigation.scss +2 -0
  156. package/moj/components/sub-navigation/_sub-navigation.scss.map +1 -0
  157. package/moj/components/tag/_tag.scss +2 -0
  158. package/moj/components/tag/_tag.scss.map +1 -0
  159. package/moj/components/task-list/_task-list.scss +2 -0
  160. package/moj/components/task-list/_task-list.scss.map +1 -0
  161. package/moj/components/ticket-panel/_ticket-panel.scss +2 -0
  162. package/moj/components/ticket-panel/_ticket-panel.scss.map +1 -0
  163. package/moj/components/timeline/_timeline.scss +2 -0
  164. package/moj/components/timeline/_timeline.scss.map +1 -0
  165. package/moj/core/_all.scss +3 -0
  166. package/moj/core/_all.scss.map +1 -0
  167. package/moj/core/_moj-frontend-properties.scss +7 -0
  168. package/moj/core/_moj-frontend-properties.scss.map +1 -0
  169. package/moj/filters/all.js +44 -22
  170. package/moj/filters/prototype-kit-13-filters.js +4 -3
  171. package/moj/helpers/_all.scss +2 -0
  172. package/moj/helpers/_all.scss.map +1 -0
  173. package/moj/helpers/_hidden.scss +2 -0
  174. package/moj/helpers/_hidden.scss.map +1 -0
  175. package/moj/helpers/_links.scss +2 -0
  176. package/moj/helpers/_links.scss.map +1 -0
  177. package/moj/helpers.bundle.js +140 -0
  178. package/moj/helpers.bundle.js.map +1 -0
  179. package/moj/helpers.bundle.mjs +128 -0
  180. package/moj/helpers.bundle.mjs.map +1 -0
  181. package/moj/helpers.mjs +50 -77
  182. package/moj/helpers.mjs.map +1 -1
  183. package/moj/init.js +11 -2
  184. package/moj/moj-frontend.min.css +1 -1
  185. package/moj/moj-frontend.min.css.map +1 -1
  186. package/moj/moj-frontend.min.js +1 -1
  187. package/moj/moj-frontend.min.js.map +1 -1
  188. package/moj/objects/_all.scss +2 -0
  189. package/moj/objects/_all.scss.map +1 -0
  190. package/moj/objects/_button-group.scss +2 -0
  191. package/moj/objects/_button-group.scss.map +1 -0
  192. package/moj/objects/_filter-layout.scss +2 -0
  193. package/moj/objects/_filter-layout.scss.map +1 -0
  194. package/moj/objects/_scrollable-pane.scss +2 -0
  195. package/moj/objects/_scrollable-pane.scss.map +1 -0
  196. package/moj/objects/_width-container.scss +2 -0
  197. package/moj/objects/_width-container.scss.map +1 -0
  198. package/moj/settings/_all.scss +2 -0
  199. package/moj/settings/_all.scss.map +1 -0
  200. package/moj/settings/_assets.scss +2 -0
  201. package/moj/settings/_assets.scss.map +1 -0
  202. package/moj/settings/_colours.scss +2 -0
  203. package/moj/settings/_colours.scss.map +1 -0
  204. package/moj/settings/_measurements.scss +2 -0
  205. package/moj/settings/_measurements.scss.map +1 -0
  206. package/moj/settings/_typography.scss +2 -0
  207. package/moj/settings/_typography.scss.map +1 -0
  208. package/moj/template.njk +13 -0
  209. package/moj/utilities/_all.scss +2 -0
  210. package/moj/utilities/_all.scss.map +1 -0
  211. package/moj/utilities/_hidden.scss +2 -0
  212. package/moj/utilities/_hidden.scss.map +1 -0
  213. package/moj/utilities/_width-container.scss +2 -0
  214. package/moj/utilities/_width-container.scss.map +1 -0
  215. package/moj/vendor/govuk-frontend/_base.scss +2 -0
  216. package/moj/vendor/govuk-frontend/_base.scss.map +1 -0
  217. package/moj/vendor/govuk-frontend/_index.scss +2 -0
  218. package/moj/vendor/govuk-frontend/_index.scss.map +1 -0
  219. package/package.json +5 -6
  220. package/moj/all.jquery.min.js +0 -1
  221. package/moj/all.jquery.min.js.map +0 -1
  222. package/moj/all.js +0 -2662
  223. package/moj/all.js.map +0 -1
  224. package/moj/components/add-another/add-another.js +0 -115
  225. package/moj/components/add-another/add-another.js.map +0 -1
  226. package/moj/components/alert/alert.js +0 -356
  227. package/moj/components/alert/alert.js.map +0 -1
  228. package/moj/components/alert/alert.spec.helper.js.map +0 -1
  229. package/moj/components/button-menu/button-menu.js +0 -338
  230. package/moj/components/button-menu/button-menu.js.map +0 -1
  231. package/moj/components/date-picker/date-picker.js +0 -970
  232. package/moj/components/date-picker/date-picker.js.map +0 -1
  233. package/moj/components/filter-toggle-button/filter-toggle-button.js +0 -102
  234. package/moj/components/filter-toggle-button/filter-toggle-button.js.map +0 -1
  235. package/moj/components/form-validator/form-validator.js +0 -205
  236. package/moj/components/form-validator/form-validator.js.map +0 -1
  237. package/moj/components/multi-file-upload/multi-file-upload.js +0 -241
  238. package/moj/components/multi-file-upload/multi-file-upload.js.map +0 -1
  239. package/moj/components/multi-select/multi-select.js +0 -86
  240. package/moj/components/multi-select/multi-select.js.map +0 -1
  241. package/moj/components/password-reveal/password-reveal.js +0 -44
  242. package/moj/components/password-reveal/password-reveal.js.map +0 -1
  243. package/moj/components/rich-text-editor/rich-text-editor.js +0 -166
  244. package/moj/components/rich-text-editor/rich-text-editor.js.map +0 -1
  245. package/moj/components/search-toggle/search-toggle.js +0 -63
  246. package/moj/components/search-toggle/search-toggle.js.map +0 -1
  247. package/moj/components/sortable-table/sortable-table.js +0 -147
  248. package/moj/components/sortable-table/sortable-table.js.map +0 -1
  249. package/moj/helpers.js +0 -200
  250. package/moj/helpers.js.map +0 -1
  251. package/moj/vendor/html5shiv.js +0 -326
  252. package/moj/vendor/jquery.js +0 -9300
  253. package/moj/version.js +0 -12
  254. package/moj/version.js.map +0 -1
  255. package/moj/version.mjs +0 -4
  256. package/moj/version.mjs.map +0 -1
@@ -1,63 +0,0 @@
1
- (function (global, factory) {
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 SearchToggle(options) {
8
- this.options = options;
9
- this.container = $(this.options.search.container);
10
- this.toggleButtonContainer = $(this.options.toggleButton.container);
11
-
12
- if (this.container.data('moj-search-toggle-initialised')) {
13
- return
14
- }
15
-
16
- this.container.data('moj-search-toggle-initialised', true);
17
-
18
- const svg =
19
- '<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>';
20
-
21
- this.toggleButton = $(
22
- `<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
23
- ${this.options.toggleButton.text} ${svg}
24
- </button>`
25
- );
26
- this.toggleButton.on('click', $.proxy(this, 'onToggleButtonClick'));
27
- this.toggleButtonContainer.append(this.toggleButton);
28
- $(document).on('click', this.onDocumentClick.bind(this));
29
- $(document).on('focusin', this.onDocumentClick.bind(this));
30
- }
31
-
32
- SearchToggle.prototype.showMenu = function () {
33
- this.toggleButton.attr('aria-expanded', 'true');
34
- this.container.removeClass('moj-js-hidden');
35
- this.container.find('input').first().get(0).focus();
36
- };
37
-
38
- SearchToggle.prototype.hideMenu = function () {
39
- this.container.addClass('moj-js-hidden');
40
- this.toggleButton.attr('aria-expanded', 'false');
41
- };
42
-
43
- SearchToggle.prototype.onToggleButtonClick = function () {
44
- if (this.toggleButton.attr('aria-expanded') === 'false') {
45
- this.showMenu();
46
- } else {
47
- this.hideMenu();
48
- }
49
- };
50
-
51
- SearchToggle.prototype.onDocumentClick = function (e) {
52
- if (
53
- !$.contains(this.toggleButtonContainer[0], e.target) &&
54
- !$.contains(this.container[0], e.target)
55
- ) {
56
- this.hideMenu();
57
- }
58
- };
59
-
60
- exports.SearchToggle = SearchToggle;
61
-
62
- }));
63
- //# sourceMappingURL=search-toggle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search-toggle.js","sources":["../../../../src/moj/components/search-toggle/search-toggle.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function SearchToggle(options) {\n this.options = options\n this.container = $(this.options.search.container)\n this.toggleButtonContainer = $(this.options.toggleButton.container)\n\n if (this.container.data('moj-search-toggle-initialised')) {\n return\n }\n\n this.container.data('moj-search-toggle-initialised', true)\n\n const svg =\n '<svg viewBox=\"0 0 20 20\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" class=\"moj-search-toggle__button__icon\"><path d=\"M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z\"></path></svg>'\n\n this.toggleButton = $(\n `<button class=\"moj-search-toggle__button\" type=\"button\" aria-haspopup=\"true\" aria-expanded=\"false\">\n ${this.options.toggleButton.text} ${svg}\n </button>`\n )\n this.toggleButton.on('click', $.proxy(this, 'onToggleButtonClick'))\n this.toggleButtonContainer.append(this.toggleButton)\n $(document).on('click', this.onDocumentClick.bind(this))\n $(document).on('focusin', this.onDocumentClick.bind(this))\n}\n\nSearchToggle.prototype.showMenu = function () {\n this.toggleButton.attr('aria-expanded', 'true')\n this.container.removeClass('moj-js-hidden')\n this.container.find('input').first().get(0).focus()\n}\n\nSearchToggle.prototype.hideMenu = function () {\n this.container.addClass('moj-js-hidden')\n this.toggleButton.attr('aria-expanded', 'false')\n}\n\nSearchToggle.prototype.onToggleButtonClick = function () {\n if (this.toggleButton.attr('aria-expanded') === 'false') {\n this.showMenu()\n } else {\n this.hideMenu()\n }\n}\n\nSearchToggle.prototype.onDocumentClick = function (e) {\n if (\n !$.contains(this.toggleButtonContainer[0], e.target) &&\n !$.contains(this.container[0], e.target)\n ) {\n this.hideMenu()\n }\n}\n"],"names":[],"mappings":";;;;;;EAEA,SAAA,YAAA,CAAA,OAAA,EAAA;EACA,EAAA,IAAA,CAAA,OAAA,GAAA;EACA,EAAA,IAAA,CAAA,SAAA,GAAA,CAAA,CAAA,IAAA,CAAA,OAAA,CAAA,MAAA,CAAA,SAAA;EACA,EAAA,IAAA,CAAA,qBAAA,GAAA,CAAA,CAAA,IAAA,CAAA,OAAA,CAAA,YAAA,CAAA,SAAA;;EAEA,EAAA,IAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,+BAAA,CAAA,EAAA;EACA,IAAA;EACA;;EAEA,EAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,+BAAA,EAAA,IAAA;;EAEA,EAAA,MAAA,GAAA;EACA,IAAA;;EAEA,EAAA,IAAA,CAAA,YAAA,GAAA,CAAA;EACA,IAAA,CAAA;AACA,MAAA,EAAA,IAAA,CAAA,OAAA,CAAA,YAAA,CAAA,IAAA,CAAA,CAAA,EAAA,GAAA;AACA,aAAA;EAC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,CAAA,EAAA,CAAA,CAAA,MAAA,CAAA;EACA,IAAA,CAAA,CAAA,CAAA,QAAA,CAAA,IAAA,CAAA,SAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,MAAA;EACA,IAAA;EACA,IAAA,IAAA,CAAA,QAAA;EACA;EACA;;;;;;;;"}
@@ -1,147 +0,0 @@
1
- (function (global, factory) {
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 SortableTable(params) {
8
- this.table = $(params.table);
9
-
10
- if (this.table.data('moj-search-toggle-initialised')) {
11
- return
12
- }
13
-
14
- this.table.data('moj-search-toggle-initialised', true);
15
-
16
- this.setupOptions(params);
17
- this.body = this.table.find('tbody');
18
- this.createHeadingButtons();
19
- this.createStatusBox();
20
- this.initialiseSortedColumn();
21
- this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'));
22
- }
23
-
24
- SortableTable.prototype.setupOptions = function (params) {
25
- params = params || {};
26
- this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)';
27
- this.ascendingText = params.ascendingText || 'ascending';
28
- this.descendingText = params.descendingText || 'descending';
29
- };
30
-
31
- SortableTable.prototype.createHeadingButtons = function () {
32
- const headings = this.table.find('thead th');
33
- let heading;
34
- for (let i = 0; i < headings.length; i++) {
35
- heading = $(headings[i]);
36
- if (heading.attr('aria-sort')) {
37
- this.createHeadingButton(heading, i);
38
- }
39
- }
40
- };
41
-
42
- SortableTable.prototype.createHeadingButton = function (heading, i) {
43
- const text = heading.text();
44
- const button = $(`<button type="button" data-index="${i}">${text}</button>`);
45
- heading.text('');
46
- heading.append(button);
47
- };
48
-
49
- SortableTable.prototype.createStatusBox = function () {
50
- this.status = $(
51
- '<div aria-live="polite" role="status" aria-atomic="true" class="govuk-visually-hidden" />'
52
- );
53
- this.table.parent().append(this.status);
54
- };
55
-
56
- SortableTable.prototype.initialiseSortedColumn = function () {
57
- const rows = this.getTableRowsArray();
58
-
59
- this.table
60
- .find('th')
61
- .filter('[aria-sort="ascending"], [aria-sort="descending"]')
62
- .first()
63
- .each((index, el) => {
64
- const sortDirection = $(el).attr('aria-sort');
65
- const columnNumber = $(el).find('button').attr('data-index');
66
- const sortedRows = this.sort(rows, columnNumber, sortDirection);
67
- this.addRows(sortedRows);
68
- });
69
- };
70
-
71
- SortableTable.prototype.onSortButtonClick = function (e) {
72
- const columnNumber = e.currentTarget.getAttribute('data-index');
73
- const sortDirection = $(e.currentTarget).parent().attr('aria-sort');
74
- let newSortDirection;
75
- if (sortDirection === 'none' || sortDirection === 'descending') {
76
- newSortDirection = 'ascending';
77
- } else {
78
- newSortDirection = 'descending';
79
- }
80
- const rows = this.getTableRowsArray();
81
- const sortedRows = this.sort(rows, columnNumber, newSortDirection);
82
- this.addRows(sortedRows);
83
- this.removeButtonStates();
84
- this.updateButtonState($(e.currentTarget), newSortDirection);
85
- };
86
-
87
- SortableTable.prototype.updateButtonState = function (button, direction) {
88
- button.parent().attr('aria-sort', direction);
89
- let message = this.statusMessage;
90
- message = message.replace(/%heading%/, button.text());
91
- message = message.replace(/%direction%/, this[`${direction}Text`]);
92
- this.status.text(message);
93
- };
94
-
95
- SortableTable.prototype.removeButtonStates = function () {
96
- this.table.find('thead th').attr('aria-sort', 'none');
97
- };
98
-
99
- SortableTable.prototype.addRows = function (rows) {
100
- for (let i = 0; i < rows.length; i++) {
101
- this.body.append(rows[i]);
102
- }
103
- };
104
-
105
- SortableTable.prototype.getTableRowsArray = function () {
106
- const rows = [];
107
- const trs = this.body.find('tr');
108
- for (let i = 0; i < trs.length; i++) {
109
- rows.push(trs[i]);
110
- }
111
- return rows
112
- };
113
-
114
- SortableTable.prototype.sort = function (rows, columnNumber, sortDirection) {
115
- const newRows = rows.sort(
116
- function (rowA, rowB) {
117
- const tdA = $(rowA).find('td,th').eq(columnNumber);
118
- const tdB = $(rowB).find('td,th').eq(columnNumber);
119
-
120
- const valueA =
121
- sortDirection === 'ascending'
122
- ? this.getCellValue(tdA)
123
- : this.getCellValue(tdB);
124
- const valueB =
125
- sortDirection === 'ascending'
126
- ? this.getCellValue(tdB)
127
- : this.getCellValue(tdA);
128
-
129
- if (typeof valueA === 'string' || typeof valueB === 'string')
130
- return valueA.toString().localeCompare(valueB.toString())
131
- return valueA - valueB
132
- }.bind(this)
133
- );
134
- return newRows
135
- };
136
-
137
- SortableTable.prototype.getCellValue = function (cell) {
138
- const val = cell.attr('data-sort-value') || cell.html();
139
-
140
- const valAsNumber = Number(val);
141
- return isNaN(valAsNumber) ? val : valAsNumber
142
- };
143
-
144
- exports.SortableTable = SortableTable;
145
-
146
- }));
147
- //# sourceMappingURL=sortable-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sortable-table.js","sources":["../../../../src/moj/components/sortable-table/sortable-table.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function SortableTable(params) {\n this.table = $(params.table)\n\n if (this.table.data('moj-search-toggle-initialised')) {\n return\n }\n\n this.table.data('moj-search-toggle-initialised', true)\n\n this.setupOptions(params)\n this.body = this.table.find('tbody')\n this.createHeadingButtons()\n this.createStatusBox()\n this.initialiseSortedColumn()\n this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'))\n}\n\nSortableTable.prototype.setupOptions = function (params) {\n params = params || {}\n this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)'\n this.ascendingText = params.ascendingText || 'ascending'\n this.descendingText = params.descendingText || 'descending'\n}\n\nSortableTable.prototype.createHeadingButtons = function () {\n const headings = this.table.find('thead th')\n let heading\n for (let i = 0; i < headings.length; i++) {\n heading = $(headings[i])\n if (heading.attr('aria-sort')) {\n this.createHeadingButton(heading, i)\n }\n }\n}\n\nSortableTable.prototype.createHeadingButton = function (heading, i) {\n const text = heading.text()\n const button = $(`<button type=\"button\" data-index=\"${i}\">${text}</button>`)\n heading.text('')\n heading.append(button)\n}\n\nSortableTable.prototype.createStatusBox = function () {\n this.status = $(\n '<div aria-live=\"polite\" role=\"status\" aria-atomic=\"true\" class=\"govuk-visually-hidden\" />'\n )\n this.table.parent().append(this.status)\n}\n\nSortableTable.prototype.initialiseSortedColumn = function () {\n const rows = this.getTableRowsArray()\n\n this.table\n .find('th')\n .filter('[aria-sort=\"ascending\"], [aria-sort=\"descending\"]')\n .first()\n .each((index, el) => {\n const sortDirection = $(el).attr('aria-sort')\n const columnNumber = $(el).find('button').attr('data-index')\n const sortedRows = this.sort(rows, columnNumber, sortDirection)\n this.addRows(sortedRows)\n })\n}\n\nSortableTable.prototype.onSortButtonClick = function (e) {\n const columnNumber = e.currentTarget.getAttribute('data-index')\n const sortDirection = $(e.currentTarget).parent().attr('aria-sort')\n let newSortDirection\n if (sortDirection === 'none' || sortDirection === 'descending') {\n newSortDirection = 'ascending'\n } else {\n newSortDirection = 'descending'\n }\n const rows = this.getTableRowsArray()\n const sortedRows = this.sort(rows, columnNumber, newSortDirection)\n this.addRows(sortedRows)\n this.removeButtonStates()\n this.updateButtonState($(e.currentTarget), newSortDirection)\n}\n\nSortableTable.prototype.updateButtonState = function (button, direction) {\n button.parent().attr('aria-sort', direction)\n let message = this.statusMessage\n message = message.replace(/%heading%/, button.text())\n message = message.replace(/%direction%/, this[`${direction}Text`])\n this.status.text(message)\n}\n\nSortableTable.prototype.removeButtonStates = function () {\n this.table.find('thead th').attr('aria-sort', 'none')\n}\n\nSortableTable.prototype.addRows = function (rows) {\n for (let i = 0; i < rows.length; i++) {\n this.body.append(rows[i])\n }\n}\n\nSortableTable.prototype.getTableRowsArray = function () {\n const rows = []\n const trs = this.body.find('tr')\n for (let i = 0; i < trs.length; i++) {\n rows.push(trs[i])\n }\n return rows\n}\n\nSortableTable.prototype.sort = function (rows, columnNumber, sortDirection) {\n const newRows = rows.sort(\n function (rowA, rowB) {\n const tdA = $(rowA).find('td,th').eq(columnNumber)\n const tdB = $(rowB).find('td,th').eq(columnNumber)\n\n const valueA =\n sortDirection === 'ascending'\n ? this.getCellValue(tdA)\n : this.getCellValue(tdB)\n const valueB =\n sortDirection === 'ascending'\n ? this.getCellValue(tdB)\n : this.getCellValue(tdA)\n\n if (typeof valueA === 'string' || typeof valueB === 'string')\n return valueA.toString().localeCompare(valueB.toString())\n return valueA - valueB\n }.bind(this)\n )\n return newRows\n}\n\nSortableTable.prototype.getCellValue = function (cell) {\n const val = cell.attr('data-sort-value') || cell.html()\n\n const valAsNumber = Number(val)\n return isNaN(valAsNumber) ? val : valAsNumber\n}\n"],"names":[],"mappings":";;;;;;EAEA,SAAA,aAAA,CAAA,MAAA,EAAA;EACA,EAAA,IAAA,CAAA,KAAA,GAAA,CAAA,CAAA,MAAA,CAAA,KAAA;;EAEA,EAAA,IAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,+BAAA,CAAA,EAAA;EACA,IAAA;EACA;;EAEA,EAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,+BAAA,EAAA,IAAA;;EAEA,EAAA,IAAA,CAAA,YAAA,CAAA,MAAA;EACA,EAAA,IAAA,CAAA,IAAA,GAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,OAAA;EACA,EAAA,IAAA,CAAA,oBAAA;EACA,EAAA,IAAA,CAAA,eAAA;EACA,EAAA,IAAA,CAAA,sBAAA;EACA,EAAA,IAAA,CAAA,KAAA,CAAA,EAAA,CAAA,OAAA,EAAA,WAAA,EAAA,CAAA,CAAA,KAAA,CAAA,IAAA,EAAA,mBAAA,CAAA;EACA;;EAEA,aAAA,CAAA,SAAA,CAAA,YAAA,GAAA,UAAA,MAAA,EAAA;EACA,EAAA,MAAA,GAAA,MAAA,IAAA;EACA,EAAA,IAAA,CAAA,aAAA,GAAA,MAAA,CAAA,aAAA,IAAA;EACA,EAAA,IAAA,CAAA,aAAA,GAAA,MAAA,CAAA,aAAA,IAAA;EACA,EAAA,IAAA,CAAA,cA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A,MAAA,GAAA,GAAA,CAAA,CAAA,IAAA,CAAA,CAAA,IAAA,CAAA,OAAA,CAAA,CAAA,EAAA,CAAA,YAAA;;EAEA,MAAA,MAAA,MAAA;EACA,QAAA,aAAA,KAAA;EACA,YAAA,IAAA,CAAA,YAAA,CAAA,GAAA;EACA,YAAA,IAAA,CAAA,YAAA,CAAA,GAAA;EACA,MAAA,MAAA,MAAA;EACA,QAAA,aAAA,KAAA;EACA,YAAA,IAAA,CAAA,YAAA,CAAA,GAAA;EACA,YAAA,IAAA,CAAA,YAAA,CAAA,GAAA;;EAEA,MAAA,IAAA,OAAA,MAAA,KAAA,QAAA,IAAA,OAAA,MAAA,KAAA,QAAA;EACA,QAAA,OAAA,MAAA,CAAA,QAAA,EAAA,CAAA,aAAA,CAAA,MAAA,CAAA,QAAA,EAAA;EACA,MAAA,OAAA,MAAA,GAAA;EACA,KAAA,CAAA,IAAA,CAAA,IAAA;EACA;EACA,EAAA,OAAA;EACA;;EAEA,aAAA,CAAA,SAAA,CAAA,YAAA,GAAA,UAAA,IAAA,EAAA;EACA,EAAA,MAAA,GAAA,GAAA,IAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,IAAA,IAAA,CAAA,IAAA;;EAEA,EAAA,MAAA,WAAA,GAAA,MAAA,CAAA,GAAA;EACA,EAAA,OAAA,KAAA,CAAA,WAAA,CAAA,GAAA,GAAA,GAAA;EACA;;;;;;;;"}
package/moj/helpers.js DELETED
@@ -1,200 +0,0 @@
1
- (function (global, factory) {
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;
198
-
199
- }));
200
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["export function removeAttributeValue(el, attr, value) {\n let re, m\n if (el.getAttribute(attr)) {\n if (el.getAttribute(attr) === value) {\n el.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = el.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n el.setAttribute(\n attr,\n el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\nexport function addAttributeValue(el, attr, value) {\n let re\n if (!el.getAttribute(attr)) {\n el.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test(el.getAttribute(attr))) {\n el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`)\n }\n }\n}\n\nexport function dragAndDropSupported() {\n const div = document.createElement('div')\n return typeof div.ondrop !== 'undefined'\n}\n\nexport function formDataSupported() {\n return typeof FormData === 'function'\n}\n\nexport function fileApiSupported() {\n const input = document.createElement('input')\n input.type = 'file'\n return typeof input.files !== 'undefined'\n}\n\nexport function nodeListForEach(nodes, callback) {\n if (window.NodeList.prototype.forEach) {\n return nodes.forEach(callback)\n }\n for (let i = 0; i < nodes.length; i++) {\n callback.call(window, nodes[i], i, nodes)\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 {HTMLElement} $element - Element to find siblings for\n * @param {string} selector - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element) return\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 {HTMLElement} $element - Element to find siblings for\n * @param {string} selector - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element) return\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\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return null\n if (!$element) return\n if (!selector) return\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\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @param {HTMLElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n if (options.onBlur) {\n options.onBlur.call($element)\n }\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n if (options.onBeforeFocus) {\n options.onBeforeFocus.call($element)\n }\n $element.focus()\n}\n"],"names":[],"mappings":";;;;;;EAAO,SAAS,oBAAoB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;EACtD,EAAE,IAAI,EAAE,EAAE;EACV,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;EAC7B,IAAI,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE;EACzC,MAAM,EAAE,CAAC,eAAe,CAAC,IAAI;EAC7B,KAAK,MAAM;EACX,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;EAC9C,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE;EACxC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;EAC/B,QAAQ,EAAE,CAAC,YAAY;EACvB,UAAU,IAAI;EACd,UAAU,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAA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