@lego-build/plugins 0.0.3 → 0.0.6
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/auto.js +3 -10
- package/dist/babel-plugin.d.ts +18 -0
- package/dist/babel-plugin.js +43 -0
- package/dist/{chunk-MZJDRENL.js → chunk-2R3NUXAB.js} +13 -9
- package/dist/chunk-3TRIUWCT.js +539 -0
- package/dist/chunk-42QHGI4F.js +512 -0
- package/dist/chunk-4EX2R46A.js +528 -0
- package/dist/{chunk-RM4HZDF3.js → chunk-6EMRLRSE.js} +12 -5
- package/dist/chunk-6MOTW5WZ.js +505 -0
- package/dist/chunk-J6RRTMEB.js +553 -0
- package/dist/chunk-NYSOJK4V.js +436 -0
- package/dist/chunk-ONSLHF7O.js +553 -0
- package/dist/chunk-QMPWAJBL.js +539 -0
- package/dist/chunk-RG2IIZUF.js +560 -0
- package/dist/chunk-SQ3BWA54.js +307 -0
- package/dist/chunk-URUG7I3S.js +539 -0
- package/dist/chunk-V3KCJYHC.js +468 -0
- package/dist/chunk-XZZFN45X.js +539 -0
- package/dist/index.d.ts +4 -32
- package/dist/index.js +8 -830
- package/dist/react.d.ts +7 -0
- package/dist/react.js +18 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +103 -0
- package/package.json +28 -31
- package/dist/webpack-loader.d.ts +0 -25
- package/dist/webpack-loader.js +0 -198
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function sendToParent(type, payload) {
|
|
3
|
+
window.parent.postMessage({ type, payload }, "*");
|
|
4
|
+
}
|
|
5
|
+
function setupIframeBridge() {
|
|
6
|
+
const pushState = window.history.pushState.bind(window.history);
|
|
7
|
+
const originalPushState = (...args) => {
|
|
8
|
+
pushState(...args);
|
|
9
|
+
sendToParent("IFRAME_URL_CHANGED", window.location.href);
|
|
10
|
+
};
|
|
11
|
+
window.history.pushState = originalPushState;
|
|
12
|
+
const replaceState = window.history.replaceState.bind(window.history);
|
|
13
|
+
const originalReplaceState = (...args) => {
|
|
14
|
+
replaceState(...args);
|
|
15
|
+
sendToParent("IFRAME_URL_CHANGED", window.location.href);
|
|
16
|
+
};
|
|
17
|
+
window.history.replaceState = originalReplaceState;
|
|
18
|
+
window.addEventListener("popstate", () => {
|
|
19
|
+
sendToParent("IFRAME_URL_CHANGED", window.location.href);
|
|
20
|
+
});
|
|
21
|
+
window.addEventListener("message", (e) => {
|
|
22
|
+
const msg = e.data;
|
|
23
|
+
if (!msg?.type) return;
|
|
24
|
+
switch (msg.type) {
|
|
25
|
+
case "NAVIGATE_BACK":
|
|
26
|
+
window.history.back();
|
|
27
|
+
break;
|
|
28
|
+
case "NAVIGATE_FORWARD":
|
|
29
|
+
window.history.forward();
|
|
30
|
+
break;
|
|
31
|
+
case "NAVIGATE_URL":
|
|
32
|
+
if (msg.payload) {
|
|
33
|
+
window.history.pushState({}, "", msg.payload);
|
|
34
|
+
sendToParent("IFRAME_URL_CHANGED", window.location.href);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case "REFRESH":
|
|
38
|
+
window.location.reload();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function createElementSelectorState() {
|
|
44
|
+
return {
|
|
45
|
+
isActive: false,
|
|
46
|
+
isEditing: false,
|
|
47
|
+
hoveredElement: null,
|
|
48
|
+
selectedElement: null,
|
|
49
|
+
overlay: null,
|
|
50
|
+
tooltip: null,
|
|
51
|
+
inlineEditor: null,
|
|
52
|
+
depth: 0,
|
|
53
|
+
originalText: ""
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createOverlay() {
|
|
57
|
+
const overlay = document.createElement("div");
|
|
58
|
+
overlay.id = "lego-element-selector-overlay";
|
|
59
|
+
overlay.style.cssText = `
|
|
60
|
+
position: fixed;
|
|
61
|
+
pointer-events: none;
|
|
62
|
+
z-index: 2147483646;
|
|
63
|
+
background: rgba(59, 130, 246, 0.1);
|
|
64
|
+
border: 2px solid #3b82f6;
|
|
65
|
+
border-radius: 4px;
|
|
66
|
+
transition: all 0.1s ease-out;
|
|
67
|
+
`;
|
|
68
|
+
document.body.appendChild(overlay);
|
|
69
|
+
return overlay;
|
|
70
|
+
}
|
|
71
|
+
function createTooltip() {
|
|
72
|
+
const tooltip = document.createElement("div");
|
|
73
|
+
tooltip.id = "lego-element-selector-tooltip";
|
|
74
|
+
tooltip.style.cssText = `
|
|
75
|
+
position: fixed;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
z-index: 2147483647;
|
|
78
|
+
background: #3b82f6;
|
|
79
|
+
color: white;
|
|
80
|
+
padding: 4px 8px;
|
|
81
|
+
border-radius: 4px;
|
|
82
|
+
font-family: ui-monospace, monospace;
|
|
83
|
+
font-size: 12px;
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
|
86
|
+
transition: all 0.1s ease-out;
|
|
87
|
+
`;
|
|
88
|
+
document.body.appendChild(tooltip);
|
|
89
|
+
return tooltip;
|
|
90
|
+
}
|
|
91
|
+
function createInlineEditor(state, element, onSave, onCancel) {
|
|
92
|
+
const rect = element.getBoundingClientRect();
|
|
93
|
+
const elementText = getElementTextContent(element);
|
|
94
|
+
const editor = document.createElement("div");
|
|
95
|
+
editor.id = "lego-inline-editor";
|
|
96
|
+
editor.style.cssText = `
|
|
97
|
+
position: fixed;
|
|
98
|
+
top: ${rect.top}px;
|
|
99
|
+
left: ${rect.left}px;
|
|
100
|
+
width: ${Math.max(rect.width, 200)}px;
|
|
101
|
+
z-index: 2147483647;
|
|
102
|
+
background: white;
|
|
103
|
+
border: 2px solid #3b82f6;
|
|
104
|
+
border-radius: 8px;
|
|
105
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
106
|
+
padding: 8px;
|
|
107
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
108
|
+
`;
|
|
109
|
+
const header = document.createElement("div");
|
|
110
|
+
header.style.cssText = `
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
justify-content: space-between;
|
|
114
|
+
margin-bottom: 8px;
|
|
115
|
+
padding-bottom: 8px;
|
|
116
|
+
border-bottom: 1px solid #e5e7eb;
|
|
117
|
+
`;
|
|
118
|
+
header.innerHTML = `
|
|
119
|
+
<span style="font-size: 11px; font-weight: 500; color: #6b7280;">
|
|
120
|
+
\u270F\uFE0F Edit Text
|
|
121
|
+
</span>
|
|
122
|
+
<span style="font-size: 10px; color: #9ca3af;">
|
|
123
|
+
Ctrl+Enter to save \u2022 Esc to cancel
|
|
124
|
+
</span>
|
|
125
|
+
`;
|
|
126
|
+
const input = document.createElement("textarea");
|
|
127
|
+
input.id = "lego-inline-editor-input";
|
|
128
|
+
input.value = elementText;
|
|
129
|
+
input.style.cssText = `
|
|
130
|
+
width: 100%;
|
|
131
|
+
min-height: 60px;
|
|
132
|
+
padding: 8px;
|
|
133
|
+
border: 1px solid #e5e7eb;
|
|
134
|
+
border-radius: 4px;
|
|
135
|
+
font-size: 14px;
|
|
136
|
+
font-family: inherit;
|
|
137
|
+
resize: vertical;
|
|
138
|
+
outline: none;
|
|
139
|
+
box-sizing: border-box;
|
|
140
|
+
`;
|
|
141
|
+
input.placeholder = "Enter text...";
|
|
142
|
+
const buttons = document.createElement("div");
|
|
143
|
+
buttons.style.cssText = `
|
|
144
|
+
display: flex;
|
|
145
|
+
gap: 8px;
|
|
146
|
+
margin-top: 8px;
|
|
147
|
+
justify-content: flex-end;
|
|
148
|
+
`;
|
|
149
|
+
const cancelBtn = document.createElement("button");
|
|
150
|
+
cancelBtn.textContent = "Cancel";
|
|
151
|
+
cancelBtn.style.cssText = `
|
|
152
|
+
padding: 6px 12px;
|
|
153
|
+
border: 1px solid #e5e7eb;
|
|
154
|
+
border-radius: 4px;
|
|
155
|
+
background: white;
|
|
156
|
+
font-size: 12px;
|
|
157
|
+
cursor: pointer;
|
|
158
|
+
transition: all 0.15s;
|
|
159
|
+
`;
|
|
160
|
+
cancelBtn.onmouseenter = () => cancelBtn.style.background = "#f3f4f6";
|
|
161
|
+
cancelBtn.onmouseleave = () => cancelBtn.style.background = "white";
|
|
162
|
+
cancelBtn.onclick = (e) => {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
onCancel();
|
|
166
|
+
};
|
|
167
|
+
const saveBtn = document.createElement("button");
|
|
168
|
+
saveBtn.textContent = "Save";
|
|
169
|
+
saveBtn.style.cssText = `
|
|
170
|
+
padding: 6px 12px;
|
|
171
|
+
border: none;
|
|
172
|
+
border-radius: 4px;
|
|
173
|
+
background: #3b82f6;
|
|
174
|
+
color: white;
|
|
175
|
+
font-size: 12px;
|
|
176
|
+
font-weight: 500;
|
|
177
|
+
cursor: pointer;
|
|
178
|
+
transition: all 0.15s;
|
|
179
|
+
`;
|
|
180
|
+
saveBtn.onmouseenter = () => saveBtn.style.background = "#2563eb";
|
|
181
|
+
saveBtn.onmouseleave = () => saveBtn.style.background = "#3b82f6";
|
|
182
|
+
saveBtn.onclick = (e) => {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
onSave();
|
|
186
|
+
};
|
|
187
|
+
editor.appendChild(header);
|
|
188
|
+
editor.appendChild(input);
|
|
189
|
+
buttons.appendChild(cancelBtn);
|
|
190
|
+
buttons.appendChild(saveBtn);
|
|
191
|
+
editor.appendChild(buttons);
|
|
192
|
+
document.body.appendChild(editor);
|
|
193
|
+
setTimeout(() => {
|
|
194
|
+
input.focus();
|
|
195
|
+
input.select();
|
|
196
|
+
}, 0);
|
|
197
|
+
input.addEventListener("keydown", (e) => {
|
|
198
|
+
if (e.key === "Escape") {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
e.stopPropagation();
|
|
201
|
+
onCancel();
|
|
202
|
+
} else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
e.stopPropagation();
|
|
205
|
+
onSave();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
input.addEventListener("keyup", (e) => {
|
|
209
|
+
e.stopPropagation();
|
|
210
|
+
});
|
|
211
|
+
input.addEventListener("keypress", (e) => {
|
|
212
|
+
e.stopPropagation();
|
|
213
|
+
});
|
|
214
|
+
return editor;
|
|
215
|
+
}
|
|
216
|
+
function getElementTextContent(element) {
|
|
217
|
+
let text = "";
|
|
218
|
+
for (const node of element.childNodes) {
|
|
219
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
220
|
+
text += node.textContent?.trim() || "";
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (!text && element.children.length === 0) {
|
|
224
|
+
text = element.textContent?.trim() || "";
|
|
225
|
+
}
|
|
226
|
+
return text;
|
|
227
|
+
}
|
|
228
|
+
function getElementDepth(element) {
|
|
229
|
+
let depth = 0;
|
|
230
|
+
let current = element;
|
|
231
|
+
while (current && current !== document.body) {
|
|
232
|
+
depth++;
|
|
233
|
+
current = current.parentElement;
|
|
234
|
+
}
|
|
235
|
+
return depth;
|
|
236
|
+
}
|
|
237
|
+
function updateOverlayPosition(state) {
|
|
238
|
+
if (!state.hoveredElement || !state.overlay || !state.tooltip) return;
|
|
239
|
+
const rect = state.hoveredElement.getBoundingClientRect();
|
|
240
|
+
const viewportWidth = window.innerWidth;
|
|
241
|
+
state.overlay.style.top = `${rect.top}px`;
|
|
242
|
+
state.overlay.style.left = `${rect.left}px`;
|
|
243
|
+
state.overlay.style.width = `${rect.width}px`;
|
|
244
|
+
state.overlay.style.height = `${rect.height}px`;
|
|
245
|
+
let tooltipTop = rect.top - 32;
|
|
246
|
+
let tooltipLeft = rect.left;
|
|
247
|
+
if (tooltipTop < 8) {
|
|
248
|
+
tooltipTop = rect.bottom + 8;
|
|
249
|
+
}
|
|
250
|
+
const estimatedTooltipWidth = state.tooltip.offsetWidth || 150;
|
|
251
|
+
if (tooltipLeft + estimatedTooltipWidth > viewportWidth - 8) {
|
|
252
|
+
tooltipLeft = viewportWidth - estimatedTooltipWidth - 8;
|
|
253
|
+
}
|
|
254
|
+
if (tooltipLeft < 8) {
|
|
255
|
+
tooltipLeft = 8;
|
|
256
|
+
}
|
|
257
|
+
state.tooltip.style.top = `${tooltipTop}px`;
|
|
258
|
+
state.tooltip.style.left = `${tooltipLeft}px`;
|
|
259
|
+
}
|
|
260
|
+
function getElementInfo(element) {
|
|
261
|
+
const filePath = element.getAttribute("data-locator-path") || "";
|
|
262
|
+
const line = element.getAttribute("data-locator-line");
|
|
263
|
+
const depth = getElementDepth(element);
|
|
264
|
+
const id = element.id ? `#${element.id}` : "";
|
|
265
|
+
const classes = element.className && typeof element.className === "string" ? element.className.split(" ").filter((c) => c).map((c) => `.${c}`).join("") : "";
|
|
266
|
+
return {
|
|
267
|
+
tagName: element.tagName.toLowerCase(),
|
|
268
|
+
selector: element.tagName.toLowerCase() + id + classes.slice(0, 50),
|
|
269
|
+
filePath,
|
|
270
|
+
line: line ? parseInt(line) : void 0,
|
|
271
|
+
depth,
|
|
272
|
+
rect: element.getBoundingClientRect()
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function highlightElement(state, element) {
|
|
276
|
+
state.hoveredElement = element;
|
|
277
|
+
if (!state.overlay) {
|
|
278
|
+
state.overlay = createOverlay();
|
|
279
|
+
}
|
|
280
|
+
if (!state.tooltip) {
|
|
281
|
+
state.tooltip = createTooltip();
|
|
282
|
+
}
|
|
283
|
+
state.overlay.style.display = "block";
|
|
284
|
+
state.tooltip.style.display = "block";
|
|
285
|
+
const info = getElementInfo(element);
|
|
286
|
+
state.depth = info.depth;
|
|
287
|
+
state.tooltip.innerHTML = `
|
|
288
|
+
<span style="opacity: 0.8">${info.selector}</span>
|
|
289
|
+
${info.filePath ? `<span style="margin-left: 8px; opacity: 0.6">\u{1F4C4} ${info.filePath.split("/").pop()}</span>` : ""}
|
|
290
|
+
`;
|
|
291
|
+
updateOverlayPosition(state);
|
|
292
|
+
sendToParent("HOVER_ELEMENT", {
|
|
293
|
+
tagName: info.tagName,
|
|
294
|
+
rect: info.rect,
|
|
295
|
+
filePath: info.filePath || void 0,
|
|
296
|
+
line: info.line,
|
|
297
|
+
depth: info.depth
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function navigateDOM(state, direction) {
|
|
301
|
+
if (!state.hoveredElement) return;
|
|
302
|
+
let target = null;
|
|
303
|
+
switch (direction) {
|
|
304
|
+
case "parent":
|
|
305
|
+
target = state.hoveredElement.parentElement;
|
|
306
|
+
if (target && target === document.body) target = null;
|
|
307
|
+
break;
|
|
308
|
+
case "child":
|
|
309
|
+
target = state.hoveredElement.firstElementChild;
|
|
310
|
+
break;
|
|
311
|
+
case "next":
|
|
312
|
+
target = state.hoveredElement.nextElementSibling;
|
|
313
|
+
break;
|
|
314
|
+
case "prev":
|
|
315
|
+
target = state.hoveredElement.previousElementSibling;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (target && target !== document.documentElement && target !== document.body) {
|
|
319
|
+
highlightElement(state, target);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function setupElementSelector() {
|
|
323
|
+
const state = createElementSelectorState();
|
|
324
|
+
function saveInlineEdit() {
|
|
325
|
+
if (!state.inlineEditor || !state.selectedElement) return;
|
|
326
|
+
const input = state.inlineEditor.querySelector(
|
|
327
|
+
"#lego-inline-editor-input"
|
|
328
|
+
);
|
|
329
|
+
const newText = input?.value || "";
|
|
330
|
+
const info = getElementInfo(state.selectedElement);
|
|
331
|
+
if (newText !== state.originalText && info.filePath) {
|
|
332
|
+
sendToParent("SAVE_INLINE_EDIT", {
|
|
333
|
+
filePath: info.filePath,
|
|
334
|
+
originalContent: state.originalText,
|
|
335
|
+
newContent: newText,
|
|
336
|
+
line: info.line
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
exitEditMode();
|
|
340
|
+
}
|
|
341
|
+
function cancelInlineEdit() {
|
|
342
|
+
sendToParent("CANCEL_INLINE_EDIT");
|
|
343
|
+
exitEditMode();
|
|
344
|
+
}
|
|
345
|
+
function exitEditMode() {
|
|
346
|
+
state.isEditing = false;
|
|
347
|
+
if (state.inlineEditor) {
|
|
348
|
+
state.inlineEditor.remove();
|
|
349
|
+
state.inlineEditor = null;
|
|
350
|
+
}
|
|
351
|
+
if (state.isActive && state.hoveredElement) {
|
|
352
|
+
if (state.overlay) state.overlay.style.display = "block";
|
|
353
|
+
if (state.tooltip) state.tooltip.style.display = "block";
|
|
354
|
+
}
|
|
355
|
+
state.selectedElement = null;
|
|
356
|
+
state.originalText = "";
|
|
357
|
+
}
|
|
358
|
+
function enterEditMode() {
|
|
359
|
+
if (!state.selectedElement) return;
|
|
360
|
+
state.isEditing = true;
|
|
361
|
+
if (state.overlay) state.overlay.style.display = "none";
|
|
362
|
+
if (state.tooltip) state.tooltip.style.display = "none";
|
|
363
|
+
state.inlineEditor = createInlineEditor(state, state.selectedElement, saveInlineEdit, cancelInlineEdit);
|
|
364
|
+
const info = getElementInfo(state.selectedElement);
|
|
365
|
+
sendToParent("START_INLINE_EDIT", {
|
|
366
|
+
tagName: info.tagName,
|
|
367
|
+
filePath: info.filePath,
|
|
368
|
+
line: info.line,
|
|
369
|
+
text: state.originalText
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function selectElement() {
|
|
373
|
+
if (!state.hoveredElement) return;
|
|
374
|
+
state.selectedElement = state.hoveredElement;
|
|
375
|
+
const info = getElementInfo(state.hoveredElement);
|
|
376
|
+
const text = getElementTextContent(state.hoveredElement);
|
|
377
|
+
state.originalText = text;
|
|
378
|
+
sendToParent("CLICK_ELEMENT", {
|
|
379
|
+
tagName: info.tagName,
|
|
380
|
+
filePath: info.filePath,
|
|
381
|
+
line: info.line,
|
|
382
|
+
depth: info.depth,
|
|
383
|
+
text
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function startEditing() {
|
|
387
|
+
if (!state.hoveredElement) return;
|
|
388
|
+
state.selectedElement = state.hoveredElement;
|
|
389
|
+
const info = getElementInfo(state.hoveredElement);
|
|
390
|
+
const text = getElementTextContent(state.hoveredElement);
|
|
391
|
+
state.originalText = text;
|
|
392
|
+
sendToParent("CLICK_ELEMENT", {
|
|
393
|
+
tagName: info.tagName,
|
|
394
|
+
filePath: info.filePath,
|
|
395
|
+
line: info.line,
|
|
396
|
+
depth: info.depth,
|
|
397
|
+
text
|
|
398
|
+
});
|
|
399
|
+
enterEditMode();
|
|
400
|
+
}
|
|
401
|
+
const handleMouseMove = (e) => {
|
|
402
|
+
if (!state.isActive) return;
|
|
403
|
+
const target = e.target;
|
|
404
|
+
if (target.id === "lego-element-selector-overlay" || target.id === "lego-element-selector-tooltip") {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (target === state.hoveredElement) return;
|
|
408
|
+
highlightElement(state, target);
|
|
409
|
+
};
|
|
410
|
+
const handleScroll = () => {
|
|
411
|
+
if (state.isActive && state.hoveredElement) {
|
|
412
|
+
updateOverlayPosition(state);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const handleResize = () => {
|
|
416
|
+
if (state.isActive && state.hoveredElement) {
|
|
417
|
+
updateOverlayPosition(state);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const handleKeyDown = (e) => {
|
|
421
|
+
if (!state.isActive) return;
|
|
422
|
+
if (state.isEditing) {
|
|
423
|
+
if (e.key === "Escape") {
|
|
424
|
+
e.preventDefault();
|
|
425
|
+
cancelInlineEdit();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
switch (e.key) {
|
|
431
|
+
case "Escape":
|
|
432
|
+
sendToParent("SELECTOR_EXIT", true);
|
|
433
|
+
break;
|
|
434
|
+
case "ArrowUp":
|
|
435
|
+
e.preventDefault();
|
|
436
|
+
navigateDOM(state, "parent");
|
|
437
|
+
break;
|
|
438
|
+
case "ArrowDown":
|
|
439
|
+
e.preventDefault();
|
|
440
|
+
navigateDOM(state, "child");
|
|
441
|
+
break;
|
|
442
|
+
case "ArrowLeft":
|
|
443
|
+
e.preventDefault();
|
|
444
|
+
navigateDOM(state, "prev");
|
|
445
|
+
break;
|
|
446
|
+
case "ArrowRight":
|
|
447
|
+
e.preventDefault();
|
|
448
|
+
navigateDOM(state, "next");
|
|
449
|
+
break;
|
|
450
|
+
case "Enter":
|
|
451
|
+
e.preventDefault();
|
|
452
|
+
selectElement();
|
|
453
|
+
break;
|
|
454
|
+
case "e":
|
|
455
|
+
case "E":
|
|
456
|
+
if (state.hoveredElement) {
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
startEditing();
|
|
459
|
+
}
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const handleClick = (e) => {
|
|
464
|
+
if (!state.isActive) return;
|
|
465
|
+
if (state.isEditing) {
|
|
466
|
+
const target = e.target;
|
|
467
|
+
if (state.inlineEditor?.contains(target)) {
|
|
468
|
+
if (target.tagName === "BUTTON") {
|
|
469
|
+
e.preventDefault();
|
|
470
|
+
e.stopPropagation();
|
|
471
|
+
if (target.textContent === "Save") {
|
|
472
|
+
saveInlineEdit();
|
|
473
|
+
} else if (target.textContent === "Cancel") {
|
|
474
|
+
cancelInlineEdit();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
e.preventDefault();
|
|
480
|
+
e.stopPropagation();
|
|
481
|
+
e.stopImmediatePropagation();
|
|
482
|
+
cancelInlineEdit();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
e.preventDefault();
|
|
486
|
+
e.stopPropagation();
|
|
487
|
+
e.stopImmediatePropagation();
|
|
488
|
+
selectElement();
|
|
489
|
+
};
|
|
490
|
+
const handleDoubleClick = (e) => {
|
|
491
|
+
if (!state.isActive || state.isEditing) return;
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
e.stopPropagation();
|
|
494
|
+
e.stopImmediatePropagation();
|
|
495
|
+
startEditing();
|
|
496
|
+
};
|
|
497
|
+
const activateSelector = () => {
|
|
498
|
+
state.isActive = true;
|
|
499
|
+
document.addEventListener("mousemove", handleMouseMove, true);
|
|
500
|
+
document.addEventListener("click", handleClick, true);
|
|
501
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
502
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
503
|
+
window.addEventListener("resize", handleResize);
|
|
504
|
+
document.body.style.cursor = "crosshair";
|
|
505
|
+
state.overlay = createOverlay();
|
|
506
|
+
state.tooltip = createTooltip();
|
|
507
|
+
};
|
|
508
|
+
const deactivateSelector = () => {
|
|
509
|
+
state.isActive = false;
|
|
510
|
+
state.isEditing = false;
|
|
511
|
+
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
512
|
+
document.removeEventListener("click", handleClick, true);
|
|
513
|
+
document.removeEventListener("keydown", handleKeyDown, true);
|
|
514
|
+
window.removeEventListener("scroll", handleScroll, true);
|
|
515
|
+
window.removeEventListener("resize", handleResize);
|
|
516
|
+
if (state.overlay) {
|
|
517
|
+
state.overlay.remove();
|
|
518
|
+
state.overlay = null;
|
|
519
|
+
}
|
|
520
|
+
if (state.tooltip) {
|
|
521
|
+
state.tooltip.remove();
|
|
522
|
+
state.tooltip = null;
|
|
523
|
+
}
|
|
524
|
+
if (state.inlineEditor) {
|
|
525
|
+
state.inlineEditor.remove();
|
|
526
|
+
state.inlineEditor = null;
|
|
527
|
+
}
|
|
528
|
+
state.hoveredElement = null;
|
|
529
|
+
state.selectedElement = null;
|
|
530
|
+
state.originalText = "";
|
|
531
|
+
document.body.style.cursor = "";
|
|
532
|
+
state.depth = 0;
|
|
533
|
+
};
|
|
534
|
+
window.addEventListener("message", (e) => {
|
|
535
|
+
const msg = e.data;
|
|
536
|
+
if (msg.type === "TOGGLE_ELEMENT_SELECTOR") {
|
|
537
|
+
if (msg.payload) {
|
|
538
|
+
activateSelector();
|
|
539
|
+
} else {
|
|
540
|
+
deactivateSelector();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function initIframeBridge() {
|
|
546
|
+
try {
|
|
547
|
+
if (window.parent !== window) {
|
|
548
|
+
setupIframeBridge();
|
|
549
|
+
setupElementSelector();
|
|
550
|
+
}
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export {
|
|
556
|
+
sendToParent,
|
|
557
|
+
setupIframeBridge,
|
|
558
|
+
setupElementSelector,
|
|
559
|
+
initIframeBridge
|
|
560
|
+
};
|