@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.
Files changed (120) hide show
  1. package/dist/injections/utils.d.ts +0 -6
  2. package/dist/injections/utils.d.ts.map +1 -1
  3. package/dist/injections/utils.js +0 -25
  4. package/dist/injections/utils.js.map +1 -1
  5. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +25 -0
  6. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +1 -0
  7. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +95 -0
  8. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +1 -0
  9. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +4 -0
  10. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +1 -0
  11. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +4 -0
  12. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +1 -0
  13. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +9 -0
  14. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +1 -0
  15. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +26 -0
  16. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +1 -0
  17. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +10 -0
  18. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +1 -0
  19. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +60 -0
  20. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +1 -0
  21. package/dist/injections/visual-edit-agent/constants.d.ts +10 -0
  22. package/dist/injections/visual-edit-agent/constants.d.ts.map +1 -0
  23. package/dist/injections/visual-edit-agent/constants.js +10 -0
  24. package/dist/injections/visual-edit-agent/constants.js.map +1 -0
  25. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +10 -0
  26. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +1 -0
  27. package/dist/injections/visual-edit-agent/handlers/click-handlers.js +107 -0
  28. package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +1 -0
  29. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +14 -0
  30. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +1 -0
  31. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +64 -0
  32. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +1 -0
  33. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +14 -0
  34. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +1 -0
  35. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +109 -0
  36. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +1 -0
  37. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +26 -0
  38. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +1 -0
  39. package/dist/injections/visual-edit-agent/handlers/message-handlers.js +145 -0
  40. package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +1 -0
  41. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +7 -0
  42. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +1 -0
  43. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +58 -0
  44. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +1 -0
  45. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +11 -0
  46. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +1 -0
  47. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +32 -0
  48. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +1 -0
  49. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +86 -0
  50. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +1 -0
  51. package/dist/injections/visual-edit-agent/handlers/messages/types.js +28 -0
  52. package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +1 -0
  53. package/dist/injections/visual-edit-agent/index.d.ts +5 -0
  54. package/dist/injections/visual-edit-agent/index.d.ts.map +1 -0
  55. package/dist/injections/visual-edit-agent/index.js +106 -0
  56. package/dist/injections/visual-edit-agent/index.js.map +1 -0
  57. package/dist/injections/visual-edit-agent/state/agent-state.d.ts +17 -0
  58. package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +1 -0
  59. package/dist/injections/visual-edit-agent/state/agent-state.js +18 -0
  60. package/dist/injections/visual-edit-agent/state/agent-state.js.map +1 -0
  61. package/dist/injections/visual-edit-agent/ui/overlay.d.ts +26 -0
  62. package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +1 -0
  63. package/dist/injections/visual-edit-agent/ui/overlay.js +102 -0
  64. package/dist/injections/visual-edit-agent/ui/overlay.js.map +1 -0
  65. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +14 -0
  66. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +1 -0
  67. package/dist/injections/visual-edit-agent/utils/dom-utils.js +34 -0
  68. package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +1 -0
  69. package/dist/injections/visual-edit-agent.d.ts +1 -1
  70. package/dist/injections/visual-edit-agent.d.ts.map +1 -1
  71. package/dist/injections/visual-edit-agent.js +1 -474
  72. package/dist/injections/visual-edit-agent.js.map +1 -1
  73. package/dist/statics/index.mjs +5 -1
  74. package/dist/statics/index.mjs.map +1 -1
  75. package/package.json +1 -1
  76. package/src/injections/utils.ts +0 -34
  77. package/src/injections/visual-edit-agent/README.md +222 -0
  78. package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +120 -0
  79. package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +10 -0
  80. package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +26 -0
  81. package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +67 -0
  82. package/src/injections/visual-edit-agent/constants.ts +9 -0
  83. package/src/injections/visual-edit-agent/handlers/click-handlers.ts +134 -0
  84. package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
  85. package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +141 -0
  86. package/src/injections/visual-edit-agent/handlers/message-handlers.ts +191 -0
  87. package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +70 -0
  88. package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +40 -0
  89. package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
  90. package/src/injections/visual-edit-agent/index.ts +120 -0
  91. package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
  92. package/src/injections/visual-edit-agent/ui/overlay.ts +123 -0
  93. package/src/injections/visual-edit-agent/utils/dom-utils.ts +39 -0
  94. package/src/injections/visual-edit-agent.ts +1 -577
  95. package/dist/injections/layer-dropdown/consts.d.ts +0 -15
  96. package/dist/injections/layer-dropdown/consts.d.ts.map +0 -1
  97. package/dist/injections/layer-dropdown/consts.js +0 -36
  98. package/dist/injections/layer-dropdown/consts.js.map +0 -1
  99. package/dist/injections/layer-dropdown/controller.d.ts +0 -4
  100. package/dist/injections/layer-dropdown/controller.d.ts.map +0 -1
  101. package/dist/injections/layer-dropdown/controller.js +0 -85
  102. package/dist/injections/layer-dropdown/controller.js.map +0 -1
  103. package/dist/injections/layer-dropdown/dropdown-ui.d.ts +0 -13
  104. package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +0 -1
  105. package/dist/injections/layer-dropdown/dropdown-ui.js +0 -158
  106. package/dist/injections/layer-dropdown/dropdown-ui.js.map +0 -1
  107. package/dist/injections/layer-dropdown/types.d.ts +0 -21
  108. package/dist/injections/layer-dropdown/types.d.ts.map +0 -1
  109. package/dist/injections/layer-dropdown/types.js +0 -3
  110. package/dist/injections/layer-dropdown/types.js.map +0 -1
  111. package/dist/injections/layer-dropdown/utils.d.ts +0 -24
  112. package/dist/injections/layer-dropdown/utils.d.ts.map +0 -1
  113. package/dist/injections/layer-dropdown/utils.js +0 -150
  114. package/dist/injections/layer-dropdown/utils.js.map +0 -1
  115. package/src/injections/layer-dropdown/LAYERS.md +0 -258
  116. package/src/injections/layer-dropdown/consts.ts +0 -44
  117. package/src/injections/layer-dropdown/controller.ts +0 -105
  118. package/src/injections/layer-dropdown/dropdown-ui.ts +0 -221
  119. package/src/injections/layer-dropdown/types.ts +0 -24
  120. 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,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,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
+ }