@base44-preview/vite-plugin 0.2.8-dev.52445d0 → 0.2.11-pr.16.45158ce
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/html-injections-plugin.d.ts +5 -1
- package/dist/html-injections-plugin.d.ts.map +1 -1
- package/dist/html-injections-plugin.js +37 -1
- package/dist/html-injections-plugin.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/injections/navigation-notifier.d.ts +2 -0
- package/dist/injections/navigation-notifier.d.ts.map +1 -0
- package/dist/injections/navigation-notifier.js +34 -0
- package/dist/injections/navigation-notifier.js.map +1 -0
- package/dist/injections/sandbox-hmr-notifier.d.ts +2 -0
- package/dist/injections/sandbox-hmr-notifier.d.ts.map +1 -0
- package/dist/injections/sandbox-hmr-notifier.js +10 -0
- package/dist/injections/sandbox-hmr-notifier.js.map +1 -0
- package/dist/injections/visual-edit-agent.d.ts +2 -0
- package/dist/injections/visual-edit-agent.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent.js +476 -0
- package/dist/injections/visual-edit-agent.js.map +1 -0
- package/package.json +1 -1
- package/src/html-injections-plugin.ts +45 -1
- package/src/index.ts +10 -2
- package/src/injections/navigation-notifier.ts +43 -0
- package/src/injections/sandbox-hmr-notifier.ts +8 -0
- package/src/injections/visual-edit-agent.ts +582 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
if (window.self !== window.top) {
|
|
2
|
+
// State variables (replacing React useState/useRef)
|
|
3
|
+
let isVisualEditMode = false;
|
|
4
|
+
let isPopoverDragging = false;
|
|
5
|
+
let isDropdownOpen = false;
|
|
6
|
+
let hoverOverlays = [];
|
|
7
|
+
let selectedOverlays = [];
|
|
8
|
+
let currentHighlightedElements = [];
|
|
9
|
+
let selectedElementId = null;
|
|
10
|
+
// Create overlay element
|
|
11
|
+
const createOverlay = (isSelected = false) => {
|
|
12
|
+
const overlay = document.createElement("div");
|
|
13
|
+
overlay.style.position = "absolute";
|
|
14
|
+
overlay.style.pointerEvents = "none";
|
|
15
|
+
overlay.style.transition = "all 0.1s ease-in-out";
|
|
16
|
+
overlay.style.zIndex = "9999";
|
|
17
|
+
if (isSelected) {
|
|
18
|
+
overlay.style.border = "2px solid #2563EB";
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
overlay.style.border = "2px solid #95a5fc";
|
|
22
|
+
overlay.style.backgroundColor = "rgba(99, 102, 241, 0.05)";
|
|
23
|
+
}
|
|
24
|
+
return overlay;
|
|
25
|
+
};
|
|
26
|
+
// Position overlay relative to element
|
|
27
|
+
const positionOverlay = (overlay, element, isSelected = false) => {
|
|
28
|
+
if (!element || !isVisualEditMode)
|
|
29
|
+
return;
|
|
30
|
+
const htmlElement = element;
|
|
31
|
+
// Force layout recalculation
|
|
32
|
+
void htmlElement.offsetWidth;
|
|
33
|
+
const rect = element.getBoundingClientRect();
|
|
34
|
+
overlay.style.top = `${rect.top + window.scrollY}px`;
|
|
35
|
+
overlay.style.left = `${rect.left + window.scrollX}px`;
|
|
36
|
+
overlay.style.width = `${rect.width}px`;
|
|
37
|
+
overlay.style.height = `${rect.height}px`;
|
|
38
|
+
// Check if label already exists in overlay
|
|
39
|
+
let label = overlay.querySelector("div");
|
|
40
|
+
if (!label) {
|
|
41
|
+
label = document.createElement("div");
|
|
42
|
+
label.textContent = element.tagName.toLowerCase();
|
|
43
|
+
label.style.position = "absolute";
|
|
44
|
+
label.style.top = "-27px";
|
|
45
|
+
label.style.left = "-2px";
|
|
46
|
+
label.style.padding = "2px 8px";
|
|
47
|
+
label.style.fontSize = "11px";
|
|
48
|
+
label.style.fontWeight = isSelected ? "500" : "400";
|
|
49
|
+
label.style.color = isSelected ? "#ffffff" : "#526cff";
|
|
50
|
+
label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
|
|
51
|
+
label.style.borderRadius = "3px";
|
|
52
|
+
label.style.minWidth = "24px";
|
|
53
|
+
label.style.textAlign = "center";
|
|
54
|
+
overlay.appendChild(label);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// Find elements by ID - first try data-source-location, fallback to data-visual-selector-id
|
|
58
|
+
const findElementsById = (id) => {
|
|
59
|
+
if (!id)
|
|
60
|
+
return [];
|
|
61
|
+
const sourceElements = Array.from(document.querySelectorAll(`[data-source-location="${id}"]`));
|
|
62
|
+
if (sourceElements.length > 0) {
|
|
63
|
+
return sourceElements;
|
|
64
|
+
}
|
|
65
|
+
return Array.from(document.querySelectorAll(`[data-visual-selector-id="${id}"]`));
|
|
66
|
+
};
|
|
67
|
+
// Clear hover overlays
|
|
68
|
+
const clearHoverOverlays = () => {
|
|
69
|
+
hoverOverlays.forEach((overlay) => {
|
|
70
|
+
if (overlay && overlay.parentNode) {
|
|
71
|
+
overlay.remove();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
hoverOverlays = [];
|
|
75
|
+
currentHighlightedElements = [];
|
|
76
|
+
};
|
|
77
|
+
// Handle mouse over event
|
|
78
|
+
const handleMouseOver = (e) => {
|
|
79
|
+
if (!isVisualEditMode || isPopoverDragging)
|
|
80
|
+
return;
|
|
81
|
+
const target = e.target;
|
|
82
|
+
// Prevent hover effects when a dropdown is open
|
|
83
|
+
if (isDropdownOpen) {
|
|
84
|
+
clearHoverOverlays();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Prevent hover effects on SVG path elements
|
|
88
|
+
if (target.tagName.toLowerCase() === "path") {
|
|
89
|
+
clearHoverOverlays();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// Support both data-source-location and data-visual-selector-id
|
|
93
|
+
const element = target.closest("[data-source-location], [data-visual-selector-id]");
|
|
94
|
+
if (!element) {
|
|
95
|
+
clearHoverOverlays();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Prefer data-source-location, fallback to data-visual-selector-id
|
|
99
|
+
const htmlElement = element;
|
|
100
|
+
const selectorId = htmlElement.dataset.sourceLocation ||
|
|
101
|
+
htmlElement.dataset.visualSelectorId;
|
|
102
|
+
// Skip if this element is already selected
|
|
103
|
+
if (selectedElementId === selectorId) {
|
|
104
|
+
clearHoverOverlays();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Find all elements with the same ID
|
|
108
|
+
const elements = findElementsById(selectorId || null);
|
|
109
|
+
// Clear previous hover overlays
|
|
110
|
+
clearHoverOverlays();
|
|
111
|
+
// Create overlays for all matching elements
|
|
112
|
+
elements.forEach((el) => {
|
|
113
|
+
const overlay = createOverlay(false);
|
|
114
|
+
document.body.appendChild(overlay);
|
|
115
|
+
hoverOverlays.push(overlay);
|
|
116
|
+
positionOverlay(overlay, el);
|
|
117
|
+
});
|
|
118
|
+
currentHighlightedElements = elements;
|
|
119
|
+
};
|
|
120
|
+
// Handle mouse out event
|
|
121
|
+
const handleMouseOut = () => {
|
|
122
|
+
if (isPopoverDragging)
|
|
123
|
+
return;
|
|
124
|
+
clearHoverOverlays();
|
|
125
|
+
};
|
|
126
|
+
// Handle element click
|
|
127
|
+
const handleElementClick = (e) => {
|
|
128
|
+
if (!isVisualEditMode)
|
|
129
|
+
return;
|
|
130
|
+
const target = e.target;
|
|
131
|
+
// Close dropdowns when clicking anywhere in iframe if a dropdown is open
|
|
132
|
+
if (isDropdownOpen) {
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
e.stopImmediatePropagation();
|
|
136
|
+
window.parent.postMessage({ type: "close-dropdowns" }, "*");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Prevent clicking on SVG path elements
|
|
140
|
+
if (target.tagName.toLowerCase() === "path") {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Prevent default behavior immediately when in visual edit mode
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
e.stopImmediatePropagation();
|
|
147
|
+
// Support both data-source-location and data-visual-selector-id
|
|
148
|
+
const element = target.closest("[data-source-location], [data-visual-selector-id]");
|
|
149
|
+
if (!element) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const htmlElement = element;
|
|
153
|
+
const visualSelectorId = htmlElement.dataset.sourceLocation ||
|
|
154
|
+
htmlElement.dataset.visualSelectorId;
|
|
155
|
+
// Clear any existing selected overlays
|
|
156
|
+
selectedOverlays.forEach((overlay) => {
|
|
157
|
+
if (overlay && overlay.parentNode) {
|
|
158
|
+
overlay.remove();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
selectedOverlays = [];
|
|
162
|
+
// Find all elements with the same ID
|
|
163
|
+
const elements = findElementsById(visualSelectorId || null);
|
|
164
|
+
// Create selected overlays for all matching elements
|
|
165
|
+
elements.forEach((el) => {
|
|
166
|
+
const overlay = createOverlay(true);
|
|
167
|
+
document.body.appendChild(overlay);
|
|
168
|
+
selectedOverlays.push(overlay);
|
|
169
|
+
positionOverlay(overlay, el, true);
|
|
170
|
+
});
|
|
171
|
+
selectedElementId = visualSelectorId || null;
|
|
172
|
+
// Clear hover overlays
|
|
173
|
+
clearHoverOverlays();
|
|
174
|
+
// Calculate element position for popover positioning
|
|
175
|
+
const rect = element.getBoundingClientRect();
|
|
176
|
+
const elementPosition = {
|
|
177
|
+
top: rect.top,
|
|
178
|
+
left: rect.left,
|
|
179
|
+
right: rect.right,
|
|
180
|
+
bottom: rect.bottom,
|
|
181
|
+
width: rect.width,
|
|
182
|
+
height: rect.height,
|
|
183
|
+
centerX: rect.left + rect.width / 2,
|
|
184
|
+
centerY: rect.top + rect.height / 2,
|
|
185
|
+
};
|
|
186
|
+
// Send message to parent window with element info including position
|
|
187
|
+
const svgElement = element;
|
|
188
|
+
const elementData = {
|
|
189
|
+
type: "element-selected",
|
|
190
|
+
tagName: element.tagName,
|
|
191
|
+
classes: svgElement.className?.baseVal ||
|
|
192
|
+
element.className ||
|
|
193
|
+
"",
|
|
194
|
+
visualSelectorId: visualSelectorId,
|
|
195
|
+
content: element.innerText,
|
|
196
|
+
dataSourceLocation: htmlElement.dataset.sourceLocation,
|
|
197
|
+
isDynamicContent: htmlElement.dataset.dynamicContent === "true",
|
|
198
|
+
linenumber: htmlElement.dataset.linenumber,
|
|
199
|
+
filename: htmlElement.dataset.filename,
|
|
200
|
+
position: elementPosition,
|
|
201
|
+
};
|
|
202
|
+
window.parent.postMessage(elementData, "*");
|
|
203
|
+
};
|
|
204
|
+
// Unselect the current element
|
|
205
|
+
const unselectElement = () => {
|
|
206
|
+
selectedOverlays.forEach((overlay) => {
|
|
207
|
+
if (overlay && overlay.parentNode) {
|
|
208
|
+
overlay.remove();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
selectedOverlays = [];
|
|
212
|
+
selectedElementId = null;
|
|
213
|
+
};
|
|
214
|
+
// Update element classes by visual selector ID
|
|
215
|
+
// Note: Parent window is responsible for class merging (twMerge).
|
|
216
|
+
// This function receives the final computed class string.
|
|
217
|
+
const updateElementClasses = (visualSelectorId, classes) => {
|
|
218
|
+
const elements = findElementsById(visualSelectorId);
|
|
219
|
+
if (elements.length === 0) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Update classes for all matching elements
|
|
223
|
+
elements.forEach((element) => {
|
|
224
|
+
element.className = classes;
|
|
225
|
+
});
|
|
226
|
+
// Use a small delay to allow the browser to recalculate layout before repositioning
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
// Reposition selected overlays
|
|
229
|
+
if (selectedElementId === visualSelectorId) {
|
|
230
|
+
selectedOverlays.forEach((overlay, index) => {
|
|
231
|
+
if (index < elements.length) {
|
|
232
|
+
positionOverlay(overlay, elements[index]);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// Reposition hover overlays if needed
|
|
237
|
+
if (currentHighlightedElements.length > 0) {
|
|
238
|
+
const hoveredElement = currentHighlightedElements[0];
|
|
239
|
+
const hoveredId = hoveredElement?.dataset?.visualSelectorId;
|
|
240
|
+
if (hoveredId === visualSelectorId) {
|
|
241
|
+
hoverOverlays.forEach((overlay, index) => {
|
|
242
|
+
if (index < currentHighlightedElements.length) {
|
|
243
|
+
positionOverlay(overlay, currentHighlightedElements[index]);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, 50);
|
|
249
|
+
};
|
|
250
|
+
// Update element content by visual selector ID
|
|
251
|
+
const updateElementContent = (visualSelectorId, content) => {
|
|
252
|
+
const elements = findElementsById(visualSelectorId);
|
|
253
|
+
if (elements.length === 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
elements.forEach((element) => {
|
|
257
|
+
element.innerText = content;
|
|
258
|
+
});
|
|
259
|
+
setTimeout(() => {
|
|
260
|
+
if (selectedElementId === visualSelectorId) {
|
|
261
|
+
selectedOverlays.forEach((overlay, index) => {
|
|
262
|
+
if (index < elements.length) {
|
|
263
|
+
positionOverlay(overlay, elements[index]);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}, 50);
|
|
268
|
+
};
|
|
269
|
+
// Toggle visual edit mode
|
|
270
|
+
const toggleVisualEditMode = (isEnabled) => {
|
|
271
|
+
isVisualEditMode = isEnabled;
|
|
272
|
+
if (!isEnabled) {
|
|
273
|
+
clearHoverOverlays();
|
|
274
|
+
selectedOverlays.forEach((overlay) => {
|
|
275
|
+
if (overlay && overlay.parentNode) {
|
|
276
|
+
overlay.remove();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
selectedOverlays = [];
|
|
280
|
+
currentHighlightedElements = [];
|
|
281
|
+
selectedElementId = null;
|
|
282
|
+
document.body.style.cursor = "default";
|
|
283
|
+
document.removeEventListener("mouseover", handleMouseOver);
|
|
284
|
+
document.removeEventListener("mouseout", handleMouseOut);
|
|
285
|
+
document.removeEventListener("click", handleElementClick, true);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
document.body.style.cursor = "crosshair";
|
|
289
|
+
document.addEventListener("mouseover", handleMouseOver);
|
|
290
|
+
document.addEventListener("mouseout", handleMouseOut);
|
|
291
|
+
document.addEventListener("click", handleElementClick, true);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
// Handle scroll events to update popover position
|
|
295
|
+
const handleScroll = () => {
|
|
296
|
+
if (selectedElementId) {
|
|
297
|
+
const elements = findElementsById(selectedElementId);
|
|
298
|
+
if (elements.length > 0) {
|
|
299
|
+
const element = elements[0];
|
|
300
|
+
const rect = element.getBoundingClientRect();
|
|
301
|
+
const viewportHeight = window.innerHeight;
|
|
302
|
+
const viewportWidth = window.innerWidth;
|
|
303
|
+
const isInViewport = rect.top < viewportHeight &&
|
|
304
|
+
rect.bottom > 0 &&
|
|
305
|
+
rect.left < viewportWidth &&
|
|
306
|
+
rect.right > 0;
|
|
307
|
+
const elementPosition = {
|
|
308
|
+
top: rect.top,
|
|
309
|
+
left: rect.left,
|
|
310
|
+
right: rect.right,
|
|
311
|
+
bottom: rect.bottom,
|
|
312
|
+
width: rect.width,
|
|
313
|
+
height: rect.height,
|
|
314
|
+
centerX: rect.left + rect.width / 2,
|
|
315
|
+
centerY: rect.top + rect.height / 2,
|
|
316
|
+
};
|
|
317
|
+
window.parent.postMessage({
|
|
318
|
+
type: "element-position-update",
|
|
319
|
+
position: elementPosition,
|
|
320
|
+
isInViewport: isInViewport,
|
|
321
|
+
visualSelectorId: selectedElementId,
|
|
322
|
+
}, "*");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
// Handle messages from parent window
|
|
327
|
+
const handleMessage = (event) => {
|
|
328
|
+
const message = event.data;
|
|
329
|
+
switch (message.type) {
|
|
330
|
+
case "toggle-visual-edit-mode":
|
|
331
|
+
toggleVisualEditMode(message.data.enabled);
|
|
332
|
+
break;
|
|
333
|
+
case "update-classes":
|
|
334
|
+
if (message.data && message.data.classes !== undefined) {
|
|
335
|
+
updateElementClasses(message.data.visualSelectorId, message.data.classes);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
console.warn("[VisualEditAgent] Invalid update-classes message:", message);
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
case "unselect-element":
|
|
342
|
+
unselectElement();
|
|
343
|
+
break;
|
|
344
|
+
case "refresh-page":
|
|
345
|
+
window.location.reload();
|
|
346
|
+
break;
|
|
347
|
+
case "update-content":
|
|
348
|
+
if (message.data && message.data.content !== undefined) {
|
|
349
|
+
updateElementContent(message.data.visualSelectorId, message.data.content);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
console.warn("[VisualEditAgent] Invalid update-content message:", message);
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
case "request-element-position":
|
|
356
|
+
if (selectedElementId) {
|
|
357
|
+
const elements = findElementsById(selectedElementId);
|
|
358
|
+
if (elements.length > 0) {
|
|
359
|
+
const element = elements[0];
|
|
360
|
+
const rect = element.getBoundingClientRect();
|
|
361
|
+
const viewportHeight = window.innerHeight;
|
|
362
|
+
const viewportWidth = window.innerWidth;
|
|
363
|
+
const isInViewport = rect.top < viewportHeight &&
|
|
364
|
+
rect.bottom > 0 &&
|
|
365
|
+
rect.left < viewportWidth &&
|
|
366
|
+
rect.right > 0;
|
|
367
|
+
const elementPosition = {
|
|
368
|
+
top: rect.top,
|
|
369
|
+
left: rect.left,
|
|
370
|
+
right: rect.right,
|
|
371
|
+
bottom: rect.bottom,
|
|
372
|
+
width: rect.width,
|
|
373
|
+
height: rect.height,
|
|
374
|
+
centerX: rect.left + rect.width / 2,
|
|
375
|
+
centerY: rect.top + rect.height / 2,
|
|
376
|
+
};
|
|
377
|
+
window.parent.postMessage({
|
|
378
|
+
type: "element-position-update",
|
|
379
|
+
position: elementPosition,
|
|
380
|
+
isInViewport: isInViewport,
|
|
381
|
+
visualSelectorId: selectedElementId,
|
|
382
|
+
}, "*");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
case "popover-drag-state":
|
|
387
|
+
if (message.data && message.data.isDragging !== undefined) {
|
|
388
|
+
isPopoverDragging = message.data.isDragging;
|
|
389
|
+
if (message.data.isDragging) {
|
|
390
|
+
clearHoverOverlays();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
case "dropdown-state":
|
|
395
|
+
if (message.data && message.data.isOpen !== undefined) {
|
|
396
|
+
isDropdownOpen = message.data.isOpen;
|
|
397
|
+
if (message.data.isOpen) {
|
|
398
|
+
clearHoverOverlays();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
default:
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
// Handle window resize to reposition overlays
|
|
407
|
+
const handleResize = () => {
|
|
408
|
+
if (selectedElementId) {
|
|
409
|
+
const elements = findElementsById(selectedElementId);
|
|
410
|
+
selectedOverlays.forEach((overlay, index) => {
|
|
411
|
+
if (index < elements.length) {
|
|
412
|
+
positionOverlay(overlay, elements[index]);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
if (currentHighlightedElements.length > 0) {
|
|
417
|
+
hoverOverlays.forEach((overlay, index) => {
|
|
418
|
+
if (index < currentHighlightedElements.length) {
|
|
419
|
+
positionOverlay(overlay, currentHighlightedElements[index]);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
// Initialize: Add IDs to elements that don't have them but have linenumbers
|
|
425
|
+
const elementsWithLineNumber = document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])");
|
|
426
|
+
elementsWithLineNumber.forEach((el, index) => {
|
|
427
|
+
const htmlEl = el;
|
|
428
|
+
const id = `visual-id-${htmlEl.dataset.filename}-${htmlEl.dataset.linenumber}-${index}`;
|
|
429
|
+
htmlEl.dataset.visualSelectorId = id;
|
|
430
|
+
});
|
|
431
|
+
// Create mutation observer to detect layout changes
|
|
432
|
+
const mutationObserver = new MutationObserver((mutations) => {
|
|
433
|
+
const needsUpdate = mutations.some((mutation) => {
|
|
434
|
+
const hasVisualId = (node) => {
|
|
435
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
436
|
+
const el = node;
|
|
437
|
+
if (el.dataset && el.dataset.visualSelectorId) {
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
for (let i = 0; i < el.children.length; i++) {
|
|
441
|
+
if (hasVisualId(el.children[i])) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
};
|
|
448
|
+
const isLayoutChange = mutation.type === "attributes" &&
|
|
449
|
+
(mutation.attributeName === "style" ||
|
|
450
|
+
mutation.attributeName === "class" ||
|
|
451
|
+
mutation.attributeName === "width" ||
|
|
452
|
+
mutation.attributeName === "height");
|
|
453
|
+
return isLayoutChange && hasVisualId(mutation.target);
|
|
454
|
+
});
|
|
455
|
+
if (needsUpdate) {
|
|
456
|
+
setTimeout(handleResize, 50);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
// Set up event listeners
|
|
460
|
+
window.addEventListener("message", handleMessage);
|
|
461
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
462
|
+
document.addEventListener("scroll", handleScroll, true);
|
|
463
|
+
window.addEventListener("resize", handleResize);
|
|
464
|
+
window.addEventListener("scroll", handleResize);
|
|
465
|
+
// Start observing DOM mutations
|
|
466
|
+
mutationObserver.observe(document.body, {
|
|
467
|
+
attributes: true,
|
|
468
|
+
childList: true,
|
|
469
|
+
subtree: true,
|
|
470
|
+
attributeFilter: ["style", "class", "width", "height"],
|
|
471
|
+
});
|
|
472
|
+
// Send ready message to parent
|
|
473
|
+
window.parent.postMessage({ type: "visual-edit-agent-ready" }, "*");
|
|
474
|
+
}
|
|
475
|
+
export {};
|
|
476
|
+
//# sourceMappingURL=visual-edit-agent.js.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
5
|
+
navigationNotifier,
|
|
6
|
+
visualEditAgent,
|
|
7
|
+
}: {
|
|
8
|
+
hmrNotifier: boolean;
|
|
9
|
+
navigationNotifier: boolean;
|
|
10
|
+
visualEditAgent: boolean;
|
|
11
|
+
}) {
|
|
4
12
|
return {
|
|
5
13
|
name: "html-injections",
|
|
6
14
|
apply: (config) => config.mode !== "production",
|
|
@@ -22,6 +30,42 @@ export function htmlInjectionsPlugin() {
|
|
|
22
30
|
},
|
|
23
31
|
injectTo: "body",
|
|
24
32
|
},
|
|
33
|
+
...(hmrNotifier
|
|
34
|
+
? [
|
|
35
|
+
{
|
|
36
|
+
tag: "script",
|
|
37
|
+
attrs: {
|
|
38
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/sandbox-hmr-notifier.js",
|
|
39
|
+
type: "module",
|
|
40
|
+
},
|
|
41
|
+
injectTo: "head",
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
: []),
|
|
45
|
+
...(navigationNotifier
|
|
46
|
+
? [
|
|
47
|
+
{
|
|
48
|
+
tag: "script",
|
|
49
|
+
attrs: {
|
|
50
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/navigation-notifier.js",
|
|
51
|
+
type: "module",
|
|
52
|
+
},
|
|
53
|
+
injectTo: "head",
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
: []),
|
|
57
|
+
...(visualEditAgent
|
|
58
|
+
? [
|
|
59
|
+
{
|
|
60
|
+
tag: "script",
|
|
61
|
+
attrs: {
|
|
62
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/visual-edit-agent.js",
|
|
63
|
+
type: "module",
|
|
64
|
+
},
|
|
65
|
+
injectTo: "body",
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
: []),
|
|
25
69
|
];
|
|
26
70
|
},
|
|
27
71
|
} as Plugin;
|
package/src/index.ts
CHANGED
|
@@ -10,9 +10,17 @@ const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
|
|
|
10
10
|
export default function vitePlugin(
|
|
11
11
|
opts: {
|
|
12
12
|
legacySDKImports?: boolean;
|
|
13
|
+
hmrNotifier?: boolean;
|
|
14
|
+
navigationNotifier?: boolean;
|
|
15
|
+
visualEditAgent?: boolean;
|
|
13
16
|
} = {}
|
|
14
17
|
) {
|
|
15
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
legacySDKImports = false,
|
|
20
|
+
hmrNotifier = false,
|
|
21
|
+
navigationNotifier = false,
|
|
22
|
+
visualEditAgent = false,
|
|
23
|
+
} = opts;
|
|
16
24
|
|
|
17
25
|
return [
|
|
18
26
|
{
|
|
@@ -182,7 +190,7 @@ export default function vitePlugin(
|
|
|
182
190
|
} as Plugin,
|
|
183
191
|
errorOverlayPlugin(),
|
|
184
192
|
visualEditPlugin(),
|
|
185
|
-
htmlInjectionsPlugin(),
|
|
193
|
+
htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent }),
|
|
186
194
|
]
|
|
187
195
|
: []),
|
|
188
196
|
];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
if (window.self !== window.top) {
|
|
2
|
+
let lastUrl = window.location.href;
|
|
3
|
+
|
|
4
|
+
function notifyNavigation() {
|
|
5
|
+
const currentUrl = window.location.href;
|
|
6
|
+
if (currentUrl !== lastUrl) {
|
|
7
|
+
lastUrl = currentUrl;
|
|
8
|
+
window.parent?.postMessage(
|
|
9
|
+
{
|
|
10
|
+
type: "app_changed_url",
|
|
11
|
+
url: currentUrl,
|
|
12
|
+
},
|
|
13
|
+
"*"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Intercept history.pushState
|
|
19
|
+
const originalPushState = history.pushState.bind(history);
|
|
20
|
+
history.pushState = function (...args) {
|
|
21
|
+
originalPushState(...args);
|
|
22
|
+
notifyNavigation();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Intercept history.replaceState
|
|
26
|
+
const originalReplaceState = history.replaceState.bind(history);
|
|
27
|
+
history.replaceState = function (...args) {
|
|
28
|
+
originalReplaceState(...args);
|
|
29
|
+
notifyNavigation();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Handle browser back/forward navigation
|
|
33
|
+
window.addEventListener("popstate", notifyNavigation);
|
|
34
|
+
|
|
35
|
+
// Notify initial URL on load
|
|
36
|
+
window.parent?.postMessage(
|
|
37
|
+
{
|
|
38
|
+
type: "app_changed_url",
|
|
39
|
+
url: window.location.href,
|
|
40
|
+
},
|
|
41
|
+
"*"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
if (import.meta.hot) {
|
|
2
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
3
|
+
window.parent?.postMessage({ type: "sandbox:beforeUpdate" }, "*");
|
|
4
|
+
});
|
|
5
|
+
import.meta.hot.on("vite:afterUpdate", () => {
|
|
6
|
+
window.parent?.postMessage({ type: "sandbox:afterUpdate" }, "*");
|
|
7
|
+
});
|
|
8
|
+
}
|