@base44-preview/vite-plugin 0.2.27-pr.41.77be9cb → 0.2.27-pr.44.489d834

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 (98) hide show
  1. package/dist/capabilities/inline-edit/controller.d.ts.map +1 -1
  2. package/dist/capabilities/inline-edit/controller.js +9 -3
  3. package/dist/capabilities/inline-edit/controller.js.map +1 -1
  4. package/dist/capabilities/inline-edit/dom-utils.d.ts +1 -0
  5. package/dist/capabilities/inline-edit/dom-utils.d.ts.map +1 -1
  6. package/dist/capabilities/inline-edit/dom-utils.js +17 -7
  7. package/dist/capabilities/inline-edit/dom-utils.js.map +1 -1
  8. package/dist/injections/visual-edit-agent.d.ts +1 -1
  9. package/dist/injections/visual-edit-agent.d.ts.map +1 -1
  10. package/dist/injections/visual-edit-agent.js +576 -1
  11. package/dist/injections/visual-edit-agent.js.map +1 -1
  12. package/dist/statics/index.mjs +2 -2
  13. package/dist/statics/index.mjs.map +1 -1
  14. package/package.json +1 -1
  15. package/src/capabilities/inline-edit/controller.ts +35 -29
  16. package/src/capabilities/inline-edit/dom-utils.ts +14 -4
  17. package/src/injections/visual-edit-agent.ts +714 -1
  18. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +0 -25
  19. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +0 -1
  20. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +0 -95
  21. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +0 -1
  22. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +0 -4
  23. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +0 -1
  24. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +0 -4
  25. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +0 -1
  26. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +0 -9
  27. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +0 -1
  28. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +0 -26
  29. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +0 -1
  30. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +0 -17
  31. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +0 -1
  32. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +0 -76
  33. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +0 -1
  34. package/dist/injections/visual-edit-agent/constants.d.ts +0 -10
  35. package/dist/injections/visual-edit-agent/constants.d.ts.map +0 -1
  36. package/dist/injections/visual-edit-agent/constants.js +0 -10
  37. package/dist/injections/visual-edit-agent/constants.js.map +0 -1
  38. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +0 -10
  39. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +0 -1
  40. package/dist/injections/visual-edit-agent/handlers/click-handlers.js +0 -117
  41. package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +0 -1
  42. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +0 -14
  43. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +0 -1
  44. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +0 -64
  45. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +0 -1
  46. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +0 -14
  47. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +0 -1
  48. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +0 -114
  49. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +0 -1
  50. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +0 -26
  51. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +0 -1
  52. package/dist/injections/visual-edit-agent/handlers/message-handlers.js +0 -148
  53. package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +0 -1
  54. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +0 -7
  55. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +0 -1
  56. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +0 -54
  57. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +0 -1
  58. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +0 -11
  59. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +0 -1
  60. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +0 -32
  61. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +0 -1
  62. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +0 -105
  63. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +0 -1
  64. package/dist/injections/visual-edit-agent/handlers/messages/types.js +0 -28
  65. package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +0 -1
  66. package/dist/injections/visual-edit-agent/index.d.ts +0 -6
  67. package/dist/injections/visual-edit-agent/index.d.ts.map +0 -1
  68. package/dist/injections/visual-edit-agent/index.js +0 -109
  69. package/dist/injections/visual-edit-agent/index.js.map +0 -1
  70. package/dist/injections/visual-edit-agent/state/agent-state.d.ts +0 -17
  71. package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +0 -1
  72. package/dist/injections/visual-edit-agent/state/agent-state.js +0 -18
  73. package/dist/injections/visual-edit-agent/state/agent-state.js.map +0 -1
  74. package/dist/injections/visual-edit-agent/ui/overlay.d.ts +0 -26
  75. package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +0 -1
  76. package/dist/injections/visual-edit-agent/ui/overlay.js +0 -104
  77. package/dist/injections/visual-edit-agent/ui/overlay.js.map +0 -1
  78. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +0 -14
  79. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +0 -1
  80. package/dist/injections/visual-edit-agent/utils/dom-utils.js +0 -34
  81. package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +0 -1
  82. package/src/injections/visual-edit-agent/README.md +0 -222
  83. package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +0 -120
  84. package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +0 -10
  85. package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +0 -26
  86. package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +0 -87
  87. package/src/injections/visual-edit-agent/constants.ts +0 -9
  88. package/src/injections/visual-edit-agent/handlers/click-handlers.ts +0 -146
  89. package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +0 -78
  90. package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +0 -146
  91. package/src/injections/visual-edit-agent/handlers/message-handlers.ts +0 -201
  92. package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +0 -65
  93. package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +0 -40
  94. package/src/injections/visual-edit-agent/handlers/messages/types.ts +0 -134
  95. package/src/injections/visual-edit-agent/index.ts +0 -121
  96. package/src/injections/visual-edit-agent/state/agent-state.ts +0 -31
  97. package/src/injections/visual-edit-agent/ui/overlay.ts +0 -126
  98. package/src/injections/visual-edit-agent/utils/dom-utils.ts +0 -39
@@ -1,120 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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, isStaticArrayTextElement, selectText } from "./validation.js";
@@ -1,26 +0,0 @@
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
- }
@@ -1,87 +0,0 @@
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 a static array text element.
14
- * These elements are "dynamic" (they reference item.field) but their source
15
- * is a compile-time static array, so they can be safely edited inline.
16
- */
17
- export function isStaticArrayTextElement(element: HTMLElement): boolean {
18
- return !!element.dataset.arrField;
19
- }
20
-
21
- const ALLOWED_INLINE_EDIT_TAGS = [
22
- "div",
23
- "p",
24
- "h1",
25
- "h2",
26
- "h3",
27
- "h4",
28
- "h5",
29
- "h6",
30
- "span",
31
- "li",
32
- "td",
33
- "a",
34
- "button",
35
- "label",
36
- ];
37
-
38
- /**
39
- * Structural checks shared by both regular and static-array inline editing:
40
- * allowed tag, non-empty text, no media children, leaf node.
41
- */
42
- function passesStructuralChecks(element: HTMLElement): boolean {
43
- if (!ALLOWED_INLINE_EDIT_TAGS.includes(element.tagName.toLowerCase())) {
44
- return false;
45
- }
46
-
47
- const textContent = element.textContent?.trim() || "";
48
- if (textContent.length === 0) {
49
- return false;
50
- }
51
-
52
- if (element.querySelector("img, video, canvas, svg") !== null) {
53
- return false;
54
- }
55
-
56
- if (element.children.length > 0) {
57
- return false;
58
- }
59
-
60
- return true;
61
- }
62
-
63
- /**
64
- * Check if an element is an editable text element
65
- * Based on the eligibility rules from inlineEdit.md (non-dynamic only),
66
- * with an exception for static array elements.
67
- */
68
- export function isEditableTextElement(element: Element): boolean {
69
- if (!(element instanceof HTMLElement)) {
70
- return false;
71
- }
72
-
73
- if (!passesStructuralChecks(element)) {
74
- return false;
75
- }
76
-
77
- // Static array elements are editable even though they are technically "dynamic"
78
- if (isStaticArrayTextElement(element)) {
79
- return true;
80
- }
81
-
82
- if (element.dataset.dynamicContent === "true") {
83
- return false;
84
- }
85
-
86
- return true;
87
- }
@@ -1,9 +0,0 @@
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;
@@ -1,146 +0,0 @@
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
-
50
- // Resolve static-array context from vite-plugin attributes (data-arr-*)
51
- const arrEl = htmlElement.closest("[data-arr-variable-name]") as HTMLElement | null;
52
- const staticArrayName = arrEl?.dataset?.arrVariableName || null;
53
- const rawIdx = arrEl?.dataset?.arrIndex;
54
- const staticArrayIndex = rawIdx != null ? parseInt(rawIdx, 10) : null;
55
- const staticArrayField = htmlElement.dataset?.arrField || null;
56
-
57
- const elementData = {
58
- type: OutgoingMessageType.ELEMENT_SELECTED,
59
- tagName: element.tagName,
60
- classes: getElementClasses(element),
61
- visualSelectorId: visualSelectorId,
62
- content: htmlElement.innerText,
63
- dataSourceLocation: htmlElement.dataset.sourceLocation,
64
- isDynamicContent: htmlElement.dataset.dynamicContent === "true",
65
- linenumber: htmlElement.dataset.linenumber,
66
- filename: htmlElement.dataset.filename,
67
- position: getElementPosition(element.getBoundingClientRect()),
68
- staticArrayName,
69
- staticArrayIndex,
70
- staticArrayField,
71
- };
72
- window.parent.postMessage(elementData, "*");
73
- }
74
-
75
- /**
76
- * Handle element click
77
- */
78
- export function handleElementClick(state: AgentState, e: MouseEvent): void {
79
- if (!state.isVisualEditMode) return;
80
-
81
- const target = e.target as Element;
82
-
83
- // Bail out early if clicking on a contentEditable element (allow normal editing)
84
- if (state.isInlineEditExperimentEnabled && target instanceof HTMLElement && target.contentEditable === "true") {
85
- return;
86
- }
87
-
88
- // If currently editing, clicking outside should exit editing mode
89
- if (state.currentEditingElement) {
90
- e.preventDefault();
91
- e.stopPropagation();
92
- e.stopImmediatePropagation();
93
- handleClearInlineEditingMode(state);
94
- return;
95
- }
96
-
97
- // Close dropdowns when clicking anywhere in iframe if a dropdown is open
98
- if (state.isDropdownOpen) {
99
- e.preventDefault();
100
- e.stopPropagation();
101
- e.stopImmediatePropagation();
102
-
103
- window.parent.postMessage({ type: OutgoingMessageType.CLOSE_DROPDOWNS }, "*");
104
- return;
105
- }
106
-
107
- // Prevent clicking on SVG path elements
108
- if (target.tagName.toLowerCase() === "path") {
109
- return;
110
- }
111
-
112
- // Prevent default behavior immediately when in visual edit mode
113
- e.preventDefault();
114
- e.stopPropagation();
115
- e.stopImmediatePropagation();
116
-
117
- // Support both data-source-location and data-visual-selector-id
118
- const element = target.closest(
119
- "[data-source-location], [data-visual-selector-id]"
120
- );
121
- if (!element) {
122
- return;
123
- }
124
-
125
- const htmlElement = element as HTMLElement;
126
- const visualSelectorId =
127
- htmlElement.dataset.sourceLocation ||
128
- htmlElement.dataset.visualSelectorId;
129
-
130
- // Check if this element is already selected (second click scenario)
131
- const isAlreadySelected =
132
- state.selectedElementId === visualSelectorId &&
133
- htmlElement.dataset.selected === "true";
134
-
135
- if (isAlreadySelected) {
136
- // Second click on already-selected element: check if it should enter inline editing
137
- // Only if the experiment is enabled
138
- if (state.isInlineEditExperimentEnabled && shouldEnterInlineEditingMode(htmlElement)) {
139
- handleEnterInlineEditingMode(state, htmlElement);
140
- return;
141
- }
142
- }
143
-
144
- // First click: select the element
145
- handleElementSelection(state, element, visualSelectorId || null);
146
- }
@@ -1,78 +0,0 @@
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
- }
@@ -1,146 +0,0 @@
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
- isStaticArrayTextElement,
9
- } from "../capabilities/inline-editing/index.js";
10
- import { INLINE_EDIT_DEBOUNCE_MS } from "../constants.js";
11
- import { getElementPosition, getElementClasses } from "../utils/dom-utils.js";
12
-
13
- /**
14
- * Enter inline editing mode
15
- */
16
- export function handleEnterInlineEditingMode(state: AgentState, element: HTMLElement): void {
17
- state.currentEditingElement = element;
18
-
19
- // Hide overlays during editing
20
- state.selectedOverlays.forEach((overlay) => {
21
- overlay.style.display = "none";
22
- });
23
-
24
- // Enter inline editing mode (from capabilities/inline-editing)
25
- enterInlineEditingMode(element);
26
-
27
- // Notify parent
28
- window.parent.postMessage(
29
- {
30
- type: OutgoingMessageType.CONTENT_EDITING_STARTED,
31
- visualSelectorId: state.selectedElementId,
32
- },
33
- "*"
34
- );
35
- }
36
-
37
- /**
38
- * Clear inline editing mode
39
- */
40
- export function handleClearInlineEditingMode(state: AgentState): void {
41
- if (!state.currentEditingElement) return;
42
-
43
- // Cancel any pending debounced edit — originalTextContent will be deleted below
44
- if (state.debouncedSendTimeout) {
45
- clearTimeout(state.debouncedSendTimeout);
46
- state.debouncedSendTimeout = null;
47
- }
48
-
49
- const element = state.currentEditingElement;
50
-
51
- // Clear inline editing mode (from capabilities/inline-editing)
52
- clearInlineEditingMode(element);
53
-
54
- // Show overlays again
55
- state.selectedOverlays.forEach((overlay) => {
56
- overlay.style.display = "";
57
- });
58
-
59
- repositionSelectedOverlays(state);
60
-
61
- // Notify parent that editing ended
62
- window.parent.postMessage(
63
- {
64
- type: OutgoingMessageType.CONTENT_EDITING_ENDED,
65
- visualSelectorId: state.selectedElementId,
66
- },
67
- "*"
68
- );
69
-
70
- state.currentEditingElement = null;
71
- }
72
-
73
- /**
74
- * Report inline edit to parent
75
- */
76
- function reportInlineEdit(state: AgentState, element: HTMLElement): void {
77
- const originalContent = element.dataset.originalTextContent;
78
- const newContent = element.textContent;
79
-
80
- const elementInfo = {
81
- tagName: element.tagName,
82
- classes: getElementClasses(element),
83
- visualSelectorId: state.selectedElementId,
84
- content: newContent,
85
- dataSourceLocation: element.dataset.sourceLocation,
86
- isDynamicContent: element.dataset.dynamicContent === "true",
87
- linenumber: element.dataset.linenumber,
88
- filename: element.dataset.filename,
89
- position: getElementPosition(element.getBoundingClientRect()),
90
- };
91
-
92
- const message: Record<string, unknown> = {
93
- type: OutgoingMessageType.INLINE_EDIT,
94
- elementInfo,
95
- originalContent,
96
- newContent,
97
- };
98
-
99
- if (isStaticArrayTextElement(element)) {
100
- message.arrIndex = element.dataset.arrIndex;
101
- message.arrVariableName = element.dataset.arrVariableName;
102
- message.arrField = element.dataset.arrField;
103
- }
104
-
105
- window.parent.postMessage(message, "*");
106
-
107
- // Update baseline for next edit
108
- element.dataset.originalTextContent = newContent || "";
109
- }
110
-
111
- /**
112
- * Debounced function to send inline edit messages
113
- *
114
- * Intentionally overwrites the previous timeout on each keystroke — this is the
115
- * correct debounce behavior. We only send ONE message 500ms after the user stops
116
- * typing, containing the final text. Intermediate keystrokes are not sent to avoid
117
- * flooding the parent with dozens of messages per second.
118
- */
119
- function debouncedSendInlineEditMessage(state: AgentState, element: HTMLElement): void {
120
- // Clear any existing timeout
121
- if (state.debouncedSendTimeout) {
122
- clearTimeout(state.debouncedSendTimeout);
123
- }
124
-
125
- // Set new timeout
126
- state.debouncedSendTimeout = setTimeout(() => {
127
- reportInlineEdit(state, element);
128
- }, INLINE_EDIT_DEBOUNCE_MS);
129
- }
130
-
131
- /**
132
- * Callback for text input changes (combines updatePosition and reportInlineEdit)
133
- */
134
- function createTextInputChangeCallback(state: AgentState) {
135
- return (element: HTMLElement) => {
136
- repositionSelectedOverlays(state);
137
- debouncedSendInlineEditMessage(state, element);
138
- };
139
- }
140
-
141
- /**
142
- * Setup inline edit callback
143
- */
144
- export function setupInlineEditCallback(state: AgentState): void {
145
- setInlineEditCallback(createTextInputChangeCallback(state));
146
- }