@defra/forms-model 3.0.663 → 3.0.664
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.
- package/dist/module/pages/helpers.js +18 -2
- package/dist/module/pages/helpers.js.map +1 -1
- package/dist/module/pages/index.js +1 -1
- package/dist/module/pages/index.js.map +1 -1
- package/dist/types/pages/helpers.d.ts +4 -0
- package/dist/types/pages/helpers.d.ts.map +1 -1
- package/dist/types/pages/index.d.ts +1 -1
- package/dist/types/pages/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/pages/helpers.ts +23 -2
- package/src/pages/index.ts +1 -0
|
@@ -103,6 +103,22 @@ export function hasPaymentQuestionInForm(definition) {
|
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Helper function to determine if the form uses postcode lookup
|
|
108
|
+
*/
|
|
109
|
+
export function hasPostcodeLookupInForm(definition) {
|
|
110
|
+
if (definition.pages.length === 0) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
for (const page of definition.pages) {
|
|
114
|
+
const addressField = hasComponents(page) ? page.components.find(component => component.type === ComponentType.UkAddressField) : undefined;
|
|
115
|
+
if (addressField?.options.usePostcodeLookup) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
106
122
|
/**
|
|
107
123
|
* Helper function to determine if a specific question type exists in the form
|
|
108
124
|
*/
|
|
@@ -111,8 +127,8 @@ export function hasSpecificQuestionTypeInForm(definition, componentType) {
|
|
|
111
127
|
return false;
|
|
112
128
|
}
|
|
113
129
|
for (const page of definition.pages) {
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
130
|
+
const hasSpecificComponent = hasComponents(page) ? page.components.some(component => component.type === componentType) : false;
|
|
131
|
+
if (hasSpecificComponent) {
|
|
116
132
|
return true;
|
|
117
133
|
}
|
|
118
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","isFormType","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","onlyDeclarationComponents","filter","comp","every","DeclarationField","includesPaymentField","PaymentField","hasPaymentQuestionInForm","definition","pages","length","hasPayment","hasSpecificQuestionTypeInForm","componentType","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","getPageTitle","title","firstComp","getPageFromDefinition","pageId","x","id","summaryPageControllers","Summary","SummaryWithConfirmationEmail","isSummaryPage","replaceCustomControllers","standardControllers","Set","Object","values","toString","has","isPaymentPage","isEndPage"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { hasFormField, isFormType } from '~/src/components/helpers.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { type FormDefinition } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nexport function includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nexport function onlyDeclarationComponents(components: ComponentDef[]): boolean {\n return components\n .filter((comp) => isFormType(comp.type))\n .every((component) => component.type === ComponentType.DeclarationField)\n}\n\nexport function includesPaymentField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.PaymentField\n )\n}\n\n/**\n * Helper function to determine if a payment question already exists in the form\n */\nexport function hasPaymentQuestionInForm(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasPayment = hasComponents(page)\n ? includesPaymentField(page.components)\n : false\n if (hasPayment) {\n return true\n }\n }\n return false\n}\n\n/**\n * Helper function to determine if a specific question type exists in the form\n */\nexport function hasSpecificQuestionTypeInForm(\n definition: FormDefinition,\n componentType: ComponentType\n) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasPayment = hasComponents(page)\n ? page.components.some((component) => component.type === componentType)\n : false\n if (hasPayment) {\n return true\n }\n }\n return false\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page)) {\n if (includesFileUploadField(page.components)) {\n return false\n }\n if (onlyDeclarationComponents(page.components)) {\n return false\n }\n if (includesPaymentField(page.components)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n\n/**\n *\n * @param {FormDefinition} definition\n * @param {string} pageId\n * @returns { Page | undefined }\n */\nexport function getPageFromDefinition(\n definition: FormDefinition,\n pageId: string\n): Page | undefined {\n return definition.pages.find((x) => x.id === pageId)\n}\n\nexport const summaryPageControllers = [\n ControllerType.Summary,\n ControllerType.SummaryWithConfirmationEmail\n]\n\nexport function isSummaryPage(page: Page | undefined) {\n return summaryPageControllers.includes(\n page?.controller ?? ControllerType.Page\n )\n}\n\n/**\n * Revert any custom controllers to their parent/base class since engine-plugin has no knowledge of them\n * @param {FormDefinition} definition\n * @returns {FormDefinition}\n */\nexport function replaceCustomControllers(definition: FormDefinition) {\n const standardControllers = new Set(\n Object.values(ControllerType)\n .filter((x) => x !== ControllerType.SummaryWithConfirmationEmail)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n .map((x) => x.toString())\n )\n\n return {\n ...definition,\n pages: definition.pages.map((page) => {\n if (\n !standardControllers.has(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n (page.controller ?? ControllerType.Page).toString()\n )\n ) {\n return /** @type {Page} */ {\n ...page,\n controller: ControllerType.Page\n }\n }\n return page\n })\n } as FormDefinition\n}\n\n/**\n * Helper function to determine if the current page contains a payment question\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isPaymentPage(page: Page | undefined) {\n if (hasComponentsEvenIfNoNext(page)) {\n return page.components.some(\n (comp) => comp.type === ComponentType.PaymentField\n )\n }\n return false\n}\n\n/**\n * Helper function to determine if the current page is an end page i.e. summary page or payment page\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isEndPage(page: Page | undefined) {\n return isSummaryPage(page) || isPaymentPage(page)\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY,EAAEC,UAAU;AAUjC,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CAAC;EAED,IAAI,CAACG,QAAQ,EAAE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B,UAAU;IACbC,KAAK,EAAED,UAAU,CAACC,KAAK,CAACtB,GAAG,CAAEtB,IAAI,IAAK;MACpC,IACE,CAAC+D,mBAAmB,CAACK,GAAG;MACtB;MACA,CAACpE,IAAI,CAACE,UAAU,IAAIL,cAAc,CAACM,IAAI,EAAEgE,QAAQ,CAAC,CACpD,CAAC,EACD;QACA,OAAO,mBAAoB;UACzB,GAAGnE,IAAI;UACPE,UAAU,EAAEL,cAAc,CAACM;QAC7B,CAAC;MACH;MACA,OAAOH,IAAI;IACb,CAAC;EACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASqE,aAAaA,CAACrE,IAAsB,EAAE;EACpD,IAAIe,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,OAAOA,IAAI,CAACc,UAAU,CAACiB,IAAI,CACxBM,IAAI,IAAKA,IAAI,CAACJ,IAAI,KAAKzC,aAAa,CAACiD,YACxC,CAAC;EACH;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS6B,SAASA,CAACtE,IAAsB,EAAE;EAChD,OAAO6D,aAAa,CAAC7D,IAAI,CAAC,IAAIqE,aAAa,CAACrE,IAAI,CAAC;AACnD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","isFormType","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","onlyDeclarationComponents","filter","comp","every","DeclarationField","includesPaymentField","PaymentField","hasPaymentQuestionInForm","definition","pages","length","hasPayment","hasPostcodeLookupInForm","addressField","UkAddressField","usePostcodeLookup","hasSpecificQuestionTypeInForm","componentType","hasSpecificComponent","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","getPageTitle","title","firstComp","getPageFromDefinition","pageId","x","id","summaryPageControllers","Summary","SummaryWithConfirmationEmail","isSummaryPage","replaceCustomControllers","standardControllers","Set","Object","values","toString","has","isPaymentPage","isEndPage"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { hasFormField, isFormType } from '~/src/components/helpers.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { type FormDefinition } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nexport function includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nexport function onlyDeclarationComponents(components: ComponentDef[]): boolean {\n return components\n .filter((comp) => isFormType(comp.type))\n .every((component) => component.type === ComponentType.DeclarationField)\n}\n\nexport function includesPaymentField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.PaymentField\n )\n}\n\n/**\n * Helper function to determine if a payment question already exists in the form\n */\nexport function hasPaymentQuestionInForm(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasPayment = hasComponents(page)\n ? includesPaymentField(page.components)\n : false\n if (hasPayment) {\n return true\n }\n }\n return false\n}\n\n/**\n * Helper function to determine if the form uses postcode lookup\n */\nexport function hasPostcodeLookupInForm(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const addressField = hasComponents(page)\n ? page.components.find(\n (component) => component.type === ComponentType.UkAddressField\n )\n : undefined\n if (addressField?.options.usePostcodeLookup) {\n return true\n }\n }\n return false\n}\n\n/**\n * Helper function to determine if a specific question type exists in the form\n */\nexport function hasSpecificQuestionTypeInForm(\n definition: FormDefinition,\n componentType: ComponentType\n) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasSpecificComponent = hasComponents(page)\n ? page.components.some((component) => component.type === componentType)\n : false\n if (hasSpecificComponent) {\n return true\n }\n }\n return false\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page)) {\n if (includesFileUploadField(page.components)) {\n return false\n }\n if (onlyDeclarationComponents(page.components)) {\n return false\n }\n if (includesPaymentField(page.components)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n\n/**\n *\n * @param {FormDefinition} definition\n * @param {string} pageId\n * @returns { Page | undefined }\n */\nexport function getPageFromDefinition(\n definition: FormDefinition,\n pageId: string\n): Page | undefined {\n return definition.pages.find((x) => x.id === pageId)\n}\n\nexport const summaryPageControllers = [\n ControllerType.Summary,\n ControllerType.SummaryWithConfirmationEmail\n]\n\nexport function isSummaryPage(page: Page | undefined) {\n return summaryPageControllers.includes(\n page?.controller ?? ControllerType.Page\n )\n}\n\n/**\n * Revert any custom controllers to their parent/base class since engine-plugin has no knowledge of them\n * @param {FormDefinition} definition\n * @returns {FormDefinition}\n */\nexport function replaceCustomControllers(definition: FormDefinition) {\n const standardControllers = new Set(\n Object.values(ControllerType)\n .filter((x) => x !== ControllerType.SummaryWithConfirmationEmail)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n .map((x) => x.toString())\n )\n\n return {\n ...definition,\n pages: definition.pages.map((page) => {\n if (\n !standardControllers.has(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n (page.controller ?? ControllerType.Page).toString()\n )\n ) {\n return /** @type {Page} */ {\n ...page,\n controller: ControllerType.Page\n }\n }\n return page\n })\n } as FormDefinition\n}\n\n/**\n * Helper function to determine if the current page contains a payment question\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isPaymentPage(page: Page | undefined) {\n if (hasComponentsEvenIfNoNext(page)) {\n return page.components.some(\n (comp) => comp.type === ComponentType.PaymentField\n )\n }\n return false\n}\n\n/**\n * Helper function to determine if the current page is an end page i.e. summary page or payment page\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isEndPage(page: Page | undefined) {\n return isSummaryPage(page) || isPaymentPage(page)\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY,EAAEC,UAAU;AAUjC,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CAAC;EAED,IAAI,CAACG,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CAAC,qCAAqCP,UAAU,GAAG,CAAC;EACrE;EAEA,OAAOQ,eAAe,CAACJ,QAAQ,CAAC;AAClC;;AAEA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAC3BV,IAAoB,EACmC;E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AO,SAASgE,wBAAwBA,CAACxB,UAA0B,EAAE;EACnE,MAAMyB,mBAAmB,GAAG,IAAIC,GAAG,CACjCC,MAAM,CAACC,MAAM,CAAC1E,cAAc,CAAC,CAC1BuC,MAAM,CAAEyB,CAAC,IAAKA,CAAC,KAAKhE,cAAc,CAACoE,4BAA4B;EAChE;EAAA,CACC3C,GAAG,CAAEuC,CAAC,IAAKA,CAAC,CAACW,QAAQ,CAAC,CAAC,CAC5B,CAAC;EAED,OAAO;IACL,GAAG7B,UAAU;IACbC,KAAK,EAAED,UAAU,CAACC,KAAK,CAACtB,GAAG,CAAEtB,IAAI,IAAK;MACpC,IACE,CAACoE,mBAAmB,CAACK,GAAG;MACtB;MACA,CAACzE,IAAI,CAACE,UAAU,IAAIL,cAAc,CAACM,IAAI,EAAEqE,QAAQ,CAAC,CACpD,CAAC,EACD;QACA,OAAO,mBAAoB;UACzB,GAAGxE,IAAI;UACPE,UAAU,EAAEL,cAAc,CAACM;QAC7B,CAAC;MACH;MACA,OAAOH,IAAI;IACb,CAAC;EACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS0E,aAAaA,CAAC1E,IAAsB,EAAE;EACpD,IAAIe,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,OAAOA,IAAI,CAACc,UAAU,CAACiB,IAAI,CACxBM,IAAI,IAAKA,IAAI,CAACJ,IAAI,KAAKzC,aAAa,CAACiD,YACxC,CAAC;EACH;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASkC,SAASA,CAAC3E,IAAsB,EAAE;EAChD,OAAOkE,aAAa,CAAClE,IAAI,CAAC,IAAI0E,aAAa,CAAC1E,IAAI,CAAC;AACnD","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ControllerNames, ControllerTypes } from "./controller-types.js";
|
|
2
2
|
export { PageTypes } from "./page-types.js";
|
|
3
|
-
export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from "./helpers.js";
|
|
3
|
+
export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasPostcodeLookupInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from "./helpers.js";
|
|
4
4
|
export { ControllerPath, ControllerType } from "./enums.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","getPageFromDefinition","getPageTitle","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasPaymentQuestionInForm","hasRepeater","hasSpecificQuestionTypeInForm","includesFileUploadField","includesPaymentField","isControllerName","isEndPage","isPaymentPage","isSummaryPage","replaceCustomControllers","showRepeaterSettings","summaryPageControllers","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n getPageFromDefinition,\n getPageTitle,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasPaymentQuestionInForm,\n hasRepeater,\n hasSpecificQuestionTypeInForm,\n includesFileUploadField,\n includesPaymentField,\n isControllerName,\n isEndPage,\n isPaymentPage,\n isSummaryPage,\n replaceCustomControllers,\n showRepeaterSettings,\n summaryPageControllers\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,wBAAwB,EACxBC,WAAW,EACXC,6BAA6B,EAC7BC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,wBAAwB,EACxBC,oBAAoB,EACpBC,sBAAsB;AAGxB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","getPageFromDefinition","getPageTitle","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasPaymentQuestionInForm","hasPostcodeLookupInForm","hasRepeater","hasSpecificQuestionTypeInForm","includesFileUploadField","includesPaymentField","isControllerName","isEndPage","isPaymentPage","isSummaryPage","replaceCustomControllers","showRepeaterSettings","summaryPageControllers","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n getPageFromDefinition,\n getPageTitle,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasPaymentQuestionInForm,\n hasPostcodeLookupInForm,\n hasRepeater,\n hasSpecificQuestionTypeInForm,\n includesFileUploadField,\n includesPaymentField,\n isControllerName,\n isEndPage,\n isPaymentPage,\n isSummaryPage,\n replaceCustomControllers,\n showRepeaterSettings,\n summaryPageControllers\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,wBAAwB,EACxBC,uBAAuB,EACvBC,WAAW,EACXC,6BAA6B,EAC7BC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,wBAAwB,EACxBC,oBAAoB,EACpBC,sBAAsB;AAGxB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
|
|
@@ -49,6 +49,10 @@ export declare function includesPaymentField(components: ComponentDef[]): boolea
|
|
|
49
49
|
* Helper function to determine if a payment question already exists in the form
|
|
50
50
|
*/
|
|
51
51
|
export declare function hasPaymentQuestionInForm(definition: FormDefinition): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Helper function to determine if the form uses postcode lookup
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasPostcodeLookupInForm(definition: FormDefinition): boolean;
|
|
52
56
|
/**
|
|
53
57
|
* Helper function to determine if a specific question type exists in the form
|
|
54
58
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pages/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEzD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,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AU,EAAE,YAAY,EAAE,GAAG,OAAO,CAI7E;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAIxE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,cAAc,WAclE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,cAAc,WAgBjE;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,cAAc,EAC1B,aAAa,EAAE,aAAa,WAe7B;AAID,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAgBxD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,UAYtC;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,MAAM,GACb,IAAI,GAAG,SAAS,CAElB;AAED,eAAO,MAAM,sBAAsB,kBAGlC,CAAA;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,WAInD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,cAAc,GAwB5D,cAAc,CACpB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,WAOnD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,WAE/C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ControllerNames, ControllerTypes } from '../pages/controller-types.js';
|
|
2
2
|
export { PageTypes } from '../pages/page-types.js';
|
|
3
|
-
export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from '../pages/helpers.js';
|
|
3
|
+
export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasPostcodeLookupInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from '../pages/helpers.js';
|
|
4
4
|
export { ControllerPath, ControllerType } from '../pages/enums.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,wBAAwB,EACxB,WAAW,EACX,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,EACX,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
package/package.json
CHANGED
package/src/pages/helpers.ts
CHANGED
|
@@ -154,6 +154,27 @@ export function hasPaymentQuestionInForm(definition: FormDefinition) {
|
|
|
154
154
|
return false
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Helper function to determine if the form uses postcode lookup
|
|
159
|
+
*/
|
|
160
|
+
export function hasPostcodeLookupInForm(definition: FormDefinition) {
|
|
161
|
+
if (definition.pages.length === 0) {
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const page of definition.pages) {
|
|
166
|
+
const addressField = hasComponents(page)
|
|
167
|
+
? page.components.find(
|
|
168
|
+
(component) => component.type === ComponentType.UkAddressField
|
|
169
|
+
)
|
|
170
|
+
: undefined
|
|
171
|
+
if (addressField?.options.usePostcodeLookup) {
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
/**
|
|
158
179
|
* Helper function to determine if a specific question type exists in the form
|
|
159
180
|
*/
|
|
@@ -166,10 +187,10 @@ export function hasSpecificQuestionTypeInForm(
|
|
|
166
187
|
}
|
|
167
188
|
|
|
168
189
|
for (const page of definition.pages) {
|
|
169
|
-
const
|
|
190
|
+
const hasSpecificComponent = hasComponents(page)
|
|
170
191
|
? page.components.some((component) => component.type === componentType)
|
|
171
192
|
: false
|
|
172
|
-
if (
|
|
193
|
+
if (hasSpecificComponent) {
|
|
173
194
|
return true
|
|
174
195
|
}
|
|
175
196
|
}
|