@defra/forms-model 3.0.580 → 3.0.582

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.
Files changed (89) hide show
  1. package/dist/module/__stubs__/components.js +46 -0
  2. package/dist/module/__stubs__/components.js.map +1 -1
  3. package/dist/module/components/component-types.js +8 -1
  4. package/dist/module/components/component-types.js.map +1 -1
  5. package/dist/module/components/enums.js +1 -0
  6. package/dist/module/components/enums.js.map +1 -1
  7. package/dist/module/components/types.js.map +1 -1
  8. package/dist/module/conditions/condition-operators.js +2 -1
  9. package/dist/module/conditions/condition-operators.js.map +1 -1
  10. package/dist/module/form/form-definition/helpers.js +19 -0
  11. package/dist/module/form/form-definition/helpers.js.map +1 -1
  12. package/dist/module/form/form-editor/__stubs__/preview.js +27 -1
  13. package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
  14. package/dist/module/form/form-editor/index.js +1 -1
  15. package/dist/module/form/form-editor/index.js.map +1 -1
  16. package/dist/module/form/form-editor/macros/types.js.map +1 -1
  17. package/dist/module/form/form-editor/preview/easting-northing.js +42 -0
  18. package/dist/module/form/form-editor/preview/easting-northing.js.map +1 -0
  19. package/dist/module/form/form-editor/preview/helpers.js +28 -5
  20. package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
  21. package/dist/module/form/form-editor/preview/hidden.js +9 -0
  22. package/dist/module/form/form-editor/preview/hidden.js.map +1 -0
  23. package/dist/module/form/form-editor/preview/index.js +5 -0
  24. package/dist/module/form/form-editor/preview/index.js.map +1 -1
  25. package/dist/module/form/form-editor/preview/lat-long.js +42 -0
  26. package/dist/module/form/form-editor/preview/lat-long.js.map +1 -0
  27. package/dist/module/form/form-editor/preview/location-helpers.js +44 -0
  28. package/dist/module/form/form-editor/preview/location-helpers.js.map +1 -0
  29. package/dist/module/form/form-editor/preview/location-question-base.js +62 -0
  30. package/dist/module/form/form-editor/preview/location-question-base.js.map +1 -0
  31. package/dist/module/form/form-editor/preview/national-grid.js +46 -0
  32. package/dist/module/form/form-editor/preview/national-grid.js.map +1 -0
  33. package/dist/module/form/form-editor/preview/os-grid-ref.js +46 -0
  34. package/dist/module/form/form-editor/preview/os-grid-ref.js.map +1 -0
  35. package/dist/module/form/form-editor/preview/types.js.map +1 -1
  36. package/dist/types/__stubs__/components.d.ts +5 -1
  37. package/dist/types/__stubs__/components.d.ts.map +1 -1
  38. package/dist/types/components/component-types.d.ts.map +1 -1
  39. package/dist/types/components/enums.d.ts +2 -1
  40. package/dist/types/components/enums.d.ts.map +1 -1
  41. package/dist/types/components/types.d.ts +7 -1
  42. package/dist/types/components/types.d.ts.map +1 -1
  43. package/dist/types/conditions/condition-operators.d.ts +1 -0
  44. package/dist/types/conditions/condition-operators.d.ts.map +1 -1
  45. package/dist/types/form/form-definition/helpers.d.ts +6 -0
  46. package/dist/types/form/form-definition/helpers.d.ts.map +1 -1
  47. package/dist/types/form/form-editor/__stubs__/preview.d.ts +18 -0
  48. package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
  49. package/dist/types/form/form-editor/index.d.ts.map +1 -1
  50. package/dist/types/form/form-editor/macros/types.d.ts +50 -0
  51. package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
  52. package/dist/types/form/form-editor/preview/easting-northing.d.ts +17 -0
  53. package/dist/types/form/form-editor/preview/easting-northing.d.ts.map +1 -0
  54. package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
  55. package/dist/types/form/form-editor/preview/hidden.d.ts +4 -0
  56. package/dist/types/form/form-editor/preview/hidden.d.ts.map +1 -0
  57. package/dist/types/form/form-editor/preview/index.d.ts +5 -0
  58. package/dist/types/form/form-editor/preview/lat-long.d.ts +17 -0
  59. package/dist/types/form/form-editor/preview/lat-long.d.ts.map +1 -0
  60. package/dist/types/form/form-editor/preview/location-helpers.d.ts +23 -0
  61. package/dist/types/form/form-editor/preview/location-helpers.d.ts.map +1 -0
  62. package/dist/types/form/form-editor/preview/location-question-base.d.ts +43 -0
  63. package/dist/types/form/form-editor/preview/location-question-base.d.ts.map +1 -0
  64. package/dist/types/form/form-editor/preview/national-grid.d.ts +17 -0
  65. package/dist/types/form/form-editor/preview/national-grid.d.ts.map +1 -0
  66. package/dist/types/form/form-editor/preview/os-grid-ref.d.ts +17 -0
  67. package/dist/types/form/form-editor/preview/os-grid-ref.d.ts.map +1 -0
  68. package/dist/types/form/form-editor/preview/types.d.ts +21 -2
  69. package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
  70. package/package.json +1 -1
  71. package/src/__stubs__/components.ts +62 -0
  72. package/src/components/component-types.ts +9 -1
  73. package/src/components/enums.ts +2 -1
  74. package/src/components/types.ts +8 -0
  75. package/src/conditions/condition-operators.ts +2 -1
  76. package/src/form/form-definition/helpers.ts +23 -0
  77. package/src/form/form-editor/__stubs__/preview.js +24 -1
  78. package/src/form/form-editor/index.ts +1 -0
  79. package/src/form/form-editor/macros/types.ts +54 -0
  80. package/src/form/form-editor/preview/easting-northing.js +55 -0
  81. package/src/form/form-editor/preview/helpers.js +42 -5
  82. package/src/form/form-editor/preview/hidden.js +9 -0
  83. package/src/form/form-editor/preview/index.js +5 -0
  84. package/src/form/form-editor/preview/lat-long.js +55 -0
  85. package/src/form/form-editor/preview/location-helpers.js +49 -0
  86. package/src/form/form-editor/preview/location-question-base.js +65 -0
  87. package/src/form/form-editor/preview/national-grid.js +56 -0
  88. package/src/form/form-editor/preview/os-grid-ref.js +56 -0
  89. package/src/form/form-editor/preview/types.ts +24 -2
@@ -0,0 +1,55 @@
1
+ import { ComponentType } from '~/src/components/enums.js'
2
+ import {
3
+ createFieldClasses,
4
+ createLocationFieldModel
5
+ } from '~/src/form/form-editor/preview/location-helpers.js'
6
+ import {
7
+ LocationQuestion,
8
+ LocationQuestionComponentPreviewElements
9
+ } from '~/src/form/form-editor/preview/location-question-base.js'
10
+ import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
11
+
12
+ /**
13
+ * @implements {QuestionElements}
14
+ */
15
+ export class LatLongComponentPreviewElements extends LocationQuestionComponentPreviewElements {}
16
+
17
+ export class LatLongQuestion extends LocationQuestion {
18
+ /**
19
+ * @type {ComponentType}
20
+ */
21
+ componentType = ComponentType.LatLongField
22
+ /**
23
+ * @type {string}
24
+ * @protected
25
+ */
26
+ _questionTemplate = PreviewComponent.PATH + 'latlongfield.njk'
27
+ _fieldName = 'LatLongField'
28
+
29
+ /**
30
+ * @protected
31
+ * @returns {LatLongModel}
32
+ */
33
+ _renderInput() {
34
+ const baseModel = super._renderInput()
35
+ const locationModel = createLocationFieldModel(
36
+ baseModel,
37
+ /** @type {LocationElements} */ (this._htmlElements),
38
+ this._highlight,
39
+ this._instructionText,
40
+ this.titleText
41
+ )
42
+
43
+ return {
44
+ ...locationModel,
45
+ latitude: createFieldClasses('latitude', this._highlight),
46
+ longitude: createFieldClasses('longitude', this._highlight)
47
+ }
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @import { LocationSettings, LocationElements, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
53
+ * @import { LatLongModel } from '~/src/form/form-editor/macros/types.js'
54
+ * @import { LatLongFieldComponent } from '~/src/components/types.js'
55
+ */
@@ -0,0 +1,49 @@
1
+ import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
2
+
3
+ /**
4
+ * Creates the standard location field model with common properties
5
+ * @param {QuestionBaseModel} baseModel - The base model from super._renderInput()
6
+ * @param {LocationElements} htmlElements - The HTML elements containing values
7
+ * @param {string | null} highlight - The currently highlighted element
8
+ * @param {string} instructionText - The instruction text to display
9
+ * @param {string} titleText - The title text including optional suffix
10
+ * @returns {LocationFieldModel}
11
+ */
12
+ export function createLocationFieldModel(
13
+ baseModel,
14
+ htmlElements,
15
+ highlight,
16
+ instructionText,
17
+ titleText
18
+ ) {
19
+ return {
20
+ ...baseModel,
21
+ userClasses: htmlElements.values.userClasses,
22
+ fieldset: {
23
+ legend: {
24
+ text: titleText,
25
+ classes: highlight === 'question' ? HIGHLIGHT_CLASS : ''
26
+ }
27
+ },
28
+ instructionText,
29
+ details: {
30
+ classes: highlight === 'instructionText' ? HIGHLIGHT_CLASS : ''
31
+ }
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Creates field classes with highlight if needed
37
+ * @param {string} fieldName - The name of the field
38
+ * @param {string | null} highlight - The currently highlighted element
39
+ * @returns {{classes: string}}
40
+ */
41
+ export function createFieldClasses(fieldName, highlight) {
42
+ return {
43
+ classes: highlight === fieldName ? HIGHLIGHT_CLASS : ''
44
+ }
45
+ }
46
+
47
+ /**
48
+ * @import { LocationElements, QuestionBaseModel, LocationFieldModel } from '~/src/form/form-editor/preview/types.js'
49
+ */
@@ -0,0 +1,65 @@
1
+ import {
2
+ Question,
3
+ QuestionComponentElements
4
+ } from '~/src/form/form-editor/preview/question.js'
5
+
6
+ /**
7
+ * Base class for location question component preview elements with instruction text support
8
+ * @implements {QuestionElements}
9
+ */
10
+ export class LocationQuestionComponentPreviewElements extends QuestionComponentElements {
11
+ /**
12
+ * @param {any} component - Component with options.instructionText
13
+ */
14
+ constructor(component) {
15
+ super(component)
16
+ this._instructionText = component.options.instructionText ?? ''
17
+ }
18
+
19
+ /**
20
+ * @protected
21
+ * @returns {LocationSettings}
22
+ */
23
+ _getValues() {
24
+ return {
25
+ ...super._getValues(),
26
+ instructionText: this._instructionText
27
+ }
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Base class for location questions with instruction text support
33
+ */
34
+ export class LocationQuestion extends Question {
35
+ /**
36
+ * @type {string}
37
+ * @protected
38
+ */
39
+ _instructionText = ''
40
+
41
+ /**
42
+ * @param {LocationElements} htmlElements
43
+ * @param {QuestionRenderer} questionRenderer
44
+ */
45
+ constructor(htmlElements, questionRenderer) {
46
+ super(htmlElements, questionRenderer)
47
+ this._instructionText = htmlElements.values.instructionText
48
+ }
49
+
50
+ get instructionText() {
51
+ return this._instructionText
52
+ }
53
+
54
+ /**
55
+ * @param {string} val
56
+ */
57
+ set instructionText(val) {
58
+ this._instructionText = val
59
+ this.render()
60
+ }
61
+ }
62
+
63
+ /**
64
+ * @import { LocationSettings, LocationElements, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
65
+ */
@@ -0,0 +1,56 @@
1
+ import { ComponentType } from '~/src/components/enums.js'
2
+ import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
3
+ import { createLocationFieldModel } from '~/src/form/form-editor/preview/location-helpers.js'
4
+ import {
5
+ LocationQuestion,
6
+ LocationQuestionComponentPreviewElements
7
+ } from '~/src/form/form-editor/preview/location-question-base.js'
8
+ import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
9
+
10
+ /**
11
+ * @implements {QuestionElements}
12
+ */
13
+ export class NationalGridComponentPreviewElements extends LocationQuestionComponentPreviewElements {}
14
+
15
+ export class NationalGridQuestion extends LocationQuestion {
16
+ /**
17
+ * @type {ComponentType}
18
+ */
19
+ componentType = ComponentType.NationalGridFieldNumberField
20
+ /**
21
+ * @type {string}
22
+ * @protected
23
+ */
24
+ _questionTemplate = PreviewComponent.PATH + 'nationalgridfieldnumberfield.njk'
25
+ _fieldName = 'NationalGridFieldNumberField'
26
+
27
+ /**
28
+ * @protected
29
+ * @returns {NationalGridModel}
30
+ */
31
+ _renderInput() {
32
+ const baseModel = super._renderInput()
33
+ const locationModel = createLocationFieldModel(
34
+ baseModel,
35
+ /** @type {LocationElements} */ (this._htmlElements),
36
+ this._highlight,
37
+ this._instructionText,
38
+ this.titleText
39
+ )
40
+
41
+ return {
42
+ ...locationModel,
43
+ label: {
44
+ text: this.titleText,
45
+ classes: this._highlight === 'question' ? HIGHLIGHT_CLASS : ''
46
+ },
47
+ inputClasses: this._highlight === 'input' ? HIGHLIGHT_CLASS : ''
48
+ }
49
+ }
50
+ }
51
+
52
+ /**
53
+ * @import { LocationSettings, LocationElements, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
54
+ * @import { NationalGridModel } from '~/src/form/form-editor/macros/types.js'
55
+ * @import { NationalGridFieldNumberFieldComponent } from '~/src/components/types.js'
56
+ */
@@ -0,0 +1,56 @@
1
+ import { ComponentType } from '~/src/components/enums.js'
2
+ import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
3
+ import { createLocationFieldModel } from '~/src/form/form-editor/preview/location-helpers.js'
4
+ import {
5
+ LocationQuestion,
6
+ LocationQuestionComponentPreviewElements
7
+ } from '~/src/form/form-editor/preview/location-question-base.js'
8
+ import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
9
+
10
+ /**
11
+ * @implements {QuestionElements}
12
+ */
13
+ export class OsGridRefComponentPreviewElements extends LocationQuestionComponentPreviewElements {}
14
+
15
+ export class OsGridRefQuestion extends LocationQuestion {
16
+ /**
17
+ * @type {ComponentType}
18
+ */
19
+ componentType = ComponentType.OsGridRefField
20
+ /**
21
+ * @type {string}
22
+ * @protected
23
+ */
24
+ _questionTemplate = PreviewComponent.PATH + 'osgridreffield.njk'
25
+ _fieldName = 'OsGridRefField'
26
+
27
+ /**
28
+ * @protected
29
+ * @returns {OsGridRefModel}
30
+ */
31
+ _renderInput() {
32
+ const baseModel = super._renderInput()
33
+ const locationModel = createLocationFieldModel(
34
+ baseModel,
35
+ /** @type {LocationElements} */ (this._htmlElements),
36
+ this._highlight,
37
+ this._instructionText,
38
+ this.titleText
39
+ )
40
+
41
+ return {
42
+ ...locationModel,
43
+ label: {
44
+ text: this.titleText,
45
+ classes: this._highlight === 'question' ? HIGHLIGHT_CLASS : ''
46
+ },
47
+ inputClasses: this._highlight === 'input' ? HIGHLIGHT_CLASS : ''
48
+ }
49
+ }
50
+ }
51
+
52
+ /**
53
+ * @import { LocationSettings, LocationElements, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
54
+ * @import { OsGridRefModel } from '~/src/form/form-editor/macros/types.js'
55
+ * @import { OsGridRefFieldComponent } from '~/src/components/types.js'
56
+ */
@@ -38,8 +38,8 @@ export interface GovukFieldset {
38
38
  }
39
39
 
40
40
  export type ListenerRow = [
41
- HTMLInputElement | null,
42
- (target: HTMLInputElement, e: Event) => void,
41
+ HTMLInputElement | HTMLTextAreaElement | null,
42
+ (target: HTMLInputElement | HTMLTextAreaElement, e: Event) => void,
43
43
  keyof HTMLElementEventMap
44
44
  ]
45
45
 
@@ -83,6 +83,28 @@ export interface NumberElements extends DomElementsBase {
83
83
  readonly values: NumberSettings
84
84
  }
85
85
 
86
+ export interface LocationSettings extends BaseSettings {
87
+ instructionText: string
88
+ }
89
+
90
+ export interface LocationElements extends DomElementsBase {
91
+ readonly values: LocationSettings
92
+ }
93
+
94
+ export interface LocationFieldModel extends QuestionBaseModel {
95
+ userClasses: string
96
+ fieldset: {
97
+ legend: {
98
+ text: string
99
+ classes: string
100
+ }
101
+ }
102
+ instructionText: string
103
+ details: {
104
+ classes: string
105
+ }
106
+ }
107
+
86
108
  export interface RenderBase {
87
109
  render(questionTemplate: string, renderContext: RenderContext): void
88
110
  }