govuk_publishing_components 51.1.1 → 51.2.1
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/app/assets/javascripts/govuk_publishing_components/components/feedback.js +29 -34
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +7 -2
- data/app/assets/stylesheets/component_guide/application.scss +1 -1
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +2 -2
- data/app/models/govuk_publishing_components/audit_comparer.rb +3 -3
- data/app/views/govuk_publishing_components/components/_title.html.erb +2 -3
- data/app/views/govuk_publishing_components/components/docs/add_another.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/feedback.yml +1 -1
- data/lib/govuk_publishing_components/presenters/checkboxes_helper.rb +1 -1
- data/lib/govuk_publishing_components/presenters/shared_helper.rb +0 -11
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +217 -184
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +216 -184
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.mjs +1 -0
- data/node_modules/govuk-frontend/dist/govuk/all.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/all.scss.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +164 -0
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -0
- data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
- data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +1 -87
- data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +149 -112
- 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 +148 -111
- 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 +5 -8
- 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 +149 -112
- 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 +148 -111
- 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 +5 -8
- 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 +174 -140
- 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 +173 -139
- 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 +17 -16
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/macro-options.json +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +1 -24
- 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 +0 -23
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/date-input/macro-options.json +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +149 -112
- 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 +148 -111
- 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 +6 -8
- 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 +149 -112
- 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 +148 -111
- 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 +5 -8
- 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/header/header.bundle.js +1 -24
- 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 +0 -23
- data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/input/macro-options.json +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +149 -112
- 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 +148 -111
- 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 +6 -8
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/macro-options.json +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +149 -112
- 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 +148 -111
- 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 +5 -8
- 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 +1 -24
- 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 +0 -23
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +1 -24
- 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 +0 -23
- 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/skip-link/skip-link.bundle.js +1 -24
- 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 +0 -23
- 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/tabs/tabs.bundle.js +1 -24
- 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 +0 -23
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/textarea/macro-options.json +1 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +1 -1
- 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/init.mjs +17 -13
- data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
- data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss +5 -10
- data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss.map +1 -1
- data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +1 -1
- data/node_modules/govuk-frontend/package.json +9 -9
- metadata +4 -6
- data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs +0 -18
- data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs.map +0 -1
- data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs +0 -31
- data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs.map +0 -1
data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
CHANGED
@@ -3,76 +3,6 @@ function closestAttributeValue($element, attributeName) {
|
|
3
3
|
return $closestElementWithAttribute ? $closestElementWithAttribute.getAttribute(attributeName) : null;
|
4
4
|
}
|
5
5
|
|
6
|
-
function normaliseString(value, property) {
|
7
|
-
const trimmedValue = value ? value.trim() : '';
|
8
|
-
let output;
|
9
|
-
let outputType = property == null ? void 0 : property.type;
|
10
|
-
if (!outputType) {
|
11
|
-
if (['true', 'false'].includes(trimmedValue)) {
|
12
|
-
outputType = 'boolean';
|
13
|
-
}
|
14
|
-
if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
|
15
|
-
outputType = 'number';
|
16
|
-
}
|
17
|
-
}
|
18
|
-
switch (outputType) {
|
19
|
-
case 'boolean':
|
20
|
-
output = trimmedValue === 'true';
|
21
|
-
break;
|
22
|
-
case 'number':
|
23
|
-
output = Number(trimmedValue);
|
24
|
-
break;
|
25
|
-
default:
|
26
|
-
output = value;
|
27
|
-
}
|
28
|
-
return output;
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* @typedef {import('./index.mjs').SchemaProperty} SchemaProperty
|
33
|
-
*/
|
34
|
-
|
35
|
-
function mergeConfigs(...configObjects) {
|
36
|
-
const formattedConfigObject = {};
|
37
|
-
for (const configObject of configObjects) {
|
38
|
-
for (const key of Object.keys(configObject)) {
|
39
|
-
const option = formattedConfigObject[key];
|
40
|
-
const override = configObject[key];
|
41
|
-
if (isObject(option) && isObject(override)) {
|
42
|
-
formattedConfigObject[key] = mergeConfigs(option, override);
|
43
|
-
} else {
|
44
|
-
formattedConfigObject[key] = override;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
return formattedConfigObject;
|
49
|
-
}
|
50
|
-
function extractConfigByNamespace(Component, dataset, namespace) {
|
51
|
-
const property = Component.schema.properties[namespace];
|
52
|
-
if ((property == null ? void 0 : property.type) !== 'object') {
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
const newObject = {
|
56
|
-
[namespace]: ({})
|
57
|
-
};
|
58
|
-
for (const [key, value] of Object.entries(dataset)) {
|
59
|
-
let current = newObject;
|
60
|
-
const keyParts = key.split('.');
|
61
|
-
for (const [index, name] of keyParts.entries()) {
|
62
|
-
if (typeof current === 'object') {
|
63
|
-
if (index < keyParts.length - 1) {
|
64
|
-
if (!isObject(current[name])) {
|
65
|
-
current[name] = {};
|
66
|
-
}
|
67
|
-
current = current[name];
|
68
|
-
} else if (key !== namespace) {
|
69
|
-
current[name] = normaliseString(value);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
}
|
74
|
-
return newObject[namespace];
|
75
|
-
}
|
76
6
|
function isInitialised($root, moduleName) {
|
77
7
|
return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);
|
78
8
|
}
|
@@ -92,26 +22,6 @@ function isSupported($scope = document.body) {
|
|
92
22
|
}
|
93
23
|
return $scope.classList.contains('govuk-frontend-supported');
|
94
24
|
}
|
95
|
-
function validateConfig(schema, config) {
|
96
|
-
const validationErrors = [];
|
97
|
-
for (const [name, conditions] of Object.entries(schema)) {
|
98
|
-
const errors = [];
|
99
|
-
if (Array.isArray(conditions)) {
|
100
|
-
for (const {
|
101
|
-
required,
|
102
|
-
errorMessage
|
103
|
-
} of conditions) {
|
104
|
-
if (!required.every(key => !!config[key])) {
|
105
|
-
errors.push(errorMessage);
|
106
|
-
}
|
107
|
-
}
|
108
|
-
if (name === 'anyOf' && !(conditions.length - errors.length >= 1)) {
|
109
|
-
validationErrors.push(...errors);
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
return validationErrors;
|
114
|
-
}
|
115
25
|
function isArray(option) {
|
116
26
|
return Array.isArray(option);
|
117
27
|
}
|
@@ -121,47 +31,11 @@ function isObject(option) {
|
|
121
31
|
function formatErrorMessage(Component, message) {
|
122
32
|
return `${Component.moduleName}: ${message}`;
|
123
33
|
}
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Schema for component config
|
127
|
-
*
|
128
|
-
* @typedef {object} Schema
|
129
|
-
* @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
|
130
|
-
* @property {SchemaCondition[]} [anyOf] - List of schema conditions
|
131
|
-
*/
|
132
|
-
|
133
|
-
/**
|
134
|
-
* Schema property for component config
|
135
|
-
*
|
136
|
-
* @typedef {object} SchemaProperty
|
137
|
-
* @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
|
138
|
-
*/
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Schema condition for component config
|
142
|
-
*
|
143
|
-
* @typedef {object} SchemaCondition
|
144
|
-
* @property {string[]} required - List of required config fields
|
145
|
-
* @property {string} errorMessage - Error message when required config fields not provided
|
146
|
-
*/
|
147
34
|
/**
|
148
35
|
* @typedef ComponentWithModuleName
|
149
36
|
* @property {string} moduleName - Name of the component
|
150
37
|
*/
|
151
38
|
|
152
|
-
function normaliseDataset(Component, dataset) {
|
153
|
-
const out = {};
|
154
|
-
for (const [field, property] of Object.entries(Component.schema.properties)) {
|
155
|
-
if (field in dataset) {
|
156
|
-
out[field] = normaliseString(dataset[field], property);
|
157
|
-
}
|
158
|
-
if ((property == null ? void 0 : property.type) === 'object') {
|
159
|
-
out[field] = extractConfigByNamespace(Component, dataset, field);
|
160
|
-
}
|
161
|
-
}
|
162
|
-
return out;
|
163
|
-
}
|
164
|
-
|
165
39
|
class GOVUKFrontendError extends Error {
|
166
40
|
constructor(...args) {
|
167
41
|
super(...args);
|
@@ -270,6 +144,164 @@ class GOVUKFrontendComponent {
|
|
270
144
|
*/
|
271
145
|
GOVUKFrontendComponent.elementType = HTMLElement;
|
272
146
|
|
147
|
+
const configOverride = Symbol.for('configOverride');
|
148
|
+
class ConfigurableComponent extends GOVUKFrontendComponent {
|
149
|
+
[configOverride](param) {
|
150
|
+
return {};
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Returns the root element of the component
|
155
|
+
*
|
156
|
+
* @protected
|
157
|
+
* @returns {ConfigurationType} - the root element of component
|
158
|
+
*/
|
159
|
+
get config() {
|
160
|
+
return this._config;
|
161
|
+
}
|
162
|
+
constructor($root, config) {
|
163
|
+
super($root);
|
164
|
+
this._config = void 0;
|
165
|
+
const childConstructor = this.constructor;
|
166
|
+
if (typeof childConstructor.defaults === 'undefined') {
|
167
|
+
throw new ConfigError(formatErrorMessage(childConstructor, 'Config passed as parameter into constructor but no defaults defined'));
|
168
|
+
}
|
169
|
+
const datasetConfig = normaliseDataset(childConstructor, this._$root.dataset);
|
170
|
+
this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {}, this[configOverride](datasetConfig), datasetConfig);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
function normaliseString(value, property) {
|
174
|
+
const trimmedValue = value ? value.trim() : '';
|
175
|
+
let output;
|
176
|
+
let outputType = property == null ? void 0 : property.type;
|
177
|
+
if (!outputType) {
|
178
|
+
if (['true', 'false'].includes(trimmedValue)) {
|
179
|
+
outputType = 'boolean';
|
180
|
+
}
|
181
|
+
if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
|
182
|
+
outputType = 'number';
|
183
|
+
}
|
184
|
+
}
|
185
|
+
switch (outputType) {
|
186
|
+
case 'boolean':
|
187
|
+
output = trimmedValue === 'true';
|
188
|
+
break;
|
189
|
+
case 'number':
|
190
|
+
output = Number(trimmedValue);
|
191
|
+
break;
|
192
|
+
default:
|
193
|
+
output = value;
|
194
|
+
}
|
195
|
+
return output;
|
196
|
+
}
|
197
|
+
function normaliseDataset(Component, dataset) {
|
198
|
+
if (typeof Component.schema === 'undefined') {
|
199
|
+
throw new ConfigError(formatErrorMessage(Component, 'Config passed as parameter into constructor but no schema defined'));
|
200
|
+
}
|
201
|
+
const out = {};
|
202
|
+
for (const [field, property] of Object.entries(Component.schema.properties)) {
|
203
|
+
if (field in dataset) {
|
204
|
+
out[field] = normaliseString(dataset[field], property);
|
205
|
+
}
|
206
|
+
if ((property == null ? void 0 : property.type) === 'object') {
|
207
|
+
out[field] = extractConfigByNamespace(Component.schema, dataset, field);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
return out;
|
211
|
+
}
|
212
|
+
function mergeConfigs(...configObjects) {
|
213
|
+
const formattedConfigObject = {};
|
214
|
+
for (const configObject of configObjects) {
|
215
|
+
for (const key of Object.keys(configObject)) {
|
216
|
+
const option = formattedConfigObject[key];
|
217
|
+
const override = configObject[key];
|
218
|
+
if (isObject(option) && isObject(override)) {
|
219
|
+
formattedConfigObject[key] = mergeConfigs(option, override);
|
220
|
+
} else {
|
221
|
+
formattedConfigObject[key] = override;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
}
|
225
|
+
return formattedConfigObject;
|
226
|
+
}
|
227
|
+
function validateConfig(schema, config) {
|
228
|
+
const validationErrors = [];
|
229
|
+
for (const [name, conditions] of Object.entries(schema)) {
|
230
|
+
const errors = [];
|
231
|
+
if (Array.isArray(conditions)) {
|
232
|
+
for (const {
|
233
|
+
required,
|
234
|
+
errorMessage
|
235
|
+
} of conditions) {
|
236
|
+
if (!required.every(key => !!config[key])) {
|
237
|
+
errors.push(errorMessage);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
if (name === 'anyOf' && !(conditions.length - errors.length >= 1)) {
|
241
|
+
validationErrors.push(...errors);
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
return validationErrors;
|
246
|
+
}
|
247
|
+
function extractConfigByNamespace(schema, dataset, namespace) {
|
248
|
+
const property = schema.properties[namespace];
|
249
|
+
if ((property == null ? void 0 : property.type) !== 'object') {
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
const newObject = {
|
253
|
+
[namespace]: ({})
|
254
|
+
};
|
255
|
+
for (const [key, value] of Object.entries(dataset)) {
|
256
|
+
let current = newObject;
|
257
|
+
const keyParts = key.split('.');
|
258
|
+
for (const [index, name] of keyParts.entries()) {
|
259
|
+
if (typeof current === 'object') {
|
260
|
+
if (index < keyParts.length - 1) {
|
261
|
+
if (!isObject(current[name])) {
|
262
|
+
current[name] = {};
|
263
|
+
}
|
264
|
+
current = current[name];
|
265
|
+
} else if (key !== namespace) {
|
266
|
+
current[name] = normaliseString(value);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
return newObject[namespace];
|
272
|
+
}
|
273
|
+
/**
|
274
|
+
* Schema for component config
|
275
|
+
*
|
276
|
+
* @typedef {object} Schema
|
277
|
+
* @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
|
278
|
+
* @property {SchemaCondition[]} [anyOf] - List of schema conditions
|
279
|
+
*/
|
280
|
+
/**
|
281
|
+
* Schema property for component config
|
282
|
+
*
|
283
|
+
* @typedef {object} SchemaProperty
|
284
|
+
* @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
|
285
|
+
*/
|
286
|
+
/**
|
287
|
+
* Schema condition for component config
|
288
|
+
*
|
289
|
+
* @typedef {object} SchemaCondition
|
290
|
+
* @property {string[]} required - List of required config fields
|
291
|
+
* @property {string} errorMessage - Error message when required config fields not provided
|
292
|
+
*/
|
293
|
+
/**
|
294
|
+
* @template {ObjectNested} [ConfigurationType={}]
|
295
|
+
* @typedef ChildClass
|
296
|
+
* @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component
|
297
|
+
* @property {Schema} [schema] - The schema of the component configuration
|
298
|
+
* @property {ConfigurationType} [defaults] - The default values of the configuration of the component
|
299
|
+
*/
|
300
|
+
/**
|
301
|
+
* @template {ObjectNested} [ConfigurationType={}]
|
302
|
+
* @typedef {typeof GOVUKFrontendComponent & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
|
303
|
+
*/
|
304
|
+
|
273
305
|
class I18n {
|
274
306
|
constructor(translations = {}, config = {}) {
|
275
307
|
var _config$locale;
|
@@ -474,22 +506,33 @@ I18n.pluralRules = {
|
|
474
506
|
* of the available characters/words has been entered.
|
475
507
|
*
|
476
508
|
* @preserve
|
509
|
+
* @augments ConfigurableComponent<CharacterCountConfig>
|
477
510
|
*/
|
478
|
-
class CharacterCount extends
|
511
|
+
class CharacterCount extends ConfigurableComponent {
|
512
|
+
[configOverride](datasetConfig) {
|
513
|
+
let configOverrides = {};
|
514
|
+
if ('maxwords' in datasetConfig || 'maxlength' in datasetConfig) {
|
515
|
+
configOverrides = {
|
516
|
+
maxlength: undefined,
|
517
|
+
maxwords: undefined
|
518
|
+
};
|
519
|
+
}
|
520
|
+
return configOverrides;
|
521
|
+
}
|
522
|
+
|
479
523
|
/**
|
480
524
|
* @param {Element | null} $root - HTML element to use for character count
|
481
525
|
* @param {CharacterCountConfig} [config] - Character count config
|
482
526
|
*/
|
483
527
|
constructor($root, config = {}) {
|
484
528
|
var _ref, _this$config$maxwords;
|
485
|
-
super($root);
|
529
|
+
super($root, config);
|
486
530
|
this.$textarea = void 0;
|
487
531
|
this.$visibleCountMessage = void 0;
|
488
532
|
this.$screenReaderCountMessage = void 0;
|
489
533
|
this.lastInputTimestamp = null;
|
490
534
|
this.lastInputValue = '';
|
491
535
|
this.valueChecker = null;
|
492
|
-
this.config = void 0;
|
493
536
|
this.i18n = void 0;
|
494
537
|
this.maxLength = void 0;
|
495
538
|
const $textarea = this.$root.querySelector('.govuk-js-character-count');
|
@@ -501,15 +544,6 @@ class CharacterCount extends GOVUKFrontendComponent {
|
|
501
544
|
identifier: 'Form field (`.govuk-js-character-count`)'
|
502
545
|
});
|
503
546
|
}
|
504
|
-
const datasetConfig = normaliseDataset(CharacterCount, this.$root.dataset);
|
505
|
-
let configOverrides = {};
|
506
|
-
if ('maxwords' in datasetConfig || 'maxlength' in datasetConfig) {
|
507
|
-
configOverrides = {
|
508
|
-
maxlength: undefined,
|
509
|
-
maxwords: undefined
|
510
|
-
};
|
511
|
-
}
|
512
|
-
this.config = mergeConfigs(CharacterCount.defaults, config, configOverrides, datasetConfig);
|
513
547
|
const errors = validateConfig(CharacterCount.schema, this.config);
|
514
548
|
if (errors[0]) {
|
515
549
|
throw new ConfigError(formatErrorMessage(CharacterCount, errors[0]));
|
@@ -695,7 +729,7 @@ class CharacterCount extends GOVUKFrontendComponent {
|
|
695
729
|
*/
|
696
730
|
|
697
731
|
/**
|
698
|
-
* @typedef {import('../../common/
|
732
|
+
* @typedef {import('../../common/configuration.mjs').Schema} Schema
|
699
733
|
* @typedef {import('../../i18n.mjs').TranslationPluralForms} TranslationPluralForms
|
700
734
|
*/
|
701
735
|
CharacterCount.moduleName = 'govuk-character-count';
|