govuk_tech_docs 5.2.1 → 6.0.0.beta
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/.github/dependabot.yml +59 -0
- data/.npmrc +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +13 -4
- data/example/config/tech-docs.yml +1 -1
- data/govuk_tech_docs.gemspec +2 -2
- data/lib/assets/stylesheets/_core.scss +1 -0
- data/lib/assets/stylesheets/_govuk_tech_docs.scss +13 -15
- data/lib/assets/stylesheets/modules/_app-pane.scss +3 -3
- data/lib/assets/stylesheets/modules/_page-review.scss +4 -4
- data/lib/assets/stylesheets/modules/_search.scss +3 -3
- data/lib/assets/stylesheets/modules/_service-navigation.scss +5 -0
- data/lib/assets/stylesheets/modules/_technical-documentation.scss +7 -7
- data/lib/assets/stylesheets/modules/_toc.scss +13 -13
- data/lib/assets/stylesheets/palette/_syntax-highlighting.scss +9 -7
- data/lib/govuk_tech_docs/meta_tags.rb +1 -1
- data/lib/govuk_tech_docs/version.rb +1 -1
- data/lib/source/layouts/_header.erb +2 -16
- data/lib/source/layouts/_service_navigation.erb +27 -0
- data/lib/source/layouts/core.erb +7 -7
- data/node_modules/govuk-frontend/dist/govuk/_base.scss +1 -0
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +183 -300
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +184 -300
- data/node_modules/govuk-frontend/dist/govuk/all.mjs +0 -1
- data/node_modules/govuk-frontend/dist/govuk/assets/images/favicon.ico +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/images/favicon.svg +1 -1
- data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-180.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-192.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-512.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-opengraph-image.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +29 -2
- 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/components/accordion/_index.scss +18 -15
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +14 -137
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +14 -137
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/back-link/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/breadcrumbs/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/button/_index.scss +18 -21
- 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.mjs +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +30 -143
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +30 -143
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +20 -10
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/_index.scss +7 -6
- 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.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/_index.scss +2 -5
- data/node_modules/govuk-frontend/dist/govuk/components/date-input/_index.scss +5 -0
- data/node_modules/govuk-frontend/dist/govuk/components/details/_index.scss +6 -4
- data/node_modules/govuk-frontend/dist/govuk/components/error-message/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/_index.scss +4 -2
- 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.mjs +8 -12
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +10 -133
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +10 -133
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/_index.scss +30 -38
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js +46 -140
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs +46 -140
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs +36 -7
- data/node_modules/govuk-frontend/dist/govuk/components/footer/_index.scss +30 -27
- data/node_modules/govuk-frontend/dist/govuk/components/header/_index.scss +89 -449
- data/node_modules/govuk-frontend/dist/govuk/components/hint/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/input/_index.scss +14 -20
- data/node_modules/govuk-frontend/dist/govuk/components/inset-text/_index.scss +2 -1
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/_index.scss +10 -8
- 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.mjs +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss +16 -11
- data/node_modules/govuk-frontend/dist/govuk/components/panel/_index.scss +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +10 -133
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +10 -133
- data/node_modules/govuk-frontend/dist/govuk/components/phase-banner/_index.scss +12 -6
- data/node_modules/govuk-frontend/dist/govuk/components/radios/_index.scss +8 -7
- 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.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/select/_index.scss +6 -11
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_index.scss +58 -74
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +40 -7
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +40 -7
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.mjs +30 -2
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss +8 -4
- 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.mjs +12 -19
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +3 -9
- data/node_modules/govuk-frontend/dist/govuk/components/summary-list/_index.scss +25 -21
- data/node_modules/govuk-frontend/dist/govuk/components/table/_index.scss +7 -8
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/_index.scss +9 -6
- 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.mjs +12 -13
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs +3 -3
- data/node_modules/govuk-frontend/dist/govuk/components/tag/_index.scss +66 -31
- data/node_modules/govuk-frontend/dist/govuk/components/task-list/_index.scss +7 -5
- data/node_modules/govuk-frontend/dist/govuk/components/textarea/_index.scss +5 -10
- data/node_modules/govuk-frontend/dist/govuk/components/warning-text/_index.scss +5 -4
- data/node_modules/govuk-frontend/dist/govuk/core/_index.scss +0 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_lists.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/core/_section-break.scss +2 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_typography.scss +6 -20
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_breakpoints.scss +17 -0
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_frontend-version.scss +15 -0
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_functional-colours.scss +17 -0
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_index.scss +5 -0
- data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +5 -3
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_colour.scss +187 -72
- data/node_modules/govuk-frontend/dist/govuk/helpers/_focused.scss +41 -6
- data/node_modules/govuk-frontend/dist/govuk/helpers/_grid.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_links.scss +24 -40
- data/node_modules/govuk-frontend/dist/govuk/helpers/_media-queries.scss +172 -33
- data/node_modules/govuk-frontend/dist/govuk/helpers/_spacing.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_typography.scss +6 -30
- data/node_modules/govuk-frontend/dist/govuk/helpers/_visually-hidden.scss +4 -1
- data/node_modules/govuk-frontend/dist/govuk/i18n.mjs +5 -128
- data/node_modules/govuk-frontend/dist/govuk/init.mjs +53 -45
- data/node_modules/govuk-frontend/dist/govuk/objects/_button-group.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/objects/_form-group.scss +2 -1
- data/node_modules/govuk-frontend/dist/govuk/objects/_main-wrapper.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/objects/_template.scss +3 -7
- data/node_modules/govuk-frontend/dist/govuk/objects/_width-container.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/overrides/_display.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/overrides/_typography.scss +0 -2
- data/node_modules/govuk-frontend/dist/govuk/overrides/_width.scss +5 -5
- data/node_modules/govuk-frontend/dist/govuk/settings/_colours-applied.scss +3 -188
- data/node_modules/govuk-frontend/dist/govuk/settings/_colours-functional.scss +366 -0
- data/node_modules/govuk-frontend/dist/govuk/settings/_colours-organisations.scss +9 -255
- data/node_modules/govuk-frontend/dist/govuk/settings/_colours-palette.scss +117 -25
- data/node_modules/govuk-frontend/dist/govuk/settings/_custom-properties.scss +18 -0
- data/node_modules/govuk-frontend/dist/govuk/settings/_index.scss +3 -14
- data/node_modules/govuk-frontend/dist/govuk/settings/_media-queries.scss +0 -9
- data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss +12 -189
- data/node_modules/govuk-frontend/dist/govuk/tools/_index.scss +0 -1
- data/node_modules/govuk-frontend/dist/govuk/tools/_px-to-em.scss +4 -2
- data/node_modules/govuk-frontend/dist/govuk/tools/_px-to-rem.scss +2 -0
- data/package-lock.json +2461 -1150
- data/package.json +3 -3
- metadata +16 -30
- data/node_modules/govuk-frontend/dist/govuk/all.scss +0 -9
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/favicon.ico +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/favicon.svg +0 -1
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-crest.svg +0 -1
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-icon-180.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-icon-192.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-icon-512.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-icon-mask.svg +0 -1
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/images/govuk-opengraph-image.png +0 -0
- data/node_modules/govuk-frontend/dist/govuk/assets/rebrand/manifest.json +0 -39
- data/node_modules/govuk-frontend/dist/govuk/components/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +0 -233
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +0 -225
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.mjs +0 -89
- data/node_modules/govuk-frontend/dist/govuk/core/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +0 -15
- data/node_modules/govuk-frontend/dist/govuk/helpers/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/objects/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/overrides/_all.scss +0 -9
- data/node_modules/govuk-frontend/dist/govuk/settings/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/tools/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/tools/_rebrand.scss +0 -65
- data/node_modules/govuk-frontend/dist/govuk/utilities/_all.scss +0 -10
- data/node_modules/govuk-frontend/dist/govuk/vendor/_sass-mq.scss +0 -349
- data/node_modules/govuk-frontend/dist/govuk-prototype-kit/functions.js +0 -25
|
@@ -4,14 +4,8 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = global.GOVUKFrontend || {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const version = '
|
|
7
|
+
const version = '6.0.0';
|
|
8
8
|
|
|
9
|
-
function getFragmentFromUrl(url) {
|
|
10
|
-
if (!url.includes('#')) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
return url.split('#').pop();
|
|
14
|
-
}
|
|
15
9
|
function getBreakpoint(name) {
|
|
16
10
|
const property = `--govuk-breakpoint-${name}`;
|
|
17
11
|
const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);
|
|
@@ -69,6 +63,9 @@
|
|
|
69
63
|
function isObject(option) {
|
|
70
64
|
return !!option && typeof option === 'object' && !isArray(option);
|
|
71
65
|
}
|
|
66
|
+
function isScope($scope) {
|
|
67
|
+
return !!$scope && ($scope instanceof Element || $scope instanceof Document);
|
|
68
|
+
}
|
|
72
69
|
function formatErrorMessage(Component, message) {
|
|
73
70
|
return `${Component.moduleName}: ${message}`;
|
|
74
71
|
}
|
|
@@ -76,9 +73,6 @@
|
|
|
76
73
|
* @typedef ComponentWithModuleName
|
|
77
74
|
* @property {string} moduleName - Name of the component
|
|
78
75
|
*/
|
|
79
|
-
/**
|
|
80
|
-
* @import { ObjectNested } from './configuration.mjs'
|
|
81
|
-
*/
|
|
82
76
|
|
|
83
77
|
class GOVUKFrontendError extends Error {
|
|
84
78
|
constructor(...args) {
|
|
@@ -107,7 +101,7 @@
|
|
|
107
101
|
class ElementError extends GOVUKFrontendError {
|
|
108
102
|
constructor(messageOrOptions) {
|
|
109
103
|
let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
|
|
110
|
-
if (
|
|
104
|
+
if (isObject(messageOrOptions)) {
|
|
111
105
|
const {
|
|
112
106
|
component,
|
|
113
107
|
identifier,
|
|
@@ -116,7 +110,9 @@
|
|
|
116
110
|
} = messageOrOptions;
|
|
117
111
|
message = identifier;
|
|
118
112
|
message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';
|
|
119
|
-
|
|
113
|
+
if (component) {
|
|
114
|
+
message = formatErrorMessage(component, message);
|
|
115
|
+
}
|
|
120
116
|
}
|
|
121
117
|
super(message);
|
|
122
118
|
this.name = 'ElementError';
|
|
@@ -256,6 +252,30 @@
|
|
|
256
252
|
}
|
|
257
253
|
return out;
|
|
258
254
|
}
|
|
255
|
+
function normaliseOptions(scopeOrOptions) {
|
|
256
|
+
let $scope = document;
|
|
257
|
+
let onError;
|
|
258
|
+
if (isObject(scopeOrOptions)) {
|
|
259
|
+
const options = scopeOrOptions;
|
|
260
|
+
if (isScope(options.scope) || options.scope === null) {
|
|
261
|
+
$scope = options.scope;
|
|
262
|
+
}
|
|
263
|
+
if (typeof options.onError === 'function') {
|
|
264
|
+
onError = options.onError;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (isScope(scopeOrOptions)) {
|
|
268
|
+
$scope = scopeOrOptions;
|
|
269
|
+
} else if (scopeOrOptions === null) {
|
|
270
|
+
$scope = null;
|
|
271
|
+
} else if (typeof scopeOrOptions === 'function') {
|
|
272
|
+
onError = scopeOrOptions;
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
scope: $scope,
|
|
276
|
+
onError
|
|
277
|
+
};
|
|
278
|
+
}
|
|
259
279
|
function mergeConfigs(...configObjects) {
|
|
260
280
|
const formattedConfigObject = {};
|
|
261
281
|
for (const configObject of configObjects) {
|
|
@@ -350,6 +370,9 @@
|
|
|
350
370
|
* @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
|
|
351
371
|
* @typedef {typeof Component & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
|
|
352
372
|
*/
|
|
373
|
+
/**
|
|
374
|
+
* @import { CompatibleClass, Config, CreateAllOptions, OnErrorCallback } from '../init.mjs'
|
|
375
|
+
*/
|
|
353
376
|
|
|
354
377
|
class I18n {
|
|
355
378
|
constructor(translations = {}, config = {}) {
|
|
@@ -364,7 +387,7 @@
|
|
|
364
387
|
throw new Error('i18n: lookup key missing');
|
|
365
388
|
}
|
|
366
389
|
let translation = this.translations[lookupKey];
|
|
367
|
-
if (typeof (options == null ? void 0 : options.count) === 'number' &&
|
|
390
|
+
if (typeof (options == null ? void 0 : options.count) === 'number' && isObject(translation)) {
|
|
368
391
|
const translationPluralForm = translation[this.getPluralSuffix(lookupKey, options.count)];
|
|
369
392
|
if (translationPluralForm) {
|
|
370
393
|
translation = translationPluralForm;
|
|
@@ -406,8 +429,8 @@
|
|
|
406
429
|
return 'other';
|
|
407
430
|
}
|
|
408
431
|
const translation = this.translations[lookupKey];
|
|
409
|
-
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) :
|
|
410
|
-
if (
|
|
432
|
+
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : 'other';
|
|
433
|
+
if (isObject(translation)) {
|
|
411
434
|
if (preferredForm in translation) {
|
|
412
435
|
return preferredForm;
|
|
413
436
|
} else if ('other' in translation) {
|
|
@@ -417,132 +440,7 @@
|
|
|
417
440
|
}
|
|
418
441
|
throw new Error(`i18n: Plural form ".other" is required for "${this.locale}" locale`);
|
|
419
442
|
}
|
|
420
|
-
selectPluralFormUsingFallbackRules(count) {
|
|
421
|
-
count = Math.abs(Math.floor(count));
|
|
422
|
-
const ruleset = this.getPluralRulesForLocale();
|
|
423
|
-
if (ruleset) {
|
|
424
|
-
return I18n.pluralRules[ruleset](count);
|
|
425
|
-
}
|
|
426
|
-
return 'other';
|
|
427
|
-
}
|
|
428
|
-
getPluralRulesForLocale() {
|
|
429
|
-
const localeShort = this.locale.split('-')[0];
|
|
430
|
-
for (const pluralRule in I18n.pluralRulesMap) {
|
|
431
|
-
const languages = I18n.pluralRulesMap[pluralRule];
|
|
432
|
-
if (languages.includes(this.locale) || languages.includes(localeShort)) {
|
|
433
|
-
return pluralRule;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
443
|
}
|
|
438
|
-
I18n.pluralRulesMap = {
|
|
439
|
-
arabic: ['ar'],
|
|
440
|
-
chinese: ['my', 'zh', 'id', 'ja', 'jv', 'ko', 'ms', 'th', 'vi'],
|
|
441
|
-
french: ['hy', 'bn', 'fr', 'gu', 'hi', 'fa', 'pa', 'zu'],
|
|
442
|
-
german: ['af', 'sq', 'az', 'eu', 'bg', 'ca', 'da', 'nl', 'en', 'et', 'fi', 'ka', 'de', 'el', 'hu', 'lb', 'no', 'so', 'sw', 'sv', 'ta', 'te', 'tr', 'ur'],
|
|
443
|
-
irish: ['ga'],
|
|
444
|
-
russian: ['ru', 'uk'],
|
|
445
|
-
scottish: ['gd'],
|
|
446
|
-
spanish: ['pt-PT', 'it', 'es'],
|
|
447
|
-
welsh: ['cy']
|
|
448
|
-
};
|
|
449
|
-
I18n.pluralRules = {
|
|
450
|
-
arabic(n) {
|
|
451
|
-
if (n === 0) {
|
|
452
|
-
return 'zero';
|
|
453
|
-
}
|
|
454
|
-
if (n === 1) {
|
|
455
|
-
return 'one';
|
|
456
|
-
}
|
|
457
|
-
if (n === 2) {
|
|
458
|
-
return 'two';
|
|
459
|
-
}
|
|
460
|
-
if (n % 100 >= 3 && n % 100 <= 10) {
|
|
461
|
-
return 'few';
|
|
462
|
-
}
|
|
463
|
-
if (n % 100 >= 11 && n % 100 <= 99) {
|
|
464
|
-
return 'many';
|
|
465
|
-
}
|
|
466
|
-
return 'other';
|
|
467
|
-
},
|
|
468
|
-
chinese() {
|
|
469
|
-
return 'other';
|
|
470
|
-
},
|
|
471
|
-
french(n) {
|
|
472
|
-
return n === 0 || n === 1 ? 'one' : 'other';
|
|
473
|
-
},
|
|
474
|
-
german(n) {
|
|
475
|
-
return n === 1 ? 'one' : 'other';
|
|
476
|
-
},
|
|
477
|
-
irish(n) {
|
|
478
|
-
if (n === 1) {
|
|
479
|
-
return 'one';
|
|
480
|
-
}
|
|
481
|
-
if (n === 2) {
|
|
482
|
-
return 'two';
|
|
483
|
-
}
|
|
484
|
-
if (n >= 3 && n <= 6) {
|
|
485
|
-
return 'few';
|
|
486
|
-
}
|
|
487
|
-
if (n >= 7 && n <= 10) {
|
|
488
|
-
return 'many';
|
|
489
|
-
}
|
|
490
|
-
return 'other';
|
|
491
|
-
},
|
|
492
|
-
russian(n) {
|
|
493
|
-
const lastTwo = n % 100;
|
|
494
|
-
const last = lastTwo % 10;
|
|
495
|
-
if (last === 1 && lastTwo !== 11) {
|
|
496
|
-
return 'one';
|
|
497
|
-
}
|
|
498
|
-
if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) {
|
|
499
|
-
return 'few';
|
|
500
|
-
}
|
|
501
|
-
if (last === 0 || last >= 5 && last <= 9 || lastTwo >= 11 && lastTwo <= 14) {
|
|
502
|
-
return 'many';
|
|
503
|
-
}
|
|
504
|
-
return 'other';
|
|
505
|
-
},
|
|
506
|
-
scottish(n) {
|
|
507
|
-
if (n === 1 || n === 11) {
|
|
508
|
-
return 'one';
|
|
509
|
-
}
|
|
510
|
-
if (n === 2 || n === 12) {
|
|
511
|
-
return 'two';
|
|
512
|
-
}
|
|
513
|
-
if (n >= 3 && n <= 10 || n >= 13 && n <= 19) {
|
|
514
|
-
return 'few';
|
|
515
|
-
}
|
|
516
|
-
return 'other';
|
|
517
|
-
},
|
|
518
|
-
spanish(n) {
|
|
519
|
-
if (n === 1) {
|
|
520
|
-
return 'one';
|
|
521
|
-
}
|
|
522
|
-
if (n % 1000000 === 0 && n !== 0) {
|
|
523
|
-
return 'many';
|
|
524
|
-
}
|
|
525
|
-
return 'other';
|
|
526
|
-
},
|
|
527
|
-
welsh(n) {
|
|
528
|
-
if (n === 0) {
|
|
529
|
-
return 'zero';
|
|
530
|
-
}
|
|
531
|
-
if (n === 1) {
|
|
532
|
-
return 'one';
|
|
533
|
-
}
|
|
534
|
-
if (n === 2) {
|
|
535
|
-
return 'two';
|
|
536
|
-
}
|
|
537
|
-
if (n === 3) {
|
|
538
|
-
return 'few';
|
|
539
|
-
}
|
|
540
|
-
if (n === 6) {
|
|
541
|
-
return 'many';
|
|
542
|
-
}
|
|
543
|
-
return 'other';
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
444
|
|
|
547
445
|
/**
|
|
548
446
|
* Accordion component
|
|
@@ -743,11 +641,11 @@
|
|
|
743
641
|
const ariaLabelParts = [];
|
|
744
642
|
const $headingText = $section.querySelector(`.${this.sectionHeadingTextClass}`);
|
|
745
643
|
if ($headingText) {
|
|
746
|
-
ariaLabelParts.push(
|
|
644
|
+
ariaLabelParts.push($headingText.textContent.trim());
|
|
747
645
|
}
|
|
748
646
|
const $summary = $section.querySelector(`.${this.sectionSummaryClass}`);
|
|
749
647
|
if ($summary) {
|
|
750
|
-
ariaLabelParts.push(
|
|
648
|
+
ariaLabelParts.push($summary.textContent.trim());
|
|
751
649
|
}
|
|
752
650
|
const ariaLabelMessage = expanded ? this.i18n.t('hideSectionAriaLabel') : this.i18n.t('showSectionAriaLabel');
|
|
753
651
|
ariaLabelParts.push(ariaLabelMessage);
|
|
@@ -800,7 +698,7 @@
|
|
|
800
698
|
if (id) {
|
|
801
699
|
try {
|
|
802
700
|
window.sessionStorage.setItem(id, isExpanded.toString());
|
|
803
|
-
} catch (
|
|
701
|
+
} catch (_unused) {}
|
|
804
702
|
}
|
|
805
703
|
}
|
|
806
704
|
setInitialState($section) {
|
|
@@ -814,7 +712,7 @@
|
|
|
814
712
|
if (state !== null) {
|
|
815
713
|
this.setExpanded(state === 'true', $section);
|
|
816
714
|
}
|
|
817
|
-
} catch (
|
|
715
|
+
} catch (_unused2) {}
|
|
818
716
|
}
|
|
819
717
|
}
|
|
820
718
|
getButtonPunctuationEl() {
|
|
@@ -988,6 +886,7 @@
|
|
|
988
886
|
var _ref, _this$config$maxwords;
|
|
989
887
|
super($root, config);
|
|
990
888
|
this.$textarea = void 0;
|
|
889
|
+
this.count = 0;
|
|
991
890
|
this.$visibleCountMessage = void 0;
|
|
992
891
|
this.$screenReaderCountMessage = void 0;
|
|
993
892
|
this.lastInputTimestamp = null;
|
|
@@ -1023,7 +922,7 @@
|
|
|
1023
922
|
});
|
|
1024
923
|
}
|
|
1025
924
|
this.$errorMessage = this.$root.querySelector('.govuk-error-message');
|
|
1026
|
-
if (
|
|
925
|
+
if ($textareaDescription.textContent.match(/^\s*$/)) {
|
|
1027
926
|
$textareaDescription.textContent = this.i18n.t('textareaDescription', {
|
|
1028
927
|
count: this.maxLength
|
|
1029
928
|
});
|
|
@@ -1043,15 +942,22 @@
|
|
|
1043
942
|
$textareaDescription.classList.add('govuk-visually-hidden');
|
|
1044
943
|
this.$textarea.removeAttribute('maxlength');
|
|
1045
944
|
this.bindChangeEvents();
|
|
1046
|
-
window.addEventListener('pageshow', () =>
|
|
945
|
+
window.addEventListener('pageshow', () => {
|
|
946
|
+
if (this.$textarea.value !== this.$textarea.textContent) {
|
|
947
|
+
this.updateCount();
|
|
948
|
+
this.updateCountMessage();
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
this.updateCount();
|
|
1047
952
|
this.updateCountMessage();
|
|
1048
953
|
}
|
|
1049
954
|
bindChangeEvents() {
|
|
1050
|
-
this.$textarea.addEventListener('
|
|
955
|
+
this.$textarea.addEventListener('input', () => this.handleInput());
|
|
1051
956
|
this.$textarea.addEventListener('focus', () => this.handleFocus());
|
|
1052
957
|
this.$textarea.addEventListener('blur', () => this.handleBlur());
|
|
1053
958
|
}
|
|
1054
|
-
|
|
959
|
+
handleInput() {
|
|
960
|
+
this.updateCount();
|
|
1055
961
|
this.updateVisibleCountMessage();
|
|
1056
962
|
this.lastInputTimestamp = Date.now();
|
|
1057
963
|
}
|
|
@@ -1078,7 +984,7 @@
|
|
|
1078
984
|
this.updateScreenReaderCountMessage();
|
|
1079
985
|
}
|
|
1080
986
|
updateVisibleCountMessage() {
|
|
1081
|
-
const remainingNumber = this.maxLength - this.count
|
|
987
|
+
const remainingNumber = this.maxLength - this.count;
|
|
1082
988
|
const isError = remainingNumber < 0;
|
|
1083
989
|
this.$visibleCountMessage.classList.toggle('govuk-character-count__message--disabled', !this.isOverThreshold());
|
|
1084
990
|
if (!this.$errorMessage) {
|
|
@@ -1096,16 +1002,18 @@
|
|
|
1096
1002
|
}
|
|
1097
1003
|
this.$screenReaderCountMessage.textContent = this.getCountMessage();
|
|
1098
1004
|
}
|
|
1099
|
-
|
|
1005
|
+
updateCount() {
|
|
1006
|
+
const text = this.$textarea.value;
|
|
1100
1007
|
if (this.config.maxwords) {
|
|
1101
1008
|
var _text$match;
|
|
1102
1009
|
const tokens = (_text$match = text.match(/\S+/g)) != null ? _text$match : [];
|
|
1103
|
-
|
|
1010
|
+
this.count = tokens.length;
|
|
1011
|
+
return;
|
|
1104
1012
|
}
|
|
1105
|
-
|
|
1013
|
+
this.count = text.length;
|
|
1106
1014
|
}
|
|
1107
1015
|
getCountMessage() {
|
|
1108
|
-
const remainingNumber = this.maxLength - this.count
|
|
1016
|
+
const remainingNumber = this.maxLength - this.count;
|
|
1109
1017
|
const countType = this.config.maxwords ? 'words' : 'characters';
|
|
1110
1018
|
return this.formatCountMessage(remainingNumber, countType);
|
|
1111
1019
|
}
|
|
@@ -1122,7 +1030,7 @@
|
|
|
1122
1030
|
if (!this.config.threshold) {
|
|
1123
1031
|
return true;
|
|
1124
1032
|
}
|
|
1125
|
-
const currentLength = this.count
|
|
1033
|
+
const currentLength = this.count;
|
|
1126
1034
|
const maxLength = this.maxLength;
|
|
1127
1035
|
const thresholdValue = maxLength * this.config.threshold / 100;
|
|
1128
1036
|
return thresholdValue <= currentLength;
|
|
@@ -1383,7 +1291,7 @@
|
|
|
1383
1291
|
if (!($target instanceof HTMLAnchorElement)) {
|
|
1384
1292
|
return false;
|
|
1385
1293
|
}
|
|
1386
|
-
const inputId =
|
|
1294
|
+
const inputId = $target.hash.replace('#', '');
|
|
1387
1295
|
if (!inputId) {
|
|
1388
1296
|
return false;
|
|
1389
1297
|
}
|
|
@@ -1696,7 +1604,6 @@
|
|
|
1696
1604
|
throw new ElementError(formatErrorMessage(FileUpload, 'File input (`<input type="file">`) attribute (`type`) is not `file`'));
|
|
1697
1605
|
}
|
|
1698
1606
|
this.$input = $input;
|
|
1699
|
-
this.$input.setAttribute('hidden', 'true');
|
|
1700
1607
|
if (!this.$input.id) {
|
|
1701
1608
|
throw new ElementError({
|
|
1702
1609
|
component: FileUpload,
|
|
@@ -1712,6 +1619,7 @@
|
|
|
1712
1619
|
$label.id = `${this.id}-label`;
|
|
1713
1620
|
}
|
|
1714
1621
|
this.$input.id = `${this.id}-input`;
|
|
1622
|
+
this.$input.setAttribute('hidden', 'true');
|
|
1715
1623
|
const $button = document.createElement('button');
|
|
1716
1624
|
$button.classList.add('govuk-file-upload-button');
|
|
1717
1625
|
$button.type = 'button';
|
|
@@ -1778,7 +1686,7 @@
|
|
|
1778
1686
|
if (this.$button.disabled) return;
|
|
1779
1687
|
if (event.target instanceof Node) {
|
|
1780
1688
|
if (this.$root.contains(event.target)) {
|
|
1781
|
-
if (event.dataTransfer &&
|
|
1689
|
+
if (event.dataTransfer && this.canDrop(event.dataTransfer)) {
|
|
1782
1690
|
if (!this.$button.classList.contains('govuk-file-upload-button--dragging')) {
|
|
1783
1691
|
this.showDraggingState();
|
|
1784
1692
|
this.$announcements.innerText = this.i18n.t('enteredDropZone');
|
|
@@ -1800,12 +1708,30 @@
|
|
|
1800
1708
|
}
|
|
1801
1709
|
onDrop(event) {
|
|
1802
1710
|
event.preventDefault();
|
|
1803
|
-
if (event.dataTransfer &&
|
|
1711
|
+
if (event.dataTransfer && this.canFillInput(event.dataTransfer)) {
|
|
1804
1712
|
this.$input.files = event.dataTransfer.files;
|
|
1805
1713
|
this.$input.dispatchEvent(new CustomEvent('change'));
|
|
1806
1714
|
this.hideDraggingState();
|
|
1807
1715
|
}
|
|
1808
1716
|
}
|
|
1717
|
+
canFillInput(dataTransfer) {
|
|
1718
|
+
return this.matchesInputCapacity(dataTransfer.files.length);
|
|
1719
|
+
}
|
|
1720
|
+
canDrop(dataTransfer) {
|
|
1721
|
+
if (dataTransfer.items.length) {
|
|
1722
|
+
return this.matchesInputCapacity(countFileItems(dataTransfer.items));
|
|
1723
|
+
}
|
|
1724
|
+
if (dataTransfer.types.length) {
|
|
1725
|
+
return dataTransfer.types.includes('Files');
|
|
1726
|
+
}
|
|
1727
|
+
return true;
|
|
1728
|
+
}
|
|
1729
|
+
matchesInputCapacity(numberOfFiles) {
|
|
1730
|
+
if (this.$input.multiple) {
|
|
1731
|
+
return numberOfFiles > 0;
|
|
1732
|
+
}
|
|
1733
|
+
return numberOfFiles === 1;
|
|
1734
|
+
}
|
|
1809
1735
|
onChange() {
|
|
1810
1736
|
const fileCount = this.$input.files.length;
|
|
1811
1737
|
if (fileCount === 0) {
|
|
@@ -1852,6 +1778,13 @@
|
|
|
1852
1778
|
this.$root.classList.toggle('govuk-drop-zone--disabled', this.$button.disabled);
|
|
1853
1779
|
}
|
|
1854
1780
|
}
|
|
1781
|
+
|
|
1782
|
+
/**
|
|
1783
|
+
* Counts the number of `DataTransferItem` whose kind is `file`
|
|
1784
|
+
*
|
|
1785
|
+
* @param {DataTransferItemList} list - The list
|
|
1786
|
+
* @returns {number} - The number of items whose kind is `file` in the list
|
|
1787
|
+
*/
|
|
1855
1788
|
FileUpload.moduleName = 'govuk-file-upload';
|
|
1856
1789
|
FileUpload.defaults = Object.freeze({
|
|
1857
1790
|
i18n: {
|
|
@@ -1873,10 +1806,14 @@
|
|
|
1873
1806
|
}
|
|
1874
1807
|
}
|
|
1875
1808
|
});
|
|
1876
|
-
function
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1809
|
+
function countFileItems(list) {
|
|
1810
|
+
let result = 0;
|
|
1811
|
+
for (let i = 0; i < list.length; i++) {
|
|
1812
|
+
if (list[i].kind === 'file') {
|
|
1813
|
+
result++;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return result;
|
|
1880
1817
|
}
|
|
1881
1818
|
|
|
1882
1819
|
/**
|
|
@@ -1914,89 +1851,6 @@
|
|
|
1914
1851
|
* @import { TranslationPluralForms } from '../../i18n.mjs'
|
|
1915
1852
|
*/
|
|
1916
1853
|
|
|
1917
|
-
/**
|
|
1918
|
-
* Header component
|
|
1919
|
-
*
|
|
1920
|
-
* @preserve
|
|
1921
|
-
*/
|
|
1922
|
-
class Header extends Component {
|
|
1923
|
-
/**
|
|
1924
|
-
* Apply a matchMedia for desktop which will trigger a state sync if the
|
|
1925
|
-
* browser viewport moves between states.
|
|
1926
|
-
*
|
|
1927
|
-
* @param {Element | null} $root - HTML element to use for header
|
|
1928
|
-
*/
|
|
1929
|
-
constructor($root) {
|
|
1930
|
-
super($root);
|
|
1931
|
-
this.$menuButton = void 0;
|
|
1932
|
-
this.$menu = void 0;
|
|
1933
|
-
this.menuIsOpen = false;
|
|
1934
|
-
this.mql = null;
|
|
1935
|
-
const $menuButton = this.$root.querySelector('.govuk-js-header-toggle');
|
|
1936
|
-
if (!$menuButton) {
|
|
1937
|
-
return this;
|
|
1938
|
-
}
|
|
1939
|
-
this.$root.classList.add('govuk-header--with-js-navigation');
|
|
1940
|
-
const menuId = $menuButton.getAttribute('aria-controls');
|
|
1941
|
-
if (!menuId) {
|
|
1942
|
-
throw new ElementError({
|
|
1943
|
-
component: Header,
|
|
1944
|
-
identifier: 'Navigation button (`<button class="govuk-js-header-toggle">`) attribute (`aria-controls`)'
|
|
1945
|
-
});
|
|
1946
|
-
}
|
|
1947
|
-
const $menu = document.getElementById(menuId);
|
|
1948
|
-
if (!$menu) {
|
|
1949
|
-
throw new ElementError({
|
|
1950
|
-
component: Header,
|
|
1951
|
-
element: $menu,
|
|
1952
|
-
identifier: `Navigation (\`<ul id="${menuId}">\`)`
|
|
1953
|
-
});
|
|
1954
|
-
}
|
|
1955
|
-
this.$menu = $menu;
|
|
1956
|
-
this.$menuButton = $menuButton;
|
|
1957
|
-
this.setupResponsiveChecks();
|
|
1958
|
-
this.$menuButton.addEventListener('click', () => this.handleMenuButtonClick());
|
|
1959
|
-
}
|
|
1960
|
-
setupResponsiveChecks() {
|
|
1961
|
-
const breakpoint = getBreakpoint('desktop');
|
|
1962
|
-
if (!breakpoint.value) {
|
|
1963
|
-
throw new ElementError({
|
|
1964
|
-
component: Header,
|
|
1965
|
-
identifier: `CSS custom property (\`${breakpoint.property}\`) on pseudo-class \`:root\``
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
this.mql = window.matchMedia(`(min-width: ${breakpoint.value})`);
|
|
1969
|
-
if ('addEventListener' in this.mql) {
|
|
1970
|
-
this.mql.addEventListener('change', () => this.checkMode());
|
|
1971
|
-
} else {
|
|
1972
|
-
this.mql.addListener(() => this.checkMode());
|
|
1973
|
-
}
|
|
1974
|
-
this.checkMode();
|
|
1975
|
-
}
|
|
1976
|
-
checkMode() {
|
|
1977
|
-
if (!this.mql || !this.$menu || !this.$menuButton) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
if (this.mql.matches) {
|
|
1981
|
-
this.$menu.removeAttribute('hidden');
|
|
1982
|
-
this.$menuButton.setAttribute('hidden', '');
|
|
1983
|
-
} else {
|
|
1984
|
-
this.$menuButton.removeAttribute('hidden');
|
|
1985
|
-
this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString());
|
|
1986
|
-
if (this.menuIsOpen) {
|
|
1987
|
-
this.$menu.removeAttribute('hidden');
|
|
1988
|
-
} else {
|
|
1989
|
-
this.$menu.setAttribute('hidden', '');
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
handleMenuButtonClick() {
|
|
1994
|
-
this.menuIsOpen = !this.menuIsOpen;
|
|
1995
|
-
this.checkMode();
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
Header.moduleName = 'govuk-header';
|
|
1999
|
-
|
|
2000
1854
|
/**
|
|
2001
1855
|
* Notification Banner component
|
|
2002
1856
|
*
|
|
@@ -2328,9 +2182,9 @@
|
|
|
2328
2182
|
}
|
|
2329
2183
|
if (this.mql.matches) {
|
|
2330
2184
|
this.$menu.removeAttribute('hidden');
|
|
2331
|
-
this.$menuButton
|
|
2185
|
+
setAttributes(this.$menuButton, attributesForHidingButton);
|
|
2332
2186
|
} else {
|
|
2333
|
-
this.$menuButton.
|
|
2187
|
+
removeAttributes(this.$menuButton, Object.keys(attributesForHidingButton));
|
|
2334
2188
|
this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString());
|
|
2335
2189
|
if (this.menuIsOpen) {
|
|
2336
2190
|
this.$menu.removeAttribute('hidden');
|
|
@@ -2345,6 +2199,34 @@
|
|
|
2345
2199
|
}
|
|
2346
2200
|
}
|
|
2347
2201
|
ServiceNavigation.moduleName = 'govuk-service-navigation';
|
|
2202
|
+
const attributesForHidingButton = {
|
|
2203
|
+
hidden: '',
|
|
2204
|
+
'aria-hidden': 'true'
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
/**
|
|
2208
|
+
* Sets a group of attributes on the given element
|
|
2209
|
+
*
|
|
2210
|
+
* @param {Element} $element - The element to set the attribute on
|
|
2211
|
+
* @param {{[attributeName: string]: string}} attributes - The attributes to set
|
|
2212
|
+
*/
|
|
2213
|
+
function setAttributes($element, attributes) {
|
|
2214
|
+
for (const attributeName in attributes) {
|
|
2215
|
+
$element.setAttribute(attributeName, attributes[attributeName]);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
/**
|
|
2220
|
+
* Removes a list of attributes from the given element
|
|
2221
|
+
*
|
|
2222
|
+
* @param {Element} $element - The element to remove the attributes from
|
|
2223
|
+
* @param {string[]} attributeNames - The names of the attributes to remove
|
|
2224
|
+
*/
|
|
2225
|
+
function removeAttributes($element, attributeNames) {
|
|
2226
|
+
for (const attributeName of attributeNames) {
|
|
2227
|
+
$element.removeAttribute(attributeName);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2348
2230
|
|
|
2349
2231
|
/**
|
|
2350
2232
|
* Skip link component
|
|
@@ -2364,16 +2246,10 @@
|
|
|
2364
2246
|
super($root);
|
|
2365
2247
|
const hash = this.$root.hash;
|
|
2366
2248
|
const href = (_this$$root$getAttrib = this.$root.getAttribute('href')) != null ? _this$$root$getAttrib : '';
|
|
2367
|
-
|
|
2368
|
-
try {
|
|
2369
|
-
url = new window.URL(this.$root.href);
|
|
2370
|
-
} catch (error) {
|
|
2371
|
-
throw new ElementError(`Skip link: Target link (\`href="${href}"\`) is invalid`);
|
|
2372
|
-
}
|
|
2373
|
-
if (url.origin !== window.location.origin || url.pathname !== window.location.pathname) {
|
|
2249
|
+
if (this.$root.origin !== window.location.origin || this.$root.pathname !== window.location.pathname) {
|
|
2374
2250
|
return;
|
|
2375
2251
|
}
|
|
2376
|
-
const linkedElementId =
|
|
2252
|
+
const linkedElementId = hash.replace('#', '');
|
|
2377
2253
|
if (!linkedElementId) {
|
|
2378
2254
|
throw new ElementError(`Skip link: Target link (\`href="${href}"\`) has no hash fragment`);
|
|
2379
2255
|
}
|
|
@@ -2529,7 +2405,7 @@
|
|
|
2529
2405
|
return this.$root.querySelector(`a.govuk-tabs__tab[href="${hash}"]`);
|
|
2530
2406
|
}
|
|
2531
2407
|
setAttributes($tab) {
|
|
2532
|
-
const panelId =
|
|
2408
|
+
const panelId = $tab.hash.replace('#', '');
|
|
2533
2409
|
if (!panelId) {
|
|
2534
2410
|
return;
|
|
2535
2411
|
}
|
|
@@ -2633,7 +2509,7 @@
|
|
|
2633
2509
|
this.createHistoryEntry($previousTab);
|
|
2634
2510
|
}
|
|
2635
2511
|
getPanel($tab) {
|
|
2636
|
-
const panelId =
|
|
2512
|
+
const panelId = $tab.hash.replace('#', '');
|
|
2637
2513
|
if (!panelId) {
|
|
2638
2514
|
return null;
|
|
2639
2515
|
}
|
|
@@ -2681,28 +2557,34 @@
|
|
|
2681
2557
|
* Use the `data-module` attributes to find, instantiate and init all of the
|
|
2682
2558
|
* components provided as part of GOV.UK Frontend.
|
|
2683
2559
|
*
|
|
2684
|
-
* @param {Config
|
|
2560
|
+
* @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
|
|
2685
2561
|
*/
|
|
2686
|
-
function initAll(
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
if (
|
|
2691
|
-
|
|
2562
|
+
function initAll(scopeOrConfig = {}) {
|
|
2563
|
+
const config = isObject(scopeOrConfig) ? scopeOrConfig : {};
|
|
2564
|
+
const options = normaliseOptions(scopeOrConfig);
|
|
2565
|
+
try {
|
|
2566
|
+
if (!isSupported()) {
|
|
2567
|
+
throw new SupportError();
|
|
2568
|
+
}
|
|
2569
|
+
if (options.scope === null) {
|
|
2570
|
+
throw new ElementError({
|
|
2571
|
+
element: options.scope,
|
|
2572
|
+
identifier: 'GOV.UK Frontend scope element (`$scope`)'
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
} catch (error) {
|
|
2576
|
+
if (options.onError) {
|
|
2577
|
+
options.onError(error, {
|
|
2692
2578
|
config
|
|
2693
2579
|
});
|
|
2694
2580
|
} else {
|
|
2695
|
-
console.log(
|
|
2581
|
+
console.log(error);
|
|
2696
2582
|
}
|
|
2697
2583
|
return;
|
|
2698
2584
|
}
|
|
2699
|
-
const components = [[Accordion, config.accordion], [Button, config.button], [CharacterCount, config.characterCount], [Checkboxes], [ErrorSummary, config.errorSummary], [ExitThisPage, config.exitThisPage], [FileUpload, config.fileUpload], [
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
onError: config.onError
|
|
2703
|
-
};
|
|
2704
|
-
components.forEach(([Component, config]) => {
|
|
2705
|
-
createAll(Component, config, options);
|
|
2585
|
+
const components = [[Accordion, config.accordion], [Button, config.button], [CharacterCount, config.characterCount], [Checkboxes], [ErrorSummary, config.errorSummary], [ExitThisPage, config.exitThisPage], [FileUpload, config.fileUpload], [NotificationBanner, config.notificationBanner], [PasswordInput, config.passwordInput], [Radios], [ServiceNavigation], [SkipLink], [Tabs]];
|
|
2586
|
+
components.forEach(([Component, componentConfig]) => {
|
|
2587
|
+
createAll(Component, componentConfig, options);
|
|
2706
2588
|
});
|
|
2707
2589
|
}
|
|
2708
2590
|
|
|
@@ -2718,42 +2600,42 @@
|
|
|
2718
2600
|
* @template {CompatibleClass} ComponentClass
|
|
2719
2601
|
* @param {ComponentClass} Component - class of the component to create
|
|
2720
2602
|
* @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
|
|
2721
|
-
* @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass>
|
|
2603
|
+
* @param {OnErrorCallback<ComponentClass> | Element | Document | null | CreateAllOptions<ComponentClass>} [scopeOrOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
|
|
2722
2604
|
* @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
|
|
2723
2605
|
*/
|
|
2724
|
-
function createAll(Component, config,
|
|
2725
|
-
let $
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
var
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
if (onError) {
|
|
2742
|
-
onError(
|
|
2606
|
+
function createAll(Component, config, scopeOrOptions) {
|
|
2607
|
+
let $elements;
|
|
2608
|
+
const options = normaliseOptions(scopeOrOptions);
|
|
2609
|
+
try {
|
|
2610
|
+
var _options$scope;
|
|
2611
|
+
if (!isSupported()) {
|
|
2612
|
+
throw new SupportError();
|
|
2613
|
+
}
|
|
2614
|
+
if (options.scope === null) {
|
|
2615
|
+
throw new ElementError({
|
|
2616
|
+
element: options.scope,
|
|
2617
|
+
component: Component,
|
|
2618
|
+
identifier: 'Scope element (`$scope`)'
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
$elements = (_options$scope = options.scope) == null ? void 0 : _options$scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
|
|
2622
|
+
} catch (error) {
|
|
2623
|
+
if (options.onError) {
|
|
2624
|
+
options.onError(error, {
|
|
2743
2625
|
component: Component,
|
|
2744
2626
|
config
|
|
2745
2627
|
});
|
|
2746
2628
|
} else {
|
|
2747
|
-
console.log(
|
|
2629
|
+
console.log(error);
|
|
2748
2630
|
}
|
|
2749
2631
|
return [];
|
|
2750
2632
|
}
|
|
2751
|
-
return Array.from($elements).map($element => {
|
|
2633
|
+
return Array.from($elements != null ? $elements : []).map($element => {
|
|
2752
2634
|
try {
|
|
2753
2635
|
return typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
|
|
2754
2636
|
} catch (error) {
|
|
2755
|
-
if (onError) {
|
|
2756
|
-
onError(error, {
|
|
2637
|
+
if (options.onError) {
|
|
2638
|
+
options.onError(error, {
|
|
2757
2639
|
element: $element,
|
|
2758
2640
|
component: Component,
|
|
2759
2641
|
config
|
|
@@ -2772,6 +2654,8 @@
|
|
|
2772
2654
|
* Config for all components via `initAll()`
|
|
2773
2655
|
*
|
|
2774
2656
|
* @typedef {object} Config
|
|
2657
|
+
* @property {Element | Document | null} [scope] - Scope of the document to search within
|
|
2658
|
+
* @property {OnErrorCallback<CompatibleClass>} [onError] - Initialisation error callback
|
|
2775
2659
|
* @property {AccordionConfig} [accordion] - Accordion config
|
|
2776
2660
|
* @property {ButtonConfig} [button] - Button config
|
|
2777
2661
|
* @property {CharacterCountConfig} [characterCount] - Character Count config
|
|
@@ -2796,7 +2680,7 @@
|
|
|
2796
2680
|
/**
|
|
2797
2681
|
* Component config keys, e.g. `accordion` and `characterCount`
|
|
2798
2682
|
*
|
|
2799
|
-
* @typedef {keyof Config} ConfigKey
|
|
2683
|
+
* @typedef {keyof Omit<Config, 'scope' | 'onError'>} ConfigKey
|
|
2800
2684
|
*/
|
|
2801
2685
|
/**
|
|
2802
2686
|
* @template {CompatibleClass} ComponentClass
|
|
@@ -2807,7 +2691,7 @@
|
|
|
2807
2691
|
* @typedef {object} ErrorContext
|
|
2808
2692
|
* @property {Element} [element] - Element used for component module initialisation
|
|
2809
2693
|
* @property {ComponentClass} [component] - Class of component
|
|
2810
|
-
* @property {ComponentConfig<ComponentClass>} config - Config supplied to
|
|
2694
|
+
* @property {Config | ComponentConfig<ComponentClass>} [config] - Config supplied to components
|
|
2811
2695
|
*/
|
|
2812
2696
|
/**
|
|
2813
2697
|
* @template {CompatibleClass} ComponentClass
|
|
@@ -2818,7 +2702,7 @@
|
|
|
2818
2702
|
/**
|
|
2819
2703
|
* @template {CompatibleClass} ComponentClass
|
|
2820
2704
|
* @typedef {object} CreateAllOptions
|
|
2821
|
-
* @property {Element | Document} [scope] - scope of the document to search within
|
|
2705
|
+
* @property {Element | Document | null} [scope] - scope of the document to search within
|
|
2822
2706
|
* @property {OnErrorCallback<ComponentClass>} [onError] - callback function if error throw by component on init
|
|
2823
2707
|
*/
|
|
2824
2708
|
|
|
@@ -2831,7 +2715,6 @@
|
|
|
2831
2715
|
exports.ErrorSummary = ErrorSummary;
|
|
2832
2716
|
exports.ExitThisPage = ExitThisPage;
|
|
2833
2717
|
exports.FileUpload = FileUpload;
|
|
2834
|
-
exports.Header = Header;
|
|
2835
2718
|
exports.NotificationBanner = NotificationBanner;
|
|
2836
2719
|
exports.PasswordInput = PasswordInput;
|
|
2837
2720
|
exports.Radios = Radios;
|