@base44-preview/vite-plugin 0.3.3-pr.50.daf0b05 → 0.3.3-pr.51.07c7470

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.
@@ -1,8 +1,10 @@
1
- import { findElementsById, updateElementClasses, updateElementAttribute, collectAllowedAttributes, ALLOWED_ATTRIBUTES, getElementSelectorId, stopAnimations, resumeAnimations, findInstrumentedElement, resolveHoverTarget } from "./utils.js";
1
+ import { findElementsById, updateElementClasses, updateElementAttribute, collectAllowedAttributes, ALLOWED_ATTRIBUTES, getElementSelectorId, stopAnimations, resumeAnimations, findInstrumentedElement, resolveHoverTarget, positionLabel } from "./utils.js";
2
2
  import { createLayerController } from "./layer-dropdown/controller.js";
3
3
  import { LAYER_DROPDOWN_ATTR } from "./layer-dropdown/consts.js";
4
4
  import { createInlineEditController } from "../capabilities/inline-edit/index.js";
5
5
 
6
+ const REPOSITION_DELAY_MS = 50;
7
+
6
8
  export function setupVisualEditAgent() {
7
9
  // State variables (replacing React useState/useRef)
8
10
  let isVisualEditMode = false;
@@ -12,8 +14,7 @@ export function setupVisualEditAgent() {
12
14
  let selectedOverlays: HTMLDivElement[] = [];
13
15
  let currentHighlightedElements: Element[] = [];
14
16
  let selectedElementId: string | null = null;
15
-
16
- const REPOSITION_DELAY_MS = 50;
17
+ let selectedElement: Element | null = null;
17
18
 
18
19
  // Create overlay element
19
20
  const createOverlay = (isSelected = false): HTMLDivElement => {
@@ -58,7 +59,6 @@ export function setupVisualEditAgent() {
58
59
  label = document.createElement("div");
59
60
  label.textContent = element.tagName.toLowerCase();
60
61
  label.style.position = "absolute";
61
- label.style.top = "-27px";
62
62
  label.style.left = "-2px";
63
63
  label.style.padding = "2px 8px";
64
64
  label.style.fontSize = "11px";
@@ -70,6 +70,8 @@ export function setupVisualEditAgent() {
70
70
  label.style.textAlign = "center";
71
71
  overlay.appendChild(label);
72
72
  }
73
+
74
+ positionLabel(label, rect);
73
75
  };
74
76
 
75
77
  // --- Inline edit controller ---
@@ -82,6 +84,7 @@ export function setupVisualEditAgent() {
82
84
  inlineEdit.clearSelectedMarks(selectedElementId);
83
85
  clearSelectedOverlays();
84
86
  selectedElementId = null;
87
+ selectedElement = null;
85
88
  },
86
89
  createSelectionOverlays: (elements, elementId) => {
87
90
  elements.forEach((el) => {
@@ -98,6 +101,7 @@ export function setupVisualEditAgent() {
98
101
  inlineEdit.clearSelectedMarks(selectedElementId);
99
102
  clearSelectedOverlays();
100
103
  selectedElementId = null;
104
+ selectedElement = null;
101
105
  };
102
106
 
103
107
  // Clear hover overlays
@@ -180,6 +184,7 @@ export function setupVisualEditAgent() {
180
184
  });
181
185
 
182
186
  selectedElementId = visualSelectorId || null;
187
+ selectedElement = element;
183
188
  clearHoverOverlays();
184
189
  notifyElementSelected(element);
185
190
 
@@ -436,10 +441,9 @@ export function setupVisualEditAgent() {
436
441
  // Handle scroll events to update popover position
437
442
  const handleScroll = () => {
438
443
  if (selectedElementId) {
439
- const elements = findElementsById(selectedElementId);
440
- if (elements.length > 0) {
441
- const element = elements[0];
442
- const rect = element!.getBoundingClientRect();
444
+ const element = selectedElement;
445
+ if (element && element.isConnected) {
446
+ const rect = element.getBoundingClientRect();
443
447
 
444
448
  const viewportHeight = window.innerHeight;
445
449
  const viewportWidth = window.innerWidth;
@@ -543,41 +547,37 @@ export function setupVisualEditAgent() {
543
547
  break;
544
548
 
545
549
  case "request-element-position":
546
- if (selectedElementId) {
547
- const elements = findElementsById(selectedElementId);
548
- if (elements.length > 0) {
549
- const element = elements[0];
550
- const rect = element!.getBoundingClientRect();
551
-
552
- const viewportHeight = window.innerHeight;
553
- const viewportWidth = window.innerWidth;
554
- const isInViewport =
555
- rect.top < viewportHeight &&
556
- rect.bottom > 0 &&
557
- rect.left < viewportWidth &&
558
- rect.right > 0;
559
-
560
- const elementPosition = {
561
- top: rect.top,
562
- left: rect.left,
563
- right: rect.right,
564
- bottom: rect.bottom,
565
- width: rect.width,
566
- height: rect.height,
567
- centerX: rect.left + rect.width / 2,
568
- centerY: rect.top + rect.height / 2,
569
- };
570
-
571
- window.parent.postMessage(
572
- {
573
- type: "element-position-update",
574
- position: elementPosition,
575
- isInViewport: isInViewport,
576
- visualSelectorId: selectedElementId,
577
- },
578
- "*"
579
- );
580
- }
550
+ if (selectedElementId && selectedElement && selectedElement.isConnected) {
551
+ const rect = selectedElement.getBoundingClientRect();
552
+
553
+ const viewportHeight = window.innerHeight;
554
+ const viewportWidth = window.innerWidth;
555
+ const isInViewport =
556
+ rect.top < viewportHeight &&
557
+ rect.bottom > 0 &&
558
+ rect.left < viewportWidth &&
559
+ rect.right > 0;
560
+
561
+ const elementPosition = {
562
+ top: rect.top,
563
+ left: rect.left,
564
+ right: rect.right,
565
+ bottom: rect.bottom,
566
+ width: rect.width,
567
+ height: rect.height,
568
+ centerX: rect.left + rect.width / 2,
569
+ centerY: rect.top + rect.height / 2,
570
+ };
571
+
572
+ window.parent.postMessage(
573
+ {
574
+ type: "element-position-update",
575
+ position: elementPosition,
576
+ isInViewport: isInViewport,
577
+ visualSelectorId: selectedElementId,
578
+ },
579
+ "*"
580
+ );
581
581
  }
582
582
  break;
583
583