govuk_tech_docs 5.2.1 → 5.2.2
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/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/govuk_tech_docs.gemspec +1 -1
- data/lib/govuk_tech_docs/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.mjs +97 -72
- 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/accordion.bundle.js +13 -11
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +13 -11
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +4 -4
- 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/character-count.bundle.js +10 -8
- 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.mjs +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.mjs +10 -5
- 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/exit-this-page.bundle.js +9 -7
- 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/file-upload/file-upload.bundle.js +10 -8
- 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.mjs +1 -1
- 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.mjs +10 -5
- 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 +4 -0
- 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.mjs +9 -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/service-navigation/_index.scss +6 -1
- 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.mjs +10 -5
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_index.scss +1 -2
- 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/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/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/govuk-frontend.min.js +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_colour.scss +31 -2
- data/node_modules/govuk-frontend/dist/govuk/helpers/_visually-hidden.scss +4 -1
- data/node_modules/govuk-frontend/dist/govuk/i18n.mjs +4 -2
- data/node_modules/govuk-frontend/dist/govuk/init.mjs +52 -43
- data/package-lock.json +2496 -4409
- data/package.json +2 -2
- metadata +7 -5
|
@@ -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,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
|
|