@defra/forms-model 3.0.491 → 3.0.493

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 (70) hide show
  1. package/dist/module/form/form-editor/__stubs__/preview.js +6 -7
  2. package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
  3. package/dist/module/form/form-editor/macros/types.js.map +1 -1
  4. package/dist/module/form/form-editor/preview/autocomplete.js +3 -0
  5. package/dist/module/form/form-editor/preview/autocomplete.js.map +1 -1
  6. package/dist/module/form/form-editor/preview/component-elements.js +2 -10
  7. package/dist/module/form/form-editor/preview/component-elements.js.map +1 -1
  8. package/dist/module/form/form-editor/preview/content.js +2 -3
  9. package/dist/module/form/form-editor/preview/content.js.map +1 -1
  10. package/dist/module/form/form-editor/preview/controller/page-controller.js +91 -6
  11. package/dist/module/form/form-editor/preview/controller/page-controller.js.map +1 -1
  12. package/dist/module/form/form-editor/preview/helpers.js +10 -8
  13. package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
  14. package/dist/module/form/form-editor/preview/list.js +60 -8
  15. package/dist/module/form/form-editor/preview/list.js.map +1 -1
  16. package/dist/module/form/form-editor/preview/preview.js +3 -8
  17. package/dist/module/form/form-editor/preview/preview.js.map +1 -1
  18. package/dist/module/form/form-editor/preview/question.js +2 -2
  19. package/dist/module/form/form-editor/preview/question.js.map +1 -1
  20. package/dist/module/form/form-editor/preview/select-sortable.js +5 -1
  21. package/dist/module/form/form-editor/preview/select-sortable.js.map +1 -1
  22. package/dist/module/form/form-editor/preview/select.js +32 -0
  23. package/dist/module/form/form-editor/preview/select.js.map +1 -1
  24. package/dist/module/form/form-editor/preview/types.js.map +1 -1
  25. package/dist/module/stubs.js +3 -0
  26. package/dist/module/stubs.js.map +1 -1
  27. package/dist/types/form/form-editor/__stubs__/preview.d.ts +4 -3
  28. package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
  29. package/dist/types/form/form-editor/macros/types.d.ts +13 -5
  30. package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
  31. package/dist/types/form/form-editor/preview/autocomplete.d.ts.map +1 -1
  32. package/dist/types/form/form-editor/preview/component-elements.d.ts +1 -7
  33. package/dist/types/form/form-editor/preview/component-elements.d.ts.map +1 -1
  34. package/dist/types/form/form-editor/preview/content.d.ts +1 -2
  35. package/dist/types/form/form-editor/preview/content.d.ts.map +1 -1
  36. package/dist/types/form/form-editor/preview/controller/page-controller.d.ts +27 -0
  37. package/dist/types/form/form-editor/preview/controller/page-controller.d.ts.map +1 -1
  38. package/dist/types/form/form-editor/preview/fieldset-question.d.ts +2 -5
  39. package/dist/types/form/form-editor/preview/fieldset-question.d.ts.map +1 -1
  40. package/dist/types/form/form-editor/preview/helpers.d.ts +1 -2
  41. package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
  42. package/dist/types/form/form-editor/preview/list.d.ts +33 -8
  43. package/dist/types/form/form-editor/preview/list.d.ts.map +1 -1
  44. package/dist/types/form/form-editor/preview/preview.d.ts +4 -5
  45. package/dist/types/form/form-editor/preview/preview.d.ts.map +1 -1
  46. package/dist/types/form/form-editor/preview/question.d.ts +1 -1
  47. package/dist/types/form/form-editor/preview/question.d.ts.map +1 -1
  48. package/dist/types/form/form-editor/preview/select-sortable.d.ts +1 -1
  49. package/dist/types/form/form-editor/preview/select-sortable.d.ts.map +1 -1
  50. package/dist/types/form/form-editor/preview/select.d.ts +14 -0
  51. package/dist/types/form/form-editor/preview/select.d.ts.map +1 -1
  52. package/dist/types/form/form-editor/preview/types.d.ts +17 -4
  53. package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
  54. package/dist/types/stubs.d.ts +3 -0
  55. package/dist/types/stubs.d.ts.map +1 -1
  56. package/package.json +1 -1
  57. package/src/form/form-editor/__stubs__/preview.js +6 -14
  58. package/src/form/form-editor/macros/types.ts +12 -1
  59. package/src/form/form-editor/preview/autocomplete.js +1 -0
  60. package/src/form/form-editor/preview/component-elements.js +2 -10
  61. package/src/form/form-editor/preview/content.js +2 -3
  62. package/src/form/form-editor/preview/controller/page-controller.js +109 -10
  63. package/src/form/form-editor/preview/helpers.js +16 -12
  64. package/src/form/form-editor/preview/list.js +73 -17
  65. package/src/form/form-editor/preview/preview.js +3 -11
  66. package/src/form/form-editor/preview/question.js +2 -2
  67. package/src/form/form-editor/preview/select-sortable.js +5 -1
  68. package/src/form/form-editor/preview/select.js +38 -0
  69. package/src/form/form-editor/preview/types.ts +23 -4
  70. package/src/stubs.ts +3 -0
@@ -96,7 +96,6 @@ export class QuestionPreviewElements {
96
96
  * @private
97
97
  */
98
98
  _items = [];
99
- _largeTitle = true;
100
99
  afterInputsHTML = '<div class="govuk-inset-text">No items added yet.</div>';
101
100
 
102
101
  /**
@@ -108,8 +107,7 @@ export class QuestionPreviewElements {
108
107
  optional,
109
108
  shortDesc,
110
109
  items,
111
- content,
112
- largeTitle = true
110
+ content
113
111
  }) {
114
112
  this._question = question;
115
113
  this._hintText = hintText;
@@ -117,7 +115,6 @@ export class QuestionPreviewElements {
117
115
  this._shortDesc = shortDesc;
118
116
  this._items = items;
119
117
  this._content = content;
120
- this._largeTitle = largeTitle;
121
118
  }
122
119
 
123
120
  /**
@@ -130,8 +127,7 @@ export class QuestionPreviewElements {
130
127
  optional: this._optional,
131
128
  shortDesc: this._shortDesc,
132
129
  items: this._items,
133
- content: this._content,
134
- largeTitle: this._largeTitle
130
+ content: this._content
135
131
  };
136
132
  }
137
133
 
@@ -172,14 +168,17 @@ export class AutocompletePreviewElements extends QuestionPreviewElements {
172
168
  export class PagePreviewElements {
173
169
  guidance;
174
170
  heading;
171
+ addHeading;
175
172
 
176
173
  /**
177
174
  * @param {string} heading
178
175
  * @param {string} guidance
176
+ * @param {boolean} [addHeading]
179
177
  */
180
- constructor(heading, guidance = '') {
178
+ constructor(heading, guidance = '', addHeading = undefined) {
181
179
  this.heading = heading;
182
180
  this.guidance = guidance;
181
+ this.addHeading = addHeading ?? heading.length > 0;
183
182
  }
184
183
  }
185
184
  export const baseElements = /** @type {BaseSettings} */{
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","names":["Question","QuestionRendererStub","renderMock","constructor","render","questionTemplate","questionBaseModel","buildHTML","_questionTemplate","_renderContext","PageRendererStub","pageTemplate","pagePreviewPanelMacro","QuestionPreviewElements","_question","_hintText","_optional","_shortDesc","_content","_items","_largeTitle","afterInputsHTML","question","hintText","optional","shortDesc","items","content","largeTitle","values","setPreviewHTML","_value","setPreviewDOM","AutocompletePreviewElements","autocompleteOptions","elements","PagePreviewElements","guidance","heading","baseElements","list1Id","list2Id","list3Id","list4Id","listElementsBase","label","text","value","id","listElementsStub","buildPreviewShortAnswer","partialBaseElements"],"sources":["../../../../../src/form/form-editor/__stubs__/preview.js"],"sourcesContent":["import { Question } from '~/src/form/form-editor/preview/question.js'\n\n/**\n * @implements {QuestionRenderer}\n */\nexport class QuestionRendererStub {\n /**\n * @type {jest.Mock<void, [string, QuestionBaseModel]>}\n */\n renderMock\n\n /**\n * @param {jest.Mock<void, [string, QuestionBaseModel]>} renderMock\n */\n constructor(renderMock) {\n this.renderMock = renderMock\n }\n\n /**\n * @param {string} questionTemplate\n * @param {QuestionBaseModel} questionBaseModel\n */\n render(questionTemplate, questionBaseModel) {\n this.renderMock(questionTemplate, questionBaseModel)\n }\n\n /**\n * @returns {string}\n * @param {string} _questionTemplate\n * @param {RenderContext} _renderContext\n */\n static buildHTML(_questionTemplate, _renderContext) {\n return '**** BUILT HTML ****'\n }\n}\n\n/**\n * @implements {PageRenderer}\n */\nexport class PageRendererStub {\n /**\n * @type {jest.Mock<void, [string, PagePreviewPanelMacro]>}\n */\n renderMock\n\n /**\n * @param {jest.Mock<void, [string, PagePreviewPanelMacro]>} renderMock\n */\n constructor(renderMock) {\n this.renderMock = renderMock\n }\n\n /**\n * @param {string} pageTemplate\n * @param {PagePreviewPanelMacro} pagePreviewPanelMacro\n */\n render(pageTemplate, pagePreviewPanelMacro) {\n this.renderMock(pageTemplate, pagePreviewPanelMacro)\n }\n\n /**\n * @returns {string}\n * @param {string} _questionTemplate\n * @param {RenderContext} _renderContext\n */\n static buildHTML(_questionTemplate, _renderContext) {\n return '**** BUILT HTML ****'\n }\n}\n\n/**\n * @implements {ListElements}\n */\nexport class QuestionPreviewElements {\n /**\n * @protected\n */\n _question = ''\n /** @protected */\n _hintText = ''\n /** @protected */\n _optional = false\n /**\n * @type {string}\n * @protected\n */\n _shortDesc = ''\n /**\n * @type {string}\n * @protected\n */\n _content = ''\n /**\n *\n * @type {ListElement[]}\n * @private\n */\n _items = []\n _largeTitle = true\n afterInputsHTML = '<div class=\"govuk-inset-text\">No items added yet.</div>'\n\n /**\n * @param {BaseSettings} baseSettings\n */\n constructor({\n question,\n hintText,\n optional,\n shortDesc,\n items,\n content,\n largeTitle = true\n }) {\n this._question = question\n this._hintText = hintText\n this._optional = optional\n this._shortDesc = shortDesc\n this._items = items\n this._content = content\n this._largeTitle = largeTitle\n }\n\n /**\n * @returns {BaseSettings}\n */\n get values() {\n return {\n question: this._question,\n hintText: this._hintText,\n optional: this._optional,\n shortDesc: this._shortDesc,\n items: this._items,\n content: this._content,\n largeTitle: this._largeTitle\n }\n }\n\n /**\n * @param {string} _value\n */\n setPreviewHTML(_value) {\n // Not implemented for server side render\n }\n\n /**\n * @param {HTMLElement} _value\n */\n setPreviewDOM(_value) {\n // Not implemented for server side render\n }\n}\n\n/**\n * @implements {AutocompleteElements}\n */\nexport class AutocompletePreviewElements extends QuestionPreviewElements {\n /**\n * @param {BaseSettings & {autocompleteOptions: string}} elements\n */\n constructor({ autocompleteOptions, ...elements }) {\n super(elements)\n this.autocompleteOptions = autocompleteOptions\n }\n}\n\n/**\n * @implements {PageOverviewElements}\n */\nexport class PagePreviewElements {\n guidance\n heading\n\n /**\n * @param {string} heading\n * @param {string} guidance\n */\n constructor(heading, guidance = '') {\n this.heading = heading\n this.guidance = guidance\n }\n}\n\nexport const baseElements = /** @type {BaseSettings} */ ({\n items: [],\n optional: false,\n question: 'Which quest would you like to pick?',\n hintText: 'Choose one adventure that best suits you.',\n shortDesc: '',\n content: '',\n largeTitle: true\n})\n\nconst list1Id = '414d82a3-4cab-416a-bd54-6b86fbd51120'\nconst list2Id = '801385a4-81e6-4171-96c3-6c6727d97f22'\nconst list3Id = 'e6e3f621-b875-4ca3-a054-cca9149149dd'\nconst list4Id = 'd71b3909-582f-4e90-b6f5-490b89a6eb8f'\n\nconst listElementsBase = /** @type {BaseSettings} */ ({\n ...baseElements,\n items: [\n {\n label: { text: 'Treasure Hunting' },\n text: 'Treasure Hunting',\n value: 'Treasure Hunting',\n id: list1Id\n },\n {\n label: { text: 'Rescuing the princess' },\n text: 'Rescuing the princess',\n value: 'Rescuing the princess',\n id: list2Id\n },\n {\n label: { text: 'Saving a city' },\n text: 'Saving a city',\n value: 'Saving a city',\n id: list3Id\n },\n {\n label: { text: 'Defeating the baron' },\n text: 'Defeating the baron',\n value: 'Defeating the baron',\n id: list4Id\n }\n ]\n})\n\nexport const listElementsStub = {\n list1Id,\n list2Id,\n list3Id,\n list4Id,\n baseElements: listElementsBase\n}\n\n/**\n * @param {Partial<BaseSettings>} partialBaseElements\n * @param {jest.Mock<void, [string, QuestionBaseModel]>} renderMock\n * @returns {Question}\n */\nexport function buildPreviewShortAnswer(partialBaseElements, renderMock) {\n return new Question(\n new QuestionPreviewElements({\n ...baseElements,\n ...partialBaseElements\n }),\n new QuestionRendererStub(renderMock)\n )\n}\n\n/**\n * @import { ListElement } from '~/src/form/form-editor/types.js'\n * @import { PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n * @import { BaseSettings, ListElements, RenderContext, QuestionBaseModel, QuestionElements, QuestionRenderer, AutocompleteElements, PageOverviewElements, PageRenderer } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,QAAQ;;AAEjB;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,CAAC;EAChC;AACF;AACA;EACEC,UAAU;;EAEV;AACF;AACA;EACEC,WAAWA,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CAAC;IAC1B,GAAG0B,YAAY;IACf,GAAGY;EACL,CAAC,CAAC,EACF,IAAIlD,oBAAoB,CAACC,UAAU,CACrC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"preview.js","names":["Question","QuestionRendererStub","renderMock","constructor","render","questionTemplate","questionBaseModel","buildHTML","_questionTemplate","_renderContext","PageRendererStub","pageTemplate","pagePreviewPanelMacro","QuestionPreviewElements","_question","_hintText","_optional","_shortDesc","_content","_items","afterInputsHTML","question","hintText","optional","shortDesc","items","content","values","setPreviewHTML","_value","setPreviewDOM","AutocompletePreviewElements","autocompleteOptions","elements","PagePreviewElements","guidance","heading","addHeading","undefined","length","baseElements","largeTitle","list1Id","list2Id","list3Id","list4Id","listElementsBase","label","text","value","id","listElementsStub","buildPreviewShortAnswer","partialBaseElements"],"sources":["../../../../../src/form/form-editor/__stubs__/preview.js"],"sourcesContent":["import { Question } from '~/src/form/form-editor/preview/question.js'\n\n/**\n * @implements {QuestionRenderer}\n */\nexport class QuestionRendererStub {\n /**\n * @type {jest.Mock<void, [string, QuestionBaseModel]>}\n */\n renderMock\n\n /**\n * @param {jest.Mock<void, [string, QuestionBaseModel]>} renderMock\n */\n constructor(renderMock) {\n this.renderMock = renderMock\n }\n\n /**\n * @param {string} questionTemplate\n * @param {QuestionBaseModel} questionBaseModel\n */\n render(questionTemplate, questionBaseModel) {\n this.renderMock(questionTemplate, questionBaseModel)\n }\n\n /**\n * @returns {string}\n * @param {string} _questionTemplate\n * @param {RenderContext} _renderContext\n */\n static buildHTML(_questionTemplate, _renderContext) {\n return '**** BUILT HTML ****'\n }\n}\n\n/**\n * @implements {PageRenderer}\n */\nexport class PageRendererStub {\n /**\n * @type {jest.Mock<void, [string, PagePreviewPanelMacro]>}\n */\n renderMock\n\n /**\n * @param {jest.Mock<void, [string, PagePreviewPanelMacro]>} renderMock\n */\n constructor(renderMock) {\n this.renderMock = renderMock\n }\n\n /**\n * @param {string} pageTemplate\n * @param {PagePreviewPanelMacro} pagePreviewPanelMacro\n */\n render(pageTemplate, pagePreviewPanelMacro) {\n this.renderMock(pageTemplate, pagePreviewPanelMacro)\n }\n\n /**\n * @returns {string}\n * @param {string} _questionTemplate\n * @param {RenderContext} _renderContext\n */\n static buildHTML(_questionTemplate, _renderContext) {\n return '**** BUILT HTML ****'\n }\n}\n\n/**\n * @implements {ListElements}\n */\nexport class QuestionPreviewElements {\n /**\n * @protected\n */\n _question = ''\n /** @protected */\n _hintText = ''\n /** @protected */\n _optional = false\n /**\n * @type {string}\n * @protected\n */\n _shortDesc = ''\n /**\n * @type {string}\n * @protected\n */\n _content = ''\n /**\n *\n * @type {ListElement[]}\n * @private\n */\n _items = []\n afterInputsHTML = '<div class=\"govuk-inset-text\">No items added yet.</div>'\n\n /**\n * @param {BaseSettings} baseSettings\n */\n constructor({ question, hintText, optional, shortDesc, items, content }) {\n this._question = question\n this._hintText = hintText\n this._optional = optional\n this._shortDesc = shortDesc\n this._items = items\n this._content = content\n }\n\n /**\n * @returns {BaseSettings}\n */\n get values() {\n return {\n question: this._question,\n hintText: this._hintText,\n optional: this._optional,\n shortDesc: this._shortDesc,\n items: this._items,\n content: this._content\n }\n }\n\n /**\n * @param {string} _value\n */\n setPreviewHTML(_value) {\n // Not implemented for server side render\n }\n\n /**\n * @param {HTMLElement} _value\n */\n setPreviewDOM(_value) {\n // Not implemented for server side render\n }\n}\n\n/**\n * @implements {AutocompleteElements}\n */\nexport class AutocompletePreviewElements extends QuestionPreviewElements {\n /**\n * @param {BaseSettings & {autocompleteOptions: string}} elements\n */\n constructor({ autocompleteOptions, ...elements }) {\n super(elements)\n this.autocompleteOptions = autocompleteOptions\n }\n}\n\n/**\n * @implements {PageOverviewElements}\n */\nexport class PagePreviewElements {\n guidance\n heading\n addHeading\n\n /**\n * @param {string} heading\n * @param {string} guidance\n * @param {boolean} [addHeading]\n */\n constructor(heading, guidance = '', addHeading = undefined) {\n this.heading = heading\n this.guidance = guidance\n this.addHeading = addHeading ?? heading.length > 0\n }\n}\n\nexport const baseElements = /** @type {BaseSettings} */ ({\n items: [],\n optional: false,\n question: 'Which quest would you like to pick?',\n hintText: 'Choose one adventure that best suits you.',\n shortDesc: '',\n content: '',\n largeTitle: true\n})\n\nconst list1Id = '414d82a3-4cab-416a-bd54-6b86fbd51120'\nconst list2Id = '801385a4-81e6-4171-96c3-6c6727d97f22'\nconst list3Id = 'e6e3f621-b875-4ca3-a054-cca9149149dd'\nconst list4Id = 'd71b3909-582f-4e90-b6f5-490b89a6eb8f'\n\nconst listElementsBase = /** @type {BaseSettings} */ ({\n ...baseElements,\n items: [\n {\n label: { text: 'Treasure Hunting' },\n text: 'Treasure Hunting',\n value: 'Treasure Hunting',\n id: list1Id\n },\n {\n label: { text: 'Rescuing the princess' },\n text: 'Rescuing the princess',\n value: 'Rescuing the princess',\n id: list2Id\n },\n {\n label: { text: 'Saving a city' },\n text: 'Saving a city',\n value: 'Saving a city',\n id: list3Id\n },\n {\n label: { text: 'Defeating the baron' },\n text: 'Defeating the baron',\n value: 'Defeating the baron',\n id: list4Id\n }\n ]\n})\n\nexport const listElementsStub = {\n list1Id,\n list2Id,\n list3Id,\n list4Id,\n baseElements: listElementsBase\n}\n\n/**\n * @param {Partial<BaseSettings>} partialBaseElements\n * @param {jest.Mock<void, [string, QuestionBaseModel]>} renderMock\n * @returns {Question}\n */\nexport function buildPreviewShortAnswer(partialBaseElements, renderMock) {\n return new Question(\n new QuestionPreviewElements({\n ...baseElements,\n ...partialBaseElements\n }),\n new QuestionRendererStub(renderMock)\n )\n}\n\n/**\n * @import { ListElement } from '~/src/form/form-editor/types.js'\n * @import { PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n * @import { BaseSettings, ListElements, RenderContext, QuestionBaseModel, QuestionElements, QuestionRenderer, AutocompleteElements, PageOverviewElements, PageRenderer } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,QAAQ;;AAEjB;AACA;AACA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BAAuBA,CAACC,mBAAmB,EAAEnD,UAAU,EAAE;EACvE,OAAO,IAAIF,QAAQ,CACjB,IAAIa,uBAAuB,CAAC;IAC1B,GAAG2B,YAAY;IACf,GAAGa;EACL,CAAC,CAAC,EACF,IAAIpD,oBAAoB,CAACC,UAAU,CACrC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/macros/types.ts"],"sourcesContent":["import { type ComponentType } from '~/src/components/enums.js'\nimport {\n type DateItem,\n type GovukField,\n type ListItemReadonly\n} from '~/src/form/form-editor/types.js'\nimport { type DefaultComponent, type GovukFieldset } from '~/src/index.js'\n\nexport interface AppPreviewErrorPanelMacroErrorTemplate {\n advancedSettingsErrors: []\n baseErrors: { template: unknown; type: string }[]\n}\n\nexport interface AppPreviewErrorPanelMacro {\n errorTemplates: AppPreviewErrorPanelMacroErrorTemplate\n fieldDetails: {\n extraFields: GovukField[]\n basePageFields: GovukField[]\n }\n questionType: ComponentType\n}\n\nexport interface AppPreviewPanelTabsMacro {\n questionType: ComponentType\n previewPageUrl: string\n previewErrorsUrl: string\n errorTemplates: AppPreviewErrorPanelMacroErrorTemplate\n extraFields: GovukField[]\n basePageFields: GovukField[]\n}\n\nexport interface QuestionBaseModel {\n id?: string\n name?: string\n content?: string\n label?: DefaultComponent\n hint?: DefaultComponent\n fieldset?: GovukFieldset\n readonly items?: ListItemReadonly[] | DateItem[]\n text?: string\n formGroup?: { afterInputs: { html: string } }\n type?: 'text' | 'number' | 'boolean'\n classes?: string\n}\n\nexport interface AppPreviewPanelMacro extends AppPreviewPanelTabsMacro {\n model: QuestionBaseModel\n}\n\nexport interface PagePreviewComponent {\n model: QuestionBaseModel\n questionType: ComponentType\n}\n\nexport interface PagePreviewPanelMacro {\n readonly pageTitle: {\n text: string\n classes: string\n }\n readonly guidance: {\n text: string\n classes: string\n }\n readonly components: PagePreviewComponent[]\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/macros/types.ts"],"sourcesContent":["import { type ComponentType } from '~/src/components/enums.js'\nimport {\n type DateItem,\n type GovukField,\n type ListItemReadonly\n} from '~/src/form/form-editor/types.js'\nimport { type DefaultComponent, type GovukFieldset } from '~/src/index.js'\n\nexport interface AppPreviewErrorPanelMacroErrorTemplate {\n advancedSettingsErrors: []\n baseErrors: { template: unknown; type: string }[]\n}\n\nexport interface AppPreviewErrorPanelMacro {\n errorTemplates: AppPreviewErrorPanelMacroErrorTemplate\n fieldDetails: {\n extraFields: GovukField[]\n basePageFields: GovukField[]\n }\n questionType: ComponentType\n}\n\nexport interface AppPreviewPanelTabsMacro {\n questionType: ComponentType\n previewPageUrl: string\n previewErrorsUrl: string\n errorTemplates: AppPreviewErrorPanelMacroErrorTemplate\n extraFields: GovukField[]\n basePageFields: GovukField[]\n}\n\nexport interface SelectAfterInput {\n afterInput: { html: string }\n}\nexport interface RadioAndCheckboxAfterInputs {\n afterInputs: { html: string }\n}\n\n// GDS components - Select uses afterInput, while Radio uses afterInputs\nexport type FormGroupAfterInput = SelectAfterInput | RadioAndCheckboxAfterInputs\n\nexport interface QuestionBaseModel {\n id?: string\n name?: string\n content?: string\n attributes?: Record<string, string>\n label?: DefaultComponent\n hint?: DefaultComponent\n fieldset?: GovukFieldset\n readonly items?: ListItemReadonly[] | DateItem[]\n text?: string\n formGroup?: FormGroupAfterInput\n type?: 'text' | 'number' | 'boolean'\n classes?: string\n}\n\nexport interface AppPreviewPanelMacro extends AppPreviewPanelTabsMacro {\n model: QuestionBaseModel\n}\n\nexport interface PagePreviewComponent {\n model: QuestionBaseModel\n questionType: ComponentType\n}\n\nexport interface PagePreviewPanelMacro {\n readonly pageTitle: {\n text: string\n classes: string\n }\n readonly guidance: {\n text: string\n classes: string\n }\n readonly components: PagePreviewComponent[]\n}\n"],"mappings":"","ignoreList":[]}
@@ -19,6 +19,9 @@ export class AutocompleteListQuestion extends Question {
19
19
  */
20
20
  get customRenderFields() {
21
21
  return {
22
+ attributes: {
23
+ 'data-module': 'govuk-accessible-autocomplete'
24
+ },
22
25
  items: this._htmlElements.values.items
23
26
  };
24
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"autocomplete.js","names":["ComponentType","autoCompleteOptionsSchema","PreviewComponent","Question","AutocompleteListQuestion","componentType","AutocompleteField","_questionTemplate","PATH","_fieldName","customRenderFields","items","_htmlElements","values","AutocompleteQuestion","_autocompleteList","constructor","autocompleteElements","questionRenderer","setAutocompleteList","autocompleteOptions","autoCompleteList","id","value","text","listHTML","validationResult","validate","error","map","render","renderInput","name","attributes","hint","label"],"sources":["../../../../../src/form/form-editor/preview/autocomplete.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { autoCompleteOptionsSchema } from '~/src/form/form-editor/index.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport { Question } from '~/src/form/form-editor/preview/question.js'\n\nexport class AutocompleteListQuestion extends Question {\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.AutocompleteField\n _questionTemplate = PreviewComponent.PATH + 'autocompletefield.njk'\n /**\n * @type {string}\n * @protected\n */\n _fieldName = 'autoCompleteField'\n\n /**\n * @returns {Partial<QuestionBaseModel>}\n */\n get customRenderFields() {\n return {\n items: this._htmlElements.values.items\n }\n }\n}\n\nexport class AutocompleteQuestion extends AutocompleteListQuestion {\n /**\n * @type {ListElement[]}\n * @private\n */\n _autocompleteList = []\n /**\n * @param {AutocompleteElements} autocompleteElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(autocompleteElements, questionRenderer) {\n super(autocompleteElements, questionRenderer)\n this.setAutocompleteList(autocompleteElements.autocompleteOptions)\n }\n\n get autoCompleteList() {\n return [{ id: '', value: '', text: '' }, ...this._autocompleteList]\n }\n\n /**\n * @param {string} listHTML\n */\n setAutocompleteList(listHTML) {\n const validationResult =\n /** @type {ValidationResult<{text: string, value: string}[]>} */ (\n autoCompleteOptionsSchema.validate(listHTML)\n )\n\n if (!validationResult.error) {\n this._autocompleteList = validationResult.value.map(\n ({ text, value }) => ({\n id: text,\n text,\n value\n })\n )\n this.render()\n }\n }\n\n get renderInput() {\n return {\n id: this._fieldName,\n name: this._fieldName,\n attributes: { 'data-module': 'govuk-accessible-autocomplete' },\n hint: this.hint,\n label: this.label,\n items: this.autoCompleteList\n }\n }\n}\n\n/**\n * @import { ValidationResult } from 'joi'\n * @import { ListElement } from '~/src/form/form-editor/types.js'\n * @import { AutocompleteElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,yBAAyB;AAClC,SAASC,gBAAgB;AACzB,SAASC,QAAQ;AAEjB,OAAO,MAAMC,wBAAwB,SAASD,QAAQ,CAAC;EACrD;AACF;AACA;EACEE,aAAa,GAAGL,aAAa,CAACM,iBAAiB;EAC/CC,iBAAiB,GAAGL,gBAAgB,CAACM,IAAI,GAAG,uBAAuB;EACnE;AACF;AACA;AACA;EACEC,UAAU,GAAG,mBAAmB;;EAEhC;AACF;AACA;EACE,IAAIC,kBAAkBA,CAAA,EAAG;IACvB,OAAO;MACLC,KAAK,EAAE,IAAI,CAACC,aAAa,CAACC,MAAM,CAACF;IACnC,CAAC;EACH;AACF;AAEA,OAAO,MAAMG,oBAAoB,SAASV,wBAAwB,CAAC;EACjE;AACF;AACA;AACA;EACEW,iBAAiB,GAAG,EAAE;EACtB;AACF;AACA;AACA;EACEC,WAAWA,CAACC,oBAAoB,EAAEC,gBAAgB,EAAE;IAClD,KAAK,CAACD,oBAAoB,EAAEC,gBAAgB,CAAC;IAC7C,IAAI,CAACC,mBAAmB,CAACF,oBAAoB,CAACG,mBAAmB,CAAC;EACpE;EAEA,IAAIC,gBAAgBA,CAAA,EAAG;IACrB,OAAO,CAAC;MAAEC,EAAE,EAAE,EAAE;MAAEC,KAAK,EAAE,EAAE;MAAEC,IAAI,EAAE;IAAG,CAAC,EAAE,GAAG,IAAI,CAACT,iBAAiB,CAAC;EACrE;;EAEA;AACF;AACA;EACEI,mBAAmBA,CAACM,QAAQ,EAAE;IAC5B,MAAMC,gBAAgB,GACpB;IACEzB,yBAAyB,CAAC0B,QAAQ,CAACF,QAAQ,CAC5C;IAEH,IAAI,CAACC,gBAAgB,CAACE,KAAK,EAAE;MAC3B,IAAI,CAACb,iBAAiB,GAAGW,gBAAgB,CAACH,KAAK,CAACM,GAAG,CACjD,CAAC;QAAEL,IAAI;QAAED;MAAM,CAAC,MAAM;QACpBD,EAAE,EAAEE,IAAI;QACRA,IAAI;QACJD;MACF,CAAC,CACH,CAAC;MACD,IAAI,CAACO,MAAM,CAAC,CAAC;IACf;EACF;EAEA,IAAIC,WAAWA,CAAA,EAAG;IAChB,OAAO;MACLT,EAAE,EAAE,IAAI,CAACb,UAAU;MACnBuB,IAAI,EAAE,IAAI,CAACvB,UAAU;MACrBwB,UAAU,EAAE;QAAE,aAAa,EAAE;MAAgC,CAAC;MAC9DC,IAAI,EAAE,IAAI,CAACA,IAAI;MACfC,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBxB,KAAK,EAAE,IAAI,CAACU;IACd,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"autocomplete.js","names":["ComponentType","autoCompleteOptionsSchema","PreviewComponent","Question","AutocompleteListQuestion","componentType","AutocompleteField","_questionTemplate","PATH","_fieldName","customRenderFields","attributes","items","_htmlElements","values","AutocompleteQuestion","_autocompleteList","constructor","autocompleteElements","questionRenderer","setAutocompleteList","autocompleteOptions","autoCompleteList","id","value","text","listHTML","validationResult","validate","error","map","render","renderInput","name","hint","label"],"sources":["../../../../../src/form/form-editor/preview/autocomplete.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { autoCompleteOptionsSchema } from '~/src/form/form-editor/index.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport { Question } from '~/src/form/form-editor/preview/question.js'\n\nexport class AutocompleteListQuestion extends Question {\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.AutocompleteField\n _questionTemplate = PreviewComponent.PATH + 'autocompletefield.njk'\n /**\n * @type {string}\n * @protected\n */\n _fieldName = 'autoCompleteField'\n\n /**\n * @returns {Partial<QuestionBaseModel>}\n */\n get customRenderFields() {\n return {\n attributes: { 'data-module': 'govuk-accessible-autocomplete' },\n items: this._htmlElements.values.items\n }\n }\n}\n\nexport class AutocompleteQuestion extends AutocompleteListQuestion {\n /**\n * @type {ListElement[]}\n * @private\n */\n _autocompleteList = []\n /**\n * @param {AutocompleteElements} autocompleteElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(autocompleteElements, questionRenderer) {\n super(autocompleteElements, questionRenderer)\n this.setAutocompleteList(autocompleteElements.autocompleteOptions)\n }\n\n get autoCompleteList() {\n return [{ id: '', value: '', text: '' }, ...this._autocompleteList]\n }\n\n /**\n * @param {string} listHTML\n */\n setAutocompleteList(listHTML) {\n const validationResult =\n /** @type {ValidationResult<{text: string, value: string}[]>} */ (\n autoCompleteOptionsSchema.validate(listHTML)\n )\n\n if (!validationResult.error) {\n this._autocompleteList = validationResult.value.map(\n ({ text, value }) => ({\n id: text,\n text,\n value\n })\n )\n this.render()\n }\n }\n\n get renderInput() {\n return {\n id: this._fieldName,\n name: this._fieldName,\n attributes: { 'data-module': 'govuk-accessible-autocomplete' },\n hint: this.hint,\n label: this.label,\n items: this.autoCompleteList\n }\n }\n}\n\n/**\n * @import { ValidationResult } from 'joi'\n * @import { ListElement } from '~/src/form/form-editor/types.js'\n * @import { AutocompleteElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,yBAAyB;AAClC,SAASC,gBAAgB;AACzB,SAASC,QAAQ;AAEjB,OAAO,MAAMC,wBAAwB,SAASD,QAAQ,CAAC;EACrD;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CAAA,EAAG;IAChB,OAAO;MACLT,EAAE,EAAE,IAAI,CAACd,UAAU;MACnBwB,IAAI,EAAE,IAAI,CAACxB,UAAU;MACrBE,UAAU,EAAE;QAAE,aAAa,EAAE;MAAgC,CAAC;MAC9DuB,IAAI,EAAE,IAAI,CAACA,IAAI;MACfC,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBvB,KAAK,EAAE,IAAI,CAACU;IACd,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -7,18 +7,11 @@ export class ComponentElements {
7
7
  * @protected
8
8
  */
9
9
  _component;
10
- /**
11
- * @type {boolean}
12
- * @private
13
- */
14
- _largeTitle = true;
15
10
  /**
16
11
  * @param {ComponentDef} component
17
- * @param {boolean} [largeTitle]
18
12
  */
19
- constructor(component, largeTitle = true) {
13
+ constructor(component) {
20
14
  this._component = component;
21
- this._largeTitle = largeTitle;
22
15
  }
23
16
 
24
17
  /**
@@ -33,8 +26,7 @@ export class ComponentElements {
33
26
  optional: !required,
34
27
  shortDesc: '',
35
28
  items: [],
36
- content: '',
37
- largeTitle: this._largeTitle
29
+ content: ''
38
30
  };
39
31
  }
40
32
 
@@ -1 +1 @@
1
- {"version":3,"file":"component-elements.js","names":["ComponentElements","_component","_largeTitle","constructor","component","largeTitle","_getValues","required","options","question","title","hintText","optional","shortDesc","items","content","values","setPreviewDOM","_element","Error","setPreviewHTML","_value"],"sources":["../../../../../src/form/form-editor/preview/component-elements.js"],"sourcesContent":["/**\n * @implements {QuestionElements}\n */\nexport class ComponentElements {\n /**\n * @type {ComponentDef}\n * @protected\n */\n _component\n /**\n * @type {boolean}\n * @private\n */\n _largeTitle = true\n /**\n * @param {ComponentDef} component\n * @param {boolean} [largeTitle]\n */\n constructor(component, largeTitle = true) {\n this._component = component\n this._largeTitle = largeTitle\n }\n\n /**\n * @protected\n * @returns {BaseSettings}\n */\n _getValues() {\n const required = this._component.options?.required ?? true\n\n return {\n question: this._component.title,\n hintText: '',\n optional: !required,\n shortDesc: '',\n items: [],\n content: '',\n largeTitle: this._largeTitle\n }\n }\n\n /**\n * @returns {BaseSettings}\n */\n get values() {\n const values = this._getValues()\n return values\n }\n\n /**\n * @param {HTMLElement} _element\n */\n setPreviewDOM(_element) {\n throw new Error('Not implemented')\n }\n\n /**\n * @param {string} _value\n */\n setPreviewHTML(_value) {\n throw new Error('Not implemented')\n }\n}\n\n/**\n * @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { FormComponentsDef, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n */\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,MAAMA,iBAAiB,CAAC;EAC7B;AACF;AACA;AACA;EACEC,UAAU;EACV;AACF;AACA;AACA;EACEC,WAAW,GAAG,IAAI;EAClB;AACF;AACA;AACA;EACEC,WAAWA,CAACC,SAAS,EAAEC,UAAU,GAAG,IAAI,EAAE;IACxC,IAAI,CAACJ,UAAU,GAAGG,SAAS;IAC3B,IAAI,CAACF,WAAW,GAAGG,UAAU;EAC/B;;EAEA;AACF;AACA;AACA;EACEC,UAAUA,CAAA,EAAG;IACX,MAAMC,QAAQ,GAAG,IAAI,CAACN,UAAU,CAACO,OAAO,EAAED,QAAQ,IAAI,IAAI;IAE1D,OAAO;MACLE,QAAQ,EAAE,IAAI,CAACR,UAAU,CAACS,KAAK;MAC/BC,QAAQ,EAAE,EAAE;MACZC,QAAQ,EAAE,CAACL,QAAQ;MACnBM,SAAS,EAAE,EAAE;MACbC,KAAK,EAAE,EAAE;MACTC,OAAO,EAAE,EAAE;MACXV,UAAU,EAAE,IAAI,CAACH;IACnB,CAAC;EACH;;EAEA;AACF;AACA;EACE,IAAIc,MAAMA,CAAA,EAAG;IACX,MAAMA,MAAM,GAAG,IAAI,CAACV,UAAU,CAAC,CAAC;IAChC,OAAOU,MAAM;EACf;;EAEA;AACF;AACA;EACEC,aAAaA,CAACC,QAAQ,EAAE;IACtB,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;EACpC;;EAEA;AACF;AACA;EACEC,cAAcA,CAACC,MAAM,EAAE;IACrB,MAAM,IAAIF,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"component-elements.js","names":["ComponentElements","_component","constructor","component","_getValues","required","options","question","title","hintText","optional","shortDesc","items","content","values","setPreviewDOM","_element","Error","setPreviewHTML","_value"],"sources":["../../../../../src/form/form-editor/preview/component-elements.js"],"sourcesContent":["/**\n * @implements {QuestionElements}\n */\nexport class ComponentElements {\n /**\n * @type {ComponentDef}\n * @protected\n */\n _component\n /**\n * @param {ComponentDef} component\n */\n constructor(component) {\n this._component = component\n }\n\n /**\n * @protected\n * @returns {BaseSettings}\n */\n _getValues() {\n const required = this._component.options?.required ?? true\n\n return {\n question: this._component.title,\n hintText: '',\n optional: !required,\n shortDesc: '',\n items: [],\n content: ''\n }\n }\n\n /**\n * @returns {BaseSettings}\n */\n get values() {\n const values = this._getValues()\n return values\n }\n\n /**\n * @param {HTMLElement} _element\n */\n setPreviewDOM(_element) {\n throw new Error('Not implemented')\n }\n\n /**\n * @param {string} _value\n */\n setPreviewHTML(_value) {\n throw new Error('Not implemented')\n }\n}\n\n/**\n * @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { FormComponentsDef, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n */\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,MAAMA,iBAAiB,CAAC;EAC7B;AACF;AACA;AACA;EACEC,UAAU;EACV;AACF;AACA;EACEC,WAAWA,CAACC,SAAS,EAAE;IACrB,IAAI,CAACF,UAAU,GAAGE,SAAS;EAC7B;;EAEA;AACF;AACA;AACA;EACEC,UAAUA,CAAA,EAAG;IACX,MAAMC,QAAQ,GAAG,IAAI,CAACJ,UAAU,CAACK,OAAO,EAAED,QAAQ,IAAI,IAAI;IAE1D,OAAO;MACLE,QAAQ,EAAE,IAAI,CAACN,UAAU,CAACO,KAAK;MAC/BC,QAAQ,EAAE,EAAE;MACZC,QAAQ,EAAE,CAACL,QAAQ;MACnBM,SAAS,EAAE,EAAE;MACbC,KAAK,EAAE,EAAE;MACTC,OAAO,EAAE;IACX,CAAC;EACH;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAAG;IACX,MAAMA,MAAM,GAAG,IAAI,CAACV,UAAU,CAAC,CAAC;IAChC,OAAOU,MAAM;EACf;;EAEA;AACF;AACA;EACEC,aAAaA,CAACC,QAAQ,EAAE;IACtB,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;EACpC;;EAEA;AACF;AACA;EACEC,cAAcA,CAACC,MAAM,EAAE;IACrB,MAAM,IAAIF,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -12,10 +12,9 @@ export class ContentElements extends ComponentElements {
12
12
  _component;
13
13
  /**
14
14
  * @param {Exclude<ContentComponentsDef, ListComponent>} component
15
- * @param {boolean} largeTitle
16
15
  */
17
- constructor(component, largeTitle = true) {
18
- super(component, largeTitle);
16
+ constructor(component) {
17
+ super(component);
19
18
  this._component = component;
20
19
  }
21
20
 
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","names":["ComponentElements","PreviewComponent","ContentElements","_component","constructor","component","largeTitle","_getValues","content","Content","_content","htmlElements","questionRenderer","values","_renderInput","_setContent","value","render"],"sources":["../../../../../src/form/form-editor/preview/content.js"],"sourcesContent":["import { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n\n/**\n * @implements {QuestionElements}\n */\nexport class ContentElements extends ComponentElements {\n /**\n * @type {Exclude<ContentComponentsDef, ListComponent>}\n * @protected\n */\n _component\n /**\n * @param {Exclude<ContentComponentsDef, ListComponent>} component\n * @param {boolean} largeTitle\n */\n constructor(component, largeTitle = true) {\n super(component, largeTitle)\n this._component = component\n }\n\n /**\n * @protected\n * @returns {BaseSettings}\n */\n _getValues() {\n return {\n ...super._getValues(),\n content: this._component.content\n }\n }\n}\n\n/**\n * @abstract\n * @class Content\n * @classdesc\n * Base of Content preview classes\n */\nexport class Content extends PreviewComponent {\n /**\n * @type {string}\n * @protected\n */\n _content\n\n /**\n * @param {QuestionElements} htmlElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(htmlElements, questionRenderer) {\n super(htmlElements, questionRenderer)\n const { content } = htmlElements.values\n\n this._content = content\n }\n\n /**\n * @returns {QuestionBaseModel}\n * @protected\n */\n _renderInput() {\n return {\n ...super._renderInput(),\n content: this.content\n }\n }\n\n /**\n * @param {string} value\n * @protected\n */\n _setContent(value) {\n this._content = value\n }\n\n /**\n * @returns {string}\n */\n get content() {\n return this._content\n }\n\n set content(value) {\n this._setContent(value)\n this.render()\n }\n}\n\n/**\n * @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { FormComponentsDef, ListComponent, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n */\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,gBAAgB;;AAEzB;AACA;AACA;AACA,OAAO,MAAMC,eAAe,SAASF,iBAAiB,CAAC;EACrD;AACF;AACA;AACA;EACEG,UAAU;EACV;AACF;AACA;AACA;EACEC,WAAWA,CAACC,SAAS,EAAEC,UAAU,GAAG,IAAI,EAAE;IACxC,KAAK,CAACD,SAAS,EAAEC,UAAU,CAAC;IAC5B,IAAI,CAACH,UAAU,GAAGE,SAAS;EAC7B;;EAEA;AACF;AACA;AACA;EACEE,UAAUA,CAAA,EAAG;IACX,OAAO;MACL,GAAG,KAAK,CAACA,UAAU,CAAC,CAAC;MACrBC,OAAO,EAAE,IAAI,CAACL,UAAU,CAACK;IAC3B,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,SAASR,gBAAgB,CAAC;EAC5C;AACF;AACA;AACA;EACES,QAAQ;;EAER;AACF;AACA;AACA;EACEN,WAAWA,CAACO,YAAY,EAAEC,gBAAgB,EAAE;IAC1C,KAAK,CAACD,YAAY,EAAEC,gBAAgB,CAAC;IACrC,MAAM;MAAEJ;IAAQ,CAAC,GAAGG,YAAY,CAACE,MAAM;IAEvC,IAAI,CAACH,QAAQ,GAAGF,OAAO;EACzB;;EAEA;AACF;AACA;AACA;EACEM,YAAYA,CAAA,EAAG;IACb,OAAO;MACL,GAAG,KAAK,CAACA,YAAY,CAAC,CAAC;MACvBN,OAAO,EAAE,IAAI,CAACA;IAChB,CAAC;EACH;;EAEA;AACF;AACA;AACA;EACEO,WAAWA,CAACC,KAAK,EAAE;IACjB,IAAI,CAACN,QAAQ,GAAGM,KAAK;EACvB;;EAEA;AACF;AACA;EACE,IAAIR,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACE,QAAQ;EACtB;EAEA,IAAIF,OAAOA,CAACQ,KAAK,EAAE;IACjB,IAAI,CAACD,WAAW,CAACC,KAAK,CAAC;IACvB,IAAI,CAACC,MAAM,CAAC,CAAC;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"content.js","names":["ComponentElements","PreviewComponent","ContentElements","_component","constructor","component","_getValues","content","Content","_content","htmlElements","questionRenderer","values","_renderInput","_setContent","value","render"],"sources":["../../../../../src/form/form-editor/preview/content.js"],"sourcesContent":["import { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n\n/**\n * @implements {QuestionElements}\n */\nexport class ContentElements extends ComponentElements {\n /**\n * @type {Exclude<ContentComponentsDef, ListComponent>}\n * @protected\n */\n _component\n /**\n * @param {Exclude<ContentComponentsDef, ListComponent>} component\n */\n constructor(component) {\n super(component)\n this._component = component\n }\n\n /**\n * @protected\n * @returns {BaseSettings}\n */\n _getValues() {\n return {\n ...super._getValues(),\n content: this._component.content\n }\n }\n}\n\n/**\n * @abstract\n * @class Content\n * @classdesc\n * Base of Content preview classes\n */\nexport class Content extends PreviewComponent {\n /**\n * @type {string}\n * @protected\n */\n _content\n\n /**\n * @param {QuestionElements} htmlElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(htmlElements, questionRenderer) {\n super(htmlElements, questionRenderer)\n const { content } = htmlElements.values\n\n this._content = content\n }\n\n /**\n * @returns {QuestionBaseModel}\n * @protected\n */\n _renderInput() {\n return {\n ...super._renderInput(),\n content: this.content\n }\n }\n\n /**\n * @param {string} value\n * @protected\n */\n _setContent(value) {\n this._content = value\n }\n\n /**\n * @returns {string}\n */\n get content() {\n return this._content\n }\n\n set content(value) {\n this._setContent(value)\n this.render()\n }\n}\n\n/**\n * @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { FormComponentsDef, ListComponent, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n */\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,gBAAgB;;AAEzB;AACA;AACA;AACA,OAAO,MAAMC,eAAe,SAASF,iBAAiB,CAAC;EACrD;AACF;AACA;AACA;EACEG,UAAU;EACV;AACF;AACA;EACEC,WAAWA,CAACC,SAAS,EAAE;IACrB,KAAK,CAACA,SAAS,CAAC;IAChB,IAAI,CAACF,UAAU,GAAGE,SAAS;EAC7B;;EAEA;AACF;AACA;AACA;EACEC,UAAUA,CAAA,EAAG;IACX,OAAO;MACL,GAAG,KAAK,CAACA,UAAU,CAAC,CAAC;MACrBC,OAAO,EAAE,IAAI,CAACJ,UAAU,CAACI;IAC3B,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,SAASP,gBAAgB,CAAC;EAC5C;AACF;AACA;AACA;EACEQ,QAAQ;;EAER;AACF;AACA;AACA;EACEL,WAAWA,CAACM,YAAY,EAAEC,gBAAgB,EAAE;IAC1C,KAAK,CAACD,YAAY,EAAEC,gBAAgB,CAAC;IACrC,MAAM;MAAEJ;IAAQ,CAAC,GAAGG,YAAY,CAACE,MAAM;IAEvC,IAAI,CAACH,QAAQ,GAAGF,OAAO;EACzB;;EAEA;AACF;AACA;AACA;EACEM,YAAYA,CAAA,EAAG;IACb,OAAO;MACL,GAAG,KAAK,CAACA,YAAY,CAAC,CAAC;MACvBN,OAAO,EAAE,IAAI,CAACA;IAChB,CAAC;EACH;;EAEA;AACF;AACA;AACA;EACEO,WAAWA,CAACC,KAAK,EAAE;IACjB,IAAI,CAACN,QAAQ,GAAGM,KAAK;EACvB;;EAEA;AACF;AACA;EACE,IAAIR,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACE,QAAQ;EACtB;EAEA,IAAIF,OAAOA,CAACQ,KAAK,EAAE;IACjB,IAAI,CAACD,WAAW,CAACC,KAAK,CAAC;IACvB,IAAI,CAACC,MAAM,CAAC,CAAC;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -26,6 +26,7 @@ export class PagePreviewElements {
26
26
  * @private
27
27
  */
28
28
  _page;
29
+
29
30
  /**
30
31
  * @param {Page} page
31
32
  */
@@ -42,6 +43,9 @@ export class PagePreviewElements {
42
43
  const [possibleGuidanceComponent] = this._page.components;
43
44
  return possibleGuidanceComponent.type === ComponentType.Markdown ? possibleGuidanceComponent.content : '';
44
45
  }
46
+ get addHeading() {
47
+ return this._page.title.length > 0;
48
+ }
45
49
  }
46
50
 
47
51
  /**
@@ -89,6 +93,11 @@ export class PreviewPageController {
89
93
  * @protected
90
94
  */
91
95
  _guidanceComponent;
96
+ /**
97
+ * @type {boolean}
98
+ * @private
99
+ */
100
+ _showTitle = true;
92
101
  /**
93
102
  * @param {ComponentDef[]} components
94
103
  * @param {PageOverviewElements} elements
@@ -96,12 +105,13 @@ export class PreviewPageController {
96
105
  * @param {PageRenderer} renderer
97
106
  */
98
107
  constructor(components, elements, definition, renderer) {
99
- const questions = components.map(mapComponentToPreviewQuestion(questionRenderer, definition, elements.heading.length > 0));
108
+ const questions = components.map(mapComponentToPreviewQuestion(questionRenderer, definition));
100
109
  const firstQuestion = /** @type { Markdown | undefined | Question } */
101
110
  questions.shift();
102
111
  this._guidanceComponent = PreviewPageController.getOrCreateGuidanceComponent(firstQuestion);
103
112
  this._guidanceText = elements.guidance;
104
113
  this._components = this.#constructComponents(firstQuestion, questions);
114
+ this._showTitle = elements.addHeading;
105
115
  this.#pageRenderer = renderer;
106
116
  this.#title = elements.heading;
107
117
  }
@@ -134,10 +144,56 @@ export class PreviewPageController {
134
144
  */
135
145
  get components() {
136
146
  const componentsWithGuidance = /** @type {Question[]} */[...this._guidanceComponents, ...this._components];
137
- return componentsWithGuidance.map(component => ({
138
- model: component.renderInput,
139
- questionType: component.componentType
140
- }));
147
+ return componentsWithGuidance.map(component => {
148
+ return {
149
+ model: this._overrideComponentHeading(component),
150
+ questionType: component.componentType
151
+ };
152
+ });
153
+ }
154
+
155
+ /**
156
+ * @returns {boolean}
157
+ */
158
+ get showLargeTitle() {
159
+ const componentsLength = this._components.length + this._guidanceComponents.length;
160
+ if (componentsLength > 1 || this._highlighted === 'title') {
161
+ return false;
162
+ }
163
+ // |_ one component and title not highlighted
164
+ if (this.#title.trim() === this._components[0].question.trim()) {
165
+ return true;
166
+ }
167
+ // titles not the same
168
+
169
+ return !this._showTitle; // add page heading deselected?
170
+ }
171
+
172
+ /**
173
+ * @param {PreviewComponent} component
174
+ * @returns {QuestionBaseModel}
175
+ */
176
+ _overrideComponentHeading(component) {
177
+ const largeTitle = this.showLargeTitle;
178
+ const fieldset = component.renderInput.fieldset ? {
179
+ fieldset: {
180
+ legend: {
181
+ ...component.renderInput.fieldset.legend,
182
+ classes: largeTitle ? 'govuk-fieldset__legend--l' : 'govuk-fieldset__legend--m'
183
+ }
184
+ }
185
+ } : {};
186
+ const label = component.renderInput.label ? {
187
+ label: {
188
+ ...component.renderInput.label,
189
+ classes: largeTitle ? 'govuk-label--l' : 'govuk-label--m'
190
+ }
191
+ } : {};
192
+ return {
193
+ ...component.renderInput,
194
+ ...fieldset,
195
+ ...label
196
+ };
141
197
  }
142
198
  set guidanceText(text) {
143
199
  this._guidanceText = text;
@@ -145,8 +201,23 @@ export class PreviewPageController {
145
201
  this.render();
146
202
  }
147
203
  get guidanceText() {
204
+ if (!this._showTitle) {
205
+ return '';
206
+ }
148
207
  return this._guidanceText;
149
208
  }
209
+
210
+ /**
211
+ *
212
+ * @param {boolean} showTitle
213
+ */
214
+ set showTitle(showTitle) {
215
+ this._showTitle = showTitle;
216
+ this.render();
217
+ }
218
+ get showTitle() {
219
+ return this._showTitle;
220
+ }
150
221
  get guidance() {
151
222
  return {
152
223
  text: this.guidanceText,
@@ -167,11 +238,24 @@ export class PreviewPageController {
167
238
  this.#pageRenderer.render(this._pageTemplate, this);
168
239
  }
169
240
 
241
+ /**
242
+ * @returns {boolean}
243
+ */
244
+ get titleAndFirstTitleSame() {
245
+ return this._components.length > 0 && this.#title.trim() === this._components[0].question.trim() && this.components.length === 1 && this._highlighted !== 'title';
246
+ }
247
+
170
248
  /**
171
249
  * @returns {string}
172
250
  */
173
251
  get title() {
174
- return this.#title;
252
+ if (!this._showTitle || this.titleAndFirstTitleSame) {
253
+ return '';
254
+ }
255
+ if (this.#title.length) {
256
+ return this.#title;
257
+ }
258
+ return 'Page heading';
175
259
  }
176
260
 
177
261
  /**
@@ -239,6 +323,7 @@ export class PreviewPageController {
239
323
  /**
240
324
  * @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'
241
325
  * @import { Question } from '~/src/form/form-editor/preview/question.js'
326
+ * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
242
327
  * @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'
243
328
  * @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'
244
329
  * @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'
@@ -1 +1 @@
1
- {"version":3,"file":"page-controller.js","names":["ComponentType","HIGHLIGHT_CLASS","ContentElements","mapComponentToPreviewQuestion","Markdown","hasComponents","questionRenderer","render","_questionTemplate","_questionBaseModel","PagePreviewElements","_page","constructor","page","heading","title","guidance","components","length","possibleGuidanceComponent","type","content","PreviewPageController","PATH","_pageTemplate","_components","pageRenderer","_highlighted","undefined","_guidanceText","_emptyGuidance","createGuidanceComponent","_guidanceComponent","elements","definition","renderer","questions","map","firstQuestion","shift","getOrCreateGuidanceComponent","constructComponents","#constructComponents","_guidanceComponents","componentsWithGuidance","component","model","renderInput","questionType","componentType","guidanceText","text","classes","pageTitle","value","highlightTitle","setHighLighted","guidanceElement","name","options","guidanceComponent","highlightContent","highlightGuidance","highlightSection","clearHighlight","unHighlightContent"],"sources":["../../../../../../src/form/form-editor/preview/controller/page-controller.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n/**\n * @type {QuestionRenderer}\n */\nconst questionRenderer = {\n /**\n * @param {string} _questionTemplate\n * @param {QuestionBaseModel} _questionBaseModel\n */\n render(_questionTemplate, _questionBaseModel) {\n //\n }\n}\n\n/**\n * @implements {PageOverviewElements}\n */\nexport class PagePreviewElements {\n /**\n * @type {Page}\n * @private\n */\n _page\n /**\n * @param {Page} page\n */\n constructor(page) {\n this._page = page\n }\n\n get heading() {\n return this._page.title\n }\n\n get guidance() {\n if (!hasComponents(this._page) || !this._page.components.length) {\n return ''\n }\n\n const [possibleGuidanceComponent] = this._page.components\n\n return possibleGuidanceComponent.type === ComponentType.Markdown\n ? possibleGuidanceComponent.content\n : ''\n }\n}\n\n/**\n * @implements {PagePreviewPanelMacro}\n */\nexport class PreviewPageController {\n static PATH = 'preview-controllers/'\n /**\n * @type {string}\n * @protected\n */\n _pageTemplate = PreviewPageController.PATH + 'page-controller.njk'\n /**\n * @protected\n * @type {Question[]}\n */\n _components = []\n /**\n * @type {string}\n */\n #title = ''\n /**\n *\n * @type {PageRenderer}\n */\n #pageRenderer\n /**\n * @type { undefined | 'title' | 'guidance'}\n * @protected\n */\n _highlighted = undefined\n /**\n * @type {string}\n * @private\n */\n _guidanceText = ''\n /**\n * @type {Markdown}\n * @private\n */\n _emptyGuidance = PreviewPageController.createGuidanceComponent()\n /**\n *\n * @type {Markdown}\n * @protected\n */\n _guidanceComponent\n /**\n * @param {ComponentDef[]} components\n * @param {PageOverviewElements} elements\n * @param {FormDefinition} definition\n * @param {PageRenderer} renderer\n */\n constructor(components, elements, definition, renderer) {\n const questions = components.map(\n mapComponentToPreviewQuestion(\n questionRenderer,\n definition,\n elements.heading.length > 0\n )\n )\n const firstQuestion = /** @type { Markdown | undefined | Question } */ (\n questions.shift()\n )\n\n this._guidanceComponent =\n PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)\n this._guidanceText = elements.guidance\n this._components = this.#constructComponents(firstQuestion, questions)\n\n this.#pageRenderer = renderer\n this.#title = elements.heading\n }\n\n /**\n * @param { Question | Markdown | undefined} firstQuestion\n * @param {Question[]} questions\n * @returns {Question[]}\n */\n #constructComponents(firstQuestion, questions) {\n return firstQuestion instanceof Markdown || firstQuestion === undefined\n ? questions\n : [firstQuestion, ...questions]\n }\n\n /**\n * @returns {Markdown[]}\n * @private\n */\n get _guidanceComponents() {\n if (this._guidanceText.length) {\n return [this._guidanceComponent]\n }\n if (this._highlighted === 'guidance') {\n return [this._emptyGuidance]\n }\n return []\n }\n\n /**\n * @returns {PagePreviewComponent[]}\n */\n get components() {\n const componentsWithGuidance = /** @type {Question[]} */ ([\n ...this._guidanceComponents,\n ...this._components\n ])\n\n return componentsWithGuidance.map((component) => ({\n model: component.renderInput,\n questionType: component.componentType\n }))\n }\n\n set guidanceText(text) {\n this._guidanceText = text\n this._guidanceComponent.content = text\n this.render()\n }\n\n get guidanceText() {\n return this._guidanceText\n }\n\n get guidance() {\n return {\n text: this.guidanceText,\n classes: this._highlighted === 'guidance' ? 'highlight' : ''\n }\n }\n\n /**\n * @returns {{ text: string, classes: string }}\n */\n get pageTitle() {\n return {\n text: this.title,\n classes: this._highlighted === 'title' ? HIGHLIGHT_CLASS : ''\n }\n }\n\n render() {\n this.#pageRenderer.render(this._pageTemplate, this)\n }\n\n /**\n * @returns {string}\n */\n get title() {\n return this.#title\n }\n\n /**\n * @param {string} value\n */\n set title(value) {\n this.#title = value\n this.render()\n }\n\n highlightTitle() {\n this.setHighLighted('title')\n }\n\n /**\n * Creates a dummy component for when guidance is highlighted\n * but no guidance text exists\n * @returns {Markdown}\n */\n static createGuidanceComponent() {\n const guidanceElement = new ContentElements({\n type: ComponentType.Markdown,\n title: 'Guidance component',\n name: 'guidanceComponent',\n content: 'Guidance text',\n options: {}\n })\n const guidanceComponent = new Markdown(guidanceElement, questionRenderer)\n\n // the dummy component should always be highlighted\n guidanceComponent.highlightContent()\n return guidanceComponent\n }\n\n /**\n * Helper method to return the guidance or a new one\n * @param { Markdown | Question | undefined } guidanceComponent\n * @returns {Markdown}\n * @private\n */\n static getOrCreateGuidanceComponent(guidanceComponent) {\n if (guidanceComponent instanceof Markdown) {\n return guidanceComponent\n }\n return PreviewPageController.createGuidanceComponent()\n }\n\n highlightGuidance() {\n this._guidanceComponent.highlightContent()\n this.setHighLighted('guidance')\n }\n\n /**\n * @param {'title'|'guidance'} highlightSection\n */\n setHighLighted(highlightSection) {\n this._highlighted = highlightSection\n this.render()\n }\n\n clearHighlight() {\n this._highlighted = undefined\n\n this._guidanceComponent.unHighlightContent()\n this.render()\n }\n}\n\n/**\n * @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'\n * @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'\n * @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,eAAe;AACxB,SAASC,eAAe;AACxB,SAASC,6BAA6B;AACtC,SAASC,QAAQ;AACjB,SAASC,aAAa;AACtB;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG;EACvB;AACF;AACA;AACA;EACEC,MAAMA,CAACC,iBAAiB,EAAEC,kBAAkB,EAAE;IAC5C;EAAA;AAEJ,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAC/B;AACF;AACA;AACA;EACEC,KAAK;EACL;AACF;AACA;EACEC,WAAWA,CAACC,IAAI,EAAE;IAChB,IAAI,CAACF,KAAK,GAAGE,IAAI;EACnB;EAEA,IAAIC,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACH,KAAK,CAACI,KAAK;EACzB;EAEA,IAAIC,QAAQA,CAAA,EAAG;IACb,IAAI,CAACX,aAAa,CAAC,IAAI,CAACM,KAAK,CAAC,IAAI,CAAC,IAAI,CAACA,KAAK,CAACM,UAAU,CAACC,MAAM,EAAE;MAC/D,OAAO,EAAE;IACX;IAEA,MAAM,CAACC,yBAAyB,CAAC,GAAG,IAAI,CAACR,K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qBAAqB,CAACS,uBAAuB,CAAC,CAAC;EACxD;EAEA+B,iBAAiBA,CAAA,EAAG;IAClB,IAAI,CAAC9B,kBAAkB,CAAC6B,gBAAgB,CAAC,CAAC;IAC1C,IAAI,CAACL,cAAc,CAAC,UAAU,CAAC;EACjC;;EAEA;AACF;AACA;EACEA,cAAcA,CAACO,gBAAgB,EAAE;IAC/B,IAAI,CAACpC,YAAY,GAAGoC,gBAAgB;IACpC,IAAI,CAACxD,MAAM,CAAC,CAAC;EACf;EAEAyD,cAAcA,CAAA,EAAG;IACf,IAAI,CAACrC,YAAY,GAAGC,SAAS;IAE7B,IAAI,CAACI,kBAAkB,CAACiC,kBAAkB,CAAC,CAAC;IAC5C,IAAI,CAAC1D,MAAM,CAAC,CAAC;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"page-controller.js","names":["ComponentType","HIGHLIGHT_CLASS","ContentElements","mapComponentToPreviewQuestion","Markdown","hasComponents","questionRenderer","render","_questionTemplate","_questionBaseModel","PagePreviewElements","_page","constructor","page","heading","title","guidance","components","length","possibleGuidanceComponent","type","content","addHeading","PreviewPageController","PATH","_pageTemplate","_components","pageRenderer","_highlighted","undefined","_guidanceText","_emptyGuidance","createGuidanceComponent","_guidanceComponent","_showTitle","elements","definition","renderer","questions","map","firstQuestion","shift","getOrCreateGuidanceComponent","constructComponents","#constructComponents","_guidanceComponents","componentsWithGuidance","component","model","_overrideComponentHeading","questionType","componentType","showLargeTitle","componentsLength","trim","question","largeTitle","fieldset","renderInput","legend","classes","label","guidanceText","text","showTitle","pageTitle","titleAndFirstTitleSame","value","highlightTitle","setHighLighted","guidanceElement","name","options","guidanceComponent","highlightContent","highlightGuidance","highlightSection","clearHighlight","unHighlightContent"],"sources":["../../../../../../src/form/form-editor/preview/controller/page-controller.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n/**\n * @type {QuestionRenderer}\n */\nconst questionRenderer = {\n /**\n * @param {string} _questionTemplate\n * @param {QuestionBaseModel} _questionBaseModel\n */\n render(_questionTemplate, _questionBaseModel) {\n //\n }\n}\n\n/**\n * @implements {PageOverviewElements}\n */\nexport class PagePreviewElements {\n /**\n * @type {Page}\n * @private\n */\n _page\n\n /**\n * @param {Page} page\n */\n constructor(page) {\n this._page = page\n }\n\n get heading() {\n return this._page.title\n }\n\n get guidance() {\n if (!hasComponents(this._page) || !this._page.components.length) {\n return ''\n }\n\n const [possibleGuidanceComponent] = this._page.components\n\n return possibleGuidanceComponent.type === ComponentType.Markdown\n ? possibleGuidanceComponent.content\n : ''\n }\n\n get addHeading() {\n return this._page.title.length > 0\n }\n}\n\n/**\n * @implements {PagePreviewPanelMacro}\n */\nexport class PreviewPageController {\n static PATH = 'preview-controllers/'\n /**\n * @type {string}\n * @protected\n */\n _pageTemplate = PreviewPageController.PATH + 'page-controller.njk'\n /**\n * @protected\n * @type {Question[]}\n */\n _components = []\n /**\n * @type {string}\n */\n #title = ''\n /**\n *\n * @type {PageRenderer}\n */\n #pageRenderer\n /**\n * @type { undefined | 'title' | 'guidance'}\n * @protected\n */\n _highlighted = undefined\n /**\n * @type {string}\n * @private\n */\n _guidanceText = ''\n /**\n * @type {Markdown}\n * @private\n */\n _emptyGuidance = PreviewPageController.createGuidanceComponent()\n /**\n *\n * @type {Markdown}\n * @protected\n */\n _guidanceComponent\n /**\n * @type {boolean}\n * @private\n */\n _showTitle = true\n /**\n * @param {ComponentDef[]} components\n * @param {PageOverviewElements} elements\n * @param {FormDefinition} definition\n * @param {PageRenderer} renderer\n */\n constructor(components, elements, definition, renderer) {\n const questions = components.map(\n mapComponentToPreviewQuestion(questionRenderer, definition)\n )\n const firstQuestion = /** @type { Markdown | undefined | Question } */ (\n questions.shift()\n )\n\n this._guidanceComponent =\n PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)\n this._guidanceText = elements.guidance\n this._components = this.#constructComponents(firstQuestion, questions)\n this._showTitle = elements.addHeading\n\n this.#pageRenderer = renderer\n this.#title = elements.heading\n }\n\n /**\n * @param { Question | Markdown | undefined} firstQuestion\n * @param {Question[]} questions\n * @returns {Question[]}\n */\n #constructComponents(firstQuestion, questions) {\n return firstQuestion instanceof Markdown || firstQuestion === undefined\n ? questions\n : [firstQuestion, ...questions]\n }\n\n /**\n * @returns {Markdown[]}\n * @private\n */\n get _guidanceComponents() {\n if (this._guidanceText.length) {\n return [this._guidanceComponent]\n }\n if (this._highlighted === 'guidance') {\n return [this._emptyGuidance]\n }\n return []\n }\n\n /**\n * @returns {PagePreviewComponent[]}\n */\n get components() {\n const componentsWithGuidance = /** @type {Question[]} */ ([\n ...this._guidanceComponents,\n ...this._components\n ])\n\n return componentsWithGuidance.map((component) => {\n return {\n model: this._overrideComponentHeading(component),\n questionType: component.componentType\n }\n })\n }\n\n /**\n * @returns {boolean}\n */\n get showLargeTitle() {\n const componentsLength =\n this._components.length + this._guidanceComponents.length\n\n if (componentsLength > 1 || this._highlighted === 'title') {\n return false\n }\n // |_ one component and title not highlighted\n if (this.#title.trim() === this._components[0].question.trim()) {\n return true\n }\n // titles not the same\n\n return !this._showTitle // add page heading deselected?\n }\n\n /**\n * @param {PreviewComponent} component\n * @returns {QuestionBaseModel}\n */\n _overrideComponentHeading(component) {\n const largeTitle = this.showLargeTitle\n\n const fieldset = component.renderInput.fieldset\n ? {\n fieldset: {\n legend: {\n ...component.renderInput.fieldset.legend,\n classes: largeTitle\n ? 'govuk-fieldset__legend--l'\n : 'govuk-fieldset__legend--m'\n }\n }\n }\n : {}\n\n const label = component.renderInput.label\n ? {\n label: {\n ...component.renderInput.label,\n classes: largeTitle ? 'govuk-label--l' : 'govuk-label--m'\n }\n }\n : {}\n\n return {\n ...component.renderInput,\n ...fieldset,\n ...label\n }\n }\n\n set guidanceText(text) {\n this._guidanceText = text\n this._guidanceComponent.content = text\n this.render()\n }\n\n get guidanceText() {\n if (!this._showTitle) {\n return ''\n }\n return this._guidanceText\n }\n\n /**\n *\n * @param {boolean} showTitle\n */\n set showTitle(showTitle) {\n this._showTitle = showTitle\n this.render()\n }\n\n get showTitle() {\n return this._showTitle\n }\n\n get guidance() {\n return {\n text: this.guidanceText,\n classes: this._highlighted === 'guidance' ? 'highlight' : ''\n }\n }\n\n /**\n * @returns {{ text: string, classes: string }}\n */\n get pageTitle() {\n return {\n text: this.title,\n classes: this._highlighted === 'title' ? HIGHLIGHT_CLASS : ''\n }\n }\n\n render() {\n this.#pageRenderer.render(this._pageTemplate, this)\n }\n\n /**\n * @returns {boolean}\n */\n get titleAndFirstTitleSame() {\n return (\n this._components.length > 0 &&\n this.#title.trim() === this._components[0].question.trim() &&\n this.components.length === 1 &&\n this._highlighted !== 'title'\n )\n }\n\n /**\n * @returns {string}\n */\n get title() {\n if (!this._showTitle || this.titleAndFirstTitleSame) {\n return ''\n }\n if (this.#title.length) {\n return this.#title\n }\n return 'Page heading'\n }\n\n /**\n * @param {string} value\n */\n set title(value) {\n this.#title = value\n this.render()\n }\n\n highlightTitle() {\n this.setHighLighted('title')\n }\n\n /**\n * Creates a dummy component for when guidance is highlighted\n * but no guidance text exists\n * @returns {Markdown}\n */\n static createGuidanceComponent() {\n const guidanceElement = new ContentElements({\n type: ComponentType.Markdown,\n title: 'Guidance component',\n name: 'guidanceComponent',\n content: 'Guidance text',\n options: {}\n })\n const guidanceComponent = new Markdown(guidanceElement, questionRenderer)\n\n // the dummy component should always be highlighted\n guidanceComponent.highlightContent()\n return guidanceComponent\n }\n\n /**\n * Helper method to return the guidance or a new one\n * @param { Markdown | Question | undefined } guidanceComponent\n * @returns {Markdown}\n * @private\n */\n static getOrCreateGuidanceComponent(guidanceComponent) {\n if (guidanceComponent instanceof Markdown) {\n return guidanceComponent\n }\n return PreviewPageController.createGuidanceComponent()\n }\n\n highlightGuidance() {\n this._guidanceComponent.highlightContent()\n this.setHighLighted('guidance')\n }\n\n /**\n * @param {'title'|'guidance'} highlightSection\n */\n setHighLighted(highlightSection) {\n this._highlighted = highlightSection\n this.render()\n }\n\n clearHighlight() {\n this._highlighted = undefined\n\n this._guidanceComponent.unHighlightContent()\n this.render()\n }\n}\n\n/**\n * @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n * @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'\n * @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'\n * @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,eAAe;AACxB,SAASC,eAAe;AACxB,SAASC,6BAA6B;AACtC,SAASC,QAAQ;AACjB,SAASC,aAAa;AACtB;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG;EACvB;AACF;AACA;AACA;EACEC,MAAMA,CAACC,iBAAiB,EAAEC,kBAAkB,EAAE;IAC5C;EAAA;AAEJ,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAC/B;AACF;AACA;AACA;EACEC,KAAK;;EAEL;AACF;AACA;EACEC,WAAWA,CAACC,IAAI,EAAE;IAChB,IAAI,CAACF,KAAK,GAAGE,IAAI;EACnB;EAEA,IAAIC,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACH,KAAK,CAACI,KAAK;EACzB;EAEA,IAAIC,QAAQA,CAAA,EAAG;IACb,IAAI,CAACX,aAAa,CAAC,IAAI,CAACM,KAAK,CAAC,IAAI,CAAC,IAAI,CAACA,KAAK,CAACM,UAAU,CAACC,MAAM,EAAE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AAI,CAACrE,MAAM,CAAC,CAAC;EACf;EAEAsE,cAAcA,CAAA,EAAG;IACf,IAAI,CAACjD,YAAY,GAAGC,SAAS;IAE7B,IAAI,CAACI,kBAAkB,CAAC6C,kBAAkB,CAAC,CAAC;IAC5C,IAAI,CAACvE,MAAM,CAAC,CAAC;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -5,7 +5,7 @@ import { ComponentElements } from "./component-elements.js";
5
5
  import { ContentElements } from "./content.js";
6
6
  import { DateInputQuestion } from "./date-input.js";
7
7
  import { EmailAddressQuestion } from "./email-address.js";
8
- import { ListQuestion } from "./list.js";
8
+ import { ListQuestion, SelectComponentElements } from "./list.js";
9
9
  import { LongAnswerQuestion } from "./long-answer.js";
10
10
  import { Markdown } from "./markdown.js";
11
11
  import { MonthYearQuestion } from "./month-year.js";
@@ -48,24 +48,26 @@ const InputFieldComponentDictionary = {
48
48
  /**
49
49
  * @param {QuestionRenderer} questionRenderer
50
50
  * @param {FormDefinition} definition
51
- * @param {boolean} hasTitle
52
51
  * @returns {(component: ComponentDef) => Question}
53
52
  */
54
- export function mapComponentToPreviewQuestion(questionRenderer, definition, hasTitle) {
53
+ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
55
54
  return /** @type {(component: ComponentDef) => Question} */component => {
56
55
  /**
57
56
  * @type {QuestionElements}
58
57
  */
59
58
  let questionElements;
60
- if (hasSelectionFields(component) && hasListField(component)) {
59
+ if (component.type === ComponentType.AutocompleteField || component.type === ComponentType.SelectField) {
61
60
  const list = findDefinitionListFromComponent(component, definition);
62
- questionElements = new ListComponentElements(component, list, !hasTitle);
61
+ questionElements = new SelectComponentElements(component, list);
62
+ } else if (hasSelectionFields(component) && hasListField(component)) {
63
+ const list = findDefinitionListFromComponent(component, definition);
64
+ questionElements = new ListComponentElements(component, list);
63
65
  } else if (hasInputField(component) || component.type === ComponentType.YesNoField) {
64
- questionElements = new QuestionComponentElements(component, !hasTitle);
66
+ questionElements = new QuestionComponentElements(component);
65
67
  } else if (hasContentField(component)) {
66
- questionElements = new ContentElements(component, !hasTitle);
68
+ questionElements = new ContentElements(component);
67
69
  } else {
68
- questionElements = new ComponentElements(component, !hasTitle);
70
+ questionElements = new ComponentElements(component);
69
71
  }
70
72
  const QuestionConstructor = InputFieldComponentDictionary[component.type];
71
73
  return new QuestionConstructor(questionElements, questionRenderer);
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["ComponentType","AutocompleteListQuestion","CheckboxQuestion","ComponentElements","ContentElements","DateInputQuestion","EmailAddressQuestion","ListQuestion","LongAnswerQuestion","Markdown","MonthYearQuestion","NumberOnlyQuestion","PhoneNumberQuestion","RadioQuestion","SelectQuestion","ShortAnswerQuestion","SupportingEvidenceQuestion","UkAddressQuestion","YesNoQuestion","findDefinitionListFromComponent","ListComponentElements","QuestionComponentElements","hasContentField","hasInputField","hasListField","hasSelectionFields","InputFieldComponentDictionary","TextField","Details","InsetText","Html","List","EmailAddressField","NumberField","MultilineTextField","TelephoneNumberField","MonthYearField","DatePartsField","UkAddressField","AutocompleteField","RadiosField","CheckboxesField","SelectField","YesNoField","FileUploadField","mapComponentToPreviewQuestion","questionRenderer","definition","hasTitle","component","questionElements","list","type","QuestionConstructor"],"sources":["../../../../../src/form/form-editor/preview/helpers.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { AutocompleteListQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { CheckboxQuestion } from '~/src/form/form-editor/preview/checkbox.js'\nimport { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { ListQuestion } from '~/src/form/form-editor/preview/list.js'\nimport { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'\nimport { NumberOnlyQuestion } from '~/src/form/form-editor/preview/number-only.js'\nimport { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'\nimport { SelectQuestion } from '~/src/form/form-editor/preview/select.js'\nimport { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'\nimport { UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'\nimport { findDefinitionListFromComponent } from '~/src/form/utils/list.js'\nimport {\n ListComponentElements,\n QuestionComponentElements,\n hasContentField,\n hasInputField,\n hasListField,\n hasSelectionFields\n} from '~/src/index.js'\n\n/**\n * @type {Record<ComponentType, typeof PreviewComponent>}\n */\nconst InputFieldComponentDictionary = {\n [ComponentType.TextField]: ShortAnswerQuestion,\n [ComponentType.Details]: ShortAnswerQuestion,\n [ComponentType.InsetText]: ShortAnswerQuestion,\n [ComponentType.Html]: ShortAnswerQuestion,\n [ComponentType.Markdown]: Markdown,\n [ComponentType.List]: ListQuestion,\n [ComponentType.EmailAddressField]: EmailAddressQuestion,\n [ComponentType.NumberField]: NumberOnlyQuestion,\n [ComponentType.MultilineTextField]: LongAnswerQuestion,\n [ComponentType.TelephoneNumberField]: PhoneNumberQuestion,\n [ComponentType.MonthYearField]: MonthYearQuestion,\n [ComponentType.DatePartsField]: DateInputQuestion,\n [ComponentType.UkAddressField]: UkAddressQuestion,\n [ComponentType.AutocompleteField]: AutocompleteListQuestion,\n [ComponentType.RadiosField]: RadioQuestion,\n [ComponentType.CheckboxesField]: CheckboxQuestion,\n [ComponentType.SelectField]: SelectQuestion,\n [ComponentType.YesNoField]: YesNoQuestion,\n [ComponentType.FileUploadField]: SupportingEvidenceQuestion\n}\n\n/**\n * @param {QuestionRenderer} questionRenderer\n * @param {FormDefinition} definition\n * @param {boolean} hasTitle\n * @returns {(component: ComponentDef) => Question}\n */\nexport function mapComponentToPreviewQuestion(\n questionRenderer,\n definition,\n hasTitle\n) {\n return /** @type {(component: ComponentDef) => Question} */ (\n (component) => {\n /**\n * @type {QuestionElements}\n */\n let questionElements\n\n if (hasSelectionFields(component) && hasListField(component)) {\n const list = findDefinitionListFromComponent(component, definition)\n questionElements = new ListComponentElements(component, list, !hasTitle)\n } else if (\n hasInputField(component) ||\n component.type === ComponentType.YesNoField\n ) {\n questionElements = new QuestionComponentElements(component, !hasTitle)\n } else if (hasContentField(component)) {\n questionElements = new ContentElements(component, !hasTitle)\n } else {\n questionElements = new ComponentElements(component, !hasTitle)\n }\n\n const QuestionConstructor = InputFieldComponentDictionary[component.type]\n\n return new QuestionConstructor(questionElements, questionRenderer)\n }\n )\n}\n\n/**\n * @import { QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n * @import { Item, FormDefinition } from '~/src/form/form-definition/types.js'\n * @import { FormComponentsDef, ComponentDef } from '~/src/components/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,wBAAwB;AACjC,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,oBAAoB;AAC7B,SAASC,YAAY;AACrB,SAASC,kBAAkB;AAC3B,SAASC,QAAQ;AACjB,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,mBAAmB;AAC5B,SAASC,0BAA0B;AACnC,SAASC,iBAAiB;AAC1B,SAASC,aAAa;AACtB,SAASC,+BAA+B;AACxC,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,e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,CAAC,IAAIzB,YAAY,CAACyB,SAAS,CAAC,EAAE;MAC5D,MAAME,IAAI,GAAGhC,+BAA+B,CAAC8B,SAAS,EAAEF,UAAU,CAAC;MACnEG,gBAAgB,GAAG,IAAI9B,qBAAqB,CAAC6B,SAAS,EAAEE,IAAI,EAAE,CAACH,QAAQ,CAAC;IAC1E,CAAC,MAAM,IACLzB,aAAa,CAAC0B,SAAS,CAAC,IACxBA,SAAS,CAACG,IAAI,KAAKpD,aAAa,CAAC2C,UAAU,EAC3C;MACAO,gBAAgB,GAAG,IAAI7B,yBAAyB,CAAC4B,SAAS,EAAE,CAACD,QAAQ,CAAC;IACxE,CAAC,MAAM,IAAI1B,eAAe,CAAC2B,SAAS,CAAC,EAAE;MACrCC,gBAAgB,GAAG,IAAI9C,eAAe,CAAC6C,SAAS,EAAE,CAACD,QAAQ,CAAC;IAC9D,CAAC,MAAM;MACLE,gBAAgB,GAAG,IAAI/C,iBAAiB,CAAC8C,SAAS,EAAE,CAACD,QAAQ,CAAC;IAChE;IAEA,MAAMK,mBAAmB,GAAG3B,6BAA6B,CAACuB,SAAS,CAACG,IAAI,CAAC;IAEzE,OAAO,IAAIC,mBAAmB,CAACH,gBAAgB,EAAEJ,gBAAgB,CAAC;EACpE,CAAC;AAEL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":["ComponentType","AutocompleteListQuestion","CheckboxQuestion","ComponentElements","ContentElements","DateInputQuestion","EmailAddressQuestion","ListQuestion","SelectComponentElements","LongAnswerQuestion","Markdown","MonthYearQuestion","NumberOnlyQuestion","PhoneNumberQuestion","RadioQuestion","SelectQuestion","ShortAnswerQuestion","SupportingEvidenceQuestion","UkAddressQuestion","YesNoQuestion","findDefinitionListFromComponent","ListComponentElements","QuestionComponentElements","hasContentField","hasInputField","hasListField","hasSelectionFields","InputFieldComponentDictionary","TextField","Details","InsetText","Html","List","EmailAddressField","NumberField","MultilineTextField","TelephoneNumberField","MonthYearField","DatePartsField","UkAddressField","AutocompleteField","RadiosField","CheckboxesField","SelectField","YesNoField","FileUploadField","mapComponentToPreviewQuestion","questionRenderer","definition","component","questionElements","type","list","QuestionConstructor"],"sources":["../../../../../src/form/form-editor/preview/helpers.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { AutocompleteListQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { CheckboxQuestion } from '~/src/form/form-editor/preview/checkbox.js'\nimport { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport {\n ListQuestion,\n SelectComponentElements\n} from '~/src/form/form-editor/preview/list.js'\nimport { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'\nimport { NumberOnlyQuestion } from '~/src/form/form-editor/preview/number-only.js'\nimport { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'\nimport { SelectQuestion } from '~/src/form/form-editor/preview/select.js'\nimport { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'\nimport { UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'\nimport { findDefinitionListFromComponent } from '~/src/form/utils/list.js'\nimport {\n ListComponentElements,\n QuestionComponentElements,\n hasContentField,\n hasInputField,\n hasListField,\n hasSelectionFields\n} from '~/src/index.js'\n\n/**\n * @type {Record<ComponentType, typeof PreviewComponent>}\n */\nconst InputFieldComponentDictionary = {\n [ComponentType.TextField]: ShortAnswerQuestion,\n [ComponentType.Details]: ShortAnswerQuestion,\n [ComponentType.InsetText]: ShortAnswerQuestion,\n [ComponentType.Html]: ShortAnswerQuestion,\n [ComponentType.Markdown]: Markdown,\n [ComponentType.List]: ListQuestion,\n [ComponentType.EmailAddressField]: EmailAddressQuestion,\n [ComponentType.NumberField]: NumberOnlyQuestion,\n [ComponentType.MultilineTextField]: LongAnswerQuestion,\n [ComponentType.TelephoneNumberField]: PhoneNumberQuestion,\n [ComponentType.MonthYearField]: MonthYearQuestion,\n [ComponentType.DatePartsField]: DateInputQuestion,\n [ComponentType.UkAddressField]: UkAddressQuestion,\n [ComponentType.AutocompleteField]: AutocompleteListQuestion,\n [ComponentType.RadiosField]: RadioQuestion,\n [ComponentType.CheckboxesField]: CheckboxQuestion,\n [ComponentType.SelectField]: SelectQuestion,\n [ComponentType.YesNoField]: YesNoQuestion,\n [ComponentType.FileUploadField]: SupportingEvidenceQuestion\n}\n\n/**\n * @param {QuestionRenderer} questionRenderer\n * @param {FormDefinition} definition\n * @returns {(component: ComponentDef) => Question}\n */\nexport function mapComponentToPreviewQuestion(questionRenderer, definition) {\n return /** @type {(component: ComponentDef) => Question} */ (\n (component) => {\n /**\n * @type {QuestionElements}\n */\n let questionElements\n\n if (\n component.type === ComponentType.AutocompleteField ||\n component.type === ComponentType.SelectField\n ) {\n const list = findDefinitionListFromComponent(component, definition)\n questionElements = new SelectComponentElements(component, list)\n } else if (hasSelectionFields(component) && hasListField(component)) {\n const list = findDefinitionListFromComponent(component, definition)\n questionElements = new ListComponentElements(component, list)\n } else if (\n hasInputField(component) ||\n component.type === ComponentType.YesNoField\n ) {\n questionElements = new QuestionComponentElements(component)\n } else if (hasContentField(component)) {\n questionElements = new ContentElements(component)\n } else {\n questionElements = new ComponentElements(component)\n }\n\n const QuestionConstructor = InputFieldComponentDictionary[component.type]\n\n return new QuestionConstructor(questionElements, questionRenderer)\n }\n )\n}\n\n/**\n * @import { QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n * @import { Item, FormDefinition } from '~/src/form/form-definition/types.js'\n * @import { FormComponentsDef, ComponentDef } from '~/src/components/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,wBAAwB;AACjC,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,oBAAoB;AAC7B,SACEC,YAAY,EACZC,uBAAuB;AAEzB,SAASC,kBAAkB;AAC3B,SAASC,QAAQ;AACjB,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,mBAAmB;AAC5B,SAASC,0BAA0B;AACnC,SAASC,iBAAiB;AAC1B,SAASC,aAAa;AACtB,SAASC,+BAA+B;AACxC,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,eAAe,EACfC,aAAa,EACbC,YAAY,EACZC,kBAAkB;;AAGpB;AACA;AACA;AACA,MAAMC,6BAA6B,GAAG;EACpC,CAAC3B,aAAa,CAAC4B,SAAS,GAAGZ,mBAAmB;EAC9C,CAAChB,aAAa,CAAC6B,OAAO,GAAGb,mBAAmB;EAC5C,CAAChB,aAAa,CAAC8B,SAAS,GAAGd,mBAAmB;EAC9C,CAAChB,aAAa,CAAC+B,IAAI,GAAGf,mBAAmB;EACzC,CAAChB,aAAa,CAACU,QAAQ,GAAGA,QAAQ;EAClC,CAACV,aAAa,CAACgC,IAAI,GAAGzB,YAAY;EAClC,CAACP,aAAa,CAACiC,iBAAiB,GAAG3B,oBAAoB;EACvD,CAACN,aAAa,CAACkC,WAAW,GAAGtB,kBAAkB;EAC/C,CAACZ,aAAa,CAACmC,kBAAkB,GAAG1B,kBAAkB;EACtD,CAACT,aAAa,CAACoC,oBAAoB,GAAGvB,mB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