@base44-preview/vite-plugin 0.2.22-pr.36.d652cb1 → 0.2.22-pr.37.1da8402
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 +108 -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 +54 -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 +95 -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 +104 -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 +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 +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 +65 -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 +108 -0
- package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
- package/src/injections/visual-edit-agent/ui/overlay.ts +126 -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,120 @@
|
|
|
1
|
+
import { injectFocusOutlineCSS, removeFocusOutlineCSS } from "./styles.js";
|
|
2
|
+
import { selectText, isEditableTextElement } from "./validation.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Callback function type for handling text input changes
|
|
6
|
+
*/
|
|
7
|
+
type OnTextInputChange = (element: HTMLElement) => void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Global callback that gets triggered on every input event
|
|
11
|
+
* This is set by the visual-edit-agent and includes both updatePosition and reportInlineEdit
|
|
12
|
+
*/
|
|
13
|
+
let onTextInputChangeCallback: OnTextInputChange | null = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Set the callback function that will be called on text input changes
|
|
17
|
+
*/
|
|
18
|
+
export function setInlineEditCallback(callback: OnTextInputChange | null): void {
|
|
19
|
+
onTextInputChangeCallback = callback;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WeakMap to track AbortControllers for each element's input listener.
|
|
24
|
+
* Using WeakMap ensures no memory leaks — when an element is garbage collected,
|
|
25
|
+
* its entry is automatically removed.
|
|
26
|
+
*/
|
|
27
|
+
const listenerAbortControllers = new WeakMap<HTMLElement, AbortController>();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Internal handler for the native input event
|
|
31
|
+
*/
|
|
32
|
+
function handleInputEvent(this: HTMLElement, e: Event): void {
|
|
33
|
+
if (onTextInputChangeCallback) {
|
|
34
|
+
onTextInputChangeCallback(this);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Check if an element should enter inline editing mode
|
|
40
|
+
* Called when user clicks on an already-selected element
|
|
41
|
+
*/
|
|
42
|
+
export function shouldEnterInlineEditingMode(element: Element): boolean {
|
|
43
|
+
// Must have data-selected="true"
|
|
44
|
+
if (!(element instanceof HTMLElement) || element.dataset.selected !== "true") {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Must pass all editability checks
|
|
49
|
+
if (!isEditableTextElement(element)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Enable contentEditable mode on an element
|
|
58
|
+
* Follows the exact flow from inlineEdit.md
|
|
59
|
+
*/
|
|
60
|
+
export function enterInlineEditingMode(element: HTMLElement): void {
|
|
61
|
+
// Inject CSS to suppress focus outline
|
|
62
|
+
injectFocusOutlineCSS();
|
|
63
|
+
|
|
64
|
+
// Store original state
|
|
65
|
+
element.dataset.originalTextContent = element.textContent || "";
|
|
66
|
+
element.dataset.originalCursor = element.style.cursor;
|
|
67
|
+
|
|
68
|
+
// Enable contentEditable
|
|
69
|
+
element.contentEditable = "true";
|
|
70
|
+
|
|
71
|
+
// Create an AbortController to manage the input listener lifecycle
|
|
72
|
+
const abortController = new AbortController();
|
|
73
|
+
listenerAbortControllers.set(element, abortController);
|
|
74
|
+
|
|
75
|
+
// Add input event listener with AbortSignal for automatic cleanup
|
|
76
|
+
element.addEventListener("input", handleInputEvent, { signal: abortController.signal });
|
|
77
|
+
|
|
78
|
+
// Set cursor to text
|
|
79
|
+
element.style.cursor = "text";
|
|
80
|
+
|
|
81
|
+
// Select all text
|
|
82
|
+
selectText(element);
|
|
83
|
+
|
|
84
|
+
// Focus after render
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
element.focus();
|
|
87
|
+
}, 0);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Disable contentEditable mode on an element
|
|
92
|
+
* Reverses everything done by enterInlineEditingMode
|
|
93
|
+
*/
|
|
94
|
+
export function clearInlineEditingMode(element: HTMLElement): void {
|
|
95
|
+
// Abort the input event listener using the stored AbortController
|
|
96
|
+
const abortController = listenerAbortControllers.get(element);
|
|
97
|
+
if (abortController) {
|
|
98
|
+
abortController.abort();
|
|
99
|
+
listenerAbortControllers.delete(element);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If element was removed from DOM before cleanup, skip DOM operations
|
|
103
|
+
if (!element.isConnected) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
removeFocusOutlineCSS();
|
|
108
|
+
|
|
109
|
+
// Disable contentEditable
|
|
110
|
+
element.contentEditable = "false";
|
|
111
|
+
|
|
112
|
+
// Remove stored original text content
|
|
113
|
+
delete element.dataset.originalTextContent;
|
|
114
|
+
|
|
115
|
+
// Restore original cursor
|
|
116
|
+
if (element.dataset.originalCursor !== undefined) {
|
|
117
|
+
element.style.cursor = element.dataset.originalCursor;
|
|
118
|
+
delete element.dataset.originalCursor;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -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,135 @@
|
|
|
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
|
+
if (state.isInlineEditExperimentEnabled) {
|
|
27
|
+
elements.forEach((el) => {
|
|
28
|
+
if (el instanceof HTMLElement) {
|
|
29
|
+
el.dataset.selected = "true";
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Create selected overlays for all matching elements
|
|
35
|
+
elements.forEach((el) => {
|
|
36
|
+
const overlay = createOverlay(true);
|
|
37
|
+
document.body.appendChild(overlay);
|
|
38
|
+
state.selectedOverlays.push(overlay);
|
|
39
|
+
positionOverlay(overlay, el, true, state.isVisualEditMode);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
state.selectedElementId = visualSelectorId;
|
|
43
|
+
|
|
44
|
+
// Clear hover overlays
|
|
45
|
+
clearHoverOverlays(state);
|
|
46
|
+
|
|
47
|
+
// Send message to parent window with element info
|
|
48
|
+
const htmlElement = element as HTMLElement;
|
|
49
|
+
const elementData = {
|
|
50
|
+
type: OutgoingMessageType.ELEMENT_SELECTED,
|
|
51
|
+
tagName: element.tagName,
|
|
52
|
+
classes: getElementClasses(element),
|
|
53
|
+
visualSelectorId: visualSelectorId,
|
|
54
|
+
content: htmlElement.innerText,
|
|
55
|
+
dataSourceLocation: htmlElement.dataset.sourceLocation,
|
|
56
|
+
isDynamicContent: htmlElement.dataset.dynamicContent === "true",
|
|
57
|
+
linenumber: htmlElement.dataset.linenumber,
|
|
58
|
+
filename: htmlElement.dataset.filename,
|
|
59
|
+
position: getElementPosition(element.getBoundingClientRect()),
|
|
60
|
+
};
|
|
61
|
+
window.parent.postMessage(elementData, "*");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Handle element click
|
|
66
|
+
*/
|
|
67
|
+
export function handleElementClick(state: AgentState, e: MouseEvent): void {
|
|
68
|
+
if (!state.isVisualEditMode) return;
|
|
69
|
+
|
|
70
|
+
const target = e.target as Element;
|
|
71
|
+
|
|
72
|
+
// Bail out early if clicking on a contentEditable element (allow normal editing)
|
|
73
|
+
if (state.isInlineEditExperimentEnabled && target instanceof HTMLElement && target.contentEditable === "true") {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If currently editing, clicking outside should exit editing mode
|
|
78
|
+
if (state.currentEditingElement) {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
e.stopImmediatePropagation();
|
|
82
|
+
handleClearInlineEditingMode(state);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Close dropdowns when clicking anywhere in iframe if a dropdown is open
|
|
87
|
+
if (state.isDropdownOpen) {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
e.stopImmediatePropagation();
|
|
91
|
+
|
|
92
|
+
window.parent.postMessage({ type: OutgoingMessageType.CLOSE_DROPDOWNS }, "*");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Prevent clicking on SVG path elements
|
|
97
|
+
if (target.tagName.toLowerCase() === "path") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Prevent default behavior immediately when in visual edit mode
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
e.stopImmediatePropagation();
|
|
105
|
+
|
|
106
|
+
// Support both data-source-location and data-visual-selector-id
|
|
107
|
+
const element = target.closest(
|
|
108
|
+
"[data-source-location], [data-visual-selector-id]"
|
|
109
|
+
);
|
|
110
|
+
if (!element) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const htmlElement = element as HTMLElement;
|
|
115
|
+
const visualSelectorId =
|
|
116
|
+
htmlElement.dataset.sourceLocation ||
|
|
117
|
+
htmlElement.dataset.visualSelectorId;
|
|
118
|
+
|
|
119
|
+
// Check if this element is already selected (second click scenario)
|
|
120
|
+
const isAlreadySelected =
|
|
121
|
+
state.selectedElementId === visualSelectorId &&
|
|
122
|
+
htmlElement.dataset.selected === "true";
|
|
123
|
+
|
|
124
|
+
if (isAlreadySelected) {
|
|
125
|
+
// Second click on already-selected element: check if it should enter inline editing
|
|
126
|
+
// Only if the experiment is enabled
|
|
127
|
+
if (state.isInlineEditExperimentEnabled && shouldEnterInlineEditingMode(htmlElement)) {
|
|
128
|
+
handleEnterInlineEditingMode(state, htmlElement);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// First click: select the element
|
|
134
|
+
handleElementSelection(state, element, visualSelectorId || null);
|
|
135
|
+
}
|
|
@@ -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,141 @@
|
|
|
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
|
+
* Intentionally overwrites the previous timeout on each keystroke — this is the
|
|
110
|
+
* correct debounce behavior. We only send ONE message 500ms after the user stops
|
|
111
|
+
* typing, containing the final text. Intermediate keystrokes are not sent to avoid
|
|
112
|
+
* flooding the parent with dozens of messages per second.
|
|
113
|
+
*/
|
|
114
|
+
function debouncedSendInlineEditMessage(state: AgentState, element: HTMLElement): void {
|
|
115
|
+
// Clear any existing timeout
|
|
116
|
+
if (state.debouncedSendTimeout) {
|
|
117
|
+
clearTimeout(state.debouncedSendTimeout);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Set new timeout
|
|
121
|
+
state.debouncedSendTimeout = setTimeout(() => {
|
|
122
|
+
reportInlineEdit(state, element);
|
|
123
|
+
}, INLINE_EDIT_DEBOUNCE_MS);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Callback for text input changes (combines updatePosition and reportInlineEdit)
|
|
128
|
+
*/
|
|
129
|
+
function createTextInputChangeCallback(state: AgentState) {
|
|
130
|
+
return (element: HTMLElement) => {
|
|
131
|
+
repositionSelectedOverlays(state);
|
|
132
|
+
debouncedSendInlineEditMessage(state, element);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Setup inline edit callback
|
|
138
|
+
*/
|
|
139
|
+
export function setupInlineEditCallback(state: AgentState): void {
|
|
140
|
+
setInlineEditCallback(createTextInputChangeCallback(state));
|
|
141
|
+
}
|