govuk_publishing_components 51.1.1 → 51.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/component_guide/application.scss +1 -1
  3. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  4. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +1 -0
  5. data/app/models/govuk_publishing_components/audit_comparer.rb +3 -3
  6. data/app/views/govuk_publishing_components/components/_title.html.erb +2 -3
  7. data/app/views/govuk_publishing_components/components/docs/add_another.yml +1 -1
  8. data/lib/govuk_publishing_components/presenters/checkboxes_helper.rb +1 -1
  9. data/lib/govuk_publishing_components/presenters/shared_helper.rb +0 -11
  10. data/lib/govuk_publishing_components/version.rb +1 -1
  11. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +217 -184
  12. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
  13. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +216 -184
  14. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
  15. data/node_modules/govuk-frontend/dist/govuk/all.mjs +1 -0
  16. data/node_modules/govuk-frontend/dist/govuk/all.mjs.map +1 -1
  17. data/node_modules/govuk-frontend/dist/govuk/all.scss +6 -0
  18. data/node_modules/govuk-frontend/dist/govuk/all.scss.map +1 -1
  19. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +164 -0
  20. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -0
  21. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
  22. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +1 -87
  23. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
  24. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +149 -112
  25. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js.map +1 -1
  26. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +148 -111
  27. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs.map +1 -1
  28. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +5 -8
  29. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs.map +1 -1
  30. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +149 -112
  31. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js.map +1 -1
  32. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +148 -111
  33. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs.map +1 -1
  34. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs +5 -8
  35. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs.map +1 -1
  36. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +174 -140
  37. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js.map +1 -1
  38. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +173 -139
  39. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs.map +1 -1
  40. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +17 -16
  41. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
  42. data/node_modules/govuk-frontend/dist/govuk/components/character-count/macro-options.json +4 -4
  43. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +1 -24
  44. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js.map +1 -1
  45. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +0 -23
  46. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
  47. data/node_modules/govuk-frontend/dist/govuk/components/date-input/macro-options.json +2 -2
  48. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +149 -112
  49. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js.map +1 -1
  50. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +148 -111
  51. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs.map +1 -1
  52. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +6 -8
  53. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs.map +1 -1
  54. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +149 -112
  55. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js.map +1 -1
  56. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +148 -111
  57. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs.map +1 -1
  58. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs +5 -8
  59. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs.map +1 -1
  60. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +1 -24
  61. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js.map +1 -1
  62. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +0 -23
  63. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs.map +1 -1
  64. data/node_modules/govuk-frontend/dist/govuk/components/input/macro-options.json +4 -4
  65. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +149 -112
  66. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js.map +1 -1
  67. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +148 -111
  68. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs.map +1 -1
  69. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs +6 -8
  70. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
  71. data/node_modules/govuk-frontend/dist/govuk/components/password-input/macro-options.json +1 -1
  72. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +149 -112
  73. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js.map +1 -1
  74. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +148 -111
  75. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs.map +1 -1
  76. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs +5 -8
  77. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs.map +1 -1
  78. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +1 -24
  79. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js.map +1 -1
  80. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +0 -23
  81. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
  82. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +1 -24
  83. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js.map +1 -1
  84. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +0 -23
  85. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs.map +1 -1
  86. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +1 -24
  87. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js.map +1 -1
  88. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +0 -23
  89. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs.map +1 -1
  90. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +1 -24
  91. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js.map +1 -1
  92. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +0 -23
  93. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
  94. data/node_modules/govuk-frontend/dist/govuk/components/textarea/macro-options.json +1 -1
  95. data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
  96. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +1 -1
  97. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css.map +1 -1
  98. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
  99. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js.map +1 -1
  100. data/node_modules/govuk-frontend/dist/govuk/init.mjs +17 -13
  101. data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
  102. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss +5 -10
  103. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss.map +1 -1
  104. data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +1 -1
  105. data/node_modules/govuk-frontend/package.json +9 -9
  106. metadata +4 -6
  107. data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs +0 -18
  108. data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs.map +0 -1
  109. data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs +0 -31
  110. data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs.map +0 -1
@@ -1,73 +1,3 @@
1
- function normaliseString(value, property) {
2
- const trimmedValue = value ? value.trim() : '';
3
- let output;
4
- let outputType = property == null ? void 0 : property.type;
5
- if (!outputType) {
6
- if (['true', 'false'].includes(trimmedValue)) {
7
- outputType = 'boolean';
8
- }
9
- if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
10
- outputType = 'number';
11
- }
12
- }
13
- switch (outputType) {
14
- case 'boolean':
15
- output = trimmedValue === 'true';
16
- break;
17
- case 'number':
18
- output = Number(trimmedValue);
19
- break;
20
- default:
21
- output = value;
22
- }
23
- return output;
24
- }
25
-
26
- /**
27
- * @typedef {import('./index.mjs').SchemaProperty} SchemaProperty
28
- */
29
-
30
- function mergeConfigs(...configObjects) {
31
- const formattedConfigObject = {};
32
- for (const configObject of configObjects) {
33
- for (const key of Object.keys(configObject)) {
34
- const option = formattedConfigObject[key];
35
- const override = configObject[key];
36
- if (isObject(option) && isObject(override)) {
37
- formattedConfigObject[key] = mergeConfigs(option, override);
38
- } else {
39
- formattedConfigObject[key] = override;
40
- }
41
- }
42
- }
43
- return formattedConfigObject;
44
- }
45
- function extractConfigByNamespace(Component, dataset, namespace) {
46
- const property = Component.schema.properties[namespace];
47
- if ((property == null ? void 0 : property.type) !== 'object') {
48
- return;
49
- }
50
- const newObject = {
51
- [namespace]: ({})
52
- };
53
- for (const [key, value] of Object.entries(dataset)) {
54
- let current = newObject;
55
- const keyParts = key.split('.');
56
- for (const [index, name] of keyParts.entries()) {
57
- if (typeof current === 'object') {
58
- if (index < keyParts.length - 1) {
59
- if (!isObject(current[name])) {
60
- current[name] = {};
61
- }
62
- current = current[name];
63
- } else if (key !== namespace) {
64
- current[name] = normaliseString(value);
65
- }
66
- }
67
- }
68
- }
69
- return newObject[namespace];
70
- }
71
1
  function isInitialised($root, moduleName) {
72
2
  return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);
73
3
  }
@@ -96,47 +26,11 @@ function isObject(option) {
96
26
  function formatErrorMessage(Component, message) {
97
27
  return `${Component.moduleName}: ${message}`;
98
28
  }
99
-
100
- /**
101
- * Schema for component config
102
- *
103
- * @typedef {object} Schema
104
- * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
105
- * @property {SchemaCondition[]} [anyOf] - List of schema conditions
106
- */
107
-
108
- /**
109
- * Schema property for component config
110
- *
111
- * @typedef {object} SchemaProperty
112
- * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
113
- */
114
-
115
- /**
116
- * Schema condition for component config
117
- *
118
- * @typedef {object} SchemaCondition
119
- * @property {string[]} required - List of required config fields
120
- * @property {string} errorMessage - Error message when required config fields not provided
121
- */
122
29
  /**
123
30
  * @typedef ComponentWithModuleName
124
31
  * @property {string} moduleName - Name of the component
125
32
  */
126
33
 
127
- function normaliseDataset(Component, dataset) {
128
- const out = {};
129
- for (const [field, property] of Object.entries(Component.schema.properties)) {
130
- if (field in dataset) {
131
- out[field] = normaliseString(dataset[field], property);
132
- }
133
- if ((property == null ? void 0 : property.type) === 'object') {
134
- out[field] = extractConfigByNamespace(Component, dataset, field);
135
- }
136
- }
137
- return out;
138
- }
139
-
140
34
  class GOVUKFrontendError extends Error {
141
35
  constructor(...args) {
142
36
  super(...args);
@@ -155,6 +49,12 @@ class SupportError extends GOVUKFrontendError {
155
49
  this.name = 'SupportError';
156
50
  }
157
51
  }
52
+ class ConfigError extends GOVUKFrontendError {
53
+ constructor(...args) {
54
+ super(...args);
55
+ this.name = 'ConfigError';
56
+ }
57
+ }
158
58
  class ElementError extends GOVUKFrontendError {
159
59
  constructor(messageOrOptions) {
160
60
  let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -239,6 +139,144 @@ class GOVUKFrontendComponent {
239
139
  */
240
140
  GOVUKFrontendComponent.elementType = HTMLElement;
241
141
 
142
+ const configOverride = Symbol.for('configOverride');
143
+ class ConfigurableComponent extends GOVUKFrontendComponent {
144
+ [configOverride](param) {
145
+ return {};
146
+ }
147
+
148
+ /**
149
+ * Returns the root element of the component
150
+ *
151
+ * @protected
152
+ * @returns {ConfigurationType} - the root element of component
153
+ */
154
+ get config() {
155
+ return this._config;
156
+ }
157
+ constructor($root, config) {
158
+ super($root);
159
+ this._config = void 0;
160
+ const childConstructor = this.constructor;
161
+ if (typeof childConstructor.defaults === 'undefined') {
162
+ throw new ConfigError(formatErrorMessage(childConstructor, 'Config passed as parameter into constructor but no defaults defined'));
163
+ }
164
+ const datasetConfig = normaliseDataset(childConstructor, this._$root.dataset);
165
+ this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {}, this[configOverride](datasetConfig), datasetConfig);
166
+ }
167
+ }
168
+ function normaliseString(value, property) {
169
+ const trimmedValue = value ? value.trim() : '';
170
+ let output;
171
+ let outputType = property == null ? void 0 : property.type;
172
+ if (!outputType) {
173
+ if (['true', 'false'].includes(trimmedValue)) {
174
+ outputType = 'boolean';
175
+ }
176
+ if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
177
+ outputType = 'number';
178
+ }
179
+ }
180
+ switch (outputType) {
181
+ case 'boolean':
182
+ output = trimmedValue === 'true';
183
+ break;
184
+ case 'number':
185
+ output = Number(trimmedValue);
186
+ break;
187
+ default:
188
+ output = value;
189
+ }
190
+ return output;
191
+ }
192
+ function normaliseDataset(Component, dataset) {
193
+ if (typeof Component.schema === 'undefined') {
194
+ throw new ConfigError(formatErrorMessage(Component, 'Config passed as parameter into constructor but no schema defined'));
195
+ }
196
+ const out = {};
197
+ for (const [field, property] of Object.entries(Component.schema.properties)) {
198
+ if (field in dataset) {
199
+ out[field] = normaliseString(dataset[field], property);
200
+ }
201
+ if ((property == null ? void 0 : property.type) === 'object') {
202
+ out[field] = extractConfigByNamespace(Component.schema, dataset, field);
203
+ }
204
+ }
205
+ return out;
206
+ }
207
+ function mergeConfigs(...configObjects) {
208
+ const formattedConfigObject = {};
209
+ for (const configObject of configObjects) {
210
+ for (const key of Object.keys(configObject)) {
211
+ const option = formattedConfigObject[key];
212
+ const override = configObject[key];
213
+ if (isObject(option) && isObject(override)) {
214
+ formattedConfigObject[key] = mergeConfigs(option, override);
215
+ } else {
216
+ formattedConfigObject[key] = override;
217
+ }
218
+ }
219
+ }
220
+ return formattedConfigObject;
221
+ }
222
+ function extractConfigByNamespace(schema, dataset, namespace) {
223
+ const property = schema.properties[namespace];
224
+ if ((property == null ? void 0 : property.type) !== 'object') {
225
+ return;
226
+ }
227
+ const newObject = {
228
+ [namespace]: ({})
229
+ };
230
+ for (const [key, value] of Object.entries(dataset)) {
231
+ let current = newObject;
232
+ const keyParts = key.split('.');
233
+ for (const [index, name] of keyParts.entries()) {
234
+ if (typeof current === 'object') {
235
+ if (index < keyParts.length - 1) {
236
+ if (!isObject(current[name])) {
237
+ current[name] = {};
238
+ }
239
+ current = current[name];
240
+ } else if (key !== namespace) {
241
+ current[name] = normaliseString(value);
242
+ }
243
+ }
244
+ }
245
+ }
246
+ return newObject[namespace];
247
+ }
248
+ /**
249
+ * Schema for component config
250
+ *
251
+ * @typedef {object} Schema
252
+ * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
253
+ * @property {SchemaCondition[]} [anyOf] - List of schema conditions
254
+ */
255
+ /**
256
+ * Schema property for component config
257
+ *
258
+ * @typedef {object} SchemaProperty
259
+ * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
260
+ */
261
+ /**
262
+ * Schema condition for component config
263
+ *
264
+ * @typedef {object} SchemaCondition
265
+ * @property {string[]} required - List of required config fields
266
+ * @property {string} errorMessage - Error message when required config fields not provided
267
+ */
268
+ /**
269
+ * @template {ObjectNested} [ConfigurationType={}]
270
+ * @typedef ChildClass
271
+ * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component
272
+ * @property {Schema} [schema] - The schema of the component configuration
273
+ * @property {ConfigurationType} [defaults] - The default values of the configuration of the component
274
+ */
275
+ /**
276
+ * @template {ObjectNested} [ConfigurationType={}]
277
+ * @typedef {typeof GOVUKFrontendComponent & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
278
+ */
279
+
242
280
  class I18n {
243
281
  constructor(translations = {}, config = {}) {
244
282
  var _config$locale;
@@ -445,15 +483,15 @@ I18n.pluralRules = {
445
483
  * attribute, which also provides accessibility.
446
484
  *
447
485
  * @preserve
486
+ * @augments ConfigurableComponent<AccordionConfig>
448
487
  */
449
- class Accordion extends GOVUKFrontendComponent {
488
+ class Accordion extends ConfigurableComponent {
450
489
  /**
451
490
  * @param {Element | null} $root - HTML element to use for accordion
452
491
  * @param {AccordionConfig} [config] - Accordion config
453
492
  */
454
493
  constructor($root, config = {}) {
455
- super($root);
456
- this.config = void 0;
494
+ super($root, config);
457
495
  this.i18n = void 0;
458
496
  this.controlsClass = 'govuk-accordion__controls';
459
497
  this.showAllClass = 'govuk-accordion__show-all';
@@ -478,7 +516,6 @@ class Accordion extends GOVUKFrontendComponent {
478
516
  this.$showAllButton = null;
479
517
  this.$showAllIcon = null;
480
518
  this.$showAllText = null;
481
- this.config = mergeConfigs(Accordion.defaults, config, normaliseDataset(Accordion, this.$root.dataset));
482
519
  this.i18n = new I18n(this.config.i18n);
483
520
  const $sections = this.$root.querySelectorAll(`.${this.sectionClass}`);
484
521
  if (!$sections.length) {
@@ -748,7 +785,7 @@ class Accordion extends GOVUKFrontendComponent {
748
785
  */
749
786
 
750
787
  /**
751
- * @typedef {import('../../common/index.mjs').Schema} Schema
788
+ * @typedef {import('../../common/configuration.mjs').Schema} Schema
752
789
  */
753
790
  Accordion.moduleName = 'govuk-accordion';
754
791
  Accordion.defaults = Object.freeze({