@base44-preview/vite-plugin 0.2.21-pr.35.60ab963 → 0.2.22-pr.36.16dc064
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 +80 -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 +90 -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,71 @@ 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
|
+
|
|
143
|
+
const unSelectElement = (): void => {
|
|
144
|
+
selectedElementId = null;
|
|
145
|
+
window.parent.postMessage({ type: "unselect-element" }, "*");
|
|
146
|
+
};
|
|
147
|
+
|
|
81
148
|
// Handle mouse over event
|
|
82
149
|
const handleMouseOver = (e: MouseEvent) => {
|
|
83
150
|
if (!isVisualEditMode || isPopoverDragging) return;
|
|
@@ -146,6 +213,9 @@ export function setupVisualEditAgent() {
|
|
|
146
213
|
|
|
147
214
|
const target = e.target as Element;
|
|
148
215
|
|
|
216
|
+
// Let layer dropdown clicks pass through without interference
|
|
217
|
+
if (target.closest(`[${LAYER_DROPDOWN_ATTR}]`)) return;
|
|
218
|
+
|
|
149
219
|
// Close dropdowns when clicking anywhere in iframe if a dropdown is open
|
|
150
220
|
if (isDropdownOpen) {
|
|
151
221
|
e.preventDefault();
|
|
@@ -174,76 +244,13 @@ export function setupVisualEditAgent() {
|
|
|
174
244
|
return;
|
|
175
245
|
}
|
|
176
246
|
|
|
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, "*");
|
|
247
|
+
const selectedOverlay = selectElement(element);
|
|
248
|
+
layerController.attachToOverlay(selectedOverlay, element);
|
|
237
249
|
};
|
|
238
250
|
|
|
239
251
|
// Unselect the current element
|
|
240
252
|
const unselectElement = () => {
|
|
241
|
-
|
|
242
|
-
if (overlay && overlay.parentNode) {
|
|
243
|
-
overlay.remove();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
selectedOverlays = [];
|
|
253
|
+
clearSelectedOverlays();
|
|
247
254
|
selectedElementId = null;
|
|
248
255
|
};
|
|
249
256
|
|
|
@@ -302,19 +309,28 @@ export function setupVisualEditAgent() {
|
|
|
302
309
|
}, 50);
|
|
303
310
|
};
|
|
304
311
|
|
|
312
|
+
// --- Layer dropdown controller ---
|
|
313
|
+
const layerController = createLayerController({
|
|
314
|
+
createPreviewOverlay: (element: Element) => {
|
|
315
|
+
const overlay = createOverlay(false);
|
|
316
|
+
overlay.style.zIndex = "9998";
|
|
317
|
+
document.body.appendChild(overlay);
|
|
318
|
+
positionOverlay(overlay, element);
|
|
319
|
+
return overlay;
|
|
320
|
+
},
|
|
321
|
+
getSelectedElementId: () => selectedElementId,
|
|
322
|
+
selectElement,
|
|
323
|
+
onDeselect: unSelectElement,
|
|
324
|
+
});
|
|
325
|
+
|
|
305
326
|
// Toggle visual edit mode
|
|
306
327
|
const toggleVisualEditMode = (isEnabled: boolean) => {
|
|
307
328
|
isVisualEditMode = isEnabled;
|
|
308
329
|
|
|
309
330
|
if (!isEnabled) {
|
|
331
|
+
layerController.cleanup();
|
|
310
332
|
clearHoverOverlays();
|
|
311
|
-
|
|
312
|
-
selectedOverlays.forEach((overlay) => {
|
|
313
|
-
if (overlay && overlay.parentNode) {
|
|
314
|
-
overlay.remove();
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
selectedOverlays = [];
|
|
333
|
+
clearSelectedOverlays();
|
|
318
334
|
|
|
319
335
|
currentHighlightedElements = [];
|
|
320
336
|
selectedElementId = null;
|