@base44-preview/vite-plugin 0.2.22-pr.36.d652cb1 → 0.2.22-pr.37.466ee63
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/utils.d.ts +0 -6
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +0 -25
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +25 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +78 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +9 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +26 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +10 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +60 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +1 -0
- package/dist/injections/visual-edit-agent/constants.d.ts +10 -0
- package/dist/injections/visual-edit-agent/constants.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/constants.js +10 -0
- package/dist/injections/visual-edit-agent/constants.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +10 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js +109 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +64 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +99 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +26 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js +145 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +7 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +42 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +11 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +33 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +86 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js +28 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +1 -0
- package/dist/injections/visual-edit-agent/index.d.ts +5 -0
- package/dist/injections/visual-edit-agent/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/index.js +100 -0
- package/dist/injections/visual-edit-agent/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts +17 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js +18 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts +26 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js +103 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +14 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js +34 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +1 -0
- package/dist/injections/visual-edit-agent.d.ts +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +1 -474
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/statics/index.mjs +5 -1
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/injections/utils.ts +0 -34
- package/src/injections/visual-edit-agent/README.md +222 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +100 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +10 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +26 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +67 -0
- package/src/injections/visual-edit-agent/constants.ts +9 -0
- package/src/injections/visual-edit-agent/handlers/click-handlers.ts +135 -0
- package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
- package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +130 -0
- package/src/injections/visual-edit-agent/handlers/message-handlers.ts +191 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +51 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +41 -0
- package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
- package/src/injections/visual-edit-agent/index.ts +116 -0
- package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
- package/src/injections/visual-edit-agent/ui/overlay.ts +125 -0
- package/src/injections/visual-edit-agent/utils/dom-utils.ts +39 -0
- package/src/injections/visual-edit-agent.ts +1 -577
- package/dist/injections/layer-dropdown/consts.d.ts +0 -15
- package/dist/injections/layer-dropdown/consts.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/consts.js +0 -36
- package/dist/injections/layer-dropdown/consts.js.map +0 -1
- package/dist/injections/layer-dropdown/controller.d.ts +0 -4
- package/dist/injections/layer-dropdown/controller.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/controller.js +0 -85
- package/dist/injections/layer-dropdown/controller.js.map +0 -1
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts +0 -13
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/dropdown-ui.js +0 -158
- package/dist/injections/layer-dropdown/dropdown-ui.js.map +0 -1
- package/dist/injections/layer-dropdown/types.d.ts +0 -21
- package/dist/injections/layer-dropdown/types.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/types.js +0 -3
- package/dist/injections/layer-dropdown/types.js.map +0 -1
- package/dist/injections/layer-dropdown/utils.d.ts +0 -24
- package/dist/injections/layer-dropdown/utils.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/utils.js +0 -150
- package/dist/injections/layer-dropdown/utils.js.map +0 -1
- package/src/injections/layer-dropdown/LAYERS.md +0 -258
- package/src/injections/layer-dropdown/consts.ts +0 -44
- package/src/injections/layer-dropdown/controller.ts +0 -105
- package/src/injections/layer-dropdown/dropdown-ui.ts +0 -221
- package/src/injections/layer-dropdown/types.ts +0 -24
- package/src/injections/layer-dropdown/utils.ts +0 -185
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AgentState } from "../../state/agent-state.js";
|
|
2
|
+
import type { ToggleVisualEditModeMessage } from "./types.js";
|
|
3
|
+
import { clearSelection } from "../../ui/overlay.js";
|
|
4
|
+
import { clearHoverOverlays } from "../hover-handlers.js";
|
|
5
|
+
import { handleClearInlineEditingMode } from "../inline-edit-handlers.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Toggle visual edit mode on/off
|
|
9
|
+
*/
|
|
10
|
+
export function toggleVisualEditMode(state: AgentState, isEnabled: boolean): void {
|
|
11
|
+
state.isVisualEditMode = isEnabled;
|
|
12
|
+
|
|
13
|
+
if (!isEnabled) {
|
|
14
|
+
if (state.currentEditingElement) {
|
|
15
|
+
handleClearInlineEditingMode(state);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
clearHoverOverlays(state);
|
|
19
|
+
clearSelection(state);
|
|
20
|
+
state.currentHighlightedElements = [];
|
|
21
|
+
document.body.style.cursor = "default";
|
|
22
|
+
} else {
|
|
23
|
+
document.body.style.cursor = "crosshair";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Handle toggle-visual-edit-mode message
|
|
29
|
+
*/
|
|
30
|
+
export function handleToggleVisualEditMode(
|
|
31
|
+
state: AgentState,
|
|
32
|
+
message: ToggleVisualEditModeMessage
|
|
33
|
+
): void {
|
|
34
|
+
toggleVisualEditMode(state, message.data.enabled);
|
|
35
|
+
|
|
36
|
+
// Update inline edit experiment flag if provided
|
|
37
|
+
if (message.data.specs?.newInlineEditEnabled !== undefined) {
|
|
38
|
+
state.isInlineEditExperimentEnabled = message.data.specs.newInlineEditEnabled;
|
|
39
|
+
console.log('[VisualEditAgent] Inline edit experiment:', state.isInlineEditExperimentEnabled);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message types and interfaces for parent-iframe communication
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Incoming message types (from parent)
|
|
6
|
+
export enum IncomingMessageType {
|
|
7
|
+
TOGGLE_VISUAL_EDIT_MODE = "toggle-visual-edit-mode",
|
|
8
|
+
UPDATE_CLASSES = "update-classes",
|
|
9
|
+
UPDATE_CONTENT = "update-content",
|
|
10
|
+
UNSELECT_ELEMENT = "unselect-element",
|
|
11
|
+
REFRESH_PAGE = "refresh-page",
|
|
12
|
+
TOGGLE_INLINE_EDIT_MODE = "toggle-inline-edit-mode",
|
|
13
|
+
REQUEST_ELEMENT_POSITION = "request-element-position",
|
|
14
|
+
POPOVER_DRAG_STATE = "popover-drag-state",
|
|
15
|
+
DROPDOWN_STATE = "dropdown-state",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Outgoing message types (to parent)
|
|
19
|
+
export enum OutgoingMessageType {
|
|
20
|
+
VISUAL_EDIT_AGENT_READY = "visual-edit-agent-ready",
|
|
21
|
+
ELEMENT_SELECTED = "element-selected",
|
|
22
|
+
ELEMENT_POSITION_UPDATE = "element-position-update",
|
|
23
|
+
CONTENT_EDITING_STARTED = "content-editing-started",
|
|
24
|
+
INLINE_EDIT = "inline-edit",
|
|
25
|
+
CONTENT_EDITING_ENDED = "content-editing-ended",
|
|
26
|
+
CLOSE_DROPDOWNS = "close-dropdowns",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Message interfaces
|
|
30
|
+
export interface ToggleVisualEditModeMessage {
|
|
31
|
+
type: IncomingMessageType.TOGGLE_VISUAL_EDIT_MODE;
|
|
32
|
+
data: {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
specs?: {
|
|
35
|
+
newInlineEditEnabled?: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UpdateClassesMessage {
|
|
41
|
+
type: IncomingMessageType.UPDATE_CLASSES;
|
|
42
|
+
data: {
|
|
43
|
+
visualSelectorId: string;
|
|
44
|
+
classes: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface UpdateContentMessage {
|
|
49
|
+
type: IncomingMessageType.UPDATE_CONTENT;
|
|
50
|
+
data: {
|
|
51
|
+
visualSelectorId: string;
|
|
52
|
+
content: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface UnselectElementMessage {
|
|
57
|
+
type: IncomingMessageType.UNSELECT_ELEMENT;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface RefreshPageMessage {
|
|
61
|
+
type: IncomingMessageType.REFRESH_PAGE;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ToggleInlineEditModeMessage {
|
|
65
|
+
type: IncomingMessageType.TOGGLE_INLINE_EDIT_MODE;
|
|
66
|
+
data: {
|
|
67
|
+
dataSourceLocation: string;
|
|
68
|
+
inlineEditingMode: boolean;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface RequestElementPositionMessage {
|
|
73
|
+
type: IncomingMessageType.REQUEST_ELEMENT_POSITION;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PopoverDragStateMessage {
|
|
77
|
+
type: IncomingMessageType.POPOVER_DRAG_STATE;
|
|
78
|
+
data: {
|
|
79
|
+
isDragging: boolean;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DropdownStateMessage {
|
|
84
|
+
type: IncomingMessageType.DROPDOWN_STATE;
|
|
85
|
+
data: {
|
|
86
|
+
isOpen: boolean;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Union type for all incoming messages
|
|
91
|
+
export type IncomingMessage =
|
|
92
|
+
| ToggleVisualEditModeMessage
|
|
93
|
+
| UpdateClassesMessage
|
|
94
|
+
| UpdateContentMessage
|
|
95
|
+
| UnselectElementMessage
|
|
96
|
+
| RefreshPageMessage
|
|
97
|
+
| ToggleInlineEditModeMessage
|
|
98
|
+
| RequestElementPositionMessage
|
|
99
|
+
| PopoverDragStateMessage
|
|
100
|
+
| DropdownStateMessage;
|
|
101
|
+
|
|
102
|
+
// Element position interface (used in multiple messages)
|
|
103
|
+
export interface ElementPosition {
|
|
104
|
+
top: number;
|
|
105
|
+
left: number;
|
|
106
|
+
right: number;
|
|
107
|
+
bottom: number;
|
|
108
|
+
width: number;
|
|
109
|
+
height: number;
|
|
110
|
+
centerX: number;
|
|
111
|
+
centerY: number;
|
|
112
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createAgentState } from "./state/agent-state.js";
|
|
2
|
+
import { handleMouseOver, handleMouseOut } from "./handlers/hover-handlers.js";
|
|
3
|
+
import { handleElementClick } from "./handlers/click-handlers.js";
|
|
4
|
+
import { handleMessage, handleScroll, handleResize } from "./handlers/message-handlers.js";
|
|
5
|
+
import { setupInlineEditCallback } from "./handlers/inline-edit-handlers.js";
|
|
6
|
+
import { OutgoingMessageType } from "./handlers/messages/types.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Initialize element IDs for elements with line numbers
|
|
10
|
+
*/
|
|
11
|
+
function initializeElementIds(): void {
|
|
12
|
+
const elementsWithLineNumber = document.querySelectorAll(
|
|
13
|
+
"[data-linenumber]:not([data-visual-selector-id])"
|
|
14
|
+
);
|
|
15
|
+
elementsWithLineNumber.forEach((el, index) => {
|
|
16
|
+
const htmlEl = el as HTMLElement;
|
|
17
|
+
const id = `visual-id-${htmlEl.dataset.filename}-${htmlEl.dataset.linenumber}-${index}`;
|
|
18
|
+
htmlEl.dataset.visualSelectorId = id;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create mutation observer to detect layout changes
|
|
24
|
+
*/
|
|
25
|
+
function createLayoutObserver(onLayoutChange: () => void): MutationObserver {
|
|
26
|
+
return new MutationObserver((mutations) => {
|
|
27
|
+
const needsUpdate = mutations.some((mutation) => {
|
|
28
|
+
const hasVisualId = (node: Node): boolean => {
|
|
29
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
30
|
+
const el = node as HTMLElement;
|
|
31
|
+
if (el.dataset && el.dataset.visualSelectorId) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0; i < el.children.length; i++) {
|
|
35
|
+
if (hasVisualId(el.children[i]!)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const isLayoutChange =
|
|
44
|
+
mutation.type === "attributes" &&
|
|
45
|
+
(mutation.attributeName === "style" ||
|
|
46
|
+
mutation.attributeName === "class" ||
|
|
47
|
+
mutation.attributeName === "width" ||
|
|
48
|
+
mutation.attributeName === "height");
|
|
49
|
+
|
|
50
|
+
return isLayoutChange && hasVisualId(mutation.target);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (needsUpdate) {
|
|
54
|
+
setTimeout(onLayoutChange, 50);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Setup keyboard event protection
|
|
61
|
+
*/
|
|
62
|
+
function setupKeyboardProtection(): void {
|
|
63
|
+
document.addEventListener("keydown", (e: KeyboardEvent) => {
|
|
64
|
+
if (e.target instanceof HTMLElement && e.target.contentEditable === "true") {
|
|
65
|
+
// Don't report keyboard events during inline editing
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// Forward other keyboard events to parent if needed
|
|
69
|
+
}, true);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Setup event listeners
|
|
74
|
+
*/
|
|
75
|
+
function setupEventListeners(state: ReturnType<typeof createAgentState>): void {
|
|
76
|
+
// Message handling
|
|
77
|
+
window.addEventListener("message", (e) => handleMessage(state, e));
|
|
78
|
+
|
|
79
|
+
// Scroll handling
|
|
80
|
+
window.addEventListener("scroll", () => handleScroll(state), true);
|
|
81
|
+
document.addEventListener("scroll", () => handleScroll(state), true);
|
|
82
|
+
|
|
83
|
+
// Resize handling
|
|
84
|
+
window.addEventListener("resize", () => handleResize(state));
|
|
85
|
+
window.addEventListener("scroll", () => handleResize(state));
|
|
86
|
+
|
|
87
|
+
// Click handling
|
|
88
|
+
document.addEventListener("click", (e) => handleElementClick(state, e), true);
|
|
89
|
+
|
|
90
|
+
// Hover handling
|
|
91
|
+
document.addEventListener("mouseover", (e) => handleMouseOver(state, e));
|
|
92
|
+
document.addEventListener("mouseout", () => handleMouseOut(state));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Main setup function for visual edit agent
|
|
97
|
+
*/
|
|
98
|
+
export function setupVisualEditAgent(): void {
|
|
99
|
+
const state = createAgentState();
|
|
100
|
+
initializeElementIds();
|
|
101
|
+
setupInlineEditCallback(state);
|
|
102
|
+
setupKeyboardProtection();
|
|
103
|
+
setupEventListeners(state);
|
|
104
|
+
|
|
105
|
+
// Create and start mutation observer
|
|
106
|
+
const mutationObserver = createLayoutObserver(() => handleResize(state));
|
|
107
|
+
mutationObserver.observe(document.body, {
|
|
108
|
+
attributes: true,
|
|
109
|
+
childList: true,
|
|
110
|
+
subtree: true,
|
|
111
|
+
attributeFilter: ["style", "class", "width", "height"],
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Send ready message to parent
|
|
115
|
+
window.parent.postMessage({ type: OutgoingMessageType.VISUAL_EDIT_AGENT_READY }, "*");
|
|
116
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central state management for the visual edit agent
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface AgentState {
|
|
6
|
+
isVisualEditMode: boolean;
|
|
7
|
+
isPopoverDragging: boolean;
|
|
8
|
+
isDropdownOpen: boolean;
|
|
9
|
+
hoverOverlays: HTMLDivElement[];
|
|
10
|
+
selectedOverlays: HTMLDivElement[];
|
|
11
|
+
currentHighlightedElements: Element[];
|
|
12
|
+
selectedElementId: string | null;
|
|
13
|
+
currentEditingElement: HTMLElement | null;
|
|
14
|
+
debouncedSendTimeout: ReturnType<typeof setTimeout> | null;
|
|
15
|
+
isInlineEditExperimentEnabled: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createAgentState(): AgentState {
|
|
19
|
+
return {
|
|
20
|
+
isVisualEditMode: false,
|
|
21
|
+
isPopoverDragging: false,
|
|
22
|
+
isDropdownOpen: false,
|
|
23
|
+
hoverOverlays: [],
|
|
24
|
+
selectedOverlays: [],
|
|
25
|
+
currentHighlightedElements: [],
|
|
26
|
+
selectedElementId: null,
|
|
27
|
+
currentEditingElement: null,
|
|
28
|
+
debouncedSendTimeout: null,
|
|
29
|
+
isInlineEditExperimentEnabled: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OVERLAY_TRANSITION,
|
|
3
|
+
OVERLAY_Z_INDEX,
|
|
4
|
+
SELECTED_BORDER_COLOR,
|
|
5
|
+
HOVER_BORDER_COLOR,
|
|
6
|
+
HOVER_BACKGROUND_COLOR,
|
|
7
|
+
LABEL_TOP_OFFSET,
|
|
8
|
+
LABEL_LEFT_OFFSET,
|
|
9
|
+
} from "../constants.js";
|
|
10
|
+
import type { AgentState } from "../state/agent-state.js";
|
|
11
|
+
import { findElementsById } from "../../utils.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create an overlay element for highlighting
|
|
15
|
+
*/
|
|
16
|
+
export function createOverlay(isSelected = false): HTMLDivElement {
|
|
17
|
+
const overlay = document.createElement("div");
|
|
18
|
+
overlay.style.position = "absolute";
|
|
19
|
+
overlay.style.pointerEvents = "none";
|
|
20
|
+
overlay.style.transition = OVERLAY_TRANSITION;
|
|
21
|
+
overlay.style.zIndex = OVERLAY_Z_INDEX;
|
|
22
|
+
|
|
23
|
+
if (isSelected) {
|
|
24
|
+
overlay.style.border = `2px solid ${SELECTED_BORDER_COLOR}`;
|
|
25
|
+
} else {
|
|
26
|
+
overlay.style.border = `2px solid ${HOVER_BORDER_COLOR}`;
|
|
27
|
+
overlay.style.backgroundColor = HOVER_BACKGROUND_COLOR;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return overlay;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Position overlay relative to element
|
|
35
|
+
*/
|
|
36
|
+
export function positionOverlay(
|
|
37
|
+
overlay: HTMLDivElement,
|
|
38
|
+
element: Element,
|
|
39
|
+
isSelected = false,
|
|
40
|
+
isVisualEditMode = true
|
|
41
|
+
): void {
|
|
42
|
+
if (!element || !isVisualEditMode) return;
|
|
43
|
+
|
|
44
|
+
const htmlElement = element as HTMLElement;
|
|
45
|
+
// Force layout recalculation
|
|
46
|
+
void htmlElement.offsetWidth;
|
|
47
|
+
|
|
48
|
+
const rect = element.getBoundingClientRect();
|
|
49
|
+
overlay.style.top = `${rect.top + window.scrollY}px`;
|
|
50
|
+
overlay.style.left = `${rect.left + window.scrollX}px`;
|
|
51
|
+
overlay.style.width = `${rect.width}px`;
|
|
52
|
+
overlay.style.height = `${rect.height}px`;
|
|
53
|
+
|
|
54
|
+
// Check if label already exists in overlay
|
|
55
|
+
let label = overlay.querySelector("div") as HTMLDivElement | null;
|
|
56
|
+
|
|
57
|
+
if (!label) {
|
|
58
|
+
label = document.createElement("div");
|
|
59
|
+
label.textContent = element.tagName.toLowerCase();
|
|
60
|
+
label.style.position = "absolute";
|
|
61
|
+
label.style.top = LABEL_TOP_OFFSET;
|
|
62
|
+
label.style.left = LABEL_LEFT_OFFSET;
|
|
63
|
+
label.style.padding = "2px 8px";
|
|
64
|
+
label.style.fontSize = "11px";
|
|
65
|
+
label.style.fontWeight = isSelected ? "500" : "400";
|
|
66
|
+
label.style.color = isSelected ? "#ffffff" : "#526cff";
|
|
67
|
+
label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
|
|
68
|
+
label.style.borderRadius = "3px";
|
|
69
|
+
label.style.minWidth = "24px";
|
|
70
|
+
label.style.textAlign = "center";
|
|
71
|
+
overlay.appendChild(label);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Clear all overlays from DOM
|
|
77
|
+
*/
|
|
78
|
+
export function clearOverlays(overlays: HTMLDivElement[]): void {
|
|
79
|
+
overlays.forEach((overlay) => {
|
|
80
|
+
if (overlay && overlay.parentNode) {
|
|
81
|
+
overlay.remove();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Remove data-selected attribute, clear selected overlays, and reset selection state
|
|
88
|
+
*/
|
|
89
|
+
export function clearSelection(state: AgentState): void {
|
|
90
|
+
if (state.selectedElementId) {
|
|
91
|
+
const elements = findElementsById(state.selectedElementId);
|
|
92
|
+
elements.forEach((el) => {
|
|
93
|
+
if (el instanceof HTMLElement) {
|
|
94
|
+
delete el.dataset.selected;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
clearOverlays(state.selectedOverlays);
|
|
99
|
+
state.selectedOverlays = [];
|
|
100
|
+
state.selectedElementId = null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Reposition selected overlays to match current element bounds
|
|
105
|
+
*/
|
|
106
|
+
export function repositionSelectedOverlays(state: AgentState): void {
|
|
107
|
+
if (!state.selectedElementId) return;
|
|
108
|
+
const elements = findElementsById(state.selectedElementId);
|
|
109
|
+
state.selectedOverlays.forEach((overlay, index) => {
|
|
110
|
+
if (index < elements.length) {
|
|
111
|
+
positionOverlay(overlay, elements[index]!, true, state.isVisualEditMode);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Reposition hover overlays to match current element bounds
|
|
118
|
+
*/
|
|
119
|
+
export function repositionHoverOverlays(state: AgentState): void {
|
|
120
|
+
state.hoverOverlays.forEach((overlay, index) => {
|
|
121
|
+
if (index < state.currentHighlightedElements.length) {
|
|
122
|
+
positionOverlay(overlay, state.currentHighlightedElements[index]!, false, state.isVisualEditMode);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ElementPosition } from "../handlers/messages/types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculate element position from bounding rect
|
|
5
|
+
*/
|
|
6
|
+
export function getElementPosition(rect: DOMRect): ElementPosition {
|
|
7
|
+
return {
|
|
8
|
+
top: rect.top,
|
|
9
|
+
left: rect.left,
|
|
10
|
+
right: rect.right,
|
|
11
|
+
bottom: rect.bottom,
|
|
12
|
+
width: rect.width,
|
|
13
|
+
height: rect.height,
|
|
14
|
+
centerX: rect.left + rect.width / 2,
|
|
15
|
+
centerY: rect.top + rect.height / 2,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if element rect is in viewport
|
|
21
|
+
*/
|
|
22
|
+
export function isElementInViewport(rect: DOMRect): boolean {
|
|
23
|
+
return (
|
|
24
|
+
rect.top < window.innerHeight &&
|
|
25
|
+
rect.bottom > 0 &&
|
|
26
|
+
rect.left < window.innerWidth &&
|
|
27
|
+
rect.right > 0
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get element classes (handles both HTML and SVG)
|
|
33
|
+
*/
|
|
34
|
+
export function getElementClasses(element: Element): string {
|
|
35
|
+
if (element instanceof SVGElement) {
|
|
36
|
+
return (element.className as unknown as SVGAnimatedString)?.baseVal || "";
|
|
37
|
+
}
|
|
38
|
+
return element.className || "";
|
|
39
|
+
}
|