@defra/forms-model 3.0.567 → 3.0.568
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-editor/__stubs__/preview.js +128 -1
- package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
- package/dist/module/form/form-editor/index.js +1 -1
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/macros/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/component-elements.js +1 -0
- package/dist/module/form/form-editor/preview/component-elements.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +3 -1
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
- package/dist/module/form/form-editor/preview/number-only.js +75 -3
- package/dist/module/form/form-editor/preview/number-only.js.map +1 -1
- package/dist/module/form/form-editor/preview/question.js +30 -3
- package/dist/module/form/form-editor/preview/question.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts +71 -1
- 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 +7 -0
- package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/component-elements.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/number-only.d.ts +123 -0
- package/dist/types/form/form-editor/preview/number-only.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/question.d.ts +13 -0
- package/dist/types/form/form-editor/preview/question.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/types.d.ts +8 -0
- package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/uk-address.d.ts +7 -0
- package/dist/types/form/form-editor/preview/uk-address.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/form/form-editor/__stubs__/preview.js +130 -1
- package/src/form/form-editor/index.ts +4 -1
- package/src/form/form-editor/macros/types.ts +3 -0
- package/src/form/form-editor/preview/component-elements.js +4 -0
- package/src/form/form-editor/preview/helpers.js +6 -1
- package/src/form/form-editor/preview/number-only.js +72 -3
- package/src/form/form-editor/preview/question.js +33 -3
- package/src/form/form-editor/preview/types.ts +10 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uk-address.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/uk-address.js"],"names":[],"mappings":"AAKA;;GAEG;AACH;IACE;;OAEG;IACH,uBAFW,uBAAuB,EAKjC;IADC,wCAA6D;CAahE;AAED;IAOE,4BAA0B;IAe1B;;OAEG;IACH,2BAFW,OAAO,EAKjB;IAVD,yBAKW,OAAO,CAHjB;IAUD;;OAEG;IACH
|
|
1
|
+
{"version":3,"file":"uk-address.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/uk-address.js"],"names":[],"mappings":"AAKA;;GAEG;AACH;IACE;;OAEG;IACH,uBAFW,uBAAuB,EAKjC;IADC,wCAA6D;CAahE;AAED;IAOE,4BAA0B;IAe1B;;OAEG;IACH,2BAFW,OAAO,EAKjB;IAVD,yBAKW,OAAO,CAHjB;IAUD;;OAEG;IACH;;;;;;;;;;;;;;;;;;;;;MAKC;CACF;sCAGoE,yCAAyC;0CApEpE,4CAA4C;6CAqE1C,2BAA2B;iCAvEtC,qDAAqD"}
|
package/package.json
CHANGED
|
@@ -85,6 +85,11 @@ export class QuestionPreviewElements {
|
|
|
85
85
|
* @protected
|
|
86
86
|
*/
|
|
87
87
|
_shortDesc = ''
|
|
88
|
+
/**
|
|
89
|
+
* @type {string}
|
|
90
|
+
* @protected
|
|
91
|
+
*/
|
|
92
|
+
_userClasses = ''
|
|
88
93
|
/**
|
|
89
94
|
* @type {string}
|
|
90
95
|
* @protected
|
|
@@ -111,6 +116,7 @@ export class QuestionPreviewElements {
|
|
|
111
116
|
hintText,
|
|
112
117
|
optional,
|
|
113
118
|
shortDesc,
|
|
119
|
+
userClasses,
|
|
114
120
|
usePostcodeLookup,
|
|
115
121
|
items,
|
|
116
122
|
content
|
|
@@ -119,6 +125,7 @@ export class QuestionPreviewElements {
|
|
|
119
125
|
this._hintText = hintText
|
|
120
126
|
this._optional = optional
|
|
121
127
|
this._shortDesc = shortDesc
|
|
128
|
+
this._userClasses = userClasses
|
|
122
129
|
this._items = items
|
|
123
130
|
this._content = content
|
|
124
131
|
this._usePostcodeLookup = usePostcodeLookup ?? false
|
|
@@ -133,6 +140,7 @@ export class QuestionPreviewElements {
|
|
|
133
140
|
hintText: this._hintText,
|
|
134
141
|
optional: this._optional,
|
|
135
142
|
shortDesc: this._shortDesc,
|
|
143
|
+
userClasses: this._userClasses,
|
|
136
144
|
usePostcodeLookup: this._usePostcodeLookup,
|
|
137
145
|
items: this._items,
|
|
138
146
|
content: this._content
|
|
@@ -204,11 +212,25 @@ export const baseElements = /** @type {BaseSettings} */ ({
|
|
|
204
212
|
optional: false,
|
|
205
213
|
question: 'Which quest would you like to pick?',
|
|
206
214
|
hintText: 'Choose one adventure that best suits you.',
|
|
215
|
+
userClasses: '',
|
|
207
216
|
shortDesc: '',
|
|
208
217
|
content: '',
|
|
209
218
|
largeTitle: true
|
|
210
219
|
})
|
|
211
220
|
|
|
221
|
+
export const numberElements = /** @type {NumberSettings} */ ({
|
|
222
|
+
items: [],
|
|
223
|
+
optional: false,
|
|
224
|
+
question: 'Which quest would you like to pick?',
|
|
225
|
+
hintText: 'Choose one adventure that best suits you.',
|
|
226
|
+
userClasses: '',
|
|
227
|
+
shortDesc: '',
|
|
228
|
+
content: '',
|
|
229
|
+
largeTitle: true,
|
|
230
|
+
prefix: '',
|
|
231
|
+
suffix: ''
|
|
232
|
+
})
|
|
233
|
+
|
|
212
234
|
const list1Id = '414d82a3-4cab-416a-bd54-6b86fbd51120'
|
|
213
235
|
const list2Id = '801385a4-81e6-4171-96c3-6c6727d97f22'
|
|
214
236
|
const list3Id = 'e6e3f621-b875-4ca3-a054-cca9149149dd'
|
|
@@ -267,8 +289,115 @@ export function buildPreviewShortAnswer(partialBaseElements, renderMock) {
|
|
|
267
289
|
)
|
|
268
290
|
}
|
|
269
291
|
|
|
292
|
+
export class NumberPreviewElements {
|
|
293
|
+
/**
|
|
294
|
+
* @protected
|
|
295
|
+
*/
|
|
296
|
+
_question = ''
|
|
297
|
+
/** @protected */
|
|
298
|
+
_hintText = ''
|
|
299
|
+
/** @protected */
|
|
300
|
+
_optional = false
|
|
301
|
+
/**
|
|
302
|
+
* @type {string}
|
|
303
|
+
* @protected
|
|
304
|
+
*/
|
|
305
|
+
_shortDesc = ''
|
|
306
|
+
/**
|
|
307
|
+
* @type {string}
|
|
308
|
+
* @protected
|
|
309
|
+
*/
|
|
310
|
+
_userClasses = ''
|
|
311
|
+
/**
|
|
312
|
+
* @type {string}
|
|
313
|
+
* @protected
|
|
314
|
+
*/
|
|
315
|
+
_prefix = ''
|
|
316
|
+
/**
|
|
317
|
+
* @type {string}
|
|
318
|
+
* @protected
|
|
319
|
+
*/
|
|
320
|
+
_suffix = ''
|
|
321
|
+
/**
|
|
322
|
+
* @type {string}
|
|
323
|
+
* @protected
|
|
324
|
+
*/
|
|
325
|
+
_content = ''
|
|
326
|
+
/**
|
|
327
|
+
*
|
|
328
|
+
* @type {ListElement[]}
|
|
329
|
+
* @private
|
|
330
|
+
*/
|
|
331
|
+
_items = []
|
|
332
|
+
/**
|
|
333
|
+
* @protected
|
|
334
|
+
* @type {boolean}
|
|
335
|
+
*/
|
|
336
|
+
_usePostcodeLookup = false
|
|
337
|
+
afterInputsHTML = '<div class="govuk-inset-text">No items added yet.</div>'
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @param {NumberSettings} baseSettings
|
|
341
|
+
*/
|
|
342
|
+
constructor({
|
|
343
|
+
question,
|
|
344
|
+
hintText,
|
|
345
|
+
optional,
|
|
346
|
+
shortDesc,
|
|
347
|
+
userClasses,
|
|
348
|
+
prefix,
|
|
349
|
+
suffix,
|
|
350
|
+
usePostcodeLookup,
|
|
351
|
+
items,
|
|
352
|
+
content
|
|
353
|
+
}) {
|
|
354
|
+
this._question = question
|
|
355
|
+
this._hintText = hintText
|
|
356
|
+
this._optional = optional
|
|
357
|
+
this._shortDesc = shortDesc
|
|
358
|
+
this._userClasses = userClasses
|
|
359
|
+
this._prefix = prefix
|
|
360
|
+
this._suffix = suffix
|
|
361
|
+
this._items = items
|
|
362
|
+
this._content = content
|
|
363
|
+
this._usePostcodeLookup = usePostcodeLookup ?? false
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @returns {NumberSettings}
|
|
368
|
+
*/
|
|
369
|
+
get values() {
|
|
370
|
+
return {
|
|
371
|
+
question: this._question,
|
|
372
|
+
hintText: this._hintText,
|
|
373
|
+
optional: this._optional,
|
|
374
|
+
shortDesc: this._shortDesc,
|
|
375
|
+
userClasses: this._userClasses,
|
|
376
|
+
prefix: this._prefix,
|
|
377
|
+
suffix: this._suffix,
|
|
378
|
+
usePostcodeLookup: this._usePostcodeLookup,
|
|
379
|
+
items: this._items,
|
|
380
|
+
content: this._content
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @param {string} _value
|
|
386
|
+
*/
|
|
387
|
+
setPreviewHTML(_value) {
|
|
388
|
+
// Not implemented for server side render
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @param {HTMLElement} _value
|
|
393
|
+
*/
|
|
394
|
+
setPreviewDOM(_value) {
|
|
395
|
+
// Not implemented for server side render
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
270
399
|
/**
|
|
271
400
|
* @import { ListElement } from '~/src/form/form-editor/types.js'
|
|
272
401
|
* @import { PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'
|
|
273
|
-
* @import { BaseSettings, ListElements, RenderContext, QuestionBaseModel,
|
|
402
|
+
* @import { BaseSettings, ListElements, NumberSettings, RenderContext, QuestionBaseModel, QuestionRenderer, AutocompleteElements, PageOverviewElements, PageRenderer } from '~/src/form/form-editor/preview/types.js'
|
|
274
403
|
*/
|
|
@@ -55,6 +55,9 @@ export interface QuestionBaseModel {
|
|
|
55
55
|
formGroup?: FormGroupAfterInput
|
|
56
56
|
type?: 'text' | 'number' | 'boolean'
|
|
57
57
|
classes?: string
|
|
58
|
+
previewClasses?: string
|
|
59
|
+
prefix?: { text: string }
|
|
60
|
+
suffix?: { text: string }
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export interface AppPreviewPanelMacro extends AppPreviewPanelTabsMacro {
|
|
@@ -26,6 +26,10 @@ export class ComponentElements {
|
|
|
26
26
|
hintText: '',
|
|
27
27
|
optional: !required,
|
|
28
28
|
shortDesc: '',
|
|
29
|
+
userClasses:
|
|
30
|
+
this._component.options && 'classes' in this._component.options
|
|
31
|
+
? (this._component.options.classes ?? '')
|
|
32
|
+
: '',
|
|
29
33
|
items: [],
|
|
30
34
|
content: ''
|
|
31
35
|
}
|
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
import { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'
|
|
20
20
|
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
|
21
21
|
import { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
NumberComponentPreviewElements,
|
|
24
|
+
NumberOnlyQuestion
|
|
25
|
+
} from '~/src/form/form-editor/preview/number-only.js'
|
|
23
26
|
import { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'
|
|
24
27
|
import { QuestionComponentElements } from '~/src/form/form-editor/preview/question.js'
|
|
25
28
|
import { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'
|
|
@@ -78,6 +81,8 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
|
78
81
|
questionElements = new SelectComponentElements(component, list)
|
|
79
82
|
} else if (component.type === ComponentType.UkAddressField) {
|
|
80
83
|
questionElements = new UkAddressComponentPreviewElements(component)
|
|
84
|
+
} else if (component.type === ComponentType.NumberField) {
|
|
85
|
+
questionElements = new NumberComponentPreviewElements(component)
|
|
81
86
|
} else if (hasSelectionFields(component) && hasListField(component)) {
|
|
82
87
|
const list = findDefinitionListFromComponent(component, definition)
|
|
83
88
|
questionElements = new ListComponentElements(component, list)
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import { ComponentType } from '~/src/components/enums.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Question,
|
|
4
|
+
QuestionComponentElements
|
|
5
|
+
} from '~/src/form/form-editor/preview/question.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @implements {QuestionElements}
|
|
9
|
+
*/
|
|
10
|
+
export class NumberComponentPreviewElements extends QuestionComponentElements {
|
|
11
|
+
/**
|
|
12
|
+
* @param {NumberFieldComponent} component
|
|
13
|
+
*/
|
|
14
|
+
constructor(component) {
|
|
15
|
+
super(component)
|
|
16
|
+
this._prefix = component.options.prefix
|
|
17
|
+
this._suffix = component.options.suffix
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @protected
|
|
22
|
+
* @returns {NumberSettings}
|
|
23
|
+
*/
|
|
24
|
+
_getValues() {
|
|
25
|
+
return {
|
|
26
|
+
...super._getValues(),
|
|
27
|
+
prefix: this._prefix ?? '',
|
|
28
|
+
suffix: this._suffix ?? ''
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
3
32
|
|
|
4
33
|
export class NumberOnlyQuestion extends Question {
|
|
5
34
|
/**
|
|
@@ -8,12 +37,14 @@ export class NumberOnlyQuestion extends Question {
|
|
|
8
37
|
componentType = ComponentType.NumberField
|
|
9
38
|
|
|
10
39
|
/**
|
|
11
|
-
* @param {
|
|
40
|
+
* @param {NumberElements} htmlElements
|
|
12
41
|
* @param {QuestionRenderer} questionRenderer
|
|
13
42
|
*/
|
|
14
43
|
constructor(htmlElements, questionRenderer) {
|
|
15
44
|
super(htmlElements, questionRenderer)
|
|
16
45
|
this._fieldName = 'numberField'
|
|
46
|
+
this._prefix = htmlElements.values.prefix
|
|
47
|
+
this._suffix = htmlElements.values.suffix
|
|
17
48
|
}
|
|
18
49
|
|
|
19
50
|
/**
|
|
@@ -24,8 +55,46 @@ export class NumberOnlyQuestion extends Question {
|
|
|
24
55
|
type: 'number'
|
|
25
56
|
}
|
|
26
57
|
}
|
|
58
|
+
|
|
59
|
+
get prefix() {
|
|
60
|
+
return this._prefix
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} val
|
|
65
|
+
*/
|
|
66
|
+
set prefix(val) {
|
|
67
|
+
this._prefix = val
|
|
68
|
+
this.render()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get suffix() {
|
|
72
|
+
return this._suffix
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} val
|
|
77
|
+
*/
|
|
78
|
+
set suffix(val) {
|
|
79
|
+
this._suffix = val
|
|
80
|
+
this.render()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
86
|
+
_renderInput() {
|
|
87
|
+
const prefixObj = this.prefix ? { prefix: { text: this.prefix } } : {}
|
|
88
|
+
const suffixObj = this.suffix ? { suffix: { text: this.suffix } } : {}
|
|
89
|
+
return {
|
|
90
|
+
...super._renderInput(),
|
|
91
|
+
...prefixObj,
|
|
92
|
+
...suffixObj
|
|
93
|
+
}
|
|
94
|
+
}
|
|
27
95
|
}
|
|
28
96
|
|
|
29
97
|
/**
|
|
30
|
-
* @import {
|
|
98
|
+
* @import { NumberSettings, NumberElements, QuestionBaseModel, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
|
99
|
+
* @import { NumberFieldComponent } from '~/src/components/types.js'
|
|
31
100
|
*/
|
|
@@ -27,7 +27,8 @@ export class QuestionComponentElements extends ComponentElements {
|
|
|
27
27
|
return {
|
|
28
28
|
...super._getValues(),
|
|
29
29
|
hintText: this._component.hint ?? '',
|
|
30
|
-
shortDesc: this._component.shortDescription ?? ''
|
|
30
|
+
shortDesc: this._component.shortDescription ?? '',
|
|
31
|
+
userClasses: this._component.options.classes ?? ''
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -65,12 +66,17 @@ export class Question extends PreviewComponent {
|
|
|
65
66
|
*/
|
|
66
67
|
constructor(htmlElements, questionRenderer) {
|
|
67
68
|
super(htmlElements, questionRenderer)
|
|
68
|
-
const { hintText } = htmlElements.values
|
|
69
|
+
const { hintText, userClasses } = htmlElements.values
|
|
69
70
|
/**
|
|
70
71
|
* @type {string}
|
|
71
72
|
* @private
|
|
72
73
|
*/
|
|
73
74
|
this._hintText = hintText
|
|
75
|
+
/**
|
|
76
|
+
* @type {string}
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
this._userClasses = userClasses
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -94,7 +100,16 @@ export class Question extends PreviewComponent {
|
|
|
94
100
|
* @protected
|
|
95
101
|
*/
|
|
96
102
|
_renderInput() {
|
|
97
|
-
|
|
103
|
+
const renderValues = {
|
|
104
|
+
...super._renderInput(),
|
|
105
|
+
label: this.label,
|
|
106
|
+
hint: this.hint
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...renderValues,
|
|
110
|
+
classes: this._userClasses,
|
|
111
|
+
previewClasses: renderValues.classes ?? ''
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
/**
|
|
@@ -111,6 +126,21 @@ export class Question extends PreviewComponent {
|
|
|
111
126
|
this._hintText = value
|
|
112
127
|
this.render()
|
|
113
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @type {string}
|
|
132
|
+
*/
|
|
133
|
+
get userClasses() {
|
|
134
|
+
return this._userClasses
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} value
|
|
139
|
+
*/
|
|
140
|
+
set userClasses(value) {
|
|
141
|
+
this._userClasses = value
|
|
142
|
+
this.render()
|
|
143
|
+
}
|
|
114
144
|
}
|
|
115
145
|
|
|
116
146
|
/**
|
|
@@ -20,6 +20,7 @@ export interface BaseSettings {
|
|
|
20
20
|
hintText: string
|
|
21
21
|
optional: boolean
|
|
22
22
|
shortDesc: string
|
|
23
|
+
userClasses: string
|
|
23
24
|
items: ListElement[]
|
|
24
25
|
content: string
|
|
25
26
|
attributes?: Record<string, string>
|
|
@@ -58,6 +59,15 @@ export interface AutocompleteElements extends QuestionElements {
|
|
|
58
59
|
autocompleteOptions: string
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
export interface NumberSettings extends BaseSettings {
|
|
63
|
+
prefix: string
|
|
64
|
+
suffix: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface NumberElements extends DomElementsBase {
|
|
68
|
+
readonly values: NumberSettings
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
export interface RenderBase {
|
|
62
72
|
render(questionTemplate: string, renderContext: RenderContext): void
|
|
63
73
|
}
|