@lego-build/plugins 0.0.2 → 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 -28
- package/dist/index.js +8 -736
- 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 +30 -21
package/dist/index.js
CHANGED
|
@@ -1,740 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
44
|
-
// src/selector.ts
|
|
45
|
-
function createElementSelectorState() {
|
|
46
|
-
return {
|
|
47
|
-
isActive: false,
|
|
48
|
-
isEditing: false,
|
|
49
|
-
hoveredElement: null,
|
|
50
|
-
selectedElement: null,
|
|
51
|
-
overlay: null,
|
|
52
|
-
tooltip: null,
|
|
53
|
-
inlineEditor: null,
|
|
54
|
-
depth: 0,
|
|
55
|
-
originalText: ""
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function createOverlay() {
|
|
59
|
-
const overlay = document.createElement("div");
|
|
60
|
-
overlay.id = "lego-element-selector-overlay";
|
|
61
|
-
overlay.style.cssText = `
|
|
62
|
-
position: fixed;
|
|
63
|
-
pointer-events: none;
|
|
64
|
-
z-index: 2147483646;
|
|
65
|
-
background: rgba(59, 130, 246, 0.1);
|
|
66
|
-
border: 2px solid #3b82f6;
|
|
67
|
-
border-radius: 4px;
|
|
68
|
-
transition: all 0.1s ease-out;
|
|
69
|
-
`;
|
|
70
|
-
document.body.appendChild(overlay);
|
|
71
|
-
return overlay;
|
|
72
|
-
}
|
|
73
|
-
function createTooltip() {
|
|
74
|
-
const tooltip = document.createElement("div");
|
|
75
|
-
tooltip.id = "lego-element-selector-tooltip";
|
|
76
|
-
tooltip.style.cssText = `
|
|
77
|
-
position: fixed;
|
|
78
|
-
pointer-events: none;
|
|
79
|
-
z-index: 2147483647;
|
|
80
|
-
background: #3b82f6;
|
|
81
|
-
color: white;
|
|
82
|
-
padding: 4px 8px;
|
|
83
|
-
border-radius: 4px;
|
|
84
|
-
font-family: ui-monospace, monospace;
|
|
85
|
-
font-size: 12px;
|
|
86
|
-
white-space: nowrap;
|
|
87
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
|
88
|
-
transition: all 0.1s ease-out;
|
|
89
|
-
`;
|
|
90
|
-
document.body.appendChild(tooltip);
|
|
91
|
-
return tooltip;
|
|
92
|
-
}
|
|
93
|
-
function createInlineEditor(state, element, onSave, onCancel) {
|
|
94
|
-
const rect = element.getBoundingClientRect();
|
|
95
|
-
const elementText = getElementTextContent(element);
|
|
96
|
-
const editor = document.createElement("div");
|
|
97
|
-
editor.id = "lego-inline-editor";
|
|
98
|
-
editor.style.cssText = `
|
|
99
|
-
position: fixed;
|
|
100
|
-
top: ${rect.top}px;
|
|
101
|
-
left: ${rect.left}px;
|
|
102
|
-
width: ${Math.max(rect.width, 200)}px;
|
|
103
|
-
z-index: 2147483647;
|
|
104
|
-
background: white;
|
|
105
|
-
border: 2px solid #3b82f6;
|
|
106
|
-
border-radius: 8px;
|
|
107
|
-
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
108
|
-
padding: 8px;
|
|
109
|
-
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
110
|
-
`;
|
|
111
|
-
const header = document.createElement("div");
|
|
112
|
-
header.style.cssText = `
|
|
113
|
-
display: flex;
|
|
114
|
-
align-items: center;
|
|
115
|
-
justify-content: space-between;
|
|
116
|
-
margin-bottom: 8px;
|
|
117
|
-
padding-bottom: 8px;
|
|
118
|
-
border-bottom: 1px solid #e5e7eb;
|
|
119
|
-
`;
|
|
120
|
-
header.innerHTML = `
|
|
121
|
-
<span style="font-size: 11px; font-weight: 500; color: #6b7280;">
|
|
122
|
-
\u270F\uFE0F Edit Text
|
|
123
|
-
</span>
|
|
124
|
-
<span style="font-size: 10px; color: #9ca3af;">
|
|
125
|
-
Ctrl+Enter to save \u2022 Esc to cancel
|
|
126
|
-
</span>
|
|
127
|
-
`;
|
|
128
|
-
const input = document.createElement("textarea");
|
|
129
|
-
input.id = "lego-inline-editor-input";
|
|
130
|
-
input.value = elementText;
|
|
131
|
-
input.style.cssText = `
|
|
132
|
-
width: 100%;
|
|
133
|
-
min-height: 60px;
|
|
134
|
-
padding: 8px;
|
|
135
|
-
border: 1px solid #e5e7eb;
|
|
136
|
-
border-radius: 4px;
|
|
137
|
-
font-size: 14px;
|
|
138
|
-
font-family: inherit;
|
|
139
|
-
resize: vertical;
|
|
140
|
-
outline: none;
|
|
141
|
-
box-sizing: border-box;
|
|
142
|
-
`;
|
|
143
|
-
input.placeholder = "Enter text...";
|
|
144
|
-
const buttons = document.createElement("div");
|
|
145
|
-
buttons.style.cssText = `
|
|
146
|
-
display: flex;
|
|
147
|
-
gap: 8px;
|
|
148
|
-
margin-top: 8px;
|
|
149
|
-
justify-content: flex-end;
|
|
150
|
-
`;
|
|
151
|
-
const cancelBtn = document.createElement("button");
|
|
152
|
-
cancelBtn.textContent = "Cancel";
|
|
153
|
-
cancelBtn.style.cssText = `
|
|
154
|
-
padding: 6px 12px;
|
|
155
|
-
border: 1px solid #e5e7eb;
|
|
156
|
-
border-radius: 4px;
|
|
157
|
-
background: white;
|
|
158
|
-
font-size: 12px;
|
|
159
|
-
cursor: pointer;
|
|
160
|
-
transition: all 0.15s;
|
|
161
|
-
`;
|
|
162
|
-
cancelBtn.onmouseenter = () => cancelBtn.style.background = "#f3f4f6";
|
|
163
|
-
cancelBtn.onmouseleave = () => cancelBtn.style.background = "white";
|
|
164
|
-
cancelBtn.onclick = (e) => {
|
|
165
|
-
e.preventDefault();
|
|
166
|
-
e.stopPropagation();
|
|
167
|
-
onCancel();
|
|
168
|
-
};
|
|
169
|
-
const saveBtn = document.createElement("button");
|
|
170
|
-
saveBtn.textContent = "Save";
|
|
171
|
-
saveBtn.style.cssText = `
|
|
172
|
-
padding: 6px 12px;
|
|
173
|
-
border: none;
|
|
174
|
-
border-radius: 4px;
|
|
175
|
-
background: #3b82f6;
|
|
176
|
-
color: white;
|
|
177
|
-
font-size: 12px;
|
|
178
|
-
font-weight: 500;
|
|
179
|
-
cursor: pointer;
|
|
180
|
-
transition: all 0.15s;
|
|
181
|
-
`;
|
|
182
|
-
saveBtn.onmouseenter = () => saveBtn.style.background = "#2563eb";
|
|
183
|
-
saveBtn.onmouseleave = () => saveBtn.style.background = "#3b82f6";
|
|
184
|
-
saveBtn.onclick = (e) => {
|
|
185
|
-
e.preventDefault();
|
|
186
|
-
e.stopPropagation();
|
|
187
|
-
onSave();
|
|
188
|
-
};
|
|
189
|
-
editor.appendChild(header);
|
|
190
|
-
editor.appendChild(input);
|
|
191
|
-
buttons.appendChild(cancelBtn);
|
|
192
|
-
buttons.appendChild(saveBtn);
|
|
193
|
-
editor.appendChild(buttons);
|
|
194
|
-
document.body.appendChild(editor);
|
|
195
|
-
setTimeout(() => {
|
|
196
|
-
input.focus();
|
|
197
|
-
input.select();
|
|
198
|
-
}, 0);
|
|
199
|
-
input.addEventListener("keydown", (e) => {
|
|
200
|
-
if (e.key === "Escape") {
|
|
201
|
-
e.preventDefault();
|
|
202
|
-
e.stopPropagation();
|
|
203
|
-
onCancel();
|
|
204
|
-
} else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
205
|
-
e.preventDefault();
|
|
206
|
-
e.stopPropagation();
|
|
207
|
-
onSave();
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
input.addEventListener("keyup", (e) => {
|
|
211
|
-
e.stopPropagation();
|
|
212
|
-
});
|
|
213
|
-
input.addEventListener("keypress", (e) => {
|
|
214
|
-
e.stopPropagation();
|
|
215
|
-
});
|
|
216
|
-
return editor;
|
|
217
|
-
}
|
|
218
|
-
function getElementTextContent(element) {
|
|
219
|
-
let text = "";
|
|
220
|
-
for (const node of element.childNodes) {
|
|
221
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
222
|
-
text += node.textContent?.trim() || "";
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (!text && element.children.length === 0) {
|
|
226
|
-
text = element.textContent?.trim() || "";
|
|
227
|
-
}
|
|
228
|
-
return text;
|
|
229
|
-
}
|
|
230
|
-
function getElementDepth(element) {
|
|
231
|
-
let depth = 0;
|
|
232
|
-
let current = element;
|
|
233
|
-
while (current && current !== document.body) {
|
|
234
|
-
depth++;
|
|
235
|
-
current = current.parentElement;
|
|
236
|
-
}
|
|
237
|
-
return depth;
|
|
238
|
-
}
|
|
239
|
-
function updateOverlayPosition(state) {
|
|
240
|
-
if (!state.hoveredElement || !state.overlay || !state.tooltip) return;
|
|
241
|
-
const rect = state.hoveredElement.getBoundingClientRect();
|
|
242
|
-
const viewportWidth = window.innerWidth;
|
|
243
|
-
state.overlay.style.top = `${rect.top}px`;
|
|
244
|
-
state.overlay.style.left = `${rect.left}px`;
|
|
245
|
-
state.overlay.style.width = `${rect.width}px`;
|
|
246
|
-
state.overlay.style.height = `${rect.height}px`;
|
|
247
|
-
let tooltipTop = rect.top - 32;
|
|
248
|
-
let tooltipLeft = rect.left;
|
|
249
|
-
if (tooltipTop < 8) {
|
|
250
|
-
tooltipTop = rect.bottom + 8;
|
|
251
|
-
}
|
|
252
|
-
const estimatedTooltipWidth = state.tooltip.offsetWidth || 150;
|
|
253
|
-
if (tooltipLeft + estimatedTooltipWidth > viewportWidth - 8) {
|
|
254
|
-
tooltipLeft = viewportWidth - estimatedTooltipWidth - 8;
|
|
255
|
-
}
|
|
256
|
-
if (tooltipLeft < 8) {
|
|
257
|
-
tooltipLeft = 8;
|
|
258
|
-
}
|
|
259
|
-
state.tooltip.style.top = `${tooltipTop}px`;
|
|
260
|
-
state.tooltip.style.left = `${tooltipLeft}px`;
|
|
261
|
-
}
|
|
262
|
-
function getElementInfo(element) {
|
|
263
|
-
const filePath = element.getAttribute("data-locator-path") || "";
|
|
264
|
-
const line = element.getAttribute("data-locator-line");
|
|
265
|
-
const depth = getElementDepth(element);
|
|
266
|
-
const id = element.id ? `#${element.id}` : "";
|
|
267
|
-
const classes = element.className && typeof element.className === "string" ? element.className.split(" ").filter((c) => c).map((c) => `.${c}`).join("") : "";
|
|
268
|
-
return {
|
|
269
|
-
tagName: element.tagName.toLowerCase(),
|
|
270
|
-
selector: element.tagName.toLowerCase() + id + classes.slice(0, 50),
|
|
271
|
-
filePath,
|
|
272
|
-
line: line ? parseInt(line) : void 0,
|
|
273
|
-
depth,
|
|
274
|
-
rect: element.getBoundingClientRect()
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
function highlightElement(state, element) {
|
|
278
|
-
state.hoveredElement = element;
|
|
279
|
-
if (!state.overlay) {
|
|
280
|
-
state.overlay = createOverlay();
|
|
281
|
-
}
|
|
282
|
-
if (!state.tooltip) {
|
|
283
|
-
state.tooltip = createTooltip();
|
|
284
|
-
}
|
|
285
|
-
state.overlay.style.display = "block";
|
|
286
|
-
state.tooltip.style.display = "block";
|
|
287
|
-
const info = getElementInfo(element);
|
|
288
|
-
state.depth = info.depth;
|
|
289
|
-
state.tooltip.innerHTML = `
|
|
290
|
-
<span style="opacity: 0.8">${info.selector}</span>
|
|
291
|
-
${info.filePath ? `<span style="margin-left: 8px; opacity: 0.6">\u{1F4C4} ${info.filePath.split("/").pop()}</span>` : ""}
|
|
292
|
-
<span style="margin-left: 8px; opacity: 0.5; font-size: 10px;">Double-click to edit</span>
|
|
293
|
-
`;
|
|
294
|
-
updateOverlayPosition(state);
|
|
295
|
-
sendToParent("HOVER_ELEMENT", {
|
|
296
|
-
tagName: info.tagName,
|
|
297
|
-
rect: info.rect,
|
|
298
|
-
filePath: info.filePath || void 0,
|
|
299
|
-
line: info.line,
|
|
300
|
-
depth: info.depth
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
function navigateDOM(state, direction) {
|
|
304
|
-
if (!state.hoveredElement) return;
|
|
305
|
-
let target = null;
|
|
306
|
-
switch (direction) {
|
|
307
|
-
case "parent":
|
|
308
|
-
target = state.hoveredElement.parentElement;
|
|
309
|
-
if (target && target === document.body) target = null;
|
|
310
|
-
break;
|
|
311
|
-
case "child":
|
|
312
|
-
target = state.hoveredElement.firstElementChild;
|
|
313
|
-
break;
|
|
314
|
-
case "next":
|
|
315
|
-
target = state.hoveredElement.nextElementSibling;
|
|
316
|
-
break;
|
|
317
|
-
case "prev":
|
|
318
|
-
target = state.hoveredElement.previousElementSibling;
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
if (target && target !== document.documentElement && target !== document.body) {
|
|
322
|
-
highlightElement(state, target);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
function setupElementSelector() {
|
|
326
|
-
const state = createElementSelectorState();
|
|
327
|
-
function saveInlineEdit() {
|
|
328
|
-
if (!state.inlineEditor || !state.selectedElement) return;
|
|
329
|
-
const input = state.inlineEditor.querySelector(
|
|
330
|
-
"#lego-inline-editor-input"
|
|
331
|
-
);
|
|
332
|
-
const newText = input?.value || "";
|
|
333
|
-
const info = getElementInfo(state.selectedElement);
|
|
334
|
-
if (newText !== state.originalText && info.filePath) {
|
|
335
|
-
sendToParent("SAVE_INLINE_EDIT", {
|
|
336
|
-
filePath: info.filePath,
|
|
337
|
-
originalContent: state.originalText,
|
|
338
|
-
newContent: newText,
|
|
339
|
-
line: info.line
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
exitEditMode();
|
|
343
|
-
}
|
|
344
|
-
function cancelInlineEdit() {
|
|
345
|
-
sendToParent("CANCEL_INLINE_EDIT");
|
|
346
|
-
exitEditMode();
|
|
347
|
-
}
|
|
348
|
-
function exitEditMode() {
|
|
349
|
-
state.isEditing = false;
|
|
350
|
-
if (state.inlineEditor) {
|
|
351
|
-
state.inlineEditor.remove();
|
|
352
|
-
state.inlineEditor = null;
|
|
353
|
-
}
|
|
354
|
-
if (state.isActive && state.hoveredElement) {
|
|
355
|
-
if (state.overlay) state.overlay.style.display = "block";
|
|
356
|
-
if (state.tooltip) state.tooltip.style.display = "block";
|
|
357
|
-
}
|
|
358
|
-
state.selectedElement = null;
|
|
359
|
-
state.originalText = "";
|
|
360
|
-
}
|
|
361
|
-
function enterEditMode() {
|
|
362
|
-
if (!state.selectedElement) return;
|
|
363
|
-
state.isEditing = true;
|
|
364
|
-
if (state.overlay) state.overlay.style.display = "none";
|
|
365
|
-
if (state.tooltip) state.tooltip.style.display = "none";
|
|
366
|
-
state.inlineEditor = createInlineEditor(state, state.selectedElement, saveInlineEdit, cancelInlineEdit);
|
|
367
|
-
const info = getElementInfo(state.selectedElement);
|
|
368
|
-
sendToParent("START_INLINE_EDIT", {
|
|
369
|
-
tagName: info.tagName,
|
|
370
|
-
filePath: info.filePath,
|
|
371
|
-
line: info.line,
|
|
372
|
-
text: state.originalText
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
function selectElement() {
|
|
376
|
-
if (!state.hoveredElement) return;
|
|
377
|
-
state.selectedElement = state.hoveredElement;
|
|
378
|
-
const info = getElementInfo(state.hoveredElement);
|
|
379
|
-
const text = getElementTextContent(state.hoveredElement);
|
|
380
|
-
state.originalText = text;
|
|
381
|
-
sendToParent("CLICK_ELEMENT", {
|
|
382
|
-
tagName: info.tagName,
|
|
383
|
-
filePath: info.filePath,
|
|
384
|
-
line: info.line,
|
|
385
|
-
depth: info.depth,
|
|
386
|
-
text
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
function startEditing() {
|
|
390
|
-
if (!state.hoveredElement) return;
|
|
391
|
-
state.selectedElement = state.hoveredElement;
|
|
392
|
-
const info = getElementInfo(state.hoveredElement);
|
|
393
|
-
const text = getElementTextContent(state.hoveredElement);
|
|
394
|
-
state.originalText = text;
|
|
395
|
-
sendToParent("CLICK_ELEMENT", {
|
|
396
|
-
tagName: info.tagName,
|
|
397
|
-
filePath: info.filePath,
|
|
398
|
-
line: info.line,
|
|
399
|
-
depth: info.depth,
|
|
400
|
-
text
|
|
401
|
-
});
|
|
402
|
-
enterEditMode();
|
|
403
|
-
}
|
|
404
|
-
const handleMouseMove = (e) => {
|
|
405
|
-
if (!state.isActive) return;
|
|
406
|
-
const target = e.target;
|
|
407
|
-
if (target.id === "lego-element-selector-overlay" || target.id === "lego-element-selector-tooltip") {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
if (target === state.hoveredElement) return;
|
|
411
|
-
highlightElement(state, target);
|
|
412
|
-
};
|
|
413
|
-
const handleScroll = () => {
|
|
414
|
-
if (state.isActive && state.hoveredElement) {
|
|
415
|
-
updateOverlayPosition(state);
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
const handleResize = () => {
|
|
419
|
-
if (state.isActive && state.hoveredElement) {
|
|
420
|
-
updateOverlayPosition(state);
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
const handleKeyDown = (e) => {
|
|
424
|
-
if (!state.isActive) return;
|
|
425
|
-
if (state.isEditing) {
|
|
426
|
-
if (e.key === "Escape") {
|
|
427
|
-
e.preventDefault();
|
|
428
|
-
cancelInlineEdit();
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
switch (e.key) {
|
|
434
|
-
case "Escape":
|
|
435
|
-
sendToParent("SELECTOR_EXIT", true);
|
|
436
|
-
break;
|
|
437
|
-
case "ArrowUp":
|
|
438
|
-
e.preventDefault();
|
|
439
|
-
navigateDOM(state, "parent");
|
|
440
|
-
break;
|
|
441
|
-
case "ArrowDown":
|
|
442
|
-
e.preventDefault();
|
|
443
|
-
navigateDOM(state, "child");
|
|
444
|
-
break;
|
|
445
|
-
case "ArrowLeft":
|
|
446
|
-
e.preventDefault();
|
|
447
|
-
navigateDOM(state, "prev");
|
|
448
|
-
break;
|
|
449
|
-
case "ArrowRight":
|
|
450
|
-
e.preventDefault();
|
|
451
|
-
navigateDOM(state, "next");
|
|
452
|
-
break;
|
|
453
|
-
case "Enter":
|
|
454
|
-
e.preventDefault();
|
|
455
|
-
selectElement();
|
|
456
|
-
break;
|
|
457
|
-
case "e":
|
|
458
|
-
case "E":
|
|
459
|
-
if (state.hoveredElement) {
|
|
460
|
-
e.preventDefault();
|
|
461
|
-
startEditing();
|
|
462
|
-
}
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
const handleClick = (e) => {
|
|
467
|
-
if (!state.isActive) return;
|
|
468
|
-
if (state.isEditing) {
|
|
469
|
-
const target = e.target;
|
|
470
|
-
if (state.inlineEditor?.contains(target)) {
|
|
471
|
-
if (target.tagName === "BUTTON") {
|
|
472
|
-
e.preventDefault();
|
|
473
|
-
e.stopPropagation();
|
|
474
|
-
if (target.textContent === "Save") {
|
|
475
|
-
saveInlineEdit();
|
|
476
|
-
} else if (target.textContent === "Cancel") {
|
|
477
|
-
cancelInlineEdit();
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
e.preventDefault();
|
|
483
|
-
e.stopPropagation();
|
|
484
|
-
e.stopImmediatePropagation();
|
|
485
|
-
cancelInlineEdit();
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
e.preventDefault();
|
|
489
|
-
e.stopPropagation();
|
|
490
|
-
e.stopImmediatePropagation();
|
|
491
|
-
selectElement();
|
|
492
|
-
};
|
|
493
|
-
const handleDoubleClick = (e) => {
|
|
494
|
-
if (!state.isActive || state.isEditing) return;
|
|
495
|
-
e.preventDefault();
|
|
496
|
-
e.stopPropagation();
|
|
497
|
-
e.stopImmediatePropagation();
|
|
498
|
-
startEditing();
|
|
499
|
-
};
|
|
500
|
-
const activateSelector = () => {
|
|
501
|
-
state.isActive = true;
|
|
502
|
-
document.addEventListener("mousemove", handleMouseMove, true);
|
|
503
|
-
document.addEventListener("click", handleClick, true);
|
|
504
|
-
document.addEventListener("dblclick", handleDoubleClick, true);
|
|
505
|
-
document.addEventListener("keydown", handleKeyDown, true);
|
|
506
|
-
window.addEventListener("scroll", handleScroll, true);
|
|
507
|
-
window.addEventListener("resize", handleResize);
|
|
508
|
-
document.body.style.cursor = "crosshair";
|
|
509
|
-
state.overlay = createOverlay();
|
|
510
|
-
state.tooltip = createTooltip();
|
|
511
|
-
};
|
|
512
|
-
const deactivateSelector = () => {
|
|
513
|
-
state.isActive = false;
|
|
514
|
-
state.isEditing = false;
|
|
515
|
-
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
516
|
-
document.removeEventListener("click", handleClick, true);
|
|
517
|
-
document.removeEventListener("dblclick", handleDoubleClick, true);
|
|
518
|
-
document.removeEventListener("keydown", handleKeyDown, true);
|
|
519
|
-
window.removeEventListener("scroll", handleScroll, true);
|
|
520
|
-
window.removeEventListener("resize", handleResize);
|
|
521
|
-
if (state.overlay) {
|
|
522
|
-
state.overlay.remove();
|
|
523
|
-
state.overlay = null;
|
|
524
|
-
}
|
|
525
|
-
if (state.tooltip) {
|
|
526
|
-
state.tooltip.remove();
|
|
527
|
-
state.tooltip = null;
|
|
528
|
-
}
|
|
529
|
-
if (state.inlineEditor) {
|
|
530
|
-
state.inlineEditor.remove();
|
|
531
|
-
state.inlineEditor = null;
|
|
532
|
-
}
|
|
533
|
-
state.hoveredElement = null;
|
|
534
|
-
state.selectedElement = null;
|
|
535
|
-
state.originalText = "";
|
|
536
|
-
document.body.style.cursor = "";
|
|
537
|
-
state.depth = 0;
|
|
538
|
-
};
|
|
539
|
-
window.addEventListener("message", (e) => {
|
|
540
|
-
const msg = e.data;
|
|
541
|
-
if (msg.type === "TOGGLE_ELEMENT_SELECTOR") {
|
|
542
|
-
if (msg.payload) {
|
|
543
|
-
activateSelector();
|
|
544
|
-
} else {
|
|
545
|
-
deactivateSelector();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// src/source-locator.ts
|
|
552
|
-
import path from "path";
|
|
553
|
-
import * as parser from "@babel/parser";
|
|
554
|
-
import traverse from "@babel/traverse";
|
|
555
|
-
import generate from "@babel/generator";
|
|
556
|
-
import * as t from "@babel/types";
|
|
557
|
-
import micromatch from "micromatch";
|
|
558
|
-
import { createHash } from "crypto";
|
|
559
|
-
var HTML_TAGS = [
|
|
560
|
-
"div",
|
|
561
|
-
"span",
|
|
562
|
-
"p",
|
|
563
|
-
"h1",
|
|
564
|
-
"h2",
|
|
565
|
-
"h3",
|
|
566
|
-
"h4",
|
|
567
|
-
"h5",
|
|
568
|
-
"h6",
|
|
569
|
-
"button",
|
|
570
|
-
"a",
|
|
571
|
-
"img",
|
|
572
|
-
"input",
|
|
573
|
-
"textarea",
|
|
574
|
-
"select",
|
|
575
|
-
"form",
|
|
576
|
-
"ul",
|
|
577
|
-
"ol",
|
|
578
|
-
"li",
|
|
579
|
-
"table",
|
|
580
|
-
"thead",
|
|
581
|
-
"tbody",
|
|
582
|
-
"tr",
|
|
583
|
-
"td",
|
|
584
|
-
"th",
|
|
585
|
-
"header",
|
|
586
|
-
"footer",
|
|
587
|
-
"nav",
|
|
588
|
-
"main",
|
|
589
|
-
"section",
|
|
590
|
-
"article",
|
|
591
|
-
"aside",
|
|
592
|
-
"label",
|
|
593
|
-
"strong",
|
|
594
|
-
"em",
|
|
595
|
-
"code",
|
|
596
|
-
"pre",
|
|
597
|
-
"blockquote"
|
|
598
|
-
];
|
|
599
|
-
var TEXT_TAGS = ["label", "span", "button", "p", "div", "h1", "h2", "h3", "h4", "h5", "h6"];
|
|
600
|
-
function getWorkspaceRoot(filePath) {
|
|
601
|
-
let dir = path.resolve(filePath);
|
|
602
|
-
const { root } = path.parse(dir);
|
|
603
|
-
while (dir !== root) {
|
|
604
|
-
if (path.basename(dir) === "workspace") return dir;
|
|
605
|
-
dir = path.dirname(dir);
|
|
606
|
-
}
|
|
607
|
-
return path.resolve(process.cwd(), "..");
|
|
608
|
-
}
|
|
609
|
-
function shouldProcessTag(tagName, options) {
|
|
610
|
-
if (options.filterTag) {
|
|
611
|
-
if (Array.isArray(options.filterTag)) {
|
|
612
|
-
return options.filterTag.includes(tagName);
|
|
613
|
-
}
|
|
614
|
-
return options.filterTag(tagName);
|
|
615
|
-
}
|
|
616
|
-
return HTML_TAGS.includes(tagName.toLowerCase());
|
|
617
|
-
}
|
|
618
|
-
function getElementTextContent2(nodePath) {
|
|
619
|
-
const parent = nodePath.parent;
|
|
620
|
-
if (!t.isJSXElement(parent)) return "";
|
|
621
|
-
let text = "";
|
|
622
|
-
let hasExpression = false;
|
|
623
|
-
for (const child of parent.children) {
|
|
624
|
-
if (t.isJSXText(child)) {
|
|
625
|
-
text += child.value;
|
|
626
|
-
} else if (t.isJSXExpressionContainer(child)) {
|
|
627
|
-
hasExpression = true;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
return hasExpression ? "" : text.trim();
|
|
631
|
-
}
|
|
632
|
-
function transformJSX(code, filePath, prefix, options) {
|
|
633
|
-
const ast = parser.parse(code, {
|
|
634
|
-
sourceType: "module",
|
|
635
|
-
plugins: ["jsx", "typescript", "classProperties", "decorators-legacy"]
|
|
636
|
-
});
|
|
637
|
-
const workspaceRoot = getWorkspaceRoot(filePath);
|
|
638
|
-
const relativePath = path.relative(workspaceRoot, filePath);
|
|
639
|
-
let hasChanges = false;
|
|
640
|
-
traverse(ast, {
|
|
641
|
-
JSXOpeningElement(nodePath) {
|
|
642
|
-
const node = nodePath.node;
|
|
643
|
-
const hasLocatorAttr = node.attributes.some(
|
|
644
|
-
(attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name.startsWith(`data-${prefix}`)
|
|
645
|
-
);
|
|
646
|
-
if (hasLocatorAttr) return;
|
|
647
|
-
if (t.isJSXIdentifier(node.name) && node.name.name === "Fragment") return;
|
|
648
|
-
if (t.isJSXMemberExpression(node.name) && t.isJSXIdentifier(node.name.object) && node.name.object.name === "React" && t.isJSXIdentifier(node.name.property) && node.name.property.name === "Fragment")
|
|
649
|
-
return;
|
|
650
|
-
let tagName = "";
|
|
651
|
-
if (t.isJSXIdentifier(node.name)) {
|
|
652
|
-
tagName = node.name.name;
|
|
653
|
-
}
|
|
654
|
-
if (!shouldProcessTag(tagName, options)) return;
|
|
655
|
-
const line = node.loc?.start.line;
|
|
656
|
-
const column = node.loc?.start.column;
|
|
657
|
-
if (!line || column === void 0) return;
|
|
658
|
-
const textContent = TEXT_TAGS.includes(tagName.toLowerCase()) ? getElementTextContent2(nodePath) : "";
|
|
659
|
-
const attributes = [
|
|
660
|
-
t.jsxAttribute(t.jsxIdentifier(`data-${prefix}-path`), t.stringLiteral(relativePath)),
|
|
661
|
-
t.jsxAttribute(t.jsxIdentifier(`data-${prefix}-line`), t.stringLiteral(String(line))),
|
|
662
|
-
t.jsxAttribute(t.jsxIdentifier(`data-${prefix}-column`), t.stringLiteral(String(column))),
|
|
663
|
-
t.jsxAttribute(t.jsxIdentifier(`data-${prefix}-tag`), t.stringLiteral(tagName))
|
|
664
|
-
];
|
|
665
|
-
if (textContent) {
|
|
666
|
-
attributes.push(
|
|
667
|
-
t.jsxAttribute(
|
|
668
|
-
t.jsxIdentifier(`data-${prefix}-text`),
|
|
669
|
-
t.stringLiteral(textContent)
|
|
670
|
-
)
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
const spreadIndex = node.attributes.findIndex((attr) => t.isJSXSpreadAttribute(attr));
|
|
674
|
-
if (spreadIndex === -1) {
|
|
675
|
-
node.attributes.push(...attributes);
|
|
676
|
-
} else {
|
|
677
|
-
node.attributes.splice(spreadIndex, 0, ...attributes);
|
|
678
|
-
}
|
|
679
|
-
hasChanges = true;
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
if (!hasChanges) return null;
|
|
683
|
-
const result = generate(ast, {}, code);
|
|
684
|
-
return {
|
|
685
|
-
code: result.code,
|
|
686
|
-
map: result.map
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
var transformCache = /* @__PURE__ */ new Map();
|
|
690
|
-
function sourceLocator(options = {}) {
|
|
691
|
-
const {
|
|
692
|
-
include = ["src/**/*.{jsx,tsx,js,ts}"],
|
|
693
|
-
exclude = [],
|
|
694
|
-
prefix = "locator",
|
|
695
|
-
enable = true
|
|
696
|
-
} = options;
|
|
697
|
-
const includePatterns = Array.isArray(include) ? include : [include];
|
|
698
|
-
const excludePatterns = Array.isArray(exclude) ? exclude : [exclude];
|
|
699
|
-
return {
|
|
700
|
-
name: "@lego/plugin-source-locator",
|
|
701
|
-
enforce: "pre",
|
|
702
|
-
apply: "serve",
|
|
703
|
-
version: "0.0.1",
|
|
704
|
-
async transform(code, id) {
|
|
705
|
-
if (!enable) return;
|
|
706
|
-
const relativePath = path.relative(process.cwd(), id);
|
|
707
|
-
const isIncluded = micromatch.isMatch(relativePath, includePatterns);
|
|
708
|
-
const isExcluded = excludePatterns.length > 0 && micromatch.isMatch(relativePath, excludePatterns);
|
|
709
|
-
if (!isIncluded || isExcluded) return;
|
|
710
|
-
const ext = path.extname(id);
|
|
711
|
-
if (![".jsx", ".tsx", ".js", ".ts"].includes(ext)) return;
|
|
712
|
-
const hash = createHash("md5").update(code).digest("hex");
|
|
713
|
-
const cacheKey = `${id}:${hash}`;
|
|
714
|
-
if (transformCache.has(cacheKey)) {
|
|
715
|
-
return transformCache.get(cacheKey);
|
|
716
|
-
}
|
|
717
|
-
const result = transformJSX(code, id, prefix, options);
|
|
718
|
-
if (result) {
|
|
719
|
-
transformCache.set(cacheKey, result);
|
|
720
|
-
return result;
|
|
721
|
-
}
|
|
722
|
-
return null;
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// src/index.ts
|
|
728
|
-
try {
|
|
729
|
-
if (typeof window !== "undefined" && window.parent !== window) {
|
|
730
|
-
setupIframeBridge();
|
|
731
|
-
setupElementSelector();
|
|
732
|
-
}
|
|
733
|
-
} catch {
|
|
734
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
initIframeBridge,
|
|
3
|
+
sendToParent,
|
|
4
|
+
setupElementSelector,
|
|
5
|
+
setupIframeBridge
|
|
6
|
+
} from "./chunk-4ILDPPTG.js";
|
|
735
7
|
export {
|
|
8
|
+
initIframeBridge,
|
|
736
9
|
sendToParent,
|
|
737
10
|
setupElementSelector,
|
|
738
|
-
setupIframeBridge
|
|
739
|
-
sourceLocator
|
|
11
|
+
setupIframeBridge
|
|
740
12
|
};
|