@base44/vite-plugin 1.0.1 → 1.0.3
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.
- package/dist/injections/layer-dropdown/consts.d.ts +5 -4
- package/dist/injections/layer-dropdown/consts.d.ts.map +1 -1
- package/dist/injections/layer-dropdown/consts.js +5 -4
- package/dist/injections/layer-dropdown/consts.js.map +1 -1
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +1 -1
- package/dist/injections/layer-dropdown/dropdown-ui.js +15 -8
- package/dist/injections/layer-dropdown/dropdown-ui.js.map +1 -1
- package/dist/injections/unhandled-errors-handlers.js +22 -1
- package/dist/injections/unhandled-errors-handlers.js.map +1 -1
- package/dist/injections/utils.d.ts +17 -0
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +36 -0
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +34 -35
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/statics/index.mjs +4 -4
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/injections/layer-dropdown/consts.ts +6 -4
- package/src/injections/layer-dropdown/dropdown-ui.ts +16 -7
- package/src/injections/unhandled-errors-handlers.ts +22 -1
- package/src/injections/utils.ts +37 -0
- package/src/injections/visual-edit-agent.ts +44 -44
|
@@ -33,10 +33,12 @@ export const DROPDOWN_ITEM_HOVER_BG = "#f1f5f9";
|
|
|
33
33
|
|
|
34
34
|
export const DEPTH_INDENT_PX = 10;
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
export const CHEVRON_COLLAPSED = "
|
|
38
|
-
/**
|
|
39
|
-
export const CHEVRON_EXPANDED = "
|
|
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";
|
|
40
42
|
|
|
41
43
|
export const BASE_PADDING_PX = 12;
|
|
42
44
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
BASE_PADDING_PX,
|
|
12
12
|
CHEVRON_COLLAPSED,
|
|
13
13
|
CHEVRON_EXPANDED,
|
|
14
|
+
CHEVRON_ATTR,
|
|
14
15
|
LAYER_DROPDOWN_ATTR,
|
|
15
16
|
} from "./consts.js";
|
|
16
17
|
import { applyStyles, getLayerDisplayName } from "./utils.js";
|
|
@@ -83,10 +84,16 @@ export function createDropdownElement(
|
|
|
83
84
|
|
|
84
85
|
/** Add chevron indicator and pointer-events to the label */
|
|
85
86
|
export function enhanceLabelWithChevron(label: HTMLDivElement): void {
|
|
86
|
-
|
|
87
|
-
if (t.endsWith(CHEVRON_COLLAPSED) || t.endsWith(CHEVRON_EXPANDED)) return;
|
|
87
|
+
if (label.querySelector(`[${CHEVRON_ATTR}]`)) return;
|
|
88
88
|
|
|
89
|
-
|
|
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";
|
|
90
97
|
label.style.cursor = "pointer";
|
|
91
98
|
label.style.userSelect = "none";
|
|
92
99
|
label.style.whiteSpace = "nowrap";
|
|
@@ -190,8 +197,9 @@ export function showDropdown(
|
|
|
190
197
|
overlay.appendChild(dropdown);
|
|
191
198
|
activeDropdown = dropdown;
|
|
192
199
|
activeLabel = label;
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
const chevronEl = label.querySelector(`[${CHEVRON_ATTR}]`);
|
|
201
|
+
if (chevronEl) {
|
|
202
|
+
chevronEl.innerHTML = CHEVRON_EXPANDED;
|
|
195
203
|
}
|
|
196
204
|
activeOnHoverEnd = callbacks.onHoverEnd ?? null;
|
|
197
205
|
|
|
@@ -201,8 +209,9 @@ export function showDropdown(
|
|
|
201
209
|
|
|
202
210
|
/** Close the active dropdown and clean up listeners */
|
|
203
211
|
export function closeDropdown(): void {
|
|
204
|
-
|
|
205
|
-
|
|
212
|
+
const chevronEl = activeLabel?.querySelector(`[${CHEVRON_ATTR}]`);
|
|
213
|
+
if (chevronEl) {
|
|
214
|
+
chevronEl.innerHTML = CHEVRON_COLLAPSED;
|
|
206
215
|
}
|
|
207
216
|
activeLabel = null;
|
|
208
217
|
|
|
@@ -8,10 +8,12 @@ window.addEventListener("error", handleWindowError);
|
|
|
8
8
|
|
|
9
9
|
let shouldPropagateErrors = true;
|
|
10
10
|
let suppressionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
let hadSuppressedErrors = false;
|
|
11
12
|
|
|
12
13
|
if (import.meta.hot) {
|
|
13
14
|
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
14
15
|
shouldPropagateErrors = false;
|
|
16
|
+
hadSuppressedErrors = false;
|
|
15
17
|
|
|
16
18
|
if (suppressionTimer) {
|
|
17
19
|
clearTimeout(suppressionTimer);
|
|
@@ -20,10 +22,25 @@ if (import.meta.hot) {
|
|
|
20
22
|
suppressionTimer = setTimeout(() => {
|
|
21
23
|
shouldPropagateErrors = true;
|
|
22
24
|
suppressionTimer = null;
|
|
25
|
+
hadSuppressedErrors = false;
|
|
26
|
+
// No vite:afterUpdate after timeout — treat the stuck update as an error
|
|
27
|
+
window.parent?.postMessage({ type: "sandbox:hmrErrorsSuppressed" }, "*");
|
|
23
28
|
}, import.meta.env.VITE_HMR_ERROR_SUPPRESSION_DELAY ?? 10000);
|
|
24
29
|
});
|
|
30
|
+
import.meta.hot.on("vite:afterUpdate", () => {
|
|
31
|
+
shouldPropagateErrors = true;
|
|
32
|
+
if (suppressionTimer) {
|
|
33
|
+
clearTimeout(suppressionTimer);
|
|
34
|
+
suppressionTimer = null;
|
|
35
|
+
}
|
|
36
|
+
if (hadSuppressedErrors) {
|
|
37
|
+
window.parent?.postMessage({ type: "sandbox:hmrErrorsSuppressed" }, "*");
|
|
38
|
+
hadSuppressedErrors = false;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
25
41
|
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
26
42
|
shouldPropagateErrors = false;
|
|
43
|
+
hadSuppressedErrors = false;
|
|
27
44
|
if (suppressionTimer) {
|
|
28
45
|
clearTimeout(suppressionTimer);
|
|
29
46
|
suppressionTimer = null;
|
|
@@ -42,7 +59,11 @@ function onAppError({
|
|
|
42
59
|
componentName: string;
|
|
43
60
|
originalError: any;
|
|
44
61
|
}) {
|
|
45
|
-
if (originalError?.response?.status === 402
|
|
62
|
+
if (originalError?.response?.status === 402) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!shouldPropagateErrors) {
|
|
66
|
+
hadSuppressedErrors = true;
|
|
46
67
|
return;
|
|
47
68
|
}
|
|
48
69
|
window.parent?.postMessage(
|
package/src/injections/utils.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
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
|
+
|
|
1
38
|
/** Check if an element has instrumentation attributes */
|
|
2
39
|
export function isInstrumentedElement(element: Element): boolean {
|
|
3
40
|
const htmlEl = element as HTMLElement;
|
|
@@ -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,18 +59,19 @@ 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";
|
|
65
65
|
label.style.fontWeight = isSelected ? "500" : "400";
|
|
66
66
|
label.style.color = isSelected ? "#ffffff" : "#526cff";
|
|
67
|
-
label.style.backgroundColor = isSelected ? "#
|
|
67
|
+
label.style.backgroundColor = isSelected ? "#2563EB" : "#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);
|
|
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
|
|
440
|
-
if (
|
|
441
|
-
const
|
|
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
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
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
|
|