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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +29 -34
  3. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +7 -2
  4. data/app/assets/stylesheets/component_guide/application.scss +1 -1
  5. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  6. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +2 -2
  7. data/app/models/govuk_publishing_components/audit_comparer.rb +3 -3
  8. data/app/views/govuk_publishing_components/components/_title.html.erb +2 -3
  9. data/app/views/govuk_publishing_components/components/docs/add_another.yml +1 -1
  10. data/app/views/govuk_publishing_components/components/docs/feedback.yml +1 -1
  11. data/lib/govuk_publishing_components/presenters/checkboxes_helper.rb +1 -1
  12. data/lib/govuk_publishing_components/presenters/shared_helper.rb +0 -11
  13. data/lib/govuk_publishing_components/version.rb +1 -1
  14. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +217 -184
  15. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
  16. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +216 -184
  17. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
  18. data/node_modules/govuk-frontend/dist/govuk/all.mjs +1 -0
  19. data/node_modules/govuk-frontend/dist/govuk/all.mjs.map +1 -1
  20. data/node_modules/govuk-frontend/dist/govuk/all.scss +6 -0
  21. data/node_modules/govuk-frontend/dist/govuk/all.scss.map +1 -1
  22. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +164 -0
  23. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -0
  24. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
  25. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +1 -87
  26. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
  27. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +149 -112
  28. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js.map +1 -1
  29. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +148 -111
  30. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs.map +1 -1
  31. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +5 -8
  32. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs.map +1 -1
  33. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +149 -112
  34. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js.map +1 -1
  35. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +148 -111
  36. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs.map +1 -1
  37. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs +5 -8
  38. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs.map +1 -1
  39. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +174 -140
  40. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js.map +1 -1
  41. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +173 -139
  42. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs.map +1 -1
  43. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +17 -16
  44. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
  45. data/node_modules/govuk-frontend/dist/govuk/components/character-count/macro-options.json +4 -4
  46. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +1 -24
  47. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js.map +1 -1
  48. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +0 -23
  49. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
  50. data/node_modules/govuk-frontend/dist/govuk/components/date-input/macro-options.json +2 -2
  51. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +149 -112
  52. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js.map +1 -1
  53. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +148 -111
  54. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs.map +1 -1
  55. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +6 -8
  56. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs.map +1 -1
  57. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +149 -112
  58. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js.map +1 -1
  59. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +148 -111
  60. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs.map +1 -1
  61. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs +5 -8
  62. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs.map +1 -1
  63. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +1 -24
  64. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js.map +1 -1
  65. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +0 -23
  66. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs.map +1 -1
  67. data/node_modules/govuk-frontend/dist/govuk/components/input/macro-options.json +4 -4
  68. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +149 -112
  69. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js.map +1 -1
  70. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +148 -111
  71. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs.map +1 -1
  72. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs +6 -8
  73. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
  74. data/node_modules/govuk-frontend/dist/govuk/components/password-input/macro-options.json +1 -1
  75. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +149 -112
  76. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js.map +1 -1
  77. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +148 -111
  78. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs.map +1 -1
  79. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs +5 -8
  80. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs.map +1 -1
  81. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +1 -24
  82. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js.map +1 -1
  83. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +0 -23
  84. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
  85. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +1 -24
  86. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js.map +1 -1
  87. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +0 -23
  88. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs.map +1 -1
  89. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +1 -24
  90. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js.map +1 -1
  91. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +0 -23
  92. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs.map +1 -1
  93. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +1 -24
  94. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js.map +1 -1
  95. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +0 -23
  96. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
  97. data/node_modules/govuk-frontend/dist/govuk/components/textarea/macro-options.json +1 -1
  98. data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
  99. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +1 -1
  100. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css.map +1 -1
  101. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
  102. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js.map +1 -1
  103. data/node_modules/govuk-frontend/dist/govuk/init.mjs +17 -13
  104. data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
  105. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss +5 -10
  106. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss.map +1 -1
  107. data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +1 -1
  108. data/node_modules/govuk-frontend/package.json +9 -9
  109. metadata +4 -6
  110. data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs +0 -18
  111. data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs.map +0 -1
  112. data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs +0 -31
  113. 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;
@@ -436,15 +474,15 @@ I18n.pluralRules = {
436
474
  * Exit this page component
437
475
  *
438
476
  * @preserve
477
+ * @augments ConfigurableComponent<ExitThisPageConfig>
439
478
  */
440
- class ExitThisPage extends GOVUKFrontendComponent {
479
+ class ExitThisPage extends ConfigurableComponent {
441
480
  /**
442
481
  * @param {Element | null} $root - HTML element that wraps the Exit This Page button
443
482
  * @param {ExitThisPageConfig} [config] - Exit This Page config
444
483
  */
445
484
  constructor($root, config = {}) {
446
- super($root);
447
- this.config = void 0;
485
+ super($root, config);
448
486
  this.i18n = void 0;
449
487
  this.$button = void 0;
450
488
  this.$skiplinkButton = null;
@@ -465,7 +503,6 @@ class ExitThisPage extends GOVUKFrontendComponent {
465
503
  identifier: 'Button (`.govuk-exit-this-page__button`)'
466
504
  });
467
505
  }
468
- this.config = mergeConfigs(ExitThisPage.defaults, config, normaliseDataset(ExitThisPage, this.$root.dataset));
469
506
  this.i18n = new I18n(this.config.i18n);
470
507
  this.$button = $button;
471
508
  const $skiplinkButton = document.querySelector('.govuk-js-exit-this-page-skiplink');
@@ -631,7 +668,7 @@ class ExitThisPage extends GOVUKFrontendComponent {
631
668
  */
632
669
 
633
670
  /**
634
- * @typedef {import('../../common/index.mjs').Schema} Schema
671
+ * @typedef {import('../../common/configuration.mjs').Schema} Schema
635
672
  */
636
673
  ExitThisPage.moduleName = 'govuk-exit-this-page';
637
674
  ExitThisPage.defaults = Object.freeze({