@defra/forms-model 3.0.481 → 3.0.482
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 +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/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/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,284 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
3
|
+
import { ContentElements } from '~/src/form/form-editor/preview/content.js'
|
4
|
+
import { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'
|
5
|
+
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
6
|
+
import { hasComponents } from '~/src/pages/helpers.js'
|
7
|
+
/**
|
8
|
+
* @type {QuestionRenderer}
|
9
|
+
*/
|
10
|
+
const questionRenderer = {
|
11
|
+
/**
|
12
|
+
* @param {string} _questionTemplate
|
13
|
+
* @param {QuestionBaseModel} _questionBaseModel
|
14
|
+
*/
|
15
|
+
render(_questionTemplate, _questionBaseModel) {
|
16
|
+
//
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @implements {PageOverviewElements}
|
22
|
+
*/
|
23
|
+
export class PagePreviewElements {
|
24
|
+
/**
|
25
|
+
* @type {Page}
|
26
|
+
* @private
|
27
|
+
*/
|
28
|
+
_page
|
29
|
+
/**
|
30
|
+
* @param {Page} page
|
31
|
+
*/
|
32
|
+
constructor(page) {
|
33
|
+
this._page = page
|
34
|
+
}
|
35
|
+
|
36
|
+
get heading() {
|
37
|
+
return this._page.title
|
38
|
+
}
|
39
|
+
|
40
|
+
get guidance() {
|
41
|
+
if (!hasComponents(this._page) || !this._page.components.length) {
|
42
|
+
return ''
|
43
|
+
}
|
44
|
+
|
45
|
+
const [possibleGuidanceComponent] = this._page.components
|
46
|
+
|
47
|
+
return possibleGuidanceComponent.type === ComponentType.Markdown
|
48
|
+
? possibleGuidanceComponent.content
|
49
|
+
: ''
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @implements {PagePreviewPanelMacro}
|
55
|
+
*/
|
56
|
+
export class PreviewPageController {
|
57
|
+
static PATH = 'preview-controllers/'
|
58
|
+
/**
|
59
|
+
* @type {string}
|
60
|
+
* @protected
|
61
|
+
*/
|
62
|
+
_pageTemplate = PreviewPageController.PATH + 'page-controller.njk'
|
63
|
+
/**
|
64
|
+
* @protected
|
65
|
+
* @type {Question[]}
|
66
|
+
*/
|
67
|
+
_components = []
|
68
|
+
/**
|
69
|
+
* @type {string}
|
70
|
+
*/
|
71
|
+
#title = ''
|
72
|
+
/**
|
73
|
+
*
|
74
|
+
* @type {PageRenderer}
|
75
|
+
*/
|
76
|
+
#pageRenderer
|
77
|
+
/**
|
78
|
+
* @type { undefined | 'title' | 'guidance'}
|
79
|
+
* @protected
|
80
|
+
*/
|
81
|
+
_highlighted = undefined
|
82
|
+
/**
|
83
|
+
* @type {string}
|
84
|
+
* @private
|
85
|
+
*/
|
86
|
+
_guidanceText = ''
|
87
|
+
/**
|
88
|
+
* @type {Markdown}
|
89
|
+
* @private
|
90
|
+
*/
|
91
|
+
_emptyGuidance = PreviewPageController.createGuidanceComponent()
|
92
|
+
/**
|
93
|
+
*
|
94
|
+
* @type {Markdown}
|
95
|
+
* @protected
|
96
|
+
*/
|
97
|
+
_guidanceComponent
|
98
|
+
|
99
|
+
/**
|
100
|
+
* @type {boolean}
|
101
|
+
* @private
|
102
|
+
*/
|
103
|
+
_showGuidance = false
|
104
|
+
/**
|
105
|
+
* @param {ComponentDef[]} components
|
106
|
+
* @param {PageOverviewElements} elements
|
107
|
+
* @param {FormDefinition} definition
|
108
|
+
* @param {PageRenderer} renderer
|
109
|
+
*/
|
110
|
+
constructor(components, elements, definition, renderer) {
|
111
|
+
const questions = components.map(
|
112
|
+
mapComponentToPreviewQuestion(questionRenderer, definition)
|
113
|
+
)
|
114
|
+
const firstQuestion = /** @type { Markdown | undefined | Question } */ (
|
115
|
+
questions.shift()
|
116
|
+
)
|
117
|
+
|
118
|
+
this._guidanceComponent =
|
119
|
+
PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)
|
120
|
+
this._guidanceText = elements.guidance
|
121
|
+
this._components = this.#constructComponents(firstQuestion, questions)
|
122
|
+
this.#title = elements.heading
|
123
|
+
this.#pageRenderer = renderer
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @param { Question | Markdown | undefined} firstQuestion
|
128
|
+
* @param {Question[]} questions
|
129
|
+
* @returns {Question[]}
|
130
|
+
*/
|
131
|
+
#constructComponents(firstQuestion, questions) {
|
132
|
+
return firstQuestion instanceof Markdown || firstQuestion === undefined
|
133
|
+
? questions
|
134
|
+
: [firstQuestion, ...questions]
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* @returns {Markdown[]}
|
139
|
+
* @private
|
140
|
+
*/
|
141
|
+
get _guidanceComponents() {
|
142
|
+
if (this._guidanceText.length) {
|
143
|
+
return [this._guidanceComponent]
|
144
|
+
}
|
145
|
+
if (this._highlighted === 'guidance') {
|
146
|
+
return [this._emptyGuidance]
|
147
|
+
}
|
148
|
+
return []
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @returns {PagePreviewComponent[]}
|
153
|
+
*/
|
154
|
+
get components() {
|
155
|
+
const componentsWithGuidance = /** @type {Question[]} */ ([
|
156
|
+
...this._guidanceComponents,
|
157
|
+
...this._components
|
158
|
+
])
|
159
|
+
|
160
|
+
return componentsWithGuidance.map((component) => ({
|
161
|
+
model: component.renderInput,
|
162
|
+
questionType: component.componentType
|
163
|
+
}))
|
164
|
+
}
|
165
|
+
|
166
|
+
set guidanceText(text) {
|
167
|
+
this._guidanceText = text
|
168
|
+
this._guidanceComponent.content = text
|
169
|
+
this.render()
|
170
|
+
}
|
171
|
+
|
172
|
+
get guidanceText() {
|
173
|
+
return this._guidanceText
|
174
|
+
}
|
175
|
+
|
176
|
+
get guidance() {
|
177
|
+
return {
|
178
|
+
text: this.guidanceText,
|
179
|
+
classes: this._highlighted === 'guidance' ? 'highlight' : ''
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @private
|
185
|
+
* @returns {string}
|
186
|
+
*/
|
187
|
+
_fallBackTitle() {
|
188
|
+
return this._components[0]?.question ?? ''
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* @returns {{ text: string, classes: string }}
|
193
|
+
*/
|
194
|
+
get pageTitle() {
|
195
|
+
return {
|
196
|
+
text: this.title,
|
197
|
+
classes: this._highlighted === 'title' ? HIGHLIGHT_CLASS : ''
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
render() {
|
202
|
+
this.#pageRenderer.render(this._pageTemplate, this)
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* @returns {string}
|
207
|
+
*/
|
208
|
+
get title() {
|
209
|
+
return this.#title.length ? this.#title : this._fallBackTitle()
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* @param {string} value
|
214
|
+
*/
|
215
|
+
set title(value) {
|
216
|
+
this.#title = value
|
217
|
+
this.render()
|
218
|
+
}
|
219
|
+
|
220
|
+
highlightTitle() {
|
221
|
+
this.setHighLighted('title')
|
222
|
+
}
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Creates a dummy component for when guidance is highlighted
|
226
|
+
* but no guidance text exists
|
227
|
+
* @returns {Markdown}
|
228
|
+
*/
|
229
|
+
static createGuidanceComponent() {
|
230
|
+
const guidanceElement = new ContentElements({
|
231
|
+
type: ComponentType.Markdown,
|
232
|
+
title: 'Guidance component',
|
233
|
+
name: 'guidanceComponent',
|
234
|
+
content: 'Guidance text',
|
235
|
+
options: {}
|
236
|
+
})
|
237
|
+
const guidanceComponent = new Markdown(guidanceElement, questionRenderer)
|
238
|
+
|
239
|
+
// the dummy component should always be highlighted
|
240
|
+
guidanceComponent.highlightContent()
|
241
|
+
return guidanceComponent
|
242
|
+
}
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Helper method to return the guidance or a new one
|
246
|
+
* @param { Markdown | Question | undefined } guidanceComponent
|
247
|
+
* @returns {Markdown}
|
248
|
+
* @private
|
249
|
+
*/
|
250
|
+
static getOrCreateGuidanceComponent(guidanceComponent) {
|
251
|
+
if (guidanceComponent instanceof Markdown) {
|
252
|
+
return guidanceComponent
|
253
|
+
}
|
254
|
+
return PreviewPageController.createGuidanceComponent()
|
255
|
+
}
|
256
|
+
|
257
|
+
highlightGuidance() {
|
258
|
+
this._guidanceComponent.highlightContent()
|
259
|
+
this.setHighLighted('guidance')
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @param {'title'|'guidance'} highlightSection
|
264
|
+
*/
|
265
|
+
setHighLighted(highlightSection) {
|
266
|
+
this._highlighted = highlightSection
|
267
|
+
this.render()
|
268
|
+
}
|
269
|
+
|
270
|
+
clearHighlight() {
|
271
|
+
this._highlighted = undefined
|
272
|
+
|
273
|
+
this._guidanceComponent.unHighlightContent()
|
274
|
+
this.render()
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'
|
280
|
+
* @import { Question } from '~/src/form/form-editor/preview/question.js'
|
281
|
+
* @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'
|
282
|
+
* @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'
|
283
|
+
* @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'
|
284
|
+
*/
|
@@ -1,10 +1,16 @@
|
|
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'
|
4
|
+
|
3
5
|
export class DateInputQuestion extends FieldsetQuestion {
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.DatePartsField
|
4
10
|
/**
|
5
11
|
* @type {string}
|
6
12
|
* @protected
|
7
13
|
*/
|
8
|
-
_questionTemplate =
|
14
|
+
_questionTemplate = PreviewComponent.PATH + 'date-input.njk'
|
9
15
|
_fieldName = 'dateInput'
|
10
16
|
}
|
@@ -1,6 +1,12 @@
|
|
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 EmailAddressQuestion extends Question {
|
4
|
-
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.EmailAddressField
|
10
|
+
_questionTemplate = PreviewComponent.PATH + 'emailaddressfield.njk'
|
5
11
|
_fieldName = 'emailAddressField'
|
6
12
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
2
3
|
|
3
4
|
/**
|
@@ -5,6 +6,11 @@ import { Question } from '~/src/form/form-editor/preview/question.js'
|
|
5
6
|
* @abstract
|
6
7
|
*/
|
7
8
|
export class FieldsetQuestion extends Question {
|
9
|
+
/**
|
10
|
+
* @type {ComponentType}
|
11
|
+
*/
|
12
|
+
componentType = ComponentType.TextField
|
13
|
+
|
8
14
|
get renderInput() {
|
9
15
|
return {
|
10
16
|
id: this._fieldName,
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { AutocompleteListQuestion } from '~/src/form/form-editor/preview/autocomplete.js'
|
3
|
+
import { CheckboxQuestion } from '~/src/form/form-editor/preview/checkbox.js'
|
4
|
+
import { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'
|
5
|
+
import { ContentElements } from '~/src/form/form-editor/preview/content.js'
|
6
|
+
import { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'
|
7
|
+
import { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'
|
8
|
+
import { ListQuestion } from '~/src/form/form-editor/preview/list.js'
|
9
|
+
import { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'
|
10
|
+
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
11
|
+
import { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'
|
12
|
+
import { NumberOnlyQuestion } from '~/src/form/form-editor/preview/number-only.js'
|
13
|
+
import { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'
|
14
|
+
import { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'
|
15
|
+
import { SelectQuestion } from '~/src/form/form-editor/preview/select.js'
|
16
|
+
import { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'
|
17
|
+
import { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'
|
18
|
+
import { UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'
|
19
|
+
import { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'
|
20
|
+
import { findDefinitionListFromComponent } from '~/src/form/utils/list.js'
|
21
|
+
import {
|
22
|
+
ListComponentElements,
|
23
|
+
QuestionComponentElements,
|
24
|
+
hasContentField,
|
25
|
+
hasInputField,
|
26
|
+
hasListField,
|
27
|
+
hasSelectionFields
|
28
|
+
} from '~/src/index.js'
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @type {Record<ComponentType, typeof PreviewComponent>}
|
32
|
+
*/
|
33
|
+
const InputFieldComponentDictionary = {
|
34
|
+
[ComponentType.TextField]: ShortAnswerQuestion,
|
35
|
+
[ComponentType.Details]: ShortAnswerQuestion,
|
36
|
+
[ComponentType.InsetText]: ShortAnswerQuestion,
|
37
|
+
[ComponentType.Html]: ShortAnswerQuestion,
|
38
|
+
[ComponentType.Markdown]: Markdown,
|
39
|
+
[ComponentType.List]: ListQuestion,
|
40
|
+
[ComponentType.EmailAddressField]: EmailAddressQuestion,
|
41
|
+
[ComponentType.NumberField]: NumberOnlyQuestion,
|
42
|
+
[ComponentType.MultilineTextField]: LongAnswerQuestion,
|
43
|
+
[ComponentType.TelephoneNumberField]: PhoneNumberQuestion,
|
44
|
+
[ComponentType.MonthYearField]: MonthYearQuestion,
|
45
|
+
[ComponentType.DatePartsField]: DateInputQuestion,
|
46
|
+
[ComponentType.UkAddressField]: UkAddressQuestion,
|
47
|
+
[ComponentType.AutocompleteField]: AutocompleteListQuestion,
|
48
|
+
[ComponentType.RadiosField]: RadioQuestion,
|
49
|
+
[ComponentType.CheckboxesField]: CheckboxQuestion,
|
50
|
+
[ComponentType.SelectField]: SelectQuestion,
|
51
|
+
[ComponentType.YesNoField]: YesNoQuestion,
|
52
|
+
[ComponentType.FileUploadField]: SupportingEvidenceQuestion
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @param {QuestionRenderer} questionRenderer
|
57
|
+
* @param {FormDefinition} definition
|
58
|
+
* @returns {(component: ComponentDef) => Question}
|
59
|
+
*/
|
60
|
+
export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
61
|
+
return /** @type {(component: ComponentDef) => Question} */ (
|
62
|
+
(component) => {
|
63
|
+
/**
|
64
|
+
* @type {QuestionElements}
|
65
|
+
*/
|
66
|
+
let questionElements
|
67
|
+
|
68
|
+
if (hasSelectionFields(component) && hasListField(component)) {
|
69
|
+
const list = findDefinitionListFromComponent(component, definition)
|
70
|
+
questionElements = new ListComponentElements(component, list)
|
71
|
+
} else if (
|
72
|
+
hasInputField(component) ||
|
73
|
+
component.type === ComponentType.YesNoField
|
74
|
+
) {
|
75
|
+
questionElements = new QuestionComponentElements(component)
|
76
|
+
} else if (hasContentField(component)) {
|
77
|
+
questionElements = new ContentElements(component)
|
78
|
+
} else {
|
79
|
+
questionElements = new ComponentElements(component)
|
80
|
+
}
|
81
|
+
|
82
|
+
const QuestionConstructor = InputFieldComponentDictionary[component.type]
|
83
|
+
|
84
|
+
return new QuestionConstructor(questionElements, questionRenderer)
|
85
|
+
}
|
86
|
+
)
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* @import { QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
91
|
+
* @import { Question } from '~/src/form/form-editor/preview/question.js'
|
92
|
+
* @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
93
|
+
* @import { Item, FormDefinition } from '~/src/form/form-definition/types.js'
|
94
|
+
* @import { FormComponentsDef, ComponentDef } from '~/src/components/types.js'
|
95
|
+
*/
|
@@ -1,17 +1,23 @@
|
|
1
1
|
export * from '~/src/form/form-editor/preview/autocomplete.js'
|
2
|
+
export * from '~/src/form/form-editor/preview/checkbox.js'
|
2
3
|
export * from '~/src/form/form-editor/preview/checkbox-sortable.js'
|
3
4
|
export * from '~/src/form/form-editor/preview/date-input.js'
|
4
5
|
export * from '~/src/form/form-editor/preview/email-address.js'
|
5
6
|
export * from '~/src/form/form-editor/preview/list.js'
|
6
7
|
export * from '~/src/form/form-editor/preview/list-sortable.js'
|
8
|
+
export * from '~/src/form/form-editor/preview/markdown.js'
|
7
9
|
export * from '~/src/form/form-editor/preview/month-year.js'
|
8
10
|
export * from '~/src/form/form-editor/preview/number-only.js'
|
9
11
|
export * from '~/src/form/form-editor/preview/phone-number.js'
|
10
12
|
export * from '~/src/form/form-editor/preview/question.js'
|
11
13
|
export * from '~/src/form/form-editor/preview/radio.js'
|
12
14
|
export * from '~/src/form/form-editor/preview/radio-sortable.js'
|
15
|
+
export * from '~/src/form/form-editor/preview/select-sortable.js'
|
13
16
|
export * from '~/src/form/form-editor/preview/short-answer.js'
|
17
|
+
export * from '~/src/form/form-editor/preview/select.js'
|
18
|
+
export * from '~/src/form/form-editor/preview/select-sortable.js'
|
14
19
|
export * from '~/src/form/form-editor/preview/supporting-evidence.js'
|
15
20
|
export * from '~/src/form/form-editor/preview/long-answer.js'
|
16
21
|
export * from '~/src/form/form-editor/preview/uk-address.js'
|
17
22
|
export * from '~/src/form/form-editor/preview/yes-no.js'
|
23
|
+
export * from '~/src/form/form-editor/preview/controller/page-controller.js'
|
@@ -1,9 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
3
|
+
import {
|
4
|
+
Question,
|
5
|
+
QuestionComponentElements
|
6
|
+
} from '~/src/form/form-editor/preview/question.js'
|
2
7
|
|
3
8
|
const DefaultListConst = {
|
4
9
|
TextElementId: 'radioText',
|
5
10
|
HintElementId: 'radioHint',
|
6
|
-
Template:
|
11
|
+
Template: PreviewComponent.PATH + 'radios.njk',
|
7
12
|
Input: 'listInput',
|
8
13
|
RenderName: 'listInputField'
|
9
14
|
}
|
@@ -26,7 +31,59 @@ export function listsElementToMap(listElements) {
|
|
26
31
|
return new Map(entries)
|
27
32
|
}
|
28
33
|
|
34
|
+
/**
|
35
|
+
* @param {Item} item
|
36
|
+
* @returns {ListElement}
|
37
|
+
*/
|
38
|
+
export function listItemToListElement(item) {
|
39
|
+
return {
|
40
|
+
text: item.text,
|
41
|
+
label: {
|
42
|
+
text: item.text,
|
43
|
+
classes: ''
|
44
|
+
},
|
45
|
+
value: item.value,
|
46
|
+
id: item.id ?? '',
|
47
|
+
hint: item.hint
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @implements {QuestionElements}
|
53
|
+
*/
|
54
|
+
export class ListComponentElements extends QuestionComponentElements {
|
55
|
+
/**
|
56
|
+
* @type {List}
|
57
|
+
* @protected
|
58
|
+
*/
|
59
|
+
_list
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @param {SelectionComponentsDef} component
|
63
|
+
* @param {List} list
|
64
|
+
*/
|
65
|
+
constructor(component, list) {
|
66
|
+
super(component)
|
67
|
+
this._list = list
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @returns {BaseSettings}
|
72
|
+
* @protected
|
73
|
+
*/
|
74
|
+
_getValues() {
|
75
|
+
return {
|
76
|
+
...super._getValues(),
|
77
|
+
items: this._list.items.map(listItemToListElement)
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
29
82
|
export class ListQuestion extends Question {
|
83
|
+
/**
|
84
|
+
* @type {ComponentType}
|
85
|
+
*/
|
86
|
+
componentType = ComponentType.List
|
30
87
|
/**
|
31
88
|
* @type {string}
|
32
89
|
* @protected
|
@@ -207,5 +264,7 @@ export class ListQuestion extends Question {
|
|
207
264
|
|
208
265
|
/**
|
209
266
|
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
210
|
-
* @import {
|
267
|
+
* @import { SelectionComponentsDef, ListComponentsDef } from '~/src/components/types.js'
|
268
|
+
* @import { List, Item } from '~/src/form/form-definition/types.js'
|
269
|
+
* @import { ListElements, QuestionRenderer, DefaultComponent, GovukFieldset, BaseSettings, QuestionElements } from '~/src/form/form-editor/preview/types.js'
|
211
270
|
*/
|
@@ -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 LongAnswerQuestion extends Question {
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.MultilineTextField
|
4
10
|
/**
|
5
11
|
* @type {string}
|
6
12
|
* @protected
|
7
13
|
*/
|
8
|
-
_questionTemplate =
|
14
|
+
_questionTemplate = PreviewComponent.PATH + 'textarea.njk'
|
9
15
|
/**
|
10
16
|
* @type {string}
|
11
17
|
* @protected
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { Content } from '~/src/form/form-editor/preview/content.js'
|
3
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
4
|
+
import { markdownToHtml } from '~/src/utils/markdown.js'
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @class Markdown
|
8
|
+
* @classdesc
|
9
|
+
* Base of Content preview classes
|
10
|
+
*/
|
11
|
+
export class Markdown extends Content {
|
12
|
+
/**
|
13
|
+
* @type {string}
|
14
|
+
* @protected
|
15
|
+
*/
|
16
|
+
_fieldName = 'markdown'
|
17
|
+
/**
|
18
|
+
* @type {ComponentType}
|
19
|
+
*/
|
20
|
+
componentType = ComponentType.Markdown
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @type {string}
|
24
|
+
* @protected
|
25
|
+
*/
|
26
|
+
_questionTemplate = PreviewComponent.PATH + 'markdown.njk'
|
27
|
+
/**
|
28
|
+
* @param {QuestionElements} htmlElements
|
29
|
+
* @param {QuestionRenderer} questionRenderer
|
30
|
+
*/
|
31
|
+
constructor(htmlElements, questionRenderer) {
|
32
|
+
super(htmlElements, questionRenderer)
|
33
|
+
const { content } = htmlElements.values
|
34
|
+
this._content = markdownToHtml(content)
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @param {string} value
|
39
|
+
* @protected
|
40
|
+
*/
|
41
|
+
_setContent(value) {
|
42
|
+
super._setContent(markdownToHtml(value))
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @import { ListenerRow, BaseSettings, QuestionElements, QuestionBaseModel, GovukFieldset, DefaultComponent, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
48
|
+
* @import { FormComponentsDef, ContentComponentsDef, ComponentDef } from '~/src/components/types.js'
|
49
|
+
* @import { ListElement, ListItemReadonly } from '~/src/form/form-editor/types.js'
|
50
|
+
*/
|
@@ -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 MonthYearQuestion extends FieldsetQuestion {
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.MonthYearField
|
5
10
|
/**
|
6
11
|
* @type {string}
|
7
12
|
* @protected
|
8
13
|
*/
|
9
|
-
_questionTemplate =
|
14
|
+
_questionTemplate = PreviewComponent.PATH + 'monthyearfield.njk'
|
10
15
|
_fieldName = 'monthYear'
|
11
16
|
|
12
17
|
/**
|
@@ -1,6 +1,11 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
1
2
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
2
3
|
|
3
4
|
export class NumberOnlyQuestion extends Question {
|
5
|
+
/**
|
6
|
+
* @type {ComponentType}
|
7
|
+
*/
|
8
|
+
componentType = ComponentType.NumberField
|
4
9
|
/**
|
5
10
|
* @returns {Partial<QuestionBaseModel>}
|
6
11
|
*/
|
@@ -1,7 +1,13 @@
|
|
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 PhoneNumberQuestion extends Question {
|
4
|
-
|
6
|
+
/**
|
7
|
+
* @type {ComponentType}
|
8
|
+
*/
|
9
|
+
componentType = ComponentType.TelephoneNumberField
|
10
|
+
_questionTemplate = PreviewComponent.PATH + 'telephonenumberfield.njk'
|
5
11
|
_fieldName = 'phoneNumberField'
|
6
12
|
}
|
7
13
|
|