@defra/forms-model 3.0.599 → 3.0.601
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/common/pagination/index.js +55 -0
- package/dist/module/common/pagination/index.js.map +1 -1
- package/dist/module/common/pagination/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +4 -3
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
- package/dist/module/form/form-editor/preview/index.js +1 -0
- package/dist/module/form/form-editor/preview/index.js.map +1 -1
- package/dist/module/form/form-editor/preview/unsupported-question.js +15 -0
- package/dist/module/form/form-editor/preview/unsupported-question.js.map +1 -0
- package/dist/types/common/pagination/index.d.ts +10 -1
- package/dist/types/common/pagination/index.d.ts.map +1 -1
- package/dist/types/common/pagination/types.d.ts +35 -0
- package/dist/types/common/pagination/types.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/index.d.ts +1 -0
- package/dist/types/form/form-editor/preview/unsupported-question.d.ts +4 -0
- package/dist/types/form/form-editor/preview/unsupported-question.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/common/pagination/index.ts +64 -1
- package/src/common/pagination/types.ts +41 -0
- package/src/form/form-editor/preview/helpers.js +4 -4
- package/src/form/form-editor/preview/index.js +1 -0
- package/src/form/form-editor/preview/unsupported-question.js +15 -0
|
@@ -12,4 +12,59 @@ export const paginationOptionFields = {
|
|
|
12
12
|
* @see {@link PaginationOptions}
|
|
13
13
|
*/
|
|
14
14
|
export const paginationOptionsSchema = Joi.object(paginationOptionFields);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
18
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
19
|
+
* @param currentPage - The current page number
|
|
20
|
+
* @param totalPages - The total number of pages
|
|
21
|
+
* @param createHref - Function to generate href for each page number
|
|
22
|
+
* @returns Array of pagination page items
|
|
23
|
+
*/
|
|
24
|
+
export function buildPaginationPages(currentPage, totalPages, createHref) {
|
|
25
|
+
const pages = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a pagination page item
|
|
29
|
+
*/
|
|
30
|
+
function createPageItem(pageNumber, isCurrent = false) {
|
|
31
|
+
return {
|
|
32
|
+
number: String(pageNumber),
|
|
33
|
+
href: createHref(pageNumber),
|
|
34
|
+
current: isCurrent
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Always show the first page
|
|
39
|
+
pages.push(createPageItem(1, currentPage === 1));
|
|
40
|
+
|
|
41
|
+
// Calculate adjacent page range (one before and one after current)
|
|
42
|
+
const adjacentStartPage = Math.max(currentPage - 1, 2);
|
|
43
|
+
const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1);
|
|
44
|
+
|
|
45
|
+
// Add ellipsis after first page if needed
|
|
46
|
+
if (adjacentStartPage > 2) {
|
|
47
|
+
pages.push({
|
|
48
|
+
ellipsis: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Add pages between adjacentStartPage and adjacentEndPage
|
|
53
|
+
for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {
|
|
54
|
+
pages.push(createPageItem(i, i === currentPage));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Add ellipsis before last page if needed
|
|
58
|
+
if (adjacentEndPage < totalPages - 1) {
|
|
59
|
+
pages.push({
|
|
60
|
+
ellipsis: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Always show the last page if totalPages > 1
|
|
65
|
+
if (totalPages > 1) {
|
|
66
|
+
pages.push(createPageItem(totalPages, currentPage === totalPages));
|
|
67
|
+
}
|
|
68
|
+
return pages;
|
|
69
|
+
}
|
|
15
70
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","paginationOptionFields","page","number","positive","integer","default","min","optional","description","perPage","max","paginationOptionsSchema","object"],"sources":["../../../../src/common/pagination/index.ts"],"sourcesContent":["import Joi from 'joi'\n\nimport { type PaginationOptions } from '~/src/common/pagination/types.js'\n\n/**\n * Field definitions for pagination options.\n */\nexport const paginationOptionFields = {\n page: Joi.number()\n .positive()\n .integer()\n .default(1)\n .min(1)\n .optional()\n .description('Current page number, starting from 1'),\n perPage: Joi.number()\n .positive()\n .integer()\n .default(24)\n .min(1)\n .max(200)\n .optional()\n .description('Number of items to display per page, between 1 and 200')\n}\n\n/**\n * Joi schema for `PaginationOptions` interface\n * @see {@link PaginationOptions}\n */\nexport const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =\n Joi.object(paginationOptionFields)\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;
|
|
1
|
+
{"version":3,"file":"index.js","names":["Joi","paginationOptionFields","page","number","positive","integer","default","min","optional","description","perPage","max","paginationOptionsSchema","object","buildPaginationPages","currentPage","totalPages","createHref","pages","createPageItem","pageNumber","isCurrent","String","href","current","push","adjacentStartPage","Math","adjacentEndPage","ellipsis","i"],"sources":["../../../../src/common/pagination/index.ts"],"sourcesContent":["import Joi from 'joi'\n\nimport {\n type CreatePageHrefFn,\n type PaginationOptions,\n type PaginationPage\n} from '~/src/common/pagination/types.js'\n\n/**\n * Field definitions for pagination options.\n */\nexport const paginationOptionFields = {\n page: Joi.number()\n .positive()\n .integer()\n .default(1)\n .min(1)\n .optional()\n .description('Current page number, starting from 1'),\n perPage: Joi.number()\n .positive()\n .integer()\n .default(24)\n .min(1)\n .max(200)\n .optional()\n .description('Number of items to display per page, between 1 and 200')\n}\n\n/**\n * Joi schema for `PaginationOptions` interface\n * @see {@link PaginationOptions}\n */\nexport const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =\n Joi.object(paginationOptionFields)\n\n/**\n * Builds the pages array for the GOV.UK Design System pagination component.\n * Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.\n * @param currentPage - The current page number\n * @param totalPages - The total number of pages\n * @param createHref - Function to generate href for each page number\n * @returns Array of pagination page items\n */\nexport function buildPaginationPages(\n currentPage: number,\n totalPages: number,\n createHref: CreatePageHrefFn\n): PaginationPage[] {\n const pages: PaginationPage[] = []\n\n /**\n * Creates a pagination page item\n */\n function createPageItem(\n pageNumber: number,\n isCurrent = false\n ): PaginationPage {\n return {\n number: String(pageNumber),\n href: createHref(pageNumber),\n current: isCurrent\n }\n }\n\n // Always show the first page\n pages.push(createPageItem(1, currentPage === 1))\n\n // Calculate adjacent page range (one before and one after current)\n const adjacentStartPage = Math.max(currentPage - 1, 2)\n const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1)\n\n // Add ellipsis after first page if needed\n if (adjacentStartPage > 2) {\n pages.push({ ellipsis: true })\n }\n\n // Add pages between adjacentStartPage and adjacentEndPage\n for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {\n pages.push(createPageItem(i, i === currentPage))\n }\n\n // Add ellipsis before last page if needed\n if (adjacentEndPage < totalPages - 1) {\n pages.push({ ellipsis: true })\n }\n\n // Always show the last page if totalPages > 1\n if (totalPages > 1) {\n pages.push(createPageItem(totalPages, currentPage === totalPages))\n }\n\n return pages\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAQrB;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG;EACpCC,IAAI,EAAEF,GAAG,CAACG,MAAM,CAAC,CAAC,CACfC,QAAQ,CAAC,CAAC,CACVC,OAAO,CAAC,CAAC,CACTC,OAAO,CAAC,CAAC,CAAC,CACVC,GAAG,CAAC,CAAC,CAAC,CACNC,QAAQ,CAAC,CAAC,CACVC,WAAW,CAAC,sCAAsC,CAAC;EACtDC,OAAO,EAAEV,GAAG,CAACG,MAAM,CAAC,CAAC,CAClBC,QAAQ,CAAC,CAAC,CACVC,OAAO,CAAC,CAAC,CACTC,OAAO,CAAC,EAAE,CAAC,CACXC,GAAG,CAAC,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,EAAE;IACpCE,KAAK,CAACO,IAAI,CAAC;MAAEI,QAAQ,EAAE;IAAK,CAAC,CAAC;EAChC;;EAEA;EACA,IAAIb,UAAU,GAAG,CAAC,EAAE;IAClBE,KAAK,CAACO,IAAI,CAACN,cAAc,CAACH,UAAU,EAAED,WAAW,KAAKC,UAAU,CAAC,CAAC;EACpE;EAEA,OAAOE,KAAK;AACd","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/common/pagination/types.ts"],"sourcesContent":["/**\n * Result of pagination containing page information\n */\nexport interface PaginationResult {\n /**\n * The current page number.\n */\n page: number\n\n /**\n * The number of items per page.\n */\n perPage: number\n\n /**\n * The total number of items available.\n */\n totalItems: number\n\n /**\n * The total number of pages available.\n */\n totalPages: number\n}\n\n/**\n * Options for paginating results\n * Allows partial specification of page and perPage from PaginationResult\n */\nexport type PaginationOptions = Required<\n Pick<PaginationResult, 'page' | 'perPage'>\n>\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/common/pagination/types.ts"],"sourcesContent":["/**\n * Result of pagination containing page information\n */\nexport interface PaginationResult {\n /**\n * The current page number.\n */\n page: number\n\n /**\n * The number of items per page.\n */\n perPage: number\n\n /**\n * The total number of items available.\n */\n totalItems: number\n\n /**\n * The total number of pages available.\n */\n totalPages: number\n}\n\n/**\n * Options for paginating results\n * Allows partial specification of page and perPage from PaginationResult\n */\nexport type PaginationOptions = Required<\n Pick<PaginationResult, 'page' | 'perPage'>\n>\n\n/**\n * A single page item for the pagination component\n */\nexport interface PaginationPage {\n /**\n * The page number (if it's a page, not an ellipsis)\n */\n number?: string\n\n /**\n * The URL for the page\n */\n href?: string\n\n /**\n * Whether this page is the current page\n */\n current?: boolean\n\n /**\n * Whether this entry is an ellipsis (gap indicator)\n */\n ellipsis?: boolean\n}\n\n/**\n * Callback function to generate href for a given page number\n */\nexport type CreatePageHrefFn = (pageNumber: number) => string\n\n/**\n * Pagination result with page items for the pagination component\n * Extends PaginationResult with the pages array needed for rendering\n */\nexport interface PaginationResultWithPages extends PaginationResult {\n /**\n * Page items for the pagination component\n */\n pages: PaginationPage[]\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -24,18 +24,19 @@ import { SelectQuestion } from "./select.js";
|
|
|
24
24
|
import { ShortAnswerQuestion } from "./short-answer.js";
|
|
25
25
|
import { SupportingEvidenceQuestion } from "./supporting-evidence.js";
|
|
26
26
|
import { UkAddressComponentPreviewElements, UkAddressQuestion } from "./uk-address.js";
|
|
27
|
+
import { UnsupportedQuestion } from "./unsupported-question.js";
|
|
27
28
|
import { YesNoQuestion } from "./yes-no.js";
|
|
28
29
|
import { findDefinitionListFromComponent } from "../../utils/list.js";
|
|
29
30
|
/**
|
|
30
31
|
* @type {typeof PreviewComponent}
|
|
31
32
|
*/
|
|
32
|
-
const
|
|
33
|
+
const InvalidFieldComponent = UnsupportedQuestion;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* @type {Partial<Record<ComponentType, typeof PreviewComponent>>}
|
|
36
37
|
*/
|
|
37
38
|
const InputFieldComponentDictionary = {
|
|
38
|
-
[ComponentType.TextField]:
|
|
39
|
+
[ComponentType.TextField]: ShortAnswerQuestion,
|
|
39
40
|
[ComponentType.Details]: ShortAnswerQuestion,
|
|
40
41
|
[ComponentType.InsetText]: ShortAnswerQuestion,
|
|
41
42
|
[ComponentType.Html]: ShortAnswerQuestion,
|
|
@@ -144,7 +145,7 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
|
144
145
|
} else {
|
|
145
146
|
questionElements = new ComponentElements(component);
|
|
146
147
|
}
|
|
147
|
-
const QuestionConstructor = InputFieldComponentDictionary[component.type] ??
|
|
148
|
+
const QuestionConstructor = InputFieldComponentDictionary[component.type] ?? InvalidFieldComponent;
|
|
148
149
|
const previewComponent = new QuestionConstructor(questionElements, questionRenderer);
|
|
149
150
|
previewComponent.id = component.id;
|
|
150
151
|
return previewComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["ComponentType","hasContentField","hasInputField","hasListField","hasSelectionFields","AutocompleteListQuestion","CheckboxQuestion","ComponentElements","ContentElements","DateInputQuestion","DeclarationComponentPreviewElements","DeclarationQuestion","EastingNorthingComponentPreviewElements","EastingNorthingQuestion","EmailAddressQuestion","HiddenQuestion","LatLongComponentPreviewElements","LatLongQuestion","ListComponentElements","ListQuestion","SelectComponentElements","LongAnswerQuestion","MultilineTextFieldComponentPreviewElements","Markdown","MonthYearQuestion","NationalGridComponentPreviewElements","NationalGridQuestion","NumberComponentPreviewElements","NumberOnlyQuestion","OsGridRefComponentPreviewElements","OsGridRefQuestion","PhoneNumberQuestion","QuestionComponentElements","RadioQuestion","SelectQuestion","ShortAnswerQuestion","SupportingEvidenceQuestion","UkAddressComponentPreviewElements","UkAddressQuestion","YesNoQuestion","findDefinitionListFromComponent","InputFieldComponentDefault","InputFieldComponentDictionary","TextField","Details","InsetText","Html","List","EmailAddressField","NumberField","MultilineTextField","TelephoneNumberField","MonthYearField","DatePartsField","UkAddressField","AutocompleteField","RadiosField","CheckboxesField","SelectField","YesNoField","DeclarationField","FileUploadField","EastingNorthingField","OsGridRefField","NationalGridFieldNumberField","LatLongField","HiddenField","ComponentToPreviewQuestion","component","definition","componentCoerced","list","_definition","mapComponentToPreviewQuestion","questionRenderer","questionElements","getQuestionElementsFunc","type","QuestionConstructor","previewComponent","id"],"sources":["../../../../../src/form/form-editor/preview/helpers.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport {\n hasContentField,\n hasInputField,\n hasListField,\n hasSelectionFields\n} from '~/src/components/helpers.js'\nimport { AutocompleteListQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { CheckboxQuestion } from '~/src/form/form-editor/preview/checkbox.js'\nimport { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport {\n DeclarationComponentPreviewElements,\n DeclarationQuestion\n} from '~/src/form/form-editor/preview/declaration.js'\nimport {\n EastingNorthingComponentPreviewElements,\n EastingNorthingQuestion\n} from '~/src/form/form-editor/preview/easting-northing.js'\nimport { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { HiddenQuestion } from '~/src/form/form-editor/preview/hidden.js'\nimport {\n LatLongComponentPreviewElements,\n LatLongQuestion\n} from '~/src/form/form-editor/preview/lat-long.js'\nimport {\n ListComponentElements,\n ListQuestion,\n SelectComponentElements\n} from '~/src/form/form-editor/preview/list.js'\nimport {\n LongAnswerQuestion,\n MultilineTextFieldComponentPreviewElements\n} from '~/src/form/form-editor/preview/long-answer.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'\nimport {\n NationalGridComponentPreviewElements,\n NationalGridQuestion\n} from '~/src/form/form-editor/preview/national-grid.js'\nimport {\n NumberComponentPreviewElements,\n NumberOnlyQuestion\n} from '~/src/form/form-editor/preview/number-only.js'\nimport {\n OsGridRefComponentPreviewElements,\n OsGridRefQuestion\n} from '~/src/form/form-editor/preview/os-grid-ref.js'\nimport { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { QuestionComponentElements } from '~/src/form/form-editor/preview/question.js'\nimport { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'\nimport { SelectQuestion } from '~/src/form/form-editor/preview/select.js'\nimport { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'\nimport {\n UkAddressComponentPreviewElements,\n UkAddressQuestion\n} from '~/src/form/form-editor/preview/uk-address.js'\nimport { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'\nimport { findDefinitionListFromComponent } from '~/src/form/utils/list.js'\n/**\n * @type {typeof PreviewComponent}\n */\nconst InputFieldComponentDefault = ShortAnswerQuestion\n\n/**\n * @type {Partial<Record<ComponentType, typeof PreviewComponent>>}\n */\nconst InputFieldComponentDictionary = {\n [ComponentType.TextField]: InputFieldComponentDefault,\n [ComponentType.Details]: ShortAnswerQuestion,\n [ComponentType.InsetText]: ShortAnswerQuestion,\n [ComponentType.Html]: ShortAnswerQuestion,\n [ComponentType.Markdown]: Markdown,\n [ComponentType.List]: ListQuestion,\n [ComponentType.EmailAddressField]: EmailAddressQuestion,\n [ComponentType.NumberField]: NumberOnlyQuestion,\n [ComponentType.MultilineTextField]: LongAnswerQuestion,\n [ComponentType.TelephoneNumberField]: PhoneNumberQuestion,\n [ComponentType.MonthYearField]: MonthYearQuestion,\n [ComponentType.DatePartsField]: DateInputQuestion,\n [ComponentType.UkAddressField]: UkAddressQuestion,\n [ComponentType.AutocompleteField]: AutocompleteListQuestion,\n [ComponentType.RadiosField]: RadioQuestion,\n [ComponentType.CheckboxesField]: CheckboxQuestion,\n [ComponentType.SelectField]: SelectQuestion,\n [ComponentType.YesNoField]: YesNoQuestion,\n [ComponentType.DeclarationField]: DeclarationQuestion,\n [ComponentType.FileUploadField]: SupportingEvidenceQuestion,\n [ComponentType.EastingNorthingField]: EastingNorthingQuestion,\n [ComponentType.OsGridRefField]: OsGridRefQuestion,\n [ComponentType.NationalGridFieldNumberField]: NationalGridQuestion,\n [ComponentType.LatLongField]: LatLongQuestion,\n [ComponentType.HiddenField]: HiddenQuestion\n}\n\n/**\n * @type {Partial<Record<ComponentType, (component: ComponentDef, definition: FormDefinition ) => QuestionElements>>}\n */\nconst ComponentToPreviewQuestion = {\n [ComponentType.AutocompleteField]: (component, definition) => {\n const componentCoerced = /** @type {AutocompleteFieldComponent} */ (\n component\n )\n const list = findDefinitionListFromComponent(componentCoerced, definition)\n return new SelectComponentElements(componentCoerced, list)\n },\n [ComponentType.SelectField]: (component, definition) => {\n const componentCoerced = /** @type {SelectFieldComponent} */ (component)\n const list = findDefinitionListFromComponent(componentCoerced, definition)\n return new SelectComponentElements(componentCoerced, list)\n },\n [ComponentType.MultilineTextField]: (component, _definition) => {\n const componentCoerced = /** @type {MultilineTextFieldComponent} */ (\n component\n )\n return new MultilineTextFieldComponentPreviewElements(componentCoerced)\n },\n [ComponentType.UkAddressField]: (component, _definition) => {\n const componentCoerced = /** @type {UkAddressFieldComponent} */ (component)\n return new UkAddressComponentPreviewElements(componentCoerced)\n },\n [ComponentType.NumberField]: (component, _definition) => {\n const componentCoerced = /** @type {NumberFieldComponent} */ (component)\n return new NumberComponentPreviewElements(componentCoerced)\n },\n [ComponentType.DeclarationField]: (component, _definition) => {\n const componentCoerced = /** @type {DeclarationFieldComponent} */ (\n component\n )\n return new DeclarationComponentPreviewElements(componentCoerced)\n },\n [ComponentType.YesNoField]: (component, _definition) => {\n const componentCoerced = /** @type {YesNoFieldComponent} */ (component)\n return new QuestionComponentElements(componentCoerced)\n },\n [ComponentType.EastingNorthingField]: (component, _definition) => {\n const componentCoerced = /** @type {EastingNorthingFieldComponent} */ (\n component\n )\n return new EastingNorthingComponentPreviewElements(componentCoerced)\n },\n [ComponentType.OsGridRefField]: (component, _definition) => {\n const componentCoerced = /** @type {OsGridRefFieldComponent} */ (component)\n return new OsGridRefComponentPreviewElements(componentCoerced)\n },\n [ComponentType.NationalGridFieldNumberField]: (component, _definition) => {\n const componentCoerced =\n /** @type {NationalGridFieldNumberFieldComponent} */ (component)\n return new NationalGridComponentPreviewElements(componentCoerced)\n },\n [ComponentType.LatLongField]: (component, _definition) => {\n const componentCoerced = /** @type {LatLongFieldComponent} */ (component)\n return new LatLongComponentPreviewElements(componentCoerced)\n }\n}\n\n/**\n * @param {QuestionRenderer} questionRenderer\n * @param {FormDefinition} definition\n * @returns {(component: ComponentDef) => Question}\n */\nexport function mapComponentToPreviewQuestion(questionRenderer, definition) {\n return /** @type {(component: ComponentDef) => Question} */ (\n (component) => {\n /**\n * @type {QuestionElements}\n */\n let questionElements\n\n // Look for one-to-one mapping first, then fallback if not found\n const getQuestionElementsFunc = ComponentToPreviewQuestion[component.type]\n if (getQuestionElementsFunc) {\n questionElements = getQuestionElementsFunc(component, definition)\n } else if (hasSelectionFields(component) && hasListField(component)) {\n const list = findDefinitionListFromComponent(component, definition)\n questionElements = new ListComponentElements(component, list)\n } else if (hasInputField(component)) {\n questionElements = new QuestionComponentElements(component)\n } else if (hasContentField(component)) {\n questionElements = new ContentElements(component)\n } else {\n questionElements = new ComponentElements(component)\n }\n\n const QuestionConstructor =\n InputFieldComponentDictionary[component.type] ??\n InputFieldComponentDefault\n const previewComponent = new QuestionConstructor(\n questionElements,\n questionRenderer\n )\n previewComponent.id = component.id\n return previewComponent\n }\n )\n}\n\n/**\n * @import { QuestionElements, QuestionRenderer } 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 } from '~/src/form/form-definition/types.js'\n * @import { AutocompleteFieldComponent, ComponentDef, DeclarationFieldComponent, EastingNorthingFieldComponent, LatLongFieldComponent, MultilineTextFieldComponent, NationalGridFieldNumberFieldComponent, NumberFieldComponent, OsGridRefFieldComponent, SelectFieldComponent, UkAddressFieldComponent, YesNoFieldComponent } from '~/src/components/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SACEC,eAAe,EACfC,aAAa,EACbC,YAAY,EACZC,kBAAkB;AAEpB,SAASC,wBAAwB;AACjC,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SACEC,mCAAmC,EACnCC,mBAAmB;AAErB,SACEC,uCAAuC,EACvCC,uBAAuB;AAEzB,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AACvB,SACEC,+BAA+B,EAC/BC,eAAe;AAEjB,SACEC,qBAAqB,EACrBC,YAAY,EACZC,uBAAuB;AAEzB,SACEC,kBAAk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AAgB,CAACC,EAAE,GAAGZ,SAAS,CAACY,EAAE;IAClC,OAAOD,gBAAgB;EACzB,CAAC;AAEL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["ComponentType","hasContentField","hasInputField","hasListField","hasSelectionFields","AutocompleteListQuestion","CheckboxQuestion","ComponentElements","ContentElements","DateInputQuestion","DeclarationComponentPreviewElements","DeclarationQuestion","EastingNorthingComponentPreviewElements","EastingNorthingQuestion","EmailAddressQuestion","HiddenQuestion","LatLongComponentPreviewElements","LatLongQuestion","ListComponentElements","ListQuestion","SelectComponentElements","LongAnswerQuestion","MultilineTextFieldComponentPreviewElements","Markdown","MonthYearQuestion","NationalGridComponentPreviewElements","NationalGridQuestion","NumberComponentPreviewElements","NumberOnlyQuestion","OsGridRefComponentPreviewElements","OsGridRefQuestion","PhoneNumberQuestion","QuestionComponentElements","RadioQuestion","SelectQuestion","ShortAnswerQuestion","SupportingEvidenceQuestion","UkAddressComponentPreviewElements","UkAddressQuestion","UnsupportedQuestion","YesNoQuestion","findDefinitionListFromComponent","InvalidFieldComponent","InputFieldComponentDictionary","TextField","Details","InsetText","Html","List","EmailAddressField","NumberField","MultilineTextField","TelephoneNumberField","MonthYearField","DatePartsField","UkAddressField","AutocompleteField","RadiosField","CheckboxesField","SelectField","YesNoField","DeclarationField","FileUploadField","EastingNorthingField","OsGridRefField","NationalGridFieldNumberField","LatLongField","HiddenField","ComponentToPreviewQuestion","component","definition","componentCoerced","list","_definition","mapComponentToPreviewQuestion","questionRenderer","questionElements","getQuestionElementsFunc","type","QuestionConstructor","previewComponent","id"],"sources":["../../../../../src/form/form-editor/preview/helpers.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport {\n hasContentField,\n hasInputField,\n hasListField,\n hasSelectionFields\n} from '~/src/components/helpers.js'\nimport { AutocompleteListQuestion } from '~/src/form/form-editor/preview/autocomplete.js'\nimport { CheckboxQuestion } from '~/src/form/form-editor/preview/checkbox.js'\nimport { ComponentElements } from '~/src/form/form-editor/preview/component-elements.js'\nimport { ContentElements } from '~/src/form/form-editor/preview/content.js'\nimport { DateInputQuestion } from '~/src/form/form-editor/preview/date-input.js'\nimport {\n DeclarationComponentPreviewElements,\n DeclarationQuestion\n} from '~/src/form/form-editor/preview/declaration.js'\nimport {\n EastingNorthingComponentPreviewElements,\n EastingNorthingQuestion\n} from '~/src/form/form-editor/preview/easting-northing.js'\nimport { EmailAddressQuestion } from '~/src/form/form-editor/preview/email-address.js'\nimport { HiddenQuestion } from '~/src/form/form-editor/preview/hidden.js'\nimport {\n LatLongComponentPreviewElements,\n LatLongQuestion\n} from '~/src/form/form-editor/preview/lat-long.js'\nimport {\n ListComponentElements,\n ListQuestion,\n SelectComponentElements\n} from '~/src/form/form-editor/preview/list.js'\nimport {\n LongAnswerQuestion,\n MultilineTextFieldComponentPreviewElements\n} from '~/src/form/form-editor/preview/long-answer.js'\nimport { Markdown } from '~/src/form/form-editor/preview/markdown.js'\nimport { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'\nimport {\n NationalGridComponentPreviewElements,\n NationalGridQuestion\n} from '~/src/form/form-editor/preview/national-grid.js'\nimport {\n NumberComponentPreviewElements,\n NumberOnlyQuestion\n} from '~/src/form/form-editor/preview/number-only.js'\nimport {\n OsGridRefComponentPreviewElements,\n OsGridRefQuestion\n} from '~/src/form/form-editor/preview/os-grid-ref.js'\nimport { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'\nimport { QuestionComponentElements } from '~/src/form/form-editor/preview/question.js'\nimport { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'\nimport { SelectQuestion } from '~/src/form/form-editor/preview/select.js'\nimport { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'\nimport { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'\nimport {\n UkAddressComponentPreviewElements,\n UkAddressQuestion\n} from '~/src/form/form-editor/preview/uk-address.js'\nimport { UnsupportedQuestion } from '~/src/form/form-editor/preview/unsupported-question.js'\nimport { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'\nimport { findDefinitionListFromComponent } from '~/src/form/utils/list.js'\n/**\n * @type {typeof PreviewComponent}\n */\nconst InvalidFieldComponent = UnsupportedQuestion\n\n/**\n * @type {Partial<Record<ComponentType, typeof PreviewComponent>>}\n */\nconst InputFieldComponentDictionary = {\n [ComponentType.TextField]: ShortAnswerQuestion,\n [ComponentType.Details]: ShortAnswerQuestion,\n [ComponentType.InsetText]: ShortAnswerQuestion,\n [ComponentType.Html]: ShortAnswerQuestion,\n [ComponentType.Markdown]: Markdown,\n [ComponentType.List]: ListQuestion,\n [ComponentType.EmailAddressField]: EmailAddressQuestion,\n [ComponentType.NumberField]: NumberOnlyQuestion,\n [ComponentType.MultilineTextField]: LongAnswerQuestion,\n [ComponentType.TelephoneNumberField]: PhoneNumberQuestion,\n [ComponentType.MonthYearField]: MonthYearQuestion,\n [ComponentType.DatePartsField]: DateInputQuestion,\n [ComponentType.UkAddressField]: UkAddressQuestion,\n [ComponentType.AutocompleteField]: AutocompleteListQuestion,\n [ComponentType.RadiosField]: RadioQuestion,\n [ComponentType.CheckboxesField]: CheckboxQuestion,\n [ComponentType.SelectField]: SelectQuestion,\n [ComponentType.YesNoField]: YesNoQuestion,\n [ComponentType.DeclarationField]: DeclarationQuestion,\n [ComponentType.FileUploadField]: SupportingEvidenceQuestion,\n [ComponentType.EastingNorthingField]: EastingNorthingQuestion,\n [ComponentType.OsGridRefField]: OsGridRefQuestion,\n [ComponentType.NationalGridFieldNumberField]: NationalGridQuestion,\n [ComponentType.LatLongField]: LatLongQuestion,\n [ComponentType.HiddenField]: HiddenQuestion\n}\n\n/**\n * @type {Partial<Record<ComponentType, (component: ComponentDef, definition: FormDefinition ) => QuestionElements>>}\n */\nconst ComponentToPreviewQuestion = {\n [ComponentType.AutocompleteField]: (component, definition) => {\n const componentCoerced = /** @type {AutocompleteFieldComponent} */ (\n component\n )\n const list = findDefinitionListFromComponent(componentCoerced, definition)\n return new SelectComponentElements(componentCoerced, list)\n },\n [ComponentType.SelectField]: (component, definition) => {\n const componentCoerced = /** @type {SelectFieldComponent} */ (component)\n const list = findDefinitionListFromComponent(componentCoerced, definition)\n return new SelectComponentElements(componentCoerced, list)\n },\n [ComponentType.MultilineTextField]: (component, _definition) => {\n const componentCoerced = /** @type {MultilineTextFieldComponent} */ (\n component\n )\n return new MultilineTextFieldComponentPreviewElements(componentCoerced)\n },\n [ComponentType.UkAddressField]: (component, _definition) => {\n const componentCoerced = /** @type {UkAddressFieldComponent} */ (component)\n return new UkAddressComponentPreviewElements(componentCoerced)\n },\n [ComponentType.NumberField]: (component, _definition) => {\n const componentCoerced = /** @type {NumberFieldComponent} */ (component)\n return new NumberComponentPreviewElements(componentCoerced)\n },\n [ComponentType.DeclarationField]: (component, _definition) => {\n const componentCoerced = /** @type {DeclarationFieldComponent} */ (\n component\n )\n return new DeclarationComponentPreviewElements(componentCoerced)\n },\n [ComponentType.YesNoField]: (component, _definition) => {\n const componentCoerced = /** @type {YesNoFieldComponent} */ (component)\n return new QuestionComponentElements(componentCoerced)\n },\n [ComponentType.EastingNorthingField]: (component, _definition) => {\n const componentCoerced = /** @type {EastingNorthingFieldComponent} */ (\n component\n )\n return new EastingNorthingComponentPreviewElements(componentCoerced)\n },\n [ComponentType.OsGridRefField]: (component, _definition) => {\n const componentCoerced = /** @type {OsGridRefFieldComponent} */ (component)\n return new OsGridRefComponentPreviewElements(componentCoerced)\n },\n [ComponentType.NationalGridFieldNumberField]: (component, _definition) => {\n const componentCoerced =\n /** @type {NationalGridFieldNumberFieldComponent} */ (component)\n return new NationalGridComponentPreviewElements(componentCoerced)\n },\n [ComponentType.LatLongField]: (component, _definition) => {\n const componentCoerced = /** @type {LatLongFieldComponent} */ (component)\n return new LatLongComponentPreviewElements(componentCoerced)\n }\n}\n\n/**\n * @param {QuestionRenderer} questionRenderer\n * @param {FormDefinition} definition\n * @returns {(component: ComponentDef) => Question}\n */\nexport function mapComponentToPreviewQuestion(questionRenderer, definition) {\n return /** @type {(component: ComponentDef) => Question} */ (\n (component) => {\n /**\n * @type {QuestionElements}\n */\n let questionElements\n\n // Look for one-to-one mapping first, then fallback if not found\n const getQuestionElementsFunc = ComponentToPreviewQuestion[component.type]\n if (getQuestionElementsFunc) {\n questionElements = getQuestionElementsFunc(component, definition)\n } else if (hasSelectionFields(component) && hasListField(component)) {\n const list = findDefinitionListFromComponent(component, definition)\n questionElements = new ListComponentElements(component, list)\n } else if (hasInputField(component)) {\n questionElements = new QuestionComponentElements(component)\n } else if (hasContentField(component)) {\n questionElements = new ContentElements(component)\n } else {\n questionElements = new ComponentElements(component)\n }\n\n const QuestionConstructor =\n InputFieldComponentDictionary[component.type] ?? InvalidFieldComponent\n const previewComponent = new QuestionConstructor(\n questionElements,\n questionRenderer\n )\n previewComponent.id = component.id\n return previewComponent\n }\n )\n}\n\n/**\n * @import { QuestionElements, QuestionRenderer } 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 } from '~/src/form/form-definition/types.js'\n * @import { AutocompleteFieldComponent, ComponentDef, DeclarationFieldComponent, EastingNorthingFieldComponent, LatLongFieldComponent, MultilineTextFieldComponent, NationalGridFieldNumberFieldComponent, NumberFieldComponent, OsGridRefFieldComponent, SelectFieldComponent, UkAddressFieldComponent, YesNoFieldComponent } from '~/src/components/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SACEC,eAAe,EACfC,aAAa,EACbC,YAAY,EACZC,kBAAkB;AAEpB,SAASC,wBAAwB;AACjC,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SACEC,mCAAmC,EACnCC,mBAAmB;AAErB,SACEC,uCAAuC,EACvCC,uBAAuB;AAEz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BAAmB,GACvBpC,6BAA6B,CAAC0B,SAAS,CAACS,IAAI,CAAC,IAAIpC,qBAAqB;IACxE,MAAMsC,gBAAgB,GAAG,IAAID,mBAAmB,CAC9CH,gBAAgB,EAChBD,gBACF,CAAC;IACDK,gBAAgB,CAACC,EAAE,GAAGZ,SAAS,CAACY,EAAE;IAClC,OAAOD,gBAAgB;EACzB,CAAC;AAEL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -24,6 +24,7 @@ export * from "./select-sortable.js";
|
|
|
24
24
|
export * from "./supporting-evidence.js";
|
|
25
25
|
export * from "./long-answer.js";
|
|
26
26
|
export * from "./uk-address.js";
|
|
27
|
+
export * from "./unsupported-question.js";
|
|
27
28
|
export * from "./yes-no.js";
|
|
28
29
|
export * from "./hidden.js";
|
|
29
30
|
export * from "./controller/page-controller-base.js";
|
|
@@ -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/declaration.js'\nexport * from '~/src/form/form-editor/preview/easting-northing.js'\nexport * from '~/src/form/form-editor/preview/email-address.js'\nexport * from '~/src/form/form-editor/preview/lat-long.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/national-grid.js'\nexport * from '~/src/form/form-editor/preview/number-only.js'\nexport * from '~/src/form/form-editor/preview/os-grid-ref.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/hidden.js'\nexport * from '~/src/form/form-editor/preview/controller/page-controller-base.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/summary-page-controller.js'\nexport * from '~/src/form/form-editor/preview/controller/reorder-questions-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;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/declaration.js'\nexport * from '~/src/form/form-editor/preview/easting-northing.js'\nexport * from '~/src/form/form-editor/preview/email-address.js'\nexport * from '~/src/form/form-editor/preview/lat-long.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/national-grid.js'\nexport * from '~/src/form/form-editor/preview/number-only.js'\nexport * from '~/src/form/form-editor/preview/os-grid-ref.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/unsupported-question.js'\nexport * from '~/src/form/form-editor/preview/yes-no.js'\nexport * from '~/src/form/form-editor/preview/hidden.js'\nexport * from '~/src/form/form-editor/preview/controller/page-controller-base.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/summary-page-controller.js'\nexport * from '~/src/form/form-editor/preview/controller/reorder-questions-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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PreviewComponent } from "./preview.js";
|
|
2
|
+
import { Question } from "./question.js";
|
|
3
|
+
export class UnsupportedQuestion extends Question {
|
|
4
|
+
/**
|
|
5
|
+
* @type {ComponentType}
|
|
6
|
+
*/
|
|
7
|
+
// @ts-expect-error - invalid component type
|
|
8
|
+
componentType = 'UnsupportedQuestion';
|
|
9
|
+
_questionTemplate = PreviewComponent.PATH + 'unsupportedquestion.njk';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import { ComponentType } from '~/src/components/enums.js'
|
|
14
|
+
*/
|
|
15
|
+
//# sourceMappingURL=unsupported-question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsupported-question.js","names":["PreviewComponent","Question","UnsupportedQuestion","componentType","_questionTemplate","PATH"],"sources":["../../../../../src/form/form-editor/preview/unsupported-question.js"],"sourcesContent":["import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'\nimport { Question } from '~/src/form/form-editor/preview/question.js'\n\nexport class UnsupportedQuestion extends Question {\n /**\n * @type {ComponentType}\n */\n // @ts-expect-error - invalid component type\n componentType = 'UnsupportedQuestion'\n _questionTemplate = PreviewComponent.PATH + 'unsupportedquestion.njk'\n}\n\n/**\n * @import { ComponentType } from '~/src/components/enums.js'\n */\n"],"mappings":"AAAA,SAASA,gBAAgB;AACzB,SAASC,QAAQ;AAEjB,OAAO,MAAMC,mBAAmB,SAASD,QAAQ,CAAC;EAChD;AACF;AACA;EACE;EACAE,aAAa,GAAG,qBAAqB;EACrCC,iBAAiB,GAAGJ,gBAAgB,CAACK,IAAI,GAAG,yBAAyB;AACvE;;AAEA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
|
-
import { type PaginationOptions } from '../../common/pagination/types.js';
|
|
2
|
+
import { type CreatePageHrefFn, type PaginationOptions, type PaginationPage } from '../../common/pagination/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Field definitions for pagination options.
|
|
5
5
|
*/
|
|
@@ -12,4 +12,13 @@ export declare const paginationOptionFields: {
|
|
|
12
12
|
* @see {@link PaginationOptions}
|
|
13
13
|
*/
|
|
14
14
|
export declare const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
17
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
18
|
+
* @param currentPage - The current page number
|
|
19
|
+
* @param totalPages - The total number of pages
|
|
20
|
+
* @param createHref - Function to generate href for each page number
|
|
21
|
+
* @returns Array of pagination page items
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildPaginationPages(currentPage: number, totalPages: number, createHref: CreatePageHrefFn): PaginationPage[];
|
|
15
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;CAgBlC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,GAAG,CAAC,YAAY,CAAC,iBAAiB,CACpC,CAAA;AAEpC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,gBAAgB,GAC3B,cAAc,EAAE,CA6ClB"}
|
|
@@ -24,4 +24,39 @@ export interface PaginationResult {
|
|
|
24
24
|
* Allows partial specification of page and perPage from PaginationResult
|
|
25
25
|
*/
|
|
26
26
|
export type PaginationOptions = Required<Pick<PaginationResult, 'page' | 'perPage'>>;
|
|
27
|
+
/**
|
|
28
|
+
* A single page item for the pagination component
|
|
29
|
+
*/
|
|
30
|
+
export interface PaginationPage {
|
|
31
|
+
/**
|
|
32
|
+
* The page number (if it's a page, not an ellipsis)
|
|
33
|
+
*/
|
|
34
|
+
number?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The URL for the page
|
|
37
|
+
*/
|
|
38
|
+
href?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether this page is the current page
|
|
41
|
+
*/
|
|
42
|
+
current?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether this entry is an ellipsis (gap indicator)
|
|
45
|
+
*/
|
|
46
|
+
ellipsis?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Callback function to generate href for a given page number
|
|
50
|
+
*/
|
|
51
|
+
export type CreatePageHrefFn = (pageNumber: number) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Pagination result with page items for the pagination component
|
|
54
|
+
* Extends PaginationResult with the pages array needed for rendering
|
|
55
|
+
*/
|
|
56
|
+
export interface PaginationResultWithPages extends PaginationResult {
|
|
57
|
+
/**
|
|
58
|
+
* Page items for the pagination component
|
|
59
|
+
*/
|
|
60
|
+
pages: PaginationPage[];
|
|
61
|
+
}
|
|
27
62
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CACtC,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAC3C,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/common/pagination/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CACtC,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAC3C,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAA;AAE7D;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IACjE;;OAEG;IACH,KAAK,EAAE,cAAc,EAAE,CAAA;CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/helpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/helpers.js"],"names":[],"mappings":"AA+JA;;;;GAIG;AACH,gEAJW,gBAAgB,cAChB,cAAc,GACZ,CAAC,SAAS,EAAE,YAAY,KAAK,QAAQ,CAmCjD;sCAGsD,yCAAyC;oCAG7D,qCAAqC;kCAC6P,2BAA2B;8BAHnU,4CAA4C"}
|
|
@@ -24,6 +24,7 @@ export * from "../../../form/form-editor/preview/select-sortable.js";
|
|
|
24
24
|
export * from "../../../form/form-editor/preview/supporting-evidence.js";
|
|
25
25
|
export * from "../../../form/form-editor/preview/long-answer.js";
|
|
26
26
|
export * from "../../../form/form-editor/preview/uk-address.js";
|
|
27
|
+
export * from "../../../form/form-editor/preview/unsupported-question.js";
|
|
27
28
|
export * from "../../../form/form-editor/preview/yes-no.js";
|
|
28
29
|
export * from "../../../form/form-editor/preview/hidden.js";
|
|
29
30
|
export * from "../../../form/form-editor/preview/controller/page-controller-base.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsupported-question.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/unsupported-question.js"],"names":[],"mappings":"AAGA;CAOC;yBATwB,4CAA4C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import Joi from 'joi'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type CreatePageHrefFn,
|
|
5
|
+
type PaginationOptions,
|
|
6
|
+
type PaginationPage
|
|
7
|
+
} from '~/src/common/pagination/types.js'
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Field definitions for pagination options.
|
|
@@ -29,3 +33,62 @@ export const paginationOptionFields = {
|
|
|
29
33
|
*/
|
|
30
34
|
export const paginationOptionsSchema: Joi.ObjectSchema<PaginationOptions> =
|
|
31
35
|
Joi.object(paginationOptionFields)
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Builds the pages array for the GOV.UK Design System pagination component.
|
|
39
|
+
* Shows first page, last page, current page, and adjacent pages with ellipsis for gaps.
|
|
40
|
+
* @param currentPage - The current page number
|
|
41
|
+
* @param totalPages - The total number of pages
|
|
42
|
+
* @param createHref - Function to generate href for each page number
|
|
43
|
+
* @returns Array of pagination page items
|
|
44
|
+
*/
|
|
45
|
+
export function buildPaginationPages(
|
|
46
|
+
currentPage: number,
|
|
47
|
+
totalPages: number,
|
|
48
|
+
createHref: CreatePageHrefFn
|
|
49
|
+
): PaginationPage[] {
|
|
50
|
+
const pages: PaginationPage[] = []
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a pagination page item
|
|
54
|
+
*/
|
|
55
|
+
function createPageItem(
|
|
56
|
+
pageNumber: number,
|
|
57
|
+
isCurrent = false
|
|
58
|
+
): PaginationPage {
|
|
59
|
+
return {
|
|
60
|
+
number: String(pageNumber),
|
|
61
|
+
href: createHref(pageNumber),
|
|
62
|
+
current: isCurrent
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Always show the first page
|
|
67
|
+
pages.push(createPageItem(1, currentPage === 1))
|
|
68
|
+
|
|
69
|
+
// Calculate adjacent page range (one before and one after current)
|
|
70
|
+
const adjacentStartPage = Math.max(currentPage - 1, 2)
|
|
71
|
+
const adjacentEndPage = Math.min(currentPage + 1, totalPages - 1)
|
|
72
|
+
|
|
73
|
+
// Add ellipsis after first page if needed
|
|
74
|
+
if (adjacentStartPage > 2) {
|
|
75
|
+
pages.push({ ellipsis: true })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Add pages between adjacentStartPage and adjacentEndPage
|
|
79
|
+
for (let i = adjacentStartPage; i <= adjacentEndPage; i++) {
|
|
80
|
+
pages.push(createPageItem(i, i === currentPage))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Add ellipsis before last page if needed
|
|
84
|
+
if (adjacentEndPage < totalPages - 1) {
|
|
85
|
+
pages.push({ ellipsis: true })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Always show the last page if totalPages > 1
|
|
89
|
+
if (totalPages > 1) {
|
|
90
|
+
pages.push(createPageItem(totalPages, currentPage === totalPages))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return pages
|
|
94
|
+
}
|
|
@@ -30,3 +30,44 @@ export interface PaginationResult {
|
|
|
30
30
|
export type PaginationOptions = Required<
|
|
31
31
|
Pick<PaginationResult, 'page' | 'perPage'>
|
|
32
32
|
>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A single page item for the pagination component
|
|
36
|
+
*/
|
|
37
|
+
export interface PaginationPage {
|
|
38
|
+
/**
|
|
39
|
+
* The page number (if it's a page, not an ellipsis)
|
|
40
|
+
*/
|
|
41
|
+
number?: string
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The URL for the page
|
|
45
|
+
*/
|
|
46
|
+
href?: string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether this page is the current page
|
|
50
|
+
*/
|
|
51
|
+
current?: boolean
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether this entry is an ellipsis (gap indicator)
|
|
55
|
+
*/
|
|
56
|
+
ellipsis?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Callback function to generate href for a given page number
|
|
61
|
+
*/
|
|
62
|
+
export type CreatePageHrefFn = (pageNumber: number) => string
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Pagination result with page items for the pagination component
|
|
66
|
+
* Extends PaginationResult with the pages array needed for rendering
|
|
67
|
+
*/
|
|
68
|
+
export interface PaginationResultWithPages extends PaginationResult {
|
|
69
|
+
/**
|
|
70
|
+
* Page items for the pagination component
|
|
71
|
+
*/
|
|
72
|
+
pages: PaginationPage[]
|
|
73
|
+
}
|
|
@@ -57,18 +57,19 @@ import {
|
|
|
57
57
|
UkAddressComponentPreviewElements,
|
|
58
58
|
UkAddressQuestion
|
|
59
59
|
} from '~/src/form/form-editor/preview/uk-address.js'
|
|
60
|
+
import { UnsupportedQuestion } from '~/src/form/form-editor/preview/unsupported-question.js'
|
|
60
61
|
import { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'
|
|
61
62
|
import { findDefinitionListFromComponent } from '~/src/form/utils/list.js'
|
|
62
63
|
/**
|
|
63
64
|
* @type {typeof PreviewComponent}
|
|
64
65
|
*/
|
|
65
|
-
const
|
|
66
|
+
const InvalidFieldComponent = UnsupportedQuestion
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* @type {Partial<Record<ComponentType, typeof PreviewComponent>>}
|
|
69
70
|
*/
|
|
70
71
|
const InputFieldComponentDictionary = {
|
|
71
|
-
[ComponentType.TextField]:
|
|
72
|
+
[ComponentType.TextField]: ShortAnswerQuestion,
|
|
72
73
|
[ComponentType.Details]: ShortAnswerQuestion,
|
|
73
74
|
[ComponentType.InsetText]: ShortAnswerQuestion,
|
|
74
75
|
[ComponentType.Html]: ShortAnswerQuestion,
|
|
@@ -185,8 +186,7 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
const QuestionConstructor =
|
|
188
|
-
InputFieldComponentDictionary[component.type] ??
|
|
189
|
-
InputFieldComponentDefault
|
|
189
|
+
InputFieldComponentDictionary[component.type] ?? InvalidFieldComponent
|
|
190
190
|
const previewComponent = new QuestionConstructor(
|
|
191
191
|
questionElements,
|
|
192
192
|
questionRenderer
|
|
@@ -24,6 +24,7 @@ export * from '~/src/form/form-editor/preview/select-sortable.js'
|
|
|
24
24
|
export * from '~/src/form/form-editor/preview/supporting-evidence.js'
|
|
25
25
|
export * from '~/src/form/form-editor/preview/long-answer.js'
|
|
26
26
|
export * from '~/src/form/form-editor/preview/uk-address.js'
|
|
27
|
+
export * from '~/src/form/form-editor/preview/unsupported-question.js'
|
|
27
28
|
export * from '~/src/form/form-editor/preview/yes-no.js'
|
|
28
29
|
export * from '~/src/form/form-editor/preview/hidden.js'
|
|
29
30
|
export * from '~/src/form/form-editor/preview/controller/page-controller-base.js'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
2
|
+
import { Question } from '~/src/form/form-editor/preview/question.js'
|
|
3
|
+
|
|
4
|
+
export class UnsupportedQuestion extends Question {
|
|
5
|
+
/**
|
|
6
|
+
* @type {ComponentType}
|
|
7
|
+
*/
|
|
8
|
+
// @ts-expect-error - invalid component type
|
|
9
|
+
componentType = 'UnsupportedQuestion'
|
|
10
|
+
_questionTemplate = PreviewComponent.PATH + 'unsupportedquestion.njk'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import { ComponentType } from '~/src/components/enums.js'
|
|
15
|
+
*/
|