@defra/forms-model 3.0.481 → 3.0.483
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/conditions/condition-operators.js +4 -1
- package/dist/module/conditions/condition-operators.js.map +1 -1
- package/dist/module/form/form-definition/index.js +0 -1
- package/dist/module/form/form-definition/index.js.map +1 -1
- package/dist/module/form/form-editor/__stubs__/preview.js +83 -4
- package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
- package/dist/module/form/form-editor/index.js +2 -2
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/macros/types.js +2 -0
- package/dist/module/form/form-editor/macros/types.js.map +1 -0
- package/dist/module/form/form-editor/preview/autocomplete.js +20 -4
- package/dist/module/form/form-editor/preview/autocomplete.js.map +1 -1
- package/dist/module/form/form-editor/preview/checkbox-sortable.js +7 -2
- package/dist/module/form/form-editor/preview/checkbox-sortable.js.map +1 -1
- package/dist/module/form/form-editor/preview/checkbox.js +17 -0
- package/dist/module/form/form-editor/preview/checkbox.js.map +1 -0
- package/dist/module/form/form-editor/preview/component-elements.js +61 -0
- package/dist/module/form/form-editor/preview/component-elements.js.map +1 -0
- package/dist/module/form/form-editor/preview/constants.js +2 -0
- package/dist/module/form/form-editor/preview/constants.js.map +1 -0
- package/dist/module/form/form-editor/preview/content.js +94 -0
- package/dist/module/form/form-editor/preview/content.js.map +1 -0
- package/dist/module/form/form-editor/preview/controller/page-controller.js +260 -0
- package/dist/module/form/form-editor/preview/controller/page-controller.js.map +1 -0
- package/dist/module/form/form-editor/preview/date-input.js +7 -2
- package/dist/module/form/form-editor/preview/date-input.js.map +1 -1
- package/dist/module/form/form-editor/preview/email-address.js +7 -1
- package/dist/module/form/form-editor/preview/email-address.js.map +1 -1
- package/dist/module/form/form-editor/preview/fieldset-question.js +5 -0
- package/dist/module/form/form-editor/preview/fieldset-question.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +81 -0
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -0
- package/dist/module/form/form-editor/preview/index.js +6 -0
- package/dist/module/form/form-editor/preview/index.js.map +1 -1
- package/dist/module/form/form-editor/preview/list.js +59 -3
- package/dist/module/form/form-editor/preview/list.js.map +1 -1
- package/dist/module/form/form-editor/preview/long-answer.js +7 -1
- package/dist/module/form/form-editor/preview/long-answer.js.map +1 -1
- package/dist/module/form/form-editor/preview/markdown.js +53 -0
- package/dist/module/form/form-editor/preview/markdown.js.map +1 -0
- package/dist/module/form/form-editor/preview/month-year.js +7 -2
- package/dist/module/form/form-editor/preview/month-year.js.map +1 -1
- package/dist/module/form/form-editor/preview/number-only.js +5 -0
- package/dist/module/form/form-editor/preview/number-only.js.map +1 -1
- package/dist/module/form/form-editor/preview/phone-number.js +7 -1
- package/dist/module/form/form-editor/preview/phone-number.js.map +1 -1
- package/dist/module/form/form-editor/preview/preview.js +212 -0
- package/dist/module/form/form-editor/preview/preview.js.map +1 -0
- package/dist/module/form/form-editor/preview/question.js +48 -138
- package/dist/module/form/form-editor/preview/question.js.map +1 -1
- package/dist/module/form/form-editor/preview/radio-sortable.js +7 -2
- package/dist/module/form/form-editor/preview/radio-sortable.js.map +1 -1
- package/dist/module/form/form-editor/preview/radio.js +7 -2
- package/dist/module/form/form-editor/preview/radio.js.map +1 -1
- package/dist/module/form/form-editor/preview/select-sortable.js +38 -0
- package/dist/module/form/form-editor/preview/select-sortable.js.map +1 -0
- package/dist/module/form/form-editor/preview/select.js +11 -0
- package/dist/module/form/form-editor/preview/select.js.map +1 -0
- package/dist/module/form/form-editor/preview/short-answer.js +7 -1
- package/dist/module/form/form-editor/preview/short-answer.js.map +1 -1
- package/dist/module/form/form-editor/preview/supporting-evidence.js +7 -1
- package/dist/module/form/form-editor/preview/supporting-evidence.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/uk-address.js +7 -2
- package/dist/module/form/form-editor/preview/uk-address.js.map +1 -1
- package/dist/module/form/form-editor/preview/yes-no.js +7 -2
- package/dist/module/form/form-editor/preview/yes-no.js.map +1 -1
- package/dist/module/form/form-editor/types.js.map +1 -1
- package/dist/module/form/form-metadata/index.js +1 -5
- package/dist/module/form/form-metadata/index.js.map +1 -1
- package/dist/module/form/utils/index.js +1 -0
- package/dist/module/form/utils/index.js.map +1 -1
- package/dist/module/form/utils/list.js +15 -0
- package/dist/module/form/utils/list.js.map +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/stubs.js +1 -0
- package/dist/module/stubs.js.map +1 -1
- package/dist/types/conditions/condition-operators.d.ts +0 -4
- package/dist/types/conditions/condition-operators.d.ts.map +1 -1
- package/dist/types/form/form-definition/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts +58 -11
- package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/macros/types.d.ts +62 -0
- package/dist/types/form/form-editor/macros/types.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/autocomplete.d.ts +3 -1
- package/dist/types/form/form-editor/preview/autocomplete.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/checkbox-sortable.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/checkbox.d.ts +4 -0
- package/dist/types/form/form-editor/preview/checkbox.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/component-elements.d.ts +35 -0
- package/dist/types/form/form-editor/preview/component-elements.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/constants.d.ts +2 -0
- package/dist/types/form/form-editor/preview/constants.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/content.d.ts +43 -0
- package/dist/types/form/form-editor/preview/content.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/controller/page-controller.d.ts +132 -0
- package/dist/types/form/form-editor/preview/controller/page-controller.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/date-input.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/email-address.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/fieldset-question.d.ts +2 -0
- package/dist/types/form/form-editor/preview/fieldset-question.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/helpers.d.ts +11 -0
- package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/index.d.ts +6 -0
- package/dist/types/form/form-editor/preview/list-sortable.d.ts +1 -1
- package/dist/types/form/form-editor/preview/list.d.ts +25 -0
- package/dist/types/form/form-editor/preview/list.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/long-answer.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/markdown.d.ts +9 -0
- package/dist/types/form/form-editor/preview/markdown.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/month-year.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/number-only.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/phone-number.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/preview.d.ts +126 -0
- package/dist/types/form/form-editor/preview/preview.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/question.d.ts +19 -93
- package/dist/types/form/form-editor/preview/question.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/radio-sortable.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/radio.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/select-sortable.d.ts +18 -0
- package/dist/types/form/form-editor/preview/select-sortable.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/select.d.ts +4 -0
- package/dist/types/form/form-editor/preview/select.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/short-answer.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/supporting-evidence.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/types.d.ts +13 -17
- package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/uk-address.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/yes-no.d.ts.map +1 -1
- package/dist/types/form/form-editor/types.d.ts +6 -4
- package/dist/types/form/form-editor/types.d.ts.map +1 -1
- package/dist/types/form/form-metadata/index.d.ts.map +1 -1
- package/dist/types/form/utils/index.d.ts +1 -0
- package/dist/types/form/utils/index.d.ts.map +1 -1
- package/dist/types/form/utils/list.d.ts +10 -0
- package/dist/types/form/utils/list.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/stubs.d.ts +1 -0
- package/dist/types/stubs.d.ts.map +1 -1
- package/package.json +1 -1
- package/schemas/form-definition-schema.json +0 -12
- package/schemas/form-metadata-input-schema.json +1 -2
- package/schemas/form-metadata-schema.json +1 -2
- package/schemas/question-type-full-schema.json +2 -1
- package/src/conditions/condition-operators.ts +4 -1
- package/src/form/form-definition/index.ts +0 -5
- package/src/form/form-editor/__stubs__/preview.js +84 -4
- package/src/form/form-editor/index.ts +4 -2
- package/src/form/form-editor/macros/types.ts +65 -0
- package/src/form/form-editor/preview/autocomplete.js +21 -4
- package/src/form/form-editor/preview/checkbox-sortable.js +7 -2
- package/src/form/form-editor/preview/checkbox.js +17 -0
- package/src/form/form-editor/preview/component-elements.js +61 -0
- package/src/form/form-editor/preview/constants.js +1 -0
- package/src/form/form-editor/preview/content.js +93 -0
- package/src/form/form-editor/preview/controller/page-controller.js +284 -0
- package/src/form/form-editor/preview/date-input.js +8 -2
- package/src/form/form-editor/preview/email-address.js +7 -1
- package/src/form/form-editor/preview/fieldset-question.js +6 -0
- package/src/form/form-editor/preview/helpers.js +95 -0
- package/src/form/form-editor/preview/index.js +6 -0
- package/src/form/form-editor/preview/list.js +62 -3
- package/src/form/form-editor/preview/long-answer.js +7 -1
- package/src/form/form-editor/preview/markdown.js +50 -0
- package/src/form/form-editor/preview/month-year.js +7 -2
- package/src/form/form-editor/preview/number-only.js +5 -0
- package/src/form/form-editor/preview/phone-number.js +7 -1
- package/src/form/form-editor/preview/preview.js +211 -0
- package/src/form/form-editor/preview/question.js +47 -142
- package/src/form/form-editor/preview/radio-sortable.js +7 -2
- package/src/form/form-editor/preview/radio.js +7 -2
- package/src/form/form-editor/preview/select-sortable.js +43 -0
- package/src/form/form-editor/preview/select.js +11 -0
- package/src/form/form-editor/preview/short-answer.js +7 -1
- package/src/form/form-editor/preview/supporting-evidence.js +7 -1
- package/src/form/form-editor/preview/types.ts +18 -18
- package/src/form/form-editor/preview/uk-address.js +7 -2
- package/src/form/form-editor/preview/yes-no.js +7 -2
- package/src/form/form-editor/types.ts +6 -4
- package/src/form/form-metadata/index.ts +2 -5
- package/src/form/utils/index.ts +1 -0
- package/src/form/utils/list.ts +25 -0
- package/src/index.ts +1 -0
- package/src/stubs.ts +1 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @abstract
|
6
|
+
*/
|
7
|
+
export class PreviewComponent {
|
8
|
+
static PATH = 'preview-components/'
|
9
|
+
/**
|
10
|
+
* @abstract
|
11
|
+
* @type {ComponentType}
|
12
|
+
*/
|
13
|
+
componentType = ComponentType.Details
|
14
|
+
/**
|
15
|
+
* @abstract
|
16
|
+
* @type {string}
|
17
|
+
* @protected
|
18
|
+
*/
|
19
|
+
_questionTemplate = ''
|
20
|
+
/**
|
21
|
+
* @type { string|null }
|
22
|
+
* @protected
|
23
|
+
*/
|
24
|
+
_highlight = null
|
25
|
+
/**
|
26
|
+
* @abstract
|
27
|
+
* @type {string}
|
28
|
+
* @protected
|
29
|
+
*/
|
30
|
+
_fieldName = ''
|
31
|
+
/**
|
32
|
+
* @type {QuestionRenderer}
|
33
|
+
* @protected
|
34
|
+
*/
|
35
|
+
_questionRenderer
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @type {QuestionElements}
|
39
|
+
* @protected
|
40
|
+
*/
|
41
|
+
_htmlElements
|
42
|
+
/**
|
43
|
+
* @type {boolean}
|
44
|
+
* @protected
|
45
|
+
*/
|
46
|
+
_highlighted = false
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @param {QuestionElements} htmlElements
|
50
|
+
* @param {QuestionRenderer} questionRenderer
|
51
|
+
*/
|
52
|
+
constructor(htmlElements, questionRenderer) {
|
53
|
+
const { question, optional } = htmlElements.values
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @type {QuestionElements}
|
57
|
+
* @protected
|
58
|
+
*/
|
59
|
+
this._htmlElements = htmlElements
|
60
|
+
/**
|
61
|
+
* @type {string}
|
62
|
+
* @private
|
63
|
+
*/
|
64
|
+
this._question = question
|
65
|
+
/**
|
66
|
+
* @type {boolean}
|
67
|
+
* @private
|
68
|
+
*/
|
69
|
+
this._optional = optional
|
70
|
+
/**
|
71
|
+
*
|
72
|
+
* @type {QuestionRenderer}
|
73
|
+
* @protected
|
74
|
+
*/
|
75
|
+
this._questionRenderer = questionRenderer
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @param {string} element
|
80
|
+
* @returns {string}
|
81
|
+
* @protected
|
82
|
+
*/
|
83
|
+
getHighlight(element) {
|
84
|
+
return this._highlight === element ? ' highlight' : ''
|
85
|
+
}
|
86
|
+
|
87
|
+
get titleText() {
|
88
|
+
const optionalText = this._optional ? ' (optional)' : ''
|
89
|
+
return (!this._question ? 'Question' : this._question) + optionalText
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* @protected
|
94
|
+
* @type {DefaultComponent}
|
95
|
+
*/
|
96
|
+
get label() {
|
97
|
+
return {
|
98
|
+
text: this.titleText,
|
99
|
+
classes: 'govuk-label--l' + this.getHighlight('question')
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* @protected
|
105
|
+
* @type {GovukFieldset}
|
106
|
+
*/
|
107
|
+
get fieldSet() {
|
108
|
+
return {
|
109
|
+
legend: {
|
110
|
+
text: this.titleText,
|
111
|
+
classes: 'govuk-fieldset__legend--l' + this.getHighlight('question')
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* @returns {Partial<QuestionBaseModel>}
|
118
|
+
*/
|
119
|
+
get customRenderFields() {
|
120
|
+
return {}
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
*
|
125
|
+
* @returns {QuestionBaseModel}
|
126
|
+
* @protected
|
127
|
+
*/
|
128
|
+
_renderInput() {
|
129
|
+
return {
|
130
|
+
id: this._fieldName,
|
131
|
+
name: this._fieldName,
|
132
|
+
classes: this._highlighted ? HIGHLIGHT_CLASS : ''
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* @type {QuestionBaseModel}
|
138
|
+
*/
|
139
|
+
get renderInput() {
|
140
|
+
return {
|
141
|
+
...this._renderInput(),
|
142
|
+
...this.customRenderFields
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
render() {
|
147
|
+
this._questionRenderer.render(this._questionTemplate, this.renderInput)
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* @type {string}
|
152
|
+
*/
|
153
|
+
get question() {
|
154
|
+
return this._question
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @param {string} value
|
159
|
+
*/
|
160
|
+
set question(value) {
|
161
|
+
this._question = value
|
162
|
+
this.render()
|
163
|
+
}
|
164
|
+
|
165
|
+
get optional() {
|
166
|
+
return this._optional
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* @param {boolean} value
|
171
|
+
*/
|
172
|
+
set optional(value) {
|
173
|
+
this._optional = value
|
174
|
+
this.render()
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* @type {string | null}
|
179
|
+
*/
|
180
|
+
get highlight() {
|
181
|
+
return this._highlight
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @param {string | null} value
|
186
|
+
*/
|
187
|
+
set highlight(value) {
|
188
|
+
this._highlight = value
|
189
|
+
this.render()
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* no render
|
194
|
+
*/
|
195
|
+
highlightContent() {
|
196
|
+
this._highlighted = true
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* no render
|
201
|
+
*/
|
202
|
+
unHighlightContent() {
|
203
|
+
this._highlighted = false
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
209
|
+
* @import { FormComponentsDef, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'
|
210
|
+
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
211
|
+
*/
|
@@ -1,3 +1,37 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @implements {QuestionElements}
|
7
|
+
*/
|
8
|
+
export class QuestionComponentElements extends ComponentElements {
|
9
|
+
/**
|
10
|
+
* @type {FormComponentsDef}
|
11
|
+
* @protected
|
12
|
+
*/
|
13
|
+
_component
|
14
|
+
/**
|
15
|
+
* @param {FormComponentsDef} component
|
16
|
+
*/
|
17
|
+
constructor(component) {
|
18
|
+
super(component)
|
19
|
+
this._component = component
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @protected
|
24
|
+
* @returns {BaseSettings}
|
25
|
+
*/
|
26
|
+
_getValues() {
|
27
|
+
return {
|
28
|
+
...super._getValues(),
|
29
|
+
hintText: this._component.hint ?? '',
|
30
|
+
shortDesc: this._component.shortDescription ?? ''
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
1
35
|
/**
|
2
36
|
* @class Question
|
3
37
|
* @classdesc
|
@@ -8,107 +42,35 @@
|
|
8
42
|
* the HTML. Question classes should only be responsible for data and rendering as are reused in the
|
9
43
|
* server side.
|
10
44
|
*/
|
11
|
-
export class Question {
|
12
|
-
static PATH = 'preview-components/'
|
13
|
-
|
45
|
+
export class Question extends PreviewComponent {
|
14
46
|
/**
|
15
|
-
* @type {
|
16
|
-
* @protected
|
47
|
+
* @type {ComponentType}
|
17
48
|
*/
|
18
|
-
|
49
|
+
componentType = ComponentType.TextField
|
50
|
+
|
19
51
|
/**
|
20
|
-
* @type {
|
52
|
+
* @type {string}
|
21
53
|
* @protected
|
22
54
|
*/
|
23
|
-
|
55
|
+
_questionTemplate = PreviewComponent.PATH + 'textfield.njk'
|
24
56
|
/**
|
25
57
|
* @type {string}
|
26
58
|
* @protected
|
27
59
|
*/
|
28
60
|
_fieldName = 'inputField'
|
29
|
-
/**
|
30
|
-
* @type {QuestionRenderer}
|
31
|
-
* @protected
|
32
|
-
*/
|
33
|
-
_questionRenderer
|
34
|
-
|
35
|
-
/**
|
36
|
-
* @type {QuestionElements}
|
37
|
-
* @private
|
38
|
-
*/
|
39
|
-
_htmlElements
|
40
61
|
|
41
62
|
/**
|
42
63
|
* @param {QuestionElements} htmlElements
|
43
64
|
* @param {QuestionRenderer} questionRenderer
|
44
65
|
*/
|
45
66
|
constructor(htmlElements, questionRenderer) {
|
46
|
-
|
47
|
-
|
48
|
-
/**
|
49
|
-
* @type {QuestionElements}
|
50
|
-
* @protected
|
51
|
-
*/
|
52
|
-
this._htmlElements = htmlElements
|
53
|
-
/**
|
54
|
-
* @type {string}
|
55
|
-
* @private
|
56
|
-
*/
|
57
|
-
this._question = question
|
67
|
+
super(htmlElements, questionRenderer)
|
68
|
+
const { hintText } = htmlElements.values
|
58
69
|
/**
|
59
70
|
* @type {string}
|
60
71
|
* @private
|
61
72
|
*/
|
62
73
|
this._hintText = hintText
|
63
|
-
/**
|
64
|
-
* @type {boolean}
|
65
|
-
* @private
|
66
|
-
*/
|
67
|
-
this._optional = optional
|
68
|
-
/**
|
69
|
-
*
|
70
|
-
* @type {QuestionRenderer}
|
71
|
-
* @protected
|
72
|
-
*/
|
73
|
-
this._questionRenderer = questionRenderer
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* @param {string} element
|
78
|
-
* @returns {string}
|
79
|
-
* @protected
|
80
|
-
*/
|
81
|
-
getHighlight(element) {
|
82
|
-
return this._highlight === element ? ' highlight' : ''
|
83
|
-
}
|
84
|
-
|
85
|
-
get titleText() {
|
86
|
-
const optionalText = this._optional ? ' (optional)' : ''
|
87
|
-
return (!this._question ? 'Question' : this._question) + optionalText
|
88
|
-
}
|
89
|
-
|
90
|
-
/**
|
91
|
-
* @protected
|
92
|
-
* @type {DefaultComponent}
|
93
|
-
*/
|
94
|
-
get label() {
|
95
|
-
return {
|
96
|
-
text: this.titleText,
|
97
|
-
classes: 'govuk-label--l' + this.getHighlight('question')
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* @protected
|
103
|
-
* @type {GovukFieldset}
|
104
|
-
*/
|
105
|
-
get fieldSet() {
|
106
|
-
return {
|
107
|
-
legend: {
|
108
|
-
text: this.titleText,
|
109
|
-
classes: 'govuk-fieldset__legend--l' + this.getHighlight('question')
|
110
|
-
}
|
111
|
-
}
|
112
74
|
}
|
113
75
|
|
114
76
|
/**
|
@@ -128,42 +90,11 @@ export class Question {
|
|
128
90
|
}
|
129
91
|
|
130
92
|
/**
|
131
|
-
* @returns {
|
132
|
-
|
133
|
-
get customRenderFields() {
|
134
|
-
return {}
|
135
|
-
}
|
136
|
-
|
137
|
-
/**
|
138
|
-
* @type {QuestionBaseModel}
|
139
|
-
*/
|
140
|
-
get renderInput() {
|
141
|
-
return {
|
142
|
-
id: this._fieldName,
|
143
|
-
name: this._fieldName,
|
144
|
-
label: this.label,
|
145
|
-
hint: this.hint,
|
146
|
-
...this.customRenderFields
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
render() {
|
151
|
-
this._questionRenderer.render(this._questionTemplate, this.renderInput)
|
152
|
-
}
|
153
|
-
|
154
|
-
/**
|
155
|
-
* @type {string}
|
156
|
-
*/
|
157
|
-
get question() {
|
158
|
-
return this._question
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* @param {string} value
|
93
|
+
* @returns {QuestionBaseModel}
|
94
|
+
* @protected
|
163
95
|
*/
|
164
|
-
|
165
|
-
this.
|
166
|
-
this.render()
|
96
|
+
_renderInput() {
|
97
|
+
return { ...super._renderInput(), label: this.label, hint: this.hint }
|
167
98
|
}
|
168
99
|
|
169
100
|
/**
|
@@ -180,36 +111,10 @@ export class Question {
|
|
180
111
|
this._hintText = value
|
181
112
|
this.render()
|
182
113
|
}
|
183
|
-
|
184
|
-
get optional() {
|
185
|
-
return this._optional
|
186
|
-
}
|
187
|
-
|
188
|
-
/**
|
189
|
-
* @param {boolean} value
|
190
|
-
*/
|
191
|
-
set optional(value) {
|
192
|
-
this._optional = value
|
193
|
-
this.render()
|
194
|
-
}
|
195
|
-
|
196
|
-
/**
|
197
|
-
* @type {string | null}
|
198
|
-
*/
|
199
|
-
get highlight() {
|
200
|
-
return this._highlight
|
201
|
-
}
|
202
|
-
|
203
|
-
/**
|
204
|
-
* @param {string | null} value
|
205
|
-
*/
|
206
|
-
set highlight(value) {
|
207
|
-
this._highlight = value
|
208
|
-
this.render()
|
209
|
-
}
|
210
114
|
}
|
211
115
|
|
212
116
|
/**
|
213
117
|
* @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
118
|
+
* @import { FormComponentsDef, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'
|
214
119
|
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
215
120
|
*/
|
@@ -1,6 +1,11 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'
|
2
|
-
import {
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
4
|
|
4
5
|
export class RadioSortableQuestion extends ListSortableQuestion {
|
5
|
-
_questionTemplate =
|
6
|
+
_questionTemplate = PreviewComponent.PATH + 'radios.njk'
|
7
|
+
/**
|
8
|
+
* @type {ComponentType}
|
9
|
+
*/
|
10
|
+
componentType = ComponentType.RadiosField
|
6
11
|
}
|
@@ -1,6 +1,11 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { ListQuestion } from '~/src/form/form-editor/preview/list.js'
|
2
|
-
import {
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
4
|
|
4
5
|
export class RadioQuestion extends ListQuestion {
|
5
|
-
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.RadiosField
|
10
|
+
_questionTemplate = PreviewComponent.PATH + 'radios.njk'
|
6
11
|
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'
|
2
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
|
+
import { ComponentType } from '~/src/index.js'
|
4
|
+
|
5
|
+
export class SelectSortableQuestion extends ListSortableQuestion {
|
6
|
+
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk'
|
7
|
+
|
8
|
+
get selectList() {
|
9
|
+
return this.list.length
|
10
|
+
? [{ id: '', value: '', text: ' ' }, ...this.list]
|
11
|
+
: this.list
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @type {ComponentType}
|
16
|
+
*/
|
17
|
+
componentType = ComponentType.SelectField
|
18
|
+
|
19
|
+
get renderInput() {
|
20
|
+
const afterInput =
|
21
|
+
/** @type {{ formGroup?: { afterInputs: { html: string } } }} */ (
|
22
|
+
this.list.length
|
23
|
+
? {}
|
24
|
+
: {
|
25
|
+
formGroup: {
|
26
|
+
afterInput: {
|
27
|
+
html: this._listElements.afterInputsHTML
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
)
|
32
|
+
|
33
|
+
return {
|
34
|
+
id: this._fieldName,
|
35
|
+
name: this._fieldName,
|
36
|
+
hint: this.hint,
|
37
|
+
label: this.label,
|
38
|
+
items: this.selectList,
|
39
|
+
classes: this.list.length ? '' : 'govuk-visually-hidden',
|
40
|
+
...afterInput
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { ListQuestion } from '~/src/form/form-editor/preview/list.js'
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
4
|
+
|
5
|
+
export class SelectQuestion extends ListQuestion {
|
6
|
+
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk'
|
7
|
+
/**
|
8
|
+
* @type {ComponentType}
|
9
|
+
*/
|
10
|
+
componentType = ComponentType.SelectField
|
11
|
+
}
|
@@ -1,3 +1,9 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
2
3
|
|
3
|
-
export class ShortAnswerQuestion extends Question {
|
4
|
+
export class ShortAnswerQuestion extends Question {
|
5
|
+
/**
|
6
|
+
* @type {ComponentType}
|
7
|
+
*/
|
8
|
+
componentType = ComponentType.TextField
|
9
|
+
}
|
@@ -1,11 +1,17 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
1
3
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
2
4
|
|
3
5
|
export class SupportingEvidenceQuestion extends Question {
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.FileUploadField
|
4
10
|
/**
|
5
11
|
* @type {string}
|
6
12
|
* @protected
|
7
13
|
*/
|
8
|
-
_questionTemplate =
|
14
|
+
_questionTemplate = PreviewComponent.PATH + 'fileuploadfield.njk'
|
9
15
|
/**
|
10
16
|
* @type {string}
|
11
17
|
* @protected
|
@@ -1,3 +1,7 @@
|
|
1
|
+
import {
|
2
|
+
type PagePreviewPanelMacro,
|
3
|
+
type QuestionBaseModel
|
4
|
+
} from '~/src/form/form-editor/macros/types.js'
|
1
5
|
import { type AutocompleteQuestion } from '~/src/form/form-editor/preview/autocomplete.js'
|
2
6
|
import { type DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'
|
3
7
|
import { type EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'
|
@@ -6,20 +10,18 @@ import { type LongAnswerQuestion } from '~/src/form/form-editor/preview/long-ans
|
|
6
10
|
import { type PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'
|
7
11
|
import { type Question } from '~/src/form/form-editor/preview/question.js'
|
8
12
|
import { type RadioSortableQuestion } from '~/src/form/form-editor/preview/radio-sortable.js'
|
13
|
+
import { type SelectSortableQuestion } from '~/src/form/form-editor/preview/select-sortable.js'
|
9
14
|
import { type ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'
|
10
15
|
import { type UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'
|
11
|
-
import {
|
12
|
-
|
13
|
-
type ListElement,
|
14
|
-
type ListItemReadonly
|
15
|
-
} from '~/src/form/form-editor/types.js'
|
16
|
-
|
16
|
+
import { type ListElement } from '~/src/form/form-editor/types.js'
|
17
|
+
export { type QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'
|
17
18
|
export interface BaseSettings {
|
18
19
|
question: string
|
19
20
|
hintText: string
|
20
21
|
optional: boolean
|
21
22
|
shortDesc: string
|
22
23
|
items: ListElement[]
|
24
|
+
content: string
|
23
25
|
}
|
24
26
|
|
25
27
|
export interface DefaultComponent {
|
@@ -32,18 +34,6 @@ export interface GovukFieldset {
|
|
32
34
|
legend: DefaultComponent
|
33
35
|
}
|
34
36
|
|
35
|
-
export interface QuestionBaseModel {
|
36
|
-
id?: string
|
37
|
-
name?: string
|
38
|
-
label?: DefaultComponent
|
39
|
-
hint?: DefaultComponent
|
40
|
-
fieldset?: GovukFieldset
|
41
|
-
readonly items?: ListItemReadonly[] | DateItem[]
|
42
|
-
text?: string
|
43
|
-
formGroup?: { afterInputs: { html: string } }
|
44
|
-
type?: 'text' | 'number' | 'boolean'
|
45
|
-
}
|
46
|
-
|
47
37
|
export type ListenerRow = [
|
48
38
|
HTMLInputElement | null,
|
49
39
|
(target: HTMLInputElement, e: Event) => void,
|
@@ -71,10 +61,19 @@ export interface QuestionRenderer {
|
|
71
61
|
render(questionTemplate: string, questionBaseModel: QuestionBaseModel): void
|
72
62
|
}
|
73
63
|
|
64
|
+
export interface PageRenderer {
|
65
|
+
render(pageTemplate: string, pagePreview: PagePreviewPanelMacro): void
|
66
|
+
}
|
67
|
+
|
74
68
|
export interface ListElements extends QuestionElements {
|
75
69
|
afterInputsHTML: string
|
76
70
|
}
|
77
71
|
|
72
|
+
export interface PageOverviewElements {
|
73
|
+
heading: string
|
74
|
+
guidance: string
|
75
|
+
}
|
76
|
+
|
78
77
|
export type PreviewQuestion =
|
79
78
|
| DateInputQuestion
|
80
79
|
| EmailAddressQuestion
|
@@ -83,6 +82,7 @@ export type PreviewQuestion =
|
|
83
82
|
| PhoneNumberQuestion
|
84
83
|
| Question
|
85
84
|
| RadioSortableQuestion
|
85
|
+
| SelectSortableQuestion
|
86
86
|
| ShortAnswerQuestion
|
87
87
|
| UkAddressQuestion
|
88
88
|
| AutocompleteQuestion
|
@@ -1,8 +1,13 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { FieldsetQuestion } from '~/src/form/form-editor/preview/fieldset-question.js'
|
2
|
-
import {
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
4
|
|
4
5
|
export class UkAddressQuestion extends FieldsetQuestion {
|
5
|
-
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.UkAddressField
|
10
|
+
_questionTemplate = PreviewComponent.PATH + 'ukaddressfield.njk'
|
6
11
|
_fieldName = 'addressField'
|
7
12
|
}
|
8
13
|
|
@@ -1,12 +1,17 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { FieldsetQuestion } from '~/src/form/form-editor/preview/fieldset-question.js'
|
2
|
-
import {
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
4
|
|
4
5
|
export class YesNoQuestion extends FieldsetQuestion {
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.YesNoField
|
5
10
|
/**
|
6
11
|
* @type {string}
|
7
12
|
* @protected
|
8
13
|
*/
|
9
|
-
_questionTemplate =
|
14
|
+
_questionTemplate = PreviewComponent.PATH + 'radios.njk'
|
10
15
|
_fieldName = 'yesNo'
|
11
16
|
|
12
17
|
/**
|