@base44-preview/vite-plugin 0.3.3-pr.51.d4ba9e8 → 0.3.3-pr.54.d511550

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.
@@ -33,12 +33,10 @@ export const DROPDOWN_ITEM_HOVER_BG = "#f1f5f9";
33
33
 
34
34
  export const DEPTH_INDENT_PX = 10;
35
35
 
36
- /** SVG chevron shown when dropdown is collapsed (click to expand) */
37
- export const CHEVRON_COLLAPSED = `<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="2" fill="none"/></svg>`;
38
- /** SVG chevron shown when dropdown is expanded (click to collapse) */
39
- export const CHEVRON_EXPANDED = `<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M18 15l-6-6-6 6" stroke="currentColor" stroke-width="2" fill="none"/></svg>`;
40
-
41
- export const CHEVRON_ATTR = "data-chevron";
36
+ /** Chevron shown when dropdown is collapsed (click to expand) */
37
+ export const CHEVRON_COLLAPSED = " \u25BE";
38
+ /** Chevron shown when dropdown is expanded (click to collapse) */
39
+ export const CHEVRON_EXPANDED = " \u25B4";
42
40
 
43
41
  export const BASE_PADDING_PX = 12;
44
42
 
@@ -11,7 +11,6 @@ import {
11
11
  BASE_PADDING_PX,
12
12
  CHEVRON_COLLAPSED,
13
13
  CHEVRON_EXPANDED,
14
- CHEVRON_ATTR,
15
14
  LAYER_DROPDOWN_ATTR,
16
15
  } from "./consts.js";
17
16
  import { applyStyles, getLayerDisplayName } from "./utils.js";
@@ -84,16 +83,10 @@ export function createDropdownElement(
84
83
 
85
84
  /** Add chevron indicator and pointer-events to the label */
86
85
  export function enhanceLabelWithChevron(label: HTMLDivElement): void {
87
- if (label.querySelector(`[${CHEVRON_ATTR}]`)) return;
86
+ const t = label.textContent ?? "";
87
+ if (t.endsWith(CHEVRON_COLLAPSED) || t.endsWith(CHEVRON_EXPANDED)) return;
88
88
 
89
- const chevron = document.createElement("span");
90
- chevron.setAttribute(CHEVRON_ATTR, "true");
91
- chevron.style.display = "inline-flex";
92
- chevron.innerHTML = CHEVRON_COLLAPSED;
93
- label.appendChild(chevron);
94
-
95
- label.style.display = "inline-flex";
96
- label.style.alignItems = "center";
89
+ label.textContent = t + CHEVRON_COLLAPSED;
97
90
  label.style.cursor = "pointer";
98
91
  label.style.userSelect = "none";
99
92
  label.style.whiteSpace = "nowrap";
@@ -197,9 +190,8 @@ export function showDropdown(
197
190
  overlay.appendChild(dropdown);
198
191
  activeDropdown = dropdown;
199
192
  activeLabel = label;
200
- const chevronEl = label.querySelector(`[${CHEVRON_ATTR}]`);
201
- if (chevronEl) {
202
- chevronEl.innerHTML = CHEVRON_EXPANDED;
193
+ if (label.textContent?.endsWith(CHEVRON_COLLAPSED.trim())) {
194
+ label.textContent = label.textContent.slice(0, -CHEVRON_COLLAPSED.length) + CHEVRON_EXPANDED;
203
195
  }
204
196
  activeOnHoverEnd = callbacks.onHoverEnd ?? null;
205
197
 
@@ -209,9 +201,8 @@ export function showDropdown(
209
201
 
210
202
  /** Close the active dropdown and clean up listeners */
211
203
  export function closeDropdown(): void {
212
- const chevronEl = activeLabel?.querySelector(`[${CHEVRON_ATTR}]`);
213
- if (chevronEl) {
214
- chevronEl.innerHTML = CHEVRON_COLLAPSED;
204
+ if (activeLabel?.textContent?.includes(CHEVRON_EXPANDED)) {
205
+ activeLabel.textContent = activeLabel.textContent.replace(CHEVRON_EXPANDED, CHEVRON_COLLAPSED);
215
206
  }
216
207
  activeLabel = null;
217
208
 
@@ -22,6 +22,13 @@ if (import.meta.hot) {
22
22
  suppressionTimer = null;
23
23
  }, import.meta.env.VITE_HMR_ERROR_SUPPRESSION_DELAY ?? 10000);
24
24
  });
25
+ import.meta.hot.on("vite:afterUpdate", () => {
26
+ shouldPropagateErrors = true;
27
+ if (suppressionTimer) {
28
+ clearTimeout(suppressionTimer);
29
+ suppressionTimer = null;
30
+ }
31
+ });
25
32
  import.meta.hot.on("vite:beforeFullReload", () => {
26
33
  shouldPropagateErrors = false;
27
34
  if (suppressionTimer) {
@@ -1,40 +1,3 @@
1
- const LABEL_HEIGHT = 27;
2
-
3
- /**
4
- * Positions an element-tag label relative to its highlighted overlay.
5
- *
6
- * Strategy (in priority order):
7
- * 1. If the element is near the viewport top AND tall enough (>= 2x label height),
8
- * place the label **inside** the element at the top-left.
9
- * 2. If the element is near the viewport top but too short, place the label
10
- * **below** the element.
11
- * 3. Otherwise, place the label **above** the element (default).
12
- *
13
- * For full-width elements (spanning nearly the entire viewport), the left offset
14
- * is nudged inward (6px) to prevent clipping against the viewport edge.
15
- *
16
- * @param label - The label div to position (style.top and style.left are set).
17
- * @param rect - The bounding client rect of the highlighted element.
18
- */
19
- export function positionLabel(label: HTMLDivElement, rect: DOMRect): void {
20
- const nearTop = rect.top < LABEL_HEIGHT;
21
- const tallEnough = rect.height >= LABEL_HEIGHT * 2;
22
- const isFullWidth = rect.width >= window.innerWidth - 4;
23
- const edgeLeft = isFullWidth ? "8px" : "-2px";
24
- const insideLeft = isFullWidth ? "8px" : "4px";
25
-
26
- if (nearTop && tallEnough) {
27
- label.style.top = "2px";
28
- label.style.left = insideLeft;
29
- } else if (nearTop) {
30
- label.style.top = `${rect.height + 2}px`;
31
- label.style.left = edgeLeft;
32
- } else {
33
- label.style.top = `-${LABEL_HEIGHT}px`;
34
- label.style.left = edgeLeft;
35
- }
36
- }
37
-
38
1
  /** Check if an element has instrumentation attributes */
39
2
  export function isInstrumentedElement(element: Element): boolean {
40
3
  const htmlEl = element as HTMLElement;
@@ -1,10 +1,8 @@
1
- import { findElementsById, updateElementClasses, updateElementAttribute, collectAllowedAttributes, ALLOWED_ATTRIBUTES, getElementSelectorId, stopAnimations, resumeAnimations, findInstrumentedElement, resolveHoverTarget, positionLabel } from "./utils.js";
1
+ import { findElementsById, updateElementClasses, updateElementAttribute, collectAllowedAttributes, ALLOWED_ATTRIBUTES, getElementSelectorId, stopAnimations, resumeAnimations, findInstrumentedElement, resolveHoverTarget } 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
-
8
6
  export function setupVisualEditAgent() {
9
7
  // State variables (replacing React useState/useRef)
10
8
  let isVisualEditMode = false;
@@ -14,7 +12,8 @@ export function setupVisualEditAgent() {
14
12
  let selectedOverlays: HTMLDivElement[] = [];
15
13
  let currentHighlightedElements: Element[] = [];
16
14
  let selectedElementId: string | null = null;
17
- let selectedElement: Element | null = null;
15
+
16
+ const REPOSITION_DELAY_MS = 50;
18
17
 
19
18
  // Create overlay element
20
19
  const createOverlay = (isSelected = false): HTMLDivElement => {
@@ -59,19 +58,18 @@ export function setupVisualEditAgent() {
59
58
  label = document.createElement("div");
60
59
  label.textContent = element.tagName.toLowerCase();
61
60
  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";
65
65
  label.style.fontWeight = isSelected ? "500" : "400";
66
66
  label.style.color = isSelected ? "#ffffff" : "#526cff";
67
- label.style.backgroundColor = isSelected ? "#2563EB" : "#DBEAFE";
67
+ label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
68
68
  label.style.borderRadius = "3px";
69
69
  label.style.minWidth = "24px";
70
70
  label.style.textAlign = "center";
71
71
  overlay.appendChild(label);
72
72
  }
73
-
74
- positionLabel(label, rect);
75
73
  };
76
74
 
77
75
  // --- Inline edit controller ---
@@ -84,7 +82,6 @@ export function setupVisualEditAgent() {
84
82
  inlineEdit.clearSelectedMarks(selectedElementId);
85
83
  clearSelectedOverlays();
86
84
  selectedElementId = null;
87
- selectedElement = null;
88
85
  },
89
86
  createSelectionOverlays: (elements, elementId) => {
90
87
  elements.forEach((el) => {
@@ -101,7 +98,6 @@ export function setupVisualEditAgent() {
101
98
  inlineEdit.clearSelectedMarks(selectedElementId);
102
99
  clearSelectedOverlays();
103
100
  selectedElementId = null;
104
- selectedElement = null;
105
101
  };
106
102
 
107
103
  // Clear hover overlays
@@ -184,7 +180,6 @@ export function setupVisualEditAgent() {
184
180
  });
185
181
 
186
182
  selectedElementId = visualSelectorId || null;
187
- selectedElement = element;
188
183
  clearHoverOverlays();
189
184
  notifyElementSelected(element);
190
185
 
@@ -441,9 +436,10 @@ export function setupVisualEditAgent() {
441
436
  // Handle scroll events to update popover position
442
437
  const handleScroll = () => {
443
438
  if (selectedElementId) {
444
- const element = selectedElement;
445
- if (element && element.isConnected) {
446
- const rect = element.getBoundingClientRect();
439
+ const elements = findElementsById(selectedElementId);
440
+ if (elements.length > 0) {
441
+ const element = elements[0];
442
+ const rect = element!.getBoundingClientRect();
447
443
 
448
444
  const viewportHeight = window.innerHeight;
449
445
  const viewportWidth = window.innerWidth;
@@ -547,37 +543,41 @@ export function setupVisualEditAgent() {
547
543
  break;
548
544
 
549
545
  case "request-element-position":
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
- );
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
+ }
581
581
  }
582
582
  break;
583
583