@defra/forms-engine-plugin 5.0.0-alpha.13 → 5.0.0-alpha.15

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.
@@ -3,6 +3,11 @@
3
3
  * @param {LanguageCode} lang - the lanugae code
4
4
  */
5
5
  export function getTexts(lang?: LanguageCode): LocationLanguageTexts;
6
+ /**
7
+ * Gets initial map config for a location field
8
+ * @param {HTMLDivElement} locationField - the location field element
9
+ */
10
+ export function getInitMapConfig(locationField: HTMLDivElement): InteractiveMapInitConfig | undefined;
6
11
  /**
7
12
  * Processes a location field to add map capability
8
13
  * @param {MapsEnvironmentConfig} config - the location field element
@@ -43,4 +48,5 @@ export type LocationLanguageTexts = {
43
48
  helpPanel: LocationPanelTexts;
44
49
  };
45
50
  import type { LanguageCode } from '../../client/javascripts/map.js';
51
+ import type { InteractiveMapInitConfig } from '../../client/javascripts/map.js';
46
52
  import type { MapsEnvironmentConfig } from '../../client/javascripts/map.js';
@@ -29,7 +29,7 @@ export function getTexts(lang = DEFAULT_LANG) {
29
29
  * Gets initial map config for a location field
30
30
  * @param {HTMLDivElement} locationField - the location field element
31
31
  */
32
- function getInitMapConfig(locationField) {
32
+ export function getInitMapConfig(locationField) {
33
33
  const locationType = locationField.dataset.locationtype;
34
34
  switch (locationType) {
35
35
  case 'latlongfield':
@@ -1 +1 @@
1
- {"version":3,"file":"location-map.js","names":["createDatasetsPlugin","DEFAULT_LANG","ENGLISH_LANG","WELSH_LANG","EVENTS","centerMap","createMap","defaultConfig","eastingNorthingToLatLong","getMapCountryLayers","getMapLayers","latLongToEastingNorthing","latLongToOsGridRef","osGridRefToLatLong","sssiDataset","cy","type","enGB","englishTranslations","components","locationFieldBase","map","welshTranslations","LOCATION_FIELD_SELECTOR","languageTexts","getTexts","lang","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","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","country","mapLayers","maplayers","datasets","apiPath","push","plugins","interactPlugin","mapReady","onMapReady","texts","addPanel","focus","showLabel","label","helpPanel","mobile","slot","open","dismissible","modal","tablet","desktop","html","point1","point2","point3","point4","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 DEFAULT_LANG,\n ENGLISH_LANG,\n WELSH_LANG\n} from '~/src/client/javascripts/map-constants.js'\nimport {\n EVENTS,\n centerMap,\n createMap,\n defaultConfig,\n eastingNorthingToLatLong,\n getMapCountryLayers,\n getMapLayers,\n latLongToEastingNorthing,\n latLongToOsGridRef,\n osGridRefToLatLong\n} from '~/src/client/javascripts/map.js'\nimport sssiDataset from '~/src/client/javascripts/sssi-dataset.js'\nimport cy from '~/src/server/plugins/engine/i18n/translations/cy.json' with { type: 'json' }\nimport enGB from '~/src/server/plugins/engine/i18n/translations/en-GB.json' with { type: 'json' }\n\nconst englishTranslations = enGB.components.locationFieldBase.map\nconst welshTranslations = cy.components.locationFieldBase.map\n\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\n\n/**\n * @type {Record<LanguageCode, LocationLanguageTexts>}\n */\nexport const languageTexts = {\n [ENGLISH_LANG]: englishTranslations,\n [WELSH_LANG]: welshTranslations\n}\n\n/**\n * Get the map texts for the given language code\n * @param {LanguageCode} lang - the lanugae code\n */\nexport function getTexts(lang = DEFAULT_LANG) {\n return languageTexts[lang]\n}\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 country = location.dataset.country\n const mapLayers = getMapLayers(location.dataset.maplayers)\n const datasets = getMapCountryLayers(config.apiPath, country)\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 lang = /** @type {LanguageCode} */ (\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n location.dataset.lang || DEFAULT_LANG\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 const texts = getTexts(lang)\n\n // Add info panel\n map.addPanel('info', {\n focus: false,\n showLabel: true,\n label: texts.helpPanel.label,\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>${texts.helpPanel.point1}</li><li>${texts.helpPanel.point2}</li><li>${texts.helpPanel.point3}</li><li>${texts.helpPanel.point4}</li></ul>`\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\n )\n}\n\n/**\n * @typedef {object} LocationPanelTexts\n * @property {string} label - the label for the info panel\n * @property {string} point1 - the text for bullet point 1 in the info panel\n * @property {string} point2 - the text for bullet point 2 in the info panel\n * @property {string} point3 - the text for bullet point 3 in the info panel\n * @property {string} point4 - the text for bullet point 4 in the info panel\n */\n\n/**\n * @typedef {object} LocationLanguageTexts\n * @property {LocationPanelTexts} helpPanel - texts for the info panel\n */\n\n/**\n * @import { LanguageCode } from '~/src/client/javascripts/map.js'\n * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'\n */\n"],"mappings":"AAAA;AACA,OAAOA,oBAAoB,MAAM,yCAAyC;AAE1E,SACEC,YAAY,EACZC,YAAY,EACZC,UAAU;AAEZ,SACEC,MAAM,EACNC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,mBAAmB,EACnBC,YAAY,EACZC,wBAAwB,EACxBC,kBAAkB,EAClBC,kBAAkB;AAEpB,OAAOC,WAAW;AAClB,OAAOC,EAAE,qEAAqEC,IAAI,EAAE,MAAM;AAC1F,OAAOC,IAAI,wEAAwED,IAAI,EAAE,MAAM;AAE/F,MAAME,mBAAmB,GAAGD,IAAI,CAACE,UAAU,CAACC,iBAAiB,CAACC,GAAG;AACjE,MAAMC,iBAAiB,GAAGP,EAAE,CAACI,UAAU,CAACC,iBAAiB,CAACC,GAAG;AAE7D,MAAME,uBAAuB,GAAG,mBAAmB;;AAEnD;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG;EAC3B,CAACtB,YAAY,GAAGgB,mBAAmB;EACnC,CAACf,UAAU,GAAGmB;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASG,QAAQA,CAACC,IAAI,GAAGzB,YAAY,EAAE;EAC5C,OAAOuB,aAAa,CAACE,IAAI,CAAC;AAC5B;;AAEA;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;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S,MAAM,YAAYd,KAAK,CAACK,SAAS,CAACU,MAAM,YAAYf,KAAK,CAACK,SAAS,CAACW,MAAM,YAAYhB,KAAK,CAACK,SAAS,CAACY,MAAM;IAC/I,CAAC,CAAC;;IAEF;IACApB,cAAc,CAACqB,MAAM,CAAC,CAAC;EACzB,CACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"location-map.js","names":["createDatasetsPlugin","DEFAULT_LANG","ENGLISH_LANG","WELSH_LANG","EVENTS","centerMap","createMap","defaultConfig","eastingNorthingToLatLong","getMapCountryLayers","getMapLayers","latLongToEastingNorthing","latLongToOsGridRef","osGridRefToLatLong","sssiDataset","cy","type","enGB","englishTranslations","components","locationFieldBase","map","welshTranslations","LOCATION_FIELD_SELECTOR","languageTexts","getTexts","lang","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","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","country","mapLayers","maplayers","datasets","apiPath","push","plugins","interactPlugin","mapReady","onMapReady","texts","addPanel","focus","showLabel","label","helpPanel","mobile","slot","open","dismissible","modal","tablet","desktop","html","point1","point2","point3","point4","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 DEFAULT_LANG,\n ENGLISH_LANG,\n WELSH_LANG\n} from '~/src/client/javascripts/map-constants.js'\nimport {\n EVENTS,\n centerMap,\n createMap,\n defaultConfig,\n eastingNorthingToLatLong,\n getMapCountryLayers,\n getMapLayers,\n latLongToEastingNorthing,\n latLongToOsGridRef,\n osGridRefToLatLong\n} from '~/src/client/javascripts/map.js'\nimport sssiDataset from '~/src/client/javascripts/sssi-dataset.js'\nimport cy from '~/src/server/plugins/engine/i18n/translations/cy.json' with { type: 'json' }\nimport enGB from '~/src/server/plugins/engine/i18n/translations/en-GB.json' with { type: 'json' }\n\nconst englishTranslations = enGB.components.locationFieldBase.map\nconst welshTranslations = cy.components.locationFieldBase.map\n\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\n\n/**\n * @type {Record<LanguageCode, LocationLanguageTexts>}\n */\nexport const languageTexts = {\n [ENGLISH_LANG]: englishTranslations,\n [WELSH_LANG]: welshTranslations\n}\n\n/**\n * Get the map texts for the given language code\n * @param {LanguageCode} lang - the lanugae code\n */\nexport function getTexts(lang = DEFAULT_LANG) {\n return languageTexts[lang]\n}\n\n/**\n * Gets initial map config for a location field\n * @param {HTMLDivElement} locationField - the location field element\n */\nexport function 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 country = location.dataset.country\n const mapLayers = getMapLayers(location.dataset.maplayers)\n const datasets = getMapCountryLayers(config.apiPath, country)\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 lang = /** @type {LanguageCode} */ (\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n location.dataset.lang || DEFAULT_LANG\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 const texts = getTexts(lang)\n\n // Add info panel\n map.addPanel('info', {\n focus: false,\n showLabel: true,\n label: texts.helpPanel.label,\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>${texts.helpPanel.point1}</li><li>${texts.helpPanel.point2}</li><li>${texts.helpPanel.point3}</li><li>${texts.helpPanel.point4}</li></ul>`\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\n )\n}\n\n/**\n * @typedef {object} LocationPanelTexts\n * @property {string} label - the label for the info panel\n * @property {string} point1 - the text for bullet point 1 in the info panel\n * @property {string} point2 - the text for bullet point 2 in the info panel\n * @property {string} point3 - the text for bullet point 3 in the info panel\n * @property {string} point4 - the text for bullet point 4 in the info panel\n */\n\n/**\n * @typedef {object} LocationLanguageTexts\n * @property {LocationPanelTexts} helpPanel - texts for the info panel\n */\n\n/**\n * @import { LanguageCode } from '~/src/client/javascripts/map.js'\n * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'\n */\n"],"mappings":"AAAA;AACA,OAAOA,oBAAoB,MAAM,yCAAyC;AAE1E,SACEC,YAAY,EACZC,YAAY,EACZC,UAAU;AAEZ,SACEC,MAAM,EACNC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,mBAAmB,EACnBC,YAAY,EACZC,wBAAwB,EACxBC,kBAAkB,EAClBC,kBAAkB;AAEpB,OAAOC,WAAW;AAClB,OAAOC,EAAE,qEAAqEC,IAAI,EAAE,MAAM;AAC1F,OAAOC,IAAI,wEAAwED,IAAI,EAAE,MAAM;AAE/F,MAAME,mBAAmB,GAAGD,IAAI,CAACE,UAAU,CAACC,iBAAiB,CAACC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AAC;QACxC;MACF;QACE,MAAM,IAAIc,KAAK,CAAC,iBAAiB,CAAC;IACtC;IAEA,MAAM2F,KAAK,GAAGrG,QAAQ,CAACC,IAAI,CAAC;;IAE5B;IACAL,GAAG,CAAC0G,QAAQ,CAAC,MAAM,EAAE;MACnBC,KAAK,EAAE,KAAK;MACZC,SAAS,EAAE,IAAI;MACfC,KAAK,EAAEJ,KAAK,CAACK,SAAS,CAACD,KAAK;MAC5BE,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,WAAWb,KAAK,CAACK,SAAS,CAACS,MAAM,YAAYd,KAAK,CAACK,SAAS,CAACU,MAAM,YAAYf,KAAK,CAACK,SAAS,CAACW,MAAM,YAAYhB,KAAK,CAACK,SAAS,CAACY,MAAM;IAC/I,CAAC,CAAC;;IAEF;IACApB,cAAc,CAACqB,MAAM,CAAC,CAAC;EACzB,CACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,9 +1,110 @@
1
1
  import { type OsGridRefFieldComponent } from '@defra/forms-model';
2
2
  import { LocationFieldBase } from '../../../../server/plugins/engine/components/LocationFieldBase.js';
3
+ import { type RenderContext } from '../../../../server/plugins/engine/components/types.js';
3
4
  import { type Translator } from '../../../../server/plugins/engine/types/index.js';
4
5
  import { type ErrorMessageTemplateList } from '../../../../server/plugins/engine/types.js';
5
6
  export declare class OsGridRefField extends LocationFieldBase {
6
7
  options: OsGridRefFieldComponent['options'];
8
+ getViewModel(context: RenderContext): {
9
+ label: {
10
+ text: string;
11
+ };
12
+ id: string;
13
+ name: string;
14
+ value: import("../../../../server/plugins/engine/types.js").FormValue;
15
+ type?: string;
16
+ hint?: {
17
+ id?: string;
18
+ text: string;
19
+ };
20
+ prefix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
21
+ suffix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
22
+ classes?: string;
23
+ condition?: string;
24
+ errors?: import("../../../../server/plugins/engine/types.js").FormSubmissionError[];
25
+ errorMessage?: {
26
+ text: string;
27
+ };
28
+ summaryHtml?: string;
29
+ html?: string;
30
+ attributes: {
31
+ autocomplete?: string;
32
+ maxlength?: number;
33
+ multiple?: string;
34
+ accept?: string;
35
+ inputmode?: string;
36
+ };
37
+ content?: import("../../../../server/plugins/engine/components/types.js").Content | import("../../../../server/plugins/engine/components/types.js").Content[] | string;
38
+ maxlength?: number;
39
+ maxwords?: number;
40
+ rows?: number;
41
+ items?: import("../../../../server/plugins/engine/components/types.js").ListItem[] | import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
42
+ fieldset?: {
43
+ attributes?: string | Record<string, string>;
44
+ legend?: import("../../../../server/plugins/engine/components/types.js").Label;
45
+ };
46
+ formGroup?: {
47
+ classes?: string;
48
+ attributes?: string | Record<string, string>;
49
+ };
50
+ showFieldsetError?: boolean;
51
+ components?: import("../../../../server/plugins/engine/components/types.js").ComponentViewModel[];
52
+ upload?: {
53
+ count: number;
54
+ summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
55
+ uploadingLabel?: string;
56
+ };
57
+ } | {
58
+ instructionText: string;
59
+ label: {
60
+ text: string;
61
+ };
62
+ id: string;
63
+ name: string;
64
+ value: import("../../../../server/plugins/engine/types.js").FormValue;
65
+ type?: string;
66
+ hint?: {
67
+ id?: string;
68
+ text: string;
69
+ };
70
+ prefix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
71
+ suffix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
72
+ classes?: string;
73
+ condition?: string;
74
+ errors?: import("../../../../server/plugins/engine/types.js").FormSubmissionError[];
75
+ errorMessage?: {
76
+ text: string;
77
+ };
78
+ summaryHtml?: string;
79
+ html?: string;
80
+ attributes: {
81
+ autocomplete?: string;
82
+ maxlength?: number;
83
+ multiple?: string;
84
+ accept?: string;
85
+ inputmode?: string;
86
+ };
87
+ content?: import("../../../../server/plugins/engine/components/types.js").Content | import("../../../../server/plugins/engine/components/types.js").Content[] | string;
88
+ maxlength?: number;
89
+ maxwords?: number;
90
+ rows?: number;
91
+ items?: import("../../../../server/plugins/engine/components/types.js").ListItem[] | import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
92
+ fieldset?: {
93
+ attributes?: string | Record<string, string>;
94
+ legend?: import("../../../../server/plugins/engine/components/types.js").Label;
95
+ };
96
+ formGroup?: {
97
+ classes?: string;
98
+ attributes?: string | Record<string, string>;
99
+ };
100
+ showFieldsetError?: boolean;
101
+ components?: import("../../../../server/plugins/engine/components/types.js").ComponentViewModel[];
102
+ upload?: {
103
+ count: number;
104
+ summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
105
+ uploadingLabel?: string;
106
+ };
107
+ };
7
108
  protected getValidationConfig(translator: Translator | undefined): {
8
109
  pattern: RegExp;
9
110
  patternErrorMessage: import("joi").JoiExpression;
@@ -1,8 +1,17 @@
1
1
  import { EN_GB } from "../../../constants.js";
2
2
  import { LocationFieldBase } from "./LocationFieldBase.js";
3
+ import { getMapLayers } from "./LocationFieldHelpers.js";
3
4
  import { createLowerFirstExpression } from "./helpers/index.js";
4
5
  import { t } from "../i18n/index.js";
5
6
  export class OsGridRefField extends LocationFieldBase {
7
+ getViewModel(context) {
8
+ const viewModel = super.getViewModel(context);
9
+ Object.assign(viewModel, {
10
+ lang: context.translator.language,
11
+ mapLayers: getMapLayers(this)
12
+ });
13
+ return viewModel;
14
+ }
6
15
  getValidationConfig(translator) {
7
16
  // Regex for OS national grid references (NGR)
8
17
  // Validates specific valid OS grid letter combinations with:
@@ -1 +1 @@
1
- {"version":3,"file":"OsGridRefField.js","names":["EN_GB","LocationFieldBase","createLowerFirstExpression","t","OsGridRefField","getValidationConfig","translator","pattern","patternErrorMessage","requiredMessage","getErrorTemplates","type","template","getAllPossibleErrors","baseErrors","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/OsGridRefField.ts"],"sourcesContent":["import { type OsGridRefFieldComponent } from '@defra/forms-model'\n\nimport { EN_GB } from '~/src/server/constants.js'\nimport { LocationFieldBase } from '~/src/server/plugins/engine/components/LocationFieldBase.js'\nimport { createLowerFirstExpression } from '~/src/server/plugins/engine/components/helpers/index.js'\nimport { t } from '~/src/server/plugins/engine/i18n/index.js'\nimport { type Translator } from '~/src/server/plugins/engine/types/index.js'\nimport { type ErrorMessageTemplateList } from '~/src/server/plugins/engine/types.js'\n\nexport class OsGridRefField extends LocationFieldBase {\n declare options: OsGridRefFieldComponent['options']\n\n protected getValidationConfig(translator: Translator | undefined) {\n // Regex for OS national grid references (NGR)\n // Validates specific valid OS grid letter combinations with:\n // - 2 letters & 6 digits in 2 blocks of 3 e.g. ST 678 678\n // - 2 letters & 8 digits in 2 blocks of 4 e.g. ST 6789 6789\n // - 2 letters & 10 digits in 2 blocks of 5 e.g. SO 12345 12345\n // Optional spaces between each block\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 return {\n pattern,\n patternErrorMessage: createLowerFirstExpression(\n translator\n ? translator.t('components.osGridRefField.pattern')\n : t('components.osGridRefField.pattern', EN_GB)\n ),\n requiredMessage: createLowerFirstExpression(\n translator\n ? translator.t('components.osGridRefField.required')\n : t('components.osGridRefField.required', EN_GB)\n )\n }\n }\n\n protected getErrorTemplates() {\n return [\n {\n type: 'pattern',\n template: createLowerFirstExpression(\n t('components.osGridRefField.pattern', 'en-GB')\n )\n }\n ]\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 {\n type: 'required',\n template: createLowerFirstExpression(\n t('components.osGridRefField.required', 'en-GB')\n )\n },\n {\n type: 'pattern',\n template: createLowerFirstExpression(\n t('components.osGridRefField.pattern', 'en-GB')\n )\n }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAEA,SAASA,KAAK;AACd,SAASC,iBAAiB;AAC1B,SAASC,0BAA0B;AACnC,SAASC,CAAC;AAIV,OAAO,MAAMC,cAAc,SAASH,iBAAiB,CAAC;EAG1CI,mBAAmBA,CAACC,UAAkC,EAAE;IAChE;IACA;IACA;IACA;IACA;IACA;IACA,MAAMC,OAAO,GACX,qLAAqL;IAEvL,OAAO;MACLA,OAAO;MACPC,mBAAmB,EAAEN,0BAA0B,CAC7CI,UAAU,GACNA,UAAU,CAACH,CAAC,CAAC,mCAAmC,CAAC,GACjDA,CAAC,CAAC,mCAAmC,EAAEH,KAAK,CAClD,CAAC;MACDS,eAAe,EAAEP,0BAA0B,CACzCI,UAAU,GACNA,UAAU,CAACH,CAAC,CAAC,oCAAoC,CAAC,GAClDA,CAAC,CAAC,oCAAoC,EAAEH,KAAK,CACnD;IACF,CAAC;EACH;EAEUU,iBAAiBA,CAAA,EAAG;IAC5B,OAAO,CACL;MACEC,IAAI,EAAE,SAAS;MACfC,QAAQ,EAAEV,0BAA0B,CAClCC,CAAC,CAAC,mCAAmC,EAAE,OAAO,CAChD;IACF,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,OAAOU,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QACEH,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAEV,0BAA0B,CAClCC,CAAC,CAAC,oCAAoC,EAAE,OAAO,CACjD;MACF,CAAC,EACD;QACEQ,IAAI,EAAE,SAAS;QACfC,QAAQ,EAAEV,0BAA0B,CAClCC,CAAC,CAAC,mCAAmC,EAAE,OAAO,CAChD;MACF,CAAC,CACF;MACDY,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"OsGridRefField.js","names":["EN_GB","LocationFieldBase","getMapLayers","createLowerFirstExpression","t","OsGridRefField","getViewModel","context","viewModel","Object","assign","lang","translator","language","mapLayers","getValidationConfig","pattern","patternErrorMessage","requiredMessage","getErrorTemplates","type","template","getAllPossibleErrors","baseErrors","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/OsGridRefField.ts"],"sourcesContent":["import { type OsGridRefFieldComponent } from '@defra/forms-model'\n\nimport { EN_GB } from '~/src/server/constants.js'\nimport { LocationFieldBase } from '~/src/server/plugins/engine/components/LocationFieldBase.js'\nimport { getMapLayers } from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { createLowerFirstExpression } from '~/src/server/plugins/engine/components/helpers/index.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { t } from '~/src/server/plugins/engine/i18n/index.js'\nimport { type Translator } from '~/src/server/plugins/engine/types/index.js'\nimport { type ErrorMessageTemplateList } from '~/src/server/plugins/engine/types.js'\n\nexport class OsGridRefField extends LocationFieldBase {\n declare options: OsGridRefFieldComponent['options']\n\n getViewModel(context: RenderContext) {\n const viewModel = super.getViewModel(context)\n\n Object.assign(viewModel, {\n lang: context.translator.language,\n mapLayers: getMapLayers(this)\n })\n\n return viewModel\n }\n\n protected getValidationConfig(translator: Translator | undefined) {\n // Regex for OS national grid references (NGR)\n // Validates specific valid OS grid letter combinations with:\n // - 2 letters & 6 digits in 2 blocks of 3 e.g. ST 678 678\n // - 2 letters & 8 digits in 2 blocks of 4 e.g. ST 6789 6789\n // - 2 letters & 10 digits in 2 blocks of 5 e.g. SO 12345 12345\n // Optional spaces between each block\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 return {\n pattern,\n patternErrorMessage: createLowerFirstExpression(\n translator\n ? translator.t('components.osGridRefField.pattern')\n : t('components.osGridRefField.pattern', EN_GB)\n ),\n requiredMessage: createLowerFirstExpression(\n translator\n ? translator.t('components.osGridRefField.required')\n : t('components.osGridRefField.required', EN_GB)\n )\n }\n }\n\n protected getErrorTemplates() {\n return [\n {\n type: 'pattern',\n template: createLowerFirstExpression(\n t('components.osGridRefField.pattern', 'en-GB')\n )\n }\n ]\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 {\n type: 'required',\n template: createLowerFirstExpression(\n t('components.osGridRefField.required', 'en-GB')\n )\n },\n {\n type: 'pattern',\n template: createLowerFirstExpression(\n t('components.osGridRefField.pattern', 'en-GB')\n )\n }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAEA,SAASA,KAAK;AACd,SAASC,iBAAiB;AAC1B,SAASC,YAAY;AACrB,SAASC,0BAA0B;AAEnC,SAASC,CAAC;AAIV,OAAO,MAAMC,cAAc,SAASJ,iBAAiB,CAAC;EAGpDK,YAAYA,CAACC,OAAsB,EAAE;IACnC,MAAMC,SAAS,GAAG,KAAK,CAACF,YAAY,CAACC,OAAO,CAAC;IAE7CE,MAAM,CAACC,MAAM,CAACF,SAAS,EAAE;MACvBG,IAAI,EAAEJ,OAAO,CAACK,UAAU,CAACC,QAAQ;MACjCC,SAAS,EAAEZ,YAAY,CAAC,IAAI;IAC9B,CAAC,CAAC;IAEF,OAAOM,SAAS;EAClB;EAEUO,mBAAmBA,CAACH,UAAkC,EAAE;IAChE;IACA;IACA;IACA;IACA;IACA;IACA,MAAMI,OAAO,GACX,qLAAqL;IAEvL,OAAO;MACLA,OAAO;MACPC,mBAAmB,EAAEd,0BAA0B,CAC7CS,UAAU,GACNA,UAAU,CAACR,CAAC,CAAC,mCAAmC,CAAC,GACjDA,CAAC,CAAC,mCAAmC,EAAEJ,KAAK,CAClD,CAAC;MACDkB,eAAe,EAAEf,0BAA0B,CACzCS,UAAU,GACNA,UAAU,CAACR,CAAC,CAAC,oCAAoC,CAAC,GAClDA,CAAC,CAAC,oCAAoC,EAAEJ,KAAK,CACnD;IACF,CAAC;EACH;EAEUmB,iBAAiBA,CAAA,EAAG;IAC5B,OAAO,CACL;MACEC,IAAI,EAAE,SAAS;MACfC,QAAQ,EAAElB,0BAA0B,CAClCC,CAAC,CAAC,mCAAmC,EAAE,OAAO,CAChD;IACF,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,OAAOkB,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QACEH,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAElB,0BAA0B,CAClCC,CAAC,CAAC,oCAAoC,EAAE,OAAO,CACjD;MACF,CAAC,EACD;QACEgB,IAAI,EAAE,SAAS;QACfC,QAAQ,EAAElB,0BAA0B,CAClCC,CAAC,CAAC,mCAAmC,EAAE,OAAO,CAChD;MACF,CAAC,CACF;MACDoB,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
@@ -5,7 +5,8 @@
5
5
  {% set hasErrors = component.model.errorMessage %}
6
6
  <div class="govuk-form-group app-location-field {{ "govuk-form-group--error" if hasErrors }}"
7
7
  data-locationtype="{{component.type | lower}}"
8
- data-lang="{{component.model.lang}}">
8
+ data-lang="{{component.model.lang}}"
9
+ data-maplayers="{{component.model.mapLayers}}">
9
10
  <div class="app-location-field-inputs">
10
11
  {{ TextField(component) }}
11
12
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-engine-plugin",
3
- "version": "5.0.0-alpha.13",
3
+ "version": "5.0.0-alpha.15",
4
4
  "description": "Defra forms engine",
5
5
  "type": "module",
6
6
  "files": [
@@ -47,7 +47,7 @@ export function getTexts(lang = DEFAULT_LANG) {
47
47
  * Gets initial map config for a location field
48
48
  * @param {HTMLDivElement} locationField - the location field element
49
49
  */
50
- function getInitMapConfig(locationField) {
50
+ export function getInitMapConfig(locationField) {
51
51
  const locationType = locationField.dataset.locationtype
52
52
 
53
53
  switch (locationType) {
@@ -2,7 +2,9 @@ import { type OsGridRefFieldComponent } from '@defra/forms-model'
2
2
 
3
3
  import { EN_GB } from '../../../constants.js'
4
4
  import { LocationFieldBase } from './LocationFieldBase.js'
5
+ import { getMapLayers } from './LocationFieldHelpers.js'
5
6
  import { createLowerFirstExpression } from './helpers/index.js'
7
+ import { type RenderContext } from './types.js'
6
8
  import { t } from '../i18n/index.js'
7
9
  import { type Translator } from '../types/index.js'
8
10
  import { type ErrorMessageTemplateList } from '../types.js'
@@ -10,6 +12,17 @@ import { type ErrorMessageTemplateList } from '../types.js'
10
12
  export class OsGridRefField extends LocationFieldBase {
11
13
  declare options: OsGridRefFieldComponent['options']
12
14
 
15
+ getViewModel(context: RenderContext) {
16
+ const viewModel = super.getViewModel(context)
17
+
18
+ Object.assign(viewModel, {
19
+ lang: context.translator.language,
20
+ mapLayers: getMapLayers(this)
21
+ })
22
+
23
+ return viewModel
24
+ }
25
+
13
26
  protected getValidationConfig(translator: Translator | undefined) {
14
27
  // Regex for OS national grid references (NGR)
15
28
  // Validates specific valid OS grid letter combinations with:
@@ -5,7 +5,8 @@
5
5
  {% set hasErrors = component.model.errorMessage %}
6
6
  <div class="govuk-form-group app-location-field {{ "govuk-form-group--error" if hasErrors }}"
7
7
  data-locationtype="{{component.type | lower}}"
8
- data-lang="{{component.model.lang}}">
8
+ data-lang="{{component.model.lang}}"
9
+ data-maplayers="{{component.model.mapLayers}}">
9
10
  <div class="app-location-field-inputs">
10
11
  {{ TextField(component) }}
11
12
  </div>