@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.
Files changed (140) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/panel-definition.md +30 -0
  9. package/docs/api/symbol-config.md +12 -0
  10. package/docs/api.md +21 -2
  11. package/docs/assets/images/slot-map.svg +3 -3
  12. package/docs/plugins/datasets.md +11 -1
  13. package/docs/plugins/draw.md +95 -13
  14. package/package.json +1 -1
  15. package/plugins/datasets/dist/esm/index.js +1 -1
  16. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  17. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  18. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  20. package/plugins/datasets/dist/umd/index.js +1 -1
  21. package/plugins/datasets/src/index.js +0 -1
  22. package/plugins/datasets/src/index.test.js +2 -8
  23. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  24. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  25. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  26. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  27. package/plugins/draw/dist/esm/index.js +1 -1
  28. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  29. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  30. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  31. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  32. package/plugins/draw/dist/umd/index.js +1 -1
  33. package/plugins/draw/src/adapterEvents.js +2 -0
  34. package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
  35. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
  36. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  37. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
  38. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
  39. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
  40. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
  41. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
  42. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
  43. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
  44. package/plugins/draw/src/api/addFeature.js +9 -6
  45. package/plugins/draw/src/api/addFeature.test.js +37 -10
  46. package/plugins/draw/src/api/editFeature.js +1 -1
  47. package/plugins/draw/src/api/recheckGeometry.js +1 -1
  48. package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
  49. package/plugins/draw/src/api/setProperties.js +39 -0
  50. package/plugins/draw/src/api/setProperties.test.js +74 -0
  51. package/plugins/draw/src/api/setStyle.js +16 -19
  52. package/plugins/draw/src/api/setStyle.test.js +17 -2
  53. package/plugins/draw/src/api/split.js +7 -4
  54. package/plugins/draw/src/api/split.test.js +25 -2
  55. package/plugins/draw/src/events.js +95 -53
  56. package/plugins/draw/src/events.test.js +425 -6
  57. package/plugins/draw/src/manifest.js +6 -4
  58. package/plugins/draw/src/manifest.test.js +20 -26
  59. package/plugins/draw/src/reducer.js +7 -0
  60. package/plugins/draw/src/reducer.test.js +11 -0
  61. package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
  62. package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
  63. package/plugins/draw/src/utils/isPlainObject.js +14 -0
  64. package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
  65. package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
  66. package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
  67. package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
  68. package/plugins/draw/src/validation/commitChecks.js +29 -11
  69. package/plugins/draw/src/validation/commitChecks.test.js +67 -11
  70. package/plugins/draw/src/validation/validateGeometry.js +12 -5
  71. package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
  72. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  73. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  74. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  75. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  76. package/plugins/search/dist/css/index.css +1 -1
  77. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  78. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  79. package/providers/esri/src/esriProvider.js +10 -21
  80. package/providers/esri/src/utils/coords.js +37 -7
  81. package/providers/esri/src/utils/coords.test.js +22 -1
  82. package/providers/esri/src/utils/spatial.js +1 -47
  83. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  84. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  85. package/providers/maplibre/src/maplibreProvider.js +5 -14
  86. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  87. package/providers/maplibre/src/utils/spatial.js +0 -40
  88. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  89. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  90. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  91. package/providers/openlayers/src/openlayersProvider.js +5 -14
  92. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  93. package/providers/openlayers/src/utils/spatial.js +0 -39
  94. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  95. package/src/App/components/Hints/Hints.jsx +9 -21
  96. package/src/App/components/Hints/Hints.test.jsx +20 -33
  97. package/src/App/components/Panel/Panel.jsx +16 -1
  98. package/src/App/components/Panel/Panel.test.jsx +44 -0
  99. package/src/App/hooks/useCrossHairAPI.js +27 -28
  100. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  101. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  102. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  103. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  104. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  105. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  106. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  107. package/src/App/hooks/useVisibleGeometry.js +35 -45
  108. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  109. package/src/App/layout/Layout.jsx +4 -4
  110. package/src/App/layout/layout.module.scss +124 -61
  111. package/src/App/store/AppProvider.jsx +3 -0
  112. package/src/App/store/MapProvider.jsx +1 -0
  113. package/src/App/store/MapProvider.test.jsx +25 -0
  114. package/src/App/store/appDispatchMiddleware.js +18 -10
  115. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  116. package/src/App/store/mapActionsMap.js +6 -0
  117. package/src/App/store/mapActionsMap.test.js +7 -0
  118. package/src/App/store/mapReducer.js +2 -0
  119. package/src/App/store/mapReducer.test.js +2 -0
  120. package/src/InteractiveMap/InteractiveMap.js +3 -2
  121. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  122. package/src/config/events.js +1 -1
  123. package/src/config/mapPanelSlots.js +8 -0
  124. package/src/config/symbolConfig.js +1 -1
  125. package/src/services/symbolRegistry.js +1 -1
  126. package/src/services/symbolRegistry.test.js +19 -0
  127. package/src/types.js +29 -8
  128. package/src/utils/getFitMove.js +73 -0
  129. package/src/utils/getFitMove.test.js +114 -0
  130. package/src/utils/getSafeZoneInset.js +122 -77
  131. package/src/utils/getSafeZoneInset.test.js +241 -54
  132. package/src/utils/getValueForStyle.js +10 -5
  133. package/src/utils/getValueForStyle.test.js +13 -2
  134. package/src/utils/renderedBoxes.js +25 -0
  135. package/src/utils/renderedBoxes.test.js +61 -0
  136. package/src/utils/screenBox.js +70 -0
  137. package/src/utils/screenBox.test.js +69 -0
  138. package/src/utils/symbolUtils.js +9 -9
  139. package/src/utils/symbolUtils.test.js +21 -0
  140. package/providers/esri/src/utils/spatial.test.js +0 -58
@@ -34,16 +34,19 @@ const refs = (o = {}) => ({
34
34
  bannerRef: { current: el(o.banner) },
35
35
  topRef: { current: o.top === null ? null : el({ offsetTop: 10, ...o.top }) },
36
36
  topLeftColRef: { current: el({ offsetHeight: 50, offsetWidth: 200, ...o.topLeftCol }) },
37
+ topMiddleColRef: { current: el(o.topMiddleCol) },
37
38
  topRightColRef: { current: el({ offsetHeight: 40, offsetWidth: 180, ...o.topRightCol }) },
38
39
  leftRef: { current: el(o.left) },
39
40
  rightRef: { current: el(o.right) },
40
41
  bottomRef: { current: o.bottom === null ? null : el({ offsetTop: 400, ...o.bottom }) },
42
+ bottomLeftColRef: { current: el(o.bottomLeftCol) },
43
+ bottomRightColRef: { current: el(o.bottomRightCol) },
41
44
  bottomRightRef: { current: el({ offsetTop: 400, ...o.bottomRight }) },
42
45
  leftTopRef: { current: el({ offsetHeight: 0, ...o.leftTop }) },
43
46
  leftBottomRef: { current: el({ offsetHeight: 0, ...o.leftBottom }) },
44
47
  rightTopRef: { current: el({ offsetHeight: 0, ...o.rightTop }) },
45
48
  rightBottomRef: { current: el({ offsetHeight: 0, ...o.rightBottom }) },
46
- attributionsRef: { current: el({ offsetHeight: 16, ...o.attributions }) },
49
+ attributionsRef: { current: el({ offsetHeight: 16, rect: { top: 400 }, ...o.attributions }) },
47
50
  drawerRef: { current: el(o.drawer) },
48
51
  actionsRef: { current: el({ offsetTop: 450, ...o.actions }) }
49
52
  })
@@ -77,6 +80,27 @@ describe('useLayoutMeasurements', () => {
77
80
  expect(layoutRefs.appContainerRef.current.style.setProperty).not.toHaveBeenCalled()
78
81
  })
79
82
 
83
+ test.each([
84
+ ['fits on one line', 900, 900, false],
85
+ ['is a pixel over from rounding', 901, 900, false],
86
+ ['no longer fits on one line', 960, 900, true]
87
+ ])('sets the top row wrapped class when the row %s', (_name, scrollWidth, clientWidth, isWrapped) => {
88
+ const { layoutRefs } = setup({ refs: { top: { scrollWidth, clientWidth } } })
89
+ renderHook(() => useLayoutMeasurements())
90
+ expect(layoutRefs.topRef.current.classList.contains('im-o-app__top--wrapped')).toBe(isWrapped)
91
+ })
92
+
93
+ test('measures the top row without the wrapped class, so it can go back to one line', () => {
94
+ const { layoutRefs } = setup()
95
+ const top = layoutRefs.topRef.current
96
+ top.classList.add('im-o-app__top--wrapped')
97
+ const isWrappedWhenMeasured = jest.fn(() => top.classList.contains('im-o-app__top--wrapped'))
98
+ Object.defineProperty(top, 'scrollWidth', { get: () => { isWrappedWhenMeasured(); return 0 } })
99
+ renderHook(() => useLayoutMeasurements())
100
+ expect(isWrappedWhenMeasured).toHaveReturnedWith(false)
101
+ expect(top.classList.contains('im-o-app__top--wrapped')).toBe(false)
102
+ })
103
+
80
104
  test('treats a top column whose children are all hidden as empty, ignoring its trailing padding', () => {
81
105
  const { layoutRefs } = setup({ refs: { topRightCol: { offsetHeight: 10 }, top: { offsetTop: 15 } } })
82
106
  // jsdom gives every element empty client rects, i.e. the same as display:none
@@ -124,60 +148,217 @@ describe('useLayoutMeasurements', () => {
124
148
  expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-offset-top', '65px')
125
149
  })
126
150
 
127
- test('calculates and sets all CSS custom properties', () => {
151
+ // By default the left column runs from 60 (50 + 10) to main's bottom padding (500 - 400 - 0 = 100),
152
+ // as nothing shows on its side of the bottom row. The right column runs from 50 (40 + 10) to a gap
153
+ // above the attributions at 400 (500 - 400 + 8 = 108)
154
+ test.each([
155
+ ['--left-offset-top', '60px'],
156
+ ['--left-offset-bottom', '100px'],
157
+ ['--right-offset-top', '50px'],
158
+ ['--right-offset-bottom', '108px']
159
+ ])('ends each side column above its own side of the bottom row: %s', (name, expected) => {
128
160
  const { layoutRefs } = setup()
129
161
  renderHook(() => useLayoutMeasurements())
162
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith(name, expected)
163
+ })
164
+
165
+ test('ends the left column above the bottom-left column, and the right above the bottom-right buttons', () => {
166
+ const { layoutRefs } = setup({
167
+ refs: {
168
+ bottom: { offsetTop: 250, offsetHeight: 150 },
169
+ bottomLeftCol: { offsetHeight: 40, rect: { top: 360 } },
170
+ bottomRight: { offsetHeight: 120, rect: { top: 260 } },
171
+ attributions: { offsetHeight: 0 }
172
+ }
173
+ })
174
+ renderHook(() => useLayoutMeasurements())
175
+ const spy = layoutRefs.appContainerRef.current.style.setProperty
176
+ expect(spy).toHaveBeenCalledWith('--left-offset-bottom', '148px') // 500 - 360 + 8
177
+ expect(spy).toHaveBeenCalledWith('--right-offset-bottom', '248px') // 500 - 260 + 8
178
+ })
179
+
180
+ test('ends the right column above the bottom-right buttons themselves when the logo is taller', () => {
181
+ // The bottom-right slot is nested in a positioned column, so it's measured from the page
182
+ const { layoutRefs } = setup({
183
+ refs: {
184
+ bottomLeftCol: { offsetHeight: 60, rect: { top: 420 } },
185
+ bottomRight: { offsetHeight: 40, rect: { top: 440 } },
186
+ attributions: { offsetHeight: 0 }
187
+ }
188
+ })
189
+ renderHook(() => useLayoutMeasurements())
130
190
  const spy = layoutRefs.appContainerRef.current.style.setProperty
131
- ;['--right-offset-top', '--right-offset-bottom']
132
- .forEach(prop => expect(spy).toHaveBeenCalledWith(prop, expect.any(String)))
191
+ expect(spy).toHaveBeenCalledWith('--left-offset-bottom', '88px') // 500 - 420 + 8
192
+ expect(spy).toHaveBeenCalledWith('--right-offset-bottom', '68px') // 500 - 440 + 8
193
+ })
194
+
195
+ // The bottom-right column the attributions dock beside, 115 in from the row's left
196
+ const bottomRightCol = { offsetWidth: 192, rect: { left: 115 } }
197
+
198
+ test('ends the left column above stacked attributions, which run the full width', () => {
199
+ const { layoutRefs } = setup({ refs: { bottomRightCol } })
200
+ appendChild(layoutRefs.attributionsRef.current, { scrollWidth: 250 }) // too wide to fit beside the logo
201
+ renderHook(() => useLayoutMeasurements())
202
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--left-offset-bottom', '108px') // 500 - 400 + 8
133
203
  })
134
204
 
205
+ // With a bottom-left column at the row's top (400), the left column runs from 60 to a gap above it:
206
+ // offset bottom 500 - 400 + 8 = 108
207
+ const actionsBar = (layoutRefs, props) => {
208
+ const bar = appendChild(layoutRefs.actionsRef.current, props)
209
+ bar.className = 'im-c-actions'
210
+ }
211
+
212
+ // Without the bar the left column ends 108 above main's bottom (500), at 392. Items reach down
213
+ // to there unless a test says otherwise
214
+ const slotItem = (slotRef, rect) => appendChild(slotRef.current, { getClientRects: () => [{}], rect: { bottom: 392, ...rect } })
215
+
216
+ const bar = { offsetHeight: 60, rect: { top: 380, left: 300, right: 500 } }
217
+
135
218
  test.each([
136
- ['right-offset-top', { topRightCol: { offsetHeight: 80 }, top: { offsetTop: 15 } }, '95px'],
137
- ['right-offset-bottom', { main: { offsetHeight: 600 }, bottom: { offsetTop: 500 } }, '116px'],
138
- // leftColumnHeight = 400 - (50+10) - 8 = 332
139
- // rightColumnHeight: rightEffectiveBottom = 400 - 0 (bottomRightHeight) - 16 (bottom-right-clearance,
140
- // since default attributions offsetHeight 16 + dividerGap 8 - primaryGap 8 = 16) = 384; 384 - 50 - 8 = 326
141
- ['left-top-max-height', {}, '332px'],
142
- ['right-top-max-height', {}, '326px']
143
- ])('calculates %s correctly', (name, refOverrides, expected) => {
144
- const { layoutRefs } = setup({ refs: refOverrides })
219
+ ['bottom sub-slot in line with the bar raises the column', 'leftBottom', { left: 8, right: 320 }, bar, '128px', 'none'], // 500 - 380 + 8
220
+ ['top sub-slot in line with the bar is capped, column stays put', 'leftTop', { left: 8, right: 320 }, bar, '108px', '312px'], // bar top 380 - 8 - offset top 60
221
+ ['sub-slot clear of the bar moves nothing', 'leftBottom', { left: 8, right: 250 }, bar, '108px', 'none'],
222
+ ['sub-slot within the divider gap of the bar raises the column', 'leftBottom', { left: 8, right: 293 }, bar, '128px', 'none'], // 293 + 8 > bar left 300
223
+ ['empty bar moves nothing', 'leftBottom', { left: 8, right: 320 }, { ...bar, offsetHeight: 0 }, '108px', 'none'],
224
+ ['bar below the bottom row keeps the row clearance', 'leftBottom', { left: 8, right: 320 }, { ...bar, rect: { ...bar.rect, top: 420 } }, '108px', 'none']
225
+ ])('%s', (_name, slot, itemRect, barProps, offsetBottom, topSlotMaxHeight) => {
226
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
227
+ actionsBar(layoutRefs, barProps)
228
+ slotItem(layoutRefs[`${slot}Ref`], itemRect)
229
+ renderHook(() => useLayoutMeasurements())
230
+ const spy = layoutRefs.appContainerRef.current.style.setProperty
231
+ expect(spy).toHaveBeenCalledWith('--left-offset-bottom', offsetBottom)
232
+ expect(spy).toHaveBeenCalledWith('--left-top-slot-max-height', topSlotMaxHeight)
233
+ })
234
+
235
+ test('leaves the column when a bottom sub-slot item in line with the bar ends above it', () => {
236
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
237
+ actionsBar(layoutRefs, bar)
238
+ slotItem(layoutRefs.leftBottomRef, { left: 8, right: 320, bottom: 300 }) // 300 < bar top 380 - 8
239
+ renderHook(() => useLayoutMeasurements())
240
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--left-offset-bottom', '108px')
241
+ expect(layoutRefs.appContainerRef.current.style.setProperty).not.toHaveBeenCalledWith('--left-offset-bottom', '128px')
242
+ })
243
+
244
+ test('doesn\'t cap a top sub-slot whose wide item ends above the bar and whose long item is beside it', () => {
245
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
246
+ actionsBar(layoutRefs, bar)
247
+ slotItem(layoutRefs.leftTopRef, { left: 8, right: 320, bottom: 300 })
248
+ slotItem(layoutRefs.leftTopRef, { left: 8, right: 250, bottom: 392 })
249
+ renderHook(() => useLayoutMeasurements())
250
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--left-top-slot-max-height', 'none')
251
+ expect(layoutRefs.appContainerRef.current.style.setProperty).not.toHaveBeenCalledWith('--left-top-slot-max-height', '312px')
252
+ })
253
+
254
+ test('measures the side columns without the bar\'s lift or cap, then sets them', () => {
255
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
256
+ actionsBar(layoutRefs, bar)
257
+ slotItem(layoutRefs.leftTopRef, { left: 8, right: 320 })
258
+ slotItem(layoutRefs.leftBottomRef, { left: 8, right: 320 })
145
259
  renderHook(() => useLayoutMeasurements())
146
- const varName = `--${name.replace(/ .+/, '')}`
147
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith(varName, expected)
260
+ const calls = (name) => layoutRefs.appContainerRef.current.style.setProperty.mock.calls.filter(([prop]) => prop === name).map(([, value]) => value)
261
+ expect(calls('--left-offset-bottom')).toEqual(['108px', '128px'])
262
+ expect(calls('--left-top-slot-max-height')).toEqual(['none', '312px'])
263
+ })
264
+
265
+ test('looks through control wrappers for what a sub-slot renders', () => {
266
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
267
+ actionsBar(layoutRefs, bar)
268
+ const wrapper = appendChild(layoutRefs.rightBottomRef.current)
269
+ wrapper.className = 'im-c-control-wrapper'
270
+ appendChild(wrapper, { getClientRects: () => [{}], rect: { left: 400, right: 760, bottom: 392 } })
271
+ renderHook(() => useLayoutMeasurements())
272
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-offset-bottom', '128px')
148
273
  })
149
274
 
150
275
  test.each([
151
- ['--left-top-panel-max-height', {}, '332px'],
152
- ['--left-top-panel-max-height', { leftBottom: { offsetHeight: 50 } }, '274px'], // 332 - 50 - 8
153
- ['--left-bottom-panel-max-height', {}, '332px'],
154
- ['--left-bottom-panel-max-height', { leftTop: { offsetHeight: 40 } }, '284px'], // 332 - 40 - 8
155
- // rightColumnHeight is 326 by default here (see the right-top-max-height case above)
156
- ['--right-top-panel-max-height', {}, '326px'],
157
- ['--right-top-panel-max-height', { rightBottom: { offsetHeight: 60 } }, '258px'], // 326 - 60 - 8
158
- ['--right-bottom-panel-max-height', {}, '326px'],
159
- ['--right-bottom-panel-max-height', { rightTop: { offsetHeight: 30 } }, '288px'] // 326 - 30 - 8
160
- ])('calculates %s with sibling buttons=%o correctly', (varName, refOverrides, expected) => {
161
- const { layoutRefs } = setup({ refs: refOverrides })
276
+ ['with the hidden attribute', { getClientRects: () => [{}], hidden: true }],
277
+ // jsdom gives every element empty client rects, i.e. the same as display:none
278
+ ['with display: none', {}]
279
+ ])('ignores sub-slot items %s when checking the actions bar', (_name, props) => {
280
+ const { layoutRefs } = setup({ refs: { main: { rect: { bottom: 500 } }, bottomLeftCol: { offsetHeight: 10, rect: { top: 400 } } } })
281
+ actionsBar(layoutRefs, bar)
282
+ appendChild(layoutRefs.rightTopRef.current, { rect: { left: 400, right: 760 }, ...props })
283
+ appendChild(layoutRefs.rightBottomRef.current, { rect: { left: 400, right: 760 }, ...props })
162
284
  renderHook(() => useLayoutMeasurements())
163
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith(varName, expected)
285
+ const spy = layoutRefs.appContainerRef.current.style.setProperty
286
+ expect(spy).toHaveBeenCalledWith('--right-offset-bottom', '108px') // a gap above the attributions at 400
287
+ expect(spy).toHaveBeenCalledWith('--right-top-slot-max-height', 'none')
164
288
  })
165
289
 
166
290
  test.each([
291
+ ['both sub-slots render', true, true, '8px'],
292
+ ['only the top sub-slot renders', true, false, '0px'],
293
+ ['only the bottom sub-slot renders', false, true, '0px']
294
+ ])('sets the sub-slot gap when %s', (_name, isTopRendered, isBottomRendered, expected) => {
295
+ const { layoutRefs } = setup()
296
+ // jsdom gives every element empty client rects, i.e. the same as display:none
297
+ appendChild(layoutRefs.rightTopRef.current, isTopRendered ? { getClientRects: () => [{}] } : {})
298
+ appendChild(layoutRefs.rightBottomRef.current, isBottomRendered ? { getClientRects: () => [{}] } : {})
299
+ renderHook(() => useLayoutMeasurements())
300
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-slot-gap', expected)
301
+ })
302
+
303
+ test('copes with missing sub-slot and drawer elements', () => {
304
+ const { layoutRefs } = setup()
305
+ layoutRefs.leftTopRef.current = null
306
+ layoutRefs.leftBottomRef.current = null
307
+ layoutRefs.rightTopRef.current = null
308
+ layoutRefs.rightBottomRef.current = null
309
+ layoutRefs.drawerRef.current = null
310
+ renderHook(() => useLayoutMeasurements())
311
+ const spy = layoutRefs.appContainerRef.current.style.setProperty
312
+ expect(spy).toHaveBeenCalledWith('--right-slot-gap', '0px')
313
+ expect(spy).toHaveBeenCalledWith('--left-top-slot-max-height', 'none')
314
+ expect(spy).toHaveBeenCalledWith('--drawer-max-height', 'none')
315
+ })
316
+
317
+ // Default column heights: left 340, right 342, both empty
318
+ test.each([
319
+ ['grows into the spare room left in the tighter side column', {}, '440px'], // 100 + 340
320
+ ['stops short of the side column buttons', { rightBottom: { offsetHeight: 300 } }, '142px'], // 100 + (342 - 300)
321
+ ['shrinks when the side column buttons no longer fit', { rightBottom: { offsetHeight: 400 } }, '42px'], // 100 + (342 - 400)
322
+ ['shrinks by what runs past the bottom of main', { main: { rect: { bottom: 500 } }, actions: { offsetTop: 450, rect: { bottom: 540 } }, rightBottom: { offsetHeight: 300 } }, '102px'] // 142 - 40
323
+ ])('drawer max height %s', (_name, refOverrides, expected) => {
324
+ const { layoutRefs } = setup({ refs: { drawer: { offsetHeight: 100 }, ...refOverrides } })
325
+ appendChild(layoutRefs.drawerRef.current, { getClientRects: () => [{}] })
326
+ renderHook(() => useLayoutMeasurements())
327
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--drawer-max-height', expected)
328
+ })
329
+
330
+ test('drawer has no max height when nothing in it renders', () => {
331
+ const { layoutRefs } = setup({ refs: { drawer: { offsetHeight: 0 } } })
332
+ renderHook(() => useLayoutMeasurements())
333
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--drawer-max-height', 'none')
334
+ })
335
+
336
+ test('calculates the right column\'s top below the top row', () => {
337
+ const { layoutRefs } = setup({ refs: { topRightCol: { offsetHeight: 80 }, top: { offsetTop: 15 } } })
338
+ renderHook(() => useLayoutMeasurements())
339
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-offset-top', '95px')
340
+ })
341
+
342
+ test.each([
343
+ [
344
+ 'no actions (height 0) — sits above the attributions, ignoring the bottom-right slot',
345
+ { main: { offsetHeight: 500 }, bottom: { offsetTop: 300, offsetHeight: 192 }, attributions: { offsetHeight: 16, rect: { top: 476 } }, actions: { offsetTop: 450, offsetHeight: 0 } },
346
+ '32px' // attributions top 476; 500 - 476 + dividerGap (8) = 32
347
+ ],
167
348
  [
168
- 'no actions (height 0) — clears the bottom row',
169
- { main: { offsetHeight: 500 }, bottom: { offsetTop: 400 }, actions: { offsetTop: 450, offsetHeight: 0 } },
170
- '108px' // clearsBottomRow = 500 - 400 + dividerGap (8) = 108
349
+ 'a logo or bottom-left buttons — sits above the bottom-left column when it is higher than the attributions',
350
+ { main: { offsetHeight: 500 }, bottom: { offsetTop: 300, offsetHeight: 192 }, bottomLeftCol: { offsetHeight: 40, rect: { top: 452 } }, attributions: { offsetHeight: 16, rect: { top: 476 } }, actions: { offsetTop: 450, offsetHeight: 0 } },
351
+ '56px' // bottom-left column top 452; 500 - 452 + dividerGap (8) = 56
171
352
  ],
172
353
  [
173
354
  'actions floating above the row (tablet/desktop) — uses actionsOffset + dividerGap',
174
- { main: { offsetHeight: 500 }, bottom: { offsetTop: 440, offsetHeight: 20 }, actions: { offsetTop: 408, offsetHeight: 60 } },
175
- '100px' // actionsOffset = 500 - 408 = 92, 92 + 8 = 100 > clearsBottomRow (68)
355
+ { main: { offsetHeight: 500 }, bottom: { offsetTop: 440, offsetHeight: 52 }, attributions: { offsetHeight: 16, rect: { top: 476 } }, actions: { offsetTop: 408, offsetHeight: 60 } },
356
+ '100px' // actionsOffset = 500 - 408 = 92, 92 + 8 = 100 > attributions (24) + 8
176
357
  ],
177
358
  [
178
- 'row clearance already larger than actionsOffset (mobile in-flow) — row clearance wins',
179
- { main: { offsetHeight: 500 }, bottom: { offsetTop: 350 }, actions: { offsetTop: 430, offsetHeight: 40 } },
180
- '158px' // clearsBottomRow = 500 - 350 + 8 = 158 > actionsOffset (70) + dividerGap (8) = 78
359
+ 'drawer and actions below the row (mobile in-flow) — clears what is below the row',
360
+ { main: { offsetHeight: 500 }, bottom: { offsetTop: 300, offsetHeight: 50 }, attributions: { offsetHeight: 0 }, actions: { offsetTop: 430, offsetHeight: 40 } },
361
+ '158px' // nothing shown in the row, so its bottom: 500 - 350 = 150, + dividerGap (8) = 158 > actionsOffset (70) + 8
181
362
  ]
182
363
  ])('calculates --hint-bottom for %s', (_, refOverrides, expected) => {
183
364
  const { layoutRefs } = setup({ refs: refOverrides })
@@ -189,7 +370,7 @@ describe('useLayoutMeasurements', () => {
189
370
  const { layoutRefs } = setup()
190
371
  layoutRefs.actionsRef.current = null
191
372
  renderHook(() => useLayoutMeasurements())
192
- // actionsHeight = 0, falls back to clearsBottomRow = 500 - 400 + dividerGap (8) = 108
373
+ // No actions: attributions top 400; 500 - 400 + dividerGap (8) = 108
193
374
  expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--hint-bottom', '108px')
194
375
  })
195
376
 
@@ -251,10 +432,7 @@ describe('useLayoutMeasurements', () => {
251
432
  })
252
433
 
253
434
  test('keeps attributions docked beside the logo when the natural text width fits', () => {
254
- const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } } } })
255
- appendChild(layoutRefs.bottomRef.current, {}) // logo column
256
- appendChild(layoutRefs.bottomRef.current, { offsetWidth: 192, rect: { left: 115 } }) // bottom-right column
257
- layoutRefs.bottomRef.current.appendChild(layoutRefs.attributionsRef.current) // sibling of both columns
435
+ const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } }, bottomRightCol } })
258
436
  appendChild(layoutRefs.attributionsRef.current, { scrollWidth: 150 }) // attribution text, fits
259
437
  renderHook(() => useLayoutMeasurements())
260
438
  expect(layoutRefs.attributionsRef.current.classList.contains('im-o-app__attributions--stacked')).toBe(false)
@@ -265,10 +443,7 @@ describe('useLayoutMeasurements', () => {
265
443
  })
266
444
 
267
445
  test('stacks attributions onto their own row when the text is wider than the space beside the logo', () => {
268
- const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } } } })
269
- appendChild(layoutRefs.bottomRef.current, {}) // logo column
270
- appendChild(layoutRefs.bottomRef.current, { offsetWidth: 192, rect: { left: 115 } }) // bottom-right column
271
- layoutRefs.bottomRef.current.appendChild(layoutRefs.attributionsRef.current) // sibling of both columns
446
+ const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } }, bottomRightCol } })
272
447
  appendChild(layoutRefs.attributionsRef.current, { scrollWidth: 250 }) // attribution text, too wide to fit
273
448
  renderHook(() => useLayoutMeasurements())
274
449
  expect(layoutRefs.attributionsRef.current.classList.contains('im-o-app__attributions--stacked')).toBe(true)
@@ -276,89 +451,19 @@ describe('useLayoutMeasurements', () => {
276
451
  expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--bottom-right-clearance', '0px')
277
452
  })
278
453
 
279
- test('never gives bottom-right negative clearance when attributions is shorter than the bleed', () => {
280
- const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } }, attributions: { offsetHeight: 0 } } })
281
- appendChild(layoutRefs.bottomRef.current, {}) // logo column
282
- appendChild(layoutRefs.bottomRef.current, { offsetWidth: 192, rect: { left: 115 } }) // bottom-right column
283
- layoutRefs.bottomRef.current.appendChild(layoutRefs.attributionsRef.current) // sibling of both columns
284
- renderHook(() => useLayoutMeasurements())
285
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--bottom-right-clearance', '0px')
286
- })
287
-
288
- test('uses 0 when bottomRightRef current is null', () => {
454
+ test('stacks the attributions, and doesn\'t offset them, when there\'s no bottom-right column', () => {
289
455
  const { layoutRefs } = setup()
290
- layoutRefs.bottomRightRef.current = null
291
- renderHook(() => useLayoutMeasurements())
292
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-offset-bottom', '116px')
293
- })
294
-
295
- test('uses bottomRight height when bottomRightHeight > 0', () => {
296
- const { layoutRefs } = setup({
297
- refs: {
298
- bottomRight: { offsetHeight: 20 } // 👈 triggers TRUE branch
299
- }
300
- })
301
- renderHook(() => useLayoutMeasurements())
302
- // bottomContainerPad = 500 - 400 - 0 = 100
303
- // attributions lift = 16 (default attributions offsetHeight 16 + dividerGap 8 - primaryGap 8)
304
- // expected = 100 + (20 + 16 + 8) = 144
305
- expect(layoutRefs.appContainerRef.current.style.setProperty)
306
- .toHaveBeenCalledWith('--right-offset-bottom', '144px')
307
- })
308
-
309
- test('adds the attributions lift into right-offset-bottom so .im-o-app__right does not overlap a bottom-right box pushed up by tall docked attributions', () => {
310
- const { layoutRefs } = setup({
311
- refs: {
312
- bottomRight: { offsetHeight: 20 },
313
- attributions: { offsetHeight: 40 } // lift = 40 + 8 (dividerGap) - 8 (primaryGap) = 40
314
- }
315
- })
316
- renderHook(() => useLayoutMeasurements())
317
- // bottomContainerPad = 500 - 400 - 0 = 100; expected = 100 + (20 + 40 + 8) = 168
318
- // Without the lift term this regressed to 128px, letting .im-o-app__right's
319
- // bottom offset sit below the (margin-bottom-raised) bottom-right box's real top edge.
320
- expect(layoutRefs.appContainerRef.current.style.setProperty)
321
- .toHaveBeenCalledWith('--right-offset-bottom', '168px')
322
- })
323
-
324
- // Stacked attributions takes a flex line of its own BELOW the bottom-right row, lifting the
325
- // row by the same amount the docked box's margin-bottom does — but as part of
326
- // .im-o-app__bottom's own grown height, not as a margin, so --bottom-right-clearance is 0.
327
- // Reading the clearance here (rather than the mode-independent lift) left the right column's
328
- // bottom offset at the un-lifted position, so a right-bottom scale bar overlapped a
329
- // bottom-right draw menu on mobile — the breakpoint where attributions always stacks.
330
- test('adds the attributions lift into right-offset-bottom when attributions is stacked, not just docked', () => {
331
- const { layoutRefs } = setup({
332
- refs: {
333
- bottom: { rect: { left: 0 } },
334
- bottomRight: { offsetHeight: 20 },
335
- attributions: { offsetHeight: 40 } // lift = 40 + 8 (dividerGap) - 8 (primaryGap) = 40
336
- }
337
- })
338
- appendChild(layoutRefs.bottomRef.current, {}) // logo column
339
- appendChild(layoutRefs.bottomRef.current, { offsetWidth: 192, rect: { left: 115 } }) // bottom-right column
340
- layoutRefs.bottomRef.current.appendChild(layoutRefs.attributionsRef.current) // sibling of both columns
341
- appendChild(layoutRefs.attributionsRef.current, { scrollWidth: 250 }) // too wide to fit beside the logo
456
+ layoutRefs.bottomRightColRef.current = null
457
+ appendChild(layoutRefs.attributionsRef.current, { scrollWidth: 150 })
342
458
  renderHook(() => useLayoutMeasurements())
343
- const spy = layoutRefs.appContainerRef.current.style.setProperty
344
459
  expect(layoutRefs.attributionsRef.current.classList.contains('im-o-app__attributions--stacked')).toBe(true)
345
- expect(spy).toHaveBeenCalledWith('--bottom-right-clearance', '0px')
346
- // Same 168px as the docked case above, despite the 0px clearance.
347
- expect(spy).toHaveBeenCalledWith('--right-offset-bottom', '168px')
348
- // rightEffectiveBottom = 400 + 0 - 20 - 40 = 340; 340 - 50 (rightOffsetTop) - 8 = 282
349
- expect(spy).toHaveBeenCalledWith('--right-top-max-height', '282px')
460
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--attributions-left', '0px')
350
461
  })
351
462
 
352
- test('uses 0 when sub-slot refs have null current', () => {
353
- const { layoutRefs } = setup()
354
- layoutRefs.leftTopRef.current = null
355
- layoutRefs.leftBottomRef.current = null
356
- layoutRefs.rightTopRef.current = null
357
- layoutRefs.rightBottomRef.current = null
463
+ test('never gives bottom-right negative clearance when attributions is shorter than the bleed', () => {
464
+ const { layoutRefs } = setup({ refs: { bottom: { rect: { left: 0 } }, bottomRightCol, attributions: { offsetHeight: 0 } } })
358
465
  renderHook(() => useLayoutMeasurements())
359
- // With all sub-slot refs null, buttons = 0 ?? 0 = 0, so max-heights equal full column height
360
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--left-top-panel-max-height', '332px')
361
- expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--right-bottom-panel-max-height', '326px')
466
+ expect(layoutRefs.appContainerRef.current.style.setProperty).toHaveBeenCalledWith('--bottom-right-clearance', '0px')
362
467
  })
363
468
 
364
469
  test('dispatches safe zone inset on desktop (post-batch RAF read only)', () => {
@@ -453,7 +558,7 @@ describe('useLayoutMeasurements', () => {
453
558
  const { layoutRefs } = setup()
454
559
  renderHook(() => useLayoutMeasurements())
455
560
  expect(useResizeObserver).toHaveBeenCalledWith(
456
- [layoutRefs.bannerRef, layoutRefs.mainRef, layoutRefs.headerRef, layoutRefs.topRef, layoutRefs.topLeftColRef, layoutRefs.topRightColRef, layoutRefs.actionsRef, layoutRefs.bottomRef, layoutRefs.bottomRightRef, layoutRefs.attributionsRef, layoutRefs.leftTopRef, layoutRefs.leftBottomRef, layoutRefs.rightTopRef, layoutRefs.rightBottomRef, layoutRefs.drawerRef, layoutRefs.leftRef, layoutRefs.rightRef],
561
+ [layoutRefs.bannerRef, layoutRefs.mainRef, layoutRefs.headerRef, layoutRefs.topRef, layoutRefs.topLeftColRef, layoutRefs.topMiddleColRef, layoutRefs.topRightColRef, layoutRefs.actionsRef, layoutRefs.bottomRef, layoutRefs.bottomLeftColRef, layoutRefs.bottomRightRef, layoutRefs.attributionsRef, layoutRefs.leftTopRef, layoutRefs.leftBottomRef, layoutRefs.rightTopRef, layoutRefs.rightBottomRef, layoutRefs.drawerRef, layoutRefs.leftRef, layoutRefs.rightRef],
457
562
  expect.any(Function)
458
563
  )
459
564
  layoutRefs.appContainerRef.current.style.setProperty.mockClear()