@base44-preview/vite-plugin 0.2.22-pr.36.69a0b76 → 0.2.22-pr.36.6dec368

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 (36) hide show
  1. package/dist/injections/layer-dropdown/consts.d.ts +5 -1
  2. package/dist/injections/layer-dropdown/consts.d.ts.map +1 -1
  3. package/dist/injections/layer-dropdown/consts.js +5 -1
  4. package/dist/injections/layer-dropdown/consts.js.map +1 -1
  5. package/dist/injections/layer-dropdown/controller.d.ts +2 -2
  6. package/dist/injections/layer-dropdown/controller.d.ts.map +1 -1
  7. package/dist/injections/layer-dropdown/controller.js +37 -34
  8. package/dist/injections/layer-dropdown/controller.js.map +1 -1
  9. package/dist/injections/layer-dropdown/dropdown-ui.d.ts +3 -3
  10. package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +1 -1
  11. package/dist/injections/layer-dropdown/dropdown-ui.js +31 -17
  12. package/dist/injections/layer-dropdown/dropdown-ui.js.map +1 -1
  13. package/dist/injections/layer-dropdown/types.d.ts +6 -1
  14. package/dist/injections/layer-dropdown/types.d.ts.map +1 -1
  15. package/dist/injections/layer-dropdown/utils.d.ts +4 -2
  16. package/dist/injections/layer-dropdown/utils.d.ts.map +1 -1
  17. package/dist/injections/layer-dropdown/utils.js +75 -57
  18. package/dist/injections/layer-dropdown/utils.js.map +1 -1
  19. package/dist/injections/utils.d.ts +0 -2
  20. package/dist/injections/utils.d.ts.map +1 -1
  21. package/dist/injections/utils.js +0 -13
  22. package/dist/injections/utils.js.map +1 -1
  23. package/dist/injections/visual-edit-agent.d.ts.map +1 -1
  24. package/dist/injections/visual-edit-agent.js +8 -7
  25. package/dist/injections/visual-edit-agent.js.map +1 -1
  26. package/dist/statics/index.mjs +1 -1
  27. package/dist/statics/index.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/src/injections/layer-dropdown/LAYERS.md +258 -0
  30. package/src/injections/layer-dropdown/consts.ts +6 -1
  31. package/src/injections/layer-dropdown/controller.ts +40 -36
  32. package/src/injections/layer-dropdown/dropdown-ui.ts +35 -28
  33. package/src/injections/layer-dropdown/types.ts +7 -1
  34. package/src/injections/layer-dropdown/utils.ts +88 -64
  35. package/src/injections/utils.ts +0 -16
  36. package/src/injections/visual-edit-agent.ts +9 -7
@@ -15,14 +15,26 @@ export function getLayerDisplayName(layer: LayerInfo): string {
15
15
  return layer.tagName;
16
16
  }
17
17
 
18
+ function toLayerInfo(element: Element, depth?: number): LayerInfo {
19
+ const info: LayerInfo = {
20
+ element,
21
+ tagName: element.tagName.toLowerCase(),
22
+ selectorId: getElementSelectorId(element),
23
+ };
24
+ if (depth !== undefined) info.depth = depth;
25
+ return info;
26
+ }
27
+
18
28
  /**
19
29
  * Collect instrumented descendants up to `maxDepth` instrumented nesting levels.
20
30
  * Non-instrumented wrappers are walked through without counting toward depth.
21
31
  * Results are in DOM order.
32
+ * When `startDepth` is provided, assigns `depth` to each item during collection.
22
33
  */
23
34
  export function getInstrumentedDescendants(
24
35
  parent: Element,
25
- maxDepth: number
36
+ maxDepth: number,
37
+ startDepth?: number
26
38
  ): LayerInfo[] {
27
39
  const result: LayerInfo[] = [];
28
40
 
@@ -31,11 +43,15 @@ export function getInstrumentedDescendants(
31
43
  for (let i = 0; i < el.children.length; i++) {
32
44
  const child = el.children[i]!;
33
45
  if (isInstrumentedElement(child)) {
34
- result.push({
46
+ const info: LayerInfo = {
35
47
  element: child,
36
48
  tagName: child.tagName.toLowerCase(),
37
49
  selectorId: getElementSelectorId(child),
38
- });
50
+ };
51
+ if (startDepth !== undefined) {
52
+ info.depth = startDepth + instrDepth - 1;
53
+ }
54
+ result.push(info);
39
55
  walk(child, instrDepth + 1);
40
56
  } else {
41
57
  walk(child, instrDepth);
@@ -47,17 +63,8 @@ export function getInstrumentedDescendants(
47
63
  return result;
48
64
  }
49
65
 
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) ---
66
+ /** Collect instrumented ancestors from selected element up to MAX_PARENT_DEPTH (outermost first). */
67
+ function collectInstrumentedParents(selectedElement: Element): LayerInfo[] {
61
68
  const parents: LayerInfo[] = [];
62
69
  let current = selectedElement.parentElement;
63
70
  while (
@@ -67,72 +74,89 @@ export function buildLayerChain(selectedElement: Element): LayerInfo[] {
67
74
  parents.length < MAX_PARENT_DEPTH
68
75
  ) {
69
76
  if (isInstrumentedElement(current)) {
70
- parents.push({
71
- element: current,
72
- tagName: current.tagName.toLowerCase(),
73
- selectorId: getElementSelectorId(current),
74
- });
77
+ parents.push(toLayerInfo(current));
75
78
  }
76
79
  current = current.parentElement;
77
80
  }
78
- // Reverse so outermost parent comes first
79
81
  parents.reverse();
82
+ return parents;
83
+ }
80
84
 
81
- // --- Build the chain with depth ---
82
- const chain: LayerInfo[] = [];
83
- const baseDepth = 0;
84
-
85
- // Parents: depth 0, 1, …
85
+ /** Add parents to chain with depth 0, 1, …; returns depth of selected (parents.length). */
86
+ function addParentsToChain(chain: LayerInfo[], parents: LayerInfo[]): number {
86
87
  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,
88
+ chain.push({ ...p, depth: i });
97
89
  });
90
+ return parents.length;
91
+ }
98
92
 
99
- // Children: up to MAX_CHILD_DEPTH instrumented levels below selected
93
+ /** Add selected element and its descendants at the given depth. */
94
+ function addSelfAndDescendantsToChain(
95
+ chain: LayerInfo[],
96
+ selectedElement: Element,
97
+ selfDepth: number
98
+ ): void {
99
+ chain.push(toLayerInfo(selectedElement, selfDepth));
100
100
  const descendants = getInstrumentedDescendants(
101
101
  selectedElement,
102
- MAX_CHILD_DEPTH
102
+ MAX_CHILD_DEPTH,
103
+ selfDepth + 1
103
104
  );
104
- // Assign visual depth: we need to track the instrumented nesting to set depth correctly
105
- assignDescendantDepths(selectedElement, descendants, selfDepth + 1);
106
-
107
105
  chain.push(...descendants);
108
- return chain;
109
106
  }
110
107
 
111
- /**
112
- * Walk the DOM tree again to assign correct visual depth to each descendant.
113
- * This avoids storing depth during collection and keeps the API simple.
114
- */
115
- function assignDescendantDepths(
116
- root: Element,
117
- descendants: LayerInfo[],
118
- startDepth: number
119
- ): void {
120
- // Build a set for O(1) lookup
121
- const descSet = new Set(descendants.map((d) => d.element));
122
- // Map element → LayerInfo for mutation
123
- const descMap = new Map(descendants.map((d) => [d.element, d]));
108
+ /** Get the innermost instrumented parent's DOM element, or null if none. */
109
+ function getImmediateInstrParent(parents: LayerInfo[]): Element | null {
110
+ return parents.at(-1)?.element ?? null;
111
+ }
124
112
 
125
- function walk(el: Element, instrDepth: number): void {
126
- for (let i = 0; i < el.children.length; i++) {
127
- const child = el.children[i]!;
128
- if (descSet.has(child)) {
129
- descMap.get(child)!.depth = startDepth + instrDepth - 1;
130
- walk(child, instrDepth + 1);
131
- } else {
132
- walk(child, instrDepth);
133
- }
113
+ /** Collect instrumented siblings of the selected element from its parent (DOM order). */
114
+ function collectSiblings(parent: Element, selectedElement: Element): LayerInfo[] {
115
+ const siblings = getInstrumentedDescendants(parent, 1);
116
+ if (!siblings.some((s) => s.element === selectedElement)) {
117
+ siblings.push(toLayerInfo(selectedElement));
118
+ }
119
+ return siblings;
120
+ }
121
+
122
+ /** Add siblings at selfDepth, expanding children only for the selected element. */
123
+ function appendSiblingsWithSelected(
124
+ chain: LayerInfo[],
125
+ siblings: LayerInfo[],
126
+ selectedElement: Element,
127
+ selfDepth: number
128
+ ): void {
129
+ for (const sibling of siblings) {
130
+ if (sibling.element === selectedElement) {
131
+ addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
132
+ } else {
133
+ chain.push({ ...sibling, depth: selfDepth });
134
134
  }
135
135
  }
136
+ }
137
+
138
+ /**
139
+ * Build the layer chain for the dropdown:
140
+ *
141
+ * Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
142
+ * Siblings – instrumented children of the immediate parent, at the same depth.
143
+ * Current – the selected element (highlighted), with children expanded.
144
+ * Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
145
+ *
146
+ * Each item carries a `depth` for visual indentation.
147
+ */
148
+ export function buildLayerChain(selectedElement: Element): LayerInfo[] {
149
+ const parents = collectInstrumentedParents(selectedElement);
150
+ const chain: LayerInfo[] = [];
151
+ const selfDepth = addParentsToChain(chain, parents);
152
+
153
+ const instrParent = getImmediateInstrParent(parents);
154
+ if (instrParent) {
155
+ const siblings = collectSiblings(instrParent, selectedElement);
156
+ appendSiblingsWithSelected(chain, siblings, selectedElement, selfDepth);
157
+ } else {
158
+ addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
159
+ }
136
160
 
137
- walk(root, 1);
161
+ return chain;
138
162
  }
@@ -16,22 +16,6 @@ export function getElementSelectorId(element: Element): string | null {
16
16
  );
17
17
  }
18
18
 
19
- /** Find the nearest instrumented ancestor (not the element itself) */
20
- export function getImmediateInstrumentedParent(element: Element): Element | null {
21
- let current = element.parentElement;
22
- while (
23
- current &&
24
- current !== document.documentElement &&
25
- current !== document.body
26
- ) {
27
- if (isInstrumentedElement(current)) {
28
- return current;
29
- }
30
- current = current.parentElement;
31
- }
32
- return null;
33
- }
34
-
35
19
  /** Find elements by ID - first try data-source-location, fallback to data-visual-selector-id */
36
20
  export function findElementsById(id: string | null): Element[] {
37
21
  if (!id) return [];
@@ -140,6 +140,11 @@ export function setupVisualEditAgent() {
140
140
  return selectedOverlays[0];
141
141
  };
142
142
 
143
+ const notifyDeselection = (): 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;
@@ -243,8 +248,8 @@ export function setupVisualEditAgent() {
243
248
  layerController.attachToOverlay(selectedOverlay, element);
244
249
  };
245
250
 
246
- // Unselect the current element
247
- const unselectElement = () => {
251
+ // Clear the current selection
252
+ const clearSelection = () => {
248
253
  clearSelectedOverlays();
249
254
  selectedElementId = null;
250
255
  };
@@ -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: notifyDeselection,
322
324
  });
323
325
 
324
326
  // Toggle visual edit mode
@@ -409,7 +411,7 @@ export function setupVisualEditAgent() {
409
411
  break;
410
412
 
411
413
  case "unselect-element":
412
- unselectElement();
414
+ clearSelection();
413
415
  break;
414
416
 
415
417
  case "refresh-page":