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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +11 -1
- data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +0 -14
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +570 -595
- data/app/views/govuk_publishing_components/audit/_applications.html.erb +13 -13
- data/app/views/govuk_publishing_components/audit/_component_contents.html.erb +2 -2
- data/app/views/govuk_publishing_components/audit/_components.html.erb +17 -19
- data/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb +3 -3
- data/app/views/govuk_publishing_components/audit/show.html.erb +5 -6
- data/app/views/govuk_publishing_components/component_guide/component_doc/_call.html.erb +2 -2
- data/app/views/govuk_publishing_components/component_guide/example.html.erb +4 -5
- data/app/views/govuk_publishing_components/component_guide/index.html.erb +9 -10
- data/app/views/govuk_publishing_components/component_guide/preview.html.erb +1 -1
- data/app/views/govuk_publishing_components/component_guide/show.html.erb +9 -10
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +5 -5
- data/app/views/govuk_publishing_components/components/_action_link.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_add_another.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_attachment.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/_back_link.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_back_to_top_link.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_big_number.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_cards.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/_character_count.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_contents_list.html.erb +6 -9
- data/app/views/govuk_publishing_components/components/_contents_list_with_body.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_contextual_footer.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +6 -6
- data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +6 -6
- data/app/views/govuk_publishing_components/components/_date_input.html.erb +5 -5
- data/app/views/govuk_publishing_components/components/_details.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_devolved_nations.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_document_list.html.erb +8 -8
- data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_feedback.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_fieldset.html.erb +3 -4
- data/app/views/govuk_publishing_components/components/_figure.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_file_upload.html.erb +5 -5
- data/app/views/govuk_publishing_components/components/_glance_metric.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_global_banner.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_google_tag_manager_script.html.erb +7 -7
- data/app/views/govuk_publishing_components/components/_govspeak_html_publication.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_image_card.html.erb +4 -5
- data/app/views/govuk_publishing_components/components/_input.html.erb +14 -14
- data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -6
- data/app/views/govuk_publishing_components/components/_label.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +6 -9
- data/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +15 -15
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +16 -19
- data/app/views/govuk_publishing_components/components/_machine_readable_metadata.html.erb +18 -17
- data/app/views/govuk_publishing_components/components/_metadata.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/_notice.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_option_select.html.erb +8 -9
- data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_password_input.html.erb +17 -17
- data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +2 -3
- data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +6 -8
- data/app/views/govuk_publishing_components/components/_print_link.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_published_dates.html.erb +6 -7
- data/app/views/govuk_publishing_components/components/_radio.html.erb +7 -8
- data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +4 -6
- data/app/views/govuk_publishing_components/components/_reorderable_list.html.erb +7 -7
- data/app/views/govuk_publishing_components/components/_search_with_autocomplete.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_secondary_navigation.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_select.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_share_links.html.erb +18 -18
- data/app/views/govuk_publishing_components/components/_signup_link.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_skip_link.html.erb +2 -3
- data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +9 -10
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +2 -3
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +5 -9
- data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +8 -8
- data/app/views/govuk_publishing_components/components/_summary_list.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_table.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/_tag.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_textarea.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +1 -2
- data/app/views/govuk_publishing_components/components/_warning_text.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_document.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_external.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_generic.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_html.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_pdf.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/attachment/_thumbnail_spreadsheet.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/cross_service_header/_one_login_header.html.erb +10 -10
- data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +10 -10
- data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +6 -8
- data/app/views/govuk_publishing_components/components/govuk_logo/_govuk_logo_crown_only.html.erb +1 -2
- data/app/views/govuk_publishing_components/components/layout_for_public/_account-layout.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/layout_for_public/_account-navigation.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +2 -3
- data/app/views/govuk_publishing_components/components/metadata/_sentence.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/search/_search_icon.html.erb +2 -3
- data/app/views/layouts/govuk_publishing_components/application.html.erb +3 -3
- data/lib/govuk_publishing_components/presenters/component_wrapper_helper.rb +1 -1
- data/lib/govuk_publishing_components/presenters/heading_helper.rb +3 -3
- data/lib/govuk_publishing_components/presenters/meta_tags.rb +1 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +97 -72
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +97 -72
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +29 -2
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
- data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +4 -10
- data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/component.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +13 -11
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +13 -11
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +10 -8
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +10 -8
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/fixtures.json +36 -0
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +8 -12
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +8 -12
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +9 -7
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +9 -7
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js +10 -8
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs +10 -8
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/footer/fixtures.json +4 -2
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss +4 -0
- data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +9 -7
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +9 -7
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/fixtures.json +30 -0
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss +1 -2
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +12 -19
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +12 -19
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +3 -9
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +12 -13
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +12 -13
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs +3 -3
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +5 -3
- data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +2 -2
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/i18n.mjs +4 -2
- data/node_modules/govuk-frontend/dist/govuk/i18n.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/init.mjs +52 -43
- data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
- data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +1 -1
- data/node_modules/govuk-frontend/package.json +11 -11
- metadata +15 -1
@@ -1,11 +1,5 @@
|
|
1
|
-
const version = '5.11.
|
1
|
+
const version = '5.11.2';
|
2
2
|
|
3
|
-
function getFragmentFromUrl(url) {
|
4
|
-
if (!url.includes('#')) {
|
5
|
-
return undefined;
|
6
|
-
}
|
7
|
-
return url.split('#').pop();
|
8
|
-
}
|
9
3
|
function getBreakpoint(name) {
|
10
4
|
const property = `--govuk-breakpoint-${name}`;
|
11
5
|
const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);
|
@@ -63,6 +57,9 @@ function isArray(option) {
|
|
63
57
|
function isObject(option) {
|
64
58
|
return !!option && typeof option === 'object' && !isArray(option);
|
65
59
|
}
|
60
|
+
function isScope($scope) {
|
61
|
+
return !!$scope && ($scope instanceof Element || $scope instanceof Document);
|
62
|
+
}
|
66
63
|
function formatErrorMessage(Component, message) {
|
67
64
|
return `${Component.moduleName}: ${message}`;
|
68
65
|
}
|
@@ -70,9 +67,6 @@ function formatErrorMessage(Component, message) {
|
|
70
67
|
* @typedef ComponentWithModuleName
|
71
68
|
* @property {string} moduleName - Name of the component
|
72
69
|
*/
|
73
|
-
/**
|
74
|
-
* @import { ObjectNested } from './configuration.mjs'
|
75
|
-
*/
|
76
70
|
|
77
71
|
class GOVUKFrontendError extends Error {
|
78
72
|
constructor(...args) {
|
@@ -101,7 +95,7 @@ class ConfigError extends GOVUKFrontendError {
|
|
101
95
|
class ElementError extends GOVUKFrontendError {
|
102
96
|
constructor(messageOrOptions) {
|
103
97
|
let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
|
104
|
-
if (
|
98
|
+
if (isObject(messageOrOptions)) {
|
105
99
|
const {
|
106
100
|
component,
|
107
101
|
identifier,
|
@@ -110,7 +104,9 @@ class ElementError extends GOVUKFrontendError {
|
|
110
104
|
} = messageOrOptions;
|
111
105
|
message = identifier;
|
112
106
|
message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';
|
113
|
-
|
107
|
+
if (component) {
|
108
|
+
message = formatErrorMessage(component, message);
|
109
|
+
}
|
114
110
|
}
|
115
111
|
super(message);
|
116
112
|
this.name = 'ElementError';
|
@@ -250,6 +246,30 @@ function normaliseDataset(Component, dataset) {
|
|
250
246
|
}
|
251
247
|
return out;
|
252
248
|
}
|
249
|
+
function normaliseOptions(scopeOrOptions) {
|
250
|
+
let $scope = document;
|
251
|
+
let onError;
|
252
|
+
if (isObject(scopeOrOptions)) {
|
253
|
+
const options = scopeOrOptions;
|
254
|
+
if (isScope(options.scope) || options.scope === null) {
|
255
|
+
$scope = options.scope;
|
256
|
+
}
|
257
|
+
if (typeof options.onError === 'function') {
|
258
|
+
onError = options.onError;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
if (isScope(scopeOrOptions)) {
|
262
|
+
$scope = scopeOrOptions;
|
263
|
+
} else if (scopeOrOptions === null) {
|
264
|
+
$scope = null;
|
265
|
+
} else if (typeof scopeOrOptions === 'function') {
|
266
|
+
onError = scopeOrOptions;
|
267
|
+
}
|
268
|
+
return {
|
269
|
+
scope: $scope,
|
270
|
+
onError
|
271
|
+
};
|
272
|
+
}
|
253
273
|
function mergeConfigs(...configObjects) {
|
254
274
|
const formattedConfigObject = {};
|
255
275
|
for (const configObject of configObjects) {
|
@@ -344,6 +364,9 @@ function extractConfigByNamespace(schema, dataset, namespace) {
|
|
344
364
|
* @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
|
345
365
|
* @typedef {typeof Component & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
|
346
366
|
*/
|
367
|
+
/**
|
368
|
+
* @import { CompatibleClass, Config, CreateAllOptions, OnErrorCallback } from '../init.mjs'
|
369
|
+
*/
|
347
370
|
|
348
371
|
class I18n {
|
349
372
|
constructor(translations = {}, config = {}) {
|
@@ -358,7 +381,7 @@ class I18n {
|
|
358
381
|
throw new Error('i18n: lookup key missing');
|
359
382
|
}
|
360
383
|
let translation = this.translations[lookupKey];
|
361
|
-
if (typeof (options == null ? void 0 : options.count) === 'number' &&
|
384
|
+
if (typeof (options == null ? void 0 : options.count) === 'number' && isObject(translation)) {
|
362
385
|
const translationPluralForm = translation[this.getPluralSuffix(lookupKey, options.count)];
|
363
386
|
if (translationPluralForm) {
|
364
387
|
translation = translationPluralForm;
|
@@ -401,7 +424,7 @@ class I18n {
|
|
401
424
|
}
|
402
425
|
const translation = this.translations[lookupKey];
|
403
426
|
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : this.selectPluralFormUsingFallbackRules(count);
|
404
|
-
if (
|
427
|
+
if (isObject(translation)) {
|
405
428
|
if (preferredForm in translation) {
|
406
429
|
return preferredForm;
|
407
430
|
} else if ('other' in translation) {
|
@@ -737,11 +760,11 @@ class Accordion extends ConfigurableComponent {
|
|
737
760
|
const ariaLabelParts = [];
|
738
761
|
const $headingText = $section.querySelector(`.${this.sectionHeadingTextClass}`);
|
739
762
|
if ($headingText) {
|
740
|
-
ariaLabelParts.push(
|
763
|
+
ariaLabelParts.push($headingText.textContent.trim());
|
741
764
|
}
|
742
765
|
const $summary = $section.querySelector(`.${this.sectionSummaryClass}`);
|
743
766
|
if ($summary) {
|
744
|
-
ariaLabelParts.push(
|
767
|
+
ariaLabelParts.push($summary.textContent.trim());
|
745
768
|
}
|
746
769
|
const ariaLabelMessage = expanded ? this.i18n.t('hideSectionAriaLabel') : this.i18n.t('showSectionAriaLabel');
|
747
770
|
ariaLabelParts.push(ariaLabelMessage);
|
@@ -794,7 +817,7 @@ class Accordion extends ConfigurableComponent {
|
|
794
817
|
if (id) {
|
795
818
|
try {
|
796
819
|
window.sessionStorage.setItem(id, isExpanded.toString());
|
797
|
-
} catch (
|
820
|
+
} catch (_unused) {}
|
798
821
|
}
|
799
822
|
}
|
800
823
|
setInitialState($section) {
|
@@ -808,7 +831,7 @@ class Accordion extends ConfigurableComponent {
|
|
808
831
|
if (state !== null) {
|
809
832
|
this.setExpanded(state === 'true', $section);
|
810
833
|
}
|
811
|
-
} catch (
|
834
|
+
} catch (_unused2) {}
|
812
835
|
}
|
813
836
|
}
|
814
837
|
getButtonPunctuationEl() {
|
@@ -1017,7 +1040,7 @@ class CharacterCount extends ConfigurableComponent {
|
|
1017
1040
|
});
|
1018
1041
|
}
|
1019
1042
|
this.$errorMessage = this.$root.querySelector('.govuk-error-message');
|
1020
|
-
if (
|
1043
|
+
if ($textareaDescription.textContent.match(/^\s*$/)) {
|
1021
1044
|
$textareaDescription.textContent = this.i18n.t('textareaDescription', {
|
1022
1045
|
count: this.maxLength
|
1023
1046
|
});
|
@@ -1377,7 +1400,7 @@ class ErrorSummary extends ConfigurableComponent {
|
|
1377
1400
|
if (!($target instanceof HTMLAnchorElement)) {
|
1378
1401
|
return false;
|
1379
1402
|
}
|
1380
|
-
const inputId =
|
1403
|
+
const inputId = $target.hash.replace('#', '');
|
1381
1404
|
if (!inputId) {
|
1382
1405
|
return false;
|
1383
1406
|
}
|
@@ -1690,7 +1713,6 @@ class FileUpload extends ConfigurableComponent {
|
|
1690
1713
|
throw new ElementError(formatErrorMessage(FileUpload, 'File input (`<input type="file">`) attribute (`type`) is not `file`'));
|
1691
1714
|
}
|
1692
1715
|
this.$input = $input;
|
1693
|
-
this.$input.setAttribute('hidden', 'true');
|
1694
1716
|
if (!this.$input.id) {
|
1695
1717
|
throw new ElementError({
|
1696
1718
|
component: FileUpload,
|
@@ -1706,6 +1728,7 @@ class FileUpload extends ConfigurableComponent {
|
|
1706
1728
|
$label.id = `${this.id}-label`;
|
1707
1729
|
}
|
1708
1730
|
this.$input.id = `${this.id}-input`;
|
1731
|
+
this.$input.setAttribute('hidden', 'true');
|
1709
1732
|
const $button = document.createElement('button');
|
1710
1733
|
$button.classList.add('govuk-file-upload-button');
|
1711
1734
|
$button.type = 'button';
|
@@ -2358,16 +2381,10 @@ class SkipLink extends Component {
|
|
2358
2381
|
super($root);
|
2359
2382
|
const hash = this.$root.hash;
|
2360
2383
|
const href = (_this$$root$getAttrib = this.$root.getAttribute('href')) != null ? _this$$root$getAttrib : '';
|
2361
|
-
|
2362
|
-
try {
|
2363
|
-
url = new window.URL(this.$root.href);
|
2364
|
-
} catch (error) {
|
2365
|
-
throw new ElementError(`Skip link: Target link (\`href="${href}"\`) is invalid`);
|
2366
|
-
}
|
2367
|
-
if (url.origin !== window.location.origin || url.pathname !== window.location.pathname) {
|
2384
|
+
if (this.$root.origin !== window.location.origin || this.$root.pathname !== window.location.pathname) {
|
2368
2385
|
return;
|
2369
2386
|
}
|
2370
|
-
const linkedElementId =
|
2387
|
+
const linkedElementId = hash.replace('#', '');
|
2371
2388
|
if (!linkedElementId) {
|
2372
2389
|
throw new ElementError(`Skip link: Target link (\`href="${href}"\`) has no hash fragment`);
|
2373
2390
|
}
|
@@ -2523,7 +2540,7 @@ class Tabs extends Component {
|
|
2523
2540
|
return this.$root.querySelector(`a.govuk-tabs__tab[href="${hash}"]`);
|
2524
2541
|
}
|
2525
2542
|
setAttributes($tab) {
|
2526
|
-
const panelId =
|
2543
|
+
const panelId = $tab.hash.replace('#', '');
|
2527
2544
|
if (!panelId) {
|
2528
2545
|
return;
|
2529
2546
|
}
|
@@ -2627,7 +2644,7 @@ class Tabs extends Component {
|
|
2627
2644
|
this.createHistoryEntry($previousTab);
|
2628
2645
|
}
|
2629
2646
|
getPanel($tab) {
|
2630
|
-
const panelId =
|
2647
|
+
const panelId = $tab.hash.replace('#', '');
|
2631
2648
|
if (!panelId) {
|
2632
2649
|
return null;
|
2633
2650
|
}
|
@@ -2675,28 +2692,34 @@ Tabs.moduleName = 'govuk-tabs';
|
|
2675
2692
|
* Use the `data-module` attributes to find, instantiate and init all of the
|
2676
2693
|
* components provided as part of GOV.UK Frontend.
|
2677
2694
|
*
|
2678
|
-
* @param {Config
|
2695
|
+
* @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
|
2679
2696
|
*/
|
2680
|
-
function initAll(
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
if (
|
2685
|
-
|
2697
|
+
function initAll(scopeOrConfig = {}) {
|
2698
|
+
const config = isObject(scopeOrConfig) ? scopeOrConfig : {};
|
2699
|
+
const options = normaliseOptions(scopeOrConfig);
|
2700
|
+
try {
|
2701
|
+
if (!isSupported()) {
|
2702
|
+
throw new SupportError();
|
2703
|
+
}
|
2704
|
+
if (options.scope === null) {
|
2705
|
+
throw new ElementError({
|
2706
|
+
element: options.scope,
|
2707
|
+
identifier: 'GOV.UK Frontend scope element (`$scope`)'
|
2708
|
+
});
|
2709
|
+
}
|
2710
|
+
} catch (error) {
|
2711
|
+
if (options.onError) {
|
2712
|
+
options.onError(error, {
|
2686
2713
|
config
|
2687
2714
|
});
|
2688
2715
|
} else {
|
2689
|
-
console.log(
|
2716
|
+
console.log(error);
|
2690
2717
|
}
|
2691
2718
|
return;
|
2692
2719
|
}
|
2693
2720
|
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]];
|
2694
|
-
|
2695
|
-
|
2696
|
-
onError: config.onError
|
2697
|
-
};
|
2698
|
-
components.forEach(([Component, config]) => {
|
2699
|
-
createAll(Component, config, options);
|
2721
|
+
components.forEach(([Component, componentConfig]) => {
|
2722
|
+
createAll(Component, componentConfig, options);
|
2700
2723
|
});
|
2701
2724
|
}
|
2702
2725
|
|
@@ -2712,42 +2735,42 @@ function initAll(config) {
|
|
2712
2735
|
* @template {CompatibleClass} ComponentClass
|
2713
2736
|
* @param {ComponentClass} Component - class of the component to create
|
2714
2737
|
* @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
|
2715
|
-
* @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass>
|
2738
|
+
* @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
|
2716
2739
|
* @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
|
2717
2740
|
*/
|
2718
|
-
function createAll(Component, config,
|
2719
|
-
let $
|
2720
|
-
|
2721
|
-
|
2722
|
-
var
|
2723
|
-
|
2724
|
-
|
2725
|
-
|
2726
|
-
|
2727
|
-
|
2728
|
-
|
2729
|
-
|
2730
|
-
|
2731
|
-
|
2732
|
-
|
2733
|
-
|
2734
|
-
|
2735
|
-
if (onError) {
|
2736
|
-
onError(
|
2741
|
+
function createAll(Component, config, scopeOrOptions) {
|
2742
|
+
let $elements;
|
2743
|
+
const options = normaliseOptions(scopeOrOptions);
|
2744
|
+
try {
|
2745
|
+
var _options$scope;
|
2746
|
+
if (!isSupported()) {
|
2747
|
+
throw new SupportError();
|
2748
|
+
}
|
2749
|
+
if (options.scope === null) {
|
2750
|
+
throw new ElementError({
|
2751
|
+
element: options.scope,
|
2752
|
+
component: Component,
|
2753
|
+
identifier: 'Scope element (`$scope`)'
|
2754
|
+
});
|
2755
|
+
}
|
2756
|
+
$elements = (_options$scope = options.scope) == null ? void 0 : _options$scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
|
2757
|
+
} catch (error) {
|
2758
|
+
if (options.onError) {
|
2759
|
+
options.onError(error, {
|
2737
2760
|
component: Component,
|
2738
2761
|
config
|
2739
2762
|
});
|
2740
2763
|
} else {
|
2741
|
-
console.log(
|
2764
|
+
console.log(error);
|
2742
2765
|
}
|
2743
2766
|
return [];
|
2744
2767
|
}
|
2745
|
-
return Array.from($elements).map($element => {
|
2768
|
+
return Array.from($elements != null ? $elements : []).map($element => {
|
2746
2769
|
try {
|
2747
2770
|
return typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
|
2748
2771
|
} catch (error) {
|
2749
|
-
if (onError) {
|
2750
|
-
onError(error, {
|
2772
|
+
if (options.onError) {
|
2773
|
+
options.onError(error, {
|
2751
2774
|
element: $element,
|
2752
2775
|
component: Component,
|
2753
2776
|
config
|
@@ -2766,6 +2789,8 @@ function createAll(Component, config, createAllOptions) {
|
|
2766
2789
|
* Config for all components via `initAll()`
|
2767
2790
|
*
|
2768
2791
|
* @typedef {object} Config
|
2792
|
+
* @property {Element | Document | null} [scope] - Scope of the document to search within
|
2793
|
+
* @property {OnErrorCallback<CompatibleClass>} [onError] - Initialisation error callback
|
2769
2794
|
* @property {AccordionConfig} [accordion] - Accordion config
|
2770
2795
|
* @property {ButtonConfig} [button] - Button config
|
2771
2796
|
* @property {CharacterCountConfig} [characterCount] - Character Count config
|
@@ -2790,7 +2815,7 @@ function createAll(Component, config, createAllOptions) {
|
|
2790
2815
|
/**
|
2791
2816
|
* Component config keys, e.g. `accordion` and `characterCount`
|
2792
2817
|
*
|
2793
|
-
* @typedef {keyof Config} ConfigKey
|
2818
|
+
* @typedef {keyof Omit<Config, 'scope' | 'onError'>} ConfigKey
|
2794
2819
|
*/
|
2795
2820
|
/**
|
2796
2821
|
* @template {CompatibleClass} ComponentClass
|
@@ -2801,7 +2826,7 @@ function createAll(Component, config, createAllOptions) {
|
|
2801
2826
|
* @typedef {object} ErrorContext
|
2802
2827
|
* @property {Element} [element] - Element used for component module initialisation
|
2803
2828
|
* @property {ComponentClass} [component] - Class of component
|
2804
|
-
* @property {ComponentConfig<ComponentClass>} config - Config supplied to
|
2829
|
+
* @property {Config | ComponentConfig<ComponentClass>} [config] - Config supplied to components
|
2805
2830
|
*/
|
2806
2831
|
/**
|
2807
2832
|
* @template {CompatibleClass} ComponentClass
|
@@ -2812,7 +2837,7 @@ function createAll(Component, config, createAllOptions) {
|
|
2812
2837
|
/**
|
2813
2838
|
* @template {CompatibleClass} ComponentClass
|
2814
2839
|
* @typedef {object} CreateAllOptions
|
2815
|
-
* @property {Element | Document} [scope] - scope of the document to search within
|
2840
|
+
* @property {Element | Document | null} [scope] - scope of the document to search within
|
2816
2841
|
* @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init
|
2817
2842
|
*/
|
2818
2843
|
|