@base44-preview/vite-plugin 0.2.22-pr.36.d652cb1 → 0.2.22-pr.37.466ee63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +78 -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 +109 -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 +99 -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 +42 -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 +33 -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 +100 -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 +103 -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 +100 -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 +135 -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 +130 -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 +51 -0
  88. package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +41 -0
  89. package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
  90. package/src/injections/visual-edit-agent/index.ts +116 -0
  91. package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
  92. package/src/injections/visual-edit-agent/ui/overlay.ts +125 -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,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 } 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 { unselectElement } from "./message-handlers.js";
9
+ import { getElementPosition, getElementClasses } from "../utils/dom-utils.js";
10
+
11
+ /**
12
+ * Handle element selection (first click)
13
+ */
14
+ export function handleElementSelection(
15
+ state: AgentState,
16
+ element: Element,
17
+ visualSelectorId: string | null
18
+ ): void {
19
+ unselectElement(state);
20
+
21
+ // Find all elements with the same ID
22
+ const elements = findElementsById(visualSelectorId);
23
+
24
+ // Mark elements as selected
25
+ elements.forEach((el) => {
26
+ if (el instanceof HTMLElement) {
27
+ el.dataset.selected = "true";
28
+ }
29
+ });
30
+
31
+ // Create selected overlays for all matching elements
32
+ elements.forEach((el) => {
33
+ const overlay = createOverlay(true);
34
+ document.body.appendChild(overlay);
35
+ state.selectedOverlays.push(overlay);
36
+ positionOverlay(overlay, el, true, state.isVisualEditMode);
37
+ });
38
+
39
+ state.selectedElementId = visualSelectorId;
40
+
41
+ // Clear hover overlays
42
+ clearHoverOverlays(state);
43
+
44
+ // Send message to parent window with element info
45
+ const htmlElement = element as HTMLElement;
46
+ const elementData = {
47
+ type: OutgoingMessageType.ELEMENT_SELECTED,
48
+ tagName: element.tagName,
49
+ classes: getElementClasses(element),
50
+ visualSelectorId: visualSelectorId,
51
+ content: htmlElement.innerText,
52
+ dataSourceLocation: htmlElement.dataset.sourceLocation,
53
+ isDynamicContent: htmlElement.dataset.dynamicContent === "true",
54
+ linenumber: htmlElement.dataset.linenumber,
55
+ filename: htmlElement.dataset.filename,
56
+ position: getElementPosition(element.getBoundingClientRect()),
57
+ };
58
+ window.parent.postMessage(elementData, "*");
59
+ }
60
+
61
+ /**
62
+ * Handle element click
63
+ */
64
+ export function handleElementClick(state: AgentState, e: MouseEvent): void {
65
+ if (!state.isVisualEditMode) return;
66
+
67
+ const target = e.target as Element;
68
+
69
+ // Bail out early if clicking on a contentEditable element (allow normal editing)
70
+ if (target instanceof HTMLElement && target.contentEditable === "true") {
71
+ return;
72
+ }
73
+
74
+ // If currently editing, clicking outside should exit editing mode
75
+ if (state.currentEditingElement) {
76
+ e.preventDefault();
77
+ e.stopPropagation();
78
+ e.stopImmediatePropagation();
79
+ handleClearInlineEditingMode(state);
80
+ return;
81
+ }
82
+
83
+ // Close dropdowns when clicking anywhere in iframe if a dropdown is open
84
+ if (state.isDropdownOpen) {
85
+ e.preventDefault();
86
+ e.stopPropagation();
87
+ e.stopImmediatePropagation();
88
+
89
+ window.parent.postMessage({ type: OutgoingMessageType.CLOSE_DROPDOWNS }, "*");
90
+ return;
91
+ }
92
+
93
+ // Prevent clicking on SVG path elements
94
+ if (target.tagName.toLowerCase() === "path") {
95
+ return;
96
+ }
97
+
98
+ // Prevent default behavior immediately when in visual edit mode
99
+ e.preventDefault();
100
+ e.stopPropagation();
101
+ e.stopImmediatePropagation();
102
+
103
+ // Support both data-source-location and data-visual-selector-id
104
+ const element = target.closest(
105
+ "[data-source-location], [data-visual-selector-id]"
106
+ );
107
+ if (!element) {
108
+ return;
109
+ }
110
+
111
+ const htmlElement = element as HTMLElement;
112
+ const visualSelectorId =
113
+ htmlElement.dataset.sourceLocation ||
114
+ htmlElement.dataset.visualSelectorId;
115
+
116
+ // Check if this element is already selected (second click scenario)
117
+ const isAlreadySelected =
118
+ state.selectedElementId === visualSelectorId &&
119
+ htmlElement.dataset.selected === "true";
120
+
121
+ if (isAlreadySelected) {
122
+ // Second click on already-selected element: check if it should enter inline editing
123
+ // Only if the experiment is enabled
124
+ if (state.isInlineEditExperimentEnabled && shouldEnterInlineEditingMode(htmlElement)) {
125
+ console.log('[VisualEditAgent] Entering inline edit mode');
126
+ handleEnterInlineEditingMode(state, htmlElement);
127
+ return;
128
+ } else if (!state.isInlineEditExperimentEnabled) {
129
+ console.log('[VisualEditAgent] Inline edit disabled - experiment flag not enabled');
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,130 @@
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
+ const element = state.currentEditingElement;
43
+
44
+ // Clear inline editing mode (from capabilities/inline-editing)
45
+ clearInlineEditingMode(element);
46
+
47
+ // Show overlays again
48
+ state.selectedOverlays.forEach((overlay) => {
49
+ overlay.style.display = "";
50
+ });
51
+
52
+ repositionSelectedOverlays(state);
53
+
54
+ // Notify parent that editing ended
55
+ window.parent.postMessage(
56
+ {
57
+ type: OutgoingMessageType.CONTENT_EDITING_ENDED,
58
+ visualSelectorId: state.selectedElementId,
59
+ },
60
+ "*"
61
+ );
62
+
63
+ state.currentEditingElement = null;
64
+ }
65
+
66
+ /**
67
+ * Report inline edit to parent
68
+ */
69
+ function reportInlineEdit(state: AgentState, element: HTMLElement): void {
70
+ const originalContent = element.dataset.originalTextContent;
71
+ const newContent = element.textContent;
72
+
73
+ const elementInfo = {
74
+ tagName: element.tagName,
75
+ classes: getElementClasses(element),
76
+ visualSelectorId: state.selectedElementId,
77
+ content: newContent,
78
+ dataSourceLocation: element.dataset.sourceLocation,
79
+ isDynamicContent: element.dataset.dynamicContent === "true",
80
+ linenumber: element.dataset.linenumber,
81
+ filename: element.dataset.filename,
82
+ position: getElementPosition(element.getBoundingClientRect()),
83
+ };
84
+
85
+ // Send inline edit message
86
+ window.parent.postMessage(
87
+ {
88
+ type: OutgoingMessageType.INLINE_EDIT,
89
+ elementInfo,
90
+ originalContent,
91
+ newContent,
92
+ },
93
+ "*"
94
+ );
95
+
96
+ // Update baseline for next edit
97
+ element.dataset.originalTextContent = newContent || "";
98
+ }
99
+
100
+ /**
101
+ * Debounced function to send inline edit messages
102
+ */
103
+ function debouncedSendInlineEditMessage(state: AgentState, element: HTMLElement): void {
104
+ // Clear any existing timeout
105
+ if (state.debouncedSendTimeout) {
106
+ clearTimeout(state.debouncedSendTimeout);
107
+ }
108
+
109
+ // Set new timeout
110
+ state.debouncedSendTimeout = setTimeout(() => {
111
+ reportInlineEdit(state, element);
112
+ }, INLINE_EDIT_DEBOUNCE_MS);
113
+ }
114
+
115
+ /**
116
+ * Callback for text input changes (combines updatePosition and reportInlineEdit)
117
+ */
118
+ function createTextInputChangeCallback(state: AgentState) {
119
+ return (element: HTMLElement) => {
120
+ repositionSelectedOverlays(state);
121
+ debouncedSendInlineEditMessage(state, element);
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Setup inline edit callback
127
+ */
128
+ export function setupInlineEditCallback(state: AgentState): void {
129
+ setInlineEditCallback(createTextInputChangeCallback(state));
130
+ }
@@ -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
+ if (elements.length === 0) return;
20
+
21
+ const element = elements[0];
22
+ const rect = element!.getBoundingClientRect();
23
+
24
+ window.parent.postMessage(
25
+ {
26
+ type: OutgoingMessageType.ELEMENT_POSITION_UPDATE,
27
+ position: getElementPosition(rect),
28
+ isInViewport: isElementInViewport(rect),
29
+ visualSelectorId: state.selectedElementId,
30
+ },
31
+ "*"
32
+ );
33
+ }
34
+
35
+ /**
36
+ * Unselect the current element
37
+ */
38
+ export function unselectElement(state: AgentState): void {
39
+ if (state.currentEditingElement) {
40
+ handleClearInlineEditingMode(state);
41
+ }
42
+ clearSelection(state);
43
+ }
44
+
45
+ /**
46
+ * Update element classes and reposition overlays
47
+ */
48
+ export function updateElementClassesAndReposition(
49
+ state: AgentState,
50
+ visualSelectorId: string,
51
+ classes: string
52
+ ): void {
53
+ const elements = findElementsById(visualSelectorId);
54
+ if (elements.length === 0) return;
55
+
56
+ updateElementClasses(elements, classes);
57
+
58
+ // Use a small delay to allow the browser to recalculate layout before repositioning
59
+ setTimeout(() => {
60
+ if (state.selectedElementId === visualSelectorId) {
61
+ repositionSelectedOverlays(state);
62
+ }
63
+
64
+ if (state.currentHighlightedElements.length > 0) {
65
+ const hoveredElement = state.currentHighlightedElements[0] as HTMLElement;
66
+ if (hoveredElement?.dataset?.visualSelectorId === visualSelectorId) {
67
+ repositionHoverOverlays(state);
68
+ }
69
+ }
70
+ }, REPOSITION_DELAY_MS);
71
+ }
72
+
73
+ /**
74
+ * Update element content by visual selector ID
75
+ */
76
+ export function updateElementContent(
77
+ state: AgentState,
78
+ visualSelectorId: string,
79
+ content: string
80
+ ): void {
81
+ const elements = findElementsById(visualSelectorId);
82
+
83
+ if (elements.length === 0) {
84
+ return;
85
+ }
86
+
87
+ elements.forEach((element) => {
88
+ (element as HTMLElement).innerText = content;
89
+ });
90
+
91
+ setTimeout(() => {
92
+ if (state.selectedElementId === visualSelectorId) {
93
+ repositionSelectedOverlays(state);
94
+ }
95
+ }, REPOSITION_DELAY_MS);
96
+ }
97
+
98
+ /**
99
+ * Handle scroll events to update popover position
100
+ */
101
+ export function handleScroll(state: AgentState): void {
102
+ sendElementPositionUpdate(state);
103
+ }
104
+
105
+ /**
106
+ * Handle window resize to reposition overlays
107
+ */
108
+ export function handleResize(state: AgentState): void {
109
+ repositionSelectedOverlays(state);
110
+ repositionHoverOverlays(state);
111
+ }
112
+
113
+ /**
114
+ * Handle messages from parent window
115
+ */
116
+ export function handleMessage(state: AgentState, event: MessageEvent): void {
117
+ const message = event.data;
118
+
119
+ switch (message.type as IncomingMessageType) {
120
+ case IncomingMessageType.TOGGLE_VISUAL_EDIT_MODE:
121
+ handleToggleVisualEditMode(state, message);
122
+ break;
123
+
124
+ case IncomingMessageType.UPDATE_CLASSES:
125
+ if (message.data && message.data.classes !== undefined) {
126
+ updateElementClassesAndReposition(
127
+ state,
128
+ message.data.visualSelectorId,
129
+ message.data.classes
130
+ );
131
+ } else {
132
+ console.warn(
133
+ "[VisualEditAgent] Invalid update-classes message:",
134
+ message
135
+ );
136
+ }
137
+ break;
138
+
139
+ case IncomingMessageType.UNSELECT_ELEMENT:
140
+ unselectElement(state);
141
+ break;
142
+
143
+ case IncomingMessageType.REFRESH_PAGE:
144
+ window.location.reload();
145
+ break;
146
+
147
+ case IncomingMessageType.UPDATE_CONTENT:
148
+ if (message.data && message.data.content !== undefined) {
149
+ updateElementContent(
150
+ state,
151
+ message.data.visualSelectorId,
152
+ message.data.content
153
+ );
154
+ } else {
155
+ console.warn(
156
+ "[VisualEditAgent] Invalid update-content message:",
157
+ message
158
+ );
159
+ }
160
+ break;
161
+
162
+ case IncomingMessageType.TOGGLE_INLINE_EDIT_MODE:
163
+ handleToggleInlineEditMode(state, message);
164
+ break;
165
+
166
+ case IncomingMessageType.REQUEST_ELEMENT_POSITION:
167
+ sendElementPositionUpdate(state);
168
+ break;
169
+
170
+ case IncomingMessageType.POPOVER_DRAG_STATE:
171
+ if (message.data && message.data.isDragging !== undefined) {
172
+ state.isPopoverDragging = message.data.isDragging;
173
+ if (message.data.isDragging) {
174
+ clearHoverOverlays(state);
175
+ }
176
+ }
177
+ break;
178
+
179
+ case IncomingMessageType.DROPDOWN_STATE:
180
+ if (message.data && message.data.isOpen !== undefined) {
181
+ state.isDropdownOpen = message.data.isOpen;
182
+ if (message.data.isOpen) {
183
+ clearHoverOverlays(state);
184
+ }
185
+ }
186
+ break;
187
+
188
+ default:
189
+ break;
190
+ }
191
+ }
@@ -0,0 +1,51 @@
1
+ import type { AgentState } from "../../state/agent-state.js";
2
+ import type { ToggleInlineEditModeMessage } from "./types.js";
3
+ import { findElementsById } from "../../../utils.js";
4
+ import { shouldEnterInlineEditingMode } from "../../capabilities/inline-editing/index.js";
5
+ import { handleElementSelection } from "../click-handlers.js";
6
+ import { handleEnterInlineEditingMode, handleClearInlineEditingMode } from "../inline-edit-handlers.js";
7
+
8
+ /**
9
+ * Handle toggle-inline-edit-mode message (parent-initiated)
10
+ */
11
+ export function handleToggleInlineEditMode(
12
+ state: AgentState,
13
+ message: ToggleInlineEditModeMessage
14
+ ): void {
15
+ // Check if inline edit experiment is enabled
16
+ if (!state.isInlineEditExperimentEnabled) {
17
+ console.log('[VisualEditAgent] toggle-inline-edit-mode ignored - experiment flag not enabled');
18
+ return;
19
+ }
20
+
21
+ console.log('[VisualEditAgent] Processing toggle-inline-edit-mode message');
22
+
23
+ // Parent-initiated inline editing mode toggle
24
+ if (!message.data || !message.data.dataSourceLocation) {
25
+ console.warn('[VisualEditAgent] Invalid toggle-inline-edit-mode message - missing dataSourceLocation');
26
+ return;
27
+ }
28
+
29
+ const elements = findElementsById(message.data.dataSourceLocation);
30
+ if (elements.length === 0 || !(elements[0] instanceof HTMLElement)) {
31
+ return;
32
+ }
33
+
34
+ const element = elements[0];
35
+
36
+ if (message.data.inlineEditingMode) {
37
+ // Enable inline editing (only for non-dynamic text elements)
38
+ if (shouldEnterInlineEditingMode(element)) {
39
+ // Select the element first if not already selected
40
+ if (state.selectedElementId !== message.data.dataSourceLocation) {
41
+ handleElementSelection(state, element, message.data.dataSourceLocation);
42
+ }
43
+ handleEnterInlineEditingMode(state, element);
44
+ }
45
+ } else {
46
+ // Disable inline editing
47
+ if (state.currentEditingElement === element) {
48
+ handleClearInlineEditingMode(state);
49
+ }
50
+ }
51
+ }