@base44-preview/vite-plugin 0.2.22-pr.36.69a0b76 → 0.2.22-pr.36.8002ffd

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.
@@ -47,17 +47,18 @@ export function getInstrumentedDescendants(
47
47
  return result;
48
48
  }
49
49
 
50
- /**
51
- * Build the layer chain for the dropdown:
52
- *
53
- * Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
54
- * Current – the selected element.
55
- * Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
56
- *
57
- * Each item carries a `depth` for visual indentation.
58
- */
59
- export function buildLayerChain(selectedElement: Element): LayerInfo[] {
60
- // --- Parents (walk up, collect at most MAX_PARENT_DEPTH) ---
50
+ function toLayerInfo(element: Element, depth?: number): LayerInfo {
51
+ const info: LayerInfo = {
52
+ element,
53
+ tagName: element.tagName.toLowerCase(),
54
+ selectorId: getElementSelectorId(element),
55
+ };
56
+ if (depth !== undefined) info.depth = depth;
57
+ return info;
58
+ }
59
+
60
+ /** Collect instrumented ancestors from selected element up to MAX_PARENT_DEPTH (outermost first). */
61
+ function collectInstrumentedParents(selectedElement: Element): LayerInfo[] {
61
62
  const parents: LayerInfo[] = [];
62
63
  let current = selectedElement.parentElement;
63
64
  while (
@@ -67,44 +68,90 @@ export function buildLayerChain(selectedElement: Element): LayerInfo[] {
67
68
  parents.length < MAX_PARENT_DEPTH
68
69
  ) {
69
70
  if (isInstrumentedElement(current)) {
70
- parents.push({
71
- element: current,
72
- tagName: current.tagName.toLowerCase(),
73
- selectorId: getElementSelectorId(current),
74
- });
71
+ parents.push(toLayerInfo(current));
75
72
  }
76
73
  current = current.parentElement;
77
74
  }
78
- // Reverse so outermost parent comes first
79
75
  parents.reverse();
76
+ return parents;
77
+ }
80
78
 
81
- // --- Build the chain with depth ---
82
- const chain: LayerInfo[] = [];
83
- const baseDepth = 0;
84
-
85
- // Parents: depth 0, 1, …
79
+ /** Append parents to chain with depth 0, 1, …; returns depth of selected (parents.length). */
80
+ function appendParentsWithDepth(chain: LayerInfo[], parents: LayerInfo[]): number {
86
81
  parents.forEach((p, i) => {
87
- chain.push({ ...p, depth: baseDepth + i });
88
- });
89
-
90
- // Self
91
- const selfDepth = parents.length;
92
- chain.push({
93
- element: selectedElement,
94
- tagName: selectedElement.tagName.toLowerCase(),
95
- selectorId: getElementSelectorId(selectedElement),
96
- depth: selfDepth,
82
+ chain.push({ ...p, depth: i });
97
83
  });
84
+ return parents.length;
85
+ }
98
86
 
99
- // Children: up to MAX_CHILD_DEPTH instrumented levels below selected
87
+ /** Append selected element and its descendants at the given depth. */
88
+ function appendSelfAndDescendants(
89
+ chain: LayerInfo[],
90
+ selectedElement: Element,
91
+ selfDepth: number
92
+ ): void {
93
+ chain.push(toLayerInfo(selectedElement, selfDepth));
100
94
  const descendants = getInstrumentedDescendants(
101
95
  selectedElement,
102
96
  MAX_CHILD_DEPTH
103
97
  );
104
- // Assign visual depth: we need to track the instrumented nesting to set depth correctly
105
98
  assignDescendantDepths(selectedElement, descendants, selfDepth + 1);
106
-
107
99
  chain.push(...descendants);
100
+ }
101
+
102
+ /** Get the innermost instrumented parent's DOM element, or null if none. */
103
+ function getImmediateInstrParent(parents: LayerInfo[]): Element | null {
104
+ return parents.length > 0 ? parents[parents.length - 1]!.element : null;
105
+ }
106
+
107
+ /** Collect instrumented siblings of the selected element from its parent (DOM order). */
108
+ function collectSiblings(parent: Element, selectedElement: Element): LayerInfo[] {
109
+ const siblings = getInstrumentedDescendants(parent, 1);
110
+ if (!siblings.some((s) => s.element === selectedElement)) {
111
+ siblings.push(toLayerInfo(selectedElement));
112
+ }
113
+ return siblings;
114
+ }
115
+
116
+ /** Append siblings at selfDepth, expanding children only for the selected element. */
117
+ function appendSiblingsWithSelected(
118
+ chain: LayerInfo[],
119
+ siblings: LayerInfo[],
120
+ selectedElement: Element,
121
+ selfDepth: number
122
+ ): void {
123
+ for (const sibling of siblings) {
124
+ if (sibling.element === selectedElement) {
125
+ appendSelfAndDescendants(chain, selectedElement, selfDepth);
126
+ } else {
127
+ chain.push({ ...sibling, depth: selfDepth });
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Build the layer chain for the dropdown:
134
+ *
135
+ * Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
136
+ * Siblings – instrumented children of the immediate parent, at the same depth.
137
+ * Current – the selected element (highlighted), with children expanded.
138
+ * Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
139
+ *
140
+ * Each item carries a `depth` for visual indentation.
141
+ */
142
+ export function buildLayerChain(selectedElement: Element): LayerInfo[] {
143
+ const parents = collectInstrumentedParents(selectedElement);
144
+ const chain: LayerInfo[] = [];
145
+ const selfDepth = appendParentsWithDepth(chain, parents);
146
+
147
+ const instrParent = getImmediateInstrParent(parents);
148
+ if (instrParent) {
149
+ const siblings = collectSiblings(instrParent, selectedElement);
150
+ appendSiblingsWithSelected(chain, siblings, selectedElement, selfDepth);
151
+ } else {
152
+ appendSelfAndDescendants(chain, selectedElement, selfDepth);
153
+ }
154
+
108
155
  return chain;
109
156
  }
110
157
 
@@ -140,6 +140,11 @@ export function setupVisualEditAgent() {
140
140
  return selectedOverlays[0];
141
141
  };
142
142
 
143
+ const unSelectElement = (): void => {
144
+ selectedElementId = null;
145
+ window.parent.postMessage({ type: "unselect-element" }, "*");
146
+ };
147
+
143
148
  // Handle mouse over event
144
149
  const handleMouseOver = (e: MouseEvent) => {
145
150
  if (!isVisualEditMode || isPopoverDragging) return;
@@ -315,10 +320,7 @@ export function setupVisualEditAgent() {
315
320
  },
316
321
  getSelectedElementId: () => selectedElementId,
317
322
  selectElement,
318
- onDeselect: () => {
319
- selectedElementId = null;
320
- window.parent.postMessage({ type: "element-selected", visualSelectorId: null }, "*");
321
- },
323
+ onDeselect: unSelectElement,
322
324
  });
323
325
 
324
326
  // Toggle visual edit mode