@defra/forms-model 3.0.492 → 3.0.494
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/form/form-editor/macros/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/autocomplete.js +3 -0
- package/dist/module/form/form-editor/preview/autocomplete.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +5 -2
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
- package/dist/module/form/form-editor/preview/list.js +58 -5
- package/dist/module/form/form-editor/preview/list.js.map +1 -1
- package/dist/module/form/form-editor/preview/select-sortable.js +5 -1
- package/dist/module/form/form-editor/preview/select-sortable.js.map +1 -1
- package/dist/module/form/form-editor/preview/select.js +32 -0
- package/dist/module/form/form-editor/preview/select.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/module/pages/helpers.js +19 -1
- package/dist/module/pages/helpers.js.map +1 -1
- package/dist/module/pages/index.js +1 -1
- package/dist/module/pages/index.js.map +1 -1
- package/dist/types/form/form-editor/macros/types.d.ts +13 -5
- package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/autocomplete.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/fieldset-question.d.ts +2 -5
- package/dist/types/form/form-editor/preview/fieldset-question.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/list.d.ts +32 -6
- package/dist/types/form/form-editor/preview/list.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/select-sortable.d.ts +1 -1
- package/dist/types/form/form-editor/preview/select-sortable.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/select.d.ts +14 -0
- package/dist/types/form/form-editor/preview/select.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/types.d.ts +4 -0
- package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
- package/dist/types/pages/helpers.d.ts +6 -0
- package/dist/types/pages/helpers.d.ts.map +1 -1
- package/dist/types/pages/index.d.ts +1 -1
- package/dist/types/pages/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/form/form-editor/macros/types.ts +12 -1
- package/src/form/form-editor/preview/autocomplete.js +1 -0
- package/src/form/form-editor/preview/helpers.js +11 -2
- package/src/form/form-editor/preview/list.js +71 -14
- package/src/form/form-editor/preview/select-sortable.js +5 -1
- package/src/form/form-editor/preview/select.js +38 -0
- package/src/form/form-editor/preview/types.ts +5 -0
- package/src/pages/helpers.ts +20 -1
- package/src/pages/index.ts +1 -0
@@ -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?:
|
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":[]}
|
@@ -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","
|
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;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,UAAU,EAAE;QAAE,aAAa,EAAE;MAAgC,CAAC;MAC9DC,KAAK,EAAE,IAAI,CAACC,aAAa,CAACC,MAAM,CAACF;IACnC,CAAC;EACH;AACF;AAEA,OAAO,MAAMG,oBAAoB,SAASX,wBAAwB,CAAC;EACjE;AACF;AACA;AACA;EACEY,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;IACE1B,yBAAyB,CAAC2B,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,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":[]}
|
@@ -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";
|
@@ -56,7 +56,10 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
56
56
|
* @type {QuestionElements}
|
57
57
|
*/
|
58
58
|
let questionElements;
|
59
|
-
if (
|
59
|
+
if (component.type === ComponentType.AutocompleteField || component.type === ComponentType.SelectField) {
|
60
|
+
const list = findDefinitionListFromComponent(component, definition);
|
61
|
+
questionElements = new SelectComponentElements(component, list);
|
62
|
+
} else if (hasSelectionFields(component) && hasListField(component)) {
|
60
63
|
const list = findDefinitionListFromComponent(component, definition);
|
61
64
|
questionElements = new ListComponentElements(component, list);
|
62
65
|
} else if (hasInputField(component) || component.type === ComponentType.YesNoField) {
|
@@ -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","component","questionElements","
|
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,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AC3C;MACAM,gBAAgB,GAAG,IAAI5B,yBAAyB,CAAC2B,SAAS,CAAC;IAC7D,CAAC,MAAM,IAAI1B,eAAe,CAAC0B,SAAS,CAAC,EAAE;MACrCC,gBAAgB,GAAG,IAAI9C,eAAe,CAAC6C,SAAS,CAAC;IACnD,CAAC,MAAM;MACLC,gBAAgB,GAAG,IAAI/C,iBAAiB,CAAC8C,SAAS,CAAC;IACrD;IAEA,MAAMI,mBAAmB,GAAG1B,6BAA6B,CAACsB,SAAS,CAACE,IAAI,CAAC;IAEzE,OAAO,IAAIE,mBAAmB,CAACH,gBAAgB,EAAEH,gBAAgB,CAAC;EACpE,CAAC;AAEL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
@@ -74,6 +74,28 @@ export class ListComponentElements extends QuestionComponentElements {
|
|
74
74
|
};
|
75
75
|
}
|
76
76
|
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @implements {QuestionElements}
|
80
|
+
*/
|
81
|
+
export class SelectComponentElements extends ListComponentElements {
|
82
|
+
/**
|
83
|
+
* @returns {BaseSettings}
|
84
|
+
* @protected
|
85
|
+
*/
|
86
|
+
_getValues() {
|
87
|
+
const emptyItem = /** @type {ListElement} */{
|
88
|
+
id: 'da310b6e-2513-4d14-a7a1-63a93231891d',
|
89
|
+
text: '',
|
90
|
+
value: ''
|
91
|
+
};
|
92
|
+
const items = /** @type {ListElement[]} */[emptyItem, ...super._getValues().items];
|
93
|
+
return {
|
94
|
+
...super._getValues(),
|
95
|
+
items
|
96
|
+
};
|
97
|
+
}
|
98
|
+
}
|
77
99
|
export class ListQuestion extends Question {
|
78
100
|
/**
|
79
101
|
* @type {ComponentType}
|
@@ -107,8 +129,9 @@ export class ListQuestion extends Question {
|
|
107
129
|
}
|
108
130
|
|
109
131
|
/**
|
132
|
+
* @protected
|
110
133
|
* @returns {{
|
111
|
-
* formGroup?:
|
134
|
+
* formGroup?: FormGroupAfterInput;
|
112
135
|
* hint: DefaultComponent;
|
113
136
|
* name: string;
|
114
137
|
* fieldset?: GovukFieldset;
|
@@ -116,8 +139,8 @@ export class ListQuestion extends Question {
|
|
116
139
|
* items: ListItemReadonly[]
|
117
140
|
* }}
|
118
141
|
*/
|
119
|
-
|
120
|
-
const afterInputs = /** @type {{ formGroup?:
|
142
|
+
_renderInput() {
|
143
|
+
const afterInputs = /** @type {{ formGroup?: FormGroupAfterInput }} */
|
121
144
|
this.list.length ? {} : {
|
122
145
|
formGroup: {
|
123
146
|
afterInputs: {
|
@@ -135,6 +158,20 @@ export class ListQuestion extends Question {
|
|
135
158
|
};
|
136
159
|
}
|
137
160
|
|
161
|
+
/**
|
162
|
+
* @returns {{
|
163
|
+
* formGroup?: FormGroupAfterInput;
|
164
|
+
* hint: DefaultComponent;
|
165
|
+
* name: string;
|
166
|
+
* fieldset?: GovukFieldset;
|
167
|
+
* id: string;
|
168
|
+
* items: ListItemReadonly[]
|
169
|
+
* }}
|
170
|
+
*/
|
171
|
+
get renderInput() {
|
172
|
+
return this._renderInput();
|
173
|
+
}
|
174
|
+
|
138
175
|
/**
|
139
176
|
*
|
140
177
|
* @param {ListElement} listElement
|
@@ -162,9 +199,10 @@ export class ListQuestion extends Question {
|
|
162
199
|
}
|
163
200
|
|
164
201
|
/**
|
202
|
+
* @protected
|
165
203
|
* @returns {ListItemReadonly[]}
|
166
204
|
*/
|
167
|
-
|
205
|
+
_getList() {
|
168
206
|
const iterator = /** @type {MapIterator<ListElement>} */
|
169
207
|
this._list.values();
|
170
208
|
return Array.from(iterator).map(listItem => {
|
@@ -175,7 +213,7 @@ export class ListQuestion extends Question {
|
|
175
213
|
classes: this.getHighlight(listItem.id + '-hint')
|
176
214
|
} : undefined
|
177
215
|
};
|
178
|
-
const text = listItem.text
|
216
|
+
const text = listItem.text;
|
179
217
|
return {
|
180
218
|
...listItem,
|
181
219
|
text,
|
@@ -188,6 +226,20 @@ export class ListQuestion extends Question {
|
|
188
226
|
});
|
189
227
|
}
|
190
228
|
|
229
|
+
/**
|
230
|
+
* @returns {ListItemReadonly[]}
|
231
|
+
*/
|
232
|
+
get list() {
|
233
|
+
const list = this._getList();
|
234
|
+
return list.map(listItem => {
|
235
|
+
const text = listItem.text.length ? listItem.text : 'Item text';
|
236
|
+
return {
|
237
|
+
...listItem,
|
238
|
+
text
|
239
|
+
};
|
240
|
+
});
|
241
|
+
}
|
242
|
+
|
191
243
|
/**
|
192
244
|
*
|
193
245
|
* @param {string | undefined} id
|
@@ -243,6 +295,7 @@ export class ListQuestion extends Question {
|
|
243
295
|
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
244
296
|
* @import { SelectionComponentsDef, ListComponentsDef } from '~/src/components/types.js'
|
245
297
|
* @import { List, Item } from '~/src/form/form-definition/types.js'
|
298
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
246
299
|
* @import { ListElements, QuestionRenderer, DefaultComponent, GovukFieldset, BaseSettings, QuestionElements } from '~/src/form/form-editor/preview/types.js'
|
247
300
|
*/
|
248
301
|
//# sourceMappingURL=list.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"list.js","names":["ComponentType","PreviewComponent","Question","QuestionComponentElements","DefaultListConst","TextElementId","HintElementId","Template","PATH","Input","RenderName","listItemMapper","listElement","id","listsElementToMap","listElements","entries","map","Map","listItemToListElement","item","text","label","classes","value","hint","ListComponentElements","_list","constructor","component","list","_getValues","items","ListQuestion","componentType","List","_questionTemplate","_listElements","listRenderId","listRenderName","questionRenderer","values","createListFromElements","renderInput","afterInputs","length","formGroup","html","afterInputsHTML","name","fieldset","fieldSet","push","set","render","delete","key","iterator","Array","from","listItem","hintText","_highlight","getHighlight","undefined","updateText","get","updateHint","updateValue"],"sources":["../../../../../src/form/form-editor/preview/list.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport {\n Question,\n QuestionComponentElements\n} from '~/src/form/form-editor/preview/question.js'\n\nconst DefaultListConst = {\n TextElementId: 'radioText',\n HintElementId: 'radioHint',\n Template: PreviewComponent.PATH + 'radios.njk',\n Input: 'listInput',\n RenderName: 'listInputField'\n}\n\n/**\n * @param {ListElement} listElement\n * @returns {[string, ListElement]}\n */\nexport function listItemMapper(listElement) {\n return [listElement.id, listElement]\n}\n\n/**\n *\n * @param { ListElement[]| undefined } listElements\n * @returns {Map<string, ListElement>}\n */\nexport function listsElementToMap(listElements) {\n const entries = listElements ? listElements.map(listItemMapper) : []\n return new Map(entries)\n}\n\n/**\n * @param {Item} item\n * @returns {ListElement}\n */\nexport function listItemToListElement(item) {\n return {\n text: item.text,\n label: {\n text: item.text,\n classes: ''\n },\n value: item.value,\n id: item.id ?? '',\n hint: item.hint\n }\n}\n\n/**\n * @implements {QuestionElements}\n */\nexport class ListComponentElements extends QuestionComponentElements {\n /**\n * @type {List}\n * @protected\n */\n _list\n\n /**\n * @param {SelectionComponentsDef} component\n * @param {List} list\n */\n constructor(component, list) {\n super(component)\n this._list = list\n }\n\n /**\n * @returns {BaseSettings}\n * @protected\n */\n _getValues() {\n return {\n ...super._getValues(),\n items: this._list.items.map(listItemToListElement)\n }\n }\n}\n\nexport class ListQuestion extends Question {\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.List\n /**\n * @type {string}\n * @protected\n */\n _questionTemplate = DefaultListConst.Template\n /** @type {ListElements} */\n _listElements\n listRenderId = DefaultListConst.Input\n listRenderName = DefaultListConst.RenderName\n\n /**\n * @type {Map<string, ListElement>}\n * @protected\n */\n _list\n\n /**\n * @param {ListElements} listElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(listElements, questionRenderer) {\n super(listElements, questionRenderer)\n\n const items = /** @type {ListElement[]} */ (listElements.values.items)\n this._list = this.createListFromElements(items)\n this._listElements = listElements\n }\n\n /**\n * @returns {{\n * formGroup?: {afterInputs: {html: string}};\n * hint: DefaultComponent;\n * name: string;\n * fieldset?: GovukFieldset;\n * id: string;\n * items: ListItemReadonly[]\n * }}\n */\n get renderInput() {\n const afterInputs =\n /** @type {{ formGroup?: { afterInputs: { html: string } } }} */ (\n this.list.length\n ? {}\n : {\n formGroup: {\n afterInputs: {\n html: this._listElements.afterInputsHTML\n }\n }\n }\n )\n\n return {\n id: this.listRenderId,\n name: this.listRenderName,\n fieldset: this.fieldSet,\n hint: this.hint,\n items: this.list,\n ...afterInputs\n }\n }\n\n /**\n *\n * @param {ListElement} listElement\n */\n push(listElement) {\n this._list.set(listElement.id, listElement)\n this.render()\n }\n\n /**\n * @param {string} key\n */\n delete(key) {\n this._list.delete(key)\n this.render()\n }\n\n /**\n * @param {ListElement[]} listElements\n * @returns {Map<string, ListElement>}\n */\n createListFromElements(listElements) {\n this._list = listsElementToMap(listElements)\n return this._list\n }\n\n /**\n * @returns {ListItemReadonly[]}\n */\n get list() {\n const iterator = /** @type {MapIterator<ListElement>} */ (\n this._list.values()\n )\n return Array.from(iterator).map((listItem) => {\n const hintText =\n this._highlight === `${listItem.id}-hint` && !listItem.hint?.text.length\n ? 'Hint text'\n : (listItem.hint?.text ?? '')\n\n const hint = {\n hint: hintText\n ? {\n text: hintText,\n classes: this.getHighlight(listItem.id + '-hint')\n }\n : undefined\n }\n\n const text = listItem.text.length ? listItem.text : 'Item text'\n\n return {\n ...listItem,\n text,\n ...hint,\n label: {\n text: listItem.text,\n classes: this.getHighlight(listItem.id + '-label')\n }\n }\n })\n }\n\n /**\n *\n * @param {string | undefined} id\n * @param {string} text\n */\n updateText(id, text) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.text = text\n this.render()\n }\n }\n\n /**\n *\n * @param {string | undefined} id\n * @param {string} hint\n */\n updateHint(id, hint) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.hint = {\n ...listItem.hint,\n text: hint\n }\n this.render()\n }\n }\n\n /**\n * @param {string | undefined} id\n * @param {string} value\n */\n updateValue(id, value) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.value = value\n this.render()\n }\n }\n}\n\n/**\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n * @import { SelectionComponentsDef, ListComponentsDef } from '~/src/components/types.js'\n * @import { List, Item } from '~/src/form/form-definition/types.js'\n * @import { ListElements, QuestionRenderer, DefaultComponent, GovukFieldset, BaseSettings, QuestionElements } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,gBAAgB;AACzB,SACEC,QAAQ,EACRC,yBAAyB;AAG3B,MAAMC,gBAAgB,GAAG;EACvBC,aAAa,EAAE,WAAW;EAC1BC,aAAa,EAAE,WAAW;EAC1BC,QAAQ,EAAEN,gBAAgB,CAACO,IAAI,GAAG,YAAY;EAC9CC,KAAK,EAAE,WAAW;EAClBC,UAAU,EAAE;AACd,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,WAAW,EAAE;EAC1C,OAAO,CAACA,WAAW,CAACC,EAAE,EAAED,WAAW,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAACC,YAAY,EAAE;EAC9C,MAAMC,OAAO,GAAGD,YAAY,GAAGA,YAAY,CAACE,GAAG,CAACN,cAAc,CAAC,GAAG,EAAE;EACpE,OAAO,IAAIO,GAAG,CAACF,OAAO,CAAC;AACzB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAACC,IAAI,EAAE;EAC1C,OAAO;IACLC,IAAI,EAAED,IAAI,CAACC,IAAI;IACfC,KAAK,EAAE;MACLD,IAAI,EAAED,IAAI,CAACC,IAAI;MACfE,OAAO,EAAE;IACX,CAAC;IACDC,KAAK,EAAEJ,IAAI,CAACI,KAAK;IACjBX,EAAE,EAAEO,IAAI,CAACP,EAAE,IAAI,EAAE;IACjBY,IAAI,EAAEL,IAAI,CAACK;EACb,CAAC;AACH;;AAEA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D,EAAE,EAAEW,KAAK,EAAE;IACrB,IAAI,CAACX,EAAE,EAAE;MACP;IACF;IAEA,MAAM+C,QAAQ,GAAG,IAAI,CAACjC,KAAK,CAACuC,GAAG,CAACrD,EAAE,CAAC;IACnC,IAAI+C,QAAQ,EAAE;MACZA,QAAQ,CAACpC,KAAK,GAAGA,KAAK;MACtB,IAAI,CAAC8B,MAAM,CAAC,CAAC;IACf;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
1
|
+
{"version":3,"file":"list.js","names":["ComponentType","PreviewComponent","Question","QuestionComponentElements","DefaultListConst","TextElementId","HintElementId","Template","PATH","Input","RenderName","listItemMapper","listElement","id","listsElementToMap","listElements","entries","map","Map","listItemToListElement","item","text","label","classes","value","hint","ListComponentElements","_list","constructor","component","list","_getValues","items","SelectComponentElements","emptyItem","ListQuestion","componentType","List","_questionTemplate","_listElements","listRenderId","listRenderName","questionRenderer","values","createListFromElements","_renderInput","afterInputs","length","formGroup","html","afterInputsHTML","name","fieldset","fieldSet","renderInput","push","set","render","delete","key","_getList","iterator","Array","from","listItem","hintText","_highlight","getHighlight","undefined","updateText","get","updateHint","updateValue"],"sources":["../../../../../src/form/form-editor/preview/list.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport {\n Question,\n QuestionComponentElements\n} from '~/src/form/form-editor/preview/question.js'\n\nconst DefaultListConst = {\n TextElementId: 'radioText',\n HintElementId: 'radioHint',\n Template: PreviewComponent.PATH + 'radios.njk',\n Input: 'listInput',\n RenderName: 'listInputField'\n}\n\n/**\n * @param {ListElement} listElement\n * @returns {[string, ListElement]}\n */\nexport function listItemMapper(listElement) {\n return [listElement.id, listElement]\n}\n\n/**\n *\n * @param { ListElement[]| undefined } listElements\n * @returns {Map<string, ListElement>}\n */\nexport function listsElementToMap(listElements) {\n const entries = listElements ? listElements.map(listItemMapper) : []\n return new Map(entries)\n}\n\n/**\n * @param {Item} item\n * @returns {ListElement}\n */\nexport function listItemToListElement(item) {\n return {\n text: item.text,\n label: {\n text: item.text,\n classes: ''\n },\n value: item.value,\n id: item.id ?? '',\n hint: item.hint\n }\n}\n\n/**\n * @implements {QuestionElements}\n */\nexport class ListComponentElements extends QuestionComponentElements {\n /**\n * @type {List}\n * @protected\n */\n _list\n\n /**\n * @param {SelectionComponentsDef} component\n * @param {List} list\n */\n constructor(component, list) {\n super(component)\n this._list = list\n }\n\n /**\n * @returns {BaseSettings}\n * @protected\n */\n _getValues() {\n return {\n ...super._getValues(),\n items: this._list.items.map(listItemToListElement)\n }\n }\n}\n\n/**\n * @implements {QuestionElements}\n */\nexport class SelectComponentElements extends ListComponentElements {\n /**\n * @returns {BaseSettings}\n * @protected\n */\n _getValues() {\n const emptyItem = /** @type {ListElement} */ ({\n id: 'da310b6e-2513-4d14-a7a1-63a93231891d',\n text: '',\n value: ''\n })\n const items = /** @type {ListElement[]} */ ([\n emptyItem,\n ...super._getValues().items\n ])\n return {\n ...super._getValues(),\n items\n }\n }\n}\n\nexport class ListQuestion extends Question {\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.List\n /**\n * @type {string}\n * @protected\n */\n _questionTemplate = DefaultListConst.Template\n /** @type {ListElements} */\n _listElements\n listRenderId = DefaultListConst.Input\n listRenderName = DefaultListConst.RenderName\n\n /**\n * @type {Map<string, ListElement>}\n * @protected\n */\n _list\n\n /**\n * @param {ListElements} listElements\n * @param {QuestionRenderer} questionRenderer\n */\n constructor(listElements, questionRenderer) {\n super(listElements, questionRenderer)\n\n const items = /** @type {ListElement[]} */ (listElements.values.items)\n this._list = this.createListFromElements(items)\n this._listElements = listElements\n }\n\n /**\n * @protected\n * @returns {{\n * formGroup?: FormGroupAfterInput;\n * hint: DefaultComponent;\n * name: string;\n * fieldset?: GovukFieldset;\n * id: string;\n * items: ListItemReadonly[]\n * }}\n */\n _renderInput() {\n const afterInputs = /** @type {{ formGroup?: FormGroupAfterInput }} */ (\n this.list.length\n ? {}\n : {\n formGroup: {\n afterInputs: {\n html: this._listElements.afterInputsHTML\n }\n }\n }\n )\n\n return {\n id: this.listRenderId,\n name: this.listRenderName,\n fieldset: this.fieldSet,\n hint: this.hint,\n items: this.list,\n ...afterInputs\n }\n }\n\n /**\n * @returns {{\n * formGroup?: FormGroupAfterInput;\n * hint: DefaultComponent;\n * name: string;\n * fieldset?: GovukFieldset;\n * id: string;\n * items: ListItemReadonly[]\n * }}\n */\n get renderInput() {\n return this._renderInput()\n }\n\n /**\n *\n * @param {ListElement} listElement\n */\n push(listElement) {\n this._list.set(listElement.id, listElement)\n this.render()\n }\n\n /**\n * @param {string} key\n */\n delete(key) {\n this._list.delete(key)\n this.render()\n }\n\n /**\n * @param {ListElement[]} listElements\n * @returns {Map<string, ListElement>}\n */\n createListFromElements(listElements) {\n this._list = listsElementToMap(listElements)\n return this._list\n }\n\n /**\n * @protected\n * @returns {ListItemReadonly[]}\n */\n _getList() {\n const iterator = /** @type {MapIterator<ListElement>} */ (\n this._list.values()\n )\n return Array.from(iterator).map((listItem) => {\n const hintText =\n this._highlight === `${listItem.id}-hint` && !listItem.hint?.text.length\n ? 'Hint text'\n : (listItem.hint?.text ?? '')\n\n const hint = {\n hint: hintText\n ? {\n text: hintText,\n classes: this.getHighlight(listItem.id + '-hint')\n }\n : undefined\n }\n\n const text = listItem.text\n\n return {\n ...listItem,\n text,\n ...hint,\n label: {\n text: listItem.text,\n classes: this.getHighlight(listItem.id + '-label')\n }\n }\n })\n }\n\n /**\n * @returns {ListItemReadonly[]}\n */\n get list() {\n const list = this._getList()\n\n return list.map((listItem) => {\n const text = listItem.text.length ? listItem.text : 'Item text'\n\n return {\n ...listItem,\n text\n }\n })\n }\n\n /**\n *\n * @param {string | undefined} id\n * @param {string} text\n */\n updateText(id, text) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.text = text\n this.render()\n }\n }\n\n /**\n *\n * @param {string | undefined} id\n * @param {string} hint\n */\n updateHint(id, hint) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.hint = {\n ...listItem.hint,\n text: hint\n }\n this.render()\n }\n }\n\n /**\n * @param {string | undefined} id\n * @param {string} value\n */\n updateValue(id, value) {\n if (!id) {\n return\n }\n\n const listItem = this._list.get(id)\n if (listItem) {\n listItem.value = value\n this.render()\n }\n }\n}\n\n/**\n * @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'\n * @import { SelectionComponentsDef, ListComponentsDef } from '~/src/components/types.js'\n * @import { List, Item } from '~/src/form/form-definition/types.js'\n * @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'\n * @import { ListElements, QuestionRenderer, DefaultComponent, GovukFieldset, BaseSettings, QuestionElements } from '~/src/form/form-editor/preview/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,gBAAgB;AACzB,SACEC,QAAQ,EACRC,yBAAyB;AAG3B,MAAMC,gBAAgB,GAAG;EACvBC,aAAa,EAAE,WAAW;EAC1BC,aAAa,EAAE,WAAW;EAC1BC,QAAQ,EAAEN,gBAAgB,CAACO,IAAI,GAAG,YAAY;EAC9CC,KAAK,EAAE,WAAW;EAClBC,UAAU,EAAE;AACd,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,WAAW,EAAE;EAC1C,OAAO,CAACA,WAAW,CAACC,EAAE,EAAED,WAAW,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAACC,YAAY,EAAE;EAC9C,MAAMC,OAAO,GAAGD,YAAY,GAAGA,YAAY,CAACE,GAAG,CAACN,cAAc,CAAC,GAAG,EAAE;EACpE,OAAO,IAAIO,GAAG,CAACF,OAAO,CAAC;AACzB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAACC,IAAI,EAAE;EAC1C,OAAO;IACLC,IAAI,EAAED,IAAI,CAACC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IACnC,IAAImD,QAAQ,EAAE;MACZA,QAAQ,CAACxC,KAAK,GAAGA,KAAK;MACtB,IAAI,CAACiC,MAAM,CAAC,CAAC;IACf;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
@@ -16,7 +16,7 @@ export class SelectSortableQuestion extends ListSortableQuestion {
|
|
16
16
|
*/
|
17
17
|
componentType = ComponentType.SelectField;
|
18
18
|
get renderInput() {
|
19
|
-
const afterInput = /** @type {{ formGroup?: {
|
19
|
+
const afterInput = /** @type {{ formGroup?: { afterInput: { html: string }} }} */
|
20
20
|
this.list.length ? {} : {
|
21
21
|
formGroup: {
|
22
22
|
afterInput: {
|
@@ -35,4 +35,8 @@ export class SelectSortableQuestion extends ListSortableQuestion {
|
|
35
35
|
};
|
36
36
|
}
|
37
37
|
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
41
|
+
*/
|
38
42
|
//# sourceMappingURL=select-sortable.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select-sortable.js","names":["ListSortableQuestion","PreviewComponent","ComponentType","SelectSortableQuestion","_questionTemplate","PATH","selectList","list","length","id","value","text","componentType","SelectField","renderInput","afterInput","formGroup","html","_listElements","afterInputsHTML","_fieldName","name","hint","label","items","classes"],"sources":["../../../../../src/form/form-editor/preview/select-sortable.js"],"sourcesContent":["import { ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport { ComponentType } from '~/src/index.js'\n\nexport class SelectSortableQuestion extends ListSortableQuestion {\n _questionTemplate = PreviewComponent.PATH + 'selectfield.njk'\n\n get selectList() {\n return this.list.length\n ? [{ id: '', value: '', text: ' ' }, ...this.list]\n : this.list\n }\n\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.SelectField\n\n get renderInput() {\n const afterInput =\n /** @type {{ formGroup?: {
|
1
|
+
{"version":3,"file":"select-sortable.js","names":["ListSortableQuestion","PreviewComponent","ComponentType","SelectSortableQuestion","_questionTemplate","PATH","selectList","list","length","id","value","text","componentType","SelectField","renderInput","afterInput","formGroup","html","_listElements","afterInputsHTML","_fieldName","name","hint","label","items","classes"],"sources":["../../../../../src/form/form-editor/preview/select-sortable.js"],"sourcesContent":["import { ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport { ComponentType } from '~/src/index.js'\n\nexport class SelectSortableQuestion extends ListSortableQuestion {\n _questionTemplate = PreviewComponent.PATH + 'selectfield.njk'\n\n get selectList() {\n return this.list.length\n ? [{ id: '', value: '', text: ' ' }, ...this.list]\n : this.list\n }\n\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.SelectField\n\n get renderInput() {\n const afterInput =\n /** @type {{ formGroup?: { afterInput: { html: string }} }} */ (\n this.list.length\n ? {}\n : {\n formGroup: {\n afterInput: {\n html: this._listElements.afterInputsHTML\n }\n }\n }\n )\n\n return {\n id: this._fieldName,\n name: this._fieldName,\n hint: this.hint,\n label: this.label,\n items: this.selectList,\n classes: this.list.length ? '' : 'govuk-visually-hidden',\n ...afterInput\n }\n }\n}\n\n/**\n * @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,oBAAoB;AAC7B,SAASC,gBAAgB;AACzB,SAASC,aAAa;AAEtB,OAAO,MAAMC,sBAAsB,SAASH,oBAAoB,CAAC;EAC/DI,iBAAiB,GAAGH,gBAAgB,CAACI,IAAI,GAAG,iBAAiB;EAE7D,IAAIC,UAAUA,CAAA,EAAG;IACf,OAAO,IAAI,CAACC,IAAI,CAACC,MAAM,GACnB,CAAC;MAAEC,EAAE,EAAE,EAAE;MAAEC,KAAK,EAAE,EAAE;MAAEC,IAAI,EAAE;IAAI,CAAC,EAAE,GAAG,IAAI,CAACJ,IAAI,CAAC,GAChD,IAAI,CAACA,IAAI;EACf;;EAEA;AACF;AACA;EACEK,aAAa,GAAGV,aAAa,CAACW,WAAW;EAEzC,IAAIC,WAAWA,CAAA,EAAG;IAChB,MAAMC,UAAU,GACd;IACE,IAAI,CAACR,IAAI,CAACC,MAAM,GACZ,CAAC,CAAC,GACF;MACEQ,SAAS,EAAE;QACTD,UAAU,EAAE;UACVE,IAAI,EAAE,IAAI,CAACC,aAAa,CAACC;QAC3B;MACF;IACF,CACL;IAEH,OAAO;MACLV,EAAE,EAAE,IAAI,CAACW,UAAU;MACnBC,IAAI,EAAE,IAAI,CAACD,UAAU;MACrBE,IAAI,EAAE,IAAI,CAACA,IAAI;MACfC,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBC,KAAK,EAAE,IAAI,CAAClB,UAAU;MACtBmB,OAAO,EAAE,IAAI,CAAClB,IAAI,CAACC,MAAM,GAAG,EAAE,GAAG,uBAAuB;MACxD,GAAGO;IACL,CAAC;EACH;AACF;;AAEA;AACA;AACA","ignoreList":[]}
|
@@ -3,9 +3,41 @@ import { ListQuestion } from "./list.js";
|
|
3
3
|
import { PreviewComponent } from "./preview.js";
|
4
4
|
export class SelectQuestion extends ListQuestion {
|
5
5
|
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk';
|
6
|
+
_fieldName = 'selectInput';
|
6
7
|
/**
|
7
8
|
* @type {ComponentType}
|
8
9
|
*/
|
9
10
|
componentType = ComponentType.SelectField;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @returns {ListItemReadonly[]}
|
14
|
+
*/
|
15
|
+
get list() {
|
16
|
+
return this._getList();
|
17
|
+
}
|
18
|
+
get renderInput() {
|
19
|
+
const afterInput = /** @type {{ formGroup?: { afterInput: { html: string }} }} */
|
20
|
+
this.list.length ? {} : {
|
21
|
+
formGroup: {
|
22
|
+
afterInput: {
|
23
|
+
html: this._listElements.afterInputsHTML
|
24
|
+
}
|
25
|
+
}
|
26
|
+
};
|
27
|
+
return {
|
28
|
+
id: this._fieldName,
|
29
|
+
name: this._fieldName,
|
30
|
+
hint: this.hint,
|
31
|
+
label: this.label,
|
32
|
+
items: this.list,
|
33
|
+
classes: this.list.length ? '' : 'govuk-visually-hidden',
|
34
|
+
...afterInput
|
35
|
+
};
|
36
|
+
}
|
10
37
|
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @import { ListItemReadonly } from '~/src/form/form-editor/types.js'
|
41
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
42
|
+
*/
|
11
43
|
//# sourceMappingURL=select.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select.js","names":["ComponentType","ListQuestion","PreviewComponent","SelectQuestion","_questionTemplate","PATH","componentType","SelectField"],"sources":["../../../../../src/form/form-editor/preview/select.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { ListQuestion } from '~/src/form/form-editor/preview/list.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n\nexport class SelectQuestion extends ListQuestion {\n _questionTemplate = PreviewComponent.PATH + 'selectfield.njk'\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.SelectField\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY;AACrB,SAASC,gBAAgB;AAEzB,OAAO,MAAMC,cAAc,SAASF,YAAY,CAAC;EAC/CG,iBAAiB,GAAGF,gBAAgB,CAACG,IAAI,GAAG,iBAAiB;
|
1
|
+
{"version":3,"file":"select.js","names":["ComponentType","ListQuestion","PreviewComponent","SelectQuestion","_questionTemplate","PATH","_fieldName","componentType","SelectField","list","_getList","renderInput","afterInput","length","formGroup","html","_listElements","afterInputsHTML","id","name","hint","label","items","classes"],"sources":["../../../../../src/form/form-editor/preview/select.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { ListQuestion } from '~/src/form/form-editor/preview/list.js'\nimport { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n\nexport class SelectQuestion extends ListQuestion {\n _questionTemplate = PreviewComponent.PATH + 'selectfield.njk'\n _fieldName = 'selectInput'\n /**\n * @type {ComponentType}\n */\n componentType = ComponentType.SelectField\n\n /**\n * @returns {ListItemReadonly[]}\n */\n get list() {\n return this._getList()\n }\n\n get renderInput() {\n const afterInput =\n /** @type {{ formGroup?: { afterInput: { html: string }} }} */ (\n this.list.length\n ? {}\n : {\n formGroup: {\n afterInput: {\n html: this._listElements.afterInputsHTML\n }\n }\n }\n )\n\n return {\n id: this._fieldName,\n name: this._fieldName,\n hint: this.hint,\n label: this.label,\n items: this.list,\n classes: this.list.length ? '' : 'govuk-visually-hidden',\n ...afterInput\n }\n }\n}\n\n/**\n * @import { ListItemReadonly } from '~/src/form/form-editor/types.js'\n * @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY;AACrB,SAASC,gBAAgB;AAEzB,OAAO,MAAMC,cAAc,SAASF,YAAY,CAAC;EAC/CG,iBAAiB,GAAGF,gBAAgB,CAACG,IAAI,GAAG,iBAAiB;EAC7DC,UAAU,GAAG,aAAa;EAC1B;AACF;AACA;EACEC,aAAa,GAAGP,aAAa,CAACQ,WAAW;;EAEzC;AACF;AACA;EACE,IAAIC,IAAIA,CAAA,EAAG;IACT,OAAO,IAAI,CAACC,QAAQ,CAAC,CAAC;EACxB;EAEA,IAAIC,WAAWA,CAAA,EAAG;IAChB,MAAMC,UAAU,GACd;IACE,IAAI,CAACH,IAAI,CAACI,MAAM,GACZ,CAAC,CAAC,GACF;MACEC,SAAS,EAAE;QACTF,UAAU,EAAE;UACVG,IAAI,EAAE,IAAI,CAACC,aAAa,CAACC;QAC3B;MACF;IACF,CACL;IAEH,OAAO;MACLC,EAAE,EAAE,IAAI,CAACZ,UAAU;MACnBa,IAAI,EAAE,IAAI,CAACb,UAAU;MACrBc,IAAI,EAAE,IAAI,CAACA,IAAI;MACfC,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBC,KAAK,EAAE,IAAI,CAACb,IAAI;MAChBc,OAAO,EAAE,IAAI,CAACd,IAAI,CAACI,MAAM,GAAG,EAAE,GAAG,uBAAuB;MACxD,GAAGD;IACL,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA","ignoreList":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/preview/types.ts"],"sourcesContent":["import {\n type PagePreviewPanelMacro,\n type QuestionBaseModel\n} from '~/src/form/form-editor/macros/types.js'\nimport { type AutocompleteQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { type DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { type EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { type ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { type LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { type PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { type Question } from '~/src/form/form-editor/preview/question.js'\nimport { type RadioSortableQuestion } from '~/src/form/form-editor/preview/radio-sortable.js'\nimport { type SelectSortableQuestion } from '~/src/form/form-editor/preview/select-sortable.js'\nimport { type ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { type UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { type ListElement } from '~/src/form/form-editor/types.js'\nexport { type QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'\nexport interface BaseSettings {\n question: string\n hintText: string\n optional: boolean\n shortDesc: string\n items: ListElement[]\n content: string\n}\n\nexport interface DefaultComponent {\n id?: string\n text: string\n classes: string\n}\n\nexport interface GovukFieldset {\n legend: DefaultComponent\n}\n\nexport type ListenerRow = [\n HTMLInputElement | null,\n (target: HTMLInputElement, e: Event) => void,\n keyof HTMLElementEventMap\n]\n\nexport interface DomElementsBase {\n readonly values?: BaseSettings\n autocompleteOptions?: string\n setPreviewHTML(value: string): void\n setPreviewDOM(element: HTMLElement): void\n}\n\nexport interface QuestionElements extends DomElementsBase {\n readonly values: BaseSettings\n}\n\nexport interface AutocompleteElements extends QuestionElements {\n autocompleteOptions: string\n}\n\nexport interface QuestionRenderContext {\n model: QuestionBaseModel\n}\n\nexport interface PageRenderContext {\n params: PagePreviewPanelMacro\n}\n\nexport type RenderContext = QuestionRenderContext | PageRenderContext\n\nexport interface HTMLBuilder {\n buildHTML(questionTemplate: string, renderContext: RenderContext): string\n}\n\nexport interface QuestionRenderer {\n render(questionTemplate: string, questionBaseModel: QuestionBaseModel): void\n}\n\nexport interface PageRenderer {\n render(pageTemplate: string, pagePreview: PagePreviewPanelMacro): void\n}\n\nexport type Renderer = QuestionRenderer | PageRenderer\n\nexport interface ListElements extends QuestionElements {\n afterInputsHTML: string\n}\n\nexport interface PageOverviewElements {\n heading: string\n guidance: string\n addHeading: boolean\n}\n\nexport type PreviewQuestion =\n | DateInputQuestion\n | EmailAddressQuestion\n | ListSortableQuestion\n | LongAnswerQuestion\n | PhoneNumberQuestion\n | Question\n | RadioSortableQuestion\n | SelectSortableQuestion\n | ShortAnswerQuestion\n | UkAddressQuestion\n | AutocompleteQuestion\n"],"mappings":"","ignoreList":[]}
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/preview/types.ts"],"sourcesContent":["import {\n type PagePreviewPanelMacro,\n type QuestionBaseModel\n} from '~/src/form/form-editor/macros/types.js'\nimport { type AutocompleteQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { type DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { type EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { type ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { type LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { type PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { type Question } from '~/src/form/form-editor/preview/question.js'\nimport { type RadioSortableQuestion } from '~/src/form/form-editor/preview/radio-sortable.js'\nimport { type SelectSortableQuestion } from '~/src/form/form-editor/preview/select-sortable.js'\nimport { type ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { type UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { type ListElement } from '~/src/form/form-editor/types.js'\nexport { type QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'\nexport interface BaseSettings {\n question: string\n hintText: string\n optional: boolean\n shortDesc: string\n items: ListElement[]\n content: string\n attributes?: Record<string, string>\n}\n\nexport interface DefaultComponent {\n id?: string\n text: string\n classes: string\n}\n\nexport interface GovukFieldset {\n legend: DefaultComponent\n}\n\nexport type ListenerRow = [\n HTMLInputElement | null,\n (target: HTMLInputElement, e: Event) => void,\n keyof HTMLElementEventMap\n]\n\nexport interface DomElementsBase {\n readonly values?: BaseSettings\n autocompleteOptions?: string\n setPreviewHTML(value: string): void\n setPreviewDOM(element: HTMLElement): void\n}\n\nexport interface QuestionElements extends DomElementsBase {\n readonly values: BaseSettings\n}\n\nexport interface AutocompleteElements extends QuestionElements {\n autocompleteOptions: string\n}\n\nexport interface RenderBase {\n render(questionTemplate: string, renderContext: RenderContext): void\n}\n\nexport interface QuestionRenderContext {\n model: QuestionBaseModel\n}\n\nexport interface PageRenderContext {\n params: PagePreviewPanelMacro\n}\n\nexport type RenderContext = QuestionRenderContext | PageRenderContext\n\nexport interface HTMLBuilder {\n buildHTML(questionTemplate: string, renderContext: RenderContext): string\n}\n\nexport interface QuestionRenderer {\n render(questionTemplate: string, questionBaseModel: QuestionBaseModel): void\n}\n\nexport interface PageRenderer {\n render(pageTemplate: string, pagePreview: PagePreviewPanelMacro): void\n}\n\nexport type Renderer = QuestionRenderer | PageRenderer\n\nexport interface ListElements extends QuestionElements {\n afterInputsHTML: string\n}\n\nexport interface PageOverviewElements {\n heading: string\n guidance: string\n addHeading: boolean\n}\n\nexport type PreviewQuestion =\n | DateInputQuestion\n | EmailAddressQuestion\n | ListSortableQuestion\n | LongAnswerQuestion\n | PhoneNumberQuestion\n | Question\n | RadioSortableQuestion\n | SelectSortableQuestion\n | ShortAnswerQuestion\n | UkAddressQuestion\n | AutocompleteQuestion\n"],"mappings":"","ignoreList":[]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ComponentType } from "../index.js";
|
1
|
+
import { ComponentType, hasFormField } from "../index.js";
|
2
2
|
import { ControllerNames, ControllerTypes } from "./controller-types.js";
|
3
3
|
import { ControllerType } from "./enums.js";
|
4
4
|
import { PageTypes } from "./page-types.js";
|
@@ -110,4 +110,22 @@ export function omitFileUploadComponent(page) {
|
|
110
110
|
}
|
111
111
|
return false;
|
112
112
|
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Gets page title, or title of first question (if no page title set)
|
116
|
+
* @param {Page} page
|
117
|
+
* @returns {string}
|
118
|
+
*/
|
119
|
+
export function getPageTitle(page) {
|
120
|
+
if (page.title !== '') {
|
121
|
+
return page.title;
|
122
|
+
}
|
123
|
+
if (hasComponentsEvenIfNoNext(page)) {
|
124
|
+
const firstComp = page.components.find(hasFormField);
|
125
|
+
if (firstComp) {
|
126
|
+
return firstComp.title;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return 'Page title unknown';
|
130
|
+
}
|
113
131
|
//# sourceMappingURL=helpers.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["ComponentType","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","omitFileUploadComponent","length"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { ComponentType } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nfunction includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page) && includesFileUploadField(page.components)) {\n return false\n }\n return true\n}\n\n/**\n * High level check for whether file upload component should be omitted\n * @param { Page | undefined } page\n * @returns {boolean}\n */\nexport function omitFileUploadComponent(page: Page | undefined): boolean {\n if (page?.controller === ControllerType.Repeat) {\n return true\n }\n if (!hasComponents(page)) {\n return false\n }\n if (page.components.length > 1) {\n return true\n }\n if (includesFileUploadField(page.components)) {\n return true\n }\n return false\n}\n"],"mappings":"AAQA,SAASA,aAAa;
|
1
|
+
{"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","omitFileUploadComponent","length","getPageTitle","title","firstComp"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { ComponentType, hasFormField } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nfunction includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page) && includesFileUploadField(page.components)) {\n return false\n }\n return true\n}\n\n/**\n * High level check for whether file upload component should be omitted\n * @param { Page | undefined } page\n * @returns {boolean}\n */\nexport function omitFileUploadComponent(page: Page | undefined): boolean {\n if (page?.controller === ControllerType.Repeat) {\n return true\n }\n if (!hasComponents(page)) {\n return false\n }\n if (page.components.length > 1) {\n return true\n }\n if (includesFileUploadField(page.components)) {\n return true\n }\n return false\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n"],"mappings":"AAQA,SAASA,aAAa,EAAEC,YAAY;AACpC,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAA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,uBAAuB,CAAC9B,IAAI,CAACc,UAAU,CAAC,EAAE;IACnE,OAAO,KAAK;EACd;EACA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASuB,uBAAuBA,CAACrC,IAAsB,EAAW;EACvE,IAAIA,IAAI,EAAEE,UAAU,KAAKL,cAAc,CAACuB,MAAM,EAAE;IAC9C,OAAO,IAAI;EACb;EACA,IAAI,CAACV,aAAa,CAACV,IAAI,CAAC,EAAE;IACxB,OAAO,KAAK;EACd;EACA,IAAIA,IAAI,CAACc,UAAU,CAACwB,MAAM,GAAG,CAAC,EAAE;IAC9B,OAAO,IAAI;EACb;EACA,IAAIR,uBAAuB,CAAC9B,IAAI,CAACc,UAAU,CAAC,EAAE;IAC5C,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASyB,YAAYA,CAACvC,IAAU,EAAE;EACvC,IAAIA,IAAI,CAACwC,KAAK,KAAK,EAAE,EAAE;IACrB,OAAOxC,IAAI,CAACwC,KAAK;EACnB;EAEA,IAAIzB,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,MAAMyC,SAAS,GAAGzC,IAAI,CAACc,UAAU,CAACR,IAAI,CAACZ,YAAY,CAAC;IACpD,IAAI+C,SAAS,EAAE;MACb,OAAOA,SAAS,CAACD,KAAK;IACxB;EACF;EACA,OAAO,oBAAoB;AAC7B","ignoreList":[]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export { ControllerNames, ControllerTypes } from "./controller-types.js";
|
2
2
|
export { PageTypes } from "./page-types.js";
|
3
|
-
export { controllerNameFromPath, getPageDefaults, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, isControllerName, omitFileUploadComponent, showRepeaterSettings } from "./helpers.js";
|
3
|
+
export { controllerNameFromPath, getPageDefaults, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, isControllerName, omitFileUploadComponent, showRepeaterSettings } from "./helpers.js";
|
4
4
|
export { ControllerPath, ControllerType } from "./enums.js";
|
5
5
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasRepeater","isControllerName","omitFileUploadComponent","showRepeaterSettings","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasRepeater,\n isControllerName,\n omitFileUploadComponent,\n showRepeaterSettings\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,uBAAuB,EACvBC,oBAAoB;AAGtB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
|
1
|
+
{"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","getPageTitle","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasRepeater","isControllerName","omitFileUploadComponent","showRepeaterSettings","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n getPageTitle,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasRepeater,\n isControllerName,\n omitFileUploadComponent,\n showRepeaterSettings\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,YAAY,EACZC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,uBAAuB,EACvBC,oBAAoB;AAGtB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
|
@@ -24,20 +24,28 @@ export interface AppPreviewPanelTabsMacro {
|
|
24
24
|
extraFields: GovukField[];
|
25
25
|
basePageFields: GovukField[];
|
26
26
|
}
|
27
|
+
export interface SelectAfterInput {
|
28
|
+
afterInput: {
|
29
|
+
html: string;
|
30
|
+
};
|
31
|
+
}
|
32
|
+
export interface RadioAndCheckboxAfterInputs {
|
33
|
+
afterInputs: {
|
34
|
+
html: string;
|
35
|
+
};
|
36
|
+
}
|
37
|
+
export type FormGroupAfterInput = SelectAfterInput | RadioAndCheckboxAfterInputs;
|
27
38
|
export interface QuestionBaseModel {
|
28
39
|
id?: string;
|
29
40
|
name?: string;
|
30
41
|
content?: string;
|
42
|
+
attributes?: Record<string, string>;
|
31
43
|
label?: DefaultComponent;
|
32
44
|
hint?: DefaultComponent;
|
33
45
|
fieldset?: GovukFieldset;
|
34
46
|
readonly items?: ListItemReadonly[] | DateItem[];
|
35
47
|
text?: string;
|
36
|
-
formGroup?:
|
37
|
-
afterInputs: {
|
38
|
-
html: string;
|
39
|
-
};
|
40
|
-
};
|
48
|
+
formGroup?: FormGroupAfterInput;
|
41
49
|
type?: 'text' | 'number' | 'boolean';
|
42
50
|
classes?: string;
|
43
51
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../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,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACnC,KAAK,CAAC,EAAE,gBAAgB,CAAA;IACxB,IAAI,CAAC,EAAE,gBAAgB,CAAA;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,EAAE,GAAG,QAAQ,EAAE,CAAA;IAChD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,mBAAmB,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE,KAAK,EAAE,iBAAiB,CAAA;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,iBAAiB,CAAA;IACxB,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,SAAS,EAAE;QAClB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,QAAQ,CAAC,QAAQ,EAAE;QACjB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,QAAQ,CAAC,UAAU,EAAE,oBAAoB,EAAE,CAAA;CAC5C"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/autocomplete.js"],"names":[],"mappings":"AAKA;
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/autocomplete.js"],"names":[],"mappings":"AAKA;CAqBC;AAED;IAME;;;OAGG;IACH,kCAHW,oBAAoB,oBACpB,gBAAgB,EAK1B;IAZD;;;OAGG;IACH,0BAAsB;IAUtB,sCAEC;IAED;;OAEG;IACH,8BAFW,MAAM,QAkBhB;IAED;;;;;;;;;MASC;CACF;yBA3EwB,4CAA4C;iCA+ErC,iCAAiC;0CACa,yCAAyC;sCAAzC,yCAAyC"}
|
@@ -7,16 +7,13 @@ export class FieldsetQuestion extends Question {
|
|
7
7
|
id: string;
|
8
8
|
name: string;
|
9
9
|
content?: string | undefined;
|
10
|
+
attributes?: Record<string, string> | undefined;
|
10
11
|
label?: import("./types.js").DefaultComponent | undefined;
|
11
12
|
hint: import("./types.js").DefaultComponent;
|
12
13
|
fieldset: import("./types.js").GovukFieldset;
|
13
14
|
items?: import("../types.js").ListItemReadonly[] | import("../types.js").DateItem[];
|
14
15
|
text?: string | undefined;
|
15
|
-
formGroup?:
|
16
|
-
afterInputs: {
|
17
|
-
html: string;
|
18
|
-
};
|
19
|
-
} | undefined;
|
16
|
+
formGroup?: import("../macros/types.js").FormGroupAfterInput | undefined;
|
20
17
|
type?: "text" | "number" | "boolean" | undefined;
|
21
18
|
classes?: string | undefined;
|
22
19
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fieldset-question.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/fieldset-question.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH;IAME
|
1
|
+
{"version":3,"file":"fieldset-question.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/fieldset-question.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH;IAME;;;;;;;;;;;;;MAQC;CACF;yBArBwB,4CAA4C"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/helpers.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/helpers.js"],"names":[],"mappings":"AAyDA;;;;GAIG;AACH,gEAJW,gBAAgB,cAChB,cAAc,GACZ,CAAC,SAAS,EAAE,YAAY,KAAK,QAAQ,CAmCjD;sCAGsD,yCAAyC;oCAGvD,qCAAqC;kCAC1B,2BAA2B;8BAHlD,4CAA4C"}
|
@@ -29,6 +29,11 @@ export class ListComponentElements extends QuestionComponentElements implements
|
|
29
29
|
*/
|
30
30
|
protected _list: List;
|
31
31
|
}
|
32
|
+
/**
|
33
|
+
* @implements {QuestionElements}
|
34
|
+
*/
|
35
|
+
export class SelectComponentElements extends ListComponentElements implements QuestionElements {
|
36
|
+
}
|
32
37
|
export class ListQuestion extends Question {
|
33
38
|
/**
|
34
39
|
* @param {ListElements} listElements
|
@@ -44,9 +49,28 @@ export class ListQuestion extends Question {
|
|
44
49
|
* @protected
|
45
50
|
*/
|
46
51
|
protected _list: Map<string, ListElement>;
|
52
|
+
/**
|
53
|
+
* @protected
|
54
|
+
* @returns {{
|
55
|
+
* formGroup?: FormGroupAfterInput;
|
56
|
+
* hint: DefaultComponent;
|
57
|
+
* name: string;
|
58
|
+
* fieldset?: GovukFieldset;
|
59
|
+
* id: string;
|
60
|
+
* items: ListItemReadonly[]
|
61
|
+
* }}
|
62
|
+
*/
|
63
|
+
protected _renderInput(): {
|
64
|
+
formGroup?: FormGroupAfterInput;
|
65
|
+
hint: DefaultComponent;
|
66
|
+
name: string;
|
67
|
+
fieldset?: GovukFieldset;
|
68
|
+
id: string;
|
69
|
+
items: ListItemReadonly[];
|
70
|
+
};
|
47
71
|
/**
|
48
72
|
* @returns {{
|
49
|
-
* formGroup?:
|
73
|
+
* formGroup?: FormGroupAfterInput;
|
50
74
|
* hint: DefaultComponent;
|
51
75
|
* name: string;
|
52
76
|
* fieldset?: GovukFieldset;
|
@@ -55,11 +79,7 @@ export class ListQuestion extends Question {
|
|
55
79
|
* }}
|
56
80
|
*/
|
57
81
|
get renderInput(): {
|
58
|
-
formGroup?:
|
59
|
-
afterInputs: {
|
60
|
-
html: string;
|
61
|
-
};
|
62
|
-
};
|
82
|
+
formGroup?: FormGroupAfterInput;
|
63
83
|
hint: DefaultComponent;
|
64
84
|
name: string;
|
65
85
|
fieldset?: GovukFieldset;
|
@@ -80,6 +100,11 @@ export class ListQuestion extends Question {
|
|
80
100
|
* @returns {Map<string, ListElement>}
|
81
101
|
*/
|
82
102
|
createListFromElements(listElements: ListElement[]): Map<string, ListElement>;
|
103
|
+
/**
|
104
|
+
* @protected
|
105
|
+
* @returns {ListItemReadonly[]}
|
106
|
+
*/
|
107
|
+
protected _getList(): ListItemReadonly[];
|
83
108
|
/**
|
84
109
|
* @returns {ListItemReadonly[]}
|
85
110
|
*/
|
@@ -110,6 +135,7 @@ import type { List } from '../../../form/form-definition/types.js';
|
|
110
135
|
import type { SelectionComponentsDef } from '../../../components/types.js';
|
111
136
|
import { Question } from '../../../form/form-editor/preview/question.js';
|
112
137
|
import type { ListElements } from '../../../form/form-editor/preview/types.js';
|
138
|
+
import type { FormGroupAfterInput } from '../../../form/form-editor/macros/types.js';
|
113
139
|
import type { DefaultComponent } from '../../../form/form-editor/preview/types.js';
|
114
140
|
import type { GovukFieldset } from '../../../form/form-editor/preview/types.js';
|
115
141
|
import type { ListItemReadonly } from '../../../form/form-editor/types.js';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/list.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,4CAHW,WAAW,GACT,CAAC,MAAM,EAAE,WAAW,CAAC,CAIjC;AAED;;;;GAIG;AACH,gDAHY,WAAW,EAAE,GAAE,SAAS,GACvB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAKpC;AAED;;;GAGG;AACH,4CAHW,IAAI,GACF,WAAW,CAavB;AAED;;GAEG;AACH;IAOE;;;OAGG;IACH,uBAHW,sBAAsB,QACtB,IAAI,EAKd;IAbD;;;OAGG;IACH,iBAHU,IAAI,CAGT;CAqBN;AAED;IAqBE;;;OAGG;IACH,0BAHW,YAAY,oBACZ,gBAAgB,EAQ1B;IArBD,2BAA2B;IAC3B,eADW,YAAY,CACV;IACb,qBAAqC;IACrC,uBAA4C;IAE5C;;;OAGG;IACH,iBAHU,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAG7B;IAcL
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/list.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,4CAHW,WAAW,GACT,CAAC,MAAM,EAAE,WAAW,CAAC,CAIjC;AAED;;;;GAIG;AACH,gDAHY,WAAW,EAAE,GAAE,SAAS,GACvB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAKpC;AAED;;;GAGG;AACH,4CAHW,IAAI,GACF,WAAW,CAavB;AAED;;GAEG;AACH;IAOE;;;OAGG;IACH,uBAHW,sBAAsB,QACtB,IAAI,EAKd;IAbD;;;OAGG;IACH,iBAHU,IAAI,CAGT;CAqBN;AAED;;GAEG;AACH;CAoBC;AAED;IAqBE;;;OAGG;IACH,0BAHW,YAAY,oBACZ,gBAAgB,EAQ1B;IArBD,2BAA2B;IAC3B,eADW,YAAY,CACV;IACb,qBAAqC;IACrC,uBAA4C;IAE5C;;;OAGG;IACH,iBAHU,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAG7B;IAcL;;;;;;;;;;OAUG;IACH,0BATa;QACT,SAAS,CAAC,EAAE,mBAAmB,CAAC;QAChC,IAAI,EAAE,gBAAgB,CAAC;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,gBAAgB,EAAE,CAAA;KACzB,CAuBH;IAED;;;;;;;;;OASG;IACH,mBATa;QACT,SAAS,CAAC,EAAE,mBAAmB,CAAC;QAChC,IAAI,EAAE,gBAAgB,CAAC;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,gBAAgB,EAAE,CAAA;KACzB,CAIH;IAED;;;OAGG;IACH,kBAFW,WAAW,QAKrB;IAED;;OAEG;IACH,YAFW,MAAM,QAKhB;IAED;;;OAGG;IACH,qCAHW,WAAW,EAAE,GACX,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAKpC;IAED;;;OAGG;IACH,sBAFa,gBAAgB,EAAE,CAiC9B;IAED;;OAEG;IACH,YAFa,gBAAgB,EAAE,CAa9B;IAED;;;;OAIG;IACH,eAHW,MAAM,GAAG,SAAS,QAClB,MAAM,QAYhB;IAED;;;;OAIG;IACH,eAHW,MAAM,GAAG,SAAS,QAClB,MAAM,QAehB;IAED;;;OAGG;IACH,gBAHW,MAAM,GAAG,SAAS,SAClB,MAAM,QAYhB;CACF;iCAGiD,iCAAiC;0BAEpD,qCAAqC;sCAEgD,yCAAyC;0CAhUtJ,4CAA4C;0BA8TpB,qCAAqC;4CADN,2BAA2B;yBA7TlF,4CAA4C;kCAgUiE,yCAAyC;yCADpH,wCAAwC;sCACmC,yCAAyC;mCAAzC,yCAAyC;sCAJ3G,iCAAiC;sCAIiC,yCAAyC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select-sortable.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/select-sortable.js"],"names":[],"mappings":"AAIA;IAGE,8DAIC;IAOD;oBAE6B;YAAE,
|
1
|
+
{"version":3,"file":"select-sortable.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/select-sortable.js"],"names":[],"mappings":"AAIA;IAGE,8DAIC;IAOD;oBAE6B;YAAE,UAAU,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAA;SAAC;;;;;;;MAqB3D;CACF;qCA1CoC,iDAAiD"}
|
@@ -1,4 +1,18 @@
|
|
1
1
|
export class SelectQuestion extends ListQuestion {
|
2
|
+
get renderInput(): {
|
3
|
+
formGroup?: {
|
4
|
+
afterInput: {
|
5
|
+
html: string;
|
6
|
+
};
|
7
|
+
};
|
8
|
+
id: string;
|
9
|
+
name: string;
|
10
|
+
hint: import("./types.js").DefaultComponent;
|
11
|
+
label: import("./types.js").DefaultComponent;
|
12
|
+
items: ListItemReadonly[];
|
13
|
+
classes: string;
|
14
|
+
};
|
2
15
|
}
|
3
16
|
import { ListQuestion } from '../../../form/form-editor/preview/list.js';
|
17
|
+
import type { ListItemReadonly } from '../../../form/form-editor/types.js';
|
4
18
|
//# sourceMappingURL=select.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/select.js"],"names":[],"mappings":"AAIA;
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/select.js"],"names":[],"mappings":"AAIA;IAeE;oBAE6B;YAAE,UAAU,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAA;SAAC;;;;;;;MAqB3D;CACF;6BA1C4B,wCAAwC;sCA6ChC,iCAAiC"}
|
@@ -19,6 +19,7 @@ export interface BaseSettings {
|
|
19
19
|
shortDesc: string;
|
20
20
|
items: ListElement[];
|
21
21
|
content: string;
|
22
|
+
attributes?: Record<string, string>;
|
22
23
|
}
|
23
24
|
export interface DefaultComponent {
|
24
25
|
id?: string;
|
@@ -45,6 +46,9 @@ export interface QuestionElements extends DomElementsBase {
|
|
45
46
|
export interface AutocompleteElements extends QuestionElements {
|
46
47
|
autocompleteOptions: string;
|
47
48
|
}
|
49
|
+
export interface RenderBase {
|
50
|
+
render(questionTemplate: string, renderContext: RenderContext): void;
|
51
|
+
}
|
48
52
|
export interface QuestionRenderContext {
|
49
53
|
model: QuestionBaseModel;
|
50
54
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/types.ts"],"names":[],"mappings":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AM,QAAQ,GAAG,gBAAgB,GAAG,YAAY,CAAA;AAEtD,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,eAAe,GACvB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,mBAAmB,GACnB,QAAQ,GACR,qBAAqB,GACrB,sBAAsB,GACtB,mBAAmB,GACnB,iBAAiB,GACjB,oBAAoB,CAAA"}
|
@@ -47,4 +47,10 @@ export declare function showRepeaterSettings(page: Page): boolean;
|
|
47
47
|
* @returns {boolean}
|
48
48
|
*/
|
49
49
|
export declare function omitFileUploadComponent(page: Page | undefined): boolean;
|
50
|
+
/**
|
51
|
+
* Gets page title, or title of first question (if no page title set)
|
52
|
+
* @param {Page} page
|
53
|
+
* @returns {string}
|
54
|
+
*/
|
55
|
+
export declare function getPageTitle(page: Page): string;
|
50
56
|
//# sourceMappingURL=helpers.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pages/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,qCAAqC,CAAA;AAM5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,IAAI,EACnD,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,GAaC,QAAQ,CAC7C;AAED;;GAEG;AACH,wBAAgB,a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B,CAAC,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,8BAO1E;AAUD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAQxD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,CAcvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,UAYtC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export { ControllerNames, ControllerTypes } from '../pages/controller-types.js';
|
2
2
|
export { PageTypes } from '../pages/page-types.js';
|
3
|
-
export { controllerNameFromPath, getPageDefaults, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, isControllerName, omitFileUploadComponent, showRepeaterSettings } from '../pages/helpers.js';
|
3
|
+
export { controllerNameFromPath, getPageDefaults, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, isControllerName, omitFileUploadComponent, showRepeaterSettings } from '../pages/helpers.js';
|
4
4
|
export { ControllerPath, ControllerType } from '../pages/enums.js';
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
package/package.json
CHANGED
@@ -29,16 +29,27 @@ export interface AppPreviewPanelTabsMacro {
|
|
29
29
|
basePageFields: GovukField[]
|
30
30
|
}
|
31
31
|
|
32
|
+
export interface SelectAfterInput {
|
33
|
+
afterInput: { html: string }
|
34
|
+
}
|
35
|
+
export interface RadioAndCheckboxAfterInputs {
|
36
|
+
afterInputs: { html: string }
|
37
|
+
}
|
38
|
+
|
39
|
+
// GDS components - Select uses afterInput, while Radio uses afterInputs
|
40
|
+
export type FormGroupAfterInput = SelectAfterInput | RadioAndCheckboxAfterInputs
|
41
|
+
|
32
42
|
export interface QuestionBaseModel {
|
33
43
|
id?: string
|
34
44
|
name?: string
|
35
45
|
content?: string
|
46
|
+
attributes?: Record<string, string>
|
36
47
|
label?: DefaultComponent
|
37
48
|
hint?: DefaultComponent
|
38
49
|
fieldset?: GovukFieldset
|
39
50
|
readonly items?: ListItemReadonly[] | DateItem[]
|
40
51
|
text?: string
|
41
|
-
formGroup?:
|
52
|
+
formGroup?: FormGroupAfterInput
|
42
53
|
type?: 'text' | 'number' | 'boolean'
|
43
54
|
classes?: string
|
44
55
|
}
|
@@ -5,7 +5,10 @@ import { ComponentElements } from '~/src/form/form-editor/preview/component-elem
|
|
5
5
|
import { ContentElements } from '~/src/form/form-editor/preview/content.js'
|
6
6
|
import { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'
|
7
7
|
import { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'
|
8
|
-
import {
|
8
|
+
import {
|
9
|
+
ListQuestion,
|
10
|
+
SelectComponentElements
|
11
|
+
} from '~/src/form/form-editor/preview/list.js'
|
9
12
|
import { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'
|
10
13
|
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
11
14
|
import { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'
|
@@ -65,7 +68,13 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
65
68
|
*/
|
66
69
|
let questionElements
|
67
70
|
|
68
|
-
if (
|
71
|
+
if (
|
72
|
+
component.type === ComponentType.AutocompleteField ||
|
73
|
+
component.type === ComponentType.SelectField
|
74
|
+
) {
|
75
|
+
const list = findDefinitionListFromComponent(component, definition)
|
76
|
+
questionElements = new SelectComponentElements(component, list)
|
77
|
+
} else if (hasSelectionFields(component) && hasListField(component)) {
|
69
78
|
const list = findDefinitionListFromComponent(component, definition)
|
70
79
|
questionElements = new ListComponentElements(component, list)
|
71
80
|
} else if (
|
@@ -79,6 +79,31 @@ export class ListComponentElements extends QuestionComponentElements {
|
|
79
79
|
}
|
80
80
|
}
|
81
81
|
|
82
|
+
/**
|
83
|
+
* @implements {QuestionElements}
|
84
|
+
*/
|
85
|
+
export class SelectComponentElements extends ListComponentElements {
|
86
|
+
/**
|
87
|
+
* @returns {BaseSettings}
|
88
|
+
* @protected
|
89
|
+
*/
|
90
|
+
_getValues() {
|
91
|
+
const emptyItem = /** @type {ListElement} */ ({
|
92
|
+
id: 'da310b6e-2513-4d14-a7a1-63a93231891d',
|
93
|
+
text: '',
|
94
|
+
value: ''
|
95
|
+
})
|
96
|
+
const items = /** @type {ListElement[]} */ ([
|
97
|
+
emptyItem,
|
98
|
+
...super._getValues().items
|
99
|
+
])
|
100
|
+
return {
|
101
|
+
...super._getValues(),
|
102
|
+
items
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
82
107
|
export class ListQuestion extends Question {
|
83
108
|
/**
|
84
109
|
* @type {ComponentType}
|
@@ -113,8 +138,9 @@ export class ListQuestion extends Question {
|
|
113
138
|
}
|
114
139
|
|
115
140
|
/**
|
141
|
+
* @protected
|
116
142
|
* @returns {{
|
117
|
-
* formGroup?:
|
143
|
+
* formGroup?: FormGroupAfterInput;
|
118
144
|
* hint: DefaultComponent;
|
119
145
|
* name: string;
|
120
146
|
* fieldset?: GovukFieldset;
|
@@ -122,19 +148,18 @@ export class ListQuestion extends Question {
|
|
122
148
|
* items: ListItemReadonly[]
|
123
149
|
* }}
|
124
150
|
*/
|
125
|
-
|
126
|
-
const afterInputs =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
html: this._listElements.afterInputsHTML
|
134
|
-
}
|
151
|
+
_renderInput() {
|
152
|
+
const afterInputs = /** @type {{ formGroup?: FormGroupAfterInput }} */ (
|
153
|
+
this.list.length
|
154
|
+
? {}
|
155
|
+
: {
|
156
|
+
formGroup: {
|
157
|
+
afterInputs: {
|
158
|
+
html: this._listElements.afterInputsHTML
|
135
159
|
}
|
136
160
|
}
|
137
|
-
|
161
|
+
}
|
162
|
+
)
|
138
163
|
|
139
164
|
return {
|
140
165
|
id: this.listRenderId,
|
@@ -146,6 +171,20 @@ export class ListQuestion extends Question {
|
|
146
171
|
}
|
147
172
|
}
|
148
173
|
|
174
|
+
/**
|
175
|
+
* @returns {{
|
176
|
+
* formGroup?: FormGroupAfterInput;
|
177
|
+
* hint: DefaultComponent;
|
178
|
+
* name: string;
|
179
|
+
* fieldset?: GovukFieldset;
|
180
|
+
* id: string;
|
181
|
+
* items: ListItemReadonly[]
|
182
|
+
* }}
|
183
|
+
*/
|
184
|
+
get renderInput() {
|
185
|
+
return this._renderInput()
|
186
|
+
}
|
187
|
+
|
149
188
|
/**
|
150
189
|
*
|
151
190
|
* @param {ListElement} listElement
|
@@ -173,9 +212,10 @@ export class ListQuestion extends Question {
|
|
173
212
|
}
|
174
213
|
|
175
214
|
/**
|
215
|
+
* @protected
|
176
216
|
* @returns {ListItemReadonly[]}
|
177
217
|
*/
|
178
|
-
|
218
|
+
_getList() {
|
179
219
|
const iterator = /** @type {MapIterator<ListElement>} */ (
|
180
220
|
this._list.values()
|
181
221
|
)
|
@@ -194,7 +234,7 @@ export class ListQuestion extends Question {
|
|
194
234
|
: undefined
|
195
235
|
}
|
196
236
|
|
197
|
-
const text = listItem.text
|
237
|
+
const text = listItem.text
|
198
238
|
|
199
239
|
return {
|
200
240
|
...listItem,
|
@@ -208,6 +248,22 @@ export class ListQuestion extends Question {
|
|
208
248
|
})
|
209
249
|
}
|
210
250
|
|
251
|
+
/**
|
252
|
+
* @returns {ListItemReadonly[]}
|
253
|
+
*/
|
254
|
+
get list() {
|
255
|
+
const list = this._getList()
|
256
|
+
|
257
|
+
return list.map((listItem) => {
|
258
|
+
const text = listItem.text.length ? listItem.text : 'Item text'
|
259
|
+
|
260
|
+
return {
|
261
|
+
...listItem,
|
262
|
+
text
|
263
|
+
}
|
264
|
+
})
|
265
|
+
}
|
266
|
+
|
211
267
|
/**
|
212
268
|
*
|
213
269
|
* @param {string | undefined} id
|
@@ -266,5 +322,6 @@ export class ListQuestion extends Question {
|
|
266
322
|
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
267
323
|
* @import { SelectionComponentsDef, ListComponentsDef } from '~/src/components/types.js'
|
268
324
|
* @import { List, Item } from '~/src/form/form-definition/types.js'
|
325
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
269
326
|
* @import { ListElements, QuestionRenderer, DefaultComponent, GovukFieldset, BaseSettings, QuestionElements } from '~/src/form/form-editor/preview/types.js'
|
270
327
|
*/
|
@@ -18,7 +18,7 @@ export class SelectSortableQuestion extends ListSortableQuestion {
|
|
18
18
|
|
19
19
|
get renderInput() {
|
20
20
|
const afterInput =
|
21
|
-
/** @type {{ formGroup?: {
|
21
|
+
/** @type {{ formGroup?: { afterInput: { html: string }} }} */ (
|
22
22
|
this.list.length
|
23
23
|
? {}
|
24
24
|
: {
|
@@ -41,3 +41,7 @@ export class SelectSortableQuestion extends ListSortableQuestion {
|
|
41
41
|
}
|
42
42
|
}
|
43
43
|
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
47
|
+
*/
|
@@ -4,8 +4,46 @@ import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
4
4
|
|
5
5
|
export class SelectQuestion extends ListQuestion {
|
6
6
|
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk'
|
7
|
+
_fieldName = 'selectInput'
|
7
8
|
/**
|
8
9
|
* @type {ComponentType}
|
9
10
|
*/
|
10
11
|
componentType = ComponentType.SelectField
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @returns {ListItemReadonly[]}
|
15
|
+
*/
|
16
|
+
get list() {
|
17
|
+
return this._getList()
|
18
|
+
}
|
19
|
+
|
20
|
+
get renderInput() {
|
21
|
+
const afterInput =
|
22
|
+
/** @type {{ formGroup?: { afterInput: { html: string }} }} */ (
|
23
|
+
this.list.length
|
24
|
+
? {}
|
25
|
+
: {
|
26
|
+
formGroup: {
|
27
|
+
afterInput: {
|
28
|
+
html: this._listElements.afterInputsHTML
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
)
|
33
|
+
|
34
|
+
return {
|
35
|
+
id: this._fieldName,
|
36
|
+
name: this._fieldName,
|
37
|
+
hint: this.hint,
|
38
|
+
label: this.label,
|
39
|
+
items: this.list,
|
40
|
+
classes: this.list.length ? '' : 'govuk-visually-hidden',
|
41
|
+
...afterInput
|
42
|
+
}
|
43
|
+
}
|
11
44
|
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @import { ListItemReadonly } from '~/src/form/form-editor/types.js'
|
48
|
+
* @import { FormGroupAfterInput } from '~/src/form/form-editor/macros/types.js'
|
49
|
+
*/
|
@@ -22,6 +22,7 @@ export interface BaseSettings {
|
|
22
22
|
shortDesc: string
|
23
23
|
items: ListElement[]
|
24
24
|
content: string
|
25
|
+
attributes?: Record<string, string>
|
25
26
|
}
|
26
27
|
|
27
28
|
export interface DefaultComponent {
|
@@ -55,6 +56,10 @@ export interface AutocompleteElements extends QuestionElements {
|
|
55
56
|
autocompleteOptions: string
|
56
57
|
}
|
57
58
|
|
59
|
+
export interface RenderBase {
|
60
|
+
render(questionTemplate: string, renderContext: RenderContext): void
|
61
|
+
}
|
62
|
+
|
58
63
|
export interface QuestionRenderContext {
|
59
64
|
model: QuestionBaseModel
|
60
65
|
}
|
package/src/pages/helpers.ts
CHANGED
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
type PageQuestion,
|
7
7
|
type PageRepeat
|
8
8
|
} from '~/src/form/form-definition/types.js'
|
9
|
-
import { ComponentType } from '~/src/index.js'
|
9
|
+
import { ComponentType, hasFormField } from '~/src/index.js'
|
10
10
|
import {
|
11
11
|
ControllerNames,
|
12
12
|
ControllerTypes
|
@@ -153,3 +153,22 @@ export function omitFileUploadComponent(page: Page | undefined): boolean {
|
|
153
153
|
}
|
154
154
|
return false
|
155
155
|
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Gets page title, or title of first question (if no page title set)
|
159
|
+
* @param {Page} page
|
160
|
+
* @returns {string}
|
161
|
+
*/
|
162
|
+
export function getPageTitle(page: Page) {
|
163
|
+
if (page.title !== '') {
|
164
|
+
return page.title
|
165
|
+
}
|
166
|
+
|
167
|
+
if (hasComponentsEvenIfNoNext(page)) {
|
168
|
+
const firstComp = page.components.find(hasFormField)
|
169
|
+
if (firstComp) {
|
170
|
+
return firstComp.title
|
171
|
+
}
|
172
|
+
}
|
173
|
+
return 'Page title unknown'
|
174
|
+
}
|