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,3 +1,5 @@
|
|
1
|
+
import { isObject } from './common/index.mjs';
|
2
|
+
|
1
3
|
class I18n {
|
2
4
|
constructor(translations = {}, config = {}) {
|
3
5
|
var _config$locale;
|
@@ -11,7 +13,7 @@ class I18n {
|
|
11
13
|
throw new Error('i18n: lookup key missing');
|
12
14
|
}
|
13
15
|
let translation = this.translations[lookupKey];
|
14
|
-
if (typeof (options == null ? void 0 : options.count) === 'number' &&
|
16
|
+
if (typeof (options == null ? void 0 : options.count) === 'number' && isObject(translation)) {
|
15
17
|
const translationPluralForm = translation[this.getPluralSuffix(lookupKey, options.count)];
|
16
18
|
if (translationPluralForm) {
|
17
19
|
translation = translationPluralForm;
|
@@ -54,7 +56,7 @@ class I18n {
|
|
54
56
|
}
|
55
57
|
const translation = this.translations[lookupKey];
|
56
58
|
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : this.selectPluralFormUsingFallbackRules(count);
|
57
|
-
if (
|
59
|
+
if (isObject(translation)) {
|
58
60
|
if (preferredForm in translation) {
|
59
61
|
return preferredForm;
|
60
62
|
} else if ('other' in translation) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"i18n.mjs","sources":["../../src/govuk/i18n.mjs"],"sourcesContent":["/**\n * Internal support for selecting messages to render, with placeholder\n * interpolation and locale-aware number formatting and pluralisation\n *\n * @internal\n */\nexport class I18n {\n translations\n locale\n\n /**\n * @internal\n * @param {{ [key: string]: string | TranslationPluralForms }} translations - Key-value pairs of the translation strings to use.\n * @param {object} [config] - Configuration options for the function.\n * @param {string | null} [config.locale] - An overriding locale for the PluralRules functionality.\n */\n constructor(translations = {}, config = {}) {\n // Make list of translations available throughout function\n this.translations = translations\n\n // The locale to use for PluralRules and NumberFormat\n this.locale = config.locale ?? (document.documentElement.lang || 'en')\n }\n\n /**\n * The most used function - takes the key for a given piece of UI text and\n * returns the appropriate string.\n *\n * @internal\n * @param {string} lookupKey - The lookup key of the string to use.\n * @param {{ [key: string]: unknown }} [options] - Any options passed with the translation string, e.g: for string interpolation.\n * @returns {string} The appropriate translation string.\n * @throws {Error} Lookup key required\n * @throws {Error} Options required for `${}` placeholders\n */\n t(lookupKey, options) {\n if (!lookupKey) {\n // Print a console error if no lookup key has been provided\n throw new Error('i18n: lookup key missing')\n }\n\n // Fetch the translation for that lookup key\n let translation = this.translations[lookupKey]\n\n // If the `count` option is set, determine which plural suffix is needed and\n // change the lookupKey to match. We check to see if it's numeric instead of\n // falsy, as this could legitimately be 0.\n if (typeof options?.count === 'number' && typeof translation === 'object') {\n const translationPluralForm =\n translation[this.getPluralSuffix(lookupKey, options.count)]\n\n // Update translation with plural suffix\n if (translationPluralForm) {\n translation = translationPluralForm\n }\n }\n\n if (typeof translation === 'string') {\n // Check for ${} placeholders in the translation string\n if (translation.match(/%{(.\\S+)}/)) {\n if (!options) {\n throw new Error(\n 'i18n: cannot replace placeholders in string if no option data provided'\n )\n }\n\n return this.replacePlaceholders(translation, options)\n }\n\n return translation\n }\n\n // If the key wasn't found in our translations object,\n // return the lookup key itself as the fallback\n return lookupKey\n }\n\n /**\n * Takes a translation string with placeholders, and replaces the placeholders\n * with the provided data\n *\n * @internal\n * @param {string} translationString - The translation string\n * @param {{ [key: string]: unknown }} options - Any options passed with the translation string, e.g: for string interpolation.\n * @returns {string} The translation string to output, with $\\{\\} placeholders replaced\n */\n replacePlaceholders(translationString, options) {\n const formatter = Intl.NumberFormat.supportedLocalesOf(this.locale).length\n ? new Intl.NumberFormat(this.locale)\n : undefined\n\n return translationString.replace(\n /%{(.\\S+)}/g,\n\n /**\n * Replace translation string placeholders\n *\n * @internal\n * @param {string} placeholderWithBraces - Placeholder with braces\n * @param {string} placeholderKey - Placeholder key\n * @returns {string} Placeholder value\n */\n function (placeholderWithBraces, placeholderKey) {\n if (Object.prototype.hasOwnProperty.call(options, placeholderKey)) {\n const placeholderValue = options[placeholderKey]\n\n // If a user has passed `false` as the value for the placeholder\n // treat it as though the value should not be displayed\n if (\n placeholderValue === false ||\n (typeof placeholderValue !== 'number' &&\n typeof placeholderValue !== 'string')\n ) {\n return ''\n }\n\n // If the placeholder's value is a number, localise the number formatting\n if (typeof placeholderValue === 'number') {\n return formatter\n ? formatter.format(placeholderValue)\n : `${placeholderValue}`\n }\n\n return placeholderValue\n }\n\n throw new Error(\n `i18n: no data found to replace ${placeholderWithBraces} placeholder in string`\n )\n }\n )\n }\n\n /**\n * Check to see if the browser supports Intl.PluralRules\n *\n * It requires all conditions to be met in order to be supported:\n * - The implementation of Intl supports PluralRules (NOT true in Safari 10–12)\n * - The browser/OS has plural rules for the current locale (browser dependent)\n *\n * {@link https://browsersl.ist/#q=supports+es6-module+and+not+supports+intl-pluralrules}\n *\n * @internal\n * @returns {boolean} Returns true if all conditions are met. Returns false otherwise.\n */\n hasIntlPluralRulesSupport() {\n return Boolean(\n 'PluralRules' in window.Intl &&\n Intl.PluralRules.supportedLocalesOf(this.locale).length\n )\n }\n\n /**\n * Get the appropriate suffix for the plural form.\n *\n * Uses Intl.PluralRules (or our own fallback implementation) to get the\n * 'preferred' form to use for the given count.\n *\n * Checks that a translation has been provided for that plural form – if it\n * hasn't, it'll fall back to the 'other' plural form (unless that doesn't exist\n * either, in which case an error will be thrown)\n *\n * @internal\n * @param {string} lookupKey - The lookup key of the string to use.\n * @param {number} count - Number used to determine which pluralisation to use.\n * @returns {PluralRule} The suffix associated with the correct pluralisation for this locale.\n * @throws {Error} Plural form `.other` required when preferred plural form is missing\n */\n getPluralSuffix(lookupKey, count) {\n // Validate that the number is actually a number.\n //\n // Number(count) will turn anything that can't be converted to a Number type\n // into 'NaN'. isFinite filters out NaN, as it isn't a finite number.\n count = Number(count)\n if (!isFinite(count)) {\n return 'other'\n }\n\n // Fetch the translation for that lookup key\n const translation = this.translations[lookupKey]\n\n // Check to verify that all the requirements for Intl.PluralRules are met.\n // If so, we can use that instead of our custom implementation. Otherwise,\n // use the hardcoded fallback.\n const preferredForm = this.hasIntlPluralRulesSupport()\n ? new Intl.PluralRules(this.locale).select(count)\n : this.selectPluralFormUsingFallbackRules(count)\n\n // Use the correct plural form if provided\n if (typeof translation === 'object') {\n if (preferredForm in translation) {\n return preferredForm\n // Fall back to `other` if the plural form is missing, but log a warning\n // to the console\n } else if ('other' in translation) {\n console.warn(\n `i18n: Missing plural form \".${preferredForm}\" for \"${this.locale}\" locale. Falling back to \".other\".`\n )\n\n return 'other'\n }\n }\n\n // If the required `other` plural form is missing, all we can do is error\n throw new Error(\n `i18n: Plural form \".other\" is required for \"${this.locale}\" locale`\n )\n }\n\n /**\n * Get the plural form using our fallback implementation\n *\n * This is split out into a separate function to make it easier to test the\n * fallback behaviour in an environment where Intl.PluralRules exists.\n *\n * @internal\n * @param {number} count - Number used to determine which pluralisation to use.\n * @returns {PluralRule} The pluralisation form for count in this locale.\n */\n selectPluralFormUsingFallbackRules(count) {\n // Currently our custom code can only handle positive integers, so let's\n // make sure our number is one of those.\n count = Math.abs(Math.floor(count))\n\n const ruleset = this.getPluralRulesForLocale()\n\n if (ruleset) {\n return I18n.pluralRules[ruleset](count)\n }\n\n return 'other'\n }\n\n /**\n * Work out which pluralisation rules to use for the current locale\n *\n * The locale may include a regional indicator (such as en-GB), but we don't\n * usually care about this part, as pluralisation rules are usually the same\n * regardless of region. There are exceptions, however, (e.g. Portuguese) so\n * this searches by both the full and shortened locale codes, just to be sure.\n *\n * @internal\n * @returns {string | undefined} The name of the pluralisation rule to use (a key for one\n * of the functions in this.pluralRules)\n */\n getPluralRulesForLocale() {\n const localeShort = this.locale.split('-')[0]\n\n // Look through the plural rules map to find which `pluralRule` is\n // appropriate for our current `locale`.\n for (const pluralRule in I18n.pluralRulesMap) {\n const languages = I18n.pluralRulesMap[pluralRule]\n if (languages.includes(this.locale) || languages.includes(localeShort)) {\n return pluralRule\n }\n }\n }\n\n /**\n * Map of plural rules to languages where those rules apply.\n *\n * Note: These groups are named for the most dominant or recognisable language\n * that uses each system. The groupings do not imply that the languages are\n * related to one another. Many languages have evolved the same systems\n * independently of one another.\n *\n * Code to support more languages can be found in the i18n spike:\n * {@link https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs}\n *\n * Languages currently supported:\n *\n * Arabic: Arabic (ar)\n * Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja),\n * Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi)\n * French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi),\n * Persian Farsi (fa), Punjabi (pa), Zulu (zu)\n * German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu),\n * Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en),\n * Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el),\n * Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so),\n * Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr),\n * Urdu (ur)\n * Irish: Irish Gaelic (ga)\n * Russian: Russian (ru), Ukrainian (uk)\n * Scottish: Scottish Gaelic (gd)\n * Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)\n * Welsh: Welsh (cy)\n *\n * @internal\n * @type {{ [key: string]: string[] }}\n */\n static pluralRulesMap = {\n arabic: ['ar'],\n chinese: ['my', 'zh', 'id', 'ja', 'jv', 'ko', 'ms', 'th', 'vi'],\n french: ['hy', 'bn', 'fr', 'gu', 'hi', 'fa', 'pa', 'zu'],\n german: [\n 'af',\n 'sq',\n 'az',\n 'eu',\n 'bg',\n 'ca',\n 'da',\n 'nl',\n 'en',\n 'et',\n 'fi',\n 'ka',\n 'de',\n 'el',\n 'hu',\n 'lb',\n 'no',\n 'so',\n 'sw',\n 'sv',\n 'ta',\n 'te',\n 'tr',\n 'ur'\n ],\n irish: ['ga'],\n russian: ['ru', 'uk'],\n scottish: ['gd'],\n spanish: ['pt-PT', 'it', 'es'],\n welsh: ['cy']\n }\n\n /**\n * Different pluralisation rule sets\n *\n * Returns the appropriate suffix for the plural form associated with `n`.\n * Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual\n * meaning of each differs per locale). 'other' should always exist, even in\n * languages without plurals, such as Chinese.\n * {@link https://cldr.unicode.org/index/cldr-spec/plural-rules}\n *\n * The count must be a positive integer. Negative numbers and decimals aren't accounted for\n *\n * @internal\n * @type {{ [key: string]: (count: number) => PluralRule }}\n */\n static pluralRules = {\n arabic(n) {\n if (n === 0) {\n return 'zero'\n }\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n % 100 >= 3 && n % 100 <= 10) {\n return 'few'\n }\n if (n % 100 >= 11 && n % 100 <= 99) {\n return 'many'\n }\n return 'other'\n },\n chinese() {\n return 'other'\n },\n french(n) {\n return n === 0 || n === 1 ? 'one' : 'other'\n },\n german(n) {\n return n === 1 ? 'one' : 'other'\n },\n irish(n) {\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n >= 3 && n <= 6) {\n return 'few'\n }\n if (n >= 7 && n <= 10) {\n return 'many'\n }\n return 'other'\n },\n russian(n) {\n const lastTwo = n % 100\n const last = lastTwo % 10\n if (last === 1 && lastTwo !== 11) {\n return 'one'\n }\n if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) {\n return 'few'\n }\n if (\n last === 0 ||\n (last >= 5 && last <= 9) ||\n (lastTwo >= 11 && lastTwo <= 14)\n ) {\n return 'many'\n }\n // Note: The 'other' suffix is only used by decimal numbers in Russian.\n // We don't anticipate it being used, but it's here for consistency.\n return 'other'\n },\n scottish(n) {\n if (n === 1 || n === 11) {\n return 'one'\n }\n if (n === 2 || n === 12) {\n return 'two'\n }\n if ((n >= 3 && n <= 10) || (n >= 13 && n <= 19)) {\n return 'few'\n }\n return 'other'\n },\n spanish(n) {\n if (n === 1) {\n return 'one'\n }\n if (n % 1000000 === 0 && n !== 0) {\n return 'many'\n }\n return 'other'\n },\n welsh(n) {\n if (n === 0) {\n return 'zero'\n }\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n === 3) {\n return 'few'\n }\n if (n === 6) {\n return 'many'\n }\n return 'other'\n }\n }\n}\n\n/**\n * Plural rule category mnemonic tags\n *\n * @internal\n * @typedef {'zero' | 'one' | 'two' | 'few' | 'many' | 'other'} PluralRule\n */\n\n/**\n * Translated message by plural rule they correspond to.\n *\n * Allows to group pluralised messages under a single key when passing\n * translations to a component's constructor\n *\n * @internal\n * @typedef {object} TranslationPluralForms\n * @property {string} [other] - General plural form\n * @property {string} [zero] - Plural form used with 0\n * @property {string} [one] - Plural form used with 1\n * @property {string} [two] - Plural form used with 2\n * @property {string} [few] - Plural form used for a few\n * @property {string} [many] - Plural form used for many\n */\n"],"names":["I18n","constructor","translations","config","_config$locale","locale","document","documentElement","lang","t","lookupKey","options","Error","translation","count","translationPluralForm","getPluralSuffix","match","replacePlaceholders","translationString","formatter","Intl","NumberFormat","supportedLocalesOf","length","undefined","replace","placeholderWithBraces","placeholderKey","Object","prototype","hasOwnProperty","call","placeholderValue","format","hasIntlPluralRulesSupport","Boolean","window","PluralRules","Number","isFinite","preferredForm","select","selectPluralFormUsingFallbackRules","console","warn","Math","abs","floor","ruleset","getPluralRulesForLocale","pluralRules","localeShort","split","pluralRule","pluralRulesMap","languages","includes","arabic","chinese","french","german","irish","russian","scottish","spanish","welsh","n","lastTwo","last"],"mappings":"AAMO,MAAMA,IAAI,CAAC;EAUhBC,WAAWA,CAACC,YAAY,GAAG,EAAE,EAAEC,MAAM,GAAG,EAAE,EAAE;AAAA,IAAA,IAAAC,cAAA;AAAA,IAAA,IAAA,CAT5CF,YAAY,GAAA,MAAA;AAAA,IAAA,IAAA,CACZG,MAAM,GAAA,MAAA;IAUJ,IAAI,CAACH,YAAY,GAAGA,YAAY;AAGhC,IAAA,IAAI,CAACG,MAAM,GAAA,CAAAD,cAAA,GAAGD,MAAM,CAACE,MAAM,KAAAD,IAAAA,GAAAA,cAAA,GAAKE,QAAQ,CAACC,eAAe,CAACC,IAAI,IAAI,IAAK;AACxE;AAaAC,EAAAA,CAACA,CAACC,SAAS,EAAEC,OAAO,EAAE;IACpB,IAAI,CAACD,SAAS,EAAE;AAEd,MAAA,MAAM,IAAIE,KAAK,CAAC,0BAA0B,CAAC;AAC7C;AAGA,IAAA,IAAIC,WAAW,GAAG,IAAI,CAACX,YAAY,CAACQ,SAAS,CAAC;AAK9C,IAAA,IAAI,QAAOC,OAAO,IAAPA,IAAAA,GAAAA,MAAAA,GAAAA,OAAO,CAAEG,KAAK,CAAK,KAAA,QAAQ,IAAI,OAAOD,WAAW,KAAK,QAAQ,EAAE;AACzE,MAAA,MAAME,qBAAqB,GACzBF,WAAW,CAAC,IAAI,CAACG,eAAe,CAACN,SAAS,EAAEC,OAAO,CAACG,KAAK,CAAC,CAAC;AAG7D,MAAA,IAAIC,qBAAqB,EAAE;AACzBF,QAAAA,WAAW,GAAGE,qBAAqB;AACrC;AACF;AAEA,IAAA,IAAI,OAAOF,WAAW,KAAK,QAAQ,EAAE;AAEnC,MAAA,IAAIA,WAAW,CAACI,KAAK,CAAC,WAAW,CAAC,EAAE;QAClC,IAAI,CAACN,OAAO,EAAE;AACZ,U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AE;AAChC,MAAA,OAAO,MAAM;AACf;AACA,IAAA,OAAO,OAAO;GACf;EACDD,KAAKA,CAACC,CAAC,EAAE;IACP,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,MAAM;AACf;IACA,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,KAAK;AACd;IACA,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,KAAK;AACd;IACA,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,KAAK;AACd;IACA,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,MAAM;AACf;AACA,IAAA,OAAO,OAAO;AAChB;AACF,CAAC;;;;"}
|
1
|
+
{"version":3,"file":"i18n.mjs","sources":["../../src/govuk/i18n.mjs"],"sourcesContent":["import { isObject } from './common/index.mjs'\n\n/**\n * Internal support for selecting messages to render, with placeholder\n * interpolation and locale-aware number formatting and pluralisation\n *\n * @internal\n */\nexport class I18n {\n translations\n locale\n\n /**\n * @internal\n * @param {{ [key: string]: string | TranslationPluralForms }} translations - Key-value pairs of the translation strings to use.\n * @param {object} [config] - Configuration options for the function.\n * @param {string | null} [config.locale] - An overriding locale for the PluralRules functionality.\n */\n constructor(translations = {}, config = {}) {\n // Make list of translations available throughout function\n this.translations = translations\n\n // The locale to use for PluralRules and NumberFormat\n this.locale = config.locale ?? (document.documentElement.lang || 'en')\n }\n\n /**\n * The most used function - takes the key for a given piece of UI text and\n * returns the appropriate string.\n *\n * @internal\n * @param {string} lookupKey - The lookup key of the string to use.\n * @param {{ [key: string]: unknown }} [options] - Any options passed with the translation string, e.g: for string interpolation.\n * @returns {string} The appropriate translation string.\n * @throws {Error} Lookup key required\n * @throws {Error} Options required for `${}` placeholders\n */\n t(lookupKey, options) {\n if (!lookupKey) {\n // Print a console error if no lookup key has been provided\n throw new Error('i18n: lookup key missing')\n }\n\n // Fetch the translation for that lookup key\n let translation = this.translations[lookupKey]\n\n // If the `count` option is set, determine which plural suffix is needed and\n // change the lookupKey to match. We check to see if it's numeric instead of\n // falsy, as this could legitimately be 0.\n if (typeof options?.count === 'number' && isObject(translation)) {\n const translationPluralForm =\n translation[this.getPluralSuffix(lookupKey, options.count)]\n\n // Update translation with plural suffix\n if (translationPluralForm) {\n translation = translationPluralForm\n }\n }\n\n if (typeof translation === 'string') {\n // Check for ${} placeholders in the translation string\n // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec\n if (translation.match(/%{(.\\S+)}/)) {\n if (!options) {\n throw new Error(\n 'i18n: cannot replace placeholders in string if no option data provided'\n )\n }\n\n return this.replacePlaceholders(translation, options)\n }\n\n return translation\n }\n\n // If the key wasn't found in our translations object,\n // return the lookup key itself as the fallback\n return lookupKey\n }\n\n /**\n * Takes a translation string with placeholders, and replaces the placeholders\n * with the provided data\n *\n * @internal\n * @param {string} translationString - The translation string\n * @param {{ [key: string]: unknown }} options - Any options passed with the translation string, e.g: for string interpolation.\n * @returns {string} The translation string to output, with $\\{\\} placeholders replaced\n */\n replacePlaceholders(translationString, options) {\n const formatter = Intl.NumberFormat.supportedLocalesOf(this.locale).length\n ? new Intl.NumberFormat(this.locale)\n : undefined\n\n return translationString.replace(\n /%{(.\\S+)}/g,\n\n /**\n * Replace translation string placeholders\n *\n * @internal\n * @param {string} placeholderWithBraces - Placeholder with braces\n * @param {string} placeholderKey - Placeholder key\n * @returns {string} Placeholder value\n */\n function (placeholderWithBraces, placeholderKey) {\n if (Object.prototype.hasOwnProperty.call(options, placeholderKey)) {\n const placeholderValue = options[placeholderKey]\n\n // If a user has passed `false` as the value for the placeholder\n // treat it as though the value should not be displayed\n if (\n placeholderValue === false ||\n (typeof placeholderValue !== 'number' &&\n typeof placeholderValue !== 'string')\n ) {\n return ''\n }\n\n // If the placeholder's value is a number, localise the number formatting\n if (typeof placeholderValue === 'number') {\n return formatter\n ? formatter.format(placeholderValue)\n : `${placeholderValue}`\n }\n\n return placeholderValue\n }\n\n throw new Error(\n `i18n: no data found to replace ${placeholderWithBraces} placeholder in string`\n )\n }\n )\n }\n\n /**\n * Check to see if the browser supports Intl.PluralRules\n *\n * It requires all conditions to be met in order to be supported:\n * - The implementation of Intl supports PluralRules (NOT true in Safari 10–12)\n * - The browser/OS has plural rules for the current locale (browser dependent)\n *\n * {@link https://browsersl.ist/#q=supports+es6-module+and+not+supports+intl-pluralrules}\n *\n * @internal\n * @returns {boolean} Returns true if all conditions are met. Returns false otherwise.\n */\n hasIntlPluralRulesSupport() {\n return Boolean(\n 'PluralRules' in window.Intl &&\n Intl.PluralRules.supportedLocalesOf(this.locale).length\n )\n }\n\n /**\n * Get the appropriate suffix for the plural form.\n *\n * Uses Intl.PluralRules (or our own fallback implementation) to get the\n * 'preferred' form to use for the given count.\n *\n * Checks that a translation has been provided for that plural form – if it\n * hasn't, it'll fall back to the 'other' plural form (unless that doesn't exist\n * either, in which case an error will be thrown)\n *\n * @internal\n * @param {string} lookupKey - The lookup key of the string to use.\n * @param {number} count - Number used to determine which pluralisation to use.\n * @returns {PluralRule} The suffix associated with the correct pluralisation for this locale.\n * @throws {Error} Plural form `.other` required when preferred plural form is missing\n */\n getPluralSuffix(lookupKey, count) {\n // Validate that the number is actually a number.\n //\n // Number(count) will turn anything that can't be converted to a Number type\n // into 'NaN'. isFinite filters out NaN, as it isn't a finite number.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n count = Number(count)\n if (!isFinite(count)) {\n return 'other'\n }\n\n // Fetch the translation for that lookup key\n const translation = this.translations[lookupKey]\n\n // Check to verify that all the requirements for Intl.PluralRules are met.\n // If so, we can use that instead of our custom implementation. Otherwise,\n // use the hardcoded fallback.\n const preferredForm = this.hasIntlPluralRulesSupport()\n ? new Intl.PluralRules(this.locale).select(count)\n : this.selectPluralFormUsingFallbackRules(count)\n\n // Use the correct plural form if provided\n if (isObject(translation)) {\n if (preferredForm in translation) {\n return preferredForm\n // Fall back to `other` if the plural form is missing, but log a warning\n // to the console\n } else if ('other' in translation) {\n console.warn(\n `i18n: Missing plural form \".${preferredForm}\" for \"${this.locale}\" locale. Falling back to \".other\".`\n )\n\n return 'other'\n }\n }\n\n // If the required `other` plural form is missing, all we can do is error\n throw new Error(\n `i18n: Plural form \".other\" is required for \"${this.locale}\" locale`\n )\n }\n\n /**\n * Get the plural form using our fallback implementation\n *\n * This is split out into a separate function to make it easier to test the\n * fallback behaviour in an environment where Intl.PluralRules exists.\n *\n * @internal\n * @param {number} count - Number used to determine which pluralisation to use.\n * @returns {PluralRule} The pluralisation form for count in this locale.\n */\n selectPluralFormUsingFallbackRules(count) {\n // Currently our custom code can only handle positive integers, so let's\n // make sure our number is one of those.\n count = Math.abs(Math.floor(count))\n\n const ruleset = this.getPluralRulesForLocale()\n\n if (ruleset) {\n return I18n.pluralRules[ruleset](count)\n }\n\n return 'other'\n }\n\n /**\n * Work out which pluralisation rules to use for the current locale\n *\n * The locale may include a regional indicator (such as en-GB), but we don't\n * usually care about this part, as pluralisation rules are usually the same\n * regardless of region. There are exceptions, however, (e.g. Portuguese) so\n * this searches by both the full and shortened locale codes, just to be sure.\n *\n * @internal\n * @returns {string | undefined} The name of the pluralisation rule to use (a key for one\n * of the functions in this.pluralRules)\n */\n getPluralRulesForLocale() {\n const localeShort = this.locale.split('-')[0]\n\n // Look through the plural rules map to find which `pluralRule` is\n // appropriate for our current `locale`.\n for (const pluralRule in I18n.pluralRulesMap) {\n const languages = I18n.pluralRulesMap[pluralRule]\n if (languages.includes(this.locale) || languages.includes(localeShort)) {\n return pluralRule\n }\n }\n }\n\n /**\n * Map of plural rules to languages where those rules apply.\n *\n * Note: These groups are named for the most dominant or recognisable language\n * that uses each system. The groupings do not imply that the languages are\n * related to one another. Many languages have evolved the same systems\n * independently of one another.\n *\n * Code to support more languages can be found in the i18n spike:\n * {@link https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs}\n *\n * Languages currently supported:\n *\n * Arabic: Arabic (ar)\n * Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja),\n * Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi)\n * French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi),\n * Persian Farsi (fa), Punjabi (pa), Zulu (zu)\n * German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu),\n * Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en),\n * Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el),\n * Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so),\n * Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr),\n * Urdu (ur)\n * Irish: Irish Gaelic (ga)\n * Russian: Russian (ru), Ukrainian (uk)\n * Scottish: Scottish Gaelic (gd)\n * Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)\n * Welsh: Welsh (cy)\n *\n * @internal\n * @type {{ [key: string]: string[] }}\n */\n static pluralRulesMap = {\n arabic: ['ar'],\n chinese: ['my', 'zh', 'id', 'ja', 'jv', 'ko', 'ms', 'th', 'vi'],\n french: ['hy', 'bn', 'fr', 'gu', 'hi', 'fa', 'pa', 'zu'],\n german: [\n 'af',\n 'sq',\n 'az',\n 'eu',\n 'bg',\n 'ca',\n 'da',\n 'nl',\n 'en',\n 'et',\n 'fi',\n 'ka',\n 'de',\n 'el',\n 'hu',\n 'lb',\n 'no',\n 'so',\n 'sw',\n 'sv',\n 'ta',\n 'te',\n 'tr',\n 'ur'\n ],\n irish: ['ga'],\n russian: ['ru', 'uk'],\n scottish: ['gd'],\n spanish: ['pt-PT', 'it', 'es'],\n welsh: ['cy']\n }\n\n /**\n * Different pluralisation rule sets\n *\n * Returns the appropriate suffix for the plural form associated with `n`.\n * Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual\n * meaning of each differs per locale). 'other' should always exist, even in\n * languages without plurals, such as Chinese.\n * {@link https://cldr.unicode.org/index/cldr-spec/plural-rules}\n *\n * The count must be a positive integer. Negative numbers and decimals aren't accounted for\n *\n * @internal\n * @type {{ [key: string]: (count: number) => PluralRule }}\n */\n static pluralRules = {\n arabic(n) {\n if (n === 0) {\n return 'zero'\n }\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n % 100 >= 3 && n % 100 <= 10) {\n return 'few'\n }\n if (n % 100 >= 11 && n % 100 <= 99) {\n return 'many'\n }\n return 'other'\n },\n chinese() {\n return 'other'\n },\n french(n) {\n return n === 0 || n === 1 ? 'one' : 'other'\n },\n german(n) {\n return n === 1 ? 'one' : 'other'\n },\n irish(n) {\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n >= 3 && n <= 6) {\n return 'few'\n }\n if (n >= 7 && n <= 10) {\n return 'many'\n }\n return 'other'\n },\n russian(n) {\n const lastTwo = n % 100\n const last = lastTwo % 10\n if (last === 1 && lastTwo !== 11) {\n return 'one'\n }\n if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) {\n return 'few'\n }\n if (\n last === 0 ||\n (last >= 5 && last <= 9) ||\n (lastTwo >= 11 && lastTwo <= 14)\n ) {\n return 'many'\n }\n // Note: The 'other' suffix is only used by decimal numbers in Russian.\n // We don't anticipate it being used, but it's here for consistency.\n return 'other'\n },\n scottish(n) {\n if (n === 1 || n === 11) {\n return 'one'\n }\n if (n === 2 || n === 12) {\n return 'two'\n }\n if ((n >= 3 && n <= 10) || (n >= 13 && n <= 19)) {\n return 'few'\n }\n return 'other'\n },\n spanish(n) {\n if (n === 1) {\n return 'one'\n }\n if (n % 1000000 === 0 && n !== 0) {\n return 'many'\n }\n return 'other'\n },\n welsh(n) {\n if (n === 0) {\n return 'zero'\n }\n if (n === 1) {\n return 'one'\n }\n if (n === 2) {\n return 'two'\n }\n if (n === 3) {\n return 'few'\n }\n if (n === 6) {\n return 'many'\n }\n return 'other'\n }\n }\n}\n\n/**\n * Plural rule category mnemonic tags\n *\n * @internal\n * @typedef {'zero' | 'one' | 'two' | 'few' | 'many' | 'other'} PluralRule\n */\n\n/**\n * Translated message by plural rule they correspond to.\n *\n * Allows to group pluralised messages under a single key when passing\n * translations to a component's constructor\n *\n * @internal\n * @typedef {object} TranslationPluralForms\n * @property {string} [other] - General plural form\n * @property {string} [zero] - Plural form used with 0\n * @property {string} [one] - Plural form used with 1\n * @property {string} [two] - Plural form used with 2\n * @property {string} [few] - Plural form used for a few\n * @property {string} [many] - Plural form used for many\n */\n"],"names":["I18n","constructor","translations","config","_config$locale","locale","document","documentElement","lang","t","lookupKey","options","Error","translation","count","isObject","translationPluralForm","getPluralSuffix","match","replacePlaceholders","translationString","formatter","Intl","NumberFormat","supportedLocalesOf","length","undefined","replace","placeholderWithBraces","placeholderKey","Object","prototype","hasOwnProperty","call","placeholderValue","format","hasIntlPluralRulesSupport","Boolean","window","PluralRules","Number","isFinite","preferredForm","select","selectPluralFormUsingFallbackRules","console","warn","Math","abs","floor","ruleset","getPluralRulesForLocale","pluralRules","localeShort","split","pluralRule","pluralRulesMap","languages","includes","arabic","chinese","french","german","irish","russian","scottish","spanish","welsh","n","lastTwo","last"],"mappings":";;AAQO,MAAMA,IAAI,CAAC;EAUhBC,WAAWA,CAACC,YAAY,GAAG,EAAE,EAAEC,MAAM,GAAG,EAAE,EAAE;AAAA,IAAA,IAAAC,cAAA;AAAA,IAAA,IAAA,CAT5CF,YAAY,GAAA,MAAA;AAAA,IAAA,IAAA,CACZG,MAAM,GAAA,MAAA;IAUJ,IAAI,CAACH,YAAY,GAAGA,YAAY;AAGhC,IAAA,IAAI,CAACG,MAAM,GAAA,CAAAD,cAAA,GAAGD,MAAM,CAACE,MAAM,KAAA,IAAA,GAAAD,cAAA,GAAKE,QAAQ,CAACC,eAAe,CAACC,IAAI,IAAI,IAAK;AACxE,EAAA;AAaAC,EAAAA,CAACA,CAACC,SAAS,EAAEC,OAAO,EAAE;IACpB,IAAI,CAACD,SAAS,EAAE;AAEd,MAAA,MAAM,IAAIE,KAAK,CA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;AACd,IAAA;IACA,IAAIA,CAAC,KAAK,CAAC,EAAE;AACX,MAAA,OAAO,MAAM;AACf,IAAA;AACA,IAAA,OAAO,OAAO;AAChB,EAAA;AACF,CAAC;;;;"}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { normaliseOptions } from './common/configuration.mjs';
|
2
|
+
import { isSupported, isObject } from './common/index.mjs';
|
2
3
|
import { Accordion } from './components/accordion/accordion.mjs';
|
3
4
|
import { Button } from './components/button/button.mjs';
|
4
5
|
import { CharacterCount } from './components/character-count/character-count.mjs';
|
@@ -13,7 +14,7 @@ import { Radios } from './components/radios/radios.mjs';
|
|
13
14
|
import { ServiceNavigation } from './components/service-navigation/service-navigation.mjs';
|
14
15
|
import { SkipLink } from './components/skip-link/skip-link.mjs';
|
15
16
|
import { Tabs } from './components/tabs/tabs.mjs';
|
16
|
-
import { SupportError } from './errors/index.mjs';
|
17
|
+
import { SupportError, ElementError } from './errors/index.mjs';
|
17
18
|
|
18
19
|
/**
|
19
20
|
* Initialise all components
|
@@ -21,28 +22,34 @@ import { SupportError } from './errors/index.mjs';
|
|
21
22
|
* Use the `data-module` attributes to find, instantiate and init all of the
|
22
23
|
* components provided as part of GOV.UK Frontend.
|
23
24
|
*
|
24
|
-
* @param {Config
|
25
|
+
* @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
|
25
26
|
*/
|
26
|
-
function initAll(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (
|
31
|
-
|
27
|
+
function initAll(scopeOrConfig = {}) {
|
28
|
+
const config = isObject(scopeOrConfig) ? scopeOrConfig : {};
|
29
|
+
const options = normaliseOptions(scopeOrConfig);
|
30
|
+
try {
|
31
|
+
if (!isSupported()) {
|
32
|
+
throw new SupportError();
|
33
|
+
}
|
34
|
+
if (options.scope === null) {
|
35
|
+
throw new ElementError({
|
36
|
+
element: options.scope,
|
37
|
+
identifier: 'GOV.UK Frontend scope element (`$scope`)'
|
38
|
+
});
|
39
|
+
}
|
40
|
+
} catch (error) {
|
41
|
+
if (options.onError) {
|
42
|
+
options.onError(error, {
|
32
43
|
config
|
33
44
|
});
|
34
45
|
} else {
|
35
|
-
console.log(
|
46
|
+
console.log(error);
|
36
47
|
}
|
37
48
|
return;
|
38
49
|
}
|
39
50
|
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]];
|
40
|
-
|
41
|
-
|
42
|
-
onError: config.onError
|
43
|
-
};
|
44
|
-
components.forEach(([Component, config]) => {
|
45
|
-
createAll(Component, config, options);
|
51
|
+
components.forEach(([Component, componentConfig]) => {
|
52
|
+
createAll(Component, componentConfig, options);
|
46
53
|
});
|
47
54
|
}
|
48
55
|
|
@@ -58,42 +65,42 @@ function initAll(config) {
|
|
58
65
|
* @template {CompatibleClass} ComponentClass
|
59
66
|
* @param {ComponentClass} Component - class of the component to create
|
60
67
|
* @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
|
61
|
-
* @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass>
|
68
|
+
* @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
|
62
69
|
* @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
|
63
70
|
*/
|
64
|
-
function createAll(Component, config,
|
65
|
-
let $
|
66
|
-
|
67
|
-
|
68
|
-
var
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if (onError) {
|
82
|
-
onError(
|
71
|
+
function createAll(Component, config, scopeOrOptions) {
|
72
|
+
let $elements;
|
73
|
+
const options = normaliseOptions(scopeOrOptions);
|
74
|
+
try {
|
75
|
+
var _options$scope;
|
76
|
+
if (!isSupported()) {
|
77
|
+
throw new SupportError();
|
78
|
+
}
|
79
|
+
if (options.scope === null) {
|
80
|
+
throw new ElementError({
|
81
|
+
element: options.scope,
|
82
|
+
component: Component,
|
83
|
+
identifier: 'Scope element (`$scope`)'
|
84
|
+
});
|
85
|
+
}
|
86
|
+
$elements = (_options$scope = options.scope) == null ? void 0 : _options$scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
|
87
|
+
} catch (error) {
|
88
|
+
if (options.onError) {
|
89
|
+
options.onError(error, {
|
83
90
|
component: Component,
|
84
91
|
config
|
85
92
|
});
|
86
93
|
} else {
|
87
|
-
console.log(
|
94
|
+
console.log(error);
|
88
95
|
}
|
89
96
|
return [];
|
90
97
|
}
|
91
|
-
return Array.from($elements).map($element => {
|
98
|
+
return Array.from($elements != null ? $elements : []).map($element => {
|
92
99
|
try {
|
93
100
|
return typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
|
94
101
|
} catch (error) {
|
95
|
-
if (onError) {
|
96
|
-
onError(error, {
|
102
|
+
if (options.onError) {
|
103
|
+
options.onError(error, {
|
97
104
|
element: $element,
|
98
105
|
component: Component,
|
99
106
|
config
|
@@ -112,6 +119,8 @@ function createAll(Component, config, createAllOptions) {
|
|
112
119
|
* Config for all components via `initAll()`
|
113
120
|
*
|
114
121
|
* @typedef {object} Config
|
122
|
+
* @property {Element | Document | null} [scope] - Scope of the document to search within
|
123
|
+
* @property {OnErrorCallback<CompatibleClass>} [onError] - Initialisation error callback
|
115
124
|
* @property {AccordionConfig} [accordion] - Accordion config
|
116
125
|
* @property {ButtonConfig} [button] - Button config
|
117
126
|
* @property {CharacterCountConfig} [characterCount] - Character Count config
|
@@ -136,7 +145,7 @@ function createAll(Component, config, createAllOptions) {
|
|
136
145
|
/**
|
137
146
|
* Component config keys, e.g. `accordion` and `characterCount`
|
138
147
|
*
|
139
|
-
* @typedef {keyof Config} ConfigKey
|
148
|
+
* @typedef {keyof Omit<Config, 'scope' | 'onError'>} ConfigKey
|
140
149
|
*/
|
141
150
|
/**
|
142
151
|
* @template {CompatibleClass} ComponentClass
|
@@ -147,7 +156,7 @@ function createAll(Component, config, createAllOptions) {
|
|
147
156
|
* @typedef {object} ErrorContext
|
148
157
|
* @property {Element} [element] - Element used for component module initialisation
|
149
158
|
* @property {ComponentClass} [component] - Class of component
|
150
|
-
* @property {ComponentConfig<ComponentClass>} config - Config supplied to
|
159
|
+
* @property {Config | ComponentConfig<ComponentClass>} [config] - Config supplied to components
|
151
160
|
*/
|
152
161
|
/**
|
153
162
|
* @template {CompatibleClass} ComponentClass
|
@@ -158,7 +167,7 @@ function createAll(Component, config, createAllOptions) {
|
|
158
167
|
/**
|
159
168
|
* @template {CompatibleClass} ComponentClass
|
160
169
|
* @typedef {object} CreateAllOptions
|
161
|
-
* @property {Element | Document} [scope] - scope of the document to search within
|
170
|
+
* @property {Element | Document | null} [scope] - scope of the document to search within
|
162
171
|
* @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init
|
163
172
|
*/
|
164
173
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.mjs","sources":["../../src/govuk/init.mjs"],"sourcesContent":["import { isSupported } from './common/index.mjs'\nimport { Accordion } from './components/accordion/accordion.mjs'\nimport { Button } from './components/button/button.mjs'\nimport { CharacterCount } from './components/character-count/character-count.mjs'\nimport { Checkboxes } from './components/checkboxes/checkboxes.mjs'\nimport { ErrorSummary } from './components/error-summary/error-summary.mjs'\nimport { ExitThisPage } from './components/exit-this-page/exit-this-page.mjs'\nimport { FileUpload } from './components/file-upload/file-upload.mjs'\nimport { Header } from './components/header/header.mjs'\nimport { NotificationBanner } from './components/notification-banner/notification-banner.mjs'\nimport { PasswordInput } from './components/password-input/password-input.mjs'\nimport { Radios } from './components/radios/radios.mjs'\nimport { ServiceNavigation } from './components/service-navigation/service-navigation.mjs'\nimport { SkipLink } from './components/skip-link/skip-link.mjs'\nimport { Tabs } from './components/tabs/tabs.mjs'\nimport { SupportError } from './errors/index.mjs'\n\n/**\n * Initialise all components\n *\n * Use the `data-module` attributes to find, instantiate and init all of the\n * components provided as part of GOV.UK Frontend.\n *\n * @param {Config & { scope?: Element, onError?: OnErrorCallback<CompatibleClass> }} [config] - Config for all components (with optional scope)\n */\nfunction initAll(config) {\n config = typeof config !== 'undefined' ? config : {}\n\n // Skip initialisation when GOV.UK Frontend is not supported\n if (!isSupported()) {\n if (config.onError) {\n config.onError(new SupportError(), {\n config\n })\n } else {\n console.log(new SupportError())\n }\n return\n }\n\n const components = /** @type {const} */ ([\n [Accordion, config.accordion],\n [Button, config.button],\n [CharacterCount, config.characterCount],\n [Checkboxes],\n [ErrorSummary, config.errorSummary],\n [ExitThisPage, config.exitThisPage],\n [FileUpload, config.fileUpload],\n [Header],\n [NotificationBanner, config.notificationBanner],\n [PasswordInput, config.passwordInput],\n [Radios],\n [ServiceNavigation],\n [SkipLink],\n [Tabs]\n ])\n\n // Allow the user to initialise GOV.UK Frontend in only certain sections of the page\n // Defaults to the entire document if nothing is set.\n // const $scope = config.scope ?? document\n\n const options = {\n scope: config.scope ?? document,\n onError: config.onError\n }\n\n components.forEach(([Component, config]) => {\n createAll(Component, config, options)\n })\n}\n\n/**\n * Create all instances of a specific component on the page\n *\n * Uses the `data-module` attribute to find all elements matching the specified\n * component on the page, creating instances of the component object for each\n * of them.\n *\n * Any component errors will be caught and logged to the console.\n *\n * @template {CompatibleClass} ComponentClass\n * @param {ComponentClass} Component - class of the component to create\n * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component\n * @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\n * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components\n */\nfunction createAll(Component, config, createAllOptions) {\n let /** @type {Element | Document} */ $scope = document\n let /** @type {OnErrorCallback<Component> | undefined} */ onError\n\n if (typeof createAllOptions === 'object') {\n createAllOptions = /** @type {CreateAllOptions<Component>} */ (\n // eslint-disable-next-line no-self-assign\n createAllOptions\n )\n\n $scope = createAllOptions.scope ?? $scope\n onError = createAllOptions.onError\n }\n\n if (typeof createAllOptions === 'function') {\n onError = createAllOptions\n }\n\n if (createAllOptions instanceof HTMLElement) {\n $scope = createAllOptions\n }\n\n const $elements = $scope.querySelectorAll(\n `[data-module=\"${Component.moduleName}\"]`\n )\n\n // Skip initialisation when GOV.UK Frontend is not supported\n if (!isSupported()) {\n if (onError) {\n onError(new SupportError(), {\n component: Component,\n config\n })\n } else {\n console.log(new SupportError())\n }\n return []\n }\n\n /* eslint-disable-next-line @typescript-eslint/no-unsafe-return --\n * We can't define CompatibleClass as `{new(): CompatibleClass, moduleName: string}`,\n * as when doing `typeof Accordion` (or any component), TypeScript doesn't seem\n * to acknowledge the static `moduleName` that's set in our component classes.\n * This means we have to set the constructor of `CompatibleClass` as `{new(): any}`,\n * leading to ESLint frowning that we're returning `any[]`.\n */\n return Array.from($elements)\n .map(($element) => {\n try {\n // Only pass config to components that accept it\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return typeof config !== 'undefined'\n ? new Component($element, config)\n : new Component($element)\n } catch (error) {\n if (onError) {\n onError(error, {\n element: $element,\n component: Component,\n config\n })\n } else {\n console.log(error)\n }\n\n return null\n }\n })\n .filter(Boolean) // Exclude components that errored\n}\n\nexport { initAll, createAll }\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef {{new (...args: any[]): any, moduleName: string}} CompatibleClass\n */\n\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Config for all components via `initAll()`\n *\n * @typedef {object} Config\n * @property {AccordionConfig} [accordion] - Accordion config\n * @property {ButtonConfig} [button] - Button config\n * @property {CharacterCountConfig} [characterCount] - Character Count config\n * @property {ErrorSummaryConfig} [errorSummary] - Error Summary config\n * @property {ExitThisPageConfig} [exitThisPage] - Exit This Page config\n * @property {FileUploadConfig} [fileUpload] - File Upload config\n * @property {NotificationBannerConfig} [notificationBanner] - Notification Banner config\n * @property {PasswordInputConfig} [passwordInput] - Password input config\n */\n\n/**\n * Config for individual components\n *\n * @import { AccordionConfig } from './components/accordion/accordion.mjs'\n * @import { ButtonConfig } from './components/button/button.mjs'\n * @import { CharacterCountConfig } from './components/character-count/character-count.mjs'\n * @import { ErrorSummaryConfig } from './components/error-summary/error-summary.mjs'\n * @import { ExitThisPageConfig } from './components/exit-this-page/exit-this-page.mjs'\n * @import { NotificationBannerConfig } from './components/notification-banner/notification-banner.mjs'\n * @import { PasswordInputConfig } from './components/password-input/password-input.mjs'\n * @import { FileUploadConfig } from './components/file-upload/file-upload.mjs'\n */\n\n/**\n * Component config keys, e.g. `accordion` and `characterCount`\n *\n * @typedef {keyof Config} ConfigKey\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {ConstructorParameters<ComponentClass>[1]} ComponentConfig\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {object} ErrorContext\n * @property {Element} [element] - Element used for component module initialisation\n * @property {ComponentClass} [component] - Class of component\n * @property {ComponentConfig<ComponentClass>} config - Config supplied to component\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @callback OnErrorCallback\n * @param {unknown} error - Thrown error\n * @param {ErrorContext<ComponentClass>} context - Object containing the element, component class and configuration\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {object} CreateAllOptions\n * @property {Element | Document} [scope] - scope of the document to search within\n * @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init\n */\n"],"names":["initAll","config","_config$scope","isSupported","onError","SupportError","console","log","components","Accordion","accordion","Button","button","CharacterCount","characterCount","Checkboxes","ErrorSummary","errorSummary","ExitThisPage","exitThisPage","FileUpload","fileUpload","Header","NotificationBanner","notificationBanner","PasswordInput","passwordInput","Radios","ServiceNavigation","SkipLink","Tabs","options","scope","document","forEach","Component","createAll","createAllOptions","$scope","_createAllOptions$sco","HTMLElement","$elements","querySelectorAll","moduleName","component","Array","from","map","$element","error","element","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAOA,CAACC,MAAM,EAAE;AAAA,EAAA,IAAAC,aAAA;EACvBD,MAAM,GAAG,OAAOA,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAG,EAAE;AAGpD,EAAA,IAAI,CAACE,WAAW,EAAE,EAAE;IAClB,IAAIF,MAAM,CAACG,OAAO,EAAE;AAClBH,MAAAA,MAAM,CAACG,OAAO,CAAC,IAAIC,YAAY,EAAE,EAAE;AACjCJ,QAAAA;AACF,OAAC,CAAC;AACJ,KAAC,MAAM;AACLK,MAAAA,OAAO,CAACC,GAAG,CAAC,IAAIF,YAAY,EAAE,CAAC;AACjC;AACA,IAAA;AACF;AAEA,EAAA,MAAMG,UAAU,GAAyB,CACvC,CAACC,SAAS,EAAER,MAAM,CAACS,SAAS,CAAC,EAC7B,CAACC,MAAM,EAAEV,MAAM,CAACW,MAAM,CAAC,EACvB,CAACC,cAAc,EAAEZ,MAAM,CAACa,cAAc,CAAC,EACvC,CAACC,UAAU,CAAC,EACZ,CAACC,YAAY,EAAEf,MAAM,CAACgB,YAAY,CAAC,EACnC,CAACC,YAAY,EAAEjB,MAAM,CAACkB,YAAY,CAAC,EACnC,CAACC,UAAU,EAAEnB,MAAM,CAACoB,UAAU,CAAC,EAC/B,CAACC,MAAM,CAAC,EACR,CAACC,kBAAkB,EAAEtB,MAAM,CAACuB,kBAAkB,CAAC,EAC/C,CAACC,aAAa,EAAExB,MAAM,CAACyB,aAAa,CAAC,EACrC,CAACC,MAAM,CAAC,EAC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;AAClB,IAAA,IAAIC,OAAO,EAAE;AACXA,MAAAA,OAAO,CAAC,IAAIC,YAAY,EAAE,EAAE;AAC1BuC,QAAAA,SAAS,EAAET,SAAS;AACpBlC,QAAAA;AACF,OAAC,CAAC;AACJ,KAAC,MAAM;AACLK,MAAAA,OAAO,CAACC,GAAG,CAAC,IAAIF,YAAY,EAAE,CAAC;AACjC;AACA,IAAA,OAAO,EAAE;AACX;EASA,OAAOwC,KAAK,CAACC,IAAI,CAACL,SAAS,CAAC,CACzBM,GAAG,CAAEC,QAAQ,IAAK;IACjB,IAAI;AAGF,MAAA,OAAO,OAAO/C,MAAM,KAAK,WAAW,GAChC,IAAIkC,SAAS,CAACa,QAAQ,EAAE/C,MAAM,CAAC,GAC/B,IAAIkC,SAAS,CAACa,QAAQ,CAAC;KAC5B,CAAC,OAAOC,KAAK,EAAE;AACd,MAAA,IAAI7C,OAAO,EAAE;QACXA,OAAO,CAAC6C,KAAK,EAAE;AACbC,UAAAA,OAAO,EAAEF,QAAQ;AACjBJ,UAAAA,SAAS,EAAET,SAAS;AACpBlC,UAAAA;AACF,SAAC,CAAC;AACJ,OAAC,MAAM;AACLK,QAAAA,OAAO,CAACC,GAAG,CAAC0C,KAAK,CAAC;AACpB;AAEA,MAAA,OAAO,IAAI;AACb;AACF,GAAC,CAAC,CACDE,MAAM,CAACC,OAAO,CAAC;AACpB;AAUA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
1
|
+
{"version":3,"file":"init.mjs","sources":["../../src/govuk/init.mjs"],"sourcesContent":["import { normaliseOptions } from './common/configuration.mjs'\nimport { isObject, isSupported } from './common/index.mjs'\nimport { Accordion } from './components/accordion/accordion.mjs'\nimport { Button } from './components/button/button.mjs'\nimport { CharacterCount } from './components/character-count/character-count.mjs'\nimport { Checkboxes } from './components/checkboxes/checkboxes.mjs'\nimport { ErrorSummary } from './components/error-summary/error-summary.mjs'\nimport { ExitThisPage } from './components/exit-this-page/exit-this-page.mjs'\nimport { FileUpload } from './components/file-upload/file-upload.mjs'\nimport { Header } from './components/header/header.mjs'\nimport { NotificationBanner } from './components/notification-banner/notification-banner.mjs'\nimport { PasswordInput } from './components/password-input/password-input.mjs'\nimport { Radios } from './components/radios/radios.mjs'\nimport { ServiceNavigation } from './components/service-navigation/service-navigation.mjs'\nimport { SkipLink } from './components/skip-link/skip-link.mjs'\nimport { Tabs } from './components/tabs/tabs.mjs'\nimport { ElementError, SupportError } from './errors/index.mjs'\n\n/**\n * Initialise all components\n *\n * Use the `data-module` attributes to find, instantiate and init all of the\n * components provided as part of GOV.UK Frontend.\n *\n * @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)\n */\nfunction initAll(scopeOrConfig = {}) {\n const config = isObject(scopeOrConfig) ? scopeOrConfig : {}\n\n // Extract initialisation options\n const options = normaliseOptions(scopeOrConfig)\n\n try {\n // Skip initialisation when GOV.UK Frontend is not supported\n if (!isSupported()) {\n throw new SupportError()\n }\n\n // Users can initialise GOV.UK Frontend in certain sections of the page\n // unless the scope is null (for example, query selector not found)\n if (options.scope === null) {\n throw new ElementError({\n element: options.scope,\n identifier: 'GOV.UK Frontend scope element (`$scope`)'\n })\n }\n } catch (error) {\n if (options.onError) {\n options.onError(error, {\n config\n })\n } else {\n console.log(error)\n }\n\n return\n }\n\n const components = /** @type {const} */ ([\n [Accordion, config.accordion],\n [Button, config.button],\n [CharacterCount, config.characterCount],\n [Checkboxes],\n [ErrorSummary, config.errorSummary],\n [ExitThisPage, config.exitThisPage],\n [FileUpload, config.fileUpload],\n [Header],\n [NotificationBanner, config.notificationBanner],\n [PasswordInput, config.passwordInput],\n [Radios],\n [ServiceNavigation],\n [SkipLink],\n [Tabs]\n ])\n\n components.forEach(([Component, componentConfig]) => {\n createAll(Component, componentConfig, options)\n })\n}\n\n/**\n * Create all instances of a specific component on the page\n *\n * Uses the `data-module` attribute to find all elements matching the specified\n * component on the page, creating instances of the component object for each\n * of them.\n *\n * Any component errors will be caught and logged to the console.\n *\n * @template {CompatibleClass} ComponentClass\n * @param {ComponentClass} Component - class of the component to create\n * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component\n * @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\n * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components\n */\nfunction createAll(Component, config, scopeOrOptions) {\n let /** @type {NodeListOf<Element> | undefined} */ $elements\n\n // Extract initialisation options\n const options = normaliseOptions(scopeOrOptions)\n\n try {\n // Skip initialisation when GOV.UK Frontend is not supported\n if (!isSupported()) {\n throw new SupportError()\n }\n\n // Users can initialise GOV.UK Frontend in certain sections of the page\n // unless the scope is null (for example, query selector not found)\n if (options.scope === null) {\n throw new ElementError({\n element: options.scope,\n component: Component,\n identifier: 'Scope element (`$scope`)'\n })\n }\n\n $elements = options.scope?.querySelectorAll(\n `[data-module=\"${Component.moduleName}\"]`\n )\n } catch (error) {\n if (options.onError) {\n options.onError(error, {\n component: Component,\n config\n })\n } else {\n console.log(error)\n }\n\n return []\n }\n\n /* eslint-disable-next-line @typescript-eslint/no-unsafe-return --\n * We can't define CompatibleClass as `{new(): CompatibleClass, moduleName: string}`,\n * as when doing `typeof Accordion` (or any component), TypeScript doesn't seem\n * to acknowledge the static `moduleName` that's set in our component classes.\n * This means we have to set the constructor of `CompatibleClass` as `{new(): any}`,\n * leading to ESLint frowning that we're returning `any[]`.\n */\n return Array.from($elements ?? [])\n .map(($element) => {\n try {\n // Only pass config to components that accept it\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return typeof config !== 'undefined'\n ? new Component($element, config)\n : new Component($element)\n } catch (error) {\n if (options.onError) {\n options.onError(error, {\n element: $element,\n component: Component,\n config\n })\n } else {\n console.log(error)\n }\n\n return null\n }\n })\n .filter(Boolean) // Exclude components that errored\n}\n\nexport { initAll, createAll }\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef {{new (...args: any[]): any, moduleName: string}} CompatibleClass\n */\n\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Config for all components via `initAll()`\n *\n * @typedef {object} Config\n * @property {Element | Document | null} [scope] - Scope of the document to search within\n * @property {OnErrorCallback<CompatibleClass>} [onError] - Initialisation error callback\n * @property {AccordionConfig} [accordion] - Accordion config\n * @property {ButtonConfig} [button] - Button config\n * @property {CharacterCountConfig} [characterCount] - Character Count config\n * @property {ErrorSummaryConfig} [errorSummary] - Error Summary config\n * @property {ExitThisPageConfig} [exitThisPage] - Exit This Page config\n * @property {FileUploadConfig} [fileUpload] - File Upload config\n * @property {NotificationBannerConfig} [notificationBanner] - Notification Banner config\n * @property {PasswordInputConfig} [passwordInput] - Password input config\n */\n\n/**\n * Config for individual components\n *\n * @import { AccordionConfig } from './components/accordion/accordion.mjs'\n * @import { ButtonConfig } from './components/button/button.mjs'\n * @import { CharacterCountConfig } from './components/character-count/character-count.mjs'\n * @import { ErrorSummaryConfig } from './components/error-summary/error-summary.mjs'\n * @import { ExitThisPageConfig } from './components/exit-this-page/exit-this-page.mjs'\n * @import { NotificationBannerConfig } from './components/notification-banner/notification-banner.mjs'\n * @import { PasswordInputConfig } from './components/password-input/password-input.mjs'\n * @import { FileUploadConfig } from './components/file-upload/file-upload.mjs'\n */\n\n/**\n * Component config keys, e.g. `accordion` and `characterCount`\n *\n * @typedef {keyof Omit<Config, 'scope' | 'onError'>} ConfigKey\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {ConstructorParameters<ComponentClass>[1]} ComponentConfig\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {object} ErrorContext\n * @property {Element} [element] - Element used for component module initialisation\n * @property {ComponentClass} [component] - Class of component\n * @property {Config | ComponentConfig<ComponentClass>} [config] - Config supplied to components\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @callback OnErrorCallback\n * @param {unknown} error - Thrown error\n * @param {ErrorContext<ComponentClass>} context - Object containing the element, component class and configuration\n */\n\n/**\n * @template {CompatibleClass} ComponentClass\n * @typedef {object} CreateAllOptions\n * @property {Element | Document | null} [scope] - scope of the document to search within\n * @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init\n */\n"],"names":["initAll","scopeOrConfig","config","isObject","options","normaliseOptions","isSupported","SupportError","scope","ElementError","element","identifier","error","onError","console","log","components","Accordion","accordion","Button","button","CharacterCount","characterCount","Checkboxes","ErrorSummary","errorSummary","ExitThisPage","exitThisPage","FileUpload","fileUpload","Header","NotificationBanner","notificationBanner","PasswordInput","passwordInput","Radios","ServiceNavigation","SkipLink","Tabs","forEach","Component","componentConfig","createAll","scopeOrOptions","$elements","_options$scope","component","querySelectorAll","moduleName","Array","from","map","$element","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAOA,CAACC,aAAa,GAAG,EAAE,EAAE;EACnC,MAAMC,MAAM,GAAGC,QAAQ,CAACF,aAAa,CAAC,GAAGA,aAAa,GAAG,EAAE;AAG3D,EAAA,MAAMG,OAAO,GAAGC,gBAAgB,CAACJ,aAAa,CAAC;EAE/C,IAAI;AAEF,IAAA,IAAI,CAACK,WAAW,EAAE,EAAE;MAClB,MAAM,IAAIC,YAAY,EAAE;AAC1B,IAAA;AAIA,IAAA,IAAIH,OAAO,CA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,QAAQ,EAAElD,MAAM,CAAC,GAC/B,IAAIsC,SAAS,CAACY,QAAQ,CAAC;IAC7B,CAAC,CAAC,OAAOxC,KAAK,EAAE;MACd,IAAIR,OAAO,CAACS,OAAO,EAAE;AACnBT,QAAAA,OAAO,CAACS,OAAO,CAACD,KAAK,EAAE;AACrBF,UAAAA,OAAO,EAAE0C,QAAQ;AACjBN,UAAAA,SAAS,EAAEN,SAAS;AACpBtC,UAAAA;AACF,SAAC,CAAC;AACJ,MAAA,CAAC,MAAM;AACLY,QAAAA,OAAO,CAACC,GAAG,CAACH,KAAK,CAAC;AACpB,MAAA;AAEA,MAAA,OAAO,IAAI;AACb,IAAA;AACF,EAAA,CAAC,CAAC,CACDyC,MAAM,CAACC,OAAO,CAAC;AACpB;AAUA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
"description": "GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.",
|
4
4
|
"urls": {
|
5
5
|
"documentation": "https://design-system.service.gov.uk/",
|
6
|
-
"releaseNotes": "https://github.com/alphagov/govuk-frontend/releases/tag/v5.11.
|
6
|
+
"releaseNotes": "https://github.com/alphagov/govuk-frontend/releases/tag/v5.11.2",
|
7
7
|
"versionHistory": "https://github.com/alphagov/govuk-frontend/releases"
|
8
8
|
}
|
9
9
|
},
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "govuk-frontend",
|
3
3
|
"description": "GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.",
|
4
|
-
"version": "5.11.
|
4
|
+
"version": "5.11.2",
|
5
5
|
"main": "dist/govuk/all.bundle.js",
|
6
6
|
"module": "dist/govuk/all.mjs",
|
7
7
|
"sass": "dist/govuk/index.scss",
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"build:package": "gulp build:package --color",
|
55
55
|
"build:release": "gulp build:release --color",
|
56
56
|
"build:stats": "npm run stats --workspace @govuk-frontend/stats",
|
57
|
-
"build:types": "tsc --build tsconfig.
|
57
|
+
"build:types": "tsc --build tsconfig.json",
|
58
58
|
"clean": "npm run clean:package",
|
59
59
|
"clean:package": "del-cli *.tsbuildinfo dist govuk-prototype-kit.config.json",
|
60
60
|
"clean:release": "del-cli ../../dist --force",
|
@@ -69,23 +69,23 @@
|
|
69
69
|
"@govuk-frontend/lib": "*",
|
70
70
|
"@govuk-frontend/tasks": "*",
|
71
71
|
"@rollup/plugin-babel": "^6.0.4",
|
72
|
-
"@rollup/plugin-replace": "^
|
72
|
+
"@rollup/plugin-replace": "^6.0.2",
|
73
73
|
"@rollup/plugin-terser": "^0.4.4",
|
74
74
|
"autoprefixer": "^10.4.21",
|
75
|
-
"cssnano": "^7.0
|
75
|
+
"cssnano": "^7.1.0",
|
76
76
|
"cssnano-preset-default": "^7.0.1",
|
77
|
-
"govuk-prototype-kit": "^13.
|
78
|
-
"gulp": "^5.0.
|
77
|
+
"govuk-prototype-kit": "^13.18.0",
|
78
|
+
"gulp": "^5.0.1",
|
79
79
|
"gulp-cli": "^3.0.0",
|
80
|
-
"html-validate": "9.
|
80
|
+
"html-validate": "9.7.1",
|
81
81
|
"nunjucks": "^3.2.4",
|
82
82
|
"outdent": "^0.8.0",
|
83
|
-
"postcss": "^8.5.
|
83
|
+
"postcss": "^8.5.6",
|
84
84
|
"postcss-scss": "^4.0.9",
|
85
|
-
"puppeteer": "^24.
|
86
|
-
"rollup": "^4.
|
85
|
+
"puppeteer": "^24.15.0",
|
86
|
+
"rollup": "^4.46.2",
|
87
87
|
"sass-color-helpers": "^2.1.1",
|
88
|
-
"sass-embedded": "^1.
|
88
|
+
"sass-embedded": "^1.89.2",
|
89
89
|
"sassdoc": "^2.7.4",
|
90
90
|
"slash": "^5.1.0"
|
91
91
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 60.
|
4
|
+
version: 60.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -177,6 +177,20 @@ dependencies:
|
|
177
177
|
- - ">="
|
178
178
|
- !ruby/object:Gem::Version
|
179
179
|
version: '0'
|
180
|
+
- !ruby/object:Gem::Dependency
|
181
|
+
name: erb_lint
|
182
|
+
requirement: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
type: :development
|
188
|
+
prerelease: false
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
180
194
|
- !ruby/object:Gem::Dependency
|
181
195
|
name: faker
|
182
196
|
requirement: !ruby/object:Gem::Requirement
|