@defra/interactive-map 0.0.58-alpha → 0.0.60-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 +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- 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/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/docs/plugins/draw.md +95 -13
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.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/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- 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/adapterEvents.js +2 -0
- package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
- package/plugins/draw/src/api/addFeature.js +9 -6
- package/plugins/draw/src/api/addFeature.test.js +37 -10
- package/plugins/draw/src/api/editFeature.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
- package/plugins/draw/src/api/setProperties.js +39 -0
- package/plugins/draw/src/api/setProperties.test.js +74 -0
- package/plugins/draw/src/api/setStyle.js +16 -19
- package/plugins/draw/src/api/setStyle.test.js +17 -2
- package/plugins/draw/src/api/split.js +7 -4
- package/plugins/draw/src/api/split.test.js +25 -2
- package/plugins/draw/src/events.js +95 -53
- package/plugins/draw/src/events.test.js +425 -6
- package/plugins/draw/src/manifest.js +6 -4
- package/plugins/draw/src/manifest.test.js +20 -26
- package/plugins/draw/src/reducer.js +7 -0
- package/plugins/draw/src/reducer.test.js +11 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
- package/plugins/draw/src/utils/isPlainObject.js +14 -0
- package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
- package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
- package/plugins/draw/src/validation/commitChecks.js +29 -11
- package/plugins/draw/src/validation/commitChecks.test.js +67 -11
- package/plugins/draw/src/validation/validateGeometry.js +12 -5
- package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- 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/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- 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/src/maplibreProvider.js +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/MapProvider.jsx +1 -0
- package/src/App/store/MapProvider.test.jsx +25 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/App/store/mapActionsMap.js +6 -0
- package/src/App/store/mapActionsMap.test.js +7 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +2 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +29 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -3,66 +3,101 @@ import { useResizeObserver } from './useResizeObserver.js'
|
|
|
3
3
|
import { useApp } from '../store/appContext.js'
|
|
4
4
|
import { useMap } from '../store/mapContext.js'
|
|
5
5
|
import { getSafeZoneInset } from '../../utils/getSafeZoneInset.js'
|
|
6
|
+
import { renderedBoxes, topColHeight } from '../../utils/renderedBoxes.js'
|
|
6
7
|
|
|
7
8
|
const BANNER_DOCKED_CLASS = 'im-o-app__banner--docked'
|
|
8
9
|
const BANNER_PANEL_SELECTOR = '.im-c-panel--banner'
|
|
9
10
|
const ATTRIBUTIONS_STACKED_CLASS = 'im-o-app__attributions--stacked'
|
|
11
|
+
const TOP_WRAPPED_CLASS = 'im-o-app__top--wrapped'
|
|
12
|
+
const SUBPIXEL_TOLERANCE = 1
|
|
10
13
|
|
|
11
14
|
const buttonHeight = (ref) => ref?.current?.offsetHeight ?? 0
|
|
12
15
|
const buttonWidth = (ref) => ref?.current?.offsetWidth ?? 0
|
|
13
16
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return element.classList.contains('im-c-control-wrapper') && Array.from(element.children).some(isRendered)
|
|
17
|
+
// The wider of the two sides, so centred content stays in the middle.
|
|
18
|
+
const symmetricWidth = (left, right) => left || right ? Math.max(left, right) : 0
|
|
19
|
+
|
|
20
|
+
// The top of the highest of these bottom row elements that shows, relative to main, or null if none
|
|
21
|
+
// do. Measured from the page, as they're nested at different depths in the row.
|
|
22
|
+
const bottomRowTop = (mainRect, elements) => {
|
|
23
|
+
const tops = elements.filter(element => element?.offsetHeight).map(element => element.getBoundingClientRect().top - mainRect.top)
|
|
24
|
+
return tops.length ? Math.min(...tops) : null
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
return
|
|
27
|
+
// Keeps the keyboard hint just above the bottom-left column (the logo and bottom-left buttons) and
|
|
28
|
+
// attributions, ignoring the bottom-right slot so opening the map controls doesn't move it. It also
|
|
29
|
+
// clears the actions bar, and anything below the bottom row, such as the drawer on mobile.
|
|
30
|
+
const hintBottom = ({ main, mainRect, bottom, bottomLeftCol, attributions, actionsEl, gap }) => {
|
|
31
|
+
const rowTop = bottomRowTop(mainRect, [bottomLeftCol, attributions]) ?? bottom.offsetTop + bottom.offsetHeight
|
|
32
|
+
const actionsOffset = actionsEl?.offsetHeight ? main.offsetHeight - actionsEl.offsetTop : 0
|
|
33
|
+
return Math.max(main.offsetHeight - rowTop, actionsOffset) + gap
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
const
|
|
36
|
+
const actionsBarRect = (actionsEl) => {
|
|
37
|
+
const bar = actionsEl?.querySelector('.im-c-actions')
|
|
38
|
+
return bar?.offsetHeight ? bar.getBoundingClientRect() : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A sub-slot with only hidden items still has a box, so the column would leave a gap next to it.
|
|
42
|
+
// Only add the gap when both sub-slots show something.
|
|
43
|
+
const slotHasContent = (ref) => renderedBoxes(ref?.current).length > 0
|
|
44
|
+
|
|
45
|
+
const subSlotGap = (topRef, bottomRef, gap) => slotHasContent(topRef) && slotHasContent(bottomRef) ? gap : 0
|
|
46
|
+
|
|
47
|
+
const columnContentHeight = (topRef, bottomRef, gap) => buttonHeight(topRef) + buttonHeight(bottomRef) + subSlotGap(topRef, bottomRef, gap)
|
|
48
|
+
|
|
49
|
+
// How far the actions bar's top is above the bottom of main, when anything in the sub-slot would
|
|
50
|
+
// overlap the bar, or come within margin of it: in line with it and reaching down to it. Otherwise 0.
|
|
51
|
+
// Measured with the side columns as they'd be without the bar (see applyColumnLayout). The sub-slot
|
|
52
|
+
// itself is as wide as the column, so what it shows is measured instead.
|
|
53
|
+
const actionsBarOverlap = (mainRect, barRect, slotRef, margin) => {
|
|
54
|
+
if (!barRect) {
|
|
55
|
+
return 0
|
|
56
|
+
}
|
|
57
|
+
const isInLine = (box) => barRect.left - margin < box.right && barRect.right + margin > box.left
|
|
58
|
+
const reachesBar = (box) => box.bottom > barRect.top - margin
|
|
59
|
+
const isOverlapping = renderedBoxes(slotRef?.current).some(box => isInLine(box) && reachesBar(box))
|
|
60
|
+
return isOverlapping ? mainRect.bottom - barRect.top : 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// On tablet and desktop the actions bar floats over the middle of the map. Only what would
|
|
64
|
+
// overlap it moves: a bottom sub-slot lifts the whole column above the bar, and a top sub-slot
|
|
65
|
+
// is capped above the bar, so the bottom sub-slot stays where it is. On mobile the bar is below
|
|
66
|
+
// the bottom row, so it never moves a column.
|
|
67
|
+
const clearActionsBar = ({ mainRect, barRect, mainHeight, baseOffsetBottom, offsetTop, topRef, bottomRef, gap }) => {
|
|
68
|
+
const topOverlap = actionsBarOverlap(mainRect, barRect, topRef, gap)
|
|
69
|
+
const bottomOverlap = actionsBarOverlap(mainRect, barRect, bottomRef, gap)
|
|
70
|
+
return {
|
|
71
|
+
offsetBottom: bottomOverlap > 0 ? Math.max(baseOffsetBottom, bottomOverlap + gap) : baseOffsetBottom,
|
|
72
|
+
topSlotMaxHeight: topOverlap > 0 ? `${Math.max(0, mainHeight - topOverlap - gap - offsetTop)}px` : 'none'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Clears the bottom row's own TOP edge (not just its trailing gap below), so the hint
|
|
49
|
-
// never overlaps the logo/attribution row itself, plus a gap above it. That trivially
|
|
50
|
-
// also clears anything after the row in flow — mobile's in-flow actions bar included.
|
|
51
|
-
// Tablet/desktop's floating actions bar can sit independently higher than the row, so
|
|
52
|
-
// still needs its own explicit clearance, hence the Math.max with actionsOffset below.
|
|
53
|
-
const hintBottom = (main, bottom, actionsEl, gap) => {
|
|
54
|
-
const clearsBottomRow = main.offsetHeight - bottom.offsetTop + gap
|
|
55
|
-
const actionsHeight = actionsEl?.offsetHeight ?? 0
|
|
56
|
-
const actionsOffset = actionsHeight > 0 ? main.offsetHeight - actionsEl.offsetTop : 0
|
|
57
|
-
return Math.max(clearsBottomRow, actionsOffset + gap)
|
|
76
|
+
// How far the actions bar, the last thing in main, runs past the bottom of main.
|
|
77
|
+
const flowOverflow = (main, actions) => {
|
|
78
|
+
if (!actions) {
|
|
79
|
+
return 0
|
|
80
|
+
}
|
|
81
|
+
const mainRect = main.getBoundingClientRect()
|
|
82
|
+
const marginBottom = Number.parseFloat(getComputedStyle(actions).marginBottom) || 0
|
|
83
|
+
const paddingBottom = Number.parseFloat(getComputedStyle(main).paddingBottom) || 0
|
|
84
|
+
return Math.max(0, actions.getBoundingClientRect().bottom + marginBottom - (mainRect.bottom - paddingBottom))
|
|
58
85
|
}
|
|
59
86
|
|
|
60
|
-
//
|
|
87
|
+
// On mobile the drawer sits below the map, but the side columns float over the map, so a tall
|
|
88
|
+
// drawer would squeeze them until their buttons sit under it, then run off the bottom. Its max
|
|
89
|
+
// height is its own height plus the space left in the fuller side column, less any overflow, so
|
|
90
|
+
// it stops just short of both, and grows again when there's room.
|
|
91
|
+
const drawerMaxHeight = (drawerRef, columnSlack, overflow) => slotHasContent(drawerRef)
|
|
92
|
+
? `${Math.max(0, Math.floor(drawerRef.current.offsetHeight + columnSlack - overflow))}px`
|
|
93
|
+
: 'none'
|
|
94
|
+
|
|
95
|
+
// The space between the side columns, where a centred banner goes.
|
|
61
96
|
const bannerGutterWidth = (mainWidth, sideColWidth, gap) => mainWidth - (sideColWidth * 2) - (gap * 2)
|
|
62
97
|
|
|
63
98
|
const isBannerDocked = (gutterWidth, preferredWidth) => gutterWidth >= preferredWidth
|
|
64
99
|
|
|
65
|
-
//
|
|
100
|
+
// The widest width set on a banner panel, if any, used instead of the default.
|
|
66
101
|
const bannerConfiguredWidth = (bannerEl) => {
|
|
67
102
|
const widths = Array.from(bannerEl?.querySelectorAll(BANNER_PANEL_SELECTOR) ?? [])
|
|
68
103
|
.map(el => Number.parseInt(el.style.width, 10))
|
|
@@ -70,19 +105,17 @@ const bannerConfiguredWidth = (bannerEl) => {
|
|
|
70
105
|
return widths.length ? Math.max(...widths) : null
|
|
71
106
|
}
|
|
72
107
|
|
|
73
|
-
//
|
|
108
|
+
// On mobile the banner is always full width, so remove any width set on its panels.
|
|
74
109
|
const clearBannerPanelWidths = (bannerEl) => {
|
|
75
110
|
bannerEl?.querySelectorAll(BANNER_PANEL_SELECTOR).forEach(el => { el.style.width = '' })
|
|
76
111
|
}
|
|
77
112
|
|
|
78
|
-
//
|
|
113
|
+
// A centred banner is inset by the side column width; a full-width one isn't.
|
|
79
114
|
const bannerInset = (isDocked, primaryGap, sideColWidth, gap) =>
|
|
80
115
|
isDocked ? primaryGap + sideColWidth + gap : primaryGap
|
|
81
116
|
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
// clearBannerPanelWidths/bannerConfiguredWidth above. Needed because once wrapping is
|
|
85
|
-
// allowed, scrollWidth alone can't tell us how wide the text *would* be on one line.
|
|
117
|
+
// The width of the attribution text on one line. Turns wrapping off just long enough to measure
|
|
118
|
+
// it, then turns it back on.
|
|
86
119
|
const attributionsNaturalWidth = (attributionsEl) => {
|
|
87
120
|
const textEl = attributionsEl?.firstElementChild
|
|
88
121
|
if (!textEl) {
|
|
@@ -95,30 +128,15 @@ const attributionsNaturalWidth = (attributionsEl) => {
|
|
|
95
128
|
return width
|
|
96
129
|
}
|
|
97
130
|
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
// margin-bottom (--bottom-right-clearance) to stay clear of it;
|
|
108
|
-
// - stacked: the box is an extra flex line *below* the row, so it lifts the row by exactly
|
|
109
|
-
// that much on its own — no margin needed, hence bottomRightClearance's isStacked branch.
|
|
110
|
-
// Either way .im-o-app__right must clear the lift, so the offsets below use this, not the
|
|
111
|
-
// clearance. Clamped at 0: a box shorter than its own bleed lifts nothing.
|
|
112
|
-
const attributionsRise = (attributionsHeight, dividerGap, primaryGap) =>
|
|
113
|
-
Math.max(0, attributionsHeight + dividerGap - primaryGap)
|
|
114
|
-
|
|
115
|
-
// Stacked gets its lift from the extra flex line itself (see attributionsRise above), so only
|
|
116
|
-
// docked needs the row pushed up by a margin.
|
|
117
|
-
const bottomRightClearance = (isStacked, rise) => isStacked ? 0 : rise
|
|
118
|
-
|
|
119
|
-
// Docks centred between the side columns when there's room, otherwise stacks full-width
|
|
120
|
-
// (mobile always stacks). Sets the banner's own CSS vars and returns what the side-column
|
|
121
|
-
// offset calc below needs.
|
|
131
|
+
// Lets the top row's columns wrap once they no longer fit on one line. Measured without the class,
|
|
132
|
+
// so the row's natural width decides, rather than how it's currently wrapped.
|
|
133
|
+
function applyTopRowLayout (top) {
|
|
134
|
+
top.classList.remove(TOP_WRAPPED_CLASS)
|
|
135
|
+
top.classList.toggle(TOP_WRAPPED_CLASS, top.scrollWidth > top.clientWidth + SUBPIXEL_TOLERANCE)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Centres the banner between the side columns when there's room, otherwise puts it on its own
|
|
139
|
+
// full-width row (always on mobile). Returns what the side column offsets below need.
|
|
122
140
|
function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, rightRef, isMobile, dividerGap, primaryGap }) {
|
|
123
141
|
const banner = bannerRef?.current
|
|
124
142
|
if (isMobile) {
|
|
@@ -138,7 +156,7 @@ function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, right
|
|
|
138
156
|
appContainer.style.setProperty('--banner-left', bannerSideInset)
|
|
139
157
|
appContainer.style.setProperty('--banner-right', bannerSideInset)
|
|
140
158
|
|
|
141
|
-
// Sits
|
|
159
|
+
// Sits just below the top row, which already includes a gap at the bottom.
|
|
142
160
|
const isBannerStacked = hasBanner && !isDocked
|
|
143
161
|
const bannerTop = hasBanner ? top.offsetTop + top.offsetHeight : 0
|
|
144
162
|
appContainer.style.setProperty('--banner-top', `${bannerTop}px`)
|
|
@@ -146,41 +164,58 @@ function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, right
|
|
|
146
164
|
return { isBannerStacked, bannerTop, bannerHeight }
|
|
147
165
|
}
|
|
148
166
|
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const attributionsCol = bottom.children[1] // the bottom-right column, a DOM sibling of attributions
|
|
156
|
-
const isStacked = isAttributionsStacked(attributionsNaturalWidth(attributions), attributionsCol?.offsetWidth ?? 0)
|
|
167
|
+
// Puts the attributions beside the logo when they fit, otherwise on their own row below, which
|
|
168
|
+
// pushes the logo and bottom-right buttons up. Docked, they grow up beside the bottom-right buttons,
|
|
169
|
+
// so the buttons need a bottom margin to clear them. Stacked, they're a row below the buttons, which
|
|
170
|
+
// lifts them by the same amount without a margin.
|
|
171
|
+
function applyAttributionsLayout ({ appContainer, bottom, attributionsCol, attributions, dividerGap, primaryGap }) {
|
|
172
|
+
const isStacked = attributionsNaturalWidth(attributions) > (attributionsCol?.offsetWidth ?? 0)
|
|
157
173
|
attributions.classList.toggle(ATTRIBUTIONS_STACKED_CLASS, isStacked)
|
|
158
|
-
//
|
|
159
|
-
// space-between` gap between the two columns isn't a fixed value (unlike `gap`) to reconstruct.
|
|
174
|
+
// Measured from the page, because the space between the two bottom columns isn't a fixed gap.
|
|
160
175
|
const left = attributionsCol ? Math.round(attributionsCol.getBoundingClientRect().left - bottom.getBoundingClientRect().left) : 0
|
|
161
176
|
appContainer.style.setProperty('--attributions-left', `${left}px`)
|
|
162
|
-
const
|
|
163
|
-
appContainer.style.setProperty('--bottom-right-clearance', `${
|
|
164
|
-
|
|
177
|
+
const clearance = isStacked ? 0 : Math.max(0, attributions.offsetHeight + dividerGap - primaryGap)
|
|
178
|
+
appContainer.style.setProperty('--bottom-right-clearance', `${clearance}px`)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Places the side columns. Each runs from below the top row to a gap above what's shown on its own
|
|
182
|
+
// side of the bottom row, or to main's bottom padding when nothing is. They're put there without the
|
|
183
|
+
// actions bar's lift or cap before measuring what would overlap the bar. Otherwise moving something
|
|
184
|
+
// clear of the bar would change whether it needs to move, and the next measurement would undo it.
|
|
185
|
+
// The browser doesn't draw this in-between layout. Returns the room left below each column's content.
|
|
186
|
+
function applyColumnLayout ({ appContainer, main, actions, columns, gap }) {
|
|
187
|
+
const setColumn = (side, name, value) => appContainer.style.setProperty(`--${side}-${name}`, value)
|
|
188
|
+
Object.entries(columns).forEach(([side, { offsetTop, baseOffsetBottom, topRef, bottomRef }]) => {
|
|
189
|
+
setColumn(side, 'offset-top', `${offsetTop}px`)
|
|
190
|
+
setColumn(side, 'offset-bottom', `${baseOffsetBottom}px`)
|
|
191
|
+
setColumn(side, 'top-slot-max-height', 'none')
|
|
192
|
+
setColumn(side, 'slot-gap', `${subSlotGap(topRef, bottomRef, gap)}px`)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const mainRect = main.getBoundingClientRect()
|
|
196
|
+
const barRect = actionsBarRect(actions)
|
|
197
|
+
return Object.entries(columns).map(([side, { offsetTop, baseOffsetBottom, topRef, bottomRef }]) => {
|
|
198
|
+
const bar = clearActionsBar({ mainRect, barRect, mainHeight: main.offsetHeight, baseOffsetBottom, offsetTop, topRef, bottomRef, gap })
|
|
199
|
+
setColumn(side, 'offset-bottom', `${bar.offsetBottom}px`)
|
|
200
|
+
setColumn(side, 'top-slot-max-height', bar.topSlotMaxHeight)
|
|
201
|
+
return main.offsetHeight - bar.offsetBottom - offsetTop - columnContentHeight(topRef, bottomRef, gap)
|
|
202
|
+
})
|
|
165
203
|
}
|
|
166
204
|
|
|
167
205
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* button visibility rather than a mid-evaluation state, which would make the map jump.
|
|
206
|
+
* Sets the layout CSS variables for the map overlay and the safe zone used by `fitBounds` and
|
|
207
|
+
* `setView`. Waits until plugins are evaluated, so the map doesn't jump while buttons appear.
|
|
171
208
|
*/
|
|
172
209
|
export function calculateLayout (layoutRefs, breakpoint) {
|
|
173
210
|
const {
|
|
174
211
|
appContainerRef, mainRef, topRef, topLeftColRef, topRightColRef,
|
|
175
|
-
bottomRef,
|
|
176
|
-
rightTopRef, rightBottomRef, actionsRef, bannerRef, leftRef, rightRef
|
|
212
|
+
bottomRef, bottomLeftColRef, bottomRightColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef,
|
|
213
|
+
rightTopRef, rightBottomRef, drawerRef, actionsRef, bannerRef, leftRef, rightRef
|
|
177
214
|
} = layoutRefs
|
|
178
215
|
|
|
179
216
|
const appContainer = appContainerRef.current
|
|
180
217
|
const main = mainRef.current
|
|
181
218
|
const top = topRef.current
|
|
182
|
-
const topLeftCol = topLeftColRef.current
|
|
183
|
-
const topRightCol = topRightColRef.current
|
|
184
219
|
const bottom = bottomRef.current
|
|
185
220
|
const attributions = attributionsRef.current
|
|
186
221
|
|
|
@@ -189,63 +224,72 @@ export function calculateLayout (layoutRefs, breakpoint) {
|
|
|
189
224
|
}
|
|
190
225
|
|
|
191
226
|
const root = document.documentElement
|
|
192
|
-
const
|
|
193
|
-
const
|
|
227
|
+
const rootStyle = getComputedStyle(root)
|
|
228
|
+
const dividerGap = Number.parseInt(rootStyle.getPropertyValue('--divider-gap'), 10)
|
|
229
|
+
const primaryGap = Number.parseInt(rootStyle.getPropertyValue('--primary-gap'), 10)
|
|
194
230
|
|
|
195
|
-
|
|
196
|
-
|
|
231
|
+
applyTopRowLayout(top)
|
|
232
|
+
|
|
233
|
+
// Banner: centred between the side columns when there's room, otherwise full width
|
|
197
234
|
const isMobile = breakpoint === 'mobile'
|
|
198
235
|
const { isBannerStacked, bannerTop, bannerHeight } = applyBannerLayout({
|
|
199
236
|
appContainer, root, top, bannerRef, leftRef, rightRef, isMobile, dividerGap, primaryGap
|
|
200
237
|
})
|
|
201
238
|
|
|
202
|
-
//
|
|
203
|
-
//
|
|
239
|
+
// A full-width banner pushes the side columns down below it. Done here rather than in CSS,
|
|
240
|
+
// because closed panels stay in the page, hidden.
|
|
204
241
|
const sideOffsetTop = (colHeight) => isBannerStacked
|
|
205
242
|
? bannerTop + bannerHeight + dividerGap
|
|
206
243
|
: colHeight + top.offsetTop
|
|
207
244
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
245
|
+
applyAttributionsLayout({ appContainer, bottom, attributionsCol: bottomRightColRef?.current, attributions, dividerGap, primaryGap })
|
|
246
|
+
|
|
247
|
+
const actions = actionsRef?.current
|
|
248
|
+
const bottomLeftCol = bottomLeftColRef?.current
|
|
249
|
+
const mainRect = main.getBoundingClientRect()
|
|
250
|
+
// A gap above what's shown on that side of the bottom row, else main's bottom padding. Docked
|
|
251
|
+
// attributions sit on the right; stacked ones run the full width
|
|
252
|
+
const containerPad = main.offsetHeight - bottom.offsetTop - bottom.offsetHeight
|
|
253
|
+
const baseOffsetBottom = (rowElements) => {
|
|
254
|
+
const rowTop = bottomRowTop(mainRect, rowElements)
|
|
255
|
+
return rowTop === null ? containerPad : main.offsetHeight - rowTop + dividerGap
|
|
256
|
+
}
|
|
257
|
+
const isStacked = attributions.classList.contains(ATTRIBUTIONS_STACKED_CLASS)
|
|
258
|
+
const columns = {
|
|
259
|
+
left: {
|
|
260
|
+
offsetTop: sideOffsetTop(topColHeight(topLeftColRef.current)),
|
|
261
|
+
baseOffsetBottom: baseOffsetBottom([bottomLeftCol, isStacked && attributions]),
|
|
262
|
+
topRef: leftTopRef,
|
|
263
|
+
bottomRef: leftBottomRef
|
|
264
|
+
},
|
|
265
|
+
right: {
|
|
266
|
+
offsetTop: sideOffsetTop(topColHeight(topRightColRef.current)),
|
|
267
|
+
baseOffsetBottom: baseOffsetBottom([bottomRightRef?.current, attributions]),
|
|
268
|
+
topRef: rightTopRef,
|
|
269
|
+
bottomRef: rightBottomRef
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const columnSlack = applyColumnLayout({ appContainer, main, actions, columns, gap: dividerGap })
|
|
273
|
+
|
|
274
|
+
// === Drawer max height ===
|
|
275
|
+
appContainer.style.setProperty('--drawer-max-height', drawerMaxHeight(drawerRef, Math.min(...columnSlack), flowOverflow(main, actions)))
|
|
226
276
|
|
|
227
277
|
// === Keyboard hint bottom offset ===
|
|
228
|
-
appContainer.style.setProperty('--hint-bottom', `${hintBottom(main, bottom,
|
|
229
|
-
|
|
230
|
-
// === Sub-slot panel max-heights ===
|
|
231
|
-
appContainer.style.setProperty('--left-top-panel-max-height', `${subSlotMaxHeight(leftColumnHeight, buttonHeight(leftBottomRef), dividerGap)}px`)
|
|
232
|
-
appContainer.style.setProperty('--left-bottom-panel-max-height', `${subSlotMaxHeight(leftColumnHeight, buttonHeight(leftTopRef), dividerGap)}px`)
|
|
233
|
-
appContainer.style.setProperty('--right-top-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightBottomRef), dividerGap)}px`)
|
|
234
|
-
appContainer.style.setProperty('--right-bottom-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightTopRef), dividerGap)}px`)
|
|
278
|
+
appContainer.style.setProperty('--hint-bottom', `${hintBottom({ main, mainRect, bottom, bottomLeftCol, attributions, actionsEl: actions, gap: dividerGap })}px`)
|
|
235
279
|
}
|
|
236
280
|
|
|
237
281
|
export function useLayoutMeasurements () {
|
|
238
282
|
const { dispatch, breakpoint, layoutRefs, arePluginsEvaluated, appVisible, isFullscreen } = useApp()
|
|
239
283
|
const { mapSize, isMapReady } = useMap()
|
|
240
284
|
|
|
241
|
-
const { bannerRef, mainRef, headerRef, topRef, topLeftColRef, topRightColRef, bottomRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, actionsRef, leftRef, rightRef } = layoutRefs
|
|
285
|
+
const { bannerRef, mainRef, headerRef, topRef, topLeftColRef, topMiddleColRef, topRightColRef, bottomRef, bottomLeftColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, actionsRef, leftRef, rightRef } = layoutRefs
|
|
242
286
|
|
|
243
|
-
// 1.
|
|
287
|
+
// 1. When the layout changes, wait for plugins to be evaluated again before setting the safe zone.
|
|
244
288
|
useLayoutEffect(() => {
|
|
245
289
|
dispatch({ type: 'CLEAR_PLUGINS_EVALUATED' })
|
|
246
290
|
}, [breakpoint, mapSize, isMapReady, appVisible, isFullscreen])
|
|
247
291
|
|
|
248
|
-
// 2. Once
|
|
292
|
+
// 2. Once they are, set the layout and the safe zone on the next frame, after the page has updated.
|
|
249
293
|
useLayoutEffect(() => {
|
|
250
294
|
if (!arePluginsEvaluated) {
|
|
251
295
|
return
|
|
@@ -259,12 +303,12 @@ export function useLayoutMeasurements () {
|
|
|
259
303
|
})
|
|
260
304
|
}, [arePluginsEvaluated])
|
|
261
305
|
|
|
262
|
-
// 3.
|
|
263
|
-
// Memoized so
|
|
306
|
+
// 3. Set the layout again whenever any of these change size. The safe zone is left to step 2.
|
|
307
|
+
// Memoized so the observer isn't set up again on every render.
|
|
264
308
|
const observedRefs = useMemo(
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
() => [bannerRef, mainRef, headerRef, topRef, topLeftColRef, topRightColRef, actionsRef, bottomRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, leftRef, rightRef],
|
|
309
|
+
// Includes the attributions, which change height when their text wraps, and the bottom-left
|
|
310
|
+
// column, which changes size when the logo loads or its buttons change
|
|
311
|
+
() => [bannerRef, mainRef, headerRef, topRef, topLeftColRef, topMiddleColRef, topRightColRef, actionsRef, bottomRef, bottomLeftColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, leftRef, rightRef],
|
|
268
312
|
[]
|
|
269
313
|
)
|
|
270
314
|
|