northants-design-system 3.2.2 → 3.3.0

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 (29) hide show
  1. package/build/index.d.ts +1 -3
  2. package/build/index.js +240 -135
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs.js +242 -135
  5. package/build/index.mjs.js.map +1 -1
  6. package/build/library/components/MapInfoWindow/MapInfoWindow.d.ts +4 -0
  7. package/build/library/components/MapInfoWindow/MapInfoWindow.types.d.ts +6 -0
  8. package/build/library/components/MapMarker/MapMarker.d.ts +2 -4
  9. package/build/library/components/MapMarker/MapMarker.types.d.ts +46 -0
  10. package/build/library/components/StaticMap/StaticMap.d.ts +6 -0
  11. package/build/library/components/StaticMap/StaticMap.types.d.ts +7 -3
  12. package/build/library/directory/DirectoryService/DirectoryService.storydata.d.ts +4 -0
  13. package/build/library/directory/DirectoryServiceMapMarker/DirectoryServiceMapMarker.d.ts +4 -0
  14. package/build/library/directory/DirectoryServiceMapMarker/DirectoryServiceMapMarker.types.d.ts +45 -0
  15. package/build/library/directory/DirectoryServiceMapMarkerSet/DirectoryServiceMapMarkerSet.d.ts +4 -0
  16. package/build/library/directory/DirectoryServiceMapMarkerSet/DirectoryServiceMapMarkerSet.storydata.d.ts +5 -0
  17. package/build/library/directory/DirectoryServiceMapMarkerSet/DirectoryServiceMapMarkerSet.types.d.ts +53 -0
  18. package/build/library/directory/DirectoryServiceStaticMap/DirectoryServiceStaticMap.d.ts +4 -0
  19. package/build/library/directory/DirectoryServiceStaticMap/DirectoryServiceStaticMap.types.d.ts +11 -0
  20. package/package.json +4 -5
  21. package/build/library/slices/LinkBlock/LinkBlock.d.ts +0 -4
  22. package/build/library/slices/LinkBlock/LinkBlock.types.d.ts +0 -36
  23. package/build/library/structure/CludoNewsSearch/CludoNewsDateSearch.d.ts +0 -6
  24. package/build/library/structure/CludoNewsSearch/CludoNewsResultCount.d.ts +0 -3
  25. package/build/library/structure/CludoNewsSearch/CludoNewsSearch.d.ts +0 -4
  26. package/build/library/structure/CludoNewsSearch/CludoNewsSearch.test.d.ts +0 -1
  27. package/build/library/structure/CludoNewsSearch/CludoNewsSearch.types.d.ts +0 -18
  28. package/build/library/structure/CludoNewsSearch/CludoNewsSort.d.ts +0 -3
  29. /package/build/library/{slices/LinkBlock/LinkBlock.test.d.ts → components/MapInfoWindow/MapInfoWindow.test.d.ts} +0 -0
package/build/index.d.ts CHANGED
@@ -6,8 +6,6 @@ import DynamicIcon from './library/components/DynamicIcon/DynamicIcon';
6
6
  import EventDetails from './library/components/EventDetails/EventDetails';
7
7
  import Heading from './library/components/Heading/Heading';
8
8
  import HeadingWithIcon from './library/components/HeadingWithIcon/HeadingWithIcon';
9
- import Map from './library/components/Map/Map';
10
- import MapMarker from './library/components/MapMarker/MapMarker';
11
9
  import Pagination from './library/components/Pagination/Pagination';
12
10
  import CheckboxListFilter from './library/components/CheckboxListFilter/CheckboxListFilter';
13
11
  import DropDownFilter from './library/components/DropDownFilter/DropDownFilter';
@@ -19,7 +17,7 @@ import SummaryList from './library/components/SummaryList/SummaryList';
19
17
  import TextInput from './library/components/TextInput/TextInput';
20
18
  import ToggleButtons from './library/components/ToggleButtons/ToggleButtons';
21
19
  import QuickExit from './library/components/QuickExit/QuickExit';
22
- export { Autocomplete, BackToTop, Button, ConsultationStatus, DynamicIcon, EventDetails, Heading, HeadingWithIcon, Map, MapMarker, Pagination, CheckboxListFilter, DropDownFilter, PromotedLinks, RelatedEvents, ResponsiveImage, QuickExit, StaticMap, SummaryList, TextInput, ToggleButtons, };
20
+ export { Autocomplete, BackToTop, Button, ConsultationStatus, DynamicIcon, EventDetails, Heading, HeadingWithIcon, Pagination, CheckboxListFilter, DropDownFilter, PromotedLinks, RelatedEvents, ResponsiveImage, QuickExit, StaticMap, SummaryList, TextInput, ToggleButtons, };
23
21
  import Accordion from './library/slices/Accordion/Accordion';
24
22
  import BinFinder from './library/slices/BinFinder/BinFinder';
25
23
  import BlockLinks from './library/slices/BlockLinks/BlockLinks';
package/build/index.js CHANGED
@@ -8,7 +8,7 @@ var require$$0$1 = require('fs');
8
8
  var axios = require('axios');
9
9
  var reactHookForm = require('react-hook-form');
10
10
  var ssr = require('@cludosearch/cludo-search-components/ssr');
11
- var reactWrapper = require('@googlemaps/react-wrapper');
11
+ var reactGoogleMaps = require('@vis.gl/react-google-maps');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
@@ -3744,7 +3744,7 @@ var Autocomplete = function (_a) {
3744
3744
  })));
3745
3745
  };
3746
3746
 
3747
- const Container$1v = styled__default.default.div`
3747
+ const Container$1u = styled__default.default.div`
3748
3748
  display: block;
3749
3749
  `;
3750
3750
 
@@ -3830,7 +3830,7 @@ var BackToTop = function (_a) {
3830
3830
  React.useEffect(function () {
3831
3831
  window.addEventListener('scroll', toggleVisible);
3832
3832
  });
3833
- return (React__namespace.default.createElement(Container$1v, { "data-testid": "BackToTop" }, isActive && (React__namespace.default.createElement(BackToTopButton, { onClick: scrollToTop, "$visible": visible, "data-testid": "BackToTopButton", type: "button", "aria-label": "Go to the top of the page" },
3833
+ return (React__namespace.default.createElement(Container$1u, { "data-testid": "BackToTop" }, isActive && (React__namespace.default.createElement(BackToTopButton, { onClick: scrollToTop, "$visible": visible, "data-testid": "BackToTopButton", type: "button", "aria-label": "Go to the top of the page" },
3834
3834
  React__namespace.default.createElement(ChevronIcon, { colourFill: theme.theme_vars.colours.white, direction: "up" })))));
3835
3835
  };
3836
3836
 
@@ -3923,7 +3923,7 @@ var Button$5 = function (_a) {
3923
3923
  return (React__namespace.default.createElement(StyledButton$1, __assign({ className: ["button--".concat(size), mode].join(' ') }, href, { title: title ? title : text, "$colourOverride": colourOverride && colourOverride }, props), text ? text : children));
3924
3924
  };
3925
3925
 
3926
- const Container$1u = styled__default.default.div`
3926
+ const Container$1t = styled__default.default.div`
3927
3927
  display: block;
3928
3928
  background-color: ${(props) =>
3929
3929
  props.$isOpen ? props.theme.theme_vars.colours.positive : props.theme.theme_vars.colours.negative}16;
@@ -19621,7 +19621,7 @@ var ConsultationStatus = function (_a) {
19621
19621
  detail: new Date(closeDate).toLocaleDateString('en-GB'),
19622
19622
  },
19623
19623
  ];
19624
- return (React__namespace.default.createElement(Container$1u, { "data-testid": "ConsultationStatus", "$isOpen": isOpen },
19624
+ return (React__namespace.default.createElement(Container$1t, { "data-testid": "ConsultationStatus", "$isOpen": isOpen },
19625
19625
  React__namespace.default.createElement(SummaryList, { terms: terms, hasBorders: false, hasMargin: false, hasWrapOnMobile: false })));
19626
19626
  };
19627
19627
 
@@ -21834,7 +21834,7 @@ var DynamicIcon = function (_a) {
21834
21834
  React__namespace.default.createElement(DynamicComponent, { name: icon, isHover: true }))))));
21835
21835
  };
21836
21836
 
21837
- const Container$1t = styled__default.default.div`
21837
+ const Container$1s = styled__default.default.div`
21838
21838
  display: block;
21839
21839
  padding: ${(props) => props.theme.theme_vars.spacingSizes.small};
21840
21840
  border-bottom: ${(props) => (props.$hasBorder ? `1px solid ${props.theme.theme_vars.colours.grey}` : 'none')};
@@ -22006,94 +22006,13 @@ var formatDateRange = function (startDate, endDate) {
22006
22006
 
22007
22007
  var EventDetails = function (_a) {
22008
22008
  var startTime = _a.startTime, endTime = _a.endTime, location = _a.location, _b = _a.hasBorder, hasBorder = _b === void 0 ? true : _b, _c = _a.hasMargin, hasMargin = _c === void 0 ? true : _c;
22009
- return (React__namespace.default.createElement(Container$1t, { "data-testid": "EventDetails", "$hasBorder": hasBorder, "$hasMargin": hasMargin },
22009
+ return (React__namespace.default.createElement(Container$1s, { "data-testid": "EventDetails", "$hasBorder": hasBorder, "$hasMargin": hasMargin },
22010
22010
  React__namespace.default.createElement(EventRow, null,
22011
22011
  React__namespace.default.createElement(HeadingWithIcon, { icon: "events", level: 4, text: formatDateRange(startTime, endTime), hasHover: false })),
22012
22012
  React__namespace.default.createElement(EventRow, null,
22013
22013
  React__namespace.default.createElement(HeadingWithIcon, { icon: "address", level: 4, text: location, hasHover: false }))));
22014
22014
  };
22015
22015
 
22016
- const Container$1s = styled__default.default.div`
22017
- display: flex;
22018
- width: 100%;
22019
- min-height: 400px;
22020
- align-items: stretch;
22021
- align-content: stretch;
22022
-
22023
- & > div {
22024
- width: 100%;
22025
- }
22026
- `;
22027
-
22028
- /**
22029
- * An interactive Google Map which can accept MapMarkers as children
22030
- */
22031
- var Map$1 = function (_a) {
22032
- var center = _a.center, zoom = _a.zoom, children = _a.children;
22033
- var ref = React__namespace.default.useRef(null);
22034
- var _b = React__namespace.default.useState(), map = _b[0], setMap = _b[1];
22035
- React__namespace.default.useEffect(function () {
22036
- if (ref.current && !map) {
22037
- setMap(new window.google.maps.Map(ref.current, { center: center, zoom: zoom }));
22038
- }
22039
- }, [ref, map]);
22040
- return (React__namespace.default.createElement(Container$1s, { "data-testid": "Map" },
22041
- React__namespace.default.createElement("div", { ref: ref }),
22042
- React__namespace.default.Children.map(children, function (child) {
22043
- if (React__namespace.default.isValidElement(child)) {
22044
- // set the map prop on the child component
22045
- // @ts-ignore
22046
- return React__namespace.default.cloneElement(child, { map: map });
22047
- }
22048
- })));
22049
- };
22050
-
22051
- /**
22052
- * A Google Maps marker to be placed inside a Map component
22053
- */
22054
- var MapMarker = function (options) {
22055
- var _a = React__namespace.default.useState(), marker = _a[0], setMarker = _a[1];
22056
- var theme = styled.useTheme();
22057
- var icon = {
22058
- path: 'M19.7,5.6c-0.1,0-0.5,0.1-0.9,0.1c-3.3,0.4-6.5,2-8.9,4.4c-2.6,2.6-4.2,5.9-4.6,9.6c-0.1,1,0,3.1,0.1,4.1c0.3,2.1,1.1,4.2,2.3,6.6c0.9,1.6,1.6,2.9,4.2,7c0.9,1.4,1.9,3.1,2.6,4.2c2.3,3.9,4.1,7.9,5.4,11.9c0.2,0.6,0.3,0.8,0.6,0.9c0.5,0.2,1.1,0.1,1.4-0.3c0.1-0.1,0.2-0.5,0.4-0.9c1.1-3.3,2.5-6.5,4.2-9.5c1.2-2.2,2-3.6,4.4-7.4c1.7-2.7,2.3-3.6,2.9-4.8c1.6-2.9,2.5-5.3,2.9-7.8c0.2-1,0.2-3.1,0.1-4.1c-0.2-1.5-0.5-3-1-4.2c-2.1-5.2-6.8-8.9-12.4-9.8C22.9,5.6,20.2,5.5,19.7,5.6z',
22059
- fillColor: "".concat(theme.theme_vars.colours.action_dark),
22060
- fillOpacity: 1,
22061
- anchor: new google.maps.Point(40, 60),
22062
- labelOrigin: new google.maps.Point(21, 25),
22063
- };
22064
- var mergedOptions = __assign(__assign({}, options), { anchorPoint: new google.maps.Point(-5, -40), icon: icon, label: {
22065
- text: typeof options.label === 'string' ? options.label : options.label.text,
22066
- color: 'white',
22067
- }, position: options.position, title: options.title });
22068
- React__namespace.default.useEffect(function () {
22069
- if (!marker) {
22070
- setMarker(new google.maps.Marker());
22071
- }
22072
- // remove marker from map on unmount
22073
- return function () {
22074
- if (marker) {
22075
- marker.setMap(null);
22076
- }
22077
- };
22078
- }, [marker]);
22079
- React__namespace.default.useEffect(function () {
22080
- if (marker) {
22081
- var infoWindow_1 = new google.maps.InfoWindow({
22082
- content: "<strong>".concat(options.title, "</strong>"),
22083
- ariaLabel: options.title,
22084
- });
22085
- marker.setOptions(mergedOptions);
22086
- marker.addListener('click', function () {
22087
- infoWindow_1.open({
22088
- anchor: marker,
22089
- map: options.map,
22090
- });
22091
- });
22092
- }
22093
- }, [marker, options]);
22094
- return null;
22095
- };
22096
-
22097
22016
  const Container$1r = styled__default.default.div`
22098
22017
  ${(props) => props.theme.fontStyles};
22099
22018
  display: block;
@@ -24051,6 +23970,51 @@ var CookieBanner = function (_a) {
24051
23970
  React__namespace.default.createElement(CookieHide, { onClick: hideCookiesConfirmationBanner, "aria-controls": "CookieBannerAccepted", "aria-hidden": "false" }, "Hide"))))));
24052
23971
  };
24053
23972
 
23973
+ /**
23974
+ * A function to validate whether a given latitude/longitude pair are valid
23975
+ * Ths function can be used to prevent untrusted backend/CMS values from
23976
+ * injecting extra query parameters into the Static Maps request.
23977
+ */
23978
+ var isValidLatLng = function (lat, lng) {
23979
+ var latNum = Number(lat);
23980
+ var lngNum = Number(lng);
23981
+ return (typeof lat !== 'undefined' &&
23982
+ typeof lng !== 'undefined' &&
23983
+ lat !== null &&
23984
+ lng !== null &&
23985
+ "".concat(lat).trim() !== '' &&
23986
+ "".concat(lng).trim() !== '' &&
23987
+ Number.isFinite(latNum) &&
23988
+ Number.isFinite(lngNum) &&
23989
+ latNum >= -90 &&
23990
+ latNum <= 90 &&
23991
+ lngNum >= -180 &&
23992
+ lngNum <= 180);
23993
+ };
23994
+ /**
23995
+ * Constrains a marker label to a single character in the API's allowed
23996
+ * set (A-Z, 0-9). Returns an empty string if nothing valid is supplied.
23997
+ */
23998
+ var sanitiseLabel = function (label) {
23999
+ if (!label) {
24000
+ return '';
24001
+ }
24002
+ var cleaned = label.replace(/[^A-Z0-9]/gi, '');
24003
+ return cleaned.length > 0 ? cleaned.charAt(0).toUpperCase() : '';
24004
+ };
24005
+ /**
24006
+ * Builds a single, fully URL-encoded `&markers=...` segment. Encoding the
24007
+ * whole value ensures colour/size/label (whose TypeScript unions only
24008
+ * apply at compile time) cannot break out of their parameter.
24009
+ */
24010
+ var buildMarkerSegment = function (size, colour, label, latitude, longitude) {
24011
+ var parts = ["size:".concat(size), "color:".concat(colour)];
24012
+ if (label) {
24013
+ parts.push("label:".concat(label));
24014
+ }
24015
+ parts.push("".concat(latitude, ",").concat(longitude));
24016
+ return "&markers=".concat(encodeURIComponent(parts.join('|')));
24017
+ };
24054
24018
  /**
24055
24019
  * A static Google map with optional markers
24056
24020
  */
@@ -24059,21 +24023,29 @@ var StaticMap = function (_a) {
24059
24023
  var centre = _a.centre, imageAltText = _a.imageAltText, _c = _a.mapMarkers, mapMarkers = _c === void 0 ? [] : _c, _d = _a.mapType, mapType = _d === void 0 ? 'roadmap' : _d, _e = _a.size, size = _e === void 0 ? '640x320' : _e, _f = _a.zoom, zoom = _f === void 0 ? 14 : _f;
24060
24024
  var apiKey = (_b = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY) !== null && _b !== void 0 ? _b : '';
24061
24025
  var markerPath = mapMarkers
24026
+ .filter(function (mapMarker) { return isValidLatLng(mapMarker.lat, mapMarker.lng); })
24062
24027
  .map(function (mapMarker) {
24063
24028
  var _a, _b;
24064
- var size = (_a = mapMarker.size) !== null && _a !== void 0 ? _a : 'normal';
24065
- var colour = (_b = mapMarker.colour) !== null && _b !== void 0 ? _b : 'red';
24066
- var label = mapMarker.label ? "%7Clabel:".concat(mapMarker.label) : '';
24067
- return "&markers=size:".concat(size, "%7Ccolor:").concat(colour).concat(label, "%7C").concat(mapMarker.lat, ",").concat(mapMarker.lng);
24029
+ return buildMarkerSegment((_a = mapMarker.size) !== null && _a !== void 0 ? _a : 'normal', (_b = mapMarker.colour) !== null && _b !== void 0 ? _b : 'red', sanitiseLabel(mapMarker.label), String(mapMarker.lat), String(mapMarker.lng));
24068
24030
  })
24069
24031
  .join('');
24032
+ // Build the base parameters via URLSearchParams so that centre/size/zoom/
24033
+ // maptype are percent-encoded and cannot inject additional query params.
24034
+ var params = new URLSearchParams({
24035
+ center: centre,
24036
+ size: size,
24037
+ zoom: "".concat(zoom),
24038
+ maptype: mapType,
24039
+ key: apiKey,
24040
+ });
24041
+ var mapSrc = "https://maps.googleapis.com/maps/api/staticmap?".concat(params.toString()).concat(markerPath);
24070
24042
  return (React__namespace.default.createElement(Container$1i, { "data-testid": "StaticMap" },
24071
24043
  React__namespace.default.createElement(Message$1, null,
24072
24044
  React__namespace.default.createElement("span", null,
24073
24045
  "To interact with the map, you need to ",
24074
24046
  React__namespace.default.createElement(Cookies, { onClick: AcceptCookies }, "accept cookies"),
24075
24047
  ".")),
24076
- React__namespace.default.createElement(MapImage, { src: "https://maps.googleapis.com/maps/api/staticmap?center=".concat(centre, "&size=").concat(size, "&zoom=").concat(zoom, "&maptype=").concat(mapType).concat(markerPath, "&key=").concat(apiKey), alt: imageAltText })));
24048
+ React__namespace.default.createElement(MapImage, { src: mapSrc, alt: imageAltText })));
24077
24049
  };
24078
24050
 
24079
24051
  /**
@@ -35978,23 +35950,150 @@ var ServiceContact = function (_a) {
35978
35950
 
35979
35951
  const Container$4 = styled__default.default.div`
35980
35952
  display: block;
35953
+
35954
+ position: relative;
35955
+ padding-bottom: 56.25%; /* 16:9 */
35956
+ height: 0;
35981
35957
  `;
35982
35958
 
35959
+ var MapMarker = function (_a) {
35960
+ var _b, _c, _d, _e, _f;
35961
+ var advancedMarkerElementOptions = _a.advancedMarkerElementOptions, pinElementOptions = _a.pinElementOptions, infoWindowContent = _a.infoWindowContent, _g = _a.markerIndex, markerIndex = _g === void 0 ? 0 : _g, currentlyOpenInfoWindow = _a.currentlyOpenInfoWindow, setCurrentlyOpenInfowindow = _a.setCurrentlyOpenInfowindow, initiateResetOfAnotherMarker = _a.initiateResetOfAnotherMarker, _h = _a.resetSignal, resetSignal = _h === void 0 ? 0 : _h;
35962
+ // Get a Marker reference to be used to associated this 'AdvancedMarker' to its Infowindow
35963
+ var _j = reactGoogleMaps.useAdvancedMarkerRef(), markerRef = _j[0], marker = _j[1];
35964
+ var _k = React.useState(false), infowindowIsOpen = _k[0], setInfowindowIsOpen = _k[1];
35965
+ var themeContext = React.useContext(styled.ThemeContext);
35966
+ // Monitor for a reset signal (i.e. a request for Infowindow closure) from the parent map...
35967
+ React.useEffect(function () {
35968
+ if (resetSignal == 0)
35969
+ return; // Ignore first initialisation of this component
35970
+ if (!infowindowIsOpen)
35971
+ return; // If the Infowindow is already closed, ignore requests to close it
35972
+ setInfowindowIsOpen(false); // Otherwise, close the Infowindow as instructed by the parent map
35973
+ }, [resetSignal]);
35974
+ // Establish the position in-which this AdvancedMarker is to be located..
35975
+ // using the coordinates of Northampton's Market Square as a default if none are provided
35976
+ var position;
35977
+ // If GPS coordinates have been specified via the 'AdvancedMarkerElementOptions' parameter
35978
+ if (((_b = advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.position) === null || _b === void 0 ? void 0 : _b.lat) &&
35979
+ ((_c = advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.position) === null || _c === void 0 ? void 0 : _c.lng)) {
35980
+ // then use those GPS coordinates...
35981
+ position = advancedMarkerElementOptions.position;
35982
+ }
35983
+ else {
35984
+ return React__namespace.default.createElement(React__namespace.default.Fragment, null);
35985
+ }
35986
+ // Function to handle the Marker being clicked...
35987
+ var handleMarkerClick = function (markerIndex) {
35988
+ // If this marker doesn't currently have its Infowindow open...
35989
+ if (!infowindowIsOpen) {
35990
+ // ... then open its InfoWindow...
35991
+ setInfowindowIsOpen(true);
35992
+ // Then, if another marker has its window open....
35993
+ if (currentlyOpenInfoWindow != -1 && currentlyOpenInfoWindow != markerIndex) {
35994
+ // ...notify the Parent map that that other marker
35995
+ // needs to close its Infowindow...
35996
+ initiateResetOfAnotherMarker(currentlyOpenInfoWindow);
35997
+ }
35998
+ // Finally, notify the parent that this Marker's Infowindow is open...
35999
+ setCurrentlyOpenInfowindow(markerIndex);
36000
+ }
36001
+ else {
36002
+ // Otherwise, if this Marker's InfoWindow IS Open...
36003
+ // ...then close this Marker's Infowindow
36004
+ setInfowindowIsOpen(false);
36005
+ // ... and notify the parent map it has been closed
36006
+ setCurrentlyOpenInfowindow(-1);
36007
+ }
36008
+ };
36009
+ // Function to handle the 'Infowindow' close button being clicked on...
36010
+ var handleInfoWindowCloseClick = function () {
36011
+ // Record the fact that the Infowindow has been closed...
36012
+ setInfowindowIsOpen(false);
36013
+ // and notify the Parent map that the Infowindow has been closed...
36014
+ setCurrentlyOpenInfowindow(-1);
36015
+ };
36016
+ if (!infoWindowContent && (advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.title)) {
36017
+ infoWindowContent = React__namespace.default.createElement("span", null, advancedMarkerElementOptions.title);
36018
+ }
36019
+ // Return, to the Parent component, an appropriately customized Advanced Marker
36020
+ // with an appropriately customised and populated Infowindow
36021
+ return (React__namespace.default.createElement(React__namespace.default.Fragment, { key: markerIndex },
36022
+ React__namespace.default.createElement(reactGoogleMaps.AdvancedMarker, __assign({ ref: markerRef, position: position, clickable: true }, advancedMarkerElementOptions, { title: (advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.title) || '', anchorLeft: (_d = advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.anchorLeft) !== null && _d !== void 0 ? _d : undefined, anchorTop: (_e = advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.anchorTop) !== null && _e !== void 0 ? _e : undefined, collisionBehavior: (_f = advancedMarkerElementOptions === null || advancedMarkerElementOptions === void 0 ? void 0 : advancedMarkerElementOptions.collisionBehavior) !== null && _f !== void 0 ? _f : undefined, onClick: function () { return handleMarkerClick(markerIndex); } }),
36023
+ React__namespace.default.createElement(reactGoogleMaps.Pin, __assign({}, __assign({ glyphColor: themeContext.theme_vars.colours.white, background: themeContext.theme_vars.colours.action_dark, borderColor: themeContext.theme_vars.colours.black }, pinElementOptions)))),
36024
+ React.isValidElement(infoWindowContent) && infowindowIsOpen && marker && (React__namespace.default.createElement(reactGoogleMaps.InfoWindow, { anchor: marker, onCloseClick: function () {
36025
+ handleInfoWindowCloseClick();
36026
+ } }, infoWindowContent))));
36027
+ };
36028
+
35983
36029
  var DirectoryMap = function (_a) {
35984
- var _b, _c;
36030
+ var _b, _c, _d, _e;
35985
36031
  var allowCookies = _a.allowCookies, mapProps = _a.mapProps;
36032
+ // Determine if Cookies have been accepted (so that, if not, a Static Map can be displayed)
35986
36033
  var cookiesAccepted = wereCookiesAccepted(allowCookies);
36034
+ // Obtain Our Google Maps API Key
35987
36035
  var apiKey = (_b = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY) !== null && _b !== void 0 ? _b : '';
35988
- var latLong = mapProps.centre.split(',');
35989
- var center = {
35990
- lat: parseFloat(latLong[0]),
35991
- lng: parseFloat(latLong[1]),
36036
+ // Get a handle to the current theme context, so that we can style the Map Markers appropriately
36037
+ var themeContext = React.useContext(styled.ThemeContext);
36038
+ // Prepare to record which Marker on the map currently has its Infowindow open (and change as necessary)
36039
+ var _f = React.useState(-1), currentlyOpenInfoWindow = _f[0], setCurrentlyOpenInfowindow = _f[1];
36040
+ // Establish an array of Reset 'Signals' so that only one Marker can have its Infowindow open at once
36041
+ var _g = React.useState(), signals = _g[0], setSignals = _g[1];
36042
+ // Determine which 'Map Markers' are "renderable", by filtering out values that don't have valid GPS coordinates
36043
+ var mapMarkersThatAreRenderable = React.useMemo(function () { var _a; return ((_a = mapProps === null || mapProps === void 0 ? void 0 : mapProps.mapMarkers) !== null && _a !== void 0 ? _a : []).filter(function (mapMarkers) { return isValidLatLng(mapMarkers.lat, mapMarkers.lng); }); }, [mapProps]);
36044
+ // Monitor for a reset signal (i.e. a request for Infowindow closure) from the parent map...
36045
+ React.useEffect(function () {
36046
+ // Create a new appropriately-sized copy of the 'reset signals' array and fill it with zeroes...
36047
+ setSignals(function () { return Array(mapMarkersThatAreRenderable.length).fill(0); });
36048
+ }, [mapProps, mapMarkersThatAreRenderable]);
36049
+ // Grab and parse the GPS Coordinates of the mapProps to deduce this Map's centre...
36050
+ // using the coordinates of Northampton's Market Square as a default if none are provided
36051
+ var center = { lat: 52.23555414368587, lng: -0.8957390701320571 };
36052
+ var latLong = ((_c = mapProps.centre) !== null && _c !== void 0 ? _c : '').split(',');
36053
+ if (isValidLatLng(latLong[0], latLong[1])) {
36054
+ center = { lat: parseFloat(latLong[0]), lng: parseFloat(latLong[1]) };
36055
+ }
36056
+ // Fit in all available space, and maintain a 16:9 aspect ratio.
36057
+ var style = { position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' };
36058
+ // Define a Function to allow Markers (or sets of Markers) to close other Marker's Infowindows on the same map...
36059
+ var initiateResetOfAnotherMarker = function (markerIndex) {
36060
+ if (markerIndex == -1)
36061
+ return; // Ignore nonsensical requests
36062
+ if (!signals || signals.length == 0)
36063
+ return; // Ignore first initialisation of the 'signals' array
36064
+ // Duplicate the 'signals' array...
36065
+ var duplicateArray = signals.slice();
36066
+ // Accumulate the counter for the specific Marker that needs to close its Infowindow
36067
+ duplicateArray[markerIndex]++;
36068
+ // Replace the signals array with the duplicate one just created...
36069
+ setSignals(duplicateArray);
35992
36070
  };
35993
- return (React__namespace.default.createElement(Container$4, { "data-testid": "DirectoryMap" }, cookiesAccepted ? (React__namespace.default.createElement(React__namespace.default.Fragment, null,
35994
- React__namespace.default.createElement(reactWrapper.Wrapper, { apiKey: apiKey },
35995
- React__namespace.default.createElement(Map$1, { center: center, zoom: (_c = mapProps.zoom) !== null && _c !== void 0 ? _c : 14 }, mapProps.mapMarkers.map(function (marker, index) {
35996
- var _a;
35997
- return (React__namespace.default.createElement(MapMarker, { position: { lat: marker.lat, lng: marker.lng }, label: marker.label, title: (_a = marker.title) !== null && _a !== void 0 ? _a : '', key: index }));
36071
+ // Define a Function to manage what happens to InfoWindows when the Map is clicked on...
36072
+ var handleMapClick = function () {
36073
+ if (currentlyOpenInfoWindow == -1)
36074
+ return; // Nothing to do if no Infowindows are open..
36075
+ if (!signals || signals.length == 0)
36076
+ return; // Ignore first initialisation of this map's 'signals' array
36077
+ // Duplicate the 'signals' array...
36078
+ var duplicateArray = signals.slice();
36079
+ // Accumulate the counter for the Marker that needs to close its Infowindow
36080
+ duplicateArray[currentlyOpenInfoWindow]++;
36081
+ // Replace the signals array with the duplicated that was just created...
36082
+ setSignals(duplicateArray);
36083
+ // Reset the currently open in this Directory Map's infowindow tracker
36084
+ setCurrentlyOpenInfowindow(-1);
36085
+ };
36086
+ return (React__namespace.default.createElement(Container$4, { "data-testid": "DirectoryMap" }, cookiesAccepted ? (React__namespace.default.createElement(reactGoogleMaps.APIProvider, { apiKey: apiKey },
36087
+ React__namespace.default.createElement(reactGoogleMaps.Map, { defaultCenter: center, defaultZoom: (_d = mapProps.zoom) !== null && _d !== void 0 ? _d : 14, mapId: 'DEMO_MAP_ID', gestureHandling: "greedy", style: style, onClick: function () { return handleMapClick(); } }, ((_e = signals === null || signals === void 0 ? void 0 : signals.length) !== null && _e !== void 0 ? _e : 0) >= 1 &&
36088
+ (mapMarkersThatAreRenderable === null || mapMarkersThatAreRenderable === void 0 ? void 0 : mapMarkersThatAreRenderable.map(function (marker, markerIndex) {
36089
+ var _a, _b;
36090
+ return (React__namespace.default.createElement(MapMarker, { key: markerIndex, advancedMarkerElementOptions: {
36091
+ position: { lat: marker.lat, lng: marker.lng },
36092
+ title: (_a = marker.title) !== null && _a !== void 0 ? _a : '',
36093
+ }, pinElementOptions: {
36094
+ glyphText: marker.label,
36095
+ glyphColor: themeContext.theme_vars.colours.white,
36096
+ }, infoWindowContent: marker.infoWindowContent ? marker.infoWindowContent : undefined, markerIndex: markerIndex, currentlyOpenInfoWindow: currentlyOpenInfoWindow, setCurrentlyOpenInfowindow: setCurrentlyOpenInfowindow, resetSignal: (_b = signals === null || signals === void 0 ? void 0 : signals[markerIndex]) !== null && _b !== void 0 ? _b : 0, initiateResetOfAnotherMarker: initiateResetOfAnotherMarker }));
35998
36097
  }))))) : (React__namespace.default.createElement(StaticMap, __assign({}, mapProps)))));
35999
36098
  };
36000
36099
 
@@ -36161,15 +36260,20 @@ var getIcon = function (profile) {
36161
36260
  };
36162
36261
 
36163
36262
  var DirectoryService = function (_a) {
36164
- var _b, _c, _d, _e;
36165
- var id = _a.id, name = _a.name, accreditations = _a.accreditations, _f = _a.ageInMonths, ageInMonths = _f === void 0 ? false : _f, description = _a.description, descriptionElement = _a.descriptionElement, eligibilitys = _a.eligibilitys, email = _a.email, fees = _a.fees, languages = _a.languages, organization = _a.organization, regular_schedules = _a.regular_schedules, contacts = _a.contacts, service_areas = _a.service_areas, service_at_locations = _a.service_at_locations, service_social_profiles = _a.service_social_profiles, service_taxonomys = _a.service_taxonomys, taxonomiesToShow = _a.taxonomiesToShow, url = _a.url, uploads = _a.uploads, shortListPath = _a.shortListPath;
36166
- var labelLetters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'];
36167
- var _g = React.useState(false), notServer = _g[0], setNotServer = _g[1];
36263
+ var _b, _c;
36264
+ var id = _a.id, name = _a.name, accreditations = _a.accreditations, _d = _a.ageInMonths, ageInMonths = _d === void 0 ? false : _d, description = _a.description, descriptionElement = _a.descriptionElement, eligibilitys = _a.eligibilitys, email = _a.email, fees = _a.fees, languages = _a.languages, organization = _a.organization, regular_schedules = _a.regular_schedules, contacts = _a.contacts, service_areas = _a.service_areas, service_at_locations = _a.service_at_locations, service_social_profiles = _a.service_social_profiles, service_taxonomys = _a.service_taxonomys, taxonomiesToShow = _a.taxonomiesToShow, url = _a.url, uploads = _a.uploads, shortListPath = _a.shortListPath;
36265
+ var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
36266
+ var labelLetters = letters.split('');
36267
+ var _e = React.useState(false), notServer = _e[0], setNotServer = _e[1];
36168
36268
  var themeContext = React.useContext(styled.ThemeContext);
36169
36269
  var favourites = useDirectoryShortListContext().favourites.favourites;
36170
36270
  React.useEffect(function () {
36171
36271
  setNotServer(true);
36172
36272
  }, []);
36273
+ // The visitable, geocoded locations for this service. Each becomes its own
36274
+ // map pin, all sharing the same `directoryServiceProps`, so a multi-location
36275
+ // service shows every location without duplicating the service data.
36276
+ var mapLocations = (service_at_locations !== null && service_at_locations !== void 0 ? service_at_locations : []).filter(function (location) { return location.is_visitable != false && isValidLatLng(location.latitude, location.longitude); });
36173
36277
  return (React__namespace.default.createElement(Container$6, { "data-testid": "DirectoryService" },
36174
36278
  React__namespace.default.createElement(Row$1, null,
36175
36279
  React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "full" },
@@ -36186,7 +36290,7 @@ var DirectoryService = function (_a) {
36186
36290
  " Shortlist (",
36187
36291
  favourites.length,
36188
36292
  ")")),
36189
- React__namespace.default.createElement(DirectoryAddToShortList, { id: id, name: name, snippet: transformSnippet(description, 350), email: email, website: url, phone: (_c = (_b = contacts === null || contacts === void 0 ? void 0 : contacts[0]) === null || _b === void 0 ? void 0 : _b.phones) === null || _c === void 0 ? void 0 : _c.flatMap(function (phone) { return phone.number; }).join(', '), addresses: service_at_locations.flatMap(function (location) {
36293
+ React__namespace.default.createElement(DirectoryAddToShortList, { id: id, name: name, snippet: transformSnippet(description, 350), email: email, website: url, phone: (_c = (_b = contacts === null || contacts === void 0 ? void 0 : contacts[0]) === null || _b === void 0 ? void 0 : _b.phones) === null || _c === void 0 ? void 0 : _c.flatMap(function (phone) { return phone.number; }).join(', '), addresses: service_at_locations === null || service_at_locations === void 0 ? void 0 : service_at_locations.flatMap(function (location) {
36190
36294
  return location.physical_addresses;
36191
36295
  }), fees: fees })))))),
36192
36296
  service_at_locations.filter(function (location) {
@@ -36207,21 +36311,15 @@ var DirectoryService = function (_a) {
36207
36311
  (location === null || location === void 0 ? void 0 : location.accessibility_for_disabilities.length) > 0 && (React__namespace.default.createElement(React__namespace.default.Fragment, null,
36208
36312
  React__namespace.default.createElement(Heading$1, { level: 3, text: "Other facilities on site" }),
36209
36313
  React__namespace.default.createElement("ul", null, location.accessibility_for_disabilities.map(function (accessibility) { return (React__namespace.default.createElement("li", { key: accessibility.id }, accessibility.accessibility)); })))))); })),
36210
- React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "two-thirds" }, service_at_locations.filter(function (location) {
36211
- return location.is_visitable != false;
36212
- }).length > 0 &&
36213
- ((_d = service_at_locations[0]) === null || _d === void 0 ? void 0 : _d.latitude) &&
36214
- ((_e = service_at_locations[0]) === null || _e === void 0 ? void 0 : _e.longitude) && (React__namespace.default.createElement(React__namespace.default.Fragment, null,
36314
+ React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "two-thirds" }, mapLocations.length > 0 && (React__namespace.default.createElement(React__namespace.default.Fragment, null,
36215
36315
  notServer && (React__namespace.default.createElement(DirectoryMap, { mapProps: {
36216
- centre: "".concat(service_at_locations[0].latitude, ",").concat(service_at_locations[0].longitude),
36217
- imageAltText: "".concat(service_at_locations[0].name, " shown on a map"),
36316
+ centre: "".concat(mapLocations[0].latitude, ",").concat(mapLocations[0].longitude),
36317
+ imageAltText: "".concat(mapLocations[0].name, " shown on a map"),
36218
36318
  zoom: 14,
36219
36319
  size: '640x320',
36220
36320
  mapMarkers: service_at_locations
36221
36321
  .filter(function (location) {
36222
- return (location.latitude != null &&
36223
- location.longitude != null &&
36224
- location.is_visitable != false);
36322
+ return (isValidLatLng(location.latitude, location.longitude) && location.is_visitable != false);
36225
36323
  })
36226
36324
  .map(function (location, locationIndex) {
36227
36325
  return {
@@ -36229,10 +36327,12 @@ var DirectoryService = function (_a) {
36229
36327
  lng: parseFloat(location.longitude),
36230
36328
  label: labelLetters[locationIndex],
36231
36329
  title: location.name,
36330
+ infoWindowContent: (React__namespace.default.createElement("span", null,
36331
+ React__namespace.default.createElement("strong", null, name !== null && name !== void 0 ? name : ''))),
36232
36332
  };
36233
36333
  }),
36234
36334
  } })),
36235
- React__namespace.default.createElement(MapLink, { href: "https://www.google.com/maps/search/?api=1&query=".concat(service_at_locations[0].latitude, "%2C").concat(service_at_locations[0].longitude) }, "View in Google Maps"))))))),
36335
+ React__namespace.default.createElement(MapLink, { href: "https://www.google.com/maps/search/?api=1&query=".concat(mapLocations[0].latitude, "%2C").concat(mapLocations[0].longitude) }, "View in Google Maps"))))))),
36236
36336
  (email || url || (contacts === null || contacts === void 0 ? void 0 : contacts.length) > 0) && (React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "full", classes: "striped-column" },
36237
36337
  React__namespace.default.createElement(Heading$1, { level: 2, text: "How to contact this service" }),
36238
36338
  React__namespace.default.createElement(ServiceContact, { email: email, website: url, contacts: contacts }))),
@@ -36749,19 +36849,26 @@ var DirectoryServiceList = function (_a) {
36749
36849
  zoom: mapZoom,
36750
36850
  size: '640x320',
36751
36851
  imageAltText: 'Directory search results displayed on a map',
36752
- mapMarkers: services
36753
- .filter(function (service) {
36754
- var _a;
36755
- return ((_a = service.service_at_locations[0]) === null || _a === void 0 ? void 0 : _a.is_visitable) != false;
36756
- })
36757
- .map(function (service, index) {
36758
- var _a, _b;
36759
- return {
36760
- lat: parseFloat((_a = service.service_at_locations[0]) === null || _a === void 0 ? void 0 : _a.latitude),
36761
- lng: parseFloat((_b = service.service_at_locations[0]) === null || _b === void 0 ? void 0 : _b.longitude),
36762
- label: labelLetters[index],
36763
- title: "<a href=\"".concat(directoryPath, "/").concat(service.id, "\">").concat(service.name, "</a>"),
36764
- };
36852
+ mapMarkers: services.flatMap(function (service, index) {
36853
+ var _a, _b, _c;
36854
+ if (service.service_at_locations &&
36855
+ service.service_at_locations[0] &&
36856
+ service.service_at_locations[0].latitude &&
36857
+ service.service_at_locations[0].longitude &&
36858
+ ((_a = service.service_at_locations[0]) === null || _a === void 0 ? void 0 : _a.is_visitable) != false) {
36859
+ return [
36860
+ {
36861
+ lat: parseFloat((_b = service.service_at_locations[0]) === null || _b === void 0 ? void 0 : _b.latitude),
36862
+ lng: parseFloat((_c = service.service_at_locations[0]) === null || _c === void 0 ? void 0 : _c.longitude),
36863
+ label: labelLetters[index],
36864
+ title: service.name,
36865
+ infoWindowContent: (React__namespace.default.createElement("a", { href: "".concat(directoryPath, "/").concat(service.id) }, service.name)),
36866
+ },
36867
+ ];
36868
+ }
36869
+ else {
36870
+ return [];
36871
+ }
36765
36872
  }),
36766
36873
  };
36767
36874
  var handleAgeChange = function (e, field) {
@@ -36876,7 +36983,7 @@ var DirectoryServiceList = function (_a) {
36876
36983
  ")"))),
36877
36984
  React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "full" },
36878
36985
  React__namespace.default.createElement(Pagination, { currentPage: pageNumber, totalResults: totalResults, resultsPerPage: perPage, postTo: directoryPath, buttonClickOverride: setPageNumber })),
36879
- React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "full" }, notServer && React__namespace.default.createElement(React__namespace.default.Fragment, null, (services === null || services === void 0 ? void 0 : services.length) > 0 && showMap && React__namespace.default.createElement(DirectoryMap, { mapProps: mapProps }))),
36986
+ React__namespace.default.createElement(Column, { small: "full", medium: "full", large: "full" }, notServer && (services === null || services === void 0 ? void 0 : services.length) > 0 && showMap && (React__namespace.default.createElement(DirectoryMap, { mapProps: mapProps }))),
36880
36987
  services.map(function (service, index) {
36881
36988
  var _a, _b, _c, _d, _e, _f, _g;
36882
36989
  var snippet = transformSnippet(service.description, extractLength);
@@ -38893,8 +39000,6 @@ exports.HomeHero = HomeHero;
38893
39000
  exports.Image = Image;
38894
39001
  exports.ImageAndText = ImageAndText;
38895
39002
  exports.InquestSchedule = InquestSchedule;
38896
- exports.Map = Map$1;
38897
- exports.MapMarker = MapMarker;
38898
39003
  exports.MaxWidthContainer = MaxWidthContainer;
38899
39004
  exports.MemorialHero = MemorialHero;
38900
39005
  exports.NewsArticleDate = NewsArticleDate;