@defra/forms-engine-plugin 5.0.0-alpha.3 → 5.0.0-alpha.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.
Files changed (100) hide show
  1. package/.public/javascripts/application.min.js +1 -1
  2. package/.public/javascripts/application.min.js.map +1 -1
  3. package/.public/javascripts/shared.min.js +1 -1
  4. package/.public/javascripts/shared.min.js.map +1 -1
  5. package/.server/client/javascripts/file-upload.js +5 -3
  6. package/.server/client/javascripts/file-upload.js.map +1 -1
  7. package/.server/client/javascripts/geospatial-map.js +31 -26
  8. package/.server/client/javascripts/geospatial-map.js.map +1 -1
  9. package/.server/client/javascripts/location-map.js +9 -1
  10. package/.server/client/javascripts/location-map.js.map +1 -1
  11. package/.server/client/javascripts/sssi-dataset.d.ts +18 -20
  12. package/.server/client/javascripts/sssi-dataset.js +37 -40
  13. package/.server/client/javascripts/sssi-dataset.js.map +1 -1
  14. package/.server/server/constants.d.ts +1 -0
  15. package/.server/server/constants.js +1 -0
  16. package/.server/server/constants.js.map +1 -1
  17. package/.server/server/plugins/engine/components/AutocompleteField.d.ts +1 -0
  18. package/.server/server/plugins/engine/components/ComponentBase.d.ts +1 -0
  19. package/.server/server/plugins/engine/components/ComponentBase.js +2 -0
  20. package/.server/server/plugins/engine/components/ComponentBase.js.map +1 -1
  21. package/.server/server/plugins/engine/components/ComponentCollection.js +2 -1
  22. package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
  23. package/.server/server/plugins/engine/components/DatePartsField.d.ts +1 -0
  24. package/.server/server/plugins/engine/components/DeclarationField.d.ts +1 -0
  25. package/.server/server/plugins/engine/components/DeclarationField.js +1 -1
  26. package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
  27. package/.server/server/plugins/engine/components/Details.d.ts +1 -0
  28. package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +2 -0
  29. package/.server/server/plugins/engine/components/EmailAddressField.d.ts +1 -0
  30. package/.server/server/plugins/engine/components/FileUploadField.js +2 -2
  31. package/.server/server/plugins/engine/components/FileUploadField.js.map +1 -1
  32. package/.server/server/plugins/engine/components/FormComponent.d.ts +1 -0
  33. package/.server/server/plugins/engine/components/FormComponent.js +2 -2
  34. package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
  35. package/.server/server/plugins/engine/components/GeospatialField.d.ts +1 -0
  36. package/.server/server/plugins/engine/components/Html.d.ts +1 -0
  37. package/.server/server/plugins/engine/components/InsetText.d.ts +1 -0
  38. package/.server/server/plugins/engine/components/LatLongField.d.ts +2 -0
  39. package/.server/server/plugins/engine/components/List.d.ts +1 -0
  40. package/.server/server/plugins/engine/components/ListFormComponent.d.ts +1 -0
  41. package/.server/server/plugins/engine/components/LocationFieldBase.d.ts +2 -0
  42. package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +2 -0
  43. package/.server/server/plugins/engine/components/Markdown.d.ts +1 -0
  44. package/.server/server/plugins/engine/components/Markdown.js +1 -1
  45. package/.server/server/plugins/engine/components/Markdown.js.map +1 -1
  46. package/.server/server/plugins/engine/components/MonthYearField.d.ts +1 -0
  47. package/.server/server/plugins/engine/components/MultilineTextField.d.ts +1 -0
  48. package/.server/server/plugins/engine/components/NotificationBanner.d.ts +1 -0
  49. package/.server/server/plugins/engine/components/NumberField.d.ts +1 -0
  50. package/.server/server/plugins/engine/components/PaymentField.d.ts +1 -0
  51. package/.server/server/plugins/engine/components/SelectField.d.ts +1 -0
  52. package/.server/server/plugins/engine/components/SelectionControlField.d.ts +1 -0
  53. package/.server/server/plugins/engine/components/TelephoneNumberField.d.ts +1 -0
  54. package/.server/server/plugins/engine/components/UkAddressField.d.ts +1 -0
  55. package/.server/server/plugins/engine/components/types.d.ts +1 -0
  56. package/.server/server/plugins/engine/components/types.js.map +1 -1
  57. package/.server/server/plugins/engine/i18n/translations/cy.json +37 -1
  58. package/.server/server/plugins/engine/i18n/translations/en-GB.json +9 -1
  59. package/.server/server/plugins/engine/i18n/types.d.ts +1 -0
  60. package/.server/server/plugins/engine/i18n/types.js.map +1 -1
  61. package/.server/server/plugins/engine/models/SummaryViewModel.js +7 -3
  62. package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
  63. package/.server/server/plugins/engine/outputFormatters/adapter/v1.js +3 -5
  64. package/.server/server/plugins/engine/outputFormatters/adapter/v1.js.map +1 -1
  65. package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js +20 -7
  66. package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js.map +1 -1
  67. package/.server/server/plugins/engine/pageControllers/RepeatPageController.js +3 -4
  68. package/.server/server/plugins/engine/pageControllers/RepeatPageController.js.map +1 -1
  69. package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +5 -2
  70. package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
  71. package/.server/server/plugins/engine/services/notifyService.d.ts +1 -1
  72. package/.server/server/plugins/engine/services/notifyService.js +1 -1
  73. package/.server/server/plugins/engine/services/notifyService.js.map +1 -1
  74. package/.server/server/plugins/engine/views/components/fileuploadfield.html +1 -1
  75. package/.server/server/types.d.ts +1 -1
  76. package/.server/server/types.js.map +1 -1
  77. package/package.json +2 -2
  78. package/src/client/javascripts/file-upload.js +10 -3
  79. package/src/client/javascripts/geospatial-map.js +32 -30
  80. package/src/client/javascripts/location-map.js +7 -1
  81. package/src/client/javascripts/sssi-dataset.js +39 -42
  82. package/src/server/constants.js +1 -0
  83. package/src/server/plugins/engine/components/ComponentBase.ts +2 -0
  84. package/src/server/plugins/engine/components/ComponentCollection.ts +4 -5
  85. package/src/server/plugins/engine/components/DeclarationField.ts +1 -2
  86. package/src/server/plugins/engine/components/FileUploadField.ts +2 -2
  87. package/src/server/plugins/engine/components/FormComponent.ts +2 -4
  88. package/src/server/plugins/engine/components/Markdown.ts +2 -3
  89. package/src/server/plugins/engine/components/types.ts +1 -0
  90. package/src/server/plugins/engine/i18n/translations/cy.json +37 -1
  91. package/src/server/plugins/engine/i18n/translations/en-GB.json +9 -1
  92. package/src/server/plugins/engine/i18n/types.ts +1 -0
  93. package/src/server/plugins/engine/models/SummaryViewModel.ts +4 -4
  94. package/src/server/plugins/engine/outputFormatters/adapter/v1.ts +3 -6
  95. package/src/server/plugins/engine/pageControllers/FileUploadPageController.ts +16 -6
  96. package/src/server/plugins/engine/pageControllers/RepeatPageController.ts +2 -2
  97. package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +7 -1
  98. package/src/server/plugins/engine/services/notifyService.ts +1 -0
  99. package/src/server/plugins/engine/views/components/fileuploadfield.html +1 -1
  100. package/src/server/types.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"location-map.js","names":["createDatasetsPlugin","EVENTS","centerMap","createMap","defaultConfig","eastingNorthingToLatLong","getMapLayers","latLongToEastingNorthing","latLongToOsGridRef","osGridRefToLatLong","sssiDataset","LOCATION_FIELD_SELECTOR","getInitMapConfig","locationField","locationType","dataset","locationtype","getInitLatLongMapConfig","getInitEastingNorthingMapConfig","getInitOsGridRefMapConfig","Error","validateLatLong","strLat","strLong","lat","trim","Number","long","valid","latMin","latMax","longMin","longMax","latInBounds","longInBounds","value","validateEastingNorthing","strEasting","strNorthing","easting","northing","eastingMin","eastingMax","northingMin","northingMax","validateOsGridRef","osGridRef","pattern","match","exec","getLatLongInputs","inputs","querySelectorAll","length","latInput","longInput","getEastingNorthingInputs","eastingInput","northingInput","getOsGridRefInput","input","querySelector","getInitMapCenterConfig","center","zoom","markers","id","coords","result","undefined","latlong","osGridRefInput","bindLatLongField","map","mapProvider","on","interactMarkerChange","onInteractMarkerChange","e","maxPrecision","toFixed","onUpdateInputs","addEventListener","bindEastingNorthingField","point","bindOsGridRefField","onUpdateInput","processLocation","config","location","index","HTMLDivElement","locationInputs","supportedLocations","includes","mapContainer","document","createElement","mapId","setAttribute","initConfig","after","mapLayers","maplayers","plugins","interactPlugin","mapReady","onMapReady","addPanel","focus","showLabel","label","mobile","slot","open","dismissible","modal","tablet","desktop","html","enable"],"sources":["../../../src/client/javascripts/location-map.js"],"sourcesContent":["// @ts-expect-error - no types\nimport createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'\n\nimport {\n EVENTS,\n centerMap,\n createMap,\n defaultConfig,\n eastingNorthingToLatLong,\n getMapLayers,\n latLongToEastingNorthing,\n latLongToOsGridRef,\n osGridRefToLatLong\n} from '~/src/client/javascripts/map.js'\nimport sssiDataset from '~/src/client/javascripts/sssi-dataset.js'\n\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\n\n/**\n * Gets initial map config for a location field\n * @param {HTMLDivElement} locationField - the location field element\n */\nfunction getInitMapConfig(locationField) {\n const locationType = locationField.dataset.locationtype\n\n switch (locationType) {\n case 'latlongfield':\n return getInitLatLongMapConfig(locationField)\n case 'eastingnorthingfield':\n return getInitEastingNorthingMapConfig(locationField)\n case 'osgridreffield':\n return getInitOsGridRefMapConfig(locationField)\n default:\n throw new Error('Not implemented')\n }\n}\n\n/**\n * Validates lat and long is numeric and within UK bounds\n * @param {string} strLat - the latitude string\n * @param {string} strLong - the longitude string\n * @returns {{ valid: false } | { valid: true, value: { lat: number, long: number } }}\n */\nfunction validateLatLong(strLat, strLong) {\n const lat = strLat.trim() && Number(strLat.trim())\n const long = strLong.trim() && Number(strLong.trim())\n\n if (!lat || !long) {\n return { valid: false }\n }\n\n const latMin = 49.85\n const latMax = 60.859\n const longMin = -13.687\n const longMax = 1.767\n\n const latInBounds = lat >= latMin && lat <= latMax\n const longInBounds = long >= longMin && long <= longMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { lat, long } }\n}\n\n/**\n * Validates easting and northing is numeric and within UK bounds\n * @param {string} strEasting - the easting string\n * @param {string} strNorthing - the northing string\n * @returns {{ valid: false } | { valid: true, value: { easting: number, northing: number } }}\n */\nfunction validateEastingNorthing(strEasting, strNorthing) {\n const easting = strEasting.trim() && Number(strEasting.trim())\n const northing = strNorthing.trim() && Number(strNorthing.trim())\n\n if (!easting || !northing) {\n return { valid: false }\n }\n\n const eastingMin = 0\n const eastingMax = 700000\n const northingMin = 0\n const northingMax = 1300000\n\n const latInBounds = easting >= eastingMin && easting <= eastingMax\n const longInBounds = northing >= northingMin && northing <= northingMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { easting, northing } }\n}\n\n/**\n * Validates OS grid reference is correct\n * @param {string} osGridRef - the OsGridRef\n * @returns {{ valid: false } | { valid: true, value: string }}\n */\nfunction validateOsGridRef(osGridRef) {\n if (!osGridRef) {\n return { valid: false }\n }\n\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?(([0-9]{3})\\s?([0-9]{3})|([0-9]{4})\\s?([0-9]{4})|([0-9]{5})\\s?([0-9]{5}))$/\n\n const match = pattern.exec(osGridRef)\n\n if (match === null) {\n return { valid: false }\n }\n\n return { valid: true, value: match[0] }\n}\n\n/**\n * Gets the inputs for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n */\nfunction getLatLongInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for lat and long')\n }\n\n const latInput = /** @type {HTMLInputElement} */ (inputs[0])\n const longInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { latInput, longInput }\n}\n\n/**\n * Gets the inputs for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n */\nfunction getEastingNorthingInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for easting and northing')\n }\n\n const eastingInput = /** @type {HTMLInputElement} */ (inputs[0])\n const northingInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { eastingInput, northingInput }\n}\n\n/**\n * Gets the input for a OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n */\nfunction getOsGridRefInput(locationField) {\n const input = locationField.querySelector(LOCATION_FIELD_SELECTOR)\n\n if (input === null) {\n throw new Error('Expected 1 input for osgridref')\n }\n\n return /** @type {HTMLInputElement} */ (input)\n}\n\n/**\n * Get the initial map config for a center point\n * @param {MapCenter} center - the point\n */\nfunction getInitMapCenterConfig(center) {\n return {\n zoom: '16',\n center,\n markers: [\n {\n id: 'location',\n coords: center\n }\n ]\n }\n}\n\n/**\n * Gets initial map config for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitLatLongMapConfig(locationField) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitEastingNorthingMapConfig(locationField) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for an OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitOsGridRefMapConfig(locationField) {\n const osGridRefInput = getOsGridRefInput(locationField)\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Bind a latlong field to the map\n * @param {HTMLDivElement} locationField - the latlong location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindLatLongField(locationField, map, mapProvider) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 7\n latInput.value = e.coords[1].toFixed(maxPrecision)\n longInput.value = e.coords[0].toFixed(maxPrecision)\n }\n )\n\n /**\n * Lat & long input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (result.valid) {\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n latInput.addEventListener('change', onUpdateInputs, false)\n longInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an eastingnorthing field to the map\n * @param {HTMLDivElement} locationField - the eastingnorthing location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindEastingNorthingField(locationField, map, mapProvider) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 0\n const point = latLongToEastingNorthing({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n eastingInput.value = point.easting.toFixed(maxPrecision)\n northingInput.value = point.northing.toFixed(maxPrecision)\n }\n )\n\n /**\n * Easting & northing input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (result.valid) {\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n eastingInput.addEventListener('change', onUpdateInputs, false)\n northingInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an OS grid reference field to the map\n * @param {HTMLDivElement} locationField - the osgridref location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindOsGridRefField(locationField, map, mapProvider) {\n const osGridRefInput = getOsGridRefInput(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const point = latLongToOsGridRef({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n osGridRefInput.value = point\n }\n )\n\n /**\n * OS grid reference input change event listener\n * Update the map view location when the input is changed\n */\n function onUpdateInput() {\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (result.valid) {\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n osGridRefInput.addEventListener('change', onUpdateInput, false)\n}\n\n/**\n * Processes a location field to add map capability\n * @param {MapsEnvironmentConfig} config - the location field element\n * @param {Element} location - the location field element\n * @param {number} index - the 0-based index\n */\nexport function processLocation(config, location, index) {\n if (!(location instanceof HTMLDivElement)) {\n return\n }\n\n const locationInputs = location.querySelector('.app-location-field-inputs')\n if (!(locationInputs instanceof HTMLDivElement)) {\n return\n }\n const locationType = location.dataset.locationtype\n\n // Check for support\n const supportedLocations = [\n 'latlongfield',\n 'eastingnorthingfield',\n 'osgridreffield'\n ]\n if (!locationType || !supportedLocations.includes(locationType)) {\n return\n }\n\n const mapContainer = document.createElement('div')\n const mapId = `map_${index}`\n\n mapContainer.setAttribute('id', mapId)\n mapContainer.setAttribute('class', 'map-container')\n\n const initConfig = getInitMapConfig(location) ?? defaultConfig\n\n locationInputs.after(mapContainer)\n\n const mapLayers = getMapLayers(location.dataset.maplayers)\n\n if (mapLayers.includes('sssi')) {\n initConfig.plugins = [createDatasetsPlugin(sssiDataset)]\n }\n\n const { map, interactPlugin } = createMap(mapId, initConfig, config)\n\n map.on(\n EVENTS.mapReady,\n /**\n * Callback function which fires when the map is ready\n * @param {object} e - the event\n * @param {MapLibreMap} e.map - the map provider instance\n */\n function onMapReady(e) {\n switch (locationType) {\n case 'latlongfield':\n bindLatLongField(location, map, e.map)\n break\n case 'eastingnorthingfield':\n bindEastingNorthingField(location, map, e.map)\n break\n case 'osgridreffield':\n bindOsGridRefField(location, map, e.map)\n break\n default:\n throw new Error('Not implemented')\n }\n\n // Add info panel\n map.addPanel('info', {\n focus: false,\n showLabel: true,\n label: 'How to use the map',\n mobile: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n tablet: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n desktop: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n html: '<ul><li>Search for a place or postcode</li><li>Use the + and - icons to zoom in and out</li><li>Use a mouse or keyboard to centre the point at the location</li><li>Click to add the location to the map</li></ul>'\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\n )\n}\n\n/**\n * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'\n */\n"],"mappings":"AAAA;AACA,OAAOA,oBAAoB,MAAM,yCAAyC;AAE1E,SACEC,MAAM,EACNC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,YAAY,EACZC,wBAAwB,EACxBC,kBAAkB,EAClBC,kBAAkB;AAEpB,OAAOC,WAAW;AAElB,MAAMC,uBAAuB,GAAG,mBAAmB;;AAE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centerMap","createMap","defaultConfig","eastingNorthingToLatLong","getMapLayers","latLongToEastingNorthing","latLongToOsGridRef","osGridRefToLatLong","sssiDataset","LOCATION_FIELD_SELECTOR","getInitMapConfig","locationField","locationType","dataset","locationtype","getInitLatLongMapConfig","getInitEastingNorthingMapConfig","getInitOsGridRefMapConfig","Error","validateLatLong","strLat","strLong","lat","trim","Number","long","valid","latMin","latMax","longMin","longMax","latInBounds","longInBounds","value","validateEastingNorthing","strEasting","strNorthing","easting","northing","eastingMin","eastingMax","northingMin","northingMax","validateOsGridRef","osGridRef","pattern","match","exec","getLatLongInputs","inputs","querySelectorAll","length","latInput","longInput","getEastingNorthingInputs","eastingInput","northingInput","getOsGridRefInput","input","querySelector","getInitMapCenterConfig","center","zoom","markers","id","coords","result","undefined","latlong","osGridRefInput","bindLatLongField","map","mapProvider","on","interactMarkerChange","onInteractMarkerChange","e","maxPrecision","toFixed","onUpdateInputs","addEventListener","bindEastingNorthingField","point","bindOsGridRefField","onUpdateInput","processLocation","config","location","index","HTMLDivElement","locationInputs","supportedLocations","includes","mapContainer","document","createElement","mapId","setAttribute","initConfig","after","datasets","mapLayers","maplayers","push","plugins","interactPlugin","mapReady","onMapReady","addPanel","focus","showLabel","label","mobile","slot","open","dismissible","modal","tablet","desktop","html","enable"],"sources":["../../../src/client/javascripts/location-map.js"],"sourcesContent":["// @ts-expect-error - no types\nimport createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'\n\nimport {\n EVENTS,\n centerMap,\n createMap,\n defaultConfig,\n eastingNorthingToLatLong,\n getMapLayers,\n latLongToEastingNorthing,\n latLongToOsGridRef,\n osGridRefToLatLong\n} from '~/src/client/javascripts/map.js'\nimport sssiDataset from '~/src/client/javascripts/sssi-dataset.js'\n\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\n\n/**\n * Gets initial map config for a location field\n * @param {HTMLDivElement} locationField - the location field element\n */\nfunction getInitMapConfig(locationField) {\n const locationType = locationField.dataset.locationtype\n\n switch (locationType) {\n case 'latlongfield':\n return getInitLatLongMapConfig(locationField)\n case 'eastingnorthingfield':\n return getInitEastingNorthingMapConfig(locationField)\n case 'osgridreffield':\n return getInitOsGridRefMapConfig(locationField)\n default:\n throw new Error('Not implemented')\n }\n}\n\n/**\n * Validates lat and long is numeric and within UK bounds\n * @param {string} strLat - the latitude string\n * @param {string} strLong - the longitude string\n * @returns {{ valid: false } | { valid: true, value: { lat: number, long: number } }}\n */\nfunction validateLatLong(strLat, strLong) {\n const lat = strLat.trim() && Number(strLat.trim())\n const long = strLong.trim() && Number(strLong.trim())\n\n if (!lat || !long) {\n return { valid: false }\n }\n\n const latMin = 49.85\n const latMax = 60.859\n const longMin = -13.687\n const longMax = 1.767\n\n const latInBounds = lat >= latMin && lat <= latMax\n const longInBounds = long >= longMin && long <= longMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { lat, long } }\n}\n\n/**\n * Validates easting and northing is numeric and within UK bounds\n * @param {string} strEasting - the easting string\n * @param {string} strNorthing - the northing string\n * @returns {{ valid: false } | { valid: true, value: { easting: number, northing: number } }}\n */\nfunction validateEastingNorthing(strEasting, strNorthing) {\n const easting = strEasting.trim() && Number(strEasting.trim())\n const northing = strNorthing.trim() && Number(strNorthing.trim())\n\n if (!easting || !northing) {\n return { valid: false }\n }\n\n const eastingMin = 0\n const eastingMax = 700000\n const northingMin = 0\n const northingMax = 1300000\n\n const latInBounds = easting >= eastingMin && easting <= eastingMax\n const longInBounds = northing >= northingMin && northing <= northingMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { easting, northing } }\n}\n\n/**\n * Validates OS grid reference is correct\n * @param {string} osGridRef - the OsGridRef\n * @returns {{ valid: false } | { valid: true, value: string }}\n */\nfunction validateOsGridRef(osGridRef) {\n if (!osGridRef) {\n return { valid: false }\n }\n\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?(([0-9]{3})\\s?([0-9]{3})|([0-9]{4})\\s?([0-9]{4})|([0-9]{5})\\s?([0-9]{5}))$/\n\n const match = pattern.exec(osGridRef)\n\n if (match === null) {\n return { valid: false }\n }\n\n return { valid: true, value: match[0] }\n}\n\n/**\n * Gets the inputs for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n */\nfunction getLatLongInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for lat and long')\n }\n\n const latInput = /** @type {HTMLInputElement} */ (inputs[0])\n const longInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { latInput, longInput }\n}\n\n/**\n * Gets the inputs for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n */\nfunction getEastingNorthingInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for easting and northing')\n }\n\n const eastingInput = /** @type {HTMLInputElement} */ (inputs[0])\n const northingInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { eastingInput, northingInput }\n}\n\n/**\n * Gets the input for a OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n */\nfunction getOsGridRefInput(locationField) {\n const input = locationField.querySelector(LOCATION_FIELD_SELECTOR)\n\n if (input === null) {\n throw new Error('Expected 1 input for osgridref')\n }\n\n return /** @type {HTMLInputElement} */ (input)\n}\n\n/**\n * Get the initial map config for a center point\n * @param {MapCenter} center - the point\n */\nfunction getInitMapCenterConfig(center) {\n return {\n zoom: '16',\n center,\n markers: [\n {\n id: 'location',\n coords: center\n }\n ]\n }\n}\n\n/**\n * Gets initial map config for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitLatLongMapConfig(locationField) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitEastingNorthingMapConfig(locationField) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for an OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitOsGridRefMapConfig(locationField) {\n const osGridRefInput = getOsGridRefInput(locationField)\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Bind a latlong field to the map\n * @param {HTMLDivElement} locationField - the latlong location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindLatLongField(locationField, map, mapProvider) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 7\n latInput.value = e.coords[1].toFixed(maxPrecision)\n longInput.value = e.coords[0].toFixed(maxPrecision)\n }\n )\n\n /**\n * Lat & long input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (result.valid) {\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n latInput.addEventListener('change', onUpdateInputs, false)\n longInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an eastingnorthing field to the map\n * @param {HTMLDivElement} locationField - the eastingnorthing location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindEastingNorthingField(locationField, map, mapProvider) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 0\n const point = latLongToEastingNorthing({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n eastingInput.value = point.easting.toFixed(maxPrecision)\n northingInput.value = point.northing.toFixed(maxPrecision)\n }\n )\n\n /**\n * Easting & northing input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (result.valid) {\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n eastingInput.addEventListener('change', onUpdateInputs, false)\n northingInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an OS grid reference field to the map\n * @param {HTMLDivElement} locationField - the osgridref location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindOsGridRefField(locationField, map, mapProvider) {\n const osGridRefInput = getOsGridRefInput(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const point = latLongToOsGridRef({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n osGridRefInput.value = point\n }\n )\n\n /**\n * OS grid reference input change event listener\n * Update the map view location when the input is changed\n */\n function onUpdateInput() {\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (result.valid) {\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n osGridRefInput.addEventListener('change', onUpdateInput, false)\n}\n\n/**\n * Processes a location field to add map capability\n * @param {MapsEnvironmentConfig} config - the location field element\n * @param {Element} location - the location field element\n * @param {number} index - the 0-based index\n */\nexport function processLocation(config, location, index) {\n if (!(location instanceof HTMLDivElement)) {\n return\n }\n\n const locationInputs = location.querySelector('.app-location-field-inputs')\n if (!(locationInputs instanceof HTMLDivElement)) {\n return\n }\n const locationType = location.dataset.locationtype\n\n // Check for support\n const supportedLocations = [\n 'latlongfield',\n 'eastingnorthingfield',\n 'osgridreffield'\n ]\n if (!locationType || !supportedLocations.includes(locationType)) {\n return\n }\n\n const mapContainer = document.createElement('div')\n const mapId = `map_${index}`\n\n mapContainer.setAttribute('id', mapId)\n mapContainer.setAttribute('class', 'map-container')\n\n const initConfig = getInitMapConfig(location) ?? defaultConfig\n\n locationInputs.after(mapContainer)\n\n const datasets = []\n const mapLayers = getMapLayers(location.dataset.maplayers)\n\n if (mapLayers.includes('sssi')) {\n datasets.push(...sssiDataset)\n }\n\n // Create a map dataset plugin if there are any present\n if (datasets.length) {\n initConfig.plugins = [createDatasetsPlugin({ datasets })]\n }\n\n const { map, interactPlugin } = createMap(mapId, initConfig, config)\n\n map.on(\n EVENTS.mapReady,\n /**\n * Callback function which fires when the map is ready\n * @param {object} e - the event\n * @param {MapLibreMap} e.map - the map provider instance\n */\n function onMapReady(e) {\n switch (locationType) {\n case 'latlongfield':\n bindLatLongField(location, map, e.map)\n break\n case 'eastingnorthingfield':\n bindEastingNorthingField(location, map, e.map)\n break\n case 'osgridreffield':\n bindOsGridRefField(location, map, e.map)\n break\n default:\n throw new Error('Not implemented')\n }\n\n // Add info panel\n map.addPanel('info', {\n focus: false,\n showLabel: true,\n label: 'How to use the map',\n mobile: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n tablet: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n desktop: {\n slot: 'drawer',\n open: true,\n dismissible: true,\n modal: false\n },\n html: '<ul><li>Search for a place or postcode</li><li>Use the + and - icons to zoom in and out</li><li>Use a mouse or keyboard to centre the point at the location</li><li>Click to add the location to the map</li></ul>'\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\n )\n}\n\n/**\n * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'\n */\n"],"mappings":"AAAA;AACA,OAAOA,oBAAoB,MAAM,yCAAyC;AAE1E,SACEC,MAAM,EACNC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,YAAY,EACZC,wBAAwB,EACxBC,kBAAkB,EAClBC,kBAAkB;AAEpB,OAAOC,WAAW;AAElB,MAAMC,uBAAuB,GAAG,mBAAmB;;AAEnD;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CAACC,aAAa,EAAE;EACvC,MAAMC,YAAY,GAAGD,aAAa,CAACE,OAAO,CAACC,YAAY;EAEvD,QAAQF,YAAY;IAClB,KAAK,cAAc;MACjB,OAAOG,uBAAuB,CAACJ,aAAa,CAAC;IAC/C,KAAK,sBAAsB;MACzB,OAAOK,+BAA+B,CAACL,aAAa,CAAC;IACvD,KAAK,gBAAgB;MACnB,OAAOM,yBAAyB,CAACN,aAAa,CAAC;IACjD;MACE,MAAM,IAAIO,KAAK,CAAC,iBAAiB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;MAClB,KAAK,cAAc;QACjB0D,gBAAgB,CAACiB,QAAQ,EAAEhB,GAAG,EAAEK,CAAC,CAACL,GAAG,CAAC;QACtC;MACF,KAAK,sBAAsB;QACzBU,wBAAwB,CAACM,QAAQ,EAAEhB,GAAG,EAAEK,CAAC,CAACL,GAAG,CAAC;QAC9C;MACF,KAAK,gBAAgB;QACnBY,kBAAkB,CAACI,QAAQ,EAAEhB,GAAG,EAAEK,CAAC,CAACL,GAAG,CAAC;QACxC;MACF;QACE,MAAM,IAAIrD,KAAK,CAAC,iBAAiB,CAAC;IACtC;;IAEA;IACAqD,GAAG,CAACqC,QAAQ,CAAC,MAAM,EAAE;MACnBC,KAAK,EAAE,KAAK;MACZC,SAAS,EAAE,IAAI;MACfC,KAAK,EAAE,oBAAoB;MAC3BC,MAAM,EAAE;QACNC,IAAI,EAAE,QAAQ;QACdC,IAAI,EAAE,IAAI;QACVC,WAAW,EAAE,IAAI;QACjBC,KAAK,EAAE;MACT,CAAC;MACDC,MAAM,EAAE;QACNJ,IAAI,EAAE,QAAQ;QACdC,IAAI,EAAE,IAAI;QACVC,WAAW,EAAE,IAAI;QACjBC,KAAK,EAAE;MACT,CAAC;MACDE,OAAO,EAAE;QACPL,IAAI,EAAE,QAAQ;QACdC,IAAI,EAAE,IAAI;QACVC,WAAW,EAAE,IAAI;QACjBC,KAAK,EAAE;MACT,CAAC;MACDG,IAAI,EAAE;IACR,CAAC,CAAC;;IAEF;IACAd,cAAc,CAACe,MAAM,CAAC,CAAC;EACzB,CACF,CAAC;AACH;;AAEA;AACA;AACA","ignoreList":[]}
@@ -1,26 +1,24 @@
1
1
  export function sssiEnglandRequestTransformer(url: string, options: TransformRequestOptions): any;
2
2
  export function sssiWalesRequestTransformer(url: string, options: TransformRequestOptions): any;
3
3
  export function sssiScotlandRequestTransformer(url: string, options: TransformRequestOptions): any;
4
- declare namespace _default {
5
- let datasets: {
6
- id: string;
7
- label: string;
8
- dynamicGeoJSON: {
9
- url: string;
10
- idProperty: string;
11
- transformRequest: typeof sssiEnglandRequestTransformer;
12
- };
13
- minZoom: number;
14
- style: {
15
- stroke: string;
16
- fillPattern: string;
17
- fillPatternForegroundColor: string;
18
- fillPatternBackgroundColor: string;
19
- };
20
- showInKey: boolean;
21
- showInMenu: boolean;
22
- }[];
23
- }
4
+ declare const _default: {
5
+ id: string;
6
+ label: string;
7
+ dynamicGeoJSON: {
8
+ url: string;
9
+ idProperty: string;
10
+ transformRequest: typeof sssiEnglandRequestTransformer;
11
+ };
12
+ minZoom: number;
13
+ style: {
14
+ stroke: string;
15
+ fillPattern: string;
16
+ fillPatternForegroundColor: string;
17
+ fillPatternBackgroundColor: string;
18
+ };
19
+ showInKey: boolean;
20
+ showInMenu: boolean;
21
+ }[];
24
22
  export default _default;
25
23
  export type TransformRequestOptions = {
26
24
  /**
@@ -47,46 +47,43 @@ export function sssiScotlandRequestTransformer(url, {
47
47
  url: uri.toString()
48
48
  };
49
49
  }
50
- export default {
51
- datasets: [{
52
- id: 'sssi-england',
53
- label: 'Sites of Special Scientific Interest',
54
- dynamicGeoJSON: {
55
- url: englandWFS,
56
- idProperty: 'ref_code',
57
- transformRequest: sssiEnglandRequestTransformer
58
- },
59
- minZoom,
60
- style,
61
- showInKey: true,
62
- showInMenu: false
63
- }, {
64
- id: 'sssi-wales',
65
- label: 'SSSI Wales',
66
- dynamicGeoJSON: {
67
- url: walesWFS,
68
- idProperty: 'id',
69
- transformRequest: sssiWalesRequestTransformer
70
- },
71
- minZoom,
72
- style,
73
- showInKey: false,
74
- showInMenu: false
75
- }, {
76
- id: 'sssi-scotland',
77
- label: 'SSSI Scotland',
78
- dynamicGeoJSON: {
79
- url: scotlandWFS,
80
- idProperty: 'OBJECTID',
81
- transformRequest: sssiScotlandRequestTransformer
82
- },
83
- minZoom,
84
- style,
85
- showInKey: false,
86
- showInMenu: false
87
- }]
88
- };
89
-
50
+ export default [{
51
+ id: 'sssi-england',
52
+ label: 'Sites of Special Scientific Interest',
53
+ dynamicGeoJSON: {
54
+ url: englandWFS,
55
+ idProperty: 'ref_code',
56
+ transformRequest: sssiEnglandRequestTransformer
57
+ },
58
+ minZoom,
59
+ style,
60
+ showInKey: true,
61
+ showInMenu: false
62
+ }, {
63
+ id: 'sssi-wales',
64
+ label: 'SSSI Wales',
65
+ dynamicGeoJSON: {
66
+ url: walesWFS,
67
+ idProperty: 'id',
68
+ transformRequest: sssiWalesRequestTransformer
69
+ },
70
+ minZoom,
71
+ style,
72
+ showInKey: false,
73
+ showInMenu: false
74
+ }, {
75
+ id: 'sssi-scotland',
76
+ label: 'SSSI Scotland',
77
+ dynamicGeoJSON: {
78
+ url: scotlandWFS,
79
+ idProperty: 'OBJECTID',
80
+ transformRequest: sssiScotlandRequestTransformer
81
+ },
82
+ minZoom,
83
+ style,
84
+ showInKey: false,
85
+ showInMenu: false
86
+ }];
90
87
  /**
91
88
  * @typedef {object} TransformRequestOptions
92
89
  * @property {string[]} bbox - the bounding box coordinates
@@ -1 +1 @@
1
- {"version":3,"file":"sssi-dataset.js","names":["style","stroke","fillPattern","fillPatternForegroundColor","fillPatternBackgroundColor","minZoom","englandWFS","walesWFS","scotlandWFS","sssiEnglandRequestTransformer","url","bbox","uri","URL","searchParams","set","join","toString","sssiWalesRequestTransformer","sssiScotlandRequestTransformer","datasets","id","label","dynamicGeoJSON","idProperty","transformRequest","showInKey","showInMenu"],"sources":["../../../src/client/javascripts/sssi-dataset.js"],"sourcesContent":["const style = {\n stroke: '#00897B',\n fillPattern: 'diagonal-cross-hatch',\n fillPatternForegroundColor: '#00897B',\n fillPatternBackgroundColor: 'transparent'\n}\nconst minZoom = 12\n\nconst englandWFS =\n 'https://environment.data.gov.uk/geoservices/datasets/ba8dc201-66ef-4983-9d46-7378af21027e/ogc/features/v1/collections/Sites_of_Special_Scientific_Interest_England/items?f=json'\nconst walesWFS =\n 'https://datamap.gov.wales/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeNames=inspire-nrw:NRW_SSSI&outputFormat=application/json&srsName=EPSG:4326'\nconst scotlandWFS =\n 'https://services1.arcgis.com/LM9GyVFsughzHdbO/ArcGIS/rest/services/Sites_of_Special_Scientific_Interest/FeatureServer/0/query?f=geojson&where=1%3D1&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects&returnGeometry=true&outFields=*'\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiEnglandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiWalesRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', `${bbox.join(',')},EPSG:4326`)\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiScotlandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('geometry', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\nexport default {\n datasets: [\n {\n id: 'sssi-england',\n label: 'Sites of Special Scientific Interest',\n dynamicGeoJSON: {\n url: englandWFS,\n idProperty: 'ref_code',\n transformRequest: sssiEnglandRequestTransformer\n },\n minZoom,\n style,\n showInKey: true,\n showInMenu: false\n },\n {\n id: 'sssi-wales',\n label: 'SSSI Wales',\n dynamicGeoJSON: {\n url: walesWFS,\n idProperty: 'id',\n transformRequest: sssiWalesRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n },\n {\n id: 'sssi-scotland',\n label: 'SSSI Scotland',\n dynamicGeoJSON: {\n url: scotlandWFS,\n idProperty: 'OBJECTID',\n transformRequest: sssiScotlandRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n }\n ]\n}\n\n/**\n * @typedef {object} TransformRequestOptions\n * @property {string[]} bbox - the bounding box coordinates\n */\n\n/**\n * Transforms the request URL with bounding box parameters\n * @callback TransformRequestArgs\n * @param {string} url - the request URL\n * @param {TransformRequestOptions} options - the bounding box coordinates\n */\n"],"mappings":"AAAA,MAAMA,KAAK,GAAG;EACZC,MAAM,EAAE,SAAS;EACjBC,WAAW,EAAE,sBAAsB;EACnCC,0BAA0B,EAAE,SAAS;EACrCC,0BAA0B,EAAE;AAC9B,CAAC;AACD,MAAMC,OAAO,GAAG,EAAE;AAElB,MAAMC,UAAU,GACd,iLAAiL;AACnL,MAAMC,QAAQ,GACZ,qKAAqK;AACvK,MAAMC,WAAW,GACf,qQAAqQ;;AAEvQ;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,GAAG,EAAE;EAAEC;AAAK,CAAC,EAAE;EAC3D,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACH,GAAG,CAAC;EACxBE,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,MAAM,EAAEJ,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC;EAE5C,OAAO;IACLN,GAAG,EAAEE,GAAG,CAACK,QAAQ,CAAC;EACpB,CAAC;AACH;;AAEA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CAACR,GAAG,EAAE;EAAEC;AAAK,CAAC,EAAE;EACzD,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACH,GAAG,CAAC;EACxBE,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,MAAM,EAAE,GAAGJ,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;EAE3D,OAAO;IACLN,GAAG,EAAEE,GAAG,CAACK,QAAQ,CAAC;EACpB,CAAC;AACH;;AAEA;AACA;AACA;AACA,OAAO,SAASE,8BAA8BA,CAACT,GAAG,EAAE;EAAEC;AAAK,CAAC,EAAE;EAC5D,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACH,GAAG,CAAC;EACxBE,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,UAAU,EAAEJ,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC;EAEhD,OAAO;IACLN,GAAG,EAAEE,GAAG,CAACK,QAAQ,CAAC;EACpB,CAAC;AACH;AAEA,eAAe;EACbG,QAAQ,EAAE,CACR;IACEC,EAAE,EAAE,cAAc;IAClBC,KAAK,EAAE,sCAAsC;IAC7CC,cAAc,EAAE;MACdb,GAAG,EAAEJ,UAAU;MACfkB,UAAU,EAAE,UAAU;MACtBC,gBAAgB,EAAEhB;IACpB,CAAC;IACDJ,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,IAAI;IACfC,UAAU,EAAE;EACd,CAAC,EACD;IACEN,EAAE,EAAE,YAAY;IAChBC,KAAK,EAAE,YAAY;IACnBC,cAAc,EAAE;MACdb,GAAG,EAAEH,QAAQ;MACbiB,UAAU,EAAE,IAAI;MAChBC,gBAAgB,EAAEP;IACpB,CAAC;IACDb,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,KAAK;IAChBC,UAAU,EAAE;EACd,CAAC,EACD;IACEN,EAAE,EAAE,eAAe;IACnBC,KAAK,EAAE,eAAe;IACtBC,cAAc,EAAE;MACdb,GAAG,EAAEF,WAAW;MAChBgB,UAAU,EAAE,UAAU;MACtBC,gBAAgB,EAAEN;IACpB,CAAC;IACDd,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,KAAK;IAChBC,UAAU,EAAE;EACd,CAAC;AAEL,CAAC;;AAED;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"sssi-dataset.js","names":["style","stroke","fillPattern","fillPatternForegroundColor","fillPatternBackgroundColor","minZoom","englandWFS","walesWFS","scotlandWFS","sssiEnglandRequestTransformer","url","bbox","uri","URL","searchParams","set","join","toString","sssiWalesRequestTransformer","sssiScotlandRequestTransformer","id","label","dynamicGeoJSON","idProperty","transformRequest","showInKey","showInMenu"],"sources":["../../../src/client/javascripts/sssi-dataset.js"],"sourcesContent":["const style = {\n stroke: '#00897B',\n fillPattern: 'diagonal-cross-hatch',\n fillPatternForegroundColor: '#00897B',\n fillPatternBackgroundColor: 'transparent'\n}\nconst minZoom = 12\n\nconst englandWFS =\n 'https://environment.data.gov.uk/geoservices/datasets/ba8dc201-66ef-4983-9d46-7378af21027e/ogc/features/v1/collections/Sites_of_Special_Scientific_Interest_England/items?f=json'\nconst walesWFS =\n 'https://datamap.gov.wales/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeNames=inspire-nrw:NRW_SSSI&outputFormat=application/json&srsName=EPSG:4326'\nconst scotlandWFS =\n 'https://services1.arcgis.com/LM9GyVFsughzHdbO/ArcGIS/rest/services/Sites_of_Special_Scientific_Interest/FeatureServer/0/query?f=geojson&where=1%3D1&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects&returnGeometry=true&outFields=*'\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiEnglandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiWalesRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', `${bbox.join(',')},EPSG:4326`)\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiScotlandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('geometry', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\nexport default [\n {\n id: 'sssi-england',\n label: 'Sites of Special Scientific Interest',\n dynamicGeoJSON: {\n url: englandWFS,\n idProperty: 'ref_code',\n transformRequest: sssiEnglandRequestTransformer\n },\n minZoom,\n style,\n showInKey: true,\n showInMenu: false\n },\n {\n id: 'sssi-wales',\n label: 'SSSI Wales',\n dynamicGeoJSON: {\n url: walesWFS,\n idProperty: 'id',\n transformRequest: sssiWalesRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n },\n {\n id: 'sssi-scotland',\n label: 'SSSI Scotland',\n dynamicGeoJSON: {\n url: scotlandWFS,\n idProperty: 'OBJECTID',\n transformRequest: sssiScotlandRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n }\n]\n/**\n * @typedef {object} TransformRequestOptions\n * @property {string[]} bbox - the bounding box coordinates\n */\n\n/**\n * Transforms the request URL with bounding box parameters\n * @callback TransformRequestArgs\n * @param {string} url - the request URL\n * @param {TransformRequestOptions} options - the bounding box coordinates\n */\n"],"mappings":"AAAA,MAAMA,KAAK,GAAG;EACZC,MAAM,EAAE,SAAS;EACjBC,WAAW,EAAE,sBAAsB;EACnCC,0BAA0B,EAAE,SAAS;EACrCC,0BAA0B,EAAE;AAC9B,CAAC;AACD,MAAMC,OAAO,GAAG,EAAE;AAElB,MAAMC,UAAU,GACd,iLAAiL;AACnL,MAAMC,QAAQ,GACZ,qKAAqK;AACvK,MAAMC,WAAW,GACf,qQAAqQ;;AAEvQ;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,GAAG,EAAE;EAAEC;AAAK,CAAC,EAAE;EAC3D,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACH,GAAG,CAAC;EACxBE,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,MAAM,EAAEJ,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC;EAE5C,OAAO;IACLN,GAAG,EAAEE,GAAG,CAACK,QAAQ,CAAC;EACpB,CAAC;AACH;;AAEA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CAACR,GAAG,EAAE;EAAEC;AAAK,CAAC,EAAE;EACzD,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACH,GAAG,CAAC;EACxBE,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,MAAM,EAAE,GAAGJ,IAAI,CAACK,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;EAE3D,OAAO;IACLN,GAAG,EAAEE,GAAG,CAACK,QAAQ,CAAC;EACpB,CAAC;AACH;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ERNAL_STATE_APPENDAGE";
6
6
  export const COMPONENT_STATE_ERROR: "COMPONENT_STATE_ERROR";
7
7
  export const PAYMENT_EXPIRED_NOTIFICATION: "PAYMENT_EXPIRED_NOTIFICATION";
8
+ export const EN_GB: "en-GB";
@@ -5,4 +5,5 @@ export const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD';
5
5
  export const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE';
6
6
  export const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR';
7
7
  export const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION';
8
+ export const EN_GB = 'en-GB';
8
9
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["FORM_VERSION_METADATA_KEY","PREVIEW_PATH_PREFIX","FORM_PREFIX","EXTERNAL_STATE_PAYLOAD","EXTERNAL_STATE_APPENDAGE","COMPONENT_STATE_ERROR","PAYMENT_EXPIRED_NOTIFICATION"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const FORM_VERSION_METADATA_KEY = '$$__formVersion'\nexport const PREVIEW_PATH_PREFIX = '/preview'\nexport const FORM_PREFIX = ''\nexport const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD'\nexport const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE'\nexport const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR'\nexport const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION'\n"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,GAAG,iBAAiB;AAC1D,OAAO,MAAMC,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,WAAW,GAAG,EAAE;AAC7B,OAAO,MAAMC,sBAAsB,GAAG,wBAAwB;AAC9D,OAAO,MAAMC,wBAAwB,GAAG,0BAA0B;AAClE,OAAO,MAAMC,qBAAqB,GAAG,uBAAuB;AAC5D,OAAO,MAAMC,4BAA4B,GAAG,8BAA8B","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","names":["FORM_VERSION_METADATA_KEY","PREVIEW_PATH_PREFIX","FORM_PREFIX","EXTERNAL_STATE_PAYLOAD","EXTERNAL_STATE_APPENDAGE","COMPONENT_STATE_ERROR","PAYMENT_EXPIRED_NOTIFICATION","EN_GB"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const FORM_VERSION_METADATA_KEY = '$$__formVersion'\nexport const PREVIEW_PATH_PREFIX = '/preview'\nexport const FORM_PREFIX = ''\nexport const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD'\nexport const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE'\nexport const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR'\nexport const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION'\nexport const EN_GB = 'en-GB'\n"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,GAAG,iBAAiB;AAC1D,OAAO,MAAMC,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,WAAW,GAAG,EAAE;AAC7B,OAAO,MAAMC,sBAAsB,GAAG,wBAAwB;AAC9D,OAAO,MAAMC,wBAAwB,GAAG,0BAA0B;AAClE,OAAO,MAAMC,qBAAqB,GAAG,uBAAuB;AAC5D,OAAO,MAAMC,4BAA4B,GAAG,8BAA8B;AAC1E,OAAO,MAAMC,KAAK,GAAG,OAAO","ignoreList":[]}
@@ -51,6 +51,7 @@ export declare class AutocompleteField extends SelectField {
51
51
  upload?: {
52
52
  count: number;
53
53
  summaryList: import("../types.js").SummaryList;
54
+ uploadingLabel?: string;
54
55
  };
55
56
  };
56
57
  }
@@ -21,6 +21,7 @@ export declare class ComponentBase {
21
21
  }>['options'];
22
22
  isFormComponent: boolean;
23
23
  model: FormModel;
24
+ def: ComponentDef;
24
25
  /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */
25
26
  formSchema: ComponentSchema;
26
27
  stateSchema: ComponentSchema;
@@ -12,6 +12,7 @@ export class ComponentBase {
12
12
  options;
13
13
  isFormComponent = false;
14
14
  model;
15
+ def;
15
16
 
16
17
  /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */
17
18
  formSchema = joi.string();
@@ -21,6 +22,7 @@ export class ComponentBase {
21
22
  this.type = def.type;
22
23
  this.name = def.name;
23
24
  this.title = def.title;
25
+ this.def = def;
24
26
  if ('schema' in def) {
25
27
  this.schema = def.schema;
26
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentBase.js","names":["isConditionalRevealType","joi","ComponentBase","id","page","parent","collection","type","name","title","schema","options","isFormComponent","model","formSchema","string","stateSchema","constructor","def","props","viewModel","attributes","autocomplete","classes","condition"],"sources":["../../../../../src/server/plugins/engine/components/ComponentBase.ts"],"sourcesContent":["import { isConditionalRevealType, type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type DateSchema,\n type NumberSchema,\n type ObjectSchema,\n type StringSchema\n} from 'joi'\n\nimport { type ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport { type Component } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport { type ViewModel } from '~/src/server/plugins/engine/components/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\n\nexport class ComponentBase {\n id?: string\n page?: PageControllerClass\n parent: Component | undefined\n collection: ComponentCollection | undefined\n\n type: ComponentDef['type']\n name: ComponentDef['name']\n title: ComponentDef['title']\n schema?: Extract<ComponentDef, { schema?: object }>['schema']\n options?: Extract<ComponentDef, { options: object }>['options']\n\n isFormComponent = false\n model: FormModel\n\n /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */\n formSchema: ComponentSchema = joi.string()\n stateSchema: ComponentSchema = joi.string()\n\n constructor(\n def: ComponentDef,\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n }\n ) {\n this.id = def.id\n this.type = def.type\n this.name = def.name\n this.title = def.title\n\n if ('schema' in def) {\n this.schema = def.schema\n }\n\n if ('options' in def) {\n this.options = def.options\n }\n\n this.page = props.page\n this.parent = props.parent\n this.model = props.model\n }\n\n get viewModel() {\n const { options, type } = this\n\n const viewModel: ViewModel = {\n attributes: {}\n }\n\n if (!options) {\n return viewModel\n }\n\n if ('autocomplete' in options) {\n viewModel.attributes.autocomplete = options.autocomplete\n }\n\n if ('classes' in options) {\n viewModel.classes = options.classes\n }\n\n if ('condition' in options && isConditionalRevealType(type)) {\n viewModel.condition = options.condition\n }\n\n return viewModel\n }\n}\n\nexport type ComponentSchema =\n | ArraySchema<string>\n | ArraySchema<number>\n | ArraySchema<boolean>\n | ArraySchema<object>\n | BooleanSchema<string>\n | BooleanSchema\n | DateSchema\n | NumberSchema<string>\n | NumberSchema\n | ObjectSchema\n | StringSchema\n"],"mappings":"AAAA,SAASA,uBAAuB,QAA2B,oBAAoB;AAC/E,OAAOC,GAAG,MAOH,KAAK;AAQZ,OAAO,MAAMC,aAAa,CAAC;EACzBC,EAAE;EACFC,IAAI;EACJC,MAAM;EACNC,UAAU;EAEVC,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,MAAM;EACNC,OAAO;EAEPC,eAAe,GAAG,KAAK;EACvBC,KAAK;;EAEL;EACAC,UAAU,GAAoBb,GAAG,CAACc,MAAM,CAAC,CAAC;EAC1CC,WAAW,GAAoBf,GAAG,CAACc,MAAM,CAAC,CAAC;EAE3CE,WAAWA,CACTC,GAAiB,EACjBC,KAIC,EACD;IACA,IAAI,CAAChB,EAAE,GAAGe,GAAG,CAACf,EAAE;IAChB,IAAI,CAACI,IAAI,GAAGW,GAAG,CAACX,IAAI;IACpB,IAAI,CAACC,IAAI,GAAGU,GAAG,CAACV,IAAI;IACpB,IAAI,CAACC,KAAK,GAAGS,GAAG,CAACT,KAAK;IAEtB,IAAI,QAAQ,IAAIS,GAAG,EAAE;MACnB,IAAI,CAACR,MAAM,GAAGQ,GAAG,CAACR,MAAM;IAC1B;IAEA,IAAI,SAAS,IAAIQ,GAAG,EAAE;MACpB,IAAI,CAACP,OAAO,GAAGO,GAAG,CAACP,OAAO;IAC5B;IAEA,IAAI,CAACP,IAAI,GAAGe,KAAK,CAACf,IAAI;IACtB,IAAI,CAACC,MAAM,GAAGc,KAAK,CAACd,MAAM;IAC1B,IAAI,CAACQ,KAAK,GAAGM,KAAK,CAACN,KAAK;EAC1B;EAEA,IAAIO,SAASA,CAAA,EAAG;IACd,MAAM;MAAET,OAAO;MAAEJ;IAAK,CAAC,GAAG,IAAI;IAE9B,MAAMa,SAAoB,GAAG;MAC3BC,UAAU,EAAE,CAAC;IACf,CAAC;IAED,IAAI,CAACV,OAAO,EAAE;MACZ,OAAOS,SAAS;IAClB;IAEA,IAAI,cAAc,IAAIT,OAAO,EAAE;MAC7BS,SAAS,CAACC,UAAU,CAACC,YAAY,GAAGX,OAAO,CAACW,YAAY;IAC1D;IAEA,IAAI,SAAS,IAAIX,OAAO,EAAE;MACxBS,SAAS,CAACG,OAAO,GAAGZ,OAAO,CAACY,OAAO;IACrC;IAEA,IAAI,WAAW,IAAIZ,OAAO,IAAIX,uBAAuB,CAACO,IAAI,CAAC,EAAE;MAC3Da,SAAS,CAACI,SAAS,GAAGb,OAAO,CAACa,SAAS;IACzC;IAEA,OAAOJ,SAAS;EAClB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"ComponentBase.js","names":["isConditionalRevealType","joi","ComponentBase","id","page","parent","collection","type","name","title","schema","options","isFormComponent","model","def","formSchema","string","stateSchema","constructor","props","viewModel","attributes","autocomplete","classes","condition"],"sources":["../../../../../src/server/plugins/engine/components/ComponentBase.ts"],"sourcesContent":["import { isConditionalRevealType, type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type DateSchema,\n type NumberSchema,\n type ObjectSchema,\n type StringSchema\n} from 'joi'\n\nimport { type ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport { type Component } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport { type ViewModel } from '~/src/server/plugins/engine/components/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\n\nexport class ComponentBase {\n id?: string\n page?: PageControllerClass\n parent: Component | undefined\n collection: ComponentCollection | undefined\n\n type: ComponentDef['type']\n name: ComponentDef['name']\n title: ComponentDef['title']\n schema?: Extract<ComponentDef, { schema?: object }>['schema']\n options?: Extract<ComponentDef, { options: object }>['options']\n\n isFormComponent = false\n model: FormModel\n def: ComponentDef\n\n /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */\n formSchema: ComponentSchema = joi.string()\n stateSchema: ComponentSchema = joi.string()\n\n constructor(\n def: ComponentDef,\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n }\n ) {\n this.id = def.id\n this.type = def.type\n this.name = def.name\n this.title = def.title\n this.def = def\n\n if ('schema' in def) {\n this.schema = def.schema\n }\n\n if ('options' in def) {\n this.options = def.options\n }\n\n this.page = props.page\n this.parent = props.parent\n this.model = props.model\n }\n\n get viewModel() {\n const { options, type } = this\n\n const viewModel: ViewModel = {\n attributes: {}\n }\n\n if (!options) {\n return viewModel\n }\n\n if ('autocomplete' in options) {\n viewModel.attributes.autocomplete = options.autocomplete\n }\n\n if ('classes' in options) {\n viewModel.classes = options.classes\n }\n\n if ('condition' in options && isConditionalRevealType(type)) {\n viewModel.condition = options.condition\n }\n\n return viewModel\n }\n}\n\nexport type ComponentSchema =\n | ArraySchema<string>\n | ArraySchema<number>\n | ArraySchema<boolean>\n | ArraySchema<object>\n | BooleanSchema<string>\n | BooleanSchema\n | DateSchema\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AAO,EAAE;MACZ,OAAOS,SAAS;IAClB;IAEA,IAAI,cAAc,IAAIT,OAAO,EAAE;MAC7BS,SAAS,CAACC,UAAU,CAACC,YAAY,GAAGX,OAAO,CAACW,YAAY;IAC1D;IAEA,IAAI,SAAS,IAAIX,OAAO,EAAE;MACxBS,SAAS,CAACG,OAAO,GAAGZ,OAAO,CAACY,OAAO;IACrC;IAEA,IAAI,WAAW,IAAIZ,OAAO,IAAIX,uBAAuB,CAACO,IAAI,CAAC,EAAE;MAC3Da,SAAS,CAACI,SAAS,GAAGb,OAAO,CAACa,SAAS;IACzC;IAEA,OAAOJ,SAAS;EAClB;AACF","ignoreList":[]}
@@ -210,7 +210,8 @@ export class ComponentCollection {
210
210
  labelOverrides[subField.name] = patchedSchema;
211
211
  }
212
212
  } else {
213
- const translatedLabel = translator.tComponent(field, 'shortDescription') || translator.tComponent(field, 'title');
213
+ const fieldDef = field.def;
214
+ const translatedLabel = translator.tComponent(fieldDef, 'errorDescription') || translator.tComponent(fieldDef, 'shortDescription') || translator.tComponent(fieldDef, 'title');
214
215
  const messagesOverride = field.getValidationMessagesOverride(translator);
215
216
  let patchedSchema = field.formSchema;
216
217
  if (translatedLabel && translatedLabel !== field.label) {
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentCollection.js","names":["joi","isFormState","isFormValue","createComponent","getErrors","buildLanguageMessages","validationOptions","opts","ComponentCollection","page","parent","components","fields","guidance","formSchema","stateSchema","constructor","defs","props","schema","map","def","filter","component","isFormComponent","object","required","field","collection","name","concat","keys","peers","and","isPresent","custom","flatMap","getFormDataFromState","state","payload","forEach","Object","assign","getFormValueFromState","value","entries","key","split","pop","getStateFromValidForm","getContextValueFromState","context","translator","errors","getFieldErrors","getViewErrors","getViewModel","result","type","model","overrideParentTitle","error","isErrorContext","local","title","missing","path","find","item","shift","child","label","length","tComponent","validate","messages","t","undefined","labelOverrides","messagesOverride","getValidationMessagesOverride","subField","translatedSubLabel","patchedSchema","translatedLabel","details","callback","list","fieldErrors","push"],"sources":["../../../../../src/server/plugins/engine/components/ComponentCollection.ts"],"sourcesContent":["import { type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type CustomValidator,\n type ErrorReportCollection,\n type ObjectSchema\n} from 'joi'\n\nimport {\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createComponent,\n type Component,\n type Field,\n type Guidance\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type ComponentViewModel,\n type RenderContext\n} from '~/src/server/plugins/engine/components/types.js'\nimport { getErrors } from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport {\n buildLanguageMessages,\n validationOptions as opts\n} from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValidationResult\n} from '~/src/server/plugins/engine/types.js'\n\nexport class ComponentCollection {\n page?: PageControllerClass\n parent?: Component\n\n components: Component[]\n fields: Field[]\n guidance: Guidance[]\n\n formSchema: ObjectSchema<FormPayload>\n stateSchema: ObjectSchema<FormSubmissionState>\n\n constructor(\n defs: ComponentDef[],\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n },\n schema?: {\n /**\n * Defines an all-or-nothing relationship between keys where if one\n * of the peers is present, all of them are required as well\n */\n peers?: string[]\n\n /**\n * Defines a custom validation rule for the object schema\n */\n custom?: CustomValidator\n }\n ) {\n const components = defs.map((def) => createComponent(def, props))\n\n const fields = components.filter(\n (component): component is Field => component.isFormComponent\n )\n\n const guidance = components.filter(\n (component): component is Guidance => !component.isFormComponent\n )\n\n let formSchema = joi.object<FormPayload>().required()\n let stateSchema = joi.object<FormSubmissionState>().required()\n\n // Add each field or concat collection\n for (const field of fields) {\n const { collection, name } = field\n\n formSchema = collection\n ? formSchema.concat(collection.formSchema)\n : formSchema.keys({ [name]: field.formSchema })\n\n stateSchema = collection\n ? stateSchema.concat(collection.stateSchema)\n : stateSchema.keys({ [name]: field.stateSchema })\n }\n\n if (schema?.peers) {\n formSchema = formSchema.and(...schema.peers, {\n isPresent: isFormValue\n })\n }\n\n if (schema?.custom) {\n formSchema = formSchema.custom(schema.custom)\n }\n\n this.page = props.page\n this.parent = props.parent\n\n this.components = components\n this.fields = fields\n this.guidance = guidance\n\n this.formSchema = formSchema\n this.stateSchema = stateSchema\n }\n\n get keys() {\n return this.fields.flatMap((field) => {\n const { name, collection } = field\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n })\n }\n\n getFormDataFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n this.fields.forEach((component) => {\n Object.assign(payload, component.getFormDataFromState(state))\n })\n\n return payload\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n // Remove name prefix for formatted value\n for (const [name, value] of Object.entries(\n this.getFormDataFromState(state)\n )) {\n const key = name.split('__').pop()\n if (!key) {\n continue\n }\n\n payload[key] = value\n }\n\n return payload\n }\n\n getStateFromValidForm(payload: FormPayload) {\n const state: FormState = {}\n\n this.fields.forEach((component) => {\n Object.assign(state, component.getStateFromValidForm(payload))\n })\n\n return state\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const context: FormState = {}\n\n for (const component of this.fields) {\n context[component.name] = component.getContextValueFromState(state)\n }\n\n return context\n }\n\n /**\n * Get all errors for all fields in this collection\n */\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getErrors(translator, errors),\n errors\n )\n }\n\n /**\n * Get view errors for all fields in this collection.\n * For most fields this means filtering to the first error in the list.\n * Composite fields like UKAddress can choose to return more than one error.\n */\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getViewErrors(translator, errors),\n errors\n )\n }\n\n getViewModel(context: RenderContext) {\n const { components } = this\n\n const result: ComponentViewModel[] = components.map((component) => {\n const { isFormComponent, type } = component\n\n const model = component.getViewModel(context)\n\n return { type, isFormComponent, model }\n })\n\n return result\n }\n\n overrideParentTitle(\n formSchema: joi.ObjectSchema<FormPayload>,\n translator: Translator | undefined\n ) {\n // Add parent field title to collection field errors\n return formSchema.error((errors) => {\n return errors.flatMap((error) => {\n if (!isErrorContext(error.local) || error.local.title) {\n return error\n }\n\n // Use field key or first missing child field\n let { missing, key = missing?.[0] } = error.local\n\n // But avoid numeric key used by array payloads\n if (typeof key === 'number') {\n key = error.path[0]\n }\n\n // Find the parent field\n const parent = this.fields.find(\n (item) => item.name === key?.split('__').shift()\n )\n\n // Find the child field\n const child = (parent?.collection?.fields ?? this.fields).find(\n (item) => item.name === key\n )\n\n // Update error with child label\n if (child && (!error.local.label || error.local.label === 'value')) {\n error.local.label = child.title\n }\n\n // Fix error summary links for missing fields\n if (missing?.length) {\n error.path = missing\n error.local.key = missing[0]\n }\n\n // Update error with parent title\n if (translator && parent) {\n error.local.title ??= translator.tComponent(\n parent as ComponentDef,\n 'title'\n )\n } else {\n error.local.title ??= parent?.label\n }\n\n return error\n })\n })\n }\n\n /**\n * Validate form payload\n */\n validate(\n value: FormPayload = {},\n translator?: Translator\n ): FormValidationResult<FormPayload> {\n const messages = translator\n ? buildLanguageMessages(translator.t)\n : undefined\n\n // When translating, override Joi labels (and custom schema messages where\n // needed) so #label/#title in message templates resolve in the correct language.\n let schema = this.formSchema\n // Add parent field title to collection field errors\n schema = this.overrideParentTitle(schema, translator)\n\n if (translator) {\n const { t } = translator\n const labelOverrides: Record<string, joi.Schema> = {}\n\n for (const field of this.fields) {\n if (field.collection) {\n // Composite field: translate each sub-field's label using the key constant\n // (e.g. 'components.addressField.line1' → \"Llinell cyfeiriad 1\") and apply\n // any field-type-specific message overrides (e.g. objectMissing for dates).\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n for (const subField of field.collection.fields) {\n const translatedSubLabel = t(subField.title) || subField.label\n let patchedSchema = subField.formSchema.label(translatedSubLabel)\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n labelOverrides[subField.name] = patchedSchema\n }\n } else {\n const translatedLabel =\n translator.tComponent(\n field as unknown as ComponentDef,\n 'shortDescription'\n ) ||\n translator.tComponent(field as unknown as ComponentDef, 'title')\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n let patchedSchema = field.formSchema\n if (translatedLabel && translatedLabel !== field.label) {\n patchedSchema = patchedSchema.label(translatedLabel)\n }\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n if (patchedSchema !== field.formSchema) {\n labelOverrides[field.name] = patchedSchema\n }\n }\n }\n\n if (Object.keys(labelOverrides).length) {\n schema = schema.keys(labelOverrides)\n }\n }\n\n const result = schema.validate(value, {\n ...opts,\n ...(messages && { messages })\n })\n\n const details = result.error?.details\n\n return {\n value: (result.value ?? {}) as typeof value,\n errors: this.page?.getErrors(details) ?? getErrors(details)\n }\n }\n\n /**\n * Helper to get errors from all fields\n */\n private getFieldErrors(\n callback: (field: Field) => FormSubmissionError[] | undefined,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { fields } = this\n\n if (!errors?.length) {\n return\n }\n\n const list: FormSubmissionError[] = []\n\n for (const field of fields) {\n const fieldErrors = callback(field)\n\n if (fieldErrors?.length) {\n list.push(...fieldErrors)\n }\n }\n\n if (!list.length) {\n return\n }\n\n return list\n }\n}\n\n/**\n * Check for field local state\n */\nexport function isErrorContext(\n value?: unknown\n): value is ErrorReportCollection['local'] {\n return isFormState(value) && typeof value.label === 'string'\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAIH,KAAK;AAEZ,SACEC,WAAW,EACXC,WAAW;AAEb,SACEC,eAAe;AASjB,SAASC,SAAS;AAIlB,SACEC,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,CAACY,IAAI,CAAC+C,cAAc,CAAC;MACtC;IACF;IAEA,MAAMrB,MAAM,GAAGtC,MAAM,CAACuD,QAAQ,CAAC9B,KAAK,EAAE;MACpC,GAAGrC,IAAI;MACP,IAAIoE,QAAQ,IAAI;QAAEA;MAAS,CAAC;IAC9B,CAAC,CAAC;IAEF,MAAMU,OAAO,GAAG5B,MAAM,CAACI,KAAK,EAAEwB,OAAO;IAErC,OAAO;MACLzC,KAAK,EAAGa,MAAM,CAACb,KAAK,IAAI,CAAC,CAAkB;MAC3CS,MAAM,EAAE,IAAI,CAAC5C,IAAI,EAAEL,SAAS,CAACiF,OAAO,CAAC,IAAIjF,SAAS,CAACiF,OAAO;IAC5D,CAAC;EACH;;EAEA;AACF;AACA;EACU/B,cAAcA,CACpBgC,QAA6D,EAC7DjC,MAA8B,EACK;IACnC,MAAM;MAAEzC;IAAO,CAAC,GAAG,IAAI;IAEvB,IAAI,CAACyC,MAAM,EAAEmB,MAAM,EAAE;MACnB;IACF;IAEA,MAAMe,IAA2B,GAAG,EAAE;IAEtC,KAAK,MAAM5D,KAAK,IAAIf,MAAM,EAAE;MAC1B,MAAM4E,WAAW,GAAGF,QAAQ,CAAC3D,KAAK,CAAC;MAEnC,IAAI6D,WAAW,EAAEhB,MAAM,EAAE;QACvBe,IAAI,CAACE,IAAI,CAAC,GAAGD,WAAW,CAAC;MAC3B;IACF;IAEA,IAAI,CAACD,IAAI,CAACf,MAAM,EAAE;MAChB;IACF;IAEA,OAAOe,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASzB,cAAcA,CAC5BlB,KAAe,EAC0B;EACzC,OAAO3C,WAAW,CAAC2C,KAAK,CAAC,IAAI,OAAOA,KAAK,CAAC2B,KAAK,KAAK,QAAQ;AAC9D","ignoreList":[]}
1
+ {"version":3,"file":"ComponentCollection.js","names":["joi","isFormState","isFormValue","createComponent","getErrors","buildLanguageMessages","validationOptions","opts","ComponentCollection","page","parent","components","fields","guidance","formSchema","stateSchema","constructor","defs","props","schema","map","def","filter","component","isFormComponent","object","required","field","collection","name","concat","keys","peers","and","isPresent","custom","flatMap","getFormDataFromState","state","payload","forEach","Object","assign","getFormValueFromState","value","entries","key","split","pop","getStateFromValidForm","getContextValueFromState","context","translator","errors","getFieldErrors","getViewErrors","getViewModel","result","type","model","overrideParentTitle","error","isErrorContext","local","title","missing","path","find","item","shift","child","label","length","tComponent","validate","messages","t","undefined","labelOverrides","messagesOverride","getValidationMessagesOverride","subField","translatedSubLabel","patchedSchema","fieldDef","translatedLabel","details","callback","list","fieldErrors","push"],"sources":["../../../../../src/server/plugins/engine/components/ComponentCollection.ts"],"sourcesContent":["import { type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type CustomValidator,\n type ErrorReportCollection,\n type ObjectSchema\n} from 'joi'\n\nimport {\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createComponent,\n type Component,\n type Field,\n type Guidance\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type ComponentViewModel,\n type RenderContext\n} from '~/src/server/plugins/engine/components/types.js'\nimport { getErrors } from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport {\n buildLanguageMessages,\n validationOptions as opts\n} from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValidationResult\n} from '~/src/server/plugins/engine/types.js'\n\nexport class ComponentCollection {\n page?: PageControllerClass\n parent?: Component\n\n components: Component[]\n fields: Field[]\n guidance: Guidance[]\n\n formSchema: ObjectSchema<FormPayload>\n stateSchema: ObjectSchema<FormSubmissionState>\n\n constructor(\n defs: ComponentDef[],\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n },\n schema?: {\n /**\n * Defines an all-or-nothing relationship between keys where if one\n * of the peers is present, all of them are required as well\n */\n peers?: string[]\n\n /**\n * Defines a custom validation rule for the object schema\n */\n custom?: CustomValidator\n }\n ) {\n const components = defs.map((def) => createComponent(def, props))\n\n const fields = components.filter(\n (component): component is Field => component.isFormComponent\n )\n\n const guidance = components.filter(\n (component): component is Guidance => !component.isFormComponent\n )\n\n let formSchema = joi.object<FormPayload>().required()\n let stateSchema = joi.object<FormSubmissionState>().required()\n\n // Add each field or concat collection\n for (const field of fields) {\n const { collection, name } = field\n\n formSchema = collection\n ? formSchema.concat(collection.formSchema)\n : formSchema.keys({ [name]: field.formSchema })\n\n stateSchema = collection\n ? stateSchema.concat(collection.stateSchema)\n : stateSchema.keys({ [name]: field.stateSchema })\n }\n\n if (schema?.peers) {\n formSchema = formSchema.and(...schema.peers, {\n isPresent: isFormValue\n })\n }\n\n if (schema?.custom) {\n formSchema = formSchema.custom(schema.custom)\n }\n\n this.page = props.page\n this.parent = props.parent\n\n this.components = components\n this.fields = fields\n this.guidance = guidance\n\n this.formSchema = formSchema\n this.stateSchema = stateSchema\n }\n\n get keys() {\n return this.fields.flatMap((field) => {\n const { name, collection } = field\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n })\n }\n\n getFormDataFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n this.fields.forEach((component) => {\n Object.assign(payload, component.getFormDataFromState(state))\n })\n\n return payload\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n // Remove name prefix for formatted value\n for (const [name, value] of Object.entries(\n this.getFormDataFromState(state)\n )) {\n const key = name.split('__').pop()\n if (!key) {\n continue\n }\n\n payload[key] = value\n }\n\n return payload\n }\n\n getStateFromValidForm(payload: FormPayload) {\n const state: FormState = {}\n\n this.fields.forEach((component) => {\n Object.assign(state, component.getStateFromValidForm(payload))\n })\n\n return state\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const context: FormState = {}\n\n for (const component of this.fields) {\n context[component.name] = component.getContextValueFromState(state)\n }\n\n return context\n }\n\n /**\n * Get all errors for all fields in this collection\n */\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getErrors(translator, errors),\n errors\n )\n }\n\n /**\n * Get view errors for all fields in this collection.\n * For most fields this means filtering to the first error in the list.\n * Composite fields like UKAddress can choose to return more than one error.\n */\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getViewErrors(translator, errors),\n errors\n )\n }\n\n getViewModel(context: RenderContext) {\n const { components } = this\n\n const result: ComponentViewModel[] = components.map((component) => {\n const { isFormComponent, type } = component\n\n const model = component.getViewModel(context)\n\n return { type, isFormComponent, model }\n })\n\n return result\n }\n\n overrideParentTitle(\n formSchema: joi.ObjectSchema<FormPayload>,\n translator: Translator | undefined\n ) {\n // Add parent field title to collection field errors\n return formSchema.error((errors) => {\n return errors.flatMap((error) => {\n if (!isErrorContext(error.local) || error.local.title) {\n return error\n }\n\n // Use field key or first missing child field\n let { missing, key = missing?.[0] } = error.local\n\n // But avoid numeric key used by array payloads\n if (typeof key === 'number') {\n key = error.path[0]\n }\n\n // Find the parent field\n const parent = this.fields.find(\n (item) => item.name === key?.split('__').shift()\n )\n\n // Find the child field\n const child = (parent?.collection?.fields ?? this.fields).find(\n (item) => item.name === key\n )\n\n // Update error with child label\n if (child && (!error.local.label || error.local.label === 'value')) {\n error.local.label = child.title\n }\n\n // Fix error summary links for missing fields\n if (missing?.length) {\n error.path = missing\n error.local.key = missing[0]\n }\n\n // Update error with parent title\n if (translator && parent) {\n error.local.title ??= translator.tComponent(\n parent as ComponentDef,\n 'title'\n )\n } else {\n error.local.title ??= parent?.label\n }\n\n return error\n })\n })\n }\n\n /**\n * Validate form payload\n */\n validate(\n value: FormPayload = {},\n translator?: Translator\n ): FormValidationResult<FormPayload> {\n const messages = translator\n ? buildLanguageMessages(translator.t)\n : undefined\n\n // When translating, override Joi labels (and custom schema messages where\n // needed) so #label/#title in message templates resolve in the correct language.\n let schema = this.formSchema\n // Add parent field title to collection field errors\n schema = this.overrideParentTitle(schema, translator)\n\n if (translator) {\n const { t } = translator\n const labelOverrides: Record<string, joi.Schema> = {}\n\n for (const field of this.fields) {\n if (field.collection) {\n // Composite field: translate each sub-field's label using the key constant\n // (e.g. 'components.addressField.line1' → \"Llinell cyfeiriad 1\") and apply\n // any field-type-specific message overrides (e.g. objectMissing for dates).\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n for (const subField of field.collection.fields) {\n const translatedSubLabel = t(subField.title) || subField.label\n let patchedSchema = subField.formSchema.label(translatedSubLabel)\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n labelOverrides[subField.name] = patchedSchema\n }\n } else {\n const fieldDef = field.def\n const translatedLabel =\n translator.tComponent(fieldDef, 'errorDescription') ||\n translator.tComponent(fieldDef, 'shortDescription') ||\n translator.tComponent(fieldDef, 'title')\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n let patchedSchema = field.formSchema\n if (translatedLabel && translatedLabel !== field.label) {\n patchedSchema = patchedSchema.label(translatedLabel)\n }\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n if (patchedSchema !== field.formSchema) {\n labelOverrides[field.name] = patchedSchema\n }\n }\n }\n\n if (Object.keys(labelOverrides).length) {\n schema = schema.keys(labelOverrides)\n }\n }\n\n const result = schema.validate(value, {\n ...opts,\n ...(messages && { messages })\n })\n\n const details = result.error?.details\n\n return {\n value: (result.value ?? {}) as typeof value,\n errors: this.page?.getErrors(details) ?? getErrors(details)\n }\n }\n\n /**\n * Helper to get errors from all fields\n */\n private getFieldErrors(\n callback: (field: Field) => FormSubmissionError[] | undefined,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { fields } = this\n\n if (!errors?.length) {\n return\n }\n\n const list: FormSubmissionError[] = []\n\n for (const field of fields) {\n const fieldErrors = callback(field)\n\n if (fieldErrors?.length) {\n list.push(...fieldErrors)\n }\n }\n\n if (!list.length) {\n return\n }\n\n return list\n }\n}\n\n/**\n * Check for field local state\n */\nexport function isErrorContext(\n value?: unknown\n): value is ErrorReportCollection['local'] {\n return isFormState(value) && typeof value.label === 'string'\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAIH,KAAK;AAEZ,SACEC,WAAW,EACXC,WAAW;AAEb,SACEC,eAAe;AASjB,SAASC,SAAS;AAIlB,SACEC,qBAAqB,EACrBC,iBAAiB,IAAIC,IAAI;AAU3B,OAAO,MAAMC,mBAAmB,CAAC;EAC/BC,IAAI;EACJC,MAAM;EAENC,UAAU;EACVC,MAAM;EACNC,QAAQ;EAERC,UAAU;EACVC,WAAW;EAEXC,WAAWA,CACTC,IAAoB,EACpBC,KAIC,EACDC,MAWC,EACD;IACA,MAAMR,UAAU,GAAGM,IAAI,CAACG,GAAG,CAAEC,GAAG,IAAKlB,eAAe,CAACkB,GAAG,EAAEH,KAAK,CAAC,CAAC;IAEjE,MAAMN,MAAM,GAAGD,UAAU,CAACW,MAAM,CAC7BC,SAAS,IAAyBA,SAAS,CAACC,eAC/C,CAAC;IAED,MAAMX,QAAQ,GAAGF,UAAU,CAACW,MAAM,CAC/BC,SAAS,IAA4B,CAACA,SAAS,CAACC,eACnD,CAAC;IAED,IAAIV,UAAU,GAAGd,GAAG,CAACyB,MAAM,CAAc,CAAC,CAACC,QAAQ,CAAC,CAAC;IACrD,IAAIX,WAAW,GAAGf,GAAG,CAACyB,MAAM,CAAsB,CAAC,CAACC,QAAQ,CAAC,CAAC;;IAE9D;IACA,KAAK,MAAMC,KAAK,IAAIf,MAAM,EAAE;MAC1B,MAAM;QAAEgB,UAAU;QAAEC;MAAK,CAAC,GAAGF,KAAK;MAElCb,UAAU,GAAGc,UAAU,GACnBd,UAAU,CAACgB,MAAM,CAACF,UAAU,CA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AAC;MAEnC,IAAI8D,WAAW,EAAEjB,MAAM,EAAE;QACvBgB,IAAI,CAACE,IAAI,CAAC,GAAGD,WAAW,CAAC;MAC3B;IACF;IAEA,IAAI,CAACD,IAAI,CAAChB,MAAM,EAAE;MAChB;IACF;IAEA,OAAOgB,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAAS1B,cAAcA,CAC5BlB,KAAe,EAC0B;EACzC,OAAO3C,WAAW,CAAC2C,KAAK,CAAC,IAAI,OAAOA,KAAK,CAAC2B,KAAK,KAAK,QAAQ;AAC9D","ignoreList":[]}
@@ -64,6 +64,7 @@ export declare class DatePartsField extends FormComponent {
64
64
  upload?: {
65
65
  count: number;
66
66
  summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
67
+ uploadingLabel?: string;
67
68
  };
68
69
  };
69
70
  isState(value?: FormStateValue | FormState): value is DatePartsState;
@@ -70,6 +70,7 @@ export declare class DeclarationField extends FormComponent {
70
70
  upload?: {
71
71
  count: number;
72
72
  summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
73
+ uploadingLabel?: string;
73
74
  };
74
75
  };
75
76
  isValue(value?: FormStateValue | FormState): value is Item['value'][];
@@ -93,7 +93,7 @@ export class DeclarationField extends FormComponent {
93
93
  hint,
94
94
  declarationConfirmationLabel = t('components.declarationField.defaultLabel')
95
95
  } = this;
96
- const content = tComponent(this, 'content');
96
+ const content = tComponent(this.def, 'content');
97
97
  const viewModel = super.getViewModel(context);
98
98
  let {
99
99
  fieldset,
@@ -1 +1 @@
1
- {"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","buildValidationMessages","messageTemplate","DeclarationField","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getValidationMessagesOverride","translator","t","msg","getDisplayStringFromFormValue","getViewModel","context","tComponent","hint","viewModel","fieldset","legend","text","classes","isChecked","Array","isArray","x","checked","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type ComponentDef,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type LanguageMessages,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { buildValidationMessages } from '~/src/server/plugins/engine/i18n/buildValidationMessages.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string | undefined\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n // Store only the form-authored label (if provided). If absent, getViewModel\n // resolves the default via t() at render time so the correct language is used.\n this.declarationConfirmationLabel = options.declarationConfirmationLabel\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getValidationMessagesOverride(translator: Translator) {\n const { declarationRequired } = buildValidationMessages(translator.t)\n const msg = declarationRequired as unknown as string\n return {\n 'any.required': msg,\n 'any.unknown': msg,\n 'array.includesRequiredUnknowns': msg\n } as unknown as LanguageMessages\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n translator: Translator\n ): string {\n const { t } = translator\n return value === 'true'\n ? (this.declarationConfirmationLabel ??\n t('components.declarationField.defaultLabel'))\n : t('components.declarationField.notProvided')\n }\n\n getViewModel(context: RenderContext) {\n const { payload } = context\n const { t, tComponent } = context.translator\n\n const {\n hint,\n declarationConfirmationLabel = t(\n 'components.declarationField.defaultLabel'\n )\n } = this\n const content = tComponent(this as unknown as ComponentDef, 'content')\n\n const viewModel = super.getViewModel(context)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const payloadValue = payload[this.name]\n const isChecked =\n payloadValue === 'true' ||\n payloadValue === true ||\n (Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))\n\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAIL,oBAAoB;AAC3B,OAAOC,GAAG,MAKH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAGb,SAASC,uBAAuB;AAEhC,SAASC,eAAe;AAUxB,OAAO,MAAMC,gBAAgB,SAASJ,aAAa,CAAC;EAQlDK,gBAAgB;EAEhBC,WAAWA,CACTC,GAA8B,EAC9BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;M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IAAI,CAAEmC,CAAC,IAAKA,CAAC,KAAK,MAAM,CAAE;IAEzE,OAAO;MACL,GAAGR,SAAS;MACZD,IAAI,EAAEA,IAAI,GAAG;QAAEI,IAAI,EAAEJ;MAAK,CAAC,GAAGT,SAAS;MACvCW,QAAQ;MACRvD,OAAO;MACPO,KAAK,EAAE,CACL;QACEkD,IAAI,EAAEzC,4BAA4B;QAClCsB,KAAK,EAAE,MAAM;QACbyB,OAAO,EAAEJ;MACX,CAAC,CACF;MACDhE,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;EAEA4C,OAAOA,CAACD,KAAkC,EAA4B;IACpE,IAAI,CAACsB,KAAK,CAACC,OAAO,CAACvB,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACb,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOa,KAAK,CAACE,KAAK,CAACjD,WAAW,CAAC;EACjC;;EAEA;AACF;AACA;EACEyE,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOtE,gBAAgB,CAACsE,oBAAoB,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAEzC,IAAI,EAAE,UAAU;QAAE0C,QAAQ,EAAEzE,eAAe,CAACmB;MAAoB,CAAC,CACpE;MACDuD,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAAC9B,KAAkC,EAAoB;IAClE,OAAO/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","buildValidationMessages","messageTemplate","DeclarationField","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getValidationMessagesOverride","translator","t","msg","getDisplayStringFromFormValue","getViewModel","context","tComponent","hint","viewModel","fieldset","legend","text","classes","isChecked","Array","isArray","x","checked","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type LanguageMessages,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { buildValidationMessages } from '~/src/server/plugins/engine/i18n/buildValidationMessages.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string | undefined\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n // Store only the form-authored label (if provided). If absent, getViewModel\n // resolves the default via t() at render time so the correct language is used.\n this.declarationConfirmationLabel = options.declarationConfirmationLabel\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getValidationMessagesOverride(translator: Translator) {\n const { declarationRequired } = buildValidationMessages(translator.t)\n const msg = declarationRequired as unknown as string\n return {\n 'any.required': msg,\n 'any.unknown': msg,\n 'array.includesRequiredUnknowns': msg\n } as unknown as LanguageMessages\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n translator: Translator\n ): string {\n const { t } = translator\n return value === 'true'\n ? (this.declarationConfirmationLabel ??\n t('components.declarationField.defaultLabel'))\n : t('components.declarationField.notProvided')\n }\n\n getViewModel(context: RenderContext) {\n const { payload } = context\n const { t, tComponent } = context.translator\n\n const {\n hint,\n declarationConfirmationLabel = t(\n 'components.declarationField.defaultLabel'\n )\n } = this\n const content = tComponent(this.def, 'content')\n\n const viewModel = super.getViewModel(context)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const payloadValue = payload[this.name]\n const isChecked =\n payloadValue === 'true' ||\n payloadValue === true ||\n (Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))\n\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAGL,oBAAoB;AAC3B,OAAOC,GAAG,MAKH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAGb,SAASC,uBAAuB;AAEhC,SAASC,eAAe;AAUxB,OAAO,MAAMC,gBAAgB,SAASJ,aAAa,CAAC;EAQlDK,gBAAgB;EAEhBC,WAAWA,CACTC,GAA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MAAM,IACvBA,YAAY,KAAK,IAAI,IACpBuB,KAAK,CAACC,OAAO,CAACxB,YAAY,CAAC,IAAIA,YAAY,CAACV,IAAI,CAAEmC,CAAC,IAAKA,CAAC,KAAK,MAAM,CAAE;IAEzE,OAAO;MACL,GAAGR,SAAS;MACZD,IAAI,EAAEA,IAAI,GAAG;QAAEI,IAAI,EAAEJ;MAAK,CAAC,GAAGT,SAAS;MACvCW,QAAQ;MACRvD,OAAO;MACPO,KAAK,EAAE,CACL;QACEkD,IAAI,EAAEzC,4BAA4B;QAClCsB,KAAK,EAAE,MAAM;QACbyB,OAAO,EAAEJ;MACX,CAAC,CACF;MACDhE,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;EAEA4C,OAAOA,CAACD,KAAkC,EAA4B;IACpE,IAAI,CAACsB,KAAK,CAACC,OAAO,CAACvB,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACb,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOa,KAAK,CAACE,KAAK,CAACjD,WAAW,CAAC;EACjC;;EAEA;AACF;AACA;EACEyE,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOtE,gBAAgB,CAACsE,oBAAoB,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAEzC,IAAI,EAAE,UAAU;QAAE0C,QAAQ,EAAEzE,eAAe,CAACmB;MAAoB,CAAC,CACpE;MACDuD,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAAC9B,KAAkC,EAAoB;IAClE,OAAO/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
@@ -49,6 +49,7 @@ export declare class Details extends ComponentBase {
49
49
  upload?: {
50
50
  count: number;
51
51
  summaryList: import("../types.js").SummaryList;
52
+ uploadingLabel?: string;
52
53
  };
53
54
  };
54
55
  }