|
4 | 4 | isInPageBuilderIframe, |
5 | 5 | markPageBuilderActive |
6 | 6 | } from './pageBuilderMode.js'; |
| 7 | +import { ensureChromeStyleInjected } from './WidgetChrome.js'; |
7 | 8 |
|
8 | 9 | /** |
9 | 10 | * Listens for `data-update` postMessages from the admin window and applies |
@@ -102,6 +103,12 @@ export function PageBuilderBridge(): null { |
102 | 103 | markPageBuilderActive(); |
103 | 104 |
|
104 | 105 | ensureGlobalsOutlineStyle(); |
| 106 | + // The chrome stylesheet carries the `[data-evershop-pb-dropzone]` sizing / |
| 107 | + // visibility rules. `WidgetChrome` injects it too, but only mounts per |
| 108 | + // existing widget — so on a route with no widgets the drop zones would |
| 109 | + // have no CSS and stay invisible / zero-height. Inject here (always |
| 110 | + // mounted in the iframe) so drop zones work on a fresh, empty store. |
| 111 | + ensureChromeStyleInjected(); |
105 | 112 |
|
106 | 113 | // Capture-phase link guard: edit mode disables in-preview navigation. |
107 | 114 | // The page-builder session lives in the iframe's URL (`?changeset=`), |
@@ -154,6 +161,22 @@ export function PageBuilderBridge(): null { |
154 | 161 | | null; |
155 | 162 | if (!raw) return; |
156 | 163 |
|
| 164 | + // Drag lifecycle: the admin posts `pb-drag-start` / `pb-drag-end` when a |
| 165 | + // palette drag begins / ends. Toggling `body[data-evershop-pb-drag]` |
| 166 | + // reveals every drop zone via the chrome CSS. `WidgetChrome` also |
| 167 | + // listens, but only when a widget is mounted — handling it here too |
| 168 | + // makes drops work on a route with no widgets. Setting / removing the |
| 169 | + // attribute is idempotent, so both listeners firing is harmless. |
| 170 | + const dragType = (raw as { type?: string }).type; |
| 171 | + if (dragType === 'pb-drag-start') { |
| 172 | + document.body.setAttribute('data-evershop-pb-drag', 'true'); |
| 173 | + return; |
| 174 | + } |
| 175 | + if (dragType === 'pb-drag-end') { |
| 176 | + document.body.removeAttribute('data-evershop-pb-drag'); |
| 177 | + return; |
| 178 | + } |
| 179 | + |
157 | 180 | // Globals-view toggle: outline `[data-evershop-global]` areas. |
158 | 181 | if ((raw as GlobalsViewMessage).type === 'globals-view') { |
159 | 182 | const enabled = !!(raw as GlobalsViewMessage).enabled; |
|
0 commit comments