@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
|
@@ -291,14 +291,8 @@ class Overlay {
|
|
|
291
291
|
const box = (0, import_utils.getNestedBoundingClientRect)(element, this.window);
|
|
292
292
|
const dims = (0, import_utils.getElementDimensions)(element);
|
|
293
293
|
outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
|
|
294
|
-
outerBox.right = Math.max(
|
|
295
|
-
|
|
296
|
-
box.left + box.width + dims.marginRight
|
|
297
|
-
);
|
|
298
|
-
outerBox.bottom = Math.max(
|
|
299
|
-
outerBox.bottom,
|
|
300
|
-
box.top + box.height + dims.marginBottom
|
|
301
|
-
);
|
|
294
|
+
outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
|
|
295
|
+
outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
|
|
302
296
|
outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
|
|
303
297
|
const rect = this.rects[index];
|
|
304
298
|
rect.update(box, dims);
|
|
@@ -313,10 +307,7 @@ class Overlay {
|
|
|
313
307
|
} else {
|
|
314
308
|
this.tip.updateText(name);
|
|
315
309
|
}
|
|
316
|
-
const tipBounds = (0, import_utils.getNestedBoundingClientRect)(
|
|
317
|
-
this.tipBoundsWindow.document.documentElement,
|
|
318
|
-
this.window
|
|
319
|
-
);
|
|
310
|
+
const tipBounds = (0, import_utils.getNestedBoundingClientRect)(this.tipBoundsWindow.document.documentElement, this.window);
|
|
320
311
|
this.tip.updatePosition(
|
|
321
312
|
{
|
|
322
313
|
top: outerBox.top,
|
|
@@ -342,10 +333,15 @@ class Overlay {
|
|
|
342
333
|
}
|
|
343
334
|
}
|
|
344
335
|
class ClickOverlay {
|
|
345
|
-
constructor(
|
|
336
|
+
constructor(options) {
|
|
346
337
|
this.currentElement = null;
|
|
347
338
|
this.currentName = void 0;
|
|
348
|
-
|
|
339
|
+
if (typeof options === "function") {
|
|
340
|
+
this.positionUpdate = options;
|
|
341
|
+
} else {
|
|
342
|
+
this.positionUpdate = options == null ? void 0 : options.positionUpdate;
|
|
343
|
+
this.onElementRebind = options == null ? void 0 : options.onElementRebind;
|
|
344
|
+
}
|
|
349
345
|
const currentWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
|
|
350
346
|
this.window = currentWindow;
|
|
351
347
|
const tipBoundsWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
|
|
@@ -363,7 +359,17 @@ class ClickOverlay {
|
|
|
363
359
|
}
|
|
364
360
|
rafId = requestAnimationFrame(() => {
|
|
365
361
|
if (this.currentElement) {
|
|
366
|
-
this.
|
|
362
|
+
if (!this.currentElement.isConnected && this.currentElementId) {
|
|
363
|
+
const candidate = this.window.document.querySelector(
|
|
364
|
+
`[data-miaoda-id="${CSS.escape(this.currentElementId)}"]`
|
|
365
|
+
);
|
|
366
|
+
if (candidate) {
|
|
367
|
+
this._rebind(candidate);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (this.currentElement) {
|
|
371
|
+
this.updatePosition(this.currentElement);
|
|
372
|
+
}
|
|
367
373
|
}
|
|
368
374
|
});
|
|
369
375
|
(_a = this.positionUpdate) == null ? void 0 : _a.call(this);
|
|
@@ -379,16 +385,23 @@ class ClickOverlay {
|
|
|
379
385
|
this.currentElement = null;
|
|
380
386
|
this.resizeObserver.disconnect();
|
|
381
387
|
this.currentName = void 0;
|
|
388
|
+
this.currentElementId = void 0;
|
|
389
|
+
if (this.mutationObserver) {
|
|
390
|
+
this.mutationObserver.disconnect();
|
|
391
|
+
this.mutationObserver = void 0;
|
|
392
|
+
}
|
|
382
393
|
if (this.container.parentNode) {
|
|
383
394
|
this.container.parentNode.removeChild(this.container);
|
|
384
395
|
}
|
|
385
396
|
}
|
|
386
|
-
highlight(element, name) {
|
|
397
|
+
highlight(element, name, elementId) {
|
|
398
|
+
var _a;
|
|
387
399
|
if (!this.rect) {
|
|
388
400
|
this.rect = new ClickOverlayRect(this.window.document, this.container);
|
|
389
401
|
}
|
|
390
402
|
this.resizeObserver.disconnect();
|
|
391
403
|
this.currentElement = element;
|
|
404
|
+
this.currentElementId = (_a = elementId != null ? elementId : element.getAttribute("data-miaoda-id")) != null ? _a : void 0;
|
|
392
405
|
if (!name) {
|
|
393
406
|
name = element.nodeName.toLowerCase();
|
|
394
407
|
}
|
|
@@ -396,6 +409,22 @@ class ClickOverlay {
|
|
|
396
409
|
this.tip.updateText(name);
|
|
397
410
|
this.updatePosition(element);
|
|
398
411
|
this.resizeObserver.observe(element);
|
|
412
|
+
if (!this.mutationObserver) {
|
|
413
|
+
this.mutationObserver = new MutationObserver(() => {
|
|
414
|
+
if (this.currentElement && this.currentElement.isConnected) return;
|
|
415
|
+
if (!this.currentElementId) return;
|
|
416
|
+
const candidate = this.window.document.querySelector(
|
|
417
|
+
`[data-miaoda-id="${CSS.escape(this.currentElementId)}"]`
|
|
418
|
+
);
|
|
419
|
+
if (candidate && candidate !== this.currentElement) {
|
|
420
|
+
this._rebind(candidate);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
this.mutationObserver.observe(this.window.document.body, {
|
|
424
|
+
childList: true,
|
|
425
|
+
subtree: true
|
|
426
|
+
});
|
|
427
|
+
}
|
|
399
428
|
}
|
|
400
429
|
updatePosition(element) {
|
|
401
430
|
var _a;
|
|
@@ -408,20 +437,11 @@ class ClickOverlay {
|
|
|
408
437
|
const box = (0, import_utils.getNestedBoundingClientRect)(element, this.window);
|
|
409
438
|
const dims = (0, import_utils.getElementDimensions)(element);
|
|
410
439
|
outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
|
|
411
|
-
outerBox.right = Math.max(
|
|
412
|
-
|
|
413
|
-
box.left + box.width + dims.marginRight
|
|
414
|
-
);
|
|
415
|
-
outerBox.bottom = Math.max(
|
|
416
|
-
outerBox.bottom,
|
|
417
|
-
box.top + box.height + dims.marginBottom
|
|
418
|
-
);
|
|
440
|
+
outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
|
|
441
|
+
outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
|
|
419
442
|
outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
|
|
420
443
|
(_a = this.rect) == null ? void 0 : _a.update(box, dims);
|
|
421
|
-
const tipBounds = (0, import_utils.getNestedBoundingClientRect)(
|
|
422
|
-
this.tipBoundsWindow.document.documentElement,
|
|
423
|
-
this.window
|
|
424
|
-
);
|
|
444
|
+
const tipBounds = (0, import_utils.getNestedBoundingClientRect)(this.tipBoundsWindow.document.documentElement, this.window);
|
|
425
445
|
if (box.width === 0 || box.height === 0) {
|
|
426
446
|
this.tip.invisible();
|
|
427
447
|
}
|
|
@@ -445,4 +465,13 @@ class ClickOverlay {
|
|
|
445
465
|
(_a = this.rect) == null ? void 0 : _a.remove();
|
|
446
466
|
this.tip.invisible();
|
|
447
467
|
}
|
|
468
|
+
_rebind(newElement) {
|
|
469
|
+
this.resizeObserver.disconnect();
|
|
470
|
+
this.currentElement = newElement;
|
|
471
|
+
this.updatePosition(newElement);
|
|
472
|
+
this.resizeObserver.observe(newElement);
|
|
473
|
+
if (this.onElementRebind) {
|
|
474
|
+
this.onElementRebind(newElement);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
448
477
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,18 +17,29 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var inspect_exports = {};
|
|
20
30
|
__export(inspect_exports, {
|
|
31
|
+
extractPropsFromFiber: () => extractPropsFromFiber,
|
|
21
32
|
getCodeInfoFromDebugSource: () => getCodeInfoFromDebugSource,
|
|
22
33
|
getCodeInfoFromFiber: () => getCodeInfoFromFiber,
|
|
23
34
|
getCodeInfoFromProps: () => getCodeInfoFromProps,
|
|
24
35
|
getElementCodeInfo: () => getElementCodeInfo,
|
|
25
36
|
getElementInspect: () => getElementInspect,
|
|
26
37
|
getNamedFiber: () => getNamedFiber,
|
|
38
|
+
getParentElement: () => getParentElement,
|
|
27
39
|
getReferenceFiber: () => getReferenceFiber
|
|
28
40
|
});
|
|
29
41
|
module.exports = __toCommonJS(inspect_exports);
|
|
42
|
+
var import_react = __toESM(require("react"));
|
|
30
43
|
var import_fiber = require("./fiber");
|
|
31
44
|
const getCodeInfoFromDebugSource = (fiber) => {
|
|
32
45
|
var _a, _b;
|
|
@@ -90,7 +103,7 @@ const getReferenceFiber = (baseFiber) => {
|
|
|
90
103
|
const directParent = (0, import_fiber.getDirectParentFiber)(baseFiber);
|
|
91
104
|
if (!directParent) return void 0;
|
|
92
105
|
const isParentNative = (0, import_fiber.isNativeTagFiber)(directParent);
|
|
93
|
-
const isOnlyOneChild = !directParent.child.sibling;
|
|
106
|
+
const isOnlyOneChild = !!directParent.child && !directParent.child.sibling;
|
|
94
107
|
let referenceFiber = !isParentNative && isOnlyOneChild ? directParent : baseFiber;
|
|
95
108
|
const originReferenceFiber = referenceFiber;
|
|
96
109
|
while (referenceFiber) {
|
|
@@ -141,3 +154,79 @@ const getElementInspect = (element) => {
|
|
|
141
154
|
title
|
|
142
155
|
};
|
|
143
156
|
};
|
|
157
|
+
const getParentElement = (element) => {
|
|
158
|
+
let parent = element;
|
|
159
|
+
while (parent && parent.tagName !== "HTML") {
|
|
160
|
+
if (parent.dataset.miaodaComponentName) {
|
|
161
|
+
return parent;
|
|
162
|
+
}
|
|
163
|
+
const fiber = (0, import_fiber.getElementFiberUpward)(parent);
|
|
164
|
+
const parentFiber = parent.parentElement ? (0, import_fiber.getElementFiberUpward)(parent.parentElement) : void 0;
|
|
165
|
+
const referenceFiber = getReferenceFiber(fiber);
|
|
166
|
+
const parentReferenceFiber = parentFiber ? getReferenceFiber(parentFiber) : null;
|
|
167
|
+
const currentName = referenceFiber == null ? void 0 : referenceFiber.pendingProps["data-miaoda-component-name"];
|
|
168
|
+
const parentName = parentReferenceFiber ? parentReferenceFiber.pendingProps["data-miaoda-component-name"] : null;
|
|
169
|
+
if (currentName && currentName !== parentName) {
|
|
170
|
+
return parent;
|
|
171
|
+
}
|
|
172
|
+
parent = parent.parentElement;
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
};
|
|
176
|
+
const extractPropsFromFiber = (fiber) => {
|
|
177
|
+
if (!(fiber == null ? void 0 : fiber.memoizedProps)) return {};
|
|
178
|
+
const filteredProps = {};
|
|
179
|
+
const internalKeys = ["key", "ref", "__self", "__source", "className", "style"];
|
|
180
|
+
const isSerializable = (value) => {
|
|
181
|
+
if (value === null || value === void 0) return true;
|
|
182
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
|
|
183
|
+
if (Array.isArray(value)) return value.every(isSerializable);
|
|
184
|
+
if (typeof value === "object") {
|
|
185
|
+
try {
|
|
186
|
+
JSON.stringify(value);
|
|
187
|
+
return true;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
};
|
|
194
|
+
Object.keys(fiber.memoizedProps).forEach((key) => {
|
|
195
|
+
var _a;
|
|
196
|
+
if (!internalKeys.includes(key) && !key.startsWith("__") && !key.startsWith("data-")) {
|
|
197
|
+
const value = fiber.memoizedProps[key];
|
|
198
|
+
if (key === "children") {
|
|
199
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
200
|
+
filteredProps[key] = value;
|
|
201
|
+
}
|
|
202
|
+
} else if (import_react.default.isValidElement(value)) {
|
|
203
|
+
const vProps = (_a = value == null ? void 0 : value.props) != null ? _a : {};
|
|
204
|
+
const importSource = vProps["data-miaoda-import-source"];
|
|
205
|
+
const elementName = vProps["data-miaoda-component-name"];
|
|
206
|
+
if (importSource === "lucide-react" && elementName) {
|
|
207
|
+
const name = elementName.includes(".") ? elementName.split(".").pop() : elementName;
|
|
208
|
+
filteredProps[key] = { __miaoda_icon__: { source: "lucide-react", name } };
|
|
209
|
+
}
|
|
210
|
+
} else if (isSerializable(value)) {
|
|
211
|
+
if (Array.isArray(value)) {
|
|
212
|
+
filteredProps[key] = value.slice(0, 10);
|
|
213
|
+
} else if (typeof value === "object" && value !== null) {
|
|
214
|
+
const obj = value;
|
|
215
|
+
const _keys = Object.keys(obj);
|
|
216
|
+
if (_keys.length <= 10) {
|
|
217
|
+
filteredProps[key] = value;
|
|
218
|
+
} else {
|
|
219
|
+
const limitedObj = {};
|
|
220
|
+
_keys.slice(0, 10).forEach((k) => {
|
|
221
|
+
limitedObj[k] = obj[k];
|
|
222
|
+
});
|
|
223
|
+
filteredProps[key] = limitedObj;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
filteredProps[key] = value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return filteredProps;
|
|
232
|
+
};
|