katalyst-govuk-formbuilder 1.21.1 → 1.23.0
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/builds/katalyst/govuk/formbuilder.css +38 -1
- data/app/assets/builds/katalyst/govuk/formbuilder.js +29 -134
- data/app/assets/builds/katalyst/govuk/formbuilder.min.js +8 -8
- data/app/assets/builds/katalyst/govuk/formbuilder.min.js.map +1 -1
- data/lib/katalyst/govuk/form_builder/builder.rb +45 -0
- data/lib/katalyst/govuk/form_builder/config.rb +0 -2
- data/lib/katalyst/govuk/form_builder/elements/time.rb +26 -0
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/_index.scss +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/breadcrumbs/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/button/_index.scss +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/file-upload/_index.scss +2 -1
- data/node_modules/govuk-frontend/dist/govuk/components/footer/_index.scss +4 -4
- data/node_modules/govuk-frontend/dist/govuk/components/header/_index.scss +20 -20
- data/node_modules/govuk-frontend/dist/govuk/components/input/_index.scss +7 -15
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/pagination/_index.scss +4 -2
- data/node_modules/govuk-frontend/dist/govuk/components/panel/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/_index.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/components/phase-banner/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/radios/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/select/_index.scss +1 -7
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_index.scss +5 -5
- data/node_modules/govuk-frontend/dist/govuk/components/summary-list/_index.scss +16 -16
- data/node_modules/govuk-frontend/dist/govuk/components/table/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/components/textarea/_index.scss +1 -7
- data/node_modules/govuk-frontend/dist/govuk/components/warning-text/_index.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/core/_lists.scss +2 -2
- data/node_modules/govuk-frontend/dist/govuk/core/_typography.scss +3 -3
- data/node_modules/govuk-frontend/dist/govuk/helpers/_focused.scss +34 -0
- data/node_modules/govuk-frontend/dist/govuk/helpers/_grid.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_links.scss +1 -1
- 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 +4 -4
- data/node_modules/govuk-frontend/dist/govuk/objects/_button-group.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/objects/_main-wrapper.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/objects/_template.scss +1 -1
- 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/_width.scss +5 -5
- data/node_modules/govuk-frontend/dist/govuk/settings/_media-queries.scss +7 -0
- data/node_modules/govuk-frontend/dist/govuk/tools/_px-to-em.scss +4 -2
- metadata +2 -2
- data/node_modules/govuk-frontend/dist/govuk/vendor/_sass-mq.scss +0 -349
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87aecd3c3100c9c5f2d9d6289dc73cc67e055d6ddcad10cdf842555e12403b57
|
|
4
|
+
data.tar.gz: e986efd621a603a205c81cf2e4201c21251189b49805c42bc144c82efd08f828
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8158813f1352293635e87e7b56a17791e9f786985ebc1f7e14cb3b8275eb4ffad250eaa0040bd0e1ee49490e4dec9ab495fa435c3497bfd79a1b485adca6681
|
|
7
|
+
data.tar.gz: 138a91674a46883f489c00e53f73bcde0682a7a54cf44e41d0521384bdee5400543b194e9e8645926a6a187cfde74a86a595ee7b1635b59e7818fcfed0bdb0c2
|
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
43
48
|
|
|
44
49
|
|
|
45
50
|
|
|
@@ -47,7 +52,7 @@
|
|
|
47
52
|
|
|
48
53
|
|
|
49
54
|
:root {
|
|
50
|
-
--govuk-frontend-version: "5.
|
|
55
|
+
--govuk-frontend-version: "5.13.0";
|
|
51
56
|
--govuk-breakpoint-mobile: 20rem;
|
|
52
57
|
--govuk-frontend-breakpoint-mobile: var(--govuk-breakpoint-mobile);
|
|
53
58
|
--govuk-breakpoint-tablet: 40.0625rem;
|
|
@@ -890,6 +895,11 @@
|
|
|
890
895
|
|
|
891
896
|
|
|
892
897
|
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
893
903
|
|
|
894
904
|
|
|
895
905
|
|
|
@@ -1004,6 +1014,11 @@
|
|
|
1004
1014
|
|
|
1005
1015
|
|
|
1006
1016
|
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1007
1022
|
|
|
1008
1023
|
|
|
1009
1024
|
|
|
@@ -1078,6 +1093,11 @@
|
|
|
1078
1093
|
|
|
1079
1094
|
|
|
1080
1095
|
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1081
1101
|
|
|
1082
1102
|
|
|
1083
1103
|
|
|
@@ -1274,6 +1294,11 @@
|
|
|
1274
1294
|
|
|
1275
1295
|
|
|
1276
1296
|
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1277
1302
|
|
|
1278
1303
|
|
|
1279
1304
|
|
|
@@ -1345,6 +1370,11 @@
|
|
|
1345
1370
|
|
|
1346
1371
|
|
|
1347
1372
|
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1348
1378
|
|
|
1349
1379
|
|
|
1350
1380
|
|
|
@@ -1424,6 +1454,11 @@
|
|
|
1424
1454
|
|
|
1425
1455
|
|
|
1426
1456
|
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1427
1462
|
|
|
1428
1463
|
|
|
1429
1464
|
|
|
@@ -2483,6 +2518,8 @@
|
|
|
2483
2518
|
padding: 15px 10px;
|
|
2484
2519
|
background-color: #ffffff;
|
|
2485
2520
|
text-align: left;
|
|
2521
|
+
word-wrap: break-word;
|
|
2522
|
+
overflow-wrap: break-word;
|
|
2486
2523
|
}
|
|
2487
2524
|
|
|
2488
2525
|
.govuk-file-upload-button__pseudo-button-container {
|
|
@@ -318,7 +318,7 @@ class I18n {
|
|
|
318
318
|
return "other";
|
|
319
319
|
}
|
|
320
320
|
const translation = this.translations[lookupKey];
|
|
321
|
-
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) :
|
|
321
|
+
const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : "other";
|
|
322
322
|
if (isObject(translation)) {
|
|
323
323
|
if (preferredForm in translation) {
|
|
324
324
|
return preferredForm;
|
|
@@ -329,135 +329,8 @@ class I18n {
|
|
|
329
329
|
}
|
|
330
330
|
throw new Error(`i18n: Plural form ".other" is required for "${this.locale}" locale`);
|
|
331
331
|
}
|
|
332
|
-
selectPluralFormUsingFallbackRules(count) {
|
|
333
|
-
count = Math.abs(Math.floor(count));
|
|
334
|
-
const ruleset = this.getPluralRulesForLocale();
|
|
335
|
-
if (ruleset) {
|
|
336
|
-
return I18n.pluralRules[ruleset](count);
|
|
337
|
-
}
|
|
338
|
-
return "other";
|
|
339
|
-
}
|
|
340
|
-
getPluralRulesForLocale() {
|
|
341
|
-
const localeShort = this.locale.split("-")[0];
|
|
342
|
-
for (const pluralRule in I18n.pluralRulesMap) {
|
|
343
|
-
const languages = I18n.pluralRulesMap[pluralRule];
|
|
344
|
-
if (languages.includes(this.locale) || languages.includes(localeShort)) {
|
|
345
|
-
return pluralRule;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
332
|
}
|
|
350
333
|
|
|
351
|
-
I18n.pluralRulesMap = {
|
|
352
|
-
arabic: [ "ar" ],
|
|
353
|
-
chinese: [ "my", "zh", "id", "ja", "jv", "ko", "ms", "th", "vi" ],
|
|
354
|
-
french: [ "hy", "bn", "fr", "gu", "hi", "fa", "pa", "zu" ],
|
|
355
|
-
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" ],
|
|
356
|
-
irish: [ "ga" ],
|
|
357
|
-
russian: [ "ru", "uk" ],
|
|
358
|
-
scottish: [ "gd" ],
|
|
359
|
-
spanish: [ "pt-PT", "it", "es" ],
|
|
360
|
-
welsh: [ "cy" ]
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
I18n.pluralRules = {
|
|
364
|
-
arabic(n) {
|
|
365
|
-
if (n === 0) {
|
|
366
|
-
return "zero";
|
|
367
|
-
}
|
|
368
|
-
if (n === 1) {
|
|
369
|
-
return "one";
|
|
370
|
-
}
|
|
371
|
-
if (n === 2) {
|
|
372
|
-
return "two";
|
|
373
|
-
}
|
|
374
|
-
if (n % 100 >= 3 && n % 100 <= 10) {
|
|
375
|
-
return "few";
|
|
376
|
-
}
|
|
377
|
-
if (n % 100 >= 11 && n % 100 <= 99) {
|
|
378
|
-
return "many";
|
|
379
|
-
}
|
|
380
|
-
return "other";
|
|
381
|
-
},
|
|
382
|
-
chinese() {
|
|
383
|
-
return "other";
|
|
384
|
-
},
|
|
385
|
-
french(n) {
|
|
386
|
-
return n === 0 || n === 1 ? "one" : "other";
|
|
387
|
-
},
|
|
388
|
-
german(n) {
|
|
389
|
-
return n === 1 ? "one" : "other";
|
|
390
|
-
},
|
|
391
|
-
irish(n) {
|
|
392
|
-
if (n === 1) {
|
|
393
|
-
return "one";
|
|
394
|
-
}
|
|
395
|
-
if (n === 2) {
|
|
396
|
-
return "two";
|
|
397
|
-
}
|
|
398
|
-
if (n >= 3 && n <= 6) {
|
|
399
|
-
return "few";
|
|
400
|
-
}
|
|
401
|
-
if (n >= 7 && n <= 10) {
|
|
402
|
-
return "many";
|
|
403
|
-
}
|
|
404
|
-
return "other";
|
|
405
|
-
},
|
|
406
|
-
russian(n) {
|
|
407
|
-
const lastTwo = n % 100;
|
|
408
|
-
const last = lastTwo % 10;
|
|
409
|
-
if (last === 1 && lastTwo !== 11) {
|
|
410
|
-
return "one";
|
|
411
|
-
}
|
|
412
|
-
if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) {
|
|
413
|
-
return "few";
|
|
414
|
-
}
|
|
415
|
-
if (last === 0 || last >= 5 && last <= 9 || lastTwo >= 11 && lastTwo <= 14) {
|
|
416
|
-
return "many";
|
|
417
|
-
}
|
|
418
|
-
return "other";
|
|
419
|
-
},
|
|
420
|
-
scottish(n) {
|
|
421
|
-
if (n === 1 || n === 11) {
|
|
422
|
-
return "one";
|
|
423
|
-
}
|
|
424
|
-
if (n === 2 || n === 12) {
|
|
425
|
-
return "two";
|
|
426
|
-
}
|
|
427
|
-
if (n >= 3 && n <= 10 || n >= 13 && n <= 19) {
|
|
428
|
-
return "few";
|
|
429
|
-
}
|
|
430
|
-
return "other";
|
|
431
|
-
},
|
|
432
|
-
spanish(n) {
|
|
433
|
-
if (n === 1) {
|
|
434
|
-
return "one";
|
|
435
|
-
}
|
|
436
|
-
if (n % 1e6 === 0 && n !== 0) {
|
|
437
|
-
return "many";
|
|
438
|
-
}
|
|
439
|
-
return "other";
|
|
440
|
-
},
|
|
441
|
-
welsh(n) {
|
|
442
|
-
if (n === 0) {
|
|
443
|
-
return "zero";
|
|
444
|
-
}
|
|
445
|
-
if (n === 1) {
|
|
446
|
-
return "one";
|
|
447
|
-
}
|
|
448
|
-
if (n === 2) {
|
|
449
|
-
return "two";
|
|
450
|
-
}
|
|
451
|
-
if (n === 3) {
|
|
452
|
-
return "few";
|
|
453
|
-
}
|
|
454
|
-
if (n === 6) {
|
|
455
|
-
return "many";
|
|
456
|
-
}
|
|
457
|
-
return "other";
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
334
|
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
|
|
462
335
|
|
|
463
336
|
/**
|
|
@@ -1018,7 +891,7 @@ ErrorSummary.schema = Object.freeze({
|
|
|
1018
891
|
if (this.$button.disabled) return;
|
|
1019
892
|
if (event.target instanceof Node) {
|
|
1020
893
|
if (this.$root.contains(event.target)) {
|
|
1021
|
-
if (event.dataTransfer &&
|
|
894
|
+
if (event.dataTransfer && this.canDrop(event.dataTransfer)) {
|
|
1022
895
|
if (!this.$button.classList.contains("govuk-file-upload-button--dragging")) {
|
|
1023
896
|
this.showDraggingState();
|
|
1024
897
|
this.$announcements.innerText = this.i18n.t("enteredDropZone");
|
|
@@ -1040,12 +913,30 @@ ErrorSummary.schema = Object.freeze({
|
|
|
1040
913
|
}
|
|
1041
914
|
onDrop(event) {
|
|
1042
915
|
event.preventDefault();
|
|
1043
|
-
if (event.dataTransfer &&
|
|
916
|
+
if (event.dataTransfer && this.canFillInput(event.dataTransfer)) {
|
|
1044
917
|
this.$input.files = event.dataTransfer.files;
|
|
1045
918
|
this.$input.dispatchEvent(new CustomEvent("change"));
|
|
1046
919
|
this.hideDraggingState();
|
|
1047
920
|
}
|
|
1048
921
|
}
|
|
922
|
+
canFillInput(dataTransfer) {
|
|
923
|
+
return this.matchesInputCapacity(dataTransfer.files.length);
|
|
924
|
+
}
|
|
925
|
+
canDrop(dataTransfer) {
|
|
926
|
+
if (dataTransfer.items.length) {
|
|
927
|
+
return this.matchesInputCapacity(countFileItems(dataTransfer.items));
|
|
928
|
+
}
|
|
929
|
+
if (dataTransfer.types.length) {
|
|
930
|
+
return dataTransfer.types.includes("Files");
|
|
931
|
+
}
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
matchesInputCapacity(numberOfFiles) {
|
|
935
|
+
if (this.$input.multiple) {
|
|
936
|
+
return numberOfFiles > 0;
|
|
937
|
+
}
|
|
938
|
+
return numberOfFiles === 1;
|
|
939
|
+
}
|
|
1049
940
|
onChange() {
|
|
1050
941
|
const fileCount = this.$input.files.length;
|
|
1051
942
|
if (fileCount === 0) {
|
|
@@ -1117,10 +1008,14 @@ FileUpload.schema = Object.freeze({
|
|
|
1117
1008
|
}
|
|
1118
1009
|
});
|
|
1119
1010
|
|
|
1120
|
-
function
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1011
|
+
function countFileItems(list) {
|
|
1012
|
+
let result = 0;
|
|
1013
|
+
for (let i = 0; i < list.length; i++) {
|
|
1014
|
+
if (list[i].kind === "file") {
|
|
1015
|
+
result++;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return result;
|
|
1124
1019
|
}
|
|
1125
1020
|
|
|
1126
1021
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{Controller as
|
|
1
|
+
import{Controller as t}from"@hotwired/stimulus";function e(t=document.body){return!!t&&t.classList.contains("govuk-frontend-supported")}function n(t){return!!t&&"object"==typeof t&&!function(t){return Array.isArray(t)}(t)}function i(t,e){return`${t.moduleName}: ${e}`}class s extends Error{constructor(...t){super(...t),this.name="GOVUKFrontendError"}}class o extends s{constructor(t=document.body){const e="noModule"in HTMLScriptElement.prototype?'GOV.UK Frontend initialised without `<body class="govuk-frontend-supported">` from template `<script>` snippet':"GOV.UK Frontend is not supported in this browser";super(t?e:'GOV.UK Frontend initialised without `<script type="module">`'),this.name="SupportError"}}class r extends s{constructor(...t){super(...t),this.name="ConfigError"}}class a extends s{constructor(t){let e="string"==typeof t?t:"";if(n(t)){const{component:n,identifier:s,element:o,expectedType:r}=t;e=s,e+=o?` is not of type ${null!=r?r:"HTMLElement"}`:" not found",n&&(e=i(n,e))}super(e),this.name="ElementError"}}class u extends s{constructor(t){super("string"==typeof t?t:i(t,"Root element (`$root`) already initialised")),this.name="InitError"}}class l{get $root(){return this._$root}constructor(t){this._$root=void 0;const e=this.constructor;if("string"!=typeof e.moduleName)throw new u("`moduleName` not defined in component");if(!(t instanceof e.elementType))throw new a({element:t,component:e,identifier:"Root element (`$root`)",expectedType:e.elementType.name});this._$root=t,e.checkSupport(),this.checkInitialised();const n=e.moduleName;this.$root.setAttribute(`data-${n}-init`,"")}checkInitialised(){const t=this.constructor,e=t.moduleName;if(e&&function(t,e){return t instanceof HTMLElement&&t.hasAttribute(`data-${e}-init`)}(this.$root,e))throw new u(t)}static checkSupport(){if(!e())throw new o}}l.elementType=HTMLElement;const c=Symbol.for("configOverride");class d extends l{[c](t){return{}}get config(){return this._config}constructor(t,e){super(t),this._config=void 0;const s=this.constructor;if(!n(s.defaults))throw new r(i(s,"Config passed as parameter into constructor but no defaults defined"));const o=function(t,e){if(!n(t.schema))throw new r(i(t,"Config passed as parameter into constructor but no schema defined"));const s={},o=Object.entries(t.schema.properties);for(const n of o){const[i,o]=n,r=i.toString();r in e&&(s[r]=h(e[r],o)),"object"===(null==o?void 0:o.type)&&(s[r]=m(t.schema,e,i))}return s}(s,this._$root.dataset);this._config=p(s.defaults,null!=e?e:{},this[c](o),o)}}function h(t,e){const n=t?t.trim():"";let i,s=null==e?void 0:e.type;switch(s||(["true","false"].includes(n)&&(s="boolean"),n.length>0&&isFinite(Number(n))&&(s="number")),s){case"boolean":i="true"===n;break;case"number":i=Number(n);break;default:i=t}return i}function p(...t){const e={};for(const i of t)for(const t of Object.keys(i)){const s=e[t],o=i[t];n(s)&&n(o)?e[t]=p(s,o):e[t]=o}return e}function m(t,e,i){const s=t.properties[i];if("object"!==(null==s?void 0:s.type))return;const o={[i]:{}};for(const[t,s]of Object.entries(e)){let e=o;const r=t.split(".");for(const[o,a]of r.entries())n(e)&&(o<r.length-1?(n(e[a])||(e[a]={}),e=e[a]):t!==i&&(e[a]=h(s)))}return o[i]}class g{constructor(t={},e={}){var n;this.translations=void 0,this.locale=void 0,this.translations=t,this.locale=null!=(n=e.locale)?n:document.documentElement.lang||"en"}t(t,e){if(!t)throw new Error("i18n: lookup key missing");let i=this.translations[t];if("number"==typeof(null==e?void 0:e.count)&&n(i)){const n=i[this.getPluralSuffix(t,e.count)];n&&(i=n)}if("string"==typeof i){if(i.match(/%{(.\S+)}/)){if(!e)throw new Error("i18n: cannot replace placeholders in string if no option data provided");return this.replacePlaceholders(i,e)}return i}return t}replacePlaceholders(t,e){const n=Intl.NumberFormat.supportedLocalesOf(this.locale).length?new Intl.NumberFormat(this.locale):void 0;return t.replace(/%{(.\S+)}/g,function(t,i){if(Object.prototype.hasOwnProperty.call(e,i)){const t=e[i];return!1===t||"number"!=typeof t&&"string"!=typeof t?"":"number"==typeof t?n?n.format(t):`${t}`:t}throw new Error(`i18n: no data found to replace ${t} placeholder in string`)})}hasIntlPluralRulesSupport(){return Boolean("PluralRules"in window.Intl&&Intl.PluralRules.supportedLocalesOf(this.locale).length)}getPluralSuffix(t,e){if(e=Number(e),!isFinite(e))return"other";const i=this.translations[t],s=this.hasIntlPluralRulesSupport()?new Intl.PluralRules(this.locale).select(e):"other";if(n(i)){if(s in i)return s;if("other"in i)return console.warn(`i18n: Missing plural form ".${s}" for "${this.locale}" locale. Falling back to ".other".`),"other"}throw new Error(`i18n: Plural form ".other" is required for "${this.locale}" locale`)}}
|
|
2
2
|
/**
|
|
3
3
|
* JavaScript enhancements for the Button component
|
|
4
4
|
*
|
|
5
5
|
* @preserve
|
|
6
6
|
* @augments ConfigurableComponent<ButtonConfig>
|
|
7
7
|
*/
|
|
8
|
-
class f extends d{constructor(e
|
|
8
|
+
class f extends d{constructor(t,e={}){super(t,e),this.debounceFormSubmitTimer=null,this.$root.addEventListener("keydown",t=>this.handleKeyDown(t)),this.$root.addEventListener("click",t=>this.debounce(t))}handleKeyDown(t){const e=t.target;" "===t.key&&e instanceof HTMLElement&&"button"===e.getAttribute("role")&&(t.preventDefault(),e.click())}debounce(t){if(this.config.preventDoubleClick)return this.debounceFormSubmitTimer?(t.preventDefault(),!1):void(this.debounceFormSubmitTimer=window.setTimeout(()=>{this.debounceFormSubmitTimer=null},1e3))}}function v(t,e){const n=t.closest(`[${e}]`);return n?n.getAttribute(e):null}
|
|
9
9
|
/**
|
|
10
10
|
* Character count component
|
|
11
11
|
*
|
|
@@ -18,13 +18,13 @@ class f extends d{constructor(e,t={}){super(e,t),this.debounceFormSubmitTimer=nu
|
|
|
18
18
|
*
|
|
19
19
|
* @preserve
|
|
20
20
|
* @augments ConfigurableComponent<CharacterCountConfig>
|
|
21
|
-
*/f.moduleName="govuk-button",f.defaults=Object.freeze({preventDoubleClick:!1}),f.schema=Object.freeze({properties:{preventDoubleClick:{type:"boolean"}}});class b extends d{[c](
|
|
21
|
+
*/f.moduleName="govuk-button",f.defaults=Object.freeze({preventDoubleClick:!1}),f.schema=Object.freeze({properties:{preventDoubleClick:{type:"boolean"}}});class b extends d{[c](t){let e={};return("maxwords"in t||"maxlength"in t)&&(e={maxlength:void 0,maxwords:void 0}),e}constructor(t,e={}){var n,s;super(t,e),this.$textarea=void 0,this.$visibleCountMessage=void 0,this.$screenReaderCountMessage=void 0,this.lastInputTimestamp=null,this.lastInputValue="",this.valueChecker=null,this.i18n=void 0,this.maxLength=void 0;const o=this.$root.querySelector(".govuk-js-character-count");if(!(o instanceof HTMLTextAreaElement||o instanceof HTMLInputElement))throw new a({component:b,element:o,expectedType:"HTMLTextareaElement or HTMLInputElement",identifier:"Form field (`.govuk-js-character-count`)"});const u=function(t,e){const n=[];for(const[i,s]of Object.entries(t)){const t=[];if(Array.isArray(s)){for(const{required:n,errorMessage:i}of s)n.every(t=>!!e[t])||t.push(i);"anyOf"!==i||s.length-t.length>=1||n.push(...t)}}return n}(b.schema,this.config);if(u[0])throw new r(i(b,u[0]));this.i18n=new g(this.config.i18n,{locale:v(this.$root,"lang")}),this.maxLength=null!=(n=null!=(s=this.config.maxwords)?s:this.config.maxlength)?n:1/0,this.$textarea=o;const l=`${this.$textarea.id}-info`,c=document.getElementById(l);if(!c)throw new a({component:b,element:c,identifier:`Count message (\`id="${l}"\`)`});this.$errorMessage=this.$root.querySelector(".govuk-error-message"),c.textContent.match(/^\s*$/)&&(c.textContent=this.i18n.t("textareaDescription",{count:this.maxLength})),this.$textarea.insertAdjacentElement("afterend",c);const d=document.createElement("div");d.className="govuk-character-count__sr-status govuk-visually-hidden",d.setAttribute("aria-live","polite"),this.$screenReaderCountMessage=d,c.insertAdjacentElement("afterend",d);const h=document.createElement("div");h.className=c.className,h.classList.add("govuk-character-count__status"),h.setAttribute("aria-hidden","true"),this.$visibleCountMessage=h,c.insertAdjacentElement("afterend",h),c.classList.add("govuk-visually-hidden"),this.$textarea.removeAttribute("maxlength"),this.bindChangeEvents(),window.addEventListener("pageshow",()=>this.updateCountMessage()),this.updateCountMessage()}bindChangeEvents(){this.$textarea.addEventListener("keyup",()=>this.handleKeyUp()),this.$textarea.addEventListener("focus",()=>this.handleFocus()),this.$textarea.addEventListener("blur",()=>this.handleBlur())}handleKeyUp(){this.updateVisibleCountMessage(),this.lastInputTimestamp=Date.now()}handleFocus(){this.valueChecker=window.setInterval(()=>{(!this.lastInputTimestamp||Date.now()-500>=this.lastInputTimestamp)&&this.updateIfValueChanged()},1e3)}handleBlur(){this.valueChecker&&window.clearInterval(this.valueChecker)}updateIfValueChanged(){this.$textarea.value!==this.lastInputValue&&(this.lastInputValue=this.$textarea.value,this.updateCountMessage())}updateCountMessage(){this.updateVisibleCountMessage(),this.updateScreenReaderCountMessage()}updateVisibleCountMessage(){const t=this.maxLength-this.count(this.$textarea.value)<0;this.$visibleCountMessage.classList.toggle("govuk-character-count__message--disabled",!this.isOverThreshold()),this.$errorMessage||this.$textarea.classList.toggle("govuk-textarea--error",t),this.$visibleCountMessage.classList.toggle("govuk-error-message",t),this.$visibleCountMessage.classList.toggle("govuk-hint",!t),this.$visibleCountMessage.textContent=this.getCountMessage()}updateScreenReaderCountMessage(){this.isOverThreshold()?this.$screenReaderCountMessage.removeAttribute("aria-hidden"):this.$screenReaderCountMessage.setAttribute("aria-hidden","true"),this.$screenReaderCountMessage.textContent=this.getCountMessage()}count(t){if(this.config.maxwords){var e;return(null!=(e=t.match(/\S+/g))?e:[]).length}return t.length}getCountMessage(){const t=this.maxLength-this.count(this.$textarea.value),e=this.config.maxwords?"words":"characters";return this.formatCountMessage(t,e)}formatCountMessage(t,e){if(0===t)return this.i18n.t(`${e}AtLimit`);const n=t<0?"OverLimit":"UnderLimit";return this.i18n.t(`${e}${n}`,{count:Math.abs(t)})}isOverThreshold(){if(!this.config.threshold)return!0;const t=this.count(this.$textarea.value);return this.maxLength*this.config.threshold/100<=t}}b.moduleName="govuk-character-count",b.defaults=Object.freeze({threshold:0,i18n:{charactersUnderLimit:{one:"You have %{count} character remaining",other:"You have %{count} characters remaining"},charactersAtLimit:"You have 0 characters remaining",charactersOverLimit:{one:"You have %{count} character too many",other:"You have %{count} characters too many"},wordsUnderLimit:{one:"You have %{count} word remaining",other:"You have %{count} words remaining"},wordsAtLimit:"You have 0 words remaining",wordsOverLimit:{one:"You have %{count} word too many",other:"You have %{count} words too many"},textareaDescription:{other:""}}}),b.schema=Object.freeze({properties:{i18n:{type:"object"},maxwords:{type:"number"},maxlength:{type:"number"},threshold:{type:"number"}},anyOf:[{required:["maxwords"],errorMessage:'Either "maxlength" or "maxwords" must be provided'},{required:["maxlength"],errorMessage:'Either "maxlength" or "maxwords" must be provided'}]});
|
|
22
22
|
/**
|
|
23
23
|
* Checkboxes component
|
|
24
24
|
*
|
|
25
25
|
* @preserve
|
|
26
26
|
*/
|
|
27
|
-
class w extends
|
|
27
|
+
class w extends l{constructor(t){super(t),this.$inputs=void 0;const e=this.$root.querySelectorAll('input[type="checkbox"]');if(!e.length)throw new a({component:w,identifier:'Form inputs (`<input type="checkbox">`)'});this.$inputs=e,this.$inputs.forEach(t=>{const e=t.getAttribute("data-aria-controls");if(e){if(!document.getElementById(e))throw new a({component:w,identifier:`Conditional reveal (\`id="${e}"\`)`});t.setAttribute("aria-controls",e),t.removeAttribute("data-aria-controls")}}),window.addEventListener("pageshow",()=>this.syncAllConditionalReveals()),this.syncAllConditionalReveals(),this.$root.addEventListener("click",t=>this.handleClick(t))}syncAllConditionalReveals(){this.$inputs.forEach(t=>this.syncConditionalRevealWithInputState(t))}syncConditionalRevealWithInputState(t){const e=t.getAttribute("aria-controls");if(!e)return;const n=document.getElementById(e);if(null!=n&&n.classList.contains("govuk-checkboxes__conditional")){const e=t.checked;t.setAttribute("aria-expanded",e.toString()),n.classList.toggle("govuk-checkboxes__conditional--hidden",!e)}}unCheckAllInputsExcept(t){document.querySelectorAll(`input[type="checkbox"][name="${t.name}"]`).forEach(e=>{t.form===e.form&&e!==t&&(e.checked=!1,this.syncConditionalRevealWithInputState(e))})}unCheckExclusiveInputs(t){document.querySelectorAll(`input[data-behaviour="exclusive"][type="checkbox"][name="${t.name}"]`).forEach(e=>{t.form===e.form&&(e.checked=!1,this.syncConditionalRevealWithInputState(e))})}handleClick(t){const e=t.target;if(!(e instanceof HTMLInputElement)||"checkbox"!==e.type)return;if(e.getAttribute("aria-controls")&&this.syncConditionalRevealWithInputState(e),!e.checked)return;"exclusive"===e.getAttribute("data-behaviour")?this.unCheckAllInputsExcept(e):this.unCheckExclusiveInputs(e)}}w.moduleName="govuk-checkboxes";
|
|
28
28
|
/**
|
|
29
29
|
* Error summary component
|
|
30
30
|
*
|
|
@@ -34,24 +34,24 @@ class w extends u{constructor(e){super(e),this.$inputs=void 0;const t=this.$root
|
|
|
34
34
|
* @preserve
|
|
35
35
|
* @augments ConfigurableComponent<ErrorSummaryConfig>
|
|
36
36
|
*/
|
|
37
|
-
class
|
|
37
|
+
class $ extends d{constructor(t,e={}){super(t,e),this.config.disableAutoFocus||function(t,e={}){var n;const i=t.getAttribute("tabindex");function s(){var n;null==(n=e.onBlur)||n.call(t),i||t.removeAttribute("tabindex")}i||t.setAttribute("tabindex","-1"),t.addEventListener("focus",function(){t.addEventListener("blur",s,{once:!0})},{once:!0}),null==(n=e.onBeforeFocus)||n.call(t),t.focus()}(this.$root),this.$root.addEventListener("click",t=>this.handleClick(t))}handleClick(t){const e=t.target;e&&this.focusTarget(e)&&t.preventDefault()}focusTarget(t){if(!(t instanceof HTMLAnchorElement))return!1;const e=t.hash.replace("#","");if(!e)return!1;const n=document.getElementById(e);if(!n)return!1;const i=this.getAssociatedLegendOrLabel(n);return!!i&&(i.scrollIntoView(),n.focus({preventScroll:!0}),!0)}getAssociatedLegendOrLabel(t){var e;const n=t.closest("fieldset");if(n){const e=n.getElementsByTagName("legend");if(e.length){const n=e[0];if(t instanceof HTMLInputElement&&("checkbox"===t.type||"radio"===t.type))return n;const i=n.getBoundingClientRect().top,s=t.getBoundingClientRect();if(s.height&&window.innerHeight){if(s.top+s.height-i<window.innerHeight/2)return n}}}return null!=(e=document.querySelector(`label[for='${t.getAttribute("id")}']`))?e:t.closest("label")}}$.moduleName="govuk-error-summary",$.defaults=Object.freeze({disableAutoFocus:!1}),$.schema=Object.freeze({properties:{disableAutoFocus:{type:"boolean"}}});
|
|
38
38
|
/**
|
|
39
39
|
* File upload component
|
|
40
40
|
*
|
|
41
41
|
* @preserve
|
|
42
42
|
* @augments ConfigurableComponent<FileUploadConfig>
|
|
43
43
|
*/
|
|
44
|
-
class
|
|
44
|
+
class y extends d{constructor(t,e={}){super(t,e),this.$input=void 0,this.$button=void 0,this.$status=void 0,this.i18n=void 0,this.id=void 0,this.$announcements=void 0,this.enteredAnotherElement=void 0;const n=this.$root.querySelector("input");if(null===n)throw new a({component:y,identifier:'File inputs (`<input type="file">`)'});if("file"!==n.type)throw new a(i(y,'File input (`<input type="file">`) attribute (`type`) is not `file`'));if(this.$input=n,!this.$input.id)throw new a({component:y,identifier:'File input (`<input type="file">`) attribute (`id`)'});this.id=this.$input.id,this.i18n=new g(this.config.i18n,{locale:v(this.$root,"lang")});const s=this.findLabel();s.id||(s.id=`${this.id}-label`),this.$input.id=`${this.id}-input`,this.$input.setAttribute("hidden","true");const o=document.createElement("button");o.classList.add("govuk-file-upload-button"),o.type="button",o.id=this.id,o.classList.add("govuk-file-upload-button--empty");const r=this.$input.getAttribute("aria-describedby");r&&o.setAttribute("aria-describedby",r);const u=document.createElement("span");u.className="govuk-body govuk-file-upload-button__status",u.setAttribute("aria-live","polite"),u.innerText=this.i18n.t("noFileChosen"),o.appendChild(u);const l=document.createElement("span");l.className="govuk-visually-hidden",l.innerText=", ",l.id=`${this.id}-comma`,o.appendChild(l);const c=document.createElement("span");c.className="govuk-file-upload-button__pseudo-button-container";const d=document.createElement("span");d.className="govuk-button govuk-button--secondary govuk-file-upload-button__pseudo-button",d.innerText=this.i18n.t("chooseFilesButton"),c.appendChild(d),c.insertAdjacentText("beforeend"," ");const h=document.createElement("span");h.className="govuk-body govuk-file-upload-button__instruction",h.innerText=this.i18n.t("dropInstruction"),c.appendChild(h),o.appendChild(c),o.setAttribute("aria-labelledby",`${s.id} ${l.id} ${o.id}`),o.addEventListener("click",this.onClick.bind(this)),o.addEventListener("dragover",t=>{t.preventDefault()}),this.$root.insertAdjacentElement("afterbegin",o),this.$input.setAttribute("tabindex","-1"),this.$input.setAttribute("aria-hidden","true"),this.$button=o,this.$status=u,this.$input.addEventListener("change",this.onChange.bind(this)),this.updateDisabledState(),this.observeDisabledState(),this.$announcements=document.createElement("span"),this.$announcements.classList.add("govuk-file-upload-announcements"),this.$announcements.classList.add("govuk-visually-hidden"),this.$announcements.setAttribute("aria-live","assertive"),this.$root.insertAdjacentElement("afterend",this.$announcements),this.$button.addEventListener("drop",this.onDrop.bind(this)),document.addEventListener("dragenter",this.updateDropzoneVisibility.bind(this)),document.addEventListener("dragenter",()=>{this.enteredAnotherElement=!0}),document.addEventListener("dragleave",()=>{this.enteredAnotherElement||this.$button.disabled||(this.hideDraggingState(),this.$announcements.innerText=this.i18n.t("leftDropZone")),this.enteredAnotherElement=!1})}updateDropzoneVisibility(t){this.$button.disabled||t.target instanceof Node&&(this.$root.contains(t.target)?t.dataTransfer&&this.canDrop(t.dataTransfer)&&(this.$button.classList.contains("govuk-file-upload-button--dragging")||(this.showDraggingState(),this.$announcements.innerText=this.i18n.t("enteredDropZone"))):this.$button.classList.contains("govuk-file-upload-button--dragging")&&(this.hideDraggingState(),this.$announcements.innerText=this.i18n.t("leftDropZone")))}showDraggingState(){this.$button.classList.add("govuk-file-upload-button--dragging")}hideDraggingState(){this.$button.classList.remove("govuk-file-upload-button--dragging")}onDrop(t){t.preventDefault(),t.dataTransfer&&this.canFillInput(t.dataTransfer)&&(this.$input.files=t.dataTransfer.files,this.$input.dispatchEvent(new CustomEvent("change")),this.hideDraggingState())}canFillInput(t){return this.matchesInputCapacity(t.files.length)}canDrop(t){return t.items.length?this.matchesInputCapacity(function(t){let e=0;for(let n=0;n<t.length;n++)"file"===t[n].kind&&e++;return e}
|
|
45
45
|
/**
|
|
46
46
|
* Password input component
|
|
47
47
|
*
|
|
48
48
|
* @preserve
|
|
49
49
|
* @augments ConfigurableComponent<PasswordInputConfig>
|
|
50
|
-
|
|
50
|
+
*/(t.items)):!t.types.length||t.types.includes("Files")}matchesInputCapacity(t){return this.$input.multiple?t>0:1===t}onChange(){const t=this.$input.files.length;0===t?(this.$status.innerText=this.i18n.t("noFileChosen"),this.$button.classList.add("govuk-file-upload-button--empty")):(this.$status.innerText=1===t?this.$input.files[0].name:this.i18n.t("multipleFilesChosen",{count:t}),this.$button.classList.remove("govuk-file-upload-button--empty"))}findLabel(){const t=document.querySelector(`label[for="${this.$input.id}"]`);if(!t)throw new a({component:y,identifier:`Field label (\`<label for=${this.$input.id}>\`)`});return t}onClick(){this.$input.click()}observeDisabledState(){new MutationObserver(t=>{for(const e of t)"attributes"===e.type&&"disabled"===e.attributeName&&this.updateDisabledState()}).observe(this.$input,{attributes:!0})}updateDisabledState(){this.$button.disabled=this.$input.disabled,this.$root.classList.toggle("govuk-drop-zone--disabled",this.$button.disabled)}}y.moduleName="govuk-file-upload",y.defaults=Object.freeze({i18n:{chooseFilesButton:"Choose file",dropInstruction:"or drop file",noFileChosen:"No file chosen",multipleFilesChosen:{one:"%{count} file chosen",other:"%{count} files chosen"},enteredDropZone:"Entered drop zone",leftDropZone:"Left drop zone"}}),y.schema=Object.freeze({properties:{i18n:{type:"object"}}});class x extends d{constructor(t,e={}){super(t,e),this.i18n=void 0,this.$input=void 0,this.$showHideButton=void 0,this.$screenReaderStatusMessage=void 0;const n=this.$root.querySelector(".govuk-js-password-input-input");if(!(n instanceof HTMLInputElement))throw new a({component:x,element:n,expectedType:"HTMLInputElement",identifier:"Form field (`.govuk-js-password-input-input`)"});if("password"!==n.type)throw new a("Password input: Form field (`.govuk-js-password-input-input`) must be of type `password`.");const i=this.$root.querySelector(".govuk-js-password-input-toggle");if(!(i instanceof HTMLButtonElement))throw new a({component:x,element:i,expectedType:"HTMLButtonElement",identifier:"Button (`.govuk-js-password-input-toggle`)"});if("button"!==i.type)throw new a("Password input: Button (`.govuk-js-password-input-toggle`) must be of type `button`.");this.$input=n,this.$showHideButton=i,this.i18n=new g(this.config.i18n,{locale:v(this.$root,"lang")}),this.$showHideButton.removeAttribute("hidden");const s=document.createElement("div");s.className="govuk-password-input__sr-status govuk-visually-hidden",s.setAttribute("aria-live","polite"),this.$screenReaderStatusMessage=s,this.$input.insertAdjacentElement("afterend",s),this.$showHideButton.addEventListener("click",this.toggle.bind(this)),this.$input.form&&this.$input.form.addEventListener("submit",()=>this.hide()),window.addEventListener("pageshow",t=>{t.persisted&&"password"!==this.$input.type&&this.hide()}),this.hide()}toggle(t){t.preventDefault(),"password"!==this.$input.type?this.hide():this.show()}show(){this.setType("text")}hide(){this.setType("password")}setType(t){if(t===this.$input.type)return;this.$input.setAttribute("type",t);const e="password"===t,n=e?"show":"hide",i=e?"passwordHidden":"passwordShown";this.$showHideButton.innerText=this.i18n.t(`${n}Password`),this.$showHideButton.setAttribute("aria-label",this.i18n.t(`${n}PasswordAriaLabel`)),this.$screenReaderStatusMessage.innerText=this.i18n.t(`${i}Announcement`)}}x.moduleName="govuk-password-input",x.defaults=Object.freeze({i18n:{showPassword:"Show",hidePassword:"Hide",showPasswordAriaLabel:"Show password",hidePasswordAriaLabel:"Hide password",passwordShownAnnouncement:"Your password is visible",passwordHiddenAnnouncement:"Your password is hidden"}}),x.schema=Object.freeze({properties:{i18n:{type:"object"}}});
|
|
51
51
|
/**
|
|
52
52
|
* Radios component
|
|
53
53
|
*
|
|
54
54
|
* @preserve
|
|
55
55
|
*/
|
|
56
|
-
class
|
|
56
|
+
class k extends l{constructor(t){super(t),this.$inputs=void 0;const e=this.$root.querySelectorAll('input[type="radio"]');if(!e.length)throw new a({component:k,identifier:'Form inputs (`<input type="radio">`)'});this.$inputs=e,this.$inputs.forEach(t=>{const e=t.getAttribute("data-aria-controls");if(e){if(!document.getElementById(e))throw new a({component:k,identifier:`Conditional reveal (\`id="${e}"\`)`});t.setAttribute("aria-controls",e),t.removeAttribute("data-aria-controls")}}),window.addEventListener("pageshow",()=>this.syncAllConditionalReveals()),this.syncAllConditionalReveals(),this.$root.addEventListener("click",t=>this.handleClick(t))}syncAllConditionalReveals(){this.$inputs.forEach(t=>this.syncConditionalRevealWithInputState(t))}syncConditionalRevealWithInputState(t){const e=t.getAttribute("aria-controls");if(!e)return;const n=document.getElementById(e);if(null!=n&&n.classList.contains("govuk-radios__conditional")){const e=t.checked;t.setAttribute("aria-expanded",e.toString()),n.classList.toggle("govuk-radios__conditional--hidden",!e)}}handleClick(t){const e=t.target;if(!(e instanceof HTMLInputElement)||"radio"!==e.type)return;const n=document.querySelectorAll('input[type="radio"][aria-controls]'),i=e.form,s=e.name;n.forEach(t=>{const e=t.form===i;t.name===s&&e&&this.syncConditionalRevealWithInputState(t)})}}k.moduleName="govuk-radios";class C extends t{static targets=["preview","destroy"];static values={mimeTypes:Array};connect(){this.counter=0,this.initialPreviewContent=null,this.onUploadFlag=!1}onUpload(t){this.onUploadFlag=!0,this.hasDestroyTarget&&(this.destroyTarget.value=!1),this.previewTarget.removeAttribute("hidden"),this.hasPreviewTarget&&(t.currentTarget.files.length>0?this.showPreview(t.currentTarget.files[0]):this.setPreviewContent(this.initialPreviewContent))}setDestroy(t){t.preventDefault(),this.initialPreviewContent&&this.onUploadFlag?(this.onUploadFlag=!1,this.setPreviewContent(this.initialPreviewContent)):(this.hasDestroyTarget&&(this.destroyTarget.value=!0),this.hasPreviewTarget&&(this.previewTarget.setAttribute("hidden",""),this.setPreviewContent("")),this.previousInput&&this.previousInput.toggleAttribute("disabled",!0)),this.fileInput.value=""}setPreviewContent(t){this.filenameTag&&(this.filenameTag.innerText=text)}drop(t){t.preventDefault();const e=this.fileForEvent(t,this.mimeTypesValue);if(e){const t=new DataTransfer;t.items.add(e),this.fileInput.files=t.files,this.fileInput.dispatchEvent(new Event("change"))}this.counter=0,this.element.classList.remove("droppable")}dragover(t){t.preventDefault()}dragenter(t){t.preventDefault(),0===this.counter&&this.element.classList.add("droppable"),this.counter++}dragleave(t){t.preventDefault(),this.counter--,0===this.counter&&this.element.classList.remove("droppable")}get fileInput(){return this.element.querySelector("input[type='file']")}get previousInput(){return this.element.querySelector(`input[type='hidden'][name='${this.fileInput.name}']`)}get filenameTag(){return this.hasPreviewTarget?this.previewTarget.querySelector("p.preview-filename"):null}showPreview(t){const e=new FileReader;e.onload=e=>{this.filenameTag&&(this.filenameTag.innerText=t.name)},e.readAsDataURL(t)}fileForEvent(t,e){const n=t=>e.indexOf(t.type)>-1;let i;if(t.dataTransfer.items){const e=[...t.dataTransfer.items].find(n);e&&(i=e.getAsFile())}else i=[...t.dataTransfer.files].find(n);return i}}const E=[{identifier:"govuk-document-field",controllerConstructor:class extends C{connect(){super.connect(),this.initialPreviewContent=this.filenameTag.text}setPreviewContent(t){this.filenameTag.innerText=t}showPreview(t){const e=new FileReader;e.onload=e=>{this.filenameTag&&(this.filenameTag.innerText=t.name)},e.readAsDataURL(t)}get filenameTag(){return this.previewTarget.querySelector("p.preview-filename")}}},{identifier:"govuk-image-field",controllerConstructor:class extends C{connect(){super.connect(),this.initialPreviewContent=this.imageTag.getAttribute("src")}setPreviewContent(t){this.imageTag.src=t}showPreview(t){const e=new FileReader;e.onload=t=>{this.imageTag.src=t.target.result},e.readAsDataURL(t)}get imageTag(){return this.previewTarget.querySelector("img")}}}];function T(t){let n;if(t=void 0!==t?t:{},!e())return void console.log(new o);const i=[[f,t.button],[b,t.characterCount],[w],[$,t.errorSummary],[y,t.fileUpload],[k],[x,t.passwordInput]],s=null!=(n=t.scope)?n:document;i.forEach(([t,e])=>{s.querySelectorAll(`[data-module="${t.moduleName}"]`).forEach(n=>{try{"defaults"in t?new t(n,e):new t(n)}catch(t){console.log(t)}})})}export{f as Button,b as CharacterCount,w as Checkboxes,$ as ErrorSummary,x as PasswordInput,k as Radios,E as default,T as initAll};
|
|
57
57
|
//# sourceMappingURL=formbuilder.min.js.map
|