@defra/forms-model 3.0.384 → 3.0.386
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/components/types.js.map +1 -1
- package/dist/module/conditions/condition-operators.js +2 -2
- package/dist/module/conditions/condition-operators.js.map +1 -1
- package/dist/module/conditions/condition-value-abstract.js +1 -1
- package/dist/module/conditions/condition-value-abstract.js.map +1 -1
- package/dist/module/conditions/condition-values.js +2 -2
- package/dist/module/conditions/condition-values.js.map +1 -1
- package/dist/types/components/types.d.ts +11 -13
- package/dist/types/components/types.d.ts.map +1 -1
- package/dist/types/conditions/condition-value-abstract.d.ts +1 -1
- package/dist/types/conditions/condition-value-abstract.d.ts.map +1 -1
- package/dist/types/conditions/condition-values.d.ts +2 -2
- package/dist/types/conditions/condition-values.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/types.ts +11 -13
- package/src/conditions/condition-operators.ts +2 -2
- package/src/conditions/condition-value-abstract.ts +1 -1
- package/src/conditions/condition-values.ts +2 -2
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/components/types.ts"],"sourcesContent":["import { type LanguageMessages } from 'joi'\n\nimport { type ComponentType } from '~/src/components/enums.js'\nimport {\n type ListTypeContent,\n type ListTypeOption\n} from '~/src/form/form-definition/types.js'\n\nexport type ConditionalComponentType = Exclude<\n ConditionalComponentsDef['type'],\n ContentComponentsDef\n>\n\n/**\n * Types for Components JSON structure which are expected by engine and turned into actual form input/content/lists\n */\n\ninterface FormFieldBase {\n type: FormComponentsDef['type']\n name: string\n title: string\n hint?: string\n options: {\n required?: boolean\n optionalText?: boolean\n classes?: string\n customValidationMessages?: LanguageMessages\n }\n}\n\ninterface ListFieldBase extends FormFieldBase {\n type:\n | ComponentType.AutocompleteField\n | ComponentType.CheckboxesField\n | ComponentType.RadiosField\n | ComponentType.SelectField\n list: string\n options: FormFieldBase['options'] & {\n type?: ListTypeContent\n }\n}\n\ninterface ContentFieldBase {\n type:\n | ComponentType.Details\n | ComponentType.Html\n | ComponentType.InsetText\n | ComponentType.List\n name: string\n title: string\n}\n\ninterface DateFieldBase {\n type: ComponentType.DatePartsField | ComponentType.MonthYearField\n name: string\n title: string\n hint?: string\n options:
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/components/types.ts"],"sourcesContent":["import { type LanguageMessages } from 'joi'\n\nimport { type ComponentType } from '~/src/components/enums.js'\nimport {\n type ListTypeContent,\n type ListTypeOption\n} from '~/src/form/form-definition/types.js'\n\nexport type ConditionalComponentType = Exclude<\n ConditionalComponentsDef['type'],\n ContentComponentsDef\n>\n\n/**\n * Types for Components JSON structure which are expected by engine and turned into actual form input/content/lists\n */\n\ninterface FormFieldBase {\n type: FormComponentsDef['type']\n name: string\n title: string\n hint?: string\n options: {\n required?: boolean\n optionalText?: boolean\n classes?: string\n customValidationMessages?: LanguageMessages\n }\n}\n\ninterface ListFieldBase extends FormFieldBase {\n type:\n | ComponentType.AutocompleteField\n | ComponentType.CheckboxesField\n | ComponentType.RadiosField\n | ComponentType.SelectField\n list: string\n options: FormFieldBase['options'] & {\n type?: ListTypeContent\n }\n}\n\ninterface ContentFieldBase {\n type:\n | ComponentType.Details\n | ComponentType.Html\n | ComponentType.InsetText\n | ComponentType.List\n name: string\n title: string\n options?: {\n required?: undefined\n optionalText?: undefined\n }\n}\n\ninterface DateFieldBase extends FormFieldBase {\n type: ComponentType.DatePartsField | ComponentType.MonthYearField\n name: string\n title: string\n hint?: string\n options: FormFieldBase['options'] & {\n maxDaysInPast?: number\n maxDaysInFuture?: number\n }\n}\n\n// Text Fields\nexport interface TextFieldComponent extends FormFieldBase {\n type: ComponentType.TextField\n options: FormFieldBase['options'] & {\n autocomplete?: string\n condition?: string\n customValidationMessage?: string\n }\n schema: {\n max?: number\n min?: number\n length?: number\n regex?: string\n }\n}\n\nexport interface EmailAddressFieldComponent extends FormFieldBase {\n type: ComponentType.EmailAddressField\n options: FormFieldBase['options'] & {\n condition?: string\n customValidationMessage?: string\n }\n}\n\nexport interface NumberFieldComponent extends FormFieldBase {\n type: ComponentType.NumberField\n options: FormFieldBase['options'] & {\n prefix?: string\n suffix?: string\n autocomplete?: string\n condition?: string\n customValidationMessage?: string\n }\n schema: {\n max?: number\n min?: number\n precision?: number\n }\n}\n\nexport interface TelephoneNumberFieldComponent extends FormFieldBase {\n type: ComponentType.TelephoneNumberField\n options: FormFieldBase['options'] & {\n condition?: string\n customValidationMessage?: string\n }\n}\n\nexport interface FileUploadFieldComponent extends FormFieldBase {\n type: ComponentType.FileUploadField\n name: string\n title: string\n hint?: string\n options: FormFieldBase['options'] & {\n accept?: string\n }\n schema: {\n max?: number\n min?: number\n length?: number\n }\n}\n\nexport interface YesNoFieldComponent extends FormFieldBase {\n type: ComponentType.YesNoField\n options: FormFieldBase['options'] & {\n condition?: string\n }\n}\n\nexport interface MultilineTextFieldComponent extends FormFieldBase {\n type: ComponentType.MultilineTextField\n options: FormFieldBase['options'] & {\n autocomplete?: string\n condition?: string\n customValidationMessage?: string\n rows?: number\n maxWords?: number\n }\n schema: {\n max?: number\n min?: number\n length?: number\n regex?: string\n }\n}\n\nexport interface UkAddressFieldComponent extends FormFieldBase {\n type: ComponentType.UkAddressField\n options: FormFieldBase['options'] & {\n hideTitle?: boolean\n }\n}\n\n// Date Fields\nexport interface DatePartsFieldComponent extends DateFieldBase {\n type: ComponentType.DatePartsField\n options: DateFieldBase['options'] & {\n condition?: string\n }\n}\n\nexport interface MonthYearFieldComponent extends DateFieldBase {\n type: ComponentType.MonthYearField\n options: DateFieldBase['options'] & {\n customValidationMessage?: string\n }\n}\n\n// Content Fields\nexport interface DetailsComponent extends ContentFieldBase {\n type: ComponentType.Details\n content: string\n options: ContentFieldBase['options'] & {\n condition?: string\n }\n}\n\nexport interface HtmlComponent extends ContentFieldBase {\n type: ComponentType.Html\n content: string\n options: ContentFieldBase['options'] & {\n condition?: string\n }\n}\n\nexport interface InsetTextComponent extends ContentFieldBase {\n type: ComponentType.InsetText\n content: string\n}\n\nexport interface ListComponent extends ContentFieldBase {\n type: ComponentType.List\n hint?: string\n list: string\n options: ContentFieldBase['options'] & {\n type?: ListTypeOption\n classes?: string\n hideTitle?: boolean\n bold?: boolean\n }\n}\n\nexport interface AutocompleteFieldComponent extends ListFieldBase {\n type: ComponentType.AutocompleteField\n options: ListFieldBase['options'] & {\n condition?: string\n }\n}\n\nexport interface CheckboxesFieldComponent extends ListFieldBase {\n type: ComponentType.CheckboxesField\n options: ListFieldBase['options'] & {\n bold?: boolean\n condition?: string\n }\n}\n\nexport interface RadiosFieldComponent extends ListFieldBase {\n type: ComponentType.RadiosField\n options: ListFieldBase['options'] & {\n bold?: boolean\n condition?: string\n }\n}\n\nexport interface SelectFieldComponent extends ListFieldBase {\n type: ComponentType.SelectField\n options: ListFieldBase['options'] & {\n autocomplete?: string\n condition?: string\n }\n}\n\nexport type ComponentDef = FormComponentsDef | ContentComponentsDef\n\n// Components that render form fields\nexport type FormComponentsDef =\n | InputFieldsComponentsDef\n | SelectionComponentsDef\n\n// Components that render inputs\nexport type InputFieldsComponentsDef =\n | TextFieldComponent\n | EmailAddressFieldComponent\n | NumberFieldComponent\n | MultilineTextFieldComponent\n | TelephoneNumberFieldComponent\n | MonthYearFieldComponent\n | DatePartsFieldComponent\n | UkAddressFieldComponent\n | FileUploadFieldComponent\n\n// Components that render content\nexport type ContentComponentsDef =\n | DetailsComponent\n | HtmlComponent\n | InsetTextComponent\n | ListComponent\n\n// Components that render lists\nexport type ListComponentsDef =\n | Exclude<SelectionComponentsDef, YesNoFieldComponent>\n | ListComponent\n\n// Components that have selection fields\nexport type SelectionComponentsDef =\n | AutocompleteFieldComponent\n | CheckboxesFieldComponent\n | RadiosFieldComponent\n | SelectFieldComponent\n | YesNoFieldComponent\n\n// Components that have condition support\nexport type ConditionalComponentsDef = Exclude<\n ComponentDef,\n | InsetTextComponent\n | ListComponent\n | MonthYearFieldComponent\n | UkAddressFieldComponent\n | FileUploadFieldComponent\n>\n"],"mappings":"","ignoreList":[]}
|
@@ -106,9 +106,9 @@ function not(operatorDefinition) {
|
|
106
106
|
}
|
107
107
|
function formatValue(field, value) {
|
108
108
|
if (field.type === ComponentType.DatePartsField && value.type === ConditionType.RelativeDate || field.type === ComponentType.NumberField || field.type === ComponentType.YesNoField) {
|
109
|
-
return value.
|
109
|
+
return value.toValue();
|
110
110
|
}
|
111
|
-
return `'${value.
|
111
|
+
return `'${value.toValue().replace(/'/g, "\\'")}'`;
|
112
112
|
}
|
113
113
|
export const absoluteDateOperatorNames = Object.keys(absoluteDateOperators);
|
114
114
|
export const relativeDateOperatorNames = Object.keys(relativeDateOperators);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-operators.js","names":["ComponentType","isConditionalType","isContentType","ConditionValue","RelativeDateValue","ConditionType","DateDirections","Operator","OperatorName","defaultOperators","Is","inline","IsNot","withDefaults","operators","textFieldOperators","IsLongerThan","lengthIs","IsMoreThan","IsShorterThan","IsLessThan","HasLength","absoluteDateOperators","absoluteDate","IsBefore","IsAfter","relativeDateOperators","IsAtLeast","relativeDate","IsAtMost","customOperators","AutocompleteField","RadiosField","CheckboxesField","Contains","reverseInline","DoesNotContain","not","NumberField","DatePartsField","TextField","MultilineTextField","EmailAddressField","TelephoneNumberField","SelectField","YesNoField","getOperatorNames","fieldType","conditionals","getConditionals","Object","keys","getExpression","fieldName","operator","value","expression","type","name","field","formatValue","operatorDefinition","RelativeDate","toExpression","absoluteDateOperatorNames","relativeDateOperatorNames","Error","pastOperator","futureOperator","isPast","direction","PAST"],"sources":["../../../src/conditions/condition-operators.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { isConditionalType, isContentType } from '~/src/components/helpers.js'\nimport {\n type ComponentDef,\n type ConditionalComponentType\n} from '~/src/components/types.js'\nimport {\n ConditionValue,\n RelativeDateValue\n} from '~/src/conditions/condition-values.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport {\n ConditionType,\n DateDirections,\n Operator,\n OperatorName\n} from '~/src/conditions/enums.js'\nimport {\n type Conditionals,\n type OperatorDefinition\n} from '~/src/conditions/types.js'\n\nconst defaultOperators = {\n [OperatorName.Is]: inline(Operator.Is),\n [OperatorName.IsNot]: inline(Operator.IsNot)\n}\n\nfunction withDefaults<T>(operators: T) {\n return { ...defaultOperators, ...operators }\n}\n\nconst textFieldOperators = {\n [OperatorName.IsLongerThan]: lengthIs(Operator.IsMoreThan),\n [OperatorName.IsShorterThan]: lengthIs(Operator.IsLessThan),\n [OperatorName.HasLength]: lengthIs(Operator.Is)\n}\n\nconst absoluteDateOperators = {\n [OperatorName.Is]: absoluteDate(Operator.Is),\n [OperatorName.IsNot]: absoluteDate(Operator.IsNot),\n [OperatorName.IsBefore]: absoluteDate(Operator.IsLessThan),\n [OperatorName.IsAfter]: absoluteDate(Operator.IsMoreThan)\n}\n\nconst relativeDateOperators = {\n [OperatorName.IsAtLeast]: relativeDate(Operator.IsAtMost, Operator.IsAtLeast),\n [OperatorName.IsAtMost]: relativeDate(Operator.IsAtLeast, Operator.IsAtMost),\n [OperatorName.IsLessThan]: relativeDate(\n Operator.IsMoreThan,\n Operator.IsLessThan\n ),\n [OperatorName.IsMoreThan]: relativeDate(\n Operator.IsLessThan,\n Operator.IsMoreThan\n )\n}\n\nexport const customOperators = {\n [ComponentType.AutocompleteField]: defaultOperators,\n [ComponentType.RadiosField]: defaultOperators,\n [ComponentType.CheckboxesField]: {\n [OperatorName.Contains]: reverseInline(Operator.Contains),\n [OperatorName.DoesNotContain]: not(reverseInline(Operator.Contains))\n },\n [ComponentType.NumberField]: withDefaults({\n [OperatorName.IsAtLeast]: inline(Operator.IsAtLeast),\n [OperatorName.IsAtMost]: inline(Operator.IsAtMost),\n [OperatorName.IsLessThan]: inline(Operator.IsLessThan),\n [OperatorName.IsMoreThan]: inline(Operator.IsMoreThan)\n }),\n [ComponentType.DatePartsField]: {\n ...absoluteDateOperators,\n ...relativeDateOperators\n },\n [ComponentType.TextField]: withDefaults(textFieldOperators),\n [ComponentType.MultilineTextField]: withDefaults(textFieldOperators),\n [ComponentType.EmailAddressField]: withDefaults(textFieldOperators),\n [ComponentType.TelephoneNumberField]: defaultOperators,\n [ComponentType.SelectField]: defaultOperators,\n [ComponentType.YesNoField]: defaultOperators\n}\n\nexport function getOperatorNames(fieldType?: ConditionalComponentType) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return []\n }\n\n return Object.keys(conditionals) as OperatorName[]\n}\n\nexport function getExpression(\n fieldType: ConditionalComponentType,\n fieldName: string,\n operator: OperatorName,\n value: Condition['value']\n) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return\n }\n\n return conditionals[operator]?.expression(\n { type: fieldType, name: fieldName },\n value\n )\n}\n\nfunction getConditionals(\n fieldType?: ConditionalComponentType\n): Partial<Conditionals> | undefined {\n if (!fieldType || !isConditionalType(fieldType) || isContentType(fieldType)) {\n return\n }\n\n return fieldType in customOperators\n ? customOperators[fieldType]\n : defaultOperators\n}\n\nfunction inline(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction lengthIs(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `length(${field.name}) ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction reverseInline(operator: Operator.Contains): OperatorDefinition {\n return {\n expression(field, value) {\n return `${formatValue(field, value)} ${operator} ${field.name}`\n }\n }\n}\n\nfunction not(operatorDefinition: OperatorDefinition): OperatorDefinition {\n return {\n expression(field, value) {\n return `not (${operatorDefinition.expression(field, value)})`\n }\n }\n}\n\nfunction formatValue(\n field: Pick<ComponentDef, 'type'>,\n value: Condition['value']\n) {\n if (\n (field.type === ComponentType.DatePartsField &&\n value.type === ConditionType.RelativeDate) ||\n field.type === ComponentType.NumberField ||\n field.type === ComponentType.YesNoField\n ) {\n return value.toExpression()\n }\n\n return `'${value.toExpression()}'`\n}\n\nexport const absoluteDateOperatorNames = Object.keys(\n absoluteDateOperators\n) as OperatorName[]\n\nexport const relativeDateOperatorNames = Object.keys(\n relativeDateOperators\n) as OperatorName[]\n\nfunction absoluteDate(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof ConditionValue)) {\n throw new Error(\n \"Expression param 'value' must be ConditionValue instance\"\n )\n }\n\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction relativeDate(\n pastOperator: Operator,\n futureOperator: Operator\n): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof RelativeDateValue)) {\n throw new Error(\n \"Expression param 'value' must be RelativeDateValue instance\"\n )\n }\n\n const isPast = value.direction === DateDirections.PAST\n return `${field.name} ${isPast ? pastOperator : futureOperator} ${formatValue(field, value)}`\n }\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,iBAAiB,EAAEC,aAAa;AAKzC,SACEC,cAAc,EACdC,iBAAiB;AAGnB,SACEC,aAAa,EACbC,cAAc,EACdC,QAAQ,EACRC,YAAY;AAOd,MAAMC,gBAAgB,GAAG;EACvB,CAACD,YAAY,CAACE,EAAE,GAAGC,MAAM,CAACJ,QAAQ,CAACG,EAAE,CAAC;EACtC,CAACF,YAAY,CAACI,KAAK,GAAGD,MAAM,CAACJ,QAAQ,CAACK,KAAK;AAC7C,CAAC;AAED,SAASC,YAAYA,CAAIC,SAAY,EAAE;EACrC,OAAO;IAAE,GAAGL,gBAAgB;IAAE,GAAGK;EAAU,CAAC;AAC9C;AAEA,MAAMC,kBAAkB,GAAG;EACzB,CAACP,YAAY,CAACQ,YAAY,GAAGC,QAAQ,CAACV,QAAQ,CAACW,UAAU,CAAC;EAC1D,CAACV,YAAY,CAACW,aAAa,GAAGF,QAAQ,CAACV,QAAQ,CAACa,UAAU,CAAC;EAC3D,CAACZ,YAAY,CAACa,SAAS,GAAGJ,QAAQ,CAACV,QAAQ,CAACG,EAAE;AAChD,CAAC;AAED,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,EAAEJ,KAAK,CAAC,EAAE;IAC/F;EACF,CAAC;AACH","ignoreList":[]}
|
1
|
+
{"version":3,"file":"condition-operators.js","names":["ComponentType","isConditionalType","isContentType","ConditionValue","RelativeDateValue","ConditionType","DateDirections","Operator","OperatorName","defaultOperators","Is","inline","IsNot","withDefaults","operators","textFieldOperators","IsLongerThan","lengthIs","IsMoreThan","IsShorterThan","IsLessThan","HasLength","absoluteDateOperators","absoluteDate","IsBefore","IsAfter","relativeDateOperators","IsAtLeast","relativeDate","IsAtMost","customOperators","AutocompleteField","RadiosField","CheckboxesField","Contains","reverseInline","DoesNotContain","not","NumberField","DatePartsField","TextField","MultilineTextField","EmailAddressField","TelephoneNumberField","SelectField","YesNoField","getOperatorNames","fieldType","conditionals","getConditionals","Object","keys","getExpression","fieldName","operator","value","expression","type","name","field","formatValue","operatorDefinition","RelativeDate","toValue","replace","absoluteDateOperatorNames","relativeDateOperatorNames","Error","pastOperator","futureOperator","isPast","direction","PAST"],"sources":["../../../src/conditions/condition-operators.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { isConditionalType, isContentType } from '~/src/components/helpers.js'\nimport {\n type ComponentDef,\n type ConditionalComponentType\n} from '~/src/components/types.js'\nimport {\n ConditionValue,\n RelativeDateValue\n} from '~/src/conditions/condition-values.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport {\n ConditionType,\n DateDirections,\n Operator,\n OperatorName\n} from '~/src/conditions/enums.js'\nimport {\n type Conditionals,\n type OperatorDefinition\n} from '~/src/conditions/types.js'\n\nconst defaultOperators = {\n [OperatorName.Is]: inline(Operator.Is),\n [OperatorName.IsNot]: inline(Operator.IsNot)\n}\n\nfunction withDefaults<T>(operators: T) {\n return { ...defaultOperators, ...operators }\n}\n\nconst textFieldOperators = {\n [OperatorName.IsLongerThan]: lengthIs(Operator.IsMoreThan),\n [OperatorName.IsShorterThan]: lengthIs(Operator.IsLessThan),\n [OperatorName.HasLength]: lengthIs(Operator.Is)\n}\n\nconst absoluteDateOperators = {\n [OperatorName.Is]: absoluteDate(Operator.Is),\n [OperatorName.IsNot]: absoluteDate(Operator.IsNot),\n [OperatorName.IsBefore]: absoluteDate(Operator.IsLessThan),\n [OperatorName.IsAfter]: absoluteDate(Operator.IsMoreThan)\n}\n\nconst relativeDateOperators = {\n [OperatorName.IsAtLeast]: relativeDate(Operator.IsAtMost, Operator.IsAtLeast),\n [OperatorName.IsAtMost]: relativeDate(Operator.IsAtLeast, Operator.IsAtMost),\n [OperatorName.IsLessThan]: relativeDate(\n Operator.IsMoreThan,\n Operator.IsLessThan\n ),\n [OperatorName.IsMoreThan]: relativeDate(\n Operator.IsLessThan,\n Operator.IsMoreThan\n )\n}\n\nexport const customOperators = {\n [ComponentType.AutocompleteField]: defaultOperators,\n [ComponentType.RadiosField]: defaultOperators,\n [ComponentType.CheckboxesField]: {\n [OperatorName.Contains]: reverseInline(Operator.Contains),\n [OperatorName.DoesNotContain]: not(reverseInline(Operator.Contains))\n },\n [ComponentType.NumberField]: withDefaults({\n [OperatorName.IsAtLeast]: inline(Operator.IsAtLeast),\n [OperatorName.IsAtMost]: inline(Operator.IsAtMost),\n [OperatorName.IsLessThan]: inline(Operator.IsLessThan),\n [OperatorName.IsMoreThan]: inline(Operator.IsMoreThan)\n }),\n [ComponentType.DatePartsField]: {\n ...absoluteDateOperators,\n ...relativeDateOperators\n },\n [ComponentType.TextField]: withDefaults(textFieldOperators),\n [ComponentType.MultilineTextField]: withDefaults(textFieldOperators),\n [ComponentType.EmailAddressField]: withDefaults(textFieldOperators),\n [ComponentType.TelephoneNumberField]: defaultOperators,\n [ComponentType.SelectField]: defaultOperators,\n [ComponentType.YesNoField]: defaultOperators\n}\n\nexport function getOperatorNames(fieldType?: ConditionalComponentType) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return []\n }\n\n return Object.keys(conditionals) as OperatorName[]\n}\n\nexport function getExpression(\n fieldType: ConditionalComponentType,\n fieldName: string,\n operator: OperatorName,\n value: Condition['value']\n) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return\n }\n\n return conditionals[operator]?.expression(\n { type: fieldType, name: fieldName },\n value\n )\n}\n\nfunction getConditionals(\n fieldType?: ConditionalComponentType\n): Partial<Conditionals> | undefined {\n if (!fieldType || !isConditionalType(fieldType) || isContentType(fieldType)) {\n return\n }\n\n return fieldType in customOperators\n ? customOperators[fieldType]\n : defaultOperators\n}\n\nfunction inline(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction lengthIs(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `length(${field.name}) ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction reverseInline(operator: Operator.Contains): OperatorDefinition {\n return {\n expression(field, value) {\n return `${formatValue(field, value)} ${operator} ${field.name}`\n }\n }\n}\n\nfunction not(operatorDefinition: OperatorDefinition): OperatorDefinition {\n return {\n expression(field, value) {\n return `not (${operatorDefinition.expression(field, value)})`\n }\n }\n}\n\nfunction formatValue(\n field: Pick<ComponentDef, 'type'>,\n value: Condition['value']\n) {\n if (\n (field.type === ComponentType.DatePartsField &&\n value.type === ConditionType.RelativeDate) ||\n field.type === ComponentType.NumberField ||\n field.type === ComponentType.YesNoField\n ) {\n return value.toValue()\n }\n\n return `'${value.toValue().replace(/'/g, \"\\\\'\")}'`\n}\n\nexport const absoluteDateOperatorNames = Object.keys(\n absoluteDateOperators\n) as OperatorName[]\n\nexport const relativeDateOperatorNames = Object.keys(\n relativeDateOperators\n) as OperatorName[]\n\nfunction absoluteDate(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof ConditionValue)) {\n throw new Error(\n \"Expression param 'value' must be ConditionValue instance\"\n )\n }\n\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction relativeDate(\n pastOperator: Operator,\n futureOperator: Operator\n): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof RelativeDateValue)) {\n throw new Error(\n \"Expression param 'value' must be RelativeDateValue instance\"\n )\n }\n\n const isPast = value.direction === DateDirections.PAST\n return `${field.name} ${isPast ? pastOperator : futureOperator} ${formatValue(field, value)}`\n }\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,iBAAiB,EAAEC,aAAa;AAKzC,SACEC,cAAc,EACdC,iBAAiB;AAGnB,SACEC,aAAa,EACbC,cAAc,EACdC,QAAQ,EACRC,YAAY;AAOd,MAAMC,gBAAgB,GAAG;EACvB,CAACD,YAAY,CAACE,EAAE,GAAGC,MAAM,CAACJ,QAAQ,CAACG,EAAE,CAAC;EACtC,CAACF,YAAY,CAACI,KAAK,GAAGD,MAAM,CAACJ,QAAQ,CAACK,KAAK;AAC7C,CAAC;AAED,SAASC,YAAYA,CAAIC,SAAY,EAAE;EACrC,OAAO;IAAE,GAAGL,gBAAgB;IAAE,GAAGK;EAAU,CAAC;AAC9C;AAEA,MAAMC,kBAAkB,GAAG;EACzB,CAACP,YAAY,CAACQ,YAAY,GAAGC,QAAQ,CAACV,QAAQ,CAACW,UAAU,CAAC;EAC1D,CAACV,YAAY,CAACW,aAAa,GAAGF,QAAQ,CAACV,QAAQ,CAACa,UAAU,CAAC;EAC3D,CAACZ,YAAY,CAACa,SAAS,GAAGJ,QAAQ,CAACV,QAAQ,CAACG,EAAE;AAChD,CAAC;AAED,MAAMY,qBAAqB,GAAG;EAC5B,CAACd,YAAY,CAACE,EAAE,GAAGa,YAAY,CAAChB,QAAQ,CAACG,EAAE,CAAC;EAC5C,CAACF,YAAY,CAACI,KAAK,GAAGW,YAAY,CAAChB,QAAQ,CAACK,KAAK,CAAC;EAClD,CAACJ,YAAY,CAACgB,QAAQ,GAAGD,YAAY,CAAChB,QAAQ,CAACa,UAAU,CAAC;EAC1D,CAACZ,YAAY,CAACiB,OAAO,GAAGF,YAAY,CAAChB,QAAQ,CAACW,UAAU;AAC1D,CAAC;AAED,MAAMQ,qB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CAAC,IAAI,EAAE,KAAK,CAAC,GAAG;AACpD;AAEA,OAAO,MAAMC,yBAAyB,GAAGf,MAAM,CAACC,IAAI,CAClD7B,qBACF,CAAmB;AAEnB,OAAO,MAAM4C,yBAAyB,GAAGhB,MAAM,CAACC,IAAI,CAClDzB,qBACF,CAAmB;AAEnB,SAASH,YAAYA,CAAC+B,QAAkB,EAAsB;EAC5D,OAAO;IACLE,UAAUA,CAACG,KAAK,EAAEJ,KAAK,EAAE;MACvB,IAAI,EAAEA,KAAK,YAAYpD,cAAc,CAAC,EAAE;QACtC,MAAM,IAAIgE,KAAK,CACb,0DACF,CAAC;MACH;MAEA,OAAO,GAAGR,KAAK,CAACD,IAAI,IAAIJ,QAAQ,IAAIM,WAAW,CAACD,KAAK,EAAEJ,KAAK,CAAC,EAAE;IACjE;EACF,CAAC;AACH;AAEA,SAAS3B,YAAYA,CACnBwC,YAAsB,EACtBC,cAAwB,EACJ;EACpB,OAAO;IACLb,UAAUA,CAACG,KAAK,EAAEJ,KAAK,EAAE;MACvB,IAAI,EAAEA,KAAK,YAAYnD,iBAAiB,CAAC,EAAE;QACzC,MAAM,IAAI+D,KAAK,CACb,6DACF,CAAC;MACH;MAEA,MAAMG,MAAM,GAAGf,KAAK,CAACgB,SAAS,KAAKjE,cAAc,CAACkE,IAAI;MACtD,OAAO,GAAGb,KAAK,CAACD,IAAI,IAAIY,MAAM,GAAGF,YAAY,GAAGC,cAAc,IAAIT,WAAW,CAACD,KAAK,EAAEJ,KAAK,CAAC,EAAE;IAC/F;EACF,CAAC;AACH","ignoreList":[]}
|
@@ -2,7 +2,7 @@ export class ConditionValueAbstract {
|
|
2
2
|
toPresentationString() {
|
3
3
|
throw new Error('Unsupported Operation. Method toPresentationString has not been implemented');
|
4
4
|
}
|
5
|
-
|
5
|
+
toValue() {
|
6
6
|
throw new Error('Unsupported Operation. Method toExpression has not been implemented');
|
7
7
|
}
|
8
8
|
clone() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-value-abstract.js","names":["ConditionValueAbstract","toPresentationString","Error","
|
1
|
+
{"version":3,"file":"condition-value-abstract.js","names":["ConditionValueAbstract","toPresentationString","Error","toValue","clone"],"sources":["../../../src/conditions/condition-value-abstract.ts"],"sourcesContent":["export class ConditionValueAbstract {\n toPresentationString(): string {\n throw new Error(\n 'Unsupported Operation. Method toPresentationString has not been implemented'\n )\n }\n\n toValue(): string {\n throw new Error(\n 'Unsupported Operation. Method toExpression has not been implemented'\n )\n }\n\n clone() {\n throw new Error(\n 'Unsupported Operation. Method clone has not been implemented'\n )\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,sBAAsB,CAAC;EAClCC,oBAAoBA,CAAA,EAAW;IAC7B,MAAM,IAAIC,KAAK,CACb,6EACF,CAAC;EACH;EAEAC,OAAOA,CAAA,EAAW;IAChB,MAAM,IAAID,KAAK,CACb,qEACF,CAAC;EACH;EAEAE,KAAKA,CAAA,EAAG;IACN,MAAM,IAAIF,KAAK,CACb,8DACF,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -19,7 +19,7 @@ export class ConditionValue extends ConditionValueAbstract {
|
|
19
19
|
toPresentationString() {
|
20
20
|
return this.display;
|
21
21
|
}
|
22
|
-
|
22
|
+
toValue() {
|
23
23
|
return this.value;
|
24
24
|
}
|
25
25
|
clone() {
|
@@ -53,7 +53,7 @@ export class RelativeDateValue extends ConditionValueAbstract {
|
|
53
53
|
toPresentationString() {
|
54
54
|
return `${this.period} ${this.unit} ${this.direction}`;
|
55
55
|
}
|
56
|
-
|
56
|
+
toValue() {
|
57
57
|
const period = this.direction === DateDirections.PAST ? 0 - Number(this.period) : this.period;
|
58
58
|
return `dateForComparison(${period}, '${this.unit}')`;
|
59
59
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-values.js","names":["ConditionValueAbstract","ConditionType","DateDirections","ConditionValue","type","value","display","constructor","Error","Value","toPresentationString","
|
1
|
+
{"version":3,"file":"condition-values.js","names":["ConditionValueAbstract","ConditionType","DateDirections","ConditionValue","type","value","display","constructor","Error","Value","toPresentationString","toValue","clone","from","toJSON","structuredClone","obj","RelativeDateValue","period","unit","direction","Object","values","includes","RelativeDate","PAST","Number","conditionValueFrom"],"sources":["../../../src/conditions/condition-values.ts"],"sourcesContent":["import { ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'\nimport { ConditionType, DateDirections } from '~/src/conditions/enums.js'\nimport { type DateUnits } from '~/src/conditions/enums.js'\nimport {\n type ConditionValueData,\n type RelativeDateValueData\n} from '~/src/conditions/types.js'\n\nexport class ConditionValue extends ConditionValueAbstract {\n type: ConditionType.Value\n value: string\n display: string\n\n constructor(value: string, display?: string) {\n if (typeof value !== 'string') {\n throw new Error(\"ConditionValue param 'value' must be a string\")\n }\n\n if (display && typeof display !== 'string') {\n throw new Error(\"ConditionValue param 'display' must be a string\")\n }\n\n super()\n\n this.type = ConditionType.Value\n this.value = value\n this.display = display ?? value\n }\n\n toPresentationString() {\n return this.display\n }\n\n toValue() {\n return this.value\n }\n\n clone() {\n return ConditionValue.from(this)\n }\n\n toJSON(): ConditionValueData {\n return structuredClone(this.clone())\n }\n\n static from(obj: ConditionValue | ConditionValueData) {\n return new ConditionValue(obj.value, obj.display)\n }\n}\n\nexport class RelativeDateValue extends ConditionValueAbstract {\n type: ConditionType.RelativeDate\n period\n unit\n direction\n\n constructor(period: string, unit: DateUnits, direction: DateDirections) {\n if (typeof period !== 'string') {\n throw new Error(\"RelativeDateValue param 'period' must be a string\")\n }\n\n if (!Object.values(DateDirections).includes(direction)) {\n throw new Error(\n \"RelativeDateValue param 'direction' must be from enum DateDirections\"\n )\n }\n\n super()\n\n this.type = ConditionType.RelativeDate\n this.period = period\n this.unit = unit\n this.direction = direction\n }\n\n toPresentationString() {\n return `${this.period} ${this.unit} ${this.direction}`\n }\n\n toValue(): string {\n const period =\n this.direction === DateDirections.PAST\n ? 0 - Number(this.period)\n : this.period\n\n return `dateForComparison(${period}, '${this.unit}')`\n }\n\n clone() {\n return RelativeDateValue.from(this)\n }\n\n toJSON(): RelativeDateValueData {\n return structuredClone(this.clone())\n }\n\n static from(obj: RelativeDateValue | RelativeDateValueData) {\n return new RelativeDateValue(obj.period, obj.unit, obj.direction)\n }\n}\n\nexport function conditionValueFrom(\n obj:\n | ConditionValue\n | ConditionValueData\n | RelativeDateValue\n | RelativeDateValueData\n) {\n if ('clone' in obj) {\n return obj.clone()\n }\n\n switch (obj.type) {\n case ConditionType.Value:\n return ConditionValue.from(obj)\n\n case ConditionType.RelativeDate:\n return RelativeDateValue.from(obj)\n }\n}\n"],"mappings":"AAAA,SAASA,sBAAsB;AAC/B,SAASC,aAAa,EAAEC,cAAc;AAOtC,OAAO,MAAMC,cAAc,SAASH,sBAAsB,CAAC;EACzDI,IAAI;EACJC,KAAK;EACLC,OAAO;EAEPC,WAAWA,CAACF,KAAa,EAAEC,OAAgB,EAAE;IAC3C,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;MAC7B,MAAM,IAAIG,KAAK,CAAC,+CAA+C,CAAC;IAClE;IAEA,IAAIF,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC1C,MAAM,IAAIE,KAAK,CAAC,iDAAiD,CAAC;IACpE;IAEA,KAAK,CAAC,CAAC;IAEP,IAAI,CAACJ,IAAI,GAAGH,aAAa,CAACQ,KAAK;IAC/B,IAAI,CAACJ,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,OAAO,GAAGA,OAAO,IAAID,KAAK;EACjC;EAEAK,oBAAoBA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACJ,OAAO;EACrB;EAEAK,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAACN,KAAK;EACnB;EAEAO,KAAKA,CAAA,EAAG;IACN,OAAOT,cAAc,CAACU,IAAI,CAAC,IAAI,CAAC;EAClC;EAEAC,MAAMA,CAAA,EAAuB;IAC3B,OAAOC,eAAe,CAAC,IAAI,CAACH,KAAK,CAAC,CAAC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AAe,CAAC,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC;EACtC;EAEA,OAAOC,IAAIA,CAACG,GAA8C,EAAE;IAC1D,OAAO,IAAIC,iBAAiB,CAACD,GAAG,CAACE,MAAM,EAAEF,GAAG,CAACG,IAAI,EAAEH,GAAG,CAACI,SAAS,CAAC;EACnE;AACF;AAEA,OAAO,SAASO,kBAAkBA,CAChCX,GAIyB,EACzB;EACA,IAAI,OAAO,IAAIA,GAAG,EAAE;IAClB,OAAOA,GAAG,CAACJ,KAAK,CAAC,CAAC;EACpB;EAEA,QAAQI,GAAG,CAACZ,IAAI;IACd,KAAKH,aAAa,CAACQ,KAAK;MACtB,OAAON,cAAc,CAACU,IAAI,CAACG,GAAG,CAAC;IAEjC,KAAKf,aAAa,CAACuB,YAAY;MAC7B,OAAOP,iBAAiB,CAACJ,IAAI,CAACG,GAAG,CAAC;EACtC;AACF","ignoreList":[]}
|
@@ -28,16 +28,17 @@ interface ContentFieldBase {
|
|
28
28
|
type: ComponentType.Details | ComponentType.Html | ComponentType.InsetText | ComponentType.List;
|
29
29
|
name: string;
|
30
30
|
title: string;
|
31
|
+
options?: {
|
32
|
+
required?: undefined;
|
33
|
+
optionalText?: undefined;
|
34
|
+
};
|
31
35
|
}
|
32
|
-
interface DateFieldBase {
|
36
|
+
interface DateFieldBase extends FormFieldBase {
|
33
37
|
type: ComponentType.DatePartsField | ComponentType.MonthYearField;
|
34
38
|
name: string;
|
35
39
|
title: string;
|
36
40
|
hint?: string;
|
37
|
-
options: {
|
38
|
-
required?: boolean;
|
39
|
-
optionalText?: boolean;
|
40
|
-
classes?: string;
|
41
|
+
options: FormFieldBase['options'] & {
|
41
42
|
maxDaysInPast?: number;
|
42
43
|
maxDaysInFuture?: number;
|
43
44
|
};
|
@@ -85,15 +86,12 @@ export interface TelephoneNumberFieldComponent extends FormFieldBase {
|
|
85
86
|
customValidationMessage?: string;
|
86
87
|
};
|
87
88
|
}
|
88
|
-
export interface FileUploadFieldComponent {
|
89
|
+
export interface FileUploadFieldComponent extends FormFieldBase {
|
89
90
|
type: ComponentType.FileUploadField;
|
90
91
|
name: string;
|
91
92
|
title: string;
|
92
93
|
hint?: string;
|
93
|
-
options: {
|
94
|
-
required?: boolean;
|
95
|
-
classes?: string;
|
96
|
-
optionalText?: boolean;
|
94
|
+
options: FormFieldBase['options'] & {
|
97
95
|
accept?: string;
|
98
96
|
};
|
99
97
|
schema: {
|
@@ -145,14 +143,14 @@ export interface MonthYearFieldComponent extends DateFieldBase {
|
|
145
143
|
export interface DetailsComponent extends ContentFieldBase {
|
146
144
|
type: ComponentType.Details;
|
147
145
|
content: string;
|
148
|
-
options: {
|
146
|
+
options: ContentFieldBase['options'] & {
|
149
147
|
condition?: string;
|
150
148
|
};
|
151
149
|
}
|
152
150
|
export interface HtmlComponent extends ContentFieldBase {
|
153
151
|
type: ComponentType.Html;
|
154
152
|
content: string;
|
155
|
-
options: {
|
153
|
+
options: ContentFieldBase['options'] & {
|
156
154
|
condition?: string;
|
157
155
|
};
|
158
156
|
}
|
@@ -164,7 +162,7 @@ export interface ListComponent extends ContentFieldBase {
|
|
164
162
|
type: ComponentType.List;
|
165
163
|
hint?: string;
|
166
164
|
list: string;
|
167
|
-
options: {
|
165
|
+
options: ContentFieldBase['options'] & {
|
168
166
|
type?: ListTypeOption;
|
169
167
|
classes?: string;
|
170
168
|
hideTitle?: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,qCAAqC,CAAA;AAE5C,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,wBAAwB,CAAC,MAAM,CAAC,EAChC,oBAAoB,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AA0B,GAC1B,oBAAoB,GACpB,2BAA2B,GAC3B,6BAA6B,GAC7B,uBAAuB,GACvB,uBAAuB,GACvB,uBAAuB,GACvB,wBAAwB,CAAA;AAG5B,MAAM,MAAM,oBAAoB,GAC5B,gBAAgB,GAChB,aAAa,GACb,kBAAkB,GAClB,aAAa,CAAA;AAGjB,MAAM,MAAM,iBAAiB,GACzB,OAAO,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,GACpD,aAAa,CAAA;AAGjB,MAAM,MAAM,sBAAsB,GAC9B,0BAA0B,GAC1B,wBAAwB,GACxB,oBAAoB,GACpB,oBAAoB,GACpB,mBAAmB,CAAA;AAGvB,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,YAAY,EACV,kBAAkB,GAClB,aAAa,GACb,uBAAuB,GACvB,uBAAuB,GACvB,wBAAwB,CAC3B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-value-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-value-abstract.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAsB;IACjC,oBAAoB,IAAI,MAAM;IAM9B,
|
1
|
+
{"version":3,"file":"condition-value-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-value-abstract.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAsB;IACjC,oBAAoB,IAAI,MAAM;IAM9B,OAAO,IAAI,MAAM;IAMjB,KAAK;CAKN"}
|
@@ -8,7 +8,7 @@ export declare class ConditionValue extends ConditionValueAbstract {
|
|
8
8
|
display: string;
|
9
9
|
constructor(value: string, display?: string);
|
10
10
|
toPresentationString(): string;
|
11
|
-
|
11
|
+
toValue(): string;
|
12
12
|
clone(): ConditionValue;
|
13
13
|
toJSON(): ConditionValueData;
|
14
14
|
static from(obj: ConditionValue | ConditionValueData): ConditionValue;
|
@@ -20,7 +20,7 @@ export declare class RelativeDateValue extends ConditionValueAbstract {
|
|
20
20
|
direction: any;
|
21
21
|
constructor(period: string, unit: DateUnits, direction: DateDirections);
|
22
22
|
toPresentationString(): string;
|
23
|
-
|
23
|
+
toValue(): string;
|
24
24
|
clone(): RelativeDateValue;
|
25
25
|
toJSON(): RelativeDateValueData;
|
26
26
|
static from(obj: RelativeDateValue | RelativeDateValueData): RelativeDateValue;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-values.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAA;AACrF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAA;AAElC,qBAAa,cAAe,SAAQ,sBAAsB;IACxD,IAAI,EAAE,aAAa,CAAC,KAAK,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;gBAEH,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAgB3C,oBAAoB;IAIpB,
|
1
|
+
{"version":3,"file":"condition-values.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAA;AACrF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAA;AAElC,qBAAa,cAAe,SAAQ,sBAAsB;IACxD,IAAI,EAAE,aAAa,CAAC,KAAK,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;gBAEH,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAgB3C,oBAAoB;IAIpB,OAAO;IAIP,KAAK;IAIL,MAAM,IAAI,kBAAkB;IAI5B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,GAAG,kBAAkB;CAGrD;AAED,qBAAa,iBAAkB,SAAQ,sBAAsB;IAC3D,IAAI,EAAE,aAAa,CAAC,YAAY,CAAA;IAChC,MAAM,MAAA;IACN,IAAI,MAAA;IACJ,SAAS,MAAA;gBAEG,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc;IAmBtE,oBAAoB;IAIpB,OAAO,IAAI,MAAM;IASjB,KAAK;IAIL,MAAM,IAAI,qBAAqB;IAI/B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,qBAAqB;CAG3D;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EACC,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,qBAAqB,sCAa1B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@defra/forms-model",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.386",
|
4
4
|
"description": "A hapi plugin providing the model for Defra forms",
|
5
5
|
"homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
|
6
6
|
"repository": {
|
@@ -21,7 +21,7 @@
|
|
21
21
|
"test:watch": "jest --color --watch"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
-
"marked": "^
|
24
|
+
"marked": "^15.0.1",
|
25
25
|
"slug": "^10.0.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
package/src/components/types.ts
CHANGED
@@ -48,17 +48,18 @@ interface ContentFieldBase {
|
|
48
48
|
| ComponentType.List
|
49
49
|
name: string
|
50
50
|
title: string
|
51
|
+
options?: {
|
52
|
+
required?: undefined
|
53
|
+
optionalText?: undefined
|
54
|
+
}
|
51
55
|
}
|
52
56
|
|
53
|
-
interface DateFieldBase {
|
57
|
+
interface DateFieldBase extends FormFieldBase {
|
54
58
|
type: ComponentType.DatePartsField | ComponentType.MonthYearField
|
55
59
|
name: string
|
56
60
|
title: string
|
57
61
|
hint?: string
|
58
|
-
options: {
|
59
|
-
required?: boolean
|
60
|
-
optionalText?: boolean
|
61
|
-
classes?: string
|
62
|
+
options: FormFieldBase['options'] & {
|
62
63
|
maxDaysInPast?: number
|
63
64
|
maxDaysInFuture?: number
|
64
65
|
}
|
@@ -112,15 +113,12 @@ export interface TelephoneNumberFieldComponent extends FormFieldBase {
|
|
112
113
|
}
|
113
114
|
}
|
114
115
|
|
115
|
-
export interface FileUploadFieldComponent {
|
116
|
+
export interface FileUploadFieldComponent extends FormFieldBase {
|
116
117
|
type: ComponentType.FileUploadField
|
117
118
|
name: string
|
118
119
|
title: string
|
119
120
|
hint?: string
|
120
|
-
options: {
|
121
|
-
required?: boolean
|
122
|
-
classes?: string
|
123
|
-
optionalText?: boolean
|
121
|
+
options: FormFieldBase['options'] & {
|
124
122
|
accept?: string
|
125
123
|
}
|
126
124
|
schema: {
|
@@ -180,7 +178,7 @@ export interface MonthYearFieldComponent extends DateFieldBase {
|
|
180
178
|
export interface DetailsComponent extends ContentFieldBase {
|
181
179
|
type: ComponentType.Details
|
182
180
|
content: string
|
183
|
-
options: {
|
181
|
+
options: ContentFieldBase['options'] & {
|
184
182
|
condition?: string
|
185
183
|
}
|
186
184
|
}
|
@@ -188,7 +186,7 @@ export interface DetailsComponent extends ContentFieldBase {
|
|
188
186
|
export interface HtmlComponent extends ContentFieldBase {
|
189
187
|
type: ComponentType.Html
|
190
188
|
content: string
|
191
|
-
options: {
|
189
|
+
options: ContentFieldBase['options'] & {
|
192
190
|
condition?: string
|
193
191
|
}
|
194
192
|
}
|
@@ -202,7 +200,7 @@ export interface ListComponent extends ContentFieldBase {
|
|
202
200
|
type: ComponentType.List
|
203
201
|
hint?: string
|
204
202
|
list: string
|
205
|
-
options: {
|
203
|
+
options: ContentFieldBase['options'] & {
|
206
204
|
type?: ListTypeOption
|
207
205
|
classes?: string
|
208
206
|
hideTitle?: boolean
|
@@ -160,10 +160,10 @@ function formatValue(
|
|
160
160
|
field.type === ComponentType.NumberField ||
|
161
161
|
field.type === ComponentType.YesNoField
|
162
162
|
) {
|
163
|
-
return value.
|
163
|
+
return value.toValue()
|
164
164
|
}
|
165
165
|
|
166
|
-
return `'${value.
|
166
|
+
return `'${value.toValue().replace(/'/g, "\\'")}'`
|
167
167
|
}
|
168
168
|
|
169
169
|
export const absoluteDateOperatorNames = Object.keys(
|
@@ -31,7 +31,7 @@ export class ConditionValue extends ConditionValueAbstract {
|
|
31
31
|
return this.display
|
32
32
|
}
|
33
33
|
|
34
|
-
|
34
|
+
toValue() {
|
35
35
|
return this.value
|
36
36
|
}
|
37
37
|
|
@@ -77,7 +77,7 @@ export class RelativeDateValue extends ConditionValueAbstract {
|
|
77
77
|
return `${this.period} ${this.unit} ${this.direction}`
|
78
78
|
}
|
79
79
|
|
80
|
-
|
80
|
+
toValue(): string {
|
81
81
|
const period =
|
82
82
|
this.direction === DateDirections.PAST
|
83
83
|
? 0 - Number(this.period)
|