@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.
- package/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- 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/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api/context.md +12 -0
- package/docs/api.md +14 -16
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/datasets.md +2 -0
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/map-key.md +41 -0
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.js +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/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +12 -24
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +21 -16
- package/plugins/datasets/src/registry/dataset.test.js +101 -11
- 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/esm/liveDrawChecks.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/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.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/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.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.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.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/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +7 -1
- package/src/App/store/ServiceProvider.test.jsx +15 -0
- package/src/InteractiveMap/InteractiveMap.js +5 -4
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/types.js +5 -7
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/webpack.dev.mjs +2 -0
- package/webpack.umd.mjs +28 -7
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/react'
|
|
2
2
|
import { KeyGroupItem } from './KeyGroupItem'
|
|
3
|
+
import { useRampOrientation } from './useRampOrientation.js'
|
|
4
|
+
|
|
5
|
+
jest.mock('./useRampOrientation.js', () => ({
|
|
6
|
+
useRampOrientation: jest.fn(() => 'horizontal')
|
|
7
|
+
}))
|
|
3
8
|
|
|
4
9
|
jest.mock('./KeyItem.jsx', () => ({
|
|
5
10
|
KeyItem: ({ keyDefinition }) => <div data-testid='key-item'>{keyDefinition.id}</div>
|
|
@@ -52,8 +57,45 @@ describe('KeyGroupItem', () => {
|
|
|
52
57
|
})
|
|
53
58
|
|
|
54
59
|
it('appends the groupStyle modifier class to the dl when groupStyle is provided', () => {
|
|
55
|
-
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='
|
|
56
|
-
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list
|
|
60
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='other' />)
|
|
61
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--other')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('adds the measured orientation to a ramp', () => {
|
|
65
|
+
const keyDefinitions = [{ id: 'a', label: 'Low', style: {} }, { id: 'b', label: 'High', style: {} }]
|
|
66
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
67
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal')
|
|
68
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), ['Low', 'High'], true, false)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('renders a vertical ramp when the labels do not fit', () => {
|
|
72
|
+
useRampOrientation.mockReturnValueOnce('vertical')
|
|
73
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' />)
|
|
74
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-vertical')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('shows a ramp with any symbol entries as a standard group', () => {
|
|
78
|
+
const keyDefinitions = [{ id: 'a', label: 'Low', style: { fill: '#000' } }, { id: 'b', label: 'High', style: { symbol: 'pin' } }]
|
|
79
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
80
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list')
|
|
81
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), ['Low', 'High'], false, false)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('does not measure groups that are not ramps', () => {
|
|
85
|
+
render(<KeyGroupItem {...baseProps} />)
|
|
86
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), [], false, false)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('adds the has-stroke modifier to a ramp when any item has a stroke', () => {
|
|
90
|
+
const keyDefinitions = [{ id: 'a', style: { fill: '#000' } }, { id: 'b', style: { stroke: { default: '#123' } } }]
|
|
91
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
92
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal im-c-map-key-list--has-stroke')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('omits the has-stroke modifier when no ramp item has a stroke', () => {
|
|
96
|
+
const keyDefinitions = [{ id: 'a', style: { fill: '#000' } }, { id: 'b', style: { fillPattern: 'dot' } }]
|
|
97
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
98
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal')
|
|
57
99
|
})
|
|
58
100
|
|
|
59
101
|
it('uses the base dl class when groupStyle is not provided', () => {
|
|
@@ -3,7 +3,7 @@ import { KeySvgSymbol } from './KeySvgSymbol.jsx'
|
|
|
3
3
|
import { KeySvgLine } from './KeySvgLine.jsx'
|
|
4
4
|
import { KeySvgRect } from './KeySvgRect.jsx'
|
|
5
5
|
import { KeySvgRamp } from './KeySvgRamp.jsx'
|
|
6
|
-
import {
|
|
6
|
+
import { RAMP } from '../../utils/groupStyles.js'
|
|
7
7
|
|
|
8
8
|
// Pure derivation of keyDefinition — computed directly during render (see KeyItem.jsx for why:
|
|
9
9
|
// staging this through useState/useEffect meant every fresh mount painted a blank symbol first).
|
|
@@ -13,8 +13,8 @@ const getSymbolShape = (keyDefinition, groupStyle, mapStyle, symbolRegistry) =>
|
|
|
13
13
|
return { symbolShape: null, keySymbol: null }
|
|
14
14
|
}
|
|
15
15
|
const { hasSymbol, hasPattern, style } = keyDefinition
|
|
16
|
-
if (groupStyle ===
|
|
17
|
-
return { symbolShape:
|
|
16
|
+
if (groupStyle === RAMP) {
|
|
17
|
+
return { symbolShape: RAMP, keySymbol: null }
|
|
18
18
|
}
|
|
19
19
|
if (hasSymbol) {
|
|
20
20
|
const keySymbol = symbolRegistry.getKeySymbol(style, mapStyle)
|
|
@@ -42,8 +42,8 @@ export const KeySvg = ({ keyDefinition, groupStyle, mapStyle, symbolRegistry, pa
|
|
|
42
42
|
return <KeySvgPattern mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />
|
|
43
43
|
} else if (symbolShape === 'line') {
|
|
44
44
|
return <KeySvgLine mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
45
|
-
} else if (symbolShape ===
|
|
46
|
-
return <KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
45
|
+
} else if (symbolShape === RAMP) {
|
|
46
|
+
return <KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />
|
|
47
47
|
} else {
|
|
48
48
|
return <KeySvgRect mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
49
49
|
}
|
|
@@ -23,7 +23,7 @@ jest.mock('./KeySvgRect.jsx', () => ({
|
|
|
23
23
|
}))
|
|
24
24
|
|
|
25
25
|
jest.mock('./KeySvgRamp.jsx', () => ({
|
|
26
|
-
KeySvgRamp: () => <svg data-testid='key-svg-
|
|
26
|
+
KeySvgRamp: () => <svg data-testid='key-svg-ramp' />
|
|
27
27
|
}))
|
|
28
28
|
|
|
29
29
|
const baseKeyDefinition = {
|
|
@@ -98,8 +98,8 @@ describe('KeySvg', () => {
|
|
|
98
98
|
expect(container.firstChild).toBeNull()
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
it('renders KeySvgRamp when groupStyle is
|
|
102
|
-
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition }} groupStyle='
|
|
103
|
-
expect(getByTestId('key-svg-
|
|
101
|
+
it('renders KeySvgRamp when groupStyle is ramp', () => {
|
|
102
|
+
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition }} groupStyle='ramp' />)
|
|
103
|
+
expect(getByTestId('key-svg-ramp')).toBeTruthy()
|
|
104
104
|
})
|
|
105
105
|
})
|
|
@@ -1,13 +1,42 @@
|
|
|
1
|
+
import { useId } from 'react'
|
|
1
2
|
import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// Matches the 2px border and 16×16 tile inset of the standard pattern key symbol.
|
|
5
|
+
const BORDER_WIDTH = 2
|
|
6
|
+
const PATTERN_TILE_SIZE = 16
|
|
7
|
+
|
|
8
|
+
// No viewBox: the band stretches to its column's width, and a viewBox would scale the
|
|
9
|
+
// pattern tile and stroke with it. Shapes and userSpaceOnUse tiles resolve in real pixels.
|
|
10
|
+
export const KeySvgRamp = ({ mapStyle, keyDefinition, patternRegistry }) => {
|
|
11
|
+
const { style, hasPattern } = keyDefinition
|
|
12
|
+
const patternId = 'im-c-map-key-ramp-' + useId().replace(/[^\w-]/g, '')
|
|
13
|
+
const paths = hasPattern ? patternRegistry.getKeyPatternPaths(style, mapStyle.id) : null
|
|
14
|
+
const stroke = getValueForStyle(style.stroke, mapStyle.id)
|
|
15
|
+
const fill = paths ? `url(#${patternId})` : getValueForStyle(style.fill, mapStyle.id)
|
|
7
16
|
|
|
8
17
|
return (
|
|
9
|
-
<svg
|
|
10
|
-
|
|
18
|
+
<svg xmlns='http://www.w3.org/2000/svg' className='im-c-map-key-symbol' aria-hidden='true' focusable='false'>
|
|
19
|
+
{paths && (
|
|
20
|
+
<defs>
|
|
21
|
+
<pattern
|
|
22
|
+
id={patternId}
|
|
23
|
+
patternUnits='userSpaceOnUse'
|
|
24
|
+
x={BORDER_WIDTH}
|
|
25
|
+
y={BORDER_WIDTH}
|
|
26
|
+
width={PATTERN_TILE_SIZE}
|
|
27
|
+
height={PATTERN_TILE_SIZE}
|
|
28
|
+
dangerouslySetInnerHTML={{ __html: paths.content }}
|
|
29
|
+
/>
|
|
30
|
+
</defs>
|
|
31
|
+
)}
|
|
32
|
+
{/* The stroke is drawn at double width on a flush rect; the svg clips the outer half */}
|
|
33
|
+
<rect
|
|
34
|
+
width='100%'
|
|
35
|
+
height='100%'
|
|
36
|
+
fill={fill || 'none'}
|
|
37
|
+
stroke={stroke}
|
|
38
|
+
strokeWidth={stroke ? BORDER_WIDTH * 2 : undefined}
|
|
39
|
+
/>
|
|
11
40
|
</svg>
|
|
12
41
|
)
|
|
13
42
|
}
|
|
@@ -7,37 +7,77 @@ jest.mock('../../../../../src/utils/getValueForStyle.js', () => ({
|
|
|
7
7
|
}))
|
|
8
8
|
|
|
9
9
|
const mapStyle = { id: 'outdoor' }
|
|
10
|
-
const
|
|
10
|
+
const fillKeyDefinition = { style: { fill: { outdoor: '#3d9', dark: '#1a5' }, stroke: '#123' } }
|
|
11
|
+
const patternKeyDefinition = {
|
|
12
|
+
hasPattern: true,
|
|
13
|
+
style: { fillPattern: 'dot', fillPatternForegroundColor: '#2E7D32' }
|
|
14
|
+
}
|
|
15
|
+
const patternRegistry = {
|
|
16
|
+
getKeyPatternPaths: jest.fn(() => ({ border: '<path/>', content: '<path d="M0 0h1v1H0z" fill="#2E7D32"/>' }))
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks()
|
|
13
21
|
getValueForStyle.mockImplementation((value) =>
|
|
14
22
|
typeof value === 'object' ? value.outdoor : value
|
|
15
23
|
)
|
|
16
24
|
})
|
|
17
25
|
|
|
26
|
+
const renderRamp = (keyDefinition) =>
|
|
27
|
+
render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />)
|
|
28
|
+
|
|
18
29
|
describe('KeySvgRamp', () => {
|
|
19
|
-
it('renders an svg
|
|
20
|
-
const { container } =
|
|
21
|
-
|
|
30
|
+
it('renders an svg without a viewBox, so the band stretches without distortion', () => {
|
|
31
|
+
const { container } = renderRamp(fillKeyDefinition)
|
|
32
|
+
const svg = container.querySelector('svg')
|
|
33
|
+
expect(svg.getAttribute('viewBox')).toBeNull()
|
|
34
|
+
expect(svg.getAttribute('class')).toBe('im-c-map-key-symbol')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('fills the rect with the resolved fill and strokes it with the resolved stroke', () => {
|
|
38
|
+
const { container } = renderRamp(fillKeyDefinition)
|
|
39
|
+
const rect = container.querySelector('rect')
|
|
40
|
+
expect(rect.getAttribute('fill')).toBe('#3d9')
|
|
41
|
+
expect(rect.getAttribute('stroke')).toBe('#123')
|
|
42
|
+
expect(rect.getAttribute('stroke-width')).toBe('4')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('omits the stroke when none is resolved', () => {
|
|
46
|
+
const { container } = renderRamp({ style: { fill: '#3d9' } })
|
|
47
|
+
const rect = container.querySelector('rect')
|
|
48
|
+
expect(rect.getAttribute('stroke')).toBeNull()
|
|
49
|
+
expect(rect.getAttribute('stroke-width')).toBeNull()
|
|
22
50
|
})
|
|
23
51
|
|
|
24
|
-
it('
|
|
25
|
-
const { container } =
|
|
26
|
-
|
|
52
|
+
it('fills the rect with a userSpaceOnUse pattern tile when the item has a pattern', () => {
|
|
53
|
+
const { container } = renderRamp(patternKeyDefinition)
|
|
54
|
+
const pattern = container.querySelector('pattern')
|
|
55
|
+
const rect = container.querySelector('rect')
|
|
56
|
+
expect(patternRegistry.getKeyPatternPaths).toHaveBeenCalledWith(patternKeyDefinition.style, 'outdoor')
|
|
57
|
+
expect(pattern.getAttribute('patternUnits')).toBe('userSpaceOnUse')
|
|
58
|
+
expect(pattern.getAttribute('width')).toBe('16')
|
|
59
|
+
expect(pattern.querySelector('path')).toBeTruthy()
|
|
60
|
+
expect(rect.getAttribute('fill')).toBe(`url(#${pattern.id})`)
|
|
27
61
|
})
|
|
28
62
|
|
|
29
|
-
it('
|
|
30
|
-
const { container } =
|
|
31
|
-
expect(container.querySelector('
|
|
63
|
+
it('draws no stroke on a pattern without a stroke', () => {
|
|
64
|
+
const { container } = renderRamp(patternKeyDefinition)
|
|
65
|
+
expect(container.querySelector('rect').getAttribute('stroke')).toBeNull()
|
|
32
66
|
})
|
|
33
67
|
|
|
34
|
-
it('
|
|
35
|
-
const { container } = render(
|
|
36
|
-
|
|
68
|
+
it('gives each band its own pattern id', () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<>
|
|
71
|
+
<KeySvgRamp mapStyle={mapStyle} keyDefinition={patternKeyDefinition} patternRegistry={patternRegistry} />
|
|
72
|
+
<KeySvgRamp mapStyle={mapStyle} keyDefinition={patternKeyDefinition} patternRegistry={patternRegistry} />
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
75
|
+
const [a, b] = container.querySelectorAll('pattern')
|
|
76
|
+
expect(a.id).not.toBe(b.id)
|
|
37
77
|
})
|
|
38
78
|
|
|
39
|
-
it('
|
|
40
|
-
const { container } =
|
|
41
|
-
expect(container.querySelector('
|
|
79
|
+
it('uses no fill when neither a fill nor a pattern is set', () => {
|
|
80
|
+
const { container } = renderRamp({ style: { stroke: '#123' } })
|
|
81
|
+
expect(container.querySelector('rect').getAttribute('fill')).toBe('none')
|
|
42
82
|
})
|
|
43
83
|
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const HORIZONTAL = 'horizontal'
|
|
4
|
+
export const VERTICAL = 'vertical'
|
|
5
|
+
|
|
6
|
+
let measureContext
|
|
7
|
+
const getMeasureContext = () => {
|
|
8
|
+
if (measureContext === undefined) {
|
|
9
|
+
measureContext = document.createElement('canvas').getContext('2d') ?? null
|
|
10
|
+
}
|
|
11
|
+
return measureContext
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Whether every label fits on one line in an equal share of the list's width. Both ramp
|
|
15
|
+
// orientations share the list's side padding and gap, so the result doesn't depend on which
|
|
16
|
+
// orientation is currently rendered. Returns null when there's nothing to measure yet.
|
|
17
|
+
const labelsFitHorizontally = (list, labels) => {
|
|
18
|
+
const label = list.querySelector('.im-c-map-key-list__item-label')
|
|
19
|
+
const context = getMeasureContext()
|
|
20
|
+
if (!label || !context || !list.clientWidth) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
const { fontStyle, fontWeight, fontSize, fontFamily } = getComputedStyle(label)
|
|
24
|
+
context.font = `${fontStyle} ${fontWeight} ${fontSize} ${fontFamily}`
|
|
25
|
+
const listStyle = getComputedStyle(list)
|
|
26
|
+
const gap = Number.parseFloat(listStyle.columnGap) || 0
|
|
27
|
+
const padding = (Number.parseFloat(listStyle.paddingLeft) || 0) + (Number.parseFloat(listStyle.paddingRight) || 0)
|
|
28
|
+
const columnWidth = (list.clientWidth - padding - gap * (labels.length - 1)) / labels.length
|
|
29
|
+
return labels.every(text => context.measureText(text).width <= columnWidth)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A ramp is horizontal when every label fits on one line under its band, otherwise vertical.
|
|
33
|
+
// Measured before paint, and again when the list resizes or web fonts finish loading.
|
|
34
|
+
export const useRampOrientation = (listRef, labels, isRamp, hasStroke) => {
|
|
35
|
+
const [fits, setFits] = useState(true)
|
|
36
|
+
const labelsKey = labels.join('\n')
|
|
37
|
+
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
const list = listRef.current
|
|
40
|
+
if (!isRamp || !list) {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
let active = true
|
|
44
|
+
const update = () => {
|
|
45
|
+
const result = active ? labelsFitHorizontally(list, labels) : null
|
|
46
|
+
if (result !== null) {
|
|
47
|
+
setFits(result)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
update()
|
|
51
|
+
const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(update) : null
|
|
52
|
+
observer?.observe(list)
|
|
53
|
+
document.fonts?.ready.then(update, () => {})
|
|
54
|
+
return () => {
|
|
55
|
+
active = false
|
|
56
|
+
observer?.disconnect()
|
|
57
|
+
}
|
|
58
|
+
}, [isRamp, hasStroke, labelsKey])
|
|
59
|
+
|
|
60
|
+
return fits ? HORIZONTAL : VERTICAL
|
|
61
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
import { render, act } from '@testing-library/react'
|
|
3
|
+
import { useRampOrientation } from './useRampOrientation.js'
|
|
4
|
+
|
|
5
|
+
// Each character measures 10px wide
|
|
6
|
+
const measureText = jest.fn(text => ({ width: text.length * 10 }))
|
|
7
|
+
jest.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({ font: '', measureText })
|
|
8
|
+
|
|
9
|
+
let resizeCallback
|
|
10
|
+
let observe
|
|
11
|
+
let disconnect
|
|
12
|
+
|
|
13
|
+
const TestRamp = ({ labels, isRamp = true, width, padding = 0 }) => {
|
|
14
|
+
const listRef = useRef(null)
|
|
15
|
+
const setList = (list) => {
|
|
16
|
+
if (list) {
|
|
17
|
+
Object.defineProperty(list, 'clientWidth', { configurable: true, get: () => width })
|
|
18
|
+
}
|
|
19
|
+
listRef.current = list
|
|
20
|
+
}
|
|
21
|
+
const orientation = useRampOrientation(listRef, labels, isRamp, false)
|
|
22
|
+
return (
|
|
23
|
+
<dl ref={setList} data-orientation={orientation} style={{ paddingLeft: `${padding}px`, paddingRight: `${padding}px` }}>
|
|
24
|
+
{labels.map(label => <dd key={label} className='im-c-map-key-list__item-label'>{label}</dd>)}
|
|
25
|
+
</dl>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getOrientation = (container) => container.querySelector('dl').dataset.orientation
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
jest.clearAllMocks()
|
|
33
|
+
observe = jest.fn()
|
|
34
|
+
disconnect = jest.fn()
|
|
35
|
+
globalThis.ResizeObserver = jest.fn(callback => {
|
|
36
|
+
resizeCallback = callback
|
|
37
|
+
return { observe, disconnect }
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
delete globalThis.ResizeObserver
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('useRampOrientation', () => {
|
|
46
|
+
it('is horizontal when every label fits in an equal column', () => {
|
|
47
|
+
// 3 columns of 100px; longest label is 90px
|
|
48
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'Very high']} width={300} />)
|
|
49
|
+
expect(getOrientation(container)).toBe('horizontal')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('is vertical when any label is wider than its column', () => {
|
|
53
|
+
// 3 columns of 50px; 'Medium' is 60px
|
|
54
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
|
|
55
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('subtracts the list padding from the available width', () => {
|
|
59
|
+
// 2 columns of 30px after 20px padding either side; 'High' is 40px
|
|
60
|
+
const { container } = render(<TestRamp labels={['Low', 'High']} width={100} padding={20} />)
|
|
61
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('re-measures when the list resizes', () => {
|
|
65
|
+
const labels = ['Low', 'Medium', 'High']
|
|
66
|
+
const { container, rerender } = render(<TestRamp labels={labels} width={150} />)
|
|
67
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
68
|
+
rerender(<TestRamp labels={labels} width={300} />)
|
|
69
|
+
act(() => resizeCallback())
|
|
70
|
+
expect(getOrientation(container)).toBe('horizontal')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('keeps its current orientation while the list has no width', () => {
|
|
74
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={0} />)
|
|
75
|
+
expect(getOrientation(container)).toBe('horizontal')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('does not measure or observe when the group is not a ramp', () => {
|
|
79
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} isRamp={false} />)
|
|
80
|
+
expect(getOrientation(container)).toBe('horizontal')
|
|
81
|
+
expect(measureText).not.toHaveBeenCalled()
|
|
82
|
+
expect(globalThis.ResizeObserver).not.toHaveBeenCalled()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('still measures when ResizeObserver is unavailable', () => {
|
|
86
|
+
delete globalThis.ResizeObserver
|
|
87
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
|
|
88
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
describe('when web fonts load', () => {
|
|
92
|
+
let resolveFonts
|
|
93
|
+
let rejectFonts
|
|
94
|
+
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
Object.defineProperty(document, 'fonts', {
|
|
97
|
+
configurable: true,
|
|
98
|
+
value: { ready: new Promise((resolve, reject) => { resolveFonts = resolve; rejectFonts = reject }) }
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
afterEach(() => {
|
|
103
|
+
delete document.fonts
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('re-measures', async () => {
|
|
107
|
+
const labels = ['Low', 'Medium', 'High']
|
|
108
|
+
const { container, rerender } = render(<TestRamp labels={labels} width={150} />)
|
|
109
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
110
|
+
rerender(<TestRamp labels={labels} width={300} />)
|
|
111
|
+
await act(async () => resolveFonts())
|
|
112
|
+
expect(getOrientation(container)).toBe('horizontal')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('ignores a font loading failure', async () => {
|
|
116
|
+
const { container } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
|
|
117
|
+
measureText.mockClear()
|
|
118
|
+
await act(async () => rejectFonts(new Error('font failed')))
|
|
119
|
+
expect(measureText).not.toHaveBeenCalled()
|
|
120
|
+
expect(getOrientation(container)).toBe('vertical')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('does not measure after unmount', async () => {
|
|
124
|
+
const { unmount } = render(<TestRamp labels={['Low', 'Medium', 'High']} width={150} />)
|
|
125
|
+
unmount()
|
|
126
|
+
measureText.mockClear()
|
|
127
|
+
await act(async () => resolveFonts())
|
|
128
|
+
expect(measureText).not.toHaveBeenCalled()
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('stays horizontal when a canvas context is unavailable', () => {
|
|
133
|
+
// A fresh copy of the module, so its cached measuring context is unset. The pure entry point
|
|
134
|
+
// doesn't register cleanup hooks, which can't be added from inside a test.
|
|
135
|
+
jest.isolateModules(() => {
|
|
136
|
+
const { renderHook } = require('@testing-library/react/pure')
|
|
137
|
+
const { useRampOrientation: isolatedUseRampOrientation } = require('./useRampOrientation.js')
|
|
138
|
+
HTMLCanvasElement.prototype.getContext.mockReturnValueOnce(null)
|
|
139
|
+
const list = document.createElement('dl')
|
|
140
|
+
list.innerHTML = '<dd class="im-c-map-key-list__item-label">Medium</dd>'
|
|
141
|
+
Object.defineProperty(list, 'clientWidth', { get: () => 10 })
|
|
142
|
+
const { result, unmount } = renderHook(() => isolatedUseRampOrientation({ current: list }, ['Medium'], true, false))
|
|
143
|
+
expect(result.current).toBe('horizontal')
|
|
144
|
+
expect(measureText).not.toHaveBeenCalled()
|
|
145
|
+
unmount()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('stops observing on unmount', () => {
|
|
150
|
+
const { unmount } = render(<TestRamp labels={['Low']} width={150} />)
|
|
151
|
+
expect(observe).toHaveBeenCalled()
|
|
152
|
+
unmount()
|
|
153
|
+
expect(disconnect).toHaveBeenCalled()
|
|
154
|
+
})
|
|
155
|
+
})
|
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
import './mapKey.scss'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Display options for a group of key entries.
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} MapKeyGroupConfig
|
|
7
|
+
*
|
|
8
|
+
* @property {string} [groupLabel]
|
|
9
|
+
* Heading shown above the group. Replaces the heading the group's entries provide.
|
|
10
|
+
*
|
|
11
|
+
* @property {'ramp'} [groupStyle]
|
|
12
|
+
* How the group's entries are laid out. `'ramp'` shows them as touching bands, each filled with the
|
|
13
|
+
* entry's fill or fill pattern and outlined in its stroke colour: in a row with each label centred
|
|
14
|
+
* below its band when every label fits on one line, otherwise stacked with each label beside its
|
|
15
|
+
* band. When any entry has a stroke, the bands are separated by a small gap. A group with any
|
|
16
|
+
* symbol entries is shown without a groupStyle.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Options for the map key plugin.
|
|
21
|
+
*
|
|
22
|
+
* @typedef {Object} MapKeyPluginOptions
|
|
23
|
+
*
|
|
24
|
+
* @property {string} [noKeyItemText='No features displayed']
|
|
25
|
+
* Text shown in the key panel when it has no visible entries to display.
|
|
26
|
+
*
|
|
27
|
+
* @property {Object<string, MapKeyGroupConfig>} [groups]
|
|
28
|
+
* Display options for key groups, keyed by group id.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates the map key plugin.
|
|
33
|
+
*
|
|
34
|
+
* @param {MapKeyPluginOptions} [options]
|
|
35
|
+
* @returns {import('../../../src/types.js').PluginDescriptor}
|
|
36
|
+
*/
|
|
3
37
|
export default function createPlugin (options = {}) {
|
|
4
38
|
return {
|
|
5
39
|
noKeyItemText: 'No features displayed',
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `groupStyle` value that lays a group's entries out as a ramp of touching bands.
|
|
3
|
+
*/
|
|
4
|
+
export const RAMP = 'ramp'
|
|
2
5
|
|
|
3
6
|
const groupStyles = {
|
|
4
|
-
|
|
7
|
+
RAMP
|
|
5
8
|
}
|
|
6
9
|
|
|
7
10
|
export default groupStyles
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as e,useContext as t,useState as
|
|
1
|
+
import{createContext as e,useContext as t,useState as n,useRef as a,useEffect as i}from"preact/compat";import{jsx as o,jsxs as s,Fragment as u}from"preact/jsx-runtime";let c={};const l=e=>{const t=c?.current?.menuState||{};for(const[n,a]of Object.entries(e)){const e=t[n];if(!a.includes(e))return!1}return!0},r=e=>{if(null==e)return!0;if("boolean"==typeof e)return e;if("object"==typeof e){for(const[t,n]of Object.entries(e))if("menu"===t&&!l(n))return!1;return!0}return!0},m=e("map-menu"),d=e=>`${t(m)}-${e}`,p=({menuGroupItem:e,name:t,checked:n,onChange:a})=>{const i=d(`radio-${e.id}`),{visibleWhen:u}=e;return!u||r(u)?o("div",{className:'im-c-menu__item govuk-radios govuk-radios--small"',"data-module":"govuk-radios",children:s("div",{className:"govuk-radios__item",children:[o("input",{id:i,className:"govuk-radios__input",type:"radio",name:t,value:e.id,checked:n,onChange:a}),o("label",{className:"im-c-menu__item-label govuk-label govuk-radios__label",htmlFor:i,children:e.label})]})}):null},h=({menuGroup:e,children:t})=>{const n=e.groupLabel||e.label;if(!n)return o(u,{children:t});return o("div",{className:"govuk-form-group im-c-menu-group",children:s("fieldset",{className:"im-c-menu-group__fieldset",children:[o("legend",{className:"im-c-menu-group__legend",children:s("h3",{children:[" ",n," "]})}),t]})},e.id)},g=({menuState:e,dispatch:t,menuGroup:n})=>{const{id:a,items:i,visibleWhen:s}=n;if(!(!s||r(s)))return null;const u=e[a],c=e=>{t({type:"UPDATE_MENU_STATE",payload:{[a]:e.target.value}})};return o(h,{menuGroup:n,children:o("div",{className:"govuk-radios govuk-radios--small","data-module":"govuk-radios",children:i.map(e=>o(p,{menuGroupItem:e,name:a,checked:e.id===u,onChange:c},e.id))})})},b=({dispatch:e,menuGroupItem:t,onChange:n,checked:a})=>{const i="im-c-menu__item govuk-checkboxes govuk-checkboxes--small"+(a?"":" im-c-menu__item--checked"),u=d(`checkbox-${t.id}`);return o("div",{className:i,"data-module":"govuk-checkboxes",children:s("div",{className:"govuk-checkboxes__item",children:[o("input",{className:"govuk-checkboxes__input",id:u,name:u,type:"checkbox",checked:a,onChange:a=>{const i=Boolean(a.target?.checked);n&&n(i),e({type:"UPDATE_MENU_STATE",payload:{[t.id]:i}})}}),o("label",{className:"im-c-menu__item-label govuk-label govuk-checkboxes__label",htmlFor:u,children:t.label})]})},u)},v=({dispatch:e,menuGroup:t,menuState:n})=>s(h,{menuGroup:t,children:[" ",t.items.map(t=>o(b,{dispatch:e,menuGroupItem:t,checked:n[t.id],onChange:t.handleOnChange},t.id))]}),k=({menuGroup:e,dispatch:t,menuState:n})=>"checkbox"===e.type?o(v,{menuGroup:e,dispatch:t,menuState:n}):o(g,{menuGroup:e,dispatch:t,menuState:n}),f=e=>{},_=({menu:e,eventBus:t,dispatch:n,pluginStateRef:a})=>{const i=(e=>{const t=new URL(window.location.href),{searchParams:n}=t,a={};return e.forEach(e=>{const t=n.get(e.id);if("radio"===e.type)a[e.id]=t||e.value||e.items?.[0].value;else{const{items:n}=e;n.forEach(e=>{const{id:n,checked:i}=e,o=t?t.includes(n):i;a[n]=o})}}),a})(e);return n({type:"SET_MENU",payload:{menu:e,menuState:i}}),t.requestOnce("datasets:registry",f),t.emitWhenRequested("menu:state",a)};const S={InitComponent:function({pluginConfig:e,pluginState:t,mapState:o,services:s}){const{dispatch:u}=t,{eventBus:l}=s,[m,d]=n(!1),p=a(t);p.current=t,i(()=>{if(!o.isMapReady)return()=>{};(e=>{c=e})(p);const{menu:t}=e,n=_({menu:t,eventBus:l,dispatch:u,pluginStateRef:p});return d(!0),n},[o.isMapReady]),i(()=>{l.emit("menu:changed",t.menuState),m&&(e=>{const t=new URL(window.location.href),{searchParams:n}=t,{menu:a,menuState:i}=e;a.forEach(e=>{const{id:t,visibleWhen:a,type:o}=e;r(a)?"radio"===o?((e,t,n)=>{const{id:a}=e,i=t[a];n.set(a,i)})(e,i,n):((e,t,n)=>{const{id:a,items:i}=e,o=[];i.forEach(e=>{const{id:n}=e;t[n]&&o.push(n)}),o.length?n.set(a,o):n.delete(a)})(e,i,n):n.delete(t)}),t.search=decodeURIComponent(t.search),window.history.replaceState({},"",t.toString())})(t)},[t.menuState])},reducer:{initialState:{menu:[],menuState:{}},actions:{SET_MENU:(e,t)=>{const{menu:n,menuState:a}=t;return{...e,menu:n,menuState:a}},UPDATE_MENU_STATE:(e,t)=>({...e,menuState:{...e.menuState,...t}})}},panels:[{id:"menu",label:"Layers",mobile:{slot:"drawer",modal:!0,dismissible:!0},tablet:{slot:"left-top",dismissible:!0,exclusive:!0,width:"260px"},desktop:{slot:"left-top",modal:!1,dismissible:!0,exclusive:!0,width:"280px"},render:({pluginState:e,appConfig:t})=>{const{menu:n=[],dispatch:a,menuState:i}=e,u=t?.id||"map",c=n.some(e=>e.groupLabel);return o(m,{value:`${u}-menu`,children:s("div",{className:"im-c-menu"+(c?" im-c-menu--has-groups":""),children:[" ",n.map(e=>o(k,{menuGroup:e,dispatch:a,menuState:i},e.id))]})})}}],buttons:[{id:"menuButton",label:"Layers",panelId:"menu",iconId:"layersMenu",mobile:{slot:"top-left",showLabel:!0},tablet:{slot:"top-left",showLabel:!0},desktop:{slot:"top-left",showLabel:!0}}],icons:[{id:"layersMenu",svgContent:'<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"></path><path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12"></path><path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17"></path>'}]};export{S as manifest};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/defineProperty";function
|
|
1
|
+
import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/regenerator";function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){r(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function i(){var r;return o(o({noKeyItemText:"No features displayed"},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"menu",load:(r=e(t.mark(function e(){var r;return t.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,import(/* webpackChunkName: "im-menu-plugin" */ "./im-menu-plugin.js");case 1:return r=e.sent.manifest,e.abrupt("return",r);case 2:case"end":return e.stop()}},e)})),function(){return r.apply(this,arguments)})})}export{i as default};
|