@base44-preview/vite-plugin 0.2.21-pr.35.60ab963 → 0.2.22-pr.36.69a0b76
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/dist/injections/layer-dropdown/consts.d.ts +15 -0
- package/dist/injections/layer-dropdown/consts.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/consts.js +36 -0
- package/dist/injections/layer-dropdown/consts.js.map +1 -0
- package/dist/injections/layer-dropdown/controller.d.ts +4 -0
- package/dist/injections/layer-dropdown/controller.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/controller.js +85 -0
- package/dist/injections/layer-dropdown/controller.js.map +1 -0
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts +13 -0
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/dropdown-ui.js +158 -0
- package/dist/injections/layer-dropdown/dropdown-ui.js.map +1 -0
- package/dist/injections/layer-dropdown/types.d.ts +21 -0
- package/dist/injections/layer-dropdown/types.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/types.js +3 -0
- package/dist/injections/layer-dropdown/types.js.map +1 -0
- package/dist/injections/layer-dropdown/utils.d.ts +23 -0
- package/dist/injections/layer-dropdown/utils.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/utils.js +113 -0
- package/dist/injections/layer-dropdown/utils.js.map +1 -0
- package/dist/injections/utils.d.ts +6 -0
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +25 -0
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +79 -64
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/statics/index.mjs +1 -1
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/injections/layer-dropdown/consts.ts +44 -0
- package/src/injections/layer-dropdown/controller.ts +105 -0
- package/src/injections/layer-dropdown/dropdown-ui.ts +221 -0
- package/src/injections/layer-dropdown/types.ts +24 -0
- package/src/injections/layer-dropdown/utils.ts +138 -0
- package/src/injections/utils.ts +34 -0
- package/src/injections/visual-edit-agent.ts +88 -74
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { findElementsById, updateElementClasses } from "./utils.js";
|
|
1
|
+
import { findElementsById, updateElementClasses, getElementSelectorId } from "./utils.js";
|
|
2
|
+
import { createLayerController } from "./layer-dropdown/controller.js";
|
|
3
|
+
import { LAYER_DROPDOWN_ATTR } from "./layer-dropdown/consts.js";
|
|
2
4
|
|
|
3
5
|
export function setupVisualEditAgent() {
|
|
4
6
|
// State variables (replacing React useState/useRef)
|
|
@@ -78,6 +80,66 @@ export function setupVisualEditAgent() {
|
|
|
78
80
|
currentHighlightedElements = [];
|
|
79
81
|
};
|
|
80
82
|
|
|
83
|
+
const clearSelectedOverlays = () => {
|
|
84
|
+
selectedOverlays.forEach((overlay) => {
|
|
85
|
+
if (overlay && overlay.parentNode) {
|
|
86
|
+
overlay.remove();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
selectedOverlays = [];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const notifyElementSelected = (element: Element) => {
|
|
93
|
+
const htmlElement = element as HTMLElement;
|
|
94
|
+
const rect = element.getBoundingClientRect();
|
|
95
|
+
const svgElement = element as SVGElement;
|
|
96
|
+
window.parent.postMessage({
|
|
97
|
+
type: "element-selected",
|
|
98
|
+
tagName: element.tagName,
|
|
99
|
+
classes:
|
|
100
|
+
(svgElement.className as unknown as SVGAnimatedString)?.baseVal ||
|
|
101
|
+
element.className ||
|
|
102
|
+
"",
|
|
103
|
+
visualSelectorId: getElementSelectorId(element),
|
|
104
|
+
content: htmlElement.innerText,
|
|
105
|
+
dataSourceLocation: htmlElement.dataset.sourceLocation,
|
|
106
|
+
isDynamicContent: htmlElement.dataset.dynamicContent === "true",
|
|
107
|
+
linenumber: htmlElement.dataset.linenumber,
|
|
108
|
+
filename: htmlElement.dataset.filename,
|
|
109
|
+
position: {
|
|
110
|
+
top: rect.top,
|
|
111
|
+
left: rect.left,
|
|
112
|
+
right: rect.right,
|
|
113
|
+
bottom: rect.bottom,
|
|
114
|
+
width: rect.width,
|
|
115
|
+
height: rect.height,
|
|
116
|
+
centerX: rect.left + rect.width / 2,
|
|
117
|
+
centerY: rect.top + rect.height / 2,
|
|
118
|
+
},
|
|
119
|
+
}, "*");
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Select an element: create overlays, update state, notify parent
|
|
123
|
+
const selectElement = (element: Element): HTMLDivElement | undefined => {
|
|
124
|
+
const visualSelectorId = getElementSelectorId(element);
|
|
125
|
+
|
|
126
|
+
clearSelectedOverlays();
|
|
127
|
+
|
|
128
|
+
const elements = findElementsById(visualSelectorId || null);
|
|
129
|
+
elements.forEach((el) => {
|
|
130
|
+
const overlay = createOverlay(true);
|
|
131
|
+
document.body.appendChild(overlay);
|
|
132
|
+
selectedOverlays.push(overlay);
|
|
133
|
+
positionOverlay(overlay, el, true);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
selectedElementId = visualSelectorId || null;
|
|
137
|
+
clearHoverOverlays();
|
|
138
|
+
notifyElementSelected(element);
|
|
139
|
+
|
|
140
|
+
return selectedOverlays[0];
|
|
141
|
+
};
|
|
142
|
+
|
|
81
143
|
// Handle mouse over event
|
|
82
144
|
const handleMouseOver = (e: MouseEvent) => {
|
|
83
145
|
if (!isVisualEditMode || isPopoverDragging) return;
|
|
@@ -146,6 +208,9 @@ export function setupVisualEditAgent() {
|
|
|
146
208
|
|
|
147
209
|
const target = e.target as Element;
|
|
148
210
|
|
|
211
|
+
// Let layer dropdown clicks pass through without interference
|
|
212
|
+
if (target.closest(`[${LAYER_DROPDOWN_ATTR}]`)) return;
|
|
213
|
+
|
|
149
214
|
// Close dropdowns when clicking anywhere in iframe if a dropdown is open
|
|
150
215
|
if (isDropdownOpen) {
|
|
151
216
|
e.preventDefault();
|
|
@@ -174,76 +239,13 @@ export function setupVisualEditAgent() {
|
|
|
174
239
|
return;
|
|
175
240
|
}
|
|
176
241
|
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
htmlElement.dataset.sourceLocation ||
|
|
180
|
-
htmlElement.dataset.visualSelectorId;
|
|
181
|
-
|
|
182
|
-
// Clear any existing selected overlays
|
|
183
|
-
selectedOverlays.forEach((overlay) => {
|
|
184
|
-
if (overlay && overlay.parentNode) {
|
|
185
|
-
overlay.remove();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
selectedOverlays = [];
|
|
189
|
-
|
|
190
|
-
// Find all elements with the same ID
|
|
191
|
-
const elements = findElementsById(visualSelectorId || null);
|
|
192
|
-
|
|
193
|
-
// Create selected overlays for all matching elements
|
|
194
|
-
elements.forEach((el) => {
|
|
195
|
-
const overlay = createOverlay(true);
|
|
196
|
-
document.body.appendChild(overlay);
|
|
197
|
-
selectedOverlays.push(overlay);
|
|
198
|
-
positionOverlay(overlay, el, true);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
selectedElementId = visualSelectorId || null;
|
|
202
|
-
|
|
203
|
-
// Clear hover overlays
|
|
204
|
-
clearHoverOverlays();
|
|
205
|
-
|
|
206
|
-
// Calculate element position for popover positioning
|
|
207
|
-
const rect = element.getBoundingClientRect();
|
|
208
|
-
const elementPosition = {
|
|
209
|
-
top: rect.top,
|
|
210
|
-
left: rect.left,
|
|
211
|
-
right: rect.right,
|
|
212
|
-
bottom: rect.bottom,
|
|
213
|
-
width: rect.width,
|
|
214
|
-
height: rect.height,
|
|
215
|
-
centerX: rect.left + rect.width / 2,
|
|
216
|
-
centerY: rect.top + rect.height / 2,
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// Send message to parent window with element info including position
|
|
220
|
-
const svgElement = element as SVGElement;
|
|
221
|
-
const elementData = {
|
|
222
|
-
type: "element-selected",
|
|
223
|
-
tagName: element.tagName,
|
|
224
|
-
classes:
|
|
225
|
-
(svgElement.className as unknown as SVGAnimatedString)?.baseVal ||
|
|
226
|
-
element.className ||
|
|
227
|
-
"",
|
|
228
|
-
visualSelectorId: visualSelectorId,
|
|
229
|
-
content: (element as HTMLElement).innerText,
|
|
230
|
-
dataSourceLocation: htmlElement.dataset.sourceLocation,
|
|
231
|
-
isDynamicContent: htmlElement.dataset.dynamicContent === "true",
|
|
232
|
-
linenumber: htmlElement.dataset.linenumber,
|
|
233
|
-
filename: htmlElement.dataset.filename,
|
|
234
|
-
position: elementPosition,
|
|
235
|
-
};
|
|
236
|
-
window.parent.postMessage(elementData, "*");
|
|
242
|
+
const selectedOverlay = selectElement(element);
|
|
243
|
+
layerController.attachToOverlay(selectedOverlay, element);
|
|
237
244
|
};
|
|
238
245
|
|
|
239
246
|
// Unselect the current element
|
|
240
247
|
const unselectElement = () => {
|
|
241
|
-
|
|
242
|
-
if (overlay && overlay.parentNode) {
|
|
243
|
-
overlay.remove();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
selectedOverlays = [];
|
|
248
|
+
clearSelectedOverlays();
|
|
247
249
|
selectedElementId = null;
|
|
248
250
|
};
|
|
249
251
|
|
|
@@ -302,19 +304,31 @@ export function setupVisualEditAgent() {
|
|
|
302
304
|
}, 50);
|
|
303
305
|
};
|
|
304
306
|
|
|
307
|
+
// --- Layer dropdown controller ---
|
|
308
|
+
const layerController = createLayerController({
|
|
309
|
+
createPreviewOverlay: (element: Element) => {
|
|
310
|
+
const overlay = createOverlay(false);
|
|
311
|
+
overlay.style.zIndex = "9998";
|
|
312
|
+
document.body.appendChild(overlay);
|
|
313
|
+
positionOverlay(overlay, element);
|
|
314
|
+
return overlay;
|
|
315
|
+
},
|
|
316
|
+
getSelectedElementId: () => selectedElementId,
|
|
317
|
+
selectElement,
|
|
318
|
+
onDeselect: () => {
|
|
319
|
+
selectedElementId = null;
|
|
320
|
+
window.parent.postMessage({ type: "element-selected", visualSelectorId: null }, "*");
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
|
|
305
324
|
// Toggle visual edit mode
|
|
306
325
|
const toggleVisualEditMode = (isEnabled: boolean) => {
|
|
307
326
|
isVisualEditMode = isEnabled;
|
|
308
327
|
|
|
309
328
|
if (!isEnabled) {
|
|
329
|
+
layerController.cleanup();
|
|
310
330
|
clearHoverOverlays();
|
|
311
|
-
|
|
312
|
-
selectedOverlays.forEach((overlay) => {
|
|
313
|
-
if (overlay && overlay.parentNode) {
|
|
314
|
-
overlay.remove();
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
selectedOverlays = [];
|
|
331
|
+
clearSelectedOverlays();
|
|
318
332
|
|
|
319
333
|
currentHighlightedElements = [];
|
|
320
334
|
selectedElementId = null;
|