@defra/forms-model 3.0.590 → 3.0.592
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/form/form-definition/helpers.js +9 -0
- package/dist/module/form/form-definition/helpers.js.map +1 -1
- package/dist/types/form/form-definition/helpers.d.ts +5 -0
- package/dist/types/form/form-definition/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/form/form-definition/helpers.ts +12 -0
|
@@ -40,4 +40,13 @@ export function getHiddenFields(definition) {
|
|
|
40
40
|
}
|
|
41
41
|
return totalHiddenFields;
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param definition - form definition
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
export function isFeedbackForm(definition) {
|
|
49
|
+
const feedback = 'FeedbackPageController';
|
|
50
|
+
return definition?.pages ? definition.pages.some(p => p.controller === feedback) : false;
|
|
51
|
+
}
|
|
43
52
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["ComponentType","hasComponents","isFormDefinition","definition","isConditionListItemRefValueData","conditionValueData","getHiddenFields","pages","length","totalHiddenFields","page","hiddenFields","components","filter","comp","type","HiddenField","push"],"sources":["../../../../src/form/form-definition/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport { type ConditionListItemRefValueDataV2 } from '~/src/conditions/types.js'\nimport { type FormDefinition } from '~/src/form/form-definition/types.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n\n/**\n * TypeGuard to check if something is a FormDefinition\n * @param { unknown } definition\n * @returns { definition is FormDefinition }\n */\nexport function isFormDefinition(\n definition: unknown\n): definition is FormDefinition {\n if (!definition) {\n return false\n }\n\n return (\n typeof definition === 'object' &&\n 'name' in definition &&\n 'pages' in definition &&\n 'conditions' in definition\n )\n}\n\n/**\n * TypeGuard to check if something is a ConditionListItemRefValueDataV2\n * @param { unknown } conditionValueData\n * @returns { definition is ConditionListItemRefValueDataV2 }\n */\nexport function isConditionListItemRefValueData(\n conditionValueData: unknown\n): conditionValueData is ConditionListItemRefValueDataV2 {\n if (!conditionValueData) {\n return false\n }\n\n return (\n typeof conditionValueData === 'object' &&\n 'listId' in conditionValueData &&\n 'itemId' in conditionValueData\n )\n}\n\n/**\n * Returns an array of all hidden fields in a form\n * @param definition - form definition\n */\nexport function getHiddenFields(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return []\n }\n const totalHiddenFields = [] as ComponentDef[]\n for (const page of definition.pages) {\n const hiddenFields = hasComponents(page)\n ? page.components.filter(\n (comp) => comp.type === ComponentType.HiddenField\n )\n : []\n totalHiddenFields.push(...hiddenFields)\n }\n return totalHiddenFields\n}\n"],"mappings":"AAAA,SAASA,aAAa;
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["ComponentType","hasComponents","isFormDefinition","definition","isConditionListItemRefValueData","conditionValueData","getHiddenFields","pages","length","totalHiddenFields","page","hiddenFields","components","filter","comp","type","HiddenField","push","isFeedbackForm","feedback","some","p","controller"],"sources":["../../../../src/form/form-definition/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport { type ConditionListItemRefValueDataV2 } from '~/src/conditions/types.js'\nimport { type FormDefinition } from '~/src/form/form-definition/types.js'\nimport { type ControllerType } from '~/src/pages/enums.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n\n/**\n * TypeGuard to check if something is a FormDefinition\n * @param { unknown } definition\n * @returns { definition is FormDefinition }\n */\nexport function isFormDefinition(\n definition: unknown\n): definition is FormDefinition {\n if (!definition) {\n return false\n }\n\n return (\n typeof definition === 'object' &&\n 'name' in definition &&\n 'pages' in definition &&\n 'conditions' in definition\n )\n}\n\n/**\n * TypeGuard to check if something is a ConditionListItemRefValueDataV2\n * @param { unknown } conditionValueData\n * @returns { definition is ConditionListItemRefValueDataV2 }\n */\nexport function isConditionListItemRefValueData(\n conditionValueData: unknown\n): conditionValueData is ConditionListItemRefValueDataV2 {\n if (!conditionValueData) {\n return false\n }\n\n return (\n typeof conditionValueData === 'object' &&\n 'listId' in conditionValueData &&\n 'itemId' in conditionValueData\n )\n}\n\n/**\n * Returns an array of all hidden fields in a form\n * @param definition - form definition\n */\nexport function getHiddenFields(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return []\n }\n const totalHiddenFields = [] as ComponentDef[]\n for (const page of definition.pages) {\n const hiddenFields = hasComponents(page)\n ? page.components.filter(\n (comp) => comp.type === ComponentType.HiddenField\n )\n : []\n totalHiddenFields.push(...hiddenFields)\n }\n return totalHiddenFields\n}\n\n/**\n * @param definition - form definition\n * @returns {boolean}\n */\nexport function isFeedbackForm(definition: FormDefinition | undefined) {\n const feedback = 'FeedbackPageController' as ControllerType\n return definition?.pages\n ? definition.pages.some((p) => p.controller === feedback)\n : false\n}\n"],"mappings":"AAAA,SAASA,aAAa;AAKtB,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,UAAmB,EACW;EAC9B,IAAI,CAACA,UAAU,EAAE;IACf,OAAO,KAAK;EACd;EAEA,OACE,OAAOA,UAAU,KAAK,QAAQ,IAC9B,MAAM,IAAIA,UAAU,IACpB,OAAO,IAAIA,UAAU,IACrB,YAAY,IAAIA,UAAU;AAE9B;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,+BAA+BA,CAC7CC,kBAA2B,EAC4B;EACvD,IAAI,CAACA,kBAAkB,EAAE;IACvB,OAAO,KAAK;EACd;EAEA,OACE,OAAOA,kBAAkB,KAAK,QAAQ,IACtC,QAAQ,IAAIA,kBAAkB,IAC9B,QAAQ,IAAIA,kBAAkB;AAElC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACH,UAA0B,EAAE;EAC1D,IAAIA,UAAU,CAACI,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACjC,OAAO,EAAE;EACX;EACA,MAAMC,iBAAiB,GAAG,EAAoB;EAC9C,KAAK,MAAMC,IAAI,IAAIP,UAAU,CAACI,KAAK,EAAE;IACnC,MAAMI,YAAY,GAAGV,aAAa,CAACS,IAAI,CAAC,GACpCA,IAAI,CAACE,UAAU,CAACC,MAAM,CACnBC,IAAI,IAAKA,IAAI,CAACC,IAAI,KAAKf,aAAa,CAACgB,WACxC,CAAC,GACD,EAAE;IACNP,iBAAiB,CAACQ,IAAI,CAAC,GAAGN,YAAY,CAAC;EACzC;EACA,OAAOF,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASS,cAAcA,CAACf,UAAsC,EAAE;EACrE,MAAMgB,QAAQ,GAAG,wBAA0C;EAC3D,OAAOhB,UAAU,EAAEI,KAAK,GACpBJ,UAAU,CAACI,KAAK,CAACa,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,UAAU,KAAKH,QAAQ,CAAC,GACvD,KAAK;AACX","ignoreList":[]}
|
|
@@ -18,4 +18,9 @@ export declare function isConditionListItemRefValueData(conditionValueData: unkn
|
|
|
18
18
|
* @param definition - form definition
|
|
19
19
|
*/
|
|
20
20
|
export declare function getHiddenFields(definition: FormDefinition): ComponentDef[];
|
|
21
|
+
/**
|
|
22
|
+
* @param definition - form definition
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export declare function isFeedbackForm(definition: FormDefinition | undefined): boolean;
|
|
21
26
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/form/form-definition/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,2BAA2B,CAAA;AAChF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/form/form-definition/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,2BAA2B,CAAA;AAChF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAIzE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,OAAO,GAClB,UAAU,IAAI,cAAc,CAW9B;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,kBAAkB,EAAE,OAAO,GAC1B,kBAAkB,IAAI,+BAA+B,CAUvD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,cAAc,kBAczD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,WAKpE"}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { ComponentType } from '~/src/components/enums.js'
|
|
|
2
2
|
import { type ComponentDef } from '~/src/components/types.js'
|
|
3
3
|
import { type ConditionListItemRefValueDataV2 } from '~/src/conditions/types.js'
|
|
4
4
|
import { type FormDefinition } from '~/src/form/form-definition/types.js'
|
|
5
|
+
import { type ControllerType } from '~/src/pages/enums.js'
|
|
5
6
|
import { hasComponents } from '~/src/pages/helpers.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -62,3 +63,14 @@ export function getHiddenFields(definition: FormDefinition) {
|
|
|
62
63
|
}
|
|
63
64
|
return totalHiddenFields
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param definition - form definition
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
export function isFeedbackForm(definition: FormDefinition | undefined) {
|
|
72
|
+
const feedback = 'FeedbackPageController' as ControllerType
|
|
73
|
+
return definition?.pages
|
|
74
|
+
? definition.pages.some((p) => p.controller === feedback)
|
|
75
|
+
: false
|
|
76
|
+
}
|