@base44-preview/vite-plugin 0.2.22-pr.36.d652cb1 → 0.2.22-pr.37.466ee63

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 (120) hide show
  1. package/dist/injections/utils.d.ts +0 -6
  2. package/dist/injections/utils.d.ts.map +1 -1
  3. package/dist/injections/utils.js +0 -25
  4. package/dist/injections/utils.js.map +1 -1
  5. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +25 -0
  6. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +1 -0
  7. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +78 -0
  8. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +1 -0
  9. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +4 -0
  10. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +1 -0
  11. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +4 -0
  12. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +1 -0
  13. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +9 -0
  14. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +1 -0
  15. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +26 -0
  16. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +1 -0
  17. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +10 -0
  18. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +1 -0
  19. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +60 -0
  20. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +1 -0
  21. package/dist/injections/visual-edit-agent/constants.d.ts +10 -0
  22. package/dist/injections/visual-edit-agent/constants.d.ts.map +1 -0
  23. package/dist/injections/visual-edit-agent/constants.js +10 -0
  24. package/dist/injections/visual-edit-agent/constants.js.map +1 -0
  25. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +10 -0
  26. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +1 -0
  27. package/dist/injections/visual-edit-agent/handlers/click-handlers.js +109 -0
  28. package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +1 -0
  29. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +14 -0
  30. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +1 -0
  31. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +64 -0
  32. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +1 -0
  33. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +14 -0
  34. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +1 -0
  35. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +99 -0
  36. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +1 -0
  37. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +26 -0
  38. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +1 -0
  39. package/dist/injections/visual-edit-agent/handlers/message-handlers.js +145 -0
  40. package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +1 -0
  41. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +7 -0
  42. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +1 -0
  43. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +42 -0
  44. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +1 -0
  45. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +11 -0
  46. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +1 -0
  47. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +33 -0
  48. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +1 -0
  49. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +86 -0
  50. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +1 -0
  51. package/dist/injections/visual-edit-agent/handlers/messages/types.js +28 -0
  52. package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +1 -0
  53. package/dist/injections/visual-edit-agent/index.d.ts +5 -0
  54. package/dist/injections/visual-edit-agent/index.d.ts.map +1 -0
  55. package/dist/injections/visual-edit-agent/index.js +100 -0
  56. package/dist/injections/visual-edit-agent/index.js.map +1 -0
  57. package/dist/injections/visual-edit-agent/state/agent-state.d.ts +17 -0
  58. package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +1 -0
  59. package/dist/injections/visual-edit-agent/state/agent-state.js +18 -0
  60. package/dist/injections/visual-edit-agent/state/agent-state.js.map +1 -0
  61. package/dist/injections/visual-edit-agent/ui/overlay.d.ts +26 -0
  62. package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +1 -0
  63. package/dist/injections/visual-edit-agent/ui/overlay.js +103 -0
  64. package/dist/injections/visual-edit-agent/ui/overlay.js.map +1 -0
  65. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +14 -0
  66. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +1 -0
  67. package/dist/injections/visual-edit-agent/utils/dom-utils.js +34 -0
  68. package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +1 -0
  69. package/dist/injections/visual-edit-agent.d.ts +1 -1
  70. package/dist/injections/visual-edit-agent.d.ts.map +1 -1
  71. package/dist/injections/visual-edit-agent.js +1 -474
  72. package/dist/injections/visual-edit-agent.js.map +1 -1
  73. package/dist/statics/index.mjs +5 -1
  74. package/dist/statics/index.mjs.map +1 -1
  75. package/package.json +1 -1
  76. package/src/injections/utils.ts +0 -34
  77. package/src/injections/visual-edit-agent/README.md +222 -0
  78. package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +100 -0
  79. package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +10 -0
  80. package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +26 -0
  81. package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +67 -0
  82. package/src/injections/visual-edit-agent/constants.ts +9 -0
  83. package/src/injections/visual-edit-agent/handlers/click-handlers.ts +135 -0
  84. package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
  85. package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +130 -0
  86. package/src/injections/visual-edit-agent/handlers/message-handlers.ts +191 -0
  87. package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +51 -0
  88. package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +41 -0
  89. package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
  90. package/src/injections/visual-edit-agent/index.ts +116 -0
  91. package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
  92. package/src/injections/visual-edit-agent/ui/overlay.ts +125 -0
  93. package/src/injections/visual-edit-agent/utils/dom-utils.ts +39 -0
  94. package/src/injections/visual-edit-agent.ts +1 -577
  95. package/dist/injections/layer-dropdown/consts.d.ts +0 -15
  96. package/dist/injections/layer-dropdown/consts.d.ts.map +0 -1
  97. package/dist/injections/layer-dropdown/consts.js +0 -36
  98. package/dist/injections/layer-dropdown/consts.js.map +0 -1
  99. package/dist/injections/layer-dropdown/controller.d.ts +0 -4
  100. package/dist/injections/layer-dropdown/controller.d.ts.map +0 -1
  101. package/dist/injections/layer-dropdown/controller.js +0 -85
  102. package/dist/injections/layer-dropdown/controller.js.map +0 -1
  103. package/dist/injections/layer-dropdown/dropdown-ui.d.ts +0 -13
  104. package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +0 -1
  105. package/dist/injections/layer-dropdown/dropdown-ui.js +0 -158
  106. package/dist/injections/layer-dropdown/dropdown-ui.js.map +0 -1
  107. package/dist/injections/layer-dropdown/types.d.ts +0 -21
  108. package/dist/injections/layer-dropdown/types.d.ts.map +0 -1
  109. package/dist/injections/layer-dropdown/types.js +0 -3
  110. package/dist/injections/layer-dropdown/types.js.map +0 -1
  111. package/dist/injections/layer-dropdown/utils.d.ts +0 -24
  112. package/dist/injections/layer-dropdown/utils.d.ts.map +0 -1
  113. package/dist/injections/layer-dropdown/utils.js +0 -150
  114. package/dist/injections/layer-dropdown/utils.js.map +0 -1
  115. package/src/injections/layer-dropdown/LAYERS.md +0 -258
  116. package/src/injections/layer-dropdown/consts.ts +0 -44
  117. package/src/injections/layer-dropdown/controller.ts +0 -105
  118. package/src/injections/layer-dropdown/dropdown-ui.ts +0 -221
  119. package/src/injections/layer-dropdown/types.ts +0 -24
  120. package/src/injections/layer-dropdown/utils.ts +0 -185
@@ -1,475 +1,2 @@
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";
4
- export function setupVisualEditAgent() {
5
- // State variables (replacing React useState/useRef)
6
- let isVisualEditMode = false;
7
- let isPopoverDragging = false;
8
- let isDropdownOpen = false;
9
- let hoverOverlays = [];
10
- let selectedOverlays = [];
11
- let currentHighlightedElements = [];
12
- let selectedElementId = null;
13
- // Create overlay element
14
- const createOverlay = (isSelected = false) => {
15
- const overlay = document.createElement("div");
16
- overlay.style.position = "absolute";
17
- overlay.style.pointerEvents = "none";
18
- overlay.style.transition = "all 0.1s ease-in-out";
19
- overlay.style.zIndex = "9999";
20
- if (isSelected) {
21
- overlay.style.border = "2px solid #2563EB";
22
- }
23
- else {
24
- overlay.style.border = "2px solid #95a5fc";
25
- overlay.style.backgroundColor = "rgba(99, 102, 241, 0.05)";
26
- }
27
- return overlay;
28
- };
29
- // Position overlay relative to element
30
- const positionOverlay = (overlay, element, isSelected = false) => {
31
- if (!element || !isVisualEditMode)
32
- return;
33
- const htmlElement = element;
34
- // Force layout recalculation
35
- void htmlElement.offsetWidth;
36
- const rect = element.getBoundingClientRect();
37
- overlay.style.top = `${rect.top + window.scrollY}px`;
38
- overlay.style.left = `${rect.left + window.scrollX}px`;
39
- overlay.style.width = `${rect.width}px`;
40
- overlay.style.height = `${rect.height}px`;
41
- // Check if label already exists in overlay
42
- let label = overlay.querySelector("div");
43
- if (!label) {
44
- label = document.createElement("div");
45
- label.textContent = element.tagName.toLowerCase();
46
- label.style.position = "absolute";
47
- label.style.top = "-27px";
48
- label.style.left = "-2px";
49
- label.style.padding = "2px 8px";
50
- label.style.fontSize = "11px";
51
- label.style.fontWeight = isSelected ? "500" : "400";
52
- label.style.color = isSelected ? "#ffffff" : "#526cff";
53
- label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
54
- label.style.borderRadius = "3px";
55
- label.style.minWidth = "24px";
56
- label.style.textAlign = "center";
57
- overlay.appendChild(label);
58
- }
59
- };
60
- // Clear hover overlays
61
- const clearHoverOverlays = () => {
62
- hoverOverlays.forEach((overlay) => {
63
- if (overlay && overlay.parentNode) {
64
- overlay.remove();
65
- }
66
- });
67
- hoverOverlays = [];
68
- currentHighlightedElements = [];
69
- };
70
- const clearSelectedOverlays = () => {
71
- selectedOverlays.forEach((overlay) => {
72
- if (overlay && overlay.parentNode) {
73
- overlay.remove();
74
- }
75
- });
76
- selectedOverlays = [];
77
- };
78
- const notifyElementSelected = (element) => {
79
- const htmlElement = element;
80
- const rect = element.getBoundingClientRect();
81
- const svgElement = element;
82
- window.parent.postMessage({
83
- type: "element-selected",
84
- tagName: element.tagName,
85
- classes: svgElement.className?.baseVal ||
86
- element.className ||
87
- "",
88
- visualSelectorId: getElementSelectorId(element),
89
- content: htmlElement.innerText,
90
- dataSourceLocation: htmlElement.dataset.sourceLocation,
91
- isDynamicContent: htmlElement.dataset.dynamicContent === "true",
92
- linenumber: htmlElement.dataset.linenumber,
93
- filename: htmlElement.dataset.filename,
94
- position: {
95
- top: rect.top,
96
- left: rect.left,
97
- right: rect.right,
98
- bottom: rect.bottom,
99
- width: rect.width,
100
- height: rect.height,
101
- centerX: rect.left + rect.width / 2,
102
- centerY: rect.top + rect.height / 2,
103
- },
104
- }, "*");
105
- };
106
- // Select an element: create overlays, update state, notify parent
107
- const selectElement = (element) => {
108
- const visualSelectorId = getElementSelectorId(element);
109
- clearSelectedOverlays();
110
- const elements = findElementsById(visualSelectorId || null);
111
- elements.forEach((el) => {
112
- const overlay = createOverlay(true);
113
- document.body.appendChild(overlay);
114
- selectedOverlays.push(overlay);
115
- positionOverlay(overlay, el, true);
116
- });
117
- selectedElementId = visualSelectorId || null;
118
- clearHoverOverlays();
119
- notifyElementSelected(element);
120
- return selectedOverlays[0];
121
- };
122
- const unSelectElement = () => {
123
- selectedElementId = null;
124
- window.parent.postMessage({ type: "unselect-element" }, "*");
125
- };
126
- // Handle mouse over event
127
- const handleMouseOver = (e) => {
128
- if (!isVisualEditMode || isPopoverDragging)
129
- return;
130
- const target = e.target;
131
- // Prevent hover effects when a dropdown is open
132
- if (isDropdownOpen) {
133
- clearHoverOverlays();
134
- return;
135
- }
136
- // Prevent hover effects on SVG path elements
137
- if (target.tagName.toLowerCase() === "path") {
138
- clearHoverOverlays();
139
- return;
140
- }
141
- // Support both data-source-location and data-visual-selector-id
142
- const element = target.closest("[data-source-location], [data-visual-selector-id]");
143
- if (!element) {
144
- clearHoverOverlays();
145
- return;
146
- }
147
- // Prefer data-source-location, fallback to data-visual-selector-id
148
- const htmlElement = element;
149
- const selectorId = htmlElement.dataset.sourceLocation ||
150
- htmlElement.dataset.visualSelectorId;
151
- // Skip if this element is already selected
152
- if (selectedElementId === selectorId) {
153
- clearHoverOverlays();
154
- return;
155
- }
156
- // Find all elements with the same ID
157
- const elements = findElementsById(selectorId || null);
158
- // Clear previous hover overlays
159
- clearHoverOverlays();
160
- // Create overlays for all matching elements
161
- elements.forEach((el) => {
162
- const overlay = createOverlay(false);
163
- document.body.appendChild(overlay);
164
- hoverOverlays.push(overlay);
165
- positionOverlay(overlay, el);
166
- });
167
- currentHighlightedElements = elements;
168
- };
169
- // Handle mouse out event
170
- const handleMouseOut = () => {
171
- if (isPopoverDragging)
172
- return;
173
- clearHoverOverlays();
174
- };
175
- // Handle element click
176
- const handleElementClick = (e) => {
177
- if (!isVisualEditMode)
178
- return;
179
- const target = e.target;
180
- // Let layer dropdown clicks pass through without interference
181
- if (target.closest(`[${LAYER_DROPDOWN_ATTR}]`))
182
- return;
183
- // Close dropdowns when clicking anywhere in iframe if a dropdown is open
184
- if (isDropdownOpen) {
185
- e.preventDefault();
186
- e.stopPropagation();
187
- e.stopImmediatePropagation();
188
- window.parent.postMessage({ type: "close-dropdowns" }, "*");
189
- return;
190
- }
191
- // Prevent clicking on SVG path elements
192
- if (target.tagName.toLowerCase() === "path") {
193
- return;
194
- }
195
- // Prevent default behavior immediately when in visual edit mode
196
- e.preventDefault();
197
- e.stopPropagation();
198
- e.stopImmediatePropagation();
199
- // Support both data-source-location and data-visual-selector-id
200
- const element = target.closest("[data-source-location], [data-visual-selector-id]");
201
- if (!element) {
202
- return;
203
- }
204
- const selectedOverlay = selectElement(element);
205
- layerController.attachToOverlay(selectedOverlay, element);
206
- };
207
- // Unselect the current element
208
- const unselectElement = () => {
209
- clearSelectedOverlays();
210
- selectedElementId = null;
211
- };
212
- const updateElementClassesAndReposition = (visualSelectorId, classes) => {
213
- const elements = findElementsById(visualSelectorId);
214
- if (elements.length === 0)
215
- return;
216
- updateElementClasses(elements, classes);
217
- // Use a small delay to allow the browser to recalculate layout before repositioning
218
- setTimeout(() => {
219
- // Reposition selected overlays
220
- if (selectedElementId === visualSelectorId) {
221
- selectedOverlays.forEach((overlay, index) => {
222
- if (index < elements.length) {
223
- positionOverlay(overlay, elements[index]);
224
- }
225
- });
226
- }
227
- // Reposition hover overlays if needed
228
- if (currentHighlightedElements.length > 0) {
229
- const hoveredElement = currentHighlightedElements[0];
230
- const hoveredId = hoveredElement?.dataset?.visualSelectorId;
231
- if (hoveredId === visualSelectorId) {
232
- hoverOverlays.forEach((overlay, index) => {
233
- if (index < currentHighlightedElements.length) {
234
- positionOverlay(overlay, currentHighlightedElements[index]);
235
- }
236
- });
237
- }
238
- }
239
- }, 50);
240
- };
241
- // Update element content by visual selector ID
242
- const updateElementContent = (visualSelectorId, content) => {
243
- const elements = findElementsById(visualSelectorId);
244
- if (elements.length === 0) {
245
- return;
246
- }
247
- elements.forEach((element) => {
248
- element.innerText = content;
249
- });
250
- setTimeout(() => {
251
- if (selectedElementId === visualSelectorId) {
252
- selectedOverlays.forEach((overlay, index) => {
253
- if (index < elements.length) {
254
- positionOverlay(overlay, elements[index]);
255
- }
256
- });
257
- }
258
- }, 50);
259
- };
260
- // --- Layer dropdown controller ---
261
- const layerController = createLayerController({
262
- createPreviewOverlay: (element) => {
263
- const overlay = createOverlay(false);
264
- overlay.style.zIndex = "9998";
265
- document.body.appendChild(overlay);
266
- positionOverlay(overlay, element);
267
- return overlay;
268
- },
269
- getSelectedElementId: () => selectedElementId,
270
- selectElement,
271
- onDeselect: unSelectElement,
272
- });
273
- // Toggle visual edit mode
274
- const toggleVisualEditMode = (isEnabled) => {
275
- isVisualEditMode = isEnabled;
276
- if (!isEnabled) {
277
- layerController.cleanup();
278
- clearHoverOverlays();
279
- clearSelectedOverlays();
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
- updateElementClassesAndReposition(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
- }
1
+ export { setupVisualEditAgent } from "./visual-edit-agent/index.js";
475
2
  //# sourceMappingURL=visual-edit-agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visual-edit-agent.js","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,UAAU,oBAAoB;IAClC,oDAAoD;IACpD,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,aAAa,GAAqB,EAAE,CAAC;IACzC,IAAI,gBAAgB,GAAqB,EAAE,CAAC;IAC5C,IAAI,0BAA0B,GAAc,EAAE,CAAC;IAC/C,IAAI,iBAAiB,GAAkB,IAAI,CAAC;IAE5C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M,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAChD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAEhD,gCAAgC;IAChC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;QACtC,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;KACvD,CAAC,CAAC;IAEH,+BAA+B;IAC/B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,yBAAyB,EAAE,EAAE,GAAG,CAAC,CAAC;AACtE,CAAC"}
1
+ {"version":3,"file":"visual-edit-agent.js","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1,2 +1,6 @@
1
- function A(e){let n=e;return!!(n.dataset?.sourceLocation||n.dataset?.visualSelectorId)}function y(e){let n=e;return n.dataset?.sourceLocation||n.dataset?.visualSelectorId||null}function w(e){if(!e)return[];let n=Array.from(document.querySelectorAll(`[data-source-location="${e}"]`));return n.length>0?n:Array.from(document.querySelectorAll(`[data-visual-selector-id="${e}"]`))}function Y(e,n){e.forEach(s=>{s.setAttribute("class",n)})}var X={position:"absolute",backgroundColor:"#ffffff",border:"1px solid #e2e8f0",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",fontSize:"12px",minWidth:"120px",maxHeight:"200px",overflowY:"auto",zIndex:"10001",padding:"4px 0",pointerEvents:"auto"},G={padding:"4px 12px",cursor:"pointer",color:"#334155",backgroundColor:"transparent",whiteSpace:"nowrap",lineHeight:"1.5",fontWeight:"400"},_="#526cff",z="#DBEAFE",F="600",R="#f1f5f9",q=10,k=" \u25BE",C="data-layer-dropdown",K=2,j=2;function W(e,n){Object.assign(e.style,n)}function U(e){return e.tagName}function J(e,n){let s=[];function a(u,i){if(!(i>n))for(let l=0;l<u.children.length;l++){let c=u.children[l];A(c)?(s.push({element:c,tagName:c.tagName.toLowerCase(),selectorId:y(c)}),a(c,i+1)):a(c,i)}}return a(e,1),s}function V(e,n){let s={element:e,tagName:e.tagName.toLowerCase(),selectorId:y(e)};return n!==void 0&&(s.depth=n),s}function ue(e){let n=[],s=e.parentElement;for(;s&&s!==document.documentElement&&s!==document.body&&n.length<K;)A(s)&&n.push(V(s)),s=s.parentElement;return n.reverse(),n}function me(e,n){return n.forEach((s,a)=>{e.push({...s,depth:a})}),n.length}function Q(e,n,s){e.push(V(n,s));let a=J(n,j);ge(n,a,s+1),e.push(...a)}function fe(e){return e.length>0?e[e.length-1].element:null}function pe(e,n){let s=J(e,1);return s.some(a=>a.element===n)||s.push(V(n)),s}function Ee(e,n,s,a){for(let u of n)u.element===s?Q(e,s,a):e.push({...u,depth:a})}function Z(e){let n=ue(e),s=[],a=me(s,n),u=fe(n);if(u){let i=pe(u,e);Ee(s,i,e,a)}else Q(s,e,a);return s}function ge(e,n,s){let a=new Set(n.map(l=>l.element)),u=new Map(n.map(l=>[l.element,l]));function i(l,c){for(let E=0;E<l.children.length;E++){let m=l.children[E];a.has(m)?(u.get(m).depth=s+c-1,i(m,c+1)):i(m,c)}}i(e,1)}var b=null,M=null,S=null,x=null;function he(e,n,s,a,u){let i=document.createElement("div");i.textContent=U(e),W(i,G);let l=e.depth??0;return l>0&&(i.style.paddingLeft=`${12+l*q}px`),n&&(i.style.color=_,i.style.backgroundColor=z,i.style.fontWeight=F),i.addEventListener("mouseenter",()=>{n||(i.style.backgroundColor=R),a&&a(e)}),i.addEventListener("mouseleave",()=>{n||(i.style.backgroundColor="transparent"),u&&u()}),i.addEventListener("click",c=>{c.stopPropagation(),c.preventDefault(),s(e)}),i}function ye(e,n,s,a,u){let i=document.createElement("div");return i.setAttribute(C,"true"),W(i,X),e.forEach(l=>{let c=l.selectorId===n;i.appendChild(he(l,c,s,a,u))}),i}function ee(e){e.textContent?.includes(k)||(e.textContent=e.textContent+k,e.style.cursor="pointer",e.style.userSelect="none",e.style.pointerEvents="auto",e.setAttribute(C,"true"))}function ve(e,n,s,a,u,i){let l=Array.from(e.children),c=n.findIndex(m=>m.selectorId===s),E=m=>{if(c>=0&&c<l.length){let g=l[c];g.style.color!==_&&(g.style.backgroundColor="transparent")}if(c=m,c>=0&&c<l.length){let g=l[c];g.style.color!==_&&(g.style.backgroundColor=R),g.scrollIntoView({block:"nearest"}),u&&u(n[c])}};x=m=>{m.key==="ArrowDown"?(m.preventDefault(),m.stopPropagation(),E(c<l.length-1?c+1:0)):m.key==="ArrowUp"?(m.preventDefault(),m.stopPropagation(),E(c>0?c-1:l.length-1)):m.key==="Enter"&&c>=0&&(m.preventDefault(),m.stopPropagation(),i&&i(),a(n[c]),L())},document.addEventListener("keydown",x,!0)}function Le(e,n){setTimeout(()=>{M=s=>{let a=s.target;!e.contains(a)&&a!==n&&L()},document.addEventListener("mousedown",M,!0)},0)}function te(e,n,s,a,u,i){L();let l=ye(n,s,E=>{i&&i(),a(E),L()},u,i),c=e.parentElement;c&&(l.style.top=`${e.offsetTop+e.offsetHeight+2}px`,l.style.left=`${e.offsetLeft}px`,c.appendChild(l),b=l,S=i??null,ve(l,n,s,a,u,i),Le(l,e))}function L(){S&&(S(),S=null),b&&b.parentNode&&b.remove(),b=null,M&&(document.removeEventListener("mousedown",M,!0),M=null),x&&(document.removeEventListener("keydown",x,!0),x=null)}function ne(){return b!==null}function oe(e){let n=null,s=null,a=null,u=()=>{n&&n.parentNode&&n.remove(),n=null},i=g=>{u(),y(g.element)!==e.getSelectedElementId()&&(n=e.createPreviewOverlay(g.element))},l=g=>{u(),L(),s&&(document.removeEventListener("keydown",s,!0),s=null),a=null;let I=e.selectElement(g.element);E(I,g.element)},c=()=>{s&&(document.removeEventListener("keydown",s,!0),s=null),a&&(l({element:a,tagName:a.tagName.toLowerCase(),selectorId:y(a)}),a=null)},E=(g,I)=>{if(!g)return;let D=g.querySelector("div");if(!D)return;let N=Z(I);if(N.length<=1)return;let H=y(I);ee(D),D.addEventListener("click",O=>{O.stopPropagation(),O.preventDefault(),ne()?(L(),c()):(a=I,e.onDeselect(),s=T=>{T.key==="Escape"&&(T.stopPropagation(),L(),c())},document.addEventListener("keydown",s,!0),te(D,N,H,l,i,u))})};return{attachToOverlay:E,cleanup:()=>{u(),L()}}}function we(){let e=!1,n=!1,s=!1,a=[],u=[],i=[],l=null,c=(r=!1)=>{let t=document.createElement("div");return t.style.position="absolute",t.style.pointerEvents="none",t.style.transition="all 0.1s ease-in-out",t.style.zIndex="9999",r?t.style.border="2px solid #2563EB":(t.style.border="2px solid #95a5fc",t.style.backgroundColor="rgba(99, 102, 241, 0.05)"),t},E=(r,t,o=!1)=>{if(!t||!e)return;t.offsetWidth;let d=t.getBoundingClientRect();r.style.top=`${d.top+window.scrollY}px`,r.style.left=`${d.left+window.scrollX}px`,r.style.width=`${d.width}px`,r.style.height=`${d.height}px`;let f=r.querySelector("div");f||(f=document.createElement("div"),f.textContent=t.tagName.toLowerCase(),f.style.position="absolute",f.style.top="-27px",f.style.left="-2px",f.style.padding="2px 8px",f.style.fontSize="11px",f.style.fontWeight=o?"500":"400",f.style.color=o?"#ffffff":"#526cff",f.style.backgroundColor=o?"#526cff":"#DBEAFE",f.style.borderRadius="3px",f.style.minWidth="24px",f.style.textAlign="center",r.appendChild(f))},m=()=>{a.forEach(r=>{r&&r.parentNode&&r.remove()}),a=[],i=[]},g=()=>{u.forEach(r=>{r&&r.parentNode&&r.remove()}),u=[]},I=r=>{let t=r,o=r.getBoundingClientRect(),p=r;window.parent.postMessage({type:"element-selected",tagName:r.tagName,classes:p.className?.baseVal||r.className||"",visualSelectorId:y(r),content:t.innerText,dataSourceLocation:t.dataset.sourceLocation,isDynamicContent:t.dataset.dynamicContent==="true",linenumber:t.dataset.linenumber,filename:t.dataset.filename,position:{top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2}},"*")},D=r=>{let t=y(r);return g(),w(t||null).forEach(p=>{let d=c(!0);document.body.appendChild(d),u.push(d),E(d,p,!0)}),l=t||null,m(),I(r),u[0]},N=()=>{l=null,window.parent.postMessage({type:"unselect-element"},"*")},H=r=>{if(!e||n)return;let t=r.target;if(s){m();return}if(t.tagName.toLowerCase()==="path"){m();return}let o=t.closest("[data-source-location], [data-visual-selector-id]");if(!o){m();return}let p=o,d=p.dataset.sourceLocation||p.dataset.visualSelectorId;if(l===d){m();return}let f=w(d||null);m(),f.forEach(h=>{let v=c(!1);document.body.appendChild(v),a.push(v),E(v,h)}),i=f},O=()=>{n||m()},T=r=>{if(!e)return;let t=r.target;if(t.closest(`[${C}]`))return;if(s){r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}if(t.tagName.toLowerCase()==="path")return;r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation();let o=t.closest("[data-source-location], [data-visual-selector-id]");if(!o)return;let p=D(o);B.attachToOverlay(p,o)},re=()=>{g(),l=null},se=(r,t)=>{let o=w(r);o.length!==0&&(Y(o,t),setTimeout(()=>{l===r&&u.forEach((p,d)=>{d<o.length&&E(p,o[d])}),i.length>0&&i[0]?.dataset?.visualSelectorId===r&&a.forEach((f,h)=>{h<i.length&&E(f,i[h])})},50))},le=(r,t)=>{let o=w(r);o.length!==0&&(o.forEach(p=>{p.innerText=t}),setTimeout(()=>{l===r&&u.forEach((p,d)=>{d<o.length&&E(p,o[d])})},50))},B=oe({createPreviewOverlay:r=>{let t=c(!1);return t.style.zIndex="9998",document.body.appendChild(t),E(t,r),t},getSelectedElementId:()=>l,selectElement:D,onDeselect:N}),ie=r=>{e=r,r?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",H),document.addEventListener("mouseout",O),document.addEventListener("click",T,!0)):(B.cleanup(),m(),g(),i=[],l=null,document.body.style.cursor="default",document.removeEventListener("mouseover",H),document.removeEventListener("mouseout",O),document.removeEventListener("click",T,!0))},$=()=>{if(l){let r=w(l);if(r.length>0){let o=r[0].getBoundingClientRect(),p=window.innerHeight,d=window.innerWidth,f=o.top<p&&o.bottom>0&&o.left<d&&o.right>0,h={top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2};window.parent.postMessage({type:"element-position-update",position:h,isInViewport:f,visualSelectorId:l},"*")}}},ae=r=>{let t=r.data;switch(t.type){case"toggle-visual-edit-mode":ie(t.data.enabled);break;case"update-classes":t.data&&t.data.classes!==void 0?se(t.data.visualSelectorId,t.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",t);break;case"unselect-element":re();break;case"refresh-page":window.location.reload();break;case"update-content":t.data&&t.data.content!==void 0?le(t.data.visualSelectorId,t.data.content):console.warn("[VisualEditAgent] Invalid update-content message:",t);break;case"request-element-position":if(l){let o=w(l);if(o.length>0){let d=o[0].getBoundingClientRect(),f=window.innerHeight,h=window.innerWidth,v=d.top<f&&d.bottom>0&&d.left<h&&d.right>0,de={top:d.top,left:d.left,right:d.right,bottom:d.bottom,width:d.width,height:d.height,centerX:d.left+d.width/2,centerY:d.top+d.height/2};window.parent.postMessage({type:"element-position-update",position:de,isInViewport:v,visualSelectorId:l},"*")}}break;case"popover-drag-state":t.data&&t.data.isDragging!==void 0&&(n=t.data.isDragging,t.data.isDragging&&m());break;case"dropdown-state":t.data&&t.data.isOpen!==void 0&&(s=t.data.isOpen,t.data.isOpen&&m());break;default:break}},P=()=>{if(l){let r=w(l);u.forEach((t,o)=>{o<r.length&&E(t,r[o])})}i.length>0&&a.forEach((r,t)=>{t<i.length&&E(r,i[t])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((r,t)=>{let o=r,p=`visual-id-${o.dataset.filename}-${o.dataset.linenumber}-${t}`;o.dataset.visualSelectorId=p});let ce=new MutationObserver(r=>{r.some(o=>{let p=f=>{if(f.nodeType===Node.ELEMENT_NODE){let h=f;if(h.dataset&&h.dataset.visualSelectorId)return!0;for(let v=0;v<h.children.length;v++)if(p(h.children[v]))return!0}return!1};return o.type==="attributes"&&(o.attributeName==="style"||o.attributeName==="class"||o.attributeName==="width"||o.attributeName==="height")&&p(o.target)})&&setTimeout(P,50)});window.addEventListener("message",ae),window.addEventListener("scroll",$,!0),document.addEventListener("scroll",$,!0),window.addEventListener("resize",P),window.addEventListener("scroll",P),ce.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{we as setupVisualEditAgent};
1
+ function P(){return{isVisualEditMode:!1,isPopoverDragging:!1,isDropdownOpen:!1,hoverOverlays:[],selectedOverlays:[],currentHighlightedElements:[],selectedElementId:null,currentEditingElement:null,debouncedSendTimeout:null,isInlineEditExperimentEnabled:!1}}function a(e){if(!e)return[];let t=Array.from(document.querySelectorAll(`[data-source-location="${e}"]`));return t.length>0?t:Array.from(document.querySelectorAll(`[data-visual-selector-id="${e}"]`))}function H(e,t){e.forEach(n=>{n.setAttribute("class",t)})}var V="all 0.1s ease-in-out",U="9999",G="#2563EB",B="#95a5fc",k="rgba(99, 102, 241, 0.05)",F="-27px",j="-2px";function f(e=!1){let t=document.createElement("div");return t.style.position="absolute",t.style.pointerEvents="none",t.style.transition=V,t.style.zIndex=U,e?t.style.border=`2px solid ${G}`:(t.style.border=`2px solid ${B}`,t.style.backgroundColor=k),t}function m(e,t,n=!1,o=!0){if(!t||!o)return;t.offsetWidth;let l=t.getBoundingClientRect();e.style.top=`${l.top+window.scrollY}px`,e.style.left=`${l.left+window.scrollX}px`,e.style.width=`${l.width}px`,e.style.height=`${l.height}px`;let i=e.querySelector("div");i||(i=document.createElement("div"),i.textContent=t.tagName.toLowerCase(),i.style.position="absolute",i.style.top=F,i.style.left=j,i.style.padding="2px 8px",i.style.fontSize="11px",i.style.fontWeight=n?"500":"400",i.style.color=n?"#ffffff":"#526cff",i.style.backgroundColor=n?"#526cff":"#DBEAFE",i.style.borderRadius="3px",i.style.minWidth="24px",i.style.textAlign="center",e.appendChild(i))}function S(e){e.forEach(t=>{t&&t.parentNode&&t.remove()})}function T(e){e.selectedElementId&&a(e.selectedElementId).forEach(n=>{n instanceof HTMLElement&&delete n.dataset.selected}),S(e.selectedOverlays),e.selectedOverlays=[],e.selectedElementId=null}function u(e){if(!e.selectedElementId)return;let t=a(e.selectedElementId);e.selectedOverlays.forEach((n,o)=>{o<t.length&&m(n,t[o],!0,e.isVisualEditMode)})}function O(e){e.hoverOverlays.forEach((t,n)=>{n<e.currentHighlightedElements.length&&m(t,e.currentHighlightedElements[n],!1,e.isVisualEditMode)})}function s(e){S(e.hoverOverlays),e.hoverOverlays=[],e.currentHighlightedElements=[]}function W(e,t){if(!e.isVisualEditMode||e.isPopoverDragging||e.currentEditingElement)return;let n=t.target;if(e.isDropdownOpen){s(e);return}if(n.tagName.toLowerCase()==="path"){s(e);return}let o=n.closest("[data-source-location], [data-visual-selector-id]");if(!o){s(e);return}let r=o,l=r.dataset.sourceLocation||r.dataset.visualSelectorId;if(e.selectedElementId===l){s(e);return}let i=a(l||null);s(e),i.forEach(d=>{let c=f(!1);document.body.appendChild(c),e.hoverOverlays.push(c),m(c,d,!1,e.isVisualEditMode)}),e.currentHighlightedElements=i}function Y(e){e.isPopoverDragging||e.currentEditingElement||s(e)}function y(){if(document.getElementById("visual-edit-focus-styles"))return;let t=document.createElement("style");t.id="visual-edit-focus-styles",t.textContent=`
2
+ [data-selected="true"][contenteditable="true"]:focus {
3
+ outline: none !important;
4
+ }
5
+ `,document.head.appendChild(t)}function M(){let e=document.getElementById("visual-edit-focus-styles");e&&e.remove()}function L(e){let t=document.createRange();t.selectNodeContents(e);let n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)}function x(e){return!(!(e instanceof HTMLElement)||!["div","p","h1","h2","h3","h4","h5","h6","span","li","td","a","button","label"].includes(e.tagName.toLowerCase())||(e.textContent?.trim()||"").length===0||e.querySelector("img, video, canvas, svg")!==null||e.children.length>0||e.dataset.dynamicContent==="true")}var b=null;function A(e){b=e}function $(e){b&&b(this)}function p(e){return!(!(e instanceof HTMLElement)||e.dataset.selected!=="true"||!x(e))}function _(e){y(),e.dataset.originalTextContent=e.textContent||"",e.dataset.originalCursor=e.style.cursor,e.contentEditable="true",e.addEventListener("input",$),e.style.cursor="text",L(e),setTimeout(()=>{e.focus()},0)}function C(e){M(),e.removeEventListener("input",$),e.contentEditable="false",delete e.dataset.originalTextContent,e.dataset.originalCursor!==void 0&&(e.style.cursor=e.dataset.originalCursor,delete e.dataset.originalCursor)}function g(e){return{top:e.top,left:e.left,right:e.right,bottom:e.bottom,width:e.width,height:e.height,centerX:e.left+e.width/2,centerY:e.top+e.height/2}}function q(e){return e.top<window.innerHeight&&e.bottom>0&&e.left<window.innerWidth&&e.right>0}function v(e){return e instanceof SVGElement?e.className?.baseVal||"":e.className||""}function I(e,t){e.currentEditingElement=t,e.selectedOverlays.forEach(n=>{n.style.display="none"}),_(t),window.parent.postMessage({type:"content-editing-started",visualSelectorId:e.selectedElementId},"*")}function E(e){if(!e.currentEditingElement)return;let t=e.currentEditingElement;C(t),e.selectedOverlays.forEach(n=>{n.style.display=""}),u(e),window.parent.postMessage({type:"content-editing-ended",visualSelectorId:e.selectedElementId},"*"),e.currentEditingElement=null}function oe(e,t){let n=t.dataset.originalTextContent,o=t.textContent,r={tagName:t.tagName,classes:v(t),visualSelectorId:e.selectedElementId,content:o,dataSourceLocation:t.dataset.sourceLocation,isDynamicContent:t.dataset.dynamicContent==="true",linenumber:t.dataset.linenumber,filename:t.dataset.filename,position:g(t.getBoundingClientRect())};window.parent.postMessage({type:"inline-edit",elementInfo:r,originalContent:n,newContent:o},"*"),t.dataset.originalTextContent=o||""}function ie(e,t){e.debouncedSendTimeout&&clearTimeout(e.debouncedSendTimeout),e.debouncedSendTimeout=setTimeout(()=>{oe(e,t)},500)}function re(e){return t=>{u(e),ie(e,t)}}function z(e){A(re(e))}function le(e,t){e.isVisualEditMode=t,t?document.body.style.cursor="crosshair":(e.currentEditingElement&&E(e),s(e),T(e),e.currentHighlightedElements=[],document.body.style.cursor="default")}function X(e,t){le(e,t.data.enabled),t.data.specs?.newInlineEditEnabled!==void 0&&(e.isInlineEditExperimentEnabled=t.data.specs.newInlineEditEnabled,console.log("[VisualEditAgent] Inline edit experiment:",e.isInlineEditExperimentEnabled))}function K(e,t){if(!e.isInlineEditExperimentEnabled){console.log("[VisualEditAgent] toggle-inline-edit-mode ignored - experiment flag not enabled");return}if(console.log("[VisualEditAgent] Processing toggle-inline-edit-mode message"),!t.data||!t.data.dataSourceLocation){console.warn("[VisualEditAgent] Invalid toggle-inline-edit-mode message - missing dataSourceLocation");return}let n=a(t.data.dataSourceLocation);if(n.length===0||!(n[0]instanceof HTMLElement))return;let o=n[0];t.data.inlineEditingMode?p(o)&&(e.selectedElementId!==t.data.dataSourceLocation&&N(e,o,t.data.dataSourceLocation),I(e,o)):e.currentEditingElement===o&&E(e)}function Z(e){if(!e.selectedElementId)return;let t=a(e.selectedElementId);if(t.length===0)return;let o=t[0].getBoundingClientRect();window.parent.postMessage({type:"element-position-update",position:g(o),isInViewport:q(o),visualSelectorId:e.selectedElementId},"*")}function w(e){e.currentEditingElement&&E(e),T(e)}function ae(e,t,n){let o=a(t);o.length!==0&&(H(o,n),setTimeout(()=>{e.selectedElementId===t&&u(e),e.currentHighlightedElements.length>0&&e.currentHighlightedElements[0]?.dataset?.visualSelectorId===t&&O(e)},50))}function se(e,t,n){let o=a(t);o.length!==0&&(o.forEach(r=>{r.innerText=n}),setTimeout(()=>{e.selectedElementId===t&&u(e)},50))}function R(e){Z(e)}function h(e){u(e),O(e)}function J(e,t){let n=t.data;switch(n.type){case"toggle-visual-edit-mode":X(e,n);break;case"update-classes":n.data&&n.data.classes!==void 0?ae(e,n.data.visualSelectorId,n.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",n);break;case"unselect-element":w(e);break;case"refresh-page":window.location.reload();break;case"update-content":n.data&&n.data.content!==void 0?se(e,n.data.visualSelectorId,n.data.content):console.warn("[VisualEditAgent] Invalid update-content message:",n);break;case"toggle-inline-edit-mode":K(e,n);break;case"request-element-position":Z(e);break;case"popover-drag-state":n.data&&n.data.isDragging!==void 0&&(e.isPopoverDragging=n.data.isDragging,n.data.isDragging&&s(e));break;case"dropdown-state":n.data&&n.data.isOpen!==void 0&&(e.isDropdownOpen=n.data.isOpen,n.data.isOpen&&s(e));break;default:break}}function N(e,t,n){w(e);let o=a(n);o.forEach(i=>{i instanceof HTMLElement&&(i.dataset.selected="true")}),o.forEach(i=>{let d=f(!0);document.body.appendChild(d),e.selectedOverlays.push(d),m(d,i,!0,e.isVisualEditMode)}),e.selectedElementId=n,s(e);let r=t,l={type:"element-selected",tagName:t.tagName,classes:v(t),visualSelectorId:n,content:r.innerText,dataSourceLocation:r.dataset.sourceLocation,isDynamicContent:r.dataset.dynamicContent==="true",linenumber:r.dataset.linenumber,filename:r.dataset.filename,position:g(t.getBoundingClientRect())};window.parent.postMessage(l,"*")}function ee(e,t){if(!e.isVisualEditMode)return;let n=t.target;if(n instanceof HTMLElement&&n.contentEditable==="true")return;if(e.currentEditingElement){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),E(e);return}if(e.isDropdownOpen){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}if(n.tagName.toLowerCase()==="path")return;t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();let o=n.closest("[data-source-location], [data-visual-selector-id]");if(!o)return;let r=o,l=r.dataset.sourceLocation||r.dataset.visualSelectorId;if(e.selectedElementId===l&&r.dataset.selected==="true")if(e.isInlineEditExperimentEnabled&&p(r)){console.log("[VisualEditAgent] Entering inline edit mode"),I(e,r);return}else e.isInlineEditExperimentEnabled||console.log("[VisualEditAgent] Inline edit disabled - experiment flag not enabled");N(e,o,l||null)}function de(){document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((t,n)=>{let o=t,r=`visual-id-${o.dataset.filename}-${o.dataset.linenumber}-${n}`;o.dataset.visualSelectorId=r})}function Ee(e){return new MutationObserver(t=>{t.some(o=>{let r=i=>{if(i.nodeType===Node.ELEMENT_NODE){let d=i;if(d.dataset&&d.dataset.visualSelectorId)return!0;for(let c=0;c<d.children.length;c++)if(r(d.children[c]))return!0}return!1};return o.type==="attributes"&&(o.attributeName==="style"||o.attributeName==="class"||o.attributeName==="width"||o.attributeName==="height")&&r(o.target)})&&setTimeout(e,50)})}function ce(){document.addEventListener("keydown",e=>{e.target instanceof HTMLElement&&e.target.contentEditable},!0)}function ue(e){window.addEventListener("message",t=>J(e,t)),window.addEventListener("scroll",()=>R(e),!0),document.addEventListener("scroll",()=>R(e),!0),window.addEventListener("resize",()=>h(e)),window.addEventListener("scroll",()=>h(e)),document.addEventListener("click",t=>ee(e,t),!0),document.addEventListener("mouseover",t=>W(e,t)),document.addEventListener("mouseout",()=>Y(e))}function te(){let e=P();de(),z(e),ce(),ue(e),Ee(()=>h(e)).observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{te as setupVisualEditAgent};
2
6
  //# sourceMappingURL=index.mjs.map