@defra/forms-model 3.0.502 → 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/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 +26 -265
- 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/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 +3 -150
- 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 +3 -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/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 +28 -288
- package/src/form/form-editor/preview/index.js +2 -0
- package/src/form/form-editor/preview/types.ts +4 -1
- package/src/pages/helpers.ts +2 -1
@@ -1,10 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { HIGHLIGHT_CLASS } from "../constants.js";
|
3
|
-
import { ContentElements } from "../content.js";
|
1
|
+
import { PreviewPageControllerBase } from "./page-controller-base.js";
|
4
2
|
import { mapComponentToPreviewQuestion } from "../helpers.js";
|
5
3
|
import { Markdown } from "../markdown.js";
|
6
|
-
import { hasRepeater } from "../../../../index.js";
|
7
|
-
import { hasComponents } from "../../../../pages/helpers.js";
|
8
4
|
|
9
5
|
/**
|
10
6
|
* @type {QuestionRenderer}
|
@@ -18,117 +14,13 @@ const questionRenderer = {
|
|
18
14
|
//
|
19
15
|
}
|
20
16
|
};
|
21
|
-
|
22
|
-
|
23
|
-
* @implements {PageOverviewElements}
|
24
|
-
*/
|
25
|
-
export class PagePreviewElements {
|
26
|
-
/**
|
27
|
-
* @type {Page}
|
28
|
-
* @private
|
29
|
-
*/
|
30
|
-
_page;
|
31
|
-
|
32
|
-
/**
|
33
|
-
* @param {Page} page
|
34
|
-
*/
|
35
|
-
constructor(page) {
|
36
|
-
this._page = page;
|
37
|
-
}
|
38
|
-
get heading() {
|
39
|
-
return this._page.title;
|
40
|
-
}
|
41
|
-
get guidance() {
|
42
|
-
if (!hasComponents(this._page) || !this._page.components.length) {
|
43
|
-
return '';
|
44
|
-
}
|
45
|
-
const [possibleGuidanceComponent] = this._page.components;
|
46
|
-
return possibleGuidanceComponent.type === ComponentType.Markdown ? possibleGuidanceComponent.content : '';
|
47
|
-
}
|
48
|
-
get addHeading() {
|
49
|
-
return this._page.title.length > 0;
|
50
|
-
}
|
51
|
-
get repeatQuestion() {
|
52
|
-
if (hasRepeater(this._page)) {
|
53
|
-
return this._page.repeat.options.title;
|
54
|
-
}
|
55
|
-
return undefined;
|
56
|
-
}
|
57
|
-
get hasRepeater() {
|
58
|
-
return hasRepeater(this._page);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Enum for Highlight classes
|
64
|
-
* @readonly
|
65
|
-
* @enum {string}
|
66
|
-
*/
|
67
|
-
const HighlightClass = {
|
68
|
-
TITLE: 'title',
|
69
|
-
GUIDANCE: 'guidance',
|
70
|
-
REPEATER: 'repeater'
|
71
|
-
};
|
72
|
-
|
73
|
-
/**
|
74
|
-
* @implements {PagePreviewPanelMacro}
|
75
|
-
*/
|
76
|
-
export class PreviewPageController {
|
77
|
-
static PATH = 'preview-controllers/';
|
78
|
-
/**
|
79
|
-
* @type {string}
|
80
|
-
* @protected
|
81
|
-
*/
|
82
|
-
_pageTemplate = PreviewPageController.PATH + 'page-controller.njk';
|
17
|
+
export class PreviewPageController extends PreviewPageControllerBase {
|
18
|
+
static PATH = PreviewPageControllerBase.PATH;
|
83
19
|
/**
|
84
20
|
* @protected
|
85
21
|
* @type {Question[]}
|
86
22
|
*/
|
87
23
|
_components = [];
|
88
|
-
/**
|
89
|
-
* @type {string}
|
90
|
-
*/
|
91
|
-
#title = '';
|
92
|
-
/**
|
93
|
-
*
|
94
|
-
* @type {PageRenderer}
|
95
|
-
*/
|
96
|
-
#pageRenderer;
|
97
|
-
/**
|
98
|
-
* @type { undefined | HighlightClass }
|
99
|
-
* @protected
|
100
|
-
*/
|
101
|
-
_highlighted = undefined;
|
102
|
-
/**
|
103
|
-
* @type {string}
|
104
|
-
* @private
|
105
|
-
*/
|
106
|
-
_guidanceText = '';
|
107
|
-
/**
|
108
|
-
* @type { string }
|
109
|
-
* @protected
|
110
|
-
*/
|
111
|
-
_sectionTitle = '';
|
112
|
-
/**
|
113
|
-
* @type {Markdown}
|
114
|
-
* @private
|
115
|
-
*/
|
116
|
-
_emptyGuidance = PreviewPageController.createGuidanceComponent();
|
117
|
-
/**
|
118
|
-
*
|
119
|
-
* @type {Markdown}
|
120
|
-
* @protected
|
121
|
-
*/
|
122
|
-
_guidanceComponent;
|
123
|
-
/**
|
124
|
-
* @type {boolean}
|
125
|
-
* @private
|
126
|
-
*/
|
127
|
-
_showTitle = true;
|
128
|
-
/**
|
129
|
-
* @type {boolean}
|
130
|
-
*/
|
131
|
-
#isRepeater = false;
|
132
24
|
|
133
25
|
/**
|
134
26
|
* @param {ComponentDef[]} components
|
@@ -137,6 +29,7 @@ export class PreviewPageController {
|
|
137
29
|
* @param {PageRenderer} renderer
|
138
30
|
*/
|
139
31
|
constructor(components, elements, definition, renderer) {
|
32
|
+
super(elements, renderer);
|
140
33
|
const questions = components.map(mapComponentToPreviewQuestion(questionRenderer, definition));
|
141
34
|
const firstQuestion = /** @type { Markdown | undefined | Question } */
|
142
35
|
questions.shift();
|
@@ -144,16 +37,14 @@ export class PreviewPageController {
|
|
144
37
|
this._guidanceText = elements.guidance;
|
145
38
|
this._components = this.#constructComponents(firstQuestion, questions);
|
146
39
|
this._showTitle = elements.addHeading;
|
147
|
-
this.#pageRenderer = renderer;
|
148
|
-
this.#title = elements.heading;
|
149
40
|
this._sectionTitle = elements.repeatQuestion ?? '';
|
150
|
-
this
|
41
|
+
this._isRepeater = elements.hasRepeater;
|
151
42
|
}
|
152
43
|
|
153
44
|
/**
|
154
|
-
* @type {typeof HighlightClass}
|
45
|
+
* @type {typeof PreviewPageControllerBase.HighlightClass}
|
155
46
|
*/
|
156
|
-
static HighlightClass = HighlightClass;
|
47
|
+
static HighlightClass = PreviewPageControllerBase.HighlightClass;
|
157
48
|
|
158
49
|
/**
|
159
50
|
* @param { Question | Markdown | undefined} firstQuestion
|
@@ -164,20 +55,6 @@ export class PreviewPageController {
|
|
164
55
|
return firstQuestion instanceof Markdown || firstQuestion === undefined ? questions : [firstQuestion, ...questions];
|
165
56
|
}
|
166
57
|
|
167
|
-
/**
|
168
|
-
* @returns {Markdown[]}
|
169
|
-
* @private
|
170
|
-
*/
|
171
|
-
get _guidanceComponents() {
|
172
|
-
if (this._guidanceText.length) {
|
173
|
-
return [this._guidanceComponent];
|
174
|
-
}
|
175
|
-
if (this._highlighted === 'guidance') {
|
176
|
-
return [this._emptyGuidance];
|
177
|
-
}
|
178
|
-
return [];
|
179
|
-
}
|
180
|
-
|
181
58
|
/**
|
182
59
|
* @returns {PagePreviewComponent[]}
|
183
60
|
*/
|
@@ -200,7 +77,7 @@ export class PreviewPageController {
|
|
200
77
|
return false;
|
201
78
|
}
|
202
79
|
// |_ one component and title not highlighted
|
203
|
-
if (this
|
80
|
+
if (this._title.trim() === this._components[0]?.question.trim()) {
|
204
81
|
return true;
|
205
82
|
}
|
206
83
|
// titles not the same
|
@@ -234,105 +111,37 @@ export class PreviewPageController {
|
|
234
111
|
...label
|
235
112
|
};
|
236
113
|
}
|
237
|
-
set guidanceText(text) {
|
238
|
-
this._guidanceText = text;
|
239
|
-
this._guidanceComponent.content = text;
|
240
|
-
this.render();
|
241
|
-
}
|
242
|
-
get guidanceText() {
|
243
|
-
if (!this._showTitle) {
|
244
|
-
return '';
|
245
|
-
}
|
246
|
-
return this._guidanceText;
|
247
|
-
}
|
248
|
-
|
249
|
-
/**
|
250
|
-
*
|
251
|
-
* @param {boolean} showTitle
|
252
|
-
*/
|
253
|
-
set showTitle(showTitle) {
|
254
|
-
this._showTitle = showTitle;
|
255
|
-
this.render();
|
256
|
-
}
|
257
|
-
get showTitle() {
|
258
|
-
return this._showTitle;
|
259
|
-
}
|
260
|
-
get guidance() {
|
261
|
-
return {
|
262
|
-
text: this.guidanceText,
|
263
|
-
classes: this.#isHighlighted(HighlightClass.GUIDANCE)
|
264
|
-
};
|
265
|
-
}
|
266
|
-
|
267
|
-
/**
|
268
|
-
* @returns {{ text: string, classes: string }}
|
269
|
-
*/
|
270
|
-
get pageTitle() {
|
271
|
-
return {
|
272
|
-
text: this.title,
|
273
|
-
classes: this.#isHighlighted(HighlightClass.TITLE)
|
274
|
-
};
|
275
|
-
}
|
276
|
-
render() {
|
277
|
-
this.#pageRenderer.render(this._pageTemplate, this);
|
278
|
-
}
|
279
114
|
|
280
115
|
/**
|
281
116
|
* @returns {boolean}
|
282
117
|
*/
|
283
118
|
get titleAndFirstTitleSame() {
|
284
|
-
return this._components.length > 0 && this
|
119
|
+
return this._components.length > 0 && this._title.trim() === this._components[0]?.question.trim() && this.components.length === 1 && this._highlighted !== 'title';
|
285
120
|
}
|
286
121
|
|
287
122
|
/**
|
288
123
|
* @returns {string}
|
124
|
+
* @protected
|
289
125
|
*/
|
290
|
-
|
126
|
+
_getTitle() {
|
291
127
|
if (!this._showTitle || this.titleAndFirstTitleSame) {
|
292
128
|
return '';
|
293
129
|
}
|
294
|
-
|
295
|
-
return this.#title;
|
296
|
-
}
|
297
|
-
return 'Page heading';
|
130
|
+
return super._getTitle();
|
298
131
|
}
|
299
132
|
|
300
133
|
/**
|
301
|
-
* @
|
302
|
-
|
303
|
-
set title(value) {
|
304
|
-
this.#title = value;
|
305
|
-
this.render();
|
306
|
-
}
|
307
|
-
highlightTitle() {
|
308
|
-
this.setHighLighted(HighlightClass.TITLE);
|
309
|
-
}
|
310
|
-
setRepeater() {
|
311
|
-
this.#isRepeater = true;
|
312
|
-
this.render();
|
313
|
-
}
|
314
|
-
unsetRepeater() {
|
315
|
-
this.#isRepeater = false;
|
316
|
-
this.render();
|
317
|
-
}
|
318
|
-
get isRepeater() {
|
319
|
-
return this.#isRepeater;
|
320
|
-
}
|
321
|
-
|
322
|
-
/**
|
323
|
-
* @returns {{classes: string, text: string} | undefined}
|
134
|
+
* @returns {string}
|
135
|
+
* @protected
|
324
136
|
*/
|
325
|
-
|
326
|
-
if (this.
|
327
|
-
return
|
137
|
+
_getGuidanceText() {
|
138
|
+
if (!this._showTitle) {
|
139
|
+
return '';
|
328
140
|
}
|
329
|
-
return
|
330
|
-
classes: this.#isHighlighted(HighlightClass.REPEATER),
|
331
|
-
text: this.sectionTitleText
|
332
|
-
};
|
141
|
+
return super._getGuidanceText();
|
333
142
|
}
|
334
143
|
get repeaterText() {
|
335
|
-
if (!this
|
144
|
+
if (!this._isRepeater) {
|
336
145
|
return undefined;
|
337
146
|
}
|
338
147
|
if (!this._sectionTitle.length) {
|
@@ -342,14 +151,11 @@ export class PreviewPageController {
|
|
342
151
|
}
|
343
152
|
|
344
153
|
/**
|
345
|
-
* @
|
154
|
+
* @returns {string|undefined}
|
155
|
+
* @protected
|
346
156
|
*/
|
347
|
-
|
348
|
-
this.
|
349
|
-
this.render();
|
350
|
-
}
|
351
|
-
get sectionTitleText() {
|
352
|
-
if (this.#isRepeater) {
|
157
|
+
_getSectionTitleText() {
|
158
|
+
if (this._isRepeater) {
|
353
159
|
return this.repeaterText;
|
354
160
|
}
|
355
161
|
return undefined;
|
@@ -359,12 +165,12 @@ export class PreviewPageController {
|
|
359
165
|
return undefined;
|
360
166
|
}
|
361
167
|
return {
|
362
|
-
classes: this
|
168
|
+
classes: this._isHighlighted(PreviewPageControllerBase.HighlightClass.REPEATER),
|
363
169
|
text: this.repeaterButtonText
|
364
170
|
};
|
365
171
|
}
|
366
172
|
get repeaterButtonText() {
|
367
|
-
if (!this
|
173
|
+
if (!this._isRepeater) {
|
368
174
|
return undefined;
|
369
175
|
}
|
370
176
|
if (this._sectionTitle === '') {
|
@@ -376,26 +182,6 @@ export class PreviewPageController {
|
|
376
182
|
return firstToken.toLowerCase() + restOfStr;
|
377
183
|
}
|
378
184
|
|
379
|
-
/**
|
380
|
-
* Creates a dummy component for when guidance is highlighted
|
381
|
-
* but no guidance text exists
|
382
|
-
* @returns {Markdown}
|
383
|
-
*/
|
384
|
-
static createGuidanceComponent() {
|
385
|
-
const guidanceElement = new ContentElements({
|
386
|
-
type: ComponentType.Markdown,
|
387
|
-
title: 'Guidance component',
|
388
|
-
name: 'guidanceComponent',
|
389
|
-
content: 'Guidance text',
|
390
|
-
options: {}
|
391
|
-
});
|
392
|
-
const guidanceComponent = new Markdown(guidanceElement, questionRenderer);
|
393
|
-
|
394
|
-
// the dummy component should always be highlighted
|
395
|
-
guidanceComponent.highlightContent();
|
396
|
-
return guidanceComponent;
|
397
|
-
}
|
398
|
-
|
399
185
|
/**
|
400
186
|
* Helper method to return the guidance or a new one
|
401
187
|
* @param { Markdown | Question | undefined } guidanceComponent
|
@@ -406,32 +192,7 @@ export class PreviewPageController {
|
|
406
192
|
if (guidanceComponent instanceof Markdown) {
|
407
193
|
return guidanceComponent;
|
408
194
|
}
|
409
|
-
return
|
410
|
-
}
|
411
|
-
highlightGuidance() {
|
412
|
-
this._guidanceComponent.highlightContent();
|
413
|
-
this.setHighLighted(HighlightClass.GUIDANCE);
|
414
|
-
}
|
415
|
-
|
416
|
-
/**
|
417
|
-
* @param {HighlightClass} highlightSection
|
418
|
-
*/
|
419
|
-
setHighLighted(highlightSection) {
|
420
|
-
this._highlighted = highlightSection;
|
421
|
-
this.render();
|
422
|
-
}
|
423
|
-
clearHighlight() {
|
424
|
-
this._highlighted = undefined;
|
425
|
-
this._guidanceComponent.unHighlightContent();
|
426
|
-
this.render();
|
427
|
-
}
|
428
|
-
|
429
|
-
/**
|
430
|
-
* @param {string} field
|
431
|
-
* @returns {string}
|
432
|
-
*/
|
433
|
-
#isHighlighted(field) {
|
434
|
-
return this._highlighted === field ? HIGHLIGHT_CLASS : '';
|
195
|
+
return PreviewPageControllerBase.createGuidanceComponent();
|
435
196
|
}
|
436
197
|
}
|
437
198
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"page-controller.js","names":["ComponentType","HIGHLIGHT_CLASS","ContentElements","mapComponentToPreviewQuestion","Markdown","hasRepeater","hasComponents","questionRenderer","render","_questionTemplate","_questionBaseModel","PagePreviewElements","_page","constructor","page","heading","title","guidance","components","length","possibleGuidanceComponent","type","content","addHeading","repeatQuestion","repeat","options","undefined","HighlightClass","TITLE","GUIDANCE","REPEATER","PreviewPageController","PATH","_pageTemplate","_components","pageRenderer","_highlighted","_guidanceText","_sectionTitle","_emptyGuidance","createGuidanceComponent","_guidanceComponent","_showTitle","isRepeater","elements","definition","renderer","questions","map","firstQuestion","shift","getOrCreateGuidanceComponent","constructComponents","#constructComponents","_guidanceComponents","componentsWithGuidance","component","model","_overrideComponentHeading","questionType","componentType","showLargeTitle","componentsLength","trim","question","largeTitle","fieldset","renderInput","legend","classes","label","guidanceText","text","showTitle","isHighlighted","pageTitle","titleAndFirstTitleSame","value","highlightTitle","setHighLighted","setRepeater","unsetRepeater","sectionTitle","sectionTitleText","repeaterText","val","repeaterButton","repeaterButtonText","firstToken","rest","restOfStr","join","toLowerCase","guidanceElement","name","guidanceComponent","highlightContent","highlightGuidance","highlightSection","clearHighlight","unHighlightContent","#isHighlighted","field"],"sources":["../../../../../../src/form/form-editor/preview/controller/page-controller.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { hasRepeater } from '~/src/index.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n\n/**\n * @type {QuestionRenderer}\n */\nconst questionRenderer = {\n /**\n * @param {string} _questionTemplate\n * @param {QuestionBaseModel} _questionBaseModel\n */\n render(_questionTemplate, _questionBaseModel) {\n //\n }\n}\n\n/**\n * @implements {PageOverviewElements}\n */\nexport class PagePreviewElements {\n /**\n * @type {Page}\n * @private\n */\n _page\n\n /**\n * @param {Page} page\n */\n constructor(page) {\n this._page = page\n }\n\n get heading() {\n return this._page.title\n }\n\n get guidance() {\n if (!hasComponents(this._page) || !this._page.components.length) {\n return ''\n }\n\n const [possibleGuidanceComponent] = this._page.components\n\n return possibleGuidanceComponent.type === ComponentType.Markdown\n ? possibleGuidanceComponent.content\n : ''\n }\n\n get addHeading() {\n return this._page.title.length > 0\n }\n\n get repeatQuestion() {\n if (hasRepeater(this._page)) {\n return this._page.repeat.options.title\n }\n return undefined\n }\n\n get hasRepeater() {\n return hasRepeater(this._page)\n }\n}\n\n/**\n * Enum for Highlight classes\n * @readonly\n * @enum {string}\n */\nconst HighlightClass = {\n TITLE: 'title',\n GUIDANCE: 'guidance',\n REPEATER: 'repeater'\n}\n\n/**\n * @implements {PagePreviewPanelMacro}\n */\nexport class PreviewPageController {\n static PATH = 'preview-controllers/'\n /**\n * @type {string}\n * @protected\n */\n _pageTemplate = PreviewPageController.PATH + 'page-controller.njk'\n /**\n * @protected\n * @type {Question[]}\n */\n _components = []\n /**\n * @type {string}\n */\n #title = ''\n /**\n *\n * @type {PageRenderer}\n */\n #pageRenderer\n /**\n * @type { undefined | HighlightClass }\n * @protected\n */\n _highlighted = undefined\n /**\n * @type {string}\n * @private\n */\n _guidanceText = ''\n /**\n * @type { string }\n * @protected\n */\n _sectionTitle = ''\n /**\n * @type {Markdown}\n * @private\n */\n _emptyGuidance = PreviewPageController.createGuidanceComponent()\n /**\n *\n * @type {Markdown}\n * @protected\n */\n _guidanceComponent\n /**\n * @type {boolean}\n * @private\n */\n _showTitle = true\n /**\n * @type {boolean}\n */\n #isRepeater = false\n\n /**\n * @param {ComponentDef[]} components\n * @param {PageOverviewElements} elements\n * @param {FormDefinition} definition\n * @param {PageRenderer} renderer\n */\n constructor(components, elements, definition, renderer) {\n const questions = components.map(\n mapComponentToPreviewQuestion(questionRenderer, definition)\n )\n const firstQuestion = /** @type { Markdown | undefined | Question } */ (\n questions.shift()\n )\n\n this._guidanceComponent =\n PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)\n this._guidanceText = elements.guidance\n this._components = this.#constructComponents(firstQuestion, questions)\n this._showTitle = elements.addHeading\n\n this.#pageRenderer = renderer\n this.#title = elements.heading\n this._sectionTitle = elements.repeatQuestion ?? ''\n this.#isRepeater = elements.hasRepeater\n }\n\n /**\n * @type {typeof HighlightClass}\n */\n static HighlightClass = HighlightClass\n\n /**\n * @param { Question | Markdown | undefined} firstQuestion\n * @param {Question[]} questions\n * @returns {Question[]}\n */\n #constructComponents(firstQuestion, questions) {\n return firstQuestion instanceof Markdown || firstQuestion === undefined\n ? questions\n : [firstQuestion, ...questions]\n }\n\n /**\n * @returns {Markdown[]}\n * @private\n */\n get _guidanceComponents() {\n if (this._guidanceText.length) {\n return [this._guidanceComponent]\n }\n if (this._highlighted === 'guidance') {\n return [this._emptyGuidance]\n }\n return []\n }\n\n /**\n * @returns {PagePreviewComponent[]}\n */\n get components() {\n const componentsWithGuidance = /** @type {Question[]} */ ([\n ...this._guidanceComponents,\n ...this._components\n ])\n\n return componentsWithGuidance.map((component) => {\n return {\n model: this._overrideComponentHeading(component),\n questionType: component.componentType\n }\n })\n }\n\n /**\n * @returns {boolean}\n */\n get showLargeTitle() {\n const componentsLength =\n this._components.length + this._guidanceComponents.length\n\n if (componentsLength > 1 || this._highlighted === 'title') {\n return false\n }\n // |_ one component and title not highlighted\n if (this.#title.trim() === this._components[0].question.trim()) {\n return true\n }\n // titles not the same\n\n return !this._showTitle // add page heading deselected?\n }\n\n /**\n * @param {PreviewComponent} component\n * @returns {QuestionBaseModel}\n */\n _overrideComponentHeading(component) {\n const largeTitle = this.showLargeTitle\n\n const fieldset = component.renderInput.fieldset\n ? {\n fieldset: {\n legend: {\n ...component.renderInput.fieldset.legend,\n classes: largeTitle\n ? 'govuk-fieldset__legend--l'\n : 'govuk-fieldset__legend--m'\n }\n }\n }\n : {}\n\n const label = component.renderInput.label\n ? {\n label: {\n ...component.renderInput.label,\n classes: largeTitle ? 'govuk-label--l' : 'govuk-label--m'\n }\n }\n : {}\n\n return {\n ...component.renderInput,\n ...fieldset,\n ...label\n }\n }\n\n set guidanceText(text) {\n this._guidanceText = text\n this._guidanceComponent.content = text\n this.render()\n }\n\n get guidanceText() {\n if (!this._showTitle) {\n return ''\n }\n return this._guidanceText\n }\n\n /**\n *\n * @param {boolean} showTitle\n */\n set showTitle(showTitle) {\n this._showTitle = showTitle\n this.render()\n }\n\n get showTitle() {\n return this._showTitle\n }\n\n get guidance() {\n return {\n text: this.guidanceText,\n classes: this.#isHighlighted(HighlightClass.GUIDANCE)\n }\n }\n\n /**\n * @returns {{ text: string, classes: string }}\n */\n get pageTitle() {\n return {\n text: this.title,\n classes: this.#isHighlighted(HighlightClass.TITLE)\n }\n }\n\n render() {\n this.#pageRenderer.render(this._pageTemplate, this)\n }\n\n /**\n * @returns {boolean}\n */\n get titleAndFirstTitleSame() {\n return (\n this._components.length > 0 &&\n this.#title.trim() === this._components[0].question.trim() &&\n this.components.length === 1 &&\n this._highlighted !== 'title'\n )\n }\n\n /**\n * @returns {string}\n */\n get title() {\n if (!this._showTitle || this.titleAndFirstTitleSame) {\n return ''\n }\n if (this.#title.length) {\n return this.#title\n }\n return 'Page heading'\n }\n\n /**\n * @param {string} value\n */\n set title(value) {\n this.#title = value\n this.render()\n }\n\n highlightTitle() {\n this.setHighLighted(HighlightClass.TITLE)\n }\n\n setRepeater() {\n this.#isRepeater = true\n this.render()\n }\n\n unsetRepeater() {\n this.#isRepeater = false\n this.render()\n }\n\n get isRepeater() {\n return this.#isRepeater\n }\n\n /**\n * @returns {{classes: string, text: string} | undefined}\n */\n get sectionTitle() {\n if (this.sectionTitleText === undefined) {\n return undefined\n }\n return {\n classes: this.#isHighlighted(HighlightClass.REPEATER),\n text: this.sectionTitleText\n }\n }\n\n get repeaterText() {\n if (!this.#isRepeater) {\n return undefined\n }\n if (!this._sectionTitle.length) {\n return 'Question set name'\n }\n return this._sectionTitle + ' 1'\n }\n\n /**\n * @param {string | undefined} val\n */\n set sectionTitleText(val) {\n this._sectionTitle = val ?? ''\n this.render()\n }\n\n get sectionTitleText() {\n if (this.#isRepeater) {\n return this.repeaterText\n }\n return undefined\n }\n\n get repeaterButton() {\n if (this.repeaterButtonText === undefined) {\n return undefined\n }\n return {\n classes: this.#isHighlighted(HighlightClass.REPEATER),\n text: this.repeaterButtonText\n }\n }\n\n get repeaterButtonText() {\n if (!this.#isRepeater) {\n return undefined\n }\n\n if (this._sectionTitle === '') {\n return '[question set name]'\n }\n\n const [firstToken, ...rest] = this._sectionTitle\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const restOfStr = rest ? rest.join('') : ''\n return firstToken.toLowerCase() + restOfStr\n }\n\n /**\n * Creates a dummy component for when guidance is highlighted\n * but no guidance text exists\n * @returns {Markdown}\n */\n static createGuidanceComponent() {\n const guidanceElement = new ContentElements({\n type: ComponentType.Markdown,\n title: 'Guidance component',\n name: 'guidanceComponent',\n content: 'Guidance text',\n options: {}\n })\n const guidanceComponent = new Markdown(guidanceElement, questionRenderer)\n\n // the dummy component should always be highlighted\n guidanceComponent.highlightContent()\n return guidanceComponent\n }\n\n /**\n * Helper method to return the guidance or a new one\n * @param { Markdown | Question | undefined } guidanceComponent\n * @returns {Markdown}\n * @private\n */\n static getOrCreateGuidanceComponent(guidanceComponent) {\n if (guidanceComponent instanceof Markdown) {\n return guidanceComponent\n }\n return PreviewPageController.createGuidanceComponent()\n }\n\n highlightGuidance() {\n this._guidanceComponent.highlightContent()\n this.setHighLighted(HighlightClass.GUIDANCE)\n }\n\n /**\n * @param {HighlightClass} highlightSection\n */\n setHighLighted(highlightSection) {\n this._highlighted = highlightSection\n this.render()\n }\n\n clearHighlight() {\n this._highlighted = undefined\n\n this._guidanceComponent.unHighlightContent()\n this.render()\n }\n\n /**\n * @param {string} field\n * @returns {string}\n */\n #isHighlighted(field) {\n return this._highlighted === field ? HIGHLIGHT_CLASS : ''\n }\n}\n\n/**\n * @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n * @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'\n * @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'\n * @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,eAAe;AACxB,SAASC,eAAe;AACxB,SAASC,6BAA6B;AACtC,SAASC,QAAQ;AAC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ACF,MAAMsE,iBAAiB,GAAG,IAAI5F,QAAQ,CAAC0F,eAAe,EAAEvF,gBAAgB,CAAC;;IAEzE;IACAyF,iBAAiB,CAACC,gBAAgB,CAAC,CAAC;IACpC,OAAOD,iBAAiB;EAC1B;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAO5C,4BAA4BA,CAAC4C,iBAAiB,EAAE;IACrD,IAAIA,iBAAiB,YAAY5F,QAAQ,EAAE;MACzC,OAAO4F,iBAAiB;IAC1B;IACA,OAAOhE,qBAAqB,CAACS,uBAAuB,CAAC,CAAC;EACxD;EAEAyD,iBAAiBA,CAAA,EAAG;IAClB,IAAI,CAACxD,kBAAkB,CAACuD,gBAAgB,CAAC,CAAC;IAC1C,IAAI,CAACjB,cAAc,CAACpD,cAAc,CAACE,QAAQ,CAAC;EAC9C;;EAEA;AACF;AACA;EACEkD,cAAcA,CAACmB,gBAAgB,EAAE;IAC/B,IAAI,CAAC9D,YAAY,GAAG8D,gBAAgB;IACpC,IAAI,CAAC3F,MAAM,CAAC,CAAC;EACf;EAEA4F,cAAcA,CAAA,EAAG;IACf,IAAI,CAAC/D,YAAY,GAAGV,SAAS;IAE7B,IAAI,CAACe,kBAAkB,CAAC2D,kBAAkB,CAAC,CAAC;IAC5C,IAAI,CAAC7F,MAAM,CAAC,CAAC;EACf;;EAEA;AACF;AACA;AACA;EACE,CAACmE,aAAa2B,CAACC,KAAK,EAAE;IACpB,OAAO,IAAI,CAAClE,YAAY,KAAKkE,KAAK,GAAGtG,eAAe,GAAG,EAAE;EAC3D;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
1
|
+
{"version":3,"file":"page-controller.js","names":["PreviewPageControllerBase","mapComponentToPreviewQuestion","Markdown","questionRenderer","render","_questionTemplate","_questionBaseModel","PreviewPageController","PATH","_components","constructor","components","elements","definition","renderer","questions","map","firstQuestion","shift","_guidanceComponent","getOrCreateGuidanceComponent","_guidanceText","guidance","constructComponents","_showTitle","addHeading","_sectionTitle","repeatQuestion","_isRepeater","hasRepeater","HighlightClass","#constructComponents","undefined","componentsWithGuidance","_guidanceComponents","component","model","_overrideComponentHeading","questionType","componentType","showLargeTitle","componentsLength","length","_highlighted","_title","trim","question","largeTitle","fieldset","renderInput","legend","classes","label","titleAndFirstTitleSame","_getTitle","_getGuidanceText","repeaterText","_getSectionTitleText","repeaterButton","repeaterButtonText","_isHighlighted","REPEATER","text","firstToken","rest","restOfStr","join","toLowerCase","guidanceComponent","createGuidanceComponent"],"sources":["../../../../../../src/form/form-editor/preview/controller/page-controller.js"],"sourcesContent":["import { PreviewPageControllerBase } from '~/src/form/form-editor/preview/controller/page-controller-base.js'\nimport { mapComponentToPreviewQuestion } from '~/src/form/form-editor/preview/helpers.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\n\n/**\n * @type {QuestionRenderer}\n */\nconst questionRenderer = {\n /**\n * @param {string} _questionTemplate\n * @param {QuestionBaseModel} _questionBaseModel\n */\n render(_questionTemplate, _questionBaseModel) {\n //\n }\n}\n\nexport class PreviewPageController extends PreviewPageControllerBase {\n static PATH = PreviewPageControllerBase.PATH\n /**\n * @protected\n * @type {Question[]}\n */\n _components = []\n\n /**\n * @param {ComponentDef[]} components\n * @param {PageOverviewElements} elements\n * @param {FormDefinition} definition\n * @param {PageRenderer} renderer\n */\n constructor(components, elements, definition, renderer) {\n super(elements, renderer)\n const questions = components.map(\n mapComponentToPreviewQuestion(questionRenderer, definition)\n )\n const firstQuestion = /** @type { Markdown | undefined | Question } */ (\n questions.shift()\n )\n this._guidanceComponent =\n PreviewPageController.getOrCreateGuidanceComponent(firstQuestion)\n this._guidanceText = elements.guidance\n this._components = this.#constructComponents(firstQuestion, questions)\n this._showTitle = elements.addHeading\n this._sectionTitle = elements.repeatQuestion ?? ''\n this._isRepeater = elements.hasRepeater\n }\n\n /**\n * @type {typeof PreviewPageControllerBase.HighlightClass}\n */\n static HighlightClass = PreviewPageControllerBase.HighlightClass\n\n /**\n * @param { Question | Markdown | undefined} firstQuestion\n * @param {Question[]} questions\n * @returns {Question[]}\n */\n #constructComponents(firstQuestion, questions) {\n return firstQuestion instanceof Markdown || firstQuestion === undefined\n ? questions\n : [firstQuestion, ...questions]\n }\n\n /**\n * @returns {PagePreviewComponent[]}\n */\n get components() {\n const componentsWithGuidance = /** @type {Question[]} */ ([\n ...this._guidanceComponents,\n ...this._components\n ])\n\n return componentsWithGuidance.map((component) => {\n return {\n model: this._overrideComponentHeading(component),\n questionType: component.componentType\n }\n })\n }\n\n /**\n * @returns {boolean}\n */\n get showLargeTitle() {\n const componentsLength =\n this._components.length + this._guidanceComponents.length\n\n if (componentsLength > 1 || this._highlighted === 'title') {\n return false\n }\n // |_ one component and title not highlighted\n if (this._title.trim() === this._components[0]?.question.trim()) {\n return true\n }\n // titles not the same\n\n return !this._showTitle // add page heading deselected?\n }\n\n /**\n * @param {PreviewComponent} component\n * @returns {QuestionBaseModel}\n */\n _overrideComponentHeading(component) {\n const largeTitle = this.showLargeTitle\n\n const fieldset = component.renderInput.fieldset\n ? {\n fieldset: {\n legend: {\n ...component.renderInput.fieldset.legend,\n classes: largeTitle\n ? 'govuk-fieldset__legend--l'\n : 'govuk-fieldset__legend--m'\n }\n }\n }\n : {}\n\n const label = component.renderInput.label\n ? {\n label: {\n ...component.renderInput.label,\n classes: largeTitle ? 'govuk-label--l' : 'govuk-label--m'\n }\n }\n : {}\n\n return {\n ...component.renderInput,\n ...fieldset,\n ...label\n }\n }\n\n /**\n * @returns {boolean}\n */\n get titleAndFirstTitleSame() {\n return (\n this._components.length > 0 &&\n this._title.trim() === this._components[0]?.question.trim() &&\n this.components.length === 1 &&\n this._highlighted !== 'title'\n )\n }\n\n /**\n * @returns {string}\n * @protected\n */\n _getTitle() {\n if (!this._showTitle || this.titleAndFirstTitleSame) {\n return ''\n }\n return super._getTitle()\n }\n\n /**\n * @returns {string}\n * @protected\n */\n _getGuidanceText() {\n if (!this._showTitle) {\n return ''\n }\n return super._getGuidanceText()\n }\n\n get repeaterText() {\n if (!this._isRepeater) {\n return undefined\n }\n if (!this._sectionTitle.length) {\n return 'Question set name'\n }\n return this._sectionTitle + ' 1'\n }\n\n /**\n * @returns {string|undefined}\n * @protected\n */\n _getSectionTitleText() {\n if (this._isRepeater) {\n return this.repeaterText\n }\n return undefined\n }\n\n get repeaterButton() {\n if (this.repeaterButtonText === undefined) {\n return undefined\n }\n return {\n classes: this._isHighlighted(\n PreviewPageControllerBase.HighlightClass.REPEATER\n ),\n text: this.repeaterButtonText\n }\n }\n\n get repeaterButtonText() {\n if (!this._isRepeater) {\n return undefined\n }\n\n if (this._sectionTitle === '') {\n return '[question set name]'\n }\n\n const [firstToken, ...rest] = this._sectionTitle\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const restOfStr = rest ? rest.join('') : ''\n return firstToken.toLowerCase() + restOfStr\n }\n\n /**\n * Helper method to return the guidance or a new one\n * @param { Markdown | Question | undefined } guidanceComponent\n * @returns {Markdown}\n * @private\n */\n static getOrCreateGuidanceComponent(guidanceComponent) {\n if (guidanceComponent instanceof Markdown) {\n return guidanceComponent\n }\n return PreviewPageControllerBase.createGuidanceComponent()\n }\n}\n\n/**\n * @import { PageRenderer, PageOverviewElements, QuestionRenderer, QuestionBaseModel } from '~/src/form/form-editor/preview/types.js'\n * @import { Question } from '~/src/form/form-editor/preview/question.js'\n * @import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\n * @import { FormDefinition, Page } from '~/src/form/form-definition/types.js'\n * @import { ComponentDef, MarkdownComponent } from '~/src/components/types.js'\n * @import { PagePreviewComponent, PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'\n */\n"],"mappings":"AAAA,SAASA,yBAAyB;AAClC,SAASC,6BAA6B;AACtC,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG;EACvB;AACF;AACA;AACA;EACEC,MAAMA,CAACC,iBAAiB,EAAEC,kBAAkB,EAAE;IAC5C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A,IAAI0B,cAAcA,CAAA,EAAG;IACnB,IAAI,IAAI,CAACC,kBAAkB,KAAK3B,SAAS,EAAE;MACzC,OAAOA,SAAS;IAClB;IACA,OAAO;MACLmB,OAAO,EAAE,IAAI,CAACS,cAAc,CAC1B5D,yBAAyB,CAAC8B,cAAc,CAAC+B,QAC3C,CAAC;MACDC,IAAI,EAAE,IAAI,CAACH;IACb,CAAC;EACH;EAEA,IAAIA,kBAAkBA,CAAA,EAAG;IACvB,IAAI,CAAC,IAAI,CAAC/B,WAAW,EAAE;MACrB,OAAOI,SAAS;IAClB;IAEA,IAAI,IAAI,CAACN,aAAa,KAAK,EAAE,EAAE;MAC7B,OAAO,qBAAqB;IAC9B;IAEA,MAAM,CAACqC,UAAU,EAAE,GAAGC,IAAI,CAAC,GAAG,IAAI,CAACtC,aAAa;IAChD;IACA,MAAMuC,SAAS,GAAGD,IAAI,GAAGA,IAAI,CAACE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;IAC3C,OAAOH,UAAU,CAACI,WAAW,CAAC,CAAC,GAAGF,SAAS;EAC7C;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAO7C,4BAA4BA,CAACgD,iBAAiB,EAAE;IACrD,IAAIA,iBAAiB,YAAYlE,QAAQ,EAAE;MACzC,OAAOkE,iBAAiB;IAC1B;IACA,OAAOpE,yBAAyB,CAACqE,uBAAuB,CAAC,CAAC;EAC5D;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
@@ -21,4 +21,6 @@ export * from "./long-answer.js";
|
|
21
21
|
export * from "./uk-address.js";
|
22
22
|
export * from "./yes-no.js";
|
23
23
|
export * from "./controller/page-controller.js";
|
24
|
+
export * from "./controller/guidance-page-controller.js";
|
25
|
+
export * from "./controller/page-controller-base.js";
|
24
26
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/form/form-editor/preview/index.js"],"sourcesContent":["export * from '~/src/form/form-editor/preview/autocomplete.js'\nexport * from '~/src/form/form-editor/preview/checkbox.js'\nexport * from '~/src/form/form-editor/preview/checkbox-sortable.js'\nexport * from '~/src/form/form-editor/preview/date-input.js'\nexport * from '~/src/form/form-editor/preview/email-address.js'\nexport * from '~/src/form/form-editor/preview/list.js'\nexport * from '~/src/form/form-editor/preview/list-sortable.js'\nexport * from '~/src/form/form-editor/preview/markdown.js'\nexport * from '~/src/form/form-editor/preview/month-year.js'\nexport * from '~/src/form/form-editor/preview/number-only.js'\nexport * from '~/src/form/form-editor/preview/phone-number.js'\nexport * from '~/src/form/form-editor/preview/question.js'\nexport * from '~/src/form/form-editor/preview/radio.js'\nexport * from '~/src/form/form-editor/preview/radio-sortable.js'\nexport * from '~/src/form/form-editor/preview/select-sortable.js'\nexport * from '~/src/form/form-editor/preview/short-answer.js'\nexport * from '~/src/form/form-editor/preview/select.js'\nexport * from '~/src/form/form-editor/preview/select-sortable.js'\nexport * from '~/src/form/form-editor/preview/supporting-evidence.js'\nexport * from '~/src/form/form-editor/preview/long-answer.js'\nexport * from '~/src/form/form-editor/preview/uk-address.js'\nexport * from '~/src/form/form-editor/preview/yes-no.js'\nexport * from '~/src/form/form-editor/preview/controller/page-controller.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/form/form-editor/preview/index.js"],"sourcesContent":["export * from '~/src/form/form-editor/preview/autocomplete.js'\nexport * from '~/src/form/form-editor/preview/checkbox.js'\nexport * from '~/src/form/form-editor/preview/checkbox-sortable.js'\nexport * from '~/src/form/form-editor/preview/date-input.js'\nexport * from '~/src/form/form-editor/preview/email-address.js'\nexport * from '~/src/form/form-editor/preview/list.js'\nexport * from '~/src/form/form-editor/preview/list-sortable.js'\nexport * from '~/src/form/form-editor/preview/markdown.js'\nexport * from '~/src/form/form-editor/preview/month-year.js'\nexport * from '~/src/form/form-editor/preview/number-only.js'\nexport * from '~/src/form/form-editor/preview/phone-number.js'\nexport * from '~/src/form/form-editor/preview/question.js'\nexport * from '~/src/form/form-editor/preview/radio.js'\nexport * from '~/src/form/form-editor/preview/radio-sortable.js'\nexport * from '~/src/form/form-editor/preview/select-sortable.js'\nexport * from '~/src/form/form-editor/preview/short-answer.js'\nexport * from '~/src/form/form-editor/preview/select.js'\nexport * from '~/src/form/form-editor/preview/select-sortable.js'\nexport * from '~/src/form/form-editor/preview/supporting-evidence.js'\nexport * from '~/src/form/form-editor/preview/long-answer.js'\nexport * from '~/src/form/form-editor/preview/uk-address.js'\nexport * from '~/src/form/form-editor/preview/yes-no.js'\nexport * from '~/src/form/form-editor/preview/controller/page-controller.js'\nexport * from '~/src/form/form-editor/preview/controller/guidance-page-controller.js'\nexport * from '~/src/form/form-editor/preview/controller/page-controller-base.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/preview/types.ts"],"sourcesContent":["import {\n type PagePreviewPanelMacro,\n type QuestionBaseModel\n} from '~/src/form/form-editor/macros/types.js'\nimport { type AutocompleteQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { type DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { type EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { type ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { type LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { type PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { type Question } from '~/src/form/form-editor/preview/question.js'\nimport { type RadioSortableQuestion } from '~/src/form/form-editor/preview/radio-sortable.js'\nimport { type SelectSortableQuestion } from '~/src/form/form-editor/preview/select-sortable.js'\nimport { type ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { type UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { type ListElement } from '~/src/form/form-editor/types.js'\nexport { type QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'\nexport interface BaseSettings {\n question: string\n hintText: string\n optional: boolean\n shortDesc: string\n items: ListElement[]\n content: string\n attributes?: Record<string, string>\n}\n\nexport interface DefaultComponent {\n id?: string\n text: string\n classes: string\n}\n\nexport interface GovukFieldset {\n legend: DefaultComponent\n}\n\nexport type ListenerRow = [\n HTMLInputElement | null,\n (target: HTMLInputElement, e: Event) => void,\n keyof HTMLElementEventMap\n]\n\nexport interface DomElementsBase {\n readonly values?: BaseSettings\n autocompleteOptions?: string\n setPreviewHTML(value: string): void\n setPreviewDOM(element: HTMLElement): void\n}\n\nexport interface QuestionElements extends DomElementsBase {\n readonly values: BaseSettings\n}\n\nexport interface AutocompleteElements extends QuestionElements {\n autocompleteOptions: string\n}\n\nexport interface RenderBase {\n render(questionTemplate: string, renderContext: RenderContext): void\n}\n\nexport interface QuestionRenderContext {\n model: QuestionBaseModel\n}\n\nexport interface PageRenderContext {\n params: PagePreviewPanelMacro\n}\n\nexport type RenderContext = QuestionRenderContext | PageRenderContext\n\nexport interface HTMLBuilder {\n buildHTML(questionTemplate: string, renderContext: RenderContext): string\n}\n\nexport interface QuestionRenderer {\n render(questionTemplate: string, questionBaseModel: QuestionBaseModel): void\n}\n\nexport interface PageRenderer {\n render(pageTemplate: string, pagePreview: PagePreviewPanelMacro): void\n}\n\nexport type Renderer = QuestionRenderer | PageRenderer\n\nexport interface ListElements extends QuestionElements {\n afterInputsHTML: string\n}\n\nexport interface
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/form/form-editor/preview/types.ts"],"sourcesContent":["import {\n type PagePreviewPanelMacro,\n type QuestionBaseModel\n} from '~/src/form/form-editor/macros/types.js'\nimport { type AutocompleteQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { type DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport { type EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { type ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'\nimport { type LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'\nimport { type PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { type Question } from '~/src/form/form-editor/preview/question.js'\nimport { type RadioSortableQuestion } from '~/src/form/form-editor/preview/radio-sortable.js'\nimport { type SelectSortableQuestion } from '~/src/form/form-editor/preview/select-sortable.js'\nimport { type ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { type UkAddressQuestion } from '~/src/form/form-editor/preview/uk-address.js'\nimport { type ListElement } from '~/src/form/form-editor/types.js'\nexport { type QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'\nexport interface BaseSettings {\n question: string\n hintText: string\n optional: boolean\n shortDesc: string\n items: ListElement[]\n content: string\n attributes?: Record<string, string>\n}\n\nexport interface DefaultComponent {\n id?: string\n text: string\n classes: string\n}\n\nexport interface GovukFieldset {\n legend: DefaultComponent\n}\n\nexport type ListenerRow = [\n HTMLInputElement | null,\n (target: HTMLInputElement, e: Event) => void,\n keyof HTMLElementEventMap\n]\n\nexport interface DomElementsBase {\n readonly values?: BaseSettings\n autocompleteOptions?: string\n setPreviewHTML(value: string): void\n setPreviewDOM(element: HTMLElement): void\n}\n\nexport interface QuestionElements extends DomElementsBase {\n readonly values: BaseSettings\n}\n\nexport interface AutocompleteElements extends QuestionElements {\n autocompleteOptions: string\n}\n\nexport interface RenderBase {\n render(questionTemplate: string, renderContext: RenderContext): void\n}\n\nexport interface QuestionRenderContext {\n model: QuestionBaseModel\n}\n\nexport interface PageRenderContext {\n params: PagePreviewPanelMacro\n}\n\nexport type RenderContext = QuestionRenderContext | PageRenderContext\n\nexport interface HTMLBuilder {\n buildHTML(questionTemplate: string, renderContext: RenderContext): string\n}\n\nexport interface QuestionRenderer {\n render(questionTemplate: string, questionBaseModel: QuestionBaseModel): void\n}\n\nexport interface PageRenderer {\n render(pageTemplate: string, pagePreview: PagePreviewPanelMacro): void\n}\n\nexport type Renderer = QuestionRenderer | PageRenderer\n\nexport interface ListElements extends QuestionElements {\n afterInputsHTML: string\n}\n\nexport interface PagePreviewBaseElements {\n heading: string\n guidance: string\n}\n\nexport interface PageOverviewElements extends PagePreviewBaseElements {\n addHeading: boolean\n repeatQuestion: string | undefined\n hasRepeater: boolean\n}\n\nexport type PreviewQuestion =\n | DateInputQuestion\n | EmailAddressQuestion\n | ListSortableQuestion\n | LongAnswerQuestion\n | PhoneNumberQuestion\n | Question\n | RadioSortableQuestion\n | SelectSortableQuestion\n | ShortAnswerQuestion\n | UkAddressQuestion\n | AutocompleteQuestion\n"],"mappings":"","ignoreList":[]}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { ComponentType
|
1
|
+
import { ComponentType } from "../components/enums.js";
|
2
|
+
import { hasFormField } from "../components/helpers.js";
|
2
3
|
import { ControllerNames, ControllerTypes } from "./controller-types.js";
|
3
4
|
import { ControllerType } from "./enums.js";
|
4
5
|
import { PageTypes } from "./page-types.js";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","omitFileUploadComponent","length","getPageTitle","title","firstComp"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport {
|
1
|
+
{"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","omitFileUploadComponent","length","getPageTitle","title","firstComp"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { hasFormField } from '~/src/components/helpers.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nfunction includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page) && includesFileUploadField(page.components)) {\n return false\n }\n return true\n}\n\n/**\n * High level check for whether file upload component should be omitted\n * @param { Page | undefined } page\n * @returns {boolean}\n */\nexport function omitFileUploadComponent(page: Page | undefined): boolean {\n if (page?.controller === ControllerType.Repeat) {\n return true\n }\n if (!hasComponents(page)) {\n return false\n }\n if (page.components.length > 1) {\n return true\n }\n if (includesFileUploadField(page.components)) {\n return true\n }\n return false\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY;AASrB,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CAAC;EAED,IAAI,CAACG,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CAAC,qCAAqCP,UAAU,GAAG,CAAC;EACrE;EAEA,OAAOQ,eAAe,CAACJ,QAAQ,CAAC;AAClC;;AAEA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAC3BV,IAAoB,EACmC;EACvD,OAAOW,OAAO,CAACX,IAAI,CAAC,IAAIY,KAAK,CAACC,OAAO,CAACb,IAAI,CAACc,UAAU,CAAC;AACxD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACvCf,IAAoB,EACmC;EACvD,OACEA,IAAI,KAAKgB,SAAS,IAAI,YAAY,IAAIhB,IAAI,IAAIY,KA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CAACwC,KAAK;EACnB;EAEA,IAAIzB,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,MAAMyC,SAAS,GAAGzC,IAAI,CAACc,UAAU,CAACR,IAAI,CAACZ,YAAY,CAAC;IACpD,IAAI+C,SAAS,EAAE;MACb,OAAOA,SAAS,CAACD,KAAK;IACxB;EACF;EACA,OAAO,oBAAoB;AAC7B","ignoreList":[]}
|
@@ -1,10 +1,24 @@
|
|
1
1
|
import { type PageFileUpload, type PageQuestion, type PageRepeat, type PageSummary } from '../form/form-definition/types.js';
|
2
|
+
import { ControllerType } from '../pages/enums.js';
|
2
3
|
/**
|
3
4
|
* Stub builder for a question page
|
4
5
|
* @param {Partial<PageQuestion>} [partialPage]
|
5
6
|
* @returns {PageQuestion}
|
6
7
|
*/
|
7
8
|
export declare function buildQuestionPage(partialPage: Partial<PageQuestion>): PageQuestion;
|
9
|
+
export declare const GUIDANCE_PAGE_CONTENT = "Lorem ipsum dolar sit amet";
|
10
|
+
export declare function buildGuidancePage(partialPage: Partial<PageQuestion>): {
|
11
|
+
controller?: ControllerType.Page | undefined;
|
12
|
+
section?: string | undefined | undefined;
|
13
|
+
next: import("../form/form-definition/types.js").Link[];
|
14
|
+
components: import("../index.js").ComponentDef[];
|
15
|
+
id: string;
|
16
|
+
title: string;
|
17
|
+
path: string;
|
18
|
+
condition?: string | undefined;
|
19
|
+
events?: import("../form/form-definition/types.js").Events | undefined;
|
20
|
+
view?: string | undefined;
|
21
|
+
};
|
8
22
|
/**
|
9
23
|
* Stub builder for a Summary page
|
10
24
|
* @param {Partial<PageSummary>} [partialSummaryPage]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../../src/__stubs__/pages.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../../src/__stubs__/pages.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAkB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,GACjC,YAAY,CASd;AAED,eAAO,MAAM,qBAAqB,+BAA+B,CAAA;AACjE,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC;iBAoB/D,eAAiB,IAAG;;;;;;;;;;EAPxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,kBAAkB,GAAE,OAAO,CAAC,WAAW,CAAM,GAC5C,WAAW,CAQb;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,qBAAqB,GAAE,OAAO,CAAC,cAAc,CAAM,GAClD,cAAc,CAwBhB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,mBAAmB,GAAE,OAAO,CAAC,UAAU,CAAM,GAC5C,UAAU,CAyBZ"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export class GuidancePageController extends PreviewPageControllerBase {
|
2
|
+
/**
|
3
|
+
* @type {Markdown}
|
4
|
+
* @protected
|
5
|
+
*/
|
6
|
+
protected _unhighlightedEmptyGuidance: Markdown;
|
7
|
+
}
|
8
|
+
import { PreviewPageControllerBase } from '../../../../form/form-editor/preview/controller/page-controller-base.js';
|
9
|
+
import type { Markdown } from '../../../../form/form-editor/preview/markdown.js';
|
10
|
+
//# sourceMappingURL=guidance-page-controller.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"guidance-page-controller.d.ts","sourceRoot":"","sources":["../../../../../../src/form/form-editor/preview/controller/guidance-page-controller.js"],"names":[],"mappings":"AAIA;IACE;;;OAGG;IACH,uCAHU,QAAQ,CAIwC;CAgD3D;0CA1DyC,mEAAmE;8BA6DhF,4CAA4C"}
|