@defra/interactive-map 0.0.43-fmp-experimental → 0.0.44-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.
- package/assets/templates/add-polygons.njk +5 -1
- package/assets/templates/add-symbols.njk +5 -1
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +24 -0
- package/docs/api/keyboard-shortcut-definition.md +102 -0
- package/docs/api.md +18 -8
- package/docs/building-a-plugin.md +1 -0
- package/docs/plugins/draw.md +2 -2
- package/docs/plugins/plugin-manifest.md +9 -0
- package/package.json +4 -2
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/src/api/newPolygon.js +1 -0
- package/plugins/beta/draw-es/src/events.js +17 -8
- package/plugins/beta/draw-es/src/reducer.js +8 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/css/index.css +1 -13
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/frame/dist/css/index.css +1 -11
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/src/Frame.jsx +28 -2
- package/plugins/beta/map-styles/dist/css/index.css +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/scale-bar/dist/css/index.css +1 -8
- package/plugins/datasets/dist/css/5648.index.css +1 -5
- package/plugins/datasets/dist/css/index.css +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/src/components/LayersMenu/Layers.module.scss +1 -0
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +6 -5
- package/plugins/datasets/src/registry/dataset.js +8 -12
- package/plugins/datasets/src/registry/dataset.test.js +17 -0
- package/plugins/datasets/src/registry/datasetRegistry.js +4 -5
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +41 -26
- package/plugins/draw/src/DrawInit.test.jsx +55 -12
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +113 -114
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +82 -9
- package/plugins/draw/src/adapters/maplibre/drawEvents.js +3 -1
- package/plugins/draw/src/adapters/maplibre/modes/createDrawMode.test.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/__helpers__/harness.js +18 -9
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +9 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +11 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.js +23 -2
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.test.js +53 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.js +29 -19
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.test.js +17 -2
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +35 -29
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +24 -6
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/keyboardHandlers.js +22 -20
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointOperations.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode.test.js +3 -3
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.js +31 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.test.js +8 -1
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.js +38 -30
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.test.js +20 -3
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +5 -5
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.test.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +3 -3
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +7 -7
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.js +4 -4
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.test.js +14 -14
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.js +12 -32
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.test.js +10 -10
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +48 -22
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.test.js +74 -6
- package/plugins/draw/src/adapters/maplibre/utils/snapMovement.js +2 -2
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +6 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +9 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +15 -2
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +27 -1
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +1 -1
- package/plugins/draw/src/adapters/openlayers/draw/drawInput.js +40 -17
- package/plugins/draw/src/adapters/openlayers/draw/drawInput.test.js +55 -1
- package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.js +13 -7
- package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.test.js +7 -15
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +36 -4
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +41 -1
- package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.js +35 -25
- package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.test.js +40 -2
- package/plugins/draw/src/adapters/openlayers/edit/nudge.js +2 -2
- package/plugins/draw/src/adapters/openlayers/edit/nudge.test.js +2 -2
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +40 -54
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +32 -13
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +1 -1
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +17 -1
- package/plugins/draw/src/events.js +4 -4
- package/plugins/draw/src/events.test.js +1 -1
- package/plugins/draw/src/hooks/useSpatialList.js +180 -0
- package/plugins/draw/src/hooks/useSpatialList.test.js +339 -0
- package/plugins/draw/src/manifest.js +4 -1
- package/plugins/draw/src/manifest.test.js +19 -7
- package/plugins/draw/src/utils/spatial.js +1 -31
- package/plugins/draw/src/utils/spatial.test.js +1 -24
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/interact/src/InteractInit.jsx +2 -2
- package/plugins/interact/src/InteractInit.test.js +3 -3
- package/plugins/interact/src/events.js +11 -2
- package/plugins/interact/src/events.test.js +32 -0
- package/plugins/interact/src/hooks/useAttachEvents.js +20 -0
- package/plugins/interact/src/hooks/useAttachEvents.test.js +44 -1
- package/plugins/interact/src/hooks/useCrossHairVisibility.js +9 -4
- package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +7 -7
- package/plugins/interact/src/hooks/useSpatialList.js +251 -0
- package/plugins/interact/src/hooks/{useMapItemList.test.js → useSpatialList.test.js} +216 -70
- package/plugins/interact/src/manifest.js +12 -1
- package/plugins/interact/src/manifest.test.js +20 -0
- package/plugins/interact/src/utils/spatial.js +24 -1
- package/plugins/interact/src/utils/spatial.test.js +26 -1
- package/plugins/map-key/dist/css/index.css +1 -106
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.jsx +3 -4
- package/plugins/map-key/src/components/Key/Key.module.scss +10 -8
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +9 -7
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
- package/plugins/map-key/src/components/Key/MapKey.jsx +5 -3
- package/plugins/map-key/src/manifest.js +1 -1
- package/plugins/map-key/src/utils/groupStyles.js +7 -0
- package/plugins/map-key/src/utils/mergeKeyGroupItems.js +12 -0
- package/plugins/map-key/src/utils/mergeKeyGroupItems.test.js +53 -0
- package/plugins/menu/dist/css/index.css +1 -80
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +1 -1
- package/plugins/menu/src/initialise/MenuInit.jsx +15 -3
- package/plugins/menu/src/initialise/MenuInit.test.jsx +25 -0
- package/plugins/menu/src/initialise/createMenu.js +3 -1
- package/plugins/menu/src/initialise/createMenu.test.js +20 -5
- package/plugins/menu/src/initialise/updateUrl.js +44 -0
- package/plugins/menu/src/initialise/updateUrl.test.js +91 -0
- package/plugins/menu/src/reducers/menuStateReducer.js +19 -1
- package/plugins/menu/src/reducers/menuStateReducer.test.js +53 -20
- package/plugins/menu/src/reducers/pluginState.js +1 -6
- package/plugins/menu/src/reducers/pluginState.test.js +0 -25
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/src/manifest.js +5 -9
- package/plugins/search/src/manifest.test.js +5 -0
- package/providers/beta/esri/dist/css/index.css +1 -34
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +3 -3
- package/providers/beta/openlayers/src/openlayersProvider.test.js +6 -3
- package/providers/beta/openlayers/src/utils/queryFeatures.js +72 -0
- package/providers/beta/openlayers/src/utils/queryFeatures.test.js +122 -1
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/defaults.test.js +26 -0
- package/providers/maplibre/src/utils/labels.js +2 -2
- package/providers/maplibre/src/utils/labels.test.js +5 -5
- package/providers/maplibre/src/utils/spatial.js +0 -57
- package/providers/maplibre/src/utils/spatial.test.js +0 -27
- package/rollup.esm.mjs +2 -1
- package/scripts/publish-package.sh +36 -0
- package/src/App/App.jsx +1 -1
- package/src/App/App.test.jsx +6 -1
- package/src/App/components/CrossHair/CrossHair.jsx +25 -11
- package/src/App/components/CrossHair/CrossHair.module.scss +37 -12
- package/src/App/components/CrossHair/CrossHair.test.jsx +40 -11
- package/src/App/components/Hints/Hints.jsx +3 -3
- package/src/App/components/Hints/Hints.test.jsx +3 -3
- package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +4 -1
- package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +17 -0
- package/src/App/components/MapButton/MapButton.jsx +19 -7
- package/src/App/components/MapButton/MapButton.module.scss +1 -2
- package/src/App/components/MapButton/MapButton.test.jsx +42 -4
- package/src/App/components/{MoveControls/MoveControls.jsx → MapControls/MapControls.jsx} +10 -10
- package/src/App/components/{MoveControls/MoveControls.module.scss → MapControls/MapControls.module.scss} +25 -25
- package/src/App/components/{MoveControls/MoveControls.test.jsx → MapControls/MapControls.test.jsx} +48 -48
- package/src/App/components/Markers/Markers.jsx +2 -2
- package/src/App/components/Markers/Markers.test.jsx +3 -3
- package/src/App/components/Markers/SymbolMarker.jsx +2 -3
- package/src/App/components/Markers/SymbolMarker.test.jsx +8 -9
- package/src/App/components/Panel/Panel.jsx +19 -20
- package/src/App/components/Panel/Panel.module.scss +5 -0
- package/src/App/components/Panel/Panel.test.jsx +69 -4
- package/src/App/components/PopupMenu/PopupMenu.jsx +7 -3
- package/src/App/components/PopupMenu/PopupMenu.test.jsx +71 -0
- package/src/App/components/PopupMenu/usePopupMenu.js +10 -9
- package/src/App/components/Viewport/MapStatus.jsx +1 -1
- package/src/App/components/Viewport/SpatialList.jsx +47 -0
- package/src/App/components/Viewport/{Features.module.scss → SpatialList.module.scss} +6 -6
- package/src/App/components/Viewport/SpatialList.test.jsx +285 -0
- package/src/App/components/Viewport/Viewport.jsx +21 -11
- package/src/App/components/Viewport/Viewport.test.jsx +18 -2
- package/src/App/controls/keyboardMappings.js +7 -2
- package/src/App/controls/keyboardMappings.test.js +21 -0
- package/src/App/controls/keyboardShortcuts.js +16 -2
- package/src/App/controls/keyboardShortcuts.test.js +21 -0
- package/src/App/hooks/useCrossHairAPI.js +29 -1
- package/src/App/hooks/useCrossHairAPI.test.js +17 -1
- package/src/App/hooks/useHintsAPI.js +5 -5
- package/src/App/hooks/useInterfaceAPI.js +2 -1
- package/src/App/hooks/useInterfaceAPI.test.js +9 -0
- package/src/App/hooks/useKeyboardShortcuts.js +66 -35
- package/src/App/hooks/useKeyboardShortcuts.test.js +52 -0
- package/src/App/hooks/useModalPanelBehaviour.js +48 -34
- package/src/App/hooks/useModalPanelBehaviour.test.js +59 -0
- package/src/App/hooks/useSpatialListFocus.js +296 -0
- package/src/App/hooks/useSpatialListFocus.test.js +957 -0
- package/src/App/hooks/useSpatialListItems.js +51 -0
- package/src/App/hooks/useSpatialListItems.test.js +217 -0
- package/src/App/initialiseApp.js +6 -3
- package/src/App/initialiseApp.test.js +11 -0
- package/src/App/layout/Layout.jsx +4 -2
- package/src/App/layout/Layout.test.jsx +21 -0
- package/src/App/layout/layout.module.scss +7 -1
- package/src/App/registry/keyboardShortcutRegistry.js +2 -2
- package/src/App/registry/keyboardShortcutRegistry.test.js +16 -0
- package/src/App/registry/pluginRegistry.js +13 -0
- package/src/App/registry/pluginRegistry.test.js +15 -0
- package/src/App/registry/spatialListRegistry.js +104 -0
- package/src/App/registry/spatialListRegistry.test.js +218 -0
- package/src/App/renderer/HtmlElementHost.jsx +12 -32
- package/src/App/renderer/mapButtons.js +4 -0
- package/src/App/renderer/mapButtons.test.js +20 -0
- package/src/App/renderer/mapPanels.js +33 -53
- package/src/App/renderer/mapPanels.test.js +29 -4
- package/src/App/renderer/slotHelpers.js +33 -0
- package/src/App/renderer/slotHelpers.test.js +79 -2
- package/src/App/store/AppProvider.jsx +3 -2
- package/src/App/store/ServiceProvider.jsx +5 -3
- package/src/App/store/ServiceProvider.test.jsx +20 -1
- package/src/InteractiveMap/InteractiveMap.js +13 -2
- package/src/InteractiveMap/InteractiveMap.test.js +33 -0
- package/src/config/appConfig.js +16 -16
- package/src/config/appConfig.test.js +19 -19
- package/src/config/defaults.js +2 -2
- package/src/config/events.js +8 -8
- package/src/scss/main.scss +2 -2
- package/src/test-utils.js +8 -0
- package/src/types.js +51 -9
- package/src/utils/findNearestItemInDirection.js +29 -0
- package/src/utils/findNearestItemInDirection.test.js +67 -0
- package/src/utils/getPanelElementId.js +4 -0
- package/src/utils/getPanelElementId.test.js +11 -0
- package/src/utils/getPanelRole.js +22 -0
- package/src/utils/getPanelRole.test.js +56 -0
- package/src/utils/globalAltShortcuts.js +12 -0
- package/src/utils/globalAltShortcuts.test.js +27 -0
- package/src/utils/spatialNavigate.js +49 -0
- package/src/utils/spatialNavigate.test.js +42 -0
- package/webpack.umd.mjs +6 -1
- package/plugins/interact/src/hooks/useMapItemList.js +0 -187
- package/src/App/components/Viewport/Features.jsx +0 -35
- package/src/App/components/Viewport/Features.test.jsx +0 -124
- package/src/App/hooks/useFeatureFocus.js +0 -199
- package/src/App/hooks/useFeatureFocus.test.js +0 -635
- package/src/App/hooks/useFeatureItems.js +0 -39
- package/src/App/hooks/useFeatureItems.test.js +0 -155
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useRef } from 'react'
|
|
2
|
-
import { EVENTS } from '../../config/events.js'
|
|
3
|
-
|
|
4
|
-
const getNavigatedId = (id, key, items) => {
|
|
5
|
-
if (!items.length) {
|
|
6
|
-
return id
|
|
7
|
-
}
|
|
8
|
-
const idx = items.findIndex(item => item.id === id)
|
|
9
|
-
if (key === 'ArrowDown') {
|
|
10
|
-
return idx === -1 ? items[0].id : items[Math.min(idx + 1, items.length - 1)].id
|
|
11
|
-
}
|
|
12
|
-
return idx === -1 ? items[items.length - 1].id : items[Math.max(idx - 1, 0)].id
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ARIA listbox entry priority: first selected → last active (if still in list) → first item
|
|
16
|
-
const resolveEntryId = (items, lastActiveId, selectedIds) => {
|
|
17
|
-
const firstSelected = items.find(item => selectedIds.includes(item.id))
|
|
18
|
-
if (firstSelected) {
|
|
19
|
-
return firstSelected.id
|
|
20
|
-
}
|
|
21
|
-
if (lastActiveId && items.some(item => item.id === lastActiveId)) {
|
|
22
|
-
return lastActiveId
|
|
23
|
-
}
|
|
24
|
-
return items[0].id
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Keeps local selectedIds in sync with interact:selectionchange, and mirrors
|
|
29
|
-
* MAP_SET_ACTIVE_FEATURE back into React state so aria-activedescendant stays current.
|
|
30
|
-
* Also tracks the last non-null active id so it can be restored on re-focus.
|
|
31
|
-
*/
|
|
32
|
-
function useEventBusListeners ({ eventBus, lastActiveIdRef, setActiveFeatureId, setSelectedIds }) {
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!eventBus) {
|
|
35
|
-
return undefined
|
|
36
|
-
}
|
|
37
|
-
const handleSetActive = ({ id }) => {
|
|
38
|
-
if (id !== null) {
|
|
39
|
-
lastActiveIdRef.current = id
|
|
40
|
-
}
|
|
41
|
-
setActiveFeatureId(id)
|
|
42
|
-
}
|
|
43
|
-
const handleSelectionChange = ({ selectedFeatures = [], selectedMarkers = [] }) => {
|
|
44
|
-
setSelectedIds([...selectedFeatures.map(f => String(f.featureId)), ...selectedMarkers])
|
|
45
|
-
}
|
|
46
|
-
eventBus.on(EVENTS.MAP_SET_ACTIVE_FEATURE, handleSetActive)
|
|
47
|
-
eventBus.on('interact:selectionchange', handleSelectionChange)
|
|
48
|
-
return () => {
|
|
49
|
-
eventBus.off(EVENTS.MAP_SET_ACTIVE_FEATURE, handleSetActive)
|
|
50
|
-
eventBus.off('interact:selectionchange', handleSelectionChange)
|
|
51
|
-
}
|
|
52
|
-
}, [eventBus])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Revalidates aria-activedescendant when the item list changes while the listbox is focused.
|
|
57
|
-
* If the current active item is no longer in the list (e.g. panned off screen), picks a new one
|
|
58
|
-
* using ARIA priority order: first selected → last active position → first item.
|
|
59
|
-
* Reads eventBus and selectedIds via refs to avoid spurious re-runs on selection change.
|
|
60
|
-
*/
|
|
61
|
-
function useItemsRevalidation ({ items, eventBus, isFocusedRef, lastActiveIdRef, activeFeatureIdRef, selectedIdsRef, setActiveFeatureId }) {
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (!isFocusedRef.current) {
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
if (!items.length) {
|
|
67
|
-
setActiveFeatureId(null)
|
|
68
|
-
eventBus?.emit(EVENTS.MAP_SET_ACTIVE_FEATURE, { id: null })
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
if (items.some(item => item.id === activeFeatureIdRef.current)) {
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
const nextId = resolveEntryId(items, lastActiveIdRef.current, selectedIdsRef.current)
|
|
75
|
-
lastActiveIdRef.current = nextId
|
|
76
|
-
setActiveFeatureId(nextId)
|
|
77
|
-
eventBus?.emit(EVENTS.MAP_SET_ACTIVE_FEATURE, { id: nextId })
|
|
78
|
-
}, [items]) // NOSONAR — eventBus/selectedIds consumed via refs to avoid spurious re-runs on selection change
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Attaches a keydown listener to the listbox element for ARIA keyboard navigation:
|
|
83
|
-
* - ArrowUp/ArrowDown — move the active item, emitting MAP_SET_ACTIVE_FEATURE
|
|
84
|
-
* - Enter/Space — confirm selection, emitting MAP_SELECT_FEATURE
|
|
85
|
-
* - Escape — return focus to the map viewport
|
|
86
|
-
*/
|
|
87
|
-
function useKeyboardNavigation ({ featuresRef, viewportRef, items, eventBus, activeFeatureIdRef, lastActiveIdRef, setActiveFeatureId, hints, currentHintRef }) {
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
const listboxEl = featuresRef.current
|
|
90
|
-
if (!listboxEl) {
|
|
91
|
-
return undefined
|
|
92
|
-
}
|
|
93
|
-
const handleKeyDown = (event) => {
|
|
94
|
-
if (event.key === 'Escape') {
|
|
95
|
-
event.preventDefault()
|
|
96
|
-
event.stopPropagation()
|
|
97
|
-
if (currentHintRef.current) {
|
|
98
|
-
hints.dismiss()
|
|
99
|
-
} else {
|
|
100
|
-
viewportRef.current?.focus()
|
|
101
|
-
}
|
|
102
|
-
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
103
|
-
event.preventDefault()
|
|
104
|
-
event.stopPropagation()
|
|
105
|
-
const newId = getNavigatedId(activeFeatureIdRef.current, event.key, items)
|
|
106
|
-
lastActiveIdRef.current = newId
|
|
107
|
-
setActiveFeatureId(newId)
|
|
108
|
-
eventBus?.emit(EVENTS.MAP_SET_ACTIVE_FEATURE, { id: newId })
|
|
109
|
-
} else if (event.key === 'Enter' || event.key === ' ') {
|
|
110
|
-
event.preventDefault()
|
|
111
|
-
event.stopPropagation()
|
|
112
|
-
eventBus?.emit(EVENTS.MAP_SELECT_FEATURE)
|
|
113
|
-
} else {
|
|
114
|
-
// No action
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
listboxEl.addEventListener('keydown', handleKeyDown)
|
|
118
|
-
return () => { listboxEl.removeEventListener('keydown', handleKeyDown) }
|
|
119
|
-
}, [viewportRef, featuresRef, items, eventBus])
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Clears listbox focus whenever the user interacts with the map via pointer (mouse or touch).
|
|
124
|
-
* Any pointerdown outside the listbox element moves focus to the viewport, removing the
|
|
125
|
-
* visible focus ring from the listbox without dropping focus to an unknown location.
|
|
126
|
-
*/
|
|
127
|
-
function useMapInteractionBlur ({ viewportRef, featuresRef, isFocusedRef }) {
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
const el = viewportRef.current
|
|
130
|
-
if (!el) {
|
|
131
|
-
return undefined
|
|
132
|
-
}
|
|
133
|
-
const handlePointerDown = (event) => {
|
|
134
|
-
if (isFocusedRef.current && !featuresRef.current?.contains(event.target)) {
|
|
135
|
-
viewportRef.current?.focus()
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
el.addEventListener('pointerdown', handlePointerDown)
|
|
139
|
-
return () => { el.removeEventListener('pointerdown', handlePointerDown) }
|
|
140
|
-
}, [viewportRef, featuresRef])
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Manages ARIA listbox focus state for the keyboard-accessible feature list.
|
|
145
|
-
*
|
|
146
|
-
* On focus, sets aria-activedescendant following ARIA priority order:
|
|
147
|
-
* 1. First selected item (if any)
|
|
148
|
-
* 2. Last active position (if still in the list)
|
|
149
|
-
* 3. First item (fallback)
|
|
150
|
-
*
|
|
151
|
-
* On blur, clears the active descendant. Revalidates automatically when the item list
|
|
152
|
-
* changes (e.g. after a map pan) so the active id never points to a stale item.
|
|
153
|
-
*
|
|
154
|
-
* @param {{ viewportRef: React.RefObject, featuresRef: React.RefObject, items: Array, eventBus: object }} params
|
|
155
|
-
* @returns {{ activeFeatureId: string|null, selectedIds: string[], onFocus: Function, onBlur: Function }}
|
|
156
|
-
*/
|
|
157
|
-
export function useFeatureFocus ({ viewportRef, featuresRef, items = [], eventBus, hints }) {
|
|
158
|
-
const [activeFeatureId, setActiveFeatureId] = useState(null)
|
|
159
|
-
const [selectedIds, setSelectedIds] = useState([])
|
|
160
|
-
|
|
161
|
-
const isFocusedRef = useRef(false)
|
|
162
|
-
const lastActiveIdRef = useRef(null) // preserved across blur; restores position on re-focus
|
|
163
|
-
const activeFeatureIdRef = useRef(null) // always-current for keydown closure
|
|
164
|
-
const selectedIdsRef = useRef([]) // always-current for items-change effect
|
|
165
|
-
const currentHintRef = useRef(null)
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
return hints.subscribe((hint) => {
|
|
169
|
-
currentHintRef.current = hint
|
|
170
|
-
})
|
|
171
|
-
}, [hints])
|
|
172
|
-
|
|
173
|
-
useEffect(() => { activeFeatureIdRef.current = activeFeatureId }, [activeFeatureId])
|
|
174
|
-
useEffect(() => { selectedIdsRef.current = selectedIds }, [selectedIds])
|
|
175
|
-
|
|
176
|
-
useEventBusListeners({ eventBus, lastActiveIdRef, setActiveFeatureId, setSelectedIds })
|
|
177
|
-
useItemsRevalidation({ items, eventBus, isFocusedRef, lastActiveIdRef, activeFeatureIdRef, selectedIdsRef, setActiveFeatureId })
|
|
178
|
-
useKeyboardNavigation({ featuresRef, viewportRef, items, eventBus, activeFeatureIdRef, lastActiveIdRef, setActiveFeatureId, hints, currentHintRef })
|
|
179
|
-
useMapInteractionBlur({ viewportRef, featuresRef, isFocusedRef })
|
|
180
|
-
|
|
181
|
-
const onFocus = () => {
|
|
182
|
-
isFocusedRef.current = true
|
|
183
|
-
if (!items.length) {
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
const id = resolveEntryId(items, lastActiveIdRef.current, selectedIds)
|
|
187
|
-
lastActiveIdRef.current = id
|
|
188
|
-
setActiveFeatureId(id)
|
|
189
|
-
eventBus?.emit(EVENTS.MAP_SET_ACTIVE_FEATURE, { id })
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const onBlur = () => {
|
|
193
|
-
isFocusedRef.current = false
|
|
194
|
-
setActiveFeatureId(null)
|
|
195
|
-
eventBus?.emit(EVENTS.MAP_SET_ACTIVE_FEATURE, { id: null })
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return { activeFeatureId, selectedIds, onFocus, onBlur }
|
|
199
|
-
}
|