@planning-inspectorate/dynamic-forms 3.15.5 → 3.15.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planning-inspectorate/dynamic-forms",
3
- "version": "3.15.5",
3
+ "version": "3.15.6",
4
4
  "description": "This package is for building GDS forms using a configuration-based approach.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -1,10 +1,11 @@
1
1
  /**
2
+ * @template {string} K Question keys in questionPropsRecord
2
3
  * @template {import('./question-props.js').BaseQuestionProps} T
3
- * @param {{[questionName: string]: T}} questionPropsRecord
4
+ * @param {{[questionName in K]: T}} questionPropsRecord
4
5
  * @param {Record<string, import('./question-types.js').QuestionClass>} questionClasses
5
6
  * @param {{[questionType: string]: Record<string, Function>}} questionMethodOverrides
6
7
  * @param {{notStartedText?: string, continueButtonText?: string, changeActionText?: string, answerActionText?: string}} [textOverrides] - customise question text
7
- * @returns {Record<string, InstanceType<import('./question-types.js').QuestionClass>>}
8
+ * @returns {{[questionName in K]: InstanceType<import('./question-types.js').QuestionClass>}} Returns the same question keys that were passed in with each value being an instantiated question
8
9
  */
9
10
  export function createQuestions(questionPropsRecord, questionClasses, questionMethodOverrides, textOverrides) {
10
11
  return Object.fromEntries(
@@ -1,19 +1,18 @@
1
1
  /**
2
+ * @template {string} K Question keys in questionPropsRecord
2
3
  * @template {import('./question-props.js').BaseQuestionProps} T
3
- * @param {{[questionName: string]: T}} questionPropsRecord
4
+ * @param {{[questionName in K]: T}} questionPropsRecord
4
5
  * @param {Record<string, import('./question-types.js').QuestionClass>} questionClasses
5
6
  * @param {{[questionType: string]: Record<string, Function>}} questionMethodOverrides
6
7
  * @param {{notStartedText?: string, continueButtonText?: string, changeActionText?: string, answerActionText?: string}} [textOverrides] - customise question text
7
- * @returns {Record<string, InstanceType<import('./question-types.js').QuestionClass>>}
8
+ * @returns {{[questionName in K]: InstanceType<import('./question-types.js').QuestionClass>}} Returns the same question keys that were passed in with each value being an instantiated question
8
9
  */
9
- export function createQuestions<T extends import("./question-props.js").BaseQuestionProps>(questionPropsRecord: {
10
- [questionName: string]: T;
11
- }, questionClasses: Record<string, import("./question-types.js").QuestionClass>, questionMethodOverrides: {
10
+ export function createQuestions<K extends string, T extends import("./question-props.js").BaseQuestionProps>(questionPropsRecord: { [questionName in K]: T; }, questionClasses: Record<string, import("./question-types.js").QuestionClass>, questionMethodOverrides: {
12
11
  [questionType: string]: Record<string, Function>;
13
12
  }, textOverrides?: {
14
13
  notStartedText?: string;
15
14
  continueButtonText?: string;
16
15
  changeActionText?: string;
17
16
  answerActionText?: string;
18
- }): Record<string, InstanceType<import("./question-types.js").QuestionClass>>;
17
+ }): { [questionName in K]: InstanceType<import("./question-types.js").QuestionClass>; };
19
18
  //# sourceMappingURL=create-questions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-questions.d.ts","sourceRoot":"","sources":["../../../src/questions/create-questions.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,gCAP+D,CAAC,SAAnD,OAAQ,qBAAqB,EAAE,iBAAkB,uBACnD;IAAC,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,CAAA;CAAC,mBAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,qBAAqB,EAAE,aAAa,CAAC,2BAC3D;IAAC,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,WAAW,CAAA;CAAC,kBAClD;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAC,GAC1G,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,qBAAqB,EAAE,aAAa,CAAC,CAAC,CAwBrF"}
1
+ {"version":3,"file":"create-questions.d.ts","sourceRoot":"","sources":["../../../src/questions/create-questions.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,gCARsB,CAAC,SAAV,MAAQ,EAC0C,CAAC,SAAnD,OAAQ,qBAAqB,EAAE,iBAAkB,uBACnD,GAAE,YAAY,IAAI,CAAC,GAAG,CAAC,GAAC,mBACxB,MAAM,CAAC,MAAM,EAAE,OAAO,qBAAqB,EAAE,aAAa,CAAC,2BAC3D;IAAC,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,WAAW,CAAA;CAAC,kBAClD;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAC,GAC1G,GAAE,YAAY,IAAI,CAAC,GAAG,YAAY,CAAC,OAAO,qBAAqB,EAAE,aAAa,CAAC,GAAC,CAwB5F"}
@@ -1,62 +0,0 @@
1
- {% extends layoutTemplate %}
2
-
3
- {% from "govuk/components/input/macro.njk" import govukInput %}
4
- {% from "govuk/components/label/macro.njk" import govukLabel %}
5
-
6
- {% block dynQuestionContent %}
7
- <div class="govuk-grid-row">
8
- <div class="govuk-grid-column-two-thirds">
9
- <form action="" method="post" novalidate>
10
- {% if _csrf %}<input type="hidden" name="_csrf" value="{{ _csrf }}">{% endif %}
11
- {% if question.label %}
12
- <h1 class="govuk-heading-l">
13
- {{ question.question }}
14
- </h1>
15
-
16
- {% if question.html %}
17
- {% include question.html ignore missing %}
18
- {% endif %}
19
-
20
- {{ govukInput({
21
- label: {
22
- text: question.label
23
- },
24
- id: question.fieldName,
25
- name: question.fieldName,
26
- value: question.value,
27
- hint: { text: question.hint },
28
- errorMessage: errors[question.fieldName] and {
29
- text: errors[question.fieldName].msg
30
- },
31
- classes: question.inputClasses
32
- }) }}
33
- {% else %}
34
- {{ govukLabel({
35
- text: question.question,
36
- isPageHeading: true,
37
- classes: 'govuk-label--l',
38
- for: question.fieldName
39
- }) }}
40
-
41
- {% if question.html %}
42
- {% include question.html ignore missing %}
43
- {% endif %}
44
-
45
- {{ govukInput({
46
- id: question.fieldName,
47
- name: question.fieldName,
48
- value: payload and payload[question.fieldName],
49
- hint: { text: question.hint },
50
- errorMessage: errors[question.fieldName] and {
51
- text: errors[question.fieldName].msg
52
- },
53
- classes: question.inputClasses
54
- }) }}
55
-
56
- {% endif %}
57
-
58
- {% include "components/utils/actions.njk" %}
59
- </form>
60
- </div>
61
- </div>
62
- {% endblock %}
@@ -1,33 +0,0 @@
1
- import { Question } from '#question';
2
-
3
- export class IdentifierQuestion extends Question {
4
- /** @type {string|undefined} page h1, optional, will default to use question's label */
5
- pageHeading;
6
- /** @type {string} css classes to apply to input element */
7
- inputClasses;
8
-
9
- /**
10
- * @param {import('#question-types').QuestionParameters} params
11
- * @param {string} [params.inputClasses] css class string to be added to the input
12
- * @param {string|undefined} [params.label] if defined this show as a label for the input and the question will just be a standard h1
13
- */
14
- constructor({ inputClasses = 'govuk-input--width-10', label, ...params }) {
15
- super({
16
- ...params,
17
- viewFolder: 'identifier'
18
- });
19
-
20
- this.inputClasses = inputClasses;
21
- this.label = label;
22
- }
23
-
24
- /**
25
- * @param {import('#question').QuestionViewModel} viewModel
26
- */
27
- addCustomDataToViewModel(viewModel) {
28
- viewModel.question.inputClasses = this.inputClasses;
29
- viewModel.question.label = this.label;
30
- }
31
- }
32
-
33
- export default IdentifierQuestion;
@@ -1,46 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import IdentifierQuestion from './question.js';
4
-
5
- describe('./src/dynamic-forms/components/identifier/question.js', () => {
6
- it('should create', () => {
7
- const TITLE = 'title';
8
- const QUESTION = 'Question?';
9
- const DESCRIPTION = 'Describe';
10
- const FIELDNAME = 'field-name';
11
- const URL = 'url';
12
- const PAGE_TITLE = 'this appears in <title>';
13
- const VALIDATORS = [1, 2];
14
- const HTML = '/path/to/html.njk';
15
- const HINT = 'hint';
16
- const INPUT_CLASSES = 'govuk-body';
17
- const LABEL = 'A label';
18
-
19
- const question = new IdentifierQuestion({
20
- title: TITLE,
21
- question: QUESTION,
22
- description: DESCRIPTION,
23
- fieldName: FIELDNAME,
24
- url: URL,
25
- pageTitle: PAGE_TITLE,
26
- validators: VALIDATORS,
27
- html: HTML,
28
- hint: HINT,
29
- inputClasses: INPUT_CLASSES,
30
- label: LABEL
31
- });
32
-
33
- assert.strictEqual(question.title, TITLE);
34
- assert.strictEqual(question.question, QUESTION);
35
- assert.strictEqual(question.description, DESCRIPTION);
36
- assert.strictEqual(question.fieldName, FIELDNAME);
37
- assert.strictEqual(question.viewFolder, 'identifier');
38
- assert.strictEqual(question.url, URL);
39
- assert.strictEqual(question.pageTitle, PAGE_TITLE);
40
- assert.strictEqual(question.validators, VALIDATORS);
41
- assert.strictEqual(question.html, HTML);
42
- assert.strictEqual(question.hint, HINT);
43
- assert.strictEqual(question.inputClasses, INPUT_CLASSES);
44
- assert.strictEqual(question.label, LABEL);
45
- });
46
- });
@@ -1,16 +0,0 @@
1
- export class IdentifierQuestion extends Question {
2
- /**
3
- * @param {import('#question-types').QuestionParameters} params
4
- * @param {string} [params.inputClasses] css class string to be added to the input
5
- * @param {string|undefined} [params.label] if defined this show as a label for the input and the question will just be a standard h1
6
- */
7
- constructor({ inputClasses, label, ...params }: import("#question-types").QuestionParameters);
8
- /** @type {string|undefined} page h1, optional, will default to use question's label */
9
- pageHeading: string | undefined;
10
- /** @type {string} css classes to apply to input element */
11
- inputClasses: string;
12
- label: any;
13
- }
14
- export default IdentifierQuestion;
15
- import { Question } from '#question';
16
- //# sourceMappingURL=question.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/identifier/question.js"],"names":[],"mappings":"AAEA;IAMC;;;;OAIG;IACH,gDAJW,OAAO,iBAAiB,EAAE,kBAAkB,EAYtD;IAlBD,uFAAuF;IACvF,aADW,MAAM,GAAC,SAAS,CACf;IACZ,2DAA2D;IAC3D,cADW,MAAM,CACJ;IAcZ,WAAkB;CAUnB;;yBA9BwB,WAAW"}