@planning-inspectorate/dynamic-forms 3.10.10 → 3.10.11

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 (133) hide show
  1. package/package.json +1 -1
  2. package/types/commitlint.config.d.ts +7 -0
  3. package/types/commitlint.config.d.ts.map +1 -0
  4. package/types/eslint.config.d.ts +95 -0
  5. package/types/eslint.config.d.ts.map +1 -0
  6. package/types/move-types.d.ts +2 -0
  7. package/types/move-types.d.ts.map +1 -0
  8. package/types/src/components/address/question.d.ts +36 -0
  9. package/types/src/components/address/question.d.ts.map +1 -0
  10. package/types/src/components/boolean/question.d.ts +52 -0
  11. package/types/src/components/boolean/question.d.ts.map +1 -0
  12. package/types/src/components/checkbox/question.d.ts +52 -0
  13. package/types/src/components/checkbox/question.d.ts.map +1 -0
  14. package/types/src/components/date/question.d.ts +23 -0
  15. package/types/src/components/date/question.d.ts.map +1 -0
  16. package/types/src/components/date-period/question.d.ts +35 -0
  17. package/types/src/components/date-period/question.d.ts.map +1 -0
  18. package/types/src/components/date-time/question.d.ts +25 -0
  19. package/types/src/components/date-time/question.d.ts.map +1 -0
  20. package/types/src/components/email/question.d.ts +31 -0
  21. package/types/src/components/email/question.d.ts.map +1 -0
  22. package/types/src/components/identifier/question.d.ts +16 -0
  23. package/types/src/components/identifier/question.d.ts.map +1 -0
  24. package/types/src/components/manage-list/manage-list-actions.d.ts +10 -0
  25. package/types/src/components/manage-list/manage-list-actions.d.ts.map +1 -0
  26. package/types/src/components/manage-list/manage-list-section.d.ts +16 -0
  27. package/types/src/components/manage-list/manage-list-section.d.ts.map +1 -0
  28. package/types/src/components/manage-list/question.d.ts +49 -0
  29. package/types/src/components/manage-list/question.d.ts.map +1 -0
  30. package/types/src/components/manage-list/utils.d.ts +18 -0
  31. package/types/src/components/manage-list/utils.d.ts.map +1 -0
  32. package/types/src/components/multi-field-input/question.d.ts +61 -0
  33. package/types/src/components/multi-field-input/question.d.ts.map +1 -0
  34. package/types/src/components/number-entry/question.d.ts +38 -0
  35. package/types/src/components/number-entry/question.d.ts.map +1 -0
  36. package/types/src/components/radio/question.d.ts +58 -0
  37. package/types/src/components/radio/question.d.ts.map +1 -0
  38. package/types/src/components/select/question.d.ts +55 -0
  39. package/types/src/components/select/question.d.ts.map +1 -0
  40. package/types/src/components/single-line-input/question.d.ts +19 -0
  41. package/types/src/components/single-line-input/question.d.ts.map +1 -0
  42. package/types/src/components/text-entry/question.d.ts +35 -0
  43. package/types/src/components/text-entry/question.d.ts.map +1 -0
  44. package/types/src/components/text-entry-redact/question.d.ts +35 -0
  45. package/types/src/components/text-entry-redact/question.d.ts.map +1 -0
  46. package/types/src/components/unit-option-entry/question.d.ts +84 -0
  47. package/types/src/components/unit-option-entry/question.d.ts.map +1 -0
  48. package/types/src/components/utils/component-types.d.ts +19 -0
  49. package/types/src/components/utils/component-types.d.ts.map +1 -0
  50. package/types/src/components/utils/persisted-number-answer.d.ts +2 -0
  51. package/types/src/components/utils/persisted-number-answer.d.ts.map +1 -0
  52. package/types/src/components/utils/question-has-answer.d.ts +17 -0
  53. package/types/src/components/utils/question-has-answer.d.ts.map +1 -0
  54. package/types/src/components/utils/question-utils.d.ts +15 -0
  55. package/types/src/components/utils/question-utils.d.ts.map +1 -0
  56. package/types/src/controller.d.ts +75 -0
  57. package/types/src/controller.d.ts.map +1 -0
  58. package/types/src/index.d.ts +59 -0
  59. package/types/src/index.d.ts.map +1 -0
  60. package/types/src/journey/journey-response.d.ts +32 -0
  61. package/types/src/journey/journey-response.d.ts.map +1 -0
  62. package/types/src/journey/journey-types.d.ts +28 -0
  63. package/types/src/journey/journey-types.d.ts.map +1 -0
  64. package/types/src/journey/journey.d.ts +136 -0
  65. package/types/src/journey/journey.d.ts.map +1 -0
  66. package/types/src/lib/address-utils.d.ts +6 -0
  67. package/types/src/lib/address-utils.d.ts.map +1 -0
  68. package/types/src/lib/address.d.ts +43 -0
  69. package/types/src/lib/address.d.ts.map +1 -0
  70. package/types/src/lib/date-utils.d.ts +60 -0
  71. package/types/src/lib/date-utils.d.ts.map +1 -0
  72. package/types/src/lib/session-answer-store.d.ts +88 -0
  73. package/types/src/lib/session-answer-store.d.ts.map +1 -0
  74. package/types/src/lib/utils.d.ts +26 -0
  75. package/types/src/lib/utils.d.ts.map +1 -0
  76. package/types/src/lib/uuid.d.ts +7 -0
  77. package/types/src/lib/uuid.d.ts.map +1 -0
  78. package/types/src/middleware/build-get-journey.d.ts +6 -0
  79. package/types/src/middleware/build-get-journey.d.ts.map +1 -0
  80. package/types/src/middleware/redirect-to-unanswered-question.d.ts +12 -0
  81. package/types/src/middleware/redirect-to-unanswered-question.d.ts.map +1 -0
  82. package/types/src/questions/create-questions.d.ts +21 -0
  83. package/types/src/questions/create-questions.d.ts.map +1 -0
  84. package/types/src/questions/options-question.d.ts +80 -0
  85. package/types/src/questions/options-question.d.ts.map +1 -0
  86. package/types/src/questions/question-props.d.ts +182 -0
  87. package/types/src/questions/question-props.d.ts.map +1 -0
  88. package/types/src/questions/question-types.d.ts +86 -0
  89. package/types/src/questions/question-types.d.ts.map +1 -0
  90. package/types/src/questions/question.d.ts +272 -0
  91. package/types/src/questions/question.d.ts.map +1 -0
  92. package/types/src/questions/questions.d.ts +3 -0
  93. package/types/src/questions/questions.d.ts.map +1 -0
  94. package/types/src/section.d.ts +107 -0
  95. package/types/src/section.d.ts.map +1 -0
  96. package/types/src/validator/address-validator.d.ts +48 -0
  97. package/types/src/validator/address-validator.d.ts.map +1 -0
  98. package/types/src/validator/base-validator.d.ts +12 -0
  99. package/types/src/validator/base-validator.d.ts.map +1 -0
  100. package/types/src/validator/conditional-required-validator.d.ts +25 -0
  101. package/types/src/validator/conditional-required-validator.d.ts.map +1 -0
  102. package/types/src/validator/confirmation-checkbox-validator.d.ts +28 -0
  103. package/types/src/validator/confirmation-checkbox-validator.d.ts.map +1 -0
  104. package/types/src/validator/coordinates-validator.d.ts +23 -0
  105. package/types/src/validator/coordinates-validator.d.ts.map +1 -0
  106. package/types/src/validator/date-period-validator.d.ts +64 -0
  107. package/types/src/validator/date-period-validator.d.ts.map +1 -0
  108. package/types/src/validator/date-time-validator.d.ts +27 -0
  109. package/types/src/validator/date-time-validator.d.ts.map +1 -0
  110. package/types/src/validator/date-validator.d.ts +49 -0
  111. package/types/src/validator/date-validator.d.ts.map +1 -0
  112. package/types/src/validator/document-upload-validator.d.ts +12 -0
  113. package/types/src/validator/document-upload-validator.d.ts.map +1 -0
  114. package/types/src/validator/email-validator.d.ts +74 -0
  115. package/types/src/validator/email-validator.d.ts.map +1 -0
  116. package/types/src/validator/multi-field-input-validator.d.ts +91 -0
  117. package/types/src/validator/multi-field-input-validator.d.ts.map +1 -0
  118. package/types/src/validator/numeric-validator.d.ts +50 -0
  119. package/types/src/validator/numeric-validator.d.ts.map +1 -0
  120. package/types/src/validator/required-validator.d.ts +23 -0
  121. package/types/src/validator/required-validator.d.ts.map +1 -0
  122. package/types/src/validator/same-answer-validator.d.ts +19 -0
  123. package/types/src/validator/same-answer-validator.d.ts.map +1 -0
  124. package/types/src/validator/string-validator.d.ts +59 -0
  125. package/types/src/validator/string-validator.d.ts.map +1 -0
  126. package/types/src/validator/unit-option-entry-validator.d.ts +41 -0
  127. package/types/src/validator/unit-option-entry-validator.d.ts.map +1 -0
  128. package/types/src/validator/valid-option-validator.d.ts +19 -0
  129. package/types/src/validator/valid-option-validator.d.ts.map +1 -0
  130. package/types/src/validator/validation-error-handler.d.ts +20 -0
  131. package/types/src/validator/validation-error-handler.d.ts.map +1 -0
  132. package/types/src/validator/validator.d.ts +5 -0
  133. package/types/src/validator/validator.d.ts.map +1 -0
@@ -0,0 +1,182 @@
1
+ import type { QuestionParameters } from '#src/questions/question-types.d.ts';
2
+
3
+ type QuestionTypes =
4
+ | 'boolean'
5
+ | 'checkbox'
6
+ | 'date'
7
+ | 'date-period'
8
+ | 'date-time'
9
+ | 'email'
10
+ | 'manage-list'
11
+ | 'multi-field-input'
12
+ | 'number'
13
+ | 'radio'
14
+ | 'select'
15
+ | 'single-line-input'
16
+ | 'site-address'
17
+ | 'text-entry'
18
+ | 'text-entry-redact'
19
+ | 'unit-option';
20
+
21
+ type CommonQuestionProps = Omit<QuestionParameters, 'viewFolder'> & {
22
+ type: QuestionTypes;
23
+ };
24
+
25
+ type Option =
26
+ | {
27
+ text: string;
28
+ value: string;
29
+ hint?: object;
30
+ checked?: boolean | undefined;
31
+ attributes?: Record<string, string>;
32
+ behaviour?: 'exclusive';
33
+ conditional?: {
34
+ question: string;
35
+ type: string;
36
+ fieldName: string;
37
+ inputClasses?: string;
38
+ html?: string;
39
+ value?: unknown;
40
+ label?: string;
41
+ hint?: string;
42
+ };
43
+ conditionalText?: {
44
+ html: string;
45
+ };
46
+ }
47
+ | { divider?: string };
48
+
49
+ type Affix = {
50
+ text: string;
51
+ classes?: string;
52
+ };
53
+
54
+ interface InputField {
55
+ fieldName: string;
56
+ label: string;
57
+ formatJoinString?: string; // used by formatAnswerForSummary (e.g. task list display), effective default to line break
58
+ formatPrefix?: string; // used by formatAnswerForSummary (e.g. task list display), to prefix answer
59
+ formatTextFunction?: (text: string) => string; // used to format the answer for display and value in question
60
+ attributes?: Record<string, string>; // used to add HTML attributes to the field
61
+ suffix?: Affix; // used to add a suffix to the field
62
+ prefix?: Affix; // used to add a prefix to the field
63
+ hint?: string;
64
+ }
65
+
66
+ /*
67
+ * UnitOptions are the options displayed in the radio format - in this case the value
68
+ * represents the unit.
69
+ * Conditionals must be used to capture the relevant quantity.
70
+ * Each conditional must have a fieldName which uses the conditionalFieldName from the
71
+ * UnitOptionEntryQuestion object as a base, followed by an underscore and unit reference
72
+ * eg 'siteAreaSquareMetres_hectares' - this is required for validation and saving to the DB
73
+ */
74
+ interface UnitOption {
75
+ text: string;
76
+ value: string;
77
+ hint?: object;
78
+ checked?: boolean | undefined;
79
+ attributes?: Record<string, string>;
80
+ behaviour?: 'exclusive';
81
+ conditional: {
82
+ fieldName: string;
83
+ suffix: string;
84
+ value?: unknown;
85
+ label?: string;
86
+ hint?: string;
87
+ conversionFactor?: number;
88
+ };
89
+ }
90
+
91
+ type BooleanQuestionProps = CommonQuestionProps & {
92
+ type: 'boolean';
93
+ options?: Option[];
94
+ interfaceType?: 'checkbox' | 'radio';
95
+ };
96
+
97
+ type CheckboxQuestionProps = CommonQuestionProps & {
98
+ type: 'checkbox';
99
+ options: Option[];
100
+ };
101
+
102
+ type DateQuestionProps = CommonQuestionProps & {
103
+ type: 'date';
104
+ };
105
+
106
+ type DatePeriodQuestionProps = CommonQuestionProps & {
107
+ type: 'date-period';
108
+ };
109
+
110
+ type DateTimeQuestionProps = CommonQuestionProps & {
111
+ type: 'date-time';
112
+ };
113
+
114
+ type ManageListQuestionProps = CommonQuestionProps & {
115
+ type: 'manage-list';
116
+ };
117
+
118
+ type EmailQuestionProps = CommonQuestionProps & {
119
+ type: 'email';
120
+ };
121
+
122
+ export type MultiFieldInputQuestionProps = CommonQuestionProps & {
123
+ type: 'multi-field-input';
124
+ inputFields: InputField[];
125
+ };
126
+
127
+ type NumberEntryQuestionProps = CommonQuestionProps & {
128
+ type: 'number';
129
+ suffix?: string;
130
+ };
131
+
132
+ type RadioQuestionProps = CommonQuestionProps & {
133
+ type: 'radio';
134
+ options: Option[];
135
+ };
136
+
137
+ type SelectQuestionProps = CommonQuestionProps & {
138
+ type: 'select';
139
+ options: Option[];
140
+ disableAccessibleAutocomplete?: boolean;
141
+ };
142
+
143
+ type SingleLineInputQuestionProps = CommonQuestionProps & {
144
+ type: 'single-line-input';
145
+ inputAttributes?: Record<string, string>;
146
+ };
147
+
148
+ type SiteAddressQuestionProps = CommonQuestionProps & {
149
+ type: 'site-address';
150
+ };
151
+
152
+ type TextEntryQuestionProps = CommonQuestionProps & {
153
+ type: 'text-entry';
154
+ };
155
+
156
+ type TextEntryRedactQuestionProps = CommonQuestionProps & {
157
+ type: 'text-entry-redact';
158
+ };
159
+
160
+ type UnitOptionEntryQuestionProps = CommonQuestionProps & {
161
+ type: 'unit-option';
162
+ conditionalFieldName: string;
163
+ options: UnitOption[];
164
+ };
165
+
166
+ export type QuestionProps =
167
+ | BooleanQuestionProps
168
+ | CheckboxQuestionProps
169
+ | DateQuestionProps
170
+ | DatePeriodQuestionProps
171
+ | DateTimeQuestionProps
172
+ | ManageListQuestionProps
173
+ | EmailQuestionProps
174
+ | MultiFieldInputQuestionProps
175
+ | NumberEntryQuestionProps
176
+ | RadioQuestionProps
177
+ | SelectQuestionProps
178
+ | SingleLineInputQuestionProps
179
+ | SiteAddressQuestionProps
180
+ | TextEntryQuestionProps
181
+ | TextEntryRedactQuestionProps
182
+ | UnitOptionEntryQuestionProps;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-props.d.ts","sourceRoot":"","sources":["../../../src/questions/question-props.js"],"names":[],"mappings":""}
@@ -0,0 +1,86 @@
1
+ import type { RouteParams } from '#src/journey/journey-types.d.ts';
2
+ import type ManageListQuestion from '#src/components/manage-list/question.js';
3
+ import type BaseValidator from '../validator/base-validator.js';
4
+ import type { JourneyResponse } from '../journey/journey-response.js';
5
+
6
+ export interface QuestionParameters {
7
+ title: string;
8
+ question: string;
9
+ viewFolder: string;
10
+ fieldName: string;
11
+ url?: string;
12
+ pageTitle?: string;
13
+ description?: string;
14
+ validators?: BaseValidator[];
15
+ html?: string;
16
+ hint?: string;
17
+ interfaceType?: string;
18
+ shouldDisplay?: (response: JourneyResponse) => boolean;
19
+ autocomplete?: string;
20
+ // is this question editable? defaults to true
21
+ editable?: boolean;
22
+ // override the action link for this question
23
+ actionLink?: ActionLink;
24
+ // static view data for this question
25
+ viewData?: {
26
+ /**
27
+ * @deprecated replaced by secondaryActions
28
+ */
29
+ extraActionButtons?: SecondaryAction[];
30
+ /**
31
+ * Secondary action buttons
32
+ */
33
+ secondaryActions?: SecondaryAction[];
34
+ [key: string]: any;
35
+ };
36
+ }
37
+
38
+ export interface ActionLink {
39
+ text: string;
40
+ href: string;
41
+ }
42
+
43
+ export type SecondaryAction = SecondaryActionButton | SecondaryActionLink;
44
+
45
+ export interface SecondaryActionButton {
46
+ text: string;
47
+ type?: string;
48
+ formaction?: string;
49
+ classes?: string;
50
+ }
51
+
52
+ export interface SecondaryActionLink {
53
+ text: string;
54
+ href: string;
55
+ classes?: string;
56
+ }
57
+
58
+ export interface QuestionViewModel {
59
+ question: {
60
+ value: string | number | Record<string, any>;
61
+ question: string;
62
+ fieldName: string;
63
+ pageTitle: string;
64
+ description?: string;
65
+ html?: string;
66
+ };
67
+ layoutTemplate: string;
68
+ pageCaption: string;
69
+ continueButtonText: string;
70
+ backLink: string;
71
+ showBackToListLink: string;
72
+ listLink: string;
73
+ journeyTitle: string;
74
+ [k: string]: any;
75
+ }
76
+
77
+ export interface PrepQuestionForRenderingOptions {
78
+ params: RouteParams;
79
+ manageListQuestion?: ManageListQuestion;
80
+ }
81
+
82
+ /**
83
+ * Define a question class type so that projects downstream can extend the
84
+ * Question class and still pass them to the createQuestions function.
85
+ */
86
+ export type QuestionClass<TQuestion extends Question = Question> = new (...args: never[]) => TQuestion;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-types.d.ts","sourceRoot":"","sources":["../../../src/questions/question-types.js"],"names":[],"mappings":""}
@@ -0,0 +1,272 @@
1
+ /**
2
+ * @import {BaseValidator} from "#base-validator"
3
+ * @import {ActionView} from "../controller.js"
4
+ * @import {ActionLink} from "./question-types.js"
5
+ */
6
+ /**
7
+ * @typedef {Object} PreppedQuestion
8
+ * @property {Object} value
9
+ * @property {string} question
10
+ * @property {string} fieldName
11
+ * @property {string} pageTitle
12
+ * @property {string} [description]
13
+ * @property {string} [html]
14
+ */
15
+ /**
16
+ * @typedef {Record<string, any>} QuestionViewModel
17
+ * @property {PreppedQuestion} question
18
+ * @property {string} layoutTemplate
19
+ * @property {string} pageCaption
20
+ * @property {string} [continueButtonText]
21
+ * @property {string} backLink
22
+ * @property {boolean} showBackToListLink
23
+ * @property {string} listLink
24
+ * @property {Object} util
25
+ * @property {function(string): string} util.trimTrailingSlash
26
+ */
27
+ /**
28
+ * A specific question within a journey which is made up of one (usually) or many (sometimes) components and their required content.
29
+ * @class
30
+ */
31
+ export class Question {
32
+ /**
33
+ * @param {import('#question-types').QuestionParameters} params
34
+ * @param {Record<string, Function>} [methodOverrides]
35
+ */
36
+ constructor({ title, question, viewFolder, fieldName, url, pageTitle, description, validators, html, hint, interfaceType, shouldDisplay, autocomplete, editable, actionLink, viewData }: import("#question-types").QuestionParameters, methodOverrides?: Record<string, Function>);
37
+ /** @type {string} - html page title, defaults to question if not provided */
38
+ pageTitle: string;
39
+ /** @type {string} - title used in the summary list */
40
+ title: string;
41
+ /** @type {string} - question shown to user on question page */
42
+ question: string;
43
+ /** @type {string|undefined} - additional information to user about the question */
44
+ description: string | undefined;
45
+ /** @type {string} the folder name of the view */
46
+ viewFolder: string;
47
+ /** @type {string} the unique name of the input on the page, also used as a url segment (should this be separated) */
48
+ fieldName: string;
49
+ /** @type {boolean} if the question should appear in the journey overview task list or not */
50
+ taskList: boolean;
51
+ /** @type {Array.<BaseValidator>} array of validators that a question uses to validate answers */
52
+ validators: Array<BaseValidator>;
53
+ /** @type {string|undefined} hint text displayed to user */
54
+ hint: string | undefined;
55
+ /** @type {boolean} show return to listing page link after question */
56
+ showBackToListLink: boolean;
57
+ /** @type {string|undefined} alternative url slug */
58
+ url: string | undefined;
59
+ /** @type {string|undefined} optional html content */
60
+ html: string | undefined;
61
+ /** @type {string|undefined} optional question type */
62
+ interfaceType: string | undefined;
63
+ /** @type {ActionLink|undefined} override action link */
64
+ actionLink: ActionLink | undefined;
65
+ /** @type {string} 'not started' text to display (if a question has no answer) */
66
+ notStartedText: string;
67
+ /** @type {string} button text to display */
68
+ continueButtonText: string;
69
+ /** @type {string} text to display for 'change' link */
70
+ changeActionText: string;
71
+ /** @type {string} text to display for 'answer' link */
72
+ answerActionText: string;
73
+ /** @type {string} text to display for 'add' link */
74
+ addActionText: string;
75
+ /**
76
+ * @param {import('../journey/journey-response.js').JourneyResponse} [response]
77
+ * @returns {boolean}
78
+ */
79
+ shouldDisplay: () => boolean;
80
+ details: {
81
+ title: string;
82
+ text: string;
83
+ };
84
+ /**
85
+ * Private, but not marked as such because it breaks types, either using #variable:
86
+ * - Property '#isInManageListSection' is missing in type
87
+ * or with the @ private tag
88
+ * - Types have separate declarations of a private property '_isInManageListSection'.
89
+ * @type {boolean}
90
+ */
91
+ _isInManageListSection: boolean;
92
+ autocomplete: string | undefined;
93
+ editable: boolean;
94
+ viewData: {
95
+ [key: string]: any;
96
+ extraActionButtons?: import("./question-types.js").SecondaryAction[];
97
+ secondaryActions?: import("./question-types.js").SecondaryAction[];
98
+ };
99
+ /**
100
+ * Is this question a manage list question?
101
+ * Implemented as a getter so manage list question implementations can override it,
102
+ * but it cannot be changed at runtime.
103
+ *
104
+ * @returns {boolean}
105
+ */
106
+ get isManageListQuestion(): boolean;
107
+ set isInManageListSection(value: boolean);
108
+ /**
109
+ * Is this question added to a ManageListSection?
110
+ *
111
+ * @returns {boolean}
112
+ */
113
+ get isInManageListSection(): boolean;
114
+ /**
115
+ * gets the view model for this question
116
+ *
117
+ * Wraps prepQuestionForRendering to add the back link - which requires more parameters
118
+ * that prepQuestionForRendering doesn't need
119
+ *
120
+ * @param {Object} options
121
+ * @param {import('../journey/journey-types.js').RouteParams} options.params
122
+ * @param {import('../components/manage-list/question.js')} [options.manageListQuestion]
123
+ * @param {import('../section.js').Section} options.section - the current section
124
+ * @param {import('../journey/journey.js').Journey} options.journey - the journey we are in
125
+ * @param {Record<string, unknown>} [options.customViewData] additional data to send to view
126
+ * @param {unknown} [options.payload]
127
+ * @returns {QuestionViewModel}
128
+ */
129
+ toViewModel({ params, manageListQuestion, section, journey, customViewData, payload }: {
130
+ params: import("../journey/journey-types.js").RouteParams;
131
+ manageListQuestion?: typeof import("../components/manage-list/question.js") | undefined;
132
+ section: import("../section.js").Section;
133
+ journey: import("../journey/journey.js").Journey;
134
+ customViewData?: Record<string, unknown> | undefined;
135
+ payload?: unknown;
136
+ }): QuestionViewModel;
137
+ /**
138
+ * gets the base view model for this question
139
+ *
140
+ * @param {import('../section.js').Section} section - the current section
141
+ * @param {import('../journey/journey.js').Journey} journey - the journey we are in
142
+ * @param {Record<string, unknown>} [customViewData] additional data to send to view
143
+ * @param {unknown} [payload]
144
+ * @param {import('#question-types').PrepQuestionForRenderingOptions} [options] - required to support manage list question
145
+ * @returns {QuestionViewModel}
146
+ */
147
+ prepQuestionForRendering(section: import("../section.js").Section, journey: import("../journey/journey.js").Journey, customViewData?: Record<string, unknown>, payload?: unknown, options?: import("#question-types").PrepQuestionForRenderingOptions): QuestionViewModel;
148
+ /**
149
+ * The answer to this question for use in the viewModel
150
+ *
151
+ * Question implementations can override this for more complex answer types
152
+ *
153
+ * @param {Record<string, any>} answers - collection of answers to pull the answer from, may be from the response or the request/payload
154
+ * @param {Boolean} isPayload - whether the answers object is from the request/payload
155
+ * @returns {*|string}
156
+ */ answerForViewModel(answers: Record<string, any>, isPayload: boolean): any | string;
157
+ /**
158
+ * Question implementations can override this to add configuration or other values to the view model
159
+ *
160
+ * If possible override this method instead of prepQuestionForRendering for simple changes to the view model
161
+ *
162
+ * @param {QuestionViewModel} viewModel
163
+ */ addCustomDataToViewModel(viewModel: QuestionViewModel): void;
164
+ /**
165
+ * Get the answers object from the journey response, which may be nested in an array for manage list questions
166
+ *
167
+ * @param {import('../journey/journey-response.js').JourneyResponse} response
168
+ * @param {import('#question-types').PrepQuestionForRenderingOptions} [options]
169
+ * @returns {Record<string, any>}
170
+ */
171
+ answerObjectFromJourneyResponse(response: import("../journey/journey-response.js").JourneyResponse, { params, manageListQuestion }?: import("#question-types").PrepQuestionForRenderingOptions): Record<string, any>;
172
+ /**
173
+ * renders the question
174
+ * @param {import('express').Response} res - the express response
175
+ * @param {QuestionViewModel} viewModel additional data to send to view
176
+ * @returns {void}
177
+ */
178
+ renderAction(res: import("express").Response, viewModel: QuestionViewModel): void;
179
+ /**
180
+ * check for validation errors
181
+ * @param {import('express').Request} req
182
+ * @param {import('../journey/journey.js').Journey} journey
183
+ * @param {import('../section.js').Section} section
184
+ * @param {import('../components/manage-list/question.js')} [manageListQuestion]
185
+ * @returns {QuestionViewModel|undefined} returns the view model for displaying the error or undefined if there are no errors
186
+ */
187
+ checkForValidationErrors(req: import("express").Request, section: import("../section.js").Section, journey: import("../journey/journey.js").Journey, manageListQuestion?: typeof import("../components/manage-list/question.js")): QuestionViewModel | undefined;
188
+ /**
189
+ * Get the data to save from the request, returns an object of answers
190
+ *
191
+ * @param {import('express').Request} req
192
+ * @param {import('../journey/journey-response.js').JourneyResponse} journeyResponse - current journey response
193
+ * @returns {Promise<{ answers: Record<string, unknown> }>}
194
+ */ getDataToSave(req: import("express").Request, journeyResponse: import("../journey/journey-response.js").JourneyResponse): Promise<{
195
+ answers: Record<string, unknown>;
196
+ }>;
197
+ /**
198
+ * check for errors after saving, by default this does nothing
199
+ * @param {import('express').Request} req
200
+ * @param {import('../journey/journey.js').Journey} journey
201
+ * @param {import('../section.js').Section} sectionObj
202
+ * @returns {QuestionViewModel | undefined} returns the view model for displaying the error or undefined if there are no errors
203
+ */ checkForSavingErrors(req: import("express").Request, sectionObj: import("../section.js").Section, journey: import("../journey/journey.js").Journey): QuestionViewModel | undefined;
204
+ /**
205
+ * Handles redirect after saving. Kept around for backwards compatibility.
206
+ *
207
+ * @param {import('express').Response} res
208
+ * @param {import('../journey/journey.js').Journey} journey
209
+ * @param {string} sectionSegment
210
+ * @param {string} questionSegment
211
+ * @returns {void}
212
+ * @deprecated - use `journey.redirectToNextQuestion`
213
+ */
214
+ handleNextQuestion(res: import("express").Response, journey: import("../journey/journey.js").Journey, sectionSegment: string, questionSegment: string): void;
215
+ /**
216
+ * returns the formatted answers values to be used to build task list elements
217
+ * @param {String} sectionSegment
218
+ * @param {import('../journey/journey.js').Journey} journey
219
+ * @param {Object} answer
220
+ * @returns {Array<{
221
+ * key: string;
222
+ * value: string | Object;
223
+ * action?: ActionView | ActionView[];
224
+ * }>}
225
+ */
226
+ formatAnswerForSummary(sectionSegment: string, journey: import("../journey/journey.js").Journey, answer: Object, capitals?: boolean): Array<{
227
+ key: string;
228
+ value: string | Object;
229
+ action?: ActionView | ActionView[];
230
+ }>;
231
+ /**
232
+ * Returns the action link for the question
233
+ * @param {Object} answer
234
+ * @param {import('../journey/journey.js').Journey} journey
235
+ * @param {String} sectionSegment
236
+ * @returns {ActionView|ActionView[]|undefined}
237
+ */
238
+ getAction(sectionSegment: string, journey: import("../journey/journey.js").Journey, answer: Object): ActionView | ActionView[] | undefined;
239
+ /**
240
+ * @param {unknown} answer
241
+ * @returns {unknown}
242
+ */
243
+ format(answer: unknown): unknown;
244
+ /**
245
+ * @returns {boolean}
246
+ */
247
+ isRequired(): boolean;
248
+ /**
249
+ * @param {string} inputField
250
+ * @returns {boolean}
251
+ */
252
+ fieldIsRequired(inputField: string): boolean;
253
+ /**
254
+ * @param {import('../journey/journey-response.js').JourneyResponse} journeyResponse
255
+ * @param {string} [fieldName] optional fieldname for multi field input questions
256
+ * @returns {boolean}
257
+ */
258
+ isAnswered(journeyResponse: import("../journey/journey-response.js").JourneyResponse, fieldName?: string): boolean;
259
+ }
260
+ export type PreppedQuestion = {
261
+ value: Object;
262
+ question: string;
263
+ fieldName: string;
264
+ pageTitle: string;
265
+ description?: string | undefined;
266
+ html?: string | undefined;
267
+ };
268
+ export type QuestionViewModel = Record<string, any>;
269
+ import type { BaseValidator } from "#base-validator";
270
+ import type { ActionLink } from "./question-types.js";
271
+ import type { ActionView } from "../controller.js";
272
+ //# sourceMappingURL=question.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../src/questions/question.js"],"names":[],"mappings":"AAOA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH;IA4DC;;;OAGG;IACH,yLAHW,OAAO,iBAAiB,EAAE,kBAAkB,oBAC5C,MAAM,CAAC,MAAM,WAAW,EAsDlC;IAn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MAAM,GACJ,IAAI,CAQhB;IAED;;;;;;;;;;OAUG;IACH,wDARW,OAAO,uBAAuB,EAAE,OAAO,UACvC,MAAM,uBACJ,KAAK,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;KACpC,CAAC,CAaJ;IAED;;;;;;OAMG;IACH,2CAJW,OAAO,uBAAuB,EAAE,OAAO,UADvC,MAAM,GAGJ,UAAU,GAAC,UAAU,EAAE,GAAC,SAAS,CAqB7C;IAED;;;OAGG;IACH,eAHW,OAAO,GACL,OAAO,CAInB;IAED;;OAEG;IACH,cAFa,OAAO,CASnB;IACD;;;OAGG;IACH,4BAHW,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,4BAJW,OAAO,gCAAgC,EAAE,eAAe,cACxD,MAAM,GACJ,OAAO,CAInB;CACD;;WAlda,MAAM;cACN,MAAM;eACN,MAAM;eACN,MAAM;;;;gCAMP,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;mCAhBA,iBAAiB;gCAEpB,qBAAqB;gCADrB,kBAAkB"}
@@ -0,0 +1,3 @@
1
+ /** @type {Record<string, import('./question').Question>} */
2
+ export const questionClasses: Record<string, any>;
3
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../../../src/questions/questions.js"],"names":[],"mappings":"AAsBA,4DAA4D;AAC5D,8BADW,MAAM,CAAC,MAAM,EAAE,GAA6B,CAAC,CAkBrD"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * A value indicating the final question of a section has been reached
3
+ *
4
+ * @type {Symbol}
5
+ */
6
+ export const END_OF_SECTION: Symbol;
7
+ /**
8
+ * Defines a section for a questionnaire, a set of Questions
9
+ * @class
10
+ */
11
+ export class Section {
12
+ /**
13
+ * Implementation of getNextQuestion given a list of questions
14
+ *
15
+ * @param {import('./section-types.d.ts').StaticGetNextQuestionParams} params
16
+ * @returns {Question|Symbol|null}
17
+ */
18
+ static getNextQuestion({ questions, questionFieldName, response, takeNextQuestion, reverse }: import("./section-types.d.ts").StaticGetNextQuestionParams): Question | Symbol | null;
19
+ /**
20
+ * creates an instance of a section
21
+ * @param {string} name
22
+ * @param {string} segment
23
+ */
24
+ constructor(name: string, segment: string);
25
+ /**
26
+ * @type {string} - the display name of the section shown to user
27
+ */
28
+ name: string;
29
+ /**
30
+ * @type {string} - the unique url segment for the section
31
+ */
32
+ segment: string;
33
+ /**
34
+ * @type {Array<Question>} - questions within the section
35
+ */
36
+ questions: Array<Question>;
37
+ /**
38
+ * Add a condition to all questions in this section
39
+ *
40
+ * @param {QuestionCondition} shouldIncludeSection
41
+ * @returns {Section}
42
+ */
43
+ withSectionCondition(shouldIncludeSection: QuestionCondition): Section;
44
+ /**
45
+ * Fluent API method for adding questions
46
+ * @param {import('#src/questions/question.js').Question} question
47
+ * @param {import('#src/components/manage-list/manage-list-section.js').ManageListSection} [manageListSection]
48
+ * @returns {Section}
49
+ */
50
+ addQuestion(question: import("#src/questions/question.js").Question, manageListSection?: import("#src/components/manage-list/manage-list-section.js").ManageListSection): Section;
51
+ /**
52
+ * Fluent API method for attaching conditions to the previously added question
53
+ * @param {QuestionCondition} shouldIncludeQuestion
54
+ * @returns {Section}
55
+ */
56
+ withCondition(shouldIncludeQuestion: QuestionCondition): Section;
57
+ withRequiredCondition(isQuestionMandatory: any, requiredFieldErrorMsg: any): this;
58
+ /**
59
+ * Fluent API method for starting a multi question condition
60
+ * @param {string} conditionName
61
+ * @param {QuestionCondition} shouldIncludeQuestion
62
+ * @returns {Section}
63
+ */
64
+ startMultiQuestionCondition(conditionName: string, shouldIncludeQuestion: QuestionCondition): Section;
65
+ /**
66
+ * Fluent API method for ending a multi question condition
67
+ * @param {string} conditionName
68
+ * @returns {Section}
69
+ */
70
+ endMultiQuestionCondition(conditionName: string): Section;
71
+ /**
72
+ * Get the next question in this section given a questionParam (question fieldName)
73
+ * @param {import('./section-types.d.ts').GetNextQuestionParams} params
74
+ * @returns {Question|Symbol|null}
75
+ */
76
+ getNextQuestion(params: import("./section-types.d.ts").GetNextQuestionParams): Question | Symbol | null;
77
+ /**
78
+ * checks answers on response to ensure that a answer is provided for each required question in the section
79
+ * @param {JourneyResponse} journeyResponse
80
+ * @returns {SectionStatus}
81
+ */
82
+ getStatus(journeyResponse: JourneyResponse): SectionStatus;
83
+ /**
84
+ * checks answers on response and return true if the status of the section is complete
85
+ * @param {JourneyResponse} journeyResponse
86
+ * @returns {boolean}
87
+ */
88
+ isComplete(journeyResponse: JourneyResponse): boolean;
89
+ #private;
90
+ }
91
+ export type SECTION_STATUS = SectionStatus;
92
+ /**
93
+ * @typedef {string} SectionStatus
94
+ */
95
+ /**
96
+ * @enum {SectionStatus}
97
+ */
98
+ export const SECTION_STATUS: Readonly<{
99
+ NOT_STARTED: "Not started";
100
+ IN_PROGRESS: "In progress";
101
+ COMPLETE: "Completed";
102
+ }>;
103
+ export type Question = any;
104
+ export type JourneyResponse = any;
105
+ export type QuestionCondition = ((response: JourneyResponse) => boolean);
106
+ export type SectionStatus = string;
107
+ //# sourceMappingURL=section.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../src/section.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,6BAFU,MAAM,CAEuC;AAEvD;;;GAGG;AACH;IAgNC;;;;;OAKG;IACH,8FAHW,OAAO,sBAAsB,EAAE,2BAA2B,GACxD,QAAQ,GAAC,MAAM,GAAC,IAAI,CAoBhC;IAvMD;;;;OAIG;IACH,kBAHW,MAAM,WACN,MAAM,EAKhB;IAxCD;;OAEG;IACH,MAFU,MAAM,CAEX;IAEL;;OAEG;IACH,SAFU,MAAM,CAER;IAER;;OAEG;IACH,WAFU,KAAK,CAAC,QAAQ,CAAC,CAEV;IA6Bf;;;;;OAKG;IACH,2CAHW,iBAAiB,GACf,OAAO,CAcnB;IAED;;;;;OAKG;IACH,sBAJW,OAAO,4BAA4B,EAAE,QAAQ,sBAC7C,OAAO,oDAAoD,EAAE,iBAAiB,GAC5E,OAAO,CAgBnB;IA8BD;;;;OAIG;IACH,qCAHW,iBAAiB,GACf,OAAO,CAanB;IAED,kFAoBC;IAED;;;;;OAKG;IACH,2CAJW,MAAM,yBACN,iBAAiB,GACf,OAAO,CAQnB;IAED;;;;OAIG;IACH,yCAHW,MAAM,GACJ,OAAO,CAQnB;IAED;;;;OAIG;IACH,wBAHW,OAAO,sBAAsB,EAAE,qBAAqB,GAClD,QAAQ,GAAC,MAAM,GAAC,IAAI,CAuBhC;IA4BD;;;;OAIG;IACH,2BAHW,eAAe,GACb,aAAa,CAoDzB;IAED;;;;OAIG;IACH,4BAHW,eAAe,GACb,OAAO,CAInB;;CAKD;6BAOS,aAAa;AALvB;;GAEG;AAEH;;GAEG;AACH;;;;GAIG;;;gCA7UU,CAAC,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;4BAmUxC,MAAM"}