@base44-preview/vite-plugin 0.2.22-pr.36.db00ef7 → 0.2.22-pr.37.68542f2
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 +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 +104 -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 +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 +100 -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 +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 +136 -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 +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 +121 -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 -23
- package/dist/injections/layer-dropdown/utils.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/utils.js +0 -119
- package/dist/injections/layer-dropdown/utils.js.map +0 -1
- 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 -148
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export {
|
|
2
|
+
enterInlineEditingMode,
|
|
3
|
+
clearInlineEditingMode,
|
|
4
|
+
shouldEnterInlineEditingMode,
|
|
5
|
+
setInlineEditCallback,
|
|
6
|
+
} from "./core.js";
|
|
7
|
+
|
|
8
|
+
export { injectFocusOutlineCSS, removeFocusOutlineCSS } from "./styles.js";
|
|
9
|
+
|
|
10
|
+
export { isEditableTextElement, selectText } from "./validation.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject CSS to suppress the browser's default focus outline on contentEditable elements
|
|
3
|
+
*/
|
|
4
|
+
export function injectFocusOutlineCSS(): void {
|
|
5
|
+
const existingStyle = document.getElementById("visual-edit-focus-styles");
|
|
6
|
+
if (existingStyle) return;
|
|
7
|
+
|
|
8
|
+
const style = document.createElement("style");
|
|
9
|
+
style.id = "visual-edit-focus-styles";
|
|
10
|
+
style.textContent = `
|
|
11
|
+
[data-selected="true"][contenteditable="true"]:focus {
|
|
12
|
+
outline: none !important;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
document.head.appendChild(style);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Remove the injected focus outline CSS
|
|
20
|
+
*/
|
|
21
|
+
export function removeFocusOutlineCSS(): void {
|
|
22
|
+
const style = document.getElementById("visual-edit-focus-styles");
|
|
23
|
+
if (style) {
|
|
24
|
+
style.remove();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select all text content in an element using the Selection API
|
|
3
|
+
*/
|
|
4
|
+
export function selectText(element: HTMLElement): void {
|
|
5
|
+
const range = document.createRange();
|
|
6
|
+
range.selectNodeContents(element);
|
|
7
|
+
const selection = window.getSelection();
|
|
8
|
+
selection?.removeAllRanges();
|
|
9
|
+
selection?.addRange(range);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if an element is an editable text element
|
|
14
|
+
* Based on the eligibility rules from inlineEdit.md (non-dynamic only)
|
|
15
|
+
*/
|
|
16
|
+
export function isEditableTextElement(element: Element): boolean {
|
|
17
|
+
// Must be an HTMLElement
|
|
18
|
+
if (!(element instanceof HTMLElement)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Must be an allowed tag
|
|
23
|
+
const allowedTags = [
|
|
24
|
+
"div",
|
|
25
|
+
"p",
|
|
26
|
+
"h1",
|
|
27
|
+
"h2",
|
|
28
|
+
"h3",
|
|
29
|
+
"h4",
|
|
30
|
+
"h5",
|
|
31
|
+
"h6",
|
|
32
|
+
"span",
|
|
33
|
+
"li",
|
|
34
|
+
"td",
|
|
35
|
+
"a",
|
|
36
|
+
"button",
|
|
37
|
+
"label",
|
|
38
|
+
];
|
|
39
|
+
if (!allowedTags.includes(element.tagName.toLowerCase())) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Must have text content
|
|
44
|
+
const textContent = element.textContent?.trim() || "";
|
|
45
|
+
if (textContent.length === 0) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Must NOT contain img, video, canvas, or svg
|
|
50
|
+
const hasMediaElements =
|
|
51
|
+
element.querySelector("img, video, canvas, svg") !== null;
|
|
52
|
+
if (hasMediaElements) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Must NOT have complex children (must be a leaf text node or simple container)
|
|
57
|
+
if (element.children.length > 0) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Must NOT be dynamic content
|
|
62
|
+
if (element.dataset.dynamicContent === "true") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const INLINE_EDIT_DEBOUNCE_MS = 500;
|
|
2
|
+
export const OVERLAY_TRANSITION = "all 0.1s ease-in-out";
|
|
3
|
+
export const OVERLAY_Z_INDEX = "9999";
|
|
4
|
+
export const SELECTED_BORDER_COLOR = "#2563EB";
|
|
5
|
+
export const HOVER_BORDER_COLOR = "#95a5fc";
|
|
6
|
+
export const HOVER_BACKGROUND_COLOR = "rgba(99, 102, 241, 0.05)";
|
|
7
|
+
export const LABEL_TOP_OFFSET = "-27px";
|
|
8
|
+
export const LABEL_LEFT_OFFSET = "-2px";
|
|
9
|
+
export const REPOSITION_DELAY_MS = 50;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { AgentState } from "../state/agent-state.js";
|
|
2
|
+
import { OutgoingMessageType } from "./messages/types.js";
|
|
3
|
+
import { findElementsById } from "../../utils.js";
|
|
4
|
+
import { createOverlay, positionOverlay, clearSelection } from "../ui/overlay.js";
|
|
5
|
+
import { clearHoverOverlays } from "./hover-handlers.js";
|
|
6
|
+
import { shouldEnterInlineEditingMode } from "../capabilities/inline-editing/index.js";
|
|
7
|
+
import { handleClearInlineEditingMode, handleEnterInlineEditingMode } from "./inline-edit-handlers.js";
|
|
8
|
+
import { getElementPosition, getElementClasses } from "../utils/dom-utils.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Handle element selection (first click)
|
|
12
|
+
*/
|
|
13
|
+
export function handleElementSelection(
|
|
14
|
+
state: AgentState,
|
|
15
|
+
element: Element,
|
|
16
|
+
visualSelectorId: string | null
|
|
17
|
+
): void {
|
|
18
|
+
if (state.currentEditingElement) {
|
|
19
|
+
handleClearInlineEditingMode(state);
|
|
20
|
+
}
|
|
21
|
+
clearSelection(state);
|
|
22
|
+
|
|
23
|
+
// Find all elements with the same ID
|
|
24
|
+
const elements = findElementsById(visualSelectorId);
|
|
25
|
+
|
|
26
|
+
// Mark elements as selected
|
|
27
|
+
elements.forEach((el) => {
|
|
28
|
+
if (el instanceof HTMLElement) {
|
|
29
|
+
el.dataset.selected = "true";
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Create selected overlays for all matching elements
|
|
34
|
+
elements.forEach((el) => {
|
|
35
|
+
const overlay = createOverlay(true);
|
|
36
|
+
document.body.appendChild(overlay);
|
|
37
|
+
state.selectedOverlays.push(overlay);
|
|
38
|
+
positionOverlay(overlay, el, true, state.isVisualEditMode);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
state.selectedElementId = visualSelectorId;
|
|
42
|
+
|
|
43
|
+
// Clear hover overlays
|
|
44
|
+
clearHoverOverlays(state);
|
|
45
|
+
|
|
46
|
+
// Send message to parent window with element info
|
|
47
|
+
const htmlElement = element as HTMLElement;
|
|
48
|
+
const elementData = {
|
|
49
|
+
type: OutgoingMessageType.ELEMENT_SELECTED,
|
|
50
|
+
tagName: element.tagName,
|
|
51
|
+
classes: getElementClasses(element),
|
|
52
|
+
visualSelectorId: visualSelectorId,
|
|
53
|
+
content: htmlElement.innerText,
|
|
54
|
+
dataSourceLocation: htmlElement.dataset.sourceLocation,
|
|
55
|
+
isDynamicContent: htmlElement.dataset.dynamicContent === "true",
|
|
56
|
+
linenumber: htmlElement.dataset.linenumber,
|
|
57
|
+
filename: htmlElement.dataset.filename,
|
|
58
|
+
position: getElementPosition(element.getBoundingClientRect()),
|
|
59
|
+
};
|
|
60
|
+
window.parent.postMessage(elementData, "*");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Handle element click
|
|
65
|
+
*/
|
|
66
|
+
export function handleElementClick(state: AgentState, e: MouseEvent): void {
|
|
67
|
+
if (!state.isVisualEditMode) return;
|
|
68
|
+
|
|
69
|
+
const target = e.target as Element;
|
|
70
|
+
|
|
71
|
+
// Bail out early if clicking on a contentEditable element (allow normal editing)
|
|
72
|
+
if (target instanceof HTMLElement && target.contentEditable === "true") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// If currently editing, clicking outside should exit editing mode
|
|
77
|
+
if (state.currentEditingElement) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
e.stopImmediatePropagation();
|
|
81
|
+
handleClearInlineEditingMode(state);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Close dropdowns when clicking anywhere in iframe if a dropdown is open
|
|
86
|
+
if (state.isDropdownOpen) {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
e.stopPropagation();
|
|
89
|
+
e.stopImmediatePropagation();
|
|
90
|
+
|
|
91
|
+
window.parent.postMessage({ type: OutgoingMessageType.CLOSE_DROPDOWNS }, "*");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Prevent clicking on SVG path elements
|
|
96
|
+
if (target.tagName.toLowerCase() === "path") {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Prevent default behavior immediately when in visual edit mode
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
e.stopImmediatePropagation();
|
|
104
|
+
|
|
105
|
+
// Support both data-source-location and data-visual-selector-id
|
|
106
|
+
const element = target.closest(
|
|
107
|
+
"[data-source-location], [data-visual-selector-id]"
|
|
108
|
+
);
|
|
109
|
+
if (!element) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const htmlElement = element as HTMLElement;
|
|
114
|
+
const visualSelectorId =
|
|
115
|
+
htmlElement.dataset.sourceLocation ||
|
|
116
|
+
htmlElement.dataset.visualSelectorId;
|
|
117
|
+
|
|
118
|
+
// Check if this element is already selected (second click scenario)
|
|
119
|
+
const isAlreadySelected =
|
|
120
|
+
state.selectedElementId === visualSelectorId &&
|
|
121
|
+
htmlElement.dataset.selected === "true";
|
|
122
|
+
|
|
123
|
+
if (isAlreadySelected) {
|
|
124
|
+
// Second click on already-selected element: check if it should enter inline editing
|
|
125
|
+
// Only if the experiment is enabled
|
|
126
|
+
if (state.isInlineEditExperimentEnabled && shouldEnterInlineEditingMode(htmlElement)) {
|
|
127
|
+
handleEnterInlineEditingMode(state, htmlElement);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// First click: select the element
|
|
133
|
+
handleElementSelection(state, element, visualSelectorId || null);
|
|
134
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AgentState } from "../state/agent-state.js";
|
|
2
|
+
import { findElementsById } from "../../utils.js";
|
|
3
|
+
import { createOverlay, positionOverlay, clearOverlays } from "../ui/overlay.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Clear hover overlays
|
|
7
|
+
*/
|
|
8
|
+
export function clearHoverOverlays(state: AgentState): void {
|
|
9
|
+
clearOverlays(state.hoverOverlays);
|
|
10
|
+
state.hoverOverlays = [];
|
|
11
|
+
state.currentHighlightedElements = [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handle mouse over event
|
|
16
|
+
*/
|
|
17
|
+
export function handleMouseOver(state: AgentState, e: MouseEvent): void {
|
|
18
|
+
if (!state.isVisualEditMode || state.isPopoverDragging || state.currentEditingElement) return;
|
|
19
|
+
|
|
20
|
+
const target = e.target as Element;
|
|
21
|
+
|
|
22
|
+
// Prevent hover effects when a dropdown is open
|
|
23
|
+
if (state.isDropdownOpen) {
|
|
24
|
+
clearHoverOverlays(state);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Prevent hover effects on SVG path elements
|
|
29
|
+
if (target.tagName.toLowerCase() === "path") {
|
|
30
|
+
clearHoverOverlays(state);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Support both data-source-location and data-visual-selector-id
|
|
35
|
+
const element = target.closest(
|
|
36
|
+
"[data-source-location], [data-visual-selector-id]"
|
|
37
|
+
);
|
|
38
|
+
if (!element) {
|
|
39
|
+
clearHoverOverlays(state);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Prefer data-source-location, fallback to data-visual-selector-id
|
|
44
|
+
const htmlElement = element as HTMLElement;
|
|
45
|
+
const selectorId =
|
|
46
|
+
htmlElement.dataset.sourceLocation ||
|
|
47
|
+
htmlElement.dataset.visualSelectorId;
|
|
48
|
+
|
|
49
|
+
// Skip if this element is already selected
|
|
50
|
+
if (state.selectedElementId === selectorId) {
|
|
51
|
+
clearHoverOverlays(state);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Find all elements with the same ID
|
|
56
|
+
const elements = findElementsById(selectorId || null);
|
|
57
|
+
|
|
58
|
+
// Clear previous hover overlays
|
|
59
|
+
clearHoverOverlays(state);
|
|
60
|
+
|
|
61
|
+
// Create overlays for all matching elements
|
|
62
|
+
elements.forEach((el) => {
|
|
63
|
+
const overlay = createOverlay(false);
|
|
64
|
+
document.body.appendChild(overlay);
|
|
65
|
+
state.hoverOverlays.push(overlay);
|
|
66
|
+
positionOverlay(overlay, el, false, state.isVisualEditMode);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
state.currentHighlightedElements = elements;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Handle mouse out event
|
|
74
|
+
*/
|
|
75
|
+
export function handleMouseOut(state: AgentState): void {
|
|
76
|
+
if (state.isPopoverDragging || state.currentEditingElement) return;
|
|
77
|
+
clearHoverOverlays(state);
|
|
78
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AgentState } from "../state/agent-state.js";
|
|
2
|
+
import { OutgoingMessageType } from "./messages/types.js";
|
|
3
|
+
import { repositionSelectedOverlays } from "../ui/overlay.js";
|
|
4
|
+
import {
|
|
5
|
+
enterInlineEditingMode,
|
|
6
|
+
clearInlineEditingMode,
|
|
7
|
+
setInlineEditCallback,
|
|
8
|
+
} from "../capabilities/inline-editing/index.js";
|
|
9
|
+
import { INLINE_EDIT_DEBOUNCE_MS } from "../constants.js";
|
|
10
|
+
import { getElementPosition, getElementClasses } from "../utils/dom-utils.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Enter inline editing mode
|
|
14
|
+
*/
|
|
15
|
+
export function handleEnterInlineEditingMode(state: AgentState, element: HTMLElement): void {
|
|
16
|
+
state.currentEditingElement = element;
|
|
17
|
+
|
|
18
|
+
// Hide overlays during editing
|
|
19
|
+
state.selectedOverlays.forEach((overlay) => {
|
|
20
|
+
overlay.style.display = "none";
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Enter inline editing mode (from capabilities/inline-editing)
|
|
24
|
+
enterInlineEditingMode(element);
|
|
25
|
+
|
|
26
|
+
// Notify parent
|
|
27
|
+
window.parent.postMessage(
|
|
28
|
+
{
|
|
29
|
+
type: OutgoingMessageType.CONTENT_EDITING_STARTED,
|
|
30
|
+
visualSelectorId: state.selectedElementId,
|
|
31
|
+
},
|
|
32
|
+
"*"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Clear inline editing mode
|
|
38
|
+
*/
|
|
39
|
+
export function handleClearInlineEditingMode(state: AgentState): void {
|
|
40
|
+
if (!state.currentEditingElement) return;
|
|
41
|
+
|
|
42
|
+
// Cancel any pending debounced edit — originalTextContent will be deleted below
|
|
43
|
+
if (state.debouncedSendTimeout) {
|
|
44
|
+
clearTimeout(state.debouncedSendTimeout);
|
|
45
|
+
state.debouncedSendTimeout = null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const element = state.currentEditingElement;
|
|
49
|
+
|
|
50
|
+
// Clear inline editing mode (from capabilities/inline-editing)
|
|
51
|
+
clearInlineEditingMode(element);
|
|
52
|
+
|
|
53
|
+
// Show overlays again
|
|
54
|
+
state.selectedOverlays.forEach((overlay) => {
|
|
55
|
+
overlay.style.display = "";
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
repositionSelectedOverlays(state);
|
|
59
|
+
|
|
60
|
+
// Notify parent that editing ended
|
|
61
|
+
window.parent.postMessage(
|
|
62
|
+
{
|
|
63
|
+
type: OutgoingMessageType.CONTENT_EDITING_ENDED,
|
|
64
|
+
visualSelectorId: state.selectedElementId,
|
|
65
|
+
},
|
|
66
|
+
"*"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
state.currentEditingElement = null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Report inline edit to parent
|
|
74
|
+
*/
|
|
75
|
+
function reportInlineEdit(state: AgentState, element: HTMLElement): void {
|
|
76
|
+
const originalContent = element.dataset.originalTextContent;
|
|
77
|
+
const newContent = element.textContent;
|
|
78
|
+
|
|
79
|
+
const elementInfo = {
|
|
80
|
+
tagName: element.tagName,
|
|
81
|
+
classes: getElementClasses(element),
|
|
82
|
+
visualSelectorId: state.selectedElementId,
|
|
83
|
+
content: newContent,
|
|
84
|
+
dataSourceLocation: element.dataset.sourceLocation,
|
|
85
|
+
isDynamicContent: element.dataset.dynamicContent === "true",
|
|
86
|
+
linenumber: element.dataset.linenumber,
|
|
87
|
+
filename: element.dataset.filename,
|
|
88
|
+
position: getElementPosition(element.getBoundingClientRect()),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Send inline edit message
|
|
92
|
+
window.parent.postMessage(
|
|
93
|
+
{
|
|
94
|
+
type: OutgoingMessageType.INLINE_EDIT,
|
|
95
|
+
elementInfo,
|
|
96
|
+
originalContent,
|
|
97
|
+
newContent,
|
|
98
|
+
},
|
|
99
|
+
"*"
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Update baseline for next edit
|
|
103
|
+
element.dataset.originalTextContent = newContent || "";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Debounced function to send inline edit messages
|
|
108
|
+
*/
|
|
109
|
+
function debouncedSendInlineEditMessage(state: AgentState, element: HTMLElement): void {
|
|
110
|
+
// Clear any existing timeout
|
|
111
|
+
if (state.debouncedSendTimeout) {
|
|
112
|
+
clearTimeout(state.debouncedSendTimeout);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Set new timeout
|
|
116
|
+
state.debouncedSendTimeout = setTimeout(() => {
|
|
117
|
+
reportInlineEdit(state, element);
|
|
118
|
+
}, INLINE_EDIT_DEBOUNCE_MS);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Callback for text input changes (combines updatePosition and reportInlineEdit)
|
|
123
|
+
*/
|
|
124
|
+
function createTextInputChangeCallback(state: AgentState) {
|
|
125
|
+
return (element: HTMLElement) => {
|
|
126
|
+
repositionSelectedOverlays(state);
|
|
127
|
+
debouncedSendInlineEditMessage(state, element);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Setup inline edit callback
|
|
133
|
+
*/
|
|
134
|
+
export function setupInlineEditCallback(state: AgentState): void {
|
|
135
|
+
setInlineEditCallback(createTextInputChangeCallback(state));
|
|
136
|
+
}
|
|
@@ -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
|
+
}
|