@defra/forms-model 3.0.570 → 3.0.572
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/form/form-definition/index.js +20 -1
 - package/dist/module/form/form-definition/index.js.map +1 -1
 - package/dist/module/form/form-editor/macros/types.js.map +1 -1
 - package/dist/module/form/form-editor/preview/controller/page-controller.js +0 -21
 - package/dist/module/form/form-editor/preview/controller/page-controller.js.map +1 -1
 - package/dist/module/form/form-manager/types.js +5 -0
 - package/dist/module/form/form-manager/types.js.map +1 -1
 - package/dist/types/form/form-definition/index.d.ts +2 -1
 - package/dist/types/form/form-definition/index.d.ts.map +1 -1
 - package/dist/types/form/form-editor/macros/types.d.ts +0 -4
 - package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
 - package/dist/types/form/form-editor/preview/controller/page-controller.d.ts +0 -5
 - package/dist/types/form/form-editor/preview/controller/page-controller.d.ts.map +1 -1
 - package/dist/types/form/form-manager/types.d.ts +1 -0
 - package/dist/types/form/form-manager/types.d.ts.map +1 -1
 - package/package.json +1 -1
 - package/schemas/component-schema-v2.json +27 -0
 - package/schemas/component-schema.json +27 -0
 - package/schemas/form-definition-schema.json +81 -0
 - package/schemas/form-definition-v2-schema.json +135 -0
 - package/schemas/list-schema-v2.json +54 -0
 - package/schemas/list-schema.json +54 -0
 - package/schemas/page-schema-v2.json +81 -0
 - package/schemas/page-schema.json +27 -0
 - package/src/form/form-definition/index.ts +28 -1
 - package/src/form/form-editor/macros/types.ts +0 -4
 - package/src/form/form-editor/preview/controller/page-controller.js +0 -27
 - package/src/form/form-manager/types.ts +5 -0
 
    
        package/schemas/page-schema.json
    CHANGED
    
    | 
         @@ -181,6 +181,33 @@ 
     | 
|
| 
       181 
181 
     | 
    
         
             
                            "type": "number",
         
     | 
| 
       182 
182 
     | 
    
         
             
                            "description": "Exact length required for validation",
         
     | 
| 
       183 
183 
     | 
    
         
             
                            "title": "Length"
         
     | 
| 
      
 184 
     | 
    
         
            +
                          },
         
     | 
| 
      
 185 
     | 
    
         
            +
                          "regex": {
         
     | 
| 
      
 186 
     | 
    
         
            +
                            "type": [
         
     | 
| 
      
 187 
     | 
    
         
            +
                              "array",
         
     | 
| 
      
 188 
     | 
    
         
            +
                              "boolean",
         
     | 
| 
      
 189 
     | 
    
         
            +
                              "number",
         
     | 
| 
      
 190 
     | 
    
         
            +
                              "object",
         
     | 
| 
      
 191 
     | 
    
         
            +
                              "string",
         
     | 
| 
      
 192 
     | 
    
         
            +
                              "null"
         
     | 
| 
      
 193 
     | 
    
         
            +
                            ],
         
     | 
| 
      
 194 
     | 
    
         
            +
                            "oneOf": [
         
     | 
| 
      
 195 
     | 
    
         
            +
                              {
         
     | 
| 
      
 196 
     | 
    
         
            +
                                "type": "string",
         
     | 
| 
      
 197 
     | 
    
         
            +
                                "description": "Regex expression for validation of user field content",
         
     | 
| 
      
 198 
     | 
    
         
            +
                                "title": "Regex (string)"
         
     | 
| 
      
 199 
     | 
    
         
            +
                              },
         
     | 
| 
      
 200 
     | 
    
         
            +
                              {
         
     | 
| 
      
 201 
     | 
    
         
            +
                                "type": "string",
         
     | 
| 
      
 202 
     | 
    
         
            +
                                "title": "Regex (string)"
         
     | 
| 
      
 203 
     | 
    
         
            +
                              }
         
     | 
| 
      
 204 
     | 
    
         
            +
                            ],
         
     | 
| 
      
 205 
     | 
    
         
            +
                            "title": "Regex",
         
     | 
| 
      
 206 
     | 
    
         
            +
                            "description": "The regex value.",
         
     | 
| 
      
 207 
     | 
    
         
            +
                            "oneOfTitles": [
         
     | 
| 
      
 208 
     | 
    
         
            +
                              "Regex (string)",
         
     | 
| 
      
 209 
     | 
    
         
            +
                              "Regex (string)"
         
     | 
| 
      
 210 
     | 
    
         
            +
                            ]
         
     | 
| 
       184 
211 
     | 
    
         
             
                          }
         
     | 
| 
       185 
212 
     | 
    
         
             
                        },
         
     | 
| 
       186 
213 
     | 
    
         
             
                        "additionalProperties": true,
         
     | 
| 
         @@ -444,6 +444,21 @@ export const conditionWrapperSchemaV2 = Joi.object<ConditionWrapperV2>() 
     | 
|
| 
       444 
444 
     | 
    
         
             
              })
         
     | 
| 
       445 
445 
     | 
    
         
             
              .description('Condition schema for V2 forms')
         
     | 
| 
       446 
446 
     | 
    
         | 
| 
      
 447 
     | 
    
         
            +
            export const regexCustomValidator = (
         
     | 
| 
      
 448 
     | 
    
         
            +
              value: string,
         
     | 
| 
      
 449 
     | 
    
         
            +
              helpers: CustomHelpers<string>
         
     | 
| 
      
 450 
     | 
    
         
            +
            ) => {
         
     | 
| 
      
 451 
     | 
    
         
            +
              try {
         
     | 
| 
      
 452 
     | 
    
         
            +
                const _regex = new RegExp(value)
         
     | 
| 
      
 453 
     | 
    
         
            +
              } catch {
         
     | 
| 
      
 454 
     | 
    
         
            +
                return helpers.error('custom.incompatible', {
         
     | 
| 
      
 455 
     | 
    
         
            +
                  errorType: FormDefinitionErrorType.Incompatible,
         
     | 
| 
      
 456 
     | 
    
         
            +
                  errorCode: FormDefinitionError.IncompatibleQuestionRegex
         
     | 
| 
      
 457 
     | 
    
         
            +
                })
         
     | 
| 
      
 458 
     | 
    
         
            +
              }
         
     | 
| 
      
 459 
     | 
    
         
            +
              return value
         
     | 
| 
      
 460 
     | 
    
         
            +
            }
         
     | 
| 
      
 461 
     | 
    
         
            +
             
     | 
| 
       447 
462 
     | 
    
         
             
            export const componentSchema = Joi.object<ComponentDef>()
         
     | 
| 
       448 
463 
     | 
    
         
             
              .description('Form component definition specifying UI element behavior')
         
     | 
| 
       449 
464 
     | 
    
         
             
              .keys({
         
     | 
| 
         @@ -531,7 +546,19 @@ export const componentSchema = Joi.object<ComponentDef>() 
     | 
|
| 
       531 
546 
     | 
    
         
             
                    .description('Maximum value or length for validation'),
         
     | 
| 
       532 
547 
     | 
    
         
             
                  length: Joi.number()
         
     | 
| 
       533 
548 
     | 
    
         
             
                    .empty('')
         
     | 
| 
       534 
     | 
    
         
            -
                    .description('Exact length required for validation')
         
     | 
| 
      
 549 
     | 
    
         
            +
                    .description('Exact length required for validation'),
         
     | 
| 
      
 550 
     | 
    
         
            +
                  regex: Joi.when('type', {
         
     | 
| 
      
 551 
     | 
    
         
            +
                    is: Joi.string().valid(
         
     | 
| 
      
 552 
     | 
    
         
            +
                      ComponentType.TextField,
         
     | 
| 
      
 553 
     | 
    
         
            +
                      ComponentType.MultilineTextField
         
     | 
| 
      
 554 
     | 
    
         
            +
                    ),
         
     | 
| 
      
 555 
     | 
    
         
            +
                    then: Joi.string() // NOSONAR
         
     | 
| 
      
 556 
     | 
    
         
            +
                      .trim()
         
     | 
| 
      
 557 
     | 
    
         
            +
                      .optional()
         
     | 
| 
      
 558 
     | 
    
         
            +
                      .description('Regex expression for validation of user field content')
         
     | 
| 
      
 559 
     | 
    
         
            +
                      .custom(regexCustomValidator),
         
     | 
| 
      
 560 
     | 
    
         
            +
                    otherwise: Joi.string().allow('')
         
     | 
| 
      
 561 
     | 
    
         
            +
                  }).messages({ 'custom.incompatible': 'The regex expression is invalid' })
         
     | 
| 
       535 
562 
     | 
    
         
             
                })
         
     | 
| 
       536 
563 
     | 
    
         
             
                  .unknown(true)
         
     | 
| 
       537 
564 
     | 
    
         
             
                  .default({})
         
     | 
| 
         @@ -190,33 +190,6 @@ export class PreviewPageController extends PreviewPageControllerBase { 
     | 
|
| 
       190 
190 
     | 
    
         
             
                return undefined
         
     | 
| 
       191 
191 
     | 
    
         
             
              }
         
     | 
| 
       192 
192 
     | 
    
         | 
| 
       193 
     | 
    
         
            -
              get repeaterButton() {
         
     | 
| 
       194 
     | 
    
         
            -
                if (this.repeaterButtonText === undefined) {
         
     | 
| 
       195 
     | 
    
         
            -
                  return undefined
         
     | 
| 
       196 
     | 
    
         
            -
                }
         
     | 
| 
       197 
     | 
    
         
            -
                return {
         
     | 
| 
       198 
     | 
    
         
            -
                  classes: this._isHighlighted(
         
     | 
| 
       199 
     | 
    
         
            -
                    PreviewPageControllerBase.HighlightClass.REPEATER
         
     | 
| 
       200 
     | 
    
         
            -
                  ),
         
     | 
| 
       201 
     | 
    
         
            -
                  text: this.repeaterButtonText
         
     | 
| 
       202 
     | 
    
         
            -
                }
         
     | 
| 
       203 
     | 
    
         
            -
              }
         
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
              get repeaterButtonText() {
         
     | 
| 
       206 
     | 
    
         
            -
                if (!this._isRepeater) {
         
     | 
| 
       207 
     | 
    
         
            -
                  return undefined
         
     | 
| 
       208 
     | 
    
         
            -
                }
         
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
                if (this._sectionTitle === '') {
         
     | 
| 
       211 
     | 
    
         
            -
                  return '[question set name]'
         
     | 
| 
       212 
     | 
    
         
            -
                }
         
     | 
| 
       213 
     | 
    
         
            -
             
     | 
| 
       214 
     | 
    
         
            -
                const [firstToken, ...rest] = this._sectionTitle
         
     | 
| 
       215 
     | 
    
         
            -
                // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
         
     | 
| 
       216 
     | 
    
         
            -
                const restOfStr = rest ? rest.join('') : ''
         
     | 
| 
       217 
     | 
    
         
            -
                return firstToken.toLowerCase() + restOfStr
         
     | 
| 
       218 
     | 
    
         
            -
              }
         
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
193 
     | 
    
         
             
              /**
         
     | 
| 
       221 
194 
     | 
    
         
             
               * Helper method to return the guidance or a new one
         
     | 
| 
       222 
195 
     | 
    
         
             
               * @param { Markdown | Question | undefined } guidanceComponent
         
     | 
| 
         @@ -46,6 +46,7 @@ export enum FormDefinitionError { 
     | 
|
| 
       46 
46 
     | 
    
         
             
              RefConditionConditionId = 'ref_condition_condition_id',
         
     | 
| 
       47 
47 
     | 
    
         
             
              RefPageComponentList = 'ref_page_component_list',
         
     | 
| 
       48 
48 
     | 
    
         
             
              IncompatibleConditionComponentType = 'incompatible_condition_component_type',
         
     | 
| 
      
 49 
     | 
    
         
            +
              IncompatibleQuestionRegex = 'incompatible_question_regex',
         
     | 
| 
       49 
50 
     | 
    
         
             
              Other = 'other'
         
     | 
| 
       50 
51 
     | 
    
         
             
            }
         
     | 
| 
       51 
52 
     | 
    
         | 
| 
         @@ -142,6 +143,10 @@ export const formDefinitionErrors: FormDefinitionErrors = { 
     | 
|
| 
       142 
143 
     | 
    
         
             
                key: 'componentId',
         
     | 
| 
       143 
144 
     | 
    
         
             
                type: FormDefinitionErrorType.Incompatible
         
     | 
| 
       144 
145 
     | 
    
         
             
              },
         
     | 
| 
      
 146 
     | 
    
         
            +
              [FormDefinitionError.IncompatibleQuestionRegex]: {
         
     | 
| 
      
 147 
     | 
    
         
            +
                key: 'regex',
         
     | 
| 
      
 148 
     | 
    
         
            +
                type: FormDefinitionErrorType.Incompatible
         
     | 
| 
      
 149 
     | 
    
         
            +
              },
         
     | 
| 
       145 
150 
     | 
    
         
             
              [FormDefinitionError.Other]: {
         
     | 
| 
       146 
151 
     | 
    
         
             
                key: '',
         
     | 
| 
       147 
152 
     | 
    
         
             
                type: FormDefinitionErrorType.Type
         
     |