@defra/forms-engine-plugin 0.1.11 → 0.1.12
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/.public/javascripts/file-upload.min.js +1 -1
- package/.public/javascripts/file-upload.min.js.map +1 -1
- package/.server/client/javascripts/file-upload.js +45 -4
- package/.server/client/javascripts/file-upload.js.map +1 -1
- package/.server/server/constants.js +2 -0
- package/.server/server/constants.js.map +1 -1
- package/.server/server/index.js +1 -1
- package/.server/server/index.js.map +1 -1
- package/.server/server/plugins/engine/components/AutocompleteField.js +2 -0
- package/.server/server/plugins/engine/components/AutocompleteField.js.map +1 -1
- package/.server/server/plugins/engine/components/CheckboxesField.js +3 -4
- package/.server/server/plugins/engine/components/CheckboxesField.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js +37 -16
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/DatePartsField.js +36 -2
- package/.server/server/plugins/engine/components/DatePartsField.js.map +1 -1
- package/.server/server/plugins/engine/components/EmailAddressField.js +19 -3
- package/.server/server/plugins/engine/components/EmailAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/FileUploadField.js +44 -4
- package/.server/server/plugins/engine/components/FileUploadField.js.map +1 -1
- package/.server/server/plugins/engine/components/FormComponent.js +14 -2
- package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/ListFormComponent.js +16 -3
- package/.server/server/plugins/engine/components/ListFormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/Markdown.js +24 -0
- package/.server/server/plugins/engine/components/Markdown.js.map +1 -0
- package/.server/server/plugins/engine/components/MonthYearField.js +30 -2
- package/.server/server/plugins/engine/components/MonthYearField.js.map +1 -1
- package/.server/server/plugins/engine/components/MultilineTextField.js +32 -3
- package/.server/server/plugins/engine/components/MultilineTextField.js.map +1 -1
- package/.server/server/plugins/engine/components/NumberField.js +28 -3
- package/.server/server/plugins/engine/components/NumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/SelectionControlField.js +14 -0
- package/.server/server/plugins/engine/components/SelectionControlField.js.map +1 -1
- package/.server/server/plugins/engine/components/TelephoneNumberField.js +19 -3
- package/.server/server/plugins/engine/components/TelephoneNumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/TextField.js +22 -3
- package/.server/server/plugins/engine/components/TextField.js.map +1 -1
- package/.server/server/plugins/engine/components/UkAddressField.js +29 -0
- package/.server/server/plugins/engine/components/UkAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/YesNoField.js +18 -0
- package/.server/server/plugins/engine/components/YesNoField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers.js +16 -0
- package/.server/server/plugins/engine/components/helpers.js.map +1 -1
- package/.server/server/plugins/engine/components/index.js +1 -0
- package/.server/server/plugins/engine/components/index.js.map +1 -1
- package/.server/server/plugins/engine/configureEnginePlugin.js +3 -1
- package/.server/server/plugins/engine/configureEnginePlugin.js.map +1 -1
- package/.server/server/plugins/engine/helpers.js +38 -18
- package/.server/server/plugins/engine/helpers.js.map +1 -1
- package/.server/server/plugins/engine/models/FormModel.js +60 -2
- package/.server/server/plugins/engine/models/FormModel.js.map +1 -1
- package/.server/server/plugins/engine/models/SummaryViewModel.js +3 -2
- package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js +1 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/PageController.js +13 -5
- package/.server/server/plugins/engine/pageControllers/PageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js +2 -2
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +19 -5
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js +6 -11
- package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
- package/.server/server/plugins/engine/plugin.js +5 -4
- package/.server/server/plugins/engine/plugin.js.map +1 -1
- package/.server/server/plugins/engine/services/notifyService.js +1 -4
- package/.server/server/plugins/engine/services/notifyService.js.map +1 -1
- package/.server/server/plugins/engine/services/uploadService.js +5 -3
- package/.server/server/plugins/engine/services/uploadService.js.map +1 -1
- package/.server/server/plugins/engine/types.js.map +1 -1
- package/.server/server/plugins/engine/views/components/html.html +1 -1
- package/.server/server/plugins/engine/views/components/markdown.html +5 -0
- package/.server/server/plugins/engine/views/summary.html +7 -1
- package/.server/server/plugins/nunjucks/context.js +6 -5
- package/.server/server/plugins/nunjucks/context.js.map +1 -1
- package/.server/server/plugins/nunjucks/enviroment.test.js +6 -3
- package/.server/server/plugins/nunjucks/enviroment.test.js.map +1 -1
- package/.server/server/utils/type-utils.js +8 -0
- package/.server/server/utils/type-utils.js.map +1 -0
- package/.server/typings/joi/index.d.js.map +1 -1
- package/package.json +3 -3
- package/src/client/javascripts/file-upload.js +60 -4
- package/src/server/constants.js +2 -0
- package/src/server/index.test.ts +34 -29
- package/src/server/index.ts +2 -1
- package/src/server/plugins/engine/components/AutocompleteField.test.ts +71 -3
- package/src/server/plugins/engine/components/AutocompleteField.ts +6 -2
- package/src/server/plugins/engine/components/CheckboxesField.test.ts +40 -8
- package/src/server/plugins/engine/components/CheckboxesField.ts +7 -3
- package/src/server/plugins/engine/components/ComponentCollection.ts +45 -18
- package/src/server/plugins/engine/components/DatePartsField.test.ts +13 -4
- package/src/server/plugins/engine/components/DatePartsField.ts +29 -8
- package/src/server/plugins/engine/components/EmailAddressField.test.ts +51 -1
- package/src/server/plugins/engine/components/EmailAddressField.ts +17 -2
- package/src/server/plugins/engine/components/FileUploadField.test.ts +53 -0
- package/src/server/plugins/engine/components/FileUploadField.ts +52 -3
- package/src/server/plugins/engine/components/FormComponent.ts +24 -2
- package/src/server/plugins/engine/components/ListFormComponent.ts +16 -2
- package/src/server/plugins/engine/components/Markdown.test.ts +48 -0
- package/src/server/plugins/engine/components/Markdown.ts +29 -0
- package/src/server/plugins/engine/components/MonthYearField.test.ts +35 -0
- package/src/server/plugins/engine/components/MonthYearField.ts +34 -9
- package/src/server/plugins/engine/components/MultilineTextField.test.ts +83 -5
- package/src/server/plugins/engine/components/MultilineTextField.ts +37 -2
- package/src/server/plugins/engine/components/NumberField.test.ts +24 -2
- package/src/server/plugins/engine/components/NumberField.ts +23 -3
- package/src/server/plugins/engine/components/RadiosField.test.ts +10 -1
- package/src/server/plugins/engine/components/SelectField.test.ts +2 -1
- package/src/server/plugins/engine/components/SelectionControlField.ts +14 -0
- package/src/server/plugins/engine/components/TelephoneNumberField.test.ts +30 -2
- package/src/server/plugins/engine/components/TelephoneNumberField.ts +17 -2
- package/src/server/plugins/engine/components/TextField.test.ts +33 -1
- package/src/server/plugins/engine/components/TextField.ts +17 -2
- package/src/server/plugins/engine/components/UkAddressField.test.ts +46 -3
- package/src/server/plugins/engine/components/UkAddressField.ts +28 -0
- package/src/server/plugins/engine/components/YesNoField.test.ts +9 -1
- package/src/server/plugins/engine/components/YesNoField.ts +24 -0
- package/src/server/plugins/engine/components/helpers.test.ts +24 -0
- package/src/server/plugins/engine/components/helpers.ts +39 -0
- package/src/server/plugins/engine/components/index.ts +1 -0
- package/src/server/plugins/engine/configureEnginePlugin.ts +13 -3
- package/src/server/plugins/engine/helpers.test.ts +71 -20
- package/src/server/plugins/engine/helpers.ts +46 -19
- package/src/server/plugins/engine/models/FormModel.test.ts +91 -1
- package/src/server/plugins/engine/models/FormModel.ts +86 -3
- package/src/server/plugins/engine/models/SummaryViewModel.test.ts +46 -7
- package/src/server/plugins/engine/models/SummaryViewModel.ts +7 -3
- package/src/server/plugins/engine/outputFormatters/human/v1.test.ts +1 -2
- package/src/server/plugins/engine/outputFormatters/human/v1.ts +1 -1
- package/src/server/plugins/engine/pageControllers/FileUploadPageController.test.ts +1 -0
- package/src/server/plugins/engine/pageControllers/PageController.test.ts +9 -6
- package/src/server/plugins/engine/pageControllers/PageController.ts +15 -5
- package/src/server/plugins/engine/pageControllers/QuestionPageController.ts +2 -2
- package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +21 -6
- package/src/server/plugins/engine/pageControllers/validationOptions.ts +31 -17
- package/src/server/plugins/engine/plugin.ts +9 -5
- package/src/server/plugins/engine/services/notifyService.ts +1 -2
- package/src/server/plugins/engine/services/uploadService.js +10 -6
- package/src/server/plugins/engine/types.ts +10 -1
- package/src/server/plugins/engine/views/components/html.html +1 -1
- package/src/server/plugins/engine/views/components/markdown.html +5 -0
- package/src/server/plugins/engine/views/summary.html +7 -1
- package/src/server/plugins/nunjucks/context.js +4 -4
- package/src/server/plugins/nunjucks/enviroment.test.js +9 -3
- package/src/server/utils/type-utils.ts +15 -0
- package/src/typings/joi/index.d.ts +8 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListFormComponent.js","names":["joi","FormComponent","ListFormComponent","list","listType","items","values","map","value","constructor","def","props","options","
|
|
1
|
+
{"version":3,"file":"ListFormComponent.js","names":["joi","FormComponent","messageTemplate","ListFormComponent","list","listType","items","values","map","value","constructor","def","props","options","model","getList","type","formSchema","valid","label","required","customValidationMessages","messages","stateSchema","default","allow","getFormValueFromState","state","name","isValue","flat","selected","filter","item","includes","at","getDisplayStringFromState","text","join","getViewModel","payload","errors","listItems","viewModel","itemModel","description","hint","getAllPossibleErrors","baseErrors","template","selectRequired","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/ListFormComponent.ts"],"sourcesContent":["import {\n type Item,\n type List,\n type ListComponentsDef,\n type SelectionComponentsDef,\n type YesNoFieldComponent\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type NumberSchema,\n type StringSchema\n} from 'joi'\n\nimport { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type ListItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class ListFormComponent extends FormComponent {\n declare options: Extract<\n SelectionComponentsDef,\n { options: object }\n >['options']\n\n declare formSchema:\n | ArraySchema<string>\n | ArraySchema<number>\n | BooleanSchema<string>\n | NumberSchema<string>\n | NumberSchema\n | StringSchema\n\n declare stateSchema:\n | ArraySchema<string>\n | ArraySchema<number>\n | BooleanSchema<string>\n | NumberSchema<string>\n | NumberSchema\n | StringSchema\n\n list?: List\n listType: List['type'] = 'string'\n\n get items(): Item[] {\n return this.list?.items ?? []\n }\n\n get values(): Item['value'][] {\n return this.items.map(({ value }) => value)\n }\n\n constructor(\n def:\n | SelectionComponentsDef // Allow for Yes/No field custom list\n | (YesNoFieldComponent & Pick<ListComponentsDef, 'list'>),\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options } = def\n const { model } = props\n\n if ('list' in def) {\n this.list = model.getList(def.list)\n this.listType = this.list?.type ?? 'string'\n }\n\n let formSchema = joi[this.listType]()\n .valid(...this.values)\n .label(this.label)\n .required()\n\n if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n this.formSchema = formSchema\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n }\n\n getFormValueFromState(\n state: FormSubmissionState\n ): Item['value'] | Item['value'][] | undefined {\n const { name, items } = this\n\n const value = state[name]\n\n // Allow for array values via subclass\n const values = this.isValue(value) ? [value].flat() : []\n const selected = items.filter((item) => values.includes(item.value))\n\n return selected.at(0)?.value\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const { items } = this\n\n // Allow for array values via subclass\n const value = this.getFormValueFromState(state)\n const values = [value ?? []].flat()\n\n return items\n .filter((item) => values.includes(item.value))\n .map((item) => item.text)\n .join(', ')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { items: listItems } = this\n\n const viewModel = super.getViewModel(payload, errors)\n const { value } = viewModel\n\n // Support multiple values for checkboxes\n const values = this.isValue(value) ? [value].flat() : []\n\n const items = listItems.map((item) => {\n const selected = values.includes(item.value)\n const itemModel: ListItem = { ...item, selected }\n\n if (item.description) {\n itemModel.hint = {\n text: item.description\n }\n }\n\n return itemModel\n })\n\n return {\n ...viewModel,\n items\n }\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'selectRequired', template: messageTemplate.selectRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAOA,OAAOA,GAAG,MAKH,KAAK;AAEZ,SAASC,aAAa;AAEtB,SAASC,eAAe;AAQxB,OAAO,MAAMC,iBAAiB,SAASF,aAAa,CAAC;EAsBnDG,IAAI;EACJC,QAAQ,GAAiB,QAAQ;EAEjC,IAAIC,KAAKA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACF,IAAI,EAAEE,KAAK,IAAI,EAAE;EAC/B;EAEA,IAAIC,MAAMA,CAAA,EAAoB;IAC5B,OAAO,IAAI,CAACD,KAAK,CAACE,GAAG,CAAC,CAAC;MAAEC;IAAM,CAAC,KAAKA,KAAK,CAAC;EAC7C;EAEAC,WAAWA,CACTC,GAE2D,EAC3DC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IACvB,MAAM;MAAEG;IAAM,CAAC,GAAGF,KAAK;IAEvB,IAAI,MAAM,IAAID,GAAG,EAAE;MACjB,IAAI,CAACP,IAAI,GAAGU,KAAK,CAACC,OAAO,CAACJ,GAAG,CAACP,IAAI,CAAC;MACnC,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACD,IAAI,EAAEY,IAAI,IAAI,QAAQ;IAC7C;IAEA,IAAIC,UAAU,GAAGjB,GAAG,CAA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ComponentBase.js";
|
|
2
|
+
export class Markdown extends ComponentBase {
|
|
3
|
+
content;
|
|
4
|
+
constructor(def, props) {
|
|
5
|
+
super(def, props);
|
|
6
|
+
const {
|
|
7
|
+
content,
|
|
8
|
+
options
|
|
9
|
+
} = def;
|
|
10
|
+
this.content = content;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
getViewModel() {
|
|
14
|
+
const {
|
|
15
|
+
content,
|
|
16
|
+
viewModel
|
|
17
|
+
} = this;
|
|
18
|
+
return {
|
|
19
|
+
...viewModel,
|
|
20
|
+
content
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Markdown.js","names":["ComponentBase","Markdown","content","constructor","def","props","options","getViewModel","viewModel"],"sources":["../../../../../src/server/plugins/engine/components/Markdown.ts"],"sourcesContent":["import { type MarkdownComponent } from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\n\nexport class Markdown extends ComponentBase {\n declare options: MarkdownComponent['options']\n content: MarkdownComponent['content']\n\n constructor(\n def: MarkdownComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { content, options } = def\n\n this.content = content\n this.options = options\n }\n\n getViewModel() {\n const { content, viewModel } = this\n\n return {\n ...viewModel,\n content\n }\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa;AAEtB,OAAO,MAAMC,QAAQ,SAASD,aAAa,CAAC;EAE1CE,OAAO;EAEPC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEH,OAAO;MAAEI;IAAQ,CAAC,GAAGF,GAAG;IAEhC,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACI,OAAO,GAAGA,OAAO;EACxB;EAEAC,YAAYA,CAAA,EAAG;IACb,MAAM;MAAEL,OAAO;MAAEM;IAAU,CAAC,GAAG,IAAI;IAEnC,OAAO;MACL,GAAGA,SAAS;MACZN;IACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -4,6 +4,7 @@ import { ComponentCollection } from "./ComponentCollection.js";
|
|
|
4
4
|
import { FormComponent, isFormState, isFormValue } from "./FormComponent.js";
|
|
5
5
|
import { NumberField } from "./NumberField.js";
|
|
6
6
|
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
7
|
+
import { convertToLanguageMessages } from "../../../utils/type-utils.js";
|
|
7
8
|
export class MonthYearField extends FormComponent {
|
|
8
9
|
constructor(def, props) {
|
|
9
10
|
super(def, props);
|
|
@@ -12,15 +13,17 @@ export class MonthYearField extends FormComponent {
|
|
|
12
13
|
options
|
|
13
14
|
} = def;
|
|
14
15
|
const isRequired = options.required !== false;
|
|
15
|
-
const customValidationMessages = {
|
|
16
|
+
const customValidationMessages = convertToLanguageMessages({
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
18
|
'any.required': messageTemplate.objectMissing,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
17
20
|
'number.base': messageTemplate.objectMissing,
|
|
18
21
|
'number.precision': messageTemplate.dateFormat,
|
|
19
22
|
'number.integer': messageTemplate.dateFormat,
|
|
20
23
|
'number.unsafe': messageTemplate.dateFormat,
|
|
21
24
|
'number.min': messageTemplate.dateFormat,
|
|
22
25
|
'number.max': messageTemplate.dateFormat
|
|
23
|
-
};
|
|
26
|
+
});
|
|
24
27
|
this.collection = new ComponentCollection([{
|
|
25
28
|
type: ComponentType.NumberField,
|
|
26
29
|
name: `${name}__month`,
|
|
@@ -146,6 +149,31 @@ export class MonthYearField extends FormComponent {
|
|
|
146
149
|
isState(value) {
|
|
147
150
|
return MonthYearField.isMonthYear(value);
|
|
148
151
|
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* For error preview page that shows all possible errors on a component
|
|
155
|
+
*/
|
|
156
|
+
getAllPossibleErrors() {
|
|
157
|
+
return {
|
|
158
|
+
baseErrors: [{
|
|
159
|
+
type: 'required',
|
|
160
|
+
template: messageTemplate.required
|
|
161
|
+
}, {
|
|
162
|
+
type: 'dateFormatMonth',
|
|
163
|
+
template: '{{#label}} must include a month'
|
|
164
|
+
}, {
|
|
165
|
+
type: 'dateFormatYear',
|
|
166
|
+
template: '{{#label}} must include a year'
|
|
167
|
+
}],
|
|
168
|
+
advancedSettingsErrors: [{
|
|
169
|
+
type: 'dateMin',
|
|
170
|
+
template: messageTemplate.dateMin
|
|
171
|
+
}, {
|
|
172
|
+
type: 'dateMax',
|
|
173
|
+
template: messageTemplate.dateMax
|
|
174
|
+
}]
|
|
175
|
+
};
|
|
176
|
+
}
|
|
149
177
|
static isMonthYear(value) {
|
|
150
178
|
return isFormState(value) && NumberField.isNumber(value.month) && NumberField.isNumber(value.year);
|
|
151
179
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonthYearField.js","names":["ComponentType","format","isValid","parse","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","messageTemplate","MonthYearField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorMonthYear","peers","formSchema","stateSchema","getFormValueFromState","state","value","isMonthYear","undefined","getDisplayStringFromState","date","Date","setMonth","month","monthString","toLocaleString","year","getContextValueFromState","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isState","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key"],"sources":["../../../../../src/server/plugins/engine/components/MonthYearField.ts"],"sourcesContent":["import { ComponentType, type MonthYearFieldComponent } from '@defra/forms-model'\nimport { format, isValid, parse } from 'date-fns'\nimport {\n type Context,\n type CustomValidator,\n type LanguageMessages,\n type ObjectSchema\n} from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type DateInputItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class MonthYearField extends FormComponent {\n declare options: MonthYearFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: MonthYearFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages: LanguageMessages = {\n 'any.required': messageTemplate.objectMissing,\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n }\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorMonthYear(this),\n peers: [`${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return MonthYearField.isMonthYear(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n const date = new Date()\n date.setMonth(value.month - 1)\n\n const monthString = date.toLocaleString('default', { month: 'long' })\n return `${monthString} ${value.year}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parse(`${value.year}-${value.month}-01`, 'yyyy-MM-dd', new Date())\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-01`, 'yyyy-MM')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return MonthYearField.isMonthYear(value)\n }\n\n static isMonthYear(\n value?: FormStateValue | FormState\n ): value is MonthYearState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport interface MonthYearState extends Record<string, number> {\n month: number\n year: number\n}\n\nexport function getValidatorMonthYear(component: MonthYearField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,MAAM,EAAEC,OAAO,EAAEC,KAAK,QAAQ,UAAU;AAQjD,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,OAAO,MAAMC,cAAc,SAASL,aAAa,CAAC;EAMhDM,WAAWA,CACTC,GAA4B,EAC5BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAE7B,MAAMI,UAAU,GAAGD,OAAO,CAACE,QAAQ,KAAK,KAAK;IAE7C,MAAMC,wBAA0C,GAAG;MACjD,cAAc,EAAET,eAAe,CAACU,aAAa;MAC7C,aAAa,EAAEV,eAAe,CAACU,aAAa;MAC5C,kBAAkB,EAAEV,eAAe,CAACW,UAAU;MAC9C,gBAAgB,EAAEX,eAAe,CAACW,UAAU;MAC5C,eAAe,EAAEX,eAAe,CAACW,UAAU;MAC3C,YAAY,EAAEX,eAAe,CAACW,UAAU;MACxC,YAAY,EAAEX,eAAe,CAACW;IAChC,CAAC;IAED,IAAI,CAACC,UAAU,GAAG,IAAIjB,mBAAmB,CACvC,CACE;MACEkB,IAAI,EAAEtB,aAAa,CAACQ,WAAW;MAC/BM,IAAI,EAAE,GAAGA,IAAI,SAAS;MACtBS,KAAK,EAAE,OAAO;MACdC,MAAM,EAAE;QAAEC,GAAG,EAAE,CAAC;QAAEC,GAAG,EAAE,EAAE;QA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,SAAS,CAACI,qBAAqB,CAACvB,OAAO,CACzC,CAAC;IAED,MAAMwB,OAAgB,GAAG;MACvBC,OAAO,EAAEvD,UAAU,CAACwD,IAAI;MACxBC,GAAG,EAAEhE;IACP,CAAC;IAED,IAAI,CAACwD,SAAS,CAACF,OAAO,CAACK,MAAM,CAAC,EAAE;MAC9B,OAAO1D,OAAO,CAACE,QAAQ,KAAK,KAAK,GAC7BuD,OAAO,CAACd,KAAK,CAAC,iBAAiB,EAAEiB,OAAO,CAAC,GACzCxB,OAAO;IACb;IAEA,OAAOA,OAAO;EAChB,CAAC;EAED,OAAOoB,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MonthYearField.js","names":["ComponentType","format","isValid","parse","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","messageTemplate","convertToLanguageMessages","MonthYearField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorMonthYear","peers","formSchema","stateSchema","getFormValueFromState","state","value","isMonthYear","undefined","getDisplayStringFromState","date","Date","setMonth","month","monthString","toLocaleString","year","getContextValueFromState","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","dateMin","dateMax","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key"],"sources":["../../../../../src/server/plugins/engine/components/MonthYearField.ts"],"sourcesContent":["import { ComponentType, type MonthYearFieldComponent } from '@defra/forms-model'\nimport { format, isValid, parse } from 'date-fns'\nimport {\n type Context,\n type CustomValidator,\n type LanguageMessages,\n type ObjectSchema\n} from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type DateInputItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class MonthYearField extends FormComponent {\n declare options: MonthYearFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: MonthYearFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required': messageTemplate.objectMissing,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorMonthYear(this),\n peers: [`${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return MonthYearField.isMonthYear(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n const date = new Date()\n date.setMonth(value.month - 1)\n\n const monthString = date.toLocaleString('default', { month: 'long' })\n return `${monthString} ${value.year}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parse(`${value.year}-${value.month}-01`, 'yyyy-MM-dd', new Date())\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-01`, 'yyyy-MM')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return MonthYearField.isMonthYear(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n {\n type: 'dateFormatMonth',\n template: '{{#label}} must include a month'\n },\n { type: 'dateFormatYear', template: '{{#label}} must include a year' }\n ],\n advancedSettingsErrors: [\n { type: 'dateMin', template: messageTemplate.dateMin },\n { type: 'dateMax', template: messageTemplate.dateMax }\n ]\n }\n }\n\n static isMonthYear(\n value?: FormStateValue | FormState\n ): value is MonthYearState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport interface MonthYearState extends Record<string, number> {\n month: number\n year: number\n}\n\nexport function getValidatorMonthYear(component: MonthYearField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,MAAM,EAAEC,OAAO,EAAEC,KAAK,QAAQ,UAAU;AAQjD,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,cAAc,SAASN,aAAa,CAAC;EAMhDO,WAAWA,CACTC,GAA4B,EAC5BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAE7B,MAAMI,UAAU,GAAGD,OAAO,CAACE,QAAQ,KAAK,KAAK;IAE7C,MAAMC,wBAA0C,GAC9CT,yBAAyB,CAAC;MACxB;MACA,cAAc,EAAED,eAAe,CAACW,aAAa;MAC7C;MACA,aAAa,EAAEX,eAAe,CAACW,aAAa;MAC5C,kBAAkB,EAAEX,eAAe,CAACY,UAAU;MAC9C,gBAAgB,EAAEZ,eAAe,CAACY,UAAU;MAC5C,eAAe,EAAEZ,eAAe,CAACY,UAAU;MAC3C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
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
2
|
import { FormComponent } from "./FormComponent.js";
|
|
3
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
3
4
|
export class MultilineTextField extends FormComponent {
|
|
4
5
|
isCharacterOrWordCount = false;
|
|
5
6
|
constructor(def, props) {
|
|
6
7
|
super(def, props);
|
|
7
8
|
const {
|
|
8
9
|
schema,
|
|
9
|
-
options
|
|
10
|
-
title
|
|
10
|
+
options
|
|
11
11
|
} = def;
|
|
12
|
-
let formSchema = Joi.string().trim().label(
|
|
12
|
+
let formSchema = Joi.string().trim().label(this.label).required();
|
|
13
13
|
if (options.required === false) {
|
|
14
14
|
formSchema = formSchema.allow('');
|
|
15
15
|
}
|
|
@@ -45,6 +45,9 @@ export class MultilineTextField extends FormComponent {
|
|
|
45
45
|
});
|
|
46
46
|
} else if (options.customValidationMessages) {
|
|
47
47
|
formSchema = formSchema.messages(options.customValidationMessages);
|
|
48
|
+
} else if (typeof schema.max === 'number' && typeof schema.min === 'number') {
|
|
49
|
+
const minMaxErrorText = this.buildMinMaxText(schema.min, schema.max);
|
|
50
|
+
formSchema = formSchema.ruleset.min(schema.min).max(schema.max).message(minMaxErrorText);
|
|
48
51
|
}
|
|
49
52
|
this.formSchema = formSchema.default('');
|
|
50
53
|
this.stateSchema = formSchema.default(null).allow(null);
|
|
@@ -80,6 +83,32 @@ export class MultilineTextField extends FormComponent {
|
|
|
80
83
|
rows
|
|
81
84
|
};
|
|
82
85
|
}
|
|
86
|
+
buildMinMaxText(min, max) {
|
|
87
|
+
const minMaxError = messageTemplate.minMax;
|
|
88
|
+
return minMaxError.replace('{{#min}}', min ? min.toString() : '[min length]').replace('{{#max}}', max ? max.toString() : '[max length]');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* For error preview page that shows all possible errors on a component
|
|
93
|
+
*/
|
|
94
|
+
getAllPossibleErrors() {
|
|
95
|
+
return {
|
|
96
|
+
baseErrors: [{
|
|
97
|
+
type: 'required',
|
|
98
|
+
template: messageTemplate.required
|
|
99
|
+
}],
|
|
100
|
+
advancedSettingsErrors: [{
|
|
101
|
+
type: 'min',
|
|
102
|
+
template: messageTemplate.min
|
|
103
|
+
}, {
|
|
104
|
+
type: 'max',
|
|
105
|
+
template: messageTemplate.max
|
|
106
|
+
}, {
|
|
107
|
+
type: 'minMax',
|
|
108
|
+
template: this.buildMinMaxText(this.schema.min, this.schema.max)
|
|
109
|
+
}]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
83
112
|
}
|
|
84
113
|
function getValidatorMaxWords(component) {
|
|
85
114
|
const validator = (value, helpers) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultilineTextField.js","names":["Joi","FormComponent","MultilineTextField","isCharacterOrWordCount","constructor","def","props","schema","options","title","formSchema","string","trim","label","required","allow","length","max","min","maxWords","custom","getValidatorMaxWords","regex","pattern","RegExp","customValidationMessage","message","messages","customValidationMessages","default","stateSchema","getViewModel","payload","errors","viewModel","maxlength","maxwords","rows","component","validator","value","helpers","limit","count","error","text","tokens","match"],"sources":["../../../../../src/server/plugins/engine/components/MultilineTextField.ts"],"sourcesContent":["import { type MultilineTextFieldComponent } from '@defra/forms-model'\nimport Joi, { type CustomValidator, type StringSchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n type FormPayload,\n type FormSubmissionError\n} from '~/src/server/plugins/engine/types.js'\n\nexport class MultilineTextField extends FormComponent {\n declare options: MultilineTextFieldComponent['options']\n declare schema: MultilineTextFieldComponent['schema']\n declare formSchema: StringSchema\n declare stateSchema: StringSchema\n\n isCharacterOrWordCount = false\n\n constructor(\n def: MultilineTextFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { schema, options, title } = def\n\n let formSchema = Joi.string().trim().label(title).required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n }\n\n if (typeof schema.length !== 'number') {\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n this.isCharacterOrWordCount = true\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n } else {\n formSchema = formSchema.length(schema.length)\n }\n\n if (typeof options.maxWords === 'number') {\n formSchema = formSchema.custom(\n getValidatorMaxWords(this),\n 'max words validation'\n )\n\n this.isCharacterOrWordCount = true\n }\n\n if (schema.regex) {\n const pattern = new RegExp(schema.regex)\n formSchema = formSchema.pattern(pattern)\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'string.empty': message,\n 'string.max': message,\n 'string.min': message,\n 'string.length': message,\n 'string.pattern.base': message,\n 'string.maxWords': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n this.schema = schema\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { schema, options, isCharacterOrWordCount } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { maxlength, maxwords, rows } = viewModel\n\n if (schema.max) {\n maxlength = schema.max\n }\n\n if (options.maxWords) {\n maxwords = options.maxWords\n }\n\n if (options.rows) {\n rows = options.rows\n }\n\n return {\n ...viewModel,\n isCharacterOrWordCount,\n maxlength,\n maxwords,\n rows\n }\n }\n}\n\nfunction getValidatorMaxWords(component: MultilineTextField) {\n const validator: CustomValidator = (value: string, helpers) => {\n const { options } = component\n\n const {\n customValidationMessage: custom,\n maxWords: limit // See {{#limit}} variable\n } = options\n\n if (!limit || count(value) <= limit) {\n return value\n }\n\n return custom\n ? helpers.message({ custom }, { limit })\n : helpers.error('string.maxWords', { limit })\n }\n\n /**\n * Count the number of words in the given text\n * @see GOV.UK Frontend {@link https://github.com/alphagov/govuk-frontend/blob/v5.4.0/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs#L343 | Character count `maxwords` implementation}\n */\n function count(text: string) {\n const tokens = text.match(/\\S+/g) ?? []\n return tokens.length\n }\n\n return validator\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAmD,KAAK;AAGlE,SAASC,aAAa;AAMtB,OAAO,MAAMC,kBAAkB,SAASD,aAAa,CAAC;EAMpDE,sBAAsB,GAAG,KAAK;EAE9BC,WAAWA,CACTC,GAAgC,EAChCC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,MAAM;MAAEC,OAAO;MAAEC;IAAM,CAAC,GAAGJ,GAAG;IAEtC,IAAIK,UAAU,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,KAAK,CAACJ,KAAK,CAAC,CAACK,QAAQ,CAAC,CAAC;IAE5D,IAAIN,OAAO,CAACM,QAAQ,KAAK,KAAK,EAAE;MAC9BJ,UAAU,GAAGA,UAAU,CAACK,KAAK,CAAC,EAAE,CAAC;IACnC;IAEA,IAAI,OAAOR,MAAM,CAACS,MAAM,KAAK,QAAQ,EAAE;MACrC,IAAI,OAAOT,MAAM,CAACU,GAAG,KAAK,QAAQ,EAAE;QAClCP,UAAU,GAAGA,UAAU,CAACO,GAAG,CAACV,MAAM,CAACU,GAAG,CAAC;QACvC,IAAI,CAACd,sBAAsB,GAAG,IAAI;MACpC;MAEA,IAAI,OAAOI,MAAM,CAACW,GAAG,KAAK,QAAQ,EAAE;QAClCR,UAAU,GAAGA,UAAU,CAACQ,GAAG,CAACX,MAAM,CAACW,GAAG,CAAC;MACzC;IACF,CAAC,MAAM;MACLR,UAAU,GAAGA,UAAU,CAACM,MAAM,CAACT,MAAM,CAACS,MAAM,CAAC;IAC/C;IAEA,IAAI,OAAOR,OAAO,CAACW,QAAQ,KAAK,QAAQ,EAAE;MACxCT,UAAU,GAA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ineTextField","isCharacterOrWordCount","constructor","def","props","schema","options","formSchema","string","trim","label","required","allow","length","max","min","maxWords","custom","getValidatorMaxWords","regex","pattern","RegExp","customValidationMessage","message","messages","customValidationMessages","minMaxErrorText","buildMinMaxText","ruleset","default","stateSchema","getViewModel","payload","errors","viewModel","maxlength","maxwords","rows","minMaxError","minMax","replace","toString","getAllPossibleErrors","baseErrors","type","template","advancedSettingsErrors","component","validator","value","helpers","limit","count","error","text","tokens","match"],"sources":["../../../../../src/server/plugins/engine/components/MultilineTextField.ts"],"sourcesContent":["import { type MultilineTextFieldComponent } from '@defra/forms-model'\nimport Joi, { type CustomValidator, type StringSchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormSubmissionError\n} from '~/src/server/plugins/engine/types.js'\n\nexport class MultilineTextField extends FormComponent {\n declare options: MultilineTextFieldComponent['options']\n declare schema: MultilineTextFieldComponent['schema']\n declare formSchema: StringSchema\n declare stateSchema: StringSchema\n\n isCharacterOrWordCount = false\n\n constructor(\n def: MultilineTextFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { schema, options } = def\n\n let formSchema = Joi.string().trim().label(this.label).required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n }\n\n if (typeof schema.length !== 'number') {\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n this.isCharacterOrWordCount = true\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n } else {\n formSchema = formSchema.length(schema.length)\n }\n\n if (typeof options.maxWords === 'number') {\n formSchema = formSchema.custom(\n getValidatorMaxWords(this),\n 'max words validation'\n )\n\n this.isCharacterOrWordCount = true\n }\n\n if (schema.regex) {\n const pattern = new RegExp(schema.regex)\n formSchema = formSchema.pattern(pattern)\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'string.empty': message,\n 'string.max': message,\n 'string.min': message,\n 'string.length': message,\n 'string.pattern.base': message,\n 'string.maxWords': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n } else if (\n typeof schema.max === 'number' &&\n typeof schema.min === 'number'\n ) {\n const minMaxErrorText = this.buildMinMaxText(schema.min, schema.max)\n formSchema = formSchema.ruleset\n .min(schema.min)\n .max(schema.max)\n .message(minMaxErrorText)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n this.schema = schema\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { schema, options, isCharacterOrWordCount } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { maxlength, maxwords, rows } = viewModel\n\n if (schema.max) {\n maxlength = schema.max\n }\n\n if (options.maxWords) {\n maxwords = options.maxWords\n }\n\n if (options.rows) {\n rows = options.rows\n }\n\n return {\n ...viewModel,\n isCharacterOrWordCount,\n maxlength,\n maxwords,\n rows\n }\n }\n\n buildMinMaxText(min?: number, max?: number): string {\n const minMaxError = messageTemplate.minMax as string\n return minMaxError\n .replace('{{#min}}', min ? min.toString() : '[min length]')\n .replace('{{#max}}', max ? max.toString() : '[max length]')\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [{ type: 'required', template: messageTemplate.required }],\n advancedSettingsErrors: [\n { type: 'min', template: messageTemplate.min },\n { type: 'max', template: messageTemplate.max },\n {\n type: 'minMax',\n template: this.buildMinMaxText(this.schema.min, this.schema.max)\n }\n ]\n }\n }\n}\n\nfunction getValidatorMaxWords(component: MultilineTextField) {\n const validator: CustomValidator = (value: string, helpers) => {\n const { options } = component\n\n const {\n customValidationMessage: custom,\n maxWords: limit // See {{#limit}} variable\n } = options\n\n if (!limit || count(value) <= limit) {\n return value\n }\n\n return custom\n ? helpers.message({ custom }, { limit })\n : helpers.error('string.maxWords', { limit })\n }\n\n /**\n * Count the number of words in the given text\n * @see GOV.UK Frontend {@link https://github.com/alphagov/govuk-frontend/blob/v5.4.0/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs#L343 | Character count `maxwords` implementation}\n */\n function count(text: string) {\n const tokens = text.match(/\\S+/g) ?? []\n return tokens.length\n }\n\n return validator\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAmD,KAAK;AAGlE,SAASC,aAAa;AACtB,SAASC,eAAe;AAOxB,OAAO,MAAMC,kBAAkB,SAASF,aAAa,CAAC;EAMpDG,sBAAsB,GAAG,KAAK;EAE9BC,WAAWA,CACTC,GAAgC,EAChCC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,MAAM;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAE/B,IAAII,UAAU,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CAACC,QAAQ,CAAC,CAAC;IAEjE,IAAIL,OAAO,CAACK,QAAQ,KAAK,KAAK,EAAE;MAC9BJ,UAAU,GAAGA,UAAU,CAACK,KAAK,CAAC,EAAE,CAAC;IACnC;IAEA,IAAI,OAAOP,MAAM,CAACQ,MAAM,KAAK,QAAQ,EAAE;MACrC,IAAI,OAAOR,MAAM,CAACS,GAAG,KAAK,QAAQ,EAAE;QAClCP,UAAU,GAAGA,UAAU,CAACO,GAAG,CAACT,MAAM,CAACS,GAAG,CAAC;QACvC,IAAI,CAACb,sBAAsB,GAAG,IAAI;MACpC;MAEA,IAAI,OAAOI,MAAM,CAACU,GAAG,KAAK,QAAQ,EAAE;QAClCR,UAAU,GAAGA,UAAU,CAACQ,GAAG,CAACV,MAAM,C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CAAC,MAAM,CAAC,IAAI,EAAE;IACvC,OAAOD,MAAM,CAAC1C,MAAM;EACtB;EAEA,OAAOmC,SAAS;AAClB","ignoreList":[]}
|
|
@@ -6,15 +6,15 @@ export class NumberField extends FormComponent {
|
|
|
6
6
|
super(def, props);
|
|
7
7
|
const {
|
|
8
8
|
options,
|
|
9
|
-
schema
|
|
10
|
-
title
|
|
9
|
+
schema
|
|
11
10
|
} = def;
|
|
12
|
-
let formSchema = joi.number().custom(getValidatorPrecision(this)).label(
|
|
11
|
+
let formSchema = joi.number().custom(getValidatorPrecision(this)).label(this.label).required();
|
|
13
12
|
if (options.required === false) {
|
|
14
13
|
formSchema = formSchema.allow('');
|
|
15
14
|
} else {
|
|
16
15
|
const messages = options.customValidationMessages;
|
|
17
16
|
formSchema = formSchema.empty('').messages({
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
18
18
|
'any.required': messages?.['any.required'] ?? messageTemplate.required
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -98,6 +98,31 @@ export class NumberField extends FormComponent {
|
|
|
98
98
|
isValue(value) {
|
|
99
99
|
return NumberField.isNumber(value);
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* For error preview page that shows all possible errors on a component
|
|
104
|
+
*/
|
|
105
|
+
getAllPossibleErrors() {
|
|
106
|
+
return {
|
|
107
|
+
baseErrors: [{
|
|
108
|
+
type: 'required',
|
|
109
|
+
template: messageTemplate.required
|
|
110
|
+
}, {
|
|
111
|
+
type: 'numberInteger',
|
|
112
|
+
template: messageTemplate.numberInteger
|
|
113
|
+
}],
|
|
114
|
+
advancedSettingsErrors: [{
|
|
115
|
+
type: 'numberMin',
|
|
116
|
+
template: messageTemplate.numberMin
|
|
117
|
+
}, {
|
|
118
|
+
type: 'numberMax',
|
|
119
|
+
template: messageTemplate.numberMax
|
|
120
|
+
}, {
|
|
121
|
+
type: 'numberPrecision',
|
|
122
|
+
template: messageTemplate.numberPrecision
|
|
123
|
+
}]
|
|
124
|
+
};
|
|
125
|
+
}
|
|
101
126
|
static isNumber(value) {
|
|
102
127
|
return typeof value === 'number';
|
|
103
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberField.js","names":["joi","FormComponent","isFormValue","messageTemplate","NumberField","constructor","def","props","options","schema","title","formSchema","number","custom","getValidatorPrecision","label","required","allow","messages","customValidationMessages","empty","min","max","precision","integer","customValidationMessage","message","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getViewModel","payload","errors","viewModel","attributes","prefix","suffix","inputmode","text","isNumber","component","validator","helpers","limit","validationSchema","prefs","convert","attempt","error"],"sources":["../../../../../src/server/plugins/engine/components/NumberField.ts"],"sourcesContent":["import { type NumberFieldComponent } from '@defra/forms-model'\nimport joi, { type CustomValidator, type NumberSchema } from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class NumberField extends FormComponent {\n declare options: NumberFieldComponent['options']\n declare schema: NumberFieldComponent['schema']\n declare formSchema: NumberSchema\n declare stateSchema: NumberSchema\n\n constructor(\n def: NumberFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, schema, title } = def\n\n let formSchema = joi\n .number()\n .custom(getValidatorPrecision(this))\n .label(title)\n .required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n } else {\n const messages = options.customValidationMessages\n\n formSchema = formSchema.empty('').messages({\n 'any.required': messages?.['any.required'] ?? messageTemplate.required\n })\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n\n if (typeof schema.precision === 'number' && schema.precision <= 0) {\n formSchema = formSchema.integer()\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'number.base': message,\n 'number.precision': message,\n 'number.integer': message,\n 'number.min': message,\n 'number.max': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n this.schema = schema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { options, schema } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { attributes, prefix, suffix, value } = viewModel\n\n if (typeof schema.precision === 'undefined' || schema.precision <= 0) {\n // If precision isn't provided or provided and\n // less than or equal to 0, use numeric inputmode\n attributes.inputmode = 'numeric'\n }\n\n if (options.prefix) {\n prefix = {\n text: options.prefix\n }\n }\n\n if (options.suffix) {\n suffix = {\n text: options.suffix\n }\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n ...viewModel,\n attributes,\n prefix,\n suffix,\n value\n }\n }\n\n isValue(value?: FormStateValue | FormState) {\n return NumberField.isNumber(value)\n }\n\n static isNumber(value?: FormStateValue | FormState): value is number {\n return typeof value === 'number'\n }\n}\n\nexport function getValidatorPrecision(component: NumberField) {\n const validator: CustomValidator = (value: number, helpers) => {\n const { options, schema } = component\n\n const { customValidationMessage: custom } = options\n const { precision: limit } = schema\n\n if (!limit || limit <= 0) {\n return value\n }\n\n const validationSchema = joi\n .number()\n .precision(limit)\n .prefs({ convert: false })\n\n try {\n return joi.attempt(value, validationSchema)\n } catch {\n return custom\n ? helpers.message({ custom }, { limit })\n : helpers.error('number.prec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MAAEC,OAAO,EAAE;IAAM,CAAC,CAAC;IAE5B,IAAI;MACF,OAAOpD,GAAG,CAACqD,OAAO,CAACpB,KAAK,EAAEiB,gBAAgB,CAAC;IAC7C,CAAC,CAAC,MAAM;MACN,OAAOrC,MAAM,GACTmC,OAAO,CAACtB,OAAO,CAAC;QAAEb;MAAO,CAAC,EAAE;QAAEoC;MAAM,CAAC,CAAC,GACtCD,OAAO,CAACM,KAAK,CAAC,kBAAkB,EAAE;QAAEL;MAAM,CAAC,CAAC;IAClD;EACF,CAAC;EAED,OAAOF,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"NumberField.js","names":["joi","FormComponent","isFormValue","messageTemplate","NumberField","constructor","def","props","options","schema","formSchema","number","custom","getValidatorPrecision","label","required","allow","messages","customValidationMessages","empty","min","max","precision","integer","customValidationMessage","message","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getViewModel","payload","errors","viewModel","attributes","prefix","suffix","inputmode","text","isNumber","getAllPossibleErrors","baseErrors","type","template","numberInteger","advancedSettingsErrors","numberMin","numberMax","numberPrecision","component","validator","helpers","limit","validationSchema","prefs","convert","attempt","error"],"sources":["../../../../../src/server/plugins/engine/components/NumberField.ts"],"sourcesContent":["import { type NumberFieldComponent } from '@defra/forms-model'\nimport joi, { type CustomValidator, type NumberSchema } from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class NumberField extends FormComponent {\n declare options: NumberFieldComponent['options']\n declare schema: NumberFieldComponent['schema']\n declare formSchema: NumberSchema\n declare stateSchema: NumberSchema\n\n constructor(\n def: NumberFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, schema } = def\n\n let formSchema = joi\n .number()\n .custom(getValidatorPrecision(this))\n .label(this.label)\n .required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n } else {\n const messages = options.customValidationMessages\n\n formSchema = formSchema.empty('').messages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required':\n messages?.['any.required'] ?? (messageTemplate.required as string)\n })\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n\n if (typeof schema.precision === 'number' && schema.precision <= 0) {\n formSchema = formSchema.integer()\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'number.base': message,\n 'number.precision': message,\n 'number.integer': message,\n 'number.min': message,\n 'number.max': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n this.schema = schema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { options, schema } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { attributes, prefix, suffix, value } = viewModel\n\n if (typeof schema.precision === 'undefined' || schema.precision <= 0) {\n // If precision isn't provided or provided and\n // less than or equal to 0, use numeric inputmode\n attributes.inputmode = 'numeric'\n }\n\n if (options.prefix) {\n prefix = {\n text: options.prefix\n }\n }\n\n if (options.suffix) {\n suffix = {\n text: options.suffix\n }\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n ...viewModel,\n attributes,\n prefix,\n suffix,\n value\n }\n }\n\n isValue(value?: FormStateValue | FormState) {\n return NumberField.isNumber(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n { type: 'numberInteger', template: messageTemplate.numberInteger }\n ],\n advancedSettingsErrors: [\n { type: 'numberMin', template: messageTemplate.numberMin },\n { type: 'numberMax', template: messageTemplate.numberMax },\n { type: 'numberPrecision', template: messageTemplate.numberPrecision }\n ]\n }\n }\n\n static isNumber(value?: FormStateValue | FormState): value is number {\n return typeof value === 'number'\n }\n}\n\nexport function getValidatorPrecision(component: NumberField) {\n const validator: CustomValidator = (value: number, helpers) => {\n const { options, schema } = component\n\n const { customValidationMessage: custom } = options\n const { precision: limit } = schema\n\n if (!limit || limit <= 0) {\n return value\n }\n\n const validationSchema = joi\n .number()\n .precision(limit)\n .prefs({ convert: false })\n\n try {\n return joi.attempt(value, validationSchema)\n } catch {\n return custom\n ? helpers.message({ custom }, { limit })\n : helpers.error('number.precision', { limit })\n }\n }\n\n return validator\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAmD,KAAK;AAElE,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAUxB,OAAO,MAAMC,WAAW,SAASH,aAAa,CAAC;EAM7CI,WAAWA,CACTC,GAAyB,EACzBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAGH,GAAG;IAE/B,IAAII,UAAU,GAAGV,GAAG,CACjBW,MAAM,CAAC,CAAC,CACRC,MAAM,CAACC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CACnCC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBC,QAAQ,CAAC,CAAC;IAEb,IAAIP,OAAO,CAACO,QAAQ,KAAK,KAAK,EAAE;MAC9BL,UAAU,GAAGA,UAAU,CAACM,KAAK,CAAC,EAAE,CAAC;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AG,CAAC6D,OAAO,CAAC7B,KAAK,EAAE0B,gBAAgB,CAAC;IAC7C,CAAC,CAAC,MAAM;MACN,OAAO9C,MAAM,GACT4C,OAAO,CAAC/B,OAAO,CAAC;QAAEb;MAAO,CAAC,EAAE;QAAE6C;MAAM,CAAC,CAAC,GACtCD,OAAO,CAACM,KAAK,CAAC,kBAAkB,EAAE;QAAEL;MAAM,CAAC,CAAC;IAClD;EACF,CAAC;EAED,OAAOF,SAAS;AAClB","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListFormComponent } from "./ListFormComponent.js";
|
|
2
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
2
3
|
/**
|
|
3
4
|
* "Selection controls" are checkboxes and radios (and switches), as per Material UI nomenclature.
|
|
4
5
|
*/
|
|
@@ -39,5 +40,18 @@ export class SelectionControlField extends ListFormComponent {
|
|
|
39
40
|
items
|
|
40
41
|
};
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* For error preview page that shows all possible errors on a component
|
|
46
|
+
*/
|
|
47
|
+
getAllPossibleErrors() {
|
|
48
|
+
return {
|
|
49
|
+
baseErrors: [{
|
|
50
|
+
type: 'selectRequired',
|
|
51
|
+
template: messageTemplate.selectRequired
|
|
52
|
+
}],
|
|
53
|
+
advancedSettingsErrors: []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
42
56
|
}
|
|
43
57
|
//# sourceMappingURL=SelectionControlField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionControlField.js","names":["ListFormComponent","SelectionControlField","getViewModel","payload","errors","options","viewModel","fieldset","items","label","legend","text","classes","map","item","selected","checked","itemModel","bold"],"sources":["../../../../../src/server/plugins/engine/components/SelectionControlField.ts"],"sourcesContent":["import { ListFormComponent } from '~/src/server/plugins/engine/components/ListFormComponent.js'\nimport { type ListItem } from '~/src/server/plugins/engine/components/types.js'\nimport {\n type FormPayload,\n type FormSubmissionError\n} from '~/src/server/plugins/engine/types.js'\n\n/**\n * \"Selection controls\" are checkboxes and radios (and switches), as per Material UI nomenclature.\n */\nexport class SelectionControlField extends ListFormComponent {\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { options } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, items, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n items = items.map((item) => {\n const { selected: checked } = item\n const itemModel = { ...item, checked } satisfies ListItem\n\n if ('bold' in options && options.bold) {\n itemModel.label ??= {}\n itemModel.label.classes = 'govuk-label--s'\n }\n\n return itemModel\n })\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;
|
|
1
|
+
{"version":3,"file":"SelectionControlField.js","names":["ListFormComponent","messageTemplate","SelectionControlField","getViewModel","payload","errors","options","viewModel","fieldset","items","label","legend","text","classes","map","item","selected","checked","itemModel","bold","getAllPossibleErrors","baseErrors","type","template","selectRequired","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/SelectionControlField.ts"],"sourcesContent":["import { ListFormComponent } from '~/src/server/plugins/engine/components/ListFormComponent.js'\nimport { type ListItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormSubmissionError\n} from '~/src/server/plugins/engine/types.js'\n\n/**\n * \"Selection controls\" are checkboxes and radios (and switches), as per Material UI nomenclature.\n */\nexport class SelectionControlField extends ListFormComponent {\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { options } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, items, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n items = items.map((item) => {\n const { selected: checked } = item\n const itemModel = { ...item, checked } satisfies ListItem\n\n if ('bold' in options && options.bold) {\n itemModel.label ??= {}\n itemModel.label.classes = 'govuk-label--s'\n }\n\n return itemModel\n })\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'selectRequired', template: messageTemplate.selectRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAE1B,SAASC,eAAe;AAOxB;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,SAASF,iBAAiB,CAAC;EAC3DG,YAAYA,CAACC,OAAoB,EAAEC,MAA8B,EAAE;IACjE,MAAM;MAAEC;IAAQ,CAAC,GAAG,IAAI;IAExB,MAAMC,SAAS,GAAG,KAAK,CAACJ,YAAY,CAACC,OAAO,EAAEC,MAAM,CAAC;IACrD,IAAI;MAAEG,QAAQ;MAAEC,KAAK;MAAEC;IAAM,CAAC,GAAGH,SAAS;IAE1CC,QAAQ,KAAK;MACXG,MAAM,EAAE;QACNC,IAAI,EAAEF,KAAK,CAACE,IAAI;QAChBC,OAAO,EAAE;MACX;IACF,CAAC;IAEDJ,KAAK,GAAGA,KAAK,CAACK,GAAG,CAAEC,IAAI,IAAK;MAC1B,MAAM;QAAEC,QAAQ,EAAEC;MAAQ,CAAC,GAAGF,IAAI;MAClC,MAAMG,SAAS,GAAG;QAAE,GAAGH,IAAI;QAAEE;MAAQ,CAAoB;MAEzD,IAAI,MAAM,IAAIX,OAAO,IAAIA,OAAO,CAACa,IAAI,EAAE;QACrCD,SAAS,CAACR,KAAK,KAAK,CAAC,CAAC;QACtBQ,SAAS,CAACR,KAAK,CAACG,OAAO,GAAG,gBAAgB;MAC5C;MAEA,OAAOK,SAAS;IAClB,CAAC,CAAC;IAEF,OAAO;MACL,GAAGX,SAAS;MACZC,QAAQ;MACRC;IACF,CAAC;EACH;;EAEA;AACF;AACA;EACEW,oBAAoBA,CAAA,EAA6B;IAC/C,OAAO;MACLC,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,gBAAgB;QAAEC,QAAQ,EAAEtB,eAAe,CAACuB;MAAe,CAAC,CACrE;MACDC,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import joi from 'joi';
|
|
2
2
|
import { FormComponent } from "./FormComponent.js";
|
|
3
3
|
import { addClassOptionIfNone } from "./helpers.js";
|
|
4
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
4
5
|
const PATTERN = /^[0-9\\\s+()-]*$/;
|
|
5
6
|
export class TelephoneNumberField extends FormComponent {
|
|
6
7
|
constructor(def, props) {
|
|
7
8
|
super(def, props);
|
|
8
9
|
const {
|
|
9
|
-
options
|
|
10
|
-
title
|
|
10
|
+
options
|
|
11
11
|
} = def;
|
|
12
|
-
let formSchema = joi.string().trim().pattern(PATTERN).label(
|
|
12
|
+
let formSchema = joi.string().trim().pattern(PATTERN).label(this.label).required();
|
|
13
13
|
if (options.required === false) {
|
|
14
14
|
formSchema = formSchema.allow('');
|
|
15
15
|
}
|
|
@@ -39,5 +39,21 @@ export class TelephoneNumberField extends FormComponent {
|
|
|
39
39
|
type: 'tel'
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* For error preview page that shows all possible errors on a component
|
|
45
|
+
*/
|
|
46
|
+
getAllPossibleErrors() {
|
|
47
|
+
return {
|
|
48
|
+
baseErrors: [{
|
|
49
|
+
type: 'required',
|
|
50
|
+
template: messageTemplate.required
|
|
51
|
+
}, {
|
|
52
|
+
type: 'format',
|
|
53
|
+
template: messageTemplate.format
|
|
54
|
+
}],
|
|
55
|
+
advancedSettingsErrors: []
|
|
56
|
+
};
|
|
57
|
+
}
|
|
42
58
|
}
|
|
43
59
|
//# sourceMappingURL=TelephoneNumberField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TelephoneNumberField.js","names":["joi","FormComponent","addClassOptionIfNone","PATTERN","TelephoneNumberField","constructor","def","props","options","
|
|
1
|
+
{"version":3,"file":"TelephoneNumberField.js","names":["joi","FormComponent","addClassOptionIfNone","messageTemplate","PATTERN","TelephoneNumberField","constructor","def","props","options","formSchema","string","trim","pattern","label","required","allow","customValidationMessage","message","messages","customValidationMessages","default","stateSchema","getViewModel","payload","errors","viewModel","attributes","autocomplete","type","getAllPossibleErrors","baseErrors","template","format","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/TelephoneNumberField.ts"],"sourcesContent":["import { type TelephoneNumberFieldComponent } from '@defra/forms-model'\nimport joi, { type StringSchema } from 'joi'\n\nimport { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { addClassOptionIfNone } from '~/src/server/plugins/engine/components/helpers.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormSubmissionError\n} from '~/src/server/plugins/engine/types.js'\n\nconst PATTERN = /^[0-9\\\\\\s+()-]*$/\n\nexport class TelephoneNumberField extends FormComponent {\n declare options: TelephoneNumberFieldComponent['options']\n declare formSchema: StringSchema\n declare stateSchema: StringSchema\n\n constructor(\n def: TelephoneNumberFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options } = def\n\n let formSchema = joi\n .string()\n .trim()\n .pattern(PATTERN)\n .label(this.label)\n .required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'string.empty': message,\n 'string.pattern.base': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n addClassOptionIfNone(options, 'govuk-input--width-20')\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n const { attributes } = viewModel\n\n attributes.autocomplete = 'tel'\n\n return {\n ...viewModel,\n type: 'tel'\n }\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n { type: 'format', template: messageTemplate.format }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAA6B,KAAK;AAE5C,SAASC,aAAa;AACtB,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAOxB,MAAMC,OAAO,GAAG,kBAAkB;AAElC,OAAO,MAAMC,oBAAoB,SAASJ,aAAa,CAAC;EAKtDK,WAAWA,CACTC,GAAkC,EAClCC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IAEvB,IAAIG,UAAU,GAAGV,GAAG,CACjBW,MAAM,CAAC,CAAC,CACRC,IAAI,CAAC,CAAC,CACNC,OAAO,CAACT,OAAO,CAAC,CAChBU,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBC,QAAQ,CAAC,CAAC;IAEb,IAAIN,OAAO,CAACM,QAAQ,KAAK,KAAK,EAAE;MAC9BL,UAAU,GAAGA,UAAU,CAACM,KAAK,CAAC,EAAE,CAAC;IACnC;IAEA,IAAIP,OAAO,CAACQ,uBAAuB,EAAE;MACnC,MAAMC,OAAO,GAAGT,OAAO,CAACQ,uBAAuB;MAE/CP,UAAU,GAAGA,UAAU,CAACS,QAAQ,CAAC;QAC/B,cAAc,EAAED,OAAO;QACvB,cAAc,EAAEA,OAAO;QACvB,qBAAqB,EAAEA;MACzB,CAAC,CAAC;IACJ,CAAC,MAAM,IAAIT,OAAO,CAACW,wBAAwB,EAAE;MAC3CV,UAAU,GAAGA,UAAU,CAACS,QAAQ,CAACV,OAAO,CAACW,wBAAwB,CAAC;IACpE;IAEAlB,oBAAoB,CAACO,OAAO,EAAE,uBAAuB,CAAC;IAEtD,IAAI,CAACC,UAAU,GAAGA,UAAU,CAACW,OAAO,CAAC,EAAE,CAAC;IACxC,IAAI,CAACC,WAAW,GAAGZ,UAAU,CAACW,OAAO,CAAC,IAAI,CAAC,CAACL,KAAK,CAAC,IAAI,CAAC;IACvD,IAAI,CAACP,OAAO,GAAGA,OAAO;EACxB;EAEAc,YAAYA,CAACC,OAAoB,EAAEC,MAA8B,EAAE;IACjE,MAAMC,SAAS,GAAG,KAAK,CAACH,YAAY,CAACC,OAAO,EAAEC,MAAM,CAAC;IACrD,MAAM;MAAEE;IAAW,CAAC,GAAGD,SAAS;IAEhCC,UAAU,CAACC,YAAY,GAAG,KAAK;IAE/B,OAAO;MACL,GAAGF,SAAS;MACZG,IAAI,EAAE;IACR,CAAC;EACH;;EAEA;AACF;AACA;EACEC,oBAAoBA,CAAA,EAA6B;IAC/C,OAAO;MACLC,UAAU,EAAE,CACV;QAAEF,IAAI,EAAE,UAAU;QAAEG,QAAQ,EAAE7B,eAAe,CAACY;MAAS,CAAC,EACxD;QAAEc,IAAI,EAAE,QAAQ;QAAEG,QAAQ,EAAE7B,eAAe,CAAC8B;MAAO,CAAC,CACrD;MACDC,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import joi from 'joi';
|
|
2
2
|
import { FormComponent, isFormValue } from "./FormComponent.js";
|
|
3
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
3
4
|
export class TextField extends FormComponent {
|
|
4
5
|
constructor(def, props) {
|
|
5
6
|
super(def, props);
|
|
6
7
|
const {
|
|
7
|
-
options
|
|
8
|
-
title
|
|
8
|
+
options
|
|
9
9
|
} = def;
|
|
10
10
|
const schema = 'schema' in def ? def.schema : {};
|
|
11
|
-
let formSchema = joi.string().trim().label(
|
|
11
|
+
let formSchema = joi.string().trim().label(this.label).required();
|
|
12
12
|
if (options.required === false) {
|
|
13
13
|
formSchema = formSchema.allow('');
|
|
14
14
|
}
|
|
@@ -56,6 +56,25 @@ export class TextField extends FormComponent {
|
|
|
56
56
|
isValue(value) {
|
|
57
57
|
return TextField.isText(value);
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* For error preview page that shows all possible errors on a component
|
|
62
|
+
*/
|
|
63
|
+
getAllPossibleErrors() {
|
|
64
|
+
return {
|
|
65
|
+
baseErrors: [{
|
|
66
|
+
type: 'required',
|
|
67
|
+
template: messageTemplate.required
|
|
68
|
+
}],
|
|
69
|
+
advancedSettingsErrors: [{
|
|
70
|
+
type: 'min',
|
|
71
|
+
template: messageTemplate.min
|
|
72
|
+
}, {
|
|
73
|
+
type: 'max',
|
|
74
|
+
template: messageTemplate.max
|
|
75
|
+
}]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
59
78
|
static isText(value) {
|
|
60
79
|
return isFormValue(value) && typeof value === 'string';
|
|
61
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","names":["joi","FormComponent","isFormValue","TextField","constructor","def","props","options","
|
|
1
|
+
{"version":3,"file":"TextField.js","names":["joi","FormComponent","isFormValue","messageTemplate","TextField","constructor","def","props","options","schema","formSchema","string","trim","label","required","allow","length","max","min","regex","pattern","RegExp","customValidationMessage","message","messages","customValidationMessages","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","isText","getAllPossibleErrors","baseErrors","type","template","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/TextField.ts"],"sourcesContent":["import {\n type EmailAddressFieldComponent,\n type TextFieldComponent\n} from '@defra/forms-model'\nimport joi, { type StringSchema } from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormState,\n type FormStateValue,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class TextField extends FormComponent {\n declare options:\n | TextFieldComponent['options']\n | EmailAddressFieldComponent['options']\n\n declare schema: TextFieldComponent['schema']\n\n declare formSchema: StringSchema\n declare stateSchema: StringSchema\n\n constructor(\n def: TextFieldComponent | EmailAddressFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options } = def\n const schema = 'schema' in def ? def.schema : {}\n\n let formSchema = joi.string().trim().label(this.label).required()\n\n if (options.required === false) {\n formSchema = formSchema.allow('')\n }\n\n if (typeof schema.length !== 'number') {\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n } else {\n formSchema = formSchema.length(schema.length)\n }\n\n if (schema.regex) {\n const pattern = new RegExp(schema.regex)\n formSchema = formSchema.pattern(pattern)\n }\n\n if (options.customValidationMessage) {\n const message = options.customValidationMessage\n\n formSchema = formSchema.messages({\n 'any.required': message,\n 'string.empty': message,\n 'string.max': message,\n 'string.min': message,\n 'string.length': message,\n 'string.pattern.base': message\n })\n } else if (options.customValidationMessages) {\n formSchema = formSchema.messages(options.customValidationMessages)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n this.schema = schema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n isValue(value?: FormStateValue | FormState): value is string {\n return TextField.isText(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [{ type: 'required', template: messageTemplate.required }],\n advancedSettingsErrors: [\n { type: 'min', template: messageTemplate.min },\n { type: 'max', template: messageTemplate.max }\n ]\n }\n }\n\n static isText(value?: FormStateValue | FormState): value is string {\n return isFormValue(value) && typeof value === 'string'\n }\n}\n"],"mappings":"AAIA,OAAOA,GAAG,MAA6B,KAAK;AAE5C,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAQxB,OAAO,MAAMC,SAAS,SAASH,aAAa,CAAC;EAU3CI,WAAWA,CACTC,GAAoD,EACpDC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IACvB,MAAMG,MAAM,GAAG,QAAQ,IAAIH,GAAG,GAAGA,GAAG,CAACG,MAAM,GAAG,CAAC,CAAC;IAEhD,IAAIC,UAAU,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CAACC,QAAQ,CAAC,CAAC;IAEjE,IAAIN,OAAO,CAACM,QAAQ,KAAK,KAAK,EAAE;MAC9BJ,UAAU,GAAGA,UAAU,CAACK,KAAK,CAAC,EAAE,CAAC;IACnC;IAEA,IAAI,OAAON,MAAM,CAACO,MAAM,KAAK,QAAQ,EAAE;MACrC,IAAI,OAAOP,MAAM,CAACQ,GAAG,KAAK,QAAQ,EAAE;QAClCP,UAAU,GAAGA,UAAU,CAACO,GAAG,CAACR,MAAM,CAACQ,GAAG,CAAC;MACzC;MAEA,IAAI,OAAOR,MAAM,CAACS,GAAG,KAAK,QAAQ,EAAE;QAClCR,UAAU,GAAGA,UAAU,CAACQ,GAAG,CAACT,MAAM,CAACS,GAAG,CAAC;MACzC;IACF,CAAC,MAAM;MACLR,UAAU,GAAGA,UAAU,CAACM,MAAM,CAACP,MAAM,CAACO,MAAM,CAAC;IAC/C;IAEA,IAAIP,MAAM,CAACU,KAAK,EAAE;MAChB,MAAMC,OAAO,GAAG,IAAIC,MAAM,CAACZ,MAAM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