@defra/forms-model 3.0.567 → 3.0.569

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/module/components/component-types.js +24 -0
  2. package/dist/module/components/component-types.js.map +1 -1
  3. package/dist/module/components/enums.js +4 -0
  4. package/dist/module/components/enums.js.map +1 -1
  5. package/dist/module/components/types.js.map +1 -1
  6. package/dist/module/conditions/condition-operators.js +5 -1
  7. package/dist/module/conditions/condition-operators.js.map +1 -1
  8. package/dist/module/form/form-editor/__stubs__/preview.js +128 -1
  9. package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
  10. package/dist/module/form/form-editor/index.js +9 -5
  11. package/dist/module/form/form-editor/index.js.map +1 -1
  12. package/dist/module/form/form-editor/macros/types.js.map +1 -1
  13. package/dist/module/form/form-editor/preview/component-elements.js +1 -0
  14. package/dist/module/form/form-editor/preview/component-elements.js.map +1 -1
  15. package/dist/module/form/form-editor/preview/helpers.js +8 -2
  16. package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
  17. package/dist/module/form/form-editor/preview/number-only.js +75 -3
  18. package/dist/module/form/form-editor/preview/number-only.js.map +1 -1
  19. package/dist/module/form/form-editor/preview/question.js +30 -3
  20. package/dist/module/form/form-editor/preview/question.js.map +1 -1
  21. package/dist/module/form/form-editor/preview/types.js.map +1 -1
  22. package/dist/module/form/form-editor/types.js.map +1 -1
  23. package/dist/types/components/component-types.d.ts.map +1 -1
  24. package/dist/types/components/enums.d.ts +5 -1
  25. package/dist/types/components/enums.d.ts.map +1 -1
  26. package/dist/types/components/types.d.ts +50 -1
  27. package/dist/types/components/types.d.ts.map +1 -1
  28. package/dist/types/conditions/condition-operators.d.ts +16 -0
  29. package/dist/types/conditions/condition-operators.d.ts.map +1 -1
  30. package/dist/types/form/form-editor/__stubs__/preview.d.ts +71 -1
  31. package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
  32. package/dist/types/form/form-editor/index.d.ts +5 -1
  33. package/dist/types/form/form-editor/index.d.ts.map +1 -1
  34. package/dist/types/form/form-editor/macros/types.d.ts +7 -0
  35. package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
  36. package/dist/types/form/form-editor/preview/component-elements.d.ts.map +1 -1
  37. package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
  38. package/dist/types/form/form-editor/preview/number-only.d.ts +123 -0
  39. package/dist/types/form/form-editor/preview/number-only.d.ts.map +1 -1
  40. package/dist/types/form/form-editor/preview/question.d.ts +13 -0
  41. package/dist/types/form/form-editor/preview/question.d.ts.map +1 -1
  42. package/dist/types/form/form-editor/preview/types.d.ts +8 -0
  43. package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
  44. package/dist/types/form/form-editor/preview/uk-address.d.ts +7 -0
  45. package/dist/types/form/form-editor/preview/uk-address.d.ts.map +1 -1
  46. package/dist/types/form/form-editor/types.d.ts +15 -2
  47. package/dist/types/form/form-editor/types.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/schemas/date-sub-schema.json +1 -1
  50. package/schemas/form-editor-input-page-schema.json +1 -0
  51. package/schemas/question-type-full-schema.json +5 -1
  52. package/schemas/question-type-schema.json +1 -0
  53. package/src/components/component-types.ts +28 -0
  54. package/src/components/enums.ts +5 -1
  55. package/src/components/types.ts +58 -0
  56. package/src/conditions/condition-operators.ts +5 -1
  57. package/src/form/form-editor/__stubs__/preview.js +130 -1
  58. package/src/form/form-editor/index.ts +34 -4
  59. package/src/form/form-editor/macros/types.ts +3 -0
  60. package/src/form/form-editor/preview/component-elements.js +4 -0
  61. package/src/form/form-editor/preview/helpers.js +11 -2
  62. package/src/form/form-editor/preview/number-only.js +72 -3
  63. package/src/form/form-editor/preview/question.js +33 -3
  64. package/src/form/form-editor/preview/types.ts +10 -0
  65. package/src/form/form-editor/types.ts +24 -1
@@ -1,5 +1,34 @@
1
1
  import { ComponentType } from '~/src/components/enums.js'
2
- import { Question } from '~/src/form/form-editor/preview/question.js'
2
+ import {
3
+ Question,
4
+ QuestionComponentElements
5
+ } from '~/src/form/form-editor/preview/question.js'
6
+
7
+ /**
8
+ * @implements {QuestionElements}
9
+ */
10
+ export class NumberComponentPreviewElements extends QuestionComponentElements {
11
+ /**
12
+ * @param {NumberFieldComponent} component
13
+ */
14
+ constructor(component) {
15
+ super(component)
16
+ this._prefix = component.options.prefix
17
+ this._suffix = component.options.suffix
18
+ }
19
+
20
+ /**
21
+ * @protected
22
+ * @returns {NumberSettings}
23
+ */
24
+ _getValues() {
25
+ return {
26
+ ...super._getValues(),
27
+ prefix: this._prefix ?? '',
28
+ suffix: this._suffix ?? ''
29
+ }
30
+ }
31
+ }
3
32
 
4
33
  export class NumberOnlyQuestion extends Question {
5
34
  /**
@@ -8,12 +37,14 @@ export class NumberOnlyQuestion extends Question {
8
37
  componentType = ComponentType.NumberField
9
38
 
10
39
  /**
11
- * @param {QuestionElements} htmlElements
40
+ * @param {NumberElements} htmlElements
12
41
  * @param {QuestionRenderer} questionRenderer
13
42
  */
14
43
  constructor(htmlElements, questionRenderer) {
15
44
  super(htmlElements, questionRenderer)
16
45
  this._fieldName = 'numberField'
46
+ this._prefix = htmlElements.values.prefix
47
+ this._suffix = htmlElements.values.suffix
17
48
  }
18
49
 
19
50
  /**
@@ -24,8 +55,46 @@ export class NumberOnlyQuestion extends Question {
24
55
  type: 'number'
25
56
  }
26
57
  }
58
+
59
+ get prefix() {
60
+ return this._prefix
61
+ }
62
+
63
+ /**
64
+ * @param {string} val
65
+ */
66
+ set prefix(val) {
67
+ this._prefix = val
68
+ this.render()
69
+ }
70
+
71
+ get suffix() {
72
+ return this._suffix
73
+ }
74
+
75
+ /**
76
+ * @param {string} val
77
+ */
78
+ set suffix(val) {
79
+ this._suffix = val
80
+ this.render()
81
+ }
82
+
83
+ /**
84
+ * @protected
85
+ */
86
+ _renderInput() {
87
+ const prefixObj = this.prefix ? { prefix: { text: this.prefix } } : {}
88
+ const suffixObj = this.suffix ? { suffix: { text: this.suffix } } : {}
89
+ return {
90
+ ...super._renderInput(),
91
+ ...prefixObj,
92
+ ...suffixObj
93
+ }
94
+ }
27
95
  }
28
96
 
29
97
  /**
30
- * @import { QuestionElements, QuestionBaseModel, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
98
+ * @import { NumberSettings, NumberElements, QuestionBaseModel, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
99
+ * @import { NumberFieldComponent } from '~/src/components/types.js'
31
100
  */
@@ -27,7 +27,8 @@ export class QuestionComponentElements extends ComponentElements {
27
27
  return {
28
28
  ...super._getValues(),
29
29
  hintText: this._component.hint ?? '',
30
- shortDesc: this._component.shortDescription ?? ''
30
+ shortDesc: this._component.shortDescription ?? '',
31
+ userClasses: this._component.options.classes ?? ''
31
32
  }
32
33
  }
33
34
  }
@@ -65,12 +66,17 @@ export class Question extends PreviewComponent {
65
66
  */
66
67
  constructor(htmlElements, questionRenderer) {
67
68
  super(htmlElements, questionRenderer)
68
- const { hintText } = htmlElements.values
69
+ const { hintText, userClasses } = htmlElements.values
69
70
  /**
70
71
  * @type {string}
71
72
  * @private
72
73
  */
73
74
  this._hintText = hintText
75
+ /**
76
+ * @type {string}
77
+ * @private
78
+ */
79
+ this._userClasses = userClasses
74
80
  }
75
81
 
76
82
  /**
@@ -94,7 +100,16 @@ export class Question extends PreviewComponent {
94
100
  * @protected
95
101
  */
96
102
  _renderInput() {
97
- return { ...super._renderInput(), label: this.label, hint: this.hint }
103
+ const renderValues = {
104
+ ...super._renderInput(),
105
+ label: this.label,
106
+ hint: this.hint
107
+ }
108
+ return {
109
+ ...renderValues,
110
+ classes: this._userClasses,
111
+ previewClasses: renderValues.classes ?? ''
112
+ }
98
113
  }
99
114
 
100
115
  /**
@@ -111,6 +126,21 @@ export class Question extends PreviewComponent {
111
126
  this._hintText = value
112
127
  this.render()
113
128
  }
129
+
130
+ /**
131
+ * @type {string}
132
+ */
133
+ get userClasses() {
134
+ return this._userClasses
135
+ }
136
+
137
+ /**
138
+ * @param {string} value
139
+ */
140
+ set userClasses(value) {
141
+ this._userClasses = value
142
+ this.render()
143
+ }
114
144
  }
115
145
 
116
146
  /**
@@ -20,6 +20,7 @@ export interface BaseSettings {
20
20
  hintText: string
21
21
  optional: boolean
22
22
  shortDesc: string
23
+ userClasses: string
23
24
  items: ListElement[]
24
25
  content: string
25
26
  attributes?: Record<string, string>
@@ -58,6 +59,15 @@ export interface AutocompleteElements extends QuestionElements {
58
59
  autocompleteOptions: string
59
60
  }
60
61
 
62
+ export interface NumberSettings extends BaseSettings {
63
+ prefix: string
64
+ suffix: string
65
+ }
66
+
67
+ export interface NumberElements extends DomElementsBase {
68
+ readonly values: NumberSettings
69
+ }
70
+
61
71
  export interface RenderBase {
62
72
  render(questionTemplate: string, renderContext: RenderContext): void
63
73
  }
@@ -30,6 +30,11 @@ export interface FormEditor {
30
30
  */
31
31
  dateSub: string
32
32
 
33
+ /**
34
+ * The sub-type of location
35
+ */
36
+ locationSub: string
37
+
33
38
  /**
34
39
  * The sub-type of lists
35
40
  */
@@ -60,6 +65,16 @@ export interface FormEditor {
60
65
  */
61
66
  shortDescription: string
62
67
 
68
+ /**
69
+ * The value of checkbox to reveal instruction text field
70
+ */
71
+ giveInstructions: string
72
+
73
+ /**
74
+ * The instruction text for location components (optional)
75
+ */
76
+ instructionText: string
77
+
63
78
  /**
64
79
  * The value of checkbox to reveal heading and guidance section
65
80
  */
@@ -283,7 +298,12 @@ export interface FormEditor {
283
298
 
284
299
  export type FormEditorInputPage = Pick<
285
300
  FormEditor,
286
- 'pageType' | 'questionType' | 'writtenAnswerSub' | 'dateSub' | 'listSub'
301
+ | 'pageType'
302
+ | 'questionType'
303
+ | 'writtenAnswerSub'
304
+ | 'dateSub'
305
+ | 'locationSub'
306
+ | 'listSub'
287
307
  >
288
308
 
289
309
  export type FormEditorInputCheckAnswersSettings = Pick<
@@ -328,6 +348,8 @@ export type FormEditorInputQuestion = Pick<
328
348
  | 'listItemsData'
329
349
  | 'jsEnabled'
330
350
  | 'usePostcodeLookup'
351
+ | 'giveInstructions'
352
+ | 'instructionText'
331
353
  >
332
354
 
333
355
  export type FormEditorInputPageSettings = Pick<
@@ -522,6 +544,7 @@ export type GovukStringField = Omit<GovukField, 'value'> & { value: string }
522
544
  export interface FormEditorGovukField {
523
545
  question?: GovukField
524
546
  hintText?: GovukField
547
+ instructionText?: GovukField
525
548
  questionOptional?: GovukField
526
549
  shortDescription?: GovukField
527
550
  fileTypes?: GovukField