@defra/interactive-map 0.0.53-alpha → 0.0.55-alpha

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 (199) hide show
  1. package/assets/templates/add-polygons.njk +1 -1
  2. package/assets/templates/add-symbols.njk +4 -4
  3. package/assets/templates/draw-tools.njk +7 -7
  4. package/assets/templates/marker-panel.njk +5 -5
  5. package/assets/templates/place-marker.njk +8 -8
  6. package/assets/templates/search-control.njk +1 -1
  7. package/assets/templates/select-feature.njk +7 -7
  8. package/assets/templates/style-switcher.njk +4 -4
  9. package/assets/templates/toggle-marker-label.njk +3 -3
  10. package/dist/css/index.css +1 -1
  11. package/dist/esm/im-core.js +1 -1
  12. package/dist/esm/im-shell.js +1 -1
  13. package/dist/esm/index.js +1 -1
  14. package/dist/umd/im-core.js +1 -1
  15. package/dist/umd/im-core.js.LICENSE.txt +0 -30
  16. package/dist/umd/index.js +1 -1
  17. package/dist/umd/index.js.LICENSE.txt +0 -20
  18. package/docs/api/context.md +12 -0
  19. package/docs/api.md +14 -16
  20. package/docs/building-a-plugin.md +2 -2
  21. package/docs/examples/add-marker-with-panel.mdx +46 -44
  22. package/docs/examples/add-polygons.mdx +100 -98
  23. package/docs/examples/add-symbols.mdx +75 -73
  24. package/docs/examples/basic-map.mdx +16 -14
  25. package/docs/examples/button-map.mdx +16 -14
  26. package/docs/examples/draw-tools.mdx +119 -117
  27. package/docs/examples/place-marker.mdx +51 -49
  28. package/docs/examples/search-control.mdx +22 -20
  29. package/docs/examples/select-feature.mdx +107 -105
  30. package/docs/examples/style-switcher.mdx +47 -45
  31. package/docs/examples/toggle-marker-label.mdx +30 -28
  32. package/docs/getting-started.md +26 -24
  33. package/docs/plugins/datasets.md +2 -0
  34. package/docs/plugins/draw.md +10 -10
  35. package/docs/plugins/interact.md +9 -9
  36. package/docs/plugins/map-key.md +41 -0
  37. package/docs/plugins/plugin-descriptor.md +1 -1
  38. package/docs/plugins/search.md +3 -3
  39. package/docusaurus.config.cjs +23 -0
  40. package/package.json +3 -7
  41. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  42. package/plugins/beta/draw-es/dist/esm/index.js +1 -1
  43. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  44. package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
  45. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  46. package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
  47. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  48. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  49. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
  50. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  51. package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
  52. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
  53. package/plugins/beta/frame/dist/esm/index.js +1 -1
  54. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
  55. package/plugins/beta/frame/dist/umd/index.js +1 -1
  56. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  57. package/plugins/beta/map-styles/dist/esm/index.js +1 -1
  58. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  59. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  60. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
  61. package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
  62. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
  63. package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
  64. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  65. package/plugins/beta/use-location/dist/esm/index.js +1 -1
  66. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  67. package/plugins/beta/use-location/dist/umd/index.js +1 -1
  68. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  69. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  70. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  71. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  72. package/plugins/datasets/dist/esm/index.js +1 -1
  73. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  74. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  75. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  76. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  77. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  78. package/plugins/datasets/dist/umd/index.js +1 -1
  79. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
  80. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  81. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
  82. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
  83. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  84. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
  85. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
  86. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
  87. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
  88. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
  89. package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
  90. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  91. package/plugins/datasets/src/initialise/defaults.js +12 -24
  92. package/plugins/datasets/src/initialise/defaults.test.js +25 -57
  93. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
  94. package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
  95. package/plugins/datasets/src/registry/dataset.js +21 -16
  96. package/plugins/datasets/src/registry/dataset.test.js +101 -11
  97. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  98. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  99. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  100. package/plugins/draw/dist/esm/index.js +1 -1
  101. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  102. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  103. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  104. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  105. package/plugins/draw/dist/umd/index.js +1 -1
  106. package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
  107. package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
  108. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  109. package/plugins/interact/dist/esm/index.js +1 -1
  110. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  111. package/plugins/interact/dist/umd/index.js +1 -1
  112. package/plugins/map-key/dist/css/index.css +1 -1
  113. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  114. package/plugins/map-key/dist/esm/index.js +1 -1
  115. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  116. package/plugins/map-key/dist/umd/index.js +1 -1
  117. package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
  118. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
  119. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
  120. package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
  121. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
  122. package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
  123. package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
  124. package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
  125. package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
  126. package/plugins/map-key/src/index.js +34 -0
  127. package/plugins/map-key/src/utils/groupStyles.js +5 -2
  128. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
  129. package/plugins/menu/dist/esm/index.js +1 -1
  130. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
  131. package/plugins/menu/dist/umd/index.js +1 -1
  132. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  133. package/plugins/search/dist/esm/index.js +1 -1
  134. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  135. package/plugins/search/dist/umd/index.js +1 -1
  136. package/plugins/search/src/Search.jsx +0 -1
  137. package/plugins/search/src/components/Form/Form.jsx +3 -3
  138. package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
  139. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
  140. package/plugins/search/src/defaults.js +3 -0
  141. package/plugins/search/src/events/formHandlers.js +3 -9
  142. package/plugins/search/src/events/formHandlers.test.js +6 -9
  143. package/plugins/search/src/events/inputHandlers.js +8 -2
  144. package/plugins/search/src/events/inputHandlers.test.js +20 -0
  145. package/plugins/search/src/events/suggestionHandlers.js +3 -5
  146. package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
  147. package/plugins/search/src/utils/showResult.js +9 -0
  148. package/plugins/search/src/utils/showResult.test.js +16 -0
  149. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  150. package/providers/beta/esri/dist/esm/index.js +1 -1
  151. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
  152. package/providers/beta/open-names/dist/esm/index.js +1 -1
  153. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
  154. package/providers/beta/open-names/dist/umd/index.js +1 -1
  155. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  156. package/providers/beta/openlayers/dist/esm/index.js +1 -1
  157. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  158. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  159. package/providers/beta/openlayers/src/index.js +27 -4
  160. package/providers/beta/openlayers/src/index.test.js +47 -0
  161. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  162. package/providers/maplibre/dist/esm/index.js +1 -1
  163. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  164. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
  165. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  166. package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
  167. package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
  168. package/providers/maplibre/dist/umd/index.js +1 -1
  169. package/providers/maplibre/src/index.js +41 -12
  170. package/providers/maplibre/src/index.test.js +43 -12
  171. package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
  172. package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
  173. package/providers/maplibre/src/utils/spatial.js +22 -12
  174. package/providers/maplibre/src/utils/spatial.test.js +6 -6
  175. package/providers/maplibre/src/utils/workerUrl.js +15 -0
  176. package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
  177. package/rollup.esm.mjs +38 -1
  178. package/src/App/components/Hints/Hints.module.scss +1 -1
  179. package/src/App/components/Viewport/Viewport.jsx +6 -4
  180. package/src/App/components/Viewport/Viewport.test.jsx +18 -1
  181. package/src/App/hooks/useMapAnnouncements.js +7 -2
  182. package/src/App/hooks/useMapAnnouncements.test.js +13 -2
  183. package/src/App/hooks/useModalPanelBehaviour.js +3 -1
  184. package/src/App/initialiseApp.js +1 -1
  185. package/src/App/store/ServiceProvider.jsx +7 -1
  186. package/src/App/store/ServiceProvider.test.jsx +15 -0
  187. package/src/InteractiveMap/InteractiveMap.js +5 -4
  188. package/src/InteractiveMap/InteractiveMap.test.js +9 -2
  189. package/src/InteractiveMap/domStateManager.js +21 -1
  190. package/src/InteractiveMap/domStateManager.test.js +48 -1
  191. package/src/InteractiveMap/polyfills.js +4 -3
  192. package/src/InteractiveMap/polyfills.test.js +12 -0
  193. package/src/services/mapFocus.js +64 -0
  194. package/src/services/mapFocus.test.js +76 -0
  195. package/src/types.js +5 -7
  196. package/src/utils/detectInterfaceType.js +16 -5
  197. package/src/utils/detectInterfaceType.test.js +32 -0
  198. package/webpack.dev.mjs +2 -0
  199. package/webpack.umd.mjs +28 -7
@@ -22,14 +22,15 @@ const setup = (overrides = {}) => {
22
22
  }
23
23
 
24
24
  useConfig.mockReturnValue({ mapProvider, ...overrides.config })
25
- useService.mockReturnValue({ announce, eventBus, ...overrides.service })
25
+ const mapFocus = { isHoldingAnnouncements: jest.fn(() => false) }
26
+ useService.mockReturnValue({ announce, eventBus, mapFocus, ...overrides.service })
26
27
 
27
28
  getMapStatusMessage.moved = jest.fn(() => 'Moved north')
28
29
  getMapStatusMessage.zoomed = jest.fn(() => 'Zoomed in')
29
30
  getMapStatusMessage.noChange = jest.fn(() => 'No change')
30
31
  getMapStatusMessage.newArea = jest.fn(() => 'New area')
31
32
 
32
- return { announce, mapProvider, eventBus }
33
+ return { announce, mapProvider, eventBus, mapFocus }
33
34
  }
34
35
 
35
36
  describe('useMapAnnouncements', () => {
@@ -50,6 +51,16 @@ describe('useMapAnnouncements', () => {
50
51
  expect(eventBus.off).toHaveBeenCalledWith('map:stateupdated', expect.any(Function))
51
52
  })
52
53
 
54
+ test('does not announce while a map focus message is holding announcements', () => {
55
+ const { announce, eventBus, mapFocus } = setup()
56
+ mapFocus.isHoldingAnnouncements.mockReturnValue(true)
57
+ renderHook(() => useMapAnnouncements())
58
+ const handler = eventBus.on.mock.calls[0][1]
59
+
60
+ handler({ previous: { center: [0, 0], zoom: 1 }, current: { center: [1, 1], zoom: 2 } })
61
+ expect(announce).not.toHaveBeenCalled()
62
+ })
63
+
53
64
  test('early returns when previous or current center is missing', () => {
54
65
  const { announce, eventBus } = setup()
55
66
  renderHook(() => useMapAnnouncements())
@@ -200,7 +200,9 @@ export function useModalPanelBehaviour ({
200
200
  }, [isModal, rootEl, handleClose])
201
201
 
202
202
  // === Inert everything outside the panel but within the app === //
203
- useEffect(() => {
203
+ // Layout effect so the cleanup restores aria-hidden at commit, before handleClose's
204
+ // requestAnimationFrame returns focus to the trigger (which sits inside an inerted branch).
205
+ useLayoutEffect(() => {
204
206
  if (!isModal || !panelRef.current || !rootEl) {
205
207
  return undefined
206
208
  }
@@ -38,7 +38,7 @@ const getOrCreateRegistries = (rootElement, eventBus) => {
38
38
  const loadPlugins = async (plugins, registerPlugin) => {
39
39
  for (const plugin of plugins) {
40
40
  if (typeof plugin.load === 'function') {
41
- const module = await plugin.load()
41
+ const module = await plugin.load() // NOSONAR: Await inside a for loop is fine, parent function is async
42
42
  const { id: pluginId, load, manifest: overrideManifest, ...config } = plugin
43
43
  const { InitComponent, api, reducer, ...baseManifest } = module
44
44
 
@@ -2,8 +2,10 @@
2
2
  import React, { createContext, useMemo, useRef } from 'react'
3
3
  import { createAnnouncer } from '../../services/announcer.js'
4
4
  import { createHints } from '../../services/hints.js'
5
+ import { createMapFocus } from '../../services/mapFocus.js'
5
6
  import { reverseGeocode } from '../../services/reverseGeocode.js'
6
7
  import { useConfig } from '../store/configContext.js'
8
+ import { useApp } from '../store/appContext.js'
7
9
  import { closeApp } from '../../services/closeApp.js'
8
10
  import { createSymbolRegistry } from '../../services/symbolRegistry.js'
9
11
  import { createPatternRegistry } from '../../services/patternRegistry.js'
@@ -15,6 +17,8 @@ export const ServiceProvider = ({ eventBus, pluginRegistry, children }) => {
15
17
  const mapStatusRef = useRef(null)
16
18
  const announce = useMemo(() => createAnnouncer(mapStatusRef), [])
17
19
  const hints = useMemo(() => createHints(announce), [announce])
20
+ const { layoutRefs } = useApp()
21
+ const mapFocus = useMemo(() => createMapFocus({ viewportRef: layoutRefs.viewportRef }), [])
18
22
  // One of each per map, so maps on the same page keep their own symbols, symbolDefaults and patterns
19
23
  const symbolRegistry = useMemo(() => createSymbolRegistry(), [])
20
24
  const patternRegistry = useMemo(() => createPatternRegistry(), [])
@@ -27,12 +31,14 @@ export const ServiceProvider = ({ eventBus, pluginRegistry, children }) => {
27
31
  reverseGeocode: (zoom, center) => reverseGeocode(zoom, center),
28
32
  eventBus,
29
33
  mapStatusRef,
34
+ focusMap: mapFocus.focus,
35
+ mapFocus,
30
36
  closeApp: () => closeApp(id, handleExitClick, eventBus),
31
37
  symbolRegistry,
32
38
  patternRegistry,
33
39
  // See pluginRegistry.js's getPlugin() for what this does and doesn't guarantee.
34
40
  getPlugin: (pluginId) => pluginRegistry?.getPlugin(pluginId)
35
- }), [announce, hints, pluginRegistry, symbolRegistry, patternRegistry])
41
+ }), [announce, hints, mapFocus, pluginRegistry, symbolRegistry, patternRegistry])
36
42
 
37
43
  return (
38
44
  <ServiceContext.Provider value={services}>
@@ -24,6 +24,11 @@ jest.mock('../../services/closeApp.js', () => ({
24
24
  closeApp: jest.fn()
25
25
  }))
26
26
 
27
+ const mockViewportRef = { current: { focus: jest.fn(), getAttribute: jest.fn(), setAttribute: jest.fn() } }
28
+ jest.mock('../store/appContext.js', () => ({
29
+ useApp: jest.fn(() => ({ layoutRefs: { viewportRef: mockViewportRef } }))
30
+ }))
31
+
27
32
  // Mock config values including id + handleExitClick
28
33
  jest.mock('../store/configContext.js', () => ({
29
34
  useConfig: jest.fn(() => ({
@@ -56,6 +61,16 @@ describe('ServiceProvider', () => {
56
61
  expect(result.current.mapStatusRef.current).toBeNull()
57
62
  })
58
63
 
64
+ test('focusMap names and focuses the viewport from layoutRefs', () => {
65
+ const { result } = renderHook(() => React.useContext(ServiceContext), { wrapper })
66
+
67
+ result.current.focusMap({ message: 'Map moved to Carlisle' })
68
+
69
+ expect(mockViewportRef.current.setAttribute).toHaveBeenCalledWith('aria-label', 'Map moved to Carlisle')
70
+ expect(mockViewportRef.current.focus).toHaveBeenCalled()
71
+ expect(result.current.mapFocus.isHoldingAnnouncements()).toBe(true)
72
+ })
73
+
59
74
  test('gives each map its own symbol registry, kept across renders, with that map\'s symbolDefaults', () => {
60
75
  const { useConfig } = jest.requireMock('../store/configContext.js')
61
76
  useConfig.mockReturnValue({ id: 'map-a', symbolDefaults: { backgroundColor: '#111111' } })
@@ -15,7 +15,7 @@ import { parseDataProperties } from './parseDataProperties.js'
15
15
  import { checkDeviceSupport } from './deviceChecker.js'
16
16
  import { createButton } from './buttonManager.js'
17
17
  import { setupBehavior, shouldLoadComponent } from './behaviourController.js'
18
- import { updateDOMState, removeLoadingState } from './domStateManager.js'
18
+ import { updateDOMState, removeLoadingState, showPageIfMapInline } from './domStateManager.js'
19
19
  import { renderError } from './renderError.js'
20
20
  import { mergeConfig } from '../config/mergeConfig.js'
21
21
  import { createBreakpointDetector } from '../utils/detectBreakpoint.js'
@@ -99,7 +99,8 @@ export default class InteractiveMap {
99
99
  this._hybridBehaviourCleanup = setupBehavior(this)
100
100
 
101
101
  if (shouldLoadComponent(this.config)) {
102
- this.loadApp()
102
+ showPageIfMapInline(this)
103
+ this.loadApp() // NOSONAR: Not changing for now as used in production
103
104
  } else {
104
105
  removeLoadingState()
105
106
  }
@@ -120,7 +121,7 @@ export default class InteractiveMap {
120
121
  history.pushState({ isBack: true }, '', e.currentTarget.getAttribute('href'))
121
122
  }
122
123
  // Only a genuine launcher click moves focus into the map — never a resize/breakpoint transition.
123
- this.loadApp({ focusOnMount: true })
124
+ this.loadApp({ focusOnMount: true }) // NOSONAR: Not changing for now as used in production
124
125
  }
125
126
  }
126
127
 
@@ -564,7 +565,7 @@ export default class InteractiveMap {
564
565
  } else if (this._root) {
565
566
  // App is already open — no-op
566
567
  } else {
567
- this.loadApp()
568
+ this.loadApp() // NOSONAR: Not changing for now as used in production
568
569
  }
569
570
  }
570
571
 
@@ -7,7 +7,7 @@ import historyManager from './historyManager.js'
7
7
  import { parseDataProperties } from './parseDataProperties.js'
8
8
  import { checkDeviceSupport } from './deviceChecker.js'
9
9
  import { setupBehavior, shouldLoadComponent } from './behaviourController.js'
10
- import { updateDOMState, removeLoadingState } from './domStateManager.js'
10
+ import { updateDOMState, removeLoadingState, showPageIfMapInline } from './domStateManager.js'
11
11
  import { renderError } from './renderError.js'
12
12
  import { createBreakpointDetector } from '../utils/detectBreakpoint.js'
13
13
  import { createInterfaceDetector } from '../utils/detectInterfaceType.js'
@@ -23,7 +23,7 @@ jest.mock('./behaviourController.js', () => ({
23
23
  setupBehavior: jest.fn(),
24
24
  shouldLoadComponent: jest.fn(() => true)
25
25
  }))
26
- jest.mock('./domStateManager.js', () => ({ updateDOMState: jest.fn().mockReturnValue({ isFullscreen: false }), removeLoadingState: jest.fn() }))
26
+ jest.mock('./domStateManager.js', () => ({ updateDOMState: jest.fn().mockReturnValue({ isFullscreen: false }), removeLoadingState: jest.fn(), showPageIfMapInline: jest.fn() }))
27
27
  jest.mock('./renderError.js', () => ({ renderError: jest.fn() }))
28
28
  jest.mock('../config/mergeConfig.js', () => ({ mergeConfig: jest.fn(cfg => cfg) }))
29
29
  const mockBreakpointDetector = {
@@ -146,6 +146,13 @@ describe('InteractiveMap — loadApp', () => {
146
146
  expect(map).toBeDefined()
147
147
  })
148
148
 
149
+ it('shows the page before loading the app when shouldLoadComponent returns true', () => {
150
+ shouldLoadComponent.mockReturnValue(true)
151
+ const map = new InteractiveMap('map', { behaviour: 'inline', mapProvider: mapProviderMock })
152
+ expect(showPageIfMapInline).toHaveBeenCalledWith(map)
153
+ expect(removeLoadingState).not.toHaveBeenCalled()
154
+ })
155
+
149
156
  it('calls removeLoadingState if shouldLoadComponent returns false', () => {
150
157
  shouldLoadComponent.mockReturnValue(false)
151
158
  const map = new InteractiveMap('map', { behaviour: 'buttonFirst', mapProvider: mapProviderMock })
@@ -85,11 +85,31 @@ function removeLoadingState () {
85
85
  document.body.classList.remove('im-is-loading')
86
86
  }
87
87
 
88
+ /**
89
+ * Show the page straight away when the map will render inline.
90
+ *
91
+ * Reserves the map container's height and removes the loading state, so the
92
+ * page's own content can render while the map app loads. When the map will
93
+ * open fullscreen, the loading state stays until the app has rendered, so the
94
+ * page doesn't show through before the map covers it.
95
+ *
96
+ * @param {Object} mapInstance - Map instance containing config and root element.
97
+ * @returns {void}
98
+ */
99
+ function showPageIfMapInline (mapInstance) {
100
+ if (getIsFullscreen(mapInstance.config)) {
101
+ return
102
+ }
103
+ updateDOMState(mapInstance, { isFullscreen: false })
104
+ removeLoadingState()
105
+ }
106
+
88
107
  // -----------------------------------------------------------------------------
89
108
  // Exports
90
109
  // -----------------------------------------------------------------------------
91
110
 
92
111
  export {
93
112
  updateDOMState,
94
- removeLoadingState
113
+ removeLoadingState,
114
+ showPageIfMapInline
95
115
  }
@@ -2,7 +2,7 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
 
5
- import { updateDOMState, removeLoadingState } from './domStateManager.js'
5
+ import { updateDOMState, removeLoadingState, showPageIfMapInline } from './domStateManager.js'
6
6
  import * as queryString from '../utils/queryString.js'
7
7
  import * as toggleInertElements from '../utils/toggleInertElements.js'
8
8
 
@@ -145,3 +145,50 @@ describe('removeLoadingState', () => {
145
145
  expect(document.body.classList.contains('im-is-loading')).toBe(false)
146
146
  })
147
147
  })
148
+
149
+ describe('showPageIfMapInline', () => {
150
+ let rootEl
151
+
152
+ const createMapInstance = (config) => ({
153
+ config: { id: 'map', pageTitle: 'Map View', containerHeight: '500px', hybridWidth: null, maxMobileWidth: 640, ...config },
154
+ rootEl
155
+ })
156
+
157
+ beforeEach(() => {
158
+ rootEl = document.createElement('div')
159
+ document.body.appendChild(rootEl)
160
+ document.body.classList.add('im-is-loading')
161
+ queryString.getQueryParam.mockReturnValue(null)
162
+ window.matchMedia = jest.fn().mockImplementation(() => ({ matches: false }))
163
+ })
164
+
165
+ afterEach(() => {
166
+ document.body.innerHTML = ''
167
+ document.body.classList.remove('im-is-loading')
168
+ })
169
+
170
+ it.each([
171
+ ['inline', {}],
172
+ ['hybrid above hybridWidth', { behaviour: 'hybrid' }]
173
+ ])('shows the page and reserves the container height for %s', (_label, config) => {
174
+ showPageIfMapInline(createMapInstance({ behaviour: 'inline', ...config }))
175
+
176
+ expect(document.body.classList.contains('im-is-loading')).toBe(false)
177
+ expect(rootEl.style.height).toBe('500px')
178
+ expect(document.documentElement.classList.contains('im-is-fullscreen')).toBe(false)
179
+ })
180
+
181
+ it.each([
182
+ ['mapOnly', { behaviour: 'mapOnly' }, null, false],
183
+ ['buttonFirst opened from the URL', { behaviour: 'buttonFirst' }, 'map', false],
184
+ ['hybrid below hybridWidth opened from the URL', { behaviour: 'hybrid' }, 'map', true]
185
+ ])('keeps the page hidden when the map opens fullscreen: %s', (_label, config, viewParam, isNarrow) => {
186
+ queryString.getQueryParam.mockReturnValue(viewParam)
187
+ window.matchMedia = jest.fn().mockImplementation(() => ({ matches: isNarrow }))
188
+
189
+ showPageIfMapInline(createMapInstance(config))
190
+
191
+ expect(document.body.classList.contains('im-is-loading')).toBe(true)
192
+ expect(rootEl.style.height).toBe('')
193
+ })
194
+ })
@@ -33,8 +33,8 @@ if (needsThrowIfAborted) {
33
33
 
34
34
  // Inject polyfills into web workers — workers have their own global scope so
35
35
  // main thread polyfills don't apply. Two cases:
36
- // 1. Blob URL workers (MapLibre default): intercept URL.createObjectURL
37
- // 2. String URL workers (MapLibre workerUrl, used in CSP environments): intercept Worker constructor
36
+ // 1. Blob URL workers (MapLibre, when its worker is cross-origin): intercept URL.createObjectURL
37
+ // 2. String URL classic workers: intercept Worker constructor
38
38
  const needsWorkerPolyfills = (needsThrowIfAborted || needsHasOwn) && typeof URL !== 'undefined' && URL.createObjectURL
39
39
 
40
40
  if (needsWorkerPolyfills) {
@@ -59,7 +59,8 @@ if (needsWorkerPolyfills) {
59
59
  const NativeWorker = Worker
60
60
  // eslint-disable-next-line no-global-assign
61
61
  Worker = function (url, options) {
62
- if (typeof url === 'string' && !url.startsWith('blob:')) {
62
+ // Module workers can't call importScripts, so they are left unwrapped
63
+ if (typeof url === 'string' && !url.startsWith('blob:') && options?.type !== 'module') {
63
64
  const blob = new Blob([`${workerPolyfillCode}importScripts(${JSON.stringify(url)})`], { type: JS_MIME })
64
65
  url = _createObjectURL(blob)
65
66
  }
@@ -147,6 +147,18 @@ describe('Worker constructor (string workerUrl)', () => {
147
147
  expect(MockWorker).toHaveBeenCalledWith('blob:http://localhost/existing', undefined)
148
148
  })
149
149
 
150
+ test('passes module worker URLs through without wrapping', () => {
151
+ const MockWorker = setupWorkerMock()
152
+ const mockCreate = jest.fn(() => 'blob:new')
153
+ URL.createObjectURL = mockCreate
154
+ load()
155
+
156
+ // eslint-disable-next-line no-new
157
+ new Worker('/maplibre-gl-worker.mjs', { type: 'module' }) // NOSONAR
158
+ expect(mockCreate).not.toHaveBeenCalled()
159
+ expect(MockWorker).toHaveBeenCalledWith('/maplibre-gl-worker.mjs', { type: 'module' })
160
+ })
161
+
150
162
  test('preserves the Worker prototype', () => {
151
163
  const MockWorker = setupWorkerMock()
152
164
  const mockProto = { foo: 'bar' }
@@ -0,0 +1,64 @@
1
+ // services/mapFocus.js
2
+
3
+ /**
4
+ * Moves focus to the map viewport, optionally with a message that stands in
5
+ * for the viewport's accessible name. Being the name, the message is spoken
6
+ * reliably and straight away as part of the focus announcement, where a live
7
+ * region update would race the focus change. The original name returns when
8
+ * focus leaves the viewport, so the name never changes while it has focus.
9
+ *
10
+ * A message also holds back map state announcements ("New area
11
+ * approximately...") until the user next presses a key or pointer on the map,
12
+ * since it already describes the move that follows.
13
+ */
14
+ const ARIA_LABEL = 'aria-label'
15
+
16
+ export function createMapFocus ({ viewportRef }) {
17
+ let originalLabel = null
18
+ let hasMessage = false
19
+ let isHoldingAnnouncements = false
20
+
21
+ const focus = ({ message } = {}) => {
22
+ const viewport = viewportRef.current
23
+ if (!viewport) {
24
+ return
25
+ }
26
+ if (message) {
27
+ if (!hasMessage) {
28
+ originalLabel = viewport.getAttribute(ARIA_LABEL)
29
+ }
30
+ viewport.setAttribute(ARIA_LABEL, message)
31
+ hasMessage = true
32
+ isHoldingAnnouncements = true
33
+ }
34
+ viewport.focus()
35
+ }
36
+
37
+ const clear = () => {
38
+ isHoldingAnnouncements = false
39
+ if (!hasMessage) {
40
+ return
41
+ }
42
+ hasMessage = false
43
+ const viewport = viewportRef.current
44
+ if (!viewport) {
45
+ return
46
+ }
47
+ if (originalLabel === null) {
48
+ viewport.removeAttribute(ARIA_LABEL)
49
+ } else {
50
+ viewport.setAttribute(ARIA_LABEL, originalLabel)
51
+ }
52
+ }
53
+
54
+ const releaseAnnouncements = () => {
55
+ isHoldingAnnouncements = false
56
+ }
57
+
58
+ return {
59
+ focus,
60
+ clear,
61
+ releaseAnnouncements,
62
+ isHoldingAnnouncements: () => isHoldingAnnouncements
63
+ }
64
+ }
@@ -0,0 +1,76 @@
1
+ import { createMapFocus } from './mapFocus.js'
2
+
3
+ describe('createMapFocus', () => {
4
+ let viewport
5
+ let mapFocus
6
+
7
+ beforeEach(() => {
8
+ viewport = document.createElement('div')
9
+ viewport.tabIndex = 0
10
+ viewport.setAttribute('aria-label', 'Interactive map')
11
+ document.body.appendChild(viewport)
12
+ mapFocus = createMapFocus({ viewportRef: { current: viewport } })
13
+ })
14
+
15
+ afterEach(() => {
16
+ viewport.remove()
17
+ })
18
+
19
+ it('focuses the viewport without changing its name or holding announcements', () => {
20
+ mapFocus.focus()
21
+ expect(document.activeElement).toBe(viewport)
22
+ expect(viewport.getAttribute('aria-label')).toBe('Interactive map')
23
+ expect(mapFocus.isHoldingAnnouncements()).toBe(false)
24
+ })
25
+
26
+ it('replaces the name with the message before focusing and holds announcements', () => {
27
+ viewport.addEventListener('focus', () => {
28
+ expect(viewport.getAttribute('aria-label')).toBe('Map moved to Carlisle')
29
+ })
30
+ mapFocus.focus({ message: 'Map moved to Carlisle' })
31
+ expect(document.activeElement).toBe(viewport)
32
+ expect(mapFocus.isHoldingAnnouncements()).toBe(true)
33
+ })
34
+
35
+ it('releaseAnnouncements ends the hold but keeps the message', () => {
36
+ mapFocus.focus({ message: 'Map moved to Carlisle' })
37
+ mapFocus.releaseAnnouncements()
38
+ expect(mapFocus.isHoldingAnnouncements()).toBe(false)
39
+ expect(viewport.getAttribute('aria-label')).toBe('Map moved to Carlisle')
40
+ })
41
+
42
+ it('clear restores the original name and ends the hold', () => {
43
+ mapFocus.focus({ message: 'Map moved to Carlisle' })
44
+ mapFocus.focus({ message: 'Map moved to Leeds' })
45
+ mapFocus.clear()
46
+ expect(viewport.getAttribute('aria-label')).toBe('Interactive map')
47
+ expect(mapFocus.isHoldingAnnouncements()).toBe(false)
48
+ })
49
+
50
+ it('clear leaves the name alone when no message was set', () => {
51
+ viewport.setAttribute('aria-label', 'Changed by the app')
52
+ mapFocus.clear()
53
+ expect(viewport.getAttribute('aria-label')).toBe('Changed by the app')
54
+ })
55
+
56
+ it('clear removes the name again when the viewport had none', () => {
57
+ viewport.removeAttribute('aria-label')
58
+ mapFocus.focus({ message: 'Map moved to Carlisle' })
59
+ mapFocus.clear()
60
+ expect(viewport.hasAttribute('aria-label')).toBe(false)
61
+ })
62
+
63
+ it('copes with the viewport not being mounted', () => {
64
+ const viewportRef = { current: null }
65
+ mapFocus = createMapFocus({ viewportRef })
66
+ expect(() => mapFocus.focus({ message: 'Map moved to Carlisle' })).not.toThrow()
67
+ expect(mapFocus.isHoldingAnnouncements()).toBe(false)
68
+ expect(() => mapFocus.clear()).not.toThrow()
69
+
70
+ // Unmounted between focus and clear
71
+ viewportRef.current = viewport
72
+ mapFocus.focus({ message: 'Map moved to Carlisle' })
73
+ viewportRef.current = null
74
+ expect(() => mapFocus.clear()).not.toThrow()
75
+ })
76
+ })
package/src/types.js CHANGED
@@ -112,7 +112,7 @@
112
112
  * Plugin-specific state.
113
113
  *
114
114
  * @property {Object} [services]
115
- * Core services (announce, reverseGeocode, closeApp, etc.).
115
+ * Core services (announce, focusMap, reverseGeocode, closeApp, etc.).
116
116
  *
117
117
  * @property {(id: string, options?: ApplicationModeOptions) => void} [setApplicationMode]
118
118
  * Plugin components only. Enters an application mode, putting it on top of the stack (or moving it to
@@ -383,11 +383,9 @@
383
383
  * @typedef {Object} MaplibreProviderConfig
384
384
  *
385
385
  * @property {string} [workerUrl]
386
- * URL to a separately hosted MapLibre worker file (`maplibre-gl-csp-worker.js`).
387
- * Required when running under a Content Security Policy that blocks `blob:` worker
388
- * URLs. The file ships with maplibre-gl and must be served from your own origin.
389
- * When set, MapLibre loads the worker from this URL instead of generating an
390
- * inline blob, so your CSP only needs `worker-src 'self'`.
386
+ * URL of the MapLibre worker file. Set automatically with webpack, Vite and the UMD
387
+ * build; with other bundlers (such as esbuild), serve `maplibre-gl/dist/maplibre-gl-worker.mjs`
388
+ * and set its URL here.
391
389
  */
392
390
 
393
391
  /**
@@ -879,7 +877,7 @@
879
877
  * @property {string} [mapHintText]
880
878
  * Visually hidden text, rendered immediately before the map for screen reader users, explaining that it must be focused before keyboard commands work. Prefixed with mapLabel, so multiple maps on one page can be told apart.
881
879
  *
882
- * @property {string} [mapLabel='Interactive map']
880
+ * @property {string} [mapLabel='Interactive map application']
883
881
  * Accessible label for the map, announced by screen readers. Also prefixed onto mapHintText, so give each map on a page a distinct label.
884
882
  *
885
883
  * @property {string} [mapControlsHintText]
@@ -18,6 +18,19 @@ function normalizePointerType (pointerType) {
18
18
  return 'unknown'
19
19
  }
20
20
 
21
+ const KEYBOARD_MODE_KEYS = new Set(['Enter', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Escape'])
22
+ const NON_TEXT_INPUT_TYPES = new Set(['button', 'checkbox', 'color', 'file', 'image', 'radio', 'range', 'reset', 'submit'])
23
+
24
+ function isTextField (el) {
25
+ if (!el) {
26
+ return false
27
+ }
28
+ if (el.tagName === 'TEXTAREA' || el.isContentEditable) {
29
+ return true
30
+ }
31
+ return el.tagName === 'INPUT' && !NON_TEXT_INPUT_TYPES.has(el.type)
32
+ }
33
+
21
34
  function notifyListeners (newType) {
22
35
  if (lastInterfaceType !== newType) {
23
36
  lastInterfaceType = newType
@@ -59,11 +72,9 @@ function createInterfaceDetector () {
59
72
  }
60
73
 
61
74
  const handleKeyDown = e => {
62
- // Recognize keyboard mode from Tab (explicit focus), arrow keys (navigation),
63
- // Enter (confirmation), or other significant keys. This allows the interface type
64
- // to update even when keyboard input happens during drawing (where focus is on map).
65
- const keyboardModeKeys = new Set(['Tab', 'Enter', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Escape'])
66
- if (keyboardModeKeys.has(e.key)) {
75
+ // Tab, and arrows/Enter/Escape outside text fields, switch to keyboard mode. The
76
+ // latter cover a pointer user who clicks the map then pans or draws by keyboard.
77
+ if (e.key === 'Tab' || (KEYBOARD_MODE_KEYS.has(e.key) && !isTextField(e.target))) {
67
78
  notifyListeners('keyboard')
68
79
  }
69
80
  }
@@ -178,6 +178,38 @@ describe('Interface Detector Utility Module', () => {
178
178
  expect(handler).toHaveBeenCalledTimes(2) // no longer called after unsubscribe
179
179
  })
180
180
 
181
+ it('ignores Enter, arrows and Escape typed in a text field but still honours Tab there', () => {
182
+ cleanup = createInterfaceDetector()
183
+ triggerDomEvent('pointerdown', { pointerType: 'mouse' })
184
+
185
+ const input = document.createElement('input')
186
+ const textarea = document.createElement('textarea')
187
+ const editable = { tagName: 'DIV', isContentEditable: true }
188
+ const textFields = [input, textarea, editable]
189
+ textFields.forEach(target => {
190
+ ['Enter', 'ArrowDown', 'ArrowUp', 'Escape'].forEach(key => {
191
+ triggerDomEvent('keydown', { key, target })
192
+ expect(getInterfaceType()).toBe('mouse')
193
+ })
194
+ })
195
+
196
+ triggerDomEvent('keydown', { key: 'Tab', target: input })
197
+ expect(getInterfaceType()).toBe('keyboard')
198
+ })
199
+
200
+ it('switches to keyboard on Enter from non-text controls', () => {
201
+ cleanup = createInterfaceDetector()
202
+ const checkbox = document.createElement('input')
203
+ checkbox.type = 'checkbox'
204
+ const button = document.createElement('button')
205
+ const targets = [checkbox, button, undefined]
206
+ targets.forEach(target => {
207
+ triggerDomEvent('pointerdown', { pointerType: 'mouse' })
208
+ triggerDomEvent('keydown', { key: 'Enter', target })
209
+ expect(getInterfaceType()).toBe('keyboard')
210
+ })
211
+ })
212
+
181
213
  it('should return "touch" when matchMedia initially matches coarse pointer', async () => {
182
214
  jest.resetModules()
183
215
 
package/webpack.dev.mjs CHANGED
@@ -106,6 +106,8 @@ export default {
106
106
  }
107
107
  })
108
108
  ],
109
+ // maplibre-gl builds a URL from an expression when its worker is cross-origin; harmless
110
+ ignoreWarnings: [{ module: /maplibre-gl/, message: /Critical dependency/ }],
109
111
  module: {
110
112
  rules: [
111
113
  {
package/webpack.umd.mjs CHANGED
@@ -59,6 +59,10 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
59
59
  return {
60
60
  mode: 'production',
61
61
 
62
+ // ES5 so the code that runs before the device check (webpack's runtime and the
63
+ // entry chunks) parses in old browsers, which then show the not-supported message
64
+ target: ['web', 'es5'],
65
+
62
66
  entry: { [entryName]: entryPath },
63
67
 
64
68
  parallelism: 100,
@@ -80,7 +84,8 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
80
84
  export: 'default',
81
85
  umdNamedDefine: true
82
86
  },
83
- globalObject: 'this',
87
+ // Not plain `this`: with the ES5 target the bundle runs in a strict-mode function, where it's undefined
88
+ globalObject: "typeof self !== 'undefined' ? self : this",
84
89
  chunkLoadingGlobal: 'webpackChunkdefra_DefraMap',
85
90
  auxiliaryComment: {
86
91
  root: 'Root Export',
@@ -109,17 +114,30 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
109
114
 
110
115
  resolve: {
111
116
  extensions: ['.tsx', '.ts', '.jsx', '.js'],
112
- alias: {
113
- preact: false,
114
- 'preact/compat': false,
115
- 'preact/hooks': false,
116
- 'preact/jsx-runtime': false
117
- }
117
+ // Plugins use the core's Preact through the externals above. The core bundles Preact
118
+ // in place of React, as the ESM and dev builds do; React's module code also uses
119
+ // Symbol, which would stop the entry point loading in old browsers.
120
+ alias: externalPreact
121
+ ? {
122
+ preact: false,
123
+ 'preact/compat': false,
124
+ 'preact/hooks': false,
125
+ 'preact/jsx-runtime': false
126
+ }
127
+ : {
128
+ react: path.resolve(__dirname, 'node_modules/preact/compat'),
129
+ 'react-dom/client': path.resolve(__dirname, 'node_modules/preact/compat/client'),
130
+ 'react-dom': path.resolve(__dirname, 'node_modules/preact/compat'),
131
+ 'react/jsx-runtime': path.resolve(__dirname, 'node_modules/preact/jsx-runtime')
132
+ }
118
133
  },
119
134
 
120
135
  module: {
121
136
  rules: [
122
137
  { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
138
+ // Emitted with a .js extension because some servers don't send a JavaScript
139
+ // content type for .mjs, which module workers require
140
+ { test: /maplibre-gl-worker\.mjs$/, type: 'asset/resource', generator: { filename: 'im-maplibre-worker.js' } },
123
141
  { test: /\.css$/i, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
124
142
  { test: /\.s[ac]ss$/i, use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] }
125
143
  ]
@@ -127,6 +145,9 @@ const createUMDConfig = (entryName, entryPath, libraryPath, outDir, isCore = fal
127
145
 
128
146
  plugins,
129
147
 
148
+ // maplibre-gl builds a URL from an expression when its worker is cross-origin; harmless
149
+ ignoreWarnings: [{ module: /maplibre-gl/, message: /Critical dependency/ }],
150
+
130
151
  optimization: {
131
152
  splitChunks: { chunks: () => false },
132
153
  removeEmptyChunks: true,