@defra/interactive-map 0.0.59-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 (87) 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/package.json +1 -1
  14. package/plugins/datasets/dist/esm/index.js +1 -1
  15. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  16. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  17. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  18. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  19. package/plugins/datasets/dist/umd/index.js +1 -1
  20. package/plugins/datasets/src/index.js +0 -1
  21. package/plugins/datasets/src/index.test.js +2 -8
  22. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  23. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  24. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  25. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  26. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  27. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  28. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  29. package/plugins/search/dist/css/index.css +1 -1
  30. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  31. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  32. package/providers/esri/src/esriProvider.js +10 -21
  33. package/providers/esri/src/utils/coords.js +37 -7
  34. package/providers/esri/src/utils/coords.test.js +22 -1
  35. package/providers/esri/src/utils/spatial.js +1 -47
  36. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  37. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  38. package/providers/maplibre/src/maplibreProvider.js +5 -14
  39. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  40. package/providers/maplibre/src/utils/spatial.js +0 -40
  41. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  42. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  43. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  44. package/providers/openlayers/src/openlayersProvider.js +5 -14
  45. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  46. package/providers/openlayers/src/utils/spatial.js +0 -39
  47. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  48. package/src/App/components/Hints/Hints.jsx +9 -21
  49. package/src/App/components/Hints/Hints.test.jsx +20 -33
  50. package/src/App/components/Panel/Panel.jsx +16 -1
  51. package/src/App/components/Panel/Panel.test.jsx +44 -0
  52. package/src/App/hooks/useCrossHairAPI.js +27 -28
  53. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  54. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  55. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  56. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  57. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  58. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  59. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  60. package/src/App/hooks/useVisibleGeometry.js +35 -45
  61. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  62. package/src/App/layout/Layout.jsx +4 -4
  63. package/src/App/layout/layout.module.scss +124 -61
  64. package/src/App/store/AppProvider.jsx +3 -0
  65. package/src/App/store/appDispatchMiddleware.js +18 -10
  66. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  67. package/src/InteractiveMap/InteractiveMap.js +3 -2
  68. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  69. package/src/config/events.js +1 -1
  70. package/src/config/mapPanelSlots.js +8 -0
  71. package/src/config/symbolConfig.js +1 -1
  72. package/src/services/symbolRegistry.js +1 -1
  73. package/src/services/symbolRegistry.test.js +19 -0
  74. package/src/types.js +29 -8
  75. package/src/utils/getFitMove.js +73 -0
  76. package/src/utils/getFitMove.test.js +114 -0
  77. package/src/utils/getSafeZoneInset.js +122 -77
  78. package/src/utils/getSafeZoneInset.test.js +241 -54
  79. package/src/utils/getValueForStyle.js +10 -5
  80. package/src/utils/getValueForStyle.test.js +13 -2
  81. package/src/utils/renderedBoxes.js +25 -0
  82. package/src/utils/renderedBoxes.test.js +61 -0
  83. package/src/utils/screenBox.js +70 -0
  84. package/src/utils/screenBox.test.js +69 -0
  85. package/src/utils/symbolUtils.js +9 -9
  86. package/src/utils/symbolUtils.test.js +21 -0
  87. package/providers/esri/src/utils/spatial.test.js +0 -58
@@ -0,0 +1,114 @@
1
+ import { getFitMove, normalisePaddingPercent } from './getFitMove.js'
2
+
3
+ // A 400 × 200 safe zone, from (100, 50) to (500, 250)
4
+ const safeZone = { left: 100, top: 50, right: 500, bottom: 250 }
5
+
6
+ describe('normalisePaddingPercent', () => {
7
+ test('defaults every side to 0', () => {
8
+ expect(normalisePaddingPercent()).toEqual({ top: 0, right: 0, bottom: 0, left: 0 })
9
+ expect(normalisePaddingPercent(null)).toEqual({ top: 0, right: 0, bottom: 0, left: 0 })
10
+ })
11
+
12
+ test('applies one value to every side', () => {
13
+ expect(normalisePaddingPercent(10)).toEqual({ top: 10, right: 10, bottom: 10, left: 10 })
14
+ })
15
+
16
+ test('takes each side from an object, defaulting missing sides to 0', () => {
17
+ expect(normalisePaddingPercent({ top: 5, left: 10 })).toEqual({ top: 5, right: 0, bottom: 0, left: 10 })
18
+ })
19
+
20
+ test('limits each side to 0–25', () => {
21
+ expect(normalisePaddingPercent(40)).toEqual({ top: 25, right: 25, bottom: 25, left: 25 })
22
+ expect(normalisePaddingPercent({ top: -5, right: 30 })).toEqual({ top: 0, right: 25, bottom: 0, left: 0 })
23
+ })
24
+
25
+ test('treats a value that is not a number as 0', () => {
26
+ expect(normalisePaddingPercent('lots')).toEqual({ top: 0, right: 0, bottom: 0, left: 0 })
27
+ })
28
+ })
29
+
30
+ describe('getFitMove', () => {
31
+ describe('without preferPan', () => {
32
+ test('always fits, with no margin by default', () => {
33
+ const box = { left: 200, top: 100, right: 300, bottom: 150 }
34
+ expect(getFitMove({ box, safeZone })).toEqual({ type: 'fit', margin: { top: 0, right: 0, bottom: 0, left: 0 } })
35
+ })
36
+
37
+ test('works out the margin from the safe zone width for left and right, and its height for top and bottom', () => {
38
+ expect(getFitMove({ safeZone, paddingPercent: 10 })).toEqual({ type: 'fit', margin: { top: 20, right: 40, bottom: 20, left: 40 } })
39
+ })
40
+
41
+ test('works out each side separately', () => {
42
+ expect(getFitMove({ safeZone, paddingPercent: { top: 5, left: 25 } })).toEqual({ type: 'fit', margin: { top: 10, right: 0, bottom: 0, left: 100 } })
43
+ })
44
+ })
45
+
46
+ describe('with preferPan', () => {
47
+ test('doesn\'t move a box already inside the safe zone', () => {
48
+ const box = { left: 110, top: 60, right: 200, bottom: 100 }
49
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'none' })
50
+ })
51
+
52
+ test('doesn\'t move a box inside the safe zone but within its margin', () => {
53
+ const box = { left: 105, top: 55, right: 200, bottom: 100 }
54
+ expect(getFitMove({ box, safeZone, preferPan: true, paddingPercent: 10 })).toEqual({ type: 'none' })
55
+ })
56
+
57
+ test('pans a box inside the safe zone but under a panel', () => {
58
+ // A small panel the safe zone leaves out, over the box. Box centre (150, 75)
59
+ const box = { left: 140, top: 70, right: 160, bottom: 80 }
60
+ const panels = [{ left: 100, top: 50, right: 300, bottom: 120 }]
61
+ expect(getFitMove({ box, safeZone, panels, preferPan: true })).toEqual({ type: 'pan', offset: [-150, -75] })
62
+ })
63
+
64
+ test('doesn\'t move a box inside the safe zone and clear of every panel', () => {
65
+ const box = { left: 400, top: 200, right: 450, bottom: 240 }
66
+ const panels = [{ left: 100, top: 50, right: 300, bottom: 120 }]
67
+ expect(getFitMove({ box, safeZone, panels, preferPan: true })).toEqual({ type: 'none' })
68
+ })
69
+
70
+ test('pans a box that fits to the centre of the safe zone', () => {
71
+ // Box centre (550, 300), safe zone centre (300, 150)
72
+ const box = { left: 500, top: 250, right: 600, bottom: 350 }
73
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'pan', offset: [250, 150] })
74
+ })
75
+
76
+ test('pans a box that is partly outside the safe zone', () => {
77
+ // Box centre (110, 150), safe zone centre (300, 150)
78
+ const box = { left: 60, top: 100, right: 160, bottom: 200 }
79
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'pan', offset: [-190, 0] })
80
+ })
81
+
82
+ test('pans a point to the centre of the safe zone', () => {
83
+ const box = { left: 0, top: 0, right: 0, bottom: 0 }
84
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'pan', offset: [-300, -150] })
85
+ })
86
+
87
+ test('centres in the safe zone less its margin when the sides differ', () => {
88
+ // Inner area (200, 50) to (500, 250), centre (350, 150)
89
+ const box = { left: 0, top: 100, right: 100, bottom: 200 }
90
+ expect(getFitMove({ box, safeZone, preferPan: true, paddingPercent: { left: 25 } })).toEqual({ type: 'pan', offset: [-300, 0] })
91
+ })
92
+
93
+ test('fits a box too wide for the safe zone', () => {
94
+ const box = { left: 0, top: 100, right: 450, bottom: 150 }
95
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'fit', margin: { top: 0, right: 0, bottom: 0, left: 0 } })
96
+ })
97
+
98
+ test('fits a box too tall for the safe zone', () => {
99
+ const box = { left: 0, top: 0, right: 100, bottom: 250 }
100
+ expect(getFitMove({ box, safeZone, preferPan: true })).toEqual({ type: 'fit', margin: { top: 0, right: 0, bottom: 0, left: 0 } })
101
+ })
102
+
103
+ test('fits a box that fits the safe zone but not the safe zone less its margin', () => {
104
+ // 360 wide fits the 400 safe zone, not the 320 left after 10% each side
105
+ const box = { left: 0, top: 100, right: 360, bottom: 150 }
106
+ expect(getFitMove({ box, safeZone, preferPan: true, paddingPercent: 10 })).toEqual({ type: 'fit', margin: { top: 20, right: 40, bottom: 20, left: 40 } })
107
+ })
108
+
109
+ test('pans a box exactly the size of the safe zone less its margin', () => {
110
+ const box = { left: 0, top: 0, right: 320, bottom: 160 }
111
+ expect(getFitMove({ box, safeZone, preferPan: true, paddingPercent: 10 })).toEqual({ type: 'pan', offset: [-140, -70] })
112
+ })
113
+ })
114
+ })
@@ -1,19 +1,14 @@
1
+ import { getRelativeBox } from './screenBox.js'
2
+ import { topColHeight } from './renderedBoxes.js'
3
+
1
4
  /**
2
- * Calculates the safe zone inset — the unobscured region of the map viewport
3
- * not hidden behind overlay panels or structural UI (button columns, footer,
4
- * action bar). Used as padding for map operations like fitBounds or setView
5
- * so the target location or extent is fully visible.
5
+ * The safe zone inset: the part of the map not hidden by the button columns, top row, actions bar
6
+ * or open panels. Used as padding by fitBounds and setView so the target is fully visible.
6
7
  *
7
- * Each edge inset is driven by:
8
- * - A structural baseline from the button columns, footer, and action bar.
9
- * - A panel contribution once a panel (or the two panels stacked in a side's
10
- * slots) covers more than 1/RATIO of the available map height (widening
11
- * that side's left/right inset) and/or more than 1/RATIO of the available
12
- * map width (pushing the top/bottom inset down/up). Both can trigger at
13
- * once for a panel that's both tall and wide — independently, not
14
- * exclusively, since the MAX_RATIO cap below already bounds each edge.
15
- * - A cap so no single inset exceeds 1/MAX_RATIO of the map dimension,
16
- * preventing fitBounds from zooming out to a corner when panels are large.
8
+ * Each edge has a structural base: the button columns, the top row (mirrored at the bottom) and the
9
+ * actions bar. Open panels push an edge further once they cover more than 1/RATIO of the room across
10
+ * or down the map, capped at (MAX_RATIO - 1)/MAX_RATIO of it. If panels leave less than 1/MIN_RATIO
11
+ * of the room on an axis, that axis falls back to the structural insets.
17
12
  *
18
13
  * @param {Object} refs - React refs from layoutRefs.
19
14
  * @param {React.RefObject} refs.mainRef - Main map container.
@@ -21,6 +16,7 @@
21
16
  * @param {React.RefObject} refs.rightRef - Right button column.
22
17
  * @param {React.RefObject} refs.actionsRef - Bottom action bar.
23
18
  * @param {React.RefObject} refs.bottomRef - Bottom row (logo, copyright, etc).
19
+ * @param {React.RefObject} [refs.topRef] - Top row of buttons.
24
20
  * @param {React.RefObject} [refs.leftTopRef] - Top-left panel slot.
25
21
  * @param {React.RefObject} [refs.leftBottomRef] - Bottom-left panel slot.
26
22
  * @param {React.RefObject} [refs.rightTopRef] - Top-right panel slot.
@@ -30,22 +26,35 @@
30
26
  */
31
27
 
32
28
  const RATIO = 2 // panels covering more than 1/RATIO of the available height/width trigger that edge's inset
33
- const MAX_RATIO = 3 // each inset is capped at 1/MAX_RATIO of its map dimension
34
-
35
- // Query the panel element directly within its slot container.
36
- // Only the first panel matters, and only when it is also the first element in the slot
37
- // (i.e. no buttons or other elements precede it — a panel pushed down by buttons is
38
- // already within the button-column structural inset and should not add extra padding).
39
- const getPanelDimensions = (slotRef) => {
40
- if (!slotRef?.current) {
41
- return { offsetWidth: 0, offsetHeight: 0 }
42
- }
43
- const first = slotRef.current.firstElementChild
44
- if (!first?.classList.contains('im-c-panel') || first.offsetWidth === 0 || first.offsetHeight === 0) {
45
- return { offsetWidth: 0, offsetHeight: 0 }
46
- }
47
- return { offsetWidth: first.offsetWidth, offsetHeight: first.offsetHeight }
48
- }
29
+ const MAX_RATIO = 3 // each inset is capped at (MAX_RATIO - 1)/MAX_RATIO of its map dimension
30
+ // An axis with less than 1/MIN_RATIO of the structural room left falls back to the structural insets.
31
+ // A single panel at the MAX_RATIO cap still leaves more than this.
32
+ const MIN_RATIO = 4
33
+
34
+ // Closed panels stay mounted with `hidden`
35
+ const isOpenPanel = (element) => element.classList.contains('im-c-panel') && !element.hidden
36
+
37
+ /**
38
+ * Every open panel in a slot, wherever it sits among buttons and controls, as a box relative to
39
+ * `origin`.
40
+ *
41
+ * @param {React.RefObject} slotRef - A panel slot.
42
+ * @param {DOMRect} origin - The rect the boxes are measured from.
43
+ * @returns {Array<{ left: number, top: number, right: number, bottom: number }>}
44
+ */
45
+ export const getOpenPanelBoxes = (slotRef, origin) => Array.from(slotRef?.current?.children ?? [])
46
+ .filter(isOpenPanel)
47
+ .map(panel => panel.getBoundingClientRect())
48
+ .filter(rect => rect.width > 0 && rect.height > 0)
49
+ .map(rect => getRelativeBox(rect, origin))
50
+
51
+ const widthOf = (box) => box.right - box.left
52
+ const heightOf = (box) => box.bottom - box.top
53
+
54
+ // Sizes laid end to end, with the gap between each
55
+ const addUp = (sizes, gap) => sizes.length ? sizes.reduce((total, size) => total + size, 0) + gap * (sizes.length - 1) : 0
56
+
57
+ const widest = (boxes) => boxes.length ? Math.max(...boxes.map(widthOf)) : 0
49
58
 
50
59
  // Panels are in normal flow inside slot containers, expanding left/right offsetWidth.
51
60
  // Query button groups directly to recover the button-only structural column width.
@@ -54,69 +63,105 @@ const getButtonColWidth = (colRef) => {
54
63
  return group ? group.offsetWidth : 0
55
64
  }
56
65
 
57
- // Determines the column (left/right) inset from the two panels stacked in that side's
58
- // slots. Combined height exceeding the threshold triggers the inset, widened to fit
59
- // whichever panel is wider.
60
- const computeColumn = (panelA, panelB, hThreshold, columnLeft, gap) => {
61
- const coverage = panelA.offsetHeight + panelB.offsetHeight + (panelA.offsetHeight > 0 && panelB.offsetHeight > 0 ? gap : 0)
62
- const triggered = coverage > hThreshold
63
- return triggered ? columnLeft + Math.max(panelA.offsetWidth, panelB.offsetWidth) + gap : 0
66
+ // The open panels in a side's slots, stacked, trigger that side's inset once their heights added
67
+ // up pass the threshold. The inset then reaches the panels' furthest edge into the map.
68
+ const isColumnTriggered = (boxes, hThreshold, gap) => addUp(boxes.map(heightOf), gap) > hThreshold
69
+
70
+ // The open panels in the left and right near slots (both top, or both bottom) push that edge once
71
+ // the widest on each side, added up, pass the threshold. Returns the panels that push it, if any.
72
+ const rowPanels = (leftBoxes, rightBoxes, wThreshold, gap) =>
73
+ addUp([widest(leftBoxes), widest(rightBoxes)].filter(width => width > 0), gap) > wThreshold
74
+ ? [...leftBoxes, ...rightBoxes]
75
+ : []
76
+
77
+ // No edge's panel inset goes past (MAX_RATIO - 1)/MAX_RATIO of the map, less a gap each side
78
+ const maxInset = (size, gap) => (size - 2 * gap) * (MAX_RATIO - 1) / MAX_RATIO
79
+
80
+ // Width first, as panels sit in the side columns: a side whose panels are tall enough is cleared by
81
+ // its own inset, then capped, and both fall back to the structural insets if too little is left.
82
+ // A side only counts as cleared if its final inset still reaches past its panels.
83
+ const resolveWidth = ({ main, leftColumn, rightColumn, base, availableW, availableH, gap }) => {
84
+ const leftPanelInset = isColumnTriggered(leftColumn, availableH / RATIO, gap)
85
+ ? main.offsetLeft + Math.max(...leftColumn.map(box => box.right)) + gap
86
+ : 0
87
+ const rightPanelInset = isColumnTriggered(rightColumn, availableH / RATIO, gap)
88
+ ? main.offsetWidth - Math.min(...rightColumn.map(box => box.left)) + gap
89
+ : 0
90
+ const cappedLeft = Math.max(base.left, Math.min(leftPanelInset, main.offsetLeft + maxInset(main.offsetWidth, gap)))
91
+ const cappedRight = Math.max(base.right, Math.min(rightPanelInset, maxInset(main.offsetWidth, gap)))
92
+ const isTooNarrow = main.offsetWidth - (cappedLeft - main.offsetLeft) - cappedRight < availableW / MIN_RATIO
93
+ const left = isTooNarrow ? base.left : cappedLeft
94
+ const right = isTooNarrow ? base.right : cappedRight
95
+ return {
96
+ left,
97
+ right,
98
+ isLeftCleared: leftPanelInset > 0 && left >= leftPanelInset,
99
+ isRightCleared: rightPanelInset > 0 && right >= rightPanelInset
100
+ }
64
101
  }
65
102
 
66
- // Determines the row (top/bottom) inset from the panels docked in the left and right
67
- // columns' near slot (both top, or both bottom). Combined width exceeding the threshold
68
- // triggers the inset, deepened to fit whichever panel is taller. Evaluated independently
69
- // of computeColumn — a panel can widen its own column AND push top/bottom down at once.
70
- const computeRow = (leftPanel, rightPanel, wThreshold, baseInset, gap) => {
71
- const coverage = leftPanel.offsetWidth + rightPanel.offsetWidth + (leftPanel.offsetWidth > 0 && rightPanel.offsetWidth > 0 ? gap : 0)
72
- const triggered = coverage > wThreshold
73
- return triggered ? baseInset + Math.max(leftPanel.offsetHeight, rightPanel.offsetHeight) + gap : 0
103
+ // Then height: only panels on a side the final width doesn't clear still cover the rest of the map,
104
+ // so only they push the top or bottom, then capped, and both fall back if too little is left.
105
+ const resolveHeight = ({ main, panels, width, base, availableW, availableH, gap }) => {
106
+ const pushingPanels = (leftBoxes, rightBoxes) =>
107
+ rowPanels(width.isLeftCleared ? [] : leftBoxes, width.isRightCleared ? [] : rightBoxes, availableW / RATIO, gap)
108
+ const topPanels = pushingPanels(panels.topLeft, panels.topRight)
109
+ const bottomPanels = pushingPanels(panels.bottomLeft, panels.bottomRight)
110
+ const topPanelInset = topPanels.length ? Math.max(...topPanels.map(box => box.bottom)) + gap : 0
111
+ const bottomPanelInset = bottomPanels.length ? main.offsetHeight - Math.min(...bottomPanels.map(box => box.top)) + gap : 0
112
+ const cappedTop = Math.max(base.top, Math.min(topPanelInset, maxInset(main.offsetHeight, gap)))
113
+ const cappedBottom = Math.max(base.bottom, Math.min(bottomPanelInset, maxInset(main.offsetHeight, gap)))
114
+ const isTooShort = main.offsetHeight - cappedTop - cappedBottom < availableH / MIN_RATIO
115
+ return { top: isTooShort ? base.top : cappedTop, bottom: isTooShort ? base.bottom : cappedBottom }
116
+ }
117
+
118
+ // The top row's height and where it ends, counting any column that shows, as a column can wrap
119
+ const measureTopRow = (top) => {
120
+ const height = Math.max(0, ...Array.from(top?.children ?? [], topColHeight))
121
+ return { height, bottom: (top?.offsetTop ?? 0) + height }
74
122
  }
75
123
 
76
124
  export const getSafeZoneInset = ({
77
- mainRef, leftRef, rightRef, actionsRef, bottomRef,
125
+ mainRef, leftRef, rightRef, actionsRef, bottomRef, topRef,
78
126
  leftTopRef, leftBottomRef, rightTopRef, rightBottomRef
79
127
  }) => {
80
128
  if ([mainRef, leftRef, rightRef, actionsRef, bottomRef].some(ref => !ref?.current)) {
81
129
  return undefined
82
130
  }
83
131
 
84
- const main = mainRef.current; const left = leftRef.current
132
+ const main = mainRef.current; const leftButtons = leftRef.current
85
133
  const actions = actionsRef.current; const bottom = bottomRef.current
86
134
 
87
- const gap = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--divider-gap'), 10)
135
+ const rootStyle = getComputedStyle(document.documentElement)
136
+ const gap = Number.parseInt(rootStyle.getPropertyValue('--divider-gap'), 10)
137
+ const primaryGap = Number.parseInt(rootStyle.getPropertyValue('--primary-gap'), 10)
88
138
 
89
- const rawTL = getPanelDimensions(leftTopRef); const rawBL = getPanelDimensions(leftBottomRef)
90
- const rawTR = getPanelDimensions(rightTopRef); const rawBR = getPanelDimensions(rightBottomRef)
139
+ // Panels measured by where they really are against the main area, so one below buttons, or
140
+ // after the controls at the bottom of a slot, counts at its real position
141
+ const mainRect = main.getBoundingClientRect()
142
+ const topLeft = getOpenPanelBoxes(leftTopRef, mainRect); const bottomLeft = getOpenPanelBoxes(leftBottomRef, mainRect)
143
+ const topRight = getOpenPanelBoxes(rightTopRef, mainRect); const bottomRight = getOpenPanelBoxes(rightBottomRef, mainRect)
144
+ const leftColumn = [...topLeft, ...bottomLeft]; const rightColumn = [...topRight, ...bottomRight]
91
145
 
92
146
  // Structural base insets — always present, never capped.
93
147
  const colWidth = Math.max(getButtonColWidth(leftRef), getButtonColWidth(rightRef))
94
- const baseLeft = main.offsetLeft + left.offsetLeft + colWidth + gap
95
- const baseRight = left.offsetLeft + colWidth + gap
96
- const baseTop = left.offsetTop
97
- const bottomContainerPad = main.offsetHeight - bottom.offsetTop - bottom.offsetHeight
98
- // Minimum: primary-gap above the bottom edge. Normally: divider-gap above the top of the bottom container.
99
- const bottomInset = Math.max(bottomContainerPad, main.offsetHeight - bottom.offsetTop + gap)
100
- const baseBottom = Math.max(main.offsetHeight - actions.offsetTop + gap, bottomInset)
101
-
102
- const availableH = main.offsetHeight - baseTop - baseBottom
103
- const availableW = main.offsetWidth - (baseLeft - main.offsetLeft) - baseRight
104
-
105
- const leftPanelInset = computeColumn(rawTL, rawBL, availableH / RATIO, main.offsetLeft + left.offsetLeft, gap)
106
- const rightPanelInset = computeColumn(rawTR, rawBR, availableH / RATIO, left.offsetLeft, gap)
107
- const topPanelInset = computeRow(rawTL, rawTR, availableW / RATIO, baseTop, gap)
108
- const bottomPanelInset = computeRow(rawBL, rawBR, availableW / RATIO, bottomInset, gap)
109
-
110
- const usableW = main.offsetWidth - 2 * gap
111
- const usableH = main.offsetHeight - 2 * gap
112
- const maxL = main.offsetLeft + usableW * (MAX_RATIO - 1) / MAX_RATIO
113
- const maxR = usableW * (MAX_RATIO - 1) / MAX_RATIO
114
- const maxV = usableH * (MAX_RATIO - 1) / MAX_RATIO
115
-
116
- return {
117
- left: Math.max(baseLeft, Math.min(leftPanelInset, maxL)),
118
- right: Math.max(baseRight, Math.min(rightPanelInset, maxR)),
119
- top: Math.max(baseTop, Math.min(topPanelInset, maxV)),
120
- bottom: Math.max(baseBottom, Math.min(bottomPanelInset, maxV))
148
+ // The bottom row itself doesn't count. The bottom mirrors the top row and its margin, so the safe
149
+ // zone is centred, but still clears the actions bar and anything below the row, such as the drawer
150
+ const topRow = measureTopRow(topRef?.current)
151
+ const base = {
152
+ left: main.offsetLeft + leftButtons.offsetLeft + colWidth + gap,
153
+ right: leftButtons.offsetLeft + colWidth + gap,
154
+ top: Math.max(leftButtons.offsetTop, rightRef.current.offsetTop, topRow.bottom),
155
+ bottom: Math.max(
156
+ primaryGap + topRow.height,
157
+ main.offsetHeight - actions.offsetTop + gap,
158
+ main.offsetHeight - bottom.offsetTop - bottom.offsetHeight
159
+ )
121
160
  }
161
+ const availableH = main.offsetHeight - base.top - base.bottom
162
+ const availableW = main.offsetWidth - (base.left - main.offsetLeft) - base.right
163
+
164
+ const width = resolveWidth({ main, leftColumn, rightColumn, base, availableW, availableH, gap })
165
+ const height = resolveHeight({ main, panels: { topLeft, topRight, bottomLeft, bottomRight }, width, base, availableW, availableH, gap })
166
+ return { left: width.left, right: width.right, top: height.top, bottom: height.bottom }
122
167
  }