@defra/forms-engine-plugin 0.1.24 → 0.1.26

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 (41) hide show
  1. package/.public/assets-manifest.json +3 -2
  2. package/.public/javascripts/application.min.js +1 -1
  3. package/.public/javascripts/application.min.js.map +1 -1
  4. package/.public/javascripts/shared.min.js +3 -0
  5. package/.public/javascripts/shared.min.js.LICENSE.txt +58 -0
  6. package/.public/javascripts/shared.min.js.map +1 -0
  7. package/.server/client/javascripts/application.js +2 -67
  8. package/.server/client/javascripts/application.js.map +1 -1
  9. package/.server/client/javascripts/autocomplete.d.ts +1 -0
  10. package/.server/client/javascripts/autocomplete.js +49 -0
  11. package/.server/client/javascripts/autocomplete.js.map +1 -0
  12. package/.server/client/javascripts/file-upload.js +8 -1
  13. package/.server/client/javascripts/file-upload.js.map +1 -1
  14. package/.server/client/javascripts/govuk.d.ts +1 -0
  15. package/.server/client/javascripts/govuk.js +12 -0
  16. package/.server/client/javascripts/govuk.js.map +1 -0
  17. package/.server/client/javascripts/preview-close-link.d.ts +1 -0
  18. package/.server/client/javascripts/preview-close-link.js +12 -0
  19. package/.server/client/javascripts/preview-close-link.js.map +1 -0
  20. package/.server/client/javascripts/shared.d.ts +9 -0
  21. package/.server/client/javascripts/shared.js +15 -0
  22. package/.server/client/javascripts/shared.js.map +1 -0
  23. package/.server/server/plugins/engine/components/index.d.ts +2 -2
  24. package/.server/server/plugins/engine/components/index.js +2 -2
  25. package/.server/server/plugins/engine/components/index.js.map +1 -1
  26. package/.server/server/plugins/engine/index.d.ts +0 -1
  27. package/.server/server/plugins/engine/index.js +0 -1
  28. package/.server/server/plugins/engine/index.js.map +1 -1
  29. package/.server/server/plugins/engine/views/file-upload.html +0 -13
  30. package/package.json +4 -8
  31. package/src/client/javascripts/application.js +2 -86
  32. package/src/client/javascripts/autocomplete.js +57 -0
  33. package/src/client/javascripts/file-upload.js +9 -1
  34. package/src/client/javascripts/govuk.js +22 -0
  35. package/src/client/javascripts/preview-close-link.js +12 -0
  36. package/src/client/javascripts/shared.js +16 -0
  37. package/src/server/plugins/engine/components/index.ts +2 -2
  38. package/src/server/plugins/engine/index.ts +0 -1
  39. package/src/server/plugins/engine/views/file-upload.html +0 -13
  40. package/.public/javascripts/file-upload.min.js +0 -2
  41. package/.public/javascripts/file-upload.min.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","names":["Button","CharacterCount","Checkboxes","ErrorSummary","Header","NotificationBanner","Radios","SkipLink","createAll","window","opener","$closeLink","document","querySelector","removeAttribute","addEventListener","event","preventDefault","close","initAutocomplete","$select","init","config","id","selectElement","$input","inputValues","options","map","option","text","value","includes","$autocompletes","querySelectorAll","length","then","component","default","accessibleAutocomplete","forEach","$module","enhanceSelectElement","catch","console","error"],"sources":["../../../src/client/javascripts/application.js"],"sourcesContent":["import {\n Button,\n CharacterCount,\n Checkboxes,\n ErrorSummary,\n Header,\n NotificationBanner,\n Radios,\n SkipLink,\n createAll\n} from 'govuk-frontend'\n\ncreateAll(Button)\ncreateAll(CharacterCount)\ncreateAll(Checkboxes)\ncreateAll(ErrorSummary)\ncreateAll(Header)\ncreateAll(NotificationBanner)\ncreateAll(Radios)\ncreateAll(SkipLink)\n\n// Show preview close link via `rel=\"opener\"`\nif (window.opener) {\n const $closeLink = document.querySelector('.js-preview-banner-close')\n\n $closeLink?.removeAttribute('hidden')\n $closeLink?.addEventListener('click', (event) => {\n event.preventDefault()\n window.close()\n })\n}\n\n/**\n * Initialise autocomplete\n * @param {HTMLSelectElement | null} $select\n * @param {(config: object) => void} init\n */\nfunction initAutocomplete($select, init) {\n if (!$select) {\n return\n }\n\n const config = {\n id: $select.id,\n selectElement: $select\n }\n\n init(config)\n\n /** @type {HTMLInputElement | null} */\n const $input = document.querySelector(`#${config.id}`)\n\n // Allowed values for input\n const inputValues = [...$select.options].map((option) => option.text)\n\n // Reset select when input value is not allowed\n $input?.addEventListener('blur', () => {\n if (!$input.value || !inputValues.includes($input.value)) {\n $select.value = ''\n }\n })\n}\n\n// Find all autocompletes\nconst $autocompletes = document.querySelectorAll(\n `[data-module=\"govuk-accessible-autocomplete\"]`\n)\n\n// Lazy load autocomplete component\nif ($autocompletes.length) {\n // @ts-expect-error -- No types available\n import('accessible-autocomplete')\n .then((component) => {\n const { default: accessibleAutocomplete } = component\n\n // Initialise each autocomplete\n $autocompletes.forEach(($module) =>\n initAutocomplete(\n $module.querySelector('select'),\n accessibleAutocomplete.enhanceSelectElement\n )\n )\n })\n\n // eslint-disable-next-line no-console\n .catch(console.error)\n}\n"],"mappings":"AAAA,SACEA,MAAM,EACNC,cAAc,EACdC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,kBAAkB,EAClBC,MAAM,EACNC,QAAQ,EACRC,SAAS,QACJ,gBAAgB;AAEvBA,SAAS,CAACR,MAAM,CAAC;AACjBQ,SAAS,CAACP,cAAc,CAAC;AACzBO,SAAS,CAACN,UAAU,CAAC;AACrBM,SAAS,CAACL,YAAY,CAAC;AACvBK,SAAS,CAACJ,MAAM,CAAC;AACjBI,SAAS,CAACH,kBAAkB,CAAC;AAC7BG,SAAS,CAACF,MAAM,CAAC;AACjBE,SAAS,CAACD,QAAQ,CAAC;;AAEnB;AACA,IAAIE,MAAM,CAACC,MAAM,EAAE;EACjB,MAAMC,UAAU,GAAGC,QAAQ,CAACC,aAAa,CAAC,0BAA0B,CAAC;EAErEF,UAAU,EAAEG,eAAe,CAAC,QAAQ,CAAC;EACrCH,UAAU,EAAEI,gBAAgB,CAAC,OAAO,EAAGC,KAAK,IAAK;IAC/CA,KAAK,CAACC,cAAc,CAAC,CAAC;IACtBR,MAAM,CAACS,KAAK,CAAC,CAAC;EAChB,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CAACC,OAAO,EAAEC,IAAI,EAAE;EACvC,IAAI,CAACD,OAAO,EAAE;IACZ;EACF;EAEA,MAAME,MAAM,GAAG;IACbC,EAAE,EAAEH,OAAO,CAACG,EAAE;IACdC,aAAa,EAAEJ;EACjB,CAAC;EAEDC,IAAI,CAACC,MAAM,CAAC;;EAEZ;EACA,MAAMG,MAAM,GAAGb,QAAQ,CAACC,aAAa,CAAC,IAAIS,MAAM,CAACC,EAAE,EAAE,CAAC;;EAEtD;EACA,MAAMG,WAAW,GAAG,CAAC,GAAGN,OAAO,CAACO,OAAO,CAAC,CAACC,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,CAAC;;EAErE;EACAL,MAAM,EAAEV,gBAAgB,CAAC,MAAM,EAAE,MAAM;IACrC,IAAI,CAACU,MAAM,CAACM,KAAK,IAAI,CAACL,WAAW,CAACM,QAAQ,CAACP,MAAM,CAACM,KAAK,CAAC,EAAE;MACxDX,OAAO,CAACW,KAAK,GAAG,EAAE;IACpB;EACF,CAAC,CAAC;AACJ;;AAEA;AACA,MAAME,cAAc,GAAGrB,QAAQ,CAACsB,gBAAgB,CAC9C,+CACF,CAAC;;AAED;AACA,IAAID,cAAc,CAACE,MAAM,EAAE;EACzB;EACA,MAAM,CAAC,yBAAyB,CAAC,CAC9BC,IAAI,CAAEC,SAAS,IAAK;IACnB,MAAM;MAAEC,OAAO,EAAEC;IAAuB,CAAC,GAAGF,SAAS;;IAErD;IACAJ,cAAc,CAACO,OAAO,CAAEC,OAAO,IAC7BtB,gBAAgB,CACdsB,OAAO,CAAC5B,aAAa,CAAC,QAAQ,CAAC,EAC/B0B,sBAAsB,CAACG,oBACzB,CACF,CAAC;EACH,CAAC;;EAED;EAAA,CACCC,KAAK,CAACC,OAAO,CAACC,KAAK,CAAC;AACzB","ignoreList":[]}
1
+ {"version":3,"file":"application.js","names":["initAll"],"sources":["../../../src/client/javascripts/application.js"],"sourcesContent":["import { initAll } from '~/src/client/javascripts/shared.js'\n\ninitAll()\n"],"mappings":"AAAA,SAASA,OAAO;AAEhBA,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export function initAllAutocomplete(): void;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Initialise autocomplete
3
+ * @param {HTMLSelectElement | null} $select
4
+ * @param {(config: object) => void} init
5
+ */
6
+ function initAutocomplete($select, init) {
7
+ if (!$select) {
8
+ return;
9
+ }
10
+ const config = {
11
+ id: $select.id,
12
+ selectElement: $select
13
+ };
14
+ init(config);
15
+
16
+ /** @type {HTMLInputElement | null} */
17
+ const $input = document.querySelector(`#${config.id}`);
18
+
19
+ // Allowed values for input
20
+ const inputValues = [...$select.options].map(option => option.text);
21
+
22
+ // Reset select when input value is not allowed
23
+ $input?.addEventListener('blur', () => {
24
+ if (!$input.value || !inputValues.includes($input.value)) {
25
+ $select.value = '';
26
+ }
27
+ });
28
+ }
29
+ export function initAllAutocomplete() {
30
+ // Find all autocompletes
31
+ const $autocompletes = document.querySelectorAll(`[data-module="govuk-accessible-autocomplete"]`);
32
+
33
+ // Lazy load autocomplete component
34
+ if ($autocompletes.length) {
35
+ // @ts-expect-error -- No types available
36
+ import('accessible-autocomplete').then(component => {
37
+ const {
38
+ default: accessibleAutocomplete
39
+ } = component;
40
+
41
+ // Initialise each autocomplete
42
+ $autocompletes.forEach($module => initAutocomplete($module.querySelector('select'), accessibleAutocomplete.enhanceSelectElement));
43
+ })
44
+
45
+ // eslint-disable-next-line no-console
46
+ .catch(console.error);
47
+ }
48
+ }
49
+ //# sourceMappingURL=autocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autocomplete.js","names":["initAutocomplete","$select","init","config","id","selectElement","$input","document","querySelector","inputValues","options","map","option","text","addEventListener","value","includes","initAllAutocomplete","$autocompletes","querySelectorAll","length","then","component","default","accessibleAutocomplete","forEach","$module","enhanceSelectElement","catch","console","error"],"sources":["../../../src/client/javascripts/autocomplete.js"],"sourcesContent":["/**\n * Initialise autocomplete\n * @param {HTMLSelectElement | null} $select\n * @param {(config: object) => void} init\n */\nfunction initAutocomplete($select, init) {\n if (!$select) {\n return\n }\n\n const config = {\n id: $select.id,\n selectElement: $select\n }\n\n init(config)\n\n /** @type {HTMLInputElement | null} */\n const $input = document.querySelector(`#${config.id}`)\n\n // Allowed values for input\n const inputValues = [...$select.options].map((option) => option.text)\n\n // Reset select when input value is not allowed\n $input?.addEventListener('blur', () => {\n if (!$input.value || !inputValues.includes($input.value)) {\n $select.value = ''\n }\n })\n}\n\nexport function initAllAutocomplete() {\n // Find all autocompletes\n const $autocompletes = document.querySelectorAll(\n `[data-module=\"govuk-accessible-autocomplete\"]`\n )\n\n // Lazy load autocomplete component\n if ($autocompletes.length) {\n // @ts-expect-error -- No types available\n import('accessible-autocomplete')\n .then((component) => {\n const { default: accessibleAutocomplete } = component\n\n // Initialise each autocomplete\n $autocompletes.forEach(($module) =>\n initAutocomplete(\n $module.querySelector('select'),\n accessibleAutocomplete.enhanceSelectElement\n )\n )\n })\n\n // eslint-disable-next-line no-console\n .catch(console.error)\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAgBA,CAACC,OAAO,EAAEC,IAAI,EAAE;EACvC,IAAI,CAACD,OAAO,EAAE;IACZ;EACF;EAEA,MAAME,MAAM,GAAG;IACbC,EAAE,EAAEH,OAAO,CAACG,EAAE;IACdC,aAAa,EAAEJ;EACjB,CAAC;EAEDC,IAAI,CAACC,MAAM,CAAC;;EAEZ;EACA,MAAMG,MAAM,GAAGC,QAAQ,CAACC,aAAa,CAAC,IAAIL,MAAM,CAACC,EAAE,EAAE,CAAC;;EAEtD;EACA,MAAMK,WAAW,GAAG,CAAC,GAAGR,OAAO,CAACS,OAAO,CAAC,CAACC,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,CAAC;;EAErE;EACAP,MAAM,EAAEQ,gBAAgB,CAAC,MAAM,EAAE,MAAM;IACrC,IAAI,CAACR,MAAM,CAACS,KAAK,IAAI,CAACN,WAAW,CAACO,QAAQ,CAACV,MAAM,CAACS,KAAK,CAAC,EAAE;MACxDd,OAAO,CAACc,KAAK,GAAG,EAAE;IACpB;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,SAASE,mBAAmBA,CAAA,EAAG;EACpC;EACA,MAAMC,cAAc,GAAGX,QAAQ,CAACY,gBAAgB,CAC9C,+CACF,CAAC;;EAED;EACA,IAAID,cAAc,CAACE,MAAM,EAAE;IACzB;IACA,MAAM,CAAC,yBAAyB,CAAC,CAC9BC,IAAI,CAAEC,SAAS,IAAK;MACnB,MAAM;QAAEC,OAAO,EAAEC;MAAuB,CAAC,GAAGF,SAAS;;MAErD;MACAJ,cAAc,CAACO,OAAO,CAAEC,OAAO,IAC7B1B,gBAAgB,CACd0B,OAAO,CAAClB,aAAa,CAAC,QAAQ,CAAC,EAC/BgB,sBAAsB,CAACG,oBACzB,CACF,CAAC;IACH,CAAC;;IAED;IAAA,CACCC,KAAK,CAACC,OAAO,CAACC,KAAK,CAAC;EACzB;AACF","ignoreList":[]}
@@ -291,7 +291,7 @@ function handleAjaxFormSubmission(event, formElement, fileInput, uploadButton, e
291
291
  });
292
292
  return true;
293
293
  }
294
- export function initFileUpload() {
294
+ function initUpload() {
295
295
  const form = document.querySelector('form:has(input[type="file"])');
296
296
  /** @type {HTMLInputElement | null} */
297
297
  const fileInput = form ? form.querySelector('input[type="file"]') : null;
@@ -330,4 +330,11 @@ export function initFileUpload() {
330
330
  handleAjaxFormSubmission(event, formElement, fileInput, uploadButton, /** @type {HTMLElement | null} */errorSummary, uploadId);
331
331
  });
332
332
  }
333
+ export function initFileUpload() {
334
+ if (document.readyState === 'loading') {
335
+ document.addEventListener('DOMContentLoaded', initUpload);
336
+ } else {
337
+ initUpload();
338
+ }
339
+ }
333
340
  //# sourceMappingURL=file-upload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-upload.js","names":["MAX_POLLING_DURATION","ARIA_DESCRIBEDBY","ERROR_SUMMARY_TITLE_ID","createOrUpdateStatusAnnouncer","form","fileCountP","statusAnnouncer","querySelector","document","createElement","id","className","setAttribute","addStatusAnnouncerToDOM","asHTMLElement","appendChild","body","nextSibling","parentNode","insertBefore","parentElement","findOrCreateSummaryList","summaryList","continueButton","createFileRow","selectedFile","statusText","row","name","innerHTML","renderSummary","container","getElementById","uploadForm","closest","HTMLFormElement","fileInput","existingRow","remove","firstChild","textContent","showError","message","errorSummary","topErrorSummary","titleElement","removeAttribute","formGroup","classList","add","inputId","errorMessage","element","reloadPage","window","history","replaceState","location","href","pathname","buildUploadStatusUrl","uploadId","pathSegments","split","filter","segment","prefix","length","pollUploadStatus","attempts","interval","setInterval","clearInterval","uploadStatusUrl","fetch","headers","Accept","then","response","ok","Error","json","data","uploadStatus","catch","handleStandardFormSubmission","formElement","uploadButton","focus","setTimeout","disabled","handleAjaxFormSubmission","event","action","preventDefault","formData","FormData","isLocalDev","dataset","proxyUrl","uploadUrl","fetchOptions","method","redirect","mode","initFileUpload","Array","from","querySelectorAll","find","button","trim","isSubmitting","addEventListener","files"],"sources":["../../../src/client/javascripts/file-upload.js"],"sourcesContent":["export const MAX_POLLING_DURATION = 300 // 5 minutes\nconst ARIA_DESCRIBEDBY = 'aria-describedby'\nconst ERROR_SUMMARY_TITLE_ID = 'error-summary-title'\n\n/**\n * Creates or updates status announcer for screen readers\n * @param {HTMLElement | null} form - The form element\n * @param {HTMLElement | null} fileCountP - The file count paragraph element\n * @returns {HTMLElement} The status announcer element\n */\nfunction createOrUpdateStatusAnnouncer(form, fileCountP) {\n let statusAnnouncer = form?.querySelector('#statusInformation')\n\n if (!statusAnnouncer) {\n statusAnnouncer = document.createElement('div')\n statusAnnouncer.id = 'statusInformation'\n statusAnnouncer.className = 'govuk-visually-hidden'\n statusAnnouncer.setAttribute('aria-live', 'polite')\n\n // multiple fallbacks to ensure the status announcer is always added to the DOM\n // this helps with cross-browser compatibility and unexpected DOM structures encountered during QA\n try {\n addStatusAnnouncerToDOM(\n asHTMLElement(form),\n asHTMLElement(fileCountP),\n asHTMLElement(statusAnnouncer)\n )\n } catch {\n try {\n form?.appendChild(statusAnnouncer)\n } catch {\n document.body.appendChild(statusAnnouncer)\n }\n }\n }\n\n return /** @type {HTMLElement} */ (statusAnnouncer)\n}\n\n/**\n * Helper function to add the status announcer to the DOM\n * @param {HTMLElement} form - The form element\n * @param {HTMLElement | null} fileCountP - The file count paragraph element\n * @param {HTMLElement} statusAnnouncer - The status announcer element to add\n */\nfunction addStatusAnnouncerToDOM(form, fileCountP, statusAnnouncer) {\n if (fileCountP?.nextSibling && fileCountP.parentNode === form) {\n form.insertBefore(statusAnnouncer, fileCountP.nextSibling)\n return\n }\n\n const parentElement = fileCountP?.parentNode ?? form\n parentElement.appendChild(statusAnnouncer)\n}\n\n/**\n * Finds an existing summary list or creates a new one\n * @param {HTMLFormElement} form - The form element\n * @param {HTMLElement} fileCountP - The file count paragraph element\n * @returns {HTMLElement} The summary list element\n */\nfunction findOrCreateSummaryList(form, fileCountP) {\n let summaryList = form.querySelector('dl.govuk-summary-list')\n\n if (!summaryList) {\n summaryList = document.createElement('dl')\n summaryList.className = 'govuk-summary-list govuk-summary-list--long-key'\n\n const continueButton = form.querySelector('.govuk-button')\n\n if (continueButton) {\n form.insertBefore(summaryList, continueButton)\n } else {\n form.insertBefore(summaryList, fileCountP.nextSibling)\n }\n }\n\n return /** @type {HTMLElement} */ (summaryList)\n}\n\n/**\n * Creates a file row element for the summary list\n * @param {File | null} selectedFile - The selected file\n * @param {string} statusText - The status to display\n * @returns {HTMLElement} The created row element\n */\nfunction createFileRow(selectedFile, statusText) {\n const row = document.createElement('div')\n row.className = 'govuk-summary-list__row'\n row.setAttribute('data-filename', selectedFile?.name ?? '')\n row.innerHTML = `\n <dt class=\"govuk-summary-list__key\">\n ${selectedFile?.name ?? ''}\n </dt>\n <dd class=\"govuk-summary-list__value\">\n <strong class=\"govuk-tag govuk-tag--yellow\">${statusText}</strong>\n </dd>\n <dd class=\"govuk-summary-list__actions\">\n </dd>\n `\n return row\n}\n\n/**\n * Renders or updates the file summary box for the selected file\n * @param {File | null} selectedFile - The selected file\n * @param {string} statusText - The status to display\n * @param {HTMLElement} form - The form element\n */\nfunction renderSummary(selectedFile, statusText, form) {\n const container = document.getElementById('uploadedFilesContainer')\n const uploadForm = container ? container.closest('form') : null\n\n if (!uploadForm || !(uploadForm instanceof HTMLFormElement)) {\n return\n }\n\n const fileCountP = uploadForm.querySelector('p.govuk-body')\n\n if (!fileCountP) {\n return\n }\n\n const statusAnnouncer = createOrUpdateStatusAnnouncer(\n /** @type {HTMLElement} */ (uploadForm),\n /** @type {HTMLElement | null} */ (fileCountP)\n )\n\n const fileInput = form.querySelector('input[type=\"file\"]')\n\n if (fileInput) {\n fileInput.setAttribute(ARIA_DESCRIBEDBY, 'statusInformation')\n }\n\n const summaryList = findOrCreateSummaryList(\n /** @type {HTMLFormElement} */ (uploadForm),\n /** @type {HTMLElement} */ (fileCountP)\n )\n\n const existingRow = document.querySelector(\n `[data-filename=\"${selectedFile?.name}\"]`\n )\n\n if (existingRow) {\n existingRow.remove()\n }\n\n const row = createFileRow(selectedFile, statusText)\n summaryList.insertBefore(row, summaryList.firstChild)\n statusAnnouncer.textContent = `${selectedFile?.name ?? ''} ${statusText}`\n}\n\n/**\n * Shows an error message using the GOV.UK error summary component\n * and adds inline error styling to the file input\n * @param {string} message - The error message to display\n * @param {HTMLElement | null} errorSummary - The error summary container\n * @param {HTMLInputElement} fileInput - The file input element\n * @returns {void}\n */\nfunction showError(message, errorSummary, fileInput) {\n const topErrorSummary = document.querySelector('.govuk-error-summary')\n\n if (topErrorSummary) {\n const titleElement = document.getElementById(ERROR_SUMMARY_TITLE_ID)\n if (titleElement) {\n fileInput.setAttribute(ARIA_DESCRIBEDBY, ERROR_SUMMARY_TITLE_ID)\n } else {\n fileInput.removeAttribute(ARIA_DESCRIBEDBY)\n }\n return\n }\n\n if (errorSummary) {\n errorSummary.innerHTML = `\n <div class=\"govuk-error-summary\" data-module=\"govuk-error-summary\">\n <div role=\"alert\">\n <h2 class=\"govuk-error-summary__title\" id=\"${ERROR_SUMMARY_TITLE_ID}\">\n There is a problem\n </h2>\n <div class=\"govuk-error-summary__body\">\n <ul class=\"govuk-list govuk-error-summary__list\">\n <li>\n <a href=\"#file-upload\">${message}</a>\n </li>\n </ul>\n </div>\n </div>\n </div>\n `\n\n fileInput.setAttribute(ARIA_DESCRIBEDBY, ERROR_SUMMARY_TITLE_ID)\n }\n\n const formGroup = fileInput.closest('.govuk-form-group')\n if (formGroup) {\n formGroup.classList.add('govuk-form-group--error')\n fileInput.classList.add('govuk-file-upload--error')\n\n const inputId = fileInput.id\n let errorMessage = document.getElementById(`${inputId}-error`)\n\n if (!errorMessage) {\n errorMessage = document.createElement('p')\n errorMessage.id = `${inputId}-error`\n errorMessage.className = 'govuk-error-message'\n errorMessage.innerHTML = `<span class=\"govuk-visually-hidden\">Error:</span> ${message}`\n formGroup.insertBefore(errorMessage, fileInput)\n }\n\n fileInput.setAttribute(\n ARIA_DESCRIBEDBY,\n `error-summary-title ${inputId}-error`\n )\n }\n}\n\n/**\n * Helper to safely convert an Element to HTMLElement\n * @param {Element | null} element - The element to convert\n */\nfunction asHTMLElement(element) {\n return /** @type {HTMLElement} */ (element)\n}\n\nfunction reloadPage() {\n window.history.replaceState(null, '', window.location.href)\n window.location.href = window.location.pathname\n}\n\n/**\n * Build the upload status URL given the current pathname and the upload ID.\n * @param {string} pathname – e.g. window.location.pathname\n * @param {string} uploadId\n * @returns {string} e.g. \"/form/upload-status/abc123\"\n */\nexport function buildUploadStatusUrl(pathname, uploadId) {\n const pathSegments = pathname.split('/').filter((segment) => segment)\n const prefix = pathSegments.length > 0 ? `/${pathSegments[0]}` : ''\n return `${prefix}/upload-status/${uploadId}`\n}\n\n/**\n * Polls the upload status endpoint until the file is ready or timeout occurs\n * @param {string} uploadId - The upload ID to check\n */\nfunction pollUploadStatus(uploadId) {\n let attempts = 0\n const interval = setInterval(() => {\n attempts++\n\n if (attempts >= MAX_POLLING_DURATION) {\n clearInterval(interval)\n reloadPage()\n return\n }\n\n const uploadStatusUrl = buildUploadStatusUrl(\n window.location.pathname,\n uploadId\n )\n\n fetch(uploadStatusUrl, {\n headers: {\n Accept: 'application/json'\n }\n })\n .then((response) => {\n if (!response.ok) {\n throw new Error('Network response was not ok')\n }\n return response.json()\n })\n .then((data) => {\n if (data.uploadStatus === 'ready') {\n clearInterval(interval)\n reloadPage()\n }\n })\n .catch(() => {\n clearInterval(interval)\n reloadPage()\n })\n }, 1000)\n}\n\n/**\n * Handle standard form submission for file upload\n * @param {HTMLFormElement} formElement - The form element\n * @param {HTMLInputElement} fileInput - The file input element\n * @param {HTMLButtonElement} uploadButton - The upload button\n * @param {HTMLButtonElement} continueButton - The continue button\n * @param {File | null} selectedFile - The selected file\n */\nfunction handleStandardFormSubmission(\n formElement,\n fileInput,\n uploadButton,\n continueButton,\n selectedFile\n) {\n renderSummary(selectedFile, 'Uploading…', formElement)\n\n fileInput.focus()\n\n setTimeout(() => {\n fileInput.disabled = true\n uploadButton.disabled = true\n continueButton.disabled = true\n }, 100)\n}\n\n/**\n * Handle AJAX form submission with upload ID\n * @param {Event} event - The click event\n * @param {HTMLFormElement} formElement - The form element\n * @param {HTMLInputElement} fileInput - The file input element\n * @param {HTMLButtonElement} uploadButton - The upload button\n * @param {HTMLElement | null} errorSummary - The error summary container\n * @param {string | undefined} uploadId - The upload ID\n * @returns {boolean} Whether the event was handled\n */\nfunction handleAjaxFormSubmission(\n event,\n formElement,\n fileInput,\n uploadButton,\n errorSummary,\n uploadId\n) {\n if (!formElement.action || !uploadId) {\n return false\n }\n\n event.preventDefault()\n\n const formData = new FormData(formElement)\n const isLocalDev = !!formElement.dataset.proxyUrl\n const uploadUrl = formElement.dataset.proxyUrl ?? formElement.action\n\n const fetchOptions = /** @type {RequestInit} */ ({\n method: 'POST',\n body: formData,\n redirect: isLocalDev ? 'follow' : 'manual' // follow mode if local development with the proxy\n })\n\n // no-cors mode if needed local development with the proxy\n if (isLocalDev) {\n fetchOptions.mode = 'no-cors'\n }\n\n fetch(uploadUrl, fetchOptions)\n .then(() => {\n pollUploadStatus(uploadId)\n })\n .catch(() => {\n fileInput.disabled = false\n uploadButton.disabled = false\n\n showError(\n 'There was a problem uploading the file',\n errorSummary,\n fileInput\n )\n\n return null\n })\n\n return true\n}\n\nexport function initFileUpload() {\n const form = document.querySelector('form:has(input[type=\"file\"])')\n /** @type {HTMLInputElement | null} */\n const fileInput = form ? form.querySelector('input[type=\"file\"]') : null\n /** @type {HTMLButtonElement | null} */\n const uploadButton = form ? form.querySelector('.upload-file-button') : null\n const continueButton =\n /** @type {HTMLButtonElement} */ (\n Array.from(document.querySelectorAll('button.govuk-button')).find(\n (button) => button.textContent?.trim() === 'Continue'\n )\n ) ?? null\n\n const errorSummary = document.querySelector('.govuk-error-summary-container')\n\n if (!form || !fileInput || !uploadButton) {\n return\n }\n\n const formElement = /** @type {HTMLFormElement} */ (form)\n /** @type {File | null} */\n let selectedFile = null\n let isSubmitting = false\n const uploadId = formElement.dataset.uploadId\n\n fileInput.addEventListener('change', () => {\n if (errorSummary) {\n errorSummary.innerHTML = ''\n }\n\n if (fileInput.files && fileInput.files.length > 0) {\n selectedFile = fileInput.files[0]\n }\n })\n\n uploadButton.addEventListener('click', (event) => {\n if (!selectedFile) {\n event.preventDefault()\n showError(\n 'Select a file',\n /** @type {HTMLElement | null} */ (errorSummary),\n fileInput\n )\n return\n }\n\n if (isSubmitting) {\n event.preventDefault()\n return\n }\n\n isSubmitting = true\n\n handleStandardFormSubmission(\n formElement,\n fileInput,\n uploadButton,\n continueButton,\n selectedFile\n )\n\n handleAjaxFormSubmission(\n event,\n formElement,\n fileInput,\n uploadButton,\n /** @type {HTMLElement | null} */ (errorSummary),\n uploadId\n )\n })\n}\n"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB,GAAG,GAAG,EAAC;AACxC,MAAMC,gBAAgB,GAAG,kBAAkB;AAC3C,MAAMC,sBAAsB,GAAG,qBAAqB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,6BAA6BA,CAACC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CAAC6E,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IACzC,IAAItE,YAAY,EAAE;MAChBA,YAAY,CAACd,SAAS,GAAG,EAAE;IAC7B;IAEA,IAAIO,SAAS,CAAC8E,KAAK,IAAI9E,SAAS,CAAC8E,KAAK,CAAC/C,MAAM,GAAG,CAAC,EAAE;MACjD1C,YAAY,GAAGW,SAAS,CAAC8E,KAAK,CAAC,CAAC,CAAC;IACnC;EACF,CAAC,CAAC;EAEF3B,YAAY,CAAC0B,gBAAgB,CAAC,OAAO,EAAGrB,KAAK,IAAK;IAChD,IAAI,CAACnE,YAAY,EAAE;MACjBmE,KAAK,CAACE,cAAc,CAAC,CAAC;MACtBrD,SAAS,CACP,eAAe,EACf,iCAAmCE,YAAY,EAC/CP,SACF,CAAC;MACD;IACF;IAEA,IAAI4E,YAAY,EAAE;MAChBpB,KAAK,CAACE,cAAc,CAAC,CAAC;MACtB;IACF;IAEAkB,YAAY,GAAG,IAAI;IAEnB3B,4BAA4B,CAC1BC,WAAW,EACXlD,SAAS,EACTmD,YAAY,EACZhE,cAAc,EACdE,YACF,CAAC;IAEDkE,wBAAwB,CACtBC,KAAK,EACLN,WAAW,EACXlD,SAAS,EACTmD,YAAY,EACZ,iCAAmC5C,YAAY,EAC/CkB,QACF,CAAC;EACH,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"file-upload.js","names":["MAX_POLLING_DURATION","ARIA_DESCRIBEDBY","ERROR_SUMMARY_TITLE_ID","createOrUpdateStatusAnnouncer","form","fileCountP","statusAnnouncer","querySelector","document","createElement","id","className","setAttribute","addStatusAnnouncerToDOM","asHTMLElement","appendChild","body","nextSibling","parentNode","insertBefore","parentElement","findOrCreateSummaryList","summaryList","continueButton","createFileRow","selectedFile","statusText","row","name","innerHTML","renderSummary","container","getElementById","uploadForm","closest","HTMLFormElement","fileInput","existingRow","remove","firstChild","textContent","showError","message","errorSummary","topErrorSummary","titleElement","removeAttribute","formGroup","classList","add","inputId","errorMessage","element","reloadPage","window","history","replaceState","location","href","pathname","buildUploadStatusUrl","uploadId","pathSegments","split","filter","segment","prefix","length","pollUploadStatus","attempts","interval","setInterval","clearInterval","uploadStatusUrl","fetch","headers","Accept","then","response","ok","Error","json","data","uploadStatus","catch","handleStandardFormSubmission","formElement","uploadButton","focus","setTimeout","disabled","handleAjaxFormSubmission","event","action","preventDefault","formData","FormData","isLocalDev","dataset","proxyUrl","uploadUrl","fetchOptions","method","redirect","mode","initUpload","Array","from","querySelectorAll","find","button","trim","isSubmitting","addEventListener","files","initFileUpload","readyState"],"sources":["../../../src/client/javascripts/file-upload.js"],"sourcesContent":["export const MAX_POLLING_DURATION = 300 // 5 minutes\nconst ARIA_DESCRIBEDBY = 'aria-describedby'\nconst ERROR_SUMMARY_TITLE_ID = 'error-summary-title'\n\n/**\n * Creates or updates status announcer for screen readers\n * @param {HTMLElement | null} form - The form element\n * @param {HTMLElement | null} fileCountP - The file count paragraph element\n * @returns {HTMLElement} The status announcer element\n */\nfunction createOrUpdateStatusAnnouncer(form, fileCountP) {\n let statusAnnouncer = form?.querySelector('#statusInformation')\n\n if (!statusAnnouncer) {\n statusAnnouncer = document.createElement('div')\n statusAnnouncer.id = 'statusInformation'\n statusAnnouncer.className = 'govuk-visually-hidden'\n statusAnnouncer.setAttribute('aria-live', 'polite')\n\n // multiple fallbacks to ensure the status announcer is always added to the DOM\n // this helps with cross-browser compatibility and unexpected DOM structures encountered during QA\n try {\n addStatusAnnouncerToDOM(\n asHTMLElement(form),\n asHTMLElement(fileCountP),\n asHTMLElement(statusAnnouncer)\n )\n } catch {\n try {\n form?.appendChild(statusAnnouncer)\n } catch {\n document.body.appendChild(statusAnnouncer)\n }\n }\n }\n\n return /** @type {HTMLElement} */ (statusAnnouncer)\n}\n\n/**\n * Helper function to add the status announcer to the DOM\n * @param {HTMLElement} form - The form element\n * @param {HTMLElement | null} fileCountP - The file count paragraph element\n * @param {HTMLElement} statusAnnouncer - The status announcer element to add\n */\nfunction addStatusAnnouncerToDOM(form, fileCountP, statusAnnouncer) {\n if (fileCountP?.nextSibling && fileCountP.parentNode === form) {\n form.insertBefore(statusAnnouncer, fileCountP.nextSibling)\n return\n }\n\n const parentElement = fileCountP?.parentNode ?? form\n parentElement.appendChild(statusAnnouncer)\n}\n\n/**\n * Finds an existing summary list or creates a new one\n * @param {HTMLFormElement} form - The form element\n * @param {HTMLElement} fileCountP - The file count paragraph element\n * @returns {HTMLElement} The summary list element\n */\nfunction findOrCreateSummaryList(form, fileCountP) {\n let summaryList = form.querySelector('dl.govuk-summary-list')\n\n if (!summaryList) {\n summaryList = document.createElement('dl')\n summaryList.className = 'govuk-summary-list govuk-summary-list--long-key'\n\n const continueButton = form.querySelector('.govuk-button')\n\n if (continueButton) {\n form.insertBefore(summaryList, continueButton)\n } else {\n form.insertBefore(summaryList, fileCountP.nextSibling)\n }\n }\n\n return /** @type {HTMLElement} */ (summaryList)\n}\n\n/**\n * Creates a file row element for the summary list\n * @param {File | null} selectedFile - The selected file\n * @param {string} statusText - The status to display\n * @returns {HTMLElement} The created row element\n */\nfunction createFileRow(selectedFile, statusText) {\n const row = document.createElement('div')\n row.className = 'govuk-summary-list__row'\n row.setAttribute('data-filename', selectedFile?.name ?? '')\n row.innerHTML = `\n <dt class=\"govuk-summary-list__key\">\n ${selectedFile?.name ?? ''}\n </dt>\n <dd class=\"govuk-summary-list__value\">\n <strong class=\"govuk-tag govuk-tag--yellow\">${statusText}</strong>\n </dd>\n <dd class=\"govuk-summary-list__actions\">\n </dd>\n `\n return row\n}\n\n/**\n * Renders or updates the file summary box for the selected file\n * @param {File | null} selectedFile - The selected file\n * @param {string} statusText - The status to display\n * @param {HTMLElement} form - The form element\n */\nfunction renderSummary(selectedFile, statusText, form) {\n const container = document.getElementById('uploadedFilesContainer')\n const uploadForm = container ? container.closest('form') : null\n\n if (!uploadForm || !(uploadForm instanceof HTMLFormElement)) {\n return\n }\n\n const fileCountP = uploadForm.querySelector('p.govuk-body')\n\n if (!fileCountP) {\n return\n }\n\n const statusAnnouncer = createOrUpdateStatusAnnouncer(\n /** @type {HTMLElement} */ (uploadForm),\n /** @type {HTMLElement | null} */ (fileCountP)\n )\n\n const fileInput = form.querySelector('input[type=\"file\"]')\n\n if (fileInput) {\n fileInput.setAttribute(ARIA_DESCRIBEDBY, 'statusInformation')\n }\n\n const summaryList = findOrCreateSummaryList(\n /** @type {HTMLFormElement} */ (uploadForm),\n /** @type {HTMLElement} */ (fileCountP)\n )\n\n const existingRow = document.querySelector(\n `[data-filename=\"${selectedFile?.name}\"]`\n )\n\n if (existingRow) {\n existingRow.remove()\n }\n\n const row = createFileRow(selectedFile, statusText)\n summaryList.insertBefore(row, summaryList.firstChild)\n statusAnnouncer.textContent = `${selectedFile?.name ?? ''} ${statusText}`\n}\n\n/**\n * Shows an error message using the GOV.UK error summary component\n * and adds inline error styling to the file input\n * @param {string} message - The error message to display\n * @param {HTMLElement | null} errorSummary - The error summary container\n * @param {HTMLInputElement} fileInput - The file input element\n * @returns {void}\n */\nfunction showError(message, errorSummary, fileInput) {\n const topErrorSummary = document.querySelector('.govuk-error-summary')\n\n if (topErrorSummary) {\n const titleElement = document.getElementById(ERROR_SUMMARY_TITLE_ID)\n if (titleElement) {\n fileInput.setAttribute(ARIA_DESCRIBEDBY, ERROR_SUMMARY_TITLE_ID)\n } else {\n fileInput.removeAttribute(ARIA_DESCRIBEDBY)\n }\n return\n }\n\n if (errorSummary) {\n errorSummary.innerHTML = `\n <div class=\"govuk-error-summary\" data-module=\"govuk-error-summary\">\n <div role=\"alert\">\n <h2 class=\"govuk-error-summary__title\" id=\"${ERROR_SUMMARY_TITLE_ID}\">\n There is a problem\n </h2>\n <div class=\"govuk-error-summary__body\">\n <ul class=\"govuk-list govuk-error-summary__list\">\n <li>\n <a href=\"#file-upload\">${message}</a>\n </li>\n </ul>\n </div>\n </div>\n </div>\n `\n\n fileInput.setAttribute(ARIA_DESCRIBEDBY, ERROR_SUMMARY_TITLE_ID)\n }\n\n const formGroup = fileInput.closest('.govuk-form-group')\n if (formGroup) {\n formGroup.classList.add('govuk-form-group--error')\n fileInput.classList.add('govuk-file-upload--error')\n\n const inputId = fileInput.id\n let errorMessage = document.getElementById(`${inputId}-error`)\n\n if (!errorMessage) {\n errorMessage = document.createElement('p')\n errorMessage.id = `${inputId}-error`\n errorMessage.className = 'govuk-error-message'\n errorMessage.innerHTML = `<span class=\"govuk-visually-hidden\">Error:</span> ${message}`\n formGroup.insertBefore(errorMessage, fileInput)\n }\n\n fileInput.setAttribute(\n ARIA_DESCRIBEDBY,\n `error-summary-title ${inputId}-error`\n )\n }\n}\n\n/**\n * Helper to safely convert an Element to HTMLElement\n * @param {Element | null} element - The element to convert\n */\nfunction asHTMLElement(element) {\n return /** @type {HTMLElement} */ (element)\n}\n\nfunction reloadPage() {\n window.history.replaceState(null, '', window.location.href)\n window.location.href = window.location.pathname\n}\n\n/**\n * Build the upload status URL given the current pathname and the upload ID.\n * @param {string} pathname – e.g. window.location.pathname\n * @param {string} uploadId\n * @returns {string} e.g. \"/form/upload-status/abc123\"\n */\nexport function buildUploadStatusUrl(pathname, uploadId) {\n const pathSegments = pathname.split('/').filter((segment) => segment)\n const prefix = pathSegments.length > 0 ? `/${pathSegments[0]}` : ''\n return `${prefix}/upload-status/${uploadId}`\n}\n\n/**\n * Polls the upload status endpoint until the file is ready or timeout occurs\n * @param {string} uploadId - The upload ID to check\n */\nfunction pollUploadStatus(uploadId) {\n let attempts = 0\n const interval = setInterval(() => {\n attempts++\n\n if (attempts >= MAX_POLLING_DURATION) {\n clearInterval(interval)\n reloadPage()\n return\n }\n\n const uploadStatusUrl = buildUploadStatusUrl(\n window.location.pathname,\n uploadId\n )\n\n fetch(uploadStatusUrl, {\n headers: {\n Accept: 'application/json'\n }\n })\n .then((response) => {\n if (!response.ok) {\n throw new Error('Network response was not ok')\n }\n return response.json()\n })\n .then((data) => {\n if (data.uploadStatus === 'ready') {\n clearInterval(interval)\n reloadPage()\n }\n })\n .catch(() => {\n clearInterval(interval)\n reloadPage()\n })\n }, 1000)\n}\n\n/**\n * Handle standard form submission for file upload\n * @param {HTMLFormElement} formElement - The form element\n * @param {HTMLInputElement} fileInput - The file input element\n * @param {HTMLButtonElement} uploadButton - The upload button\n * @param {HTMLButtonElement} continueButton - The continue button\n * @param {File | null} selectedFile - The selected file\n */\nfunction handleStandardFormSubmission(\n formElement,\n fileInput,\n uploadButton,\n continueButton,\n selectedFile\n) {\n renderSummary(selectedFile, 'Uploading…', formElement)\n\n fileInput.focus()\n\n setTimeout(() => {\n fileInput.disabled = true\n uploadButton.disabled = true\n continueButton.disabled = true\n }, 100)\n}\n\n/**\n * Handle AJAX form submission with upload ID\n * @param {Event} event - The click event\n * @param {HTMLFormElement} formElement - The form element\n * @param {HTMLInputElement} fileInput - The file input element\n * @param {HTMLButtonElement} uploadButton - The upload button\n * @param {HTMLElement | null} errorSummary - The error summary container\n * @param {string | undefined} uploadId - The upload ID\n * @returns {boolean} Whether the event was handled\n */\nfunction handleAjaxFormSubmission(\n event,\n formElement,\n fileInput,\n uploadButton,\n errorSummary,\n uploadId\n) {\n if (!formElement.action || !uploadId) {\n return false\n }\n\n event.preventDefault()\n\n const formData = new FormData(formElement)\n const isLocalDev = !!formElement.dataset.proxyUrl\n const uploadUrl = formElement.dataset.proxyUrl ?? formElement.action\n\n const fetchOptions = /** @type {RequestInit} */ ({\n method: 'POST',\n body: formData,\n redirect: isLocalDev ? 'follow' : 'manual' // follow mode if local development with the proxy\n })\n\n // no-cors mode if needed local development with the proxy\n if (isLocalDev) {\n fetchOptions.mode = 'no-cors'\n }\n\n fetch(uploadUrl, fetchOptions)\n .then(() => {\n pollUploadStatus(uploadId)\n })\n .catch(() => {\n fileInput.disabled = false\n uploadButton.disabled = false\n\n showError(\n 'There was a problem uploading the file',\n errorSummary,\n fileInput\n )\n\n return null\n })\n\n return true\n}\n\nfunction initUpload() {\n const form = document.querySelector('form:has(input[type=\"file\"])')\n /** @type {HTMLInputElement | null} */\n const fileInput = form ? form.querySelector('input[type=\"file\"]') : null\n /** @type {HTMLButtonElement | null} */\n const uploadButton = form ? form.querySelector('.upload-file-button') : null\n const continueButton =\n /** @type {HTMLButtonElement} */ (\n Array.from(document.querySelectorAll('button.govuk-button')).find(\n (button) => button.textContent?.trim() === 'Continue'\n )\n ) ?? null\n\n const errorSummary = document.querySelector('.govuk-error-summary-container')\n\n if (!form || !fileInput || !uploadButton) {\n return\n }\n\n const formElement = /** @type {HTMLFormElement} */ (form)\n /** @type {File | null} */\n let selectedFile = null\n let isSubmitting = false\n const uploadId = formElement.dataset.uploadId\n\n fileInput.addEventListener('change', () => {\n if (errorSummary) {\n errorSummary.innerHTML = ''\n }\n\n if (fileInput.files && fileInput.files.length > 0) {\n selectedFile = fileInput.files[0]\n }\n })\n\n uploadButton.addEventListener('click', (event) => {\n if (!selectedFile) {\n event.preventDefault()\n showError(\n 'Select a file',\n /** @type {HTMLElement | null} */ (errorSummary),\n fileInput\n )\n return\n }\n\n if (isSubmitting) {\n event.preventDefault()\n return\n }\n\n isSubmitting = true\n\n handleStandardFormSubmission(\n formElement,\n fileInput,\n uploadButton,\n continueButton,\n selectedFile\n )\n\n handleAjaxFormSubmission(\n event,\n formElement,\n fileInput,\n uploadButton,\n /** @type {HTMLElement | null} */ (errorSummary),\n uploadId\n )\n })\n}\n\nexport function initFileUpload() {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', initUpload)\n } else {\n initUpload()\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB,GAAG,GAAG,EAAC;AACxC,MAAMC,gBAAgB,GAAG,kBAAkB;AAC3C,MAAMC,sBAAsB,GAAG,qBAAqB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,6BAA6BA,CAACC,IAAI,EAAEC,UAAU,EAAE;EACvD,IAAIC,eAAe,GAAGF,IAAI,EAAEG,aAAa,CAAC,oBAAoB,CAAC;EAE/D,IAAI,CAACD,eAAe,EAAE;IACpBA,eAAe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K,IAAI9E,SAAS,CAAC8E,KAAK,CAAC/C,MAAM,GAAG,CAAC,EAAE;MACjD1C,YAAY,GAAGW,SAAS,CAAC8E,KAAK,CAAC,CAAC,CAAC;IACnC;EACF,CAAC,CAAC;EAEF3B,YAAY,CAAC0B,gBAAgB,CAAC,OAAO,EAAGrB,KAAK,IAAK;IAChD,IAAI,CAACnE,YAAY,EAAE;MACjBmE,KAAK,CAACE,cAAc,CAAC,CAAC;MACtBrD,SAAS,CACP,eAAe,EACf,iCAAmCE,YAAY,EAC/CP,SACF,CAAC;MACD;IACF;IAEA,IAAI4E,YAAY,EAAE;MAChBpB,KAAK,CAACE,cAAc,CAAC,CAAC;MACtB;IACF;IAEAkB,YAAY,GAAG,IAAI;IAEnB3B,4BAA4B,CAC1BC,WAAW,EACXlD,SAAS,EACTmD,YAAY,EACZhE,cAAc,EACdE,YACF,CAAC;IAEDkE,wBAAwB,CACtBC,KAAK,EACLN,WAAW,EACXlD,SAAS,EACTmD,YAAY,EACZ,iCAAmC5C,YAAY,EAC/CkB,QACF,CAAC;EACH,CAAC,CAAC;AACJ;AAEA,OAAO,SAASsD,cAAcA,CAAA,EAAG;EAC/B,IAAI3G,QAAQ,CAAC4G,UAAU,KAAK,SAAS,EAAE;IACrC5G,QAAQ,CAACyG,gBAAgB,CAAC,kBAAkB,EAAER,UAAU,CAAC;EAC3D,CAAC,MAAM;IACLA,UAAU,CAAC,CAAC;EACd;AACF","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export function initAllGovuk(): void;
@@ -0,0 +1,12 @@
1
+ import { Button, CharacterCount, Checkboxes, ErrorSummary, Header, NotificationBanner, Radios, SkipLink, createAll } from 'govuk-frontend';
2
+ export function initAllGovuk() {
3
+ createAll(Button);
4
+ createAll(CharacterCount);
5
+ createAll(Checkboxes);
6
+ createAll(ErrorSummary);
7
+ createAll(Header);
8
+ createAll(NotificationBanner);
9
+ createAll(Radios);
10
+ createAll(SkipLink);
11
+ }
12
+ //# sourceMappingURL=govuk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"govuk.js","names":["Button","CharacterCount","Checkboxes","ErrorSummary","Header","NotificationBanner","Radios","SkipLink","createAll","initAllGovuk"],"sources":["../../../src/client/javascripts/govuk.js"],"sourcesContent":["import {\n Button,\n CharacterCount,\n Checkboxes,\n ErrorSummary,\n Header,\n NotificationBanner,\n Radios,\n SkipLink,\n createAll\n} from 'govuk-frontend'\n\nexport function initAllGovuk() {\n createAll(Button)\n createAll(CharacterCount)\n createAll(Checkboxes)\n createAll(ErrorSummary)\n createAll(Header)\n createAll(NotificationBanner)\n createAll(Radios)\n createAll(SkipLink)\n}\n"],"mappings":"AAAA,SACEA,MAAM,EACNC,cAAc,EACdC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,kBAAkB,EAClBC,MAAM,EACNC,QAAQ,EACRC,SAAS,QACJ,gBAAgB;AAEvB,OAAO,SAASC,YAAYA,CAAA,EAAG;EAC7BD,SAAS,CAACR,MAAM,CAAC;EACjBQ,SAAS,CAACP,cAAc,CAAC;EACzBO,SAAS,CAACN,UAAU,CAAC;EACrBM,SAAS,CAACL,YAAY,CAAC;EACvBK,SAAS,CAACJ,MAAM,CAAC;EACjBI,SAAS,CAACH,kBAAkB,CAAC;EAC7BG,SAAS,CAACF,MAAM,CAAC;EACjBE,SAAS,CAACD,QAAQ,CAAC;AACrB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export function initPreviewCloseLink(): void;
@@ -0,0 +1,12 @@
1
+ export function initPreviewCloseLink() {
2
+ // Show preview close link via `rel="opener"`
3
+ if (window.opener) {
4
+ const $closeLink = document.querySelector('.js-preview-banner-close');
5
+ $closeLink?.removeAttribute('hidden');
6
+ $closeLink?.addEventListener('click', event => {
7
+ event.preventDefault();
8
+ window.close();
9
+ });
10
+ }
11
+ }
12
+ //# sourceMappingURL=preview-close-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-close-link.js","names":["initPreviewCloseLink","window","opener","$closeLink","document","querySelector","removeAttribute","addEventListener","event","preventDefault","close"],"sources":["../../../src/client/javascripts/preview-close-link.js"],"sourcesContent":["export function initPreviewCloseLink() {\n // Show preview close link via `rel=\"opener\"`\n if (window.opener) {\n const $closeLink = document.querySelector('.js-preview-banner-close')\n\n $closeLink?.removeAttribute('hidden')\n $closeLink?.addEventListener('click', (event) => {\n event.preventDefault()\n window.close()\n })\n }\n}\n"],"mappings":"AAAA,OAAO,SAASA,oBAAoBA,CAAA,EAAG;EACrC;EACA,IAAIC,MAAM,CAACC,MAAM,EAAE;IACjB,MAAMC,UAAU,GAAGC,QAAQ,CAACC,aAAa,CAAC,0BAA0B,CAAC;IAErEF,UAAU,EAAEG,eAAe,CAAC,QAAQ,CAAC;IACrCH,UAAU,EAAEI,gBAAgB,CAAC,OAAO,EAAGC,KAAK,IAAK;MAC/CA,KAAK,CAACC,cAAc,CAAC,CAAC;MACtBR,MAAM,CAACS,KAAK,CAAC,CAAC;IAChB,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ export function initAll(): void;
2
+ export const initAllGovuk: typeof initAllGovukImp;
3
+ export const initAllAutocomplete: typeof initAllAutocompleteImp;
4
+ export const initFileUpload: typeof initFileUploadImp;
5
+ export const initPreviewCloseLink: typeof initPreviewCloseLinkImp;
6
+ import { initAllGovuk as initAllGovukImp } from '~/src/client/javascripts/govuk.js';
7
+ import { initAllAutocomplete as initAllAutocompleteImp } from '~/src/client/javascripts/autocomplete.js';
8
+ import { initFileUpload as initFileUploadImp } from '~/src/client/javascripts/file-upload.js';
9
+ import { initPreviewCloseLink as initPreviewCloseLinkImp } from '~/src/client/javascripts/preview-close-link.js';
@@ -0,0 +1,15 @@
1
+ import { initAllAutocomplete as initAllAutocompleteImp } from "./autocomplete.js";
2
+ import { initFileUpload as initFileUploadImp } from "./file-upload.js";
3
+ import { initAllGovuk as initAllGovukImp } from "./govuk.js";
4
+ import { initPreviewCloseLink as initPreviewCloseLinkImp } from "./preview-close-link.js";
5
+ export const initAllGovuk = initAllGovukImp;
6
+ export const initAllAutocomplete = initAllAutocompleteImp;
7
+ export const initFileUpload = initFileUploadImp;
8
+ export const initPreviewCloseLink = initPreviewCloseLinkImp;
9
+ export function initAll() {
10
+ initAllGovuk();
11
+ initAllAutocomplete();
12
+ initFileUpload();
13
+ initPreviewCloseLink();
14
+ }
15
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","names":["initAllAutocomplete","initAllAutocompleteImp","initFileUpload","initFileUploadImp","initAllGovuk","initAllGovukImp","initPreviewCloseLink","initPreviewCloseLinkImp","initAll"],"sources":["../../../src/client/javascripts/shared.js"],"sourcesContent":["import { initAllAutocomplete as initAllAutocompleteImp } from '~/src/client/javascripts/autocomplete.js'\nimport { initFileUpload as initFileUploadImp } from '~/src/client/javascripts/file-upload.js'\nimport { initAllGovuk as initAllGovukImp } from '~/src/client/javascripts/govuk.js'\nimport { initPreviewCloseLink as initPreviewCloseLinkImp } from '~/src/client/javascripts/preview-close-link.js'\n\nexport const initAllGovuk = initAllGovukImp\nexport const initAllAutocomplete = initAllAutocompleteImp\nexport const initFileUpload = initFileUploadImp\nexport const initPreviewCloseLink = initPreviewCloseLinkImp\n\nexport function initAll() {\n initAllGovuk()\n initAllAutocomplete()\n initFileUpload()\n initPreviewCloseLink()\n}\n"],"mappings":"AAAA,SAASA,mBAAmB,IAAIC,sBAAsB;AACtD,SAASC,cAAc,IAAIC,iBAAiB;AAC5C,SAASC,YAAY,IAAIC,eAAe;AACxC,SAASC,oBAAoB,IAAIC,uBAAuB;AAExD,OAAO,MAAMH,YAAY,GAAGC,eAAe;AAC3C,OAAO,MAAML,mBAAmB,GAAGC,sBAAsB;AACzD,OAAO,MAAMC,cAAc,GAAGC,iBAAiB;AAC/C,OAAO,MAAMG,oBAAoB,GAAGC,uBAAuB;AAE3D,OAAO,SAASC,OAAOA,CAAA,EAAG;EACxBJ,YAAY,CAAC,CAAC;EACdJ,mBAAmB,CAAC,CAAC;EACrBE,cAAc,CAAC,CAAC;EAChBI,oBAAoB,CAAC,CAAC;AACxB","ignoreList":[]}
@@ -8,10 +8,12 @@ export { CheckboxesField } from '~/src/server/plugins/engine/components/Checkbox
8
8
  export { DatePartsField } from '~/src/server/plugins/engine/components/DatePartsField.js';
9
9
  export { Details } from '~/src/server/plugins/engine/components/Details.js';
10
10
  export { EmailAddressField } from '~/src/server/plugins/engine/components/EmailAddressField.js';
11
+ export { FileUploadField } from '~/src/server/plugins/engine/components/FileUploadField.js';
11
12
  export { Html } from '~/src/server/plugins/engine/components/Html.js';
12
13
  export { InsetText } from '~/src/server/plugins/engine/components/InsetText.js';
13
14
  export { List } from '~/src/server/plugins/engine/components/List.js';
14
15
  export { Markdown } from '~/src/server/plugins/engine/components/Markdown.js';
16
+ export { MonthYearField } from '~/src/server/plugins/engine/components/MonthYearField.js';
15
17
  export { MultilineTextField } from '~/src/server/plugins/engine/components/MultilineTextField.js';
16
18
  export { NumberField } from '~/src/server/plugins/engine/components/NumberField.js';
17
19
  export { RadiosField } from '~/src/server/plugins/engine/components/RadiosField.js';
@@ -20,5 +22,3 @@ export { TelephoneNumberField } from '~/src/server/plugins/engine/components/Tel
20
22
  export { TextField } from '~/src/server/plugins/engine/components/TextField.js';
21
23
  export { UkAddressField } from '~/src/server/plugins/engine/components/UkAddressField.js';
22
24
  export { YesNoField } from '~/src/server/plugins/engine/components/YesNoField.js';
23
- export { MonthYearField } from '~/src/server/plugins/engine/components/MonthYearField.js';
24
- export { FileUploadField } from '~/src/server/plugins/engine/components/FileUploadField.js';
@@ -9,10 +9,12 @@ export { CheckboxesField } from "./CheckboxesField.js";
9
9
  export { DatePartsField } from "./DatePartsField.js";
10
10
  export { Details } from "./Details.js";
11
11
  export { EmailAddressField } from "./EmailAddressField.js";
12
+ export { FileUploadField } from "./FileUploadField.js";
12
13
  export { Html } from "./Html.js";
13
14
  export { InsetText } from "./InsetText.js";
14
15
  export { List } from "./List.js";
15
16
  export { Markdown } from "./Markdown.js";
17
+ export { MonthYearField } from "./MonthYearField.js";
16
18
  export { MultilineTextField } from "./MultilineTextField.js";
17
19
  export { NumberField } from "./NumberField.js";
18
20
  export { RadiosField } from "./RadiosField.js";
@@ -21,6 +23,4 @@ export { TelephoneNumberField } from "./TelephoneNumberField.js";
21
23
  export { TextField } from "./TextField.js";
22
24
  export { UkAddressField } from "./UkAddressField.js";
23
25
  export { YesNoField } from "./YesNoField.js";
24
- export { MonthYearField } from "./MonthYearField.js";
25
- export { FileUploadField } from "./FileUploadField.js";
26
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["AutocompleteField","CheckboxesField","DatePartsField","Details","EmailAddressField","Html","InsetText","List","Markdown","MultilineTextField","NumberField","RadiosField","SelectField","TelephoneNumberField","TextField","UkAddressField","YesNoField","MonthYearField","FileUploadField"],"sources":["../../../../../src/server/plugins/engine/components/index.ts"],"sourcesContent":["/**\n * IMPORTANT: Exported Components must follow the naming convention implemented in {@link @defra/forms-model#ComponentType}\n * In the Form JSON, components have a type property which is the name of the components, e.g. DatePartsField.\n * Components are loaded in the ComponentsCollection constructor.\n */\n\nexport { AutocompleteField } from '~/src/server/plugins/engine/components/AutocompleteField.js'\nexport { CheckboxesField } from '~/src/server/plugins/engine/components/CheckboxesField.js'\nexport { DatePartsField } from '~/src/server/plugins/engine/components/DatePartsField.js'\nexport { Details } from '~/src/server/plugins/engine/components/Details.js'\nexport { EmailAddressField } from '~/src/server/plugins/engine/components/EmailAddressField.js'\nexport { Html } from '~/src/server/plugins/engine/components/Html.js'\nexport { InsetText } from '~/src/server/plugins/engine/components/InsetText.js'\nexport { List } from '~/src/server/plugins/engine/components/List.js'\nexport { Markdown } from '~/src/server/plugins/engine/components/Markdown.js'\nexport { MultilineTextField } from '~/src/server/plugins/engine/components/MultilineTextField.js'\nexport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nexport { RadiosField } from '~/src/server/plugins/engine/components/RadiosField.js'\nexport { SelectField } from '~/src/server/plugins/engine/components/SelectField.js'\nexport { TelephoneNumberField } from '~/src/server/plugins/engine/components/TelephoneNumberField.js'\nexport { TextField } from '~/src/server/plugins/engine/components/TextField.js'\nexport { UkAddressField } from '~/src/server/plugins/engine/components/UkAddressField.js'\nexport { YesNoField } from '~/src/server/plugins/engine/components/YesNoField.js'\nexport { MonthYearField } from '~/src/server/plugins/engine/components/MonthYearField.js'\nexport { FileUploadField } from '~/src/server/plugins/engine/components/FileUploadField.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,cAAc;AACvB,SAASC,OAAO;AAChB,SAASC,iBAAiB;AAC1B,SAASC,IAAI;AACb,SAASC,SAAS;AAClB,SAASC,IAAI;AACb,SAASC,QAAQ;AACjB,SAASC,kBAAkB;AAC3B,SAASC,WAAW;AACpB,SAASC,WAAW;AACpB,SAASC,WAAW;AACpB,SAASC,oBAAoB;AAC7B,SAASC,SAAS;AAClB,SAASC,cAAc;AACvB,SAASC,UAAU;AACnB,SAASC,cAAc;AACvB,SAASC,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["AutocompleteField","CheckboxesField","DatePartsField","Details","EmailAddressField","FileUploadField","Html","InsetText","List","Markdown","MonthYearField","MultilineTextField","NumberField","RadiosField","SelectField","TelephoneNumberField","TextField","UkAddressField","YesNoField"],"sources":["../../../../../src/server/plugins/engine/components/index.ts"],"sourcesContent":["/**\n * IMPORTANT: Exported Components must follow the naming convention implemented in {@link @defra/forms-model#ComponentType}\n * In the Form JSON, components have a type property which is the name of the components, e.g. DatePartsField.\n * Components are loaded in the ComponentsCollection constructor.\n */\n\nexport { AutocompleteField } from '~/src/server/plugins/engine/components/AutocompleteField.js'\nexport { CheckboxesField } from '~/src/server/plugins/engine/components/CheckboxesField.js'\nexport { DatePartsField } from '~/src/server/plugins/engine/components/DatePartsField.js'\nexport { Details } from '~/src/server/plugins/engine/components/Details.js'\nexport { EmailAddressField } from '~/src/server/plugins/engine/components/EmailAddressField.js'\nexport { FileUploadField } from '~/src/server/plugins/engine/components/FileUploadField.js'\nexport { Html } from '~/src/server/plugins/engine/components/Html.js'\nexport { InsetText } from '~/src/server/plugins/engine/components/InsetText.js'\nexport { List } from '~/src/server/plugins/engine/components/List.js'\nexport { Markdown } from '~/src/server/plugins/engine/components/Markdown.js'\nexport { MonthYearField } from '~/src/server/plugins/engine/components/MonthYearField.js'\nexport { MultilineTextField } from '~/src/server/plugins/engine/components/MultilineTextField.js'\nexport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nexport { RadiosField } from '~/src/server/plugins/engine/components/RadiosField.js'\nexport { SelectField } from '~/src/server/plugins/engine/components/SelectField.js'\nexport { TelephoneNumberField } from '~/src/server/plugins/engine/components/TelephoneNumberField.js'\nexport { TextField } from '~/src/server/plugins/engine/components/TextField.js'\nexport { UkAddressField } from '~/src/server/plugins/engine/components/UkAddressField.js'\nexport { YesNoField } from '~/src/server/plugins/engine/components/YesNoField.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,cAAc;AACvB,SAASC,OAAO;AAChB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,IAAI;AACb,SAASC,SAAS;AAClB,SAASC,IAAI;AACb,SAASC,QAAQ;AACjB,SAASC,cAAc;AACvB,SAASC,kBAAkB;AAC3B,SAASC,WAAW;AACpB,SAASC,WAAW;AACpB,SAASC,WAAW;AACpB,SAASC,oBAAoB;AAC7B,SAASC,SAAS;AAClB,SAASC,cAAc;AACvB,SAASC,UAAU","ignoreList":[]}
@@ -2,7 +2,6 @@ import { type Environment } from 'nunjucks';
2
2
  import { plugin } from '~/src/server/plugins/engine/plugin.js';
3
3
  import { type FilterFunction } from '~/src/server/plugins/engine/types.js';
4
4
  export { getPageHref } from '~/src/server/plugins/engine/helpers.js';
5
- export { configureEnginePlugin } from '~/src/server/plugins/engine/configureEnginePlugin.js';
6
5
  export { context } from '~/src/server/plugins/nunjucks/context.js';
7
6
  export declare const VIEW_PATH = "src/server/plugins/engine/views";
8
7
  export declare const PLUGIN_PATH = "node_modules/@defra/forms-engine-plugin";
@@ -3,7 +3,6 @@ import { plugin } from "./plugin.js";
3
3
  import { checkComponentTemplates, checkErrorTemplates, evaluate } from "../nunjucks/environment.js";
4
4
  import * as filters from "../nunjucks/filters/index.js";
5
5
  export { getPageHref } from "./helpers.js";
6
- export { configureEnginePlugin } from "./configureEnginePlugin.js";
7
6
  export { context } from "../nunjucks/context.js";
8
7
  const globals = {
9
8
  checkComponentTemplates,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["engine","plugin","checkComponentTemplates","checkErrorTemplates","evaluate","filters","getPageHref","configureEnginePlugin","context","globals","VIEW_PATH","PLUGIN_PATH","prepareNunjucksEnvironment","env","additionalFilters","name","nunjucksFilter","Object","entries","addFilter","nunjucksGlobal","addGlobal","filter","registerFilter"],"sources":["../../../../src/server/plugins/engine/index.ts"],"sourcesContent":["import { type Environment } from 'nunjucks'\n\nimport { engine } from '~/src/server/plugins/engine/helpers.js'\nimport { plugin } from '~/src/server/plugins/engine/plugin.js'\nimport { type FilterFunction } from '~/src/server/plugins/engine/types.js'\nimport {\n checkComponentTemplates,\n checkErrorTemplates,\n evaluate\n} from '~/src/server/plugins/nunjucks/environment.js'\nimport * as filters from '~/src/server/plugins/nunjucks/filters/index.js'\n\nexport { getPageHref } from '~/src/server/plugins/engine/helpers.js'\nexport { configureEnginePlugin } from '~/src/server/plugins/engine/configureEnginePlugin.js'\nexport { context } from '~/src/server/plugins/nunjucks/context.js'\n\nconst globals = {\n checkComponentTemplates,\n checkErrorTemplates,\n evaluate\n}\n\nexport const VIEW_PATH = 'src/server/plugins/engine/views'\nexport const PLUGIN_PATH = 'node_modules/@defra/forms-engine-plugin'\n\nexport const prepareNunjucksEnvironment = function (\n env: Environment,\n additionalFilters?: Record<string, FilterFunction>\n) {\n for (const [name, nunjucksFilter] of Object.entries(filters)) {\n env.addFilter(name, nunjucksFilter)\n }\n\n for (const [name, nunjucksGlobal] of Object.entries(globals)) {\n env.addGlobal(name, nunjucksGlobal)\n }\n\n // Apply any additional filters to both the liquid and nunjucks engines\n if (additionalFilters) {\n for (const [name, filter] of Object.entries(additionalFilters)) {\n env.addFilter(name, filter)\n engine.registerFilter(name, filter)\n }\n }\n}\n\nexport default plugin\n"],"mappings":"AAEA,SAASA,MAAM;AACf,SAASC,MAAM;AAEf,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,QAAQ;AAEV,OAAO,KAAKC,OAAO;AAEnB,SAASC,WAAW;AACpB,SAASC,qBAAqB;AAC9B,SAASC,OAAO;AAEhB,MAAMC,OAAO,GAAG;EACdP,uBAAuB;EACvBC,mBAAmB;EACnBC;AACF,CAAC;AAED,OAAO,MAAMM,SAAS,GAAG,iCAAiC;AAC1D,OAAO,MAAMC,WAAW,GAAG,yCAAyC;AAEpE,OAAO,MAAMC,0BAA0B,GAAG,SAAAA,CACxCC,GAAgB,EAChBC,iBAAkD,EAClD;EACA,KAAK,MAAM,CAACC,IAAI,EAAEC,cAAc,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACb,OAAO,CAAC,EAAE;IAC5DQ,GAAG,CAACM,SAAS,CAACJ,IAAI,EAAEC,cAAc,CAAC;EACrC;EAEA,KAAK,MAAM,CAACD,IAAI,EAAEK,cAAc,CAAC,IAAIH,MAAM,CAACC,OAAO,CAACT,OAAO,CAAC,EAAE;IAC5DI,GAAG,CAACQ,SAAS,CAACN,IAAI,EAAEK,cAAc,CAAC;EACrC;;EAEA;EACA,IAAIN,iBAAiB,EAAE;IACrB,KAAK,MAAM,CAACC,IAAI,EAAEO,MAAM,CAAC,IAAIL,MAAM,CAACC,OAAO,CAACJ,iBAAiB,CAAC,EAAE;MAC9DD,GAAG,CAACM,SAAS,CAACJ,IAAI,EAAEO,MAAM,CAAC;MAC3BtB,MAAM,CAACuB,cAAc,CAACR,IAAI,EAAEO,MAAM,CAAC;IACrC;EACF;AACF,CAAC;AAED,eAAerB,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["engine","plugin","checkComponentTemplates","checkErrorTemplates","evaluate","filters","getPageHref","context","globals","VIEW_PATH","PLUGIN_PATH","prepareNunjucksEnvironment","env","additionalFilters","name","nunjucksFilter","Object","entries","addFilter","nunjucksGlobal","addGlobal","filter","registerFilter"],"sources":["../../../../src/server/plugins/engine/index.ts"],"sourcesContent":["import { type Environment } from 'nunjucks'\n\nimport { engine } from '~/src/server/plugins/engine/helpers.js'\nimport { plugin } from '~/src/server/plugins/engine/plugin.js'\nimport { type FilterFunction } from '~/src/server/plugins/engine/types.js'\nimport {\n checkComponentTemplates,\n checkErrorTemplates,\n evaluate\n} from '~/src/server/plugins/nunjucks/environment.js'\nimport * as filters from '~/src/server/plugins/nunjucks/filters/index.js'\n\nexport { getPageHref } from '~/src/server/plugins/engine/helpers.js'\nexport { context } from '~/src/server/plugins/nunjucks/context.js'\n\nconst globals = {\n checkComponentTemplates,\n checkErrorTemplates,\n evaluate\n}\n\nexport const VIEW_PATH = 'src/server/plugins/engine/views'\nexport const PLUGIN_PATH = 'node_modules/@defra/forms-engine-plugin'\n\nexport const prepareNunjucksEnvironment = function (\n env: Environment,\n additionalFilters?: Record<string, FilterFunction>\n) {\n for (const [name, nunjucksFilter] of Object.entries(filters)) {\n env.addFilter(name, nunjucksFilter)\n }\n\n for (const [name, nunjucksGlobal] of Object.entries(globals)) {\n env.addGlobal(name, nunjucksGlobal)\n }\n\n // Apply any additional filters to both the liquid and nunjucks engines\n if (additionalFilters) {\n for (const [name, filter] of Object.entries(additionalFilters)) {\n env.addFilter(name, filter)\n engine.registerFilter(name, filter)\n }\n }\n}\n\nexport default plugin\n"],"mappings":"AAEA,SAASA,MAAM;AACf,SAASC,MAAM;AAEf,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,QAAQ;AAEV,OAAO,KAAKC,OAAO;AAEnB,SAASC,WAAW;AACpB,SAASC,OAAO;AAEhB,MAAMC,OAAO,GAAG;EACdN,uBAAuB;EACvBC,mBAAmB;EACnBC;AACF,CAAC;AAED,OAAO,MAAMK,SAAS,GAAG,iCAAiC;AAC1D,OAAO,MAAMC,WAAW,GAAG,yCAAyC;AAEpE,OAAO,MAAMC,0BAA0B,GAAG,SAAAA,CACxCC,GAAgB,EAChBC,iBAAkD,EAClD;EACA,KAAK,MAAM,CAACC,IAAI,EAAEC,cAAc,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;IAC5DO,GAAG,CAACM,SAAS,CAACJ,IAAI,EAAEC,cAAc,CAAC;EACrC;EAEA,KAAK,MAAM,CAACD,IAAI,EAAEK,cAAc,CAAC,IAAIH,MAAM,CAACC,OAAO,CAACT,OAAO,CAAC,EAAE;IAC5DI,GAAG,CAACQ,SAAS,CAACN,IAAI,EAAEK,cAAc,CAAC;EACrC;;EAEA;EACA,IAAIN,iBAAiB,EAAE;IACrB,KAAK,MAAM,CAACC,IAAI,EAAEO,MAAM,CAAC,IAAIL,MAAM,CAACC,OAAO,CAACJ,iBAAiB,CAAC,EAAE;MAC9DD,GAAG,CAACM,SAAS,CAACJ,IAAI,EAAEO,MAAM,CAAC;MAC3BrB,MAAM,CAACsB,cAAc,CAACR,IAAI,EAAEO,MAAM,CAAC;IACrC;EACF;AACF,CAAC;AAED,eAAepB,MAAM","ignoreList":[]}
@@ -29,17 +29,4 @@
29
29
  {{ super() }}
30
30
 
31
31
  <div class="govuk-summary-list-container"></div>
32
-
33
- {% endblock %}
34
-
35
- {% block bodyEnd %}
36
- {{ super() }}
37
- <script type="module" nonce="{{ cspNonce }}">
38
- import { initFileUpload } from '{{ getDxtAssetPath("file-upload.js") }}';
39
- if (document.readyState === 'loading') {
40
- document.addEventListener('DOMContentLoaded', initFileUpload);
41
- } else {
42
- initFileUpload();
43
- }
44
- </script>
45
32
  {% endblock %}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-engine-plugin",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Defra forms engine",
5
5
  "type": "module",
6
6
  "files": [
@@ -14,13 +14,9 @@
14
14
  "import": "./.server/server/plugins/engine/index.js",
15
15
  "default": "./.server/server/plugins/engine/index.js"
16
16
  },
17
- "./application.js": "./.server/client/javascripts/application.js",
18
- "./application.min.js": "./.public/javascripts/application.min.js",
19
- "./application.min.js.map": "./.public/javascripts/application.min.js.map",
20
- "./file-upload.js": "./.server/client/javascripts/file-upload.js",
21
- "./file-upload.min.js": "./.public/javascripts/file-upload.min.js",
22
- "./file-upload.min.js.map": "./.public/javascripts/file-upload.min.js.map",
23
- "./application.min.css": "./.public/stylesheets/application.min.css",
17
+ "./shared.js": "./.server/client/javascripts/shared.js",
18
+ "./shared.min.js": "./.public/javascripts/shared.min.js",
19
+ "./shared.min.js.map": "./.public/javascripts/shared.min.js.map",
24
20
  "./file-form-service.js": "./.server/server/utils/file-form-service.js",
25
21
  "./controllers/*": "./.server/server/plugins/engine/pageControllers/*",
26
22
  "./components": "./.server/server/plugins/engine/components/index.js",
@@ -1,87 +1,3 @@
1
- import {
2
- Button,
3
- CharacterCount,
4
- Checkboxes,
5
- ErrorSummary,
6
- Header,
7
- NotificationBanner,
8
- Radios,
9
- SkipLink,
10
- createAll
11
- } from 'govuk-frontend'
1
+ import { initAll } from '~/src/client/javascripts/shared.js'
12
2
 
13
- createAll(Button)
14
- createAll(CharacterCount)
15
- createAll(Checkboxes)
16
- createAll(ErrorSummary)
17
- createAll(Header)
18
- createAll(NotificationBanner)
19
- createAll(Radios)
20
- createAll(SkipLink)
21
-
22
- // Show preview close link via `rel="opener"`
23
- if (window.opener) {
24
- const $closeLink = document.querySelector('.js-preview-banner-close')
25
-
26
- $closeLink?.removeAttribute('hidden')
27
- $closeLink?.addEventListener('click', (event) => {
28
- event.preventDefault()
29
- window.close()
30
- })
31
- }
32
-
33
- /**
34
- * Initialise autocomplete
35
- * @param {HTMLSelectElement | null} $select
36
- * @param {(config: object) => void} init
37
- */
38
- function initAutocomplete($select, init) {
39
- if (!$select) {
40
- return
41
- }
42
-
43
- const config = {
44
- id: $select.id,
45
- selectElement: $select
46
- }
47
-
48
- init(config)
49
-
50
- /** @type {HTMLInputElement | null} */
51
- const $input = document.querySelector(`#${config.id}`)
52
-
53
- // Allowed values for input
54
- const inputValues = [...$select.options].map((option) => option.text)
55
-
56
- // Reset select when input value is not allowed
57
- $input?.addEventListener('blur', () => {
58
- if (!$input.value || !inputValues.includes($input.value)) {
59
- $select.value = ''
60
- }
61
- })
62
- }
63
-
64
- // Find all autocompletes
65
- const $autocompletes = document.querySelectorAll(
66
- `[data-module="govuk-accessible-autocomplete"]`
67
- )
68
-
69
- // Lazy load autocomplete component
70
- if ($autocompletes.length) {
71
- // @ts-expect-error -- No types available
72
- import('accessible-autocomplete')
73
- .then((component) => {
74
- const { default: accessibleAutocomplete } = component
75
-
76
- // Initialise each autocomplete
77
- $autocompletes.forEach(($module) =>
78
- initAutocomplete(
79
- $module.querySelector('select'),
80
- accessibleAutocomplete.enhanceSelectElement
81
- )
82
- )
83
- })
84
-
85
- // eslint-disable-next-line no-console
86
- .catch(console.error)
87
- }
3
+ initAll()
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Initialise autocomplete
3
+ * @param {HTMLSelectElement | null} $select
4
+ * @param {(config: object) => void} init
5
+ */
6
+ function initAutocomplete($select, init) {
7
+ if (!$select) {
8
+ return
9
+ }
10
+
11
+ const config = {
12
+ id: $select.id,
13
+ selectElement: $select
14
+ }
15
+
16
+ init(config)
17
+
18
+ /** @type {HTMLInputElement | null} */
19
+ const $input = document.querySelector(`#${config.id}`)
20
+
21
+ // Allowed values for input
22
+ const inputValues = [...$select.options].map((option) => option.text)
23
+
24
+ // Reset select when input value is not allowed
25
+ $input?.addEventListener('blur', () => {
26
+ if (!$input.value || !inputValues.includes($input.value)) {
27
+ $select.value = ''
28
+ }
29
+ })
30
+ }
31
+
32
+ export function initAllAutocomplete() {
33
+ // Find all autocompletes
34
+ const $autocompletes = document.querySelectorAll(
35
+ `[data-module="govuk-accessible-autocomplete"]`
36
+ )
37
+
38
+ // Lazy load autocomplete component
39
+ if ($autocompletes.length) {
40
+ // @ts-expect-error -- No types available
41
+ import('accessible-autocomplete')
42
+ .then((component) => {
43
+ const { default: accessibleAutocomplete } = component
44
+
45
+ // Initialise each autocomplete
46
+ $autocompletes.forEach(($module) =>
47
+ initAutocomplete(
48
+ $module.querySelector('select'),
49
+ accessibleAutocomplete.enhanceSelectElement
50
+ )
51
+ )
52
+ })
53
+
54
+ // eslint-disable-next-line no-console
55
+ .catch(console.error)
56
+ }
57
+ }
@@ -369,7 +369,7 @@ function handleAjaxFormSubmission(
369
369
  return true
370
370
  }
371
371
 
372
- export function initFileUpload() {
372
+ function initUpload() {
373
373
  const form = document.querySelector('form:has(input[type="file"])')
374
374
  /** @type {HTMLInputElement | null} */
375
375
  const fileInput = form ? form.querySelector('input[type="file"]') : null
@@ -440,3 +440,11 @@ export function initFileUpload() {
440
440
  )
441
441
  })
442
442
  }
443
+
444
+ export function initFileUpload() {
445
+ if (document.readyState === 'loading') {
446
+ document.addEventListener('DOMContentLoaded', initUpload)
447
+ } else {
448
+ initUpload()
449
+ }
450
+ }