@lark-apaas/miaoda-inspector 0.1.0-alpha.4 → 0.1.0-alpha.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/es/Inspector/Inspector.mjs +4 -22
- package/dist/es/Inspector/Overlay.mjs +58 -32
- package/dist/es/Inspector/utils/inspect.mjs +80 -1
- package/dist/es/MiaodaInspector/MiaodaInspector.mjs +332 -173
- package/dist/es/config/ui-config.mjs +138 -136
- package/dist/es/index.mjs +2 -0
- package/dist/es/types/feature.mjs +0 -0
- package/dist/es/types/index.mjs +4 -0
- package/dist/es/utils/config-mapper.mjs +1 -3
- package/dist/es/utils/element-guards.mjs +36 -0
- package/dist/es/utils/index.mjs +1 -6
- package/dist/es/utils/style-calculator.mjs +17 -60
- package/dist/lib/Inspector/Inspector.js +4 -23
- package/dist/lib/Inspector/Overlay.js +57 -28
- package/dist/lib/Inspector/utils/inspect.js +90 -1
- package/dist/lib/MiaodaInspector/MiaodaInspector.js +337 -183
- package/dist/lib/config/ui-config.js +138 -136
- package/dist/lib/index.js +2 -0
- package/dist/lib/types/feature.js +16 -0
- package/dist/lib/types/index.js +3 -0
- package/dist/lib/utils/config-mapper.js +1 -3
- package/dist/lib/utils/element-guards.js +55 -0
- package/dist/lib/utils/style-calculator.js +17 -60
- package/dist/types/Inspector/Inspector.d.ts +8 -1
- package/dist/types/Inspector/Overlay.d.ts +9 -2
- package/dist/types/Inspector/utils/index.d.ts +1 -1
- package/dist/types/Inspector/utils/inspect.d.ts +8 -1
- package/dist/types/config/ui-config.d.ts +26 -3
- package/dist/types/global.d.d.ts +6 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/types/feature.d.ts +6 -0
- package/dist/types/types/iframe-events.d.ts +44 -2
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/utils/element-guards.d.ts +7 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/origin.d.ts +1 -0
- package/package.json +1 -1
|
@@ -9,28 +9,9 @@ import {
|
|
|
9
9
|
setupHighlighter,
|
|
10
10
|
getElementCodeInfo,
|
|
11
11
|
getElementInspect,
|
|
12
|
-
|
|
12
|
+
getParentElement,
|
|
13
|
+
extractPropsFromFiber
|
|
13
14
|
} from "./utils";
|
|
14
|
-
import { getElementFiberUpward } from "./utils/fiber";
|
|
15
|
-
const getParentElement = (element) => {
|
|
16
|
-
let parent = element;
|
|
17
|
-
while (parent && parent.tagName !== "HTML") {
|
|
18
|
-
if (parent.dataset.miaodaComponentName) {
|
|
19
|
-
return parent;
|
|
20
|
-
}
|
|
21
|
-
const fiber = getElementFiberUpward(parent);
|
|
22
|
-
const parentFiber = parent.parentElement ? getElementFiberUpward(parent.parentElement) : void 0;
|
|
23
|
-
const referenceFiber = getReferenceFiber(fiber);
|
|
24
|
-
const parentReferenceFiber = parentFiber ? getReferenceFiber(parentFiber) : null;
|
|
25
|
-
const currentName = referenceFiber == null ? void 0 : referenceFiber.pendingProps["data-miaoda-component-name"];
|
|
26
|
-
const parentName = parentReferenceFiber ? parentReferenceFiber.pendingProps["data-miaoda-component-name"] : null;
|
|
27
|
-
if (currentName && currentName !== parentName) {
|
|
28
|
-
return parent;
|
|
29
|
-
}
|
|
30
|
-
parent = parent.parentElement;
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
};
|
|
34
15
|
const defaultHotkeys = () => {
|
|
35
16
|
var _a;
|
|
36
17
|
return ((_a = navigator.platform) == null ? void 0 : _a.startsWith("Mac")) ? ["Ctrl", "Shift", "Command", "C"] : ["Ctrl", "Shift", "Alt", "C"];
|
|
@@ -99,7 +80,8 @@ const Inspector = (props) => {
|
|
|
99
80
|
fiber,
|
|
100
81
|
codeInfo,
|
|
101
82
|
name,
|
|
102
|
-
title
|
|
83
|
+
title,
|
|
84
|
+
componentProps: extractPropsFromFiber(fiber)
|
|
103
85
|
});
|
|
104
86
|
if (fiber && codeInfo) {
|
|
105
87
|
onInspectElement == null ? void 0 : onInspectElement({
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import "../chunk-I4E63NIC.mjs";
|
|
2
|
-
import {
|
|
3
|
-
getElementDimensions,
|
|
4
|
-
getNestedBoundingClientRect
|
|
5
|
-
} from "./utils";
|
|
2
|
+
import { getElementDimensions, getNestedBoundingClientRect } from "./utils";
|
|
6
3
|
const overlayStyles = {
|
|
7
4
|
padding: "transparent",
|
|
8
5
|
margin: "transparent",
|
|
@@ -271,14 +268,8 @@ class Overlay {
|
|
|
271
268
|
const box = getNestedBoundingClientRect(element, this.window);
|
|
272
269
|
const dims = getElementDimensions(element);
|
|
273
270
|
outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
|
|
274
|
-
outerBox.right = Math.max(
|
|
275
|
-
|
|
276
|
-
box.left + box.width + dims.marginRight
|
|
277
|
-
);
|
|
278
|
-
outerBox.bottom = Math.max(
|
|
279
|
-
outerBox.bottom,
|
|
280
|
-
box.top + box.height + dims.marginBottom
|
|
281
|
-
);
|
|
271
|
+
outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
|
|
272
|
+
outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
|
|
282
273
|
outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
|
|
283
274
|
const rect = this.rects[index];
|
|
284
275
|
rect.update(box, dims);
|
|
@@ -293,10 +284,7 @@ class Overlay {
|
|
|
293
284
|
} else {
|
|
294
285
|
this.tip.updateText(name);
|
|
295
286
|
}
|
|
296
|
-
const tipBounds = getNestedBoundingClientRect(
|
|
297
|
-
this.tipBoundsWindow.document.documentElement,
|
|
298
|
-
this.window
|
|
299
|
-
);
|
|
287
|
+
const tipBounds = getNestedBoundingClientRect(this.tipBoundsWindow.document.documentElement, this.window);
|
|
300
288
|
this.tip.updatePosition(
|
|
301
289
|
{
|
|
302
290
|
top: outerBox.top,
|
|
@@ -322,10 +310,15 @@ class Overlay {
|
|
|
322
310
|
}
|
|
323
311
|
}
|
|
324
312
|
class ClickOverlay {
|
|
325
|
-
constructor(
|
|
313
|
+
constructor(options) {
|
|
326
314
|
this.currentElement = null;
|
|
327
315
|
this.currentName = void 0;
|
|
328
|
-
|
|
316
|
+
if (typeof options === "function") {
|
|
317
|
+
this.positionUpdate = options;
|
|
318
|
+
} else {
|
|
319
|
+
this.positionUpdate = options == null ? void 0 : options.positionUpdate;
|
|
320
|
+
this.onElementRebind = options == null ? void 0 : options.onElementRebind;
|
|
321
|
+
}
|
|
329
322
|
const currentWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
|
|
330
323
|
this.window = currentWindow;
|
|
331
324
|
const tipBoundsWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
|
|
@@ -343,7 +336,17 @@ class ClickOverlay {
|
|
|
343
336
|
}
|
|
344
337
|
rafId = requestAnimationFrame(() => {
|
|
345
338
|
if (this.currentElement) {
|
|
346
|
-
this.
|
|
339
|
+
if (!this.currentElement.isConnected && this.currentElementId) {
|
|
340
|
+
const candidate = this.window.document.querySelector(
|
|
341
|
+
`[data-miaoda-id="${CSS.escape(this.currentElementId)}"]`
|
|
342
|
+
);
|
|
343
|
+
if (candidate) {
|
|
344
|
+
this._rebind(candidate);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (this.currentElement) {
|
|
348
|
+
this.updatePosition(this.currentElement);
|
|
349
|
+
}
|
|
347
350
|
}
|
|
348
351
|
});
|
|
349
352
|
(_a = this.positionUpdate) == null ? void 0 : _a.call(this);
|
|
@@ -359,16 +362,23 @@ class ClickOverlay {
|
|
|
359
362
|
this.currentElement = null;
|
|
360
363
|
this.resizeObserver.disconnect();
|
|
361
364
|
this.currentName = void 0;
|
|
365
|
+
this.currentElementId = void 0;
|
|
366
|
+
if (this.mutationObserver) {
|
|
367
|
+
this.mutationObserver.disconnect();
|
|
368
|
+
this.mutationObserver = void 0;
|
|
369
|
+
}
|
|
362
370
|
if (this.container.parentNode) {
|
|
363
371
|
this.container.parentNode.removeChild(this.container);
|
|
364
372
|
}
|
|
365
373
|
}
|
|
366
|
-
highlight(element, name) {
|
|
374
|
+
highlight(element, name, elementId) {
|
|
375
|
+
var _a;
|
|
367
376
|
if (!this.rect) {
|
|
368
377
|
this.rect = new ClickOverlayRect(this.window.document, this.container);
|
|
369
378
|
}
|
|
370
379
|
this.resizeObserver.disconnect();
|
|
371
380
|
this.currentElement = element;
|
|
381
|
+
this.currentElementId = (_a = elementId != null ? elementId : element.getAttribute("data-miaoda-id")) != null ? _a : void 0;
|
|
372
382
|
if (!name) {
|
|
373
383
|
name = element.nodeName.toLowerCase();
|
|
374
384
|
}
|
|
@@ -376,6 +386,22 @@ class ClickOverlay {
|
|
|
376
386
|
this.tip.updateText(name);
|
|
377
387
|
this.updatePosition(element);
|
|
378
388
|
this.resizeObserver.observe(element);
|
|
389
|
+
if (!this.mutationObserver) {
|
|
390
|
+
this.mutationObserver = new MutationObserver(() => {
|
|
391
|
+
if (this.currentElement && this.currentElement.isConnected) return;
|
|
392
|
+
if (!this.currentElementId) return;
|
|
393
|
+
const candidate = this.window.document.querySelector(
|
|
394
|
+
`[data-miaoda-id="${CSS.escape(this.currentElementId)}"]`
|
|
395
|
+
);
|
|
396
|
+
if (candidate && candidate !== this.currentElement) {
|
|
397
|
+
this._rebind(candidate);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
this.mutationObserver.observe(this.window.document.body, {
|
|
401
|
+
childList: true,
|
|
402
|
+
subtree: true
|
|
403
|
+
});
|
|
404
|
+
}
|
|
379
405
|
}
|
|
380
406
|
updatePosition(element) {
|
|
381
407
|
var _a;
|
|
@@ -388,20 +414,11 @@ class ClickOverlay {
|
|
|
388
414
|
const box = getNestedBoundingClientRect(element, this.window);
|
|
389
415
|
const dims = getElementDimensions(element);
|
|
390
416
|
outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
|
|
391
|
-
outerBox.right = Math.max(
|
|
392
|
-
|
|
393
|
-
box.left + box.width + dims.marginRight
|
|
394
|
-
);
|
|
395
|
-
outerBox.bottom = Math.max(
|
|
396
|
-
outerBox.bottom,
|
|
397
|
-
box.top + box.height + dims.marginBottom
|
|
398
|
-
);
|
|
417
|
+
outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
|
|
418
|
+
outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
|
|
399
419
|
outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
|
|
400
420
|
(_a = this.rect) == null ? void 0 : _a.update(box, dims);
|
|
401
|
-
const tipBounds = getNestedBoundingClientRect(
|
|
402
|
-
this.tipBoundsWindow.document.documentElement,
|
|
403
|
-
this.window
|
|
404
|
-
);
|
|
421
|
+
const tipBounds = getNestedBoundingClientRect(this.tipBoundsWindow.document.documentElement, this.window);
|
|
405
422
|
if (box.width === 0 || box.height === 0) {
|
|
406
423
|
this.tip.invisible();
|
|
407
424
|
}
|
|
@@ -425,6 +442,15 @@ class ClickOverlay {
|
|
|
425
442
|
(_a = this.rect) == null ? void 0 : _a.remove();
|
|
426
443
|
this.tip.invisible();
|
|
427
444
|
}
|
|
445
|
+
_rebind(newElement) {
|
|
446
|
+
this.resizeObserver.disconnect();
|
|
447
|
+
this.currentElement = newElement;
|
|
448
|
+
this.updatePosition(newElement);
|
|
449
|
+
this.resizeObserver.observe(newElement);
|
|
450
|
+
if (this.onElementRebind) {
|
|
451
|
+
this.onElementRebind(newElement);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
428
454
|
}
|
|
429
455
|
export {
|
|
430
456
|
ClickOverlay,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "../../chunk-I4E63NIC.mjs";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import {
|
|
3
4
|
isNativeTagFiber,
|
|
4
5
|
isReactSymbolFiber,
|
|
@@ -69,7 +70,7 @@ const getReferenceFiber = (baseFiber) => {
|
|
|
69
70
|
const directParent = getDirectParentFiber(baseFiber);
|
|
70
71
|
if (!directParent) return void 0;
|
|
71
72
|
const isParentNative = isNativeTagFiber(directParent);
|
|
72
|
-
const isOnlyOneChild = !directParent.child.sibling;
|
|
73
|
+
const isOnlyOneChild = !!directParent.child && !directParent.child.sibling;
|
|
73
74
|
let referenceFiber = !isParentNative && isOnlyOneChild ? directParent : baseFiber;
|
|
74
75
|
const originReferenceFiber = referenceFiber;
|
|
75
76
|
while (referenceFiber) {
|
|
@@ -120,12 +121,90 @@ const getElementInspect = (element) => {
|
|
|
120
121
|
title
|
|
121
122
|
};
|
|
122
123
|
};
|
|
124
|
+
const getParentElement = (element) => {
|
|
125
|
+
let parent = element;
|
|
126
|
+
while (parent && parent.tagName !== "HTML") {
|
|
127
|
+
if (parent.dataset.miaodaComponentName) {
|
|
128
|
+
return parent;
|
|
129
|
+
}
|
|
130
|
+
const fiber = getElementFiberUpward(parent);
|
|
131
|
+
const parentFiber = parent.parentElement ? getElementFiberUpward(parent.parentElement) : void 0;
|
|
132
|
+
const referenceFiber = getReferenceFiber(fiber);
|
|
133
|
+
const parentReferenceFiber = parentFiber ? getReferenceFiber(parentFiber) : null;
|
|
134
|
+
const currentName = referenceFiber == null ? void 0 : referenceFiber.pendingProps["data-miaoda-component-name"];
|
|
135
|
+
const parentName = parentReferenceFiber ? parentReferenceFiber.pendingProps["data-miaoda-component-name"] : null;
|
|
136
|
+
if (currentName && currentName !== parentName) {
|
|
137
|
+
return parent;
|
|
138
|
+
}
|
|
139
|
+
parent = parent.parentElement;
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
};
|
|
143
|
+
const extractPropsFromFiber = (fiber) => {
|
|
144
|
+
if (!(fiber == null ? void 0 : fiber.memoizedProps)) return {};
|
|
145
|
+
const filteredProps = {};
|
|
146
|
+
const internalKeys = ["key", "ref", "__self", "__source", "className", "style"];
|
|
147
|
+
const isSerializable = (value) => {
|
|
148
|
+
if (value === null || value === void 0) return true;
|
|
149
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
|
|
150
|
+
if (Array.isArray(value)) return value.every(isSerializable);
|
|
151
|
+
if (typeof value === "object") {
|
|
152
|
+
try {
|
|
153
|
+
JSON.stringify(value);
|
|
154
|
+
return true;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
};
|
|
161
|
+
Object.keys(fiber.memoizedProps).forEach((key) => {
|
|
162
|
+
var _a;
|
|
163
|
+
if (!internalKeys.includes(key) && !key.startsWith("__") && !key.startsWith("data-")) {
|
|
164
|
+
const value = fiber.memoizedProps[key];
|
|
165
|
+
if (key === "children") {
|
|
166
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
167
|
+
filteredProps[key] = value;
|
|
168
|
+
}
|
|
169
|
+
} else if (React.isValidElement(value)) {
|
|
170
|
+
const vProps = (_a = value == null ? void 0 : value.props) != null ? _a : {};
|
|
171
|
+
const importSource = vProps["data-miaoda-import-source"];
|
|
172
|
+
const elementName = vProps["data-miaoda-component-name"];
|
|
173
|
+
if (importSource === "lucide-react" && elementName) {
|
|
174
|
+
const name = elementName.includes(".") ? elementName.split(".").pop() : elementName;
|
|
175
|
+
filteredProps[key] = { __miaoda_icon__: { source: "lucide-react", name } };
|
|
176
|
+
}
|
|
177
|
+
} else if (isSerializable(value)) {
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
filteredProps[key] = value.slice(0, 10);
|
|
180
|
+
} else if (typeof value === "object" && value !== null) {
|
|
181
|
+
const obj = value;
|
|
182
|
+
const _keys = Object.keys(obj);
|
|
183
|
+
if (_keys.length <= 10) {
|
|
184
|
+
filteredProps[key] = value;
|
|
185
|
+
} else {
|
|
186
|
+
const limitedObj = {};
|
|
187
|
+
_keys.slice(0, 10).forEach((k) => {
|
|
188
|
+
limitedObj[k] = obj[k];
|
|
189
|
+
});
|
|
190
|
+
filteredProps[key] = limitedObj;
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
filteredProps[key] = value;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return filteredProps;
|
|
199
|
+
};
|
|
123
200
|
export {
|
|
201
|
+
extractPropsFromFiber,
|
|
124
202
|
getCodeInfoFromDebugSource,
|
|
125
203
|
getCodeInfoFromFiber,
|
|
126
204
|
getCodeInfoFromProps,
|
|
127
205
|
getElementCodeInfo,
|
|
128
206
|
getElementInspect,
|
|
129
207
|
getNamedFiber,
|
|
208
|
+
getParentElement,
|
|
130
209
|
getReferenceFiber
|
|
131
210
|
};
|