@defra/forms-model 3.0.501 → 3.0.503
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/__stubs__/pages.js +14 -1
- package/dist/module/__stubs__/pages.js.map +1 -1
- package/dist/module/form/form-editor/__stubs__/preview.js +7 -1
- package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
- package/dist/module/form/form-editor/macros/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/controller/guidance-page-controller.js +58 -0
- package/dist/module/form/form-editor/preview/controller/guidance-page-controller.js.map +1 -0
- package/dist/module/form/form-editor/preview/controller/page-controller-base.js +363 -0
- package/dist/module/form/form-editor/preview/controller/page-controller-base.js.map +1 -0
- package/dist/module/form/form-editor/preview/controller/page-controller.js +62 -186
- package/dist/module/form/form-editor/preview/controller/page-controller.js.map +1 -1
- package/dist/module/form/form-editor/preview/index.js +2 -0
- package/dist/module/form/form-editor/preview/index.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/module/pages/helpers.js +2 -1
- package/dist/module/pages/helpers.js.map +1 -1
- package/dist/types/__stubs__/pages.d.ts +14 -0
- package/dist/types/__stubs__/pages.d.ts.map +1 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts +5 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
- package/dist/types/form/form-editor/macros/types.d.ts +8 -0
- package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/controller/guidance-page-controller.d.ts +10 -0
- package/dist/types/form/form-editor/preview/controller/guidance-page-controller.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/controller/page-controller-base.d.ts +198 -0
- package/dist/types/form/form-editor/preview/controller/page-controller-base.d.ts.map +1 -0
- package/dist/types/form/form-editor/preview/controller/page-controller.d.ts +9 -114
- package/dist/types/form/form-editor/preview/controller/page-controller.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/index.d.ts +2 -0
- package/dist/types/form/form-editor/preview/types.d.ts +5 -1
- package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
- package/dist/types/pages/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__stubs__/pages.ts +20 -1
- package/src/form/form-editor/__stubs__/preview.js +13 -1
- package/src/form/form-editor/macros/types.ts +8 -0
- package/src/form/form-editor/preview/controller/guidance-page-controller.js +64 -0
- package/src/form/form-editor/preview/controller/page-controller-base.js +388 -0
- package/src/form/form-editor/preview/controller/page-controller.js +67 -201
- package/src/form/form-editor/preview/index.js +2 -0
- package/src/form/form-editor/preview/types.ts +6 -1
- package/src/pages/helpers.ts +2 -1
@@ -1,9 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
3
|
-
import { ContentElements } from '~/src/form/form-editor/preview/content.js'
|
1
|
+
import { PreviewPageControllerBase } from '~/src/form/form-editor/preview/controller/page-controller-base.js'
|
4
2
|
import { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'
|
5
3
|
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
6
|
-
|
4
|
+
|
7
5
|
/**
|
8
6
|
* @type {QuestionRenderer}
|
9
7
|
*/
|
@@ -17,94 +15,14 @@ const questionRenderer = {
|
|
17
15
|
}
|
18
16
|
}
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
*/
|
23
|
-
export class PagePreviewElements {
|
24
|
-
/**
|
25
|
-
* @type {Page}
|
26
|
-
* @private
|
27
|
-
*/
|
28
|
-
_page
|
29
|
-
|
30
|
-
/**
|
31
|
-
* @param {Page} page
|
32
|
-
*/
|
33
|
-
constructor(page) {
|
34
|
-
this._page = page
|
35
|
-
}
|
36
|
-
|
37
|
-
get heading() {
|
38
|
-
return this._page.title
|
39
|
-
}
|
40
|
-
|
41
|
-
get guidance() {
|
42
|
-
if (!hasComponents(this._page) || !this._page.components.length) {
|
43
|
-
return ''
|
44
|
-
}
|
45
|
-
|
46
|
-
const [possibleGuidanceComponent] = this._page.components
|
47
|
-
|
48
|
-
return possibleGuidanceComponent.type === ComponentType.Markdown
|
49
|
-
? possibleGuidanceComponent.content
|
50
|
-
: ''
|
51
|
-
}
|
52
|
-
|
53
|
-
get addHeading() {
|
54
|
-
return this._page.title.length > 0
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
/**
|
59
|
-
* @implements {PagePreviewPanelMacro}
|
60
|
-
*/
|
61
|
-
export class PreviewPageController {
|
62
|
-
static PATH = 'preview-controllers/'
|
63
|
-
/**
|
64
|
-
* @type {string}
|
65
|
-
* @protected
|
66
|
-
*/
|
67
|
-
_pageTemplate = PreviewPageController.PATH + 'page-controller.njk'
|
18
|
+
export class PreviewPageController extends PreviewPageControllerBase {
|
19
|
+
static PATH = PreviewPageControllerBase.PATH
|
68
20
|
/**
|
69
21
|
* @protected
|
70
22
|
* @type {Question[]}
|
71
23
|
*/
|
72
24
|
_components = []
|
73
|
-
|
74
|
-
* @type {string}
|
75
|
-
*/
|
76
|
-
#title = ''
|
77
|
-
/**
|
78
|
-
*
|
79
|
-
* @type {PageRenderer}
|
80
|
-
*/
|
81
|
-
#pageRenderer
|
82
|
-
/**
|
83
|
-
* @type { undefined | 'title' | 'guidance'}
|
84
|
-
* @protected
|
85
|
-
*/
|
86
|
-
_highlighted = undefined
|
87
|
-
/**
|
88
|
-
* @type {string}
|
89
|
-
* @private
|
90
|
-
*/
|
91
|
-
_guidanceText = ''
|
92
|
-
/**
|
93
|
-
* @type {Markdown}
|
94
|
-
* @private
|
95
|
-
*/
|
96
|
-
_emptyGuidance = PreviewPageController.createGuidanceComponent()
|
97
|
-
/**
|
98
|
-
*
|
99
|
-
* @type {Markdown}
|
100
|
-
* @protected
|
101
|
-
*/
|
102
|
-
_guidanceComponent
|
103
|
-
/**
|
104
|
-
* @type {boolean}
|
105
|
-
* @private
|
106
|
-
*/
|
107
|
-
_showTitle = true
|
25
|
+
|
108
26
|
/**
|
109
27
|
* @param {ComponentDef[]} components
|
110
28
|
* @param {PageOverviewElements} elements
|
@@ -112,23 +30,27 @@ export class PreviewPageController {
|
|
112
30
|
* @param {PageRenderer} renderer
|
113
31
|
*/
|
114
32
|
constructor(components, elements, definition, renderer) {
|
33
|
+
super(elements, renderer)
|
115
34
|
const questions = components.map(
|
116
35
|
mapComponentToPreviewQuestion(questionRenderer, definition)
|
117
36
|
)
|
118
37
|
const firstQuestion = /** @type { Markdown | undefined | Question } */ (
|
119
38
|
questions.shift()
|
120
39
|
)
|
121
|
-
|
122
40
|
this._guidanceComponent =
|
123
41
|
PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)
|
124
42
|
this._guidanceText = elements.guidance
|
125
43
|
this._components = this.#constructComponents(firstQuestion, questions)
|
126
44
|
this._showTitle = elements.addHeading
|
127
|
-
|
128
|
-
this
|
129
|
-
this.#title = elements.heading
|
45
|
+
this._sectionTitle = elements.repeatQuestion ?? ''
|
46
|
+
this._isRepeater = elements.hasRepeater
|
130
47
|
}
|
131
48
|
|
49
|
+
/**
|
50
|
+
* @type {typeof PreviewPageControllerBase.HighlightClass}
|
51
|
+
*/
|
52
|
+
static HighlightClass = PreviewPageControllerBase.HighlightClass
|
53
|
+
|
132
54
|
/**
|
133
55
|
* @param { Question | Markdown | undefined} firstQuestion
|
134
56
|
* @param {Question[]} questions
|
@@ -140,20 +62,6 @@ export class PreviewPageController {
|
|
140
62
|
: [firstQuestion, ...questions]
|
141
63
|
}
|
142
64
|
|
143
|
-
/**
|
144
|
-
* @returns {Markdown[]}
|
145
|
-
* @private
|
146
|
-
*/
|
147
|
-
get _guidanceComponents() {
|
148
|
-
if (this._guidanceText.length) {
|
149
|
-
return [this._guidanceComponent]
|
150
|
-
}
|
151
|
-
if (this._highlighted === 'guidance') {
|
152
|
-
return [this._emptyGuidance]
|
153
|
-
}
|
154
|
-
return []
|
155
|
-
}
|
156
|
-
|
157
65
|
/**
|
158
66
|
* @returns {PagePreviewComponent[]}
|
159
67
|
*/
|
@@ -182,7 +90,7 @@ export class PreviewPageController {
|
|
182
90
|
return false
|
183
91
|
}
|
184
92
|
// |_ one component and title not highlighted
|
185
|
-
if (this
|
93
|
+
if (this._title.trim() === this._components[0]?.question.trim()) {
|
186
94
|
return true
|
187
95
|
}
|
188
96
|
// titles not the same
|
@@ -226,60 +134,13 @@ export class PreviewPageController {
|
|
226
134
|
}
|
227
135
|
}
|
228
136
|
|
229
|
-
set guidanceText(text) {
|
230
|
-
this._guidanceText = text
|
231
|
-
this._guidanceComponent.content = text
|
232
|
-
this.render()
|
233
|
-
}
|
234
|
-
|
235
|
-
get guidanceText() {
|
236
|
-
if (!this._showTitle) {
|
237
|
-
return ''
|
238
|
-
}
|
239
|
-
return this._guidanceText
|
240
|
-
}
|
241
|
-
|
242
|
-
/**
|
243
|
-
*
|
244
|
-
* @param {boolean} showTitle
|
245
|
-
*/
|
246
|
-
set showTitle(showTitle) {
|
247
|
-
this._showTitle = showTitle
|
248
|
-
this.render()
|
249
|
-
}
|
250
|
-
|
251
|
-
get showTitle() {
|
252
|
-
return this._showTitle
|
253
|
-
}
|
254
|
-
|
255
|
-
get guidance() {
|
256
|
-
return {
|
257
|
-
text: this.guidanceText,
|
258
|
-
classes: this._highlighted === 'guidance' ? 'highlight' : ''
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
/**
|
263
|
-
* @returns {{ text: string, classes: string }}
|
264
|
-
*/
|
265
|
-
get pageTitle() {
|
266
|
-
return {
|
267
|
-
text: this.title,
|
268
|
-
classes: this._highlighted === 'title' ? HIGHLIGHT_CLASS : ''
|
269
|
-
}
|
270
|
-
}
|
271
|
-
|
272
|
-
render() {
|
273
|
-
this.#pageRenderer.render(this._pageTemplate, this)
|
274
|
-
}
|
275
|
-
|
276
137
|
/**
|
277
138
|
* @returns {boolean}
|
278
139
|
*/
|
279
140
|
get titleAndFirstTitleSame() {
|
280
141
|
return (
|
281
142
|
this._components.length > 0 &&
|
282
|
-
this
|
143
|
+
this._title.trim() === this._components[0]?.question.trim() &&
|
283
144
|
this.components.length === 1 &&
|
284
145
|
this._highlighted !== 'title'
|
285
146
|
)
|
@@ -287,47 +148,72 @@ export class PreviewPageController {
|
|
287
148
|
|
288
149
|
/**
|
289
150
|
* @returns {string}
|
151
|
+
* @protected
|
290
152
|
*/
|
291
|
-
|
153
|
+
_getTitle() {
|
292
154
|
if (!this._showTitle || this.titleAndFirstTitleSame) {
|
293
155
|
return ''
|
294
156
|
}
|
295
|
-
|
296
|
-
return this.#title
|
297
|
-
}
|
298
|
-
return 'Page heading'
|
157
|
+
return super._getTitle()
|
299
158
|
}
|
300
159
|
|
301
160
|
/**
|
302
|
-
* @
|
161
|
+
* @returns {string}
|
162
|
+
* @protected
|
303
163
|
*/
|
304
|
-
|
305
|
-
this
|
306
|
-
|
164
|
+
_getGuidanceText() {
|
165
|
+
if (!this._showTitle) {
|
166
|
+
return ''
|
167
|
+
}
|
168
|
+
return super._getGuidanceText()
|
307
169
|
}
|
308
170
|
|
309
|
-
|
310
|
-
this.
|
171
|
+
get repeaterText() {
|
172
|
+
if (!this._isRepeater) {
|
173
|
+
return undefined
|
174
|
+
}
|
175
|
+
if (!this._sectionTitle.length) {
|
176
|
+
return 'Question set name'
|
177
|
+
}
|
178
|
+
return this._sectionTitle + ' 1'
|
311
179
|
}
|
312
180
|
|
313
181
|
/**
|
314
|
-
*
|
315
|
-
*
|
316
|
-
* @returns {Markdown}
|
182
|
+
* @returns {string|undefined}
|
183
|
+
* @protected
|
317
184
|
*/
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
options: {}
|
325
|
-
})
|
326
|
-
const guidanceComponent = new Markdown(guidanceElement, questionRenderer)
|
185
|
+
_getSectionTitleText() {
|
186
|
+
if (this._isRepeater) {
|
187
|
+
return this.repeaterText
|
188
|
+
}
|
189
|
+
return undefined
|
190
|
+
}
|
327
191
|
|
328
|
-
|
329
|
-
|
330
|
-
|
192
|
+
get repeaterButton() {
|
193
|
+
if (this.repeaterButtonText === undefined) {
|
194
|
+
return undefined
|
195
|
+
}
|
196
|
+
return {
|
197
|
+
classes: this._isHighlighted(
|
198
|
+
PreviewPageControllerBase.HighlightClass.REPEATER
|
199
|
+
),
|
200
|
+
text: this.repeaterButtonText
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
get repeaterButtonText() {
|
205
|
+
if (!this._isRepeater) {
|
206
|
+
return undefined
|
207
|
+
}
|
208
|
+
|
209
|
+
if (this._sectionTitle === '') {
|
210
|
+
return '[question set name]'
|
211
|
+
}
|
212
|
+
|
213
|
+
const [firstToken, ...rest] = this._sectionTitle
|
214
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
215
|
+
const restOfStr = rest ? rest.join('') : ''
|
216
|
+
return firstToken.toLowerCase() + restOfStr
|
331
217
|
}
|
332
218
|
|
333
219
|
/**
|
@@ -340,27 +226,7 @@ export class PreviewPageController {
|
|
340
226
|
if (guidanceComponent instanceof Markdown) {
|
341
227
|
return guidanceComponent
|
342
228
|
}
|
343
|
-
return
|
344
|
-
}
|
345
|
-
|
346
|
-
highlightGuidance() {
|
347
|
-
this._guidanceComponent.highlightContent()
|
348
|
-
this.setHighLighted('guidance')
|
349
|
-
}
|
350
|
-
|
351
|
-
/**
|
352
|
-
* @param {'title'|'guidance'} highlightSection
|
353
|
-
*/
|
354
|
-
setHighLighted(highlightSection) {
|
355
|
-
this._highlighted = highlightSection
|
356
|
-
this.render()
|
357
|
-
}
|
358
|
-
|
359
|
-
clearHighlight() {
|
360
|
-
this._highlighted = undefined
|
361
|
-
|
362
|
-
this._guidanceComponent.unHighlightContent()
|
363
|
-
this.render()
|
229
|
+
return PreviewPageControllerBase.createGuidanceComponent()
|
364
230
|
}
|
365
231
|
}
|
366
232
|
|
@@ -21,3 +21,5 @@ export * from '~/src/form/form-editor/preview/long-answer.js'
|
|
21
21
|
export * from '~/src/form/form-editor/preview/uk-address.js'
|
22
22
|
export * from '~/src/form/form-editor/preview/yes-no.js'
|
23
23
|
export * from '~/src/form/form-editor/preview/controller/page-controller.js'
|
24
|
+
export * from '~/src/form/form-editor/preview/controller/guidance-page-controller.js'
|
25
|
+
export * from '~/src/form/form-editor/preview/controller/page-controller-base.js'
|
@@ -88,10 +88,15 @@ export interface ListElements extends QuestionElements {
|
|
88
88
|
afterInputsHTML: string
|
89
89
|
}
|
90
90
|
|
91
|
-
export interface
|
91
|
+
export interface PagePreviewBaseElements {
|
92
92
|
heading: string
|
93
93
|
guidance: string
|
94
|
+
}
|
95
|
+
|
96
|
+
export interface PageOverviewElements extends PagePreviewBaseElements {
|
94
97
|
addHeading: boolean
|
98
|
+
repeatQuestion: string | undefined
|
99
|
+
hasRepeater: boolean
|
95
100
|
}
|
96
101
|
|
97
102
|
export type PreviewQuestion =
|
package/src/pages/helpers.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { hasFormField } from '~/src/components/helpers.js'
|
1
3
|
import { type ComponentDef } from '~/src/components/types.js'
|
2
4
|
import {
|
3
5
|
type Link,
|
@@ -6,7 +8,6 @@ import {
|
|
6
8
|
type PageQuestion,
|
7
9
|
type PageRepeat
|
8
10
|
} from '~/src/form/form-definition/types.js'
|
9
|
-
import { ComponentType, hasFormField } from '~/src/index.js'
|
10
11
|
import {
|
11
12
|
ControllerNames,
|
12
13
|
ControllerTypes
|