@base44-preview/vite-plugin 0.2.22-pr.36.d652cb1 → 0.2.22-pr.37.26664a5
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 +95 -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 +107 -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 +109 -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 +58 -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 +32 -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 +106 -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 +102 -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 +120 -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 +134 -0
- package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
- package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +141 -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 +70 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +40 -0
- package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
- package/src/injections/visual-edit-agent/index.ts +120 -0
- package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
- package/src/injections/visual-edit-agent/ui/overlay.ts +123 -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,191 @@
|
|
|
1
|
+
import type { AgentState } from "../state/agent-state.js";
|
|
2
|
+
import { IncomingMessageType, OutgoingMessageType } from "./messages/types.js";
|
|
3
|
+
import { findElementsById, updateElementClasses } from "../../utils.js";
|
|
4
|
+
import { clearSelection, repositionSelectedOverlays, repositionHoverOverlays } from "../ui/overlay.js";
|
|
5
|
+
import { clearHoverOverlays } from "./hover-handlers.js";
|
|
6
|
+
import { handleClearInlineEditingMode } from "./inline-edit-handlers.js";
|
|
7
|
+
import { REPOSITION_DELAY_MS } from "../constants.js";
|
|
8
|
+
import { handleToggleVisualEditMode } from "./messages/toggle-visual-edit-mode.js";
|
|
9
|
+
import { handleToggleInlineEditMode } from "./messages/toggle-inline-edit-mode.js";
|
|
10
|
+
import { getElementPosition, isElementInViewport } from "../utils/dom-utils.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Send element position update to parent
|
|
14
|
+
*/
|
|
15
|
+
function sendElementPositionUpdate(state: AgentState): void {
|
|
16
|
+
if (!state.selectedElementId) return;
|
|
17
|
+
|
|
18
|
+
const elements = findElementsById(state.selectedElementId);
|
|
19
|
+
const [element] = elements;
|
|
20
|
+
if (!element) return;
|
|
21
|
+
|
|
22
|
+
const rect = element.getBoundingClientRect();
|
|
23
|
+
|
|
24
|
+
window.parent.postMessage(
|
|
25
|
+
{
|
|
26
|
+
type: OutgoingMessageType.ELEMENT_POSITION_UPDATE,
|
|
27
|
+
position: getElementPosition(rect),
|
|
28
|
+
isInViewport: isElementInViewport(rect),
|
|
29
|
+
visualSelectorId: state.selectedElementId,
|
|
30
|
+
},
|
|
31
|
+
"*"
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Unselect the current element
|
|
37
|
+
*/
|
|
38
|
+
export function unselectElement(state: AgentState): void {
|
|
39
|
+
if (state.currentEditingElement) {
|
|
40
|
+
handleClearInlineEditingMode(state);
|
|
41
|
+
}
|
|
42
|
+
clearSelection(state);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Update element classes and reposition overlays
|
|
47
|
+
*/
|
|
48
|
+
export function updateElementClassesAndReposition(
|
|
49
|
+
state: AgentState,
|
|
50
|
+
visualSelectorId: string,
|
|
51
|
+
classes: string
|
|
52
|
+
): void {
|
|
53
|
+
const elements = findElementsById(visualSelectorId);
|
|
54
|
+
if (elements.length === 0) return;
|
|
55
|
+
|
|
56
|
+
updateElementClasses(elements, classes);
|
|
57
|
+
|
|
58
|
+
// Use a small delay to allow the browser to recalculate layout before repositioning
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
if (state.selectedElementId === visualSelectorId) {
|
|
61
|
+
repositionSelectedOverlays(state);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (state.currentHighlightedElements.length > 0) {
|
|
65
|
+
const hoveredElement = state.currentHighlightedElements[0] as HTMLElement;
|
|
66
|
+
if (hoveredElement?.dataset?.visualSelectorId === visualSelectorId) {
|
|
67
|
+
repositionHoverOverlays(state);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, REPOSITION_DELAY_MS);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Update element content by visual selector ID
|
|
75
|
+
*/
|
|
76
|
+
export function updateElementContent(
|
|
77
|
+
state: AgentState,
|
|
78
|
+
visualSelectorId: string,
|
|
79
|
+
content: string
|
|
80
|
+
): void {
|
|
81
|
+
const elements = findElementsById(visualSelectorId);
|
|
82
|
+
|
|
83
|
+
if (elements.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
elements.forEach((element) => {
|
|
88
|
+
(element as HTMLElement).innerText = content;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
if (state.selectedElementId === visualSelectorId) {
|
|
93
|
+
repositionSelectedOverlays(state);
|
|
94
|
+
}
|
|
95
|
+
}, REPOSITION_DELAY_MS);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Handle scroll events to update popover position
|
|
100
|
+
*/
|
|
101
|
+
export function handleScroll(state: AgentState): void {
|
|
102
|
+
sendElementPositionUpdate(state);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Handle window resize to reposition overlays
|
|
107
|
+
*/
|
|
108
|
+
export function handleResize(state: AgentState): void {
|
|
109
|
+
repositionSelectedOverlays(state);
|
|
110
|
+
repositionHoverOverlays(state);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Handle messages from parent window
|
|
115
|
+
*/
|
|
116
|
+
export function handleMessage(state: AgentState, event: MessageEvent): void {
|
|
117
|
+
const message = event.data;
|
|
118
|
+
|
|
119
|
+
switch (message.type as IncomingMessageType) {
|
|
120
|
+
case IncomingMessageType.TOGGLE_VISUAL_EDIT_MODE:
|
|
121
|
+
handleToggleVisualEditMode(state, message);
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
case IncomingMessageType.UPDATE_CLASSES:
|
|
125
|
+
if (message.data && message.data.classes !== undefined) {
|
|
126
|
+
updateElementClassesAndReposition(
|
|
127
|
+
state,
|
|
128
|
+
message.data.visualSelectorId,
|
|
129
|
+
message.data.classes
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
console.warn(
|
|
133
|
+
"[VisualEditAgent] Invalid update-classes message:",
|
|
134
|
+
message
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
|
|
139
|
+
case IncomingMessageType.UNSELECT_ELEMENT:
|
|
140
|
+
unselectElement(state);
|
|
141
|
+
break;
|
|
142
|
+
|
|
143
|
+
case IncomingMessageType.REFRESH_PAGE:
|
|
144
|
+
window.location.reload();
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case IncomingMessageType.UPDATE_CONTENT:
|
|
148
|
+
if (message.data && message.data.content !== undefined) {
|
|
149
|
+
updateElementContent(
|
|
150
|
+
state,
|
|
151
|
+
message.data.visualSelectorId,
|
|
152
|
+
message.data.content
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
console.warn(
|
|
156
|
+
"[VisualEditAgent] Invalid update-content message:",
|
|
157
|
+
message
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
|
|
162
|
+
case IncomingMessageType.TOGGLE_INLINE_EDIT_MODE:
|
|
163
|
+
handleToggleInlineEditMode(state, message);
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case IncomingMessageType.REQUEST_ELEMENT_POSITION:
|
|
167
|
+
sendElementPositionUpdate(state);
|
|
168
|
+
break;
|
|
169
|
+
|
|
170
|
+
case IncomingMessageType.POPOVER_DRAG_STATE:
|
|
171
|
+
if (message.data && message.data.isDragging !== undefined) {
|
|
172
|
+
state.isPopoverDragging = message.data.isDragging;
|
|
173
|
+
if (message.data.isDragging) {
|
|
174
|
+
clearHoverOverlays(state);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
|
|
179
|
+
case IncomingMessageType.DROPDOWN_STATE:
|
|
180
|
+
if (message.data && message.data.isOpen !== undefined) {
|
|
181
|
+
state.isDropdownOpen = message.data.isOpen;
|
|
182
|
+
if (message.data.isOpen) {
|
|
183
|
+
clearHoverOverlays(state);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
default:
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AgentState } from "../../state/agent-state.js";
|
|
2
|
+
import type { ToggleInlineEditModeMessage } from "./types.js";
|
|
3
|
+
import { findElementsById } from "../../../utils.js";
|
|
4
|
+
import { shouldEnterInlineEditingMode } from "../../capabilities/inline-editing/index.js";
|
|
5
|
+
import { handleEnterInlineEditingMode, handleClearInlineEditingMode } from "../inline-edit-handlers.js";
|
|
6
|
+
import { clearSelection } from "../../ui/overlay.js";
|
|
7
|
+
import { createOverlay, positionOverlay } from "../../ui/overlay.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handle toggle-inline-edit-mode message (parent-initiated)
|
|
11
|
+
*/
|
|
12
|
+
export function handleToggleInlineEditMode(
|
|
13
|
+
state: AgentState,
|
|
14
|
+
message: ToggleInlineEditModeMessage
|
|
15
|
+
): void {
|
|
16
|
+
if (!state.isInlineEditExperimentEnabled) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!message.data || !message.data.dataSourceLocation) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const elements = findElementsById(message.data.dataSourceLocation);
|
|
25
|
+
if (elements.length === 0 || !(elements[0] instanceof HTMLElement)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const element = elements[0];
|
|
30
|
+
|
|
31
|
+
if (message.data.inlineEditingMode) {
|
|
32
|
+
// Enable inline editing (only for non-dynamic text elements)
|
|
33
|
+
if (shouldEnterInlineEditingMode(element)) {
|
|
34
|
+
// Select the element first if not already selected
|
|
35
|
+
if (state.selectedElementId !== message.data.dataSourceLocation) {
|
|
36
|
+
// Clear any existing selection
|
|
37
|
+
if (state.currentEditingElement) {
|
|
38
|
+
handleClearInlineEditingMode(state);
|
|
39
|
+
}
|
|
40
|
+
clearSelection(state);
|
|
41
|
+
|
|
42
|
+
// Find all elements with the same ID
|
|
43
|
+
const elements = findElementsById(message.data.dataSourceLocation);
|
|
44
|
+
|
|
45
|
+
// Mark elements as selected
|
|
46
|
+
elements.forEach((el) => {
|
|
47
|
+
if (el instanceof HTMLElement) {
|
|
48
|
+
el.dataset.selected = "true";
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Create selected overlays for all matching elements
|
|
53
|
+
elements.forEach((el) => {
|
|
54
|
+
const overlay = createOverlay(true);
|
|
55
|
+
document.body.appendChild(overlay);
|
|
56
|
+
state.selectedOverlays.push(overlay);
|
|
57
|
+
positionOverlay(overlay, el, true, state.isVisualEditMode);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
state.selectedElementId = message.data.dataSourceLocation;
|
|
61
|
+
}
|
|
62
|
+
handleEnterInlineEditingMode(state, element);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// Disable inline editing
|
|
66
|
+
if (state.currentEditingElement === element) {
|
|
67
|
+
handleClearInlineEditingMode(state);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
}
|
|
40
|
+
}
|
|
@@ -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,120 @@
|
|
|
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
|
+
* Uses requestAnimationFrame to coalesce many rapid mutations into one reposition
|
|
25
|
+
* per paint frame, avoiding stacking multiple timers during CSS transitions.
|
|
26
|
+
*/
|
|
27
|
+
function createLayoutObserver(onLayoutChange: () => void): MutationObserver {
|
|
28
|
+
let rafHandle: number | null = null;
|
|
29
|
+
|
|
30
|
+
const hasVisualId = (node: Node): boolean => {
|
|
31
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
32
|
+
const el = node as HTMLElement;
|
|
33
|
+
if (el.dataset?.visualSelectorId) return true;
|
|
34
|
+
for (const child of Array.from(el.children)) {
|
|
35
|
+
if (hasVisualId(child)) return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return new MutationObserver((mutations) => {
|
|
41
|
+
if (rafHandle !== null) return;
|
|
42
|
+
|
|
43
|
+
const needsUpdate = mutations.some((mutation) => {
|
|
44
|
+
const isLayoutChange =
|
|
45
|
+
mutation.type === "attributes" &&
|
|
46
|
+
(mutation.attributeName === "style" ||
|
|
47
|
+
mutation.attributeName === "class" ||
|
|
48
|
+
mutation.attributeName === "width" ||
|
|
49
|
+
mutation.attributeName === "height");
|
|
50
|
+
|
|
51
|
+
return isLayoutChange && hasVisualId(mutation.target);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (needsUpdate) {
|
|
55
|
+
rafHandle = requestAnimationFrame(() => {
|
|
56
|
+
rafHandle = null;
|
|
57
|
+
onLayoutChange();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Setup keyboard event protection
|
|
65
|
+
*/
|
|
66
|
+
function setupKeyboardProtection(): void {
|
|
67
|
+
document.addEventListener("keydown", (e: KeyboardEvent) => {
|
|
68
|
+
if (e.target instanceof HTMLElement && e.target.contentEditable === "true") {
|
|
69
|
+
// Don't report keyboard events during inline editing
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Forward other keyboard events to parent if needed
|
|
73
|
+
}, true);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Setup event listeners
|
|
78
|
+
*/
|
|
79
|
+
function setupEventListeners(state: ReturnType<typeof createAgentState>): void {
|
|
80
|
+
// Message handling
|
|
81
|
+
window.addEventListener("message", (e) => handleMessage(state, e));
|
|
82
|
+
|
|
83
|
+
// Scroll handling
|
|
84
|
+
window.addEventListener("scroll", () => handleScroll(state), true);
|
|
85
|
+
document.addEventListener("scroll", () => handleScroll(state), true);
|
|
86
|
+
|
|
87
|
+
// Resize handling
|
|
88
|
+
window.addEventListener("resize", () => handleResize(state));
|
|
89
|
+
window.addEventListener("scroll", () => handleResize(state));
|
|
90
|
+
|
|
91
|
+
// Click handling
|
|
92
|
+
document.addEventListener("click", (e) => handleElementClick(state, e), true);
|
|
93
|
+
|
|
94
|
+
// Hover handling
|
|
95
|
+
document.addEventListener("mouseover", (e) => handleMouseOver(state, e));
|
|
96
|
+
document.addEventListener("mouseout", () => handleMouseOut(state));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Main setup function for visual edit agent
|
|
101
|
+
*/
|
|
102
|
+
export function setupVisualEditAgent(): void {
|
|
103
|
+
const state = createAgentState();
|
|
104
|
+
initializeElementIds();
|
|
105
|
+
setupInlineEditCallback(state);
|
|
106
|
+
setupKeyboardProtection();
|
|
107
|
+
setupEventListeners(state);
|
|
108
|
+
|
|
109
|
+
// Create and start mutation observer
|
|
110
|
+
const mutationObserver = createLayoutObserver(() => handleResize(state));
|
|
111
|
+
mutationObserver.observe(document.body, {
|
|
112
|
+
attributes: true,
|
|
113
|
+
childList: true,
|
|
114
|
+
subtree: true,
|
|
115
|
+
attributeFilter: ["style", "class", "width", "height"],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Send ready message to parent
|
|
119
|
+
window.parent.postMessage({ type: OutgoingMessageType.VISUAL_EDIT_AGENT_READY }, "*");
|
|
120
|
+
}
|
|
@@ -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,123 @@
|
|
|
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 rect = element.getBoundingClientRect();
|
|
45
|
+
overlay.style.top = `${rect.top + window.scrollY}px`;
|
|
46
|
+
overlay.style.left = `${rect.left + window.scrollX}px`;
|
|
47
|
+
overlay.style.width = `${rect.width}px`;
|
|
48
|
+
overlay.style.height = `${rect.height}px`;
|
|
49
|
+
|
|
50
|
+
// Check if label already exists in overlay
|
|
51
|
+
let label = overlay.querySelector("div") as HTMLDivElement | null;
|
|
52
|
+
|
|
53
|
+
if (!label) {
|
|
54
|
+
label = document.createElement("div");
|
|
55
|
+
label.textContent = element.tagName.toLowerCase();
|
|
56
|
+
label.style.position = "absolute";
|
|
57
|
+
label.style.top = LABEL_TOP_OFFSET;
|
|
58
|
+
label.style.left = LABEL_LEFT_OFFSET;
|
|
59
|
+
label.style.padding = "2px 8px";
|
|
60
|
+
label.style.fontSize = "11px";
|
|
61
|
+
label.style.fontWeight = isSelected ? "500" : "400";
|
|
62
|
+
label.style.color = isSelected ? "#ffffff" : "#526cff";
|
|
63
|
+
label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
|
|
64
|
+
label.style.borderRadius = "3px";
|
|
65
|
+
label.style.minWidth = "24px";
|
|
66
|
+
label.style.textAlign = "center";
|
|
67
|
+
overlay.appendChild(label);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Clear all overlays from DOM
|
|
73
|
+
*/
|
|
74
|
+
export function clearOverlays(overlays: HTMLDivElement[]): void {
|
|
75
|
+
overlays.forEach((overlay) => {
|
|
76
|
+
if (overlay && overlay.parentNode) {
|
|
77
|
+
overlay.remove();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Remove data-selected attribute, clear selected overlays, and reset selection state
|
|
84
|
+
*/
|
|
85
|
+
export function clearSelection(state: AgentState): void {
|
|
86
|
+
if (state.selectedElementId) {
|
|
87
|
+
const elements = findElementsById(state.selectedElementId);
|
|
88
|
+
elements.forEach((el) => {
|
|
89
|
+
if (el instanceof HTMLElement) {
|
|
90
|
+
delete el.dataset.selected;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
clearOverlays(state.selectedOverlays);
|
|
95
|
+
state.selectedOverlays = [];
|
|
96
|
+
state.selectedElementId = null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Reposition selected overlays to match current element bounds
|
|
101
|
+
*/
|
|
102
|
+
export function repositionSelectedOverlays(state: AgentState): void {
|
|
103
|
+
if (!state.selectedElementId) return;
|
|
104
|
+
const elements = findElementsById(state.selectedElementId);
|
|
105
|
+
state.selectedOverlays.forEach((overlay, index) => {
|
|
106
|
+
const element = elements[index];
|
|
107
|
+
if (element) {
|
|
108
|
+
positionOverlay(overlay, element, true, state.isVisualEditMode);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Reposition hover overlays to match current element bounds
|
|
115
|
+
*/
|
|
116
|
+
export function repositionHoverOverlays(state: AgentState): void {
|
|
117
|
+
state.hoverOverlays.forEach((overlay, index) => {
|
|
118
|
+
const element = state.currentHighlightedElements[index];
|
|
119
|
+
if (element) {
|
|
120
|
+
positionOverlay(overlay, element, false, state.isVisualEditMode);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|