@defra/forms-engine-plugin 0.0.1 → 0.0.3

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.
@@ -21,7 +21,7 @@ for (const [name, nunjucksFilter] of Object.entries(filters)) {
21
21
  * @this {NunjucksContext}
22
22
  * @param {FormSubmissionError[]} errors
23
23
  */
24
- function checkErrorTemplates(errors) {
24
+ export function checkErrorTemplates(errors) {
25
25
  const {
26
26
  context
27
27
  } = this.ctx;
@@ -39,7 +39,7 @@ environment.addGlobal('checkErrorTemplates', checkErrorTemplates);
39
39
  * @this {NunjucksContext}
40
40
  * @param {ComponentViewModel} component
41
41
  */
42
- function checkComponentTemplates(component) {
42
+ export function checkComponentTemplates(component) {
43
43
  const {
44
44
  context
45
45
  } = this.ctx;
@@ -79,7 +79,7 @@ environment.addGlobal('checkComponentTemplates', checkComponentTemplates);
79
79
  * @this {NunjucksContext}
80
80
  * @param {string} template
81
81
  */
82
- function evaluate(template) {
82
+ export function evaluate(template) {
83
83
  const {
84
84
  context
85
85
  } = this.ctx;
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","names":["dirname","join","ComponentType","nunjucks","resolvePkg","config","evaluateTemplate","filters","govukFrontendPath","sync","paths","get","environment","configure","trimBlocks","lstripBlocks","watch","noCache","name","nunjucksFilter","Object","entries","addFilter","checkErrorTemplates","errors","context","ctx","forEach","error","text","addGlobal","checkComponentTemplates","component","isFormComponent","model","fieldset","legend","label","errorMessage","message","type","Html","content","evaluate","template"],"sources":["../../../../src/server/plugins/nunjucks/environment.js"],"sourcesContent":["import { dirname, join } from 'node:path'\n\nimport { ComponentType } from '@defra/forms-model'\nimport nunjucks from 'nunjucks'\nimport resolvePkg from 'resolve'\n\nimport { config } from '~/src/config/index.js'\nimport { evaluateTemplate } from '~/src/server/plugins/engine/helpers.js'\nimport * as filters from '~/src/server/plugins/nunjucks/filters/index.js'\n\nconst govukFrontendPath = dirname(\n resolvePkg.sync('govuk-frontend/package.json')\n)\n\nexport const paths = [\n join(config.get('appDir'), 'plugins/engine/views'),\n join(config.get('appDir'), 'views')\n]\n\nexport const environment = nunjucks.configure(\n [...paths, join(govukFrontendPath, 'dist')],\n {\n trimBlocks: true,\n lstripBlocks: true,\n watch: config.get('isDevelopment'),\n noCache: config.get('isDevelopment')\n }\n)\n\nfor (const [name, nunjucksFilter] of Object.entries(filters)) {\n environment.addFilter(name, nunjucksFilter)\n}\n\n/**\n * @this {NunjucksContext}\n * @param {FormSubmissionError[]} errors\n */\nfunction checkErrorTemplates(errors) {\n const { context } = this.ctx\n\n if (!context) {\n return errors\n }\n\n errors.forEach((error) => {\n error.text = evaluateTemplate(error.text, context)\n })\n\n return errors\n}\n\nenvironment.addGlobal('checkErrorTemplates', checkErrorTemplates)\n\n/**\n * @this {NunjucksContext}\n * @param {ComponentViewModel} component\n */\nfunction checkComponentTemplates(component) {\n const { context } = this.ctx\n\n if (!context) {\n return component\n }\n\n if (component.isFormComponent) {\n // Evaluate label/legend text\n if (component.model.fieldset?.legend?.text) {\n const legend = component.model.fieldset.legend\n\n legend.text = evaluateTemplate(legend.text, context)\n } else if (component.model.label?.text) {\n const label = component.model.label\n\n label.text = evaluateTemplate(label.text, context)\n } else {\n // No template evaluation needed for other component types\n }\n\n // Evaluate error message\n if (component.model.errorMessage?.text) {\n const message = component.model.errorMessage\n\n message.text = evaluateTemplate(message.text, context)\n }\n } else if (component.type === ComponentType.Html) {\n const content = component.model.content\n\n if (typeof content === 'string') {\n component.model.content = evaluateTemplate(content, context)\n }\n } else {\n // No template evaluation needed for other component types\n }\n\n return component\n}\n\nenvironment.addGlobal('checkComponentTemplates', checkComponentTemplates)\n\n/**\n * @this {NunjucksContext}\n * @param {string} template\n */\nfunction evaluate(template) {\n const { context } = this.ctx\n\n return context ? evaluateTemplate(template, context) : template\n}\n\nenvironment.addGlobal('evaluate', evaluate)\n\n/**\n * @import { NunjucksContext } from '~/src/server/plugins/nunjucks/types.js'\n * @import { FormSubmissionError } from '~/src/server/plugins/engine/types.js'\n * @import { ComponentViewModel } from '~/src/server/plugins/engine/components/types.js'\n */\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,IAAI,QAAQ,WAAW;AAEzC,SAASC,aAAa,QAAQ,oBAAoB;AAClD,OAAOC,QAAQ,MAAM,UAAU;AAC/B,OAAOC,UAAU,MAAM,SAAS;AAEhC,SAASC,MAAM;AACf,SAASC,gBAAgB;AACzB,OAAO,KAAKC,OAAO;AAEnB,MAAMC,iBAAiB,GAAGR,OAAO,CAC/BI,UAAU,CAACK,IAAI,CAAC,6BAA6B,CAC/C,CAAC;AAED,OAAO,MAAMC,KAAK,GAAG,CACnBT,IAAI,CAACI,MAAM,CAACM,GAAG,CAAC,QAAQ,CAAC,EAAE,sBAAsB,CAAC,EAClDV,IAAI,CAACI,MAAM,CAACM,GAAG,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CACpC;AAED,OAAO,MAAMC,WAAW,GAAGT,QAAQ,CAACU,SAAS,CAC3C,CAAC,GAAGH,KAAK,EAAET,IAAI,CAACO,iBAAiB,EAAE,MAAM,CAAC,CAAC,EAC3C;EACEM,UAAU,EAAE,IAAI;EAChBC,YAAY,EAAE,IAAI;EAClBC,KAAK,EAAEX,MAAM,CAACM,GAAG,CAAC,eAAe,CAAC;EAClCM,OAAO,EAAEZ,MAAM,CAACM,GAAG,CAAC,eAAe;AACrC,CACF,CAAC;AAED,KAAK,MAAM,CAACO,IAAI,EAAEC,cAAc,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACd,OAAO,CAAC,EAAE;EAC5DK,WAAW,CAACU,SAAS,CAACJ,IAAI,EAAEC,cAAc,CAAC;AAC7C;;AAEA;AACA;AACA;AACA;AACA,SAASI,mBAAmBA,CAACC,MAAM,EAAE;EACnC,MAAM;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,GAAG;EAE5B,IAAI,CAACD,OAAO,EAAE;IACZ,OAAOD,MAAM;EACf;EAEAA,MAAM,CAACG,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AMC,OAAO,GAAGV,SAAS,CAACE,KAAK,CAACQ,OAAO;IAEvC,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/BV,SAAS,CAACE,KAAK,CAACQ,OAAO,GAAGpC,gBAAgB,CAACoC,OAAO,EAAEjB,OAAO,CAAC;IAC9D;EACF,CAAC,MAAM;IACL;EAAA;EAGF,OAAOO,SAAS;AAClB;AAEApB,WAAW,CAACkB,SAAS,CAAC,yBAAyB,EAAEC,uBAAuB,CAAC;;AAEzE;AACA;AACA;AACA;AACA,SAASY,QAAQA,CAACC,QAAQ,EAAE;EAC1B,MAAM;IAAEnB;EAAQ,CAAC,GAAG,IAAI,CAACC,GAAG;EAE5B,OAAOD,OAAO,GAAGnB,gBAAgB,CAACsC,QAAQ,EAAEnB,OAAO,CAAC,GAAGmB,QAAQ;AACjE;AAEAhC,WAAW,CAACkB,SAAS,CAAC,UAAU,EAAEa,QAAQ,CAAC;;AAE3C;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"environment.js","names":["dirname","join","ComponentType","nunjucks","resolvePkg","config","evaluateTemplate","filters","govukFrontendPath","sync","paths","get","environment","configure","trimBlocks","lstripBlocks","watch","noCache","name","nunjucksFilter","Object","entries","addFilter","checkErrorTemplates","errors","context","ctx","forEach","error","text","addGlobal","checkComponentTemplates","component","isFormComponent","model","fieldset","legend","label","errorMessage","message","type","Html","content","evaluate","template"],"sources":["../../../../src/server/plugins/nunjucks/environment.js"],"sourcesContent":["import { dirname, join } from 'node:path'\n\nimport { ComponentType } from '@defra/forms-model'\nimport nunjucks from 'nunjucks'\nimport resolvePkg from 'resolve'\n\nimport { config } from '~/src/config/index.js'\nimport { evaluateTemplate } from '~/src/server/plugins/engine/helpers.js'\nimport * as filters from '~/src/server/plugins/nunjucks/filters/index.js'\n\nconst govukFrontendPath = dirname(\n resolvePkg.sync('govuk-frontend/package.json')\n)\n\nexport const paths = [\n join(config.get('appDir'), 'plugins/engine/views'),\n join(config.get('appDir'), 'views')\n]\n\nexport const environment = nunjucks.configure(\n [...paths, join(govukFrontendPath, 'dist')],\n {\n trimBlocks: true,\n lstripBlocks: true,\n watch: config.get('isDevelopment'),\n noCache: config.get('isDevelopment')\n }\n)\n\nfor (const [name, nunjucksFilter] of Object.entries(filters)) {\n environment.addFilter(name, nunjucksFilter)\n}\n\n/**\n * @this {NunjucksContext}\n * @param {FormSubmissionError[]} errors\n */\nexport function checkErrorTemplates(errors) {\n const { context } = this.ctx\n\n if (!context) {\n return errors\n }\n\n errors.forEach((error) => {\n error.text = evaluateTemplate(error.text, context)\n })\n\n return errors\n}\n\nenvironment.addGlobal('checkErrorTemplates', checkErrorTemplates)\n\n/**\n * @this {NunjucksContext}\n * @param {ComponentViewModel} component\n */\nexport function checkComponentTemplates(component) {\n const { context } = this.ctx\n\n if (!context) {\n return component\n }\n\n if (component.isFormComponent) {\n // Evaluate label/legend text\n if (component.model.fieldset?.legend?.text) {\n const legend = component.model.fieldset.legend\n\n legend.text = evaluateTemplate(legend.text, context)\n } else if (component.model.label?.text) {\n const label = component.model.label\n\n label.text = evaluateTemplate(label.text, context)\n } else {\n // No template evaluation needed for other component types\n }\n\n // Evaluate error message\n if (component.model.errorMessage?.text) {\n const message = component.model.errorMessage\n\n message.text = evaluateTemplate(message.text, context)\n }\n } else if (component.type === ComponentType.Html) {\n const content = component.model.content\n\n if (typeof content === 'string') {\n component.model.content = evaluateTemplate(content, context)\n }\n } else {\n // No template evaluation needed for other component types\n }\n\n return component\n}\n\nenvironment.addGlobal('checkComponentTemplates', checkComponentTemplates)\n\n/**\n * @this {NunjucksContext}\n * @param {string} template\n */\nexport function evaluate(template) {\n const { context } = this.ctx\n\n return context ? evaluateTemplate(template, context) : template\n}\n\nenvironment.addGlobal('evaluate', evaluate)\n\n/**\n * @import { NunjucksContext } from '~/src/server/plugins/nunjucks/types.js'\n * @import { FormSubmissionError } from '~/src/server/plugins/engine/types.js'\n * @import { ComponentViewModel } from '~/src/server/plugins/engine/components/types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AEvC,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/BV,SAAS,CAACE,KAAK,CAACQ,OAAO,GAAGpC,gBAAgB,CAACoC,OAAO,EAAEjB,OAAO,CAAC;IAC9D;EACF,CAAC,MAAM;IACL;EAAA;EAGF,OAAOO,SAAS;AAClB;AAEApB,WAAW,CAACkB,SAAS,CAAC,yBAAyB,EAAEC,uBAAuB,CAAC;;AAEzE;AACA;AACA;AACA;AACA,OAAO,SAASY,QAAQA,CAACC,QAAQ,EAAE;EACjC,MAAM;IAAEnB;EAAQ,CAAC,GAAG,IAAI,CAACC,GAAG;EAE5B,OAAOD,OAAO,GAAGnB,gBAAgB,CAACsC,QAAQ,EAAEnB,OAAO,CAAC,GAAGmB,QAAQ;AACjE;AAEAhC,WAAW,CAACkB,SAAS,CAAC,UAAU,EAAEa,QAAQ,CAAC;;AAE3C;AACA;AACA;AACA;AACA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-engine-plugin",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Defra forms engine",
5
5
  "type": "module",
6
6
  "main": ".server/server/plugins/engine/index.js",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "repository": {
33
33
  "type": "git",
34
- "url": "https://github.com/XGovFormBuilder/digital-form-builder/tree/main/builder"
34
+ "url": "https://github.com/DEFRA/forms-engine-plugin"
35
35
  },
36
36
  "engines": {
37
37
  "node": "^22.11.0",
@@ -35,7 +35,7 @@ for (const [name, nunjucksFilter] of Object.entries(filters)) {
35
35
  * @this {NunjucksContext}
36
36
  * @param {FormSubmissionError[]} errors
37
37
  */
38
- function checkErrorTemplates(errors) {
38
+ export function checkErrorTemplates(errors) {
39
39
  const { context } = this.ctx
40
40
 
41
41
  if (!context) {
@@ -55,7 +55,7 @@ environment.addGlobal('checkErrorTemplates', checkErrorTemplates)
55
55
  * @this {NunjucksContext}
56
56
  * @param {ComponentViewModel} component
57
57
  */
58
- function checkComponentTemplates(component) {
58
+ export function checkComponentTemplates(component) {
59
59
  const { context } = this.ctx
60
60
 
61
61
  if (!context) {
@@ -101,7 +101,7 @@ environment.addGlobal('checkComponentTemplates', checkComponentTemplates)
101
101
  * @this {NunjucksContext}
102
102
  * @param {string} template
103
103
  */
104
- function evaluate(template) {
104
+ export function evaluate(template) {
105
105
  const { context } = this.ctx
106
106
 
107
107
  return context ? evaluateTemplate(template, context) : template