govuk_publishing_components 60.1.0 → 60.2.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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +11 -1
  4. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +0 -14
  5. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +570 -595
  6. data/app/views/govuk_publishing_components/audit/_applications.html.erb +13 -13
  7. data/app/views/govuk_publishing_components/audit/_component_contents.html.erb +2 -2
  8. data/app/views/govuk_publishing_components/audit/_components.html.erb +17 -19
  9. data/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb +3 -3
  10. data/app/views/govuk_publishing_components/audit/show.html.erb +5 -6
  11. data/app/views/govuk_publishing_components/component_guide/component_doc/_call.html.erb +2 -2
  12. data/app/views/govuk_publishing_components/component_guide/example.html.erb +4 -5
  13. data/app/views/govuk_publishing_components/component_guide/index.html.erb +9 -10
  14. data/app/views/govuk_publishing_components/component_guide/preview.html.erb +1 -1
  15. data/app/views/govuk_publishing_components/component_guide/show.html.erb +9 -10
  16. data/app/views/govuk_publishing_components/components/_accordion.html.erb +5 -5
  17. data/app/views/govuk_publishing_components/components/_action_link.html.erb +2 -2
  18. data/app/views/govuk_publishing_components/components/_add_another.html.erb +3 -3
  19. data/app/views/govuk_publishing_components/components/_attachment.html.erb +4 -4
  20. data/app/views/govuk_publishing_components/components/_back_link.html.erb +1 -1
  21. data/app/views/govuk_publishing_components/components/_back_to_top_link.html.erb +1 -1
  22. data/app/views/govuk_publishing_components/components/_big_number.html.erb +1 -1
  23. data/app/views/govuk_publishing_components/components/_cards.html.erb +4 -4
  24. data/app/views/govuk_publishing_components/components/_character_count.html.erb +1 -1
  25. data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +3 -3
  26. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +6 -9
  27. data/app/views/govuk_publishing_components/components/_contents_list_with_body.html.erb +2 -2
  28. data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +2 -2
  29. data/app/views/govuk_publishing_components/components/_contextual_footer.html.erb +1 -1
  30. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +6 -6
  31. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +6 -6
  32. data/app/views/govuk_publishing_components/components/_date_input.html.erb +5 -5
  33. data/app/views/govuk_publishing_components/components/_details.html.erb +1 -1
  34. data/app/views/govuk_publishing_components/components/_devolved_nations.html.erb +1 -1
  35. data/app/views/govuk_publishing_components/components/_document_list.html.erb +8 -8
  36. data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +3 -3
  37. data/app/views/govuk_publishing_components/components/_feedback.html.erb +2 -2
  38. data/app/views/govuk_publishing_components/components/_fieldset.html.erb +3 -4
  39. data/app/views/govuk_publishing_components/components/_figure.html.erb +1 -1
  40. data/app/views/govuk_publishing_components/components/_file_upload.html.erb +5 -5
  41. data/app/views/govuk_publishing_components/components/_glance_metric.html.erb +1 -1
  42. data/app/views/govuk_publishing_components/components/_global_banner.html.erb +2 -2
  43. data/app/views/govuk_publishing_components/components/_google_tag_manager_script.html.erb +7 -7
  44. data/app/views/govuk_publishing_components/components/_govspeak_html_publication.html.erb +1 -1
  45. data/app/views/govuk_publishing_components/components/_image_card.html.erb +4 -5
  46. data/app/views/govuk_publishing_components/components/_input.html.erb +14 -14
  47. data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -6
  48. data/app/views/govuk_publishing_components/components/_label.html.erb +1 -1
  49. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +6 -9
  50. data/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +2 -2
  51. data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +15 -15
  52. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +16 -19
  53. data/app/views/govuk_publishing_components/components/_machine_readable_metadata.html.erb +18 -17
  54. data/app/views/govuk_publishing_components/components/_metadata.html.erb +4 -4
  55. data/app/views/govuk_publishing_components/components/_notice.html.erb +1 -1
  56. data/app/views/govuk_publishing_components/components/_option_select.html.erb +8 -9
  57. data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +1 -1
  58. data/app/views/govuk_publishing_components/components/_password_input.html.erb +17 -17
  59. data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +2 -3
  60. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +6 -8
  61. data/app/views/govuk_publishing_components/components/_print_link.html.erb +3 -3
  62. data/app/views/govuk_publishing_components/components/_published_dates.html.erb +6 -7
  63. data/app/views/govuk_publishing_components/components/_radio.html.erb +7 -8
  64. data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +4 -6
  65. data/app/views/govuk_publishing_components/components/_reorderable_list.html.erb +7 -7
  66. data/app/views/govuk_publishing_components/components/_search_with_autocomplete.html.erb +2 -2
  67. data/app/views/govuk_publishing_components/components/_secondary_navigation.html.erb +1 -1
  68. data/app/views/govuk_publishing_components/components/_select.html.erb +1 -1
  69. data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +1 -1
  70. data/app/views/govuk_publishing_components/components/_share_links.html.erb +18 -18
  71. data/app/views/govuk_publishing_components/components/_signup_link.html.erb +3 -3
  72. data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +3 -3
  73. data/app/views/govuk_publishing_components/components/_skip_link.html.erb +2 -3
  74. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +9 -10
  75. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +2 -3
  76. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +5 -9
  77. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +8 -8
  78. data/app/views/govuk_publishing_components/components/_summary_list.html.erb +1 -1
  79. data/app/views/govuk_publishing_components/components/_table.html.erb +3 -3
  80. data/app/views/govuk_publishing_components/components/_tag.html.erb +1 -1
  81. data/app/views/govuk_publishing_components/components/_textarea.html.erb +4 -4
  82. data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +1 -2
  83. data/app/views/govuk_publishing_components/components/_warning_text.html.erb +2 -2
  84. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_document.html.erb +1 -1
  85. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_external.html.erb +1 -1
  86. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_generic.html.erb +2 -2
  87. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_html.html.erb +1 -1
  88. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_pdf.html.erb +1 -1
  89. data/app/views/govuk_publishing_components/components/attachment/_thumbnail_spreadsheet.html.erb +3 -3
  90. data/app/views/govuk_publishing_components/components/cross_service_header/_one_login_header.html.erb +10 -10
  91. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +10 -10
  92. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +6 -8
  93. data/app/views/govuk_publishing_components/components/govuk_logo/_govuk_logo_crown_only.html.erb +1 -2
  94. data/app/views/govuk_publishing_components/components/layout_for_public/_account-layout.html.erb +2 -2
  95. data/app/views/govuk_publishing_components/components/layout_for_public/_account-navigation.html.erb +2 -2
  96. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  97. data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +2 -3
  98. data/app/views/govuk_publishing_components/components/metadata/_sentence.html.erb +1 -1
  99. data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +4 -4
  100. data/app/views/govuk_publishing_components/components/search/_search_icon.html.erb +2 -3
  101. data/app/views/layouts/govuk_publishing_components/application.html.erb +3 -3
  102. data/lib/govuk_publishing_components/presenters/component_wrapper_helper.rb +1 -1
  103. data/lib/govuk_publishing_components/presenters/heading_helper.rb +3 -3
  104. data/lib/govuk_publishing_components/presenters/meta_tags.rb +1 -0
  105. data/lib/govuk_publishing_components/version.rb +1 -1
  106. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +97 -72
  107. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
  108. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +97 -72
  109. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
  110. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +29 -2
  111. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -1
  112. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
  113. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +4 -10
  114. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
  115. data/node_modules/govuk-frontend/dist/govuk/component.mjs.map +1 -1
  116. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +13 -11
  117. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js.map +1 -1
  118. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +13 -11
  119. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs.map +1 -1
  120. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +4 -4
  121. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs.map +1 -1
  122. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +7 -5
  123. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js.map +1 -1
  124. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +7 -5
  125. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs.map +1 -1
  126. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs.map +1 -1
  127. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +10 -8
  128. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js.map +1 -1
  129. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +10 -8
  130. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs.map +1 -1
  131. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +1 -1
  132. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
  133. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +10 -5
  134. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js.map +1 -1
  135. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +10 -5
  136. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
  137. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.mjs.map +1 -1
  138. data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/fixtures.json +36 -0
  139. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +8 -12
  140. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js.map +1 -1
  141. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +8 -12
  142. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs.map +1 -1
  143. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +2 -2
  144. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs.map +1 -1
  145. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +9 -7
  146. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js.map +1 -1
  147. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +9 -7
  148. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs.map +1 -1
  149. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs.map +1 -1
  150. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js +10 -8
  151. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js.map +1 -1
  152. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs +10 -8
  153. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs.map +1 -1
  154. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs +1 -1
  155. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs.map +1 -1
  156. data/node_modules/govuk-frontend/dist/govuk/components/footer/fixtures.json +4 -2
  157. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +10 -5
  158. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js.map +1 -1
  159. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +10 -5
  160. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs.map +1 -1
  161. data/node_modules/govuk-frontend/dist/govuk/components/header/header.mjs.map +1 -1
  162. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +7 -5
  163. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js.map +1 -1
  164. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +7 -5
  165. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs.map +1 -1
  166. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
  167. data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss +4 -0
  168. data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss.map +1 -1
  169. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +9 -7
  170. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js.map +1 -1
  171. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +9 -7
  172. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs.map +1 -1
  173. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs.map +1 -1
  174. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +10 -5
  175. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js.map +1 -1
  176. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +10 -5
  177. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
  178. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.mjs.map +1 -1
  179. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/fixtures.json +30 -0
  180. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +10 -5
  181. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js.map +1 -1
  182. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +10 -5
  183. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs.map +1 -1
  184. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.mjs.map +1 -1
  185. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss +1 -2
  186. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss.map +1 -1
  187. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +12 -19
  188. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js.map +1 -1
  189. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +12 -19
  190. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs.map +1 -1
  191. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +3 -9
  192. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs.map +1 -1
  193. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +12 -13
  194. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js.map +1 -1
  195. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +12 -13
  196. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
  197. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs +3 -3
  198. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs.map +1 -1
  199. data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
  200. data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +5 -3
  201. data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs.map +1 -1
  202. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +2 -2
  203. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css.map +1 -1
  204. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
  205. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js.map +1 -1
  206. data/node_modules/govuk-frontend/dist/govuk/i18n.mjs +4 -2
  207. data/node_modules/govuk-frontend/dist/govuk/i18n.mjs.map +1 -1
  208. data/node_modules/govuk-frontend/dist/govuk/init.mjs +52 -43
  209. data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
  210. data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +1 -1
  211. data/node_modules/govuk-frontend/package.json +11 -11
  212. metadata +15 -1
@@ -4,14 +4,8 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = global.GOVUKFrontend || {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- const version = '5.11.1';
7
+ const version = '5.11.2';
8
8
 
9
- function getFragmentFromUrl(url) {
10
- if (!url.includes('#')) {
11
- return undefined;
12
- }
13
- return url.split('#').pop();
14
- }
15
9
  function getBreakpoint(name) {
16
10
  const property = `--govuk-breakpoint-${name}`;
17
11
  const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);
@@ -69,6 +63,9 @@
69
63
  function isObject(option) {
70
64
  return !!option && typeof option === 'object' && !isArray(option);
71
65
  }
66
+ function isScope($scope) {
67
+ return !!$scope && ($scope instanceof Element || $scope instanceof Document);
68
+ }
72
69
  function formatErrorMessage(Component, message) {
73
70
  return `${Component.moduleName}: ${message}`;
74
71
  }
@@ -76,9 +73,6 @@
76
73
  * @typedef ComponentWithModuleName
77
74
  * @property {string} moduleName - Name of the component
78
75
  */
79
- /**
80
- * @import { ObjectNested } from './configuration.mjs'
81
- */
82
76
 
83
77
  class GOVUKFrontendError extends Error {
84
78
  constructor(...args) {
@@ -107,7 +101,7 @@
107
101
  class ElementError extends GOVUKFrontendError {
108
102
  constructor(messageOrOptions) {
109
103
  let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
110
- if (typeof messageOrOptions === 'object') {
104
+ if (isObject(messageOrOptions)) {
111
105
  const {
112
106
  component,
113
107
  identifier,
@@ -116,7 +110,9 @@
116
110
  } = messageOrOptions;
117
111
  message = identifier;
118
112
  message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';
119
- message = formatErrorMessage(component, message);
113
+ if (component) {
114
+ message = formatErrorMessage(component, message);
115
+ }
120
116
  }
121
117
  super(message);
122
118
  this.name = 'ElementError';
@@ -256,6 +252,30 @@
256
252
  }
257
253
  return out;
258
254
  }
255
+ function normaliseOptions(scopeOrOptions) {
256
+ let $scope = document;
257
+ let onError;
258
+ if (isObject(scopeOrOptions)) {
259
+ const options = scopeOrOptions;
260
+ if (isScope(options.scope) || options.scope === null) {
261
+ $scope = options.scope;
262
+ }
263
+ if (typeof options.onError === 'function') {
264
+ onError = options.onError;
265
+ }
266
+ }
267
+ if (isScope(scopeOrOptions)) {
268
+ $scope = scopeOrOptions;
269
+ } else if (scopeOrOptions === null) {
270
+ $scope = null;
271
+ } else if (typeof scopeOrOptions === 'function') {
272
+ onError = scopeOrOptions;
273
+ }
274
+ return {
275
+ scope: $scope,
276
+ onError
277
+ };
278
+ }
259
279
  function mergeConfigs(...configObjects) {
260
280
  const formattedConfigObject = {};
261
281
  for (const configObject of configObjects) {
@@ -350,6 +370,9 @@
350
370
  * @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
351
371
  * @typedef {typeof Component & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
352
372
  */
373
+ /**
374
+ * @import { CompatibleClass, Config, CreateAllOptions, OnErrorCallback } from '../init.mjs'
375
+ */
353
376
 
354
377
  class I18n {
355
378
  constructor(translations = {}, config = {}) {
@@ -364,7 +387,7 @@
364
387
  throw new Error('i18n: lookup key missing');
365
388
  }
366
389
  let translation = this.translations[lookupKey];
367
- if (typeof (options == null ? void 0 : options.count) === 'number' && typeof translation === 'object') {
390
+ if (typeof (options == null ? void 0 : options.count) === 'number' && isObject(translation)) {
368
391
  const translationPluralForm = translation[this.getPluralSuffix(lookupKey, options.count)];
369
392
  if (translationPluralForm) {
370
393
  translation = translationPluralForm;
@@ -407,7 +430,7 @@
407
430
  }
408
431
  const translation = this.translations[lookupKey];
409
432
  const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : this.selectPluralFormUsingFallbackRules(count);
410
- if (typeof translation === 'object') {
433
+ if (isObject(translation)) {
411
434
  if (preferredForm in translation) {
412
435
  return preferredForm;
413
436
  } else if ('other' in translation) {
@@ -743,11 +766,11 @@
743
766
  const ariaLabelParts = [];
744
767
  const $headingText = $section.querySelector(`.${this.sectionHeadingTextClass}`);
745
768
  if ($headingText) {
746
- ariaLabelParts.push(`${$headingText.textContent}`.trim());
769
+ ariaLabelParts.push($headingText.textContent.trim());
747
770
  }
748
771
  const $summary = $section.querySelector(`.${this.sectionSummaryClass}`);
749
772
  if ($summary) {
750
- ariaLabelParts.push(`${$summary.textContent}`.trim());
773
+ ariaLabelParts.push($summary.textContent.trim());
751
774
  }
752
775
  const ariaLabelMessage = expanded ? this.i18n.t('hideSectionAriaLabel') : this.i18n.t('showSectionAriaLabel');
753
776
  ariaLabelParts.push(ariaLabelMessage);
@@ -800,7 +823,7 @@
800
823
  if (id) {
801
824
  try {
802
825
  window.sessionStorage.setItem(id, isExpanded.toString());
803
- } catch (exception) {}
826
+ } catch (_unused) {}
804
827
  }
805
828
  }
806
829
  setInitialState($section) {
@@ -814,7 +837,7 @@
814
837
  if (state !== null) {
815
838
  this.setExpanded(state === 'true', $section);
816
839
  }
817
- } catch (exception) {}
840
+ } catch (_unused2) {}
818
841
  }
819
842
  }
820
843
  getButtonPunctuationEl() {
@@ -1023,7 +1046,7 @@
1023
1046
  });
1024
1047
  }
1025
1048
  this.$errorMessage = this.$root.querySelector('.govuk-error-message');
1026
- if (`${$textareaDescription.textContent}`.match(/^\s*$/)) {
1049
+ if ($textareaDescription.textContent.match(/^\s*$/)) {
1027
1050
  $textareaDescription.textContent = this.i18n.t('textareaDescription', {
1028
1051
  count: this.maxLength
1029
1052
  });
@@ -1383,7 +1406,7 @@
1383
1406
  if (!($target instanceof HTMLAnchorElement)) {
1384
1407
  return false;
1385
1408
  }
1386
- const inputId = getFragmentFromUrl($target.href);
1409
+ const inputId = $target.hash.replace('#', '');
1387
1410
  if (!inputId) {
1388
1411
  return false;
1389
1412
  }
@@ -1696,7 +1719,6 @@
1696
1719
  throw new ElementError(formatErrorMessage(FileUpload, 'File input (`<input type="file">`) attribute (`type`) is not `file`'));
1697
1720
  }
1698
1721
  this.$input = $input;
1699
- this.$input.setAttribute('hidden', 'true');
1700
1722
  if (!this.$input.id) {
1701
1723
  throw new ElementError({
1702
1724
  component: FileUpload,
@@ -1712,6 +1734,7 @@
1712
1734
  $label.id = `${this.id}-label`;
1713
1735
  }
1714
1736
  this.$input.id = `${this.id}-input`;
1737
+ this.$input.setAttribute('hidden', 'true');
1715
1738
  const $button = document.createElement('button');
1716
1739
  $button.classList.add('govuk-file-upload-button');
1717
1740
  $button.type = 'button';
@@ -2364,16 +2387,10 @@
2364
2387
  super($root);
2365
2388
  const hash = this.$root.hash;
2366
2389
  const href = (_this$$root$getAttrib = this.$root.getAttribute('href')) != null ? _this$$root$getAttrib : '';
2367
- let url;
2368
- try {
2369
- url = new window.URL(this.$root.href);
2370
- } catch (error) {
2371
- throw new ElementError(`Skip link: Target link (\`href="${href}"\`) is invalid`);
2372
- }
2373
- if (url.origin !== window.location.origin || url.pathname !== window.location.pathname) {
2390
+ if (this.$root.origin !== window.location.origin || this.$root.pathname !== window.location.pathname) {
2374
2391
  return;
2375
2392
  }
2376
- const linkedElementId = getFragmentFromUrl(hash);
2393
+ const linkedElementId = hash.replace('#', '');
2377
2394
  if (!linkedElementId) {
2378
2395
  throw new ElementError(`Skip link: Target link (\`href="${href}"\`) has no hash fragment`);
2379
2396
  }
@@ -2529,7 +2546,7 @@
2529
2546
  return this.$root.querySelector(`a.govuk-tabs__tab[href="${hash}"]`);
2530
2547
  }
2531
2548
  setAttributes($tab) {
2532
- const panelId = getFragmentFromUrl($tab.href);
2549
+ const panelId = $tab.hash.replace('#', '');
2533
2550
  if (!panelId) {
2534
2551
  return;
2535
2552
  }
@@ -2633,7 +2650,7 @@
2633
2650
  this.createHistoryEntry($previousTab);
2634
2651
  }
2635
2652
  getPanel($tab) {
2636
- const panelId = getFragmentFromUrl($tab.href);
2653
+ const panelId = $tab.hash.replace('#', '');
2637
2654
  if (!panelId) {
2638
2655
  return null;
2639
2656
  }
@@ -2681,28 +2698,34 @@
2681
2698
  * Use the `data-module` attributes to find, instantiate and init all of the
2682
2699
  * components provided as part of GOV.UK Frontend.
2683
2700
  *
2684
- * @param {Config & { scope?: Element, onError?: OnErrorCallback<CompatibleClass> }} [config] - Config for all components (with optional scope)
2701
+ * @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
2685
2702
  */
2686
- function initAll(config) {
2687
- var _config$scope;
2688
- config = typeof config !== 'undefined' ? config : {};
2689
- if (!isSupported()) {
2690
- if (config.onError) {
2691
- config.onError(new SupportError(), {
2703
+ function initAll(scopeOrConfig = {}) {
2704
+ const config = isObject(scopeOrConfig) ? scopeOrConfig : {};
2705
+ const options = normaliseOptions(scopeOrConfig);
2706
+ try {
2707
+ if (!isSupported()) {
2708
+ throw new SupportError();
2709
+ }
2710
+ if (options.scope === null) {
2711
+ throw new ElementError({
2712
+ element: options.scope,
2713
+ identifier: 'GOV.UK Frontend scope element (`$scope`)'
2714
+ });
2715
+ }
2716
+ } catch (error) {
2717
+ if (options.onError) {
2718
+ options.onError(error, {
2692
2719
  config
2693
2720
  });
2694
2721
  } else {
2695
- console.log(new SupportError());
2722
+ console.log(error);
2696
2723
  }
2697
2724
  return;
2698
2725
  }
2699
2726
  const components = [[Accordion, config.accordion], [Button, config.button], [CharacterCount, config.characterCount], [Checkboxes], [ErrorSummary, config.errorSummary], [ExitThisPage, config.exitThisPage], [FileUpload, config.fileUpload], [Header], [NotificationBanner, config.notificationBanner], [PasswordInput, config.passwordInput], [Radios], [ServiceNavigation], [SkipLink], [Tabs]];
2700
- const options = {
2701
- scope: (_config$scope = config.scope) != null ? _config$scope : document,
2702
- onError: config.onError
2703
- };
2704
- components.forEach(([Component, config]) => {
2705
- createAll(Component, config, options);
2727
+ components.forEach(([Component, componentConfig]) => {
2728
+ createAll(Component, componentConfig, options);
2706
2729
  });
2707
2730
  }
2708
2731
 
@@ -2718,42 +2741,42 @@
2718
2741
  * @template {CompatibleClass} ComponentClass
2719
2742
  * @param {ComponentClass} Component - class of the component to create
2720
2743
  * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
2721
- * @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
2744
+ * @param {OnErrorCallback<ComponentClass> | Element | Document | null | CreateAllOptions<ComponentClass>} [scopeOrOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
2722
2745
  * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
2723
2746
  */
2724
- function createAll(Component, config, createAllOptions) {
2725
- let $scope = document;
2726
- let onError;
2727
- if (typeof createAllOptions === 'object') {
2728
- var _createAllOptions$sco;
2729
- createAllOptions = createAllOptions;
2730
- $scope = (_createAllOptions$sco = createAllOptions.scope) != null ? _createAllOptions$sco : $scope;
2731
- onError = createAllOptions.onError;
2732
- }
2733
- if (typeof createAllOptions === 'function') {
2734
- onError = createAllOptions;
2735
- }
2736
- if (createAllOptions instanceof HTMLElement) {
2737
- $scope = createAllOptions;
2738
- }
2739
- const $elements = $scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
2740
- if (!isSupported()) {
2741
- if (onError) {
2742
- onError(new SupportError(), {
2747
+ function createAll(Component, config, scopeOrOptions) {
2748
+ let $elements;
2749
+ const options = normaliseOptions(scopeOrOptions);
2750
+ try {
2751
+ var _options$scope;
2752
+ if (!isSupported()) {
2753
+ throw new SupportError();
2754
+ }
2755
+ if (options.scope === null) {
2756
+ throw new ElementError({
2757
+ element: options.scope,
2758
+ component: Component,
2759
+ identifier: 'Scope element (`$scope`)'
2760
+ });
2761
+ }
2762
+ $elements = (_options$scope = options.scope) == null ? void 0 : _options$scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
2763
+ } catch (error) {
2764
+ if (options.onError) {
2765
+ options.onError(error, {
2743
2766
  component: Component,
2744
2767
  config
2745
2768
  });
2746
2769
  } else {
2747
- console.log(new SupportError());
2770
+ console.log(error);
2748
2771
  }
2749
2772
  return [];
2750
2773
  }
2751
- return Array.from($elements).map($element => {
2774
+ return Array.from($elements != null ? $elements : []).map($element => {
2752
2775
  try {
2753
2776
  return typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
2754
2777
  } catch (error) {
2755
- if (onError) {
2756
- onError(error, {
2778
+ if (options.onError) {
2779
+ options.onError(error, {
2757
2780
  element: $element,
2758
2781
  component: Component,
2759
2782
  config
@@ -2772,6 +2795,8 @@
2772
2795
  * Config for all components via `initAll()`
2773
2796
  *
2774
2797
  * @typedef {object} Config
2798
+ * @property {Element | Document | null} [scope] - Scope of the document to search within
2799
+ * @property {OnErrorCallback<CompatibleClass>} [onError] - Initialisation error callback
2775
2800
  * @property {AccordionConfig} [accordion] - Accordion config
2776
2801
  * @property {ButtonConfig} [button] - Button config
2777
2802
  * @property {CharacterCountConfig} [characterCount] - Character Count config
@@ -2796,7 +2821,7 @@
2796
2821
  /**
2797
2822
  * Component config keys, e.g. `accordion` and `characterCount`
2798
2823
  *
2799
- * @typedef {keyof Config} ConfigKey
2824
+ * @typedef {keyof Omit<Config, 'scope' | 'onError'>} ConfigKey
2800
2825
  */
2801
2826
  /**
2802
2827
  * @template {CompatibleClass} ComponentClass
@@ -2807,7 +2832,7 @@
2807
2832
  * @typedef {object} ErrorContext
2808
2833
  * @property {Element} [element] - Element used for component module initialisation
2809
2834
  * @property {ComponentClass} [component] - Class of component
2810
- * @property {ComponentConfig<ComponentClass>} config - Config supplied to component
2835
+ * @property {Config | ComponentConfig<ComponentClass>} [config] - Config supplied to components
2811
2836
  */
2812
2837
  /**
2813
2838
  * @template {CompatibleClass} ComponentClass
@@ -2818,7 +2843,7 @@
2818
2843
  /**
2819
2844
  * @template {CompatibleClass} ComponentClass
2820
2845
  * @typedef {object} CreateAllOptions
2821
- * @property {Element | Document} [scope] - scope of the document to search within
2846
+ * @property {Element | Document | null} [scope] - scope of the document to search within
2822
2847
  * @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init
2823
2848
  */
2824
2849